@portabletext/editor 1.30.6 → 1.31.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 (65) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +35 -2
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +4 -4
  4. package/lib/_chunks-cjs/plugin.event-listener.cjs +143 -170
  5. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
  6. package/lib/_chunks-cjs/selector.get-text-before.cjs +5 -41
  7. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  8. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +174 -6
  9. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  10. package/lib/_chunks-cjs/util.is-empty-text-block.cjs +1 -58
  11. package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -1
  12. package/lib/_chunks-cjs/util.reverse-selection.cjs +105 -0
  13. package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
  14. package/lib/_chunks-es/behavior.core.js +36 -3
  15. package/lib/_chunks-es/behavior.core.js.map +1 -1
  16. package/lib/_chunks-es/behavior.markdown.js +2 -1
  17. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  18. package/lib/_chunks-es/plugin.event-listener.js +143 -170
  19. package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
  20. package/lib/_chunks-es/selector.get-text-before.js +4 -41
  21. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  22. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +170 -2
  23. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  24. package/lib/_chunks-es/util.is-empty-text-block.js +1 -59
  25. package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -1
  26. package/lib/_chunks-es/util.reverse-selection.js +106 -1
  27. package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
  28. package/lib/index.d.cts +0 -4
  29. package/lib/index.d.ts +0 -4
  30. package/lib/plugins/index.cjs +8 -8
  31. package/lib/plugins/index.cjs.map +1 -1
  32. package/lib/plugins/index.d.cts +0 -4
  33. package/lib/plugins/index.d.ts +0 -4
  34. package/lib/plugins/index.js +2 -3
  35. package/lib/plugins/index.js.map +1 -1
  36. package/lib/selectors/index.cjs +33 -6
  37. package/lib/selectors/index.cjs.map +1 -1
  38. package/lib/selectors/index.d.cts +209 -0
  39. package/lib/selectors/index.d.ts +209 -0
  40. package/lib/selectors/index.js +31 -5
  41. package/lib/selectors/index.js.map +1 -1
  42. package/lib/utils/index.cjs +10 -13
  43. package/lib/utils/index.cjs.map +1 -1
  44. package/lib/utils/index.js +3 -6
  45. package/lib/utils/index.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/behaviors/behavior.core.annotations.ts +32 -0
  48. package/src/behaviors/behavior.core.ts +1 -0
  49. package/src/editor/plugins/createWithEditableAPI.ts +1 -2
  50. package/src/editor/plugins/createWithUtils.ts +1 -52
  51. package/src/selectors/index.ts +4 -0
  52. package/src/selectors/selector.get-block-offsets.ts +33 -0
  53. package/src/selectors/selector.get-caret-word-selection.test.ts +288 -0
  54. package/src/selectors/selector.get-caret-word-selection.ts +116 -0
  55. package/src/selectors/selector.get-next-inline-object.ts +56 -0
  56. package/src/selectors/selector.get-previous-inline-object.ts +53 -0
  57. package/src/types/editor.ts +0 -5
  58. package/lib/_chunks-cjs/selector.get-selection-start-point.cjs +0 -15
  59. package/lib/_chunks-cjs/selector.get-selection-start-point.cjs.map +0 -1
  60. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +0 -46
  61. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +0 -1
  62. package/lib/_chunks-es/selector.get-selection-start-point.js +0 -16
  63. package/lib/_chunks-es/selector.get-selection-start-point.js.map +0 -1
  64. package/lib/_chunks-es/util.is-equal-selection-points.js +0 -47
  65. package/lib/_chunks-es/util.is-equal-selection-points.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
- var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), jsxRuntime = require("react/jsx-runtime"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$f = require("debug"), slate = require("slate"), xstate = require("xstate"), isEqual = require("lodash/isEqual.js"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), parseBlocks = require("./parse-blocks.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"), startCase = require("lodash.startcase"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), util_isEmptyTextBlock = require("./util.is-empty-text-block.cjs"), behavior_core = require("./behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), rxjs = require("rxjs");
2
+ var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), jsxRuntime = require("react/jsx-runtime"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$e = require("debug"), slate = require("slate"), xstate = require("xstate"), isEqual = require("lodash/isEqual.js"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), parseBlocks = require("./parse-blocks.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"), startCase = require("lodash.startcase"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), util_reverseSelection = require("./util.reverse-selection.cjs"), behavior_core = require("./behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), rxjs = require("rxjs");
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$f), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
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), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
7
7
  function createEditorSchema(portableTextType) {
8
8
  if (!portableTextType)
9
9
  throw new Error("Parameter 'portabletextType' missing (required)");
@@ -1391,7 +1391,7 @@ function isRedoing(editor) {
1391
1391
  function setIsRedoing(editor, isRedoing2) {
1392
1392
  IS_REDOING.set(editor, isRedoing2);
1393
1393
  }
1394
- const debug$e = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1394
+ const debug$d = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1395
1395
  const state = SAVING.get(editor);
1396
1396
  return state === void 0 ? !0 : state;
1397
1397
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
@@ -1404,7 +1404,7 @@ function createWithUndoRedo(options) {
1404
1404
  let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
1405
1405
  const remotePatches = getRemotePatches(editor);
1406
1406
  options.subscriptions.push(() => {
1407
- debug$e("Subscribing to patches");
1407
+ debug$d("Subscribing to patches");
1408
1408
  const sub = editorActor.on("patches", ({
1409
1409
  patches: patches2,
1410
1410
  snapshot
@@ -1413,7 +1413,7 @@ function createWithUndoRedo(options) {
1413
1413
  patches2.forEach((patch) => {
1414
1414
  if (!reset && patch.origin !== "local" && remotePatches) {
1415
1415
  if (patch.type === "unset" && patch.path.length === 0) {
1416
- debug$e("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1416
+ debug$d("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1417
1417
  undos: [],
1418
1418
  redos: []
1419
1419
  }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
@@ -1429,7 +1429,7 @@ function createWithUndoRedo(options) {
1429
1429
  }), previousSnapshot = snapshot;
1430
1430
  });
1431
1431
  return () => {
1432
- debug$e("Unsubscribing to patches"), sub.unsubscribe();
1432
+ debug$d("Unsubscribing to patches"), sub.unsubscribe();
1433
1433
  };
1434
1434
  }), editor.history = {
1435
1435
  undos: [],
@@ -1468,7 +1468,7 @@ function createWithUndoRedo(options) {
1468
1468
  operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
1469
1469
  timestamp: /* @__PURE__ */ new Date()
1470
1470
  };
1471
- undos.push(newStep), debug$e("Created new undo step", step);
1471
+ undos.push(newStep), debug$d("Created new undo step", step);
1472
1472
  }
1473
1473
  for (; undos.length > UNDO_STEP_LIMIT; )
1474
1474
  undos.shift();
@@ -1485,7 +1485,7 @@ function createWithUndoRedo(options) {
1485
1485
  } = editor.history;
1486
1486
  if (undos.length > 0) {
1487
1487
  const step = undos[undos.length - 1];
1488
- if (debug$e("Undoing", step), step.operations.length > 0) {
1488
+ if (debug$d("Undoing", step), step.operations.length > 0) {
1489
1489
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
1490
1490
  let transformedOperations = step.operations;
1491
1491
  otherPatches.forEach((item) => {
@@ -1503,7 +1503,7 @@ function createWithUndoRedo(options) {
1503
1503
  });
1504
1504
  }), editor.normalize(), editor.onChange();
1505
1505
  } catch (err) {
1506
- debug$e("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1506
+ debug$d("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1507
1507
  undos: [],
1508
1508
  redos: []
1509
1509
  }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
@@ -1522,7 +1522,7 @@ function createWithUndoRedo(options) {
1522
1522
  } = editor.history;
1523
1523
  if (redos.length > 0) {
1524
1524
  const step = redos[redos.length - 1];
1525
- if (debug$e("Redoing", step), step.operations.length > 0) {
1525
+ if (debug$d("Redoing", step), step.operations.length > 0) {
1526
1526
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
1527
1527
  let transformedOperations = step.operations;
1528
1528
  otherPatches.forEach((item) => {
@@ -1539,7 +1539,7 @@ function createWithUndoRedo(options) {
1539
1539
  });
1540
1540
  }), editor.normalize(), editor.onChange();
1541
1541
  } catch (err) {
1542
- debug$e("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1542
+ debug$d("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1543
1543
  undos: [],
1544
1544
  redos: []
1545
1545
  }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
@@ -1559,16 +1559,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
1559
1559
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
1560
1560
  _key: blk._key
1561
1561
  }, patch.path[0]));
1562
- return debug$e(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
1562
+ return debug$d(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
1563
1563
  }
1564
1564
  if (patch.type === "unset" && patch.path.length === 1) {
1565
1565
  const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
1566
1566
  _key: blk._key
1567
1567
  }, patch.path[0]));
1568
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$e("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
1568
+ return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$d("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
1569
1569
  }
1570
1570
  if (patch.type === "unset" && patch.path.length === 0)
1571
- return debug$e(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
1571
+ return debug$d(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
1572
1572
  if (patch.type === "diffMatchPatch") {
1573
1573
  const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
1574
1574
  return !operationTargetBlock || !isEqual__default.default({
@@ -1655,7 +1655,7 @@ function findOperationTargetBlock(editor, operation) {
1655
1655
  let block;
1656
1656
  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;
1657
1657
  }
1658
- const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1658
+ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
1659
1659
  sendBack,
1660
1660
  input
1661
1661
  }) => {
@@ -1707,7 +1707,7 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1707
1707
  context
1708
1708
  }) => {
1709
1709
  const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
1710
- return debug$d("isBusy", {
1710
+ return debug$c("isBusy", {
1711
1711
  isBusy,
1712
1712
  editable,
1713
1713
  isProcessingLocalChanges,
@@ -1761,10 +1761,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1761
1761
  states: {
1762
1762
  "syncing initial value": {
1763
1763
  entry: [() => {
1764
- debug$d("entry: syncing initial value");
1764
+ debug$c("entry: syncing initial value");
1765
1765
  }],
1766
1766
  exit: [() => {
1767
- debug$d("exit: syncing initial value");
1767
+ debug$c("exit: syncing initial value");
1768
1768
  }],
1769
1769
  always: {
1770
1770
  guard: "initial value synced",
@@ -1773,10 +1773,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1773
1773
  },
1774
1774
  "done syncing initial value": {
1775
1775
  entry: ["emit done syncing initial value", () => {
1776
- debug$d("entry: done syncing initial value");
1776
+ debug$c("entry: done syncing initial value");
1777
1777
  }],
1778
1778
  exit: [() => {
1779
- debug$d("exit: done syncing initial value");
1779
+ debug$c("exit: done syncing initial value");
1780
1780
  }],
1781
1781
  type: "final"
1782
1782
  }
@@ -1787,10 +1787,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1787
1787
  states: {
1788
1788
  idle: {
1789
1789
  entry: [() => {
1790
- debug$d("entry: syncing->idle");
1790
+ debug$c("entry: syncing->idle");
1791
1791
  }],
1792
1792
  exit: [() => {
1793
- debug$d("exit: syncing->idle");
1793
+ debug$c("exit: syncing->idle");
1794
1794
  }],
1795
1795
  on: {
1796
1796
  "update value": [{
@@ -1805,10 +1805,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1805
1805
  },
1806
1806
  busy: {
1807
1807
  entry: [() => {
1808
- debug$d("entry: syncing->busy");
1808
+ debug$c("entry: syncing->busy");
1809
1809
  }],
1810
1810
  exit: [() => {
1811
- debug$d("exit: syncing->busy");
1811
+ debug$c("exit: syncing->busy");
1812
1812
  }],
1813
1813
  after: {
1814
1814
  1e3: [{
@@ -1816,7 +1816,7 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1816
1816
  target: ".",
1817
1817
  reenter: !0,
1818
1818
  actions: [() => {
1819
- debug$d("reenter: syncing->busy");
1819
+ debug$c("reenter: syncing->busy");
1820
1820
  }]
1821
1821
  }, {
1822
1822
  target: "syncing"
@@ -1830,10 +1830,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1830
1830
  },
1831
1831
  syncing: {
1832
1832
  entry: [() => {
1833
- debug$d("entry: syncing->syncing");
1833
+ debug$c("entry: syncing->syncing");
1834
1834
  }],
1835
1835
  exit: [() => {
1836
- debug$d("exit: syncing->syncing");
1836
+ debug$c("exit: syncing->syncing");
1837
1837
  }],
1838
1838
  always: {
1839
1839
  guard: "pending value equals previous value",
@@ -1899,7 +1899,7 @@ async function updateValue({
1899
1899
  }) {
1900
1900
  let isChanged = !1, isValid = !0;
1901
1901
  const hadSelection = !!slateEditor.selection;
1902
- if ((!value || value.length === 0) && (debug$d("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
1902
+ if ((!value || value.length === 0) && (debug$c("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
1903
1903
  withoutSaving(slateEditor, () => {
1904
1904
  withoutPatching(slateEditor, () => {
1905
1905
  hadSelection && slate.Transforms.deselect(slateEditor);
@@ -1955,14 +1955,14 @@ async function updateValue({
1955
1955
  });
1956
1956
  }
1957
1957
  if (!isValid) {
1958
- debug$d("Invalid value, returning"), sendBack({
1958
+ debug$c("Invalid value, returning"), sendBack({
1959
1959
  type: "done syncing",
1960
1960
  value
1961
1961
  });
1962
1962
  return;
1963
1963
  }
1964
1964
  if (isChanged) {
1965
- debug$d("Server value changed, syncing editor");
1965
+ debug$c("Server value changed, syncing editor");
1966
1966
  try {
1967
1967
  slateEditor.onChange();
1968
1968
  } catch (err) {
@@ -1990,7 +1990,7 @@ async function updateValue({
1990
1990
  value
1991
1991
  });
1992
1992
  } else
1993
- debug$d("Server value and editor value is equal, no need to sync.");
1993
+ debug$c("Server value and editor value is equal, no need to sync.");
1994
1994
  sendBack({
1995
1995
  type: "done syncing",
1996
1996
  value
@@ -2024,7 +2024,7 @@ function syncBlock({
2024
2024
  type: "patch",
2025
2025
  patch
2026
2026
  });
2027
- })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$d.enabled && debug$d("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$d.enabled && debug$d("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
2027
+ })), 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({
2028
2028
  type: "invalid value",
2029
2029
  resolution: validation.resolution,
2030
2030
  value
@@ -2032,9 +2032,9 @@ function syncBlock({
2032
2032
  }
2033
2033
  if (!oldBlock && blockValid) {
2034
2034
  const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
2035
- debug$d.enabled && debug$d("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
2035
+ 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, {
2036
2036
  at: [currentBlockIndex]
2037
- }) : (debug$d("Invalid", validation), sendBack({
2037
+ }) : (debug$c("Invalid", validation), sendBack({
2038
2038
  type: "invalid value",
2039
2039
  resolution: validation.resolution,
2040
2040
  value
@@ -2062,14 +2062,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2062
2062
  const oldBlockChildrenLength = oldBlock.children.length;
2063
2063
  currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
2064
2064
  const childIndex = oldBlockChildrenLength - 1 - index;
2065
- childIndex > 0 && (debug$d("Removing child"), slate.Transforms.removeNodes(slateEditor, {
2065
+ childIndex > 0 && (debug$c("Removing child"), slate.Transforms.removeNodes(slateEditor, {
2066
2066
  at: [currentBlockIndex, childIndex]
2067
2067
  }));
2068
2068
  }), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
2069
2069
  const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
2070
2070
  if (isChildChanged)
2071
2071
  if (currentBlockChild._key === oldBlockChild?._key) {
2072
- debug$d("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
2072
+ debug$c("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
2073
2073
  at: path
2074
2074
  });
2075
2075
  const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
@@ -2086,23 +2086,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2086
2086
  }
2087
2087
  }), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
2088
2088
  at: path
2089
- }), slateEditor.onChange()) : isSpanNode || (debug$d("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
2089
+ }), slateEditor.onChange()) : isSpanNode || (debug$c("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
2090
2090
  _key: VOID_CHILD_KEY
2091
2091
  }, {
2092
2092
  at: [...path, 0],
2093
2093
  voids: !0
2094
2094
  }));
2095
- } else oldBlockChild ? (debug$d("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
2095
+ } else oldBlockChild ? (debug$c("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
2096
2096
  at: [currentBlockIndex, currentBlockChildIndex]
2097
2097
  }), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2098
2098
  at: [currentBlockIndex, currentBlockChildIndex]
2099
- }), slateEditor.onChange()) : oldBlockChild || (debug$d("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2099
+ }), slateEditor.onChange()) : oldBlockChild || (debug$c("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2100
2100
  at: [currentBlockIndex, currentBlockChildIndex]
2101
2101
  }), slateEditor.onChange());
2102
2102
  });
2103
2103
  }
2104
2104
  }
2105
- const debug$c = debugWithName("component:PortableTextEditor:Synchronizer");
2105
+ const debug$b = debugWithName("component:PortableTextEditor:Synchronizer");
2106
2106
  function Synchronizer(props) {
2107
2107
  const $ = reactCompilerRuntime.c(40), {
2108
2108
  editorActor,
@@ -2190,19 +2190,19 @@ function Synchronizer(props) {
2190
2190
  }, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), React.useEffect(t11, t12);
2191
2191
  let t13, t14;
2192
2192
  $[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
2193
- debug$c("Value from props changed, syncing new value"), syncActorRef.send({
2193
+ debug$b("Value from props changed, syncing new value"), syncActorRef.send({
2194
2194
  type: "update value",
2195
2195
  value
2196
2196
  });
2197
2197
  }, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), React.useEffect(t13, t14);
2198
2198
  let t15;
2199
2199
  $[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
2200
- debug$c("Subscribing to patch events");
2200
+ debug$b("Subscribing to patch events");
2201
2201
  const sub = editorActor.on("patch", (event_1) => {
2202
2202
  mutationActorRef.send(event_1);
2203
2203
  });
2204
2204
  return () => {
2205
- debug$c("Unsubscribing to patch events"), sub.unsubscribe();
2205
+ debug$b("Unsubscribing to patch events"), sub.unsubscribe();
2206
2206
  };
2207
2207
  }, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
2208
2208
  let t16;
@@ -2404,11 +2404,11 @@ const converterJson = {
2404
2404
  function escapeHtml(str) {
2405
2405
  return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
2406
2406
  }
2407
- const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$b = debugWithName("operationToPatches");
2407
+ const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$a = debugWithName("operationToPatches");
2408
2408
  function createOperationToPatches(types2) {
2409
2409
  const textBlockName = types2.block.name;
2410
2410
  function insertTextPatch(editor, operation, beforeValue) {
2411
- debug$b.enabled && debug$b("Operation", JSON.stringify(operation, null, 2));
2411
+ debug$a.enabled && debug$a("Operation", JSON.stringify(operation, null, 2));
2412
2412
  const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
2413
2413
  if (!block)
2414
2414
  throw new Error("Could not find block");
@@ -2501,7 +2501,7 @@ function createOperationToPatches(types2) {
2501
2501
  _key: block.children[operation.path[1] - 1]._key
2502
2502
  }])];
2503
2503
  }
2504
- return debug$b("Something was inserted into a void block. Not producing editor patches."), [];
2504
+ return debug$a("Something was inserted into a void block. Not producing editor patches."), [];
2505
2505
  }
2506
2506
  function splitNodePatch(editor, operation, beforeValue) {
2507
2507
  const patches$1 = [], splitBlock = editor.children[operation.path[0]];
@@ -2559,9 +2559,9 @@ function createOperationToPatches(types2) {
2559
2559
  _key: block._key
2560
2560
  }, "children", {
2561
2561
  _key: spanToRemove._key
2562
- }])] : (debug$b("Span not found in editor trying to remove node"), []);
2562
+ }])] : (debug$a("Span not found in editor trying to remove node"), []);
2563
2563
  } else
2564
- return debug$b("Not creating patch inside object block"), [];
2564
+ return debug$a("Not creating patch inside object block"), [];
2565
2565
  }
2566
2566
  function mergeNodePatch(editor, operation, beforeValue) {
2567
2567
  const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
@@ -2587,7 +2587,7 @@ function createOperationToPatches(types2) {
2587
2587
  _key: removedSpan._key
2588
2588
  }])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
2589
2589
  } else
2590
- debug$b("Void nodes can't be merged, not creating any patches");
2590
+ debug$a("Void nodes can't be merged, not creating any patches");
2591
2591
  return patches$1;
2592
2592
  }
2593
2593
  function moveNodePatch(editor, operation, beforeValue) {
@@ -2977,13 +2977,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
2977
2977
  }, editor;
2978
2978
  };
2979
2979
  }
2980
- const debug$a = debugWithName("applyPatches"), debugVerbose = debug$a.enabled && !0;
2980
+ const debug$9 = debugWithName("applyPatches"), debugVerbose = debug$9.enabled && !0;
2981
2981
  function createApplyPatch(schemaTypes) {
2982
2982
  return (editor, patch) => {
2983
2983
  let changed = !1;
2984
- debugVerbose && (debug$a(`
2984
+ debugVerbose && (debug$9(`
2985
2985
 
2986
- NEW PATCH =============================================================`), debug$a(JSON.stringify(patch, null, 2)));
2986
+ NEW PATCH =============================================================`), debug$9(JSON.stringify(patch, null, 2)));
2987
2987
  try {
2988
2988
  switch (patch.type) {
2989
2989
  case "insert":
@@ -2999,7 +2999,7 @@ NEW PATCH =============================================================`), debug
2999
2999
  changed = diffMatchPatch(editor, patch);
3000
3000
  break;
3001
3001
  default:
3002
- debug$a("Unhandled patch", patch.type);
3002
+ debug$9("Unhandled patch", patch.type);
3003
3003
  }
3004
3004
  } catch (err) {
3005
3005
  console.error(err);
@@ -3014,9 +3014,9 @@ function diffMatchPatch(editor, patch) {
3014
3014
  childPath
3015
3015
  } = findBlockAndChildFromPath(editor, patch.path);
3016
3016
  if (!block)
3017
- return debug$a("Block not found"), !1;
3017
+ return debug$9("Block not found"), !1;
3018
3018
  if (!child || !childPath)
3019
- return debug$a("Child not found"), !1;
3019
+ return debug$9("Child not found"), !1;
3020
3020
  if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
3021
3021
  return !1;
3022
3022
  const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
@@ -3046,9 +3046,9 @@ function insertPatch(editor, patch, schemaTypes) {
3046
3046
  childPath: targetChildPath
3047
3047
  } = findBlockAndChildFromPath(editor, patch.path);
3048
3048
  if (!targetBlock || !targetBlockPath)
3049
- return debug$a("Block not found"), !1;
3049
+ return debug$9("Block not found"), !1;
3050
3050
  if (patch.path.length > 1 && patch.path[1] !== "children")
3051
- return debug$a("Ignoring patch targeting void value"), !1;
3051
+ return debug$9("Ignoring patch targeting void value"), !1;
3052
3052
  if (patch.path.length === 1) {
3053
3053
  const {
3054
3054
  items: items2,
@@ -3056,7 +3056,7 @@ function insertPatch(editor, patch, schemaTypes) {
3056
3056
  } = patch, blocksToInsert = toSlateValue(items2, {
3057
3057
  schemaTypes
3058
3058
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
3059
- return debug$a(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
3059
+ return debug$9(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
3060
3060
  at: [normalizedIdx2]
3061
3061
  }), debugState(editor, "after"), !0;
3062
3062
  }
@@ -3065,14 +3065,14 @@ function insertPatch(editor, patch, schemaTypes) {
3065
3065
  position
3066
3066
  } = patch;
3067
3067
  if (!targetChild || !targetChildPath)
3068
- return debug$a("Child not found"), !1;
3068
+ return debug$9("Child not found"), !1;
3069
3069
  const childrenToInsert = targetBlock && toSlateValue([{
3070
3070
  ...targetBlock,
3071
3071
  children: items
3072
3072
  }], {
3073
3073
  schemaTypes
3074
3074
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
3075
- return debug$a(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
3075
+ return debug$9(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
3076
3076
  at: childInsertPath
3077
3077
  }), debugState(editor, "after"), !0;
3078
3078
  }
@@ -3086,14 +3086,14 @@ function setPatch(editor, patch) {
3086
3086
  childPath
3087
3087
  } = findBlockAndChildFromPath(editor, patch.path);
3088
3088
  if (!block)
3089
- return debug$a("Block not found"), !1;
3089
+ return debug$9("Block not found"), !1;
3090
3090
  const isTextBlock = editor.isTextBlock(block);
3091
3091
  if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
3092
- return debug$a("Ignoring setting void value"), !1;
3092
+ return debug$9("Ignoring setting void value"), !1;
3093
3093
  if (debugState(editor, "before"), isTextBlock && child && childPath) {
3094
3094
  if (slate.Text.isText(value) && slate.Text.isText(child)) {
3095
3095
  const newText = child.text;
3096
- value.text !== newText && (debug$a("Setting text property"), editor.apply({
3096
+ value.text !== newText && (debug$9("Setting text property"), editor.apply({
3097
3097
  type: "remove_text",
3098
3098
  path: childPath,
3099
3099
  offset: 0,
@@ -3105,7 +3105,7 @@ function setPatch(editor, patch) {
3105
3105
  text: value.text
3106
3106
  }), editor.onChange());
3107
3107
  } else
3108
- debug$a("Setting non-text property"), editor.apply({
3108
+ debug$9("Setting non-text property"), editor.apply({
3109
3109
  type: "set_node",
3110
3110
  path: childPath,
3111
3111
  properties: {},
@@ -3113,7 +3113,7 @@ function setPatch(editor, patch) {
3113
3113
  });
3114
3114
  return !0;
3115
3115
  } else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
3116
- debug$a("Setting block property");
3116
+ debug$9("Setting block property");
3117
3117
  const {
3118
3118
  children,
3119
3119
  ...nextRest
@@ -3130,7 +3130,7 @@ function setPatch(editor, patch) {
3130
3130
  ...prevRest
3131
3131
  },
3132
3132
  newProperties: nextRest
3133
- }), debug$a("Setting children"), block.children.forEach((c, cIndex) => {
3133
+ }), debug$9("Setting children"), block.children.forEach((c, cIndex) => {
3134
3134
  editor.apply({
3135
3135
  type: "remove_node",
3136
3136
  path: blockPath.concat(block.children.length - 1 - cIndex),
@@ -3161,7 +3161,7 @@ function setPatch(editor, patch) {
3161
3161
  }
3162
3162
  function unsetPatch(editor, patch) {
3163
3163
  if (patch.path.length === 0) {
3164
- debug$a("Removing everything"), debugState(editor, "before");
3164
+ debug$9("Removing everything"), debugState(editor, "before");
3165
3165
  const previousSelection = editor.selection;
3166
3166
  return slate.Transforms.deselect(editor), editor.children.forEach((_child, i) => {
3167
3167
  slate.Transforms.removeNodes(editor, {
@@ -3188,13 +3188,13 @@ function unsetPatch(editor, patch) {
3188
3188
  } = findBlockAndChildFromPath(editor, patch.path);
3189
3189
  if (patch.path.length === 1) {
3190
3190
  if (!block || !blockPath)
3191
- return debug$a("Block not found"), !1;
3191
+ return debug$9("Block not found"), !1;
3192
3192
  const blockIndex = blockPath[0];
3193
- return debug$a(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
3193
+ return debug$9(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
3194
3194
  at: [blockIndex]
3195
3195
  }), debugState(editor, "after"), !0;
3196
3196
  }
3197
- return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$a("Child not found"), !1) : (debug$a(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$a(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
3197
+ return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$9("Child not found"), !1) : (debug$9(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$9(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
3198
3198
  at: childPath
3199
3199
  }), debugState(editor, "after"), !0) : !1;
3200
3200
  }
@@ -3202,7 +3202,7 @@ function isKeyedSegment(segment) {
3202
3202
  return typeof segment == "object" && "_key" in segment;
3203
3203
  }
3204
3204
  function debugState(editor, stateName) {
3205
- debugVerbose && (debug$a(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$a(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
3205
+ debugVerbose && (debug$9(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$9(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
3206
3206
  }
3207
3207
  function findBlockFromPath(editor, path) {
3208
3208
  let blockIndex = -1;
@@ -3244,7 +3244,7 @@ function findBlockAndChildFromPath(editor, path) {
3244
3244
  childPath: void 0
3245
3245
  };
3246
3246
  }
3247
- const debug$9 = debugWithName("plugin:withPatches");
3247
+ const debug$8 = debugWithName("plugin:withPatches");
3248
3248
  function createWithPatches({
3249
3249
  editorActor,
3250
3250
  patchFunctions,
@@ -3270,7 +3270,7 @@ function createWithPatches({
3270
3270
  withoutPatching(editor, () => {
3271
3271
  withoutSaving(editor, () => {
3272
3272
  patches2.forEach((patch) => {
3273
- debug$9.enabled && debug$9(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
3273
+ debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
3274
3274
  });
3275
3275
  });
3276
3276
  });
@@ -3283,10 +3283,10 @@ function createWithPatches({
3283
3283
  remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
3284
3284
  };
3285
3285
  return subscriptions.push(() => {
3286
- debug$9("Subscribing to remote patches");
3286
+ debug$8("Subscribing to remote patches");
3287
3287
  const sub = editorActor.on("patches", handlePatches);
3288
3288
  return () => {
3289
- debug$9("Unsubscribing to remote patches"), sub.unsubscribe();
3289
+ debug$8("Unsubscribing to remote patches"), sub.unsubscribe();
3290
3290
  };
3291
3291
  }), editor.apply = (operation) => {
3292
3292
  let patches$1 = [];
@@ -3337,7 +3337,7 @@ function createWithPatches({
3337
3337
  }, editor;
3338
3338
  };
3339
3339
  }
3340
- const debug$8 = debugWithName("plugin:withPlaceholderBlock");
3340
+ const debug$7 = debugWithName("plugin:withPlaceholderBlock");
3341
3341
  function createWithPlaceholderBlock(editorActor) {
3342
3342
  return function(editor) {
3343
3343
  const {
@@ -3362,7 +3362,7 @@ function createWithPlaceholderBlock(editorActor) {
3362
3362
  const node = op.node;
3363
3363
  if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
3364
3364
  const nextPath = slate.Path.next(op.path);
3365
- editor.children[nextPath[0]] || (debug$8("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
3365
+ editor.children[nextPath[0]] || (debug$7("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
3366
3366
  decorators: []
3367
3367
  })));
3368
3368
  }
@@ -3371,7 +3371,7 @@ function createWithPlaceholderBlock(editorActor) {
3371
3371
  }, editor;
3372
3372
  };
3373
3373
  }
3374
- const debug$7 = debugWithName("plugin:withPortableTextBlockStyle");
3374
+ const debug$6 = debugWithName("plugin:withPortableTextBlockStyle");
3375
3375
  function createWithPortableTextBlockStyle(editorActor, types2) {
3376
3376
  const defaultStyle = types2.styles[0].value;
3377
3377
  return function(editor) {
@@ -3384,7 +3384,7 @@ function createWithPortableTextBlockStyle(editorActor, types2) {
3384
3384
  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)) {
3385
3385
  const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
3386
3386
  if (slate.Text.isText(child) && child.text === "") {
3387
- debug$7(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
3387
+ debug$6(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
3388
3388
  type: "normalizing"
3389
3389
  }), slate.Transforms.setNodes(editor, {
3390
3390
  style: defaultStyle
@@ -3444,7 +3444,7 @@ function getNextSpan({
3444
3444
  }
3445
3445
  return nextSpan;
3446
3446
  }
3447
- const debug$6 = debugWithName("plugin:withPortableTextMarkModel");
3447
+ const debug$5 = debugWithName("plugin:withPortableTextMarkModel");
3448
3448
  function createWithPortableTextMarkModel(editorActor, types2) {
3449
3449
  return function(editor) {
3450
3450
  const {
@@ -3458,7 +3458,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3458
3458
  for (const [child, childPath] of children) {
3459
3459
  const nextNode = node.children[childPath[1] + 1];
3460
3460
  if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
3461
- debug$6("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3461
+ debug$5("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3462
3462
  type: "normalizing"
3463
3463
  }), slate.Transforms.mergeNodes(editor, {
3464
3464
  at: [childPath[0], childPath[1] + 1],
@@ -3471,7 +3471,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3471
3471
  }
3472
3472
  }
3473
3473
  if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
3474
- debug$6("Adding .markDefs to block node"), editorActor.send({
3474
+ debug$5("Adding .markDefs to block node"), editorActor.send({
3475
3475
  type: "normalizing"
3476
3476
  }), slate.Transforms.setNodes(editor, {
3477
3477
  markDefs: []
@@ -3483,7 +3483,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3483
3483
  return;
3484
3484
  }
3485
3485
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
3486
- debug$6("Adding .marks to span node"), editorActor.send({
3486
+ debug$5("Adding .marks to span node"), editorActor.send({
3487
3487
  type: "normalizing"
3488
3488
  }), slate.Transforms.setNodes(editor, {
3489
3489
  marks: []
@@ -3497,7 +3497,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3497
3497
  if (editor.isTextSpan(node)) {
3498
3498
  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));
3499
3499
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
3500
- debug$6("Removing annotations from empty span node"), editorActor.send({
3500
+ debug$5("Removing annotations from empty span node"), editorActor.send({
3501
3501
  type: "normalizing"
3502
3502
  }), slate.Transforms.setNodes(editor, {
3503
3503
  marks: node.marks?.filter((mark) => decorators2.includes(mark))
@@ -3515,7 +3515,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3515
3515
  if (editor.isTextSpan(child)) {
3516
3516
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
3517
3517
  if (orphanedAnnotations.length > 0) {
3518
- debug$6("Removing orphaned annotations from span node"), editorActor.send({
3518
+ debug$5("Removing orphaned annotations from span node"), editorActor.send({
3519
3519
  type: "normalizing"
3520
3520
  }), slate.Transforms.setNodes(editor, {
3521
3521
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3533,7 +3533,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3533
3533
  if (editor.isTextBlock(block)) {
3534
3534
  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));
3535
3535
  if (orphanedAnnotations.length > 0) {
3536
- debug$6("Removing orphaned annotations from span node"), editorActor.send({
3536
+ debug$5("Removing orphaned annotations from span node"), editorActor.send({
3537
3537
  type: "normalizing"
3538
3538
  }), slate.Transforms.setNodes(editor, {
3539
3539
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3551,7 +3551,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3551
3551
  for (const markDef of markDefs)
3552
3552
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
3553
3553
  if (markDefs.length !== newMarkDefs.length) {
3554
- debug$6("Removing duplicate markDefs"), editorActor.send({
3554
+ debug$5("Removing duplicate markDefs"), editorActor.send({
3555
3555
  type: "normalizing"
3556
3556
  }), slate.Transforms.setNodes(editor, {
3557
3557
  markDefs: newMarkDefs
@@ -3566,7 +3566,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3566
3566
  if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
3567
3567
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
3568
3568
  if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
3569
- debug$6("Removing markDef not in use"), editorActor.send({
3569
+ debug$5("Removing markDef not in use"), editorActor.send({
3570
3570
  type: "normalizing"
3571
3571
  }), slate.Transforms.setNodes(editor, {
3572
3572
  markDefs: newMarkDefs
@@ -3786,7 +3786,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3786
3786
  const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
3787
3787
  if (editor.isTextBlock(targetBlock)) {
3788
3788
  const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
3789
- debug$6("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
3789
+ debug$5("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
3790
3790
  markDefs: newMarkDefs
3791
3791
  }, {
3792
3792
  at: targetPath,
@@ -3986,7 +3986,7 @@ function createWithPortableTextSelections(editorActor, types2) {
3986
3986
  }, editor;
3987
3987
  };
3988
3988
  }
3989
- const debug$5 = debugWithName("plugin:withSchemaTypes");
3989
+ const debug$4 = debugWithName("plugin:withSchemaTypes");
3990
3990
  function createWithSchemaTypes({
3991
3991
  editorActor,
3992
3992
  schemaTypes
@@ -3999,7 +3999,7 @@ function createWithSchemaTypes({
3999
3999
  return editor.normalizeNode = (entry) => {
4000
4000
  const [node, path] = entry;
4001
4001
  if (node._type === void 0 && path.length === 2) {
4002
- debug$5("Setting span type on text node without a type");
4002
+ debug$4("Setting span type on text node without a type");
4003
4003
  const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
4004
4004
  editorActor.send({
4005
4005
  type: "normalizing"
@@ -4015,7 +4015,7 @@ function createWithSchemaTypes({
4015
4015
  return;
4016
4016
  }
4017
4017
  if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
4018
- debug$5("Setting missing key on child node without a key");
4018
+ debug$4("Setting missing key on child node without a key");
4019
4019
  const key = editorActor.getSnapshot().context.keyGenerator();
4020
4020
  editorActor.send({
4021
4021
  type: "normalizing"
@@ -4032,43 +4032,12 @@ function createWithSchemaTypes({
4032
4032
  }, editor;
4033
4033
  };
4034
4034
  }
4035
- const debug$4 = debugWithName("plugin:withUtils");
4036
4035
  function createWithUtils({
4037
4036
  editorActor,
4038
4037
  schemaTypes
4039
4038
  }) {
4040
4039
  return function(editor) {
4041
- return editor.pteExpandToWord = () => {
4042
- const {
4043
- selection
4044
- } = editor;
4045
- if (selection && !slate.Range.isExpanded(selection)) {
4046
- const [textNode] = slate.Editor.node(editor, selection.focus, {
4047
- depth: 2
4048
- });
4049
- if (!textNode || !slate.Text.isText(textNode) || textNode.text.length === 0) {
4050
- debug$4("pteExpandToWord: Can't expand to word here");
4051
- return;
4052
- }
4053
- const {
4054
- focus
4055
- } = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
4056
- if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
4057
- debug$4("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
4058
- anchor: {
4059
- ...selection.anchor,
4060
- offset: newStartOffset
4061
- },
4062
- focus: {
4063
- ...selection.focus,
4064
- offset: newEndOffset
4065
- }
4066
- });
4067
- return;
4068
- }
4069
- debug$4("pteExpandToWord: Can't expand to word here");
4070
- }
4071
- }, editor.pteCreateTextBlock = (options) => toSlateValue([{
4040
+ return editor.pteCreateTextBlock = (options) => toSlateValue([{
4072
4041
  _type: schemaTypes.block.name,
4073
4042
  _key: editorActor.getSnapshot().context.keyGenerator(),
4074
4043
  style: schemaTypes.styles[0].value || "normal",
@@ -4607,57 +4576,61 @@ const addAnnotationActionImplementation = ({
4607
4576
  selection: originalSelection
4608
4577
  } = editor;
4609
4578
  let paths;
4610
- if (originalSelection && (slate.Range.isCollapsed(originalSelection) && (editor.pteExpandToWord(), editor.onChange()), editor.selection)) {
4611
- let spanPath, markDefPath;
4612
- const markDefPaths = [];
4613
- if (!editor.selection)
4579
+ if (originalSelection) {
4580
+ if (slate.Range.isCollapsed(originalSelection))
4614
4581
  return;
4615
- const selectedBlocks = slate.Editor.nodes(editor, {
4616
- at: editor.selection,
4617
- match: (node) => editor.isTextBlock(node),
4618
- reverse: slate.Range.isBackward(editor.selection)
4619
- });
4620
- for (const [block, blockPath] of selectedBlocks) {
4621
- if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
4622
- continue;
4623
- const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
4624
- markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (slate.Transforms.setNodes(editor, {
4625
- markDefs: [...markDefs, {
4626
- _type: action.annotation.name,
4627
- _key: annotationKey,
4628
- ...action.annotation.value
4629
- }]
4630
- }, {
4631
- at: blockPath
4632
- }), markDefPath = [{
4633
- _key: block._key
4634
- }, "markDefs", {
4635
- _key: annotationKey
4636
- }], slate.Range.isBackward(editor.selection) ? markDefPaths.unshift(markDefPath) : markDefPaths.push(markDefPath)), slate.Transforms.setNodes(editor, {}, {
4637
- match: slate.Text.isText,
4638
- split: !0
4582
+ if (editor.selection) {
4583
+ let spanPath, markDefPath;
4584
+ const markDefPaths = [];
4585
+ if (!editor.selection)
4586
+ return;
4587
+ const selectedBlocks = slate.Editor.nodes(editor, {
4588
+ at: editor.selection,
4589
+ match: (node) => editor.isTextBlock(node),
4590
+ reverse: slate.Range.isBackward(editor.selection)
4639
4591
  });
4640
- const children = slate.Node.children(editor, blockPath);
4641
- for (const [span, path] of children) {
4642
- if (!editor.isTextSpan(span) || !slate.Range.includes(editor.selection, path))
4592
+ for (const [block, blockPath] of selectedBlocks) {
4593
+ if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
4643
4594
  continue;
4644
- const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
4645
- slate.Transforms.setNodes(editor, {
4646
- marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
4595
+ const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
4596
+ markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (slate.Transforms.setNodes(editor, {
4597
+ markDefs: [...markDefs, {
4598
+ _type: action.annotation.name,
4599
+ _key: annotationKey,
4600
+ ...action.annotation.value
4601
+ }]
4647
4602
  }, {
4648
- at: path
4649
- }), spanPath = [{
4603
+ at: blockPath
4604
+ }), markDefPath = [{
4650
4605
  _key: block._key
4651
- }, "children", {
4652
- _key: span._key
4653
- }];
4606
+ }, "markDefs", {
4607
+ _key: annotationKey
4608
+ }], slate.Range.isBackward(editor.selection) ? markDefPaths.unshift(markDefPath) : markDefPaths.push(markDefPath)), slate.Transforms.setNodes(editor, {}, {
4609
+ match: slate.Text.isText,
4610
+ split: !0
4611
+ });
4612
+ const children = slate.Node.children(editor, blockPath);
4613
+ for (const [span, path] of children) {
4614
+ if (!editor.isTextSpan(span) || !slate.Range.includes(editor.selection, path))
4615
+ continue;
4616
+ const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
4617
+ slate.Transforms.setNodes(editor, {
4618
+ marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
4619
+ }, {
4620
+ at: path
4621
+ }), spanPath = [{
4622
+ _key: block._key
4623
+ }, "children", {
4624
+ _key: span._key
4625
+ }];
4626
+ }
4654
4627
  }
4628
+ markDefPath && spanPath && (paths = {
4629
+ markDefPath,
4630
+ markDefPaths,
4631
+ spanPath
4632
+ });
4655
4633
  }
4656
- markDefPath && spanPath && (paths = {
4657
- markDefPath,
4658
- markDefPaths,
4659
- spanPath
4660
- });
4661
4634
  }
4662
4635
  return paths;
4663
4636
  }, removeAnnotationActionImplementation = ({
@@ -5078,10 +5051,10 @@ const blockSetBehaviorActionImplementation = ({
5078
5051
  context,
5079
5052
  action
5080
5053
  }) => {
5081
- const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), anchor = util_isEmptyTextBlock.blockOffsetToSpanSelectionPoint({
5054
+ const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), anchor = util_reverseSelection.blockOffsetToSpanSelectionPoint({
5082
5055
  value,
5083
5056
  blockOffset: action.anchor
5084
- }), focus = util_isEmptyTextBlock.blockOffsetToSpanSelectionPoint({
5057
+ }), focus = util_reverseSelection.blockOffsetToSpanSelectionPoint({
5085
5058
  value,
5086
5059
  blockOffset: action.focus
5087
5060
  });