@manuscripts/body-editor 1.8.4-LEAN-3136-2MB → 1.8.5
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 +2 -13
- package/dist/cjs/plugins/footnotes/footnotes-utils.js +1 -33
- package/dist/cjs/plugins/footnotes/index.js +22 -72
- package/dist/es/commands.js +3 -14
- package/dist/es/plugins/footnotes/footnotes-utils.js +0 -31
- package/dist/es/plugins/footnotes/index.js +23 -73
- package/dist/types/plugins/footnotes/footnotes-utils.d.ts +0 -1
- package/dist/types/plugins/footnotes/index.d.ts +3 -5
- package/package.json +2 -2
package/dist/cjs/commands.js
CHANGED
|
@@ -329,18 +329,7 @@ const insertInlineFootnote = (kind) => (state, dispatch) => {
|
|
|
329
329
|
]);
|
|
330
330
|
const backmatter = (0, prosemirror_utils_1.findChildrenByType)(tr.doc, transform_1.schema.nodes.backmatter)[0];
|
|
331
331
|
tr.insert(backmatter.pos + 1, section);
|
|
332
|
-
|
|
333
|
-
tr.doc.descendants((n, pos) => {
|
|
334
|
-
if ((0, transform_1.isFootnoteNode)(n)) {
|
|
335
|
-
footnotePos = pos;
|
|
336
|
-
n.descendants((childNode, childPos) => {
|
|
337
|
-
if ((0, transform_1.isParagraphNode)(childNode)) {
|
|
338
|
-
footnotePos += childPos;
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
selectionPos = footnotePos + 2;
|
|
332
|
+
selectionPos = backmatter.pos + section.nodeSize - 3;
|
|
344
333
|
}
|
|
345
334
|
else {
|
|
346
335
|
const footnoteElement = (0, prosemirror_utils_1.findChildrenByType)(footnotesSection.node, transform_1.schema.nodes.footnotes_element);
|
|
@@ -352,7 +341,7 @@ const insertInlineFootnote = (kind) => (state, dispatch) => {
|
|
|
352
341
|
selectionPos = pos + 2;
|
|
353
342
|
}
|
|
354
343
|
if (dispatch && selectionPos) {
|
|
355
|
-
const selection = prosemirror_state_1.TextSelection.
|
|
344
|
+
const selection = prosemirror_state_1.TextSelection.create(tr.doc, selectionPos);
|
|
356
345
|
dispatch(tr.setSelection(selection).scrollIntoView());
|
|
357
346
|
}
|
|
358
347
|
return true;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
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");
|
|
@@ -108,35 +108,3 @@ const getInlineFootnotes = (id, tableElement) => {
|
|
|
108
108
|
return inlineFootnotes;
|
|
109
109
|
};
|
|
110
110
|
exports.getInlineFootnotes = getInlineFootnotes;
|
|
111
|
-
function getAlphaOrderIndices(index) {
|
|
112
|
-
const unicodeInterval = [97, 123];
|
|
113
|
-
const places = unicodeInterval[1] - unicodeInterval[0];
|
|
114
|
-
function getClassCount(n, order) {
|
|
115
|
-
return n * Math.pow(places, order - 1);
|
|
116
|
-
}
|
|
117
|
-
let indices = null;
|
|
118
|
-
for (;;) {
|
|
119
|
-
let current = index;
|
|
120
|
-
let position = 1;
|
|
121
|
-
while (current >= places) {
|
|
122
|
-
current = current / places;
|
|
123
|
-
position++;
|
|
124
|
-
}
|
|
125
|
-
const newIndex = Math.floor(current);
|
|
126
|
-
indices = indices ? indices : new Array(position).fill(0);
|
|
127
|
-
indices.splice(indices.length - position, 1, newIndex);
|
|
128
|
-
index -= getClassCount(newIndex, position);
|
|
129
|
-
if (position === 1) {
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return (indices || [])
|
|
134
|
-
.map((v, i, array) => {
|
|
135
|
-
if (array.length > 1 && i !== array.length - 1) {
|
|
136
|
-
return String.fromCodePoint(v + unicodeInterval[0] - 1);
|
|
137
|
-
}
|
|
138
|
-
return String.fromCodePoint(v + unicodeInterval[0]);
|
|
139
|
-
})
|
|
140
|
-
.join('');
|
|
141
|
-
}
|
|
142
|
-
exports.getAlphaOrderIndices = getAlphaOrderIndices;
|
|
@@ -18,8 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.
|
|
22
|
-
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
21
|
+
exports.uncitedFootnoteWidget = exports.buildPluginState = exports.footnotesKey = void 0;
|
|
23
22
|
const transform_1 = require("@manuscripts/transform");
|
|
24
23
|
const lodash_1 = require("lodash");
|
|
25
24
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
@@ -32,6 +31,23 @@ const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
|
|
|
32
31
|
const placeholder_1 = require("../placeholder");
|
|
33
32
|
const footnotes_utils_1 = require("./footnotes-utils");
|
|
34
33
|
exports.footnotesKey = new prosemirror_state_1.PluginKey('footnotes');
|
|
34
|
+
const buildPluginState = (doc) => {
|
|
35
|
+
const nodes = [];
|
|
36
|
+
let index = 0;
|
|
37
|
+
const labels = new Map();
|
|
38
|
+
doc.descendants((node, pos, parentNode) => {
|
|
39
|
+
if ((0, transform_1.isInlineFootnoteNode)(node) &&
|
|
40
|
+
parentNode &&
|
|
41
|
+
parentNode.type !== transform_1.schema.nodes.table_cell) {
|
|
42
|
+
nodes.push([node, pos]);
|
|
43
|
+
node.attrs.rids.forEach((rid) => {
|
|
44
|
+
labels.set(rid, String(++index));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return { nodes, labels };
|
|
49
|
+
};
|
|
50
|
+
exports.buildPluginState = buildPluginState;
|
|
35
51
|
const scrollToInlineFootnote = (rid, view) => {
|
|
36
52
|
view.state.doc.descendants((node, pos) => {
|
|
37
53
|
const footnote = node;
|
|
@@ -110,38 +126,6 @@ const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage, id, ta
|
|
|
110
126
|
});
|
|
111
127
|
return deleteBtn;
|
|
112
128
|
};
|
|
113
|
-
const buildPluginState = (doc) => {
|
|
114
|
-
const inlineFootnotes = [];
|
|
115
|
-
const footnotes = new Map();
|
|
116
|
-
let footnoteElement;
|
|
117
|
-
doc.descendants((node, pos, parentNode) => {
|
|
118
|
-
if ((0, transform_1.isFootnoteNode)(node)) {
|
|
119
|
-
footnotes.set(node.attrs.id, [node, pos]);
|
|
120
|
-
}
|
|
121
|
-
if ((0, transform_1.isFootnotesSectionNode)(node)) {
|
|
122
|
-
node.descendants((node, childPos) => {
|
|
123
|
-
if ((0, transform_1.isFootnotesElementNode)(node)) {
|
|
124
|
-
footnoteElement = [node, pos + childPos];
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
if ((0, transform_1.isInlineFootnoteNode)(node) &&
|
|
129
|
-
parentNode &&
|
|
130
|
-
parentNode.type !== transform_1.schema.nodes.table_cell) {
|
|
131
|
-
inlineFootnotes.push([node, pos]);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
let index = 0;
|
|
135
|
-
const labels = new Map();
|
|
136
|
-
inlineFootnotes.sort((a, b) => a[1] - b[1]);
|
|
137
|
-
inlineFootnotes.forEach(([node]) => {
|
|
138
|
-
node.attrs.rids.forEach((rid) => {
|
|
139
|
-
labels.set(rid, (0, footnotes_utils_1.getAlphaOrderIndices)(index++));
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
return { inlineFootnotes, labels, footnotes, footnoteElement };
|
|
143
|
-
};
|
|
144
|
-
exports.buildPluginState = buildPluginState;
|
|
145
129
|
exports.default = (props) => {
|
|
146
130
|
return new prosemirror_state_1.Plugin({
|
|
147
131
|
key: exports.footnotesKey,
|
|
@@ -150,59 +134,25 @@ exports.default = (props) => {
|
|
|
150
134
|
return (0, exports.buildPluginState)(instance.doc);
|
|
151
135
|
},
|
|
152
136
|
apply(tr, value, oldState, newState) {
|
|
153
|
-
const prevState = exports.footnotesKey.getState(oldState);
|
|
154
|
-
if (!tr.docChanged && prevState) {
|
|
155
|
-
return prevState;
|
|
156
|
-
}
|
|
157
137
|
return (0, exports.buildPluginState)(newState.doc);
|
|
158
138
|
},
|
|
159
139
|
},
|
|
160
140
|
appendTransaction(transactions, oldState, newState) {
|
|
161
|
-
const {
|
|
162
|
-
const {
|
|
163
|
-
|
|
164
|
-
const newIds = inlineFootnoteNodes.map(([node]) => node.attrs.rids);
|
|
165
|
-
if (!footnoteElement || (0, lodash_1.isEqual)(prevIds, newIds) || newIds.length < 2) {
|
|
141
|
+
const { nodes: oldInlineFootnoteNodes } = exports.footnotesKey.getState(oldState);
|
|
142
|
+
const { nodes: inlineFootnoteNodes, labels } = exports.footnotesKey.getState(newState);
|
|
143
|
+
if ((0, lodash_1.isEqual)(inlineFootnoteNodes, oldInlineFootnoteNodes)) {
|
|
166
144
|
return null;
|
|
167
145
|
}
|
|
168
146
|
const { tr } = newState;
|
|
169
|
-
const footnotesReordered = [];
|
|
170
|
-
const footnotesRest = new Map(footnotes);
|
|
171
147
|
inlineFootnoteNodes.forEach(([node, pos]) => {
|
|
172
148
|
const footnote = node;
|
|
173
149
|
const contents = footnote.attrs.rids
|
|
174
|
-
.map((rid) =>
|
|
175
|
-
const currentfNode = footnotesRest.get(rid);
|
|
176
|
-
if (currentfNode) {
|
|
177
|
-
footnotesReordered.push(currentfNode[0]);
|
|
178
|
-
footnotesRest.delete(rid);
|
|
179
|
-
}
|
|
180
|
-
return labels.get(rid);
|
|
181
|
-
})
|
|
150
|
+
.map((rid) => labels.get(rid))
|
|
182
151
|
.join('');
|
|
183
152
|
if (footnote.attrs.contents !== contents) {
|
|
184
153
|
tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, footnote.attrs), { rids: footnote.attrs.rids, contents }));
|
|
185
154
|
}
|
|
186
155
|
});
|
|
187
|
-
footnotesRest.forEach(([node]) => footnotesReordered.push(node));
|
|
188
|
-
const newFElement = transform_1.schema.nodes.footnotes_element.create(footnoteElement[0].attrs, footnotesReordered);
|
|
189
|
-
if (newFElement) {
|
|
190
|
-
tr.replaceWith(footnoteElement[1], footnoteElement[1] + footnoteElement[0].nodeSize, newFElement);
|
|
191
|
-
}
|
|
192
|
-
const prevSelection = newState.selection;
|
|
193
|
-
const selectedFootnote = (0, prosemirror_utils_1.findParentNodeClosestToPos)(prevSelection.$anchor, (node) => (0, transform_1.isFootnoteNode)(node));
|
|
194
|
-
if (selectedFootnote && footnotes.size > 1) {
|
|
195
|
-
let newFootnotePos = 0;
|
|
196
|
-
for (let i = 0; i < footnotesReordered.length; i++) {
|
|
197
|
-
const node = footnotesReordered[i];
|
|
198
|
-
newFootnotePos += node.nodeSize;
|
|
199
|
-
if (node.attrs.id === selectedFootnote.node.attrs.id) {
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, footnoteElement[1] + newFootnotePos));
|
|
204
|
-
}
|
|
205
|
-
(0, track_changes_plugin_1.skipTracking)(tr);
|
|
206
156
|
return tr;
|
|
207
157
|
},
|
|
208
158
|
props: {
|
package/dist/es/commands.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
17
|
import { skipTracking } from '@manuscripts/track-changes-plugin';
|
|
18
|
-
import { buildComment, generateID, isElementNodeType,
|
|
18
|
+
import { buildComment, generateID, isElementNodeType, isInBibliographySection, isListNode, isSectionNodeType, schema, } from '@manuscripts/transform';
|
|
19
19
|
import { NodeRange } from 'prosemirror-model';
|
|
20
20
|
import { wrapInList } from 'prosemirror-schema-list';
|
|
21
21
|
import { NodeSelection, TextSelection, } from 'prosemirror-state';
|
|
@@ -310,18 +310,7 @@ export const insertInlineFootnote = (kind) => (state, dispatch) => {
|
|
|
310
310
|
]);
|
|
311
311
|
const backmatter = findChildrenByType(tr.doc, schema.nodes.backmatter)[0];
|
|
312
312
|
tr.insert(backmatter.pos + 1, section);
|
|
313
|
-
|
|
314
|
-
tr.doc.descendants((n, pos) => {
|
|
315
|
-
if (isFootnoteNode(n)) {
|
|
316
|
-
footnotePos = pos;
|
|
317
|
-
n.descendants((childNode, childPos) => {
|
|
318
|
-
if (isParagraphNode(childNode)) {
|
|
319
|
-
footnotePos += childPos;
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
selectionPos = footnotePos + 2;
|
|
313
|
+
selectionPos = backmatter.pos + section.nodeSize - 3;
|
|
325
314
|
}
|
|
326
315
|
else {
|
|
327
316
|
const footnoteElement = findChildrenByType(footnotesSection.node, schema.nodes.footnotes_element);
|
|
@@ -333,7 +322,7 @@ export const insertInlineFootnote = (kind) => (state, dispatch) => {
|
|
|
333
322
|
selectionPos = pos + 2;
|
|
334
323
|
}
|
|
335
324
|
if (dispatch && selectionPos) {
|
|
336
|
-
const selection = TextSelection.
|
|
325
|
+
const selection = TextSelection.create(tr.doc, selectionPos);
|
|
337
326
|
dispatch(tr.setSelection(selection).scrollIntoView());
|
|
338
327
|
}
|
|
339
328
|
return true;
|
|
@@ -99,34 +99,3 @@ export const getInlineFootnotes = (id, tableElement) => {
|
|
|
99
99
|
});
|
|
100
100
|
return inlineFootnotes;
|
|
101
101
|
};
|
|
102
|
-
export function getAlphaOrderIndices(index) {
|
|
103
|
-
const unicodeInterval = [97, 123];
|
|
104
|
-
const places = unicodeInterval[1] - unicodeInterval[0];
|
|
105
|
-
function getClassCount(n, order) {
|
|
106
|
-
return n * Math.pow(places, order - 1);
|
|
107
|
-
}
|
|
108
|
-
let indices = null;
|
|
109
|
-
for (;;) {
|
|
110
|
-
let current = index;
|
|
111
|
-
let position = 1;
|
|
112
|
-
while (current >= places) {
|
|
113
|
-
current = current / places;
|
|
114
|
-
position++;
|
|
115
|
-
}
|
|
116
|
-
const newIndex = Math.floor(current);
|
|
117
|
-
indices = indices ? indices : new Array(position).fill(0);
|
|
118
|
-
indices.splice(indices.length - position, 1, newIndex);
|
|
119
|
-
index -= getClassCount(newIndex, position);
|
|
120
|
-
if (position === 1) {
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return (indices || [])
|
|
125
|
-
.map((v, i, array) => {
|
|
126
|
-
if (array.length > 1 && i !== array.length - 1) {
|
|
127
|
-
return String.fromCodePoint(v + unicodeInterval[0] - 1);
|
|
128
|
-
}
|
|
129
|
-
return String.fromCodePoint(v + unicodeInterval[0]);
|
|
130
|
-
})
|
|
131
|
-
.join('');
|
|
132
|
-
}
|
|
@@ -13,10 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import { isFootnoteNode, isFootnotesElementNode, isFootnotesSectionNode, isInlineFootnoteNode, schema, } from '@manuscripts/transform';
|
|
16
|
+
import { isFootnoteNode, isInlineFootnoteNode, schema, } from '@manuscripts/transform';
|
|
18
17
|
import { isEqual } from 'lodash';
|
|
19
|
-
import { NodeSelection, Plugin, PluginKey
|
|
18
|
+
import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
20
19
|
import { findParentNodeClosestToPos, findParentNodeOfType, hasParentNodeOfType, } from 'prosemirror-utils';
|
|
21
20
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
22
21
|
import { alertIcon, deleteIcon } from '../../assets';
|
|
@@ -24,8 +23,24 @@ import { DeleteFootnoteDialog, } from '../../components/views/DeleteFootnoteDial
|
|
|
24
23
|
import { findParentNodeWithIdValue, getChildOfType } from '../../lib/utils';
|
|
25
24
|
import ReactSubView from '../../views/ReactSubView';
|
|
26
25
|
import { placeholderWidget } from '../placeholder';
|
|
27
|
-
import { findTableInlineFootnoteIds,
|
|
26
|
+
import { findTableInlineFootnoteIds, getInlineFootnotes, } from './footnotes-utils';
|
|
28
27
|
export const footnotesKey = new PluginKey('footnotes');
|
|
28
|
+
export const buildPluginState = (doc) => {
|
|
29
|
+
const nodes = [];
|
|
30
|
+
let index = 0;
|
|
31
|
+
const labels = new Map();
|
|
32
|
+
doc.descendants((node, pos, parentNode) => {
|
|
33
|
+
if (isInlineFootnoteNode(node) &&
|
|
34
|
+
parentNode &&
|
|
35
|
+
parentNode.type !== schema.nodes.table_cell) {
|
|
36
|
+
nodes.push([node, pos]);
|
|
37
|
+
node.attrs.rids.forEach((rid) => {
|
|
38
|
+
labels.set(rid, String(++index));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return { nodes, labels };
|
|
43
|
+
};
|
|
29
44
|
const scrollToInlineFootnote = (rid, view) => {
|
|
30
45
|
view.state.doc.descendants((node, pos) => {
|
|
31
46
|
const footnote = node;
|
|
@@ -103,37 +118,6 @@ const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage, id, ta
|
|
|
103
118
|
});
|
|
104
119
|
return deleteBtn;
|
|
105
120
|
};
|
|
106
|
-
export const buildPluginState = (doc) => {
|
|
107
|
-
const inlineFootnotes = [];
|
|
108
|
-
const footnotes = new Map();
|
|
109
|
-
let footnoteElement;
|
|
110
|
-
doc.descendants((node, pos, parentNode) => {
|
|
111
|
-
if (isFootnoteNode(node)) {
|
|
112
|
-
footnotes.set(node.attrs.id, [node, pos]);
|
|
113
|
-
}
|
|
114
|
-
if (isFootnotesSectionNode(node)) {
|
|
115
|
-
node.descendants((node, childPos) => {
|
|
116
|
-
if (isFootnotesElementNode(node)) {
|
|
117
|
-
footnoteElement = [node, pos + childPos];
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
if (isInlineFootnoteNode(node) &&
|
|
122
|
-
parentNode &&
|
|
123
|
-
parentNode.type !== schema.nodes.table_cell) {
|
|
124
|
-
inlineFootnotes.push([node, pos]);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
let index = 0;
|
|
128
|
-
const labels = new Map();
|
|
129
|
-
inlineFootnotes.sort((a, b) => a[1] - b[1]);
|
|
130
|
-
inlineFootnotes.forEach(([node]) => {
|
|
131
|
-
node.attrs.rids.forEach((rid) => {
|
|
132
|
-
labels.set(rid, getAlphaOrderIndices(index++));
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
return { inlineFootnotes, labels, footnotes, footnoteElement };
|
|
136
|
-
};
|
|
137
121
|
export default (props) => {
|
|
138
122
|
return new Plugin({
|
|
139
123
|
key: footnotesKey,
|
|
@@ -142,59 +126,25 @@ export default (props) => {
|
|
|
142
126
|
return buildPluginState(instance.doc);
|
|
143
127
|
},
|
|
144
128
|
apply(tr, value, oldState, newState) {
|
|
145
|
-
const prevState = footnotesKey.getState(oldState);
|
|
146
|
-
if (!tr.docChanged && prevState) {
|
|
147
|
-
return prevState;
|
|
148
|
-
}
|
|
149
129
|
return buildPluginState(newState.doc);
|
|
150
130
|
},
|
|
151
131
|
},
|
|
152
132
|
appendTransaction(transactions, oldState, newState) {
|
|
153
|
-
const {
|
|
154
|
-
const {
|
|
155
|
-
|
|
156
|
-
const newIds = inlineFootnoteNodes.map(([node]) => node.attrs.rids);
|
|
157
|
-
if (!footnoteElement || isEqual(prevIds, newIds) || newIds.length < 2) {
|
|
133
|
+
const { nodes: oldInlineFootnoteNodes } = footnotesKey.getState(oldState);
|
|
134
|
+
const { nodes: inlineFootnoteNodes, labels } = footnotesKey.getState(newState);
|
|
135
|
+
if (isEqual(inlineFootnoteNodes, oldInlineFootnoteNodes)) {
|
|
158
136
|
return null;
|
|
159
137
|
}
|
|
160
138
|
const { tr } = newState;
|
|
161
|
-
const footnotesReordered = [];
|
|
162
|
-
const footnotesRest = new Map(footnotes);
|
|
163
139
|
inlineFootnoteNodes.forEach(([node, pos]) => {
|
|
164
140
|
const footnote = node;
|
|
165
141
|
const contents = footnote.attrs.rids
|
|
166
|
-
.map((rid) =>
|
|
167
|
-
const currentfNode = footnotesRest.get(rid);
|
|
168
|
-
if (currentfNode) {
|
|
169
|
-
footnotesReordered.push(currentfNode[0]);
|
|
170
|
-
footnotesRest.delete(rid);
|
|
171
|
-
}
|
|
172
|
-
return labels.get(rid);
|
|
173
|
-
})
|
|
142
|
+
.map((rid) => labels.get(rid))
|
|
174
143
|
.join('');
|
|
175
144
|
if (footnote.attrs.contents !== contents) {
|
|
176
145
|
tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, footnote.attrs), { rids: footnote.attrs.rids, contents }));
|
|
177
146
|
}
|
|
178
147
|
});
|
|
179
|
-
footnotesRest.forEach(([node]) => footnotesReordered.push(node));
|
|
180
|
-
const newFElement = schema.nodes.footnotes_element.create(footnoteElement[0].attrs, footnotesReordered);
|
|
181
|
-
if (newFElement) {
|
|
182
|
-
tr.replaceWith(footnoteElement[1], footnoteElement[1] + footnoteElement[0].nodeSize, newFElement);
|
|
183
|
-
}
|
|
184
|
-
const prevSelection = newState.selection;
|
|
185
|
-
const selectedFootnote = findParentNodeClosestToPos(prevSelection.$anchor, (node) => isFootnoteNode(node));
|
|
186
|
-
if (selectedFootnote && footnotes.size > 1) {
|
|
187
|
-
let newFootnotePos = 0;
|
|
188
|
-
for (let i = 0; i < footnotesReordered.length; i++) {
|
|
189
|
-
const node = footnotesReordered[i];
|
|
190
|
-
newFootnotePos += node.nodeSize;
|
|
191
|
-
if (node.attrs.id === selectedFootnote.node.attrs.id) {
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
tr.setSelection(TextSelection.create(tr.doc, footnoteElement[1] + newFootnotePos));
|
|
196
|
-
}
|
|
197
|
-
skipTracking(tr);
|
|
198
148
|
return tr;
|
|
199
149
|
},
|
|
200
150
|
props: {
|
|
@@ -13,17 +13,15 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { InlineFootnoteNode, ManuscriptNode } from '@manuscripts/transform';
|
|
17
17
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
18
18
|
import { PluginProps } from '../../configs/editor-plugins';
|
|
19
19
|
interface PluginState {
|
|
20
|
-
|
|
20
|
+
nodes: [InlineFootnoteNode, number][];
|
|
21
21
|
labels: Map<string, string>;
|
|
22
|
-
footnotes: Map<string, [FootnoteNode, number]>;
|
|
23
|
-
footnoteElement?: [FootnotesElementNode, number];
|
|
24
22
|
}
|
|
25
23
|
export declare const footnotesKey: PluginKey<PluginState>;
|
|
26
|
-
export declare const uncitedFootnoteWidget: () => () => HTMLSpanElement;
|
|
27
24
|
export declare const buildPluginState: (doc: ManuscriptNode) => PluginState;
|
|
25
|
+
export declare const uncitedFootnoteWidget: () => () => HTMLSpanElement;
|
|
28
26
|
declare const _default: (props: PluginProps) => Plugin<PluginState>;
|
|
29
27
|
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.8.
|
|
4
|
+
"version": "1.8.5",
|
|
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.2",
|
|
35
|
-
"@manuscripts/track-changes-plugin": "1.7.10
|
|
35
|
+
"@manuscripts/track-changes-plugin": "1.7.10",
|
|
36
36
|
"@manuscripts/transform": "^2.2.1",
|
|
37
37
|
"astrocite-eutils": "^0.16.4",
|
|
38
38
|
"axios": "^1.6.7",
|