@manuscripts/body-editor 2.0.25 → 2.0.26-LEAN-3884.0
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 +39 -14
- package/dist/cjs/versions.js +1 -1
- package/dist/es/commands.js +39 -14
- package/dist/es/versions.js +1 -1
- package/dist/types/commands.d.ts +2 -2
- package/dist/types/versions.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/commands.js
CHANGED
|
@@ -132,7 +132,8 @@ const createBlock = (nodeType, position, state, dispatch, attrs, tableConfig) =>
|
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
exports.createBlock = createBlock;
|
|
135
|
-
const insertGeneralFootnote = (
|
|
135
|
+
const insertGeneralFootnote = (tableNode, position, view, tableElementFooter) => {
|
|
136
|
+
var _a;
|
|
136
137
|
const { state, dispatch } = view;
|
|
137
138
|
const paragraph = state.schema.nodes.paragraph.create({
|
|
138
139
|
placeholder: 'Add general note here',
|
|
@@ -140,14 +141,13 @@ const insertGeneralFootnote = (tableElementNode, position, view, tableElementFoo
|
|
|
140
141
|
const generalNote = state.schema.nodes.general_table_footnote.create({}, [
|
|
141
142
|
paragraph,
|
|
142
143
|
]);
|
|
143
|
-
const tableColGroup = (0, prosemirror_utils_1.findChildrenByType)(
|
|
144
|
-
const table = (0, prosemirror_utils_1.findChildrenByType)(tableElementNode, transform_1.schema.nodes.table)[0];
|
|
144
|
+
const tableColGroup = (0, prosemirror_utils_1.findChildrenByType)(tableNode, transform_1.schema.nodes.table_colgroup)[0];
|
|
145
145
|
const tr = state.tr;
|
|
146
146
|
const pos = (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length)
|
|
147
147
|
? position + tableElementFooter[0].pos + 2
|
|
148
148
|
: position +
|
|
149
149
|
(!tableColGroup
|
|
150
|
-
?
|
|
150
|
+
? ((_a = tableNode.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize) || 0
|
|
151
151
|
: tableColGroup.pos + tableColGroup.node.nodeSize);
|
|
152
152
|
if (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length) {
|
|
153
153
|
tr.insert(pos, generalNote);
|
|
@@ -236,6 +236,25 @@ const insertBreak = (state, dispatch) => {
|
|
|
236
236
|
};
|
|
237
237
|
exports.insertBreak = insertBreak;
|
|
238
238
|
const selectedText = () => (window.getSelection() || '').toString();
|
|
239
|
+
const findPosBeforeFirstSubsection = ($pos) => {
|
|
240
|
+
let posBeforeFirstSubsection = null;
|
|
241
|
+
for (let d = $pos.depth; d >= 0; d--) {
|
|
242
|
+
const parentNode = $pos.node(d);
|
|
243
|
+
if ((0, transform_1.isSectionNodeType)(parentNode.type)) {
|
|
244
|
+
const parentStartPos = $pos.start(d);
|
|
245
|
+
parentNode.descendants((node, pos) => {
|
|
246
|
+
if (node.type === transform_1.schema.nodes.section &&
|
|
247
|
+
posBeforeFirstSubsection === null) {
|
|
248
|
+
posBeforeFirstSubsection = parentStartPos + pos;
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
return true;
|
|
252
|
+
});
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return posBeforeFirstSubsection;
|
|
257
|
+
};
|
|
239
258
|
const findPosAfterParentSection = ($pos) => {
|
|
240
259
|
for (let d = $pos.depth; d >= 0; d--) {
|
|
241
260
|
const node = $pos.node(d);
|
|
@@ -430,7 +449,10 @@ const insertSection = (subsection = false) => (state, dispatch, view) => {
|
|
|
430
449
|
}
|
|
431
450
|
let pos;
|
|
432
451
|
if ((0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.body)(selection) || subsection) {
|
|
433
|
-
pos =
|
|
452
|
+
pos = subsection
|
|
453
|
+
? findPosBeforeFirstSubsection(state.selection.$from) ||
|
|
454
|
+
findPosAfterParentSection(state.selection.$from)
|
|
455
|
+
: findPosAfterParentSection(state.selection.$from);
|
|
434
456
|
}
|
|
435
457
|
else {
|
|
436
458
|
const body = (0, doc_1.findBody)(state.doc);
|
|
@@ -933,7 +955,8 @@ const addInlineComment = (state, dispatch) => {
|
|
|
933
955
|
return false;
|
|
934
956
|
};
|
|
935
957
|
exports.addInlineComment = addInlineComment;
|
|
936
|
-
const insertTableFootnote = (
|
|
958
|
+
const insertTableFootnote = (node, position, view, inlineFootnote) => {
|
|
959
|
+
var _a;
|
|
937
960
|
const { state, dispatch } = view;
|
|
938
961
|
const tr = state.tr;
|
|
939
962
|
const footnote = state.schema.nodes.footnote.createAndFill({
|
|
@@ -951,9 +974,9 @@ const insertTableFootnote = (tableElementNode, position, view, inlineFootnote) =
|
|
|
951
974
|
});
|
|
952
975
|
}
|
|
953
976
|
else {
|
|
954
|
-
const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(
|
|
977
|
+
const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote);
|
|
955
978
|
footnoteIndex =
|
|
956
|
-
inlineFootnotes.filter(({ pos }) => !(0, track_changes_utils_1.isRejectedInsert)(
|
|
979
|
+
inlineFootnotes.filter(({ pos }) => !(0, track_changes_utils_1.isRejectedInsert)(node) && position + pos <= insertedAt).length + 1;
|
|
957
980
|
const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
|
|
958
981
|
rids: [footnote.attrs.id],
|
|
959
982
|
contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
|
|
@@ -961,7 +984,7 @@ const insertTableFootnote = (tableElementNode, position, view, inlineFootnote) =
|
|
|
961
984
|
tr.insert(insertedAt, inlineFootnoteNode);
|
|
962
985
|
}
|
|
963
986
|
let insertionPos = position;
|
|
964
|
-
const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(
|
|
987
|
+
const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.footnotes_element).pop();
|
|
965
988
|
if (footnotesElement &&
|
|
966
989
|
!(0, track_changes_utils_1.isDeleted)(footnotesElement.node) &&
|
|
967
990
|
!(0, track_changes_utils_1.isRejectedInsert)(footnotesElement.node)) {
|
|
@@ -971,7 +994,7 @@ const insertTableFootnote = (tableElementNode, position, view, inlineFootnote) =
|
|
|
971
994
|
}
|
|
972
995
|
else {
|
|
973
996
|
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
974
|
-
const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(
|
|
997
|
+
const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_element_footer)[0];
|
|
975
998
|
if (tableElementFooter) {
|
|
976
999
|
const pos = tableElementFooter.pos;
|
|
977
1000
|
insertionPos = position + pos + tableElementFooter.node.nodeSize;
|
|
@@ -981,16 +1004,18 @@ const insertTableFootnote = (tableElementNode, position, view, inlineFootnote) =
|
|
|
981
1004
|
const tableElementFooter = transform_1.schema.nodes.table_element_footer.create({
|
|
982
1005
|
id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.TableElementFooter),
|
|
983
1006
|
}, [footnoteElement]);
|
|
984
|
-
const tableColGroup = (0, prosemirror_utils_1.findChildrenByType)(
|
|
985
|
-
const table = (0, prosemirror_utils_1.findChildrenByType)(tableElementNode, transform_1.schema.nodes.table)[0];
|
|
1007
|
+
const tableColGroup = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_colgroup)[0];
|
|
986
1008
|
if (tableColGroup) {
|
|
987
1009
|
insertionPos =
|
|
988
1010
|
position + tableColGroup.pos + tableColGroup.node.nodeSize;
|
|
989
1011
|
tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
|
|
990
1012
|
}
|
|
991
1013
|
else {
|
|
992
|
-
|
|
993
|
-
|
|
1014
|
+
const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
|
|
1015
|
+
if (tableSize) {
|
|
1016
|
+
insertionPos = position + tableSize;
|
|
1017
|
+
tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
|
|
1018
|
+
}
|
|
994
1019
|
}
|
|
995
1020
|
}
|
|
996
1021
|
}
|
package/dist/cjs/versions.js
CHANGED
package/dist/es/commands.js
CHANGED
|
@@ -123,7 +123,8 @@ export const createBlock = (nodeType, position, state, dispatch, attrs, tableCon
|
|
|
123
123
|
dispatch(tr.setSelection(selection).scrollIntoView());
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
-
export const insertGeneralFootnote = (
|
|
126
|
+
export const insertGeneralFootnote = (tableNode, position, view, tableElementFooter) => {
|
|
127
|
+
var _a;
|
|
127
128
|
const { state, dispatch } = view;
|
|
128
129
|
const paragraph = state.schema.nodes.paragraph.create({
|
|
129
130
|
placeholder: 'Add general note here',
|
|
@@ -131,14 +132,13 @@ export const insertGeneralFootnote = (tableElementNode, position, view, tableEle
|
|
|
131
132
|
const generalNote = state.schema.nodes.general_table_footnote.create({}, [
|
|
132
133
|
paragraph,
|
|
133
134
|
]);
|
|
134
|
-
const tableColGroup = findChildrenByType(
|
|
135
|
-
const table = findChildrenByType(tableElementNode, schema.nodes.table)[0];
|
|
135
|
+
const tableColGroup = findChildrenByType(tableNode, schema.nodes.table_colgroup)[0];
|
|
136
136
|
const tr = state.tr;
|
|
137
137
|
const pos = (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length)
|
|
138
138
|
? position + tableElementFooter[0].pos + 2
|
|
139
139
|
: position +
|
|
140
140
|
(!tableColGroup
|
|
141
|
-
?
|
|
141
|
+
? ((_a = tableNode.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize) || 0
|
|
142
142
|
: tableColGroup.pos + tableColGroup.node.nodeSize);
|
|
143
143
|
if (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length) {
|
|
144
144
|
tr.insert(pos, generalNote);
|
|
@@ -221,6 +221,25 @@ export const insertBreak = (state, dispatch) => {
|
|
|
221
221
|
return true;
|
|
222
222
|
};
|
|
223
223
|
const selectedText = () => (window.getSelection() || '').toString();
|
|
224
|
+
const findPosBeforeFirstSubsection = ($pos) => {
|
|
225
|
+
let posBeforeFirstSubsection = null;
|
|
226
|
+
for (let d = $pos.depth; d >= 0; d--) {
|
|
227
|
+
const parentNode = $pos.node(d);
|
|
228
|
+
if (isSectionNodeType(parentNode.type)) {
|
|
229
|
+
const parentStartPos = $pos.start(d);
|
|
230
|
+
parentNode.descendants((node, pos) => {
|
|
231
|
+
if (node.type === schema.nodes.section &&
|
|
232
|
+
posBeforeFirstSubsection === null) {
|
|
233
|
+
posBeforeFirstSubsection = parentStartPos + pos;
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
return true;
|
|
237
|
+
});
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return posBeforeFirstSubsection;
|
|
242
|
+
};
|
|
224
243
|
const findPosAfterParentSection = ($pos) => {
|
|
225
244
|
for (let d = $pos.depth; d >= 0; d--) {
|
|
226
245
|
const node = $pos.node(d);
|
|
@@ -406,7 +425,10 @@ export const insertSection = (subsection = false) => (state, dispatch, view) =>
|
|
|
406
425
|
}
|
|
407
426
|
let pos;
|
|
408
427
|
if (hasParentNodeOfType(schema.nodes.body)(selection) || subsection) {
|
|
409
|
-
pos =
|
|
428
|
+
pos = subsection
|
|
429
|
+
? findPosBeforeFirstSubsection(state.selection.$from) ||
|
|
430
|
+
findPosAfterParentSection(state.selection.$from)
|
|
431
|
+
: findPosAfterParentSection(state.selection.$from);
|
|
410
432
|
}
|
|
411
433
|
else {
|
|
412
434
|
const body = findBody(state.doc);
|
|
@@ -891,7 +913,8 @@ export const addInlineComment = (state, dispatch) => {
|
|
|
891
913
|
}
|
|
892
914
|
return false;
|
|
893
915
|
};
|
|
894
|
-
export const insertTableFootnote = (
|
|
916
|
+
export const insertTableFootnote = (node, position, view, inlineFootnote) => {
|
|
917
|
+
var _a;
|
|
895
918
|
const { state, dispatch } = view;
|
|
896
919
|
const tr = state.tr;
|
|
897
920
|
const footnote = state.schema.nodes.footnote.createAndFill({
|
|
@@ -909,9 +932,9 @@ export const insertTableFootnote = (tableElementNode, position, view, inlineFoot
|
|
|
909
932
|
});
|
|
910
933
|
}
|
|
911
934
|
else {
|
|
912
|
-
const inlineFootnotes = findChildrenByType(
|
|
935
|
+
const inlineFootnotes = findChildrenByType(node, schema.nodes.inline_footnote);
|
|
913
936
|
footnoteIndex =
|
|
914
|
-
inlineFootnotes.filter(({ pos }) => !isRejectedInsert(
|
|
937
|
+
inlineFootnotes.filter(({ pos }) => !isRejectedInsert(node) && position + pos <= insertedAt).length + 1;
|
|
915
938
|
const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
|
|
916
939
|
rids: [footnote.attrs.id],
|
|
917
940
|
contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
|
|
@@ -919,7 +942,7 @@ export const insertTableFootnote = (tableElementNode, position, view, inlineFoot
|
|
|
919
942
|
tr.insert(insertedAt, inlineFootnoteNode);
|
|
920
943
|
}
|
|
921
944
|
let insertionPos = position;
|
|
922
|
-
const footnotesElement = findChildrenByType(
|
|
945
|
+
const footnotesElement = findChildrenByType(node, schema.nodes.footnotes_element).pop();
|
|
923
946
|
if (footnotesElement &&
|
|
924
947
|
!isDeleted(footnotesElement.node) &&
|
|
925
948
|
!isRejectedInsert(footnotesElement.node)) {
|
|
@@ -929,7 +952,7 @@ export const insertTableFootnote = (tableElementNode, position, view, inlineFoot
|
|
|
929
952
|
}
|
|
930
953
|
else {
|
|
931
954
|
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
932
|
-
const tableElementFooter = findChildrenByType(
|
|
955
|
+
const tableElementFooter = findChildrenByType(node, schema.nodes.table_element_footer)[0];
|
|
933
956
|
if (tableElementFooter) {
|
|
934
957
|
const pos = tableElementFooter.pos;
|
|
935
958
|
insertionPos = position + pos + tableElementFooter.node.nodeSize;
|
|
@@ -939,16 +962,18 @@ export const insertTableFootnote = (tableElementNode, position, view, inlineFoot
|
|
|
939
962
|
const tableElementFooter = schema.nodes.table_element_footer.create({
|
|
940
963
|
id: generateID(ObjectTypes.TableElementFooter),
|
|
941
964
|
}, [footnoteElement]);
|
|
942
|
-
const tableColGroup = findChildrenByType(
|
|
943
|
-
const table = findChildrenByType(tableElementNode, schema.nodes.table)[0];
|
|
965
|
+
const tableColGroup = findChildrenByType(node, schema.nodes.table_colgroup)[0];
|
|
944
966
|
if (tableColGroup) {
|
|
945
967
|
insertionPos =
|
|
946
968
|
position + tableColGroup.pos + tableColGroup.node.nodeSize;
|
|
947
969
|
tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
|
|
948
970
|
}
|
|
949
971
|
else {
|
|
950
|
-
|
|
951
|
-
|
|
972
|
+
const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
|
|
973
|
+
if (tableSize) {
|
|
974
|
+
insertionPos = position + tableSize;
|
|
975
|
+
tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
|
|
976
|
+
}
|
|
952
977
|
}
|
|
953
978
|
}
|
|
954
979
|
}
|
package/dist/es/versions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '2.0.
|
|
1
|
+
export const VERSION = '2.0.26-LEAN-3884.0';
|
|
2
2
|
export const MATHJAX_VERSION = '3.2.2';
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare const blockActive: (type: ManuscriptNodeType) => (state: Manuscri
|
|
|
28
28
|
export declare const canInsert: (type: ManuscriptNodeType) => (state: ManuscriptEditorState) => boolean;
|
|
29
29
|
export declare const createSelection: (nodeType: ManuscriptNodeType, position: number, doc: ManuscriptNode) => Selection;
|
|
30
30
|
export declare const createBlock: (nodeType: ManuscriptNodeType, position: number, state: ManuscriptEditorState, dispatch?: Dispatch, attrs?: Attrs, tableConfig?: TableConfig) => void;
|
|
31
|
-
export declare const insertGeneralFootnote: (
|
|
31
|
+
export declare const insertGeneralFootnote: (tableNode: ManuscriptNode, position: number, view: ManuscriptEditorView, tableElementFooter?: NodeWithPos[]) => void;
|
|
32
32
|
export declare const insertFigure: (file: FileAttachment, state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
|
|
33
33
|
export declare const insertSupplement: (file: FileAttachment, state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
|
|
34
34
|
export declare const insertBlock: (nodeType: ManuscriptNodeType) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView, tableConfig?: TableConfig) => boolean;
|
|
@@ -65,7 +65,7 @@ interface NodeWithPosition {
|
|
|
65
65
|
node: InlineFootnoteNode;
|
|
66
66
|
pos: number;
|
|
67
67
|
}
|
|
68
|
-
export declare const insertTableFootnote: (
|
|
68
|
+
export declare const insertTableFootnote: (node: ManuscriptNode, position: number, view: EditorView, inlineFootnote?: NodeWithPosition) => void;
|
|
69
69
|
export declare const addRows: (direction: 'top' | 'bottom') => (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
|
|
70
70
|
export declare const addColumns: (direction: 'right' | 'left') => (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
|
|
71
71
|
export declare function mergeCellsWithSpace(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
package/dist/types/versions.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.
|
|
1
|
+
export declare const VERSION = "2.0.26-LEAN-3884.0";
|
|
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": "2.0.
|
|
4
|
+
"version": "2.0.26-LEAN-3884.0",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|