@manuscripts/body-editor 2.6.22-LEAN-4192.0 → 2.6.22

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 (38) hide show
  1. package/dist/cjs/commands.js +13 -16
  2. package/dist/cjs/icons.js +5 -3
  3. package/dist/cjs/lib/context-menu.js +1 -3
  4. package/dist/cjs/menus.js +13 -50
  5. package/dist/cjs/plugins/section-category/section-category-utils.js +40 -70
  6. package/dist/cjs/plugins/section_title/autocompletion.js +15 -12
  7. package/dist/cjs/versions.js +1 -1
  8. package/dist/es/commands.js +11 -14
  9. package/dist/es/icons.js +5 -3
  10. package/dist/es/lib/context-menu.js +1 -3
  11. package/dist/es/menus.js +15 -52
  12. package/dist/es/plugins/section-category/section-category-utils.js +40 -70
  13. package/dist/es/plugins/section_title/autocompletion.js +16 -13
  14. package/dist/es/versions.js +1 -1
  15. package/dist/types/commands.d.ts +1 -1
  16. package/dist/types/configs/ManuscriptsEditor.d.ts +3 -3
  17. package/dist/types/icons.d.ts +1 -0
  18. package/dist/types/plugins/section-category/index.d.ts +1 -5
  19. package/dist/types/plugins/section-category/section-category-utils.d.ts +3 -11
  20. package/dist/types/plugins/section_title/autocompletion.d.ts +3 -3
  21. package/dist/types/versions.d.ts +1 -1
  22. package/package.json +2 -2
  23. package/styles/AdvancedEditor.css +1 -1
  24. package/dist/cjs/lib/section-categories.js +0 -48
  25. package/dist/cjs/lib/section-titles.js +0 -38
  26. package/dist/cjs/testing/default-editor-data.js +0 -85
  27. package/dist/cjs/testing/polyfill-dom.js +0 -35
  28. package/dist/cjs/testing/setup-editor.js +0 -63
  29. package/dist/es/lib/section-categories.js +0 -40
  30. package/dist/es/lib/section-titles.js +0 -35
  31. package/dist/es/testing/default-editor-data.js +0 -79
  32. package/dist/es/testing/polyfill-dom.js +0 -31
  33. package/dist/es/testing/setup-editor.js +0 -55
  34. package/dist/types/lib/section-categories.d.ts +0 -23
  35. package/dist/types/lib/section-titles.d.ts +0 -17
  36. package/dist/types/testing/default-editor-data.d.ts +0 -28
  37. package/dist/types/testing/polyfill-dom.d.ts +0 -16
  38. package/dist/types/testing/setup-editor.d.ts +0 -20
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.autoComplete = exports.mergeCellsWithSpace = exports.addColumns = exports.addHeaderRow = exports.addRows = exports.addInlineComment = exports.addNodeComment = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertKeywords = exports.insertContributors = exports.insertAbstract = exports.insertBackMatterSection = exports.insertSection = exports.insertGraphicalAbstract = exports.insertBoxElement = exports.insertInlineFootnote = exports.insertFootnotesElement = exports.insertTableElementFooter = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.findPosBeforeFirstSubsection = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertTable = exports.insertFigure = exports.insertGeneralTableFootnote = exports.insertInlineTableFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = exports.addToStart = void 0;
18
+ exports.autoComplete = exports.mergeCellsWithSpace = exports.addColumns = exports.addHeaderRow = exports.addRows = exports.addInlineComment = exports.addNodeComment = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertKeywords = exports.insertContributors = exports.insertAbstract = exports.insertBackmatterSection = exports.insertSection = exports.insertGraphicalAbstract = exports.insertBoxElement = exports.insertInlineFootnote = exports.insertFootnotesElement = exports.insertTableElementFooter = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.findPosBeforeFirstSubsection = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertTable = exports.insertFigure = exports.insertGeneralTableFootnote = exports.insertInlineTableFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = exports.addToStart = void 0;
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
20
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
21
21
  const transform_1 = require("@manuscripts/transform");
@@ -29,7 +29,6 @@ const comments_1 = require("./lib/comments");
29
29
  const doc_1 = require("./lib/doc");
30
30
  const footnotes_1 = require("./lib/footnotes");
31
31
  const helpers_1 = require("./lib/helpers");
32
- const section_titles_1 = require("./lib/section-titles");
33
32
  const track_changes_utils_1 = require("./lib/track-changes-utils");
34
33
  const utils_1 = require("./lib/utils");
35
34
  const comments_2 = require("./plugins/comments");
@@ -500,7 +499,7 @@ const insertGraphicalAbstract = (state, dispatch, view) => {
500
499
  }
501
500
  const abstracts = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.abstracts)[0];
502
501
  const pos = abstracts.pos + abstracts.node.content.size + 1;
503
- const section = transform_1.schema.nodes.graphical_abstract_section.createAndFill({ category: 'MPSectionCategory:abstract-graphical' }, [
502
+ const section = transform_1.schema.nodes.graphical_abstract_section.createAndFill({}, [
504
503
  transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Graphical Abstract')),
505
504
  createAndFillFigureElement(state),
506
505
  ]);
@@ -540,9 +539,7 @@ const insertSection = (subsection = false) => (state, dispatch, view) => {
540
539
  const body = (0, doc_1.findBody)(state.doc);
541
540
  pos = body.pos + body.node.content.size + 1;
542
541
  }
543
- const section = nodes.section.createAndFill({
544
- category: subsection ? 'MPSectionCategory:subsection' : '',
545
- });
542
+ const section = nodes.section.createAndFill();
546
543
  const tr = state.tr.insert(pos, section);
547
544
  if (dispatch) {
548
545
  const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos + 2);
@@ -552,11 +549,10 @@ const insertSection = (subsection = false) => (state, dispatch, view) => {
552
549
  return true;
553
550
  };
554
551
  exports.insertSection = insertSection;
555
- const insertBackMatterSection = (category) => (state, dispatch, view) => {
556
- var _a;
552
+ const insertBackmatterSection = (category) => (state, dispatch, view) => {
557
553
  const backmatter = (0, doc_1.findBackmatter)(state.doc);
558
554
  const sections = (0, prosemirror_utils_1.findChildrenByType)(backmatter.node, transform_1.schema.nodes.section);
559
- if (sections.some((s) => s.node.attrs.category === category)) {
555
+ if (sections.some((s) => s.node.attrs.category === category.id)) {
560
556
  return false;
561
557
  }
562
558
  const bibliography = (0, doc_1.findBibliographySection)(state.doc);
@@ -567,10 +563,11 @@ const insertBackMatterSection = (category) => (state, dispatch, view) => {
567
563
  else {
568
564
  pos = backmatter.pos + backmatter.node.content.size + 1;
569
565
  }
570
- const node = transform_1.schema.nodes.section.createAndFill({
571
- category,
572
- }, [
573
- transform_1.schema.nodes.section_title.create({}, transform_1.schema.text(((_a = section_titles_1.sectionTitles.get(category)) === null || _a === void 0 ? void 0 : _a.split('|')[0]) || '')),
566
+ const attrs = {
567
+ category: category.id,
568
+ };
569
+ const node = transform_1.schema.nodes.section.create(attrs, [
570
+ transform_1.schema.nodes.section_title.create({}, transform_1.schema.text(category.titles[0])),
574
571
  ]);
575
572
  const tr = state.tr.insert(pos, node);
576
573
  if (dispatch) {
@@ -580,7 +577,7 @@ const insertBackMatterSection = (category) => (state, dispatch, view) => {
580
577
  }
581
578
  return true;
582
579
  };
583
- exports.insertBackMatterSection = insertBackMatterSection;
580
+ exports.insertBackmatterSection = insertBackmatterSection;
584
581
  const findSelectedList = (selection) => (selection instanceof prosemirror_state_1.NodeSelection &&
585
582
  selection.node.type === transform_1.schema.nodes.list && {
586
583
  pos: selection.from,
@@ -588,12 +585,12 @@ const findSelectedList = (selection) => (selection instanceof prosemirror_state_
588
585
  }) ||
589
586
  (0, prosemirror_utils_1.findParentNodeOfType)([transform_1.schema.nodes.list])(selection);
590
587
  const insertAbstract = (state, dispatch, view) => {
591
- if ((0, utils_1.getMatchingChild)(state.doc, (node) => node.attrs.category === 'MPSectionCategory:abstract', true)) {
588
+ if ((0, utils_1.getMatchingChild)(state.doc, (node) => node.attrs.category === 'abstract', true)) {
592
589
  return false;
593
590
  }
594
591
  const abstracts = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.abstracts)[0];
595
592
  const pos = abstracts.pos + 1;
596
- const section = transform_1.schema.nodes.section.createAndFill({ category: 'MPSectionCategory:abstract' }, [
593
+ const section = transform_1.schema.nodes.section.createAndFill({ category: 'abstract' }, [
597
594
  transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Abstract')),
598
595
  transform_1.schema.nodes.paragraph.create({ placeholder: 'Type abstract here...' }),
599
596
  ]);
package/dist/cjs/icons.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteIcon = exports.alertIcon = void 0;
3
+ exports.sectionCategoryIcon = exports.deleteIcon = exports.alertIcon = void 0;
4
4
  const style_guide_1 = require("@manuscripts/style-guide");
5
5
  const react_1 = require("react");
6
6
  const server_1 = require("react-dom/server");
7
- exports.alertIcon = (0, server_1.renderToStaticMarkup)((0, react_1.createElement)(style_guide_1.AlertIcon));
8
- exports.deleteIcon = (0, server_1.renderToStaticMarkup)((0, react_1.createElement)(style_guide_1.DeleteIcon));
7
+ const renderIcon = (c) => (0, server_1.renderToStaticMarkup)((0, react_1.createElement)(c));
8
+ exports.alertIcon = renderIcon(style_guide_1.AlertIcon);
9
+ exports.deleteIcon = renderIcon(style_guide_1.DeleteIcon);
10
+ exports.sectionCategoryIcon = renderIcon(style_guide_1.SectionCategoryIcon);
@@ -81,9 +81,7 @@ class ContextMenu {
81
81
  const level = (0, exports.sectionLevel)($pos.depth);
82
82
  const label = `New ${level} to ${itemTitle}`;
83
83
  section.appendChild(this.createMenuItem(label, () => {
84
- insertNode(transform_1.schema.nodes.section, insPos, {
85
- category: 'MPSectionCategory:subsection',
86
- });
84
+ insertNode(transform_1.schema.nodes.section, insPos);
87
85
  popper.destroy();
88
86
  }));
89
87
  }
package/dist/cjs/menus.js CHANGED
@@ -23,9 +23,21 @@ const commands_1 = require("./commands");
23
23
  const InsertTableDialog_1 = require("./components/toolbar/InsertTableDialog");
24
24
  const ListMenuItem_1 = require("./components/toolbar/ListMenuItem");
25
25
  const hierarchy_1 = require("./lib/hierarchy");
26
+ const editor_props_1 = require("./plugins/editor-props");
26
27
  const getEditorMenus = (editor) => {
27
28
  const { isCommandValid, state } = editor;
28
29
  const doCommand = (command) => () => editor.doCommand(command);
30
+ const props = (0, editor_props_1.getEditorProps)(state);
31
+ const insertBackmatterSectionMenu = (category) => {
32
+ const command = (0, commands_1.insertBackmatterSection)(category);
33
+ return {
34
+ id: `insert-${category.id}`,
35
+ label: category.titles[0],
36
+ isEnabled: isCommandValid(command),
37
+ run: doCommand(command),
38
+ };
39
+ };
40
+ const categories = (0, transform_1.getGroupCateogries)(props.sectionCategories, 'backmatter');
29
41
  const edit = {
30
42
  id: 'edit',
31
43
  label: 'Edit',
@@ -108,56 +120,7 @@ const getEditorMenus = (editor) => {
108
120
  id: 'back-matter',
109
121
  label: 'Author Notes',
110
122
  isEnabled: true,
111
- submenu: [
112
- {
113
- id: 'insert-acknowledgements',
114
- label: 'Acknowledgements',
115
- isEnabled: isCommandValid((0, commands_1.insertBackMatterSection)('MPSectionCategory:acknowledgement')),
116
- run: doCommand((0, commands_1.insertBackMatterSection)('MPSectionCategory:acknowledgement')),
117
- },
118
- {
119
- id: 'insert-availability',
120
- label: 'Availability',
121
- isEnabled: isCommandValid((0, commands_1.insertBackMatterSection)('MPSectionCategory:availability')),
122
- run: doCommand((0, commands_1.insertBackMatterSection)('MPSectionCategory:availability')),
123
- },
124
- {
125
- id: 'insert-coi-statement',
126
- label: 'COI Statement',
127
- isEnabled: isCommandValid((0, commands_1.insertBackMatterSection)('MPSectionCategory:competing-interests')),
128
- run: doCommand((0, commands_1.insertBackMatterSection)('MPSectionCategory:competing-interests')),
129
- },
130
- {
131
- id: 'insert-con',
132
- label: 'Contributed-by Information',
133
- isEnabled: isCommandValid((0, commands_1.insertBackMatterSection)('MPSectionCategory:con')),
134
- run: doCommand((0, commands_1.insertBackMatterSection)('MPSectionCategory:con')),
135
- },
136
- {
137
- id: 'insert-ethics-statement',
138
- label: 'Ethics Statement',
139
- isEnabled: isCommandValid((0, commands_1.insertBackMatterSection)('MPSectionCategory:ethics-statement')),
140
- run: doCommand((0, commands_1.insertBackMatterSection)('MPSectionCategory:ethics-statement')),
141
- },
142
- {
143
- id: 'insert-financial-disclosure',
144
- label: 'Financial Disclosure',
145
- isEnabled: isCommandValid((0, commands_1.insertBackMatterSection)('MPSectionCategory:financial-disclosure')),
146
- run: doCommand((0, commands_1.insertBackMatterSection)('MPSectionCategory:financial-disclosure')),
147
- },
148
- {
149
- id: 'insert-supplementary-material',
150
- label: 'Supplementary Material',
151
- isEnabled: isCommandValid((0, commands_1.insertBackMatterSection)('MPSectionCategory:supplementary-material')),
152
- run: doCommand((0, commands_1.insertBackMatterSection)('MPSectionCategory:supplementary-material')),
153
- },
154
- {
155
- id: 'insert-supported-by',
156
- label: 'Supported By',
157
- isEnabled: isCommandValid((0, commands_1.insertBackMatterSection)('MPSectionCategory:supported-by')),
158
- run: doCommand((0, commands_1.insertBackMatterSection)('MPSectionCategory:supported-by')),
159
- },
160
- ],
123
+ submenu: categories.map(insertBackmatterSectionMenu),
161
124
  },
162
125
  {
163
126
  id: 'insert-section',
@@ -1,20 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildPluginState = exports.sectionCategoryKey = void 0;
4
- const style_guide_1 = require("@manuscripts/style-guide");
3
+ exports.buildPluginState = void 0;
5
4
  const transform_1 = require("@manuscripts/transform");
6
- const prosemirror_state_1 = require("prosemirror-state");
5
+ const prosemirror_utils_1 = require("prosemirror-utils");
7
6
  const prosemirror_view_1 = require("prosemirror-view");
8
- const react_1 = require("react");
9
- const server_1 = require("react-dom/server");
7
+ const icons_1 = require("../../icons");
10
8
  const popper_1 = require("../../lib/popper");
11
- const section_categories_1 = require("../../lib/section-categories");
12
- const utils_1 = require("../../lib/utils");
13
- exports.sectionCategoryKey = new prosemirror_state_1.PluginKey('section-category');
14
9
  const popper = new popper_1.PopperManager();
15
- function changeNodeAttrs(view, node, type, pos) {
16
- view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), { category: type })));
17
- }
18
10
  function createMenuItem(contents, handler, isDisabled = false, isSelected = false) {
19
11
  const item = document.createElement('button');
20
12
  item.className = `menu-item ${isDisabled ? 'disabled' : ''} ${isSelected ? 'selected' : ''}`;
@@ -25,13 +17,11 @@ function createMenuItem(contents, handler, isDisabled = false, isSelected = fals
25
17
  });
26
18
  return item;
27
19
  }
28
- function createMenu(view, props, node, pos, currCategory) {
20
+ function createMenu(currentCategory, categories, usedCategoryIDs, onSelect) {
29
21
  const menu = document.createElement('div');
30
22
  menu.className = 'section-category menu';
31
- const existingCatsCounted = getExistingCatsCounted(view.state);
32
- const categories = getSortedSectionCategories(view.state, node, props.sectionCategories, pos, existingCatsCounted);
33
23
  categories.forEach((category) => {
34
- const item = createMenuItem(category.name, () => changeNodeAttrs(view, node, category._id, pos), category.isDisabled, currCategory === category._id);
24
+ const item = createMenuItem(category.titles[0], () => onSelect(category), category.isUnique && usedCategoryIDs.has(category.id), currentCategory === category);
35
25
  menu.appendChild(item);
36
26
  });
37
27
  document.addEventListener('mousedown', (event) => {
@@ -41,16 +31,24 @@ function createMenu(view, props, node, pos, currCategory) {
41
31
  });
42
32
  return menu;
43
33
  }
44
- function createButton(view, props, node, pos, category, canEdit = true) {
34
+ function createButton(view, pos, currentCategory, categories, usedCategoryIDs, canEdit = true) {
35
+ const handleSelect = (category) => {
36
+ const tr = view.state.tr;
37
+ tr.setNodeAttribute(pos, 'category', category.id);
38
+ view.dispatch(tr);
39
+ };
45
40
  const arrow = document.createElement('div');
46
41
  arrow.className = 'section-category popper-arrow';
47
42
  const button = document.createElement('button');
48
- button.innerHTML = (0, server_1.renderToStaticMarkup)((0, react_1.createElement)(style_guide_1.SectionCategoryIcon));
49
- button.className = `section-category-button ${category && 'assigned'}`;
43
+ button.innerHTML = icons_1.sectionCategoryIcon;
44
+ button.classList.add('section-category-button');
45
+ if (currentCategory) {
46
+ button.classList.add('assigned');
47
+ }
50
48
  if (canEdit) {
51
49
  button.addEventListener('mousedown', () => {
52
50
  popper.destroy();
53
- const menu = createMenu(view, props, node, pos, category);
51
+ const menu = createMenu(currentCategory, categories, usedCategoryIDs, handleSelect);
54
52
  popper.show(button, menu, 'bottom-end', false, [
55
53
  { name: 'offset', options: { offset: [0, -10] } },
56
54
  ]);
@@ -62,7 +60,7 @@ function createButton(view, props, node, pos, category, canEdit = true) {
62
60
  tooltip.className = 'section-category tooltip';
63
61
  tooltip.textContent = 'Category:';
64
62
  const span = document.createElement('span');
65
- span.textContent = (0, section_categories_1.getCategoryName)(props.sectionCategories, category);
63
+ span.textContent = (currentCategory === null || currentCategory === void 0 ? void 0 : currentCategory.titles[0]) || '';
66
64
  tooltip.appendChild(span);
67
65
  tooltip.appendChild(arrow);
68
66
  popper.show(button, tooltip, 'left', false, [
@@ -79,62 +77,34 @@ function createButton(view, props, node, pos, category, canEdit = true) {
79
77
  function buildPluginState(state, props) {
80
78
  const decorations = [];
81
79
  const can = props.getCapabilities();
80
+ const categories = props.sectionCategories;
81
+ const usedCategoryIDs = getUsedSectionCategoryIDs(state);
82
82
  state.doc.descendants((node, pos) => {
83
- if ((0, transform_1.isSectionNode)(node)) {
84
- const attrs = node.attrs;
85
- if ((0, section_categories_1.isEditableSectionCategoryID)(attrs.category) &&
86
- !(0, section_categories_1.isUnique)(attrs.category) &&
87
- !(0, section_categories_1.isSubSection)(attrs.category)) {
88
- decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, (view) => createButton(view, props, node, pos, attrs.category, can === null || can === void 0 ? void 0 : can.editArticle)));
89
- }
83
+ if (node.type === transform_1.schema.nodes.abstracts ||
84
+ node.type === transform_1.schema.nodes.box_element) {
85
+ return false;
90
86
  }
91
- if (node.type === transform_1.schema.nodes.box_element) {
87
+ if ((0, transform_1.isSectionNode)(node)) {
88
+ const categoryID = node.attrs.category;
89
+ const category = categories.get(categoryID);
90
+ const $pos = state.doc.resolve(pos);
91
+ const group = isInBackmatter($pos) ? 'backmatter' : 'body';
92
+ const groupCategories = (0, transform_1.getGroupCateogries)(categories, group);
93
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, (view) => createButton(view, pos, category, groupCategories, usedCategoryIDs, can === null || can === void 0 ? void 0 : can.editArticle)));
92
94
  return false;
93
95
  }
94
96
  });
95
97
  return { decorations: prosemirror_view_1.DecorationSet.create(state.doc, decorations) };
96
98
  }
97
99
  exports.buildPluginState = buildPluginState;
98
- function getExistingCatsCounted(state) {
99
- const existingCatsCounted = {};
100
- state.doc.descendants((node) => {
101
- var _a;
102
- if (node.type.name === 'section' &&
103
- ((_a = node.attrs.category) === null || _a === void 0 ? void 0 : _a.startsWith('MPSectionCategory:'))) {
104
- existingCatsCounted[node.attrs.category] =
105
- (existingCatsCounted[node.attrs.category] || 0) + 1;
106
- }
107
- });
108
- return existingCatsCounted;
109
- }
110
- function getSortedSectionCategories(state, container, sectionCategories, pos, existingCatsCounted) {
111
- var _a;
112
- let groupIDToUse = '';
113
- if (container.attrs.category) {
114
- const sectionCategory = sectionCategories.find(({ _id }) => _id === container.attrs.category);
115
- if (sectionCategory) {
116
- groupIDToUse = (_a = sectionCategory.groupIDs) === null || _a === void 0 ? void 0 : _a[0];
117
- }
118
- }
119
- else {
120
- const isChildOfBody = (0, utils_1.isChildOfNodeTypes)(state.doc, pos, [
121
- transform_1.schema.nodes.body,
122
- ]);
123
- if (isChildOfBody) {
124
- groupIDToUse = 'MPSectionCategory:body';
125
- }
126
- else {
127
- groupIDToUse = 'MPSectionCategory:backmatter';
128
- }
129
- }
130
- if (!groupIDToUse) {
131
- return [];
132
- }
133
- return sectionCategories
134
- .filter((category) => { var _a; return (_a = category.groupIDs) === null || _a === void 0 ? void 0 : _a.includes(groupIDToUse); })
135
- .map((category) => {
136
- var _a, _b;
137
- return (Object.assign(Object.assign({}, category), { isDisabled: Boolean(existingCatsCounted[category._id] &&
138
- (0, section_categories_1.isBackMatterSection)((_b = (_a = category.groupIDs) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '')) }));
100
+ const getUsedSectionCategoryIDs = (state) => {
101
+ const sections = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.section);
102
+ const used = new Set();
103
+ sections.forEach(({ node }) => {
104
+ node.attrs.category && used.add(node.attrs.category);
139
105
  });
140
- }
106
+ return used;
107
+ };
108
+ const isInBackmatter = ($pos) => {
109
+ return !!(0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)($pos, transform_1.schema.nodes.backmatter);
110
+ };
@@ -3,19 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkForCompletion = exports.hasAutoCompletionSlack = void 0;
4
4
  const transform_1 = require("@manuscripts/transform");
5
5
  const prosemirror_utils_1 = require("prosemirror-utils");
6
- const section_titles_1 = require("../../lib/section-titles");
7
6
  const track_changes_utils_1 = require("../../lib/track-changes-utils");
7
+ const editor_props_1 = require("../editor-props");
8
8
  function cursorAtTheEndOfText(state, nodeSize, nodePos) {
9
9
  const { from, to } = state.selection;
10
10
  return from === to && to === nodePos + nodeSize - 1;
11
11
  }
12
12
  const isUpperCase = (test) => test === test.toUpperCase() && test.length > 1;
13
- function hasAutoCompletionSlack(parentSection, titleSection) {
14
- var _a;
15
- const category = parentSection.attrs.category;
16
- const titles = (_a = section_titles_1.sectionTitles.get(category)) === null || _a === void 0 ? void 0 : _a.split('|');
17
- if (category && (titles === null || titles === void 0 ? void 0 : titles.length) && titleSection.textContent) {
18
- const actualTextContent = (0, track_changes_utils_1.getActualTextContent)(titleSection.content);
13
+ function hasAutoCompletionSlack(node, category) {
14
+ const titles = category.titles;
15
+ if (titles.length && node.textContent) {
16
+ const actualTextContent = (0, track_changes_utils_1.getActualTextContent)(node.content);
19
17
  const title = titles.find((t) => t.toLowerCase().startsWith(actualTextContent.toLowerCase()));
20
18
  if (title) {
21
19
  const suggestionPart = title.slice(actualTextContent.length);
@@ -33,15 +31,20 @@ function hasAutoCompletionSlack(parentSection, titleSection) {
33
31
  exports.hasAutoCompletionSlack = hasAutoCompletionSlack;
34
32
  function checkForCompletion(state) {
35
33
  const section = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)(state.selection.$from, transform_1.schema.nodes.section);
34
+ if (!section) {
35
+ return;
36
+ }
36
37
  const title = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)(state.selection.$from, transform_1.schema.nodes.section_title);
37
- if (section &&
38
- title &&
39
- cursorAtTheEndOfText(state, title.node.nodeSize, title.pos)) {
40
- const text = hasAutoCompletionSlack(section.node, title.node);
38
+ if (!title || !cursorAtTheEndOfText(state, title.node.nodeSize, title.pos)) {
39
+ return;
40
+ }
41
+ const props = (0, editor_props_1.getEditorProps)(state);
42
+ const category = props.sectionCategories.get(section.node.attrs.category);
43
+ if (category) {
44
+ const text = hasAutoCompletionSlack(title.node, category);
41
45
  if (text) {
42
46
  return text;
43
47
  }
44
48
  }
45
- return null;
46
49
  }
47
50
  exports.checkForCompletion = checkForCompletion;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MATHJAX_VERSION = exports.VERSION = void 0;
4
- exports.VERSION = '2.6.22-LEAN-4192.0';
4
+ exports.VERSION = '2.6.22';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -26,7 +26,6 @@ import { getCommentKey, getCommentRange } from './lib/comments';
26
26
  import { findBackmatter, findBibliographySection, findBody, insertFootnotesSection, insertSupplementsNode, } from './lib/doc';
27
27
  import { createFootnote, findFootnotesContainerNode, getFootnotesElementState, } from './lib/footnotes';
28
28
  import { findWordBoundaries, isNodeOfType, nearestAncestor, } from './lib/helpers';
29
- import { sectionTitles } from './lib/section-titles';
30
29
  import { isDeleted } from './lib/track-changes-utils';
31
30
  import { findParentNodeWithId, getChildOfType, getMatchingChild, } from './lib/utils';
32
31
  import { setCommentSelection } from './plugins/comments';
@@ -472,7 +471,7 @@ export const insertGraphicalAbstract = (state, dispatch, view) => {
472
471
  }
473
472
  const abstracts = findChildrenByType(state.doc, schema.nodes.abstracts)[0];
474
473
  const pos = abstracts.pos + abstracts.node.content.size + 1;
475
- const section = schema.nodes.graphical_abstract_section.createAndFill({ category: 'MPSectionCategory:abstract-graphical' }, [
474
+ const section = schema.nodes.graphical_abstract_section.createAndFill({}, [
476
475
  schema.nodes.section_title.create({}, schema.text('Graphical Abstract')),
477
476
  createAndFillFigureElement(state),
478
477
  ]);
@@ -511,9 +510,7 @@ export const insertSection = (subsection = false) => (state, dispatch, view) =>
511
510
  const body = findBody(state.doc);
512
511
  pos = body.pos + body.node.content.size + 1;
513
512
  }
514
- const section = nodes.section.createAndFill({
515
- category: subsection ? 'MPSectionCategory:subsection' : '',
516
- });
513
+ const section = nodes.section.createAndFill();
517
514
  const tr = state.tr.insert(pos, section);
518
515
  if (dispatch) {
519
516
  const selection = TextSelection.create(tr.doc, pos + 2);
@@ -522,11 +519,10 @@ export const insertSection = (subsection = false) => (state, dispatch, view) =>
522
519
  }
523
520
  return true;
524
521
  };
525
- export const insertBackMatterSection = (category) => (state, dispatch, view) => {
526
- var _a;
522
+ export const insertBackmatterSection = (category) => (state, dispatch, view) => {
527
523
  const backmatter = findBackmatter(state.doc);
528
524
  const sections = findChildrenByType(backmatter.node, schema.nodes.section);
529
- if (sections.some((s) => s.node.attrs.category === category)) {
525
+ if (sections.some((s) => s.node.attrs.category === category.id)) {
530
526
  return false;
531
527
  }
532
528
  const bibliography = findBibliographySection(state.doc);
@@ -537,10 +533,11 @@ export const insertBackMatterSection = (category) => (state, dispatch, view) =>
537
533
  else {
538
534
  pos = backmatter.pos + backmatter.node.content.size + 1;
539
535
  }
540
- const node = schema.nodes.section.createAndFill({
541
- category,
542
- }, [
543
- schema.nodes.section_title.create({}, schema.text(((_a = sectionTitles.get(category)) === null || _a === void 0 ? void 0 : _a.split('|')[0]) || '')),
536
+ const attrs = {
537
+ category: category.id,
538
+ };
539
+ const node = schema.nodes.section.create(attrs, [
540
+ schema.nodes.section_title.create({}, schema.text(category.titles[0])),
544
541
  ]);
545
542
  const tr = state.tr.insert(pos, node);
546
543
  if (dispatch) {
@@ -557,12 +554,12 @@ const findSelectedList = (selection) => (selection instanceof NodeSelection &&
557
554
  }) ||
558
555
  findParentNodeOfType([schema.nodes.list])(selection);
559
556
  export const insertAbstract = (state, dispatch, view) => {
560
- if (getMatchingChild(state.doc, (node) => node.attrs.category === 'MPSectionCategory:abstract', true)) {
557
+ if (getMatchingChild(state.doc, (node) => node.attrs.category === 'abstract', true)) {
561
558
  return false;
562
559
  }
563
560
  const abstracts = findChildrenByType(state.doc, schema.nodes.abstracts)[0];
564
561
  const pos = abstracts.pos + 1;
565
- const section = schema.nodes.section.createAndFill({ category: 'MPSectionCategory:abstract' }, [
562
+ const section = schema.nodes.section.createAndFill({ category: 'abstract' }, [
566
563
  schema.nodes.section_title.create({}, schema.text('Abstract')),
567
564
  schema.nodes.paragraph.create({ placeholder: 'Type abstract here...' }),
568
565
  ]);
package/dist/es/icons.js CHANGED
@@ -1,5 +1,7 @@
1
- import { AlertIcon, DeleteIcon } from '@manuscripts/style-guide';
1
+ import { AlertIcon, DeleteIcon, SectionCategoryIcon, } from '@manuscripts/style-guide';
2
2
  import { createElement } from 'react';
3
3
  import { renderToStaticMarkup } from 'react-dom/server';
4
- export const alertIcon = renderToStaticMarkup(createElement(AlertIcon));
5
- export const deleteIcon = renderToStaticMarkup(createElement(DeleteIcon));
4
+ const renderIcon = (c) => renderToStaticMarkup(createElement(c));
5
+ export const alertIcon = renderIcon(AlertIcon);
6
+ export const deleteIcon = renderIcon(DeleteIcon);
7
+ export const sectionCategoryIcon = renderIcon(SectionCategoryIcon);
@@ -77,9 +77,7 @@ export class ContextMenu {
77
77
  const level = sectionLevel($pos.depth);
78
78
  const label = `New ${level} to ${itemTitle}`;
79
79
  section.appendChild(this.createMenuItem(label, () => {
80
- insertNode(schema.nodes.section, insPos, {
81
- category: 'MPSectionCategory:subsection',
82
- });
80
+ insertNode(schema.nodes.section, insPos);
83
81
  popper.destroy();
84
82
  }));
85
83
  }
package/dist/es/menus.js CHANGED
@@ -13,16 +13,28 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { schema } from '@manuscripts/transform';
16
+ import { getGroupCateogries, schema, } from '@manuscripts/transform';
17
17
  import { toggleMark } from 'prosemirror-commands';
18
18
  import { redo, undo } from 'prosemirror-history';
19
- import { addInlineComment, blockActive, canInsert, insertAbstract, insertBackMatterSection, insertBlock, insertBoxElement, insertContributors, insertCrossReference, insertGraphicalAbstract, insertInlineCitation, insertInlineEquation, insertInlineFootnote, insertKeywords, insertLink, insertList, insertSection, markActive, } from './commands';
19
+ import { addInlineComment, blockActive, canInsert, insertAbstract, insertBackmatterSection, insertBlock, insertBoxElement, insertContributors, insertCrossReference, insertGraphicalAbstract, insertInlineCitation, insertInlineEquation, insertInlineFootnote, insertKeywords, insertLink, insertList, insertSection, markActive, } from './commands';
20
20
  import { openInsertTableDialog } from './components/toolbar/InsertTableDialog';
21
21
  import { ListMenuItem } from './components/toolbar/ListMenuItem';
22
22
  import { deleteClosestParentElement, findClosestParentElementNodeName, } from './lib/hierarchy';
23
+ import { getEditorProps } from './plugins/editor-props';
23
24
  export const getEditorMenus = (editor) => {
24
25
  const { isCommandValid, state } = editor;
25
26
  const doCommand = (command) => () => editor.doCommand(command);
27
+ const props = getEditorProps(state);
28
+ const insertBackmatterSectionMenu = (category) => {
29
+ const command = insertBackmatterSection(category);
30
+ return {
31
+ id: `insert-${category.id}`,
32
+ label: category.titles[0],
33
+ isEnabled: isCommandValid(command),
34
+ run: doCommand(command),
35
+ };
36
+ };
37
+ const categories = getGroupCateogries(props.sectionCategories, 'backmatter');
26
38
  const edit = {
27
39
  id: 'edit',
28
40
  label: 'Edit',
@@ -105,56 +117,7 @@ export const getEditorMenus = (editor) => {
105
117
  id: 'back-matter',
106
118
  label: 'Author Notes',
107
119
  isEnabled: true,
108
- submenu: [
109
- {
110
- id: 'insert-acknowledgements',
111
- label: 'Acknowledgements',
112
- isEnabled: isCommandValid(insertBackMatterSection('MPSectionCategory:acknowledgement')),
113
- run: doCommand(insertBackMatterSection('MPSectionCategory:acknowledgement')),
114
- },
115
- {
116
- id: 'insert-availability',
117
- label: 'Availability',
118
- isEnabled: isCommandValid(insertBackMatterSection('MPSectionCategory:availability')),
119
- run: doCommand(insertBackMatterSection('MPSectionCategory:availability')),
120
- },
121
- {
122
- id: 'insert-coi-statement',
123
- label: 'COI Statement',
124
- isEnabled: isCommandValid(insertBackMatterSection('MPSectionCategory:competing-interests')),
125
- run: doCommand(insertBackMatterSection('MPSectionCategory:competing-interests')),
126
- },
127
- {
128
- id: 'insert-con',
129
- label: 'Contributed-by Information',
130
- isEnabled: isCommandValid(insertBackMatterSection('MPSectionCategory:con')),
131
- run: doCommand(insertBackMatterSection('MPSectionCategory:con')),
132
- },
133
- {
134
- id: 'insert-ethics-statement',
135
- label: 'Ethics Statement',
136
- isEnabled: isCommandValid(insertBackMatterSection('MPSectionCategory:ethics-statement')),
137
- run: doCommand(insertBackMatterSection('MPSectionCategory:ethics-statement')),
138
- },
139
- {
140
- id: 'insert-financial-disclosure',
141
- label: 'Financial Disclosure',
142
- isEnabled: isCommandValid(insertBackMatterSection('MPSectionCategory:financial-disclosure')),
143
- run: doCommand(insertBackMatterSection('MPSectionCategory:financial-disclosure')),
144
- },
145
- {
146
- id: 'insert-supplementary-material',
147
- label: 'Supplementary Material',
148
- isEnabled: isCommandValid(insertBackMatterSection('MPSectionCategory:supplementary-material')),
149
- run: doCommand(insertBackMatterSection('MPSectionCategory:supplementary-material')),
150
- },
151
- {
152
- id: 'insert-supported-by',
153
- label: 'Supported By',
154
- isEnabled: isCommandValid(insertBackMatterSection('MPSectionCategory:supported-by')),
155
- run: doCommand(insertBackMatterSection('MPSectionCategory:supported-by')),
156
- },
157
- ],
120
+ submenu: categories.map(insertBackmatterSectionMenu),
158
121
  },
159
122
  {
160
123
  id: 'insert-section',