@portabletext/editor 7.0.5 → 7.0.6

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.
package/lib/index.js CHANGED
@@ -4785,32 +4785,6 @@ function DropIndicator() {
4785
4785
  zIndex: 5
4786
4786
  }, children: /* @__PURE__ */ jsx("span", {}) }), $[0] = t0) : t0 = $[0], t0;
4787
4787
  }
4788
- function defaultCompare(a, b) {
4789
- return a === b;
4790
- }
4791
- function useEditorSelector(editor, selector, t0) {
4792
- return useSelector(editor, selector, t0 === void 0 ? defaultCompare : t0);
4793
- }
4794
- function getEditorSnapshot({
4795
- editorActorSnapshot,
4796
- editorEngineInstance
4797
- }) {
4798
- return {
4799
- blockIndexMap: editorEngineInstance.blockIndexMap,
4800
- context: {
4801
- containers: editorEngineInstance.publicContainers,
4802
- converters: editorActorSnapshot.context.converters,
4803
- keyGenerator: editorActorSnapshot.context.keyGenerator,
4804
- readOnly: editorActorSnapshot.matches({
4805
- "edit mode": "read only"
4806
- }),
4807
- schema: editorActorSnapshot.context.schema,
4808
- selection: editorEngineInstance.selection,
4809
- value: editorEngineInstance.children
4810
- },
4811
- decoratorState: editorEngineInstance.decoratorState
4812
- };
4813
- }
4814
4788
  const emptySet$1 = /* @__PURE__ */ new Set(), emptyState = {
4815
4789
  focusedLeafPath: void 0,
4816
4790
  selectedLeafPaths: emptySet$1,
@@ -4885,15 +4859,12 @@ const defaultStore = {
4885
4859
  getSnapshot: () => defaultSelectionState
4886
4860
  }, SelectionStateStoreContext = createContext(defaultStore);
4887
4861
  function SelectionStateProvider(t0) {
4888
- const $ = c(10), {
4862
+ const $ = c(11), {
4889
4863
  children
4890
4864
  } = t0, editorActor = useContext(EditorActorContext), editorEngine = useEngineStatic();
4891
4865
  let t1;
4892
- $[0] !== editorActor || $[1] !== editorEngine ? (t1 = () => {
4893
- const actorSnapshot = editorActor.getSnapshot(), snapshot = getEditorSnapshot({
4894
- editorActorSnapshot: actorSnapshot,
4895
- editorEngineInstance: editorEngine
4896
- }), selection = snapshot.context.selection ? {
4866
+ $[0] !== editorEngine.blockIndexMap || $[1] !== editorEngine.publicContainers || $[2] !== editorEngine.snapshot ? (t1 = () => {
4867
+ const snapshot = editorEngine.snapshot, selection = snapshot.context.selection ? {
4897
4868
  anchorPath: snapshot.context.selection.anchor.path,
4898
4869
  focusPath: snapshot.context.selection.focus.path,
4899
4870
  backward: snapshot.context.selection.backward ?? !1,
@@ -4907,10 +4878,10 @@ function SelectionStateProvider(t0) {
4907
4878
  },
4908
4879
  blockIndexMap: editorEngine.blockIndexMap
4909
4880
  }, selection);
4910
- }, $[0] = editorActor, $[1] = editorEngine, $[2] = t1) : t1 = $[2];
4881
+ }, $[0] = editorEngine.blockIndexMap, $[1] = editorEngine.publicContainers, $[2] = editorEngine.snapshot, $[3] = t1) : t1 = $[3];
4911
4882
  const computeCurrent = t1, [seed] = useState(computeCurrent), stateRef = useRef(seed), [initialSubscribers] = useState(_temp$2), subscribersRef = useRef(initialSubscribers);
4912
4883
  let t2, t3;
4913
- $[3] !== computeCurrent || $[4] !== editorActor ? (t2 = () => {
4884
+ $[4] !== computeCurrent || $[5] !== editorActor ? (t2 = () => {
4914
4885
  const next = computeCurrent();
4915
4886
  if (!selectionStatesEqual(stateRef.current, next)) {
4916
4887
  stateRef.current = next;
@@ -4930,17 +4901,17 @@ function SelectionStateProvider(t0) {
4930
4901
  }));
4931
4902
  });
4932
4903
  return () => subscription.unsubscribe();
4933
- }, t3 = [editorActor, computeCurrent], $[3] = computeCurrent, $[4] = editorActor, $[5] = t2, $[6] = t3) : (t2 = $[5], t3 = $[6]), useEffect(t2, t3);
4904
+ }, t3 = [editorActor, computeCurrent], $[4] = computeCurrent, $[5] = editorActor, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3);
4934
4905
  let t4;
4935
- $[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = {
4906
+ $[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = {
4936
4907
  subscribe: (callback) => (subscribersRef.current.add(callback), () => {
4937
4908
  subscribersRef.current.delete(callback);
4938
4909
  }),
4939
4910
  getSnapshot: () => stateRef.current
4940
- }, $[7] = t4) : t4 = $[7];
4911
+ }, $[8] = t4) : t4 = $[8];
4941
4912
  const store = t4;
4942
4913
  let t5;
4943
- return $[8] !== children ? (t5 = /* @__PURE__ */ jsx(SelectionStateStoreContext.Provider, { value: store, children }), $[8] = children, $[9] = t5) : t5 = $[9], t5;
4914
+ return $[9] !== children ? (t5 = /* @__PURE__ */ jsx(SelectionStateStoreContext.Provider, { value: store, children }), $[9] = children, $[10] = t5) : t5 = $[10], t5;
4944
4915
  }
4945
4916
  function _temp$2() {
4946
4917
  return /* @__PURE__ */ new Set();
@@ -5355,7 +5326,7 @@ function resolveElementDropPosition(dropPosition, elementPath) {
5355
5326
  return dropPosition.position;
5356
5327
  }
5357
5328
  function tupleRefEqual(previous, next) {
5358
- if (previous.length !== next.length)
5329
+ if (previous === null || previous.length !== next.length)
5359
5330
  return !1;
5360
5331
  for (let i = 0; i < previous.length; i++)
5361
5332
  if (!Object.is(previous[i], next[i]))
@@ -5363,7 +5334,7 @@ function tupleRefEqual(previous, next) {
5363
5334
  return !0;
5364
5335
  }
5365
5336
  function RenderElement(props) {
5366
- const $ = c(84), editorActor = useContext(EditorActorContext), parentContainer = useContext(ParentContainerContext), parentTextBlock = useContext(ParentTextBlockContext), isInNewPipeline = useContext(NewPipelineContext), engineStatic = useEngineStatic(), schema = props.schema, type = props.element._type;
5337
+ const $ = c(84), parentContainer = useContext(ParentContainerContext), parentTextBlock = useContext(ParentTextBlockContext), isInNewPipeline = useContext(NewPipelineContext), engineStatic = useEngineStatic(), schema = props.schema, type = props.element._type;
5367
5338
  let t0;
5368
5339
  $[0] !== parentContainer || $[1] !== type ? (t0 = findBlockPositionalOverride(parentContainer, type), $[0] = parentContainer, $[1] = type, $[2] = t0) : t0 = $[2];
5369
5340
  const blockPositionalOverride = t0;
@@ -5371,8 +5342,8 @@ function RenderElement(props) {
5371
5342
  $[3] !== parentTextBlock || $[4] !== type ? (t1 = findInlinePositionalOverride(parentTextBlock, type), $[3] = parentTextBlock, $[4] = type, $[5] = t1) : t1 = $[5];
5372
5343
  const inlinePositionalOverride = t1;
5373
5344
  let t2;
5374
- $[6] !== type ? (t2 = (state) => [state.context.containers.get(type), state.context.blockObjects.get(type), state.context.inlineObjects.get(type), state.context.textBlocks.get(type)], $[6] = type, $[7] = t2) : t2 = $[7];
5375
- const [globalContainerConfig, globalBlockObjectConfig, globalInlineObjectConfig, textBlockConfig] = useSelector(editorActor, t2, tupleRefEqual);
5345
+ $[6] !== type ? (t2 = (engine) => [engine.containers.get(type), engine.blockObjects.get(type), engine.inlineObjects.get(type), engine.textBlocks.get(type)], $[6] = type, $[7] = t2) : t2 = $[7];
5346
+ const [globalContainerConfig, globalBlockObjectConfig, globalInlineObjectConfig, textBlockConfig] = useEngineSelector(t2, tupleRefEqual);
5376
5347
  let t3;
5377
5348
  bb0: {
5378
5349
  if (blockPositionalOverride && "container" in blockPositionalOverride) {
@@ -5564,13 +5535,13 @@ function RenderTextBlockConfig(props) {
5564
5535
  }), $[2] = focused, $[3] = props.attributes, $[4] = props.children, $[5] = props.node, $[6] = props.path, $[7] = props.readOnly, $[8] = props.render, $[9] = selected, $[10] = t1) : t1 = $[10], t1;
5565
5536
  }
5566
5537
  function useSpanConfig(node, _path) {
5567
- const $ = c(5), editorActor = useContext(EditorActorContext), parentTextBlock = useContext(ParentTextBlockContext);
5538
+ const $ = c(5), parentTextBlock = useContext(ParentTextBlockContext);
5568
5539
  let t0;
5569
5540
  $[0] !== node._type || $[1] !== parentTextBlock ? (t0 = findInlinePositionalOverride(parentTextBlock, node._type), $[0] = node._type, $[1] = parentTextBlock, $[2] = t0) : t0 = $[2];
5570
5541
  const positional = t0;
5571
5542
  let t1;
5572
- $[3] !== node._type ? (t1 = (state) => state.context.spans.get(node._type), $[3] = node._type, $[4] = t1) : t1 = $[4];
5573
- const globalSpan = useSelector(editorActor, t1);
5543
+ $[3] !== node._type ? (t1 = (engine) => engine.spans.get(node._type), $[3] = node._type, $[4] = t1) : t1 = $[4];
5544
+ const globalSpan = useEngineSelector(t1);
5574
5545
  return positional && "span" in positional ? positional.span.render === void 0 ? globalSpan : positional : globalSpan;
5575
5546
  }
5576
5547
  function RenderSpan(props) {
@@ -6025,7 +5996,7 @@ function validateSelection(editorEngine, editorElement) {
6025
5996
  }
6026
5997
  }
6027
5998
  const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6028
- const $ = c(183);
5999
+ const $ = c(180);
6029
6000
  let hotkeys, onBeforeInput, onBlur, onClick, onCopy, onCut, onDrag, onDragEnd, onDragEnter, onDragLeave, onDragOver, onDragStart, onDrop, onFocus, onPaste, propsSelection, rangeDecorations, renderAnnotation, renderBlock, renderChild, renderDecorator, renderListItem, renderPlaceholder, renderStyle, restProps, scrollSelectionIntoView;
6030
6001
  $[0] !== props ? ({
6031
6002
  hotkeys,
@@ -6055,65 +6026,62 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6055
6026
  scrollSelectionIntoView,
6056
6027
  ...restProps
6057
6028
  } = props, $[0] = props, $[1] = hotkeys, $[2] = onBeforeInput, $[3] = onBlur, $[4] = onClick, $[5] = onCopy, $[6] = onCut, $[7] = onDrag, $[8] = onDragEnd, $[9] = onDragEnter, $[10] = onDragLeave, $[11] = onDragOver, $[12] = onDragStart, $[13] = onDrop, $[14] = onFocus, $[15] = onPaste, $[16] = propsSelection, $[17] = rangeDecorations, $[18] = renderAnnotation, $[19] = renderBlock, $[20] = renderChild, $[21] = renderDecorator, $[22] = renderListItem, $[23] = renderPlaceholder, $[24] = renderStyle, $[25] = restProps, $[26] = scrollSelectionIntoView) : (hotkeys = $[1], onBeforeInput = $[2], onBlur = $[3], onClick = $[4], onCopy = $[5], onCut = $[6], onDrag = $[7], onDragEnd = $[8], onDragEnter = $[9], onDragLeave = $[10], onDragOver = $[11], onDragStart = $[12], onDrop = $[13], onFocus = $[14], onPaste = $[15], propsSelection = $[16], rangeDecorations = $[17], renderAnnotation = $[18], renderBlock = $[19], renderChild = $[20], renderDecorator = $[21], renderListItem = $[22], renderPlaceholder = $[23], renderStyle = $[24], restProps = $[25], scrollSelectionIntoView = $[26]);
6058
- const portableTextEditor = usePortableTextEditor(), [hasInvalidValue, setHasInvalidValue] = useState(!1), editorActor = useContext(EditorActorContext), relayActor = useContext(RelayActorContext);
6029
+ const portableTextEditor = usePortableTextEditor(), [hasInvalidValue, setHasInvalidValue] = useState(!1), editorActor = useContext(EditorActorContext), relayActor = useContext(RelayActorContext), editorEngine = useEngine(), schema = editorEngine.schema, readOnly = useSelector(editorActor, _temp);
6059
6030
  let t0;
6060
- $[27] !== editorActor ? (t0 = editorActor.getSnapshot(), $[27] = editorActor, $[28] = t0) : t0 = $[28];
6061
- const schema = t0.context.schema, readOnly = useSelector(editorActor, _temp), editorEngine = useEngine();
6062
- let t1;
6063
- $[29] !== editorEngine ? (t1 = {
6031
+ $[27] !== editorEngine ? (t0 = {
6064
6032
  input: {
6065
6033
  editorEngine
6066
6034
  }
6067
- }, $[29] = editorEngine, $[30] = t1) : t1 = $[30];
6068
- const validateSelectionActor = useActorRef(validateSelectionMachine, t1);
6035
+ }, $[27] = editorEngine, $[28] = t0) : t0 = $[28];
6036
+ const validateSelectionActor = useActorRef(validateSelectionMachine, t0);
6037
+ let t1;
6038
+ $[29] !== rangeDecorations ? (t1 = rangeDecorations ?? [], $[29] = rangeDecorations, $[30] = t1) : t1 = $[30];
6069
6039
  let t2;
6070
- $[31] !== rangeDecorations ? (t2 = rangeDecorations ?? [], $[31] = rangeDecorations, $[32] = t2) : t2 = $[32];
6071
- let t3;
6072
- $[33] !== editorActor ? (t3 = editorActor.getSnapshot().matches({
6040
+ $[31] !== editorActor ? (t2 = editorActor.getSnapshot().matches({
6073
6041
  setup: "setting up"
6074
- }), $[33] = editorActor, $[34] = t3) : t3 = $[34];
6075
- const t4 = !t3;
6076
- let t5;
6077
- $[35] !== editorEngine || $[36] !== readOnly || $[37] !== schema || $[38] !== t2 || $[39] !== t4 ? (t5 = {
6042
+ }), $[31] = editorActor, $[32] = t2) : t2 = $[32];
6043
+ const t3 = !t2;
6044
+ let t4;
6045
+ $[33] !== editorEngine || $[34] !== readOnly || $[35] !== schema || $[36] !== t1 || $[37] !== t3 ? (t4 = {
6078
6046
  input: {
6079
- rangeDecorations: t2,
6047
+ rangeDecorations: t1,
6080
6048
  readOnly,
6081
6049
  schema,
6082
6050
  editorEngine,
6083
- skipSetup: t4
6051
+ skipSetup: t3
6084
6052
  }
6085
- }, $[35] = editorEngine, $[36] = readOnly, $[37] = schema, $[38] = t2, $[39] = t4, $[40] = t5) : t5 = $[40];
6086
- const rangeDecorationsActor = useActorRef(rangeDecorationsMachine, t5), decorate = useSelector(rangeDecorationsActor, _temp2), dropPosition = useDropPosition();
6087
- let t6, t7;
6088
- $[41] !== rangeDecorationsActor || $[42] !== readOnly ? (t6 = () => {
6053
+ }, $[33] = editorEngine, $[34] = readOnly, $[35] = schema, $[36] = t1, $[37] = t3, $[38] = t4) : t4 = $[38];
6054
+ const rangeDecorationsActor = useActorRef(rangeDecorationsMachine, t4), decorate = useSelector(rangeDecorationsActor, _temp2), dropPosition = useDropPosition();
6055
+ let t5, t6;
6056
+ $[39] !== rangeDecorationsActor || $[40] !== readOnly ? (t5 = () => {
6089
6057
  rangeDecorationsActor.send({
6090
6058
  type: "update read only",
6091
6059
  readOnly
6092
6060
  });
6093
- }, t7 = [rangeDecorationsActor, readOnly], $[41] = rangeDecorationsActor, $[42] = readOnly, $[43] = t6, $[44] = t7) : (t6 = $[43], t7 = $[44]), useEffect(t6, t7);
6094
- let t8, t9;
6095
- $[45] !== rangeDecorations || $[46] !== rangeDecorationsActor ? (t8 = () => {
6061
+ }, t6 = [rangeDecorationsActor, readOnly], $[39] = rangeDecorationsActor, $[40] = readOnly, $[41] = t5, $[42] = t6) : (t5 = $[41], t6 = $[42]), useEffect(t5, t6);
6062
+ let t7, t8;
6063
+ $[43] !== rangeDecorations || $[44] !== rangeDecorationsActor ? (t7 = () => {
6096
6064
  rangeDecorationsActor.send({
6097
6065
  type: "range decorations updated",
6098
6066
  rangeDecorations: rangeDecorations ?? []
6099
6067
  });
6100
- }, t9 = [rangeDecorationsActor, rangeDecorations], $[45] = rangeDecorations, $[46] = rangeDecorationsActor, $[47] = t8, $[48] = t9) : (t8 = $[47], t9 = $[48]), useEffect(t8, t9);
6101
- let t10;
6102
- $[49] !== renderBlock || $[50] !== renderChild || $[51] !== renderListItem || $[52] !== renderStyle ? (t10 = {
6068
+ }, t8 = [rangeDecorationsActor, rangeDecorations], $[43] = rangeDecorations, $[44] = rangeDecorationsActor, $[45] = t7, $[46] = t8) : (t7 = $[45], t8 = $[46]), useEffect(t7, t8);
6069
+ let t9;
6070
+ $[47] !== renderBlock || $[48] !== renderChild || $[49] !== renderListItem || $[50] !== renderStyle ? (t9 = {
6103
6071
  renderBlock,
6104
6072
  renderChild,
6105
6073
  renderListItem,
6106
6074
  renderStyle
6107
- }, $[49] = renderBlock, $[50] = renderChild, $[51] = renderListItem, $[52] = renderStyle, $[53] = t10) : t10 = $[53];
6108
- const legacy = t10;
6075
+ }, $[47] = renderBlock, $[48] = renderChild, $[49] = renderListItem, $[50] = renderStyle, $[51] = t9) : t9 = $[51];
6076
+ const legacy = t9;
6077
+ let t10;
6078
+ $[52] !== dropPosition || $[53] !== legacy || $[54] !== readOnly || $[55] !== schema ? (t10 = (eProps) => /* @__PURE__ */ jsx(RenderElement, { ...eProps, dropPosition, legacy, readOnly, schema }), $[52] = dropPosition, $[53] = legacy, $[54] = readOnly, $[55] = schema, $[56] = t10) : t10 = $[56];
6079
+ const renderElement = t10;
6109
6080
  let t11;
6110
- $[54] !== dropPosition || $[55] !== legacy || $[56] !== readOnly || $[57] !== schema ? (t11 = (eProps) => /* @__PURE__ */ jsx(RenderElement, { ...eProps, dropPosition, legacy, readOnly, schema }), $[54] = dropPosition, $[55] = legacy, $[56] = readOnly, $[57] = schema, $[58] = t11) : t11 = $[58];
6111
- const renderElement = t11;
6081
+ $[57] !== readOnly || $[58] !== renderAnnotation || $[59] !== renderChild || $[60] !== renderDecorator || $[61] !== renderPlaceholder || $[62] !== schema ? (t11 = (leafProps) => /* @__PURE__ */ jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schema }), $[57] = readOnly, $[58] = renderAnnotation, $[59] = renderChild, $[60] = renderDecorator, $[61] = renderPlaceholder, $[62] = schema, $[63] = t11) : t11 = $[63];
6082
+ const renderLeaf = t11, renderText = _temp3;
6112
6083
  let t12;
6113
- $[59] !== readOnly || $[60] !== renderAnnotation || $[61] !== renderChild || $[62] !== renderDecorator || $[63] !== renderPlaceholder || $[64] !== schema ? (t12 = (leafProps) => /* @__PURE__ */ jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schema }), $[59] = readOnly, $[60] = renderAnnotation, $[61] = renderChild, $[62] = renderDecorator, $[63] = renderPlaceholder, $[64] = schema, $[65] = t12) : t12 = $[65];
6114
- const renderLeaf = t12, renderText = _temp3;
6115
- let t13;
6116
- $[66] !== editorActor || $[67] !== editorEngine || $[68] !== propsSelection ? (t13 = () => {
6084
+ $[64] !== editorActor || $[65] !== editorEngine || $[66] !== propsSelection ? (t12 = () => {
6117
6085
  if (propsSelection) {
6118
6086
  debug.selection.enabled && debug.selection(`Selection from props ${safeStringify(propsSelection)}`);
6119
6087
  const resolvedSelection = resolveSelection(editorEngine, propsSelection);
@@ -6122,10 +6090,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6122
6090
  selection: resolvedSelection
6123
6091
  }), editorEngine.onChange());
6124
6092
  }
6125
- }, $[66] = editorActor, $[67] = editorEngine, $[68] = propsSelection, $[69] = t13) : t13 = $[69];
6126
- const restoreSelectionFromProps = t13;
6127
- let t14, t15;
6128
- $[70] !== editorActor || $[71] !== rangeDecorationsActor || $[72] !== restoreSelectionFromProps ? (t14 = () => {
6093
+ }, $[64] = editorActor, $[65] = editorEngine, $[66] = propsSelection, $[67] = t12) : t12 = $[67];
6094
+ const restoreSelectionFromProps = t12;
6095
+ let t13, t14;
6096
+ $[68] !== editorActor || $[69] !== rangeDecorationsActor || $[70] !== restoreSelectionFromProps ? (t13 = () => {
6129
6097
  const onReady = editorActor.on("ready", () => {
6130
6098
  rangeDecorationsActor.send({
6131
6099
  type: "ready"
@@ -6138,13 +6106,13 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6138
6106
  return () => {
6139
6107
  onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
6140
6108
  };
6141
- }, t15 = [rangeDecorationsActor, editorActor, restoreSelectionFromProps], $[70] = editorActor, $[71] = rangeDecorationsActor, $[72] = restoreSelectionFromProps, $[73] = t14, $[74] = t15) : (t14 = $[73], t15 = $[74]), useEffect(t14, t15);
6142
- let t16, t17;
6143
- $[75] !== hasInvalidValue || $[76] !== propsSelection || $[77] !== restoreSelectionFromProps ? (t16 = () => {
6109
+ }, t14 = [rangeDecorationsActor, editorActor, restoreSelectionFromProps], $[68] = editorActor, $[69] = rangeDecorationsActor, $[70] = restoreSelectionFromProps, $[71] = t13, $[72] = t14) : (t13 = $[71], t14 = $[72]), useEffect(t13, t14);
6110
+ let t15, t16;
6111
+ $[73] !== hasInvalidValue || $[74] !== propsSelection || $[75] !== restoreSelectionFromProps ? (t15 = () => {
6144
6112
  propsSelection && !hasInvalidValue && restoreSelectionFromProps();
6145
- }, t17 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[75] = hasInvalidValue, $[76] = propsSelection, $[77] = restoreSelectionFromProps, $[78] = t16, $[79] = t17) : (t16 = $[78], t17 = $[79]), useEffect(t16, t17);
6146
- let t18;
6147
- $[80] !== editorActor || $[81] !== editorEngine || $[82] !== onCopy ? (t18 = (event) => {
6113
+ }, t16 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[73] = hasInvalidValue, $[74] = propsSelection, $[75] = restoreSelectionFromProps, $[76] = t15, $[77] = t16) : (t15 = $[76], t16 = $[77]), useEffect(t15, t16);
6114
+ let t17;
6115
+ $[78] !== editorActor || $[79] !== editorEngine || $[80] !== onCopy ? (t17 = (event) => {
6148
6116
  if (DOMEditor.hasSelectableTarget(editorEngine, event.target)) {
6149
6117
  if (onCopy)
6150
6118
  onCopy(event) !== void 0 && event.preventDefault();
@@ -6171,16 +6139,16 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6171
6139
  });
6172
6140
  }
6173
6141
  }
6174
- }, $[80] = editorActor, $[81] = editorEngine, $[82] = onCopy, $[83] = t18) : t18 = $[83];
6175
- const handleCopy = t18;
6176
- let t19;
6177
- $[84] !== editorActor || $[85] !== editorEngine || $[86] !== onCut ? (t19 = (event_0) => {
6142
+ }, $[78] = editorActor, $[79] = editorEngine, $[80] = onCopy, $[81] = t17) : t17 = $[81];
6143
+ const handleCopy = t17;
6144
+ let t18;
6145
+ $[82] !== editorActor || $[83] !== editorEngine || $[84] !== onCut ? (t18 = (event_0) => {
6178
6146
  if (DOMEditor.hasSelectableTarget(editorEngine, event_0.target)) {
6179
6147
  if (onCut)
6180
6148
  onCut(event_0) !== void 0 && event_0.preventDefault();
6181
6149
  else if (event_0.nativeEvent.clipboardData) {
6182
6150
  event_0.stopPropagation(), event_0.preventDefault();
6183
- const selection_0 = editorActor.getSnapshot().context.selection, position_0 = selection_0 ? {
6151
+ const selection_0 = editorEngine.selection, position_0 = selection_0 ? {
6184
6152
  selection: selection_0
6185
6153
  } : void 0;
6186
6154
  if (!position_0) {
@@ -6201,10 +6169,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6201
6169
  });
6202
6170
  }
6203
6171
  }
6204
- }, $[84] = editorActor, $[85] = editorEngine, $[86] = onCut, $[87] = t19) : t19 = $[87];
6205
- const handleCut = t19;
6206
- let t20;
6207
- $[88] !== editorActor || $[89] !== editorEngine || $[90] !== onPaste || $[91] !== portableTextEditor || $[92] !== relayActor ? (t20 = (event_1) => {
6172
+ }, $[82] = editorActor, $[83] = editorEngine, $[84] = onCut, $[85] = t18) : t18 = $[85];
6173
+ const handleCut = t18;
6174
+ let t19;
6175
+ $[86] !== editorActor || $[87] !== editorEngine || $[88] !== onPaste || $[89] !== portableTextEditor || $[90] !== relayActor ? (t19 = (event_1) => {
6208
6176
  const value = editorEngine.children, path2 = editorEngine.selection?.focus.path || [], onPasteResult = onPaste?.({
6209
6177
  event: event_1,
6210
6178
  value,
@@ -6217,7 +6185,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6217
6185
  }), Promise.resolve(onPasteResult).then((result_1) => {
6218
6186
  if (debug.behaviors("Custom paste function from client resolved", result_1), !result_1 || !result_1.insert) {
6219
6187
  debug.behaviors("No result from custom paste handler, pasting normally");
6220
- const selection_1 = editorActor.getSnapshot().context.selection, position_1 = selection_1 ? {
6188
+ const selection_1 = editorEngine.selection, position_1 = selection_1 ? {
6221
6189
  selection: selection_1
6222
6190
  } : void 0;
6223
6191
  if (!position_1) {
@@ -6242,8 +6210,8 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6242
6210
  behaviorEvent: {
6243
6211
  type: "insert.blocks",
6244
6212
  blocks: parseBlocks({
6245
- keyGenerator: editorActor.getSnapshot().context.keyGenerator,
6246
- schema: editorActor.getSnapshot().context.schema,
6213
+ keyGenerator: editorEngine.keyGenerator,
6214
+ schema: editorEngine.schema,
6247
6215
  blocks: result_1.insert,
6248
6216
  options: {
6249
6217
  normalize: !1,
@@ -6262,7 +6230,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6262
6230
  });
6263
6231
  else if (event_1.nativeEvent.clipboardData) {
6264
6232
  event_1.preventDefault(), event_1.stopPropagation();
6265
- const selection_2 = editorActor.getSnapshot().context.selection, position_2 = selection_2 ? {
6233
+ const selection_2 = editorEngine.selection, position_2 = selection_2 ? {
6266
6234
  selection: selection_2
6267
6235
  } : void 0;
6268
6236
  if (!position_2) {
@@ -6283,18 +6251,18 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6283
6251
  });
6284
6252
  }
6285
6253
  debug.behaviors("No result from custom paste handler, pasting normally");
6286
- }, $[88] = editorActor, $[89] = editorEngine, $[90] = onPaste, $[91] = portableTextEditor, $[92] = relayActor, $[93] = t20) : t20 = $[93];
6287
- const handlePaste = t20;
6288
- let t21;
6289
- $[94] !== editorActor || $[95] !== editorEngine || $[96] !== onFocus || $[97] !== relayActor ? (t21 = (event_2) => {
6254
+ }, $[86] = editorActor, $[87] = editorEngine, $[88] = onPaste, $[89] = portableTextEditor, $[90] = relayActor, $[91] = t19) : t19 = $[91];
6255
+ const handlePaste = t19;
6256
+ let t20;
6257
+ $[92] !== editorEngine || $[93] !== onFocus || $[94] !== relayActor ? (t20 = (event_2) => {
6290
6258
  onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
6291
6259
  type: "focused",
6292
6260
  event: event_2
6293
- }), !editorEngine.selection && editorEngine.children.length === 1 && isEmptyTextBlock(editorActor.getSnapshot().context, editorEngine.children.at(0)) && (editorEngine.select(start(editorEngine, [])), editorEngine.onChange()));
6294
- }, $[94] = editorActor, $[95] = editorEngine, $[96] = onFocus, $[97] = relayActor, $[98] = t21) : t21 = $[98];
6295
- const handleOnFocus = t21;
6296
- let t22;
6297
- $[99] !== editorActor || $[100] !== editorEngine || $[101] !== onClick ? (t22 = (event_3) => {
6261
+ }), !editorEngine.selection && editorEngine.children.length === 1 && isEmptyTextBlock(editorEngine, editorEngine.children.at(0)) && (editorEngine.select(start(editorEngine, [])), editorEngine.onChange()));
6262
+ }, $[92] = editorEngine, $[93] = onFocus, $[94] = relayActor, $[95] = t20) : t20 = $[95];
6263
+ const handleOnFocus = t20;
6264
+ let t21;
6265
+ $[96] !== editorActor || $[97] !== editorEngine || $[98] !== onClick ? (t21 = (event_3) => {
6298
6266
  if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
6299
6267
  return;
6300
6268
  const position_3 = getEventPosition({
@@ -6311,23 +6279,23 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6311
6279
  editor: editorEngine,
6312
6280
  nativeEvent: event_3
6313
6281
  });
6314
- }, $[99] = editorActor, $[100] = editorEngine, $[101] = onClick, $[102] = t22) : t22 = $[102];
6315
- const handleClick = t22;
6316
- let t23;
6317
- $[103] !== onBlur || $[104] !== relayActor ? (t23 = (event_4) => {
6282
+ }, $[96] = editorActor, $[97] = editorEngine, $[98] = onClick, $[99] = t21) : t21 = $[99];
6283
+ const handleClick = t21;
6284
+ let t22;
6285
+ $[100] !== onBlur || $[101] !== relayActor ? (t22 = (event_4) => {
6318
6286
  onBlur && onBlur(event_4), event_4.isPropagationStopped() || relayActor.send({
6319
6287
  type: "blurred",
6320
6288
  event: event_4
6321
6289
  });
6322
- }, $[103] = onBlur, $[104] = relayActor, $[105] = t23) : t23 = $[105];
6323
- const handleOnBlur = t23;
6324
- let t24;
6325
- $[106] !== onBeforeInput ? (t24 = (event_5) => {
6290
+ }, $[100] = onBlur, $[101] = relayActor, $[102] = t22) : t22 = $[102];
6291
+ const handleOnBlur = t22;
6292
+ let t23;
6293
+ $[103] !== onBeforeInput ? (t23 = (event_5) => {
6326
6294
  onBeforeInput && onBeforeInput(event_5);
6327
- }, $[106] = onBeforeInput, $[107] = t24) : t24 = $[107];
6328
- const handleOnBeforeInput = t24;
6329
- let t25;
6330
- $[108] !== editorActor || $[109] !== editorEngine || $[110] !== hotkeys || $[111] !== portableTextEditor || $[112] !== props ? (t25 = (event_6) => {
6295
+ }, $[103] = onBeforeInput, $[104] = t23) : t23 = $[104];
6296
+ const handleOnBeforeInput = t23;
6297
+ let t24;
6298
+ $[105] !== editorActor || $[106] !== editorEngine || $[107] !== hotkeys || $[108] !== portableTextEditor || $[109] !== props ? (t24 = (event_6) => {
6331
6299
  props.onKeyDown && props.onKeyDown(event_6), event_6.isDefaultPrevented() || performHotkey({
6332
6300
  editorActor,
6333
6301
  editor: editorEngine,
@@ -6350,10 +6318,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6350
6318
  editor: editorEngine,
6351
6319
  nativeEvent: event_6
6352
6320
  });
6353
- }, $[108] = editorActor, $[109] = editorEngine, $[110] = hotkeys, $[111] = portableTextEditor, $[112] = props, $[113] = t25) : t25 = $[113];
6354
- const handleKeyDown = t25;
6355
- let t26;
6356
- $[114] !== editorActor || $[115] !== editorEngine || $[116] !== props ? (t26 = (event_7) => {
6321
+ }, $[105] = editorActor, $[106] = editorEngine, $[107] = hotkeys, $[108] = portableTextEditor, $[109] = props, $[110] = t24) : t24 = $[110];
6322
+ const handleKeyDown = t24;
6323
+ let t25;
6324
+ $[111] !== editorActor || $[112] !== editorEngine || $[113] !== props ? (t25 = (event_7) => {
6357
6325
  props.onKeyUp && props.onKeyUp(event_7), event_7.isDefaultPrevented() || editorActor.send({
6358
6326
  type: "behavior event",
6359
6327
  behaviorEvent: {
@@ -6370,26 +6338,26 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6370
6338
  editor: editorEngine,
6371
6339
  nativeEvent: event_7
6372
6340
  });
6373
- }, $[114] = editorActor, $[115] = editorEngine, $[116] = props, $[117] = t26) : t26 = $[117];
6374
- const handleKeyUp = t26;
6375
- let t27;
6341
+ }, $[111] = editorActor, $[112] = editorEngine, $[113] = props, $[114] = t25) : t25 = $[114];
6342
+ const handleKeyUp = t25;
6343
+ let t26;
6376
6344
  bb0: {
6377
6345
  if (scrollSelectionIntoView === void 0) {
6378
- t27 = void 0;
6346
+ t26 = void 0;
6379
6347
  break bb0;
6380
6348
  }
6381
6349
  if (scrollSelectionIntoView === null) {
6382
- t27 = noop;
6350
+ t26 = noop;
6383
6351
  break bb0;
6384
6352
  }
6385
- let t282;
6386
- $[118] !== portableTextEditor || $[119] !== scrollSelectionIntoView ? (t282 = (_editor, domRange) => {
6353
+ let t272;
6354
+ $[115] !== portableTextEditor || $[116] !== scrollSelectionIntoView ? (t272 = (_editor, domRange) => {
6387
6355
  scrollSelectionIntoView(portableTextEditor, domRange);
6388
- }, $[118] = portableTextEditor, $[119] = scrollSelectionIntoView, $[120] = t282) : t282 = $[120], t27 = t282;
6356
+ }, $[115] = portableTextEditor, $[116] = scrollSelectionIntoView, $[117] = t272) : t272 = $[117], t26 = t272;
6389
6357
  }
6390
- const scrollSelectionIntoViewToEngine = t27;
6391
- let t28, t29;
6392
- $[121] !== editorActor || $[122] !== editorEngine ? (t28 = () => {
6358
+ const scrollSelectionIntoViewToEngine = t26;
6359
+ let t27, t28;
6360
+ $[118] !== editorActor || $[119] !== editorEngine ? (t27 = () => {
6393
6361
  const window2 = DOMEditor.getWindow(editorEngine), onDragEnd_0 = () => {
6394
6362
  editorActor.send({
6395
6363
  type: "dragend"
@@ -6402,9 +6370,9 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6402
6370
  return window2.document.addEventListener("dragend", onDragEnd_0), window2.document.addEventListener("drop", onDrop_0), () => {
6403
6371
  window2.document.removeEventListener("dragend", onDragEnd_0), window2.document.removeEventListener("drop", onDrop_0);
6404
6372
  };
6405
- }, t29 = [editorEngine, editorActor], $[121] = editorActor, $[122] = editorEngine, $[123] = t28, $[124] = t29) : (t28 = $[123], t29 = $[124]), useEffect(t28, t29);
6406
- let t30;
6407
- $[125] !== editorActor || $[126] !== editorEngine || $[127] !== onDragStart || $[128] !== readOnly ? (t30 = (event_8) => {
6373
+ }, t28 = [editorEngine, editorActor], $[118] = editorActor, $[119] = editorEngine, $[120] = t27, $[121] = t28) : (t27 = $[120], t28 = $[121]), useEffect(t27, t28);
6374
+ let t29;
6375
+ $[122] !== editorActor || $[123] !== editorEngine || $[124] !== onDragStart || $[125] !== readOnly ? (t29 = (event_8) => {
6408
6376
  if (readOnly || !DOMEditor.hasTarget(editorEngine, event_8.target) || (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped()))
6409
6377
  return;
6410
6378
  const position_4 = getEventPosition({
@@ -6432,10 +6400,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6432
6400
  },
6433
6401
  editor: editorEngine
6434
6402
  }), !0;
6435
- }, $[125] = editorActor, $[126] = editorEngine, $[127] = onDragStart, $[128] = readOnly, $[129] = t30) : t30 = $[129];
6436
- const handleDragStart = t30;
6437
- let t31;
6438
- $[130] !== editorActor || $[131] !== editorEngine || $[132] !== onDrag ? (t31 = (event_9) => {
6403
+ }, $[122] = editorActor, $[123] = editorEngine, $[124] = onDragStart, $[125] = readOnly, $[126] = t29) : t29 = $[126];
6404
+ const handleDragStart = t29;
6405
+ let t30;
6406
+ $[127] !== editorActor || $[128] !== editorEngine || $[129] !== onDrag ? (t30 = (event_9) => {
6439
6407
  if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
6440
6408
  editorActor,
6441
6409
  editorEngine,
@@ -6451,10 +6419,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6451
6419
  },
6452
6420
  editor: editorEngine
6453
6421
  }), !0;
6454
- }, $[130] = editorActor, $[131] = editorEngine, $[132] = onDrag, $[133] = t31) : t31 = $[133];
6455
- const handleDrag = t31;
6456
- let t32;
6457
- $[134] !== editorActor || $[135] !== editorEngine || $[136] !== onDragEnd ? (t32 = (event_10) => {
6422
+ }, $[127] = editorActor, $[128] = editorEngine, $[129] = onDrag, $[130] = t30) : t30 = $[130];
6423
+ const handleDrag = t30;
6424
+ let t31;
6425
+ $[131] !== editorActor || $[132] !== editorEngine || $[133] !== onDragEnd ? (t31 = (event_10) => {
6458
6426
  if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
6459
6427
  return editorActor.send({
6460
6428
  type: "behavior event",
@@ -6466,10 +6434,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6466
6434
  },
6467
6435
  editor: editorEngine
6468
6436
  }), !0;
6469
- }, $[134] = editorActor, $[135] = editorEngine, $[136] = onDragEnd, $[137] = t32) : t32 = $[137];
6470
- const handleDragEnd = t32;
6471
- let t33;
6472
- $[138] !== editorActor || $[139] !== editorEngine || $[140] !== onDragEnter ? (t33 = (event_11) => {
6437
+ }, $[131] = editorActor, $[132] = editorEngine, $[133] = onDragEnd, $[134] = t31) : t31 = $[134];
6438
+ const handleDragEnd = t31;
6439
+ let t32;
6440
+ $[135] !== editorActor || $[136] !== editorEngine || $[137] !== onDragEnter ? (t32 = (event_11) => {
6473
6441
  if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
6474
6442
  return;
6475
6443
  const position_6 = getEventPosition({
@@ -6489,10 +6457,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6489
6457
  },
6490
6458
  editor: editorEngine
6491
6459
  }), !0;
6492
- }, $[138] = editorActor, $[139] = editorEngine, $[140] = onDragEnter, $[141] = t33) : t33 = $[141];
6493
- const handleDragEnter = t33;
6494
- let t34;
6495
- $[142] !== editorActor || $[143] !== editorEngine || $[144] !== onDragOver ? (t34 = (event_12) => {
6460
+ }, $[135] = editorActor, $[136] = editorEngine, $[137] = onDragEnter, $[138] = t32) : t32 = $[138];
6461
+ const handleDragEnter = t32;
6462
+ let t33;
6463
+ $[139] !== editorActor || $[140] !== editorEngine || $[141] !== onDragOver ? (t33 = (event_12) => {
6496
6464
  if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
6497
6465
  return;
6498
6466
  const position_7 = getEventPosition({
@@ -6514,10 +6482,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6514
6482
  editor: editorEngine,
6515
6483
  nativeEvent: event_12
6516
6484
  }), !0;
6517
- }, $[142] = editorActor, $[143] = editorEngine, $[144] = onDragOver, $[145] = t34) : t34 = $[145];
6518
- const handleDragOver = t34;
6519
- let t35;
6520
- $[146] !== editorActor || $[147] !== editorEngine || $[148] !== onDrop ? (t35 = (event_13) => {
6485
+ }, $[139] = editorActor, $[140] = editorEngine, $[141] = onDragOver, $[142] = t33) : t33 = $[142];
6486
+ const handleDragOver = t33;
6487
+ let t34;
6488
+ $[143] !== editorActor || $[144] !== editorEngine || $[145] !== onDrop ? (t34 = (event_13) => {
6521
6489
  if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
6522
6490
  return;
6523
6491
  const position_8 = getEventPosition({
@@ -6542,10 +6510,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6542
6510
  editor: editorEngine,
6543
6511
  nativeEvent: event_13
6544
6512
  }), !0;
6545
- }, $[146] = editorActor, $[147] = editorEngine, $[148] = onDrop, $[149] = t35) : t35 = $[149];
6546
- const handleDrop = t35;
6547
- let t36;
6548
- $[150] !== editorActor || $[151] !== editorEngine || $[152] !== onDragLeave ? (t36 = (event_14) => {
6513
+ }, $[143] = editorActor, $[144] = editorEngine, $[145] = onDrop, $[146] = t34) : t34 = $[146];
6514
+ const handleDrop = t34;
6515
+ let t35;
6516
+ $[147] !== editorActor || $[148] !== editorEngine || $[149] !== onDragLeave ? (t35 = (event_14) => {
6549
6517
  if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
6550
6518
  editorActor,
6551
6519
  editorEngine,
@@ -6561,10 +6529,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6561
6529
  },
6562
6530
  editor: editorEngine
6563
6531
  }), !0;
6564
- }, $[150] = editorActor, $[151] = editorEngine, $[152] = onDragLeave, $[153] = t36) : t36 = $[153];
6565
- const handleDragLeave = t36;
6566
- let t37;
6567
- $[154] !== forwardedRef || $[155] !== validateSelectionActor ? (t37 = (editorElement) => {
6532
+ }, $[147] = editorActor, $[148] = editorEngine, $[149] = onDragLeave, $[150] = t35) : t35 = $[150];
6533
+ const handleDragLeave = t35;
6534
+ let t36;
6535
+ $[151] !== forwardedRef || $[152] !== validateSelectionActor ? (t36 = (editorElement) => {
6568
6536
  if (typeof forwardedRef == "function" ? forwardedRef(editorElement) : forwardedRef && (forwardedRef.current = editorElement), editorElement) {
6569
6537
  const mutationObserver = new MutationObserver(() => {
6570
6538
  validateSelectionActor.send({
@@ -6582,12 +6550,12 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6582
6550
  mutationObserver.disconnect();
6583
6551
  };
6584
6552
  }
6585
- }, $[154] = forwardedRef, $[155] = validateSelectionActor, $[156] = t37) : t37 = $[156];
6586
- const callbackRef = t37;
6553
+ }, $[151] = forwardedRef, $[152] = validateSelectionActor, $[153] = t36) : t36 = $[153];
6554
+ const callbackRef = t36;
6587
6555
  if (!portableTextEditor)
6588
6556
  return null;
6589
- let t38;
6590
- return $[157] !== callbackRef || $[158] !== decorate || $[159] !== editorActor || $[160] !== handleClick || $[161] !== handleCopy || $[162] !== handleCut || $[163] !== handleDrag || $[164] !== handleDragEnd || $[165] !== handleDragEnter || $[166] !== handleDragLeave || $[167] !== handleDragOver || $[168] !== handleDragStart || $[169] !== handleDrop || $[170] !== handleKeyDown || $[171] !== handleKeyUp || $[172] !== handleOnBeforeInput || $[173] !== handleOnBlur || $[174] !== handleOnFocus || $[175] !== handlePaste || $[176] !== hasInvalidValue || $[177] !== readOnly || $[178] !== renderElement || $[179] !== renderLeaf || $[180] !== restProps || $[181] !== scrollSelectionIntoViewToEngine ? (t38 = hasInvalidValue ? null : /* @__PURE__ */ jsx(SelectionStateProvider, { children: /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, editorActor, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToEngine }) }), $[157] = callbackRef, $[158] = decorate, $[159] = editorActor, $[160] = handleClick, $[161] = handleCopy, $[162] = handleCut, $[163] = handleDrag, $[164] = handleDragEnd, $[165] = handleDragEnter, $[166] = handleDragLeave, $[167] = handleDragOver, $[168] = handleDragStart, $[169] = handleDrop, $[170] = handleKeyDown, $[171] = handleKeyUp, $[172] = handleOnBeforeInput, $[173] = handleOnBlur, $[174] = handleOnFocus, $[175] = handlePaste, $[176] = hasInvalidValue, $[177] = readOnly, $[178] = renderElement, $[179] = renderLeaf, $[180] = restProps, $[181] = scrollSelectionIntoViewToEngine, $[182] = t38) : t38 = $[182], t38;
6557
+ let t37;
6558
+ return $[154] !== callbackRef || $[155] !== decorate || $[156] !== editorActor || $[157] !== handleClick || $[158] !== handleCopy || $[159] !== handleCut || $[160] !== handleDrag || $[161] !== handleDragEnd || $[162] !== handleDragEnter || $[163] !== handleDragLeave || $[164] !== handleDragOver || $[165] !== handleDragStart || $[166] !== handleDrop || $[167] !== handleKeyDown || $[168] !== handleKeyUp || $[169] !== handleOnBeforeInput || $[170] !== handleOnBlur || $[171] !== handleOnFocus || $[172] !== handlePaste || $[173] !== hasInvalidValue || $[174] !== readOnly || $[175] !== renderElement || $[176] !== renderLeaf || $[177] !== restProps || $[178] !== scrollSelectionIntoViewToEngine ? (t37 = hasInvalidValue ? null : /* @__PURE__ */ jsx(SelectionStateProvider, { children: /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, editorActor, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToEngine }) }), $[154] = callbackRef, $[155] = decorate, $[156] = editorActor, $[157] = handleClick, $[158] = handleCopy, $[159] = handleCut, $[160] = handleDrag, $[161] = handleDragEnd, $[162] = handleDragEnter, $[163] = handleDragLeave, $[164] = handleDragOver, $[165] = handleDragStart, $[166] = handleDrop, $[167] = handleKeyDown, $[168] = handleKeyUp, $[169] = handleOnBeforeInput, $[170] = handleOnBlur, $[171] = handleOnFocus, $[172] = handlePaste, $[173] = hasInvalidValue, $[174] = readOnly, $[175] = renderElement, $[176] = renderLeaf, $[177] = restProps, $[178] = scrollSelectionIntoViewToEngine, $[179] = t37) : t37 = $[179], t37;
6591
6559
  });
6592
6560
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
6593
6561
  function noop() {
@@ -6993,17 +6961,11 @@ function createEditableAPI(editor, editorActor) {
6993
6961
  });
6994
6962
  },
6995
6963
  isMarkActive: (mark) => {
6996
- const snapshot = getEditorSnapshot({
6997
- editorActorSnapshot: editorActor.getSnapshot(),
6998
- editorEngineInstance: editor
6999
- });
6964
+ const snapshot = editor.snapshot;
7000
6965
  return getActiveDecorators(snapshot).includes(mark);
7001
6966
  },
7002
6967
  marks: () => {
7003
- const snapshot = getEditorSnapshot({
7004
- editorActorSnapshot: editorActor.getSnapshot(),
7005
- editorEngineInstance: editor
7006
- }), activeAnnotations = getActiveAnnotationsMarks(snapshot), activeDecorators = getActiveDecorators(snapshot);
6968
+ const snapshot = editor.snapshot, activeAnnotations = getActiveAnnotationsMarks(snapshot), activeDecorators = getActiveDecorators(snapshot);
7007
6969
  return [...activeAnnotations, ...activeDecorators];
7008
6970
  },
7009
6971
  undo: () => {
@@ -7093,7 +7055,7 @@ function createEditableAPI(editor, editorActor) {
7093
7055
  }
7094
7056
  },
7095
7057
  isVoid: (element) => {
7096
- const schema = editorActor.getSnapshot().context.schema;
7058
+ const schema = editor.schema;
7097
7059
  return ![schema.block.name, schema.span.name].includes(element._type);
7098
7060
  },
7099
7061
  findByPath: (path2) => {
@@ -7142,17 +7104,11 @@ function createEditableAPI(editor, editorActor) {
7142
7104
  }
7143
7105
  },
7144
7106
  isAnnotationActive: (annotationType) => {
7145
- const snapshot = getEditorSnapshot({
7146
- editorActorSnapshot: editorActor.getSnapshot(),
7147
- editorEngineInstance: editor
7148
- });
7107
+ const snapshot = editor.snapshot;
7149
7108
  return isActiveAnnotation(annotationType)(snapshot);
7150
7109
  },
7151
7110
  addAnnotation: (type, value) => {
7152
- const snapshotBefore = getEditorSnapshot({
7153
- editorActorSnapshot: editorActor.getSnapshot(),
7154
- editorEngineInstance: editor
7155
- }), selectedValueBefore = getSelectedValue(snapshotBefore), focusSpanBefore = getFocusSpan(snapshotBefore), markDefsBefore = selectedValueBefore.flatMap((block) => isTextBlock(snapshotBefore.context, block) ? block.markDefs ?? [] : []);
7111
+ const snapshotBefore = editor.snapshot, selectedValueBefore = getSelectedValue(snapshotBefore), focusSpanBefore = getFocusSpan(snapshotBefore), markDefsBefore = selectedValueBefore.flatMap((block) => isTextBlock(snapshotBefore.context, block) ? block.markDefs ?? [] : []);
7156
7112
  editorActor.send({
7157
7113
  type: "behavior event",
7158
7114
  behaviorEvent: {
@@ -7164,10 +7120,7 @@ function createEditableAPI(editor, editorActor) {
7164
7120
  },
7165
7121
  editor
7166
7122
  });
7167
- const snapshotAfter = getEditorSnapshot({
7168
- editorActorSnapshot: editorActor.getSnapshot(),
7169
- editorEngineInstance: editor
7170
- }), selectedValueAfter = getSelectedValue(snapshotAfter), focusBlockAfter = getFocusBlock(snapshotAfter), focusSpanAfter = getFocusSpan(snapshotAfter), focusSpanDecorators = focusSpanAfter ? getPathSubSchema(snapshotAfter, focusSpanAfter.path).decorators.map((decorator) => decorator.name) : snapshotAfter.context.schema.decorators.map((decorator) => decorator.name), newMarkDefKeysOnFocusSpan = focusSpanAfter?.node.marks?.filter((mark) => !focusSpanBefore?.node.marks?.includes(mark) && !focusSpanDecorators.includes(mark)), markDefs = selectedValueAfter.flatMap((block) => isTextBlock(snapshotAfter.context, block) ? block.markDefs?.map((markDef2) => ({
7123
+ const snapshotAfter = editor.snapshot, selectedValueAfter = getSelectedValue(snapshotAfter), focusBlockAfter = getFocusBlock(snapshotAfter), focusSpanAfter = getFocusSpan(snapshotAfter), focusSpanDecorators = focusSpanAfter ? getPathSubSchema(snapshotAfter, focusSpanAfter.path).decorators.map((decorator) => decorator.name) : snapshotAfter.context.schema.decorators.map((decorator) => decorator.name), newMarkDefKeysOnFocusSpan = focusSpanAfter?.node.marks?.filter((mark) => !focusSpanBefore?.node.marks?.includes(mark) && !focusSpanDecorators.includes(mark)), markDefs = selectedValueAfter.flatMap((block) => isTextBlock(snapshotAfter.context, block) ? block.markDefs?.map((markDef2) => ({
7171
7124
  markDef: markDef2,
7172
7125
  path: [{
7173
7126
  _key: block._key
@@ -7219,10 +7172,7 @@ function createEditableAPI(editor, editorActor) {
7219
7172
  });
7220
7173
  },
7221
7174
  getFragment: () => {
7222
- const snapshot = getEditorSnapshot({
7223
- editorActorSnapshot: editorActor.getSnapshot(),
7224
- editorEngineInstance: editor
7225
- });
7175
+ const snapshot = editor.snapshot;
7226
7176
  return getFragment(snapshot).map((entry) => entry.node);
7227
7177
  },
7228
7178
  isSelectionsOverlapping: (selectionA, selectionB) => !selectionA || !selectionB ? !1 : rangeIncludes(selectionA, selectionB, editor)
@@ -10391,56 +10341,43 @@ const shouldNormalize = (_editor, {
10391
10341
  onContextChange && onContextChange(options), onChange(options);
10392
10342
  }, e;
10393
10343
  };
10394
- function buildPublicContainers(resolved) {
10395
- const projected = /* @__PURE__ */ new Map();
10396
- for (const [type, config] of resolved)
10397
- projected.set(type, toRegisteredContainer(config));
10398
- return projected;
10344
+ function defaultCompare(a, b) {
10345
+ return a === b;
10399
10346
  }
10400
- function toRegisteredContainer(config) {
10347
+ function useEditorSelector(editor, selector, t0) {
10348
+ return useSelector(editor, selector, t0 === void 0 ? defaultCompare : t0);
10349
+ }
10350
+ function getEditorSnapshot({
10351
+ editorEngineInstance
10352
+ }) {
10401
10353
  return {
10402
- kind: "container",
10403
- type: config.container.type,
10404
- field: config.field,
10405
- ...config.of ? {
10406
- of: config.of.map(toRegisteredOfEntry).filter(isDefined)
10407
- } : {}
10354
+ blockIndexMap: editorEngineInstance.blockIndexMap,
10355
+ context: {
10356
+ containers: editorEngineInstance.publicContainers,
10357
+ converters: editorEngineInstance.converters,
10358
+ keyGenerator: editorEngineInstance.keyGenerator,
10359
+ readOnly: editorEngineInstance.readOnly,
10360
+ schema: editorEngineInstance.schema,
10361
+ selection: editorEngineInstance.selection,
10362
+ value: editorEngineInstance.children
10363
+ },
10364
+ decoratorState: editorEngineInstance.decoratorState
10408
10365
  };
10409
10366
  }
10410
- function toRegisteredOfEntry(entry) {
10411
- if ("container" in entry)
10412
- return toRegisteredContainer(entry);
10413
- if ("span" in entry)
10414
- return {
10415
- kind: "span",
10416
- type: entry.span.type
10417
- };
10418
- if ("blockObject" in entry)
10419
- return {
10420
- kind: "blockObject",
10421
- type: entry.blockObject.type
10422
- };
10423
- if ("inlineObject" in entry)
10424
- return {
10425
- kind: "inlineObject",
10426
- type: entry.inlineObject.type
10427
- };
10428
- }
10429
- function isDefined(value) {
10430
- return value !== void 0;
10431
- }
10432
10367
  function createEditorEngine(config) {
10433
10368
  debug.setup("creating new editor engine instance");
10434
10369
  const context = config.editorActor.getSnapshot().context, placeholderBlock = createPlaceholderBlock({
10435
10370
  context: {
10436
10371
  schema: context.schema,
10437
- containers: buildPublicContainers(context.containers),
10372
+ // No containers registered at engine-init time. NodePlugin
10373
+ // registrations run later, after the engine is attached.
10374
+ containers: /* @__PURE__ */ new Map(),
10438
10375
  value: [],
10439
10376
  keyGenerator: context.keyGenerator
10440
10377
  },
10441
10378
  blockIndexMap: /* @__PURE__ */ new Map()
10442
10379
  }), editor = createEditor();
10443
- editor.schema = context.schema, editor.keyGenerator = context.keyGenerator, editor.containers = /* @__PURE__ */ new Map(), editor.publicContainers = /* @__PURE__ */ new Map(), editor.blockObjects = /* @__PURE__ */ new Map(), editor.inlineObjects = /* @__PURE__ */ new Map(), editor.spans = /* @__PURE__ */ new Map(), editor.textBlocks = /* @__PURE__ */ new Map(), editor.decoratedRanges = [], editor.decoratorState = {}, editor.blockIndexMap = /* @__PURE__ */ new Map(), editor.history = {
10380
+ editor.schema = context.schema, editor.keyGenerator = context.keyGenerator, editor.converters = context.initialConverters, editor.readOnly = context.initialReadOnly, editor.containers = /* @__PURE__ */ new Map(), editor.publicContainers = /* @__PURE__ */ new Map(), editor.blockObjects = /* @__PURE__ */ new Map(), editor.inlineObjects = /* @__PURE__ */ new Map(), editor.spans = /* @__PURE__ */ new Map(), editor.textBlocks = /* @__PURE__ */ new Map(), editor.decoratedRanges = [], editor.decoratorState = {}, editor.blockIndexMap = /* @__PURE__ */ new Map(), editor.history = {
10444
10381
  undos: [],
10445
10382
  redos: []
10446
10383
  }, editor.listIndexMap = /* @__PURE__ */ new Map(), editor.remotePatches = [], editor.undoStepId = void 0, editor.children = [placeholderBlock], editor.isDeferringMutations = !1, editor.isNormalizingNode = !1, editor.isPatching = !0, editor.isPerformingBehaviorOperation = !1, editor.isProcessingRemoteChanges = !1, editor.isRedoing = !1, editor.isUndoing = !1, editor.withHistory = !0;
@@ -10455,6 +10392,17 @@ function createEditorEngine(config) {
10455
10392
  }, {
10456
10393
  blockIndexMap: editorEngine.blockIndexMap,
10457
10394
  listIndexMap: editorEngine.listIndexMap
10395
+ }), editorEngine.snapshot = getEditorSnapshot({
10396
+ editorEngineInstance: editorEngine
10397
+ }), config.subscriptions.push(() => {
10398
+ const subscription = config.editorActor.subscribe(() => {
10399
+ editorEngine.snapshot = getEditorSnapshot({
10400
+ editorEngineInstance: editorEngine
10401
+ });
10402
+ });
10403
+ return () => {
10404
+ subscription.unsubscribe();
10405
+ };
10458
10406
  }), editorEngine;
10459
10407
  }
10460
10408
  function createEditorDom(sendBack, editorEngine) {
@@ -16191,6 +16139,51 @@ function sortByPriority(items) {
16191
16139
  result.includes(item) || result.push(item);
16192
16140
  return [...result, ...itemsWithoutPriority];
16193
16141
  }
16142
+ function pathsOverlap(pathA, pathB) {
16143
+ const minLength = Math.min(pathA.length, pathB.length);
16144
+ for (let i = 0; i < minLength; i++)
16145
+ if (!isEqualPathSegments(pathA[i], pathB[i]))
16146
+ return !1;
16147
+ return !0;
16148
+ }
16149
+ function buildPublicContainers(resolved) {
16150
+ const projected = /* @__PURE__ */ new Map();
16151
+ for (const [type, config] of resolved)
16152
+ projected.set(type, toRegisteredContainer(config));
16153
+ return projected;
16154
+ }
16155
+ function toRegisteredContainer(config) {
16156
+ return {
16157
+ kind: "container",
16158
+ type: config.container.type,
16159
+ field: config.field,
16160
+ ...config.of ? {
16161
+ of: config.of.map(toRegisteredOfEntry).filter(isDefined)
16162
+ } : {}
16163
+ };
16164
+ }
16165
+ function toRegisteredOfEntry(entry) {
16166
+ if ("container" in entry)
16167
+ return toRegisteredContainer(entry);
16168
+ if ("span" in entry)
16169
+ return {
16170
+ kind: "span",
16171
+ type: entry.span.type
16172
+ };
16173
+ if ("blockObject" in entry)
16174
+ return {
16175
+ kind: "blockObject",
16176
+ type: entry.blockObject.type
16177
+ };
16178
+ if ("inlineObject" in entry)
16179
+ return {
16180
+ kind: "inlineObject",
16181
+ type: entry.inlineObject.type
16182
+ };
16183
+ }
16184
+ function isDefined(value) {
16185
+ return value !== void 0;
16186
+ }
16194
16187
  const PRIMITIVE_TYPES = /* @__PURE__ */ new Set(["string", "number", "boolean"]);
16195
16188
  function isChildArrayField(field) {
16196
16189
  return field.type === "array" && "of" in field && Array.isArray(field.of);
@@ -16299,13 +16292,6 @@ function resolveTextBlockConfig(textBlock) {
16299
16292
  } : {}
16300
16293
  };
16301
16294
  }
16302
- function pathsOverlap(pathA, pathB) {
16303
- const minLength = Math.min(pathA.length, pathB.length);
16304
- for (let i = 0; i < minLength; i++)
16305
- if (!isEqualPathSegments(pathA[i], pathB[i]))
16306
- return !1;
16307
- return !0;
16308
- }
16309
16295
  function isTypeAlreadyRegistered(maps, attempting, type) {
16310
16296
  const claimedAs = (kind) => {
16311
16297
  switch (kind) {
@@ -16333,6 +16319,77 @@ function isTypeAlreadyRegistered(maps, attempting, type) {
16333
16319
  }
16334
16320
  return !1;
16335
16321
  }
16322
+ function registerNodeOnEngine(engine, node) {
16323
+ if (node.kind === "container") {
16324
+ if (isTypeAlreadyRegistered(engine, "container", node.type))
16325
+ return;
16326
+ const containerConfig = resolveNestedContainer(engine.schema, node);
16327
+ if (!containerConfig)
16328
+ return;
16329
+ const containers = new Map(engine.containers);
16330
+ containers.set(node.type, containerConfig), engine.containers = containers, engine.publicContainers = buildPublicContainers(containers), normalize(engine, {
16331
+ force: !0
16332
+ }), engine.onChange();
16333
+ return;
16334
+ }
16335
+ if (node.kind === "textBlock") {
16336
+ if (isTypeAlreadyRegistered(engine, "textBlock", node.type))
16337
+ return;
16338
+ const textBlocks = new Map(engine.textBlocks);
16339
+ textBlocks.set(node.type, resolveTextBlockConfig(node)), engine.textBlocks = textBlocks, engine.onChange();
16340
+ return;
16341
+ }
16342
+ if (node.kind === "span") {
16343
+ if (isTypeAlreadyRegistered(engine, "span", node.type))
16344
+ return;
16345
+ const spans = new Map(engine.spans);
16346
+ spans.set(node.type, {
16347
+ span: node
16348
+ }), engine.spans = spans, engine.onChange();
16349
+ return;
16350
+ }
16351
+ if (node.kind === "blockObject") {
16352
+ if (isTypeAlreadyRegistered(engine, "blockObject", node.type))
16353
+ return;
16354
+ const blockObjects = new Map(engine.blockObjects);
16355
+ blockObjects.set(node.type, {
16356
+ blockObject: node
16357
+ }), engine.blockObjects = blockObjects, engine.onChange();
16358
+ return;
16359
+ }
16360
+ if (isTypeAlreadyRegistered(engine, "inlineObject", node.type))
16361
+ return;
16362
+ const inlineObjects = new Map(engine.inlineObjects);
16363
+ inlineObjects.set(node.type, {
16364
+ inlineObject: node
16365
+ }), engine.inlineObjects = inlineObjects, engine.onChange();
16366
+ }
16367
+ function unregisterNodeOnEngine(engine, node) {
16368
+ if (node.kind === "container") {
16369
+ const containers = new Map(engine.containers);
16370
+ containers.delete(node.type), engine.containers = containers, engine.publicContainers = buildPublicContainers(containers), normalize(engine, {
16371
+ force: !0
16372
+ }), engine.onChange();
16373
+ return;
16374
+ }
16375
+ if (node.kind === "textBlock") {
16376
+ const textBlocks = new Map(engine.textBlocks);
16377
+ textBlocks.delete(node.type), engine.textBlocks = textBlocks, engine.onChange();
16378
+ return;
16379
+ }
16380
+ if (node.kind === "span") {
16381
+ const spans = new Map(engine.spans);
16382
+ spans.delete(node.type), engine.spans = spans, engine.onChange();
16383
+ return;
16384
+ }
16385
+ if (node.kind === "blockObject") {
16386
+ const blockObjects = new Map(engine.blockObjects);
16387
+ blockObjects.delete(node.type), engine.blockObjects = blockObjects, engine.onChange();
16388
+ return;
16389
+ }
16390
+ const inlineObjects = new Map(engine.inlineObjects);
16391
+ inlineObjects.delete(node.type), engine.inlineObjects = inlineObjects, engine.onChange();
16392
+ }
16336
16393
  function rerouteExternalBehaviorEvent({
16337
16394
  event,
16338
16395
  editorEngine
@@ -16397,105 +16454,38 @@ const editorMachine = setup({
16397
16454
  event
16398
16455
  }) => event.type === "add editor engine" ? event.editor : context.editorEngine
16399
16456
  }),
16400
- register: assign(({
16457
+ register: ({
16401
16458
  context,
16402
16459
  event
16403
16460
  }) => {
16404
- assertEvent(event, "register");
16405
- const node = event.node;
16406
- if (node.kind === "container") {
16407
- if (isTypeAlreadyRegistered(context, "container", node.type))
16408
- return {};
16409
- const containerConfig = resolveNestedContainer(context.schema, node);
16410
- if (!containerConfig)
16411
- return {};
16412
- const containers = new Map(context.containers);
16413
- return containers.set(node.type, containerConfig), context.editorEngine && (context.editorEngine.containers = containers, context.editorEngine.publicContainers = buildPublicContainers(containers), normalize(context.editorEngine, {
16414
- force: !0
16415
- }), context.editorEngine.onChange()), {
16416
- containers
16417
- };
16418
- }
16419
- if (node.kind === "textBlock") {
16420
- if (isTypeAlreadyRegistered(context, "textBlock", node.type))
16421
- return {};
16422
- const textBlocks = new Map(context.textBlocks);
16423
- return textBlocks.set(node.type, resolveTextBlockConfig(node)), context.editorEngine && (context.editorEngine.textBlocks = textBlocks, context.editorEngine.onChange()), {
16424
- textBlocks
16425
- };
16426
- }
16427
- if (node.kind === "span") {
16428
- if (isTypeAlreadyRegistered(context, "span", node.type))
16429
- return {};
16430
- const spans = new Map(context.spans);
16431
- return spans.set(node.type, {
16432
- span: node
16433
- }), context.editorEngine && (context.editorEngine.spans = spans, context.editorEngine.onChange()), {
16434
- spans
16435
- };
16436
- }
16437
- if (node.kind === "blockObject") {
16438
- if (isTypeAlreadyRegistered(context, "blockObject", node.type))
16439
- return {};
16440
- const blockObjects = new Map(context.blockObjects);
16441
- return blockObjects.set(node.type, {
16442
- blockObject: node
16443
- }), context.editorEngine && (context.editorEngine.blockObjects = blockObjects, context.editorEngine.onChange()), {
16444
- blockObjects
16445
- };
16461
+ if (assertEvent(event, "register"), !context.editorEngine) {
16462
+ context.pendingRegistrations.push(event.node);
16463
+ return;
16446
16464
  }
16447
- if (isTypeAlreadyRegistered(context, "inlineObject", node.type))
16448
- return {};
16449
- const inlineObjects = new Map(context.inlineObjects);
16450
- return inlineObjects.set(node.type, {
16451
- inlineObject: node
16452
- }), context.editorEngine && (context.editorEngine.inlineObjects = inlineObjects, context.editorEngine.onChange()), {
16453
- inlineObjects
16454
- };
16455
- }),
16456
- unregister: assign(({
16465
+ registerNodeOnEngine(context.editorEngine, event.node);
16466
+ },
16467
+ unregister: ({
16457
16468
  context,
16458
16469
  event
16459
16470
  }) => {
16460
- assertEvent(event, "unregister");
16461
- const node = event.node;
16462
- if (node.kind === "container") {
16463
- const containers = new Map(context.containers);
16464
- return containers.delete(node.type), context.editorEngine && (context.editorEngine.containers = containers, context.editorEngine.publicContainers = buildPublicContainers(containers), normalize(context.editorEngine, {
16465
- force: !0
16466
- }), context.editorEngine.onChange()), {
16467
- containers
16468
- };
16469
- }
16470
- if (node.kind === "textBlock") {
16471
- const textBlocks = new Map(context.textBlocks);
16472
- return textBlocks.delete(node.type), context.editorEngine && (context.editorEngine.textBlocks = textBlocks, context.editorEngine.onChange()), {
16473
- textBlocks
16474
- };
16475
- }
16476
- if (node.kind === "span") {
16477
- const spans = new Map(context.spans);
16478
- return spans.delete(node.type), context.editorEngine && (context.editorEngine.spans = spans, context.editorEngine.onChange()), {
16479
- spans
16480
- };
16481
- }
16482
- if (node.kind === "blockObject") {
16483
- const blockObjects = new Map(context.blockObjects);
16484
- return blockObjects.delete(node.type), context.editorEngine && (context.editorEngine.blockObjects = blockObjects, context.editorEngine.onChange()), {
16485
- blockObjects
16486
- };
16471
+ if (assertEvent(event, "unregister"), !context.editorEngine) {
16472
+ const index = context.pendingRegistrations.indexOf(event.node);
16473
+ index >= 0 && context.pendingRegistrations.splice(index, 1);
16474
+ return;
16487
16475
  }
16488
- const inlineObjects = new Map(context.inlineObjects);
16489
- return inlineObjects.delete(node.type), context.editorEngine && (context.editorEngine.inlineObjects = inlineObjects, context.editorEngine.onChange()), {
16490
- inlineObjects
16491
- };
16492
- }),
16476
+ unregisterNodeOnEngine(context.editorEngine, event.node);
16477
+ },
16493
16478
  "attach maps to editor engine": ({
16494
16479
  context
16495
16480
  }) => {
16496
- context.editorEngine && (context.editorEngine.containers = context.containers, context.editorEngine.publicContainers = buildPublicContainers(context.containers), context.editorEngine.blockObjects = context.blockObjects, context.editorEngine.inlineObjects = context.inlineObjects, context.editorEngine.spans = context.spans, context.editorEngine.textBlocks = context.textBlocks, normalize(context.editorEngine, {
16481
+ if (!context.editorEngine)
16482
+ return;
16483
+ const engine = context.editorEngine;
16484
+ for (const node of context.pendingRegistrations)
16485
+ registerNodeOnEngine(engine, node);
16486
+ context.pendingRegistrations.length = 0, normalize(engine, {
16497
16487
  force: !0
16498
- }), context.editorEngine.onChange());
16488
+ }), engine.onChange();
16499
16489
  },
16500
16490
  "emit patch event": emit(({
16501
16491
  event
@@ -16503,11 +16493,21 @@ const editorMachine = setup({
16503
16493
  "emit mutation event": emit(({
16504
16494
  event
16505
16495
  }) => (assertEvent(event, "mutation"), event)),
16506
- "emit read only": emit({
16507
- type: "read only"
16496
+ "emit read only": enqueueActions(({
16497
+ context,
16498
+ enqueue
16499
+ }) => {
16500
+ context.editorEngine && (context.editorEngine.readOnly = !0, context.editorEngine.onChange()), enqueue.emit({
16501
+ type: "read only"
16502
+ });
16508
16503
  }),
16509
- "emit editable": emit({
16510
- type: "editable"
16504
+ "emit editable": enqueueActions(({
16505
+ context,
16506
+ enqueue
16507
+ }) => {
16508
+ context.editorEngine && (context.editorEngine.readOnly = !1, context.editorEngine.onChange()), enqueue.emit({
16509
+ type: "editable"
16510
+ });
16511
16511
  }),
16512
16512
  "defer event": assign({
16513
16513
  pendingEvents: ({
@@ -16597,12 +16597,10 @@ const editorMachine = setup({
16597
16597
  remainingEventBehaviors: behaviors,
16598
16598
  event: event.behaviorEvent,
16599
16599
  editor: event.editor,
16600
- converters: context.converters,
16601
- keyGenerator: context.keyGenerator,
16602
- schema: context.schema,
16603
- readOnly: self.getSnapshot().matches({
16604
- "edit mode": "read only"
16605
- }),
16600
+ converters: event.editor.converters,
16601
+ keyGenerator: event.editor.keyGenerator,
16602
+ schema: event.editor.schema,
16603
+ readOnly: event.editor.readOnly,
16606
16604
  nativeEvent: event.nativeEvent,
16607
16605
  sendBack: (eventSentBack) => {
16608
16606
  if (eventSentBack.type === "set drag ghost") {
@@ -16641,17 +16639,12 @@ const editorMachine = setup({
16641
16639
  }) => ({
16642
16640
  behaviors: new Set(coreBehaviorsConfig),
16643
16641
  behaviorsSorted: !1,
16644
- containers: /* @__PURE__ */ new Map(),
16645
- blockObjects: /* @__PURE__ */ new Map(),
16646
- inlineObjects: /* @__PURE__ */ new Map(),
16647
- spans: /* @__PURE__ */ new Map(),
16648
- textBlocks: /* @__PURE__ */ new Map(),
16649
- converters: input.converters ?? [],
16642
+ initialConverters: input.converters ?? [],
16650
16643
  keyGenerator: input.keyGenerator,
16651
16644
  pendingEvents: [],
16652
16645
  pendingIncomingPatchesEvents: [],
16646
+ pendingRegistrations: [],
16653
16647
  schema: input.schema,
16654
- selection: null,
16655
16648
  initialReadOnly: input.readOnly ?? !1,
16656
16649
  initialValue: input.initialValue
16657
16650
  }),
@@ -16672,11 +16665,7 @@ const editorMachine = setup({
16672
16665
  actions: ["unregister"]
16673
16666
  },
16674
16667
  "update selection": {
16675
- actions: [assign({
16676
- selection: ({
16677
- event
16678
- }) => event.selection
16679
- }), emit(({
16668
+ actions: [emit(({
16680
16669
  event
16681
16670
  }) => ({
16682
16671
  ...event,
@@ -18284,10 +18273,7 @@ function createInternalEditor(config) {
18284
18273
  subscriptions
18285
18274
  }), editor = {
18286
18275
  dom: createEditorDom((event) => editorActor.send(event), editorEngine),
18287
- getSnapshot: () => getEditorSnapshot({
18288
- editorActorSnapshot: editorActor.getSnapshot(),
18289
- editorEngineInstance: editorEngine
18290
- }),
18276
+ getSnapshot: () => editorEngine.snapshot,
18291
18277
  registerBehavior: (behaviorConfig) => {
18292
18278
  const priority = createEditorPriority({
18293
18279
  name: "custom",
@@ -18914,12 +18900,9 @@ function EditorProvider(props) {
18914
18900
  return $[23] !== internalEditor_0.editor || $[24] !== t7 ? (t8 = /* @__PURE__ */ jsx(EditorContext$1.Provider, { value: internalEditor_0.editor, children: t7 }), $[23] = internalEditor_0.editor, $[24] = t7, $[25] = t8) : t8 = $[25], t8;
18915
18901
  }
18916
18902
  const usePortableTextEditorSelection = () => {
18917
- const $ = c(5), editorActor = useContext(EditorActorContext);
18918
- let t0;
18919
- $[0] !== editorActor ? (t0 = editorActor.getSnapshot(), $[0] = editorActor, $[1] = t0) : t0 = $[1];
18920
- const [selection, setSelection2] = useState(t0.context.selection);
18921
- let t1, t2;
18922
- return $[2] !== editorActor ? (t1 = () => {
18903
+ const $ = c(3), editorActor = useContext(EditorActorContext), editorEngine = useEngineStatic(), [selection, setSelection2] = useState(editorEngine.selection);
18904
+ let t0, t1;
18905
+ return $[0] !== editorActor ? (t0 = () => {
18923
18906
  const subscription = editorActor.on("selection", (event) => {
18924
18907
  startTransition(() => {
18925
18908
  setSelection2(event.selection);
@@ -18928,7 +18911,7 @@ const usePortableTextEditorSelection = () => {
18928
18911
  return () => {
18929
18912
  subscription.unsubscribe();
18930
18913
  };
18931
- }, t2 = [editorActor], $[2] = editorActor, $[3] = t1, $[4] = t2) : (t1 = $[3], t2 = $[4]), useEffect(t1, t2), selection;
18914
+ }, t1 = [editorActor], $[0] = editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1), selection;
18932
18915
  };
18933
18916
  function defineContainer(config) {
18934
18917
  return {