@manuscripts/body-editor 1.10.7-LEAN-3591.0 → 1.10.7

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 (58) hide show
  1. package/dist/cjs/commands.js +118 -75
  2. package/dist/cjs/configs/editor-plugins.js +5 -5
  3. package/dist/cjs/index.js +6 -3
  4. package/dist/cjs/lib/context-menu.js +4 -15
  5. package/dist/cjs/menus.js +2 -2
  6. package/dist/cjs/plugins/comment_annotation.js +191 -0
  7. package/dist/cjs/plugins/highlight/findHighlightMarkers.js +26 -0
  8. package/dist/cjs/plugins/highlight/index.js +85 -0
  9. package/dist/cjs/plugins/highlight/types.js +2 -0
  10. package/dist/cjs/plugins/sections.js +4 -1
  11. package/dist/cjs/toolbar.js +1 -1
  12. package/dist/cjs/views/bibliography_element.js +41 -64
  13. package/dist/cjs/views/citation.js +6 -9
  14. package/dist/cjs/views/citation_editable.js +2 -2
  15. package/dist/cjs/views/contributors.js +6 -2
  16. package/dist/cjs/views/editable_block.js +2 -1
  17. package/dist/cjs/views/keyword_group.js +1 -0
  18. package/dist/es/commands.js +115 -74
  19. package/dist/es/configs/editor-plugins.js +5 -5
  20. package/dist/es/index.js +2 -2
  21. package/dist/es/lib/context-menu.js +5 -16
  22. package/dist/es/menus.js +3 -3
  23. package/dist/es/plugins/comment_annotation.js +184 -0
  24. package/dist/es/plugins/highlight/findHighlightMarkers.js +22 -0
  25. package/dist/es/plugins/highlight/index.js +79 -0
  26. package/dist/es/plugins/highlight/types.js +1 -0
  27. package/dist/es/plugins/sections.js +4 -1
  28. package/dist/es/toolbar.js +2 -2
  29. package/dist/es/views/bibliography_element.js +42 -65
  30. package/dist/es/views/citation.js +6 -9
  31. package/dist/es/views/citation_editable.js +3 -3
  32. package/dist/es/views/contributors.js +6 -2
  33. package/dist/es/views/editable_block.js +2 -1
  34. package/dist/es/views/keyword_group.js +1 -0
  35. package/dist/types/commands.d.ts +7 -3
  36. package/dist/types/configs/ManuscriptsEditor.d.ts +3 -1
  37. package/dist/types/index.d.ts +2 -2
  38. package/dist/types/lib/context-menu.d.ts +2 -2
  39. package/dist/types/lib/references.d.ts +2 -3
  40. package/dist/types/plugins/comment_annotation.d.ts +14 -0
  41. package/dist/types/plugins/highlight/findHighlightMarkers.d.ts +3 -0
  42. package/dist/types/plugins/highlight/index.d.ts +26 -0
  43. package/dist/types/plugins/highlight/types.d.ts +18 -0
  44. package/dist/types/views/bibliography_element.d.ts +8 -3
  45. package/dist/types/views/citation_editable.d.ts +1 -1
  46. package/dist/types/views/editable_block.d.ts +2 -0
  47. package/dist/types/views/keyword_group.d.ts +1 -0
  48. package/package.json +2 -2
  49. package/styles/AdvancedEditor.css +54 -45
  50. package/dist/cjs/lib/comments.js +0 -49
  51. package/dist/cjs/plugins/comments.js +0 -209
  52. package/dist/cjs/plugins/editor-props.js +0 -22
  53. package/dist/es/lib/comments.js +0 -42
  54. package/dist/es/plugins/comments.js +0 -204
  55. package/dist/es/plugins/editor-props.js +0 -18
  56. package/dist/types/lib/comments.d.ts +0 -33
  57. package/dist/types/plugins/comments.d.ts +0 -15
  58. package/dist/types/plugins/editor-props.d.ts +0 -7
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.insertTableFootnote = exports.addInlineComment = exports.addNodeComment = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.ifInTableBody = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertFileAsFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
18
+ exports.insertTableFootnote = exports.updateCommentAnnotationState = exports.addComment = exports.deleteHighlightMarkers = exports.insertHighlight = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.ifInTableBody = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertFileAsFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
20
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
21
21
  const transform_1 = require("@manuscripts/transform");
@@ -24,13 +24,12 @@ const prosemirror_schema_list_1 = require("prosemirror-schema-list");
24
24
  const prosemirror_state_1 = require("prosemirror-state");
25
25
  const prosemirror_transform_1 = require("prosemirror-transform");
26
26
  const prosemirror_utils_1 = require("prosemirror-utils");
27
- const comments_1 = require("./lib/comments");
28
27
  const helpers_1 = require("./lib/helpers");
29
28
  const track_changes_utils_1 = require("./lib/track-changes-utils");
30
29
  const utils_1 = require("./lib/utils");
31
- const comments_2 = require("./plugins/comments");
32
- const editor_props_1 = require("./plugins/editor-props");
30
+ const comment_annotation_1 = require("./plugins/comment_annotation");
33
31
  const footnotes_utils_1 = require("./plugins/footnotes/footnotes-utils");
32
+ const highlight_1 = require("./plugins/highlight");
34
33
  const markActive = (type) => (state) => {
35
34
  const { from, $from, to, empty } = state.selection;
36
35
  return empty
@@ -657,6 +656,83 @@ const createAndFillFigcaptionElement = (state) => state.schema.nodes.figcaption.
657
656
  state.schema.nodes.caption_title.create(),
658
657
  state.schema.nodes.caption.create(),
659
658
  ]);
659
+ const insertHighlight = (state, comment, dispatch) => {
660
+ const { from, to } = state.selection;
661
+ const fromNode = state.schema.nodes.highlight_marker.create({
662
+ id: comment._id,
663
+ tid: comment.target,
664
+ position: 'start',
665
+ });
666
+ const toNode = state.schema.nodes.highlight_marker.create({
667
+ id: comment._id,
668
+ tid: comment.target,
669
+ position: 'end',
670
+ });
671
+ const tr = state.tr
672
+ .insert(from, fromNode)
673
+ .insert(to + 1, toNode)
674
+ .setMeta(highlight_1.highlightKey, {
675
+ [highlight_1.SET_COMMENT]: Object.assign(Object.assign({}, comment), { selector: { from, to }, originalText: state.tr.doc.textBetween(from, to, '\n') }),
676
+ });
677
+ tr.setMeta('addToHistory', false);
678
+ if (dispatch) {
679
+ dispatch(tr);
680
+ }
681
+ return true;
682
+ };
683
+ exports.insertHighlight = insertHighlight;
684
+ const deleteHighlightMarkers = (rid) => (state, dispatch) => {
685
+ var _a;
686
+ const markersToDelete = [];
687
+ (_a = highlight_1.highlightKey.getState(state)) === null || _a === void 0 ? void 0 : _a.highlights.forEach((highlight) => {
688
+ if (highlight.id === rid) {
689
+ markersToDelete.push(highlight.start - 1);
690
+ markersToDelete.push(highlight.end);
691
+ }
692
+ });
693
+ if (markersToDelete.length === 0) {
694
+ return false;
695
+ }
696
+ const { tr } = state;
697
+ markersToDelete
698
+ .sort((a, b) => b - a)
699
+ .forEach((pos) => {
700
+ tr.delete(pos, pos + 1);
701
+ });
702
+ tr.setMeta('track-changes-skip-tracking', true);
703
+ dispatch && dispatch(tr);
704
+ return true;
705
+ };
706
+ exports.deleteHighlightMarkers = deleteHighlightMarkers;
707
+ function addComment(state, dispatch, viewNode, resolvePos) {
708
+ const { selection } = state;
709
+ const hasText = selection.content().size > 0;
710
+ const parent = getParentNode(selection);
711
+ if (!parent) {
712
+ return false;
713
+ }
714
+ if (viewNode && resolvePos) {
715
+ const viewNode = getParentNode(prosemirror_state_1.TextSelection.near(resolvePos));
716
+ if (!viewNode) {
717
+ return false;
718
+ }
719
+ if (hasText && parent.attrs.id === viewNode.attrs.id) {
720
+ return addHighlightComment(viewNode, state, dispatch);
721
+ }
722
+ else {
723
+ return addBlockComment(viewNode, state, dispatch);
724
+ }
725
+ }
726
+ else {
727
+ if (hasText) {
728
+ return addHighlightComment(parent, state, dispatch);
729
+ }
730
+ else {
731
+ return addBlockComment(parent, state, dispatch);
732
+ }
733
+ }
734
+ }
735
+ exports.addComment = addComment;
660
736
  const getParentNode = (selection) => {
661
737
  var _a;
662
738
  const parentNode = (0, utils_1.findParentNodeWithId)(selection);
@@ -666,94 +742,61 @@ const getParentNode = (selection) => {
666
742
  }
667
743
  return node;
668
744
  };
669
- const isCommentingAllowed = (type) => type === transform_1.schema.nodes.section ||
670
- type === transform_1.schema.nodes.citation ||
671
- type === transform_1.schema.nodes.bibliography_item ||
745
+ const isAllowedType = (type) => type === transform_1.schema.nodes.section ||
672
746
  type === transform_1.schema.nodes.footnotes_section ||
673
747
  type === transform_1.schema.nodes.bibliography_section ||
674
748
  type === transform_1.schema.nodes.keyword_group ||
675
749
  type === transform_1.schema.nodes.paragraph ||
676
750
  type === transform_1.schema.nodes.figure_element ||
677
751
  type === transform_1.schema.nodes.table_element;
678
- const addNodeComment = (node, state, dispatch) => {
679
- if (!isCommentingAllowed(node.type)) {
680
- return false;
752
+ const getNode = (node) => {
753
+ if (node.type === transform_1.schema.nodes.keywords) {
754
+ const keywordGroups = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.keyword_group, true);
755
+ return keywordGroups.length ? keywordGroups[0].node : node;
681
756
  }
682
- const props = (0, editor_props_1.getEditorProps)(state);
683
- const contribution = (0, json_schema_1.buildContribution)(props.userID);
684
- const attrs = {
685
- id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.CommentAnnotation),
686
- contents: '',
687
- target: node.attrs.id,
688
- contributions: [contribution],
689
- };
690
- const comment = transform_1.schema.nodes.comment.create(attrs);
691
- const comments = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.comments)[0];
692
- const pos = comments.pos + 1;
693
- const tr = state.tr.insert(pos, comment);
694
- const key = (0, comments_1.getCommentKey)(attrs, undefined, node);
695
- (0, comments_2.setCommentSelection)(tr, key, attrs.id, true);
696
- if (dispatch) {
697
- dispatch(tr);
698
- }
699
- return true;
757
+ return node;
700
758
  };
701
- exports.addNodeComment = addNodeComment;
702
- const addInlineComment = (state, dispatch) => {
703
- const selection = state.selection;
704
- const node = getParentNode(selection);
705
- if (!node) {
759
+ const addBlockComment = (node, state, dispatch) => {
760
+ const { attrs: { id }, type, } = getNode(node);
761
+ const comment = (0, transform_1.buildComment)(id);
762
+ const tr = state.tr.setMeta(comment_annotation_1.commentAnnotation, {
763
+ [highlight_1.SET_COMMENT]: comment,
764
+ });
765
+ tr.setMeta('addToHistory', false);
766
+ if (isAllowedType(type)) {
767
+ dispatch && dispatch(tr);
768
+ return true;
769
+ }
770
+ else {
706
771
  return false;
707
772
  }
708
- const from = selection.from;
709
- const to = selection.to;
710
- const props = (0, editor_props_1.getEditorProps)(state);
711
- const contribution = (0, json_schema_1.buildContribution)(props.userID);
712
- const attrs = {
713
- id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.CommentAnnotation),
714
- contents: '',
715
- target: node.attrs.id,
716
- contributions: [contribution],
717
- originalText: selectedText(),
718
- selector: {
719
- from,
720
- to,
721
- },
722
- };
723
- const comment = transform_1.schema.nodes.comment.create(attrs);
724
- const comments = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.comments)[0];
725
- const pos = comments.pos + 1;
726
- const tr = state.tr.insert(pos, comment);
727
- if (from === to) {
728
- const point = transform_1.schema.nodes.highlight_marker.create({
729
- id: comment.attrs.id,
730
- tid: node.attrs.id,
731
- position: 'point',
732
- });
733
- tr.insert(from, point);
773
+ };
774
+ const addHighlightComment = (node, state, dispatch) => {
775
+ const { attrs: { id }, type, } = node;
776
+ const comment = (0, transform_1.buildComment)(id);
777
+ if (type === transform_1.schema.nodes.paragraph) {
778
+ const { $anchor, $head } = state.selection;
779
+ const isAllTextSelected = ($anchor.textOffset === 0 && $head.textOffset === 0) ||
780
+ $anchor.textOffset === $head.textOffset;
781
+ if (isAllTextSelected) {
782
+ return addBlockComment(node, state, dispatch);
783
+ }
784
+ else {
785
+ return (0, exports.insertHighlight)(state, comment, dispatch);
786
+ }
734
787
  }
735
788
  else {
736
- const start = transform_1.schema.nodes.highlight_marker.create({
737
- id: comment.attrs.id,
738
- tid: node.attrs.id,
739
- position: 'start',
740
- });
741
- const end = transform_1.schema.nodes.highlight_marker.create({
742
- id: comment.attrs.id,
743
- tid: node.attrs.id,
744
- position: 'end',
745
- });
746
- tr.insert(from, start).insert(to + 1, end);
789
+ return (0, exports.insertHighlight)(state, comment, dispatch);
747
790
  }
748
- const range = (0, comments_1.getCommentRange)(attrs);
749
- const key = (0, comments_1.getCommentKey)(attrs, range, node);
750
- (0, comments_2.setCommentSelection)(tr, key, attrs.id, true);
791
+ };
792
+ const updateCommentAnnotationState = (state, dispatch) => {
793
+ const tr = state.tr.setMeta(comment_annotation_1.commentAnnotation, {});
794
+ tr.setMeta('addToHistory', false);
751
795
  if (dispatch) {
752
796
  dispatch(tr);
753
797
  }
754
- return true;
755
798
  };
756
- exports.addInlineComment = addInlineComment;
799
+ exports.updateCommentAnnotationState = updateCommentAnnotationState;
757
800
  const insertTableFootnote = (node, position, view, inlineFootnote) => {
758
801
  var _a;
759
802
  const { state, dispatch } = view;
@@ -28,10 +28,10 @@ const prosemirror_tables_1 = require("prosemirror-tables");
28
28
  const keys_1 = __importDefault(require("../keys"));
29
29
  const affiliations_1 = __importDefault(require("../plugins/affiliations"));
30
30
  const bibliography_1 = __importDefault(require("../plugins/bibliography"));
31
- const comments_1 = __importDefault(require("../plugins/comments"));
32
- const editor_props_1 = __importDefault(require("../plugins/editor-props"));
31
+ const comment_annotation_1 = __importDefault(require("../plugins/comment_annotation"));
33
32
  const elements_1 = __importDefault(require("../plugins/elements"));
34
33
  const footnotes_1 = __importDefault(require("../plugins/footnotes"));
34
+ const highlight_1 = __importDefault(require("../plugins/highlight"));
35
35
  const objects_1 = __importDefault(require("../plugins/objects"));
36
36
  const paragraphs_1 = __importDefault(require("../plugins/paragraphs"));
37
37
  const persist_1 = __importDefault(require("../plugins/persist"));
@@ -63,14 +63,14 @@ exports.default = (props) => {
63
63
  (0, bibliography_1.default)(props),
64
64
  (0, objects_1.default)(props),
65
65
  (0, affiliations_1.default)(),
66
- (0, comments_1.default)(),
66
+ (0, comment_annotation_1.default)(props),
67
67
  (0, paragraphs_1.default)(),
68
68
  (0, placeholder_1.default)(),
69
69
  (0, prosemirror_tables_1.tableEditing)(),
70
- (0, selected_suggestion_1.default)(),
70
+ (0, highlight_1.default)(props),
71
71
  (0, footnotes_1.default)(props),
72
72
  (0, table_footnote_1.default)(),
73
- (0, editor_props_1.default)(props),
73
+ (0, selected_suggestion_1.default)(),
74
74
  ];
75
75
  if (props.collabProvider) {
76
76
  allPlugins.push((0, prosemirror_collab_1.collab)({ version: props.collabProvider.currentVersion }));
package/dist/cjs/index.js CHANGED
@@ -29,7 +29,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
29
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.selectedSuggestionKey = exports.PopperManager = exports.CollabProvider = exports.LevelSelector = exports.OutlineItemIcon = exports.ManuscriptOutline = void 0;
32
+ exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.selectedSuggestionKey = exports.PopperManager = exports.CollabProvider = exports.LevelSelector = exports.OutlineItemIcon = exports.ManuscriptOutline = void 0;
33
33
  __exportStar(require("./commands"), exports);
34
34
  var ManuscriptOutline_1 = require("./components/outline/ManuscriptOutline");
35
35
  Object.defineProperty(exports, "ManuscriptOutline", { enumerable: true, get: function () { return ManuscriptOutline_1.ManuscriptOutline; } });
@@ -43,10 +43,13 @@ Object.defineProperty(exports, "CollabProvider", { enumerable: true, get: functi
43
43
  var popper_1 = require("./lib/popper");
44
44
  Object.defineProperty(exports, "PopperManager", { enumerable: true, get: function () { return popper_1.PopperManager; } });
45
45
  __exportStar(require("./toolbar"), exports);
46
- __exportStar(require("./lib/comments"), exports);
47
- __exportStar(require("./plugins/comments"), exports);
48
46
  var selected_suggestion_1 = require("./plugins/selected-suggestion");
49
47
  Object.defineProperty(exports, "selectedSuggestionKey", { enumerable: true, get: function () { return selected_suggestion_1.selectedSuggestionKey; } });
48
+ __exportStar(require("./plugins/highlight"), exports);
49
+ var comment_annotation_1 = require("./plugins/comment_annotation");
50
+ Object.defineProperty(exports, "commentScroll", { enumerable: true, get: function () { return comment_annotation_1.commentScroll; } });
51
+ Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: function () { return comment_annotation_1.isThereSelector; } });
52
+ Object.defineProperty(exports, "isHighlightComment", { enumerable: true, get: function () { return comment_annotation_1.isHighlightComment; } });
50
53
  __exportStar(require("./lib/utils"), exports);
51
54
  __exportStar(require("./lib/track-changes-utils"), exports);
52
55
  __exportStar(require("./useEditor"), exports);
@@ -164,12 +164,12 @@ class ContextMenu {
164
164
  }
165
165
  }));
166
166
  }
167
- const { addComment } = this.actions;
168
- if (addComment) {
167
+ const { setComment } = this.actions;
168
+ if (setComment) {
169
169
  menu.appendChild(this.createMenuSection((section) => {
170
170
  section.appendChild(this.createMenuItem('Comment', () => {
171
- const target = this.getCommentTarget();
172
- (0, commands_1.addNodeComment)(target, this.view.state, this.view.dispatch);
171
+ const { state, dispatch } = this.view;
172
+ (0, commands_1.addComment)(state, dispatch, this.node, this.resolvePos());
173
173
  popper.destroy();
174
174
  }));
175
175
  }));
@@ -378,17 +378,6 @@ class ContextMenu {
378
378
  this.trimTitle = (title, max) => {
379
379
  return title.length > max ? title.substring(0, max) + '…' : title;
380
380
  };
381
- this.getCommentTarget = () => {
382
- if (this.node.type === transform_1.schema.nodes.section_title) {
383
- const $pos = this.resolvePos();
384
- const parent = $pos.parent;
385
- if (parent.type === transform_1.schema.nodes.keywords) {
386
- const groups = (0, prosemirror_utils_1.findChildrenByType)(parent, transform_1.schema.nodes.keyword_group);
387
- return groups.length ? groups[0].node : this.node;
388
- }
389
- }
390
- return this.node;
391
- };
392
381
  this.node = node;
393
382
  this.view = view;
394
383
  this.getPos = getPos;
package/dist/cjs/menus.js CHANGED
@@ -215,8 +215,8 @@ const getEditorMenus = (editor) => {
215
215
  {
216
216
  id: 'insert-comment',
217
217
  label: 'Comment',
218
- isEnabled: isCommandValid(commands_1.addInlineComment),
219
- run: doCommand(commands_1.addInlineComment),
218
+ isEnabled: isCommandValid(commands_1.addComment),
219
+ run: doCommand(commands_1.addComment),
220
220
  },
221
221
  ],
222
222
  };
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addCommentToLeafNode = exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.commentAnnotation = void 0;
4
+ const transform_1 = require("@manuscripts/transform");
5
+ const prosemirror_state_1 = require("prosemirror-state");
6
+ const prosemirror_transform_1 = require("prosemirror-transform");
7
+ const prosemirror_view_1 = require("prosemirror-view");
8
+ const highlight_1 = require("./highlight");
9
+ exports.commentAnnotation = new prosemirror_state_1.PluginKey('comment_annotation');
10
+ const commentScroll = (id, direction, isHighlight) => {
11
+ const elementClass = isHighlight ? 'highlight-marker' : 'block-comment-button';
12
+ const commentIcon = document.querySelector(`[id="${id}"].${elementClass}`);
13
+ const commentCard = document.querySelectorAll(`.comments-group [id="${id}"]`);
14
+ if (commentIcon && commentCard.length > 0) {
15
+ const element = direction === 'editor' ? commentIcon : commentCard.item(0);
16
+ document
17
+ .querySelectorAll(`.selected-comment`)
18
+ .forEach((element) => element.classList.remove('selected-comment'));
19
+ commentIcon.classList.add('selected-comment');
20
+ commentCard.forEach((node) => node.classList.add('selected-comment'));
21
+ element === null || element === void 0 ? void 0 : element.scrollIntoView({
22
+ behavior: 'auto',
23
+ block: 'start',
24
+ inline: 'start',
25
+ });
26
+ }
27
+ };
28
+ exports.commentScroll = commentScroll;
29
+ const isThereSelector = (selector) => !!(selector && Object.keys(selector).length);
30
+ exports.isThereSelector = isThereSelector;
31
+ const isHighlightComment = (comment) => comment.selector &&
32
+ (0, exports.isThereSelector)(comment.selector) &&
33
+ comment.selector.from !== comment.selector.to;
34
+ exports.isHighlightComment = isHighlightComment;
35
+ exports.default = (props) => {
36
+ return new prosemirror_state_1.Plugin({
37
+ key: exports.commentAnnotation,
38
+ state: {
39
+ init: (tr) => {
40
+ if (tr.doc) {
41
+ return commentsState(props.setSelectedComment, tr.doc);
42
+ }
43
+ else {
44
+ return new prosemirror_view_1.DecorationSet();
45
+ }
46
+ },
47
+ apply: (tr, value, oldState, newState) => {
48
+ const meta = tr.getMeta(exports.commentAnnotation);
49
+ if (meta) {
50
+ if (highlight_1.SET_COMMENT in meta) {
51
+ props.setComment(meta[highlight_1.SET_COMMENT]);
52
+ return value;
53
+ }
54
+ }
55
+ const hasCommentChange = !!tr.steps.find((s) => {
56
+ var _a, _b, _c, _d;
57
+ if (s instanceof prosemirror_transform_1.ReplaceStep) {
58
+ if (s.slice.size > 0) {
59
+ return (((_a = newState.doc.nodeAt(s.from + 1)) === null || _a === void 0 ? void 0 : _a.type) ===
60
+ transform_1.schema.nodes.comment ||
61
+ ((_b = newState.doc.nodeAt(s.from)) === null || _b === void 0 ? void 0 : _b.type) ===
62
+ transform_1.schema.nodes.highlight_marker);
63
+ }
64
+ return (((_c = oldState.doc.nodeAt(s.from)) === null || _c === void 0 ? void 0 : _c.type) === transform_1.schema.nodes.comment ||
65
+ ((_d = oldState.doc.nodeAt(s.from)) === null || _d === void 0 ? void 0 : _d.type) ===
66
+ transform_1.schema.nodes.highlight_marker);
67
+ }
68
+ });
69
+ if (hasCommentChange) {
70
+ return commentsState(props.setSelectedComment, tr.doc);
71
+ }
72
+ return value;
73
+ },
74
+ },
75
+ props: {
76
+ decorations: (state) => {
77
+ const pluginState = exports.commentAnnotation.getState(state);
78
+ if (pluginState) {
79
+ return pluginState;
80
+ }
81
+ },
82
+ },
83
+ });
84
+ };
85
+ const getNodePosition = (node, pos) => {
86
+ switch (node.type) {
87
+ case transform_1.schema.nodes.keywords:
88
+ return pos + 2;
89
+ default:
90
+ return pos + 1;
91
+ }
92
+ };
93
+ const commentsState = (setSelectedComment, doc) => {
94
+ const comments = [];
95
+ doc.descendants((node) => {
96
+ if (node.type === transform_1.schema.nodes.comments) {
97
+ node.descendants((comment) => {
98
+ comments.push(comment.attrs);
99
+ });
100
+ return false;
101
+ }
102
+ });
103
+ const commentsMap = comments.reduce((map, { id, target, selector }) => {
104
+ var _a;
105
+ if (!(0, exports.isHighlightComment)({ selector })) {
106
+ const commentId = (0, exports.isThereSelector)(selector) ? id : target;
107
+ map.set(commentId, {
108
+ id,
109
+ target,
110
+ location: (0, exports.isThereSelector)(selector) ? 'point' : 'block',
111
+ count: (((_a = map.get(commentId)) === null || _a === void 0 ? void 0 : _a.count) || 0) + 1,
112
+ });
113
+ }
114
+ return map;
115
+ }, new Map());
116
+ const decorations = [];
117
+ doc.descendants((node, pos) => {
118
+ const id = node.attrs['id'] || node.attrs['rid'];
119
+ const targetComment = commentsMap.get(id);
120
+ if (targetComment) {
121
+ if (node.isAtom && node.type !== transform_1.schema.nodes.highlight_marker) {
122
+ decorations.push(prosemirror_view_1.Decoration.inline(pos, pos + node.nodeSize, {}, {
123
+ toDOM: getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type, isAtom: node.isAtom }), setSelectedComment),
124
+ }));
125
+ }
126
+ else {
127
+ const position = getNodePosition(node, pos);
128
+ decorations.push(prosemirror_view_1.Decoration.widget(position, getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type }), setSelectedComment), { key: targetComment.id }));
129
+ }
130
+ }
131
+ });
132
+ return prosemirror_view_1.DecorationSet.create(doc, decorations);
133
+ };
134
+ const getCommentIcon = (comment, setSelectedComment) => () => {
135
+ const { id, targetType, target, count, location, isAtom } = comment;
136
+ const commentId = location === 'block' ? target : id;
137
+ const element = document.createElement(isAtom ? 'span' : 'div');
138
+ element.id = commentId;
139
+ let elementClass;
140
+ switch (targetType) {
141
+ case transform_1.schema.nodes.section:
142
+ case transform_1.schema.nodes.footnotes_section:
143
+ case transform_1.schema.nodes.bibliography_section:
144
+ elementClass = 'block-comment';
145
+ break;
146
+ case transform_1.schema.nodes.figure_element:
147
+ elementClass = 'figure-comment';
148
+ break;
149
+ case transform_1.schema.nodes.bibliography_item:
150
+ elementClass = 'bibliography-comment';
151
+ break;
152
+ default:
153
+ elementClass = 'inline-comment';
154
+ }
155
+ if (isAtom || location === 'point') {
156
+ element.classList.add('point-comment');
157
+ }
158
+ element.classList.add('block-comment-button', elementClass);
159
+ element.onclick = (e) => {
160
+ e.stopPropagation();
161
+ setSelectedComment(commentId);
162
+ (0, exports.commentScroll)(commentId, 'inspector');
163
+ };
164
+ const groupCommentIcon = (count > 1 &&
165
+ ` <svg class="group-comment-icon" width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
166
+ <rect width="12" height="12" rx="6" fill="#F7B314"></rect>
167
+ <text x="6" y="8" fill="#FFF" font-size="9px" text-anchor="middle" font-weight="400">${count}</text>
168
+ </svg>`) ||
169
+ '';
170
+ element.innerHTML = `
171
+ <svg class="comment-icon" width="16" height="13" viewBox="0 0 16 13" fill="none" xmlns="http://www.w3.org/2000/svg">
172
+ <path d="M4.0625 2.9375V7.3125L1.4375 11.6875H12.8125C13.7794 11.6875 14.5625 10.9044 14.5625 9.9375V2.9375C14.5625 1.97062 13.7794 1.1875 12.8125 1.1875H5.8125C4.84562 1.1875 4.0625 1.97062 4.0625 2.9375Z"
173
+ fill="#FFFCDB" stroke="#FFBD26" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
174
+ <path d="M6.6875 4.6875H11.9375" stroke="#FFBD26" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
175
+ <path d="M6.6875 8.1875H9.3125" stroke="#FFBD26" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
176
+ </svg>
177
+ ${groupCommentIcon}
178
+ `;
179
+ return element;
180
+ };
181
+ const addCommentToLeafNode = (from, to, state, dom) => {
182
+ const commentsDecorationSet = exports.commentAnnotation.getState(state);
183
+ if (commentsDecorationSet) {
184
+ const commentWidget = commentsDecorationSet.find(from, to);
185
+ if (commentWidget.length) {
186
+ const commentElement = commentWidget[0].type.spec.toDOM();
187
+ dom.appendChild(commentElement);
188
+ }
189
+ }
190
+ };
191
+ exports.addCommentToLeafNode = addCommentToLeafNode;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findHighlightMarkers = void 0;
4
+ const transform_1 = require("@manuscripts/transform");
5
+ function findHighlightMarkers(doc) {
6
+ const markers = [];
7
+ let current;
8
+ doc.descendants((node, pos) => {
9
+ if ((0, transform_1.isHighlightMarkerNode)(node)) {
10
+ const { position, tid, id } = node.attrs;
11
+ if (position === 'start') {
12
+ current = {
13
+ start: pos + 1,
14
+ id,
15
+ tid,
16
+ };
17
+ }
18
+ else if (position === 'end' && current) {
19
+ markers.push(Object.assign(Object.assign({}, current), { text: doc.textBetween(current.start, pos, '\n'), end: pos }));
20
+ current = undefined;
21
+ }
22
+ }
23
+ });
24
+ return markers;
25
+ }
26
+ exports.findHighlightMarkers = findHighlightMarkers;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.selectedHighlights = exports.getHighlightTarget = exports.hasHighlightTarget = exports.SET_COMMENT = exports.highlightKey = void 0;
19
+ const prosemirror_state_1 = require("prosemirror-state");
20
+ const prosemirror_view_1 = require("prosemirror-view");
21
+ const findHighlightMarkers_1 = require("./findHighlightMarkers");
22
+ exports.highlightKey = new prosemirror_state_1.PluginKey('highlight');
23
+ exports.SET_COMMENT = 'SET_COMMENT';
24
+ const hasHighlightTarget = (comment) => comment.target.startsWith('MPHighlight:');
25
+ exports.hasHighlightTarget = hasHighlightTarget;
26
+ const getHighlightTarget = (comment, state) => {
27
+ var _a;
28
+ return (_a = exports.highlightKey
29
+ .getState(state)) === null || _a === void 0 ? void 0 : _a.highlights.find((item) => item.id === comment._id);
30
+ };
31
+ exports.getHighlightTarget = getHighlightTarget;
32
+ const selectedHighlights = (state) => {
33
+ var _a;
34
+ const items = [];
35
+ const { selection } = state;
36
+ if (!(selection instanceof prosemirror_state_1.TextSelection)) {
37
+ return items;
38
+ }
39
+ const { $cursor } = selection;
40
+ if (!$cursor) {
41
+ return items;
42
+ }
43
+ const { pos } = $cursor;
44
+ (_a = exports.highlightKey.getState(state)) === null || _a === void 0 ? void 0 : _a.highlights.forEach((highlight) => {
45
+ if (highlight.start <= pos && highlight.end >= pos) {
46
+ items.push(highlight);
47
+ }
48
+ });
49
+ return items;
50
+ };
51
+ exports.selectedHighlights = selectedHighlights;
52
+ const buildPluginState = (doc) => {
53
+ const highlights = (0, findHighlightMarkers_1.findHighlightMarkers)(doc);
54
+ const decorations = prosemirror_view_1.DecorationSet.create(doc, highlights.map((h) => prosemirror_view_1.Decoration.inline(h.start, h.end, {
55
+ nodeName: 'span',
56
+ class: 'highlight',
57
+ })));
58
+ return { highlights, decorations };
59
+ };
60
+ exports.default = (props) => {
61
+ return new prosemirror_state_1.Plugin({
62
+ key: exports.highlightKey,
63
+ state: {
64
+ init: (tr, state) => buildPluginState(state.doc),
65
+ apply: (tr, value) => {
66
+ const meta = tr.getMeta(exports.highlightKey);
67
+ if (meta && exports.SET_COMMENT in meta) {
68
+ props.setComment(meta[exports.SET_COMMENT]);
69
+ }
70
+ else if (!tr.docChanged || tr.step.length === 0) {
71
+ return value;
72
+ }
73
+ return buildPluginState(tr.doc);
74
+ },
75
+ },
76
+ props: {
77
+ decorations: (state) => {
78
+ const pluginState = exports.highlightKey.getState(state);
79
+ if (pluginState) {
80
+ return pluginState.decorations;
81
+ }
82
+ },
83
+ },
84
+ });
85
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });