@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.
- package/dist/cjs/commands.js +19 -21
- package/dist/cjs/configs/editor-plugins.js +0 -2
- package/dist/cjs/lib/context-menu.js +15 -26
- package/dist/cjs/plugins/footnotes/footnotes-utils.js +1 -67
- package/dist/es/commands.js +19 -21
- package/dist/es/configs/editor-plugins.js +0 -2
- package/dist/es/lib/context-menu.js +16 -27
- package/dist/es/plugins/footnotes/footnotes-utils.js +2 -64
- package/dist/types/commands.d.ts +1 -2
- package/dist/types/plugins/footnotes/footnotes-utils.d.ts +0 -7
- package/package.json +3 -3
- package/dist/cjs/plugins/table-footnote.js +0 -43
- package/dist/es/plugins/table-footnote.js +0 -41
- package/dist/types/plugins/table-footnote.d.ts +0 -3
package/dist/cjs/commands.js
CHANGED
|
@@ -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,
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
752
|
-
insertionPos =
|
|
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)
|
|
758
|
-
if (tableElementFooter) {
|
|
759
|
-
const pos = tableElementFooter.pos;
|
|
760
|
-
insertionPos = position + pos + tableElementFooter.node.nodeSize;
|
|
761
|
-
tr.insert(
|
|
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(
|
|
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(
|
|
774
|
+
insertionPos = position + tableSize + 2;
|
|
775
|
+
tr.insert(insertionPos, tableElementFooter);
|
|
778
776
|
}
|
|
779
777
|
}
|
|
780
778
|
}
|
|
781
779
|
}
|
|
782
|
-
dispatch
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
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
|
|
193
|
-
if (!
|
|
194
|
-
(0, track_changes_utils_1.isDeleted)(
|
|
195
|
-
(0, track_changes_utils_1.isRejectedInsert)(
|
|
196
|
-
|
|
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
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
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((
|
|
216
|
+
rids: notes.map((note) => note.attrs.id),
|
|
228
217
|
contents: notes
|
|
229
|
-
.map((
|
|
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
|
-
(
|
|
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.
|
|
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;
|
package/dist/es/commands.js
CHANGED
|
@@ -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,
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
715
|
-
insertionPos =
|
|
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)
|
|
721
|
-
if (tableElementFooter) {
|
|
722
|
-
const pos = tableElementFooter.pos;
|
|
723
|
-
insertionPos = position + pos + tableElementFooter.node.nodeSize;
|
|
724
|
-
tr.insert(
|
|
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(
|
|
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(
|
|
737
|
+
insertionPos = position + tableSize + 2;
|
|
738
|
+
tr.insert(insertionPos, tableElementFooter);
|
|
741
739
|
}
|
|
742
740
|
}
|
|
743
741
|
}
|
|
744
742
|
}
|
|
745
|
-
dispatch
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
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
|
|
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
|
|
186
|
-
if (!
|
|
187
|
-
isDeleted(
|
|
188
|
-
isRejectedInsert(
|
|
189
|
-
|
|
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
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
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((
|
|
209
|
+
rids: notes.map((note) => note.attrs.id),
|
|
221
210
|
contents: notes
|
|
222
|
-
.map((
|
|
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
|
-
(
|
|
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 {
|
|
17
|
-
import {
|
|
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
|
-
};
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -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,
|
|
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.
|
|
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
|
|
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
|
-
};
|