@portabletext/editor 6.1.2 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
|
16
16
|
import { htmlToPortableText } from "@portabletext/html";
|
|
17
17
|
import { toHTML } from "@portabletext/to-html";
|
|
18
18
|
import { markdownToPortableText, portableTextToMarkdown } from "@portabletext/markdown";
|
|
19
|
-
import { applyAll, unset, insert, setIfMissing,
|
|
19
|
+
import { applyAll, set, unset, insert, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
20
20
|
import { EditorContext as EditorContext$1 } from "./_chunks-es/use-editor.js";
|
|
21
21
|
import { useEditor } from "./_chunks-es/use-editor.js";
|
|
22
22
|
const rootName = "pte:";
|
|
@@ -906,42 +906,6 @@ const debug$1 = {
|
|
|
906
906
|
}), transformSelection = !0;
|
|
907
907
|
break;
|
|
908
908
|
}
|
|
909
|
-
case "merge_node": {
|
|
910
|
-
const {
|
|
911
|
-
path: path2
|
|
912
|
-
} = op, index = path2[path2.length - 1], prevPath = Path.previous(path2), prevIndex = prevPath[prevPath.length - 1];
|
|
913
|
-
modifyChildren(editor, Path.parent(path2), editor.schema, (children) => {
|
|
914
|
-
const node2 = children[index], prev = children[prevIndex];
|
|
915
|
-
let newNode;
|
|
916
|
-
if (Text$1.isText(node2, editor.schema) && Text$1.isText(prev, editor.schema))
|
|
917
|
-
newNode = {
|
|
918
|
-
...prev,
|
|
919
|
-
text: prev.text + node2.text
|
|
920
|
-
};
|
|
921
|
-
else if (!Text$1.isText(node2, editor.schema) && !Text$1.isText(prev, editor.schema))
|
|
922
|
-
newNode = {
|
|
923
|
-
...prev,
|
|
924
|
-
children: prev.children.concat(node2.children)
|
|
925
|
-
};
|
|
926
|
-
else
|
|
927
|
-
throw new Error(`Cannot apply a "merge_node" operation at path [${path2}] to nodes of different interfaces: ${Scrubber.stringify(node2)} ${Scrubber.stringify(prev)}`);
|
|
928
|
-
return replaceChildren(children, prevIndex, 2, newNode);
|
|
929
|
-
}), transformSelection = !0;
|
|
930
|
-
break;
|
|
931
|
-
}
|
|
932
|
-
case "move_node": {
|
|
933
|
-
const {
|
|
934
|
-
path: path2,
|
|
935
|
-
newPath
|
|
936
|
-
} = op, index = path2[path2.length - 1];
|
|
937
|
-
if (Path.isAncestor(path2, newPath))
|
|
938
|
-
throw new Error(`Cannot move a path [${path2}] to new path [${newPath}] because the destination is inside itself.`);
|
|
939
|
-
const node2 = Node$1.get(editor, path2, editor.schema);
|
|
940
|
-
modifyChildren(editor, Path.parent(path2), editor.schema, (children) => removeChildren(children, index, 1));
|
|
941
|
-
const truePath = Path.transform(path2, op), newIndex = truePath[truePath.length - 1];
|
|
942
|
-
modifyChildren(editor, Path.parent(truePath), editor.schema, (children) => insertChildren(children, newIndex, node2)), transformSelection = !0;
|
|
943
|
-
break;
|
|
944
|
-
}
|
|
945
909
|
case "remove_node": {
|
|
946
910
|
const {
|
|
947
911
|
path: path2
|
|
@@ -1051,40 +1015,6 @@ const debug$1 = {
|
|
|
1051
1015
|
editor.selection = selection;
|
|
1052
1016
|
break;
|
|
1053
1017
|
}
|
|
1054
|
-
case "split_node": {
|
|
1055
|
-
const {
|
|
1056
|
-
path: path2,
|
|
1057
|
-
position,
|
|
1058
|
-
properties
|
|
1059
|
-
} = op, index = path2[path2.length - 1];
|
|
1060
|
-
if (path2.length === 0)
|
|
1061
|
-
throw new Error(`Cannot apply a "split_node" operation at path [${path2}] because the root node cannot be split.`);
|
|
1062
|
-
modifyChildren(editor, Path.parent(path2), editor.schema, (children) => {
|
|
1063
|
-
const node2 = children[index];
|
|
1064
|
-
let newNode, nextNode;
|
|
1065
|
-
if (Text$1.isText(node2, editor.schema)) {
|
|
1066
|
-
const before2 = node2.text.slice(0, position), after2 = node2.text.slice(position);
|
|
1067
|
-
newNode = {
|
|
1068
|
-
...node2,
|
|
1069
|
-
text: before2
|
|
1070
|
-
}, nextNode = {
|
|
1071
|
-
...properties,
|
|
1072
|
-
text: after2
|
|
1073
|
-
};
|
|
1074
|
-
} else {
|
|
1075
|
-
const before2 = node2.children.slice(0, position), after2 = node2.children.slice(position);
|
|
1076
|
-
newNode = {
|
|
1077
|
-
...node2,
|
|
1078
|
-
children: before2
|
|
1079
|
-
}, nextNode = {
|
|
1080
|
-
...properties,
|
|
1081
|
-
children: after2
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
return replaceChildren(children, index, 1, newNode, nextNode);
|
|
1085
|
-
}), transformSelection = !0;
|
|
1086
|
-
break;
|
|
1087
|
-
}
|
|
1088
1018
|
}
|
|
1089
1019
|
if (transformSelection && editor.selection) {
|
|
1090
1020
|
const selection = {
|
|
@@ -1099,17 +1029,8 @@ const debug$1 = {
|
|
|
1099
1029
|
insertNodes(editor, nodes2, options) {
|
|
1100
1030
|
editor.insertNodes(nodes2, options);
|
|
1101
1031
|
},
|
|
1102
|
-
mergeNodes(editor, options) {
|
|
1103
|
-
editor.mergeNodes(options);
|
|
1104
|
-
},
|
|
1105
|
-
moveNodes(editor, options) {
|
|
1106
|
-
editor.moveNodes(options);
|
|
1107
|
-
},
|
|
1108
1032
|
removeNodes(editor, options) {
|
|
1109
1033
|
editor.removeNodes(options);
|
|
1110
|
-
},
|
|
1111
|
-
splitNodes(editor, options) {
|
|
1112
|
-
editor.splitNodes(options);
|
|
1113
1034
|
}
|
|
1114
1035
|
}, SelectionTransforms = {
|
|
1115
1036
|
collapse(editor, options) {
|
|
@@ -1477,43 +1398,12 @@ const apply$1 = (editor, op) => {
|
|
|
1477
1398
|
} = op, levels2 = Path.levels(path2), descendants = Text$1.isText(node2, _editor.schema) ? [] : Array.from(Node$1.nodes(node2, _editor.schema), ([, p]) => path2.concat(p));
|
|
1478
1399
|
return [...levels2, ...descendants];
|
|
1479
1400
|
}
|
|
1480
|
-
case "merge_node": {
|
|
1481
|
-
const {
|
|
1482
|
-
path: path2
|
|
1483
|
-
} = op, ancestors = Path.ancestors(path2), previousPath = Path.previous(path2);
|
|
1484
|
-
return [...ancestors, previousPath];
|
|
1485
|
-
}
|
|
1486
|
-
case "move_node": {
|
|
1487
|
-
const {
|
|
1488
|
-
path: path2,
|
|
1489
|
-
newPath
|
|
1490
|
-
} = op;
|
|
1491
|
-
if (Path.equals(path2, newPath))
|
|
1492
|
-
return [];
|
|
1493
|
-
const oldAncestors = [], newAncestors = [];
|
|
1494
|
-
for (const ancestor of Path.ancestors(path2)) {
|
|
1495
|
-
const p = Path.transform(ancestor, op);
|
|
1496
|
-
oldAncestors.push(p);
|
|
1497
|
-
}
|
|
1498
|
-
for (const ancestor of Path.ancestors(newPath)) {
|
|
1499
|
-
const p = Path.transform(ancestor, op);
|
|
1500
|
-
newAncestors.push(p);
|
|
1501
|
-
}
|
|
1502
|
-
const newParent = newAncestors[newAncestors.length - 1], newIndex = newPath[newPath.length - 1], resultPath = newParent.concat(newIndex);
|
|
1503
|
-
return [...oldAncestors, ...newAncestors, resultPath];
|
|
1504
|
-
}
|
|
1505
1401
|
case "remove_node": {
|
|
1506
1402
|
const {
|
|
1507
1403
|
path: path2
|
|
1508
1404
|
} = op;
|
|
1509
1405
|
return [...Path.ancestors(path2)];
|
|
1510
1406
|
}
|
|
1511
|
-
case "split_node": {
|
|
1512
|
-
const {
|
|
1513
|
-
path: path2
|
|
1514
|
-
} = op, levels2 = Path.levels(path2), nextPath = Path.next(path2);
|
|
1515
|
-
return [...levels2, nextPath];
|
|
1516
|
-
}
|
|
1517
1407
|
default:
|
|
1518
1408
|
return [];
|
|
1519
1409
|
}
|
|
@@ -1522,7 +1412,135 @@ const apply$1 = (editor, op) => {
|
|
|
1522
1412
|
selection
|
|
1523
1413
|
} = editor;
|
|
1524
1414
|
return selection ? Node$1.fragment(editor, selection, editor.schema) : [];
|
|
1525
|
-
}
|
|
1415
|
+
};
|
|
1416
|
+
function applyMergeNode(editor, path2, position, properties) {
|
|
1417
|
+
const node2 = Node$1.get(editor, path2, editor.schema), prevPath = Path.previous(path2), mergeOp = {
|
|
1418
|
+
type: "merge_node",
|
|
1419
|
+
path: path2,
|
|
1420
|
+
position,
|
|
1421
|
+
properties
|
|
1422
|
+
};
|
|
1423
|
+
for (const ref of Editor.pathRefs(editor))
|
|
1424
|
+
PathRef.transform(ref, mergeOp);
|
|
1425
|
+
for (const ref of Editor.pointRefs(editor))
|
|
1426
|
+
PointRef.transform(ref, mergeOp);
|
|
1427
|
+
for (const ref of Editor.rangeRefs(editor))
|
|
1428
|
+
RangeRef.transform(ref, mergeOp);
|
|
1429
|
+
if (editor.selection) {
|
|
1430
|
+
const sel = {
|
|
1431
|
+
...editor.selection
|
|
1432
|
+
};
|
|
1433
|
+
for (const [point2, key] of Range.points(sel)) {
|
|
1434
|
+
const result = Point.transform(point2, mergeOp);
|
|
1435
|
+
result && (sel[key] = result);
|
|
1436
|
+
}
|
|
1437
|
+
editor.selection = sel;
|
|
1438
|
+
}
|
|
1439
|
+
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
1440
|
+
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
1441
|
+
const savedSelection = editor.selection, editorAny = editor, savedPendingDiffs = editorAny.pendingDiffs, savedPendingSelection = editorAny.pendingSelection, savedPendingAction = editorAny.pendingAction;
|
|
1442
|
+
if (Array.isArray(savedPendingDiffs) && savedPendingDiffs.length > 0 && (editorAny.pendingDiffs = savedPendingDiffs.map((textDiff) => transformTextDiffForMerge(textDiff, mergeOp)).filter(Boolean)), savedPendingSelection && typeof savedPendingSelection == "object" && "anchor" in savedPendingSelection && "focus" in savedPendingSelection) {
|
|
1443
|
+
const sel = savedPendingSelection, anchor = Point.transform(sel.anchor, mergeOp, {
|
|
1444
|
+
affinity: "backward"
|
|
1445
|
+
}), focus = Point.transform(sel.focus, mergeOp, {
|
|
1446
|
+
affinity: "backward"
|
|
1447
|
+
});
|
|
1448
|
+
editorAny.pendingSelection = anchor && focus ? {
|
|
1449
|
+
anchor,
|
|
1450
|
+
focus
|
|
1451
|
+
} : null;
|
|
1452
|
+
}
|
|
1453
|
+
if (savedPendingAction && typeof savedPendingAction == "object" && "at" in savedPendingAction) {
|
|
1454
|
+
const action = savedPendingAction;
|
|
1455
|
+
if (Point.isPoint(action.at)) {
|
|
1456
|
+
const at = Point.transform(action.at, mergeOp, {
|
|
1457
|
+
affinity: "backward"
|
|
1458
|
+
});
|
|
1459
|
+
editorAny.pendingAction = at ? {
|
|
1460
|
+
...action,
|
|
1461
|
+
at
|
|
1462
|
+
} : null;
|
|
1463
|
+
} else if (Range.isRange(action.at)) {
|
|
1464
|
+
const anchor = Point.transform(action.at.anchor, mergeOp, {
|
|
1465
|
+
affinity: "backward"
|
|
1466
|
+
}), focus = Point.transform(action.at.focus, mergeOp, {
|
|
1467
|
+
affinity: "backward"
|
|
1468
|
+
});
|
|
1469
|
+
editorAny.pendingAction = anchor && focus ? {
|
|
1470
|
+
...action,
|
|
1471
|
+
at: {
|
|
1472
|
+
anchor,
|
|
1473
|
+
focus
|
|
1474
|
+
}
|
|
1475
|
+
} : null;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
const preTransformedPendingDiffs = editorAny.pendingDiffs, preTransformedPendingSelection = editorAny.pendingSelection, preTransformedPendingAction = editorAny.pendingAction;
|
|
1479
|
+
editorAny.pendingDiffs = [], editorAny.pendingSelection = null, editorAny.pendingAction = null;
|
|
1480
|
+
try {
|
|
1481
|
+
Editor.withoutNormalizing(editor, () => {
|
|
1482
|
+
if (Text$1.isText(node2, editor.schema))
|
|
1483
|
+
node2.text.length > 0 && editor.apply({
|
|
1484
|
+
type: "insert_text",
|
|
1485
|
+
path: prevPath,
|
|
1486
|
+
offset: position,
|
|
1487
|
+
text: node2.text
|
|
1488
|
+
}), editor.apply({
|
|
1489
|
+
type: "remove_node",
|
|
1490
|
+
path: path2,
|
|
1491
|
+
node: node2
|
|
1492
|
+
});
|
|
1493
|
+
else if (Element$2.isElement(node2, editor.schema)) {
|
|
1494
|
+
const children = node2.children;
|
|
1495
|
+
for (let i = 0; i < children.length; i++)
|
|
1496
|
+
editor.apply({
|
|
1497
|
+
type: "insert_node",
|
|
1498
|
+
path: [...prevPath, position + i],
|
|
1499
|
+
node: children[i]
|
|
1500
|
+
});
|
|
1501
|
+
editor.apply({
|
|
1502
|
+
type: "remove_node",
|
|
1503
|
+
path: path2,
|
|
1504
|
+
node: node2
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
} finally {
|
|
1509
|
+
editor.selection = savedSelection;
|
|
1510
|
+
for (const ref of pathRefs)
|
|
1511
|
+
Editor.pathRefs(editor).add(ref);
|
|
1512
|
+
for (const ref of pointRefs)
|
|
1513
|
+
Editor.pointRefs(editor).add(ref);
|
|
1514
|
+
for (const ref of rangeRefs)
|
|
1515
|
+
Editor.rangeRefs(editor).add(ref);
|
|
1516
|
+
editorAny.pendingDiffs = preTransformedPendingDiffs, editorAny.pendingSelection = preTransformedPendingSelection, editorAny.pendingAction = preTransformedPendingAction;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
function transformTextDiffForMerge(textDiff, op) {
|
|
1520
|
+
const {
|
|
1521
|
+
path: path2,
|
|
1522
|
+
diff: diff2,
|
|
1523
|
+
id
|
|
1524
|
+
} = textDiff;
|
|
1525
|
+
if (!Path.equals(op.path, path2)) {
|
|
1526
|
+
const newPath = Path.transform(path2, op);
|
|
1527
|
+
return newPath ? {
|
|
1528
|
+
diff: diff2,
|
|
1529
|
+
id,
|
|
1530
|
+
path: newPath
|
|
1531
|
+
} : null;
|
|
1532
|
+
}
|
|
1533
|
+
return {
|
|
1534
|
+
diff: {
|
|
1535
|
+
start: diff2.start + op.position,
|
|
1536
|
+
end: diff2.end + op.position,
|
|
1537
|
+
text: diff2.text
|
|
1538
|
+
},
|
|
1539
|
+
id,
|
|
1540
|
+
path: Path.transform(path2, op)
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
const normalizeNode = (editor, entry) => {
|
|
1526
1544
|
const [node2, path2] = entry;
|
|
1527
1545
|
if (Text$1.isText(node2, editor.schema) || editor.isObjectNode(node2))
|
|
1528
1546
|
return;
|
|
@@ -1539,20 +1557,29 @@ const apply$1 = (editor, op) => {
|
|
|
1539
1557
|
if (element !== editor && (editor.isInline(element) || Text$1.isText(firstChild, editor.schema) || editor.isObjectNode(firstChild) || Element$2.isElement(firstChild, editor.schema) && editor.isInline(firstChild)))
|
|
1540
1558
|
for (let n2 = 0; n2 < element.children.length; n2++) {
|
|
1541
1559
|
const child = element.children[n2], prev = element.children[n2 - 1];
|
|
1542
|
-
if (Text$1.isText(child, editor.schema))
|
|
1543
|
-
prev != null && Text$1.isText(prev, editor.schema)
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1560
|
+
if (Text$1.isText(child, editor.schema)) {
|
|
1561
|
+
if (prev != null && Text$1.isText(prev, editor.schema)) {
|
|
1562
|
+
if (child.text === "")
|
|
1563
|
+
Transforms.removeNodes(editor, {
|
|
1564
|
+
at: path2.concat(n2),
|
|
1565
|
+
voids: !0
|
|
1566
|
+
}), element = Node$1.get(editor, path2, editor.schema), n2--;
|
|
1567
|
+
else if (prev.text === "")
|
|
1568
|
+
Transforms.removeNodes(editor, {
|
|
1569
|
+
at: path2.concat(n2 - 1),
|
|
1570
|
+
voids: !0
|
|
1571
|
+
}), element = Node$1.get(editor, path2, editor.schema), n2--;
|
|
1572
|
+
else if (Text$1.equals(child, prev, {
|
|
1573
|
+
loose: !0
|
|
1574
|
+
})) {
|
|
1575
|
+
const mergePath = path2.concat(n2), {
|
|
1576
|
+
text: _text,
|
|
1577
|
+
...properties
|
|
1578
|
+
} = child;
|
|
1579
|
+
applyMergeNode(editor, mergePath, prev.text.length, properties), element = Node$1.get(editor, path2, editor.schema), n2--;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
} else if (Element$2.isElement(child, editor.schema))
|
|
1556
1583
|
if (editor.isInline(child)) {
|
|
1557
1584
|
if (prev == null || !Text$1.isText(prev, editor.schema)) {
|
|
1558
1585
|
const newChild = editor.createSpan();
|
|
@@ -2147,7 +2174,77 @@ const previous = (editor, options = {}) => {
|
|
|
2147
2174
|
Editor.setNormalizing(editor, value);
|
|
2148
2175
|
}
|
|
2149
2176
|
Editor.normalize(editor);
|
|
2150
|
-
}, shouldMergeNodesRemovePrevNode = (_editor, [prevNode, prevPath], [_curNode, _curNodePath]) => Element$2.isElement(prevNode, _editor.schema) && (prevNode.children.length === 0 || prevNode.children.length === 1 && Text$1.isText(prevNode.children[0], _editor.schema) && prevNode.children[0].text === "") || Text$1.isText(prevNode, _editor.schema) && prevNode.text === "" && prevPath[prevPath.length - 1] !== 0
|
|
2177
|
+
}, shouldMergeNodesRemovePrevNode = (_editor, [prevNode, prevPath], [_curNode, _curNodePath]) => Element$2.isElement(prevNode, _editor.schema) && (prevNode.children.length === 0 || prevNode.children.length === 1 && Text$1.isText(prevNode.children[0], _editor.schema) && prevNode.children[0].text === "") || Text$1.isText(prevNode, _editor.schema) && prevNode.text === "" && prevPath[prevPath.length - 1] !== 0;
|
|
2178
|
+
function applySplitNode(editor, path2, position, properties) {
|
|
2179
|
+
const node2 = Node$1.get(editor, path2, editor.schema), splitOp = {
|
|
2180
|
+
type: "split_node",
|
|
2181
|
+
path: path2,
|
|
2182
|
+
position,
|
|
2183
|
+
properties
|
|
2184
|
+
};
|
|
2185
|
+
for (const ref of Editor.pathRefs(editor))
|
|
2186
|
+
PathRef.transform(ref, splitOp);
|
|
2187
|
+
for (const ref of Editor.pointRefs(editor))
|
|
2188
|
+
PointRef.transform(ref, splitOp);
|
|
2189
|
+
for (const ref of Editor.rangeRefs(editor))
|
|
2190
|
+
RangeRef.transform(ref, splitOp);
|
|
2191
|
+
if (editor.selection) {
|
|
2192
|
+
const sel = {
|
|
2193
|
+
...editor.selection
|
|
2194
|
+
};
|
|
2195
|
+
for (const [point2, key] of Range.points(sel))
|
|
2196
|
+
sel[key] = Point.transform(point2, splitOp);
|
|
2197
|
+
editor.selection = sel;
|
|
2198
|
+
}
|
|
2199
|
+
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
2200
|
+
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
2201
|
+
const savedSelection = editor.selection;
|
|
2202
|
+
try {
|
|
2203
|
+
Editor.withoutNormalizing(editor, () => {
|
|
2204
|
+
if (Text$1.isText(node2, editor.schema)) {
|
|
2205
|
+
const afterText = node2.text.slice(position), newNode = {
|
|
2206
|
+
...properties,
|
|
2207
|
+
text: afterText
|
|
2208
|
+
};
|
|
2209
|
+
editor.apply({
|
|
2210
|
+
type: "remove_text",
|
|
2211
|
+
path: path2,
|
|
2212
|
+
offset: position,
|
|
2213
|
+
text: afterText
|
|
2214
|
+
}), editor.apply({
|
|
2215
|
+
type: "insert_node",
|
|
2216
|
+
path: Path.next(path2),
|
|
2217
|
+
node: newNode
|
|
2218
|
+
});
|
|
2219
|
+
} else if (Element$2.isElement(node2, editor.schema)) {
|
|
2220
|
+
const afterChildren = node2.children.slice(position), newNode = {
|
|
2221
|
+
...properties,
|
|
2222
|
+
children: afterChildren
|
|
2223
|
+
};
|
|
2224
|
+
for (let i = node2.children.length - 1; i >= position; i--)
|
|
2225
|
+
editor.apply({
|
|
2226
|
+
type: "remove_node",
|
|
2227
|
+
path: [...path2, i],
|
|
2228
|
+
node: node2.children[i]
|
|
2229
|
+
});
|
|
2230
|
+
editor.apply({
|
|
2231
|
+
type: "insert_node",
|
|
2232
|
+
path: Path.next(path2),
|
|
2233
|
+
node: newNode
|
|
2234
|
+
});
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2237
|
+
} finally {
|
|
2238
|
+
editor.selection = savedSelection;
|
|
2239
|
+
for (const ref of pathRefs)
|
|
2240
|
+
Editor.pathRefs(editor).add(ref);
|
|
2241
|
+
for (const ref of pointRefs)
|
|
2242
|
+
Editor.pointRefs(editor).add(ref);
|
|
2243
|
+
for (const ref of rangeRefs)
|
|
2244
|
+
Editor.rangeRefs(editor).add(ref);
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
const insertNodes = (editor, nodes2, options = {}) => {
|
|
2151
2248
|
Editor.withoutNormalizing(editor, () => {
|
|
2152
2249
|
const {
|
|
2153
2250
|
hanging = !1,
|
|
@@ -2184,12 +2281,43 @@ const previous = (editor, options = {}) => {
|
|
|
2184
2281
|
});
|
|
2185
2282
|
if (entry) {
|
|
2186
2283
|
const [, matchPath2] = entry, pathRef2 = Editor.pathRef(editor, matchPath2), isAtEnd = Editor.isEnd(editor, at, matchPath2);
|
|
2187
|
-
|
|
2188
|
-
at,
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2284
|
+
{
|
|
2285
|
+
const splitAt = at, beforeRef = Editor.pointRef(editor, splitAt, {
|
|
2286
|
+
affinity: "backward"
|
|
2287
|
+
});
|
|
2288
|
+
let afterRef;
|
|
2289
|
+
try {
|
|
2290
|
+
const [highest] = Editor.nodes(editor, {
|
|
2291
|
+
at: splitAt,
|
|
2292
|
+
match: match2,
|
|
2293
|
+
mode,
|
|
2294
|
+
voids
|
|
2295
|
+
});
|
|
2296
|
+
if (highest) {
|
|
2297
|
+
afterRef = Editor.pointRef(editor, splitAt);
|
|
2298
|
+
const depth = splitAt.path.length, [, highestPath] = highest, lowestPath = splitAt.path.slice(0, depth);
|
|
2299
|
+
let position = splitAt.offset;
|
|
2300
|
+
for (const [node22, nodePath] of Editor.levels(editor, {
|
|
2301
|
+
at: lowestPath,
|
|
2302
|
+
reverse: !0,
|
|
2303
|
+
voids
|
|
2304
|
+
})) {
|
|
2305
|
+
let split = !1;
|
|
2306
|
+
if (nodePath.length < highestPath.length || nodePath.length === 0)
|
|
2307
|
+
break;
|
|
2308
|
+
const point2 = beforeRef.current, isEndOfNode = Editor.isEnd(editor, point2, nodePath);
|
|
2309
|
+
if (!Editor.isEdge(editor, point2, nodePath)) {
|
|
2310
|
+
split = !0;
|
|
2311
|
+
const properties = Node$1.extractProps(node22, editor.schema);
|
|
2312
|
+
applySplitNode(editor, nodePath, position, properties);
|
|
2313
|
+
}
|
|
2314
|
+
position = nodePath[nodePath.length - 1] + (split || isEndOfNode ? 1 : 0);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
} finally {
|
|
2318
|
+
beforeRef.unref(), afterRef?.unref();
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2193
2321
|
const path2 = pathRef2.unref();
|
|
2194
2322
|
at = isAtEnd ? Path.next(path2) : path2;
|
|
2195
2323
|
} else
|
|
@@ -2237,126 +2365,6 @@ const previous = (editor, options = {}) => {
|
|
|
2237
2365
|
}
|
|
2238
2366
|
}
|
|
2239
2367
|
});
|
|
2240
|
-
}, hasSingleChildNest = (editor, node2) => {
|
|
2241
|
-
if (Element$2.isElement(node2, editor.schema)) {
|
|
2242
|
-
const element = node2;
|
|
2243
|
-
return element.children.length === 1 ? hasSingleChildNest(editor, element.children[0]) : !1;
|
|
2244
|
-
} else return !Editor.isEditor(node2);
|
|
2245
|
-
}, mergeNodes = (editor, options = {}) => {
|
|
2246
|
-
Editor.withoutNormalizing(editor, () => {
|
|
2247
|
-
let {
|
|
2248
|
-
match: match2,
|
|
2249
|
-
at = editor.selection
|
|
2250
|
-
} = options;
|
|
2251
|
-
const {
|
|
2252
|
-
hanging = !1,
|
|
2253
|
-
voids = !1,
|
|
2254
|
-
mode = "lowest"
|
|
2255
|
-
} = options;
|
|
2256
|
-
if (!at)
|
|
2257
|
-
return;
|
|
2258
|
-
if (match2 == null)
|
|
2259
|
-
if (Path.isPath(at)) {
|
|
2260
|
-
const [parent2] = Editor.parent(editor, at);
|
|
2261
|
-
match2 = (n2) => parent2.children.includes(n2);
|
|
2262
|
-
} else
|
|
2263
|
-
match2 = (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2);
|
|
2264
|
-
if (!hanging && Range.isRange(at) && (at = Editor.unhangRange(editor, at, {
|
|
2265
|
-
voids
|
|
2266
|
-
})), Range.isRange(at))
|
|
2267
|
-
if (Range.isCollapsed(at))
|
|
2268
|
-
at = at.anchor;
|
|
2269
|
-
else {
|
|
2270
|
-
const [, end2] = Range.edges(at), pointRef2 = Editor.pointRef(editor, end2);
|
|
2271
|
-
Transforms.delete(editor, {
|
|
2272
|
-
at
|
|
2273
|
-
}), at = pointRef2.unref(), options.at == null && Transforms.select(editor, at);
|
|
2274
|
-
}
|
|
2275
|
-
const [current] = Editor.nodes(editor, {
|
|
2276
|
-
at,
|
|
2277
|
-
match: match2,
|
|
2278
|
-
voids,
|
|
2279
|
-
mode
|
|
2280
|
-
}), prev = Editor.previous(editor, {
|
|
2281
|
-
at,
|
|
2282
|
-
match: match2,
|
|
2283
|
-
voids,
|
|
2284
|
-
mode
|
|
2285
|
-
});
|
|
2286
|
-
if (!current || !prev)
|
|
2287
|
-
return;
|
|
2288
|
-
const [node2, path2] = current, [prevNode, prevPath] = prev;
|
|
2289
|
-
if (path2.length === 0 || prevPath.length === 0)
|
|
2290
|
-
return;
|
|
2291
|
-
const newPath = Path.next(prevPath), commonPath = Path.common(path2, prevPath), isPreviousSibling = Path.isSibling(path2, prevPath), levels2 = Array.from(Editor.levels(editor, {
|
|
2292
|
-
at: path2
|
|
2293
|
-
}), ([n2]) => n2).slice(commonPath.length).slice(0, -1), emptyAncestor = Editor.above(editor, {
|
|
2294
|
-
at: path2,
|
|
2295
|
-
mode: "highest",
|
|
2296
|
-
match: (n2) => levels2.includes(n2) && hasSingleChildNest(editor, n2)
|
|
2297
|
-
}), emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
|
|
2298
|
-
let properties, position;
|
|
2299
|
-
if (Text$1.isText(node2, editor.schema) && Text$1.isText(prevNode, editor.schema)) {
|
|
2300
|
-
const {
|
|
2301
|
-
text: _text,
|
|
2302
|
-
...rest
|
|
2303
|
-
} = node2;
|
|
2304
|
-
position = prevNode.text.length, properties = rest;
|
|
2305
|
-
} else if (Element$2.isElement(node2, editor.schema) && Element$2.isElement(prevNode, editor.schema)) {
|
|
2306
|
-
const {
|
|
2307
|
-
children: _children,
|
|
2308
|
-
...rest
|
|
2309
|
-
} = node2;
|
|
2310
|
-
position = prevNode.children.length, properties = rest;
|
|
2311
|
-
} else
|
|
2312
|
-
throw new Error(`Cannot merge the node at path [${path2}] with the previous sibling because it is not the same kind: ${Scrubber.stringify(node2)} ${Scrubber.stringify(prevNode)}`);
|
|
2313
|
-
isPreviousSibling || Transforms.moveNodes(editor, {
|
|
2314
|
-
at: path2,
|
|
2315
|
-
to: newPath,
|
|
2316
|
-
voids
|
|
2317
|
-
}), emptyRef && Transforms.removeNodes(editor, {
|
|
2318
|
-
at: emptyRef.current,
|
|
2319
|
-
voids
|
|
2320
|
-
}), Editor.shouldMergeNodesRemovePrevNode(editor, prev, current) ? Transforms.removeNodes(editor, {
|
|
2321
|
-
at: prevPath,
|
|
2322
|
-
voids
|
|
2323
|
-
}) : editor.apply({
|
|
2324
|
-
type: "merge_node",
|
|
2325
|
-
path: newPath,
|
|
2326
|
-
position,
|
|
2327
|
-
properties
|
|
2328
|
-
}), emptyRef && emptyRef.unref();
|
|
2329
|
-
});
|
|
2330
|
-
}, moveNodes = (editor, options) => {
|
|
2331
|
-
Editor.withoutNormalizing(editor, () => {
|
|
2332
|
-
const {
|
|
2333
|
-
to,
|
|
2334
|
-
at = editor.selection,
|
|
2335
|
-
mode = "lowest",
|
|
2336
|
-
voids = !1
|
|
2337
|
-
} = options;
|
|
2338
|
-
let {
|
|
2339
|
-
match: match2
|
|
2340
|
-
} = options;
|
|
2341
|
-
if (!at)
|
|
2342
|
-
return;
|
|
2343
|
-
match2 == null && (match2 = Path.isPath(at) ? matchPath(editor, at) : (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2));
|
|
2344
|
-
const toRef = Editor.pathRef(editor, to), targets = Editor.nodes(editor, {
|
|
2345
|
-
at,
|
|
2346
|
-
match: match2,
|
|
2347
|
-
mode,
|
|
2348
|
-
voids
|
|
2349
|
-
}), pathRefs = Array.from(targets, ([, p]) => Editor.pathRef(editor, p));
|
|
2350
|
-
for (const pathRef2 of pathRefs) {
|
|
2351
|
-
const path2 = pathRef2.unref(), newPath = toRef.current;
|
|
2352
|
-
path2.length !== 0 && editor.apply({
|
|
2353
|
-
type: "move_node",
|
|
2354
|
-
path: path2,
|
|
2355
|
-
newPath
|
|
2356
|
-
}), toRef.current && Path.isSibling(newPath, path2) && Path.isAfter(newPath, path2) && (toRef.current = Path.next(toRef.current));
|
|
2357
|
-
}
|
|
2358
|
-
toRef.unref();
|
|
2359
|
-
});
|
|
2360
2368
|
}, removeNodes = (editor, options = {}) => {
|
|
2361
2369
|
Editor.withoutNormalizing(editor, () => {
|
|
2362
2370
|
const {
|
|
@@ -2391,97 +2399,6 @@ const previous = (editor, options = {}) => {
|
|
|
2391
2399
|
}
|
|
2392
2400
|
}
|
|
2393
2401
|
});
|
|
2394
|
-
}, deleteRange = (editor, range2) => {
|
|
2395
|
-
if (Range.isCollapsed(range2))
|
|
2396
|
-
return range2.anchor;
|
|
2397
|
-
{
|
|
2398
|
-
const [, end2] = Range.edges(range2), pointRef2 = Editor.pointRef(editor, end2);
|
|
2399
|
-
return Transforms.delete(editor, {
|
|
2400
|
-
at: range2
|
|
2401
|
-
}), pointRef2.unref();
|
|
2402
|
-
}
|
|
2403
|
-
}, splitNodes = (editor, options = {}) => {
|
|
2404
|
-
Editor.withoutNormalizing(editor, () => {
|
|
2405
|
-
const {
|
|
2406
|
-
mode = "lowest",
|
|
2407
|
-
voids = !1
|
|
2408
|
-
} = options;
|
|
2409
|
-
let {
|
|
2410
|
-
match: match2,
|
|
2411
|
-
at = editor.selection,
|
|
2412
|
-
height = 0,
|
|
2413
|
-
always = !1
|
|
2414
|
-
} = options;
|
|
2415
|
-
if (match2 == null && (match2 = (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2)), Range.isRange(at) && (at = deleteRange(editor, at)), Path.isPath(at)) {
|
|
2416
|
-
const path2 = at, point2 = Editor.point(editor, path2), [parent2] = Editor.parent(editor, path2);
|
|
2417
|
-
match2 = (n2) => n2 === parent2, height = point2.path.length - path2.length + 1, at = point2, always = !0;
|
|
2418
|
-
}
|
|
2419
|
-
if (!at)
|
|
2420
|
-
return;
|
|
2421
|
-
const beforeRef = Editor.pointRef(editor, at, {
|
|
2422
|
-
affinity: "backward"
|
|
2423
|
-
});
|
|
2424
|
-
let afterRef;
|
|
2425
|
-
try {
|
|
2426
|
-
const [highest] = Editor.nodes(editor, {
|
|
2427
|
-
at,
|
|
2428
|
-
match: match2,
|
|
2429
|
-
mode,
|
|
2430
|
-
voids
|
|
2431
|
-
});
|
|
2432
|
-
if (!highest)
|
|
2433
|
-
return;
|
|
2434
|
-
const voidMatch = Editor.void(editor, {
|
|
2435
|
-
at,
|
|
2436
|
-
mode: "highest"
|
|
2437
|
-
}), nudge = 0;
|
|
2438
|
-
if (!voids && voidMatch) {
|
|
2439
|
-
const [voidNode, voidPath] = voidMatch;
|
|
2440
|
-
if (Element$2.isElement(voidNode, editor.schema) && editor.isInline(voidNode)) {
|
|
2441
|
-
let after2 = Editor.after(editor, voidPath);
|
|
2442
|
-
if (!after2) {
|
|
2443
|
-
const text = editor.createSpan(), afterPath = Path.next(voidPath);
|
|
2444
|
-
Transforms.insertNodes(editor, text, {
|
|
2445
|
-
at: afterPath,
|
|
2446
|
-
voids
|
|
2447
|
-
}), after2 = Editor.point(editor, afterPath);
|
|
2448
|
-
}
|
|
2449
|
-
at = after2, always = !0;
|
|
2450
|
-
}
|
|
2451
|
-
height = at.path.length - voidPath.length + 1, always = !0;
|
|
2452
|
-
}
|
|
2453
|
-
afterRef = Editor.pointRef(editor, at);
|
|
2454
|
-
const depth = at.path.length - height, [, highestPath] = highest, lowestPath = at.path.slice(0, depth);
|
|
2455
|
-
let position = height === 0 ? at.offset : at.path[depth] + nudge;
|
|
2456
|
-
for (const [node2, path2] of Editor.levels(editor, {
|
|
2457
|
-
at: lowestPath,
|
|
2458
|
-
reverse: !0,
|
|
2459
|
-
voids
|
|
2460
|
-
})) {
|
|
2461
|
-
let split = !1;
|
|
2462
|
-
if (path2.length < highestPath.length || path2.length === 0)
|
|
2463
|
-
break;
|
|
2464
|
-
const point2 = beforeRef.current, isEnd2 = Editor.isEnd(editor, point2, path2);
|
|
2465
|
-
if (always || !beforeRef || !Editor.isEdge(editor, point2, path2)) {
|
|
2466
|
-
split = !0;
|
|
2467
|
-
const properties = Node$1.extractProps(node2, editor.schema);
|
|
2468
|
-
editor.apply({
|
|
2469
|
-
type: "split_node",
|
|
2470
|
-
path: path2,
|
|
2471
|
-
position,
|
|
2472
|
-
properties
|
|
2473
|
-
});
|
|
2474
|
-
}
|
|
2475
|
-
position = path2[path2.length - 1] + (split || isEnd2 ? 1 : 0);
|
|
2476
|
-
}
|
|
2477
|
-
if (options.at == null) {
|
|
2478
|
-
const point2 = afterRef.current || Editor.end(editor, []);
|
|
2479
|
-
Transforms.select(editor, point2);
|
|
2480
|
-
}
|
|
2481
|
-
} finally {
|
|
2482
|
-
beforeRef.unref(), afterRef?.unref();
|
|
2483
|
-
}
|
|
2484
|
-
});
|
|
2485
2402
|
}, collapse = (editor, options = {}) => {
|
|
2486
2403
|
const {
|
|
2487
2404
|
edge = "anchor"
|
|
@@ -2568,7 +2485,68 @@ const previous = (editor, options = {}) => {
|
|
|
2568
2485
|
newProperties: newProps
|
|
2569
2486
|
});
|
|
2570
2487
|
}
|
|
2571
|
-
}
|
|
2488
|
+
};
|
|
2489
|
+
function applyMoveNode(editor, path2, newPath) {
|
|
2490
|
+
if (Path.equals(path2, newPath))
|
|
2491
|
+
return;
|
|
2492
|
+
if (Path.isAncestor(path2, newPath))
|
|
2493
|
+
throw new Error(`Cannot move a path [${path2}] to new path [${newPath}] because the destination is inside itself.`);
|
|
2494
|
+
const node2 = Node$1.get(editor, path2, editor.schema), moveOp = {
|
|
2495
|
+
type: "move_node",
|
|
2496
|
+
path: path2,
|
|
2497
|
+
newPath
|
|
2498
|
+
};
|
|
2499
|
+
for (const ref of Editor.pathRefs(editor))
|
|
2500
|
+
PathRef.transform(ref, moveOp);
|
|
2501
|
+
for (const ref of Editor.pointRefs(editor))
|
|
2502
|
+
PointRef.transform(ref, moveOp);
|
|
2503
|
+
for (const ref of Editor.rangeRefs(editor))
|
|
2504
|
+
RangeRef.transform(ref, moveOp);
|
|
2505
|
+
if (editor.selection) {
|
|
2506
|
+
const sel = {
|
|
2507
|
+
...editor.selection
|
|
2508
|
+
};
|
|
2509
|
+
for (const [point2, key] of Range.points(sel))
|
|
2510
|
+
sel[key] = Point.transform(point2, moveOp);
|
|
2511
|
+
editor.selection = sel;
|
|
2512
|
+
}
|
|
2513
|
+
const pathRefs = new Set(Editor.pathRefs(editor)), pointRefs = new Set(Editor.pointRefs(editor)), rangeRefs = new Set(Editor.rangeRefs(editor));
|
|
2514
|
+
Editor.pathRefs(editor).clear(), Editor.pointRefs(editor).clear(), Editor.rangeRefs(editor).clear();
|
|
2515
|
+
const savedSelection = editor.selection;
|
|
2516
|
+
try {
|
|
2517
|
+
Editor.withoutNormalizing(editor, () => {
|
|
2518
|
+
editor.apply({
|
|
2519
|
+
type: "remove_node",
|
|
2520
|
+
path: path2,
|
|
2521
|
+
node: node2
|
|
2522
|
+
}), editor.apply({
|
|
2523
|
+
type: "insert_node",
|
|
2524
|
+
path: newPath,
|
|
2525
|
+
node: node2
|
|
2526
|
+
});
|
|
2527
|
+
});
|
|
2528
|
+
} finally {
|
|
2529
|
+
editor.selection = savedSelection;
|
|
2530
|
+
for (const ref of pathRefs)
|
|
2531
|
+
Editor.pathRefs(editor).add(ref);
|
|
2532
|
+
for (const ref of pointRefs)
|
|
2533
|
+
Editor.pointRefs(editor).add(ref);
|
|
2534
|
+
for (const ref of rangeRefs)
|
|
2535
|
+
Editor.rangeRefs(editor).add(ref);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
function applySetNode(editor, props, path2) {
|
|
2539
|
+
const node2 = Node$1.get(editor, path2, editor.schema), propsRecord = props, properties = {}, newProperties = {};
|
|
2540
|
+
for (const key of Object.keys(propsRecord))
|
|
2541
|
+
key !== "children" && (key === "text" && !Element$2.isElement(node2, editor.schema) && !editor.isObjectNode(node2) || propsRecord[key] !== node2[key] && (node2.hasOwnProperty(key) && (properties[key] = node2[key]), propsRecord[key] != null && (newProperties[key] = propsRecord[key])));
|
|
2542
|
+
(Object.keys(newProperties).length > 0 || Object.keys(properties).length > 0) && editor.apply({
|
|
2543
|
+
type: "set_node",
|
|
2544
|
+
path: path2,
|
|
2545
|
+
properties,
|
|
2546
|
+
newProperties
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
const deleteText = (editor, options = {}) => {
|
|
2572
2550
|
Editor.withoutNormalizing(editor, () => {
|
|
2573
2551
|
const {
|
|
2574
2552
|
reverse = !1,
|
|
@@ -2693,11 +2671,71 @@ const previous = (editor, options = {}) => {
|
|
|
2693
2671
|
}), removedText = text);
|
|
2694
2672
|
}
|
|
2695
2673
|
}
|
|
2696
|
-
!isSingleText && isAcrossBlocks && endRef.current && startRef.current
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2674
|
+
if (!isSingleText && isAcrossBlocks && endRef.current && startRef.current) {
|
|
2675
|
+
const mergeAt = endRef.current, mergeMatch = (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2), [current] = Editor.nodes(editor, {
|
|
2676
|
+
at: mergeAt,
|
|
2677
|
+
match: mergeMatch,
|
|
2678
|
+
voids,
|
|
2679
|
+
mode: "lowest"
|
|
2680
|
+
}), prev = Editor.previous(editor, {
|
|
2681
|
+
at: mergeAt,
|
|
2682
|
+
match: mergeMatch,
|
|
2683
|
+
voids,
|
|
2684
|
+
mode: "lowest"
|
|
2685
|
+
});
|
|
2686
|
+
if (current && prev) {
|
|
2687
|
+
const [mergeNode, mergePath] = current, [prevNode, prevPath] = prev;
|
|
2688
|
+
if (mergePath.length !== 0 && prevPath.length !== 0) {
|
|
2689
|
+
const newPath = Path.next(prevPath), commonPath = Path.common(mergePath, prevPath), isPreviousSibling = Path.isSibling(mergePath, prevPath), levels2 = Array.from(Editor.levels(editor, {
|
|
2690
|
+
at: mergePath
|
|
2691
|
+
}), ([n2]) => n2).slice(commonPath.length).slice(0, -1), hasSingleChildNest = (node2) => {
|
|
2692
|
+
if (Element$2.isElement(node2, editor.schema)) {
|
|
2693
|
+
const element = node2;
|
|
2694
|
+
return element.children.length === 1 ? hasSingleChildNest(element.children[0]) : !1;
|
|
2695
|
+
} else return !Editor.isEditor(node2);
|
|
2696
|
+
}, emptyAncestor = Editor.above(editor, {
|
|
2697
|
+
at: mergePath,
|
|
2698
|
+
mode: "highest",
|
|
2699
|
+
match: (n2) => levels2.includes(n2) && hasSingleChildNest(n2)
|
|
2700
|
+
}), emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
|
|
2701
|
+
let properties, position;
|
|
2702
|
+
if (Text$1.isText(mergeNode, editor.schema) && Text$1.isText(prevNode, editor.schema)) {
|
|
2703
|
+
const {
|
|
2704
|
+
text: _text,
|
|
2705
|
+
...rest
|
|
2706
|
+
} = mergeNode;
|
|
2707
|
+
position = prevNode.text.length, properties = rest;
|
|
2708
|
+
} else if (Element$2.isElement(mergeNode, editor.schema) && Element$2.isElement(prevNode, editor.schema)) {
|
|
2709
|
+
const {
|
|
2710
|
+
children: _children,
|
|
2711
|
+
...rest
|
|
2712
|
+
} = mergeNode;
|
|
2713
|
+
position = prevNode.children.length, properties = rest;
|
|
2714
|
+
} else
|
|
2715
|
+
throw new Error(`Cannot merge the node at path [${mergePath}] with the previous sibling because it is not the same kind: ${Scrubber.stringify(mergeNode)} ${Scrubber.stringify(prevNode)}`);
|
|
2716
|
+
if (isPreviousSibling || applyMoveNode(editor, mergePath, newPath), emptyRef && Transforms.removeNodes(editor, {
|
|
2717
|
+
at: emptyRef.current,
|
|
2718
|
+
voids
|
|
2719
|
+
}), Editor.shouldMergeNodesRemovePrevNode(editor, prev, current))
|
|
2720
|
+
Transforms.removeNodes(editor, {
|
|
2721
|
+
at: prevPath,
|
|
2722
|
+
voids
|
|
2723
|
+
});
|
|
2724
|
+
else {
|
|
2725
|
+
const pteEditor = editor;
|
|
2726
|
+
if (pteEditor.isTextBlock(mergeNode) && pteEditor.isTextBlock(prevNode) && Array.isArray(mergeNode.markDefs) && mergeNode.markDefs.length > 0) {
|
|
2727
|
+
const targetPath = isPreviousSibling ? prevPath : Path.previous(newPath), oldDefs = Array.isArray(prevNode.markDefs) && prevNode.markDefs || [], newMarkDefs = [...new Map([...oldDefs, ...mergeNode.markDefs].map((def) => [def._key, def])).values()];
|
|
2728
|
+
applySetNode(pteEditor, {
|
|
2729
|
+
markDefs: newMarkDefs
|
|
2730
|
+
}, targetPath);
|
|
2731
|
+
}
|
|
2732
|
+
applyMergeNode(pteEditor, newPath, position, properties);
|
|
2733
|
+
}
|
|
2734
|
+
emptyRef && emptyRef.unref();
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
isCollapsed && reverse && unit === "character" && removedText.length > 1 && removedText.match(/[\u0980-\u09FF\u0E00-\u0E7F\u1000-\u109F\u0900-\u097F\u1780-\u17FF\u0D00-\u0D7F\u0B00-\u0B7F\u0A00-\u0A7F\u0B80-\u0BFF\u0C00-\u0C7F]+/) && Transforms.insertText(editor, removedText.slice(0, removedText.length - distance));
|
|
2701
2739
|
const startUnref = startRef.unref(), endUnref = endRef.unref(), point2 = reverse ? startUnref || endUnref : endUnref || startUnref;
|
|
2702
2740
|
options.at == null && point2 && Transforms.select(editor, point2);
|
|
2703
2741
|
});
|
|
@@ -2753,9 +2791,7 @@ const previous = (editor, options = {}) => {
|
|
|
2753
2791
|
isStart: (...args) => isStart(e, ...args),
|
|
2754
2792
|
leaf: (...args) => leaf(e, ...args),
|
|
2755
2793
|
levels: (...args) => levels(e, ...args),
|
|
2756
|
-
mergeNodes: (...args) => mergeNodes(e, ...args),
|
|
2757
2794
|
move: (...args) => move(e, ...args),
|
|
2758
|
-
moveNodes: (...args) => moveNodes(e, ...args),
|
|
2759
2795
|
next: (...args) => next(e, ...args),
|
|
2760
2796
|
node: (...args) => node(e, ...args),
|
|
2761
2797
|
nodes: (...args) => nodes(e, ...args),
|
|
@@ -2773,7 +2809,6 @@ const previous = (editor, options = {}) => {
|
|
|
2773
2809
|
select: (...args) => select(e, ...args),
|
|
2774
2810
|
setNormalizing: (...args) => setNormalizing(e, ...args),
|
|
2775
2811
|
setSelection: (...args) => setSelection$1(e, ...args),
|
|
2776
|
-
splitNodes: (...args) => splitNodes(e, ...args),
|
|
2777
2812
|
start: (...args) => start(e, ...args),
|
|
2778
2813
|
string: (...args) => string(e, ...args),
|
|
2779
2814
|
unhangRange: (...args) => unhangRange(e, ...args),
|
|
@@ -3525,46 +3560,6 @@ function transformTextDiff(textDiff, op) {
|
|
|
3525
3560
|
id,
|
|
3526
3561
|
path: path2
|
|
3527
3562
|
};
|
|
3528
|
-
case "split_node":
|
|
3529
|
-
return !Path.equals(op.path, path2) || op.position >= diff2.end ? {
|
|
3530
|
-
diff: diff2,
|
|
3531
|
-
id,
|
|
3532
|
-
path: Path.transform(path2, op, {
|
|
3533
|
-
affinity: "backward"
|
|
3534
|
-
})
|
|
3535
|
-
} : op.position > diff2.start ? {
|
|
3536
|
-
diff: {
|
|
3537
|
-
start: diff2.start,
|
|
3538
|
-
end: Math.min(op.position, diff2.end),
|
|
3539
|
-
text: diff2.text
|
|
3540
|
-
},
|
|
3541
|
-
id,
|
|
3542
|
-
path: path2
|
|
3543
|
-
} : {
|
|
3544
|
-
diff: {
|
|
3545
|
-
start: diff2.start - op.position,
|
|
3546
|
-
end: diff2.end - op.position,
|
|
3547
|
-
text: diff2.text
|
|
3548
|
-
},
|
|
3549
|
-
id,
|
|
3550
|
-
path: Path.transform(path2, op, {
|
|
3551
|
-
affinity: "forward"
|
|
3552
|
-
})
|
|
3553
|
-
};
|
|
3554
|
-
case "merge_node":
|
|
3555
|
-
return Path.equals(op.path, path2) ? {
|
|
3556
|
-
diff: {
|
|
3557
|
-
start: diff2.start + op.position,
|
|
3558
|
-
end: diff2.end + op.position,
|
|
3559
|
-
text: diff2.text
|
|
3560
|
-
},
|
|
3561
|
-
id,
|
|
3562
|
-
path: Path.transform(path2, op)
|
|
3563
|
-
} : {
|
|
3564
|
-
diff: diff2,
|
|
3565
|
-
id,
|
|
3566
|
-
path: Path.transform(path2, op)
|
|
3567
|
-
};
|
|
3568
3563
|
}
|
|
3569
3564
|
const newPath = Path.transform(path2, op);
|
|
3570
3565
|
return newPath ? {
|
|
@@ -3579,7 +3574,7 @@ const withDOM = (editor) => {
|
|
|
3579
3574
|
onChange
|
|
3580
3575
|
} = e;
|
|
3581
3576
|
return e.isNodeMapDirty = !1, e.domWindow = null, e.domElement = null, e.domPlaceholder = "", e.domPlaceholderElement = null, e.keyToElement = /* @__PURE__ */ new WeakMap(), e.nodeToIndex = /* @__PURE__ */ new WeakMap(), e.nodeToParent = /* @__PURE__ */ new WeakMap(), e.elementToNode = /* @__PURE__ */ new WeakMap(), e.nodeToElement = /* @__PURE__ */ new WeakMap(), e.nodeToKey = /* @__PURE__ */ new WeakMap(), e.readOnly = !1, e.focused = !1, e.composing = !1, e.userSelection = null, e.onContextChange = null, e.scheduleFlush = null, e.pendingInsertionMarks = null, e.userMarks = null, e.pendingDiffs = [], e.pendingAction = null, e.pendingSelection = null, e.forceRender = null, e.apply = (op) => {
|
|
3582
|
-
const matches = [],
|
|
3577
|
+
const matches = [], pendingDiffs = e.pendingDiffs;
|
|
3583
3578
|
if (pendingDiffs?.length) {
|
|
3584
3579
|
const transformed = pendingDiffs.map((textDiff) => transformTextDiff(textDiff, op)).filter(Boolean);
|
|
3585
3580
|
e.pendingDiffs = transformed;
|
|
@@ -3597,8 +3592,7 @@ const withDOM = (editor) => {
|
|
|
3597
3592
|
switch (op.type) {
|
|
3598
3593
|
case "insert_text":
|
|
3599
3594
|
case "remove_text":
|
|
3600
|
-
case "set_node":
|
|
3601
|
-
case "split_node": {
|
|
3595
|
+
case "set_node": {
|
|
3602
3596
|
matches.push(...getMatches(e, op.path));
|
|
3603
3597
|
break;
|
|
3604
3598
|
}
|
|
@@ -3611,27 +3605,10 @@ const withDOM = (editor) => {
|
|
|
3611
3605
|
matches.push(...getMatches(e, Path.parent(op.path)));
|
|
3612
3606
|
break;
|
|
3613
3607
|
}
|
|
3614
|
-
case "merge_node": {
|
|
3615
|
-
const prevPath = Path.previous(op.path);
|
|
3616
|
-
matches.push(...getMatches(e, prevPath));
|
|
3617
|
-
break;
|
|
3618
|
-
}
|
|
3619
|
-
case "move_node": {
|
|
3620
|
-
const commonPath = Path.common(Path.parent(op.path), Path.parent(op.newPath));
|
|
3621
|
-
matches.push(...getMatches(e, commonPath));
|
|
3622
|
-
let changedPath;
|
|
3623
|
-
Path.isBefore(op.path, op.newPath) ? (matches.push(...getMatches(e, Path.parent(op.path))), changedPath = op.newPath) : (matches.push(...getMatches(e, Path.parent(op.newPath))), changedPath = op.path);
|
|
3624
|
-
const changedNode = Node$1.get(editor, Path.parent(changedPath), editor.schema), changedNodeKey = DOMEditor.findKey(e, changedNode), changedPathRef = Editor.pathRef(e, Path.parent(changedPath));
|
|
3625
|
-
pathRefMatches.push([changedPathRef, changedNodeKey]);
|
|
3626
|
-
break;
|
|
3627
|
-
}
|
|
3628
3608
|
}
|
|
3629
3609
|
switch (apply2(op), op.type) {
|
|
3630
3610
|
case "insert_node":
|
|
3631
3611
|
case "remove_node":
|
|
3632
|
-
case "merge_node":
|
|
3633
|
-
case "move_node":
|
|
3634
|
-
case "split_node":
|
|
3635
3612
|
case "insert_text":
|
|
3636
3613
|
case "remove_text":
|
|
3637
3614
|
case "set_selection":
|
|
@@ -3641,13 +3618,6 @@ const withDOM = (editor) => {
|
|
|
3641
3618
|
const [node2] = Editor.node(e, path2);
|
|
3642
3619
|
e.nodeToKey.set(node2, key);
|
|
3643
3620
|
}
|
|
3644
|
-
for (const [pathRef2, key] of pathRefMatches) {
|
|
3645
|
-
if (pathRef2.current) {
|
|
3646
|
-
const [node2] = Editor.node(e, pathRef2.current);
|
|
3647
|
-
e.nodeToKey.set(node2, key);
|
|
3648
|
-
}
|
|
3649
|
-
pathRef2.unref();
|
|
3650
|
-
}
|
|
3651
3621
|
}, e.setFragmentData = (data) => {
|
|
3652
3622
|
const {
|
|
3653
3623
|
selection
|
|
@@ -3689,8 +3659,53 @@ const withDOM = (editor) => {
|
|
|
3689
3659
|
const lines = text.split(/\r\n|\r|\n/);
|
|
3690
3660
|
let split = !1;
|
|
3691
3661
|
for (const line of lines)
|
|
3692
|
-
split &&
|
|
3693
|
-
|
|
3662
|
+
split && Editor.withoutNormalizing(e, () => {
|
|
3663
|
+
let splitAt = null;
|
|
3664
|
+
if (e.selection)
|
|
3665
|
+
if (Range.isCollapsed(e.selection))
|
|
3666
|
+
splitAt = e.selection.anchor;
|
|
3667
|
+
else {
|
|
3668
|
+
const [, end2] = Range.edges(e.selection), pointRef2 = Editor.pointRef(e, end2);
|
|
3669
|
+
Transforms.delete(e, {
|
|
3670
|
+
at: e.selection
|
|
3671
|
+
}), splitAt = pointRef2.unref();
|
|
3672
|
+
}
|
|
3673
|
+
if (!splitAt)
|
|
3674
|
+
return;
|
|
3675
|
+
const splitMatch = (n2) => Element$2.isElement(n2, e.schema) && Editor.isBlock(e, n2), beforeRef = Editor.pointRef(e, splitAt, {
|
|
3676
|
+
affinity: "backward"
|
|
3677
|
+
});
|
|
3678
|
+
let afterRef;
|
|
3679
|
+
try {
|
|
3680
|
+
const [highest] = Editor.nodes(e, {
|
|
3681
|
+
at: splitAt,
|
|
3682
|
+
match: splitMatch,
|
|
3683
|
+
mode: "lowest",
|
|
3684
|
+
voids: !1
|
|
3685
|
+
});
|
|
3686
|
+
if (!highest)
|
|
3687
|
+
return;
|
|
3688
|
+
afterRef = Editor.pointRef(e, splitAt);
|
|
3689
|
+
const depth = splitAt.path.length, [, highestPath] = highest, lowestPath = splitAt.path.slice(0, depth);
|
|
3690
|
+
let position = splitAt.offset;
|
|
3691
|
+
for (const [node2, nodePath] of Editor.levels(e, {
|
|
3692
|
+
at: lowestPath,
|
|
3693
|
+
reverse: !0,
|
|
3694
|
+
voids: !1
|
|
3695
|
+
})) {
|
|
3696
|
+
let didSplit = !1;
|
|
3697
|
+
if (nodePath.length < highestPath.length || nodePath.length === 0)
|
|
3698
|
+
break;
|
|
3699
|
+
const point22 = beforeRef.current, isEndOfNode = Editor.isEnd(e, point22, nodePath);
|
|
3700
|
+
didSplit = !0;
|
|
3701
|
+
const properties = Node$1.extractProps(node2, e.schema);
|
|
3702
|
+
applySplitNode(e, nodePath, position, properties), position = nodePath[nodePath.length - 1] + (didSplit || isEndOfNode ? 1 : 0);
|
|
3703
|
+
}
|
|
3704
|
+
const point2 = afterRef.current || Editor.end(e, []);
|
|
3705
|
+
Transforms.select(e, point2);
|
|
3706
|
+
} finally {
|
|
3707
|
+
beforeRef.unref(), afterRef?.unref();
|
|
3708
|
+
}
|
|
3694
3709
|
}), e.insertText(line), split = !0;
|
|
3695
3710
|
return !0;
|
|
3696
3711
|
}
|
|
@@ -5601,8 +5616,8 @@ const reconcileChildren = (editor, {
|
|
|
5601
5616
|
}), childrenHelper = new ChildrenHelper(editor, children);
|
|
5602
5617
|
let treeLeaf;
|
|
5603
5618
|
for (; treeLeaf = chunkTreeHelper.readLeaf(); ) {
|
|
5604
|
-
const lookAhead = childrenHelper.lookAhead(treeLeaf.node, treeLeaf.key)
|
|
5605
|
-
if (lookAhead === -1
|
|
5619
|
+
const lookAhead = childrenHelper.lookAhead(treeLeaf.node, treeLeaf.key);
|
|
5620
|
+
if (lookAhead === -1) {
|
|
5606
5621
|
chunkTreeHelper.remove();
|
|
5607
5622
|
continue;
|
|
5608
5623
|
}
|
|
@@ -5622,13 +5637,11 @@ const reconcileChildren = (editor, {
|
|
|
5622
5637
|
onInsert?.(node2, childrenHelper.pointerIndex + relativeIndex);
|
|
5623
5638
|
});
|
|
5624
5639
|
}
|
|
5625
|
-
chunkTree.movedNodeKeys.clear();
|
|
5626
5640
|
}, getChunkTreeForNode = (editor, node2, options = {}) => {
|
|
5627
5641
|
const key = ReactEditor.findKey(editor, node2);
|
|
5628
5642
|
let chunkTree = editor.keyToChunkTree.get(key);
|
|
5629
5643
|
return chunkTree || (chunkTree = {
|
|
5630
5644
|
type: "root",
|
|
5631
|
-
movedNodeKeys: /* @__PURE__ */ new Set(),
|
|
5632
5645
|
modifiedChunks: /* @__PURE__ */ new Set(),
|
|
5633
5646
|
children: []
|
|
5634
5647
|
}, editor.keyToChunkTree.set(key, chunkTree)), options.reconcile && reconcileChildren(editor, {
|
|
@@ -7538,13 +7551,6 @@ const withReact = (editor) => {
|
|
|
7538
7551
|
onChange(options);
|
|
7539
7552
|
});
|
|
7540
7553
|
}, e.apply = (operation) => {
|
|
7541
|
-
if (operation.type === "move_node") {
|
|
7542
|
-
const parent2 = Node$1.parent(e, operation.path, e.schema);
|
|
7543
|
-
if (e.getChunkSize(parent2)) {
|
|
7544
|
-
const node2 = Node$1.get(e, operation.path, e.schema), chunkTree = getChunkTreeForNode(e, parent2), key = ReactEditor.findKey(e, node2);
|
|
7545
|
-
chunkTree.movedNodeKeys.add(key);
|
|
7546
|
-
}
|
|
7547
|
-
}
|
|
7548
7554
|
apply2(operation);
|
|
7549
7555
|
}, e;
|
|
7550
7556
|
}, EditorActorContext = createContext({}), IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
@@ -10693,12 +10699,7 @@ function applyInsertNodeAtPoint(editor, node2, at, options = {}) {
|
|
|
10693
10699
|
const [, matchPath2] = entry, pathRef2 = Editor.pathRef(editor, matchPath2), isAtEnd = Editor.isEnd(editor, at, matchPath2);
|
|
10694
10700
|
if (!Editor.isEdge(editor, at, matchPath2)) {
|
|
10695
10701
|
const textNode = Node$1.get(editor, at.path, editor.schema), properties = Node$1.extractProps(textNode, editor.schema);
|
|
10696
|
-
editor.
|
|
10697
|
-
type: "split_node",
|
|
10698
|
-
path: at.path,
|
|
10699
|
-
position: at.offset,
|
|
10700
|
-
properties
|
|
10701
|
-
});
|
|
10702
|
+
applySplitNode(editor, at.path, at.offset, properties);
|
|
10702
10703
|
}
|
|
10703
10704
|
const path2 = pathRef2.unref(), insertPath = isAtEnd ? Path.next(path2) : path2;
|
|
10704
10705
|
if (editor.apply({
|
|
@@ -10711,17 +10712,6 @@ function applyInsertNodeAtPoint(editor, node2, at, options = {}) {
|
|
|
10711
10712
|
}
|
|
10712
10713
|
});
|
|
10713
10714
|
}
|
|
10714
|
-
function applySetNode(editor, props, path2) {
|
|
10715
|
-
const node2 = Node$1.get(editor, path2, editor.schema), propsRecord = props, properties = {}, newProperties = {};
|
|
10716
|
-
for (const key of Object.keys(propsRecord))
|
|
10717
|
-
key !== "children" && (key === "text" && !Element$2.isElement(node2, editor.schema) && !editor.isObjectNode(node2) || propsRecord[key] !== node2[key] && (node2.hasOwnProperty(key) && (properties[key] = node2[key]), propsRecord[key] != null && (newProperties[key] = propsRecord[key])));
|
|
10718
|
-
(Object.keys(newProperties).length > 0 || Object.keys(properties).length > 0) && editor.apply({
|
|
10719
|
-
type: "set_node",
|
|
10720
|
-
path: path2,
|
|
10721
|
-
properties,
|
|
10722
|
-
newProperties
|
|
10723
|
-
});
|
|
10724
|
-
}
|
|
10725
10715
|
function withNormalizeNode(editor, fn) {
|
|
10726
10716
|
const prev = editor.isNormalizingNode;
|
|
10727
10717
|
editor.isNormalizingNode = !0, fn(), editor.isNormalizingNode = prev;
|
|
@@ -10754,12 +10744,7 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10754
10744
|
text: _text,
|
|
10755
10745
|
...properties
|
|
10756
10746
|
} = nextNode;
|
|
10757
|
-
editor.
|
|
10758
|
-
type: "merge_node",
|
|
10759
|
-
path: mergePath,
|
|
10760
|
-
position: child.text.length,
|
|
10761
|
-
properties
|
|
10762
|
-
});
|
|
10747
|
+
applyMergeNode(editor, mergePath, child.text.length, properties);
|
|
10763
10748
|
});
|
|
10764
10749
|
return;
|
|
10765
10750
|
}
|
|
@@ -10842,7 +10827,7 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10842
10827
|
return;
|
|
10843
10828
|
}
|
|
10844
10829
|
}
|
|
10845
|
-
if (editor.isTextBlock(node2)
|
|
10830
|
+
if (editor.isTextBlock(node2)) {
|
|
10846
10831
|
const newMarkDefs = (node2.markDefs || []).filter((def) => node2.children.find((child) => Text$1.isText(child, editor.schema) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
10847
10832
|
if (node2.markDefs && !isEqualMarkDefs(newMarkDefs, node2.markDefs)) {
|
|
10848
10833
|
debug$1.normalization("removing markDef not in use"), withNormalizeNode(editor, () => {
|
|
@@ -10890,16 +10875,6 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10890
10875
|
}
|
|
10891
10876
|
} else
|
|
10892
10877
|
editor.decoratorState = {};
|
|
10893
|
-
if (op.type === "merge_node" && op.path.length === 1 && "markDefs" in op.properties && op.properties._type === editorActor.getSnapshot().context.schema.block.name && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] - 1 >= 0) {
|
|
10894
|
-
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
10895
|
-
if (editor.isTextBlock(targetBlock)) {
|
|
10896
|
-
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = [...new Map([...oldDefs, ...op.properties.markDefs].map((def) => [def._key, def])).values()];
|
|
10897
|
-
debug$1.normalization("copying markDefs over to merged block", op), applySetNode(editor, {
|
|
10898
|
-
markDefs: newMarkDefs
|
|
10899
|
-
}, targetPath), apply2(op);
|
|
10900
|
-
return;
|
|
10901
|
-
}
|
|
10902
|
-
}
|
|
10903
10878
|
apply2(op);
|
|
10904
10879
|
}, editor;
|
|
10905
10880
|
};
|
|
@@ -12090,58 +12065,6 @@ function insertNodePatch(schema, children, operation, beforeValue) {
|
|
|
12090
12065
|
}
|
|
12091
12066
|
return [];
|
|
12092
12067
|
}
|
|
12093
|
-
function splitNodePatch(schema, children, operation, beforeValue) {
|
|
12094
|
-
const patches = [], splitBlock2 = children[operation.path[0]];
|
|
12095
|
-
if (!isTextBlock({
|
|
12096
|
-
schema
|
|
12097
|
-
}, splitBlock2))
|
|
12098
|
-
throw new Error(`Block with path ${JSON.stringify(operation.path[0])} is not a text block and can't be split`);
|
|
12099
|
-
if (operation.path.length === 1) {
|
|
12100
|
-
const oldBlock = beforeValue[operation.path[0]];
|
|
12101
|
-
if (isTextBlock({
|
|
12102
|
-
schema
|
|
12103
|
-
}, oldBlock)) {
|
|
12104
|
-
const nextBlock = children[operation.path[0] + 1];
|
|
12105
|
-
if (!nextBlock)
|
|
12106
|
-
return patches;
|
|
12107
|
-
const targetValue = nextBlock;
|
|
12108
|
-
targetValue && (patches.push(insert([targetValue], "after", [{
|
|
12109
|
-
_key: splitBlock2._key
|
|
12110
|
-
}])), oldBlock.children.slice(operation.position).forEach((span) => {
|
|
12111
|
-
const path2 = [{
|
|
12112
|
-
_key: oldBlock._key
|
|
12113
|
-
}, "children", {
|
|
12114
|
-
_key: span._key
|
|
12115
|
-
}];
|
|
12116
|
-
patches.push(unset(path2));
|
|
12117
|
-
}));
|
|
12118
|
-
}
|
|
12119
|
-
return patches;
|
|
12120
|
-
}
|
|
12121
|
-
if (operation.path.length === 2) {
|
|
12122
|
-
const splitSpan = splitBlock2.children[operation.path[1]];
|
|
12123
|
-
if (isSpan({
|
|
12124
|
-
schema
|
|
12125
|
-
}, splitSpan)) {
|
|
12126
|
-
const targetSpans = {
|
|
12127
|
-
children: splitBlock2.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
12128
|
-
}.children;
|
|
12129
|
-
patches.push(setIfMissing([], [{
|
|
12130
|
-
_key: splitBlock2._key
|
|
12131
|
-
}, "children"])), patches.push(insert(targetSpans, "after", [{
|
|
12132
|
-
_key: splitBlock2._key
|
|
12133
|
-
}, "children", {
|
|
12134
|
-
_key: splitSpan._key
|
|
12135
|
-
}])), patches.push(set(splitSpan.text, [{
|
|
12136
|
-
_key: splitBlock2._key
|
|
12137
|
-
}, "children", {
|
|
12138
|
-
_key: splitSpan._key
|
|
12139
|
-
}, "text"]));
|
|
12140
|
-
}
|
|
12141
|
-
return patches;
|
|
12142
|
-
}
|
|
12143
|
-
return patches;
|
|
12144
|
-
}
|
|
12145
12068
|
function removeNodePatch(schema, beforeValue, operation) {
|
|
12146
12069
|
const block = beforeValue[operation.path[0]];
|
|
12147
12070
|
if (operation.path.length === 1) {
|
|
@@ -12162,86 +12085,6 @@ function removeNodePatch(schema, beforeValue, operation) {
|
|
|
12162
12085
|
} else
|
|
12163
12086
|
return [];
|
|
12164
12087
|
}
|
|
12165
|
-
function mergeNodePatch(schema, children, operation, beforeValue) {
|
|
12166
|
-
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = children[operation.path[0]];
|
|
12167
|
-
if (operation.path.length === 1)
|
|
12168
|
-
if (block?._key) {
|
|
12169
|
-
const prevBlock = children[operation.path[0] - 1];
|
|
12170
|
-
if (!prevBlock)
|
|
12171
|
-
throw new Error("Previous block not found!");
|
|
12172
|
-
const newBlock = prevBlock;
|
|
12173
|
-
patches.push(set(newBlock, [{
|
|
12174
|
-
_key: newBlock._key
|
|
12175
|
-
}])), patches.push(unset([{
|
|
12176
|
-
_key: block._key
|
|
12177
|
-
}]));
|
|
12178
|
-
} else
|
|
12179
|
-
throw new Error("Target key not found!");
|
|
12180
|
-
else if (isTextBlock({
|
|
12181
|
-
schema
|
|
12182
|
-
}, block) && isTextBlock({
|
|
12183
|
-
schema
|
|
12184
|
-
}, updatedBlock) && operation.path.length === 2) {
|
|
12185
|
-
const updatedSpan = updatedBlock.children[operation.path[1] - 1] && isSpan({
|
|
12186
|
-
schema
|
|
12187
|
-
}, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && isSpan({
|
|
12188
|
-
schema
|
|
12189
|
-
}, block.children[operation.path[1]]) ? block.children[operation.path[1]] : void 0;
|
|
12190
|
-
if (updatedSpan) {
|
|
12191
|
-
const spansMatchingKey = block.children.filter((span) => span._key === updatedSpan._key);
|
|
12192
|
-
if (spansMatchingKey.length === 1) {
|
|
12193
|
-
const prevSpan = spansMatchingKey[0];
|
|
12194
|
-
isSpan({
|
|
12195
|
-
schema
|
|
12196
|
-
}, prevSpan) && prevSpan.text !== updatedSpan.text && patches.push(set(updatedSpan.text, [{
|
|
12197
|
-
_key: block._key
|
|
12198
|
-
}, "children", {
|
|
12199
|
-
_key: updatedSpan._key
|
|
12200
|
-
}, "text"]));
|
|
12201
|
-
} else
|
|
12202
|
-
console.warn(`Multiple spans have \`_key\` ${updatedSpan._key}. It's ambiguous which one to update.`, JSON.stringify(block, null, 2));
|
|
12203
|
-
}
|
|
12204
|
-
removedSpan && (block.children.filter((span) => span._key === removedSpan._key).length === 1 ? patches.push(unset([{
|
|
12205
|
-
_key: block._key
|
|
12206
|
-
}, "children", {
|
|
12207
|
-
_key: removedSpan._key
|
|
12208
|
-
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
12209
|
-
}
|
|
12210
|
-
return patches;
|
|
12211
|
-
}
|
|
12212
|
-
function moveNodePatch(schema, beforeValue, operation) {
|
|
12213
|
-
const patches = [], block = beforeValue[operation.path[0]], targetBlock = beforeValue[operation.newPath[0]];
|
|
12214
|
-
if (!targetBlock || !block)
|
|
12215
|
-
return patches;
|
|
12216
|
-
if (operation.path.length === 1) {
|
|
12217
|
-
const position = operation.path[0] > operation.newPath[0] ? "before" : "after";
|
|
12218
|
-
patches.push(unset([{
|
|
12219
|
-
_key: block._key
|
|
12220
|
-
}])), patches.push(insert([block], position, [{
|
|
12221
|
-
_key: targetBlock._key
|
|
12222
|
-
}]));
|
|
12223
|
-
} else if (operation.path.length === 2 && isTextBlock({
|
|
12224
|
-
schema
|
|
12225
|
-
}, block) && isTextBlock({
|
|
12226
|
-
schema
|
|
12227
|
-
}, targetBlock)) {
|
|
12228
|
-
const child = block.children[operation.path[1]], targetChild = targetBlock.children[operation.newPath[1]], position = operation.newPath[1] === targetBlock.children.length ? "after" : "before", childToInsert = block.children[operation.path[1]];
|
|
12229
|
-
if (!child || !targetChild || !childToInsert)
|
|
12230
|
-
return patches;
|
|
12231
|
-
patches.push(unset([{
|
|
12232
|
-
_key: block._key
|
|
12233
|
-
}, "children", {
|
|
12234
|
-
_key: child._key
|
|
12235
|
-
}])), patches.push(setIfMissing([], [{
|
|
12236
|
-
_key: targetBlock._key
|
|
12237
|
-
}, "children"])), patches.push(insert([childToInsert], position, [{
|
|
12238
|
-
_key: targetBlock._key
|
|
12239
|
-
}, "children", {
|
|
12240
|
-
_key: targetChild._key
|
|
12241
|
-
}]));
|
|
12242
|
-
}
|
|
12243
|
-
return patches;
|
|
12244
|
-
}
|
|
12245
12088
|
function withRemoteChanges(editor, fn) {
|
|
12246
12089
|
const prev = editor.isProcessingRemoteChanges;
|
|
12247
12090
|
editor.isProcessingRemoteChanges = !0, fn(), editor.isProcessingRemoteChanges = prev;
|
|
@@ -12313,23 +12156,14 @@ function createPatchesPlugin({
|
|
|
12313
12156
|
case "remove_node":
|
|
12314
12157
|
patches = [...patches, ...removeNodePatch(editorActor.getSnapshot().context.schema, previousValue, operation)];
|
|
12315
12158
|
break;
|
|
12316
|
-
case "split_node":
|
|
12317
|
-
patches = [...patches, ...splitNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
|
|
12318
|
-
break;
|
|
12319
12159
|
case "insert_node":
|
|
12320
12160
|
patches = [...patches, ...insertNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
|
|
12321
12161
|
break;
|
|
12322
12162
|
case "set_node":
|
|
12323
12163
|
patches = [...patches, ...setNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation)];
|
|
12324
12164
|
break;
|
|
12325
|
-
case "merge_node":
|
|
12326
|
-
patches = [...patches, ...mergeNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
|
|
12327
|
-
break;
|
|
12328
|
-
case "move_node":
|
|
12329
|
-
patches = [...patches, ...moveNodePatch(editorActor.getSnapshot().context.schema, previousValue, operation)];
|
|
12330
|
-
break;
|
|
12331
12165
|
}
|
|
12332
|
-
if (!editorWasEmpty && editorIsEmpty && ["
|
|
12166
|
+
if (!editorWasEmpty && editorIsEmpty && ["set_node", "remove_text", "remove_node"].includes(operation.type) && (patches = [...patches, unset([])], relayActor.send({
|
|
12333
12167
|
type: "unset",
|
|
12334
12168
|
previousValue
|
|
12335
12169
|
})), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0)
|
|
@@ -12418,23 +12252,6 @@ function createUniqueKeysPlugin(editorActor) {
|
|
|
12418
12252
|
apply2(operation);
|
|
12419
12253
|
return;
|
|
12420
12254
|
}
|
|
12421
|
-
if (operation.type === "split_node") {
|
|
12422
|
-
const _key = operation.properties._key && keyExistsAtPath({
|
|
12423
|
-
blockIndexMap: editor.blockIndexMap,
|
|
12424
|
-
context: {
|
|
12425
|
-
schema: context.schema,
|
|
12426
|
-
value: editor.children
|
|
12427
|
-
}
|
|
12428
|
-
}, operation.path, operation.properties._key) ? void 0 : operation.properties._key;
|
|
12429
|
-
apply2({
|
|
12430
|
-
...operation,
|
|
12431
|
-
properties: {
|
|
12432
|
-
...operation.properties,
|
|
12433
|
-
_key: _key === void 0 ? editorActor.getSnapshot().context.keyGenerator() : _key
|
|
12434
|
-
}
|
|
12435
|
-
});
|
|
12436
|
-
return;
|
|
12437
|
-
}
|
|
12438
12255
|
if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
|
|
12439
12256
|
const _key = operation.node._key && keyExistsAtPath({
|
|
12440
12257
|
blockIndexMap: editor.blockIndexMap,
|
|
@@ -12452,54 +12269,6 @@ function createUniqueKeysPlugin(editorActor) {
|
|
|
12452
12269
|
});
|
|
12453
12270
|
return;
|
|
12454
12271
|
}
|
|
12455
|
-
if (operation.type === "merge_node") {
|
|
12456
|
-
const index = operation.path[operation.path.length - 1], prevPath = Path.previous(operation.path), prevIndex = prevPath[prevPath.length - 1];
|
|
12457
|
-
if (operation.path.length !== 1 || prevPath.length !== 1) {
|
|
12458
|
-
apply2(operation);
|
|
12459
|
-
return;
|
|
12460
|
-
}
|
|
12461
|
-
const block = editor.children.at(index), previousBlock = editor.children.at(prevIndex);
|
|
12462
|
-
if (!block || !previousBlock) {
|
|
12463
|
-
apply2(operation);
|
|
12464
|
-
return;
|
|
12465
|
-
}
|
|
12466
|
-
if (!isTextBlock(editorActor.getSnapshot().context, block) || !isTextBlock(editorActor.getSnapshot().context, previousBlock)) {
|
|
12467
|
-
apply2(operation);
|
|
12468
|
-
return;
|
|
12469
|
-
}
|
|
12470
|
-
const previousBlockChildKeys = previousBlock.children.map((child) => child._key), previousBlockMarkDefKeys = previousBlock.markDefs?.map((markDef) => markDef._key) ?? [], markDefKeyMap = /* @__PURE__ */ new Map(), adjustedMarkDefs = block.markDefs?.map((markDef) => {
|
|
12471
|
-
if (previousBlockMarkDefKeys.includes(markDef._key)) {
|
|
12472
|
-
const newKey = editorActor.getSnapshot().context.keyGenerator();
|
|
12473
|
-
return markDefKeyMap.set(markDef._key, newKey), {
|
|
12474
|
-
...markDef,
|
|
12475
|
-
_key: newKey
|
|
12476
|
-
};
|
|
12477
|
-
}
|
|
12478
|
-
return markDef;
|
|
12479
|
-
});
|
|
12480
|
-
let childIndex = 0;
|
|
12481
|
-
for (const child of block.children) {
|
|
12482
|
-
if (isSpan(editorActor.getSnapshot().context, child)) {
|
|
12483
|
-
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
12484
|
-
isEqualMarks(child.marks, marks) || applySetNode(editor, {
|
|
12485
|
-
marks
|
|
12486
|
-
}, [index, childIndex]);
|
|
12487
|
-
}
|
|
12488
|
-
previousBlockChildKeys.includes(child._key) && applySetNode(editor, {
|
|
12489
|
-
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
12490
|
-
}, [index, childIndex]), childIndex++;
|
|
12491
|
-
}
|
|
12492
|
-
apply2({
|
|
12493
|
-
...operation,
|
|
12494
|
-
properties: {
|
|
12495
|
-
...operation.properties,
|
|
12496
|
-
// Make sure the adjusted markDefs are carried along for the merge
|
|
12497
|
-
// operation
|
|
12498
|
-
markDefs: adjustedMarkDefs
|
|
12499
|
-
}
|
|
12500
|
-
});
|
|
12501
|
-
return;
|
|
12502
|
-
}
|
|
12503
12272
|
apply2(operation);
|
|
12504
12273
|
}, editor.normalizeNode = (entry) => {
|
|
12505
12274
|
const [node2, path2] = entry;
|
|
@@ -14213,21 +13982,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
14213
13982
|
}), [splitStart, splitEnd] = Range.edges(splitRange);
|
|
14214
13983
|
if (!Editor.isEnd(editor, splitEnd, splitEnd.path) || !Editor.isEdge(editor, splitEnd, splitEnd.path)) {
|
|
14215
13984
|
const [endNode] = Editor.node(editor, splitEnd.path);
|
|
14216
|
-
editor.
|
|
14217
|
-
type: "split_node",
|
|
14218
|
-
path: splitEnd.path,
|
|
14219
|
-
position: splitEnd.offset,
|
|
14220
|
-
properties: Node$1.extractProps(endNode, editor.schema)
|
|
14221
|
-
});
|
|
13985
|
+
applySplitNode(editor, splitEnd.path, splitEnd.offset, Node$1.extractProps(endNode, editor.schema));
|
|
14222
13986
|
}
|
|
14223
13987
|
if (!Editor.isStart(editor, splitStart, splitStart.path) || !Editor.isEdge(editor, splitStart, splitStart.path)) {
|
|
14224
13988
|
const [startNode] = Editor.node(editor, splitStart.path);
|
|
14225
|
-
editor.
|
|
14226
|
-
type: "split_node",
|
|
14227
|
-
path: splitStart.path,
|
|
14228
|
-
position: splitStart.offset,
|
|
14229
|
-
properties: Node$1.extractProps(startNode, editor.schema)
|
|
14230
|
-
});
|
|
13989
|
+
applySplitNode(editor, splitStart.path, splitStart.offset, Node$1.extractProps(startNode, editor.schema));
|
|
14231
13990
|
}
|
|
14232
13991
|
const updatedSplitRange = splitRangeRef.unref();
|
|
14233
13992
|
!at && updatedSplitRange && applySelect(editor, updatedSplitRange);
|
|
@@ -14304,21 +14063,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
14304
14063
|
}), [splitStart, splitEnd] = Range.edges(splitRange);
|
|
14305
14064
|
if (!Editor.isEnd(editor, splitEnd, splitEnd.path) || !Editor.isEdge(editor, splitEnd, splitEnd.path)) {
|
|
14306
14065
|
const [endNode] = Editor.node(editor, splitEnd.path);
|
|
14307
|
-
editor.
|
|
14308
|
-
type: "split_node",
|
|
14309
|
-
path: splitEnd.path,
|
|
14310
|
-
position: splitEnd.offset,
|
|
14311
|
-
properties: Node$1.extractProps(endNode, editor.schema)
|
|
14312
|
-
});
|
|
14066
|
+
applySplitNode(editor, splitEnd.path, splitEnd.offset, Node$1.extractProps(endNode, editor.schema));
|
|
14313
14067
|
}
|
|
14314
14068
|
if (!Editor.isStart(editor, splitStart, splitStart.path) || !Editor.isEdge(editor, splitStart, splitStart.path)) {
|
|
14315
14069
|
const [startNode] = Editor.node(editor, splitStart.path);
|
|
14316
|
-
editor.
|
|
14317
|
-
type: "split_node",
|
|
14318
|
-
path: splitStart.path,
|
|
14319
|
-
position: splitStart.offset,
|
|
14320
|
-
properties: Node$1.extractProps(startNode, editor.schema)
|
|
14321
|
-
});
|
|
14070
|
+
applySplitNode(editor, splitStart.path, splitStart.offset, Node$1.extractProps(startNode, editor.schema));
|
|
14322
14071
|
}
|
|
14323
14072
|
const updatedSplitRange = splitRangeRef.unref();
|
|
14324
14073
|
!at && updatedSplitRange && applySelect(editor, updatedSplitRange);
|
|
@@ -14557,21 +14306,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
14557
14306
|
}), [start2, end2] = Range.edges(at);
|
|
14558
14307
|
if (!Editor.isEnd(editor, end2, end2.path) || !Editor.isEdge(editor, end2, end2.path)) {
|
|
14559
14308
|
const [endNode] = Editor.node(editor, end2.path);
|
|
14560
|
-
editor.
|
|
14561
|
-
type: "split_node",
|
|
14562
|
-
path: end2.path,
|
|
14563
|
-
position: end2.offset,
|
|
14564
|
-
properties: Node$1.extractProps(endNode, editor.schema)
|
|
14565
|
-
});
|
|
14309
|
+
applySplitNode(editor, end2.path, end2.offset, Node$1.extractProps(endNode, editor.schema));
|
|
14566
14310
|
}
|
|
14567
14311
|
if (!Editor.isStart(editor, start2, start2.path) || !Editor.isEdge(editor, start2, start2.path)) {
|
|
14568
14312
|
const [startNode] = Editor.node(editor, start2.path);
|
|
14569
|
-
editor.
|
|
14570
|
-
type: "split_node",
|
|
14571
|
-
path: start2.path,
|
|
14572
|
-
position: start2.offset,
|
|
14573
|
-
properties: Node$1.extractProps(startNode, editor.schema)
|
|
14574
|
-
});
|
|
14313
|
+
applySplitNode(editor, start2.path, start2.offset, Node$1.extractProps(startNode, editor.schema));
|
|
14575
14314
|
}
|
|
14576
14315
|
if (at = rangeRef2.unref(), !at)
|
|
14577
14316
|
throw new Error("Unable to add decorator without a selection");
|
|
@@ -14635,21 +14374,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
14635
14374
|
const [start2, end2] = Range.edges(at);
|
|
14636
14375
|
if (!Editor.isEnd(editor, end2, end2.path) || !Editor.isEdge(editor, end2, end2.path)) {
|
|
14637
14376
|
const [endNode] = Editor.node(editor, end2.path);
|
|
14638
|
-
editor.
|
|
14639
|
-
type: "split_node",
|
|
14640
|
-
path: end2.path,
|
|
14641
|
-
position: end2.offset,
|
|
14642
|
-
properties: Node$1.extractProps(endNode, editor.schema)
|
|
14643
|
-
});
|
|
14377
|
+
applySplitNode(editor, end2.path, end2.offset, Node$1.extractProps(endNode, editor.schema));
|
|
14644
14378
|
}
|
|
14645
14379
|
if (!Editor.isStart(editor, start2, start2.path) || !Editor.isEdge(editor, start2, start2.path)) {
|
|
14646
14380
|
const [startNode] = Editor.node(editor, start2.path);
|
|
14647
|
-
editor.
|
|
14648
|
-
type: "split_node",
|
|
14649
|
-
path: start2.path,
|
|
14650
|
-
position: start2.offset,
|
|
14651
|
-
properties: Node$1.extractProps(startNode, editor.schema)
|
|
14652
|
-
});
|
|
14381
|
+
applySplitNode(editor, start2.path, start2.offset, Node$1.extractProps(startNode, editor.schema));
|
|
14653
14382
|
}
|
|
14654
14383
|
}
|
|
14655
14384
|
const updatedAt = rangeRef2.unref();
|
|
@@ -15267,24 +14996,14 @@ function insertBlock(options) {
|
|
|
15267
14996
|
text: _2,
|
|
15268
14997
|
...properties
|
|
15269
14998
|
} = textNode;
|
|
15270
|
-
editor.
|
|
15271
|
-
type: "split_node",
|
|
15272
|
-
path: selectionPoint.path,
|
|
15273
|
-
position: childOffset,
|
|
15274
|
-
properties
|
|
15275
|
-
});
|
|
14999
|
+
applySplitNode(editor, selectionPoint.path, childOffset, properties);
|
|
15276
15000
|
}
|
|
15277
15001
|
}
|
|
15278
15002
|
const splitAtIndex = childOffset > 0 ? childIndex + 1 : childIndex, {
|
|
15279
15003
|
children: _,
|
|
15280
15004
|
...blockProperties
|
|
15281
15005
|
} = currentBlock;
|
|
15282
|
-
editor
|
|
15283
|
-
type: "split_node",
|
|
15284
|
-
path: blockPath,
|
|
15285
|
-
position: splitAtIndex,
|
|
15286
|
-
properties: blockProperties
|
|
15287
|
-
});
|
|
15006
|
+
applySplitNode(editor, blockPath, splitAtIndex, blockProperties);
|
|
15288
15007
|
const insertPath = [blockPath[0] + 1];
|
|
15289
15008
|
if (editor.apply({
|
|
15290
15009
|
type: "insert_node",
|
|
@@ -15476,12 +15195,7 @@ function insertBlock(options) {
|
|
|
15476
15195
|
text: _,
|
|
15477
15196
|
...properties
|
|
15478
15197
|
} = nodeToSplit;
|
|
15479
|
-
editor.
|
|
15480
|
-
type: "split_node",
|
|
15481
|
-
path: startPoint.path,
|
|
15482
|
-
position: startPoint.offset,
|
|
15483
|
-
properties
|
|
15484
|
-
});
|
|
15198
|
+
applySplitNode(editor, startPoint.path, startPoint.offset, properties);
|
|
15485
15199
|
}
|
|
15486
15200
|
insertTextBlockFragment(editor, block, startPoint), select2 === "none" ? setSelectionToRange(editor, at) : setSelection(editor, [endBlockPath[0] + 1], "start");
|
|
15487
15201
|
} else {
|
|
@@ -15494,12 +15208,7 @@ function insertBlock(options) {
|
|
|
15494
15208
|
text: _,
|
|
15495
15209
|
...properties
|
|
15496
15210
|
} = textNode;
|
|
15497
|
-
editor.
|
|
15498
|
-
type: "split_node",
|
|
15499
|
-
path: currentPath,
|
|
15500
|
-
position: currentOffset,
|
|
15501
|
-
properties
|
|
15502
|
-
}), currentPath = Path.next(currentPath), currentOffset = 0;
|
|
15211
|
+
applySplitNode(editor, currentPath, currentOffset, properties), currentPath = Path.next(currentPath), currentOffset = 0;
|
|
15503
15212
|
}
|
|
15504
15213
|
const splitAtIndex = currentOffset > 0 ? currentPath[1] + 1 : currentPath[1], blockToSplit = Node$1.get(editor, blockPath, editor.schema);
|
|
15505
15214
|
if (splitAtIndex < blockToSplit.children.length && Element$2.isElement(blockToSplit, editor.schema)) {
|
|
@@ -15507,12 +15216,7 @@ function insertBlock(options) {
|
|
|
15507
15216
|
children: _,
|
|
15508
15217
|
...blockProperties
|
|
15509
15218
|
} = blockToSplit;
|
|
15510
|
-
editor
|
|
15511
|
-
type: "split_node",
|
|
15512
|
-
path: blockPath,
|
|
15513
|
-
position: splitAtIndex,
|
|
15514
|
-
properties: blockProperties
|
|
15515
|
-
});
|
|
15219
|
+
applySplitNode(editor, blockPath, splitAtIndex, blockProperties);
|
|
15516
15220
|
}
|
|
15517
15221
|
const currentFirstBlockPath = firstBlockPathRef.unref(), insertPath = currentFirstBlockPath ? [currentFirstBlockPath[0] + 1] : [blockPath[0] + 1];
|
|
15518
15222
|
if (editor.apply({
|
|
@@ -15659,12 +15363,7 @@ function deleteSameBlockRange(editor, start2, end2) {
|
|
|
15659
15363
|
text: _,
|
|
15660
15364
|
...properties
|
|
15661
15365
|
} = endNodeAfter;
|
|
15662
|
-
editor.
|
|
15663
|
-
type: "merge_node",
|
|
15664
|
-
path: newEndPath,
|
|
15665
|
-
position: startNodeAfter.text.length,
|
|
15666
|
-
properties
|
|
15667
|
-
});
|
|
15366
|
+
applyMergeNode(editor, newEndPath, startNodeAfter.text.length, properties);
|
|
15668
15367
|
}
|
|
15669
15368
|
}
|
|
15670
15369
|
function deleteCrossBlockRange(editor, start2, end2) {
|
|
@@ -15702,18 +15401,19 @@ function deleteCrossBlockRange(editor, start2, end2) {
|
|
|
15702
15401
|
}
|
|
15703
15402
|
}
|
|
15704
15403
|
const startBlock = Node$1.get(editor, startBlockPath, editor.schema), endBlock = Node$1.get(editor, adjustedEndBlockPath, editor.schema);
|
|
15705
|
-
|
|
15404
|
+
editor.isTextBlock(startBlock) && editor.isTextBlock(endBlock) && Editor.withoutNormalizing(editor, () => {
|
|
15405
|
+
if (Array.isArray(endBlock.markDefs) && endBlock.markDefs.length > 0) {
|
|
15406
|
+
const oldDefs = Array.isArray(startBlock.markDefs) && startBlock.markDefs || [], newMarkDefs = [...new Map([...oldDefs, ...endBlock.markDefs].map((def) => [def._key, def])).values()];
|
|
15407
|
+
applySetNode(editor, {
|
|
15408
|
+
markDefs: newMarkDefs
|
|
15409
|
+
}, startBlockPath);
|
|
15410
|
+
}
|
|
15706
15411
|
const {
|
|
15707
15412
|
children: _,
|
|
15708
15413
|
...properties
|
|
15709
15414
|
} = endBlock;
|
|
15710
|
-
editor.
|
|
15711
|
-
|
|
15712
|
-
path: adjustedEndBlockPath,
|
|
15713
|
-
position: startBlock.children.length,
|
|
15714
|
-
properties
|
|
15715
|
-
});
|
|
15716
|
-
}
|
|
15415
|
+
applyMergeNode(editor, adjustedEndBlockPath, startBlock.children.length, properties);
|
|
15416
|
+
});
|
|
15717
15417
|
}
|
|
15718
15418
|
function deleteExpandedRange(editor, range2) {
|
|
15719
15419
|
const [start2, end2] = Range.edges(range2);
|
|
@@ -15729,12 +15429,7 @@ function insertTextBlockFragment(editor, block, at) {
|
|
|
15729
15429
|
text: _,
|
|
15730
15430
|
...properties
|
|
15731
15431
|
} = textNode;
|
|
15732
|
-
editor.
|
|
15733
|
-
type: "split_node",
|
|
15734
|
-
path: at.path,
|
|
15735
|
-
position: at.offset,
|
|
15736
|
-
properties
|
|
15737
|
-
});
|
|
15432
|
+
applySplitNode(editor, at.path, at.offset, properties);
|
|
15738
15433
|
}
|
|
15739
15434
|
}
|
|
15740
15435
|
const parentPath = Path.parent(at.path);
|
|
@@ -15901,11 +15596,7 @@ const moveBackwardOperationImplementation = ({
|
|
|
15901
15596
|
const destinationBlockIndex = operation.editor.blockIndexMap.get(destinationKey);
|
|
15902
15597
|
if (destinationBlockIndex === void 0)
|
|
15903
15598
|
throw new Error("Failed to get block index from block key");
|
|
15904
|
-
operation.editor
|
|
15905
|
-
type: "move_node",
|
|
15906
|
-
path: [originBlockIndex],
|
|
15907
|
-
newPath: [destinationBlockIndex]
|
|
15908
|
-
});
|
|
15599
|
+
applyMoveNode(operation.editor, [originBlockIndex], [destinationBlockIndex]);
|
|
15909
15600
|
}, moveForwardOperationImplementation = ({
|
|
15910
15601
|
operation
|
|
15911
15602
|
}) => {
|