@portabletext/editor 1.50.5 → 1.50.7
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/_chunks-cjs/util.selection-point-to-block-offset.cjs +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +24 -16
- package/lib/behaviors/index.d.ts +24 -16
- package/lib/index.cjs +324 -252
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +24 -16
- package/lib/index.d.ts +24 -16
- package/lib/index.js +326 -254
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +24 -16
- package/lib/plugins/index.d.ts +24 -16
- package/lib/selectors/index.d.cts +24 -16
- package/lib/selectors/index.d.ts +24 -16
- package/lib/utils/index.d.cts +24 -16
- package/lib/utils/index.d.ts +24 -16
- package/package.json +4 -4
- package/src/behaviors/behavior.abstract.delete.ts +60 -0
- package/src/behaviors/behavior.abstract.split.ts +23 -13
- package/src/behaviors/behavior.types.event.ts +23 -16
- package/src/editor/plugins/create-with-event-listeners.ts +41 -1
- package/src/editor/sync-machine.ts +26 -20
- package/src/internal-utils/applyPatch.ts +298 -207
- package/src/internal-utils/slate-utils.ts +31 -0
- package/src/internal-utils/test-editor.tsx +45 -0
- package/src/operations/behavior.operation.delete.ts +36 -22
- package/src/operations/behavior.operations.ts +0 -27
- package/src/utils/util.is-selection-collapsed.ts +2 -1
- package/src/internal-utils/__tests__/dmpToOperations.test.ts +0 -207
- package/src/operations/behavior.operation.delete.backward.ts +0 -8
- package/src/operations/behavior.operation.delete.block.ts +0 -24
- package/src/operations/behavior.operation.delete.forward.ts +0 -8
package/lib/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$h = require("debug"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$
|
|
7
|
+
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$h), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
|
|
8
8
|
function EditorEventListener(props) {
|
|
9
9
|
const $ = reactCompilerRuntime.c(5), editor = useEditor.useEditor(), on = useEffectEvent.useEffectEvent(props.on);
|
|
10
10
|
let t0;
|
|
@@ -209,6 +209,17 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
209
209
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
210
210
|
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].name && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
211
211
|
}
|
|
212
|
+
function getBlockPath({
|
|
213
|
+
editor,
|
|
214
|
+
_key
|
|
215
|
+
}) {
|
|
216
|
+
const [, blockPath] = Array.from(slate.Editor.nodes(editor, {
|
|
217
|
+
at: [],
|
|
218
|
+
match: (n) => n._key === _key
|
|
219
|
+
})).at(0) ?? [void 0, void 0], blockIndex = blockPath?.at(0);
|
|
220
|
+
if (blockIndex !== void 0)
|
|
221
|
+
return [blockIndex];
|
|
222
|
+
}
|
|
212
223
|
function getFocusBlock({
|
|
213
224
|
editor
|
|
214
225
|
}) {
|
|
@@ -316,6 +327,8 @@ function getPointChild({
|
|
|
316
327
|
function getFirstBlock({
|
|
317
328
|
editor
|
|
318
329
|
}) {
|
|
330
|
+
if (editor.children.length === 0)
|
|
331
|
+
return [void 0, void 0];
|
|
319
332
|
const firstBlockPath = slate.Editor.start(editor, []).path.at(0);
|
|
320
333
|
try {
|
|
321
334
|
return firstBlockPath !== void 0 ? slate.Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
@@ -326,6 +339,8 @@ function getFirstBlock({
|
|
|
326
339
|
function getLastBlock({
|
|
327
340
|
editor
|
|
328
341
|
}) {
|
|
342
|
+
if (editor.children.length === 0)
|
|
343
|
+
return [void 0, void 0];
|
|
329
344
|
const lastBlockPath = slate.Editor.end(editor, []).path.at(0);
|
|
330
345
|
try {
|
|
331
346
|
return lastBlockPath !== void 0 ? slate.Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
@@ -1554,7 +1569,7 @@ function getEditorSnapshot({
|
|
|
1554
1569
|
}
|
|
1555
1570
|
};
|
|
1556
1571
|
}
|
|
1557
|
-
const debug$
|
|
1572
|
+
const debug$g = debugWithName("plugin:withPortableTextMarkModel");
|
|
1558
1573
|
function createWithPortableTextMarkModel(editorActor) {
|
|
1559
1574
|
return function(editor) {
|
|
1560
1575
|
const {
|
|
@@ -1568,7 +1583,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1568
1583
|
for (const [child, childPath] of children) {
|
|
1569
1584
|
const nextNode = node.children[childPath[1] + 1];
|
|
1570
1585
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
1571
|
-
debug$
|
|
1586
|
+
debug$g("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
1572
1587
|
type: "normalizing"
|
|
1573
1588
|
}), slate.Transforms.mergeNodes(editor, {
|
|
1574
1589
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -1581,7 +1596,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1581
1596
|
}
|
|
1582
1597
|
}
|
|
1583
1598
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
1584
|
-
debug$
|
|
1599
|
+
debug$g("Adding .markDefs to block node"), editorActor.send({
|
|
1585
1600
|
type: "normalizing"
|
|
1586
1601
|
}), slate.Transforms.setNodes(editor, {
|
|
1587
1602
|
markDefs: []
|
|
@@ -1593,7 +1608,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1593
1608
|
return;
|
|
1594
1609
|
}
|
|
1595
1610
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
1596
|
-
debug$
|
|
1611
|
+
debug$g("Adding .marks to span node"), editorActor.send({
|
|
1597
1612
|
type: "normalizing"
|
|
1598
1613
|
}), slate.Transforms.setNodes(editor, {
|
|
1599
1614
|
marks: []
|
|
@@ -1607,7 +1622,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1607
1622
|
if (editor.isTextSpan(node)) {
|
|
1608
1623
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
1609
1624
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
1610
|
-
debug$
|
|
1625
|
+
debug$g("Removing annotations from empty span node"), editorActor.send({
|
|
1611
1626
|
type: "normalizing"
|
|
1612
1627
|
}), slate.Transforms.setNodes(editor, {
|
|
1613
1628
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -1625,7 +1640,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1625
1640
|
if (editor.isTextSpan(child)) {
|
|
1626
1641
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
1627
1642
|
if (orphanedAnnotations.length > 0) {
|
|
1628
|
-
debug$
|
|
1643
|
+
debug$g("Removing orphaned annotations from span node"), editorActor.send({
|
|
1629
1644
|
type: "normalizing"
|
|
1630
1645
|
}), slate.Transforms.setNodes(editor, {
|
|
1631
1646
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1643,7 +1658,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1643
1658
|
if (editor.isTextBlock(block)) {
|
|
1644
1659
|
const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
1645
1660
|
if (orphanedAnnotations.length > 0) {
|
|
1646
|
-
debug$
|
|
1661
|
+
debug$g("Removing orphaned annotations from span node"), editorActor.send({
|
|
1647
1662
|
type: "normalizing"
|
|
1648
1663
|
}), slate.Transforms.setNodes(editor, {
|
|
1649
1664
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1661,7 +1676,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1661
1676
|
for (const markDef of markDefs)
|
|
1662
1677
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
1663
1678
|
if (markDefs.length !== newMarkDefs.length) {
|
|
1664
|
-
debug$
|
|
1679
|
+
debug$g("Removing duplicate markDefs"), editorActor.send({
|
|
1665
1680
|
type: "normalizing"
|
|
1666
1681
|
}), slate.Transforms.setNodes(editor, {
|
|
1667
1682
|
markDefs: newMarkDefs
|
|
@@ -1676,7 +1691,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1676
1691
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
1677
1692
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
1678
1693
|
if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
|
|
1679
|
-
debug$
|
|
1694
|
+
debug$g("Removing markDef not in use"), editorActor.send({
|
|
1680
1695
|
type: "normalizing"
|
|
1681
1696
|
}), slate.Transforms.setNodes(editor, {
|
|
1682
1697
|
markDefs: newMarkDefs
|
|
@@ -1829,7 +1844,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1829
1844
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
1830
1845
|
if (editor.isTextBlock(targetBlock)) {
|
|
1831
1846
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
1832
|
-
debug$
|
|
1847
|
+
debug$g("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
|
|
1833
1848
|
markDefs: newMarkDefs
|
|
1834
1849
|
}, {
|
|
1835
1850
|
at: targetPath,
|
|
@@ -2539,7 +2554,7 @@ function withUndoStep(editor, fn) {
|
|
|
2539
2554
|
function getCurrentUndoStepId(editor) {
|
|
2540
2555
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
2541
2556
|
}
|
|
2542
|
-
const debug$
|
|
2557
|
+
const debug$f = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2543
2558
|
const state = SAVING.get(editor);
|
|
2544
2559
|
return state === void 0 ? !0 : state;
|
|
2545
2560
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -2552,7 +2567,7 @@ function createWithUndoRedo(options) {
|
|
|
2552
2567
|
const remotePatches = getRemotePatches(editor);
|
|
2553
2568
|
let previousUndoStepId = getCurrentUndoStepId(editor);
|
|
2554
2569
|
options.subscriptions.push(() => {
|
|
2555
|
-
debug$
|
|
2570
|
+
debug$f("Subscribing to patches");
|
|
2556
2571
|
const sub = editorActor.on("patches", ({
|
|
2557
2572
|
patches: patches2,
|
|
2558
2573
|
snapshot
|
|
@@ -2561,7 +2576,7 @@ function createWithUndoRedo(options) {
|
|
|
2561
2576
|
patches2.forEach((patch) => {
|
|
2562
2577
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2563
2578
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2564
|
-
debug$
|
|
2579
|
+
debug$f("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
2565
2580
|
undos: [],
|
|
2566
2581
|
redos: []
|
|
2567
2582
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -2577,7 +2592,7 @@ function createWithUndoRedo(options) {
|
|
|
2577
2592
|
}), previousSnapshot = snapshot;
|
|
2578
2593
|
});
|
|
2579
2594
|
return () => {
|
|
2580
|
-
debug$
|
|
2595
|
+
debug$f("Unsubscribing to patches"), sub.unsubscribe();
|
|
2581
2596
|
};
|
|
2582
2597
|
}), editor.history = {
|
|
2583
2598
|
undos: [],
|
|
@@ -2616,7 +2631,7 @@ function createWithUndoRedo(options) {
|
|
|
2616
2631
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
2617
2632
|
timestamp: /* @__PURE__ */ new Date()
|
|
2618
2633
|
};
|
|
2619
|
-
undos.push(newStep), debug$
|
|
2634
|
+
undos.push(newStep), debug$f("Created new undo step", step);
|
|
2620
2635
|
}
|
|
2621
2636
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
2622
2637
|
undos.shift();
|
|
@@ -2634,7 +2649,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2634
2649
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2635
2650
|
if (undos.length > 0) {
|
|
2636
2651
|
const step = undos[undos.length - 1];
|
|
2637
|
-
if (debug$
|
|
2652
|
+
if (debug$f("Undoing", step), step.operations.length > 0) {
|
|
2638
2653
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2639
2654
|
let transformedOperations = step.operations;
|
|
2640
2655
|
otherPatches.forEach((item) => {
|
|
@@ -2652,7 +2667,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2652
2667
|
});
|
|
2653
2668
|
});
|
|
2654
2669
|
} catch (err) {
|
|
2655
|
-
debug$
|
|
2670
|
+
debug$f("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
2656
2671
|
undos: [],
|
|
2657
2672
|
redos: []
|
|
2658
2673
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -2669,7 +2684,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2669
2684
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2670
2685
|
if (redos.length > 0) {
|
|
2671
2686
|
const step = redos[redos.length - 1];
|
|
2672
|
-
if (debug$
|
|
2687
|
+
if (debug$f("Redoing", step), step.operations.length > 0) {
|
|
2673
2688
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2674
2689
|
let transformedOperations = step.operations;
|
|
2675
2690
|
otherPatches.forEach((item) => {
|
|
@@ -2686,7 +2701,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2686
2701
|
});
|
|
2687
2702
|
});
|
|
2688
2703
|
} catch (err) {
|
|
2689
|
-
debug$
|
|
2704
|
+
debug$f("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
2690
2705
|
undos: [],
|
|
2691
2706
|
redos: []
|
|
2692
2707
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -2704,16 +2719,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2704
2719
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2705
2720
|
_key: blk._key
|
|
2706
2721
|
}, patch.path[0]));
|
|
2707
|
-
return debug$
|
|
2722
|
+
return debug$f(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2708
2723
|
}
|
|
2709
2724
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2710
2725
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2711
2726
|
_key: blk._key
|
|
2712
2727
|
}, patch.path[0]));
|
|
2713
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
2728
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$f("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
2714
2729
|
}
|
|
2715
2730
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2716
|
-
return debug$
|
|
2731
|
+
return debug$f(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2717
2732
|
if (patch.type === "diffMatchPatch") {
|
|
2718
2733
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2719
2734
|
return !operationTargetBlock || !isEqual__default.default({
|
|
@@ -3163,58 +3178,29 @@ const addAnnotationOperationImplementation = ({
|
|
|
3163
3178
|
};
|
|
3164
3179
|
}
|
|
3165
3180
|
}, deleteOperationImplementation = ({
|
|
3166
|
-
context,
|
|
3167
3181
|
operation
|
|
3168
3182
|
}) => {
|
|
3183
|
+
const anchorBlockPath = util_sliceBlocks.isKeyedSegment(operation.at.anchor.path[0]) ? getBlockPath({
|
|
3184
|
+
editor: operation.editor,
|
|
3185
|
+
_key: operation.at.anchor.path[0]._key
|
|
3186
|
+
}) : void 0, focusBlockPath = util_sliceBlocks.isKeyedSegment(operation.at.focus.path[0]) ? getBlockPath({
|
|
3187
|
+
editor: operation.editor,
|
|
3188
|
+
_key: operation.at.focus.path[0]._key
|
|
3189
|
+
}) : void 0;
|
|
3190
|
+
if (operation.at.anchor.path.length === 1 && operation.at.focus.path.length === 1 && anchorBlockPath && focusBlockPath && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
3191
|
+
slate.Transforms.removeNodes(operation.editor, {
|
|
3192
|
+
at: [anchorBlockPath[0]]
|
|
3193
|
+
});
|
|
3194
|
+
return;
|
|
3195
|
+
}
|
|
3169
3196
|
const range = toSlateRange(operation.at, operation.editor);
|
|
3170
3197
|
if (!range)
|
|
3171
3198
|
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
|
|
3172
|
-
if (slate.Range.isCollapsed(range)) {
|
|
3173
|
-
const [focusBlock] = getFocusBlock({
|
|
3174
|
-
editor: {
|
|
3175
|
-
...operation.editor,
|
|
3176
|
-
selection: range
|
|
3177
|
-
}
|
|
3178
|
-
}), [focusChild] = getFocusChild({
|
|
3179
|
-
editor: {
|
|
3180
|
-
...operation.editor,
|
|
3181
|
-
selection: range
|
|
3182
|
-
}
|
|
3183
|
-
});
|
|
3184
|
-
if (focusBlock && focusBlock._type === context.schema.block.name && focusChild && focusChild._type === context.schema.span.name)
|
|
3185
|
-
return;
|
|
3186
|
-
}
|
|
3187
3199
|
operation.editor.delete({
|
|
3188
|
-
at: range
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
operation
|
|
3192
|
-
}) => {
|
|
3193
|
-
slate.deleteBackward(operation.editor, operation.unit);
|
|
3194
|
-
}, deleteBlockOperationImplementation = ({
|
|
3195
|
-
operation
|
|
3196
|
-
}) => {
|
|
3197
|
-
const range = toSlateRange({
|
|
3198
|
-
anchor: {
|
|
3199
|
-
path: operation.at,
|
|
3200
|
-
offset: 0
|
|
3201
|
-
},
|
|
3202
|
-
focus: {
|
|
3203
|
-
path: operation.at,
|
|
3204
|
-
offset: 0
|
|
3205
|
-
}
|
|
3206
|
-
}, operation.editor);
|
|
3207
|
-
if (!range) {
|
|
3208
|
-
console.error("Unable to find Slate range from selection points");
|
|
3209
|
-
return;
|
|
3210
|
-
}
|
|
3211
|
-
slate.Transforms.removeNodes(operation.editor, {
|
|
3212
|
-
at: range
|
|
3200
|
+
at: range,
|
|
3201
|
+
reverse: operation.direction === "backward",
|
|
3202
|
+
unit: operation.unit
|
|
3213
3203
|
});
|
|
3214
|
-
}, deleteForwardOperationImplementation = ({
|
|
3215
|
-
operation
|
|
3216
|
-
}) => {
|
|
3217
|
-
slate.deleteForward(operation.editor, operation.unit);
|
|
3218
3204
|
}, insertInlineObjectOperationImplementation = ({
|
|
3219
3205
|
context,
|
|
3220
3206
|
operation
|
|
@@ -3507,9 +3493,6 @@ const moveBackwardOperationImplementation = ({
|
|
|
3507
3493
|
"decorator.add": decoratorAddOperationImplementation,
|
|
3508
3494
|
"decorator.remove": removeDecoratorOperationImplementation,
|
|
3509
3495
|
delete: deleteOperationImplementation,
|
|
3510
|
-
"delete.backward": deleteBackwardOperationImplementation,
|
|
3511
|
-
"delete.forward": deleteForwardOperationImplementation,
|
|
3512
|
-
"delete.block": deleteBlockOperationImplementation,
|
|
3513
3496
|
"history.redo": historyRedoOperationImplementation,
|
|
3514
3497
|
"history.undo": historyUndoOperationImplementation,
|
|
3515
3498
|
"insert.block": insertBlockOperationImplementation,
|
|
@@ -3576,27 +3559,6 @@ function performOperation({
|
|
|
3576
3559
|
});
|
|
3577
3560
|
break;
|
|
3578
3561
|
}
|
|
3579
|
-
case "delete.backward": {
|
|
3580
|
-
behaviorOperationImplementations["delete.backward"]({
|
|
3581
|
-
context,
|
|
3582
|
-
operation
|
|
3583
|
-
});
|
|
3584
|
-
break;
|
|
3585
|
-
}
|
|
3586
|
-
case "delete.block": {
|
|
3587
|
-
behaviorOperationImplementations["delete.block"]({
|
|
3588
|
-
context,
|
|
3589
|
-
operation
|
|
3590
|
-
});
|
|
3591
|
-
break;
|
|
3592
|
-
}
|
|
3593
|
-
case "delete.forward": {
|
|
3594
|
-
behaviorOperationImplementations["delete.forward"]({
|
|
3595
|
-
context,
|
|
3596
|
-
operation
|
|
3597
|
-
});
|
|
3598
|
-
break;
|
|
3599
|
-
}
|
|
3600
3562
|
case "history.redo": {
|
|
3601
3563
|
behaviorOperationImplementations["history.redo"]({
|
|
3602
3564
|
context,
|
|
@@ -3687,9 +3649,39 @@ function createWithEventListeners(editorActor) {
|
|
|
3687
3649
|
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
3688
3650
|
return editor;
|
|
3689
3651
|
const {
|
|
3652
|
+
delete: editorDelete,
|
|
3690
3653
|
select
|
|
3691
3654
|
} = editor;
|
|
3692
|
-
return editor.
|
|
3655
|
+
return editor.delete = (options) => {
|
|
3656
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
3657
|
+
editorDelete(options);
|
|
3658
|
+
return;
|
|
3659
|
+
}
|
|
3660
|
+
const at = options?.at ?? editor.selection;
|
|
3661
|
+
if (!at) {
|
|
3662
|
+
console.error("Unexpected call to .delete(...) without `at` option");
|
|
3663
|
+
return;
|
|
3664
|
+
}
|
|
3665
|
+
const range = slate.Editor.range(editor, at), selection = slateRangeToSelection({
|
|
3666
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
3667
|
+
editor,
|
|
3668
|
+
range
|
|
3669
|
+
});
|
|
3670
|
+
if (!selection) {
|
|
3671
|
+
console.error("Unexpected call to .delete(...) with invalid `at` option");
|
|
3672
|
+
return;
|
|
3673
|
+
}
|
|
3674
|
+
editorActor.send({
|
|
3675
|
+
type: "behavior event",
|
|
3676
|
+
behaviorEvent: {
|
|
3677
|
+
type: "delete",
|
|
3678
|
+
at: selection,
|
|
3679
|
+
direction: options?.reverse ? "backward" : "forward",
|
|
3680
|
+
unit: options?.unit
|
|
3681
|
+
},
|
|
3682
|
+
editor
|
|
3683
|
+
});
|
|
3684
|
+
}, editor.deleteBackward = (unit) => {
|
|
3693
3685
|
if (isApplyingBehaviorOperations(editor)) {
|
|
3694
3686
|
console.error("Unexpected call to .deleteBackward(...)");
|
|
3695
3687
|
return;
|
|
@@ -3947,13 +3939,9 @@ function createWithObjectKeys(editorActor) {
|
|
|
3947
3939
|
}, editor;
|
|
3948
3940
|
};
|
|
3949
3941
|
}
|
|
3950
|
-
const debug$f = debugWithName("applyPatches"), debugVerbose = debug$f.enabled && !0;
|
|
3951
3942
|
function createApplyPatch(schema2) {
|
|
3952
3943
|
return (editor, patch) => {
|
|
3953
3944
|
let changed = !1;
|
|
3954
|
-
debugVerbose && (debug$f(`
|
|
3955
|
-
|
|
3956
|
-
NEW PATCH =============================================================`), debug$f(JSON.stringify(patch, null, 2)));
|
|
3957
3945
|
try {
|
|
3958
3946
|
switch (patch.type) {
|
|
3959
3947
|
case "insert":
|
|
@@ -3968,8 +3956,6 @@ NEW PATCH =============================================================`), debug
|
|
|
3968
3956
|
case "diffMatchPatch":
|
|
3969
3957
|
changed = diffMatchPatch(editor, patch);
|
|
3970
3958
|
break;
|
|
3971
|
-
default:
|
|
3972
|
-
debug$f("Unhandled patch", patch.type);
|
|
3973
3959
|
}
|
|
3974
3960
|
} catch (err) {
|
|
3975
3961
|
console.error(err);
|
|
@@ -3978,164 +3964,166 @@ NEW PATCH =============================================================`), debug
|
|
|
3978
3964
|
};
|
|
3979
3965
|
}
|
|
3980
3966
|
function diffMatchPatch(editor, patch) {
|
|
3981
|
-
const
|
|
3982
|
-
block,
|
|
3983
|
-
child,
|
|
3984
|
-
childPath
|
|
3985
|
-
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3967
|
+
const block = findBlock(editor.children, patch.path);
|
|
3986
3968
|
if (!block)
|
|
3987
|
-
return debug$f("Block not found"), !1;
|
|
3988
|
-
if (!child || !childPath)
|
|
3989
|
-
return debug$f("Child not found"), !1;
|
|
3990
|
-
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
|
|
3991
3969
|
return !1;
|
|
3992
|
-
const
|
|
3970
|
+
const child = findBlockChild(block, patch.path);
|
|
3971
|
+
if (!child || !(block && editor.isTextBlock(block.node) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child.node))
|
|
3972
|
+
return !1;
|
|
3973
|
+
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.node.text, {
|
|
3993
3974
|
allowExceedingIndices: !0
|
|
3994
|
-
}), diff$1 = cleanupEfficiency(diff(child.text, newValue), 5);
|
|
3995
|
-
debugState(editor, "before");
|
|
3975
|
+
}), diff$1 = cleanupEfficiency(diff(child.node.text, newValue), 5);
|
|
3996
3976
|
let offset = 0;
|
|
3997
3977
|
for (const [op, text] of diff$1)
|
|
3998
3978
|
op === DIFF_INSERT ? (editor.apply({
|
|
3999
3979
|
type: "insert_text",
|
|
4000
|
-
path:
|
|
3980
|
+
path: [block.index, child.index],
|
|
4001
3981
|
offset,
|
|
4002
3982
|
text
|
|
4003
3983
|
}), offset += text.length) : op === DIFF_DELETE ? editor.apply({
|
|
4004
3984
|
type: "remove_text",
|
|
4005
|
-
path:
|
|
3985
|
+
path: [block.index, child.index],
|
|
4006
3986
|
offset,
|
|
4007
3987
|
text
|
|
4008
3988
|
}) : op === DIFF_EQUAL && (offset += text.length);
|
|
4009
|
-
return
|
|
3989
|
+
return !0;
|
|
4010
3990
|
}
|
|
4011
3991
|
function insertPatch(editor, patch, schema2) {
|
|
4012
|
-
const
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
blockPath: targetBlockPath,
|
|
4016
|
-
childPath: targetChildPath
|
|
4017
|
-
} = findBlockAndChildFromPath(editor, patch.path);
|
|
4018
|
-
if (!targetBlock || !targetBlockPath)
|
|
4019
|
-
return debug$f("Block not found"), !1;
|
|
4020
|
-
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
4021
|
-
return debug$f("Ignoring patch targeting void value"), !1;
|
|
3992
|
+
const block = findBlock(editor.children, patch.path);
|
|
3993
|
+
if (!block || patch.path.length > 1 && patch.path[1] !== "children")
|
|
3994
|
+
return !1;
|
|
4022
3995
|
if (patch.path.length === 1) {
|
|
4023
3996
|
const {
|
|
4024
3997
|
items: items2,
|
|
4025
3998
|
position: position2
|
|
4026
3999
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
4027
4000
|
schemaTypes: schema2
|
|
4028
|
-
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex =
|
|
4029
|
-
debug$f(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before");
|
|
4030
|
-
const editorWasEmptyBefore = isEqualToEmptyEditor(editor.children, schema2);
|
|
4001
|
+
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = block.index, normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex, editorWasEmptyBefore = isEqualToEmptyEditor(editor.children, schema2);
|
|
4031
4002
|
return slate.Transforms.insertNodes(editor, blocksToInsert, {
|
|
4032
4003
|
at: [normalizedIdx2]
|
|
4033
4004
|
}), editorWasEmptyBefore && typeof patch.path[0] == "number" && patch.path[0] === 0 && slate.Transforms.removeNodes(editor, {
|
|
4034
4005
|
at: [position2 === "before" ? targetBlockIndex + 1 : targetBlockIndex]
|
|
4035
|
-
}),
|
|
4006
|
+
}), !0;
|
|
4036
4007
|
}
|
|
4037
4008
|
const {
|
|
4038
4009
|
items,
|
|
4039
4010
|
position
|
|
4040
|
-
} = patch;
|
|
4041
|
-
if (!targetChild
|
|
4042
|
-
return
|
|
4043
|
-
const childrenToInsert =
|
|
4044
|
-
...
|
|
4011
|
+
} = patch, targetChild = findBlockChild(block, patch.path);
|
|
4012
|
+
if (!targetChild)
|
|
4013
|
+
return !1;
|
|
4014
|
+
const childrenToInsert = toSlateValue([{
|
|
4015
|
+
...block.node,
|
|
4045
4016
|
children: items
|
|
4046
4017
|
}], {
|
|
4047
4018
|
schemaTypes: schema2
|
|
4048
|
-
}, KEY_TO_SLATE_ELEMENT.get(editor)),
|
|
4049
|
-
return
|
|
4019
|
+
}, KEY_TO_SLATE_ELEMENT.get(editor)), normalizedIdx = position === "after" ? targetChild.index + 1 : targetChild.index, childInsertPath = [block.index, normalizedIdx];
|
|
4020
|
+
return childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
4050
4021
|
at: childInsertPath
|
|
4051
|
-
}),
|
|
4022
|
+
}), !0;
|
|
4052
4023
|
}
|
|
4053
4024
|
function setPatch(editor, patch) {
|
|
4054
4025
|
let value = patch.value;
|
|
4055
4026
|
typeof patch.path[3] == "string" && (value = {}, value[patch.path[3]] = patch.value);
|
|
4056
|
-
const
|
|
4057
|
-
block,
|
|
4058
|
-
blockPath,
|
|
4059
|
-
child,
|
|
4060
|
-
childPath
|
|
4061
|
-
} = findBlockAndChildFromPath(editor, patch.path);
|
|
4027
|
+
const block = findBlock(editor.children, patch.path);
|
|
4062
4028
|
if (!block)
|
|
4063
|
-
return
|
|
4064
|
-
const isTextBlock = editor.isTextBlock(block);
|
|
4029
|
+
return !1;
|
|
4030
|
+
const isTextBlock = editor.isTextBlock(block.node);
|
|
4065
4031
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
4066
|
-
return
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
path
|
|
4085
|
-
|
|
4086
|
-
|
|
4032
|
+
return !1;
|
|
4033
|
+
const child = findBlockChild(block, patch.path);
|
|
4034
|
+
if (isTextBlock && child) {
|
|
4035
|
+
if (slate.Text.isText(child.node))
|
|
4036
|
+
if (slate.Text.isText(value)) {
|
|
4037
|
+
const oldText = child.node.text, newText = value.text;
|
|
4038
|
+
oldText !== newText && (editor.apply({
|
|
4039
|
+
type: "remove_text",
|
|
4040
|
+
path: [block.index, child.index],
|
|
4041
|
+
offset: 0,
|
|
4042
|
+
text: oldText
|
|
4043
|
+
}), editor.apply({
|
|
4044
|
+
type: "insert_text",
|
|
4045
|
+
path: [block.index, child.index],
|
|
4046
|
+
offset: 0,
|
|
4047
|
+
text: newText
|
|
4048
|
+
}), editor.onChange());
|
|
4049
|
+
} else {
|
|
4050
|
+
const propPath = patch.path.slice(3), propEntry = propPath.at(0);
|
|
4051
|
+
if (propEntry === void 0 || typeof propEntry == "string" && ["_key", "_type", "text"].includes(propEntry))
|
|
4052
|
+
return !1;
|
|
4053
|
+
const newNode = patches.applyAll(child.node, [{
|
|
4054
|
+
...patch,
|
|
4055
|
+
path: propPath
|
|
4056
|
+
}]);
|
|
4057
|
+
slate.Transforms.setNodes(editor, newNode, {
|
|
4058
|
+
at: [block.index, child.index]
|
|
4059
|
+
});
|
|
4060
|
+
}
|
|
4061
|
+
else {
|
|
4062
|
+
const propPath = patch.path.slice(3), reservedProps = ["_key", "_type", "children", "__inline"], propEntry = propPath.at(0);
|
|
4063
|
+
if (propEntry === void 0 || typeof propEntry == "string" && reservedProps.includes(propEntry))
|
|
4064
|
+
return !1;
|
|
4065
|
+
const value2 = "value" in child.node && typeof child.node.value == "object" ? child.node.value : {}, newValue = patches.applyAll(value2, [{
|
|
4066
|
+
...patch,
|
|
4067
|
+
path: patch.path.slice(3)
|
|
4068
|
+
}]);
|
|
4069
|
+
slate.Transforms.setNodes(editor, {
|
|
4070
|
+
...child.node,
|
|
4071
|
+
value: newValue
|
|
4072
|
+
}, {
|
|
4073
|
+
at: [block.index, child.index]
|
|
4087
4074
|
});
|
|
4075
|
+
}
|
|
4088
4076
|
return !0;
|
|
4089
|
-
} else if (slate.Element.isElement(block) && patch.path.length === 1
|
|
4090
|
-
debug$f("Setting block property");
|
|
4077
|
+
} else if (slate.Element.isElement(block.node) && patch.path.length === 1) {
|
|
4091
4078
|
const {
|
|
4092
4079
|
children,
|
|
4093
4080
|
...nextRest
|
|
4094
4081
|
} = value, {
|
|
4095
4082
|
children: prevChildren,
|
|
4096
4083
|
...prevRest
|
|
4097
|
-
} = block || {
|
|
4084
|
+
} = block.node || {
|
|
4098
4085
|
children: void 0
|
|
4099
4086
|
};
|
|
4100
4087
|
editor.apply({
|
|
4101
4088
|
type: "set_node",
|
|
4102
|
-
path:
|
|
4089
|
+
path: [block.index],
|
|
4103
4090
|
properties: {
|
|
4104
4091
|
...prevRest
|
|
4105
4092
|
},
|
|
4106
4093
|
newProperties: nextRest
|
|
4107
|
-
})
|
|
4094
|
+
});
|
|
4095
|
+
const blockNode = block.node;
|
|
4096
|
+
blockNode.children.forEach((child2, childIndex) => {
|
|
4108
4097
|
editor.apply({
|
|
4109
4098
|
type: "remove_node",
|
|
4110
|
-
path:
|
|
4111
|
-
node:
|
|
4099
|
+
path: [block.index, blockNode.children.length - 1 - childIndex],
|
|
4100
|
+
node: child2
|
|
4112
4101
|
});
|
|
4113
|
-
}), Array.isArray(children) && children.forEach((
|
|
4102
|
+
}), Array.isArray(children) && children.forEach((child2, childIndex) => {
|
|
4114
4103
|
editor.apply({
|
|
4115
4104
|
type: "insert_node",
|
|
4116
|
-
path:
|
|
4117
|
-
node:
|
|
4105
|
+
path: [block.index, childIndex],
|
|
4106
|
+
node: child2
|
|
4118
4107
|
});
|
|
4119
4108
|
});
|
|
4120
|
-
} else if (block && "value" in block)
|
|
4109
|
+
} else if (block && "value" in block.node)
|
|
4121
4110
|
if (patch.path.length > 1 && patch.path[1] !== "children") {
|
|
4122
|
-
const newVal = patches.applyAll(block.value, [{
|
|
4111
|
+
const newVal = patches.applyAll(block.node.value, [{
|
|
4123
4112
|
...patch,
|
|
4124
4113
|
path: patch.path.slice(1)
|
|
4125
4114
|
}]);
|
|
4126
4115
|
slate.Transforms.setNodes(editor, {
|
|
4127
|
-
...block,
|
|
4116
|
+
...block.node,
|
|
4128
4117
|
value: newVal
|
|
4129
4118
|
}, {
|
|
4130
|
-
at:
|
|
4119
|
+
at: [block.index]
|
|
4131
4120
|
});
|
|
4132
4121
|
} else
|
|
4133
4122
|
return !1;
|
|
4134
|
-
return
|
|
4123
|
+
return !0;
|
|
4135
4124
|
}
|
|
4136
4125
|
function unsetPatch(editor, patch) {
|
|
4137
4126
|
if (patch.path.length === 0) {
|
|
4138
|
-
debug$f("Removing everything"), debugState(editor, "before");
|
|
4139
4127
|
const previousSelection = editor.selection;
|
|
4140
4128
|
slate.Transforms.deselect(editor);
|
|
4141
4129
|
const children = slate.Node.children(editor, [], {
|
|
@@ -4156,71 +4144,97 @@ function unsetPatch(editor, patch) {
|
|
|
4156
4144
|
path: [0, 0],
|
|
4157
4145
|
offset: 0
|
|
4158
4146
|
}
|
|
4159
|
-
}), editor.onChange(),
|
|
4147
|
+
}), editor.onChange(), !0;
|
|
4160
4148
|
}
|
|
4161
|
-
const
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4149
|
+
const block = findBlock(editor.children, patch.path);
|
|
4150
|
+
if (!block)
|
|
4151
|
+
return !1;
|
|
4152
|
+
if (patch.path.length === 1)
|
|
4153
|
+
return slate.Transforms.removeNodes(editor, {
|
|
4154
|
+
at: [block.index]
|
|
4155
|
+
}), !0;
|
|
4156
|
+
const child = findBlockChild(block, patch.path);
|
|
4157
|
+
if (editor.isTextBlock(block.node) && child && patch.path[1] === "children" && patch.path.length === 3)
|
|
4158
|
+
return slate.Transforms.removeNodes(editor, {
|
|
4159
|
+
at: [block.index, child.index]
|
|
4160
|
+
}), !0;
|
|
4161
|
+
if (child && !slate.Text.isText(child.node)) {
|
|
4162
|
+
const propEntry = patch.path.slice(3).at(0);
|
|
4163
|
+
if (propEntry === void 0 || typeof propEntry == "string" && ["_key", "_type", "children", "__inline"].includes(propEntry))
|
|
4164
|
+
return !1;
|
|
4165
|
+
const value = "value" in child.node && typeof child.node.value == "object" ? child.node.value : {}, newValue = patches.applyAll(value, [{
|
|
4166
|
+
...patch,
|
|
4167
|
+
path: patch.path.slice(3)
|
|
4168
|
+
}]);
|
|
4169
|
+
return slate.Transforms.setNodes(editor, {
|
|
4170
|
+
...child.node,
|
|
4171
|
+
value: newValue
|
|
4172
|
+
}, {
|
|
4173
|
+
at: [block.index, child.index]
|
|
4174
|
+
}), !0;
|
|
4174
4175
|
}
|
|
4175
|
-
|
|
4176
|
-
at
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4176
|
+
if (child && slate.Text.isText(child.node)) {
|
|
4177
|
+
const propPath = patch.path.slice(3), propEntry = propPath.at(0);
|
|
4178
|
+
if (propEntry === void 0 || typeof propEntry == "string" && ["_key", "_type"].includes(propEntry))
|
|
4179
|
+
return !1;
|
|
4180
|
+
if (typeof propEntry == "string" && propEntry === "text")
|
|
4181
|
+
return editor.apply({
|
|
4182
|
+
type: "remove_text",
|
|
4183
|
+
path: [block.index, child.index],
|
|
4184
|
+
offset: 0,
|
|
4185
|
+
text: child.node.text
|
|
4186
|
+
}), !0;
|
|
4187
|
+
const newNode = patches.applyAll(child.node, [{
|
|
4188
|
+
...patch,
|
|
4189
|
+
path: propPath
|
|
4190
|
+
}]), removedProperties = Object.keys(child.node).filter((property) => newNode[property] === void 0);
|
|
4191
|
+
return slate.Transforms.unsetNodes(editor, removedProperties, {
|
|
4192
|
+
at: [block.index, child.index]
|
|
4193
|
+
}), !0;
|
|
4194
|
+
}
|
|
4195
|
+
if (!child) {
|
|
4196
|
+
if ("value" in block.node) {
|
|
4197
|
+
const newVal = patches.applyAll(block.node.value, [{
|
|
4198
|
+
...patch,
|
|
4199
|
+
path: patch.path.slice(1)
|
|
4200
|
+
}]);
|
|
4201
|
+
return slate.Transforms.setNodes(editor, {
|
|
4202
|
+
...block.node,
|
|
4203
|
+
value: newVal
|
|
4204
|
+
}, {
|
|
4205
|
+
at: [block.index]
|
|
4206
|
+
}), !0;
|
|
4207
|
+
}
|
|
4208
|
+
return !1;
|
|
4209
|
+
}
|
|
4210
|
+
return !1;
|
|
4184
4211
|
}
|
|
4185
|
-
function
|
|
4212
|
+
function findBlock(children, path) {
|
|
4186
4213
|
let blockIndex = -1;
|
|
4187
|
-
const block =
|
|
4188
|
-
const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
|
|
4214
|
+
const block = children.find((node, index) => {
|
|
4215
|
+
const isMatch = util_sliceBlocks.isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
|
|
4189
4216
|
return isMatch && (blockIndex = index), isMatch;
|
|
4190
4217
|
});
|
|
4191
|
-
|
|
4192
|
-
block,
|
|
4193
|
-
path: [blockIndex]
|
|
4194
|
-
} : {};
|
|
4195
|
-
}
|
|
4196
|
-
function findBlockAndChildFromPath(editor, path) {
|
|
4197
|
-
const {
|
|
4198
|
-
block,
|
|
4199
|
-
path: blockPath
|
|
4200
|
-
} = findBlockFromPath(editor, path);
|
|
4201
|
-
if (!(slate.Element.isElement(block) && path[1] === "children"))
|
|
4218
|
+
if (block)
|
|
4202
4219
|
return {
|
|
4203
|
-
block,
|
|
4204
|
-
|
|
4205
|
-
child: void 0,
|
|
4206
|
-
childPath: void 0
|
|
4220
|
+
node: block,
|
|
4221
|
+
index: blockIndex
|
|
4207
4222
|
};
|
|
4223
|
+
}
|
|
4224
|
+
function findBlockChild(block, path) {
|
|
4225
|
+
const blockNode = block.node;
|
|
4226
|
+
if (!slate.Element.isElement(blockNode) || path[1] !== "children")
|
|
4227
|
+
return;
|
|
4208
4228
|
let childIndex = -1;
|
|
4209
|
-
const child =
|
|
4210
|
-
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
|
|
4229
|
+
const child = blockNode.children.find((node, index) => {
|
|
4230
|
+
const isMatch = util_sliceBlocks.isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
|
|
4211
4231
|
return isMatch && (childIndex = index), isMatch;
|
|
4212
4232
|
});
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
} : {
|
|
4219
|
-
block,
|
|
4220
|
-
blockPath,
|
|
4221
|
-
child: void 0,
|
|
4222
|
-
childPath: void 0
|
|
4223
|
-
};
|
|
4233
|
+
if (child)
|
|
4234
|
+
return {
|
|
4235
|
+
node: child,
|
|
4236
|
+
index: childIndex
|
|
4237
|
+
};
|
|
4224
4238
|
}
|
|
4225
4239
|
function insertTextPatch(schema2, children, operation, beforeValue) {
|
|
4226
4240
|
const block = util_sliceBlocks.isTextBlock({
|
|
@@ -5881,6 +5895,57 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
5881
5895
|
type: "decorator.add"
|
|
5882
5896
|
})]]
|
|
5883
5897
|
})], abstractDeleteBehaviors = [behaviors_index.defineBehavior({
|
|
5898
|
+
on: "delete.backward",
|
|
5899
|
+
guard: ({
|
|
5900
|
+
snapshot
|
|
5901
|
+
}) => snapshot.context.selection ? {
|
|
5902
|
+
selection: snapshot.context.selection
|
|
5903
|
+
} : !1,
|
|
5904
|
+
actions: [({
|
|
5905
|
+
event
|
|
5906
|
+
}, {
|
|
5907
|
+
selection
|
|
5908
|
+
}) => [behaviors_index.raise({
|
|
5909
|
+
type: "delete",
|
|
5910
|
+
direction: "backward",
|
|
5911
|
+
unit: event.unit,
|
|
5912
|
+
at: selection
|
|
5913
|
+
})]]
|
|
5914
|
+
}), behaviors_index.defineBehavior({
|
|
5915
|
+
on: "delete.forward",
|
|
5916
|
+
guard: ({
|
|
5917
|
+
snapshot
|
|
5918
|
+
}) => snapshot.context.selection ? {
|
|
5919
|
+
selection: snapshot.context.selection
|
|
5920
|
+
} : !1,
|
|
5921
|
+
actions: [({
|
|
5922
|
+
event
|
|
5923
|
+
}, {
|
|
5924
|
+
selection
|
|
5925
|
+
}) => [behaviors_index.raise({
|
|
5926
|
+
type: "delete",
|
|
5927
|
+
direction: "forward",
|
|
5928
|
+
unit: event.unit,
|
|
5929
|
+
at: selection
|
|
5930
|
+
})]]
|
|
5931
|
+
}), behaviors_index.defineBehavior({
|
|
5932
|
+
on: "delete.block",
|
|
5933
|
+
actions: [({
|
|
5934
|
+
event
|
|
5935
|
+
}) => [behaviors_index.raise({
|
|
5936
|
+
type: "delete",
|
|
5937
|
+
at: {
|
|
5938
|
+
anchor: {
|
|
5939
|
+
path: event.at,
|
|
5940
|
+
offset: 0
|
|
5941
|
+
},
|
|
5942
|
+
focus: {
|
|
5943
|
+
path: event.at,
|
|
5944
|
+
offset: 0
|
|
5945
|
+
}
|
|
5946
|
+
}
|
|
5947
|
+
})]]
|
|
5948
|
+
}), behaviors_index.defineBehavior({
|
|
5884
5949
|
on: "delete.text",
|
|
5885
5950
|
guard: ({
|
|
5886
5951
|
snapshot,
|
|
@@ -6295,7 +6360,12 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6295
6360
|
actions: [(_, {
|
|
6296
6361
|
newTextBlock,
|
|
6297
6362
|
selection
|
|
6298
|
-
}) => [behaviors_index.raise({
|
|
6363
|
+
}) => util_selectionPointToBlockOffset.isSelectionCollapsed(selection) ? [behaviors_index.raise({
|
|
6364
|
+
type: "insert.block",
|
|
6365
|
+
block: newTextBlock,
|
|
6366
|
+
placement: "after",
|
|
6367
|
+
select: "start"
|
|
6368
|
+
})] : [behaviors_index.raise({
|
|
6299
6369
|
type: "delete",
|
|
6300
6370
|
at: selection
|
|
6301
6371
|
}), behaviors_index.raise({
|
|
@@ -6707,7 +6777,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6707
6777
|
function isSyntheticBehaviorEvent(event) {
|
|
6708
6778
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
6709
6779
|
}
|
|
6710
|
-
const abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
6780
|
+
const abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.forward", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
6711
6781
|
function isAbstractBehaviorEvent(event) {
|
|
6712
6782
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
6713
6783
|
}
|
|
@@ -8860,20 +8930,22 @@ async function updateValue({
|
|
|
8860
8930
|
const hadSelection = !!slateEditor.selection;
|
|
8861
8931
|
if ((!value || value.length === 0) && (debug$5("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
8862
8932
|
withoutSaving(slateEditor, () => {
|
|
8863
|
-
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8876
|
-
|
|
8933
|
+
withRemoteChanges(slateEditor, () => {
|
|
8934
|
+
withoutPatching(slateEditor, () => {
|
|
8935
|
+
if (doneSyncing)
|
|
8936
|
+
return;
|
|
8937
|
+
hadSelection && slate.Transforms.deselect(slateEditor);
|
|
8938
|
+
const childrenLength = slateEditor.children.length;
|
|
8939
|
+
slateEditor.children.forEach((_, index) => {
|
|
8940
|
+
slate.Transforms.removeNodes(slateEditor, {
|
|
8941
|
+
at: [childrenLength - 1 - index]
|
|
8942
|
+
});
|
|
8943
|
+
}), slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
8944
|
+
decorators: []
|
|
8945
|
+
}), {
|
|
8946
|
+
at: [0]
|
|
8947
|
+
}), hadSelection && slate.Transforms.select(slateEditor, [0, 0]);
|
|
8948
|
+
});
|
|
8877
8949
|
});
|
|
8878
8950
|
});
|
|
8879
8951
|
}), isChanged = !0), value && value.length > 0) {
|