@manuscripts/body-editor 1.7.26-LEAN-3429-1 → 1.7.27

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.
@@ -29,7 +29,6 @@ const helpers_1 = require("./lib/helpers");
29
29
  const track_changes_utils_1 = require("./lib/track-changes-utils");
30
30
  const utils_1 = require("./lib/utils");
31
31
  const comment_annotation_1 = require("./plugins/comment_annotation");
32
- const footnotes_utils_1 = require("./plugins/footnotes/footnotes-utils");
33
32
  const highlight_1 = require("./plugins/highlight");
34
33
  const markActive = (type) => (state) => {
35
34
  const { from, $from, to, empty } = state.selection;
@@ -727,38 +726,37 @@ const updateCommentAnnotationState = (state, dispatch) => {
727
726
  }
728
727
  };
729
728
  exports.updateCommentAnnotationState = updateCommentAnnotationState;
730
- const insertTableFootnote = (node, position, view) => {
729
+ const insertTableFootnote = (node, position, state, dispatch) => {
731
730
  var _a;
732
- const { state, dispatch } = view;
733
731
  const footnote = state.schema.nodes.footnote.createAndFill({
734
732
  id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Footnote),
735
733
  kind: 'footnote',
736
734
  });
737
735
  const insertedAt = state.selection.to;
738
736
  const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote);
739
- const footnoteIndex = inlineFootnotes.filter(({ pos }) => position + pos <= insertedAt).length + 1;
737
+ const labels = inlineFootnotes.map((nodeWithPos) => nodeWithPos.node.attrs.contents);
740
738
  const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
741
739
  rids: [footnote.attrs.id],
742
- contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
740
+ contents: labels.length ? Math.max(...labels) + 1 : 1,
743
741
  });
744
742
  const tr = state.tr;
745
743
  tr.insert(insertedAt, inlineFootnoteNode);
746
- let insertionPos = position;
744
+ let insertionPos;
747
745
  const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.footnotes_element).pop();
748
746
  if (footnotesElement &&
749
747
  !(0, track_changes_utils_1.isDeleted)(footnotesElement.node) &&
750
748
  !(0, track_changes_utils_1.isRejectedInsert)(footnotesElement.node)) {
751
- const footnotePos = (0, footnotes_utils_1.getNewFootnotePos)(footnotesElement, footnoteIndex);
752
- insertionPos = tr.mapping.map(position + footnotePos);
749
+ const pos = footnotesElement.pos;
750
+ insertionPos = position + pos + footnotesElement.node.nodeSize + 1;
753
751
  tr.insert(insertionPos, footnote);
754
752
  }
755
753
  else {
756
754
  const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
757
- const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_element_footer)[0];
758
- if (tableElementFooter) {
759
- const pos = tableElementFooter.pos;
760
- insertionPos = position + pos + tableElementFooter.node.nodeSize;
761
- tr.insert(tr.mapping.map(insertionPos), footnoteElement);
755
+ const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_element_footer);
756
+ if (tableElementFooter.length) {
757
+ const pos = tableElementFooter[0].pos;
758
+ insertionPos = position + pos + tableElementFooter[0].node.nodeSize + 1;
759
+ tr.insert(insertionPos, footnoteElement);
762
760
  }
763
761
  else {
764
762
  const tableElementFooter = transform_1.schema.nodes.table_element_footer.create({
@@ -767,21 +765,21 @@ const insertTableFootnote = (node, position, view) => {
767
765
  const tableColGroup = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_colgroup)[0];
768
766
  if (tableColGroup) {
769
767
  insertionPos =
770
- position + tableColGroup.pos + tableColGroup.node.nodeSize;
771
- tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
768
+ position + tableColGroup.pos + tableColGroup.node.nodeSize + 2;
769
+ tr.insert(insertionPos, tableElementFooter);
772
770
  }
773
771
  else {
774
772
  const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
775
773
  if (tableSize) {
776
- insertionPos = position + tableSize;
777
- tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
774
+ insertionPos = position + tableSize + 2;
775
+ tr.insert(insertionPos, tableElementFooter);
778
776
  }
779
777
  }
780
778
  }
781
779
  }
782
- dispatch(tr);
783
- const textSelection = prosemirror_state_1.TextSelection.near(view.state.tr.doc.resolve(insertionPos + 1));
784
- view.focus();
785
- dispatch(view.state.tr.setSelection(textSelection).scrollIntoView());
780
+ if (dispatch && insertionPos) {
781
+ const nodeSelection = prosemirror_state_1.NodeSelection.create(tr.doc, insertionPos);
782
+ dispatch(tr.setSelection(nodeSelection));
783
+ }
786
784
  };
787
785
  exports.insertTableFootnote = insertTableFootnote;
@@ -38,7 +38,6 @@ const persist_1 = __importDefault(require("../plugins/persist"));
38
38
  const placeholder_1 = __importDefault(require("../plugins/placeholder"));
39
39
  const sections_1 = __importDefault(require("../plugins/sections"));
40
40
  const selected_suggestion_ui_1 = __importDefault(require("../plugins/selected-suggestion-ui"));
41
- const table_footnote_1 = __importDefault(require("../plugins/table-footnote"));
42
41
  const tables_cursor_fix_1 = __importDefault(require("../plugins/tables-cursor-fix"));
43
42
  const toc_1 = __importDefault(require("../plugins/toc"));
44
43
  const rules_1 = __importDefault(require("../rules"));
@@ -70,7 +69,6 @@ exports.default = (props) => {
70
69
  (0, highlight_1.default)(props),
71
70
  (0, selected_suggestion_ui_1.default)(props),
72
71
  (0, footnotes_1.default)(),
73
- (0, table_footnote_1.default)(),
74
72
  ];
75
73
  if (props.collabProvider) {
76
74
  allPlugins.push((0, prosemirror_collab_1.collab)({ version: props.collabProvider.currentVersion }));
@@ -23,7 +23,6 @@ const style_guide_1 = require("@manuscripts/style-guide");
23
23
  const transform_1 = require("@manuscripts/transform");
24
24
  const prosemirror_utils_1 = require("prosemirror-utils");
25
25
  const commands_1 = require("../commands");
26
- const footnotes_utils_1 = require("../plugins/footnotes/footnotes-utils");
27
26
  const ReactSubView_1 = __importDefault(require("../views/ReactSubView"));
28
27
  const popper_1 = require("./popper");
29
28
  const track_changes_utils_1 = require("./track-changes-utils");
@@ -188,45 +187,35 @@ class ContextMenu {
188
187
  if (isInTable) {
189
188
  menu.appendChild(this.createMenuSection((section) => {
190
189
  section.appendChild(this.createMenuItem('Add Reference Note', () => {
191
- var _a;
192
- const footnotesElementWithPos = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.footnotes_element).pop();
193
- if (!footnotesElementWithPos ||
194
- (0, track_changes_utils_1.isDeleted)(footnotesElementWithPos.node) ||
195
- (0, track_changes_utils_1.isRejectedInsert)(footnotesElementWithPos.node)) {
196
- (0, commands_1.insertTableFootnote)(this.node, this.getPos(), this.view);
190
+ var _a, _b;
191
+ const footnotesElement = (_a = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.footnotes_element).pop()) === null || _a === void 0 ? void 0 : _a.node;
192
+ if (!footnotesElement ||
193
+ (0, track_changes_utils_1.isDeleted)(footnotesElement) ||
194
+ (0, track_changes_utils_1.isRejectedInsert)(footnotesElement)) {
195
+ const { state, dispatch } = this.view;
196
+ (0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
197
197
  }
198
198
  else {
199
- const tablesFootnoteLabels = (0, footnotes_utils_1.buildTableFootnoteLabels)(this.node);
200
- const footnotesWithPos = (0, prosemirror_utils_1.findChildrenByType)(footnotesElementWithPos.node, transform_1.schema.nodes.footnote);
201
- const footnotes = footnotesWithPos.map((nodeWithPos) => ({
202
- node: nodeWithPos.node,
203
- index: tablesFootnoteLabels.get(nodeWithPos.node.attrs.id),
204
- }));
199
+ const footnotes = (0, prosemirror_utils_1.findChildrenByType)(footnotesElement, transform_1.schema.nodes.footnote).map((nodeWithPos) => {
200
+ return nodeWithPos.node;
201
+ });
205
202
  const targetDom = this.view.domAtPos(this.view.state.selection.from);
206
203
  if (targetDom.node instanceof Element && this.props) {
207
204
  const popperContainer = (0, ReactSubView_1.default)(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), style_guide_1.TableFootnotesSelector, {
208
205
  notes: footnotes,
209
206
  onAdd: () => {
210
207
  var _a;
211
- (0, commands_1.insertTableFootnote)(this.node, this.getPos(), this.view);
208
+ const { state, dispatch } = this.view;
209
+ (0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
212
210
  (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
213
211
  },
214
212
  onInsert: (notes) => {
215
213
  var _a;
216
214
  const insertedAt = this.view.state.selection.to;
217
- let inlineFootnoteIndex = 1;
218
- this.view.state.doc
219
- .slice(this.getPos(), insertedAt)
220
- .content.descendants((node) => {
221
- if (node.type === transform_1.schema.nodes.inline_footnote) {
222
- inlineFootnoteIndex++;
223
- return false;
224
- }
225
- });
226
215
  const node = this.view.state.schema.nodes.inline_footnote.create({
227
- rids: notes.map(({ node }) => node.attrs.id),
216
+ rids: notes.map((note) => note.attrs.id),
228
217
  contents: notes
229
- .map(({ index }) => index ? index : inlineFootnoteIndex)
218
+ .map((note) => footnotes.indexOf(note) + 1)
230
219
  .join(),
231
220
  });
232
221
  const tr = this.view.state.tr;
@@ -239,7 +228,7 @@ class ContextMenu {
239
228
  (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
240
229
  },
241
230
  }, this.node, this.getPos, this.view, 'table-footnote-editor');
242
- (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.show(targetDom.node, popperContainer, 'bottom-end');
231
+ (_b = this.props) === null || _b === void 0 ? void 0 : _b.popper.show(targetDom.node, popperContainer, 'bottom-end');
243
232
  }
244
233
  }
245
234
  }));
@@ -15,10 +15,8 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.updateTableInlineFootnoteLabels = exports.orderTableFootnotes = exports.buildTableFootnoteLabels = exports.getNewFootnotePos = exports.findTableInlineFootnoteIds = void 0;
19
- const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
18
+ exports.findTableInlineFootnoteIds = void 0;
20
19
  const transform_1 = require("@manuscripts/transform");
21
- const prosemirror_model_1 = require("prosemirror-model");
22
20
  const prosemirror_utils_1 = require("prosemirror-utils");
23
21
  const findTableInlineFootnoteIds = ($pos) => {
24
22
  var _a;
@@ -30,67 +28,3 @@ const findTableInlineFootnoteIds = ($pos) => {
30
28
  : []);
31
29
  };
32
30
  exports.findTableInlineFootnoteIds = findTableInlineFootnoteIds;
33
- const getNewFootnotePos = (footnotesElement, footnoteIndex) => {
34
- let newFootnotePos = footnotesElement.pos + footnotesElement.node.nodeSize - 1;
35
- footnotesElement.node.descendants((node, pos, parent, index) => {
36
- if ((0, transform_1.isFootnoteNode)(node)) {
37
- if (footnoteIndex === ++index) {
38
- newFootnotePos = footnotesElement.pos + pos + (index === 1 ? 2 : 1);
39
- }
40
- }
41
- });
42
- return newFootnotePos;
43
- };
44
- exports.getNewFootnotePos = getNewFootnotePos;
45
- const buildTableFootnoteLabels = (node) => {
46
- const labels = new Map((0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.footnote).map((node) => [
47
- node.node.attrs.id,
48
- undefined,
49
- ]));
50
- let index = 0;
51
- (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote)
52
- .map(({ node }) => node.attrs.rids)
53
- .flat()
54
- .map((rid) => {
55
- if (!labels.get(rid)) {
56
- labels.set(rid, String(++index));
57
- }
58
- });
59
- return labels;
60
- };
61
- exports.buildTableFootnoteLabels = buildTableFootnoteLabels;
62
- const orderTableFootnotes = (tr, footnotesElementWithPos, position) => {
63
- const tablesFootnoteLabels = (0, exports.buildTableFootnoteLabels)(tr.doc.nodeAt(tr.mapping.map(position)));
64
- const footnotes = (0, prosemirror_utils_1.findChildrenByType)(footnotesElementWithPos.node, transform_1.schema.nodes.footnote).map((nodeWithPos) => ({
65
- node: nodeWithPos.node,
66
- index: tablesFootnoteLabels.get(nodeWithPos.node.attrs.id),
67
- }));
68
- const orderedFootnotes = [...footnotes]
69
- .sort((a, b) => {
70
- if (a.index !== undefined && b.index !== undefined) {
71
- return Number.parseInt(a.index) - Number.parseInt(b.index);
72
- }
73
- else {
74
- return a.index === undefined ? 1 : -1;
75
- }
76
- })
77
- .map(({ node }) => node);
78
- const { node: footnotesElement, pos } = footnotesElementWithPos;
79
- const footnoteElementPos = position + pos;
80
- return (0, track_changes_plugin_1.skipTracking)(tr.replaceWith(tr.mapping.map(footnoteElementPos), tr.mapping.map(footnoteElementPos + footnotesElement.nodeSize), prosemirror_model_1.Fragment.fromArray(orderedFootnotes)));
81
- };
82
- exports.orderTableFootnotes = orderTableFootnotes;
83
- const updateTableInlineFootnoteLabels = (tr, table) => {
84
- const labels = (0, exports.buildTableFootnoteLabels)(table.node);
85
- (0, prosemirror_utils_1.findChildrenByType)(table.node, transform_1.schema.nodes.inline_footnote).map(({ node, pos }) => {
86
- const contents = node.attrs.rids
87
- .map((rid) => labels.get(rid))
88
- .join(',');
89
- if (contents !== node.attrs.contents &&
90
- tr.doc.nodeAt(tr.mapping.map(table.pos + pos + 1))) {
91
- tr.setNodeMarkup(tr.mapping.map(table.pos + pos + 1), undefined, Object.assign(Object.assign({}, node.attrs), { rids: node.attrs.rids, contents }));
92
- }
93
- });
94
- return tr;
95
- };
96
- exports.updateTableInlineFootnoteLabels = updateTableInlineFootnoteLabels;
@@ -26,7 +26,6 @@ import { isNodeOfType, nearestAncestor } from './lib/helpers';
26
26
  import { isDeleted, isRejectedInsert } from './lib/track-changes-utils';
27
27
  import { findParentNodeWithId, getChildOfType } from './lib/utils';
28
28
  import { commentAnnotation } from './plugins/comment_annotation';
29
- import { getNewFootnotePos } from './plugins/footnotes/footnotes-utils';
30
29
  import { highlightKey, SET_COMMENT } from './plugins/highlight';
31
30
  export const markActive = (type) => (state) => {
32
31
  const { from, $from, to, empty } = state.selection;
@@ -690,38 +689,37 @@ export const updateCommentAnnotationState = (state, dispatch) => {
690
689
  dispatch(tr);
691
690
  }
692
691
  };
693
- export const insertTableFootnote = (node, position, view) => {
692
+ export const insertTableFootnote = (node, position, state, dispatch) => {
694
693
  var _a;
695
- const { state, dispatch } = view;
696
694
  const footnote = state.schema.nodes.footnote.createAndFill({
697
695
  id: generateID(ObjectTypes.Footnote),
698
696
  kind: 'footnote',
699
697
  });
700
698
  const insertedAt = state.selection.to;
701
699
  const inlineFootnotes = findChildrenByType(node, schema.nodes.inline_footnote);
702
- const footnoteIndex = inlineFootnotes.filter(({ pos }) => position + pos <= insertedAt).length + 1;
700
+ const labels = inlineFootnotes.map((nodeWithPos) => nodeWithPos.node.attrs.contents);
703
701
  const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
704
702
  rids: [footnote.attrs.id],
705
- contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
703
+ contents: labels.length ? Math.max(...labels) + 1 : 1,
706
704
  });
707
705
  const tr = state.tr;
708
706
  tr.insert(insertedAt, inlineFootnoteNode);
709
- let insertionPos = position;
707
+ let insertionPos;
710
708
  const footnotesElement = findChildrenByType(node, schema.nodes.footnotes_element).pop();
711
709
  if (footnotesElement &&
712
710
  !isDeleted(footnotesElement.node) &&
713
711
  !isRejectedInsert(footnotesElement.node)) {
714
- const footnotePos = getNewFootnotePos(footnotesElement, footnoteIndex);
715
- insertionPos = tr.mapping.map(position + footnotePos);
712
+ const pos = footnotesElement.pos;
713
+ insertionPos = position + pos + footnotesElement.node.nodeSize + 1;
716
714
  tr.insert(insertionPos, footnote);
717
715
  }
718
716
  else {
719
717
  const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
720
- const tableElementFooter = findChildrenByType(node, schema.nodes.table_element_footer)[0];
721
- if (tableElementFooter) {
722
- const pos = tableElementFooter.pos;
723
- insertionPos = position + pos + tableElementFooter.node.nodeSize;
724
- tr.insert(tr.mapping.map(insertionPos), footnoteElement);
718
+ const tableElementFooter = findChildrenByType(node, schema.nodes.table_element_footer);
719
+ if (tableElementFooter.length) {
720
+ const pos = tableElementFooter[0].pos;
721
+ insertionPos = position + pos + tableElementFooter[0].node.nodeSize + 1;
722
+ tr.insert(insertionPos, footnoteElement);
725
723
  }
726
724
  else {
727
725
  const tableElementFooter = schema.nodes.table_element_footer.create({
@@ -730,20 +728,20 @@ export const insertTableFootnote = (node, position, view) => {
730
728
  const tableColGroup = findChildrenByType(node, schema.nodes.table_colgroup)[0];
731
729
  if (tableColGroup) {
732
730
  insertionPos =
733
- position + tableColGroup.pos + tableColGroup.node.nodeSize;
734
- tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
731
+ position + tableColGroup.pos + tableColGroup.node.nodeSize + 2;
732
+ tr.insert(insertionPos, tableElementFooter);
735
733
  }
736
734
  else {
737
735
  const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
738
736
  if (tableSize) {
739
- insertionPos = position + tableSize;
740
- tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
737
+ insertionPos = position + tableSize + 2;
738
+ tr.insert(insertionPos, tableElementFooter);
741
739
  }
742
740
  }
743
741
  }
744
742
  }
745
- dispatch(tr);
746
- const textSelection = TextSelection.near(view.state.tr.doc.resolve(insertionPos + 1));
747
- view.focus();
748
- dispatch(view.state.tr.setSelection(textSelection).scrollIntoView());
743
+ if (dispatch && insertionPos) {
744
+ const nodeSelection = NodeSelection.create(tr.doc, insertionPos);
745
+ dispatch(tr.setSelection(nodeSelection));
746
+ }
749
747
  };
@@ -33,7 +33,6 @@ import persist from '../plugins/persist';
33
33
  import placeholder from '../plugins/placeholder';
34
34
  import sections from '../plugins/sections';
35
35
  import selected_suggestion_ui from '../plugins/selected-suggestion-ui';
36
- import table_footnote from '../plugins/table-footnote';
37
36
  import table_editing_fix from '../plugins/tables-cursor-fix';
38
37
  import toc from '../plugins/toc';
39
38
  import rules from '../rules';
@@ -65,7 +64,6 @@ export default (props) => {
65
64
  highlights(props),
66
65
  selected_suggestion_ui(props),
67
66
  footnotes(),
68
- table_footnote(),
69
67
  ];
70
68
  if (props.collabProvider) {
71
69
  allPlugins.push(collab({ version: props.collabProvider.currentVersion }));
@@ -13,11 +13,10 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { TableFootnotesSelector, } from '@manuscripts/style-guide';
16
+ import { TableFootnotesSelector } from '@manuscripts/style-guide';
17
17
  import { isInBibliographySection, nodeNames, schema, } from '@manuscripts/transform';
18
18
  import { findChildrenByType, hasParentNodeOfType } from 'prosemirror-utils';
19
19
  import { addComment, createBlock, insertGeneralFootnote, insertTableFootnote, } from '../commands';
20
- import { buildTableFootnoteLabels } from '../plugins/footnotes/footnotes-utils';
21
20
  import ReactSubView from '../views/ReactSubView';
22
21
  import { PopperManager } from './popper';
23
22
  import { isDeleted, isRejectedInsert } from './track-changes-utils';
@@ -181,45 +180,35 @@ export class ContextMenu {
181
180
  if (isInTable) {
182
181
  menu.appendChild(this.createMenuSection((section) => {
183
182
  section.appendChild(this.createMenuItem('Add Reference Note', () => {
184
- var _a;
185
- const footnotesElementWithPos = findChildrenByType(this.node, schema.nodes.footnotes_element).pop();
186
- if (!footnotesElementWithPos ||
187
- isDeleted(footnotesElementWithPos.node) ||
188
- isRejectedInsert(footnotesElementWithPos.node)) {
189
- insertTableFootnote(this.node, this.getPos(), this.view);
183
+ var _a, _b;
184
+ const footnotesElement = (_a = findChildrenByType(this.node, schema.nodes.footnotes_element).pop()) === null || _a === void 0 ? void 0 : _a.node;
185
+ if (!footnotesElement ||
186
+ isDeleted(footnotesElement) ||
187
+ isRejectedInsert(footnotesElement)) {
188
+ const { state, dispatch } = this.view;
189
+ insertTableFootnote(this.node, this.getPos(), state, dispatch);
190
190
  }
191
191
  else {
192
- const tablesFootnoteLabels = buildTableFootnoteLabels(this.node);
193
- const footnotesWithPos = findChildrenByType(footnotesElementWithPos.node, schema.nodes.footnote);
194
- const footnotes = footnotesWithPos.map((nodeWithPos) => ({
195
- node: nodeWithPos.node,
196
- index: tablesFootnoteLabels.get(nodeWithPos.node.attrs.id),
197
- }));
192
+ const footnotes = findChildrenByType(footnotesElement, schema.nodes.footnote).map((nodeWithPos) => {
193
+ return nodeWithPos.node;
194
+ });
198
195
  const targetDom = this.view.domAtPos(this.view.state.selection.from);
199
196
  if (targetDom.node instanceof Element && this.props) {
200
197
  const popperContainer = ReactSubView(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), TableFootnotesSelector, {
201
198
  notes: footnotes,
202
199
  onAdd: () => {
203
200
  var _a;
204
- insertTableFootnote(this.node, this.getPos(), this.view);
201
+ const { state, dispatch } = this.view;
202
+ insertTableFootnote(this.node, this.getPos(), state, dispatch);
205
203
  (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
206
204
  },
207
205
  onInsert: (notes) => {
208
206
  var _a;
209
207
  const insertedAt = this.view.state.selection.to;
210
- let inlineFootnoteIndex = 1;
211
- this.view.state.doc
212
- .slice(this.getPos(), insertedAt)
213
- .content.descendants((node) => {
214
- if (node.type === schema.nodes.inline_footnote) {
215
- inlineFootnoteIndex++;
216
- return false;
217
- }
218
- });
219
208
  const node = this.view.state.schema.nodes.inline_footnote.create({
220
- rids: notes.map(({ node }) => node.attrs.id),
209
+ rids: notes.map((note) => note.attrs.id),
221
210
  contents: notes
222
- .map(({ index }) => index ? index : inlineFootnoteIndex)
211
+ .map((note) => footnotes.indexOf(note) + 1)
223
212
  .join(),
224
213
  });
225
214
  const tr = this.view.state.tr;
@@ -232,7 +221,7 @@ export class ContextMenu {
232
221
  (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
233
222
  },
234
223
  }, this.node, this.getPos, this.view, 'table-footnote-editor');
235
- (_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.show(targetDom.node, popperContainer, 'bottom-end');
224
+ (_b = this.props) === null || _b === void 0 ? void 0 : _b.popper.show(targetDom.node, popperContainer, 'bottom-end');
236
225
  }
237
226
  }
238
227
  }));
@@ -13,10 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { skipTracking } from '@manuscripts/track-changes-plugin';
17
- import { isFootnoteNode, schema, } from '@manuscripts/transform';
18
- import { Fragment } from 'prosemirror-model';
19
- import { findChildren, findChildrenByType, findParentNodeClosestToPos, } from 'prosemirror-utils';
16
+ import { schema } from '@manuscripts/transform';
17
+ import { findChildren, findParentNodeClosestToPos } from 'prosemirror-utils';
20
18
  export const findTableInlineFootnoteIds = ($pos) => {
21
19
  var _a;
22
20
  const tableElement = (_a = findParentNodeClosestToPos($pos, (node) => node.type === schema.nodes.table_element)) === null || _a === void 0 ? void 0 : _a.node.firstChild;
@@ -26,63 +24,3 @@ export const findTableInlineFootnoteIds = ($pos) => {
26
24
  .flat()
27
25
  : []);
28
26
  };
29
- export const getNewFootnotePos = (footnotesElement, footnoteIndex) => {
30
- let newFootnotePos = footnotesElement.pos + footnotesElement.node.nodeSize - 1;
31
- footnotesElement.node.descendants((node, pos, parent, index) => {
32
- if (isFootnoteNode(node)) {
33
- if (footnoteIndex === ++index) {
34
- newFootnotePos = footnotesElement.pos + pos + (index === 1 ? 2 : 1);
35
- }
36
- }
37
- });
38
- return newFootnotePos;
39
- };
40
- export const buildTableFootnoteLabels = (node) => {
41
- const labels = new Map(findChildrenByType(node, schema.nodes.footnote).map((node) => [
42
- node.node.attrs.id,
43
- undefined,
44
- ]));
45
- let index = 0;
46
- findChildrenByType(node, schema.nodes.inline_footnote)
47
- .map(({ node }) => node.attrs.rids)
48
- .flat()
49
- .map((rid) => {
50
- if (!labels.get(rid)) {
51
- labels.set(rid, String(++index));
52
- }
53
- });
54
- return labels;
55
- };
56
- export const orderTableFootnotes = (tr, footnotesElementWithPos, position) => {
57
- const tablesFootnoteLabels = buildTableFootnoteLabels(tr.doc.nodeAt(tr.mapping.map(position)));
58
- const footnotes = findChildrenByType(footnotesElementWithPos.node, schema.nodes.footnote).map((nodeWithPos) => ({
59
- node: nodeWithPos.node,
60
- index: tablesFootnoteLabels.get(nodeWithPos.node.attrs.id),
61
- }));
62
- const orderedFootnotes = [...footnotes]
63
- .sort((a, b) => {
64
- if (a.index !== undefined && b.index !== undefined) {
65
- return Number.parseInt(a.index) - Number.parseInt(b.index);
66
- }
67
- else {
68
- return a.index === undefined ? 1 : -1;
69
- }
70
- })
71
- .map(({ node }) => node);
72
- const { node: footnotesElement, pos } = footnotesElementWithPos;
73
- const footnoteElementPos = position + pos;
74
- return skipTracking(tr.replaceWith(tr.mapping.map(footnoteElementPos), tr.mapping.map(footnoteElementPos + footnotesElement.nodeSize), Fragment.fromArray(orderedFootnotes)));
75
- };
76
- export const updateTableInlineFootnoteLabels = (tr, table) => {
77
- const labels = buildTableFootnoteLabels(table.node);
78
- findChildrenByType(table.node, schema.nodes.inline_footnote).map(({ node, pos }) => {
79
- const contents = node.attrs.rids
80
- .map((rid) => labels.get(rid))
81
- .join(',');
82
- if (contents !== node.attrs.contents &&
83
- tr.doc.nodeAt(tr.mapping.map(table.pos + pos + 1))) {
84
- tr.setNodeMarkup(tr.mapping.map(table.pos + pos + 1), undefined, Object.assign(Object.assign({}, node.attrs), { rids: node.attrs.rids, contents }));
85
- }
86
- });
87
- return tr;
88
- };
@@ -19,7 +19,6 @@ import { ManuscriptEditorState, ManuscriptEditorView, ManuscriptMarkType, Manusc
19
19
  import { ResolvedPos } from 'prosemirror-model';
20
20
  import { Command, NodeSelection, Selection, TextSelection, Transaction } from 'prosemirror-state';
21
21
  import { NodeWithPos } from 'prosemirror-utils';
22
- import { EditorView } from 'prosemirror-view';
23
22
  import { EditorAction } from './types';
24
23
  export type Dispatch = (tr: ManuscriptTransaction) => void;
25
24
  export declare const markActive: (type: ManuscriptMarkType) => (state: ManuscriptEditorState) => boolean;
@@ -57,4 +56,4 @@ export declare const deleteHighlightMarkers: (rid: string) => Command;
57
56
  export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch): boolean;
58
57
  export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch, viewNode?: ManuscriptNode, resolvePos?: ResolvedPos): boolean;
59
58
  export declare const updateCommentAnnotationState: (state: ManuscriptEditorState, dispatch?: Dispatch) => void;
60
- export declare const insertTableFootnote: (node: ManuscriptNode, position: number, view: EditorView) => void;
59
+ export declare const insertTableFootnote: (node: ManuscriptNode, position: number, state: ManuscriptEditorState, dispatch?: Dispatch) => void;
@@ -13,12 +13,5 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ManuscriptNode } from '@manuscripts/transform';
17
16
  import { ResolvedPos } from 'prosemirror-model';
18
- import { Transaction } from 'prosemirror-state';
19
- import { ContentNodeWithPos, NodeWithPos } from 'prosemirror-utils';
20
17
  export declare const findTableInlineFootnoteIds: ($pos: ResolvedPos) => Set<string>;
21
- export declare const getNewFootnotePos: (footnotesElement: NodeWithPos, footnoteIndex: number) => number;
22
- export declare const buildTableFootnoteLabels: (node: ManuscriptNode) => Map<string, string | undefined>;
23
- export declare const orderTableFootnotes: (tr: Transaction, footnotesElementWithPos: NodeWithPos, position: number) => Transaction;
24
- export declare const updateTableInlineFootnoteLabels: (tr: Transaction, table: ContentNodeWithPos) => Transaction;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/body-editor",
3
3
  "description": "Prosemirror components for editing and viewing manuscripts",
4
- "version": "1.7.26-LEAN-3429-1",
4
+ "version": "1.7.27",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -31,7 +31,7 @@
31
31
  "@manuscripts/assets": "^0.6.4",
32
32
  "@manuscripts/json-schema": "^2.2.6",
33
33
  "@manuscripts/library": "^1.3.5",
34
- "@manuscripts/style-guide": "1.8.2-LEAN-3429-0",
34
+ "@manuscripts/style-guide": "1.8.2",
35
35
  "@manuscripts/track-changes-plugin": "1.7.8",
36
36
  "@manuscripts/transform": "^2.1.6",
37
37
  "astrocite-eutils": "^0.16.4",
@@ -112,4 +112,4 @@
112
112
  "@types/react": "^17.0.2",
113
113
  "prosemirror-tables": "^1.3.5"
114
114
  }
115
- }
115
+ }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const transform_1 = require("@manuscripts/transform");
4
- const prosemirror_state_1 = require("prosemirror-state");
5
- const prosemirror_transform_1 = require("prosemirror-transform");
6
- const prosemirror_utils_1 = require("prosemirror-utils");
7
- const footnotes_utils_1 = require("./footnotes/footnotes-utils");
8
- const isInlineFootnoteChange = (step, oldState, newState) => {
9
- var _a, _b;
10
- return step.slice.size > 0
11
- ? ((_a = newState.doc.nodeAt(step.from)) === null || _a === void 0 ? void 0 : _a.type) === transform_1.schema.nodes.inline_footnote
12
- : ((_b = oldState.doc.nodeAt(step.from)) === null || _b === void 0 ? void 0 : _b.type) === transform_1.schema.nodes.inline_footnote;
13
- };
14
- exports.default = () => {
15
- return new prosemirror_state_1.Plugin({
16
- appendTransaction(transactions, oldState, newState) {
17
- const tableInlineFootnoteChange = transactions.find((tr) => tr.steps.find((s) => {
18
- var _a;
19
- if (s instanceof prosemirror_transform_1.ReplaceStep) {
20
- const step = s;
21
- const $pos = oldState.doc.resolve(step.from);
22
- return (((_a = $pos.node($pos.depth - 2)) === null || _a === void 0 ? void 0 : _a.type) === transform_1.schema.nodes.table &&
23
- isInlineFootnoteChange(step, oldState, newState));
24
- }
25
- }));
26
- if (!tableInlineFootnoteChange) {
27
- return null;
28
- }
29
- const step = tableInlineFootnoteChange.steps[0];
30
- const tr = newState.tr;
31
- const $pos = newState.doc.resolve(step.from);
32
- const table = (0, prosemirror_utils_1.findParentNodeClosestToPos)($pos, (node) => node.type === transform_1.schema.nodes.table_element);
33
- const footnotesElementWithPos = table &&
34
- (0, prosemirror_utils_1.findChildrenByType)(table.node, transform_1.schema.nodes.footnotes_element).pop();
35
- if (!table || !footnotesElementWithPos) {
36
- return null;
37
- }
38
- (0, footnotes_utils_1.updateTableInlineFootnoteLabels)(tr, table);
39
- (0, footnotes_utils_1.orderTableFootnotes)(tr, footnotesElementWithPos, tr.mapping.map(table.pos));
40
- return tr;
41
- },
42
- });
43
- };
@@ -1,41 +0,0 @@
1
- import { schema } from '@manuscripts/transform';
2
- import { Plugin } from 'prosemirror-state';
3
- import { ReplaceStep } from 'prosemirror-transform';
4
- import { findChildrenByType, findParentNodeClosestToPos, } from 'prosemirror-utils';
5
- import { orderTableFootnotes, updateTableInlineFootnoteLabels, } from './footnotes/footnotes-utils';
6
- const isInlineFootnoteChange = (step, oldState, newState) => {
7
- var _a, _b;
8
- return step.slice.size > 0
9
- ? ((_a = newState.doc.nodeAt(step.from)) === null || _a === void 0 ? void 0 : _a.type) === schema.nodes.inline_footnote
10
- : ((_b = oldState.doc.nodeAt(step.from)) === null || _b === void 0 ? void 0 : _b.type) === schema.nodes.inline_footnote;
11
- };
12
- export default () => {
13
- return new Plugin({
14
- appendTransaction(transactions, oldState, newState) {
15
- const tableInlineFootnoteChange = transactions.find((tr) => tr.steps.find((s) => {
16
- var _a;
17
- if (s instanceof ReplaceStep) {
18
- const step = s;
19
- const $pos = oldState.doc.resolve(step.from);
20
- return (((_a = $pos.node($pos.depth - 2)) === null || _a === void 0 ? void 0 : _a.type) === schema.nodes.table &&
21
- isInlineFootnoteChange(step, oldState, newState));
22
- }
23
- }));
24
- if (!tableInlineFootnoteChange) {
25
- return null;
26
- }
27
- const step = tableInlineFootnoteChange.steps[0];
28
- const tr = newState.tr;
29
- const $pos = newState.doc.resolve(step.from);
30
- const table = findParentNodeClosestToPos($pos, (node) => node.type === schema.nodes.table_element);
31
- const footnotesElementWithPos = table &&
32
- findChildrenByType(table.node, schema.nodes.footnotes_element).pop();
33
- if (!table || !footnotesElementWithPos) {
34
- return null;
35
- }
36
- updateTableInlineFootnoteLabels(tr, table);
37
- orderTableFootnotes(tr, footnotesElementWithPos, tr.mapping.map(table.pos));
38
- return tr;
39
- },
40
- });
41
- };
@@ -1,3 +0,0 @@
1
- import { Plugin } from 'prosemirror-state';
2
- declare const _default: () => Plugin<any>;
3
- export default _default;