@manuscripts/body-editor 3.16.1 → 3.16.2
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.
- package/dist/cjs/components/references/CitationEditor.js +13 -19
- package/dist/cjs/components/references/ImportBibliography.js +77 -0
- package/dist/cjs/components/references/ImportBibliographyForm.js +1 -1
- package/dist/cjs/components/references/ImportBibliographyModal.js +12 -81
- package/dist/cjs/components/references/ImportReferencesConfirmation.js +113 -0
- package/dist/cjs/components/references/ImportSuccessPlaceholder.js +56 -0
- package/dist/cjs/components/references/ReferenceSearch.js +2 -5
- package/dist/cjs/components/references/ReferencesEditor.js +18 -2
- package/dist/cjs/components/references/ReferencesModal.js +86 -33
- package/dist/cjs/lib/view.js +39 -1
- package/dist/cjs/versions.js +1 -1
- package/dist/cjs/views/bibliography_element.js +1 -2
- package/dist/cjs/views/citation_editable.js +2 -29
- package/dist/es/components/references/CitationEditor.js +13 -19
- package/dist/es/components/references/ImportBibliography.js +70 -0
- package/dist/es/components/references/ImportBibliographyForm.js +1 -1
- package/dist/es/components/references/ImportBibliographyModal.js +13 -79
- package/dist/es/components/references/ImportReferencesConfirmation.js +73 -0
- package/dist/es/components/references/ImportSuccessPlaceholder.js +49 -0
- package/dist/es/components/references/ReferenceSearch.js +3 -6
- package/dist/es/components/references/ReferencesEditor.js +19 -3
- package/dist/es/components/references/ReferencesModal.js +88 -35
- package/dist/es/lib/view.js +36 -0
- package/dist/es/versions.js +1 -1
- package/dist/es/views/bibliography_element.js +2 -3
- package/dist/es/views/citation_editable.js +3 -30
- package/dist/types/components/references/CitationEditor.d.ts +1 -1
- package/dist/types/components/references/ImportBibliography.d.ts +7 -0
- package/dist/types/components/references/ImportReferencesConfirmation.d.ts +8 -0
- package/dist/types/components/references/ImportSuccessPlaceholder.d.ts +5 -0
- package/dist/types/components/references/ReferenceSearch.d.ts +0 -1
- package/dist/types/components/references/ReferencesEditor.d.ts +4 -1
- package/dist/types/components/references/ReferencesModal.d.ts +1 -0
- package/dist/types/lib/view.d.ts +3 -1
- package/dist/types/versions.d.ts +1 -1
- package/dist/types/views/citation_editable.d.ts +0 -1
- package/package.json +1 -1
- package/src/components/references/CitationEditor.tsx +16 -25
- package/src/components/references/ImportBibliography.tsx +119 -0
- package/src/components/references/ImportBibliographyForm.tsx +1 -1
- package/src/components/references/ImportBibliographyModal.tsx +34 -110
- package/src/components/references/ImportReferencesConfirmation.tsx +133 -0
- package/src/components/references/ImportSuccessPlaceholder.tsx +93 -0
- package/src/components/references/ReferenceSearch.tsx +0 -7
- package/src/components/references/ReferencesEditor.tsx +35 -6
- package/src/components/references/ReferencesModal.tsx +164 -78
- package/src/lib/view.ts +65 -0
- package/src/versions.ts +1 -1
- package/src/views/bibliography_element.ts +3 -4
- package/src/views/citation_editable.ts +5 -50
|
@@ -43,6 +43,8 @@ const react_1 = __importStar(require("react"));
|
|
|
43
43
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
44
44
|
const ReferenceForm_1 = require("./ReferenceForm/ReferenceForm");
|
|
45
45
|
const ReferenceLine_1 = require("./ReferenceLine");
|
|
46
|
+
const ImportBibliographyModal_1 = require("./ImportBibliographyModal");
|
|
47
|
+
const ImportSuccessPlaceholder_1 = require("./ImportSuccessPlaceholder");
|
|
46
48
|
const ReferencesModalContainer = (0, styled_components_1.default)(style_guide_1.ModalContainer) `
|
|
47
49
|
min-width: 960px;
|
|
48
50
|
`;
|
|
@@ -52,6 +54,33 @@ const ReferencesSidebar = (0, styled_components_1.default)(style_guide_1.ModalSi
|
|
|
52
54
|
const ReferencesSidebarContent = (0, styled_components_1.default)(style_guide_1.SidebarContent) `
|
|
53
55
|
overflow-y: auto;
|
|
54
56
|
`;
|
|
57
|
+
const ImportFromFileFooter = styled_components_1.default.div `
|
|
58
|
+
padding: 16px;
|
|
59
|
+
`;
|
|
60
|
+
const ImportFromFileButton = styled_components_1.default.button `
|
|
61
|
+
display: flex;
|
|
62
|
+
width: 100%;
|
|
63
|
+
padding: 8px 24px;
|
|
64
|
+
justify-content: center;
|
|
65
|
+
align-items: center;
|
|
66
|
+
gap: 8px;
|
|
67
|
+
border-radius: 4px;
|
|
68
|
+
border: 1px dashed #c9c9c9;
|
|
69
|
+
background: #fafafa;
|
|
70
|
+
cursor: pointer;
|
|
71
|
+
font-family: ${(props) => props.theme.font.family.sans};
|
|
72
|
+
font-size: 14px;
|
|
73
|
+
color: #353535;
|
|
74
|
+
|
|
75
|
+
svg {
|
|
76
|
+
width: 20px;
|
|
77
|
+
height: 20px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
svg rect {
|
|
81
|
+
fill: #6e6e6e;
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
55
84
|
const ReferencesInnerWrapper = (0, style_guide_1.withListNavigation)(styled_components_1.default.div `
|
|
56
85
|
width: 100%;
|
|
57
86
|
padding: 12px 0;
|
|
@@ -139,15 +168,25 @@ const normalize = (item) => ({
|
|
|
139
168
|
accessed: item.accessed,
|
|
140
169
|
comment: item.comment || '',
|
|
141
170
|
});
|
|
142
|
-
const ReferencesModal = ({ isOpen, onCancel, items, item, citationCounts, onSave, onDelete, }) => {
|
|
171
|
+
const ReferencesModal = ({ isOpen, onCancel, items, item, citationCounts, onSave, onDelete, handleImport, }) => {
|
|
172
|
+
const [importing, setImporting] = (0, react_1.useState)(false);
|
|
173
|
+
const [importSuccessCount, setImportSuccessCount] = (0, react_1.useState)(null);
|
|
143
174
|
const [confirm, setConfirm] = (0, react_1.useState)(false);
|
|
144
175
|
const valuesRef = (0, react_1.useRef)(undefined);
|
|
145
176
|
const [selection, setSelection] = (0, react_1.useState)();
|
|
146
177
|
const selectionRef = (0, react_1.useRef)(null);
|
|
178
|
+
const sortedItems = (0, react_1.useMemo)(() => [...items].sort((a, b) => {
|
|
179
|
+
const aUncited = (citationCounts.get(a.id) ?? 0) === 0;
|
|
180
|
+
const bUncited = (citationCounts.get(b.id) ?? 0) === 0;
|
|
181
|
+
if (aUncited === bUncited) {
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
return aUncited ? 1 : -1;
|
|
185
|
+
}), [items, citationCounts]);
|
|
147
186
|
const isSelected = (item) => {
|
|
148
187
|
return item.id === selection?.id;
|
|
149
188
|
};
|
|
150
|
-
const selectionIndex =
|
|
189
|
+
const selectionIndex = sortedItems.findIndex(isSelected);
|
|
151
190
|
(0, react_1.useEffect)(() => {
|
|
152
191
|
setSelection(item);
|
|
153
192
|
}, [item]);
|
|
@@ -165,8 +204,8 @@ const ReferencesModal = ({ isOpen, onCancel, items, item, citationCounts, onSave
|
|
|
165
204
|
(0, react_1.useEffect)(() => {
|
|
166
205
|
const base = Math.max(0, selectionIndex - selectionTopOffset);
|
|
167
206
|
setStartIndex(base);
|
|
168
|
-
setEndIndex(Math.min(
|
|
169
|
-
}, [selectionIndex,
|
|
207
|
+
setEndIndex(Math.min(sortedItems.length - 1, base + pageSize));
|
|
208
|
+
}, [selectionIndex, sortedItems]);
|
|
170
209
|
(0, react_1.useEffect)(() => {
|
|
171
210
|
if (triggers.top) {
|
|
172
211
|
const newFirst = Math.max(0, startIndex - pageSize);
|
|
@@ -174,11 +213,11 @@ const ReferencesModal = ({ isOpen, onCancel, items, item, citationCounts, onSave
|
|
|
174
213
|
setEndIndex(Math.min(newFirst + dropLimit, endIndex));
|
|
175
214
|
}
|
|
176
215
|
if (triggers.bottom) {
|
|
177
|
-
const newLast = Math.min(
|
|
216
|
+
const newLast = Math.min(sortedItems.length - 1, endIndex + pageSize);
|
|
178
217
|
setEndIndex(newLast);
|
|
179
218
|
setStartIndex(Math.max(newLast - dropLimit, startIndex));
|
|
180
219
|
}
|
|
181
|
-
}, [triggers,
|
|
220
|
+
}, [triggers, sortedItems]);
|
|
182
221
|
const actionsRef = (0, react_1.useRef)(undefined);
|
|
183
222
|
const reset = () => {
|
|
184
223
|
actionsRef.current?.reset();
|
|
@@ -212,7 +251,9 @@ const ReferencesModal = ({ isOpen, onCancel, items, item, citationCounts, onSave
|
|
|
212
251
|
onDelete(selection);
|
|
213
252
|
setSelection(undefined);
|
|
214
253
|
};
|
|
254
|
+
const clearImportSuccess = () => setImportSuccessCount(null);
|
|
215
255
|
const handleItemClick = (item) => {
|
|
256
|
+
clearImportSuccess();
|
|
216
257
|
const values = valuesRef.current;
|
|
217
258
|
if (values && selection && !(0, isEqual_1.default)(values, normalize(selection))) {
|
|
218
259
|
setConfirm(true);
|
|
@@ -223,34 +264,46 @@ const ReferencesModal = ({ isOpen, onCancel, items, item, citationCounts, onSave
|
|
|
223
264
|
const handleChange = (values) => {
|
|
224
265
|
valuesRef.current = values;
|
|
225
266
|
};
|
|
226
|
-
|
|
267
|
+
const handleImportSave = (data) => {
|
|
268
|
+
handleImport(data);
|
|
269
|
+
setImporting(false);
|
|
270
|
+
setSelection(undefined);
|
|
271
|
+
setImportSuccessCount(data.length);
|
|
272
|
+
};
|
|
273
|
+
if (sortedItems.length <= 0) {
|
|
227
274
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
228
275
|
}
|
|
229
|
-
return (react_1.default.createElement(
|
|
230
|
-
react_1.default.createElement(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
276
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
277
|
+
importing && (react_1.default.createElement(ImportBibliographyModal_1.ImportBibliographyModal, { onCancel: () => setImporting(false), onSave: handleImportSave })),
|
|
278
|
+
react_1.default.createElement(style_guide_1.StyledModal, { isOpen: isOpen, onRequestClose: onCancel },
|
|
279
|
+
react_1.default.createElement(style_guide_1.Dialog, { isOpen: confirm, category: style_guide_1.Category.confirmation, header: "You've made changes to this option", message: "Would you like to save or discard your changes?", actions: {
|
|
280
|
+
secondary: {
|
|
281
|
+
action: () => reset(),
|
|
282
|
+
title: 'Discard',
|
|
283
|
+
},
|
|
284
|
+
primary: {
|
|
285
|
+
action: () => handleSave(valuesRef.current),
|
|
286
|
+
title: 'Save',
|
|
287
|
+
},
|
|
288
|
+
} }),
|
|
289
|
+
react_1.default.createElement(ReferencesModalContainer, { "data-cy": 'references-editor' },
|
|
290
|
+
react_1.default.createElement(style_guide_1.ModalHeader, null,
|
|
291
|
+
react_1.default.createElement(style_guide_1.CloseButton, { "data-cy": "modal-close-button", onClick: onCancel })),
|
|
292
|
+
react_1.default.createElement(style_guide_1.ModalBody, null,
|
|
293
|
+
react_1.default.createElement(ReferencesSidebar, null,
|
|
294
|
+
react_1.default.createElement(style_guide_1.ModalSidebarHeader, null,
|
|
295
|
+
react_1.default.createElement(style_guide_1.ModalSidebarTitle, null, "References")),
|
|
296
|
+
react_1.default.createElement(ReferencesSidebarContent, { ref: ref },
|
|
297
|
+
react_1.default.createElement(ReferencesInnerWrapper, null, sortedItems.slice(startIndex, endIndex + 1).map((item) => (react_1.default.createElement(ReferenceButton, { key: item.id, id: item.id, className: isSelected(item) ? 'selected' : '', onClick: () => handleItemClick(item), ref: isSelected(item) ? selectionRef : null },
|
|
298
|
+
react_1.default.createElement(IconContainer, null,
|
|
299
|
+
react_1.default.createElement(style_guide_1.CitationCountIcon, null),
|
|
300
|
+
(citationCounts.get(item.id) || 0) > 0 ? (react_1.default.createElement(CitationCount, { "data-tooltip-content": "Number of times used in the document" }, citationCounts.get(item.id))) : (react_1.default.createElement(CitationCount, { className: "unused" }, "0"))),
|
|
301
|
+
react_1.default.createElement(ReferenceLine_1.ReferenceLine, { item: item })))))),
|
|
302
|
+
react_1.default.createElement(ImportFromFileFooter, null,
|
|
303
|
+
react_1.default.createElement(ImportFromFileButton, { type: "button", "data-cy": "import-from-file-button", onClick: () => setImporting(true) },
|
|
304
|
+
react_1.default.createElement(style_guide_1.AddAuthorIcon, null),
|
|
305
|
+
"Import from file"))),
|
|
306
|
+
react_1.default.createElement(style_guide_1.ScrollableModalContent, null, importSuccessCount !== null ? (react_1.default.createElement(ImportSuccessPlaceholder_1.ImportSuccessPlaceholder, { count: importSuccessCount })) : (selection && (react_1.default.createElement(ReferenceForm_1.ReferenceForm, { values: normalize(selection), showDelete: !citationCounts.get(selection.id) &&
|
|
307
|
+
isNewItem(selection, ['id', 'type']), onChange: handleChange, onCancel: onCancel, onDelete: handleDelete, onSave: handleSave, actionsRef: actionsRef })))))))));
|
|
255
308
|
};
|
|
256
309
|
exports.ReferencesModal = ReferencesModal;
|
package/dist/cjs/lib/view.js
CHANGED
|
@@ -48,7 +48,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
48
48
|
};
|
|
49
49
|
})();
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.deleteNode = exports.updateNodeAttrs = exports.findChildrenAttrsByType = exports.findChildrenByType = exports.findChildByType = exports.findChildByID = void 0;
|
|
51
|
+
exports.saveBibliographyItem = exports.insertBibliographyItems = exports.deleteNode = exports.updateNodeAttrs = exports.findChildrenAttrsByType = exports.findChildrenByType = exports.findChildByType = exports.findChildByID = void 0;
|
|
52
52
|
const transform_1 = require("@manuscripts/transform");
|
|
53
53
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
54
54
|
const utils = __importStar(require("prosemirror-utils"));
|
|
@@ -106,3 +106,41 @@ const deleteNode = (view, id) => {
|
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
exports.deleteNode = deleteNode;
|
|
109
|
+
const createBibliographySection = (nodes) => transform_1.schema.nodes.bibliography_section.createAndFill({}, [
|
|
110
|
+
transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('References')),
|
|
111
|
+
transform_1.schema.nodes.bibliography_element.create({}, nodes),
|
|
112
|
+
]);
|
|
113
|
+
const insertBibliographyItems = (view, items) => {
|
|
114
|
+
const { doc } = view.state;
|
|
115
|
+
let tr = view.state.tr;
|
|
116
|
+
const biblioSection = utils.findChildrenByType(doc, transform_1.schema.nodes.bibliography_element, true);
|
|
117
|
+
if (biblioSection.length) {
|
|
118
|
+
let insertPos = biblioSection[0].pos + 1;
|
|
119
|
+
for (const attrs of items) {
|
|
120
|
+
const node = transform_1.schema.nodes.bibliography_item.create(attrs);
|
|
121
|
+
tr = tr.insert(insertPos, node);
|
|
122
|
+
insertPos += node.nodeSize;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const backmatter = utils.findChildrenByType(doc, transform_1.schema.nodes.backmatter, true);
|
|
127
|
+
const backmatterEnd = backmatter[0]
|
|
128
|
+
? backmatter[0].node.nodeSize + backmatter[0].pos
|
|
129
|
+
: 0;
|
|
130
|
+
const nodes = items.map((attrs) => transform_1.schema.nodes.bibliography_item.create(attrs));
|
|
131
|
+
tr = tr.insert(backmatterEnd ? backmatterEnd - 1 : tr.doc.content.size, createBibliographySection(nodes));
|
|
132
|
+
}
|
|
133
|
+
view.dispatch(tr);
|
|
134
|
+
};
|
|
135
|
+
exports.insertBibliographyItems = insertBibliographyItems;
|
|
136
|
+
const saveBibliographyItem = (view, attrs) => {
|
|
137
|
+
if (attrs.length === 1) {
|
|
138
|
+
const item = attrs[0];
|
|
139
|
+
if ((0, exports.findChildByID)(view, item.id)) {
|
|
140
|
+
(0, exports.updateNodeAttrs)(view, transform_1.schema.nodes.bibliography_item, item);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
(0, exports.insertBibliographyItems)(view, attrs);
|
|
145
|
+
};
|
|
146
|
+
exports.saveBibliographyItem = saveBibliographyItem;
|
package/dist/cjs/versions.js
CHANGED
|
@@ -20,7 +20,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.BibliographyElementBlockView = void 0;
|
|
22
22
|
const style_guide_1 = require("@manuscripts/style-guide");
|
|
23
|
-
const transform_1 = require("@manuscripts/transform");
|
|
24
23
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
25
24
|
const ReferencesEditor_1 = require("../components/references/ReferencesEditor");
|
|
26
25
|
const comments_1 = require("../lib/comments");
|
|
@@ -92,7 +91,7 @@ class BibliographyElementBlockView extends block_view_1.default {
|
|
|
92
91
|
this.dom.appendChild(this.container);
|
|
93
92
|
};
|
|
94
93
|
this.handleSave = (attrs) => {
|
|
95
|
-
(0, view_1.
|
|
94
|
+
(0, view_1.saveBibliographyItem)(this.view, attrs);
|
|
96
95
|
};
|
|
97
96
|
this.handleDelete = (item) => {
|
|
98
97
|
(0, view_1.deleteNode)(this.view, item.id);
|
|
@@ -21,9 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
exports.CitationEditableView = void 0;
|
|
22
22
|
const style_guide_1 = require("@manuscripts/style-guide");
|
|
23
23
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
24
|
-
const transform_1 = require("@manuscripts/transform");
|
|
25
24
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
26
|
-
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
27
25
|
const CitationEditor_1 = require("../components/references/CitationEditor");
|
|
28
26
|
const CitationViewer_1 = require("../components/references/CitationViewer");
|
|
29
27
|
const comments_1 = require("../lib/comments");
|
|
@@ -34,10 +32,6 @@ const bibliography_1 = require("../plugins/bibliography");
|
|
|
34
32
|
const citation_1 = require("./citation");
|
|
35
33
|
const creators_1 = require("./creators");
|
|
36
34
|
const ReactSubView_1 = __importDefault(require("./ReactSubView"));
|
|
37
|
-
const createBibliographySection = (node) => transform_1.schema.nodes.bibliography_section.createAndFill({}, [
|
|
38
|
-
transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('References')),
|
|
39
|
-
transform_1.schema.nodes.bibliography_element.create({}, node ? [node] : []),
|
|
40
|
-
]);
|
|
41
35
|
class CitationEditableView extends citation_1.CitationView {
|
|
42
36
|
constructor() {
|
|
43
37
|
super(...arguments);
|
|
@@ -143,12 +137,7 @@ class CitationEditableView extends citation_1.CitationView {
|
|
|
143
137
|
this.props.popper.destroy();
|
|
144
138
|
};
|
|
145
139
|
this.handleSave = (attrs) => {
|
|
146
|
-
|
|
147
|
-
this.insertBibliographyNode(attrs);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
(0, view_1.updateNodeAttrs)(this.view, transform_1.schema.nodes.bibliography_item, attrs);
|
|
151
|
-
}
|
|
140
|
+
(0, view_1.saveBibliographyItem)(this.view, attrs);
|
|
152
141
|
};
|
|
153
142
|
this.handleUncite = (id) => {
|
|
154
143
|
const attrs = this.node.attrs;
|
|
@@ -181,7 +170,7 @@ class CitationEditableView extends citation_1.CitationView {
|
|
|
181
170
|
item.id = existingItem.id;
|
|
182
171
|
}
|
|
183
172
|
else {
|
|
184
|
-
this.
|
|
173
|
+
(0, view_1.saveBibliographyItem)(this.view, [item]);
|
|
185
174
|
}
|
|
186
175
|
rids.push(item.id);
|
|
187
176
|
}
|
|
@@ -200,22 +189,6 @@ class CitationEditableView extends citation_1.CitationView {
|
|
|
200
189
|
this.dom.addEventListener('mouseup', () => this.handleClick(false));
|
|
201
190
|
this.dom.addEventListener('keydown', (0, navigation_utils_1.handleEnterKey)(() => this.handleClick(true)));
|
|
202
191
|
}
|
|
203
|
-
insertBibliographyNode(attrs) {
|
|
204
|
-
const { doc, tr } = this.view.state;
|
|
205
|
-
const biblioSection = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.bibliography_element, true);
|
|
206
|
-
const backmatter = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.backmatter, true);
|
|
207
|
-
const backmatterEnd = backmatter[0]
|
|
208
|
-
? backmatter[0].node.nodeSize + backmatter[0].pos
|
|
209
|
-
: 0;
|
|
210
|
-
const node = transform_1.schema.nodes.bibliography_item.create(attrs);
|
|
211
|
-
if (biblioSection.length) {
|
|
212
|
-
this.view.dispatch(tr.insert(biblioSection[0].pos + 1, node));
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
this.view.dispatch(tr.insert(backmatterEnd ? backmatterEnd - 1 : tr.doc.content.size, createBibliographySection(node)));
|
|
216
|
-
}
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
192
|
}
|
|
220
193
|
exports.CitationEditableView = CitationEditableView;
|
|
221
194
|
exports.default = (0, creators_1.createEditableNodeView)(CitationEditableView);
|
|
@@ -5,7 +5,6 @@ import styled from 'styled-components';
|
|
|
5
5
|
import { arrayReducer, attrsReducer } from '../../lib/array-reducer';
|
|
6
6
|
import { cleanItemValues } from '../../lib/utils';
|
|
7
7
|
import { CitedItem, CitedItems } from './CitationViewer';
|
|
8
|
-
import { ImportBibliographyModal } from './ImportBibliographyModal';
|
|
9
8
|
import { ReferenceLine } from './ReferenceLine';
|
|
10
9
|
import { ReferenceSearch } from './ReferenceSearch';
|
|
11
10
|
import { ReferencesModal } from './ReferencesModal';
|
|
@@ -55,7 +54,7 @@ export const CitationEditor = ({ query, rids: $rids, items: $items, citationCoun
|
|
|
55
54
|
const [rids, dispatchRids] = useReducer(ridsReducer, $rids);
|
|
56
55
|
const handleSave = (item) => {
|
|
57
56
|
const cleanedItem = cleanItemValues(item);
|
|
58
|
-
onSave(cleanedItem);
|
|
57
|
+
onSave([cleanedItem]);
|
|
59
58
|
dispatchItems({
|
|
60
59
|
type: 'update',
|
|
61
60
|
items: [cleanedItem],
|
|
@@ -90,7 +89,6 @@ export const CitationEditor = ({ query, rids: $rids, items: $items, citationCoun
|
|
|
90
89
|
show: false,
|
|
91
90
|
});
|
|
92
91
|
const [searching, setSearching] = useState(false);
|
|
93
|
-
const [importing, setImporting] = useState(false);
|
|
94
92
|
const handleAdd = () => {
|
|
95
93
|
setSearching(false);
|
|
96
94
|
const item = {
|
|
@@ -103,35 +101,31 @@ export const CitationEditor = ({ query, rids: $rids, items: $items, citationCoun
|
|
|
103
101
|
});
|
|
104
102
|
setEditingForm({ show: true, item: item });
|
|
105
103
|
};
|
|
106
|
-
const handleImport = () => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
handleCite([newItem]);
|
|
104
|
+
const handleImport = (data) => {
|
|
105
|
+
const newItems = data.map((item) => cleanItemValues({
|
|
106
|
+
...item,
|
|
107
|
+
id: generateNodeID(schema.nodes.bibliography_item),
|
|
108
|
+
}));
|
|
109
|
+
onSave(newItems);
|
|
110
|
+
dispatchItems({
|
|
111
|
+
type: 'set',
|
|
112
|
+
state: [...items, ...newItems],
|
|
116
113
|
});
|
|
117
114
|
};
|
|
118
115
|
const cited = useMemo(() => {
|
|
119
116
|
return rids.flatMap((rid) => items.filter((i) => i.id === rid));
|
|
120
117
|
}, [rids, items]);
|
|
121
118
|
if (editingForm.show) {
|
|
122
|
-
return (React.createElement(ReferencesModal, { isOpen: editingForm.show, onCancel: () => setEditingForm({ show: false }), items: items, citationCounts: citationCounts, item: editingForm.item, onSave: handleSave, onDelete: handleDelete }));
|
|
123
|
-
}
|
|
124
|
-
if (importing) {
|
|
125
|
-
return (React.createElement(ImportBibliographyModal, { onCancel: () => setImporting(false), onSave: handleSaveImport }));
|
|
119
|
+
return (React.createElement(ReferencesModal, { isOpen: editingForm.show, onCancel: () => setEditingForm({ show: false }), items: items, citationCounts: citationCounts, item: editingForm.item, onSave: handleSave, onDelete: handleDelete, handleImport: handleImport }));
|
|
126
120
|
}
|
|
127
121
|
if (searching) {
|
|
128
|
-
return (React.createElement(ReferenceSearch, { sources: sources, items: items, onAdd: handleAdd,
|
|
122
|
+
return (React.createElement(ReferenceSearch, { sources: sources, items: items, onAdd: handleAdd, onCite: (items) => {
|
|
129
123
|
setSearching(false);
|
|
130
124
|
handleCite(items);
|
|
131
125
|
}, onCancel: () => setSearching(false) }));
|
|
132
126
|
}
|
|
133
127
|
if (!rids.length) {
|
|
134
|
-
return (React.createElement(ReferenceSearch, { query: query, sources: sources, items: items, onAdd: handleAdd,
|
|
128
|
+
return (React.createElement(ReferenceSearch, { query: query, sources: sources, items: items, onAdd: handleAdd, onCite: handleCite, onCancel: onCancel }));
|
|
135
129
|
}
|
|
136
130
|
return (React.createElement(Container, null,
|
|
137
131
|
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,70 @@
|
|
|
1
|
+
import { ModalTitle, Tooltip } from '@manuscripts/style-guide';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { ImportBibliographyForm } from './ImportBibliographyForm';
|
|
5
|
+
const exampleBibtex = `@book{abramowitz+stegun,
|
|
6
|
+
author = "Milton {Abramowitz} and Irene A. {Stegun}",
|
|
7
|
+
title = "Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables",
|
|
8
|
+
publisher = "Dover",
|
|
9
|
+
year = 1964,
|
|
10
|
+
address = "New York City",
|
|
11
|
+
edition = "ninth Dover printing, tenth GPO printing"
|
|
12
|
+
}`;
|
|
13
|
+
const examplePubmed = `Example Identifiers:
|
|
14
|
+
pmid:17170128
|
|
15
|
+
PMC1852221`;
|
|
16
|
+
const exampleRis = `TY - JOUR
|
|
17
|
+
AU - Shannon, Claude E.
|
|
18
|
+
PY - 1948
|
|
19
|
+
DA - July
|
|
20
|
+
TI - A Mathematical Theory of Communication
|
|
21
|
+
T2 - Bell System Technical Journal
|
|
22
|
+
SP - 379
|
|
23
|
+
EP - 423
|
|
24
|
+
VL - 27
|
|
25
|
+
ER - `;
|
|
26
|
+
const exampleEnw = `%0 Journal Article
|
|
27
|
+
%D 2018
|
|
28
|
+
%@ 0903-4641
|
|
29
|
+
%A Abbassi-Daloii, Tooba
|
|
30
|
+
%A Yousefi, Soheil
|
|
31
|
+
%A Sekhavati, Mohammad Hadi
|
|
32
|
+
%A Tahmoorespur, Mojtaba
|
|
33
|
+
%J APMIS
|
|
34
|
+
%N 1
|
|
35
|
+
%P 65-75
|
|
36
|
+
%T Impact of heat shock protein 60KD in combination with outer membrane proteins on immune response against Brucella melitensis
|
|
37
|
+
%R https://doi.org/10.1111/apm.12778
|
|
38
|
+
%U https://onlinelibrary.wiley.com/doi/abs/10.1111/apm.12778
|
|
39
|
+
%V 126
|
|
40
|
+
%X Lorem ipsum dolor sit amet`;
|
|
41
|
+
const exampleDoi = `Example DOI Identifiers:
|
|
42
|
+
10.1080/15588742.2015.1017684
|
|
43
|
+
http://dx.doi.org/10.1080/15588742.2015.1017684`;
|
|
44
|
+
const supportedFormats = [
|
|
45
|
+
{ label: 'BibTex', example: exampleBibtex },
|
|
46
|
+
{ label: 'PubMed', example: examplePubmed },
|
|
47
|
+
{ label: 'RIS', example: exampleRis },
|
|
48
|
+
{ label: 'ENW', example: exampleEnw },
|
|
49
|
+
{ label: 'DOI', example: exampleDoi },
|
|
50
|
+
];
|
|
51
|
+
export const ImportBibliography = ({ onCancel, onContinue, }) => (React.createElement(React.Fragment, null,
|
|
52
|
+
React.createElement(ModalTitle, null, "Import Bibliography"),
|
|
53
|
+
React.createElement("p", null,
|
|
54
|
+
supportedFormats.map(({ label, example }, index) => (React.createElement(React.Fragment, { key: label },
|
|
55
|
+
index > 0 &&
|
|
56
|
+
(index === supportedFormats.length - 1 ? ' and ' : ', '),
|
|
57
|
+
React.createElement(SpanWithExample, { "data-tooltip-id": "import-example-tooltip", "data-tooltip-content": example }, label)))),
|
|
58
|
+
' ',
|
|
59
|
+
"formats are supported"),
|
|
60
|
+
React.createElement(ImportBibliographyForm, { onCancel: onCancel, onSave: onContinue }),
|
|
61
|
+
React.createElement(Example, { id: "import-example-tooltip", place: "bottom", render: (s) => React.createElement("pre", null, s.content) })));
|
|
62
|
+
const SpanWithExample = styled.span `
|
|
63
|
+
text-decoration: underline dotted;
|
|
64
|
+
text-underline-offset: 4px;
|
|
65
|
+
`;
|
|
66
|
+
const Example = styled(Tooltip) `
|
|
67
|
+
text-align: left !important;
|
|
68
|
+
max-width: 480px !important;
|
|
69
|
+
overflow: hidden !important;
|
|
70
|
+
`;
|
|
@@ -103,7 +103,7 @@ export const ImportBibliographyForm = ({ onCancel, onSave, }) => {
|
|
|
103
103
|
formik.values.data.map((item) => (React.createElement(ReferenceLine, { item: item, key: item.id })))),
|
|
104
104
|
React.createElement(FormActionsBar, null,
|
|
105
105
|
React.createElement(SecondaryButton, { type: "reset" }, "Cancel"),
|
|
106
|
-
React.createElement(PrimaryButton, { type: "submit", disabled: !formik.dirty || formik.isSubmitting || !formik.values.data.length }, "
|
|
106
|
+
React.createElement(PrimaryButton, { type: "submit", disabled: !formik.dirty || formik.isSubmitting || !formik.values.data.length }, "Import References"))));
|
|
107
107
|
};
|
|
108
108
|
const Preview = styled.div `
|
|
109
109
|
display: flex;
|
|
@@ -1,88 +1,22 @@
|
|
|
1
|
-
import { CloseButton, ModalCardBody, ModalContainer, ModalHeader,
|
|
1
|
+
import { CloseButton, ModalCardBody, ModalContainer, ModalHeader, StyledModal, } from '@manuscripts/style-guide';
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
const exampleBibtex = `@book{abramowitz+stegun,
|
|
6
|
-
author = "Milton {Abramowitz} and Irene A. {Stegun}",
|
|
7
|
-
title = "Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables",
|
|
8
|
-
publisher = "Dover",
|
|
9
|
-
year = 1964,
|
|
10
|
-
address = "New York City",
|
|
11
|
-
edition = "ninth Dover printing, tenth GPO printing"
|
|
12
|
-
}`;
|
|
13
|
-
const examplePubmed = `Example Identifiers:
|
|
14
|
-
pmid:17170128
|
|
15
|
-
PMC1852221`;
|
|
16
|
-
const exampleRis = `TY - JOUR
|
|
17
|
-
AU - Shannon, Claude E.
|
|
18
|
-
PY - 1948
|
|
19
|
-
DA - July
|
|
20
|
-
TI - A Mathematical Theory of Communication
|
|
21
|
-
T2 - Bell System Technical Journal
|
|
22
|
-
SP - 379
|
|
23
|
-
EP - 423
|
|
24
|
-
VL - 27
|
|
25
|
-
ER - `;
|
|
26
|
-
const exampleEnw = `%0 Journal Article
|
|
27
|
-
%D 2018
|
|
28
|
-
%@ 0903-4641
|
|
29
|
-
%A Abbassi-Daloii, Tooba
|
|
30
|
-
%A Yousefi, Soheil
|
|
31
|
-
%A Sekhavati, Mohammad Hadi
|
|
32
|
-
%A Tahmoorespur, Mojtaba
|
|
33
|
-
%J APMIS
|
|
34
|
-
%N 1
|
|
35
|
-
%P 65-75
|
|
36
|
-
%T Impact of heat shock protein 60KD in combination with outer membrane proteins on immune response against Brucella melitensis
|
|
37
|
-
%R https://doi.org/10.1111/apm.12778
|
|
38
|
-
%U https://onlinelibrary.wiley.com/doi/abs/10.1111/apm.12778
|
|
39
|
-
%V 126
|
|
40
|
-
%X Lorem ipsum dolor sit amet`;
|
|
41
|
-
const exampleDoi = `Example DOI Identifiers:
|
|
42
|
-
10.1080/15588742.2015.1017684
|
|
43
|
-
http://dx.doi.org/10.1080/15588742.2015.1017684`;
|
|
3
|
+
import { ImportBibliography } from './ImportBibliography';
|
|
4
|
+
import { ImportReferencesConfirmation } from './ImportReferencesConfirmation';
|
|
44
5
|
export const ImportBibliographyModal = ({ onCancel, onSave }) => {
|
|
45
6
|
const [isOpen, setOpen] = useState(true);
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
};
|
|
7
|
+
const [pendingItems, setPendingItems] = useState(null);
|
|
8
|
+
const isConfirming = pendingItems !== null;
|
|
49
9
|
const handleClose = () => setOpen(false);
|
|
50
|
-
const
|
|
51
|
-
|
|
10
|
+
const handleBack = () => setPendingItems(null);
|
|
11
|
+
const handleConfirm = (items) => {
|
|
12
|
+
onSave(items);
|
|
52
13
|
handleClose();
|
|
53
14
|
};
|
|
54
15
|
return (React.createElement(StyledModal, { isOpen: isOpen, onRequestClose: onCancel },
|
|
55
|
-
React.createElement(ModalContainer, { "data-cy":
|
|
16
|
+
React.createElement(ModalContainer, { "data-cy": isConfirming
|
|
17
|
+
? 'import-confirmation-modal'
|
|
18
|
+
: 'import-bibliography-modal' },
|
|
56
19
|
React.createElement(ModalHeader, null,
|
|
57
|
-
React.createElement(CloseButton, { onClick: onCancel, "data-cy": "modal-close-button" })),
|
|
58
|
-
React.createElement(ModalCardBody, { "$width":
|
|
59
|
-
React.createElement(ModalTitle, null, "Import Bibliography"),
|
|
60
|
-
React.createElement("p", null,
|
|
61
|
-
React.createElement(SpanWithExample, { "data-tooltip-id": "import-example-tooltip", "data-tooltip-content": exampleBibtex }, "BibTex"),
|
|
62
|
-
",",
|
|
63
|
-
' ',
|
|
64
|
-
React.createElement(SpanWithExample, { "data-tooltip-id": "import-example-tooltip", "data-tooltip-content": examplePubmed }, "PubMed"),
|
|
65
|
-
",",
|
|
66
|
-
' ',
|
|
67
|
-
React.createElement(SpanWithExample, { "data-tooltip-id": "import-example-tooltip", "data-tooltip-content": exampleRis }, "RIS"),
|
|
68
|
-
",",
|
|
69
|
-
' ',
|
|
70
|
-
React.createElement(SpanWithExample, { "data-tooltip-id": "import-example-tooltip", "data-tooltip-content": exampleEnw }, "ENW"),
|
|
71
|
-
' ',
|
|
72
|
-
"and",
|
|
73
|
-
' ',
|
|
74
|
-
React.createElement(SpanWithExample, { "data-tooltip-id": "import-example-tooltip", "data-tooltip-content": exampleDoi }, "DOI"),
|
|
75
|
-
' ',
|
|
76
|
-
"formats are supported"),
|
|
77
|
-
React.createElement(ImportBibliographyForm, { onCancel: handleCancel, onSave: handleSave }),
|
|
78
|
-
React.createElement(Example, { id: "import-example-tooltip", place: "bottom", render: (s) => React.createElement("pre", null, s.content) })))));
|
|
20
|
+
React.createElement(CloseButton, { onClick: isConfirming ? handleBack : onCancel, "data-cy": "modal-close-button" })),
|
|
21
|
+
React.createElement(ModalCardBody, { "$width": 724 }, pendingItems ? (React.createElement(ImportReferencesConfirmation, { items: pendingItems, onCancel: handleBack, onConfirm: handleConfirm })) : (React.createElement(ImportBibliography, { onCancel: onCancel, onContinue: setPendingItems }))))));
|
|
79
22
|
};
|
|
80
|
-
const SpanWithExample = styled.span `
|
|
81
|
-
text-decoration: underline dotted;
|
|
82
|
-
text-underline-offset: 4px;
|
|
83
|
-
`;
|
|
84
|
-
const Example = styled(Tooltip) `
|
|
85
|
-
text-align: left !important;
|
|
86
|
-
max-width: 480px !important;
|
|
87
|
-
overflow: hidden !important;
|
|
88
|
-
`;
|