@manuscripts/body-editor 2.8.2 → 2.8.3

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.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.addHeaderRow = exports.addRows = exports.addInlineComment = exports.addNodeComment = exports.isCommentingAllowed = 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.insertAward = exports.insertAffiliation = 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.insertEmbed = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = exports.addToStart = void 0;
18
+ exports.addHeaderRow = exports.addRows = exports.addInlineComment = exports.addNodeComment = exports.isCommentingAllowed = 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.insertAward = exports.insertAffiliation = exports.insertContributors = exports.insertGraphicalAbstract = exports.insertBackmatterSection = exports.insertAbstractSection = exports.insertSection = 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.insertEmbed = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = exports.addToStart = void 0;
19
19
  exports.activateSearchReplace = exports.activateSearch = exports.autoComplete = exports.addColumns = void 0;
20
20
  const json_schema_1 = require("@manuscripts/json-schema");
21
21
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
@@ -517,27 +517,6 @@ const insertBoxElement = (state, dispatch) => {
517
517
  return true;
518
518
  };
519
519
  exports.insertBoxElement = insertBoxElement;
520
- const insertGraphicalAbstract = (state, dispatch, view) => {
521
- if ((0, utils_1.getChildOfType)(state.doc, transform_1.schema.nodes.graphical_abstract_section, true)) {
522
- return false;
523
- }
524
- const abstracts = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.abstracts)[0];
525
- const pos = abstracts.pos + abstracts.node.content.size + 1;
526
- const section = transform_1.schema.nodes.graphical_abstract_section.createAndFill({}, [
527
- transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Graphical Abstract')),
528
- createAndFillFigureElement(state),
529
- ]);
530
- const tr = state.tr.insert(pos, section);
531
- if (dispatch) {
532
- const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos + 1);
533
- if (view) {
534
- view.focus();
535
- }
536
- dispatch(tr.setSelection(selection).scrollIntoView());
537
- }
538
- return true;
539
- };
540
- exports.insertGraphicalAbstract = insertGraphicalAbstract;
541
520
  const insertSection = (subsection = false) => (state, dispatch, view) => {
542
521
  const nodes = transform_1.schema.nodes;
543
522
  const $pos = state.selection.$from;
@@ -573,6 +552,30 @@ const insertSection = (subsection = false) => (state, dispatch, view) => {
573
552
  return true;
574
553
  };
575
554
  exports.insertSection = insertSection;
555
+ const insertAbstractSection = (category) => (state, dispatch, view) => {
556
+ const abstracts = (0, doc_1.findAbstractsNode)(state.doc);
557
+ const sections = (0, prosemirror_utils_1.findChildrenByType)(abstracts.node, transform_1.schema.nodes.section);
558
+ if (sections.some((s) => s.node.attrs.category === category.id)) {
559
+ return false;
560
+ }
561
+ const ga = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.graphical_abstract_section)[0];
562
+ let pos = ga ? ga.pos : abstracts.pos + abstracts.node.content.size + 1;
563
+ if (category.id === 'abstract') {
564
+ pos = abstracts.pos + 1;
565
+ }
566
+ const node = transform_1.schema.nodes.section.create({ category: category.id }, [
567
+ transform_1.schema.nodes.section_title.create({}, transform_1.schema.text(category.titles[0])),
568
+ transform_1.schema.nodes.paragraph.create({ placeholder: 'Type abstract here...' }),
569
+ ]);
570
+ const tr = state.tr.insert(pos, node);
571
+ if (dispatch) {
572
+ const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos);
573
+ view === null || view === void 0 ? void 0 : view.focus();
574
+ dispatch(tr.setSelection(selection).scrollIntoView());
575
+ }
576
+ return true;
577
+ };
578
+ exports.insertAbstractSection = insertAbstractSection;
576
579
  const insertBackmatterSection = (category) => (state, dispatch, view) => {
577
580
  const backmatter = (0, doc_1.findBackmatter)(state.doc);
578
581
  const sections = (0, prosemirror_utils_1.findChildrenByType)(backmatter.node, transform_1.schema.nodes.section);
@@ -580,16 +583,10 @@ const insertBackmatterSection = (category) => (state, dispatch, view) => {
580
583
  return false;
581
584
  }
582
585
  const bibliography = (0, doc_1.findBibliographySection)(state.doc);
583
- let pos;
584
- if (bibliography) {
585
- pos = bibliography.pos;
586
- }
587
- else {
588
- pos = backmatter.pos + backmatter.node.content.size + 1;
589
- }
590
- const attrs = {
591
- category: category.id,
592
- };
586
+ const pos = bibliography
587
+ ? bibliography.pos
588
+ : backmatter.pos + backmatter.node.content.size + 1;
589
+ const attrs = { category: category.id };
593
590
  const node = transform_1.schema.nodes.section.create(attrs, [
594
591
  transform_1.schema.nodes.section_title.create({}, transform_1.schema.text(category.titles[0])),
595
592
  ]);
@@ -608,32 +605,30 @@ const findSelectedList = (selection) => (selection instanceof prosemirror_state_
608
605
  node: selection.node,
609
606
  }) ||
610
607
  (0, prosemirror_utils_1.findParentNodeOfType)([transform_1.schema.nodes.list])(selection);
611
- const insertAbstract = (state, dispatch, view) => {
612
- if ((0, utils_1.getMatchingChild)(state.doc, (node) => node.attrs.category === 'abstract', true)) {
608
+ const insertGraphicalAbstract = (category) => (state, dispatch, view) => {
609
+ const abstracts = (0, doc_1.findAbstractsNode)(state.doc);
610
+ const sections = (0, prosemirror_utils_1.findChildrenByType)(abstracts.node, transform_1.schema.nodes.graphical_abstract_section);
611
+ if (sections.some((s) => s.node.attrs.category === category.id)) {
613
612
  return false;
614
613
  }
615
- const abstracts = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.abstracts)[0];
616
- const pos = abstracts.pos + 1;
617
- const section = transform_1.schema.nodes.section.createAndFill({ category: 'abstract' }, [
618
- transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Abstract')),
619
- transform_1.schema.nodes.paragraph.create({ placeholder: 'Type abstract here...' }),
614
+ const ga = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.graphical_abstract_section)[0];
615
+ let pos = abstracts.pos + abstracts.node.content.size + 1;
616
+ pos = ga && category.id === 'abstract-key-image' ? ga.pos : pos;
617
+ const node = transform_1.schema.nodes.graphical_abstract_section.createAndFill({ category: category.id }, [
618
+ transform_1.schema.nodes.section_title.create({}, transform_1.schema.text(category.titles[0])),
619
+ createAndFillFigureElement(state),
620
620
  ]);
621
- const tr = state.tr.insert(pos, section);
621
+ const tr = state.tr.insert(pos, node);
622
622
  if (dispatch) {
623
- const sectionStart = tr.doc.resolve(pos);
624
- const sectionNode = sectionStart.nodeAfter;
625
- if (sectionNode && sectionNode.firstChild) {
626
- const paragraphPos = pos + sectionNode.firstChild.nodeSize + 2;
627
- const selection = prosemirror_state_1.TextSelection.create(tr.doc, paragraphPos);
628
- if (view) {
629
- view.focus();
630
- }
631
- dispatch(tr.setSelection(selection).scrollIntoView());
623
+ const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos + 1);
624
+ if (view) {
625
+ view.focus();
632
626
  }
627
+ dispatch(tr.setSelection(selection).scrollIntoView());
633
628
  }
634
629
  return true;
635
630
  };
636
- exports.insertAbstract = insertAbstract;
631
+ exports.insertGraphicalAbstract = insertGraphicalAbstract;
637
632
  const insertContributors = (state, dispatch, view) => {
638
633
  if ((0, utils_1.getChildOfType)(state.doc, transform_1.schema.nodes.contributors, true)) {
639
634
  return false;
package/dist/cjs/menus.js CHANGED
@@ -38,7 +38,17 @@ const getEditorMenus = (editor) => {
38
38
  run: doCommand(command),
39
39
  };
40
40
  };
41
- const categories = (0, transform_1.getGroupCategories)(props.sectionCategories, 'backmatter');
41
+ const insertAbstractsSectionMenu = (category) => {
42
+ const command = category.group === 'abstracts-graphic'
43
+ ? (0, commands_1.insertGraphicalAbstract)(category)
44
+ : (0, commands_1.insertAbstractSection)(category);
45
+ return {
46
+ id: `insert-${category.id}`,
47
+ label: category.titles[0],
48
+ isEnabled: isCommandValid(command),
49
+ run: doCommand(command),
50
+ };
51
+ };
42
52
  const edit = {
43
53
  id: 'edit',
44
54
  label: 'Edit',
@@ -95,6 +105,13 @@ const getEditorMenus = (editor) => {
95
105
  },
96
106
  ],
97
107
  };
108
+ const categories = (0, transform_1.getGroupCategories)(props.sectionCategories, 'backmatter');
109
+ const abstractsCategories = (0, transform_1.getGroupCategories)(props.sectionCategories, 'abstracts');
110
+ const graphicalAbstractsCategories = (0, transform_1.getGroupCategories)(props.sectionCategories, 'abstracts-graphic');
111
+ const allAbstractsCategories = [
112
+ ...abstractsCategories,
113
+ ...graphicalAbstractsCategories,
114
+ ];
98
115
  const insert = {
99
116
  id: 'insert',
100
117
  label: 'Insert',
@@ -106,16 +123,10 @@ const getEditorMenus = (editor) => {
106
123
  isEnabled: true,
107
124
  submenu: [
108
125
  {
109
- id: 'insert-abstract',
110
- label: 'Abstract',
111
- isEnabled: isCommandValid(commands_1.insertAbstract),
112
- run: doCommand(commands_1.insertAbstract),
113
- },
114
- {
115
- id: 'insert-graphical-abstract',
116
- label: 'Graphical Abstract',
117
- isEnabled: isCommandValid(commands_1.insertGraphicalAbstract),
118
- run: doCommand(commands_1.insertGraphicalAbstract),
126
+ id: 'insert-abstract-types',
127
+ label: 'Abstract Types',
128
+ isEnabled: true,
129
+ submenu: allAbstractsCategories.map(insertAbstractsSectionMenu),
119
130
  },
120
131
  {
121
132
  id: 'insert-contributors',
@@ -80,17 +80,16 @@ function buildPluginState(state, props) {
80
80
  const categories = props.sectionCategories;
81
81
  const usedCategoryIDs = getUsedSectionCategoryIDs(state);
82
82
  state.doc.descendants((node, pos) => {
83
- if (node.type === transform_1.schema.nodes.abstracts ||
84
- node.type === transform_1.schema.nodes.box_element) {
83
+ if (node.type === transform_1.schema.nodes.box_element) {
85
84
  return false;
86
85
  }
87
86
  if ((0, transform_1.isSectionNode)(node)) {
88
87
  const categoryID = node.attrs.category;
89
88
  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.getGroupCategories)(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)));
89
+ if (category && category.group) {
90
+ const groupCategories = (0, transform_1.getGroupCategories)(categories, category.group);
91
+ 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
93
  return false;
95
94
  }
96
95
  });
@@ -105,6 +104,3 @@ const getUsedSectionCategoryIDs = (state) => {
105
104
  });
106
105
  return used;
107
106
  };
108
- const isInBackmatter = ($pos) => {
109
- return !!(0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)($pos, transform_1.schema.nodes.backmatter);
110
- };
@@ -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.8.2';
4
+ exports.VERSION = '2.8.3';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -23,11 +23,11 @@ import { addColumnAfter, addColumnBefore, addRow, selectedRect, } from 'prosemir
23
23
  import { findWrapping, liftTarget, ReplaceAroundStep, ReplaceStep, } from 'prosemirror-transform';
24
24
  import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos, flatten, hasParentNodeOfType, } from 'prosemirror-utils';
25
25
  import { getCommentKey, getCommentRange } from './lib/comments';
26
- import { findBackmatter, findBibliographySection, findBody, insertAwardsNode, insertFootnotesSection, insertSupplementsNode, } from './lib/doc';
26
+ import { findAbstractsNode, findBackmatter, findBibliographySection, findBody, insertAwardsNode, insertFootnotesSection, insertSupplementsNode, } from './lib/doc';
27
27
  import { createFootnote, findFootnotesContainerNode, getFootnotesElementState, } from './lib/footnotes';
28
28
  import { findWordBoundaries, isNodeOfType, nearestAncestor, } from './lib/helpers';
29
29
  import { isDeleted } from './lib/track-changes-utils';
30
- import { findParentNodeWithId, getChildOfType, getMatchingChild, } from './lib/utils';
30
+ import { findParentNodeWithId, getChildOfType } from './lib/utils';
31
31
  import { setCommentSelection } from './plugins/comments';
32
32
  import { getEditorProps } from './plugins/editor-props';
33
33
  import { searchReplaceKey } from './plugins/search-replace';
@@ -487,26 +487,6 @@ export const insertBoxElement = (state, dispatch) => {
487
487
  }
488
488
  return true;
489
489
  };
490
- export const insertGraphicalAbstract = (state, dispatch, view) => {
491
- if (getChildOfType(state.doc, schema.nodes.graphical_abstract_section, true)) {
492
- return false;
493
- }
494
- const abstracts = findChildrenByType(state.doc, schema.nodes.abstracts)[0];
495
- const pos = abstracts.pos + abstracts.node.content.size + 1;
496
- const section = schema.nodes.graphical_abstract_section.createAndFill({}, [
497
- schema.nodes.section_title.create({}, schema.text('Graphical Abstract')),
498
- createAndFillFigureElement(state),
499
- ]);
500
- const tr = state.tr.insert(pos, section);
501
- if (dispatch) {
502
- const selection = TextSelection.create(tr.doc, pos + 1);
503
- if (view) {
504
- view.focus();
505
- }
506
- dispatch(tr.setSelection(selection).scrollIntoView());
507
- }
508
- return true;
509
- };
510
490
  export const insertSection = (subsection = false) => (state, dispatch, view) => {
511
491
  const nodes = schema.nodes;
512
492
  const $pos = state.selection.$from;
@@ -541,6 +521,29 @@ export const insertSection = (subsection = false) => (state, dispatch, view) =>
541
521
  }
542
522
  return true;
543
523
  };
524
+ export const insertAbstractSection = (category) => (state, dispatch, view) => {
525
+ const abstracts = findAbstractsNode(state.doc);
526
+ const sections = findChildrenByType(abstracts.node, schema.nodes.section);
527
+ if (sections.some((s) => s.node.attrs.category === category.id)) {
528
+ return false;
529
+ }
530
+ const ga = findChildrenByType(state.doc, schema.nodes.graphical_abstract_section)[0];
531
+ let pos = ga ? ga.pos : abstracts.pos + abstracts.node.content.size + 1;
532
+ if (category.id === 'abstract') {
533
+ pos = abstracts.pos + 1;
534
+ }
535
+ const node = schema.nodes.section.create({ category: category.id }, [
536
+ schema.nodes.section_title.create({}, schema.text(category.titles[0])),
537
+ schema.nodes.paragraph.create({ placeholder: 'Type abstract here...' }),
538
+ ]);
539
+ const tr = state.tr.insert(pos, node);
540
+ if (dispatch) {
541
+ const selection = TextSelection.create(tr.doc, pos);
542
+ view === null || view === void 0 ? void 0 : view.focus();
543
+ dispatch(tr.setSelection(selection).scrollIntoView());
544
+ }
545
+ return true;
546
+ };
544
547
  export const insertBackmatterSection = (category) => (state, dispatch, view) => {
545
548
  const backmatter = findBackmatter(state.doc);
546
549
  const sections = findChildrenByType(backmatter.node, schema.nodes.section);
@@ -548,16 +551,10 @@ export const insertBackmatterSection = (category) => (state, dispatch, view) =>
548
551
  return false;
549
552
  }
550
553
  const bibliography = findBibliographySection(state.doc);
551
- let pos;
552
- if (bibliography) {
553
- pos = bibliography.pos;
554
- }
555
- else {
556
- pos = backmatter.pos + backmatter.node.content.size + 1;
557
- }
558
- const attrs = {
559
- category: category.id,
560
- };
554
+ const pos = bibliography
555
+ ? bibliography.pos
556
+ : backmatter.pos + backmatter.node.content.size + 1;
557
+ const attrs = { category: category.id };
561
558
  const node = schema.nodes.section.create(attrs, [
562
559
  schema.nodes.section_title.create({}, schema.text(category.titles[0])),
563
560
  ]);
@@ -575,28 +572,26 @@ const findSelectedList = (selection) => (selection instanceof NodeSelection &&
575
572
  node: selection.node,
576
573
  }) ||
577
574
  findParentNodeOfType([schema.nodes.list])(selection);
578
- export const insertAbstract = (state, dispatch, view) => {
579
- if (getMatchingChild(state.doc, (node) => node.attrs.category === 'abstract', true)) {
575
+ export const insertGraphicalAbstract = (category) => (state, dispatch, view) => {
576
+ const abstracts = findAbstractsNode(state.doc);
577
+ const sections = findChildrenByType(abstracts.node, schema.nodes.graphical_abstract_section);
578
+ if (sections.some((s) => s.node.attrs.category === category.id)) {
580
579
  return false;
581
580
  }
582
- const abstracts = findChildrenByType(state.doc, schema.nodes.abstracts)[0];
583
- const pos = abstracts.pos + 1;
584
- const section = schema.nodes.section.createAndFill({ category: 'abstract' }, [
585
- schema.nodes.section_title.create({}, schema.text('Abstract')),
586
- schema.nodes.paragraph.create({ placeholder: 'Type abstract here...' }),
581
+ const ga = findChildrenByType(state.doc, schema.nodes.graphical_abstract_section)[0];
582
+ let pos = abstracts.pos + abstracts.node.content.size + 1;
583
+ pos = ga && category.id === 'abstract-key-image' ? ga.pos : pos;
584
+ const node = schema.nodes.graphical_abstract_section.createAndFill({ category: category.id }, [
585
+ schema.nodes.section_title.create({}, schema.text(category.titles[0])),
586
+ createAndFillFigureElement(state),
587
587
  ]);
588
- const tr = state.tr.insert(pos, section);
588
+ const tr = state.tr.insert(pos, node);
589
589
  if (dispatch) {
590
- const sectionStart = tr.doc.resolve(pos);
591
- const sectionNode = sectionStart.nodeAfter;
592
- if (sectionNode && sectionNode.firstChild) {
593
- const paragraphPos = pos + sectionNode.firstChild.nodeSize + 2;
594
- const selection = TextSelection.create(tr.doc, paragraphPos);
595
- if (view) {
596
- view.focus();
597
- }
598
- dispatch(tr.setSelection(selection).scrollIntoView());
590
+ const selection = TextSelection.create(tr.doc, pos + 1);
591
+ if (view) {
592
+ view.focus();
599
593
  }
594
+ dispatch(tr.setSelection(selection).scrollIntoView());
600
595
  }
601
596
  return true;
602
597
  };
package/dist/es/menus.js CHANGED
@@ -16,7 +16,7 @@
16
16
  import { getGroupCategories, schema, } from '@manuscripts/transform';
17
17
  import { toggleMark } from 'prosemirror-commands';
18
18
  import { redo, undo } from 'prosemirror-history';
19
- import { activateSearchReplace, addInlineComment, blockActive, canInsert, insertAbstract, insertAffiliation, insertAward, insertBackmatterSection, insertBlock, insertBoxElement, insertContributors, insertCrossReference, insertGraphicalAbstract, insertInlineCitation, insertInlineEquation, insertInlineFootnote, insertKeywords, insertLink, insertList, insertSection, markActive, } from './commands';
19
+ import { activateSearchReplace, addInlineComment, blockActive, canInsert, insertAbstractSection, insertAffiliation, insertAward, insertBackmatterSection, insertBlock, insertBoxElement, insertContributors, insertCrossReference, insertGraphicalAbstract, insertInlineCitation, insertInlineEquation, insertInlineFootnote, insertKeywords, insertLink, insertList, insertSection, markActive, } from './commands';
20
20
  import { openEmbedDialog } from './components/toolbar/InsertEmbedDialog';
21
21
  import { openInsertTableDialog } from './components/toolbar/InsertTableDialog';
22
22
  import { ListMenuItem } from './components/toolbar/ListMenuItem';
@@ -35,7 +35,17 @@ export const getEditorMenus = (editor) => {
35
35
  run: doCommand(command),
36
36
  };
37
37
  };
38
- const categories = getGroupCategories(props.sectionCategories, 'backmatter');
38
+ const insertAbstractsSectionMenu = (category) => {
39
+ const command = category.group === 'abstracts-graphic'
40
+ ? insertGraphicalAbstract(category)
41
+ : insertAbstractSection(category);
42
+ return {
43
+ id: `insert-${category.id}`,
44
+ label: category.titles[0],
45
+ isEnabled: isCommandValid(command),
46
+ run: doCommand(command),
47
+ };
48
+ };
39
49
  const edit = {
40
50
  id: 'edit',
41
51
  label: 'Edit',
@@ -92,6 +102,13 @@ export const getEditorMenus = (editor) => {
92
102
  },
93
103
  ],
94
104
  };
105
+ const categories = getGroupCategories(props.sectionCategories, 'backmatter');
106
+ const abstractsCategories = getGroupCategories(props.sectionCategories, 'abstracts');
107
+ const graphicalAbstractsCategories = getGroupCategories(props.sectionCategories, 'abstracts-graphic');
108
+ const allAbstractsCategories = [
109
+ ...abstractsCategories,
110
+ ...graphicalAbstractsCategories,
111
+ ];
95
112
  const insert = {
96
113
  id: 'insert',
97
114
  label: 'Insert',
@@ -103,16 +120,10 @@ export const getEditorMenus = (editor) => {
103
120
  isEnabled: true,
104
121
  submenu: [
105
122
  {
106
- id: 'insert-abstract',
107
- label: 'Abstract',
108
- isEnabled: isCommandValid(insertAbstract),
109
- run: doCommand(insertAbstract),
110
- },
111
- {
112
- id: 'insert-graphical-abstract',
113
- label: 'Graphical Abstract',
114
- isEnabled: isCommandValid(insertGraphicalAbstract),
115
- run: doCommand(insertGraphicalAbstract),
123
+ id: 'insert-abstract-types',
124
+ label: 'Abstract Types',
125
+ isEnabled: true,
126
+ submenu: allAbstractsCategories.map(insertAbstractsSectionMenu),
116
127
  },
117
128
  {
118
129
  id: 'insert-contributors',
@@ -1,5 +1,5 @@
1
1
  import { getGroupCategories, isSectionNode, schema, } from '@manuscripts/transform';
2
- import { findChildrenByType, findParentNodeOfTypeClosestToPos, } from 'prosemirror-utils';
2
+ import { findChildrenByType } from 'prosemirror-utils';
3
3
  import { Decoration, DecorationSet } from 'prosemirror-view';
4
4
  import { sectionCategoryIcon } from '../../icons';
5
5
  import { PopperManager } from '../../lib/popper';
@@ -77,17 +77,16 @@ export function buildPluginState(state, props) {
77
77
  const categories = props.sectionCategories;
78
78
  const usedCategoryIDs = getUsedSectionCategoryIDs(state);
79
79
  state.doc.descendants((node, pos) => {
80
- if (node.type === schema.nodes.abstracts ||
81
- node.type === schema.nodes.box_element) {
80
+ if (node.type === schema.nodes.box_element) {
82
81
  return false;
83
82
  }
84
83
  if (isSectionNode(node)) {
85
84
  const categoryID = node.attrs.category;
86
85
  const category = categories.get(categoryID);
87
- const $pos = state.doc.resolve(pos);
88
- const group = isInBackmatter($pos) ? 'backmatter' : 'body';
89
- const groupCategories = getGroupCategories(categories, group);
90
- decorations.push(Decoration.widget(pos + 1, (view) => createButton(view, pos, category, groupCategories, usedCategoryIDs, can === null || can === void 0 ? void 0 : can.editArticle)));
86
+ if (category && category.group) {
87
+ const groupCategories = getGroupCategories(categories, category.group);
88
+ decorations.push(Decoration.widget(pos + 1, (view) => createButton(view, pos, category, groupCategories, usedCategoryIDs, can === null || can === void 0 ? void 0 : can.editArticle)));
89
+ }
91
90
  return false;
92
91
  }
93
92
  });
@@ -101,6 +100,3 @@ const getUsedSectionCategoryIDs = (state) => {
101
100
  });
102
101
  return used;
103
102
  };
104
- const isInBackmatter = ($pos) => {
105
- return !!findParentNodeOfTypeClosestToPos($pos, schema.nodes.backmatter);
106
- };
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.8.2';
1
+ export const VERSION = '2.8.3';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -49,10 +49,10 @@ export declare const insertTableElementFooter: (tr: Transaction, table: [Manuscr
49
49
  export declare const insertFootnotesElement: (tr: Transaction, container: [ManuscriptNode, number]) => [FootnotesElementNode, number];
50
50
  export declare const insertInlineFootnote: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
51
51
  export declare const insertBoxElement: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
52
- export declare const insertGraphicalAbstract: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
53
52
  export declare const insertSection: (subsection?: boolean) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
53
+ export declare const insertAbstractSection: (category: SectionCategory) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
54
54
  export declare const insertBackmatterSection: (category: SectionCategory) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
55
- export declare const insertAbstract: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
55
+ export declare const insertGraphicalAbstract: (category: SectionCategory) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
56
56
  export declare const insertContributors: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
57
57
  export declare const insertAffiliation: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
58
58
  export declare const insertAward: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.8.2";
1
+ export declare const VERSION = "2.8.3";
2
2
  export declare const MATHJAX_VERSION = "3.2.2";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/body-editor",
3
3
  "description": "Prosemirror components for editing and viewing manuscripts",
4
- "version": "2.8.2",
4
+ "version": "2.8.3",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -32,7 +32,7 @@
32
32
  "@iarna/word-count": "^1.1.2",
33
33
  "@manuscripts/json-schema": "2.2.11",
34
34
  "@manuscripts/library": "1.3.11",
35
- "@manuscripts/style-guide": "2.1.1",
35
+ "@manuscripts/style-guide": "2.1.2",
36
36
  "@manuscripts/track-changes-plugin": "1.10.0",
37
37
  "@manuscripts/transform": "3.0.45",
38
38
  "@popperjs/core": "^2.11.8",
@@ -620,14 +620,6 @@ span.comment-marker {
620
620
  text-decoration: underline;
621
621
  }
622
622
 
623
- .ProseMirror .selected-suggestion .inserted,
624
- .ProseMirror .block-award.selected-suggestion span,
625
- .ProseMirror .selected-suggestion [data-track-op='insert'] .block,
626
- .ProseMirror .selected-suggestion .deleted {
627
- background-color: var(--selected-pending-background-color) !important;
628
- color: var(--common-color) !important;
629
- }
630
-
631
623
  .tracking-visible .ProseMirror .set_attrs,
632
624
  .tracking-visible .ProseMirror .block-award[data-track-op='set_attrs'] span {
633
625
  background: var(--updated-pending-bg-color);
@@ -722,9 +714,9 @@ figure .selected-suggestion {
722
714
  }
723
715
 
724
716
  .selected-suggestion[data-track-status='pending'] .block,
717
+ .selected-suggestion [data-track-status='pending'] .block,
725
718
  .block:has(figure.selected-suggestion),
726
- figure.block:has(.equation.selected-suggestion)
727
- {
719
+ figure.block:has(.equation.selected-suggestion) {
728
720
  box-shadow: inset 6px 0 0 black, inset 9px 0 0 lightgray;
729
721
  --fade-color: none;
730
722
  }
@@ -742,7 +734,7 @@ figure.block:has(.equation.selected-suggestion)
742
734
  }
743
735
 
744
736
  .tracking-visible .selected-suggestion[data-track-status='pending'][data-track-op='insert'] .block,
745
- .tracking-visible .selected-suggestion[data-track-status='pending'][data-track-op='insert'] .block,
737
+ .tracking-visible .selected-suggestion [data-track-status='pending'][data-track-op='insert'] .block,
746
738
  .tracking-visible .selected-suggestion[data-track-op='wrap_with_node'][data-track-status='pending'] .block {
747
739
  box-shadow: inset 6px 0 0 var(--inserted-pending-color), inset 9px 0 0 var(--inserted-pending-bg-color) !important;
748
740
  animation: fadeOutBackground 3s forwards;