@portabletext/editor 1.15.2 → 1.16.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 (82) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +30 -28
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +14 -14
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/{selectors.cjs → selector.is-selection-collapsed.cjs} +8 -8
  6. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -0
  7. package/lib/_chunks-es/behavior.core.js +12 -10
  8. package/lib/_chunks-es/behavior.core.js.map +1 -1
  9. package/lib/_chunks-es/selector.get-text-before.js +14 -14
  10. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  11. package/lib/_chunks-es/{selectors.js → selector.is-selection-collapsed.js} +8 -8
  12. package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -0
  13. package/lib/behaviors/index.cjs +35 -35
  14. package/lib/behaviors/index.cjs.map +1 -1
  15. package/lib/behaviors/index.d.cts +40 -45
  16. package/lib/behaviors/index.d.ts +40 -45
  17. package/lib/behaviors/index.js +20 -20
  18. package/lib/behaviors/index.js.map +1 -1
  19. package/lib/index.cjs +868 -542
  20. package/lib/index.cjs.map +1 -1
  21. package/lib/index.d.cts +3791 -4503
  22. package/lib/index.d.ts +3791 -4503
  23. package/lib/index.js +865 -541
  24. package/lib/index.js.map +1 -1
  25. package/lib/selectors/index.cjs +166 -16
  26. package/lib/selectors/index.cjs.map +1 -1
  27. package/lib/selectors/index.d.cts +62 -17
  28. package/lib/selectors/index.d.ts +62 -17
  29. package/lib/selectors/index.js +154 -3
  30. package/lib/selectors/index.js.map +1 -1
  31. package/package.json +11 -11
  32. package/src/behavior-actions/behavior.action-utils.insert-block.ts +3 -5
  33. package/src/behavior-actions/behavior.actions.ts +6 -6
  34. package/src/behavior-actions/behavior.guards.ts +2 -6
  35. package/src/behaviors/behavior.code-editor.ts +5 -9
  36. package/src/behaviors/behavior.core.block-objects.ts +14 -20
  37. package/src/behaviors/behavior.core.lists.ts +13 -19
  38. package/src/behaviors/behavior.links.ts +6 -6
  39. package/src/behaviors/behavior.markdown.ts +27 -40
  40. package/src/behaviors/behavior.types.ts +7 -7
  41. package/src/behaviors/index.ts +1 -0
  42. package/src/editor/Editable.tsx +11 -4
  43. package/src/editor/PortableTextEditor.tsx +4 -5
  44. package/src/editor/{hooks/useSyncValue.test.tsx → __tests__/sync-value.test.tsx} +42 -23
  45. package/src/editor/components/Synchronizer.tsx +53 -80
  46. package/src/{utils/getPortableTextMemberSchemaTypes.ts → editor/create-editor-schema.ts} +3 -3
  47. package/src/editor/create-editor.ts +2 -2
  48. package/src/editor/define-schema.ts +8 -3
  49. package/src/editor/editor-machine.ts +136 -104
  50. package/src/editor/editor-provider.tsx +0 -3
  51. package/src/editor/editor-selector.ts +6 -13
  52. package/src/editor/editor-snapshot.ts +5 -6
  53. package/src/editor/get-active-decorators.ts +20 -0
  54. package/src/editor/mutation-machine.ts +100 -0
  55. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +21 -15
  56. package/src/editor/plugins/createWithMaxBlocks.ts +1 -1
  57. package/src/editor/plugins/createWithPatches.ts +0 -4
  58. package/src/editor/plugins/createWithPlaceholderBlock.ts +1 -1
  59. package/src/editor/plugins/createWithPortableTextSelections.ts +4 -1
  60. package/src/editor/plugins/createWithUndoRedo.ts +3 -3
  61. package/src/editor/sync-machine.ts +657 -0
  62. package/src/editor/withSyncRangeDecorations.ts +17 -5
  63. package/src/index.ts +3 -5
  64. package/src/selectors/_exports/index.ts +1 -0
  65. package/src/selectors/index.ts +10 -4
  66. package/src/selectors/selector.get-active-style.ts +37 -0
  67. package/src/selectors/selector.get-selected-spans.ts +136 -0
  68. package/src/selectors/selector.is-active-annotation.ts +49 -0
  69. package/src/selectors/selector.is-active-decorator.ts +21 -0
  70. package/src/selectors/selector.is-active-list-item.ts +13 -0
  71. package/src/selectors/selector.is-active-style.ts +13 -0
  72. package/src/selectors/selector.is-selection-collapsed.ts +12 -0
  73. package/src/selectors/selector.is-selection-expanded.ts +9 -0
  74. package/src/selectors/selectors.ts +0 -11
  75. package/src/utils/__tests__/operationToPatches.test.ts +2 -2
  76. package/src/utils/__tests__/patchToOperations.test.ts +2 -2
  77. package/src/utils/__tests__/values.test.ts +2 -2
  78. package/src/utils/weakMaps.ts +0 -3
  79. package/src/utils/withChanges.ts +1 -8
  80. package/lib/_chunks-cjs/selectors.cjs.map +0 -1
  81. package/lib/_chunks-es/selectors.js.map +0 -1
  82. package/src/editor/hooks/useSyncValue.ts +0 -426
package/lib/index.js CHANGED
@@ -16,7 +16,7 @@ import { jsx, Fragment, jsxs } from "react/jsx-runtime";
16
16
  import { useSelector, useActorRef } from "@xstate/react";
17
17
  import isEqual from "lodash/isEqual.js";
18
18
  import noop from "lodash/noop.js";
19
- import React, { useRef, useState, useEffect, useMemo, createContext, useContext, useCallback, startTransition, Component, forwardRef, useImperativeHandle } from "react";
19
+ import React, { useRef, useState, useEffect, useMemo, createContext, useContext, startTransition, Component, useCallback, forwardRef, useImperativeHandle } from "react";
20
20
  import { Editor, Element as Element$1, Range, Point, Text, Path, Transforms, Operation, Node, createEditor as createEditor$1, deleteBackward, deleteForward, insertText } from "slate";
21
21
  import { useSlateStatic, ReactEditor, useSelected, withReact, Slate, useSlate, Editable } from "slate-react";
22
22
  import debug$m from "debug";
@@ -25,20 +25,18 @@ import { styled } from "styled-components";
25
25
  import uniq from "lodash/uniq.js";
26
26
  import { Subject } from "rxjs";
27
27
  import { useEffectEvent } from "use-effect-event";
28
- import throttle from "lodash/throttle.js";
29
- import debounce from "lodash/debounce.js";
28
+ import { setup, emit, assign, fromCallback, assertEvent, and, not, or, enqueueActions, createActor } from "xstate";
30
29
  import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
31
30
  import flatten from "lodash/flatten.js";
32
31
  import isPlainObject from "lodash/isPlainObject.js";
33
- import { setup, assign, assertEvent, emit, enqueueActions, createActor } from "xstate";
34
32
  import get from "lodash/get.js";
35
33
  import isUndefined from "lodash/isUndefined.js";
36
34
  import omitBy from "lodash/omitBy.js";
37
- import { createGuards } from "./_chunks-es/selectors.js";
35
+ import { createGuards } from "./_chunks-es/selector.is-selection-collapsed.js";
38
36
  import { blockOffsetToSpanSelectionPoint, coreBehaviors, isHotkey } from "./_chunks-es/behavior.core.js";
39
37
  import getRandomValues from "get-random-values-esm";
40
38
  import { htmlToBlocks, normalizeBlock } from "@sanity/block-tools";
41
- function getPortableTextMemberSchemaTypes(portableTextType) {
39
+ function createEditorSchema(portableTextType) {
42
40
  var _a, _b, _c;
43
41
  if (!portableTextType)
44
42
  throw new Error("Parameter 'portabletextType' missing (required)");
@@ -93,12 +91,12 @@ function resolveEnabledListItems(blockType) {
93
91
  function findBlockType(type) {
94
92
  return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
95
93
  }
96
- var __defProp$p = Object.defineProperty, __defProps$j = Object.defineProperties, __getOwnPropDescs$j = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$p = Object.getOwnPropertySymbols, __hasOwnProp$p = Object.prototype.hasOwnProperty, __propIsEnum$p = Object.prototype.propertyIsEnumerable, __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$p = (a, b) => {
94
+ var __defProp$q = Object.defineProperty, __defProps$j = Object.defineProperties, __getOwnPropDescs$j = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$q = Object.getOwnPropertySymbols, __hasOwnProp$q = Object.prototype.hasOwnProperty, __propIsEnum$q = Object.prototype.propertyIsEnumerable, __defNormalProp$q = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$q = (a, b) => {
97
95
  for (var prop in b || (b = {}))
98
- __hasOwnProp$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
99
- if (__getOwnPropSymbols$p)
100
- for (var prop of __getOwnPropSymbols$p(b))
101
- __propIsEnum$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
96
+ __hasOwnProp$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
97
+ if (__getOwnPropSymbols$q)
98
+ for (var prop of __getOwnPropSymbols$q(b))
99
+ __propIsEnum$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
102
100
  return a;
103
101
  }, __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
104
102
  function defineSchema(definition) {
@@ -166,11 +164,11 @@ function compileSchemaDefinition(definition) {
166
164
  }]
167
165
  }), schema = Schema.compile({
168
166
  types: [portableTextSchema, ...blockObjects, ...inlineObjects]
169
- }).get("portable-text"), pteSchema = getPortableTextMemberSchemaTypes(schema);
170
- return __spreadProps$j(__spreadValues$p({}, pteSchema), {
171
- blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$p({}, blockObject), {
167
+ }).get("portable-text"), pteSchema = createEditorSchema(schema);
168
+ return __spreadProps$j(__spreadValues$q({}, pteSchema), {
169
+ blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$q({}, blockObject), {
172
170
  name: "image",
173
- type: __spreadProps$j(__spreadValues$p({}, blockObject.type), {
171
+ type: __spreadProps$j(__spreadValues$q({}, blockObject.type), {
174
172
  name: "image"
175
173
  })
176
174
  }) : blockObject)
@@ -309,20 +307,20 @@ function normalizeSelection(selection, value) {
309
307
  backward: selection.backward
310
308
  } : null;
311
309
  }
312
- var __defProp$o = Object.defineProperty, __defProps$i = Object.defineProperties, __getOwnPropDescs$i = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$o = Object.getOwnPropertySymbols, __hasOwnProp$o = Object.prototype.hasOwnProperty, __propIsEnum$o = Object.prototype.propertyIsEnumerable, __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$o = (a, b) => {
310
+ var __defProp$p = Object.defineProperty, __defProps$i = Object.defineProperties, __getOwnPropDescs$i = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$p = Object.getOwnPropertySymbols, __hasOwnProp$p = Object.prototype.hasOwnProperty, __propIsEnum$p = Object.prototype.propertyIsEnumerable, __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$p = (a, b) => {
313
311
  for (var prop in b || (b = {}))
314
- __hasOwnProp$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
315
- if (__getOwnPropSymbols$o)
316
- for (var prop of __getOwnPropSymbols$o(b))
317
- __propIsEnum$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
312
+ __hasOwnProp$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
313
+ if (__getOwnPropSymbols$p)
314
+ for (var prop of __getOwnPropSymbols$p(b))
315
+ __propIsEnum$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
318
316
  return a;
319
317
  }, __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b)), __objRest$3 = (source, exclude) => {
320
318
  var target = {};
321
319
  for (var prop in source)
322
- __hasOwnProp$o.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
323
- if (source != null && __getOwnPropSymbols$o)
324
- for (var prop of __getOwnPropSymbols$o(source))
325
- exclude.indexOf(prop) < 0 && __propIsEnum$o.call(source, prop) && (target[prop] = source[prop]);
320
+ __hasOwnProp$p.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
321
+ if (source != null && __getOwnPropSymbols$p)
322
+ for (var prop of __getOwnPropSymbols$p(source))
323
+ exclude.indexOf(prop) < 0 && __propIsEnum$p.call(source, prop) && (target[prop] = source[prop]);
326
324
  return target;
327
325
  };
328
326
  const VOID_CHILD_KEY = "void-child";
@@ -365,7 +363,7 @@ function toSlateValue(value, {
365
363
  __inline: !0
366
364
  }, keyMap)) : child;
367
365
  });
368
- return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(__spreadProps$i(__spreadValues$o({
366
+ return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(__spreadProps$i(__spreadValues$p({
369
367
  _type,
370
368
  _key
371
369
  }, rest), {
@@ -409,21 +407,21 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
409
407
  "__inline",
410
408
  "children"
411
409
  ]);
412
- return keepObjectEquality(__spreadProps$i(__spreadValues$o(__spreadValues$o({}, rest), v), {
410
+ return keepObjectEquality(__spreadProps$i(__spreadValues$p(__spreadValues$p({}, rest), v), {
413
411
  _key: k,
414
412
  _type: t
415
413
  }), keyMap);
416
414
  }
417
415
  return child;
418
416
  });
419
- return hasInlines ? keepObjectEquality(__spreadProps$i(__spreadValues$o({}, block), {
417
+ return hasInlines ? keepObjectEquality(__spreadProps$i(__spreadValues$p({}, block), {
420
418
  children,
421
419
  _key,
422
420
  _type
423
421
  }), keyMap) : block;
424
422
  }
425
423
  const blockValue = "value" in block && block.value;
426
- return keepObjectEquality(__spreadValues$o({
424
+ return keepObjectEquality(__spreadValues$p({
427
425
  _key,
428
426
  _type
429
427
  }, typeof blockValue == "object" ? blockValue : {}), keyMap);
@@ -433,7 +431,7 @@ function isEqualToEmptyEditor(children, schemaTypes) {
433
431
  var _a;
434
432
  return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element$1.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !((_a = children[0].children[0].marks) != null && _a.join("")) && children[0].children[0].text === "";
435
433
  }
436
- const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_PROCESSING_LOCAL_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), DefaultObject = (props) => {
434
+ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), DefaultObject = (props) => {
437
435
  const $ = c(4);
438
436
  let t0;
439
437
  $[0] !== props.value ? (t0 = JSON.stringify(props.value, null, 2), $[0] = props.value, $[1] = t0) : t0 = $[1];
@@ -731,12 +729,12 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
731
729
  ] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
732
730
  };
733
731
  DraggableBlock.displayName = "DraggableBlock";
734
- var __defProp$n = Object.defineProperty, __defProps$h = Object.defineProperties, __getOwnPropDescs$h = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$n = Object.getOwnPropertySymbols, __hasOwnProp$n = Object.prototype.hasOwnProperty, __propIsEnum$n = Object.prototype.propertyIsEnumerable, __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$n = (a, b) => {
732
+ var __defProp$o = Object.defineProperty, __defProps$h = Object.defineProperties, __getOwnPropDescs$h = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$o = Object.getOwnPropertySymbols, __hasOwnProp$o = Object.prototype.hasOwnProperty, __propIsEnum$o = Object.prototype.propertyIsEnumerable, __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$o = (a, b) => {
735
733
  for (var prop in b || (b = {}))
736
- __hasOwnProp$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
737
- if (__getOwnPropSymbols$n)
738
- for (var prop of __getOwnPropSymbols$n(b))
739
- __propIsEnum$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
734
+ __hasOwnProp$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
735
+ if (__getOwnPropSymbols$o)
736
+ for (var prop of __getOwnPropSymbols$o(b))
737
+ __propIsEnum$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
740
738
  return a;
741
739
  }, __spreadProps$h = (a, b) => __defProps$h(a, __getOwnPropDescs$h(b));
742
740
  debugWithName("components:Element");
@@ -775,7 +773,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
775
773
  }, "children", {
776
774
  _key: element._key
777
775
  }];
778
- return /* @__PURE__ */ jsxs("span", __spreadProps$h(__spreadValues$n({}, attributes), { children: [
776
+ return /* @__PURE__ */ jsxs("span", __spreadProps$h(__spreadValues$o({}, attributes), { children: [
779
777
  children,
780
778
  /* @__PURE__ */ jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
781
779
  renderChild && renderChild({
@@ -843,7 +841,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
843
841
  return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
844
842
  }
845
843
  }), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
846
- return /* @__PURE__ */ jsx("div", __spreadProps$h(__spreadValues$n({}, attributes), { className, spellCheck, children: /* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }), element._key);
844
+ return /* @__PURE__ */ jsx("div", __spreadProps$h(__spreadValues$o({}, attributes), { className, spellCheck, children: /* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }), element._key);
847
845
  }
848
846
  const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
849
847
  if (!schemaType_0)
@@ -868,7 +866,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
868
866
  });
869
867
  renderedBlockFromProps = renderBlock(_props);
870
868
  }
871
- return /* @__PURE__ */ jsxs("div", __spreadProps$h(__spreadValues$n({}, attributes), { className, children: [
869
+ return /* @__PURE__ */ jsxs("div", __spreadProps$h(__spreadValues$o({}, attributes), { className, children: [
872
870
  children,
873
871
  /* @__PURE__ */ jsxs(DraggableBlock, { element, readOnly, blockRef, children: [
874
872
  renderedBlockFromProps && /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
@@ -902,12 +900,83 @@ function compileType(rawType) {
902
900
  types: [rawType]
903
901
  }).get(rawType.name);
904
902
  }
905
- var __defProp$m = Object.defineProperty, __defProps$g = Object.defineProperties, __getOwnPropDescs$g = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$m = Object.getOwnPropertySymbols, __hasOwnProp$m = Object.prototype.hasOwnProperty, __propIsEnum$m = Object.prototype.propertyIsEnumerable, __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$m = (a, b) => {
903
+ const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3, mutationMachine = setup({
904
+ types: {
905
+ context: {},
906
+ events: {},
907
+ input: {},
908
+ emitted: {}
909
+ },
910
+ actions: {
911
+ "emit has pending patches": emit({
912
+ type: "has pending patches"
913
+ }),
914
+ "emit mutation": emit(({
915
+ context
916
+ }) => ({
917
+ type: "mutation",
918
+ patches: context.pendingPatches,
919
+ snapshot: fromSlateValue(context.slateEditor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(context.slateEditor))
920
+ })),
921
+ "clear pending patches": assign({
922
+ pendingPatches: []
923
+ }),
924
+ "defer patch": assign({
925
+ pendingPatches: ({
926
+ context,
927
+ event
928
+ }) => [...context.pendingPatches, event.patch]
929
+ })
930
+ },
931
+ guards: {
932
+ "slate is normalizing": ({
933
+ context
934
+ }) => Editor.isNormalizing(context.slateEditor)
935
+ }
936
+ }).createMachine({
937
+ id: "mutation",
938
+ context: ({
939
+ input
940
+ }) => ({
941
+ pendingPatches: [],
942
+ schema: input.schema,
943
+ slateEditor: input.slateEditor
944
+ }),
945
+ initial: "idle",
946
+ states: {
947
+ idle: {
948
+ on: {
949
+ patch: {
950
+ actions: ["defer patch", "emit has pending patches"],
951
+ target: "has pending patches"
952
+ }
953
+ }
954
+ },
955
+ "has pending patches": {
956
+ after: {
957
+ [FLUSH_PATCHES_THROTTLED_MS]: [{
958
+ guard: "slate is normalizing",
959
+ target: "idle",
960
+ actions: ["emit mutation", "clear pending patches"]
961
+ }, {
962
+ reenter: !0
963
+ }]
964
+ },
965
+ on: {
966
+ patch: {
967
+ actions: ["defer patch"],
968
+ reenter: !0
969
+ }
970
+ }
971
+ }
972
+ }
973
+ });
974
+ var __defProp$n = Object.defineProperty, __defProps$g = Object.defineProperties, __getOwnPropDescs$g = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$n = Object.getOwnPropertySymbols, __hasOwnProp$n = Object.prototype.hasOwnProperty, __propIsEnum$n = Object.prototype.propertyIsEnumerable, __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$n = (a, b) => {
906
975
  for (var prop in b || (b = {}))
907
- __hasOwnProp$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
908
- if (__getOwnPropSymbols$m)
909
- for (var prop of __getOwnPropSymbols$m(b))
910
- __propIsEnum$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
976
+ __hasOwnProp$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
977
+ if (__getOwnPropSymbols$n)
978
+ for (var prop of __getOwnPropSymbols$n(b))
979
+ __propIsEnum$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
911
980
  return a;
912
981
  }, __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
913
982
  function validateValue(value, types, keyGenerator) {
@@ -947,7 +1016,7 @@ function validateValue(value, types, keyGenerator) {
947
1016
  }, !0;
948
1017
  if (!blk._key || typeof blk._key != "string")
949
1018
  return resolution = {
950
- patches: [set(__spreadProps$g(__spreadValues$m({}, blk), {
1019
+ patches: [set(__spreadProps$g(__spreadValues$n({}, blk), {
951
1020
  _key: keyGenerator()
952
1021
  }), [index])],
953
1022
  description: `Block at index ${index} is missing required _key.`,
@@ -965,7 +1034,7 @@ function validateValue(value, types, keyGenerator) {
965
1034
  if (blk._type === "block") {
966
1035
  const currentBlockTypeName = types.block.name;
967
1036
  return resolution = {
968
- patches: [set(__spreadProps$g(__spreadValues$m({}, blk), {
1037
+ patches: [set(__spreadProps$g(__spreadValues$n({}, blk), {
969
1038
  _type: currentBlockTypeName
970
1039
  }), [{
971
1040
  _key: blk._key
@@ -983,10 +1052,10 @@ function validateValue(value, types, keyGenerator) {
983
1052
  }
984
1053
  }, !0;
985
1054
  }
986
- return !blk._type && isPortableTextTextBlock(__spreadProps$g(__spreadValues$m({}, blk), {
1055
+ return !blk._type && isPortableTextTextBlock(__spreadProps$g(__spreadValues$n({}, blk), {
987
1056
  _type: types.block.name
988
1057
  })) ? (resolution = {
989
- patches: [set(__spreadProps$g(__spreadValues$m({}, blk), {
1058
+ patches: [set(__spreadProps$g(__spreadValues$n({}, blk), {
990
1059
  _type: types.block.name
991
1060
  }), [{
992
1061
  _key: blk._key
@@ -1148,7 +1217,7 @@ function validateValue(value, types, keyGenerator) {
1148
1217
  }
1149
1218
  }, !0;
1150
1219
  if (!child._key || typeof child._key != "string") {
1151
- const newChild = __spreadProps$g(__spreadValues$m({}, child), {
1220
+ const newChild = __spreadProps$g(__spreadValues$n({}, child), {
1152
1221
  _key: keyGenerator()
1153
1222
  });
1154
1223
  return resolution = {
@@ -1170,7 +1239,7 @@ function validateValue(value, types, keyGenerator) {
1170
1239
  }, !0;
1171
1240
  }
1172
1241
  return child._type ? validChildTypes.includes(child._type) ? child._type === types.span.name && typeof child.text != "string" ? (resolution = {
1173
- patches: [set(__spreadProps$g(__spreadValues$m({}, child), {
1242
+ patches: [set(__spreadProps$g(__spreadValues$n({}, child), {
1174
1243
  text: ""
1175
1244
  }), [{
1176
1245
  _key: blk._key
@@ -1240,9 +1309,6 @@ function withRemoteChanges(editor, fn) {
1240
1309
  function isChangingRemotely(editor) {
1241
1310
  return IS_PROCESSING_REMOTE_CHANGES.get(editor);
1242
1311
  }
1243
- function isChangingLocally(editor) {
1244
- return IS_PROCESSING_LOCAL_CHANGES.get(editor);
1245
- }
1246
1312
  const PATCHING = /* @__PURE__ */ new WeakMap();
1247
1313
  function withoutPatching(editor, fn) {
1248
1314
  const prev = isPatching(editor);
@@ -1965,15 +2031,15 @@ function isRedoing(editor) {
1965
2031
  function setIsRedoing(editor, isRedoing2) {
1966
2032
  IS_REDOING.set(editor, isRedoing2);
1967
2033
  }
1968
- var __defProp$l = Object.defineProperty, __getOwnPropSymbols$l = Object.getOwnPropertySymbols, __hasOwnProp$l = Object.prototype.hasOwnProperty, __propIsEnum$l = Object.prototype.propertyIsEnumerable, __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$l = (a, b) => {
2034
+ var __defProp$m = Object.defineProperty, __getOwnPropSymbols$m = Object.getOwnPropertySymbols, __hasOwnProp$m = Object.prototype.hasOwnProperty, __propIsEnum$m = Object.prototype.propertyIsEnumerable, __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$m = (a, b) => {
1969
2035
  for (var prop in b || (b = {}))
1970
- __hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
1971
- if (__getOwnPropSymbols$l)
1972
- for (var prop of __getOwnPropSymbols$l(b))
1973
- __propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
2036
+ __hasOwnProp$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
2037
+ if (__getOwnPropSymbols$m)
2038
+ for (var prop of __getOwnPropSymbols$m(b))
2039
+ __propIsEnum$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
1974
2040
  return a;
1975
2041
  };
1976
- const debug$j = debugWithName("plugin:withUndoRedo"), debugVerbose$4 = debug$j.enabled && !1, SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
2042
+ const debug$j = debugWithName("plugin:withUndoRedo"), debugVerbose$3 = debug$j.enabled && !1, SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
1977
2043
  const state = SAVING.get(editor);
1978
2044
  return state === void 0 ? !0 : state;
1979
2045
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
@@ -2021,7 +2087,9 @@ function createWithUndoRedo(options) {
2021
2087
  apply: apply2
2022
2088
  } = editor;
2023
2089
  return editor.apply = (op) => {
2024
- if (editorActor.getSnapshot().context.readOnly) {
2090
+ if (editorActor.getSnapshot().matches({
2091
+ "edit mode": "read only"
2092
+ })) {
2025
2093
  apply2(op);
2026
2094
  return;
2027
2095
  }
@@ -2056,7 +2124,9 @@ function createWithUndoRedo(options) {
2056
2124
  }
2057
2125
  apply2(op);
2058
2126
  }, editor.undo = () => {
2059
- if (editorActor.getSnapshot().context.readOnly)
2127
+ if (editorActor.getSnapshot().matches({
2128
+ "edit mode": "read only"
2129
+ }))
2060
2130
  return;
2061
2131
  const {
2062
2132
  undos
@@ -2091,7 +2161,9 @@ function createWithUndoRedo(options) {
2091
2161
  }
2092
2162
  }
2093
2163
  }, editor.redo = () => {
2094
- if (editorActor.getSnapshot().context.readOnly)
2164
+ if (editorActor.getSnapshot().matches({
2165
+ "edit mode": "read only"
2166
+ }))
2095
2167
  return;
2096
2168
  const {
2097
2169
  redos
@@ -2128,8 +2200,8 @@ function createWithUndoRedo(options) {
2128
2200
  };
2129
2201
  }
2130
2202
  function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
2131
- debugVerbose$4 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
2132
- const transformedOperation = __spreadValues$l({}, operation);
2203
+ debugVerbose$3 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
2204
+ const transformedOperation = __spreadValues$m({}, operation);
2133
2205
  if (patch.type === "insert" && patch.path.length === 1) {
2134
2206
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
2135
2207
  _key: blk._key
@@ -2140,7 +2212,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
2140
2212
  const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
2141
2213
  _key: blk._key
2142
2214
  }, patch.path[0]));
2143
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$j("Skipping transformation that targeted removed block"), []) : (debugVerbose$4 && (debug$j(`Selection ${JSON.stringify(editor.selection)}`), debug$j(`Adjusting block path (-1) for '${transformedOperation.type}' operation and patch '${patch.type}'`)), [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)]);
2215
+ return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$j("Skipping transformation that targeted removed block"), []) : (debugVerbose$3 && (debug$j(`Selection ${JSON.stringify(editor.selection)}`), debug$j(`Adjusting block path (-1) for '${transformedOperation.type}' operation and patch '${patch.type}'`)), [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)]);
2144
2216
  }
2145
2217
  if (patch.type === "unset" && patch.path.length === 0)
2146
2218
  return debug$j(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
@@ -2158,7 +2230,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
2158
2230
  const [diffType, text] = diff2;
2159
2231
  diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
2160
2232
  }), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
2161
- const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$l({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$l({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$l({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$l({}, transformedOperation.newProperties.anchor) : void 0;
2233
+ const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$m({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$m({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$m({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$m({}, transformedOperation.newProperties.anchor) : void 0;
2162
2234
  (currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
2163
2235
  point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
2164
2236
  }), currentFocus && currentAnchor && (transformedOperation.properties = {
@@ -2175,13 +2247,13 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
2175
2247
  }
2176
2248
  function adjustBlockPath(operation, level, blockIndex) {
2177
2249
  var _a, _b, _c, _d;
2178
- const transformedOperation = __spreadValues$l({}, operation);
2250
+ const transformedOperation = __spreadValues$m({}, operation);
2179
2251
  if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
2180
2252
  const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
2181
2253
  transformedOperation.path = newPath;
2182
2254
  }
2183
2255
  if (transformedOperation.type === "set_selection") {
2184
- const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$l({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$l({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$l({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$l({}, transformedOperation.newProperties.anchor) : void 0;
2256
+ const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$m({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$m({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$m({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$m({}, transformedOperation.newProperties.anchor) : void 0;
2185
2257
  (currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
2186
2258
  point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
2187
2259
  }), currentFocus && currentAnchor && (transformedOperation.properties = {
@@ -2202,147 +2274,336 @@ function withoutSaving(editor, fn) {
2202
2274
  function createSelectOperation(editor) {
2203
2275
  return {
2204
2276
  type: "set_selection",
2205
- properties: __spreadValues$l({}, editor.selection),
2206
- newProperties: __spreadValues$l({}, editor.selection)
2277
+ properties: __spreadValues$m({}, editor.selection),
2278
+ newProperties: __spreadValues$m({}, editor.selection)
2207
2279
  };
2208
2280
  }
2209
2281
  function findOperationTargetBlock(editor, operation) {
2210
2282
  let block;
2211
2283
  return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
2212
2284
  }
2213
- const debug$i = debugWithName("hook:useSyncValue"), CURRENT_VALUE = /* @__PURE__ */ new WeakMap();
2214
- function useSyncValue(props) {
2215
- const {
2216
- editorActor,
2217
- portableTextEditor,
2218
- readOnly,
2219
- slateEditor
2220
- } = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = useRef(void 0), updateValueFunctionRef = useRef(void 0), updateFromCurrentValue = useCallback(() => {
2221
- const currentValue = CURRENT_VALUE.get(portableTextEditor);
2222
- if (previousValue.current === currentValue) {
2223
- debug$i("Value is the same object as previous, not need to sync");
2224
- return;
2285
+ const syncValueCallback = ({
2286
+ sendBack,
2287
+ input
2288
+ }) => {
2289
+ updateValue({
2290
+ context: input.context,
2291
+ sendBack,
2292
+ slateEditor: input.slateEditor,
2293
+ value: input.value
2294
+ });
2295
+ }, syncValueLogic = fromCallback(syncValueCallback), syncMachine = setup({
2296
+ types: {
2297
+ context: {},
2298
+ input: {},
2299
+ events: {},
2300
+ emitted: {}
2301
+ },
2302
+ actions: {
2303
+ "assign readOnly": assign({
2304
+ readOnly: ({
2305
+ context
2306
+ }) => !context.readOnly
2307
+ }),
2308
+ "assign pending value": assign({
2309
+ pendingValue: ({
2310
+ event
2311
+ }) => (assertEvent(event, "update value"), event.value)
2312
+ }),
2313
+ "clear pending value": assign({
2314
+ pendingValue: void 0
2315
+ }),
2316
+ "assign previous value": assign({
2317
+ previousValue: ({
2318
+ event
2319
+ }) => (assertEvent(event, "done syncing"), event.value)
2320
+ }),
2321
+ "emit done syncing": emit(({
2322
+ event
2323
+ }) => (assertEvent(event, "done syncing"), event))
2324
+ },
2325
+ guards: {
2326
+ "is readOnly": ({
2327
+ context
2328
+ }) => context.readOnly,
2329
+ "is processing local changes": ({
2330
+ context
2331
+ }) => context.isProcessingLocalChanges,
2332
+ "is processing remote changes": ({
2333
+ context
2334
+ }) => {
2335
+ var _a;
2336
+ return (_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1;
2337
+ },
2338
+ "is busy": and([not("is readOnly"), or(["is processing local changes", "is processing remote changes"])]),
2339
+ "value changed while syncing": ({
2340
+ context,
2341
+ event
2342
+ }) => (assertEvent(event, "done syncing"), context.pendingValue !== event.value),
2343
+ "pending value equals previous value": ({
2344
+ context
2345
+ }) => !(context.previousValue === void 0 && context.pendingValue === void 0) && isEqual(context.pendingValue, context.previousValue)
2346
+ },
2347
+ actors: {
2348
+ "sync value": syncValueLogic
2349
+ }
2350
+ }).createMachine({
2351
+ id: "sync",
2352
+ context: ({
2353
+ input
2354
+ }) => ({
2355
+ isProcessingLocalChanges: !1,
2356
+ keyGenerator: input.keyGenerator,
2357
+ schema: input.schema,
2358
+ readOnly: input.readOnly,
2359
+ slateEditor: input.slateEditor,
2360
+ pendingValue: void 0,
2361
+ previousValue: void 0
2362
+ }),
2363
+ initial: "idle",
2364
+ on: {
2365
+ "has pending patches": {
2366
+ actions: assign({
2367
+ isProcessingLocalChanges: !0
2368
+ })
2369
+ },
2370
+ mutation: {
2371
+ actions: assign({
2372
+ isProcessingLocalChanges: !1
2373
+ })
2374
+ },
2375
+ "toggle readOnly": {
2376
+ actions: ["assign readOnly"]
2225
2377
  }
2226
- updateValueFunctionRef.current && currentValue && (debug$i("Updating the value debounced"), updateValueFunctionRef.current(currentValue));
2227
- }, [portableTextEditor]), updateValueDebounced = useMemo(() => debounce(updateFromCurrentValue, 1e3, {
2228
- trailing: !0,
2229
- leading: !1
2230
- }), [updateFromCurrentValue]);
2231
- return useMemo(() => {
2232
- const updateFunction = (value) => {
2233
- CURRENT_VALUE.set(portableTextEditor, value);
2234
- const isProcessingLocalChanges = isChangingLocally(slateEditor), isProcessingRemoteChanges = isChangingRemotely(slateEditor);
2235
- if (!readOnly) {
2236
- if (isProcessingLocalChanges) {
2237
- debug$i("Has local changes, not syncing value right now"), updateValueDebounced();
2238
- return;
2378
+ },
2379
+ states: {
2380
+ idle: {
2381
+ on: {
2382
+ "update value": [{
2383
+ guard: "is busy",
2384
+ target: "busy",
2385
+ actions: ["assign pending value"]
2386
+ }, {
2387
+ target: "syncing",
2388
+ actions: ["assign pending value"]
2389
+ }]
2390
+ }
2391
+ },
2392
+ busy: {
2393
+ after: {
2394
+ 1e3: {
2395
+ target: "syncing"
2239
2396
  }
2240
- if (isProcessingRemoteChanges) {
2241
- debug$i("Has remote changes, not syncing value right now"), updateValueDebounced();
2242
- return;
2397
+ },
2398
+ on: {
2399
+ "update value": [{
2400
+ guard: "is busy",
2401
+ actions: ["assign pending value"],
2402
+ reenter: !0
2403
+ }, {
2404
+ target: "syncing",
2405
+ actions: ["assign pending value"]
2406
+ }]
2407
+ }
2408
+ },
2409
+ syncing: {
2410
+ invoke: {
2411
+ src: "sync value",
2412
+ id: "sync value",
2413
+ input: ({
2414
+ context
2415
+ }) => {
2416
+ var _a;
2417
+ return {
2418
+ context: {
2419
+ keyGenerator: context.keyGenerator,
2420
+ previousValue: context.previousValue,
2421
+ readOnly: context.readOnly,
2422
+ schema: context.schema
2423
+ },
2424
+ slateEditor: context.slateEditor,
2425
+ value: (_a = context.pendingValue) != null ? _a : void 0
2426
+ };
2243
2427
  }
2428
+ },
2429
+ always: {
2430
+ guard: "pending value equals previous value",
2431
+ actions: [emit(({
2432
+ context
2433
+ }) => ({
2434
+ type: "done syncing",
2435
+ value: context.previousValue
2436
+ }))],
2437
+ target: "idle"
2438
+ },
2439
+ on: {
2440
+ "update value": {
2441
+ actions: ["assign pending value"]
2442
+ },
2443
+ patch: {
2444
+ actions: [emit(({
2445
+ event
2446
+ }) => event)]
2447
+ },
2448
+ "invalid value": {
2449
+ actions: [emit(({
2450
+ event
2451
+ }) => event)]
2452
+ },
2453
+ "value changed": {
2454
+ actions: [emit(({
2455
+ event
2456
+ }) => event)]
2457
+ },
2458
+ "done syncing": [{
2459
+ guard: "value changed while syncing",
2460
+ actions: ["assign previous value", "emit done syncing"],
2461
+ reenter: !0
2462
+ }, {
2463
+ target: "idle",
2464
+ actions: ["clear pending value", "assign previous value", "emit done syncing"]
2465
+ }]
2244
2466
  }
2245
- let isChanged = !1, isValid = !0;
2246
- const hadSelection = !!slateEditor.selection;
2247
- if ((!value || value.length === 0) && (debug$i("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
2248
- withoutSaving(slateEditor, () => {
2249
- withoutPatching(slateEditor, () => {
2250
- hadSelection && Transforms.deselect(slateEditor);
2251
- const childrenLength = slateEditor.children.length;
2252
- slateEditor.children.forEach((_, index) => {
2253
- Transforms.removeNodes(slateEditor, {
2254
- at: [childrenLength - 1 - index]
2255
- });
2256
- }), Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
2257
- decorators: []
2258
- }), {
2259
- at: [0]
2260
- }), hadSelection && Transforms.select(slateEditor, [0, 0]);
2467
+ }
2468
+ }
2469
+ }), debug$i = debugWithName("hook:useSyncValue");
2470
+ function updateValue({
2471
+ context,
2472
+ sendBack,
2473
+ slateEditor,
2474
+ value
2475
+ }) {
2476
+ let isChanged = !1, isValid = !0;
2477
+ const hadSelection = !!slateEditor.selection;
2478
+ if ((!value || value.length === 0) && (debug$i("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
2479
+ withoutSaving(slateEditor, () => {
2480
+ withoutPatching(slateEditor, () => {
2481
+ hadSelection && Transforms.deselect(slateEditor);
2482
+ const childrenLength = slateEditor.children.length;
2483
+ slateEditor.children.forEach((_, index) => {
2484
+ Transforms.removeNodes(slateEditor, {
2485
+ at: [childrenLength - 1 - index]
2261
2486
  });
2262
- });
2263
- }), isChanged = !0), value && value.length > 0) {
2264
- const slateValueFromProps = toSlateValue(value, {
2265
- schemaTypes
2266
- });
2267
- Editor.withoutNormalizing(slateEditor, () => {
2268
- withRemoteChanges(slateEditor, () => {
2269
- withoutSaving(slateEditor, () => {
2270
- withoutPatching(slateEditor, () => {
2271
- const childrenLength_0 = slateEditor.children.length;
2272
- if (slateValueFromProps.length < childrenLength_0) {
2273
- for (let i = childrenLength_0 - 1; i > slateValueFromProps.length - 1; i--)
2274
- Transforms.removeNodes(slateEditor, {
2275
- at: [i]
2276
- });
2277
- isChanged = !0;
2278
- }
2279
- slateValueFromProps.forEach((currentBlock, currentBlockIndex) => {
2280
- var _a, _b, _c, _d, _e;
2281
- const oldBlock = slateEditor.children[currentBlockIndex];
2282
- if (oldBlock && !isEqual(currentBlock, oldBlock) && isValid) {
2283
- const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
2284
- !validation.valid && (_a = validation.resolution) != null && _a.autoResolve && ((_b = validation.resolution) == null ? void 0 : _b.patches.length) > 0 && !readOnly && previousValue.current && previousValue.current !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${(_c = validation.resolution) == null ? void 0 : _c.description}`), validation.resolution.patches.forEach((patch) => {
2285
- editorActor.send({
2286
- type: "patch",
2287
- patch
2288
- });
2289
- })), validation.valid || (_d = validation.resolution) != null && _d.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), isChanged = !0) : (editorActor.send({
2290
- type: "invalid value",
2291
- resolution: validation.resolution,
2292
- value
2293
- }), isValid = !1);
2294
- }
2295
- if (!oldBlock && isValid) {
2296
- const validationValue_0 = [value[currentBlockIndex]], validation_0 = validateValue(validationValue_0, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
2297
- debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation_0.valid || (_e = validation_0.resolution) != null && _e.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
2298
- at: [currentBlockIndex]
2299
- }) : (debug$i("Invalid", validation_0), editorActor.send({
2300
- type: "invalid value",
2301
- resolution: validation_0.resolution,
2302
- value
2303
- }), isValid = !1);
2304
- }
2305
- });
2487
+ }), Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
2488
+ decorators: []
2489
+ }), {
2490
+ at: [0]
2491
+ }), hadSelection && Transforms.select(slateEditor, [0, 0]);
2492
+ });
2493
+ });
2494
+ }), isChanged = !0), value && value.length > 0) {
2495
+ const slateValueFromProps = toSlateValue(value, {
2496
+ schemaTypes: context.schema
2497
+ });
2498
+ Editor.withoutNormalizing(slateEditor, () => {
2499
+ withRemoteChanges(slateEditor, () => {
2500
+ withoutPatching(slateEditor, () => {
2501
+ const childrenLength = slateEditor.children.length;
2502
+ if (slateValueFromProps.length < childrenLength) {
2503
+ for (let i = childrenLength - 1; i > slateValueFromProps.length - 1; i--)
2504
+ Transforms.removeNodes(slateEditor, {
2505
+ at: [i]
2306
2506
  });
2507
+ isChanged = !0;
2508
+ }
2509
+ for (const [currentBlockIndex, currentBlock] of slateValueFromProps.entries()) {
2510
+ const {
2511
+ blockChanged,
2512
+ blockValid
2513
+ } = syncBlock({
2514
+ context,
2515
+ sendBack,
2516
+ block: currentBlock,
2517
+ index: currentBlockIndex,
2518
+ slateEditor,
2519
+ value
2307
2520
  });
2308
- });
2309
- });
2310
- }
2311
- if (!isValid) {
2312
- debug$i("Invalid value, returning");
2313
- return;
2314
- }
2315
- if (isChanged) {
2316
- debug$i("Server value changed, syncing editor");
2317
- try {
2318
- slateEditor.onChange();
2319
- } catch (err) {
2320
- console.error(err), editorActor.send({
2321
- type: "invalid value",
2322
- resolution: null,
2323
- value
2324
- });
2325
- return;
2326
- }
2327
- hadSelection && !slateEditor.selection && (Transforms.select(slateEditor, {
2328
- anchor: {
2329
- path: [0, 0],
2330
- offset: 0
2331
- },
2332
- focus: {
2333
- path: [0, 0],
2334
- offset: 0
2521
+ isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
2335
2522
  }
2336
- }), slateEditor.onChange()), editorActor.send({
2337
- type: "value changed",
2338
- value
2339
2523
  });
2340
- } else
2341
- debug$i("Server value and editor value is equal, no need to sync.");
2342
- previousValue.current = value;
2343
- };
2344
- return updateValueFunctionRef.current = updateFunction, updateFunction;
2345
- }, [editorActor, portableTextEditor, readOnly, schemaTypes, slateEditor, updateValueDebounced]);
2524
+ });
2525
+ });
2526
+ }
2527
+ if (!isValid) {
2528
+ debug$i("Invalid value, returning"), sendBack({
2529
+ type: "done syncing",
2530
+ value
2531
+ });
2532
+ return;
2533
+ }
2534
+ if (isChanged) {
2535
+ debug$i("Server value changed, syncing editor");
2536
+ try {
2537
+ slateEditor.onChange();
2538
+ } catch (err) {
2539
+ console.error(err), sendBack({
2540
+ type: "invalid value",
2541
+ resolution: null,
2542
+ value
2543
+ }), sendBack({
2544
+ type: "done syncing",
2545
+ value
2546
+ });
2547
+ return;
2548
+ }
2549
+ hadSelection && !slateEditor.selection && (Transforms.select(slateEditor, {
2550
+ anchor: {
2551
+ path: [0, 0],
2552
+ offset: 0
2553
+ },
2554
+ focus: {
2555
+ path: [0, 0],
2556
+ offset: 0
2557
+ }
2558
+ }), slateEditor.onChange()), sendBack({
2559
+ type: "value changed",
2560
+ value
2561
+ });
2562
+ } else
2563
+ debug$i("Server value and editor value is equal, no need to sync.");
2564
+ sendBack({
2565
+ type: "done syncing",
2566
+ value
2567
+ });
2568
+ }
2569
+ function syncBlock({
2570
+ context,
2571
+ sendBack,
2572
+ block,
2573
+ index,
2574
+ slateEditor,
2575
+ value
2576
+ }) {
2577
+ var _a, _b, _c, _d, _e;
2578
+ let blockChanged = !1, blockValid = !0;
2579
+ const currentBlock = block, currentBlockIndex = index, oldBlock = slateEditor.children[currentBlockIndex];
2580
+ if (oldBlock && !isEqual(currentBlock, oldBlock) && blockValid) {
2581
+ const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
2582
+ !validation.valid && (_a = validation.resolution) != null && _a.autoResolve && ((_b = validation.resolution) == null ? void 0 : _b.patches.length) > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${(_c = validation.resolution) == null ? void 0 : _c.description}`), validation.resolution.patches.forEach((patch) => {
2583
+ sendBack({
2584
+ type: "patch",
2585
+ patch
2586
+ });
2587
+ })), validation.valid || (_d = validation.resolution) != null && _d.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
2588
+ type: "invalid value",
2589
+ resolution: validation.resolution,
2590
+ value
2591
+ }), blockValid = !1);
2592
+ }
2593
+ if (!oldBlock && blockValid) {
2594
+ const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
2595
+ debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid || (_e = validation.resolution) != null && _e.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
2596
+ at: [currentBlockIndex]
2597
+ }) : (debug$i("Invalid", validation), sendBack({
2598
+ type: "invalid value",
2599
+ resolution: validation.resolution,
2600
+ value
2601
+ }), blockValid = !1);
2602
+ }
2603
+ return {
2604
+ blockChanged,
2605
+ blockValid
2606
+ };
2346
2607
  }
2347
2608
  function _replaceBlock(slateEditor, currentBlock, currentBlockIndex) {
2348
2609
  const currentSelection = slateEditor.selection, selectionFocusOnBlock = currentSelection && currentSelection.focus.path[0] === currentBlockIndex;
@@ -2399,89 +2660,106 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2399
2660
  });
2400
2661
  }
2401
2662
  }
2402
- const debug$h = debugWithName("component:PortableTextEditor:Synchronizer"), debugVerbose$3 = debug$h.enabled && !1, FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3;
2663
+ const debug$h = debugWithName("component:PortableTextEditor:Synchronizer");
2403
2664
  function Synchronizer(props) {
2404
- const $ = c(26), readOnly = useSelector(props.editorActor, _temp), value = useSelector(props.editorActor, _temp2), {
2665
+ const $ = c(41), {
2405
2666
  editorActor,
2406
- getValue: getValue2,
2407
- portableTextEditor,
2408
2667
  slateEditor
2409
- } = props;
2668
+ } = props, value = useSelector(props.editorActor, _temp), readOnly = useSelector(props.editorActor, _temp2);
2410
2669
  let t0;
2411
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
2412
- const pendingPatches = useRef(t0);
2413
- let t1;
2414
- $[1] !== editorActor || $[2] !== portableTextEditor || $[3] !== readOnly || $[4] !== slateEditor ? (t1 = {
2415
- editorActor,
2416
- portableTextEditor,
2417
- readOnly,
2418
- slateEditor
2419
- }, $[1] = editorActor, $[2] = portableTextEditor, $[3] = readOnly, $[4] = slateEditor, $[5] = t1) : t1 = $[5];
2420
- const syncValue = useSyncValue(t1);
2421
- let t2, t3;
2422
- $[6] !== slateEditor ? (t2 = () => {
2423
- IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
2424
- }, t3 = [slateEditor], $[6] = slateEditor, $[7] = t2, $[8] = t3) : (t2 = $[7], t3 = $[8]), useEffect(t2, t3);
2670
+ $[0] !== props.editorActor ? (t0 = props.editorActor.getSnapshot(), $[0] = props.editorActor, $[1] = t0) : t0 = $[1];
2671
+ const t1 = t0.context.keyGenerator;
2672
+ let t2;
2673
+ $[2] !== props.editorActor ? (t2 = props.editorActor.getSnapshot().matches({
2674
+ "edit mode": "read only"
2675
+ }), $[2] = props.editorActor, $[3] = t2) : t2 = $[3];
2676
+ let t3;
2677
+ $[4] !== props.editorActor ? (t3 = props.editorActor.getSnapshot(), $[4] = props.editorActor, $[5] = t3) : t3 = $[5];
2425
2678
  let t4;
2426
- $[9] !== editorActor || $[10] !== getValue2 || $[11] !== slateEditor ? (t4 = () => {
2427
- if (pendingPatches.current.length > 0) {
2428
- debug$h("Flushing pending patches"), debugVerbose$3 && debug$h(`Patches:
2429
- ${JSON.stringify(pendingPatches.current, null, 2)}`);
2430
- const snapshot = getValue2();
2431
- editorActor.send({
2432
- type: "mutation",
2433
- patches: pendingPatches.current,
2434
- snapshot
2435
- }), pendingPatches.current = [];
2679
+ $[6] !== slateEditor || $[7] !== t0.context.keyGenerator || $[8] !== t2 || $[9] !== t3.context.schema ? (t4 = {
2680
+ input: {
2681
+ keyGenerator: t1,
2682
+ readOnly: t2,
2683
+ schema: t3.context.schema,
2684
+ slateEditor
2436
2685
  }
2437
- IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
2438
- }, $[9] = editorActor, $[10] = getValue2, $[11] = slateEditor, $[12] = t4) : t4 = $[12];
2439
- const onFlushPendingPatches = t4;
2440
- let t5, t6;
2441
- $[13] !== onFlushPendingPatches ? (t5 = () => () => {
2442
- onFlushPendingPatches();
2443
- }, t6 = [onFlushPendingPatches], $[13] = onFlushPendingPatches, $[14] = t5, $[15] = t6) : (t5 = $[14], t6 = $[15]), useEffect(t5, t6);
2686
+ }, $[6] = slateEditor, $[7] = t0.context.keyGenerator, $[8] = t2, $[9] = t3.context.schema, $[10] = t4) : t4 = $[10];
2687
+ const syncActorRef = useActorRef(syncMachine, t4);
2688
+ let t5;
2689
+ $[11] !== editorActor ? (t5 = editorActor.getSnapshot(), $[11] = editorActor, $[12] = t5) : t5 = $[12];
2690
+ let t6;
2691
+ $[13] !== slateEditor || $[14] !== t5.context.schema ? (t6 = {
2692
+ input: {
2693
+ schema: t5.context.schema,
2694
+ slateEditor
2695
+ }
2696
+ }, $[13] = slateEditor, $[14] = t5.context.schema, $[15] = t6) : t6 = $[15];
2697
+ const mutationActorRef = useActorRef(mutationMachine, t6);
2444
2698
  let t7, t8;
2445
- $[16] !== editorActor || $[17] !== onFlushPendingPatches || $[18] !== slateEditor ? (t7 = () => {
2446
- const onFlushPendingPatchesThrottled = throttle(() => {
2447
- if (Editor.isNormalizing(slateEditor)) {
2448
- onFlushPendingPatches();
2449
- return;
2450
- }
2451
- onFlushPendingPatchesThrottled();
2452
- }, FLUSH_PATCHES_THROTTLED_MS, {
2453
- leading: !1,
2454
- trailing: !0
2699
+ $[16] !== editorActor || $[17] !== mutationActorRef || $[18] !== syncActorRef ? (t7 = () => {
2700
+ const subscription = mutationActorRef.on("*", (event) => {
2701
+ event.type === "has pending patches" && syncActorRef.send({
2702
+ type: "has pending patches"
2703
+ }), event.type === "mutation" && (syncActorRef.send({
2704
+ type: "mutation"
2705
+ }), editorActor.send(event));
2706
+ });
2707
+ return () => {
2708
+ subscription.unsubscribe();
2709
+ };
2710
+ }, t8 = [mutationActorRef, syncActorRef, editorActor], $[16] = editorActor, $[17] = mutationActorRef, $[18] = syncActorRef, $[19] = t7, $[20] = t8) : (t7 = $[19], t8 = $[20]), useEffect(t7, t8);
2711
+ let t10, t9;
2712
+ $[21] !== props.editorActor || $[22] !== syncActorRef ? (t9 = () => {
2713
+ const subscription_0 = syncActorRef.on("*", (event_0) => {
2714
+ props.editorActor.send(event_0);
2455
2715
  });
2716
+ return () => {
2717
+ subscription_0.unsubscribe();
2718
+ };
2719
+ }, t10 = [props.editorActor, syncActorRef], $[21] = props.editorActor, $[22] = syncActorRef, $[23] = t10, $[24] = t9) : (t10 = $[23], t9 = $[24]), useEffect(t9, t10);
2720
+ let t11;
2721
+ $[25] !== syncActorRef ? (t11 = () => {
2722
+ syncActorRef.send({
2723
+ type: "toggle readOnly"
2724
+ });
2725
+ }, $[25] = syncActorRef, $[26] = t11) : t11 = $[26];
2726
+ let t12;
2727
+ $[27] !== readOnly || $[28] !== syncActorRef ? (t12 = [syncActorRef, readOnly], $[27] = readOnly, $[28] = syncActorRef, $[29] = t12) : t12 = $[29], useEffect(t11, t12);
2728
+ let t13, t14;
2729
+ $[30] !== syncActorRef || $[31] !== value ? (t13 = () => {
2730
+ debug$h("Value from props changed, syncing new value"), syncActorRef.send({
2731
+ type: "update value",
2732
+ value
2733
+ });
2734
+ }, t14 = [syncActorRef, value], $[30] = syncActorRef, $[31] = value, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), useEffect(t13, t14);
2735
+ let t15;
2736
+ $[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
2456
2737
  debug$h("Subscribing to patch events");
2457
- const sub = editorActor.on("patch", (event) => {
2458
- IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !0), pendingPatches.current.push(event.patch), onFlushPendingPatchesThrottled();
2738
+ const sub = editorActor.on("patch", (event_1) => {
2739
+ mutationActorRef.send(event_1);
2459
2740
  });
2460
2741
  return () => {
2461
2742
  debug$h("Unsubscribing to patch events"), sub.unsubscribe();
2462
2743
  };
2463
- }, t8 = [editorActor, onFlushPendingPatches, slateEditor], $[16] = editorActor, $[17] = onFlushPendingPatches, $[18] = slateEditor, $[19] = t7, $[20] = t8) : (t7 = $[19], t8 = $[20]), useEffect(t7, t8);
2464
- const isInitialValueFromProps = useRef(!0);
2465
- let t10, t9;
2466
- return $[21] !== editorActor || $[22] !== syncValue || $[23] !== value ? (t9 = () => {
2467
- debug$h("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (editorActor.send({
2468
- type: "ready"
2469
- }), isInitialValueFromProps.current = !1);
2470
- }, t10 = [editorActor, syncValue, value], $[21] = editorActor, $[22] = syncValue, $[23] = value, $[24] = t10, $[25] = t9) : (t10 = $[24], t9 = $[25]), useEffect(t9, t10), null;
2744
+ }, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
2745
+ let t16;
2746
+ return $[37] !== editorActor || $[38] !== mutationActorRef || $[39] !== slateEditor ? (t16 = [editorActor, mutationActorRef, slateEditor], $[37] = editorActor, $[38] = mutationActorRef, $[39] = slateEditor, $[40] = t16) : t16 = $[40], useEffect(t15, t16), null;
2471
2747
  }
2472
2748
  function _temp2(s_0) {
2473
- return s_0.context.value;
2749
+ return s_0.matches({
2750
+ "edit mode": "read only"
2751
+ });
2474
2752
  }
2475
2753
  function _temp(s) {
2476
- return s.context.readOnly;
2754
+ return s.context.value;
2477
2755
  }
2478
2756
  Synchronizer.displayName = "Synchronizer";
2479
- var __defProp$k = Object.defineProperty, __defProps$f = Object.defineProperties, __getOwnPropDescs$f = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$k = Object.getOwnPropertySymbols, __hasOwnProp$k = Object.prototype.hasOwnProperty, __propIsEnum$k = Object.prototype.propertyIsEnumerable, __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$k = (a, b) => {
2757
+ var __defProp$l = Object.defineProperty, __defProps$f = Object.defineProperties, __getOwnPropDescs$f = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$l = Object.getOwnPropertySymbols, __hasOwnProp$l = Object.prototype.hasOwnProperty, __propIsEnum$l = Object.prototype.propertyIsEnumerable, __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$l = (a, b) => {
2480
2758
  for (var prop in b || (b = {}))
2481
- __hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
2482
- if (__getOwnPropSymbols$k)
2483
- for (var prop of __getOwnPropSymbols$k(b))
2484
- __propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
2759
+ __hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
2760
+ if (__getOwnPropSymbols$l)
2761
+ for (var prop of __getOwnPropSymbols$l(b))
2762
+ __propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
2485
2763
  return a;
2486
2764
  }, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
2487
2765
  const debug$g = debugWithName("operationToPatches");
@@ -2523,7 +2801,7 @@ function createOperationToPatches(types) {
2523
2801
  const block = editor.children[operation.path[0]];
2524
2802
  if (typeof block._key != "string")
2525
2803
  throw new Error("Expected block to have a _key");
2526
- const setNode = omitBy(__spreadValues$k(__spreadValues$k({}, editor.children[operation.path[0]]), operation.newProperties), isUndefined);
2804
+ const setNode = omitBy(__spreadValues$l(__spreadValues$l({}, editor.children[operation.path[0]]), operation.newProperties), isUndefined);
2527
2805
  return [set(fromSlateValue([setNode], textBlockName)[0], [{
2528
2806
  _key: block._key
2529
2807
  }])];
@@ -2563,7 +2841,7 @@ function createOperationToPatches(types) {
2563
2841
  _key: targetKey
2564
2842
  }])] : [setIfMissing(beforeValue, []), insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
2565
2843
  } else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
2566
- const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = __spreadValues$k({}, operation.node);
2844
+ const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = __spreadValues$l({}, operation.node);
2567
2845
  !node._type && Text.isText(node) && (node._type = "span", node.marks = []);
2568
2846
  const child = fromSlateValue([{
2569
2847
  _key: "bogus",
@@ -2602,7 +2880,7 @@ function createOperationToPatches(types) {
2602
2880
  if (operation.path.length === 2) {
2603
2881
  const splitSpan = splitBlock.children[operation.path[1]];
2604
2882
  if (editor.isTextSpan(splitSpan)) {
2605
- const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$k({}, splitBlock), {
2883
+ const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$l({}, splitBlock), {
2606
2884
  children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
2607
2885
  })], textBlockName)[0].children;
2608
2886
  patches.push(insert(targetSpans, "after", [{
@@ -2913,7 +3191,9 @@ function createWithMaxBlocks(editorActor) {
2913
3191
  } = editor;
2914
3192
  return editor.apply = (operation) => {
2915
3193
  var _a;
2916
- if (editorActor.getSnapshot().context.readOnly) {
3194
+ if (editorActor.getSnapshot().matches({
3195
+ "edit mode": "read only"
3196
+ })) {
2917
3197
  apply2(operation);
2918
3198
  return;
2919
3199
  }
@@ -2930,12 +3210,12 @@ function createWithMaxBlocks(editorActor) {
2930
3210
  }, editor;
2931
3211
  };
2932
3212
  }
2933
- var __defProp$j = Object.defineProperty, __defProps$e = Object.defineProperties, __getOwnPropDescs$e = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$j = Object.getOwnPropertySymbols, __hasOwnProp$j = Object.prototype.hasOwnProperty, __propIsEnum$j = Object.prototype.propertyIsEnumerable, __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$j = (a, b) => {
3213
+ var __defProp$k = Object.defineProperty, __defProps$e = Object.defineProperties, __getOwnPropDescs$e = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$k = Object.getOwnPropertySymbols, __hasOwnProp$k = Object.prototype.hasOwnProperty, __propIsEnum$k = Object.prototype.propertyIsEnumerable, __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$k = (a, b) => {
2934
3214
  for (var prop in b || (b = {}))
2935
- __hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
2936
- if (__getOwnPropSymbols$j)
2937
- for (var prop of __getOwnPropSymbols$j(b))
2938
- __propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
3215
+ __hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
3216
+ if (__getOwnPropSymbols$k)
3217
+ for (var prop of __getOwnPropSymbols$k(b))
3218
+ __propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
2939
3219
  return a;
2940
3220
  }, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
2941
3221
  function createWithObjectKeys(editorActor, schemaTypes) {
@@ -2954,16 +3234,16 @@ function createWithObjectKeys(editorActor, schemaTypes) {
2954
3234
  return;
2955
3235
  }
2956
3236
  if (operation.type === "split_node") {
2957
- apply2(__spreadProps$e(__spreadValues$j({}, operation), {
2958
- properties: __spreadProps$e(__spreadValues$j({}, operation.properties), {
3237
+ apply2(__spreadProps$e(__spreadValues$k({}, operation), {
3238
+ properties: __spreadProps$e(__spreadValues$k({}, operation.properties), {
2959
3239
  _key: editorActor.getSnapshot().context.keyGenerator()
2960
3240
  })
2961
3241
  }));
2962
3242
  return;
2963
3243
  }
2964
3244
  if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
2965
- apply2(__spreadProps$e(__spreadValues$j({}, operation), {
2966
- node: __spreadProps$e(__spreadValues$j({}, operation.node), {
3245
+ apply2(__spreadProps$e(__spreadValues$k({}, operation), {
3246
+ node: __spreadProps$e(__spreadValues$k({}, operation.node), {
2967
3247
  _key: editorActor.getSnapshot().context.keyGenerator()
2968
3248
  })
2969
3249
  }));
@@ -3003,20 +3283,20 @@ function createWithObjectKeys(editorActor, schemaTypes) {
3003
3283
  }, editor;
3004
3284
  };
3005
3285
  }
3006
- var __defProp$i = Object.defineProperty, __defProps$d = Object.defineProperties, __getOwnPropDescs$d = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$i = Object.getOwnPropertySymbols, __hasOwnProp$i = Object.prototype.hasOwnProperty, __propIsEnum$i = Object.prototype.propertyIsEnumerable, __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$i = (a, b) => {
3286
+ var __defProp$j = Object.defineProperty, __defProps$d = Object.defineProperties, __getOwnPropDescs$d = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$j = Object.getOwnPropertySymbols, __hasOwnProp$j = Object.prototype.hasOwnProperty, __propIsEnum$j = Object.prototype.propertyIsEnumerable, __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$j = (a, b) => {
3007
3287
  for (var prop in b || (b = {}))
3008
- __hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
3009
- if (__getOwnPropSymbols$i)
3010
- for (var prop of __getOwnPropSymbols$i(b))
3011
- __propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
3288
+ __hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
3289
+ if (__getOwnPropSymbols$j)
3290
+ for (var prop of __getOwnPropSymbols$j(b))
3291
+ __propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
3012
3292
  return a;
3013
3293
  }, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
3014
3294
  var target = {};
3015
3295
  for (var prop in source)
3016
- __hasOwnProp$i.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
3017
- if (source != null && __getOwnPropSymbols$i)
3018
- for (var prop of __getOwnPropSymbols$i(source))
3019
- exclude.indexOf(prop) < 0 && __propIsEnum$i.call(source, prop) && (target[prop] = source[prop]);
3296
+ __hasOwnProp$j.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
3297
+ if (source != null && __getOwnPropSymbols$j)
3298
+ for (var prop of __getOwnPropSymbols$j(source))
3299
+ exclude.indexOf(prop) < 0 && __propIsEnum$j.call(source, prop) && (target[prop] = source[prop]);
3020
3300
  return target;
3021
3301
  };
3022
3302
  const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
@@ -3108,7 +3388,7 @@ function insertPatch(editor, patch, schemaTypes) {
3108
3388
  } = patch;
3109
3389
  if (!targetChild || !targetChildPath)
3110
3390
  return debug$f("Child not found"), !1;
3111
- const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$i({}, targetBlock), {
3391
+ const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$j({}, targetBlock), {
3112
3392
  children: items
3113
3393
  })], {
3114
3394
  schemaTypes
@@ -3167,7 +3447,7 @@ function setPatch(editor, patch) {
3167
3447
  editor.apply({
3168
3448
  type: "set_node",
3169
3449
  path: blockPath,
3170
- properties: __spreadValues$i({}, prevRest),
3450
+ properties: __spreadValues$j({}, prevRest),
3171
3451
  newProperties: nextRest
3172
3452
  }), debug$f("Setting children"), block.children.forEach((c2, cIndex) => {
3173
3453
  editor.apply({
@@ -3184,7 +3464,7 @@ function setPatch(editor, patch) {
3184
3464
  });
3185
3465
  } else if (block && "value" in block) {
3186
3466
  const newVal = applyAll([block.value], [patch])[0];
3187
- return Transforms.setNodes(editor, __spreadProps$d(__spreadValues$i({}, block), {
3467
+ return Transforms.setNodes(editor, __spreadProps$d(__spreadValues$j({}, block), {
3188
3468
  value: newVal
3189
3469
  }), {
3190
3470
  at: blockPath
@@ -3277,12 +3557,12 @@ function findBlockAndChildFromPath(editor, path) {
3277
3557
  childPath: void 0
3278
3558
  };
3279
3559
  }
3280
- var __defProp$h = Object.defineProperty, __defProps$c = Object.defineProperties, __getOwnPropDescs$c = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$h = Object.getOwnPropertySymbols, __hasOwnProp$h = Object.prototype.hasOwnProperty, __propIsEnum$h = Object.prototype.propertyIsEnumerable, __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$h = (a, b) => {
3560
+ var __defProp$i = Object.defineProperty, __defProps$c = Object.defineProperties, __getOwnPropDescs$c = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$i = Object.getOwnPropertySymbols, __hasOwnProp$i = Object.prototype.hasOwnProperty, __propIsEnum$i = Object.prototype.propertyIsEnumerable, __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$i = (a, b) => {
3281
3561
  for (var prop in b || (b = {}))
3282
- __hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
3283
- if (__getOwnPropSymbols$h)
3284
- for (var prop of __getOwnPropSymbols$h(b))
3285
- __propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
3562
+ __hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
3563
+ if (__getOwnPropSymbols$i)
3564
+ for (var prop of __getOwnPropSymbols$i(b))
3565
+ __propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
3286
3566
  return a;
3287
3567
  }, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
3288
3568
  const debug$e = debugWithName("plugin:withPatches");
@@ -3330,8 +3610,6 @@ function createWithPatches({
3330
3610
  debug$e("Unsubscribing to remote patches"), sub.unsubscribe();
3331
3611
  };
3332
3612
  }), editor.apply = (operation) => {
3333
- if (editorActor.getSnapshot().context.readOnly)
3334
- return apply2(operation), editor;
3335
3613
  let patches = [];
3336
3614
  previousChildren = editor.children;
3337
3615
  const editorWasEmpty = isEqualToEmptyEditor(previousChildren, schemaTypes);
@@ -3371,7 +3649,7 @@ function createWithPatches({
3371
3649
  })), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0 && patches.forEach((patch) => {
3372
3650
  editorActor.send({
3373
3651
  type: "patch",
3374
- patch: __spreadProps$c(__spreadValues$h({}, patch), {
3652
+ patch: __spreadProps$c(__spreadValues$i({}, patch), {
3375
3653
  origin: "local"
3376
3654
  })
3377
3655
  });
@@ -3386,7 +3664,9 @@ function createWithPlaceholderBlock(editorActor) {
3386
3664
  apply: apply2
3387
3665
  } = editor;
3388
3666
  return editor.apply = (op) => {
3389
- if (editorActor.getSnapshot().context.readOnly) {
3667
+ if (editorActor.getSnapshot().matches({
3668
+ "edit mode": "read only"
3669
+ })) {
3390
3670
  apply2(op);
3391
3671
  return;
3392
3672
  }
@@ -3484,12 +3764,12 @@ function getNextSpan({
3484
3764
  }
3485
3765
  return nextSpan;
3486
3766
  }
3487
- var __defProp$g = Object.defineProperty, __defProps$b = Object.defineProperties, __getOwnPropDescs$b = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$g = Object.getOwnPropertySymbols, __hasOwnProp$g = Object.prototype.hasOwnProperty, __propIsEnum$g = Object.prototype.propertyIsEnumerable, __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$g = (a, b) => {
3767
+ var __defProp$h = Object.defineProperty, __defProps$b = Object.defineProperties, __getOwnPropDescs$b = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$h = Object.getOwnPropertySymbols, __hasOwnProp$h = Object.prototype.hasOwnProperty, __propIsEnum$h = Object.prototype.propertyIsEnumerable, __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$h = (a, b) => {
3488
3768
  for (var prop in b || (b = {}))
3489
- __hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
3490
- if (__getOwnPropSymbols$g)
3491
- for (var prop of __getOwnPropSymbols$g(b))
3492
- __propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
3769
+ __hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
3770
+ if (__getOwnPropSymbols$h)
3771
+ for (var prop of __getOwnPropSymbols$h(b))
3772
+ __propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
3493
3773
  return a;
3494
3774
  }, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
3495
3775
  const debug$b = debugWithName("plugin:withPortableTextMarkModel");
@@ -3691,21 +3971,21 @@ function createWithPortableTextMarkModel(editorActor, types) {
3691
3971
  spanPath: [op.path[0], op.path[1] - 1]
3692
3972
  }), nextSpanAnnotations = nextSpan ? (_d = nextSpan.marks) == null ? void 0 : _d.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = (_e = previousSpanAnnotations == null ? void 0 : previousSpanAnnotations.filter((annotation) => !(nextSpanAnnotations != null && nextSpanAnnotations.includes(annotation)))) != null ? _e : [], atTheEndOfAnnotation = annotationsEnding.length > 0;
3693
3973
  if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && (_f = op.node.marks) != null && _f.some((mark) => annotationsEnding.includes(mark))) {
3694
- Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
3974
+ Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
3695
3975
  marks: (_h = (_g = op.node.marks) == null ? void 0 : _g.filter((mark) => !annotationsEnding.includes(mark))) != null ? _h : []
3696
3976
  }));
3697
3977
  return;
3698
3978
  }
3699
3979
  const annotationsStarting = (_i = nextSpanAnnotations == null ? void 0 : nextSpanAnnotations.filter((annotation) => !(previousSpanAnnotations != null && previousSpanAnnotations.includes(annotation)))) != null ? _i : [], atTheStartOfAnnotation = annotationsStarting.length > 0;
3700
3980
  if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && (_j = op.node.marks) != null && _j.some((mark) => annotationsStarting.includes(mark))) {
3701
- Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
3981
+ Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
3702
3982
  marks: (_l = (_k = op.node.marks) == null ? void 0 : _k.filter((mark) => !annotationsStarting.includes(mark))) != null ? _l : []
3703
3983
  }));
3704
3984
  return;
3705
3985
  }
3706
3986
  const nextSpanDecorators = (_n = (_m = nextSpan == null ? void 0 : nextSpan.marks) == null ? void 0 : _m.filter((mark) => decorators.includes(mark))) != null ? _n : [];
3707
3987
  if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && ((_o = op.node.marks) == null ? void 0 : _o.length) === 0) {
3708
- Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
3988
+ Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
3709
3989
  marks: nextSpanDecorators
3710
3990
  }));
3711
3991
  return;
@@ -3823,7 +4103,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3823
4103
  spanPath
3824
4104
  }), previousSpanHasSameAnnotation = previousSpan ? (_E = previousSpan.marks) == null ? void 0 : _E.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? (_F = nextSpan.marks) == null ? void 0 : _F.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
3825
4105
  if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
3826
- const marksWithoutAnnotationMarks = (__spreadValues$g({}, Editor.marks(editor) || {}).marks || []).filter((mark) => decorators.includes(mark));
4106
+ const marksWithoutAnnotationMarks = (__spreadValues$h({}, Editor.marks(editor) || {}).marks || []).filter((mark) => decorators.includes(mark));
3827
4107
  Editor.withoutNormalizing(editor, () => {
3828
4108
  apply2(op), Transforms.setNodes(editor, {
3829
4109
  marks: marksWithoutAnnotationMarks
@@ -3896,7 +4176,7 @@ const addDecoratorActionImplementation = ({
3896
4176
  match: (node) => editor.isTextSpan(node)
3897
4177
  });
3898
4178
  } else {
3899
- const existingMarks = __spreadValues$g({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, Editor.marks(editor) || {}), {
4179
+ const existingMarks = __spreadValues$h({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$h({}, Editor.marks(editor) || {}), {
3900
4180
  marks: [...existingMarks, mark]
3901
4181
  });
3902
4182
  editor.marks = marks;
@@ -3942,7 +4222,7 @@ const addDecoratorActionImplementation = ({
3942
4222
  match: (node) => editor.isTextSpan(node)
3943
4223
  });
3944
4224
  } else {
3945
- const existingMarks = __spreadValues$g({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, Editor.marks(editor) || {}), {
4225
+ const existingMarks = __spreadValues$h({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$h({}, Editor.marks(editor) || {}), {
3946
4226
  marks: existingMarks.filter((eMark) => eMark !== mark)
3947
4227
  });
3948
4228
  editor.marks = {
@@ -3966,7 +4246,7 @@ function isDecoratorActive({
3966
4246
  var _a;
3967
4247
  const [node] = n;
3968
4248
  return (_a = node.marks) == null ? void 0 : _a.includes(decorator);
3969
- }) : (__spreadValues$g({}, Editor.marks(editor) || {}).marks || []).includes(decorator);
4249
+ }) : (__spreadValues$h({}, Editor.marks(editor) || {}).marks || []).includes(decorator);
3970
4250
  }
3971
4251
  const toggleDecoratorActionImplementation = ({
3972
4252
  context,
@@ -4020,16 +4300,18 @@ function createWithPortableTextSelections(editorActor, types) {
4020
4300
  } = editor;
4021
4301
  return editor.onChange = () => {
4022
4302
  const hasChanges = editor.operations.length > 0;
4023
- onChange(), hasChanges && emitPortableTextSelection();
4303
+ onChange(), hasChanges && !editorActor.getSnapshot().matches({
4304
+ setup: "setting up"
4305
+ }) && emitPortableTextSelection();
4024
4306
  }, editor;
4025
4307
  };
4026
4308
  }
4027
- var __defProp$f = Object.defineProperty, __defProps$a = Object.defineProperties, __getOwnPropDescs$a = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$f = Object.getOwnPropertySymbols, __hasOwnProp$f = Object.prototype.hasOwnProperty, __propIsEnum$f = Object.prototype.propertyIsEnumerable, __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$f = (a, b) => {
4309
+ var __defProp$g = Object.defineProperty, __defProps$a = Object.defineProperties, __getOwnPropDescs$a = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$g = Object.getOwnPropertySymbols, __hasOwnProp$g = Object.prototype.hasOwnProperty, __propIsEnum$g = Object.prototype.propertyIsEnumerable, __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$g = (a, b) => {
4028
4310
  for (var prop in b || (b = {}))
4029
- __hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
4030
- if (__getOwnPropSymbols$f)
4031
- for (var prop of __getOwnPropSymbols$f(b))
4032
- __propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
4311
+ __hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
4312
+ if (__getOwnPropSymbols$g)
4313
+ for (var prop of __getOwnPropSymbols$g(b))
4314
+ __propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
4033
4315
  return a;
4034
4316
  }, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
4035
4317
  const debug$9 = debugWithName("plugin:withSchemaTypes");
@@ -4049,7 +4331,7 @@ function createWithSchemaTypes({
4049
4331
  const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
4050
4332
  editorActor.send({
4051
4333
  type: "normalizing"
4052
- }), Transforms.setNodes(editor, __spreadProps$a(__spreadValues$f({}, span), {
4334
+ }), Transforms.setNodes(editor, __spreadProps$a(__spreadValues$g({}, span), {
4053
4335
  _type: schemaTypes.span.name,
4054
4336
  _key: key
4055
4337
  }), {
@@ -4077,12 +4359,12 @@ function createWithSchemaTypes({
4077
4359
  }, editor;
4078
4360
  };
4079
4361
  }
4080
- var __defProp$e = Object.defineProperty, __defProps$9 = Object.defineProperties, __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$e = Object.getOwnPropertySymbols, __hasOwnProp$e = Object.prototype.hasOwnProperty, __propIsEnum$e = Object.prototype.propertyIsEnumerable, __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$e = (a, b) => {
4362
+ var __defProp$f = Object.defineProperty, __defProps$9 = Object.defineProperties, __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$f = Object.getOwnPropertySymbols, __hasOwnProp$f = Object.prototype.hasOwnProperty, __propIsEnum$f = Object.prototype.propertyIsEnumerable, __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$f = (a, b) => {
4081
4363
  for (var prop in b || (b = {}))
4082
- __hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
4083
- if (__getOwnPropSymbols$e)
4084
- for (var prop of __getOwnPropSymbols$e(b))
4085
- __propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
4364
+ __hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
4365
+ if (__getOwnPropSymbols$f)
4366
+ for (var prop of __getOwnPropSymbols$f(b))
4367
+ __propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
4086
4368
  return a;
4087
4369
  }, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
4088
4370
  const debug$8 = debugWithName("plugin:withUtils");
@@ -4108,10 +4390,10 @@ function createWithUtils({
4108
4390
  } = 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);
4109
4391
  if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
4110
4392
  debug$8("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
4111
- anchor: __spreadProps$9(__spreadValues$e({}, selection.anchor), {
4393
+ anchor: __spreadProps$9(__spreadValues$f({}, selection.anchor), {
4112
4394
  offset: newStartOffset
4113
4395
  }),
4114
- focus: __spreadProps$9(__spreadValues$e({}, selection.focus), {
4396
+ focus: __spreadProps$9(__spreadValues$f({}, selection.focus), {
4115
4397
  offset: newEndOffset
4116
4398
  })
4117
4399
  });
@@ -4119,7 +4401,7 @@ function createWithUtils({
4119
4401
  }
4120
4402
  debug$8("pteExpandToWord: Can't expand to word here");
4121
4403
  }
4122
- }, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$e(__spreadValues$e({
4404
+ }, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$f(__spreadValues$f({
4123
4405
  _type: schemaTypes.block.name,
4124
4406
  _key: editorActor.getSnapshot().context.keyGenerator(),
4125
4407
  style: schemaTypes.styles[0].value || "normal"
@@ -4183,12 +4465,12 @@ function createSlateEditor(config) {
4183
4465
  };
4184
4466
  return slateEditors.set(config.editorActor, slateEditor), slateEditor;
4185
4467
  }
4186
- var __defProp$d = Object.defineProperty, __defProps$8 = Object.defineProperties, __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$d = Object.getOwnPropertySymbols, __hasOwnProp$d = Object.prototype.hasOwnProperty, __propIsEnum$d = Object.prototype.propertyIsEnumerable, __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$d = (a, b) => {
4468
+ var __defProp$e = Object.defineProperty, __defProps$8 = Object.defineProperties, __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$e = Object.getOwnPropertySymbols, __hasOwnProp$e = Object.prototype.hasOwnProperty, __propIsEnum$e = Object.prototype.propertyIsEnumerable, __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$e = (a, b) => {
4187
4469
  for (var prop in b || (b = {}))
4188
- __hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
4189
- if (__getOwnPropSymbols$d)
4190
- for (var prop of __getOwnPropSymbols$d(b))
4191
- __propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
4470
+ __hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
4471
+ if (__getOwnPropSymbols$e)
4472
+ for (var prop of __getOwnPropSymbols$e(b))
4473
+ __propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
4192
4474
  return a;
4193
4475
  }, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
4194
4476
  const toggleListItemActionImplementation = ({
@@ -4200,12 +4482,12 @@ const toggleListItemActionImplementation = ({
4200
4482
  listItem: action.listItem
4201
4483
  }) ? removeListItemActionImplementation({
4202
4484
  context,
4203
- action: __spreadProps$8(__spreadValues$d({}, action), {
4485
+ action: __spreadProps$8(__spreadValues$e({}, action), {
4204
4486
  type: "list item.remove"
4205
4487
  })
4206
4488
  }) : addListItemActionImplementation({
4207
4489
  context,
4208
- action: __spreadProps$8(__spreadValues$d({}, action), {
4490
+ action: __spreadProps$8(__spreadValues$e({}, action), {
4209
4491
  type: "list item.add"
4210
4492
  })
4211
4493
  });
@@ -4253,12 +4535,12 @@ function isListItemActive({
4253
4535
  })];
4254
4536
  return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
4255
4537
  }
4256
- var __defProp$c = Object.defineProperty, __defProps$7 = Object.defineProperties, __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$c = Object.getOwnPropertySymbols, __hasOwnProp$c = Object.prototype.hasOwnProperty, __propIsEnum$c = Object.prototype.propertyIsEnumerable, __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$c = (a, b) => {
4538
+ var __defProp$d = Object.defineProperty, __defProps$7 = Object.defineProperties, __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$d = Object.getOwnPropertySymbols, __hasOwnProp$d = Object.prototype.hasOwnProperty, __propIsEnum$d = Object.prototype.propertyIsEnumerable, __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$d = (a, b) => {
4257
4539
  for (var prop in b || (b = {}))
4258
- __hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
4259
- if (__getOwnPropSymbols$c)
4260
- for (var prop of __getOwnPropSymbols$c(b))
4261
- __propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
4540
+ __hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
4541
+ if (__getOwnPropSymbols$d)
4542
+ for (var prop of __getOwnPropSymbols$d(b))
4543
+ __propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
4262
4544
  return a;
4263
4545
  }, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
4264
4546
  const toggleStyleActionImplementation = ({
@@ -4270,12 +4552,12 @@ const toggleStyleActionImplementation = ({
4270
4552
  style: action.style
4271
4553
  }) ? removeStyleActionImplementation({
4272
4554
  context,
4273
- action: __spreadProps$7(__spreadValues$c({}, action), {
4555
+ action: __spreadProps$7(__spreadValues$d({}, action), {
4274
4556
  type: "style.remove"
4275
4557
  })
4276
4558
  }) : addStyleActionImplementation({
4277
4559
  context,
4278
- action: __spreadProps$7(__spreadValues$c({}, action), {
4560
+ action: __spreadProps$7(__spreadValues$d({}, action), {
4279
4561
  type: "style.add"
4280
4562
  })
4281
4563
  });
@@ -4324,12 +4606,12 @@ function isStyleActive({
4324
4606
  })];
4325
4607
  return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
4326
4608
  }
4327
- var __defProp$b = Object.defineProperty, __getOwnPropSymbols$b = Object.getOwnPropertySymbols, __hasOwnProp$b = Object.prototype.hasOwnProperty, __propIsEnum$b = Object.prototype.propertyIsEnumerable, __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$b = (a, b) => {
4609
+ var __defProp$c = Object.defineProperty, __getOwnPropSymbols$c = Object.getOwnPropertySymbols, __hasOwnProp$c = Object.prototype.hasOwnProperty, __propIsEnum$c = Object.prototype.propertyIsEnumerable, __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$c = (a, b) => {
4328
4610
  for (var prop in b || (b = {}))
4329
- __hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
4330
- if (__getOwnPropSymbols$b)
4331
- for (var prop of __getOwnPropSymbols$b(b))
4332
- __propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
4611
+ __hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
4612
+ if (__getOwnPropSymbols$c)
4613
+ for (var prop of __getOwnPropSymbols$c(b))
4614
+ __propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
4333
4615
  return a;
4334
4616
  };
4335
4617
  const debug$6 = debugWithName("API:editable");
@@ -4394,7 +4676,7 @@ function createEditableAPI(editor, editorActor) {
4394
4676
  return console.warn(err), !1;
4395
4677
  }
4396
4678
  },
4397
- marks: () => __spreadValues$b({}, Editor.marks(editor) || {}).marks || [],
4679
+ marks: () => __spreadValues$c({}, Editor.marks(editor) || {}).marks || [],
4398
4680
  undo: () => editor.undo(),
4399
4681
  redo: () => editor.redo(),
4400
4682
  select: (selection) => {
@@ -4442,7 +4724,7 @@ function createEditableAPI(editor, editorActor) {
4442
4724
  const child = toSlateValue([{
4443
4725
  _key: editorActor.getSnapshot().context.keyGenerator(),
4444
4726
  _type: types.block.name,
4445
- children: [__spreadValues$b({
4727
+ children: [__spreadValues$c({
4446
4728
  _key: editorActor.getSnapshot().context.keyGenerator(),
4447
4729
  _type: type.name
4448
4730
  }, value || {})]
@@ -4706,7 +4988,7 @@ const addAnnotationActionImplementation = ({
4706
4988
  continue;
4707
4989
  const annotationKey = context.keyGenerator(), markDefs = (_a = block.markDefs) != null ? _a : [];
4708
4990
  markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
4709
- markDefs: [...markDefs, __spreadValues$b({
4991
+ markDefs: [...markDefs, __spreadValues$c({
4710
4992
  _type: action.annotation.name,
4711
4993
  _key: annotationKey
4712
4994
  }, action.annotation.value)]
@@ -4883,19 +5165,19 @@ function insertBlock({
4883
5165
  });
4884
5166
  }
4885
5167
  }
4886
- var __defProp$a = Object.defineProperty, __getOwnPropSymbols$a = Object.getOwnPropertySymbols, __hasOwnProp$a = Object.prototype.hasOwnProperty, __propIsEnum$a = Object.prototype.propertyIsEnumerable, __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$a = (a, b) => {
5168
+ var __defProp$b = Object.defineProperty, __getOwnPropSymbols$b = Object.getOwnPropertySymbols, __hasOwnProp$b = Object.prototype.hasOwnProperty, __propIsEnum$b = Object.prototype.propertyIsEnumerable, __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$b = (a, b) => {
4887
5169
  for (var prop in b || (b = {}))
4888
- __hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
4889
- if (__getOwnPropSymbols$a)
4890
- for (var prop of __getOwnPropSymbols$a(b))
4891
- __propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
5170
+ __hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
5171
+ if (__getOwnPropSymbols$b)
5172
+ for (var prop of __getOwnPropSymbols$b(b))
5173
+ __propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
4892
5174
  return a;
4893
5175
  };
4894
5176
  const insertBlockObjectActionImplementation = ({
4895
5177
  context,
4896
5178
  action
4897
5179
  }) => {
4898
- const block = toSlateValue([__spreadValues$a({
5180
+ const block = toSlateValue([__spreadValues$b({
4899
5181
  _key: context.keyGenerator(),
4900
5182
  _type: action.blockObject.name
4901
5183
  }, action.blockObject.value ? action.blockObject.value : {})], {
@@ -4908,12 +5190,12 @@ const insertBlockObjectActionImplementation = ({
4908
5190
  schema: context.schema
4909
5191
  });
4910
5192
  };
4911
- var __defProp$9 = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$9 = Object.getOwnPropertySymbols, __hasOwnProp$9 = Object.prototype.hasOwnProperty, __propIsEnum$9 = Object.prototype.propertyIsEnumerable, __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$9 = (a, b) => {
5193
+ var __defProp$a = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$a = Object.getOwnPropertySymbols, __hasOwnProp$a = Object.prototype.hasOwnProperty, __propIsEnum$a = Object.prototype.propertyIsEnumerable, __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$a = (a, b) => {
4912
5194
  for (var prop in b || (b = {}))
4913
- __hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
4914
- if (__getOwnPropSymbols$9)
4915
- for (var prop of __getOwnPropSymbols$9(b))
4916
- __propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
5195
+ __hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
5196
+ if (__getOwnPropSymbols$a)
5197
+ for (var prop of __getOwnPropSymbols$a(b))
5198
+ __propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
4917
5199
  return a;
4918
5200
  }, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
4919
5201
  const insertBreakActionImplementation = ({
@@ -5009,7 +5291,7 @@ const insertBreakActionImplementation = ({
5009
5291
  }
5010
5292
  const newMarkDefs = nextNode.markDefs.map((markDef) => {
5011
5293
  var _a3;
5012
- return __spreadProps$6(__spreadValues$9({}, markDef), {
5294
+ return __spreadProps$6(__spreadValues$a({}, markDef), {
5013
5295
  _key: (_a3 = newMarkDefKeys.get(markDef._key)) != null ? _a3 : markDef._key
5014
5296
  });
5015
5297
  });
@@ -5033,17 +5315,17 @@ const insertBreakActionImplementation = ({
5033
5315
  }) => {
5034
5316
  insertBreakActionImplementation({
5035
5317
  context,
5036
- action: __spreadProps$6(__spreadValues$9({}, action), {
5318
+ action: __spreadProps$6(__spreadValues$a({}, action), {
5037
5319
  type: "insert.break"
5038
5320
  })
5039
5321
  });
5040
5322
  };
5041
- var __defProp$8 = Object.defineProperty, __getOwnPropSymbols$8 = Object.getOwnPropertySymbols, __hasOwnProp$8 = Object.prototype.hasOwnProperty, __propIsEnum$8 = Object.prototype.propertyIsEnumerable, __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$8 = (a, b) => {
5323
+ var __defProp$9 = Object.defineProperty, __getOwnPropSymbols$9 = Object.getOwnPropertySymbols, __hasOwnProp$9 = Object.prototype.hasOwnProperty, __propIsEnum$9 = Object.prototype.propertyIsEnumerable, __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$9 = (a, b) => {
5042
5324
  for (var prop in b || (b = {}))
5043
- __hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
5044
- if (__getOwnPropSymbols$8)
5045
- for (var prop of __getOwnPropSymbols$8(b))
5046
- __propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
5325
+ __hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
5326
+ if (__getOwnPropSymbols$9)
5327
+ for (var prop of __getOwnPropSymbols$9(b))
5328
+ __propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
5047
5329
  return a;
5048
5330
  };
5049
5331
  const insertInlineObjectActionImplementation = ({
@@ -5070,7 +5352,7 @@ const insertInlineObjectActionImplementation = ({
5070
5352
  const block = toSlateValue([{
5071
5353
  _type: context.schema.block.name,
5072
5354
  _key: context.keyGenerator(),
5073
- children: [__spreadValues$8({
5355
+ children: [__spreadValues$9({
5074
5356
  _type: action.inlineObject.name,
5075
5357
  _key: context.keyGenerator()
5076
5358
  }, (_b = action.inlineObject.value) != null ? _b : {})]
@@ -5083,12 +5365,12 @@ const insertInlineObjectActionImplementation = ({
5083
5365
  }
5084
5366
  Transforms.insertNodes(action.editor, child);
5085
5367
  };
5086
- var __defProp$7 = Object.defineProperty, __getOwnPropSymbols$7 = Object.getOwnPropertySymbols, __hasOwnProp$7 = Object.prototype.hasOwnProperty, __propIsEnum$7 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$7 = (a, b) => {
5368
+ var __defProp$8 = Object.defineProperty, __getOwnPropSymbols$8 = Object.getOwnPropertySymbols, __hasOwnProp$8 = Object.prototype.hasOwnProperty, __propIsEnum$8 = Object.prototype.propertyIsEnumerable, __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$8 = (a, b) => {
5087
5369
  for (var prop in b || (b = {}))
5088
- __hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
5089
- if (__getOwnPropSymbols$7)
5090
- for (var prop of __getOwnPropSymbols$7(b))
5091
- __propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
5370
+ __hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
5371
+ if (__getOwnPropSymbols$8)
5372
+ for (var prop of __getOwnPropSymbols$8(b))
5373
+ __propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
5092
5374
  return a;
5093
5375
  };
5094
5376
  const insertSpanActionImplementation = ({
@@ -5108,7 +5390,7 @@ const insertSpanActionImplementation = ({
5108
5390
  console.error("Unable to perform action without focus block", action);
5109
5391
  return;
5110
5392
  }
5111
- const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$7({
5393
+ const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$8({
5112
5394
  _type: annotation.name,
5113
5395
  _key: context.keyGenerator()
5114
5396
  }, annotation.value)) : void 0;
@@ -5121,12 +5403,12 @@ const insertSpanActionImplementation = ({
5121
5403
  marks: [...(_c = annotations == null ? void 0 : annotations.map((annotation) => annotation._key)) != null ? _c : [], ...(_d = action.decorators) != null ? _d : []]
5122
5404
  });
5123
5405
  };
5124
- var __defProp$6 = Object.defineProperty, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
5406
+ var __defProp$7 = Object.defineProperty, __getOwnPropSymbols$7 = Object.getOwnPropertySymbols, __hasOwnProp$7 = Object.prototype.hasOwnProperty, __propIsEnum$7 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$7 = (a, b) => {
5125
5407
  for (var prop in b || (b = {}))
5126
- __hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
5127
- if (__getOwnPropSymbols$6)
5128
- for (var prop of __getOwnPropSymbols$6(b))
5129
- __propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
5408
+ __hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
5409
+ if (__getOwnPropSymbols$7)
5410
+ for (var prop of __getOwnPropSymbols$7(b))
5411
+ __propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
5130
5412
  return a;
5131
5413
  };
5132
5414
  const textBlockSetActionImplementation = ({
@@ -5142,7 +5424,7 @@ const textBlockSetActionImplementation = ({
5142
5424
  offset: 0
5143
5425
  }
5144
5426
  }, action.editor);
5145
- Transforms.setNodes(action.editor, __spreadValues$6(__spreadValues$6(__spreadValues$6({}, action.style ? {
5427
+ Transforms.setNodes(action.editor, __spreadValues$7(__spreadValues$7(__spreadValues$7({}, action.style ? {
5146
5428
  style: action.style
5147
5429
  } : {}), action.listItem ? {
5148
5430
  listItem: action.listItem
@@ -5168,12 +5450,12 @@ const textBlockSetActionImplementation = ({
5168
5450
  at
5169
5451
  });
5170
5452
  };
5171
- var __defProp$5 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
5453
+ var __defProp$6 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
5172
5454
  for (var prop in b || (b = {}))
5173
- __hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
5174
- if (__getOwnPropSymbols$5)
5175
- for (var prop of __getOwnPropSymbols$5(b))
5176
- __propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
5455
+ __hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
5456
+ if (__getOwnPropSymbols$6)
5457
+ for (var prop of __getOwnPropSymbols$6(b))
5458
+ __propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
5177
5459
  return a;
5178
5460
  }, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
5179
5461
  const behaviorActionImplementations = {
@@ -5271,7 +5553,7 @@ const behaviorActionImplementations = {
5271
5553
  _type: context.schema.block.name,
5272
5554
  style: (_a = context.schema.styles[0].value) != null ? _a : "normal",
5273
5555
  markDefs: [],
5274
- children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$5({}, child), {
5556
+ children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$6({}, child), {
5275
5557
  _key: context.keyGenerator()
5276
5558
  }))) != null ? _d : [{
5277
5559
  _type: context.schema.span.name,
@@ -5337,7 +5619,7 @@ const behaviorActionImplementations = {
5337
5619
  const newSelection = toSlateRange(action.selection, action.editor);
5338
5620
  newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
5339
5621
  },
5340
- "select previous block": ({
5622
+ "select.previous block": ({
5341
5623
  action
5342
5624
  }) => {
5343
5625
  if (!action.editor.selection) {
@@ -5352,7 +5634,7 @@ const behaviorActionImplementations = {
5352
5634
  const previousBlockPath = Path.previous(blockPath);
5353
5635
  Transforms.select(action.editor, previousBlockPath);
5354
5636
  },
5355
- "select next block": ({
5637
+ "select.next block": ({
5356
5638
  action
5357
5639
  }) => {
5358
5640
  if (!action.editor.selection) {
@@ -5366,7 +5648,7 @@ const behaviorActionImplementations = {
5366
5648
  action
5367
5649
  }) => {
5368
5650
  const selection = action.editor.selection;
5369
- selection && (Transforms.select(action.editor, __spreadValues$5({}, selection)), action.editor.selection = __spreadValues$5({}, selection));
5651
+ selection && (Transforms.select(action.editor, __spreadValues$6({}, selection)), action.editor.selection = __spreadValues$6({}, selection));
5370
5652
  },
5371
5653
  "style.toggle": toggleStyleActionImplementation,
5372
5654
  "style.add": addStyleActionImplementation,
@@ -5458,15 +5740,15 @@ function performAction({
5458
5740
  });
5459
5741
  break;
5460
5742
  }
5461
- case "select previous block": {
5462
- behaviorActionImplementations["select previous block"]({
5743
+ case "select.previous block": {
5744
+ behaviorActionImplementations["select.previous block"]({
5463
5745
  context,
5464
5746
  action
5465
5747
  });
5466
5748
  break;
5467
5749
  }
5468
- case "select next block": {
5469
- behaviorActionImplementations["select next block"]({
5750
+ case "select.next block": {
5751
+ behaviorActionImplementations["select.next block"]({
5470
5752
  context,
5471
5753
  action
5472
5754
  });
@@ -5638,6 +5920,22 @@ function performDefaultAction({
5638
5920
  });
5639
5921
  }
5640
5922
  }
5923
+ var __defProp$5 = Object.defineProperty, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
5924
+ for (var prop in b || (b = {}))
5925
+ __hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
5926
+ if (__getOwnPropSymbols$5)
5927
+ for (var prop of __getOwnPropSymbols$5(b))
5928
+ __propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
5929
+ return a;
5930
+ };
5931
+ function getActiveDecorators({
5932
+ schema,
5933
+ slateEditorInstance
5934
+ }) {
5935
+ var _a, _b;
5936
+ const decorators = schema.decorators.map((decorator) => decorator.value);
5937
+ return ((_b = __spreadValues$5({}, (_a = Editor.marks(slateEditorInstance)) != null ? _a : {}).marks) != null ? _b : []).filter((mark) => decorators.includes(mark));
5938
+ }
5641
5939
  var __defProp$4 = Object.defineProperty, __defProps$4 = Object.defineProperties, __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$4 = Object.getOwnPropertySymbols, __hasOwnProp$4 = Object.prototype.hasOwnProperty, __propIsEnum$4 = Object.prototype.propertyIsEnumerable, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$4 = (a, b) => {
5642
5940
  for (var prop in b || (b = {}))
5643
5941
  __hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
@@ -5670,6 +5968,12 @@ const editorMachine = setup({
5670
5968
  "emit mutation event": emit(({
5671
5969
  event
5672
5970
  }) => (assertEvent(event, "mutation"), event)),
5971
+ "emit read only": emit({
5972
+ type: "read only"
5973
+ }),
5974
+ "emit editable": emit({
5975
+ type: "editable"
5976
+ }),
5673
5977
  "defer event": assign({
5674
5978
  pendingEvents: ({
5675
5979
  context,
@@ -5683,6 +5987,9 @@ const editorMachine = setup({
5683
5987
  for (const event of context.pendingEvents)
5684
5988
  enqueue(emit(event));
5685
5989
  }),
5990
+ "emit ready": emit({
5991
+ type: "ready"
5992
+ }),
5686
5993
  "clear pending events": assign({
5687
5994
  pendingEvents: []
5688
5995
  }),
@@ -5706,18 +6013,11 @@ const editorMachine = setup({
5706
6013
  });
5707
6014
  return;
5708
6015
  }
5709
- const value = fromSlateValue(event.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(event.editor)), selection = toPortableTextRange(value, event.editor.selection, context.schema);
5710
- if (!selection) {
5711
- if (console.warn(`Unable to handle event ${event.type} due to missing selection`), !defaultAction)
5712
- return;
5713
- enqueue.raise({
5714
- type: "behavior action intends",
5715
- editor: event.editor,
5716
- actionIntends: [defaultAction]
5717
- });
5718
- return;
5719
- }
5720
- const editorContext = {
6016
+ const value = fromSlateValue(event.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(event.editor)), selection = toPortableTextRange(value, event.editor.selection, context.schema), editorContext = {
6017
+ activeDecorators: getActiveDecorators({
6018
+ schema: context.schema,
6019
+ slateEditorInstance: event.editor
6020
+ }),
5721
6021
  keyGenerator: context.keyGenerator,
5722
6022
  schema: context.schema,
5723
6023
  selection,
@@ -5768,90 +6068,13 @@ const editorMachine = setup({
5768
6068
  keyGenerator: input.keyGenerator,
5769
6069
  pendingEvents: [],
5770
6070
  schema: input.schema,
5771
- selection: void 0,
5772
- readOnly: (_b = input.readOnly) != null ? _b : !1,
6071
+ selection: null,
6072
+ initialReadOnly: (_b = input.readOnly) != null ? _b : !1,
5773
6073
  maxBlocks: input.maxBlocks,
5774
6074
  value: input.value
5775
6075
  };
5776
6076
  },
5777
6077
  on: {
5778
- "annotation.add": {
5779
- actions: emit(({
5780
- event
5781
- }) => event),
5782
- guard: ({
5783
- context
5784
- }) => !context.readOnly
5785
- },
5786
- "annotation.remove": {
5787
- actions: emit(({
5788
- event
5789
- }) => event),
5790
- guard: ({
5791
- context
5792
- }) => !context.readOnly
5793
- },
5794
- "annotation.toggle": {
5795
- actions: emit(({
5796
- event
5797
- }) => event),
5798
- guard: ({
5799
- context
5800
- }) => !context.readOnly
5801
- },
5802
- blur: {
5803
- actions: emit(({
5804
- event
5805
- }) => event),
5806
- guard: ({
5807
- context
5808
- }) => !context.readOnly
5809
- },
5810
- "decorator.*": {
5811
- actions: emit(({
5812
- event
5813
- }) => event),
5814
- guard: ({
5815
- context
5816
- }) => !context.readOnly
5817
- },
5818
- focus: {
5819
- actions: emit(({
5820
- event
5821
- }) => event),
5822
- guard: ({
5823
- context
5824
- }) => !context.readOnly
5825
- },
5826
- "insert.*": {
5827
- actions: emit(({
5828
- event
5829
- }) => event),
5830
- guard: ({
5831
- context
5832
- }) => !context.readOnly
5833
- },
5834
- "list item.*": {
5835
- actions: emit(({
5836
- event
5837
- }) => event),
5838
- guard: ({
5839
- context
5840
- }) => !context.readOnly
5841
- },
5842
- "style.*": {
5843
- actions: emit(({
5844
- event
5845
- }) => event),
5846
- guard: ({
5847
- context
5848
- }) => !context.readOnly
5849
- },
5850
- ready: {
5851
- actions: emit(({
5852
- event
5853
- }) => event)
5854
- },
5855
6078
  unset: {
5856
6079
  actions: emit(({
5857
6080
  event
@@ -5876,10 +6099,7 @@ const editorMachine = setup({
5876
6099
  actions: [assign({
5877
6100
  selection: ({
5878
6101
  event
5879
- }) => {
5880
- var _a;
5881
- return (_a = event.selection) != null ? _a : void 0;
5882
- }
6102
+ }) => event.selection
5883
6103
  }), emit(({
5884
6104
  event
5885
6105
  }) => event)]
@@ -5922,18 +6142,6 @@ const editorMachine = setup({
5922
6142
  }) => event.value
5923
6143
  })
5924
6144
  },
5925
- "toggle readOnly": {
5926
- actions: [assign({
5927
- readOnly: ({
5928
- context
5929
- }) => !context.readOnly
5930
- }), emit(({
5931
- context
5932
- }) => ({
5933
- type: "readOnly toggled",
5934
- readOnly: context.readOnly
5935
- }))]
5936
- },
5937
6145
  "update maxBlocks": {
5938
6146
  actions: assign({
5939
6147
  maxBlocks: ({
@@ -5941,12 +6149,6 @@ const editorMachine = setup({
5941
6149
  }) => event.maxBlocks
5942
6150
  })
5943
6151
  },
5944
- "behavior event": {
5945
- actions: "handle behavior event",
5946
- guard: ({
5947
- context
5948
- }) => !context.readOnly
5949
- },
5950
6152
  "behavior action intends": {
5951
6153
  actions: [({
5952
6154
  context,
@@ -5975,49 +6177,154 @@ const editorMachine = setup({
5975
6177
  })]
5976
6178
  }
5977
6179
  },
5978
- initial: "pristine",
6180
+ type: "parallel",
5979
6181
  states: {
5980
- pristine: {
5981
- initial: "idle",
6182
+ "edit mode": {
6183
+ initial: "read only",
5982
6184
  states: {
5983
- idle: {
5984
- on: {
5985
- normalizing: {
5986
- target: "normalizing"
5987
- },
5988
- patch: {
5989
- actions: "defer event",
5990
- target: "#editor.dirty"
6185
+ "read only": {
6186
+ initial: "determine initial edit mode",
6187
+ states: {
6188
+ "determine initial edit mode": {
6189
+ on: {
6190
+ "done syncing": [{
6191
+ target: "#editor.edit mode.read only.read only",
6192
+ guard: ({
6193
+ context
6194
+ }) => context.initialReadOnly
6195
+ }, {
6196
+ target: "#editor.edit mode.editable"
6197
+ }]
6198
+ }
5991
6199
  },
5992
- mutation: {
5993
- actions: "defer event",
5994
- target: "#editor.dirty"
6200
+ "read only": {
6201
+ on: {
6202
+ "toggle readOnly": {
6203
+ target: "#editor.edit mode.editable",
6204
+ actions: ["emit editable"]
6205
+ }
6206
+ }
5995
6207
  }
5996
6208
  }
5997
6209
  },
5998
- normalizing: {
6210
+ editable: {
5999
6211
  on: {
6000
- "done normalizing": {
6001
- target: "idle"
6212
+ "toggle readOnly": {
6213
+ target: "#editor.edit mode.read only.read only",
6214
+ actions: ["emit read only"]
6215
+ },
6216
+ "behavior event": {
6217
+ actions: "handle behavior event"
6218
+ },
6219
+ "annotation.add": {
6220
+ actions: emit(({
6221
+ event
6222
+ }) => event)
6223
+ },
6224
+ "annotation.remove": {
6225
+ actions: emit(({
6226
+ event
6227
+ }) => event)
6228
+ },
6229
+ "annotation.toggle": {
6230
+ actions: emit(({
6231
+ event
6232
+ }) => event)
6233
+ },
6234
+ blur: {
6235
+ actions: emit(({
6236
+ event
6237
+ }) => event)
6238
+ },
6239
+ "decorator.*": {
6240
+ actions: emit(({
6241
+ event
6242
+ }) => event)
6243
+ },
6244
+ focus: {
6245
+ actions: emit(({
6246
+ event
6247
+ }) => event)
6248
+ },
6249
+ "insert.*": {
6250
+ actions: emit(({
6251
+ event
6252
+ }) => event)
6253
+ },
6254
+ "list item.*": {
6255
+ actions: emit(({
6256
+ event
6257
+ }) => event)
6002
6258
  },
6259
+ "style.*": {
6260
+ actions: emit(({
6261
+ event
6262
+ }) => event)
6263
+ }
6264
+ }
6265
+ }
6266
+ }
6267
+ },
6268
+ setup: {
6269
+ initial: "setting up",
6270
+ states: {
6271
+ "setting up": {
6272
+ exit: ["emit ready"],
6273
+ on: {
6003
6274
  patch: {
6004
6275
  actions: "defer event"
6005
6276
  },
6006
6277
  mutation: {
6007
6278
  actions: "defer event"
6279
+ },
6280
+ "done syncing": {
6281
+ target: "pristine"
6282
+ }
6283
+ }
6284
+ },
6285
+ pristine: {
6286
+ initial: "idle",
6287
+ states: {
6288
+ idle: {
6289
+ on: {
6290
+ normalizing: {
6291
+ target: "normalizing"
6292
+ },
6293
+ patch: {
6294
+ actions: "defer event",
6295
+ target: "#editor.setup.dirty"
6296
+ },
6297
+ mutation: {
6298
+ actions: "defer event",
6299
+ target: "#editor.setup.dirty"
6300
+ }
6301
+ }
6302
+ },
6303
+ normalizing: {
6304
+ on: {
6305
+ "done normalizing": {
6306
+ target: "idle"
6307
+ },
6308
+ patch: {
6309
+ actions: "defer event"
6310
+ },
6311
+ mutation: {
6312
+ actions: "defer event"
6313
+ }
6314
+ }
6008
6315
  }
6009
6316
  }
6010
- }
6011
- }
6012
- },
6013
- dirty: {
6014
- entry: ["emit pending events", "clear pending events"],
6015
- on: {
6016
- patch: {
6017
- actions: "emit patch event"
6018
6317
  },
6019
- mutation: {
6020
- actions: "emit mutation event"
6318
+ dirty: {
6319
+ entry: ["emit pending events", "clear pending events"],
6320
+ on: {
6321
+ patch: {
6322
+ actions: "emit patch event"
6323
+ },
6324
+ mutation: {
6325
+ actions: "emit mutation event"
6326
+ }
6327
+ }
6021
6328
  }
6022
6329
  }
6023
6330
  }
@@ -6066,7 +6373,7 @@ function editorConfigToMachineInput(config) {
6066
6373
  keyGenerator: (_a = config.keyGenerator) != null ? _a : defaultKeyGenerator,
6067
6374
  maxBlocks: config.maxBlocks,
6068
6375
  readOnly: config.readOnly,
6069
- schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
6376
+ schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
6070
6377
  value: config.initialValue
6071
6378
  };
6072
6379
  }
@@ -6145,7 +6452,7 @@ class PortableTextEditor extends Component {
6145
6452
  }), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
6146
6453
  }
6147
6454
  componentDidUpdate(prevProps) {
6148
- !this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
6455
+ !this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = createEditorSchema(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
6149
6456
  type: "update schema",
6150
6457
  schema: this.schemaTypes
6151
6458
  })), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
@@ -6166,7 +6473,7 @@ class PortableTextEditor extends Component {
6166
6473
  /* @__PURE__ */ jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
6167
6474
  this.props.editor || this.props.onChange(change), this.change$.next(change);
6168
6475
  } }),
6169
- /* @__PURE__ */ jsx(Synchronizer, { editorActor: this.editor._internal.editorActor, getValue: this.editor._internal.editable.getValue, portableTextEditor: this, slateEditor: this.editor._internal.slateEditor.instance }),
6476
+ /* @__PURE__ */ jsx(Synchronizer, { editorActor: this.editor._internal.editorActor, slateEditor: this.editor._internal.slateEditor.instance }),
6170
6477
  /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsx(Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
6171
6478
  ] });
6172
6479
  }
@@ -6351,7 +6658,8 @@ function RouteEventsToChanges(props) {
6351
6658
  case "list item.toggle":
6352
6659
  case "style.toggle":
6353
6660
  case "patches":
6354
- case "readOnly toggled":
6661
+ case "editable":
6662
+ case "read only":
6355
6663
  break bb5;
6356
6664
  default:
6357
6665
  handleChange(event);
@@ -6761,10 +7069,16 @@ function _insertFragment(editor, fragment, schemaTypes) {
6761
7069
  })) : editor.insertFragment(fragment);
6762
7070
  }), editor.onChange();
6763
7071
  }
6764
- function withSyncRangeDecorations(slateEditor, syncRangeDecorations) {
7072
+ function withSyncRangeDecorations({
7073
+ editorActor,
7074
+ slateEditor,
7075
+ syncRangeDecorations
7076
+ }) {
6765
7077
  const originalApply = slateEditor.apply;
6766
7078
  return slateEditor.apply = (op) => {
6767
- originalApply(op), op.type !== "set_selection" && syncRangeDecorations(op);
7079
+ originalApply(op), !editorActor.getSnapshot().matches({
7080
+ "edit mode": "read only"
7081
+ }) && op.type !== "set_selection" && syncRangeDecorations(op);
6768
7082
  }, () => {
6769
7083
  slateEditor.apply = originalApply;
6770
7084
  };
@@ -6832,7 +7146,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6832
7146
  "spellCheck"
6833
7147
  ]), portableTextEditor = usePortableTextEditor(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
6834
7148
  useImperativeHandle(forwardedRef, () => ref.current);
6835
- const rangeDecorationsRef = useRef(rangeDecorations), editorActor = useContext(EditorActorContext), readOnly = useSelector(editorActor, (s) => s.context.readOnly), schemaTypes = useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = useSlate(), blockTypeName = schemaTypes.block.name;
7149
+ const rangeDecorationsRef = useRef(rangeDecorations), editorActor = useContext(EditorActorContext), readOnly = useSelector(editorActor, (s) => s.matches({
7150
+ "edit mode": "read only"
7151
+ })), schemaTypes = useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = useSlate(), blockTypeName = schemaTypes.block.name;
6836
7152
  useMemo(() => {
6837
7153
  const withInsertData = createWithInsertData(editorActor, schemaTypes);
6838
7154
  if (readOnly)
@@ -6901,7 +7217,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6901
7217
  }, [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]);
6902
7218
  useEffect(() => {
6903
7219
  const onReady = editorActor.on("ready", () => {
6904
- restoreSelectionFromProps();
7220
+ syncRangeDecorations(), restoreSelectionFromProps();
6905
7221
  }), onInvalidValue = editorActor.on("invalid value", () => {
6906
7222
  setHasInvalidValue(!0);
6907
7223
  }), onValueChanged = editorActor.on("value changed", () => {
@@ -6910,7 +7226,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6910
7226
  return () => {
6911
7227
  onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
6912
7228
  };
6913
- }, [editorActor, restoreSelectionFromProps]), useEffect(() => {
7229
+ }, [editorActor, restoreSelectionFromProps, syncRangeDecorations]), useEffect(() => {
6914
7230
  propsSelection && !hasInvalidValue && restoreSelectionFromProps();
6915
7231
  }, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
6916
7232
  const [syncedRangeDecorations, setSyncedRangeDecorations] = useState(!1);
@@ -6919,9 +7235,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6919
7235
  }, [syncRangeDecorations, syncedRangeDecorations]), useEffect(() => {
6920
7236
  isEqual(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
6921
7237
  }, [rangeDecorations, syncRangeDecorations]), useEffect(() => {
6922
- const teardown = withSyncRangeDecorations(slateEditor, syncRangeDecorations);
7238
+ const teardown = withSyncRangeDecorations({
7239
+ editorActor,
7240
+ slateEditor,
7241
+ syncRangeDecorations
7242
+ });
6923
7243
  return () => teardown();
6924
- }, [slateEditor, syncRangeDecorations]);
7244
+ }, [editorActor, slateEditor, syncRangeDecorations]);
6925
7245
  const handleCopy = useCallback((event) => {
6926
7246
  onCopy ? onCopy(event) !== void 0 && event.preventDefault() : event.nativeEvent.clipboardData && editorActor.send({
6927
7247
  type: "behavior event",
@@ -7110,7 +7430,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7110
7430
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
7111
7431
  const EditorContext = React.createContext(void 0);
7112
7432
  function EditorProvider(props) {
7113
- const $ = c(30), editor = useCreateEditor(props.initialConfig), editorActor = editor._internal.editorActor, slateEditor = editor._internal.slateEditor, editable = editor._internal.editable;
7433
+ const $ = c(28), editor = useCreateEditor(props.initialConfig), editorActor = editor._internal.editorActor, slateEditor = editor._internal.slateEditor;
7114
7434
  let t0, t1;
7115
7435
  $[0] !== editor ? (t1 = new PortableTextEditor({
7116
7436
  editor
@@ -7123,21 +7443,21 @@ function EditorProvider(props) {
7123
7443
  let t3;
7124
7444
  $[4] !== editorActor || $[5] !== t2 ? (t3 = /* @__PURE__ */ jsx(RouteEventsToChanges, { editorActor, onChange: t2 }), $[4] = editorActor, $[5] = t2, $[6] = t3) : t3 = $[6];
7125
7445
  let t4;
7126
- $[7] !== editable.getValue || $[8] !== editorActor || $[9] !== portableTextEditor || $[10] !== slateEditor.instance ? (t4 = /* @__PURE__ */ jsx(Synchronizer, { editorActor, getValue: editable.getValue, portableTextEditor, slateEditor: slateEditor.instance }), $[7] = editable.getValue, $[8] = editorActor, $[9] = portableTextEditor, $[10] = slateEditor.instance, $[11] = t4) : t4 = $[11];
7446
+ $[7] !== editorActor || $[8] !== slateEditor.instance ? (t4 = /* @__PURE__ */ jsx(Synchronizer, { editorActor, slateEditor: slateEditor.instance }), $[7] = editorActor, $[8] = slateEditor.instance, $[9] = t4) : t4 = $[9];
7127
7447
  let t5;
7128
- $[12] !== editorActor || $[13] !== props.children ? (t5 = /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor, children: props.children }), $[12] = editorActor, $[13] = props.children, $[14] = t5) : t5 = $[14];
7448
+ $[10] !== editorActor || $[11] !== props.children ? (t5 = /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor, children: props.children }), $[10] = editorActor, $[11] = props.children, $[12] = t5) : t5 = $[12];
7129
7449
  let t6;
7130
- $[15] !== portableTextEditor || $[16] !== t5 ? (t6 = /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: portableTextEditor, children: t5 }), $[15] = portableTextEditor, $[16] = t5, $[17] = t6) : t6 = $[17];
7450
+ $[13] !== portableTextEditor || $[14] !== t5 ? (t6 = /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: portableTextEditor, children: t5 }), $[13] = portableTextEditor, $[14] = t5, $[15] = t6) : t6 = $[15];
7131
7451
  let t7;
7132
- $[18] !== slateEditor.initialValue || $[19] !== slateEditor.instance || $[20] !== t6 ? (t7 = /* @__PURE__ */ jsx(Slate, { editor: slateEditor.instance, initialValue: slateEditor.initialValue, children: t6 }), $[18] = slateEditor.initialValue, $[19] = slateEditor.instance, $[20] = t6, $[21] = t7) : t7 = $[21];
7452
+ $[16] !== slateEditor.initialValue || $[17] !== slateEditor.instance || $[18] !== t6 ? (t7 = /* @__PURE__ */ jsx(Slate, { editor: slateEditor.instance, initialValue: slateEditor.initialValue, children: t6 }), $[16] = slateEditor.initialValue, $[17] = slateEditor.instance, $[18] = t6, $[19] = t7) : t7 = $[19];
7133
7453
  let t8;
7134
- $[22] !== editorActor || $[23] !== t7 ? (t8 = /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: editorActor, children: t7 }), $[22] = editorActor, $[23] = t7, $[24] = t8) : t8 = $[24];
7454
+ $[20] !== editorActor || $[21] !== t7 ? (t8 = /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: editorActor, children: t7 }), $[20] = editorActor, $[21] = t7, $[22] = t8) : t8 = $[22];
7135
7455
  let t9;
7136
- return $[25] !== editor || $[26] !== t3 || $[27] !== t4 || $[28] !== t8 ? (t9 = /* @__PURE__ */ jsxs(EditorContext.Provider, { value: editor, children: [
7456
+ return $[23] !== editor || $[24] !== t3 || $[25] !== t4 || $[26] !== t8 ? (t9 = /* @__PURE__ */ jsxs(EditorContext.Provider, { value: editor, children: [
7137
7457
  t3,
7138
7458
  t4,
7139
7459
  t8
7140
- ] }), $[25] = editor, $[26] = t3, $[27] = t4, $[28] = t8, $[29] = t9) : t9 = $[29], t9;
7460
+ ] }), $[23] = editor, $[24] = t3, $[25] = t4, $[26] = t8, $[27] = t9) : t9 = $[27], t9;
7141
7461
  }
7142
7462
  function useEditor() {
7143
7463
  const editor = React.useContext(EditorContext);
@@ -7166,6 +7486,10 @@ function useEditorSelector(editor, selector, t0) {
7166
7486
  let t1;
7167
7487
  return $[0] !== editor || $[1] !== selector ? (t1 = (snapshot) => {
7168
7488
  const context = {
7489
+ activeDecorators: getActiveDecorators({
7490
+ schema: snapshot.context.schema,
7491
+ slateEditorInstance: editor._internal.slateEditor.instance
7492
+ }),
7169
7493
  keyGenerator: snapshot.context.keyGenerator,
7170
7494
  schema: snapshot.context.schema,
7171
7495
  selection: snapshot.context.selection,