@manuscripts/body-editor 1.5.2 → 1.5.4-LEAN-2926-0

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 (78) hide show
  1. package/dist/cjs/commands.js +2 -8
  2. package/dist/cjs/components/outline/DraggableTree.js +31 -28
  3. package/dist/cjs/components/outline/ManuscriptOutline.js +2 -13
  4. package/dist/cjs/components/outline/OutlineManuscript.js +2 -9
  5. package/dist/cjs/configs/editor-views.js +4 -0
  6. package/dist/cjs/lib/utils.js +3 -3
  7. package/dist/cjs/node-type-icons.js +1 -4
  8. package/dist/cjs/plugins/bibliography/bibliography-utils.js +10 -1
  9. package/dist/cjs/plugins/bibliography/index.js +15 -6
  10. package/dist/cjs/plugins/persist.js +1 -2
  11. package/dist/cjs/plugins/sections.js +3 -2
  12. package/dist/cjs/plugins/tracking-mark.js +3 -3
  13. package/dist/cjs/toolbar.js +3 -1
  14. package/dist/cjs/useEditor.js +1 -3
  15. package/dist/cjs/views/bibliography_element.js +140 -1
  16. package/dist/cjs/views/block_view.js +4 -0
  17. package/dist/cjs/views/citation.js +1 -1
  18. package/dist/cjs/views/citation_editable.js +22 -4
  19. package/dist/cjs/views/contributors_section.js +35 -0
  20. package/dist/cjs/views/cross_reference_editable.js +0 -1
  21. package/dist/cjs/views/footnotes_element.js +9 -0
  22. package/dist/cjs/views/title.js +37 -0
  23. package/dist/cjs/views/title_editable.js +20 -0
  24. package/dist/es/commands.js +2 -8
  25. package/dist/es/components/outline/DraggableTree.js +32 -29
  26. package/dist/es/components/outline/ManuscriptOutline.js +2 -13
  27. package/dist/es/components/outline/OutlineManuscript.js +4 -11
  28. package/dist/es/configs/editor-views.js +4 -0
  29. package/dist/es/lib/utils.js +3 -3
  30. package/dist/es/node-type-icons.js +1 -4
  31. package/dist/es/plugins/bibliography/bibliography-utils.js +10 -1
  32. package/dist/es/plugins/bibliography/index.js +15 -6
  33. package/dist/es/plugins/persist.js +1 -2
  34. package/dist/es/plugins/sections.js +3 -2
  35. package/dist/es/plugins/tracking-mark.js +3 -3
  36. package/dist/es/toolbar.js +3 -1
  37. package/dist/es/useEditor.js +2 -4
  38. package/dist/es/views/bibliography_element.js +140 -1
  39. package/dist/es/views/block_view.js +4 -0
  40. package/dist/es/views/citation.js +1 -1
  41. package/dist/es/views/citation_editable.js +22 -4
  42. package/dist/es/views/contributors_section.js +28 -0
  43. package/dist/es/views/cross_reference_editable.js +0 -1
  44. package/dist/es/views/footnotes_element.js +9 -0
  45. package/dist/es/views/title.js +33 -0
  46. package/dist/es/views/title_editable.js +18 -0
  47. package/dist/types/components/outline/DraggableTree.d.ts +0 -1
  48. package/dist/types/components/outline/OutlineManuscript.d.ts +2 -0
  49. package/dist/types/configs/editor-views.d.ts +16 -0
  50. package/dist/types/lib/utils.d.ts +2 -2
  51. package/dist/types/plugins/bibliography/bibliography-utils.d.ts +1 -1
  52. package/dist/types/plugins/bibliography/types.d.ts +1 -0
  53. package/dist/types/plugins/tracking-mark.d.ts +2 -2
  54. package/dist/types/views/bibliography_element.d.ts +12 -1
  55. package/dist/types/views/bibliography_element_editable.d.ts +1 -0
  56. package/dist/types/views/block_view.d.ts +1 -0
  57. package/dist/types/views/blockquote_element_editable.d.ts +1 -0
  58. package/dist/types/views/bullet_list_editable.d.ts +1 -0
  59. package/dist/types/views/contributors_section.d.ts +17 -0
  60. package/dist/types/views/editable_block.d.ts +1 -0
  61. package/dist/types/views/equation_element_editable.d.ts +1 -0
  62. package/dist/types/views/figure_element_editable.d.ts +1 -0
  63. package/dist/types/views/footnote_editable.d.ts +1 -0
  64. package/dist/types/views/footnotes_element.d.ts +2 -0
  65. package/dist/types/views/footnotes_element_editable.d.ts +1 -0
  66. package/dist/types/views/listing_element_editable.d.ts +1 -0
  67. package/dist/types/views/ordered_list_editable.d.ts +1 -0
  68. package/dist/types/views/paragraph_editable.d.ts +1 -0
  69. package/dist/types/views/placeholder_element_editable.d.ts +1 -0
  70. package/dist/types/views/pullquote_element_editable.d.ts +1 -0
  71. package/dist/types/views/section_title_editable.d.ts +1 -0
  72. package/dist/types/views/table_element_editable.d.ts +1 -0
  73. package/dist/types/views/title.d.ts +24 -0
  74. package/dist/types/views/title_editable.d.ts +18 -0
  75. package/dist/types/views/toc_element_editable.d.ts +1 -0
  76. package/package.json +7 -8
  77. package/styles/AdvancedEditor.css +24 -0
  78. package/styles/Editor.css +9 -9
@@ -257,9 +257,6 @@ const insertLink = (state, dispatch) => {
257
257
  return true;
258
258
  };
259
259
  exports.insertLink = insertLink;
260
- const needsBibliography = (state) => !bibliography_1.bibliographyKey.getState(state).citations.length &&
261
- !(0, utils_1.getChildOfType)(state.tr.doc, state.schema.nodes.bibliography_section);
262
- const createBibliographySection = (state) => state.schema.nodes.bibliography_section.createAndFill({}, state.schema.nodes.section_title.create({}, state.schema.text('Bibliography')));
263
260
  const insertInlineCitation = (state, dispatch, view, embeddedCitationItems = []) => {
264
261
  const citation = (0, transform_1.buildCitation)(state.selection.$anchor.parent.attrs.id, embeddedCitationItems);
265
262
  const node = state.schema.nodes.citation.create({
@@ -270,9 +267,6 @@ const insertInlineCitation = (state, dispatch, view, embeddedCitationItems = [])
270
267
  const pos = state.selection.to;
271
268
  const { tr } = state;
272
269
  tr.insert(pos, node);
273
- if (needsBibliography(state)) {
274
- tr.insert(tr.doc.content.size, createBibliographySection(state)).setMeta(bibliography_1.bibliographyKey, { bibliographyInserted: true });
275
- }
276
270
  if (dispatch) {
277
271
  const selection = prosemirror_state_1.NodeSelection.create(tr.doc, pos);
278
272
  dispatch(tr.setSelection(selection).scrollIntoView());
@@ -349,7 +343,7 @@ const insertGraphicalAbstract = (state, dispatch) => {
349
343
  !(0, transform_1.isInAbstractsSection)(state.selection.$from)) {
350
344
  return false;
351
345
  }
352
- if ((0, utils_1.getMatchingDescendant)(state.doc, (node) => node.type === state.schema.nodes.graphical_abstract_section)) {
346
+ if (!(0, utils_1.getMatchingDescendant)(state.doc, (node) => node.type === state.schema.nodes.graphical_abstract_section)) {
353
347
  return false;
354
348
  }
355
349
  const section = state.schema.nodes.graphical_abstract_section.createAndFill({ category: 'MPSectionCategory:abstract-graphical' }, [
@@ -399,7 +393,7 @@ const insertFootnotesSection = (state, dispatch) => {
399
393
  };
400
394
  exports.insertFootnotesSection = insertFootnotesSection;
401
395
  const insertBibliographySection = (state, dispatch) => {
402
- if ((0, utils_1.getChildOfType)(state.doc, state.schema.nodes.bibliography_section)) {
396
+ if ((0, utils_1.getMatchingDescendant)(state.doc, (node) => node.type === state.schema.nodes.bibliography_section)) {
403
397
  return false;
404
398
  }
405
399
  const section = state.schema.nodes.bibliography_section.createAndFill({}, [
@@ -34,21 +34,25 @@ const track_changes_utils_1 = require("../../lib/track-changes-utils");
34
34
  const node_type_icons_1 = require("../../node-type-icons");
35
35
  const section_title_1 = require("../../views/section_title");
36
36
  const Outline_1 = require("./Outline");
37
+ const excludedTypes = [
38
+ transform_1.schema.nodes.table,
39
+ transform_1.schema.nodes.figure,
40
+ transform_1.schema.nodes.footnotes_element,
41
+ transform_1.schema.nodes.bibliography_element,
42
+ transform_1.schema.nodes.keywords_section,
43
+ transform_1.schema.nodes.affiliations_section,
44
+ transform_1.schema.nodes.contributors_section,
45
+ transform_1.schema.nodes.title,
46
+ ];
47
+ const childrenExcludedTypes = [
48
+ transform_1.schema.nodes.pullquote_element,
49
+ transform_1.schema.nodes.blockquote_element,
50
+ ];
37
51
  const isExcluded = (nodeType) => {
38
- const { nodes } = nodeType.schema;
39
- const excludedTypes = [
40
- nodes.table,
41
- nodes.figure,
42
- nodes.footnotes_element,
43
- nodes.bibliography_element,
44
- nodes.keywords_section,
45
- ];
46
52
  return excludedTypes.includes(nodeType);
47
53
  };
48
54
  const isChildrenExcluded = (nodeType) => {
49
- const { nodes } = nodeType.schema;
50
- const excludedTypes = [nodes.pullquote_element, nodes.blockquote_element];
51
- return excludedTypes.includes(nodeType);
55
+ return childrenExcludedTypes.includes(nodeType);
52
56
  };
53
57
  const buildTree = ({ node, pos, index, selected, parent, }) => {
54
58
  const items = [];
@@ -134,23 +138,22 @@ class Tree extends React.Component {
134
138
  if (isRejectedItem || node.attrs.id === 'META_SECTION') {
135
139
  return null;
136
140
  }
137
- return connectDropTarget(React.createElement("div", null,
138
- React.createElement(Outline_1.Outline, { style: this.outlineStyles(isDragging) },
139
- React.createElement(Outline_1.OutlineDropPreview, { depth: depth, style: this.topPreviewStyles(mightDrop, dragPosition) }),
140
- !(0, section_title_1.isSpecialSection)(node) && (React.createElement(React.Fragment, null, connectDragSource(React.createElement("div", null,
141
- React.createElement(Outline_1.OutlineItem, { isSelected: isSelected, depth: depth, onContextMenu: this.handleContextMenu },
142
- items.length ? (React.createElement(Outline_1.OutlineItemArrow, { onClick: this.toggle }, open ? (React.createElement(Outline_1.StyledTriangleExpanded, null)) : (React.createElement(Outline_1.StyledTriangleCollapsed, null)))) : (React.createElement(Outline_1.OutlineItemNoArrow, null)),
143
- React.createElement(Outline_1.OutlineItemLink, { to: `#${node.attrs.id || ''}` },
144
- connectDragPreview(React.createElement("span", { style: {
145
- display: 'inline-flex',
146
- alignItems: 'center',
147
- } },
148
- React.createElement(Outline_1.OutlineItemIcon, null, (0, node_type_icons_1.nodeTypeIcon)(node.type)))),
149
- React.createElement(Outline_1.OutlineItemLinkText, { className: `outline-text-${node.type.name} ${isDeletedItem && 'deleted'}` }, this.itemText(node)))))))),
150
- items.length ? (React.createElement("div", { style: {
151
- display: open || (0, section_title_1.isSpecialSection)(node) ? '' : 'none',
152
- } }, items.map((subtree) => (React.createElement(DraggableTree, Object.assign({}, this.props, { key: subtree.node.attrs.id, tree: subtree, view: view, depth: (0, section_title_1.isSpecialSection)(node) ? depth : depth + 1 })))))) : null,
153
- React.createElement(Outline_1.OutlineDropPreview, { depth: depth, style: this.bottomPreviewStyles(mightDrop, dragPosition) }))));
141
+ return connectDropTarget(React.createElement("div", null, node.type.name !== 'titles' && (React.createElement(Outline_1.Outline, { style: this.outlineStyles(isDragging) },
142
+ React.createElement(Outline_1.OutlineDropPreview, { depth: depth, style: this.topPreviewStyles(mightDrop, dragPosition) }),
143
+ !(0, section_title_1.isSpecialSection)(node) && (React.createElement(React.Fragment, null, connectDragSource(React.createElement("div", null,
144
+ React.createElement(Outline_1.OutlineItem, { isSelected: isSelected, depth: depth, onContextMenu: this.handleContextMenu },
145
+ items.length ? (React.createElement(Outline_1.OutlineItemArrow, { onClick: this.toggle }, open ? (React.createElement(Outline_1.StyledTriangleExpanded, null)) : (React.createElement(Outline_1.StyledTriangleCollapsed, null)))) : (React.createElement(Outline_1.OutlineItemNoArrow, null)),
146
+ React.createElement(Outline_1.OutlineItemLink, { to: `#${node.attrs.id || ''}` },
147
+ connectDragPreview(React.createElement("span", { style: {
148
+ display: 'inline-flex',
149
+ alignItems: 'center',
150
+ } },
151
+ React.createElement(Outline_1.OutlineItemIcon, null, (0, node_type_icons_1.nodeTypeIcon)(node.type)))),
152
+ React.createElement(Outline_1.OutlineItemLinkText, { className: `outline-text-${node.type.name} ${isDeletedItem && 'deleted'}` }, this.itemText(node)))))))),
153
+ items.length ? (React.createElement("div", { style: {
154
+ display: open || (0, section_title_1.isSpecialSection)(node) ? '' : 'none',
155
+ } }, items.map((subtree) => (React.createElement(DraggableTree, Object.assign({}, this.props, { key: subtree.node.attrs.id, tree: subtree, view: view, depth: (0, section_title_1.isSpecialSection)(node) ? depth : depth + 1 })))))) : null,
156
+ React.createElement(Outline_1.OutlineDropPreview, { depth: depth, style: this.bottomPreviewStyles(mightDrop, dragPosition) })))));
154
157
  }
155
158
  }
156
159
  const dragSource = (0, react_dnd_1.DragSource)('outline', {
@@ -39,7 +39,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.ManuscriptOutline = void 0;
42
- const title_editor_1 = require("@manuscripts/title-editor");
43
42
  const react_1 = __importStar(require("react"));
44
43
  const use_debounce_1 = require("../hooks/use-debounce");
45
44
  const DraggableTree_1 = __importStar(require("./DraggableTree"));
@@ -49,24 +48,14 @@ const ManuscriptOutline = (props) => {
49
48
  const debouncedProps = (0, use_debounce_1.useDebounce)(props, 500);
50
49
  (0, react_1.useEffect)(() => {
51
50
  var _a;
52
- const { doc, view, manuscript, selected } = debouncedProps;
51
+ const { doc, view, selected } = debouncedProps;
53
52
  if (doc) {
54
- const { items } = (0, DraggableTree_1.buildTree)({
53
+ const tree = (0, DraggableTree_1.buildTree)({
55
54
  node: doc,
56
55
  pos: 0,
57
56
  index: 0,
58
57
  selected,
59
58
  });
60
- const node = (0, title_editor_1.parse)(manuscript.title || '');
61
- const tree = {
62
- node,
63
- requirementsNode: doc,
64
- pos: 0,
65
- endPos: 0,
66
- index: 0,
67
- isSelected: !selected,
68
- items,
69
- };
70
59
  setValues({ tree, view, editArticle: !!((_a = props.capabilities) === null || _a === void 0 ? void 0 : _a.editArticle) });
71
60
  }
72
61
  else {
@@ -20,22 +20,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.OutlineManuscript = void 0;
22
22
  const OutlineIconManuscript_1 = __importDefault(require("@manuscripts/assets/react/OutlineIconManuscript"));
23
- const title_editor_1 = require("@manuscripts/title-editor");
24
23
  const transform_1 = require("@manuscripts/transform");
25
24
  const react_1 = __importDefault(require("react"));
26
25
  const Outline_1 = require("./Outline");
27
- const titleText = (value) => {
28
- const node = (0, title_editor_1.parse)(value, {
29
- topNode: title_editor_1.schema.nodes.title.create(),
30
- });
31
- return node.textContent;
32
- };
33
- const OutlineManuscript = ({ project, manuscript, }) => (react_1.default.createElement(Outline_1.Outline, null,
26
+ const OutlineManuscript = ({ project, manuscript, doc, }) => (react_1.default.createElement(Outline_1.Outline, null,
34
27
  react_1.default.createElement(Outline_1.OutlineItem, { isSelected: false, depth: 0 },
35
28
  react_1.default.createElement(Outline_1.OutlineItemLink, { to: `/projects/${project._id}/manuscripts/${manuscript._id}` },
36
29
  react_1.default.createElement(Outline_1.OutlineItemArrow, null,
37
30
  react_1.default.createElement(Outline_1.StyledTriangleCollapsed, null)),
38
31
  react_1.default.createElement(Outline_1.OutlineItemIcon, null,
39
32
  react_1.default.createElement(OutlineIconManuscript_1.default, null)),
40
- react_1.default.createElement(Outline_1.OutlineItemLinkText, { className: 'outline-text-title' }, manuscript.title ? (titleText(manuscript.title)) : (react_1.default.createElement(Outline_1.OutlineItemPlaceholder, null, (0, transform_1.nodeTitlePlaceholder)(title_editor_1.schema.nodes.title))))))));
33
+ react_1.default.createElement(Outline_1.OutlineItemLinkText, { className: 'outline-text-title' }, (0, transform_1.nodeTitle)(doc))))));
41
34
  exports.OutlineManuscript = OutlineManuscript;
@@ -23,6 +23,7 @@ const bibliography_item_editable_1 = __importDefault(require("../views/bibliogra
23
23
  const blockquote_element_editable_1 = __importDefault(require("../views/blockquote_element_editable"));
24
24
  const bullet_list_editable_1 = __importDefault(require("../views/bullet_list_editable"));
25
25
  const citation_editable_1 = __importDefault(require("../views/citation_editable"));
26
+ const contributors_section_1 = __importDefault(require("../views/contributors_section"));
26
27
  const cross_reference_editable_1 = __importDefault(require("../views/cross_reference_editable"));
27
28
  const equation_editable_1 = __importDefault(require("../views/equation_editable"));
28
29
  const equation_element_editable_1 = __importDefault(require("../views/equation_element_editable"));
@@ -46,15 +47,18 @@ const pullquote_element_editable_1 = __importDefault(require("../views/pullquote
46
47
  const section_label_1 = __importDefault(require("../views/section_label"));
47
48
  const section_title_editable_1 = __importDefault(require("../views/section_title_editable"));
48
49
  const table_element_editable_1 = __importDefault(require("../views/table_element_editable"));
50
+ const title_editable_1 = __importDefault(require("../views/title_editable"));
49
51
  const toc_element_editable_1 = __importDefault(require("../views/toc_element_editable"));
50
52
  exports.default = (props, dispatch) => {
51
53
  return {
54
+ title: (0, title_editable_1.default)(props, dispatch),
52
55
  bibliography_item: (0, bibliography_item_editable_1.default)(props),
53
56
  bibliography_element: (0, bibliography_element_editable_1.default)(props),
54
57
  blockquote_element: (0, blockquote_element_editable_1.default)(props),
55
58
  bullet_list: (0, bullet_list_editable_1.default)(props),
56
59
  citation: (0, citation_editable_1.default)(props),
57
60
  cross_reference: (0, cross_reference_editable_1.default)(props),
61
+ contributors_section: (0, contributors_section_1.default)(props, dispatch),
58
62
  equation: (0, equation_editable_1.default)(props),
59
63
  equation_element: (0, equation_element_editable_1.default)(props),
60
64
  figure: (0, figure_editable_1.default)(props, dispatch),
@@ -30,8 +30,8 @@ function* iterateChildren(node, recurse = false) {
30
30
  }
31
31
  }
32
32
  exports.iterateChildren = iterateChildren;
33
- const getMatchingChild = (parent, matcher) => {
34
- for (const node of iterateChildren(parent)) {
33
+ const getMatchingChild = (parent, matcher, deep = false) => {
34
+ for (const node of iterateChildren(parent, deep)) {
35
35
  if (matcher(node)) {
36
36
  return node;
37
37
  }
@@ -46,7 +46,7 @@ const getMatchingDescendant = (parent, matcher) => {
46
46
  }
47
47
  };
48
48
  exports.getMatchingDescendant = getMatchingDescendant;
49
- const getChildOfType = (parent, nodeType) => !!(0, exports.getMatchingChild)(parent, (node) => node.type === nodeType);
49
+ const getChildOfType = (parent, nodeType, deep = false) => !!(0, exports.getMatchingChild)(parent, (node) => node.type.name === nodeType.name, deep);
50
50
  exports.getChildOfType = getChildOfType;
51
51
  exports.findParentNodeWithId = (0, prosemirror_utils_1.findParentNode)((node) => 'id' in node.attrs);
52
52
  exports.findParentNodeWithIdValue = (0, prosemirror_utils_1.findParentNode)((node) => node.attrs.id);
@@ -29,11 +29,11 @@ const OutlineIconSection_1 = __importDefault(require("@manuscripts/assets/react/
29
29
  const OutlineIconTable_1 = __importDefault(require("@manuscripts/assets/react/OutlineIconTable"));
30
30
  const OutlineIconUnorderedList_1 = __importDefault(require("@manuscripts/assets/react/OutlineIconUnorderedList"));
31
31
  const style_guide_1 = require("@manuscripts/style-guide");
32
- const title_editor_1 = require("@manuscripts/title-editor");
33
32
  const transform_1 = require("@manuscripts/transform");
34
33
  const react_1 = __importDefault(require("react"));
35
34
  const { nodes } = transform_1.schema;
36
35
  const icons = new Map([
36
+ [nodes.manuscript, OutlineIconManuscript_1.default],
37
37
  [nodes.bibliography_section, OutlineIconSection_1.default],
38
38
  [nodes.blockquote_element, style_guide_1.BlockQuoteIcon],
39
39
  [nodes.bullet_list, OutlineIconUnorderedList_1.default],
@@ -52,9 +52,6 @@ const icons = new Map([
52
52
  [nodes.footnotes_section, OutlineIconSection_1.default],
53
53
  ]);
54
54
  const nodeTypeIcon = (nodeType) => {
55
- if (nodeType === title_editor_1.schema.nodes.title) {
56
- return react_1.default.createElement(OutlineIconManuscript_1.default, null);
57
- }
58
55
  const Icon = icons.get(nodeType);
59
56
  return Icon ? react_1.default.createElement(Icon, null) : null;
60
57
  };
@@ -34,7 +34,7 @@ const lodash_es_1 = require("lodash-es");
34
34
  const prosemirror_view_1 = require("prosemirror-view");
35
35
  const isBibliographyElement = (node) => node.type === node.type.schema.nodes.bibliography_element;
36
36
  exports.isBibliographyElement = isBibliographyElement;
37
- const buildDecorations = (doc, citationNodes, popper, referencesModelMap) => {
37
+ const buildDecorations = (doc, citationNodes, popper, referencesModelMap, triggerUpdate) => {
38
38
  const decorations = [];
39
39
  let hasMissingItems = false;
40
40
  for (const [node, pos, citation] of citationNodes) {
@@ -72,6 +72,15 @@ const buildDecorations = (doc, citationNodes, popper, referencesModelMap) => {
72
72
  }
73
73
  });
74
74
  }
75
+ if (triggerUpdate) {
76
+ doc.descendants((node, pos) => {
77
+ if ((0, exports.isBibliographyElement)(node)) {
78
+ decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {}, {
79
+ triggerUpdate: true,
80
+ }));
81
+ }
82
+ });
83
+ }
75
84
  return decorations;
76
85
  };
77
86
  exports.buildDecorations = buildDecorations;
@@ -20,6 +20,7 @@ const library_1 = require("@manuscripts/library");
20
20
  const lodash_es_1 = require("lodash-es");
21
21
  const prosemirror_state_1 = require("prosemirror-state");
22
22
  const prosemirror_view_1 = require("prosemirror-view");
23
+ const track_changes_utils_1 = require("../../lib/track-changes-utils");
23
24
  const bibliography_utils_1 = require("./bibliography-utils");
24
25
  exports.bibliographyKey = new prosemirror_state_1.PluginKey('bibliography');
25
26
  exports.default = (props) => {
@@ -30,8 +31,9 @@ exports.default = (props) => {
30
31
  init(config, instance) {
31
32
  const referencesModelMap = (0, bibliography_utils_1.getReferencesModelMap)(instance.doc);
32
33
  const citationNodes = (0, library_1.buildCitationNodes)(instance.doc, referencesModelMap);
33
- const citations = (0, library_1.buildCitations)(citationNodes, (id) => referencesModelMap.get(id));
34
- const bibliographyItems = (0, library_1.buildBibliographyItems)(citationNodes, (id) => referencesModelMap.get(id));
34
+ const filteredCitationNodes = citationNodes.filter((node) => !(0, track_changes_utils_1.isRejectedInsert)(node[0]));
35
+ const citations = (0, library_1.buildCitations)(filteredCitationNodes, (id) => referencesModelMap.get(id));
36
+ const bibliographyItems = (0, library_1.buildBibliographyItems)(filteredCitationNodes, (id) => referencesModelMap.get(id));
35
37
  return {
36
38
  citationNodes,
37
39
  citations,
@@ -41,12 +43,16 @@ exports.default = (props) => {
41
43
  apply(tr, value, oldState, newState) {
42
44
  const referencesModelMap = (0, bibliography_utils_1.getReferencesModelMap)(newState.doc);
43
45
  const citationNodes = (0, library_1.buildCitationNodes)(newState.doc, referencesModelMap);
44
- const citations = (0, library_1.buildCitations)(citationNodes, (id) => referencesModelMap.get(id));
45
- const bibliographyItems = (0, library_1.buildBibliographyItems)(citationNodes, (id) => referencesModelMap.get(id));
46
+ const filteredCitationNodes = citationNodes.filter((node) => !(0, track_changes_utils_1.isRejectedInsert)(node[0]));
47
+ const citations = (0, library_1.buildCitations)(filteredCitationNodes, (id) => referencesModelMap.get(id));
48
+ const bibliographyItems = (0, library_1.buildBibliographyItems)(filteredCitationNodes, (id) => referencesModelMap.get(id));
49
+ const meta = tr.getMeta(exports.bibliographyKey);
50
+ const triggerUpdate = meta && meta.triggerUpdate;
46
51
  return {
47
52
  citationNodes,
48
53
  citations,
49
54
  bibliographyItems,
55
+ triggerUpdate,
50
56
  };
51
57
  },
52
58
  },
@@ -74,6 +80,9 @@ exports.default = (props) => {
74
80
  if (selection instanceof prosemirror_state_1.NodeSelection) {
75
81
  tr.setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, selection.from));
76
82
  }
83
+ tr.setMeta(exports.bibliographyKey, {
84
+ triggerUpdate: true,
85
+ });
77
86
  tr.setMeta('origin', exports.bibliographyKey);
78
87
  return tr;
79
88
  }
@@ -83,8 +92,8 @@ exports.default = (props) => {
83
92
  },
84
93
  props: {
85
94
  decorations(state) {
86
- const { citationNodes } = exports.bibliographyKey.getState(state);
87
- return prosemirror_view_1.DecorationSet.create(state.doc, (0, bibliography_utils_1.buildDecorations)(state.doc, citationNodes, props.popper, (0, bibliography_utils_1.getReferencesModelMap)(state.doc)));
95
+ const { citationNodes, triggerUpdate } = exports.bibliographyKey.getState(state);
96
+ return prosemirror_view_1.DecorationSet.create(state.doc, (0, bibliography_utils_1.buildDecorations)(state.doc, citationNodes, props.popper, (0, bibliography_utils_1.getReferencesModelMap)(state.doc), triggerUpdate));
88
97
  },
89
98
  },
90
99
  });
@@ -25,10 +25,9 @@ exports.default = () => {
25
25
  else if ((0, transform_1.isFootnoteNode)(node)) {
26
26
  endOfFootnote = Math.max(endOfFootnote, pos + node.nodeSize);
27
27
  }
28
- const insideList = pos <= endOfList;
29
28
  const insideFootnote = pos <= endOfFootnote;
30
29
  if ('id' in node.attrs &&
31
- ((!insideList && !insideFootnote) || node.isInline) &&
30
+ (!insideFootnote || node.isInline) &&
32
31
  (!id || id.length === 0 || ids.has(id))) {
33
32
  const newId = (0, transform_1.generateNodeID)(node.type);
34
33
  const updatedAttrs = Object.assign(Object.assign({}, node.attrs), { id: newId });
@@ -33,12 +33,13 @@ const preventTitleEdit = (tr) => {
33
33
  }
34
34
  const hasReplaceAroundSteps = tr.steps.some((step) => step instanceof prosemirror_transform_1.ReplaceAroundStep);
35
35
  if (!hasReplaceAroundSteps) {
36
- tr.steps.forEach((step) => {
36
+ tr.steps.forEach((step, i) => {
37
37
  if (!(step instanceof prosemirror_transform_1.ReplaceStep)) {
38
38
  return;
39
39
  }
40
+ const currentDoc = tr.docs[i];
40
41
  step.getMap().forEach((fromA, toA) => {
41
- tr.doc.nodesBetween(fromA, toA, (node, nodePos) => {
42
+ currentDoc.nodesBetween(fromA, toA, (node, nodePos) => {
42
43
  if ((0, transform_1.isGraphicalAbstractSectionNode)(node) ||
43
44
  (0, transform_1.isKeywordsSectionNode)(node)) {
44
45
  node.descendants((childNode, childPos) => {
@@ -41,17 +41,17 @@ const buildDecorations = (state) => {
41
41
  if (change.type === 'node-attr-change' &&
42
42
  change.dataTracked.status === track_changes_plugin_1.CHANGE_STATUS.pending &&
43
43
  change.dataTracked.operation === track_changes_plugin_1.CHANGE_OPERATION.set_node_attributes) {
44
- decorations.push(prosemirror_view_1.Decoration.widget(change.from + 1, (0, exports.getAttrsTrackingButton)(change), {
44
+ decorations.push(prosemirror_view_1.Decoration.widget(change.from + 1, (0, exports.getAttrsTrackingButton)(change.id), {
45
45
  key: change.id,
46
46
  }));
47
47
  }
48
48
  });
49
49
  return decorations;
50
50
  };
51
- const getAttrsTrackingButton = (change) => {
51
+ const getAttrsTrackingButton = (changeID) => {
52
52
  const el = document.createElement('button');
53
53
  el.className = 'attrs-popper-button';
54
- el.value = change.id;
54
+ el.value = changeID;
55
55
  el.innerHTML = editIcon;
56
56
  return el;
57
57
  };
@@ -78,7 +78,9 @@ exports.toolbar = {
78
78
  title: 'Wrap in ordered list',
79
79
  active: (0, commands_1.blockActive)(transform_1.schema.nodes.ordered_list),
80
80
  enable: (0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.ordered_list),
81
- run: (0, list_1.skipTrackingChanges)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.ordered_list)),
81
+ run: (0, list_1.skipTrackingChanges)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.ordered_list, {
82
+ listStyleType: 'order',
83
+ })),
82
84
  Component: OrderListSelector_1.OrderListSelector,
83
85
  },
84
86
  },
@@ -68,9 +68,7 @@ const useEditor = (initialState, createView) => {
68
68
  state.doc.descendants((node, pos) => {
69
69
  if (node.attrs.id === id) {
70
70
  currentView.focus();
71
- const selection = node.isAtom
72
- ? prosemirror_state_1.NodeSelection.create(state.tr.doc, pos)
73
- : prosemirror_state_1.TextSelection.near(state.tr.doc.resolve(pos + 1));
71
+ const selection = prosemirror_state_1.NodeSelection.create(state.tr.doc, pos);
74
72
  currentView.dispatch(state.tr.setSelection(selection));
75
73
  const dom = currentView.domAtPos(pos + 1);
76
74
  if (dom.node instanceof Element) {
@@ -14,23 +14,162 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __rest = (this && this.__rest) || function (s, e) {
27
+ var t = {};
28
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
29
+ t[p] = s[p];
30
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
31
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
32
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
33
+ t[p[i]] = s[p[i]];
34
+ }
35
+ return t;
36
+ };
17
37
  var __importDefault = (this && this.__importDefault) || function (mod) {
18
38
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
39
  };
20
40
  Object.defineProperty(exports, "__esModule", { value: true });
21
41
  exports.BibliographyElementBlockView = void 0;
42
+ const library_1 = require("@manuscripts/library");
43
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
44
+ const transform_1 = require("@manuscripts/transform");
45
+ const react_1 = __importDefault(require("react"));
46
+ const assets_1 = require("../assets");
47
+ const dompurify_1 = require("../lib/dompurify");
48
+ const bibliography_1 = require("../plugins/bibliography");
49
+ const bibliography_utils_1 = require("../plugins/bibliography/bibliography-utils");
50
+ const comment_annotation_1 = require("../plugins/comment_annotation");
51
+ const tracking_mark_1 = require("../plugins/tracking-mark");
22
52
  const block_view_1 = __importDefault(require("./block_view"));
23
53
  const creators_1 = require("./creators");
54
+ const createBibliography = (bibliographyItems, cslProps) => __awaiter(void 0, void 0, void 0, function* () {
55
+ const bibliographyItemsMap = new Map(bibliographyItems.map((item) => [item._id, item]));
56
+ const getLibraryItem = (id) => bibliographyItemsMap.get(id);
57
+ const { style = '', locale } = cslProps;
58
+ const provider = new library_1.CitationProvider({
59
+ getLibraryItem,
60
+ citationStyle: style,
61
+ locale,
62
+ });
63
+ const [bibmeta, generatedBibliographyItems] = provider.makeBibliography(bibliographyItems);
64
+ if (bibmeta.bibliography_errors.length) {
65
+ console.error(bibmeta.bibliography_errors);
66
+ }
67
+ const bibliographyFragment = generatedBibliographyItems
68
+ .map((item, i) => `<div id=${bibmeta.entry_ids[i]} class="bib-item"><div><div class="csl-bib-body">${item}</div></div></div>`)
69
+ .join('');
70
+ return (0, dompurify_1.sanitize)(`<div class="contents">${bibliographyFragment}</div>`);
71
+ });
24
72
  class BibliographyElementBlockView extends block_view_1.default {
25
73
  constructor() {
26
74
  super(...arguments);
75
+ this.showPopper = (referenceID) => {
76
+ const { renderReactComponent, components: { ReferencesEditor }, } = this.props;
77
+ const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
78
+ const _a = data, { _id: id, 'container-title': containerTitle, DOI: doi } = _a, rest = __rest(_a, ["_id", 'container-title', "DOI"]);
79
+ this.updateNodeAttrs(Object.assign({ id,
80
+ containerTitle,
81
+ doi }, rest));
82
+ });
83
+ if (!this.popperContainer) {
84
+ this.popperContainer = document.createElement('div');
85
+ this.popperContainer.className = 'references';
86
+ }
87
+ renderReactComponent(react_1.default.createElement(ReferencesEditor, { saveModel: handleSave, deleteModel: this.deleteNode, modelMap: (0, bibliography_utils_1.getReferencesModelMap)(this.view.state.doc, true), referenceID: referenceID }), this.popperContainer);
88
+ this.props.popper.show(this.dom, this.popperContainer, 'right');
89
+ };
27
90
  this.stopEvent = () => true;
28
91
  this.ignoreMutation = () => true;
92
+ this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
93
+ const bibliographyItems = bibliography_1.bibliographyKey.getState(this.view.state).bibliographyItems;
94
+ const commentsDecorationSet = comment_annotation_1.commentAnnotation.getState(this.view.state);
95
+ const commentElementMap = new Map();
96
+ const dataTrackedMap = new Map();
97
+ this.node.descendants((node, pos) => {
98
+ if (commentsDecorationSet) {
99
+ const nodePosition = this.getPos() + pos + 2;
100
+ const commentWidget = commentsDecorationSet.find(nodePosition, nodePosition);
101
+ if (commentWidget.length) {
102
+ const commentElement = commentWidget[0].type.toDOM();
103
+ commentElementMap.set(commentElement.id, commentElement);
104
+ }
105
+ }
106
+ const dataTracked = node.attrs.dataTracked;
107
+ if (dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.length) {
108
+ const lastChange = dataTracked[dataTracked.length - 1];
109
+ dataTrackedMap.set(node.attrs.id, lastChange);
110
+ }
111
+ });
112
+ const bibliographyFragment = yield createBibliography(bibliographyItems, this.props.cslProps);
113
+ const bibItems = bibliographyFragment.querySelectorAll('.bib-item');
114
+ bibItems.forEach((element) => {
115
+ const doubleButton = document.createElement('div');
116
+ const editButton = document.createElement('button');
117
+ const commentButton = document.createElement('button');
118
+ doubleButton.className = 'bibliography-double-button';
119
+ editButton.className = 'bibliography-edit-button';
120
+ commentButton.className = 'bibliography-comment-button';
121
+ commentButton.addEventListener('click', (e) => {
122
+ e.preventDefault();
123
+ this.props.setComment((0, transform_1.buildComment)(element.id));
124
+ });
125
+ editButton.addEventListener('click', (e) => {
126
+ e.preventDefault();
127
+ this.showPopper(element.id);
128
+ this.popperContainer = undefined;
129
+ });
130
+ editButton.innerHTML = assets_1.editIcon;
131
+ commentButton.innerHTML = assets_1.commentIcon;
132
+ doubleButton.append(editButton, commentButton);
133
+ if (this.props.getCapabilities().seeReferencesButtons &&
134
+ !element.querySelector('.bibliography-double-button')) {
135
+ element.appendChild(doubleButton);
136
+ }
137
+ editButton.disabled = !this.props.getCapabilities().editCitationsAndRefs;
138
+ const commentElement = commentElementMap.get(element.id);
139
+ if (commentElement) {
140
+ element.childNodes[0].appendChild(commentElement);
141
+ }
142
+ const dataTracked = dataTrackedMap.get(element.id);
143
+ if (dataTracked) {
144
+ element.classList.add('attrs-track-mark');
145
+ const decoration = (0, tracking_mark_1.getMarkDecoration)(dataTracked);
146
+ decoration.style && element.setAttribute('style', decoration.style);
147
+ if (dataTracked.status === track_changes_plugin_1.CHANGE_STATUS.pending &&
148
+ dataTracked.operation === track_changes_plugin_1.CHANGE_OPERATION.set_node_attributes) {
149
+ element.childNodes[0].appendChild((0, tracking_mark_1.getAttrsTrackingButton)(dataTracked.id));
150
+ }
151
+ }
152
+ });
153
+ const oldContent = this.container.querySelector('.contents');
154
+ if (oldContent) {
155
+ this.container.replaceChild(bibliographyFragment, oldContent);
156
+ }
157
+ else {
158
+ this.container.appendChild(bibliographyFragment);
159
+ }
160
+ });
29
161
  this.createElement = () => {
162
+ this.container = document.createElement('div');
163
+ this.container.classList.add('block');
164
+ this.container.contentEditable = 'false';
165
+ this.dom.setAttribute('contenteditable', 'false');
166
+ this.dom.appendChild(this.container);
30
167
  this.contentDOM = document.createElement('div');
31
168
  this.contentDOM.classList.add('block');
32
169
  this.contentDOM.setAttribute('id', this.node.attrs.id);
33
- this.dom.appendChild(this.contentDOM);
170
+ this.contentDOM.setAttribute('contenteditable', 'false');
171
+ this.contentDOM.hidden = true;
172
+ this.container.appendChild(this.contentDOM);
34
173
  };
35
174
  }
36
175
  }
@@ -34,6 +34,7 @@ class BlockView extends base_node_view_1.BaseNodeView {
34
34
  this.updateContents = () => {
35
35
  this.updateClasses();
36
36
  this.updateAttributes();
37
+ this.onUpdateContent();
37
38
  };
38
39
  this.updateClasses = () => {
39
40
  if (!this.contentDOM) {
@@ -89,5 +90,8 @@ class BlockView extends base_node_view_1.BaseNodeView {
89
90
  this.gutterButtons = () => [];
90
91
  this.actionGutterButtons = () => [];
91
92
  }
93
+ onUpdateContent() {
94
+ return;
95
+ }
92
96
  }
93
97
  exports.default = BlockView;
@@ -119,7 +119,7 @@ class CitationView extends base_node_view_1.BaseNodeView {
119
119
  const citeprocContent = citeprocCitations === null || citeprocCitations === void 0 ? void 0 : citeprocCitations.get(this.node.attrs.rid);
120
120
  const fragment = (0, dompurify_1.sanitize)(citeprocContent && citeprocContent !== '[NO_PRINTED_FORM]'
121
121
  ? citeprocContent
122
- : this.node.attrs.contents, {
122
+ : ' ', {
123
123
  ALLOWED_TAGS: ['i', 'b', 'span', 'sup', 'sub', '#text'],
124
124
  });
125
125
  citationElement.appendChild(fragment);