@portabletext/editor 1.42.1 → 1.43.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 (38) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +522 -418
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-active-style.cjs +14 -0
  4. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +2 -2
  6. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  8. package/lib/_chunks-es/editor-provider.js +527 -423
  9. package/lib/_chunks-es/editor-provider.js.map +1 -1
  10. package/lib/_chunks-es/selector.is-active-style.js +15 -1
  11. package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
  12. package/lib/_chunks-es/selector.is-overlapping-selection.js +2 -2
  13. package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
  14. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  15. package/lib/behaviors/index.d.cts +11 -11
  16. package/lib/behaviors/index.d.ts +11 -11
  17. package/lib/index.d.cts +1 -1
  18. package/lib/index.d.ts +1 -1
  19. package/lib/plugins/index.d.cts +1 -1
  20. package/lib/plugins/index.d.ts +1 -1
  21. package/lib/selectors/index.cjs +3 -8
  22. package/lib/selectors/index.cjs.map +1 -1
  23. package/lib/selectors/index.d.cts +1 -1
  24. package/lib/selectors/index.d.ts +1 -1
  25. package/lib/selectors/index.js +5 -11
  26. package/lib/selectors/index.js.map +1 -1
  27. package/lib/utils/index.d.cts +1 -1
  28. package/lib/utils/index.d.ts +1 -1
  29. package/package.json +7 -7
  30. package/src/behavior-actions/behavior.actions.ts +6 -0
  31. package/src/behaviors/behavior.default.ts +67 -1
  32. package/src/behaviors/behavior.perform-event.ts +266 -0
  33. package/src/editor/editor-machine.ts +31 -257
  34. package/src/editor/with-applying-behavior-actions.ts +13 -4
  35. package/src/internal-utils/parse-blocks.ts +14 -0
  36. package/src/plugins/plugin.markdown.test.tsx +64 -0
  37. package/src/selectors/selector.get-active-annotations.test.ts +28 -0
  38. package/src/selectors/selector.get-active-annotations.ts +15 -2
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
- var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$e = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), selector_isActiveStyle = require("./selector.is-active-style.cjs"), omit = require("lodash/omit.js"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
2
+ var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$g = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), omit = require("lodash/omit.js"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), selector_isActiveStyle = require("./selector.is-active-style.cjs"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
3
3
  function _interopDefaultCompat(e) {
4
4
  return e && typeof e == "object" && "default" in e ? e : { default: e };
5
5
  }
6
- var React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$e), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase);
6
+ var React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$g), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase);
7
7
  function createEditorSchema(portableTextType) {
8
8
  if (!portableTextType)
9
9
  throw new Error("Parameter 'portabletextType' missing (required)");
@@ -1590,14 +1590,18 @@ function isApplyingBehaviorActions(editor) {
1590
1590
  const CURRENT_BEHAVIOR_ACTION_SET = /* @__PURE__ */ new WeakMap();
1591
1591
  function withApplyingBehaviorActionSet(editor, fn) {
1592
1592
  const current = CURRENT_BEHAVIOR_ACTION_SET.get(editor);
1593
- CURRENT_BEHAVIOR_ACTION_SET.set(editor, {
1593
+ if (current) {
1594
+ withApplyingBehaviorActions(editor, fn);
1595
+ return;
1596
+ }
1597
+ CURRENT_BEHAVIOR_ACTION_SET.set(editor, current ?? {
1594
1598
  actionSetId: defaultKeyGenerator()
1595
- }), withApplyingBehaviorActions(editor, fn), CURRENT_BEHAVIOR_ACTION_SET.set(editor, current);
1599
+ }), withApplyingBehaviorActions(editor, fn), CURRENT_BEHAVIOR_ACTION_SET.set(editor, void 0);
1596
1600
  }
1597
1601
  function getCurrentBehaviorActionSetId(editor) {
1598
1602
  return CURRENT_BEHAVIOR_ACTION_SET.get(editor)?.actionSetId;
1599
1603
  }
1600
- const debug$d = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1604
+ const debug$f = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1601
1605
  const state = SAVING.get(editor);
1602
1606
  return state === void 0 ? !0 : state;
1603
1607
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
@@ -1611,7 +1615,7 @@ function createWithUndoRedo(options) {
1611
1615
  const remotePatches = getRemotePatches(editor);
1612
1616
  let previousBehaviorActionSetId = getCurrentBehaviorActionSetId(editor);
1613
1617
  options.subscriptions.push(() => {
1614
- debug$d("Subscribing to patches");
1618
+ debug$f("Subscribing to patches");
1615
1619
  const sub = editorActor.on("patches", ({
1616
1620
  patches: patches2,
1617
1621
  snapshot
@@ -1620,7 +1624,7 @@ function createWithUndoRedo(options) {
1620
1624
  patches2.forEach((patch) => {
1621
1625
  if (!reset && patch.origin !== "local" && remotePatches) {
1622
1626
  if (patch.type === "unset" && patch.path.length === 0) {
1623
- debug$d("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1627
+ debug$f("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1624
1628
  undos: [],
1625
1629
  redos: []
1626
1630
  }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
@@ -1636,7 +1640,7 @@ function createWithUndoRedo(options) {
1636
1640
  }), previousSnapshot = snapshot;
1637
1641
  });
1638
1642
  return () => {
1639
- debug$d("Unsubscribing to patches"), sub.unsubscribe();
1643
+ debug$f("Unsubscribing to patches"), sub.unsubscribe();
1640
1644
  };
1641
1645
  }), editor.history = {
1642
1646
  undos: [],
@@ -1675,7 +1679,7 @@ function createWithUndoRedo(options) {
1675
1679
  operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
1676
1680
  timestamp: /* @__PURE__ */ new Date()
1677
1681
  };
1678
- undos.push(newStep), debug$d("Created new undo step", step);
1682
+ undos.push(newStep), debug$f("Created new undo step", step);
1679
1683
  }
1680
1684
  for (; undos.length > UNDO_STEP_LIMIT; )
1681
1685
  undos.shift();
@@ -1693,7 +1697,7 @@ const historyUndoActionImplementation = ({
1693
1697
  } = editor.history, remotePatches = getRemotePatches(editor);
1694
1698
  if (undos.length > 0) {
1695
1699
  const step = undos[undos.length - 1];
1696
- if (debug$d("Undoing", step), step.operations.length > 0) {
1700
+ if (debug$f("Undoing", step), step.operations.length > 0) {
1697
1701
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
1698
1702
  let transformedOperations = step.operations;
1699
1703
  otherPatches.forEach((item) => {
@@ -1711,7 +1715,7 @@ const historyUndoActionImplementation = ({
1711
1715
  });
1712
1716
  });
1713
1717
  } catch (err) {
1714
- debug$d("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1718
+ debug$f("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1715
1719
  undos: [],
1716
1720
  redos: []
1717
1721
  }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
@@ -1728,7 +1732,7 @@ const historyUndoActionImplementation = ({
1728
1732
  } = editor.history, remotePatches = getRemotePatches(editor);
1729
1733
  if (redos.length > 0) {
1730
1734
  const step = redos[redos.length - 1];
1731
- if (debug$d("Redoing", step), step.operations.length > 0) {
1735
+ if (debug$f("Redoing", step), step.operations.length > 0) {
1732
1736
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
1733
1737
  let transformedOperations = step.operations;
1734
1738
  otherPatches.forEach((item) => {
@@ -1745,7 +1749,7 @@ const historyUndoActionImplementation = ({
1745
1749
  });
1746
1750
  });
1747
1751
  } catch (err) {
1748
- debug$d("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1752
+ debug$f("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1749
1753
  undos: [],
1750
1754
  redos: []
1751
1755
  }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
@@ -1763,16 +1767,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
1763
1767
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
1764
1768
  _key: blk._key
1765
1769
  }, patch.path[0]));
1766
- return debug$d(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
1770
+ return debug$f(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
1767
1771
  }
1768
1772
  if (patch.type === "unset" && patch.path.length === 1) {
1769
1773
  const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
1770
1774
  _key: blk._key
1771
1775
  }, patch.path[0]));
1772
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$d("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
1776
+ return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$f("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
1773
1777
  }
1774
1778
  if (patch.type === "unset" && patch.path.length === 0)
1775
- return debug$d(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
1779
+ return debug$f(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
1776
1780
  if (patch.type === "diffMatchPatch") {
1777
1781
  const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
1778
1782
  return !operationTargetBlock || !isEqual__default.default({
@@ -1859,7 +1863,7 @@ function findOperationTargetBlock(editor, operation) {
1859
1863
  let block;
1860
1864
  return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
1861
1865
  }
1862
- const debug$c = debugWithName("sync machine"), syncValueCallback = ({
1866
+ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
1863
1867
  sendBack,
1864
1868
  input
1865
1869
  }) => {
@@ -1911,7 +1915,7 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
1911
1915
  context
1912
1916
  }) => {
1913
1917
  const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
1914
- return debug$c("isBusy", {
1918
+ return debug$e("isBusy", {
1915
1919
  isBusy,
1916
1920
  editable,
1917
1921
  isProcessingLocalChanges,
@@ -1965,10 +1969,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
1965
1969
  states: {
1966
1970
  "syncing initial value": {
1967
1971
  entry: [() => {
1968
- debug$c("entry: syncing initial value");
1972
+ debug$e("entry: syncing initial value");
1969
1973
  }],
1970
1974
  exit: [() => {
1971
- debug$c("exit: syncing initial value");
1975
+ debug$e("exit: syncing initial value");
1972
1976
  }],
1973
1977
  always: {
1974
1978
  guard: "initial value synced",
@@ -1977,10 +1981,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
1977
1981
  },
1978
1982
  "done syncing initial value": {
1979
1983
  entry: ["emit done syncing initial value", () => {
1980
- debug$c("entry: done syncing initial value");
1984
+ debug$e("entry: done syncing initial value");
1981
1985
  }],
1982
1986
  exit: [() => {
1983
- debug$c("exit: done syncing initial value");
1987
+ debug$e("exit: done syncing initial value");
1984
1988
  }],
1985
1989
  type: "final"
1986
1990
  }
@@ -1991,10 +1995,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
1991
1995
  states: {
1992
1996
  idle: {
1993
1997
  entry: [() => {
1994
- debug$c("entry: syncing->idle");
1998
+ debug$e("entry: syncing->idle");
1995
1999
  }],
1996
2000
  exit: [() => {
1997
- debug$c("exit: syncing->idle");
2001
+ debug$e("exit: syncing->idle");
1998
2002
  }],
1999
2003
  on: {
2000
2004
  "update value": [{
@@ -2009,10 +2013,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
2009
2013
  },
2010
2014
  busy: {
2011
2015
  entry: [() => {
2012
- debug$c("entry: syncing->busy");
2016
+ debug$e("entry: syncing->busy");
2013
2017
  }],
2014
2018
  exit: [() => {
2015
- debug$c("exit: syncing->busy");
2019
+ debug$e("exit: syncing->busy");
2016
2020
  }],
2017
2021
  after: {
2018
2022
  1e3: [{
@@ -2020,7 +2024,7 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
2020
2024
  target: ".",
2021
2025
  reenter: !0,
2022
2026
  actions: [() => {
2023
- debug$c("reenter: syncing->busy");
2027
+ debug$e("reenter: syncing->busy");
2024
2028
  }]
2025
2029
  }, {
2026
2030
  target: "syncing"
@@ -2034,10 +2038,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
2034
2038
  },
2035
2039
  syncing: {
2036
2040
  entry: [() => {
2037
- debug$c("entry: syncing->syncing");
2041
+ debug$e("entry: syncing->syncing");
2038
2042
  }],
2039
2043
  exit: [() => {
2040
- debug$c("exit: syncing->syncing");
2044
+ debug$e("exit: syncing->syncing");
2041
2045
  }],
2042
2046
  always: {
2043
2047
  guard: "pending value equals previous value",
@@ -2104,7 +2108,7 @@ async function updateValue({
2104
2108
  }) {
2105
2109
  let isChanged = !1, isValid = !0;
2106
2110
  const hadSelection = !!slateEditor.selection;
2107
- if ((!value || value.length === 0) && (debug$c("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
2111
+ if ((!value || value.length === 0) && (debug$e("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
2108
2112
  withoutSaving(slateEditor, () => {
2109
2113
  withoutPatching(slateEditor, () => {
2110
2114
  hadSelection && slate.Transforms.deselect(slateEditor);
@@ -2160,14 +2164,14 @@ async function updateValue({
2160
2164
  });
2161
2165
  }
2162
2166
  if (!isValid) {
2163
- debug$c("Invalid value, returning"), sendBack({
2167
+ debug$e("Invalid value, returning"), sendBack({
2164
2168
  type: "done syncing",
2165
2169
  value
2166
2170
  });
2167
2171
  return;
2168
2172
  }
2169
2173
  if (isChanged) {
2170
- debug$c("Server value changed, syncing editor");
2174
+ debug$e("Server value changed, syncing editor");
2171
2175
  try {
2172
2176
  slateEditor.onChange();
2173
2177
  } catch (err) {
@@ -2195,7 +2199,7 @@ async function updateValue({
2195
2199
  value
2196
2200
  });
2197
2201
  } else
2198
- debug$c("Server value and editor value is equal, no need to sync.");
2202
+ debug$e("Server value and editor value is equal, no need to sync.");
2199
2203
  sendBack({
2200
2204
  type: "done syncing",
2201
2205
  value
@@ -2229,7 +2233,7 @@ function syncBlock({
2229
2233
  type: "patch",
2230
2234
  patch
2231
2235
  });
2232
- })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$c.enabled && debug$c("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$c.enabled && debug$c("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
2236
+ })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$e.enabled && debug$e("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$e.enabled && debug$e("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
2233
2237
  type: "invalid value",
2234
2238
  resolution: validation.resolution,
2235
2239
  value
@@ -2237,9 +2241,9 @@ function syncBlock({
2237
2241
  }
2238
2242
  if (!oldBlock && blockValid) {
2239
2243
  const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
2240
- debug$c.enabled && debug$c("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
2244
+ debug$e.enabled && debug$e("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
2241
2245
  at: [currentBlockIndex]
2242
- }) : (debug$c("Invalid", validation), sendBack({
2246
+ }) : (debug$e("Invalid", validation), sendBack({
2243
2247
  type: "invalid value",
2244
2248
  resolution: validation.resolution,
2245
2249
  value
@@ -2267,14 +2271,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2267
2271
  const oldBlockChildrenLength = oldBlock.children.length;
2268
2272
  currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
2269
2273
  const childIndex = oldBlockChildrenLength - 1 - index;
2270
- childIndex > 0 && (debug$c("Removing child"), slate.Transforms.removeNodes(slateEditor, {
2274
+ childIndex > 0 && (debug$e("Removing child"), slate.Transforms.removeNodes(slateEditor, {
2271
2275
  at: [currentBlockIndex, childIndex]
2272
2276
  }));
2273
2277
  }), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
2274
2278
  const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
2275
2279
  if (isChildChanged)
2276
2280
  if (currentBlockChild._key === oldBlockChild?._key) {
2277
- debug$c("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
2281
+ debug$e("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
2278
2282
  at: path
2279
2283
  });
2280
2284
  const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
@@ -2291,23 +2295,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2291
2295
  }
2292
2296
  }), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
2293
2297
  at: path
2294
- }), slateEditor.onChange()) : isSpanNode || (debug$c("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
2298
+ }), slateEditor.onChange()) : isSpanNode || (debug$e("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
2295
2299
  _key: VOID_CHILD_KEY
2296
2300
  }, {
2297
2301
  at: [...path, 0],
2298
2302
  voids: !0
2299
2303
  }));
2300
- } else oldBlockChild ? (debug$c("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
2304
+ } else oldBlockChild ? (debug$e("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
2301
2305
  at: [currentBlockIndex, currentBlockChildIndex]
2302
2306
  }), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2303
2307
  at: [currentBlockIndex, currentBlockChildIndex]
2304
- }), slateEditor.onChange()) : oldBlockChild || (debug$c("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2308
+ }), slateEditor.onChange()) : oldBlockChild || (debug$e("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2305
2309
  at: [currentBlockIndex, currentBlockChildIndex]
2306
2310
  }), slateEditor.onChange());
2307
2311
  });
2308
2312
  }
2309
2313
  }
2310
- const debug$b = debugWithName("component:PortableTextEditor:Synchronizer");
2314
+ const debug$d = debugWithName("component:PortableTextEditor:Synchronizer");
2311
2315
  function Synchronizer(props) {
2312
2316
  const $ = reactCompilerRuntime.c(41), {
2313
2317
  editorActor,
@@ -2403,14 +2407,14 @@ function Synchronizer(props) {
2403
2407
  }, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), React.useEffect(t11, t12);
2404
2408
  let t13, t14;
2405
2409
  $[30] !== syncActorRef || $[31] !== value ? (t13 = () => {
2406
- debug$b("Value from props changed, syncing new value"), syncActorRef.send({
2410
+ debug$d("Value from props changed, syncing new value"), syncActorRef.send({
2407
2411
  type: "update value",
2408
2412
  value
2409
2413
  });
2410
2414
  }, t14 = [syncActorRef, value], $[30] = syncActorRef, $[31] = value, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
2411
2415
  let t15;
2412
2416
  $[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
2413
- debug$b("Subscribing to patch events");
2417
+ debug$d("Subscribing to patch events");
2414
2418
  const sub = editorActor.on("internal.patch", (event_1) => {
2415
2419
  mutationActorRef.send({
2416
2420
  ...event_1,
@@ -2418,7 +2422,7 @@ function Synchronizer(props) {
2418
2422
  });
2419
2423
  });
2420
2424
  return () => {
2421
- debug$b("Unsubscribing to patch events"), sub.unsubscribe();
2425
+ debug$d("Unsubscribing to patch events"), sub.unsubscribe();
2422
2426
  };
2423
2427
  }, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
2424
2428
  let t16;
@@ -2645,11 +2649,11 @@ const converterJson = {
2645
2649
  function escapeHtml(str) {
2646
2650
  return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
2647
2651
  }
2648
- const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$a = debugWithName("operationToPatches");
2652
+ const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$c = debugWithName("operationToPatches");
2649
2653
  function createOperationToPatches(types2) {
2650
2654
  const textBlockName = types2.block.name;
2651
2655
  function insertTextPatch(editor, operation, beforeValue) {
2652
- debug$a.enabled && debug$a("Operation", JSON.stringify(operation, null, 2));
2656
+ debug$c.enabled && debug$c("Operation", JSON.stringify(operation, null, 2));
2653
2657
  const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
2654
2658
  if (!block)
2655
2659
  throw new Error("Could not find block");
@@ -2742,7 +2746,7 @@ function createOperationToPatches(types2) {
2742
2746
  _key: block.children[operation.path[1] - 1]._key
2743
2747
  }])];
2744
2748
  }
2745
- return debug$a("Something was inserted into a void block. Not producing editor patches."), [];
2749
+ return debug$c("Something was inserted into a void block. Not producing editor patches."), [];
2746
2750
  }
2747
2751
  function splitNodePatch(editor, operation, beforeValue) {
2748
2752
  const patches$1 = [], splitBlock = editor.children[operation.path[0]];
@@ -2800,9 +2804,9 @@ function createOperationToPatches(types2) {
2800
2804
  _key: block._key
2801
2805
  }, "children", {
2802
2806
  _key: spanToRemove._key
2803
- }])] : (debug$a("Span not found in editor trying to remove node"), []);
2807
+ }])] : (debug$c("Span not found in editor trying to remove node"), []);
2804
2808
  } else
2805
- return debug$a("Not creating patch inside object block"), [];
2809
+ return debug$c("Not creating patch inside object block"), [];
2806
2810
  }
2807
2811
  function mergeNodePatch(editor, operation, beforeValue) {
2808
2812
  const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
@@ -2828,7 +2832,7 @@ function createOperationToPatches(types2) {
2828
2832
  _key: removedSpan._key
2829
2833
  }])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
2830
2834
  } else
2831
- debug$a("Void nodes can't be merged, not creating any patches");
2835
+ debug$c("Void nodes can't be merged, not creating any patches");
2832
2836
  return patches$1;
2833
2837
  }
2834
2838
  function moveNodePatch(editor, operation, beforeValue) {
@@ -3209,7 +3213,7 @@ function getNextSpan({
3209
3213
  }
3210
3214
  return nextSpan;
3211
3215
  }
3212
- const debug$9 = debugWithName("plugin:withPortableTextMarkModel");
3216
+ const debug$b = debugWithName("plugin:withPortableTextMarkModel");
3213
3217
  function createWithPortableTextMarkModel(editorActor, types2) {
3214
3218
  return function(editor) {
3215
3219
  const {
@@ -3223,7 +3227,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3223
3227
  for (const [child, childPath] of children) {
3224
3228
  const nextNode = node.children[childPath[1] + 1];
3225
3229
  if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
3226
- debug$9("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3230
+ debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3227
3231
  type: "normalizing"
3228
3232
  }), slate.Transforms.mergeNodes(editor, {
3229
3233
  at: [childPath[0], childPath[1] + 1],
@@ -3236,7 +3240,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3236
3240
  }
3237
3241
  }
3238
3242
  if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
3239
- debug$9("Adding .markDefs to block node"), editorActor.send({
3243
+ debug$b("Adding .markDefs to block node"), editorActor.send({
3240
3244
  type: "normalizing"
3241
3245
  }), slate.Transforms.setNodes(editor, {
3242
3246
  markDefs: []
@@ -3248,7 +3252,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3248
3252
  return;
3249
3253
  }
3250
3254
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
3251
- debug$9("Adding .marks to span node"), editorActor.send({
3255
+ debug$b("Adding .marks to span node"), editorActor.send({
3252
3256
  type: "normalizing"
3253
3257
  }), slate.Transforms.setNodes(editor, {
3254
3258
  marks: []
@@ -3262,7 +3266,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3262
3266
  if (editor.isTextSpan(node)) {
3263
3267
  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));
3264
3268
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
3265
- debug$9("Removing annotations from empty span node"), editorActor.send({
3269
+ debug$b("Removing annotations from empty span node"), editorActor.send({
3266
3270
  type: "normalizing"
3267
3271
  }), slate.Transforms.setNodes(editor, {
3268
3272
  marks: node.marks?.filter((mark) => decorators2.includes(mark))
@@ -3280,7 +3284,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3280
3284
  if (editor.isTextSpan(child)) {
3281
3285
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
3282
3286
  if (orphanedAnnotations.length > 0) {
3283
- debug$9("Removing orphaned annotations from span node"), editorActor.send({
3287
+ debug$b("Removing orphaned annotations from span node"), editorActor.send({
3284
3288
  type: "normalizing"
3285
3289
  }), slate.Transforms.setNodes(editor, {
3286
3290
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3298,7 +3302,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3298
3302
  if (editor.isTextBlock(block)) {
3299
3303
  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));
3300
3304
  if (orphanedAnnotations.length > 0) {
3301
- debug$9("Removing orphaned annotations from span node"), editorActor.send({
3305
+ debug$b("Removing orphaned annotations from span node"), editorActor.send({
3302
3306
  type: "normalizing"
3303
3307
  }), slate.Transforms.setNodes(editor, {
3304
3308
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3316,7 +3320,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3316
3320
  for (const markDef of markDefs)
3317
3321
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
3318
3322
  if (markDefs.length !== newMarkDefs.length) {
3319
- debug$9("Removing duplicate markDefs"), editorActor.send({
3323
+ debug$b("Removing duplicate markDefs"), editorActor.send({
3320
3324
  type: "normalizing"
3321
3325
  }), slate.Transforms.setNodes(editor, {
3322
3326
  markDefs: newMarkDefs
@@ -3331,7 +3335,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3331
3335
  if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
3332
3336
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
3333
3337
  if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
3334
- debug$9("Removing markDef not in use"), editorActor.send({
3338
+ debug$b("Removing markDef not in use"), editorActor.send({
3335
3339
  type: "normalizing"
3336
3340
  }), slate.Transforms.setNodes(editor, {
3337
3341
  markDefs: newMarkDefs
@@ -3551,7 +3555,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3551
3555
  const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
3552
3556
  if (editor.isTextBlock(targetBlock)) {
3553
3557
  const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
3554
- debug$9("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
3558
+ debug$b("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
3555
3559
  markDefs: newMarkDefs
3556
3560
  }, {
3557
3561
  at: targetPath,
@@ -3656,7 +3660,7 @@ const toggleDecoratorActionImplementation = ({
3656
3660
  ...action
3657
3661
  }
3658
3662
  });
3659
- }, debug$8 = debugWithName("API:editable");
3663
+ }, debug$a = debugWithName("API:editable");
3660
3664
  function createEditableAPI(editor, editorActor) {
3661
3665
  const types2 = editorActor.getSnapshot().context.schema;
3662
3666
  return {
@@ -3791,7 +3795,7 @@ function createEditableAPI(editor, editorActor) {
3791
3795
  }], {
3792
3796
  schemaTypes: editorActor.getSnapshot().context.schema
3793
3797
  })[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
3794
- return isSpanNode && focusNode._type !== types2.span.name && (debug$8("Inserting span child next to inline object child, moving selection + 1"), editor.move({
3798
+ return isSpanNode && focusNode._type !== types2.span.name && (debug$a("Inserting span child next to inline object child, moving selection + 1"), editor.move({
3795
3799
  distance: 1,
3796
3800
  unit: "character"
3797
3801
  })), slate.Transforms.insertNodes(editor, child, {
@@ -3928,18 +3932,18 @@ function createEditableAPI(editor, editorActor) {
3928
3932
  throw new Error("Invalid range");
3929
3933
  if (range) {
3930
3934
  if (!options?.mode || options?.mode === "selected") {
3931
- debug$8("Deleting content in selection"), slate.Transforms.delete(editor, {
3935
+ debug$a("Deleting content in selection"), slate.Transforms.delete(editor, {
3932
3936
  at: range,
3933
3937
  hanging: !0,
3934
3938
  voids: !0
3935
3939
  }), editor.onChange();
3936
3940
  return;
3937
3941
  }
3938
- options?.mode === "blocks" && (debug$8("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
3942
+ options?.mode === "blocks" && (debug$a("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
3939
3943
  at: range,
3940
3944
  voids: !0,
3941
3945
  match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
3942
- })), options?.mode === "children" && (debug$8("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
3946
+ })), options?.mode === "children" && (debug$a("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
3943
3947
  at: range,
3944
3948
  voids: !0,
3945
3949
  match: (node) => node._type === types2.span.name || // Text children
@@ -4066,7 +4070,7 @@ const addAnnotationActionImplementation = ({
4066
4070
  action
4067
4071
  }) => {
4068
4072
  const editor = action.editor;
4069
- if (debug$8("Removing annotation", action.annotation.name), !!editor.selection)
4073
+ if (debug$a("Removing annotation", action.annotation.name), !!editor.selection)
4070
4074
  if (slate.Range.isCollapsed(editor.selection)) {
4071
4075
  const [block, blockPath] = slate.Editor.node(editor, editor.selection, {
4072
4076
  depth: 1
@@ -4812,7 +4816,7 @@ const selectActionImplementation = ({
4812
4816
  mimeType: action.mimeType
4813
4817
  }
4814
4818
  });
4815
- }, behaviorActionImplementations = {
4819
+ }, debug$9 = debugWithName("behaviors:action"), behaviorActionImplementations = {
4816
4820
  "annotation.add": addAnnotationActionImplementation,
4817
4821
  "annotation.remove": removeAnnotationActionImplementation,
4818
4822
  "annotation.toggle": toggleAnnotationActionImplementation,
@@ -4861,7 +4865,7 @@ function performAction({
4861
4865
  context,
4862
4866
  action
4863
4867
  }) {
4864
- switch (action.type) {
4868
+ switch (debug$9(JSON.stringify(omit__default.default(action, ["editor"]), null, 2)), action.type) {
4865
4869
  case "annotation.add": {
4866
4870
  behaviorActionImplementations["annotation.add"]({
4867
4871
  context,
@@ -5473,13 +5477,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
5473
5477
  }, editor;
5474
5478
  };
5475
5479
  }
5476
- const debug$7 = debugWithName("applyPatches"), debugVerbose = debug$7.enabled && !0;
5480
+ const debug$8 = debugWithName("applyPatches"), debugVerbose = debug$8.enabled && !0;
5477
5481
  function createApplyPatch(schemaTypes) {
5478
5482
  return (editor, patch) => {
5479
5483
  let changed = !1;
5480
- debugVerbose && (debug$7(`
5484
+ debugVerbose && (debug$8(`
5481
5485
 
5482
- NEW PATCH =============================================================`), debug$7(JSON.stringify(patch, null, 2)));
5486
+ NEW PATCH =============================================================`), debug$8(JSON.stringify(patch, null, 2)));
5483
5487
  try {
5484
5488
  switch (patch.type) {
5485
5489
  case "insert":
@@ -5495,7 +5499,7 @@ NEW PATCH =============================================================`), debug
5495
5499
  changed = diffMatchPatch(editor, patch);
5496
5500
  break;
5497
5501
  default:
5498
- debug$7("Unhandled patch", patch.type);
5502
+ debug$8("Unhandled patch", patch.type);
5499
5503
  }
5500
5504
  } catch (err) {
5501
5505
  console.error(err);
@@ -5510,9 +5514,9 @@ function diffMatchPatch(editor, patch) {
5510
5514
  childPath
5511
5515
  } = findBlockAndChildFromPath(editor, patch.path);
5512
5516
  if (!block)
5513
- return debug$7("Block not found"), !1;
5517
+ return debug$8("Block not found"), !1;
5514
5518
  if (!child || !childPath)
5515
- return debug$7("Child not found"), !1;
5519
+ return debug$8("Child not found"), !1;
5516
5520
  if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
5517
5521
  return !1;
5518
5522
  const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
@@ -5542,9 +5546,9 @@ function insertPatch(editor, patch, schemaTypes) {
5542
5546
  childPath: targetChildPath
5543
5547
  } = findBlockAndChildFromPath(editor, patch.path);
5544
5548
  if (!targetBlock || !targetBlockPath)
5545
- return debug$7("Block not found"), !1;
5549
+ return debug$8("Block not found"), !1;
5546
5550
  if (patch.path.length > 1 && patch.path[1] !== "children")
5547
- return debug$7("Ignoring patch targeting void value"), !1;
5551
+ return debug$8("Ignoring patch targeting void value"), !1;
5548
5552
  if (patch.path.length === 1) {
5549
5553
  const {
5550
5554
  items: items2,
@@ -5552,7 +5556,7 @@ function insertPatch(editor, patch, schemaTypes) {
5552
5556
  } = patch, blocksToInsert = toSlateValue(items2, {
5553
5557
  schemaTypes
5554
5558
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
5555
- return debug$7(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
5559
+ return debug$8(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
5556
5560
  at: [normalizedIdx2]
5557
5561
  }), debugState(editor, "after"), !0;
5558
5562
  }
@@ -5561,14 +5565,14 @@ function insertPatch(editor, patch, schemaTypes) {
5561
5565
  position
5562
5566
  } = patch;
5563
5567
  if (!targetChild || !targetChildPath)
5564
- return debug$7("Child not found"), !1;
5568
+ return debug$8("Child not found"), !1;
5565
5569
  const childrenToInsert = targetBlock && toSlateValue([{
5566
5570
  ...targetBlock,
5567
5571
  children: items
5568
5572
  }], {
5569
5573
  schemaTypes
5570
5574
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
5571
- return debug$7(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
5575
+ return debug$8(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
5572
5576
  at: childInsertPath
5573
5577
  }), debugState(editor, "after"), !0;
5574
5578
  }
@@ -5582,14 +5586,14 @@ function setPatch(editor, patch) {
5582
5586
  childPath
5583
5587
  } = findBlockAndChildFromPath(editor, patch.path);
5584
5588
  if (!block)
5585
- return debug$7("Block not found"), !1;
5589
+ return debug$8("Block not found"), !1;
5586
5590
  const isTextBlock = editor.isTextBlock(block);
5587
5591
  if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
5588
- return debug$7("Ignoring setting void value"), !1;
5592
+ return debug$8("Ignoring setting void value"), !1;
5589
5593
  if (debugState(editor, "before"), isTextBlock && child && childPath) {
5590
5594
  if (slate.Text.isText(value) && slate.Text.isText(child)) {
5591
5595
  const newText = child.text;
5592
- value.text !== newText && (debug$7("Setting text property"), editor.apply({
5596
+ value.text !== newText && (debug$8("Setting text property"), editor.apply({
5593
5597
  type: "remove_text",
5594
5598
  path: childPath,
5595
5599
  offset: 0,
@@ -5601,7 +5605,7 @@ function setPatch(editor, patch) {
5601
5605
  text: value.text
5602
5606
  }), editor.onChange());
5603
5607
  } else
5604
- debug$7("Setting non-text property"), editor.apply({
5608
+ debug$8("Setting non-text property"), editor.apply({
5605
5609
  type: "set_node",
5606
5610
  path: childPath,
5607
5611
  properties: {},
@@ -5609,7 +5613,7 @@ function setPatch(editor, patch) {
5609
5613
  });
5610
5614
  return !0;
5611
5615
  } else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
5612
- debug$7("Setting block property");
5616
+ debug$8("Setting block property");
5613
5617
  const {
5614
5618
  children,
5615
5619
  ...nextRest
@@ -5626,7 +5630,7 @@ function setPatch(editor, patch) {
5626
5630
  ...prevRest
5627
5631
  },
5628
5632
  newProperties: nextRest
5629
- }), debug$7("Setting children"), block.children.forEach((c, cIndex) => {
5633
+ }), debug$8("Setting children"), block.children.forEach((c, cIndex) => {
5630
5634
  editor.apply({
5631
5635
  type: "remove_node",
5632
5636
  path: blockPath.concat(block.children.length - 1 - cIndex),
@@ -5657,7 +5661,7 @@ function setPatch(editor, patch) {
5657
5661
  }
5658
5662
  function unsetPatch(editor, patch) {
5659
5663
  if (patch.path.length === 0) {
5660
- debug$7("Removing everything"), debugState(editor, "before");
5664
+ debug$8("Removing everything"), debugState(editor, "before");
5661
5665
  const previousSelection = editor.selection;
5662
5666
  return slate.Transforms.deselect(editor), editor.children.forEach((_child, i) => {
5663
5667
  slate.Transforms.removeNodes(editor, {
@@ -5684,13 +5688,13 @@ function unsetPatch(editor, patch) {
5684
5688
  } = findBlockAndChildFromPath(editor, patch.path);
5685
5689
  if (patch.path.length === 1) {
5686
5690
  if (!block || !blockPath)
5687
- return debug$7("Block not found"), !1;
5691
+ return debug$8("Block not found"), !1;
5688
5692
  const blockIndex = blockPath[0];
5689
- return debug$7(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
5693
+ return debug$8(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
5690
5694
  at: [blockIndex]
5691
5695
  }), debugState(editor, "after"), !0;
5692
5696
  }
5693
- return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$7("Child not found"), !1) : (debug$7(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$7(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
5697
+ return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$8("Child not found"), !1) : (debug$8(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$8(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
5694
5698
  at: childPath
5695
5699
  }), debugState(editor, "after"), !0) : !1;
5696
5700
  }
@@ -5698,7 +5702,7 @@ function isKeyedSegment(segment) {
5698
5702
  return typeof segment == "object" && "_key" in segment;
5699
5703
  }
5700
5704
  function debugState(editor, stateName) {
5701
- debugVerbose && (debug$7(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$7(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
5705
+ debugVerbose && (debug$8(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$8(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
5702
5706
  }
5703
5707
  function findBlockFromPath(editor, path) {
5704
5708
  let blockIndex = -1;
@@ -5740,7 +5744,7 @@ function findBlockAndChildFromPath(editor, path) {
5740
5744
  childPath: void 0
5741
5745
  };
5742
5746
  }
5743
- const debug$6 = debugWithName("plugin:withPatches");
5747
+ const debug$7 = debugWithName("plugin:withPatches");
5744
5748
  function createWithPatches({
5745
5749
  editorActor,
5746
5750
  patchFunctions,
@@ -5766,7 +5770,7 @@ function createWithPatches({
5766
5770
  withoutPatching(editor, () => {
5767
5771
  withoutSaving(editor, () => {
5768
5772
  patches2.forEach((patch) => {
5769
- debug$6.enabled && debug$6(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
5773
+ debug$7.enabled && debug$7(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
5770
5774
  });
5771
5775
  });
5772
5776
  });
@@ -5779,10 +5783,10 @@ function createWithPatches({
5779
5783
  remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
5780
5784
  };
5781
5785
  return subscriptions.push(() => {
5782
- debug$6("Subscribing to remote patches");
5786
+ debug$7("Subscribing to remote patches");
5783
5787
  const sub = editorActor.on("patches", handlePatches);
5784
5788
  return () => {
5785
- debug$6("Unsubscribing to remote patches"), sub.unsubscribe();
5789
+ debug$7("Unsubscribing to remote patches"), sub.unsubscribe();
5786
5790
  };
5787
5791
  }), editor.apply = (operation) => {
5788
5792
  let patches$1 = [];
@@ -5836,7 +5840,7 @@ function createWithPatches({
5836
5840
  }, editor;
5837
5841
  };
5838
5842
  }
5839
- const debug$5 = debugWithName("plugin:withPlaceholderBlock");
5843
+ const debug$6 = debugWithName("plugin:withPlaceholderBlock");
5840
5844
  function createWithPlaceholderBlock(editorActor) {
5841
5845
  return function(editor) {
5842
5846
  const {
@@ -5861,7 +5865,7 @@ function createWithPlaceholderBlock(editorActor) {
5861
5865
  const node = op.node;
5862
5866
  if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
5863
5867
  const nextPath = slate.Path.next(op.path);
5864
- editor.children[nextPath[0]] || (debug$5("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
5868
+ editor.children[nextPath[0]] || (debug$6("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
5865
5869
  decorators: []
5866
5870
  })));
5867
5871
  }
@@ -5870,7 +5874,7 @@ function createWithPlaceholderBlock(editorActor) {
5870
5874
  }, editor;
5871
5875
  };
5872
5876
  }
5873
- const debug$4 = debugWithName("plugin:withPortableTextBlockStyle");
5877
+ const debug$5 = debugWithName("plugin:withPortableTextBlockStyle");
5874
5878
  function createWithPortableTextBlockStyle(editorActor, types2) {
5875
5879
  const defaultStyle = types2.styles[0].value;
5876
5880
  return function(editor) {
@@ -5883,7 +5887,7 @@ function createWithPortableTextBlockStyle(editorActor, types2) {
5883
5887
  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)) {
5884
5888
  const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
5885
5889
  if (slate.Text.isText(child) && child.text === "") {
5886
- debug$4(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
5890
+ debug$5(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
5887
5891
  type: "normalizing"
5888
5892
  }), slate.Transforms.setNodes(editor, {
5889
5893
  style: defaultStyle
@@ -5935,7 +5939,7 @@ function createWithPortableTextSelections(editorActor, types2) {
5935
5939
  }, editor;
5936
5940
  };
5937
5941
  }
5938
- const debug$3 = debugWithName("plugin:withSchemaTypes");
5942
+ const debug$4 = debugWithName("plugin:withSchemaTypes");
5939
5943
  function createWithSchemaTypes({
5940
5944
  editorActor,
5941
5945
  schemaTypes
@@ -5948,7 +5952,7 @@ function createWithSchemaTypes({
5948
5952
  return editor.normalizeNode = (entry) => {
5949
5953
  const [node, path] = entry;
5950
5954
  if (node._type === void 0 && path.length === 2) {
5951
- debug$3("Setting span type on text node without a type");
5955
+ debug$4("Setting span type on text node without a type");
5952
5956
  const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
5953
5957
  editorActor.send({
5954
5958
  type: "normalizing"
@@ -5964,7 +5968,7 @@ function createWithSchemaTypes({
5964
5968
  return;
5965
5969
  }
5966
5970
  if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
5967
- debug$3("Setting missing key on child node without a key");
5971
+ debug$4("Setting missing key on child node without a key");
5968
5972
  const key = editorActor.getSnapshot().context.keyGenerator();
5969
5973
  editorActor.send({
5970
5974
  type: "normalizing"
@@ -6030,12 +6034,12 @@ const withPlugins = (editor, options) => {
6030
6034
  schemaTypes
6031
6035
  }), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
6032
6036
  return createWithEventListeners(editorActor, options.subscriptions)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
6033
- }, debug$2 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
6037
+ }, debug$3 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
6034
6038
  function createSlateEditor(config) {
6035
6039
  const existingSlateEditor = slateEditors.get(config.editorActor);
6036
6040
  if (existingSlateEditor)
6037
- return debug$2("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
6038
- debug$2("Creating new Slate editor instance", config.editorActor.id);
6041
+ return debug$3("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
6042
+ debug$3("Creating new Slate editor instance", config.editorActor.id);
6039
6043
  const unsubscriptions = [], subscriptions = [], instance = withPlugins(slateReact.withReact(slate.createEditor()), {
6040
6044
  editorActor: config.editorActor,
6041
6045
  subscriptions
@@ -6220,195 +6224,273 @@ const keyIs = {
6220
6224
  ...serializeEvent,
6221
6225
  originEvent: event.originEvent
6222
6226
  }))]
6223
- }), defaultBehaviors = [behavior_core.defineBehavior({
6224
- on: "clipboard.copy",
6225
- guard: ({
6226
- snapshot
6227
- }) => {
6228
- const focusSpan = selector_isOverlappingSelection.getFocusSpan(snapshot), selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot);
6229
- return focusSpan && selectionCollapsed;
6230
- },
6231
- actions: [() => [{
6232
- type: "noop"
6233
- }]]
6234
- }), behavior_core.defineBehavior({
6235
- on: "clipboard.copy",
6236
- actions: [({
6237
- event
6238
- }) => [behavior_core.raise({
6239
- type: "serialize",
6240
- originEvent: event
6241
- })]]
6242
- }), behavior_core.defineBehavior({
6243
- on: "clipboard.cut",
6244
- guard: ({
6245
- snapshot
6246
- }) => {
6247
- const focusSpan = selector_isOverlappingSelection.getFocusSpan(snapshot), selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot);
6248
- return focusSpan && selectionCollapsed;
6249
- },
6250
- actions: [() => [{
6251
- type: "noop"
6252
- }]]
6253
- }), behavior_core.defineBehavior({
6254
- on: "clipboard.cut",
6255
- guard: ({
6256
- snapshot
6257
- }) => snapshot.context.selection ? {
6258
- selection: snapshot.context.selection
6259
- } : !1,
6260
- actions: [({
6261
- event
6262
- }, {
6263
- selection
6264
- }) => [behavior_core.raise({
6265
- type: "serialize",
6266
- originEvent: event
6267
- }), behavior_core.raise({
6268
- type: "delete",
6269
- selection
6270
- })]]
6271
- }), behavior_core.defineBehavior({
6272
- on: "drag.dragstart",
6273
- actions: [({
6274
- event
6275
- }) => [behavior_core.raise({
6276
- type: "serialize",
6277
- originEvent: event
6278
- })]]
6279
- }), behavior_core.defineBehavior({
6280
- on: "serialization.success",
6281
- actions: [({
6282
- event
6283
- }) => [behavior_core.raise({
6284
- type: "data transfer.set",
6285
- data: event.data,
6286
- dataTransfer: event.originEvent.originEvent.dataTransfer,
6287
- mimeType: event.mimeType
6288
- })]]
6289
- }), behavior_core.defineBehavior({
6290
- on: "drag.drop",
6291
- guard: ({
6292
- snapshot,
6293
- event
6294
- }) => {
6295
- const dragOrigin = snapshot.beta.internalDrag?.origin, dropPosition = event.position.selection;
6296
- return dragOrigin ? selector_isOverlappingSelection.isOverlappingSelection(dropPosition)({
6297
- ...snapshot,
6298
- context: {
6299
- ...snapshot.context,
6300
- selection: dragOrigin.selection
6301
- }
6302
- }) : !1;
6303
- },
6304
- actions: [() => [{
6305
- type: "noop"
6306
- }]]
6307
- }), behavior_core.defineBehavior({
6308
- on: "drag.drop",
6309
- actions: [({
6310
- event
6311
- }) => [behavior_core.raise({
6312
- type: "select",
6313
- selection: event.position.selection
6314
- }), behavior_core.raise({
6315
- type: "deserialize",
6316
- originEvent: event
6317
- })]]
6318
- }), behavior_core.defineBehavior({
6319
- on: "deserialization.success",
6320
- guard: ({
6321
- snapshot,
6322
- event
6323
- }) => {
6324
- if (event.originEvent.type !== "drag.drop" || snapshot.beta.internalDrag === void 0)
6325
- return !1;
6326
- const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? selector_isOverlappingSelection.isOverlappingSelection(dropPosition)({
6327
- ...snapshot,
6328
- context: {
6329
- ...snapshot.context,
6330
- selection: dragOrigin.selection
6331
- }
6332
- }) : !1, draggingEntireBlocks = selector_isActiveStyle.isSelectingEntireBlocks({
6333
- context: {
6334
- ...snapshot.context,
6335
- selection: dragOrigin.selection
6336
- }
6337
- }), draggedBlocks = selector_isOverlappingSelection.getSelectedBlocks({
6338
- context: {
6339
- ...snapshot.context,
6340
- selection: dragOrigin.selection
6341
- }
6342
- });
6343
- return droppingOnDragOrigin ? !1 : {
6227
+ }), defaultBehaviors = [
6228
+ behavior_core.defineBehavior({
6229
+ on: "clipboard.copy",
6230
+ guard: ({
6231
+ snapshot
6232
+ }) => {
6233
+ const focusSpan = selector_isOverlappingSelection.getFocusSpan(snapshot), selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot);
6234
+ return focusSpan && selectionCollapsed;
6235
+ },
6236
+ actions: [() => [{
6237
+ type: "noop"
6238
+ }]]
6239
+ }),
6240
+ behavior_core.defineBehavior({
6241
+ on: "clipboard.copy",
6242
+ actions: [({
6243
+ event
6244
+ }) => [behavior_core.raise({
6245
+ type: "serialize",
6246
+ originEvent: event
6247
+ })]]
6248
+ }),
6249
+ behavior_core.defineBehavior({
6250
+ on: "clipboard.cut",
6251
+ guard: ({
6252
+ snapshot
6253
+ }) => {
6254
+ const focusSpan = selector_isOverlappingSelection.getFocusSpan(snapshot), selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot);
6255
+ return focusSpan && selectionCollapsed;
6256
+ },
6257
+ actions: [() => [{
6258
+ type: "noop"
6259
+ }]]
6260
+ }),
6261
+ behavior_core.defineBehavior({
6262
+ on: "clipboard.cut",
6263
+ guard: ({
6264
+ snapshot
6265
+ }) => snapshot.context.selection ? {
6266
+ selection: snapshot.context.selection
6267
+ } : !1,
6268
+ actions: [({
6269
+ event
6270
+ }, {
6271
+ selection
6272
+ }) => [behavior_core.raise({
6273
+ type: "serialize",
6274
+ originEvent: event
6275
+ }), behavior_core.raise({
6276
+ type: "delete",
6277
+ selection
6278
+ })]]
6279
+ }),
6280
+ behavior_core.defineBehavior({
6281
+ on: "drag.dragstart",
6282
+ actions: [({
6283
+ event
6284
+ }) => [behavior_core.raise({
6285
+ type: "serialize",
6286
+ originEvent: event
6287
+ })]]
6288
+ }),
6289
+ behavior_core.defineBehavior({
6290
+ on: "serialization.success",
6291
+ actions: [({
6292
+ event
6293
+ }) => [behavior_core.raise({
6294
+ type: "data transfer.set",
6295
+ data: event.data,
6296
+ dataTransfer: event.originEvent.originEvent.dataTransfer,
6297
+ mimeType: event.mimeType
6298
+ })]]
6299
+ }),
6300
+ behavior_core.defineBehavior({
6301
+ on: "drag.drop",
6302
+ guard: ({
6303
+ snapshot,
6304
+ event
6305
+ }) => {
6306
+ const dragOrigin = snapshot.beta.internalDrag?.origin, dropPosition = event.position.selection;
6307
+ return dragOrigin ? selector_isOverlappingSelection.isOverlappingSelection(dropPosition)({
6308
+ ...snapshot,
6309
+ context: {
6310
+ ...snapshot.context,
6311
+ selection: dragOrigin.selection
6312
+ }
6313
+ }) : !1;
6314
+ },
6315
+ actions: [() => [{
6316
+ type: "noop"
6317
+ }]]
6318
+ }),
6319
+ behavior_core.defineBehavior({
6320
+ on: "drag.drop",
6321
+ actions: [({
6322
+ event
6323
+ }) => [behavior_core.raise({
6324
+ type: "select",
6325
+ selection: event.position.selection
6326
+ }), behavior_core.raise({
6327
+ type: "deserialize",
6328
+ originEvent: event
6329
+ })]]
6330
+ }),
6331
+ behavior_core.defineBehavior({
6332
+ on: "deserialization.success",
6333
+ guard: ({
6334
+ snapshot,
6335
+ event
6336
+ }) => {
6337
+ if (event.originEvent.type !== "drag.drop" || snapshot.beta.internalDrag === void 0)
6338
+ return !1;
6339
+ const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? selector_isOverlappingSelection.isOverlappingSelection(dropPosition)({
6340
+ ...snapshot,
6341
+ context: {
6342
+ ...snapshot.context,
6343
+ selection: dragOrigin.selection
6344
+ }
6345
+ }) : !1, draggingEntireBlocks = selector_isActiveStyle.isSelectingEntireBlocks({
6346
+ context: {
6347
+ ...snapshot.context,
6348
+ selection: dragOrigin.selection
6349
+ }
6350
+ }), draggedBlocks = selector_isOverlappingSelection.getSelectedBlocks({
6351
+ context: {
6352
+ ...snapshot.context,
6353
+ selection: dragOrigin.selection
6354
+ }
6355
+ });
6356
+ return droppingOnDragOrigin ? !1 : {
6357
+ draggingEntireBlocks,
6358
+ draggedBlocks,
6359
+ dragOrigin,
6360
+ originEvent: event.originEvent
6361
+ };
6362
+ },
6363
+ actions: [({
6364
+ event
6365
+ }, {
6344
6366
  draggingEntireBlocks,
6345
6367
  draggedBlocks,
6346
6368
  dragOrigin,
6347
- originEvent: event.originEvent
6348
- };
6349
- },
6350
- actions: [({
6351
- event
6352
- }, {
6353
- draggingEntireBlocks,
6354
- draggedBlocks,
6355
- dragOrigin,
6356
- originEvent
6357
- }) => [...draggingEntireBlocks ? draggedBlocks.map((block) => behavior_core.raise({
6358
- type: "delete.block",
6359
- at: block.path
6360
- })) : [behavior_core.raise({
6361
- type: "delete",
6362
- selection: dragOrigin.selection
6363
- })], behavior_core.raise({
6364
- type: "insert.blocks",
6365
- blocks: event.data,
6366
- placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
6367
- })]]
6368
- }), behavior_core.defineBehavior({
6369
- on: "deserialization.success",
6370
- actions: [({
6371
- event
6372
- }) => [behavior_core.raise({
6373
- type: "insert.blocks",
6374
- blocks: event.data,
6375
- placement: "auto"
6376
- })]]
6377
- }), behavior_core.defineBehavior({
6378
- on: "clipboard.paste",
6379
- guard: ({
6380
- snapshot
6381
- }) => snapshot.context.selection && selector_isOverlappingSelection.isSelectionExpanded(snapshot) ? {
6382
- selection: snapshot.context.selection
6383
- } : !1,
6384
- actions: [({
6385
- event
6386
- }, {
6387
- selection
6388
- }) => [behavior_core.raise({
6389
- type: "delete",
6390
- selection
6391
- }), behavior_core.raise({
6392
- type: "deserialize",
6393
- originEvent: event
6394
- })]]
6395
- }), behavior_core.defineBehavior({
6396
- on: "clipboard.paste",
6397
- actions: [({
6398
- event
6399
- }) => [behavior_core.raise({
6400
- type: "deserialize",
6401
- originEvent: event
6402
- })]]
6403
- }), behavior_core.defineBehavior({
6404
- on: "input.*",
6405
- actions: [({
6406
- event
6407
- }) => [behavior_core.raise({
6408
- type: "deserialize",
6409
- originEvent: event
6410
- })]]
6411
- }), toggleAnnotationOff, toggleAnnotationOn, toggleDecoratorOff, toggleDecoratorOn, toggleListItemOff, toggleListItemOn, toggleStyleOff, toggleStyleOn, raiseDeserializationSuccessOrFailure, raiseSerializationSuccessOrFailure, raiseInsertSoftBreak];
6369
+ originEvent
6370
+ }) => [...draggingEntireBlocks ? draggedBlocks.map((block) => behavior_core.raise({
6371
+ type: "delete.block",
6372
+ at: block.path
6373
+ })) : [behavior_core.raise({
6374
+ type: "delete",
6375
+ selection: dragOrigin.selection
6376
+ })], behavior_core.raise({
6377
+ type: "insert.blocks",
6378
+ blocks: event.data,
6379
+ placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
6380
+ })]]
6381
+ }),
6382
+ /**
6383
+ * If we are pasting text/plain into a text block then we can probably
6384
+ * assume that the intended behavior is that the pasted text inherits
6385
+ * formatting from the text it's pasted into.
6386
+ */
6387
+ behavior_core.defineBehavior({
6388
+ on: "deserialization.success",
6389
+ guard: ({
6390
+ snapshot,
6391
+ event
6392
+ }) => {
6393
+ if (selector_isOverlappingSelection.getFocusTextBlock(snapshot) && event.mimeType === "text/plain" && event.originEvent.type === "clipboard.paste") {
6394
+ const activeDecorators = snapshot.context.activeDecorators;
6395
+ return {
6396
+ activeAnnotations: selector_isActiveStyle.getActiveAnnotations(snapshot),
6397
+ activeDecorators,
6398
+ textRuns: event.data.flatMap((block) => util_selectionPointToBlockOffset.isTextBlock(snapshot.context.schema, block) ? [util_sliceBlocks.getTextBlockText(block)] : [])
6399
+ };
6400
+ }
6401
+ return !1;
6402
+ },
6403
+ actions: [(_, {
6404
+ activeAnnotations,
6405
+ activeDecorators,
6406
+ textRuns
6407
+ }) => textRuns.flatMap((textRun, index) => index !== textRuns.length - 1 ? [behavior_core.raise({
6408
+ type: "insert.span",
6409
+ text: textRun,
6410
+ decorators: activeDecorators,
6411
+ annotations: activeAnnotations.map(({
6412
+ _key,
6413
+ _type,
6414
+ ...value
6415
+ }) => ({
6416
+ name: _type,
6417
+ value
6418
+ }))
6419
+ }), behavior_core.raise({
6420
+ type: "insert.break"
6421
+ })] : [behavior_core.raise({
6422
+ type: "insert.span",
6423
+ text: textRun,
6424
+ decorators: activeDecorators,
6425
+ annotations: activeAnnotations.map(({
6426
+ _key,
6427
+ _type,
6428
+ ...value
6429
+ }) => ({
6430
+ name: _type,
6431
+ value
6432
+ }))
6433
+ })])]
6434
+ }),
6435
+ behavior_core.defineBehavior({
6436
+ on: "deserialization.success",
6437
+ actions: [({
6438
+ event
6439
+ }) => [behavior_core.raise({
6440
+ type: "insert.blocks",
6441
+ blocks: event.data,
6442
+ placement: "auto"
6443
+ })]]
6444
+ }),
6445
+ behavior_core.defineBehavior({
6446
+ on: "clipboard.paste",
6447
+ guard: ({
6448
+ snapshot
6449
+ }) => snapshot.context.selection && selector_isOverlappingSelection.isSelectionExpanded(snapshot) ? {
6450
+ selection: snapshot.context.selection
6451
+ } : !1,
6452
+ actions: [({
6453
+ event
6454
+ }, {
6455
+ selection
6456
+ }) => [behavior_core.raise({
6457
+ type: "delete",
6458
+ selection
6459
+ }), behavior_core.raise({
6460
+ type: "deserialize",
6461
+ originEvent: event
6462
+ })]]
6463
+ }),
6464
+ behavior_core.defineBehavior({
6465
+ on: "clipboard.paste",
6466
+ actions: [({
6467
+ event
6468
+ }) => [behavior_core.raise({
6469
+ type: "deserialize",
6470
+ originEvent: event
6471
+ })]]
6472
+ }),
6473
+ behavior_core.defineBehavior({
6474
+ on: "input.*",
6475
+ actions: [({
6476
+ event
6477
+ }) => [behavior_core.raise({
6478
+ type: "deserialize",
6479
+ originEvent: event
6480
+ })]]
6481
+ }),
6482
+ toggleAnnotationOff,
6483
+ toggleAnnotationOn,
6484
+ toggleDecoratorOff,
6485
+ toggleDecoratorOn,
6486
+ toggleListItemOff,
6487
+ toggleListItemOn,
6488
+ toggleStyleOff,
6489
+ toggleStyleOn,
6490
+ raiseDeserializationSuccessOrFailure,
6491
+ raiseSerializationSuccessOrFailure,
6492
+ raiseInsertSoftBreak
6493
+ ];
6412
6494
  function isKeyboardBehaviorEvent(event) {
6413
6495
  return event.type.startsWith("keyboard.");
6414
6496
  }
@@ -6427,6 +6509,137 @@ function isMouseBehaviorEvent(event) {
6427
6509
  function isCustomBehaviorEvent(event) {
6428
6510
  return event.type.startsWith("custom.");
6429
6511
  }
6512
+ const debug$2 = debugWithName("behaviors:event");
6513
+ function performEvent({
6514
+ behaviors,
6515
+ event,
6516
+ editor,
6517
+ keyGenerator,
6518
+ schema: schema2,
6519
+ getSnapshot,
6520
+ nativeEvent,
6521
+ defaultActionCallback
6522
+ }) {
6523
+ debug$2(JSON.stringify(event, null, 2));
6524
+ const defaultAction = isCustomBehaviorEvent(event) || isClipboardBehaviorEvent(event) || isDragBehaviorEvent(event) || isInputBehaviorEvent(event) || isKeyboardBehaviorEvent(event) || isMouseBehaviorEvent(event) || event.type === "deserialize" || event.type === "serialize" ? void 0 : {
6525
+ ...event,
6526
+ editor
6527
+ }, eventBehaviors = behaviors.filter((behavior) => {
6528
+ if (behavior.on === "*")
6529
+ return !0;
6530
+ const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
6531
+ return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
6532
+ });
6533
+ if (eventBehaviors.length === 0) {
6534
+ if (defaultActionCallback) {
6535
+ withApplyingBehaviorActions(editor, () => {
6536
+ try {
6537
+ defaultActionCallback();
6538
+ } catch (error) {
6539
+ console.error(new Error(`Performing action "${event.type}" failed due to: ${error.message}`));
6540
+ }
6541
+ });
6542
+ return;
6543
+ }
6544
+ if (!defaultAction)
6545
+ return;
6546
+ withApplyingBehaviorActions(editor, () => {
6547
+ try {
6548
+ performAction({
6549
+ context: {
6550
+ keyGenerator,
6551
+ schema: schema2
6552
+ },
6553
+ action: defaultAction
6554
+ });
6555
+ } catch (error) {
6556
+ console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6557
+ }
6558
+ }), editor.onChange();
6559
+ return;
6560
+ }
6561
+ const editorSnapshot = getSnapshot();
6562
+ let behaviorOverwritten = !1;
6563
+ for (const eventBehavior of eventBehaviors) {
6564
+ const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
6565
+ context: editorSnapshot.context,
6566
+ snapshot: editorSnapshot,
6567
+ event
6568
+ });
6569
+ if (!shouldRun)
6570
+ continue;
6571
+ const actionSets = eventBehavior.actions.map((actionSet) => actionSet({
6572
+ context: editorSnapshot.context,
6573
+ snapshot: editorSnapshot,
6574
+ event
6575
+ }, shouldRun));
6576
+ for (const actionSet of actionSets)
6577
+ actionSet.length !== 0 && (behaviorOverwritten = behaviorOverwritten || actionSet.some((action) => action.type !== "effect"), withApplyingBehaviorActionSet(editor, () => {
6578
+ for (const action of actionSet) {
6579
+ if (action.type === "raise") {
6580
+ performEvent({
6581
+ behaviors,
6582
+ event: action.event,
6583
+ editor,
6584
+ keyGenerator,
6585
+ schema: schema2,
6586
+ getSnapshot,
6587
+ defaultActionCallback: void 0,
6588
+ nativeEvent: void 0
6589
+ });
6590
+ continue;
6591
+ }
6592
+ const internalAction = {
6593
+ ...action,
6594
+ editor
6595
+ };
6596
+ try {
6597
+ performAction({
6598
+ context: {
6599
+ keyGenerator,
6600
+ schema: schema2
6601
+ },
6602
+ action: internalAction
6603
+ });
6604
+ } catch (error) {
6605
+ console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6606
+ break;
6607
+ }
6608
+ }
6609
+ }), editor.onChange());
6610
+ if (behaviorOverwritten) {
6611
+ nativeEvent?.preventDefault();
6612
+ break;
6613
+ }
6614
+ }
6615
+ if (!behaviorOverwritten) {
6616
+ if (defaultActionCallback) {
6617
+ withApplyingBehaviorActions(editor, () => {
6618
+ try {
6619
+ defaultActionCallback();
6620
+ } catch (error) {
6621
+ console.error(new Error(`Performing "${event.type}" failed due to: ${error.message}`));
6622
+ }
6623
+ });
6624
+ return;
6625
+ }
6626
+ if (!defaultAction)
6627
+ return;
6628
+ withApplyingBehaviorActions(editor, () => {
6629
+ try {
6630
+ performAction({
6631
+ context: {
6632
+ keyGenerator,
6633
+ schema: schema2
6634
+ },
6635
+ action: defaultAction
6636
+ });
6637
+ } catch (error) {
6638
+ console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6639
+ }
6640
+ }), editor.onChange();
6641
+ }
6642
+ }
6430
6643
  function getActiveDecorators({
6431
6644
  schema: schema2,
6432
6645
  slateEditorInstance
@@ -6536,141 +6749,32 @@ const editorMachine = xstate.setup({
6536
6749
  "clear pending events": xstate.assign({
6537
6750
  pendingEvents: []
6538
6751
  }),
6539
- "handle behavior event": xstate.enqueueActions(({
6752
+ "handle behavior event": ({
6540
6753
  context,
6541
6754
  event,
6542
- enqueue,
6543
6755
  self
6544
6756
  }) => {
6545
- xstate.assertEvent(event, ["behavior event", "custom behavior event"]);
6546
- const defaultAction = event.type === "custom behavior event" || isClipboardBehaviorEvent(event.behaviorEvent) || isDragBehaviorEvent(event.behaviorEvent) || isInputBehaviorEvent(event.behaviorEvent) || isKeyboardBehaviorEvent(event.behaviorEvent) || isMouseBehaviorEvent(event.behaviorEvent) || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "serialize" ? void 0 : {
6547
- ...event.behaviorEvent,
6548
- editor: event.editor
6549
- }, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => {
6550
- if (behavior.on === "*")
6551
- return !0;
6552
- const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.behaviorEvent.type.includes(".") ? event.behaviorEvent.type.split(".") : [void 0];
6553
- return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.behaviorEvent.type ? !0 : behavior.on === event.behaviorEvent.type;
6554
- });
6555
- if (eventBehaviors.length === 0) {
6556
- if (defaultActionCallback) {
6557
- withApplyingBehaviorActions(event.editor, () => {
6558
- try {
6559
- defaultActionCallback();
6560
- } catch (error) {
6561
- console.error(new Error(`Performing action "${event.behaviorEvent.type}" failed due to: ${error.message}`));
6562
- }
6563
- });
6564
- return;
6565
- }
6566
- if (!defaultAction)
6567
- return;
6568
- withApplyingBehaviorActions(event.editor, () => {
6569
- try {
6570
- performAction({
6571
- context: {
6572
- keyGenerator: context.keyGenerator,
6573
- schema: context.schema
6574
- },
6575
- action: defaultAction
6576
- });
6577
- } catch (error) {
6578
- console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`));
6579
- }
6580
- }), event.editor.onChange();
6581
- return;
6582
- }
6583
- const editorSnapshot = createEditorSnapshot({
6584
- converters: [...context.converters],
6757
+ xstate.assertEvent(event, ["behavior event", "custom behavior event"]), performEvent({
6758
+ behaviors: [...context.behaviors.values(), ...defaultBehaviors],
6759
+ event: event.behaviorEvent,
6585
6760
  editor: event.editor,
6586
6761
  keyGenerator: context.keyGenerator,
6587
- readOnly: self.getSnapshot().matches({
6588
- "edit mode": "read only"
6589
- }),
6590
6762
  schema: context.schema,
6591
- hasTag: (tag) => self.getSnapshot().hasTag(tag),
6592
- internalDrag: context.internalDrag
6763
+ getSnapshot: () => createEditorSnapshot({
6764
+ converters: [...context.converters],
6765
+ editor: event.editor,
6766
+ keyGenerator: context.keyGenerator,
6767
+ readOnly: self.getSnapshot().matches({
6768
+ "edit mode": "read only"
6769
+ }),
6770
+ schema: context.schema,
6771
+ hasTag: (tag) => self.getSnapshot().hasTag(tag),
6772
+ internalDrag: context.internalDrag
6773
+ }),
6774
+ nativeEvent: event.nativeEvent,
6775
+ defaultActionCallback: event.type === "behavior event" ? event.defaultActionCallback : void 0
6593
6776
  });
6594
- let behaviorOverwritten = !1;
6595
- for (const eventBehavior of eventBehaviors) {
6596
- const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
6597
- context: editorSnapshot.context,
6598
- snapshot: editorSnapshot,
6599
- event: event.behaviorEvent
6600
- });
6601
- if (!shouldRun)
6602
- continue;
6603
- const actionSets = eventBehavior.actions.map((actionSet) => actionSet({
6604
- context: editorSnapshot.context,
6605
- snapshot: editorSnapshot,
6606
- event: event.behaviorEvent
6607
- }, shouldRun));
6608
- for (const actionSet of actionSets)
6609
- actionSet.length !== 0 && (behaviorOverwritten = behaviorOverwritten || actionSet.some((action) => action.type !== "effect"), withApplyingBehaviorActionSet(event.editor, () => {
6610
- for (const action of actionSet) {
6611
- if (action.type === "raise") {
6612
- isCustomBehaviorEvent(action.event) ? enqueue.raise({
6613
- type: "custom behavior event",
6614
- behaviorEvent: action.event,
6615
- editor: event.editor
6616
- }) : enqueue.raise({
6617
- type: "behavior event",
6618
- behaviorEvent: action.event,
6619
- editor: event.editor
6620
- });
6621
- continue;
6622
- }
6623
- const internalAction = {
6624
- ...action,
6625
- editor: event.editor
6626
- };
6627
- try {
6628
- performAction({
6629
- context: {
6630
- keyGenerator: context.keyGenerator,
6631
- schema: context.schema
6632
- },
6633
- action: internalAction
6634
- });
6635
- } catch (error) {
6636
- console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`));
6637
- break;
6638
- }
6639
- }
6640
- }), event.editor.onChange());
6641
- if (behaviorOverwritten) {
6642
- event.nativeEvent?.preventDefault();
6643
- break;
6644
- }
6645
- }
6646
- if (!behaviorOverwritten) {
6647
- if (defaultActionCallback) {
6648
- withApplyingBehaviorActions(event.editor, () => {
6649
- try {
6650
- defaultActionCallback();
6651
- } catch (error) {
6652
- console.error(new Error(`Performing "${event.behaviorEvent.type}" failed due to: ${error.message}`));
6653
- }
6654
- });
6655
- return;
6656
- }
6657
- if (!defaultAction)
6658
- return;
6659
- withApplyingBehaviorActions(event.editor, () => {
6660
- try {
6661
- performAction({
6662
- context: {
6663
- keyGenerator: context.keyGenerator,
6664
- schema: context.schema
6665
- },
6666
- action: defaultAction
6667
- });
6668
- } catch (error) {
6669
- console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`));
6670
- }
6671
- }), event.editor.onChange();
6672
- }
6673
- })
6777
+ }
6674
6778
  }
6675
6779
  }).createMachine({
6676
6780
  id: "editor",