@manuscripts/body-editor 2.0.16 → 2.0.17

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.
@@ -424,56 +424,53 @@ const insertGraphicalAbstract = (state, dispatch, view) => {
424
424
  };
425
425
  exports.insertGraphicalAbstract = insertGraphicalAbstract;
426
426
  const insertSection = (subsection = false) => (state, dispatch, view) => {
427
- let pos = findPosAfterParentSection(state.selection.$from);
428
- const body = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.body)[0];
429
- if ((0, transform_1.isInBibliographySection)(state.selection.$from)) {
427
+ const selection = state.selection;
428
+ if ((0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.bibliography_section)(selection)) {
430
429
  return false;
431
430
  }
432
- else if (pos === null && subsection) {
433
- return false;
431
+ let pos;
432
+ if ((0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.body)(selection) || subsection) {
433
+ pos = findPosAfterParentSection(state.selection.$from);
434
434
  }
435
- if (pos === null) {
435
+ else {
436
+ const body = (0, doc_1.findBody)(state.doc);
436
437
  pos = body.pos + body.node.content.size + 1;
437
438
  }
438
- const resolvePos = state.doc.resolve(pos);
439
- const isAbstract = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)(resolvePos, transform_1.schema.nodes.abstracts);
440
- if (isAbstract && !subsection) {
439
+ if (!pos) {
441
440
  return false;
442
441
  }
443
- const adjustment = subsection ? -1 : 0;
444
- const tr = state.tr.insert(pos + adjustment, state.schema.nodes.section.createAndFill());
442
+ const section = transform_1.schema.nodes.section.createAndFill();
443
+ const diff = subsection ? -1 : 0;
444
+ const tr = state.tr.insert(pos + diff, section);
445
445
  if (dispatch) {
446
- const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos + adjustment + 2);
447
- if (view) {
448
- view.focus();
449
- }
446
+ const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos + diff + 2);
447
+ view === null || view === void 0 ? void 0 : view.focus();
450
448
  dispatch(tr.setSelection(selection).scrollIntoView());
451
449
  }
452
450
  return true;
453
451
  };
454
452
  exports.insertSection = insertSection;
455
453
  const insertBackMatterSection = (category) => (state, dispatch, view) => {
456
- const bibliographySection = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.bibliography_section)[0];
457
- const backmatter = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.backmatter)[0];
458
- const backmatterSections = (0, prosemirror_utils_1.findChildrenByType)(backmatter.node, transform_1.schema.nodes.section, true);
459
- if (backmatterSections.some((section) => section.node.attrs.category === category)) {
454
+ const backmatter = (0, doc_1.findBackmatter)(state.doc);
455
+ const sections = (0, prosemirror_utils_1.findChildrenByType)(backmatter.node, transform_1.schema.nodes.section);
456
+ if (sections.some((s) => s.node.attrs.category === category)) {
460
457
  return false;
461
458
  }
459
+ const bibliography = (0, doc_1.findBibliographySection)(state.doc);
462
460
  let pos;
463
- if (bibliographySection) {
464
- pos = bibliographySection.pos;
461
+ if (bibliography) {
462
+ pos = bibliography.pos;
465
463
  }
466
464
  else {
467
465
  pos = backmatter.pos + backmatter.node.content.size + 1;
468
466
  }
469
- const tr = state.tr.insert(pos, state.schema.nodes.section.createAndFill({
470
- category: category,
471
- }));
467
+ const node = transform_1.schema.nodes.section.createAndFill({
468
+ category,
469
+ });
470
+ const tr = state.tr.insert(pos, node);
472
471
  if (dispatch) {
473
472
  const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos);
474
- if (view) {
475
- view.focus();
476
- }
473
+ view === null || view === void 0 ? void 0 : view.focus();
477
474
  dispatch(tr.setSelection(selection).scrollIntoView());
478
475
  }
479
476
  return true;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findGraphicalAbstractFigureElement = exports.findAbstractsNode = exports.insertSupplementsNode = void 0;
3
+ exports.findGraphicalAbstractFigureElement = exports.findBibliographySection = exports.findBackmatter = exports.findBody = exports.findAbstractsNode = exports.insertSupplementsNode = void 0;
4
4
  const transform_1 = require("@manuscripts/transform");
5
5
  const prosemirror_utils_1 = require("prosemirror-utils");
6
6
  const insertSupplementsNode = (tr) => {
@@ -22,6 +22,18 @@ const findAbstractsNode = (doc) => {
22
22
  return (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.abstracts)[0];
23
23
  };
24
24
  exports.findAbstractsNode = findAbstractsNode;
25
+ const findBody = (doc) => {
26
+ return (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.body)[0];
27
+ };
28
+ exports.findBody = findBody;
29
+ const findBackmatter = (doc) => {
30
+ return (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.backmatter)[0];
31
+ };
32
+ exports.findBackmatter = findBackmatter;
33
+ const findBibliographySection = (doc) => {
34
+ return (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.bibliography_section)[0];
35
+ };
36
+ exports.findBibliographySection = findBibliographySection;
25
37
  const findGraphicalAbstractFigureElement = (doc) => {
26
38
  const ga = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.graphical_abstract_section)[0];
27
39
  if (!ga) {
@@ -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.0.16';
4
+ exports.VERSION = '2.0.17';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -15,15 +15,15 @@
15
15
  */
16
16
  import { buildContribution, ObjectTypes } from '@manuscripts/json-schema';
17
17
  import { skipTracking } from '@manuscripts/track-changes-plugin';
18
- import { generateID, generateNodeID, isElementNodeType, isFootnoteNode, isInBibliographySection, isListNode, isParagraphNode, isSectionNodeType, schema, } from '@manuscripts/transform';
18
+ import { generateID, generateNodeID, isElementNodeType, isFootnoteNode, isListNode, isParagraphNode, isSectionNodeType, schema, } from '@manuscripts/transform';
19
19
  import { Fragment, NodeRange, } from 'prosemirror-model';
20
20
  import { wrapInList } from 'prosemirror-schema-list';
21
21
  import { NodeSelection, TextSelection, } from 'prosemirror-state';
22
22
  import { addColSpan, addColumnAfter, addColumnBefore, addRow, CellSelection, selectedRect, } from 'prosemirror-tables';
23
23
  import { findWrapping, liftTarget, ReplaceAroundStep, } from 'prosemirror-transform';
24
- import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos, } from 'prosemirror-utils';
24
+ import { findChildrenByType, findParentNodeOfType, hasParentNodeOfType, } from 'prosemirror-utils';
25
25
  import { getCommentKey, getCommentRange } from './lib/comments';
26
- import { insertSupplementsNode } from './lib/doc';
26
+ import { findBackmatter, findBibliographySection, findBody, insertSupplementsNode, } from './lib/doc';
27
27
  import { findWordBoundaries, isNodeOfType, nearestAncestor, } from './lib/helpers';
28
28
  import { isDeleted, isRejectedInsert } from './lib/track-changes-utils';
29
29
  import { findParentNodeWithId, getChildOfType, getMatchingChild, } from './lib/utils';
@@ -400,55 +400,52 @@ export const insertGraphicalAbstract = (state, dispatch, view) => {
400
400
  return true;
401
401
  };
402
402
  export const insertSection = (subsection = false) => (state, dispatch, view) => {
403
- let pos = findPosAfterParentSection(state.selection.$from);
404
- const body = findChildrenByType(state.doc, schema.nodes.body)[0];
405
- if (isInBibliographySection(state.selection.$from)) {
403
+ const selection = state.selection;
404
+ if (hasParentNodeOfType(schema.nodes.bibliography_section)(selection)) {
406
405
  return false;
407
406
  }
408
- else if (pos === null && subsection) {
409
- return false;
407
+ let pos;
408
+ if (hasParentNodeOfType(schema.nodes.body)(selection) || subsection) {
409
+ pos = findPosAfterParentSection(state.selection.$from);
410
410
  }
411
- if (pos === null) {
411
+ else {
412
+ const body = findBody(state.doc);
412
413
  pos = body.pos + body.node.content.size + 1;
413
414
  }
414
- const resolvePos = state.doc.resolve(pos);
415
- const isAbstract = findParentNodeOfTypeClosestToPos(resolvePos, schema.nodes.abstracts);
416
- if (isAbstract && !subsection) {
415
+ if (!pos) {
417
416
  return false;
418
417
  }
419
- const adjustment = subsection ? -1 : 0;
420
- const tr = state.tr.insert(pos + adjustment, state.schema.nodes.section.createAndFill());
418
+ const section = schema.nodes.section.createAndFill();
419
+ const diff = subsection ? -1 : 0;
420
+ const tr = state.tr.insert(pos + diff, section);
421
421
  if (dispatch) {
422
- const selection = TextSelection.create(tr.doc, pos + adjustment + 2);
423
- if (view) {
424
- view.focus();
425
- }
422
+ const selection = TextSelection.create(tr.doc, pos + diff + 2);
423
+ view === null || view === void 0 ? void 0 : view.focus();
426
424
  dispatch(tr.setSelection(selection).scrollIntoView());
427
425
  }
428
426
  return true;
429
427
  };
430
428
  export const insertBackMatterSection = (category) => (state, dispatch, view) => {
431
- const bibliographySection = findChildrenByType(state.doc, schema.nodes.bibliography_section)[0];
432
- const backmatter = findChildrenByType(state.doc, schema.nodes.backmatter)[0];
433
- const backmatterSections = findChildrenByType(backmatter.node, schema.nodes.section, true);
434
- if (backmatterSections.some((section) => section.node.attrs.category === category)) {
429
+ const backmatter = findBackmatter(state.doc);
430
+ const sections = findChildrenByType(backmatter.node, schema.nodes.section);
431
+ if (sections.some((s) => s.node.attrs.category === category)) {
435
432
  return false;
436
433
  }
434
+ const bibliography = findBibliographySection(state.doc);
437
435
  let pos;
438
- if (bibliographySection) {
439
- pos = bibliographySection.pos;
436
+ if (bibliography) {
437
+ pos = bibliography.pos;
440
438
  }
441
439
  else {
442
440
  pos = backmatter.pos + backmatter.node.content.size + 1;
443
441
  }
444
- const tr = state.tr.insert(pos, state.schema.nodes.section.createAndFill({
445
- category: category,
446
- }));
442
+ const node = schema.nodes.section.createAndFill({
443
+ category,
444
+ });
445
+ const tr = state.tr.insert(pos, node);
447
446
  if (dispatch) {
448
447
  const selection = TextSelection.create(tr.doc, pos);
449
- if (view) {
450
- view.focus();
451
- }
448
+ view === null || view === void 0 ? void 0 : view.focus();
452
449
  dispatch(tr.setSelection(selection).scrollIntoView());
453
450
  }
454
451
  return true;
@@ -17,6 +17,15 @@ export const insertSupplementsNode = (tr) => {
17
17
  export const findAbstractsNode = (doc) => {
18
18
  return findChildrenByType(doc, schema.nodes.abstracts)[0];
19
19
  };
20
+ export const findBody = (doc) => {
21
+ return findChildrenByType(doc, schema.nodes.body)[0];
22
+ };
23
+ export const findBackmatter = (doc) => {
24
+ return findChildrenByType(doc, schema.nodes.backmatter)[0];
25
+ };
26
+ export const findBibliographySection = (doc) => {
27
+ return findChildrenByType(doc, schema.nodes.bibliography_section)[0];
28
+ };
20
29
  export const findGraphicalAbstractFigureElement = (doc) => {
21
30
  const ga = findChildrenByType(doc, schema.nodes.graphical_abstract_section)[0];
22
31
  if (!ga) {
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.0.16';
1
+ export const VERSION = '2.0.17';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -1,6 +1,9 @@
1
1
  import { ManuscriptNode, ManuscriptTransaction } from '@manuscripts/transform';
2
2
  export declare const insertSupplementsNode: (tr: ManuscriptTransaction) => import("prosemirror-utils").NodeWithPos;
3
3
  export declare const findAbstractsNode: (doc: ManuscriptNode) => import("prosemirror-utils").NodeWithPos;
4
+ export declare const findBody: (doc: ManuscriptNode) => import("prosemirror-utils").NodeWithPos;
5
+ export declare const findBackmatter: (doc: ManuscriptNode) => import("prosemirror-utils").NodeWithPos;
6
+ export declare const findBibliographySection: (doc: ManuscriptNode) => import("prosemirror-utils").NodeWithPos;
4
7
  export declare const findGraphicalAbstractFigureElement: (doc: ManuscriptNode) => {
5
8
  node: import("prosemirror-model").Node;
6
9
  pos: number;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.0.16";
1
+ export declare const VERSION = "2.0.17";
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.0.16",
4
+ "version": "2.0.17",
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.10",
34
34
  "@manuscripts/library": "1.3.10",
35
- "@manuscripts/style-guide": "2.0.3",
35
+ "@manuscripts/style-guide": "2.0.4",
36
36
  "@manuscripts/track-changes-plugin": "1.7.17",
37
37
  "@manuscripts/transform": "2.3.23",
38
38
  "@popperjs/core": "^2.11.8",
@@ -116,4 +116,4 @@
116
116
  "engines": {
117
117
  "node": ">=20.16.0"
118
118
  }
119
- }
119
+ }