@portabletext/editor 1.23.0 → 1.25.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 (71) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +249 -62
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/{selector.is-selection-collapsed.cjs → selector.is-active-style.cjs} +158 -3
  4. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
  5. package/lib/_chunks-cjs/util.slice-blocks.cjs +23 -9
  6. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  7. package/lib/_chunks-es/behavior.core.js +225 -38
  8. package/lib/_chunks-es/behavior.core.js.map +1 -1
  9. package/lib/_chunks-es/{selector.is-selection-collapsed.js → selector.is-active-style.js} +159 -4
  10. package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
  11. package/lib/_chunks-es/util.slice-blocks.js +23 -9
  12. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  13. package/lib/behaviors/index.cjs +27 -27
  14. package/lib/behaviors/index.cjs.map +1 -1
  15. package/lib/behaviors/index.d.cts +2830 -139
  16. package/lib/behaviors/index.d.ts +2830 -139
  17. package/lib/behaviors/index.js +1 -1
  18. package/lib/index.cjs +695 -526
  19. package/lib/index.cjs.map +1 -1
  20. package/lib/index.d.cts +8950 -246
  21. package/lib/index.d.ts +8950 -246
  22. package/lib/index.js +696 -525
  23. package/lib/index.js.map +1 -1
  24. package/lib/selectors/index.cjs +24 -171
  25. package/lib/selectors/index.cjs.map +1 -1
  26. package/lib/selectors/index.d.cts +73 -0
  27. package/lib/selectors/index.d.ts +73 -0
  28. package/lib/selectors/index.js +3 -151
  29. package/lib/selectors/index.js.map +1 -1
  30. package/package.json +11 -10
  31. package/src/behavior-actions/behavior.action.data-transfer-set.ts +7 -0
  32. package/src/behavior-actions/behavior.action.insert-blocks.ts +61 -0
  33. package/src/behavior-actions/behavior.actions.ts +159 -83
  34. package/src/behaviors/behavior.core.annotations.ts +29 -0
  35. package/src/behaviors/behavior.core.block-objects.ts +13 -13
  36. package/src/behaviors/behavior.core.decorators.ts +19 -0
  37. package/src/behaviors/behavior.core.deserialize.ts +46 -0
  38. package/src/behaviors/behavior.core.lists.ts +57 -23
  39. package/src/behaviors/behavior.core.serialize.ts +44 -0
  40. package/src/behaviors/behavior.core.style.ts +19 -0
  41. package/src/behaviors/behavior.core.ts +19 -0
  42. package/src/behaviors/behavior.types.ts +126 -89
  43. package/src/converters/converter.json.ts +53 -0
  44. package/src/converters/converter.portable-text.deserialize.test.ts +686 -0
  45. package/src/converters/converter.portable-text.ts +59 -0
  46. package/src/converters/converter.text-html.deserialize.test.ts +349 -0
  47. package/src/converters/converter.text-html.serialize.test.ts +233 -0
  48. package/src/converters/converter.text-html.ts +61 -0
  49. package/src/converters/converter.text-plain.test.ts +241 -0
  50. package/src/converters/converter.text-plain.ts +91 -0
  51. package/src/converters/converter.ts +65 -0
  52. package/src/converters/converters.ts +11 -0
  53. package/src/editor/Editable.tsx +3 -13
  54. package/src/editor/create-editor.ts +48 -6
  55. package/src/editor/editor-machine.ts +56 -2
  56. package/src/editor/editor-selector.ts +1 -0
  57. package/src/editor/editor-snapshot.ts +5 -0
  58. package/src/editor/plugins/create-with-event-listeners.ts +82 -106
  59. package/src/internal-utils/asserters.ts +9 -0
  60. package/src/internal-utils/mime-type.ts +1 -0
  61. package/src/internal-utils/parse-blocks.ts +136 -0
  62. package/src/internal-utils/test-key-generator.ts +9 -0
  63. package/src/selectors/selector.get-selected-spans.test.ts +1 -0
  64. package/src/selectors/selector.get-selection-text.test.ts +1 -0
  65. package/src/selectors/selector.is-active-decorator.test.ts +1 -0
  66. package/src/utils/util.slice-blocks.test.ts +87 -0
  67. package/src/utils/util.slice-blocks.ts +27 -10
  68. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +0 -1
  69. package/lib/_chunks-es/selector.is-selection-collapsed.js.map +0 -1
  70. package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +0 -181
  71. package/src/editor/plugins/createWithInsertData.ts +0 -425
package/lib/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$k = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isSelectionCollapsed = require("./_chunks-cjs/selector.is-selection-collapsed.cjs"), util_isEmptyTextBlock = require("./_chunks-cjs/util.is-empty-text-block.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), blockTools = require("@portabletext/block-tools");
3
+ var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$j = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isActiveStyle = require("./_chunks-cjs/selector.is-active-style.cjs"), util_isEmptyTextBlock = require("./_chunks-cjs/util.is-empty-text-block.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
7
- var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$k), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
7
+ var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$j), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
8
8
  function createEditorSchema(portableTextType) {
9
9
  if (!portableTextType)
10
10
  throw new Error("Parameter 'portabletextType' missing (required)");
@@ -370,7 +370,7 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING
370
370
  ] }), $[1] = props.value._key, $[2] = props.value._type, $[3] = t1) : t1 = $[3], t1;
371
371
  };
372
372
  DefaultObject.displayName = "DefaultObject";
373
- const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
373
+ const debug$i = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
374
374
  const $ = reactCompilerRuntime.c(51), {
375
375
  children,
376
376
  element,
@@ -408,39 +408,39 @@ const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
408
408
  $[16] !== editor || $[17] !== element ? (t9 = (event_0) => {
409
409
  const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor);
410
410
  if (targetBlock) {
411
- IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$j("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
411
+ IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$i("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
412
412
  const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor);
413
413
  IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
414
414
  let targetPath = slateReact.ReactEditor.findPath(editor, targetBlock);
415
415
  const myPath = slateReact.ReactEditor.findPath(editor, element), isBefore = slate.Path.isBefore(myPath, targetPath);
416
416
  if (dragPosition === "bottom" && !isBefore) {
417
417
  if (targetPath[0] >= editor.children.length - 1) {
418
- debug$j("target is already at the bottom, not moving");
418
+ debug$i("target is already at the bottom, not moving");
419
419
  return;
420
420
  }
421
421
  const originalPath = targetPath;
422
- targetPath = slate.Path.next(targetPath), debug$j(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
422
+ targetPath = slate.Path.next(targetPath), debug$i(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
423
423
  }
424
424
  if (dragPosition === "top" && isBefore && targetPath[0] !== editor.children.length - 1) {
425
425
  const originalPath_0 = targetPath;
426
- targetPath = slate.Path.previous(targetPath), debug$j(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
426
+ targetPath = slate.Path.previous(targetPath), debug$i(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
427
427
  }
428
428
  if (slate.Path.equals(targetPath, myPath)) {
429
- event_0.preventDefault(), debug$j("targetPath and myPath is the same, not moving");
429
+ event_0.preventDefault(), debug$i("targetPath and myPath is the same, not moving");
430
430
  return;
431
431
  }
432
- debug$j(`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), slate.Transforms.moveNodes(editor, {
432
+ debug$i(`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), slate.Transforms.moveNodes(editor, {
433
433
  at: myPath,
434
434
  to: targetPath
435
435
  }), editor.onChange();
436
436
  return;
437
437
  }
438
- debug$j("No target element, not doing anything");
438
+ debug$i("No target element, not doing anything");
439
439
  }, $[16] = editor, $[17] = element, $[18] = t9) : t9 = $[18];
440
440
  const handleDragEnd = t9;
441
441
  let t10;
442
442
  $[19] !== editor || $[20] !== element ? (t10 = (event_1) => {
443
- IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$j("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
443
+ IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$i("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
444
444
  }, $[19] = editor, $[20] = element, $[21] = t10) : t10 = $[21];
445
445
  const handleDrop = t10;
446
446
  let t11;
@@ -457,10 +457,10 @@ const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
457
457
  let t12;
458
458
  $[26] !== blockElement || $[27] !== editor || $[28] !== handleDrag || $[29] !== isInline || $[30] !== isVoid ? (t12 = (event_3) => {
459
459
  if (!isVoid || isInline) {
460
- debug$j("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
460
+ debug$i("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
461
461
  return;
462
462
  }
463
- if (debug$j("Drag start"), IS_DRAGGING.set(editor, !0), event_3.dataTransfer && (event_3.dataTransfer.setData("application/portable-text", "something"), event_3.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
463
+ if (debug$i("Drag start"), IS_DRAGGING.set(editor, !0), event_3.dataTransfer && (event_3.dataTransfer.setData("application/portable-text", "something"), event_3.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
464
464
  let dragGhost = blockElement.cloneNode(!0);
465
465
  const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
466
466
  if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
@@ -1497,14 +1497,14 @@ function getAlphabetFromPattern(pattern) {
1497
1497
  for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
1498
1498
  return s;
1499
1499
  }
1500
- function match(text, pattern, searchLocation) {
1500
+ function match(text, pattern, searchLocation, options = {}) {
1501
1501
  if (text === null || pattern === null || searchLocation === null) throw new Error("Null input. (match())");
1502
1502
  const loc = Math.max(0, Math.min(searchLocation, text.length));
1503
1503
  if (text === pattern) return 0;
1504
1504
  if (text.length) {
1505
1505
  if (text.substring(loc, loc + pattern.length) === pattern) return loc;
1506
1506
  } else return -1;
1507
- return bitap(text, pattern, loc);
1507
+ return bitap(text, pattern, loc, options);
1508
1508
  }
1509
1509
  function diffText1(diffs) {
1510
1510
  const text = [];
@@ -1536,10 +1536,10 @@ function levenshtein(diffs) {
1536
1536
  }
1537
1537
  return leven += Math.max(insertions, deletions), leven;
1538
1538
  }
1539
- function xIndex(diffs, loc) {
1539
+ function xIndex(diffs, location) {
1540
1540
  let chars1 = 0, chars2 = 0, lastChars1 = 0, lastChars2 = 0, x;
1541
- for (x = 0; x < diffs.length && (diffs[x][0] !== DIFF_INSERT && (chars1 += diffs[x][1].length), diffs[x][0] !== DIFF_DELETE && (chars2 += diffs[x][1].length), !(chars1 > loc)); x++) lastChars1 = chars1, lastChars2 = chars2;
1542
- return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (loc - lastChars1);
1541
+ for (x = 0; x < diffs.length && (diffs[x][0] !== DIFF_INSERT && (chars1 += diffs[x][1].length), diffs[x][0] !== DIFF_DELETE && (chars2 += diffs[x][1].length), !(chars1 > location)); x++) lastChars1 = chars1, lastChars2 = chars2;
1542
+ return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (location - lastChars1);
1543
1543
  }
1544
1544
  function countUtf8Bytes(str) {
1545
1545
  let bytes = 0;
@@ -1732,7 +1732,7 @@ function isRedoing(editor) {
1732
1732
  function setIsRedoing(editor, isRedoing2) {
1733
1733
  IS_REDOING.set(editor, isRedoing2);
1734
1734
  }
1735
- const debug$i = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1735
+ const debug$h = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1736
1736
  const state = SAVING.get(editor);
1737
1737
  return state === void 0 ? !0 : state;
1738
1738
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
@@ -1745,7 +1745,7 @@ function createWithUndoRedo(options) {
1745
1745
  let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
1746
1746
  const remotePatches = getRemotePatches(editor);
1747
1747
  options.subscriptions.push(() => {
1748
- debug$i("Subscribing to patches");
1748
+ debug$h("Subscribing to patches");
1749
1749
  const sub = editorActor.on("patches", ({
1750
1750
  patches: patches2,
1751
1751
  snapshot
@@ -1754,7 +1754,7 @@ function createWithUndoRedo(options) {
1754
1754
  patches2.forEach((patch) => {
1755
1755
  if (!reset && patch.origin !== "local" && remotePatches) {
1756
1756
  if (patch.type === "unset" && patch.path.length === 0) {
1757
- debug$i("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1757
+ debug$h("Someone else cleared the content, resetting undo/redo history"), editor.history = {
1758
1758
  undos: [],
1759
1759
  redos: []
1760
1760
  }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
@@ -1770,7 +1770,7 @@ function createWithUndoRedo(options) {
1770
1770
  }), previousSnapshot = snapshot;
1771
1771
  });
1772
1772
  return () => {
1773
- debug$i("Unsubscribing to patches"), sub.unsubscribe();
1773
+ debug$h("Unsubscribing to patches"), sub.unsubscribe();
1774
1774
  };
1775
1775
  }), editor.history = {
1776
1776
  undos: [],
@@ -1809,7 +1809,7 @@ function createWithUndoRedo(options) {
1809
1809
  operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
1810
1810
  timestamp: /* @__PURE__ */ new Date()
1811
1811
  };
1812
- undos.push(newStep), debug$i("Created new undo step", step);
1812
+ undos.push(newStep), debug$h("Created new undo step", step);
1813
1813
  }
1814
1814
  for (; undos.length > UNDO_STEP_LIMIT; )
1815
1815
  undos.shift();
@@ -1826,7 +1826,7 @@ function createWithUndoRedo(options) {
1826
1826
  } = editor.history;
1827
1827
  if (undos.length > 0) {
1828
1828
  const step = undos[undos.length - 1];
1829
- if (debug$i("Undoing", step), step.operations.length > 0) {
1829
+ if (debug$h("Undoing", step), step.operations.length > 0) {
1830
1830
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
1831
1831
  let transformedOperations = step.operations;
1832
1832
  otherPatches.forEach((item) => {
@@ -1844,7 +1844,7 @@ function createWithUndoRedo(options) {
1844
1844
  });
1845
1845
  }), editor.normalize(), editor.onChange();
1846
1846
  } catch (err) {
1847
- debug$i("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1847
+ debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1848
1848
  undos: [],
1849
1849
  redos: []
1850
1850
  }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
@@ -1863,7 +1863,7 @@ function createWithUndoRedo(options) {
1863
1863
  } = editor.history;
1864
1864
  if (redos.length > 0) {
1865
1865
  const step = redos[redos.length - 1];
1866
- if (debug$i("Redoing", step), step.operations.length > 0) {
1866
+ if (debug$h("Redoing", step), step.operations.length > 0) {
1867
1867
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
1868
1868
  let transformedOperations = step.operations;
1869
1869
  otherPatches.forEach((item) => {
@@ -1880,7 +1880,7 @@ function createWithUndoRedo(options) {
1880
1880
  });
1881
1881
  }), editor.normalize(), editor.onChange();
1882
1882
  } catch (err) {
1883
- debug$i("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1883
+ debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
1884
1884
  undos: [],
1885
1885
  redos: []
1886
1886
  }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
@@ -1900,16 +1900,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
1900
1900
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
1901
1901
  _key: blk._key
1902
1902
  }, patch.path[0]));
1903
- return debug$i(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
1903
+ return debug$h(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
1904
1904
  }
1905
1905
  if (patch.type === "unset" && patch.path.length === 1) {
1906
1906
  const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
1907
1907
  _key: blk._key
1908
1908
  }, patch.path[0]));
1909
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$i("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
1909
+ return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$h("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
1910
1910
  }
1911
1911
  if (patch.type === "unset" && patch.path.length === 0)
1912
- return debug$i(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
1912
+ return debug$h(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
1913
1913
  if (patch.type === "diffMatchPatch") {
1914
1914
  const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
1915
1915
  return !operationTargetBlock || !isEqual__default.default({
@@ -2189,7 +2189,7 @@ const syncValueCallback = ({
2189
2189
  }
2190
2190
  }
2191
2191
  }
2192
- }), debug$h = debugWithName("hook:useSyncValue");
2192
+ }), debug$g = debugWithName("hook:useSyncValue");
2193
2193
  async function updateValue({
2194
2194
  context,
2195
2195
  sendBack,
@@ -2199,7 +2199,7 @@ async function updateValue({
2199
2199
  }) {
2200
2200
  let isChanged = !1, isValid = !0;
2201
2201
  const hadSelection = !!slateEditor.selection;
2202
- if ((!value || value.length === 0) && (debug$h("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
2202
+ if ((!value || value.length === 0) && (debug$g("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
2203
2203
  withoutSaving(slateEditor, () => {
2204
2204
  withoutPatching(slateEditor, () => {
2205
2205
  hadSelection && slate.Transforms.deselect(slateEditor);
@@ -2255,14 +2255,14 @@ async function updateValue({
2255
2255
  });
2256
2256
  }
2257
2257
  if (!isValid) {
2258
- debug$h("Invalid value, returning"), sendBack({
2258
+ debug$g("Invalid value, returning"), sendBack({
2259
2259
  type: "done syncing",
2260
2260
  value
2261
2261
  });
2262
2262
  return;
2263
2263
  }
2264
2264
  if (isChanged) {
2265
- debug$h("Server value changed, syncing editor");
2265
+ debug$g("Server value changed, syncing editor");
2266
2266
  try {
2267
2267
  slateEditor.onChange();
2268
2268
  } catch (err) {
@@ -2290,7 +2290,7 @@ async function updateValue({
2290
2290
  value
2291
2291
  });
2292
2292
  } else
2293
- debug$h("Server value and editor value is equal, no need to sync.");
2293
+ debug$g("Server value and editor value is equal, no need to sync.");
2294
2294
  sendBack({
2295
2295
  type: "done syncing",
2296
2296
  value
@@ -2324,7 +2324,7 @@ function syncBlock({
2324
2324
  type: "patch",
2325
2325
  patch
2326
2326
  });
2327
- })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$h.enabled && debug$h("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$h.enabled && debug$h("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
2327
+ })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$g.enabled && debug$g("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$g.enabled && debug$g("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
2328
2328
  type: "invalid value",
2329
2329
  resolution: validation.resolution,
2330
2330
  value
@@ -2332,9 +2332,9 @@ function syncBlock({
2332
2332
  }
2333
2333
  if (!oldBlock && blockValid) {
2334
2334
  const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
2335
- debug$h.enabled && debug$h("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
2335
+ debug$g.enabled && debug$g("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
2336
2336
  at: [currentBlockIndex]
2337
- }) : (debug$h("Invalid", validation), sendBack({
2337
+ }) : (debug$g("Invalid", validation), sendBack({
2338
2338
  type: "invalid value",
2339
2339
  resolution: validation.resolution,
2340
2340
  value
@@ -2362,14 +2362,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2362
2362
  const oldBlockChildrenLength = oldBlock.children.length;
2363
2363
  currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
2364
2364
  const childIndex = oldBlockChildrenLength - 1 - index;
2365
- childIndex > 0 && (debug$h("Removing child"), slate.Transforms.removeNodes(slateEditor, {
2365
+ childIndex > 0 && (debug$g("Removing child"), slate.Transforms.removeNodes(slateEditor, {
2366
2366
  at: [currentBlockIndex, childIndex]
2367
2367
  }));
2368
2368
  }), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
2369
2369
  const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
2370
2370
  if (isChildChanged)
2371
2371
  if (currentBlockChild._key === oldBlockChild?._key) {
2372
- debug$h("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
2372
+ debug$g("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
2373
2373
  at: path
2374
2374
  });
2375
2375
  const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
@@ -2386,23 +2386,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2386
2386
  }
2387
2387
  }), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
2388
2388
  at: path
2389
- }), slateEditor.onChange()) : isSpanNode || (debug$h("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
2389
+ }), slateEditor.onChange()) : isSpanNode || (debug$g("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
2390
2390
  _key: VOID_CHILD_KEY
2391
2391
  }, {
2392
2392
  at: [...path, 0],
2393
2393
  voids: !0
2394
2394
  }));
2395
- } else oldBlockChild ? (debug$h("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
2395
+ } else oldBlockChild ? (debug$g("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
2396
2396
  at: [currentBlockIndex, currentBlockChildIndex]
2397
2397
  }), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2398
2398
  at: [currentBlockIndex, currentBlockChildIndex]
2399
- }), slateEditor.onChange()) : oldBlockChild || (debug$h("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2399
+ }), slateEditor.onChange()) : oldBlockChild || (debug$g("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
2400
2400
  at: [currentBlockIndex, currentBlockChildIndex]
2401
2401
  }), slateEditor.onChange());
2402
2402
  });
2403
2403
  }
2404
2404
  }
2405
- const debug$g = debugWithName("component:PortableTextEditor:Synchronizer");
2405
+ const debug$f = debugWithName("component:PortableTextEditor:Synchronizer");
2406
2406
  function Synchronizer(props) {
2407
2407
  const $ = reactCompilerRuntime.c(40), {
2408
2408
  editorActor,
@@ -2473,19 +2473,19 @@ function Synchronizer(props) {
2473
2473
  }, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), React.useEffect(t11, t12);
2474
2474
  let t13, t14;
2475
2475
  $[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
2476
- debug$g("Value from props changed, syncing new value"), syncActorRef.send({
2476
+ debug$f("Value from props changed, syncing new value"), syncActorRef.send({
2477
2477
  type: "update value",
2478
2478
  value
2479
2479
  });
2480
2480
  }, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), React.useEffect(t13, t14);
2481
2481
  let t15;
2482
2482
  $[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
2483
- debug$g("Subscribing to patch events");
2483
+ debug$f("Subscribing to patch events");
2484
2484
  const sub = editorActor.on("patch", (event_1) => {
2485
2485
  mutationActorRef.send(event_1);
2486
2486
  });
2487
2487
  return () => {
2488
- debug$g("Unsubscribing to patch events"), sub.unsubscribe();
2488
+ debug$f("Unsubscribing to patch events"), sub.unsubscribe();
2489
2489
  };
2490
2490
  }, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
2491
2491
  let t16;
@@ -2500,11 +2500,255 @@ function _temp(s) {
2500
2500
  return s.context.value;
2501
2501
  }
2502
2502
  Synchronizer.displayName = "Synchronizer";
2503
- const debug$f = debugWithName("operationToPatches");
2503
+ const converterJson = {
2504
+ serialize: ({
2505
+ context,
2506
+ event
2507
+ }) => {
2508
+ const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
2509
+ return portableTextConverter ? {
2510
+ ...portableTextConverter.serialize({
2511
+ context,
2512
+ event
2513
+ }),
2514
+ mimeType: "application/json",
2515
+ originEvent: event.originEvent
2516
+ } : {
2517
+ type: "serialization.failure",
2518
+ mimeType: "application/json",
2519
+ originEvent: event.originEvent,
2520
+ reason: "No application/x-portable-text Converter found"
2521
+ };
2522
+ },
2523
+ deserialize: ({
2524
+ context,
2525
+ event
2526
+ }) => {
2527
+ const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
2528
+ return portableTextConverter ? {
2529
+ ...portableTextConverter.deserialize({
2530
+ context,
2531
+ event
2532
+ }),
2533
+ mimeType: "application/json"
2534
+ } : {
2535
+ type: "deserialization.failure",
2536
+ mimeType: "application/json",
2537
+ reason: "No application/x-portable-text Converter found"
2538
+ };
2539
+ },
2540
+ mimeType: "application/json"
2541
+ };
2542
+ function isTypedObject(object) {
2543
+ return isRecord(object) && typeof object._type == "string";
2544
+ }
2545
+ function isRecord(value) {
2546
+ return !!value && (typeof value == "object" || typeof value == "function");
2547
+ }
2548
+ function parseBlock({
2549
+ context,
2550
+ block
2551
+ }) {
2552
+ if (!isTypedObject(block) || block._type !== context.schema.block.name && !context.schema.blockObjects.some((blockObject) => blockObject.name === block._type))
2553
+ return;
2554
+ if (!types.isPortableTextTextBlock(block))
2555
+ return {
2556
+ ...block,
2557
+ _key: context.keyGenerator()
2558
+ };
2559
+ const markDefKeyMap = /* @__PURE__ */ new Map(), markDefs = (block.markDefs ?? []).flatMap((markDef) => {
2560
+ if (context.schema.annotations.some((annotation) => annotation.name === markDef._type)) {
2561
+ const _key = context.keyGenerator();
2562
+ return markDefKeyMap.set(markDef._key, _key), [{
2563
+ ...markDef,
2564
+ _key
2565
+ }];
2566
+ }
2567
+ return [];
2568
+ }), children = block.children.flatMap((child) => {
2569
+ if (!isTypedObject(child))
2570
+ return [];
2571
+ if (child._type !== context.schema.span.name && !context.schema.inlineObjects.some((inlineObject) => inlineObject.name === child._type))
2572
+ return [];
2573
+ if (!types.isPortableTextSpan(child))
2574
+ return [{
2575
+ ...child,
2576
+ _key: context.keyGenerator()
2577
+ }];
2578
+ const marks = (child.marks ?? []).flatMap((mark) => markDefKeyMap.has(mark) ? [markDefKeyMap.get(mark)] : context.schema.decorators.some((decorator) => decorator.value === mark) ? [mark] : []);
2579
+ return [{
2580
+ ...child,
2581
+ _key: context.keyGenerator(),
2582
+ marks
2583
+ }];
2584
+ }), parsedBlock = {
2585
+ ...block,
2586
+ _key: context.keyGenerator(),
2587
+ children: children.length > 0 ? children : [{
2588
+ _key: context.keyGenerator(),
2589
+ _type: context.schema.span.name,
2590
+ text: "",
2591
+ marks: []
2592
+ }],
2593
+ markDefs
2594
+ };
2595
+ if (!context.schema.styles.find((style) => style.value === block.style)) {
2596
+ const defaultStyle = context.schema.styles[0].value;
2597
+ defaultStyle !== void 0 ? parsedBlock.style = defaultStyle : delete parsedBlock.style;
2598
+ }
2599
+ return context.schema.lists.find((list) => list.value === block.listItem) || (delete parsedBlock.listItem, delete parsedBlock.level), parsedBlock;
2600
+ }
2601
+ const converterPortableText = {
2602
+ serialize: ({
2603
+ context,
2604
+ event
2605
+ }) => {
2606
+ if (!context.selection)
2607
+ return {
2608
+ type: "serialization.failure",
2609
+ mimeType: "application/x-portable-text",
2610
+ originEvent: event.originEvent,
2611
+ reason: "No selection"
2612
+ };
2613
+ const blocks = util_sliceBlocks.sliceBlocks({
2614
+ blocks: context.value,
2615
+ selection: context.selection
2616
+ });
2617
+ return {
2618
+ type: "serialization.success",
2619
+ data: JSON.stringify(blocks),
2620
+ mimeType: "application/x-portable-text",
2621
+ originEvent: event.originEvent
2622
+ };
2623
+ },
2624
+ deserialize: ({
2625
+ context,
2626
+ event
2627
+ }) => {
2628
+ const blocks = JSON.parse(event.data);
2629
+ if (!Array.isArray(blocks))
2630
+ return {
2631
+ type: "deserialization.failure",
2632
+ mimeType: "application/x-portable-text",
2633
+ reason: "Data is not an array"
2634
+ };
2635
+ const parsedBlocks = blocks.flatMap((block) => {
2636
+ const parsedBlock = parseBlock({
2637
+ context,
2638
+ block
2639
+ });
2640
+ return parsedBlock ? [parsedBlock] : [];
2641
+ });
2642
+ return parsedBlocks.length === 0 && blocks.length > 0 ? {
2643
+ type: "deserialization.failure",
2644
+ mimeType: "application/x-portable-text",
2645
+ reason: "No blocks were parsed"
2646
+ } : {
2647
+ type: "deserialization.success",
2648
+ data: parsedBlocks,
2649
+ mimeType: "application/x-portable-text"
2650
+ };
2651
+ },
2652
+ mimeType: "application/x-portable-text"
2653
+ }, converterTextHtml = {
2654
+ serialize: ({
2655
+ context,
2656
+ event
2657
+ }) => {
2658
+ if (!context.selection)
2659
+ return {
2660
+ type: "serialization.failure",
2661
+ mimeType: "text/html",
2662
+ originEvent: event.originEvent,
2663
+ reason: "No selection"
2664
+ };
2665
+ const blocks = util_sliceBlocks.sliceBlocks({
2666
+ blocks: context.value,
2667
+ selection: context.selection
2668
+ }), html = toHtml.toHTML(blocks, {
2669
+ onMissingComponent: !1,
2670
+ components: {
2671
+ unknownType: ({
2672
+ children
2673
+ }) => children !== void 0 ? `${children}` : ""
2674
+ }
2675
+ });
2676
+ return html === "" ? {
2677
+ type: "serialization.failure",
2678
+ mimeType: "text/html",
2679
+ originEvent: event.originEvent,
2680
+ reason: "Serialized HTML is empty"
2681
+ } : {
2682
+ type: "serialization.success",
2683
+ data: html,
2684
+ mimeType: "text/html",
2685
+ originEvent: event.originEvent
2686
+ };
2687
+ },
2688
+ deserialize: ({
2689
+ context,
2690
+ event
2691
+ }) => ({
2692
+ type: "deserialization.success",
2693
+ data: blockTools.htmlToBlocks(event.data, context.schema.portableText, {
2694
+ keyGenerator: context.keyGenerator,
2695
+ unstable_whitespaceOnPasteMode: context.schema.block.options.unstable_whitespaceOnPasteMode
2696
+ }),
2697
+ mimeType: "text/html"
2698
+ }),
2699
+ mimeType: "text/html"
2700
+ }, converterTextPlain = {
2701
+ mimeType: "text/plain",
2702
+ serialize: ({
2703
+ context,
2704
+ event
2705
+ }) => context.selection ? {
2706
+ type: "serialization.success",
2707
+ data: util_sliceBlocks.sliceBlocks({
2708
+ blocks: context.value,
2709
+ selection: context.selection
2710
+ }).map((block) => types.isPortableTextTextBlock(block) ? block.children.map((child) => child._type === context.schema.span.name ? child.text : `[${context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]`).join("") : `[${context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]`).join(`
2711
+
2712
+ `),
2713
+ mimeType: "text/plain",
2714
+ originEvent: event.originEvent
2715
+ } : {
2716
+ type: "serialization.failure",
2717
+ mimeType: "text/plain",
2718
+ originEvent: event.originEvent,
2719
+ reason: "No selection"
2720
+ },
2721
+ deserialize: ({
2722
+ context,
2723
+ event
2724
+ }) => {
2725
+ const textToHtml = `<html><body>${escapeHtml(event.data).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`;
2726
+ return {
2727
+ type: "deserialization.success",
2728
+ data: blockTools.htmlToBlocks(textToHtml, context.schema.portableText, {
2729
+ keyGenerator: context.keyGenerator
2730
+ }),
2731
+ mimeType: "text/plain"
2732
+ };
2733
+ }
2734
+ }, entityMap = {
2735
+ "&": "&amp;",
2736
+ "<": "&lt;",
2737
+ ">": "&gt;",
2738
+ '"': "&quot;",
2739
+ "'": "&#39;",
2740
+ "/": "&#x2F;",
2741
+ "`": "&#x60;",
2742
+ "=": "&#x3D;"
2743
+ };
2744
+ function escapeHtml(str) {
2745
+ return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
2746
+ }
2747
+ const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$e = debugWithName("operationToPatches");
2504
2748
  function createOperationToPatches(types2) {
2505
2749
  const textBlockName = types2.block.name;
2506
2750
  function insertTextPatch(editor, operation, beforeValue) {
2507
- debug$f.enabled && debug$f("Operation", JSON.stringify(operation, null, 2));
2751
+ debug$e.enabled && debug$e("Operation", JSON.stringify(operation, null, 2));
2508
2752
  const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
2509
2753
  if (!block)
2510
2754
  throw new Error("Could not find block");
@@ -2597,7 +2841,7 @@ function createOperationToPatches(types2) {
2597
2841
  _key: block.children[operation.path[1] - 1]._key
2598
2842
  }])];
2599
2843
  }
2600
- return debug$f("Something was inserted into a void block. Not producing editor patches."), [];
2844
+ return debug$e("Something was inserted into a void block. Not producing editor patches."), [];
2601
2845
  }
2602
2846
  function splitNodePatch(editor, operation, beforeValue) {
2603
2847
  const patches$1 = [], splitBlock = editor.children[operation.path[0]];
@@ -2655,9 +2899,9 @@ function createOperationToPatches(types2) {
2655
2899
  _key: block._key
2656
2900
  }, "children", {
2657
2901
  _key: spanToRemove._key
2658
- }])] : (debug$f("Span not found in editor trying to remove node"), []);
2902
+ }])] : (debug$e("Span not found in editor trying to remove node"), []);
2659
2903
  } else
2660
- return debug$f("Not creating patch inside object block"), [];
2904
+ return debug$e("Not creating patch inside object block"), [];
2661
2905
  }
2662
2906
  function mergeNodePatch(editor, operation, beforeValue) {
2663
2907
  const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
@@ -2683,7 +2927,7 @@ function createOperationToPatches(types2) {
2683
2927
  _key: removedSpan._key
2684
2928
  }])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
2685
2929
  } else
2686
- debug$f("Void nodes can't be merged, not creating any patches");
2930
+ debug$e("Void nodes can't be merged, not creating any patches");
2687
2931
  return patches$1;
2688
2932
  }
2689
2933
  function moveNodePatch(editor, operation, beforeValue) {
@@ -2737,123 +2981,54 @@ function createWithEventListeners(editorActor, subscriptions) {
2737
2981
  subscriptions.push(() => {
2738
2982
  const subscription = editorActor.on("*", (event) => {
2739
2983
  switch (event.type) {
2740
- case "annotation.add": {
2741
- editorActor.send({
2742
- type: "behavior event",
2743
- behaviorEvent: {
2744
- type: "annotation.add",
2745
- annotation: event.annotation
2746
- },
2747
- editor
2748
- });
2749
- break;
2750
- }
2751
- case "annotation.remove": {
2752
- editorActor.send({
2753
- type: "behavior event",
2754
- behaviorEvent: {
2755
- type: "annotation.remove",
2756
- annotation: event.annotation
2757
- },
2758
- editor
2759
- });
2760
- break;
2761
- }
2762
- case "blur": {
2763
- editorActor.send({
2764
- type: "behavior event",
2765
- behaviorEvent: {
2766
- type: "blur"
2767
- },
2768
- editor
2769
- });
2770
- break;
2771
- }
2772
- case "custom.*": {
2984
+ case "custom.*":
2773
2985
  editorActor.send({
2774
2986
  type: "custom behavior event",
2775
2987
  behaviorEvent: event.event,
2776
2988
  editor
2777
2989
  });
2778
2990
  break;
2779
- }
2780
- case "decorator.toggle": {
2991
+ case "annotation.add":
2992
+ case "annotation.remove":
2993
+ case "annotation.toggle":
2994
+ case "blur":
2995
+ case "data transfer.set":
2996
+ case "decorator.add":
2997
+ case "decorator.remove":
2998
+ case "decorator.toggle":
2999
+ case "delete.backward":
3000
+ case "delete.block":
3001
+ case "delete.forward":
3002
+ case "delete.text":
3003
+ case "deserialization.failure":
3004
+ case "deserialization.success":
3005
+ case "focus":
3006
+ case "insert.block object":
3007
+ case "insert.inline object":
3008
+ case "insert.span":
3009
+ case "insert.text block":
3010
+ case "list item.add":
3011
+ case "list item.remove":
3012
+ case "list item.toggle":
3013
+ case "move.block":
3014
+ case "move.block down":
3015
+ case "move.block up":
3016
+ case "select":
3017
+ case "select.next block":
3018
+ case "select.previous block":
3019
+ case "serialization.failure":
3020
+ case "serialization.success":
3021
+ case "style.add":
3022
+ case "style.remove":
3023
+ case "style.toggle":
3024
+ case "text block.set":
3025
+ case "text block.unset":
2781
3026
  editorActor.send({
2782
3027
  type: "behavior event",
2783
- behaviorEvent: {
2784
- type: "decorator.toggle",
2785
- decorator: event.decorator
2786
- },
3028
+ behaviorEvent: event,
2787
3029
  editor
2788
3030
  });
2789
3031
  break;
2790
- }
2791
- case "focus": {
2792
- editorActor.send({
2793
- type: "behavior event",
2794
- behaviorEvent: {
2795
- type: "focus"
2796
- },
2797
- editor
2798
- });
2799
- break;
2800
- }
2801
- case "insert.block object": {
2802
- editorActor.send({
2803
- type: "behavior event",
2804
- behaviorEvent: {
2805
- type: "insert.block object",
2806
- placement: event.placement,
2807
- blockObject: event.blockObject
2808
- },
2809
- editor
2810
- });
2811
- break;
2812
- }
2813
- case "insert.inline object": {
2814
- editorActor.send({
2815
- type: "behavior event",
2816
- behaviorEvent: {
2817
- type: "insert.inline object",
2818
- inlineObject: event.inlineObject
2819
- },
2820
- editor
2821
- });
2822
- break;
2823
- }
2824
- case "list item.toggle": {
2825
- editorActor.send({
2826
- type: "behavior event",
2827
- behaviorEvent: {
2828
- type: "list item.toggle",
2829
- listItem: event.listItem
2830
- },
2831
- editor
2832
- });
2833
- break;
2834
- }
2835
- case "select": {
2836
- editorActor.send({
2837
- type: "behavior event",
2838
- behaviorEvent: {
2839
- type: "select",
2840
- selection: event.selection
2841
- },
2842
- editor
2843
- });
2844
- break;
2845
- }
2846
- case "style.toggle": {
2847
- editorActor.send({
2848
- type: "behavior event",
2849
- behaviorEvent: {
2850
- type: "style.toggle",
2851
- style: event.style
2852
- },
2853
- editor
2854
- });
2855
- break;
2856
- }
2857
3032
  }
2858
3033
  });
2859
3034
  return () => {
@@ -2864,9 +3039,11 @@ function createWithEventListeners(editorActor, subscriptions) {
2864
3039
  deleteBackward,
2865
3040
  deleteForward,
2866
3041
  insertBreak,
3042
+ insertData,
2867
3043
  insertSoftBreak,
2868
3044
  insertText,
2869
- select
3045
+ select,
3046
+ setFragmentData
2870
3047
  } = editor;
2871
3048
  return editor.deleteBackward = (unit) => {
2872
3049
  if (isApplyingBehaviorActions(editor)) {
@@ -2906,6 +3083,19 @@ function createWithEventListeners(editorActor, subscriptions) {
2906
3083
  },
2907
3084
  editor
2908
3085
  });
3086
+ }, editor.insertData = (dataTransfer) => {
3087
+ if (isApplyingBehaviorActions(editor)) {
3088
+ insertData(dataTransfer);
3089
+ return;
3090
+ }
3091
+ editorActor.send({
3092
+ type: "behavior event",
3093
+ behaviorEvent: {
3094
+ type: "deserialize",
3095
+ dataTransfer
3096
+ },
3097
+ editor
3098
+ });
2909
3099
  }, editor.insertSoftBreak = () => {
2910
3100
  if (isApplyingBehaviorActions(editor)) {
2911
3101
  insertSoftBreak();
@@ -2952,6 +3142,24 @@ function createWithEventListeners(editorActor, subscriptions) {
2952
3142
  select(location);
2953
3143
  }
2954
3144
  });
3145
+ }, editor.setFragmentData = (dataTransfer, originEvent) => {
3146
+ if (originEvent === "drag") {
3147
+ setFragmentData(dataTransfer);
3148
+ return;
3149
+ }
3150
+ if (isApplyingBehaviorActions(editor)) {
3151
+ setFragmentData(dataTransfer);
3152
+ return;
3153
+ }
3154
+ dataTransfer.clearData(), editorActor.send({
3155
+ type: "behavior event",
3156
+ behaviorEvent: {
3157
+ type: "serialize",
3158
+ dataTransfer,
3159
+ originEvent: originEvent ?? "unknown"
3160
+ },
3161
+ editor
3162
+ });
2955
3163
  }, editor;
2956
3164
  };
2957
3165
  }
@@ -3049,13 +3257,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
3049
3257
  }, editor;
3050
3258
  };
3051
3259
  }
3052
- const debug$e = debugWithName("applyPatches"), debugVerbose = debug$e.enabled && !0;
3260
+ const debug$d = debugWithName("applyPatches"), debugVerbose = debug$d.enabled && !0;
3053
3261
  function createApplyPatch(schemaTypes) {
3054
3262
  return (editor, patch) => {
3055
3263
  let changed = !1;
3056
- debugVerbose && (debug$e(`
3264
+ debugVerbose && (debug$d(`
3057
3265
 
3058
- NEW PATCH =============================================================`), debug$e(JSON.stringify(patch, null, 2)));
3266
+ NEW PATCH =============================================================`), debug$d(JSON.stringify(patch, null, 2)));
3059
3267
  try {
3060
3268
  switch (patch.type) {
3061
3269
  case "insert":
@@ -3071,7 +3279,7 @@ NEW PATCH =============================================================`), debug
3071
3279
  changed = diffMatchPatch(editor, patch);
3072
3280
  break;
3073
3281
  default:
3074
- debug$e("Unhandled patch", patch.type);
3282
+ debug$d("Unhandled patch", patch.type);
3075
3283
  }
3076
3284
  } catch (err) {
3077
3285
  console.error(err);
@@ -3086,9 +3294,9 @@ function diffMatchPatch(editor, patch) {
3086
3294
  childPath
3087
3295
  } = findBlockAndChildFromPath(editor, patch.path);
3088
3296
  if (!block)
3089
- return debug$e("Block not found"), !1;
3297
+ return debug$d("Block not found"), !1;
3090
3298
  if (!child || !childPath)
3091
- return debug$e("Child not found"), !1;
3299
+ return debug$d("Child not found"), !1;
3092
3300
  if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
3093
3301
  return !1;
3094
3302
  const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
@@ -3118,9 +3326,9 @@ function insertPatch(editor, patch, schemaTypes) {
3118
3326
  childPath: targetChildPath
3119
3327
  } = findBlockAndChildFromPath(editor, patch.path);
3120
3328
  if (!targetBlock || !targetBlockPath)
3121
- return debug$e("Block not found"), !1;
3329
+ return debug$d("Block not found"), !1;
3122
3330
  if (patch.path.length > 1 && patch.path[1] !== "children")
3123
- return debug$e("Ignoring patch targeting void value"), !1;
3331
+ return debug$d("Ignoring patch targeting void value"), !1;
3124
3332
  if (patch.path.length === 1) {
3125
3333
  const {
3126
3334
  items: items2,
@@ -3128,7 +3336,7 @@ function insertPatch(editor, patch, schemaTypes) {
3128
3336
  } = patch, blocksToInsert = toSlateValue(items2, {
3129
3337
  schemaTypes
3130
3338
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
3131
- return debug$e(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
3339
+ return debug$d(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
3132
3340
  at: [normalizedIdx2]
3133
3341
  }), debugState(editor, "after"), !0;
3134
3342
  }
@@ -3137,14 +3345,14 @@ function insertPatch(editor, patch, schemaTypes) {
3137
3345
  position
3138
3346
  } = patch;
3139
3347
  if (!targetChild || !targetChildPath)
3140
- return debug$e("Child not found"), !1;
3348
+ return debug$d("Child not found"), !1;
3141
3349
  const childrenToInsert = targetBlock && toSlateValue([{
3142
3350
  ...targetBlock,
3143
3351
  children: items
3144
3352
  }], {
3145
3353
  schemaTypes
3146
3354
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
3147
- return debug$e(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
3355
+ return debug$d(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
3148
3356
  at: childInsertPath
3149
3357
  }), debugState(editor, "after"), !0;
3150
3358
  }
@@ -3158,14 +3366,14 @@ function setPatch(editor, patch) {
3158
3366
  childPath
3159
3367
  } = findBlockAndChildFromPath(editor, patch.path);
3160
3368
  if (!block)
3161
- return debug$e("Block not found"), !1;
3369
+ return debug$d("Block not found"), !1;
3162
3370
  const isTextBlock = editor.isTextBlock(block);
3163
3371
  if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
3164
- return debug$e("Ignoring setting void value"), !1;
3372
+ return debug$d("Ignoring setting void value"), !1;
3165
3373
  if (debugState(editor, "before"), isTextBlock && child && childPath) {
3166
3374
  if (slate.Text.isText(value) && slate.Text.isText(child)) {
3167
3375
  const newText = child.text;
3168
- value.text !== newText && (debug$e("Setting text property"), editor.apply({
3376
+ value.text !== newText && (debug$d("Setting text property"), editor.apply({
3169
3377
  type: "remove_text",
3170
3378
  path: childPath,
3171
3379
  offset: 0,
@@ -3177,7 +3385,7 @@ function setPatch(editor, patch) {
3177
3385
  text: value.text
3178
3386
  }), editor.onChange());
3179
3387
  } else
3180
- debug$e("Setting non-text property"), editor.apply({
3388
+ debug$d("Setting non-text property"), editor.apply({
3181
3389
  type: "set_node",
3182
3390
  path: childPath,
3183
3391
  properties: {},
@@ -3185,7 +3393,7 @@ function setPatch(editor, patch) {
3185
3393
  });
3186
3394
  return !0;
3187
3395
  } else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
3188
- debug$e("Setting block property");
3396
+ debug$d("Setting block property");
3189
3397
  const {
3190
3398
  children,
3191
3399
  ...nextRest
@@ -3202,7 +3410,7 @@ function setPatch(editor, patch) {
3202
3410
  ...prevRest
3203
3411
  },
3204
3412
  newProperties: nextRest
3205
- }), debug$e("Setting children"), block.children.forEach((c, cIndex) => {
3413
+ }), debug$d("Setting children"), block.children.forEach((c, cIndex) => {
3206
3414
  editor.apply({
3207
3415
  type: "remove_node",
3208
3416
  path: blockPath.concat(block.children.length - 1 - cIndex),
@@ -3228,7 +3436,7 @@ function setPatch(editor, patch) {
3228
3436
  }
3229
3437
  function unsetPatch(editor, patch) {
3230
3438
  if (patch.path.length === 0) {
3231
- debug$e("Removing everything"), debugState(editor, "before");
3439
+ debug$d("Removing everything"), debugState(editor, "before");
3232
3440
  const previousSelection = editor.selection;
3233
3441
  return slate.Transforms.deselect(editor), editor.children.forEach((_child, i) => {
3234
3442
  slate.Transforms.removeNodes(editor, {
@@ -3255,13 +3463,13 @@ function unsetPatch(editor, patch) {
3255
3463
  } = findBlockAndChildFromPath(editor, patch.path);
3256
3464
  if (patch.path.length === 1) {
3257
3465
  if (!block || !blockPath)
3258
- return debug$e("Block not found"), !1;
3466
+ return debug$d("Block not found"), !1;
3259
3467
  const blockIndex = blockPath[0];
3260
- return debug$e(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
3468
+ return debug$d(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
3261
3469
  at: [blockIndex]
3262
3470
  }), debugState(editor, "after"), !0;
3263
3471
  }
3264
- return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$e("Child not found"), !1) : (debug$e(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$e(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
3472
+ return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$d("Child not found"), !1) : (debug$d(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$d(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
3265
3473
  at: childPath
3266
3474
  }), debugState(editor, "after"), !0) : !1;
3267
3475
  }
@@ -3269,7 +3477,7 @@ function isKeyedSegment(segment) {
3269
3477
  return typeof segment == "object" && "_key" in segment;
3270
3478
  }
3271
3479
  function debugState(editor, stateName) {
3272
- debugVerbose && (debug$e(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$e(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
3480
+ debugVerbose && (debug$d(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$d(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
3273
3481
  }
3274
3482
  function findBlockFromPath(editor, path) {
3275
3483
  let blockIndex = -1;
@@ -3311,7 +3519,7 @@ function findBlockAndChildFromPath(editor, path) {
3311
3519
  childPath: void 0
3312
3520
  };
3313
3521
  }
3314
- const debug$d = debugWithName("plugin:withPatches");
3522
+ const debug$c = debugWithName("plugin:withPatches");
3315
3523
  function createWithPatches({
3316
3524
  editorActor,
3317
3525
  patchFunctions,
@@ -3337,7 +3545,7 @@ function createWithPatches({
3337
3545
  withoutPatching(editor, () => {
3338
3546
  withoutSaving(editor, () => {
3339
3547
  patches2.forEach((patch) => {
3340
- debug$d.enabled && debug$d(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
3548
+ debug$c.enabled && debug$c(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
3341
3549
  });
3342
3550
  });
3343
3551
  });
@@ -3350,10 +3558,10 @@ function createWithPatches({
3350
3558
  remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
3351
3559
  };
3352
3560
  return subscriptions.push(() => {
3353
- debug$d("Subscribing to remote patches");
3561
+ debug$c("Subscribing to remote patches");
3354
3562
  const sub = editorActor.on("patches", handlePatches);
3355
3563
  return () => {
3356
- debug$d("Unsubscribing to remote patches"), sub.unsubscribe();
3564
+ debug$c("Unsubscribing to remote patches"), sub.unsubscribe();
3357
3565
  };
3358
3566
  }), editor.apply = (operation) => {
3359
3567
  let patches$1 = [];
@@ -3404,7 +3612,7 @@ function createWithPatches({
3404
3612
  }, editor;
3405
3613
  };
3406
3614
  }
3407
- const debug$c = debugWithName("plugin:withPlaceholderBlock");
3615
+ const debug$b = debugWithName("plugin:withPlaceholderBlock");
3408
3616
  function createWithPlaceholderBlock(editorActor) {
3409
3617
  return function(editor) {
3410
3618
  const {
@@ -3429,7 +3637,7 @@ function createWithPlaceholderBlock(editorActor) {
3429
3637
  const node = op.node;
3430
3638
  if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
3431
3639
  const nextPath = slate.Path.next(op.path);
3432
- editor.children[nextPath[0]] || (debug$c("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
3640
+ editor.children[nextPath[0]] || (debug$b("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
3433
3641
  decorators: []
3434
3642
  })));
3435
3643
  }
@@ -3438,7 +3646,7 @@ function createWithPlaceholderBlock(editorActor) {
3438
3646
  }, editor;
3439
3647
  };
3440
3648
  }
3441
- const debug$b = debugWithName("plugin:withPortableTextBlockStyle");
3649
+ const debug$a = debugWithName("plugin:withPortableTextBlockStyle");
3442
3650
  function createWithPortableTextBlockStyle(editorActor, types2) {
3443
3651
  const defaultStyle = types2.styles[0].value;
3444
3652
  return function(editor) {
@@ -3451,7 +3659,7 @@ function createWithPortableTextBlockStyle(editorActor, types2) {
3451
3659
  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)) {
3452
3660
  const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
3453
3661
  if (slate.Text.isText(child) && child.text === "") {
3454
- debug$b(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
3662
+ debug$a(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
3455
3663
  type: "normalizing"
3456
3664
  }), slate.Transforms.setNodes(editor, {
3457
3665
  style: defaultStyle
@@ -3511,7 +3719,7 @@ function getNextSpan({
3511
3719
  }
3512
3720
  return nextSpan;
3513
3721
  }
3514
- const debug$a = debugWithName("plugin:withPortableTextMarkModel");
3722
+ const debug$9 = debugWithName("plugin:withPortableTextMarkModel");
3515
3723
  function createWithPortableTextMarkModel(editorActor, types2) {
3516
3724
  return function(editor) {
3517
3725
  const {
@@ -3525,7 +3733,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3525
3733
  for (const [child, childPath] of children) {
3526
3734
  const nextNode = node.children[childPath[1] + 1];
3527
3735
  if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
3528
- debug$a("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3736
+ debug$9("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3529
3737
  type: "normalizing"
3530
3738
  }), slate.Transforms.mergeNodes(editor, {
3531
3739
  at: [childPath[0], childPath[1] + 1],
@@ -3538,7 +3746,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3538
3746
  }
3539
3747
  }
3540
3748
  if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
3541
- debug$a("Adding .markDefs to block node"), editorActor.send({
3749
+ debug$9("Adding .markDefs to block node"), editorActor.send({
3542
3750
  type: "normalizing"
3543
3751
  }), slate.Transforms.setNodes(editor, {
3544
3752
  markDefs: []
@@ -3550,7 +3758,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3550
3758
  return;
3551
3759
  }
3552
3760
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
3553
- debug$a("Adding .marks to span node"), editorActor.send({
3761
+ debug$9("Adding .marks to span node"), editorActor.send({
3554
3762
  type: "normalizing"
3555
3763
  }), slate.Transforms.setNodes(editor, {
3556
3764
  marks: []
@@ -3564,7 +3772,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3564
3772
  if (editor.isTextSpan(node)) {
3565
3773
  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));
3566
3774
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
3567
- debug$a("Removing annotations from empty span node"), editorActor.send({
3775
+ debug$9("Removing annotations from empty span node"), editorActor.send({
3568
3776
  type: "normalizing"
3569
3777
  }), slate.Transforms.setNodes(editor, {
3570
3778
  marks: node.marks?.filter((mark) => decorators2.includes(mark))
@@ -3582,7 +3790,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3582
3790
  if (editor.isTextSpan(child)) {
3583
3791
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
3584
3792
  if (orphanedAnnotations.length > 0) {
3585
- debug$a("Removing orphaned annotations from span node"), editorActor.send({
3793
+ debug$9("Removing orphaned annotations from span node"), editorActor.send({
3586
3794
  type: "normalizing"
3587
3795
  }), slate.Transforms.setNodes(editor, {
3588
3796
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3600,7 +3808,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3600
3808
  if (editor.isTextBlock(block)) {
3601
3809
  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));
3602
3810
  if (orphanedAnnotations.length > 0) {
3603
- debug$a("Removing orphaned annotations from span node"), editorActor.send({
3811
+ debug$9("Removing orphaned annotations from span node"), editorActor.send({
3604
3812
  type: "normalizing"
3605
3813
  }), slate.Transforms.setNodes(editor, {
3606
3814
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3618,7 +3826,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3618
3826
  for (const markDef of markDefs)
3619
3827
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
3620
3828
  if (markDefs.length !== newMarkDefs.length) {
3621
- debug$a("Removing duplicate markDefs"), editorActor.send({
3829
+ debug$9("Removing duplicate markDefs"), editorActor.send({
3622
3830
  type: "normalizing"
3623
3831
  }), slate.Transforms.setNodes(editor, {
3624
3832
  markDefs: newMarkDefs
@@ -3633,7 +3841,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3633
3841
  if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
3634
3842
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
3635
3843
  if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
3636
- debug$a("Removing markDef not in use"), editorActor.send({
3844
+ debug$9("Removing markDef not in use"), editorActor.send({
3637
3845
  type: "normalizing"
3638
3846
  }), slate.Transforms.setNodes(editor, {
3639
3847
  markDefs: newMarkDefs
@@ -3850,7 +4058,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
3850
4058
  const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
3851
4059
  if (editor.isTextBlock(targetBlock)) {
3852
4060
  const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
3853
- debug$a("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
4061
+ debug$9("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
3854
4062
  markDefs: newMarkDefs
3855
4063
  }, {
3856
4064
  at: targetPath,
@@ -4050,7 +4258,7 @@ function createWithPortableTextSelections(editorActor, types2) {
4050
4258
  }, editor;
4051
4259
  };
4052
4260
  }
4053
- const debug$9 = debugWithName("plugin:withSchemaTypes");
4261
+ const debug$8 = debugWithName("plugin:withSchemaTypes");
4054
4262
  function createWithSchemaTypes({
4055
4263
  editorActor,
4056
4264
  schemaTypes
@@ -4063,7 +4271,7 @@ function createWithSchemaTypes({
4063
4271
  return editor.normalizeNode = (entry) => {
4064
4272
  const [node, path] = entry;
4065
4273
  if (node._type === void 0 && path.length === 2) {
4066
- debug$9("Setting span type on text node without a type");
4274
+ debug$8("Setting span type on text node without a type");
4067
4275
  const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
4068
4276
  editorActor.send({
4069
4277
  type: "normalizing"
@@ -4079,7 +4287,7 @@ function createWithSchemaTypes({
4079
4287
  return;
4080
4288
  }
4081
4289
  if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
4082
- debug$9("Setting missing key on child node without a key");
4290
+ debug$8("Setting missing key on child node without a key");
4083
4291
  const key = editorActor.getSnapshot().context.keyGenerator();
4084
4292
  editorActor.send({
4085
4293
  type: "normalizing"
@@ -4096,7 +4304,7 @@ function createWithSchemaTypes({
4096
4304
  }, editor;
4097
4305
  };
4098
4306
  }
4099
- const debug$8 = debugWithName("plugin:withUtils");
4307
+ const debug$7 = debugWithName("plugin:withUtils");
4100
4308
  function createWithUtils({
4101
4309
  editorActor,
4102
4310
  schemaTypes
@@ -4111,14 +4319,14 @@ function createWithUtils({
4111
4319
  depth: 2
4112
4320
  });
4113
4321
  if (!textNode || !slate.Text.isText(textNode) || textNode.text.length === 0) {
4114
- debug$8("pteExpandToWord: Can't expand to word here");
4322
+ debug$7("pteExpandToWord: Can't expand to word here");
4115
4323
  return;
4116
4324
  }
4117
4325
  const {
4118
4326
  focus
4119
4327
  } = 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);
4120
4328
  if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
4121
- debug$8("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
4329
+ debug$7("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
4122
4330
  anchor: {
4123
4331
  ...selection.anchor,
4124
4332
  offset: newStartOffset
@@ -4130,7 +4338,7 @@ function createWithUtils({
4130
4338
  });
4131
4339
  return;
4132
4340
  }
4133
- debug$8("pteExpandToWord: Can't expand to word here");
4341
+ debug$7("pteExpandToWord: Can't expand to word here");
4134
4342
  }
4135
4343
  }, editor.pteCreateTextBlock = (options) => toSlateValue([{
4136
4344
  _type: schemaTypes.block.name,
@@ -4176,12 +4384,12 @@ const withPlugins = (editor, options) => {
4176
4384
  schemaTypes
4177
4385
  }), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
4178
4386
  return createWithEventListeners(editorActor, options.subscriptions)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
4179
- }, debug$7 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
4387
+ }, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
4180
4388
  function createSlateEditor(config) {
4181
4389
  const existingSlateEditor = slateEditors.get(config.editorActor);
4182
4390
  if (existingSlateEditor)
4183
- return debug$7("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
4184
- debug$7("Creating new Slate editor instance", config.editorActor.id);
4391
+ return debug$6("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
4392
+ debug$6("Creating new Slate editor instance", config.editorActor.id);
4185
4393
  const unsubscriptions = [], subscriptions = [], instance = withPlugins(slateReact.withReact(slate.createEditor()), {
4186
4394
  editorActor: config.editorActor,
4187
4395
  subscriptions
@@ -4223,7 +4431,7 @@ const toggleListItemActionImplementation = ({
4223
4431
  }) => {
4224
4432
  if (!action.editor.selection)
4225
4433
  return;
4226
- const guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4434
+ const guards = selector_isActiveStyle.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4227
4435
  at: action.editor.selection,
4228
4436
  match: (node) => guards.isListBlock(node)
4229
4437
  })];
@@ -4237,7 +4445,7 @@ const toggleListItemActionImplementation = ({
4237
4445
  }) => {
4238
4446
  if (!action.editor.selection)
4239
4447
  return;
4240
- const guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4448
+ const guards = selector_isActiveStyle.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4241
4449
  at: action.editor.selection,
4242
4450
  match: (node) => guards.isTextBlock(node)
4243
4451
  })];
@@ -4287,7 +4495,7 @@ const toggleStyleActionImplementation = ({
4287
4495
  }) => {
4288
4496
  if (!action.editor.selection)
4289
4497
  return;
4290
- const defaultStyle = context.schema.styles[0].value, guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4498
+ const defaultStyle = context.schema.styles[0].value, guards = selector_isActiveStyle.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4291
4499
  at: action.editor.selection,
4292
4500
  match: (node) => guards.isTextBlock(node)
4293
4501
  })];
@@ -4303,7 +4511,7 @@ const toggleStyleActionImplementation = ({
4303
4511
  }) => {
4304
4512
  if (!action.editor.selection)
4305
4513
  return;
4306
- const guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4514
+ const guards = selector_isActiveStyle.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4307
4515
  at: action.editor.selection,
4308
4516
  match: (node) => guards.isTextBlock(node)
4309
4517
  })];
@@ -4326,7 +4534,7 @@ function isStyleActive({
4326
4534
  })];
4327
4535
  return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
4328
4536
  }
4329
- const debug$6 = debugWithName("API:editable");
4537
+ const debug$5 = debugWithName("API:editable");
4330
4538
  function createEditableAPI(editor, editorActor) {
4331
4539
  const types2 = editorActor.getSnapshot().context.schema;
4332
4540
  return {
@@ -4445,7 +4653,7 @@ function createEditableAPI(editor, editorActor) {
4445
4653
  }], {
4446
4654
  schemaTypes: editorActor.getSnapshot().context.schema
4447
4655
  })[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
4448
- return isSpanNode && focusNode._type !== types2.span.name && (debug$6("Inserting span child next to inline object child, moving selection + 1"), editor.move({
4656
+ return isSpanNode && focusNode._type !== types2.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
4449
4657
  distance: 1,
4450
4658
  unit: "character"
4451
4659
  })), slate.Transforms.insertNodes(editor, child, {
@@ -4583,18 +4791,18 @@ function createEditableAPI(editor, editorActor) {
4583
4791
  throw new Error("Invalid range");
4584
4792
  if (range) {
4585
4793
  if (!options?.mode || options?.mode === "selected") {
4586
- debug$6("Deleting content in selection"), slate.Transforms.delete(editor, {
4794
+ debug$5("Deleting content in selection"), slate.Transforms.delete(editor, {
4587
4795
  at: range,
4588
4796
  hanging: !0,
4589
4797
  voids: !0
4590
4798
  }), editor.onChange();
4591
4799
  return;
4592
4800
  }
4593
- options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
4801
+ options?.mode === "blocks" && (debug$5("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
4594
4802
  at: range,
4595
4803
  voids: !0,
4596
4804
  match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
4597
- })), options?.mode === "children" && (debug$6("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
4805
+ })), options?.mode === "children" && (debug$5("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
4598
4806
  at: range,
4599
4807
  voids: !0,
4600
4808
  match: (node) => node._type === types2.span.name || // Text children
@@ -4728,7 +4936,7 @@ const addAnnotationActionImplementation = ({
4728
4936
  action
4729
4937
  }) => {
4730
4938
  const editor = action.editor;
4731
- if (debug$6("Removing annotation", action.annotation.name), !!editor.selection)
4939
+ if (debug$5("Removing annotation", action.annotation.name), !!editor.selection)
4732
4940
  if (slate.Range.isCollapsed(editor.selection)) {
4733
4941
  const [block, blockPath] = slate.Editor.node(editor, editor.selection, {
4734
4942
  depth: 1
@@ -4859,7 +5067,11 @@ function insertBlock({
4859
5067
  });
4860
5068
  }
4861
5069
  }
4862
- const insertBlockObjectActionImplementation = ({
5070
+ const dataTransferSetActionImplementation = ({
5071
+ action
5072
+ }) => {
5073
+ action.dataTransfer.setData(action.mimeType, action.data);
5074
+ }, insertBlockObjectActionImplementation = ({
4863
5075
  context,
4864
5076
  action
4865
5077
  }) => {
@@ -4876,6 +5088,35 @@ const insertBlockObjectActionImplementation = ({
4876
5088
  editor: action.editor,
4877
5089
  schema: context.schema
4878
5090
  });
5091
+ }, insertBlocksActionImplementation = ({
5092
+ context,
5093
+ action
5094
+ }) => {
5095
+ const fragment = toSlateValue(action.blocks, {
5096
+ schemaTypes: context.schema
5097
+ });
5098
+ if (!action.editor.selection)
5099
+ return;
5100
+ const [focusBlock, focusPath] = slate.Editor.node(action.editor, action.editor.selection, {
5101
+ depth: 1
5102
+ });
5103
+ if (action.editor.isTextBlock(focusBlock) && action.editor.isTextBlock(fragment[0])) {
5104
+ const {
5105
+ markDefs
5106
+ } = focusBlock;
5107
+ isEqual__default.default(markDefs, fragment[0].markDefs) || slate.Transforms.setNodes(action.editor, {
5108
+ markDefs: uniq__default.default([...fragment[0].markDefs || [], ...markDefs || []])
5109
+ }, {
5110
+ at: focusPath,
5111
+ mode: "lowest",
5112
+ voids: !1
5113
+ });
5114
+ }
5115
+ isEqualToEmptyEditor(action.editor.children, context.schema) ? (slate.Transforms.splitNodes(action.editor, {
5116
+ at: [0, 0]
5117
+ }), action.editor.insertFragment(fragment), slate.Transforms.removeNodes(action.editor, {
5118
+ at: [0]
5119
+ })) : action.editor.insertFragment(fragment);
4879
5120
  }, insertBreakActionImplementation = ({
4880
5121
  context,
4881
5122
  action
@@ -5104,6 +5345,7 @@ const insertBlockObjectActionImplementation = ({
5104
5345
  }) => {
5105
5346
  slateReact.ReactEditor.blur(action.editor);
5106
5347
  },
5348
+ "data transfer.set": dataTransferSetActionImplementation,
5107
5349
  "decorator.add": addDecoratorActionImplementation,
5108
5350
  "decorator.remove": removeDecoratorActionImplementation,
5109
5351
  "decorator.toggle": toggleDecoratorActionImplementation,
@@ -5170,6 +5412,25 @@ const insertBlockObjectActionImplementation = ({
5170
5412
  at: range
5171
5413
  });
5172
5414
  },
5415
+ "deserialization.failure": ({
5416
+ action
5417
+ }) => {
5418
+ console.error(`Deserialization of ${action.mimeType} failed with reason ${action.reason}`);
5419
+ },
5420
+ "deserialization.success": ({
5421
+ context,
5422
+ action
5423
+ }) => {
5424
+ insertBlocksActionImplementation({
5425
+ context,
5426
+ action: {
5427
+ type: "insert.blocks",
5428
+ blocks: action.data,
5429
+ editor: action.editor
5430
+ }
5431
+ });
5432
+ },
5433
+ "insert.blocks": insertBlocksActionImplementation,
5173
5434
  "insert.block object": insertBlockObjectActionImplementation,
5174
5435
  "insert.break": insertBreakActionImplementation,
5175
5436
  "insert.inline object": insertInlineObjectActionImplementation,
@@ -5281,6 +5542,23 @@ const insertBlockObjectActionImplementation = ({
5281
5542
  const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
5282
5543
  slate.Transforms.select(action.editor, nextBlockPath);
5283
5544
  },
5545
+ "serialization.failure": ({
5546
+ action
5547
+ }) => {
5548
+ console.error(`Serialization of ${action.mimeType} failed with reason ${action.reason}`);
5549
+ },
5550
+ "serialization.success": ({
5551
+ context,
5552
+ action
5553
+ }) => {
5554
+ dataTransferSetActionImplementation({
5555
+ context,
5556
+ action: {
5557
+ ...action,
5558
+ type: "data transfer.set"
5559
+ }
5560
+ });
5561
+ },
5284
5562
  "style.toggle": toggleStyleActionImplementation,
5285
5563
  "style.add": addStyleActionImplementation,
5286
5564
  "style.remove": removeStyleActionImplementation,
@@ -5292,6 +5570,48 @@ function performAction({
5292
5570
  action
5293
5571
  }) {
5294
5572
  switch (action.type) {
5573
+ case "noop":
5574
+ break;
5575
+ case "effect": {
5576
+ behaviorActionImplementations.effect({
5577
+ context,
5578
+ action
5579
+ });
5580
+ break;
5581
+ }
5582
+ case "select": {
5583
+ behaviorActionImplementations.select({
5584
+ context,
5585
+ action
5586
+ });
5587
+ break;
5588
+ }
5589
+ default:
5590
+ performDefaultAction({
5591
+ context,
5592
+ action
5593
+ });
5594
+ }
5595
+ }
5596
+ function performDefaultAction({
5597
+ context,
5598
+ action
5599
+ }) {
5600
+ switch (action.type) {
5601
+ case "annotation.add": {
5602
+ behaviorActionImplementations["annotation.add"]({
5603
+ context,
5604
+ action
5605
+ });
5606
+ break;
5607
+ }
5608
+ case "annotation.remove": {
5609
+ behaviorActionImplementations["annotation.remove"]({
5610
+ context,
5611
+ action
5612
+ });
5613
+ break;
5614
+ }
5295
5615
  case "annotation.toggle": {
5296
5616
  behaviorActionImplementations["annotation.toggle"]({
5297
5617
  context,
@@ -5299,256 +5619,258 @@ function performAction({
5299
5619
  });
5300
5620
  break;
5301
5621
  }
5302
- case "decorator.add": {
5303
- behaviorActionImplementations["decorator.add"]({
5622
+ case "blur": {
5623
+ behaviorActionImplementations.blur({
5304
5624
  context,
5305
5625
  action
5306
5626
  });
5307
5627
  break;
5308
5628
  }
5309
- case "decorator.remove": {
5310
- behaviorActionImplementations["decorator.remove"]({
5629
+ case "data transfer.set": {
5630
+ behaviorActionImplementations["data transfer.set"]({
5311
5631
  context,
5312
5632
  action
5313
5633
  });
5314
5634
  break;
5315
5635
  }
5316
- case "delete.block": {
5317
- behaviorActionImplementations["delete.block"]({
5636
+ case "decorator.add": {
5637
+ behaviorActionImplementations["decorator.add"]({
5318
5638
  context,
5319
5639
  action
5320
5640
  });
5321
5641
  break;
5322
5642
  }
5323
- case "delete.text": {
5324
- behaviorActionImplementations["delete.text"]({
5643
+ case "decorator.remove": {
5644
+ behaviorActionImplementations["decorator.remove"]({
5325
5645
  context,
5326
5646
  action
5327
5647
  });
5328
5648
  break;
5329
5649
  }
5330
- case "insert.span": {
5331
- behaviorActionImplementations["insert.span"]({
5650
+ case "decorator.toggle": {
5651
+ behaviorActionImplementations["decorator.toggle"]({
5332
5652
  context,
5333
5653
  action
5334
5654
  });
5335
5655
  break;
5336
5656
  }
5337
- case "insert.text block": {
5338
- behaviorActionImplementations["insert.text block"]({
5657
+ case "delete.backward": {
5658
+ behaviorActionImplementations["delete.backward"]({
5339
5659
  context,
5340
5660
  action
5341
5661
  });
5342
5662
  break;
5343
5663
  }
5344
- case "list item.add": {
5345
- behaviorActionImplementations["list item.add"]({
5664
+ case "delete.block": {
5665
+ behaviorActionImplementations["delete.block"]({
5346
5666
  context,
5347
5667
  action
5348
5668
  });
5349
5669
  break;
5350
5670
  }
5351
- case "list item.remove": {
5352
- behaviorActionImplementations["list item.remove"]({
5671
+ case "delete.forward": {
5672
+ behaviorActionImplementations["delete.forward"]({
5353
5673
  context,
5354
5674
  action
5355
5675
  });
5356
5676
  break;
5357
5677
  }
5358
- case "move.block": {
5359
- behaviorActionImplementations["move.block"]({
5678
+ case "delete.text": {
5679
+ behaviorActionImplementations["delete.text"]({
5360
5680
  context,
5361
5681
  action
5362
5682
  });
5363
5683
  break;
5364
5684
  }
5365
- case "move.block down": {
5366
- behaviorActionImplementations["move.block down"]({
5685
+ case "deserialization.failure": {
5686
+ behaviorActionImplementations["deserialization.failure"]({
5367
5687
  context,
5368
5688
  action
5369
5689
  });
5370
5690
  break;
5371
5691
  }
5372
- case "move.block up": {
5373
- behaviorActionImplementations["move.block up"]({
5692
+ case "deserialization.success": {
5693
+ behaviorActionImplementations["deserialization.success"]({
5374
5694
  context,
5375
5695
  action
5376
5696
  });
5377
5697
  break;
5378
5698
  }
5379
- case "noop":
5699
+ case "focus": {
5700
+ behaviorActionImplementations.focus({
5701
+ context,
5702
+ action
5703
+ });
5380
5704
  break;
5381
- case "effect": {
5382
- behaviorActionImplementations.effect({
5705
+ }
5706
+ case "insert.blocks": {
5707
+ behaviorActionImplementations["insert.blocks"]({
5383
5708
  context,
5384
5709
  action
5385
5710
  });
5386
5711
  break;
5387
5712
  }
5388
- case "select": {
5389
- behaviorActionImplementations.select({
5713
+ case "insert.block object": {
5714
+ behaviorActionImplementations["insert.block object"]({
5390
5715
  context,
5391
5716
  action
5392
5717
  });
5393
5718
  break;
5394
5719
  }
5395
- case "select.previous block": {
5396
- behaviorActionImplementations["select.previous block"]({
5720
+ case "insert.inline object": {
5721
+ behaviorActionImplementations["insert.inline object"]({
5397
5722
  context,
5398
5723
  action
5399
5724
  });
5400
5725
  break;
5401
5726
  }
5402
- case "select.next block": {
5403
- behaviorActionImplementations["select.next block"]({
5727
+ case "insert.break": {
5728
+ behaviorActionImplementations["insert.break"]({
5404
5729
  context,
5405
5730
  action
5406
5731
  });
5407
5732
  break;
5408
5733
  }
5409
- case "style.add": {
5410
- behaviorActionImplementations["style.add"]({
5734
+ case "insert.soft break": {
5735
+ behaviorActionImplementations["insert.soft break"]({
5411
5736
  context,
5412
5737
  action
5413
5738
  });
5414
5739
  break;
5415
5740
  }
5416
- case "style.remove": {
5417
- behaviorActionImplementations["style.remove"]({
5741
+ case "insert.span": {
5742
+ behaviorActionImplementations["insert.span"]({
5418
5743
  context,
5419
5744
  action
5420
5745
  });
5421
5746
  break;
5422
5747
  }
5423
- case "text block.set": {
5424
- behaviorActionImplementations["text block.set"]({
5748
+ case "insert.text": {
5749
+ behaviorActionImplementations["insert.text"]({
5425
5750
  context,
5426
5751
  action
5427
5752
  });
5428
5753
  break;
5429
5754
  }
5430
- case "text block.unset": {
5431
- behaviorActionImplementations["text block.unset"]({
5755
+ case "insert.text block": {
5756
+ behaviorActionImplementations["insert.text block"]({
5432
5757
  context,
5433
5758
  action
5434
5759
  });
5435
5760
  break;
5436
5761
  }
5437
- default:
5438
- performDefaultAction({
5762
+ case "list item.add": {
5763
+ behaviorActionImplementations["list item.add"]({
5439
5764
  context,
5440
5765
  action
5441
5766
  });
5442
- }
5443
- }
5444
- function performDefaultAction({
5445
- context,
5446
- action
5447
- }) {
5448
- switch (action.type) {
5449
- case "annotation.add": {
5450
- behaviorActionImplementations["annotation.add"]({
5767
+ break;
5768
+ }
5769
+ case "list item.remove": {
5770
+ behaviorActionImplementations["list item.remove"]({
5451
5771
  context,
5452
5772
  action
5453
5773
  });
5454
5774
  break;
5455
5775
  }
5456
- case "annotation.remove": {
5457
- behaviorActionImplementations["annotation.remove"]({
5776
+ case "list item.toggle": {
5777
+ behaviorActionImplementations["list item.toggle"]({
5458
5778
  context,
5459
5779
  action
5460
5780
  });
5461
5781
  break;
5462
5782
  }
5463
- case "blur": {
5464
- behaviorActionImplementations.blur({
5783
+ case "move.block": {
5784
+ behaviorActionImplementations["move.block"]({
5465
5785
  context,
5466
5786
  action
5467
5787
  });
5468
5788
  break;
5469
5789
  }
5470
- case "decorator.toggle": {
5471
- behaviorActionImplementations["decorator.toggle"]({
5790
+ case "move.block down": {
5791
+ behaviorActionImplementations["move.block down"]({
5472
5792
  context,
5473
5793
  action
5474
5794
  });
5475
5795
  break;
5476
5796
  }
5477
- case "delete.backward": {
5478
- behaviorActionImplementations["delete.backward"]({
5797
+ case "move.block up": {
5798
+ behaviorActionImplementations["move.block up"]({
5479
5799
  context,
5480
5800
  action
5481
5801
  });
5482
5802
  break;
5483
5803
  }
5484
- case "delete.forward": {
5485
- behaviorActionImplementations["delete.forward"]({
5804
+ case "select": {
5805
+ behaviorActionImplementations.select({
5486
5806
  context,
5487
5807
  action
5488
5808
  });
5489
5809
  break;
5490
5810
  }
5491
- case "focus": {
5492
- behaviorActionImplementations.focus({
5811
+ case "select.previous block": {
5812
+ behaviorActionImplementations["select.previous block"]({
5493
5813
  context,
5494
5814
  action
5495
5815
  });
5496
5816
  break;
5497
5817
  }
5498
- case "insert.block object": {
5499
- behaviorActionImplementations["insert.block object"]({
5818
+ case "select.next block": {
5819
+ behaviorActionImplementations["select.next block"]({
5500
5820
  context,
5501
5821
  action
5502
5822
  });
5503
5823
  break;
5504
5824
  }
5505
- case "insert.inline object": {
5506
- behaviorActionImplementations["insert.inline object"]({
5825
+ case "serialization.failure": {
5826
+ behaviorActionImplementations["serialization.failure"]({
5507
5827
  context,
5508
5828
  action
5509
5829
  });
5510
5830
  break;
5511
5831
  }
5512
- case "insert.break": {
5513
- behaviorActionImplementations["insert.break"]({
5832
+ case "serialization.success": {
5833
+ behaviorActionImplementations["serialization.success"]({
5514
5834
  context,
5515
5835
  action
5516
5836
  });
5517
5837
  break;
5518
5838
  }
5519
- case "insert.soft break": {
5520
- behaviorActionImplementations["insert.soft break"]({
5839
+ case "style.add": {
5840
+ behaviorActionImplementations["style.add"]({
5521
5841
  context,
5522
5842
  action
5523
5843
  });
5524
5844
  break;
5525
5845
  }
5526
- case "insert.text": {
5527
- behaviorActionImplementations["insert.text"]({
5846
+ case "style.remove": {
5847
+ behaviorActionImplementations["style.remove"]({
5528
5848
  context,
5529
5849
  action
5530
5850
  });
5531
5851
  break;
5532
5852
  }
5533
- case "list item.toggle": {
5534
- behaviorActionImplementations["list item.toggle"]({
5853
+ case "style.toggle": {
5854
+ behaviorActionImplementations["style.toggle"]({
5535
5855
  context,
5536
5856
  action
5537
5857
  });
5538
5858
  break;
5539
5859
  }
5540
- case "select": {
5541
- behaviorActionImplementations.select({
5860
+ case "text block.set": {
5861
+ behaviorActionImplementations["text block.set"]({
5542
5862
  context,
5543
5863
  action
5544
5864
  });
5545
5865
  break;
5546
5866
  }
5547
- default:
5548
- behaviorActionImplementations["style.toggle"]({
5867
+ case "text block.unset": {
5868
+ behaviorActionImplementations["text block.unset"]({
5549
5869
  context,
5550
5870
  action
5551
5871
  });
5872
+ break;
5873
+ }
5552
5874
  }
5553
5875
  }
5554
5876
  function getActiveDecorators({
@@ -5561,6 +5883,7 @@ function getActiveDecorators({
5561
5883
  }.marks ?? []).filter((mark) => decorators.includes(mark));
5562
5884
  }
5563
5885
  function createEditorSnapshot({
5886
+ converters,
5564
5887
  editor,
5565
5888
  keyGenerator,
5566
5889
  schema: schema2
@@ -5572,6 +5895,7 @@ function createEditorSnapshot({
5572
5895
  schema: schema2,
5573
5896
  slateEditorInstance: editor
5574
5897
  }),
5898
+ converters,
5575
5899
  keyGenerator,
5576
5900
  schema: schema2,
5577
5901
  selection,
@@ -5646,7 +5970,7 @@ const editorMachine = xstate.setup({
5646
5970
  enqueue
5647
5971
  }) => {
5648
5972
  xstate.assertEvent(event, ["behavior event", "custom behavior event"]);
5649
- const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
5973
+ const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
5650
5974
  ...event.behaviorEvent,
5651
5975
  editor: event.editor
5652
5976
  }, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values()].filter((behavior) => behavior.on === event.behaviorEvent.type);
@@ -5680,6 +6004,7 @@ const editorMachine = xstate.setup({
5680
6004
  return;
5681
6005
  }
5682
6006
  const editorSnapshot = createEditorSnapshot({
6007
+ converters: [...context.converters],
5683
6008
  editor: event.editor,
5684
6009
  keyGenerator: context.keyGenerator,
5685
6010
  schema: context.schema
@@ -5769,6 +6094,7 @@ const editorMachine = xstate.setup({
5769
6094
  input
5770
6095
  }) => ({
5771
6096
  behaviors: new Set(input.behaviors ?? behavior_core.coreBehaviors),
6097
+ converters: new Set(input.converters ?? []),
5772
6098
  keyGenerator: input.keyGenerator,
5773
6099
  pendingEvents: [],
5774
6100
  schema: input.schema,
@@ -5888,6 +6214,12 @@ const editorMachine = xstate.setup({
5888
6214
  },
5889
6215
  "read only": {
5890
6216
  on: {
6217
+ "behavior event": {
6218
+ actions: "handle behavior event",
6219
+ guard: ({
6220
+ event
6221
+ }) => event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "data transfer.set" || event.behaviorEvent.type === "serialize" || event.behaviorEvent.type === "serialization.failure" || event.behaviorEvent.type === "serialization.success" || event.behaviorEvent.type === "select"
6222
+ },
5891
6223
  "update readOnly": {
5892
6224
  guard: ({
5893
6225
  event
@@ -5937,6 +6269,11 @@ const editorMachine = xstate.setup({
5937
6269
  event
5938
6270
  }) => event)
5939
6271
  },
6272
+ "delete.*": {
6273
+ actions: xstate.emit(({
6274
+ event
6275
+ }) => event)
6276
+ },
5940
6277
  focus: {
5941
6278
  actions: xstate.emit(({
5942
6279
  event
@@ -5952,15 +6289,30 @@ const editorMachine = xstate.setup({
5952
6289
  event
5953
6290
  }) => event)
5954
6291
  },
6292
+ "move.*": {
6293
+ actions: xstate.emit(({
6294
+ event
6295
+ }) => event)
6296
+ },
5955
6297
  select: {
5956
6298
  actions: xstate.emit(({
5957
6299
  event
5958
6300
  }) => event)
5959
6301
  },
6302
+ "select.*": {
6303
+ actions: xstate.emit(({
6304
+ event
6305
+ }) => event)
6306
+ },
5960
6307
  "style.*": {
5961
6308
  actions: xstate.emit(({
5962
6309
  event
5963
6310
  }) => event)
6311
+ },
6312
+ "text block.*": {
6313
+ actions: xstate.emit(({
6314
+ event
6315
+ }) => event)
5964
6316
  }
5965
6317
  }
5966
6318
  }
@@ -6057,6 +6409,7 @@ function getEditorSnapshot({
6057
6409
  }) {
6058
6410
  return {
6059
6411
  context: {
6412
+ converters: [...editorActorSnapshot.context.converters],
6060
6413
  activeDecorators: getActiveDecorators({
6061
6414
  schema: editorActorSnapshot.context.schema,
6062
6415
  slateEditorInstance
@@ -6111,6 +6464,7 @@ function useCreateEditor(config) {
6111
6464
  function editorConfigToMachineInput(config) {
6112
6465
  return {
6113
6466
  behaviors: config.behaviors,
6467
+ converters: coreConverters,
6114
6468
  keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
6115
6469
  maxBlocks: config.maxBlocks,
6116
6470
  readOnly: config.readOnly,
@@ -6139,11 +6493,25 @@ function createEditorFromActor(editorActor) {
6139
6493
  send: (event) => {
6140
6494
  editorActor.send(event);
6141
6495
  },
6142
- on: (event, listener) => editorActor.on(
6143
- event,
6144
- // @ts-expect-error
6145
- listener
6146
- ),
6496
+ on: (event, listener) => editorActor.on(event, (event2) => {
6497
+ switch (event2.type) {
6498
+ case "blurred":
6499
+ case "done loading":
6500
+ case "editable":
6501
+ case "error":
6502
+ case "focused":
6503
+ case "invalid value":
6504
+ case "loading":
6505
+ case "mutation":
6506
+ case "patch":
6507
+ case "read only":
6508
+ case "ready":
6509
+ case "selection":
6510
+ case "value changed":
6511
+ listener(event2);
6512
+ break;
6513
+ }
6514
+ }),
6147
6515
  _internal: {
6148
6516
  editable,
6149
6517
  editorActor,
@@ -6156,25 +6524,25 @@ const EditorActorContext = React.createContext({}), PortableTextEditorSelectionC
6156
6524
  if (selection === void 0)
6157
6525
  throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
6158
6526
  return selection;
6159
- }, debug$5 = debugWithName("component:PortableTextEditor:SelectionProvider");
6527
+ }, debug$4 = debugWithName("component:PortableTextEditor:SelectionProvider");
6160
6528
  function PortableTextEditorSelectionProvider(props) {
6161
6529
  const $ = reactCompilerRuntime.c(6), [selection, setSelection] = React.useState(null);
6162
6530
  let t0, t1;
6163
6531
  $[0] !== props.editorActor ? (t0 = () => {
6164
- debug$5("Subscribing to selection changes");
6532
+ debug$4("Subscribing to selection changes");
6165
6533
  const subscription = props.editorActor.on("selection", (event) => {
6166
6534
  React.startTransition(() => {
6167
6535
  setSelection(event.selection);
6168
6536
  });
6169
6537
  });
6170
6538
  return () => {
6171
- debug$5("Unsubscribing to selection changes"), subscription.unsubscribe();
6539
+ debug$4("Unsubscribing to selection changes"), subscription.unsubscribe();
6172
6540
  };
6173
6541
  }, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), React.useEffect(t0, t1);
6174
6542
  let t2;
6175
6543
  return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
6176
6544
  }
6177
- const debug$4 = debugWithName("component:PortableTextEditor");
6545
+ const debug$3 = debugWithName("component:PortableTextEditor");
6178
6546
  class PortableTextEditor extends React.Component {
6179
6547
  static displayName = "PortableTextEditor";
6180
6548
  /**
@@ -6236,13 +6604,13 @@ class PortableTextEditor extends React.Component {
6236
6604
  static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
6237
6605
  static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
6238
6606
  static blur = (editor) => {
6239
- debug$4("Host blurred"), editor.editable?.blur();
6607
+ debug$3("Host blurred"), editor.editable?.blur();
6240
6608
  };
6241
6609
  static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
6242
6610
  static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
6243
6611
  static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
6244
6612
  static focus = (editor) => {
6245
- debug$4("Host requesting focus"), editor.editable?.focus();
6613
+ debug$3("Host requesting focus"), editor.editable?.focus();
6246
6614
  };
6247
6615
  static focusBlock = (editor) => editor.editable?.focusBlock();
6248
6616
  static focusChild = (editor) => editor.editable?.focusChild();
@@ -6253,7 +6621,7 @@ class PortableTextEditor extends React.Component {
6253
6621
  static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
6254
6622
  static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
6255
6623
  static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
6256
- static insertChild = (editor, type, value) => (debug$4("Host inserting child"), editor.editable?.insertChild(type, value));
6624
+ static insertChild = (editor, type, value) => (debug$3("Host inserting child"), editor.editable?.insertChild(type, value));
6257
6625
  static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
6258
6626
  static insertBreak = (editor) => editor.editable?.insertBreak();
6259
6627
  static isVoid = (editor, element) => editor.editable?.isVoid(element);
@@ -6264,20 +6632,20 @@ class PortableTextEditor extends React.Component {
6264
6632
  };
6265
6633
  static marks = (editor) => editor.editable?.marks();
6266
6634
  static select = (editor, selection) => {
6267
- debug$4("Host setting selection", selection), editor.editable?.select(selection);
6635
+ debug$3("Host setting selection", selection), editor.editable?.select(selection);
6268
6636
  };
6269
6637
  static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
6270
- static toggleBlockStyle = (editor, blockStyle) => (debug$4("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
6638
+ static toggleBlockStyle = (editor, blockStyle) => (debug$3("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
6271
6639
  static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
6272
6640
  static toggleMark = (editor, mark) => {
6273
- debug$4("Host toggling mark", mark), editor.editable?.toggleMark(mark);
6641
+ debug$3("Host toggling mark", mark), editor.editable?.toggleMark(mark);
6274
6642
  };
6275
- static getFragment = (editor) => (debug$4("Host getting fragment"), editor.editable?.getFragment());
6643
+ static getFragment = (editor) => (debug$3("Host getting fragment"), editor.editable?.getFragment());
6276
6644
  static undo = (editor) => {
6277
- debug$4("Host undoing"), editor.editable?.undo();
6645
+ debug$3("Host undoing"), editor.editable?.undo();
6278
6646
  };
6279
6647
  static redo = (editor) => {
6280
- debug$4("Host redoing"), editor.editable?.redo();
6648
+ debug$3("Host redoing"), editor.editable?.redo();
6281
6649
  };
6282
6650
  static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
6283
6651
  }
@@ -6303,7 +6671,7 @@ function RouteEventsToChanges(props) {
6303
6671
  const handleChange = useEffectEvent.useEffectEvent(t0);
6304
6672
  let t1, t2;
6305
6673
  return $[2] !== handleChange || $[3] !== props.editorActor ? (t1 = () => {
6306
- debug$4("Subscribing to editor changes");
6674
+ debug$3("Subscribing to editor changes");
6307
6675
  const sub = props.editorActor.on("*", (event) => {
6308
6676
  bb5: switch (event.type) {
6309
6677
  case "blurred": {
@@ -6377,11 +6745,11 @@ function RouteEventsToChanges(props) {
6377
6745
  }
6378
6746
  });
6379
6747
  return () => {
6380
- debug$4("Unsubscribing to changes"), sub.unsubscribe();
6748
+ debug$3("Unsubscribing to changes"), sub.unsubscribe();
6381
6749
  };
6382
6750
  }, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), React.useEffect(t1, t2), null;
6383
6751
  }
6384
- const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
6752
+ const debug$2 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
6385
6753
  const {
6386
6754
  editorActor,
6387
6755
  attributes,
@@ -6409,7 +6777,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
6409
6777
  const setSelectedFromRange = React.useCallback(() => {
6410
6778
  if (!shouldTrackSelectionAndFocus)
6411
6779
  return;
6412
- debug$3("Setting selection and focus from range");
6780
+ debug$2("Setting selection and focus from range");
6413
6781
  const winSelection = window.getSelection();
6414
6782
  if (!winSelection) {
6415
6783
  setSelected(!1);
@@ -6505,7 +6873,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
6505
6873
  return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
6506
6874
  };
6507
6875
  Leaf.displayName = "Leaf";
6508
- const debug$2 = debugWithName("plugin:withHotKeys");
6876
+ const debug$1 = debugWithName("plugin:withHotKeys");
6509
6877
  function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
6510
6878
  const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
6511
6879
  return function(editor) {
@@ -6520,7 +6888,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
6520
6888
  const possibleMark = activeHotkeys[cat];
6521
6889
  if (possibleMark) {
6522
6890
  const mark = possibleMark[hotkey];
6523
- debug$2(`HotKey ${hotkey} to toggle ${mark}`), editorActor.send({
6891
+ debug$1(`HotKey ${hotkey} to toggle ${mark}`), editorActor.send({
6524
6892
  type: "behavior event",
6525
6893
  behaviorEvent: {
6526
6894
  type: "decorator.toggle",
@@ -6547,204 +6915,6 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
6547
6915
  }, editor;
6548
6916
  };
6549
6917
  }
6550
- const debug$1 = debugWithName("plugin:withInsertData");
6551
- function createWithInsertData(editorActor, schemaTypes) {
6552
- return function(editor) {
6553
- const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => editor.isTextBlock(block) ? block.children.map((child) => child._type === spanTypeName ? child.text : `[${schemaTypes.inlineObjects.find((t) => t.name === child._type)?.title || "Object"}]`).join("") : `[${schemaTypes.blockObjects.find((t) => t.name === block._type)?.title || "Object"}]`).join(`
6554
-
6555
- `);
6556
- return editor.setFragmentData = (data, originEvent) => {
6557
- const {
6558
- selection
6559
- } = editor;
6560
- if (!selection)
6561
- return;
6562
- const [start, end] = slate.Range.edges(selection), startVoid = slate.Editor.void(editor, {
6563
- at: start.path
6564
- }), endVoid = slate.Editor.void(editor, {
6565
- at: end.path
6566
- });
6567
- if (slate.Range.isCollapsed(selection) && !startVoid)
6568
- return;
6569
- const domRange = slateReact.ReactEditor.toDOMRange(editor, selection);
6570
- let contents = domRange.cloneContents();
6571
- if (endVoid) {
6572
- const [voidNode] = endVoid, r = domRange.cloneRange(), domNode = slateReact.ReactEditor.toDOMNode(editor, voidNode);
6573
- r.setEndAfter(domNode), contents = r.cloneContents();
6574
- }
6575
- Array.from(contents.querySelectorAll("[data-slate-zero-width]")).forEach((zw) => {
6576
- const isNewline = zw.getAttribute("data-slate-zero-width") === "n";
6577
- zw.textContent = isNewline ? `
6578
- ` : "";
6579
- }), Array.from(contents.querySelectorAll("*")).forEach((elm) => {
6580
- elm.removeAttribute("contentEditable"), elm.removeAttribute("data-slate-inline"), elm.removeAttribute("data-slate-leaf"), elm.removeAttribute("data-slate-node"), elm.removeAttribute("data-slate-spacer"), elm.removeAttribute("data-slate-string"), elm.removeAttribute("data-slate-zero-width"), elm.removeAttribute("draggable");
6581
- for (const key in elm.attributes)
6582
- elm.hasAttribute(key) && elm.removeAttribute(key);
6583
- });
6584
- const div = contents.ownerDocument.createElement("div");
6585
- div.appendChild(contents), div.setAttribute("hidden", "true"), contents.ownerDocument.body.appendChild(div);
6586
- const asHTML = div.innerHTML;
6587
- contents.ownerDocument.body.removeChild(div);
6588
- const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
6589
- data.clearData(), data.setData("text/plain", asPlainText), data.setData("text/html", asHTML), data.setData("application/json", asJSON), data.setData("application/x-portable-text", asJSON), debug$1("text", asPlainText), data.setData("application/x-portable-text-event-origin", originEvent || "external"), debug$1("Set fragment data", asJSON, asHTML);
6590
- }, editor.insertPortableTextData = (data) => {
6591
- if (!editor.selection)
6592
- return !1;
6593
- const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
6594
- if (debug$1(`Inserting portable text from ${origin} event`, pText), pText) {
6595
- const parsed = JSON.parse(pText);
6596
- if (Array.isArray(parsed) && parsed.length > 0) {
6597
- const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
6598
- schemaTypes
6599
- }), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
6600
- if (!validation.valid && !validation.resolution?.autoResolve) {
6601
- const errorDescription = `${validation.resolution?.description}`;
6602
- return editorActor.send({
6603
- type: "error",
6604
- name: "pasteError",
6605
- description: errorDescription,
6606
- data: validation
6607
- }), debug$1("Invalid insert result", validation), !1;
6608
- }
6609
- return _insertFragment(editor, slateValue, schemaTypes), !0;
6610
- }
6611
- }
6612
- return !1;
6613
- }, editor.insertTextOrHTMLData = (data) => {
6614
- if (!editor.selection)
6615
- return debug$1("No selection, not inserting"), !1;
6616
- const html = data.getData("text/html"), text = data.getData("text/plain");
6617
- if (html || text) {
6618
- debug$1("Inserting data", data);
6619
- let portableText, fragment, insertedType;
6620
- if (html) {
6621
- if (portableText = blockTools.htmlToBlocks(html, schemaTypes.portableText, {
6622
- unstable_whitespaceOnPasteMode: whitespaceOnPasteMode,
6623
- keyGenerator: editorActor.getSnapshot().context.keyGenerator
6624
- }), fragment = toSlateValue(portableText, {
6625
- schemaTypes
6626
- }), insertedType = "HTML", portableText.length === 0)
6627
- return !1;
6628
- } else {
6629
- const textToHtml = `<html><body>${escapeHtml(text).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`;
6630
- portableText = blockTools.htmlToBlocks(textToHtml, schemaTypes.portableText, {
6631
- keyGenerator: editorActor.getSnapshot().context.keyGenerator
6632
- }), fragment = toSlateValue(portableText, {
6633
- schemaTypes
6634
- }), insertedType = "text";
6635
- }
6636
- const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
6637
- if (!validation.valid) {
6638
- const errorDescription = `Could not validate the resulting portable text to insert.
6639
- ${validation.resolution?.description}
6640
- Try to insert as plain text (shift-paste) instead.`;
6641
- return editorActor.send({
6642
- type: "error",
6643
- name: "pasteError",
6644
- description: errorDescription,
6645
- data: validation
6646
- }), debug$1("Invalid insert result", validation), !1;
6647
- }
6648
- return debug$1(`Inserting ${insertedType} fragment at ${JSON.stringify(editor.selection)}`), _insertFragment(editor, fragment, schemaTypes), !0;
6649
- }
6650
- return !1;
6651
- }, editor.insertData = (data) => {
6652
- editor.insertPortableTextData(data) || editor.insertTextOrHTMLData(data);
6653
- }, editor.insertFragmentData = (data) => {
6654
- const fragment = data.getData("application/x-portable-text");
6655
- if (fragment) {
6656
- const parsed = JSON.parse(fragment);
6657
- return editor.insertFragment(parsed), !0;
6658
- }
6659
- return !1;
6660
- }, editor;
6661
- };
6662
- }
6663
- const entityMap = {
6664
- "&": "&amp;",
6665
- "<": "&lt;",
6666
- ">": "&gt;",
6667
- '"': "&quot;",
6668
- "'": "&#39;",
6669
- "/": "&#x2F;",
6670
- "`": "&#x60;",
6671
- "=": "&#x3D;"
6672
- };
6673
- function escapeHtml(str) {
6674
- return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
6675
- }
6676
- function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
6677
- return fragment.map((node) => {
6678
- const newNode = {
6679
- ...node
6680
- };
6681
- if (editor.isTextBlock(newNode)) {
6682
- const annotations = editorTypes.annotations.map((t) => t.name);
6683
- if (annotations.length === 0) {
6684
- const {
6685
- markDefs,
6686
- ...NewNodeNoDefs
6687
- } = newNode;
6688
- return {
6689
- ...NewNodeNoDefs,
6690
- _key: keyGenerator()
6691
- };
6692
- }
6693
- if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
6694
- const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
6695
- return {
6696
- ...newNode,
6697
- markDefs: allowedAnnotations,
6698
- _key: keyGenerator()
6699
- };
6700
- }
6701
- newNode.markDefs = (newNode.markDefs || []).map((def) => {
6702
- const oldKey = def._key, newKey = keyGenerator();
6703
- return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
6704
- ...child,
6705
- marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
6706
- } : child), {
6707
- ...def,
6708
- _key: newKey
6709
- };
6710
- });
6711
- }
6712
- const nodeWithNewKeys = {
6713
- ...newNode,
6714
- _key: keyGenerator()
6715
- };
6716
- return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
6717
- ...child,
6718
- _key: keyGenerator()
6719
- }))), nodeWithNewKeys;
6720
- });
6721
- }
6722
- function _insertFragment(editor, fragment, schemaTypes) {
6723
- editor.withoutNormalizing(() => {
6724
- if (!editor.selection)
6725
- return;
6726
- const [focusBlock, focusPath] = slate.Editor.node(editor, editor.selection, {
6727
- depth: 1
6728
- });
6729
- if (editor.isTextBlock(focusBlock) && editor.isTextBlock(fragment[0])) {
6730
- const {
6731
- markDefs
6732
- } = focusBlock;
6733
- debug$1("Mixing markDefs of focusBlock and fragments[0] block", markDefs, fragment[0].markDefs), isEqual__default.default(markDefs, fragment[0].markDefs) || slate.Transforms.setNodes(editor, {
6734
- markDefs: uniq__default.default([...fragment[0].markDefs || [], ...markDefs || []])
6735
- }, {
6736
- at: focusPath,
6737
- mode: "lowest",
6738
- voids: !1
6739
- });
6740
- }
6741
- isEqualToEmptyEditor(editor.children, schemaTypes) ? (slate.Transforms.splitNodes(editor, {
6742
- at: [0, 0]
6743
- }), editor.insertFragment(fragment), slate.Transforms.removeNodes(editor, {
6744
- at: [0]
6745
- })) : editor.insertFragment(fragment);
6746
- }), editor.onChange();
6747
- }
6748
6918
  function withSyncRangeDecorations({
6749
6919
  editorActor,
6750
6920
  slateEditor,
@@ -6792,12 +6962,11 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6792
6962
  "edit mode": "read only"
6793
6963
  })), schemaTypes = react.useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name;
6794
6964
  React.useMemo(() => {
6795
- const withInsertData = createWithInsertData(editorActor, schemaTypes);
6796
6965
  if (readOnly)
6797
- return debug("Editable is in read only mode"), withInsertData(slateEditor);
6966
+ return debug("Editable is in read only mode"), slateEditor;
6798
6967
  const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
6799
- return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
6800
- }, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
6968
+ return debug("Editable is in edit mode"), withHotKeys(slateEditor);
6969
+ }, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
6801
6970
  const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = React.useCallback((lProps) => {
6802
6971
  if (lProps.leaf._type === "span") {
6803
6972
  let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });