@manuscripts/body-editor 1.7.27 → 1.7.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.
- package/dist/cjs/commands.js +21 -19
- package/dist/cjs/components/views/FigureDropdown.js +1 -1
- package/dist/cjs/configs/editor-plugins.js +2 -0
- package/dist/cjs/lib/context-menu.js +26 -15
- package/dist/cjs/menus.js +38 -25
- package/dist/cjs/plugins/footnotes/footnotes-utils.js +67 -1
- package/dist/cjs/plugins/table-footnote.js +43 -0
- package/dist/cjs/toolbar.js +6 -2
- package/dist/cjs/views/bullet_list.js +9 -0
- package/dist/cjs/views/ordered_list.js +1 -0
- package/dist/es/commands.js +21 -19
- package/dist/es/components/views/FigureDropdown.js +1 -1
- package/dist/es/configs/editor-plugins.js +2 -0
- package/dist/es/lib/context-menu.js +27 -16
- package/dist/es/menus.js +39 -26
- package/dist/es/plugins/footnotes/footnotes-utils.js +64 -2
- package/dist/es/plugins/table-footnote.js +41 -0
- package/dist/es/toolbar.js +6 -2
- package/dist/es/views/bullet_list.js +9 -0
- package/dist/es/views/ordered_list.js +1 -0
- package/dist/types/commands.d.ts +2 -1
- package/dist/types/plugins/footnotes/footnotes-utils.d.ts +7 -0
- package/dist/types/plugins/table-footnote.d.ts +3 -0
- package/dist/types/views/bullet_list.d.ts +1 -0
- package/dist/types/views/ordered_list.d.ts +1 -1
- package/package.json +5 -5
package/dist/cjs/commands.js
CHANGED
|
@@ -29,6 +29,7 @@ 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");
|
|
32
33
|
const highlight_1 = require("./plugins/highlight");
|
|
33
34
|
const markActive = (type) => (state) => {
|
|
34
35
|
const { from, $from, to, empty } = state.selection;
|
|
@@ -726,37 +727,38 @@ const updateCommentAnnotationState = (state, dispatch) => {
|
|
|
726
727
|
}
|
|
727
728
|
};
|
|
728
729
|
exports.updateCommentAnnotationState = updateCommentAnnotationState;
|
|
729
|
-
const insertTableFootnote = (node, position,
|
|
730
|
+
const insertTableFootnote = (node, position, view) => {
|
|
730
731
|
var _a;
|
|
732
|
+
const { state, dispatch } = view;
|
|
731
733
|
const footnote = state.schema.nodes.footnote.createAndFill({
|
|
732
734
|
id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Footnote),
|
|
733
735
|
kind: 'footnote',
|
|
734
736
|
});
|
|
735
737
|
const insertedAt = state.selection.to;
|
|
736
738
|
const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote);
|
|
737
|
-
const
|
|
739
|
+
const footnoteIndex = inlineFootnotes.filter(({ pos }) => position + pos <= insertedAt).length + 1;
|
|
738
740
|
const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
|
|
739
741
|
rids: [footnote.attrs.id],
|
|
740
|
-
contents:
|
|
742
|
+
contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
|
|
741
743
|
});
|
|
742
744
|
const tr = state.tr;
|
|
743
745
|
tr.insert(insertedAt, inlineFootnoteNode);
|
|
744
|
-
let insertionPos;
|
|
746
|
+
let insertionPos = position;
|
|
745
747
|
const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.footnotes_element).pop();
|
|
746
748
|
if (footnotesElement &&
|
|
747
749
|
!(0, track_changes_utils_1.isDeleted)(footnotesElement.node) &&
|
|
748
750
|
!(0, track_changes_utils_1.isRejectedInsert)(footnotesElement.node)) {
|
|
749
|
-
const
|
|
750
|
-
insertionPos =
|
|
751
|
+
const footnotePos = (0, footnotes_utils_1.getNewFootnotePos)(footnotesElement, footnoteIndex);
|
|
752
|
+
insertionPos = tr.mapping.map(position + footnotePos);
|
|
751
753
|
tr.insert(insertionPos, footnote);
|
|
752
754
|
}
|
|
753
755
|
else {
|
|
754
756
|
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
755
|
-
const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_element_footer);
|
|
756
|
-
if (tableElementFooter
|
|
757
|
-
const pos = tableElementFooter
|
|
758
|
-
insertionPos = position + pos + tableElementFooter
|
|
759
|
-
tr.insert(insertionPos, footnoteElement);
|
|
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);
|
|
760
762
|
}
|
|
761
763
|
else {
|
|
762
764
|
const tableElementFooter = transform_1.schema.nodes.table_element_footer.create({
|
|
@@ -765,21 +767,21 @@ const insertTableFootnote = (node, position, state, dispatch) => {
|
|
|
765
767
|
const tableColGroup = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_colgroup)[0];
|
|
766
768
|
if (tableColGroup) {
|
|
767
769
|
insertionPos =
|
|
768
|
-
position + tableColGroup.pos + tableColGroup.node.nodeSize
|
|
769
|
-
tr.insert(insertionPos, tableElementFooter);
|
|
770
|
+
position + tableColGroup.pos + tableColGroup.node.nodeSize;
|
|
771
|
+
tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
|
|
770
772
|
}
|
|
771
773
|
else {
|
|
772
774
|
const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
|
|
773
775
|
if (tableSize) {
|
|
774
|
-
insertionPos = position + tableSize
|
|
775
|
-
tr.insert(insertionPos, tableElementFooter);
|
|
776
|
+
insertionPos = position + tableSize;
|
|
777
|
+
tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
|
|
776
778
|
}
|
|
777
779
|
}
|
|
778
780
|
}
|
|
779
781
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
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());
|
|
784
786
|
};
|
|
785
787
|
exports.insertTableFootnote = insertTableFootnote;
|
|
@@ -60,7 +60,7 @@ const NestedDropdown = ({ parentToggleOpen, buttonText, disabled, list, moveLeft
|
|
|
60
60
|
" ",
|
|
61
61
|
react_1.default.createElement(TriangleCollapsed_1.default, null)),
|
|
62
62
|
isOpen && (react_1.default.createElement(NestedListDropdownList, { direction: 'right', moveLeft: moveLeft, width: 192, onClick: (e) => {
|
|
63
|
-
toggleOpen(
|
|
63
|
+
toggleOpen();
|
|
64
64
|
parentToggleOpen(e);
|
|
65
65
|
} }, list))));
|
|
66
66
|
};
|
|
@@ -38,6 +38,7 @@ 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"));
|
|
41
42
|
const tables_cursor_fix_1 = __importDefault(require("../plugins/tables-cursor-fix"));
|
|
42
43
|
const toc_1 = __importDefault(require("../plugins/toc"));
|
|
43
44
|
const rules_1 = __importDefault(require("../rules"));
|
|
@@ -69,6 +70,7 @@ exports.default = (props) => {
|
|
|
69
70
|
(0, highlight_1.default)(props),
|
|
70
71
|
(0, selected_suggestion_ui_1.default)(props),
|
|
71
72
|
(0, footnotes_1.default)(),
|
|
73
|
+
(0, table_footnote_1.default)(),
|
|
72
74
|
];
|
|
73
75
|
if (props.collabProvider) {
|
|
74
76
|
allPlugins.push((0, prosemirror_collab_1.collab)({ version: props.collabProvider.currentVersion }));
|
|
@@ -23,6 +23,7 @@ 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");
|
|
26
27
|
const ReactSubView_1 = __importDefault(require("../views/ReactSubView"));
|
|
27
28
|
const popper_1 = require("./popper");
|
|
28
29
|
const track_changes_utils_1 = require("./track-changes-utils");
|
|
@@ -187,35 +188,45 @@ class ContextMenu {
|
|
|
187
188
|
if (isInTable) {
|
|
188
189
|
menu.appendChild(this.createMenuSection((section) => {
|
|
189
190
|
section.appendChild(this.createMenuItem('Add Reference Note', () => {
|
|
190
|
-
var _a
|
|
191
|
-
const
|
|
192
|
-
if (!
|
|
193
|
-
(0, track_changes_utils_1.isDeleted)(
|
|
194
|
-
(0, track_changes_utils_1.isRejectedInsert)(
|
|
195
|
-
|
|
196
|
-
(0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
|
|
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);
|
|
197
197
|
}
|
|
198
198
|
else {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
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
|
+
}));
|
|
202
205
|
const targetDom = this.view.domAtPos(this.view.state.selection.from);
|
|
203
206
|
if (targetDom.node instanceof Element && this.props) {
|
|
204
207
|
const popperContainer = (0, ReactSubView_1.default)(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), style_guide_1.TableFootnotesSelector, {
|
|
205
208
|
notes: footnotes,
|
|
206
209
|
onAdd: () => {
|
|
207
210
|
var _a;
|
|
208
|
-
|
|
209
|
-
(0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
|
|
211
|
+
(0, commands_1.insertTableFootnote)(this.node, this.getPos(), this.view);
|
|
210
212
|
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
211
213
|
},
|
|
212
214
|
onInsert: (notes) => {
|
|
213
215
|
var _a;
|
|
214
216
|
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
|
+
});
|
|
215
226
|
const node = this.view.state.schema.nodes.inline_footnote.create({
|
|
216
|
-
rids: notes.map((
|
|
227
|
+
rids: notes.map(({ node }) => node.attrs.id),
|
|
217
228
|
contents: notes
|
|
218
|
-
.map((
|
|
229
|
+
.map(({ index }) => index ? index : inlineFootnoteIndex)
|
|
219
230
|
.join(),
|
|
220
231
|
});
|
|
221
232
|
const tr = this.view.state.tr;
|
|
@@ -228,7 +239,7 @@ class ContextMenu {
|
|
|
228
239
|
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
229
240
|
},
|
|
230
241
|
}, this.node, this.getPos, this.view, 'table-footnote-editor');
|
|
231
|
-
(
|
|
242
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.show(targetDom.node, popperContainer, 'bottom-end');
|
|
232
243
|
}
|
|
233
244
|
}
|
|
234
245
|
}));
|
package/dist/cjs/menus.js
CHANGED
|
@@ -19,10 +19,8 @@ exports.getEditorMenus = void 0;
|
|
|
19
19
|
const transform_1 = require("@manuscripts/transform");
|
|
20
20
|
const prosemirror_commands_1 = require("prosemirror-commands");
|
|
21
21
|
const prosemirror_history_1 = require("prosemirror-history");
|
|
22
|
-
const prosemirror_schema_list_1 = require("prosemirror-schema-list");
|
|
23
22
|
const prosemirror_tables_1 = require("prosemirror-tables");
|
|
24
23
|
const commands_1 = require("./commands");
|
|
25
|
-
const list_1 = require("./keys/list");
|
|
26
24
|
const hierarchy_1 = require("./lib/hierarchy");
|
|
27
25
|
const getEditorMenus = (editor) => {
|
|
28
26
|
const { isCommandValid, state } = editor;
|
|
@@ -109,29 +107,6 @@ const getEditorMenus = (editor) => {
|
|
|
109
107
|
{
|
|
110
108
|
role: 'separator',
|
|
111
109
|
},
|
|
112
|
-
{
|
|
113
|
-
id: 'insert-ordered-list',
|
|
114
|
-
label: 'Numbered List',
|
|
115
|
-
shortcut: {
|
|
116
|
-
mac: 'Option+CommandOrControl+O',
|
|
117
|
-
pc: 'CommandOrControl+Option+O',
|
|
118
|
-
},
|
|
119
|
-
isEnabled: isCommandValid((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.ordered_list)),
|
|
120
|
-
run: doCommand((0, list_1.skipCommandTracking)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.ordered_list))),
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
id: 'insert-bullet-list',
|
|
124
|
-
label: 'Bullet List',
|
|
125
|
-
shortcut: {
|
|
126
|
-
mac: 'Option+CommandOrControl+K',
|
|
127
|
-
pc: 'CommandOrControl+Option+K',
|
|
128
|
-
},
|
|
129
|
-
isEnabled: isCommandValid((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.bullet_list)),
|
|
130
|
-
run: doCommand((0, list_1.skipCommandTracking)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.bullet_list))),
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
role: 'separator',
|
|
134
|
-
},
|
|
135
110
|
{
|
|
136
111
|
id: 'insert-blockquote',
|
|
137
112
|
label: 'Block Quote',
|
|
@@ -322,6 +297,44 @@ const getEditorMenus = (editor) => {
|
|
|
322
297
|
{
|
|
323
298
|
role: 'separator',
|
|
324
299
|
},
|
|
300
|
+
{
|
|
301
|
+
id: 'insert-bullet-list',
|
|
302
|
+
label: 'Bullet List',
|
|
303
|
+
isEnabled: isCommandValid((0, commands_1.insertList)(transform_1.schema.nodes.bullet_list)),
|
|
304
|
+
submenu: [
|
|
305
|
+
{
|
|
306
|
+
id: 'bullet-list-context-menu',
|
|
307
|
+
label: '',
|
|
308
|
+
isEnabled: true,
|
|
309
|
+
options: {
|
|
310
|
+
bullet: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.bullet_list, 'bullet')),
|
|
311
|
+
simple: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.bullet_list, 'simple')),
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
id: 'insert-ordered-list',
|
|
318
|
+
label: 'Ordered List',
|
|
319
|
+
isEnabled: isCommandValid((0, commands_1.insertList)(transform_1.schema.nodes.ordered_list)),
|
|
320
|
+
submenu: [
|
|
321
|
+
{
|
|
322
|
+
id: 'ordered-list-context-menu',
|
|
323
|
+
label: '',
|
|
324
|
+
isEnabled: true,
|
|
325
|
+
options: {
|
|
326
|
+
order: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.ordered_list, 'order')),
|
|
327
|
+
'alpha-upper': doCommand((0, commands_1.insertList)(transform_1.schema.nodes.ordered_list, 'alpha-upper')),
|
|
328
|
+
'alpha-lower': doCommand((0, commands_1.insertList)(transform_1.schema.nodes.ordered_list, 'alpha-lower')),
|
|
329
|
+
'roman-upper': doCommand((0, commands_1.insertList)(transform_1.schema.nodes.ordered_list, 'roman-upper')),
|
|
330
|
+
'roman-lower': doCommand((0, commands_1.insertList)(transform_1.schema.nodes.ordered_list, 'roman-lower')),
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
role: 'separator',
|
|
337
|
+
},
|
|
325
338
|
{
|
|
326
339
|
id: 'format-table',
|
|
327
340
|
label: 'Table',
|
|
@@ -15,8 +15,10 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.findTableInlineFootnoteIds = void 0;
|
|
18
|
+
exports.updateTableInlineFootnoteLabels = exports.orderTableFootnotes = exports.buildTableFootnoteLabels = exports.getNewFootnotePos = exports.findTableInlineFootnoteIds = void 0;
|
|
19
|
+
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
19
20
|
const transform_1 = require("@manuscripts/transform");
|
|
21
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
20
22
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
21
23
|
const findTableInlineFootnoteIds = ($pos) => {
|
|
22
24
|
var _a;
|
|
@@ -28,3 +30,67 @@ const findTableInlineFootnoteIds = ($pos) => {
|
|
|
28
30
|
: []);
|
|
29
31
|
};
|
|
30
32
|
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;
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
};
|
package/dist/cjs/toolbar.js
CHANGED
|
@@ -68,8 +68,12 @@ exports.toolbar = {
|
|
|
68
68
|
title: 'Wrap in bullet list',
|
|
69
69
|
content: icons_1.default.bullet_list,
|
|
70
70
|
isActive: (0, commands_1.blockActive)(transform_1.schema.nodes.bullet_list),
|
|
71
|
-
isEnabled: (0, commands_1.insertList)(transform_1.schema.nodes.bullet_list),
|
|
72
|
-
run: (0, commands_1.insertList)(transform_1.schema.nodes.bullet_list),
|
|
71
|
+
isEnabled: (0, commands_1.insertList)(transform_1.schema.nodes.bullet_list, 'bullet'),
|
|
72
|
+
run: (0, commands_1.insertList)(transform_1.schema.nodes.bullet_list, 'bullet'),
|
|
73
|
+
options: {
|
|
74
|
+
bullet: (0, commands_1.insertList)(transform_1.schema.nodes.bullet_list, 'bullet'),
|
|
75
|
+
simple: (0, commands_1.insertList)(transform_1.schema.nodes.bullet_list, 'simple'),
|
|
76
|
+
},
|
|
73
77
|
},
|
|
74
78
|
ordered_list: {
|
|
75
79
|
title: 'Wrap in ordered list',
|
|
@@ -21,15 +21,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
exports.bulletListCallback = exports.BulletListView = void 0;
|
|
22
22
|
const block_view_1 = __importDefault(require("./block_view"));
|
|
23
23
|
const creators_1 = require("./creators");
|
|
24
|
+
const ordered_list_1 = require("./ordered_list");
|
|
24
25
|
class BulletListView extends block_view_1.default {
|
|
25
26
|
constructor() {
|
|
26
27
|
super(...arguments);
|
|
27
28
|
this.elementType = 'ul';
|
|
29
|
+
this.updateContents = () => {
|
|
30
|
+
if (this.contentDOM) {
|
|
31
|
+
const type = this.node.attrs.listStyleType || 'bullet';
|
|
32
|
+
this.contentDOM.style.listStyleType = ordered_list_1.JATS_HTML_LIST_STYLE_MAPPING[type];
|
|
33
|
+
}
|
|
34
|
+
};
|
|
28
35
|
}
|
|
29
36
|
}
|
|
30
37
|
exports.BulletListView = BulletListView;
|
|
31
38
|
const bulletListCallback = (node, dom) => {
|
|
32
39
|
dom.classList.add('list');
|
|
40
|
+
const type = node.attrs.listStyleType || 'bullet';
|
|
41
|
+
dom.style.listStyleType = ordered_list_1.JATS_HTML_LIST_STYLE_MAPPING[type];
|
|
33
42
|
};
|
|
34
43
|
exports.bulletListCallback = bulletListCallback;
|
|
35
44
|
exports.default = (0, creators_1.createNodeOrElementView)(BulletListView, 'ul', exports.bulletListCallback);
|
|
@@ -22,6 +22,7 @@ exports.orderedListCallback = exports.OrderedListView = exports.JATS_HTML_LIST_S
|
|
|
22
22
|
const block_view_1 = __importDefault(require("./block_view"));
|
|
23
23
|
const creators_1 = require("./creators");
|
|
24
24
|
exports.JATS_HTML_LIST_STYLE_MAPPING = {
|
|
25
|
+
simple: 'none',
|
|
25
26
|
bullet: 'disc',
|
|
26
27
|
order: 'decimal',
|
|
27
28
|
'alpha-lower': 'lower-alpha',
|
package/dist/es/commands.js
CHANGED
|
@@ -26,6 +26,7 @@ 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';
|
|
29
30
|
import { highlightKey, SET_COMMENT } from './plugins/highlight';
|
|
30
31
|
export const markActive = (type) => (state) => {
|
|
31
32
|
const { from, $from, to, empty } = state.selection;
|
|
@@ -689,37 +690,38 @@ export const updateCommentAnnotationState = (state, dispatch) => {
|
|
|
689
690
|
dispatch(tr);
|
|
690
691
|
}
|
|
691
692
|
};
|
|
692
|
-
export const insertTableFootnote = (node, position,
|
|
693
|
+
export const insertTableFootnote = (node, position, view) => {
|
|
693
694
|
var _a;
|
|
695
|
+
const { state, dispatch } = view;
|
|
694
696
|
const footnote = state.schema.nodes.footnote.createAndFill({
|
|
695
697
|
id: generateID(ObjectTypes.Footnote),
|
|
696
698
|
kind: 'footnote',
|
|
697
699
|
});
|
|
698
700
|
const insertedAt = state.selection.to;
|
|
699
701
|
const inlineFootnotes = findChildrenByType(node, schema.nodes.inline_footnote);
|
|
700
|
-
const
|
|
702
|
+
const footnoteIndex = inlineFootnotes.filter(({ pos }) => position + pos <= insertedAt).length + 1;
|
|
701
703
|
const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
|
|
702
704
|
rids: [footnote.attrs.id],
|
|
703
|
-
contents:
|
|
705
|
+
contents: footnoteIndex === -1 ? inlineFootnotes.length : footnoteIndex,
|
|
704
706
|
});
|
|
705
707
|
const tr = state.tr;
|
|
706
708
|
tr.insert(insertedAt, inlineFootnoteNode);
|
|
707
|
-
let insertionPos;
|
|
709
|
+
let insertionPos = position;
|
|
708
710
|
const footnotesElement = findChildrenByType(node, schema.nodes.footnotes_element).pop();
|
|
709
711
|
if (footnotesElement &&
|
|
710
712
|
!isDeleted(footnotesElement.node) &&
|
|
711
713
|
!isRejectedInsert(footnotesElement.node)) {
|
|
712
|
-
const
|
|
713
|
-
insertionPos =
|
|
714
|
+
const footnotePos = getNewFootnotePos(footnotesElement, footnoteIndex);
|
|
715
|
+
insertionPos = tr.mapping.map(position + footnotePos);
|
|
714
716
|
tr.insert(insertionPos, footnote);
|
|
715
717
|
}
|
|
716
718
|
else {
|
|
717
719
|
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
718
|
-
const tableElementFooter = findChildrenByType(node, schema.nodes.table_element_footer);
|
|
719
|
-
if (tableElementFooter
|
|
720
|
-
const pos = tableElementFooter
|
|
721
|
-
insertionPos = position + pos + tableElementFooter
|
|
722
|
-
tr.insert(insertionPos, footnoteElement);
|
|
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);
|
|
723
725
|
}
|
|
724
726
|
else {
|
|
725
727
|
const tableElementFooter = schema.nodes.table_element_footer.create({
|
|
@@ -728,20 +730,20 @@ export const insertTableFootnote = (node, position, state, dispatch) => {
|
|
|
728
730
|
const tableColGroup = findChildrenByType(node, schema.nodes.table_colgroup)[0];
|
|
729
731
|
if (tableColGroup) {
|
|
730
732
|
insertionPos =
|
|
731
|
-
position + tableColGroup.pos + tableColGroup.node.nodeSize
|
|
732
|
-
tr.insert(insertionPos, tableElementFooter);
|
|
733
|
+
position + tableColGroup.pos + tableColGroup.node.nodeSize;
|
|
734
|
+
tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
|
|
733
735
|
}
|
|
734
736
|
else {
|
|
735
737
|
const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
|
|
736
738
|
if (tableSize) {
|
|
737
|
-
insertionPos = position + tableSize
|
|
738
|
-
tr.insert(insertionPos, tableElementFooter);
|
|
739
|
+
insertionPos = position + tableSize;
|
|
740
|
+
tr.insert(tr.mapping.map(insertionPos), tableElementFooter);
|
|
739
741
|
}
|
|
740
742
|
}
|
|
741
743
|
}
|
|
742
744
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
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());
|
|
747
749
|
};
|
|
@@ -52,7 +52,7 @@ const NestedDropdown = ({ parentToggleOpen, buttonText, disabled, list, moveLeft
|
|
|
52
52
|
" ",
|
|
53
53
|
React.createElement(TriangleCollapsed, null)),
|
|
54
54
|
isOpen && (React.createElement(NestedListDropdownList, { direction: 'right', moveLeft: moveLeft, width: 192, onClick: (e) => {
|
|
55
|
-
toggleOpen(
|
|
55
|
+
toggleOpen();
|
|
56
56
|
parentToggleOpen(e);
|
|
57
57
|
} }, list))));
|
|
58
58
|
};
|
|
@@ -33,6 +33,7 @@ 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';
|
|
36
37
|
import table_editing_fix from '../plugins/tables-cursor-fix';
|
|
37
38
|
import toc from '../plugins/toc';
|
|
38
39
|
import rules from '../rules';
|
|
@@ -64,6 +65,7 @@ export default (props) => {
|
|
|
64
65
|
highlights(props),
|
|
65
66
|
selected_suggestion_ui(props),
|
|
66
67
|
footnotes(),
|
|
68
|
+
table_footnote(),
|
|
67
69
|
];
|
|
68
70
|
if (props.collabProvider) {
|
|
69
71
|
allPlugins.push(collab({ version: props.collabProvider.currentVersion }));
|
|
@@ -13,10 +13,11 @@
|
|
|
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';
|
|
20
21
|
import ReactSubView from '../views/ReactSubView';
|
|
21
22
|
import { PopperManager } from './popper';
|
|
22
23
|
import { isDeleted, isRejectedInsert } from './track-changes-utils';
|
|
@@ -180,35 +181,45 @@ export class ContextMenu {
|
|
|
180
181
|
if (isInTable) {
|
|
181
182
|
menu.appendChild(this.createMenuSection((section) => {
|
|
182
183
|
section.appendChild(this.createMenuItem('Add Reference Note', () => {
|
|
183
|
-
var _a
|
|
184
|
-
const
|
|
185
|
-
if (!
|
|
186
|
-
isDeleted(
|
|
187
|
-
isRejectedInsert(
|
|
188
|
-
|
|
189
|
-
insertTableFootnote(this.node, this.getPos(), state, dispatch);
|
|
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);
|
|
190
190
|
}
|
|
191
191
|
else {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
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
|
+
}));
|
|
195
198
|
const targetDom = this.view.domAtPos(this.view.state.selection.from);
|
|
196
199
|
if (targetDom.node instanceof Element && this.props) {
|
|
197
200
|
const popperContainer = ReactSubView(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), TableFootnotesSelector, {
|
|
198
201
|
notes: footnotes,
|
|
199
202
|
onAdd: () => {
|
|
200
203
|
var _a;
|
|
201
|
-
|
|
202
|
-
insertTableFootnote(this.node, this.getPos(), state, dispatch);
|
|
204
|
+
insertTableFootnote(this.node, this.getPos(), this.view);
|
|
203
205
|
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
204
206
|
},
|
|
205
207
|
onInsert: (notes) => {
|
|
206
208
|
var _a;
|
|
207
209
|
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
|
+
});
|
|
208
219
|
const node = this.view.state.schema.nodes.inline_footnote.create({
|
|
209
|
-
rids: notes.map((
|
|
220
|
+
rids: notes.map(({ node }) => node.attrs.id),
|
|
210
221
|
contents: notes
|
|
211
|
-
.map((
|
|
222
|
+
.map(({ index }) => index ? index : inlineFootnoteIndex)
|
|
212
223
|
.join(),
|
|
213
224
|
});
|
|
214
225
|
const tr = this.view.state.tr;
|
|
@@ -221,7 +232,7 @@ export class ContextMenu {
|
|
|
221
232
|
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
222
233
|
},
|
|
223
234
|
}, this.node, this.getPos, this.view, 'table-footnote-editor');
|
|
224
|
-
(
|
|
235
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.show(targetDom.node, popperContainer, 'bottom-end');
|
|
225
236
|
}
|
|
226
237
|
}
|
|
227
238
|
}));
|
package/dist/es/menus.js
CHANGED
|
@@ -16,10 +16,8 @@
|
|
|
16
16
|
import { schema } from '@manuscripts/transform';
|
|
17
17
|
import { toggleMark } from 'prosemirror-commands';
|
|
18
18
|
import { redo, undo } from 'prosemirror-history';
|
|
19
|
-
import { wrapInList } from 'prosemirror-schema-list';
|
|
20
19
|
import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, deleteColumn, deleteRow, } from 'prosemirror-tables';
|
|
21
|
-
import { addComment, blockActive, canInsert, ifInTableBody, insertBlock, insertCrossReference, insertGraphicalAbstract, insertInlineCitation, insertInlineEquation, insertInlineFootnote, insertLink, insertSection, markActive, } from './commands';
|
|
22
|
-
import { skipCommandTracking } from './keys/list';
|
|
20
|
+
import { addComment, blockActive, canInsert, ifInTableBody, insertBlock, insertCrossReference, insertGraphicalAbstract, insertInlineCitation, insertInlineEquation, insertInlineFootnote, insertLink, insertList, insertSection, markActive, } from './commands';
|
|
23
21
|
import { deleteClosestParentElement, findClosestParentElementNodeName, } from './lib/hierarchy';
|
|
24
22
|
export const getEditorMenus = (editor) => {
|
|
25
23
|
const { isCommandValid, state } = editor;
|
|
@@ -106,29 +104,6 @@ export const getEditorMenus = (editor) => {
|
|
|
106
104
|
{
|
|
107
105
|
role: 'separator',
|
|
108
106
|
},
|
|
109
|
-
{
|
|
110
|
-
id: 'insert-ordered-list',
|
|
111
|
-
label: 'Numbered List',
|
|
112
|
-
shortcut: {
|
|
113
|
-
mac: 'Option+CommandOrControl+O',
|
|
114
|
-
pc: 'CommandOrControl+Option+O',
|
|
115
|
-
},
|
|
116
|
-
isEnabled: isCommandValid(wrapInList(schema.nodes.ordered_list)),
|
|
117
|
-
run: doCommand(skipCommandTracking(wrapInList(schema.nodes.ordered_list))),
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
id: 'insert-bullet-list',
|
|
121
|
-
label: 'Bullet List',
|
|
122
|
-
shortcut: {
|
|
123
|
-
mac: 'Option+CommandOrControl+K',
|
|
124
|
-
pc: 'CommandOrControl+Option+K',
|
|
125
|
-
},
|
|
126
|
-
isEnabled: isCommandValid(wrapInList(schema.nodes.bullet_list)),
|
|
127
|
-
run: doCommand(skipCommandTracking(wrapInList(schema.nodes.bullet_list))),
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
role: 'separator',
|
|
131
|
-
},
|
|
132
107
|
{
|
|
133
108
|
id: 'insert-blockquote',
|
|
134
109
|
label: 'Block Quote',
|
|
@@ -319,6 +294,44 @@ export const getEditorMenus = (editor) => {
|
|
|
319
294
|
{
|
|
320
295
|
role: 'separator',
|
|
321
296
|
},
|
|
297
|
+
{
|
|
298
|
+
id: 'insert-bullet-list',
|
|
299
|
+
label: 'Bullet List',
|
|
300
|
+
isEnabled: isCommandValid(insertList(schema.nodes.bullet_list)),
|
|
301
|
+
submenu: [
|
|
302
|
+
{
|
|
303
|
+
id: 'bullet-list-context-menu',
|
|
304
|
+
label: '',
|
|
305
|
+
isEnabled: true,
|
|
306
|
+
options: {
|
|
307
|
+
bullet: doCommand(insertList(schema.nodes.bullet_list, 'bullet')),
|
|
308
|
+
simple: doCommand(insertList(schema.nodes.bullet_list, 'simple')),
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
id: 'insert-ordered-list',
|
|
315
|
+
label: 'Ordered List',
|
|
316
|
+
isEnabled: isCommandValid(insertList(schema.nodes.ordered_list)),
|
|
317
|
+
submenu: [
|
|
318
|
+
{
|
|
319
|
+
id: 'ordered-list-context-menu',
|
|
320
|
+
label: '',
|
|
321
|
+
isEnabled: true,
|
|
322
|
+
options: {
|
|
323
|
+
order: doCommand(insertList(schema.nodes.ordered_list, 'order')),
|
|
324
|
+
'alpha-upper': doCommand(insertList(schema.nodes.ordered_list, 'alpha-upper')),
|
|
325
|
+
'alpha-lower': doCommand(insertList(schema.nodes.ordered_list, 'alpha-lower')),
|
|
326
|
+
'roman-upper': doCommand(insertList(schema.nodes.ordered_list, 'roman-upper')),
|
|
327
|
+
'roman-lower': doCommand(insertList(schema.nodes.ordered_list, 'roman-lower')),
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
role: 'separator',
|
|
334
|
+
},
|
|
322
335
|
{
|
|
323
336
|
id: 'format-table',
|
|
324
337
|
label: 'Table',
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
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';
|
|
18
20
|
export const findTableInlineFootnoteIds = ($pos) => {
|
|
19
21
|
var _a;
|
|
20
22
|
const tableElement = (_a = findParentNodeClosestToPos($pos, (node) => node.type === schema.nodes.table_element)) === null || _a === void 0 ? void 0 : _a.node.firstChild;
|
|
@@ -24,3 +26,63 @@ export const findTableInlineFootnoteIds = ($pos) => {
|
|
|
24
26
|
.flat()
|
|
25
27
|
: []);
|
|
26
28
|
};
|
|
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
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
};
|
package/dist/es/toolbar.js
CHANGED
|
@@ -62,8 +62,12 @@ export const toolbar = {
|
|
|
62
62
|
title: 'Wrap in bullet list',
|
|
63
63
|
content: icons.bullet_list,
|
|
64
64
|
isActive: blockActive(schema.nodes.bullet_list),
|
|
65
|
-
isEnabled: insertList(schema.nodes.bullet_list),
|
|
66
|
-
run: insertList(schema.nodes.bullet_list),
|
|
65
|
+
isEnabled: insertList(schema.nodes.bullet_list, 'bullet'),
|
|
66
|
+
run: insertList(schema.nodes.bullet_list, 'bullet'),
|
|
67
|
+
options: {
|
|
68
|
+
bullet: insertList(schema.nodes.bullet_list, 'bullet'),
|
|
69
|
+
simple: insertList(schema.nodes.bullet_list, 'simple'),
|
|
70
|
+
},
|
|
67
71
|
},
|
|
68
72
|
ordered_list: {
|
|
69
73
|
title: 'Wrap in ordered list',
|
|
@@ -15,13 +15,22 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import BlockView from './block_view';
|
|
17
17
|
import { createNodeOrElementView } from './creators';
|
|
18
|
+
import { JATS_HTML_LIST_STYLE_MAPPING } from './ordered_list';
|
|
18
19
|
export class BulletListView extends BlockView {
|
|
19
20
|
constructor() {
|
|
20
21
|
super(...arguments);
|
|
21
22
|
this.elementType = 'ul';
|
|
23
|
+
this.updateContents = () => {
|
|
24
|
+
if (this.contentDOM) {
|
|
25
|
+
const type = this.node.attrs.listStyleType || 'bullet';
|
|
26
|
+
this.contentDOM.style.listStyleType = JATS_HTML_LIST_STYLE_MAPPING[type];
|
|
27
|
+
}
|
|
28
|
+
};
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
export const bulletListCallback = (node, dom) => {
|
|
25
32
|
dom.classList.add('list');
|
|
33
|
+
const type = node.attrs.listStyleType || 'bullet';
|
|
34
|
+
dom.style.listStyleType = JATS_HTML_LIST_STYLE_MAPPING[type];
|
|
26
35
|
};
|
|
27
36
|
export default createNodeOrElementView(BulletListView, 'ul', bulletListCallback);
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ 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';
|
|
22
23
|
import { EditorAction } from './types';
|
|
23
24
|
export type Dispatch = (tr: ManuscriptTransaction) => void;
|
|
24
25
|
export declare const markActive: (type: ManuscriptMarkType) => (state: ManuscriptEditorState) => boolean;
|
|
@@ -56,4 +57,4 @@ export declare const deleteHighlightMarkers: (rid: string) => Command;
|
|
|
56
57
|
export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch): boolean;
|
|
57
58
|
export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch, viewNode?: ManuscriptNode, resolvePos?: ResolvedPos): boolean;
|
|
58
59
|
export declare const updateCommentAnnotationState: (state: ManuscriptEditorState, dispatch?: Dispatch) => void;
|
|
59
|
-
export declare const insertTableFootnote: (node: ManuscriptNode, position: number,
|
|
60
|
+
export declare const insertTableFootnote: (node: ManuscriptNode, position: number, view: EditorView) => void;
|
|
@@ -13,5 +13,12 @@
|
|
|
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';
|
|
16
17
|
import { ResolvedPos } from 'prosemirror-model';
|
|
18
|
+
import { Transaction } from 'prosemirror-state';
|
|
19
|
+
import { ContentNodeWithPos, NodeWithPos } from 'prosemirror-utils';
|
|
17
20
|
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;
|
|
@@ -18,6 +18,7 @@ import { BaseNodeProps } from './base_node_view';
|
|
|
18
18
|
import BlockView from './block_view';
|
|
19
19
|
export declare class BulletListView<PropsType extends BaseNodeProps> extends BlockView<PropsType> {
|
|
20
20
|
elementType: string;
|
|
21
|
+
updateContents: () => void;
|
|
21
22
|
}
|
|
22
23
|
export declare const bulletListCallback: (node: ManuscriptNode, dom: HTMLElement) => void;
|
|
23
24
|
declare const _default: (props: BaseNodeProps) => import("../types").NodeViewCreator<BulletListView<any>>;
|
|
@@ -17,7 +17,7 @@ import { ListElement } from '@manuscripts/json-schema';
|
|
|
17
17
|
import { ManuscriptNode } from '@manuscripts/transform';
|
|
18
18
|
import { BaseNodeProps } from './base_node_view';
|
|
19
19
|
import BlockView from './block_view';
|
|
20
|
-
type JatsStyleType = NonNullable<ListElement['listStyleType']>;
|
|
20
|
+
export type JatsStyleType = NonNullable<ListElement['listStyleType']>;
|
|
21
21
|
export declare const JATS_HTML_LIST_STYLE_MAPPING: {
|
|
22
22
|
[key in JatsStyleType]: string;
|
|
23
23
|
};
|
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.28",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@iarna/word-count": "^1.1.2",
|
|
31
31
|
"@manuscripts/assets": "^0.6.4",
|
|
32
|
-
"@manuscripts/json-schema": "^2.2.
|
|
33
|
-
"@manuscripts/library": "^1.3.
|
|
34
|
-
"@manuscripts/style-guide": "1.8.
|
|
32
|
+
"@manuscripts/json-schema": "^2.2.7",
|
|
33
|
+
"@manuscripts/library": "^1.3.6",
|
|
34
|
+
"@manuscripts/style-guide": "^1.8.3",
|
|
35
35
|
"@manuscripts/track-changes-plugin": "1.7.8",
|
|
36
|
-
"@manuscripts/transform": "^2.1.
|
|
36
|
+
"@manuscripts/transform": "^2.1.10",
|
|
37
37
|
"astrocite-eutils": "^0.16.4",
|
|
38
38
|
"axios": "^1.6.7",
|
|
39
39
|
"mathjax-full": "^3.2.2",
|