@manuscripts/body-editor 1.13.27 → 1.13.28

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.
@@ -80,6 +80,9 @@ const orderTableFootnotes = (tr, footnotesElementWithPos, position) => {
80
80
  .map(({ node }) => node);
81
81
  const { node: footnotesElement, pos } = footnotesElementWithPos;
82
82
  const footnoteElementPos = position + pos + 1;
83
+ if (orderedFootnotes.length === 0) {
84
+ return;
85
+ }
83
86
  const oldDataTracked = footnotesElement.attrs.dataTracked;
84
87
  (0, track_changes_plugin_1.skipTracking)(tr.replaceWith(tr.mapping.map(footnoteElementPos), tr.mapping.map(footnoteElementPos + footnotesElement.nodeSize), prosemirror_model_1.Fragment.fromArray(orderedFootnotes)));
85
88
  if (oldDataTracked) {
@@ -73,7 +73,7 @@ const deleteFootnoteWidget = (node, props, id, tableElement, tableElementFooter)
73
73
  };
74
74
  deleteBtn.addEventListener('mousedown', () => {
75
75
  const handleDelete = () => {
76
- let tr = view.state.tr;
76
+ const tr = view.state.tr;
77
77
  const pos = getPos();
78
78
  if (node.type === transform_1.schema.nodes.general_table_footnote && pos) {
79
79
  if (tableElementFooter &&
@@ -88,18 +88,29 @@ const deleteFootnoteWidget = (node, props, id, tableElement, tableElementFooter)
88
88
  if (node.type === transform_1.schema.nodes.footnote && pos) {
89
89
  const targetNode = tableElement ? tableElement.node : view.state.doc;
90
90
  const inlineFootnotes = (0, footnotes_utils_1.getInlineFootnotes)(id, targetNode);
91
- const nodeWithPos = (0, prosemirror_utils_1.findParentNodeClosestToPos)(tr.doc.resolve(pos), (node) => node.type === transform_1.schema.nodes.footnote);
92
- if (nodeWithPos) {
93
- const { pos: fnPos, node: fnNode } = nodeWithPos;
94
- view.dispatch(tr.delete(fnPos, fnPos + fnNode.nodeSize));
91
+ const footnotesElement = (0, prosemirror_utils_1.findParentNodeClosestToPos)(tr.doc.resolve(pos), (node) => node.type === transform_1.schema.nodes.footnotes_element);
92
+ if ((footnotesElement === null || footnotesElement === void 0 ? void 0 : footnotesElement.node.childCount) === 1 &&
93
+ (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.node.childCount) === 1) {
94
+ const { pos: fnPos, node: fnNode } = tableElementFooter;
95
+ tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
96
+ }
97
+ else if ((footnotesElement === null || footnotesElement === void 0 ? void 0 : footnotesElement.node.childCount) === 1) {
98
+ const { pos: fnPos, node: fnNode } = footnotesElement;
99
+ tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
100
+ }
101
+ else {
102
+ const footnote = (0, prosemirror_utils_1.findParentNodeClosestToPos)(tr.doc.resolve(pos), (node) => node.type === transform_1.schema.nodes.footnote);
103
+ if (footnote) {
104
+ const { pos: fnPos, node: fnNode } = footnote;
105
+ tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
106
+ }
95
107
  }
96
108
  if (inlineFootnotes) {
97
- tr = view.state.tr;
98
109
  inlineFootnotes.forEach((footnote) => {
99
110
  const pos = footnote.pos + (tableElement ? tableElement.pos + 1 : 0);
100
111
  if (footnote.node.attrs.rids.length > 1) {
101
112
  const updatedRids = footnote.node.attrs.rids.filter((rid) => rid !== id);
102
- tr.setNodeMarkup(tr.mapping.map(pos + 1), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
113
+ tr.setNodeMarkup(tr.mapping.map(pos), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
103
114
  }
104
115
  else {
105
116
  tr.delete(tr.mapping.map(pos), tr.mapping.map(pos + footnote.node.nodeSize));
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MATHJAX_VERSION = exports.VERSION = void 0;
4
- exports.VERSION = '1.13.27';
4
+ exports.VERSION = '1.13.28';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -74,6 +74,9 @@ export const orderTableFootnotes = (tr, footnotesElementWithPos, position) => {
74
74
  .map(({ node }) => node);
75
75
  const { node: footnotesElement, pos } = footnotesElementWithPos;
76
76
  const footnoteElementPos = position + pos + 1;
77
+ if (orderedFootnotes.length === 0) {
78
+ return;
79
+ }
77
80
  const oldDataTracked = footnotesElement.attrs.dataTracked;
78
81
  skipTracking(tr.replaceWith(tr.mapping.map(footnoteElementPos), tr.mapping.map(footnoteElementPos + footnotesElement.nodeSize), Fragment.fromArray(orderedFootnotes)));
79
82
  if (oldDataTracked) {
@@ -66,7 +66,7 @@ const deleteFootnoteWidget = (node, props, id, tableElement, tableElementFooter)
66
66
  };
67
67
  deleteBtn.addEventListener('mousedown', () => {
68
68
  const handleDelete = () => {
69
- let tr = view.state.tr;
69
+ const tr = view.state.tr;
70
70
  const pos = getPos();
71
71
  if (node.type === schema.nodes.general_table_footnote && pos) {
72
72
  if (tableElementFooter &&
@@ -81,18 +81,29 @@ const deleteFootnoteWidget = (node, props, id, tableElement, tableElementFooter)
81
81
  if (node.type === schema.nodes.footnote && pos) {
82
82
  const targetNode = tableElement ? tableElement.node : view.state.doc;
83
83
  const inlineFootnotes = getInlineFootnotes(id, targetNode);
84
- const nodeWithPos = findParentNodeClosestToPos(tr.doc.resolve(pos), (node) => node.type === schema.nodes.footnote);
85
- if (nodeWithPos) {
86
- const { pos: fnPos, node: fnNode } = nodeWithPos;
87
- view.dispatch(tr.delete(fnPos, fnPos + fnNode.nodeSize));
84
+ const footnotesElement = findParentNodeClosestToPos(tr.doc.resolve(pos), (node) => node.type === schema.nodes.footnotes_element);
85
+ if ((footnotesElement === null || footnotesElement === void 0 ? void 0 : footnotesElement.node.childCount) === 1 &&
86
+ (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.node.childCount) === 1) {
87
+ const { pos: fnPos, node: fnNode } = tableElementFooter;
88
+ tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
89
+ }
90
+ else if ((footnotesElement === null || footnotesElement === void 0 ? void 0 : footnotesElement.node.childCount) === 1) {
91
+ const { pos: fnPos, node: fnNode } = footnotesElement;
92
+ tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
93
+ }
94
+ else {
95
+ const footnote = findParentNodeClosestToPos(tr.doc.resolve(pos), (node) => node.type === schema.nodes.footnote);
96
+ if (footnote) {
97
+ const { pos: fnPos, node: fnNode } = footnote;
98
+ tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
99
+ }
88
100
  }
89
101
  if (inlineFootnotes) {
90
- tr = view.state.tr;
91
102
  inlineFootnotes.forEach((footnote) => {
92
103
  const pos = footnote.pos + (tableElement ? tableElement.pos + 1 : 0);
93
104
  if (footnote.node.attrs.rids.length > 1) {
94
105
  const updatedRids = footnote.node.attrs.rids.filter((rid) => rid !== id);
95
- tr.setNodeMarkup(tr.mapping.map(pos + 1), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
106
+ tr.setNodeMarkup(tr.mapping.map(pos), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
96
107
  }
97
108
  else {
98
109
  tr.delete(tr.mapping.map(pos), tr.mapping.map(pos + footnote.node.nodeSize));
@@ -1,2 +1,2 @@
1
- export const VERSION = '1.13.27';
1
+ export const VERSION = '1.13.28';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.13.27";
1
+ export declare const VERSION = "1.13.28";
2
2
  export declare const MATHJAX_VERSION = "3.2.2";
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.13.27",
4
+ "version": "1.13.28",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",