@manuscripts/body-editor 1.5.16 → 1.6.0

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 (78) 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/views/bibliography_element.js +20 -38
  16. package/dist/cjs/views/citation.js +29 -26
  17. package/dist/cjs/views/citation_editable.js +25 -44
  18. package/dist/cjs/views/{contributors_section.js → contributors.js} +4 -4
  19. package/dist/cjs/views/cross_reference.js +7 -36
  20. package/dist/cjs/views/cross_reference_editable.js +6 -14
  21. package/dist/cjs/views/editable_block.js +2 -2
  22. package/dist/cjs/views/{meta_section.js → empty.js} +3 -3
  23. package/dist/cjs/views/section_title.js +1 -16
  24. package/dist/es/commands.js +55 -110
  25. package/dist/es/components/outline/DraggableTree.js +33 -25
  26. package/dist/es/components/toolbar/OrderListSelector.js +4 -12
  27. package/dist/es/configs/editor-plugins.js +2 -2
  28. package/dist/es/configs/editor-views.js +4 -6
  29. package/dist/es/lib/context-menu.js +7 -6
  30. package/dist/es/node-type-icons.js +0 -1
  31. package/dist/es/plugins/bibliography/bibliography-utils.js +56 -45
  32. package/dist/es/plugins/bibliography/index.js +49 -65
  33. package/dist/es/plugins/comment_annotation.js +2 -2
  34. package/dist/es/plugins/footnotes/index.js +20 -11
  35. package/dist/es/plugins/persist.js +22 -32
  36. package/dist/es/plugins/sections.js +2 -3
  37. package/dist/es/plugins/toc.js +29 -24
  38. package/dist/es/views/bibliography_element.js +21 -39
  39. package/dist/es/views/citation.js +31 -28
  40. package/dist/es/views/citation_editable.js +28 -47
  41. package/dist/es/views/{contributors_section.js → contributors.js} +2 -2
  42. package/dist/es/views/cross_reference.js +7 -33
  43. package/dist/es/views/cross_reference_editable.js +6 -14
  44. package/dist/es/views/editable_block.js +3 -3
  45. package/dist/es/views/{meta_section.js → empty.js} +3 -3
  46. package/dist/es/views/section_title.js +0 -14
  47. package/dist/types/commands.d.ts +1 -2
  48. package/dist/types/components/outline/DraggableTree.d.ts +1 -2
  49. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -10
  50. package/dist/types/configs/editor-plugins.d.ts +1 -5
  51. package/dist/types/configs/editor-views.d.ts +5 -6
  52. package/dist/types/lib/context-menu.d.ts +0 -1
  53. package/dist/types/plugins/bibliography/bibliography-utils.d.ts +10 -7
  54. package/dist/types/plugins/bibliography/index.d.ts +21 -3
  55. package/dist/types/views/bibliography_element.d.ts +1 -0
  56. package/dist/types/views/citation.d.ts +3 -4
  57. package/dist/types/views/citation_editable.d.ts +2 -8
  58. package/dist/types/views/{contributors_section.d.ts → contributors.d.ts} +3 -3
  59. package/dist/types/views/cross_reference.d.ts +0 -5
  60. package/dist/types/views/{meta_section.d.ts → empty.d.ts} +2 -2
  61. package/dist/types/views/section_title.d.ts +0 -2
  62. package/package.json +4 -22
  63. package/styles/AdvancedEditor.css +30 -34
  64. package/dist/cjs/plugins/auxiliary_object_order.js +0 -49
  65. package/dist/cjs/plugins/bibliography/types.js +0 -17
  66. package/dist/cjs/plugins/footnotes/footnotes-utils.js +0 -52
  67. package/dist/cjs/views/bibliography_item.js +0 -138
  68. package/dist/cjs/views/bibliography_item_editable.js +0 -20
  69. package/dist/es/plugins/auxiliary_object_order.js +0 -46
  70. package/dist/es/plugins/bibliography/types.js +0 -16
  71. package/dist/es/plugins/footnotes/footnotes-utils.js +0 -46
  72. package/dist/es/views/bibliography_item.js +0 -131
  73. package/dist/es/views/bibliography_item_editable.js +0 -18
  74. package/dist/types/plugins/auxiliary_object_order.d.ts +0 -12
  75. package/dist/types/plugins/bibliography/types.d.ts +0 -40
  76. package/dist/types/plugins/footnotes/footnotes-utils.d.ts +0 -25
  77. package/dist/types/views/bibliography_item.d.ts +0 -34
  78. 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) => {
@@ -33,39 +33,20 @@ var __rest = (this && this.__rest) || function (s, e) {
33
33
  }
34
34
  return t;
35
35
  };
36
- import { CitationProvider } from '@manuscripts/library';
37
36
  import { CHANGE_OPERATION, CHANGE_STATUS, } from '@manuscripts/track-changes-plugin';
38
37
  import { buildComment } from '@manuscripts/transform';
39
38
  import React from 'react';
40
39
  import { commentIcon, editIcon } from '../assets';
41
40
  import { sanitize } from '../lib/dompurify';
42
- import { bibliographyKey } from '../plugins/bibliography';
43
- import { getReferencesModelMap } from '../plugins/bibliography/bibliography-utils';
41
+ import { getBibliographyPluginState } from '../plugins/bibliography';
44
42
  import { commentAnnotation } from '../plugins/comment_annotation';
45
43
  import { getAttrsTrackingButton, getMarkDecoration, } from '../plugins/tracking-mark';
46
44
  import BlockView from './block_view';
47
45
  import { createNodeView } from './creators';
48
- const createBibliography = (bibliographyItems, cslProps) => __awaiter(void 0, void 0, void 0, function* () {
49
- const bibliographyItemsMap = new Map(bibliographyItems.map((item) => [item._id, item]));
50
- const getLibraryItem = (id) => bibliographyItemsMap.get(id);
51
- const { style = '', locale } = cslProps;
52
- const provider = new CitationProvider({
53
- getLibraryItem,
54
- citationStyle: style,
55
- locale,
56
- });
57
- const [bibmeta, generatedBibliographyItems] = provider.makeBibliography(bibliographyItems);
58
- if (bibmeta.bibliography_errors.length) {
59
- console.error(bibmeta.bibliography_errors);
60
- }
61
- const bibliographyFragment = generatedBibliographyItems
62
- .map((item, i) => `<div id=${bibmeta.entry_ids[i]} class="bib-item"><div><div class="csl-bib-body">${item}</div></div></div>`)
63
- .join('');
64
- return sanitize(`<div class="contents">${bibliographyFragment}</div>`);
65
- });
66
46
  export class BibliographyElementBlockView extends BlockView {
67
47
  constructor() {
68
48
  super(...arguments);
49
+ this.gutterButtons = () => [];
69
50
  this.showPopper = (referenceID) => {
70
51
  const { renderReactComponent, components: { ReferencesEditor }, } = this.props;
71
52
  const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
@@ -78,13 +59,14 @@ export class BibliographyElementBlockView extends BlockView {
78
59
  this.popperContainer = document.createElement('div');
79
60
  this.popperContainer.className = 'references';
80
61
  }
81
- renderReactComponent(React.createElement(ReferencesEditor, { saveModel: handleSave, deleteModel: this.deleteNode, modelMap: getReferencesModelMap(this.view.state.doc, true), referenceID: referenceID }), this.popperContainer);
62
+ const bib = getBibliographyPluginState(this.view.state);
63
+ renderReactComponent(React.createElement(ReferencesEditor, { saveModel: handleSave, deleteModel: this.deleteNode, modelMap: bib.bibliographyItems, referenceID: referenceID }), this.popperContainer);
82
64
  this.props.popper.show(this.dom, this.popperContainer, 'right');
83
65
  };
84
66
  this.stopEvent = () => true;
85
67
  this.ignoreMutation = () => true;
86
68
  this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
87
- const bibliographyItems = bibliographyKey.getState(this.view.state).bibliographyItems;
69
+ const bib = getBibliographyPluginState(this.view.state);
88
70
  const commentsDecorationSet = commentAnnotation.getState(this.view.state);
89
71
  const commentElementMap = new Map();
90
72
  const dataTrackedMap = new Map();
@@ -103,9 +85,14 @@ export class BibliographyElementBlockView extends BlockView {
103
85
  dataTrackedMap.set(node.attrs.id, lastChange);
104
86
  }
105
87
  });
106
- const bibliographyFragment = yield createBibliography(bibliographyItems, this.props.cslProps);
107
- const bibItems = bibliographyFragment.querySelectorAll('.bib-item');
108
- bibItems.forEach((element) => {
88
+ const can = this.props.getCapabilities();
89
+ const wrapper = document.createElement('div');
90
+ wrapper.classList.add('contents');
91
+ const [meta, bibliography] = bib.provider.makeBibliography();
92
+ for (let i = 0; i < bibliography.length; i++) {
93
+ const id = meta.entry_ids[i];
94
+ const fragment = bibliography[i];
95
+ const element = sanitize(`<div id="${id}" class="bib-item"><div class="csl-bib-body">${fragment}</div></div>`).firstElementChild;
109
96
  const doubleButton = document.createElement('div');
110
97
  const editButton = document.createElement('button');
111
98
  const commentButton = document.createElement('button');
@@ -124,14 +111,14 @@ export class BibliographyElementBlockView extends BlockView {
124
111
  editButton.innerHTML = editIcon;
125
112
  commentButton.innerHTML = commentIcon;
126
113
  doubleButton.append(editButton, commentButton);
127
- if (this.props.getCapabilities().seeReferencesButtons &&
114
+ if (can.seeReferencesButtons &&
128
115
  !element.querySelector('.bibliography-double-button')) {
129
116
  element.appendChild(doubleButton);
130
117
  }
131
- editButton.disabled = !this.props.getCapabilities().editCitationsAndRefs;
118
+ editButton.disabled = !can.editCitationsAndRefs;
132
119
  const commentElement = commentElementMap.get(element.id);
133
120
  if (commentElement) {
134
- element.childNodes[0].appendChild(commentElement);
121
+ element.appendChild(commentElement);
135
122
  }
136
123
  const dataTracked = dataTrackedMap.get(element.id);
137
124
  if (dataTracked) {
@@ -140,16 +127,17 @@ export class BibliographyElementBlockView extends BlockView {
140
127
  decoration.style && element.setAttribute('style', decoration.style);
141
128
  if (dataTracked.status === CHANGE_STATUS.pending &&
142
129
  dataTracked.operation === CHANGE_OPERATION.set_node_attributes) {
143
- element.childNodes[0].appendChild(getAttrsTrackingButton(dataTracked.id));
130
+ element.appendChild(getAttrsTrackingButton(dataTracked.id));
144
131
  }
145
132
  }
146
- });
133
+ wrapper.append(element);
134
+ }
147
135
  const oldContent = this.container.querySelector('.contents');
148
136
  if (oldContent) {
149
- this.container.replaceChild(bibliographyFragment, oldContent);
137
+ this.container.replaceChild(wrapper, oldContent);
150
138
  }
151
139
  else {
152
- this.container.appendChild(bibliographyFragment);
140
+ this.container.appendChild(wrapper);
153
141
  }
154
142
  });
155
143
  this.createElement = () => {
@@ -158,12 +146,6 @@ export class BibliographyElementBlockView extends BlockView {
158
146
  this.container.contentEditable = 'false';
159
147
  this.dom.setAttribute('contenteditable', 'false');
160
148
  this.dom.appendChild(this.container);
161
- this.contentDOM = document.createElement('div');
162
- this.contentDOM.classList.add('block');
163
- this.contentDOM.setAttribute('id', this.node.attrs.id);
164
- this.contentDOM.setAttribute('contenteditable', 'false');
165
- this.contentDOM.hidden = true;
166
- this.container.appendChild(this.contentDOM);
167
149
  };
168
150
  }
169
151
  }