@manuscripts/body-editor 1.7.5 → 1.7.6-LEAN-3342-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 +62 -1
- package/dist/cjs/lib/context-menu.js +29 -0
- package/dist/cjs/plugins/footnotes/index.js +13 -3
- package/dist/cjs/plugins/placeholder.js +3 -1
- package/dist/es/commands.js +59 -0
- package/dist/es/lib/context-menu.js +30 -1
- package/dist/es/plugins/footnotes/index.js +13 -3
- package/dist/es/plugins/placeholder.js +1 -1
- package/dist/types/commands.d.ts +3 -0
- package/dist/types/plugins/placeholder.d.ts +2 -0
- package/package.json +2 -2
- package/styles/Editor.css +1 -0
package/dist/cjs/commands.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.updateCommentAnnotationState = exports.addComment = exports.deleteHighlightMarkers = exports.insertHighlight = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.ifInTableBody = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertFileAsFigure = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
|
|
18
|
+
exports.insertTableFootnote = exports.updateCommentAnnotationState = exports.addComment = exports.deleteHighlightMarkers = exports.insertHighlight = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.ifInTableBody = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertFileAsFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
|
|
19
19
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
20
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
21
21
|
const transform_1 = require("@manuscripts/transform");
|
|
@@ -122,6 +122,29 @@ const createBlock = (nodeType, position, state, dispatch) => {
|
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
124
|
exports.createBlock = createBlock;
|
|
125
|
+
const insertGeneralFootnote = (tableNode, position, state, dispatch, tableElementFooter, view) => {
|
|
126
|
+
var _a;
|
|
127
|
+
const generalNote = state.schema.nodes.paragraph.create();
|
|
128
|
+
const tr = state.tr;
|
|
129
|
+
const pos = (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length)
|
|
130
|
+
? position + tableElementFooter[0].pos + 2
|
|
131
|
+
: position + (((_a = tableNode.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize) || 0);
|
|
132
|
+
if (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length) {
|
|
133
|
+
tr.insert(pos, generalNote);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const tableElementFooter = transform_1.schema.nodes.table_element_footer.create({
|
|
137
|
+
id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.TableElementFooter),
|
|
138
|
+
}, [generalNote]);
|
|
139
|
+
tr.insert(pos, tableElementFooter);
|
|
140
|
+
}
|
|
141
|
+
if (dispatch && pos) {
|
|
142
|
+
const selection = (0, exports.createSelection)(state.schema.nodes.paragraph, pos, tr.doc);
|
|
143
|
+
view === null || view === void 0 ? void 0 : view.focus();
|
|
144
|
+
dispatch(tr.setSelection(selection).scrollIntoView());
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
exports.insertGeneralFootnote = insertGeneralFootnote;
|
|
125
148
|
const insertFileAsFigure = (file, state, dispatch) => {
|
|
126
149
|
const position = findBlockInsertPosition(state);
|
|
127
150
|
if (position === null || !dispatch) {
|
|
@@ -688,3 +711,41 @@ const updateCommentAnnotationState = (state, dispatch) => {
|
|
|
688
711
|
}
|
|
689
712
|
};
|
|
690
713
|
exports.updateCommentAnnotationState = updateCommentAnnotationState;
|
|
714
|
+
const insertTableFootnote = (node, position, state, dispatch) => {
|
|
715
|
+
var _a;
|
|
716
|
+
const footnote = state.schema.nodes.footnote.createAndFill({
|
|
717
|
+
id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Footnote),
|
|
718
|
+
kind: 'footnote',
|
|
719
|
+
});
|
|
720
|
+
const insertedAt = state.selection.to;
|
|
721
|
+
const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote);
|
|
722
|
+
const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
|
|
723
|
+
rids: [footnote.attrs.id],
|
|
724
|
+
contents: inlineFootnotes.length + 1,
|
|
725
|
+
});
|
|
726
|
+
const tr = state.tr;
|
|
727
|
+
tr.insert(insertedAt, inlineFootnoteNode);
|
|
728
|
+
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
729
|
+
const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_element_footer);
|
|
730
|
+
let insertionPos;
|
|
731
|
+
if (tableElementFooter.length) {
|
|
732
|
+
const pos = tableElementFooter[0].pos;
|
|
733
|
+
insertionPos = position + pos + tableElementFooter[0].node.nodeSize + 1;
|
|
734
|
+
tr.insert(insertionPos, footnoteElement);
|
|
735
|
+
}
|
|
736
|
+
else {
|
|
737
|
+
const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
|
|
738
|
+
if (tableSize) {
|
|
739
|
+
insertionPos = position + tableSize + 2;
|
|
740
|
+
const tableElementFooter = transform_1.schema.nodes.table_element_footer.create({
|
|
741
|
+
id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.TableElementFooter),
|
|
742
|
+
}, [footnoteElement]);
|
|
743
|
+
tr.insert(insertionPos, tableElementFooter);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
if (dispatch && insertionPos) {
|
|
747
|
+
const nodeSelection = prosemirror_state_1.NodeSelection.create(tr.doc, insertionPos);
|
|
748
|
+
dispatch(tr.setSelection(nodeSelection));
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
exports.insertTableFootnote = insertTableFootnote;
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.ContextMenu = exports.sectionLevel = void 0;
|
|
19
19
|
const transform_1 = require("@manuscripts/transform");
|
|
20
|
+
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
20
21
|
const commands_1 = require("../commands");
|
|
21
22
|
const popper_1 = require("./popper");
|
|
22
23
|
const popper = new popper_1.PopperManager();
|
|
@@ -134,6 +135,7 @@ class ContextMenu {
|
|
|
134
135
|
this.addPopperEventListeners();
|
|
135
136
|
};
|
|
136
137
|
this.showEditMenu = (target) => {
|
|
138
|
+
var _a;
|
|
137
139
|
const menu = document.createElement('div');
|
|
138
140
|
menu.className = 'menu';
|
|
139
141
|
const $pos = this.resolvePos();
|
|
@@ -164,6 +166,33 @@ class ContextMenu {
|
|
|
164
166
|
}));
|
|
165
167
|
}));
|
|
166
168
|
}
|
|
169
|
+
if (type === transform_1.schema.nodes.table_element) {
|
|
170
|
+
const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.table_element_footer);
|
|
171
|
+
const hasGeneralNote = tableElementFooter.length &&
|
|
172
|
+
((_a = tableElementFooter[0].node.firstChild) === null || _a === void 0 ? void 0 : _a.type) === transform_1.schema.nodes.paragraph;
|
|
173
|
+
if (!hasGeneralNote) {
|
|
174
|
+
menu.appendChild(this.createMenuSection((section) => {
|
|
175
|
+
section.appendChild(this.createMenuItem('Add General Note', () => {
|
|
176
|
+
const { state, dispatch } = this.view;
|
|
177
|
+
(0, commands_1.insertGeneralFootnote)(this.node, this.getPos(), state, dispatch, tableElementFooter, this.view);
|
|
178
|
+
}));
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (type === transform_1.schema.nodes.table_element) {
|
|
183
|
+
const isInTable = (0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.table)(this.view.state.selection);
|
|
184
|
+
if (isInTable) {
|
|
185
|
+
menu.appendChild(this.createMenuSection((section) => {
|
|
186
|
+
section.appendChild(this.createMenuItem('Add Reference Note', () => {
|
|
187
|
+
const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.footnotes_element);
|
|
188
|
+
if (!footnotesElement.length) {
|
|
189
|
+
const { state, dispatch } = this.view;
|
|
190
|
+
(0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
|
|
191
|
+
}
|
|
192
|
+
}));
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
167
196
|
if (!readonlyTypes.includes(type) &&
|
|
168
197
|
!readonlyTypes.includes($pos.parent.type)) {
|
|
169
198
|
menu.appendChild(this.createMenuSection((section) => {
|
|
@@ -22,6 +22,7 @@ const prosemirror_state_1 = require("prosemirror-state");
|
|
|
22
22
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
23
23
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
24
24
|
const utils_1 = require("../../lib/utils");
|
|
25
|
+
const placeholder_1 = require("../placeholder");
|
|
25
26
|
exports.footnotesKey = new prosemirror_state_1.PluginKey('footnotes');
|
|
26
27
|
const buildPluginState = (doc) => {
|
|
27
28
|
const nodes = [];
|
|
@@ -101,9 +102,10 @@ exports.default = () => {
|
|
|
101
102
|
}
|
|
102
103
|
const { labels } = exports.footnotesKey.getState(state);
|
|
103
104
|
state.doc.descendants((node, pos) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
var _a, _b;
|
|
106
|
+
if ((0, transform_1.isFootnoteNode)(node)) {
|
|
107
|
+
const id = node.attrs.id;
|
|
108
|
+
if (labels) {
|
|
107
109
|
const label = labels.get(id);
|
|
108
110
|
if (label) {
|
|
109
111
|
decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, labelWidget(label, id), {
|
|
@@ -111,12 +113,20 @@ exports.default = () => {
|
|
|
111
113
|
}));
|
|
112
114
|
}
|
|
113
115
|
}
|
|
116
|
+
if (!((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.textContent)) {
|
|
117
|
+
decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, placeholder_1.placeholderWidget)('Add new note here')));
|
|
118
|
+
}
|
|
114
119
|
}
|
|
115
120
|
if (node.type === transform_1.schema.nodes.footnotes_element) {
|
|
116
121
|
decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
|
|
117
122
|
class: 'footnote-element',
|
|
118
123
|
}));
|
|
119
124
|
}
|
|
125
|
+
if (node.type === transform_1.schema.nodes.table_element_footer) {
|
|
126
|
+
if (((_b = node.firstChild) === null || _b === void 0 ? void 0 : _b.type) === transform_1.schema.nodes.paragraph) {
|
|
127
|
+
decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, placeholder_1.placeholderWidget)('Add general note here')));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
120
130
|
});
|
|
121
131
|
return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
|
|
122
132
|
},
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.placeholderWidget = void 0;
|
|
18
19
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
19
20
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
20
21
|
const placeholderWidget = (placeholder) => (view, getPos) => {
|
|
@@ -27,6 +28,7 @@ const placeholderWidget = (placeholder) => (view, getPos) => {
|
|
|
27
28
|
});
|
|
28
29
|
return element;
|
|
29
30
|
};
|
|
31
|
+
exports.placeholderWidget = placeholderWidget;
|
|
30
32
|
exports.default = () => new prosemirror_state_1.Plugin({
|
|
31
33
|
props: {
|
|
32
34
|
decorations: (state) => {
|
|
@@ -38,7 +40,7 @@ exports.default = () => new prosemirror_state_1.Plugin({
|
|
|
38
40
|
node.type.isBlock &&
|
|
39
41
|
node.childCount === 0) {
|
|
40
42
|
if (node.type === node.type.schema.nodes.paragraph) {
|
|
41
|
-
decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, placeholderWidget(placeholder)));
|
|
43
|
+
decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, (0, exports.placeholderWidget)(placeholder)));
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
46
|
decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
|
package/dist/es/commands.js
CHANGED
|
@@ -113,6 +113,28 @@ export const createBlock = (nodeType, position, state, dispatch) => {
|
|
|
113
113
|
dispatch(tr.setSelection(selection).scrollIntoView());
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
|
+
export const insertGeneralFootnote = (tableNode, position, state, dispatch, tableElementFooter, view) => {
|
|
117
|
+
var _a;
|
|
118
|
+
const generalNote = state.schema.nodes.paragraph.create();
|
|
119
|
+
const tr = state.tr;
|
|
120
|
+
const pos = (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length)
|
|
121
|
+
? position + tableElementFooter[0].pos + 2
|
|
122
|
+
: position + (((_a = tableNode.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize) || 0);
|
|
123
|
+
if (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length) {
|
|
124
|
+
tr.insert(pos, generalNote);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const tableElementFooter = schema.nodes.table_element_footer.create({
|
|
128
|
+
id: generateID(ObjectTypes.TableElementFooter),
|
|
129
|
+
}, [generalNote]);
|
|
130
|
+
tr.insert(pos, tableElementFooter);
|
|
131
|
+
}
|
|
132
|
+
if (dispatch && pos) {
|
|
133
|
+
const selection = createSelection(state.schema.nodes.paragraph, pos, tr.doc);
|
|
134
|
+
view === null || view === void 0 ? void 0 : view.focus();
|
|
135
|
+
dispatch(tr.setSelection(selection).scrollIntoView());
|
|
136
|
+
}
|
|
137
|
+
};
|
|
116
138
|
export const insertFileAsFigure = (file, state, dispatch) => {
|
|
117
139
|
const position = findBlockInsertPosition(state);
|
|
118
140
|
if (position === null || !dispatch) {
|
|
@@ -652,3 +674,40 @@ export const updateCommentAnnotationState = (state, dispatch) => {
|
|
|
652
674
|
dispatch(tr);
|
|
653
675
|
}
|
|
654
676
|
};
|
|
677
|
+
export const insertTableFootnote = (node, position, state, dispatch) => {
|
|
678
|
+
var _a;
|
|
679
|
+
const footnote = state.schema.nodes.footnote.createAndFill({
|
|
680
|
+
id: generateID(ObjectTypes.Footnote),
|
|
681
|
+
kind: 'footnote',
|
|
682
|
+
});
|
|
683
|
+
const insertedAt = state.selection.to;
|
|
684
|
+
const inlineFootnotes = findChildrenByType(node, schema.nodes.inline_footnote);
|
|
685
|
+
const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
|
|
686
|
+
rids: [footnote.attrs.id],
|
|
687
|
+
contents: inlineFootnotes.length + 1,
|
|
688
|
+
});
|
|
689
|
+
const tr = state.tr;
|
|
690
|
+
tr.insert(insertedAt, inlineFootnoteNode);
|
|
691
|
+
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
692
|
+
const tableElementFooter = findChildrenByType(node, schema.nodes.table_element_footer);
|
|
693
|
+
let insertionPos;
|
|
694
|
+
if (tableElementFooter.length) {
|
|
695
|
+
const pos = tableElementFooter[0].pos;
|
|
696
|
+
insertionPos = position + pos + tableElementFooter[0].node.nodeSize + 1;
|
|
697
|
+
tr.insert(insertionPos, footnoteElement);
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
|
|
701
|
+
if (tableSize) {
|
|
702
|
+
insertionPos = position + tableSize + 2;
|
|
703
|
+
const tableElementFooter = schema.nodes.table_element_footer.create({
|
|
704
|
+
id: generateID(ObjectTypes.TableElementFooter),
|
|
705
|
+
}, [footnoteElement]);
|
|
706
|
+
tr.insert(insertionPos, tableElementFooter);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (dispatch && insertionPos) {
|
|
710
|
+
const nodeSelection = NodeSelection.create(tr.doc, insertionPos);
|
|
711
|
+
dispatch(tr.setSelection(nodeSelection));
|
|
712
|
+
}
|
|
713
|
+
};
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { isInBibliographySection, nodeNames, schema, } from '@manuscripts/transform';
|
|
17
|
-
import {
|
|
17
|
+
import { findChildrenByType, hasParentNodeOfType } from 'prosemirror-utils';
|
|
18
|
+
import { addComment, createBlock, insertGeneralFootnote, insertTableFootnote, } from '../commands';
|
|
18
19
|
import { PopperManager } from './popper';
|
|
19
20
|
const popper = new PopperManager();
|
|
20
21
|
const listTypes = [schema.nodes.ordered_list, schema.nodes.bullet_list];
|
|
@@ -130,6 +131,7 @@ export class ContextMenu {
|
|
|
130
131
|
this.addPopperEventListeners();
|
|
131
132
|
};
|
|
132
133
|
this.showEditMenu = (target) => {
|
|
134
|
+
var _a;
|
|
133
135
|
const menu = document.createElement('div');
|
|
134
136
|
menu.className = 'menu';
|
|
135
137
|
const $pos = this.resolvePos();
|
|
@@ -160,6 +162,33 @@ export class ContextMenu {
|
|
|
160
162
|
}));
|
|
161
163
|
}));
|
|
162
164
|
}
|
|
165
|
+
if (type === schema.nodes.table_element) {
|
|
166
|
+
const tableElementFooter = findChildrenByType(this.node, schema.nodes.table_element_footer);
|
|
167
|
+
const hasGeneralNote = tableElementFooter.length &&
|
|
168
|
+
((_a = tableElementFooter[0].node.firstChild) === null || _a === void 0 ? void 0 : _a.type) === schema.nodes.paragraph;
|
|
169
|
+
if (!hasGeneralNote) {
|
|
170
|
+
menu.appendChild(this.createMenuSection((section) => {
|
|
171
|
+
section.appendChild(this.createMenuItem('Add General Note', () => {
|
|
172
|
+
const { state, dispatch } = this.view;
|
|
173
|
+
insertGeneralFootnote(this.node, this.getPos(), state, dispatch, tableElementFooter, this.view);
|
|
174
|
+
}));
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (type === schema.nodes.table_element) {
|
|
179
|
+
const isInTable = hasParentNodeOfType(schema.nodes.table)(this.view.state.selection);
|
|
180
|
+
if (isInTable) {
|
|
181
|
+
menu.appendChild(this.createMenuSection((section) => {
|
|
182
|
+
section.appendChild(this.createMenuItem('Add Reference Note', () => {
|
|
183
|
+
const footnotesElement = findChildrenByType(this.node, schema.nodes.footnotes_element);
|
|
184
|
+
if (!footnotesElement.length) {
|
|
185
|
+
const { state, dispatch } = this.view;
|
|
186
|
+
insertTableFootnote(this.node, this.getPos(), state, dispatch);
|
|
187
|
+
}
|
|
188
|
+
}));
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
163
192
|
if (!readonlyTypes.includes(type) &&
|
|
164
193
|
!readonlyTypes.includes($pos.parent.type)) {
|
|
165
194
|
menu.appendChild(this.createMenuSection((section) => {
|
|
@@ -19,6 +19,7 @@ import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
|
19
19
|
import { hasParentNodeOfType } from 'prosemirror-utils';
|
|
20
20
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
21
21
|
import { findParentNodeWithIdValue } from '../../lib/utils';
|
|
22
|
+
import { placeholderWidget } from '../placeholder';
|
|
22
23
|
export const footnotesKey = new PluginKey('footnotes');
|
|
23
24
|
export const buildPluginState = (doc) => {
|
|
24
25
|
const nodes = [];
|
|
@@ -97,9 +98,10 @@ export default () => {
|
|
|
97
98
|
}
|
|
98
99
|
const { labels } = footnotesKey.getState(state);
|
|
99
100
|
state.doc.descendants((node, pos) => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
var _a, _b;
|
|
102
|
+
if (isFootnoteNode(node)) {
|
|
103
|
+
const id = node.attrs.id;
|
|
104
|
+
if (labels) {
|
|
103
105
|
const label = labels.get(id);
|
|
104
106
|
if (label) {
|
|
105
107
|
decorations.push(Decoration.widget(pos + 2, labelWidget(label, id), {
|
|
@@ -107,12 +109,20 @@ export default () => {
|
|
|
107
109
|
}));
|
|
108
110
|
}
|
|
109
111
|
}
|
|
112
|
+
if (!((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.textContent)) {
|
|
113
|
+
decorations.push(Decoration.widget(pos + 2, placeholderWidget('Add new note here')));
|
|
114
|
+
}
|
|
110
115
|
}
|
|
111
116
|
if (node.type === schema.nodes.footnotes_element) {
|
|
112
117
|
decorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
113
118
|
class: 'footnote-element',
|
|
114
119
|
}));
|
|
115
120
|
}
|
|
121
|
+
if (node.type === schema.nodes.table_element_footer) {
|
|
122
|
+
if (((_b = node.firstChild) === null || _b === void 0 ? void 0 : _b.type) === schema.nodes.paragraph) {
|
|
123
|
+
decorations.push(Decoration.widget(pos + 2, placeholderWidget('Add general note here')));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
116
126
|
});
|
|
117
127
|
return DecorationSet.create(state.doc, decorations);
|
|
118
128
|
},
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { Plugin, TextSelection } from 'prosemirror-state';
|
|
17
17
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
18
|
-
const placeholderWidget = (placeholder) => (view, getPos) => {
|
|
18
|
+
export const placeholderWidget = (placeholder) => (view, getPos) => {
|
|
19
19
|
const element = document.createElement('span');
|
|
20
20
|
element.className = 'placeholder-text';
|
|
21
21
|
element.textContent = placeholder;
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { FileAttachment } from '@manuscripts/style-guide';
|
|
|
18
18
|
import { ManuscriptEditorState, ManuscriptEditorView, ManuscriptMarkType, ManuscriptNode, ManuscriptNodeType, ManuscriptTransaction } from '@manuscripts/transform';
|
|
19
19
|
import { ResolvedPos } from 'prosemirror-model';
|
|
20
20
|
import { Command, NodeSelection, Selection, TextSelection, Transaction } from 'prosemirror-state';
|
|
21
|
+
import { NodeWithPos } from 'prosemirror-utils';
|
|
21
22
|
import { EditorAction } from './types';
|
|
22
23
|
export type Dispatch = (tr: ManuscriptTransaction) => void;
|
|
23
24
|
export declare const markActive: (type: ManuscriptMarkType) => (state: ManuscriptEditorState) => boolean;
|
|
@@ -26,6 +27,7 @@ export declare const blockActive: (type: ManuscriptNodeType) => (state: Manuscri
|
|
|
26
27
|
export declare const canInsert: (type: ManuscriptNodeType) => (state: ManuscriptEditorState) => boolean;
|
|
27
28
|
export declare const createSelection: (nodeType: ManuscriptNodeType, position: number, doc: ManuscriptNode) => Selection;
|
|
28
29
|
export declare const createBlock: (nodeType: ManuscriptNodeType, position: number, state: ManuscriptEditorState, dispatch?: Dispatch) => void;
|
|
30
|
+
export declare const insertGeneralFootnote: (tableNode: ManuscriptNode, position: number, state: ManuscriptEditorState, dispatch?: Dispatch, tableElementFooter?: NodeWithPos[], view?: ManuscriptEditorView) => void;
|
|
29
31
|
export declare const insertFileAsFigure: (file: FileAttachment, state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
|
|
30
32
|
export declare const insertBlock: (nodeType: ManuscriptNodeType) => (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
|
|
31
33
|
export declare const deleteBlock: (typeToDelete: string) => (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
|
|
@@ -54,3 +56,4 @@ export declare const deleteHighlightMarkers: (rid: string) => Command;
|
|
|
54
56
|
export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch): boolean;
|
|
55
57
|
export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch, viewNode?: ManuscriptNode, resolvePos?: ResolvedPos): boolean;
|
|
56
58
|
export declare const updateCommentAnnotationState: (state: ManuscriptEditorState, dispatch?: Dispatch) => void;
|
|
59
|
+
export declare const insertTableFootnote: (node: ManuscriptNode, position: number, state: ManuscriptEditorState, dispatch?: Dispatch) => void;
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { ManuscriptEditorView } from '@manuscripts/transform';
|
|
16
17
|
import { Plugin } from 'prosemirror-state';
|
|
18
|
+
export declare const placeholderWidget: (placeholder: string) => (view: ManuscriptEditorView, getPos: () => number | undefined) => HTMLSpanElement;
|
|
17
19
|
declare const _default: () => Plugin<null>;
|
|
18
20
|
export default _default;
|
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.6-LEAN-3342-0",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -109,4 +109,4 @@
|
|
|
109
109
|
"resolutions": {
|
|
110
110
|
"@types/react": "^17.0.2"
|
|
111
111
|
}
|
|
112
|
-
}
|
|
112
|
+
}
|