@portabletext/editor 6.2.0 → 6.3.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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx, jsxs, Fragment
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react/compiler-runtime";
|
|
3
3
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
4
|
-
import React, { useRef, useEffect, useLayoutEffect, useState, createContext, useContext,
|
|
4
|
+
import React, { useRef, useEffect, useLayoutEffect, useState, createContext, useContext, useReducer, useCallback, useMemo, memo, forwardRef, Component, startTransition } from "react";
|
|
5
5
|
import rawDebug from "debug";
|
|
6
6
|
import { createKeyboardShortcut, code, underline, italic as italic$1, bold as bold$1, undo as undo$1, redo as redo$1 } from "@portabletext/keyboard-shortcuts";
|
|
7
7
|
import { getBlockEndPoint, getBlockStartPoint, getBlockKeyFromSelectionPoint, isSelectionCollapsed, isKeyedSegment, isEqualSelectionPoints, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, isListBlock, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject, isEqualPathSegments } from "./_chunks-es/util.slice-blocks.js";
|
|
@@ -44,10 +44,6 @@ const debug$1 = {
|
|
|
44
44
|
return Path.isPath(value.path) && isObject(value.node);
|
|
45
45
|
case "insert_text":
|
|
46
46
|
return typeof value.offset == "number" && typeof value.text == "string" && Path.isPath(value.path);
|
|
47
|
-
case "merge_node":
|
|
48
|
-
return typeof value.position == "number" && Path.isPath(value.path) && isObject(value.properties);
|
|
49
|
-
case "move_node":
|
|
50
|
-
return Path.isPath(value.path) && Path.isPath(value.newPath);
|
|
51
47
|
case "remove_node":
|
|
52
48
|
return Path.isPath(value.path) && isObject(value.node);
|
|
53
49
|
case "remove_text":
|
|
@@ -56,8 +52,6 @@ const debug$1 = {
|
|
|
56
52
|
return Path.isPath(value.path) && isObject(value.properties) && isObject(value.newProperties);
|
|
57
53
|
case "set_selection":
|
|
58
54
|
return value.properties === null && Range.isRange(value.newProperties) || value.newProperties === null && Range.isRange(value.properties) || isObject(value.properties) && isObject(value.newProperties);
|
|
59
|
-
case "split_node":
|
|
60
|
-
return Path.isPath(value.path) && typeof value.position == "number" && isObject(value.properties);
|
|
61
55
|
default:
|
|
62
56
|
return !1;
|
|
63
57
|
}
|
|
@@ -77,32 +71,6 @@ const debug$1 = {
|
|
|
77
71
|
...op,
|
|
78
72
|
type: "remove_text"
|
|
79
73
|
};
|
|
80
|
-
case "merge_node":
|
|
81
|
-
return {
|
|
82
|
-
...op,
|
|
83
|
-
type: "split_node",
|
|
84
|
-
path: Path.previous(op.path)
|
|
85
|
-
};
|
|
86
|
-
case "move_node": {
|
|
87
|
-
const {
|
|
88
|
-
newPath,
|
|
89
|
-
path: path2
|
|
90
|
-
} = op;
|
|
91
|
-
if (Path.equals(newPath, path2))
|
|
92
|
-
return op;
|
|
93
|
-
if (Path.isSibling(path2, newPath))
|
|
94
|
-
return {
|
|
95
|
-
...op,
|
|
96
|
-
path: newPath,
|
|
97
|
-
newPath: path2
|
|
98
|
-
};
|
|
99
|
-
const inversePath = Path.transform(path2, op), inverseNewPath = Path.transform(Path.next(path2), op);
|
|
100
|
-
return {
|
|
101
|
-
...op,
|
|
102
|
-
path: inversePath,
|
|
103
|
-
newPath: inverseNewPath
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
74
|
case "remove_node":
|
|
107
75
|
return {
|
|
108
76
|
...op,
|
|
@@ -143,12 +111,6 @@ const debug$1 = {
|
|
|
143
111
|
newProperties: properties
|
|
144
112
|
};
|
|
145
113
|
}
|
|
146
|
-
case "split_node":
|
|
147
|
-
return {
|
|
148
|
-
...op,
|
|
149
|
-
type: "merge_node",
|
|
150
|
-
path: Path.next(op.path)
|
|
151
|
-
};
|
|
152
114
|
}
|
|
153
115
|
}
|
|
154
116
|
}, Range = {
|
|
@@ -505,14 +467,11 @@ const debug$1 = {
|
|
|
505
467
|
}, PathRef = {
|
|
506
468
|
transform(ref, op) {
|
|
507
469
|
const {
|
|
508
|
-
current
|
|
509
|
-
affinity
|
|
470
|
+
current
|
|
510
471
|
} = ref;
|
|
511
472
|
if (current == null)
|
|
512
473
|
return;
|
|
513
|
-
const path2 = Path.transform(current, op
|
|
514
|
-
affinity
|
|
515
|
-
});
|
|
474
|
+
const path2 = Path.transform(current, op);
|
|
516
475
|
ref.current = path2, path2 == null && ref.unref();
|
|
517
476
|
}
|
|
518
477
|
}, Path = {
|
|
@@ -595,9 +554,6 @@ const debug$1 = {
|
|
|
595
554
|
switch (operation.type) {
|
|
596
555
|
case "insert_node":
|
|
597
556
|
case "remove_node":
|
|
598
|
-
case "merge_node":
|
|
599
|
-
case "split_node":
|
|
600
|
-
case "move_node":
|
|
601
557
|
return !0;
|
|
602
558
|
default:
|
|
603
559
|
return !1;
|
|
@@ -616,12 +572,10 @@ const debug$1 = {
|
|
|
616
572
|
throw new Error(`Cannot get the previous path of a first child path [${path2}] because it would result in a negative index.`);
|
|
617
573
|
return path2.slice(0, -1).concat(last - 1);
|
|
618
574
|
},
|
|
619
|
-
transform(path2, operation
|
|
575
|
+
transform(path2, operation) {
|
|
620
576
|
if (!path2)
|
|
621
577
|
return null;
|
|
622
|
-
const p = [...path2]
|
|
623
|
-
affinity = "forward"
|
|
624
|
-
} = options;
|
|
578
|
+
const p = [...path2];
|
|
625
579
|
if (path2.length === 0)
|
|
626
580
|
return p;
|
|
627
581
|
switch (operation.type) {
|
|
@@ -641,40 +595,6 @@ const debug$1 = {
|
|
|
641
595
|
Path.endsBefore(op, p) && (p[op.length - 1] = p[op.length - 1] - 1);
|
|
642
596
|
break;
|
|
643
597
|
}
|
|
644
|
-
case "merge_node": {
|
|
645
|
-
const {
|
|
646
|
-
path: op,
|
|
647
|
-
position
|
|
648
|
-
} = operation;
|
|
649
|
-
Path.equals(op, p) || Path.endsBefore(op, p) ? p[op.length - 1] = p[op.length - 1] - 1 : Path.isAncestor(op, p) && (p[op.length - 1] = p[op.length - 1] - 1, p[op.length] = p[op.length] + position);
|
|
650
|
-
break;
|
|
651
|
-
}
|
|
652
|
-
case "split_node": {
|
|
653
|
-
const {
|
|
654
|
-
path: op,
|
|
655
|
-
position
|
|
656
|
-
} = operation;
|
|
657
|
-
if (Path.equals(op, p)) {
|
|
658
|
-
if (affinity === "forward")
|
|
659
|
-
p[p.length - 1] = p[p.length - 1] + 1;
|
|
660
|
-
else if (affinity !== "backward")
|
|
661
|
-
return null;
|
|
662
|
-
} else Path.endsBefore(op, p) ? p[op.length - 1] = p[op.length - 1] + 1 : Path.isAncestor(op, p) && path2[op.length] >= position && (p[op.length - 1] = p[op.length - 1] + 1, p[op.length] = p[op.length] - position);
|
|
663
|
-
break;
|
|
664
|
-
}
|
|
665
|
-
case "move_node": {
|
|
666
|
-
const {
|
|
667
|
-
path: op,
|
|
668
|
-
newPath: onp
|
|
669
|
-
} = operation;
|
|
670
|
-
if (Path.equals(op, onp))
|
|
671
|
-
return p;
|
|
672
|
-
if (Path.isAncestor(op, p) || Path.equals(op, p)) {
|
|
673
|
-
const copy = onp.slice();
|
|
674
|
-
return Path.endsBefore(op, onp) && op.length < onp.length && (copy[op.length - 1] = copy[op.length - 1] - 1), copy.concat(p.slice(op.length));
|
|
675
|
-
} else Path.isSibling(op, onp) && (Path.isAncestor(onp, p) || Path.equals(onp, p)) ? Path.endsBefore(op, p) ? p[op.length - 1] = p[op.length - 1] - 1 : p[op.length - 1] = p[op.length - 1] + 1 : Path.endsBefore(onp, p) || Path.equals(onp, p) || Path.isAncestor(onp, p) ? (Path.endsBefore(op, p) && (p[op.length - 1] = p[op.length - 1] - 1), p[onp.length - 1] = p[onp.length - 1] + 1) : Path.endsBefore(op, p) && (Path.equals(onp, p) && (p[onp.length - 1] = p[onp.length - 1] + 1), p[op.length - 1] = p[op.length - 1] - 1);
|
|
676
|
-
break;
|
|
677
|
-
}
|
|
678
598
|
}
|
|
679
599
|
return p;
|
|
680
600
|
}
|
|
@@ -719,19 +639,14 @@ const debug$1 = {
|
|
|
719
639
|
offset
|
|
720
640
|
} = point2;
|
|
721
641
|
switch (op.type) {
|
|
722
|
-
case "insert_node":
|
|
723
|
-
|
|
724
|
-
path2 = Path.transform(path2, op, options);
|
|
642
|
+
case "insert_node": {
|
|
643
|
+
path2 = Path.transform(path2, op);
|
|
725
644
|
break;
|
|
726
645
|
}
|
|
727
646
|
case "insert_text": {
|
|
728
647
|
Path.equals(op.path, path2) && (op.offset < offset || op.offset === offset && affinity === "forward") && (offset += op.text.length);
|
|
729
648
|
break;
|
|
730
649
|
}
|
|
731
|
-
case "merge_node": {
|
|
732
|
-
Path.equals(op.path, path2) && (offset += op.position), path2 = Path.transform(path2, op, options);
|
|
733
|
-
break;
|
|
734
|
-
}
|
|
735
650
|
case "remove_text": {
|
|
736
651
|
Path.equals(op.path, path2) && op.offset <= offset && (offset -= Math.min(offset - op.offset, op.text.length));
|
|
737
652
|
break;
|
|
@@ -739,19 +654,7 @@ const debug$1 = {
|
|
|
739
654
|
case "remove_node": {
|
|
740
655
|
if (Path.equals(op.path, path2) || Path.isAncestor(op.path, path2))
|
|
741
656
|
return null;
|
|
742
|
-
path2 = Path.transform(path2, op
|
|
743
|
-
break;
|
|
744
|
-
}
|
|
745
|
-
case "split_node": {
|
|
746
|
-
if (Path.equals(op.path, path2)) {
|
|
747
|
-
if (op.position === offset && affinity == null)
|
|
748
|
-
return null;
|
|
749
|
-
(op.position < offset || op.position === offset && affinity === "forward") && (offset -= op.position, path2 = Path.transform(path2, op, {
|
|
750
|
-
...options,
|
|
751
|
-
affinity: "forward"
|
|
752
|
-
}));
|
|
753
|
-
} else
|
|
754
|
-
path2 = Path.transform(path2, op, options);
|
|
657
|
+
path2 = Path.transform(path2, op);
|
|
755
658
|
break;
|
|
756
659
|
}
|
|
757
660
|
default:
|
|
@@ -1413,38 +1316,38 @@ const apply$1 = (editor, op) => {
|
|
|
1413
1316
|
} = editor;
|
|
1414
1317
|
return selection ? Node$1.fragment(editor, selection, editor.schema) : [];
|
|
1415
1318
|
};
|
|
1416
|
-
function applyMergeNode(editor, path2, position
|
|
1417
|
-
const node2 = Node$1.get(editor, path2, editor.schema), prevPath = Path.previous(path2)
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
position
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
const result = Point.transform(point2, mergeOp);
|
|
1435
|
-
result && (sel[key] = result);
|
|
1319
|
+
function applyMergeNode(editor, path2, position) {
|
|
1320
|
+
const node2 = Node$1.get(editor, path2, editor.schema), prevPath = Path.previous(path2);
|
|
1321
|
+
for (const ref of Editor.pathRefs(editor)) {
|
|
1322
|
+
const current = ref.current;
|
|
1323
|
+
current && (ref.current = transformPathForMerge(current, path2, position));
|
|
1324
|
+
}
|
|
1325
|
+
for (const ref of Editor.pointRefs(editor)) {
|
|
1326
|
+
const current = ref.current;
|
|
1327
|
+
current && (ref.current = transformPointForMerge(current, path2, position));
|
|
1328
|
+
}
|
|
1329
|
+
for (const ref of Editor.rangeRefs(editor)) {
|
|
1330
|
+
const current = ref.current;
|
|
1331
|
+
if (current) {
|
|
1332
|
+
const anchor = transformPointForMerge(current.anchor, path2, position), focus = transformPointForMerge(current.focus, path2, position);
|
|
1333
|
+
anchor && focus ? ref.current = {
|
|
1334
|
+
anchor,
|
|
1335
|
+
focus
|
|
1336
|
+
} : (ref.current = null, ref.unref());
|
|
1436
1337
|
}
|
|
1437
|
-
|
|
1338
|
+
}
|
|
1339
|
+
if (editor.selection) {
|
|
1340
|
+
const anchor = transformPointForMerge(editor.selection.anchor, path2, position), focus = transformPointForMerge(editor.selection.focus, path2, position);
|
|
1341
|
+
anchor && focus && (editor.selection = {
|
|
1342
|
+
anchor,
|
|
1343
|
+
focus
|
|
1344
|
+
});
|
|
1438
1345
|
}
|
|
1439
1346
|
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
1440
1347
|
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
1441
1348
|
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,
|
|
1443
|
-
const sel = savedPendingSelection, anchor =
|
|
1444
|
-
affinity: "backward"
|
|
1445
|
-
}), focus = Point.transform(sel.focus, mergeOp, {
|
|
1446
|
-
affinity: "backward"
|
|
1447
|
-
});
|
|
1349
|
+
if (Array.isArray(savedPendingDiffs) && savedPendingDiffs.length > 0 && (editorAny.pendingDiffs = savedPendingDiffs.map((textDiff) => transformTextDiffForMerge(textDiff, path2, position)).filter(Boolean)), savedPendingSelection && typeof savedPendingSelection == "object" && "anchor" in savedPendingSelection && "focus" in savedPendingSelection) {
|
|
1350
|
+
const sel = savedPendingSelection, anchor = transformPointForMerge(sel.anchor, path2, position), focus = transformPointForMerge(sel.focus, path2, position);
|
|
1448
1351
|
editorAny.pendingSelection = anchor && focus ? {
|
|
1449
1352
|
anchor,
|
|
1450
1353
|
focus
|
|
@@ -1452,20 +1355,14 @@ function applyMergeNode(editor, path2, position, properties) {
|
|
|
1452
1355
|
}
|
|
1453
1356
|
if (savedPendingAction && typeof savedPendingAction == "object" && "at" in savedPendingAction) {
|
|
1454
1357
|
const action = savedPendingAction;
|
|
1455
|
-
if (
|
|
1456
|
-
const at =
|
|
1457
|
-
affinity: "backward"
|
|
1458
|
-
});
|
|
1358
|
+
if ("offset" in action.at && typeof action.at.offset == "number") {
|
|
1359
|
+
const at = transformPointForMerge(action.at, path2, position);
|
|
1459
1360
|
editorAny.pendingAction = at ? {
|
|
1460
1361
|
...action,
|
|
1461
1362
|
at
|
|
1462
1363
|
} : null;
|
|
1463
1364
|
} else if (Range.isRange(action.at)) {
|
|
1464
|
-
const anchor =
|
|
1465
|
-
affinity: "backward"
|
|
1466
|
-
}), focus = Point.transform(action.at.focus, mergeOp, {
|
|
1467
|
-
affinity: "backward"
|
|
1468
|
-
});
|
|
1365
|
+
const anchor = transformPointForMerge(action.at.anchor, path2, position), focus = transformPointForMerge(action.at.focus, path2, position);
|
|
1469
1366
|
editorAny.pendingAction = anchor && focus ? {
|
|
1470
1367
|
...action,
|
|
1471
1368
|
at: {
|
|
@@ -1516,14 +1413,14 @@ function applyMergeNode(editor, path2, position, properties) {
|
|
|
1516
1413
|
editorAny.pendingDiffs = preTransformedPendingDiffs, editorAny.pendingSelection = preTransformedPendingSelection, editorAny.pendingAction = preTransformedPendingAction;
|
|
1517
1414
|
}
|
|
1518
1415
|
}
|
|
1519
|
-
function transformTextDiffForMerge(textDiff,
|
|
1416
|
+
function transformTextDiffForMerge(textDiff, mergePath, position) {
|
|
1520
1417
|
const {
|
|
1521
1418
|
path: path2,
|
|
1522
1419
|
diff: diff2,
|
|
1523
1420
|
id
|
|
1524
1421
|
} = textDiff;
|
|
1525
|
-
if (!Path.equals(
|
|
1526
|
-
const newPath =
|
|
1422
|
+
if (!Path.equals(mergePath, path2)) {
|
|
1423
|
+
const newPath = transformPathForMerge(path2, mergePath, position);
|
|
1527
1424
|
return newPath ? {
|
|
1528
1425
|
diff: diff2,
|
|
1529
1426
|
id,
|
|
@@ -1532,12 +1429,26 @@ function transformTextDiffForMerge(textDiff, op) {
|
|
|
1532
1429
|
}
|
|
1533
1430
|
return {
|
|
1534
1431
|
diff: {
|
|
1535
|
-
start: diff2.start +
|
|
1536
|
-
end: diff2.end +
|
|
1432
|
+
start: diff2.start + position,
|
|
1433
|
+
end: diff2.end + position,
|
|
1537
1434
|
text: diff2.text
|
|
1538
1435
|
},
|
|
1539
1436
|
id,
|
|
1540
|
-
path:
|
|
1437
|
+
path: transformPathForMerge(path2, mergePath, position)
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
function transformPathForMerge(path2, mergePath, position) {
|
|
1441
|
+
const p = [...path2];
|
|
1442
|
+
return Path.equals(mergePath, p) || Path.endsBefore(mergePath, p) ? p[mergePath.length - 1] = p[mergePath.length - 1] - 1 : Path.isAncestor(mergePath, p) && (p[mergePath.length - 1] = p[mergePath.length - 1] - 1, p[mergePath.length] = p[mergePath.length] + position), p;
|
|
1443
|
+
}
|
|
1444
|
+
function transformPointForMerge(point2, mergePath, position) {
|
|
1445
|
+
let {
|
|
1446
|
+
path: path2,
|
|
1447
|
+
offset
|
|
1448
|
+
} = point2;
|
|
1449
|
+
return Path.equals(mergePath, path2) && (offset += position), path2 = transformPathForMerge(path2, mergePath, position), {
|
|
1450
|
+
path: path2,
|
|
1451
|
+
offset
|
|
1541
1452
|
};
|
|
1542
1453
|
}
|
|
1543
1454
|
const normalizeNode = (editor, entry) => {
|
|
@@ -1572,11 +1483,8 @@ const normalizeNode = (editor, entry) => {
|
|
|
1572
1483
|
else if (Text$1.equals(child, prev, {
|
|
1573
1484
|
loose: !0
|
|
1574
1485
|
})) {
|
|
1575
|
-
const mergePath = path2.concat(n2)
|
|
1576
|
-
|
|
1577
|
-
...properties
|
|
1578
|
-
} = child;
|
|
1579
|
-
applyMergeNode(editor, mergePath, prev.text.length, properties), element = Node$1.get(editor, path2, editor.schema), n2--;
|
|
1486
|
+
const mergePath = path2.concat(n2);
|
|
1487
|
+
applyMergeNode(editor, mergePath, prev.text.length), element = Node$1.get(editor, path2, editor.schema), n2--;
|
|
1580
1488
|
}
|
|
1581
1489
|
}
|
|
1582
1490
|
} else if (Element$2.isElement(child, editor.schema))
|
|
@@ -2175,26 +2083,44 @@ const previous = (editor, options = {}) => {
|
|
|
2175
2083
|
}
|
|
2176
2084
|
Editor.normalize(editor);
|
|
2177
2085
|
}, 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;
|
|
2086
|
+
function rangeRefAffinities(range2, affinity) {
|
|
2087
|
+
if (affinity === "inward") {
|
|
2088
|
+
const isCollapsed = Range.isCollapsed(range2);
|
|
2089
|
+
if (Range.isForward(range2)) {
|
|
2090
|
+
const anchorAffinity = "forward";
|
|
2091
|
+
return [anchorAffinity, isCollapsed ? anchorAffinity : "backward"];
|
|
2092
|
+
} else {
|
|
2093
|
+
const anchorAffinity = "backward";
|
|
2094
|
+
return [anchorAffinity, isCollapsed ? anchorAffinity : "forward"];
|
|
2095
|
+
}
|
|
2096
|
+
} else return affinity === "outward" ? Range.isForward(range2) ? ["backward", "forward"] : ["forward", "backward"] : [affinity, affinity];
|
|
2097
|
+
}
|
|
2178
2098
|
function applySplitNode(editor, path2, position, properties) {
|
|
2179
|
-
const node2 = Node$1.get(editor, path2, editor.schema)
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
position,
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2099
|
+
const node2 = Node$1.get(editor, path2, editor.schema);
|
|
2100
|
+
for (const ref of Editor.pathRefs(editor)) {
|
|
2101
|
+
const current = ref.current;
|
|
2102
|
+
current && (ref.current = transformPathForSplit(current, path2, position, ref.affinity ?? "forward"));
|
|
2103
|
+
}
|
|
2104
|
+
for (const ref of Editor.pointRefs(editor)) {
|
|
2105
|
+
const current = ref.current;
|
|
2106
|
+
current && (ref.current = transformPointForSplit(current, path2, position, ref.affinity ?? "forward"));
|
|
2107
|
+
}
|
|
2108
|
+
for (const ref of Editor.rangeRefs(editor)) {
|
|
2109
|
+
const current = ref.current;
|
|
2110
|
+
if (current) {
|
|
2111
|
+
const [anchorAffinity, focusAffinity] = rangeRefAffinities(current, ref.affinity), anchor = transformPointForSplit(current.anchor, path2, position, anchorAffinity ?? "forward"), focus = transformPointForSplit(current.focus, path2, position, focusAffinity ?? "forward");
|
|
2112
|
+
anchor && focus ? ref.current = {
|
|
2113
|
+
anchor,
|
|
2114
|
+
focus
|
|
2115
|
+
} : (ref.current = null, ref.unref());
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2191
2118
|
if (editor.selection) {
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
editor.selection = sel;
|
|
2119
|
+
const anchor = transformPointForSplit(editor.selection.anchor, path2, position, "forward"), focus = transformPointForSplit(editor.selection.focus, path2, position, "forward");
|
|
2120
|
+
anchor && focus && (editor.selection = {
|
|
2121
|
+
anchor,
|
|
2122
|
+
focus
|
|
2123
|
+
});
|
|
2198
2124
|
}
|
|
2199
2125
|
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
2200
2126
|
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
@@ -2244,6 +2170,20 @@ function applySplitNode(editor, path2, position, properties) {
|
|
|
2244
2170
|
Editor.rangeRefs(editor).add(ref);
|
|
2245
2171
|
}
|
|
2246
2172
|
}
|
|
2173
|
+
function transformPathForSplit(path2, splitPath, position, affinity = "forward") {
|
|
2174
|
+
const p = [...path2];
|
|
2175
|
+
return Path.equals(splitPath, p) ? affinity === "forward" && (p[p.length - 1] = p[p.length - 1] + 1) : Path.endsBefore(splitPath, p) ? p[splitPath.length - 1] = p[splitPath.length - 1] + 1 : Path.isAncestor(splitPath, p) && path2[splitPath.length] >= position && (p[splitPath.length - 1] = p[splitPath.length - 1] + 1, p[splitPath.length] = p[splitPath.length] - position), p;
|
|
2176
|
+
}
|
|
2177
|
+
function transformPointForSplit(point2, splitPath, position, affinity = "forward") {
|
|
2178
|
+
let {
|
|
2179
|
+
path: path2,
|
|
2180
|
+
offset
|
|
2181
|
+
} = point2;
|
|
2182
|
+
return Path.equals(splitPath, path2) ? (position < offset || position === offset && affinity === "forward") && (offset -= position, path2 = transformPathForSplit(path2, splitPath, position, "forward")) : path2 = transformPathForSplit(path2, splitPath, position, affinity), {
|
|
2183
|
+
path: path2,
|
|
2184
|
+
offset
|
|
2185
|
+
};
|
|
2186
|
+
}
|
|
2247
2187
|
const insertNodes = (editor, nodes2, options = {}) => {
|
|
2248
2188
|
Editor.withoutNormalizing(editor, () => {
|
|
2249
2189
|
const {
|
|
@@ -2486,55 +2426,6 @@ const insertNodes = (editor, nodes2, options = {}) => {
|
|
|
2486
2426
|
});
|
|
2487
2427
|
}
|
|
2488
2428
|
};
|
|
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
2429
|
function applySetNode(editor, props, path2) {
|
|
2539
2430
|
const node2 = Node$1.get(editor, path2, editor.schema), propsRecord = props, properties = {}, newProperties = {};
|
|
2540
2431
|
for (const key of Object.keys(propsRecord))
|
|
@@ -2698,22 +2589,26 @@ const deleteText = (editor, options = {}) => {
|
|
|
2698
2589
|
mode: "highest",
|
|
2699
2590
|
match: (n2) => levels2.includes(n2) && hasSingleChildNest(n2)
|
|
2700
2591
|
}), emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
|
|
2701
|
-
let
|
|
2702
|
-
if (Text$1.isText(mergeNode, editor.schema) && Text$1.isText(prevNode, editor.schema))
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
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
|
|
2592
|
+
let position;
|
|
2593
|
+
if (Text$1.isText(mergeNode, editor.schema) && Text$1.isText(prevNode, editor.schema))
|
|
2594
|
+
position = prevNode.text.length;
|
|
2595
|
+
else if (Element$2.isElement(mergeNode, editor.schema) && Element$2.isElement(prevNode, editor.schema))
|
|
2596
|
+
position = prevNode.children.length;
|
|
2597
|
+
else
|
|
2715
2598
|
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
|
|
2599
|
+
if (!isPreviousSibling) {
|
|
2600
|
+
const moveNode = Node$1.get(editor, mergePath, editor.schema);
|
|
2601
|
+
editor.apply({
|
|
2602
|
+
type: "remove_node",
|
|
2603
|
+
path: mergePath,
|
|
2604
|
+
node: moveNode
|
|
2605
|
+
}), editor.apply({
|
|
2606
|
+
type: "insert_node",
|
|
2607
|
+
path: newPath,
|
|
2608
|
+
node: moveNode
|
|
2609
|
+
});
|
|
2610
|
+
}
|
|
2611
|
+
if (emptyRef && Transforms.removeNodes(editor, {
|
|
2717
2612
|
at: emptyRef.current,
|
|
2718
2613
|
voids
|
|
2719
2614
|
}), Editor.shouldMergeNodesRemovePrevNode(editor, prev, current))
|
|
@@ -2729,7 +2624,7 @@ const deleteText = (editor, options = {}) => {
|
|
|
2729
2624
|
markDefs: newMarkDefs
|
|
2730
2625
|
}, targetPath);
|
|
2731
2626
|
}
|
|
2732
|
-
applyMergeNode(pteEditor, newPath, position
|
|
2627
|
+
applyMergeNode(pteEditor, newPath, position);
|
|
2733
2628
|
}
|
|
2734
2629
|
emptyRef && emptyRef.unref();
|
|
2735
2630
|
}
|
|
@@ -3497,7 +3392,7 @@ function transformPendingPoint(editor, point2, op) {
|
|
|
3497
3392
|
}, transformed = Point.transform(anchor, op, {
|
|
3498
3393
|
affinity: "backward"
|
|
3499
3394
|
});
|
|
3500
|
-
return transformed ?
|
|
3395
|
+
return transformed ? {
|
|
3501
3396
|
path: transformed.path,
|
|
3502
3397
|
offset: transformed.offset + diff2.text.length - diff2.end + diff2.start
|
|
3503
3398
|
} : null;
|
|
@@ -5200,480 +5095,6 @@ const MUTATION_OBSERVER_CONFIG$1 = {
|
|
|
5200
5095
|
}));
|
|
5201
5096
|
return useMutationObserver(node2, inputManager.handleDomMutations, MUTATION_OBSERVER_CONFIG$1), editor.scheduleFlush = inputManager.scheduleFlush, isMounted && inputManager.flush(), inputManager;
|
|
5202
5097
|
} : () => null;
|
|
5203
|
-
class ChildrenHelper {
|
|
5204
|
-
/**
|
|
5205
|
-
* Sparse array of Slate node keys, each index corresponding to an index in
|
|
5206
|
-
* the children array
|
|
5207
|
-
*
|
|
5208
|
-
* Fetching the key for a Slate node is expensive, so we cache them here.
|
|
5209
|
-
*/
|
|
5210
|
-
/**
|
|
5211
|
-
* The index of the next node to be read in the children array
|
|
5212
|
-
*/
|
|
5213
|
-
constructor(editor, children) {
|
|
5214
|
-
this.editor = editor, this.children = children, this.cachedKeys = new Array(children.length), this.pointerIndex = 0;
|
|
5215
|
-
}
|
|
5216
|
-
/**
|
|
5217
|
-
* Read a given number of nodes, advancing the pointer by that amount
|
|
5218
|
-
*/
|
|
5219
|
-
read(n2) {
|
|
5220
|
-
if (n2 === 1)
|
|
5221
|
-
return [this.children[this.pointerIndex++]];
|
|
5222
|
-
const slicedChildren = this.remaining(n2);
|
|
5223
|
-
return this.pointerIndex += n2, slicedChildren;
|
|
5224
|
-
}
|
|
5225
|
-
/**
|
|
5226
|
-
* Get the remaining children without advancing the pointer
|
|
5227
|
-
*
|
|
5228
|
-
* @param [maxChildren] Limit the number of children returned.
|
|
5229
|
-
*/
|
|
5230
|
-
remaining(maxChildren) {
|
|
5231
|
-
return maxChildren === void 0 ? this.children.slice(this.pointerIndex) : this.children.slice(this.pointerIndex, this.pointerIndex + maxChildren);
|
|
5232
|
-
}
|
|
5233
|
-
/**
|
|
5234
|
-
* Whether all children have been read
|
|
5235
|
-
*/
|
|
5236
|
-
get reachedEnd() {
|
|
5237
|
-
return this.pointerIndex >= this.children.length;
|
|
5238
|
-
}
|
|
5239
|
-
/**
|
|
5240
|
-
* Determine whether a node with a given key appears in the unread part of the
|
|
5241
|
-
* children array, and return its index relative to the current pointer if so
|
|
5242
|
-
*
|
|
5243
|
-
* Searching for the node object itself using indexOf is most efficient, but
|
|
5244
|
-
* will fail to locate nodes that have been modified. In this case, nodes
|
|
5245
|
-
* should be identified by their keys instead.
|
|
5246
|
-
*
|
|
5247
|
-
* Searching an array of keys using indexOf is very inefficient since fetching
|
|
5248
|
-
* the keys for all children in advance is very slow. Insead, if the node
|
|
5249
|
-
* search fails to return a value, fetch the keys of each remaining child one
|
|
5250
|
-
* by one and compare it to the known key.
|
|
5251
|
-
*/
|
|
5252
|
-
lookAhead(node2, key) {
|
|
5253
|
-
const elementResult = this.children.indexOf(node2, this.pointerIndex);
|
|
5254
|
-
if (elementResult > -1)
|
|
5255
|
-
return elementResult - this.pointerIndex;
|
|
5256
|
-
for (let i = this.pointerIndex; i < this.children.length; i++) {
|
|
5257
|
-
const candidateNode = this.children[i];
|
|
5258
|
-
if (this.findKey(candidateNode, i) === key)
|
|
5259
|
-
return i - this.pointerIndex;
|
|
5260
|
-
}
|
|
5261
|
-
return -1;
|
|
5262
|
-
}
|
|
5263
|
-
/**
|
|
5264
|
-
* Convert an array of Slate nodes to an array of chunk leaves, each
|
|
5265
|
-
* containing the node and its key
|
|
5266
|
-
*/
|
|
5267
|
-
toChunkLeaves(nodes2, startIndex) {
|
|
5268
|
-
return nodes2.map((node2, i) => ({
|
|
5269
|
-
type: "leaf",
|
|
5270
|
-
node: node2,
|
|
5271
|
-
key: this.findKey(node2, startIndex + i),
|
|
5272
|
-
index: startIndex + i
|
|
5273
|
-
}));
|
|
5274
|
-
}
|
|
5275
|
-
/**
|
|
5276
|
-
* Get the key for a Slate node, cached using the node's index
|
|
5277
|
-
*/
|
|
5278
|
-
findKey(node2, index) {
|
|
5279
|
-
const cachedKey = this.cachedKeys[index];
|
|
5280
|
-
if (cachedKey)
|
|
5281
|
-
return cachedKey;
|
|
5282
|
-
const key = ReactEditor.findKey(this.editor, node2);
|
|
5283
|
-
return this.cachedKeys[index] = key, key;
|
|
5284
|
-
}
|
|
5285
|
-
}
|
|
5286
|
-
class ChunkTreeHelper {
|
|
5287
|
-
/**
|
|
5288
|
-
* The root of the chunk tree
|
|
5289
|
-
*/
|
|
5290
|
-
/**
|
|
5291
|
-
* The ideal size of a chunk
|
|
5292
|
-
*/
|
|
5293
|
-
/**
|
|
5294
|
-
* Whether debug mode is enabled
|
|
5295
|
-
*
|
|
5296
|
-
* If enabled, the pointer state will be checked for internal consistency
|
|
5297
|
-
* after each mutating operation.
|
|
5298
|
-
*/
|
|
5299
|
-
/**
|
|
5300
|
-
* Whether the traversal has reached the end of the chunk tree
|
|
5301
|
-
*
|
|
5302
|
-
* When this is true, the pointerChunk and pointerIndex point to the last
|
|
5303
|
-
* top-level node in the chunk tree, although pointerNode returns null.
|
|
5304
|
-
*/
|
|
5305
|
-
/**
|
|
5306
|
-
* The chunk containing the current node
|
|
5307
|
-
*/
|
|
5308
|
-
/**
|
|
5309
|
-
* The index of the current node within pointerChunk
|
|
5310
|
-
*
|
|
5311
|
-
* Can be -1 to indicate that the pointer is before the start of the tree.
|
|
5312
|
-
*/
|
|
5313
|
-
/**
|
|
5314
|
-
* Similar to a Slate path; tracks the path of pointerChunk relative to the
|
|
5315
|
-
* root.
|
|
5316
|
-
*
|
|
5317
|
-
* Used to move the pointer from the current chunk to the parent chunk more
|
|
5318
|
-
* efficiently.
|
|
5319
|
-
*/
|
|
5320
|
-
/**
|
|
5321
|
-
* Indexing the current chunk's children has a slight time cost, which adds up
|
|
5322
|
-
* when traversing very large trees, so the current node is cached.
|
|
5323
|
-
*
|
|
5324
|
-
* A value of undefined means that the current node is not cached. This
|
|
5325
|
-
* property must be set to undefined whenever the pointer is moved, unless
|
|
5326
|
-
* the pointer is guaranteed to point to the same node that it did previously.
|
|
5327
|
-
*/
|
|
5328
|
-
constructor(chunkTree, {
|
|
5329
|
-
chunkSize,
|
|
5330
|
-
debug: debug2
|
|
5331
|
-
}) {
|
|
5332
|
-
this.root = chunkTree, this.chunkSize = chunkSize, this.debug = debug2 ?? !1, this.pointerChunk = chunkTree, this.pointerIndex = -1, this.pointerIndexStack = [], this.reachedEnd = !1, this.validateState();
|
|
5333
|
-
}
|
|
5334
|
-
/**
|
|
5335
|
-
* Move the pointer to the next leaf in the chunk tree
|
|
5336
|
-
*/
|
|
5337
|
-
readLeaf() {
|
|
5338
|
-
if (this.reachedEnd)
|
|
5339
|
-
return null;
|
|
5340
|
-
for (; ; )
|
|
5341
|
-
if (this.pointerIndex + 1 < this.pointerSiblings.length) {
|
|
5342
|
-
this.pointerIndex++, this.cachedPointerNode = void 0;
|
|
5343
|
-
break;
|
|
5344
|
-
} else {
|
|
5345
|
-
if (this.pointerChunk.type === "root")
|
|
5346
|
-
return this.reachedEnd = !0, null;
|
|
5347
|
-
this.exitChunk();
|
|
5348
|
-
}
|
|
5349
|
-
return this.validateState(), this.enterChunkUntilLeaf(!1), this.pointerNode;
|
|
5350
|
-
}
|
|
5351
|
-
/**
|
|
5352
|
-
* Move the pointer to the previous leaf in the chunk tree
|
|
5353
|
-
*/
|
|
5354
|
-
returnToPreviousLeaf() {
|
|
5355
|
-
if (this.reachedEnd) {
|
|
5356
|
-
this.reachedEnd = !1, this.enterChunkUntilLeaf(!0);
|
|
5357
|
-
return;
|
|
5358
|
-
}
|
|
5359
|
-
for (; ; )
|
|
5360
|
-
if (this.pointerIndex >= 1) {
|
|
5361
|
-
this.pointerIndex--, this.cachedPointerNode = void 0;
|
|
5362
|
-
break;
|
|
5363
|
-
} else if (this.pointerChunk.type === "root") {
|
|
5364
|
-
this.pointerIndex = -1;
|
|
5365
|
-
return;
|
|
5366
|
-
} else
|
|
5367
|
-
this.exitChunk();
|
|
5368
|
-
this.validateState(), this.enterChunkUntilLeaf(!0);
|
|
5369
|
-
}
|
|
5370
|
-
/**
|
|
5371
|
-
* Insert leaves before the current leaf, leaving the pointer unchanged
|
|
5372
|
-
*/
|
|
5373
|
-
insertBefore(leaves) {
|
|
5374
|
-
this.returnToPreviousLeaf(), this.insertAfter(leaves), this.readLeaf();
|
|
5375
|
-
}
|
|
5376
|
-
/**
|
|
5377
|
-
* Insert leaves after the current leaf, leaving the pointer on the last
|
|
5378
|
-
* inserted leaf
|
|
5379
|
-
*
|
|
5380
|
-
* The insertion algorithm first checks for any chunk we're currently at the
|
|
5381
|
-
* end of that can receive additional leaves. Next, it tries to insert leaves
|
|
5382
|
-
* at the starts of any subsequent chunks.
|
|
5383
|
-
*
|
|
5384
|
-
* Any remaining leaves are passed to rawInsertAfter to be chunked and
|
|
5385
|
-
* inserted at the highest possible level.
|
|
5386
|
-
*/
|
|
5387
|
-
insertAfter(leaves) {
|
|
5388
|
-
if (leaves.length === 0)
|
|
5389
|
-
return;
|
|
5390
|
-
let beforeDepth = 0, afterDepth = 0;
|
|
5391
|
-
for (; this.pointerChunk.type === "chunk" && this.pointerIndex === this.pointerSiblings.length - 1; ) {
|
|
5392
|
-
const remainingCapacity = this.chunkSize - this.pointerSiblings.length, toInsertCount = Math.min(remainingCapacity, leaves.length);
|
|
5393
|
-
if (toInsertCount > 0) {
|
|
5394
|
-
const leavesToInsert = leaves.splice(0, toInsertCount);
|
|
5395
|
-
this.rawInsertAfter(leavesToInsert, beforeDepth);
|
|
5396
|
-
}
|
|
5397
|
-
this.exitChunk(), beforeDepth++;
|
|
5398
|
-
}
|
|
5399
|
-
if (leaves.length === 0)
|
|
5400
|
-
return;
|
|
5401
|
-
const rawInsertPointer = this.savePointer();
|
|
5402
|
-
let finalPointer = null;
|
|
5403
|
-
if (this.readLeaf())
|
|
5404
|
-
for (; this.pointerChunk.type === "chunk" && this.pointerIndex === 0; ) {
|
|
5405
|
-
const remainingCapacity = this.chunkSize - this.pointerSiblings.length, toInsertCount = Math.min(remainingCapacity, leaves.length);
|
|
5406
|
-
if (toInsertCount > 0) {
|
|
5407
|
-
const leavesToInsert = leaves.splice(-toInsertCount, toInsertCount);
|
|
5408
|
-
this.pointerIndex = -1, this.cachedPointerNode = void 0, this.rawInsertAfter(leavesToInsert, afterDepth), finalPointer || (finalPointer = this.savePointer());
|
|
5409
|
-
}
|
|
5410
|
-
this.exitChunk(), afterDepth++;
|
|
5411
|
-
}
|
|
5412
|
-
this.restorePointer(rawInsertPointer);
|
|
5413
|
-
const minDepth = Math.max(beforeDepth, afterDepth);
|
|
5414
|
-
this.rawInsertAfter(leaves, minDepth), finalPointer && this.restorePointer(finalPointer), this.validateState();
|
|
5415
|
-
}
|
|
5416
|
-
/**
|
|
5417
|
-
* Remove the current node and decrement the pointer, deleting any ancestor
|
|
5418
|
-
* chunk that becomes empty as a result
|
|
5419
|
-
*/
|
|
5420
|
-
remove() {
|
|
5421
|
-
this.pointerSiblings.splice(this.pointerIndex--, 1), this.cachedPointerNode = void 0, this.pointerSiblings.length === 0 && this.pointerChunk.type === "chunk" ? (this.exitChunk(), this.remove()) : this.invalidateChunk(), this.validateState();
|
|
5422
|
-
}
|
|
5423
|
-
/**
|
|
5424
|
-
* Add the current chunk and all ancestor chunks to the list of modified
|
|
5425
|
-
* chunks
|
|
5426
|
-
*/
|
|
5427
|
-
invalidateChunk() {
|
|
5428
|
-
for (let c2 = this.pointerChunk; c2.type === "chunk"; c2 = c2.parent)
|
|
5429
|
-
this.root.modifiedChunks.add(c2);
|
|
5430
|
-
}
|
|
5431
|
-
/**
|
|
5432
|
-
* Whether the pointer is at the start of the tree
|
|
5433
|
-
*/
|
|
5434
|
-
get atStart() {
|
|
5435
|
-
return this.pointerChunk.type === "root" && this.pointerIndex === -1;
|
|
5436
|
-
}
|
|
5437
|
-
/**
|
|
5438
|
-
* The siblings of the current node
|
|
5439
|
-
*/
|
|
5440
|
-
get pointerSiblings() {
|
|
5441
|
-
return this.pointerChunk.children;
|
|
5442
|
-
}
|
|
5443
|
-
/**
|
|
5444
|
-
* Get the current node (uncached)
|
|
5445
|
-
*
|
|
5446
|
-
* If the pointer is at the start or end of the document, returns null.
|
|
5447
|
-
*
|
|
5448
|
-
* Usually, the current node is a chunk leaf, although it can be a chunk
|
|
5449
|
-
* while insertions are in progress.
|
|
5450
|
-
*/
|
|
5451
|
-
getPointerNode() {
|
|
5452
|
-
return this.reachedEnd || this.pointerIndex === -1 ? null : this.pointerSiblings[this.pointerIndex] ?? null;
|
|
5453
|
-
}
|
|
5454
|
-
/**
|
|
5455
|
-
* Cached getter for the current node
|
|
5456
|
-
*/
|
|
5457
|
-
get pointerNode() {
|
|
5458
|
-
if (this.cachedPointerNode !== void 0)
|
|
5459
|
-
return this.cachedPointerNode;
|
|
5460
|
-
const pointerNode = this.getPointerNode();
|
|
5461
|
-
return this.cachedPointerNode = pointerNode, pointerNode;
|
|
5462
|
-
}
|
|
5463
|
-
/**
|
|
5464
|
-
* Get the path of a chunk relative to the root, returning null if the chunk
|
|
5465
|
-
* is not connected to the root
|
|
5466
|
-
*/
|
|
5467
|
-
getChunkPath(chunk) {
|
|
5468
|
-
const path2 = [];
|
|
5469
|
-
for (let c2 = chunk; c2.type === "chunk"; c2 = c2.parent) {
|
|
5470
|
-
const index = c2.parent.children.indexOf(c2);
|
|
5471
|
-
if (index === -1)
|
|
5472
|
-
return null;
|
|
5473
|
-
path2.unshift(index);
|
|
5474
|
-
}
|
|
5475
|
-
return path2;
|
|
5476
|
-
}
|
|
5477
|
-
/**
|
|
5478
|
-
* Save the current pointer to be restored later
|
|
5479
|
-
*/
|
|
5480
|
-
savePointer() {
|
|
5481
|
-
if (this.atStart)
|
|
5482
|
-
return "start";
|
|
5483
|
-
if (!this.pointerNode)
|
|
5484
|
-
throw new Error("Cannot save pointer when pointerNode is null");
|
|
5485
|
-
return {
|
|
5486
|
-
chunk: this.pointerChunk,
|
|
5487
|
-
node: this.pointerNode
|
|
5488
|
-
};
|
|
5489
|
-
}
|
|
5490
|
-
/**
|
|
5491
|
-
* Restore the pointer to a previous state
|
|
5492
|
-
*/
|
|
5493
|
-
restorePointer(savedPointer) {
|
|
5494
|
-
if (savedPointer === "start") {
|
|
5495
|
-
this.pointerChunk = this.root, this.pointerIndex = -1, this.pointerIndexStack = [], this.reachedEnd = !1, this.cachedPointerNode = void 0;
|
|
5496
|
-
return;
|
|
5497
|
-
}
|
|
5498
|
-
const {
|
|
5499
|
-
chunk,
|
|
5500
|
-
node: node2
|
|
5501
|
-
} = savedPointer, index = chunk.children.indexOf(node2);
|
|
5502
|
-
if (index === -1)
|
|
5503
|
-
throw new Error("Cannot restore point because saved node is no longer in saved chunk");
|
|
5504
|
-
const indexStack = this.getChunkPath(chunk);
|
|
5505
|
-
if (!indexStack)
|
|
5506
|
-
throw new Error("Cannot restore point because saved chunk is no longer connected to root");
|
|
5507
|
-
this.pointerChunk = chunk, this.pointerIndex = index, this.pointerIndexStack = indexStack, this.reachedEnd = !1, this.cachedPointerNode = node2, this.validateState();
|
|
5508
|
-
}
|
|
5509
|
-
/**
|
|
5510
|
-
* Assuming the current node is a chunk, move the pointer into that chunk
|
|
5511
|
-
*
|
|
5512
|
-
* @param end If true, place the pointer on the last node of the chunk.
|
|
5513
|
-
* Otherwise, place the pointer on the first node.
|
|
5514
|
-
*/
|
|
5515
|
-
enterChunk(end2) {
|
|
5516
|
-
if (this.pointerNode?.type !== "chunk")
|
|
5517
|
-
throw new Error("Cannot enter non-chunk");
|
|
5518
|
-
if (this.pointerIndexStack.push(this.pointerIndex), this.pointerChunk = this.pointerNode, this.pointerIndex = end2 ? this.pointerSiblings.length - 1 : 0, this.cachedPointerNode = void 0, this.validateState(), this.pointerChunk.children.length === 0)
|
|
5519
|
-
throw new Error("Cannot enter empty chunk");
|
|
5520
|
-
}
|
|
5521
|
-
/**
|
|
5522
|
-
* Assuming the current node is a chunk, move the pointer into that chunk
|
|
5523
|
-
* repeatedly until the current node is a leaf
|
|
5524
|
-
*
|
|
5525
|
-
* @param end If true, place the pointer on the last node of the chunk.
|
|
5526
|
-
* Otherwise, place the pointer on the first node.
|
|
5527
|
-
*/
|
|
5528
|
-
enterChunkUntilLeaf(end2) {
|
|
5529
|
-
for (; this.pointerNode?.type === "chunk"; )
|
|
5530
|
-
this.enterChunk(end2);
|
|
5531
|
-
}
|
|
5532
|
-
/**
|
|
5533
|
-
* Move the pointer to the parent chunk
|
|
5534
|
-
*/
|
|
5535
|
-
exitChunk() {
|
|
5536
|
-
if (this.pointerChunk.type === "root")
|
|
5537
|
-
throw new Error("Cannot exit root");
|
|
5538
|
-
const previousPointerChunk = this.pointerChunk;
|
|
5539
|
-
this.pointerChunk = previousPointerChunk.parent, this.pointerIndex = this.pointerIndexStack.pop(), this.cachedPointerNode = void 0, this.validateState();
|
|
5540
|
-
}
|
|
5541
|
-
/**
|
|
5542
|
-
* Insert leaves immediately after the current node, leaving the pointer on
|
|
5543
|
-
* the last inserted leaf
|
|
5544
|
-
*
|
|
5545
|
-
* Leaves are chunked according to the number of nodes already in the parent
|
|
5546
|
-
* plus the number of nodes being inserted, or the minimum depth if larger
|
|
5547
|
-
*/
|
|
5548
|
-
rawInsertAfter(leaves, minDepth) {
|
|
5549
|
-
if (leaves.length === 0)
|
|
5550
|
-
return;
|
|
5551
|
-
const groupIntoChunks = (leaves2, parent2, perChunk) => {
|
|
5552
|
-
if (perChunk === 1)
|
|
5553
|
-
return leaves2;
|
|
5554
|
-
const chunks2 = [];
|
|
5555
|
-
for (let i = 0; i < this.chunkSize; i++) {
|
|
5556
|
-
const chunkNodes = leaves2.slice(i * perChunk, (i + 1) * perChunk);
|
|
5557
|
-
if (chunkNodes.length === 0)
|
|
5558
|
-
break;
|
|
5559
|
-
const chunk = {
|
|
5560
|
-
type: "chunk",
|
|
5561
|
-
key: new Key(),
|
|
5562
|
-
parent: parent2,
|
|
5563
|
-
children: []
|
|
5564
|
-
};
|
|
5565
|
-
chunk.children = groupIntoChunks(chunkNodes, chunk, perChunk / this.chunkSize), chunks2.push(chunk);
|
|
5566
|
-
}
|
|
5567
|
-
return chunks2;
|
|
5568
|
-
}, newTotal = this.pointerSiblings.length + leaves.length;
|
|
5569
|
-
let depthForTotal = 0;
|
|
5570
|
-
for (let i = this.chunkSize; i < newTotal; i *= this.chunkSize)
|
|
5571
|
-
depthForTotal++;
|
|
5572
|
-
const depth = Math.max(depthForTotal, minDepth), perTopLevelChunk = this.chunkSize ** depth, chunks = groupIntoChunks(leaves, this.pointerChunk, perTopLevelChunk);
|
|
5573
|
-
this.pointerSiblings.splice(this.pointerIndex + 1, 0, ...chunks), this.pointerIndex += chunks.length, this.cachedPointerNode = void 0, this.invalidateChunk(), this.validateState();
|
|
5574
|
-
}
|
|
5575
|
-
/**
|
|
5576
|
-
* If debug mode is enabled, ensure that the state is internally consistent
|
|
5577
|
-
*/
|
|
5578
|
-
// istanbul ignore next
|
|
5579
|
-
validateState() {
|
|
5580
|
-
if (!this.debug)
|
|
5581
|
-
return;
|
|
5582
|
-
const validateDescendant = (node2) => {
|
|
5583
|
-
if (node2.type === "chunk") {
|
|
5584
|
-
const {
|
|
5585
|
-
parent: parent2,
|
|
5586
|
-
children
|
|
5587
|
-
} = node2;
|
|
5588
|
-
if (!parent2.children.includes(node2))
|
|
5589
|
-
throw new Error(`Debug: Chunk ${node2.key.id} has an incorrect parent property`);
|
|
5590
|
-
children.forEach(validateDescendant);
|
|
5591
|
-
}
|
|
5592
|
-
};
|
|
5593
|
-
if (this.root.children.forEach(validateDescendant), this.cachedPointerNode !== void 0 && this.cachedPointerNode !== this.getPointerNode())
|
|
5594
|
-
throw new Error("Debug: The cached pointer is incorrect and has not been invalidated");
|
|
5595
|
-
const actualIndexStack = this.getChunkPath(this.pointerChunk);
|
|
5596
|
-
if (!actualIndexStack)
|
|
5597
|
-
throw new Error("Debug: The pointer chunk is not connected to the root");
|
|
5598
|
-
if (!Path.equals(this.pointerIndexStack, actualIndexStack))
|
|
5599
|
-
throw new Error(`Debug: The cached index stack [${this.pointerIndexStack.join(", ")}] does not match the path of the pointer chunk [${actualIndexStack.join(", ")}]`);
|
|
5600
|
-
}
|
|
5601
|
-
}
|
|
5602
|
-
const reconcileChildren = (editor, {
|
|
5603
|
-
chunkTree,
|
|
5604
|
-
children,
|
|
5605
|
-
chunkSize,
|
|
5606
|
-
rerenderChildren = [],
|
|
5607
|
-
onInsert,
|
|
5608
|
-
onUpdate,
|
|
5609
|
-
onIndexChange,
|
|
5610
|
-
debug: debug2
|
|
5611
|
-
}) => {
|
|
5612
|
-
chunkTree.modifiedChunks.clear();
|
|
5613
|
-
const chunkTreeHelper = new ChunkTreeHelper(chunkTree, {
|
|
5614
|
-
chunkSize,
|
|
5615
|
-
debug: debug2
|
|
5616
|
-
}), childrenHelper = new ChildrenHelper(editor, children);
|
|
5617
|
-
let treeLeaf;
|
|
5618
|
-
for (; treeLeaf = chunkTreeHelper.readLeaf(); ) {
|
|
5619
|
-
const lookAhead = childrenHelper.lookAhead(treeLeaf.node, treeLeaf.key);
|
|
5620
|
-
if (lookAhead === -1) {
|
|
5621
|
-
chunkTreeHelper.remove();
|
|
5622
|
-
continue;
|
|
5623
|
-
}
|
|
5624
|
-
const insertedChildrenStartIndex = childrenHelper.pointerIndex, insertedChildren = childrenHelper.read(lookAhead + 1), matchingChild = insertedChildren.pop();
|
|
5625
|
-
if (insertedChildren.length) {
|
|
5626
|
-
const leavesToInsert = childrenHelper.toChunkLeaves(insertedChildren, insertedChildrenStartIndex);
|
|
5627
|
-
chunkTreeHelper.insertBefore(leavesToInsert), insertedChildren.forEach((node2, relativeIndex) => {
|
|
5628
|
-
onInsert?.(node2, insertedChildrenStartIndex + relativeIndex);
|
|
5629
|
-
});
|
|
5630
|
-
}
|
|
5631
|
-
const matchingChildIndex = childrenHelper.pointerIndex - 1;
|
|
5632
|
-
treeLeaf.node !== matchingChild && (treeLeaf.node = matchingChild, chunkTreeHelper.invalidateChunk(), onUpdate?.(matchingChild, matchingChildIndex)), treeLeaf.index !== matchingChildIndex && (treeLeaf.index = matchingChildIndex, onIndexChange?.(matchingChild, matchingChildIndex)), rerenderChildren.includes(matchingChildIndex) && chunkTreeHelper.invalidateChunk();
|
|
5633
|
-
}
|
|
5634
|
-
if (!childrenHelper.reachedEnd) {
|
|
5635
|
-
const remainingChildren = childrenHelper.remaining(), leavesToInsert = childrenHelper.toChunkLeaves(remainingChildren, childrenHelper.pointerIndex);
|
|
5636
|
-
chunkTreeHelper.returnToPreviousLeaf(), chunkTreeHelper.insertAfter(leavesToInsert), remainingChildren.forEach((node2, relativeIndex) => {
|
|
5637
|
-
onInsert?.(node2, childrenHelper.pointerIndex + relativeIndex);
|
|
5638
|
-
});
|
|
5639
|
-
}
|
|
5640
|
-
}, getChunkTreeForNode = (editor, node2, options = {}) => {
|
|
5641
|
-
const key = ReactEditor.findKey(editor, node2);
|
|
5642
|
-
let chunkTree = editor.keyToChunkTree.get(key);
|
|
5643
|
-
return chunkTree || (chunkTree = {
|
|
5644
|
-
type: "root",
|
|
5645
|
-
modifiedChunks: /* @__PURE__ */ new Set(),
|
|
5646
|
-
children: []
|
|
5647
|
-
}, editor.keyToChunkTree.set(key, chunkTree)), options.reconcile && reconcileChildren(editor, {
|
|
5648
|
-
chunkTree,
|
|
5649
|
-
children: node2.children,
|
|
5650
|
-
...options.reconcile
|
|
5651
|
-
}), chunkTree;
|
|
5652
|
-
}, defaultRenderChunk = ({
|
|
5653
|
-
children
|
|
5654
|
-
}) => children, ChunkAncestor = (props) => {
|
|
5655
|
-
const {
|
|
5656
|
-
root,
|
|
5657
|
-
ancestor,
|
|
5658
|
-
renderElement,
|
|
5659
|
-
renderChunk = defaultRenderChunk
|
|
5660
|
-
} = props;
|
|
5661
|
-
return ancestor.children.map((chunkNode) => {
|
|
5662
|
-
if (chunkNode.type === "chunk") {
|
|
5663
|
-
const key = chunkNode.key.id, renderedChunk = renderChunk({
|
|
5664
|
-
highest: ancestor === root,
|
|
5665
|
-
lowest: chunkNode.children.some((c2) => c2.type === "leaf"),
|
|
5666
|
-
attributes: {
|
|
5667
|
-
"data-slate-chunk": !0
|
|
5668
|
-
},
|
|
5669
|
-
children: /* @__PURE__ */ jsx(MemoizedChunk, { root, ancestor: chunkNode, renderElement, renderChunk })
|
|
5670
|
-
});
|
|
5671
|
-
return /* @__PURE__ */ jsx(Fragment, { children: renderedChunk }, key);
|
|
5672
|
-
}
|
|
5673
|
-
const element = chunkNode.node;
|
|
5674
|
-
return renderElement(element, chunkNode.index, chunkNode.key);
|
|
5675
|
-
});
|
|
5676
|
-
}, ChunkTree = ChunkAncestor, MemoizedChunk = React.memo(ChunkAncestor, (prev, next2) => prev.root === next2.root && prev.renderElement === next2.renderElement && prev.renderChunk === next2.renderChunk && !next2.root.modifiedChunks.has(next2.ancestor));
|
|
5677
5098
|
function useGenericSelector(selector, equalityFn) {
|
|
5678
5099
|
const [, forceRender] = useReducer((s) => s + 1, 0), latestSubscriptionCallbackError = useRef(void 0), latestSelector = useRef(() => null), latestSelectedState = useRef(null);
|
|
5679
5100
|
let selectedState;
|
|
@@ -5743,7 +5164,6 @@ const defaultRenderElement$1 = (props) => /* @__PURE__ */ jsx(DefaultElement, {
|
|
|
5743
5164
|
decorations: parentDecorations,
|
|
5744
5165
|
element,
|
|
5745
5166
|
renderElement = defaultRenderElement$1,
|
|
5746
|
-
renderChunk,
|
|
5747
5167
|
renderPlaceholder,
|
|
5748
5168
|
renderLeaf,
|
|
5749
5169
|
renderText
|
|
@@ -5753,7 +5173,6 @@ const defaultRenderElement$1 = (props) => /* @__PURE__ */ jsx(DefaultElement, {
|
|
|
5753
5173
|
decorations,
|
|
5754
5174
|
node: element,
|
|
5755
5175
|
renderElement,
|
|
5756
|
-
renderChunk,
|
|
5757
5176
|
renderPlaceholder,
|
|
5758
5177
|
renderLeaf,
|
|
5759
5178
|
renderText
|
|
@@ -5770,7 +5189,7 @@ const defaultRenderElement$1 = (props) => /* @__PURE__ */ jsx(DefaultElement, {
|
|
|
5770
5189
|
children,
|
|
5771
5190
|
element
|
|
5772
5191
|
});
|
|
5773
|
-
}, MemoizedElement = React.memo(Element$1, (prev, next2) => prev.element === next2.element && prev.renderElement === next2.renderElement && prev.
|
|
5192
|
+
}, MemoizedElement = React.memo(Element$1, (prev, next2) => prev.element === next2.element && prev.renderElement === next2.renderElement && prev.renderText === next2.renderText && prev.renderLeaf === next2.renderLeaf && prev.renderPlaceholder === next2.renderPlaceholder && isElementDecorationsEqual(prev.decorations, next2.decorations)), DefaultElement = (props) => {
|
|
5774
5193
|
const {
|
|
5775
5194
|
attributes,
|
|
5776
5195
|
children,
|
|
@@ -5966,58 +5385,34 @@ const defaultRenderLeaf = (props) => /* @__PURE__ */ jsx(DefaultLeaf, { ...props
|
|
|
5966
5385
|
decorations,
|
|
5967
5386
|
node: node2,
|
|
5968
5387
|
renderElement,
|
|
5969
|
-
renderChunk,
|
|
5970
5388
|
renderPlaceholder,
|
|
5971
5389
|
renderText,
|
|
5972
5390
|
renderLeaf
|
|
5973
5391
|
} = props, editor = useSlateStatic();
|
|
5974
5392
|
editor.isNodeMapDirty = !1;
|
|
5975
|
-
const isEditor2 = Editor.isEditor(node2),
|
|
5976
|
-
|
|
5977
|
-
childrenToRedecorate
|
|
5978
|
-
} = useDecorationsByChild(editor, node2, decorations);
|
|
5979
|
-
chunking || node2.children.forEach((n2, i) => {
|
|
5393
|
+
const isEditor2 = Editor.isEditor(node2), decorationsByChild = useDecorationsByChild(editor, node2, decorations);
|
|
5394
|
+
node2.children.forEach((n2, i) => {
|
|
5980
5395
|
editor.nodeToIndex.set(n2, i), editor.nodeToParent.set(n2, node2);
|
|
5981
5396
|
});
|
|
5982
5397
|
const renderElementComponent = useCallback((n2, i, cachedKey) => {
|
|
5983
5398
|
const key = cachedKey ?? ReactEditor.findKey(editor, n2);
|
|
5984
|
-
return /* @__PURE__ */ jsx(ElementContext.Provider, { value: n2, children: /* @__PURE__ */ jsx(MemoizedElement, { decorations: decorationsByChild[i] ?? [], element: n2, renderElement,
|
|
5985
|
-
}, [editor, decorationsByChild, renderElement,
|
|
5399
|
+
return /* @__PURE__ */ jsx(ElementContext.Provider, { value: n2, children: /* @__PURE__ */ jsx(MemoizedElement, { decorations: decorationsByChild[i] ?? [], element: n2, renderElement, renderPlaceholder, renderLeaf, renderText }, key.id) }, `provider-${key.id}`);
|
|
5400
|
+
}, [editor, decorationsByChild, renderElement, renderPlaceholder, renderLeaf, renderText]), renderTextComponent = (n2, i) => {
|
|
5986
5401
|
const key = ReactEditor.findKey(editor, n2);
|
|
5987
5402
|
return /* @__PURE__ */ jsx(MemoizedText, { decorations: decorationsByChild[i] ?? [], isLast: i === node2.children.length - 1, parent: node2, renderPlaceholder, renderLeaf, renderText, text: n2 }, key.id);
|
|
5988
5403
|
}, renderObjectNodeComponent = (n2, i) => {
|
|
5989
5404
|
const key = ReactEditor.findKey(editor, n2);
|
|
5990
5405
|
return /* @__PURE__ */ jsx(MemoizedObjectNode, { decorations: decorationsByChild[i] ?? [], isInline: !isEditor2, objectNode: n2, renderElement }, key.id);
|
|
5991
5406
|
};
|
|
5992
|
-
|
|
5993
|
-
return node2.children.map((n2, i) => Element$2.isElement(n2, editor.schema) ? renderElementComponent(n2, i) : Node$1.isObjectNode(n2, editor.schema) ? renderObjectNodeComponent(n2, i) : renderTextComponent(n2, i));
|
|
5994
|
-
const chunkTree = getChunkTreeForNode(editor, node2, {
|
|
5995
|
-
reconcile: {
|
|
5996
|
-
chunkSize,
|
|
5997
|
-
rerenderChildren: childrenToRedecorate,
|
|
5998
|
-
onInsert: (n2, i) => {
|
|
5999
|
-
editor.nodeToIndex.set(n2, i), editor.nodeToParent.set(n2, node2);
|
|
6000
|
-
},
|
|
6001
|
-
onUpdate: (n2, i) => {
|
|
6002
|
-
editor.nodeToIndex.set(n2, i), editor.nodeToParent.set(n2, node2);
|
|
6003
|
-
},
|
|
6004
|
-
onIndexChange: (n2, i) => {
|
|
6005
|
-
editor.nodeToIndex.set(n2, i);
|
|
6006
|
-
}
|
|
6007
|
-
}
|
|
6008
|
-
});
|
|
6009
|
-
return /* @__PURE__ */ jsx(ChunkTree, { root: chunkTree, ancestor: chunkTree, renderElement: renderElementComponent, renderChunk });
|
|
5407
|
+
return node2.children.map((n2, i) => Element$2.isElement(n2, editor.schema) ? renderElementComponent(n2, i) : Node$1.isObjectNode(n2, editor.schema) ? renderObjectNodeComponent(n2, i) : renderTextComponent(n2, i));
|
|
6010
5408
|
}, useDecorationsByChild = (editor, node2, decorations) => {
|
|
6011
|
-
const decorationsByChild = splitDecorationsByChild(editor, node2, decorations), mutableDecorationsByChild = useRef(decorationsByChild).current
|
|
5409
|
+
const decorationsByChild = splitDecorationsByChild(editor, node2, decorations), mutableDecorationsByChild = useRef(decorationsByChild).current;
|
|
6012
5410
|
mutableDecorationsByChild.length = decorationsByChild.length;
|
|
6013
5411
|
for (let i = 0; i < decorationsByChild.length; i++) {
|
|
6014
5412
|
const decorations2 = decorationsByChild[i], previousDecorations = mutableDecorationsByChild[i] ?? null;
|
|
6015
|
-
isElementDecorationsEqual(previousDecorations, decorations2) || (mutableDecorationsByChild[i] = decorations2
|
|
5413
|
+
isElementDecorationsEqual(previousDecorations, decorations2) || (mutableDecorationsByChild[i] = decorations2);
|
|
6016
5414
|
}
|
|
6017
|
-
return
|
|
6018
|
-
decorationsByChild: mutableDecorationsByChild,
|
|
6019
|
-
childrenToRedecorate
|
|
6020
|
-
};
|
|
5415
|
+
return mutableDecorationsByChild;
|
|
6021
5416
|
}, ComposingContext = createContext(!1), ReadOnlyContext = createContext(!1), useReadOnly = () => useContext(ReadOnlyContext), SlateSelectorContext = createContext({}), refEquality = (a, b) => a === b;
|
|
6022
5417
|
function useSlateSelector(selector, equalityFn = refEquality, {
|
|
6023
5418
|
deferred
|
|
@@ -6197,7 +5592,7 @@ class RestoreDOMComponent extends Component {
|
|
|
6197
5592
|
}
|
|
6198
5593
|
const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
6199
5594
|
children
|
|
6200
|
-
}) => /* @__PURE__ */ jsx(Fragment
|
|
5595
|
+
}) => /* @__PURE__ */ jsx(Fragment, { children }), Children = (props) => /* @__PURE__ */ jsx(React.Fragment, { children: useChildren(props) }), Editable = forwardRef((props, forwardedRef) => {
|
|
6201
5596
|
const defaultRenderPlaceholder = useCallback((props2) => /* @__PURE__ */ jsx(DefaultPlaceholder, { ...props2 }), []), {
|
|
6202
5597
|
autoFocus,
|
|
6203
5598
|
decorate = defaultDecorate,
|
|
@@ -6206,7 +5601,6 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6206
5601
|
placeholder,
|
|
6207
5602
|
readOnly = !1,
|
|
6208
5603
|
renderElement,
|
|
6209
|
-
renderChunk,
|
|
6210
5604
|
renderLeaf,
|
|
6211
5605
|
renderText,
|
|
6212
5606
|
renderPlaceholder = defaultRenderPlaceholder,
|
|
@@ -7147,7 +6541,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
7147
6541
|
editor
|
|
7148
6542
|
}));
|
|
7149
6543
|
}, [readOnly, editor, editorActor, attributes.onPaste]),
|
|
7150
|
-
children: /* @__PURE__ */ jsx(Children, { decorations, node: editor, renderElement,
|
|
6544
|
+
children: /* @__PURE__ */ jsx(Children, { decorations, node: editor, renderElement, renderPlaceholder, renderLeaf, renderText })
|
|
7151
6545
|
}
|
|
7152
6546
|
) }) }) }) });
|
|
7153
6547
|
}), DefaultPlaceholder = ({
|
|
@@ -7546,7 +6940,7 @@ const withReact = (editor) => {
|
|
|
7546
6940
|
apply: apply2,
|
|
7547
6941
|
insertText: insertText2
|
|
7548
6942
|
} = e;
|
|
7549
|
-
return
|
|
6943
|
+
return IS_ANDROID && (e.insertText = (text, options) => (e.pendingSelection = null, insertText2(text, options))), e.onChange = (options) => {
|
|
7550
6944
|
(REACT_MAJOR_VERSION < 18 ? ReactDOM.unstable_batchedUpdates : (callback) => callback())(() => {
|
|
7551
6945
|
onChange(options);
|
|
7552
6946
|
});
|
|
@@ -8769,7 +8163,7 @@ function RenderLeaf(props) {
|
|
|
8769
8163
|
let t2;
|
|
8770
8164
|
$[4] !== t1 ? (t2 = /* @__PURE__ */ jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: t1 }), $[4] = t1, $[5] = t2) : t2 = $[5];
|
|
8771
8165
|
let t3;
|
|
8772
|
-
return $[6] !== renderedSpan || $[7] !== t2 ? (t3 = /* @__PURE__ */ jsxs(Fragment
|
|
8166
|
+
return $[6] !== renderedSpan || $[7] !== t2 ? (t3 = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
8773
8167
|
t2,
|
|
8774
8168
|
renderedSpan
|
|
8775
8169
|
] }), $[6] = renderedSpan, $[7] = t2, $[8] = t3) : t3 = $[8], t3;
|
|
@@ -10674,21 +10068,18 @@ function createHistoryPlugin({
|
|
|
10674
10068
|
}, editor;
|
|
10675
10069
|
};
|
|
10676
10070
|
}
|
|
10677
|
-
function applyInsertNodeAtPath(editor, node2, path2
|
|
10678
|
-
|
|
10071
|
+
function applyInsertNodeAtPath(editor, node2, path2) {
|
|
10072
|
+
editor.apply({
|
|
10679
10073
|
type: "insert_node",
|
|
10680
10074
|
path: path2,
|
|
10681
10075
|
node: node2
|
|
10682
|
-
})
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
}
|
|
10076
|
+
});
|
|
10077
|
+
const point2 = Editor.end(editor, path2);
|
|
10078
|
+
point2 && applySelect(editor, point2);
|
|
10686
10079
|
}
|
|
10687
|
-
function applyInsertNodeAtPoint(editor, node2, at
|
|
10080
|
+
function applyInsertNodeAtPoint(editor, node2, at) {
|
|
10688
10081
|
Editor.withoutNormalizing(editor, () => {
|
|
10689
|
-
|
|
10690
|
-
Text$1.isText(node2, editor.schema) ? match2 = (n2) => Text$1.isText(n2, editor.schema) : Element$2.isElement(node2, editor.schema) && editor.isInline(node2) ? match2 = (n2) => Text$1.isText(n2, editor.schema) || Element$2.isElement(n2, editor.schema) && Editor.isInline(editor, n2) : editor.isObjectNode(node2) ? match2 = (n2) => Text$1.isText(n2, editor.schema) || editor.isObjectNode(n2) || Element$2.isElement(n2, editor.schema) && Editor.isInline(editor, n2) : match2 = (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2) || editor.isObjectNode(n2);
|
|
10691
|
-
const [entry] = Editor.nodes(editor, {
|
|
10082
|
+
const match2 = Text$1.isText(node2, editor.schema) ? (n2) => Text$1.isText(n2, editor.schema) : (n2) => Text$1.isText(n2, editor.schema) || editor.isObjectNode(n2), [entry] = Editor.nodes(editor, {
|
|
10692
10083
|
at: at.path,
|
|
10693
10084
|
match: match2,
|
|
10694
10085
|
mode: "lowest",
|
|
@@ -10702,14 +10093,13 @@ function applyInsertNodeAtPoint(editor, node2, at, options = {}) {
|
|
|
10702
10093
|
applySplitNode(editor, at.path, at.offset, properties);
|
|
10703
10094
|
}
|
|
10704
10095
|
const path2 = pathRef2.unref(), insertPath = isAtEnd ? Path.next(path2) : path2;
|
|
10705
|
-
|
|
10096
|
+
editor.apply({
|
|
10706
10097
|
type: "insert_node",
|
|
10707
10098
|
path: insertPath,
|
|
10708
10099
|
node: node2
|
|
10709
|
-
})
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
}
|
|
10100
|
+
});
|
|
10101
|
+
const point2 = Editor.end(editor, insertPath);
|
|
10102
|
+
point2 && applySelect(editor, point2);
|
|
10713
10103
|
});
|
|
10714
10104
|
}
|
|
10715
10105
|
function withNormalizeNode(editor, fn) {
|
|
@@ -10730,9 +10120,7 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10730
10120
|
const [node2, path2] = nodeEntry;
|
|
10731
10121
|
if (Editor.isEditor(node2) && node2.children.length === 0 && withoutPatching(editor, () => {
|
|
10732
10122
|
withNormalizeNode(editor, () => {
|
|
10733
|
-
applyInsertNodeAtPath(editor, createPlaceholderBlock(editorActor.getSnapshot().context), [0]
|
|
10734
|
-
select: !0
|
|
10735
|
-
});
|
|
10123
|
+
applyInsertNodeAtPath(editor, createPlaceholderBlock(editorActor.getSnapshot().context), [0]);
|
|
10736
10124
|
});
|
|
10737
10125
|
}), editor.isTextBlock(node2)) {
|
|
10738
10126
|
const children = Node$1.children(editor, path2, editor.schema);
|
|
@@ -10740,11 +10128,8 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10740
10128
|
const nextNode = node2.children[childPath[1] + 1];
|
|
10741
10129
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
10742
10130
|
debug$1.normalization("merging spans with same marks"), withNormalizeNode(editor, () => {
|
|
10743
|
-
const mergePath = [childPath[0], childPath[1] + 1]
|
|
10744
|
-
|
|
10745
|
-
...properties
|
|
10746
|
-
} = nextNode;
|
|
10747
|
-
applyMergeNode(editor, mergePath, child.text.length, properties);
|
|
10131
|
+
const mergePath = [childPath[0], childPath[1] + 1];
|
|
10132
|
+
applyMergeNode(editor, mergePath, child.text.length);
|
|
10748
10133
|
});
|
|
10749
10134
|
return;
|
|
10750
10135
|
}
|
|
@@ -15358,13 +14743,7 @@ function deleteSameBlockRange(editor, start2, end2) {
|
|
|
15358
14743
|
});
|
|
15359
14744
|
}
|
|
15360
14745
|
const startNodeAfter = Node$1.get(editor, start2.path, editor.schema), endNodeAfter = Node$1.get(editor, newEndPath, editor.schema);
|
|
15361
|
-
|
|
15362
|
-
const {
|
|
15363
|
-
text: _,
|
|
15364
|
-
...properties
|
|
15365
|
-
} = endNodeAfter;
|
|
15366
|
-
applyMergeNode(editor, newEndPath, startNodeAfter.text.length, properties);
|
|
15367
|
-
}
|
|
14746
|
+
Text$1.isText(startNodeAfter, editor.schema) && Text$1.isText(endNodeAfter, editor.schema) && applyMergeNode(editor, newEndPath, startNodeAfter.text.length);
|
|
15368
14747
|
}
|
|
15369
14748
|
function deleteCrossBlockRange(editor, start2, end2) {
|
|
15370
14749
|
const startBlockPath = [start2.path[0]];
|
|
@@ -15408,11 +14787,7 @@ function deleteCrossBlockRange(editor, start2, end2) {
|
|
|
15408
14787
|
markDefs: newMarkDefs
|
|
15409
14788
|
}, startBlockPath);
|
|
15410
14789
|
}
|
|
15411
|
-
|
|
15412
|
-
children: _,
|
|
15413
|
-
...properties
|
|
15414
|
-
} = endBlock;
|
|
15415
|
-
applyMergeNode(editor, adjustedEndBlockPath, startBlock.children.length, properties);
|
|
14790
|
+
applyMergeNode(editor, adjustedEndBlockPath, startBlock.children.length);
|
|
15416
14791
|
});
|
|
15417
14792
|
}
|
|
15418
14793
|
function deleteExpandedRange(editor, range2) {
|
|
@@ -15472,11 +14847,7 @@ const insertChildOperationImplementation = ({
|
|
|
15472
14847
|
const [focusSpan] = getFocusSpan({
|
|
15473
14848
|
editor: operation.editor
|
|
15474
14849
|
});
|
|
15475
|
-
focusSpan ? applyInsertNodeAtPoint(operation.editor, span, focus,
|
|
15476
|
-
select: !0
|
|
15477
|
-
}) : applyInsertNodeAtPath(operation.editor, span, [focusBlockIndex, focusChildIndex + 1], {
|
|
15478
|
-
select: !0
|
|
15479
|
-
}), operation.editor.pendingSelection = operation.editor.selection;
|
|
14850
|
+
focusSpan ? applyInsertNodeAtPoint(operation.editor, span, focus) : applyInsertNodeAtPath(operation.editor, span, [focusBlockIndex, focusChildIndex + 1]), operation.editor.pendingSelection = operation.editor.selection;
|
|
15480
14851
|
return;
|
|
15481
14852
|
}
|
|
15482
14853
|
const inlineObject = parseInlineObject({
|
|
@@ -15498,11 +14869,7 @@ const insertChildOperationImplementation = ({
|
|
|
15498
14869
|
}, [focusSpan] = getFocusSpan({
|
|
15499
14870
|
editor: operation.editor
|
|
15500
14871
|
});
|
|
15501
|
-
focusSpan ? applyInsertNodeAtPoint(operation.editor, inlineNode, focus,
|
|
15502
|
-
select: !0
|
|
15503
|
-
}) : applyInsertNodeAtPath(operation.editor, inlineNode, [focusBlockIndex, focusChildIndex + 1], {
|
|
15504
|
-
select: !0
|
|
15505
|
-
});
|
|
14872
|
+
focusSpan ? applyInsertNodeAtPoint(operation.editor, inlineNode, focus) : applyInsertNodeAtPath(operation.editor, inlineNode, [focusBlockIndex, focusChildIndex + 1]);
|
|
15506
14873
|
return;
|
|
15507
14874
|
}
|
|
15508
14875
|
throw new Error("Unable to parse child");
|
|
@@ -15596,7 +14963,34 @@ const moveBackwardOperationImplementation = ({
|
|
|
15596
14963
|
const destinationBlockIndex = operation.editor.blockIndexMap.get(destinationKey);
|
|
15597
14964
|
if (destinationBlockIndex === void 0)
|
|
15598
14965
|
throw new Error("Failed to get block index from block key");
|
|
15599
|
-
|
|
14966
|
+
const editor = operation.editor, node2 = Node$1.get(editor, [originBlockIndex], editor.schema), savedSelection = editor.selection ? {
|
|
14967
|
+
anchor: {
|
|
14968
|
+
...editor.selection.anchor
|
|
14969
|
+
},
|
|
14970
|
+
focus: {
|
|
14971
|
+
...editor.selection.focus
|
|
14972
|
+
}
|
|
14973
|
+
} : null;
|
|
14974
|
+
if (Editor.withoutNormalizing(editor, () => {
|
|
14975
|
+
editor.apply({
|
|
14976
|
+
type: "remove_node",
|
|
14977
|
+
path: [originBlockIndex],
|
|
14978
|
+
node: node2
|
|
14979
|
+
}), editor.apply({
|
|
14980
|
+
type: "insert_node",
|
|
14981
|
+
path: [destinationBlockIndex],
|
|
14982
|
+
node: node2
|
|
14983
|
+
});
|
|
14984
|
+
}), savedSelection) {
|
|
14985
|
+
const fixPoint = (point2) => point2.path[0] === originBlockIndex ? {
|
|
14986
|
+
...point2,
|
|
14987
|
+
path: [destinationBlockIndex, ...point2.path.slice(1)]
|
|
14988
|
+
} : point2;
|
|
14989
|
+
editor.selection = {
|
|
14990
|
+
anchor: fixPoint(savedSelection.anchor),
|
|
14991
|
+
focus: fixPoint(savedSelection.focus)
|
|
14992
|
+
};
|
|
14993
|
+
}
|
|
15600
14994
|
}, moveForwardOperationImplementation = ({
|
|
15601
14995
|
operation
|
|
15602
14996
|
}) => {
|