@manuscripts/body-editor 1.8.0-LEAN-3354 → 1.8.1
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/lib/context-menu.js +1 -0
- package/dist/cjs/plugins/footnotes/footnotes-utils.js +15 -1
- package/dist/cjs/plugins/footnotes/index.js +32 -6
- package/dist/es/lib/context-menu.js +1 -0
- package/dist/es/plugins/footnotes/footnotes-utils.js +13 -0
- package/dist/es/plugins/footnotes/index.js +34 -8
- package/dist/types/plugins/footnotes/footnotes-utils.d.ts +7 -1
- package/package.json +3 -3
- package/styles/AdvancedEditor.css +0 -1
|
@@ -199,6 +199,7 @@ class ContextMenu {
|
|
|
199
199
|
var _a;
|
|
200
200
|
const footnotesElementWithPos = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.footnotes_element).pop();
|
|
201
201
|
if (!footnotesElementWithPos ||
|
|
202
|
+
!(footnotesElementWithPos === null || footnotesElementWithPos === void 0 ? void 0 : footnotesElementWithPos.node.content.childCount) ||
|
|
202
203
|
(0, track_changes_utils_1.isDeleted)(footnotesElementWithPos.node) ||
|
|
203
204
|
(0, track_changes_utils_1.isRejectedInsert)(footnotesElementWithPos.node)) {
|
|
204
205
|
(0, commands_1.insertTableFootnote)(this.node, this.getPos(), this.view);
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.updateTableInlineFootnoteLabels = exports.orderTableFootnotes = exports.buildTableFootnoteLabels = exports.getNewFootnotePos = exports.findTableInlineFootnoteIds = void 0;
|
|
18
|
+
exports.getInlineFootnotes = exports.updateTableInlineFootnoteLabels = exports.orderTableFootnotes = exports.buildTableFootnoteLabels = exports.getNewFootnotePos = exports.findTableInlineFootnoteIds = void 0;
|
|
19
19
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
20
20
|
const transform_1 = require("@manuscripts/transform");
|
|
21
21
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
@@ -94,3 +94,17 @@ const updateTableInlineFootnoteLabels = (tr, table) => {
|
|
|
94
94
|
return tr;
|
|
95
95
|
};
|
|
96
96
|
exports.updateTableInlineFootnoteLabels = updateTableInlineFootnoteLabels;
|
|
97
|
+
const getInlineFootnotes = (id, tableElement) => {
|
|
98
|
+
const inlineFootnotes = [];
|
|
99
|
+
tableElement.node.content.descendants((node, pos) => {
|
|
100
|
+
var _a;
|
|
101
|
+
if (node.type === transform_1.schema.nodes.inline_footnote) {
|
|
102
|
+
const footnote = node;
|
|
103
|
+
if ((_a = footnote.attrs.rids) === null || _a === void 0 ? void 0 : _a.includes(id)) {
|
|
104
|
+
inlineFootnotes.push({ node: footnote, pos });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return inlineFootnotes;
|
|
109
|
+
};
|
|
110
|
+
exports.getInlineFootnotes = getInlineFootnotes;
|
|
@@ -73,13 +73,13 @@ const uncitedFootnoteWidget = () => () => {
|
|
|
73
73
|
return element;
|
|
74
74
|
};
|
|
75
75
|
exports.uncitedFootnoteWidget = uncitedFootnoteWidget;
|
|
76
|
-
const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage) => (view, getPos) => {
|
|
76
|
+
const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage, id, tableElement) => (view, getPos) => {
|
|
77
77
|
const deleteBtn = document.createElement('span');
|
|
78
78
|
deleteBtn.className = 'delete-icon';
|
|
79
79
|
deleteBtn.innerHTML = assets_1.deleteIcon;
|
|
80
80
|
deleteBtn.addEventListener('click', () => {
|
|
81
81
|
const handleDelete = () => {
|
|
82
|
-
|
|
82
|
+
let tr = view.state.tr;
|
|
83
83
|
const pos = getPos();
|
|
84
84
|
if (node.type === transform_1.schema.nodes.table_element_footer) {
|
|
85
85
|
if (!(0, utils_1.getChildOfType)(node, transform_1.schema.nodes.footnotes_element, true) &&
|
|
@@ -94,6 +94,27 @@ const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage) => (vi
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
if (node.type === transform_1.schema.nodes.footnote && pos) {
|
|
98
|
+
const inlineFootnotes = (0, footnotes_utils_1.getInlineFootnotes)(id, tableElement);
|
|
99
|
+
const nodeWithPos = (0, prosemirror_utils_1.findParentNodeClosestToPos)(tr.doc.resolve(pos), (node) => node.type === transform_1.schema.nodes.footnote);
|
|
100
|
+
if (nodeWithPos) {
|
|
101
|
+
const { pos: fnPos, node: fnNode } = nodeWithPos;
|
|
102
|
+
view.dispatch(tr.delete(fnPos, fnPos + fnNode.nodeSize));
|
|
103
|
+
}
|
|
104
|
+
if (inlineFootnotes) {
|
|
105
|
+
tr = view.state.tr;
|
|
106
|
+
inlineFootnotes.forEach((footnote) => {
|
|
107
|
+
const pos = footnote.pos + tableElement.pos;
|
|
108
|
+
if (footnote.node.attrs.rids.length > 1) {
|
|
109
|
+
const updatedRids = footnote.node.attrs.rids.filter((rid) => rid !== id);
|
|
110
|
+
tr.setNodeMarkup(tr.mapping.map(pos + 1), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
tr.delete(tr.mapping.map(pos + 1), tr.mapping.map(pos + footnote.node.nodeSize + 1));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
97
118
|
view.dispatch(tr);
|
|
98
119
|
};
|
|
99
120
|
const componentProps = {
|
|
@@ -138,7 +159,7 @@ exports.default = (props) => {
|
|
|
138
159
|
decorations: (state) => {
|
|
139
160
|
const decorations = [];
|
|
140
161
|
const isInTableElementFooter = (0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.table_element_footer)(state.selection);
|
|
141
|
-
const
|
|
162
|
+
const tableElement = (0, prosemirror_utils_1.findParentNodeOfType)(transform_1.schema.nodes.table_element)(state.selection);
|
|
142
163
|
if (isInTableElementFooter) {
|
|
143
164
|
const parent = (0, utils_1.findParentNodeWithIdValue)(state.selection);
|
|
144
165
|
if (parent) {
|
|
@@ -171,7 +192,7 @@ exports.default = (props) => {
|
|
|
171
192
|
}
|
|
172
193
|
}
|
|
173
194
|
if (can.editArticle) {
|
|
174
|
-
if (
|
|
195
|
+
if (tableElement) {
|
|
175
196
|
const footnote = (() => {
|
|
176
197
|
switch (node.type) {
|
|
177
198
|
case transform_1.schema.nodes.footnote:
|
|
@@ -186,9 +207,14 @@ exports.default = (props) => {
|
|
|
186
207
|
};
|
|
187
208
|
}
|
|
188
209
|
})();
|
|
189
|
-
if (node.type === transform_1.schema.nodes.
|
|
210
|
+
if (node.type === transform_1.schema.nodes.footnote) {
|
|
211
|
+
decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, deleteFootnoteWidget(node, props, footnote.type, footnote.message, node.attrs.id, tableElement), {
|
|
212
|
+
key: node.attrs.id,
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
else if (node.type === transform_1.schema.nodes.paragraph &&
|
|
190
216
|
(parent === null || parent === void 0 ? void 0 : parent.type) === transform_1.schema.nodes.table_element_footer) {
|
|
191
|
-
decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, deleteFootnoteWidget(parent, props, footnote.type, footnote.message), {
|
|
217
|
+
decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, deleteFootnoteWidget(parent, props, footnote.type, footnote.message, parent.attrs.id, tableElement), {
|
|
192
218
|
key: parent.attrs.id,
|
|
193
219
|
}));
|
|
194
220
|
}
|
|
@@ -192,6 +192,7 @@ export class ContextMenu {
|
|
|
192
192
|
var _a;
|
|
193
193
|
const footnotesElementWithPos = findChildrenByType(this.node, schema.nodes.footnotes_element).pop();
|
|
194
194
|
if (!footnotesElementWithPos ||
|
|
195
|
+
!(footnotesElementWithPos === null || footnotesElementWithPos === void 0 ? void 0 : footnotesElementWithPos.node.content.childCount) ||
|
|
195
196
|
isDeleted(footnotesElementWithPos.node) ||
|
|
196
197
|
isRejectedInsert(footnotesElementWithPos.node)) {
|
|
197
198
|
insertTableFootnote(this.node, this.getPos(), this.view);
|
|
@@ -86,3 +86,16 @@ export const updateTableInlineFootnoteLabels = (tr, table) => {
|
|
|
86
86
|
});
|
|
87
87
|
return tr;
|
|
88
88
|
};
|
|
89
|
+
export const getInlineFootnotes = (id, tableElement) => {
|
|
90
|
+
const inlineFootnotes = [];
|
|
91
|
+
tableElement.node.content.descendants((node, pos) => {
|
|
92
|
+
var _a;
|
|
93
|
+
if (node.type === schema.nodes.inline_footnote) {
|
|
94
|
+
const footnote = node;
|
|
95
|
+
if ((_a = footnote.attrs.rids) === null || _a === void 0 ? void 0 : _a.includes(id)) {
|
|
96
|
+
inlineFootnotes.push({ node: footnote, pos });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return inlineFootnotes;
|
|
101
|
+
};
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
import { isFootnoteNode, isInlineFootnoteNode, schema, } from '@manuscripts/transform';
|
|
17
17
|
import { isEqual } from 'lodash';
|
|
18
18
|
import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
19
|
-
import { hasParentNodeOfType } from 'prosemirror-utils';
|
|
19
|
+
import { findParentNodeClosestToPos, findParentNodeOfType, hasParentNodeOfType, } from 'prosemirror-utils';
|
|
20
20
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
21
21
|
import { alertIcon, deleteIcon } from '../../assets';
|
|
22
22
|
import { DeleteFootnoteDialog, } from '../../components/views/DeleteFootnoteDialog';
|
|
23
23
|
import { findParentNodeWithIdValue, getChildOfType } from '../../lib/utils';
|
|
24
24
|
import ReactSubView from '../../views/ReactSubView';
|
|
25
25
|
import { placeholderWidget } from '../placeholder';
|
|
26
|
-
import { findTableInlineFootnoteIds } from './footnotes-utils';
|
|
26
|
+
import { findTableInlineFootnoteIds, getInlineFootnotes, } from './footnotes-utils';
|
|
27
27
|
export const footnotesKey = new PluginKey('footnotes');
|
|
28
28
|
export const buildPluginState = (doc) => {
|
|
29
29
|
const nodes = [];
|
|
@@ -65,13 +65,13 @@ export const uncitedFootnoteWidget = () => () => {
|
|
|
65
65
|
element.innerHTML = alertIcon;
|
|
66
66
|
return element;
|
|
67
67
|
};
|
|
68
|
-
const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage) => (view, getPos) => {
|
|
68
|
+
const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage, id, tableElement) => (view, getPos) => {
|
|
69
69
|
const deleteBtn = document.createElement('span');
|
|
70
70
|
deleteBtn.className = 'delete-icon';
|
|
71
71
|
deleteBtn.innerHTML = deleteIcon;
|
|
72
72
|
deleteBtn.addEventListener('click', () => {
|
|
73
73
|
const handleDelete = () => {
|
|
74
|
-
|
|
74
|
+
let tr = view.state.tr;
|
|
75
75
|
const pos = getPos();
|
|
76
76
|
if (node.type === schema.nodes.table_element_footer) {
|
|
77
77
|
if (!getChildOfType(node, schema.nodes.footnotes_element, true) &&
|
|
@@ -86,6 +86,27 @@ const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage) => (vi
|
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
if (node.type === schema.nodes.footnote && pos) {
|
|
90
|
+
const inlineFootnotes = getInlineFootnotes(id, tableElement);
|
|
91
|
+
const nodeWithPos = findParentNodeClosestToPos(tr.doc.resolve(pos), (node) => node.type === schema.nodes.footnote);
|
|
92
|
+
if (nodeWithPos) {
|
|
93
|
+
const { pos: fnPos, node: fnNode } = nodeWithPos;
|
|
94
|
+
view.dispatch(tr.delete(fnPos, fnPos + fnNode.nodeSize));
|
|
95
|
+
}
|
|
96
|
+
if (inlineFootnotes) {
|
|
97
|
+
tr = view.state.tr;
|
|
98
|
+
inlineFootnotes.forEach((footnote) => {
|
|
99
|
+
const pos = footnote.pos + tableElement.pos;
|
|
100
|
+
if (footnote.node.attrs.rids.length > 1) {
|
|
101
|
+
const updatedRids = footnote.node.attrs.rids.filter((rid) => rid !== id);
|
|
102
|
+
tr.setNodeMarkup(tr.mapping.map(pos + 1), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
tr.delete(tr.mapping.map(pos + 1), tr.mapping.map(pos + footnote.node.nodeSize + 1));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
89
110
|
view.dispatch(tr);
|
|
90
111
|
};
|
|
91
112
|
const componentProps = {
|
|
@@ -130,7 +151,7 @@ export default (props) => {
|
|
|
130
151
|
decorations: (state) => {
|
|
131
152
|
const decorations = [];
|
|
132
153
|
const isInTableElementFooter = hasParentNodeOfType(schema.nodes.table_element_footer)(state.selection);
|
|
133
|
-
const
|
|
154
|
+
const tableElement = findParentNodeOfType(schema.nodes.table_element)(state.selection);
|
|
134
155
|
if (isInTableElementFooter) {
|
|
135
156
|
const parent = findParentNodeWithIdValue(state.selection);
|
|
136
157
|
if (parent) {
|
|
@@ -163,7 +184,7 @@ export default (props) => {
|
|
|
163
184
|
}
|
|
164
185
|
}
|
|
165
186
|
if (can.editArticle) {
|
|
166
|
-
if (
|
|
187
|
+
if (tableElement) {
|
|
167
188
|
const footnote = (() => {
|
|
168
189
|
switch (node.type) {
|
|
169
190
|
case schema.nodes.footnote:
|
|
@@ -178,9 +199,14 @@ export default (props) => {
|
|
|
178
199
|
};
|
|
179
200
|
}
|
|
180
201
|
})();
|
|
181
|
-
if (node.type === schema.nodes.
|
|
202
|
+
if (node.type === schema.nodes.footnote) {
|
|
203
|
+
decorations.push(Decoration.widget(pos + 2, deleteFootnoteWidget(node, props, footnote.type, footnote.message, node.attrs.id, tableElement), {
|
|
204
|
+
key: node.attrs.id,
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
else if (node.type === schema.nodes.paragraph &&
|
|
182
208
|
(parent === null || parent === void 0 ? void 0 : parent.type) === schema.nodes.table_element_footer) {
|
|
183
|
-
decorations.push(Decoration.widget(pos + 1, deleteFootnoteWidget(parent, props, footnote.type, footnote.message), {
|
|
209
|
+
decorations.push(Decoration.widget(pos + 1, deleteFootnoteWidget(parent, props, footnote.type, footnote.message, parent.attrs.id, tableElement), {
|
|
184
210
|
key: parent.attrs.id,
|
|
185
211
|
}));
|
|
186
212
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
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
|
+
import { InlineFootnoteNode, ManuscriptNode } from '@manuscripts/transform';
|
|
17
17
|
import { ResolvedPos } from 'prosemirror-model';
|
|
18
18
|
import { Transaction } from 'prosemirror-state';
|
|
19
19
|
import { ContentNodeWithPos, NodeWithPos } from 'prosemirror-utils';
|
|
@@ -22,3 +22,9 @@ export declare const getNewFootnotePos: (footnotesElement: NodeWithPos, footnote
|
|
|
22
22
|
export declare const buildTableFootnoteLabels: (node: ManuscriptNode) => Map<string, string | undefined>;
|
|
23
23
|
export declare const orderTableFootnotes: (tr: Transaction, footnotesElementWithPos: NodeWithPos, position: number) => Transaction;
|
|
24
24
|
export declare const updateTableInlineFootnoteLabels: (tr: Transaction, table: ContentNodeWithPos) => Transaction;
|
|
25
|
+
interface InlineFootnote {
|
|
26
|
+
node: InlineFootnoteNode;
|
|
27
|
+
pos: number;
|
|
28
|
+
}
|
|
29
|
+
export declare const getInlineFootnotes: (id: string, tableElement: NodeWithPos) => InlineFootnote[];
|
|
30
|
+
export {};
|
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.8.
|
|
4
|
+
"version": "1.8.1",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@manuscripts/json-schema": "^2.2.7",
|
|
33
33
|
"@manuscripts/library": "^1.3.6",
|
|
34
34
|
"@manuscripts/style-guide": "1.11.1",
|
|
35
|
-
"@manuscripts/track-changes-plugin": "1.7.9
|
|
35
|
+
"@manuscripts/track-changes-plugin": "1.7.9",
|
|
36
36
|
"@manuscripts/transform": "2.2.0",
|
|
37
37
|
"astrocite-eutils": "^0.16.4",
|
|
38
38
|
"axios": "^1.6.7",
|
|
@@ -112,4 +112,4 @@
|
|
|
112
112
|
"@types/react": "^17.0.2",
|
|
113
113
|
"prosemirror-tables": "^1.3.5"
|
|
114
114
|
}
|
|
115
|
-
}
|
|
115
|
+
}
|