@portabletext/editor 6.2.0 → 6.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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:
|
|
@@ -775,9 +678,24 @@ const debug$1 = {
|
|
|
775
678
|
});
|
|
776
679
|
ref.current = path2, path2 == null && ref.unref();
|
|
777
680
|
}
|
|
778
|
-
}
|
|
681
|
+
};
|
|
682
|
+
function safeStringify(value, space) {
|
|
683
|
+
try {
|
|
684
|
+
return JSON.stringify(value, null, space);
|
|
685
|
+
} catch (error) {
|
|
686
|
+
return console.error(error), "JSON.stringify failed";
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function safeParse(text) {
|
|
690
|
+
try {
|
|
691
|
+
return JSON.parse(text);
|
|
692
|
+
} catch (error) {
|
|
693
|
+
return console.error(error), "JSON.parse failed";
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
const Scrubber = {
|
|
779
697
|
stringify(value) {
|
|
780
|
-
return
|
|
698
|
+
return safeStringify(value);
|
|
781
699
|
}
|
|
782
700
|
}, Text$1 = {
|
|
783
701
|
equals(text, another, options = {}) {
|
|
@@ -1413,38 +1331,38 @@ const apply$1 = (editor, op) => {
|
|
|
1413
1331
|
} = editor;
|
|
1414
1332
|
return selection ? Node$1.fragment(editor, selection, editor.schema) : [];
|
|
1415
1333
|
};
|
|
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);
|
|
1334
|
+
function applyMergeNode(editor, path2, position) {
|
|
1335
|
+
const node2 = Node$1.get(editor, path2, editor.schema), prevPath = Path.previous(path2);
|
|
1336
|
+
for (const ref of Editor.pathRefs(editor)) {
|
|
1337
|
+
const current = ref.current;
|
|
1338
|
+
current && (ref.current = transformPathForMerge(current, path2, position));
|
|
1339
|
+
}
|
|
1340
|
+
for (const ref of Editor.pointRefs(editor)) {
|
|
1341
|
+
const current = ref.current;
|
|
1342
|
+
current && (ref.current = transformPointForMerge(current, path2, position));
|
|
1343
|
+
}
|
|
1344
|
+
for (const ref of Editor.rangeRefs(editor)) {
|
|
1345
|
+
const current = ref.current;
|
|
1346
|
+
if (current) {
|
|
1347
|
+
const anchor = transformPointForMerge(current.anchor, path2, position), focus = transformPointForMerge(current.focus, path2, position);
|
|
1348
|
+
anchor && focus ? ref.current = {
|
|
1349
|
+
anchor,
|
|
1350
|
+
focus
|
|
1351
|
+
} : (ref.current = null, ref.unref());
|
|
1436
1352
|
}
|
|
1437
|
-
|
|
1353
|
+
}
|
|
1354
|
+
if (editor.selection) {
|
|
1355
|
+
const anchor = transformPointForMerge(editor.selection.anchor, path2, position), focus = transformPointForMerge(editor.selection.focus, path2, position);
|
|
1356
|
+
anchor && focus && (editor.selection = {
|
|
1357
|
+
anchor,
|
|
1358
|
+
focus
|
|
1359
|
+
});
|
|
1438
1360
|
}
|
|
1439
1361
|
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
1440
1362
|
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
1441
1363
|
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
|
-
});
|
|
1364
|
+
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) {
|
|
1365
|
+
const sel = savedPendingSelection, anchor = transformPointForMerge(sel.anchor, path2, position), focus = transformPointForMerge(sel.focus, path2, position);
|
|
1448
1366
|
editorAny.pendingSelection = anchor && focus ? {
|
|
1449
1367
|
anchor,
|
|
1450
1368
|
focus
|
|
@@ -1452,20 +1370,14 @@ function applyMergeNode(editor, path2, position, properties) {
|
|
|
1452
1370
|
}
|
|
1453
1371
|
if (savedPendingAction && typeof savedPendingAction == "object" && "at" in savedPendingAction) {
|
|
1454
1372
|
const action = savedPendingAction;
|
|
1455
|
-
if (
|
|
1456
|
-
const at =
|
|
1457
|
-
affinity: "backward"
|
|
1458
|
-
});
|
|
1373
|
+
if ("offset" in action.at && typeof action.at.offset == "number") {
|
|
1374
|
+
const at = transformPointForMerge(action.at, path2, position);
|
|
1459
1375
|
editorAny.pendingAction = at ? {
|
|
1460
1376
|
...action,
|
|
1461
1377
|
at
|
|
1462
1378
|
} : null;
|
|
1463
1379
|
} else if (Range.isRange(action.at)) {
|
|
1464
|
-
const anchor =
|
|
1465
|
-
affinity: "backward"
|
|
1466
|
-
}), focus = Point.transform(action.at.focus, mergeOp, {
|
|
1467
|
-
affinity: "backward"
|
|
1468
|
-
});
|
|
1380
|
+
const anchor = transformPointForMerge(action.at.anchor, path2, position), focus = transformPointForMerge(action.at.focus, path2, position);
|
|
1469
1381
|
editorAny.pendingAction = anchor && focus ? {
|
|
1470
1382
|
...action,
|
|
1471
1383
|
at: {
|
|
@@ -1516,14 +1428,14 @@ function applyMergeNode(editor, path2, position, properties) {
|
|
|
1516
1428
|
editorAny.pendingDiffs = preTransformedPendingDiffs, editorAny.pendingSelection = preTransformedPendingSelection, editorAny.pendingAction = preTransformedPendingAction;
|
|
1517
1429
|
}
|
|
1518
1430
|
}
|
|
1519
|
-
function transformTextDiffForMerge(textDiff,
|
|
1431
|
+
function transformTextDiffForMerge(textDiff, mergePath, position) {
|
|
1520
1432
|
const {
|
|
1521
1433
|
path: path2,
|
|
1522
1434
|
diff: diff2,
|
|
1523
1435
|
id
|
|
1524
1436
|
} = textDiff;
|
|
1525
|
-
if (!Path.equals(
|
|
1526
|
-
const newPath =
|
|
1437
|
+
if (!Path.equals(mergePath, path2)) {
|
|
1438
|
+
const newPath = transformPathForMerge(path2, mergePath, position);
|
|
1527
1439
|
return newPath ? {
|
|
1528
1440
|
diff: diff2,
|
|
1529
1441
|
id,
|
|
@@ -1532,12 +1444,26 @@ function transformTextDiffForMerge(textDiff, op) {
|
|
|
1532
1444
|
}
|
|
1533
1445
|
return {
|
|
1534
1446
|
diff: {
|
|
1535
|
-
start: diff2.start +
|
|
1536
|
-
end: diff2.end +
|
|
1447
|
+
start: diff2.start + position,
|
|
1448
|
+
end: diff2.end + position,
|
|
1537
1449
|
text: diff2.text
|
|
1538
1450
|
},
|
|
1539
1451
|
id,
|
|
1540
|
-
path:
|
|
1452
|
+
path: transformPathForMerge(path2, mergePath, position)
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
function transformPathForMerge(path2, mergePath, position) {
|
|
1456
|
+
const p = [...path2];
|
|
1457
|
+
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;
|
|
1458
|
+
}
|
|
1459
|
+
function transformPointForMerge(point2, mergePath, position) {
|
|
1460
|
+
let {
|
|
1461
|
+
path: path2,
|
|
1462
|
+
offset
|
|
1463
|
+
} = point2;
|
|
1464
|
+
return Path.equals(mergePath, path2) && (offset += position), path2 = transformPathForMerge(path2, mergePath, position), {
|
|
1465
|
+
path: path2,
|
|
1466
|
+
offset
|
|
1541
1467
|
};
|
|
1542
1468
|
}
|
|
1543
1469
|
const normalizeNode = (editor, entry) => {
|
|
@@ -1572,11 +1498,8 @@ const normalizeNode = (editor, entry) => {
|
|
|
1572
1498
|
else if (Text$1.equals(child, prev, {
|
|
1573
1499
|
loose: !0
|
|
1574
1500
|
})) {
|
|
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--;
|
|
1501
|
+
const mergePath = path2.concat(n2);
|
|
1502
|
+
applyMergeNode(editor, mergePath, prev.text.length), element = Node$1.get(editor, path2, editor.schema), n2--;
|
|
1580
1503
|
}
|
|
1581
1504
|
}
|
|
1582
1505
|
} else if (Element$2.isElement(child, editor.schema))
|
|
@@ -2175,26 +2098,44 @@ const previous = (editor, options = {}) => {
|
|
|
2175
2098
|
}
|
|
2176
2099
|
Editor.normalize(editor);
|
|
2177
2100
|
}, 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;
|
|
2101
|
+
function rangeRefAffinities(range2, affinity) {
|
|
2102
|
+
if (affinity === "inward") {
|
|
2103
|
+
const isCollapsed = Range.isCollapsed(range2);
|
|
2104
|
+
if (Range.isForward(range2)) {
|
|
2105
|
+
const anchorAffinity = "forward";
|
|
2106
|
+
return [anchorAffinity, isCollapsed ? anchorAffinity : "backward"];
|
|
2107
|
+
} else {
|
|
2108
|
+
const anchorAffinity = "backward";
|
|
2109
|
+
return [anchorAffinity, isCollapsed ? anchorAffinity : "forward"];
|
|
2110
|
+
}
|
|
2111
|
+
} else return affinity === "outward" ? Range.isForward(range2) ? ["backward", "forward"] : ["forward", "backward"] : [affinity, affinity];
|
|
2112
|
+
}
|
|
2178
2113
|
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
|
-
|
|
2114
|
+
const node2 = Node$1.get(editor, path2, editor.schema);
|
|
2115
|
+
for (const ref of Editor.pathRefs(editor)) {
|
|
2116
|
+
const current = ref.current;
|
|
2117
|
+
current && (ref.current = transformPathForSplit(current, path2, position, ref.affinity ?? "forward"));
|
|
2118
|
+
}
|
|
2119
|
+
for (const ref of Editor.pointRefs(editor)) {
|
|
2120
|
+
const current = ref.current;
|
|
2121
|
+
current && (ref.current = transformPointForSplit(current, path2, position, ref.affinity ?? "forward"));
|
|
2122
|
+
}
|
|
2123
|
+
for (const ref of Editor.rangeRefs(editor)) {
|
|
2124
|
+
const current = ref.current;
|
|
2125
|
+
if (current) {
|
|
2126
|
+
const [anchorAffinity, focusAffinity] = rangeRefAffinities(current, ref.affinity), anchor = transformPointForSplit(current.anchor, path2, position, anchorAffinity ?? "forward"), focus = transformPointForSplit(current.focus, path2, position, focusAffinity ?? "forward");
|
|
2127
|
+
anchor && focus ? ref.current = {
|
|
2128
|
+
anchor,
|
|
2129
|
+
focus
|
|
2130
|
+
} : (ref.current = null, ref.unref());
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2191
2133
|
if (editor.selection) {
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
editor.selection = sel;
|
|
2134
|
+
const anchor = transformPointForSplit(editor.selection.anchor, path2, position, "forward"), focus = transformPointForSplit(editor.selection.focus, path2, position, "forward");
|
|
2135
|
+
anchor && focus && (editor.selection = {
|
|
2136
|
+
anchor,
|
|
2137
|
+
focus
|
|
2138
|
+
});
|
|
2198
2139
|
}
|
|
2199
2140
|
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
2200
2141
|
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
@@ -2244,6 +2185,20 @@ function applySplitNode(editor, path2, position, properties) {
|
|
|
2244
2185
|
Editor.rangeRefs(editor).add(ref);
|
|
2245
2186
|
}
|
|
2246
2187
|
}
|
|
2188
|
+
function transformPathForSplit(path2, splitPath, position, affinity = "forward") {
|
|
2189
|
+
const p = [...path2];
|
|
2190
|
+
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;
|
|
2191
|
+
}
|
|
2192
|
+
function transformPointForSplit(point2, splitPath, position, affinity = "forward") {
|
|
2193
|
+
let {
|
|
2194
|
+
path: path2,
|
|
2195
|
+
offset
|
|
2196
|
+
} = point2;
|
|
2197
|
+
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), {
|
|
2198
|
+
path: path2,
|
|
2199
|
+
offset
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2247
2202
|
const insertNodes = (editor, nodes2, options = {}) => {
|
|
2248
2203
|
Editor.withoutNormalizing(editor, () => {
|
|
2249
2204
|
const {
|
|
@@ -2486,55 +2441,6 @@ const insertNodes = (editor, nodes2, options = {}) => {
|
|
|
2486
2441
|
});
|
|
2487
2442
|
}
|
|
2488
2443
|
};
|
|
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
2444
|
function applySetNode(editor, props, path2) {
|
|
2539
2445
|
const node2 = Node$1.get(editor, path2, editor.schema), propsRecord = props, properties = {}, newProperties = {};
|
|
2540
2446
|
for (const key of Object.keys(propsRecord))
|
|
@@ -2698,22 +2604,26 @@ const deleteText = (editor, options = {}) => {
|
|
|
2698
2604
|
mode: "highest",
|
|
2699
2605
|
match: (n2) => levels2.includes(n2) && hasSingleChildNest(n2)
|
|
2700
2606
|
}), 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
|
|
2607
|
+
let position;
|
|
2608
|
+
if (Text$1.isText(mergeNode, editor.schema) && Text$1.isText(prevNode, editor.schema))
|
|
2609
|
+
position = prevNode.text.length;
|
|
2610
|
+
else if (Element$2.isElement(mergeNode, editor.schema) && Element$2.isElement(prevNode, editor.schema))
|
|
2611
|
+
position = prevNode.children.length;
|
|
2612
|
+
else
|
|
2715
2613
|
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
|
|
2614
|
+
if (!isPreviousSibling) {
|
|
2615
|
+
const moveNode = Node$1.get(editor, mergePath, editor.schema);
|
|
2616
|
+
editor.apply({
|
|
2617
|
+
type: "remove_node",
|
|
2618
|
+
path: mergePath,
|
|
2619
|
+
node: moveNode
|
|
2620
|
+
}), editor.apply({
|
|
2621
|
+
type: "insert_node",
|
|
2622
|
+
path: newPath,
|
|
2623
|
+
node: moveNode
|
|
2624
|
+
});
|
|
2625
|
+
}
|
|
2626
|
+
if (emptyRef && Transforms.removeNodes(editor, {
|
|
2717
2627
|
at: emptyRef.current,
|
|
2718
2628
|
voids
|
|
2719
2629
|
}), Editor.shouldMergeNodesRemovePrevNode(editor, prev, current))
|
|
@@ -2729,7 +2639,7 @@ const deleteText = (editor, options = {}) => {
|
|
|
2729
2639
|
markDefs: newMarkDefs
|
|
2730
2640
|
}, targetPath);
|
|
2731
2641
|
}
|
|
2732
|
-
applyMergeNode(pteEditor, newPath, position
|
|
2642
|
+
applyMergeNode(pteEditor, newPath, position);
|
|
2733
2643
|
}
|
|
2734
2644
|
emptyRef && emptyRef.unref();
|
|
2735
2645
|
}
|
|
@@ -2823,7 +2733,7 @@ const deleteText = (editor, options = {}) => {
|
|
|
2823
2733
|
}, isDOMSelection = (value) => {
|
|
2824
2734
|
const window2 = value && value.anchorNode && getDefaultView(value.anchorNode);
|
|
2825
2735
|
return !!window2 && value instanceof window2.Selection;
|
|
2826
|
-
},
|
|
2736
|
+
}, isPlainTextOnlyPaste = (event) => event.clipboardData && event.clipboardData.getData("text/plain") !== "" && event.clipboardData.types.length === 1, normalizeDOMPoint = (domPoint) => {
|
|
2827
2737
|
let [node2, offset] = domPoint;
|
|
2828
2738
|
if (isDOMElement(node2) && node2.childNodes.length) {
|
|
2829
2739
|
let isLast = offset === node2.childNodes.length, index = isLast ? offset - 1 : offset;
|
|
@@ -2862,18 +2772,6 @@ const deleteText = (editor, options = {}) => {
|
|
|
2862
2772
|
}, getEditableChild = (parent2, index, direction) => {
|
|
2863
2773
|
const [child] = getEditableChildAndIndex(parent2, index, direction);
|
|
2864
2774
|
return child;
|
|
2865
|
-
}, getPlainText = (domNode) => {
|
|
2866
|
-
let text = "";
|
|
2867
|
-
if (isDOMText(domNode) && domNode.nodeValue)
|
|
2868
|
-
return domNode.nodeValue;
|
|
2869
|
-
if (isDOMElement(domNode)) {
|
|
2870
|
-
for (const childNode of Array.from(domNode.childNodes))
|
|
2871
|
-
text += getPlainText(childNode);
|
|
2872
|
-
const display = getComputedStyle(domNode).getPropertyValue("display");
|
|
2873
|
-
(display === "block" || display === "list" || domNode.tagName === "BR") && (text += `
|
|
2874
|
-
`);
|
|
2875
|
-
}
|
|
2876
|
-
return text;
|
|
2877
2775
|
}, getSelection = (root) => "getSelection" in root && typeof root.getSelection == "function" ? root.getSelection() : document.getSelection(), isTrackedMutation = (editor, mutation, batch) => {
|
|
2878
2776
|
const {
|
|
2879
2777
|
target
|
|
@@ -3075,7 +2973,6 @@ const DOMEditor = {
|
|
|
3075
2973
|
const slateNode = DOMEditor.hasTarget(editor, target) && DOMEditor.toSlateNode(editor, target);
|
|
3076
2974
|
return !!slateNode && editor.isObjectNode(slateNode);
|
|
3077
2975
|
},
|
|
3078
|
-
setFragmentData: (editor, data, originEvent) => editor.setFragmentData(data, originEvent),
|
|
3079
2976
|
toDOMNode: (editor, node2) => {
|
|
3080
2977
|
const domNode = Editor.isEditor(node2) ? editor.domElement : editor.keyToElement?.get(DOMEditor.findKey(editor, node2));
|
|
3081
2978
|
if (!domNode)
|
|
@@ -3497,7 +3394,7 @@ function transformPendingPoint(editor, point2, op) {
|
|
|
3497
3394
|
}, transformed = Point.transform(anchor, op, {
|
|
3498
3395
|
affinity: "backward"
|
|
3499
3396
|
});
|
|
3500
|
-
return transformed ?
|
|
3397
|
+
return transformed ? {
|
|
3501
3398
|
path: transformed.path,
|
|
3502
3399
|
offset: transformed.offset + diff2.text.length - diff2.end + diff2.start
|
|
3503
3400
|
} : null;
|
|
@@ -3618,39 +3515,6 @@ const withDOM = (editor) => {
|
|
|
3618
3515
|
const [node2] = Editor.node(e, path2);
|
|
3619
3516
|
e.nodeToKey.set(node2, key);
|
|
3620
3517
|
}
|
|
3621
|
-
}, e.setFragmentData = (data) => {
|
|
3622
|
-
const {
|
|
3623
|
-
selection
|
|
3624
|
-
} = e;
|
|
3625
|
-
if (!selection)
|
|
3626
|
-
return;
|
|
3627
|
-
const [start2, end2] = Range.edges(selection), startVoid = Editor.void(e, {
|
|
3628
|
-
at: start2.path
|
|
3629
|
-
}), endVoid = Editor.void(e, {
|
|
3630
|
-
at: end2.path
|
|
3631
|
-
});
|
|
3632
|
-
if (Range.isCollapsed(selection) && !startVoid)
|
|
3633
|
-
return;
|
|
3634
|
-
const domRange = DOMEditor.toDOMRange(e, selection);
|
|
3635
|
-
let contents = domRange.cloneContents(), attach = contents.childNodes[0];
|
|
3636
|
-
if (contents.childNodes.forEach((node2) => {
|
|
3637
|
-
node2.textContent && node2.textContent.trim() !== "" && (attach = node2);
|
|
3638
|
-
}), endVoid) {
|
|
3639
|
-
const [voidNode] = endVoid, r = domRange.cloneRange(), domNode = DOMEditor.toDOMNode(e, voidNode);
|
|
3640
|
-
r.setEndAfter(domNode), contents = r.cloneContents();
|
|
3641
|
-
}
|
|
3642
|
-
if (startVoid && (attach = contents.querySelector("[data-slate-spacer]")), Array.from(contents.querySelectorAll("[data-slate-zero-width]")).forEach((zw) => {
|
|
3643
|
-
const isNewline = zw.getAttribute("data-slate-zero-width") === "n";
|
|
3644
|
-
zw.textContent = isNewline ? `
|
|
3645
|
-
` : "";
|
|
3646
|
-
}), isDOMText(attach)) {
|
|
3647
|
-
const span = attach.ownerDocument.createElement("span");
|
|
3648
|
-
span.style.whiteSpace = "pre", span.appendChild(attach), contents.appendChild(span), attach = span;
|
|
3649
|
-
}
|
|
3650
|
-
const fragment = e.getFragment(), string2 = JSON.stringify(fragment), encoded = window.btoa(encodeURIComponent(string2));
|
|
3651
|
-
attach.setAttribute("data-slate-fragment", encoded), data.setData("application/x-slate-fragment", encoded);
|
|
3652
|
-
const div = contents.ownerDocument.createElement("div");
|
|
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;
|
|
3654
3518
|
}, e.insertData = (data) => {
|
|
3655
3519
|
e.insertTextData(data);
|
|
3656
3520
|
}, e.insertTextData = (data) => {
|
|
@@ -5200,480 +5064,6 @@ const MUTATION_OBSERVER_CONFIG$1 = {
|
|
|
5200
5064
|
}));
|
|
5201
5065
|
return useMutationObserver(node2, inputManager.handleDomMutations, MUTATION_OBSERVER_CONFIG$1), editor.scheduleFlush = inputManager.scheduleFlush, isMounted && inputManager.flush(), inputManager;
|
|
5202
5066
|
} : () => 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
5067
|
function useGenericSelector(selector, equalityFn) {
|
|
5678
5068
|
const [, forceRender] = useReducer((s) => s + 1, 0), latestSubscriptionCallbackError = useRef(void 0), latestSelector = useRef(() => null), latestSelectedState = useRef(null);
|
|
5679
5069
|
let selectedState;
|
|
@@ -5743,7 +5133,6 @@ const defaultRenderElement$1 = (props) => /* @__PURE__ */ jsx(DefaultElement, {
|
|
|
5743
5133
|
decorations: parentDecorations,
|
|
5744
5134
|
element,
|
|
5745
5135
|
renderElement = defaultRenderElement$1,
|
|
5746
|
-
renderChunk,
|
|
5747
5136
|
renderPlaceholder,
|
|
5748
5137
|
renderLeaf,
|
|
5749
5138
|
renderText
|
|
@@ -5753,7 +5142,6 @@ const defaultRenderElement$1 = (props) => /* @__PURE__ */ jsx(DefaultElement, {
|
|
|
5753
5142
|
decorations,
|
|
5754
5143
|
node: element,
|
|
5755
5144
|
renderElement,
|
|
5756
|
-
renderChunk,
|
|
5757
5145
|
renderPlaceholder,
|
|
5758
5146
|
renderLeaf,
|
|
5759
5147
|
renderText
|
|
@@ -5770,7 +5158,7 @@ const defaultRenderElement$1 = (props) => /* @__PURE__ */ jsx(DefaultElement, {
|
|
|
5770
5158
|
children,
|
|
5771
5159
|
element
|
|
5772
5160
|
});
|
|
5773
|
-
}, MemoizedElement = React.memo(Element$1, (prev, next2) => prev.element === next2.element && prev.renderElement === next2.renderElement && prev.
|
|
5161
|
+
}, 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
5162
|
const {
|
|
5775
5163
|
attributes,
|
|
5776
5164
|
children,
|
|
@@ -5966,58 +5354,34 @@ const defaultRenderLeaf = (props) => /* @__PURE__ */ jsx(DefaultLeaf, { ...props
|
|
|
5966
5354
|
decorations,
|
|
5967
5355
|
node: node2,
|
|
5968
5356
|
renderElement,
|
|
5969
|
-
renderChunk,
|
|
5970
5357
|
renderPlaceholder,
|
|
5971
5358
|
renderText,
|
|
5972
5359
|
renderLeaf
|
|
5973
5360
|
} = props, editor = useSlateStatic();
|
|
5974
5361
|
editor.isNodeMapDirty = !1;
|
|
5975
|
-
const isEditor2 = Editor.isEditor(node2),
|
|
5976
|
-
|
|
5977
|
-
childrenToRedecorate
|
|
5978
|
-
} = useDecorationsByChild(editor, node2, decorations);
|
|
5979
|
-
chunking || node2.children.forEach((n2, i) => {
|
|
5362
|
+
const isEditor2 = Editor.isEditor(node2), decorationsByChild = useDecorationsByChild(editor, node2, decorations);
|
|
5363
|
+
node2.children.forEach((n2, i) => {
|
|
5980
5364
|
editor.nodeToIndex.set(n2, i), editor.nodeToParent.set(n2, node2);
|
|
5981
5365
|
});
|
|
5982
5366
|
const renderElementComponent = useCallback((n2, i, cachedKey) => {
|
|
5983
5367
|
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,
|
|
5368
|
+
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}`);
|
|
5369
|
+
}, [editor, decorationsByChild, renderElement, renderPlaceholder, renderLeaf, renderText]), renderTextComponent = (n2, i) => {
|
|
5986
5370
|
const key = ReactEditor.findKey(editor, n2);
|
|
5987
5371
|
return /* @__PURE__ */ jsx(MemoizedText, { decorations: decorationsByChild[i] ?? [], isLast: i === node2.children.length - 1, parent: node2, renderPlaceholder, renderLeaf, renderText, text: n2 }, key.id);
|
|
5988
5372
|
}, renderObjectNodeComponent = (n2, i) => {
|
|
5989
5373
|
const key = ReactEditor.findKey(editor, n2);
|
|
5990
5374
|
return /* @__PURE__ */ jsx(MemoizedObjectNode, { decorations: decorationsByChild[i] ?? [], isInline: !isEditor2, objectNode: n2, renderElement }, key.id);
|
|
5991
5375
|
};
|
|
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 });
|
|
5376
|
+
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
5377
|
}, useDecorationsByChild = (editor, node2, decorations) => {
|
|
6011
|
-
const decorationsByChild = splitDecorationsByChild(editor, node2, decorations), mutableDecorationsByChild = useRef(decorationsByChild).current
|
|
5378
|
+
const decorationsByChild = splitDecorationsByChild(editor, node2, decorations), mutableDecorationsByChild = useRef(decorationsByChild).current;
|
|
6012
5379
|
mutableDecorationsByChild.length = decorationsByChild.length;
|
|
6013
5380
|
for (let i = 0; i < decorationsByChild.length; i++) {
|
|
6014
5381
|
const decorations2 = decorationsByChild[i], previousDecorations = mutableDecorationsByChild[i] ?? null;
|
|
6015
|
-
isElementDecorationsEqual(previousDecorations, decorations2) || (mutableDecorationsByChild[i] = decorations2
|
|
5382
|
+
isElementDecorationsEqual(previousDecorations, decorations2) || (mutableDecorationsByChild[i] = decorations2);
|
|
6016
5383
|
}
|
|
6017
|
-
return
|
|
6018
|
-
decorationsByChild: mutableDecorationsByChild,
|
|
6019
|
-
childrenToRedecorate
|
|
6020
|
-
};
|
|
5384
|
+
return mutableDecorationsByChild;
|
|
6021
5385
|
}, ComposingContext = createContext(!1), ReadOnlyContext = createContext(!1), useReadOnly = () => useContext(ReadOnlyContext), SlateSelectorContext = createContext({}), refEquality = (a, b) => a === b;
|
|
6022
5386
|
function useSlateSelector(selector, equalityFn = refEquality, {
|
|
6023
5387
|
deferred
|
|
@@ -6197,7 +5561,7 @@ class RestoreDOMComponent extends Component {
|
|
|
6197
5561
|
}
|
|
6198
5562
|
const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
6199
5563
|
children
|
|
6200
|
-
}) => /* @__PURE__ */ jsx(Fragment
|
|
5564
|
+
}) => /* @__PURE__ */ jsx(Fragment, { children }), Children = (props) => /* @__PURE__ */ jsx(React.Fragment, { children: useChildren(props) }), Editable = forwardRef((props, forwardedRef) => {
|
|
6201
5565
|
const defaultRenderPlaceholder = useCallback((props2) => /* @__PURE__ */ jsx(DefaultPlaceholder, { ...props2 }), []), {
|
|
6202
5566
|
autoFocus,
|
|
6203
5567
|
decorate = defaultDecorate,
|
|
@@ -6206,7 +5570,6 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6206
5570
|
placeholder,
|
|
6207
5571
|
readOnly = !1,
|
|
6208
5572
|
renderElement,
|
|
6209
|
-
renderChunk,
|
|
6210
5573
|
renderLeaf,
|
|
6211
5574
|
renderText,
|
|
6212
5575
|
renderPlaceholder = defaultRenderPlaceholder,
|
|
@@ -6221,7 +5584,6 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6221
5584
|
} = useTrackUserInput(), [, forceRender] = useReducer((s) => s + 1, 0);
|
|
6222
5585
|
editor.forceRender = forceRender, editor.readOnly = readOnly;
|
|
6223
5586
|
const state = useMemo(() => ({
|
|
6224
|
-
isDraggingInternally: !1,
|
|
6225
5587
|
isUpdatingSelection: !1,
|
|
6226
5588
|
latestElement: null,
|
|
6227
5589
|
hasMarkPlaceholder: !1
|
|
@@ -6240,7 +5602,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6240
5602
|
return;
|
|
6241
5603
|
}
|
|
6242
5604
|
const androidInputManager = androidInputManagerRef.current;
|
|
6243
|
-
if ((IS_ANDROID || !ReactEditor.isComposing(editor)) && (!state.isUpdatingSelection || androidInputManager?.isFlushing())
|
|
5605
|
+
if ((IS_ANDROID || !ReactEditor.isComposing(editor)) && (!state.isUpdatingSelection || androidInputManager?.isFlushing())) {
|
|
6244
5606
|
const root2 = ReactEditor.findDocumentOrShadowRoot(editor), {
|
|
6245
5607
|
activeElement
|
|
6246
5608
|
} = root2, el2 = ReactEditor.toDOMNode(editor, editor), domSelection = getSelection(root2);
|
|
@@ -6598,14 +5960,10 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6598
5960
|
const targetTagName = (target instanceof HTMLElement ? target : null)?.tagName;
|
|
6599
5961
|
targetTagName === "INPUT" || targetTagName === "TEXTAREA" || scheduleOnDOMSelectionChange();
|
|
6600
5962
|
};
|
|
6601
|
-
window2.document.addEventListener("selectionchange", onSelectionChange)
|
|
6602
|
-
|
|
6603
|
-
state.isDraggingInternally = !1;
|
|
6604
|
-
};
|
|
6605
|
-
return window2.document.addEventListener("dragend", stoppedDragging), window2.document.addEventListener("drop", stoppedDragging), () => {
|
|
6606
|
-
window2.document.removeEventListener("selectionchange", onSelectionChange), window2.document.removeEventListener("dragend", stoppedDragging), window2.document.removeEventListener("drop", stoppedDragging);
|
|
5963
|
+
return window2.document.addEventListener("selectionchange", onSelectionChange), () => {
|
|
5964
|
+
window2.document.removeEventListener("selectionchange", onSelectionChange);
|
|
6607
5965
|
};
|
|
6608
|
-
}, [scheduleOnDOMSelectionChange
|
|
5966
|
+
}, [scheduleOnDOMSelectionChange]);
|
|
6609
5967
|
const decorations = decorate([editor, []]), decorateContext = useDecorateContext(decorate), showPlaceholder = placeholder && editor.children.length === 1 && Array.from(Node$1.texts(editor, editor.schema)).length === 1 && Node$1.string(editor, editor.schema) === "" && !isComposing, placeHolderResizeHandler = useCallback((placeholderEl) => {
|
|
6610
5968
|
setPlaceholderHeight(placeholderEl && showPlaceholder ? placeholderEl.getBoundingClientRect()?.height : void 0);
|
|
6611
5969
|
}, [showPlaceholder]);
|
|
@@ -6813,74 +6171,12 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6813
6171
|
}
|
|
6814
6172
|
}
|
|
6815
6173
|
}, [attributes.onCompositionStart, editor, editorActor]),
|
|
6816
|
-
onCopy:
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
const {
|
|
6823
|
-
selection
|
|
6824
|
-
} = editor;
|
|
6825
|
-
if (selection)
|
|
6826
|
-
if (Range.isExpanded(selection))
|
|
6827
|
-
editorActor.send({
|
|
6828
|
-
type: "behavior event",
|
|
6829
|
-
behaviorEvent: {
|
|
6830
|
-
type: "delete",
|
|
6831
|
-
direction: "forward"
|
|
6832
|
-
},
|
|
6833
|
-
editor
|
|
6834
|
-
});
|
|
6835
|
-
else {
|
|
6836
|
-
const node2 = Node$1.get(editor, selection.anchor.path, editor.schema);
|
|
6837
|
-
editor.isObjectNode(node2) && Transforms.delete(editor);
|
|
6838
|
-
}
|
|
6839
|
-
}
|
|
6840
|
-
}, [readOnly, editor, editorActor, attributes.onCut]),
|
|
6841
|
-
onDragOver: useCallback((event) => {
|
|
6842
|
-
if (ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragOver)) {
|
|
6843
|
-
const node2 = ReactEditor.toSlateNode(editor, event.target);
|
|
6844
|
-
editor.isObjectNode(node2) && event.preventDefault();
|
|
6845
|
-
}
|
|
6846
|
-
}, [attributes.onDragOver, editor]),
|
|
6847
|
-
onDragStart: useCallback((event) => {
|
|
6848
|
-
if (!readOnly && ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragStart)) {
|
|
6849
|
-
const node2 = ReactEditor.toSlateNode(editor, event.target), path2 = ReactEditor.findPath(editor, node2);
|
|
6850
|
-
if (editor.isObjectNode(node2) || Editor.void(editor, {
|
|
6851
|
-
at: path2,
|
|
6852
|
-
voids: !0
|
|
6853
|
-
})) {
|
|
6854
|
-
const range2 = Editor.range(editor, path2);
|
|
6855
|
-
Transforms.select(editor, range2);
|
|
6856
|
-
}
|
|
6857
|
-
state.isDraggingInternally = !0, ReactEditor.setFragmentData(editor, event.dataTransfer, "drag");
|
|
6858
|
-
}
|
|
6859
|
-
}, [readOnly, editor, attributes.onDragStart, state]),
|
|
6860
|
-
onDrop: useCallback((event) => {
|
|
6861
|
-
if (!readOnly && ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDrop)) {
|
|
6862
|
-
event.preventDefault();
|
|
6863
|
-
const draggedRange = editor.selection, range2 = ReactEditor.findEventRange(editor, event), data = event.dataTransfer;
|
|
6864
|
-
Transforms.select(editor, range2), state.isDraggingInternally && draggedRange && !Range.equals(draggedRange, range2) && !Editor.void(editor, {
|
|
6865
|
-
at: range2,
|
|
6866
|
-
voids: !0
|
|
6867
|
-
}) && Transforms.delete(editor, {
|
|
6868
|
-
at: draggedRange
|
|
6869
|
-
}), editorActor.send({
|
|
6870
|
-
type: "behavior event",
|
|
6871
|
-
behaviorEvent: {
|
|
6872
|
-
type: "input.*",
|
|
6873
|
-
originEvent: {
|
|
6874
|
-
dataTransfer: data
|
|
6875
|
-
}
|
|
6876
|
-
},
|
|
6877
|
-
editor
|
|
6878
|
-
}), ReactEditor.isFocused(editor) || ReactEditor.focus(editor);
|
|
6879
|
-
}
|
|
6880
|
-
}, [readOnly, editor, editorActor, attributes.onDrop, state]),
|
|
6881
|
-
onDragEnd: useCallback((event) => {
|
|
6882
|
-
!readOnly && state.isDraggingInternally && attributes.onDragEnd && ReactEditor.hasTarget(editor, event.target) && attributes.onDragEnd(event);
|
|
6883
|
-
}, [readOnly, state, attributes, editor]),
|
|
6174
|
+
onCopy: attributes.onCopy,
|
|
6175
|
+
onCut: attributes.onCut,
|
|
6176
|
+
onDragOver: attributes.onDragOver,
|
|
6177
|
+
onDragStart: attributes.onDragStart,
|
|
6178
|
+
onDrop: attributes.onDrop,
|
|
6179
|
+
onDragEnd: attributes.onDragEnd,
|
|
6884
6180
|
onFocus: useCallback((event) => {
|
|
6885
6181
|
if (!readOnly && !state.isUpdatingSelection && ReactEditor.hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onFocus)) {
|
|
6886
6182
|
const el = ReactEditor.toDOMNode(editor, editor), root = ReactEditor.findDocumentOrShadowRoot(editor);
|
|
@@ -6902,26 +6198,6 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6902
6198
|
const {
|
|
6903
6199
|
selection
|
|
6904
6200
|
} = editor, element = editor.children[selection !== null ? selection.focus.path[0] : 0], isRTL = getDirection(Node$1.string(element, editor.schema)) === "rtl";
|
|
6905
|
-
if (Hotkeys.isRedo(nativeEvent)) {
|
|
6906
|
-
event.preventDefault(), editorActor.send({
|
|
6907
|
-
type: "behavior event",
|
|
6908
|
-
behaviorEvent: {
|
|
6909
|
-
type: "history.redo"
|
|
6910
|
-
},
|
|
6911
|
-
editor
|
|
6912
|
-
});
|
|
6913
|
-
return;
|
|
6914
|
-
}
|
|
6915
|
-
if (Hotkeys.isUndo(nativeEvent)) {
|
|
6916
|
-
event.preventDefault(), editorActor.send({
|
|
6917
|
-
type: "behavior event",
|
|
6918
|
-
behaviorEvent: {
|
|
6919
|
-
type: "history.undo"
|
|
6920
|
-
},
|
|
6921
|
-
editor
|
|
6922
|
-
});
|
|
6923
|
-
return;
|
|
6924
|
-
}
|
|
6925
6201
|
if (Hotkeys.isMoveLineBackward(nativeEvent)) {
|
|
6926
6202
|
event.preventDefault(), Transforms.move(editor, {
|
|
6927
6203
|
unit: "line",
|
|
@@ -7147,7 +6423,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
7147
6423
|
editor
|
|
7148
6424
|
}));
|
|
7149
6425
|
}, [readOnly, editor, editorActor, attributes.onPaste]),
|
|
7150
|
-
children: /* @__PURE__ */ jsx(Children, { decorations, node: editor, renderElement,
|
|
6426
|
+
children: /* @__PURE__ */ jsx(Children, { decorations, node: editor, renderElement, renderPlaceholder, renderLeaf, renderText })
|
|
7151
6427
|
}
|
|
7152
6428
|
) }) }) }) });
|
|
7153
6429
|
}), DefaultPlaceholder = ({
|
|
@@ -7546,7 +6822,7 @@ const withReact = (editor) => {
|
|
|
7546
6822
|
apply: apply2,
|
|
7547
6823
|
insertText: insertText2
|
|
7548
6824
|
} = e;
|
|
7549
|
-
return
|
|
6825
|
+
return IS_ANDROID && (e.insertText = (text, options) => (e.pendingSelection = null, insertText2(text, options))), e.onChange = (options) => {
|
|
7550
6826
|
(REACT_MAJOR_VERSION < 18 ? ReactDOM.unstable_batchedUpdates : (callback) => callback())(() => {
|
|
7551
6827
|
onChange(options);
|
|
7552
6828
|
});
|
|
@@ -8769,7 +8045,7 @@ function RenderLeaf(props) {
|
|
|
8769
8045
|
let t2;
|
|
8770
8046
|
$[4] !== t1 ? (t2 = /* @__PURE__ */ jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: t1 }), $[4] = t1, $[5] = t2) : t2 = $[5];
|
|
8771
8047
|
let t3;
|
|
8772
|
-
return $[6] !== renderedSpan || $[7] !== t2 ? (t3 = /* @__PURE__ */ jsxs(Fragment
|
|
8048
|
+
return $[6] !== renderedSpan || $[7] !== t2 ? (t3 = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
8773
8049
|
t2,
|
|
8774
8050
|
renderedSpan
|
|
8775
8051
|
] }), $[6] = renderedSpan, $[7] = t2, $[8] = t3) : t3 = $[8], t3;
|
|
@@ -9102,7 +8378,7 @@ function validateSelection(slateEditor, editorElement) {
|
|
|
9102
8378
|
}
|
|
9103
8379
|
}
|
|
9104
8380
|
const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
9105
|
-
const $ = c(
|
|
8381
|
+
const $ = c(181);
|
|
9106
8382
|
let hotkeys, onBeforeInput, onBlur, onClick, onCopy, onCut, onDrag, onDragEnd, onDragEnter, onDragLeave, onDragOver, onDragStart, onDrop, onFocus, onPaste, propsSelection, rangeDecorations, renderAnnotation, renderBlock, renderChild, renderDecorator, renderListItem, renderPlaceholder, renderStyle, restProps, scrollSelectionIntoView, spellCheck;
|
|
9107
8383
|
$[0] !== props ? ({
|
|
9108
8384
|
hotkeys,
|
|
@@ -9185,10 +8461,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9185
8461
|
let t13;
|
|
9186
8462
|
$[64] !== editorActor || $[65] !== propsSelection || $[66] !== slateEditor ? (t13 = () => {
|
|
9187
8463
|
if (propsSelection) {
|
|
9188
|
-
debug$1.selection(`Selection from props ${
|
|
8464
|
+
debug$1.selection(`Selection from props ${safeStringify(propsSelection)}`);
|
|
9189
8465
|
const normalizedSelection = normalizeSelection(propsSelection, slateEditor.children);
|
|
9190
8466
|
if (normalizedSelection !== null) {
|
|
9191
|
-
debug$1.selection(`Normalized selection from props ${
|
|
8467
|
+
debug$1.selection(`Normalized selection from props ${safeStringify(normalizedSelection)}`);
|
|
9192
8468
|
const slateRange = toSlateRange({
|
|
9193
8469
|
context: {
|
|
9194
8470
|
schema: editorActor.getSnapshot().context.schema,
|
|
@@ -9226,61 +8502,65 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9226
8502
|
}, t17 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[73] = hasInvalidValue, $[74] = propsSelection, $[75] = restoreSelectionFromProps, $[76] = t16, $[77] = t17) : (t16 = $[76], t17 = $[77]), useEffect(t16, t17);
|
|
9227
8503
|
let t18;
|
|
9228
8504
|
$[78] !== editorActor || $[79] !== onCopy || $[80] !== slateEditor ? (t18 = (event) => {
|
|
9229
|
-
if (
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
event.
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
selection
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
8505
|
+
if (ReactEditor.hasSelectableTarget(slateEditor, event.target)) {
|
|
8506
|
+
if (onCopy)
|
|
8507
|
+
onCopy(event) !== void 0 && event.preventDefault();
|
|
8508
|
+
else if (event.nativeEvent.clipboardData) {
|
|
8509
|
+
event.stopPropagation(), event.preventDefault();
|
|
8510
|
+
const selection = slateEditor.selection ? slateRangeToSelection({
|
|
8511
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8512
|
+
editor: slateEditor,
|
|
8513
|
+
range: slateEditor.selection
|
|
8514
|
+
}) : void 0, position = selection ? {
|
|
8515
|
+
selection
|
|
8516
|
+
} : void 0;
|
|
8517
|
+
if (!position) {
|
|
8518
|
+
console.warn("Could not find position for copy event");
|
|
8519
|
+
return;
|
|
8520
|
+
}
|
|
8521
|
+
editorActor.send({
|
|
8522
|
+
type: "behavior event",
|
|
8523
|
+
behaviorEvent: {
|
|
8524
|
+
type: "clipboard.copy",
|
|
8525
|
+
originEvent: {
|
|
8526
|
+
dataTransfer: event.nativeEvent.clipboardData
|
|
8527
|
+
},
|
|
8528
|
+
position
|
|
9250
8529
|
},
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
});
|
|
8530
|
+
editor: slateEditor,
|
|
8531
|
+
nativeEvent: event
|
|
8532
|
+
});
|
|
8533
|
+
}
|
|
9256
8534
|
}
|
|
9257
8535
|
}, $[78] = editorActor, $[79] = onCopy, $[80] = slateEditor, $[81] = t18) : t18 = $[81];
|
|
9258
8536
|
const handleCopy = t18;
|
|
9259
8537
|
let t19;
|
|
9260
8538
|
$[82] !== editorActor || $[83] !== onCut || $[84] !== slateEditor ? (t19 = (event_0) => {
|
|
9261
|
-
if (
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
event_0.
|
|
9265
|
-
|
|
9266
|
-
selection
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
8539
|
+
if (ReactEditor.hasSelectableTarget(slateEditor, event_0.target)) {
|
|
8540
|
+
if (onCut)
|
|
8541
|
+
onCut(event_0) !== void 0 && event_0.preventDefault();
|
|
8542
|
+
else if (event_0.nativeEvent.clipboardData) {
|
|
8543
|
+
event_0.stopPropagation(), event_0.preventDefault();
|
|
8544
|
+
const selection_0 = editorActor.getSnapshot().context.selection, position_0 = selection_0 ? {
|
|
8545
|
+
selection: selection_0
|
|
8546
|
+
} : void 0;
|
|
8547
|
+
if (!position_0) {
|
|
8548
|
+
console.warn("Could not find position for cut event");
|
|
8549
|
+
return;
|
|
8550
|
+
}
|
|
8551
|
+
editorActor.send({
|
|
8552
|
+
type: "behavior event",
|
|
8553
|
+
behaviorEvent: {
|
|
8554
|
+
type: "clipboard.cut",
|
|
8555
|
+
originEvent: {
|
|
8556
|
+
dataTransfer: event_0.nativeEvent.clipboardData
|
|
8557
|
+
},
|
|
8558
|
+
position: position_0
|
|
9278
8559
|
},
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
});
|
|
8560
|
+
editor: slateEditor,
|
|
8561
|
+
nativeEvent: event_0
|
|
8562
|
+
});
|
|
8563
|
+
}
|
|
9284
8564
|
}
|
|
9285
8565
|
}, $[82] = editorActor, $[83] = onCut, $[84] = slateEditor, $[85] = t19) : t19 = $[85];
|
|
9286
8566
|
const handleCut = t19;
|
|
@@ -9491,8 +8771,8 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9491
8771
|
};
|
|
9492
8772
|
}, t29 = [slateEditor, editorActor], $[119] = editorActor, $[120] = slateEditor, $[121] = t28, $[122] = t29) : (t28 = $[121], t29 = $[122]), useEffect(t28, t29);
|
|
9493
8773
|
let t30;
|
|
9494
|
-
$[123] !== editorActor || $[124] !== onDragStart || $[125] !== slateEditor ? (t30 = (event_8) => {
|
|
9495
|
-
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
8774
|
+
$[123] !== editorActor || $[124] !== onDragStart || $[125] !== readOnly || $[126] !== slateEditor ? (t30 = (event_8) => {
|
|
8775
|
+
if (readOnly || !ReactEditor.hasTarget(slateEditor, event_8.target) || (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped()))
|
|
9496
8776
|
return;
|
|
9497
8777
|
const position_4 = getEventPosition({
|
|
9498
8778
|
editorActor,
|
|
@@ -9519,10 +8799,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9519
8799
|
},
|
|
9520
8800
|
editor: slateEditor
|
|
9521
8801
|
}), !0;
|
|
9522
|
-
}, $[123] = editorActor, $[124] = onDragStart, $[125] =
|
|
8802
|
+
}, $[123] = editorActor, $[124] = onDragStart, $[125] = readOnly, $[126] = slateEditor, $[127] = t30) : t30 = $[127];
|
|
9523
8803
|
const handleDragStart = t30;
|
|
9524
8804
|
let t31;
|
|
9525
|
-
$[
|
|
8805
|
+
$[128] !== editorActor || $[129] !== onDrag || $[130] !== slateEditor ? (t31 = (event_9) => {
|
|
9526
8806
|
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
9527
8807
|
editorActor,
|
|
9528
8808
|
slateEditor,
|
|
@@ -9538,10 +8818,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9538
8818
|
},
|
|
9539
8819
|
editor: slateEditor
|
|
9540
8820
|
}), !0;
|
|
9541
|
-
}, $[
|
|
8821
|
+
}, $[128] = editorActor, $[129] = onDrag, $[130] = slateEditor, $[131] = t31) : t31 = $[131];
|
|
9542
8822
|
const handleDrag = t31;
|
|
9543
8823
|
let t32;
|
|
9544
|
-
$[
|
|
8824
|
+
$[132] !== editorActor || $[133] !== onDragEnd || $[134] !== slateEditor ? (t32 = (event_10) => {
|
|
9545
8825
|
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
9546
8826
|
return editorActor.send({
|
|
9547
8827
|
type: "behavior event",
|
|
@@ -9553,10 +8833,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9553
8833
|
},
|
|
9554
8834
|
editor: slateEditor
|
|
9555
8835
|
}), !0;
|
|
9556
|
-
}, $[
|
|
8836
|
+
}, $[132] = editorActor, $[133] = onDragEnd, $[134] = slateEditor, $[135] = t32) : t32 = $[135];
|
|
9557
8837
|
const handleDragEnd = t32;
|
|
9558
8838
|
let t33;
|
|
9559
|
-
$[
|
|
8839
|
+
$[136] !== editorActor || $[137] !== onDragEnter || $[138] !== slateEditor ? (t33 = (event_11) => {
|
|
9560
8840
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
9561
8841
|
return;
|
|
9562
8842
|
const position_6 = getEventPosition({
|
|
@@ -9576,10 +8856,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9576
8856
|
},
|
|
9577
8857
|
editor: slateEditor
|
|
9578
8858
|
}), !0;
|
|
9579
|
-
}, $[
|
|
8859
|
+
}, $[136] = editorActor, $[137] = onDragEnter, $[138] = slateEditor, $[139] = t33) : t33 = $[139];
|
|
9580
8860
|
const handleDragEnter = t33;
|
|
9581
8861
|
let t34;
|
|
9582
|
-
$[
|
|
8862
|
+
$[140] !== editorActor || $[141] !== onDragOver || $[142] !== slateEditor ? (t34 = (event_12) => {
|
|
9583
8863
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
9584
8864
|
return;
|
|
9585
8865
|
const position_7 = getEventPosition({
|
|
@@ -9601,10 +8881,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9601
8881
|
editor: slateEditor,
|
|
9602
8882
|
nativeEvent: event_12
|
|
9603
8883
|
}), !0;
|
|
9604
|
-
}, $[
|
|
8884
|
+
}, $[140] = editorActor, $[141] = onDragOver, $[142] = slateEditor, $[143] = t34) : t34 = $[143];
|
|
9605
8885
|
const handleDragOver = t34;
|
|
9606
8886
|
let t35;
|
|
9607
|
-
$[
|
|
8887
|
+
$[144] !== editorActor || $[145] !== onDrop || $[146] !== slateEditor ? (t35 = (event_13) => {
|
|
9608
8888
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
9609
8889
|
return;
|
|
9610
8890
|
const position_8 = getEventPosition({
|
|
@@ -9629,10 +8909,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9629
8909
|
editor: slateEditor,
|
|
9630
8910
|
nativeEvent: event_13
|
|
9631
8911
|
}), !0;
|
|
9632
|
-
}, $[
|
|
8912
|
+
}, $[144] = editorActor, $[145] = onDrop, $[146] = slateEditor, $[147] = t35) : t35 = $[147];
|
|
9633
8913
|
const handleDrop = t35;
|
|
9634
8914
|
let t36;
|
|
9635
|
-
$[
|
|
8915
|
+
$[148] !== editorActor || $[149] !== onDragLeave || $[150] !== slateEditor ? (t36 = (event_14) => {
|
|
9636
8916
|
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
9637
8917
|
editorActor,
|
|
9638
8918
|
slateEditor,
|
|
@@ -9648,10 +8928,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9648
8928
|
},
|
|
9649
8929
|
editor: slateEditor
|
|
9650
8930
|
}), !0;
|
|
9651
|
-
}, $[
|
|
8931
|
+
}, $[148] = editorActor, $[149] = onDragLeave, $[150] = slateEditor, $[151] = t36) : t36 = $[151];
|
|
9652
8932
|
const handleDragLeave = t36;
|
|
9653
8933
|
let t37;
|
|
9654
|
-
$[
|
|
8934
|
+
$[152] !== forwardedRef || $[153] !== validateSelectionActor ? (t37 = (editorElement) => {
|
|
9655
8935
|
if (typeof forwardedRef == "function" ? forwardedRef(editorElement) : forwardedRef && (forwardedRef.current = editorElement), editorElement) {
|
|
9656
8936
|
const mutationObserver = new MutationObserver(() => {
|
|
9657
8937
|
validateSelectionActor.send({
|
|
@@ -9669,12 +8949,12 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
9669
8949
|
mutationObserver.disconnect();
|
|
9670
8950
|
};
|
|
9671
8951
|
}
|
|
9672
|
-
}, $[
|
|
8952
|
+
}, $[152] = forwardedRef, $[153] = validateSelectionActor, $[154] = t37) : t37 = $[154];
|
|
9673
8953
|
const callbackRef = t37;
|
|
9674
8954
|
if (!portableTextEditor)
|
|
9675
8955
|
return null;
|
|
9676
8956
|
let t38;
|
|
9677
|
-
return $[
|
|
8957
|
+
return $[155] !== callbackRef || $[156] !== decorate || $[157] !== editorActor || $[158] !== handleClick || $[159] !== handleCopy || $[160] !== handleCut || $[161] !== handleDrag || $[162] !== handleDragEnd || $[163] !== handleDragEnter || $[164] !== handleDragLeave || $[165] !== handleDragOver || $[166] !== handleDragStart || $[167] !== handleDrop || $[168] !== handleKeyDown || $[169] !== handleKeyUp || $[170] !== handleOnBeforeInput || $[171] !== handleOnBlur || $[172] !== handleOnFocus || $[173] !== handlePaste || $[174] !== hasInvalidValue || $[175] !== readOnly || $[176] !== renderElement || $[177] !== renderLeaf || $[178] !== restProps || $[179] !== scrollSelectionIntoViewToSlate ? (t38 = hasInvalidValue ? null : /* @__PURE__ */ jsx(SelectionStateProvider, { children: /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, editorActor, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderPlaceholder: void 0, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToSlate }) }), $[155] = callbackRef, $[156] = decorate, $[157] = editorActor, $[158] = handleClick, $[159] = handleCopy, $[160] = handleCut, $[161] = handleDrag, $[162] = handleDragEnd, $[163] = handleDragEnter, $[164] = handleDragLeave, $[165] = handleDragOver, $[166] = handleDragStart, $[167] = handleDrop, $[168] = handleKeyDown, $[169] = handleKeyUp, $[170] = handleOnBeforeInput, $[171] = handleOnBlur, $[172] = handleOnFocus, $[173] = handlePaste, $[174] = hasInvalidValue, $[175] = readOnly, $[176] = renderElement, $[177] = renderLeaf, $[178] = restProps, $[179] = scrollSelectionIntoViewToSlate, $[180] = t38) : t38 = $[180], t38;
|
|
9678
8958
|
});
|
|
9679
8959
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
9680
8960
|
function noop() {
|
|
@@ -9772,7 +9052,7 @@ const converterJson = {
|
|
|
9772
9052
|
originEvent: event.originEvent
|
|
9773
9053
|
} : {
|
|
9774
9054
|
type: "serialization.success",
|
|
9775
|
-
data:
|
|
9055
|
+
data: safeStringify(blocks),
|
|
9776
9056
|
mimeType: "application/x-portable-text",
|
|
9777
9057
|
originEvent: event.originEvent
|
|
9778
9058
|
};
|
|
@@ -9781,7 +9061,7 @@ const converterJson = {
|
|
|
9781
9061
|
snapshot,
|
|
9782
9062
|
event
|
|
9783
9063
|
}) => {
|
|
9784
|
-
const blocks =
|
|
9064
|
+
const blocks = safeParse(event.data);
|
|
9785
9065
|
if (!Array.isArray(blocks))
|
|
9786
9066
|
return {
|
|
9787
9067
|
type: "deserialization.failure",
|
|
@@ -10539,8 +9819,6 @@ function createBehaviorApiPlugin(editorActor) {
|
|
|
10539
9819
|
},
|
|
10540
9820
|
editor
|
|
10541
9821
|
});
|
|
10542
|
-
}, editor.setFragmentData = () => {
|
|
10543
|
-
console.error("Unexpected call to .setFragmentData(...)");
|
|
10544
9822
|
}, editor.undo = () => {
|
|
10545
9823
|
if (editor.isNormalizingNode || editor.isPerformingBehaviorOperation) {
|
|
10546
9824
|
console.error("Unexpected call to .undo(...)");
|
|
@@ -10674,21 +9952,18 @@ function createHistoryPlugin({
|
|
|
10674
9952
|
}, editor;
|
|
10675
9953
|
};
|
|
10676
9954
|
}
|
|
10677
|
-
function applyInsertNodeAtPath(editor, node2, path2
|
|
10678
|
-
|
|
9955
|
+
function applyInsertNodeAtPath(editor, node2, path2) {
|
|
9956
|
+
editor.apply({
|
|
10679
9957
|
type: "insert_node",
|
|
10680
9958
|
path: path2,
|
|
10681
9959
|
node: node2
|
|
10682
|
-
})
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
}
|
|
9960
|
+
});
|
|
9961
|
+
const point2 = Editor.end(editor, path2);
|
|
9962
|
+
point2 && applySelect(editor, point2);
|
|
10686
9963
|
}
|
|
10687
|
-
function applyInsertNodeAtPoint(editor, node2, at
|
|
9964
|
+
function applyInsertNodeAtPoint(editor, node2, at) {
|
|
10688
9965
|
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, {
|
|
9966
|
+
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
9967
|
at: at.path,
|
|
10693
9968
|
match: match2,
|
|
10694
9969
|
mode: "lowest",
|
|
@@ -10702,14 +9977,13 @@ function applyInsertNodeAtPoint(editor, node2, at, options = {}) {
|
|
|
10702
9977
|
applySplitNode(editor, at.path, at.offset, properties);
|
|
10703
9978
|
}
|
|
10704
9979
|
const path2 = pathRef2.unref(), insertPath = isAtEnd ? Path.next(path2) : path2;
|
|
10705
|
-
|
|
9980
|
+
editor.apply({
|
|
10706
9981
|
type: "insert_node",
|
|
10707
9982
|
path: insertPath,
|
|
10708
9983
|
node: node2
|
|
10709
|
-
})
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
}
|
|
9984
|
+
});
|
|
9985
|
+
const point2 = Editor.end(editor, insertPath);
|
|
9986
|
+
point2 && applySelect(editor, point2);
|
|
10713
9987
|
});
|
|
10714
9988
|
}
|
|
10715
9989
|
function withNormalizeNode(editor, fn) {
|
|
@@ -10730,9 +10004,7 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10730
10004
|
const [node2, path2] = nodeEntry;
|
|
10731
10005
|
if (Editor.isEditor(node2) && node2.children.length === 0 && withoutPatching(editor, () => {
|
|
10732
10006
|
withNormalizeNode(editor, () => {
|
|
10733
|
-
applyInsertNodeAtPath(editor, createPlaceholderBlock(editorActor.getSnapshot().context), [0]
|
|
10734
|
-
select: !0
|
|
10735
|
-
});
|
|
10007
|
+
applyInsertNodeAtPath(editor, createPlaceholderBlock(editorActor.getSnapshot().context), [0]);
|
|
10736
10008
|
});
|
|
10737
10009
|
}), editor.isTextBlock(node2)) {
|
|
10738
10010
|
const children = Node$1.children(editor, path2, editor.schema);
|
|
@@ -10740,11 +10012,8 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10740
10012
|
const nextNode = node2.children[childPath[1] + 1];
|
|
10741
10013
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
10742
10014
|
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);
|
|
10015
|
+
const mergePath = [childPath[0], childPath[1] + 1];
|
|
10016
|
+
applyMergeNode(editor, mergePath, child.text.length);
|
|
10748
10017
|
});
|
|
10749
10018
|
return;
|
|
10750
10019
|
}
|
|
@@ -12040,7 +11309,7 @@ function setNodePatch(schema, children, operation) {
|
|
|
12040
11309
|
}
|
|
12041
11310
|
throw new Error("Could not find a valid block");
|
|
12042
11311
|
} else
|
|
12043
|
-
throw new Error(`Unexpected path encountered: ${
|
|
11312
|
+
throw new Error(`Unexpected path encountered: ${safeStringify(operation.path)}`);
|
|
12044
11313
|
}
|
|
12045
11314
|
function insertNodePatch(schema, children, operation, beforeValue) {
|
|
12046
11315
|
const block = beforeValue[operation.path[0]];
|
|
@@ -12077,7 +11346,7 @@ function removeNodePatch(schema, beforeValue, operation) {
|
|
|
12077
11346
|
schema
|
|
12078
11347
|
}, block) && operation.path.length === 2) {
|
|
12079
11348
|
const spanToRemove = block.children[operation.path[1]];
|
|
12080
|
-
return spanToRemove ? block.children.filter((span) => span._key === operation.node._key).length > 1 ? (console.warn(`Multiple spans have \`_key\` ${operation.node._key}. It's ambiguous which one to remove.`,
|
|
11349
|
+
return spanToRemove ? block.children.filter((span) => span._key === operation.node._key).length > 1 ? (console.warn(`Multiple spans have \`_key\` ${operation.node._key}. It's ambiguous which one to remove.`, safeStringify(block, 2)), []) : [unset([{
|
|
12081
11350
|
_key: block._key
|
|
12082
11351
|
}, "children", {
|
|
12083
11352
|
_key: spanToRemove._key
|
|
@@ -12118,9 +11387,9 @@ function createPatchesPlugin({
|
|
|
12118
11387
|
pluginWithoutHistory(editor, () => {
|
|
12119
11388
|
for (const patch of patches)
|
|
12120
11389
|
try {
|
|
12121
|
-
changed = applyPatch(editor, patch), changed ? debug$1.syncPatch(`(applied) ${
|
|
11390
|
+
changed = applyPatch(editor, patch), changed ? debug$1.syncPatch(`(applied) ${safeStringify(patch, 2)}`) : debug$1.syncPatch(`(ignored) ${safeStringify(patch, 2)}`);
|
|
12122
11391
|
} catch (error) {
|
|
12123
|
-
console.error(`Applying patch ${
|
|
11392
|
+
console.error(`Applying patch ${safeStringify(patch)} failed due to: ${error instanceof Error ? error.message : error}`);
|
|
12124
11393
|
}
|
|
12125
11394
|
});
|
|
12126
11395
|
});
|
|
@@ -12387,7 +11656,7 @@ function updateValuePlugin(context, editor) {
|
|
|
12387
11656
|
} = editor;
|
|
12388
11657
|
return editor.apply = (operation) => {
|
|
12389
11658
|
if (editor.isNormalizingNode && debug$1.normalization(`(slate operation)
|
|
12390
|
-
${
|
|
11659
|
+
${safeStringify(operation, 2)}`), operation.type === "set_selection") {
|
|
12391
11660
|
apply2(operation);
|
|
12392
11661
|
return;
|
|
12393
11662
|
}
|
|
@@ -13944,7 +13213,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
13944
13213
|
}
|
|
13945
13214
|
});
|
|
13946
13215
|
if (!parsedAnnotation)
|
|
13947
|
-
throw new Error(`Failed to parse annotation ${
|
|
13216
|
+
throw new Error(`Failed to parse annotation ${safeStringify(operation.annotation)}`);
|
|
13948
13217
|
const editor = operation.editor, at = operation.at ? toSlateRange({
|
|
13949
13218
|
context: {
|
|
13950
13219
|
schema: context.schema,
|
|
@@ -14096,10 +13365,10 @@ const addAnnotationOperationImplementation = ({
|
|
|
14096
13365
|
}) => {
|
|
14097
13366
|
const blockIndex = operation.editor.blockIndexMap.get(operation.at[0]._key);
|
|
14098
13367
|
if (blockIndex === void 0)
|
|
14099
|
-
throw new Error(`Unable to find block index for block at ${
|
|
13368
|
+
throw new Error(`Unable to find block index for block at ${safeStringify(operation.at)}`);
|
|
14100
13369
|
const slateBlock = operation.editor.children.at(blockIndex);
|
|
14101
13370
|
if (!slateBlock)
|
|
14102
|
-
throw new Error(`Unable to find block at ${
|
|
13371
|
+
throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
|
|
14103
13372
|
if (isTextBlock(context, slateBlock)) {
|
|
14104
13373
|
const filteredProps = {};
|
|
14105
13374
|
for (const key of Object.keys(operation.props))
|
|
@@ -14154,7 +13423,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
14154
13423
|
throw new Error(`Unable to find block index for block key ${blockKey}`);
|
|
14155
13424
|
const slateBlock = blockIndex !== void 0 ? operation.editor.children.at(blockIndex) : void 0;
|
|
14156
13425
|
if (!slateBlock)
|
|
14157
|
-
throw new Error(`Unable to find block at ${
|
|
13426
|
+
throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
|
|
14158
13427
|
if (isTextBlock(context, slateBlock)) {
|
|
14159
13428
|
const propsToRemove = operation.props.filter((prop) => prop !== "_type" && prop !== "_key" && prop !== "children"), unsetProps2 = {};
|
|
14160
13429
|
for (const prop of propsToRemove)
|
|
@@ -14190,12 +13459,12 @@ const addAnnotationOperationImplementation = ({
|
|
|
14190
13459
|
blockIndexMap: operation.editor.blockIndexMap
|
|
14191
13460
|
});
|
|
14192
13461
|
if (!location)
|
|
14193
|
-
throw new Error(`Unable to convert ${
|
|
13462
|
+
throw new Error(`Unable to convert ${safeStringify(operation.at)} into a Slate Range`);
|
|
14194
13463
|
const childEntry = Editor.node(operation.editor, location, {
|
|
14195
13464
|
depth: 2
|
|
14196
13465
|
}), child = childEntry?.[0], childPath = childEntry?.[1];
|
|
14197
13466
|
if (!child || !childPath)
|
|
14198
|
-
throw new Error(`Unable to find child at ${
|
|
13467
|
+
throw new Error(`Unable to find child at ${safeStringify(operation.at)}`);
|
|
14199
13468
|
if (operation.editor.isTextSpan(child)) {
|
|
14200
13469
|
const {
|
|
14201
13470
|
_type,
|
|
@@ -14236,7 +13505,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
14236
13505
|
}, childPath);
|
|
14237
13506
|
return;
|
|
14238
13507
|
}
|
|
14239
|
-
throw new Error(`Unable to determine the type of child at ${
|
|
13508
|
+
throw new Error(`Unable to determine the type of child at ${safeStringify(operation.at)}`);
|
|
14240
13509
|
}, childUnsetOperationImplementation = ({
|
|
14241
13510
|
context,
|
|
14242
13511
|
operation
|
|
@@ -14246,20 +13515,20 @@ const addAnnotationOperationImplementation = ({
|
|
|
14246
13515
|
throw new Error(`Unable to find block index for block key ${blockKey}`);
|
|
14247
13516
|
const block = blockIndex !== void 0 ? operation.editor.children.at(blockIndex) : void 0;
|
|
14248
13517
|
if (!block)
|
|
14249
|
-
throw new Error(`Unable to find block at ${
|
|
13518
|
+
throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
|
|
14250
13519
|
if (!isTextBlock(context, block))
|
|
14251
|
-
throw new Error(`Block ${
|
|
13520
|
+
throw new Error(`Block ${safeStringify(blockKey)} is not a text block`);
|
|
14252
13521
|
const childKey = operation.at[2]._key;
|
|
14253
13522
|
if (!childKey)
|
|
14254
|
-
throw new Error(`Unable to find child key at ${
|
|
13523
|
+
throw new Error(`Unable to find child key at ${safeStringify(operation.at)}`);
|
|
14255
13524
|
const childIndex = block.children.findIndex((child2) => child2._key === childKey);
|
|
14256
13525
|
if (childIndex === -1)
|
|
14257
|
-
throw new Error(`Unable to find child at ${
|
|
13526
|
+
throw new Error(`Unable to find child at ${safeStringify(operation.at)}`);
|
|
14258
13527
|
const childEntry = Editor.node(operation.editor, [blockIndex, childIndex], {
|
|
14259
13528
|
depth: 2
|
|
14260
13529
|
}), child = childEntry?.[0], childPath = childEntry?.[1];
|
|
14261
13530
|
if (!child || !childPath)
|
|
14262
|
-
throw new Error(`Unable to find child at ${
|
|
13531
|
+
throw new Error(`Unable to find child at ${safeStringify(operation.at)}`);
|
|
14263
13532
|
if (operation.editor.isTextSpan(child)) {
|
|
14264
13533
|
const newNode = {};
|
|
14265
13534
|
for (const prop of operation.props)
|
|
@@ -14285,7 +13554,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
14285
13554
|
applySetNode(operation.editor, unsetProps, childPath);
|
|
14286
13555
|
return;
|
|
14287
13556
|
}
|
|
14288
|
-
throw new Error(`Unable to determine the type of child at ${
|
|
13557
|
+
throw new Error(`Unable to determine the type of child at ${safeStringify(operation.at)}`);
|
|
14289
13558
|
}, decoratorAddOperationImplementation = ({
|
|
14290
13559
|
context,
|
|
14291
13560
|
operation
|
|
@@ -14875,7 +14144,7 @@ const historyUndoOperationImplementation = ({
|
|
|
14875
14144
|
}
|
|
14876
14145
|
});
|
|
14877
14146
|
if (!parsedBlock)
|
|
14878
|
-
throw new Error(`Failed to parse block ${
|
|
14147
|
+
throw new Error(`Failed to parse block ${safeStringify(operation.block)}`);
|
|
14879
14148
|
const block = toSlateBlock(parsedBlock, {
|
|
14880
14149
|
schemaTypes: context.schema
|
|
14881
14150
|
});
|
|
@@ -15358,13 +14627,7 @@ function deleteSameBlockRange(editor, start2, end2) {
|
|
|
15358
14627
|
});
|
|
15359
14628
|
}
|
|
15360
14629
|
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
|
-
}
|
|
14630
|
+
Text$1.isText(startNodeAfter, editor.schema) && Text$1.isText(endNodeAfter, editor.schema) && applyMergeNode(editor, newEndPath, startNodeAfter.text.length);
|
|
15368
14631
|
}
|
|
15369
14632
|
function deleteCrossBlockRange(editor, start2, end2) {
|
|
15370
14633
|
const startBlockPath = [start2.path[0]];
|
|
@@ -15408,11 +14671,7 @@ function deleteCrossBlockRange(editor, start2, end2) {
|
|
|
15408
14671
|
markDefs: newMarkDefs
|
|
15409
14672
|
}, startBlockPath);
|
|
15410
14673
|
}
|
|
15411
|
-
|
|
15412
|
-
children: _,
|
|
15413
|
-
...properties
|
|
15414
|
-
} = endBlock;
|
|
15415
|
-
applyMergeNode(editor, adjustedEndBlockPath, startBlock.children.length, properties);
|
|
14674
|
+
applyMergeNode(editor, adjustedEndBlockPath, startBlock.children.length);
|
|
15416
14675
|
});
|
|
15417
14676
|
}
|
|
15418
14677
|
function deleteExpandedRange(editor, range2) {
|
|
@@ -15472,11 +14731,7 @@ const insertChildOperationImplementation = ({
|
|
|
15472
14731
|
const [focusSpan] = getFocusSpan({
|
|
15473
14732
|
editor: operation.editor
|
|
15474
14733
|
});
|
|
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;
|
|
14734
|
+
focusSpan ? applyInsertNodeAtPoint(operation.editor, span, focus) : applyInsertNodeAtPath(operation.editor, span, [focusBlockIndex, focusChildIndex + 1]), operation.editor.pendingSelection = operation.editor.selection;
|
|
15480
14735
|
return;
|
|
15481
14736
|
}
|
|
15482
14737
|
const inlineObject = parseInlineObject({
|
|
@@ -15498,11 +14753,7 @@ const insertChildOperationImplementation = ({
|
|
|
15498
14753
|
}, [focusSpan] = getFocusSpan({
|
|
15499
14754
|
editor: operation.editor
|
|
15500
14755
|
});
|
|
15501
|
-
focusSpan ? applyInsertNodeAtPoint(operation.editor, inlineNode, focus,
|
|
15502
|
-
select: !0
|
|
15503
|
-
}) : applyInsertNodeAtPath(operation.editor, inlineNode, [focusBlockIndex, focusChildIndex + 1], {
|
|
15504
|
-
select: !0
|
|
15505
|
-
});
|
|
14756
|
+
focusSpan ? applyInsertNodeAtPoint(operation.editor, inlineNode, focus) : applyInsertNodeAtPath(operation.editor, inlineNode, [focusBlockIndex, focusChildIndex + 1]);
|
|
15506
14757
|
return;
|
|
15507
14758
|
}
|
|
15508
14759
|
throw new Error("Unable to parse child");
|
|
@@ -15596,7 +14847,34 @@ const moveBackwardOperationImplementation = ({
|
|
|
15596
14847
|
const destinationBlockIndex = operation.editor.blockIndexMap.get(destinationKey);
|
|
15597
14848
|
if (destinationBlockIndex === void 0)
|
|
15598
14849
|
throw new Error("Failed to get block index from block key");
|
|
15599
|
-
|
|
14850
|
+
const editor = operation.editor, node2 = Node$1.get(editor, [originBlockIndex], editor.schema), savedSelection = editor.selection ? {
|
|
14851
|
+
anchor: {
|
|
14852
|
+
...editor.selection.anchor
|
|
14853
|
+
},
|
|
14854
|
+
focus: {
|
|
14855
|
+
...editor.selection.focus
|
|
14856
|
+
}
|
|
14857
|
+
} : null;
|
|
14858
|
+
if (Editor.withoutNormalizing(editor, () => {
|
|
14859
|
+
editor.apply({
|
|
14860
|
+
type: "remove_node",
|
|
14861
|
+
path: [originBlockIndex],
|
|
14862
|
+
node: node2
|
|
14863
|
+
}), editor.apply({
|
|
14864
|
+
type: "insert_node",
|
|
14865
|
+
path: [destinationBlockIndex],
|
|
14866
|
+
node: node2
|
|
14867
|
+
});
|
|
14868
|
+
}), savedSelection) {
|
|
14869
|
+
const fixPoint = (point2) => point2.path[0] === originBlockIndex ? {
|
|
14870
|
+
...point2,
|
|
14871
|
+
path: [destinationBlockIndex, ...point2.path.slice(1)]
|
|
14872
|
+
} : point2;
|
|
14873
|
+
editor.selection = {
|
|
14874
|
+
anchor: fixPoint(savedSelection.anchor),
|
|
14875
|
+
focus: fixPoint(savedSelection.focus)
|
|
14876
|
+
};
|
|
14877
|
+
}
|
|
15600
14878
|
}, moveForwardOperationImplementation = ({
|
|
15601
14879
|
operation
|
|
15602
14880
|
}) => {
|
|
@@ -17629,7 +16907,7 @@ function performEvent({
|
|
|
17629
16907
|
nativeEvent,
|
|
17630
16908
|
sendBack
|
|
17631
16909
|
}) {
|
|
17632
|
-
mode === "send" && !isNativeBehaviorEvent(event) && (editor.undoStepId = defaultKeyGenerator()), debug$1.behaviors(`(${mode}:${eventCategory(event)})`,
|
|
16910
|
+
mode === "send" && !isNativeBehaviorEvent(event) && (editor.undoStepId = defaultKeyGenerator()), debug$1.behaviors(`(${mode}:${eventCategory(event)})`, safeStringify(event, 2));
|
|
17633
16911
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
17634
16912
|
if (behavior.on === "*")
|
|
17635
16913
|
return !0;
|
|
@@ -17638,7 +16916,7 @@ function performEvent({
|
|
|
17638
16916
|
});
|
|
17639
16917
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
17640
16918
|
nativeEvent?.preventDefault(), mode === "send" && (editor.undoStepId = void 0), withPerformingBehaviorOperation(editor, () => {
|
|
17641
|
-
debug$1.operation(
|
|
16919
|
+
debug$1.operation(safeStringify(event, 2)), performOperation({
|
|
17642
16920
|
context: {
|
|
17643
16921
|
keyGenerator,
|
|
17644
16922
|
schema
|
|
@@ -17764,7 +17042,7 @@ function performEvent({
|
|
|
17764
17042
|
break;
|
|
17765
17043
|
}
|
|
17766
17044
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && (editor.undoStepId = void 0), withPerformingBehaviorOperation(editor, () => {
|
|
17767
|
-
debug$1.operation(
|
|
17045
|
+
debug$1.operation(safeStringify(event, 2)), performOperation({
|
|
17768
17046
|
context: {
|
|
17769
17047
|
keyGenerator,
|
|
17770
17048
|
schema
|
|
@@ -19052,7 +18330,7 @@ const syncValueCallback = ({
|
|
|
19052
18330
|
context
|
|
19053
18331
|
}) => {
|
|
19054
18332
|
const isBusy = context.slateEditor.isDeferringMutations || context.slateEditor.isProcessingRemoteChanges;
|
|
19055
|
-
return debug$1.syncValue(
|
|
18333
|
+
return debug$1.syncValue(safeStringify({
|
|
19056
18334
|
isBusy,
|
|
19057
18335
|
isDeferringMutations: context.slateEditor.isDeferringMutations,
|
|
19058
18336
|
isProcessingRemoteChanges: context.slateEditor.isProcessingRemoteChanges
|