@manuscripts/body-editor 1.5.16 → 1.6.1

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 (80) hide show
  1. package/dist/cjs/commands.js +53 -132
  2. package/dist/cjs/components/outline/DraggableTree.js +33 -25
  3. package/dist/cjs/components/toolbar/OrderListSelector.js +3 -11
  4. package/dist/cjs/configs/editor-plugins.js +2 -2
  5. package/dist/cjs/configs/editor-views.js +4 -6
  6. package/dist/cjs/lib/context-menu.js +6 -5
  7. package/dist/cjs/node-type-icons.js +0 -1
  8. package/dist/cjs/plugins/bibliography/bibliography-utils.js +60 -47
  9. package/dist/cjs/plugins/bibliography/index.js +48 -63
  10. package/dist/cjs/plugins/comment_annotation.js +2 -2
  11. package/dist/cjs/plugins/footnotes/index.js +19 -10
  12. package/dist/cjs/plugins/persist.js +21 -31
  13. package/dist/cjs/plugins/sections.js +1 -2
  14. package/dist/cjs/plugins/toc.js +28 -23
  15. package/dist/cjs/useEditor.js +1 -3
  16. package/dist/cjs/views/bibliography_element.js +20 -38
  17. package/dist/cjs/views/citation.js +29 -26
  18. package/dist/cjs/views/citation_editable.js +25 -44
  19. package/dist/cjs/views/{contributors_section.js → contributors.js} +4 -4
  20. package/dist/cjs/views/cross_reference.js +7 -36
  21. package/dist/cjs/views/cross_reference_editable.js +6 -14
  22. package/dist/cjs/views/editable_block.js +2 -2
  23. package/dist/cjs/views/{meta_section.js → empty.js} +3 -3
  24. package/dist/cjs/views/section_title.js +1 -16
  25. package/dist/es/commands.js +55 -110
  26. package/dist/es/components/outline/DraggableTree.js +33 -25
  27. package/dist/es/components/toolbar/OrderListSelector.js +4 -12
  28. package/dist/es/configs/editor-plugins.js +2 -2
  29. package/dist/es/configs/editor-views.js +4 -6
  30. package/dist/es/lib/context-menu.js +7 -6
  31. package/dist/es/node-type-icons.js +0 -1
  32. package/dist/es/plugins/bibliography/bibliography-utils.js +56 -45
  33. package/dist/es/plugins/bibliography/index.js +49 -65
  34. package/dist/es/plugins/comment_annotation.js +2 -2
  35. package/dist/es/plugins/footnotes/index.js +20 -11
  36. package/dist/es/plugins/persist.js +22 -32
  37. package/dist/es/plugins/sections.js +2 -3
  38. package/dist/es/plugins/toc.js +29 -24
  39. package/dist/es/useEditor.js +2 -4
  40. package/dist/es/views/bibliography_element.js +21 -39
  41. package/dist/es/views/citation.js +31 -28
  42. package/dist/es/views/citation_editable.js +28 -47
  43. package/dist/es/views/{contributors_section.js → contributors.js} +2 -2
  44. package/dist/es/views/cross_reference.js +7 -33
  45. package/dist/es/views/cross_reference_editable.js +6 -14
  46. package/dist/es/views/editable_block.js +3 -3
  47. package/dist/es/views/{meta_section.js → empty.js} +3 -3
  48. package/dist/es/views/section_title.js +0 -14
  49. package/dist/types/commands.d.ts +1 -2
  50. package/dist/types/components/outline/DraggableTree.d.ts +1 -2
  51. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -10
  52. package/dist/types/configs/editor-plugins.d.ts +1 -5
  53. package/dist/types/configs/editor-views.d.ts +5 -6
  54. package/dist/types/lib/context-menu.d.ts +0 -1
  55. package/dist/types/plugins/bibliography/bibliography-utils.d.ts +10 -7
  56. package/dist/types/plugins/bibliography/index.d.ts +21 -3
  57. package/dist/types/views/bibliography_element.d.ts +1 -0
  58. package/dist/types/views/citation.d.ts +3 -4
  59. package/dist/types/views/citation_editable.d.ts +2 -8
  60. package/dist/types/views/{contributors_section.d.ts → contributors.d.ts} +3 -3
  61. package/dist/types/views/cross_reference.d.ts +0 -5
  62. package/dist/types/views/{meta_section.d.ts → empty.d.ts} +2 -2
  63. package/dist/types/views/section_title.d.ts +0 -2
  64. package/package.json +4 -22
  65. package/styles/AdvancedEditor.css +30 -34
  66. package/dist/cjs/plugins/auxiliary_object_order.js +0 -49
  67. package/dist/cjs/plugins/bibliography/types.js +0 -17
  68. package/dist/cjs/plugins/footnotes/footnotes-utils.js +0 -52
  69. package/dist/cjs/views/bibliography_item.js +0 -138
  70. package/dist/cjs/views/bibliography_item_editable.js +0 -20
  71. package/dist/es/plugins/auxiliary_object_order.js +0 -46
  72. package/dist/es/plugins/bibliography/types.js +0 -16
  73. package/dist/es/plugins/footnotes/footnotes-utils.js +0 -46
  74. package/dist/es/views/bibliography_item.js +0 -131
  75. package/dist/es/views/bibliography_item_editable.js +0 -18
  76. package/dist/types/plugins/auxiliary_object_order.d.ts +0 -12
  77. package/dist/types/plugins/bibliography/types.d.ts +0 -40
  78. package/dist/types/plugins/footnotes/footnotes-utils.d.ts +0 -25
  79. package/dist/types/views/bibliography_item.d.ts +0 -34
  80. package/dist/types/views/bibliography_item_editable.d.ts +0 -18
@@ -26,17 +26,19 @@ var __rest = (this && this.__rest) || function (s, e) {
26
26
  };
27
27
  import { ObjectTypes, } from '@manuscripts/json-schema';
28
28
  import { CHANGE_OPERATION, CHANGE_STATUS, } from '@manuscripts/track-changes-plugin';
29
- import { schema } from '@manuscripts/transform';
30
- import { pickBy } from 'lodash-es';
29
+ import { schema, } from '@manuscripts/transform';
30
+ import { pickBy } from 'lodash';
31
31
  import { Decoration } from 'prosemirror-view';
32
32
  export const isBibliographyElement = (node) => node.type === node.type.schema.nodes.bibliography_element;
33
- export const buildDecorations = (doc, citationNodes, popper, referencesModelMap, triggerUpdate) => {
33
+ let count = 0;
34
+ export const buildDecorations = (state, doc) => {
34
35
  const decorations = [];
35
36
  let hasMissingItems = false;
36
- for (const [node, pos, citation] of citationNodes) {
37
- if (citation.embeddedCitationItems.length) {
38
- for (const citationItem of citation.embeddedCitationItems) {
39
- if (!referencesModelMap.get(citationItem.bibliographyItem)) {
37
+ for (const [node, pos] of state.citationNodes) {
38
+ const rids = node.attrs.rids;
39
+ if (rids.length) {
40
+ for (const rid of rids) {
41
+ if (!state.bibliographyItems.has(rid)) {
40
42
  decorations.push(Decoration.node(pos, pos + node.nodeSize, {
41
43
  class: 'citation-missing',
42
44
  }));
@@ -68,55 +70,55 @@ export const buildDecorations = (doc, citationNodes, popper, referencesModelMap,
68
70
  }
69
71
  });
70
72
  }
71
- if (triggerUpdate) {
72
- doc.descendants((node, pos) => {
73
- if (isBibliographyElement(node)) {
74
- decorations.push(Decoration.node(pos, pos + node.nodeSize, {}, {
75
- triggerUpdate: true,
76
- }));
77
- }
78
- });
79
- }
73
+ doc.descendants((node, pos) => {
74
+ if (isBibliographyElement(node)) {
75
+ decorations.push(Decoration.node(pos, pos + node.nodeSize, {}, {
76
+ refresh: count++,
77
+ }));
78
+ }
79
+ });
80
80
  return decorations;
81
81
  };
82
- const cleanData = (model) => pickBy(model, (value) => value !== undefined);
83
- export const getNodeModel = (node, excludeDeletedNode) => {
84
- const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
85
- const mapNodeToModel = (attrs, nodeType) => {
86
- if (nodeType === schema.nodes.bibliography_item) {
87
- const { id, containerTitle, doi } = attrs, rest = __rest(attrs, ["id", "containerTitle", "doi"]);
88
- return cleanData(Object.assign(Object.assign({ _id: id, 'container-title': containerTitle, DOI: doi }, rest), { objectType: ObjectTypes.BibliographyItem }));
89
- }
90
- const { rid, embeddedCitationItems } = attrs;
91
- return {
92
- _id: rid,
93
- embeddedCitationItems: (embeddedCitationItems === null || embeddedCitationItems === void 0 ? void 0 : embeddedCitationItems.map((item) => ({
94
- _id: item.id,
95
- bibliographyItem: item.bibliographyItem,
96
- objectType: ObjectTypes.CitationItem,
97
- }))) || [],
98
- objectType: ObjectTypes.Citation,
99
- };
82
+ export const getCitation = (node) => {
83
+ const attrs = getEffectiveAttrs(node);
84
+ if (!attrs) {
85
+ return undefined;
86
+ }
87
+ const rids = attrs.rids;
88
+ const items = rids.map((i) => ({
89
+ _id: '_',
90
+ objectType: ObjectTypes.CitationItem,
91
+ bibliographyItem: i,
92
+ }));
93
+ return {
94
+ _id: attrs.id,
95
+ objectType: ObjectTypes.Citation,
96
+ embeddedCitationItems: items,
100
97
  };
101
- const _a = node.attrs, { dataTracked } = _a, attrs = __rest(_a, ["dataTracked"]);
102
- const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(getLatest);
103
- if (nodeChange &&
104
- excludeDeletedNode &&
105
- nodeChange.operation === CHANGE_OPERATION.delete &&
106
- nodeChange.status !== CHANGE_STATUS.rejected) {
98
+ };
99
+ export const getBibliographyItem = (node) => {
100
+ const attrs = getEffectiveAttrs(node);
101
+ if (!attrs) {
107
102
  return undefined;
108
103
  }
104
+ const { id, containerTitle, doi } = attrs, rest = __rest(attrs, ["id", "containerTitle", "doi"]);
105
+ const item = Object.assign({ _id: id, objectType: ObjectTypes.BibliographyItem, 'container-title': containerTitle, DOI: doi }, rest);
106
+ return pickBy(item, (v) => v !== undefined);
107
+ };
108
+ const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
109
+ const getEffectiveAttrs = (node) => {
110
+ const _a = node.attrs, { dataTracked } = _a, attrs = __rest(_a, ["dataTracked"]);
111
+ const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(getLatest);
109
112
  const isRejected = nodeChange &&
110
113
  nodeChange.operation === CHANGE_OPERATION.set_node_attributes &&
111
114
  nodeChange.status === CHANGE_STATUS.rejected;
112
- return mapNodeToModel(isRejected ? nodeChange === null || nodeChange === void 0 ? void 0 : nodeChange.oldAttrs : attrs, node.type);
115
+ return isRejected ? nodeChange === null || nodeChange === void 0 ? void 0 : nodeChange.oldAttrs : attrs;
113
116
  };
114
- export const getReferencesModelMap = (doc, excludeDeletedNode) => {
117
+ export const getBibliographyItemModelMap = (doc) => {
115
118
  const modelMap = new Map();
116
119
  doc.descendants((node) => {
117
- if (node.type === schema.nodes.bibliography_item ||
118
- node.type === schema.nodes.citation) {
119
- const model = getNodeModel(node, excludeDeletedNode);
120
+ if (node.type === schema.nodes.bibliography_item) {
121
+ const model = getBibliographyItem(node);
120
122
  if (model) {
121
123
  modelMap.set(model._id, model);
122
124
  }
@@ -124,3 +126,12 @@ export const getReferencesModelMap = (doc, excludeDeletedNode) => {
124
126
  });
125
127
  return modelMap;
126
128
  };
129
+ export const buildCitations = (citations) => citations.map((citation) => ({
130
+ citationID: citation[0].attrs.id,
131
+ citationItems: citation[0].attrs.rids.map((rid) => ({
132
+ id: rid,
133
+ })),
134
+ properties: {
135
+ noteIndex: 0,
136
+ },
137
+ }));
@@ -13,85 +13,69 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { buildBibliographyItems, buildCitationNodes, buildCitations, CitationProvider, } from '@manuscripts/library';
17
- import { isEqual } from 'lodash-es';
18
- import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
16
+ import { CitationProvider } from '@manuscripts/library';
17
+ import { isCitationNode } from '@manuscripts/transform';
18
+ import { isEqual } from 'lodash';
19
+ import { Plugin, PluginKey } from 'prosemirror-state';
19
20
  import { DecorationSet } from 'prosemirror-view';
20
21
  import { isRejectedInsert } from '../../lib/track-changes-utils';
21
- import { buildDecorations, getReferencesModelMap } from './bibliography-utils';
22
+ import { buildCitations, buildDecorations, getBibliographyItemModelMap, } from './bibliography-utils';
22
23
  export const bibliographyKey = new PluginKey('bibliography');
23
24
  export default (props) => {
24
- const { style, locale } = props.cslProps;
25
25
  return new Plugin({
26
26
  key: bibliographyKey,
27
27
  state: {
28
28
  init(config, instance) {
29
- const referencesModelMap = getReferencesModelMap(instance.doc);
30
- const citationNodes = buildCitationNodes(instance.doc, referencesModelMap);
31
- const filteredCitationNodes = citationNodes.filter((node) => !isRejectedInsert(node[0]));
32
- const citations = buildCitations(filteredCitationNodes, (id) => referencesModelMap.get(id));
33
- const bibliographyItems = buildBibliographyItems(filteredCitationNodes, (id) => referencesModelMap.get(id));
34
- return {
35
- citationNodes,
36
- citations,
37
- bibliographyItems,
38
- };
29
+ return buildBibliographyPluginState(instance.doc, props.cslProps);
39
30
  },
40
- apply(tr, value, oldState, newState) {
41
- const referencesModelMap = getReferencesModelMap(newState.doc);
42
- const citationNodes = buildCitationNodes(newState.doc, referencesModelMap);
43
- const filteredCitationNodes = citationNodes.filter((node) => !isRejectedInsert(node[0]));
44
- const citations = buildCitations(filteredCitationNodes, (id) => referencesModelMap.get(id));
45
- const bibliographyItems = buildBibliographyItems(filteredCitationNodes, (id) => referencesModelMap.get(id));
46
- const meta = tr.getMeta(bibliographyKey);
47
- const triggerUpdate = meta && meta.triggerUpdate;
48
- return {
49
- citationNodes,
50
- citations,
51
- bibliographyItems,
52
- triggerUpdate,
53
- };
54
- },
55
- },
56
- appendTransaction(transactions, oldState, newState) {
57
- const { citations: oldCitations } = bibliographyKey.getState(oldState);
58
- const { citations, bibliographyItems } = bibliographyKey.getState(newState);
59
- const bibliographyInserted = transactions.some((tr) => {
60
- const meta = tr.getMeta(bibliographyKey);
61
- return meta && meta.bibliographyInserted;
62
- });
63
- const initCitations = transactions.some((tr) => {
64
- const meta = tr.getMeta(bibliographyKey);
65
- return meta && meta.initCitations;
66
- });
67
- if (isEqual(citations, oldCitations) &&
68
- !bibliographyInserted &&
69
- !initCitations) {
70
- return null;
71
- }
72
- const { tr } = newState;
73
- const { selection } = tr;
74
- try {
75
- const generatedCitations = new Map(CitationProvider.rebuildProcessorState(citations, bibliographyItems, style || '', locale, 'html').map((item) => [item[0], item[2]]));
76
- props.setCiteprocCitations(generatedCitations);
77
- if (selection instanceof NodeSelection) {
78
- tr.setSelection(NodeSelection.create(tr.doc, selection.from));
31
+ apply(tr, value) {
32
+ if (!tr.steps.length) {
33
+ return value;
79
34
  }
80
- tr.setMeta(bibliographyKey, {
81
- triggerUpdate: true,
82
- });
83
- tr.setMeta('origin', bibliographyKey);
84
- return tr;
85
- }
86
- catch (error) {
87
- console.error(error);
88
- }
35
+ return buildBibliographyPluginState(tr.doc, props.cslProps, value);
36
+ },
89
37
  },
90
38
  props: {
91
39
  decorations(state) {
92
- const { citationNodes, triggerUpdate } = bibliographyKey.getState(state);
93
- return DecorationSet.create(state.doc, buildDecorations(state.doc, citationNodes, props.popper, getReferencesModelMap(state.doc), triggerUpdate));
40
+ const bib = getBibliographyPluginState(state);
41
+ return DecorationSet.create(state.doc, buildDecorations(bib, state.doc));
94
42
  },
95
43
  },
96
44
  });
97
45
  };
46
+ const buildBibliographyPluginState = (doc, csl, $old) => {
47
+ const nodes = [];
48
+ doc.descendants((node, pos) => {
49
+ if (isCitationNode(node) && !isRejectedInsert(node)) {
50
+ nodes.push([node, pos]);
51
+ }
52
+ });
53
+ const modelMap = getBibliographyItemModelMap(doc);
54
+ const citations = buildCitations(nodes);
55
+ const $new = {
56
+ citationNodes: nodes,
57
+ citations,
58
+ bibliographyItems: modelMap,
59
+ };
60
+ if (!csl.style) {
61
+ return $new;
62
+ }
63
+ if ($old && isEqual(citations, $old.citations)) {
64
+ $new.provider = $old.provider;
65
+ $new.renderedCitations = $old.renderedCitations;
66
+ }
67
+ else {
68
+ const provider = new CitationProvider({
69
+ getLibraryItem: (id) => modelMap.get(id),
70
+ citationStyle: csl.style || '',
71
+ locale: csl.locale,
72
+ });
73
+ const citationTexts = provider.rebuildState(buildCitations(nodes));
74
+ $new.provider = provider;
75
+ $new.renderedCitations = new Map(citationTexts.map((i) => [i[0], i[2]]));
76
+ }
77
+ return $new;
78
+ };
79
+ export const getBibliographyPluginState = (state) => {
80
+ return bibliographyKey.getState(state);
81
+ };
@@ -59,7 +59,7 @@ export default (props) => {
59
59
  };
60
60
  const getNodePosition = (node, pos) => {
61
61
  switch (node.type) {
62
- case node.type.schema.nodes.keywords_section:
62
+ case schema.nodes.keywords:
63
63
  return pos + 2;
64
64
  default:
65
65
  return pos + 1;
@@ -68,7 +68,7 @@ const getNodePosition = (node, pos) => {
68
68
  const commentsState = (setSelectedComment, doc) => {
69
69
  const comments = [];
70
70
  doc.descendants((node) => {
71
- if (node.type === schema.nodes.comment_list) {
71
+ if (node.type === schema.nodes.comments) {
72
72
  node.descendants((comment) => {
73
73
  comments.push(comment.attrs);
74
74
  });
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { isInlineFootnoteNode, } from '@manuscripts/transform';
16
+ import { isFootnoteNode, isInlineFootnoteNode, } from '@manuscripts/transform';
17
17
  import { isEqual } from 'lodash-es';
18
18
  import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
19
19
  import { Decoration, DecorationSet } from 'prosemirror-view';
@@ -25,14 +25,17 @@ export const buildPluginState = (doc) => {
25
25
  doc.descendants((node, pos) => {
26
26
  if (isInlineFootnoteNode(node)) {
27
27
  nodes.push([node, pos]);
28
- labels.set(node.attrs.rid, String(++index));
28
+ node.attrs.rids.forEach((rid) => {
29
+ labels.set(rid, String(++index));
30
+ });
29
31
  }
30
32
  });
31
33
  return { nodes, labels };
32
34
  };
33
35
  const scrollToInlineFootnote = (rid, view) => {
34
36
  view.state.doc.descendants((node, pos) => {
35
- if (node.attrs.rid === rid) {
37
+ const footnote = node;
38
+ if (footnote.attrs.rids.includes(rid)) {
36
39
  const selection = NodeSelection.create(view.state.doc, pos);
37
40
  view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
38
41
  }
@@ -66,9 +69,12 @@ export default () => {
66
69
  }
67
70
  const { tr } = newState;
68
71
  inlineFootnoteNodes.forEach(([node, pos]) => {
69
- const contents = labels.get(node.attrs.rid);
70
- if (node.attrs.contents !== contents) {
71
- tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), { contents }));
72
+ const footnote = node;
73
+ const contents = footnote.attrs.rids
74
+ .map((rid) => labels.get(rid))
75
+ .join('');
76
+ if (footnote.attrs.contents !== contents) {
77
+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, footnote.attrs), { rids: footnote.attrs.rids, contents }));
72
78
  }
73
79
  });
74
80
  return tr;
@@ -79,11 +85,14 @@ export default () => {
79
85
  const { labels } = footnotesKey.getState(state);
80
86
  if (labels) {
81
87
  state.doc.descendants((node, pos) => {
82
- const { id } = node.attrs;
83
- if (labels.has(id)) {
84
- decorations.push(Decoration.widget(pos + 2, labelWidget(labels.get(id), id), {
85
- side: -1,
86
- }));
88
+ if (isFootnoteNode(node)) {
89
+ const id = node.attrs.id;
90
+ const label = labels.get(id);
91
+ if (label) {
92
+ decorations.push(Decoration.widget(pos + 2, labelWidget(label, id), {
93
+ side: -1,
94
+ }));
95
+ }
87
96
  }
88
97
  });
89
98
  }
@@ -1,43 +1,33 @@
1
1
  import { skipTracking } from '@manuscripts/track-changes-plugin';
2
- import { generateNodeID, isFootnoteNode, isListNode, } from '@manuscripts/transform';
2
+ import { generateNodeID, schema } from '@manuscripts/transform';
3
3
  import { Plugin } from 'prosemirror-state';
4
+ const isManuscriptNode = (node) => {
5
+ return node && node.type === schema.nodes.manuscript;
6
+ };
4
7
  export default () => {
5
8
  return new Plugin({
6
9
  appendTransaction(transactions, oldState, newState) {
7
- if (!transactions.some((transaction) => transaction.docChanged)) {
10
+ if (!transactions.some((tr) => tr.docChanged)) {
8
11
  return null;
9
12
  }
10
- const newTr = newState.tr;
11
- const diffStart = oldState.doc.content.findDiffStart(newState.doc.content);
12
- const diffEnd = oldState.doc.content.findDiffEnd(newState.doc.content);
13
13
  const ids = new Set();
14
- if (diffStart || diffEnd) {
15
- const start = diffStart || 0;
16
- const end = diffEnd ? diffEnd.b : newState.doc.nodeSize - 2;
17
- let endOfList = 0, endOfFootnote = 0;
18
- newState.doc.nodesBetween(start, end, (node, pos) => {
19
- const { id } = node.attrs;
20
- if (isListNode(node)) {
21
- endOfList = Math.max(endOfList, pos + node.nodeSize);
22
- }
23
- else if (isFootnoteNode(node)) {
24
- endOfFootnote = Math.max(endOfFootnote, pos + node.nodeSize);
25
- }
26
- const insideFootnote = pos <= endOfFootnote;
27
- if ('id' in node.attrs &&
28
- (!insideFootnote || node.isInline) &&
29
- (!id || id.length === 0 || ids.has(id))) {
30
- const newId = generateNodeID(node.type);
31
- const updatedAttrs = Object.assign(Object.assign({}, node.attrs), { id: newId });
32
- newTr.setNodeMarkup(pos, undefined, updatedAttrs, node.marks);
33
- ids.add(newId);
34
- }
35
- });
36
- skipTracking(newTr);
37
- newTr.setMeta('origin', 'persist');
38
- return newTr;
39
- }
40
- return null;
14
+ const tr = newState.tr;
15
+ newState.doc.descendants((node, pos, parent) => {
16
+ if (node.isInline ||
17
+ isManuscriptNode(node) ||
18
+ isManuscriptNode(parent)) {
19
+ return;
20
+ }
21
+ let id = node.attrs.id;
22
+ if (!id || ids.has(id)) {
23
+ id = generateNodeID(node.type);
24
+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), { id }), node.marks);
25
+ }
26
+ ids.add(id);
27
+ });
28
+ skipTracking(tr);
29
+ tr.setMeta('origin', 'persist');
30
+ return tr;
41
31
  },
42
32
  });
43
33
  };
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { trackChangesPluginKey } from '@manuscripts/track-changes-plugin';
17
- import { isGraphicalAbstractSectionNode, isKeywordsSectionNode, isSectionTitleNode, } from '@manuscripts/transform';
17
+ import { isGraphicalAbstractSectionNode, isKeywordsNode, isSectionTitleNode, } from '@manuscripts/transform';
18
18
  import { Plugin } from 'prosemirror-state';
19
19
  import { ReplaceAroundStep, ReplaceStep } from 'prosemirror-transform';
20
20
  import { highlightKey, SET_COMMENT } from './highlight';
@@ -38,8 +38,7 @@ const preventTitleEdit = (tr) => {
38
38
  const currentDoc = tr.docs[i];
39
39
  step.getMap().forEach((fromA, toA) => {
40
40
  currentDoc.nodesBetween(fromA, toA, (node, nodePos) => {
41
- if (isGraphicalAbstractSectionNode(node) ||
42
- isKeywordsSectionNode(node)) {
41
+ if (isGraphicalAbstractSectionNode(node) || isKeywordsNode(node)) {
43
42
  node.descendants((childNode, childPos) => {
44
43
  const inDocPos = nodePos + childPos;
45
44
  if (isSectionTitleNode(childNode) &&
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { ObjectTypes, } from '@manuscripts/json-schema';
17
- import { generateID, hasObjectType, isSectionNodeType, isTOCSectionNode, } from '@manuscripts/transform';
17
+ import { generateID, hasObjectType, isSectionNodeType, isTOCSectionNode, schema, } from '@manuscripts/transform';
18
18
  import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
19
19
  import { getMatchingChild, iterateChildren } from '../lib/utils';
20
20
  export const tocKey = new PluginKey('toc');
@@ -34,32 +34,37 @@ const buildTOCList = (headingStyles, list, node, depth = 1, prefix = '') => {
34
34
  ? sectionNumberingStyle.suffix
35
35
  : '.';
36
36
  let index = sectionNumberingStyle ? sectionNumberingStyle.startIndex : 1;
37
- for (const childNode of iterateChildren(node)) {
38
- if (isSectionNodeType(childNode.type) && !isTOCSectionNode(childNode)) {
39
- const numbering = numberingScheme === 'none' ? '' : `${prefix}${index}`;
40
- const firstChildNode = childNode.child(0);
41
- if (firstChildNode.type === firstChildNode.type.schema.nodes.section_title) {
42
- const item = document.createElement('li');
43
- item.classList.add('manuscript-toc-list-item');
44
- item.setAttribute('data-referenced-section', childNode.attrs.id);
45
- item.setAttribute('data-referenced-section-path-length', String(depth));
46
- item.textContent = `${numbering ? `${numbering}${suffix}` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
47
- list.appendChild(item);
48
- }
49
- const childSection = getMatchingChild(childNode, (node) => isSectionNodeType(node.type));
50
- if (childSection) {
51
- const paragraphStyle = headingStyles.get(`heading${depth + 1}`);
52
- if (!paragraphStyle || paragraphStyle.partOfTOC) {
53
- const sublist = document.createElement('ul');
54
- buildTOCList(headingStyles, sublist, childNode, depth + 1, numbering ? `${numbering}.` : '');
55
- const item = document.createElement('li');
56
- item.appendChild(sublist);
57
- list.appendChild(item);
37
+ node.forEach((child) => {
38
+ if (child.type === schema.nodes.body) {
39
+ for (const childNode of iterateChildren(child)) {
40
+ if (isSectionNodeType(childNode.type) && !isTOCSectionNode(childNode)) {
41
+ const numbering = numberingScheme === 'none' ? '' : `${prefix}${index}`;
42
+ const firstChildNode = childNode.child(0);
43
+ if (firstChildNode.type ===
44
+ firstChildNode.type.schema.nodes.section_title) {
45
+ const item = document.createElement('li');
46
+ item.classList.add('manuscript-toc-list-item');
47
+ item.setAttribute('data-referenced-section', childNode.attrs.id);
48
+ item.setAttribute('data-referenced-section-path-length', String(depth));
49
+ item.textContent = `${numbering ? `${numbering}${suffix}` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
50
+ list.appendChild(item);
51
+ }
52
+ const childSection = getMatchingChild(childNode, (node) => isSectionNodeType(node.type));
53
+ if (childSection) {
54
+ const paragraphStyle = headingStyles.get(`heading${depth + 1}`);
55
+ if (!paragraphStyle || paragraphStyle.partOfTOC) {
56
+ const sublist = document.createElement('ul');
57
+ buildTOCList(headingStyles, sublist, childNode, depth + 1, numbering ? `${numbering}.` : '');
58
+ const item = document.createElement('li');
59
+ item.appendChild(sublist);
60
+ list.appendChild(item);
61
+ }
62
+ }
63
+ index++;
58
64
  }
59
65
  }
60
- index++;
61
66
  }
62
- }
67
+ });
63
68
  };
64
69
  const isParagraphStyle = hasObjectType(ObjectTypes.ParagraphStyle);
65
70
  const buildHeadingStyles = (modelMap) => {
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { NodeSelection, TextSelection, } from 'prosemirror-state';
16
+ import { NodeSelection, } from 'prosemirror-state';
17
17
  import { useCallback, useEffect, useRef, useState } from 'react';
18
18
  import { useHistory } from 'react-router-dom';
19
19
  import { bibliographyKey } from './plugins/bibliography';
@@ -66,9 +66,7 @@ const useEditor = (initialState, createView) => {
66
66
  state.doc.descendants((node, pos) => {
67
67
  if (node.attrs.id === id) {
68
68
  currentView.focus();
69
- const selection = node.isAtom
70
- ? NodeSelection.create(state.tr.doc, pos)
71
- : TextSelection.near(state.tr.doc.resolve(pos + 1));
69
+ const selection = NodeSelection.create(state.tr.doc, pos);
72
70
  currentView.dispatch(state.tr.setSelection(selection));
73
71
  const dom = currentView.domAtPos(pos + 1);
74
72
  if (dom.node instanceof Element) {