@manuscripts/body-editor 3.12.3 → 3.12.5

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 (82) hide show
  1. package/dist/cjs/commands.js +4 -5
  2. package/dist/cjs/components/affiliations/AffiliationsModal.js +1 -3
  3. package/dist/cjs/components/keywords/AddKeywordInline.js +2 -2
  4. package/dist/cjs/components/outline/DraggableTree.js +4 -4
  5. package/dist/cjs/components/toolbar/helpers.js +7 -13
  6. package/dist/cjs/components/toolbar/type-selector/TypeSelector.js +5 -5
  7. package/dist/cjs/components/views/FootnotesSelector.js +2 -2
  8. package/dist/cjs/lib/track-changes-utils.js +3 -140
  9. package/dist/cjs/lib/utils.js +1 -1
  10. package/dist/cjs/lib/view.js +2 -1
  11. package/dist/cjs/menus.js +2 -2
  12. package/dist/cjs/plugins/affiliations.js +2 -2
  13. package/dist/cjs/plugins/objects.js +3 -6
  14. package/dist/cjs/plugins/persist.js +2 -4
  15. package/dist/cjs/plugins/search-replace/lib.js +2 -2
  16. package/dist/cjs/plugins/section_category.js +10 -43
  17. package/dist/cjs/plugins/section_title/autocompletion.js +2 -2
  18. package/dist/cjs/plugins/section_title/index.js +2 -5
  19. package/dist/cjs/plugins/selected-suggestion.js +1 -2
  20. package/dist/cjs/versions.js +1 -1
  21. package/dist/cjs/views/affiliations.js +4 -4
  22. package/dist/cjs/views/award.js +2 -2
  23. package/dist/cjs/views/base_node_view.js +3 -3
  24. package/dist/cjs/views/bibliography_element.js +3 -3
  25. package/dist/cjs/views/block_view.js +2 -2
  26. package/dist/cjs/views/citation_editable.js +3 -3
  27. package/dist/cjs/views/contributors.js +4 -4
  28. package/dist/cjs/views/creators.js +2 -2
  29. package/dist/cjs/views/figure_editable.js +5 -5
  30. package/dist/cjs/views/footnote.js +11 -11
  31. package/dist/cjs/views/general_table_footnote.js +4 -4
  32. package/dist/cjs/views/inline_footnote.js +3 -3
  33. package/dist/cjs/views/keyword.js +2 -2
  34. package/dist/cjs/views/keyword_group.js +2 -2
  35. package/dist/cjs/views/link_editable.js +2 -2
  36. package/dist/cjs/views/quote_image_editable.js +4 -4
  37. package/dist/es/commands.js +1 -2
  38. package/dist/es/components/affiliations/AffiliationsModal.js +1 -3
  39. package/dist/es/components/authors/AuthorsModal.js +1 -1
  40. package/dist/es/components/keywords/AddKeywordInline.js +1 -1
  41. package/dist/es/components/outline/DraggableTree.js +1 -1
  42. package/dist/es/components/toolbar/helpers.js +4 -9
  43. package/dist/es/components/toolbar/type-selector/TypeSelector.js +1 -1
  44. package/dist/es/components/views/FootnotesSelector.js +1 -1
  45. package/dist/es/lib/track-changes-utils.js +3 -128
  46. package/dist/es/lib/utils.js +1 -1
  47. package/dist/es/lib/view.js +2 -1
  48. package/dist/es/menus.js +2 -2
  49. package/dist/es/plugins/affiliations.js +1 -1
  50. package/dist/es/plugins/objects.js +3 -6
  51. package/dist/es/plugins/persist.js +3 -5
  52. package/dist/es/plugins/search-replace/lib.js +1 -1
  53. package/dist/es/plugins/section_category.js +10 -43
  54. package/dist/es/plugins/section_title/autocompletion.js +1 -1
  55. package/dist/es/plugins/section_title/index.js +2 -5
  56. package/dist/es/plugins/selected-suggestion.js +1 -2
  57. package/dist/es/versions.js +1 -1
  58. package/dist/es/views/affiliations.js +1 -1
  59. package/dist/es/views/award.js +1 -1
  60. package/dist/es/views/base_node_view.js +1 -1
  61. package/dist/es/views/bibliography_element.js +1 -1
  62. package/dist/es/views/block_view.js +1 -1
  63. package/dist/es/views/citation_editable.js +1 -1
  64. package/dist/es/views/contributors.js +1 -1
  65. package/dist/es/views/creators.js +1 -1
  66. package/dist/es/views/figure_editable.js +1 -1
  67. package/dist/es/views/footnote.js +7 -7
  68. package/dist/es/views/general_table_footnote.js +1 -1
  69. package/dist/es/views/inline_footnote.js +1 -1
  70. package/dist/es/views/keyword.js +1 -1
  71. package/dist/es/views/keyword_group.js +1 -1
  72. package/dist/es/views/link_editable.js +1 -1
  73. package/dist/es/views/quote_image_editable.js +1 -1
  74. package/dist/types/components/toolbar/helpers.d.ts +0 -1
  75. package/dist/types/lib/track-changes-utils.d.ts +2 -15
  76. package/dist/types/lib/utils.d.ts +1 -1
  77. package/dist/types/versions.d.ts +1 -1
  78. package/dist/types/views/footnote.d.ts +2 -2
  79. package/package.json +3 -3
  80. package/dist/cjs/lib/filtered-document.js +0 -49
  81. package/dist/es/lib/filtered-document.js +0 -44
  82. package/dist/types/lib/filtered-document.d.ts +0 -18
@@ -30,7 +30,6 @@ const doc_1 = require("./lib/doc");
30
30
  const footnotes_1 = require("./lib/footnotes");
31
31
  const helpers_1 = require("./lib/helpers");
32
32
  const template_1 = require("./lib/template");
33
- const track_changes_utils_1 = require("./lib/track-changes-utils");
34
33
  const utils_1 = require("./lib/utils");
35
34
  const accessibility_element_1 = require("./plugins/accessibility_element");
36
35
  const comments_2 = require("./plugins/comments");
@@ -71,7 +70,7 @@ const markActive = (type) => (state) => {
71
70
  state.doc.nodesBetween(from, to, (node) => {
72
71
  if (node.isText) {
73
72
  node.marks.forEach((m) => {
74
- if (m.type === type && !(0, track_changes_utils_1.isDeleted)(m)) {
73
+ if (m.type === type && !(0, track_changes_plugin_1.isDeleted)(m)) {
75
74
  hasMark = true;
76
75
  }
77
76
  });
@@ -498,7 +497,7 @@ const insertTableElementFooter = (tr, table) => {
498
497
  const footer = (0, prosemirror_utils_1.findChildrenByType)(table[0], transform_1.schema.nodes.table_element_footer)[0];
499
498
  if (footer) {
500
499
  const pos = tr.mapping.map(table[1] + footer.pos);
501
- if ((0, track_changes_utils_1.isDeleted)(footer.node)) {
500
+ if ((0, track_changes_plugin_1.isDeleted)(footer.node)) {
502
501
  reinstateNode(tr, footer.node, pos);
503
502
  }
504
503
  return {
@@ -535,7 +534,7 @@ const insertInlineFootnote = (state, dispatch) => {
535
534
  const tr = state.tr;
536
535
  const container = (0, footnotes_1.findFootnotesContainerNode)(state.doc, pos);
537
536
  const fn = (0, footnotes_1.getFootnotesElementState)(state, container.node.attrs.id);
538
- const hasFootnotes = fn && fn.footnotes.filter((fn) => !(0, track_changes_utils_1.isDeleted)(fn[0])).length > 0;
537
+ const hasFootnotes = fn && fn.footnotes.filter((fn) => !(0, track_changes_plugin_1.isDeleted)(fn[0])).length > 0;
539
538
  const footnote = !hasFootnotes && (0, footnotes_1.createFootnote)();
540
539
  const node = transform_1.schema.nodes.inline_footnote.create({
541
540
  rids: footnote ? [footnote.attrs.id] : [],
@@ -549,7 +548,7 @@ const insertInlineFootnote = (state, dispatch) => {
549
548
  else {
550
549
  element = (0, exports.insertFootnotesElement)(tr, [container.node, container.pos]);
551
550
  }
552
- if ((0, track_changes_utils_1.isDeleted)(element[0])) {
551
+ if ((0, track_changes_plugin_1.isDeleted)(element[0])) {
553
552
  reinstateNode(tr, element[0], element[1]);
554
553
  }
555
554
  const fnPos = element[1] + element[0].nodeSize - 1;
@@ -254,9 +254,7 @@ const AffiliationsModal = ({ authors: $authors, affiliations: $affiliations, aff
254
254
  const author = authors.find((a) => a.id === authorId);
255
255
  return {
256
256
  id: authorId,
257
- label: author
258
- ? `${author.given} ${author.family}`
259
- : '',
257
+ label: author ? `${author.given} ${author.family}` : '',
260
258
  };
261
259
  })
262
260
  .filter((author) => author.label);
@@ -53,11 +53,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
54
  exports.AddKeywordInline = void 0;
55
55
  const style_guide_1 = require("@manuscripts/style-guide");
56
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
56
57
  const transform_1 = require("@manuscripts/transform");
57
58
  const prosemirror_state_1 = require("prosemirror-state");
58
59
  const react_1 = __importStar(require("react"));
59
60
  const styled_components_1 = __importDefault(require("styled-components"));
60
- const track_changes_utils_1 = require("../../lib/track-changes-utils");
61
61
  const AddNewKeyword = styled_components_1.default.div `
62
62
  position: relative;
63
63
  display: inline-block;
@@ -121,7 +121,7 @@ const AddKeywordInline = ({ viewProps, getUpdatedNode }) => {
121
121
  const keywords = [];
122
122
  node.content.descendants((descNode) => {
123
123
  if (descNode.type === descNode.type.schema.nodes.keyword &&
124
- !(0, track_changes_utils_1.isDeleted)(descNode)) {
124
+ !(0, track_changes_plugin_1.isDeleted)(descNode)) {
125
125
  keywords.push({
126
126
  id: descNode.attrs.id,
127
127
  contents: descNode.textContent,
@@ -41,11 +41,11 @@ const react_1 = __importStar(require("react"));
41
41
  const react_dnd_1 = require("react-dnd");
42
42
  const context_menu_1 = require("../../lib/context-menu");
43
43
  const dnd_1 = require("../../lib/dnd");
44
- const track_changes_utils_1 = require("../../lib/track-changes-utils");
45
44
  const utils_1 = require("../../lib/utils");
46
45
  const node_type_icons_1 = require("../../node-type-icons");
47
46
  const section_title_1 = require("../../plugins/section_title");
48
47
  const Outline_1 = require("./Outline");
48
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
49
49
  const excludedTypes = [
50
50
  transform_1.schema.nodes.table,
51
51
  transform_1.schema.nodes.figure,
@@ -107,7 +107,7 @@ const buildTree = ({ node, pos, index, parent, }) => {
107
107
  if (isManuscriptNode(node) ||
108
108
  ((!childNode.isAtom || (0, transform_1.isElementNodeType)(childNode.type)) &&
109
109
  childNode.attrs.id &&
110
- !(0, track_changes_utils_1.isDeleted)(childNode))) {
110
+ !(0, track_changes_plugin_1.isDeleted)(childNode))) {
111
111
  items.push((0, exports.buildTree)({
112
112
  node: childNode,
113
113
  pos: startPos + offset,
@@ -152,7 +152,7 @@ const DraggableTree = ({ tree, view, depth, can, getFiles, }) => {
152
152
  type: 'outline',
153
153
  item: tree,
154
154
  canDrag: () => {
155
- return depth !== 0 && !disableDragAndDrop && !(0, track_changes_utils_1.isDeleted)(node);
155
+ return depth !== 0 && !disableDragAndDrop && !(0, track_changes_plugin_1.isDeleted)(node);
156
156
  },
157
157
  collect: (monitor) => ({
158
158
  isDragging: monitor.isDragging(),
@@ -212,7 +212,7 @@ const DraggableTree = ({ tree, view, depth, can, getFiles, }) => {
212
212
  isOver: monitor.isOver({ shallow: true }),
213
213
  }),
214
214
  });
215
- const isDeletedItem = (0, track_changes_utils_1.isDeleted)(node);
215
+ const isDeletedItem = (0, track_changes_plugin_1.isDeleted)(node);
216
216
  const isHeroImage = (0, transform_1.isHeroImageNode)(node);
217
217
  const isSupplements = (0, transform_1.isSupplementsNode)(node);
218
218
  const isMainDocument = (0, transform_1.isAttachmentsNode)(node);
@@ -1,18 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.changeIndentation = exports.unindentParagraph = exports.unindentSection = exports.indentParagraph = exports.indentSection = exports.isIndentationAllowed = exports.promoteParagraphToSection = exports.demoteSectionToParagraph = exports.getDeepestSubsectionPosition = exports.findSelectedOption = exports.titleCase = exports.optionName = exports.shouldSkipNode = void 0;
3
+ exports.changeIndentation = exports.unindentParagraph = exports.unindentSection = exports.indentParagraph = exports.indentSection = exports.isIndentationAllowed = exports.promoteParagraphToSection = exports.demoteSectionToParagraph = exports.getDeepestSubsectionPosition = exports.findSelectedOption = exports.titleCase = exports.optionName = void 0;
4
4
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
5
5
  const transform_1 = require("@manuscripts/transform");
6
6
  const prosemirror_model_1 = require("prosemirror-model");
7
7
  const prosemirror_state_1 = require("prosemirror-state");
8
8
  const prosemirror_utils_1 = require("prosemirror-utils");
9
- const filtered_document_1 = require("../../lib/filtered-document");
10
- const track_changes_utils_1 = require("../../lib/track-changes-utils");
11
9
  const utils_1 = require("../../lib/utils");
12
- const shouldSkipNode = (node) => {
13
- return (0, filtered_document_1.isMoved)(node) || (0, track_changes_utils_1.isDeleted)(node);
14
- };
15
- exports.shouldSkipNode = shouldSkipNode;
16
10
  const optionName = (nodeType) => {
17
11
  switch (nodeType) {
18
12
  case nodeType.schema.nodes.section:
@@ -34,7 +28,7 @@ const findSelectedOption = (options) => {
34
28
  exports.findSelectedOption = findSelectedOption;
35
29
  const getDeepestSubsectionPosition = (subsection, position) => {
36
30
  while (subsection.lastChild && (0, transform_1.isSectionNodeType)(subsection.lastChild.type)) {
37
- if ((0, track_changes_utils_1.isDeleted)(subsection.lastChild)) {
31
+ if ((0, track_changes_plugin_1.isDeleted)(subsection.lastChild)) {
38
32
  return (position +
39
33
  jumpToPreviousValidNode(subsection.nodeSize - subsection.lastChild.nodeSize - 2, subsection) +
40
34
  1);
@@ -56,7 +50,7 @@ const jumpToPreviousValidNode = (beforeSection, doc) => {
56
50
  for (let i = $beforeSection.index() - 1; i >= 0; i--) {
57
51
  pos = $beforeSection.posAtIndex(i);
58
52
  const node = doc.resolve(pos + 1).node();
59
- if (!((0, track_changes_utils_1.isDeleted)(node) && node.type === transform_1.schema.nodes.section) && i >= 0) {
53
+ if (!((0, track_changes_plugin_1.isDeleted)(node) && node.type === transform_1.schema.nodes.section) && i >= 0) {
60
54
  pos = $beforeSection.posAtIndex(i + 1);
61
55
  break;
62
56
  }
@@ -95,7 +89,7 @@ const demoteSectionToParagraph = (state, dispatch, view) => {
95
89
  else {
96
90
  anchor = beforeSection + 1;
97
91
  }
98
- const content = (0, utils_1.filterBlockNodes)(prosemirror_model_1.Fragment.from(paragraph).append(sectionContent), (node) => !(0, track_changes_utils_1.isShadowDelete)(node));
92
+ const content = (0, utils_1.filterBlockNodes)(prosemirror_model_1.Fragment.from(paragraph).append(sectionContent));
99
93
  tr.insert(beforeSection, content);
100
94
  const afterSection = tr.mapping.map($from.after(sectionDepth));
101
95
  tr.delete(afterSection - section.nodeSize, afterSection);
@@ -149,7 +143,7 @@ const promoteParagraphToSection = (state, dispatch, view) => {
149
143
  else {
150
144
  items.push(parentSection.type.create({ dataTracked: getInsertDataTracked(paragraph) }, sectionContent));
151
145
  }
152
- const content = (0, utils_1.filterBlockNodes)(prosemirror_model_1.Fragment.from(items[items.length - 1]), (node) => !(0, track_changes_utils_1.isShadowDelete)(node));
146
+ const content = (0, utils_1.filterBlockNodes)(prosemirror_model_1.Fragment.from(items[items.length - 1]));
153
147
  tr.insert(afterParentSection, content);
154
148
  tr.delete(beforeParagraph, afterParentSection - 1);
155
149
  const anchor = tr.mapping.map(afterParentSection) - content.size + 2;
@@ -169,7 +163,7 @@ const isIndentationAllowed = (action) => (state) => {
169
163
  return false;
170
164
  }
171
165
  const isInBody = (0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.body)(state.selection);
172
- const isDeletedNode = (0, track_changes_utils_1.isDeleted)($from.node($from.depth));
166
+ const isDeletedNode = (0, track_changes_plugin_1.isDeleted)($from.node($from.depth));
173
167
  if (!isInBody || isDeletedNode) {
174
168
  return false;
175
169
  }
@@ -209,7 +203,7 @@ const indentSection = () => (state, dispatch, view) => {
209
203
  let previousSection = null;
210
204
  for (let i = startIndex - 1; i >= 0; i--) {
211
205
  const candidate = parentSection.child(i);
212
- if (candidate.type === nodes.section && !(0, exports.shouldSkipNode)(candidate)) {
206
+ if (candidate.type === nodes.section && (0, track_changes_plugin_1.isValid)(candidate)) {
213
207
  previousSection = candidate;
214
208
  break;
215
209
  }
@@ -8,11 +8,11 @@ const transform_1 = require("@manuscripts/transform");
8
8
  const prosemirror_utils_1 = require("prosemirror-utils");
9
9
  const react_1 = __importDefault(require("react"));
10
10
  const hierarchy_1 = require("../../../lib/hierarchy");
11
- const track_changes_utils_1 = require("../../../lib/track-changes-utils");
12
11
  const utils_1 = require("../../../lib/utils");
13
12
  const helpers_1 = require("../helpers");
14
13
  const OptionComponent_1 = require("./OptionComponent");
15
14
  const styles_1 = require("./styles");
15
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
16
16
  const buildOptions = (state) => {
17
17
  const { doc, selection: { $from, $to }, schema, } = state;
18
18
  const { nodes } = schema;
@@ -32,12 +32,12 @@ const buildOptions = (state) => {
32
32
  const $beforeSection = doc.resolve(beforeSection);
33
33
  const sectionOffset = $beforeSection.parentOffset;
34
34
  const section = $from.node(sectionDepth);
35
- !(0, track_changes_utils_1.isDeleted)(section) &&
35
+ !(0, track_changes_plugin_1.isDeleted)(section) &&
36
36
  options.push({
37
37
  nodeType: nodes.paragraph,
38
38
  label: 'Paragraph',
39
39
  action: helpers_1.demoteSectionToParagraph,
40
- isDisabled: (sectionDepth <= 1 && sectionOffset <= 1) || (0, track_changes_utils_1.isDeleted)(section),
40
+ isDisabled: (sectionDepth <= 1 && sectionOffset <= 1) || (0, track_changes_plugin_1.isDeleted)(section),
41
41
  isSelected: false,
42
42
  });
43
43
  options.push({
@@ -56,12 +56,12 @@ const buildOptions = (state) => {
56
56
  isDisabled: true,
57
57
  isSelected: true,
58
58
  });
59
- !(0, track_changes_utils_1.isDeleted)(paragraph) &&
59
+ !(0, track_changes_plugin_1.isDeleted)(paragraph) &&
60
60
  options.push({
61
61
  nodeType: nodes.section,
62
62
  label: 'Heading',
63
63
  action: helpers_1.promoteParagraphToSection,
64
- isDisabled: (0, track_changes_utils_1.isDeleted)(paragraph),
64
+ isDisabled: (0, track_changes_plugin_1.isDeleted)(paragraph),
65
65
  isSelected: false,
66
66
  });
67
67
  return options;
@@ -53,9 +53,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
54
  exports.FootnotesSelector = void 0;
55
55
  const style_guide_1 = require("@manuscripts/style-guide");
56
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
56
57
  const react_1 = __importStar(require("react"));
57
58
  const styled_components_1 = __importDefault(require("styled-components"));
58
- const track_changes_utils_1 = require("../../lib/track-changes-utils");
59
59
  const NotesContainer = styled_components_1.default.div `
60
60
  height: 90vh;
61
61
  max-height: 400px;
@@ -131,7 +131,7 @@ const FootnotesList = ({ footnotes, inlineFootnote, labels, isSelected, onSelect
131
131
  const remainingNotes = [];
132
132
  footnotes.forEach((footnote) => {
133
133
  const isNoteSelected = rids?.includes(footnote.attrs.id);
134
- if ((0, track_changes_utils_1.isDeleted)(footnote)) {
134
+ if ((0, track_changes_plugin_1.isDeleted)(footnote)) {
135
135
  return;
136
136
  }
137
137
  isNoteSelected
@@ -15,79 +15,14 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.addTrackChangesClassNames = exports.addTrackChangesAttributes = exports.getAttrsTrackingButton = void 0;
19
- exports.isDeleted = isDeleted;
20
- exports.isShadowDelete = isShadowDelete;
21
- exports.isPendingInsert = isPendingInsert;
22
- exports.isPending = isPending;
23
- exports.isPendingSetAttrs = isPendingSetAttrs;
24
- exports.getChangeClasses = getChangeClasses;
25
- exports.isTracked = isTracked;
18
+ exports.getAttrsTrackingButton = void 0;
26
19
  exports.isHidden = isHidden;
27
- exports.isDeletedText = isDeletedText;
28
- exports.getActualTextContent = getActualTextContent;
29
- exports.sanitizeAttrsChange = sanitizeAttrsChange;
30
20
  const style_guide_1 = require("@manuscripts/style-guide");
31
21
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
32
- const transform_1 = require("@manuscripts/transform");
33
22
  const react_1 = require("react");
34
23
  const server_1 = require("react-dom/server");
35
- function isDeleted(node) {
36
- if (node.attrs.dataTracked) {
37
- const changes = node.attrs.dataTracked;
38
- return changes.some(({ operation }) => operation === 'delete');
39
- }
40
- return false;
41
- }
42
- function isShadowDelete(node) {
43
- if (node.attrs.dataTracked) {
44
- const changes = node.attrs.dataTracked;
45
- return changes.some(({ operation, moveNodeId }) => operation === 'delete' && moveNodeId);
46
- }
47
- return false;
48
- }
49
- function isPendingInsert(node) {
50
- if (node.attrs.dataTracked) {
51
- const changes = node.attrs.dataTracked;
52
- return changes.some(({ operation, status }) => operation === 'insert' && status == 'pending');
53
- }
54
- return false;
55
- }
56
- function isPending(node) {
57
- if (node.attrs.dataTracked) {
58
- const changes = node.attrs.dataTracked;
59
- return changes.some(({ status }) => status == 'pending');
60
- }
61
- return false;
62
- }
63
- function isPendingSetAttrs(node) {
64
- if (node.attrs.dataTracked) {
65
- const changes = node.attrs.dataTracked;
66
- return changes.some(({ operation, status }) => operation === 'set_attrs' && status == 'pending');
67
- }
68
- return false;
69
- }
70
- function getChangeClasses(dataTracked) {
71
- const classes = [];
72
- if (dataTracked) {
73
- const changes = dataTracked;
74
- const operationClasses = new Map([
75
- ['insert', 'inserted'],
76
- ['delete', 'deleted'],
77
- ['set_attrs', 'set_attrs'],
78
- ]);
79
- changes.forEach(({ operation, status }) => classes.push(operationClasses.get(operation) || '', status));
80
- }
81
- return classes;
82
- }
83
- function isTracked(node) {
84
- if (node.attrs.dataTracked) {
85
- const changes = node.attrs.dataTracked;
86
- return changes.some(({ operation }) => operation === 'insert' ||
87
- operation === 'delete' ||
88
- operation === 'set_attrs');
89
- }
90
- return false;
24
+ function isHidden(node) {
25
+ return (0, track_changes_plugin_1.isDeleted)(node);
91
26
  }
92
27
  const getAttrsTrackingButton = (changeID) => {
93
28
  const el = document.createElement('button');
@@ -97,75 +32,3 @@ const getAttrsTrackingButton = (changeID) => {
97
32
  return el;
98
33
  };
99
34
  exports.getAttrsTrackingButton = getAttrsTrackingButton;
100
- function isHidden(node) {
101
- return isDeleted(node);
102
- }
103
- function isDeletedText(node) {
104
- if (node.type === transform_1.schema.nodes.text && node.marks.length) {
105
- const deleteMark = node.marks.find((mark) => mark.type === transform_1.schema.marks.tracked_delete);
106
- if (deleteMark &&
107
- deleteMark.attrs?.dataTracked?.status &&
108
- 'pending' === deleteMark.attrs?.dataTracked?.status) {
109
- return true;
110
- }
111
- }
112
- return false;
113
- }
114
- function getActualTextContent(fragment) {
115
- let finalContent = '';
116
- function getContent(fragment) {
117
- fragment.forEach((node) => {
118
- if (node.type !== transform_1.schema.nodes.text) {
119
- finalContent += getContent(node.content);
120
- }
121
- if (!isDeletedText(node)) {
122
- finalContent += node.textContent;
123
- }
124
- });
125
- }
126
- getContent(fragment);
127
- return finalContent;
128
- }
129
- function sanitizeAttrsChange(newAttr, currentAttrs) {
130
- return Object.keys(newAttr).reduce((acc, attr) => {
131
- const key = attr;
132
- if (!currentAttrs[key] &&
133
- currentAttrs[key] !== 0 &&
134
- !newAttr[key] &&
135
- newAttr[key] !== 0) {
136
- return acc;
137
- }
138
- acc[key] = newAttr[key];
139
- return acc;
140
- }, {});
141
- }
142
- const classNames = new Map([
143
- [track_changes_plugin_1.CHANGE_OPERATION.insert, 'inserted'],
144
- [track_changes_plugin_1.CHANGE_OPERATION.delete, 'deleted'],
145
- [track_changes_plugin_1.CHANGE_OPERATION.set_node_attributes, 'set_attrs'],
146
- ]);
147
- const addTrackChangesAttributes = (attrs, dom) => {
148
- dom.removeAttribute('data-track-id');
149
- dom.removeAttribute('data-track-op');
150
- dom.removeAttribute('data-track-status');
151
- const changes = attrs.dataTracked;
152
- if (!changes || !changes.length) {
153
- return;
154
- }
155
- const change = changes[0];
156
- dom.setAttribute('data-track-id', change.id);
157
- dom.setAttribute('data-track-op', change.operation);
158
- dom.setAttribute('data-track-status', change.status);
159
- };
160
- exports.addTrackChangesAttributes = addTrackChangesAttributes;
161
- const addTrackChangesClassNames = (attrs, dom) => {
162
- dom.classList.remove(...classNames.values());
163
- const changes = attrs.dataTracked;
164
- if (!changes || !changes.length) {
165
- return;
166
- }
167
- const change = changes[0];
168
- const className = classNames.get(change.operation);
169
- className && dom.classList.add(className);
170
- };
171
- exports.addTrackChangesClassNames = addTrackChangesClassNames;
@@ -204,7 +204,7 @@ const filterBlockNodes = (fragment, predicate) => {
204
204
  const newContent = child.content.size
205
205
  ? (0, exports.filterBlockNodes)(child.content, predicate)
206
206
  : child.content;
207
- if (predicate(child)) {
207
+ if (!predicate || predicate(child)) {
208
208
  updatedNodes.push(child.type.create(child.attrs, newContent, child.marks));
209
209
  }
210
210
  });
@@ -53,6 +53,7 @@ const transform_1 = require("@manuscripts/transform");
53
53
  const prosemirror_state_1 = require("prosemirror-state");
54
54
  const utils = __importStar(require("prosemirror-utils"));
55
55
  const track_changes_utils_1 = require("./track-changes-utils");
56
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
56
57
  const metaNodeTypes = [
57
58
  transform_1.schema.nodes.bibliography_item,
58
59
  transform_1.schema.nodes.affiliation,
@@ -82,7 +83,7 @@ exports.findChildrenAttrsByType = findChildrenAttrsByType;
82
83
  const updateNodeAttrs = (view, type, attrs) => {
83
84
  const child = (0, exports.findChildByID)(view, attrs.id);
84
85
  if (child) {
85
- const copy = (0, track_changes_utils_1.sanitizeAttrsChange)(attrs, child.node.attrs);
86
+ const copy = (0, track_changes_plugin_1.sanitizeAttrsChange)(attrs, child.node.attrs);
86
87
  delete copy.dataTracked;
87
88
  const pos = child.pos;
88
89
  const tr = view.state.tr;
package/dist/cjs/menus.js CHANGED
@@ -36,7 +36,7 @@ const getEditorMenus = (editor) => {
36
36
  const command = (0, commands_1.insertBackmatterSection)(category);
37
37
  return {
38
38
  id: `insert-${category.id}`,
39
- label: category.label || category.titles[0],
39
+ label: category.titles[0],
40
40
  isEnabled: isCommandValid(command),
41
41
  run: doCommand(command),
42
42
  };
@@ -47,7 +47,7 @@ const getEditorMenus = (editor) => {
47
47
  : (0, commands_1.insertAbstractSection)(category);
48
48
  return {
49
49
  id: `insert-${category.id}`,
50
- label: category.label || category.titles[0],
50
+ label: category.titles[0],
51
51
  isEnabled: isCommandValid(command),
52
52
  run: doCommand(command),
53
53
  };
@@ -16,12 +16,12 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.buildPluginState = exports.affiliationsKey = void 0;
19
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
19
20
  const transform_1 = require("@manuscripts/transform");
20
21
  const lodash_1 = require("lodash");
21
22
  const prosemirror_state_1 = require("prosemirror-state");
22
23
  const prosemirror_view_1 = require("prosemirror-view");
23
24
  const authors_1 = require("../lib/authors");
24
- const track_changes_utils_1 = require("../lib/track-changes-utils");
25
25
  exports.affiliationsKey = new prosemirror_state_1.PluginKey('affiliations');
26
26
  let id = 1;
27
27
  const buildPluginState = (doc, $old) => {
@@ -36,7 +36,7 @@ const buildPluginState = (doc, $old) => {
36
36
  affiliations.push(attrs);
37
37
  }
38
38
  if ((0, transform_1.isContributorNode)(node)) {
39
- (0, track_changes_utils_1.isDeleted)(node) && deletedContribId.add(attrs.id);
39
+ (0, track_changes_plugin_1.isDeleted)(node) && deletedContribId.add(attrs.id);
40
40
  nodes.push([node, pos]);
41
41
  contributors.push(attrs);
42
42
  }
@@ -17,22 +17,19 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.objectsKey = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
- const prosemirror_model_1 = require("prosemirror-model");
21
20
  const prosemirror_state_1 = require("prosemirror-state");
22
21
  const prosemirror_view_1 = require("prosemirror-view");
23
- const filtered_document_1 = require("../lib/filtered-document");
22
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
24
23
  exports.objectsKey = new prosemirror_state_1.PluginKey('objects');
25
24
  exports.default = () => {
26
25
  return new prosemirror_state_1.Plugin({
27
26
  key: exports.objectsKey,
28
27
  state: {
29
28
  init: (config, state) => {
30
- const filteredDoc = (0, filtered_document_1.getDocWithoutMovedContent)(state.doc);
31
- return (0, transform_1.buildTargets)(prosemirror_model_1.Fragment.from(filteredDoc.content));
29
+ return (0, transform_1.buildTargets)((0, track_changes_plugin_1.clear)(state.doc).descendants);
32
30
  },
33
31
  apply: (tr) => {
34
- const filteredDoc = (0, filtered_document_1.getDocWithoutMovedContent)(tr.doc);
35
- return (0, transform_1.buildTargets)(prosemirror_model_1.Fragment.from(filteredDoc.content));
32
+ return (0, transform_1.buildTargets)((0, track_changes_plugin_1.clear)(tr.doc).descendants);
36
33
  },
37
34
  },
38
35
  props: {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
4
4
  const transform_1 = require("@manuscripts/transform");
5
5
  const prosemirror_state_1 = require("prosemirror-state");
6
- const filtered_document_1 = require("../lib/filtered-document");
7
6
  const plugins_1 = require("../lib/plugins");
8
7
  const isManuscriptNode = (node) => {
9
8
  return node && node.type === transform_1.schema.nodes.manuscript;
@@ -16,12 +15,11 @@ exports.default = () => {
16
15
  }
17
16
  const ids = new Set();
18
17
  const tr = newState.tr;
19
- newState.doc.descendants((node, pos, parent) => {
18
+ (0, track_changes_plugin_1.clear)(newState.doc).descendants((node, pos, parent) => {
20
19
  if (!(node.type.spec.attrs && 'id' in node.type.spec.attrs) ||
21
20
  (0, transform_1.isHighlightMarkerNode)(node) ||
22
21
  isManuscriptNode(node) ||
23
- isManuscriptNode(parent) ||
24
- (0, filtered_document_1.isMoved)(node)) {
22
+ isManuscriptNode(parent)) {
25
23
  return;
26
24
  }
27
25
  let id = node.attrs.id;
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.getNewMatch = getNewMatch;
19
19
  exports.getClosestMatch = getClosestMatch;
20
20
  exports.getMatches = getMatches;
21
- const track_changes_utils_1 = require("../../lib/track-changes-utils");
21
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
22
22
  function getNewMatch(side, current, selection, matches) {
23
23
  if (current < 0) {
24
24
  return getClosestMatch(side, selection, matches);
@@ -54,7 +54,7 @@ function getMatches(doc, value, caseSensitive, ignoreDiacritics) {
54
54
  }
55
55
  const matches = [];
56
56
  doc.descendants((node, pos) => {
57
- if ((0, track_changes_utils_1.isDeleted)(node) || (0, track_changes_utils_1.isDeletedText)(node)) {
57
+ if ((0, track_changes_plugin_1.isDeleted)(node) || (0, track_changes_plugin_1.isDeletedText)(node)) {
58
58
  return;
59
59
  }
60
60
  if (node.isText && node.text) {
@@ -6,7 +6,6 @@ const prosemirror_state_1 = require("prosemirror-state");
6
6
  const prosemirror_utils_1 = require("prosemirror-utils");
7
7
  const prosemirror_view_1 = require("prosemirror-view");
8
8
  const icons_1 = require("../icons");
9
- const navigation_utils_1 = require("../lib/navigation-utils");
10
9
  exports.sectionCategoryKey = new prosemirror_state_1.PluginKey('section-category');
11
10
  exports.default = (props) => new prosemirror_state_1.Plugin({
12
11
  key: exports.sectionCategoryKey,
@@ -33,74 +32,42 @@ const createMenuItem = (props, contents, handler, isDisabled, isSelected) => {
33
32
  item.classList.add('disabled');
34
33
  }
35
34
  item.textContent = contents;
36
- item.setAttribute('tabindex', '0');
37
- item.addEventListener('mousedown', handler);
38
- item.addEventListener('keydown', (0, navigation_utils_1.handleEnterKey)(handler));
35
+ item.addEventListener('mousedown', (event) => {
36
+ handler(event);
37
+ props.popper.destroy();
38
+ });
39
39
  return item;
40
40
  };
41
41
  const createMenu = (props, currentCategory, categories, usedCategoryIDs, onSelect) => {
42
42
  const menu = document.createElement('div');
43
43
  menu.className = 'section-category menu';
44
- const menuItems = [];
45
- const removeKeydownListener = (0, navigation_utils_1.createKeyboardInteraction)({
46
- container: document,
47
- navigation: {
48
- getItems: () => menuItems,
49
- arrowKeys: {
50
- forward: 'ArrowDown',
51
- backward: 'ArrowUp',
52
- },
53
- getCurrentElement: () => document.activeElement,
54
- },
55
- });
56
- const destroy = () => {
57
- removeKeydownListener();
58
- props.popper.destroy();
59
- };
60
44
  categories.forEach((category) => {
61
- const item = createMenuItem(props, category.label || category.titles[0], () => {
62
- onSelect(category);
63
- destroy();
64
- }, category.isUnique && usedCategoryIDs.has(category.id), currentCategory === category);
65
- menuItems.push(item);
45
+ const item = createMenuItem(props, category.titles[0], () => onSelect(category), category.isUnique && usedCategoryIDs.has(category.id), currentCategory === category);
66
46
  menu.appendChild(item);
67
47
  });
68
- return { menu, destroy };
48
+ return menu;
69
49
  };
70
50
  const createButton = (props, view, pos, currentCategory, categories, usedCategoryIDs, canEdit = true, disabled) => {
71
- let menuInstance = null;
72
51
  const handleSelect = (category) => {
73
52
  const tr = view.state.tr;
74
53
  tr.setNodeAttribute(pos, 'category', category.id);
75
54
  view.dispatch(tr);
76
55
  };
77
- const openMenu = () => {
78
- menuInstance = createMenu(props, currentCategory, categories, usedCategoryIDs, handleSelect);
79
- props.popper.show(button, menuInstance.menu, 'bottom-end', false);
80
- };
81
56
  const button = document.createElement('button');
82
57
  button.innerHTML = icons_1.sectionCategoryIcon;
83
58
  button.classList.add('section-category-button');
84
59
  button.setAttribute('aria-label', 'Section categories menu');
85
60
  if (currentCategory) {
86
- button.setAttribute('data-tooltip-content', currentCategory.label || currentCategory.titles[0]);
61
+ button.setAttribute('data-tooltip-content', currentCategory.titles[0]);
87
62
  button.classList.add('assigned');
88
63
  }
89
64
  if (disabled) {
90
65
  button.classList.add('disabled');
91
66
  }
92
67
  else if (canEdit) {
93
- button.addEventListener('click', openMenu);
94
- (0, navigation_utils_1.createKeyboardInteraction)({
95
- container: button,
96
- additionalKeys: {
97
- Enter: openMenu,
98
- Escape: (e) => {
99
- e.preventDefault();
100
- menuInstance?.destroy();
101
- menuInstance = null;
102
- },
103
- },
68
+ button.addEventListener('mousedown', () => {
69
+ const menu = createMenu(props, currentCategory, categories, usedCategoryIDs, handleSelect);
70
+ props.popper.show(button, menu, 'bottom-end', false);
104
71
  });
105
72
  }
106
73
  return button;