"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
require("core-js/modules/es.array.map.js");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _keys3 = _interopRequireDefault(require("lodash/keys"));
var _reactBootstrap = require("react-bootstrap");
var _authorCreditDisplay = _interopRequireDefault(require("../../components/author-credit-display"));
var _authorCreditRow = _interopRequireDefault(require("./author-credit-row"));
var _reactFontawesome = require("@fortawesome/react-fontawesome");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _actions = require("./actions");
var _reactRedux = require("react-redux");
var _utils = require("../../helpers/utils");
var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
var _excluded = ["authorCredit", "onAddAuthorCreditRow", "onClose", "showEditor"];
/*
* Copyright (C) 2020 Sean Burke
* 2020 Nicolas Pelletier
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* Container component. The AuthorCreditEditor component contains a number of
* AuthorCreditRow elements, and renders these inside a modal, which appears when
* the show property of the component is set.
*
* @param {Object} props - The properties passed to the component.
* @param {Object} props.authorCredit - The Author credit object containing rows
* to be rendered in the editor.
* @param {Function} props.onAddAuthorCreditRow - A function to be called when the
* button to add an Author is clicked.
* @param {Function} props.onClose - A function to be called when the
* modal is closed by a button click or clicking outside the modal.
* @param {boolean} props.showEditor - A boolean indicating whether to show the modal or not.
* @returns {ReactElement} React element containing the rendered
* AuthorCreditEditor modal.
*/
var AuthorCreditEditor = function AuthorCreditEditor(_ref) {
var authorCredit = _ref.authorCredit,
onAddAuthorCreditRow = _ref.onAddAuthorCreditRow,
onClose = _ref.onClose,
showEditor = _ref.showEditor,
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
return /*#__PURE__*/_react.default.createElement(_reactBootstrap.Modal, {
show: showEditor,
size: "lg",
onHide: onClose
}, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Modal.Header, null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Modal.Title, null, "Edit Author credit")), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Modal.Body, null, /*#__PURE__*/_react.default.createElement("p", null, "Author credits indicate who is the main credited Author (or Authors) for Editions, and how they are credited. They consist of Authors, with (optionally) their names as credited in the specific Edition (i.e. on the cover), and join phrases between them. Keep in mind that join phrases should include spaces before and after if you want any to appear in the final credit."), /*#__PURE__*/_react.default.createElement("hr", null), /*#__PURE__*/_react.default.createElement("dl", null, /*#__PURE__*/_react.default.createElement("dt", null, "Preview of the final Author credit:"), /*#__PURE__*/_react.default.createElement("dd", null, /*#__PURE__*/_react.default.createElement(_authorCreditDisplay.default, {
names: authorCredit
}))), /*#__PURE__*/_react.default.createElement("hr", {
className: "thin"
}), /*#__PURE__*/_react.default.createElement("div", null, (0, _keys3.default)(authorCredit).map(function (rowId) {
return /*#__PURE__*/_react.default.createElement(_authorCreditRow.default, (0, _extends2.default)({
index: rowId
// eslint-disable-next-line react/no-array-index-key
,
key: rowId
}, rest));
}))), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Modal.Footer, null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
variant: "success",
onClick: onAddAuthorCreditRow
}, /*#__PURE__*/_react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
icon: _freeSolidSvgIcons.faPlus
}), "\xA0Add another author"), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
variant: "warning",
onClick: onClose
}, "Close")));
};
AuthorCreditEditor.displayName = 'AuthorCreditEditor';
AuthorCreditEditor.propTypes = {
authorCredit: _propTypes.default.object.isRequired,
onAddAuthorCreditRow: _propTypes.default.func.isRequired,
onClose: _propTypes.default.func.isRequired,
showEditor: _propTypes.default.bool
};
AuthorCreditEditor.defaultProps = {
showEditor: false
};
function mapStateToProps(state) {
return {
authorCredit: (0, _utils.convertMapToObject)(state.get('authorCreditEditor'))
};
}
function mapDispatchToProps(dispatch) {
return {
onAddAuthorCreditRow: function onAddAuthorCreditRow() {
return dispatch((0, _actions.addAuthorCreditRow)());
}
};
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(AuthorCreditEditor);
exports.default = _default;
//# sourceMappingURL=author-credit-editor.js.map