@manuscripts/body-editor 3.18.4 → 3.18.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/cjs/components/references/CitationEditor.js +5 -5
  2. package/dist/cjs/components/references/InsertCitationModal.js +142 -0
  3. package/dist/cjs/components/references/ReferenceSearchResults.js +2 -2
  4. package/dist/cjs/components/references/ReferenceSearchSection.js +16 -10
  5. package/dist/cjs/components/references/SearchInput.js +1 -8
  6. package/dist/cjs/versions.js +1 -1
  7. package/dist/cjs/views/citation_editable.js +1 -0
  8. package/dist/es/components/references/CitationEditor.js +5 -5
  9. package/dist/es/components/references/InsertCitationModal.js +102 -0
  10. package/dist/es/components/references/ReferenceSearchResults.js +2 -2
  11. package/dist/es/components/references/ReferenceSearchSection.js +16 -10
  12. package/dist/es/components/references/SearchInput.js +0 -7
  13. package/dist/es/versions.js +1 -1
  14. package/dist/es/views/citation_editable.js +1 -0
  15. package/dist/types/components/references/CitationEditor.d.ts +1 -0
  16. package/dist/types/components/references/{ReferenceSearch.d.ts → InsertCitationModal.d.ts} +2 -1
  17. package/dist/types/components/references/ReferenceSearchResults.d.ts +1 -0
  18. package/dist/types/components/references/ReferenceSearchSection.d.ts +1 -0
  19. package/dist/types/components/references/SearchInput.d.ts +0 -1
  20. package/dist/types/versions.d.ts +1 -1
  21. package/package.json +3 -3
  22. package/src/components/references/CitationEditor.tsx +8 -4
  23. package/src/components/references/InsertCitationModal.tsx +198 -0
  24. package/src/components/references/ReferenceSearchResults.tsx +15 -2
  25. package/src/components/references/ReferenceSearchSection.tsx +19 -10
  26. package/src/components/references/SearchInput.tsx +0 -8
  27. package/src/versions.ts +1 -1
  28. package/src/views/citation_editable.ts +1 -0
  29. package/styles/popper.css +4 -0
  30. package/dist/cjs/components/references/ReferenceSearch.js +0 -133
  31. package/dist/es/components/references/ReferenceSearch.js +0 -93
  32. package/src/components/references/ReferenceSearch.tsx +0 -149
@@ -46,7 +46,7 @@ const array_reducer_1 = require("../../lib/array-reducer");
46
46
  const utils_1 = require("../../lib/utils");
47
47
  const CitationViewer_1 = require("./CitationViewer");
48
48
  const ReferenceLine_1 = require("./ReferenceLine");
49
- const ReferenceSearch_1 = require("./ReferenceSearch");
49
+ const InsertCitationModal_1 = require("./InsertCitationModal");
50
50
  const ReferencesModal_1 = require("./ReferencesModal");
51
51
  const Container = (0, style_guide_1.withFocusTrap)(styled_components_1.default.div ``);
52
52
  const CitedItemActions = styled_components_1.default.div `
@@ -62,7 +62,7 @@ const Actions = (0, styled_components_1.default)(style_guide_1.ButtonGroup) `
62
62
  `;
63
63
  const itemsReducer = (0, array_reducer_1.attrsReducer)();
64
64
  const ridsReducer = (0, array_reducer_1.arrayReducer)();
65
- const CitationEditor = ({ query, rids: $rids, items: $items, citationCounts, sources, onSave, onDelete, onCite, onUncite, onCancel, canEdit, }) => {
65
+ const CitationEditor = ({ query, rids: $rids, items: $items, citationCounts, sources, onSave, onDelete, onCite, onUncite, onCancel, canEdit, isNodeDeleted, }) => {
66
66
  const [items, dispatchItems] = (0, react_1.useReducer)(itemsReducer, $items);
67
67
  const [rids, dispatchRids] = (0, react_1.useReducer)(ridsReducer, $rids);
68
68
  const handleSave = (item) => {
@@ -132,13 +132,13 @@ const CitationEditor = ({ query, rids: $rids, items: $items, citationCounts, sou
132
132
  return (react_1.default.createElement(ReferencesModal_1.ReferencesModal, { isOpen: editingForm.show, onCancel: () => setEditingForm({ show: false }), items: items, citationCounts: citationCounts, item: editingForm.item, onSave: handleSave, onDelete: handleDelete, handleImport: handleImport }));
133
133
  }
134
134
  if (searching) {
135
- return (react_1.default.createElement(ReferenceSearch_1.ReferenceSearch, { sources: sources, items: items, onAdd: handleAdd, onCite: (items) => {
135
+ return (react_1.default.createElement(InsertCitationModal_1.InsertCitationModal, { sources: sources, items: items, citationCounts: citationCounts, onAdd: handleAdd, onCite: (items) => {
136
136
  setSearching(false);
137
137
  handleCite(items);
138
138
  }, onCancel: () => setSearching(false) }));
139
139
  }
140
- if (!rids.length) {
141
- return (react_1.default.createElement(ReferenceSearch_1.ReferenceSearch, { query: query, sources: sources, items: items, onAdd: handleAdd, onCite: handleCite, onCancel: onCancel }));
140
+ if (!rids.length && !isNodeDeleted()) {
141
+ return (react_1.default.createElement(InsertCitationModal_1.InsertCitationModal, { query: query, sources: sources, items: items, citationCounts: citationCounts, onAdd: handleAdd, onCite: handleCite, onCancel: onCancel }));
142
142
  }
143
143
  return (react_1.default.createElement(Container, null,
144
144
  react_1.default.createElement(style_guide_1.Dialog, { isOpen: deleteDialog.show, category: style_guide_1.Category.confirmation, header: "Remove cited item", message: "Are you sure you want to remove this cited item? It will still exist in the reference list.", actions: {
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2023 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || (function () {
34
+ var ownKeys = function(o) {
35
+ ownKeys = Object.getOwnPropertyNames || function (o) {
36
+ var ar = [];
37
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
+ return ar;
39
+ };
40
+ return ownKeys(o);
41
+ };
42
+ return function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
+ __setModuleDefault(result, mod);
47
+ return result;
48
+ };
49
+ })();
50
+ var __importDefault = (this && this.__importDefault) || function (mod) {
51
+ return (mod && mod.__esModule) ? mod : { "default": mod };
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.InsertCitationModal = void 0;
55
+ const style_guide_1 = require("@manuscripts/style-guide");
56
+ const lodash_1 = require("lodash");
57
+ const react_1 = __importStar(require("react"));
58
+ const styled_components_1 = __importDefault(require("styled-components"));
59
+ const CreateModalStyles_1 = require("../form/CreateModalStyles");
60
+ const BibliographyItemSource_1 = require("./BibliographyItemSource");
61
+ const ReferenceSearchSection_1 = require("./ReferenceSearchSection");
62
+ const SearchInput_1 = require("./SearchInput");
63
+ const Container = (0, style_guide_1.withFocusTrap)(style_guide_1.ModalContainer);
64
+ const StyledModalSidebar = (0, styled_components_1.default)(style_guide_1.ModalSidebar) `
65
+ background: white;
66
+ width: 44vw;
67
+ padding: ${(props) => props.theme.grid.unit * 6}px;
68
+ `;
69
+ const StyledSidebarContent = (0, styled_components_1.default)(style_guide_1.SidebarContent) `
70
+ display: flex;
71
+ flex-direction: column;
72
+ gap: ${(props) => props.theme.grid.unit * 4}px;
73
+ padding: 6px;
74
+ `;
75
+ const StyledSidebarHeader = (0, styled_components_1.default)(style_guide_1.ModalSidebarHeader) `
76
+ padding: 0;
77
+ `;
78
+ const InsertCitationButton = (0, styled_components_1.default)(style_guide_1.IconTextButton) `
79
+ svg {
80
+ margin-right: ${(props) => props.theme.grid.unit * 2}px;
81
+ }
82
+ `;
83
+ const Actions = (0, styled_components_1.default)(style_guide_1.ButtonGroup) `
84
+ display: flex;
85
+ align-items: center;
86
+ justify-content: space-between;
87
+ padding: ${(props) => props.theme.grid.unit * 4}px 0;
88
+ `;
89
+ const InsertCitationModal = ({ query: initialQuery, sources, items, citationCounts, onAdd, onCite, onCancel, }) => {
90
+ const [isOpen, setOpen] = (0, react_1.useState)(true);
91
+ const [query, setQuery] = (0, react_1.useState)(initialQuery || '');
92
+ const [selections, setSelections] = (0, react_1.useState)(new Map());
93
+ const handleClose = () => {
94
+ onCancel();
95
+ setOpen(false);
96
+ };
97
+ const toggleSelection = (item) => {
98
+ const id = item.id;
99
+ if (selections.has(id)) {
100
+ selections.delete(id);
101
+ setSelections(new Map([...selections]));
102
+ }
103
+ else {
104
+ selections.set(id, item);
105
+ setSelections(new Map([...selections]));
106
+ }
107
+ };
108
+ const isSelected = (item) => {
109
+ return selections.has(item.id);
110
+ };
111
+ const document = new BibliographyItemSource_1.DocumentReferenceSource(items);
112
+ const handleClick = () => {
113
+ const items = Array.from(selections.values());
114
+ return onCite(items);
115
+ };
116
+ const debouncedSetQuery = (0, react_1.useMemo)(() => (0, lodash_1.debounce)((e) => {
117
+ setQuery(e.target.value.trim());
118
+ }, 800), []);
119
+ (0, react_1.useEffect)(() => () => debouncedSetQuery.cancel(), [debouncedSetQuery]);
120
+ return (react_1.default.createElement(style_guide_1.StyledModal, { isOpen: isOpen, onRequestClose: handleClose, shouldCloseOnOverlayClick: true },
121
+ react_1.default.createElement(Container, { "data-cy": "reference-finder" },
122
+ react_1.default.createElement(style_guide_1.ModalHeader, null,
123
+ react_1.default.createElement(style_guide_1.CloseButton, { onClick: handleClose, "data-cy": "modal-close-button" })),
124
+ react_1.default.createElement(CreateModalStyles_1.StyledModalBody, null,
125
+ react_1.default.createElement(StyledModalSidebar, null,
126
+ react_1.default.createElement(StyledSidebarHeader, null,
127
+ react_1.default.createElement(style_guide_1.ModalSidebarTitle, null, "Insert Citation")),
128
+ react_1.default.createElement(StyledSidebarContent, null,
129
+ react_1.default.createElement(SearchInput_1.SearchInput, { onChange: debouncedSetQuery, defaultValue: initialQuery }),
130
+ react_1.default.createElement(ReferenceSearchSection_1.ReferenceSearchSection, { key: document.id, query: query, source: document, documentCitationCounts: citationCounts, isSelected: isSelected, onSelect: toggleSelection }),
131
+ query.length
132
+ ? sources.map((source) => (react_1.default.createElement(ReferenceSearchSection_1.ReferenceSearchSection, { key: source.id, query: query, source: source, isSelected: isSelected, onSelect: toggleSelection })))
133
+ : ''),
134
+ react_1.default.createElement(Actions, null,
135
+ react_1.default.createElement(InsertCitationButton, { onClick: onAdd },
136
+ react_1.default.createElement(style_guide_1.AddNewIcon, null),
137
+ "Add new"),
138
+ react_1.default.createElement(style_guide_1.ButtonGroup, null,
139
+ react_1.default.createElement(style_guide_1.TertiaryButton, { onClick: handleClose }, "Cancel"),
140
+ react_1.default.createElement(style_guide_1.PrimaryButton, { onClick: handleClick, disabled: selections.size === 0 }, "Insert Citation"))))))));
141
+ };
142
+ exports.InsertCitationModal = InsertCitationModal;
@@ -91,7 +91,7 @@ exports.ReferenceSearchResult = (0, style_guide_1.withNavigableListItem)(styled_
91
91
  border-bottom: 1px solid #f6f6f6;
92
92
  }
93
93
  `);
94
- const ReferenceSearchResults = ({ items, total, isSelected, onSelect, onShowMore }) => {
94
+ const ReferenceSearchResults = ({ items, total, documentCitationCounts, isSelected, onSelect, onShowMore, }) => {
95
95
  const list = (0, react_1.useRef)(null);
96
96
  const onExpandReferenceList = () => {
97
97
  const element = list.current;
@@ -105,7 +105,7 @@ const ReferenceSearchResults = ({ items, total, isSelected, onSelect, onShowMore
105
105
  return (react_1.default.createElement(exports.ReferenceSearchResultsContainer, { ref: list },
106
106
  items.map((item) => (react_1.default.createElement(exports.ReferenceSearchResult, { onClick: () => onSelect(item), key: item.id, "data-cy": `${isSelected(item) ? 'selected-reference' : 'reference'}` },
107
107
  react_1.default.createElement(StatusIcon, null, isSelected(item) ? (react_1.default.createElement(style_guide_1.AddedIcon, { width: 24, height: 24 })) : (react_1.default.createElement(style_guide_1.AddIcon, { width: 24, height: 24 }))),
108
- react_1.default.createElement(ReferenceLine_1.ReferenceLine, { item: item })))),
108
+ react_1.default.createElement(ReferenceLine_1.ReferenceLine, { item: item, showUncited: documentCitationCounts && !documentCitationCounts.get(item.id) })))),
109
109
  items.length < 25 && total > items.length ? (react_1.default.createElement(MoreButton, { onClick: onExpandReferenceList, "data-cy": 'more-button' }, "Show more")) : undefined));
110
110
  };
111
111
  exports.ReferenceSearchResults = ReferenceSearchResults;
@@ -58,16 +58,22 @@ const styled_components_1 = __importDefault(require("styled-components"));
58
58
  const ReferenceSearchResults_1 = require("./ReferenceSearchResults");
59
59
  const ReferenceSearchResultsPlaceholder_1 = require("./ReferenceSearchResultsPlaceholder");
60
60
  const SearchSourceLabel = (0, styled_components_1.default)(style_guide_1.IconTextButton) `
61
- margin: ${(props) => props.theme.grid.unit * 2}px
62
- ${(props) => props.theme.grid.unit * 4}px
63
- ${(props) => props.theme.grid.unit * 2}px;
64
- color: ${(props) => props.theme.colors.text.secondary};
65
-
66
- &:hover {
67
- color: ${(props) => props.theme.colors.text.muted};
61
+ height: ${(props) => props.theme.grid.unit * 10}px;
62
+ background: #f2f2f2;
63
+ display: flex;
64
+ justify-content: flex-start;
65
+ padding: ${(props) => props.theme.grid.unit * 2}px;
66
+ svg {
67
+ margin-right: ${(props) => props.theme.grid.unit * 2}px;
68
68
  }
69
69
  `;
70
- const ReferenceSearchSection = ({ query, source, isSelected, onSelect }) => {
70
+ const Container = styled_components_1.default.div `
71
+ display: flex;
72
+ flex-direction: column;
73
+ border-radius: 4px;
74
+ border: 1px solid #e2e2e2;
75
+ `;
76
+ const ReferenceSearchSection = ({ query, source, documentCitationCounts, isSelected, onSelect }) => {
71
77
  const [expanded, setExpanded] = (0, react_1.useState)(true);
72
78
  const [state, setState] = (0, react_1.useState)();
73
79
  const [limit, setLimit] = (0, react_1.useState)(3);
@@ -100,11 +106,11 @@ const ReferenceSearchSection = ({ query, source, isSelected, onSelect }) => {
100
106
  const handleShowMore = () => {
101
107
  setLimit(25);
102
108
  };
103
- return (react_1.default.createElement(react_1.default.Fragment, null,
109
+ return (react_1.default.createElement(Container, null,
104
110
  react_1.default.createElement(SearchSourceLabel, { onClick: toggleExpanded },
105
111
  expanded ? (react_1.default.createElement(style_guide_1.TriangleExpandedIcon, { className: 'icon' })) : (react_1.default.createElement(style_guide_1.TriangleCollapsedIcon, { className: 'icon' })),
106
112
  source.label),
107
113
  expanded && state?.type === 'running' && (react_1.default.createElement(ReferenceSearchResultsPlaceholder_1.ReferenceSearchResultsPlaceholder, null)),
108
- expanded && state?.type === 'completed' && (react_1.default.createElement(ReferenceSearchResults_1.ReferenceSearchResults, { items: state.items, total: state.total, isSelected: isSelected, onSelect: onSelect, onShowMore: handleShowMore }))));
114
+ expanded && state?.type === 'completed' && (react_1.default.createElement(ReferenceSearchResults_1.ReferenceSearchResults, { items: state.items, total: state.total, documentCitationCounts: documentCitationCounts, isSelected: isSelected, onSelect: onSelect, onShowMore: handleShowMore }))));
109
115
  };
110
116
  exports.ReferenceSearchSection = ReferenceSearchSection;
@@ -51,16 +51,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
51
51
  return (mod && mod.__esModule) ? mod : { "default": mod };
52
52
  };
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.SearchInput = exports.SearchWrapper = void 0;
54
+ exports.SearchInput = void 0;
55
55
  const style_guide_1 = require("@manuscripts/style-guide");
56
56
  const react_1 = __importStar(require("react"));
57
57
  const styled_components_1 = __importDefault(require("styled-components"));
58
58
  const SearchContainer = styled_components_1.default.div `
59
59
  align-items: center;
60
60
  display: flex;
61
- flex: 1 0 auto;
62
61
  position: relative;
63
- margin: 12px;
64
62
  `;
65
63
  const SearchIconContainer = styled_components_1.default.span `
66
64
  display: flex;
@@ -84,11 +82,6 @@ const SearchTextField = (0, styled_components_1.default)(style_guide_1.TextField
84
82
  background-color: ${(props) => props.theme.colors.background.fifth};
85
83
  }
86
84
  `;
87
- exports.SearchWrapper = styled_components_1.default.div `
88
- display: flex;
89
- align-items: center;
90
- padding: ${(props) => props.theme.grid.unit * 3}px;
91
- `;
92
85
  const SearchInput = (props) => {
93
86
  const [hover, setHover] = (0, react_1.useState)(false);
94
87
  const [focus, setFocus] = (0, react_1.useState)(false);
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MATHJAX_VERSION = exports.VERSION = void 0;
4
- exports.VERSION = '3.18.4';
4
+ exports.VERSION = '3.18.6';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -115,6 +115,7 @@ class CitationEditableView extends citation_1.CitationView {
115
115
  onSave: this.handleSave,
116
116
  onDelete: this.handleDelete,
117
117
  onCancel: this.handleCancel,
118
+ isNodeDeleted: () => (0, track_changes_plugin_1.isDeleted)(this.node),
118
119
  canEdit: can.editCitationsAndRefs,
119
120
  };
120
121
  this.editor = (0, ReactSubView_1.default)(this.props, CitationEditor_1.CitationEditor, componentProps, this.node, this.getPos, this.view, ['citation-editor']);
@@ -7,7 +7,7 @@ import { arrayReducer, attrsReducer } from '../../lib/array-reducer';
7
7
  import { cleanItemValues } from '../../lib/utils';
8
8
  import { CitedItem, CitedItems } from './CitationViewer';
9
9
  import { ReferenceLine } from './ReferenceLine';
10
- import { ReferenceSearch } from './ReferenceSearch';
10
+ import { InsertCitationModal } from './InsertCitationModal';
11
11
  import { ReferencesModal } from './ReferencesModal';
12
12
  const Container = withFocusTrap(styled.div ``);
13
13
  const CitedItemActions = styled.div `
@@ -23,7 +23,7 @@ const Actions = styled(ButtonGroup) `
23
23
  `;
24
24
  const itemsReducer = attrsReducer();
25
25
  const ridsReducer = arrayReducer();
26
- export const CitationEditor = ({ query, rids: $rids, items: $items, citationCounts, sources, onSave, onDelete, onCite, onUncite, onCancel, canEdit, }) => {
26
+ export const CitationEditor = ({ query, rids: $rids, items: $items, citationCounts, sources, onSave, onDelete, onCite, onUncite, onCancel, canEdit, isNodeDeleted, }) => {
27
27
  const [items, dispatchItems] = useReducer(itemsReducer, $items);
28
28
  const [rids, dispatchRids] = useReducer(ridsReducer, $rids);
29
29
  const handleSave = (item) => {
@@ -93,13 +93,13 @@ export const CitationEditor = ({ query, rids: $rids, items: $items, citationCoun
93
93
  return (React.createElement(ReferencesModal, { isOpen: editingForm.show, onCancel: () => setEditingForm({ show: false }), items: items, citationCounts: citationCounts, item: editingForm.item, onSave: handleSave, onDelete: handleDelete, handleImport: handleImport }));
94
94
  }
95
95
  if (searching) {
96
- return (React.createElement(ReferenceSearch, { sources: sources, items: items, onAdd: handleAdd, onCite: (items) => {
96
+ return (React.createElement(InsertCitationModal, { sources: sources, items: items, citationCounts: citationCounts, onAdd: handleAdd, onCite: (items) => {
97
97
  setSearching(false);
98
98
  handleCite(items);
99
99
  }, onCancel: () => setSearching(false) }));
100
100
  }
101
- if (!rids.length) {
102
- return (React.createElement(ReferenceSearch, { query: query, sources: sources, items: items, onAdd: handleAdd, onCite: handleCite, onCancel: onCancel }));
101
+ if (!rids.length && !isNodeDeleted()) {
102
+ return (React.createElement(InsertCitationModal, { query: query, sources: sources, items: items, citationCounts: citationCounts, onAdd: handleAdd, onCite: handleCite, onCancel: onCancel }));
103
103
  }
104
104
  return (React.createElement(Container, null,
105
105
  React.createElement(Dialog, { isOpen: deleteDialog.show, category: Category.confirmation, header: "Remove cited item", message: "Are you sure you want to remove this cited item? It will still exist in the reference list.", actions: {
@@ -0,0 +1,102 @@
1
+ /*!
2
+ * © 2023 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { AddNewIcon, ButtonGroup, CloseButton, IconTextButton, ModalContainer, ModalHeader, ModalSidebar, ModalSidebarHeader, ModalSidebarTitle, PrimaryButton, SidebarContent, StyledModal, TertiaryButton, withFocusTrap, } from '@manuscripts/style-guide';
17
+ import { debounce } from 'lodash';
18
+ import React, { useEffect, useMemo, useState } from 'react';
19
+ import styled from 'styled-components';
20
+ import { StyledModalBody } from '../form/CreateModalStyles';
21
+ import { DocumentReferenceSource, } from './BibliographyItemSource';
22
+ import { ReferenceSearchSection } from './ReferenceSearchSection';
23
+ import { SearchInput } from './SearchInput';
24
+ const Container = withFocusTrap(ModalContainer);
25
+ const StyledModalSidebar = styled(ModalSidebar) `
26
+ background: white;
27
+ width: 44vw;
28
+ padding: ${(props) => props.theme.grid.unit * 6}px;
29
+ `;
30
+ const StyledSidebarContent = styled(SidebarContent) `
31
+ display: flex;
32
+ flex-direction: column;
33
+ gap: ${(props) => props.theme.grid.unit * 4}px;
34
+ padding: 6px;
35
+ `;
36
+ const StyledSidebarHeader = styled(ModalSidebarHeader) `
37
+ padding: 0;
38
+ `;
39
+ const InsertCitationButton = styled(IconTextButton) `
40
+ svg {
41
+ margin-right: ${(props) => props.theme.grid.unit * 2}px;
42
+ }
43
+ `;
44
+ const Actions = styled(ButtonGroup) `
45
+ display: flex;
46
+ align-items: center;
47
+ justify-content: space-between;
48
+ padding: ${(props) => props.theme.grid.unit * 4}px 0;
49
+ `;
50
+ export const InsertCitationModal = ({ query: initialQuery, sources, items, citationCounts, onAdd, onCite, onCancel, }) => {
51
+ const [isOpen, setOpen] = useState(true);
52
+ const [query, setQuery] = useState(initialQuery || '');
53
+ const [selections, setSelections] = useState(new Map());
54
+ const handleClose = () => {
55
+ onCancel();
56
+ setOpen(false);
57
+ };
58
+ const toggleSelection = (item) => {
59
+ const id = item.id;
60
+ if (selections.has(id)) {
61
+ selections.delete(id);
62
+ setSelections(new Map([...selections]));
63
+ }
64
+ else {
65
+ selections.set(id, item);
66
+ setSelections(new Map([...selections]));
67
+ }
68
+ };
69
+ const isSelected = (item) => {
70
+ return selections.has(item.id);
71
+ };
72
+ const document = new DocumentReferenceSource(items);
73
+ const handleClick = () => {
74
+ const items = Array.from(selections.values());
75
+ return onCite(items);
76
+ };
77
+ const debouncedSetQuery = useMemo(() => debounce((e) => {
78
+ setQuery(e.target.value.trim());
79
+ }, 800), []);
80
+ useEffect(() => () => debouncedSetQuery.cancel(), [debouncedSetQuery]);
81
+ return (React.createElement(StyledModal, { isOpen: isOpen, onRequestClose: handleClose, shouldCloseOnOverlayClick: true },
82
+ React.createElement(Container, { "data-cy": "reference-finder" },
83
+ React.createElement(ModalHeader, null,
84
+ React.createElement(CloseButton, { onClick: handleClose, "data-cy": "modal-close-button" })),
85
+ React.createElement(StyledModalBody, null,
86
+ React.createElement(StyledModalSidebar, null,
87
+ React.createElement(StyledSidebarHeader, null,
88
+ React.createElement(ModalSidebarTitle, null, "Insert Citation")),
89
+ React.createElement(StyledSidebarContent, null,
90
+ React.createElement(SearchInput, { onChange: debouncedSetQuery, defaultValue: initialQuery }),
91
+ React.createElement(ReferenceSearchSection, { key: document.id, query: query, source: document, documentCitationCounts: citationCounts, isSelected: isSelected, onSelect: toggleSelection }),
92
+ query.length
93
+ ? sources.map((source) => (React.createElement(ReferenceSearchSection, { key: source.id, query: query, source: source, isSelected: isSelected, onSelect: toggleSelection })))
94
+ : ''),
95
+ React.createElement(Actions, null,
96
+ React.createElement(InsertCitationButton, { onClick: onAdd },
97
+ React.createElement(AddNewIcon, null),
98
+ "Add new"),
99
+ React.createElement(ButtonGroup, null,
100
+ React.createElement(TertiaryButton, { onClick: handleClose }, "Cancel"),
101
+ React.createElement(PrimaryButton, { onClick: handleClick, disabled: selections.size === 0 }, "Insert Citation"))))))));
102
+ };
@@ -52,7 +52,7 @@ export const ReferenceSearchResult = withNavigableListItem(styled.div `
52
52
  border-bottom: 1px solid #f6f6f6;
53
53
  }
54
54
  `);
55
- export const ReferenceSearchResults = ({ items, total, isSelected, onSelect, onShowMore }) => {
55
+ export const ReferenceSearchResults = ({ items, total, documentCitationCounts, isSelected, onSelect, onShowMore, }) => {
56
56
  const list = useRef(null);
57
57
  const onExpandReferenceList = () => {
58
58
  const element = list.current;
@@ -66,6 +66,6 @@ export const ReferenceSearchResults = ({ items, total, isSelected, onSelect, onS
66
66
  return (React.createElement(ReferenceSearchResultsContainer, { ref: list },
67
67
  items.map((item) => (React.createElement(ReferenceSearchResult, { onClick: () => onSelect(item), key: item.id, "data-cy": `${isSelected(item) ? 'selected-reference' : 'reference'}` },
68
68
  React.createElement(StatusIcon, null, isSelected(item) ? (React.createElement(AddedIcon, { width: 24, height: 24 })) : (React.createElement(AddIcon, { width: 24, height: 24 }))),
69
- React.createElement(ReferenceLine, { item: item })))),
69
+ React.createElement(ReferenceLine, { item: item, showUncited: documentCitationCounts && !documentCitationCounts.get(item.id) })))),
70
70
  items.length < 25 && total > items.length ? (React.createElement(MoreButton, { onClick: onExpandReferenceList, "data-cy": 'more-button' }, "Show more")) : undefined));
71
71
  };
@@ -19,16 +19,22 @@ import styled from 'styled-components';
19
19
  import { ReferenceSearchResults } from './ReferenceSearchResults';
20
20
  import { ReferenceSearchResultsPlaceholder } from './ReferenceSearchResultsPlaceholder';
21
21
  const SearchSourceLabel = styled(IconTextButton) `
22
- margin: ${(props) => props.theme.grid.unit * 2}px
23
- ${(props) => props.theme.grid.unit * 4}px
24
- ${(props) => props.theme.grid.unit * 2}px;
25
- color: ${(props) => props.theme.colors.text.secondary};
26
-
27
- &:hover {
28
- color: ${(props) => props.theme.colors.text.muted};
22
+ height: ${(props) => props.theme.grid.unit * 10}px;
23
+ background: #f2f2f2;
24
+ display: flex;
25
+ justify-content: flex-start;
26
+ padding: ${(props) => props.theme.grid.unit * 2}px;
27
+ svg {
28
+ margin-right: ${(props) => props.theme.grid.unit * 2}px;
29
29
  }
30
30
  `;
31
- export const ReferenceSearchSection = ({ query, source, isSelected, onSelect }) => {
31
+ const Container = styled.div `
32
+ display: flex;
33
+ flex-direction: column;
34
+ border-radius: 4px;
35
+ border: 1px solid #e2e2e2;
36
+ `;
37
+ export const ReferenceSearchSection = ({ query, source, documentCitationCounts, isSelected, onSelect }) => {
32
38
  const [expanded, setExpanded] = useState(true);
33
39
  const [state, setState] = useState();
34
40
  const [limit, setLimit] = useState(3);
@@ -61,10 +67,10 @@ export const ReferenceSearchSection = ({ query, source, isSelected, onSelect })
61
67
  const handleShowMore = () => {
62
68
  setLimit(25);
63
69
  };
64
- return (React.createElement(React.Fragment, null,
70
+ return (React.createElement(Container, null,
65
71
  React.createElement(SearchSourceLabel, { onClick: toggleExpanded },
66
72
  expanded ? (React.createElement(TriangleExpandedIcon, { className: 'icon' })) : (React.createElement(TriangleCollapsedIcon, { className: 'icon' })),
67
73
  source.label),
68
74
  expanded && state?.type === 'running' && (React.createElement(ReferenceSearchResultsPlaceholder, null)),
69
- expanded && state?.type === 'completed' && (React.createElement(ReferenceSearchResults, { items: state.items, total: state.total, isSelected: isSelected, onSelect: onSelect, onShowMore: handleShowMore }))));
75
+ expanded && state?.type === 'completed' && (React.createElement(ReferenceSearchResults, { items: state.items, total: state.total, documentCitationCounts: documentCitationCounts, isSelected: isSelected, onSelect: onSelect, onShowMore: handleShowMore }))));
70
76
  };
@@ -19,9 +19,7 @@ import styled from 'styled-components';
19
19
  const SearchContainer = styled.div `
20
20
  align-items: center;
21
21
  display: flex;
22
- flex: 1 0 auto;
23
22
  position: relative;
24
- margin: 12px;
25
23
  `;
26
24
  const SearchIconContainer = styled.span `
27
25
  display: flex;
@@ -45,11 +43,6 @@ const SearchTextField = styled(TextField) `
45
43
  background-color: ${(props) => props.theme.colors.background.fifth};
46
44
  }
47
45
  `;
48
- export const SearchWrapper = styled.div `
49
- display: flex;
50
- align-items: center;
51
- padding: ${(props) => props.theme.grid.unit * 3}px;
52
- `;
53
46
  export const SearchInput = (props) => {
54
47
  const [hover, setHover] = useState(false);
55
48
  const [focus, setFocus] = useState(false);
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.18.4';
1
+ export const VERSION = '3.18.6';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -109,6 +109,7 @@ export class CitationEditableView extends CitationView {
109
109
  onSave: this.handleSave,
110
110
  onDelete: this.handleDelete,
111
111
  onCancel: this.handleCancel,
112
+ isNodeDeleted: () => isDeleted(this.node),
112
113
  canEdit: can.editCitationsAndRefs,
113
114
  };
114
115
  this.editor = ReactSubView(this.props, CitationEditor, componentProps, this.node, this.getPos, this.view, ['citation-editor']);
@@ -12,6 +12,7 @@ export interface CitationEditorProps {
12
12
  onSave: (item: BibliographyItemAttrs[]) => void;
13
13
  onDelete: (item: BibliographyItemAttrs) => void;
14
14
  onCancel: () => void;
15
+ isNodeDeleted: () => boolean;
15
16
  canEdit: boolean;
16
17
  }
17
18
  export declare const CitationEditor: React.FC<CitationEditorProps>;
@@ -16,10 +16,11 @@
16
16
  import { BibliographyItemAttrs } from '@manuscripts/transform';
17
17
  import React from 'react';
18
18
  import { BibliographyItemSource } from './BibliographyItemSource';
19
- export declare const ReferenceSearch: React.FC<{
19
+ export declare const InsertCitationModal: React.FC<{
20
20
  query?: string;
21
21
  sources: BibliographyItemSource[];
22
22
  items: BibliographyItemAttrs[];
23
+ citationCounts: Map<string, number>;
23
24
  onAdd: () => void;
24
25
  onCite: (items: BibliographyItemAttrs[]) => void;
25
26
  onCancel: () => void;
@@ -38,6 +38,7 @@ export declare const ReferenceSearchResult: import("styled-components/dist/types
38
38
  export declare const ReferenceSearchResults: React.FC<{
39
39
  items: BibliographyItemAttrs[];
40
40
  total: number;
41
+ documentCitationCounts?: Map<string, number>;
41
42
  isSelected: (item: BibliographyItemAttrs) => boolean;
42
43
  onSelect: (item: BibliographyItemAttrs) => void;
43
44
  onShowMore: () => void;
@@ -19,6 +19,7 @@ import { BibliographyItemSource } from './BibliographyItemSource';
19
19
  export declare const ReferenceSearchSection: React.FC<{
20
20
  query: string;
21
21
  source: BibliographyItemSource;
22
+ documentCitationCounts?: Map<string, number>;
22
23
  isSelected: (item: BibliographyItemAttrs) => boolean;
23
24
  onSelect: (item: BibliographyItemAttrs) => void;
24
25
  }>;
@@ -14,5 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import React, { InputHTMLAttributes } from 'react';
17
- export declare const SearchWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never> & Partial<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>> & string;
18
17
  export declare const SearchInput: React.FC<InputHTMLAttributes<HTMLInputElement>>;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "3.18.4";
1
+ export declare const VERSION = "3.18.6";
2
2
  export declare const MATHJAX_VERSION = "3.2.2";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/body-editor",
3
3
  "description": "Prosemirror components for editing and viewing manuscripts",
4
- "version": "3.18.4",
4
+ "version": "3.18.6",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -41,9 +41,9 @@
41
41
  "@citation-js/plugin-pubmed": "0.3.0",
42
42
  "@citation-js/plugin-ris": "0.7.18",
43
43
  "@iarna/word-count": "1.1.2",
44
- "@manuscripts/style-guide": "3.7.3",
44
+ "@manuscripts/style-guide": "3.7.4",
45
45
  "@manuscripts/track-changes-plugin": "2.4.0",
46
- "@manuscripts/transform": "4.5.6",
46
+ "@manuscripts/transform": "4.5.7",
47
47
  "@popperjs/core": "2.11.8",
48
48
  "citeproc": "2.4.63",
49
49
  "codemirror": "5.65.19",