@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
@@ -4,7 +4,7 @@ import { useEffectEvent } from "use-effect-event";
4
4
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
5
5
  import { withReact, ReactEditor, Slate } from "slate-react";
6
6
  import { useSelector, useActorRef } from "@xstate/react";
7
- import debug$f from "debug";
7
+ import debug$e from "debug";
8
8
  import { Editor, Element, Range, Point, Text, Operation, Transforms, Path, Node, insertText, createEditor as createEditor$1, select, deleteFragment, deleteBackward, deleteForward } from "slate";
9
9
  import { setup, emit, assign, fromCallback, assertEvent, enqueueActions, createActor } from "xstate";
10
10
  import isEqual from "lodash/isEqual.js";
@@ -23,7 +23,7 @@ import isUndefined from "lodash/isUndefined.js";
23
23
  import omitBy from "lodash/omitBy.js";
24
24
  import startCase from "lodash.startcase";
25
25
  import { createGuards } from "./selector.is-at-the-start-of-block.js";
26
- import { blockOffsetToSpanSelectionPoint } from "./util.is-empty-text-block.js";
26
+ import { blockOffsetToSpanSelectionPoint } from "./util.reverse-selection.js";
27
27
  import { defineBehavior, raise, coreBehaviors, isCustomBehaviorEvent } from "./behavior.core.js";
28
28
  import getRandomValues from "get-random-values-esm";
29
29
  import { Subject } from "rxjs";
@@ -142,10 +142,10 @@ function compileSchemaDefinition(definition) {
142
142
  };
143
143
  }
144
144
  const rootName = "sanity-pte:";
145
- debug$f(rootName);
145
+ debug$e(rootName);
146
146
  function debugWithName(name) {
147
147
  const namespace = `${rootName}${name}`;
148
- return debug$f && debug$f.enabled(namespace) ? debug$f(namespace) : debug$f(rootName);
148
+ return debug$e && debug$e.enabled(namespace) ? debug$e(namespace) : debug$e(rootName);
149
149
  }
150
150
  function createKeyedPath(point, value, types) {
151
151
  const blockPath = [point.path[0]];
@@ -1414,7 +1414,7 @@ function isRedoing(editor) {
1414
1414
  function setIsRedoing(editor, isRedoing2) {
1415
1415
  IS_REDOING.set(editor, isRedoing2);
1416
1416
  }
1417
- const debug$e = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1417
+ const debug$d = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1418
1418
  const state = SAVING.get(editor);
1419
1419
  return state === void 0 ? !0 : state;
1420
1420
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
@@ -1427,7 +1427,7 @@ function createWithUndoRedo(options) {
1427
1427
  let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
1428
1428
  const remotePatches = getRemotePatches(editor);
1429
1429
  options.subscriptions.push(() => {
1430
- debug$e("Subscribing to patches");
1430
+ debug$d("Subscribing to patches");
1431
1431
  const sub = editorActor.on("patches", ({
1432
1432
  patches,
1433
1433
  snapshot
@@ -1436,7 +1436,7 @@ function createWithUndoRedo(options) {
1436
1436
  patches.forEach((patch) => {
1437
1437
  if (!reset && patch.origin !== "local" && remotePatches) {
1438
1438
  if (patch.type === "unset" && patch.path.length === 0) {
1439
- debug$e("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1439
+ debug$d("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1440
1440
  undos: [],
1441
1441
  redos: []
1442
1442
  }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
@@ -1452,7 +1452,7 @@ function createWithUndoRedo(options) {
1452
1452
  }), previousSnapshot = snapshot;
1453
1453
  });
1454
1454
  return () => {
1455
- debug$e("Unsubscribing to patches"), sub.unsubscribe();
1455
+ debug$d("Unsubscribing to patches"), sub.unsubscribe();
1456
1456
  };
1457
1457
  }), editor.history = {
1458
1458
  undos: [],
@@ -1491,7 +1491,7 @@ function createWithUndoRedo(options) {
1491
1491
  operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
1492
1492
  timestamp: /* @__PURE__ */ new Date()
1493
1493
  };
1494
- undos.push(newStep), debug$e("Created new undo step", step);
1494
+ undos.push(newStep), debug$d("Created new undo step", step);
1495
1495
  }
1496
1496
  for (; undos.length > UNDO_STEP_LIMIT; )
1497
1497
  undos.shift();
@@ -1508,7 +1508,7 @@ function createWithUndoRedo(options) {
1508
1508
  } = editor.history;
1509
1509
  if (undos.length > 0) {
1510
1510
  const step = undos[undos.length - 1];
1511
- if (debug$e("Undoing", step), step.operations.length > 0) {
1511
+ if (debug$d("Undoing", step), step.operations.length > 0) {
1512
1512
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
1513
1513
  let transformedOperations = step.operations;
1514
1514
  otherPatches.forEach((item) => {
@@ -1526,7 +1526,7 @@ function createWithUndoRedo(options) {
1526
1526
  });
1527
1527
  }), editor.normalize(), editor.onChange();
1528
1528
  } catch (err) {
1529
- debug$e("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
1529
+ debug$d("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
1530
1530
  undos: [],
1531
1531
  redos: []
1532
1532
  }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
@@ -1545,7 +1545,7 @@ function createWithUndoRedo(options) {
1545
1545
  } = editor.history;
1546
1546
  if (redos.length > 0) {
1547
1547
  const step = redos[redos.length - 1];
1548
- if (debug$e("Redoing", step), step.operations.length > 0) {
1548
+ if (debug$d("Redoing", step), step.operations.length > 0) {
1549
1549
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
1550
1550
  let transformedOperations = step.operations;
1551
1551
  otherPatches.forEach((item) => {
@@ -1562,7 +1562,7 @@ function createWithUndoRedo(options) {
1562
1562
  });
1563
1563
  }), editor.normalize(), editor.onChange();
1564
1564
  } catch (err) {
1565
- debug$e("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
1565
+ debug$d("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
1566
1566
  undos: [],
1567
1567
  redos: []
1568
1568
  }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
@@ -1582,16 +1582,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
1582
1582
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
1583
1583
  _key: blk._key
1584
1584
  }, patch.path[0]));
1585
- return debug$e(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
1585
+ return debug$d(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
1586
1586
  }
1587
1587
  if (patch.type === "unset" && patch.path.length === 1) {
1588
1588
  const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
1589
1589
  _key: blk._key
1590
1590
  }, patch.path[0]));
1591
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$e("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
1591
+ return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$d("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
1592
1592
  }
1593
1593
  if (patch.type === "unset" && patch.path.length === 0)
1594
- return debug$e(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
1594
+ return debug$d(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
1595
1595
  if (patch.type === "diffMatchPatch") {
1596
1596
  const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
1597
1597
  return !operationTargetBlock || !isEqual({
@@ -1678,7 +1678,7 @@ function findOperationTargetBlock(editor, operation) {
1678
1678
  let block;
1679
1679
  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;
1680
1680
  }
1681
- const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1681
+ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
1682
1682
  sendBack,
1683
1683
  input
1684
1684
  }) => {
@@ -1730,7 +1730,7 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1730
1730
  context
1731
1731
  }) => {
1732
1732
  const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
1733
- return debug$d("isBusy", {
1733
+ return debug$c("isBusy", {
1734
1734
  isBusy,
1735
1735
  editable,
1736
1736
  isProcessingLocalChanges,
@@ -1784,10 +1784,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1784
1784
  states: {
1785
1785
  "syncing initial value": {
1786
1786
  entry: [() => {
1787
- debug$d("entry: syncing initial value");
1787
+ debug$c("entry: syncing initial value");
1788
1788
  }],
1789
1789
  exit: [() => {
1790
- debug$d("exit: syncing initial value");
1790
+ debug$c("exit: syncing initial value");
1791
1791
  }],
1792
1792
  always: {
1793
1793
  guard: "initial value synced",
@@ -1796,10 +1796,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1796
1796
  },
1797
1797
  "done syncing initial value": {
1798
1798
  entry: ["emit done syncing initial value", () => {
1799
- debug$d("entry: done syncing initial value");
1799
+ debug$c("entry: done syncing initial value");
1800
1800
  }],
1801
1801
  exit: [() => {
1802
- debug$d("exit: done syncing initial value");
1802
+ debug$c("exit: done syncing initial value");
1803
1803
  }],
1804
1804
  type: "final"
1805
1805
  }
@@ -1810,10 +1810,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1810
1810
  states: {
1811
1811
  idle: {
1812
1812
  entry: [() => {
1813
- debug$d("entry: syncing->idle");
1813
+ debug$c("entry: syncing->idle");
1814
1814
  }],
1815
1815
  exit: [() => {
1816
- debug$d("exit: syncing->idle");
1816
+ debug$c("exit: syncing->idle");
1817
1817
  }],
1818
1818
  on: {
1819
1819
  "update value": [{
@@ -1828,10 +1828,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1828
1828
  },
1829
1829
  busy: {
1830
1830
  entry: [() => {
1831
- debug$d("entry: syncing->busy");
1831
+ debug$c("entry: syncing->busy");
1832
1832
  }],
1833
1833
  exit: [() => {
1834
- debug$d("exit: syncing->busy");
1834
+ debug$c("exit: syncing->busy");
1835
1835
  }],
1836
1836
  after: {
1837
1837
  1e3: [{
@@ -1839,7 +1839,7 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1839
1839
  target: ".",
1840
1840
  reenter: !0,
1841
1841
  actions: [() => {
1842
- debug$d("reenter: syncing->busy");
1842
+ debug$c("reenter: syncing->busy");
1843
1843
  }]
1844
1844
  }, {
1845
1845
  target: "syncing"
@@ -1853,10 +1853,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
1853
1853
  },
1854
1854
  syncing: {
1855
1855
  entry: [() => {
1856
- debug$d("entry: syncing->syncing");
1856
+ debug$c("entry: syncing->syncing");
1857
1857
  }],
1858
1858
  exit: [() => {
1859
- debug$d("exit: syncing->syncing");
1859
+ debug$c("exit: syncing->syncing");
1860
1860
  }],
1861
1861
  always: {
1862
1862
  guard: "pending value equals previous value",
@@ -1922,7 +1922,7 @@ async function updateValue({
1922
1922
  }) {
1923
1923
  let isChanged = !1, isValid = !0;
1924
1924
  const hadSelection = !!slateEditor.selection;
1925
- if ((!value || value.length === 0) && (debug$d("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
1925
+ if ((!value || value.length === 0) && (debug$c("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
1926
1926
  withoutSaving(slateEditor, () => {
1927
1927
  withoutPatching(slateEditor, () => {
1928
1928
  hadSelection && Transforms.deselect(slateEditor);
@@ -1978,14 +1978,14 @@ async function updateValue({
1978
1978
  });
1979
1979
  }
1980
1980
  if (!isValid) {
1981
- debug$d("Invalid value, returning"), sendBack({
1981
+ debug$c("Invalid value, returning"), sendBack({
1982
1982
  type: "done syncing",
1983
1983
  value
1984
1984
  });
1985
1985
  return;
1986
1986
  }
1987
1987
  if (isChanged) {
1988
- debug$d("Server value changed, syncing editor");
1988
+ debug$c("Server value changed, syncing editor");
1989
1989
  try {
1990
1990
  slateEditor.onChange();
1991
1991
  } catch (err) {
@@ -2013,7 +2013,7 @@ async function updateValue({
2013
2013
  value
2014
2014
  });
2015
2015
  } else
2016
- debug$d("Server value and editor value is equal, no need to sync.");
2016
+ debug$c("Server value and editor value is equal, no need to sync.");
2017
2017
  sendBack({
2018
2018
  type: "done syncing",
2019
2019
  value
@@ -2047,7 +2047,7 @@ function syncBlock({
2047
2047
  type: "patch",
2048
2048
  patch
2049
2049
  });
2050
- })), 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({
2050
+ })), 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({
2051
2051
  type: "invalid value",
2052
2052
  resolution: validation.resolution,
2053
2053
  value
@@ -2055,9 +2055,9 @@ function syncBlock({
2055
2055
  }
2056
2056
  if (!oldBlock && blockValid) {
2057
2057
  const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
2058
- debug$d.enabled && debug$d("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
2058
+ debug$c.enabled && debug$c("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
2059
2059
  at: [currentBlockIndex]
2060
- }) : (debug$d("Invalid", validation), sendBack({
2060
+ }) : (debug$c("Invalid", validation), sendBack({
2061
2061
  type: "invalid value",
2062
2062
  resolution: validation.resolution,
2063
2063
  value
@@ -2085,14 +2085,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2085
2085
  const oldBlockChildrenLength = oldBlock.children.length;
2086
2086
  currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
2087
2087
  const childIndex = oldBlockChildrenLength - 1 - index;
2088
- childIndex > 0 && (debug$d("Removing child"), Transforms.removeNodes(slateEditor, {
2088
+ childIndex > 0 && (debug$c("Removing child"), Transforms.removeNodes(slateEditor, {
2089
2089
  at: [currentBlockIndex, childIndex]
2090
2090
  }));
2091
2091
  }), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
2092
2092
  const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
2093
2093
  if (isChildChanged)
2094
2094
  if (currentBlockChild._key === oldBlockChild?._key) {
2095
- debug$d("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
2095
+ debug$c("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
2096
2096
  at: path
2097
2097
  });
2098
2098
  const isSpanNode = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
@@ -2109,23 +2109,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2109
2109
  }
2110
2110
  }), Transforms.insertText(slateEditor, currentBlockChild.text, {
2111
2111
  at: path
2112
- }), slateEditor.onChange()) : isSpanNode || (debug$d("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
2112
+ }), slateEditor.onChange()) : isSpanNode || (debug$c("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
2113
2113
  _key: VOID_CHILD_KEY
2114
2114
  }, {
2115
2115
  at: [...path, 0],
2116
2116
  voids: !0
2117
2117
  }));
2118
- } else oldBlockChild ? (debug$d("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
2118
+ } else oldBlockChild ? (debug$c("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
2119
2119
  at: [currentBlockIndex, currentBlockChildIndex]
2120
2120
  }), Transforms.insertNodes(slateEditor, currentBlockChild, {
2121
2121
  at: [currentBlockIndex, currentBlockChildIndex]
2122
- }), slateEditor.onChange()) : oldBlockChild || (debug$d("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
2122
+ }), slateEditor.onChange()) : oldBlockChild || (debug$c("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
2123
2123
  at: [currentBlockIndex, currentBlockChildIndex]
2124
2124
  }), slateEditor.onChange());
2125
2125
  });
2126
2126
  }
2127
2127
  }
2128
- const debug$c = debugWithName("component:PortableTextEditor:Synchronizer");
2128
+ const debug$b = debugWithName("component:PortableTextEditor:Synchronizer");
2129
2129
  function Synchronizer(props) {
2130
2130
  const $ = c(40), {
2131
2131
  editorActor,
@@ -2213,19 +2213,19 @@ function Synchronizer(props) {
2213
2213
  }, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), useEffect(t11, t12);
2214
2214
  let t13, t14;
2215
2215
  $[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
2216
- debug$c("Value from props changed, syncing new value"), syncActorRef.send({
2216
+ debug$b("Value from props changed, syncing new value"), syncActorRef.send({
2217
2217
  type: "update value",
2218
2218
  value
2219
2219
  });
2220
2220
  }, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), useEffect(t13, t14);
2221
2221
  let t15;
2222
2222
  $[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
2223
- debug$c("Subscribing to patch events");
2223
+ debug$b("Subscribing to patch events");
2224
2224
  const sub = editorActor.on("patch", (event_1) => {
2225
2225
  mutationActorRef.send(event_1);
2226
2226
  });
2227
2227
  return () => {
2228
- debug$c("Unsubscribing to patch events"), sub.unsubscribe();
2228
+ debug$b("Unsubscribing to patch events"), sub.unsubscribe();
2229
2229
  };
2230
2230
  }, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
2231
2231
  let t16;
@@ -2427,11 +2427,11 @@ const converterJson = {
2427
2427
  function escapeHtml(str) {
2428
2428
  return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
2429
2429
  }
2430
- const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$b = debugWithName("operationToPatches");
2430
+ const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$a = debugWithName("operationToPatches");
2431
2431
  function createOperationToPatches(types) {
2432
2432
  const textBlockName = types.block.name;
2433
2433
  function insertTextPatch(editor, operation, beforeValue) {
2434
- debug$b.enabled && debug$b("Operation", JSON.stringify(operation, null, 2));
2434
+ debug$a.enabled && debug$a("Operation", JSON.stringify(operation, null, 2));
2435
2435
  const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
2436
2436
  if (!block)
2437
2437
  throw new Error("Could not find block");
@@ -2524,7 +2524,7 @@ function createOperationToPatches(types) {
2524
2524
  _key: block.children[operation.path[1] - 1]._key
2525
2525
  }])];
2526
2526
  }
2527
- return debug$b("Something was inserted into a void block. Not producing editor patches."), [];
2527
+ return debug$a("Something was inserted into a void block. Not producing editor patches."), [];
2528
2528
  }
2529
2529
  function splitNodePatch(editor, operation, beforeValue) {
2530
2530
  const patches = [], splitBlock = editor.children[operation.path[0]];
@@ -2582,9 +2582,9 @@ function createOperationToPatches(types) {
2582
2582
  _key: block._key
2583
2583
  }, "children", {
2584
2584
  _key: spanToRemove._key
2585
- }])] : (debug$b("Span not found in editor trying to remove node"), []);
2585
+ }])] : (debug$a("Span not found in editor trying to remove node"), []);
2586
2586
  } else
2587
- return debug$b("Not creating patch inside object block"), [];
2587
+ return debug$a("Not creating patch inside object block"), [];
2588
2588
  }
2589
2589
  function mergeNodePatch(editor, operation, beforeValue) {
2590
2590
  const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
@@ -2610,7 +2610,7 @@ function createOperationToPatches(types) {
2610
2610
  _key: removedSpan._key
2611
2611
  }])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
2612
2612
  } else
2613
- debug$b("Void nodes can't be merged, not creating any patches");
2613
+ debug$a("Void nodes can't be merged, not creating any patches");
2614
2614
  return patches;
2615
2615
  }
2616
2616
  function moveNodePatch(editor, operation, beforeValue) {
@@ -3000,13 +3000,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
3000
3000
  }, editor;
3001
3001
  };
3002
3002
  }
3003
- const debug$a = debugWithName("applyPatches"), debugVerbose = debug$a.enabled && !0;
3003
+ const debug$9 = debugWithName("applyPatches"), debugVerbose = debug$9.enabled && !0;
3004
3004
  function createApplyPatch(schemaTypes) {
3005
3005
  return (editor, patch) => {
3006
3006
  let changed = !1;
3007
- debugVerbose && (debug$a(`
3007
+ debugVerbose && (debug$9(`
3008
3008
 
3009
- NEW PATCH =============================================================`), debug$a(JSON.stringify(patch, null, 2)));
3009
+ NEW PATCH =============================================================`), debug$9(JSON.stringify(patch, null, 2)));
3010
3010
  try {
3011
3011
  switch (patch.type) {
3012
3012
  case "insert":
@@ -3022,7 +3022,7 @@ NEW PATCH =============================================================`), debug
3022
3022
  changed = diffMatchPatch(editor, patch);
3023
3023
  break;
3024
3024
  default:
3025
- debug$a("Unhandled patch", patch.type);
3025
+ debug$9("Unhandled patch", patch.type);
3026
3026
  }
3027
3027
  } catch (err) {
3028
3028
  console.error(err);
@@ -3037,9 +3037,9 @@ function diffMatchPatch(editor, patch) {
3037
3037
  childPath
3038
3038
  } = findBlockAndChildFromPath(editor, patch.path);
3039
3039
  if (!block)
3040
- return debug$a("Block not found"), !1;
3040
+ return debug$9("Block not found"), !1;
3041
3041
  if (!child || !childPath)
3042
- return debug$a("Child not found"), !1;
3042
+ return debug$9("Child not found"), !1;
3043
3043
  if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !Text.isText(child))
3044
3044
  return !1;
3045
3045
  const patches = parse(patch.value), [newValue] = apply(patches, child.text, {
@@ -3069,9 +3069,9 @@ function insertPatch(editor, patch, schemaTypes) {
3069
3069
  childPath: targetChildPath
3070
3070
  } = findBlockAndChildFromPath(editor, patch.path);
3071
3071
  if (!targetBlock || !targetBlockPath)
3072
- return debug$a("Block not found"), !1;
3072
+ return debug$9("Block not found"), !1;
3073
3073
  if (patch.path.length > 1 && patch.path[1] !== "children")
3074
- return debug$a("Ignoring patch targeting void value"), !1;
3074
+ return debug$9("Ignoring patch targeting void value"), !1;
3075
3075
  if (patch.path.length === 1) {
3076
3076
  const {
3077
3077
  items: items2,
@@ -3079,7 +3079,7 @@ function insertPatch(editor, patch, schemaTypes) {
3079
3079
  } = patch, blocksToInsert = toSlateValue(items2, {
3080
3080
  schemaTypes
3081
3081
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
3082
- return debug$a(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
3082
+ return debug$9(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
3083
3083
  at: [normalizedIdx2]
3084
3084
  }), debugState(editor, "after"), !0;
3085
3085
  }
@@ -3088,14 +3088,14 @@ function insertPatch(editor, patch, schemaTypes) {
3088
3088
  position
3089
3089
  } = patch;
3090
3090
  if (!targetChild || !targetChildPath)
3091
- return debug$a("Child not found"), !1;
3091
+ return debug$9("Child not found"), !1;
3092
3092
  const childrenToInsert = targetBlock && toSlateValue([{
3093
3093
  ...targetBlock,
3094
3094
  children: items
3095
3095
  }], {
3096
3096
  schemaTypes
3097
3097
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
3098
- return debug$a(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
3098
+ return debug$9(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
3099
3099
  at: childInsertPath
3100
3100
  }), debugState(editor, "after"), !0;
3101
3101
  }
@@ -3109,14 +3109,14 @@ function setPatch(editor, patch) {
3109
3109
  childPath
3110
3110
  } = findBlockAndChildFromPath(editor, patch.path);
3111
3111
  if (!block)
3112
- return debug$a("Block not found"), !1;
3112
+ return debug$9("Block not found"), !1;
3113
3113
  const isTextBlock = editor.isTextBlock(block);
3114
3114
  if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
3115
- return debug$a("Ignoring setting void value"), !1;
3115
+ return debug$9("Ignoring setting void value"), !1;
3116
3116
  if (debugState(editor, "before"), isTextBlock && child && childPath) {
3117
3117
  if (Text.isText(value) && Text.isText(child)) {
3118
3118
  const newText = child.text;
3119
- value.text !== newText && (debug$a("Setting text property"), editor.apply({
3119
+ value.text !== newText && (debug$9("Setting text property"), editor.apply({
3120
3120
  type: "remove_text",
3121
3121
  path: childPath,
3122
3122
  offset: 0,
@@ -3128,7 +3128,7 @@ function setPatch(editor, patch) {
3128
3128
  text: value.text
3129
3129
  }), editor.onChange());
3130
3130
  } else
3131
- debug$a("Setting non-text property"), editor.apply({
3131
+ debug$9("Setting non-text property"), editor.apply({
3132
3132
  type: "set_node",
3133
3133
  path: childPath,
3134
3134
  properties: {},
@@ -3136,7 +3136,7 @@ function setPatch(editor, patch) {
3136
3136
  });
3137
3137
  return !0;
3138
3138
  } else if (Element.isElement(block) && patch.path.length === 1 && blockPath) {
3139
- debug$a("Setting block property");
3139
+ debug$9("Setting block property");
3140
3140
  const {
3141
3141
  children,
3142
3142
  ...nextRest
@@ -3153,7 +3153,7 @@ function setPatch(editor, patch) {
3153
3153
  ...prevRest
3154
3154
  },
3155
3155
  newProperties: nextRest
3156
- }), debug$a("Setting children"), block.children.forEach((c2, cIndex) => {
3156
+ }), debug$9("Setting children"), block.children.forEach((c2, cIndex) => {
3157
3157
  editor.apply({
3158
3158
  type: "remove_node",
3159
3159
  path: blockPath.concat(block.children.length - 1 - cIndex),
@@ -3184,7 +3184,7 @@ function setPatch(editor, patch) {
3184
3184
  }
3185
3185
  function unsetPatch(editor, patch) {
3186
3186
  if (patch.path.length === 0) {
3187
- debug$a("Removing everything"), debugState(editor, "before");
3187
+ debug$9("Removing everything"), debugState(editor, "before");
3188
3188
  const previousSelection = editor.selection;
3189
3189
  return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
3190
3190
  Transforms.removeNodes(editor, {
@@ -3211,13 +3211,13 @@ function unsetPatch(editor, patch) {
3211
3211
  } = findBlockAndChildFromPath(editor, patch.path);
3212
3212
  if (patch.path.length === 1) {
3213
3213
  if (!block || !blockPath)
3214
- return debug$a("Block not found"), !1;
3214
+ return debug$9("Block not found"), !1;
3215
3215
  const blockIndex = blockPath[0];
3216
- return debug$a(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
3216
+ return debug$9(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
3217
3217
  at: [blockIndex]
3218
3218
  }), debugState(editor, "after"), !0;
3219
3219
  }
3220
- 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)}`), Transforms.removeNodes(editor, {
3220
+ 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)}`), Transforms.removeNodes(editor, {
3221
3221
  at: childPath
3222
3222
  }), debugState(editor, "after"), !0) : !1;
3223
3223
  }
@@ -3225,7 +3225,7 @@ function isKeyedSegment(segment) {
3225
3225
  return typeof segment == "object" && "_key" in segment;
3226
3226
  }
3227
3227
  function debugState(editor, stateName) {
3228
- debugVerbose && (debug$a(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$a(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
3228
+ debugVerbose && (debug$9(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$9(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
3229
3229
  }
3230
3230
  function findBlockFromPath(editor, path) {
3231
3231
  let blockIndex = -1;
@@ -3267,7 +3267,7 @@ function findBlockAndChildFromPath(editor, path) {
3267
3267
  childPath: void 0
3268
3268
  };
3269
3269
  }
3270
- const debug$9 = debugWithName("plugin:withPatches");
3270
+ const debug$8 = debugWithName("plugin:withPatches");
3271
3271
  function createWithPatches({
3272
3272
  editorActor,
3273
3273
  patchFunctions,
@@ -3293,7 +3293,7 @@ function createWithPatches({
3293
3293
  withoutPatching(editor, () => {
3294
3294
  withoutSaving(editor, () => {
3295
3295
  patches.forEach((patch) => {
3296
- debug$9.enabled && debug$9(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
3296
+ debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
3297
3297
  });
3298
3298
  });
3299
3299
  });
@@ -3306,10 +3306,10 @@ function createWithPatches({
3306
3306
  remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
3307
3307
  };
3308
3308
  return subscriptions.push(() => {
3309
- debug$9("Subscribing to remote patches");
3309
+ debug$8("Subscribing to remote patches");
3310
3310
  const sub = editorActor.on("patches", handlePatches);
3311
3311
  return () => {
3312
- debug$9("Unsubscribing to remote patches"), sub.unsubscribe();
3312
+ debug$8("Unsubscribing to remote patches"), sub.unsubscribe();
3313
3313
  };
3314
3314
  }), editor.apply = (operation) => {
3315
3315
  let patches = [];
@@ -3360,7 +3360,7 @@ function createWithPatches({
3360
3360
  }, editor;
3361
3361
  };
3362
3362
  }
3363
- const debug$8 = debugWithName("plugin:withPlaceholderBlock");
3363
+ const debug$7 = debugWithName("plugin:withPlaceholderBlock");
3364
3364
  function createWithPlaceholderBlock(editorActor) {
3365
3365
  return function(editor) {
3366
3366
  const {
@@ -3385,7 +3385,7 @@ function createWithPlaceholderBlock(editorActor) {
3385
3385
  const node = op.node;
3386
3386
  if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
3387
3387
  const nextPath = Path.next(op.path);
3388
- editor.children[nextPath[0]] || (debug$8("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
3388
+ editor.children[nextPath[0]] || (debug$7("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
3389
3389
  decorators: []
3390
3390
  })));
3391
3391
  }
@@ -3394,7 +3394,7 @@ function createWithPlaceholderBlock(editorActor) {
3394
3394
  }, editor;
3395
3395
  };
3396
3396
  }
3397
- const debug$7 = debugWithName("plugin:withPortableTextBlockStyle");
3397
+ const debug$6 = debugWithName("plugin:withPortableTextBlockStyle");
3398
3398
  function createWithPortableTextBlockStyle(editorActor, types) {
3399
3399
  const defaultStyle = types.styles[0].value;
3400
3400
  return function(editor) {
@@ -3407,7 +3407,7 @@ function createWithPortableTextBlockStyle(editorActor, types) {
3407
3407
  if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !Path.equals(path, op.path)) {
3408
3408
  const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
3409
3409
  if (Text.isText(child) && child.text === "") {
3410
- debug$7(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
3410
+ debug$6(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
3411
3411
  type: "normalizing"
3412
3412
  }), Transforms.setNodes(editor, {
3413
3413
  style: defaultStyle
@@ -3467,7 +3467,7 @@ function getNextSpan({
3467
3467
  }
3468
3468
  return nextSpan;
3469
3469
  }
3470
- const debug$6 = debugWithName("plugin:withPortableTextMarkModel");
3470
+ const debug$5 = debugWithName("plugin:withPortableTextMarkModel");
3471
3471
  function createWithPortableTextMarkModel(editorActor, types) {
3472
3472
  return function(editor) {
3473
3473
  const {
@@ -3481,7 +3481,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3481
3481
  for (const [child, childPath] of children) {
3482
3482
  const nextNode = node.children[childPath[1] + 1];
3483
3483
  if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
3484
- debug$6("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3484
+ debug$5("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3485
3485
  type: "normalizing"
3486
3486
  }), Transforms.mergeNodes(editor, {
3487
3487
  at: [childPath[0], childPath[1] + 1],
@@ -3494,7 +3494,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3494
3494
  }
3495
3495
  }
3496
3496
  if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
3497
- debug$6("Adding .markDefs to block node"), editorActor.send({
3497
+ debug$5("Adding .markDefs to block node"), editorActor.send({
3498
3498
  type: "normalizing"
3499
3499
  }), Transforms.setNodes(editor, {
3500
3500
  markDefs: []
@@ -3506,7 +3506,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3506
3506
  return;
3507
3507
  }
3508
3508
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
3509
- debug$6("Adding .marks to span node"), editorActor.send({
3509
+ debug$5("Adding .marks to span node"), editorActor.send({
3510
3510
  type: "normalizing"
3511
3511
  }), Transforms.setNodes(editor, {
3512
3512
  marks: []
@@ -3520,7 +3520,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3520
3520
  if (editor.isTextSpan(node)) {
3521
3521
  const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
3522
3522
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
3523
- debug$6("Removing annotations from empty span node"), editorActor.send({
3523
+ debug$5("Removing annotations from empty span node"), editorActor.send({
3524
3524
  type: "normalizing"
3525
3525
  }), Transforms.setNodes(editor, {
3526
3526
  marks: node.marks?.filter((mark) => decorators2.includes(mark))
@@ -3538,7 +3538,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3538
3538
  if (editor.isTextSpan(child)) {
3539
3539
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
3540
3540
  if (orphanedAnnotations.length > 0) {
3541
- debug$6("Removing orphaned annotations from span node"), editorActor.send({
3541
+ debug$5("Removing orphaned annotations from span node"), editorActor.send({
3542
3542
  type: "normalizing"
3543
3543
  }), Transforms.setNodes(editor, {
3544
3544
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3556,7 +3556,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3556
3556
  if (editor.isTextBlock(block)) {
3557
3557
  const decorators2 = types.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
3558
3558
  if (orphanedAnnotations.length > 0) {
3559
- debug$6("Removing orphaned annotations from span node"), editorActor.send({
3559
+ debug$5("Removing orphaned annotations from span node"), editorActor.send({
3560
3560
  type: "normalizing"
3561
3561
  }), Transforms.setNodes(editor, {
3562
3562
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3574,7 +3574,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3574
3574
  for (const markDef of markDefs)
3575
3575
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
3576
3576
  if (markDefs.length !== newMarkDefs.length) {
3577
- debug$6("Removing duplicate markDefs"), editorActor.send({
3577
+ debug$5("Removing duplicate markDefs"), editorActor.send({
3578
3578
  type: "normalizing"
3579
3579
  }), Transforms.setNodes(editor, {
3580
3580
  markDefs: newMarkDefs
@@ -3589,7 +3589,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3589
3589
  if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
3590
3590
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
3591
3591
  if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
3592
- debug$6("Removing markDef not in use"), editorActor.send({
3592
+ debug$5("Removing markDef not in use"), editorActor.send({
3593
3593
  type: "normalizing"
3594
3594
  }), Transforms.setNodes(editor, {
3595
3595
  markDefs: newMarkDefs
@@ -3809,7 +3809,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3809
3809
  const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
3810
3810
  if (editor.isTextBlock(targetBlock)) {
3811
3811
  const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
3812
- debug$6("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
3812
+ debug$5("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
3813
3813
  markDefs: newMarkDefs
3814
3814
  }, {
3815
3815
  at: targetPath,
@@ -4009,7 +4009,7 @@ function createWithPortableTextSelections(editorActor, types) {
4009
4009
  }, editor;
4010
4010
  };
4011
4011
  }
4012
- const debug$5 = debugWithName("plugin:withSchemaTypes");
4012
+ const debug$4 = debugWithName("plugin:withSchemaTypes");
4013
4013
  function createWithSchemaTypes({
4014
4014
  editorActor,
4015
4015
  schemaTypes
@@ -4022,7 +4022,7 @@ function createWithSchemaTypes({
4022
4022
  return editor.normalizeNode = (entry) => {
4023
4023
  const [node, path] = entry;
4024
4024
  if (node._type === void 0 && path.length === 2) {
4025
- debug$5("Setting span type on text node without a type");
4025
+ debug$4("Setting span type on text node without a type");
4026
4026
  const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
4027
4027
  editorActor.send({
4028
4028
  type: "normalizing"
@@ -4038,7 +4038,7 @@ function createWithSchemaTypes({
4038
4038
  return;
4039
4039
  }
4040
4040
  if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
4041
- debug$5("Setting missing key on child node without a key");
4041
+ debug$4("Setting missing key on child node without a key");
4042
4042
  const key = editorActor.getSnapshot().context.keyGenerator();
4043
4043
  editorActor.send({
4044
4044
  type: "normalizing"
@@ -4055,43 +4055,12 @@ function createWithSchemaTypes({
4055
4055
  }, editor;
4056
4056
  };
4057
4057
  }
4058
- const debug$4 = debugWithName("plugin:withUtils");
4059
4058
  function createWithUtils({
4060
4059
  editorActor,
4061
4060
  schemaTypes
4062
4061
  }) {
4063
4062
  return function(editor) {
4064
- return editor.pteExpandToWord = () => {
4065
- const {
4066
- selection
4067
- } = editor;
4068
- if (selection && !Range.isExpanded(selection)) {
4069
- const [textNode] = Editor.node(editor, selection.focus, {
4070
- depth: 2
4071
- });
4072
- if (!textNode || !Text.isText(textNode) || textNode.text.length === 0) {
4073
- debug$4("pteExpandToWord: Can't expand to word here");
4074
- return;
4075
- }
4076
- const {
4077
- focus
4078
- } = 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);
4079
- if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
4080
- debug$4("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
4081
- anchor: {
4082
- ...selection.anchor,
4083
- offset: newStartOffset
4084
- },
4085
- focus: {
4086
- ...selection.focus,
4087
- offset: newEndOffset
4088
- }
4089
- });
4090
- return;
4091
- }
4092
- debug$4("pteExpandToWord: Can't expand to word here");
4093
- }
4094
- }, editor.pteCreateTextBlock = (options) => toSlateValue([{
4063
+ return editor.pteCreateTextBlock = (options) => toSlateValue([{
4095
4064
  _type: schemaTypes.block.name,
4096
4065
  _key: editorActor.getSnapshot().context.keyGenerator(),
4097
4066
  style: schemaTypes.styles[0].value || "normal",
@@ -4630,57 +4599,61 @@ const addAnnotationActionImplementation = ({
4630
4599
  selection: originalSelection
4631
4600
  } = editor;
4632
4601
  let paths;
4633
- if (originalSelection && (Range.isCollapsed(originalSelection) && (editor.pteExpandToWord(), editor.onChange()), editor.selection)) {
4634
- let spanPath, markDefPath;
4635
- const markDefPaths = [];
4636
- if (!editor.selection)
4602
+ if (originalSelection) {
4603
+ if (Range.isCollapsed(originalSelection))
4637
4604
  return;
4638
- const selectedBlocks = Editor.nodes(editor, {
4639
- at: editor.selection,
4640
- match: (node) => editor.isTextBlock(node),
4641
- reverse: Range.isBackward(editor.selection)
4642
- });
4643
- for (const [block, blockPath] of selectedBlocks) {
4644
- if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
4645
- continue;
4646
- const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
4647
- markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
4648
- markDefs: [...markDefs, {
4649
- _type: action.annotation.name,
4650
- _key: annotationKey,
4651
- ...action.annotation.value
4652
- }]
4653
- }, {
4654
- at: blockPath
4655
- }), markDefPath = [{
4656
- _key: block._key
4657
- }, "markDefs", {
4658
- _key: annotationKey
4659
- }], Range.isBackward(editor.selection) ? markDefPaths.unshift(markDefPath) : markDefPaths.push(markDefPath)), Transforms.setNodes(editor, {}, {
4660
- match: Text.isText,
4661
- split: !0
4605
+ if (editor.selection) {
4606
+ let spanPath, markDefPath;
4607
+ const markDefPaths = [];
4608
+ if (!editor.selection)
4609
+ return;
4610
+ const selectedBlocks = Editor.nodes(editor, {
4611
+ at: editor.selection,
4612
+ match: (node) => editor.isTextBlock(node),
4613
+ reverse: Range.isBackward(editor.selection)
4662
4614
  });
4663
- const children = Node.children(editor, blockPath);
4664
- for (const [span, path] of children) {
4665
- if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
4615
+ for (const [block, blockPath] of selectedBlocks) {
4616
+ if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
4666
4617
  continue;
4667
- const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
4668
- Transforms.setNodes(editor, {
4669
- marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
4618
+ const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
4619
+ markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
4620
+ markDefs: [...markDefs, {
4621
+ _type: action.annotation.name,
4622
+ _key: annotationKey,
4623
+ ...action.annotation.value
4624
+ }]
4670
4625
  }, {
4671
- at: path
4672
- }), spanPath = [{
4626
+ at: blockPath
4627
+ }), markDefPath = [{
4673
4628
  _key: block._key
4674
- }, "children", {
4675
- _key: span._key
4676
- }];
4629
+ }, "markDefs", {
4630
+ _key: annotationKey
4631
+ }], Range.isBackward(editor.selection) ? markDefPaths.unshift(markDefPath) : markDefPaths.push(markDefPath)), Transforms.setNodes(editor, {}, {
4632
+ match: Text.isText,
4633
+ split: !0
4634
+ });
4635
+ const children = Node.children(editor, blockPath);
4636
+ for (const [span, path] of children) {
4637
+ if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
4638
+ continue;
4639
+ const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
4640
+ Transforms.setNodes(editor, {
4641
+ marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
4642
+ }, {
4643
+ at: path
4644
+ }), spanPath = [{
4645
+ _key: block._key
4646
+ }, "children", {
4647
+ _key: span._key
4648
+ }];
4649
+ }
4677
4650
  }
4651
+ markDefPath && spanPath && (paths = {
4652
+ markDefPath,
4653
+ markDefPaths,
4654
+ spanPath
4655
+ });
4678
4656
  }
4679
- markDefPath && spanPath && (paths = {
4680
- markDefPath,
4681
- markDefPaths,
4682
- spanPath
4683
- });
4684
4657
  }
4685
4658
  return paths;
4686
4659
  }, removeAnnotationActionImplementation = ({