@manuscripts/body-editor 2.5.6-date-fix.0 → 2.5.7

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 (93) hide show
  1. package/dist/cjs/commands.js +121 -211
  2. package/dist/cjs/components/views/DeleteFootnoteDialog.js +2 -2
  3. package/dist/cjs/components/views/FootnotesSelector.js +18 -19
  4. package/dist/cjs/configs/ManuscriptsEditor.js +2 -1
  5. package/dist/cjs/configs/editor-plugins.js +0 -2
  6. package/dist/cjs/configs/editor-views.js +6 -4
  7. package/dist/cjs/icons.js +8 -0
  8. package/dist/cjs/index.js +1 -0
  9. package/dist/cjs/lib/comments.js +5 -1
  10. package/dist/cjs/lib/context-menu.js +21 -101
  11. package/dist/cjs/lib/doc.js +27 -4
  12. package/dist/cjs/lib/footnotes.js +31 -122
  13. package/dist/cjs/lib/plugins.js +8 -0
  14. package/dist/cjs/menus.js +1 -1
  15. package/dist/cjs/plugins/affiliations.js +2 -1
  16. package/dist/cjs/plugins/comments.js +10 -8
  17. package/dist/cjs/plugins/footnotes.js +188 -0
  18. package/dist/cjs/plugins/persist.js +4 -4
  19. package/dist/cjs/plugins/placeholder.js +19 -12
  20. package/dist/cjs/testing/default-editor-data.js +1 -1
  21. package/dist/cjs/testing/setup-editor.js +1 -0
  22. package/dist/cjs/versions.js +1 -1
  23. package/dist/cjs/views/editable_block.js +1 -1
  24. package/dist/cjs/views/footnote.js +117 -13
  25. package/dist/cjs/views/footnotes_element.js +10 -2
  26. package/dist/cjs/views/general_table_footnote.js +83 -0
  27. package/dist/cjs/views/inline_footnote.js +74 -124
  28. package/dist/cjs/views/table_element_footer.js +2 -5
  29. package/dist/es/commands.js +118 -207
  30. package/dist/es/components/views/DeleteFootnoteDialog.js +2 -2
  31. package/dist/es/components/views/FootnotesSelector.js +18 -19
  32. package/dist/es/configs/ManuscriptsEditor.js +2 -1
  33. package/dist/es/configs/editor-plugins.js +0 -2
  34. package/dist/es/configs/editor-views.js +4 -2
  35. package/dist/es/icons.js +5 -0
  36. package/dist/es/index.js +1 -0
  37. package/dist/es/lib/comments.js +3 -0
  38. package/dist/es/lib/context-menu.js +24 -101
  39. package/dist/es/lib/doc.js +25 -4
  40. package/dist/es/lib/footnotes.js +28 -116
  41. package/dist/es/lib/plugins.js +4 -0
  42. package/dist/es/menus.js +1 -1
  43. package/dist/es/plugins/affiliations.js +2 -1
  44. package/dist/es/plugins/comments.js +11 -9
  45. package/dist/es/plugins/footnotes.js +185 -0
  46. package/dist/es/plugins/persist.js +4 -4
  47. package/dist/es/plugins/placeholder.js +20 -11
  48. package/dist/es/testing/default-editor-data.js +1 -1
  49. package/dist/es/testing/setup-editor.js +1 -0
  50. package/dist/es/versions.js +1 -1
  51. package/dist/es/views/editable_block.js +1 -1
  52. package/dist/es/views/footnote.js +118 -13
  53. package/dist/es/views/footnotes_element.js +10 -2
  54. package/dist/es/views/general_table_footnote.js +76 -0
  55. package/dist/es/views/inline_footnote.js +78 -128
  56. package/dist/es/views/table_element_footer.js +4 -5
  57. package/dist/types/commands.d.ts +10 -14
  58. package/dist/types/components/views/DeleteFootnoteDialog.d.ts +2 -2
  59. package/dist/types/components/views/FootnotesSelector.d.ts +7 -7
  60. package/dist/types/configs/editor-views.d.ts +22 -35
  61. package/dist/types/icons.d.ts +2 -0
  62. package/dist/types/index.d.ts +1 -0
  63. package/dist/types/lib/comments.d.ts +1 -0
  64. package/dist/types/lib/context-menu.d.ts +1 -3
  65. package/dist/types/lib/doc.d.ts +2 -0
  66. package/dist/types/lib/footnotes.d.ts +8 -19
  67. package/dist/types/lib/plugins.d.ts +3 -0
  68. package/dist/types/plugins/{footnotes/index.d.ts → footnotes.d.ts} +14 -11
  69. package/dist/types/plugins/placeholder.d.ts +0 -2
  70. package/dist/types/versions.d.ts +1 -1
  71. package/dist/types/views/footnote.d.ts +14 -6
  72. package/dist/types/views/footnotes_element.d.ts +1 -0
  73. package/dist/types/views/{table_element_footer_editable.d.ts → general_table_footnote.d.ts} +11 -2
  74. package/dist/types/views/inline_footnote.d.ts +8 -14
  75. package/dist/types/views/table_element_footer.d.ts +2 -2
  76. package/package.json +3 -3
  77. package/styles/Editor.css +35 -64
  78. package/dist/cjs/plugins/footnotes/index.js +0 -215
  79. package/dist/cjs/plugins/footnotes/widgets.js +0 -136
  80. package/dist/cjs/plugins/table-footnote.js +0 -46
  81. package/dist/cjs/views/footnote_editable.js +0 -21
  82. package/dist/cjs/views/footnotes_element_editable.js +0 -22
  83. package/dist/cjs/views/table_element_footer_editable.js +0 -20
  84. package/dist/es/plugins/footnotes/index.js +0 -211
  85. package/dist/es/plugins/footnotes/widgets.js +0 -127
  86. package/dist/es/plugins/table-footnote.js +0 -44
  87. package/dist/es/views/footnote_editable.js +0 -19
  88. package/dist/es/views/footnotes_element_editable.js +0 -20
  89. package/dist/es/views/table_element_footer_editable.js +0 -18
  90. package/dist/types/plugins/footnotes/widgets.d.ts +0 -22
  91. package/dist/types/plugins/table-footnote.d.ts +0 -3
  92. package/dist/types/views/footnote_editable.d.ts +0 -51
  93. package/dist/types/views/footnotes_element_editable.d.ts +0 -51
@@ -15,7 +15,6 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.TableElementFooterView = void 0;
19
18
  const base_node_view_1 = require("./base_node_view");
20
19
  const creators_1 = require("./creators");
21
20
  class TableElementFooterView extends base_node_view_1.BaseNodeView {
@@ -28,10 +27,8 @@ class TableElementFooterView extends base_node_view_1.BaseNodeView {
28
27
  this.dom = document.createElement('div');
29
28
  this.dom.classList.add('table-footer');
30
29
  this.dom.setAttribute('id', this.node.attrs.id);
31
- this.contentDOM = document.createElement('div');
32
- this.dom.appendChild(this.contentDOM);
30
+ this.contentDOM = this.dom;
33
31
  };
34
32
  }
35
33
  }
36
- exports.TableElementFooterView = TableElementFooterView;
37
- exports.default = (0, creators_1.createNodeView)(TableElementFooterView);
34
+ exports.default = (0, creators_1.createEditableNodeView)(TableElementFooterView);
@@ -15,23 +15,22 @@
15
15
  */
16
16
  import { buildContribution } from '@manuscripts/json-schema';
17
17
  import { skipTracking } from '@manuscripts/track-changes-plugin';
18
- import { generateNodeID, isElementNodeType, isFootnoteNode, isListNode, isParagraphNode, isSectionNodeType, schema, } from '@manuscripts/transform';
18
+ import { generateNodeID, isElementNodeType, isListNode, isSectionNodeType, isTableElementNode, schema, } from '@manuscripts/transform';
19
19
  import { Fragment, NodeRange, } from 'prosemirror-model';
20
20
  import { wrapInList } from 'prosemirror-schema-list';
21
21
  import { NodeSelection, TextSelection, } from 'prosemirror-state';
22
22
  import { addColSpan, addColumnAfter, addColumnBefore, addRow, CellSelection, selectedRect, } from 'prosemirror-tables';
23
23
  import { findWrapping, liftTarget, ReplaceAroundStep, } from 'prosemirror-transform';
24
- import { findChildrenByType, findParentNodeOfType, hasParentNodeOfType, } from 'prosemirror-utils';
24
+ import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos, hasParentNodeOfType, } from 'prosemirror-utils';
25
25
  import { getCommentKey, getCommentRange } from './lib/comments';
26
- import { findBackmatter, findBibliographySection, findBody, insertSupplementsNode, } from './lib/doc';
27
- import { getNewFootnotePos } from './lib/footnotes';
26
+ import { findBackmatter, findBibliographySection, findBody, insertFootnotesSection, insertSupplementsNode, } from './lib/doc';
27
+ import { createFootnote, findFootnotesContainerNode, getFootnotesElementState, } from './lib/footnotes';
28
28
  import { findWordBoundaries, isNodeOfType, nearestAncestor, } from './lib/helpers';
29
29
  import { sectionTitles } from './lib/section-titles';
30
30
  import { isDeleted } from './lib/track-changes-utils';
31
31
  import { findParentNodeWithId, getChildOfType, getMatchingChild, } from './lib/utils';
32
32
  import { setCommentSelection } from './plugins/comments';
33
33
  import { getEditorProps } from './plugins/editor-props';
34
- import { footnotesKey } from './plugins/footnotes';
35
34
  import { checkForCompletion } from './plugins/section_title/autocompletion';
36
35
  export const addToStart = (state, dispatch) => {
37
36
  const { selection } = state;
@@ -152,45 +151,35 @@ export const createBlock = (nodeType, position, state, dispatch, attrs) => {
152
151
  dispatch(tr.setSelection(selection).scrollIntoView());
153
152
  }
154
153
  };
155
- export const undoFootnoteDelete = (tr, footnote, position) => {
156
- const updatedAttrs = Object.assign(Object.assign({}, footnote.node.attrs), { dataTracked: null });
157
- tr.setNodeMarkup(position, undefined, updatedAttrs, footnote.node.marks);
158
- };
159
- export const insertGeneralFootnote = (tableElementNode, position, view, tableElementFooter) => {
160
- const { state, dispatch } = view;
161
- const paragraph = state.schema.nodes.paragraph.create({
162
- placeholder: 'Add general note here',
163
- });
164
- const generalNote = state.schema.nodes.general_table_footnote.create({}, [
165
- paragraph,
166
- ]);
167
- const tableColGroup = findChildrenByType(tableElementNode, schema.nodes.table_colgroup)[0];
168
- const table = findChildrenByType(tableElementNode, schema.nodes.table)[0];
169
- const tr = state.tr;
170
- const pos = (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length)
171
- ? position + tableElementFooter[0].pos + 2
172
- : position +
173
- (!tableColGroup
174
- ? table.pos + table.node.nodeSize
175
- : tableColGroup.pos + tableColGroup.node.nodeSize);
176
- if (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length) {
177
- if (isDeleted(tableElementFooter[0].node)) {
178
- const tableElementFooterPos = tr.mapping.map(position + tableElementFooter[0].pos + 1);
179
- undoFootnoteDelete(tr, tableElementFooter[0], tableElementFooterPos);
180
- }
181
- tr.insert(pos, generalNote);
154
+ export const insertInlineTableFootnote = (state, dispatch) => {
155
+ const $pos = state.selection.$to;
156
+ const table = findParentNodeOfTypeClosestToPos($pos, schema.nodes.table);
157
+ if (!table) {
158
+ return false;
182
159
  }
183
- else {
184
- const tableElementFooter = schema.nodes.table_element_footer.create({
185
- id: generateNodeID(schema.nodes.table_element_footer),
186
- }, [generalNote]);
187
- tr.insert(pos, tableElementFooter);
160
+ if (!dispatch) {
161
+ return true;
188
162
  }
189
- if (dispatch && pos) {
190
- const selection = createSelection(state.schema.nodes.paragraph, pos, tr.doc);
191
- view === null || view === void 0 ? void 0 : view.focus();
192
- dispatch(tr.setSelection(selection).scrollIntoView());
163
+ return insertInlineFootnote(state, dispatch);
164
+ };
165
+ export const insertGeneralTableFootnote = (element, state, dispatch) => {
166
+ const existing = findChildrenByType(element[0], schema.nodes.general_table_footnote);
167
+ if (existing.length) {
168
+ return false;
169
+ }
170
+ if (!dispatch) {
171
+ return true;
193
172
  }
173
+ const tr = state.tr;
174
+ const footer = insertTableElementFooter(tr, element);
175
+ const pos = footer.pos + 1;
176
+ const node = schema.nodes.general_table_footnote.create({}, [
177
+ schema.nodes.paragraph.create(),
178
+ ]);
179
+ tr.insert(pos, node);
180
+ const selection = TextSelection.create(tr.doc, pos + 1);
181
+ tr.setSelection(selection).scrollIntoView();
182
+ dispatch(tr);
194
183
  };
195
184
  export const insertFigure = (file, state, dispatch) => {
196
185
  const position = findBlockInsertPosition(state);
@@ -380,81 +369,99 @@ export const insertInlineEquation = (state, dispatch) => {
380
369
  }
381
370
  return true;
382
371
  };
383
- export const createFootnote = (state, kind) => {
384
- return schema.nodes.footnote.createAndFill({
385
- id: generateNodeID(schema.nodes.footnote),
386
- kind,
387
- });
372
+ export const insertTableElementFooter = (tr, table) => {
373
+ const footer = findChildrenByType(table[0], schema.nodes.table_element_footer)[0];
374
+ if (footer) {
375
+ const pos = tr.mapping.map(table[1] + footer.pos + 1);
376
+ if (isDeleted(footer.node)) {
377
+ reinstateNode(tr, footer.node, pos);
378
+ }
379
+ return {
380
+ node: footer.node,
381
+ pos,
382
+ };
383
+ }
384
+ const pos = tr.mapping.map(table[1] + table[0].nodeSize - 2);
385
+ const node = schema.nodes.table_element_footer.create();
386
+ tr.insert(pos, node);
387
+ return {
388
+ node,
389
+ pos,
390
+ };
388
391
  };
389
- export const insertFootnote = (state, tr, footnote) => {
390
- const footnotesSection = findChildrenByType(tr.doc, schema.nodes.footnotes_section)[0];
391
- let selectionPos = 0;
392
- if (!footnotesSection) {
393
- const section = state.schema.nodes.footnotes_section.create({}, [
394
- state.schema.nodes.section_title.create({}, state.schema.text('Footnotes')),
395
- state.schema.nodes.footnotes_element.create({}, footnote),
396
- ]);
397
- const backmatter = findChildrenByType(tr.doc, schema.nodes.backmatter)[0];
398
- const sectionPos = backmatter.pos + 1;
399
- tr.insert(sectionPos, section);
400
- let footnotePos = 0;
401
- section.descendants((n, pos) => {
402
- if (isFootnoteNode(n)) {
403
- footnotePos = pos;
404
- n.descendants((childNode, childPos) => {
405
- if (isParagraphNode(childNode)) {
406
- footnotePos += childPos;
407
- }
408
- });
409
- }
410
- });
411
- selectionPos = sectionPos + footnotePos;
392
+ export const insertFootnotesElement = (tr, container) => {
393
+ let pos;
394
+ if (isTableElementNode(container[0])) {
395
+ const footer = insertTableElementFooter(tr, container);
396
+ pos = footer.pos + footer.node.nodeSize - 1;
412
397
  }
413
398
  else {
414
- const footnoteElement = findChildrenByType(footnotesSection.node, schema.nodes.footnotes_element).pop();
415
- if (footnoteElement) {
416
- if (isDeleted(footnoteElement.node)) {
417
- const footnoteElementPos = footnotesSection.pos + footnoteElement.pos + 1;
418
- undoFootnoteDelete(tr, footnoteElement, footnoteElementPos);
419
- const updatedAttrs = Object.assign(Object.assign({}, footnoteElement.node.attrs), { dataTracked: null });
420
- tr.setNodeMarkup(footnoteElementPos, undefined, updatedAttrs, footnoteElement.node.marks);
421
- }
422
- const pos = footnotesSection.pos +
423
- footnoteElement.pos +
424
- footnoteElement.node.nodeSize -
425
- 1;
426
- tr.insert(pos, footnote);
427
- selectionPos = pos + 2;
399
+ const section = insertFootnotesSection(tr);
400
+ pos = section.pos + section.node.nodeSize - 1;
401
+ }
402
+ const node = schema.nodes.footnotes_element.create();
403
+ tr.insert(pos, node);
404
+ return [node, pos];
405
+ };
406
+ export const insertInlineFootnote = (state, dispatch) => {
407
+ const pos = state.selection.to;
408
+ const tr = state.tr;
409
+ const container = findFootnotesContainerNode(state.doc, pos);
410
+ const fn = getFootnotesElementState(state, container.node.attrs.id);
411
+ const hasUnusedFootnotes = fn && fn.unusedFootnoteIDs.size > 0;
412
+ const footnote = !hasUnusedFootnotes && createFootnote();
413
+ const node = schema.nodes.inline_footnote.create({
414
+ rids: footnote ? [footnote.attrs.id] : [],
415
+ });
416
+ tr.insert(pos, node);
417
+ if (footnote) {
418
+ let element;
419
+ if (fn) {
420
+ element = [fn.element[0], tr.mapping.map(fn.element[1])];
428
421
  }
429
422
  else {
430
- const footnoteElement = schema.nodes.footnotes_element.create({}, footnote);
431
- const pos = footnotesSection.pos + footnotesSection.node.nodeSize - 1;
432
- tr.insert(pos, footnoteElement);
433
- selectionPos = pos + 2;
423
+ element = insertFootnotesElement(tr, [container.node, container.pos]);
424
+ }
425
+ if (isDeleted(element[0])) {
426
+ reinstateNode(tr, element[0], element[1]);
434
427
  }
428
+ const fnPos = element[1] + element[0].nodeSize - 1;
429
+ tr.insert(fnPos, footnote);
430
+ const selection = TextSelection.create(tr.doc, fnPos + 2);
431
+ tr.setSelection(selection).scrollIntoView();
435
432
  }
436
- if (selectionPos) {
437
- const selection = TextSelection.near(tr.doc.resolve(selectionPos));
433
+ else {
434
+ const selection = NodeSelection.create(tr.doc, pos);
438
435
  tr.setSelection(selection).scrollIntoView();
439
436
  }
440
- return tr;
437
+ if (dispatch) {
438
+ dispatch(tr);
439
+ }
440
+ return true;
441
441
  };
442
- export const insertInlineFootnote = (kind) => (state, dispatch) => {
443
- const fnState = footnotesKey.getState(state);
444
- const hasUnusedNodes = fnState && fnState.unusedFootnotes.size > 0;
445
- const footnote = !hasUnusedNodes
446
- ? createFootnote(state, kind)
447
- : null;
448
- const insertedAt = state.selection.to;
449
- let tr = state.tr;
450
- const node = state.schema.nodes.inline_footnote.create({
451
- rids: footnote ? [footnote.attrs.id] : [],
452
- });
453
- tr.insert(insertedAt, node);
454
- if (footnote) {
455
- tr = insertFootnote(state, tr, footnote);
442
+ const reinstateNode = (tr, node, pos) => {
443
+ const attrs = Object.assign(Object.assign({}, node.attrs), { dataTracked: null });
444
+ tr.setNodeMarkup(pos, null, attrs);
445
+ };
446
+ export const insertBoxElement = (state, dispatch) => {
447
+ const selection = state.selection;
448
+ const isBody = hasParentNodeOfType(schema.nodes.body)(selection);
449
+ const isBoxText = hasParentNodeOfType(schema.nodes.box_element)(selection);
450
+ if (!isBody || isBoxText) {
451
+ return false;
456
452
  }
457
- if (dispatch) {
453
+ const position = findBlockInsertPosition(state);
454
+ const paragraph = schema.nodes.paragraph.create({});
455
+ const section = schema.nodes.section.createAndFill({}, [
456
+ schema.nodes.section_title.create(),
457
+ paragraph,
458
+ ]);
459
+ const node = schema.nodes.box_element.createAndFill({}, [
460
+ schema.nodes.figcaption.create({}, [schema.nodes.caption_title.create()]),
461
+ section,
462
+ ]);
463
+ if (position && dispatch) {
464
+ const tr = state.tr.insert(position, node);
458
465
  dispatch(tr);
459
466
  }
460
467
  return true;
@@ -930,6 +937,11 @@ export const addInlineComment = (state, dispatch) => {
930
937
  }
931
938
  let from = selection.from;
932
939
  let to = selection.to;
940
+ if (from === to) {
941
+ const result = findWordBoundaries(state, from);
942
+ from = result.from;
943
+ to = result.to;
944
+ }
933
945
  const props = getEditorProps(state);
934
946
  const contribution = buildContribution(props.userID);
935
947
  const attrs = {
@@ -937,7 +949,7 @@ export const addInlineComment = (state, dispatch) => {
937
949
  contents: '',
938
950
  target: node.attrs.id,
939
951
  contributions: [contribution],
940
- originalText: selectedText(),
952
+ originalText: selectedText() || state.doc.textBetween(from, to),
941
953
  selector: {
942
954
  from,
943
955
  to,
@@ -948,11 +960,6 @@ export const addInlineComment = (state, dispatch) => {
948
960
  if (comments) {
949
961
  const pos = comments.pos + 1;
950
962
  const tr = state.tr.insert(pos, comment);
951
- if (from === to) {
952
- const result = findWordBoundaries(state, from);
953
- from = result.from;
954
- to = result.to;
955
- }
956
963
  const start = schema.nodes.highlight_marker.create({
957
964
  id: comment.attrs.id,
958
965
  tid: node.attrs.id,
@@ -974,102 +981,6 @@ export const addInlineComment = (state, dispatch) => {
974
981
  }
975
982
  return false;
976
983
  };
977
- export const insertTableFootnote = (tableElementNode, position, view, inlineFootnote) => {
978
- const { state, dispatch } = view;
979
- const tr = state.tr;
980
- const footnote = schema.nodes.footnote.createAndFill({
981
- id: generateNodeID(schema.nodes.footnote),
982
- kind: 'footnote',
983
- });
984
- const insertedAt = state.selection.to;
985
- let footnoteIndex;
986
- if (inlineFootnote) {
987
- const contents = inlineFootnote.node.attrs.contents.split(',').map(Number);
988
- footnoteIndex = Math.max(...contents) + 1;
989
- tr.setNodeMarkup(inlineFootnote.pos, undefined, {
990
- rids: [...inlineFootnote.node.attrs.rids, footnote.attrs.id],
991
- contents: inlineFootnote.node.attrs.contents + ',' + footnoteIndex,
992
- });
993
- }
994
- else {
995
- const inlineFootnotes = findChildrenByType(tableElementNode, schema.nodes.inline_footnote);
996
- footnoteIndex =
997
- inlineFootnotes.filter(({ pos }) => position + pos <= insertedAt).length +
998
- 1;
999
- const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
1000
- rids: [footnote.attrs.id],
1001
- contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
1002
- });
1003
- tr.insert(insertedAt, inlineFootnoteNode);
1004
- }
1005
- let insertionPos = position;
1006
- const footnotesElement = findChildrenByType(tableElementNode, schema.nodes.footnotes_element).pop();
1007
- if (footnotesElement) {
1008
- if (isDeleted(footnotesElement.node)) {
1009
- const footnotesElementPos = tr.mapping.map(position + footnotesElement.pos + 1);
1010
- undoFootnoteDelete(tr, footnotesElement, footnotesElementPos);
1011
- }
1012
- const footnotePos = getNewFootnotePos(footnotesElement, footnoteIndex);
1013
- insertionPos = tr.mapping.map(position + footnotePos);
1014
- tr.insert(insertionPos, footnote);
1015
- }
1016
- else {
1017
- const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
1018
- const tableElementFooter = findChildrenByType(tableElementNode, schema.nodes.table_element_footer)[0];
1019
- if (tableElementFooter) {
1020
- if (isDeleted(tableElementFooter.node)) {
1021
- const tableElementFooterPos = tr.mapping.map(position + tableElementFooter.pos + 1);
1022
- undoFootnoteDelete(tr, tableElementFooter, tableElementFooterPos);
1023
- }
1024
- const pos = tableElementFooter.pos;
1025
- insertionPos = position + pos + tableElementFooter.node.nodeSize;
1026
- tr.insert(tr.mapping.map(insertionPos), footnoteElement);
1027
- }
1028
- else {
1029
- const tableElementFooter = schema.nodes.table_element_footer.create({
1030
- id: generateNodeID(schema.nodes.table_element_footer),
1031
- }, [footnoteElement]);
1032
- const tableColGroup = findChildrenByType(tableElementNode, schema.nodes.table_colgroup)[0];
1033
- const table = findChildrenByType(tableElementNode, schema.nodes.table)[0];
1034
- if (tableColGroup) {
1035
- insertionPos =
1036
- position + tableColGroup.pos + tableColGroup.node.nodeSize;
1037
- tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
1038
- }
1039
- else {
1040
- insertionPos = position + table.pos + table.node.nodeSize;
1041
- tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
1042
- }
1043
- }
1044
- }
1045
- dispatch(tr);
1046
- const textSelection = TextSelection.near(view.state.tr.doc.resolve(insertionPos + 1));
1047
- view.focus();
1048
- dispatch(view.state.tr.setSelection(textSelection).scrollIntoView());
1049
- };
1050
- export const insertBoxElement = (state, dispatch) => {
1051
- const selection = state.selection;
1052
- const isBody = hasParentNodeOfType(schema.nodes.body)(selection);
1053
- const isBoxText = hasParentNodeOfType(schema.nodes.box_element)(selection);
1054
- if (!isBody || isBoxText) {
1055
- return false;
1056
- }
1057
- const position = findBlockInsertPosition(state);
1058
- const paragraph = schema.nodes.paragraph.create({});
1059
- const section = schema.nodes.section.createAndFill({}, [
1060
- schema.nodes.section_title.create(),
1061
- paragraph,
1062
- ]);
1063
- const BoxElementNode = schema.nodes.box_element.createAndFill({}, [
1064
- schema.nodes.figcaption.create({}, [schema.nodes.caption_title.create()]),
1065
- section,
1066
- ]);
1067
- if (position && dispatch) {
1068
- const tr = state.tr.insert(position, BoxElementNode);
1069
- dispatch(tr);
1070
- }
1071
- return true;
1072
- };
1073
984
  export const addRows = (direction) => (state, dispatch) => {
1074
985
  if (dispatch) {
1075
986
  const { tr } = state;
@@ -1,6 +1,6 @@
1
1
  import { Category, Dialog } from '@manuscripts/style-guide';
2
2
  import React, { useState } from 'react';
3
- export const DeleteFootnoteDialog = ({ footnoteType, footnoteMessage, handleDelete, }) => {
3
+ export const DeleteFootnoteDialog = ({ header, message, handleDelete, }) => {
4
4
  const [isOpen, setOpen] = useState(true);
5
5
  return (React.createElement(Dialog, { className: "delete-footnote-dialog", isOpen: isOpen, actions: {
6
6
  primary: {
@@ -14,5 +14,5 @@ export const DeleteFootnoteDialog = ({ footnoteType, footnoteMessage, handleDele
14
14
  action: () => setOpen(false),
15
15
  title: 'Cancel',
16
16
  },
17
- }, category: Category.confirmation, header: `Delete ${footnoteType}`, message: `${footnoteMessage}` }));
17
+ }, category: Category.confirmation, header: header, message: message }));
18
18
  };
@@ -47,12 +47,12 @@ const AddNewFootnote = styled(ButtonGroup) `
47
47
  }
48
48
  }
49
49
  `;
50
- export const FootnotesSelector = ({ notes, inlineFootnote, onAdd, onInsert, onCancel, addNewLabel }) => {
50
+ export const FootnotesSelector = ({ footnotes, inlineFootnote, labels, onAdd, onInsert, onCancel, }) => {
51
51
  let selectedNotesMap;
52
52
  if (inlineFootnote) {
53
53
  const rids = inlineFootnote.attrs.rids;
54
- const selectedNotes = notes.filter(({ node }) => rids.includes(node.attrs.id));
55
- selectedNotesMap = new Map(selectedNotes.map(({ node }) => [node.attrs.id, node]));
54
+ const selectedNotes = footnotes.filter((node) => rids.includes(node.attrs.id));
55
+ selectedNotesMap = new Map(selectedNotes.map((node) => [node.attrs.id, node]));
56
56
  }
57
57
  const [selections, setSelections] = useState(new Map(selectedNotesMap));
58
58
  const toggleSelection = (item) => {
@@ -70,43 +70,42 @@ export const FootnotesSelector = ({ notes, inlineFootnote, onAdd, onInsert, onCa
70
70
  return selections.has(item.attrs.id);
71
71
  };
72
72
  const handleClick = () => {
73
- return onInsert(notes.filter(({ node }) => selections.has(node.attrs.id)));
73
+ return onInsert(footnotes.filter((node) => selections.has(node.attrs.id)));
74
74
  };
75
75
  return (React.createElement(Container, null,
76
76
  React.createElement(NotesContainer, null,
77
- React.createElement(FootnotesList, { notes: notes, inlineFootnote: inlineFootnote, isSelected: isSelected, onSelect: toggleSelection })),
77
+ React.createElement(FootnotesList, { footnotes: footnotes, inlineFootnote: inlineFootnote, labels: labels, isSelected: isSelected, onSelect: toggleSelection })),
78
78
  React.createElement(Actions, null,
79
79
  React.createElement(AddNewFootnote, null,
80
80
  React.createElement(IconTextButton, { onClick: onAdd },
81
81
  React.createElement(AddNewIcon, null),
82
- addNewLabel || 'Add new')),
82
+ "Add new")),
83
83
  React.createElement(ButtonGroup, null,
84
84
  React.createElement(SecondaryButton, { onClick: onCancel }, "Cancel"),
85
85
  React.createElement(PrimaryButton, { onClick: handleClick, disabled: selections.size === 0 && !inlineFootnote }, inlineFootnote ? 'Update' : 'Insert')))));
86
86
  };
87
- const FootnotesList = ({ notes, isSelected, onSelect, inlineFootnote }) => {
87
+ const FootnotesList = ({ footnotes, inlineFootnote, labels, isSelected, onSelect }) => {
88
+ const rids = inlineFootnote === null || inlineFootnote === void 0 ? void 0 : inlineFootnote.attrs.rids;
88
89
  const selectedNotes = [];
89
90
  const remainingNotes = [];
90
- notes.forEach((note) => {
91
- const isNoteSelected = inlineFootnote && inlineFootnote.attrs.rids.includes(note.node.attrs.id);
91
+ footnotes.forEach((footnote) => {
92
+ const isNoteSelected = rids === null || rids === void 0 ? void 0 : rids.includes(footnote.attrs.id);
92
93
  if (isNoteSelected) {
93
- selectedNotes.push(note);
94
+ selectedNotes.push(footnote);
94
95
  }
95
96
  else {
96
- remainingNotes.push(note);
97
+ remainingNotes.push(footnote);
97
98
  }
98
99
  });
99
100
  return (React.createElement(NotesListContainer, null,
100
- selectedNotes.map((note) => (React.createElement(FootnoteItem, { key: note.node.attrs.id, note: note, isSelected: isSelected, onSelect: onSelect }))),
101
+ selectedNotes.map((footnote) => (React.createElement(FootnoteItem, { key: footnote.attrs.id, footnote: footnote, label: labels.get(footnote.attrs.id), isSelected: isSelected, onSelect: onSelect }))),
101
102
  selectedNotes.length > 0 && remainingNotes.length > 0 && React.createElement(Separator, null),
102
- remainingNotes.map((note) => (React.createElement(FootnoteItem, { key: note.node.attrs.id, note: note, isSelected: isSelected, onSelect: onSelect })))));
103
+ remainingNotes.map((footnote) => (React.createElement(FootnoteItem, { key: footnote.attrs.id, footnote: footnote, label: labels.get(footnote.attrs.id), isSelected: isSelected, onSelect: onSelect })))));
103
104
  };
104
- const FootnoteItem = ({ note, isSelected, onSelect }) => {
105
- var _a;
106
- const { node, index } = note;
107
- return (React.createElement(FootnoteItemContainer, { onClick: () => onSelect(node) },
108
- React.createElement(StatusIcon, null, isSelected(node) ? (React.createElement(AddedIcon, { "data-cy": 'plus-icon-ok' })) : (React.createElement(AddIcon, { "data-cy": 'plus-icon' }))),
109
- React.createElement(NoteText, null, (index ? index + '. ' : '') + ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.textContent))));
105
+ const FootnoteItem = ({ footnote, label, isSelected, onSelect }) => {
106
+ return (React.createElement(FootnoteItemContainer, { onClick: () => onSelect(footnote) },
107
+ React.createElement(StatusIcon, null, isSelected(footnote) ? (React.createElement(AddedIcon, { "data-cy": 'plus-icon-ok' })) : (React.createElement(AddIcon, { "data-cy": 'plus-icon' }))),
108
+ React.createElement(NoteText, null, (label ? label + '. ' : '') + footnote.textContent)));
110
109
  };
111
110
  const Separator = styled.div `
112
111
  height: 0;
@@ -20,6 +20,7 @@ import { EditorView } from 'prosemirror-view';
20
20
  import { clipboardParser } from '../clipboard';
21
21
  import { handleScrollToBibliographyItem } from '../lib/helpers';
22
22
  import { handlePaste, transformPasted } from '../lib/paste';
23
+ import { INIT_META } from '../lib/plugins';
23
24
  import plugins from './editor-plugins';
24
25
  import views from './editor-views';
25
26
  export const createEditorState = (props) => EditorState.create({
@@ -51,7 +52,7 @@ export const createEditorView = (props, root, state, dispatch) => {
51
52
  }
52
53
  },
53
54
  });
54
- const tr = view.state.tr.setMeta('INIT', true);
55
+ const tr = view.state.tr.setMeta(INIT_META, true);
55
56
  const nextState = view.state.apply(tr);
56
57
  view.updateState(nextState);
57
58
  return view;
@@ -36,7 +36,6 @@ import section_title from '../plugins/section_title';
36
36
  import section_category from '../plugins/section-category';
37
37
  import sections from '../plugins/sections';
38
38
  import selected_suggestion from '../plugins/selected-suggestion';
39
- import table_footnote from '../plugins/table-footnote';
40
39
  import table_editing_fix from '../plugins/tables-cursor-fix';
41
40
  import toc from '../plugins/toc';
42
41
  import rules from '../rules';
@@ -68,7 +67,6 @@ export default (props) => {
68
67
  tableEditing(),
69
68
  selected_suggestion(),
70
69
  footnotes(props),
71
- table_footnote(),
72
70
  editorProps(props),
73
71
  doi(),
74
72
  section_category(props),
@@ -26,8 +26,9 @@ import equation from '../views/equation_editable';
26
26
  import equationElement from '../views/equation_element_editable';
27
27
  import figure from '../views/figure_editable';
28
28
  import figureElement from '../views/figure_element_editable';
29
- import footnote from '../views/footnote_editable';
29
+ import footnote from '../views/footnote';
30
30
  import footnotesElement from '../views/footnotes_element';
31
+ import generalTableFootnote from '../views/general_table_footnote';
31
32
  import inlineEquation from '../views/inline_equation_editable';
32
33
  import inlineFootnote from '../views/inline_footnote_editable';
33
34
  import keyword from '../views/keyword';
@@ -44,7 +45,7 @@ import sectionLabel from '../views/section_label';
44
45
  import sectionTitle from '../views/section_title_editable';
45
46
  import tableCell from '../views/table_cell';
46
47
  import tableElement from '../views/table_element_editable';
47
- import tableElementFooter from '../views/table_element_footer_editable';
48
+ import tableElementFooter from '../views/table_element_footer';
48
49
  import title from '../views/title_editable';
49
50
  import tocElement from '../views/toc_element_editable';
50
51
  export default (props, dispatch) => {
@@ -63,6 +64,7 @@ export default (props, dispatch) => {
63
64
  figure_element: figureElement(props, dispatch),
64
65
  footnote: footnote(props),
65
66
  footnotes_element: footnotesElement(props),
67
+ general_table_footnote: generalTableFootnote(props, dispatch),
66
68
  inline_equation: inlineEquation(props),
67
69
  inline_footnote: inlineFootnote(props, dispatch),
68
70
  keyword: keyword(props, dispatch),
@@ -0,0 +1,5 @@
1
+ import { AlertIcon, DeleteIcon } from '@manuscripts/style-guide';
2
+ import { createElement } from 'react';
3
+ import { renderToStaticMarkup } from 'react-dom/server';
4
+ export const alertIcon = renderToStaticMarkup(createElement(AlertIcon));
5
+ export const deleteIcon = renderToStaticMarkup(createElement(DeleteIcon));
package/dist/es/index.js CHANGED
@@ -25,6 +25,7 @@ export { PopperManager } from './lib/popper';
25
25
  export * from './toolbar';
26
26
  export * from './lib/comments';
27
27
  export * from './lib/files';
28
+ export * from './lib/footnotes';
28
29
  export * from './lib/doc';
29
30
  export * from './plugins/comments';
30
31
  export { selectedSuggestionKey } from './plugins/selected-suggestion';
@@ -1,4 +1,7 @@
1
1
  export const isNodeComment = (c) => !c.range;
2
+ export const isReply = (comment) => {
3
+ return comment.node.attrs.target.includes('MPCommentAnnotation');
4
+ };
2
5
  export const getCommentKey = (comment, range, target) => {
3
6
  if (!range) {
4
7
  return target.attrs.id;