@manuscripts/body-editor 1.9.7-LEAN-3136 → 1.9.9

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 (43) hide show
  1. package/dist/cjs/commands.js +4 -16
  2. package/dist/cjs/components/outline/DraggableTree.js +1 -1
  3. package/dist/cjs/configs/ManuscriptsEditor.js +14 -20
  4. package/dist/cjs/configs/editor-views.js +1 -1
  5. package/dist/cjs/keys/list.js +13 -2
  6. package/dist/cjs/plugins/affiliations.js +0 -3
  7. package/dist/cjs/plugins/bibliography/index.js +1 -1
  8. package/dist/cjs/plugins/footnotes/footnotes-utils.js +1 -33
  9. package/dist/cjs/plugins/footnotes/index.js +26 -77
  10. package/dist/cjs/plugins/highlight/index.js +5 -6
  11. package/dist/cjs/plugins/selected-suggestion-ui.js +4 -8
  12. package/dist/cjs/plugins/table-footnote.js +0 -3
  13. package/dist/cjs/views/base_node_view.js +1 -1
  14. package/dist/cjs/views/bibliography_element.js +0 -6
  15. package/dist/cjs/views/citation.js +0 -3
  16. package/dist/cjs/views/citation_editable.js +0 -6
  17. package/dist/cjs/views/footnotes_element.js +1 -3
  18. package/dist/cjs/views/inline_footnote.js +2 -17
  19. package/dist/es/commands.js +5 -17
  20. package/dist/es/components/outline/DraggableTree.js +1 -1
  21. package/dist/es/configs/ManuscriptsEditor.js +14 -20
  22. package/dist/es/configs/editor-views.js +1 -1
  23. package/dist/es/keys/list.js +13 -2
  24. package/dist/es/plugins/affiliations.js +0 -3
  25. package/dist/es/plugins/bibliography/index.js +1 -1
  26. package/dist/es/plugins/footnotes/footnotes-utils.js +0 -31
  27. package/dist/es/plugins/footnotes/index.js +27 -78
  28. package/dist/es/plugins/highlight/index.js +5 -6
  29. package/dist/es/plugins/selected-suggestion-ui.js +4 -8
  30. package/dist/es/plugins/table-footnote.js +0 -3
  31. package/dist/es/views/base_node_view.js +1 -1
  32. package/dist/es/views/bibliography_element.js +0 -6
  33. package/dist/es/views/citation.js +0 -3
  34. package/dist/es/views/citation_editable.js +0 -6
  35. package/dist/es/views/footnotes_element.js +1 -3
  36. package/dist/es/views/inline_footnote.js +2 -17
  37. package/dist/types/plugins/bibliography/index.d.ts +1 -1
  38. package/dist/types/plugins/footnotes/footnotes-utils.d.ts +0 -1
  39. package/dist/types/plugins/footnotes/index.d.ts +3 -5
  40. package/dist/types/views/footnotes_element.d.ts +3 -3
  41. package/package.json +3 -3
  42. package/styles/AdvancedEditor.css +8 -6
  43. package/styles/Editor.css +3 -7
@@ -327,24 +327,12 @@ const insertInlineFootnote = (kind) => (state, dispatch) => {
327
327
  let selectionPos;
328
328
  if (!footnotesSection) {
329
329
  const section = state.schema.nodes.footnotes_section.create({}, [
330
- state.schema.nodes.section_title.create({}, state.schema.text('Footnotes')),
330
+ state.schema.nodes.section_title.create({}, state.schema.text('Notes')),
331
331
  state.schema.nodes.footnotes_element.create({}, footnote),
332
332
  ]);
333
333
  const backmatter = (0, prosemirror_utils_1.findChildrenByType)(tr.doc, transform_1.schema.nodes.backmatter)[0];
334
- const sectionPos = backmatter.pos + 1;
335
- tr.insert(sectionPos, section);
336
- let footnotePos = 0;
337
- section.descendants((n, pos) => {
338
- if ((0, transform_1.isFootnoteNode)(n)) {
339
- footnotePos = pos;
340
- n.descendants((childNode, childPos) => {
341
- if ((0, transform_1.isParagraphNode)(childNode)) {
342
- footnotePos += childPos;
343
- }
344
- });
345
- }
346
- });
347
- selectionPos = sectionPos + footnotePos;
334
+ tr.insert(backmatter.pos + 1, section);
335
+ selectionPos = backmatter.pos + section.nodeSize - 3;
348
336
  }
349
337
  else {
350
338
  const footnoteElement = (0, prosemirror_utils_1.findChildrenByType)(footnotesSection.node, transform_1.schema.nodes.footnotes_element);
@@ -356,7 +344,7 @@ const insertInlineFootnote = (kind) => (state, dispatch) => {
356
344
  selectionPos = pos + 2;
357
345
  }
358
346
  if (dispatch && selectionPos) {
359
- const selection = prosemirror_state_1.TextSelection.near(tr.doc.resolve(selectionPos));
347
+ const selection = prosemirror_state_1.TextSelection.create(tr.doc, selectionPos);
360
348
  dispatch(tr.setSelection(selection).scrollIntoView());
361
349
  }
362
350
  return true;
@@ -176,6 +176,6 @@ const DraggableTree = ({ tree, view, depth, can, }) => {
176
176
  react_1.default.createElement(Outline_1.OutlineItemLink, { to: `#${node.attrs.id}` },
177
177
  react_1.default.createElement(Outline_1.OutlineItemIcon, null, (0, node_type_icons_1.nodeTypeIcon)(node.type)),
178
178
  react_1.default.createElement(Outline_1.OutlineItemLinkText, { className: `outline-text-${node.type.name} ${isDeletedItem && 'deleted'}` }, itemText(node))))),
179
- items.length ? (react_1.default.createElement("div", { className: `subtree ${isOpen ? '' : 'collapsed'}` }, items.map((subtree) => (react_1.default.createElement(exports.DraggableTree, { key: subtree.node.attrs.id, tree: subtree, view: view, depth: !tree.parent ? depth : depth + 1, can: can }))))) : null));
179
+ items.length ? (react_1.default.createElement("div", { className: `subtree ${isOpen ? '' : 'collapsed'}` }, items.map((subtree, index) => (react_1.default.createElement(exports.DraggableTree, { key: subtree.node.attrs.id || 'subtree-' + index, tree: subtree, view: view, depth: !tree.parent ? depth : depth + 1, can: can }))))) : null));
180
180
  };
181
181
  exports.DraggableTree = DraggableTree;
@@ -32,24 +32,18 @@ const createEditorState = (props) => prosemirror_state_1.EditorState.create({
32
32
  plugins: (0, editor_plugins_1.default)(props),
33
33
  });
34
34
  exports.createEditorState = createEditorState;
35
- const createEditorView = (props, root, state, dispatch) => {
36
- const view = new prosemirror_view_1.EditorView(root, {
37
- state,
38
- editable: () => props.getCapabilities().editArticle,
39
- scrollMargin: {
40
- top: 100,
41
- bottom: 100,
42
- left: 0,
43
- right: 0,
44
- },
45
- dispatchTransaction: dispatch,
46
- nodeViews: (0, editor_views_1.default)(props, dispatch),
47
- attributes: props.attributes,
48
- transformPasted: paste_1.transformPasted,
49
- });
50
- const tr = view.state.tr.setMeta('INIT', true);
51
- const nextState = view.state.apply(tr);
52
- view.updateState(nextState);
53
- return view;
54
- };
35
+ const createEditorView = (props, root, state, dispatch) => new prosemirror_view_1.EditorView(root, {
36
+ state,
37
+ editable: () => props.getCapabilities().editArticle,
38
+ scrollMargin: {
39
+ top: 100,
40
+ bottom: 100,
41
+ left: 0,
42
+ right: 0,
43
+ },
44
+ dispatchTransaction: dispatch,
45
+ nodeViews: (0, editor_views_1.default)(props, dispatch),
46
+ attributes: props.attributes,
47
+ transformPasted: paste_1.transformPasted,
48
+ });
55
49
  exports.createEditorView = createEditorView;
@@ -69,7 +69,7 @@ exports.default = (props, dispatch) => {
69
69
  footnote: (0, footnote_editable_1.default)(props),
70
70
  footnotes_element: (0, footnotes_element_1.default)(props),
71
71
  inline_equation: (0, inline_equation_editable_1.default)(props),
72
- inline_footnote: (0, inline_footnote_editable_1.default)(props, dispatch),
72
+ inline_footnote: (0, inline_footnote_editable_1.default)(props),
73
73
  keyword: (0, keyword_1.default)(props, dispatch),
74
74
  keyword_group: (0, keyword_group_1.default)(props, dispatch),
75
75
  link: (0, link_editable_1.default)(props, dispatch),
@@ -18,17 +18,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.skipCommandTracking = void 0;
19
19
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
20
20
  const transform_1 = require("@manuscripts/transform");
21
+ const prosemirror_commands_1 = require("prosemirror-commands");
22
+ const prosemirror_inputrules_1 = require("prosemirror-inputrules");
21
23
  const prosemirror_schema_list_1 = require("prosemirror-schema-list");
24
+ const prosemirror_utils_1 = require("prosemirror-utils");
22
25
  const skipCommandTracking = (command) => (state, dispatch) => {
23
- command(state, (tr) => {
26
+ return command(state, (tr) => {
24
27
  if (dispatch) {
25
28
  (0, track_changes_plugin_1.skipTracking)(tr);
26
29
  dispatch(tr);
27
30
  }
28
31
  });
29
- return true;
30
32
  };
31
33
  exports.skipCommandTracking = skipCommandTracking;
34
+ const listItemBackward = (state, dispatch) => {
35
+ const { selection } = state;
36
+ const isListItem = (0, prosemirror_utils_1.findParentNodeOfType)(transform_1.schema.nodes.list_item)(selection);
37
+ if (isListItem) {
38
+ return (0, prosemirror_commands_1.joinBackward)(state, dispatch);
39
+ }
40
+ return false;
41
+ };
32
42
  const liftToOuterList = (itemType) => {
33
43
  return function (state, dispatch) {
34
44
  const { $from, $to } = state.selection;
@@ -55,5 +65,6 @@ const listKeymap = {
55
65
  'Mod-Alt-k': (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.bullet_list)),
56
66
  'Shift-Tab': (0, exports.skipCommandTracking)(liftToOuterList(transform_1.schema.nodes.list_item)),
57
67
  Tab: (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.sinkListItem)(transform_1.schema.nodes.list_item)),
68
+ Backspace: (0, exports.skipCommandTracking)((0, prosemirror_commands_1.chainCommands)(prosemirror_inputrules_1.undoInputRule, listItemBackward, prosemirror_commands_1.deleteSelection)),
58
69
  };
59
70
  exports.default = listKeymap;
@@ -74,9 +74,6 @@ exports.default = () => {
74
74
  },
75
75
  appendTransaction(transactions, oldState, newState) {
76
76
  const { indexedAffiliationIds } = exports.affiliationsKey.getState(newState);
77
- if (!transactions.find((tr) => tr.docChanged)) {
78
- return;
79
- }
80
77
  const oldPluginState = exports.affiliationsKey.getState(oldState);
81
78
  const { tr } = newState;
82
79
  const affiliations = [];
@@ -54,7 +54,7 @@ exports.default = (props) => {
54
54
  props: {
55
55
  decorations(state) {
56
56
  const bib = (0, exports.getBibliographyPluginState)(state);
57
- return prosemirror_view_1.DecorationSet.create(state.doc, bib ? (0, bibliography_utils_1.buildDecorations)(bib, state.doc) : []);
57
+ return prosemirror_view_1.DecorationSet.create(state.doc, (0, bibliography_utils_1.buildDecorations)(bib, state.doc));
58
58
  },
59
59
  },
60
60
  });
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getAlphaOrderIndices = exports.getInlineFootnotes = exports.updateTableInlineFootnoteLabels = exports.orderTableFootnotes = exports.buildTableFootnoteLabels = exports.getNewFootnotePos = exports.findTableInlineFootnoteIds = void 0;
18
+ exports.getInlineFootnotes = exports.updateTableInlineFootnoteLabels = exports.orderTableFootnotes = exports.buildTableFootnoteLabels = exports.getNewFootnotePos = exports.findTableInlineFootnoteIds = void 0;
19
19
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
20
20
  const transform_1 = require("@manuscripts/transform");
21
21
  const prosemirror_model_1 = require("prosemirror-model");
@@ -113,35 +113,3 @@ const getInlineFootnotes = (id, targetNode) => {
113
113
  return inlineFootnotes;
114
114
  };
115
115
  exports.getInlineFootnotes = getInlineFootnotes;
116
- function getAlphaOrderIndices(index) {
117
- const unicodeInterval = [97, 123];
118
- const places = unicodeInterval[1] - unicodeInterval[0];
119
- function getClassCount(n, order) {
120
- return n * Math.pow(places, order - 1);
121
- }
122
- let indices = null;
123
- for (;;) {
124
- let current = index;
125
- let position = 1;
126
- while (current >= places) {
127
- current = current / places;
128
- position++;
129
- }
130
- const newIndex = Math.floor(current);
131
- indices = indices ? indices : new Array(position).fill(0);
132
- indices.splice(indices.length - position, 1, newIndex);
133
- index -= getClassCount(newIndex, position);
134
- if (position === 1) {
135
- break;
136
- }
137
- }
138
- return (indices || [])
139
- .map((v, i, array) => {
140
- if (array.length > 1 && i !== array.length - 1) {
141
- return String.fromCodePoint(v + unicodeInterval[0] - 1);
142
- }
143
- return String.fromCodePoint(v + unicodeInterval[0]);
144
- })
145
- .join('');
146
- }
147
- exports.getAlphaOrderIndices = getAlphaOrderIndices;
@@ -18,8 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.buildPluginState = exports.uncitedFootnoteWidget = exports.footnotesKey = void 0;
22
- const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
21
+ exports.uncitedFootnoteWidget = exports.buildPluginState = exports.footnotesKey = void 0;
23
22
  const transform_1 = require("@manuscripts/transform");
24
23
  const lodash_1 = require("lodash");
25
24
  const prosemirror_state_1 = require("prosemirror-state");
@@ -32,10 +31,28 @@ const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
32
31
  const placeholder_1 = require("../placeholder");
33
32
  const footnotes_utils_1 = require("./footnotes-utils");
34
33
  exports.footnotesKey = new prosemirror_state_1.PluginKey('footnotes');
34
+ const buildPluginState = (doc) => {
35
+ const nodes = [];
36
+ let index = 0;
37
+ const labels = new Map();
38
+ doc.descendants((node, pos, parentNode) => {
39
+ if ((0, transform_1.isInlineFootnoteNode)(node) &&
40
+ parentNode &&
41
+ parentNode.type !== transform_1.schema.nodes.table_cell &&
42
+ parentNode.type !== transform_1.schema.nodes.table_header) {
43
+ nodes.push([node, pos]);
44
+ node.attrs.rids.forEach((rid) => {
45
+ labels.set(rid, String(++index));
46
+ });
47
+ }
48
+ });
49
+ return { nodes, labels };
50
+ };
51
+ exports.buildPluginState = buildPluginState;
35
52
  const scrollToInlineFootnote = (rid, view) => {
36
53
  view.state.doc.descendants((node, pos) => {
37
54
  const footnote = node;
38
- if ((0, transform_1.isInlineFootnoteNode)(node) && footnote.attrs.rids.includes(rid)) {
55
+ if (footnote.attrs.rids.includes(rid)) {
39
56
  const selection = prosemirror_state_1.NodeSelection.create(view.state.doc, pos);
40
57
  view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
41
58
  }
@@ -45,7 +62,7 @@ const labelWidget = (label, id) => (view) => {
45
62
  const element = document.createElement('span');
46
63
  element.className = 'footnote-label';
47
64
  element.textContent = label;
48
- element.addEventListener('mousedown', () => {
65
+ element.addEventListener('click', () => {
49
66
  scrollToInlineFootnote(id, view);
50
67
  });
51
68
  return element;
@@ -120,39 +137,6 @@ const deleteFootnoteWidget = (node, props, id, tableElement) => (view, getPos) =
120
137
  });
121
138
  return deleteBtn;
122
139
  };
123
- const buildPluginState = (doc) => {
124
- const inlineFootnotes = [];
125
- const footnotes = new Map();
126
- let footnoteElement;
127
- doc.descendants((node, pos, parentNode) => {
128
- if ((0, transform_1.isFootnotesSectionNode)(node)) {
129
- node.descendants((node, childPos) => {
130
- if ((0, transform_1.isFootnotesElementNode)(node)) {
131
- footnoteElement = [node, pos + childPos];
132
- }
133
- if ((0, transform_1.isFootnoteNode)(node)) {
134
- footnotes.set(node.attrs.id, [node, pos + childPos]);
135
- }
136
- });
137
- }
138
- if ((0, transform_1.isInlineFootnoteNode)(node) &&
139
- parentNode &&
140
- parentNode.type !== transform_1.schema.nodes.table_cell &&
141
- parentNode.type !== transform_1.schema.nodes.table_header) {
142
- inlineFootnotes.push([node, pos]);
143
- }
144
- });
145
- let index = 0;
146
- const labels = new Map();
147
- inlineFootnotes.sort((a, b) => a[1] - b[1]);
148
- inlineFootnotes.forEach(([node]) => {
149
- node.attrs.rids.forEach((rid) => {
150
- labels.set(rid, (0, footnotes_utils_1.getAlphaOrderIndices)(index++));
151
- });
152
- });
153
- return { inlineFootnotes, labels, footnotes, footnoteElement };
154
- };
155
- exports.buildPluginState = buildPluginState;
156
140
  exports.default = (props) => {
157
141
  return new prosemirror_state_1.Plugin({
158
142
  key: exports.footnotesKey,
@@ -161,60 +145,25 @@ exports.default = (props) => {
161
145
  return (0, exports.buildPluginState)(instance.doc);
162
146
  },
163
147
  apply(tr, value, oldState, newState) {
164
- const prevState = exports.footnotesKey.getState(oldState);
165
- if (!tr.docChanged && prevState) {
166
- return prevState;
167
- }
168
148
  return (0, exports.buildPluginState)(newState.doc);
169
149
  },
170
150
  },
171
151
  appendTransaction(transactions, oldState, newState) {
172
- const { inlineFootnotes: oldInlineFootnoteNodes } = exports.footnotesKey.getState(oldState);
173
- const { inlineFootnotes: inlineFootnoteNodes, footnotes, labels, footnoteElement, } = exports.footnotesKey.getState(newState);
174
- const prevIds = oldInlineFootnoteNodes.map(([node]) => node.attrs.rids);
175
- const newIds = inlineFootnoteNodes.map(([node]) => node.attrs.rids);
176
- const initTransaction = transactions.find((t) => t.getMeta('INIT'));
177
- if (!footnoteElement || (!initTransaction && (0, lodash_1.isEqual)(prevIds, newIds))) {
152
+ const { nodes: oldInlineFootnoteNodes } = exports.footnotesKey.getState(oldState);
153
+ const { nodes: inlineFootnoteNodes, labels } = exports.footnotesKey.getState(newState);
154
+ if ((0, lodash_1.isEqual)(inlineFootnoteNodes, oldInlineFootnoteNodes)) {
178
155
  return null;
179
156
  }
180
157
  const { tr } = newState;
181
- const footnotesReordered = [];
182
- const footnotesRest = new Map(footnotes);
183
158
  inlineFootnoteNodes.forEach(([node, pos]) => {
184
159
  const footnote = node;
185
160
  const contents = footnote.attrs.rids
186
- .map((rid) => {
187
- const currentfNode = footnotesRest.get(rid);
188
- if (currentfNode) {
189
- footnotesReordered.push(currentfNode[0]);
190
- footnotesRest.delete(rid);
191
- }
192
- return labels.get(rid);
193
- })
161
+ .map((rid) => labels.get(rid))
194
162
  .join('');
195
163
  if (footnote.attrs.contents !== contents) {
196
164
  tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, footnote.attrs), { rids: footnote.attrs.rids, contents }));
197
165
  }
198
166
  });
199
- footnotesRest.forEach(([node]) => footnotesReordered.push(node));
200
- const newFElement = transform_1.schema.nodes.footnotes_element.create(footnoteElement[0].attrs, footnotesReordered);
201
- if (newFElement && footnotes.size > 0) {
202
- tr.replaceWith(footnoteElement[1], footnoteElement[1] + footnoteElement[0].nodeSize, newFElement);
203
- }
204
- const prevSelection = newState.selection;
205
- const selectedFootnote = (0, prosemirror_utils_1.findParentNodeClosestToPos)(prevSelection.$anchor, (node) => (0, transform_1.isFootnoteNode)(node));
206
- if (selectedFootnote && footnotes.size > 0) {
207
- let newFootnotePos = 0;
208
- for (let i = 0; i < footnotesReordered.length; i++) {
209
- const node = footnotesReordered[i];
210
- newFootnotePos += node.nodeSize;
211
- if (node.attrs.id === selectedFootnote.node.attrs.id) {
212
- break;
213
- }
214
- }
215
- tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, footnoteElement[1] + newFootnotePos));
216
- }
217
- (0, track_changes_plugin_1.skipTracking)(tr);
218
167
  return tr;
219
168
  },
220
169
  props: {
@@ -257,7 +206,7 @@ exports.default = (props) => {
257
206
  }
258
207
  }
259
208
  if (!((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.textContent)) {
260
- decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, placeholder_1.placeholderWidget)('Type new footnote here')));
209
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, placeholder_1.placeholderWidget)('Add new note here')));
261
210
  }
262
211
  if (tableInlineFootnoteIds &&
263
212
  !tableInlineFootnoteIds.has(node.attrs.id)) {
@@ -62,13 +62,12 @@ exports.default = (props) => {
62
62
  key: exports.highlightKey,
63
63
  state: {
64
64
  init: (tr, state) => buildPluginState(state.doc),
65
- apply: (tr, value) => {
65
+ apply: (tr) => {
66
66
  const meta = tr.getMeta(exports.highlightKey);
67
- if (meta && exports.SET_COMMENT in meta) {
68
- props.setComment(meta[exports.SET_COMMENT]);
69
- }
70
- else if (!tr.docChanged || tr.step.length === 0) {
71
- return value;
67
+ if (meta) {
68
+ if (exports.SET_COMMENT in meta) {
69
+ props.setComment(meta[exports.SET_COMMENT]);
70
+ }
72
71
  }
73
72
  return buildPluginState(tr.doc);
74
73
  },
@@ -94,6 +94,7 @@ exports.default = (props) => new prosemirror_state_1.Plugin({
94
94
  return buildSelectedSuggestionDecoration(suggestionId, state, props);
95
95
  }
96
96
  if (tr.getMeta(exports.CLEAR_SUGGESTION_ID)) {
97
+ props.setEditorSelectedSuggestion(undefined);
97
98
  return prosemirror_view_1.DecorationSet.empty;
98
99
  }
99
100
  return value;
@@ -104,11 +105,8 @@ exports.default = (props) => new prosemirror_state_1.Plugin({
104
105
  const nodeClicked = view.state.doc.nodeAt(pos);
105
106
  const trackChangesData = nodeClicked && getTrackChangesData(nodeClicked);
106
107
  if (!trackChangesData) {
107
- setTimeout(() => {
108
- const newTr = view.state.tr.setMeta(exports.CLEAR_SUGGESTION_ID, true);
109
- view.dispatch(newTr);
110
- props.setEditorSelectedSuggestion(undefined);
111
- });
108
+ view.dispatch(view.state.tr.setMeta(exports.CLEAR_SUGGESTION_ID, true));
109
+ props.setEditorSelectedSuggestion(undefined);
112
110
  }
113
111
  },
114
112
  decorations: (state) => exports.selectedSuggestionKey.getState(state),
@@ -124,9 +122,7 @@ const buildSelectedSuggestionDecoration = (suggestionId, state, props) => {
124
122
  decorations.push(decoration(change.from, change.to, {
125
123
  class: 'selected-suggestion',
126
124
  }));
127
- setTimeout(() => {
128
- props.setEditorSelectedSuggestion(change.id);
129
- }, 0);
125
+ props.setEditorSelectedSuggestion(change.id);
130
126
  }
131
127
  return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
132
128
  };
@@ -14,9 +14,6 @@ const isInlineFootnoteChange = (step, oldState, newState) => {
14
14
  exports.default = () => {
15
15
  return new prosemirror_state_1.Plugin({
16
16
  appendTransaction(transactions, oldState, newState) {
17
- if (!transactions.find((tr) => tr.docChanged)) {
18
- return null;
19
- }
20
17
  const tableInlineFootnoteChange = transactions.find((tr) => tr.steps.find((s, i) => {
21
18
  var _a;
22
19
  if (s instanceof prosemirror_transform_1.ReplaceStep) {
@@ -62,7 +62,7 @@ class BaseNodeView {
62
62
  }
63
63
  };
64
64
  }
65
- setDomAttrs(node, element, omit = ['contents']) {
65
+ setDomAttrs(node, element, omit = []) {
66
66
  Object.keys(node.attrs || {}).forEach((attr) => {
67
67
  if (!omit.includes(attr)) {
68
68
  element.setAttribute(attr, node.attrs[attr]);
@@ -49,9 +49,6 @@ class BibliographyElementBlockView extends block_view_1.default {
49
49
  this.showPopper = (id) => {
50
50
  this.props.popper.destroy();
51
51
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
52
- if (!bib) {
53
- return;
54
- }
55
52
  const componentProps = {
56
53
  items: Array.from(bib.bibliographyItems.values()),
57
54
  citationCounts: bib.citationCounts,
@@ -143,9 +140,6 @@ class BibliographyElementBlockView extends block_view_1.default {
143
140
  const can = this.props.getCapabilities();
144
141
  const wrapper = document.createElement('div');
145
142
  wrapper.classList.add('contents');
146
- if (!bib) {
147
- return;
148
- }
149
143
  const [meta, bibliography] = bib.provider.makeBibliography();
150
144
  for (let i = 0; i < bibliography.length; i++) {
151
145
  const id = meta.entry_ids[i];
@@ -40,9 +40,6 @@ class CitationView extends base_node_view_1.BaseNodeView {
40
40
  };
41
41
  this.updateContents = () => {
42
42
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
43
- if (!bib) {
44
- return;
45
- }
46
43
  const classes = [
47
44
  'citation',
48
45
  ...(0, track_changes_utils_1.getChangeClasses)(this.node.attrs.dataTracked),
@@ -90,9 +90,6 @@ class CitationEditableView extends citation_1.CitationView {
90
90
  this.showPopper = () => {
91
91
  this.props.popper.destroy();
92
92
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
93
- if (!bib) {
94
- return;
95
- }
96
93
  const can = this.props.getCapabilities();
97
94
  const attrs = (0, track_changes_utils_1.getActualAttrs)(this.node);
98
95
  const rids = attrs.rids;
@@ -155,9 +152,6 @@ class CitationEditableView extends citation_1.CitationView {
155
152
  };
156
153
  this.handleCite = (items) => {
157
154
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
158
- if (!bib) {
159
- return;
160
- }
161
155
  const attrs = (0, track_changes_utils_1.getActualAttrs)(this.node);
162
156
  const rids = [...attrs.rids];
163
157
  items = items.filter((i) => !rids.includes(i.id));
@@ -28,9 +28,7 @@ class FootnotesElementView extends block_view_1.default {
28
28
  this.elementType = 'div';
29
29
  this.checkEditability = () => {
30
30
  var _a, _b;
31
- const editable = this.props.getCapabilities().editArticle && this.node.childCount
32
- ? 'true'
33
- : 'false';
31
+ const editable = this.node.childCount ? 'true' : 'false';
34
32
  (_a = this.contentDOM) === null || _a === void 0 ? void 0 : _a.setAttribute('contenteditable', editable);
35
33
  (_b = this.dom) === null || _b === void 0 ? void 0 : _b.setAttribute('contenteditable', editable);
36
34
  };
@@ -21,7 +21,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.InlineFootnoteView = void 0;
22
22
  const style_guide_1 = require("@manuscripts/style-guide");
23
23
  const transform_1 = require("@manuscripts/transform");
24
- const prosemirror_state_1 = require("prosemirror-state");
25
24
  const prosemirror_utils_1 = require("prosemirror-utils");
26
25
  const commands_1 = require("../commands");
27
26
  const track_changes_utils_1 = require("../lib/track-changes-utils");
@@ -34,7 +33,6 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
34
33
  super(...arguments);
35
34
  this.findParentTableElement = () => (0, prosemirror_utils_1.findParentNodeClosestToPos)(this.view.state.doc.resolve(this.getPos()), (node) => node.type === transform_1.schema.nodes.table_element);
36
35
  this.handleClick = () => {
37
- var _a;
38
36
  if ((0, track_changes_utils_1.isDeleted)(this.node)) {
39
37
  return;
40
38
  }
@@ -51,24 +49,11 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
51
49
  this.props.popper.show(this.dom, this.popperContainer, 'bottom-end');
52
50
  }
53
51
  else {
54
- if ((_a = this.node.attrs.rids) === null || _a === void 0 ? void 0 : _a.length) {
55
- let nodePos = undefined;
56
- this.view.state.doc.descendants((node, pos) => {
57
- if (node.attrs.id === this.node.attrs.rids[0]) {
58
- nodePos = pos;
59
- }
60
- });
61
- if (nodePos && this.props.dispatch) {
62
- const sel = prosemirror_state_1.TextSelection.near(this.view.state.doc.resolve(nodePos + 1));
63
- this.props.dispatch(this.view.state.tr.setSelection(sel).scrollIntoView());
64
- }
65
- }
52
+ this.props.history.push(Object.assign(Object.assign({}, this.props.history.location), { hash: '#' + this.node.attrs.rid }));
66
53
  }
67
54
  };
68
55
  this.updateContents = () => {
69
- const node = this.node;
70
- this.dom.setAttribute('rids', node.attrs.rids.join(','));
71
- this.dom.setAttribute('contents', node.attrs.contents);
56
+ this.setDomAttrs(this.node, this.dom);
72
57
  this.dom.className = [
73
58
  'footnote',
74
59
  ...(0, track_changes_utils_1.getChangeClasses)(this.node.attrs.dataTracked),
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { ObjectTypes } from '@manuscripts/json-schema';
17
17
  import { skipTracking } from '@manuscripts/track-changes-plugin';
18
- import { buildComment, generateID, isElementNodeType, isFootnoteNode, isInBibliographySection, isListNode, isParagraphNode, isSectionNodeType, schema, } from '@manuscripts/transform';
18
+ import { buildComment, generateID, isElementNodeType, isInBibliographySection, isListNode, isSectionNodeType, schema, } from '@manuscripts/transform';
19
19
  import { NodeRange } from 'prosemirror-model';
20
20
  import { wrapInList } from 'prosemirror-schema-list';
21
21
  import { NodeSelection, TextSelection, } from 'prosemirror-state';
@@ -308,24 +308,12 @@ export const insertInlineFootnote = (kind) => (state, dispatch) => {
308
308
  let selectionPos;
309
309
  if (!footnotesSection) {
310
310
  const section = state.schema.nodes.footnotes_section.create({}, [
311
- state.schema.nodes.section_title.create({}, state.schema.text('Footnotes')),
311
+ state.schema.nodes.section_title.create({}, state.schema.text('Notes')),
312
312
  state.schema.nodes.footnotes_element.create({}, footnote),
313
313
  ]);
314
314
  const backmatter = findChildrenByType(tr.doc, schema.nodes.backmatter)[0];
315
- const sectionPos = backmatter.pos + 1;
316
- tr.insert(sectionPos, section);
317
- let footnotePos = 0;
318
- section.descendants((n, pos) => {
319
- if (isFootnoteNode(n)) {
320
- footnotePos = pos;
321
- n.descendants((childNode, childPos) => {
322
- if (isParagraphNode(childNode)) {
323
- footnotePos += childPos;
324
- }
325
- });
326
- }
327
- });
328
- selectionPos = sectionPos + footnotePos;
315
+ tr.insert(backmatter.pos + 1, section);
316
+ selectionPos = backmatter.pos + section.nodeSize - 3;
329
317
  }
330
318
  else {
331
319
  const footnoteElement = findChildrenByType(footnotesSection.node, schema.nodes.footnotes_element);
@@ -337,7 +325,7 @@ export const insertInlineFootnote = (kind) => (state, dispatch) => {
337
325
  selectionPos = pos + 2;
338
326
  }
339
327
  if (dispatch && selectionPos) {
340
- const selection = TextSelection.near(tr.doc.resolve(selectionPos));
328
+ const selection = TextSelection.create(tr.doc, selectionPos);
341
329
  dispatch(tr.setSelection(selection).scrollIntoView());
342
330
  }
343
331
  return true;
@@ -149,5 +149,5 @@ export const DraggableTree = ({ tree, view, depth, can, }) => {
149
149
  React.createElement(OutlineItemLink, { to: `#${node.attrs.id}` },
150
150
  React.createElement(OutlineItemIcon, null, nodeTypeIcon(node.type)),
151
151
  React.createElement(OutlineItemLinkText, { className: `outline-text-${node.type.name} ${isDeletedItem && 'deleted'}` }, itemText(node))))),
152
- items.length ? (React.createElement("div", { className: `subtree ${isOpen ? '' : 'collapsed'}` }, items.map((subtree) => (React.createElement(DraggableTree, { key: subtree.node.attrs.id, tree: subtree, view: view, depth: !tree.parent ? depth : depth + 1, can: can }))))) : null));
152
+ items.length ? (React.createElement("div", { className: `subtree ${isOpen ? '' : 'collapsed'}` }, items.map((subtree, index) => (React.createElement(DraggableTree, { key: subtree.node.attrs.id || 'subtree-' + index, tree: subtree, view: view, depth: !tree.parent ? depth : depth + 1, can: can }))))) : null));
153
153
  };
@@ -25,23 +25,17 @@ export const createEditorState = (props) => EditorState.create({
25
25
  schema,
26
26
  plugins: plugins(props),
27
27
  });
28
- export const createEditorView = (props, root, state, dispatch) => {
29
- const view = new EditorView(root, {
30
- state,
31
- editable: () => props.getCapabilities().editArticle,
32
- scrollMargin: {
33
- top: 100,
34
- bottom: 100,
35
- left: 0,
36
- right: 0,
37
- },
38
- dispatchTransaction: dispatch,
39
- nodeViews: views(props, dispatch),
40
- attributes: props.attributes,
41
- transformPasted,
42
- });
43
- const tr = view.state.tr.setMeta('INIT', true);
44
- const nextState = view.state.apply(tr);
45
- view.updateState(nextState);
46
- return view;
47
- };
28
+ export const createEditorView = (props, root, state, dispatch) => new EditorView(root, {
29
+ state,
30
+ editable: () => props.getCapabilities().editArticle,
31
+ scrollMargin: {
32
+ top: 100,
33
+ bottom: 100,
34
+ left: 0,
35
+ right: 0,
36
+ },
37
+ dispatchTransaction: dispatch,
38
+ nodeViews: views(props, dispatch),
39
+ attributes: props.attributes,
40
+ transformPasted,
41
+ });