@portabletext/editor 1.50.6 → 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.
Files changed (34) hide show
  1. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +1 -1
  2. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  3. package/lib/_chunks-es/util.selection-point-to-block-offset.js +1 -1
  4. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  5. package/lib/behaviors/index.d.cts +24 -16
  6. package/lib/behaviors/index.d.ts +24 -16
  7. package/lib/index.cjs +320 -252
  8. package/lib/index.cjs.map +1 -1
  9. package/lib/index.d.cts +24 -16
  10. package/lib/index.d.ts +24 -16
  11. package/lib/index.js +322 -254
  12. package/lib/index.js.map +1 -1
  13. package/lib/plugins/index.d.cts +24 -16
  14. package/lib/plugins/index.d.ts +24 -16
  15. package/lib/selectors/index.d.cts +24 -16
  16. package/lib/selectors/index.d.ts +24 -16
  17. package/lib/utils/index.d.cts +24 -16
  18. package/lib/utils/index.d.ts +24 -16
  19. package/package.json +4 -4
  20. package/src/behaviors/behavior.abstract.delete.ts +60 -0
  21. package/src/behaviors/behavior.abstract.split.ts +23 -13
  22. package/src/behaviors/behavior.types.event.ts +23 -16
  23. package/src/editor/plugins/create-with-event-listeners.ts +41 -1
  24. package/src/editor/sync-machine.ts +26 -20
  25. package/src/internal-utils/applyPatch.ts +298 -207
  26. package/src/internal-utils/slate-utils.ts +23 -0
  27. package/src/internal-utils/test-editor.tsx +45 -0
  28. package/src/operations/behavior.operation.delete.ts +36 -22
  29. package/src/operations/behavior.operations.ts +0 -27
  30. package/src/utils/util.is-selection-collapsed.ts +2 -1
  31. package/src/internal-utils/__tests__/dmpToOperations.test.ts +0 -207
  32. package/src/operations/behavior.operation.delete.backward.ts +0 -8
  33. package/src/operations/behavior.operation.delete.block.ts +0 -24
  34. 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$i = 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");
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$i), 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);
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
  }) {
@@ -1558,7 +1569,7 @@ function getEditorSnapshot({
1558
1569
  }
1559
1570
  };
1560
1571
  }
1561
- const debug$h = debugWithName("plugin:withPortableTextMarkModel");
1572
+ const debug$g = debugWithName("plugin:withPortableTextMarkModel");
1562
1573
  function createWithPortableTextMarkModel(editorActor) {
1563
1574
  return function(editor) {
1564
1575
  const {
@@ -1572,7 +1583,7 @@ function createWithPortableTextMarkModel(editorActor) {
1572
1583
  for (const [child, childPath] of children) {
1573
1584
  const nextNode = node.children[childPath[1] + 1];
1574
1585
  if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
1575
- debug$h("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
1586
+ debug$g("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
1576
1587
  type: "normalizing"
1577
1588
  }), slate.Transforms.mergeNodes(editor, {
1578
1589
  at: [childPath[0], childPath[1] + 1],
@@ -1585,7 +1596,7 @@ function createWithPortableTextMarkModel(editorActor) {
1585
1596
  }
1586
1597
  }
1587
1598
  if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
1588
- debug$h("Adding .markDefs to block node"), editorActor.send({
1599
+ debug$g("Adding .markDefs to block node"), editorActor.send({
1589
1600
  type: "normalizing"
1590
1601
  }), slate.Transforms.setNodes(editor, {
1591
1602
  markDefs: []
@@ -1597,7 +1608,7 @@ function createWithPortableTextMarkModel(editorActor) {
1597
1608
  return;
1598
1609
  }
1599
1610
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
1600
- debug$h("Adding .marks to span node"), editorActor.send({
1611
+ debug$g("Adding .marks to span node"), editorActor.send({
1601
1612
  type: "normalizing"
1602
1613
  }), slate.Transforms.setNodes(editor, {
1603
1614
  marks: []
@@ -1611,7 +1622,7 @@ function createWithPortableTextMarkModel(editorActor) {
1611
1622
  if (editor.isTextSpan(node)) {
1612
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));
1613
1624
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
1614
- debug$h("Removing annotations from empty span node"), editorActor.send({
1625
+ debug$g("Removing annotations from empty span node"), editorActor.send({
1615
1626
  type: "normalizing"
1616
1627
  }), slate.Transforms.setNodes(editor, {
1617
1628
  marks: node.marks?.filter((mark) => decorators2.includes(mark))
@@ -1629,7 +1640,7 @@ function createWithPortableTextMarkModel(editorActor) {
1629
1640
  if (editor.isTextSpan(child)) {
1630
1641
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
1631
1642
  if (orphanedAnnotations.length > 0) {
1632
- debug$h("Removing orphaned annotations from span node"), editorActor.send({
1643
+ debug$g("Removing orphaned annotations from span node"), editorActor.send({
1633
1644
  type: "normalizing"
1634
1645
  }), slate.Transforms.setNodes(editor, {
1635
1646
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -1647,7 +1658,7 @@ function createWithPortableTextMarkModel(editorActor) {
1647
1658
  if (editor.isTextBlock(block)) {
1648
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));
1649
1660
  if (orphanedAnnotations.length > 0) {
1650
- debug$h("Removing orphaned annotations from span node"), editorActor.send({
1661
+ debug$g("Removing orphaned annotations from span node"), editorActor.send({
1651
1662
  type: "normalizing"
1652
1663
  }), slate.Transforms.setNodes(editor, {
1653
1664
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -1665,7 +1676,7 @@ function createWithPortableTextMarkModel(editorActor) {
1665
1676
  for (const markDef of markDefs)
1666
1677
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
1667
1678
  if (markDefs.length !== newMarkDefs.length) {
1668
- debug$h("Removing duplicate markDefs"), editorActor.send({
1679
+ debug$g("Removing duplicate markDefs"), editorActor.send({
1669
1680
  type: "normalizing"
1670
1681
  }), slate.Transforms.setNodes(editor, {
1671
1682
  markDefs: newMarkDefs
@@ -1680,7 +1691,7 @@ function createWithPortableTextMarkModel(editorActor) {
1680
1691
  if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
1681
1692
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
1682
1693
  if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
1683
- debug$h("Removing markDef not in use"), editorActor.send({
1694
+ debug$g("Removing markDef not in use"), editorActor.send({
1684
1695
  type: "normalizing"
1685
1696
  }), slate.Transforms.setNodes(editor, {
1686
1697
  markDefs: newMarkDefs
@@ -1833,7 +1844,7 @@ function createWithPortableTextMarkModel(editorActor) {
1833
1844
  const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
1834
1845
  if (editor.isTextBlock(targetBlock)) {
1835
1846
  const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
1836
- debug$h("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
1847
+ debug$g("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
1837
1848
  markDefs: newMarkDefs
1838
1849
  }, {
1839
1850
  at: targetPath,
@@ -2543,7 +2554,7 @@ function withUndoStep(editor, fn) {
2543
2554
  function getCurrentUndoStepId(editor) {
2544
2555
  return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
2545
2556
  }
2546
- const debug$g = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
2557
+ const debug$f = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
2547
2558
  const state = SAVING.get(editor);
2548
2559
  return state === void 0 ? !0 : state;
2549
2560
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
@@ -2556,7 +2567,7 @@ function createWithUndoRedo(options) {
2556
2567
  const remotePatches = getRemotePatches(editor);
2557
2568
  let previousUndoStepId = getCurrentUndoStepId(editor);
2558
2569
  options.subscriptions.push(() => {
2559
- debug$g("Subscribing to patches");
2570
+ debug$f("Subscribing to patches");
2560
2571
  const sub = editorActor.on("patches", ({
2561
2572
  patches: patches2,
2562
2573
  snapshot
@@ -2565,7 +2576,7 @@ function createWithUndoRedo(options) {
2565
2576
  patches2.forEach((patch) => {
2566
2577
  if (!reset && patch.origin !== "local" && remotePatches) {
2567
2578
  if (patch.type === "unset" && patch.path.length === 0) {
2568
- debug$g("Someone else cleared the content, resetting undo/redo history"), editor.history = {
2579
+ debug$f("Someone else cleared the content, resetting undo/redo history"), editor.history = {
2569
2580
  undos: [],
2570
2581
  redos: []
2571
2582
  }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
@@ -2581,7 +2592,7 @@ function createWithUndoRedo(options) {
2581
2592
  }), previousSnapshot = snapshot;
2582
2593
  });
2583
2594
  return () => {
2584
- debug$g("Unsubscribing to patches"), sub.unsubscribe();
2595
+ debug$f("Unsubscribing to patches"), sub.unsubscribe();
2585
2596
  };
2586
2597
  }), editor.history = {
2587
2598
  undos: [],
@@ -2620,7 +2631,7 @@ function createWithUndoRedo(options) {
2620
2631
  operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
2621
2632
  timestamp: /* @__PURE__ */ new Date()
2622
2633
  };
2623
- undos.push(newStep), debug$g("Created new undo step", step);
2634
+ undos.push(newStep), debug$f("Created new undo step", step);
2624
2635
  }
2625
2636
  for (; undos.length > UNDO_STEP_LIMIT; )
2626
2637
  undos.shift();
@@ -2638,7 +2649,7 @@ const historyUndoOperationImplementation = ({
2638
2649
  } = editor.history, remotePatches = getRemotePatches(editor);
2639
2650
  if (undos.length > 0) {
2640
2651
  const step = undos[undos.length - 1];
2641
- if (debug$g("Undoing", step), step.operations.length > 0) {
2652
+ if (debug$f("Undoing", step), step.operations.length > 0) {
2642
2653
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
2643
2654
  let transformedOperations = step.operations;
2644
2655
  otherPatches.forEach((item) => {
@@ -2656,7 +2667,7 @@ const historyUndoOperationImplementation = ({
2656
2667
  });
2657
2668
  });
2658
2669
  } catch (err) {
2659
- debug$g("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2670
+ debug$f("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2660
2671
  undos: [],
2661
2672
  redos: []
2662
2673
  }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
@@ -2673,7 +2684,7 @@ const historyUndoOperationImplementation = ({
2673
2684
  } = editor.history, remotePatches = getRemotePatches(editor);
2674
2685
  if (redos.length > 0) {
2675
2686
  const step = redos[redos.length - 1];
2676
- if (debug$g("Redoing", step), step.operations.length > 0) {
2687
+ if (debug$f("Redoing", step), step.operations.length > 0) {
2677
2688
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
2678
2689
  let transformedOperations = step.operations;
2679
2690
  otherPatches.forEach((item) => {
@@ -2690,7 +2701,7 @@ const historyUndoOperationImplementation = ({
2690
2701
  });
2691
2702
  });
2692
2703
  } catch (err) {
2693
- debug$g("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2704
+ debug$f("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2694
2705
  undos: [],
2695
2706
  redos: []
2696
2707
  }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
@@ -2708,16 +2719,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
2708
2719
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
2709
2720
  _key: blk._key
2710
2721
  }, patch.path[0]));
2711
- return debug$g(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
2722
+ return debug$f(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
2712
2723
  }
2713
2724
  if (patch.type === "unset" && patch.path.length === 1) {
2714
2725
  const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
2715
2726
  _key: blk._key
2716
2727
  }, patch.path[0]));
2717
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$g("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
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)];
2718
2729
  }
2719
2730
  if (patch.type === "unset" && patch.path.length === 0)
2720
- return debug$g(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
2731
+ return debug$f(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
2721
2732
  if (patch.type === "diffMatchPatch") {
2722
2733
  const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
2723
2734
  return !operationTargetBlock || !isEqual__default.default({
@@ -3167,58 +3178,29 @@ const addAnnotationOperationImplementation = ({
3167
3178
  };
3168
3179
  }
3169
3180
  }, deleteOperationImplementation = ({
3170
- context,
3171
3181
  operation
3172
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
+ }
3173
3196
  const range = toSlateRange(operation.at, operation.editor);
3174
3197
  if (!range)
3175
3198
  throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
3176
- if (slate.Range.isCollapsed(range)) {
3177
- const [focusBlock] = getFocusBlock({
3178
- editor: {
3179
- ...operation.editor,
3180
- selection: range
3181
- }
3182
- }), [focusChild] = getFocusChild({
3183
- editor: {
3184
- ...operation.editor,
3185
- selection: range
3186
- }
3187
- });
3188
- if (focusBlock && focusBlock._type === context.schema.block.name && focusChild && focusChild._type === context.schema.span.name)
3189
- return;
3190
- }
3191
3199
  operation.editor.delete({
3192
- at: range
3193
- });
3194
- }, deleteBackwardOperationImplementation = ({
3195
- operation
3196
- }) => {
3197
- slate.deleteBackward(operation.editor, operation.unit);
3198
- }, deleteBlockOperationImplementation = ({
3199
- operation
3200
- }) => {
3201
- const range = toSlateRange({
3202
- anchor: {
3203
- path: operation.at,
3204
- offset: 0
3205
- },
3206
- focus: {
3207
- path: operation.at,
3208
- offset: 0
3209
- }
3210
- }, operation.editor);
3211
- if (!range) {
3212
- console.error("Unable to find Slate range from selection points");
3213
- return;
3214
- }
3215
- slate.Transforms.removeNodes(operation.editor, {
3216
- at: range
3200
+ at: range,
3201
+ reverse: operation.direction === "backward",
3202
+ unit: operation.unit
3217
3203
  });
3218
- }, deleteForwardOperationImplementation = ({
3219
- operation
3220
- }) => {
3221
- slate.deleteForward(operation.editor, operation.unit);
3222
3204
  }, insertInlineObjectOperationImplementation = ({
3223
3205
  context,
3224
3206
  operation
@@ -3511,9 +3493,6 @@ const moveBackwardOperationImplementation = ({
3511
3493
  "decorator.add": decoratorAddOperationImplementation,
3512
3494
  "decorator.remove": removeDecoratorOperationImplementation,
3513
3495
  delete: deleteOperationImplementation,
3514
- "delete.backward": deleteBackwardOperationImplementation,
3515
- "delete.forward": deleteForwardOperationImplementation,
3516
- "delete.block": deleteBlockOperationImplementation,
3517
3496
  "history.redo": historyRedoOperationImplementation,
3518
3497
  "history.undo": historyUndoOperationImplementation,
3519
3498
  "insert.block": insertBlockOperationImplementation,
@@ -3580,27 +3559,6 @@ function performOperation({
3580
3559
  });
3581
3560
  break;
3582
3561
  }
3583
- case "delete.backward": {
3584
- behaviorOperationImplementations["delete.backward"]({
3585
- context,
3586
- operation
3587
- });
3588
- break;
3589
- }
3590
- case "delete.block": {
3591
- behaviorOperationImplementations["delete.block"]({
3592
- context,
3593
- operation
3594
- });
3595
- break;
3596
- }
3597
- case "delete.forward": {
3598
- behaviorOperationImplementations["delete.forward"]({
3599
- context,
3600
- operation
3601
- });
3602
- break;
3603
- }
3604
3562
  case "history.redo": {
3605
3563
  behaviorOperationImplementations["history.redo"]({
3606
3564
  context,
@@ -3691,9 +3649,39 @@ function createWithEventListeners(editorActor) {
3691
3649
  if (editorActor.getSnapshot().context.maxBlocks !== void 0)
3692
3650
  return editor;
3693
3651
  const {
3652
+ delete: editorDelete,
3694
3653
  select
3695
3654
  } = editor;
3696
- return editor.deleteBackward = (unit) => {
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) => {
3697
3685
  if (isApplyingBehaviorOperations(editor)) {
3698
3686
  console.error("Unexpected call to .deleteBackward(...)");
3699
3687
  return;
@@ -3951,13 +3939,9 @@ function createWithObjectKeys(editorActor) {
3951
3939
  }, editor;
3952
3940
  };
3953
3941
  }
3954
- const debug$f = debugWithName("applyPatches"), debugVerbose = debug$f.enabled && !0;
3955
3942
  function createApplyPatch(schema2) {
3956
3943
  return (editor, patch) => {
3957
3944
  let changed = !1;
3958
- debugVerbose && (debug$f(`
3959
-
3960
- NEW PATCH =============================================================`), debug$f(JSON.stringify(patch, null, 2)));
3961
3945
  try {
3962
3946
  switch (patch.type) {
3963
3947
  case "insert":
@@ -3972,8 +3956,6 @@ NEW PATCH =============================================================`), debug
3972
3956
  case "diffMatchPatch":
3973
3957
  changed = diffMatchPatch(editor, patch);
3974
3958
  break;
3975
- default:
3976
- debug$f("Unhandled patch", patch.type);
3977
3959
  }
3978
3960
  } catch (err) {
3979
3961
  console.error(err);
@@ -3982,164 +3964,166 @@ NEW PATCH =============================================================`), debug
3982
3964
  };
3983
3965
  }
3984
3966
  function diffMatchPatch(editor, patch) {
3985
- const {
3986
- block,
3987
- child,
3988
- childPath
3989
- } = findBlockAndChildFromPath(editor, patch.path);
3967
+ const block = findBlock(editor.children, patch.path);
3990
3968
  if (!block)
3991
- return debug$f("Block not found"), !1;
3992
- if (!child || !childPath)
3993
- return debug$f("Child not found"), !1;
3994
- if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
3995
3969
  return !1;
3996
- const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
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, {
3997
3974
  allowExceedingIndices: !0
3998
- }), diff$1 = cleanupEfficiency(diff(child.text, newValue), 5);
3999
- debugState(editor, "before");
3975
+ }), diff$1 = cleanupEfficiency(diff(child.node.text, newValue), 5);
4000
3976
  let offset = 0;
4001
3977
  for (const [op, text] of diff$1)
4002
3978
  op === DIFF_INSERT ? (editor.apply({
4003
3979
  type: "insert_text",
4004
- path: childPath,
3980
+ path: [block.index, child.index],
4005
3981
  offset,
4006
3982
  text
4007
3983
  }), offset += text.length) : op === DIFF_DELETE ? editor.apply({
4008
3984
  type: "remove_text",
4009
- path: childPath,
3985
+ path: [block.index, child.index],
4010
3986
  offset,
4011
3987
  text
4012
3988
  }) : op === DIFF_EQUAL && (offset += text.length);
4013
- return debugState(editor, "after"), !0;
3989
+ return !0;
4014
3990
  }
4015
3991
  function insertPatch(editor, patch, schema2) {
4016
- const {
4017
- block: targetBlock,
4018
- child: targetChild,
4019
- blockPath: targetBlockPath,
4020
- childPath: targetChildPath
4021
- } = findBlockAndChildFromPath(editor, patch.path);
4022
- if (!targetBlock || !targetBlockPath)
4023
- return debug$f("Block not found"), !1;
4024
- if (patch.path.length > 1 && patch.path[1] !== "children")
4025
- 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;
4026
3995
  if (patch.path.length === 1) {
4027
3996
  const {
4028
3997
  items: items2,
4029
3998
  position: position2
4030
3999
  } = patch, blocksToInsert = toSlateValue(items2, {
4031
4000
  schemaTypes: schema2
4032
- }, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
4033
- debug$f(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before");
4034
- 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);
4035
4002
  return slate.Transforms.insertNodes(editor, blocksToInsert, {
4036
4003
  at: [normalizedIdx2]
4037
4004
  }), editorWasEmptyBefore && typeof patch.path[0] == "number" && patch.path[0] === 0 && slate.Transforms.removeNodes(editor, {
4038
4005
  at: [position2 === "before" ? targetBlockIndex + 1 : targetBlockIndex]
4039
- }), debugState(editor, "after"), !0;
4006
+ }), !0;
4040
4007
  }
4041
4008
  const {
4042
4009
  items,
4043
4010
  position
4044
- } = patch;
4045
- if (!targetChild || !targetChildPath)
4046
- return debug$f("Child not found"), !1;
4047
- const childrenToInsert = targetBlock && toSlateValue([{
4048
- ...targetBlock,
4011
+ } = patch, targetChild = findBlockChild(block, patch.path);
4012
+ if (!targetChild)
4013
+ return !1;
4014
+ const childrenToInsert = toSlateValue([{
4015
+ ...block.node,
4049
4016
  children: items
4050
4017
  }], {
4051
4018
  schemaTypes: schema2
4052
- }, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
4053
- return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
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, {
4054
4021
  at: childInsertPath
4055
- }), debugState(editor, "after"), !0;
4022
+ }), !0;
4056
4023
  }
4057
4024
  function setPatch(editor, patch) {
4058
4025
  let value = patch.value;
4059
4026
  typeof patch.path[3] == "string" && (value = {}, value[patch.path[3]] = patch.value);
4060
- const {
4061
- block,
4062
- blockPath,
4063
- child,
4064
- childPath
4065
- } = findBlockAndChildFromPath(editor, patch.path);
4027
+ const block = findBlock(editor.children, patch.path);
4066
4028
  if (!block)
4067
- return debug$f("Block not found"), !1;
4068
- const isTextBlock = editor.isTextBlock(block);
4029
+ return !1;
4030
+ const isTextBlock = editor.isTextBlock(block.node);
4069
4031
  if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
4070
- return debug$f("Ignoring setting void value"), !1;
4071
- if (debugState(editor, "before"), isTextBlock && child && childPath) {
4072
- if (slate.Text.isText(value) && slate.Text.isText(child)) {
4073
- const newText = child.text;
4074
- value.text !== newText && (debug$f("Setting text property"), editor.apply({
4075
- type: "remove_text",
4076
- path: childPath,
4077
- offset: 0,
4078
- text: newText
4079
- }), editor.apply({
4080
- type: "insert_text",
4081
- path: childPath,
4082
- offset: 0,
4083
- text: value.text
4084
- }), editor.onChange());
4085
- } else
4086
- debug$f("Setting non-text property"), editor.apply({
4087
- type: "set_node",
4088
- path: childPath,
4089
- properties: {},
4090
- newProperties: value
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]
4091
4074
  });
4075
+ }
4092
4076
  return !0;
4093
- } else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
4094
- debug$f("Setting block property");
4077
+ } else if (slate.Element.isElement(block.node) && patch.path.length === 1) {
4095
4078
  const {
4096
4079
  children,
4097
4080
  ...nextRest
4098
4081
  } = value, {
4099
4082
  children: prevChildren,
4100
4083
  ...prevRest
4101
- } = block || {
4084
+ } = block.node || {
4102
4085
  children: void 0
4103
4086
  };
4104
4087
  editor.apply({
4105
4088
  type: "set_node",
4106
- path: blockPath,
4089
+ path: [block.index],
4107
4090
  properties: {
4108
4091
  ...prevRest
4109
4092
  },
4110
4093
  newProperties: nextRest
4111
- }), debug$f("Setting children"), block.children.forEach((c, cIndex) => {
4094
+ });
4095
+ const blockNode = block.node;
4096
+ blockNode.children.forEach((child2, childIndex) => {
4112
4097
  editor.apply({
4113
4098
  type: "remove_node",
4114
- path: blockPath.concat(block.children.length - 1 - cIndex),
4115
- node: c
4099
+ path: [block.index, blockNode.children.length - 1 - childIndex],
4100
+ node: child2
4116
4101
  });
4117
- }), Array.isArray(children) && children.forEach((c, cIndex) => {
4102
+ }), Array.isArray(children) && children.forEach((child2, childIndex) => {
4118
4103
  editor.apply({
4119
4104
  type: "insert_node",
4120
- path: blockPath.concat(cIndex),
4121
- node: c
4105
+ path: [block.index, childIndex],
4106
+ node: child2
4122
4107
  });
4123
4108
  });
4124
- } else if (block && "value" in block)
4109
+ } else if (block && "value" in block.node)
4125
4110
  if (patch.path.length > 1 && patch.path[1] !== "children") {
4126
- const newVal = patches.applyAll(block.value, [{
4111
+ const newVal = patches.applyAll(block.node.value, [{
4127
4112
  ...patch,
4128
4113
  path: patch.path.slice(1)
4129
4114
  }]);
4130
4115
  slate.Transforms.setNodes(editor, {
4131
- ...block,
4116
+ ...block.node,
4132
4117
  value: newVal
4133
4118
  }, {
4134
- at: blockPath
4119
+ at: [block.index]
4135
4120
  });
4136
4121
  } else
4137
4122
  return !1;
4138
- return debugState(editor, "after"), !0;
4123
+ return !0;
4139
4124
  }
4140
4125
  function unsetPatch(editor, patch) {
4141
4126
  if (patch.path.length === 0) {
4142
- debug$f("Removing everything"), debugState(editor, "before");
4143
4127
  const previousSelection = editor.selection;
4144
4128
  slate.Transforms.deselect(editor);
4145
4129
  const children = slate.Node.children(editor, [], {
@@ -4160,71 +4144,97 @@ function unsetPatch(editor, patch) {
4160
4144
  path: [0, 0],
4161
4145
  offset: 0
4162
4146
  }
4163
- }), editor.onChange(), debugState(editor, "after"), !0;
4147
+ }), editor.onChange(), !0;
4164
4148
  }
4165
- const {
4166
- block,
4167
- blockPath,
4168
- child,
4169
- childPath
4170
- } = findBlockAndChildFromPath(editor, patch.path);
4171
- if (patch.path.length === 1) {
4172
- if (!block || !blockPath)
4173
- return debug$f("Block not found"), !1;
4174
- const blockIndex = blockPath[0];
4175
- return debug$f(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
4176
- at: [blockIndex]
4177
- }), debugState(editor, "after"), !0;
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;
4178
4175
  }
4179
- return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$f("Child not found"), !1) : (debug$f(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$f(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
4180
- at: childPath
4181
- }), debugState(editor, "after"), !0) : !1;
4182
- }
4183
- function isKeyedSegment(segment) {
4184
- return typeof segment == "object" && "_key" in segment;
4185
- }
4186
- function debugState(editor, stateName) {
4187
- debugVerbose && (debug$f(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$f(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
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;
4188
4211
  }
4189
- function findBlockFromPath(editor, path) {
4212
+ function findBlock(children, path) {
4190
4213
  let blockIndex = -1;
4191
- const block = editor.children.find((node, index) => {
4192
- 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];
4193
4216
  return isMatch && (blockIndex = index), isMatch;
4194
4217
  });
4195
- return block ? {
4196
- block,
4197
- path: [blockIndex]
4198
- } : {};
4199
- }
4200
- function findBlockAndChildFromPath(editor, path) {
4201
- const {
4202
- block,
4203
- path: blockPath
4204
- } = findBlockFromPath(editor, path);
4205
- if (!(slate.Element.isElement(block) && path[1] === "children"))
4218
+ if (block)
4206
4219
  return {
4207
- block,
4208
- blockPath,
4209
- child: void 0,
4210
- childPath: void 0
4220
+ node: block,
4221
+ index: blockIndex
4211
4222
  };
4223
+ }
4224
+ function findBlockChild(block, path) {
4225
+ const blockNode = block.node;
4226
+ if (!slate.Element.isElement(blockNode) || path[1] !== "children")
4227
+ return;
4212
4228
  let childIndex = -1;
4213
- const child = block.children.find((node, index) => {
4214
- 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];
4215
4231
  return isMatch && (childIndex = index), isMatch;
4216
4232
  });
4217
- return child ? {
4218
- block,
4219
- child,
4220
- blockPath,
4221
- childPath: blockPath?.concat(childIndex)
4222
- } : {
4223
- block,
4224
- blockPath,
4225
- child: void 0,
4226
- childPath: void 0
4227
- };
4233
+ if (child)
4234
+ return {
4235
+ node: child,
4236
+ index: childIndex
4237
+ };
4228
4238
  }
4229
4239
  function insertTextPatch(schema2, children, operation, beforeValue) {
4230
4240
  const block = util_sliceBlocks.isTextBlock({
@@ -5885,6 +5895,57 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5885
5895
  type: "decorator.add"
5886
5896
  })]]
5887
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({
5888
5949
  on: "delete.text",
5889
5950
  guard: ({
5890
5951
  snapshot,
@@ -6299,7 +6360,12 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6299
6360
  actions: [(_, {
6300
6361
  newTextBlock,
6301
6362
  selection
6302
- }) => [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({
6303
6369
  type: "delete",
6304
6370
  at: selection
6305
6371
  }), behaviors_index.raise({
@@ -6711,7 +6777,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6711
6777
  function isSyntheticBehaviorEvent(event) {
6712
6778
  return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
6713
6779
  }
6714
- 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"];
6715
6781
  function isAbstractBehaviorEvent(event) {
6716
6782
  return abstractBehaviorEventTypes.includes(event.type);
6717
6783
  }
@@ -8864,20 +8930,22 @@ async function updateValue({
8864
8930
  const hadSelection = !!slateEditor.selection;
8865
8931
  if ((!value || value.length === 0) && (debug$5("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
8866
8932
  withoutSaving(slateEditor, () => {
8867
- withoutPatching(slateEditor, () => {
8868
- if (doneSyncing)
8869
- return;
8870
- hadSelection && slate.Transforms.deselect(slateEditor);
8871
- const childrenLength = slateEditor.children.length;
8872
- slateEditor.children.forEach((_, index) => {
8873
- slate.Transforms.removeNodes(slateEditor, {
8874
- at: [childrenLength - 1 - index]
8875
- });
8876
- }), slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
8877
- decorators: []
8878
- }), {
8879
- at: [0]
8880
- }), hadSelection && slate.Transforms.select(slateEditor, [0, 0]);
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
+ });
8881
8949
  });
8882
8950
  });
8883
8951
  }), isChanged = !0), value && value.length > 0) {