@portabletext/editor 7.1.1 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -3,14 +3,14 @@ import { c } from "react/compiler-runtime";
3
3
  import { useSelector, useActorRef } from "@xstate/react";
4
4
  import React, { createContext, useContext, useRef, useEffect, useLayoutEffect, useState, useReducer, useCallback, memo, forwardRef, useMemo, Component, useSyncExternalStore, startTransition } from "react";
5
5
  import { isKeyedSegment, getNode, getParent, parentPath, getChildren, getNodeChildren } from "./_chunks-es/get-parent.js";
6
- import { getLeaf, isLeafObject, getAncestor, getSpan, getText, getTextBlock, getUnionSchema, getFirstChild } from "./_chunks-es/get-first-child.js";
7
- import { isTextBlockNode, hasNode, getNodes, isAncestorPath, isEditableContainer, getSibling, isInline, isObject as isObject$1, isSpanNode, isBlock, getEnclosingBlock, getAncestors, getPathSubSchema, getBlock, resolveContainerAt, getEnclosingContainer } from "./_chunks-es/get-path-sub-schema.js";
8
- import { rangeEdges, isBackwardRange, comparePoints, rangesOverlap, isAfterPoint, comparePaths, isSelectionCollapsed as isSelectionCollapsed$1, getFocusInlineObject, getFocusTextBlock, getFocusSpan, getFragment, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, getFocusBlock, getSelectedBlocks, isSelectingEntireBlocks, getSelectedValue, isActiveAnnotation, getActiveAnnotationsMarks, getActiveDecorators, getCaretWordSelection, getSelectionStartChild, getSelectionEndChild, getPreviousSpan, getNextSpan, getSelectionStartPoint, getSelectionEndPoint, getFocusBlockObject, getLastBlock, getFirstBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getMarkState, getFocusListBlock, getNextBlock, getPreviousBlock, getSelectedTextBlocks, getRootAcceptedTypes, isActiveDecorator, getFocusChild, getActiveAnnotations, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
6
+ import { isPath, getLeaf, isRange, isPoint, isObject, isLeafObject, getAncestor, pathContains, getSpan, isBeforePoint, getText, rangeIntersects, getTextBlock, getUnionSchema, getFirstChild } from "./_chunks-es/get-first-child.js";
7
+ import { rangeEdges, isTextBlockNode, isBackwardRange, hasNode, getNodes, isAncestorPath, isEditableContainer, getSibling, isInline, isObject as isObject$1, isSpanNode, isBlock, getEnclosingBlock, getAncestors, getPathSubSchema, getBlock, resolveContainerAt, comparePaths, getEnclosingContainer, comparePoints$1 as comparePoints, isAfterPoint } from "./_chunks-es/get-path-sub-schema.js";
9
8
  import { isSpan, isTextBlock, compileSchema } from "@portabletext/schema";
10
9
  import { defineSchema } from "@portabletext/schema";
11
10
  import scrollIntoView from "scroll-into-view-if-needed";
12
11
  import { createKeyboardShortcut, undo, redo, code, underline, italic as italic$1, bold as bold$1 } from "@portabletext/keyboard-shortcuts";
13
- import { isEqualSelectionPoints, blockOffsetToSpanSelectionPoint, getBlockKeyFromSelectionPoint, getBlockEndPoint, getBlockStartPoint, isSelectionCollapsed, defaultKeyGenerator, parseBlocks, parseBlock, isListBlock, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject, isEqualPathSegments } from "./_chunks-es/util.slice-blocks.js";
12
+ import { rangesOverlap, isSelectionCollapsed as isSelectionCollapsed$1, getFocusInlineObject, getFocusTextBlock, getFocusSpan, getFragment, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, getFocusBlock, getSelectedBlocks, isSelectingEntireBlocks, getSelectedValue, isActiveAnnotation, getActiveAnnotationsMarks, getActiveDecorators, getCaretWordSelection, getSelectionStartChild, getSelectionEndChild, getPreviousSpan, getNextSpan, getSelectionStartPoint, getSelectionEndPoint, getFocusBlockObject, getLastBlock, getFirstBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getMarkState, getFocusListBlock, getNextBlock, getPreviousBlock, getSelectedTextBlocks, getRootAcceptedTypes, isActiveDecorator, getFocusChild, getActiveAnnotations, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
13
+ import { isEqualSelectionPoints, blockOffsetToSpanSelectionPoint, getBlockKeyFromSelectionPoint, getBlockEndPoint, getBlockStartPoint, isSelectionCollapsed, defaultKeyGenerator, parseBlocks, parseBlock, isListBlock, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject } from "./_chunks-es/util.slice-blocks.js";
14
14
  import rawDebug from "debug";
15
15
  import { isEmptyTextBlock, getTextBlockText } from "./_chunks-es/util.is-empty-text-block.js";
16
16
  import { setup, fromCallback, assign, and, assertEvent, enqueueActions, emit, not, raise as raise$1, createActor } from "xstate";
@@ -214,16 +214,6 @@ function commonPath(path2, another) {
214
214
  }
215
215
  return common;
216
216
  }
217
- function isPath(value) {
218
- return Array.isArray(value) && (value.length === 0 || typeof value[0] == "number" || typeof value[0] == "string" || isKeyedSegment(value[0]));
219
- }
220
- const isObject = (value) => typeof value == "object" && value !== null;
221
- function isPoint(value) {
222
- return isObject(value) && typeof value.offset == "number" && isPath(value.path);
223
- }
224
- function isRange(value) {
225
- return isObject(value) && isPoint(value.anchor) && isPoint(value.focus);
226
- }
227
217
  function rangeEnd(range2, root) {
228
218
  const [, end2] = rangeEdges(range2, root);
229
219
  return end2;
@@ -238,12 +228,12 @@ function path(editor, at, options = {}) {
238
228
  edge
239
229
  } = options;
240
230
  if (isPath(at) && (edge === "start" || edge === "end")) {
241
- const leaf = getLeaf(editor, at, {
231
+ const leaf = getLeaf(editor.snapshot, at, {
242
232
  edge
243
233
  });
244
234
  leaf && (at = leaf.path);
245
235
  }
246
- return isRange(at) && (edge === "start" ? at = rangeStart(at, editor) : edge === "end" ? at = rangeEnd(at, editor) : at = commonPath(at.anchor.path, at.focus.path)), isPoint(at) && (at = at.path), depth != null && (at = sliceToNodeDepth(at, depth)), at;
236
+ return isRange(at) && (edge === "start" ? at = rangeStart(at, editor.snapshot.context) : edge === "end" ? at = rangeEnd(at, editor.snapshot.context) : at = commonPath(at.anchor.path, at.focus.path)), isPoint(at) && (at = at.path), depth != null && (at = sliceToNodeDepth(at, depth)), at;
247
237
  }
248
238
  function sliceToNodeDepth(nodePath, depth) {
249
239
  let nodeCount = 0;
@@ -264,7 +254,7 @@ function point(editor, at, options = {}) {
264
254
  } = options;
265
255
  if (isPath(at)) {
266
256
  let path2;
267
- const deepest = getLeaf(editor, at, {
257
+ const deepest = getLeaf(editor.snapshot, at, {
268
258
  edge: edge === "end" ? "end" : "start"
269
259
  });
270
260
  if (!deepest)
@@ -274,16 +264,16 @@ function point(editor, at, options = {}) {
274
264
  path: nodePath
275
265
  } = deepest;
276
266
  if (path2 = nodePath, !isSpan({
277
- schema: editor.schema
267
+ schema: editor.snapshot.context.schema
278
268
  }, node) && !isTextBlockNode({
279
- schema: editor.schema
269
+ schema: editor.snapshot.context.schema
280
270
  }, node) && !isEditor(node))
281
271
  return {
282
272
  path: path2,
283
273
  offset: 0
284
274
  };
285
275
  if (!isSpan({
286
- schema: editor.schema
276
+ schema: editor.snapshot.context.schema
287
277
  }, node))
288
278
  throw new Error(`Cannot get the ${edge} point in the node at path [${at}] because it has no ${edge} text node.`);
289
279
  return {
@@ -292,7 +282,7 @@ function point(editor, at, options = {}) {
292
282
  };
293
283
  }
294
284
  if (isRange(at)) {
295
- const [start2, end2] = rangeEdges(at, editor);
285
+ const [start2, end2] = rangeEdges(at, editor.snapshot.context);
296
286
  return edge === "start" ? start2 : end2;
297
287
  }
298
288
  return at;
@@ -359,14 +349,14 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
359
349
  throw new Error("Cannot resolve a DOM node: editor is not mounted");
360
350
  const root = DOMEditor.findDocumentOrShadowRoot(editor);
361
351
  if (root.activeElement !== el) {
362
- if (editor.selection && root instanceof Document) {
363
- const domSelection = getSelection(root), domRange = DOMEditor.toDOMRange(editor, editor.selection);
352
+ if (editor.snapshot.context.selection && root instanceof Document) {
353
+ const domSelection = getSelection(root), domRange = DOMEditor.toDOMRange(editor, editor.snapshot.context.selection);
364
354
  domSelection?.removeAllRanges(), domSelection?.addRange(domRange);
365
355
  }
366
- if (editor.selection || editor.select(start(editor, [])), editor.focused = !0, el.focus({
356
+ if (editor.snapshot.context.selection || editor.select(start(editor, [])), editor.focused = !0, el.focus({
367
357
  preventScroll: !0
368
- }), editor.selection && root instanceof Document) {
369
- const domSelection = getSelection(root), domRange = DOMEditor.toDOMRange(editor, editor.selection);
358
+ }), editor.snapshot.context.selection && root instanceof Document) {
359
+ const domSelection = getSelection(root), domRange = DOMEditor.toDOMRange(editor, editor.snapshot.context.selection);
370
360
  domSelection?.removeAllRanges(), domSelection?.addRange(domRange);
371
361
  }
372
362
  }
@@ -402,17 +392,17 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
402
392
  anchor,
403
393
  focus
404
394
  } = range2;
405
- return hasNode(editor, anchor.path) && hasNode(editor, focus.path);
395
+ return hasNode(editor.snapshot, anchor.path) && hasNode(editor.snapshot, focus.path);
406
396
  },
407
397
  hasSelectableTarget: (editor, target) => DOMEditor.hasEditableTarget(editor, target) || DOMEditor.isTargetInsideNonReadonlyVoid(editor, target),
408
398
  hasTarget: (editor, target) => isDOMNode(target) && DOMEditor.hasDOMNode(editor, target),
409
399
  isTargetInsideNonReadonlyVoid: (editor, target) => editor.readOnly || !DOMEditor.hasTarget(editor, target) ? !1 : !!(isDOMElement(target) ? target : target.parentElement)?.closest('[data-pt-block="object"], [data-pt-inline="object"]'),
410
400
  toDOMPoint: (editor, point2) => {
411
- const nodeEntry = getNode(editor, point2.path), el = getDomNode(editor, point2.path);
401
+ const nodeEntry = getNode(editor.snapshot, point2.path), el = getDomNode(editor, point2.path);
412
402
  if (!el)
413
403
  throw new Error(`Cannot find a DOM node for editor path: ${point2.path}`);
414
404
  let domPoint;
415
- if (nodeEntry && isLeafObject(editor, nodeEntry.node, point2.path)) {
405
+ if (nodeEntry && isLeafObject(editor.snapshot, nodeEntry.node, point2.path)) {
416
406
  const spacer = el.querySelector("[data-pt-zero-width]");
417
407
  if (spacer) {
418
408
  const domText = spacer.childNodes[0];
@@ -427,10 +417,10 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
427
417
  }
428
418
  return [el, 0];
429
419
  }
430
- const pointPath = path(editor, point2), pointEntry = getNode(editor, pointPath), pointObjectNode = pointEntry && isLeafObject(editor, pointEntry.node, pointPath) ? pointEntry : getAncestor(editor, point2.path, {
431
- match: (node, ancestorPath) => isLeafObject(editor, node, ancestorPath)
420
+ const pointPath = path(editor, point2), pointEntry = getNode(editor.snapshot, pointPath), pointObjectNode = pointEntry && isLeafObject(editor.snapshot, pointEntry.node, pointPath) ? pointEntry : getAncestor(editor.snapshot, point2.path, {
421
+ match: (node, ancestorPath) => isLeafObject(editor.snapshot, node, ancestorPath)
432
422
  });
433
- pointObjectNode && isLeafObject(editor, pointObjectNode.node, pointObjectNode.path) && (point2 = {
423
+ pointObjectNode && isLeafObject(editor.snapshot, pointObjectNode.node, pointObjectNode.path) && (point2 = {
434
424
  path: point2.path,
435
425
  offset: 0
436
426
  });
@@ -458,7 +448,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
458
448
  const {
459
449
  anchor,
460
450
  focus
461
- } = range2, isBackward = isBackwardRange(range2, editor), domAnchor = DOMEditor.toDOMPoint(editor, anchor), domFocus = isCollapsedRange(range2) ? domAnchor : DOMEditor.toDOMPoint(editor, focus), domRange = DOMEditor.getWindow(editor).document.createRange(), [startNode, startOffset] = isBackward ? domFocus : domAnchor, [endNode, endOffset] = isBackward ? domAnchor : domFocus, isStartAtZeroWidth = !!(isDOMElement(startNode) ? startNode : startNode.parentElement).getAttribute("data-pt-zero-width"), isEndAtZeroWidth = !!(isDOMElement(endNode) ? endNode : endNode.parentElement).getAttribute("data-pt-zero-width");
451
+ } = range2, isBackward = isBackwardRange(range2, editor.snapshot.context), domAnchor = DOMEditor.toDOMPoint(editor, anchor), domFocus = isCollapsedRange(range2) ? domAnchor : DOMEditor.toDOMPoint(editor, focus), domRange = DOMEditor.getWindow(editor).document.createRange(), [startNode, startOffset] = isBackward ? domFocus : domAnchor, [endNode, endOffset] = isBackward ? domAnchor : domFocus, isStartAtZeroWidth = !!(isDOMElement(startNode) ? startNode : startNode.parentElement).getAttribute("data-pt-zero-width"), isEndAtZeroWidth = !!(isDOMElement(endNode) ? endNode : endNode.parentElement).getAttribute("data-pt-zero-width");
462
452
  return domRange.setStart(startNode, isStartAtZeroWidth ? 1 : startOffset), domRange.setEnd(endNode, isEndAtZeroWidth ? 1 : endOffset), domRange;
463
453
  },
464
454
  toSelectionPoint: (editor, domPoint, options) => {
@@ -583,8 +573,8 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
583
573
  throw new Error(`Cannot map DOM position to an editor location: ${domPoint}`);
584
574
  }
585
575
  if (path2.length > 1) {
586
- const parentPath2 = path2.slice(0, -1), parentEntry = getNode(editor, parentPath2);
587
- if (parentEntry && isLeafObject(editor, parentEntry.node, parentPath2))
576
+ const parentPath2 = path2.slice(0, -1), parentEntry = getNode(editor.snapshot, parentPath2);
577
+ if (parentEntry && isLeafObject(editor.snapshot, parentEntry.node, parentPath2))
588
578
  return {
589
579
  path: parentPath2,
590
580
  offset: 0
@@ -647,27 +637,23 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
647
637
  function collapse(editor, options = {}) {
648
638
  const {
649
639
  edge = "anchor"
650
- } = options, {
651
- selection
652
- } = editor;
640
+ } = options, selection = editor.snapshot.context.selection;
653
641
  if (selection) {
654
642
  if (edge === "anchor")
655
643
  editor.select(selection.anchor);
656
644
  else if (edge === "focus")
657
645
  editor.select(selection.focus);
658
646
  else if (edge === "start") {
659
- const [start2] = rangeEdges(selection, editor);
647
+ const [start2] = rangeEdges(selection, editor.snapshot.context);
660
648
  editor.select(start2);
661
649
  } else if (edge === "end") {
662
- const [, end2] = rangeEdges(selection, editor);
650
+ const [, end2] = rangeEdges(selection, editor.snapshot.context);
663
651
  editor.select(end2);
664
652
  }
665
653
  } else return;
666
654
  }
667
655
  function deselect(editor) {
668
- const {
669
- selection
670
- } = editor;
656
+ const selection = editor.snapshot.context.selection;
671
657
  selection && editor.apply({
672
658
  type: "set_selection",
673
659
  properties: selection,
@@ -790,39 +776,39 @@ function range(editor, at, to) {
790
776
  }
791
777
  function* positions(editor, options = {}) {
792
778
  const {
793
- at = editor.selection,
779
+ at = editor.snapshot.context.selection,
794
780
  unit = "offset",
795
781
  reverse = !1
796
782
  } = options;
797
783
  if (!at)
798
784
  return;
799
- const editorRange = range(editor, at), [start$1, end$1] = rangeEdges(editorRange, editor), first = reverse ? end$1 : start$1;
785
+ const editorRange = range(editor, at), [start$1, end$1] = rangeEdges(editorRange, editor.snapshot.context), first = reverse ? end$1 : start$1;
800
786
  let isNewBlock = !1, blockText = "", distance = 0, leafTextRemaining = 0, leafTextOffset = 0;
801
787
  for (const {
802
788
  node,
803
789
  path: nodePath
804
- } of getNodes(editor, {
790
+ } of getNodes(editor.snapshot, {
805
791
  from: start$1.path,
806
792
  to: end$1.path,
807
793
  reverse
808
794
  })) {
809
795
  if (isTextBlockNode({
810
- schema: editor.schema
796
+ schema: editor.snapshot.context.schema
811
797
  }, node)) {
812
798
  const e = isAncestorPath(nodePath, end$1.path) ? end$1 : end(editor, nodePath), s = isAncestorPath(nodePath, start$1.path) ? start$1 : start(editor, nodePath);
813
799
  blockText = "";
814
800
  for (const {
815
801
  node: spanNode,
816
802
  path: spanPath
817
- } of getNodes(editor, {
803
+ } of getNodes(editor.snapshot, {
818
804
  from: s.path,
819
805
  to: e.path,
820
806
  match: (n) => isSpan({
821
- schema: editor.schema
807
+ schema: editor.snapshot.context.schema
822
808
  }, n)
823
809
  })) {
824
810
  if (!isSpan({
825
- schema: editor.schema
811
+ schema: editor.snapshot.context.schema
826
812
  }, spanNode))
827
813
  continue;
828
814
  let spanText = spanNode.text;
@@ -830,7 +816,7 @@ function* positions(editor, options = {}) {
830
816
  }
831
817
  isNewBlock = !0;
832
818
  }
833
- if (isLeafObject(editor, node, nodePath)) {
819
+ if (isLeafObject(editor.snapshot, node, nodePath)) {
834
820
  yield {
835
821
  path: nodePath,
836
822
  offset: 0
@@ -838,11 +824,11 @@ function* positions(editor, options = {}) {
838
824
  continue;
839
825
  }
840
826
  if (!isTextBlockNode({
841
- schema: editor.schema
827
+ schema: editor.snapshot.context.schema
842
828
  }, node) && !isSpan({
843
- schema: editor.schema
829
+ schema: editor.snapshot.context.schema
844
830
  }, node)) {
845
- if (isEditableContainer(editor, node, nodePath))
831
+ if (isEditableContainer(editor.snapshot, node, nodePath))
846
832
  continue;
847
833
  yield {
848
834
  path: nodePath,
@@ -851,7 +837,7 @@ function* positions(editor, options = {}) {
851
837
  continue;
852
838
  }
853
839
  if (isSpan({
854
- schema: editor.schema
840
+ schema: editor.snapshot.context.schema
855
841
  }, node)) {
856
842
  const isFirst = pathEquals(nodePath, first.path);
857
843
  for (isFirst ? (leafTextRemaining = reverse ? first.offset : node.text.length - first.offset, leafTextOffset = first.offset) : (leafTextRemaining = node.text.length, leafTextOffset = reverse ? leafTextRemaining : 0), (isFirst || isNewBlock || unit === "offset") && (yield {
@@ -920,9 +906,7 @@ function before(editor, at, options = {}) {
920
906
  return target;
921
907
  }
922
908
  function move(editor, options = {}) {
923
- const {
924
- selection
925
- } = editor, {
909
+ const selection = editor.snapshot.context.selection, {
926
910
  distance = 1,
927
911
  unit = "character",
928
912
  reverse = !1
@@ -932,7 +916,7 @@ function move(editor, options = {}) {
932
916
  } = options;
933
917
  if (!selection)
934
918
  return;
935
- edge === "start" && (edge = isBackwardRange(selection, editor) ? "focus" : "anchor"), edge === "end" && (edge = isBackwardRange(selection, editor) ? "anchor" : "focus");
919
+ edge === "start" && (edge = isBackwardRange(selection, editor.snapshot.context) ? "focus" : "anchor"), edge === "end" && (edge = isBackwardRange(selection, editor.snapshot.context) ? "anchor" : "focus");
936
920
  const {
937
921
  anchor,
938
922
  focus
@@ -1338,7 +1322,7 @@ function transformPath(path2, operation) {
1338
1322
  const {
1339
1323
  path: operationPath
1340
1324
  } = operation;
1341
- if (pathEquals(operationPath, path2) || isAncestorPath(operationPath, path2))
1325
+ if (pathContains(operationPath, path2))
1342
1326
  return null;
1343
1327
  }
1344
1328
  break;
@@ -1387,7 +1371,7 @@ function transformPoint$1(point2, op, options = {}) {
1387
1371
  case "unset": {
1388
1372
  const lastSegment = op.path[op.path.length - 1];
1389
1373
  if (isKeyedSegment(lastSegment))
1390
- return pathEquals(op.path, point2.path) || isAncestorPath(op.path, point2.path) ? null : point2;
1374
+ return pathContains(op.path, point2.path) ? null : point2;
1391
1375
  const propertyName = lastSegment, nodePath = op.path.slice(0, -1);
1392
1376
  return propertyName === "text" && pathEquals(nodePath, point2.path) && point2.offset !== 0 ? {
1393
1377
  path: point2.path,
@@ -1404,20 +1388,20 @@ function verifyDiffState(editor, textDiff) {
1404
1388
  path: path2,
1405
1389
  diff: diff2
1406
1390
  } = textDiff;
1407
- if (!hasNode(editor, path2))
1391
+ if (!hasNode(editor.snapshot, path2))
1408
1392
  return !1;
1409
- const nodeEntry = getSpan(editor, path2);
1393
+ const nodeEntry = getSpan(editor.snapshot, path2);
1410
1394
  if (!nodeEntry)
1411
1395
  return !1;
1412
1396
  const node = nodeEntry.node;
1413
1397
  if (diff2.start !== node.text.length || diff2.text.length === 0)
1414
1398
  return node.text.slice(diff2.start, diff2.start + diff2.text.length) === diff2.text;
1415
- const nextSibling = getSibling(editor, path2, {
1399
+ const nextSibling = getSibling(editor.snapshot, path2, {
1416
1400
  direction: "next"
1417
1401
  });
1418
1402
  if (!nextSibling)
1419
1403
  return !1;
1420
- const nextNodeEntry = getSpan(editor, nextSibling.path);
1404
+ const nextNodeEntry = getSpan(editor.snapshot, nextSibling.path);
1421
1405
  return !!nextNodeEntry && nextNodeEntry.node.text.startsWith(diff2.text);
1422
1406
  }
1423
1407
  function applyStringDiff(text, ...diffs) {
@@ -1478,28 +1462,28 @@ function normalizePoint(editor, point2) {
1478
1462
  path: path2,
1479
1463
  offset
1480
1464
  } = point2;
1481
- if (!hasNode(editor, path2))
1465
+ if (!hasNode(editor.snapshot, path2))
1482
1466
  return null;
1483
- const leafEntry = getSpan(editor, path2);
1467
+ const leafEntry = getSpan(editor.snapshot, path2);
1484
1468
  if (!leafEntry)
1485
1469
  return null;
1486
1470
  let leaf = leafEntry.node;
1487
- const parentBlock = getParent(editor, path2, {
1471
+ const parentBlock = getParent(editor.snapshot, path2, {
1488
1472
  match: (node) => isTextBlock({
1489
- schema: editor.schema
1473
+ schema: editor.snapshot.context.schema
1490
1474
  }, node)
1491
1475
  });
1492
1476
  if (!parentBlock)
1493
1477
  return null;
1494
1478
  for (; offset > leaf.text.length; ) {
1495
- const afterPoint = after(editor, path2), [nextEntry] = afterPoint ? getNodes(editor, {
1479
+ const afterPoint = after(editor, path2), [nextEntry] = afterPoint ? getNodes(editor.snapshot, {
1496
1480
  from: afterPoint.path,
1497
1481
  match: (n) => isSpan({
1498
- schema: editor.schema
1482
+ schema: editor.snapshot.context.schema
1499
1483
  }, n)
1500
1484
  }) : [];
1501
1485
  if (!nextEntry || !isSpan({
1502
- schema: editor.schema
1486
+ schema: editor.snapshot.context.schema
1503
1487
  }, nextEntry.node) || !isDescendantPath(nextEntry.path, parentBlock.path))
1504
1488
  return null;
1505
1489
  offset -= leaf.text.length, leaf = nextEntry.node, path2 = nextEntry.path;
@@ -1637,7 +1621,7 @@ function createAndroidInputManager({
1637
1621
  if (editor.pendingSelection = null, pendingSelection) {
1638
1622
  const {
1639
1623
  selection
1640
- } = editor, normalized = normalizeRange(editor, pendingSelection);
1624
+ } = editor.snapshot.context, normalized = normalizeRange(editor, pendingSelection);
1641
1625
  normalized && (!selection || !rangeEquals(normalized, selection)) && editor.select(normalized);
1642
1626
  }
1643
1627
  }, performAction = () => {
@@ -1648,7 +1632,7 @@ function createAndroidInputManager({
1648
1632
  if (!target)
1649
1633
  return;
1650
1634
  const targetRange2 = range(editor, target);
1651
- (!editor.selection || !rangeEquals(editor.selection, targetRange2)) && editor.select(target);
1635
+ (!editor.snapshot.context.selection || !rangeEquals(editor.snapshot.context.selection, targetRange2)) && editor.select(target);
1652
1636
  }
1653
1637
  action.run();
1654
1638
  }
@@ -1658,13 +1642,13 @@ function createAndroidInputManager({
1658
1642
  return;
1659
1643
  }
1660
1644
  flushing || (flushing = !0, setTimeout(() => flushing = !1)), hasPendingAction() && (flushing = "action");
1661
- const selectionRef = editor.selection && rangeRef(editor, editor.selection, {
1645
+ const selectionRef = editor.snapshot.context.selection && rangeRef(editor, editor.snapshot.context.selection, {
1662
1646
  affinity: "forward"
1663
1647
  });
1664
1648
  let scheduleSelectionChange = hasPendingDiffs(), diff2;
1665
1649
  for (; diff2 = editor.pendingDiffs?.[0]; ) {
1666
1650
  const range2 = targetRange(diff2);
1667
- (!editor.selection || !rangeEquals(editor.selection, range2)) && editor.select(range2), diff2.diff.text ? editorActor.send({
1651
+ (!editor.snapshot.context.selection || !rangeEquals(editor.snapshot.context.selection, range2)) && editor.select(range2), diff2.diff.text ? editorActor.send({
1668
1652
  type: "behavior event",
1669
1653
  behaviorEvent: {
1670
1654
  type: "insert.text",
@@ -1683,7 +1667,7 @@ function createAndroidInputManager({
1683
1667
  }) => id !== diff2.id), verifyDiffState(editor, diff2) || (scheduleSelectionChange = !1, editor.pendingAction = null, flushing = "action", editor.pendingSelection = null, scheduleOnDOMSelectionChange.cancel(), onDOMSelectionChange.cancel(), selectionRef?.unref());
1684
1668
  }
1685
1669
  const selection = selectionRef?.unref();
1686
- if (selection && !editor.pendingSelection && (!editor.selection || !rangeEquals(selection, editor.selection)) && editor.select(selection), hasPendingAction()) {
1670
+ if (selection && !editor.pendingSelection && (!editor.snapshot.context.selection || !rangeEquals(selection, editor.snapshot.context.selection)) && editor.select(selection), hasPendingAction()) {
1687
1671
  performAction();
1688
1672
  return;
1689
1673
  }
@@ -1695,7 +1679,7 @@ function createAndroidInputManager({
1695
1679
  }, handleCompositionStart = (_event) => {
1696
1680
  editor.composing = !0, compositionEndTimeoutId && (clearTimeout(compositionEndTimeoutId), compositionEndTimeoutId = null);
1697
1681
  }, storeDiff = (path2, diff2) => {
1698
- const pendingDiffs = editor.pendingDiffs, targetEntry = getSpan(editor, path2);
1682
+ const pendingDiffs = editor.pendingDiffs, targetEntry = getSpan(editor.snapshot, path2);
1699
1683
  if (!targetEntry)
1700
1684
  return;
1701
1685
  const target = targetEntry.node, idx = pendingDiffs.findIndex((change) => pathEquals(change.path, path2));
@@ -1741,15 +1725,15 @@ function createAndroidInputManager({
1741
1725
  if (!targetRange2 && domSelection && (nativeTargetRange = domSelection, targetRange2 = DOMEditor.toEditorSelection(editor, domSelection, {
1742
1726
  exactMatch: !1,
1743
1727
  suppressThrow: !0
1744
- })), targetRange2 = targetRange2 ?? editor.selection, !targetRange2)
1728
+ })), targetRange2 = targetRange2 ?? editor.snapshot.context.selection, !targetRange2)
1745
1729
  return;
1746
1730
  let canStoreDiff = !0;
1747
1731
  if (type.startsWith("delete")) {
1748
1732
  const direction = type.endsWith("Backward") ? "backward" : "forward";
1749
- let [start2, end2] = rangeEdges(targetRange2, editor);
1750
- const leafNodeEntry = getNode(editor, start2.path), leafResult = leafNodeEntry && (isSpan({
1751
- schema: editor.schema
1752
- }, leafNodeEntry.node) || isLeafObject(editor, leafNodeEntry.node, start2.path)) ? leafNodeEntry : void 0;
1733
+ let [start2, end2] = rangeEdges(targetRange2, editor.snapshot.context);
1734
+ const leafNodeEntry = getNode(editor.snapshot, start2.path), leafResult = leafNodeEntry && (isSpan({
1735
+ schema: editor.snapshot.context.schema
1736
+ }, leafNodeEntry.node) || isLeafObject(editor.snapshot, leafNodeEntry.node, start2.path)) ? leafNodeEntry : void 0;
1753
1737
  if (!leafResult)
1754
1738
  return scheduleAction(() => editorActor.send({
1755
1739
  type: "behavior event",
@@ -1763,7 +1747,7 @@ function createAndroidInputManager({
1763
1747
  });
1764
1748
  let leaf = leafResult.node, path2 = leafResult.path;
1765
1749
  if (!isSpan({
1766
- schema: editor.schema
1750
+ schema: editor.snapshot.context.schema
1767
1751
  }, leaf))
1768
1752
  return scheduleAction(() => editorActor.send({
1769
1753
  type: "behavior event",
@@ -1776,14 +1760,14 @@ function createAndroidInputManager({
1776
1760
  at: targetRange2
1777
1761
  });
1778
1762
  if (isExpandedRange(targetRange2) && leaf.text.length === start2.offset && end2.offset === 0) {
1779
- const afterPoint = after(editor, start2.path), [nextEntry] = afterPoint ? getNodes(editor, {
1763
+ const afterPoint = after(editor, start2.path), [nextEntry] = afterPoint ? getNodes(editor.snapshot, {
1780
1764
  from: afterPoint.path,
1781
1765
  match: (n) => isSpan({
1782
- schema: editor.schema
1766
+ schema: editor.snapshot.context.schema
1783
1767
  }, n)
1784
1768
  }) : [];
1785
1769
  nextEntry && isSpan({
1786
- schema: editor.schema
1770
+ schema: editor.snapshot.context.schema
1787
1771
  }, nextEntry.node) && pathEquals(nextEntry.path, end2.path) && (direction === "backward" ? (targetRange2 = {
1788
1772
  anchor: end2,
1789
1773
  focus: end2
@@ -1793,7 +1777,7 @@ function createAndroidInputManager({
1793
1777
  }, end2 = start2));
1794
1778
  }
1795
1779
  if (!isSpan({
1796
- schema: editor.schema
1780
+ schema: editor.snapshot.context.schema
1797
1781
  }, leaf))
1798
1782
  return;
1799
1783
  const diff2 = {
@@ -1845,7 +1829,7 @@ function createAndroidInputManager({
1845
1829
  anchor
1846
1830
  } = targetRange2;
1847
1831
  if (canStoreDiff && isCollapsedRange(targetRange2)) {
1848
- const targetNodeEntry = getSpan(editor, anchor.path);
1832
+ const targetNodeEntry = getSpan(editor.snapshot, anchor.path);
1849
1833
  if (targetNodeEntry && anchor.offset < targetNodeEntry.node.text.length)
1850
1834
  return storeDiff(anchor.path, {
1851
1835
  text: "",
@@ -2036,7 +2020,7 @@ function createAndroidInputManager({
2036
2020
  at: targetRange2
2037
2021
  });
2038
2022
  if (pathEquals(targetRange2.anchor.path, targetRange2.focus.path)) {
2039
- const [start2, end2] = rangeEdges(targetRange2, editor), diff2 = {
2023
+ const [start2, end2] = rangeEdges(targetRange2, editor.snapshot.context), diff2 = {
2040
2024
  start: start2.offset,
2041
2025
  end: end2.offset,
2042
2026
  text
@@ -2049,7 +2033,7 @@ function createAndroidInputManager({
2049
2033
  text: insertPositionHint.text + text
2050
2034
  } : insertPositionHint = !1 : insertPositionHint = !1;
2051
2035
  if (canStoreDiff) {
2052
- const currentSelection = editor.selection;
2036
+ const currentSelection = editor.snapshot.context.selection;
2053
2037
  if (storeDiff(start2.path, diff2), currentSelection) {
2054
2038
  const newPoint = {
2055
2039
  path: start2.path,
@@ -2083,7 +2067,7 @@ function createAndroidInputManager({
2083
2067
  editor.pendingSelection = range2, flushTimeoutId && (clearTimeout(flushTimeoutId), flushTimeoutId = null);
2084
2068
  const {
2085
2069
  selection
2086
- } = editor;
2070
+ } = editor.snapshot.context;
2087
2071
  if (!range2)
2088
2072
  return;
2089
2073
  const pathChanged = !selection || !pathEquals(selection.anchor.path, range2.anchor.path), parentPathChanged = !selection || !pathEquals(selection.anchor.path.slice(0, -1), range2.anchor.path.slice(0, -1));
@@ -2133,9 +2117,6 @@ const MUTATION_OBSERVER_CONFIG$1 = {
2133
2117
  function useParentContainer() {
2134
2118
  return useContext(ParentContainerContext);
2135
2119
  }
2136
- function isBeforePoint(point2, another, root) {
2137
- return comparePoints(point2, another, root) === -1;
2138
- }
2139
2120
  function rangeIntersection(range2, another, root) {
2140
2121
  if (!rangesOverlap(range2, another, root))
2141
2122
  return null;
@@ -2184,8 +2165,8 @@ const shallowCompare = (obj1, obj2) => Object.keys(obj1).length === Object.keys(
2184
2165
  }
2185
2166
  return !0;
2186
2167
  }, splitDecorationsByChild = (editor, node, path2, decorations) => {
2187
- const children = isEditor(node) || isTextBlock({
2188
- schema: editor.schema
2168
+ const children = isEditor(node) ? editor.snapshot.context.value : isTextBlock({
2169
+ schema: editor.snapshot.context.schema
2189
2170
  }, node) ? node.children : [], decorationsByChild = Array.from(children, () => []);
2190
2171
  if (decorations.length === 0)
2191
2172
  return decorationsByChild;
@@ -2213,10 +2194,10 @@ const shallowCompare = (obj1, obj2) => Object.keys(obj1).length === Object.keys(
2213
2194
  return keyToIndex.get(segment._key);
2214
2195
  };
2215
2196
  for (const decoration of decorations) {
2216
- const decorationRange = rangeIntersection(ancestorRange, decoration, editor);
2197
+ const decorationRange = rangeIntersection(ancestorRange, decoration, editor.snapshot.context);
2217
2198
  if (!decorationRange)
2218
2199
  continue;
2219
- const [startPoint, endPoint] = rangeEdges(decorationRange, editor), startIndex = resolveChildIndex2(startPoint) ?? 0, endIndex = resolveChildIndex2(endPoint) ?? children.length - 1;
2200
+ const [startPoint, endPoint] = rangeEdges(decorationRange, editor.snapshot.context), startIndex = resolveChildIndex2(startPoint) ?? 0, endIndex = resolveChildIndex2(endPoint) ?? children.length - 1;
2220
2201
  for (let i = startIndex; i <= endIndex; i++) {
2221
2202
  const ds = decorationsByChild[i];
2222
2203
  if (!ds)
@@ -2224,7 +2205,7 @@ const shallowCompare = (obj1, obj2) => Object.keys(obj1).length === Object.keys(
2224
2205
  const childRange = getChildRange(i);
2225
2206
  if (!childRange)
2226
2207
  continue;
2227
- const childDecorationRange = rangeIntersection(childRange, decoration, editor);
2208
+ const childDecorationRange = rangeIntersection(childRange, decoration, editor.snapshot.context);
2228
2209
  childDecorationRange && ds.push({
2229
2210
  ...decoration,
2230
2211
  ...childDecorationRange
@@ -2274,7 +2255,7 @@ const DecorateContext = createContext({}), useDecorations = (node, path2, parent
2274
2255
  let t0;
2275
2256
  $[0] !== decorate || $[1] !== node || $[2] !== path2 ? (t0 = () => decorate([node, path2]), $[0] = decorate, $[1] = node, $[2] = path2, $[3] = t0) : t0 = $[3];
2276
2257
  const selector = t0, equalityFn = isSpan({
2277
- schema: editor.schema
2258
+ schema: editor.snapshot.context.schema
2278
2259
  }, node) ? isTextDecorationsEqual : isElementDecorationsEqual, [decorations, update] = useGenericSelector(selector, equalityFn);
2279
2260
  let t1, t2;
2280
2261
  $[4] !== addEventListener || $[5] !== update ? (t1 = () => {
@@ -2322,7 +2303,7 @@ const Element$1 = (props) => {
2322
2303
  renderElement,
2323
2304
  renderLeaf,
2324
2305
  renderText
2325
- } = props, dataPath = serializePath(props.path), editor = useEngineStatic(), isInline$1 = isInline(editor, props.path), isInNewPipeline = useContext(NewPipelineContext), decorations = useDecorations(element, props.path, parentDecorations);
2306
+ } = props, dataPath = serializePath(props.path), editor = useEngineStatic(), isInline$1 = isInline(editor.snapshot, props.path), isInNewPipeline = useContext(NewPipelineContext), decorations = useDecorations(element, props.path, parentDecorations);
2326
2307
  let t0;
2327
2308
  $[0] !== decorations || $[1] !== element || $[2] !== props.path || $[3] !== renderElement || $[4] !== renderLeaf || $[5] !== renderText ? (t0 = {
2328
2309
  decorations,
@@ -2342,9 +2323,9 @@ const Element$1 = (props) => {
2342
2323
  "data-pt-path": dataPath
2343
2324
  };
2344
2325
  if (!isInline$1 && isTextBlockNode({
2345
- schema: editor.schema
2326
+ schema: editor.snapshot.context.schema
2346
2327
  }, element)) {
2347
- const text = getText(editor, props.path), dir = text !== void 0 ? getDirection(text) : void 0;
2328
+ const text = getText(editor.snapshot, props.path), dir = text !== void 0 ? getDirection(text) : void 0;
2348
2329
  dir === "rtl" && (attributes.dir = dir);
2349
2330
  }
2350
2331
  return renderElement({
@@ -2622,15 +2603,15 @@ function getTextContent(editor, path2) {
2622
2603
  for (const {
2623
2604
  node,
2624
2605
  path: nodePath
2625
- } of getNodes(editor, {
2606
+ } of getNodes(editor.snapshot, {
2626
2607
  from: start$1.path,
2627
2608
  to: end$1.path,
2628
2609
  match: (n) => isSpan({
2629
- schema: editor.schema
2610
+ schema: editor.snapshot.context.schema
2630
2611
  }, n)
2631
2612
  })) {
2632
2613
  if (!isSpan({
2633
- schema: editor.schema
2614
+ schema: editor.snapshot.context.schema
2634
2615
  }, node))
2635
2616
  continue;
2636
2617
  let nodeText = node.text;
@@ -2647,7 +2628,7 @@ const EngineString = (props) => {
2647
2628
  text
2648
2629
  } = props, editor = useEngineStatic(), parentPath$1 = parentPath(path2), leafText = leaf.text ?? "";
2649
2630
  if (leafText === "" && isTextBlock({
2650
- schema: editor.schema
2631
+ schema: editor.snapshot.context.schema
2651
2632
  }, parent) && parent.children[parent.children.length - 1] === text && getTextContent(editor, parentPath$1) === "") {
2652
2633
  let t02;
2653
2634
  return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t02 = /* @__PURE__ */ jsx(ZeroWidthString, { isLineBreak: !0 }), $[0] = t02) : t02 = $[0], t02;
@@ -2825,12 +2806,12 @@ const useChildren = (props) => {
2825
2806
  const parentContainer = useParentContainer(), parentIsInNewPipeline = useContext(NewPipelineContext), decorationsByChild = useDecorationsByChild(editor, node, parentPath2, decorations);
2826
2807
  let children = [], arrayFieldName = "children", childContainer = parentContainer;
2827
2808
  if (isEditor(node))
2828
- children = node.children;
2809
+ children = node.snapshot.context.value;
2829
2810
  else if (isTextBlock({
2830
- schema: editor.schema
2811
+ schema: editor.snapshot.context.schema
2831
2812
  }, node))
2832
2813
  children = node.children;
2833
- else if (isObject$1(editor, node)) {
2814
+ else if (isObject$1(editor.snapshot, node)) {
2834
2815
  const containerConfig = resolveContainerForNode(editor, parentContainer, node);
2835
2816
  if (containerConfig) {
2836
2817
  const fieldValue = node[containerConfig.field.name];
@@ -2845,7 +2826,7 @@ const useChildren = (props) => {
2845
2826
  }];
2846
2827
  return /* @__PURE__ */ jsx(MemoizedElement, { decorations: decorationsByChild[i] ?? [], element: node2, isContainer, path: nodePath, renderElement, renderLeaf, renderText }, node2._key);
2847
2828
  }, [arrayFieldName, decorationsByChild, parentPath2, renderElement, renderLeaf, renderText]), textBlockParent = isTextBlock({
2848
- schema: editor.schema
2829
+ schema: editor.snapshot.context.schema
2849
2830
  }, node) ? node : void 0, wrapNewPipeline = (child, isInNewPipelineForChild2, key) => parentIsInNewPipeline || !isInNewPipelineForChild2 ? child : /* @__PURE__ */ jsx(NewPipelineContext.Provider, { value: !0, children: child }, key), renderTextComponent = (node2, index) => {
2850
2831
  if (!textBlockParent)
2851
2832
  throw new Error("Cannot render text component without a text block parent");
@@ -2864,9 +2845,9 @@ const useChildren = (props) => {
2864
2845
  return /* @__PURE__ */ jsx(MemoizedObjectNode, { decorations: decorationsByChild[index] ?? [], isInline: textBlockParent !== void 0, objectNode: node2, path: nodePath, renderElement }, node2._key);
2865
2846
  }, isInNewPipelineForChild = (n, isContainerChild) => {
2866
2847
  if (isTextBlock({
2867
- schema: editor.schema
2848
+ schema: editor.snapshot.context.schema
2868
2849
  }, n)) {
2869
- if (editor.textBlocks.has(n._type))
2850
+ if (editor.textBlocks.has(n._type) || editor.textBlocks.has("*"))
2870
2851
  return !0;
2871
2852
  if (parentContainer?.of) {
2872
2853
  for (const entry of parentContainer.of)
@@ -2875,10 +2856,10 @@ const useChildren = (props) => {
2875
2856
  }
2876
2857
  return !1;
2877
2858
  }
2878
- if (isObject$1(editor, n)) {
2859
+ if (isObject$1(editor.snapshot, n)) {
2879
2860
  if (textBlockParent !== void 0)
2880
2861
  return !1;
2881
- if (editor.blockObjects.has(n._type))
2862
+ if (editor.blockObjects.has(n._type) || editor.blockObjects.has("*"))
2882
2863
  return !0;
2883
2864
  if (parentContainer?.of) {
2884
2865
  for (const entry of parentContainer.of)
@@ -2888,25 +2869,25 @@ const useChildren = (props) => {
2888
2869
  return !1;
2889
2870
  }
2890
2871
  return isSpan({
2891
- schema: editor.schema
2872
+ schema: editor.snapshot.context.schema
2892
2873
  }, n), !1;
2893
2874
  }, elements = children.map((n, i) => {
2894
2875
  if (isTextBlock({
2895
- schema: editor.schema
2876
+ schema: editor.snapshot.context.schema
2896
2877
  }, n))
2897
2878
  return wrapNewPipeline(renderElementComponent(n, i, !1), isInNewPipelineForChild(n), n._key);
2898
2879
  if (isTextBlockNode({
2899
- schema: editor.schema
2880
+ schema: editor.snapshot.context.schema
2900
2881
  }, n))
2901
2882
  return null;
2902
- if (isObject$1(editor, n))
2883
+ if (isObject$1(editor.snapshot, n))
2903
2884
  return resolveContainerForNode(editor, childContainer, n) ? wrapNewPipeline(renderElementComponent(n, i, !0), !0, n._key) : wrapNewPipeline(renderObjectNodeComponent(n, i), isInNewPipelineForChild(n), n._key);
2904
2885
  if (isSpan({
2905
- schema: editor.schema
2886
+ schema: editor.snapshot.context.schema
2906
2887
  }, n))
2907
2888
  return wrapNewPipeline(renderTextComponent(n, i), isInNewPipelineForChild(n), n._key);
2908
2889
  if (isSpanNode({
2909
- schema: editor.schema
2890
+ schema: editor.snapshot.context.schema
2910
2891
  }, n))
2911
2892
  return null;
2912
2893
  throw new Error("Unexpected node type");
@@ -3163,7 +3144,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3163
3144
  ref.current && (window2 = getDefaultView(ref.current)) && (editor.domWindow = window2, editor.domElement = ref.current);
3164
3145
  const {
3165
3146
  selection
3166
- } = editor, root = DOMEditor.findDocumentOrShadowRoot(editor), domSelection = getSelection(root);
3147
+ } = editor.snapshot.context, root = DOMEditor.findDocumentOrShadowRoot(editor), domSelection = getSelection(root);
3167
3148
  if (!domSelection || !editor.focused || androidInputManagerRef.current?.hasPendingAction())
3168
3149
  return;
3169
3150
  const setDomSelection = (forceChange) => {
@@ -3194,9 +3175,9 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3194
3175
  exactMatch: !1,
3195
3176
  suppressThrow: !0
3196
3177
  });
3197
- editor.selection = fallbackRange ? {
3178
+ editor.snapshot.context.selection = fallbackRange ? {
3198
3179
  ...fallbackRange,
3199
- backward: isBackwardRange(fallbackRange, editor)
3180
+ backward: isBackwardRange(fallbackRange, editor.snapshot.context)
3200
3181
  } : null;
3201
3182
  return;
3202
3183
  }
@@ -3206,7 +3187,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3206
3187
  newDomRange = selection && DOMEditor.toDOMRange(editor, selection);
3207
3188
  } catch {
3208
3189
  }
3209
- return newDomRange ? (editor.composing && !IS_ANDROID ? domSelection.collapseToEnd() : isBackwardRange(selection, editor) ? domSelection.setBaseAndExtent(newDomRange.endContainer, newDomRange.endOffset, newDomRange.startContainer, newDomRange.startOffset) : domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset), scrollSelectionIntoView(editor, newDomRange)) : domSelection.removeAllRanges(), newDomRange;
3190
+ return newDomRange ? (editor.composing && !IS_ANDROID ? domSelection.collapseToEnd() : isBackwardRange(selection, editor.snapshot.context) ? domSelection.setBaseAndExtent(newDomRange.endContainer, newDomRange.endOffset, newDomRange.startContainer, newDomRange.startOffset) : domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset), scrollSelectionIntoView(editor, newDomRange)) : domSelection.removeAllRanges(), newDomRange;
3210
3191
  };
3211
3192
  domSelection.rangeCount <= 1 && setDomSelection();
3212
3193
  const ensureSelection = androidInputManagerRef.current?.isFlushing() === "action";
@@ -3259,7 +3240,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3259
3240
  scheduleOnDOMSelectionChange.flush(), onDOMSelectionChange.flush();
3260
3241
  const {
3261
3242
  selection
3262
- } = editor, {
3243
+ } = editor.snapshot.context, {
3263
3244
  inputType: type
3264
3245
  } = event, data = event.dataTransfer || event.data || void 0, isCompositionChange = type === "insertCompositionText" || type === "deleteCompositionText";
3265
3246
  if (isCompositionChange && editor.composing)
@@ -3280,12 +3261,12 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3280
3261
  lastText === node && lastText.textContent?.length === offset && (native = !1);
3281
3262
  }
3282
3263
  if (native && node.parentElement && window2?.getComputedStyle(node.parentElement)?.whiteSpace === "pre") {
3283
- const block = getParent(editor, anchor.path, {
3264
+ const block = getParent(editor.snapshot, anchor.path, {
3284
3265
  match: (node2) => isTextBlock({
3285
- schema: editor.schema
3266
+ schema: editor.snapshot.context.schema
3286
3267
  }, node2)
3287
3268
  });
3288
- block && getText(editor, block.path)?.includes(" ") && (native = !1);
3269
+ block && getText(editor.snapshot, block.path)?.includes(" ") && (native = !1);
3289
3270
  }
3290
3271
  }
3291
3272
  if ((!type.startsWith("delete") || type.startsWith("deleteBy")) && !editor.isNodeMapDirty) {
@@ -3297,7 +3278,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3297
3278
  });
3298
3279
  if (!selection || !rangeEquals(selection, range2)) {
3299
3280
  native = !1;
3300
- const selectionRef = !isCompositionChange && editor.selection && rangeRef(editor, editor.selection);
3281
+ const selectionRef = !isCompositionChange && editor.snapshot.context.selection && rangeRef(editor, editor.snapshot.context.selection);
3301
3282
  editor.select(range2), selectionRef && (editor.userSelection = selectionRef);
3302
3283
  }
3303
3284
  }
@@ -3490,7 +3471,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3490
3471
  }
3491
3472
  }
3492
3473
  const toRestore = editor.userSelection?.unref();
3493
- editor.userSelection = null, toRestore && (!editor.selection || !rangeEquals(editor.selection, toRestore)) && editor.select(toRestore);
3474
+ editor.userSelection = null, toRestore && (!editor.snapshot.context.selection || !rangeEquals(editor.snapshot.context.selection, toRestore)) && editor.select(toRestore);
3494
3475
  }
3495
3476
  }, [editor, editorActor, onDOMSelectionChange, onUserInput, propsOnDOMBeforeInput, readOnly, scheduleOnDOMSelectionChange]), callbackRef = useCallback((node) => {
3496
3477
  node == null ? (onDOMSelectionChange.cancel(), scheduleOnDOMSelectionChange.cancel(), editor.domElement = null, ref.current && HAS_BEFORE_INPUT_SUPPORT && ref.current.removeEventListener("beforeinput", onDOMBeforeInput)) : HAS_BEFORE_INPUT_SUPPORT && node.addEventListener("beforeinput", onDOMBeforeInput), ref.current = node, typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node);
@@ -3572,10 +3553,10 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3572
3553
  if (relatedTarget != null && isDOMNode(relatedTarget) && DOMEditor.hasDOMNode(editor, relatedTarget)) {
3573
3554
  const relatedPath = getDomNodePath(relatedTarget);
3574
3555
  if (relatedPath) {
3575
- const relatedNodeEntry = getNode(editor, relatedPath), relatedNode = relatedNodeEntry ? relatedNodeEntry.node : void 0;
3556
+ const relatedNodeEntry = getNode(editor.snapshot, relatedPath), relatedNode = relatedNodeEntry ? relatedNodeEntry.node : void 0;
3576
3557
  if (relatedNode && (isTextBlockNode({
3577
- schema: editor.schema
3578
- }, relatedNode) || isLeafObject(editor, relatedNode, relatedPath)))
3558
+ schema: editor.snapshot.context.schema
3559
+ }, relatedNode) || isLeafObject(editor.snapshot, relatedNode, relatedPath)))
3579
3560
  return;
3580
3561
  }
3581
3562
  }
@@ -3587,17 +3568,17 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3587
3568
  const path2 = getDomNodePath(event.target);
3588
3569
  if (!path2)
3589
3570
  return;
3590
- const nodeClickEntry = getNode(editor, path2);
3571
+ const nodeClickEntry = getNode(editor.snapshot, path2);
3591
3572
  if (!nodeClickEntry)
3592
3573
  return;
3593
3574
  const node = nodeClickEntry.node;
3594
3575
  if (event.detail === TRIPLE_CLICK && path2.length >= 1) {
3595
3576
  let blockPath = path2;
3596
3577
  isTextBlockNode({
3597
- schema: editor.schema
3598
- }, node) || (blockPath = getParent(editor, path2, {
3578
+ schema: editor.snapshot.context.schema
3579
+ }, node) || (blockPath = getParent(editor.snapshot, path2, {
3599
3580
  match: (node2) => isTextBlock({
3600
- schema: editor.schema
3581
+ schema: editor.snapshot.context.schema
3601
3582
  }, node2)
3602
3583
  })?.path ?? path2.slice(0, 1));
3603
3584
  const range$1 = range(editor, blockPath);
@@ -3606,10 +3587,10 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3606
3587
  }
3607
3588
  if (readOnly)
3608
3589
  return;
3609
- const start$1 = start(editor, path2), end$1 = end(editor, path2), startEntry = getNode(editor, start$1.path), startVoidNode = startEntry && isLeafObject(editor, startEntry.node, start$1.path) ? startEntry : getAncestor(editor, start$1.path, {
3610
- match: (node2, ancestorPath) => isLeafObject(editor, node2, ancestorPath)
3611
- }), endEntry = getNode(editor, end$1.path), endVoidNode = endEntry && isLeafObject(editor, endEntry.node, end$1.path) ? endEntry : getAncestor(editor, end$1.path, {
3612
- match: (node2, ancestorPath) => isLeafObject(editor, node2, ancestorPath)
3590
+ const start$1 = start(editor, path2), end$1 = end(editor, path2), startEntry = getNode(editor.snapshot, start$1.path), startVoidNode = startEntry && isLeafObject(editor.snapshot, startEntry.node, start$1.path) ? startEntry : getAncestor(editor.snapshot, start$1.path, {
3591
+ match: (node2, ancestorPath) => isLeafObject(editor.snapshot, node2, ancestorPath)
3592
+ }), endEntry = getNode(editor.snapshot, end$1.path), endVoidNode = endEntry && isLeafObject(editor.snapshot, endEntry.node, end$1.path) ? endEntry : getAncestor(editor.snapshot, end$1.path, {
3593
+ match: (node2, ancestorPath) => isLeafObject(editor.snapshot, node2, ancestorPath)
3613
3594
  });
3614
3595
  if (startVoidNode && endVoidNode && pathEquals(startVoidNode.path, endVoidNode.path)) {
3615
3596
  const range$1 = range(editor, start$1);
@@ -3643,7 +3624,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3643
3624
  return;
3644
3625
  const {
3645
3626
  selection
3646
- } = editor;
3627
+ } = editor.snapshot.context;
3647
3628
  if (selection && isExpandedRange(selection)) {
3648
3629
  editorActor.send({
3649
3630
  type: "behavior event",
@@ -3686,7 +3667,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3686
3667
  return;
3687
3668
  const {
3688
3669
  selection
3689
- } = editor, blockSegment = selection !== null ? selection.focus.path[0] : 0, elementText = getText(editor, [blockSegment]), isRTL = elementText !== void 0 && getDirection(elementText) === "rtl";
3670
+ } = editor.snapshot.context, blockSegment = selection !== null ? selection.focus.path[0] : 0, elementText = getText(editor.snapshot, [blockSegment]), isRTL = elementText !== void 0 && getDirection(elementText) === "rtl";
3690
3671
  if (Hotkeys.isMoveLineBackward(nativeEvent)) {
3691
3672
  event.preventDefault(), move(editor, {
3692
3673
  unit: "line",
@@ -3751,8 +3732,8 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3751
3732
  }
3752
3733
  if (HAS_BEFORE_INPUT_SUPPORT) {
3753
3734
  if ((IS_CHROME || IS_WEBKIT) && selection && (Hotkeys.isDeleteBackward(nativeEvent) || Hotkeys.isDeleteForward(nativeEvent)) && isCollapsedRange(selection)) {
3754
- const currentNodeEntry = getNode(editor, selection.anchor.path);
3755
- if (currentNodeEntry && isLeafObject(editor, currentNodeEntry.node, selection.anchor.path)) {
3735
+ const currentNodeEntry = getNode(editor.snapshot, selection.anchor.path);
3736
+ if (currentNodeEntry && isLeafObject(editor.snapshot, currentNodeEntry.node, selection.anchor.path)) {
3756
3737
  event.preventDefault(), editorActor.send({
3757
3738
  type: "behavior event",
3758
3739
  behaviorEvent: {
@@ -3916,7 +3897,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
3916
3897
  }
3917
3898
  ) }) }) });
3918
3899
  }), defaultDecorate = () => [], defaultScrollSelectionIntoView = (editor, domRange) => {
3919
- const isBackward = !!editor.selection && isBackwardRange(editor.selection, editor), domFocusPoint = domRange.cloneRange();
3900
+ const isBackward = !!editor.snapshot.context.selection && isBackwardRange(editor.snapshot.context.selection, editor.snapshot.context), domFocusPoint = domRange.cloneRange();
3920
3901
  if (domFocusPoint.collapse(isBackward), domFocusPoint.getBoundingClientRect) {
3921
3902
  const leafEl = domFocusPoint.startContainer.parentElement, domRect = domFocusPoint.getBoundingClientRect();
3922
3903
  if (domRect.width === 0 && domRect.height === 0 && domRect.x === 0 && domRect.y === 0) {
@@ -3969,23 +3950,23 @@ function resolveSelection(editor, selection) {
3969
3950
  function resolveSelectionPoint(editor, selectionPoint, direction) {
3970
3951
  const snapshot = {
3971
3952
  context: {
3972
- schema: editor.schema,
3973
- containers: editor.publicContainers,
3974
- value: editor.children
3953
+ schema: editor.snapshot.context.schema,
3954
+ containers: editor.snapshot.context.containers,
3955
+ value: editor.snapshot.context.value
3975
3956
  },
3976
- blockIndexMap: editor.blockIndexMap
3957
+ blockIndexMap: editor.snapshot.blockIndexMap
3977
3958
  }, entry = getNode(snapshot, selectionPoint.path);
3978
3959
  if (entry) {
3979
3960
  if (getChildren(snapshot, entry.path).length === 0)
3980
3961
  return {
3981
3962
  path: entry.path,
3982
3963
  offset: isSpan({
3983
- schema: editor.schema
3964
+ schema: editor.snapshot.context.schema
3984
3965
  }, entry.node) ? Math.min(entry.node.text.length, selectionPoint.offset) : 0
3985
3966
  };
3986
3967
  const isBlockLevelPath = isBlock(snapshot, selectionPoint.path);
3987
3968
  if (isTextBlock({
3988
- schema: editor.schema
3969
+ schema: editor.snapshot.context.schema
3989
3970
  }, entry.node) && isBlockLevelPath) {
3990
3971
  const spanPoint = blockOffsetToSpanSelectionPoint({
3991
3972
  snapshot,
@@ -4029,9 +4010,7 @@ function resolveSelectionPoint(editor, selectionPoint, direction) {
4029
4010
  };
4030
4011
  }
4031
4012
  function applySelect(editor, target) {
4032
- const range2 = toRange(editor, target), {
4033
- selection
4034
- } = editor;
4013
+ const range2 = toRange(editor, target), selection = editor.snapshot.context.selection;
4035
4014
  if (selection) {
4036
4015
  const oldProps = {}, newProps = {};
4037
4016
  range2.anchor != null && !pointEquals(range2.anchor, selection.anchor) && (oldProps.anchor = selection.anchor, newProps.anchor = range2.anchor), range2.focus != null && !pointEquals(range2.focus, selection.focus) && (oldProps.focus = selection.focus, newProps.focus = range2.focus), Object.keys(oldProps).length > 0 && editor.apply({
@@ -4047,9 +4026,7 @@ function applySelect(editor, target) {
4047
4026
  });
4048
4027
  }
4049
4028
  function applyDeselect(editor) {
4050
- const {
4051
- selection
4052
- } = editor;
4029
+ const selection = editor.snapshot.context.selection;
4053
4030
  selection && editor.apply({
4054
4031
  type: "set_selection",
4055
4032
  properties: selection,
@@ -4105,7 +4082,7 @@ function getEventPosition({
4105
4082
  const {
4106
4083
  node: eventNode,
4107
4084
  path: eventPath
4108
- } = eventResult, eventBlockEntry = getEnclosingBlock(editorEngine, eventPath), eventBlock = eventBlockEntry?.node, eventBlockPath = eventBlockEntry?.path, eventPositionBlock = getEventPositionBlock({
4085
+ } = eventResult, eventBlockEntry = getEnclosingBlock(editorEngine.snapshot, eventPath), eventBlock = eventBlockEntry?.node, eventBlockPath = eventBlockEntry?.path, eventPositionBlock = getEventPositionBlock({
4109
4086
  nodePath: eventPath,
4110
4087
  editorEngine,
4111
4088
  event
@@ -4117,14 +4094,14 @@ function getEventPosition({
4117
4094
  isContainer: !1,
4118
4095
  selection: {
4119
4096
  anchor: getBlockStartPoint({
4120
- context: editorEngine,
4097
+ context: editorEngine.snapshot.context,
4121
4098
  block: {
4122
4099
  node: eventBlock,
4123
4100
  path: eventBlockPath
4124
4101
  }
4125
4102
  }),
4126
4103
  focus: getBlockEndPoint({
4127
- context: editorEngine,
4104
+ context: editorEngine.snapshot.context,
4128
4105
  block: {
4129
4106
  node: eventBlock,
4130
4107
  path: eventBlockPath
@@ -4134,7 +4111,7 @@ function getEventPosition({
4134
4111
  };
4135
4112
  if (!eventPositionBlock || !eventSelection)
4136
4113
  return;
4137
- const eventSelectionFocusBlock = getEnclosingBlock(editorEngine, eventSelection.focus.path);
4114
+ const eventSelectionFocusBlock = getEnclosingBlock(editorEngine.snapshot, eventSelection.focus.path);
4138
4115
  if (eventSelectionFocusBlock)
4139
4116
  return isSelectionCollapsed(eventSelection) && eventBlock && eventBlockPath && eventSelectionFocusBlock.node._key !== eventBlock._key && !isAncestorPath(eventBlockPath, eventSelectionFocusBlock.path) ? {
4140
4117
  block: eventPositionBlock,
@@ -4142,14 +4119,14 @@ function getEventPosition({
4142
4119
  isContainer: !1,
4143
4120
  selection: {
4144
4121
  anchor: getBlockStartPoint({
4145
- context: editorEngine,
4122
+ context: editorEngine.snapshot.context,
4146
4123
  block: {
4147
4124
  node: eventBlock,
4148
4125
  path: eventBlockPath
4149
4126
  }
4150
4127
  }),
4151
4128
  focus: getBlockEndPoint({
4152
- context: editorEngine,
4129
+ context: editorEngine.snapshot.context,
4153
4130
  block: {
4154
4131
  node: eventBlock,
4155
4132
  path: eventBlockPath
@@ -4159,7 +4136,7 @@ function getEventPosition({
4159
4136
  } : {
4160
4137
  block: eventPositionBlock,
4161
4138
  isEditor: isEditor(eventNode),
4162
- isContainer: isEditor(eventNode) ? !1 : isEditableContainer(editorEngine, eventNode, eventPath),
4139
+ isContainer: isEditor(eventNode) ? !1 : isEditableContainer(editorEngine.snapshot, eventNode, eventPath),
4163
4140
  selection: eventSelection
4164
4141
  };
4165
4142
  }
@@ -4177,7 +4154,7 @@ function getEventNode({
4177
4154
  path: path2
4178
4155
  };
4179
4156
  {
4180
- const nodeEntry = getNode(editorEngine, path2);
4157
+ const nodeEntry = getNode(editorEngine.snapshot, path2);
4181
4158
  if (nodeEntry)
4182
4159
  return {
4183
4160
  node: nodeEntry.node,
@@ -4194,7 +4171,7 @@ function getEventPositionBlock({
4194
4171
  editorEngine,
4195
4172
  event
4196
4173
  }) {
4197
- const firstBlockEntry = getNode(editorEngine, [0]);
4174
+ const firstBlockEntry = getNode(editorEngine.snapshot, [0]);
4198
4175
  if (!firstBlockEntry)
4199
4176
  return;
4200
4177
  const firstBlockElement = getDomNode(editorEngine, firstBlockEntry.path);
@@ -4203,7 +4180,7 @@ function getEventPositionBlock({
4203
4180
  const firstBlockRect = firstBlockElement.getBoundingClientRect();
4204
4181
  if (event.pageY < firstBlockRect.top)
4205
4182
  return "start";
4206
- const lastBlock = editorEngine.children.at(-1), lastBlockEntry = lastBlock ? getNode(editorEngine, [{
4183
+ const lastBlock = editorEngine.snapshot.context.value.at(-1), lastBlockEntry = lastBlock ? getNode(editorEngine.snapshot, [{
4207
4184
  _key: lastBlock._key
4208
4185
  }]) : void 0;
4209
4186
  if (!lastBlockEntry)
@@ -4250,7 +4227,7 @@ function getSelectionFromEvent(editor, event) {
4250
4227
  }
4251
4228
  }
4252
4229
  function isEventContainer(editorEngine, eventNode, eventPath) {
4253
- return isEditor(eventNode) ? !0 : isEditableContainer(editorEngine, eventNode, eventPath);
4230
+ return isEditor(eventNode) ? !0 : isEditableContainer(editorEngine.snapshot, eventNode, eventPath);
4254
4231
  }
4255
4232
  const EditorActorContext = createContext({}), IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
4256
4233
  alt: "altKey",
@@ -4409,20 +4386,32 @@ function performHotkey({
4409
4386
  }
4410
4387
  });
4411
4388
  }
4412
- function rangeIncludes(range2, target, root) {
4413
- if (isRange(target)) {
4414
- if (rangeIncludes(range2, target.anchor, root) || rangeIncludes(range2, target.focus, root))
4415
- return !0;
4416
- const [rs, re] = rangeEdges(range2, root), [ts, te] = rangeEdges(target, root);
4417
- return isBeforePoint(rs, ts, root) && isAfterPoint(re, te, root);
4389
+ function isForwardRange(range2, root) {
4390
+ return !isBackwardRange(range2, root);
4391
+ }
4392
+ function resolveRangeAffinities(range2, root, affinity) {
4393
+ if (affinity === "inward") {
4394
+ const isCollapsed = isCollapsedRange(range2);
4395
+ if (isForwardRange(range2, root)) {
4396
+ const anchorAffinity2 = "forward";
4397
+ return [anchorAffinity2, isCollapsed ? anchorAffinity2 : "backward"];
4398
+ }
4399
+ const anchorAffinity = "backward";
4400
+ return [anchorAffinity, isCollapsed ? anchorAffinity : "forward"];
4418
4401
  }
4419
- const [start2, end2] = rangeEdges(range2, root);
4420
- let isAfterStart = !1, isBeforeEnd = !1;
4421
- return isPoint(target) ? (isAfterStart = comparePoints(target, start2, root) >= 0, isBeforeEnd = comparePoints(target, end2, root) <= 0) : (isAfterStart = comparePaths(target, start2.path, root) >= 0, isBeforeEnd = comparePaths(target, end2.path, root) <= 0), isAfterStart && isBeforeEnd;
4402
+ return affinity === "outward" ? isForwardRange(range2, root) ? ["backward", "forward"] : ["forward", "backward"] : [affinity, affinity];
4422
4403
  }
4423
- function moveRangeByOperation(range2, operation) {
4424
- const anchor = transformPoint$1(range2.anchor, operation), focus = transformPoint$1(range2.focus, operation);
4425
- return anchor === null || focus === null ? null : pointEquals(anchor, range2.anchor) && pointEquals(focus, range2.focus) ? range2 : {
4404
+ function transformRange(range2, op, root, options = {}) {
4405
+ if (range2 === null)
4406
+ return null;
4407
+ const {
4408
+ affinity = "inward"
4409
+ } = options, [affinityAnchor, affinityFocus] = resolveRangeAffinities(range2, root, affinity), anchor = transformPoint$1(range2.anchor, op, {
4410
+ affinity: affinityAnchor
4411
+ }), focus = transformPoint$1(range2.focus, op, {
4412
+ affinity: affinityFocus
4413
+ });
4414
+ return !anchor || !focus ? null : anchor === range2.anchor && focus === range2.focus ? range2 : {
4426
4415
  anchor,
4427
4416
  focus
4428
4417
  };
@@ -4513,7 +4502,7 @@ const engineOperationCallback = ({
4513
4502
  });
4514
4503
  continue;
4515
4504
  }
4516
- const newRange = moveRangeByOperation(currentSelection, event.operation);
4505
+ const newRange = transformRange(currentSelection, event.operation, context.editorEngine.snapshot.context);
4517
4506
  (newRange && newRange !== currentSelection || newRange === null && currentSelection) && decoratedRange.rangeDecoration.onMoved?.({
4518
4507
  newSelection: newRange,
4519
4508
  rangeDecoration: decoratedRange.rangeDecoration,
@@ -4658,8 +4647,8 @@ const engineOperationCallback = ({
4658
4647
  });
4659
4648
  function createDecorate(schema, editorEngine) {
4660
4649
  return function([node, path2]) {
4661
- const defaultStyle = schema.styles.at(0)?.name, firstBlock = editorEngine.children[0];
4662
- return editorEngine.children.length === 1 && firstBlock && isEmptyTextBlock({
4650
+ const defaultStyle = schema.styles.at(0)?.name, firstBlock = editorEngine.snapshot.context.value[0];
4651
+ return editorEngine.snapshot.context.value.length === 1 && firstBlock && isEmptyTextBlock({
4663
4652
  schema
4664
4653
  }, firstBlock) && (!firstBlock.style || firstBlock.style === defaultStyle) && !firstBlock.listItem ? [{
4665
4654
  anchor: {
@@ -4672,10 +4661,10 @@ function createDecorate(schema, editorEngine) {
4672
4661
  },
4673
4662
  placeholder: !0
4674
4663
  }] : path2.length === 0 ? [] : !isTextBlock({
4675
- schema: editorEngine.schema
4664
+ schema: editorEngine.snapshot.context.schema
4676
4665
  }, node) || node.children.length === 0 ? [] : editorEngine.decoratedRanges.filter((decoratedRange) => {
4677
4666
  if (isCollapsedRange(decoratedRange)) {
4678
- const anchorBlock = getEnclosingBlock(editorEngine, decoratedRange.anchor.path), anchorChildSegment = decoratedRange.anchor.path.at(-1);
4667
+ const anchorBlock = getEnclosingBlock(editorEngine.snapshot, decoratedRange.anchor.path), anchorChildSegment = decoratedRange.anchor.path.at(-1);
4679
4668
  return !anchorBlock || !isKeyedSegment(anchorChildSegment) ? !1 : anchorBlock.node._key === node._key && node.children.some((child) => child._key === anchorChildSegment._key);
4680
4669
  }
4681
4670
  return rangeIntersection(decoratedRange, {
@@ -4687,18 +4676,16 @@ function createDecorate(schema, editorEngine) {
4687
4676
  path: path2,
4688
4677
  offset: 0
4689
4678
  }
4690
- }, editorEngine) || rangeIncludes(decoratedRange, path2, editorEngine);
4679
+ }, editorEngine.snapshot.context) || rangeIntersects(editorEngine.snapshot, decoratedRange, path2);
4691
4680
  });
4692
4681
  };
4693
4682
  }
4694
4683
  const RelayActorContext = createContext({});
4695
4684
  function findBlockPositionalOverride(parentConfig, type) {
4696
- if (parentConfig?.of)
4697
- return parentConfig.of.find((entry) => "container" in entry ? entry.container.type === type : "textBlock" in entry ? entry.textBlock.type === type : entry.blockObject.type === type);
4685
+ return parentConfig?.of ? parentConfig.of.find((entry) => "container" in entry ? entry.container.type === type : "textBlock" in entry ? entry.textBlock.type === type : entry.blockObject.type === type) || parentConfig.of.find((entry) => "container" in entry ? !1 : "textBlock" in entry ? entry.textBlock.type === "*" : entry.blockObject.type === "*") : void 0;
4698
4686
  }
4699
4687
  function findInlinePositionalOverride(parentTextBlock, type) {
4700
- if (parentTextBlock?.of)
4701
- return parentTextBlock.of.find((entry) => "span" in entry ? entry.span.type === type : entry.inlineObject.type === type);
4688
+ return parentTextBlock?.of ? parentTextBlock.of.find((entry) => "span" in entry ? entry.span.type === type : entry.inlineObject.type === type) || parentTextBlock.of.find((entry) => "span" in entry ? entry.span.type === "*" : entry.inlineObject.type === "*") : void 0;
4702
4689
  }
4703
4690
  const ParentTextBlockContext = createContext(void 0);
4704
4691
  function renderDefaultContainer(props) {
@@ -4853,11 +4840,11 @@ const defaultStore = {
4853
4840
  getSnapshot: () => defaultSelectionState
4854
4841
  }, SelectionStateStoreContext = createContext(defaultStore);
4855
4842
  function SelectionStateProvider(t0) {
4856
- const $ = c(11), {
4843
+ const $ = c(10), {
4857
4844
  children
4858
4845
  } = t0, editorActor = useContext(EditorActorContext), editorEngine = useEngineStatic();
4859
4846
  let t1;
4860
- $[0] !== editorEngine.blockIndexMap || $[1] !== editorEngine.publicContainers || $[2] !== editorEngine.snapshot ? (t1 = () => {
4847
+ $[0] !== editorEngine.blockIndexMap || $[1] !== editorEngine.snapshot ? (t1 = () => {
4861
4848
  const snapshot = editorEngine.snapshot, selection = snapshot.context.selection ? {
4862
4849
  anchorPath: snapshot.context.selection.anchor.path,
4863
4850
  focusPath: snapshot.context.selection.focus.path,
@@ -4867,15 +4854,15 @@ function SelectionStateProvider(t0) {
4867
4854
  return getSelectionState({
4868
4855
  context: {
4869
4856
  schema: snapshot.context.schema,
4870
- containers: editorEngine.publicContainers,
4857
+ containers: editorEngine.snapshot.context.containers,
4871
4858
  value: snapshot.context.value
4872
4859
  },
4873
4860
  blockIndexMap: editorEngine.blockIndexMap
4874
4861
  }, selection);
4875
- }, $[0] = editorEngine.blockIndexMap, $[1] = editorEngine.publicContainers, $[2] = editorEngine.snapshot, $[3] = t1) : t1 = $[3];
4862
+ }, $[0] = editorEngine.blockIndexMap, $[1] = editorEngine.snapshot, $[2] = t1) : t1 = $[2];
4876
4863
  const computeCurrent = t1, [seed] = useState(computeCurrent), stateRef = useRef(seed), [initialSubscribers] = useState(_temp$2), subscribersRef = useRef(initialSubscribers);
4877
4864
  let t2, t3;
4878
- $[4] !== computeCurrent || $[5] !== editorActor ? (t2 = () => {
4865
+ $[3] !== computeCurrent || $[4] !== editorActor ? (t2 = () => {
4879
4866
  const next = computeCurrent();
4880
4867
  if (!selectionStatesEqual(stateRef.current, next)) {
4881
4868
  stateRef.current = next;
@@ -4895,17 +4882,17 @@ function SelectionStateProvider(t0) {
4895
4882
  }));
4896
4883
  });
4897
4884
  return () => subscription.unsubscribe();
4898
- }, t3 = [editorActor, computeCurrent], $[4] = computeCurrent, $[5] = editorActor, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3);
4885
+ }, t3 = [editorActor, computeCurrent], $[3] = computeCurrent, $[4] = editorActor, $[5] = t2, $[6] = t3) : (t2 = $[5], t3 = $[6]), useEffect(t2, t3);
4899
4886
  let t4;
4900
- $[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = {
4887
+ $[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = {
4901
4888
  subscribe: (callback) => (subscribersRef.current.add(callback), () => {
4902
4889
  subscribersRef.current.delete(callback);
4903
4890
  }),
4904
4891
  getSnapshot: () => stateRef.current
4905
- }, $[8] = t4) : t4 = $[8];
4892
+ }, $[7] = t4) : t4 = $[7];
4906
4893
  const store = t4;
4907
4894
  let t5;
4908
- return $[9] !== children ? (t5 = /* @__PURE__ */ jsx(SelectionStateStoreContext.Provider, { value: store, children }), $[9] = children, $[10] = t5) : t5 = $[10], t5;
4895
+ return $[8] !== children ? (t5 = /* @__PURE__ */ jsx(SelectionStateStoreContext.Provider, { value: store, children }), $[8] = children, $[9] = t5) : t5 = $[9], t5;
4909
4896
  }
4910
4897
  function _temp$2() {
4911
4898
  return /* @__PURE__ */ new Set();
@@ -5058,7 +5045,7 @@ function RenderContainer(props) {
5058
5045
  function useBlockSubSchema(path2) {
5059
5046
  const $ = c(3), editor = useEngineStatic();
5060
5047
  let t0;
5061
- return $[0] !== editor || $[1] !== path2 ? (t0 = getPathSubSchema(editor, path2), $[0] = editor, $[1] = path2, $[2] = t0) : t0 = $[2], t0;
5048
+ return $[0] !== editor.snapshot || $[1] !== path2 ? (t0 = getPathSubSchema(editor.snapshot, path2), $[0] = editor.snapshot, $[1] = path2, $[2] = t0) : t0 = $[2], t0;
5062
5049
  }
5063
5050
  function RenderInlineObject(props) {
5064
5051
  const $ = c(41), inlineObjectRef = useRef(null), subSchema = useBlockSubSchema(props.path);
@@ -5336,8 +5323,8 @@ function RenderElement(props) {
5336
5323
  $[3] !== parentTextBlock || $[4] !== type ? (t1 = findInlinePositionalOverride(parentTextBlock, type), $[3] = parentTextBlock, $[4] = type, $[5] = t1) : t1 = $[5];
5337
5324
  const inlinePositionalOverride = t1;
5338
5325
  let t2;
5339
- $[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];
5340
- const [globalContainerConfig, globalBlockObjectConfig, globalInlineObjectConfig, textBlockConfig] = useEngineSelector(t2, tupleRefEqual);
5326
+ $[6] !== type ? (t2 = (engine) => [engine.containers.get(type), engine.blockObjects.get(type), engine.blockObjects.get("*"), engine.inlineObjects.get(type), engine.inlineObjects.get("*"), engine.textBlocks.get(type), engine.textBlocks.get("*")], $[6] = type, $[7] = t2) : t2 = $[7];
5327
+ const [globalContainerConfig, globalBlockObjectConfig, globalBlockObjectCatchAll, globalInlineObjectConfig, globalInlineObjectCatchAll, textBlockConfig, textBlockCatchAll] = useEngineSelector(t2, tupleRefEqual);
5341
5328
  let t3;
5342
5329
  bb0: {
5343
5330
  if (blockPositionalOverride && "container" in blockPositionalOverride) {
@@ -5357,27 +5344,27 @@ function RenderElement(props) {
5357
5344
  t4 = blockPositionalOverride;
5358
5345
  break bb1;
5359
5346
  }
5360
- t4 = textBlockConfig;
5347
+ t4 = textBlockConfig ?? textBlockCatchAll;
5361
5348
  }
5362
5349
  const textBlockScope = t4;
5363
5350
  let t5;
5364
5351
  bb2: {
5365
5352
  if (blockPositionalOverride && "textBlock" in blockPositionalOverride) {
5366
5353
  if (blockPositionalOverride.textBlock.render === void 0) {
5367
- t5 = textBlockConfig;
5354
+ t5 = textBlockConfig ?? textBlockCatchAll;
5368
5355
  break bb2;
5369
5356
  }
5370
5357
  t5 = blockPositionalOverride;
5371
5358
  break bb2;
5372
5359
  }
5373
- t5 = textBlockConfig;
5360
+ t5 = textBlockConfig ?? textBlockCatchAll;
5374
5361
  }
5375
5362
  const renderableTextBlockConfig = t5;
5376
5363
  let t6;
5377
5364
  bb3: {
5378
5365
  if (blockPositionalOverride && "blockObject" in blockPositionalOverride) {
5379
5366
  if (blockPositionalOverride.blockObject.render === void 0) {
5380
- t6 = globalBlockObjectConfig;
5367
+ t6 = globalBlockObjectConfig ?? globalBlockObjectCatchAll;
5381
5368
  break bb3;
5382
5369
  }
5383
5370
  t6 = blockPositionalOverride;
@@ -5387,14 +5374,14 @@ function RenderElement(props) {
5387
5374
  t6 = void 0;
5388
5375
  break bb3;
5389
5376
  }
5390
- t6 = globalBlockObjectConfig;
5377
+ t6 = globalBlockObjectConfig ?? globalBlockObjectCatchAll;
5391
5378
  }
5392
5379
  const blockObjectConfig = t6;
5393
5380
  let t7;
5394
5381
  bb4: {
5395
5382
  if (inlinePositionalOverride && "inlineObject" in inlinePositionalOverride) {
5396
5383
  if (inlinePositionalOverride.inlineObject.render === void 0) {
5397
- t7 = globalInlineObjectConfig;
5384
+ t7 = globalInlineObjectConfig ?? globalInlineObjectCatchAll;
5398
5385
  break bb4;
5399
5386
  }
5400
5387
  t7 = inlinePositionalOverride;
@@ -5404,7 +5391,7 @@ function RenderElement(props) {
5404
5391
  t7 = void 0;
5405
5392
  break bb4;
5406
5393
  }
5407
- t7 = globalInlineObjectConfig;
5394
+ t7 = globalInlineObjectConfig ?? globalInlineObjectCatchAll;
5408
5395
  }
5409
5396
  const inlineObjectConfig = t7;
5410
5397
  if (containerConfig) {
@@ -5451,7 +5438,7 @@ function RenderElement(props) {
5451
5438
  }
5452
5439
  return rendered;
5453
5440
  }
5454
- if (isInline(engineStatic, props.path)) {
5441
+ if (isInline(engineStatic.snapshot, props.path)) {
5455
5442
  if (isInNewPipeline && !inlineObjectConfig) {
5456
5443
  let rest_0;
5457
5444
  if ($[44] !== props.attributes) {
@@ -5534,9 +5521,9 @@ function useSpanConfig(node, _path) {
5534
5521
  $[0] !== node._type || $[1] !== parentTextBlock ? (t0 = findInlinePositionalOverride(parentTextBlock, node._type), $[0] = node._type, $[1] = parentTextBlock, $[2] = t0) : t0 = $[2];
5535
5522
  const positional = t0;
5536
5523
  let t1;
5537
- $[3] !== node._type ? (t1 = (engine) => engine.spans.get(node._type), $[3] = node._type, $[4] = t1) : t1 = $[4];
5538
- const globalSpan = useEngineSelector(t1);
5539
- return positional && "span" in positional ? positional.span.render === void 0 ? globalSpan : positional : globalSpan;
5524
+ $[3] !== node._type ? (t1 = (engine) => [engine.spans.get(node._type), engine.spans.get("*")], $[3] = node._type, $[4] = t1) : t1 = $[4];
5525
+ const [globalSpan, globalSpanCatchAll] = useEngineSelector(t1, tupleRefEqual);
5526
+ return positional && "span" in positional ? positional.span.render === void 0 ? globalSpan ?? globalSpanCatchAll : positional : globalSpan ?? globalSpanCatchAll;
5540
5527
  }
5541
5528
  function RenderSpan(props) {
5542
5529
  const $ = c(41), schema = props.schema, spanRef = useRef(null);
@@ -5969,7 +5956,7 @@ const PortableTextEditorContext = createContext(null), usePortableTextEditor = (
5969
5956
  }
5970
5957
  });
5971
5958
  function validateSelection(editorEngine, editorElement) {
5972
- if (!editorEngine.selection)
5959
+ if (!editorEngine.snapshot.context.selection)
5973
5960
  return;
5974
5961
  let root;
5975
5962
  try {
@@ -5983,10 +5970,10 @@ function validateSelection(editorEngine, editorElement) {
5983
5970
  return;
5984
5971
  const existingDOMRange = domSelection.getRangeAt(0);
5985
5972
  try {
5986
- const newDOMRange = DOMEditor.toDOMRange(editorEngine, editorEngine.selection);
5973
+ const newDOMRange = DOMEditor.toDOMRange(editorEngine, editorEngine.snapshot.context.selection);
5987
5974
  (newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug.selection("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
5988
5975
  } catch {
5989
- debug.selection("Could not resolve selection, selecting top document"), applyDeselect(editorEngine), editorEngine.children.length > 0 && applySelect(editorEngine, start(editorEngine, [])), editorEngine.onChange();
5976
+ debug.selection("Could not resolve selection, selecting top document"), applyDeselect(editorEngine), editorEngine.snapshot.context.value.length > 0 && applySelect(editorEngine, start(editorEngine, [])), editorEngine.onChange();
5990
5977
  }
5991
5978
  }
5992
5979
  const PortableTextEditable = forwardRef(function(props, forwardedRef) {
@@ -6020,7 +6007,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6020
6007
  scrollSelectionIntoView,
6021
6008
  ...restProps
6022
6009
  } = 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]);
6023
- const portableTextEditor = usePortableTextEditor(), [hasInvalidValue, setHasInvalidValue] = useState(!1), editorActor = useContext(EditorActorContext), relayActor = useContext(RelayActorContext), editorEngine = useEngine(), schema = editorEngine.schema, readOnly = useSelector(editorActor, _temp);
6010
+ const portableTextEditor = usePortableTextEditor(), [hasInvalidValue, setHasInvalidValue] = useState(!1), editorActor = useContext(EditorActorContext), relayActor = useContext(RelayActorContext), editorEngine = useEngine(), schema = editorEngine.snapshot.context.schema, readOnly = useSelector(editorActor, _temp);
6024
6011
  let t0;
6025
6012
  $[27] !== editorEngine ? (t0 = {
6026
6013
  input: {
@@ -6112,7 +6099,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6112
6099
  onCopy(event) !== void 0 && event.preventDefault();
6113
6100
  else if (event.nativeEvent.clipboardData) {
6114
6101
  event.stopPropagation(), event.preventDefault();
6115
- const selection = editorEngine.selection ?? void 0, position = selection ? {
6102
+ const selection = editorEngine.snapshot.context.selection ?? void 0, position = selection ? {
6116
6103
  selection
6117
6104
  } : void 0;
6118
6105
  if (!position) {
@@ -6142,7 +6129,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6142
6129
  onCut(event_0) !== void 0 && event_0.preventDefault();
6143
6130
  else if (event_0.nativeEvent.clipboardData) {
6144
6131
  event_0.stopPropagation(), event_0.preventDefault();
6145
- const selection_0 = editorEngine.selection, position_0 = selection_0 ? {
6132
+ const selection_0 = editorEngine.snapshot.context.selection, position_0 = selection_0 ? {
6146
6133
  selection: selection_0
6147
6134
  } : void 0;
6148
6135
  if (!position_0) {
@@ -6167,19 +6154,19 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6167
6154
  const handleCut = t18;
6168
6155
  let t19;
6169
6156
  $[86] !== editorActor || $[87] !== editorEngine || $[88] !== onPaste || $[89] !== portableTextEditor || $[90] !== relayActor ? (t19 = (event_1) => {
6170
- const value = editorEngine.children, path2 = editorEngine.selection?.focus.path || [], onPasteResult = onPaste?.({
6157
+ const value = editorEngine.snapshot.context.value, path2 = editorEngine.snapshot.context.selection?.focus.path || [], onPasteResult = onPaste?.({
6171
6158
  event: event_1,
6172
6159
  value,
6173
6160
  path: path2,
6174
6161
  schemaTypes: portableTextEditor.schemaTypes
6175
6162
  });
6176
- if (onPasteResult || !editorEngine.selection)
6163
+ if (onPasteResult || !editorEngine.snapshot.context.selection)
6177
6164
  event_1.preventDefault(), relayActor.send({
6178
6165
  type: "loading"
6179
6166
  }), Promise.resolve(onPasteResult).then((result_1) => {
6180
6167
  if (debug.behaviors("Custom paste function from client resolved", result_1), !result_1 || !result_1.insert) {
6181
6168
  debug.behaviors("No result from custom paste handler, pasting normally");
6182
- const selection_1 = editorEngine.selection, position_1 = selection_1 ? {
6169
+ const selection_1 = editorEngine.snapshot.context.selection, position_1 = selection_1 ? {
6183
6170
  selection: selection_1
6184
6171
  } : void 0;
6185
6172
  if (!position_1) {
@@ -6204,8 +6191,8 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6204
6191
  behaviorEvent: {
6205
6192
  type: "insert.blocks",
6206
6193
  blocks: parseBlocks({
6207
- keyGenerator: editorEngine.keyGenerator,
6208
- schema: editorEngine.schema,
6194
+ keyGenerator: editorEngine.snapshot.context.keyGenerator,
6195
+ schema: editorEngine.snapshot.context.schema,
6209
6196
  blocks: result_1.insert,
6210
6197
  options: {
6211
6198
  normalize: !1,
@@ -6224,7 +6211,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6224
6211
  });
6225
6212
  else if (event_1.nativeEvent.clipboardData) {
6226
6213
  event_1.preventDefault(), event_1.stopPropagation();
6227
- const selection_2 = editorEngine.selection, position_2 = selection_2 ? {
6214
+ const selection_2 = editorEngine.snapshot.context.selection, position_2 = selection_2 ? {
6228
6215
  selection: selection_2
6229
6216
  } : void 0;
6230
6217
  if (!position_2) {
@@ -6252,7 +6239,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
6252
6239
  onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
6253
6240
  type: "focused",
6254
6241
  event: event_2
6255
- }), !editorEngine.selection && editorEngine.children.length === 1 && isEmptyTextBlock(editorEngine, editorEngine.children.at(0)) && (editorEngine.select(start(editorEngine, [])), editorEngine.onChange()));
6242
+ }), !editorEngine.snapshot.context.selection && editorEngine.snapshot.context.value.length === 1 && isEmptyTextBlock(editorEngine.snapshot.context, editorEngine.snapshot.context.value.at(0)) && (editorEngine.select(start(editorEngine, [])), editorEngine.onChange()));
6256
6243
  }, $[92] = editorEngine, $[93] = onFocus, $[94] = relayActor, $[95] = t20) : t20 = $[95];
6257
6244
  const handleOnFocus = t20;
6258
6245
  let t21;
@@ -6880,34 +6867,34 @@ function isListItemActive({
6880
6867
  editor,
6881
6868
  listItem
6882
6869
  }) {
6883
- if (!editor.selection)
6870
+ if (!editor.snapshot.context.selection)
6884
6871
  return !1;
6885
- const [selStart, selEnd] = rangeEdges(editor.selection, editor), selectedBlocks = [...getNodes(editor, {
6872
+ const [selStart, selEnd] = rangeEdges(editor.snapshot.context.selection, editor.snapshot.context), selectedBlocks = [...getNodes(editor.snapshot, {
6886
6873
  from: selStart.path,
6887
6874
  to: selEnd.path,
6888
6875
  match: (node) => isTextBlock({
6889
- schema: editor.schema
6876
+ schema: editor.snapshot.context.schema
6890
6877
  }, node)
6891
6878
  })];
6892
6879
  return selectedBlocks.length > 0 ? selectedBlocks.every((entry) => isListBlock({
6893
- schema: editor.schema
6880
+ schema: editor.snapshot.context.schema
6894
6881
  }, entry.node) && entry.node.listItem === listItem) : !1;
6895
6882
  }
6896
6883
  function isStyleActive({
6897
6884
  editor,
6898
6885
  style
6899
6886
  }) {
6900
- if (!editor.selection)
6887
+ if (!editor.snapshot.context.selection)
6901
6888
  return !1;
6902
- const [selStart, selEnd] = rangeEdges(editor.selection, editor), selectedBlocks = [...getNodes(editor, {
6889
+ const [selStart, selEnd] = rangeEdges(editor.snapshot.context.selection, editor.snapshot.context), selectedBlocks = [...getNodes(editor.snapshot, {
6903
6890
  from: selStart.path,
6904
6891
  to: selEnd.path,
6905
6892
  match: (node) => isTextBlock({
6906
- schema: editor.schema
6893
+ schema: editor.snapshot.context.schema
6907
6894
  }, node)
6908
6895
  })];
6909
6896
  return selectedBlocks.length > 0 ? selectedBlocks.every((entry) => isTextBlock({
6910
- schema: editor.schema
6897
+ schema: editor.snapshot.context.schema
6911
6898
  }, entry.node) && entry.node.style === style) : !1;
6912
6899
  }
6913
6900
  function createEditableAPI(editor, editorActor) {
@@ -6991,18 +6978,18 @@ function createEditableAPI(editor, editorActor) {
6991
6978
  });
6992
6979
  },
6993
6980
  focusBlock: () => {
6994
- if (!editor.selection)
6981
+ if (!editor.snapshot.context.selection)
6995
6982
  return;
6996
- const focusPath = editor.selection.focus.path;
6997
- return getBlock(editor, focusPath)?.node ?? getBlock(editor, parentPath(focusPath))?.node;
6983
+ const focusPath = editor.snapshot.context.selection.focus.path;
6984
+ return getBlock(editor.snapshot, focusPath)?.node ?? getBlock(editor.snapshot, parentPath(focusPath))?.node;
6998
6985
  },
6999
6986
  focusChild: () => {
7000
- if (!editor.selection)
6987
+ if (!editor.snapshot.context.selection)
7001
6988
  return;
7002
- const leaf = getLeaf(editor, editor.selection.focus.path, {
6989
+ const leaf = getLeaf(editor.snapshot, editor.snapshot.context.selection.focus.path, {
7003
6990
  edge: "start"
7004
6991
  });
7005
- if (!(!leaf || isBlock(editor, leaf.path)))
6992
+ if (!(!leaf || isBlock(editor.snapshot, leaf.path)))
7006
6993
  return leaf.node;
7007
6994
  },
7008
6995
  insertChild: (type, value) => (editorActor.send({
@@ -7015,7 +7002,7 @@ function createEditableAPI(editor, editorActor) {
7015
7002
  }
7016
7003
  },
7017
7004
  editor
7018
- }), editor.selection?.focus.path ?? []),
7005
+ }), editor.snapshot.context.selection?.focus.path ?? []),
7019
7006
  insertBlock: (type, value) => (editorActor.send({
7020
7007
  type: "behavior event",
7021
7008
  behaviorEvent: {
@@ -7027,7 +7014,7 @@ function createEditableAPI(editor, editorActor) {
7027
7014
  placement: "auto"
7028
7015
  },
7029
7016
  editor
7030
- }), editor.selection?.focus.path ?? []),
7017
+ }), editor.snapshot.context.selection?.focus.path ?? []),
7031
7018
  hasBlockStyle: (style) => {
7032
7019
  try {
7033
7020
  return isStyleActive({
@@ -7049,17 +7036,17 @@ function createEditableAPI(editor, editorActor) {
7049
7036
  }
7050
7037
  },
7051
7038
  isVoid: (element) => {
7052
- const schema = editor.schema;
7039
+ const schema = editor.snapshot.context.schema;
7053
7040
  return ![schema.block.name, schema.span.name].includes(element._type);
7054
7041
  },
7055
7042
  findByPath: (path2) => {
7056
- const result = getNode(editor, path2);
7043
+ const result = getNode(editor.snapshot, path2);
7057
7044
  return result ? [result.node, path2] : [void 0, void 0];
7058
7045
  },
7059
7046
  findDOMNode: (element) => {
7060
7047
  let node;
7061
7048
  try {
7062
- const entry = Array.from(getNodes(editor, {
7049
+ const entry = Array.from(getNodes(editor.snapshot, {
7063
7050
  match: (n) => n._key === element._key
7064
7051
  }))[0];
7065
7052
  if (entry) {
@@ -7071,24 +7058,24 @@ function createEditableAPI(editor, editorActor) {
7071
7058
  return node;
7072
7059
  },
7073
7060
  activeAnnotations: () => {
7074
- if (!editor.selection || editor.selection.focus.path.length < 2)
7061
+ if (!editor.snapshot.context.selection || editor.snapshot.context.selection.focus.path.length < 2)
7075
7062
  return [];
7076
7063
  try {
7077
- const activeAnnotations = [], spans = getNodes(editor, {
7078
- from: rangeStart(editor.selection, editor).path,
7079
- to: rangeEnd(editor.selection, editor).path,
7064
+ const activeAnnotations = [], spans = getNodes(editor.snapshot, {
7065
+ from: rangeStart(editor.snapshot.context.selection, editor.snapshot.context).path,
7066
+ to: rangeEnd(editor.snapshot.context.selection, editor.snapshot.context).path,
7080
7067
  match: (node) => isSpan({
7081
- schema: editor.schema
7068
+ schema: editor.snapshot.context.schema
7082
7069
  }, node) && node.marks !== void 0 && Array.isArray(node.marks) && node.marks.length > 0
7083
7070
  });
7084
7071
  for (const {
7085
7072
  node: span,
7086
7073
  path: spanPath
7087
7074
  } of spans) {
7088
- const blockEntry = getTextBlock(editor, parentPath(spanPath));
7075
+ const blockEntry = getTextBlock(editor.snapshot, parentPath(spanPath));
7089
7076
  blockEntry && blockEntry.node.markDefs?.forEach((def) => {
7090
7077
  isSpan({
7091
- schema: editor.schema
7078
+ schema: editor.snapshot.context.schema
7092
7079
  }, span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
7093
7080
  });
7094
7081
  }
@@ -7152,10 +7139,10 @@ function createEditableAPI(editor, editorActor) {
7152
7139
  editor
7153
7140
  });
7154
7141
  },
7155
- getSelection: () => editor.selection,
7156
- getValue: () => editor.children,
7157
- isCollapsedSelection: () => !!editor.selection && isCollapsedRange(editor.selection),
7158
- isExpandedSelection: () => !!editor.selection && isExpandedRange(editor.selection),
7142
+ getSelection: () => editor.snapshot.context.selection,
7143
+ getValue: () => editor.snapshot.context.value,
7144
+ isCollapsedSelection: () => !!editor.snapshot.context.selection && isCollapsedRange(editor.snapshot.context.selection),
7145
+ isExpandedSelection: () => !!editor.snapshot.context.selection && isExpandedRange(editor.snapshot.context.selection),
7159
7146
  insertBreak: () => {
7160
7147
  editorActor.send({
7161
7148
  type: "behavior event",
@@ -7169,7 +7156,7 @@ function createEditableAPI(editor, editorActor) {
7169
7156
  const snapshot = editor.snapshot;
7170
7157
  return getFragment(snapshot).map((entry) => entry.node);
7171
7158
  },
7172
- isSelectionsOverlapping: (selectionA, selectionB) => !selectionA || !selectionB ? !1 : rangeIncludes(selectionA, selectionB, editor)
7159
+ isSelectionsOverlapping: (selectionA, selectionB) => !selectionA || !selectionB ? !1 : rangeIntersects(editor.snapshot, selectionA, selectionB)
7173
7160
  };
7174
7161
  }
7175
7162
  function createBehaviorApiPlugin(editorActor) {
@@ -7183,7 +7170,7 @@ function createBehaviorApiPlugin(editorActor) {
7183
7170
  select2(location);
7184
7171
  return;
7185
7172
  }
7186
- if (editor.selection) {
7173
+ if (editor.snapshot.context.selection) {
7187
7174
  select2(location);
7188
7175
  return;
7189
7176
  }
@@ -7194,7 +7181,7 @@ function createBehaviorApiPlugin(editorActor) {
7194
7181
  type: "select",
7195
7182
  at: {
7196
7183
  ...range$1,
7197
- backward: isBackwardRange(range$1, editor)
7184
+ backward: isBackwardRange(range$1, editor.snapshot.context)
7198
7185
  }
7199
7186
  },
7200
7187
  editor
@@ -7204,16 +7191,16 @@ function createBehaviorApiPlugin(editorActor) {
7204
7191
  setSelection2(partialRange);
7205
7192
  return;
7206
7193
  }
7207
- const anchor = partialRange.anchor, focus = partialRange.focus, backward = editor.selection ? isBackwardRange({
7208
- anchor: partialRange.anchor ?? editor.selection.anchor,
7209
- focus: partialRange.focus ?? editor.selection.focus
7210
- }, editor) : partialRange.anchor && partialRange.focus ? isBackwardRange({
7194
+ const anchor = partialRange.anchor, focus = partialRange.focus, backward = editor.snapshot.context.selection ? isBackwardRange({
7195
+ anchor: partialRange.anchor ?? editor.snapshot.context.selection.anchor,
7196
+ focus: partialRange.focus ?? editor.snapshot.context.selection.focus
7197
+ }, editor.snapshot.context) : partialRange.anchor && partialRange.focus ? isBackwardRange({
7211
7198
  anchor: partialRange.anchor,
7212
7199
  focus: partialRange.focus
7213
- }, editor) : void 0;
7214
- if (editor.selection) {
7215
- const newAnchor = partialRange.anchor ?? editor.selection.anchor, newFocus = partialRange.focus ?? editor.selection.focus;
7216
- if (pointEquals(newAnchor, editor.selection.anchor) && pointEquals(newFocus, editor.selection.focus)) {
7200
+ }, editor.snapshot.context) : void 0;
7201
+ if (editor.snapshot.context.selection) {
7202
+ const newAnchor = partialRange.anchor ?? editor.snapshot.context.selection.anchor, newFocus = partialRange.focus ?? editor.snapshot.context.selection.focus;
7203
+ if (pointEquals(newAnchor, editor.snapshot.context.selection.anchor) && pointEquals(newFocus, editor.snapshot.context.selection.focus)) {
7217
7204
  setSelection2(partialRange);
7218
7205
  return;
7219
7206
  }
@@ -7240,38 +7227,45 @@ function createBehaviorApiPlugin(editorActor) {
7240
7227
  function createUndoSteps({
7241
7228
  steps,
7242
7229
  op,
7243
- editor,
7244
7230
  currentUndoStepId,
7245
- previousUndoStepId
7231
+ previousUndoStepId,
7232
+ operationsInProgress,
7233
+ isNormalizingNode,
7234
+ selectionBeforeApply
7246
7235
  }) {
7247
7236
  const lastStep = steps.at(-1);
7248
7237
  if (!lastStep)
7249
- return createNewStep(steps, op, editor);
7250
- if (editor.operations.length > 0)
7251
- return currentUndoStepId === previousUndoStepId || editor.isNormalizingNode ? mergeIntoLastStep(steps, lastStep, op) : createNewStep(steps, op, editor);
7238
+ return createNewStep(steps, op, selectionBeforeApply);
7239
+ if (operationsInProgress)
7240
+ return currentUndoStepId === previousUndoStepId || isNormalizingNode ? mergeIntoLastStep(steps, lastStep, op) : createNewStep(steps, op, selectionBeforeApply);
7252
7241
  if (op.type === "set_selection" && currentUndoStepId === void 0 && previousUndoStepId !== void 0 || op.type === "set_selection" && currentUndoStepId !== void 0 && previousUndoStepId !== void 0 && previousUndoStepId !== currentUndoStepId)
7253
7242
  return mergeIntoLastStep(steps, lastStep, op);
7254
7243
  if (currentUndoStepId === void 0 && previousUndoStepId === void 0) {
7255
7244
  if (op.type === "set_selection")
7256
7245
  return mergeIntoLastStep(steps, lastStep, op);
7257
7246
  const lastOp = lastStep.operations.at(-1);
7258
- return lastOp && op.type === "insert_text" && lastOp.type === "insert_text" && op.offset === lastOp.offset + lastOp.text.length && pathEquals(op.path, lastOp.path) && op.text !== " " || lastOp && op.type === "remove_text" && lastOp.type === "remove_text" && op.offset + op.text.length === lastOp.offset && pathEquals(op.path, lastOp.path) ? mergeIntoLastStep(steps, lastStep, op) : createNewStep(steps, op, editor);
7247
+ return lastOp && op.type === "insert_text" && lastOp.type === "insert_text" && op.offset === lastOp.offset + lastOp.text.length && pathEquals(op.path, lastOp.path) && op.text !== " " || lastOp && op.type === "remove_text" && lastOp.type === "remove_text" && op.offset + op.text.length === lastOp.offset && pathEquals(op.path, lastOp.path) ? mergeIntoLastStep(steps, lastStep, op) : createNewStep(steps, op, selectionBeforeApply);
7259
7248
  }
7260
7249
  if (currentUndoStepId !== void 0 && previousUndoStepId !== void 0 && currentUndoStepId !== previousUndoStepId) {
7261
7250
  const lastOp = lastStep.operations.at(-1);
7262
7251
  if (lastOp && op.type === "insert_text" && lastOp.type === "insert_text" && op.offset === lastOp.offset + lastOp.text.length && pathEquals(op.path, lastOp.path) && op.text !== " " || lastOp && op.type === "remove_text" && lastOp.type === "remove_text" && op.offset + op.text.length === lastOp.offset && pathEquals(op.path, lastOp.path))
7263
7252
  return mergeIntoLastStep(steps, lastStep, op);
7264
7253
  }
7265
- return createNewStep(steps, op, editor);
7254
+ if (currentUndoStepId === void 0 && previousUndoStepId !== void 0) {
7255
+ const lastOp = lastStep.operations.at(-1);
7256
+ if (lastOp && op.type === "insert_text" && lastOp.type === "insert_text" && op.offset === lastOp.offset + lastOp.text.length && pathEquals(op.path, lastOp.path) && op.text !== " ")
7257
+ return mergeIntoLastStep(steps, lastStep, op);
7258
+ }
7259
+ return createNewStep(steps, op, selectionBeforeApply);
7266
7260
  }
7267
- function createNewStep(steps, op, editor) {
7268
- const operations = editor.selection === null ? [op] : [{
7261
+ function createNewStep(steps, op, selectionBeforeApply) {
7262
+ const operations = selectionBeforeApply === null ? [op] : [{
7269
7263
  type: "set_selection",
7270
7264
  properties: {
7271
- ...editor.selection
7265
+ ...selectionBeforeApply
7272
7266
  },
7273
7267
  newProperties: {
7274
- ...editor.selection
7268
+ ...selectionBeforeApply
7275
7269
  }
7276
7270
  }, op];
7277
7271
  return steps.push({
@@ -7288,7 +7282,7 @@ function createHistoryPlugin({
7288
7282
  subscriptions
7289
7283
  }) {
7290
7284
  return function(editor) {
7291
- let previousSnapshot = editor.children, previousUndoStepId = editor.undoStepId;
7285
+ let previousSnapshot = editor.snapshot.context.value, previousUndoStepId = editor.undoStepId;
7292
7286
  subscriptions.push(() => {
7293
7287
  const subscription = editorActor.on("patches", ({
7294
7288
  patches,
@@ -7340,15 +7334,22 @@ function createHistoryPlugin({
7340
7334
  previousUndoStepId = currentUndoStepId, apply2(op);
7341
7335
  return;
7342
7336
  }
7337
+ const operationsInProgress = editor.operations.length > 0, isNormalizingNode = editor.isNormalizingNode, selectionBeforeApply = editor.snapshot.context.selection;
7338
+ if (apply2(op), (op.type === "set" || op.type === "unset" || op.type === "insert") && !op.inverse || (op.type === "insert_text" || op.type === "remove_text") && op.text.length === 0) {
7339
+ previousUndoStepId = currentUndoStepId;
7340
+ return;
7341
+ }
7343
7342
  for (op.type !== "set_selection" && editor.history.redos.length > 0 && (editor.history.redos = []), editor.history.undos = createUndoSteps({
7344
7343
  steps: editor.history.undos,
7345
7344
  op,
7346
- editor,
7347
7345
  currentUndoStepId,
7348
- previousUndoStepId
7346
+ previousUndoStepId,
7347
+ operationsInProgress,
7348
+ isNormalizingNode,
7349
+ selectionBeforeApply
7349
7350
  }); editor.history.undos.length > UNDO_STEP_LIMIT; )
7350
7351
  editor.history.undos.shift();
7351
- previousUndoStepId = currentUndoStepId, apply2(op);
7352
+ previousUndoStepId = currentUndoStepId;
7352
7353
  }, editor;
7353
7354
  };
7354
7355
  }
@@ -7378,18 +7379,18 @@ function normalize(editor, options = {}) {
7378
7379
  };
7379
7380
  if (isNormalizing(editor)) {
7380
7381
  if (force) {
7381
- const allPaths = Array.from(getNodes(editor), (entry) => entry.path), allPathKeys = new Set(allPaths.map((p) => serializePath(p)));
7382
+ const allPaths = Array.from(getNodes(editor.snapshot), (entry) => entry.path), allPathKeys = new Set(allPaths.map((p) => serializePath(p)));
7382
7383
  editor.dirtyPaths = allPaths, editor.dirtyPathKeys = allPathKeys;
7383
7384
  }
7384
7385
  getDirtyPaths2(editor).length !== 0 && withoutNormalizing(editor, () => {
7385
7386
  for (const dirtyPath of getDirtyPaths2(editor))
7386
- if (dirtyPath.length !== 0 && hasNode(editor, dirtyPath)) {
7387
- const entry = getNode(editor, dirtyPath);
7387
+ if (dirtyPath.length !== 0 && hasNode(editor.snapshot, dirtyPath)) {
7388
+ const entry = getNode(editor.snapshot, dirtyPath);
7388
7389
  if (!entry)
7389
7390
  continue;
7390
7391
  const entryNode = entry.node;
7391
7392
  isTextBlock({
7392
- schema: editor.schema
7393
+ schema: editor.snapshot.context.schema
7393
7394
  }, entryNode) && entryNode.children.length === 0 && (editor.isNormalizingNode = !0, editor.normalizeNode([entry.node, entry.path], {
7394
7395
  operation
7395
7396
  }), editor.isNormalizingNode = !1);
@@ -7410,8 +7411,8 @@ function normalize(editor, options = {}) {
7410
7411
  editor.isNormalizingNode = !0, editor.normalizeNode([editor, dirtyPath], {
7411
7412
  operation
7412
7413
  }), editor.isNormalizingNode = !1;
7413
- else if (hasNode(editor, dirtyPath)) {
7414
- const entry = getNode(editor, dirtyPath);
7414
+ else if (hasNode(editor.snapshot, dirtyPath)) {
7415
+ const entry = getNode(editor.snapshot, dirtyPath);
7415
7416
  entry && (editor.isNormalizingNode = !0, editor.normalizeNode([entry.node, entry.path], {
7416
7417
  operation
7417
7418
  }), editor.isNormalizingNode = !1);
@@ -8171,9 +8172,9 @@ function createApplyPatch(context) {
8171
8172
  function diffMatchPatch(editor, patch) {
8172
8173
  if (patch.path.at(-1) !== "text")
8173
8174
  return !1;
8174
- const spanPath = patch.path.slice(0, -1), spanEntry = getNode(editor, spanPath);
8175
+ const spanPath = patch.path.slice(0, -1), spanEntry = getNode(editor.snapshot, spanPath);
8175
8176
  if (!spanEntry || !isSpan({
8176
- schema: editor.schema
8177
+ schema: editor.snapshot.context.schema
8177
8178
  }, spanEntry.node))
8178
8179
  return !1;
8179
8180
  const patches = parse(patch.value), [newValue] = apply$1(patches, spanEntry.node.text, {
@@ -8198,7 +8199,7 @@ function insertPatch(context, editor, patch) {
8198
8199
  const {
8199
8200
  items,
8200
8201
  position
8201
- } = patch, editorWasEmptyBefore = patch.path.length === 1 && isEqualToEmptyEditor(context.initialValue, editor.children, context.schema), arrayFieldPath = patch.path.slice(0, -1);
8202
+ } = patch, editorWasEmptyBefore = patch.path.length === 1 && isEqualToEmptyEditor(context.initialValue, editor.snapshot.context.value, context.schema), arrayFieldPath = patch.path.slice(0, -1);
8202
8203
  for (let index = 0; index < items.length; index++)
8203
8204
  if (index === 0)
8204
8205
  editor.apply({
@@ -8229,7 +8230,7 @@ function insertPatch(context, editor, patch) {
8229
8230
  }
8230
8231
  }
8231
8232
  if (editorWasEmptyBefore && typeof patch.path[0] == "number") {
8232
- const removeIdx = position === "before" ? items.length : 0, removeNode = editor.children[removeIdx];
8233
+ const removeIdx = position === "before" ? items.length : 0, removeNode = editor.snapshot.context.value[removeIdx];
8233
8234
  removeNode && editor.apply({
8234
8235
  type: "unset",
8235
8236
  path: [{
@@ -8240,7 +8241,7 @@ function insertPatch(context, editor, patch) {
8240
8241
  return !0;
8241
8242
  }
8242
8243
  function setPatch(editor, patch) {
8243
- return patch.type === "setIfMissing" && (patch.path.length === 0 ? editor.children.length > 0 : getValue(editor.children, patch.path) !== void 0) ? !1 : (editor.apply({
8244
+ return patch.type === "setIfMissing" && (patch.path.length === 0 ? editor.snapshot.context.value.length > 0 : getValue(editor.snapshot.context.value, patch.path) !== void 0) ? !1 : (editor.apply({
8244
8245
  type: "set",
8245
8246
  path: patch.path,
8246
8247
  value: patch.value
@@ -8290,7 +8291,7 @@ function createPatchesPlugin({
8290
8291
  let previousValue;
8291
8292
  const applyPatch = createApplyPatch(editorActor.getSnapshot().context);
8292
8293
  return function(editor) {
8293
- previousValue = [...editor.children];
8294
+ previousValue = [...editor.snapshot.context.value];
8294
8295
  const {
8295
8296
  apply: apply2
8296
8297
  } = editor;
@@ -8329,21 +8330,21 @@ function createPatchesPlugin({
8329
8330
  };
8330
8331
  }), editor.apply = (operation) => {
8331
8332
  let patches = [];
8332
- previousValue = editor.children;
8333
+ previousValue = editor.snapshot.context.value;
8333
8334
  const snapshot = editorActor.getSnapshot(), {
8334
8335
  initialValue,
8335
8336
  schema
8336
8337
  } = snapshot.context, editorWasEmpty = previousValue.length === 1 && isEqualToEmptyEditor(initialValue, previousValue, schema);
8337
8338
  apply2(operation);
8338
- const editorIsEmpty = editor.children.length === 1 && isEqualToEmptyEditor(initialValue, editor.children, schema);
8339
+ const editorIsEmpty = editor.snapshot.context.value.length === 1 && isEqualToEmptyEditor(initialValue, editor.snapshot.context.value, schema);
8339
8340
  if (!editor.isPatching)
8340
8341
  return editor;
8341
8342
  switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches.push(insert(previousValue, "before", [0])), operation.type) {
8342
8343
  case "insert_text":
8343
- patches = [...patches, ...textPatch(editor, operation, previousValue)];
8344
+ patches = [...patches, ...textPatch(editor.snapshot, operation, previousValue)];
8344
8345
  break;
8345
8346
  case "remove_text":
8346
- patches = [...patches, ...textPatch(editor, operation, previousValue)];
8347
+ patches = [...patches, ...textPatch(editor.snapshot, operation, previousValue)];
8347
8348
  break;
8348
8349
  case "insert":
8349
8350
  patches = [...patches, ...insertNodePatch(operation)];
@@ -8367,7 +8368,7 @@ function createPatchesPlugin({
8367
8368
  origin: "local"
8368
8369
  },
8369
8370
  operationId: editor.undoStepId,
8370
- value: editor.children
8371
+ value: editor.snapshot.context.value
8371
8372
  });
8372
8373
  return editor;
8373
8374
  }, editor;
@@ -8380,7 +8381,7 @@ function updateSelectionPlugin({
8380
8381
  const updateSelection = () => {
8381
8382
  editorActor.send({
8382
8383
  type: "update selection",
8383
- selection: editor.selection
8384
+ selection: editor.snapshot.context.selection
8384
8385
  });
8385
8386
  }, {
8386
8387
  onChange
@@ -8459,7 +8460,7 @@ ${safeStringify(operation, 2)}`), operation.type === "set_selection") {
8459
8460
  }
8460
8461
  apply2(operation), operation.path.length <= 2 && buildIndexMaps({
8461
8462
  schema: context.schema,
8462
- value: editor.children
8463
+ value: editor.snapshot.context.value
8463
8464
  }, {
8464
8465
  blockIndexMap: editor.blockIndexMap,
8465
8466
  listIndexMap: editor.listIndexMap
@@ -8661,36 +8662,6 @@ const PathRef = {
8661
8662
  ref.current = point2, point2 == null && ref.unref();
8662
8663
  }
8663
8664
  };
8664
- function isForwardRange(range2, root) {
8665
- return !isBackwardRange(range2, root);
8666
- }
8667
- function resolveRangeAffinities(range2, root, affinity) {
8668
- if (affinity === "inward") {
8669
- const isCollapsed = isCollapsedRange(range2);
8670
- if (isForwardRange(range2, root)) {
8671
- const anchorAffinity2 = "forward";
8672
- return [anchorAffinity2, isCollapsed ? anchorAffinity2 : "backward"];
8673
- }
8674
- const anchorAffinity = "backward";
8675
- return [anchorAffinity, isCollapsed ? anchorAffinity : "forward"];
8676
- }
8677
- return affinity === "outward" ? isForwardRange(range2, root) ? ["backward", "forward"] : ["forward", "backward"] : [affinity, affinity];
8678
- }
8679
- function transformRange(range2, op, root, options = {}) {
8680
- if (range2 === null)
8681
- return null;
8682
- const {
8683
- affinity = "inward"
8684
- } = options, [affinityAnchor, affinityFocus] = resolveRangeAffinities(range2, root, affinity), anchor = transformPoint$1(range2.anchor, op, {
8685
- affinity: affinityAnchor
8686
- }), focus = transformPoint$1(range2.focus, op, {
8687
- affinity: affinityFocus
8688
- });
8689
- return !anchor || !focus ? null : {
8690
- anchor,
8691
- focus
8692
- };
8693
- }
8694
8665
  function transformRangeRef(ref, op, root) {
8695
8666
  const {
8696
8667
  current,
@@ -8731,9 +8702,9 @@ const modifyDescendant = (editor, path2, f) => {
8731
8702
  if (path2.length === 0)
8732
8703
  return;
8733
8704
  const context = {
8734
- schema: editor.schema,
8735
- containers: editor.publicContainers
8736
- }, nodeEntry = getNode(editor, path2);
8705
+ schema: editor.snapshot.context.schema,
8706
+ containers: editor.snapshot.context.containers
8707
+ }, nodeEntry = getNode(editor.snapshot, path2);
8737
8708
  if (!nodeEntry)
8738
8709
  return;
8739
8710
  const node = nodeEntry.node;
@@ -8747,7 +8718,7 @@ const modifyDescendant = (editor, path2, f) => {
8747
8718
  const fieldNames = [];
8748
8719
  {
8749
8720
  let currentNode = {
8750
- value: editor.children
8721
+ value: editor.snapshot.context.value
8751
8722
  }, currentParent;
8752
8723
  for (let i = 0; i < keyedSegments.length; i++) {
8753
8724
  const result = getNodeChildren(context, currentNode, currentParent);
@@ -8771,7 +8742,7 @@ const modifyDescendant = (editor, path2, f) => {
8771
8742
  }
8772
8743
  keyedCount++;
8773
8744
  }
8774
- const ancestorPath = ancestorPathEnd > 0 ? path2.slice(0, ancestorPathEnd) : [], ancestorEntry = getNode(editor, ancestorPath);
8745
+ const ancestorPath = ancestorPathEnd > 0 ? path2.slice(0, ancestorPathEnd) : [], ancestorEntry = getNode(editor.snapshot, ancestorPath);
8775
8746
  if (!ancestorEntry)
8776
8747
  return;
8777
8748
  const ancestorNode = ancestorEntry.node, ancestorRecord = ancestorNode, currentChildren = Array.isArray(ancestorRecord[fieldName]) ? ancestorRecord[fieldName] : [], originalNumericIndex = numericIndices.get(level + 1), childIndex = originalNumericIndex !== void 0 ? originalNumericIndex : findIndexByKey(currentChildren, childKey);
@@ -8788,23 +8759,23 @@ const modifyDescendant = (editor, path2, f) => {
8788
8759
  rootIndex = rootNumericIndex;
8789
8760
  else if (keyedSegments.length > 0) {
8790
8761
  const rootKey = keyedSegments[0]._key;
8791
- editor.blockIndexMap.size === editor.children.length && editor.blockIndexMap.has(rootKey) ? rootIndex = editor.blockIndexMap.get(rootKey) : rootIndex = findIndexByKey(editor.children, rootKey);
8762
+ editor.blockIndexMap.size === editor.snapshot.context.value.length && editor.blockIndexMap.has(rootKey) ? rootIndex = editor.blockIndexMap.get(rootKey) : rootIndex = findIndexByKey(editor.snapshot.context.value, rootKey);
8792
8763
  } else {
8793
8764
  const firstSegment = path2[0];
8794
8765
  rootIndex = typeof firstSegment == "number" ? firstSegment : -1;
8795
8766
  }
8796
- rootIndex === -1 || rootIndex >= editor.children.length || (editor.children = replaceChildren(editor.children, rootIndex, 1, modifiedNode));
8767
+ rootIndex === -1 || rootIndex >= editor.snapshot.context.value.length || (editor.snapshot.context.value = replaceChildren(editor.snapshot.context.value, rootIndex, 1, modifiedNode));
8797
8768
  }, modifyChildren = (editor, path2, f) => {
8798
8769
  if (path2.length === 0)
8799
- editor.children = f(editor.children);
8770
+ editor.snapshot.context.value = f(editor.snapshot.context.value);
8800
8771
  else {
8801
8772
  const context = {
8802
- schema: editor.schema,
8803
- containers: editor.publicContainers
8804
- }, nodeEntry = getNode(editor, path2);
8773
+ schema: editor.snapshot.context.schema,
8774
+ containers: editor.snapshot.context.containers
8775
+ }, nodeEntry = getNode(editor.snapshot, path2);
8805
8776
  if (!nodeEntry)
8806
8777
  return;
8807
- const resolved = resolveContainerAt(context.containers, editor.children, path2);
8778
+ const resolved = resolveContainerAt(context.containers, editor.snapshot.context.value, path2);
8808
8779
  let fieldName;
8809
8780
  resolved && "field" in resolved ? fieldName = resolved.field.name : (isTextBlock(context, nodeEntry.node), fieldName = "children"), modifyDescendant(editor, path2, (node) => {
8810
8781
  const record = node, currentChildren = Array.isArray(record[fieldName]) ? record[fieldName] : [];
@@ -8815,7 +8786,7 @@ const modifyDescendant = (editor, path2, f) => {
8815
8786
  });
8816
8787
  }
8817
8788
  }, modifyLeaf = (editor, path2, f) => modifyDescendant(editor, path2, (node) => isSpan({
8818
- schema: editor.schema
8789
+ schema: editor.snapshot.context.schema
8819
8790
  }, node) ? f(node) : node);
8820
8791
  function applyOperation(editor, op) {
8821
8792
  let transformSelection = !1;
@@ -8832,7 +8803,7 @@ function applyOperation(editor, op) {
8832
8803
  if (modifyChildren(editor, parentPath(path2), (children) => {
8833
8804
  !editor.isProcessingRemoteChanges && !editor.isUndoing && !editor.isRedoing && node._key !== void 0 && children.some((sibling) => sibling._key === node._key) && (node = {
8834
8805
  ...node,
8835
- _key: editor.keyGenerator()
8806
+ _key: editor.snapshot.context.keyGenerator()
8836
8807
  }, op.node = node);
8837
8808
  const lastSegment = path2[path2.length - 1];
8838
8809
  let index;
@@ -8901,11 +8872,22 @@ function applyOperation(editor, op) {
8901
8872
  path: path2,
8902
8873
  value
8903
8874
  } = op;
8875
+ if (!op.inverse && !editor.isProcessingRemoteChanges) {
8876
+ const previousValue = getValue(editor.snapshot.context.value, path2);
8877
+ op.inverse = previousValue === void 0 ? {
8878
+ type: "unset",
8879
+ path: path2
8880
+ } : {
8881
+ type: "set",
8882
+ path: path2,
8883
+ value: previousValue
8884
+ };
8885
+ }
8904
8886
  if (path2.length === 0) {
8905
8887
  if (Array.isArray(value)) {
8906
- editor.children = value, editor.blockIndexMap.clear();
8907
- for (let i = 0; i < editor.children.length; i++) {
8908
- const child = editor.children[i];
8888
+ editor.snapshot.context.value = value, editor.blockIndexMap.clear();
8889
+ for (let i = 0; i < editor.snapshot.context.value.length; i++) {
8890
+ const child = editor.snapshot.context.value[i];
8909
8891
  child && editor.blockIndexMap.set(child._key, i);
8910
8892
  }
8911
8893
  }
@@ -8922,26 +8904,16 @@ function applyOperation(editor, op) {
8922
8904
  value !== null && typeof value == "object" && !Array.isArray(value) && modifyDescendant(editor, setNodePath, () => value), transformSelection = !0;
8923
8905
  break;
8924
8906
  }
8925
- if (getNode(editor, setNodePath))
8907
+ if (getNode(editor.snapshot, setNodePath))
8926
8908
  if (setPropertyPath.length === 1) {
8927
8909
  const propertyName = setPropertyPath[0];
8928
8910
  if (modifyDescendant(editor, setNodePath, (node) => ({
8929
8911
  ...node,
8930
8912
  [propertyName]: value
8931
- })), propertyName === "_key" && setNodePath.length === 1)
8932
- if (op.inverse) {
8933
- const oldKey = op.inverse.type === "set" ? op.inverse.value : void 0, newKey = value;
8934
- if (typeof oldKey == "string" && typeof newKey == "string") {
8935
- const blockIndex = editor.blockIndexMap.get(oldKey);
8936
- blockIndex !== void 0 && (editor.blockIndexMap.delete(oldKey), editor.blockIndexMap.set(newKey, blockIndex));
8937
- }
8938
- } else {
8939
- editor.blockIndexMap.clear();
8940
- for (let i = 0; i < editor.children.length; i++) {
8941
- const child = editor.children[i];
8942
- child && editor.blockIndexMap.set(child._key, i);
8943
- }
8944
- }
8913
+ })), propertyName === "_key" && setNodePath.length === 1 && op.inverse?.type === "set" && typeof op.inverse.value == "string" && typeof value == "string") {
8914
+ const blockIndex = editor.blockIndexMap.get(op.inverse.value);
8915
+ blockIndex !== void 0 && (editor.blockIndexMap.delete(op.inverse.value), editor.blockIndexMap.set(value, blockIndex));
8916
+ }
8945
8917
  } else
8946
8918
  modifyDescendant(editor, setNodePath, (node) => deepSet(node, setPropertyPath, value));
8947
8919
  else {
@@ -8951,11 +8923,11 @@ function applyOperation(editor, op) {
8951
8923
  const blockIndex = resolveBlockIndex(editor, blockKey);
8952
8924
  if (blockIndex === -1)
8953
8925
  break;
8954
- const block = editor.children[blockIndex];
8926
+ const block = editor.snapshot.context.value[blockIndex];
8955
8927
  if (!block)
8956
8928
  break;
8957
- const updatedBlock = applyAll(block, [set(value, path2.slice(1))]), newChildren = editor.children.slice();
8958
- newChildren[blockIndex] = updatedBlock, editor.children = newChildren;
8929
+ const updatedBlock = applyAll(block, [set(value, path2.slice(1))]), newChildren = editor.snapshot.context.value.slice();
8930
+ newChildren[blockIndex] = updatedBlock, editor.snapshot.context.value = newChildren;
8959
8931
  }
8960
8932
  transformSelection = !0;
8961
8933
  break;
@@ -8965,14 +8937,18 @@ function applyOperation(editor, op) {
8965
8937
  path: path2
8966
8938
  } = op;
8967
8939
  if (path2.length === 0) {
8968
- editor.children = [], editor.blockIndexMap.clear(), transformSelection = !0;
8940
+ !op.inverse && !editor.isProcessingRemoteChanges && (op.inverse = {
8941
+ type: "set",
8942
+ path: path2,
8943
+ value: editor.snapshot.context.value
8944
+ }), editor.snapshot.context.value = [], editor.blockIndexMap.clear(), transformSelection = !0;
8969
8945
  break;
8970
8946
  }
8971
8947
  const lastSegment = path2[path2.length - 1];
8972
8948
  if (isKeyedSegment(lastSegment) || typeof lastSegment == "number") {
8973
- if (editor.selection) {
8949
+ if (editor.snapshot.context.selection) {
8974
8950
  let selection = {
8975
- ...editor.selection
8951
+ ...editor.snapshot.context.selection
8976
8952
  };
8977
8953
  for (const [point2, key] of rangePoints(selection)) {
8978
8954
  const result = transformPoint$1(point2, op);
@@ -8983,11 +8959,11 @@ function applyOperation(editor, op) {
8983
8959
  for (const {
8984
8960
  node: n,
8985
8961
  path: p
8986
- } of getNodes(editor))
8962
+ } of getNodes(editor.snapshot))
8987
8963
  if (isSpan({
8988
- schema: editor.schema
8964
+ schema: editor.snapshot.context.schema
8989
8965
  }, n) && !pathEquals(p, path2))
8990
- if (comparePaths(p, path2, editor) === -1)
8966
+ if (comparePaths(p, path2, editor.snapshot.context) === -1)
8991
8967
  prev = [n, p];
8992
8968
  else {
8993
8969
  next = [n, p];
@@ -9003,9 +8979,9 @@ function applyOperation(editor, op) {
9003
8979
  } : selection = null;
9004
8980
  }
9005
8981
  }
9006
- editor.selection = selection ? {
8982
+ editor.snapshot.context.selection = selection ? {
9007
8983
  ...selection,
9008
- backward: isBackwardRange(selection, editor)
8984
+ backward: isBackwardRange(selection, editor.snapshot.context)
9009
8985
  } : null;
9010
8986
  }
9011
8987
  const isRootRemove = parentPath(path2).length === 0;
@@ -9044,7 +9020,17 @@ function applyOperation(editor, op) {
9044
9020
  } = splitNodeAndPropertyPath(path2);
9045
9021
  if (unsetPropertyPath.length === 0 || unsetNodePath.length === 0)
9046
9022
  break;
9047
- if (getNode(editor, unsetNodePath))
9023
+ if (!op.inverse && !editor.isProcessingRemoteChanges) {
9024
+ const previousValue = getValue(editor.snapshot.context.value, path2);
9025
+ if (previousValue === void 0)
9026
+ break;
9027
+ op.inverse = {
9028
+ type: "set",
9029
+ path: path2,
9030
+ value: previousValue
9031
+ };
9032
+ }
9033
+ if (getNode(editor.snapshot, unsetNodePath))
9048
9034
  if (unsetPropertyPath.length === 1) {
9049
9035
  const propertyName = unsetPropertyPath[0];
9050
9036
  modifyDescendant(editor, unsetNodePath, (node) => {
@@ -9062,11 +9048,11 @@ function applyOperation(editor, op) {
9062
9048
  const blockIndex = resolveBlockIndex(editor, blockKey);
9063
9049
  if (blockIndex === -1)
9064
9050
  break;
9065
- const block = editor.children[blockIndex];
9051
+ const block = editor.snapshot.context.value[blockIndex];
9066
9052
  if (!block)
9067
9053
  break;
9068
- const updatedBlock = applyAll(block, [unset(path2.slice(1))]), newChildren = editor.children.slice();
9069
- newChildren[blockIndex] = updatedBlock, editor.children = newChildren;
9054
+ const updatedBlock = applyAll(block, [unset(path2.slice(1))]), newChildren = editor.snapshot.context.value.slice();
9055
+ newChildren[blockIndex] = updatedBlock, editor.snapshot.context.value = newChildren;
9070
9056
  }
9071
9057
  transformSelection = !0;
9072
9058
  break;
@@ -9076,20 +9062,20 @@ function applyOperation(editor, op) {
9076
9062
  newProperties
9077
9063
  } = op;
9078
9064
  if (newProperties == null) {
9079
- editor.selection = null;
9065
+ editor.snapshot.context.selection = null;
9080
9066
  break;
9081
9067
  }
9082
- if (editor.selection == null) {
9068
+ if (editor.snapshot.context.selection == null) {
9083
9069
  if (!isRange(newProperties))
9084
9070
  throw new Error(`Cannot apply an incomplete "set_selection" operation properties ${safeStringify(newProperties)} when there is no current selection.`);
9085
- editor.selection = {
9071
+ editor.snapshot.context.selection = {
9086
9072
  ...newProperties,
9087
- backward: isBackwardRange(newProperties, editor)
9073
+ backward: isBackwardRange(newProperties, editor.snapshot.context)
9088
9074
  };
9089
9075
  break;
9090
9076
  }
9091
9077
  const selection = {
9092
- ...editor.selection
9078
+ ...editor.snapshot.context.selection
9093
9079
  };
9094
9080
  for (const key in newProperties) {
9095
9081
  const value = newProperties[key];
@@ -9100,22 +9086,22 @@ function applyOperation(editor, op) {
9100
9086
  } else
9101
9087
  selection[key] = value;
9102
9088
  }
9103
- editor.selection = {
9089
+ editor.snapshot.context.selection = {
9104
9090
  ...selection,
9105
- backward: isBackwardRange(selection, editor)
9091
+ backward: isBackwardRange(selection, editor.snapshot.context)
9106
9092
  };
9107
9093
  break;
9108
9094
  }
9109
9095
  }
9110
- if (transformSelection && editor.selection) {
9111
- const anchor = transformPoint$1(editor.selection.anchor, op), focus = transformPoint$1(editor.selection.focus, op);
9112
- !anchor || !focus ? editor.selection = null : (anchor !== editor.selection.anchor || focus !== editor.selection.focus) && (editor.selection = {
9096
+ if (transformSelection && editor.snapshot.context.selection) {
9097
+ const anchor = transformPoint$1(editor.snapshot.context.selection.anchor, op), focus = transformPoint$1(editor.snapshot.context.selection.focus, op);
9098
+ !anchor || !focus ? editor.snapshot.context.selection = null : (anchor !== editor.snapshot.context.selection.anchor || focus !== editor.snapshot.context.selection.focus) && (editor.snapshot.context.selection = {
9113
9099
  anchor,
9114
9100
  focus,
9115
9101
  backward: isBackwardRange({
9116
9102
  anchor,
9117
9103
  focus
9118
- }, editor)
9104
+ }, editor.snapshot.context)
9119
9105
  });
9120
9106
  }
9121
9107
  }
@@ -9143,7 +9129,7 @@ function findBlockKey(path2) {
9143
9129
  }
9144
9130
  function resolveBlockIndex(editor, blockKey) {
9145
9131
  const mapIndex = editor.blockIndexMap.get(blockKey);
9146
- return mapIndex !== void 0 ? mapIndex : editor.children.findIndex((child) => child._key === blockKey);
9132
+ return mapIndex !== void 0 ? mapIndex : editor.snapshot.context.value.findIndex((child) => child._key === blockKey);
9147
9133
  }
9148
9134
  function splitNodeAndPropertyPath(path2) {
9149
9135
  let lastKeyedOrNumericIndex = -1;
@@ -9238,8 +9224,8 @@ const apply = (editor, op) => {
9238
9224
  for (const ref of editor.pointRefs)
9239
9225
  PointRef.transform(ref, op);
9240
9226
  for (const ref of editor.rangeRefs)
9241
- transformRangeRef(ref, op, editor);
9242
- if (applyOperation(editor, op), updateDirtyPaths(editor, getDirtyPaths(editor.context, op)), editor.operations.push(op), normalize(editor, {
9227
+ transformRangeRef(ref, op, editor.snapshot.context);
9228
+ if (applyOperation(editor, op), updateDirtyPaths(editor, getDirtyPaths(editor.snapshot.context, op)), editor.operations.push(op), normalize(editor, {
9243
9229
  operation: op
9244
9230
  }), op.type === "set_selection")
9245
9231
  if (op.properties && op.newProperties && op.properties.anchor && op.properties.focus && op.newProperties.anchor && op.newProperties.focus) {
@@ -9251,20 +9237,20 @@ const apply = (editor, op) => {
9251
9237
  focus: op.newProperties.focus
9252
9238
  });
9253
9239
  if (previousSelectionIsCollapsed && newSelectionIsCollapsed) {
9254
- const focusSpan = getSpan(editor, op.properties.focus.path)?.node, newFocusSpan = getSpan(editor, op.newProperties.focus.path)?.node, sameParent = pathEquals(parentPath(op.properties.focus.path), parentPath(op.newProperties.focus.path));
9240
+ const focusSpan = getSpan(editor.snapshot, op.properties.focus.path)?.node, newFocusSpan = getSpan(editor.snapshot, op.newProperties.focus.path)?.node, sameParent = pathEquals(parentPath(op.properties.focus.path), parentPath(op.newProperties.focus.path));
9255
9241
  let movedToNextSpan = !1, movedToPreviousSpan = !1;
9256
9242
  if (sameParent && focusSpan && newFocusSpan) {
9257
- const nextSibling = getSibling(editor, op.properties.focus.path, {
9243
+ const nextSibling = getSibling(editor.snapshot, op.properties.focus.path, {
9258
9244
  direction: "next"
9259
- }), previousSibling = getSibling(editor, op.properties.focus.path, {
9245
+ }), previousSibling = getSibling(editor.snapshot, op.properties.focus.path, {
9260
9246
  direction: "previous"
9261
9247
  });
9262
9248
  movedToNextSpan = nextSibling !== void 0 && pathEquals(nextSibling.path, op.newProperties.focus.path) && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = previousSibling !== void 0 && pathEquals(previousSibling.path, op.newProperties.focus.path) && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
9263
9249
  }
9264
- !movedToNextSpan && !movedToPreviousSpan && (editor.decoratorState = {});
9250
+ !movedToNextSpan && !movedToPreviousSpan && (editor.snapshot.decoratorState = {});
9265
9251
  }
9266
9252
  } else
9267
- editor.decoratorState = {};
9253
+ editor.snapshot.decoratorState = {};
9268
9254
  editor.flushing || (editor.flushing = !0, Promise.resolve().then(() => {
9269
9255
  editor.flushing = !1, editor.onChange({
9270
9256
  operation: op
@@ -9300,12 +9286,12 @@ function pathRef(editor, path2, options = {}) {
9300
9286
  return editor.pathRefs.add(ref), ref;
9301
9287
  }
9302
9288
  function applySplitNode(editor, path2, position) {
9303
- const nodeEntry = getNode(editor, path2);
9289
+ const nodeEntry = getNode(editor.snapshot, path2);
9304
9290
  if (!nodeEntry)
9305
9291
  return;
9306
- const node = nodeEntry.node, newKey = editor.keyGenerator(), movedChildKeys = /* @__PURE__ */ new Set();
9292
+ const node = nodeEntry.node, newKey = editor.snapshot.context.keyGenerator(), movedChildKeys = /* @__PURE__ */ new Set();
9307
9293
  if (isTextBlock({
9308
- schema: editor.schema
9294
+ schema: editor.snapshot.context.schema
9309
9295
  }, node))
9310
9296
  for (let i = position; i < node.children.length; i++)
9311
9297
  movedChildKeys.add(node.children[i]._key);
@@ -9320,31 +9306,31 @@ function applySplitNode(editor, path2, position) {
9320
9306
  for (const ref of editor.rangeRefs) {
9321
9307
  const current = ref.current;
9322
9308
  if (current) {
9323
- const [anchorAffinity, focusAffinity] = resolveRangeAffinities(current, editor, ref.affinity), anchor = transformPointForSplit(current.anchor, path2, position, newKey, movedChildKeys, anchorAffinity ?? "forward"), focus = transformPointForSplit(current.focus, path2, position, newKey, movedChildKeys, focusAffinity ?? "forward");
9309
+ const [anchorAffinity, focusAffinity] = resolveRangeAffinities(current, editor.snapshot.context, ref.affinity), anchor = transformPointForSplit(current.anchor, path2, position, newKey, movedChildKeys, anchorAffinity ?? "forward"), focus = transformPointForSplit(current.focus, path2, position, newKey, movedChildKeys, focusAffinity ?? "forward");
9324
9310
  anchor && focus ? ref.current = {
9325
9311
  anchor,
9326
9312
  focus
9327
9313
  } : (ref.current = null, ref.unref());
9328
9314
  }
9329
9315
  }
9330
- if (editor.selection) {
9331
- const anchor = transformPointForSplit(editor.selection.anchor, path2, position, newKey, movedChildKeys, "forward"), focus = transformPointForSplit(editor.selection.focus, path2, position, newKey, movedChildKeys, "forward");
9332
- anchor && focus && (editor.selection = {
9316
+ if (editor.snapshot.context.selection) {
9317
+ const anchor = transformPointForSplit(editor.snapshot.context.selection.anchor, path2, position, newKey, movedChildKeys, "forward"), focus = transformPointForSplit(editor.snapshot.context.selection.focus, path2, position, newKey, movedChildKeys, "forward");
9318
+ anchor && focus && (editor.snapshot.context.selection = {
9333
9319
  anchor,
9334
9320
  focus,
9335
9321
  backward: isBackwardRange({
9336
9322
  anchor,
9337
9323
  focus
9338
- }, editor)
9324
+ }, editor.snapshot.context)
9339
9325
  });
9340
9326
  }
9341
9327
  const pathRefs = new Set(editor.pathRefs), pointRefs = new Set(editor.pointRefs), rangeRefs = new Set(editor.rangeRefs);
9342
9328
  editor.pathRefs.clear(), editor.pointRefs.clear(), editor.rangeRefs.clear();
9343
- const savedSelection = editor.selection;
9329
+ const savedSelection = editor.snapshot.context.selection;
9344
9330
  try {
9345
9331
  withoutNormalizing(editor, () => {
9346
9332
  if (isSpan({
9347
- schema: editor.schema
9333
+ schema: editor.snapshot.context.schema
9348
9334
  }, node)) {
9349
9335
  const {
9350
9336
  text: _text,
@@ -9366,7 +9352,7 @@ function applySplitNode(editor, path2, position) {
9366
9352
  position: "after"
9367
9353
  });
9368
9354
  } else if (isTextBlock({
9369
- schema: editor.schema
9355
+ schema: editor.snapshot.context.schema
9370
9356
  }, node)) {
9371
9357
  const {
9372
9358
  children: _children,
@@ -9392,7 +9378,7 @@ function applySplitNode(editor, path2, position) {
9392
9378
  }
9393
9379
  });
9394
9380
  } finally {
9395
- editor.selection = savedSelection;
9381
+ editor.snapshot.context.selection = savedSelection;
9396
9382
  for (const ref of pathRefs)
9397
9383
  editor.pathRefs.add(ref);
9398
9384
  for (const ref of pointRefs)
@@ -9454,12 +9440,12 @@ function applyInsertNodeAtPath(editor, node, path2) {
9454
9440
  function applyInsertNodeAtPoint(editor, node, at) {
9455
9441
  withoutNormalizing(editor, () => {
9456
9442
  const match2 = isSpan({
9457
- schema: editor.schema
9443
+ schema: editor.snapshot.context.schema
9458
9444
  }, node) ? (n) => isSpan({
9459
- schema: editor.schema
9445
+ schema: editor.snapshot.context.schema
9460
9446
  }, n) : (n) => isSpan({
9461
- schema: editor.schema
9462
- }, n) || isObject$1(editor, n), nodeEntry = getNode(editor, at.path), entry = nodeEntry && match2(nodeEntry.node) ? nodeEntry : void 0;
9447
+ schema: editor.snapshot.context.schema
9448
+ }, n) || isObject$1(editor.snapshot, n), nodeEntry = getNode(editor.snapshot, at.path), entry = nodeEntry && match2(nodeEntry.node) ? nodeEntry : void 0;
9463
9449
  if (!entry)
9464
9450
  return;
9465
9451
  const matchPath = entry.path, ref = pathRef(editor, matchPath), isAtEnd = isEnd(editor, at, matchPath);
@@ -9478,10 +9464,10 @@ function applyInsertNodeAtPoint(editor, node, at) {
9478
9464
  });
9479
9465
  }
9480
9466
  function applyMergeNode(editor, path2, position) {
9481
- const nodeEntry = getNode(editor, path2);
9467
+ const nodeEntry = getNode(editor.snapshot, path2);
9482
9468
  if (!nodeEntry)
9483
9469
  return;
9484
- const node = nodeEntry.node, prevSibling = getSibling(editor, path2, {
9470
+ const node = nodeEntry.node, prevSibling = getSibling(editor.snapshot, path2, {
9485
9471
  direction: "previous"
9486
9472
  });
9487
9473
  if (!prevSibling)
@@ -9505,20 +9491,20 @@ function applyMergeNode(editor, path2, position) {
9505
9491
  } : (ref.current = null, ref.unref());
9506
9492
  }
9507
9493
  }
9508
- if (editor.selection) {
9509
- const anchor = transformPointForMerge(editor.selection.anchor, path2, prevKey, position), focus = transformPointForMerge(editor.selection.focus, path2, prevKey, position);
9510
- anchor && focus && (editor.selection = {
9494
+ if (editor.snapshot.context.selection) {
9495
+ const anchor = transformPointForMerge(editor.snapshot.context.selection.anchor, path2, prevKey, position), focus = transformPointForMerge(editor.snapshot.context.selection.focus, path2, prevKey, position);
9496
+ anchor && focus && (editor.snapshot.context.selection = {
9511
9497
  anchor,
9512
9498
  focus,
9513
9499
  backward: isBackwardRange({
9514
9500
  anchor,
9515
9501
  focus
9516
- }, editor)
9502
+ }, editor.snapshot.context)
9517
9503
  });
9518
9504
  }
9519
9505
  const pathRefs = new Set(editor.pathRefs), pointRefs = new Set(editor.pointRefs), rangeRefs = new Set(editor.rangeRefs);
9520
9506
  editor.pathRefs.clear(), editor.pointRefs.clear(), editor.rangeRefs.clear();
9521
- const savedSelection = editor.selection, editorAny = editor, savedPendingDiffs = editorAny.pendingDiffs, savedPendingSelection = editorAny.pendingSelection, savedPendingAction = editorAny.pendingAction;
9507
+ const savedSelection = editor.snapshot.context.selection, editorAny = editor, savedPendingDiffs = editorAny.pendingDiffs, savedPendingSelection = editorAny.pendingSelection, savedPendingAction = editorAny.pendingAction;
9522
9508
  if (Array.isArray(savedPendingDiffs) && savedPendingDiffs.length > 0 && (editorAny.pendingDiffs = savedPendingDiffs.map((textDiff) => transformTextDiffForMerge(textDiff, path2, prevKey, position)).filter(Boolean)), savedPendingSelection && typeof savedPendingSelection == "object" && "anchor" in savedPendingSelection && "focus" in savedPendingSelection) {
9523
9509
  const sel = savedPendingSelection, anchor = transformPointForMerge(sel.anchor, path2, prevKey, position), focus = transformPointForMerge(sel.focus, path2, prevKey, position);
9524
9510
  editorAny.pendingSelection = anchor && focus ? {
@@ -9550,7 +9536,7 @@ function applyMergeNode(editor, path2, position) {
9550
9536
  try {
9551
9537
  withoutNormalizing(editor, () => {
9552
9538
  if (isSpan({
9553
- schema: editor.schema
9539
+ schema: editor.snapshot.context.schema
9554
9540
  }, node))
9555
9541
  node.text.length > 0 && editor.apply({
9556
9542
  type: "insert_text",
@@ -9562,11 +9548,11 @@ function applyMergeNode(editor, path2, position) {
9562
9548
  path: path2
9563
9549
  });
9564
9550
  else if (isTextBlock({
9565
- schema: editor.schema
9551
+ schema: editor.snapshot.context.schema
9566
9552
  }, node)) {
9567
- const prevEntry = getNode(editor, prevPath);
9553
+ const prevEntry = getNode(editor.snapshot, prevPath);
9568
9554
  if (!prevEntry || !isTextBlock({
9569
- schema: editor.schema
9555
+ schema: editor.snapshot.context.schema
9570
9556
  }, prevEntry.node))
9571
9557
  return;
9572
9558
  const prevChildren = prevEntry.node.children;
@@ -9594,7 +9580,7 @@ function applyMergeNode(editor, path2, position) {
9594
9580
  }
9595
9581
  });
9596
9582
  } finally {
9597
- editor.selection = savedSelection;
9583
+ editor.snapshot.context.selection = savedSelection;
9598
9584
  for (const ref of pathRefs)
9599
9585
  editor.pathRefs.add(ref);
9600
9586
  for (const ref of pointRefs)
@@ -9679,7 +9665,7 @@ function resolveDefaultStyle(snapshot, path2) {
9679
9665
  return path2 ? getPathSubSchema(snapshot, path2).styles[0]?.name ?? rootFallback : rootFallback;
9680
9666
  }
9681
9667
  function setNodeProperties(editor, props, path2) {
9682
- const nodeEntry = getNode(editor, path2);
9668
+ const nodeEntry = getNode(editor.snapshot, path2);
9683
9669
  if (!nodeEntry)
9684
9670
  return;
9685
9671
  const nodeRecord = nodeEntry.node, propsRecord = props, keys = Object.keys(propsRecord), keyIndex = keys.indexOf("_key");
@@ -9805,16 +9791,16 @@ function createSpanNode(context) {
9805
9791
  }
9806
9792
  const normalizeNode = (editor, entry) => {
9807
9793
  const [node, path2] = entry, nodeRecord = node;
9808
- if (isEditor(node) && node.children.length === 0) {
9794
+ if (isEditor(node) && node.snapshot.context.value.length === 0) {
9809
9795
  withoutPatching(editor, () => {
9810
- applyInsertNodeAtPath(editor, createPlaceholderBlock(editor), [0]);
9796
+ applyInsertNodeAtPath(editor, createPlaceholderBlock(editor.snapshot), [0]);
9811
9797
  });
9812
9798
  return;
9813
9799
  }
9814
9800
  if (isTextBlock({
9815
- schema: editor.schema
9801
+ schema: editor.snapshot.context.schema
9816
9802
  }, node)) {
9817
- const children = getChildren(editor, path2);
9803
+ const children = getChildren(editor.snapshot, path2);
9818
9804
  for (let i = 0; i < children.length - 1; i++) {
9819
9805
  const {
9820
9806
  node: child
@@ -9823,9 +9809,9 @@ const normalizeNode = (editor, entry) => {
9823
9809
  path: nextChildPath
9824
9810
  } = children[i + 1];
9825
9811
  if (isSpan({
9826
- schema: editor.schema
9812
+ schema: editor.snapshot.context.schema
9827
9813
  }, child) && isSpan({
9828
- schema: editor.schema
9814
+ schema: editor.snapshot.context.schema
9829
9815
  }, nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
9830
9816
  debug.normalization("merging spans with same marks"), applyMergeNode(editor, nextChildPath, child.text.length);
9831
9817
  return;
@@ -9833,14 +9819,14 @@ const normalizeNode = (editor, entry) => {
9833
9819
  }
9834
9820
  }
9835
9821
  if (nodeRecord._type === void 0 && path2.length > 0) {
9836
- const parent = getNode(editor, parentPath(path2));
9822
+ const parent = getNode(editor.snapshot, parentPath(path2));
9837
9823
  if (parent && isTextBlock({
9838
- schema: editor.schema
9824
+ schema: editor.snapshot.context.schema
9839
9825
  }, parent.node)) {
9840
9826
  debug.normalization("Setting span type on node without a type"), editor.apply({
9841
9827
  type: "set",
9842
9828
  path: [...path2, "_type"],
9843
- value: editor.schema.span.name,
9829
+ value: editor.snapshot.context.schema.span.name,
9844
9830
  inverse: {
9845
9831
  type: "unset",
9846
9832
  path: [...path2, "_type"]
@@ -9851,7 +9837,7 @@ const normalizeNode = (editor, entry) => {
9851
9837
  debug.normalization("Setting block type on node without a type"), editor.apply({
9852
9838
  type: "set",
9853
9839
  path: [...path2, "_type"],
9854
- value: editor.schema.block.name,
9840
+ value: editor.snapshot.context.schema.block.name,
9855
9841
  inverse: {
9856
9842
  type: "unset",
9857
9843
  path: [...path2, "_type"]
@@ -9860,7 +9846,7 @@ const normalizeNode = (editor, entry) => {
9860
9846
  return;
9861
9847
  }
9862
9848
  if (nodeRecord._key === void 0 && path2.length > 0) {
9863
- const newKey = editor.keyGenerator();
9849
+ const newKey = editor.snapshot.context.keyGenerator();
9864
9850
  debug.normalization("Setting missing key on node");
9865
9851
  const numericPath = [];
9866
9852
  let currentNode;
@@ -9869,7 +9855,7 @@ const normalizeNode = (editor, entry) => {
9869
9855
  currentNode && numericPath.push(segment);
9870
9856
  continue;
9871
9857
  }
9872
- const siblings = currentNode ? currentNode[numericPath[numericPath.length - 1]] ?? [] : editor.children;
9858
+ const siblings = currentNode ? currentNode[numericPath[numericPath.length - 1]] ?? [] : editor.snapshot.context.value;
9873
9859
  if (isKeyedSegment(segment) && segment._key !== void 0)
9874
9860
  numericPath.push(segment), currentNode = Array.prototype.find.call(siblings, (child) => child._key === segment._key);
9875
9861
  else {
@@ -9896,7 +9882,7 @@ const normalizeNode = (editor, entry) => {
9896
9882
  return;
9897
9883
  }
9898
9884
  if (path2.length > 0 && nodeRecord._key !== void 0) {
9899
- const parent = getParent(editor, path2), siblingList = [...parent ? getChildren(editor, parent.path) : editor.children.map((child, index) => ({
9885
+ const parent = getParent(editor.snapshot, path2), siblingList = [...parent ? getChildren(editor.snapshot, parent.path) : editor.snapshot.context.value.map((child, index) => ({
9900
9886
  node: child,
9901
9887
  path: [{
9902
9888
  _key: child._key
@@ -9909,9 +9895,9 @@ const normalizeNode = (editor, entry) => {
9909
9895
  if (firstIndex === -1)
9910
9896
  firstIndex = i;
9911
9897
  else {
9912
- const newKey = editor.keyGenerator();
9898
+ const newKey = editor.snapshot.context.keyGenerator();
9913
9899
  debug.normalization("Fixing duplicate key on node");
9914
- const dupParentPath = parent ? parent.path : [], numericPath = dupParentPath.length === 0 ? [i] : [...dupParentPath, getChildFieldName(editor.context, parent.path) ?? "children", i];
9900
+ const dupParentPath = parent ? parent.path : [], numericPath = dupParentPath.length === 0 ? [i] : [...dupParentPath, getChildFieldName(editor.snapshot.context, parent.path) ?? "children", i];
9915
9901
  editor.apply({
9916
9902
  type: "set",
9917
9903
  path: [...numericPath, "_key"],
@@ -9926,7 +9912,7 @@ const normalizeNode = (editor, entry) => {
9926
9912
  }
9927
9913
  }
9928
9914
  if (isTextBlockNode({
9929
- schema: editor.schema
9915
+ schema: editor.snapshot.context.schema
9930
9916
  }, node) && !Array.isArray(node.markDefs)) {
9931
9917
  debug.normalization("adding .markDefs to block node"), setNodeProperties(editor, {
9932
9918
  markDefs: []
@@ -9934,9 +9920,9 @@ const normalizeNode = (editor, entry) => {
9934
9920
  return;
9935
9921
  }
9936
9922
  if (isTextBlockNode({
9937
- schema: editor.schema
9923
+ schema: editor.snapshot.context.schema
9938
9924
  }, node) && typeof node.style > "u") {
9939
- const defaultStyle = getPathSubSchema(editor, path2).styles.at(0)?.name;
9925
+ const defaultStyle = getPathSubSchema(editor.snapshot, path2).styles.at(0)?.name;
9940
9926
  if (defaultStyle) {
9941
9927
  debug.normalization("adding .style to block node"), setNodeProperties(editor, {
9942
9928
  style: defaultStyle
@@ -9944,7 +9930,7 @@ const normalizeNode = (editor, entry) => {
9944
9930
  return;
9945
9931
  }
9946
9932
  }
9947
- if (isSpanNode(editor, node) && typeof node.text != "string") {
9933
+ if (isSpanNode(editor.snapshot.context, node) && typeof node.text != "string") {
9948
9934
  debug.normalization("Adding .text to span node"), editor.apply({
9949
9935
  type: "set",
9950
9936
  path: [...path2, "text"],
@@ -9957,7 +9943,7 @@ const normalizeNode = (editor, entry) => {
9957
9943
  return;
9958
9944
  }
9959
9945
  if (isSpan({
9960
- schema: editor.schema
9946
+ schema: editor.snapshot.context.schema
9961
9947
  }, node) && !Array.isArray(node.marks)) {
9962
9948
  debug.normalization("Adding .marks to span node"), setNodeProperties(editor, {
9963
9949
  marks: []
@@ -9965,12 +9951,12 @@ const normalizeNode = (editor, entry) => {
9965
9951
  return;
9966
9952
  }
9967
9953
  if (isSpan({
9968
- schema: editor.schema
9954
+ schema: editor.snapshot.context.schema
9969
9955
  }, node)) {
9970
9956
  const blockPath = parentPath(path2);
9971
- if (!getTextBlock(editor, blockPath))
9957
+ if (!getTextBlock(editor.snapshot, blockPath))
9972
9958
  return;
9973
- const decorators = getPathSubSchema(editor, path2).decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators.includes(mark));
9959
+ const decorators = getPathSubSchema(editor.snapshot, path2).decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators.includes(mark));
9974
9960
  if (node.text === "" && annotations && annotations.length > 0) {
9975
9961
  debug.normalization("removing annotations from empty span node"), setNodeProperties(editor, {
9976
9962
  marks: node.marks?.filter((mark) => decorators.includes(mark))
@@ -9979,15 +9965,15 @@ const normalizeNode = (editor, entry) => {
9979
9965
  }
9980
9966
  }
9981
9967
  if (isTextBlock({
9982
- schema: editor.schema
9968
+ schema: editor.snapshot.context.schema
9983
9969
  }, node)) {
9984
- const decorators = getPathSubSchema(editor, path2).decorators.map((decorator) => decorator.name);
9970
+ const decorators = getPathSubSchema(editor.snapshot, path2).decorators.map((decorator) => decorator.name);
9985
9971
  for (const {
9986
9972
  node: child,
9987
9973
  path: childPath
9988
- } of getChildren(editor, path2))
9974
+ } of getChildren(editor.snapshot, path2))
9989
9975
  if (isSpan({
9990
- schema: editor.schema
9976
+ schema: editor.snapshot.context.schema
9991
9977
  }, child)) {
9992
9978
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
9993
9979
  if (orphanedAnnotations.length > 0) {
@@ -9999,11 +9985,11 @@ const normalizeNode = (editor, entry) => {
9999
9985
  }
10000
9986
  }
10001
9987
  if (isSpan({
10002
- schema: editor.schema
9988
+ schema: editor.snapshot.context.schema
10003
9989
  }, node)) {
10004
- const blockPath = parentPath(path2), blockEntry2 = getTextBlock(editor, blockPath);
9990
+ const blockPath = parentPath(path2), blockEntry2 = getTextBlock(editor.snapshot, blockPath);
10005
9991
  if (blockEntry2) {
10006
- const block = blockEntry2.node, decorators = getPathSubSchema(editor, path2).decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
9992
+ const block = blockEntry2.node, decorators = getPathSubSchema(editor.snapshot, path2).decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
10007
9993
  if (orphanedAnnotations.length > 0) {
10008
9994
  debug.normalization("removing orphaned annotations from span node"), setNodeProperties(editor, {
10009
9995
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -10013,7 +9999,7 @@ const normalizeNode = (editor, entry) => {
10013
9999
  }
10014
10000
  }
10015
10001
  if (isTextBlock({
10016
- schema: editor.schema
10002
+ schema: editor.snapshot.context.schema
10017
10003
  }, node)) {
10018
10004
  const markDefs = node.markDefs ?? [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
10019
10005
  for (const markDef of markDefs)
@@ -10026,10 +10012,10 @@ const normalizeNode = (editor, entry) => {
10026
10012
  }
10027
10013
  }
10028
10014
  if (isTextBlock({
10029
- schema: editor.schema
10015
+ schema: editor.snapshot.context.schema
10030
10016
  }, node)) {
10031
10017
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => isSpan({
10032
- schema: editor.schema
10018
+ schema: editor.snapshot.context.schema
10033
10019
  }, child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
10034
10020
  if (node.markDefs && !isEqualMarkDefs(newMarkDefs, node.markDefs)) {
10035
10021
  debug.normalization("removing markDef not in use"), setNodeProperties(editor, {
@@ -10039,7 +10025,7 @@ const normalizeNode = (editor, entry) => {
10039
10025
  }
10040
10026
  }
10041
10027
  if (isSpanNode({
10042
- schema: editor.schema
10028
+ schema: editor.snapshot.context.schema
10043
10029
  }, node)) {
10044
10030
  if (typeof node.text != "string") {
10045
10031
  debug.normalization("Adding .text to span node"), editor.apply({
@@ -10055,16 +10041,20 @@ const normalizeNode = (editor, entry) => {
10055
10041
  }
10056
10042
  return;
10057
10043
  }
10058
- if (isObject$1(editor, node)) {
10059
- const resolved = resolveContainerByPath(editor, path2, node), arrayField = resolved && "container" in resolved ? resolved.field : void 0;
10044
+ if (isObject$1(editor.snapshot, node)) {
10045
+ const resolved = resolveContainerByPath({
10046
+ containers: editor.containers,
10047
+ schema: editor.snapshot.context.schema,
10048
+ value: editor.snapshot.context.value
10049
+ }, path2, node), arrayField = resolved && "container" in resolved ? resolved.field : void 0;
10060
10050
  if (arrayField) {
10061
10051
  const fieldValue = node[arrayField.name], needsField = !Array.isArray(fieldValue);
10062
10052
  if (needsField || fieldValue.length === 0) {
10063
10053
  const acceptsBlocks = arrayField.of.some((definition) => definition.type === "block"), firstChildType = arrayField.of.at(0);
10064
10054
  let childNode;
10065
- if (acceptsBlocks ? childNode = createPlaceholderBlock(editor, [...path2, arrayField.name, 0]) : firstChildType && firstChildType.type !== "block" && (childNode = {
10055
+ if (acceptsBlocks ? childNode = createPlaceholderBlock(editor.snapshot, [...path2, arrayField.name, 0]) : firstChildType && firstChildType.type !== "block" && (childNode = {
10066
10056
  _type: firstChildType.type === "object" && "name" in firstChildType ? firstChildType.name : firstChildType.type,
10067
- _key: editor.keyGenerator()
10057
+ _key: editor.snapshot.context.keyGenerator()
10068
10058
  }), needsField && childNode) {
10069
10059
  setNodeProperties(editor, {
10070
10060
  [arrayField.name]: [childNode]
@@ -10089,16 +10079,16 @@ const normalizeNode = (editor, entry) => {
10089
10079
  }
10090
10080
  }
10091
10081
  }
10092
- if (isObject$1(editor, node)) {
10093
- const children = [...getChildren(editor, path2)];
10082
+ if (isObject$1(editor.snapshot, node)) {
10083
+ const children = [...getChildren(editor.snapshot, path2)];
10094
10084
  if (children.length > 1) {
10095
10085
  const seen = /* @__PURE__ */ new Map();
10096
10086
  for (let i = 0; i < children.length; i++) {
10097
10087
  const key = children[i].node._key;
10098
10088
  if (key !== void 0 && seen.has(key)) {
10099
- const newKey = editor.keyGenerator();
10089
+ const newKey = editor.snapshot.context.keyGenerator();
10100
10090
  debug.normalization("Fixing duplicate key on container child");
10101
- const arrayFieldName = getChildFieldName(editor.context, path2);
10091
+ const arrayFieldName = getChildFieldName(editor.snapshot.context, path2);
10102
10092
  if (arrayFieldName) {
10103
10093
  editor.apply({
10104
10094
  type: "set",
@@ -10119,9 +10109,10 @@ const normalizeNode = (editor, entry) => {
10119
10109
  return;
10120
10110
  }
10121
10111
  if (isTextBlockNode({
10122
- schema: editor.schema
10112
+ schema: editor.snapshot.context.schema
10123
10113
  }, node)) {
10124
- if (!Array.isArray(node.children)) {
10114
+ let element = node;
10115
+ if (!Array.isArray(element.children)) {
10125
10116
  editor.apply({
10126
10117
  type: "set",
10127
10118
  path: [...path2, "children"],
@@ -10133,16 +10124,15 @@ const normalizeNode = (editor, entry) => {
10133
10124
  });
10134
10125
  return;
10135
10126
  }
10136
- let element = node;
10137
10127
  if (element.children.length === 0) {
10138
- const child = createSpanNode(editor);
10128
+ const child = createSpanNode(editor.snapshot.context);
10139
10129
  editor.apply({
10140
10130
  type: "insert",
10141
10131
  path: [...path2, "children", 0],
10142
10132
  node: child,
10143
10133
  position: "before"
10144
10134
  });
10145
- const refetched = getTextBlock(editor, path2)?.node;
10135
+ const refetched = getTextBlock(editor.snapshot, path2)?.node;
10146
10136
  if (!refetched)
10147
10137
  return;
10148
10138
  element = refetched;
@@ -10152,17 +10142,17 @@ const normalizeNode = (editor, entry) => {
10152
10142
  _key: child._key
10153
10143
  }];
10154
10144
  if (isSpan({
10155
- schema: editor.schema
10145
+ schema: editor.snapshot.context.schema
10156
10146
  }, child)) {
10157
10147
  if (prev != null && isSpan({
10158
- schema: editor.schema
10148
+ schema: editor.snapshot.context.schema
10159
10149
  }, prev)) {
10160
10150
  if (child.text === "") {
10161
10151
  editor.apply({
10162
10152
  type: "unset",
10163
10153
  path: childPath
10164
10154
  });
10165
- const refetched = getTextBlock(editor, path2)?.node;
10155
+ const refetched = getTextBlock(editor.snapshot, path2)?.node;
10166
10156
  if (!refetched)
10167
10157
  return;
10168
10158
  element = refetched, n--;
@@ -10174,7 +10164,7 @@ const normalizeNode = (editor, entry) => {
10174
10164
  type: "unset",
10175
10165
  path: prevPath
10176
10166
  });
10177
- const refetched = getTextBlock(editor, path2)?.node;
10167
+ const refetched = getTextBlock(editor.snapshot, path2)?.node;
10178
10168
  if (!refetched)
10179
10169
  return;
10180
10170
  element = refetched, n--;
@@ -10182,30 +10172,30 @@ const normalizeNode = (editor, entry) => {
10182
10172
  loose: !0
10183
10173
  })) {
10184
10174
  applyMergeNode(editor, childPath, prev.text.length);
10185
- const refetched = getTextBlock(editor, path2)?.node;
10175
+ const refetched = getTextBlock(editor.snapshot, path2)?.node;
10186
10176
  if (!refetched)
10187
10177
  return;
10188
10178
  element = refetched, n--;
10189
10179
  }
10190
10180
  }
10191
- } else if (isObject$1(editor, child)) {
10181
+ } else if (isObject$1(editor.snapshot, child)) {
10192
10182
  if (prev == null || !isSpan({
10193
- schema: editor.schema
10183
+ schema: editor.snapshot.context.schema
10194
10184
  }, prev)) {
10195
- const newChild = createSpanNode(editor);
10185
+ const newChild = createSpanNode(editor.snapshot.context);
10196
10186
  editor.apply({
10197
10187
  type: "insert",
10198
10188
  path: childPath,
10199
10189
  node: newChild,
10200
10190
  position: "before"
10201
10191
  });
10202
- const refetched = getTextBlock(editor, path2)?.node;
10192
+ const refetched = getTextBlock(editor.snapshot, path2)?.node;
10203
10193
  if (!refetched)
10204
10194
  return;
10205
10195
  element = refetched, n++;
10206
10196
  }
10207
10197
  if (n === element.children.length - 1) {
10208
- const newChild = createSpanNode(editor);
10198
+ const newChild = createSpanNode(editor.snapshot.context);
10209
10199
  editor.apply({
10210
10200
  type: "insert",
10211
10201
  path: [...path2, "children", {
@@ -10214,7 +10204,7 @@ const normalizeNode = (editor, entry) => {
10214
10204
  node: newChild,
10215
10205
  position: "after"
10216
10206
  });
10217
- const refetched = getTextBlock(editor, path2)?.node;
10207
+ const refetched = getTextBlock(editor.snapshot, path2)?.node;
10218
10208
  if (!refetched)
10219
10209
  return;
10220
10210
  element = refetched, n++;
@@ -10225,9 +10215,7 @@ const normalizeNode = (editor, entry) => {
10225
10215
  }
10226
10216
  };
10227
10217
  function select(editor, target) {
10228
- const {
10229
- selection
10230
- } = editor;
10218
+ const selection = editor.snapshot.context.selection;
10231
10219
  if (target = range(editor, target), selection) {
10232
10220
  editor.setSelection(target);
10233
10221
  return;
@@ -10241,9 +10229,7 @@ function select(editor, target) {
10241
10229
  });
10242
10230
  }
10243
10231
  function setSelection(editor, props) {
10244
- const {
10245
- selection
10246
- } = editor, oldProps = {}, newProps = {};
10232
+ const selection = editor.snapshot.context.selection, oldProps = {}, newProps = {};
10247
10233
  if (selection) {
10248
10234
  for (const k in props)
10249
10235
  (k === "anchor" && props.anchor != null && !pointEquals(props.anchor, selection.anchor) || k === "focus" && props.focus != null && !pointEquals(props.focus, selection.focus) || k !== "anchor" && k !== "focus" && props[k] !== selection[k]) && (oldProps[k] = selection[k], newProps[k] = props[k]);
@@ -10265,20 +10251,7 @@ const shouldNormalize = (_editor, {
10265
10251
  }, createEditor = () => {
10266
10252
  const e = {
10267
10253
  [EDITOR_BRAND]: !0,
10268
- children: [],
10269
- get value() {
10270
- return this.children;
10271
- },
10272
- get context() {
10273
- return {
10274
- schema: this.schema,
10275
- containers: this.publicContainers,
10276
- value: this.children,
10277
- keyGenerator: this.keyGenerator
10278
- };
10279
- },
10280
10254
  operations: [],
10281
- selection: null,
10282
10255
  marks: null,
10283
10256
  dirtyPaths: [],
10284
10257
  dirtyPathKeys: /* @__PURE__ */ new Set(),
@@ -10333,29 +10306,6 @@ const shouldNormalize = (_editor, {
10333
10306
  onContextChange && onContextChange(options), onChange(options);
10334
10307
  }, e;
10335
10308
  };
10336
- function defaultCompare(a, b) {
10337
- return a === b;
10338
- }
10339
- function useEditorSelector(editor, selector, t0) {
10340
- return useSelector(editor, selector, t0 === void 0 ? defaultCompare : t0);
10341
- }
10342
- function getEditorSnapshot({
10343
- editorEngineInstance
10344
- }) {
10345
- return {
10346
- blockIndexMap: editorEngineInstance.blockIndexMap,
10347
- context: {
10348
- containers: editorEngineInstance.publicContainers,
10349
- converters: editorEngineInstance.converters,
10350
- keyGenerator: editorEngineInstance.keyGenerator,
10351
- readOnly: editorEngineInstance.readOnly,
10352
- schema: editorEngineInstance.schema,
10353
- selection: editorEngineInstance.selection,
10354
- value: editorEngineInstance.children
10355
- },
10356
- decoratorState: editorEngineInstance.decoratorState
10357
- };
10358
- }
10359
10309
  function createEditorEngine(config) {
10360
10310
  debug.setup("creating new editor engine instance");
10361
10311
  const context = config.editorActor.getSnapshot().context, placeholderBlock = createPlaceholderBlock({
@@ -10369,10 +10319,22 @@ function createEditorEngine(config) {
10369
10319
  },
10370
10320
  blockIndexMap: /* @__PURE__ */ new Map()
10371
10321
  }), editor = createEditor();
10372
- 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 = {
10322
+ editor.snapshot = {
10323
+ blockIndexMap: /* @__PURE__ */ new Map(),
10324
+ context: {
10325
+ containers: /* @__PURE__ */ new Map(),
10326
+ converters: context.initialConverters,
10327
+ keyGenerator: context.keyGenerator,
10328
+ readOnly: context.initialReadOnly,
10329
+ schema: context.schema,
10330
+ selection: null,
10331
+ value: [placeholderBlock]
10332
+ },
10333
+ decoratorState: {}
10334
+ }, editor.containers = /* @__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.blockIndexMap = editor.snapshot.blockIndexMap, editor.history = {
10373
10335
  undos: [],
10374
10336
  redos: []
10375
- }, 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;
10337
+ }, editor.listIndexMap = /* @__PURE__ */ new Map(), editor.remotePatches = [], editor.undoStepId = void 0, editor.isDeferringMutations = !1, editor.isNormalizingNode = !1, editor.isPatching = !0, editor.isPerformingBehaviorOperation = !1, editor.isProcessingRemoteChanges = !1, editor.isRedoing = !1, editor.isUndoing = !1, editor.withHistory = !0;
10376
10338
  const editorEngine = plugins(withDOM(editor), {
10377
10339
  editorActor: config.editorActor,
10378
10340
  relayActor: config.relayActor,
@@ -10380,17 +10342,18 @@ function createEditorEngine(config) {
10380
10342
  });
10381
10343
  return buildIndexMaps({
10382
10344
  schema: context.schema,
10383
- value: editorEngine.children
10345
+ value: editorEngine.snapshot.context.value
10384
10346
  }, {
10385
10347
  blockIndexMap: editorEngine.blockIndexMap,
10386
10348
  listIndexMap: editorEngine.listIndexMap
10387
- }), editorEngine.snapshot = getEditorSnapshot({
10388
- editorEngineInstance: editorEngine
10389
10349
  }), config.subscriptions.push(() => {
10390
10350
  const subscription = config.editorActor.subscribe(() => {
10391
- editorEngine.snapshot = getEditorSnapshot({
10392
- editorEngineInstance: editorEngine
10393
- });
10351
+ editorEngine.snapshot = {
10352
+ ...editorEngine.snapshot,
10353
+ context: {
10354
+ ...editorEngine.snapshot.context
10355
+ }
10356
+ };
10394
10357
  });
10395
10358
  return () => {
10396
10359
  subscription.unsubscribe();
@@ -10431,9 +10394,9 @@ function getChildNodes(editorEngine, snapshot) {
10431
10394
  if (!snapshot.context.selection)
10432
10395
  return [];
10433
10396
  try {
10434
- const [start2, end2] = rangeEdges(snapshot.context.selection, editorEngine), childEntries = [];
10397
+ const [start2, end2] = rangeEdges(snapshot.context.selection, editorEngine.snapshot.context), childEntries = [];
10435
10398
  let buffered;
10436
- for (const entry of getNodes(editorEngine, {
10399
+ for (const entry of getNodes(editorEngine.snapshot, {
10437
10400
  from: start2.path,
10438
10401
  to: end2.path
10439
10402
  })) {
@@ -11103,7 +11066,7 @@ function isDropTargetingDragOrigin(dropSelection, dragOriginSelection, snapshot)
11103
11066
  if (isCollapsedRange(dropSelection) || isCollapsedRange(dragOriginSelection))
11104
11067
  return !0;
11105
11068
  const root = {
11106
- children: snapshot.context.value
11069
+ value: snapshot.context.value
11107
11070
  }, [startA, endA] = rangeEdges(dropSelection, root), [startB, endB] = rangeEdges(dragOriginSelection, root);
11108
11071
  return !(comparePoints(endA, startB, root) === 0 || comparePoints(endB, startA, root) === 0);
11109
11072
  }
@@ -12012,19 +11975,19 @@ function createEditorSnapshot({
12012
11975
  readOnly,
12013
11976
  schema
12014
11977
  }) {
12015
- const selection = editor.selection, context = {
12016
- containers: editor.publicContainers,
11978
+ const selection = editor.snapshot.context.selection, context = {
11979
+ containers: editor.snapshot.context.containers,
12017
11980
  converters,
12018
11981
  keyGenerator,
12019
11982
  readOnly,
12020
11983
  schema,
12021
11984
  selection,
12022
- value: editor.children
11985
+ value: editor.snapshot.context.value
12023
11986
  };
12024
11987
  return {
12025
11988
  blockIndexMap: editor.blockIndexMap,
12026
11989
  context,
12027
- decoratorState: editor.decoratorState
11990
+ decoratorState: editor.snapshot.decoratorState
12028
11991
  };
12029
11992
  }
12030
11993
  function withPerformingBehaviorOperation(editor, fn) {
@@ -12040,7 +12003,7 @@ const addAnnotationOperationImplementation = ({
12040
12003
  }) => {
12041
12004
  const {
12042
12005
  context
12043
- } = snapshot, editor = operation.editor, at = operation.at ? resolveSelection(operation.editor, operation.at) : null, effectiveSelection = at ?? editor.selection, anchorPath = effectiveSelection?.anchor.path, annotationSchema = anchorPath ? getPathSubSchema(snapshot, anchorPath) : context.schema, parsedAnnotation = parseAnnotation({
12006
+ } = snapshot, editor = operation.editor, at = operation.at ? resolveSelection(operation.editor, operation.at) : null, effectiveSelection = at ?? editor.snapshot.context.selection, anchorPath = effectiveSelection?.anchor.path, annotationSchema = anchorPath ? getPathSubSchema(snapshot, anchorPath) : context.schema, parsedAnnotation = parseAnnotation({
12044
12007
  annotation: {
12045
12008
  _type: operation.annotation.name,
12046
12009
  _key: operation.annotation._key,
@@ -12058,13 +12021,13 @@ const addAnnotationOperationImplementation = ({
12058
12021
  return;
12059
12022
  const ref = at ? rangeRef(editor, at, {
12060
12023
  affinity: "inward"
12061
- }) : null, selectedBlocks = Array.from(getNodes(editor, {
12062
- from: rangeStart(effectiveSelection, editor).path,
12063
- to: rangeEnd(effectiveSelection, editor).path,
12024
+ }) : null, selectedBlocks = Array.from(getNodes(editor.snapshot, {
12025
+ from: rangeStart(effectiveSelection, editor.snapshot.context).path,
12026
+ to: rangeEnd(effectiveSelection, editor.snapshot.context).path,
12064
12027
  match: (node) => isTextBlock({
12065
- schema: editor.schema
12028
+ schema: editor.snapshot.context.schema
12066
12029
  }, node),
12067
- reverse: isBackwardRange(effectiveSelection, editor)
12030
+ reverse: isBackwardRange(effectiveSelection, editor.snapshot.context)
12068
12031
  }));
12069
12032
  let blockIndex = 0;
12070
12033
  withoutNormalizing(editor, () => {
@@ -12073,7 +12036,7 @@ const addAnnotationOperationImplementation = ({
12073
12036
  path: blockPath
12074
12037
  } of selectedBlocks) {
12075
12038
  if (!isTextBlock({
12076
- schema: editor.schema
12039
+ schema: editor.snapshot.context.schema
12077
12040
  }, block) || block.children.length === 0 || block.children.length === 1 && block.children[0]?.text === "" || !getPathSubSchema(snapshot, blockPath).annotations.some((annotation) => annotation.name === parsedAnnotation._type))
12078
12041
  continue;
12079
12042
  const annotationKey = blockIndex === 0 ? parsedAnnotation._key : context.keyGenerator(), markDefs = block.markDefs ?? [];
@@ -12083,28 +12046,28 @@ const addAnnotationOperationImplementation = ({
12083
12046
  _key: annotationKey
12084
12047
  }]
12085
12048
  }, blockPath);
12086
- const splitRange = at ?? editor.selection;
12049
+ const splitRange = at ?? editor.snapshot.context.selection;
12087
12050
  if (splitRange && isRange(splitRange)) {
12088
- const splitLeaf = getNode(editor, splitRange.anchor.path)?.node;
12051
+ const splitLeaf = getNode(editor.snapshot, splitRange.anchor.path)?.node;
12089
12052
  if (!(splitLeaf && isCollapsedRange(splitRange) && isSpan({
12090
- schema: editor.schema
12053
+ schema: editor.snapshot.context.schema
12091
12054
  }, splitLeaf) && splitLeaf.text.length > 0)) {
12092
12055
  const splitRangeRef = rangeRef(editor, splitRange, {
12093
12056
  affinity: "inward"
12094
- }), [splitStart, splitEnd] = rangeEdges(splitRange, editor);
12057
+ }), [splitStart, splitEnd] = rangeEdges(splitRange, editor.snapshot.context);
12095
12058
  (!isEnd(editor, splitEnd, splitEnd.path) || !isEdge(editor, splitEnd, splitEnd.path)) && applySplitNode(editor, splitEnd.path, splitEnd.offset), (!isStart(editor, splitStart, splitStart.path) || !isEdge(editor, splitStart, splitStart.path)) && applySplitNode(editor, splitStart.path, splitStart.offset);
12096
12059
  const updatedSplitRange = splitRangeRef.unref();
12097
12060
  !at && updatedSplitRange && applySelect(editor, updatedSplitRange);
12098
12061
  }
12099
12062
  }
12100
- const children = getChildren(editor, blockPath), selectionRange = ref?.current ?? editor.selection;
12063
+ const children = getChildren(editor.snapshot, blockPath), selectionRange = ref?.current ?? editor.snapshot.context.selection;
12101
12064
  for (const {
12102
12065
  node: span,
12103
12066
  path: spanPath
12104
12067
  } of children) {
12105
12068
  if (!isSpan({
12106
- schema: editor.schema
12107
- }, span) || !selectionRange || !rangeIncludes(selectionRange, spanPath, editor))
12069
+ schema: editor.snapshot.context.schema
12070
+ }, span) || !selectionRange || !rangeIntersects(editor.snapshot, selectionRange, spanPath))
12108
12071
  continue;
12109
12072
  const marks = span.marks ?? [];
12110
12073
  setNodeProperties(editor, {
@@ -12125,12 +12088,12 @@ const removeAnnotationOperationImplementation = ({
12125
12088
  snapshot,
12126
12089
  operation
12127
12090
  }) => {
12128
- const editor = operation.editor, at = operation.at ? resolveSelection(operation.editor, operation.at) : null, effectiveSelection = at ?? editor.selection;
12091
+ const editor = operation.editor, at = operation.at ? resolveSelection(operation.editor, operation.at) : null, effectiveSelection = at ?? editor.snapshot.context.selection;
12129
12092
  if (effectiveSelection)
12130
12093
  if (isCollapsedRange(effectiveSelection)) {
12131
12094
  const blockEntry = getParent(snapshot, effectiveSelection.focus.path, {
12132
12095
  match: (node) => isTextBlock({
12133
- schema: editor.schema
12096
+ schema: editor.snapshot.context.schema
12134
12097
  }, node)
12135
12098
  });
12136
12099
  if (!blockEntry)
@@ -12138,7 +12101,7 @@ const removeAnnotationOperationImplementation = ({
12138
12101
  const {
12139
12102
  node: block,
12140
12103
  path: blockPath
12141
- } = blockEntry, potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === operation.annotation.name), selectedChildEntry = getNode(editor, effectiveSelection.focus.path);
12104
+ } = blockEntry, potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === operation.annotation.name), selectedChildEntry = getNode(editor.snapshot, effectiveSelection.focus.path);
12142
12105
  if (!selectedChildEntry)
12143
12106
  return;
12144
12107
  const {
@@ -12146,13 +12109,13 @@ const removeAnnotationOperationImplementation = ({
12146
12109
  path: selectedChildPath
12147
12110
  } = selectedChildEntry;
12148
12111
  if (!isSpan({
12149
- schema: editor.schema
12112
+ schema: editor.snapshot.context.schema
12150
12113
  }, selectedChild))
12151
12114
  return;
12152
12115
  const annotationToRemove = selectedChild.marks?.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
12153
12116
  if (!annotationToRemove)
12154
12117
  return;
12155
- const previousSpansWithSameAnnotation = [], reversedChildren = getChildren(editor, blockPath);
12118
+ const previousSpansWithSameAnnotation = [], reversedChildren = getChildren(editor.snapshot, blockPath);
12156
12119
  for (let index = reversedChildren.length - 1; index >= 0; index--) {
12157
12120
  const entry = reversedChildren[index];
12158
12121
  if (!entry)
@@ -12162,8 +12125,8 @@ const removeAnnotationOperationImplementation = ({
12162
12125
  path: childPath
12163
12126
  } = entry;
12164
12127
  if (isSpan({
12165
- schema: editor.schema
12166
- }, child) && isBeforePath(childPath, selectedChildPath, editor))
12128
+ schema: editor.snapshot.context.schema
12129
+ }, child) && isBeforePath(childPath, selectedChildPath, editor.snapshot.context))
12167
12130
  if (child.marks?.includes(annotationToRemove))
12168
12131
  previousSpansWithSameAnnotation.push([child, childPath]);
12169
12132
  else
@@ -12173,10 +12136,10 @@ const removeAnnotationOperationImplementation = ({
12173
12136
  for (const {
12174
12137
  node: child,
12175
12138
  path: childPath
12176
- } of getChildren(editor, blockPath))
12139
+ } of getChildren(editor.snapshot, blockPath))
12177
12140
  if (isSpan({
12178
- schema: editor.schema
12179
- }, child) && isAfterPath(childPath, selectedChildPath, editor))
12141
+ schema: editor.snapshot.context.schema
12142
+ }, child) && isAfterPath(childPath, selectedChildPath, editor.snapshot.context))
12180
12143
  if (child.marks?.includes(annotationToRemove))
12181
12144
  nextSpansWithSameAnnotation.push([child, childPath]);
12182
12145
  else
@@ -12190,43 +12153,43 @@ const removeAnnotationOperationImplementation = ({
12190
12153
  affinity: "inward"
12191
12154
  }) : null;
12192
12155
  withoutNormalizing(editor, () => {
12193
- const splitRange = at ?? editor.selection;
12156
+ const splitRange = at ?? editor.snapshot.context.selection;
12194
12157
  if (splitRange && isRange(splitRange)) {
12195
- const splitLeaf = getNode(editor, splitRange.anchor.path)?.node;
12158
+ const splitLeaf = getNode(editor.snapshot, splitRange.anchor.path)?.node;
12196
12159
  if (!(splitLeaf && isCollapsedRange(splitRange) && isSpan({
12197
- schema: editor.schema
12160
+ schema: editor.snapshot.context.schema
12198
12161
  }, splitLeaf) && splitLeaf.text.length > 0)) {
12199
12162
  const splitRangeRef = rangeRef(editor, splitRange, {
12200
12163
  affinity: "inward"
12201
- }), [splitStart, splitEnd] = rangeEdges(splitRange, editor);
12164
+ }), [splitStart, splitEnd] = rangeEdges(splitRange, editor.snapshot.context);
12202
12165
  (!isEnd(editor, splitEnd, splitEnd.path) || !isEdge(editor, splitEnd, splitEnd.path)) && applySplitNode(editor, splitEnd.path, splitEnd.offset), (!isStart(editor, splitStart, splitStart.path) || !isEdge(editor, splitStart, splitStart.path)) && applySplitNode(editor, splitStart.path, splitStart.offset);
12203
12166
  const updatedSplitRange = splitRangeRef.unref();
12204
12167
  !at && updatedSplitRange && applySelect(editor, updatedSplitRange);
12205
12168
  }
12206
12169
  }
12207
- const blocks = Array.from(getNodes(editor, {
12208
- from: rangeStart(effectiveSelection, editor).path,
12209
- to: rangeEnd(effectiveSelection, editor).path,
12170
+ const blocks = Array.from(getNodes(editor.snapshot, {
12171
+ from: rangeStart(effectiveSelection, editor.snapshot.context).path,
12172
+ to: rangeEnd(effectiveSelection, editor.snapshot.context).path,
12210
12173
  match: (node) => isTextBlock({
12211
- schema: editor.schema
12174
+ schema: editor.snapshot.context.schema
12212
12175
  }, node)
12213
- })), selectionRange = ref?.current ?? editor.selection;
12176
+ })), selectionRange = ref?.current ?? editor.snapshot.context.selection;
12214
12177
  for (const {
12215
12178
  node: block,
12216
12179
  path: blockPath
12217
12180
  } of blocks) {
12218
12181
  if (!isTextBlock({
12219
- schema: editor.schema
12182
+ schema: editor.snapshot.context.schema
12220
12183
  }, block))
12221
12184
  continue;
12222
- const children = getChildren(editor, blockPath);
12185
+ const children = getChildren(editor.snapshot, blockPath);
12223
12186
  for (const {
12224
12187
  node: child,
12225
12188
  path: childPath
12226
12189
  } of children) {
12227
12190
  if (!isSpan({
12228
- schema: editor.schema
12229
- }, child) || !selectionRange || !rangeIncludes(selectionRange, childPath, editor))
12191
+ schema: editor.snapshot.context.schema
12192
+ }, child) || !selectionRange || !rangeIntersects(editor.snapshot, selectionRange, childPath))
12230
12193
  continue;
12231
12194
  const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== operation.annotation.name);
12232
12195
  marksWithoutAnnotation.length !== marks.length && setNodeProperties(editor, {
@@ -12256,7 +12219,7 @@ const blockSetOperationImplementation = ({
12256
12219
  }) => {
12257
12220
  const {
12258
12221
  context
12259
- } = snapshot, blockEntry = getNode(operation.editor, operation.at);
12222
+ } = snapshot, blockEntry = getNode(operation.editor.snapshot, operation.at);
12260
12223
  if (!blockEntry)
12261
12224
  throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
12262
12225
  const engineBlock = blockEntry.node;
@@ -12316,7 +12279,7 @@ const blockSetOperationImplementation = ({
12316
12279
  }) => {
12317
12280
  const {
12318
12281
  context
12319
- } = snapshot, blockEntry = getNode(operation.editor, operation.at);
12282
+ } = snapshot, blockEntry = getNode(operation.editor.snapshot, operation.at);
12320
12283
  if (!blockEntry)
12321
12284
  throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
12322
12285
  const engineBlock = blockEntry.node;
@@ -12348,7 +12311,7 @@ const childSetOperationImplementation = ({
12348
12311
  snapshot,
12349
12312
  operation
12350
12313
  }) => {
12351
- const childEntry = getNode(operation.editor, operation.at);
12314
+ const childEntry = getNode(operation.editor.snapshot, operation.at);
12352
12315
  if (!childEntry)
12353
12316
  throw new Error(`Unable to find child at ${safeStringify(operation.at)}`);
12354
12317
  const {
@@ -12356,7 +12319,7 @@ const childSetOperationImplementation = ({
12356
12319
  path: childPath
12357
12320
  } = childEntry;
12358
12321
  if (isSpan({
12359
- schema: operation.editor.schema
12322
+ schema: operation.editor.snapshot.context.schema
12360
12323
  }, child)) {
12361
12324
  const {
12362
12325
  _type,
@@ -12381,7 +12344,7 @@ const childSetOperationImplementation = ({
12381
12344
  }));
12382
12345
  return;
12383
12346
  }
12384
- if (isObject$1(operation.editor, child)) {
12347
+ if (isObject$1(operation.editor.snapshot, child)) {
12385
12348
  const blockPath = parentPath(childPath), {
12386
12349
  inlineObjects
12387
12350
  } = getPathSubSchema(snapshot, blockPath), definition = inlineObjects.find((definition2) => definition2.name === child._type);
@@ -12408,7 +12371,7 @@ const childSetOperationImplementation = ({
12408
12371
  }) => {
12409
12372
  const {
12410
12373
  context
12411
- } = snapshot, childEntry = getNode(operation.editor, operation.at);
12374
+ } = snapshot, childEntry = getNode(operation.editor.snapshot, operation.at);
12412
12375
  if (!childEntry)
12413
12376
  throw new Error(`Could not find a valid child at ${safeStringify(operation.at)}`);
12414
12377
  const {
@@ -12416,7 +12379,7 @@ const childSetOperationImplementation = ({
12416
12379
  path: childPath
12417
12380
  } = childEntry;
12418
12381
  if (isSpan({
12419
- schema: operation.editor.schema
12382
+ schema: operation.editor.snapshot.context.schema
12420
12383
  }, child)) {
12421
12384
  const newNode = {};
12422
12385
  for (const prop of operation.props)
@@ -12430,7 +12393,7 @@ const childSetOperationImplementation = ({
12430
12393
  setNodeProperties(operation.editor, newNode, childPath);
12431
12394
  return;
12432
12395
  }
12433
- if (isObject$1(operation.editor, child)) {
12396
+ if (isObject$1(operation.editor.snapshot, child)) {
12434
12397
  const unsetProps = {};
12435
12398
  for (const prop of operation.props)
12436
12399
  prop !== "_type" && (prop === "_key" ? unsetProps._key = context.keyGenerator() : unsetProps[prop] = null);
@@ -12443,22 +12406,22 @@ const childSetOperationImplementation = ({
12443
12406
  operation
12444
12407
  }) => {
12445
12408
  const editor = operation.editor, mark = operation.decorator;
12446
- let at = operation.at ? resolveSelection(operation.editor, operation.at) : operation.editor.selection;
12409
+ let at = operation.at ? resolveSelection(operation.editor, operation.at) : operation.editor.snapshot.context.selection;
12447
12410
  if (at) {
12448
12411
  if (isExpandedRange(at)) {
12449
12412
  const ref = rangeRef(editor, at, {
12450
12413
  affinity: "inward"
12451
12414
  });
12452
12415
  withoutNormalizing(editor, () => {
12453
- const [start2, end2] = rangeEdges(at, editor);
12416
+ const [start2, end2] = rangeEdges(at, editor.snapshot.context);
12454
12417
  if (isEdge(editor, end2, end2.path) || applySplitNode(editor, end2.path, end2.offset), isEdge(editor, start2, start2.path) || applySplitNode(editor, start2.path, start2.offset), at = ref.unref(), !at)
12455
12418
  throw new Error("Unable to add decorator without a selection");
12456
12419
  operation.at || applySelect(editor, at);
12457
- const atStart = rangeStart(at, editor), atEnd = rangeEnd(at, editor), splitTextNodes = Array.from(getNodes(editor, {
12420
+ const atStart = rangeStart(at, editor.snapshot.context), atEnd = rangeEnd(at, editor.snapshot.context), splitTextNodes = Array.from(getNodes(editor.snapshot, {
12458
12421
  from: atStart.path,
12459
12422
  to: atEnd.path,
12460
12423
  match: (n) => isSpan({
12461
- schema: editor.schema
12424
+ schema: editor.snapshot.context.schema
12462
12425
  }, n)
12463
12426
  }));
12464
12427
  for (const {
@@ -12466,7 +12429,7 @@ const childSetOperationImplementation = ({
12466
12429
  path: spanPath
12467
12430
  } of splitTextNodes) {
12468
12431
  if (!isSpan({
12469
- schema: editor.schema
12432
+ schema: editor.snapshot.context.schema
12470
12433
  }, node) || isEnd(editor, atStart, spanPath) && !isStart(editor, atStart, spanPath) || isStart(editor, atEnd, spanPath) && !isEnd(editor, atEnd, spanPath))
12471
12434
  continue;
12472
12435
  const blockPath = parentPath(spanPath);
@@ -12479,11 +12442,11 @@ const childSetOperationImplementation = ({
12479
12442
  }
12480
12443
  });
12481
12444
  } else {
12482
- if (!Array.from(getNodes(editor, {
12483
- from: rangeStart(at, editor).path,
12484
- to: rangeEnd(at, editor).path,
12445
+ if (!Array.from(getNodes(editor.snapshot, {
12446
+ from: rangeStart(at, editor.snapshot.context).path,
12447
+ to: rangeEnd(at, editor.snapshot.context).path,
12485
12448
  match: (node) => isSpan({
12486
- schema: editor.schema
12449
+ schema: editor.snapshot.context.schema
12487
12450
  }, node)
12488
12451
  }))?.at(0))
12489
12452
  return;
@@ -12501,27 +12464,27 @@ const childSetOperationImplementation = ({
12501
12464
  if (!getPathSubSchema(snapshot, blockPath).decorators.some((decorator) => decorator.name === mark))
12502
12465
  return;
12503
12466
  const lonelyEmptySpan = block.children.length === 1 && isSpan({
12504
- schema: editor.schema
12467
+ schema: editor.snapshot.context.schema
12505
12468
  }, block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
12506
12469
  if (lonelyEmptySpan) {
12507
12470
  const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark), newMarks = existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator;
12508
12471
  for (const {
12509
12472
  path: spanPath
12510
- } of Array.from(getNodes(editor, {
12473
+ } of Array.from(getNodes(editor.snapshot, {
12511
12474
  at: blockPath,
12512
12475
  match: (node) => isSpan({
12513
- schema: editor.schema
12476
+ schema: editor.snapshot.context.schema
12514
12477
  }, node)
12515
12478
  })))
12516
12479
  setNodeProperties(editor, {
12517
12480
  marks: newMarks
12518
12481
  }, spanPath);
12519
12482
  } else
12520
- editor.decoratorState[mark] = !0;
12483
+ editor.snapshot.decoratorState[mark] = !0;
12521
12484
  }
12522
- if (editor.selection) {
12523
- const selection = editor.selection;
12524
- editor.selection = {
12485
+ if (editor.snapshot.context.selection) {
12486
+ const selection = editor.snapshot.context.selection;
12487
+ editor.snapshot.context.selection = {
12525
12488
  ...selection
12526
12489
  };
12527
12490
  }
@@ -12532,27 +12495,27 @@ const childSetOperationImplementation = ({
12532
12495
  }) => {
12533
12496
  const {
12534
12497
  context
12535
- } = snapshot, editor = operation.editor, mark = operation.decorator, at = operation.at ? resolveSelection(operation.editor, operation.at) : editor.selection;
12498
+ } = snapshot, editor = operation.editor, mark = operation.decorator, at = operation.at ? resolveSelection(operation.editor, operation.at) : editor.snapshot.context.selection;
12536
12499
  if (at) {
12537
12500
  if (isExpandedRange(at)) {
12538
12501
  const ref = rangeRef(editor, at, {
12539
12502
  affinity: "inward"
12540
12503
  });
12541
12504
  withoutNormalizing(editor, () => {
12542
- const decoratorLeaf = getNode(editor, at.anchor.path)?.node;
12505
+ const decoratorLeaf = getNode(editor.snapshot, at.anchor.path)?.node;
12543
12506
  if (!(decoratorLeaf && isCollapsedRange(at) && isSpan({
12544
- schema: editor.schema
12507
+ schema: editor.snapshot.context.schema
12545
12508
  }, decoratorLeaf) && decoratorLeaf.text.length > 0)) {
12546
- const [start2, end2] = rangeEdges(at, editor);
12509
+ const [start2, end2] = rangeEdges(at, editor.snapshot.context);
12547
12510
  (!isEnd(editor, end2, end2.path) || !isEdge(editor, end2, end2.path)) && applySplitNode(editor, end2.path, end2.offset), (!isStart(editor, start2, start2.path) || !isEdge(editor, start2, start2.path)) && applySplitNode(editor, start2.path, start2.offset);
12548
12511
  }
12549
12512
  const updatedAt = ref.unref();
12550
12513
  if (updatedAt) {
12551
- const splitTextNodes = [...getNodes(editor, {
12552
- from: rangeStart(updatedAt, editor).path,
12553
- to: rangeEnd(updatedAt, editor).path,
12514
+ const splitTextNodes = [...getNodes(editor.snapshot, {
12515
+ from: rangeStart(updatedAt, editor.snapshot.context).path,
12516
+ to: rangeEnd(updatedAt, editor.snapshot.context).path,
12554
12517
  match: (n) => isSpan({
12555
- schema: editor.schema
12518
+ schema: editor.snapshot.context.schema
12556
12519
  }, n)
12557
12520
  })];
12558
12521
  for (const {
@@ -12560,12 +12523,12 @@ const childSetOperationImplementation = ({
12560
12523
  path: nodePath
12561
12524
  } of splitTextNodes) {
12562
12525
  if (!isSpan({
12563
- schema: editor.schema
12526
+ schema: editor.snapshot.context.schema
12564
12527
  }, node))
12565
12528
  continue;
12566
- const blockPath = parentPath(nodePath), block = getNode(editor, blockPath)?.node;
12529
+ const blockPath = parentPath(nodePath), block = getNode(editor.snapshot, blockPath)?.node;
12567
12530
  isTextBlock({
12568
- schema: editor.schema
12531
+ schema: editor.snapshot.context.schema
12569
12532
  }, block) && block.children.includes(node) && setNodeProperties(editor, {
12570
12533
  marks: (Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark),
12571
12534
  _type: context.schema.span.name
@@ -12576,7 +12539,7 @@ const childSetOperationImplementation = ({
12576
12539
  } else {
12577
12540
  const textBlockEntry = getParent(snapshot, at.focus.path, {
12578
12541
  match: (node) => isTextBlock({
12579
- schema: editor.schema
12542
+ schema: editor.snapshot.context.schema
12580
12543
  }, node)
12581
12544
  });
12582
12545
  if (!textBlockEntry)
@@ -12585,27 +12548,27 @@ const childSetOperationImplementation = ({
12585
12548
  node: block,
12586
12549
  path: blockPath
12587
12550
  } = textBlockEntry, lonelyEmptySpan = block.children.length === 1 && isSpan({
12588
- schema: editor.schema
12551
+ schema: editor.snapshot.context.schema
12589
12552
  }, block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
12590
12553
  if (lonelyEmptySpan) {
12591
12554
  const existingMarksWithoutDecorator = (lonelyEmptySpan.marks ?? []).filter((existingMark) => existingMark !== mark);
12592
12555
  for (const {
12593
12556
  path: spanPath
12594
- } of Array.from(getNodes(editor, {
12557
+ } of Array.from(getNodes(editor.snapshot, {
12595
12558
  at: blockPath,
12596
12559
  match: (node) => isSpan({
12597
- schema: editor.schema
12560
+ schema: editor.snapshot.context.schema
12598
12561
  }, node)
12599
12562
  })))
12600
12563
  setNodeProperties(editor, {
12601
12564
  marks: existingMarksWithoutDecorator
12602
12565
  }, spanPath);
12603
12566
  } else
12604
- editor.decoratorState[mark] = !1;
12567
+ editor.snapshot.decoratorState[mark] = !1;
12605
12568
  }
12606
- if (editor.selection) {
12607
- const selection = editor.selection;
12608
- editor.selection = {
12569
+ if (editor.snapshot.context.selection) {
12570
+ const selection = editor.snapshot.context.selection;
12571
+ editor.snapshot.context.selection = {
12609
12572
  ...selection
12610
12573
  };
12611
12574
  }
@@ -12616,7 +12579,7 @@ function unhangRange(snapshot, range2) {
12616
12579
  context
12617
12580
  } = snapshot;
12618
12581
  let [start2, end2] = rangeEdges(range2, {
12619
- children: context.value
12582
+ value: context.value
12620
12583
  });
12621
12584
  if (start2.offset !== 0 || end2.offset !== 0 || isCollapsedRange(range2) || getSibling(snapshot, end2.path, {
12622
12585
  direction: "previous"
@@ -12655,7 +12618,7 @@ function unhangRange(snapshot, range2) {
12655
12618
  if (isSpan({
12656
12619
  schema: context.schema
12657
12620
  }, node) && (node.text !== "" || isBeforePath(nodePath, blockPath, {
12658
- children: context.value
12621
+ value: context.value
12659
12622
  }))) {
12660
12623
  end2 = {
12661
12624
  path: nodePath,
@@ -12685,23 +12648,23 @@ function pointRef(editor, point2, options = {}) {
12685
12648
  return editor.pointRefs.add(ref), ref;
12686
12649
  }
12687
12650
  function getFullyCoveredContainers(editor, range2) {
12688
- const [start2, end2] = rangeEdges(range2, editor);
12651
+ const [start2, end2] = rangeEdges(range2, editor.snapshot.context);
12689
12652
  return {
12690
- start: getAncestor(editor, start2.path, {
12653
+ start: getAncestor(editor.snapshot, start2.path, {
12691
12654
  match: (node, path2) => isFullyCovered(editor, node, path2, start2, end2)
12692
12655
  })?.path,
12693
- end: getAncestor(editor, end2.path, {
12656
+ end: getAncestor(editor.snapshot, end2.path, {
12694
12657
  match: (node, path2) => isFullyCovered(editor, node, path2, start2, end2)
12695
12658
  })?.path
12696
12659
  };
12697
12660
  }
12698
12661
  function isFullyCovered(editor, node, path2, rangeStart2, rangeEnd2) {
12699
- if (!isEditableContainer(editor, node, path2) || isTextBlock({
12700
- schema: editor.schema
12662
+ if (!isEditableContainer(editor.snapshot, node, path2) || isTextBlock({
12663
+ schema: editor.snapshot.context.schema
12701
12664
  }, node))
12702
12665
  return !1;
12703
12666
  const root = {
12704
- children: editor.children
12667
+ value: editor.snapshot.context.value
12705
12668
  }, containerStart = start(editor, path2), containerEnd = end(editor, path2), reachesStart = pointEquals(rangeStart2, containerStart) || isBeforePoint(rangeStart2, containerStart, root), reachesEnd = pointEquals(rangeEnd2, containerEnd) || isAfterPoint(rangeEnd2, containerEnd, root);
12706
12669
  return !reachesStart || !reachesEnd || pointEquals(rangeStart2, containerStart) && pointEquals(rangeEnd2, containerEnd) && fieldAcceptsTextBlock(editor, node) ? !1 : parentFieldAcceptsTextBlock(editor, path2);
12707
12670
  }
@@ -12709,12 +12672,12 @@ function parentFieldAcceptsTextBlock(editor, path2) {
12709
12672
  const parent = parentPath(path2);
12710
12673
  if (parent.length === 0)
12711
12674
  return !0;
12712
- const parentEntry = getNode(editor, parent);
12675
+ const parentEntry = getNode(editor.snapshot, parent);
12713
12676
  return parentEntry ? fieldAcceptsTextBlock(editor, parentEntry.node) : !1;
12714
12677
  }
12715
12678
  function fieldAcceptsTextBlock(editor, node, _path) {
12716
12679
  const container = editor.containers.get(node._type);
12717
- return container ? container.field.of.some((member) => member.type === editor.schema.block.name) : !1;
12680
+ return container ? container.field.of.some((member) => member.type === editor.snapshot.context.schema.block.name) : !1;
12718
12681
  }
12719
12682
  const COMPOUND_SCRIPT_REGEX = /[\u0980-\u09FF\u0E00-\u0E7F\u1000-\u109F\u0900-\u097F\u1780-\u17FF\u0D00-\u0D7F\u0B00-\u0B7F\u0A00-\u0A7F\u0B80-\u0BFF\u0C00-\u0C7F]+/;
12720
12683
  function applyDelete(editor, range2, options) {
@@ -12740,11 +12703,11 @@ function applyDelete(editor, range2, options) {
12740
12703
  startRef?.unref(), endRef?.unref();
12741
12704
  if (reverse && unit === "character" && collapsedInput && removedText && removedText.length > 1 && COMPOUND_SCRIPT_REGEX.test(removedText)) {
12742
12705
  const reinsert = removedText.slice(0, removedText.length - 1);
12743
- if (editor.selection) {
12706
+ if (editor.snapshot.context.selection) {
12744
12707
  const {
12745
12708
  path: path2,
12746
12709
  offset
12747
- } = editor.selection.anchor;
12710
+ } = editor.snapshot.context.selection.anchor;
12748
12711
  editor.apply({
12749
12712
  type: "insert_text",
12750
12713
  path: path2,
@@ -12758,30 +12721,30 @@ function mutateRange(editor, range2, options) {
12758
12721
  const {
12759
12722
  capture,
12760
12723
  removeEmptyStartBlock
12761
- } = options, [start2, end2] = rangeEdges(range2, editor), startBlock = getEnclosingBlock(editor, start2.path), endBlock = getEnclosingBlock(editor, end2.path);
12724
+ } = options, [start2, end2] = rangeEdges(range2, editor.snapshot.context), startBlock = getEnclosingBlock(editor.snapshot, start2.path), endBlock = getEnclosingBlock(editor.snapshot, end2.path);
12762
12725
  return !startBlock || !endBlock ? null : pathEquals(startBlock.path, endBlock.path) ? deleteSameBlockRange(editor, start2, end2, capture) : pathEquals(parentPath(startBlock.path), parentPath(endBlock.path)) ? (deleteSameParentCrossBlockRange(editor, startBlock.path, endBlock.path, start2, end2, removeEmptyStartBlock), null) : (deleteCrossParentRange(editor, startBlock.path, endBlock.path, start2, end2), null);
12763
12726
  }
12764
12727
  function deleteSameBlockRange(editor, start2, end2, capture) {
12765
12728
  if (pathEquals(start2.path, end2.path))
12766
12729
  return removeTextRange(editor, start2.path, start2.offset, end2.offset, capture);
12767
- const startEntry = getNode(editor, start2.path);
12768
- if (startEntry && isLeafObject(editor, startEntry.node, start2.path))
12730
+ const startEntry = getNode(editor.snapshot, start2.path);
12731
+ if (startEntry && isLeafObject(editor.snapshot, startEntry.node, start2.path))
12769
12732
  return editor.apply({
12770
12733
  type: "unset",
12771
12734
  path: start2.path
12772
12735
  }), null;
12773
12736
  const removed = removeTextFromOffset(editor, start2.path, start2.offset, capture);
12774
12737
  removeChildrenBetween(editor, start2.path, end2.path);
12775
- const adjustedEnd = getSibling(editor, start2.path, {
12738
+ const adjustedEnd = getSibling(editor.snapshot, start2.path, {
12776
12739
  direction: "next"
12777
12740
  });
12778
- return adjustedEnd ? isLeafObject(editor, adjustedEnd.node, adjustedEnd.path) ? (editor.apply({
12741
+ return adjustedEnd ? isLeafObject(editor.snapshot, adjustedEnd.node, adjustedEnd.path) ? (editor.apply({
12779
12742
  type: "unset",
12780
12743
  path: adjustedEnd.path
12781
12744
  }), removed) : (removeTextUpToOffset(editor, adjustedEnd.path, end2.offset), removed) : removed;
12782
12745
  }
12783
12746
  function deleteSameParentCrossBlockRange(editor, startBlockPath, endBlockPath, start2, end2, removeEmptyStartBlock) {
12784
- const startBlockNode = getNode(editor, startBlockPath), endBlockNode = getNode(editor, endBlockPath), startIsVoid = startBlockNode != null && isLeafObject(editor, startBlockNode.node, startBlockPath), endIsVoid = endBlockNode != null && isLeafObject(editor, endBlockNode.node, endBlockPath);
12747
+ const startBlockNode = getNode(editor.snapshot, startBlockPath), endBlockNode = getNode(editor.snapshot, endBlockPath), startIsVoid = startBlockNode != null && isLeafObject(editor.snapshot, startBlockNode.node, startBlockPath), endIsVoid = endBlockNode != null && isLeafObject(editor.snapshot, endBlockNode.node, endBlockPath);
12785
12748
  if (startIsVoid || (pathEquals(start2.path, startBlockPath) ? removeAllChildren(editor, startBlockPath) : (removeTextFromOffset(editor, start2.path, start2.offset, !1), removeTrailingChildren(editor, start2.path))), removeBlocksBetween(editor, startBlockPath, endBlockPath), startIsVoid && endIsVoid) {
12786
12749
  removeNodeAt(editor, endBlockPath), removeNodeAt(editor, startBlockPath);
12787
12750
  return;
@@ -12789,7 +12752,7 @@ function deleteSameParentCrossBlockRange(editor, startBlockPath, endBlockPath, s
12789
12752
  if (startIsVoid) {
12790
12753
  if (!pathEquals(end2.path, endBlockPath)) {
12791
12754
  removeLeadingChildrenOf(editor, endBlockPath, end2.path);
12792
- const firstChild = getFirstChild(editor, endBlockPath);
12755
+ const firstChild = getFirstChild(editor.snapshot, endBlockPath);
12793
12756
  firstChild && removeTextUpToOffset(editor, firstChild.path, end2.offset);
12794
12757
  }
12795
12758
  removeNodeAt(editor, startBlockPath);
@@ -12799,12 +12762,12 @@ function deleteSameParentCrossBlockRange(editor, startBlockPath, endBlockPath, s
12799
12762
  removeNodeAt(editor, endBlockPath);
12800
12763
  return;
12801
12764
  }
12802
- const adjustedEndBlockPath = getSibling(editor, startBlockPath, {
12765
+ const adjustedEndBlockPath = getSibling(editor.snapshot, startBlockPath, {
12803
12766
  direction: "next"
12804
12767
  })?.path ?? startBlockPath;
12805
12768
  if (!pathEquals(end2.path, endBlockPath)) {
12806
12769
  removeLeadingChildrenOf(editor, adjustedEndBlockPath, end2.path);
12807
- const firstChild = getFirstChild(editor, adjustedEndBlockPath);
12770
+ const firstChild = getFirstChild(editor.snapshot, adjustedEndBlockPath);
12808
12771
  firstChild && removeTextUpToOffset(editor, firstChild.path, end2.offset);
12809
12772
  }
12810
12773
  mergeBlock(editor, startBlockPath, adjustedEndBlockPath, removeEmptyStartBlock);
@@ -12818,16 +12781,16 @@ function deleteCrossParentRange(editor, startBlockPath, endBlockPath, start2, en
12818
12781
  let startLevel = startBlockPath;
12819
12782
  for (; !pathEquals(startLevel, startBranchRoot); )
12820
12783
  parentAcceptsTextBlock(editor, startLevel) ? removeTrailingChildren(editor, startLevel) : clearTrailingSiblings(editor, startLevel), startLevel = parentPath(startLevel);
12821
- const lcaContainer = getEnclosingContainer(editor, startBranchRoot);
12822
- if (!lcaContainer || lcaContainer.of.some((member) => member.type === editor.schema.block.name))
12784
+ const lcaContainer = getEnclosingContainer(editor.snapshot, startBranchRoot);
12785
+ if (!lcaContainer || lcaContainer.of.some((member) => member.type === editor.snapshot.context.schema.block.name))
12823
12786
  removeChildrenBetween(editor, startBranchRoot, endBranchRoot);
12824
12787
  else {
12825
- let cursor = getSibling(editor, startBranchRoot, {
12788
+ let cursor = getSibling(editor.snapshot, startBranchRoot, {
12826
12789
  direction: "next"
12827
12790
  });
12828
12791
  for (; cursor && !pathEquals(cursor.path, endBranchRoot); ) {
12829
12792
  const cursorPath = cursor.path;
12830
- clearContainerContents(editor, cursorPath), cursor = getSibling(editor, cursorPath, {
12793
+ clearContainerContents(editor, cursorPath), cursor = getSibling(editor.snapshot, cursorPath, {
12831
12794
  direction: "next"
12832
12795
  });
12833
12796
  }
@@ -12837,7 +12800,7 @@ function deleteCrossParentRange(editor, startBlockPath, endBlockPath, start2, en
12837
12800
  parentAcceptsTextBlock(editor, endLevel) ? removePrecedingSiblings(editor, endLevel) : clearPrecedingSiblings(editor, endLevel), endLevel = parentPath(endLevel);
12838
12801
  if (!pathEquals(end2.path, endBlockPath)) {
12839
12802
  removeLeadingChildrenOf(editor, endBlockPath, end2.path);
12840
- const firstChild = getFirstChild(editor, endBlockPath);
12803
+ const firstChild = getFirstChild(editor.snapshot, endBlockPath);
12841
12804
  firstChild && removeTextUpToOffset(editor, firstChild.path, end2.offset);
12842
12805
  }
12843
12806
  if (fullyCovered.start && fullyCovered.end && pathEquals(fullyCovered.start, fullyCovered.end)) {
@@ -12856,7 +12819,7 @@ function deleteCrossParentRange(editor, startBlockPath, endBlockPath, start2, en
12856
12819
  });
12857
12820
  }
12858
12821
  function removeTextRange(editor, path2, startOffset, endOffset, capture) {
12859
- const span = getSpan(editor, path2);
12822
+ const span = getSpan(editor.snapshot, path2);
12860
12823
  if (!span)
12861
12824
  return null;
12862
12825
  const text = span.node.text.slice(startOffset, endOffset);
@@ -12868,7 +12831,7 @@ function removeTextRange(editor, path2, startOffset, endOffset, capture) {
12868
12831
  }), capture ? text : null);
12869
12832
  }
12870
12833
  function removeTextFromOffset(editor, path2, offset, capture) {
12871
- const span = getSpan(editor, path2);
12834
+ const span = getSpan(editor.snapshot, path2);
12872
12835
  if (!span || offset >= span.node.text.length)
12873
12836
  return null;
12874
12837
  const text = span.node.text.slice(offset);
@@ -12882,7 +12845,7 @@ function removeTextFromOffset(editor, path2, offset, capture) {
12882
12845
  function removeTextUpToOffset(editor, path2, offset) {
12883
12846
  if (offset <= 0)
12884
12847
  return;
12885
- const span = getSpan(editor, path2);
12848
+ const span = getSpan(editor.snapshot, path2);
12886
12849
  span && editor.apply({
12887
12850
  type: "remove_text",
12888
12851
  path: path2,
@@ -12891,115 +12854,119 @@ function removeTextUpToOffset(editor, path2, offset) {
12891
12854
  });
12892
12855
  }
12893
12856
  function removeChildrenBetween(editor, startChildPath, endChildPath) {
12894
- let cursor = getSibling(editor, startChildPath, {
12857
+ let cursor = getSibling(editor.snapshot, startChildPath, {
12895
12858
  direction: "next"
12896
12859
  });
12897
12860
  for (; cursor && !pathEquals(cursor.path, endChildPath); )
12898
- removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startChildPath, {
12861
+ removeNodeAt(editor, cursor.path), cursor = getSibling(editor.snapshot, startChildPath, {
12899
12862
  direction: "next"
12900
12863
  });
12901
12864
  }
12902
12865
  function clearContainerContents(editor, containerPath) {
12903
- const node = getNode(editor, containerPath)?.node;
12866
+ const node = getNode(editor.snapshot, containerPath)?.node;
12904
12867
  if (!node)
12905
12868
  return;
12906
- const container = resolveContainerByPath(editor, containerPath, node);
12869
+ const container = resolveContainerByPath({
12870
+ containers: editor.containers,
12871
+ schema: editor.snapshot.context.schema,
12872
+ value: editor.snapshot.context.value
12873
+ }, containerPath, node);
12907
12874
  if (!container || !("container" in container))
12908
12875
  return;
12909
12876
  const fieldName = container.field.name;
12910
- if (container.field.of.some((member) => member.type === editor.schema.block.name)) {
12911
- let firstChild = getFirstChild(editor, containerPath);
12877
+ if (container.field.of.some((member) => member.type === editor.snapshot.context.schema.block.name)) {
12878
+ let firstChild = getFirstChild(editor.snapshot, containerPath);
12912
12879
  for (; firstChild; )
12913
- removeNodeAt(editor, firstChild.path), firstChild = getFirstChild(editor, containerPath);
12880
+ removeNodeAt(editor, firstChild.path), firstChild = getFirstChild(editor.snapshot, containerPath);
12914
12881
  const placeholderPath = [...containerPath, fieldName, 0];
12915
12882
  editor.apply({
12916
12883
  type: "insert",
12917
12884
  path: placeholderPath,
12918
- node: createPlaceholderBlock(editor, placeholderPath),
12885
+ node: createPlaceholderBlock(editor.snapshot, placeholderPath),
12919
12886
  position: "before"
12920
12887
  });
12921
12888
  return;
12922
12889
  }
12923
- for (const child of getChildren(editor, containerPath))
12890
+ for (const child of getChildren(editor.snapshot, containerPath))
12924
12891
  clearContainerContents(editor, child.path);
12925
12892
  }
12926
12893
  function removeTrailingChildren(editor, startChildPath) {
12927
- let cursor = getSibling(editor, startChildPath, {
12894
+ let cursor = getSibling(editor.snapshot, startChildPath, {
12928
12895
  direction: "next"
12929
12896
  });
12930
12897
  for (; cursor; )
12931
- removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startChildPath, {
12898
+ removeNodeAt(editor, cursor.path), cursor = getSibling(editor.snapshot, startChildPath, {
12932
12899
  direction: "next"
12933
12900
  });
12934
12901
  }
12935
12902
  function clearTrailingSiblings(editor, startChildPath) {
12936
- let cursor = getSibling(editor, startChildPath, {
12903
+ let cursor = getSibling(editor.snapshot, startChildPath, {
12937
12904
  direction: "next"
12938
12905
  });
12939
12906
  for (; cursor; ) {
12940
12907
  const cursorPath = cursor.path;
12941
- clearContainerContents(editor, cursorPath), cursor = getSibling(editor, cursorPath, {
12908
+ clearContainerContents(editor, cursorPath), cursor = getSibling(editor.snapshot, cursorPath, {
12942
12909
  direction: "next"
12943
12910
  });
12944
12911
  }
12945
12912
  }
12946
12913
  function removePrecedingSiblings(editor, startChildPath) {
12947
- let cursor = getSibling(editor, startChildPath, {
12914
+ let cursor = getSibling(editor.snapshot, startChildPath, {
12948
12915
  direction: "previous"
12949
12916
  });
12950
12917
  for (; cursor; )
12951
- removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startChildPath, {
12918
+ removeNodeAt(editor, cursor.path), cursor = getSibling(editor.snapshot, startChildPath, {
12952
12919
  direction: "previous"
12953
12920
  });
12954
12921
  }
12955
12922
  function clearPrecedingSiblings(editor, startChildPath) {
12956
- let cursor = getSibling(editor, startChildPath, {
12923
+ let cursor = getSibling(editor.snapshot, startChildPath, {
12957
12924
  direction: "previous"
12958
12925
  });
12959
12926
  for (; cursor; ) {
12960
12927
  const cursorPath = cursor.path;
12961
- clearContainerContents(editor, cursorPath), cursor = getSibling(editor, cursorPath, {
12928
+ clearContainerContents(editor, cursorPath), cursor = getSibling(editor.snapshot, cursorPath, {
12962
12929
  direction: "previous"
12963
12930
  });
12964
12931
  }
12965
12932
  }
12966
12933
  function parentAcceptsTextBlock(editor, path2) {
12967
- const enclosing = getEnclosingContainer(editor, path2);
12968
- return enclosing ? enclosing.of.some((member) => member.type === editor.schema.block.name) : !0;
12934
+ const enclosing = getEnclosingContainer(editor.snapshot, path2);
12935
+ return enclosing ? enclosing.of.some((member) => member.type === editor.snapshot.context.schema.block.name) : !0;
12969
12936
  }
12970
12937
  function removeAllChildren(editor, blockPath) {
12971
- let firstChild = getFirstChild(editor, blockPath);
12938
+ let firstChild = getFirstChild(editor.snapshot, blockPath);
12972
12939
  for (; firstChild; )
12973
- removeNodeAt(editor, firstChild.path), firstChild = getFirstChild(editor, blockPath);
12940
+ removeNodeAt(editor, firstChild.path), firstChild = getFirstChild(editor.snapshot, blockPath);
12974
12941
  }
12975
12942
  function removeLeadingChildrenOf(editor, blockPath, endChildPath) {
12976
12943
  const endKey = endChildPath.at(-1)?._key;
12977
12944
  if (!endKey)
12978
12945
  return;
12979
- let firstChild = getFirstChild(editor, blockPath);
12946
+ let firstChild = getFirstChild(editor.snapshot, blockPath);
12980
12947
  for (; firstChild && firstChild.path.at(-1)?._key !== endKey; )
12981
- removeNodeAt(editor, firstChild.path), firstChild = getFirstChild(editor, blockPath);
12948
+ removeNodeAt(editor, firstChild.path), firstChild = getFirstChild(editor.snapshot, blockPath);
12982
12949
  }
12983
12950
  function removeBlocksBetween(editor, startBlockPath, endBlockPath) {
12984
- let cursor = getSibling(editor, startBlockPath, {
12951
+ let cursor = getSibling(editor.snapshot, startBlockPath, {
12985
12952
  direction: "next"
12986
12953
  });
12987
12954
  for (; cursor && !pathEquals(cursor.path, endBlockPath); )
12988
- removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startBlockPath, {
12955
+ removeNodeAt(editor, cursor.path), cursor = getSibling(editor.snapshot, startBlockPath, {
12989
12956
  direction: "next"
12990
12957
  });
12991
12958
  }
12992
12959
  function mergeBlock(editor, startBlockPath, endBlockPath, removeEmptyStartBlock) {
12993
12960
  if (pathEquals(startBlockPath, endBlockPath))
12994
12961
  return;
12995
- const startBlock = getTextBlock(editor, startBlockPath), endBlock = getTextBlock(editor, endBlockPath);
12962
+ const startBlock = getTextBlock(editor.snapshot, startBlockPath), endBlock = getTextBlock(editor.snapshot, endBlockPath);
12996
12963
  if (!startBlock || !endBlock)
12997
12964
  return;
12998
12965
  if (removeEmptyStartBlock && isEmptyTextBlock({
12999
- schema: editor.schema
12966
+ schema: editor.snapshot.context.schema
13000
12967
  }, startBlock.node)) {
13001
12968
  if (isEmptyTextBlock({
13002
- schema: editor.schema
12969
+ schema: editor.snapshot.context.schema
13003
12970
  }, endBlock.node)) {
13004
12971
  removeNodeAt(editor, endBlockPath);
13005
12972
  return;
@@ -13017,15 +12984,15 @@ function mergeBlock(editor, startBlockPath, endBlockPath, removeEmptyStartBlock)
13017
12984
  applyMergeNode(editor, endBlockPath, startBlock.node.children.length);
13018
12985
  }
13019
12986
  function removeNodeAt(editor, path2) {
13020
- getNode(editor, path2) && editor.apply({
12987
+ getNode(editor.snapshot, path2) && editor.apply({
13021
12988
  type: "unset",
13022
12989
  path: path2
13023
12990
  });
13024
12991
  }
13025
12992
  function deleteCollapsed(editor, point2, options) {
13026
12993
  withoutNormalizing(editor, () => {
13027
- const pointEntry = getNode(editor, point2.path), furthestObjectNode = pointEntry && isLeafObject(editor, pointEntry.node, point2.path) ? pointEntry : getAncestor(editor, point2.path, {
13028
- match: (node, ancestorPath) => isLeafObject(editor, node, ancestorPath),
12994
+ const pointEntry = getNode(editor.snapshot, point2.path), furthestObjectNode = pointEntry && isLeafObject(editor.snapshot, pointEntry.node, point2.path) ? pointEntry : getAncestor(editor.snapshot, point2.path, {
12995
+ match: (node, ancestorPath) => isLeafObject(editor.snapshot, node, ancestorPath),
13029
12996
  mode: "highest"
13030
12997
  });
13031
12998
  if (furthestObjectNode) {
@@ -13072,19 +13039,19 @@ function deleteRange(editor, range2, options) {
13072
13039
  function resolveExplicitRange(editor, at) {
13073
13040
  if (isCollapsedRange(at))
13074
13041
  return null;
13075
- const [start2, end2] = rangeEdges(at, editor), startBlock = getEnclosingBlock(editor, start2.path), endBlock = getEnclosingBlock(editor, end2.path);
13042
+ const [start2, end2] = rangeEdges(at, editor.snapshot.context), startBlock = getEnclosingBlock(editor.snapshot, start2.path), endBlock = getEnclosingBlock(editor.snapshot, end2.path);
13076
13043
  let clampedStart = start2, clampedEnd = end2;
13077
- const startEntry = getNode(editor, start2.path);
13078
- if ((startEntry && isLeafObject(editor, startEntry.node, start2.path) ? startEntry : getAncestor(editor, start2.path, {
13079
- match: (node, ancestorPath) => isLeafObject(editor, node, ancestorPath),
13044
+ const startEntry = getNode(editor.snapshot, start2.path);
13045
+ if ((startEntry && isLeafObject(editor.snapshot, startEntry.node, start2.path) ? startEntry : getAncestor(editor.snapshot, start2.path, {
13046
+ match: (node, ancestorPath) => isLeafObject(editor.snapshot, node, ancestorPath),
13080
13047
  mode: "highest"
13081
13048
  })) && startBlock) {
13082
13049
  const beforePoint = before(editor, start2);
13083
13050
  beforePoint && isAncestorPath(startBlock.path, beforePoint.path) && (clampedStart = beforePoint);
13084
13051
  }
13085
- const endEntry = getNode(editor, end2.path);
13086
- if ((endEntry && isLeafObject(editor, endEntry.node, end2.path) ? endEntry : getAncestor(editor, end2.path, {
13087
- match: (node, ancestorPath) => isLeafObject(editor, node, ancestorPath),
13052
+ const endEntry = getNode(editor.snapshot, end2.path);
13053
+ if ((endEntry && isLeafObject(editor.snapshot, endEntry.node, end2.path) ? endEntry : getAncestor(editor.snapshot, end2.path, {
13054
+ match: (node, ancestorPath) => isLeafObject(editor.snapshot, node, ancestorPath),
13088
13055
  mode: "highest"
13089
13056
  })) && endBlock) {
13090
13057
  const afterPoint = after(editor, end2);
@@ -13096,7 +13063,7 @@ function resolveExplicitRange(editor, at) {
13096
13063
  };
13097
13064
  }
13098
13065
  function findCurrentLineRange(editor, parentRange) {
13099
- const parentRangeBoundary = range(editor, rangeEnd(parentRange, editor)), positions$1 = Array.from(positions(editor, {
13066
+ const parentRangeBoundary = range(editor, rangeEnd(parentRange, editor.snapshot.context)), positions$1 = Array.from(positions(editor, {
13100
13067
  at: parentRange
13101
13068
  }));
13102
13069
  let left = 0, right = positions$1.length, middle = Math.floor(right / 2);
@@ -13118,7 +13085,7 @@ function domRectsIntersect(rect, compareRect) {
13118
13085
  }
13119
13086
  function unsetMatchedNodesInRange(editor, from, to, predicate) {
13120
13087
  const candidates = [];
13121
- for (const entry of getNodes(editor, {
13088
+ for (const entry of getNodes(editor.snapshot, {
13122
13089
  from,
13123
13090
  to,
13124
13091
  match: predicate
@@ -13127,7 +13094,7 @@ function unsetMatchedNodesInRange(editor, from, to, predicate) {
13127
13094
  const matchPathRefs = candidates.filter((candidate, index) => !candidates.some((other, otherIndex) => otherIndex > index && isAncestorPath(candidate.path, other.path))).map((entry) => pathRef(editor, entry.path));
13128
13095
  for (const ref of matchPathRefs) {
13129
13096
  const path2 = ref.unref();
13130
- path2 && getNode(editor, path2) && editor.apply({
13097
+ path2 && getNode(editor.snapshot, path2) && editor.apply({
13131
13098
  type: "unset",
13132
13099
  path: path2
13133
13100
  });
@@ -13150,7 +13117,7 @@ function getUnwrapTarget(snapshot, originPath, payloadTypes) {
13150
13117
  }
13151
13118
  }
13152
13119
  function unwrapContainer(editor, originPath, position) {
13153
- const children = getChildren(editor, originPath);
13120
+ const children = getChildren(editor.snapshot, originPath);
13154
13121
  if (children.length === 0) {
13155
13122
  editor.apply({
13156
13123
  type: "unset",
@@ -13158,10 +13125,10 @@ function unwrapContainer(editor, originPath, position) {
13158
13125
  });
13159
13126
  return;
13160
13127
  }
13161
- const payloadTypes = new Set(children.map((child) => child.node._type)), unwrapTarget = getUnwrapTarget(editor, originPath, payloadTypes);
13128
+ const payloadTypes = new Set(children.map((child) => child.node._type)), unwrapTarget = getUnwrapTarget(editor.snapshot, originPath, payloadTypes);
13162
13129
  if (!unwrapTarget)
13163
13130
  return;
13164
- const innerPrefix = children[0].path.slice(0, originPath.length + 1), previousSelection = editor.selection, order = position === "before" ? [...children].reverse() : children;
13131
+ const innerPrefix = children[0].path.slice(0, originPath.length + 1), previousSelection = editor.snapshot.context.selection, order = position === "before" ? [...children].reverse() : children;
13165
13132
  for (const child of order)
13166
13133
  editor.apply({
13167
13134
  type: "insert",
@@ -13176,7 +13143,7 @@ function unwrapContainer(editor, originPath, position) {
13176
13143
  const anchor = transformPoint(previousSelection.anchor, innerPrefix), focus = transformPoint(previousSelection.focus, innerPrefix);
13177
13144
  editor.apply({
13178
13145
  type: "set_selection",
13179
- properties: editor.selection,
13146
+ properties: editor.snapshot.context.selection,
13180
13147
  newProperties: {
13181
13148
  anchor,
13182
13149
  focus
@@ -13193,30 +13160,30 @@ function transformPoint(point2, innerPrefix) {
13193
13160
  const deleteOperationImplementation = ({
13194
13161
  operation
13195
13162
  }) => {
13196
- const at = operation.at ? resolveSelection(operation.editor, operation.at) : operation.editor.selection;
13163
+ const at = operation.at ? resolveSelection(operation.editor, operation.at) : operation.editor.snapshot.context.selection;
13197
13164
  if (!at)
13198
13165
  throw new Error("Unable to delete without a selection");
13199
- const [start2, end2] = rangeEdges(at, operation.editor);
13166
+ const [start2, end2] = rangeEdges(at, operation.editor.snapshot.context);
13200
13167
  if (operation.unit === "block") {
13201
- unsetMatchedNodesInRange(operation.editor, start2.path, end2.path, (_, path2) => isBlock(operation.editor, path2));
13168
+ unsetMatchedNodesInRange(operation.editor, start2.path, end2.path, (_, path2) => isBlock(operation.editor.snapshot, path2));
13202
13169
  return;
13203
13170
  }
13204
13171
  if (operation.unit === "child") {
13205
- unsetMatchedNodesInRange(operation.editor, start2.path, end2.path, (_, path2) => isInline(operation.editor, path2));
13172
+ unsetMatchedNodesInRange(operation.editor, start2.path, end2.path, (_, path2) => isInline(operation.editor.snapshot, path2));
13206
13173
  return;
13207
13174
  }
13208
13175
  if (operation.direction === "backward" && operation.unit === "line") {
13209
- const parentBlockEntry = pathEquals(at.anchor.path, at.focus.path) ? getParent(operation.editor, at.anchor.path, {
13176
+ const parentBlockEntry = pathEquals(at.anchor.path, at.focus.path) ? getParent(operation.editor.snapshot, at.anchor.path, {
13210
13177
  match: (node) => isTextBlock({
13211
- schema: operation.editor.schema
13178
+ schema: operation.editor.snapshot.context.schema
13212
13179
  }, node)
13213
13180
  }) : (() => {
13214
- const fromPath = commonPath(at.anchor.path, at.focus.path), nodeEntry = getNode(operation.editor, fromPath);
13181
+ const fromPath = commonPath(at.anchor.path, at.focus.path), nodeEntry = getNode(operation.editor.snapshot, fromPath);
13215
13182
  return nodeEntry && isTextBlockNode({
13216
- schema: operation.editor.schema
13217
- }, nodeEntry.node) ? nodeEntry : getParent(operation.editor, fromPath, {
13183
+ schema: operation.editor.snapshot.context.schema
13184
+ }, nodeEntry.node) ? nodeEntry : getParent(operation.editor.snapshot, fromPath, {
13218
13185
  match: (node) => isTextBlock({
13219
- schema: operation.editor.schema
13186
+ schema: operation.editor.snapshot.context.schema
13220
13187
  }, node)
13221
13188
  });
13222
13189
  })();
@@ -13233,10 +13200,10 @@ const deleteOperationImplementation = ({
13233
13200
  }
13234
13201
  const direction = operation.direction === "backward" ? "backward" : "forward", selection = operation.at ? "preserve" : "collapse-to-start";
13235
13202
  if (isCollapsedRange(at)) {
13236
- const enclosingContainer = getAncestor(operation.editor, at.anchor.path, {
13237
- match: (node, path2) => isObject$1(operation.editor, node) && isEditableContainer(operation.editor, node, path2)
13238
- }), enclosingContainerChildren = enclosingContainer ? getChildren(operation.editor, enclosingContainer.path) : void 0, [firstChild] = enclosingContainerChildren ?? [];
13239
- if (enclosingContainer && enclosingContainerChildren?.length === 1 && firstChild && isEmptyTextBlock(operation.editor.context, firstChild.node)) {
13203
+ const enclosingContainer = getAncestor(operation.editor.snapshot, at.anchor.path, {
13204
+ match: (node, path2) => isObject$1(operation.editor.snapshot, node) && isEditableContainer(operation.editor.snapshot, node, path2)
13205
+ }), enclosingContainerChildren = enclosingContainer ? getChildren(operation.editor.snapshot, enclosingContainer.path) : void 0, [firstChild] = enclosingContainerChildren ?? [];
13206
+ if (enclosingContainer && enclosingContainerChildren?.length === 1 && firstChild && isEmptyTextBlock(operation.editor.snapshot.context, firstChild.node)) {
13240
13207
  unwrapContainer(operation.editor, enclosingContainer.path, operation.direction === "backward" ? "before" : "after");
13241
13208
  return;
13242
13209
  }
@@ -13257,7 +13224,7 @@ const deleteOperationImplementation = ({
13257
13224
  });
13258
13225
  return;
13259
13226
  }
13260
- deleteRange(operation.editor, unhangRange(operation.editor, at), {
13227
+ deleteRange(operation.editor, unhangRange(operation.editor.snapshot, at), {
13261
13228
  selection,
13262
13229
  removeEmptyStartBlock: !0
13263
13230
  });
@@ -13267,13 +13234,13 @@ function pluginRedoing(editor, fn) {
13267
13234
  editor.isRedoing = !0, fn(), editor.isRedoing = prev;
13268
13235
  }
13269
13236
  function transformOperation(editor, patch, operation) {
13270
- const snapshot = editor, transformedOperation = {
13237
+ const snapshot = editor.snapshot, transformedOperation = {
13271
13238
  ...operation
13272
13239
  };
13273
13240
  if (patch.type === "insert")
13274
13241
  return debug.history(`No path adjustment needed for '${transformedOperation.type}' operation and patch '${patch.type}' (keyed paths)`), [transformedOperation];
13275
13242
  if (patch.type === "unset" && patch.path.length > 0)
13276
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && pathStartsWith(transformedOperation.path, patch.path) ? (debug.history("Skipping transformation that targeted removed block"), []) : [transformedOperation];
13243
+ return "path" in transformedOperation && Array.isArray(transformedOperation.path) && pathContains(patch.path, transformedOperation.path) ? (debug.history("Skipping transformation that targeted removed block"), []) : [transformedOperation];
13277
13244
  if (patch.type === "unset" && patch.path.length === 0)
13278
13245
  return debug.history(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
13279
13246
  if (patch.type === "diffMatchPatch") {
@@ -13311,14 +13278,11 @@ function transformOperation(editor, patch, operation) {
13311
13278
  return [transformedOperation];
13312
13279
  }
13313
13280
  function findOperationTargetBlock(snapshot, editor, operation) {
13314
- if (operation.type === "set_selection" && editor.selection)
13315
- return getEnclosingBlock(snapshot, editor.selection.focus.path)?.node;
13281
+ if (operation.type === "set_selection" && editor.snapshot.context.selection)
13282
+ return getEnclosingBlock(snapshot, editor.snapshot.context.selection.focus.path)?.node;
13316
13283
  if ("path" in operation)
13317
13284
  return getEnclosingBlock(snapshot, operation.path)?.node;
13318
13285
  }
13319
- function pathStartsWith(path2, prefix) {
13320
- return pathEquals(path2, prefix) || isAncestorPath(prefix, path2);
13321
- }
13322
13286
  const historyRedoOperationImplementation = ({
13323
13287
  operation
13324
13288
  }) => {
@@ -13489,7 +13453,7 @@ const historyUndoOperationImplementation = ({
13489
13453
  }) => {
13490
13454
  const {
13491
13455
  context
13492
- } = snapshot, editor = operation.editor, resolved = operation.at ? resolveSelection(editor, operation.at) : resolveSelection(editor, editor.selection), at = resolved && operation.at && operation.placement !== "auto" ? operation.at : resolved, destinationPath = at ? operation.placement === "before" ? rangeStart(at, editor).path : rangeEnd(at, editor).path : editor.children.length > 0 ? end(editor, []).path : void 0, schema = destinationPath ? getPathSubSchema(snapshot, destinationPath) : context.schema, parsedBlock = parseBlock({
13456
+ } = snapshot, editor = operation.editor, resolved = operation.at ? resolveSelection(editor, operation.at) : resolveSelection(editor, editor.snapshot.context.selection), at = resolved && operation.at && operation.placement !== "auto" ? operation.at : resolved, destinationPath = at ? operation.placement === "before" ? rangeStart(at, editor.snapshot.context).path : rangeEnd(at, editor.snapshot.context).path : editor.snapshot.context.value.length > 0 ? end(editor, []).path : void 0, schema = destinationPath ? getPathSubSchema(snapshot, destinationPath) : context.schema, parsedBlock = parseBlock({
13493
13457
  block: operation.block,
13494
13458
  keyGenerator: context.keyGenerator,
13495
13459
  options: {
@@ -13515,7 +13479,7 @@ const historyUndoOperationImplementation = ({
13515
13479
  block,
13516
13480
  target,
13517
13481
  select: operation.select ?? "start",
13518
- selectionAtEntry: editor.selection
13482
+ selectionAtEntry: editor.snapshot.context.selection
13519
13483
  });
13520
13484
  };
13521
13485
  function resolveTarget(args) {
@@ -13525,11 +13489,11 @@ function resolveTarget(args) {
13525
13489
  at,
13526
13490
  placement
13527
13491
  } = args;
13528
- if (editor.children.length === 0)
13492
+ if (editor.snapshot.context.value.length === 0)
13529
13493
  return {
13530
13494
  kind: "empty-editor"
13531
13495
  };
13532
- const [startPoint, endPoint] = at ? rangeEdges(at, editor) : [start(editor, []), end(editor, [])], startBlockEntry = getEnclosingBlock(editor, startPoint.path), endBlockEntry = getEnclosingBlock(editor, endPoint.path);
13496
+ const [startPoint, endPoint] = at ? rangeEdges(at, editor.snapshot.context) : [start(editor, []), end(editor, [])], startBlockEntry = getEnclosingBlock(editor.snapshot, startPoint.path), endBlockEntry = getEnclosingBlock(editor.snapshot, endPoint.path);
13533
13497
  if (!startBlockEntry || !endBlockEntry)
13534
13498
  return;
13535
13499
  const startBlockPath = startBlockEntry.path, endBlock = endBlockEntry.node, endBlockPath = endBlockEntry.path;
@@ -13544,7 +13508,7 @@ function resolveTarget(args) {
13544
13508
  blockPath: endBlockPath
13545
13509
  };
13546
13510
  const schemaContext = {
13547
- schema: editor.schema
13511
+ schema: editor.snapshot.context.schema
13548
13512
  };
13549
13513
  if (!at) {
13550
13514
  if (isEmptyTextBlock(schemaContext, endBlock))
@@ -13567,7 +13531,7 @@ function resolveTarget(args) {
13567
13531
  range: at,
13568
13532
  startBlockPath
13569
13533
  };
13570
- const collapsedPoint = rangeStart(at, editor);
13534
+ const collapsedPoint = rangeStart(at, editor.snapshot.context);
13571
13535
  if (isEmptyTextBlock(schemaContext, endBlock))
13572
13536
  return {
13573
13537
  kind: "replace",
@@ -13693,10 +13657,10 @@ function splitBlockAndInsert(editor, block, blockPath, splitAt) {
13693
13657
  affinity: "backward"
13694
13658
  });
13695
13659
  if (splitAt.offset > 0) {
13696
- const spanEntry = getSpan(editor, splitAt.path);
13660
+ const spanEntry = getSpan(editor.snapshot, splitAt.path);
13697
13661
  spanEntry && splitAt.offset < spanEntry.node.text.length && applySplitNode(editor, splitAt.path, splitAt.offset);
13698
13662
  }
13699
- const currentBlockPath = blockPathRef.current ?? blockPath, blockEntry = getTextBlock(editor, currentBlockPath);
13663
+ const currentBlockPath = blockPathRef.current ?? blockPath, blockEntry = getTextBlock(editor.snapshot, currentBlockPath);
13700
13664
  if (blockEntry) {
13701
13665
  const childSegment = splitAt.path[blockPath.length + 1], childIndex = resolveChildIndex(blockEntry.node.children, childSegment), splitAtIndex = splitAt.offset > 0 ? childIndex + 1 : childIndex;
13702
13666
  splitAtIndex > 0 && splitAtIndex < blockEntry.node.children.length && applySplitNode(editor, currentBlockPath, splitAtIndex);
@@ -13713,7 +13677,7 @@ function mergeTextBlockFragment(args) {
13713
13677
  endBlockPath,
13714
13678
  select: select2,
13715
13679
  wasCrossBlock
13716
- } = args, endBlockEntry = getTextBlock(editor, endBlockPath);
13680
+ } = args, endBlockEntry = getTextBlock(editor.snapshot, endBlockPath);
13717
13681
  if (!endBlockEntry)
13718
13682
  return;
13719
13683
  const endBlock = endBlockEntry.node, {
@@ -13743,9 +13707,9 @@ function applyPostInsertSelection(editor, insertedBlockPath, select2, selectionA
13743
13707
  applySelect(editor, selectionAtEntry);
13744
13708
  return;
13745
13709
  }
13746
- editor.selection && editor.apply({
13710
+ editor.snapshot.context.selection && editor.apply({
13747
13711
  type: "set_selection",
13748
- properties: editor.selection,
13712
+ properties: editor.snapshot.context.selection,
13749
13713
  newProperties: null
13750
13714
  });
13751
13715
  return;
@@ -13761,22 +13725,22 @@ function executeDeleteThenInsert(args) {
13761
13725
  range: range2,
13762
13726
  select: select2,
13763
13727
  selectionAtEntry
13764
- } = args, rangeStartPoint = rangeStart(range2, editor), rangeEndPoint = rangeEnd(range2, editor), startBlockEntry = getEnclosingBlock(editor, rangeStartPoint.path), endBlockEntry = getEnclosingBlock(editor, rangeEndPoint.path), wasCrossBlock = startBlockEntry !== void 0 && endBlockEntry !== void 0 && !pathEquals(startBlockEntry.path, endBlockEntry.path), startBlockPath = startBlockEntry?.path, startOfStartBlock = startBlockPath ? start(editor, startBlockPath) : void 0, isAtStartOfBlock = startOfStartBlock ? pointEquals(rangeStartPoint, startOfStartBlock) : !1, collapsedRangeRef = rangeRef(editor, range2, {
13728
+ } = args, rangeStartPoint = rangeStart(range2, editor.snapshot.context), rangeEndPoint = rangeEnd(range2, editor.snapshot.context), startBlockEntry = getEnclosingBlock(editor.snapshot, rangeStartPoint.path), endBlockEntry = getEnclosingBlock(editor.snapshot, rangeEndPoint.path), wasCrossBlock = startBlockEntry !== void 0 && endBlockEntry !== void 0 && !pathEquals(startBlockEntry.path, endBlockEntry.path), startBlockPath = startBlockEntry?.path, startOfStartBlock = startBlockPath ? start(editor, startBlockPath) : void 0, isAtStartOfBlock = startOfStartBlock ? pointEquals(rangeStartPoint, startOfStartBlock) : !1, collapsedRangeRef = rangeRef(editor, range2, {
13765
13729
  affinity: "inward"
13766
13730
  });
13767
13731
  deleteRange(editor, range2, {
13768
13732
  selection: "preserve",
13769
13733
  removeEmptyStartBlock: !1
13770
13734
  });
13771
- const collapsedRange = collapsedRangeRef.unref() ?? editor.selection, collapsedPoint = collapsedRange ? rangeStart(collapsedRange, editor) : void 0;
13735
+ const collapsedRange = collapsedRangeRef.unref() ?? editor.snapshot.context.selection, collapsedPoint = collapsedRange ? rangeStart(collapsedRange, editor.snapshot.context) : void 0;
13772
13736
  if (!collapsedPoint)
13773
13737
  return;
13774
- const resolvedBlock = getParent(editor, collapsedPoint.path, {
13738
+ const resolvedBlock = getParent(editor.snapshot, collapsedPoint.path, {
13775
13739
  match: (node) => isTextBlock({
13776
- schema: editor.schema
13740
+ schema: editor.snapshot.context.schema
13777
13741
  }, node)
13778
13742
  }), blockIsText = isTextBlock({
13779
- schema: editor.schema
13743
+ schema: editor.snapshot.context.schema
13780
13744
  }, block), postDeleteSelection = select2 === "none" ? collapsedRange : selectionAtEntry;
13781
13745
  if (blockIsText && resolvedBlock) {
13782
13746
  if (!wasCrossBlock && isEmptyTextBlock(context, resolvedBlock.node)) {
@@ -13808,7 +13772,7 @@ function executeDeleteThenInsert(args) {
13808
13772
  });
13809
13773
  return;
13810
13774
  }
13811
- const containingBlockEntry = resolvedBlock ?? getEnclosingBlock(editor, collapsedPoint.path);
13775
+ const containingBlockEntry = resolvedBlock ?? getEnclosingBlock(editor.snapshot, collapsedPoint.path);
13812
13776
  if (!containingBlockEntry)
13813
13777
  return;
13814
13778
  const insertedPath = insertSiblingBlock(editor, block, containingBlockEntry.path, isAtStartOfBlock ? "before" : "after");
@@ -13825,7 +13789,7 @@ function removeAdjacentEmptyTextBlock(args) {
13825
13789
  insertedPath
13826
13790
  } = args;
13827
13791
  for (const direction of ["next", "previous"]) {
13828
- const sibling = getSibling(editor, insertedPath, {
13792
+ const sibling = getSibling(editor.snapshot, insertedPath, {
13829
13793
  direction
13830
13794
  });
13831
13795
  if (sibling && isEmptyTextBlock(context, sibling.node)) {
@@ -13894,16 +13858,16 @@ function adjustFragmentKeys(args) {
13894
13858
  }
13895
13859
  function insertFragmentChildren(editor, block, at) {
13896
13860
  if (!isTextBlock({
13897
- schema: editor.schema
13861
+ schema: editor.snapshot.context.schema
13898
13862
  }, block))
13899
13863
  return;
13900
- at.offset > 0 && getSpan(editor, at.path) && applySplitNode(editor, at.path, at.offset);
13864
+ at.offset > 0 && getSpan(editor.snapshot, at.path) && applySplitNode(editor, at.path, at.offset);
13901
13865
  const parent = parentPath(at.path);
13902
13866
  let firstInsertedKey;
13903
13867
  if (at.offset === 0 && block.children.length === 1) {
13904
- const firstChild = block.children[0], existingEntry = getSpan(editor, at.path);
13868
+ const firstChild = block.children[0], existingEntry = getSpan(editor.snapshot, at.path);
13905
13869
  if (existingEntry && isSpan({
13906
- schema: editor.schema
13870
+ schema: editor.snapshot.context.schema
13907
13871
  }, firstChild))
13908
13872
  return firstChild.text.length > 0 && editor.apply({
13909
13873
  type: "insert_text",
@@ -13932,12 +13896,12 @@ const insertChildOperationImplementation = ({
13932
13896
  }) => {
13933
13897
  const {
13934
13898
  context
13935
- } = snapshot, focus = operation.editor.selection?.focus;
13899
+ } = snapshot, focus = operation.editor.snapshot.context.selection?.focus;
13936
13900
  if (!focus)
13937
13901
  throw new Error("Unable to insert child without a focus");
13938
- const focusBlockEntry = getParent(operation.editor, focus.path, {
13902
+ const focusBlockEntry = getParent(operation.editor.snapshot, focus.path, {
13939
13903
  match: (node) => isTextBlock({
13940
- schema: operation.editor.schema
13904
+ schema: operation.editor.snapshot.context.schema
13941
13905
  }, node)
13942
13906
  });
13943
13907
  if (!focusBlockEntry)
@@ -13961,13 +13925,13 @@ const insertChildOperationImplementation = ({
13961
13925
  schema
13962
13926
  });
13963
13927
  if (span) {
13964
- const focusSpanEntry = getNode(operation.editor, focusChildPath);
13928
+ const focusSpanEntry = getNode(operation.editor.snapshot, focusChildPath);
13965
13929
  if (focusSpanEntry && isSpan({
13966
- schema: operation.editor.schema
13930
+ schema: operation.editor.snapshot.context.schema
13967
13931
  }, focusSpanEntry.node) && focusSpanEntry.node)
13968
13932
  applyInsertNodeAtPoint(operation.editor, span, focus);
13969
13933
  else {
13970
- const nextSibling = getSibling(operation.editor, focusChildPath, {
13934
+ const nextSibling = getSibling(operation.editor.snapshot, focusChildPath, {
13971
13935
  direction: "next"
13972
13936
  });
13973
13937
  nextSibling ? applyInsertNodeAtPath(operation.editor, span, nextSibling.path) : operation.editor.apply({
@@ -13977,7 +13941,7 @@ const insertChildOperationImplementation = ({
13977
13941
  position: "after"
13978
13942
  });
13979
13943
  }
13980
- operation.editor.pendingSelection = operation.editor.selection;
13944
+ operation.editor.pendingSelection = operation.editor.snapshot.context.selection;
13981
13945
  return;
13982
13946
  }
13983
13947
  const inlineObject = parseInlineObject({
@@ -13997,13 +13961,13 @@ const insertChildOperationImplementation = ({
13997
13961
  _key,
13998
13962
  _type,
13999
13963
  ...rest
14000
- }, focusSpanEntry = getNode(operation.editor, focusChildPath);
13964
+ }, focusSpanEntry = getNode(operation.editor.snapshot, focusChildPath);
14001
13965
  if (focusSpanEntry && isSpan({
14002
- schema: operation.editor.schema
13966
+ schema: operation.editor.snapshot.context.schema
14003
13967
  }, focusSpanEntry.node) && focusSpanEntry.node)
14004
13968
  applyInsertNodeAtPoint(operation.editor, inlineNode, focus);
14005
13969
  else {
14006
- const nextSibling = getSibling(operation.editor, focusChildPath, {
13970
+ const nextSibling = getSibling(operation.editor.snapshot, focusChildPath, {
14007
13971
  direction: "next"
14008
13972
  });
14009
13973
  nextSibling ? applyInsertNodeAtPath(operation.editor, inlineNode, nextSibling.path) : operation.editor.apply({
@@ -14034,23 +13998,23 @@ const insertChildOperationImplementation = ({
14034
13998
  }
14035
13999
  const {
14036
14000
  selection
14037
- } = editor;
14001
+ } = editor.snapshot.context;
14038
14002
  if (!selection || !isCollapsedRange(selection))
14039
14003
  return;
14040
14004
  let {
14041
14005
  path: path2,
14042
14006
  offset
14043
14007
  } = selection.anchor;
14044
- const nodeEntry = getNode(editor, path2);
14008
+ const nodeEntry = getNode(editor.snapshot, path2);
14045
14009
  if (!nodeEntry)
14046
14010
  return;
14047
14011
  const node = nodeEntry.node;
14048
- if (isLeafObject(editor, node, nodeEntry.path)) {
14049
- const nextSibling = getSibling(editor, nodeEntry.path, {
14012
+ if (isLeafObject(editor.snapshot, node, nodeEntry.path)) {
14013
+ const nextSibling = getSibling(editor.snapshot, nodeEntry.path, {
14050
14014
  direction: "next"
14051
14015
  });
14052
14016
  if (nextSibling)
14053
- if (getSpan(editor, nextSibling.path))
14017
+ if (getSpan(editor.snapshot, nextSibling.path))
14054
14018
  path2 = nextSibling.path, offset = 0, applySelect(editor, {
14055
14019
  path: path2,
14056
14020
  offset
@@ -14068,9 +14032,7 @@ const insertChildOperationImplementation = ({
14068
14032
  });
14069
14033
  };
14070
14034
  function applyMove(editor, options = {}) {
14071
- const {
14072
- selection
14073
- } = editor;
14035
+ const selection = editor.snapshot.context.selection;
14074
14036
  if (!selection)
14075
14037
  return;
14076
14038
  const {
@@ -14117,7 +14079,7 @@ const moveBackwardOperationImplementation = ({
14117
14079
  operation
14118
14080
  }) => {
14119
14081
  const newSelection = resolveSelection(operation.editor, operation.at);
14120
- newSelection ? applySelect(operation.editor, newSelection) : applyDeselect(operation.editor), operation.editor.focused && operation.editor.readOnly && (operation.editor.focused = !1);
14082
+ newSelection ? applySelect(operation.editor, newSelection) : applyDeselect(operation.editor), operation.editor.focused && operation.editor.snapshot.context.readOnly && (operation.editor.focused = !1);
14121
14083
  }, setOperationImplementation = ({
14122
14084
  operation
14123
14085
  }) => {
@@ -16069,7 +16031,7 @@ function performEvent({
16069
16031
  if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
16070
16032
  nativeEvent?.preventDefault(), mode === "send" && (editor.undoStepId = void 0), withPerformingBehaviorOperation(editor, () => {
16071
16033
  debug.operation.enabled && debug.operation(safeStringify(event, 2)), performOperation({
16072
- snapshot: editor,
16034
+ snapshot: editor.snapshot,
16073
16035
  operation: {
16074
16036
  ...event,
16075
16037
  editor
@@ -16192,7 +16154,7 @@ function performEvent({
16192
16154
  }
16193
16155
  !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && (editor.undoStepId = void 0), withPerformingBehaviorOperation(editor, () => {
16194
16156
  debug.operation.enabled && debug.operation(safeStringify(event, 2)), performOperation({
16195
- snapshot: editor,
16157
+ snapshot: editor.snapshot,
16196
16158
  operation: {
16197
16159
  ...event,
16198
16160
  editor
@@ -16243,13 +16205,6 @@ function sortByPriority(items) {
16243
16205
  result.includes(item) || result.push(item);
16244
16206
  return [...result, ...itemsWithoutPriority];
16245
16207
  }
16246
- function pathsOverlap(pathA, pathB) {
16247
- const minLength = Math.min(pathA.length, pathB.length);
16248
- for (let i = 0; i < minLength; i++)
16249
- if (!isEqualPathSegments(pathA[i], pathB[i]))
16250
- return !1;
16251
- return !0;
16252
- }
16253
16208
  function buildPublicContainers(resolved) {
16254
16209
  const projected = /* @__PURE__ */ new Map();
16255
16210
  for (const [type, config] of resolved)
@@ -16427,11 +16382,11 @@ function registerNodeOnEngine(engine, node) {
16427
16382
  if (node.kind === "container") {
16428
16383
  if (isTypeAlreadyRegistered(engine, "container", node.type))
16429
16384
  return;
16430
- const containerConfig = resolveNestedContainer(engine.schema, node);
16385
+ const containerConfig = resolveNestedContainer(engine.snapshot.context.schema, node);
16431
16386
  if (!containerConfig)
16432
16387
  return;
16433
16388
  const containers = new Map(engine.containers);
16434
- containers.set(node.type, containerConfig), engine.containers = containers, engine.publicContainers = buildPublicContainers(containers), normalize(engine, {
16389
+ containers.set(node.type, containerConfig), engine.containers = containers, engine.snapshot.context.containers = buildPublicContainers(containers), normalize(engine, {
16435
16390
  force: !0
16436
16391
  }), engine.onChange();
16437
16392
  return;
@@ -16471,7 +16426,7 @@ function registerNodeOnEngine(engine, node) {
16471
16426
  function unregisterNodeOnEngine(engine, node) {
16472
16427
  if (node.kind === "container") {
16473
16428
  const containers = new Map(engine.containers);
16474
- containers.delete(node.type), engine.containers = containers, engine.publicContainers = buildPublicContainers(containers), normalize(engine, {
16429
+ containers.delete(node.type), engine.containers = containers, engine.snapshot.context.containers = buildPublicContainers(containers), normalize(engine, {
16475
16430
  force: !0
16476
16431
  }), engine.onChange();
16477
16432
  return;
@@ -16601,7 +16556,7 @@ const editorMachine = setup({
16601
16556
  context,
16602
16557
  enqueue
16603
16558
  }) => {
16604
- context.editorEngine && (context.editorEngine.readOnly = !0, context.editorEngine.onChange()), enqueue.emit({
16559
+ context.editorEngine && (context.editorEngine.snapshot.context.readOnly = !0, context.editorEngine.onChange()), enqueue.emit({
16605
16560
  type: "read only"
16606
16561
  });
16607
16562
  }),
@@ -16609,7 +16564,7 @@ const editorMachine = setup({
16609
16564
  context,
16610
16565
  enqueue
16611
16566
  }) => {
16612
- context.editorEngine && (context.editorEngine.readOnly = !1, context.editorEngine.onChange()), enqueue.emit({
16567
+ context.editorEngine && (context.editorEngine.snapshot.context.readOnly = !1, context.editorEngine.onChange()), enqueue.emit({
16613
16568
  type: "editable"
16614
16569
  });
16615
16570
  }),
@@ -16640,7 +16595,7 @@ const editorMachine = setup({
16640
16595
  if (event.type !== "patches")
16641
16596
  return context.pendingEvents;
16642
16597
  const incomingPaths = event.patches.map((patch) => patch.path);
16643
- return context.pendingEvents.filter((pendingEvent) => pendingEvent.type !== "internal.patch" ? !0 : !incomingPaths.some((incomingPath) => pathsOverlap(pendingEvent.patch.path, incomingPath)));
16598
+ return context.pendingEvents.filter((pendingEvent) => pendingEvent.type !== "internal.patch" ? !0 : !incomingPaths.some((incomingPath) => pathContains(pendingEvent.patch.path, incomingPath) || pathContains(incomingPath, pendingEvent.patch.path)));
16644
16599
  }
16645
16600
  }),
16646
16601
  "discard all pending events": assign({
@@ -16681,8 +16636,8 @@ const editorMachine = setup({
16681
16636
  return;
16682
16637
  }
16683
16638
  try {
16684
- const currentSelection = editorEngine.selection;
16685
- DOMEditor.focus(editorEngine), currentSelection && (editorEngine.select(currentSelection), editorEngine.pendingSelection = editorEngine.selection, editorEngine.onChange());
16639
+ const currentSelection = editorEngine.snapshot.context.selection;
16640
+ DOMEditor.focus(editorEngine), currentSelection && (editorEngine.select(currentSelection), editorEngine.pendingSelection = editorEngine.snapshot.context.selection, editorEngine.onChange());
16686
16641
  } catch (error) {
16687
16642
  console.error(new Error(`Failed to focus editor: ${error instanceof Error ? error.message : error}`));
16688
16643
  }
@@ -16701,10 +16656,10 @@ const editorMachine = setup({
16701
16656
  remainingEventBehaviors: behaviors,
16702
16657
  event: event.behaviorEvent,
16703
16658
  editor: event.editor,
16704
- converters: event.editor.converters,
16705
- keyGenerator: event.editor.keyGenerator,
16706
- schema: event.editor.schema,
16707
- readOnly: event.editor.readOnly,
16659
+ converters: event.editor.snapshot.context.converters,
16660
+ keyGenerator: event.editor.snapshot.context.keyGenerator,
16661
+ schema: event.editor.snapshot.context.schema,
16662
+ readOnly: event.editor.snapshot.context.readOnly,
16708
16663
  nativeEvent: event.nativeEvent,
16709
16664
  sendBack: (eventSentBack) => {
16710
16665
  if (eventSentBack.type === "set drag ghost") {
@@ -17947,7 +17902,7 @@ async function updateValue({
17947
17902
  value
17948
17903
  }) {
17949
17904
  let doneSyncing = !1, isChanged = !1, isValid = !0;
17950
- const hadSelection = !!editorEngine.selection;
17905
+ const hadSelection = !!editorEngine.snapshot.context.selection;
17951
17906
  if ((!value || value.length === 0) && (clearEditor({
17952
17907
  editorEngine,
17953
17908
  doneSyncing
@@ -18029,7 +17984,7 @@ async function updateValue({
18029
17984
  });
18030
17985
  return;
18031
17986
  }
18032
- hadSelection && !editorEngine.selection && editorEngine.children.length > 0 && (applySelect(editorEngine, start(editorEngine, [])), editorEngine.onChange()), sendBack({
17987
+ hadSelection && !editorEngine.snapshot.context.selection && editorEngine.snapshot.context.value.length > 0 && (applySelect(editorEngine, start(editorEngine, [])), editorEngine.onChange()), sendBack({
18033
17988
  type: "value changed",
18034
17989
  value
18035
17990
  });
@@ -18057,9 +18012,9 @@ function clearEditor({
18057
18012
  withoutPatching(editorEngine, () => {
18058
18013
  if (doneSyncing)
18059
18014
  return;
18060
- const childrenLength = editorEngine.children.length;
18061
- editorEngine.children.forEach((_, index) => {
18062
- const removeNode = editorEngine.children[childrenLength - 1 - index];
18015
+ const childrenLength = editorEngine.snapshot.context.value.length;
18016
+ editorEngine.snapshot.context.value.forEach((_, index) => {
18017
+ const removeNode = editorEngine.snapshot.context.value[childrenLength - 1 - index];
18063
18018
  removeNode && editorEngine.apply({
18064
18019
  type: "unset",
18065
18020
  path: [{
@@ -18080,10 +18035,10 @@ function removeExtraBlocks({
18080
18035
  return withoutNormalizing(editorEngine, () => {
18081
18036
  withRemoteChanges(editorEngine, () => {
18082
18037
  withoutPatching(editorEngine, () => {
18083
- const childrenLength = editorEngine.children.length;
18038
+ const childrenLength = editorEngine.snapshot.context.value.length;
18084
18039
  if (value.length < childrenLength) {
18085
18040
  for (let i = childrenLength - 1; i > value.length - 1; i--) {
18086
- const removeNode = editorEngine.children[i];
18041
+ const removeNode = editorEngine.snapshot.context.value[i];
18087
18042
  removeNode && editorEngine.apply({
18088
18043
  type: "unset",
18089
18044
  path: [{
@@ -18105,7 +18060,7 @@ function syncBlock({
18105
18060
  editorEngine,
18106
18061
  value
18107
18062
  }) {
18108
- const oldEngineBlock = editorEngine.children.at(index), oldBlock = editorEngine.children.at(index);
18063
+ const oldEngineBlock = editorEngine.snapshot.context.value.at(index), oldBlock = editorEngine.snapshot.context.value.at(index);
18109
18064
  if (!oldEngineBlock || !oldBlock) {
18110
18065
  const validation2 = validateValue([block], context.schema, context.keyGenerator);
18111
18066
  if (debug.syncValue("Validating and inserting new block in the end of the value", block), validation2.valid || validation2.resolution?.autoResolve) {
@@ -18117,7 +18072,7 @@ function syncBlock({
18117
18072
  withoutPatching(editorEngine, () => {
18118
18073
  editorEngine.apply({
18119
18074
  type: "insert",
18120
- path: [editorEngine.children.length],
18075
+ path: [editorEngine.snapshot.context.value.length],
18121
18076
  node: engineBlock,
18122
18077
  position: "before"
18123
18078
  });
@@ -18197,9 +18152,9 @@ function replaceBlock({
18197
18152
  }) {
18198
18153
  const engineBlock = toEngineBlock(block, {
18199
18154
  schemaTypes: context.schema
18200
- }), currentSelection = editorEngine.selection, focusBlockSegment = currentSelection?.focus.path[0], blockAtIndex = editorEngine.children[index], selectionFocusOnBlock = currentSelection && isKeyedSegment(focusBlockSegment) && blockAtIndex && focusBlockSegment._key === blockAtIndex._key;
18155
+ }), currentSelection = editorEngine.snapshot.context.selection, focusBlockSegment = currentSelection?.focus.path[0], blockAtIndex = editorEngine.snapshot.context.value[index], selectionFocusOnBlock = currentSelection && isKeyedSegment(focusBlockSegment) && blockAtIndex && focusBlockSegment._key === blockAtIndex._key;
18201
18156
  selectionFocusOnBlock && applyDeselect(editorEngine);
18202
- const oldNode = editorEngine.children[index];
18157
+ const oldNode = editorEngine.snapshot.context.value[index];
18203
18158
  oldNode && (editorEngine.apply({
18204
18159
  type: "unset",
18205
18160
  path: [{
@@ -18210,7 +18165,7 @@ function replaceBlock({
18210
18165
  path: [index],
18211
18166
  node: engineBlock,
18212
18167
  position: "before"
18213
- }), editorEngine.onChange(), selectionFocusOnBlock && hasNode(editorEngine, currentSelection.anchor.path) && hasNode(editorEngine, currentSelection.focus.path) && applySelect(editorEngine, currentSelection));
18168
+ }), editorEngine.onChange(), selectionFocusOnBlock && hasNode(editorEngine.snapshot, currentSelection.anchor.path) && hasNode(editorEngine.snapshot, currentSelection.focus.path) && applySelect(editorEngine, currentSelection));
18214
18169
  }
18215
18170
  function updateBlock({
18216
18171
  context,
@@ -18234,9 +18189,9 @@ function updateBlock({
18234
18189
  if (Object.keys(removedProperties).length > 0 && setNodeProperties(editorEngine, removedProperties, [{
18235
18190
  _key: oldEngineBlock._key
18236
18191
  }]), isTextBlock({
18237
- schema: editorEngine.schema
18192
+ schema: editorEngine.snapshot.context.schema
18238
18193
  }, engineBlock) && isTextBlock({
18239
- schema: editorEngine.schema
18194
+ schema: editorEngine.snapshot.context.schema
18240
18195
  }, oldEngineBlock)) {
18241
18196
  const oldKeys = oldEngineBlock.children.map((c2) => c2._key), newKeys = engineBlock.children.map((c2) => c2._key), oldKeySet = new Set(oldKeys), hasSharedKeys = newKeys.some((key) => oldKeySet.has(key));
18242
18197
  if (oldKeys.length === newKeys.length && oldKeys.length > 0 && oldKeySet.size === oldKeys.length && oldKeys.some((key, i) => key !== newKeys[i]) && newKeys.every((key) => oldKeySet.has(key)) || newKeys.length > 0 && !hasSharedKeys) {
@@ -18265,8 +18220,8 @@ function updateBlock({
18265
18220
  });
18266
18221
  }
18267
18222
  }), engineBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
18268
- const oldBlockChild = oldEngineBlock.children.at(currentBlockChildIndex), isChildChanged = !oldBlockChild || !isEqualChild(currentBlockChild, oldBlockChild, editorEngine.schema.span.name), isTextChanged = oldBlockChild && isSpan({
18269
- schema: editorEngine.schema
18223
+ const oldBlockChild = oldEngineBlock.children.at(currentBlockChildIndex), isChildChanged = !oldBlockChild || !isEqualChild(currentBlockChild, oldBlockChild, editorEngine.snapshot.context.schema.span.name), isTextChanged = oldBlockChild && isSpan({
18224
+ schema: editorEngine.snapshot.context.schema
18270
18225
  }, oldBlockChild) && currentBlockChild.text !== oldBlockChild.text, path2 = [{
18271
18226
  _key: oldEngineBlock._key
18272
18227
  }, "children", {
@@ -18523,7 +18478,7 @@ function createActors(config) {
18523
18478
  config.editorActor.send({
18524
18479
  ...event,
18525
18480
  type: "internal.patch",
18526
- value: config.editorEngine.children
18481
+ value: config.editorEngine.snapshot.context.value
18527
18482
  });
18528
18483
  break;
18529
18484
  default:
@@ -19003,8 +18958,14 @@ function EditorProvider(props) {
19003
18958
  let t8;
19004
18959
  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;
19005
18960
  }
18961
+ function defaultCompare(a, b) {
18962
+ return a === b;
18963
+ }
18964
+ function useEditorSelector(editor, selector, t0) {
18965
+ return useSelector(editor, selector, t0 === void 0 ? defaultCompare : t0);
18966
+ }
19006
18967
  const usePortableTextEditorSelection = () => {
19007
- const $ = c(3), editorActor = useContext(EditorActorContext), editorEngine = useEngineStatic(), [selection, setSelection2] = useState(editorEngine.selection);
18968
+ const $ = c(3), editorActor = useContext(EditorActorContext), editorEngine = useEngineStatic(), [selection, setSelection2] = useState(editorEngine.snapshot.context.selection);
19008
18969
  let t0, t1;
19009
18970
  return $[0] !== editorActor ? (t0 = () => {
19010
18971
  const subscription = editorActor.on("selection", (event) => {