@manuscripts/body-editor 1.10.1-LEAN-3535.0 → 1.10.1

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 (61) hide show
  1. package/dist/cjs/components/authors/AuthorAffiliations.js +0 -6
  2. package/dist/cjs/components/authors/AuthorsModal.js +0 -4
  3. package/dist/cjs/configs/editor-plugins.js +2 -2
  4. package/dist/cjs/configs/editor-views.js +2 -0
  5. package/dist/cjs/index.js +3 -3
  6. package/dist/cjs/lib/authors.js +1 -15
  7. package/dist/cjs/lib/context-menu.js +2 -7
  8. package/dist/cjs/lib/popper.js +3 -25
  9. package/dist/cjs/plugins/affiliations.js +43 -53
  10. package/dist/cjs/plugins/selected-suggestion-ui.js +132 -0
  11. package/dist/cjs/useEditor.js +1 -1
  12. package/dist/cjs/views/affiliation.js +76 -0
  13. package/dist/cjs/views/affiliations.js +9 -102
  14. package/dist/cjs/views/bibliography_element.js +57 -46
  15. package/dist/cjs/views/citation.js +5 -13
  16. package/dist/cjs/views/citation_editable.js +19 -11
  17. package/dist/cjs/views/contributors.js +95 -92
  18. package/dist/cjs/views/editable_block.js +4 -2
  19. package/dist/cjs/views/keyword_group.js +10 -0
  20. package/dist/es/components/authors/AuthorAffiliations.js +0 -6
  21. package/dist/es/components/authors/AuthorsModal.js +0 -4
  22. package/dist/es/configs/editor-plugins.js +2 -2
  23. package/dist/es/configs/editor-views.js +4 -2
  24. package/dist/es/index.js +1 -1
  25. package/dist/es/lib/authors.js +0 -13
  26. package/dist/es/lib/context-menu.js +1 -6
  27. package/dist/es/lib/popper.js +3 -25
  28. package/dist/es/plugins/affiliations.js +43 -53
  29. package/dist/es/plugins/selected-suggestion-ui.js +129 -0
  30. package/dist/es/useEditor.js +1 -1
  31. package/dist/es/views/affiliation.js +72 -0
  32. package/dist/es/views/affiliations.js +9 -102
  33. package/dist/es/views/bibliography_element.js +58 -47
  34. package/dist/es/views/citation.js +5 -13
  35. package/dist/es/views/citation_editable.js +19 -11
  36. package/dist/es/views/contributors.js +98 -95
  37. package/dist/es/views/editable_block.js +5 -3
  38. package/dist/es/views/keyword_group.js +10 -0
  39. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -0
  40. package/dist/types/configs/editor-plugins.d.ts +21 -2
  41. package/dist/types/configs/editor-views.d.ts +3 -2
  42. package/dist/types/index.d.ts +1 -1
  43. package/dist/types/lib/authors.d.ts +2 -4
  44. package/dist/types/lib/context-menu.d.ts +0 -1
  45. package/dist/types/lib/popper.d.ts +1 -3
  46. package/dist/types/plugins/affiliations.d.ts +5 -8
  47. package/dist/types/plugins/footnotes/index.d.ts +2 -2
  48. package/dist/types/plugins/selected-suggestion-ui.d.ts +25 -0
  49. package/dist/types/views/affiliation.d.ts +30 -0
  50. package/dist/types/views/affiliations.d.ts +3 -28
  51. package/dist/types/views/base_node_view.d.ts +1 -0
  52. package/dist/types/views/bibliography_element.d.ts +4 -5
  53. package/dist/types/views/citation.d.ts +0 -2
  54. package/dist/types/views/citation_editable.d.ts +1 -1
  55. package/dist/types/views/contributors.d.ts +15 -13
  56. package/dist/types/views/keyword_group.d.ts +2 -0
  57. package/package.json +3 -3
  58. package/styles/AdvancedEditor.css +22 -29
  59. package/dist/cjs/plugins/selected-suggestion.js +0 -127
  60. package/dist/es/plugins/selected-suggestion.js +0 -124
  61. package/dist/types/plugins/selected-suggestion.d.ts +0 -10
@@ -92,16 +92,10 @@ const AuthorAffiliations = ({ author, affiliations, onSave, onAdd, onRemove, })
92
92
  const affiliation = {
93
93
  id: (0, json_schema_1.generateID)(json_schema_1.ObjectTypes.Affiliation),
94
94
  addressLine1: '',
95
- addressLine2: '',
96
- addressLine3: '',
97
95
  city: '',
98
96
  country: '',
99
97
  county: '',
100
98
  department: '',
101
- email: {
102
- href: '',
103
- text: '',
104
- },
105
99
  institution: institution,
106
100
  postCode: '',
107
101
  priority: 0,
@@ -91,8 +91,6 @@ const normalize = (author) => ({
91
91
  ORCIDIdentifier: author.ORCIDIdentifier || '',
92
92
  priority: author.priority,
93
93
  isJointContributor: author.isJointContributor || false,
94
- userID: '',
95
- invitationID: '',
96
94
  });
97
95
  const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author, onSaveAuthor, onDeleteAuthor, onSaveAffiliation, }) => {
98
96
  const [isOpen, setOpen] = (0, react_1.useState)(true);
@@ -160,8 +158,6 @@ const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author,
160
158
  ORCIDIdentifier: '',
161
159
  priority: authors.length,
162
160
  isJointContributor: false,
163
- userID: '',
164
- invitationID: '',
165
161
  };
166
162
  onSaveAuthor(author);
167
163
  setSelection(author);
@@ -37,7 +37,7 @@ const paragraphs_1 = __importDefault(require("../plugins/paragraphs"));
37
37
  const persist_1 = __importDefault(require("../plugins/persist"));
38
38
  const placeholder_1 = __importDefault(require("../plugins/placeholder"));
39
39
  const sections_1 = __importDefault(require("../plugins/sections"));
40
- const selected_suggestion_1 = __importDefault(require("../plugins/selected-suggestion"));
40
+ const selected_suggestion_ui_1 = __importDefault(require("../plugins/selected-suggestion-ui"));
41
41
  const table_footnote_1 = __importDefault(require("../plugins/table-footnote"));
42
42
  const tables_cursor_fix_1 = __importDefault(require("../plugins/tables-cursor-fix"));
43
43
  const toc_1 = __importDefault(require("../plugins/toc"));
@@ -68,9 +68,9 @@ exports.default = (props) => {
68
68
  (0, placeholder_1.default)(),
69
69
  (0, prosemirror_tables_1.tableEditing)(),
70
70
  (0, highlight_1.default)(props),
71
+ (0, selected_suggestion_ui_1.default)(props),
71
72
  (0, footnotes_1.default)(props),
72
73
  (0, table_footnote_1.default)(),
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 }));
@@ -18,6 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ const affiliation_1 = __importDefault(require("../views/affiliation"));
21
22
  const affiliations_1 = __importDefault(require("../views/affiliations"));
22
23
  const bibliography_element_editable_1 = __importDefault(require("../views/bibliography_element_editable"));
23
24
  const blockquote_element_editable_1 = __importDefault(require("../views/blockquote_element_editable"));
@@ -60,6 +61,7 @@ exports.default = (props, dispatch) => {
60
61
  cross_reference: (0, cross_reference_editable_1.default)(props, dispatch),
61
62
  contributors: (0, contributors_1.default)(props, dispatch),
62
63
  affiliations: (0, affiliations_1.default)(props, dispatch),
64
+ affiliation: (0, affiliation_1.default)(props, dispatch),
63
65
  equation: (0, equation_editable_1.default)(props),
64
66
  equation_element: (0, equation_element_editable_1.default)(props),
65
67
  figure: (0, figure_editable_1.default)(props, dispatch),
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.selectedSuggestionKey = exports.PopperManager = exports.CollabProvider = exports.LevelSelector = exports.OutlineItemIcon = exports.ManuscriptOutline = void 0;
32
+ exports.SET_SUGGESTION_ID = exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = 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,13 +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
- var selected_suggestion_1 = require("./plugins/selected-suggestion");
47
- Object.defineProperty(exports, "selectedSuggestionKey", { enumerable: true, get: function () { return selected_suggestion_1.selectedSuggestionKey; } });
48
46
  __exportStar(require("./plugins/highlight"), exports);
49
47
  var comment_annotation_1 = require("./plugins/comment_annotation");
50
48
  Object.defineProperty(exports, "commentScroll", { enumerable: true, get: function () { return comment_annotation_1.commentScroll; } });
51
49
  Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: function () { return comment_annotation_1.isThereSelector; } });
52
50
  Object.defineProperty(exports, "isHighlightComment", { enumerable: true, get: function () { return comment_annotation_1.isHighlightComment; } });
51
+ var selected_suggestion_ui_1 = require("./plugins/selected-suggestion-ui");
52
+ Object.defineProperty(exports, "SET_SUGGESTION_ID", { enumerable: true, get: function () { return selected_suggestion_ui_1.SET_SUGGESTION_ID; } });
53
53
  __exportStar(require("./lib/utils"), exports);
54
54
  __exportStar(require("./lib/track-changes-utils"), exports);
55
55
  __exportStar(require("./useEditor"), exports);
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.authorComparator = exports.initials = exports.authorLabel = exports.affiliationName = exports.affiliationLabel = void 0;
18
+ exports.authorComparator = exports.initials = exports.authorLabel = exports.affiliationLabel = void 0;
19
19
  const affiliationLabel = (affiliation) => {
20
20
  const institution = affiliation.institution;
21
21
  if (!institution) {
@@ -25,20 +25,6 @@ const affiliationLabel = (affiliation) => {
25
25
  return department ? `${institution} (${department})`.trim() : institution;
26
26
  };
27
27
  exports.affiliationLabel = affiliationLabel;
28
- const affiliationName = (affiliation) => {
29
- return [
30
- affiliation.department,
31
- affiliation.institution,
32
- affiliation.addressLine1,
33
- affiliation.city,
34
- affiliation.county,
35
- affiliation.country,
36
- affiliation.postCode,
37
- ]
38
- .filter(Boolean)
39
- .join(', ');
40
- };
41
- exports.affiliationName = affiliationName;
42
28
  const authorLabel = (author) => {
43
29
  const name = author.bibliographicName;
44
30
  const parts = [(0, exports.initials)(name), name.family, name.suffix].filter(Boolean);
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.ContextMenu = exports.contextMenuBtnClass = exports.sectionLevel = void 0;
21
+ exports.ContextMenu = exports.sectionLevel = void 0;
22
22
  const style_guide_1 = require("@manuscripts/style-guide");
23
23
  const transform_1 = require("@manuscripts/transform");
24
24
  const prosemirror_utils_1 = require("prosemirror-utils");
@@ -42,7 +42,6 @@ exports.sectionLevel = sectionLevel;
42
42
  const hasAny = (set, ...items) => {
43
43
  return items.some((i) => set.has(i));
44
44
  };
45
- exports.contextMenuBtnClass = 'btn-context-menu';
46
45
  class ContextMenu {
47
46
  constructor(node, view, getPos, actions = {}, props) {
48
47
  this.showAddMenu = (target, after) => {
@@ -356,11 +355,7 @@ class ContextMenu {
356
355
  };
357
356
  this.resolvePos = () => this.view.state.doc.resolve(this.getPos());
358
357
  this.addPopperEventListeners = () => {
359
- const mouseListener = (event) => {
360
- const target = event.target;
361
- if (target.classList.contains(exports.contextMenuBtnClass)) {
362
- return;
363
- }
358
+ const mouseListener = () => {
364
359
  window.requestAnimationFrame(() => {
365
360
  window.removeEventListener('mousedown', mouseListener);
366
361
  popper.destroy();
@@ -22,14 +22,12 @@ exports.PopperManager = void 0;
22
22
  const popper_js_1 = __importDefault(require("popper.js"));
23
23
  class PopperManager {
24
24
  show(target, contents, placement = 'bottom', showArrow = true, modifiers = {}) {
25
- console.log(target);
26
- this.destroy();
25
+ if (this.activePopper) {
26
+ return this.destroy();
27
+ }
27
28
  window.requestAnimationFrame(() => {
28
29
  const container = document.createElement('div');
29
30
  container.className = 'popper';
30
- container.addEventListener('click', (e) => {
31
- e.stopPropagation();
32
- });
33
31
  if (showArrow) {
34
32
  const arrow = document.createElement('div');
35
33
  arrow.className = 'popper-arrow';
@@ -57,32 +55,12 @@ class PopperManager {
57
55
  this.focusInput(container);
58
56
  },
59
57
  });
60
- this.handleDocumentClick = (e) => {
61
- const node = e.target;
62
- if (!container.contains(node) && !target.contains(node)) {
63
- this.destroy();
64
- }
65
- };
66
- if (contents.classList.contains('context-menu')) {
67
- window.addEventListener('click', this.handleDocumentClick);
68
- }
69
58
  });
70
59
  }
71
- clickEventHandler(event) {
72
- const contextMenuElement = document.querySelector('.context-menu');
73
- if (contextMenuElement === null || contextMenuElement === void 0 ? void 0 : contextMenuElement.contains(event.target)) {
74
- return;
75
- }
76
- this.destroy();
77
- }
78
60
  destroy() {
79
61
  if (this.activePopper) {
80
- window.removeEventListener('click', this.clickEventHandler);
81
62
  this.removeContainerClass(this.activePopper.reference);
82
63
  this.activePopper.destroy();
83
- if (this.handleDocumentClick) {
84
- window.removeEventListener('click', this.handleDocumentClick);
85
- }
86
64
  delete this.activePopper;
87
65
  }
88
66
  }
@@ -17,53 +17,41 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.buildPluginState = exports.affiliationsKey = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
- const lodash_1 = require("lodash");
21
20
  const prosemirror_state_1 = require("prosemirror-state");
22
21
  const prosemirror_view_1 = require("prosemirror-view");
23
- const authors_1 = require("../lib/authors");
24
22
  const track_changes_utils_1 = require("../lib/track-changes-utils");
25
23
  exports.affiliationsKey = new prosemirror_state_1.PluginKey('affiliations');
26
24
  let id = 1;
27
- const buildPluginState = (doc, $old) => {
28
- const nodes = [];
25
+ const buildPluginState = (doc) => {
29
26
  const contributors = [];
30
27
  const affiliations = [];
31
28
  doc.descendants((node, pos) => {
32
- const attrs = (0, track_changes_utils_1.isDeleted)(node) ? node.attrs : (0, track_changes_utils_1.getActualAttrs)(node);
29
+ if ((0, track_changes_utils_1.isDeleted)(node)) {
30
+ return;
31
+ }
33
32
  if ((0, transform_1.isAffiliationNode)(node)) {
34
- nodes.push([node, pos]);
35
- affiliations.push(attrs);
33
+ affiliations.push([node, pos]);
36
34
  }
37
35
  if ((0, transform_1.isContributorNode)(node)) {
38
- nodes.push([node, pos]);
39
- contributors.push(attrs);
36
+ contributors.push([node, pos]);
40
37
  }
41
38
  });
42
- if ($old &&
43
- (0, lodash_1.isEqual)(contributors, $old.contributors) &&
44
- (0, lodash_1.isEqual)(affiliations, $old.affiliations)) {
45
- return $old;
46
- }
47
39
  const iAffiliations = new Set();
48
- contributors.sort(authors_1.authorComparator).forEach((attrs) => {
49
- attrs.affiliations.forEach((aff) => {
40
+ contributors
41
+ .sort(([a], [b]) => {
42
+ return (Number((0, track_changes_utils_1.getActualAttrs)(a).priority) - Number((0, track_changes_utils_1.getActualAttrs)(b).priority));
43
+ })
44
+ .forEach(([author]) => {
45
+ (0, track_changes_utils_1.getActualAttrs)(author).affiliations.forEach((aff) => {
50
46
  iAffiliations.add(aff);
51
47
  });
52
48
  });
53
49
  const indexedAffiliationIds = new Map([...iAffiliations].map((id, i) => [id, i + 1]));
54
- const version = String(id++);
55
- const decorations = [];
56
- nodes.forEach(([node, pos]) => {
57
- decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
58
- version,
59
- }));
60
- });
61
50
  return {
62
- version,
51
+ version: String(id++),
63
52
  indexedAffiliationIds,
64
53
  contributors,
65
54
  affiliations,
66
- decorations: prosemirror_view_1.DecorationSet.create(doc, decorations),
67
55
  };
68
56
  };
69
57
  exports.buildPluginState = buildPluginState;
@@ -75,52 +63,54 @@ exports.default = () => {
75
63
  return (0, exports.buildPluginState)(instance.doc);
76
64
  },
77
65
  apply(tr, value, oldState, newState) {
78
- const $old = exports.affiliationsKey.getState(oldState);
79
- if (!tr.docChanged && $old) {
80
- return $old;
66
+ const prevPluginState = exports.affiliationsKey.getState(oldState);
67
+ if (!tr.docChanged && prevPluginState) {
68
+ return prevPluginState;
81
69
  }
82
70
  else {
83
- return (0, exports.buildPluginState)(newState.doc, $old);
71
+ return (0, exports.buildPluginState)(newState.doc);
84
72
  }
85
73
  },
86
74
  },
87
75
  appendTransaction(transactions, oldState, newState) {
88
- const affs = exports.affiliationsKey.getState(newState);
89
- if (!affs || !transactions.find((tr) => tr.docChanged)) {
76
+ const { indexedAffiliationIds } = exports.affiliationsKey.getState(newState);
77
+ if (!transactions.find((tr) => tr.docChanged)) {
90
78
  return;
91
79
  }
92
- const $old = exports.affiliationsKey.getState(oldState);
93
- const affiliations = new Map();
80
+ const oldPluginState = exports.affiliationsKey.getState(oldState);
81
+ const { tr } = newState;
82
+ const affiliations = [];
94
83
  newState.doc.descendants((node, pos) => {
84
+ if ((0, track_changes_utils_1.isDeleted)(node)) {
85
+ return;
86
+ }
95
87
  if ((0, transform_1.isAffiliationNode)(node)) {
96
- affiliations.set(node.attrs.id, [node, pos]);
88
+ affiliations.push([node, pos]);
97
89
  }
98
90
  });
99
- const deleteIDs = [];
100
- for (const [id] of $old.indexedAffiliationIds.entries()) {
101
- if (!affs.indexedAffiliationIds.has(id)) {
102
- deleteIDs.push(id);
91
+ for (const [id] of oldPluginState.indexedAffiliationIds.entries()) {
92
+ if (!indexedAffiliationIds.has(id)) {
93
+ const affiliation = affiliations.find(([node]) => node.attrs.id === id);
94
+ if (affiliation && !(0, track_changes_utils_1.isPendingInsert)(affiliation[0])) {
95
+ tr.delete(affiliation[1], affiliation[1] + affiliation[0].nodeSize);
96
+ }
103
97
  }
104
98
  }
105
- if (!deleteIDs.length) {
106
- return;
107
- }
108
- const tr = newState.tr;
109
99
  tr.setMeta('origin', 'affiliations');
110
- for (const id of deleteIDs) {
111
- const affiliation = affiliations.get(id);
112
- if (!affiliation) {
113
- continue;
114
- }
115
- const [node, pos] = affiliation;
116
- if (node && !(0, track_changes_utils_1.isPendingInsert)(node)) {
117
- tr.delete(pos, pos + node.nodeSize);
118
- }
119
- }
120
100
  return tr;
121
101
  },
122
102
  props: {
123
- decorations: (state) => { var _a; return (_a = exports.affiliationsKey.getState(state)) === null || _a === void 0 ? void 0 : _a.decorations; },
103
+ decorations: (state) => {
104
+ const decorations = [];
105
+ const aff = exports.affiliationsKey.getState(state);
106
+ const nodes = [...aff.contributors, ...aff.affiliations];
107
+ nodes.forEach(([node, pos]) => {
108
+ decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
109
+ version: aff.version,
110
+ }));
111
+ });
112
+ return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
113
+ },
124
114
  },
125
115
  });
126
116
  };
@@ -0,0 +1,132 @@
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.CLEAR_SUGGESTION_ID = 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
+ exports.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(exports.CLEAR_SUGGESTION_ID)) {
97
+ return prosemirror_view_1.DecorationSet.empty;
98
+ }
99
+ return value;
100
+ },
101
+ },
102
+ props: {
103
+ handleClick(view, pos) {
104
+ const nodeClicked = view.state.doc.nodeAt(pos);
105
+ const trackChangesData = nodeClicked && getTrackChangesData(nodeClicked);
106
+ if (!trackChangesData) {
107
+ setTimeout(() => {
108
+ const newTr = view.state.tr.setMeta(exports.CLEAR_SUGGESTION_ID, true);
109
+ view.dispatch(newTr);
110
+ props.setEditorSelectedSuggestion(undefined);
111
+ });
112
+ }
113
+ },
114
+ decorations: (state) => exports.selectedSuggestionKey.getState(state),
115
+ },
116
+ });
117
+ const buildSelectedSuggestionDecoration = (suggestionId, state, props) => {
118
+ var _a;
119
+ const change = (_a = track_changes_plugin_1.trackChangesPluginKey
120
+ .getState(state)) === null || _a === void 0 ? void 0 : _a.changeSet.get(suggestionId);
121
+ const decorations = [];
122
+ if (change) {
123
+ const decoration = change.type === 'text-change' ? prosemirror_view_1.Decoration.inline : prosemirror_view_1.Decoration.node;
124
+ decorations.push(decoration(change.from, change.to, {
125
+ class: 'selected-suggestion',
126
+ }));
127
+ setTimeout(() => {
128
+ props.setEditorSelectedSuggestion(change.id);
129
+ }, 0);
130
+ }
131
+ return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
132
+ };
@@ -70,7 +70,7 @@ const useEditor = (externalProps) => {
70
70
  }
71
71
  debounce(() => {
72
72
  setState(nextState);
73
- }, 200, !tr.isGeneric || !tr.docChanged);
73
+ }, 200, !tr.isGeneric);
74
74
  return nextState;
75
75
  }, []);
76
76
  const onRender = (0, react_1.useCallback)((el) => {
@@ -0,0 +1,76 @@
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.AffiliationView = void 0;
19
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
20
+ const affiliations_1 = require("../plugins/affiliations");
21
+ const base_node_view_1 = require("./base_node_view");
22
+ const creators_1 = require("./creators");
23
+ class AffiliationView extends base_node_view_1.BaseNodeView {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.initialise = () => {
27
+ this.createDOM();
28
+ };
29
+ this.updateContents = () => {
30
+ var _a;
31
+ const attrs = this.node.attrs;
32
+ const pluginState = affiliations_1.affiliationsKey.getState(this.view.state);
33
+ this.dom.innerHTML = this.formatAddress((0, track_changes_utils_1.getActualAttrs)(this.node));
34
+ if (pluginState === null || pluginState === void 0 ? void 0 : pluginState.indexedAffiliationIds) {
35
+ const order = pluginState.indexedAffiliationIds.get(attrs.id);
36
+ this.dom.innerHTML = order
37
+ ? `<b>${order}</b> ${this.dom.innerHTML}`
38
+ : this.dom.innerHTML;
39
+ this.dom.setAttribute('style', 'order: ' + (order || (pluginState === null || pluginState === void 0 ? void 0 : pluginState.affiliations.length) + 1));
40
+ }
41
+ if ((_a = attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
42
+ this.dom.setAttribute('data-track-id', attrs.dataTracked[0].id);
43
+ this.dom.setAttribute('data-track-status', attrs.dataTracked[0].status);
44
+ this.dom.setAttribute('data-track-op', attrs.dataTracked[0].operation);
45
+ }
46
+ else {
47
+ this.dom.removeAttribute('data-track-id');
48
+ this.dom.removeAttribute('data-track-status');
49
+ this.dom.removeAttribute('data-track-type');
50
+ }
51
+ };
52
+ this.createDOM = () => {
53
+ this.dom = document.createElement('div');
54
+ this.dom.classList.add('affiliation');
55
+ this.dom.setAttribute('id', this.node.attrs.id);
56
+ this.updateContents();
57
+ };
58
+ this.ignoreMutation = () => true;
59
+ this.formatAddress = (affiliation) => {
60
+ const { department, institution, addressLine1, city, county, country, postCode, } = affiliation;
61
+ return [
62
+ department,
63
+ institution,
64
+ addressLine1,
65
+ city,
66
+ county,
67
+ country,
68
+ postCode,
69
+ ]
70
+ .filter(Boolean)
71
+ .join(', ');
72
+ };
73
+ }
74
+ }
75
+ exports.AffiliationView = AffiliationView;
76
+ exports.default = (0, creators_1.createNodeView)(AffiliationView);