@portabletext/editor 6.1.1 → 6.2.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/lib/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
|
16
16
|
import { htmlToPortableText } from "@portabletext/html";
|
|
17
17
|
import { toHTML } from "@portabletext/to-html";
|
|
18
18
|
import { markdownToPortableText, portableTextToMarkdown } from "@portabletext/markdown";
|
|
19
|
-
import { applyAll, unset, insert, setIfMissing,
|
|
19
|
+
import { applyAll, set, unset, insert, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
20
20
|
import { EditorContext as EditorContext$1 } from "./_chunks-es/use-editor.js";
|
|
21
21
|
import { useEditor } from "./_chunks-es/use-editor.js";
|
|
22
22
|
const rootName = "pte:";
|
|
@@ -36,9 +36,6 @@ const debug$1 = {
|
|
|
36
36
|
syncValue: createDebugger("sync:value"),
|
|
37
37
|
syncPatch: createDebugger("sync:patch")
|
|
38
38
|
}, Operation = {
|
|
39
|
-
isNodeOperation(value) {
|
|
40
|
-
return Operation.isOperation(value) && value.type.endsWith("_node");
|
|
41
|
-
},
|
|
42
39
|
isOperation(value) {
|
|
43
40
|
if (!isObject(value))
|
|
44
41
|
return !1;
|
|
@@ -68,12 +65,6 @@ const debug$1 = {
|
|
|
68
65
|
isOperationList(value) {
|
|
69
66
|
return Array.isArray(value) && value.every((val) => Operation.isOperation(val));
|
|
70
67
|
},
|
|
71
|
-
isSelectionOperation(value) {
|
|
72
|
-
return Operation.isOperation(value) && value.type.endsWith("_selection");
|
|
73
|
-
},
|
|
74
|
-
isTextOperation(value) {
|
|
75
|
-
return Operation.isOperation(value) && value.type.endsWith("_text");
|
|
76
|
-
},
|
|
77
68
|
inverse(op) {
|
|
78
69
|
switch (op.type) {
|
|
79
70
|
case "insert_node":
|
|
@@ -177,10 +168,6 @@ const debug$1 = {
|
|
|
177
168
|
equals(range2, another) {
|
|
178
169
|
return Point.equals(range2.anchor, another.anchor) && Point.equals(range2.focus, another.focus);
|
|
179
170
|
},
|
|
180
|
-
surrounds(range2, target) {
|
|
181
|
-
const intersectionRange = Range.intersection(range2, target);
|
|
182
|
-
return intersectionRange ? Range.equals(intersectionRange, target) : !1;
|
|
183
|
-
},
|
|
184
171
|
includes(range2, target) {
|
|
185
172
|
if (Range.isRange(target)) {
|
|
186
173
|
if (Range.includes(range2, target.anchor) || Range.includes(range2, target.focus))
|
|
@@ -280,18 +267,6 @@ const debug$1 = {
|
|
|
280
267
|
},
|
|
281
268
|
isElement(value, schema) {
|
|
282
269
|
return isObject(value) && value._type === schema.block.name;
|
|
283
|
-
},
|
|
284
|
-
isElementList(value, schema) {
|
|
285
|
-
return Array.isArray(value) && value.every((val) => Element$2.isElement(val, schema));
|
|
286
|
-
},
|
|
287
|
-
isElementProps(props) {
|
|
288
|
-
return props.children !== void 0;
|
|
289
|
-
},
|
|
290
|
-
matches(element, props) {
|
|
291
|
-
for (const key in props)
|
|
292
|
-
if (key !== "children" && element[key] !== props[key])
|
|
293
|
-
return !1;
|
|
294
|
-
return !0;
|
|
295
270
|
}
|
|
296
271
|
}, Span = {
|
|
297
272
|
isSpan(value) {
|
|
@@ -331,10 +306,6 @@ const debug$1 = {
|
|
|
331
306
|
throw new Error(`Cannot get the ancestor node at path [${path2}] because it refers to a leaf node instead: ${Scrubber.stringify(node2)}`);
|
|
332
307
|
return node2;
|
|
333
308
|
},
|
|
334
|
-
*ancestors(root, path2, schema, options = {}) {
|
|
335
|
-
for (const p of Path.ancestors(path2, options))
|
|
336
|
-
yield [Node$1.ancestor(root, p, schema), p];
|
|
337
|
-
},
|
|
338
309
|
child(root, index, schema) {
|
|
339
310
|
if (Text$1.isText(root, schema) || Node$1.isObjectNode(root, schema))
|
|
340
311
|
throw new Error(`Cannot get the child of a leaf node: ${Scrubber.stringify(root)}`);
|
|
@@ -355,24 +326,6 @@ const debug$1 = {
|
|
|
355
326
|
yield [child, childPath], index = reverse ? index - 1 : index + 1;
|
|
356
327
|
}
|
|
357
328
|
},
|
|
358
|
-
common(root, path2, another, schema) {
|
|
359
|
-
const p = Path.common(path2, another);
|
|
360
|
-
return [Node$1.get(root, p, schema), p];
|
|
361
|
-
},
|
|
362
|
-
descendant(root, path2, schema) {
|
|
363
|
-
const node2 = Node$1.get(root, path2, schema);
|
|
364
|
-
if (Editor.isEditor(node2))
|
|
365
|
-
throw new Error(`Cannot get the descendant node at path [${path2}] because it refers to the root editor node instead: ${Scrubber.stringify(node2)}`);
|
|
366
|
-
return node2;
|
|
367
|
-
},
|
|
368
|
-
*descendants(root, schema, options = {}) {
|
|
369
|
-
for (const [node2, path2] of Node$1.nodes(root, schema, options))
|
|
370
|
-
path2.length !== 0 && (yield [node2, path2]);
|
|
371
|
-
},
|
|
372
|
-
*elements(root, schema, options = {}) {
|
|
373
|
-
for (const [node2, path2] of Node$1.nodes(root, schema, options))
|
|
374
|
-
Element$2.isElement(node2, schema) && (yield [node2, path2]);
|
|
375
|
-
},
|
|
376
329
|
extractProps(node2, schema) {
|
|
377
330
|
if (Element$2.isAncestor(node2, schema)) {
|
|
378
331
|
const {
|
|
@@ -503,9 +456,6 @@ const debug$1 = {
|
|
|
503
456
|
for (const p of Path.levels(path2, options))
|
|
504
457
|
yield [Node$1.get(root, p, schema), p];
|
|
505
458
|
},
|
|
506
|
-
matches(node2, props, schema) {
|
|
507
|
-
return Element$2.isElement(node2, schema) && Element$2.isElementProps(props) && Element$2.matches(node2, props) || Text$1.isText(node2, schema) && Text$1.isTextProps(props) && Text$1.matches(node2, props);
|
|
508
|
-
},
|
|
509
459
|
*nodes(root, schema, options = {}) {
|
|
510
460
|
const {
|
|
511
461
|
pass,
|
|
@@ -593,14 +543,6 @@ const debug$1 = {
|
|
|
593
543
|
}
|
|
594
544
|
return 0;
|
|
595
545
|
},
|
|
596
|
-
endsAfter(path2, another) {
|
|
597
|
-
const i = path2.length - 1, as = path2.slice(0, i), bs = another.slice(0, i), av = path2[i], bv = another[i];
|
|
598
|
-
return Path.equals(as, bs) && av > bv;
|
|
599
|
-
},
|
|
600
|
-
endsAt(path2, another) {
|
|
601
|
-
const i = path2.length, as = path2.slice(0, i), bs = another.slice(0, i);
|
|
602
|
-
return Path.equals(as, bs);
|
|
603
|
-
},
|
|
604
546
|
endsBefore(path2, another) {
|
|
605
547
|
const i = path2.length - 1, as = path2.slice(0, i), bs = another.slice(0, i), av = path2[i], bv = another[i];
|
|
606
548
|
return Path.equals(as, bs) && av < bv;
|
|
@@ -620,18 +562,12 @@ const debug$1 = {
|
|
|
620
562
|
isBefore(path2, another) {
|
|
621
563
|
return Path.compare(path2, another) === -1;
|
|
622
564
|
},
|
|
623
|
-
isChild(path2, another) {
|
|
624
|
-
return path2.length === another.length + 1 && Path.compare(path2, another) === 0;
|
|
625
|
-
},
|
|
626
565
|
isCommon(path2, another) {
|
|
627
566
|
return path2.length <= another.length && Path.compare(path2, another) === 0;
|
|
628
567
|
},
|
|
629
568
|
isDescendant(path2, another) {
|
|
630
569
|
return path2.length > another.length && Path.compare(path2, another) === 0;
|
|
631
570
|
},
|
|
632
|
-
isParent(path2, another) {
|
|
633
|
-
return path2.length + 1 === another.length && Path.compare(path2, another) === 0;
|
|
634
|
-
},
|
|
635
571
|
isPath(value) {
|
|
636
572
|
return Array.isArray(value) && (value.length === 0 || typeof value[0] == "number");
|
|
637
573
|
},
|
|
@@ -680,11 +616,6 @@ const debug$1 = {
|
|
|
680
616
|
throw new Error(`Cannot get the previous path of a first child path [${path2}] because it would result in a negative index.`);
|
|
681
617
|
return path2.slice(0, -1).concat(last - 1);
|
|
682
618
|
},
|
|
683
|
-
relative(path2, ancestor) {
|
|
684
|
-
if (!Path.isAncestor(ancestor, path2) && !Path.equals(path2, ancestor))
|
|
685
|
-
throw new Error(`Cannot get the relative path of [${path2}] inside ancestor [${ancestor}], because it is not above or equal to the path.`);
|
|
686
|
-
return path2.slice(ancestor.length);
|
|
687
|
-
},
|
|
688
619
|
transform(path2, operation, options = {}) {
|
|
689
620
|
if (!path2)
|
|
690
621
|
return null;
|
|
@@ -844,14 +775,9 @@ const debug$1 = {
|
|
|
844
775
|
});
|
|
845
776
|
ref.current = path2, path2 == null && ref.unref();
|
|
846
777
|
}
|
|
847
|
-
}
|
|
848
|
-
let _scrubber;
|
|
849
|
-
const Scrubber = {
|
|
850
|
-
setScrubber(scrubber) {
|
|
851
|
-
_scrubber = scrubber;
|
|
852
|
-
},
|
|
778
|
+
}, Scrubber = {
|
|
853
779
|
stringify(value) {
|
|
854
|
-
return JSON.stringify(value
|
|
780
|
+
return JSON.stringify(value);
|
|
855
781
|
}
|
|
856
782
|
}, Text$1 = {
|
|
857
783
|
equals(text, another, options = {}) {
|
|
@@ -870,18 +796,6 @@ const Scrubber = {
|
|
|
870
796
|
isText(value, schema) {
|
|
871
797
|
return isObject(value) && value._type === schema.span.name;
|
|
872
798
|
},
|
|
873
|
-
isTextList(value, schema) {
|
|
874
|
-
return Array.isArray(value) && value.every((val) => Text$1.isText(val, schema));
|
|
875
|
-
},
|
|
876
|
-
isTextProps(props) {
|
|
877
|
-
return props.text !== void 0;
|
|
878
|
-
},
|
|
879
|
-
matches(text, props) {
|
|
880
|
-
for (const key in props)
|
|
881
|
-
if (key !== "text" && (!text.hasOwnProperty(key) || text[key] !== props[key]))
|
|
882
|
-
return !1;
|
|
883
|
-
return !0;
|
|
884
|
-
},
|
|
885
799
|
decorations(node2, decorations) {
|
|
886
800
|
let leaves = [{
|
|
887
801
|
leaf: {
|
|
@@ -992,42 +906,6 @@ const Scrubber = {
|
|
|
992
906
|
}), transformSelection = !0;
|
|
993
907
|
break;
|
|
994
908
|
}
|
|
995
|
-
case "merge_node": {
|
|
996
|
-
const {
|
|
997
|
-
path: path2
|
|
998
|
-
} = op, index = path2[path2.length - 1], prevPath = Path.previous(path2), prevIndex = prevPath[prevPath.length - 1];
|
|
999
|
-
modifyChildren(editor, Path.parent(path2), editor.schema, (children) => {
|
|
1000
|
-
const node2 = children[index], prev = children[prevIndex];
|
|
1001
|
-
let newNode;
|
|
1002
|
-
if (Text$1.isText(node2, editor.schema) && Text$1.isText(prev, editor.schema))
|
|
1003
|
-
newNode = {
|
|
1004
|
-
...prev,
|
|
1005
|
-
text: prev.text + node2.text
|
|
1006
|
-
};
|
|
1007
|
-
else if (!Text$1.isText(node2, editor.schema) && !Text$1.isText(prev, editor.schema))
|
|
1008
|
-
newNode = {
|
|
1009
|
-
...prev,
|
|
1010
|
-
children: prev.children.concat(node2.children)
|
|
1011
|
-
};
|
|
1012
|
-
else
|
|
1013
|
-
throw new Error(`Cannot apply a "merge_node" operation at path [${path2}] to nodes of different interfaces: ${Scrubber.stringify(node2)} ${Scrubber.stringify(prev)}`);
|
|
1014
|
-
return replaceChildren(children, prevIndex, 2, newNode);
|
|
1015
|
-
}), transformSelection = !0;
|
|
1016
|
-
break;
|
|
1017
|
-
}
|
|
1018
|
-
case "move_node": {
|
|
1019
|
-
const {
|
|
1020
|
-
path: path2,
|
|
1021
|
-
newPath
|
|
1022
|
-
} = op, index = path2[path2.length - 1];
|
|
1023
|
-
if (Path.isAncestor(path2, newPath))
|
|
1024
|
-
throw new Error(`Cannot move a path [${path2}] to new path [${newPath}] because the destination is inside itself.`);
|
|
1025
|
-
const node2 = Node$1.get(editor, path2, editor.schema);
|
|
1026
|
-
modifyChildren(editor, Path.parent(path2), editor.schema, (children) => removeChildren(children, index, 1));
|
|
1027
|
-
const truePath = Path.transform(path2, op), newIndex = truePath[truePath.length - 1];
|
|
1028
|
-
modifyChildren(editor, Path.parent(truePath), editor.schema, (children) => insertChildren(children, newIndex, node2)), transformSelection = !0;
|
|
1029
|
-
break;
|
|
1030
|
-
}
|
|
1031
909
|
case "remove_node": {
|
|
1032
910
|
const {
|
|
1033
911
|
path: path2
|
|
@@ -1137,40 +1015,6 @@ const Scrubber = {
|
|
|
1137
1015
|
editor.selection = selection;
|
|
1138
1016
|
break;
|
|
1139
1017
|
}
|
|
1140
|
-
case "split_node": {
|
|
1141
|
-
const {
|
|
1142
|
-
path: path2,
|
|
1143
|
-
position,
|
|
1144
|
-
properties
|
|
1145
|
-
} = op, index = path2[path2.length - 1];
|
|
1146
|
-
if (path2.length === 0)
|
|
1147
|
-
throw new Error(`Cannot apply a "split_node" operation at path [${path2}] because the root node cannot be split.`);
|
|
1148
|
-
modifyChildren(editor, Path.parent(path2), editor.schema, (children) => {
|
|
1149
|
-
const node2 = children[index];
|
|
1150
|
-
let newNode, nextNode;
|
|
1151
|
-
if (Text$1.isText(node2, editor.schema)) {
|
|
1152
|
-
const before2 = node2.text.slice(0, position), after2 = node2.text.slice(position);
|
|
1153
|
-
newNode = {
|
|
1154
|
-
...node2,
|
|
1155
|
-
text: before2
|
|
1156
|
-
}, nextNode = {
|
|
1157
|
-
...properties,
|
|
1158
|
-
text: after2
|
|
1159
|
-
};
|
|
1160
|
-
} else {
|
|
1161
|
-
const before2 = node2.children.slice(0, position), after2 = node2.children.slice(position);
|
|
1162
|
-
newNode = {
|
|
1163
|
-
...node2,
|
|
1164
|
-
children: before2
|
|
1165
|
-
}, nextNode = {
|
|
1166
|
-
...properties,
|
|
1167
|
-
children: after2
|
|
1168
|
-
};
|
|
1169
|
-
}
|
|
1170
|
-
return replaceChildren(children, index, 1, newNode, nextNode);
|
|
1171
|
-
}), transformSelection = !0;
|
|
1172
|
-
break;
|
|
1173
|
-
}
|
|
1174
1018
|
}
|
|
1175
1019
|
if (transformSelection && editor.selection) {
|
|
1176
1020
|
const selection = {
|
|
@@ -1185,17 +1029,8 @@ const Scrubber = {
|
|
|
1185
1029
|
insertNodes(editor, nodes2, options) {
|
|
1186
1030
|
editor.insertNodes(nodes2, options);
|
|
1187
1031
|
},
|
|
1188
|
-
mergeNodes(editor, options) {
|
|
1189
|
-
editor.mergeNodes(options);
|
|
1190
|
-
},
|
|
1191
|
-
moveNodes(editor, options) {
|
|
1192
|
-
editor.moveNodes(options);
|
|
1193
|
-
},
|
|
1194
1032
|
removeNodes(editor, options) {
|
|
1195
1033
|
editor.removeNodes(options);
|
|
1196
|
-
},
|
|
1197
|
-
splitNodes(editor, options) {
|
|
1198
|
-
editor.splitNodes(options);
|
|
1199
1034
|
}
|
|
1200
1035
|
}, SelectionTransforms = {
|
|
1201
1036
|
collapse(editor, options) {
|
|
@@ -1431,9 +1266,6 @@ const endingEmojiZWJ = new RegExp("\\p{ExtPict}[\\p{Gr_Ext}\\p{EMod}]*\\u200D$",
|
|
|
1431
1266
|
levels(editor, options) {
|
|
1432
1267
|
return editor.levels(options);
|
|
1433
1268
|
},
|
|
1434
|
-
marks(editor) {
|
|
1435
|
-
return editor.getMarks();
|
|
1436
|
-
},
|
|
1437
1269
|
next(editor, options) {
|
|
1438
1270
|
return editor.next(options);
|
|
1439
1271
|
},
|
|
@@ -1566,43 +1398,12 @@ const apply$1 = (editor, op) => {
|
|
|
1566
1398
|
} = op, levels2 = Path.levels(path2), descendants = Text$1.isText(node2, _editor.schema) ? [] : Array.from(Node$1.nodes(node2, _editor.schema), ([, p]) => path2.concat(p));
|
|
1567
1399
|
return [...levels2, ...descendants];
|
|
1568
1400
|
}
|
|
1569
|
-
case "merge_node": {
|
|
1570
|
-
const {
|
|
1571
|
-
path: path2
|
|
1572
|
-
} = op, ancestors = Path.ancestors(path2), previousPath = Path.previous(path2);
|
|
1573
|
-
return [...ancestors, previousPath];
|
|
1574
|
-
}
|
|
1575
|
-
case "move_node": {
|
|
1576
|
-
const {
|
|
1577
|
-
path: path2,
|
|
1578
|
-
newPath
|
|
1579
|
-
} = op;
|
|
1580
|
-
if (Path.equals(path2, newPath))
|
|
1581
|
-
return [];
|
|
1582
|
-
const oldAncestors = [], newAncestors = [];
|
|
1583
|
-
for (const ancestor of Path.ancestors(path2)) {
|
|
1584
|
-
const p = Path.transform(ancestor, op);
|
|
1585
|
-
oldAncestors.push(p);
|
|
1586
|
-
}
|
|
1587
|
-
for (const ancestor of Path.ancestors(newPath)) {
|
|
1588
|
-
const p = Path.transform(ancestor, op);
|
|
1589
|
-
newAncestors.push(p);
|
|
1590
|
-
}
|
|
1591
|
-
const newParent = newAncestors[newAncestors.length - 1], newIndex = newPath[newPath.length - 1], resultPath = newParent.concat(newIndex);
|
|
1592
|
-
return [...oldAncestors, ...newAncestors, resultPath];
|
|
1593
|
-
}
|
|
1594
1401
|
case "remove_node": {
|
|
1595
1402
|
const {
|
|
1596
1403
|
path: path2
|
|
1597
1404
|
} = op;
|
|
1598
1405
|
return [...Path.ancestors(path2)];
|
|
1599
1406
|
}
|
|
1600
|
-
case "split_node": {
|
|
1601
|
-
const {
|
|
1602
|
-
path: path2
|
|
1603
|
-
} = op, levels2 = Path.levels(path2), nextPath = Path.next(path2);
|
|
1604
|
-
return [...levels2, nextPath];
|
|
1605
|
-
}
|
|
1606
1407
|
default:
|
|
1607
1408
|
return [];
|
|
1608
1409
|
}
|
|
@@ -1611,7 +1412,135 @@ const apply$1 = (editor, op) => {
|
|
|
1611
1412
|
selection
|
|
1612
1413
|
} = editor;
|
|
1613
1414
|
return selection ? Node$1.fragment(editor, selection, editor.schema) : [];
|
|
1614
|
-
}
|
|
1415
|
+
};
|
|
1416
|
+
function applyMergeNode(editor, path2, position, properties) {
|
|
1417
|
+
const node2 = Node$1.get(editor, path2, editor.schema), prevPath = Path.previous(path2), mergeOp = {
|
|
1418
|
+
type: "merge_node",
|
|
1419
|
+
path: path2,
|
|
1420
|
+
position,
|
|
1421
|
+
properties
|
|
1422
|
+
};
|
|
1423
|
+
for (const ref of Editor.pathRefs(editor))
|
|
1424
|
+
PathRef.transform(ref, mergeOp);
|
|
1425
|
+
for (const ref of Editor.pointRefs(editor))
|
|
1426
|
+
PointRef.transform(ref, mergeOp);
|
|
1427
|
+
for (const ref of Editor.rangeRefs(editor))
|
|
1428
|
+
RangeRef.transform(ref, mergeOp);
|
|
1429
|
+
if (editor.selection) {
|
|
1430
|
+
const sel = {
|
|
1431
|
+
...editor.selection
|
|
1432
|
+
};
|
|
1433
|
+
for (const [point2, key] of Range.points(sel)) {
|
|
1434
|
+
const result = Point.transform(point2, mergeOp);
|
|
1435
|
+
result && (sel[key] = result);
|
|
1436
|
+
}
|
|
1437
|
+
editor.selection = sel;
|
|
1438
|
+
}
|
|
1439
|
+
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
1440
|
+
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
1441
|
+
const savedSelection = editor.selection, editorAny = editor, savedPendingDiffs = editorAny.pendingDiffs, savedPendingSelection = editorAny.pendingSelection, savedPendingAction = editorAny.pendingAction;
|
|
1442
|
+
if (Array.isArray(savedPendingDiffs) && savedPendingDiffs.length > 0 && (editorAny.pendingDiffs = savedPendingDiffs.map((textDiff) => transformTextDiffForMerge(textDiff, mergeOp)).filter(Boolean)), savedPendingSelection && typeof savedPendingSelection == "object" && "anchor" in savedPendingSelection && "focus" in savedPendingSelection) {
|
|
1443
|
+
const sel = savedPendingSelection, anchor = Point.transform(sel.anchor, mergeOp, {
|
|
1444
|
+
affinity: "backward"
|
|
1445
|
+
}), focus = Point.transform(sel.focus, mergeOp, {
|
|
1446
|
+
affinity: "backward"
|
|
1447
|
+
});
|
|
1448
|
+
editorAny.pendingSelection = anchor && focus ? {
|
|
1449
|
+
anchor,
|
|
1450
|
+
focus
|
|
1451
|
+
} : null;
|
|
1452
|
+
}
|
|
1453
|
+
if (savedPendingAction && typeof savedPendingAction == "object" && "at" in savedPendingAction) {
|
|
1454
|
+
const action = savedPendingAction;
|
|
1455
|
+
if (Point.isPoint(action.at)) {
|
|
1456
|
+
const at = Point.transform(action.at, mergeOp, {
|
|
1457
|
+
affinity: "backward"
|
|
1458
|
+
});
|
|
1459
|
+
editorAny.pendingAction = at ? {
|
|
1460
|
+
...action,
|
|
1461
|
+
at
|
|
1462
|
+
} : null;
|
|
1463
|
+
} else if (Range.isRange(action.at)) {
|
|
1464
|
+
const anchor = Point.transform(action.at.anchor, mergeOp, {
|
|
1465
|
+
affinity: "backward"
|
|
1466
|
+
}), focus = Point.transform(action.at.focus, mergeOp, {
|
|
1467
|
+
affinity: "backward"
|
|
1468
|
+
});
|
|
1469
|
+
editorAny.pendingAction = anchor && focus ? {
|
|
1470
|
+
...action,
|
|
1471
|
+
at: {
|
|
1472
|
+
anchor,
|
|
1473
|
+
focus
|
|
1474
|
+
}
|
|
1475
|
+
} : null;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
const preTransformedPendingDiffs = editorAny.pendingDiffs, preTransformedPendingSelection = editorAny.pendingSelection, preTransformedPendingAction = editorAny.pendingAction;
|
|
1479
|
+
editorAny.pendingDiffs = [], editorAny.pendingSelection = null, editorAny.pendingAction = null;
|
|
1480
|
+
try {
|
|
1481
|
+
Editor.withoutNormalizing(editor, () => {
|
|
1482
|
+
if (Text$1.isText(node2, editor.schema))
|
|
1483
|
+
node2.text.length > 0 && editor.apply({
|
|
1484
|
+
type: "insert_text",
|
|
1485
|
+
path: prevPath,
|
|
1486
|
+
offset: position,
|
|
1487
|
+
text: node2.text
|
|
1488
|
+
}), editor.apply({
|
|
1489
|
+
type: "remove_node",
|
|
1490
|
+
path: path2,
|
|
1491
|
+
node: node2
|
|
1492
|
+
});
|
|
1493
|
+
else if (Element$2.isElement(node2, editor.schema)) {
|
|
1494
|
+
const children = node2.children;
|
|
1495
|
+
for (let i = 0; i < children.length; i++)
|
|
1496
|
+
editor.apply({
|
|
1497
|
+
type: "insert_node",
|
|
1498
|
+
path: [...prevPath, position + i],
|
|
1499
|
+
node: children[i]
|
|
1500
|
+
});
|
|
1501
|
+
editor.apply({
|
|
1502
|
+
type: "remove_node",
|
|
1503
|
+
path: path2,
|
|
1504
|
+
node: node2
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
} finally {
|
|
1509
|
+
editor.selection = savedSelection;
|
|
1510
|
+
for (const ref of pathRefs)
|
|
1511
|
+
Editor.pathRefs(editor).add(ref);
|
|
1512
|
+
for (const ref of pointRefs)
|
|
1513
|
+
Editor.pointRefs(editor).add(ref);
|
|
1514
|
+
for (const ref of rangeRefs)
|
|
1515
|
+
Editor.rangeRefs(editor).add(ref);
|
|
1516
|
+
editorAny.pendingDiffs = preTransformedPendingDiffs, editorAny.pendingSelection = preTransformedPendingSelection, editorAny.pendingAction = preTransformedPendingAction;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
function transformTextDiffForMerge(textDiff, op) {
|
|
1520
|
+
const {
|
|
1521
|
+
path: path2,
|
|
1522
|
+
diff: diff2,
|
|
1523
|
+
id
|
|
1524
|
+
} = textDiff;
|
|
1525
|
+
if (!Path.equals(op.path, path2)) {
|
|
1526
|
+
const newPath = Path.transform(path2, op);
|
|
1527
|
+
return newPath ? {
|
|
1528
|
+
diff: diff2,
|
|
1529
|
+
id,
|
|
1530
|
+
path: newPath
|
|
1531
|
+
} : null;
|
|
1532
|
+
}
|
|
1533
|
+
return {
|
|
1534
|
+
diff: {
|
|
1535
|
+
start: diff2.start + op.position,
|
|
1536
|
+
end: diff2.end + op.position,
|
|
1537
|
+
text: diff2.text
|
|
1538
|
+
},
|
|
1539
|
+
id,
|
|
1540
|
+
path: Path.transform(path2, op)
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
const normalizeNode = (editor, entry) => {
|
|
1615
1544
|
const [node2, path2] = entry;
|
|
1616
1545
|
if (Text$1.isText(node2, editor.schema) || editor.isObjectNode(node2))
|
|
1617
1546
|
return;
|
|
@@ -1628,20 +1557,29 @@ const apply$1 = (editor, op) => {
|
|
|
1628
1557
|
if (element !== editor && (editor.isInline(element) || Text$1.isText(firstChild, editor.schema) || editor.isObjectNode(firstChild) || Element$2.isElement(firstChild, editor.schema) && editor.isInline(firstChild)))
|
|
1629
1558
|
for (let n2 = 0; n2 < element.children.length; n2++) {
|
|
1630
1559
|
const child = element.children[n2], prev = element.children[n2 - 1];
|
|
1631
|
-
if (Text$1.isText(child, editor.schema))
|
|
1632
|
-
prev != null && Text$1.isText(prev, editor.schema)
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1560
|
+
if (Text$1.isText(child, editor.schema)) {
|
|
1561
|
+
if (prev != null && Text$1.isText(prev, editor.schema)) {
|
|
1562
|
+
if (child.text === "")
|
|
1563
|
+
Transforms.removeNodes(editor, {
|
|
1564
|
+
at: path2.concat(n2),
|
|
1565
|
+
voids: !0
|
|
1566
|
+
}), element = Node$1.get(editor, path2, editor.schema), n2--;
|
|
1567
|
+
else if (prev.text === "")
|
|
1568
|
+
Transforms.removeNodes(editor, {
|
|
1569
|
+
at: path2.concat(n2 - 1),
|
|
1570
|
+
voids: !0
|
|
1571
|
+
}), element = Node$1.get(editor, path2, editor.schema), n2--;
|
|
1572
|
+
else if (Text$1.equals(child, prev, {
|
|
1573
|
+
loose: !0
|
|
1574
|
+
})) {
|
|
1575
|
+
const mergePath = path2.concat(n2), {
|
|
1576
|
+
text: _text,
|
|
1577
|
+
...properties
|
|
1578
|
+
} = child;
|
|
1579
|
+
applyMergeNode(editor, mergePath, prev.text.length, properties), element = Node$1.get(editor, path2, editor.schema), n2--;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
} else if (Element$2.isElement(child, editor.schema))
|
|
1645
1583
|
if (editor.isInline(child)) {
|
|
1646
1584
|
if (prev == null || !Text$1.isText(prev, editor.schema)) {
|
|
1647
1585
|
const newChild = editor.createSpan();
|
|
@@ -1775,13 +1713,13 @@ const apply$1 = (editor, op) => {
|
|
|
1775
1713
|
}, hasInlines = (editor, element) => element.children.some((n2) => Text$1.isText(n2, editor.schema) || Editor.isInline(editor, n2)), hasPath = (editor, path2) => Node$1.has(editor, path2, editor.schema), insertText = (editor, text, options = {}) => {
|
|
1776
1714
|
const {
|
|
1777
1715
|
selection,
|
|
1778
|
-
marks
|
|
1716
|
+
marks
|
|
1779
1717
|
} = editor;
|
|
1780
1718
|
if (selection) {
|
|
1781
|
-
if (
|
|
1719
|
+
if (marks) {
|
|
1782
1720
|
const node2 = {
|
|
1783
1721
|
text,
|
|
1784
|
-
...
|
|
1722
|
+
...marks
|
|
1785
1723
|
};
|
|
1786
1724
|
Transforms.insertNodes(editor, node2, {
|
|
1787
1725
|
at: options.at,
|
|
@@ -1818,64 +1756,7 @@ function* levels(editor, options = {}) {
|
|
|
1818
1756
|
match2(n2, p) && levels2.push([n2, p]);
|
|
1819
1757
|
reverse && levels2.reverse(), yield* levels2;
|
|
1820
1758
|
}
|
|
1821
|
-
const
|
|
1822
|
-
const {
|
|
1823
|
-
marks: marks2,
|
|
1824
|
-
selection
|
|
1825
|
-
} = editor;
|
|
1826
|
-
if (!selection)
|
|
1827
|
-
return null;
|
|
1828
|
-
let {
|
|
1829
|
-
anchor,
|
|
1830
|
-
focus
|
|
1831
|
-
} = selection;
|
|
1832
|
-
if (marks2)
|
|
1833
|
-
return marks2;
|
|
1834
|
-
if (Range.isExpanded(selection)) {
|
|
1835
|
-
if (Range.isBackward(selection) && ([focus, anchor] = [anchor, focus]), Editor.isEnd(editor, anchor, anchor.path)) {
|
|
1836
|
-
const after2 = Editor.after(editor, anchor);
|
|
1837
|
-
after2 && (anchor = after2);
|
|
1838
|
-
}
|
|
1839
|
-
const [match2] = Editor.nodes(editor, {
|
|
1840
|
-
match: (n2) => Text$1.isText(n2, editor.schema),
|
|
1841
|
-
at: {
|
|
1842
|
-
anchor,
|
|
1843
|
-
focus
|
|
1844
|
-
}
|
|
1845
|
-
});
|
|
1846
|
-
if (match2) {
|
|
1847
|
-
const [node22] = match2, {
|
|
1848
|
-
text: _text,
|
|
1849
|
-
...rest2
|
|
1850
|
-
} = node22;
|
|
1851
|
-
return rest2;
|
|
1852
|
-
} else
|
|
1853
|
-
return {};
|
|
1854
|
-
}
|
|
1855
|
-
const {
|
|
1856
|
-
path: path2
|
|
1857
|
-
} = anchor;
|
|
1858
|
-
let [node2] = Editor.leaf(editor, path2);
|
|
1859
|
-
if (!Text$1.isText(node2, editor.schema))
|
|
1860
|
-
return {};
|
|
1861
|
-
if (anchor.offset === 0) {
|
|
1862
|
-
const prev = Editor.previous(editor, {
|
|
1863
|
-
at: path2,
|
|
1864
|
-
match: (n2) => Text$1.isText(n2, editor.schema)
|
|
1865
|
-
}), block = Editor.above(editor, {
|
|
1866
|
-
match: (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2)
|
|
1867
|
-
});
|
|
1868
|
-
if (prev && block) {
|
|
1869
|
-
const [prevNode, prevPath] = prev, [, blockPath] = block;
|
|
1870
|
-
Path.isAncestor(blockPath, prevPath) && (node2 = prevNode);
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
const {
|
|
1874
|
-
text: _text2,
|
|
1875
|
-
...rest
|
|
1876
|
-
} = node2;
|
|
1877
|
-
return rest;
|
|
1878
|
-
}, next = (editor, options = {}) => {
|
|
1759
|
+
const next = (editor, options = {}) => {
|
|
1879
1760
|
const {
|
|
1880
1761
|
mode = "lowest",
|
|
1881
1762
|
voids = !1
|
|
@@ -2293,7 +2174,77 @@ const previous = (editor, options = {}) => {
|
|
|
2293
2174
|
Editor.setNormalizing(editor, value);
|
|
2294
2175
|
}
|
|
2295
2176
|
Editor.normalize(editor);
|
|
2296
|
-
}, shouldMergeNodesRemovePrevNode = (_editor, [prevNode, prevPath], [_curNode, _curNodePath]) => Element$2.isElement(prevNode, _editor.schema) && (prevNode.children.length === 0 || prevNode.children.length === 1 && Text$1.isText(prevNode.children[0], _editor.schema) && prevNode.children[0].text === "") || Text$1.isText(prevNode, _editor.schema) && prevNode.text === "" && prevPath[prevPath.length - 1] !== 0
|
|
2177
|
+
}, shouldMergeNodesRemovePrevNode = (_editor, [prevNode, prevPath], [_curNode, _curNodePath]) => Element$2.isElement(prevNode, _editor.schema) && (prevNode.children.length === 0 || prevNode.children.length === 1 && Text$1.isText(prevNode.children[0], _editor.schema) && prevNode.children[0].text === "") || Text$1.isText(prevNode, _editor.schema) && prevNode.text === "" && prevPath[prevPath.length - 1] !== 0;
|
|
2178
|
+
function applySplitNode(editor, path2, position, properties) {
|
|
2179
|
+
const node2 = Node$1.get(editor, path2, editor.schema), splitOp = {
|
|
2180
|
+
type: "split_node",
|
|
2181
|
+
path: path2,
|
|
2182
|
+
position,
|
|
2183
|
+
properties
|
|
2184
|
+
};
|
|
2185
|
+
for (const ref of Editor.pathRefs(editor))
|
|
2186
|
+
PathRef.transform(ref, splitOp);
|
|
2187
|
+
for (const ref of Editor.pointRefs(editor))
|
|
2188
|
+
PointRef.transform(ref, splitOp);
|
|
2189
|
+
for (const ref of Editor.rangeRefs(editor))
|
|
2190
|
+
RangeRef.transform(ref, splitOp);
|
|
2191
|
+
if (editor.selection) {
|
|
2192
|
+
const sel = {
|
|
2193
|
+
...editor.selection
|
|
2194
|
+
};
|
|
2195
|
+
for (const [point2, key] of Range.points(sel))
|
|
2196
|
+
sel[key] = Point.transform(point2, splitOp);
|
|
2197
|
+
editor.selection = sel;
|
|
2198
|
+
}
|
|
2199
|
+
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
2200
|
+
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
2201
|
+
const savedSelection = editor.selection;
|
|
2202
|
+
try {
|
|
2203
|
+
Editor.withoutNormalizing(editor, () => {
|
|
2204
|
+
if (Text$1.isText(node2, editor.schema)) {
|
|
2205
|
+
const afterText = node2.text.slice(position), newNode = {
|
|
2206
|
+
...properties,
|
|
2207
|
+
text: afterText
|
|
2208
|
+
};
|
|
2209
|
+
editor.apply({
|
|
2210
|
+
type: "remove_text",
|
|
2211
|
+
path: path2,
|
|
2212
|
+
offset: position,
|
|
2213
|
+
text: afterText
|
|
2214
|
+
}), editor.apply({
|
|
2215
|
+
type: "insert_node",
|
|
2216
|
+
path: Path.next(path2),
|
|
2217
|
+
node: newNode
|
|
2218
|
+
});
|
|
2219
|
+
} else if (Element$2.isElement(node2, editor.schema)) {
|
|
2220
|
+
const afterChildren = node2.children.slice(position), newNode = {
|
|
2221
|
+
...properties,
|
|
2222
|
+
children: afterChildren
|
|
2223
|
+
};
|
|
2224
|
+
for (let i = node2.children.length - 1; i >= position; i--)
|
|
2225
|
+
editor.apply({
|
|
2226
|
+
type: "remove_node",
|
|
2227
|
+
path: [...path2, i],
|
|
2228
|
+
node: node2.children[i]
|
|
2229
|
+
});
|
|
2230
|
+
editor.apply({
|
|
2231
|
+
type: "insert_node",
|
|
2232
|
+
path: Path.next(path2),
|
|
2233
|
+
node: newNode
|
|
2234
|
+
});
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2237
|
+
} finally {
|
|
2238
|
+
editor.selection = savedSelection;
|
|
2239
|
+
for (const ref of pathRefs)
|
|
2240
|
+
Editor.pathRefs(editor).add(ref);
|
|
2241
|
+
for (const ref of pointRefs)
|
|
2242
|
+
Editor.pointRefs(editor).add(ref);
|
|
2243
|
+
for (const ref of rangeRefs)
|
|
2244
|
+
Editor.rangeRefs(editor).add(ref);
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
const insertNodes = (editor, nodes2, options = {}) => {
|
|
2297
2248
|
Editor.withoutNormalizing(editor, () => {
|
|
2298
2249
|
const {
|
|
2299
2250
|
hanging = !1,
|
|
@@ -2330,12 +2281,43 @@ const previous = (editor, options = {}) => {
|
|
|
2330
2281
|
});
|
|
2331
2282
|
if (entry) {
|
|
2332
2283
|
const [, matchPath2] = entry, pathRef2 = Editor.pathRef(editor, matchPath2), isAtEnd = Editor.isEnd(editor, at, matchPath2);
|
|
2333
|
-
|
|
2334
|
-
at,
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2284
|
+
{
|
|
2285
|
+
const splitAt = at, beforeRef = Editor.pointRef(editor, splitAt, {
|
|
2286
|
+
affinity: "backward"
|
|
2287
|
+
});
|
|
2288
|
+
let afterRef;
|
|
2289
|
+
try {
|
|
2290
|
+
const [highest] = Editor.nodes(editor, {
|
|
2291
|
+
at: splitAt,
|
|
2292
|
+
match: match2,
|
|
2293
|
+
mode,
|
|
2294
|
+
voids
|
|
2295
|
+
});
|
|
2296
|
+
if (highest) {
|
|
2297
|
+
afterRef = Editor.pointRef(editor, splitAt);
|
|
2298
|
+
const depth = splitAt.path.length, [, highestPath] = highest, lowestPath = splitAt.path.slice(0, depth);
|
|
2299
|
+
let position = splitAt.offset;
|
|
2300
|
+
for (const [node22, nodePath] of Editor.levels(editor, {
|
|
2301
|
+
at: lowestPath,
|
|
2302
|
+
reverse: !0,
|
|
2303
|
+
voids
|
|
2304
|
+
})) {
|
|
2305
|
+
let split = !1;
|
|
2306
|
+
if (nodePath.length < highestPath.length || nodePath.length === 0)
|
|
2307
|
+
break;
|
|
2308
|
+
const point2 = beforeRef.current, isEndOfNode = Editor.isEnd(editor, point2, nodePath);
|
|
2309
|
+
if (!Editor.isEdge(editor, point2, nodePath)) {
|
|
2310
|
+
split = !0;
|
|
2311
|
+
const properties = Node$1.extractProps(node22, editor.schema);
|
|
2312
|
+
applySplitNode(editor, nodePath, position, properties);
|
|
2313
|
+
}
|
|
2314
|
+
position = nodePath[nodePath.length - 1] + (split || isEndOfNode ? 1 : 0);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
} finally {
|
|
2318
|
+
beforeRef.unref(), afterRef?.unref();
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2339
2321
|
const path2 = pathRef2.unref();
|
|
2340
2322
|
at = isAtEnd ? Path.next(path2) : path2;
|
|
2341
2323
|
} else
|
|
@@ -2383,126 +2365,6 @@ const previous = (editor, options = {}) => {
|
|
|
2383
2365
|
}
|
|
2384
2366
|
}
|
|
2385
2367
|
});
|
|
2386
|
-
}, hasSingleChildNest = (editor, node2) => {
|
|
2387
|
-
if (Element$2.isElement(node2, editor.schema)) {
|
|
2388
|
-
const element = node2;
|
|
2389
|
-
return element.children.length === 1 ? hasSingleChildNest(editor, element.children[0]) : !1;
|
|
2390
|
-
} else return !Editor.isEditor(node2);
|
|
2391
|
-
}, mergeNodes = (editor, options = {}) => {
|
|
2392
|
-
Editor.withoutNormalizing(editor, () => {
|
|
2393
|
-
let {
|
|
2394
|
-
match: match2,
|
|
2395
|
-
at = editor.selection
|
|
2396
|
-
} = options;
|
|
2397
|
-
const {
|
|
2398
|
-
hanging = !1,
|
|
2399
|
-
voids = !1,
|
|
2400
|
-
mode = "lowest"
|
|
2401
|
-
} = options;
|
|
2402
|
-
if (!at)
|
|
2403
|
-
return;
|
|
2404
|
-
if (match2 == null)
|
|
2405
|
-
if (Path.isPath(at)) {
|
|
2406
|
-
const [parent2] = Editor.parent(editor, at);
|
|
2407
|
-
match2 = (n2) => parent2.children.includes(n2);
|
|
2408
|
-
} else
|
|
2409
|
-
match2 = (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2);
|
|
2410
|
-
if (!hanging && Range.isRange(at) && (at = Editor.unhangRange(editor, at, {
|
|
2411
|
-
voids
|
|
2412
|
-
})), Range.isRange(at))
|
|
2413
|
-
if (Range.isCollapsed(at))
|
|
2414
|
-
at = at.anchor;
|
|
2415
|
-
else {
|
|
2416
|
-
const [, end2] = Range.edges(at), pointRef2 = Editor.pointRef(editor, end2);
|
|
2417
|
-
Transforms.delete(editor, {
|
|
2418
|
-
at
|
|
2419
|
-
}), at = pointRef2.unref(), options.at == null && Transforms.select(editor, at);
|
|
2420
|
-
}
|
|
2421
|
-
const [current] = Editor.nodes(editor, {
|
|
2422
|
-
at,
|
|
2423
|
-
match: match2,
|
|
2424
|
-
voids,
|
|
2425
|
-
mode
|
|
2426
|
-
}), prev = Editor.previous(editor, {
|
|
2427
|
-
at,
|
|
2428
|
-
match: match2,
|
|
2429
|
-
voids,
|
|
2430
|
-
mode
|
|
2431
|
-
});
|
|
2432
|
-
if (!current || !prev)
|
|
2433
|
-
return;
|
|
2434
|
-
const [node2, path2] = current, [prevNode, prevPath] = prev;
|
|
2435
|
-
if (path2.length === 0 || prevPath.length === 0)
|
|
2436
|
-
return;
|
|
2437
|
-
const newPath = Path.next(prevPath), commonPath = Path.common(path2, prevPath), isPreviousSibling = Path.isSibling(path2, prevPath), levels2 = Array.from(Editor.levels(editor, {
|
|
2438
|
-
at: path2
|
|
2439
|
-
}), ([n2]) => n2).slice(commonPath.length).slice(0, -1), emptyAncestor = Editor.above(editor, {
|
|
2440
|
-
at: path2,
|
|
2441
|
-
mode: "highest",
|
|
2442
|
-
match: (n2) => levels2.includes(n2) && hasSingleChildNest(editor, n2)
|
|
2443
|
-
}), emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
|
|
2444
|
-
let properties, position;
|
|
2445
|
-
if (Text$1.isText(node2, editor.schema) && Text$1.isText(prevNode, editor.schema)) {
|
|
2446
|
-
const {
|
|
2447
|
-
text: _text,
|
|
2448
|
-
...rest
|
|
2449
|
-
} = node2;
|
|
2450
|
-
position = prevNode.text.length, properties = rest;
|
|
2451
|
-
} else if (Element$2.isElement(node2, editor.schema) && Element$2.isElement(prevNode, editor.schema)) {
|
|
2452
|
-
const {
|
|
2453
|
-
children: _children,
|
|
2454
|
-
...rest
|
|
2455
|
-
} = node2;
|
|
2456
|
-
position = prevNode.children.length, properties = rest;
|
|
2457
|
-
} else
|
|
2458
|
-
throw new Error(`Cannot merge the node at path [${path2}] with the previous sibling because it is not the same kind: ${Scrubber.stringify(node2)} ${Scrubber.stringify(prevNode)}`);
|
|
2459
|
-
isPreviousSibling || Transforms.moveNodes(editor, {
|
|
2460
|
-
at: path2,
|
|
2461
|
-
to: newPath,
|
|
2462
|
-
voids
|
|
2463
|
-
}), emptyRef && Transforms.removeNodes(editor, {
|
|
2464
|
-
at: emptyRef.current,
|
|
2465
|
-
voids
|
|
2466
|
-
}), Editor.shouldMergeNodesRemovePrevNode(editor, prev, current) ? Transforms.removeNodes(editor, {
|
|
2467
|
-
at: prevPath,
|
|
2468
|
-
voids
|
|
2469
|
-
}) : editor.apply({
|
|
2470
|
-
type: "merge_node",
|
|
2471
|
-
path: newPath,
|
|
2472
|
-
position,
|
|
2473
|
-
properties
|
|
2474
|
-
}), emptyRef && emptyRef.unref();
|
|
2475
|
-
});
|
|
2476
|
-
}, moveNodes = (editor, options) => {
|
|
2477
|
-
Editor.withoutNormalizing(editor, () => {
|
|
2478
|
-
const {
|
|
2479
|
-
to,
|
|
2480
|
-
at = editor.selection,
|
|
2481
|
-
mode = "lowest",
|
|
2482
|
-
voids = !1
|
|
2483
|
-
} = options;
|
|
2484
|
-
let {
|
|
2485
|
-
match: match2
|
|
2486
|
-
} = options;
|
|
2487
|
-
if (!at)
|
|
2488
|
-
return;
|
|
2489
|
-
match2 == null && (match2 = Path.isPath(at) ? matchPath(editor, at) : (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2));
|
|
2490
|
-
const toRef = Editor.pathRef(editor, to), targets = Editor.nodes(editor, {
|
|
2491
|
-
at,
|
|
2492
|
-
match: match2,
|
|
2493
|
-
mode,
|
|
2494
|
-
voids
|
|
2495
|
-
}), pathRefs = Array.from(targets, ([, p]) => Editor.pathRef(editor, p));
|
|
2496
|
-
for (const pathRef2 of pathRefs) {
|
|
2497
|
-
const path2 = pathRef2.unref(), newPath = toRef.current;
|
|
2498
|
-
path2.length !== 0 && editor.apply({
|
|
2499
|
-
type: "move_node",
|
|
2500
|
-
path: path2,
|
|
2501
|
-
newPath
|
|
2502
|
-
}), toRef.current && Path.isSibling(newPath, path2) && Path.isAfter(newPath, path2) && (toRef.current = Path.next(toRef.current));
|
|
2503
|
-
}
|
|
2504
|
-
toRef.unref();
|
|
2505
|
-
});
|
|
2506
2368
|
}, removeNodes = (editor, options = {}) => {
|
|
2507
2369
|
Editor.withoutNormalizing(editor, () => {
|
|
2508
2370
|
const {
|
|
@@ -2528,104 +2390,13 @@ const previous = (editor, options = {}) => {
|
|
|
2528
2390
|
for (const pathRef2 of pathRefs) {
|
|
2529
2391
|
const path2 = pathRef2.unref();
|
|
2530
2392
|
if (path2) {
|
|
2531
|
-
const [node2] = Editor.node(editor, path2);
|
|
2532
|
-
editor.apply({
|
|
2533
|
-
type: "remove_node",
|
|
2534
|
-
path: path2,
|
|
2535
|
-
node: node2
|
|
2536
|
-
});
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
});
|
|
2540
|
-
}, deleteRange = (editor, range2) => {
|
|
2541
|
-
if (Range.isCollapsed(range2))
|
|
2542
|
-
return range2.anchor;
|
|
2543
|
-
{
|
|
2544
|
-
const [, end2] = Range.edges(range2), pointRef2 = Editor.pointRef(editor, end2);
|
|
2545
|
-
return Transforms.delete(editor, {
|
|
2546
|
-
at: range2
|
|
2547
|
-
}), pointRef2.unref();
|
|
2548
|
-
}
|
|
2549
|
-
}, splitNodes = (editor, options = {}) => {
|
|
2550
|
-
Editor.withoutNormalizing(editor, () => {
|
|
2551
|
-
const {
|
|
2552
|
-
mode = "lowest",
|
|
2553
|
-
voids = !1
|
|
2554
|
-
} = options;
|
|
2555
|
-
let {
|
|
2556
|
-
match: match2,
|
|
2557
|
-
at = editor.selection,
|
|
2558
|
-
height = 0,
|
|
2559
|
-
always = !1
|
|
2560
|
-
} = options;
|
|
2561
|
-
if (match2 == null && (match2 = (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2)), Range.isRange(at) && (at = deleteRange(editor, at)), Path.isPath(at)) {
|
|
2562
|
-
const path2 = at, point2 = Editor.point(editor, path2), [parent2] = Editor.parent(editor, path2);
|
|
2563
|
-
match2 = (n2) => n2 === parent2, height = point2.path.length - path2.length + 1, at = point2, always = !0;
|
|
2564
|
-
}
|
|
2565
|
-
if (!at)
|
|
2566
|
-
return;
|
|
2567
|
-
const beforeRef = Editor.pointRef(editor, at, {
|
|
2568
|
-
affinity: "backward"
|
|
2569
|
-
});
|
|
2570
|
-
let afterRef;
|
|
2571
|
-
try {
|
|
2572
|
-
const [highest] = Editor.nodes(editor, {
|
|
2573
|
-
at,
|
|
2574
|
-
match: match2,
|
|
2575
|
-
mode,
|
|
2576
|
-
voids
|
|
2577
|
-
});
|
|
2578
|
-
if (!highest)
|
|
2579
|
-
return;
|
|
2580
|
-
const voidMatch = Editor.void(editor, {
|
|
2581
|
-
at,
|
|
2582
|
-
mode: "highest"
|
|
2583
|
-
}), nudge = 0;
|
|
2584
|
-
if (!voids && voidMatch) {
|
|
2585
|
-
const [voidNode, voidPath] = voidMatch;
|
|
2586
|
-
if (Element$2.isElement(voidNode, editor.schema) && editor.isInline(voidNode)) {
|
|
2587
|
-
let after2 = Editor.after(editor, voidPath);
|
|
2588
|
-
if (!after2) {
|
|
2589
|
-
const text = editor.createSpan(), afterPath = Path.next(voidPath);
|
|
2590
|
-
Transforms.insertNodes(editor, text, {
|
|
2591
|
-
at: afterPath,
|
|
2592
|
-
voids
|
|
2593
|
-
}), after2 = Editor.point(editor, afterPath);
|
|
2594
|
-
}
|
|
2595
|
-
at = after2, always = !0;
|
|
2596
|
-
}
|
|
2597
|
-
height = at.path.length - voidPath.length + 1, always = !0;
|
|
2598
|
-
}
|
|
2599
|
-
afterRef = Editor.pointRef(editor, at);
|
|
2600
|
-
const depth = at.path.length - height, [, highestPath] = highest, lowestPath = at.path.slice(0, depth);
|
|
2601
|
-
let position = height === 0 ? at.offset : at.path[depth] + nudge;
|
|
2602
|
-
for (const [node2, path2] of Editor.levels(editor, {
|
|
2603
|
-
at: lowestPath,
|
|
2604
|
-
reverse: !0,
|
|
2605
|
-
voids
|
|
2606
|
-
})) {
|
|
2607
|
-
let split = !1;
|
|
2608
|
-
if (path2.length < highestPath.length || path2.length === 0)
|
|
2609
|
-
break;
|
|
2610
|
-
const point2 = beforeRef.current, isEnd2 = Editor.isEnd(editor, point2, path2);
|
|
2611
|
-
if (always || !beforeRef || !Editor.isEdge(editor, point2, path2)) {
|
|
2612
|
-
split = !0;
|
|
2613
|
-
const properties = Node$1.extractProps(node2, editor.schema);
|
|
2614
|
-
editor.apply({
|
|
2615
|
-
type: "split_node",
|
|
2616
|
-
path: path2,
|
|
2617
|
-
position,
|
|
2618
|
-
properties
|
|
2619
|
-
});
|
|
2620
|
-
}
|
|
2621
|
-
position = path2[path2.length - 1] + (split || isEnd2 ? 1 : 0);
|
|
2622
|
-
}
|
|
2623
|
-
if (options.at == null) {
|
|
2624
|
-
const point2 = afterRef.current || Editor.end(editor, []);
|
|
2625
|
-
Transforms.select(editor, point2);
|
|
2393
|
+
const [node2] = Editor.node(editor, path2);
|
|
2394
|
+
editor.apply({
|
|
2395
|
+
type: "remove_node",
|
|
2396
|
+
path: path2,
|
|
2397
|
+
node: node2
|
|
2398
|
+
});
|
|
2626
2399
|
}
|
|
2627
|
-
} finally {
|
|
2628
|
-
beforeRef.unref(), afterRef?.unref();
|
|
2629
2400
|
}
|
|
2630
2401
|
});
|
|
2631
2402
|
}, collapse = (editor, options = {}) => {
|
|
@@ -2714,7 +2485,68 @@ const previous = (editor, options = {}) => {
|
|
|
2714
2485
|
newProperties: newProps
|
|
2715
2486
|
});
|
|
2716
2487
|
}
|
|
2717
|
-
}
|
|
2488
|
+
};
|
|
2489
|
+
function applyMoveNode(editor, path2, newPath) {
|
|
2490
|
+
if (Path.equals(path2, newPath))
|
|
2491
|
+
return;
|
|
2492
|
+
if (Path.isAncestor(path2, newPath))
|
|
2493
|
+
throw new Error(`Cannot move a path [${path2}] to new path [${newPath}] because the destination is inside itself.`);
|
|
2494
|
+
const node2 = Node$1.get(editor, path2, editor.schema), moveOp = {
|
|
2495
|
+
type: "move_node",
|
|
2496
|
+
path: path2,
|
|
2497
|
+
newPath
|
|
2498
|
+
};
|
|
2499
|
+
for (const ref of Editor.pathRefs(editor))
|
|
2500
|
+
PathRef.transform(ref, moveOp);
|
|
2501
|
+
for (const ref of Editor.pointRefs(editor))
|
|
2502
|
+
PointRef.transform(ref, moveOp);
|
|
2503
|
+
for (const ref of Editor.rangeRefs(editor))
|
|
2504
|
+
RangeRef.transform(ref, moveOp);
|
|
2505
|
+
if (editor.selection) {
|
|
2506
|
+
const sel = {
|
|
2507
|
+
...editor.selection
|
|
2508
|
+
};
|
|
2509
|
+
for (const [point2, key] of Range.points(sel))
|
|
2510
|
+
sel[key] = Point.transform(point2, moveOp);
|
|
2511
|
+
editor.selection = sel;
|
|
2512
|
+
}
|
|
2513
|
+
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
2514
|
+
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
2515
|
+
const savedSelection = editor.selection;
|
|
2516
|
+
try {
|
|
2517
|
+
Editor.withoutNormalizing(editor, () => {
|
|
2518
|
+
editor.apply({
|
|
2519
|
+
type: "remove_node",
|
|
2520
|
+
path: path2,
|
|
2521
|
+
node: node2
|
|
2522
|
+
}), editor.apply({
|
|
2523
|
+
type: "insert_node",
|
|
2524
|
+
path: newPath,
|
|
2525
|
+
node: node2
|
|
2526
|
+
});
|
|
2527
|
+
});
|
|
2528
|
+
} finally {
|
|
2529
|
+
editor.selection = savedSelection;
|
|
2530
|
+
for (const ref of pathRefs)
|
|
2531
|
+
Editor.pathRefs(editor).add(ref);
|
|
2532
|
+
for (const ref of pointRefs)
|
|
2533
|
+
Editor.pointRefs(editor).add(ref);
|
|
2534
|
+
for (const ref of rangeRefs)
|
|
2535
|
+
Editor.rangeRefs(editor).add(ref);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
function applySetNode(editor, props, path2) {
|
|
2539
|
+
const node2 = Node$1.get(editor, path2, editor.schema), propsRecord = props, properties = {}, newProperties = {};
|
|
2540
|
+
for (const key of Object.keys(propsRecord))
|
|
2541
|
+
key !== "children" && (key === "text" && !Element$2.isElement(node2, editor.schema) && !editor.isObjectNode(node2) || propsRecord[key] !== node2[key] && (node2.hasOwnProperty(key) && (properties[key] = node2[key]), propsRecord[key] != null && (newProperties[key] = propsRecord[key])));
|
|
2542
|
+
(Object.keys(newProperties).length > 0 || Object.keys(properties).length > 0) && editor.apply({
|
|
2543
|
+
type: "set_node",
|
|
2544
|
+
path: path2,
|
|
2545
|
+
properties,
|
|
2546
|
+
newProperties
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
const deleteText = (editor, options = {}) => {
|
|
2718
2550
|
Editor.withoutNormalizing(editor, () => {
|
|
2719
2551
|
const {
|
|
2720
2552
|
reverse = !1,
|
|
@@ -2839,11 +2671,71 @@ const previous = (editor, options = {}) => {
|
|
|
2839
2671
|
}), removedText = text);
|
|
2840
2672
|
}
|
|
2841
2673
|
}
|
|
2842
|
-
!isSingleText && isAcrossBlocks && endRef.current && startRef.current
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2674
|
+
if (!isSingleText && isAcrossBlocks && endRef.current && startRef.current) {
|
|
2675
|
+
const mergeAt = endRef.current, mergeMatch = (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2), [current] = Editor.nodes(editor, {
|
|
2676
|
+
at: mergeAt,
|
|
2677
|
+
match: mergeMatch,
|
|
2678
|
+
voids,
|
|
2679
|
+
mode: "lowest"
|
|
2680
|
+
}), prev = Editor.previous(editor, {
|
|
2681
|
+
at: mergeAt,
|
|
2682
|
+
match: mergeMatch,
|
|
2683
|
+
voids,
|
|
2684
|
+
mode: "lowest"
|
|
2685
|
+
});
|
|
2686
|
+
if (current && prev) {
|
|
2687
|
+
const [mergeNode, mergePath] = current, [prevNode, prevPath] = prev;
|
|
2688
|
+
if (mergePath.length !== 0 && prevPath.length !== 0) {
|
|
2689
|
+
const newPath = Path.next(prevPath), commonPath = Path.common(mergePath, prevPath), isPreviousSibling = Path.isSibling(mergePath, prevPath), levels2 = Array.from(Editor.levels(editor, {
|
|
2690
|
+
at: mergePath
|
|
2691
|
+
}), ([n2]) => n2).slice(commonPath.length).slice(0, -1), hasSingleChildNest = (node2) => {
|
|
2692
|
+
if (Element$2.isElement(node2, editor.schema)) {
|
|
2693
|
+
const element = node2;
|
|
2694
|
+
return element.children.length === 1 ? hasSingleChildNest(element.children[0]) : !1;
|
|
2695
|
+
} else return !Editor.isEditor(node2);
|
|
2696
|
+
}, emptyAncestor = Editor.above(editor, {
|
|
2697
|
+
at: mergePath,
|
|
2698
|
+
mode: "highest",
|
|
2699
|
+
match: (n2) => levels2.includes(n2) && hasSingleChildNest(n2)
|
|
2700
|
+
}), emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
|
|
2701
|
+
let properties, position;
|
|
2702
|
+
if (Text$1.isText(mergeNode, editor.schema) && Text$1.isText(prevNode, editor.schema)) {
|
|
2703
|
+
const {
|
|
2704
|
+
text: _text,
|
|
2705
|
+
...rest
|
|
2706
|
+
} = mergeNode;
|
|
2707
|
+
position = prevNode.text.length, properties = rest;
|
|
2708
|
+
} else if (Element$2.isElement(mergeNode, editor.schema) && Element$2.isElement(prevNode, editor.schema)) {
|
|
2709
|
+
const {
|
|
2710
|
+
children: _children,
|
|
2711
|
+
...rest
|
|
2712
|
+
} = mergeNode;
|
|
2713
|
+
position = prevNode.children.length, properties = rest;
|
|
2714
|
+
} else
|
|
2715
|
+
throw new Error(`Cannot merge the node at path [${mergePath}] with the previous sibling because it is not the same kind: ${Scrubber.stringify(mergeNode)} ${Scrubber.stringify(prevNode)}`);
|
|
2716
|
+
if (isPreviousSibling || applyMoveNode(editor, mergePath, newPath), emptyRef && Transforms.removeNodes(editor, {
|
|
2717
|
+
at: emptyRef.current,
|
|
2718
|
+
voids
|
|
2719
|
+
}), Editor.shouldMergeNodesRemovePrevNode(editor, prev, current))
|
|
2720
|
+
Transforms.removeNodes(editor, {
|
|
2721
|
+
at: prevPath,
|
|
2722
|
+
voids
|
|
2723
|
+
});
|
|
2724
|
+
else {
|
|
2725
|
+
const pteEditor = editor;
|
|
2726
|
+
if (pteEditor.isTextBlock(mergeNode) && pteEditor.isTextBlock(prevNode) && Array.isArray(mergeNode.markDefs) && mergeNode.markDefs.length > 0) {
|
|
2727
|
+
const targetPath = isPreviousSibling ? prevPath : Path.previous(newPath), oldDefs = Array.isArray(prevNode.markDefs) && prevNode.markDefs || [], newMarkDefs = [...new Map([...oldDefs, ...mergeNode.markDefs].map((def) => [def._key, def])).values()];
|
|
2728
|
+
applySetNode(pteEditor, {
|
|
2729
|
+
markDefs: newMarkDefs
|
|
2730
|
+
}, targetPath);
|
|
2731
|
+
}
|
|
2732
|
+
applyMergeNode(pteEditor, newPath, position, properties);
|
|
2733
|
+
}
|
|
2734
|
+
emptyRef && emptyRef.unref();
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
isCollapsed && reverse && unit === "character" && removedText.length > 1 && removedText.match(/[\u0980-\u09FF\u0E00-\u0E7F\u1000-\u109F\u0900-\u097F\u1780-\u17FF\u0D00-\u0D7F\u0B00-\u0B7F\u0A00-\u0A7F\u0B80-\u0BFF\u0C00-\u0C7F]+/) && Transforms.insertText(editor, removedText.slice(0, removedText.length - distance));
|
|
2847
2739
|
const startUnref = startRef.unref(), endUnref = endRef.unref(), point2 = reverse ? startUnref || endUnref : endUnref || startUnref;
|
|
2848
2740
|
options.at == null && point2 && Transforms.select(editor, point2);
|
|
2849
2741
|
});
|
|
@@ -2889,7 +2781,6 @@ const previous = (editor, options = {}) => {
|
|
|
2889
2781
|
deselect: (...args) => deselect(e, ...args),
|
|
2890
2782
|
elementReadOnly: (...args) => elementReadOnly(e, ...args),
|
|
2891
2783
|
end: (...args) => end(e, ...args),
|
|
2892
|
-
getMarks: (...args) => marks(e, ...args),
|
|
2893
2784
|
hasInlines: (...args) => hasInlines(e, ...args),
|
|
2894
2785
|
hasPath: (...args) => hasPath(e, ...args),
|
|
2895
2786
|
insertNodes: (...args) => insertNodes(e, ...args),
|
|
@@ -2900,9 +2791,7 @@ const previous = (editor, options = {}) => {
|
|
|
2900
2791
|
isStart: (...args) => isStart(e, ...args),
|
|
2901
2792
|
leaf: (...args) => leaf(e, ...args),
|
|
2902
2793
|
levels: (...args) => levels(e, ...args),
|
|
2903
|
-
mergeNodes: (...args) => mergeNodes(e, ...args),
|
|
2904
2794
|
move: (...args) => move(e, ...args),
|
|
2905
|
-
moveNodes: (...args) => moveNodes(e, ...args),
|
|
2906
2795
|
next: (...args) => next(e, ...args),
|
|
2907
2796
|
node: (...args) => node(e, ...args),
|
|
2908
2797
|
nodes: (...args) => nodes(e, ...args),
|
|
@@ -2920,7 +2809,6 @@ const previous = (editor, options = {}) => {
|
|
|
2920
2809
|
select: (...args) => select(e, ...args),
|
|
2921
2810
|
setNormalizing: (...args) => setNormalizing(e, ...args),
|
|
2922
2811
|
setSelection: (...args) => setSelection$1(e, ...args),
|
|
2923
|
-
splitNodes: (...args) => splitNodes(e, ...args),
|
|
2924
2812
|
start: (...args) => start(e, ...args),
|
|
2925
2813
|
string: (...args) => string(e, ...args),
|
|
2926
2814
|
unhangRange: (...args) => unhangRange(e, ...args),
|
|
@@ -3048,10 +2936,7 @@ const previous = (editor, options = {}) => {
|
|
|
3048
2936
|
}
|
|
3049
2937
|
return !1;
|
|
3050
2938
|
}, IS_IOS = typeof navigator < "u" && typeof window < "u" && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream, IS_ANDROID = typeof navigator < "u" && /Android/.test(navigator.userAgent), IS_FIREFOX = typeof navigator < "u" && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent), IS_WEBKIT = typeof navigator < "u" && /AppleWebKit(?!.*Chrome)/i.test(navigator.userAgent), IS_EDGE_LEGACY = typeof navigator < "u" && /Edge?\/(?:[0-6][0-9]|[0-7][0-8])(?:\.)/i.test(navigator.userAgent), IS_CHROME = typeof navigator < "u" && /Chrome/i.test(navigator.userAgent), IS_CHROME_LEGACY = typeof navigator < "u" && /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])(?:\.)/i.test(navigator.userAgent), IS_ANDROID_CHROME_LEGACY = IS_ANDROID && typeof navigator < "u" && /Chrome?\/(?:[0-5]?\d)(?:\.)/i.test(navigator.userAgent), IS_FIREFOX_LEGACY = typeof navigator < "u" && /^(?!.*Seamonkey)(?=.*Firefox\/(?:[0-7][0-9]|[0-8][0-6])(?:\.)).*/i.test(navigator.userAgent), IS_UC_MOBILE = typeof navigator < "u" && /.*UCBrowser/.test(navigator.userAgent), IS_WECHATBROWSER = typeof navigator < "u" && /.*Wechat/.test(navigator.userAgent) && !/.*MacWechat/.test(navigator.userAgent) && // avoid lookbehind (buggy in safari < 16.4)
|
|
3051
|
-
(!IS_CHROME || IS_CHROME_LEGACY), CAN_USE_DOM = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u"
|
|
3052
|
-
typeof navigator < "u" && /Safari/.test(navigator.userAgent) && /Version\/(\\d+)/.test(navigator.userAgent) && (navigator.userAgent.match(/Version\/(\\d+)/)?.[1] && // biome-ignore lint/suspicious/noNonNullAssertedOptionalChain: Slate upstream — regex match guaranteed by outer test
|
|
3053
|
-
parseInt(navigator.userAgent.match(/Version\/(\\d+)/)?.[1], 10) < 17);
|
|
3054
|
-
const HAS_BEFORE_INPUT_SUPPORT = (!IS_CHROME_LEGACY || !IS_ANDROID_CHROME_LEGACY) && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
|
|
2939
|
+
(!IS_CHROME || IS_CHROME_LEGACY), CAN_USE_DOM = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", HAS_BEFORE_INPUT_SUPPORT = (!IS_CHROME_LEGACY || !IS_ANDROID_CHROME_LEGACY) && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
|
|
3055
2940
|
typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent.prototype.getTargetRanges == "function";
|
|
3056
2941
|
let n = 0;
|
|
3057
2942
|
class Key {
|
|
@@ -3060,20 +2945,10 @@ class Key {
|
|
|
3060
2945
|
}
|
|
3061
2946
|
}
|
|
3062
2947
|
const DOMEditor = {
|
|
3063
|
-
androidPendingDiffs: (editor) => editor.pendingDiffs,
|
|
3064
|
-
androidScheduleFlush: (editor) => {
|
|
3065
|
-
editor.scheduleFlush?.();
|
|
3066
|
-
},
|
|
3067
2948
|
blur: (editor) => {
|
|
3068
2949
|
const el = DOMEditor.toDOMNode(editor, editor), root = DOMEditor.findDocumentOrShadowRoot(editor);
|
|
3069
2950
|
editor.focused = !1, root.activeElement === el && el.blur();
|
|
3070
2951
|
},
|
|
3071
|
-
deselect: (editor) => {
|
|
3072
|
-
const {
|
|
3073
|
-
selection
|
|
3074
|
-
} = editor, root = DOMEditor.findDocumentOrShadowRoot(editor), domSelection = getSelection(root);
|
|
3075
|
-
domSelection && domSelection.rangeCount > 0 && domSelection.removeAllRanges(), selection && Transforms.deselect(editor);
|
|
3076
|
-
},
|
|
3077
2952
|
findDocumentOrShadowRoot: (editor) => {
|
|
3078
2953
|
const el = DOMEditor.toDOMNode(editor, editor), root = el.getRootNode();
|
|
3079
2954
|
return root instanceof Document || root instanceof ShadowRoot ? root : el.ownerDocument;
|
|
@@ -3194,7 +3069,6 @@ const DOMEditor = {
|
|
|
3194
3069
|
hasTarget: (editor, target) => isDOMNode(target) && DOMEditor.hasDOMNode(editor, target),
|
|
3195
3070
|
isComposing: (editor) => !!editor.composing,
|
|
3196
3071
|
isFocused: (editor) => !!editor.focused,
|
|
3197
|
-
isReadOnly: (editor) => !!editor.readOnly,
|
|
3198
3072
|
isTargetInsideNonReadonlyVoid: (editor, target) => {
|
|
3199
3073
|
if (editor.readOnly)
|
|
3200
3074
|
return !1;
|
|
@@ -3686,46 +3560,6 @@ function transformTextDiff(textDiff, op) {
|
|
|
3686
3560
|
id,
|
|
3687
3561
|
path: path2
|
|
3688
3562
|
};
|
|
3689
|
-
case "split_node":
|
|
3690
|
-
return !Path.equals(op.path, path2) || op.position >= diff2.end ? {
|
|
3691
|
-
diff: diff2,
|
|
3692
|
-
id,
|
|
3693
|
-
path: Path.transform(path2, op, {
|
|
3694
|
-
affinity: "backward"
|
|
3695
|
-
})
|
|
3696
|
-
} : op.position > diff2.start ? {
|
|
3697
|
-
diff: {
|
|
3698
|
-
start: diff2.start,
|
|
3699
|
-
end: Math.min(op.position, diff2.end),
|
|
3700
|
-
text: diff2.text
|
|
3701
|
-
},
|
|
3702
|
-
id,
|
|
3703
|
-
path: path2
|
|
3704
|
-
} : {
|
|
3705
|
-
diff: {
|
|
3706
|
-
start: diff2.start - op.position,
|
|
3707
|
-
end: diff2.end - op.position,
|
|
3708
|
-
text: diff2.text
|
|
3709
|
-
},
|
|
3710
|
-
id,
|
|
3711
|
-
path: Path.transform(path2, op, {
|
|
3712
|
-
affinity: "forward"
|
|
3713
|
-
})
|
|
3714
|
-
};
|
|
3715
|
-
case "merge_node":
|
|
3716
|
-
return Path.equals(op.path, path2) ? {
|
|
3717
|
-
diff: {
|
|
3718
|
-
start: diff2.start + op.position,
|
|
3719
|
-
end: diff2.end + op.position,
|
|
3720
|
-
text: diff2.text
|
|
3721
|
-
},
|
|
3722
|
-
id,
|
|
3723
|
-
path: Path.transform(path2, op)
|
|
3724
|
-
} : {
|
|
3725
|
-
diff: diff2,
|
|
3726
|
-
id,
|
|
3727
|
-
path: Path.transform(path2, op)
|
|
3728
|
-
};
|
|
3729
3563
|
}
|
|
3730
3564
|
const newPath = Path.transform(path2, op);
|
|
3731
3565
|
return newPath ? {
|
|
@@ -3734,15 +3568,13 @@ function transformTextDiff(textDiff, op) {
|
|
|
3734
3568
|
id
|
|
3735
3569
|
} : null;
|
|
3736
3570
|
}
|
|
3737
|
-
const withDOM = (editor
|
|
3571
|
+
const withDOM = (editor) => {
|
|
3738
3572
|
const e = editor, {
|
|
3739
3573
|
apply: apply2,
|
|
3740
3574
|
onChange
|
|
3741
3575
|
} = e;
|
|
3742
|
-
return e.isNodeMapDirty = !1, e.domWindow = null, e.domElement = null, e.domPlaceholder = "", e.domPlaceholderElement = null, e.keyToElement = /* @__PURE__ */ new WeakMap(), e.nodeToIndex = /* @__PURE__ */ new WeakMap(), e.nodeToParent = /* @__PURE__ */ new WeakMap(), e.elementToNode = /* @__PURE__ */ new WeakMap(), e.nodeToElement = /* @__PURE__ */ new WeakMap(), e.nodeToKey = /* @__PURE__ */ new WeakMap(), e.
|
|
3743
|
-
|
|
3744
|
-
}, e.readOnly = !1, e.focused = !1, e.composing = !1, e.userSelection = null, e.onContextChange = null, e.scheduleFlush = null, e.pendingInsertionMarks = null, e.userMarks = null, e.pendingDiffs = [], e.pendingAction = null, e.pendingSelection = null, e.forceRender = null, e.apply = (op) => {
|
|
3745
|
-
const matches = [], pathRefMatches = [], pendingDiffs = e.pendingDiffs;
|
|
3576
|
+
return e.isNodeMapDirty = !1, e.domWindow = null, e.domElement = null, e.domPlaceholder = "", e.domPlaceholderElement = null, e.keyToElement = /* @__PURE__ */ new WeakMap(), e.nodeToIndex = /* @__PURE__ */ new WeakMap(), e.nodeToParent = /* @__PURE__ */ new WeakMap(), e.elementToNode = /* @__PURE__ */ new WeakMap(), e.nodeToElement = /* @__PURE__ */ new WeakMap(), e.nodeToKey = /* @__PURE__ */ new WeakMap(), e.readOnly = !1, e.focused = !1, e.composing = !1, e.userSelection = null, e.onContextChange = null, e.scheduleFlush = null, e.pendingInsertionMarks = null, e.userMarks = null, e.pendingDiffs = [], e.pendingAction = null, e.pendingSelection = null, e.forceRender = null, e.apply = (op) => {
|
|
3577
|
+
const matches = [], pendingDiffs = e.pendingDiffs;
|
|
3746
3578
|
if (pendingDiffs?.length) {
|
|
3747
3579
|
const transformed = pendingDiffs.map((textDiff) => transformTextDiff(textDiff, op)).filter(Boolean);
|
|
3748
3580
|
e.pendingDiffs = transformed;
|
|
@@ -3760,8 +3592,7 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
3760
3592
|
switch (op.type) {
|
|
3761
3593
|
case "insert_text":
|
|
3762
3594
|
case "remove_text":
|
|
3763
|
-
case "set_node":
|
|
3764
|
-
case "split_node": {
|
|
3595
|
+
case "set_node": {
|
|
3765
3596
|
matches.push(...getMatches(e, op.path));
|
|
3766
3597
|
break;
|
|
3767
3598
|
}
|
|
@@ -3774,27 +3605,10 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
3774
3605
|
matches.push(...getMatches(e, Path.parent(op.path)));
|
|
3775
3606
|
break;
|
|
3776
3607
|
}
|
|
3777
|
-
case "merge_node": {
|
|
3778
|
-
const prevPath = Path.previous(op.path);
|
|
3779
|
-
matches.push(...getMatches(e, prevPath));
|
|
3780
|
-
break;
|
|
3781
|
-
}
|
|
3782
|
-
case "move_node": {
|
|
3783
|
-
const commonPath = Path.common(Path.parent(op.path), Path.parent(op.newPath));
|
|
3784
|
-
matches.push(...getMatches(e, commonPath));
|
|
3785
|
-
let changedPath;
|
|
3786
|
-
Path.isBefore(op.path, op.newPath) ? (matches.push(...getMatches(e, Path.parent(op.path))), changedPath = op.newPath) : (matches.push(...getMatches(e, Path.parent(op.newPath))), changedPath = op.path);
|
|
3787
|
-
const changedNode = Node$1.get(editor, Path.parent(changedPath), editor.schema), changedNodeKey = DOMEditor.findKey(e, changedNode), changedPathRef = Editor.pathRef(e, Path.parent(changedPath));
|
|
3788
|
-
pathRefMatches.push([changedPathRef, changedNodeKey]);
|
|
3789
|
-
break;
|
|
3790
|
-
}
|
|
3791
3608
|
}
|
|
3792
3609
|
switch (apply2(op), op.type) {
|
|
3793
3610
|
case "insert_node":
|
|
3794
3611
|
case "remove_node":
|
|
3795
|
-
case "merge_node":
|
|
3796
|
-
case "move_node":
|
|
3797
|
-
case "split_node":
|
|
3798
3612
|
case "insert_text":
|
|
3799
3613
|
case "remove_text":
|
|
3800
3614
|
case "set_selection":
|
|
@@ -3804,13 +3618,6 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
3804
3618
|
const [node2] = Editor.node(e, path2);
|
|
3805
3619
|
e.nodeToKey.set(node2, key);
|
|
3806
3620
|
}
|
|
3807
|
-
for (const [pathRef2, key] of pathRefMatches) {
|
|
3808
|
-
if (pathRef2.current) {
|
|
3809
|
-
const [node2] = Editor.node(e, pathRef2.current);
|
|
3810
|
-
e.nodeToKey.set(node2, key);
|
|
3811
|
-
}
|
|
3812
|
-
pathRef2.unref();
|
|
3813
|
-
}
|
|
3814
3621
|
}, e.setFragmentData = (data) => {
|
|
3815
3622
|
const {
|
|
3816
3623
|
selection
|
|
@@ -3841,7 +3648,7 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
3841
3648
|
span.style.whiteSpace = "pre", span.appendChild(attach), contents.appendChild(span), attach = span;
|
|
3842
3649
|
}
|
|
3843
3650
|
const fragment = e.getFragment(), string2 = JSON.stringify(fragment), encoded = window.btoa(encodeURIComponent(string2));
|
|
3844
|
-
attach.setAttribute("data-slate-fragment", encoded), data.setData(
|
|
3651
|
+
attach.setAttribute("data-slate-fragment", encoded), data.setData("application/x-slate-fragment", encoded);
|
|
3845
3652
|
const div = contents.ownerDocument.createElement("div");
|
|
3846
3653
|
return div.appendChild(contents), div.setAttribute("hidden", "true"), contents.ownerDocument.body.appendChild(div), data.setData("text/html", div.innerHTML), data.setData("text/plain", getPlainText(div)), contents.ownerDocument.body.removeChild(div), data;
|
|
3847
3654
|
}, e.insertData = (data) => {
|
|
@@ -3852,8 +3659,53 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
3852
3659
|
const lines = text.split(/\r\n|\r|\n/);
|
|
3853
3660
|
let split = !1;
|
|
3854
3661
|
for (const line of lines)
|
|
3855
|
-
split &&
|
|
3856
|
-
|
|
3662
|
+
split && Editor.withoutNormalizing(e, () => {
|
|
3663
|
+
let splitAt = null;
|
|
3664
|
+
if (e.selection)
|
|
3665
|
+
if (Range.isCollapsed(e.selection))
|
|
3666
|
+
splitAt = e.selection.anchor;
|
|
3667
|
+
else {
|
|
3668
|
+
const [, end2] = Range.edges(e.selection), pointRef2 = Editor.pointRef(e, end2);
|
|
3669
|
+
Transforms.delete(e, {
|
|
3670
|
+
at: e.selection
|
|
3671
|
+
}), splitAt = pointRef2.unref();
|
|
3672
|
+
}
|
|
3673
|
+
if (!splitAt)
|
|
3674
|
+
return;
|
|
3675
|
+
const splitMatch = (n2) => Element$2.isElement(n2, e.schema) && Editor.isBlock(e, n2), beforeRef = Editor.pointRef(e, splitAt, {
|
|
3676
|
+
affinity: "backward"
|
|
3677
|
+
});
|
|
3678
|
+
let afterRef;
|
|
3679
|
+
try {
|
|
3680
|
+
const [highest] = Editor.nodes(e, {
|
|
3681
|
+
at: splitAt,
|
|
3682
|
+
match: splitMatch,
|
|
3683
|
+
mode: "lowest",
|
|
3684
|
+
voids: !1
|
|
3685
|
+
});
|
|
3686
|
+
if (!highest)
|
|
3687
|
+
return;
|
|
3688
|
+
afterRef = Editor.pointRef(e, splitAt);
|
|
3689
|
+
const depth = splitAt.path.length, [, highestPath] = highest, lowestPath = splitAt.path.slice(0, depth);
|
|
3690
|
+
let position = splitAt.offset;
|
|
3691
|
+
for (const [node2, nodePath] of Editor.levels(e, {
|
|
3692
|
+
at: lowestPath,
|
|
3693
|
+
reverse: !0,
|
|
3694
|
+
voids: !1
|
|
3695
|
+
})) {
|
|
3696
|
+
let didSplit = !1;
|
|
3697
|
+
if (nodePath.length < highestPath.length || nodePath.length === 0)
|
|
3698
|
+
break;
|
|
3699
|
+
const point22 = beforeRef.current, isEndOfNode = Editor.isEnd(e, point22, nodePath);
|
|
3700
|
+
didSplit = !0;
|
|
3701
|
+
const properties = Node$1.extractProps(node2, e.schema);
|
|
3702
|
+
applySplitNode(e, nodePath, position, properties), position = nodePath[nodePath.length - 1] + (didSplit || isEndOfNode ? 1 : 0);
|
|
3703
|
+
}
|
|
3704
|
+
const point2 = afterRef.current || Editor.end(e, []);
|
|
3705
|
+
Transforms.select(e, point2);
|
|
3706
|
+
} finally {
|
|
3707
|
+
beforeRef.unref(), afterRef?.unref();
|
|
3708
|
+
}
|
|
3857
3709
|
}), e.insertText(line), split = !0;
|
|
3858
3710
|
return !0;
|
|
3859
3711
|
}
|
|
@@ -4018,22 +3870,6 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
4018
3870
|
meta: !1,
|
|
4019
3871
|
alt: !1
|
|
4020
3872
|
}]
|
|
4021
|
-
}), extendBackward = createKeyboardShortcut({
|
|
4022
|
-
default: [{
|
|
4023
|
-
key: "ArrowLeft",
|
|
4024
|
-
shift: !0,
|
|
4025
|
-
ctrl: !1,
|
|
4026
|
-
meta: !1,
|
|
4027
|
-
alt: !1
|
|
4028
|
-
}]
|
|
4029
|
-
}), extendForward = createKeyboardShortcut({
|
|
4030
|
-
default: [{
|
|
4031
|
-
key: "ArrowRight",
|
|
4032
|
-
shift: !0,
|
|
4033
|
-
ctrl: !1,
|
|
4034
|
-
meta: !1,
|
|
4035
|
-
alt: !1
|
|
4036
|
-
}]
|
|
4037
3873
|
}), italic = createKeyboardShortcut({
|
|
4038
3874
|
default: [{
|
|
4039
3875
|
key: "I",
|
|
@@ -4241,8 +4077,6 @@ var Hotkeys = {
|
|
|
4241
4077
|
isDeleteLineForward: deleteLineForward.guard,
|
|
4242
4078
|
isDeleteWordBackward: deleteWordBackward.guard,
|
|
4243
4079
|
isDeleteWordForward: deleteWordForward.guard,
|
|
4244
|
-
isExtendBackward: extendBackward.guard,
|
|
4245
|
-
isExtendForward: extendForward.guard,
|
|
4246
4080
|
isExtendLineBackward: extendLineBackward.guard,
|
|
4247
4081
|
isExtendLineForward: extendLineForward.guard,
|
|
4248
4082
|
isItalic: italic.guard,
|
|
@@ -5782,8 +5616,8 @@ const reconcileChildren = (editor, {
|
|
|
5782
5616
|
}), childrenHelper = new ChildrenHelper(editor, children);
|
|
5783
5617
|
let treeLeaf;
|
|
5784
5618
|
for (; treeLeaf = chunkTreeHelper.readLeaf(); ) {
|
|
5785
|
-
const lookAhead = childrenHelper.lookAhead(treeLeaf.node, treeLeaf.key)
|
|
5786
|
-
if (lookAhead === -1
|
|
5619
|
+
const lookAhead = childrenHelper.lookAhead(treeLeaf.node, treeLeaf.key);
|
|
5620
|
+
if (lookAhead === -1) {
|
|
5787
5621
|
chunkTreeHelper.remove();
|
|
5788
5622
|
continue;
|
|
5789
5623
|
}
|
|
@@ -5803,13 +5637,11 @@ const reconcileChildren = (editor, {
|
|
|
5803
5637
|
onInsert?.(node2, childrenHelper.pointerIndex + relativeIndex);
|
|
5804
5638
|
});
|
|
5805
5639
|
}
|
|
5806
|
-
chunkTree.movedNodeKeys.clear();
|
|
5807
5640
|
}, getChunkTreeForNode = (editor, node2, options = {}) => {
|
|
5808
5641
|
const key = ReactEditor.findKey(editor, node2);
|
|
5809
5642
|
let chunkTree = editor.keyToChunkTree.get(key);
|
|
5810
5643
|
return chunkTree || (chunkTree = {
|
|
5811
5644
|
type: "root",
|
|
5812
|
-
movedNodeKeys: /* @__PURE__ */ new Set(),
|
|
5813
5645
|
modifiedChunks: /* @__PURE__ */ new Set(),
|
|
5814
5646
|
children: []
|
|
5815
5647
|
}, editor.keyToChunkTree.set(key, chunkTree)), options.reconcile && reconcileChildren(editor, {
|
|
@@ -6788,9 +6620,9 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6788
6620
|
});
|
|
6789
6621
|
}
|
|
6790
6622
|
const {
|
|
6791
|
-
marks
|
|
6623
|
+
marks
|
|
6792
6624
|
} = editor;
|
|
6793
|
-
if (state.hasMarkPlaceholder = !1, editor.selection && Range.isCollapsed(editor.selection) &&
|
|
6625
|
+
if (state.hasMarkPlaceholder = !1, editor.selection && Range.isCollapsed(editor.selection) && marks) {
|
|
6794
6626
|
const {
|
|
6795
6627
|
anchor
|
|
6796
6628
|
} = editor.selection, leaf2 = Node$1.leaf(editor, anchor.path, editor.schema);
|
|
@@ -6799,7 +6631,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6799
6631
|
text: _text,
|
|
6800
6632
|
...rest
|
|
6801
6633
|
} = leaf2;
|
|
6802
|
-
if (!Text$1.equals(leaf2,
|
|
6634
|
+
if (!Text$1.equals(leaf2, marks, {
|
|
6803
6635
|
loose: !0
|
|
6804
6636
|
})) {
|
|
6805
6637
|
state.hasMarkPlaceholder = !0;
|
|
@@ -6807,7 +6639,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6807
6639
|
decorations.push({
|
|
6808
6640
|
[MARK_PLACEHOLDER_SYMBOL]: !0,
|
|
6809
6641
|
...unset2,
|
|
6810
|
-
...
|
|
6642
|
+
...marks,
|
|
6811
6643
|
anchor,
|
|
6812
6644
|
focus: anchor
|
|
6813
6645
|
});
|
|
@@ -6825,10 +6657,10 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6825
6657
|
} = selection, text = Node$1.leaf(editor, anchor.path, editor.schema);
|
|
6826
6658
|
if (!Text$1.isText(text, editor.schema))
|
|
6827
6659
|
return;
|
|
6828
|
-
if (
|
|
6660
|
+
if (marks && !Text$1.equals(text, marks, {
|
|
6829
6661
|
loose: !0
|
|
6830
6662
|
})) {
|
|
6831
|
-
editor.pendingInsertionMarks =
|
|
6663
|
+
editor.pendingInsertionMarks = marks;
|
|
6832
6664
|
return;
|
|
6833
6665
|
}
|
|
6834
6666
|
}
|
|
@@ -7706,9 +7538,9 @@ function requireReactDom() {
|
|
|
7706
7538
|
return process.env.NODE_ENV === "production" ? (checkDCE(), reactDom.exports = requireReactDom_production()) : reactDom.exports = requireReactDom_development(), reactDom.exports;
|
|
7707
7539
|
}
|
|
7708
7540
|
var reactDomExports = requireReactDom(), ReactDOM = /* @__PURE__ */ getDefaultExportFromCjs(reactDomExports);
|
|
7709
|
-
const withReact = (editor
|
|
7541
|
+
const withReact = (editor) => {
|
|
7710
7542
|
let e = editor;
|
|
7711
|
-
e = withDOM(e
|
|
7543
|
+
e = withDOM(e);
|
|
7712
7544
|
const {
|
|
7713
7545
|
onChange,
|
|
7714
7546
|
apply: apply2,
|
|
@@ -7719,13 +7551,6 @@ const withReact = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
7719
7551
|
onChange(options);
|
|
7720
7552
|
});
|
|
7721
7553
|
}, e.apply = (operation) => {
|
|
7722
|
-
if (operation.type === "move_node") {
|
|
7723
|
-
const parent2 = Node$1.parent(e, operation.path, e.schema);
|
|
7724
|
-
if (e.getChunkSize(parent2)) {
|
|
7725
|
-
const node2 = Node$1.get(e, operation.path, e.schema), chunkTree = getChunkTreeForNode(e, parent2), key = ReactEditor.findKey(e, node2);
|
|
7726
|
-
chunkTree.movedNodeKeys.add(key);
|
|
7727
|
-
}
|
|
7728
|
-
}
|
|
7729
7554
|
apply2(operation);
|
|
7730
7555
|
}, e;
|
|
7731
7556
|
}, EditorActorContext = createContext({}), IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
@@ -10874,12 +10699,7 @@ function applyInsertNodeAtPoint(editor, node2, at, options = {}) {
|
|
|
10874
10699
|
const [, matchPath2] = entry, pathRef2 = Editor.pathRef(editor, matchPath2), isAtEnd = Editor.isEnd(editor, at, matchPath2);
|
|
10875
10700
|
if (!Editor.isEdge(editor, at, matchPath2)) {
|
|
10876
10701
|
const textNode = Node$1.get(editor, at.path, editor.schema), properties = Node$1.extractProps(textNode, editor.schema);
|
|
10877
|
-
editor.
|
|
10878
|
-
type: "split_node",
|
|
10879
|
-
path: at.path,
|
|
10880
|
-
position: at.offset,
|
|
10881
|
-
properties
|
|
10882
|
-
});
|
|
10702
|
+
applySplitNode(editor, at.path, at.offset, properties);
|
|
10883
10703
|
}
|
|
10884
10704
|
const path2 = pathRef2.unref(), insertPath = isAtEnd ? Path.next(path2) : path2;
|
|
10885
10705
|
if (editor.apply({
|
|
@@ -10892,17 +10712,6 @@ function applyInsertNodeAtPoint(editor, node2, at, options = {}) {
|
|
|
10892
10712
|
}
|
|
10893
10713
|
});
|
|
10894
10714
|
}
|
|
10895
|
-
function applySetNode(editor, props, path2) {
|
|
10896
|
-
const node2 = Node$1.get(editor, path2, editor.schema), propsRecord = props, properties = {}, newProperties = {};
|
|
10897
|
-
for (const key of Object.keys(propsRecord))
|
|
10898
|
-
key !== "children" && (key === "text" && !Element$2.isElement(node2, editor.schema) && !editor.isObjectNode(node2) || propsRecord[key] !== node2[key] && (node2.hasOwnProperty(key) && (properties[key] = node2[key]), propsRecord[key] != null && (newProperties[key] = propsRecord[key])));
|
|
10899
|
-
(Object.keys(newProperties).length > 0 || Object.keys(properties).length > 0) && editor.apply({
|
|
10900
|
-
type: "set_node",
|
|
10901
|
-
path: path2,
|
|
10902
|
-
properties,
|
|
10903
|
-
newProperties
|
|
10904
|
-
});
|
|
10905
|
-
}
|
|
10906
10715
|
function withNormalizeNode(editor, fn) {
|
|
10907
10716
|
const prev = editor.isNormalizingNode;
|
|
10908
10717
|
editor.isNormalizingNode = !0, fn(), editor.isNormalizingNode = prev;
|
|
@@ -10935,12 +10744,7 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10935
10744
|
text: _text,
|
|
10936
10745
|
...properties
|
|
10937
10746
|
} = nextNode;
|
|
10938
|
-
editor.
|
|
10939
|
-
type: "merge_node",
|
|
10940
|
-
path: mergePath,
|
|
10941
|
-
position: child.text.length,
|
|
10942
|
-
properties
|
|
10943
|
-
});
|
|
10747
|
+
applyMergeNode(editor, mergePath, child.text.length, properties);
|
|
10944
10748
|
});
|
|
10945
10749
|
return;
|
|
10946
10750
|
}
|
|
@@ -10985,11 +10789,11 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10985
10789
|
const decorators = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name);
|
|
10986
10790
|
for (const [child, childPath] of Node$1.children(editor, path2, editor.schema))
|
|
10987
10791
|
if (editor.isTextSpan(child)) {
|
|
10988
|
-
const
|
|
10792
|
+
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !node2.markDefs?.find((def) => def._key === mark));
|
|
10989
10793
|
if (orphanedAnnotations.length > 0) {
|
|
10990
10794
|
debug$1.normalization("removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
10991
10795
|
applySetNode(editor, {
|
|
10992
|
-
marks:
|
|
10796
|
+
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
10993
10797
|
}, childPath);
|
|
10994
10798
|
});
|
|
10995
10799
|
return;
|
|
@@ -10999,11 +10803,11 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10999
10803
|
if (editor.isTextSpan(node2)) {
|
|
11000
10804
|
const blockPath = Path.parent(path2), [block] = Editor.node(editor, blockPath);
|
|
11001
10805
|
if (editor.isTextBlock(block)) {
|
|
11002
|
-
const decorators = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name),
|
|
10806
|
+
const decorators = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node2.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
11003
10807
|
if (orphanedAnnotations.length > 0) {
|
|
11004
10808
|
debug$1.normalization("removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
11005
10809
|
applySetNode(editor, {
|
|
11006
|
-
marks:
|
|
10810
|
+
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
11007
10811
|
}, path2);
|
|
11008
10812
|
});
|
|
11009
10813
|
return;
|
|
@@ -11023,7 +10827,7 @@ function createNormalizationPlugin(editorActor) {
|
|
|
11023
10827
|
return;
|
|
11024
10828
|
}
|
|
11025
10829
|
}
|
|
11026
|
-
if (editor.isTextBlock(node2)
|
|
10830
|
+
if (editor.isTextBlock(node2)) {
|
|
11027
10831
|
const newMarkDefs = (node2.markDefs || []).filter((def) => node2.children.find((child) => Text$1.isText(child, editor.schema) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
11028
10832
|
if (node2.markDefs && !isEqualMarkDefs(newMarkDefs, node2.markDefs)) {
|
|
11029
10833
|
debug$1.normalization("removing markDef not in use"), withNormalizeNode(editor, () => {
|
|
@@ -11071,16 +10875,6 @@ function createNormalizationPlugin(editorActor) {
|
|
|
11071
10875
|
}
|
|
11072
10876
|
} else
|
|
11073
10877
|
editor.decoratorState = {};
|
|
11074
|
-
if (op.type === "merge_node" && op.path.length === 1 && "markDefs" in op.properties && op.properties._type === editorActor.getSnapshot().context.schema.block.name && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] - 1 >= 0) {
|
|
11075
|
-
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
11076
|
-
if (editor.isTextBlock(targetBlock)) {
|
|
11077
|
-
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = [...new Map([...oldDefs, ...op.properties.markDefs].map((def) => [def._key, def])).values()];
|
|
11078
|
-
debug$1.normalization("copying markDefs over to merged block", op), applySetNode(editor, {
|
|
11079
|
-
markDefs: newMarkDefs
|
|
11080
|
-
}, targetPath), apply2(op);
|
|
11081
|
-
return;
|
|
11082
|
-
}
|
|
11083
|
-
}
|
|
11084
10878
|
apply2(op);
|
|
11085
10879
|
}, editor;
|
|
11086
10880
|
};
|
|
@@ -12271,58 +12065,6 @@ function insertNodePatch(schema, children, operation, beforeValue) {
|
|
|
12271
12065
|
}
|
|
12272
12066
|
return [];
|
|
12273
12067
|
}
|
|
12274
|
-
function splitNodePatch(schema, children, operation, beforeValue) {
|
|
12275
|
-
const patches = [], splitBlock2 = children[operation.path[0]];
|
|
12276
|
-
if (!isTextBlock({
|
|
12277
|
-
schema
|
|
12278
|
-
}, splitBlock2))
|
|
12279
|
-
throw new Error(`Block with path ${JSON.stringify(operation.path[0])} is not a text block and can't be split`);
|
|
12280
|
-
if (operation.path.length === 1) {
|
|
12281
|
-
const oldBlock = beforeValue[operation.path[0]];
|
|
12282
|
-
if (isTextBlock({
|
|
12283
|
-
schema
|
|
12284
|
-
}, oldBlock)) {
|
|
12285
|
-
const nextBlock = children[operation.path[0] + 1];
|
|
12286
|
-
if (!nextBlock)
|
|
12287
|
-
return patches;
|
|
12288
|
-
const targetValue = nextBlock;
|
|
12289
|
-
targetValue && (patches.push(insert([targetValue], "after", [{
|
|
12290
|
-
_key: splitBlock2._key
|
|
12291
|
-
}])), oldBlock.children.slice(operation.position).forEach((span) => {
|
|
12292
|
-
const path2 = [{
|
|
12293
|
-
_key: oldBlock._key
|
|
12294
|
-
}, "children", {
|
|
12295
|
-
_key: span._key
|
|
12296
|
-
}];
|
|
12297
|
-
patches.push(unset(path2));
|
|
12298
|
-
}));
|
|
12299
|
-
}
|
|
12300
|
-
return patches;
|
|
12301
|
-
}
|
|
12302
|
-
if (operation.path.length === 2) {
|
|
12303
|
-
const splitSpan = splitBlock2.children[operation.path[1]];
|
|
12304
|
-
if (isSpan({
|
|
12305
|
-
schema
|
|
12306
|
-
}, splitSpan)) {
|
|
12307
|
-
const targetSpans = {
|
|
12308
|
-
children: splitBlock2.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
12309
|
-
}.children;
|
|
12310
|
-
patches.push(setIfMissing([], [{
|
|
12311
|
-
_key: splitBlock2._key
|
|
12312
|
-
}, "children"])), patches.push(insert(targetSpans, "after", [{
|
|
12313
|
-
_key: splitBlock2._key
|
|
12314
|
-
}, "children", {
|
|
12315
|
-
_key: splitSpan._key
|
|
12316
|
-
}])), patches.push(set(splitSpan.text, [{
|
|
12317
|
-
_key: splitBlock2._key
|
|
12318
|
-
}, "children", {
|
|
12319
|
-
_key: splitSpan._key
|
|
12320
|
-
}, "text"]));
|
|
12321
|
-
}
|
|
12322
|
-
return patches;
|
|
12323
|
-
}
|
|
12324
|
-
return patches;
|
|
12325
|
-
}
|
|
12326
12068
|
function removeNodePatch(schema, beforeValue, operation) {
|
|
12327
12069
|
const block = beforeValue[operation.path[0]];
|
|
12328
12070
|
if (operation.path.length === 1) {
|
|
@@ -12343,86 +12085,6 @@ function removeNodePatch(schema, beforeValue, operation) {
|
|
|
12343
12085
|
} else
|
|
12344
12086
|
return [];
|
|
12345
12087
|
}
|
|
12346
|
-
function mergeNodePatch(schema, children, operation, beforeValue) {
|
|
12347
|
-
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = children[operation.path[0]];
|
|
12348
|
-
if (operation.path.length === 1)
|
|
12349
|
-
if (block?._key) {
|
|
12350
|
-
const prevBlock = children[operation.path[0] - 1];
|
|
12351
|
-
if (!prevBlock)
|
|
12352
|
-
throw new Error("Previous block not found!");
|
|
12353
|
-
const newBlock = prevBlock;
|
|
12354
|
-
patches.push(set(newBlock, [{
|
|
12355
|
-
_key: newBlock._key
|
|
12356
|
-
}])), patches.push(unset([{
|
|
12357
|
-
_key: block._key
|
|
12358
|
-
}]));
|
|
12359
|
-
} else
|
|
12360
|
-
throw new Error("Target key not found!");
|
|
12361
|
-
else if (isTextBlock({
|
|
12362
|
-
schema
|
|
12363
|
-
}, block) && isTextBlock({
|
|
12364
|
-
schema
|
|
12365
|
-
}, updatedBlock) && operation.path.length === 2) {
|
|
12366
|
-
const updatedSpan = updatedBlock.children[operation.path[1] - 1] && isSpan({
|
|
12367
|
-
schema
|
|
12368
|
-
}, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && isSpan({
|
|
12369
|
-
schema
|
|
12370
|
-
}, block.children[operation.path[1]]) ? block.children[operation.path[1]] : void 0;
|
|
12371
|
-
if (updatedSpan) {
|
|
12372
|
-
const spansMatchingKey = block.children.filter((span) => span._key === updatedSpan._key);
|
|
12373
|
-
if (spansMatchingKey.length === 1) {
|
|
12374
|
-
const prevSpan = spansMatchingKey[0];
|
|
12375
|
-
isSpan({
|
|
12376
|
-
schema
|
|
12377
|
-
}, prevSpan) && prevSpan.text !== updatedSpan.text && patches.push(set(updatedSpan.text, [{
|
|
12378
|
-
_key: block._key
|
|
12379
|
-
}, "children", {
|
|
12380
|
-
_key: updatedSpan._key
|
|
12381
|
-
}, "text"]));
|
|
12382
|
-
} else
|
|
12383
|
-
console.warn(`Multiple spans have \`_key\` ${updatedSpan._key}. It's ambiguous which one to update.`, JSON.stringify(block, null, 2));
|
|
12384
|
-
}
|
|
12385
|
-
removedSpan && (block.children.filter((span) => span._key === removedSpan._key).length === 1 ? patches.push(unset([{
|
|
12386
|
-
_key: block._key
|
|
12387
|
-
}, "children", {
|
|
12388
|
-
_key: removedSpan._key
|
|
12389
|
-
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
12390
|
-
}
|
|
12391
|
-
return patches;
|
|
12392
|
-
}
|
|
12393
|
-
function moveNodePatch(schema, beforeValue, operation) {
|
|
12394
|
-
const patches = [], block = beforeValue[operation.path[0]], targetBlock = beforeValue[operation.newPath[0]];
|
|
12395
|
-
if (!targetBlock || !block)
|
|
12396
|
-
return patches;
|
|
12397
|
-
if (operation.path.length === 1) {
|
|
12398
|
-
const position = operation.path[0] > operation.newPath[0] ? "before" : "after";
|
|
12399
|
-
patches.push(unset([{
|
|
12400
|
-
_key: block._key
|
|
12401
|
-
}])), patches.push(insert([block], position, [{
|
|
12402
|
-
_key: targetBlock._key
|
|
12403
|
-
}]));
|
|
12404
|
-
} else if (operation.path.length === 2 && isTextBlock({
|
|
12405
|
-
schema
|
|
12406
|
-
}, block) && isTextBlock({
|
|
12407
|
-
schema
|
|
12408
|
-
}, targetBlock)) {
|
|
12409
|
-
const child = block.children[operation.path[1]], targetChild = targetBlock.children[operation.newPath[1]], position = operation.newPath[1] === targetBlock.children.length ? "after" : "before", childToInsert = block.children[operation.path[1]];
|
|
12410
|
-
if (!child || !targetChild || !childToInsert)
|
|
12411
|
-
return patches;
|
|
12412
|
-
patches.push(unset([{
|
|
12413
|
-
_key: block._key
|
|
12414
|
-
}, "children", {
|
|
12415
|
-
_key: child._key
|
|
12416
|
-
}])), patches.push(setIfMissing([], [{
|
|
12417
|
-
_key: targetBlock._key
|
|
12418
|
-
}, "children"])), patches.push(insert([childToInsert], position, [{
|
|
12419
|
-
_key: targetBlock._key
|
|
12420
|
-
}, "children", {
|
|
12421
|
-
_key: targetChild._key
|
|
12422
|
-
}]));
|
|
12423
|
-
}
|
|
12424
|
-
return patches;
|
|
12425
|
-
}
|
|
12426
12088
|
function withRemoteChanges(editor, fn) {
|
|
12427
12089
|
const prev = editor.isProcessingRemoteChanges;
|
|
12428
12090
|
editor.isProcessingRemoteChanges = !0, fn(), editor.isProcessingRemoteChanges = prev;
|
|
@@ -12494,23 +12156,14 @@ function createPatchesPlugin({
|
|
|
12494
12156
|
case "remove_node":
|
|
12495
12157
|
patches = [...patches, ...removeNodePatch(editorActor.getSnapshot().context.schema, previousValue, operation)];
|
|
12496
12158
|
break;
|
|
12497
|
-
case "split_node":
|
|
12498
|
-
patches = [...patches, ...splitNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
|
|
12499
|
-
break;
|
|
12500
12159
|
case "insert_node":
|
|
12501
12160
|
patches = [...patches, ...insertNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
|
|
12502
12161
|
break;
|
|
12503
12162
|
case "set_node":
|
|
12504
12163
|
patches = [...patches, ...setNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation)];
|
|
12505
12164
|
break;
|
|
12506
|
-
case "merge_node":
|
|
12507
|
-
patches = [...patches, ...mergeNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
|
|
12508
|
-
break;
|
|
12509
|
-
case "move_node":
|
|
12510
|
-
patches = [...patches, ...moveNodePatch(editorActor.getSnapshot().context.schema, previousValue, operation)];
|
|
12511
|
-
break;
|
|
12512
12165
|
}
|
|
12513
|
-
if (!editorWasEmpty && editorIsEmpty && ["
|
|
12166
|
+
if (!editorWasEmpty && editorIsEmpty && ["set_node", "remove_text", "remove_node"].includes(operation.type) && (patches = [...patches, unset([])], relayActor.send({
|
|
12514
12167
|
type: "unset",
|
|
12515
12168
|
previousValue
|
|
12516
12169
|
})), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0)
|
|
@@ -12599,23 +12252,6 @@ function createUniqueKeysPlugin(editorActor) {
|
|
|
12599
12252
|
apply2(operation);
|
|
12600
12253
|
return;
|
|
12601
12254
|
}
|
|
12602
|
-
if (operation.type === "split_node") {
|
|
12603
|
-
const _key = operation.properties._key && keyExistsAtPath({
|
|
12604
|
-
blockIndexMap: editor.blockIndexMap,
|
|
12605
|
-
context: {
|
|
12606
|
-
schema: context.schema,
|
|
12607
|
-
value: editor.children
|
|
12608
|
-
}
|
|
12609
|
-
}, operation.path, operation.properties._key) ? void 0 : operation.properties._key;
|
|
12610
|
-
apply2({
|
|
12611
|
-
...operation,
|
|
12612
|
-
properties: {
|
|
12613
|
-
...operation.properties,
|
|
12614
|
-
_key: _key === void 0 ? editorActor.getSnapshot().context.keyGenerator() : _key
|
|
12615
|
-
}
|
|
12616
|
-
});
|
|
12617
|
-
return;
|
|
12618
|
-
}
|
|
12619
12255
|
if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
|
|
12620
12256
|
const _key = operation.node._key && keyExistsAtPath({
|
|
12621
12257
|
blockIndexMap: editor.blockIndexMap,
|
|
@@ -12633,54 +12269,6 @@ function createUniqueKeysPlugin(editorActor) {
|
|
|
12633
12269
|
});
|
|
12634
12270
|
return;
|
|
12635
12271
|
}
|
|
12636
|
-
if (operation.type === "merge_node") {
|
|
12637
|
-
const index = operation.path[operation.path.length - 1], prevPath = Path.previous(operation.path), prevIndex = prevPath[prevPath.length - 1];
|
|
12638
|
-
if (operation.path.length !== 1 || prevPath.length !== 1) {
|
|
12639
|
-
apply2(operation);
|
|
12640
|
-
return;
|
|
12641
|
-
}
|
|
12642
|
-
const block = editor.children.at(index), previousBlock = editor.children.at(prevIndex);
|
|
12643
|
-
if (!block || !previousBlock) {
|
|
12644
|
-
apply2(operation);
|
|
12645
|
-
return;
|
|
12646
|
-
}
|
|
12647
|
-
if (!isTextBlock(editorActor.getSnapshot().context, block) || !isTextBlock(editorActor.getSnapshot().context, previousBlock)) {
|
|
12648
|
-
apply2(operation);
|
|
12649
|
-
return;
|
|
12650
|
-
}
|
|
12651
|
-
const previousBlockChildKeys = previousBlock.children.map((child) => child._key), previousBlockMarkDefKeys = previousBlock.markDefs?.map((markDef) => markDef._key) ?? [], markDefKeyMap = /* @__PURE__ */ new Map(), adjustedMarkDefs = block.markDefs?.map((markDef) => {
|
|
12652
|
-
if (previousBlockMarkDefKeys.includes(markDef._key)) {
|
|
12653
|
-
const newKey = editorActor.getSnapshot().context.keyGenerator();
|
|
12654
|
-
return markDefKeyMap.set(markDef._key, newKey), {
|
|
12655
|
-
...markDef,
|
|
12656
|
-
_key: newKey
|
|
12657
|
-
};
|
|
12658
|
-
}
|
|
12659
|
-
return markDef;
|
|
12660
|
-
});
|
|
12661
|
-
let childIndex = 0;
|
|
12662
|
-
for (const child of block.children) {
|
|
12663
|
-
if (isSpan(editorActor.getSnapshot().context, child)) {
|
|
12664
|
-
const marks2 = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
12665
|
-
isEqualMarks(child.marks, marks2) || applySetNode(editor, {
|
|
12666
|
-
marks: marks2
|
|
12667
|
-
}, [index, childIndex]);
|
|
12668
|
-
}
|
|
12669
|
-
previousBlockChildKeys.includes(child._key) && applySetNode(editor, {
|
|
12670
|
-
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
12671
|
-
}, [index, childIndex]), childIndex++;
|
|
12672
|
-
}
|
|
12673
|
-
apply2({
|
|
12674
|
-
...operation,
|
|
12675
|
-
properties: {
|
|
12676
|
-
...operation.properties,
|
|
12677
|
-
// Make sure the adjusted markDefs are carried along for the merge
|
|
12678
|
-
// operation
|
|
12679
|
-
markDefs: adjustedMarkDefs
|
|
12680
|
-
}
|
|
12681
|
-
});
|
|
12682
|
-
return;
|
|
12683
|
-
}
|
|
12684
12272
|
apply2(operation);
|
|
12685
12273
|
}, editor.normalizeNode = (entry) => {
|
|
12686
12274
|
const [node2, path2] = entry;
|
|
@@ -13069,10 +12657,10 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
13069
12657
|
const startChild = getSelectionStartChild(effectiveSnapshot), startPoint = getSelectionStartPoint(effectiveSnapshot), endChild = getSelectionEndChild(effectiveSnapshot), endPoint = getSelectionEndPoint(effectiveSnapshot);
|
|
13070
12658
|
if (!startChild || !endChild || !startPoint || !endPoint || startChild.path[2]._key !== endChild.path[2]._key || !isSpan(snapshot.context, startChild.node) || !(startPoint.offset === 0 && endPoint.offset === startChild.node.text.length))
|
|
13071
12659
|
return !1;
|
|
13072
|
-
const decorators = snapshot.context.schema.decorators.map((decorator) => decorator.name),
|
|
13073
|
-
if (!
|
|
12660
|
+
const decorators = snapshot.context.schema.decorators.map((decorator) => decorator.name), marks = startChild.node.marks ?? [];
|
|
12661
|
+
if (!marks.some((mark) => !decorators.includes(mark)))
|
|
13074
12662
|
return !1;
|
|
13075
|
-
const previousSpan = getPreviousSpan(effectiveSnapshot), nextSpan = getNextSpan(effectiveSnapshot), previousSpanHasSameAnnotation = previousSpan ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark) &&
|
|
12663
|
+
const previousSpan = getPreviousSpan(effectiveSnapshot), nextSpan = getNextSpan(effectiveSnapshot), previousSpanHasSameAnnotation = previousSpan ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? nextSpan.node.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
|
|
13076
12664
|
if (previousSpanHasSameAnnotation || nextSpanHasSameAnnotation)
|
|
13077
12665
|
return !1;
|
|
13078
12666
|
const activeDecorators = getActiveDecorators(effectiveSnapshot);
|
|
@@ -14394,21 +13982,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
14394
13982
|
}), [splitStart, splitEnd] = Range.edges(splitRange);
|
|
14395
13983
|
if (!Editor.isEnd(editor, splitEnd, splitEnd.path) || !Editor.isEdge(editor, splitEnd, splitEnd.path)) {
|
|
14396
13984
|
const [endNode] = Editor.node(editor, splitEnd.path);
|
|
14397
|
-
editor.
|
|
14398
|
-
type: "split_node",
|
|
14399
|
-
path: splitEnd.path,
|
|
14400
|
-
position: splitEnd.offset,
|
|
14401
|
-
properties: Node$1.extractProps(endNode, editor.schema)
|
|
14402
|
-
});
|
|
13985
|
+
applySplitNode(editor, splitEnd.path, splitEnd.offset, Node$1.extractProps(endNode, editor.schema));
|
|
14403
13986
|
}
|
|
14404
13987
|
if (!Editor.isStart(editor, splitStart, splitStart.path) || !Editor.isEdge(editor, splitStart, splitStart.path)) {
|
|
14405
13988
|
const [startNode] = Editor.node(editor, splitStart.path);
|
|
14406
|
-
editor.
|
|
14407
|
-
type: "split_node",
|
|
14408
|
-
path: splitStart.path,
|
|
14409
|
-
position: splitStart.offset,
|
|
14410
|
-
properties: Node$1.extractProps(startNode, editor.schema)
|
|
14411
|
-
});
|
|
13989
|
+
applySplitNode(editor, splitStart.path, splitStart.offset, Node$1.extractProps(startNode, editor.schema));
|
|
14412
13990
|
}
|
|
14413
13991
|
const updatedSplitRange = splitRangeRef.unref();
|
|
14414
13992
|
!at && updatedSplitRange && applySelect(editor, updatedSplitRange);
|
|
@@ -14418,9 +13996,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
14418
13996
|
for (const [span, path2] of children) {
|
|
14419
13997
|
if (!editor.isTextSpan(span) || !selectionRange || !Range.includes(selectionRange, path2))
|
|
14420
13998
|
continue;
|
|
14421
|
-
const
|
|
13999
|
+
const marks = span.marks ?? [];
|
|
14422
14000
|
applySetNode(editor, {
|
|
14423
|
-
marks: [...
|
|
14001
|
+
marks: [...marks, annotationKey]
|
|
14424
14002
|
}, path2);
|
|
14425
14003
|
}
|
|
14426
14004
|
blockIndex++;
|
|
@@ -14485,21 +14063,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
14485
14063
|
}), [splitStart, splitEnd] = Range.edges(splitRange);
|
|
14486
14064
|
if (!Editor.isEnd(editor, splitEnd, splitEnd.path) || !Editor.isEdge(editor, splitEnd, splitEnd.path)) {
|
|
14487
14065
|
const [endNode] = Editor.node(editor, splitEnd.path);
|
|
14488
|
-
editor.
|
|
14489
|
-
type: "split_node",
|
|
14490
|
-
path: splitEnd.path,
|
|
14491
|
-
position: splitEnd.offset,
|
|
14492
|
-
properties: Node$1.extractProps(endNode, editor.schema)
|
|
14493
|
-
});
|
|
14066
|
+
applySplitNode(editor, splitEnd.path, splitEnd.offset, Node$1.extractProps(endNode, editor.schema));
|
|
14494
14067
|
}
|
|
14495
14068
|
if (!Editor.isStart(editor, splitStart, splitStart.path) || !Editor.isEdge(editor, splitStart, splitStart.path)) {
|
|
14496
14069
|
const [startNode] = Editor.node(editor, splitStart.path);
|
|
14497
|
-
editor.
|
|
14498
|
-
type: "split_node",
|
|
14499
|
-
path: splitStart.path,
|
|
14500
|
-
position: splitStart.offset,
|
|
14501
|
-
properties: Node$1.extractProps(startNode, editor.schema)
|
|
14502
|
-
});
|
|
14070
|
+
applySplitNode(editor, splitStart.path, splitStart.offset, Node$1.extractProps(startNode, editor.schema));
|
|
14503
14071
|
}
|
|
14504
14072
|
const updatedSplitRange = splitRangeRef.unref();
|
|
14505
14073
|
!at && updatedSplitRange && applySelect(editor, updatedSplitRange);
|
|
@@ -14514,8 +14082,8 @@ const addAnnotationOperationImplementation = ({
|
|
|
14514
14082
|
for (const [child, childPath] of children) {
|
|
14515
14083
|
if (!editor.isTextSpan(child) || !selectionRange || !Range.includes(selectionRange, childPath))
|
|
14516
14084
|
continue;
|
|
14517
|
-
const markDefs = block.markDefs ?? [],
|
|
14518
|
-
marksWithoutAnnotation.length !==
|
|
14085
|
+
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== operation.annotation.name);
|
|
14086
|
+
marksWithoutAnnotation.length !== marks.length && applySetNode(editor, {
|
|
14519
14087
|
marks: marksWithoutAnnotation
|
|
14520
14088
|
}, childPath);
|
|
14521
14089
|
}
|
|
@@ -14738,21 +14306,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
14738
14306
|
}), [start2, end2] = Range.edges(at);
|
|
14739
14307
|
if (!Editor.isEnd(editor, end2, end2.path) || !Editor.isEdge(editor, end2, end2.path)) {
|
|
14740
14308
|
const [endNode] = Editor.node(editor, end2.path);
|
|
14741
|
-
editor.
|
|
14742
|
-
type: "split_node",
|
|
14743
|
-
path: end2.path,
|
|
14744
|
-
position: end2.offset,
|
|
14745
|
-
properties: Node$1.extractProps(endNode, editor.schema)
|
|
14746
|
-
});
|
|
14309
|
+
applySplitNode(editor, end2.path, end2.offset, Node$1.extractProps(endNode, editor.schema));
|
|
14747
14310
|
}
|
|
14748
14311
|
if (!Editor.isStart(editor, start2, start2.path) || !Editor.isEdge(editor, start2, start2.path)) {
|
|
14749
14312
|
const [startNode] = Editor.node(editor, start2.path);
|
|
14750
|
-
editor.
|
|
14751
|
-
type: "split_node",
|
|
14752
|
-
path: start2.path,
|
|
14753
|
-
position: start2.offset,
|
|
14754
|
-
properties: Node$1.extractProps(startNode, editor.schema)
|
|
14755
|
-
});
|
|
14313
|
+
applySplitNode(editor, start2.path, start2.offset, Node$1.extractProps(startNode, editor.schema));
|
|
14756
14314
|
}
|
|
14757
14315
|
if (at = rangeRef2.unref(), !at)
|
|
14758
14316
|
throw new Error("Unable to add decorator without a selection");
|
|
@@ -14762,9 +14320,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
14762
14320
|
match: (n2) => Text$1.isText(n2, editor.schema)
|
|
14763
14321
|
});
|
|
14764
14322
|
for (const [node2, path2] of splitTextNodes) {
|
|
14765
|
-
const
|
|
14323
|
+
const marks = [...(Array.isArray(node2.marks) ? node2.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
14766
14324
|
applySetNode(editor, {
|
|
14767
|
-
marks
|
|
14325
|
+
marks
|
|
14768
14326
|
}, path2);
|
|
14769
14327
|
}
|
|
14770
14328
|
} else {
|
|
@@ -14816,21 +14374,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
14816
14374
|
const [start2, end2] = Range.edges(at);
|
|
14817
14375
|
if (!Editor.isEnd(editor, end2, end2.path) || !Editor.isEdge(editor, end2, end2.path)) {
|
|
14818
14376
|
const [endNode] = Editor.node(editor, end2.path);
|
|
14819
|
-
editor.
|
|
14820
|
-
type: "split_node",
|
|
14821
|
-
path: end2.path,
|
|
14822
|
-
position: end2.offset,
|
|
14823
|
-
properties: Node$1.extractProps(endNode, editor.schema)
|
|
14824
|
-
});
|
|
14377
|
+
applySplitNode(editor, end2.path, end2.offset, Node$1.extractProps(endNode, editor.schema));
|
|
14825
14378
|
}
|
|
14826
14379
|
if (!Editor.isStart(editor, start2, start2.path) || !Editor.isEdge(editor, start2, start2.path)) {
|
|
14827
14380
|
const [startNode] = Editor.node(editor, start2.path);
|
|
14828
|
-
editor.
|
|
14829
|
-
type: "split_node",
|
|
14830
|
-
path: start2.path,
|
|
14831
|
-
position: start2.offset,
|
|
14832
|
-
properties: Node$1.extractProps(startNode, editor.schema)
|
|
14833
|
-
});
|
|
14381
|
+
applySplitNode(editor, start2.path, start2.offset, Node$1.extractProps(startNode, editor.schema));
|
|
14834
14382
|
}
|
|
14835
14383
|
}
|
|
14836
14384
|
const updatedAt = rangeRef2.unref();
|
|
@@ -15448,24 +14996,14 @@ function insertBlock(options) {
|
|
|
15448
14996
|
text: _2,
|
|
15449
14997
|
...properties
|
|
15450
14998
|
} = textNode;
|
|
15451
|
-
editor.
|
|
15452
|
-
type: "split_node",
|
|
15453
|
-
path: selectionPoint.path,
|
|
15454
|
-
position: childOffset,
|
|
15455
|
-
properties
|
|
15456
|
-
});
|
|
14999
|
+
applySplitNode(editor, selectionPoint.path, childOffset, properties);
|
|
15457
15000
|
}
|
|
15458
15001
|
}
|
|
15459
15002
|
const splitAtIndex = childOffset > 0 ? childIndex + 1 : childIndex, {
|
|
15460
15003
|
children: _,
|
|
15461
15004
|
...blockProperties
|
|
15462
15005
|
} = currentBlock;
|
|
15463
|
-
editor
|
|
15464
|
-
type: "split_node",
|
|
15465
|
-
path: blockPath,
|
|
15466
|
-
position: splitAtIndex,
|
|
15467
|
-
properties: blockProperties
|
|
15468
|
-
});
|
|
15006
|
+
applySplitNode(editor, blockPath, splitAtIndex, blockProperties);
|
|
15469
15007
|
const insertPath = [blockPath[0] + 1];
|
|
15470
15008
|
if (editor.apply({
|
|
15471
15009
|
type: "insert_node",
|
|
@@ -15544,12 +15082,12 @@ function insertBlock(options) {
|
|
|
15544
15082
|
return markDef;
|
|
15545
15083
|
}), adjustedChildren = block.children.map((child) => {
|
|
15546
15084
|
if (isSpan(context, child)) {
|
|
15547
|
-
const
|
|
15548
|
-
if (!isEqualMarks(child.marks,
|
|
15085
|
+
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
15086
|
+
if (!isEqualMarks(child.marks, marks))
|
|
15549
15087
|
return {
|
|
15550
15088
|
...child,
|
|
15551
15089
|
_key: endBlockChildKeys.includes(child._key) ? context.keyGenerator() : child._key,
|
|
15552
|
-
marks
|
|
15090
|
+
marks
|
|
15553
15091
|
};
|
|
15554
15092
|
}
|
|
15555
15093
|
return endBlockChildKeys.includes(child._key) ? {
|
|
@@ -15657,12 +15195,7 @@ function insertBlock(options) {
|
|
|
15657
15195
|
text: _,
|
|
15658
15196
|
...properties
|
|
15659
15197
|
} = nodeToSplit;
|
|
15660
|
-
editor.
|
|
15661
|
-
type: "split_node",
|
|
15662
|
-
path: startPoint.path,
|
|
15663
|
-
position: startPoint.offset,
|
|
15664
|
-
properties
|
|
15665
|
-
});
|
|
15198
|
+
applySplitNode(editor, startPoint.path, startPoint.offset, properties);
|
|
15666
15199
|
}
|
|
15667
15200
|
insertTextBlockFragment(editor, block, startPoint), select2 === "none" ? setSelectionToRange(editor, at) : setSelection(editor, [endBlockPath[0] + 1], "start");
|
|
15668
15201
|
} else {
|
|
@@ -15675,12 +15208,7 @@ function insertBlock(options) {
|
|
|
15675
15208
|
text: _,
|
|
15676
15209
|
...properties
|
|
15677
15210
|
} = textNode;
|
|
15678
|
-
editor.
|
|
15679
|
-
type: "split_node",
|
|
15680
|
-
path: currentPath,
|
|
15681
|
-
position: currentOffset,
|
|
15682
|
-
properties
|
|
15683
|
-
}), currentPath = Path.next(currentPath), currentOffset = 0;
|
|
15211
|
+
applySplitNode(editor, currentPath, currentOffset, properties), currentPath = Path.next(currentPath), currentOffset = 0;
|
|
15684
15212
|
}
|
|
15685
15213
|
const splitAtIndex = currentOffset > 0 ? currentPath[1] + 1 : currentPath[1], blockToSplit = Node$1.get(editor, blockPath, editor.schema);
|
|
15686
15214
|
if (splitAtIndex < blockToSplit.children.length && Element$2.isElement(blockToSplit, editor.schema)) {
|
|
@@ -15688,12 +15216,7 @@ function insertBlock(options) {
|
|
|
15688
15216
|
children: _,
|
|
15689
15217
|
...blockProperties
|
|
15690
15218
|
} = blockToSplit;
|
|
15691
|
-
editor
|
|
15692
|
-
type: "split_node",
|
|
15693
|
-
path: blockPath,
|
|
15694
|
-
position: splitAtIndex,
|
|
15695
|
-
properties: blockProperties
|
|
15696
|
-
});
|
|
15219
|
+
applySplitNode(editor, blockPath, splitAtIndex, blockProperties);
|
|
15697
15220
|
}
|
|
15698
15221
|
const currentFirstBlockPath = firstBlockPathRef.unref(), insertPath = currentFirstBlockPath ? [currentFirstBlockPath[0] + 1] : [blockPath[0] + 1];
|
|
15699
15222
|
if (editor.apply({
|
|
@@ -15840,12 +15363,7 @@ function deleteSameBlockRange(editor, start2, end2) {
|
|
|
15840
15363
|
text: _,
|
|
15841
15364
|
...properties
|
|
15842
15365
|
} = endNodeAfter;
|
|
15843
|
-
editor.
|
|
15844
|
-
type: "merge_node",
|
|
15845
|
-
path: newEndPath,
|
|
15846
|
-
position: startNodeAfter.text.length,
|
|
15847
|
-
properties
|
|
15848
|
-
});
|
|
15366
|
+
applyMergeNode(editor, newEndPath, startNodeAfter.text.length, properties);
|
|
15849
15367
|
}
|
|
15850
15368
|
}
|
|
15851
15369
|
function deleteCrossBlockRange(editor, start2, end2) {
|
|
@@ -15883,18 +15401,19 @@ function deleteCrossBlockRange(editor, start2, end2) {
|
|
|
15883
15401
|
}
|
|
15884
15402
|
}
|
|
15885
15403
|
const startBlock = Node$1.get(editor, startBlockPath, editor.schema), endBlock = Node$1.get(editor, adjustedEndBlockPath, editor.schema);
|
|
15886
|
-
|
|
15404
|
+
editor.isTextBlock(startBlock) && editor.isTextBlock(endBlock) && Editor.withoutNormalizing(editor, () => {
|
|
15405
|
+
if (Array.isArray(endBlock.markDefs) && endBlock.markDefs.length > 0) {
|
|
15406
|
+
const oldDefs = Array.isArray(startBlock.markDefs) && startBlock.markDefs || [], newMarkDefs = [...new Map([...oldDefs, ...endBlock.markDefs].map((def) => [def._key, def])).values()];
|
|
15407
|
+
applySetNode(editor, {
|
|
15408
|
+
markDefs: newMarkDefs
|
|
15409
|
+
}, startBlockPath);
|
|
15410
|
+
}
|
|
15887
15411
|
const {
|
|
15888
15412
|
children: _,
|
|
15889
15413
|
...properties
|
|
15890
15414
|
} = endBlock;
|
|
15891
|
-
editor.
|
|
15892
|
-
|
|
15893
|
-
path: adjustedEndBlockPath,
|
|
15894
|
-
position: startBlock.children.length,
|
|
15895
|
-
properties
|
|
15896
|
-
});
|
|
15897
|
-
}
|
|
15415
|
+
applyMergeNode(editor, adjustedEndBlockPath, startBlock.children.length, properties);
|
|
15416
|
+
});
|
|
15898
15417
|
}
|
|
15899
15418
|
function deleteExpandedRange(editor, range2) {
|
|
15900
15419
|
const [start2, end2] = Range.edges(range2);
|
|
@@ -15910,12 +15429,7 @@ function insertTextBlockFragment(editor, block, at) {
|
|
|
15910
15429
|
text: _,
|
|
15911
15430
|
...properties
|
|
15912
15431
|
} = textNode;
|
|
15913
|
-
editor.
|
|
15914
|
-
type: "split_node",
|
|
15915
|
-
path: at.path,
|
|
15916
|
-
position: at.offset,
|
|
15917
|
-
properties
|
|
15918
|
-
});
|
|
15432
|
+
applySplitNode(editor, at.path, at.offset, properties);
|
|
15919
15433
|
}
|
|
15920
15434
|
}
|
|
15921
15435
|
const parentPath = Path.parent(at.path);
|
|
@@ -16082,11 +15596,7 @@ const moveBackwardOperationImplementation = ({
|
|
|
16082
15596
|
const destinationBlockIndex = operation.editor.blockIndexMap.get(destinationKey);
|
|
16083
15597
|
if (destinationBlockIndex === void 0)
|
|
16084
15598
|
throw new Error("Failed to get block index from block key");
|
|
16085
|
-
operation.editor
|
|
16086
|
-
type: "move_node",
|
|
16087
|
-
path: [originBlockIndex],
|
|
16088
|
-
newPath: [destinationBlockIndex]
|
|
16089
|
-
});
|
|
15599
|
+
applyMoveNode(operation.editor, [originBlockIndex], [destinationBlockIndex]);
|
|
16090
15600
|
}, moveForwardOperationImplementation = ({
|
|
16091
15601
|
operation
|
|
16092
15602
|
}) => {
|