@manuscripts/body-editor 1.7.4 → 1.7.6-LEAN-3342-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 (51) hide show
  1. package/dist/cjs/assets.js +25 -1
  2. package/dist/cjs/commands.js +62 -1
  3. package/dist/cjs/configs/editor-plugins.js +2 -4
  4. package/dist/cjs/index.js +3 -1
  5. package/dist/cjs/lib/context-menu.js +29 -0
  6. package/dist/cjs/lib/track-changes-utils.js +13 -4
  7. package/dist/cjs/plugins/comment_annotation.js +2 -1
  8. package/dist/cjs/plugins/footnotes/index.js +13 -3
  9. package/dist/cjs/plugins/placeholder.js +3 -1
  10. package/dist/cjs/plugins/selected-suggestion-ui.js +129 -0
  11. package/dist/cjs/views/affiliation.js +2 -1
  12. package/dist/cjs/views/bibliography_element.js +23 -6
  13. package/dist/cjs/views/citation.js +4 -1
  14. package/dist/cjs/views/contributors.js +14 -3
  15. package/dist/cjs/views/cross_reference.js +4 -1
  16. package/dist/cjs/views/keyword.js +17 -7
  17. package/dist/es/assets.js +24 -0
  18. package/dist/es/commands.js +59 -0
  19. package/dist/es/configs/editor-plugins.js +2 -4
  20. package/dist/es/index.js +1 -0
  21. package/dist/es/lib/context-menu.js +30 -1
  22. package/dist/es/lib/track-changes-utils.js +11 -3
  23. package/dist/es/plugins/comment_annotation.js +2 -1
  24. package/dist/es/plugins/footnotes/index.js +13 -3
  25. package/dist/es/plugins/placeholder.js +1 -1
  26. package/dist/es/plugins/selected-suggestion-ui.js +126 -0
  27. package/dist/es/views/affiliation.js +2 -1
  28. package/dist/es/views/bibliography_element.js +22 -5
  29. package/dist/es/views/citation.js +4 -1
  30. package/dist/es/views/contributors.js +14 -3
  31. package/dist/es/views/cross_reference.js +4 -1
  32. package/dist/es/views/keyword.js +17 -7
  33. package/dist/types/assets.d.ts +1 -0
  34. package/dist/types/commands.d.ts +3 -0
  35. package/dist/types/configs/editor-plugins.d.ts +1 -1
  36. package/dist/types/index.d.ts +1 -0
  37. package/dist/types/lib/track-changes-utils.d.ts +3 -1
  38. package/dist/types/plugins/placeholder.d.ts +2 -0
  39. package/dist/types/plugins/{track-changes-ui.d.ts → selected-suggestion-ui.d.ts} +7 -5
  40. package/dist/types/views/affiliation.d.ts +0 -1
  41. package/dist/types/views/base_node_view.d.ts +1 -0
  42. package/dist/types/views/bibliography_element.d.ts +1 -0
  43. package/dist/types/views/contributors.d.ts +1 -1
  44. package/package.json +1 -1
  45. package/styles/AdvancedEditor.css +18 -3
  46. package/styles/Editor.css +1 -0
  47. package/dist/cjs/plugins/track-changes-ui.js +0 -104
  48. package/dist/cjs/plugins/tracking-mark.js +0 -123
  49. package/dist/es/plugins/track-changes-ui.js +0 -102
  50. package/dist/es/plugins/tracking-mark.js +0 -118
  51. package/dist/types/plugins/tracking-mark.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.commentIcon = exports.editIcon = void 0;
18
+ exports.editAttrsTrackingIcon = exports.commentIcon = exports.editIcon = void 0;
19
19
  exports.editIcon = `
20
20
  <svg
21
21
  width="14"
@@ -78,3 +78,27 @@ exports.commentIcon = `
78
78
  />
79
79
  </svg>
80
80
  `;
81
+ exports.editAttrsTrackingIcon = `
82
+ <svg
83
+ width="16"
84
+ height="16"
85
+ viewBox="0 0 16 16"
86
+ fill="none"
87
+ xmlns="http://www.w3.org/2000/svg"
88
+ >
89
+ <path
90
+ d="M12 2L14 4L9 9L6 10L7 7L12 2Z"
91
+ stroke="#353535"
92
+ stroke-width="1.5"
93
+ stroke-linecap="round"
94
+ stroke-linejoin="round"
95
+ />
96
+ <path
97
+ d="M13 10V11.5C13 12.328 12.328 13 11.5 13H4.5C3.672 13 3 12.328 3 11.5V4.5C3 3.672 3.672 3 4.5 3H6"
98
+ stroke="#353535"
99
+ stroke-width="1.5"
100
+ stroke-linecap="round"
101
+ stroke-linejoin="round"
102
+ />
103
+ </svg>
104
+ `;
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.updateCommentAnnotationState = exports.addComment = exports.deleteHighlightMarkers = exports.insertHighlight = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = 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.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.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");
@@ -122,6 +122,29 @@ const createBlock = (nodeType, position, state, dispatch) => {
122
122
  }
123
123
  };
124
124
  exports.createBlock = createBlock;
125
+ const insertGeneralFootnote = (tableNode, position, state, dispatch, tableElementFooter, view) => {
126
+ var _a;
127
+ const generalNote = state.schema.nodes.paragraph.create();
128
+ const tr = state.tr;
129
+ const pos = (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length)
130
+ ? position + tableElementFooter[0].pos + 2
131
+ : position + (((_a = tableNode.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize) || 0);
132
+ if (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length) {
133
+ tr.insert(pos, generalNote);
134
+ }
135
+ else {
136
+ const tableElementFooter = transform_1.schema.nodes.table_element_footer.create({
137
+ id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.TableElementFooter),
138
+ }, [generalNote]);
139
+ tr.insert(pos, tableElementFooter);
140
+ }
141
+ if (dispatch && pos) {
142
+ const selection = (0, exports.createSelection)(state.schema.nodes.paragraph, pos, tr.doc);
143
+ view === null || view === void 0 ? void 0 : view.focus();
144
+ dispatch(tr.setSelection(selection).scrollIntoView());
145
+ }
146
+ };
147
+ exports.insertGeneralFootnote = insertGeneralFootnote;
125
148
  const insertFileAsFigure = (file, state, dispatch) => {
126
149
  const position = findBlockInsertPosition(state);
127
150
  if (position === null || !dispatch) {
@@ -688,3 +711,41 @@ const updateCommentAnnotationState = (state, dispatch) => {
688
711
  }
689
712
  };
690
713
  exports.updateCommentAnnotationState = updateCommentAnnotationState;
714
+ const insertTableFootnote = (node, position, state, dispatch) => {
715
+ var _a;
716
+ const footnote = state.schema.nodes.footnote.createAndFill({
717
+ id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Footnote),
718
+ kind: 'footnote',
719
+ });
720
+ const insertedAt = state.selection.to;
721
+ const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote);
722
+ const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
723
+ rids: [footnote.attrs.id],
724
+ contents: inlineFootnotes.length + 1,
725
+ });
726
+ const tr = state.tr;
727
+ tr.insert(insertedAt, inlineFootnoteNode);
728
+ const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
729
+ const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_element_footer);
730
+ let insertionPos;
731
+ if (tableElementFooter.length) {
732
+ const pos = tableElementFooter[0].pos;
733
+ insertionPos = position + pos + tableElementFooter[0].node.nodeSize + 1;
734
+ tr.insert(insertionPos, footnoteElement);
735
+ }
736
+ else {
737
+ const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
738
+ if (tableSize) {
739
+ insertionPos = position + tableSize + 2;
740
+ const tableElementFooter = transform_1.schema.nodes.table_element_footer.create({
741
+ id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.TableElementFooter),
742
+ }, [footnoteElement]);
743
+ tr.insert(insertionPos, tableElementFooter);
744
+ }
745
+ }
746
+ if (dispatch && insertionPos) {
747
+ const nodeSelection = prosemirror_state_1.NodeSelection.create(tr.doc, insertionPos);
748
+ dispatch(tr.setSelection(nodeSelection));
749
+ }
750
+ };
751
+ exports.insertTableFootnote = insertTableFootnote;
@@ -36,10 +36,9 @@ const paragraphs_1 = __importDefault(require("../plugins/paragraphs"));
36
36
  const persist_1 = __importDefault(require("../plugins/persist"));
37
37
  const placeholder_1 = __importDefault(require("../plugins/placeholder"));
38
38
  const sections_1 = __importDefault(require("../plugins/sections"));
39
+ const selected_suggestion_ui_1 = __importDefault(require("../plugins/selected-suggestion-ui"));
39
40
  const tables_cursor_fix_1 = __importDefault(require("../plugins/tables-cursor-fix"));
40
41
  const toc_1 = __importDefault(require("../plugins/toc"));
41
- const track_changes_ui_1 = __importDefault(require("../plugins/track-changes-ui"));
42
- const tracking_mark_1 = __importDefault(require("../plugins/tracking-mark"));
43
42
  const rules_1 = __importDefault(require("../rules"));
44
43
  exports.default = (props) => {
45
44
  const plugins = props.plugins || [];
@@ -62,8 +61,7 @@ exports.default = (props) => {
62
61
  (0, placeholder_1.default)(),
63
62
  (0, prosemirror_tables_1.tableEditing)(),
64
63
  (0, highlight_1.default)(props),
65
- (0, track_changes_ui_1.default)(props),
66
- (0, tracking_mark_1.default)(),
64
+ (0, selected_suggestion_ui_1.default)(props),
67
65
  (0, footnotes_1.default)(),
68
66
  ];
69
67
  if (props.collabProvider) {
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.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.PopperManager = exports.CollabProvider = exports.LevelSelector = exports.OutlineManuscript = exports.OutlineItemIcon = exports.ManuscriptOutline = void 0;
32
+ exports.SET_SUGGESTION_ID = exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.PopperManager = exports.CollabProvider = exports.LevelSelector = exports.OutlineManuscript = exports.OutlineItemIcon = exports.ManuscriptOutline = void 0;
33
33
  __exportStar(require("./citation-sources"), exports);
34
34
  __exportStar(require("./commands"), exports);
35
35
  var ManuscriptOutline_1 = require("./components/outline/ManuscriptOutline");
@@ -51,6 +51,8 @@ var comment_annotation_1 = require("./plugins/comment_annotation");
51
51
  Object.defineProperty(exports, "commentScroll", { enumerable: true, get: function () { return comment_annotation_1.commentScroll; } });
52
52
  Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: function () { return comment_annotation_1.isThereSelector; } });
53
53
  Object.defineProperty(exports, "isHighlightComment", { enumerable: true, get: function () { return comment_annotation_1.isHighlightComment; } });
54
+ var selected_suggestion_ui_1 = require("./plugins/selected-suggestion-ui");
55
+ Object.defineProperty(exports, "SET_SUGGESTION_ID", { enumerable: true, get: function () { return selected_suggestion_ui_1.SET_SUGGESTION_ID; } });
54
56
  __exportStar(require("./lib/utils"), exports);
55
57
  __exportStar(require("./lib/track-changes-utils"), exports);
56
58
  __exportStar(require("./useEditor"), exports);
@@ -17,6 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.ContextMenu = exports.sectionLevel = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
+ const prosemirror_utils_1 = require("prosemirror-utils");
20
21
  const commands_1 = require("../commands");
21
22
  const popper_1 = require("./popper");
22
23
  const popper = new popper_1.PopperManager();
@@ -134,6 +135,7 @@ class ContextMenu {
134
135
  this.addPopperEventListeners();
135
136
  };
136
137
  this.showEditMenu = (target) => {
138
+ var _a;
137
139
  const menu = document.createElement('div');
138
140
  menu.className = 'menu';
139
141
  const $pos = this.resolvePos();
@@ -164,6 +166,33 @@ class ContextMenu {
164
166
  }));
165
167
  }));
166
168
  }
169
+ if (type === transform_1.schema.nodes.table_element) {
170
+ const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.table_element_footer);
171
+ const hasGeneralNote = tableElementFooter.length &&
172
+ ((_a = tableElementFooter[0].node.firstChild) === null || _a === void 0 ? void 0 : _a.type) === transform_1.schema.nodes.paragraph;
173
+ if (!hasGeneralNote) {
174
+ menu.appendChild(this.createMenuSection((section) => {
175
+ section.appendChild(this.createMenuItem('Add General Note', () => {
176
+ const { state, dispatch } = this.view;
177
+ (0, commands_1.insertGeneralFootnote)(this.node, this.getPos(), state, dispatch, tableElementFooter, this.view);
178
+ }));
179
+ }));
180
+ }
181
+ }
182
+ if (type === transform_1.schema.nodes.table_element) {
183
+ const isInTable = (0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.table)(this.view.state.selection);
184
+ if (isInTable) {
185
+ menu.appendChild(this.createMenuSection((section) => {
186
+ section.appendChild(this.createMenuItem('Add Reference Note', () => {
187
+ const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.footnotes_element);
188
+ if (!footnotesElement.length) {
189
+ const { state, dispatch } = this.view;
190
+ (0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
191
+ }
192
+ }));
193
+ }));
194
+ }
195
+ }
167
196
  if (!readonlyTypes.includes(type) &&
168
197
  !readonlyTypes.includes($pos.parent.type)) {
169
198
  menu.appendChild(this.createMenuSection((section) => {
@@ -15,7 +15,8 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getActualAttrs = exports.isTracked = exports.getChangeClasses = exports.isPendingSetAttrs = exports.isPending = exports.isPendingInsert = exports.isDeleted = exports.isRejectedInsert = void 0;
18
+ exports.getAttrsTrackingButton = exports.getActualAttrs = exports.isTracked = exports.getChangeClasses = exports.isPendingSetAttrs = exports.isPending = exports.isPendingInsert = exports.isDeleted = exports.isRejectedInsert = void 0;
19
+ const assets_1 = require("../assets");
19
20
  function isRejectedInsert(node) {
20
21
  if (node.attrs.dataTracked) {
21
22
  const changes = node.attrs.dataTracked;
@@ -56,10 +57,10 @@ function isPendingSetAttrs(node) {
56
57
  return false;
57
58
  }
58
59
  exports.isPendingSetAttrs = isPendingSetAttrs;
59
- function getChangeClasses(node) {
60
+ function getChangeClasses(dataTracked) {
60
61
  const classes = [];
61
- if (node.attrs.dataTracked) {
62
- const changes = node.attrs.dataTracked;
62
+ if (dataTracked) {
63
+ const changes = dataTracked;
63
64
  const operationClasses = new Map([
64
65
  ['insert', 'inserted'],
65
66
  ['delete', 'deleted'],
@@ -90,3 +91,11 @@ function getActualAttrs(node) {
90
91
  return attrs;
91
92
  }
92
93
  exports.getActualAttrs = getActualAttrs;
94
+ const getAttrsTrackingButton = (changeID) => {
95
+ const el = document.createElement('button');
96
+ el.className = 'attrs-popper-button';
97
+ el.value = changeID;
98
+ el.innerHTML = assets_1.editAttrsTrackingIcon;
99
+ return el;
100
+ };
101
+ exports.getAttrsTrackingButton = getAttrsTrackingButton;
@@ -130,7 +130,8 @@ const getCommentIcon = (comment, setSelectedComment) => () => {
130
130
  element.classList.add(location === 'point' ? 'point-comment' : 'inline-citation');
131
131
  }
132
132
  element.classList.add('block-comment-button', elementClass);
133
- element.onclick = () => {
133
+ element.onclick = (e) => {
134
+ e.stopPropagation();
134
135
  setSelectedComment(commentId);
135
136
  (0, exports.commentScroll)(commentId, 'inspector');
136
137
  };
@@ -22,6 +22,7 @@ const prosemirror_state_1 = require("prosemirror-state");
22
22
  const prosemirror_utils_1 = require("prosemirror-utils");
23
23
  const prosemirror_view_1 = require("prosemirror-view");
24
24
  const utils_1 = require("../../lib/utils");
25
+ const placeholder_1 = require("../placeholder");
25
26
  exports.footnotesKey = new prosemirror_state_1.PluginKey('footnotes');
26
27
  const buildPluginState = (doc) => {
27
28
  const nodes = [];
@@ -101,9 +102,10 @@ exports.default = () => {
101
102
  }
102
103
  const { labels } = exports.footnotesKey.getState(state);
103
104
  state.doc.descendants((node, pos) => {
104
- if (labels) {
105
- if ((0, transform_1.isFootnoteNode)(node)) {
106
- const id = node.attrs.id;
105
+ var _a, _b;
106
+ if ((0, transform_1.isFootnoteNode)(node)) {
107
+ const id = node.attrs.id;
108
+ if (labels) {
107
109
  const label = labels.get(id);
108
110
  if (label) {
109
111
  decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, labelWidget(label, id), {
@@ -111,12 +113,20 @@ exports.default = () => {
111
113
  }));
112
114
  }
113
115
  }
116
+ if (!((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.textContent)) {
117
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, placeholder_1.placeholderWidget)('Add new note here')));
118
+ }
114
119
  }
115
120
  if (node.type === transform_1.schema.nodes.footnotes_element) {
116
121
  decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
117
122
  class: 'footnote-element',
118
123
  }));
119
124
  }
125
+ if (node.type === transform_1.schema.nodes.table_element_footer) {
126
+ if (((_b = node.firstChild) === null || _b === void 0 ? void 0 : _b.type) === transform_1.schema.nodes.paragraph) {
127
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, placeholder_1.placeholderWidget)('Add general note here')));
128
+ }
129
+ }
120
130
  });
121
131
  return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
122
132
  },
@@ -15,6 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.placeholderWidget = void 0;
18
19
  const prosemirror_state_1 = require("prosemirror-state");
19
20
  const prosemirror_view_1 = require("prosemirror-view");
20
21
  const placeholderWidget = (placeholder) => (view, getPos) => {
@@ -27,6 +28,7 @@ const placeholderWidget = (placeholder) => (view, getPos) => {
27
28
  });
28
29
  return element;
29
30
  };
31
+ exports.placeholderWidget = placeholderWidget;
30
32
  exports.default = () => new prosemirror_state_1.Plugin({
31
33
  props: {
32
34
  decorations: (state) => {
@@ -38,7 +40,7 @@ exports.default = () => new prosemirror_state_1.Plugin({
38
40
  node.type.isBlock &&
39
41
  node.childCount === 0) {
40
42
  if (node.type === node.type.schema.nodes.paragraph) {
41
- decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, placeholderWidget(placeholder)));
43
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, (0, exports.placeholderWidget)(placeholder)));
42
44
  }
43
45
  else {
44
46
  decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
@@ -0,0 +1,129 @@
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.selectedSuggestionKey = exports.SET_SUGGESTION_ID = void 0;
19
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
20
+ const lodash_1 = require("lodash");
21
+ const prosemirror_state_1 = require("prosemirror-state");
22
+ const prosemirror_view_1 = require("prosemirror-view");
23
+ class SuggestionView {
24
+ constructor(view) {
25
+ this.listener = (e) => {
26
+ const changeId = e.currentTarget.getAttribute('data-track-id');
27
+ this.view.dispatch(this.view.state.tr.setMeta(exports.SET_SUGGESTION_ID, changeId));
28
+ };
29
+ this.view = view;
30
+ this.addEventListener(view);
31
+ this.update(view, undefined);
32
+ }
33
+ update(view, prevState) {
34
+ var _a, _b;
35
+ this.view = view;
36
+ if (!prevState) {
37
+ return;
38
+ }
39
+ const oldChanges = ((_a = track_changes_plugin_1.trackChangesPluginKey.getState(prevState)) === null || _a === void 0 ? void 0 : _a.changeSet.changes) || [];
40
+ const newChangeSet = (_b = track_changes_plugin_1.trackChangesPluginKey.getState(view.state)) === null || _b === void 0 ? void 0 : _b.changeSet;
41
+ if (newChangeSet && !(0, lodash_1.isEqual)(oldChanges, newChangeSet.changes)) {
42
+ this.addEventListener(view);
43
+ oldChanges.map((change) => {
44
+ var _a;
45
+ if (!newChangeSet.get(change.id) ||
46
+ ((_a = newChangeSet.get(change.id)) === null || _a === void 0 ? void 0 : _a.dataTracked.status) === 'rejected') {
47
+ const dom = view.dom.querySelector(`[data-track-id="${change.id}"]`);
48
+ dom === null || dom === void 0 ? void 0 : dom.removeEventListener('click', this.listener);
49
+ }
50
+ });
51
+ }
52
+ }
53
+ destroy() {
54
+ this.view.dom
55
+ .querySelectorAll('[data-track-status="pending"], [data-track-status="accepted"]')
56
+ .forEach((dom) => {
57
+ var _a, _b;
58
+ if ((_b = (_a = dom.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.classList.contains('keyword')) {
59
+ return;
60
+ }
61
+ dom.removeEventListener('click', this.listener);
62
+ });
63
+ }
64
+ addEventListener(view) {
65
+ view.dom
66
+ .querySelectorAll('[data-track-status="pending"], [data-track-status="accepted"]')
67
+ .forEach((dom) => {
68
+ var _a, _b;
69
+ if ((_b = (_a = dom.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.classList.contains('keyword')) {
70
+ return;
71
+ }
72
+ dom.addEventListener('click', this.listener);
73
+ });
74
+ }
75
+ }
76
+ const getTrackChangesData = (node) => {
77
+ var _a;
78
+ const trackChangesMark = node.marks.find((mark) => (mark.type.name === 'tracked_insert' ||
79
+ mark.type.name === 'tracked_delete') &&
80
+ mark.attrs.dataTracked);
81
+ return (_a = trackChangesMark === null || trackChangesMark === void 0 ? void 0 : trackChangesMark.attrs) === null || _a === void 0 ? void 0 : _a.dataTracked;
82
+ };
83
+ exports.SET_SUGGESTION_ID = 'SET_SELECTED_SUGGESTION_ID';
84
+ const CLEAR_SUGGESTION_ID = 'CLEAR_SUGGESTION_ID';
85
+ exports.selectedSuggestionKey = new prosemirror_state_1.PluginKey('selected_suggestion');
86
+ exports.default = (props) => new prosemirror_state_1.Plugin({
87
+ key: exports.selectedSuggestionKey,
88
+ view: (view) => new SuggestionView(view),
89
+ state: {
90
+ init: () => prosemirror_view_1.DecorationSet.empty,
91
+ apply: (tr, value, _, state) => {
92
+ const suggestionId = tr.getMeta(exports.SET_SUGGESTION_ID);
93
+ if (suggestionId) {
94
+ return buildSelectedSuggestionDecoration(suggestionId, state, props);
95
+ }
96
+ if (tr.getMeta(CLEAR_SUGGESTION_ID) ||
97
+ tr.getMeta('track-changes-refresh-changes')) {
98
+ props.setEditorSelectedSuggestion(undefined);
99
+ return prosemirror_view_1.DecorationSet.empty;
100
+ }
101
+ return value;
102
+ },
103
+ },
104
+ props: {
105
+ handleClick(view, pos) {
106
+ const nodeClicked = view.state.doc.nodeAt(pos);
107
+ const trackChangesData = nodeClicked && getTrackChangesData(nodeClicked);
108
+ if (!trackChangesData) {
109
+ view.dispatch(view.state.tr.setMeta(CLEAR_SUGGESTION_ID, true));
110
+ props.setEditorSelectedSuggestion(undefined);
111
+ }
112
+ },
113
+ decorations: (state) => exports.selectedSuggestionKey.getState(state),
114
+ },
115
+ });
116
+ const buildSelectedSuggestionDecoration = (suggestionId, state, props) => {
117
+ var _a;
118
+ const change = (_a = track_changes_plugin_1.trackChangesPluginKey
119
+ .getState(state)) === null || _a === void 0 ? void 0 : _a.changeSet.get(suggestionId);
120
+ const decorations = [];
121
+ if (change) {
122
+ const decoration = change.type === 'text-change' ? prosemirror_view_1.Decoration.inline : prosemirror_view_1.Decoration.node;
123
+ decorations.push(decoration(change.from, change.to, {
124
+ class: 'selected-suggestion',
125
+ }));
126
+ props.setEditorSelectedSuggestion(change.id);
127
+ }
128
+ return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
129
+ };
@@ -39,10 +39,12 @@ class AffiliationView extends base_node_view_1.BaseNodeView {
39
39
  this.dom.setAttribute('style', 'order: ' + (order || (pluginState === null || pluginState === void 0 ? void 0 : pluginState.affiliations.length) + 1));
40
40
  }
41
41
  if ((_a = attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
42
+ this.dom.setAttribute('data-track-id', attrs.dataTracked[0].id);
42
43
  this.dom.setAttribute('data-track-status', attrs.dataTracked[0].status);
43
44
  this.dom.setAttribute('data-track-op', attrs.dataTracked[0].operation);
44
45
  }
45
46
  else {
47
+ this.dom.removeAttribute('data-track-id');
46
48
  this.dom.removeAttribute('data-track-status');
47
49
  this.dom.removeAttribute('data-track-type');
48
50
  }
@@ -54,7 +56,6 @@ class AffiliationView extends base_node_view_1.BaseNodeView {
54
56
  this.updateContents();
55
57
  };
56
58
  this.ignoreMutation = () => true;
57
- this.stopEvent = () => true;
58
59
  this.formatAddress = (affiliation) => {
59
60
  const { department, institution, addressLine1, city, county, country, postCode, } = affiliation;
60
61
  return [
@@ -32,9 +32,10 @@ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
32
32
  const transform_1 = require("@manuscripts/transform");
33
33
  const assets_1 = require("../assets");
34
34
  const dompurify_1 = require("../lib/dompurify");
35
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
35
36
  const bibliography_1 = require("../plugins/bibliography");
36
37
  const comment_annotation_1 = require("../plugins/comment_annotation");
37
- const tracking_mark_1 = require("../plugins/tracking-mark");
38
+ const selected_suggestion_ui_1 = require("../plugins/selected-suggestion-ui");
38
39
  const block_view_1 = __importDefault(require("./block_view"));
39
40
  const creators_1 = require("./creators");
40
41
  const ReactSubView_1 = __importDefault(require("./ReactSubView"));
@@ -61,11 +62,13 @@ class BibliographyElementBlockView extends block_view_1.default {
61
62
  this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
62
63
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
63
64
  const commentsDecorationSet = comment_annotation_1.commentAnnotation.getState(this.view.state);
65
+ const selectedSuggestion = selected_suggestion_ui_1.selectedSuggestionKey.getState(this.view.state);
64
66
  const commentElementMap = new Map();
65
67
  const dataTrackedMap = new Map();
68
+ let selectedBibItemSuggestion;
66
69
  this.node.descendants((node, pos) => {
70
+ const nodePosition = this.getPos() + pos + 2;
67
71
  if (commentsDecorationSet) {
68
- const nodePosition = this.getPos() + pos + 2;
69
72
  const commentWidget = commentsDecorationSet.find(nodePosition, nodePosition);
70
73
  if (commentWidget.length) {
71
74
  const commentElement = commentWidget[0].type.toDOM();
@@ -77,6 +80,10 @@ class BibliographyElementBlockView extends block_view_1.default {
77
80
  const lastChange = dataTracked[dataTracked.length - 1];
78
81
  dataTrackedMap.set(node.attrs.id, lastChange);
79
82
  }
83
+ if ((dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.length) &&
84
+ (selectedSuggestion === null || selectedSuggestion === void 0 ? void 0 : selectedSuggestion.find(nodePosition, nodePosition + node.nodeSize).length)) {
85
+ selectedBibItemSuggestion = node.attrs.id;
86
+ }
80
87
  });
81
88
  const can = this.props.getCapabilities();
82
89
  const wrapper = document.createElement('div');
@@ -114,13 +121,16 @@ class BibliographyElementBlockView extends block_view_1.default {
114
121
  }
115
122
  const dataTracked = dataTrackedMap.get(element.id);
116
123
  if (dataTracked) {
117
- element.classList.add('attrs-track-mark');
118
- const decoration = (0, tracking_mark_1.getMarkDecoration)(dataTracked);
119
- decoration.style && element.setAttribute('style', decoration.style);
124
+ element.classList.add('attrs-track-mark', ...(0, track_changes_utils_1.getChangeClasses)([dataTracked]));
120
125
  if (dataTracked.status === track_changes_plugin_1.CHANGE_STATUS.pending &&
121
126
  dataTracked.operation === track_changes_plugin_1.CHANGE_OPERATION.set_node_attributes) {
122
- element.appendChild((0, tracking_mark_1.getAttrsTrackingButton)(dataTracked.id));
127
+ element.appendChild((0, track_changes_utils_1.getAttrsTrackingButton)(dataTracked.id));
123
128
  }
129
+ this.addClickListenerToBibItem(element, dataTracked);
130
+ }
131
+ if (selectedBibItemSuggestion &&
132
+ selectedBibItemSuggestion === element.id) {
133
+ element.classList.add('selected-suggestion');
124
134
  }
125
135
  wrapper.append(element);
126
136
  }
@@ -146,6 +156,13 @@ class BibliographyElementBlockView extends block_view_1.default {
146
156
  this.handleDelete = (item) => {
147
157
  return this.deleteNode(item._id);
148
158
  };
159
+ this.addClickListenerToBibItem = (element, dataTracked) => {
160
+ if (dataTracked.status !== track_changes_plugin_1.CHANGE_STATUS.rejected) {
161
+ element.addEventListener('click', () => {
162
+ this.view.dispatch(this.view.state.tr.setMeta(selected_suggestion_ui_1.SET_SUGGESTION_ID, dataTracked.id));
163
+ });
164
+ }
165
+ };
149
166
  }
150
167
  }
151
168
  exports.BibliographyElementBlockView = BibliographyElementBlockView;
@@ -47,7 +47,10 @@ class CitationView extends base_node_view_1.BaseNodeView {
47
47
  this.updateContents = () => {
48
48
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
49
49
  const citation = this.getCitation();
50
- const classes = ['citation', ...(0, track_changes_utils_1.getChangeClasses)(this.node)];
50
+ const classes = [
51
+ 'citation',
52
+ ...(0, track_changes_utils_1.getChangeClasses)(this.node.attrs.dataTracked),
53
+ ];
51
54
  const element = document.createElement('span');
52
55
  element.className = classes.join(' ');
53
56
  const text = bib.renderedCitations.get(citation._id);
@@ -8,6 +8,7 @@ const style_guide_1 = require("@manuscripts/style-guide");
8
8
  const transform_1 = require("@manuscripts/transform");
9
9
  const track_changes_utils_1 = require("../lib/track-changes-utils");
10
10
  const affiliations_1 = require("../plugins/affiliations");
11
+ const selected_suggestion_ui_1 = require("../plugins/selected-suggestion-ui");
11
12
  const block_view_1 = __importDefault(require("./block_view"));
12
13
  const creators_1 = require("./creators");
13
14
  const ReactSubView_1 = __importDefault(require("./ReactSubView"));
@@ -31,12 +32,17 @@ class ContributorsView extends block_view_1.default {
31
32
  };
32
33
  this.buildAuthors = () => {
33
34
  var _a;
35
+ const selectedSuggestion = selected_suggestion_ui_1.selectedSuggestionKey.getState(this.view.state);
36
+ let selectedAuthor;
34
37
  const authors = [];
35
38
  const authorsWrapper = document.createElement('div');
36
39
  authorsWrapper.classList.add('contributors-list');
37
- (_a = this.node.content) === null || _a === void 0 ? void 0 : _a.forEach((node) => {
40
+ (_a = this.node.content) === null || _a === void 0 ? void 0 : _a.forEach((node, offset) => {
38
41
  if ((0, transform_1.isContributorNode)(node)) {
39
42
  authors.push(node);
43
+ if (selectedSuggestion === null || selectedSuggestion === void 0 ? void 0 : selectedSuggestion.find(this.getPos() + offset + 2, this.getPos() + offset + node.nodeSize + 2).length) {
44
+ selectedAuthor = node.attrs.id;
45
+ }
40
46
  }
41
47
  });
42
48
  authors
@@ -46,11 +52,11 @@ class ContributorsView extends block_view_1.default {
46
52
  return;
47
53
  }
48
54
  const jointAuthors = this.isJointFirstAuthor(authors, i);
49
- authorsWrapper.appendChild(this.buildAuthor(author, jointAuthors));
55
+ authorsWrapper.appendChild(this.buildAuthor(author, jointAuthors, selectedAuthor));
50
56
  });
51
57
  this.container.appendChild(authorsWrapper);
52
58
  };
53
- this.buildAuthor = (node, isJointFirstAuthor) => {
59
+ this.buildAuthor = (node, isJointFirstAuthor, selectedAuthor) => {
54
60
  var _a;
55
61
  const pluginState = affiliations_1.affiliationsKey.getState(this.view.state);
56
62
  const attrs = node.attrs;
@@ -60,10 +66,12 @@ class ContributorsView extends block_view_1.default {
60
66
  container.setAttribute('id', attrs.id);
61
67
  container.setAttribute('contenteditable', 'false');
62
68
  if ((_a = attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
69
+ container.setAttribute('data-track-id', attrs.dataTracked[0].id);
63
70
  container.setAttribute('data-track-status', attrs.dataTracked[0].status);
64
71
  container.setAttribute('data-track-op', attrs.dataTracked[0].operation);
65
72
  }
66
73
  else {
74
+ container.removeAttribute('data-track-id');
67
75
  container.removeAttribute('data-track-status');
68
76
  container.removeAttribute('data-track-type');
69
77
  }
@@ -100,6 +108,9 @@ class ContributorsView extends block_view_1.default {
100
108
  if (displayAttr.isCorresponding) {
101
109
  container.appendChild(this.createNote('*', 'Corresponding author'));
102
110
  }
111
+ if (selectedAuthor && selectedAuthor === attrs.id) {
112
+ container.classList.add('selected-suggestion');
113
+ }
103
114
  return container;
104
115
  };
105
116
  this.initials = (given) => given
@@ -36,7 +36,10 @@ class CrossReferenceView extends base_node_view_1.BaseNodeView {
36
36
  });
37
37
  };
38
38
  this.updateContents = () => {
39
- const nodeClasses = ['cross-reference', ...(0, track_changes_utils_1.getChangeClasses)(this.node)];
39
+ const nodeClasses = [
40
+ 'cross-reference',
41
+ ...(0, track_changes_utils_1.getChangeClasses)(this.node.attrs.dataTracked),
42
+ ];
40
43
  this.dom.className = nodeClasses.join(' ');
41
44
  this.dom.textContent = this.node.attrs.customLabel || this.node.attrs.label;
42
45
  this.dom.addEventListener('click', this.handleClick);