@portabletext/editor 1.18.7 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +52 -35
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-es/behavior.core.js +52 -35
  4. package/lib/_chunks-es/behavior.core.js.map +1 -1
  5. package/lib/behaviors/index.cjs +1 -0
  6. package/lib/behaviors/index.cjs.map +1 -1
  7. package/lib/behaviors/index.d.cts +76 -84
  8. package/lib/behaviors/index.d.ts +76 -84
  9. package/lib/behaviors/index.js +3 -2
  10. package/lib/index.cjs +234 -251
  11. package/lib/index.cjs.map +1 -1
  12. package/lib/index.d.cts +241 -1098
  13. package/lib/index.d.ts +241 -1098
  14. package/lib/index.js +235 -252
  15. package/lib/index.js.map +1 -1
  16. package/lib/selectors/index.cjs +12 -9
  17. package/lib/selectors/index.cjs.map +1 -1
  18. package/lib/selectors/index.js +12 -9
  19. package/lib/selectors/index.js.map +1 -1
  20. package/package.json +2 -2
  21. package/src/behavior-actions/behavior.actions.ts +28 -36
  22. package/src/behaviors/behavior.core.decorators.ts +36 -42
  23. package/src/behaviors/behavior.core.ts +4 -3
  24. package/src/behaviors/behavior.types.ts +38 -24
  25. package/src/behaviors/index.ts +1 -0
  26. package/src/editor/PortableTextEditor.tsx +14 -16
  27. package/src/editor/__tests__/self-solving.test.tsx +4 -11
  28. package/src/editor/create-editor.ts +1 -3
  29. package/src/editor/editor-machine.ts +37 -41
  30. package/src/editor/plugins/create-with-event-listeners.ts +44 -57
  31. package/src/editor/plugins/createWithHotKeys.ts +1 -11
  32. package/src/editor/plugins/createWithPortableTextMarkModel.ts +12 -1
  33. package/src/editor/plugins/createWithPortableTextSelections.ts +1 -5
  34. package/src/editor/with-applying-behavior-actions.ts +15 -0
  35. package/src/selectors/selector.get-selected-spans.test.ts +122 -0
  36. package/src/selectors/selector.get-selected-spans.ts +3 -1
  37. package/src/selectors/selector.is-active-decorator.test.ts +65 -0
package/lib/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$l = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isSelectionCollapsed = require("./_chunks-cjs/selector.is-selection-collapsed.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), blockTools = require("@sanity/block-tools");
3
+ var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$k = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isSelectionCollapsed = require("./_chunks-cjs/selector.is-selection-collapsed.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), blockTools = require("@sanity/block-tools");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
7
- var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$l), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
7
+ var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$k), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
8
8
  function createEditorSchema(portableTextType) {
9
9
  if (!portableTextType)
10
10
  throw new Error("Parameter 'portabletextType' missing (required)");
@@ -194,7 +194,7 @@ function toSlateRange(selection, editor) {
194
194
  path: toSlatePath(selection.focus.path, editor),
195
195
  offset: selection.focus.offset
196
196
  };
197
- return focus.path.length === 0 || anchor.path.length === 0 ? null : anchor && focus ? {
197
+ return focus.path.length === 0 || anchor.path.length === 0 ? null : focus ? {
198
198
  anchor,
199
199
  focus
200
200
  } : null;
@@ -522,7 +522,7 @@ function getCounterContentForListLevel(level) {
522
522
  return "counter(listItemNumberNextNextNext) '. '";
523
523
  }
524
524
  }
525
- const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
525
+ const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
526
526
  const $ = reactCompilerRuntime.c(51), {
527
527
  children,
528
528
  element,
@@ -560,39 +560,39 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
560
560
  $[16] !== editor || $[17] !== element ? (t9 = (event_0) => {
561
561
  const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor);
562
562
  if (targetBlock) {
563
- IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$k("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
563
+ IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$j("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
564
564
  const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor);
565
565
  IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
566
566
  let targetPath = slateReact.ReactEditor.findPath(editor, targetBlock);
567
567
  const myPath = slateReact.ReactEditor.findPath(editor, element), isBefore = slate.Path.isBefore(myPath, targetPath);
568
568
  if (dragPosition === "bottom" && !isBefore) {
569
569
  if (targetPath[0] >= editor.children.length - 1) {
570
- debug$k("target is already at the bottom, not moving");
570
+ debug$j("target is already at the bottom, not moving");
571
571
  return;
572
572
  }
573
573
  const originalPath = targetPath;
574
- targetPath = slate.Path.next(targetPath), debug$k(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
574
+ targetPath = slate.Path.next(targetPath), debug$j(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
575
575
  }
576
576
  if (dragPosition === "top" && isBefore && targetPath[0] !== editor.children.length - 1) {
577
577
  const originalPath_0 = targetPath;
578
- targetPath = slate.Path.previous(targetPath), debug$k(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
578
+ targetPath = slate.Path.previous(targetPath), debug$j(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
579
579
  }
580
580
  if (slate.Path.equals(targetPath, myPath)) {
581
- event_0.preventDefault(), debug$k("targetPath and myPath is the same, not moving");
581
+ event_0.preventDefault(), debug$j("targetPath and myPath is the same, not moving");
582
582
  return;
583
583
  }
584
- debug$k(`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), slate.Transforms.moveNodes(editor, {
584
+ debug$j(`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), slate.Transforms.moveNodes(editor, {
585
585
  at: myPath,
586
586
  to: targetPath
587
587
  }), editor.onChange();
588
588
  return;
589
589
  }
590
- debug$k("No target element, not doing anything");
590
+ debug$j("No target element, not doing anything");
591
591
  }, $[16] = editor, $[17] = element, $[18] = t9) : t9 = $[18];
592
592
  const handleDragEnd = t9;
593
593
  let t10;
594
594
  $[19] !== editor || $[20] !== element ? (t10 = (event_1) => {
595
- IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$k("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
595
+ IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$j("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
596
596
  }, $[19] = editor, $[20] = element, $[21] = t10) : t10 = $[21];
597
597
  const handleDrop = t10;
598
598
  let t11;
@@ -609,10 +609,10 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
609
609
  let t12;
610
610
  $[26] !== blockElement || $[27] !== editor || $[28] !== handleDrag || $[29] !== isInline || $[30] !== isVoid ? (t12 = (event_3) => {
611
611
  if (!isVoid || isInline) {
612
- debug$k("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
612
+ debug$j("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
613
613
  return;
614
614
  }
615
- if (debug$k("Drag start"), IS_DRAGGING.set(editor, !0), event_3.dataTransfer && (event_3.dataTransfer.setData("application/portable-text", "something"), event_3.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
615
+ if (debug$j("Drag start"), IS_DRAGGING.set(editor, !0), event_3.dataTransfer && (event_3.dataTransfer.setData("application/portable-text", "something"), event_3.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
616
616
  let dragGhost = blockElement.cloneNode(!0);
617
617
  const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
618
618
  if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
@@ -1887,7 +1887,7 @@ function isRedoing(editor) {
1887
1887
  function setIsRedoing(editor, isRedoing2) {
1888
1888
  IS_REDOING.set(editor, isRedoing2);
1889
1889
  }
1890
- const debug$j = debugWithName("plugin:withUndoRedo"), debugVerbose$3 = debug$j.enabled && !1, SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1890
+ const debug$i = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1891
1891
  const state = SAVING.get(editor);
1892
1892
  return state === void 0 ? !0 : state;
1893
1893
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
@@ -1900,7 +1900,7 @@ function createWithUndoRedo(options) {
1900
1900
  let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
1901
1901
  const remotePatches = getRemotePatches(editor);
1902
1902
  options.subscriptions.push(() => {
1903
- debug$j("Subscribing to patches");
1903
+ debug$i("Subscribing to patches");
1904
1904
  const sub = editorActor.on("patches", ({
1905
1905
  patches: patches2,
1906
1906
  snapshot
@@ -1909,7 +1909,7 @@ function createWithUndoRedo(options) {
1909
1909
  patches2.forEach((patch) => {
1910
1910
  if (!reset && patch.origin !== "local" && remotePatches) {
1911
1911
  if (patch.type === "unset" && patch.path.length === 0) {
1912
- debug$j("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1912
+ debug$i("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1913
1913
  undos: [],
1914
1914
  redos: []
1915
1915
  }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
@@ -1925,7 +1925,7 @@ function createWithUndoRedo(options) {
1925
1925
  }), previousSnapshot = snapshot;
1926
1926
  });
1927
1927
  return () => {
1928
- debug$j("Unsubscribing to patches"), sub.unsubscribe();
1928
+ debug$i("Unsubscribing to patches"), sub.unsubscribe();
1929
1929
  };
1930
1930
  }), editor.history = {
1931
1931
  undos: [],
@@ -1964,7 +1964,7 @@ function createWithUndoRedo(options) {
1964
1964
  operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
1965
1965
  timestamp: /* @__PURE__ */ new Date()
1966
1966
  };
1967
- undos.push(newStep), debug$j("Created new undo step", step);
1967
+ undos.push(newStep), debug$i("Created new undo step", step);
1968
1968
  }
1969
1969
  for (; undos.length > UNDO_STEP_LIMIT; )
1970
1970
  undos.shift();
@@ -1981,7 +1981,7 @@ function createWithUndoRedo(options) {
1981
1981
  } = editor.history;
1982
1982
  if (undos.length > 0) {
1983
1983
  const step = undos[undos.length - 1];
1984
- if (debug$j("Undoing", step), step.operations.length > 0) {
1984
+ if (debug$i("Undoing", step), step.operations.length > 0) {
1985
1985
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
1986
1986
  let transformedOperations = step.operations;
1987
1987
  otherPatches.forEach((item) => {
@@ -1999,7 +1999,7 @@ function createWithUndoRedo(options) {
1999
1999
  });
2000
2000
  }), editor.normalize(), editor.onChange();
2001
2001
  } catch (err) {
2002
- debug$j("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2002
+ debug$i("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2003
2003
  undos: [],
2004
2004
  redos: []
2005
2005
  }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
@@ -2018,7 +2018,7 @@ function createWithUndoRedo(options) {
2018
2018
  } = editor.history;
2019
2019
  if (redos.length > 0) {
2020
2020
  const step = redos[redos.length - 1];
2021
- if (debug$j("Redoing", step), step.operations.length > 0) {
2021
+ if (debug$i("Redoing", step), step.operations.length > 0) {
2022
2022
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
2023
2023
  let transformedOperations = step.operations;
2024
2024
  otherPatches.forEach((item) => {
@@ -2035,7 +2035,7 @@ function createWithUndoRedo(options) {
2035
2035
  });
2036
2036
  }), editor.normalize(), editor.onChange();
2037
2037
  } catch (err) {
2038
- debug$j("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2038
+ debug$i("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2039
2039
  undos: [],
2040
2040
  redos: []
2041
2041
  }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
@@ -2048,7 +2048,6 @@ function createWithUndoRedo(options) {
2048
2048
  };
2049
2049
  }
2050
2050
  function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
2051
- debugVerbose$3 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
2052
2051
  const transformedOperation = {
2053
2052
  ...operation
2054
2053
  };
@@ -2056,16 +2055,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
2056
2055
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
2057
2056
  _key: blk._key
2058
2057
  }, patch.path[0]));
2059
- return debug$j(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
2058
+ return debug$i(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
2060
2059
  }
2061
2060
  if (patch.type === "unset" && patch.path.length === 1) {
2062
2061
  const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
2063
2062
  _key: blk._key
2064
2063
  }, patch.path[0]));
2065
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$j("Skipping transformation that targeted removed block"), []) : (debugVerbose$3 && (debug$j(`Selection ${JSON.stringify(editor.selection)}`), debug$j(`Adjusting block path (-1) for '${transformedOperation.type}' operation and patch '${patch.type}'`)), [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)]);
2064
+ return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$i("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
2066
2065
  }
2067
2066
  if (patch.type === "unset" && patch.path.length === 0)
2068
- return debug$j(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
2067
+ return debug$i(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
2069
2068
  if (patch.type === "diffMatchPatch") {
2070
2069
  const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
2071
2070
  return !operationTargetBlock || !isEqual__default.default({
@@ -2345,7 +2344,7 @@ const syncValueCallback = ({
2345
2344
  }
2346
2345
  }
2347
2346
  }
2348
- }), debug$i = debugWithName("hook:useSyncValue");
2347
+ }), debug$h = debugWithName("hook:useSyncValue");
2349
2348
  async function updateValue({
2350
2349
  context,
2351
2350
  sendBack,
@@ -2355,7 +2354,7 @@ async function updateValue({
2355
2354
  }) {
2356
2355
  let isChanged = !1, isValid = !0;
2357
2356
  const hadSelection = !!slateEditor.selection;
2358
- if ((!value || value.length === 0) && (debug$i("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
2357
+ if ((!value || value.length === 0) && (debug$h("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
2359
2358
  withoutSaving(slateEditor, () => {
2360
2359
  withoutPatching(slateEditor, () => {
2361
2360
  hadSelection && slate.Transforms.deselect(slateEditor);
@@ -2411,14 +2410,14 @@ async function updateValue({
2411
2410
  });
2412
2411
  }
2413
2412
  if (!isValid) {
2414
- debug$i("Invalid value, returning"), sendBack({
2413
+ debug$h("Invalid value, returning"), sendBack({
2415
2414
  type: "done syncing",
2416
2415
  value
2417
2416
  });
2418
2417
  return;
2419
2418
  }
2420
2419
  if (isChanged) {
2421
- debug$i("Server value changed, syncing editor");
2420
+ debug$h("Server value changed, syncing editor");
2422
2421
  try {
2423
2422
  slateEditor.onChange();
2424
2423
  } catch (err) {
@@ -2446,7 +2445,7 @@ async function updateValue({
2446
2445
  value
2447
2446
  });
2448
2447
  } else
2449
- debug$i("Server value and editor value is equal, no need to sync.");
2448
+ debug$h("Server value and editor value is equal, no need to sync.");
2450
2449
  sendBack({
2451
2450
  type: "done syncing",
2452
2451
  value
@@ -2480,7 +2479,7 @@ function syncBlock({
2480
2479
  type: "patch",
2481
2480
  patch
2482
2481
  });
2483
- })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
2482
+ })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$h.enabled && debug$h("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$h.enabled && debug$h("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
2484
2483
  type: "invalid value",
2485
2484
  resolution: validation.resolution,
2486
2485
  value
@@ -2488,9 +2487,9 @@ function syncBlock({
2488
2487
  }
2489
2488
  if (!oldBlock && blockValid) {
2490
2489
  const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
2491
- debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
2490
+ debug$h.enabled && debug$h("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
2492
2491
  at: [currentBlockIndex]
2493
- }) : (debug$i("Invalid", validation), sendBack({
2492
+ }) : (debug$h("Invalid", validation), sendBack({
2494
2493
  type: "invalid value",
2495
2494
  resolution: validation.resolution,
2496
2495
  value
@@ -2518,14 +2517,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2518
2517
  const oldBlockChildrenLength = oldBlock.children.length;
2519
2518
  currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
2520
2519
  const childIndex = oldBlockChildrenLength - 1 - index;
2521
- childIndex > 0 && (debug$i("Removing child"), slate.Transforms.removeNodes(slateEditor, {
2520
+ childIndex > 0 && (debug$h("Removing child"), slate.Transforms.removeNodes(slateEditor, {
2522
2521
  at: [currentBlockIndex, childIndex]
2523
2522
  }));
2524
2523
  }), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
2525
2524
  const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
2526
2525
  if (isChildChanged)
2527
2526
  if (currentBlockChild._key === oldBlockChild?._key) {
2528
- debug$i("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
2527
+ debug$h("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
2529
2528
  at: path
2530
2529
  });
2531
2530
  const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
@@ -2542,23 +2541,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2542
2541
  }
2543
2542
  }), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
2544
2543
  at: path
2545
- }), slateEditor.onChange()) : isSpanNode || (debug$i("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
2544
+ }), slateEditor.onChange()) : isSpanNode || (debug$h("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
2546
2545
  _key: VOID_CHILD_KEY
2547
2546
  }, {
2548
2547
  at: [...path, 0],
2549
2548
  voids: !0
2550
2549
  }));
2551
- } else oldBlockChild ? (debug$i("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
2550
+ } else oldBlockChild ? (debug$h("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
2552
2551
  at: [currentBlockIndex, currentBlockChildIndex]
2553
2552
  }), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2554
2553
  at: [currentBlockIndex, currentBlockChildIndex]
2555
- }), slateEditor.onChange()) : oldBlockChild || (debug$i("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2554
+ }), slateEditor.onChange()) : oldBlockChild || (debug$h("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2556
2555
  at: [currentBlockIndex, currentBlockChildIndex]
2557
2556
  }), slateEditor.onChange());
2558
2557
  });
2559
2558
  }
2560
2559
  }
2561
- const debug$h = debugWithName("component:PortableTextEditor:Synchronizer");
2560
+ const debug$g = debugWithName("component:PortableTextEditor:Synchronizer");
2562
2561
  function Synchronizer(props) {
2563
2562
  const $ = reactCompilerRuntime.c(40), {
2564
2563
  editorActor,
@@ -2629,19 +2628,19 @@ function Synchronizer(props) {
2629
2628
  }, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), React.useEffect(t11, t12);
2630
2629
  let t13, t14;
2631
2630
  $[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
2632
- debug$h("Value from props changed, syncing new value"), syncActorRef.send({
2631
+ debug$g("Value from props changed, syncing new value"), syncActorRef.send({
2633
2632
  type: "update value",
2634
2633
  value
2635
2634
  });
2636
2635
  }, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), React.useEffect(t13, t14);
2637
2636
  let t15;
2638
2637
  $[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
2639
- debug$h("Subscribing to patch events");
2638
+ debug$g("Subscribing to patch events");
2640
2639
  const sub = editorActor.on("patch", (event_1) => {
2641
2640
  mutationActorRef.send(event_1);
2642
2641
  });
2643
2642
  return () => {
2644
- debug$h("Unsubscribing to patch events"), sub.unsubscribe();
2643
+ debug$g("Unsubscribing to patch events"), sub.unsubscribe();
2645
2644
  };
2646
2645
  }, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
2647
2646
  let t16;
@@ -2656,11 +2655,11 @@ function _temp(s) {
2656
2655
  return s.context.value;
2657
2656
  }
2658
2657
  Synchronizer.displayName = "Synchronizer";
2659
- const debug$g = debugWithName("operationToPatches");
2658
+ const debug$f = debugWithName("operationToPatches");
2660
2659
  function createOperationToPatches(types2) {
2661
2660
  const textBlockName = types2.block.name;
2662
2661
  function insertTextPatch(editor, operation, beforeValue) {
2663
- debug$g.enabled && debug$g("Operation", JSON.stringify(operation, null, 2));
2662
+ debug$f.enabled && debug$f("Operation", JSON.stringify(operation, null, 2));
2664
2663
  const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
2665
2664
  if (!block)
2666
2665
  throw new Error("Could not find block");
@@ -2753,7 +2752,7 @@ function createOperationToPatches(types2) {
2753
2752
  _key: block.children[operation.path[1] - 1]._key
2754
2753
  }])];
2755
2754
  }
2756
- return debug$g("Something was inserted into a void block. Not producing editor patches."), [];
2755
+ return debug$f("Something was inserted into a void block. Not producing editor patches."), [];
2757
2756
  }
2758
2757
  function splitNodePatch(editor, operation, beforeValue) {
2759
2758
  const patches$1 = [], splitBlock = editor.children[operation.path[0]];
@@ -2811,9 +2810,9 @@ function createOperationToPatches(types2) {
2811
2810
  _key: block._key
2812
2811
  }, "children", {
2813
2812
  _key: spanToRemove._key
2814
- }])] : (debug$g("Span not found in editor trying to remove node"), []);
2813
+ }])] : (debug$f("Span not found in editor trying to remove node"), []);
2815
2814
  } else
2816
- return debug$g("Not creating patch inside object block"), [];
2815
+ return debug$f("Not creating patch inside object block"), [];
2817
2816
  }
2818
2817
  function mergeNodePatch(editor, operation, beforeValue) {
2819
2818
  const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
@@ -2839,7 +2838,7 @@ function createOperationToPatches(types2) {
2839
2838
  _key: removedSpan._key
2840
2839
  }])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
2841
2840
  } else
2842
- debug$g("Void nodes can't be merged, not creating any patches");
2841
+ debug$f("Void nodes can't be merged, not creating any patches");
2843
2842
  return patches$1;
2844
2843
  }
2845
2844
  function moveNodePatch(editor, operation, beforeValue) {
@@ -2878,9 +2877,19 @@ function createOperationToPatches(types2) {
2878
2877
  splitNodePatch
2879
2878
  };
2880
2879
  }
2880
+ const IS_APPLYING_BEHAVIOR_ACTIONS = /* @__PURE__ */ new WeakMap();
2881
+ function withApplyingBehaviorActions(editor, fn) {
2882
+ const prev = isApplyingBehaviorActions(editor);
2883
+ IS_APPLYING_BEHAVIOR_ACTIONS.set(editor, !0), fn(), IS_APPLYING_BEHAVIOR_ACTIONS.set(editor, prev);
2884
+ }
2885
+ function isApplyingBehaviorActions(editor) {
2886
+ return IS_APPLYING_BEHAVIOR_ACTIONS.get(editor) ?? !1;
2887
+ }
2881
2888
  function createWithEventListeners(editorActor, subscriptions) {
2882
2889
  return function(editor) {
2883
- return editorActor.getSnapshot().context.maxBlocks !== void 0 || (subscriptions.push(() => {
2890
+ if (editorActor.getSnapshot().context.maxBlocks !== void 0)
2891
+ return editor;
2892
+ subscriptions.push(() => {
2884
2893
  const subscription = editorActor.on("*", (event) => {
2885
2894
  switch (event.type) {
2886
2895
  case "annotation.add": {
@@ -2905,17 +2914,6 @@ function createWithEventListeners(editorActor, subscriptions) {
2905
2914
  });
2906
2915
  break;
2907
2916
  }
2908
- case "annotation.toggle": {
2909
- editorActor.send({
2910
- type: "behavior event",
2911
- behaviorEvent: {
2912
- type: "annotation.toggle",
2913
- annotation: event.annotation
2914
- },
2915
- editor
2916
- });
2917
- break;
2918
- }
2919
2917
  case "blur": {
2920
2918
  editorActor.send({
2921
2919
  type: "behavior event",
@@ -2926,28 +2924,6 @@ function createWithEventListeners(editorActor, subscriptions) {
2926
2924
  });
2927
2925
  break;
2928
2926
  }
2929
- case "decorator.add": {
2930
- editorActor.send({
2931
- type: "behavior event",
2932
- behaviorEvent: {
2933
- type: "decorator.add",
2934
- decorator: event.decorator
2935
- },
2936
- editor
2937
- });
2938
- break;
2939
- }
2940
- case "decorator.remove": {
2941
- editorActor.send({
2942
- type: "behavior event",
2943
- behaviorEvent: {
2944
- type: "decorator.remove",
2945
- decorator: event.decorator
2946
- },
2947
- editor
2948
- });
2949
- break;
2950
- }
2951
2927
  case "decorator.toggle": {
2952
2928
  editorActor.send({
2953
2929
  type: "behavior event",
@@ -3003,6 +2979,17 @@ function createWithEventListeners(editorActor, subscriptions) {
3003
2979
  });
3004
2980
  break;
3005
2981
  }
2982
+ case "select": {
2983
+ editorActor.send({
2984
+ type: "behavior event",
2985
+ behaviorEvent: {
2986
+ type: "select",
2987
+ selection: event.selection
2988
+ },
2989
+ editor
2990
+ });
2991
+ break;
2992
+ }
3006
2993
  case "style.toggle": {
3007
2994
  editorActor.send({
3008
2995
  type: "behavior event",
@@ -3019,25 +3006,11 @@ function createWithEventListeners(editorActor, subscriptions) {
3019
3006
  return () => {
3020
3007
  subscription.unsubscribe();
3021
3008
  };
3022
- }), editor.addMark = (mark) => {
3023
- editorActor.send({
3024
- type: "behavior event",
3025
- behaviorEvent: {
3026
- type: "decorator.add",
3027
- decorator: mark
3028
- },
3029
- editor
3030
- });
3031
- }, editor.removeMark = (mark) => {
3032
- editorActor.send({
3033
- type: "behavior event",
3034
- behaviorEvent: {
3035
- type: "decorator.remove",
3036
- decorator: mark
3037
- },
3038
- editor
3039
- });
3040
- }, editor.deleteBackward = (unit) => {
3009
+ });
3010
+ const {
3011
+ select
3012
+ } = editor;
3013
+ return editor.deleteBackward = (unit) => {
3041
3014
  editorActor.send({
3042
3015
  type: "behavior event",
3043
3016
  behaviorEvent: {
@@ -3081,7 +3054,21 @@ function createWithEventListeners(editorActor, subscriptions) {
3081
3054
  },
3082
3055
  editor
3083
3056
  });
3084
- }), editor;
3057
+ }, editor.select = (location) => {
3058
+ if (isApplyingBehaviorActions(editor)) {
3059
+ select(location);
3060
+ return;
3061
+ }
3062
+ const range = slate.Editor.range(editor, location);
3063
+ editorActor.send({
3064
+ type: "behavior event",
3065
+ behaviorEvent: {
3066
+ type: "select",
3067
+ selection: toPortableTextRange(fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), range, editorActor.getSnapshot().context.schema)
3068
+ },
3069
+ editor
3070
+ });
3071
+ }, editor;
3085
3072
  };
3086
3073
  }
3087
3074
  function createWithMaxBlocks(editorActor) {
@@ -3178,13 +3165,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
3178
3165
  }, editor;
3179
3166
  };
3180
3167
  }
3181
- const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
3168
+ const debug$e = debugWithName("applyPatches"), debugVerbose = debug$e.enabled && !0;
3182
3169
  function createApplyPatch(schemaTypes) {
3183
3170
  return (editor, patch) => {
3184
3171
  let changed = !1;
3185
- debugVerbose$2 && (debug$f(`
3172
+ debugVerbose && (debug$e(`
3186
3173
 
3187
- NEW PATCH =============================================================`), debug$f(JSON.stringify(patch, null, 2)));
3174
+ NEW PATCH =============================================================`), debug$e(JSON.stringify(patch, null, 2)));
3188
3175
  try {
3189
3176
  switch (patch.type) {
3190
3177
  case "insert":
@@ -3200,7 +3187,7 @@ NEW PATCH =============================================================`), debug
3200
3187
  changed = diffMatchPatch(editor, patch);
3201
3188
  break;
3202
3189
  default:
3203
- debug$f("Unhandled patch", patch.type);
3190
+ debug$e("Unhandled patch", patch.type);
3204
3191
  }
3205
3192
  } catch (err) {
3206
3193
  console.error(err);
@@ -3215,9 +3202,9 @@ function diffMatchPatch(editor, patch) {
3215
3202
  childPath
3216
3203
  } = findBlockAndChildFromPath(editor, patch.path);
3217
3204
  if (!block)
3218
- return debug$f("Block not found"), !1;
3205
+ return debug$e("Block not found"), !1;
3219
3206
  if (!child || !childPath)
3220
- return debug$f("Child not found"), !1;
3207
+ return debug$e("Child not found"), !1;
3221
3208
  if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
3222
3209
  return !1;
3223
3210
  const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
@@ -3247,9 +3234,9 @@ function insertPatch(editor, patch, schemaTypes) {
3247
3234
  childPath: targetChildPath
3248
3235
  } = findBlockAndChildFromPath(editor, patch.path);
3249
3236
  if (!targetBlock || !targetBlockPath)
3250
- return debug$f("Block not found"), !1;
3237
+ return debug$e("Block not found"), !1;
3251
3238
  if (patch.path.length > 1 && patch.path[1] !== "children")
3252
- return debug$f("Ignoring patch targeting void value"), !1;
3239
+ return debug$e("Ignoring patch targeting void value"), !1;
3253
3240
  if (patch.path.length === 1) {
3254
3241
  const {
3255
3242
  items: items2,
@@ -3257,7 +3244,7 @@ function insertPatch(editor, patch, schemaTypes) {
3257
3244
  } = patch, blocksToInsert = toSlateValue(items2, {
3258
3245
  schemaTypes
3259
3246
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
3260
- return debug$f(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
3247
+ return debug$e(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
3261
3248
  at: [normalizedIdx2]
3262
3249
  }), debugState(editor, "after"), !0;
3263
3250
  }
@@ -3266,14 +3253,14 @@ function insertPatch(editor, patch, schemaTypes) {
3266
3253
  position
3267
3254
  } = patch;
3268
3255
  if (!targetChild || !targetChildPath)
3269
- return debug$f("Child not found"), !1;
3256
+ return debug$e("Child not found"), !1;
3270
3257
  const childrenToInsert = targetBlock && toSlateValue([{
3271
3258
  ...targetBlock,
3272
3259
  children: items
3273
3260
  }], {
3274
3261
  schemaTypes
3275
3262
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
3276
- return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
3263
+ return debug$e(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
3277
3264
  at: childInsertPath
3278
3265
  }), debugState(editor, "after"), !0;
3279
3266
  }
@@ -3287,14 +3274,14 @@ function setPatch(editor, patch) {
3287
3274
  childPath
3288
3275
  } = findBlockAndChildFromPath(editor, patch.path);
3289
3276
  if (!block)
3290
- return debug$f("Block not found"), !1;
3277
+ return debug$e("Block not found"), !1;
3291
3278
  const isTextBlock = editor.isTextBlock(block);
3292
3279
  if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
3293
- return debug$f("Ignoring setting void value"), !1;
3280
+ return debug$e("Ignoring setting void value"), !1;
3294
3281
  if (debugState(editor, "before"), isTextBlock && child && childPath) {
3295
3282
  if (slate.Text.isText(value) && slate.Text.isText(child)) {
3296
3283
  const newText = child.text;
3297
- value.text !== newText && (debug$f("Setting text property"), editor.apply({
3284
+ value.text !== newText && (debug$e("Setting text property"), editor.apply({
3298
3285
  type: "remove_text",
3299
3286
  path: childPath,
3300
3287
  offset: 0,
@@ -3306,7 +3293,7 @@ function setPatch(editor, patch) {
3306
3293
  text: value.text
3307
3294
  }), editor.onChange());
3308
3295
  } else
3309
- debug$f("Setting non-text property"), editor.apply({
3296
+ debug$e("Setting non-text property"), editor.apply({
3310
3297
  type: "set_node",
3311
3298
  path: childPath,
3312
3299
  properties: {},
@@ -3314,7 +3301,7 @@ function setPatch(editor, patch) {
3314
3301
  });
3315
3302
  return !0;
3316
3303
  } else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
3317
- debug$f("Setting block property");
3304
+ debug$e("Setting block property");
3318
3305
  const {
3319
3306
  children,
3320
3307
  ...nextRest
@@ -3331,7 +3318,7 @@ function setPatch(editor, patch) {
3331
3318
  ...prevRest
3332
3319
  },
3333
3320
  newProperties: nextRest
3334
- }), debug$f("Setting children"), block.children.forEach((c, cIndex) => {
3321
+ }), debug$e("Setting children"), block.children.forEach((c, cIndex) => {
3335
3322
  editor.apply({
3336
3323
  type: "remove_node",
3337
3324
  path: blockPath.concat(block.children.length - 1 - cIndex),
@@ -3357,7 +3344,7 @@ function setPatch(editor, patch) {
3357
3344
  }
3358
3345
  function unsetPatch(editor, patch) {
3359
3346
  if (patch.path.length === 0) {
3360
- debug$f("Removing everything"), debugState(editor, "before");
3347
+ debug$e("Removing everything"), debugState(editor, "before");
3361
3348
  const previousSelection = editor.selection;
3362
3349
  return slate.Transforms.deselect(editor), editor.children.forEach((_child, i) => {
3363
3350
  slate.Transforms.removeNodes(editor, {
@@ -3384,13 +3371,13 @@ function unsetPatch(editor, patch) {
3384
3371
  } = findBlockAndChildFromPath(editor, patch.path);
3385
3372
  if (patch.path.length === 1) {
3386
3373
  if (!block || !blockPath)
3387
- return debug$f("Block not found"), !1;
3374
+ return debug$e("Block not found"), !1;
3388
3375
  const blockIndex = blockPath[0];
3389
- return debug$f(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
3376
+ return debug$e(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
3390
3377
  at: [blockIndex]
3391
3378
  }), debugState(editor, "after"), !0;
3392
3379
  }
3393
- 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$2 && debug$f(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
3380
+ return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$e("Child not found"), !1) : (debug$e(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$e(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
3394
3381
  at: childPath
3395
3382
  }), debugState(editor, "after"), !0) : !1;
3396
3383
  }
@@ -3398,7 +3385,7 @@ function isKeyedSegment(segment) {
3398
3385
  return typeof segment == "object" && "_key" in segment;
3399
3386
  }
3400
3387
  function debugState(editor, stateName) {
3401
- debugVerbose$2 && (debug$f(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$f(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
3388
+ debugVerbose && (debug$e(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$e(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
3402
3389
  }
3403
3390
  function findBlockFromPath(editor, path) {
3404
3391
  let blockIndex = -1;
@@ -3440,7 +3427,7 @@ function findBlockAndChildFromPath(editor, path) {
3440
3427
  childPath: void 0
3441
3428
  };
3442
3429
  }
3443
- const debug$e = debugWithName("plugin:withPatches");
3430
+ const debug$d = debugWithName("plugin:withPatches");
3444
3431
  function createWithPatches({
3445
3432
  editorActor,
3446
3433
  patchFunctions,
@@ -3466,7 +3453,7 @@ function createWithPatches({
3466
3453
  withoutPatching(editor, () => {
3467
3454
  withoutSaving(editor, () => {
3468
3455
  patches2.forEach((patch) => {
3469
- debug$e.enabled && debug$e(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
3456
+ debug$d.enabled && debug$d(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
3470
3457
  });
3471
3458
  });
3472
3459
  });
@@ -3479,10 +3466,10 @@ function createWithPatches({
3479
3466
  remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
3480
3467
  };
3481
3468
  return subscriptions.push(() => {
3482
- debug$e("Subscribing to remote patches");
3469
+ debug$d("Subscribing to remote patches");
3483
3470
  const sub = editorActor.on("patches", handlePatches);
3484
3471
  return () => {
3485
- debug$e("Unsubscribing to remote patches"), sub.unsubscribe();
3472
+ debug$d("Unsubscribing to remote patches"), sub.unsubscribe();
3486
3473
  };
3487
3474
  }), editor.apply = (operation) => {
3488
3475
  let patches$1 = [];
@@ -3533,7 +3520,7 @@ function createWithPatches({
3533
3520
  }, editor;
3534
3521
  };
3535
3522
  }
3536
- const debug$d = debugWithName("plugin:withPlaceholderBlock");
3523
+ const debug$c = debugWithName("plugin:withPlaceholderBlock");
3537
3524
  function createWithPlaceholderBlock(editorActor) {
3538
3525
  return function(editor) {
3539
3526
  const {
@@ -3558,7 +3545,7 @@ function createWithPlaceholderBlock(editorActor) {
3558
3545
  const node = op.node;
3559
3546
  if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
3560
3547
  const nextPath = slate.Path.next(op.path);
3561
- editor.children[nextPath[0]] || (debug$d("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
3548
+ editor.children[nextPath[0]] || (debug$c("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
3562
3549
  decorators: []
3563
3550
  })));
3564
3551
  }
@@ -3567,7 +3554,7 @@ function createWithPlaceholderBlock(editorActor) {
3567
3554
  }, editor;
3568
3555
  };
3569
3556
  }
3570
- const debug$c = debugWithName("plugin:withPortableTextBlockStyle");
3557
+ const debug$b = debugWithName("plugin:withPortableTextBlockStyle");
3571
3558
  function createWithPortableTextBlockStyle(editorActor, types2) {
3572
3559
  const defaultStyle = types2.styles[0].value;
3573
3560
  return function(editor) {
@@ -3580,7 +3567,7 @@ function createWithPortableTextBlockStyle(editorActor, types2) {
3580
3567
  if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !slate.Path.equals(path, op.path)) {
3581
3568
  const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
3582
3569
  if (slate.Text.isText(child) && child.text === "") {
3583
- debug$c(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
3570
+ debug$b(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
3584
3571
  type: "normalizing"
3585
3572
  }), slate.Transforms.setNodes(editor, {
3586
3573
  style: defaultStyle
@@ -3640,7 +3627,7 @@ function getNextSpan({
3640
3627
  }
3641
3628
  return nextSpan;
3642
3629
  }
3643
- const debug$b = debugWithName("plugin:withPortableTextMarkModel");
3630
+ const debug$a = debugWithName("plugin:withPortableTextMarkModel");
3644
3631
  function createWithPortableTextMarkModel(editorActor, types2) {
3645
3632
  return function(editor) {
3646
3633
  const {
@@ -3654,7 +3641,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3654
3641
  for (const [child, childPath] of children) {
3655
3642
  const nextNode = node.children[childPath[1] + 1];
3656
3643
  if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
3657
- debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3644
+ debug$a("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3658
3645
  type: "normalizing"
3659
3646
  }), slate.Transforms.mergeNodes(editor, {
3660
3647
  at: [childPath[0], childPath[1] + 1],
@@ -3667,7 +3654,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3667
3654
  }
3668
3655
  }
3669
3656
  if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
3670
- debug$b("Adding .markDefs to block node"), editorActor.send({
3657
+ debug$a("Adding .markDefs to block node"), editorActor.send({
3671
3658
  type: "normalizing"
3672
3659
  }), slate.Transforms.setNodes(editor, {
3673
3660
  markDefs: []
@@ -3679,7 +3666,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3679
3666
  return;
3680
3667
  }
3681
3668
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
3682
- debug$b("Adding .marks to span node"), editorActor.send({
3669
+ debug$a("Adding .marks to span node"), editorActor.send({
3683
3670
  type: "normalizing"
3684
3671
  }), slate.Transforms.setNodes(editor, {
3685
3672
  marks: []
@@ -3693,7 +3680,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3693
3680
  if (editor.isTextSpan(node)) {
3694
3681
  const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
3695
3682
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
3696
- debug$b("Removing annotations from empty span node"), editorActor.send({
3683
+ debug$a("Removing annotations from empty span node"), editorActor.send({
3697
3684
  type: "normalizing"
3698
3685
  }), slate.Transforms.setNodes(editor, {
3699
3686
  marks: node.marks?.filter((mark) => decorators2.includes(mark))
@@ -3711,7 +3698,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3711
3698
  if (editor.isTextSpan(child)) {
3712
3699
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
3713
3700
  if (orphanedAnnotations.length > 0) {
3714
- debug$b("Removing orphaned annotations from span node"), editorActor.send({
3701
+ debug$a("Removing orphaned annotations from span node"), editorActor.send({
3715
3702
  type: "normalizing"
3716
3703
  }), slate.Transforms.setNodes(editor, {
3717
3704
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3729,7 +3716,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3729
3716
  if (editor.isTextBlock(block)) {
3730
3717
  const decorators2 = types2.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
3731
3718
  if (orphanedAnnotations.length > 0) {
3732
- debug$b("Removing orphaned annotations from span node"), editorActor.send({
3719
+ debug$a("Removing orphaned annotations from span node"), editorActor.send({
3733
3720
  type: "normalizing"
3734
3721
  }), slate.Transforms.setNodes(editor, {
3735
3722
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3747,7 +3734,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3747
3734
  for (const markDef of markDefs)
3748
3735
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
3749
3736
  if (markDefs.length !== newMarkDefs.length) {
3750
- debug$b("Removing duplicate markDefs"), editorActor.send({
3737
+ debug$a("Removing duplicate markDefs"), editorActor.send({
3751
3738
  type: "normalizing"
3752
3739
  }), slate.Transforms.setNodes(editor, {
3753
3740
  markDefs: newMarkDefs
@@ -3762,7 +3749,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3762
3749
  if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
3763
3750
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
3764
3751
  if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
3765
- debug$b("Removing markDef not in use"), editorActor.send({
3752
+ debug$a("Removing markDef not in use"), editorActor.send({
3766
3753
  type: "normalizing"
3767
3754
  }), slate.Transforms.setNodes(editor, {
3768
3755
  markDefs: newMarkDefs
@@ -3979,7 +3966,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3979
3966
  const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
3980
3967
  if (editor.isTextBlock(targetBlock)) {
3981
3968
  const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
3982
- debug$b("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
3969
+ debug$a("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
3983
3970
  markDefs: newMarkDefs
3984
3971
  }, {
3985
3972
  at: targetPath,
@@ -4040,7 +4027,12 @@ const addDecoratorActionImplementation = ({
4040
4027
  editor.marks = marks;
4041
4028
  }
4042
4029
  }
4043
- editor.onChange();
4030
+ if (editor.selection) {
4031
+ const selection = editor.selection;
4032
+ editor.selection = {
4033
+ ...selection
4034
+ };
4035
+ }
4044
4036
  }
4045
4037
  }, removeDecoratorActionImplementation = ({
4046
4038
  action
@@ -4048,7 +4040,7 @@ const addDecoratorActionImplementation = ({
4048
4040
  const editor = action.editor, mark = action.decorator, {
4049
4041
  selection
4050
4042
  } = editor;
4051
- if (selection)
4043
+ if (selection) {
4052
4044
  if (slate.Range.isExpanded(selection))
4053
4045
  slate.Transforms.setNodes(editor, {}, {
4054
4046
  match: slate.Text.isText,
@@ -4091,6 +4083,13 @@ const addDecoratorActionImplementation = ({
4091
4083
  };
4092
4084
  }
4093
4085
  }
4086
+ if (editor.selection) {
4087
+ const selection2 = editor.selection;
4088
+ editor.selection = {
4089
+ ...selection2
4090
+ };
4091
+ }
4092
+ }
4094
4093
  };
4095
4094
  function isDecoratorActive({
4096
4095
  editor,
@@ -4131,7 +4130,8 @@ const toggleDecoratorActionImplementation = ({
4131
4130
  decorator: action.decorator
4132
4131
  }
4133
4132
  });
4134
- }, debug$a = debugWithName("plugin:withPortableTextSelections"), debugVerbose$1 = debug$a.enabled && !1;
4133
+ };
4134
+ debugWithName("plugin:withPortableTextSelections");
4135
4135
  function createWithPortableTextSelections(editorActor, types2) {
4136
4136
  let prevSelection = null;
4137
4137
  return function(editor) {
@@ -4147,7 +4147,7 @@ function createWithPortableTextSelections(editorActor, types2) {
4147
4147
  ptRange = toPortableTextRange(value, editor.selection, types2), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange);
4148
4148
  }
4149
4149
  }
4150
- debugVerbose$1 && debug$a(`Emitting selection ${JSON.stringify(ptRange || null)} (${JSON.stringify(editor.selection)})`), ptRange ? editorActor.send({
4150
+ ptRange ? editorActor.send({
4151
4151
  type: "selection",
4152
4152
  selection: ptRange
4153
4153
  }) : editorActor.send({
@@ -4160,10 +4160,9 @@ function createWithPortableTextSelections(editorActor, types2) {
4160
4160
  onChange
4161
4161
  } = editor;
4162
4162
  return editor.onChange = () => {
4163
- const hasChanges = editor.operations.length > 0;
4164
- onChange(), hasChanges && !editorActor.getSnapshot().matches({
4163
+ onChange(), editorActor.getSnapshot().matches({
4165
4164
  setup: "setting up"
4166
- }) && emitPortableTextSelection();
4165
+ }) || emitPortableTextSelection();
4167
4166
  }, editor;
4168
4167
  };
4169
4168
  }
@@ -5398,16 +5397,6 @@ const insertBlockObjectActionImplementation = ({
5398
5397
  const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
5399
5398
  slate.Transforms.select(action.editor, nextBlockPath);
5400
5399
  },
5401
- reselect: ({
5402
- action
5403
- }) => {
5404
- const selection = action.editor.selection;
5405
- selection && (slate.Transforms.select(action.editor, {
5406
- ...selection
5407
- }), action.editor.selection = {
5408
- ...selection
5409
- });
5410
- },
5411
5400
  "style.toggle": toggleStyleActionImplementation,
5412
5401
  "style.add": addStyleActionImplementation,
5413
5402
  "style.remove": removeStyleActionImplementation,
@@ -5419,6 +5408,27 @@ function performAction({
5419
5408
  action
5420
5409
  }) {
5421
5410
  switch (action.type) {
5411
+ case "annotation.toggle": {
5412
+ behaviorActionImplementations["annotation.toggle"]({
5413
+ context,
5414
+ action
5415
+ });
5416
+ break;
5417
+ }
5418
+ case "decorator.add": {
5419
+ behaviorActionImplementations["decorator.add"]({
5420
+ context,
5421
+ action
5422
+ });
5423
+ break;
5424
+ }
5425
+ case "decorator.remove": {
5426
+ behaviorActionImplementations["decorator.remove"]({
5427
+ context,
5428
+ action
5429
+ });
5430
+ break;
5431
+ }
5422
5432
  case "delete.block": {
5423
5433
  behaviorActionImplementations["delete.block"]({
5424
5434
  context,
@@ -5512,13 +5522,6 @@ function performAction({
5512
5522
  });
5513
5523
  break;
5514
5524
  }
5515
- case "reselect": {
5516
- behaviorActionImplementations.reselect({
5517
- context,
5518
- action
5519
- });
5520
- break;
5521
- }
5522
5525
  case "style.add": {
5523
5526
  behaviorActionImplementations["style.add"]({
5524
5527
  context,
@@ -5573,13 +5576,6 @@ function performDefaultAction({
5573
5576
  });
5574
5577
  break;
5575
5578
  }
5576
- case "annotation.toggle": {
5577
- behaviorActionImplementations["annotation.toggle"]({
5578
- context,
5579
- action
5580
- });
5581
- break;
5582
- }
5583
5579
  case "blur": {
5584
5580
  behaviorActionImplementations.blur({
5585
5581
  context,
@@ -5587,20 +5583,6 @@ function performDefaultAction({
5587
5583
  });
5588
5584
  break;
5589
5585
  }
5590
- case "decorator.add": {
5591
- behaviorActionImplementations["decorator.add"]({
5592
- context,
5593
- action
5594
- });
5595
- break;
5596
- }
5597
- case "decorator.remove": {
5598
- behaviorActionImplementations["decorator.remove"]({
5599
- context,
5600
- action
5601
- });
5602
- break;
5603
- }
5604
5586
  case "decorator.toggle": {
5605
5587
  behaviorActionImplementations["decorator.toggle"]({
5606
5588
  context,
@@ -5671,6 +5653,13 @@ function performDefaultAction({
5671
5653
  });
5672
5654
  break;
5673
5655
  }
5656
+ case "select": {
5657
+ behaviorActionImplementations.select({
5658
+ context,
5659
+ action
5660
+ });
5661
+ break;
5662
+ }
5674
5663
  default:
5675
5664
  behaviorActionImplementations["style.toggle"]({
5676
5665
  context,
@@ -5749,10 +5738,12 @@ const editorMachine = xstate.setup({
5749
5738
  if (eventBehaviors.length === 0) {
5750
5739
  if (!defaultAction)
5751
5740
  return;
5752
- slate.Editor.withoutNormalizing(event.editor, () => {
5753
- performAction({
5754
- context,
5755
- action: defaultAction
5741
+ withApplyingBehaviorActions(event.editor, () => {
5742
+ slate.Editor.withoutNormalizing(event.editor, () => {
5743
+ performAction({
5744
+ context,
5745
+ action: defaultAction
5746
+ });
5756
5747
  });
5757
5748
  }), event.editor.onChange();
5758
5749
  return;
@@ -5780,21 +5771,28 @@ const editorMachine = xstate.setup({
5780
5771
  event: event.behaviorEvent
5781
5772
  }, shouldRun));
5782
5773
  for (const actionIntends of actionIntendSets)
5783
- behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), slate.Editor.withoutNormalizing(event.editor, () => {
5784
- for (const actionIntend of actionIntends) {
5785
- const action = {
5786
- ...actionIntend,
5787
- editor: event.editor
5788
- };
5789
- performAction({
5790
- context,
5791
- action
5792
- });
5793
- }
5794
- }), event.editor.onChange(), actionIntends.some((actionIntend) => actionIntend.type === "reselect") && enqueue.raise({
5795
- type: "selection",
5796
- selection: toPortableTextRange(event.editor.children, event.editor.selection, context.schema)
5797
- });
5774
+ behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), withApplyingBehaviorActions(event.editor, () => {
5775
+ slate.Editor.withoutNormalizing(event.editor, () => {
5776
+ for (const actionIntend of actionIntends) {
5777
+ if (actionIntend.type === "raise") {
5778
+ enqueue.raise({
5779
+ type: "behavior event",
5780
+ behaviorEvent: actionIntend.event,
5781
+ editor: event.editor
5782
+ });
5783
+ continue;
5784
+ }
5785
+ const action = {
5786
+ ...actionIntend,
5787
+ editor: event.editor
5788
+ };
5789
+ performAction({
5790
+ context,
5791
+ action
5792
+ });
5793
+ }
5794
+ });
5795
+ }), event.editor.onChange();
5798
5796
  if (behaviorOverwritten) {
5799
5797
  event.nativeEvent?.preventDefault();
5800
5798
  break;
@@ -5803,10 +5801,12 @@ const editorMachine = xstate.setup({
5803
5801
  if (!behaviorOverwritten) {
5804
5802
  if (!defaultAction)
5805
5803
  return;
5806
- slate.Editor.withoutNormalizing(event.editor, () => {
5807
- performAction({
5808
- context,
5809
- action: defaultAction
5804
+ withApplyingBehaviorActions(event.editor, () => {
5805
+ slate.Editor.withoutNormalizing(event.editor, () => {
5806
+ performAction({
5807
+ context,
5808
+ action: defaultAction
5809
+ });
5810
5810
  });
5811
5811
  }), event.editor.onChange();
5812
5812
  }
@@ -5947,17 +5947,7 @@ const editorMachine = xstate.setup({
5947
5947
  "behavior event": {
5948
5948
  actions: "handle behavior event"
5949
5949
  },
5950
- "annotation.add": {
5951
- actions: xstate.emit(({
5952
- event
5953
- }) => event)
5954
- },
5955
- "annotation.remove": {
5956
- actions: xstate.emit(({
5957
- event
5958
- }) => event)
5959
- },
5960
- "annotation.toggle": {
5950
+ "annotation.*": {
5961
5951
  actions: xstate.emit(({
5962
5952
  event
5963
5953
  }) => event)
@@ -5987,6 +5977,11 @@ const editorMachine = xstate.setup({
5987
5977
  event
5988
5978
  }) => event)
5989
5979
  },
5980
+ select: {
5981
+ actions: xstate.emit(({
5982
+ event
5983
+ }) => event)
5984
+ },
5990
5985
  "style.*": {
5991
5986
  actions: xstate.emit(({
5992
5987
  event
@@ -6177,7 +6172,7 @@ const EditorActorContext = React.createContext({}), PortableTextEditorSelectionC
6177
6172
  if (selection === void 0)
6178
6173
  throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
6179
6174
  return selection;
6180
- }, debug$5 = debugWithName("component:PortableTextEditor:SelectionProvider"), debugVerbose = debug$5.enabled && !1;
6175
+ }, debug$5 = debugWithName("component:PortableTextEditor:SelectionProvider");
6181
6176
  function PortableTextEditorSelectionProvider(props) {
6182
6177
  const $ = reactCompilerRuntime.c(6), [selection, setSelection] = React.useState(null);
6183
6178
  let t0, t1;
@@ -6185,7 +6180,7 @@ function PortableTextEditorSelectionProvider(props) {
6185
6180
  debug$5("Subscribing to selection changes");
6186
6181
  const subscription = props.editorActor.on("selection", (event) => {
6187
6182
  React.startTransition(() => {
6188
- debugVerbose && debug$5("Setting selection"), setSelection(event.selection);
6183
+ setSelection(event.selection);
6189
6184
  });
6190
6185
  });
6191
6186
  return () => {
@@ -6381,23 +6376,19 @@ function RouteEventsToChanges(props) {
6381
6376
  });
6382
6377
  break bb5;
6383
6378
  }
6384
- case "annotation.add":
6385
- case "annotation.remove":
6386
- case "annotation.toggle":
6387
- case "blur":
6388
- case "decorator.add":
6389
- case "decorator.remove":
6390
- case "decorator.toggle":
6391
- case "focus":
6392
- case "insert.block object":
6393
- case "insert.inline object":
6394
- case "list item.toggle":
6395
- case "style.toggle":
6396
- case "patches":
6397
- case "editable":
6398
- case "read only":
6379
+ case "mutation": {
6380
+ handleChange(event);
6399
6381
  break bb5;
6400
- default:
6382
+ }
6383
+ case "ready": {
6384
+ handleChange(event);
6385
+ break bb5;
6386
+ }
6387
+ case "selection": {
6388
+ handleChange(event);
6389
+ break bb5;
6390
+ }
6391
+ case "unset":
6401
6392
  handleChange(event);
6402
6393
  }
6403
6394
  });
@@ -6530,17 +6521,9 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
6530
6521
  return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
6531
6522
  };
6532
6523
  Leaf.displayName = "Leaf";
6533
- const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
6534
- marks: {
6535
- "mod+b": "strong",
6536
- "mod+i": "em",
6537
- "mod+u": "underline",
6538
- "mod+'": "code"
6539
- },
6540
- custom: {}
6541
- };
6524
+ const debug$2 = debugWithName("plugin:withHotKeys");
6542
6525
  function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
6543
- const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions || DEFAULT_HOTKEYS;
6526
+ const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
6544
6527
  return function(editor) {
6545
6528
  return editor.pteWithHotKeys = (event) => {
6546
6529
  Object.keys(activeHotkeys).forEach((cat) => {