@manuscripts/body-editor 1.7.10 → 1.7.12
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 +23 -14
- package/dist/cjs/components/keywords/AddKeywordInline.js +1 -1
- package/dist/cjs/lib/context-menu.js +44 -1
- package/dist/cjs/views/editable_block.js +1 -1
- package/dist/es/commands.js +23 -14
- package/dist/es/components/keywords/AddKeywordInline.js +1 -1
- package/dist/es/lib/context-menu.js +41 -1
- package/dist/es/views/editable_block.js +1 -1
- package/dist/types/lib/context-menu.d.ts +3 -1
- package/dist/types/views/editable_block.d.ts +1 -1
- package/package.json +3 -3
- package/styles/popper.css +10 -3
package/dist/cjs/commands.js
CHANGED
|
@@ -722,28 +722,37 @@ const insertTableFootnote = (node, position, state, dispatch) => {
|
|
|
722
722
|
});
|
|
723
723
|
const insertedAt = state.selection.to;
|
|
724
724
|
const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote);
|
|
725
|
+
const labels = inlineFootnotes.map((nodeWithPos) => nodeWithPos.node.attrs.contents);
|
|
725
726
|
const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
|
|
726
727
|
rids: [footnote.attrs.id],
|
|
727
|
-
contents:
|
|
728
|
+
contents: labels.length ? Math.max(...labels) + 1 : 1,
|
|
728
729
|
});
|
|
729
730
|
const tr = state.tr;
|
|
730
731
|
tr.insert(insertedAt, inlineFootnoteNode);
|
|
731
|
-
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
732
|
-
const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_element_footer);
|
|
733
732
|
let insertionPos;
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
733
|
+
const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.footnotes_element);
|
|
734
|
+
if (footnotesElement.length) {
|
|
735
|
+
const pos = footnotesElement[0].pos;
|
|
736
|
+
insertionPos = position + pos + footnotesElement[0].node.nodeSize + 1;
|
|
737
|
+
tr.insert(insertionPos, footnote);
|
|
738
738
|
}
|
|
739
739
|
else {
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
740
|
+
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
741
|
+
const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_element_footer);
|
|
742
|
+
if (tableElementFooter.length) {
|
|
743
|
+
const pos = tableElementFooter[0].pos;
|
|
744
|
+
insertionPos = position + pos + tableElementFooter[0].node.nodeSize + 1;
|
|
745
|
+
tr.insert(insertionPos, footnoteElement);
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
|
|
749
|
+
if (tableSize) {
|
|
750
|
+
insertionPos = position + tableSize + 2;
|
|
751
|
+
const tableElementFooter = transform_1.schema.nodes.table_element_footer.create({
|
|
752
|
+
id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.TableElementFooter),
|
|
753
|
+
}, [footnoteElement]);
|
|
754
|
+
tr.insert(insertionPos, tableElementFooter);
|
|
755
|
+
}
|
|
747
756
|
}
|
|
748
757
|
}
|
|
749
758
|
if (dispatch && insertionPos) {
|
|
@@ -14,11 +14,16 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
17
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
21
|
exports.ContextMenu = exports.sectionLevel = void 0;
|
|
22
|
+
const style_guide_1 = require("@manuscripts/style-guide");
|
|
19
23
|
const transform_1 = require("@manuscripts/transform");
|
|
20
24
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
21
25
|
const commands_1 = require("../commands");
|
|
26
|
+
const ReactSubView_1 = __importDefault(require("../views/ReactSubView"));
|
|
22
27
|
const popper_1 = require("./popper");
|
|
23
28
|
const popper = new popper_1.PopperManager();
|
|
24
29
|
const listTypes = [transform_1.schema.nodes.ordered_list, transform_1.schema.nodes.bullet_list];
|
|
@@ -36,7 +41,7 @@ const hasAny = (set, ...items) => {
|
|
|
36
41
|
return items.some((i) => set.has(i));
|
|
37
42
|
};
|
|
38
43
|
class ContextMenu {
|
|
39
|
-
constructor(node, view, getPos, actions = {}) {
|
|
44
|
+
constructor(node, view, getPos, actions = {}, props) {
|
|
40
45
|
this.showAddMenu = (target, after) => {
|
|
41
46
|
const menu = document.createElement('div');
|
|
42
47
|
menu.className = 'menu';
|
|
@@ -181,11 +186,48 @@ class ContextMenu {
|
|
|
181
186
|
if (isInTable) {
|
|
182
187
|
menu.appendChild(this.createMenuSection((section) => {
|
|
183
188
|
section.appendChild(this.createMenuItem('Add Reference Note', () => {
|
|
189
|
+
var _a;
|
|
184
190
|
const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.footnotes_element);
|
|
185
191
|
if (!footnotesElement.length) {
|
|
186
192
|
const { state, dispatch } = this.view;
|
|
187
193
|
(0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
|
|
188
194
|
}
|
|
195
|
+
else {
|
|
196
|
+
const footnotes = (0, prosemirror_utils_1.findChildrenByType)(footnotesElement[0].node, transform_1.schema.nodes.footnote).map((nodeWithPos) => {
|
|
197
|
+
return nodeWithPos.node;
|
|
198
|
+
});
|
|
199
|
+
const targetDom = this.view.domAtPos(this.view.state.selection.from);
|
|
200
|
+
if (targetDom.node instanceof Element && this.props) {
|
|
201
|
+
const popperContainer = (0, ReactSubView_1.default)(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), style_guide_1.TableFootnotesSelector, {
|
|
202
|
+
notes: footnotes,
|
|
203
|
+
onAdd: () => {
|
|
204
|
+
var _a;
|
|
205
|
+
const { state, dispatch } = this.view;
|
|
206
|
+
(0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
|
|
207
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
208
|
+
},
|
|
209
|
+
onInsert: (notes) => {
|
|
210
|
+
var _a;
|
|
211
|
+
const insertedAt = this.view.state.selection.to;
|
|
212
|
+
const node = this.view.state.schema.nodes.inline_footnote.create({
|
|
213
|
+
rids: notes.map((note) => note.attrs.id),
|
|
214
|
+
contents: notes
|
|
215
|
+
.map((note) => footnotes.indexOf(note) + 1)
|
|
216
|
+
.join(),
|
|
217
|
+
});
|
|
218
|
+
const tr = this.view.state.tr;
|
|
219
|
+
tr.insert(insertedAt, node);
|
|
220
|
+
this.view.dispatch(tr);
|
|
221
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
222
|
+
},
|
|
223
|
+
onCancel: () => {
|
|
224
|
+
var _a;
|
|
225
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
226
|
+
},
|
|
227
|
+
}, this.node, this.getPos, this.view, 'table-footnote-editor');
|
|
228
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.show(targetDom.node, popperContainer, 'bottom-end');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
189
231
|
}));
|
|
190
232
|
}));
|
|
191
233
|
}
|
|
@@ -306,6 +348,7 @@ class ContextMenu {
|
|
|
306
348
|
this.view = view;
|
|
307
349
|
this.getPos = getPos;
|
|
308
350
|
this.actions = actions;
|
|
351
|
+
this.props = props;
|
|
309
352
|
}
|
|
310
353
|
}
|
|
311
354
|
exports.ContextMenu = ContextMenu;
|
package/dist/es/commands.js
CHANGED
|
@@ -685,28 +685,37 @@ export const insertTableFootnote = (node, position, state, dispatch) => {
|
|
|
685
685
|
});
|
|
686
686
|
const insertedAt = state.selection.to;
|
|
687
687
|
const inlineFootnotes = findChildrenByType(node, schema.nodes.inline_footnote);
|
|
688
|
+
const labels = inlineFootnotes.map((nodeWithPos) => nodeWithPos.node.attrs.contents);
|
|
688
689
|
const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
|
|
689
690
|
rids: [footnote.attrs.id],
|
|
690
|
-
contents:
|
|
691
|
+
contents: labels.length ? Math.max(...labels) + 1 : 1,
|
|
691
692
|
});
|
|
692
693
|
const tr = state.tr;
|
|
693
694
|
tr.insert(insertedAt, inlineFootnoteNode);
|
|
694
|
-
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
695
|
-
const tableElementFooter = findChildrenByType(node, schema.nodes.table_element_footer);
|
|
696
695
|
let insertionPos;
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
696
|
+
const footnotesElement = findChildrenByType(node, schema.nodes.footnotes_element);
|
|
697
|
+
if (footnotesElement.length) {
|
|
698
|
+
const pos = footnotesElement[0].pos;
|
|
699
|
+
insertionPos = position + pos + footnotesElement[0].node.nodeSize + 1;
|
|
700
|
+
tr.insert(insertionPos, footnote);
|
|
701
701
|
}
|
|
702
702
|
else {
|
|
703
|
-
const
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
703
|
+
const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
|
|
704
|
+
const tableElementFooter = findChildrenByType(node, schema.nodes.table_element_footer);
|
|
705
|
+
if (tableElementFooter.length) {
|
|
706
|
+
const pos = tableElementFooter[0].pos;
|
|
707
|
+
insertionPos = position + pos + tableElementFooter[0].node.nodeSize + 1;
|
|
708
|
+
tr.insert(insertionPos, footnoteElement);
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
|
|
712
|
+
if (tableSize) {
|
|
713
|
+
insertionPos = position + tableSize + 2;
|
|
714
|
+
const tableElementFooter = schema.nodes.table_element_footer.create({
|
|
715
|
+
id: generateID(ObjectTypes.TableElementFooter),
|
|
716
|
+
}, [footnoteElement]);
|
|
717
|
+
tr.insert(insertionPos, tableElementFooter);
|
|
718
|
+
}
|
|
710
719
|
}
|
|
711
720
|
}
|
|
712
721
|
if (dispatch && insertionPos) {
|
|
@@ -13,9 +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
17
|
import { isInBibliographySection, nodeNames, schema, } from '@manuscripts/transform';
|
|
17
18
|
import { findChildrenByType, hasParentNodeOfType } from 'prosemirror-utils';
|
|
18
19
|
import { addComment, createBlock, insertGeneralFootnote, insertTableFootnote, } from '../commands';
|
|
20
|
+
import ReactSubView from '../views/ReactSubView';
|
|
19
21
|
import { PopperManager } from './popper';
|
|
20
22
|
const popper = new PopperManager();
|
|
21
23
|
const listTypes = [schema.nodes.ordered_list, schema.nodes.bullet_list];
|
|
@@ -32,7 +34,7 @@ const hasAny = (set, ...items) => {
|
|
|
32
34
|
return items.some((i) => set.has(i));
|
|
33
35
|
};
|
|
34
36
|
export class ContextMenu {
|
|
35
|
-
constructor(node, view, getPos, actions = {}) {
|
|
37
|
+
constructor(node, view, getPos, actions = {}, props) {
|
|
36
38
|
this.showAddMenu = (target, after) => {
|
|
37
39
|
const menu = document.createElement('div');
|
|
38
40
|
menu.className = 'menu';
|
|
@@ -177,11 +179,48 @@ export class ContextMenu {
|
|
|
177
179
|
if (isInTable) {
|
|
178
180
|
menu.appendChild(this.createMenuSection((section) => {
|
|
179
181
|
section.appendChild(this.createMenuItem('Add Reference Note', () => {
|
|
182
|
+
var _a;
|
|
180
183
|
const footnotesElement = findChildrenByType(this.node, schema.nodes.footnotes_element);
|
|
181
184
|
if (!footnotesElement.length) {
|
|
182
185
|
const { state, dispatch } = this.view;
|
|
183
186
|
insertTableFootnote(this.node, this.getPos(), state, dispatch);
|
|
184
187
|
}
|
|
188
|
+
else {
|
|
189
|
+
const footnotes = findChildrenByType(footnotesElement[0].node, schema.nodes.footnote).map((nodeWithPos) => {
|
|
190
|
+
return nodeWithPos.node;
|
|
191
|
+
});
|
|
192
|
+
const targetDom = this.view.domAtPos(this.view.state.selection.from);
|
|
193
|
+
if (targetDom.node instanceof Element && this.props) {
|
|
194
|
+
const popperContainer = ReactSubView(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), TableFootnotesSelector, {
|
|
195
|
+
notes: footnotes,
|
|
196
|
+
onAdd: () => {
|
|
197
|
+
var _a;
|
|
198
|
+
const { state, dispatch } = this.view;
|
|
199
|
+
insertTableFootnote(this.node, this.getPos(), state, dispatch);
|
|
200
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
201
|
+
},
|
|
202
|
+
onInsert: (notes) => {
|
|
203
|
+
var _a;
|
|
204
|
+
const insertedAt = this.view.state.selection.to;
|
|
205
|
+
const node = this.view.state.schema.nodes.inline_footnote.create({
|
|
206
|
+
rids: notes.map((note) => note.attrs.id),
|
|
207
|
+
contents: notes
|
|
208
|
+
.map((note) => footnotes.indexOf(note) + 1)
|
|
209
|
+
.join(),
|
|
210
|
+
});
|
|
211
|
+
const tr = this.view.state.tr;
|
|
212
|
+
tr.insert(insertedAt, node);
|
|
213
|
+
this.view.dispatch(tr);
|
|
214
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
215
|
+
},
|
|
216
|
+
onCancel: () => {
|
|
217
|
+
var _a;
|
|
218
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.destroy();
|
|
219
|
+
},
|
|
220
|
+
}, this.node, this.getPos, this.view, 'table-footnote-editor');
|
|
221
|
+
(_a = this.props) === null || _a === void 0 ? void 0 : _a.popper.show(targetDom.node, popperContainer, 'bottom-end');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
185
224
|
}));
|
|
186
225
|
}));
|
|
187
226
|
}
|
|
@@ -302,5 +341,6 @@ export class ContextMenu {
|
|
|
302
341
|
this.view = view;
|
|
303
342
|
this.getPos = getPos;
|
|
304
343
|
this.actions = actions;
|
|
344
|
+
this.props = props;
|
|
305
345
|
}
|
|
306
346
|
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { CommentAnnotation } from '@manuscripts/json-schema';
|
|
17
17
|
import { ManuscriptEditorView, ManuscriptNode } from '@manuscripts/transform';
|
|
18
|
+
import { EditableBlockProps } from '../views/editable_block';
|
|
18
19
|
export declare const sectionLevel: (depth: number) => string;
|
|
19
20
|
interface Actions {
|
|
20
21
|
setComment?: (comment: CommentAnnotation) => void;
|
|
@@ -24,7 +25,8 @@ export declare class ContextMenu {
|
|
|
24
25
|
private readonly view;
|
|
25
26
|
private readonly getPos;
|
|
26
27
|
private readonly actions;
|
|
27
|
-
|
|
28
|
+
private readonly props?;
|
|
29
|
+
constructor(node: ManuscriptNode, view: ManuscriptEditorView, getPos: () => number, actions?: Actions, props?: EditableBlockProps);
|
|
28
30
|
showAddMenu: (target: Element, after: boolean) => void;
|
|
29
31
|
showEditMenu: (target: Element) => void;
|
|
30
32
|
private createMenuItem;
|
|
@@ -26,7 +26,7 @@ export interface EditableBlockProps extends BaseNodeProps {
|
|
|
26
26
|
retrySync: (componentIDs: string[]) => Promise<void>;
|
|
27
27
|
setComment: (comment: CommentAnnotation) => void;
|
|
28
28
|
dispatch?: Dispatch;
|
|
29
|
-
theme
|
|
29
|
+
theme: DefaultTheme;
|
|
30
30
|
}
|
|
31
31
|
export declare const EditableBlock: <T extends Constructor<BlockView<EditableBlockProps>>>(Base: T) => {
|
|
32
32
|
new (...args: any[]): {
|
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.12",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@manuscripts/assets": "^0.6.4",
|
|
32
32
|
"@manuscripts/json-schema": "^2.2.4",
|
|
33
33
|
"@manuscripts/library": "^1.3.3",
|
|
34
|
-
"@manuscripts/style-guide": "
|
|
34
|
+
"@manuscripts/style-guide": "1.7.7",
|
|
35
35
|
"@manuscripts/track-changes-plugin": "^1.7.5",
|
|
36
36
|
"@manuscripts/transform": "^2.1.2",
|
|
37
37
|
"astrocite-eutils": "^0.16.4",
|
|
@@ -109,4 +109,4 @@
|
|
|
109
109
|
"resolutions": {
|
|
110
110
|
"@types/react": "^17.0.2"
|
|
111
111
|
}
|
|
112
|
-
}
|
|
112
|
+
}
|
package/styles/popper.css
CHANGED
|
@@ -135,7 +135,8 @@
|
|
|
135
135
|
.popper .citation-editor,
|
|
136
136
|
.popper .cross-reference-editor,
|
|
137
137
|
.popper .citation-references,
|
|
138
|
-
.popper .track-changes-review-panel
|
|
138
|
+
.popper .track-changes-review-panel,
|
|
139
|
+
.popper .table-footnote-editor {
|
|
139
140
|
background: #fff;
|
|
140
141
|
border: 1px solid #e2e2e2;
|
|
141
142
|
border-radius: 8px;
|
|
@@ -189,7 +190,8 @@
|
|
|
189
190
|
height: auto;
|
|
190
191
|
}
|
|
191
192
|
|
|
192
|
-
.popper .citation-editor
|
|
193
|
+
.popper .citation-editor,
|
|
194
|
+
.popper .table-footnote-editor {
|
|
193
195
|
width: 600px;
|
|
194
196
|
}
|
|
195
197
|
|
|
@@ -204,7 +206,8 @@
|
|
|
204
206
|
.popper .citation-editor,
|
|
205
207
|
.popper .cross-reference-editor,
|
|
206
208
|
.popper .equation-editor,
|
|
207
|
-
.popper .link-editor
|
|
209
|
+
.popper .link-editor,
|
|
210
|
+
.popper .table-footnote-editor {
|
|
208
211
|
min-width: 90%;
|
|
209
212
|
max-width: 90%;
|
|
210
213
|
}
|
|
@@ -219,6 +222,10 @@
|
|
|
219
222
|
width: 600px;
|
|
220
223
|
}
|
|
221
224
|
|
|
225
|
+
.popper .table-footnote-editor {
|
|
226
|
+
left: 50%;
|
|
227
|
+
transform: translate(-50%, -100%);
|
|
228
|
+
}
|
|
222
229
|
|
|
223
230
|
.popper .track-attrs-popper {
|
|
224
231
|
box-shadow: 0 4px 9px 0 rgba(0, 0, 0, 0.30);
|