@manuscripts/body-editor 1.10.2-LEAN-3530.0 → 1.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/cjs/components/authors/AuthorAffiliations.js +6 -0
  2. package/dist/cjs/components/authors/AuthorsModal.js +4 -0
  3. package/dist/cjs/components/views/FigureDropdown.js +1 -1
  4. package/dist/cjs/configs/editor-plugins.js +2 -2
  5. package/dist/cjs/configs/editor-views.js +0 -2
  6. package/dist/cjs/index.js +3 -3
  7. package/dist/cjs/lib/authors.js +15 -1
  8. package/dist/cjs/lib/popper.js +13 -0
  9. package/dist/cjs/plugins/affiliations.js +53 -43
  10. package/dist/cjs/plugins/selected-suggestion.js +123 -0
  11. package/dist/cjs/useEditor.js +1 -1
  12. package/dist/cjs/views/affiliations.js +102 -9
  13. package/dist/cjs/views/bibliography_element.js +44 -56
  14. package/dist/cjs/views/citation.js +6 -5
  15. package/dist/cjs/views/citation_editable.js +2 -10
  16. package/dist/cjs/views/contributors.js +92 -95
  17. package/dist/cjs/views/keyword_group.js +0 -10
  18. package/dist/es/components/authors/AuthorAffiliations.js +6 -0
  19. package/dist/es/components/authors/AuthorsModal.js +4 -0
  20. package/dist/es/components/views/FigureDropdown.js +1 -1
  21. package/dist/es/configs/editor-plugins.js +2 -2
  22. package/dist/es/configs/editor-views.js +2 -4
  23. package/dist/es/index.js +1 -1
  24. package/dist/es/lib/authors.js +13 -0
  25. package/dist/es/lib/popper.js +13 -0
  26. package/dist/es/plugins/affiliations.js +53 -43
  27. package/dist/es/plugins/selected-suggestion.js +120 -0
  28. package/dist/es/useEditor.js +1 -1
  29. package/dist/es/views/affiliations.js +102 -9
  30. package/dist/es/views/bibliography_element.js +45 -57
  31. package/dist/es/views/citation.js +6 -5
  32. package/dist/es/views/citation_editable.js +2 -10
  33. package/dist/es/views/contributors.js +95 -98
  34. package/dist/es/views/keyword_group.js +0 -10
  35. package/dist/types/configs/ManuscriptsEditor.d.ts +0 -1
  36. package/dist/types/configs/editor-plugins.d.ts +2 -21
  37. package/dist/types/configs/editor-views.d.ts +2 -3
  38. package/dist/types/index.d.ts +1 -1
  39. package/dist/types/lib/authors.d.ts +4 -2
  40. package/dist/types/lib/popper.d.ts +2 -1
  41. package/dist/types/plugins/affiliations.d.ts +8 -5
  42. package/dist/types/plugins/footnotes/index.d.ts +2 -2
  43. package/dist/types/plugins/selected-suggestion.d.ts +10 -0
  44. package/dist/types/views/affiliations.d.ts +28 -3
  45. package/dist/types/views/base_node_view.d.ts +0 -1
  46. package/dist/types/views/bibliography_element.d.ts +5 -4
  47. package/dist/types/views/contributors.d.ts +13 -15
  48. package/dist/types/views/keyword_group.d.ts +0 -2
  49. package/package.json +1 -1
  50. package/styles/AdvancedEditor.css +41 -22
  51. package/dist/cjs/plugins/selected-suggestion-ui.js +0 -132
  52. package/dist/cjs/views/affiliation.js +0 -76
  53. package/dist/es/plugins/selected-suggestion-ui.js +0 -129
  54. package/dist/es/views/affiliation.js +0 -72
  55. package/dist/types/plugins/selected-suggestion-ui.d.ts +0 -25
  56. package/dist/types/views/affiliation.d.ts +0 -30
@@ -92,10 +92,16 @@ 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: '',
95
97
  city: '',
96
98
  country: '',
97
99
  county: '',
98
100
  department: '',
101
+ email: {
102
+ href: '',
103
+ text: '',
104
+ },
99
105
  institution: institution,
100
106
  postCode: '',
101
107
  priority: 0,
@@ -91,6 +91,8 @@ const normalize = (author) => ({
91
91
  ORCIDIdentifier: author.ORCIDIdentifier || '',
92
92
  priority: author.priority,
93
93
  isJointContributor: author.isJointContributor || false,
94
+ userID: '',
95
+ invitationID: '',
94
96
  });
95
97
  const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author, onSaveAuthor, onDeleteAuthor, onSaveAffiliation, }) => {
96
98
  const [isOpen, setOpen] = (0, react_1.useState)(true);
@@ -158,6 +160,8 @@ const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author,
158
160
  ORCIDIdentifier: '',
159
161
  priority: authors.length,
160
162
  isJointContributor: false,
163
+ userID: '',
164
+ invitationID: '',
161
165
  };
162
166
  onSaveAuthor(author);
163
167
  setSelection(author);
@@ -37,7 +37,7 @@ const FigureOptions = ({ can, files, getFilesMap, handleDownload, handleUpload,
37
37
  return (react_1.default.createElement(DropdownWrapper, { ref: wrapperRef },
38
38
  react_1.default.createElement(OptionsButton, { className: 'options-button', onClick: toggleOpen },
39
39
  react_1.default.createElement(style_guide_1.DotsIcon, null)),
40
- isOpen && (react_1.default.createElement(OptionsDropdownList, { direction: 'right', width: 128, top: 5 },
40
+ isOpen && (react_1.default.createElement(OptionsDropdownList, { direction: 'right', width: 128, onClick: toggleOpen, top: 5 },
41
41
  react_1.default.createElement(ListItemButton, { onClick: handleDownload, disabled: !showDownload }, "Download"),
42
42
  react_1.default.createElement(NestedDropdown, { disabled: !showReplace, parentToggleOpen: toggleOpen, buttonText: 'Replace', moveLeft: true, list: react_1.default.createElement(react_1.default.Fragment, null,
43
43
  otherFiles.map((file, index) => (react_1.default.createElement(ListItemButton, { key: file.id, id: index.toString(), onClick: () => handleReplace && handleReplace(file) },
@@ -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_ui_1 = __importDefault(require("../plugins/selected-suggestion-ui"));
40
+ const selected_suggestion_1 = __importDefault(require("../plugins/selected-suggestion"));
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),
72
71
  (0, footnotes_1.default)(props),
73
72
  (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,7 +18,6 @@ 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"));
22
21
  const affiliations_1 = __importDefault(require("../views/affiliations"));
23
22
  const bibliography_element_editable_1 = __importDefault(require("../views/bibliography_element_editable"));
24
23
  const blockquote_element_editable_1 = __importDefault(require("../views/blockquote_element_editable"));
@@ -61,7 +60,6 @@ exports.default = (props, dispatch) => {
61
60
  cross_reference: (0, cross_reference_editable_1.default)(props, dispatch),
62
61
  contributors: (0, contributors_1.default)(props, dispatch),
63
62
  affiliations: (0, affiliations_1.default)(props, dispatch),
64
- affiliation: (0, affiliation_1.default)(props, dispatch),
65
63
  equation: (0, equation_editable_1.default)(props),
66
64
  equation_element: (0, equation_element_editable_1.default)(props),
67
65
  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.SET_SUGGESTION_ID = exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = 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,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; } });
46
48
  __exportStar(require("./plugins/highlight"), exports);
47
49
  var comment_annotation_1 = require("./plugins/comment_annotation");
48
50
  Object.defineProperty(exports, "commentScroll", { enumerable: true, get: function () { return comment_annotation_1.commentScroll; } });
49
51
  Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: function () { return comment_annotation_1.isThereSelector; } });
50
52
  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.affiliationLabel = void 0;
18
+ exports.authorComparator = exports.initials = exports.authorLabel = exports.affiliationName = exports.affiliationLabel = void 0;
19
19
  const affiliationLabel = (affiliation) => {
20
20
  const institution = affiliation.institution;
21
21
  if (!institution) {
@@ -25,6 +25,20 @@ 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;
28
42
  const authorLabel = (author) => {
29
43
  const name = author.bibliographicName;
30
44
  const parts = [(0, exports.initials)(name), name.family, name.suffix].filter(Boolean);
@@ -28,6 +28,9 @@ class PopperManager {
28
28
  window.requestAnimationFrame(() => {
29
29
  const container = document.createElement('div');
30
30
  container.className = 'popper';
31
+ container.addEventListener('click', (e) => {
32
+ e.stopPropagation();
33
+ });
31
34
  if (showArrow) {
32
35
  const arrow = document.createElement('div');
33
36
  arrow.className = 'popper-arrow';
@@ -55,12 +58,22 @@ class PopperManager {
55
58
  this.focusInput(container);
56
59
  },
57
60
  });
61
+ this.handleDocumentClick = (e) => {
62
+ const node = e.target;
63
+ if (!container.contains(node) && !target.contains(node)) {
64
+ this.destroy();
65
+ }
66
+ };
67
+ document.addEventListener('click', this.handleDocumentClick);
58
68
  });
59
69
  }
60
70
  destroy() {
61
71
  if (this.activePopper) {
62
72
  this.removeContainerClass(this.activePopper.reference);
63
73
  this.activePopper.destroy();
74
+ if (this.handleDocumentClick) {
75
+ document.removeEventListener('click', this.handleDocumentClick);
76
+ }
64
77
  delete this.activePopper;
65
78
  }
66
79
  }
@@ -17,41 +17,53 @@
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");
20
21
  const prosemirror_state_1 = require("prosemirror-state");
21
22
  const prosemirror_view_1 = require("prosemirror-view");
23
+ const authors_1 = require("../lib/authors");
22
24
  const track_changes_utils_1 = require("../lib/track-changes-utils");
23
25
  exports.affiliationsKey = new prosemirror_state_1.PluginKey('affiliations');
24
26
  let id = 1;
25
- const buildPluginState = (doc) => {
27
+ const buildPluginState = (doc, $old) => {
28
+ const nodes = [];
26
29
  const contributors = [];
27
30
  const affiliations = [];
28
31
  doc.descendants((node, pos) => {
29
- if ((0, track_changes_utils_1.isDeleted)(node)) {
30
- return;
31
- }
32
+ const attrs = (0, track_changes_utils_1.isDeleted)(node) ? node.attrs : (0, track_changes_utils_1.getActualAttrs)(node);
32
33
  if ((0, transform_1.isAffiliationNode)(node)) {
33
- affiliations.push([node, pos]);
34
+ nodes.push([node, pos]);
35
+ affiliations.push(attrs);
34
36
  }
35
37
  if ((0, transform_1.isContributorNode)(node)) {
36
- contributors.push([node, pos]);
38
+ nodes.push([node, pos]);
39
+ contributors.push(attrs);
37
40
  }
38
41
  });
42
+ if ($old &&
43
+ (0, lodash_1.isEqual)(contributors, $old.contributors) &&
44
+ (0, lodash_1.isEqual)(affiliations, $old.affiliations)) {
45
+ return $old;
46
+ }
39
47
  const iAffiliations = new Set();
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) => {
48
+ contributors.sort(authors_1.authorComparator).forEach((attrs) => {
49
+ attrs.affiliations.forEach((aff) => {
46
50
  iAffiliations.add(aff);
47
51
  });
48
52
  });
49
53
  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
+ });
50
61
  return {
51
- version: String(id++),
62
+ version,
52
63
  indexedAffiliationIds,
53
64
  contributors,
54
65
  affiliations,
66
+ decorations: prosemirror_view_1.DecorationSet.create(doc, decorations),
55
67
  };
56
68
  };
57
69
  exports.buildPluginState = buildPluginState;
@@ -63,54 +75,52 @@ exports.default = () => {
63
75
  return (0, exports.buildPluginState)(instance.doc);
64
76
  },
65
77
  apply(tr, value, oldState, newState) {
66
- const prevPluginState = exports.affiliationsKey.getState(oldState);
67
- if (!tr.docChanged && prevPluginState) {
68
- return prevPluginState;
78
+ const $old = exports.affiliationsKey.getState(oldState);
79
+ if (!tr.docChanged && $old) {
80
+ return $old;
69
81
  }
70
82
  else {
71
- return (0, exports.buildPluginState)(newState.doc);
83
+ return (0, exports.buildPluginState)(newState.doc, $old);
72
84
  }
73
85
  },
74
86
  },
75
87
  appendTransaction(transactions, oldState, newState) {
76
- const { indexedAffiliationIds } = exports.affiliationsKey.getState(newState);
77
- if (!transactions.find((tr) => tr.docChanged)) {
88
+ const affs = exports.affiliationsKey.getState(newState);
89
+ if (!affs || !transactions.find((tr) => tr.docChanged)) {
78
90
  return;
79
91
  }
80
- const oldPluginState = exports.affiliationsKey.getState(oldState);
81
- const { tr } = newState;
82
- const affiliations = [];
92
+ const $old = exports.affiliationsKey.getState(oldState);
93
+ const affiliations = new Map();
83
94
  newState.doc.descendants((node, pos) => {
84
- if ((0, track_changes_utils_1.isDeleted)(node)) {
85
- return;
86
- }
87
95
  if ((0, transform_1.isAffiliationNode)(node)) {
88
- affiliations.push([node, pos]);
96
+ affiliations.set(node.attrs.id, [node, pos]);
89
97
  }
90
98
  });
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
- }
99
+ const deleteIDs = [];
100
+ for (const [id] of $old.indexedAffiliationIds.entries()) {
101
+ if (!affs.indexedAffiliationIds.has(id)) {
102
+ deleteIDs.push(id);
97
103
  }
98
104
  }
105
+ if (!deleteIDs.length) {
106
+ return;
107
+ }
108
+ const tr = newState.tr;
99
109
  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
+ }
100
120
  return tr;
101
121
  },
102
122
  props: {
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
- },
123
+ decorations: (state) => { var _a; return (_a = exports.affiliationsKey.getState(state)) === null || _a === void 0 ? void 0 : _a.decorations; },
114
124
  },
115
125
  });
116
126
  };
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selectedSuggestionKey = void 0;
4
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
5
+ const transform_1 = require("@manuscripts/transform");
6
+ const prosemirror_state_1 = require("prosemirror-state");
7
+ const prosemirror_view_1 = require("prosemirror-view");
8
+ const commands_1 = require("../commands");
9
+ exports.selectedSuggestionKey = new prosemirror_state_1.PluginKey('selected-suggestion');
10
+ const EMPTY = {
11
+ decorations: prosemirror_view_1.DecorationSet.empty,
12
+ };
13
+ exports.default = () => {
14
+ return new prosemirror_state_1.Plugin({
15
+ key: exports.selectedSuggestionKey,
16
+ state: {
17
+ init: (_, state) => buildPluginState(state),
18
+ apply: (tr, value, oldState, newState) => buildPluginState(newState),
19
+ },
20
+ props: {
21
+ decorations: (state) => {
22
+ const suggestion = exports.selectedSuggestionKey.getState(state);
23
+ return (suggestion === null || suggestion === void 0 ? void 0 : suggestion.decorations) || prosemirror_view_1.DecorationSet.empty;
24
+ },
25
+ },
26
+ });
27
+ };
28
+ const buildPluginState = (state) => {
29
+ const selection = state.selection;
30
+ const $pos = (0, commands_1.isTextSelection)(selection) ? selection.$cursor : selection.$to;
31
+ if (!$pos) {
32
+ return EMPTY;
33
+ }
34
+ const effective = getEffectiveSelection($pos);
35
+ if (!effective) {
36
+ return EMPTY;
37
+ }
38
+ if (effective.node.isText) {
39
+ return buildTextDecoration(state.doc, effective);
40
+ }
41
+ else {
42
+ return buildNodeDecoration(state.doc, effective);
43
+ }
44
+ };
45
+ const getEffectiveSelection = ($pos) => {
46
+ let current;
47
+ for (let depth = $pos.depth; depth > 0; depth--) {
48
+ const node = $pos.node(depth);
49
+ if (node.attrs.dataTracked) {
50
+ current = {
51
+ node,
52
+ from: $pos.before(depth),
53
+ to: $pos.after(depth),
54
+ };
55
+ }
56
+ else {
57
+ break;
58
+ }
59
+ }
60
+ if (current) {
61
+ return current;
62
+ }
63
+ const parent = $pos.parent;
64
+ const child = parent.childBefore($pos.parentOffset);
65
+ const node = child.node;
66
+ if (node) {
67
+ const from = $pos.start() + child.offset;
68
+ const to = from + node.nodeSize;
69
+ return {
70
+ node,
71
+ from,
72
+ to,
73
+ };
74
+ }
75
+ };
76
+ const buildNodeDecoration = (doc, selection) => {
77
+ var _a;
78
+ const node = selection.node;
79
+ const suggestion = (_a = node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a[0];
80
+ if (!(suggestion === null || suggestion === void 0 ? void 0 : suggestion.status) || suggestion.status === track_changes_plugin_1.CHANGE_STATUS.rejected) {
81
+ return EMPTY;
82
+ }
83
+ const from = selection.from;
84
+ const to = selection.to;
85
+ const inline = node.type === transform_1.schema.nodes.keyword || node.isInline;
86
+ const decoration = prosemirror_view_1.Decoration.node(from, to, {
87
+ nodeName: inline ? 'span' : 'div',
88
+ class: 'selected-suggestion',
89
+ });
90
+ return {
91
+ suggestion,
92
+ decorations: prosemirror_view_1.DecorationSet.create(doc, [decoration]),
93
+ };
94
+ };
95
+ const buildTextDecoration = (doc, selection) => {
96
+ var _a;
97
+ const node = selection.node;
98
+ const suggestion = (_a = getTrackedMark(node)) === null || _a === void 0 ? void 0 : _a.attrs.dataTracked;
99
+ if (!suggestion) {
100
+ return EMPTY;
101
+ }
102
+ const from = selection.from;
103
+ const to = selection.to;
104
+ const decoration = prosemirror_view_1.Decoration.inline(from, to, {
105
+ nodeName: 'span',
106
+ class: 'selected-suggestion',
107
+ });
108
+ return {
109
+ suggestion,
110
+ decorations: prosemirror_view_1.DecorationSet.create(doc, [decoration]),
111
+ };
112
+ };
113
+ const trackedMarkTypes = new Set([
114
+ transform_1.schema.marks.tracked_insert,
115
+ transform_1.schema.marks.tracked_delete,
116
+ ]);
117
+ const getTrackedMark = (node) => {
118
+ for (const mark of node.marks) {
119
+ if (trackedMarkTypes.has(mark.type)) {
120
+ return mark;
121
+ }
122
+ }
123
+ };
@@ -70,7 +70,7 @@ const useEditor = (externalProps) => {
70
70
  }
71
71
  debounce(() => {
72
72
  setState(nextState);
73
- }, 200, !tr.isGeneric);
73
+ }, 200, !tr.isGeneric || !tr.docChanged);
74
74
  return nextState;
75
75
  }, []);
76
76
  const onRender = (0, react_1.useCallback)((el) => {
@@ -1,10 +1,29 @@
1
1
  "use strict";
2
+ /*!
3
+ * © 2023 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
+ */
2
17
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
19
  };
5
20
  Object.defineProperty(exports, "__esModule", { value: true });
6
21
  exports.AffiliationsView = void 0;
7
22
  const prosemirror_state_1 = require("prosemirror-state");
23
+ const authors_1 = require("../lib/authors");
24
+ const view_1 = require("../lib/view");
25
+ const affiliations_1 = require("../plugins/affiliations");
26
+ const selected_suggestion_1 = require("../plugins/selected-suggestion");
8
27
  const block_view_1 = __importDefault(require("./block_view"));
9
28
  const creators_1 = require("./creators");
10
29
  class AffiliationsView extends block_view_1.default {
@@ -13,19 +32,93 @@ class AffiliationsView extends block_view_1.default {
13
32
  this.ignoreMutation = () => true;
14
33
  this.stopEvent = () => true;
15
34
  this.createElement = () => {
16
- this.contentDOM = document.createElement(this.elementType);
17
- this.contentDOM.className = 'block';
18
- this.contentDOM.setAttribute('contenteditable', 'false');
35
+ this.container = document.createElement('div');
36
+ this.container.classList.add('affiliations', 'block');
37
+ this.container.contentEditable = 'false';
38
+ this.container.addEventListener('click', this.handleClick);
19
39
  this.dom.setAttribute('contenteditable', 'false');
20
- this.dom.appendChild(this.contentDOM);
40
+ this.dom.appendChild(this.container);
21
41
  };
22
42
  this.updateContents = () => {
23
- this.dom.addEventListener('click', () => this.onClickHandler());
43
+ const affs = affiliations_1.affiliationsKey.getState(this.view.state);
44
+ if (!affs) {
45
+ return;
46
+ }
47
+ if (this.version === affs.version) {
48
+ this.updateSelection();
49
+ return;
50
+ }
51
+ this.version = affs.version;
52
+ this.container.innerHTML = '';
53
+ this.buildAffiliations(affs);
54
+ this.updateSelection();
24
55
  };
25
- this.onClickHandler = () => {
26
- const { tr, doc } = this.view.state;
27
- tr.setSelection(prosemirror_state_1.NodeSelection.create(doc, this.getPos()));
28
- this.view.dispatch(tr);
56
+ this.buildAffiliations = (affs) => {
57
+ const elements = [];
58
+ for (const affiliation of affs.affiliations) {
59
+ const index = affs.indexedAffiliationIds.get(affiliation.id);
60
+ elements.push({
61
+ index,
62
+ element: this.buildAffiliation(affiliation, index),
63
+ });
64
+ }
65
+ elements
66
+ .sort(this.sortAffiliations)
67
+ .forEach((e) => this.container.appendChild(e.element));
68
+ };
69
+ this.buildAffiliation = (attrs, index) => {
70
+ var _a;
71
+ const element = document.createElement('div');
72
+ element.classList.add('affiliation');
73
+ element.id = attrs.id;
74
+ if ((_a = attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
75
+ const change = attrs.dataTracked[0];
76
+ element.setAttribute('data-track-id', change.id);
77
+ element.setAttribute('data-track-status', change.status);
78
+ element.setAttribute('data-track-op', change.operation);
79
+ }
80
+ if (index) {
81
+ const label = document.createElement('span');
82
+ label.classList.add('affiliation-label');
83
+ label.innerHTML = String(index);
84
+ element.appendChild(label);
85
+ }
86
+ const name = document.createElement('span');
87
+ name.classList.add('affiliation-name');
88
+ name.innerHTML = (0, authors_1.affiliationName)(attrs);
89
+ element.appendChild(name);
90
+ return element;
91
+ };
92
+ this.sortAffiliations = (aff1, aff2) => {
93
+ const index1 = aff1.index || 10000;
94
+ const index2 = aff2.index || 10000;
95
+ return index1 - index2;
96
+ };
97
+ this.handleClick = (event) => {
98
+ const element = event.target;
99
+ const item = element.closest('.affiliation');
100
+ if (item) {
101
+ const node = (0, view_1.findChildByID)(this.view, item.id);
102
+ if (!node) {
103
+ return;
104
+ }
105
+ const view = this.view;
106
+ const tr = view.state.tr;
107
+ tr.setSelection(prosemirror_state_1.NodeSelection.create(view.state.doc, node.pos));
108
+ view.dispatch(tr);
109
+ }
110
+ };
111
+ this.updateSelection = () => {
112
+ var _a;
113
+ const state = this.view.state;
114
+ const selection = (_a = selected_suggestion_1.selectedSuggestionKey.getState(state)) === null || _a === void 0 ? void 0 : _a.suggestion;
115
+ this.container
116
+ .querySelectorAll('.selected-suggestion')
117
+ .forEach((e) => e.classList.remove('selected-suggestion'));
118
+ if (selection) {
119
+ const item = this.container.querySelector(`[data-track-id="${selection.id}"]`);
120
+ item === null || item === void 0 ? void 0 : item.classList.add('selected-suggestion');
121
+ }
29
122
  };
30
123
  }
31
124
  }