@portabletext/editor 1.15.3 → 1.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +25 -25
  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 +7 -7
  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 +23 -23
  14. package/lib/behaviors/index.cjs.map +1 -1
  15. package/lib/behaviors/index.d.cts +1 -0
  16. package/lib/behaviors/index.d.ts +1 -0
  17. package/lib/behaviors/index.js +8 -8
  18. package/lib/behaviors/index.js.map +1 -1
  19. package/lib/index.cjs +863 -516
  20. package/lib/index.cjs.map +1 -1
  21. package/lib/index.d.cts +3816 -4457
  22. package/lib/index.d.ts +3816 -4457
  23. package/lib/index.js +860 -515
  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 +54 -5
  28. package/lib/selectors/index.d.ts +54 -5
  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/behaviors/behavior.code-editor.ts +5 -9
  33. package/src/behaviors/behavior.core.block-objects.ts +13 -19
  34. package/src/behaviors/behavior.core.lists.ts +11 -17
  35. package/src/behaviors/behavior.links.ts +4 -4
  36. package/src/behaviors/behavior.markdown.ts +16 -21
  37. package/src/editor/Editable.tsx +11 -4
  38. package/src/editor/PortableTextEditor.tsx +4 -4
  39. package/src/editor/{hooks/useSyncValue.test.tsx → __tests__/sync-value.test.tsx} +42 -23
  40. package/src/editor/components/Synchronizer.tsx +53 -80
  41. package/src/editor/create-editor.ts +4 -1
  42. package/src/editor/editor-machine.ts +135 -83
  43. package/src/editor/editor-provider.tsx +0 -3
  44. package/src/editor/editor-selector.ts +5 -0
  45. package/src/editor/editor-snapshot.ts +1 -0
  46. package/src/editor/get-active-decorators.ts +20 -0
  47. package/src/editor/mutation-machine.ts +100 -0
  48. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +21 -15
  49. package/src/editor/plugins/createWithMaxBlocks.ts +1 -1
  50. package/src/editor/plugins/createWithPatches.ts +0 -4
  51. package/src/editor/plugins/createWithPlaceholderBlock.ts +1 -1
  52. package/src/editor/plugins/createWithPortableTextSelections.ts +4 -1
  53. package/src/editor/plugins/createWithUndoRedo.ts +3 -3
  54. package/src/editor/sync-machine.ts +661 -0
  55. package/src/editor/withSyncRangeDecorations.ts +17 -5
  56. package/src/selectors/_exports/index.ts +1 -0
  57. package/src/selectors/index.ts +9 -1
  58. package/src/selectors/selector.get-active-style.ts +37 -0
  59. package/src/selectors/selector.get-selected-spans.ts +136 -0
  60. package/src/selectors/selector.is-active-annotation.ts +49 -0
  61. package/src/selectors/selector.is-active-decorator.ts +21 -0
  62. package/src/selectors/selector.is-active-list-item.ts +13 -0
  63. package/src/selectors/selector.is-active-style.ts +13 -0
  64. package/src/selectors/selector.is-selection-collapsed.ts +12 -0
  65. package/src/selectors/selector.is-selection-expanded.ts +9 -0
  66. package/src/selectors/selectors.ts +0 -11
  67. package/src/utils/weakMaps.ts +0 -3
  68. package/src/utils/withChanges.ts +1 -8
  69. package/lib/_chunks-cjs/selectors.cjs.map +0 -1
  70. package/lib/_chunks-es/selectors.js.map +0 -1
  71. 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,16 +25,14 @@ 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";
@@ -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) {
@@ -167,10 +165,10 @@ function compileSchemaDefinition(definition) {
167
165
  }), schema = Schema.compile({
168
166
  types: [portableTextSchema, ...blockObjects, ...inlineObjects]
169
167
  }).get("portable-text"), pteSchema = createEditorSchema(schema);
170
- return __spreadProps$j(__spreadValues$p({}, pteSchema), {
171
- blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$p({}, blockObject), {
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
+ event
2306
+ }) => (assertEvent(event, "update readOnly"), event.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
+ "update 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,105 @@ 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(40), {
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));
2455
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);
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, t12;
2721
+ $[25] !== readOnly || $[26] !== syncActorRef ? (t11 = () => {
2722
+ syncActorRef.send({
2723
+ type: "update readOnly",
2724
+ readOnly
2725
+ });
2726
+ }, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), useEffect(t11, t12);
2727
+ let t13, t14;
2728
+ $[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
2729
+ debug$h("Value from props changed, syncing new value"), syncActorRef.send({
2730
+ type: "update value",
2731
+ value
2732
+ });
2733
+ }, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), useEffect(t13, t14);
2734
+ let t15;
2735
+ $[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
2456
2736
  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();
2737
+ const sub = editorActor.on("patch", (event_1) => {
2738
+ mutationActorRef.send(event_1);
2459
2739
  });
2460
2740
  return () => {
2461
2741
  debug$h("Unsubscribing to patch events"), sub.unsubscribe();
2462
2742
  };
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;
2743
+ }, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
2744
+ let t16;
2745
+ return $[36] !== editorActor || $[37] !== mutationActorRef || $[38] !== slateEditor ? (t16 = [editorActor, mutationActorRef, slateEditor], $[36] = editorActor, $[37] = mutationActorRef, $[38] = slateEditor, $[39] = t16) : t16 = $[39], useEffect(t15, t16), null;
2471
2746
  }
2472
2747
  function _temp2(s_0) {
2473
- return s_0.context.value;
2748
+ return s_0.matches({
2749
+ "edit mode": "read only"
2750
+ });
2474
2751
  }
2475
2752
  function _temp(s) {
2476
- return s.context.readOnly;
2753
+ return s.context.value;
2477
2754
  }
2478
2755
  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) => {
2756
+ 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
2757
  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]);
2758
+ __hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
2759
+ if (__getOwnPropSymbols$l)
2760
+ for (var prop of __getOwnPropSymbols$l(b))
2761
+ __propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
2485
2762
  return a;
2486
2763
  }, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
2487
2764
  const debug$g = debugWithName("operationToPatches");
@@ -2523,7 +2800,7 @@ function createOperationToPatches(types) {
2523
2800
  const block = editor.children[operation.path[0]];
2524
2801
  if (typeof block._key != "string")
2525
2802
  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);
2803
+ const setNode = omitBy(__spreadValues$l(__spreadValues$l({}, editor.children[operation.path[0]]), operation.newProperties), isUndefined);
2527
2804
  return [set(fromSlateValue([setNode], textBlockName)[0], [{
2528
2805
  _key: block._key
2529
2806
  }])];
@@ -2563,7 +2840,7 @@ function createOperationToPatches(types) {
2563
2840
  _key: targetKey
2564
2841
  }])] : [setIfMissing(beforeValue, []), insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
2565
2842
  } 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);
2843
+ const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = __spreadValues$l({}, operation.node);
2567
2844
  !node._type && Text.isText(node) && (node._type = "span", node.marks = []);
2568
2845
  const child = fromSlateValue([{
2569
2846
  _key: "bogus",
@@ -2602,7 +2879,7 @@ function createOperationToPatches(types) {
2602
2879
  if (operation.path.length === 2) {
2603
2880
  const splitSpan = splitBlock.children[operation.path[1]];
2604
2881
  if (editor.isTextSpan(splitSpan)) {
2605
- const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$k({}, splitBlock), {
2882
+ const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$l({}, splitBlock), {
2606
2883
  children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
2607
2884
  })], textBlockName)[0].children;
2608
2885
  patches.push(insert(targetSpans, "after", [{
@@ -2913,7 +3190,9 @@ function createWithMaxBlocks(editorActor) {
2913
3190
  } = editor;
2914
3191
  return editor.apply = (operation) => {
2915
3192
  var _a;
2916
- if (editorActor.getSnapshot().context.readOnly) {
3193
+ if (editorActor.getSnapshot().matches({
3194
+ "edit mode": "read only"
3195
+ })) {
2917
3196
  apply2(operation);
2918
3197
  return;
2919
3198
  }
@@ -2930,12 +3209,12 @@ function createWithMaxBlocks(editorActor) {
2930
3209
  }, editor;
2931
3210
  };
2932
3211
  }
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) => {
3212
+ 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
3213
  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]);
3214
+ __hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
3215
+ if (__getOwnPropSymbols$k)
3216
+ for (var prop of __getOwnPropSymbols$k(b))
3217
+ __propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
2939
3218
  return a;
2940
3219
  }, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
2941
3220
  function createWithObjectKeys(editorActor, schemaTypes) {
@@ -2954,16 +3233,16 @@ function createWithObjectKeys(editorActor, schemaTypes) {
2954
3233
  return;
2955
3234
  }
2956
3235
  if (operation.type === "split_node") {
2957
- apply2(__spreadProps$e(__spreadValues$j({}, operation), {
2958
- properties: __spreadProps$e(__spreadValues$j({}, operation.properties), {
3236
+ apply2(__spreadProps$e(__spreadValues$k({}, operation), {
3237
+ properties: __spreadProps$e(__spreadValues$k({}, operation.properties), {
2959
3238
  _key: editorActor.getSnapshot().context.keyGenerator()
2960
3239
  })
2961
3240
  }));
2962
3241
  return;
2963
3242
  }
2964
3243
  if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
2965
- apply2(__spreadProps$e(__spreadValues$j({}, operation), {
2966
- node: __spreadProps$e(__spreadValues$j({}, operation.node), {
3244
+ apply2(__spreadProps$e(__spreadValues$k({}, operation), {
3245
+ node: __spreadProps$e(__spreadValues$k({}, operation.node), {
2967
3246
  _key: editorActor.getSnapshot().context.keyGenerator()
2968
3247
  })
2969
3248
  }));
@@ -3003,20 +3282,20 @@ function createWithObjectKeys(editorActor, schemaTypes) {
3003
3282
  }, editor;
3004
3283
  };
3005
3284
  }
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) => {
3285
+ 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
3286
  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]);
3287
+ __hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
3288
+ if (__getOwnPropSymbols$j)
3289
+ for (var prop of __getOwnPropSymbols$j(b))
3290
+ __propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
3012
3291
  return a;
3013
3292
  }, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
3014
3293
  var target = {};
3015
3294
  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]);
3295
+ __hasOwnProp$j.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
3296
+ if (source != null && __getOwnPropSymbols$j)
3297
+ for (var prop of __getOwnPropSymbols$j(source))
3298
+ exclude.indexOf(prop) < 0 && __propIsEnum$j.call(source, prop) && (target[prop] = source[prop]);
3020
3299
  return target;
3021
3300
  };
3022
3301
  const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
@@ -3108,7 +3387,7 @@ function insertPatch(editor, patch, schemaTypes) {
3108
3387
  } = patch;
3109
3388
  if (!targetChild || !targetChildPath)
3110
3389
  return debug$f("Child not found"), !1;
3111
- const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$i({}, targetBlock), {
3390
+ const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$j({}, targetBlock), {
3112
3391
  children: items
3113
3392
  })], {
3114
3393
  schemaTypes
@@ -3167,7 +3446,7 @@ function setPatch(editor, patch) {
3167
3446
  editor.apply({
3168
3447
  type: "set_node",
3169
3448
  path: blockPath,
3170
- properties: __spreadValues$i({}, prevRest),
3449
+ properties: __spreadValues$j({}, prevRest),
3171
3450
  newProperties: nextRest
3172
3451
  }), debug$f("Setting children"), block.children.forEach((c2, cIndex) => {
3173
3452
  editor.apply({
@@ -3184,7 +3463,7 @@ function setPatch(editor, patch) {
3184
3463
  });
3185
3464
  } else if (block && "value" in block) {
3186
3465
  const newVal = applyAll([block.value], [patch])[0];
3187
- return Transforms.setNodes(editor, __spreadProps$d(__spreadValues$i({}, block), {
3466
+ return Transforms.setNodes(editor, __spreadProps$d(__spreadValues$j({}, block), {
3188
3467
  value: newVal
3189
3468
  }), {
3190
3469
  at: blockPath
@@ -3277,12 +3556,12 @@ function findBlockAndChildFromPath(editor, path) {
3277
3556
  childPath: void 0
3278
3557
  };
3279
3558
  }
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) => {
3559
+ 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
3560
  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]);
3561
+ __hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
3562
+ if (__getOwnPropSymbols$i)
3563
+ for (var prop of __getOwnPropSymbols$i(b))
3564
+ __propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
3286
3565
  return a;
3287
3566
  }, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
3288
3567
  const debug$e = debugWithName("plugin:withPatches");
@@ -3330,8 +3609,6 @@ function createWithPatches({
3330
3609
  debug$e("Unsubscribing to remote patches"), sub.unsubscribe();
3331
3610
  };
3332
3611
  }), editor.apply = (operation) => {
3333
- if (editorActor.getSnapshot().context.readOnly)
3334
- return apply2(operation), editor;
3335
3612
  let patches = [];
3336
3613
  previousChildren = editor.children;
3337
3614
  const editorWasEmpty = isEqualToEmptyEditor(previousChildren, schemaTypes);
@@ -3371,7 +3648,7 @@ function createWithPatches({
3371
3648
  })), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0 && patches.forEach((patch) => {
3372
3649
  editorActor.send({
3373
3650
  type: "patch",
3374
- patch: __spreadProps$c(__spreadValues$h({}, patch), {
3651
+ patch: __spreadProps$c(__spreadValues$i({}, patch), {
3375
3652
  origin: "local"
3376
3653
  })
3377
3654
  });
@@ -3386,7 +3663,9 @@ function createWithPlaceholderBlock(editorActor) {
3386
3663
  apply: apply2
3387
3664
  } = editor;
3388
3665
  return editor.apply = (op) => {
3389
- if (editorActor.getSnapshot().context.readOnly) {
3666
+ if (editorActor.getSnapshot().matches({
3667
+ "edit mode": "read only"
3668
+ })) {
3390
3669
  apply2(op);
3391
3670
  return;
3392
3671
  }
@@ -3484,12 +3763,12 @@ function getNextSpan({
3484
3763
  }
3485
3764
  return nextSpan;
3486
3765
  }
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) => {
3766
+ 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
3767
  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]);
3768
+ __hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
3769
+ if (__getOwnPropSymbols$h)
3770
+ for (var prop of __getOwnPropSymbols$h(b))
3771
+ __propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
3493
3772
  return a;
3494
3773
  }, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
3495
3774
  const debug$b = debugWithName("plugin:withPortableTextMarkModel");
@@ -3691,21 +3970,21 @@ function createWithPortableTextMarkModel(editorActor, types) {
3691
3970
  spanPath: [op.path[0], op.path[1] - 1]
3692
3971
  }), 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
3972
  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), {
3973
+ Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
3695
3974
  marks: (_h = (_g = op.node.marks) == null ? void 0 : _g.filter((mark) => !annotationsEnding.includes(mark))) != null ? _h : []
3696
3975
  }));
3697
3976
  return;
3698
3977
  }
3699
3978
  const annotationsStarting = (_i = nextSpanAnnotations == null ? void 0 : nextSpanAnnotations.filter((annotation) => !(previousSpanAnnotations != null && previousSpanAnnotations.includes(annotation)))) != null ? _i : [], atTheStartOfAnnotation = annotationsStarting.length > 0;
3700
3979
  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), {
3980
+ Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
3702
3981
  marks: (_l = (_k = op.node.marks) == null ? void 0 : _k.filter((mark) => !annotationsStarting.includes(mark))) != null ? _l : []
3703
3982
  }));
3704
3983
  return;
3705
3984
  }
3706
3985
  const nextSpanDecorators = (_n = (_m = nextSpan == null ? void 0 : nextSpan.marks) == null ? void 0 : _m.filter((mark) => decorators.includes(mark))) != null ? _n : [];
3707
3986
  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), {
3987
+ Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
3709
3988
  marks: nextSpanDecorators
3710
3989
  }));
3711
3990
  return;
@@ -3823,7 +4102,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
3823
4102
  spanPath
3824
4103
  }), 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
4104
  if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
3826
- const marksWithoutAnnotationMarks = (__spreadValues$g({}, Editor.marks(editor) || {}).marks || []).filter((mark) => decorators.includes(mark));
4105
+ const marksWithoutAnnotationMarks = (__spreadValues$h({}, Editor.marks(editor) || {}).marks || []).filter((mark) => decorators.includes(mark));
3827
4106
  Editor.withoutNormalizing(editor, () => {
3828
4107
  apply2(op), Transforms.setNodes(editor, {
3829
4108
  marks: marksWithoutAnnotationMarks
@@ -3896,7 +4175,7 @@ const addDecoratorActionImplementation = ({
3896
4175
  match: (node) => editor.isTextSpan(node)
3897
4176
  });
3898
4177
  } else {
3899
- const existingMarks = __spreadValues$g({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, Editor.marks(editor) || {}), {
4178
+ const existingMarks = __spreadValues$h({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$h({}, Editor.marks(editor) || {}), {
3900
4179
  marks: [...existingMarks, mark]
3901
4180
  });
3902
4181
  editor.marks = marks;
@@ -3942,7 +4221,7 @@ const addDecoratorActionImplementation = ({
3942
4221
  match: (node) => editor.isTextSpan(node)
3943
4222
  });
3944
4223
  } else {
3945
- const existingMarks = __spreadValues$g({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, Editor.marks(editor) || {}), {
4224
+ const existingMarks = __spreadValues$h({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$h({}, Editor.marks(editor) || {}), {
3946
4225
  marks: existingMarks.filter((eMark) => eMark !== mark)
3947
4226
  });
3948
4227
  editor.marks = {
@@ -3966,7 +4245,7 @@ function isDecoratorActive({
3966
4245
  var _a;
3967
4246
  const [node] = n;
3968
4247
  return (_a = node.marks) == null ? void 0 : _a.includes(decorator);
3969
- }) : (__spreadValues$g({}, Editor.marks(editor) || {}).marks || []).includes(decorator);
4248
+ }) : (__spreadValues$h({}, Editor.marks(editor) || {}).marks || []).includes(decorator);
3970
4249
  }
3971
4250
  const toggleDecoratorActionImplementation = ({
3972
4251
  context,
@@ -4020,16 +4299,18 @@ function createWithPortableTextSelections(editorActor, types) {
4020
4299
  } = editor;
4021
4300
  return editor.onChange = () => {
4022
4301
  const hasChanges = editor.operations.length > 0;
4023
- onChange(), hasChanges && emitPortableTextSelection();
4302
+ onChange(), hasChanges && !editorActor.getSnapshot().matches({
4303
+ setup: "setting up"
4304
+ }) && emitPortableTextSelection();
4024
4305
  }, editor;
4025
4306
  };
4026
4307
  }
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) => {
4308
+ 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
4309
  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]);
4310
+ __hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
4311
+ if (__getOwnPropSymbols$g)
4312
+ for (var prop of __getOwnPropSymbols$g(b))
4313
+ __propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
4033
4314
  return a;
4034
4315
  }, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
4035
4316
  const debug$9 = debugWithName("plugin:withSchemaTypes");
@@ -4049,7 +4330,7 @@ function createWithSchemaTypes({
4049
4330
  const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
4050
4331
  editorActor.send({
4051
4332
  type: "normalizing"
4052
- }), Transforms.setNodes(editor, __spreadProps$a(__spreadValues$f({}, span), {
4333
+ }), Transforms.setNodes(editor, __spreadProps$a(__spreadValues$g({}, span), {
4053
4334
  _type: schemaTypes.span.name,
4054
4335
  _key: key
4055
4336
  }), {
@@ -4077,12 +4358,12 @@ function createWithSchemaTypes({
4077
4358
  }, editor;
4078
4359
  };
4079
4360
  }
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) => {
4361
+ 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
4362
  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]);
4363
+ __hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
4364
+ if (__getOwnPropSymbols$f)
4365
+ for (var prop of __getOwnPropSymbols$f(b))
4366
+ __propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
4086
4367
  return a;
4087
4368
  }, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
4088
4369
  const debug$8 = debugWithName("plugin:withUtils");
@@ -4108,10 +4389,10 @@ function createWithUtils({
4108
4389
  } = 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
4390
  if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
4110
4391
  debug$8("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
4111
- anchor: __spreadProps$9(__spreadValues$e({}, selection.anchor), {
4392
+ anchor: __spreadProps$9(__spreadValues$f({}, selection.anchor), {
4112
4393
  offset: newStartOffset
4113
4394
  }),
4114
- focus: __spreadProps$9(__spreadValues$e({}, selection.focus), {
4395
+ focus: __spreadProps$9(__spreadValues$f({}, selection.focus), {
4115
4396
  offset: newEndOffset
4116
4397
  })
4117
4398
  });
@@ -4119,7 +4400,7 @@ function createWithUtils({
4119
4400
  }
4120
4401
  debug$8("pteExpandToWord: Can't expand to word here");
4121
4402
  }
4122
- }, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$e(__spreadValues$e({
4403
+ }, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$f(__spreadValues$f({
4123
4404
  _type: schemaTypes.block.name,
4124
4405
  _key: editorActor.getSnapshot().context.keyGenerator(),
4125
4406
  style: schemaTypes.styles[0].value || "normal"
@@ -4183,12 +4464,12 @@ function createSlateEditor(config) {
4183
4464
  };
4184
4465
  return slateEditors.set(config.editorActor, slateEditor), slateEditor;
4185
4466
  }
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) => {
4467
+ 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
4468
  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]);
4469
+ __hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
4470
+ if (__getOwnPropSymbols$e)
4471
+ for (var prop of __getOwnPropSymbols$e(b))
4472
+ __propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
4192
4473
  return a;
4193
4474
  }, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
4194
4475
  const toggleListItemActionImplementation = ({
@@ -4200,12 +4481,12 @@ const toggleListItemActionImplementation = ({
4200
4481
  listItem: action.listItem
4201
4482
  }) ? removeListItemActionImplementation({
4202
4483
  context,
4203
- action: __spreadProps$8(__spreadValues$d({}, action), {
4484
+ action: __spreadProps$8(__spreadValues$e({}, action), {
4204
4485
  type: "list item.remove"
4205
4486
  })
4206
4487
  }) : addListItemActionImplementation({
4207
4488
  context,
4208
- action: __spreadProps$8(__spreadValues$d({}, action), {
4489
+ action: __spreadProps$8(__spreadValues$e({}, action), {
4209
4490
  type: "list item.add"
4210
4491
  })
4211
4492
  });
@@ -4253,12 +4534,12 @@ function isListItemActive({
4253
4534
  })];
4254
4535
  return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
4255
4536
  }
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) => {
4537
+ 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
4538
  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]);
4539
+ __hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
4540
+ if (__getOwnPropSymbols$d)
4541
+ for (var prop of __getOwnPropSymbols$d(b))
4542
+ __propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
4262
4543
  return a;
4263
4544
  }, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
4264
4545
  const toggleStyleActionImplementation = ({
@@ -4270,12 +4551,12 @@ const toggleStyleActionImplementation = ({
4270
4551
  style: action.style
4271
4552
  }) ? removeStyleActionImplementation({
4272
4553
  context,
4273
- action: __spreadProps$7(__spreadValues$c({}, action), {
4554
+ action: __spreadProps$7(__spreadValues$d({}, action), {
4274
4555
  type: "style.remove"
4275
4556
  })
4276
4557
  }) : addStyleActionImplementation({
4277
4558
  context,
4278
- action: __spreadProps$7(__spreadValues$c({}, action), {
4559
+ action: __spreadProps$7(__spreadValues$d({}, action), {
4279
4560
  type: "style.add"
4280
4561
  })
4281
4562
  });
@@ -4324,12 +4605,12 @@ function isStyleActive({
4324
4605
  })];
4325
4606
  return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
4326
4607
  }
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) => {
4608
+ 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
4609
  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]);
4610
+ __hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
4611
+ if (__getOwnPropSymbols$c)
4612
+ for (var prop of __getOwnPropSymbols$c(b))
4613
+ __propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
4333
4614
  return a;
4334
4615
  };
4335
4616
  const debug$6 = debugWithName("API:editable");
@@ -4394,7 +4675,7 @@ function createEditableAPI(editor, editorActor) {
4394
4675
  return console.warn(err), !1;
4395
4676
  }
4396
4677
  },
4397
- marks: () => __spreadValues$b({}, Editor.marks(editor) || {}).marks || [],
4678
+ marks: () => __spreadValues$c({}, Editor.marks(editor) || {}).marks || [],
4398
4679
  undo: () => editor.undo(),
4399
4680
  redo: () => editor.redo(),
4400
4681
  select: (selection) => {
@@ -4442,7 +4723,7 @@ function createEditableAPI(editor, editorActor) {
4442
4723
  const child = toSlateValue([{
4443
4724
  _key: editorActor.getSnapshot().context.keyGenerator(),
4444
4725
  _type: types.block.name,
4445
- children: [__spreadValues$b({
4726
+ children: [__spreadValues$c({
4446
4727
  _key: editorActor.getSnapshot().context.keyGenerator(),
4447
4728
  _type: type.name
4448
4729
  }, value || {})]
@@ -4706,7 +4987,7 @@ const addAnnotationActionImplementation = ({
4706
4987
  continue;
4707
4988
  const annotationKey = context.keyGenerator(), markDefs = (_a = block.markDefs) != null ? _a : [];
4708
4989
  markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
4709
- markDefs: [...markDefs, __spreadValues$b({
4990
+ markDefs: [...markDefs, __spreadValues$c({
4710
4991
  _type: action.annotation.name,
4711
4992
  _key: annotationKey
4712
4993
  }, action.annotation.value)]
@@ -4883,19 +5164,19 @@ function insertBlock({
4883
5164
  });
4884
5165
  }
4885
5166
  }
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) => {
5167
+ 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
5168
  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]);
5169
+ __hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
5170
+ if (__getOwnPropSymbols$b)
5171
+ for (var prop of __getOwnPropSymbols$b(b))
5172
+ __propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
4892
5173
  return a;
4893
5174
  };
4894
5175
  const insertBlockObjectActionImplementation = ({
4895
5176
  context,
4896
5177
  action
4897
5178
  }) => {
4898
- const block = toSlateValue([__spreadValues$a({
5179
+ const block = toSlateValue([__spreadValues$b({
4899
5180
  _key: context.keyGenerator(),
4900
5181
  _type: action.blockObject.name
4901
5182
  }, action.blockObject.value ? action.blockObject.value : {})], {
@@ -4908,12 +5189,12 @@ const insertBlockObjectActionImplementation = ({
4908
5189
  schema: context.schema
4909
5190
  });
4910
5191
  };
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) => {
5192
+ 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
5193
  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]);
5194
+ __hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
5195
+ if (__getOwnPropSymbols$a)
5196
+ for (var prop of __getOwnPropSymbols$a(b))
5197
+ __propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
4917
5198
  return a;
4918
5199
  }, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
4919
5200
  const insertBreakActionImplementation = ({
@@ -5009,7 +5290,7 @@ const insertBreakActionImplementation = ({
5009
5290
  }
5010
5291
  const newMarkDefs = nextNode.markDefs.map((markDef) => {
5011
5292
  var _a3;
5012
- return __spreadProps$6(__spreadValues$9({}, markDef), {
5293
+ return __spreadProps$6(__spreadValues$a({}, markDef), {
5013
5294
  _key: (_a3 = newMarkDefKeys.get(markDef._key)) != null ? _a3 : markDef._key
5014
5295
  });
5015
5296
  });
@@ -5033,17 +5314,17 @@ const insertBreakActionImplementation = ({
5033
5314
  }) => {
5034
5315
  insertBreakActionImplementation({
5035
5316
  context,
5036
- action: __spreadProps$6(__spreadValues$9({}, action), {
5317
+ action: __spreadProps$6(__spreadValues$a({}, action), {
5037
5318
  type: "insert.break"
5038
5319
  })
5039
5320
  });
5040
5321
  };
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) => {
5322
+ 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
5323
  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]);
5324
+ __hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
5325
+ if (__getOwnPropSymbols$9)
5326
+ for (var prop of __getOwnPropSymbols$9(b))
5327
+ __propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
5047
5328
  return a;
5048
5329
  };
5049
5330
  const insertInlineObjectActionImplementation = ({
@@ -5070,7 +5351,7 @@ const insertInlineObjectActionImplementation = ({
5070
5351
  const block = toSlateValue([{
5071
5352
  _type: context.schema.block.name,
5072
5353
  _key: context.keyGenerator(),
5073
- children: [__spreadValues$8({
5354
+ children: [__spreadValues$9({
5074
5355
  _type: action.inlineObject.name,
5075
5356
  _key: context.keyGenerator()
5076
5357
  }, (_b = action.inlineObject.value) != null ? _b : {})]
@@ -5083,12 +5364,12 @@ const insertInlineObjectActionImplementation = ({
5083
5364
  }
5084
5365
  Transforms.insertNodes(action.editor, child);
5085
5366
  };
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) => {
5367
+ 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
5368
  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]);
5369
+ __hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
5370
+ if (__getOwnPropSymbols$8)
5371
+ for (var prop of __getOwnPropSymbols$8(b))
5372
+ __propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
5092
5373
  return a;
5093
5374
  };
5094
5375
  const insertSpanActionImplementation = ({
@@ -5108,7 +5389,7 @@ const insertSpanActionImplementation = ({
5108
5389
  console.error("Unable to perform action without focus block", action);
5109
5390
  return;
5110
5391
  }
5111
- const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$7({
5392
+ const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$8({
5112
5393
  _type: annotation.name,
5113
5394
  _key: context.keyGenerator()
5114
5395
  }, annotation.value)) : void 0;
@@ -5121,12 +5402,12 @@ const insertSpanActionImplementation = ({
5121
5402
  marks: [...(_c = annotations == null ? void 0 : annotations.map((annotation) => annotation._key)) != null ? _c : [], ...(_d = action.decorators) != null ? _d : []]
5122
5403
  });
5123
5404
  };
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) => {
5405
+ 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
5406
  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]);
5407
+ __hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
5408
+ if (__getOwnPropSymbols$7)
5409
+ for (var prop of __getOwnPropSymbols$7(b))
5410
+ __propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
5130
5411
  return a;
5131
5412
  };
5132
5413
  const textBlockSetActionImplementation = ({
@@ -5142,7 +5423,7 @@ const textBlockSetActionImplementation = ({
5142
5423
  offset: 0
5143
5424
  }
5144
5425
  }, action.editor);
5145
- Transforms.setNodes(action.editor, __spreadValues$6(__spreadValues$6(__spreadValues$6({}, action.style ? {
5426
+ Transforms.setNodes(action.editor, __spreadValues$7(__spreadValues$7(__spreadValues$7({}, action.style ? {
5146
5427
  style: action.style
5147
5428
  } : {}), action.listItem ? {
5148
5429
  listItem: action.listItem
@@ -5168,12 +5449,12 @@ const textBlockSetActionImplementation = ({
5168
5449
  at
5169
5450
  });
5170
5451
  };
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) => {
5452
+ 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
5453
  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]);
5454
+ __hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
5455
+ if (__getOwnPropSymbols$6)
5456
+ for (var prop of __getOwnPropSymbols$6(b))
5457
+ __propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
5177
5458
  return a;
5178
5459
  }, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
5179
5460
  const behaviorActionImplementations = {
@@ -5271,7 +5552,7 @@ const behaviorActionImplementations = {
5271
5552
  _type: context.schema.block.name,
5272
5553
  style: (_a = context.schema.styles[0].value) != null ? _a : "normal",
5273
5554
  markDefs: [],
5274
- children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$5({}, child), {
5555
+ children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$6({}, child), {
5275
5556
  _key: context.keyGenerator()
5276
5557
  }))) != null ? _d : [{
5277
5558
  _type: context.schema.span.name,
@@ -5366,7 +5647,7 @@ const behaviorActionImplementations = {
5366
5647
  action
5367
5648
  }) => {
5368
5649
  const selection = action.editor.selection;
5369
- selection && (Transforms.select(action.editor, __spreadValues$5({}, selection)), action.editor.selection = __spreadValues$5({}, selection));
5650
+ selection && (Transforms.select(action.editor, __spreadValues$6({}, selection)), action.editor.selection = __spreadValues$6({}, selection));
5370
5651
  },
5371
5652
  "style.toggle": toggleStyleActionImplementation,
5372
5653
  "style.add": addStyleActionImplementation,
@@ -5638,6 +5919,22 @@ function performDefaultAction({
5638
5919
  });
5639
5920
  }
5640
5921
  }
5922
+ 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) => {
5923
+ for (var prop in b || (b = {}))
5924
+ __hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
5925
+ if (__getOwnPropSymbols$5)
5926
+ for (var prop of __getOwnPropSymbols$5(b))
5927
+ __propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
5928
+ return a;
5929
+ };
5930
+ function getActiveDecorators({
5931
+ schema,
5932
+ slateEditorInstance
5933
+ }) {
5934
+ var _a, _b;
5935
+ const decorators = schema.decorators.map((decorator) => decorator.value);
5936
+ return ((_b = __spreadValues$5({}, (_a = Editor.marks(slateEditorInstance)) != null ? _a : {}).marks) != null ? _b : []).filter((mark) => decorators.includes(mark));
5937
+ }
5641
5938
  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
5939
  for (var prop in b || (b = {}))
5643
5940
  __hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
@@ -5670,6 +5967,12 @@ const editorMachine = setup({
5670
5967
  "emit mutation event": emit(({
5671
5968
  event
5672
5969
  }) => (assertEvent(event, "mutation"), event)),
5970
+ "emit read only": emit({
5971
+ type: "read only"
5972
+ }),
5973
+ "emit editable": emit({
5974
+ type: "editable"
5975
+ }),
5673
5976
  "defer event": assign({
5674
5977
  pendingEvents: ({
5675
5978
  context,
@@ -5683,6 +5986,9 @@ const editorMachine = setup({
5683
5986
  for (const event of context.pendingEvents)
5684
5987
  enqueue(emit(event));
5685
5988
  }),
5989
+ "emit ready": emit({
5990
+ type: "ready"
5991
+ }),
5686
5992
  "clear pending events": assign({
5687
5993
  pendingEvents: []
5688
5994
  }),
@@ -5707,6 +6013,10 @@ const editorMachine = setup({
5707
6013
  return;
5708
6014
  }
5709
6015
  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 = {
6016
+ activeDecorators: getActiveDecorators({
6017
+ schema: context.schema,
6018
+ slateEditorInstance: event.editor
6019
+ }),
5710
6020
  keyGenerator: context.keyGenerator,
5711
6021
  schema: context.schema,
5712
6022
  selection,
@@ -5758,89 +6068,12 @@ const editorMachine = setup({
5758
6068
  pendingEvents: [],
5759
6069
  schema: input.schema,
5760
6070
  selection: null,
5761
- readOnly: (_b = input.readOnly) != null ? _b : !1,
6071
+ initialReadOnly: (_b = input.readOnly) != null ? _b : !1,
5762
6072
  maxBlocks: input.maxBlocks,
5763
6073
  value: input.value
5764
6074
  };
5765
6075
  },
5766
6076
  on: {
5767
- "annotation.add": {
5768
- actions: emit(({
5769
- event
5770
- }) => event),
5771
- guard: ({
5772
- context
5773
- }) => !context.readOnly
5774
- },
5775
- "annotation.remove": {
5776
- actions: emit(({
5777
- event
5778
- }) => event),
5779
- guard: ({
5780
- context
5781
- }) => !context.readOnly
5782
- },
5783
- "annotation.toggle": {
5784
- actions: emit(({
5785
- event
5786
- }) => event),
5787
- guard: ({
5788
- context
5789
- }) => !context.readOnly
5790
- },
5791
- blur: {
5792
- actions: emit(({
5793
- event
5794
- }) => event),
5795
- guard: ({
5796
- context
5797
- }) => !context.readOnly
5798
- },
5799
- "decorator.*": {
5800
- actions: emit(({
5801
- event
5802
- }) => event),
5803
- guard: ({
5804
- context
5805
- }) => !context.readOnly
5806
- },
5807
- focus: {
5808
- actions: emit(({
5809
- event
5810
- }) => event),
5811
- guard: ({
5812
- context
5813
- }) => !context.readOnly
5814
- },
5815
- "insert.*": {
5816
- actions: emit(({
5817
- event
5818
- }) => event),
5819
- guard: ({
5820
- context
5821
- }) => !context.readOnly
5822
- },
5823
- "list item.*": {
5824
- actions: emit(({
5825
- event
5826
- }) => event),
5827
- guard: ({
5828
- context
5829
- }) => !context.readOnly
5830
- },
5831
- "style.*": {
5832
- actions: emit(({
5833
- event
5834
- }) => event),
5835
- guard: ({
5836
- context
5837
- }) => !context.readOnly
5838
- },
5839
- ready: {
5840
- actions: emit(({
5841
- event
5842
- }) => event)
5843
- },
5844
6077
  unset: {
5845
6078
  actions: emit(({
5846
6079
  event
@@ -5908,18 +6141,6 @@ const editorMachine = setup({
5908
6141
  }) => event.value
5909
6142
  })
5910
6143
  },
5911
- "toggle readOnly": {
5912
- actions: [assign({
5913
- readOnly: ({
5914
- context
5915
- }) => !context.readOnly
5916
- }), emit(({
5917
- context
5918
- }) => ({
5919
- type: "readOnly toggled",
5920
- readOnly: context.readOnly
5921
- }))]
5922
- },
5923
6144
  "update maxBlocks": {
5924
6145
  actions: assign({
5925
6146
  maxBlocks: ({
@@ -5927,12 +6148,6 @@ const editorMachine = setup({
5927
6148
  }) => event.maxBlocks
5928
6149
  })
5929
6150
  },
5930
- "behavior event": {
5931
- actions: "handle behavior event",
5932
- guard: ({
5933
- context
5934
- }) => !context.readOnly
5935
- },
5936
6151
  "behavior action intends": {
5937
6152
  actions: [({
5938
6153
  context,
@@ -5961,49 +6176,160 @@ const editorMachine = setup({
5961
6176
  })]
5962
6177
  }
5963
6178
  },
5964
- initial: "pristine",
6179
+ type: "parallel",
5965
6180
  states: {
5966
- pristine: {
5967
- initial: "idle",
6181
+ "edit mode": {
6182
+ initial: "read only",
5968
6183
  states: {
5969
- idle: {
5970
- on: {
5971
- normalizing: {
5972
- target: "normalizing"
5973
- },
5974
- patch: {
5975
- actions: "defer event",
5976
- target: "#editor.dirty"
6184
+ "read only": {
6185
+ initial: "determine initial edit mode",
6186
+ states: {
6187
+ "determine initial edit mode": {
6188
+ on: {
6189
+ "done syncing": [{
6190
+ target: "#editor.edit mode.read only.read only",
6191
+ guard: ({
6192
+ context
6193
+ }) => context.initialReadOnly
6194
+ }, {
6195
+ target: "#editor.edit mode.editable"
6196
+ }]
6197
+ }
5977
6198
  },
5978
- mutation: {
5979
- actions: "defer event",
5980
- target: "#editor.dirty"
6199
+ "read only": {
6200
+ on: {
6201
+ "update readOnly": {
6202
+ guard: ({
6203
+ event
6204
+ }) => !event.readOnly,
6205
+ target: "#editor.edit mode.editable",
6206
+ actions: ["emit editable"]
6207
+ }
6208
+ }
5981
6209
  }
5982
6210
  }
5983
6211
  },
5984
- normalizing: {
6212
+ editable: {
5985
6213
  on: {
5986
- "done normalizing": {
5987
- target: "idle"
6214
+ "update readOnly": {
6215
+ guard: ({
6216
+ event
6217
+ }) => event.readOnly,
6218
+ target: "#editor.edit mode.read only.read only",
6219
+ actions: ["emit read only"]
6220
+ },
6221
+ "behavior event": {
6222
+ actions: "handle behavior event"
6223
+ },
6224
+ "annotation.add": {
6225
+ actions: emit(({
6226
+ event
6227
+ }) => event)
6228
+ },
6229
+ "annotation.remove": {
6230
+ actions: emit(({
6231
+ event
6232
+ }) => event)
6233
+ },
6234
+ "annotation.toggle": {
6235
+ actions: emit(({
6236
+ event
6237
+ }) => event)
6238
+ },
6239
+ blur: {
6240
+ actions: emit(({
6241
+ event
6242
+ }) => event)
5988
6243
  },
6244
+ "decorator.*": {
6245
+ actions: emit(({
6246
+ event
6247
+ }) => event)
6248
+ },
6249
+ focus: {
6250
+ actions: emit(({
6251
+ event
6252
+ }) => event)
6253
+ },
6254
+ "insert.*": {
6255
+ actions: emit(({
6256
+ event
6257
+ }) => event)
6258
+ },
6259
+ "list item.*": {
6260
+ actions: emit(({
6261
+ event
6262
+ }) => event)
6263
+ },
6264
+ "style.*": {
6265
+ actions: emit(({
6266
+ event
6267
+ }) => event)
6268
+ }
6269
+ }
6270
+ }
6271
+ }
6272
+ },
6273
+ setup: {
6274
+ initial: "setting up",
6275
+ states: {
6276
+ "setting up": {
6277
+ exit: ["emit ready"],
6278
+ on: {
5989
6279
  patch: {
5990
6280
  actions: "defer event"
5991
6281
  },
5992
6282
  mutation: {
5993
6283
  actions: "defer event"
6284
+ },
6285
+ "done syncing": {
6286
+ target: "pristine"
6287
+ }
6288
+ }
6289
+ },
6290
+ pristine: {
6291
+ initial: "idle",
6292
+ states: {
6293
+ idle: {
6294
+ on: {
6295
+ normalizing: {
6296
+ target: "normalizing"
6297
+ },
6298
+ patch: {
6299
+ actions: "defer event",
6300
+ target: "#editor.setup.dirty"
6301
+ },
6302
+ mutation: {
6303
+ actions: "defer event",
6304
+ target: "#editor.setup.dirty"
6305
+ }
6306
+ }
6307
+ },
6308
+ normalizing: {
6309
+ on: {
6310
+ "done normalizing": {
6311
+ target: "idle"
6312
+ },
6313
+ patch: {
6314
+ actions: "defer event"
6315
+ },
6316
+ mutation: {
6317
+ actions: "defer event"
6318
+ }
6319
+ }
5994
6320
  }
5995
6321
  }
5996
- }
5997
- }
5998
- },
5999
- dirty: {
6000
- entry: ["emit pending events", "clear pending events"],
6001
- on: {
6002
- patch: {
6003
- actions: "emit patch event"
6004
6322
  },
6005
- mutation: {
6006
- actions: "emit mutation event"
6323
+ dirty: {
6324
+ entry: ["emit pending events", "clear pending events"],
6325
+ on: {
6326
+ patch: {
6327
+ actions: "emit patch event"
6328
+ },
6329
+ mutation: {
6330
+ actions: "emit mutation event"
6331
+ }
6332
+ }
6007
6333
  }
6008
6334
  }
6009
6335
  }
@@ -6131,11 +6457,13 @@ class PortableTextEditor extends Component {
6131
6457
  }), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
6132
6458
  }
6133
6459
  componentDidUpdate(prevProps) {
6460
+ var _a;
6134
6461
  !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({
6135
6462
  type: "update schema",
6136
6463
  schema: this.schemaTypes
6137
6464
  })), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
6138
- type: "toggle readOnly"
6465
+ type: "update readOnly",
6466
+ readOnly: (_a = this.props.readOnly) != null ? _a : !1
6139
6467
  }), this.props.maxBlocks !== prevProps.maxBlocks && this.editor._internal.editorActor.send({
6140
6468
  type: "update maxBlocks",
6141
6469
  maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
@@ -6152,7 +6480,7 @@ class PortableTextEditor extends Component {
6152
6480
  /* @__PURE__ */ jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
6153
6481
  this.props.editor || this.props.onChange(change), this.change$.next(change);
6154
6482
  } }),
6155
- /* @__PURE__ */ jsx(Synchronizer, { editorActor: this.editor._internal.editorActor, getValue: this.editor._internal.editable.getValue, portableTextEditor: this, slateEditor: this.editor._internal.slateEditor.instance }),
6483
+ /* @__PURE__ */ jsx(Synchronizer, { editorActor: this.editor._internal.editorActor, slateEditor: this.editor._internal.slateEditor.instance }),
6156
6484
  /* @__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 }) }) }) })
6157
6485
  ] });
6158
6486
  }
@@ -6337,7 +6665,8 @@ function RouteEventsToChanges(props) {
6337
6665
  case "list item.toggle":
6338
6666
  case "style.toggle":
6339
6667
  case "patches":
6340
- case "readOnly toggled":
6668
+ case "editable":
6669
+ case "read only":
6341
6670
  break bb5;
6342
6671
  default:
6343
6672
  handleChange(event);
@@ -6747,10 +7076,16 @@ function _insertFragment(editor, fragment, schemaTypes) {
6747
7076
  })) : editor.insertFragment(fragment);
6748
7077
  }), editor.onChange();
6749
7078
  }
6750
- function withSyncRangeDecorations(slateEditor, syncRangeDecorations) {
7079
+ function withSyncRangeDecorations({
7080
+ editorActor,
7081
+ slateEditor,
7082
+ syncRangeDecorations
7083
+ }) {
6751
7084
  const originalApply = slateEditor.apply;
6752
7085
  return slateEditor.apply = (op) => {
6753
- originalApply(op), op.type !== "set_selection" && syncRangeDecorations(op);
7086
+ originalApply(op), !editorActor.getSnapshot().matches({
7087
+ "edit mode": "read only"
7088
+ }) && op.type !== "set_selection" && syncRangeDecorations(op);
6754
7089
  }, () => {
6755
7090
  slateEditor.apply = originalApply;
6756
7091
  };
@@ -6818,7 +7153,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6818
7153
  "spellCheck"
6819
7154
  ]), portableTextEditor = usePortableTextEditor(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
6820
7155
  useImperativeHandle(forwardedRef, () => ref.current);
6821
- 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;
7156
+ const rangeDecorationsRef = useRef(rangeDecorations), editorActor = useContext(EditorActorContext), readOnly = useSelector(editorActor, (s) => s.matches({
7157
+ "edit mode": "read only"
7158
+ })), schemaTypes = useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = useSlate(), blockTypeName = schemaTypes.block.name;
6822
7159
  useMemo(() => {
6823
7160
  const withInsertData = createWithInsertData(editorActor, schemaTypes);
6824
7161
  if (readOnly)
@@ -6887,7 +7224,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6887
7224
  }, [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]);
6888
7225
  useEffect(() => {
6889
7226
  const onReady = editorActor.on("ready", () => {
6890
- restoreSelectionFromProps();
7227
+ syncRangeDecorations(), restoreSelectionFromProps();
6891
7228
  }), onInvalidValue = editorActor.on("invalid value", () => {
6892
7229
  setHasInvalidValue(!0);
6893
7230
  }), onValueChanged = editorActor.on("value changed", () => {
@@ -6896,7 +7233,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6896
7233
  return () => {
6897
7234
  onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
6898
7235
  };
6899
- }, [editorActor, restoreSelectionFromProps]), useEffect(() => {
7236
+ }, [editorActor, restoreSelectionFromProps, syncRangeDecorations]), useEffect(() => {
6900
7237
  propsSelection && !hasInvalidValue && restoreSelectionFromProps();
6901
7238
  }, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
6902
7239
  const [syncedRangeDecorations, setSyncedRangeDecorations] = useState(!1);
@@ -6905,9 +7242,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6905
7242
  }, [syncRangeDecorations, syncedRangeDecorations]), useEffect(() => {
6906
7243
  isEqual(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
6907
7244
  }, [rangeDecorations, syncRangeDecorations]), useEffect(() => {
6908
- const teardown = withSyncRangeDecorations(slateEditor, syncRangeDecorations);
7245
+ const teardown = withSyncRangeDecorations({
7246
+ editorActor,
7247
+ slateEditor,
7248
+ syncRangeDecorations
7249
+ });
6909
7250
  return () => teardown();
6910
- }, [slateEditor, syncRangeDecorations]);
7251
+ }, [editorActor, slateEditor, syncRangeDecorations]);
6911
7252
  const handleCopy = useCallback((event) => {
6912
7253
  onCopy ? onCopy(event) !== void 0 && event.preventDefault() : event.nativeEvent.clipboardData && editorActor.send({
6913
7254
  type: "behavior event",
@@ -7096,7 +7437,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7096
7437
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
7097
7438
  const EditorContext = React.createContext(void 0);
7098
7439
  function EditorProvider(props) {
7099
- const $ = c(30), editor = useCreateEditor(props.initialConfig), editorActor = editor._internal.editorActor, slateEditor = editor._internal.slateEditor, editable = editor._internal.editable;
7440
+ const $ = c(28), editor = useCreateEditor(props.initialConfig), editorActor = editor._internal.editorActor, slateEditor = editor._internal.slateEditor;
7100
7441
  let t0, t1;
7101
7442
  $[0] !== editor ? (t1 = new PortableTextEditor({
7102
7443
  editor
@@ -7109,21 +7450,21 @@ function EditorProvider(props) {
7109
7450
  let t3;
7110
7451
  $[4] !== editorActor || $[5] !== t2 ? (t3 = /* @__PURE__ */ jsx(RouteEventsToChanges, { editorActor, onChange: t2 }), $[4] = editorActor, $[5] = t2, $[6] = t3) : t3 = $[6];
7111
7452
  let t4;
7112
- $[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];
7453
+ $[7] !== editorActor || $[8] !== slateEditor.instance ? (t4 = /* @__PURE__ */ jsx(Synchronizer, { editorActor, slateEditor: slateEditor.instance }), $[7] = editorActor, $[8] = slateEditor.instance, $[9] = t4) : t4 = $[9];
7113
7454
  let t5;
7114
- $[12] !== editorActor || $[13] !== props.children ? (t5 = /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor, children: props.children }), $[12] = editorActor, $[13] = props.children, $[14] = t5) : t5 = $[14];
7455
+ $[10] !== editorActor || $[11] !== props.children ? (t5 = /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor, children: props.children }), $[10] = editorActor, $[11] = props.children, $[12] = t5) : t5 = $[12];
7115
7456
  let t6;
7116
- $[15] !== portableTextEditor || $[16] !== t5 ? (t6 = /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: portableTextEditor, children: t5 }), $[15] = portableTextEditor, $[16] = t5, $[17] = t6) : t6 = $[17];
7457
+ $[13] !== portableTextEditor || $[14] !== t5 ? (t6 = /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: portableTextEditor, children: t5 }), $[13] = portableTextEditor, $[14] = t5, $[15] = t6) : t6 = $[15];
7117
7458
  let t7;
7118
- $[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];
7459
+ $[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];
7119
7460
  let t8;
7120
- $[22] !== editorActor || $[23] !== t7 ? (t8 = /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: editorActor, children: t7 }), $[22] = editorActor, $[23] = t7, $[24] = t8) : t8 = $[24];
7461
+ $[20] !== editorActor || $[21] !== t7 ? (t8 = /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: editorActor, children: t7 }), $[20] = editorActor, $[21] = t7, $[22] = t8) : t8 = $[22];
7121
7462
  let t9;
7122
- return $[25] !== editor || $[26] !== t3 || $[27] !== t4 || $[28] !== t8 ? (t9 = /* @__PURE__ */ jsxs(EditorContext.Provider, { value: editor, children: [
7463
+ return $[23] !== editor || $[24] !== t3 || $[25] !== t4 || $[26] !== t8 ? (t9 = /* @__PURE__ */ jsxs(EditorContext.Provider, { value: editor, children: [
7123
7464
  t3,
7124
7465
  t4,
7125
7466
  t8
7126
- ] }), $[25] = editor, $[26] = t3, $[27] = t4, $[28] = t8, $[29] = t9) : t9 = $[29], t9;
7467
+ ] }), $[23] = editor, $[24] = t3, $[25] = t4, $[26] = t8, $[27] = t9) : t9 = $[27], t9;
7127
7468
  }
7128
7469
  function useEditor() {
7129
7470
  const editor = React.useContext(EditorContext);
@@ -7152,6 +7493,10 @@ function useEditorSelector(editor, selector, t0) {
7152
7493
  let t1;
7153
7494
  return $[0] !== editor || $[1] !== selector ? (t1 = (snapshot) => {
7154
7495
  const context = {
7496
+ activeDecorators: getActiveDecorators({
7497
+ schema: snapshot.context.schema,
7498
+ slateEditorInstance: editor._internal.slateEditor.instance
7499
+ }),
7155
7500
  keyGenerator: snapshot.context.keyGenerator,
7156
7501
  schema: snapshot.context.schema,
7157
7502
  selection: snapshot.context.selection,