@manuscripts/body-editor 3.5.1 → 3.5.3
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/components/toolbar/helpers.js +114 -74
- package/dist/cjs/components/toolbar/type-selector/TypeSelector.js +19 -12
- package/dist/cjs/lib/filtered-document.js +49 -0
- package/dist/cjs/lib/track-changes-utils.js +8 -0
- package/dist/cjs/lib/utils.js +19 -1
- package/dist/cjs/plugins/objects.js +5 -2
- package/dist/cjs/plugins/persist.js +3 -1
- package/dist/cjs/plugins/section_title/index.js +4 -0
- package/dist/cjs/plugins/selected-suggestion.js +11 -8
- package/dist/cjs/selection.js +25 -6
- package/dist/cjs/versions.js +1 -1
- package/dist/es/components/toolbar/helpers.js +115 -76
- package/dist/es/components/toolbar/type-selector/TypeSelector.js +19 -12
- package/dist/es/lib/filtered-document.js +44 -0
- package/dist/es/lib/track-changes-utils.js +7 -0
- package/dist/es/lib/utils.js +17 -0
- package/dist/es/plugins/objects.js +5 -2
- package/dist/es/plugins/persist.js +3 -1
- package/dist/es/plugins/section_title/index.js +4 -0
- package/dist/es/plugins/selected-suggestion.js +12 -9
- package/dist/es/selection.js +25 -7
- package/dist/es/versions.js +1 -1
- package/dist/types/components/toolbar/helpers.d.ts +3 -1
- package/dist/types/lib/filtered-document.d.ts +18 -0
- package/dist/types/lib/track-changes-utils.d.ts +1 -0
- package/dist/types/lib/utils.d.ts +2 -1
- package/dist/types/selection.d.ts +11 -4
- package/dist/types/versions.d.ts +1 -1
- package/package.json +2 -2
- package/styles/AdvancedEditor.css +2 -2
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.changeIndentation = exports.unindentParagraph = exports.unindentSection = exports.indentParagraph = exports.indentSection = exports.isIndentationAllowed = exports.promoteParagraphToSection = exports.demoteSectionToParagraph = exports.findSelectedOption = exports.titleCase = exports.optionName = void 0;
|
|
3
|
+
exports.changeIndentation = exports.unindentParagraph = exports.unindentSection = exports.indentParagraph = exports.indentSection = exports.isIndentationAllowed = exports.promoteParagraphToSection = exports.demoteSectionToParagraph = exports.findSelectedOption = exports.titleCase = exports.optionName = exports.shouldSkipNode = void 0;
|
|
4
4
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
5
5
|
const transform_1 = require("@manuscripts/transform");
|
|
6
6
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
7
7
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
8
8
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
9
|
+
const filtered_document_1 = require("../../lib/filtered-document");
|
|
9
10
|
const track_changes_utils_1 = require("../../lib/track-changes-utils");
|
|
11
|
+
const utils_1 = require("../../lib/utils");
|
|
12
|
+
const shouldSkipNode = (node) => {
|
|
13
|
+
return (0, filtered_document_1.isMoved)(node) || (0, track_changes_utils_1.isDeleted)(node);
|
|
14
|
+
};
|
|
15
|
+
exports.shouldSkipNode = shouldSkipNode;
|
|
10
16
|
const optionName = (nodeType) => {
|
|
11
17
|
switch (nodeType) {
|
|
12
18
|
case nodeType.schema.nodes.section:
|
|
@@ -26,20 +32,35 @@ const findSelectedOption = (options) => {
|
|
|
26
32
|
}
|
|
27
33
|
};
|
|
28
34
|
exports.findSelectedOption = findSelectedOption;
|
|
29
|
-
const
|
|
35
|
+
const getDeepestSubsectionPosition = (subsection, position) => {
|
|
30
36
|
while (subsection.lastChild && (0, transform_1.isSectionNodeType)(subsection.lastChild.type)) {
|
|
37
|
+
if ((0, track_changes_utils_1.isDeleted)(subsection.lastChild)) {
|
|
38
|
+
return (position +
|
|
39
|
+
jumpToPreviousValidNode(subsection.nodeSize - subsection.lastChild.nodeSize - 2, subsection) +
|
|
40
|
+
1);
|
|
41
|
+
}
|
|
42
|
+
position += subsection.nodeSize - subsection.lastChild.nodeSize;
|
|
31
43
|
subsection = subsection.lastChild;
|
|
32
44
|
}
|
|
33
|
-
return subsection;
|
|
45
|
+
return position + subsection.content.size;
|
|
46
|
+
};
|
|
47
|
+
const getInsertDataTracked = (node) => {
|
|
48
|
+
const dataTracked = node.attrs.dataTracked;
|
|
49
|
+
const change = dataTracked?.find((c) => c.operation === 'insert');
|
|
50
|
+
return change ? [change] : null;
|
|
34
51
|
};
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
52
|
+
const jumpToPreviousValidNode = (beforeSection, doc) => {
|
|
53
|
+
const $beforeSection = doc.resolve(beforeSection);
|
|
54
|
+
let pos = beforeSection;
|
|
55
|
+
for (let i = $beforeSection.index() - 1; i >= 0; i--) {
|
|
56
|
+
pos = $beforeSection.posAtIndex(i);
|
|
57
|
+
const node = doc.resolve(pos + 1).node();
|
|
58
|
+
if (!((0, track_changes_utils_1.isDeleted)(node) && node.type === transform_1.schema.nodes.section) && i >= 0) {
|
|
59
|
+
pos = $beforeSection.posAtIndex(i + 1);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
38
62
|
}
|
|
39
|
-
|
|
40
|
-
const lastSubsection = parentNode.content.child(lastSubsectionIndex);
|
|
41
|
-
const updatedSubsection = replaceDeepestSubsection(lastSubsection, newSubsection);
|
|
42
|
-
return parentNode.copy(parentNode.content.replaceChild(lastSubsectionIndex, updatedSubsection));
|
|
63
|
+
return pos;
|
|
43
64
|
};
|
|
44
65
|
const demoteSectionToParagraph = (state, dispatch, view) => {
|
|
45
66
|
const { doc, selection: { $from }, schema, tr, } = state;
|
|
@@ -50,40 +71,35 @@ const demoteSectionToParagraph = (state, dispatch, view) => {
|
|
|
50
71
|
const afterSectionTitleOffset = $afterSectionTitle.parentOffset;
|
|
51
72
|
const sectionDepth = $from.depth - 1;
|
|
52
73
|
const section = $from.node(sectionDepth);
|
|
53
|
-
|
|
54
|
-
|
|
74
|
+
let beforeSection = $from.before(sectionDepth);
|
|
75
|
+
beforeSection = jumpToPreviousValidNode(beforeSection, doc);
|
|
55
76
|
const $beforeSection = doc.resolve(beforeSection);
|
|
56
77
|
const previousNode = $beforeSection.nodeBefore;
|
|
57
78
|
const paragraph = nodes.paragraph.create({
|
|
58
79
|
id: (0, transform_1.generateNodeID)(nodes.paragraph),
|
|
80
|
+
dataTracked: getInsertDataTracked(section),
|
|
59
81
|
}, sectionTitle.content);
|
|
60
82
|
let anchor;
|
|
61
|
-
let fragment;
|
|
62
83
|
const sectionContent = section.content.cut(afterSectionTitleOffset);
|
|
63
84
|
if (previousNode && (0, transform_1.isSectionNodeType)(previousNode.type)) {
|
|
64
85
|
const hasSubsections = previousNode.lastChild && (0, transform_1.isSectionNodeType)(previousNode.lastChild.type);
|
|
65
86
|
if (hasSubsections) {
|
|
66
|
-
|
|
67
|
-
const updatedDeepestSubsection = deepestSubsection.copy(deepestSubsection.content
|
|
68
|
-
.append(prosemirror_model_1.Fragment.from(paragraph))
|
|
69
|
-
.append(sectionContent));
|
|
70
|
-
const updatedPreviousNode = replaceDeepestSubsection(previousNode, updatedDeepestSubsection);
|
|
71
|
-
fragment = updatedPreviousNode.content;
|
|
87
|
+
beforeSection = getDeepestSubsectionPosition(previousNode, beforeSection - previousNode.nodeSize);
|
|
72
88
|
}
|
|
73
89
|
else {
|
|
74
|
-
|
|
75
|
-
.append(prosemirror_model_1.Fragment.from(paragraph))
|
|
76
|
-
.append(sectionContent);
|
|
90
|
+
beforeSection = beforeSection - 1;
|
|
77
91
|
}
|
|
78
|
-
|
|
79
|
-
anchor = beforeSection;
|
|
92
|
+
anchor = beforeSection + 1;
|
|
80
93
|
}
|
|
81
94
|
else {
|
|
82
|
-
tr.replaceWith(beforeSection, afterSection, prosemirror_model_1.Fragment.from(paragraph).append(sectionContent));
|
|
83
95
|
anchor = beforeSection + 1;
|
|
84
96
|
}
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
const content = (0, utils_1.filterBlockNodes)(prosemirror_model_1.Fragment.from(paragraph).append(sectionContent), (node) => !(0, track_changes_utils_1.isShadowDelete)(node));
|
|
98
|
+
tr.insert(beforeSection, content);
|
|
99
|
+
const afterSection = tr.mapping.map($from.after(sectionDepth));
|
|
100
|
+
tr.delete(afterSection - section.nodeSize, afterSection);
|
|
101
|
+
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor));
|
|
102
|
+
dispatch((0, track_changes_plugin_1.setAction)(tr, track_changes_plugin_1.TrackChangesAction.structuralChangeAction, 'convert-to-paragraph'));
|
|
87
103
|
view && view.focus();
|
|
88
104
|
};
|
|
89
105
|
exports.demoteSectionToParagraph = demoteSectionToParagraph;
|
|
@@ -99,18 +115,15 @@ const promoteParagraphToSection = (state, dispatch, view) => {
|
|
|
99
115
|
const parentSection = $from.node(sectionDepth);
|
|
100
116
|
const startIndex = $from.index(sectionDepth);
|
|
101
117
|
const endIndex = $from.indexAfter(sectionDepth);
|
|
102
|
-
|
|
103
|
-
const afterParentSection = $from.after(sectionDepth);
|
|
118
|
+
let afterParentSection = $from.after(sectionDepth);
|
|
104
119
|
const items = [];
|
|
105
|
-
let offset = 0;
|
|
106
120
|
if (startIndex > 0) {
|
|
107
121
|
const precedingSection = parentSection.cut(0, beforeParagraphOffset);
|
|
108
122
|
items.push(precedingSection);
|
|
109
|
-
offset += precedingSection.nodeSize;
|
|
110
123
|
}
|
|
111
|
-
const textContent = paragraph.
|
|
124
|
+
const textContent = (0, prosemirror_utils_1.findChildrenByType)(paragraph, schema.nodes.text).map(({ node }) => node);
|
|
112
125
|
const sectionTitle = textContent
|
|
113
|
-
? nodes.section_title.create({},
|
|
126
|
+
? nodes.section_title.create({}, prosemirror_model_1.Fragment.from(textContent))
|
|
114
127
|
: nodes.section_title.create();
|
|
115
128
|
let sectionContent = prosemirror_model_1.Fragment.from(sectionTitle);
|
|
116
129
|
if (endIndex < parentSection.childCount) {
|
|
@@ -120,18 +133,27 @@ const promoteParagraphToSection = (state, dispatch, view) => {
|
|
|
120
133
|
sectionContent = sectionContent.append(prosemirror_model_1.Fragment.from(paragraph.copy()));
|
|
121
134
|
}
|
|
122
135
|
if (parentSection.type.name === 'body') {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
sectionContent = prosemirror_model_1.Fragment.from(sectionTitle);
|
|
137
|
+
afterParentSection = beforeParagraph + paragraph.nodeSize;
|
|
138
|
+
parentSection.forEach((node, offset, index) => {
|
|
139
|
+
if (node.type !== nodes.section &&
|
|
140
|
+
index > tr.doc.resolve(beforeParagraph).index()) {
|
|
141
|
+
const pos = $from.start($from.depth - 1);
|
|
142
|
+
afterParentSection = pos + offset + node.nodeSize;
|
|
143
|
+
sectionContent = sectionContent.append(prosemirror_model_1.Fragment.from(node));
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
items[0] = nodes.section.create({ dataTracked: getInsertDataTracked(paragraph) }, sectionContent);
|
|
127
147
|
}
|
|
128
148
|
else {
|
|
129
|
-
items.push(parentSection.
|
|
149
|
+
items.push(parentSection.type.create({ dataTracked: getInsertDataTracked(paragraph) }, sectionContent));
|
|
130
150
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
tr.
|
|
134
|
-
|
|
151
|
+
const content = (0, utils_1.filterBlockNodes)(prosemirror_model_1.Fragment.from(items[items.length - 1]), (node) => !(0, track_changes_utils_1.isShadowDelete)(node));
|
|
152
|
+
tr.insert(afterParentSection, content);
|
|
153
|
+
tr.delete(beforeParagraph, afterParentSection - 1);
|
|
154
|
+
const anchor = tr.mapping.map(afterParentSection) - content.size + 2;
|
|
155
|
+
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor));
|
|
156
|
+
dispatch((0, track_changes_plugin_1.setAction)(tr, track_changes_plugin_1.TrackChangesAction.structuralChangeAction, 'convert-to-section'));
|
|
135
157
|
view && view.focus();
|
|
136
158
|
};
|
|
137
159
|
exports.promoteParagraphToSection = promoteParagraphToSection;
|
|
@@ -183,24 +205,46 @@ const indentSection = () => (state, dispatch, view) => {
|
|
|
183
205
|
const parentSectionDepth = sectionDepth - 1;
|
|
184
206
|
const parentSection = $from.node(parentSectionDepth);
|
|
185
207
|
const startIndex = $from.index(parentSectionDepth);
|
|
186
|
-
|
|
187
|
-
|
|
208
|
+
let previousSection = null;
|
|
209
|
+
for (let i = startIndex - 1; i >= 0; i--) {
|
|
210
|
+
const candidate = parentSection.child(i);
|
|
211
|
+
if (candidate.type === nodes.section && !(0, exports.shouldSkipNode)(candidate)) {
|
|
212
|
+
previousSection = candidate;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
188
216
|
let anchor;
|
|
189
|
-
if (!previousSection
|
|
217
|
+
if (!previousSection) {
|
|
190
218
|
const emptyTitle = nodes.section_title.create();
|
|
191
219
|
const newParentSectionContent = prosemirror_model_1.Fragment.fromArray([emptyTitle, section]);
|
|
192
220
|
const newParentSection = nodes.section.create({}, newParentSectionContent);
|
|
193
|
-
tr.
|
|
221
|
+
tr.insert(beforeSection, newParentSection);
|
|
222
|
+
const newBeforeSection = beforeSection + newParentSection.nodeSize;
|
|
223
|
+
const newAfterSection = afterSection + newParentSection.nodeSize;
|
|
224
|
+
tr.delete(newBeforeSection, newAfterSection);
|
|
194
225
|
anchor = beforeSection + 1;
|
|
195
226
|
}
|
|
196
227
|
else {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
228
|
+
let beforePreviousSection = null;
|
|
229
|
+
$from.doc.descendants((node, pos) => {
|
|
230
|
+
if (node === previousSection) {
|
|
231
|
+
beforePreviousSection = pos;
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
if (beforePreviousSection === null) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const insertPos = beforePreviousSection + previousSection.nodeSize - 1;
|
|
239
|
+
tr.insert(insertPos, section);
|
|
240
|
+
const newBeforeSection = beforeSection + section.nodeSize;
|
|
241
|
+
const newAfterSection = afterSection + section.nodeSize;
|
|
242
|
+
tr.delete(newBeforeSection, newAfterSection);
|
|
243
|
+
anchor = insertPos + 1;
|
|
201
244
|
}
|
|
202
245
|
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor));
|
|
203
|
-
|
|
246
|
+
(0, track_changes_plugin_1.setAction)(tr, track_changes_plugin_1.TrackChangesAction.indentationAction, { action: 'indent' });
|
|
247
|
+
dispatch(tr);
|
|
204
248
|
view && view.focus();
|
|
205
249
|
};
|
|
206
250
|
exports.indentSection = indentSection;
|
|
@@ -214,15 +258,16 @@ const indentParagraph = () => (state, dispatch, view) => {
|
|
|
214
258
|
const sectionEnd = $from.end(sectionDepth);
|
|
215
259
|
const sectionContent = prosemirror_model_1.Fragment.from(schema.nodes.section_title.create()).append(parentSection.content.cut(beforeParagraph - sectionStart));
|
|
216
260
|
const newSection = schema.nodes.section.create({ id: (0, transform_1.generateNodeID)(schema.nodes.section) }, sectionContent);
|
|
217
|
-
|
|
218
|
-
tr.
|
|
219
|
-
|
|
261
|
+
(0, track_changes_plugin_1.setAction)(tr, track_changes_plugin_1.TrackChangesAction.indentationAction, { action: 'indent' });
|
|
262
|
+
tr.delete(beforeParagraph, sectionEnd);
|
|
263
|
+
tr.insert(beforeParagraph, newSection);
|
|
264
|
+
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, beforeParagraph + newSection.nodeSize - 2));
|
|
265
|
+
dispatch(tr);
|
|
220
266
|
view?.focus();
|
|
221
267
|
};
|
|
222
268
|
exports.indentParagraph = indentParagraph;
|
|
223
269
|
const unindentSection = () => (state, dispatch, view) => {
|
|
224
|
-
const { selection: { $from },
|
|
225
|
-
const { nodes } = schema;
|
|
270
|
+
const { selection: { $from }, tr, } = state;
|
|
226
271
|
const sectionDepth = $from.depth - 1;
|
|
227
272
|
const section = $from.node(sectionDepth);
|
|
228
273
|
const beforeSection = $from.before(sectionDepth);
|
|
@@ -232,26 +277,20 @@ const unindentSection = () => (state, dispatch, view) => {
|
|
|
232
277
|
const afterSectionOffset = beforeSectionOffset + section.nodeSize;
|
|
233
278
|
const parentSectionDepth = $from.depth - 2;
|
|
234
279
|
const parentSection = $from.node(parentSectionDepth);
|
|
235
|
-
const startIndex = $from.index(parentSectionDepth);
|
|
236
280
|
const endIndex = $from.indexAfter(parentSectionDepth);
|
|
237
|
-
const beforeParentSection = $from.before(parentSectionDepth);
|
|
238
281
|
const afterParentSection = $from.after(parentSectionDepth);
|
|
239
|
-
const
|
|
240
|
-
let
|
|
241
|
-
if (
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
offset += precedingSection.nodeSize;
|
|
245
|
-
}
|
|
246
|
-
items.push(section);
|
|
247
|
-
if (endIndex < parentSection.childCount) {
|
|
248
|
-
const fragment = prosemirror_model_1.Fragment.from(nodes.section_title.create()).append(parentSection.content.cut(afterSectionOffset));
|
|
249
|
-
items.push(parentSection.copy(fragment));
|
|
282
|
+
const hasFollowingSiblings = endIndex < parentSection.childCount;
|
|
283
|
+
let extendedSection = section;
|
|
284
|
+
if (hasFollowingSiblings) {
|
|
285
|
+
const siblingsContent = parentSection.content.cut(afterSectionOffset);
|
|
286
|
+
extendedSection = section.copy(section.content.append(siblingsContent));
|
|
250
287
|
}
|
|
251
|
-
tr.
|
|
252
|
-
|
|
288
|
+
tr.insert(afterParentSection, prosemirror_model_1.Fragment.from(extendedSection));
|
|
289
|
+
tr.delete(beforeSection, beforeSection + extendedSection.nodeSize);
|
|
290
|
+
const anchor = afterParentSection + 2;
|
|
253
291
|
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, anchor, anchor + sectionTitle.content.size));
|
|
254
|
-
|
|
292
|
+
(0, track_changes_plugin_1.setAction)(tr, track_changes_plugin_1.TrackChangesAction.indentationAction, { action: 'unindent' });
|
|
293
|
+
dispatch(tr);
|
|
255
294
|
view && view.focus();
|
|
256
295
|
};
|
|
257
296
|
exports.unindentSection = unindentSection;
|
|
@@ -273,8 +312,9 @@ const unindentParagraph = () => (state, dispatch, view) => {
|
|
|
273
312
|
const newSection = schema.nodes.section.create({ id: (0, transform_1.generateNodeID)(schema.nodes.section) }, sectionContent);
|
|
274
313
|
tr.delete(paragraphPos, parentSectionEnd);
|
|
275
314
|
tr.insert(paragraphPos + 2, newSection);
|
|
276
|
-
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc,
|
|
277
|
-
|
|
315
|
+
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, paragraphPos + newSection.nodeSize));
|
|
316
|
+
(0, track_changes_plugin_1.setAction)(tr, track_changes_plugin_1.TrackChangesAction.indentationAction, { action: 'unindent' });
|
|
317
|
+
dispatch(tr);
|
|
278
318
|
view?.focus();
|
|
279
319
|
};
|
|
280
320
|
exports.unindentParagraph = unindentParagraph;
|
|
@@ -8,6 +8,7 @@ const transform_1 = require("@manuscripts/transform");
|
|
|
8
8
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
9
9
|
const react_1 = __importDefault(require("react"));
|
|
10
10
|
const hierarchy_1 = require("../../../lib/hierarchy");
|
|
11
|
+
const track_changes_utils_1 = require("../../../lib/track-changes-utils");
|
|
11
12
|
const utils_1 = require("../../../lib/utils");
|
|
12
13
|
const helpers_1 = require("../helpers");
|
|
13
14
|
const OptionComponent_1 = require("./OptionComponent");
|
|
@@ -30,13 +31,16 @@ const buildOptions = (state) => {
|
|
|
30
31
|
const beforeSection = $from.before(sectionDepth);
|
|
31
32
|
const $beforeSection = doc.resolve(beforeSection);
|
|
32
33
|
const sectionOffset = $beforeSection.parentOffset;
|
|
34
|
+
const section = $from.node(sectionDepth);
|
|
35
|
+
!(0, track_changes_utils_1.isDeleted)(section) &&
|
|
36
|
+
options.push({
|
|
37
|
+
nodeType: nodes.paragraph,
|
|
38
|
+
label: 'Paragraph',
|
|
39
|
+
action: helpers_1.demoteSectionToParagraph,
|
|
40
|
+
isDisabled: (sectionDepth <= 1 && sectionOffset <= 1) || (0, track_changes_utils_1.isDeleted)(section),
|
|
41
|
+
isSelected: false,
|
|
42
|
+
});
|
|
33
43
|
options.push({
|
|
34
|
-
nodeType: nodes.paragraph,
|
|
35
|
-
label: 'Paragraph',
|
|
36
|
-
action: helpers_1.demoteSectionToParagraph,
|
|
37
|
-
isDisabled: sectionDepth <= 1 && sectionOffset <= 1,
|
|
38
|
-
isSelected: false,
|
|
39
|
-
}, {
|
|
40
44
|
nodeType: nodes.section,
|
|
41
45
|
label: 'Heading',
|
|
42
46
|
isDisabled: true,
|
|
@@ -45,18 +49,21 @@ const buildOptions = (state) => {
|
|
|
45
49
|
return options;
|
|
46
50
|
}
|
|
47
51
|
case parentElementType.schema.nodes.paragraph: {
|
|
52
|
+
const paragraph = $from.node($from.depth);
|
|
48
53
|
options.push({
|
|
49
54
|
nodeType: nodes.paragraph,
|
|
50
55
|
label: 'Paragraph',
|
|
51
56
|
isDisabled: true,
|
|
52
57
|
isSelected: true,
|
|
53
|
-
}, {
|
|
54
|
-
nodeType: nodes.section,
|
|
55
|
-
label: 'Heading',
|
|
56
|
-
action: helpers_1.promoteParagraphToSection,
|
|
57
|
-
isDisabled: false,
|
|
58
|
-
isSelected: false,
|
|
59
58
|
});
|
|
59
|
+
!(0, track_changes_utils_1.isDeleted)(paragraph) &&
|
|
60
|
+
options.push({
|
|
61
|
+
nodeType: nodes.section,
|
|
62
|
+
label: 'Heading',
|
|
63
|
+
action: helpers_1.promoteParagraphToSection,
|
|
64
|
+
isDisabled: (0, track_changes_utils_1.isDeleted)(paragraph),
|
|
65
|
+
isSelected: false,
|
|
66
|
+
});
|
|
60
67
|
return options;
|
|
61
68
|
}
|
|
62
69
|
default: {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2025 Atypon Systems LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.getDocWithoutMovedContent = void 0;
|
|
19
|
+
exports.isMoved = isMoved;
|
|
20
|
+
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
21
|
+
function isMoved(node) {
|
|
22
|
+
if (node.attrs.dataTracked) {
|
|
23
|
+
const changes = node.attrs.dataTracked;
|
|
24
|
+
return changes.some(({ operation, status, moveNodeId }) => operation === track_changes_plugin_1.CHANGE_OPERATION.delete &&
|
|
25
|
+
status === track_changes_plugin_1.CHANGE_STATUS.pending &&
|
|
26
|
+
moveNodeId);
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const filterMovedContent = (node) => {
|
|
31
|
+
const nodes = [];
|
|
32
|
+
node.forEach((child) => {
|
|
33
|
+
const { attrs } = child;
|
|
34
|
+
if (isMoved(child)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (child.isText) {
|
|
38
|
+
nodes.push(child);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
nodes.push(child.type.create(attrs, filterMovedContent(child), child.marks));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return nodes;
|
|
45
|
+
};
|
|
46
|
+
const getDocWithoutMovedContent = (doc) => {
|
|
47
|
+
return doc.type.create(doc.attrs, filterMovedContent(doc), doc.marks);
|
|
48
|
+
};
|
|
49
|
+
exports.getDocWithoutMovedContent = getDocWithoutMovedContent;
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.addTrackChangesClassNames = exports.addTrackChangesAttributes = exports.getAttrsTrackingButton = void 0;
|
|
19
19
|
exports.isDeleted = isDeleted;
|
|
20
|
+
exports.isShadowDelete = isShadowDelete;
|
|
20
21
|
exports.isPendingInsert = isPendingInsert;
|
|
21
22
|
exports.isPending = isPending;
|
|
22
23
|
exports.isPendingSetAttrs = isPendingSetAttrs;
|
|
@@ -38,6 +39,13 @@ function isDeleted(node) {
|
|
|
38
39
|
}
|
|
39
40
|
return false;
|
|
40
41
|
}
|
|
42
|
+
function isShadowDelete(node) {
|
|
43
|
+
if (node.attrs.dataTracked) {
|
|
44
|
+
const changes = node.attrs.dataTracked;
|
|
45
|
+
return changes.some(({ operation, moveNodeId }) => operation === 'delete' && moveNodeId);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
41
49
|
function isPendingInsert(node) {
|
|
42
50
|
if (node.attrs.dataTracked) {
|
|
43
51
|
const changes = node.attrs.dataTracked;
|
package/dist/cjs/lib/utils.js
CHANGED
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getLastTitleNode = exports.getInsertPos = exports.createToggleButton = exports.isEditAllowed = exports.isBodyLocked = exports.cleanItemValues = exports.shouldRenderField = exports.hasParent = exports.isNotNull = exports.createHeader = exports.isSelectionInBody = exports.isSelectionInNode = exports.isChildOfNodeTypes = exports.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = void 0;
|
|
18
|
+
exports.getLastTitleNode = exports.filterBlockNodes = exports.getInsertPos = exports.createToggleButton = exports.isEditAllowed = exports.isBodyLocked = exports.cleanItemValues = exports.shouldRenderField = exports.hasParent = exports.isNotNull = exports.createHeader = exports.isSelectionInBody = exports.isSelectionInNode = exports.isChildOfNodeTypes = exports.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = void 0;
|
|
19
19
|
exports.iterateChildren = iterateChildren;
|
|
20
20
|
const transform_1 = require("@manuscripts/transform");
|
|
21
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
21
22
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
22
23
|
const config_1 = require("../components/references/ReferenceForm/config");
|
|
23
24
|
const icons_1 = require("../icons");
|
|
@@ -170,6 +171,23 @@ const getInsertPos = (type, parent, pos) => {
|
|
|
170
171
|
return insertPos;
|
|
171
172
|
};
|
|
172
173
|
exports.getInsertPos = getInsertPos;
|
|
174
|
+
const filterBlockNodes = (fragment, predicate) => {
|
|
175
|
+
const updatedNodes = [];
|
|
176
|
+
fragment.forEach((child) => {
|
|
177
|
+
if (!child.isBlock) {
|
|
178
|
+
updatedNodes.push(child);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const newContent = child.content.size
|
|
182
|
+
? (0, exports.filterBlockNodes)(child.content, predicate)
|
|
183
|
+
: child.content;
|
|
184
|
+
if (predicate(child)) {
|
|
185
|
+
updatedNodes.push(child.type.create(child.attrs, newContent, child.marks));
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return prosemirror_model_1.Fragment.fromArray(updatedNodes);
|
|
189
|
+
};
|
|
190
|
+
exports.filterBlockNodes = filterBlockNodes;
|
|
173
191
|
const getLastTitleNode = (state) => {
|
|
174
192
|
const altTitleNode = (0, prosemirror_utils_1.findChildrenByType)(state.doc, state.schema.nodes.alt_titles)[0];
|
|
175
193
|
if (altTitleNode) {
|
|
@@ -20,16 +20,19 @@ const transform_1 = require("@manuscripts/transform");
|
|
|
20
20
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
21
21
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
22
22
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
23
|
+
const filtered_document_1 = require("../lib/filtered-document");
|
|
23
24
|
exports.objectsKey = new prosemirror_state_1.PluginKey('objects');
|
|
24
25
|
exports.default = () => {
|
|
25
26
|
return new prosemirror_state_1.Plugin({
|
|
26
27
|
key: exports.objectsKey,
|
|
27
28
|
state: {
|
|
28
29
|
init: (config, state) => {
|
|
29
|
-
|
|
30
|
+
const filteredDoc = (0, filtered_document_1.getDocWithoutMovedContent)(state.doc);
|
|
31
|
+
return (0, transform_1.buildTargets)(prosemirror_model_1.Fragment.from(filteredDoc.content));
|
|
30
32
|
},
|
|
31
33
|
apply: (tr) => {
|
|
32
|
-
|
|
34
|
+
const filteredDoc = (0, filtered_document_1.getDocWithoutMovedContent)(tr.doc);
|
|
35
|
+
return (0, transform_1.buildTargets)(prosemirror_model_1.Fragment.from(filteredDoc.content));
|
|
33
36
|
},
|
|
34
37
|
},
|
|
35
38
|
props: {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
4
4
|
const transform_1 = require("@manuscripts/transform");
|
|
5
5
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
|
+
const filtered_document_1 = require("../lib/filtered-document");
|
|
6
7
|
const plugins_1 = require("../lib/plugins");
|
|
7
8
|
const isManuscriptNode = (node) => {
|
|
8
9
|
return node && node.type === transform_1.schema.nodes.manuscript;
|
|
@@ -19,7 +20,8 @@ exports.default = () => {
|
|
|
19
20
|
if (!(node.type.spec.attrs && 'id' in node.type.spec.attrs) ||
|
|
20
21
|
(0, transform_1.isHighlightMarkerNode)(node) ||
|
|
21
22
|
isManuscriptNode(node) ||
|
|
22
|
-
isManuscriptNode(parent)
|
|
23
|
+
isManuscriptNode(parent) ||
|
|
24
|
+
(0, filtered_document_1.isMoved)(node)) {
|
|
23
25
|
return;
|
|
24
26
|
}
|
|
25
27
|
let id = node.attrs.id;
|
|
@@ -5,10 +5,14 @@ const transform_1 = require("@manuscripts/transform");
|
|
|
5
5
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
6
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
7
7
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
8
|
+
const filtered_document_1 = require("../../lib/filtered-document");
|
|
8
9
|
const autocompletion_1 = require("./autocompletion");
|
|
9
10
|
exports.sectionTitleKey = new prosemirror_state_1.PluginKey('sectionNumbering');
|
|
10
11
|
const calculateSectionLevels = (node, startPos, sectionNumberMap, numbering = [0]) => {
|
|
11
12
|
node.forEach((childNode, offset) => {
|
|
13
|
+
if ((0, filtered_document_1.isMoved)(childNode)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
12
16
|
if (childNode.type === transform_1.schema.nodes.section ||
|
|
13
17
|
childNode.type === transform_1.schema.nodes.box_element) {
|
|
14
18
|
numbering[numbering.length - 1] += 1;
|
|
@@ -59,9 +59,6 @@ const getEffectiveSelection = ($pos) => {
|
|
|
59
59
|
to: $pos.after(depth),
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
else {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
62
|
}
|
|
66
63
|
if (current) {
|
|
67
64
|
return current;
|
|
@@ -115,12 +112,18 @@ const buildTextDecoration = (doc, selection) => {
|
|
|
115
112
|
};
|
|
116
113
|
};
|
|
117
114
|
const buildGroupOfChangesDecoration = (doc, changes) => {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
class: 'selected-suggestion'
|
|
121
|
-
}
|
|
115
|
+
const decorations = [];
|
|
116
|
+
if (changes[0].dataTracked.operation === track_changes_plugin_1.CHANGE_OPERATION.structure) {
|
|
117
|
+
changes.map((c) => decorations.push(prosemirror_view_1.Decoration.node(c.from, c.to, { class: 'selected-suggestion' })));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const from = changes[0].from, to = changes[changes.length - 1].to;
|
|
121
|
+
decorations.push(prosemirror_view_1.Decoration.inline(from, to, {
|
|
122
|
+
class: 'selected-suggestion',
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
122
125
|
return {
|
|
123
|
-
decorations: prosemirror_view_1.DecorationSet.create(doc,
|
|
126
|
+
decorations: prosemirror_view_1.DecorationSet.create(doc, decorations),
|
|
124
127
|
suggestion: changes[0].dataTracked,
|
|
125
128
|
};
|
|
126
129
|
};
|
package/dist/cjs/selection.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSelectionChangeGroup = exports.NodesSelection = void 0;
|
|
3
|
+
exports.getSelectionChangeGroup = exports.NodesSelection = exports.InlineNodesSelection = void 0;
|
|
4
4
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
5
5
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
6
|
const commands_1 = require("./commands");
|
|
7
|
-
class
|
|
7
|
+
class InlineNodesSelection extends prosemirror_state_1.Selection {
|
|
8
8
|
constructor($from, $to) {
|
|
9
9
|
super($to, $to);
|
|
10
10
|
this.$startNode = $from;
|
|
@@ -28,18 +28,37 @@ class NodesSelection extends prosemirror_state_1.Selection {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
exports.InlineNodesSelection = InlineNodesSelection;
|
|
32
|
+
class NodesSelection extends prosemirror_state_1.NodeSelection {
|
|
33
|
+
constructor($from, $to) {
|
|
34
|
+
super($from);
|
|
35
|
+
this.$startNode = $from;
|
|
36
|
+
this.$endNode = $to;
|
|
37
|
+
}
|
|
38
|
+
toJSON() {
|
|
39
|
+
return {
|
|
40
|
+
type: 'nodes',
|
|
41
|
+
startNode: this.$startNode,
|
|
42
|
+
endNode: this.$endNode,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
31
46
|
exports.NodesSelection = NodesSelection;
|
|
32
47
|
const getSelectionChangeGroup = (state) => {
|
|
33
48
|
const selection = state.selection;
|
|
34
49
|
const $pos = (0, commands_1.isTextSelection)(selection)
|
|
35
50
|
? selection.$cursor
|
|
36
|
-
: selection instanceof NodesSelection
|
|
51
|
+
: (selection instanceof NodesSelection ||
|
|
52
|
+
selection instanceof InlineNodesSelection) &&
|
|
53
|
+
selection.$from;
|
|
37
54
|
if ($pos) {
|
|
38
55
|
return track_changes_plugin_1.trackChangesPluginKey
|
|
39
56
|
.getState(state)
|
|
40
|
-
?.changeSet.groupChanges.find((
|
|
41
|
-
$pos.pos >= changes[0].from &&
|
|
42
|
-
$pos.pos <= changes[changes.length - 1].to);
|
|
57
|
+
?.changeSet.groupChanges.find((c) => isPositionAtRange(c, $pos.pos));
|
|
43
58
|
}
|
|
44
59
|
};
|
|
45
60
|
exports.getSelectionChangeGroup = getSelectionChangeGroup;
|
|
61
|
+
const isPositionAtRange = (changes, pos) => (changes.length > 1 ||
|
|
62
|
+
changes[0].dataTracked.operation === track_changes_plugin_1.CHANGE_OPERATION.structure) &&
|
|
63
|
+
pos >= changes[0].from &&
|
|
64
|
+
pos <= changes[changes.length - 1].to;
|
package/dist/cjs/versions.js
CHANGED