@portabletext/editor 4.2.1 → 4.2.3

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,7 +3,7 @@ import { c } from "react/compiler-runtime";
3
3
  import { useSelector, useActorRef } from "@xstate/react";
4
4
  import { createContext, useContext, useRef, useState, useEffect, forwardRef, Component, startTransition } from "react";
5
5
  import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transforms, createEditor, deleteText, Operation } from "slate";
6
- import { useSlateStatic, ReactEditor, useSlate, Editable, withReact, Slate } from "slate-react";
6
+ import { useSlateStatic, useSlateSelector, ReactEditor, useSlate, Editable, withReact, Slate } from "slate-react";
7
7
  import rawDebug from "debug";
8
8
  import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION, IS_FOCUSED, IS_READ_ONLY } from "slate-dom";
9
9
  import { getBlockEndPoint, getBlockStartPoint, getBlockKeyFromSelectionPoint, isSelectionCollapsed, isKeyedSegment, isEqualSelectionPoints, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, isListBlock, isTypedObject, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject } from "./_chunks-es/util.slice-blocks.js";
@@ -1575,90 +1575,90 @@ function RenderChild$1({
1575
1575
  });
1576
1576
  }
1577
1577
  function RenderTextBlock(props) {
1578
- const $ = c(77), blockRef = useRef(null), {
1578
+ const $ = c(76), blockRef = useRef(null), {
1579
1579
  selectedBlockKeys,
1580
1580
  focusedBlockKey
1581
1581
  } = useContext(SelectionStateContext);
1582
1582
  let t0;
1583
1583
  $[0] !== props.textBlock._key || $[1] !== selectedBlockKeys ? (t0 = selectedBlockKeys.has(props.textBlock._key), $[0] = props.textBlock._key, $[1] = selectedBlockKeys, $[2] = t0) : t0 = $[2];
1584
- const selected = t0, focused = focusedBlockKey === props.textBlock._key, slateEditor = useSlateStatic();
1584
+ const selected = t0, focused = focusedBlockKey === props.textBlock._key;
1585
1585
  let t1;
1586
- $[3] !== props.textBlock._key || $[4] !== slateEditor.listIndexMap ? (t1 = slateEditor.listIndexMap.get(props.textBlock._key), $[3] = props.textBlock._key, $[4] = slateEditor.listIndexMap, $[5] = t1) : t1 = $[5];
1587
- const listIndex = t1;
1586
+ $[3] !== props.textBlock._key ? (t1 = (editor) => editor.listIndexMap.get(props.textBlock._key), $[3] = props.textBlock._key, $[4] = t1) : t1 = $[4];
1587
+ const listIndex = useSlateSelector(t1);
1588
1588
  let children = props.children;
1589
1589
  if (props.renderStyle && props.textBlock.style) {
1590
1590
  let t22;
1591
- $[6] !== props.legacySchema || $[7] !== props.textBlock.style ? (t22 = props.textBlock.style !== void 0 ? props.legacySchema.styles.find((style) => style.value === props.textBlock.style) : void 0, $[6] = props.legacySchema, $[7] = props.textBlock.style, $[8] = t22) : t22 = $[8];
1591
+ $[5] !== props.legacySchema || $[6] !== props.textBlock.style ? (t22 = props.textBlock.style !== void 0 ? props.legacySchema.styles.find((style) => style.value === props.textBlock.style) : void 0, $[5] = props.legacySchema, $[6] = props.textBlock.style, $[7] = t22) : t22 = $[7];
1592
1592
  const legacyStyleSchemaType = t22;
1593
1593
  if (legacyStyleSchemaType) {
1594
1594
  let t32;
1595
- $[9] !== props.textBlock._key ? (t32 = [{
1595
+ $[8] !== props.textBlock._key ? (t32 = [{
1596
1596
  _key: props.textBlock._key
1597
- }], $[9] = props.textBlock._key, $[10] = t32) : t32 = $[10];
1597
+ }], $[8] = props.textBlock._key, $[9] = t32) : t32 = $[9];
1598
1598
  let t42;
1599
- $[11] !== children || $[12] !== focused || $[13] !== legacyStyleSchemaType || $[14] !== props.renderStyle || $[15] !== props.textBlock || $[16] !== selected || $[17] !== t32 ? (t42 = /* @__PURE__ */ jsx(RenderStyle, { renderStyle: props.renderStyle, block: props.textBlock, editorElementRef: blockRef, focused, path: t32, schemaType: legacyStyleSchemaType, selected, value: props.textBlock.style, children }), $[11] = children, $[12] = focused, $[13] = legacyStyleSchemaType, $[14] = props.renderStyle, $[15] = props.textBlock, $[16] = selected, $[17] = t32, $[18] = t42) : t42 = $[18], children = t42;
1599
+ $[10] !== children || $[11] !== focused || $[12] !== legacyStyleSchemaType || $[13] !== props.renderStyle || $[14] !== props.textBlock || $[15] !== selected || $[16] !== t32 ? (t42 = /* @__PURE__ */ jsx(RenderStyle, { renderStyle: props.renderStyle, block: props.textBlock, editorElementRef: blockRef, focused, path: t32, schemaType: legacyStyleSchemaType, selected, value: props.textBlock.style, children }), $[10] = children, $[11] = focused, $[12] = legacyStyleSchemaType, $[13] = props.renderStyle, $[14] = props.textBlock, $[15] = selected, $[16] = t32, $[17] = t42) : t42 = $[17], children = t42;
1600
1600
  } else
1601
1601
  console.error(`Unable to find Schema type for text block style ${props.textBlock.style}`);
1602
1602
  }
1603
1603
  if (props.renderListItem && props.textBlock.listItem) {
1604
1604
  let t22;
1605
- if ($[19] !== props.legacySchema.lists || $[20] !== props.textBlock.listItem) {
1605
+ if ($[18] !== props.legacySchema.lists || $[19] !== props.textBlock.listItem) {
1606
1606
  let t32;
1607
- $[22] !== props.textBlock.listItem ? (t32 = (list) => list.value === props.textBlock.listItem, $[22] = props.textBlock.listItem, $[23] = t32) : t32 = $[23], t22 = props.legacySchema.lists.find(t32), $[19] = props.legacySchema.lists, $[20] = props.textBlock.listItem, $[21] = t22;
1607
+ $[21] !== props.textBlock.listItem ? (t32 = (list) => list.value === props.textBlock.listItem, $[21] = props.textBlock.listItem, $[22] = t32) : t32 = $[22], t22 = props.legacySchema.lists.find(t32), $[18] = props.legacySchema.lists, $[19] = props.textBlock.listItem, $[20] = t22;
1608
1608
  } else
1609
- t22 = $[21];
1609
+ t22 = $[20];
1610
1610
  const legacyListItemSchemaType = t22;
1611
1611
  if (legacyListItemSchemaType) {
1612
1612
  const t32 = props.textBlock.level ?? 1;
1613
1613
  let t42;
1614
- $[24] !== props.textBlock._key ? (t42 = [{
1614
+ $[23] !== props.textBlock._key ? (t42 = [{
1615
1615
  _key: props.textBlock._key
1616
- }], $[24] = props.textBlock._key, $[25] = t42) : t42 = $[25];
1616
+ }], $[23] = props.textBlock._key, $[24] = t42) : t42 = $[24];
1617
1617
  let t52;
1618
- $[26] !== children || $[27] !== focused || $[28] !== legacyListItemSchemaType || $[29] !== props.renderListItem || $[30] !== props.textBlock || $[31] !== selected || $[32] !== t32 || $[33] !== t42 ? (t52 = /* @__PURE__ */ jsx(RenderListItem, { renderListItem: props.renderListItem, block: props.textBlock, editorElementRef: blockRef, focused, level: t32, path: t42, selected, value: props.textBlock.listItem, schemaType: legacyListItemSchemaType, children }), $[26] = children, $[27] = focused, $[28] = legacyListItemSchemaType, $[29] = props.renderListItem, $[30] = props.textBlock, $[31] = selected, $[32] = t32, $[33] = t42, $[34] = t52) : t52 = $[34], children = t52;
1618
+ $[25] !== children || $[26] !== focused || $[27] !== legacyListItemSchemaType || $[28] !== props.renderListItem || $[29] !== props.textBlock || $[30] !== selected || $[31] !== t32 || $[32] !== t42 ? (t52 = /* @__PURE__ */ jsx(RenderListItem, { renderListItem: props.renderListItem, block: props.textBlock, editorElementRef: blockRef, focused, level: t32, path: t42, selected, value: props.textBlock.listItem, schemaType: legacyListItemSchemaType, children }), $[25] = children, $[26] = focused, $[27] = legacyListItemSchemaType, $[28] = props.renderListItem, $[29] = props.textBlock, $[30] = selected, $[31] = t32, $[32] = t42, $[33] = t52) : t52 = $[33], children = t52;
1619
1619
  } else
1620
1620
  console.error(`Unable to find Schema type for text block list item ${props.textBlock.listItem}`);
1621
1621
  }
1622
1622
  const t2 = props.attributes;
1623
1623
  let t3;
1624
- $[35] !== props.textBlock.style ? (t3 = props.textBlock.style ? [`pt-text-block-style-${props.textBlock.style}`] : [], $[35] = props.textBlock.style, $[36] = t3) : t3 = $[36];
1624
+ $[34] !== props.textBlock.style ? (t3 = props.textBlock.style ? [`pt-text-block-style-${props.textBlock.style}`] : [], $[34] = props.textBlock.style, $[35] = t3) : t3 = $[35];
1625
1625
  let t4;
1626
- $[37] !== props.textBlock.level || $[38] !== props.textBlock.listItem ? (t4 = props.textBlock.listItem ? ["pt-list-item", `pt-list-item-${props.textBlock.listItem}`, `pt-list-item-level-${props.textBlock.level ?? 1}`] : [], $[37] = props.textBlock.level, $[38] = props.textBlock.listItem, $[39] = t4) : t4 = $[39];
1626
+ $[36] !== props.textBlock.level || $[37] !== props.textBlock.listItem ? (t4 = props.textBlock.listItem ? ["pt-list-item", `pt-list-item-${props.textBlock.listItem}`, `pt-list-item-level-${props.textBlock.level ?? 1}`] : [], $[36] = props.textBlock.level, $[37] = props.textBlock.listItem, $[38] = t4) : t4 = $[38];
1627
1627
  let t5;
1628
- $[40] !== t3 || $[41] !== t4 ? (t5 = ["pt-block", "pt-text-block", ...t3, ...t4], $[40] = t3, $[41] = t4, $[42] = t5) : t5 = $[42];
1628
+ $[39] !== t3 || $[40] !== t4 ? (t5 = ["pt-block", "pt-text-block", ...t3, ...t4], $[39] = t3, $[40] = t4, $[41] = t5) : t5 = $[41];
1629
1629
  const t6 = t5.join(" ");
1630
1630
  let t7;
1631
- $[43] !== props.textBlock.listItem ? (t7 = props.textBlock.listItem !== void 0 ? {
1631
+ $[42] !== props.textBlock.listItem ? (t7 = props.textBlock.listItem !== void 0 ? {
1632
1632
  "data-list-item": props.textBlock.listItem
1633
- } : {}, $[43] = props.textBlock.listItem, $[44] = t7) : t7 = $[44];
1633
+ } : {}, $[42] = props.textBlock.listItem, $[43] = t7) : t7 = $[43];
1634
1634
  let t8;
1635
- $[45] !== props.textBlock.level ? (t8 = props.textBlock.level !== void 0 ? {
1635
+ $[44] !== props.textBlock.level ? (t8 = props.textBlock.level !== void 0 ? {
1636
1636
  "data-level": props.textBlock.level
1637
- } : {}, $[45] = props.textBlock.level, $[46] = t8) : t8 = $[46];
1637
+ } : {}, $[44] = props.textBlock.level, $[45] = t8) : t8 = $[45];
1638
1638
  let t9;
1639
- $[47] !== props.textBlock.style ? (t9 = props.textBlock.style !== void 0 ? {
1639
+ $[46] !== props.textBlock.style ? (t9 = props.textBlock.style !== void 0 ? {
1640
1640
  "data-style": props.textBlock.style
1641
- } : {}, $[47] = props.textBlock.style, $[48] = t9) : t9 = $[48];
1641
+ } : {}, $[46] = props.textBlock.style, $[47] = t9) : t9 = $[47];
1642
1642
  let t10;
1643
- $[49] !== listIndex ? (t10 = listIndex !== void 0 ? {
1643
+ $[48] !== listIndex ? (t10 = listIndex !== void 0 ? {
1644
1644
  "data-list-index": listIndex
1645
- } : {}, $[49] = listIndex, $[50] = t10) : t10 = $[50];
1645
+ } : {}, $[48] = listIndex, $[49] = t10) : t10 = $[49];
1646
1646
  let t11;
1647
- $[51] !== props.dropPosition ? (t11 = props.dropPosition === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null, $[51] = props.dropPosition, $[52] = t11) : t11 = $[52];
1647
+ $[50] !== props.dropPosition ? (t11 = props.dropPosition === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null, $[50] = props.dropPosition, $[51] = t11) : t11 = $[51];
1648
1648
  let t12;
1649
- $[53] !== children || $[54] !== focused || $[55] !== props.legacySchema || $[56] !== props.renderBlock || $[57] !== props.textBlock || $[58] !== selected ? (t12 = props.renderBlock ? /* @__PURE__ */ jsx(RenderBlock, { renderBlock: props.renderBlock, editorElementRef: blockRef, focused, level: props.textBlock.level, listItem: props.textBlock.listItem, path: [{
1649
+ $[52] !== children || $[53] !== focused || $[54] !== props.legacySchema || $[55] !== props.renderBlock || $[56] !== props.textBlock || $[57] !== selected ? (t12 = props.renderBlock ? /* @__PURE__ */ jsx(RenderBlock, { renderBlock: props.renderBlock, editorElementRef: blockRef, focused, level: props.textBlock.level, listItem: props.textBlock.listItem, path: [{
1650
1650
  _key: props.textBlock._key
1651
- }], selected, schemaType: props.legacySchema.block, style: props.textBlock.style, type: props.legacySchema.block, value: props.textBlock, children }) : children, $[53] = children, $[54] = focused, $[55] = props.legacySchema, $[56] = props.renderBlock, $[57] = props.textBlock, $[58] = selected, $[59] = t12) : t12 = $[59];
1651
+ }], selected, schemaType: props.legacySchema.block, style: props.textBlock.style, type: props.legacySchema.block, value: props.textBlock, children }) : children, $[52] = children, $[53] = focused, $[54] = props.legacySchema, $[55] = props.renderBlock, $[56] = props.textBlock, $[57] = selected, $[58] = t12) : t12 = $[58];
1652
1652
  let t13;
1653
- $[60] !== t12 ? (t13 = /* @__PURE__ */ jsx("div", { ref: blockRef, children: t12 }), $[60] = t12, $[61] = t13) : t13 = $[61];
1653
+ $[59] !== t12 ? (t13 = /* @__PURE__ */ jsx("div", { ref: blockRef, children: t12 }), $[59] = t12, $[60] = t13) : t13 = $[60];
1654
1654
  let t14;
1655
- $[62] !== props.dropPosition ? (t14 = props.dropPosition === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null, $[62] = props.dropPosition, $[63] = t14) : t14 = $[63];
1655
+ $[61] !== props.dropPosition ? (t14 = props.dropPosition === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null, $[61] = props.dropPosition, $[62] = t14) : t14 = $[62];
1656
1656
  let t15;
1657
- return $[64] !== props.attributes || $[65] !== props.spellCheck || $[66] !== props.textBlock._key || $[67] !== props.textBlock._type || $[68] !== t10 || $[69] !== t11 || $[70] !== t13 || $[71] !== t14 || $[72] !== t6 || $[73] !== t7 || $[74] !== t8 || $[75] !== t9 ? (t15 = /* @__PURE__ */ jsxs("div", { ...t2, className: t6, spellCheck: props.spellCheck, "data-block-key": props.textBlock._key, "data-block-name": props.textBlock._type, "data-block-type": "text", ...t7, ...t8, ...t9, ...t10, children: [
1657
+ return $[63] !== props.attributes || $[64] !== props.spellCheck || $[65] !== props.textBlock._key || $[66] !== props.textBlock._type || $[67] !== t10 || $[68] !== t11 || $[69] !== t13 || $[70] !== t14 || $[71] !== t6 || $[72] !== t7 || $[73] !== t8 || $[74] !== t9 ? (t15 = /* @__PURE__ */ jsxs("div", { ...t2, className: t6, spellCheck: props.spellCheck, "data-block-key": props.textBlock._key, "data-block-name": props.textBlock._type, "data-block-type": "text", ...t7, ...t8, ...t9, ...t10, children: [
1658
1658
  t11,
1659
1659
  t13,
1660
1660
  t14
1661
- ] }), $[64] = props.attributes, $[65] = props.spellCheck, $[66] = props.textBlock._key, $[67] = props.textBlock._type, $[68] = t10, $[69] = t11, $[70] = t13, $[71] = t14, $[72] = t6, $[73] = t7, $[74] = t8, $[75] = t9, $[76] = t15) : t15 = $[76], t15;
1661
+ ] }), $[63] = props.attributes, $[64] = props.spellCheck, $[65] = props.textBlock._key, $[66] = props.textBlock._type, $[67] = t10, $[68] = t11, $[69] = t13, $[70] = t14, $[71] = t6, $[72] = t7, $[73] = t8, $[74] = t9, $[75] = t15) : t15 = $[75], t15;
1662
1662
  }
1663
1663
  function RenderBlock({
1664
1664
  renderBlock,
@@ -3491,7 +3491,7 @@ function createBehaviorApiPlugin(editorActor) {
3491
3491
  delete: editorDelete,
3492
3492
  insertNodes,
3493
3493
  select,
3494
- setSelection
3494
+ setSelection: setSelection2
3495
3495
  } = editor;
3496
3496
  return editor.delete = (options) => {
3497
3497
  if (editor.isNormalizingNode || editor.isPerformingBehaviorOperation) {
@@ -3645,7 +3645,7 @@ function createBehaviorApiPlugin(editorActor) {
3645
3645
  });
3646
3646
  }, editor.setSelection = (partialRange) => {
3647
3647
  if (editor.isNormalizingNode || editor.isPerformingBehaviorOperation) {
3648
- setSelection(partialRange);
3648
+ setSelection2(partialRange);
3649
3649
  return;
3650
3650
  }
3651
3651
  const anchor = partialRange.anchor ? slatePointToSelectionPoint({
@@ -3666,12 +3666,12 @@ function createBehaviorApiPlugin(editorActor) {
3666
3666
  if (editor.selection) {
3667
3667
  const newAnchor = partialRange.anchor ?? editor.selection.anchor, newFocus = partialRange.focus ?? editor.selection.focus;
3668
3668
  if (Point.equals(newAnchor, editor.selection.anchor) && Point.equals(newFocus, editor.selection.focus)) {
3669
- setSelection(partialRange);
3669
+ setSelection2(partialRange);
3670
3670
  return;
3671
3671
  }
3672
3672
  }
3673
3673
  if (!anchor || !focus) {
3674
- setSelection(partialRange);
3674
+ setSelection2(partialRange);
3675
3675
  return;
3676
3676
  }
3677
3677
  editorActor.send({
@@ -6271,25 +6271,44 @@ const abstractAnnotationBehaviors = [defineBehavior({
6271
6271
  guard: ({
6272
6272
  snapshot,
6273
6273
  event
6274
- }) => isActiveDecorator(event.decorator)(snapshot),
6274
+ }) => {
6275
+ const at = event.at ?? snapshot.context.selection;
6276
+ if (!at)
6277
+ return !1;
6278
+ const adjustedSnapshot = {
6279
+ ...snapshot,
6280
+ context: {
6281
+ ...snapshot.context,
6282
+ selection: at
6283
+ }
6284
+ };
6285
+ return isActiveDecorator(event.decorator)(adjustedSnapshot);
6286
+ },
6275
6287
  actions: [({
6276
6288
  event
6277
6289
  }) => [raise({
6278
6290
  type: "decorator.remove",
6279
- decorator: event.decorator
6291
+ decorator: event.decorator,
6292
+ at: event.at
6280
6293
  })]]
6281
6294
  }), defineBehavior({
6282
6295
  on: "decorator.toggle",
6283
6296
  guard: ({
6284
6297
  snapshot,
6285
6298
  event
6286
- }) => event.at ? !isActiveDecorator(event.decorator)({
6287
- ...snapshot,
6288
- context: {
6289
- ...snapshot.context,
6290
- selection: event.at
6291
- }
6292
- }) : !isActiveDecorator(event.decorator)(snapshot),
6299
+ }) => {
6300
+ const at = event.at ?? snapshot.context.selection;
6301
+ if (!at)
6302
+ return !1;
6303
+ const adjustedSnapshot = {
6304
+ ...snapshot,
6305
+ context: {
6306
+ ...snapshot.context,
6307
+ selection: at
6308
+ }
6309
+ };
6310
+ return !isActiveDecorator(event.decorator)(adjustedSnapshot);
6311
+ },
6293
6312
  actions: [({
6294
6313
  event
6295
6314
  }) => [raise({
@@ -6316,8 +6335,17 @@ const abstractAnnotationBehaviors = [defineBehavior({
6316
6335
  }) => {
6317
6336
  if (event.direction !== "backward")
6318
6337
  return !1;
6319
- const previousBlock = getPreviousBlock(snapshot), focusTextBlock = getFocusTextBlock(snapshot);
6320
- if (!previousBlock || !focusTextBlock || !isAtTheStartOfBlock(focusTextBlock)(snapshot))
6338
+ const at = event.at ?? snapshot.context.selection;
6339
+ if (!at)
6340
+ return !1;
6341
+ const adjustedSnapshot = {
6342
+ ...snapshot,
6343
+ context: {
6344
+ ...snapshot.context,
6345
+ selection: at
6346
+ }
6347
+ }, previousBlock = getPreviousBlock(adjustedSnapshot), focusTextBlock = getFocusTextBlock(adjustedSnapshot);
6348
+ if (!previousBlock || !focusTextBlock || !isAtTheStartOfBlock(focusTextBlock)(adjustedSnapshot))
6321
6349
  return !1;
6322
6350
  const previousBlockEndPoint = getBlockEndPoint({
6323
6351
  context: snapshot.context,
@@ -6414,8 +6442,17 @@ const abstractAnnotationBehaviors = [defineBehavior({
6414
6442
  }) => {
6415
6443
  if (event.direction !== "forward")
6416
6444
  return !1;
6417
- const nextBlock = getNextBlock(snapshot), focusTextBlock = getFocusTextBlock(snapshot);
6418
- return !nextBlock || !focusTextBlock || !isAtTheEndOfBlock(focusTextBlock)(snapshot) || !isTextBlock(snapshot.context, nextBlock.node) ? !1 : {
6445
+ const at = event.at ?? snapshot.context.selection;
6446
+ if (!at)
6447
+ return !1;
6448
+ const adjustedSnapshot = {
6449
+ ...snapshot,
6450
+ context: {
6451
+ ...snapshot.context,
6452
+ selection: at
6453
+ }
6454
+ }, nextBlock = getNextBlock(adjustedSnapshot), focusTextBlock = getFocusTextBlock(adjustedSnapshot);
6455
+ return !nextBlock || !focusTextBlock || !isAtTheEndOfBlock(focusTextBlock)(adjustedSnapshot) || !isTextBlock(snapshot.context, nextBlock.node) ? !1 : {
6419
6456
  nextBlock
6420
6457
  };
6421
6458
  },
@@ -9104,7 +9141,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
9104
9141
  snapshot,
9105
9142
  event
9106
9143
  }) => {
9107
- const focusListBlock = getFocusListBlock(snapshot);
9144
+ const adjustedSnapshot = {
9145
+ ...snapshot,
9146
+ context: {
9147
+ ...snapshot.context,
9148
+ selection: event.at ?? snapshot.context.selection
9149
+ }
9150
+ }, focusListBlock = getFocusListBlock(adjustedSnapshot);
9108
9151
  if (!focusListBlock)
9109
9152
  return !1;
9110
9153
  const firstInsertedBlock = event.blocks.at(0), secondInsertedBlock = event.blocks.at(1), insertedListBlock = isListBlock(snapshot.context, firstInsertedBlock) ? firstInsertedBlock : isListBlock(snapshot.context, secondInsertedBlock) ? secondInsertedBlock : void 0;
@@ -9138,7 +9181,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
9138
9181
  snapshot,
9139
9182
  event
9140
9183
  }) => {
9141
- const focusListBlock = getFocusListBlock(snapshot);
9184
+ const adjustedSnapshot = {
9185
+ ...snapshot,
9186
+ context: {
9187
+ ...snapshot.context,
9188
+ selection: event.at ?? snapshot.context.selection
9189
+ }
9190
+ }, focusListBlock = getFocusListBlock(adjustedSnapshot);
9142
9191
  if (!focusListBlock || isEmptyTextBlock(snapshot.context, focusListBlock.node))
9143
9192
  return !1;
9144
9193
  const firstInsertedBlock = event.blocks.at(0), secondInsertedBlock = event.blocks.at(1), insertedListBlock = isListBlock(snapshot.context, firstInsertedBlock) ? firstInsertedBlock : isListBlock(snapshot.context, secondInsertedBlock) ? secondInsertedBlock : void 0;
@@ -9171,7 +9220,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
9171
9220
  }) => {
9172
9221
  if (event.placement !== "auto" || event.block._type !== snapshot.context.schema.block.name || event.block.listItem !== void 0)
9173
9222
  return !1;
9174
- const focusListBlock = getFocusListBlock(snapshot);
9223
+ const adjustedSnapshot = {
9224
+ ...snapshot,
9225
+ context: {
9226
+ ...snapshot.context,
9227
+ selection: event.at ?? snapshot.context.selection
9228
+ }
9229
+ }, focusListBlock = getFocusListBlock(adjustedSnapshot);
9175
9230
  return !focusListBlock || !isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
9176
9231
  level: focusListBlock.node.level,
9177
9232
  listItem: focusListBlock.node.listItem
@@ -9237,6 +9292,31 @@ function getEventBehaviors(behaviorIndex, type) {
9237
9292
  const global = behaviorIndex.global, namespace = type.includes(".") ? type.split(".").at(0) : type, namespaced = namespace ? behaviorIndex.namespaced.get(namespace) ?? [] : [], exact = behaviorIndex.exact.get(type) ?? [];
9238
9293
  return [...global, ...namespaced, ...exact].sort((a, b) => a.sortOrder - b.sortOrder).map((sortedBehavior) => sortedBehavior.behavior);
9239
9294
  }
9295
+ function createEditorSnapshot({
9296
+ converters,
9297
+ editor,
9298
+ keyGenerator,
9299
+ readOnly,
9300
+ schema
9301
+ }) {
9302
+ const selection = editor.selection ? slateRangeToSelection({
9303
+ schema,
9304
+ editor,
9305
+ range: editor.selection
9306
+ }) : null, context = {
9307
+ converters,
9308
+ keyGenerator,
9309
+ readOnly,
9310
+ schema,
9311
+ selection,
9312
+ value: editor.value
9313
+ };
9314
+ return {
9315
+ blockIndexMap: editor.blockIndexMap,
9316
+ context,
9317
+ decoratorState: editor.decoratorState
9318
+ };
9319
+ }
9240
9320
  const addAnnotationOperationImplementation = ({
9241
9321
  context,
9242
9322
  operation
@@ -9587,84 +9667,96 @@ const addAnnotationOperationImplementation = ({
9587
9667
  },
9588
9668
  blockIndexMap: operation.editor.blockIndexMap
9589
9669
  }) : operation.editor.selection;
9590
- if (!at)
9591
- throw new Error("Unable to add decorator without a selection");
9592
- if (Range.isExpanded(at)) {
9593
- const rangeRef = Editor.rangeRef(editor, at, {
9594
- affinity: "inward"
9595
- }), [start, end] = Range.edges(at), endAtEndOfNode = Editor.isEnd(editor, end, end.path);
9596
- Transforms.splitNodes(editor, {
9597
- at: end,
9598
- match: Text.isText,
9599
- mode: "lowest",
9600
- voids: !1,
9601
- always: !endAtEndOfNode
9602
- });
9603
- const startAtStartOfNode = Editor.isStart(editor, start, start.path);
9604
- if (Transforms.splitNodes(editor, {
9605
- at: start,
9606
- match: Text.isText,
9607
- mode: "lowest",
9608
- voids: !1,
9609
- always: !startAtStartOfNode
9610
- }), at = rangeRef.unref(), !at)
9611
- throw new Error("Unable to add decorator without a selection");
9612
- operation.at || Transforms.select(editor, at);
9613
- const splitTextNodes = Editor.nodes(editor, {
9614
- at,
9615
- match: Text.isText
9616
- });
9617
- for (const [node, path] of splitTextNodes) {
9618
- const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
9619
- Transforms.setNodes(editor, {
9620
- marks
9621
- }, {
9622
- at: path,
9670
+ if (at) {
9671
+ if (Range.isExpanded(at)) {
9672
+ const rangeRef = Editor.rangeRef(editor, at, {
9673
+ affinity: "inward"
9674
+ }), [start, end] = Range.edges(at), endAtEndOfNode = Editor.isEnd(editor, end, end.path);
9675
+ Transforms.splitNodes(editor, {
9676
+ at: end,
9623
9677
  match: Text.isText,
9624
- split: !0,
9625
- hanging: !0
9678
+ mode: "lowest",
9679
+ voids: !1,
9680
+ always: !endAtEndOfNode
9626
9681
  });
9627
- }
9628
- } else {
9629
- if (!Array.from(Editor.nodes(editor, {
9630
- at,
9631
- match: (node) => editor.isTextSpan(node)
9632
- }))?.at(0))
9633
- return;
9634
- const [block, blockPath] = Editor.node(editor, at, {
9635
- depth: 1
9636
- }), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
9637
- if (lonelyEmptySpan) {
9638
- const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
9639
- Transforms.setNodes(editor, {
9640
- marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
9641
- }, {
9642
- at: blockPath,
9643
- match: (node) => editor.isTextSpan(node)
9682
+ const startAtStartOfNode = Editor.isStart(editor, start, start.path);
9683
+ if (Transforms.splitNodes(editor, {
9684
+ at: start,
9685
+ match: Text.isText,
9686
+ mode: "lowest",
9687
+ voids: !1,
9688
+ always: !startAtStartOfNode
9689
+ }), at = rangeRef.unref(), !at)
9690
+ throw new Error("Unable to add decorator without a selection");
9691
+ operation.at || Transforms.select(editor, at);
9692
+ const splitTextNodes = Editor.nodes(editor, {
9693
+ at,
9694
+ match: Text.isText
9644
9695
  });
9645
- } else
9646
- editor.decoratorState[mark] = !0;
9647
- }
9648
- if (editor.selection) {
9649
- const selection = editor.selection;
9650
- editor.selection = {
9651
- ...selection
9652
- };
9696
+ for (const [node, path] of splitTextNodes) {
9697
+ const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
9698
+ Transforms.setNodes(editor, {
9699
+ marks
9700
+ }, {
9701
+ at: path,
9702
+ match: Text.isText,
9703
+ split: !0,
9704
+ hanging: !0
9705
+ });
9706
+ }
9707
+ } else {
9708
+ if (!Array.from(Editor.nodes(editor, {
9709
+ at,
9710
+ match: (node) => editor.isTextSpan(node)
9711
+ }))?.at(0))
9712
+ return;
9713
+ const [block, blockPath] = Editor.node(editor, at, {
9714
+ depth: 1
9715
+ }), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
9716
+ if (lonelyEmptySpan) {
9717
+ const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
9718
+ Transforms.setNodes(editor, {
9719
+ marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
9720
+ }, {
9721
+ at: blockPath,
9722
+ match: (node) => editor.isTextSpan(node)
9723
+ });
9724
+ } else
9725
+ editor.decoratorState[mark] = !0;
9726
+ }
9727
+ if (editor.selection) {
9728
+ const selection = editor.selection;
9729
+ editor.selection = {
9730
+ ...selection
9731
+ };
9732
+ }
9653
9733
  }
9654
9734
  }, decoratorRemoveOperationImplementation = ({
9735
+ context,
9655
9736
  operation
9656
9737
  }) => {
9657
- const editor = operation.editor, mark = operation.decorator, {
9658
- selection
9659
- } = editor;
9660
- if (selection) {
9661
- if (Range.isExpanded(selection))
9738
+ const editor = operation.editor, mark = operation.decorator, at = operation.at ? toSlateRange({
9739
+ context: {
9740
+ schema: context.schema,
9741
+ value: operation.editor.value,
9742
+ selection: operation.at
9743
+ },
9744
+ blockIndexMap: operation.editor.blockIndexMap
9745
+ }) : editor.selection;
9746
+ if (at) {
9747
+ if (Range.isExpanded(at)) {
9748
+ const rangeRef = Editor.rangeRef(editor, at, {
9749
+ affinity: "inward"
9750
+ });
9662
9751
  Transforms.setNodes(editor, {}, {
9752
+ at,
9663
9753
  match: Text.isText,
9664
9754
  split: !0,
9665
9755
  hanging: !0
9666
- }), editor.selection && [...Editor.nodes(editor, {
9667
- at: editor.selection,
9756
+ });
9757
+ const updatedAt = rangeRef.unref();
9758
+ updatedAt && [...Editor.nodes(editor, {
9759
+ at: updatedAt,
9668
9760
  match: Text.isText
9669
9761
  })].forEach(([node, path]) => {
9670
9762
  const block = editor.children[path[0]];
@@ -9675,8 +9767,8 @@ const addAnnotationOperationImplementation = ({
9675
9767
  at: path
9676
9768
  });
9677
9769
  });
9678
- else {
9679
- const [block, blockPath] = Editor.node(editor, selection, {
9770
+ } else {
9771
+ const [block, blockPath] = Editor.node(editor, at, {
9680
9772
  depth: 1
9681
9773
  }), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
9682
9774
  if (lonelyEmptySpan) {
@@ -9691,9 +9783,9 @@ const addAnnotationOperationImplementation = ({
9691
9783
  editor.decoratorState[mark] = !1;
9692
9784
  }
9693
9785
  if (editor.selection) {
9694
- const selection2 = editor.selection;
9786
+ const selection = editor.selection;
9695
9787
  editor.selection = {
9696
- ...selection2
9788
+ ...selection
9697
9789
  };
9698
9790
  }
9699
9791
  }
@@ -10058,199 +10150,578 @@ function insertBlock(options) {
10058
10150
  },
10059
10151
  blockIndexMap: editor.blockIndexMap
10060
10152
  }) : editor.selection;
10061
- editor.children.length === 0 && Transforms.insertNodes(editor, createPlaceholderBlock(context), {
10062
- at: [0]
10063
- });
10153
+ if (editor.children.length === 0) {
10154
+ insertNodeAt(editor, [0], block, select);
10155
+ return;
10156
+ }
10064
10157
  const start = at ? Range.start(at) : Editor.start(editor, []), end = at ? Range.end(at) : Editor.end(editor, []), [startBlock, startBlockPath] = Array.from(Editor.nodes(editor, {
10065
10158
  at: start,
10066
10159
  mode: "lowest",
10067
10160
  match: (node, path) => Element$1.isElement(node) && path.length <= start.path.length
10068
- })).at(0) ?? [void 0, void 0], [endBlock, endBlockPath] = Array.from(Editor.nodes(editor, {
10161
+ })).at(0) ?? [void 0, void 0];
10162
+ let [endBlock, endBlockPath] = Array.from(Editor.nodes(editor, {
10069
10163
  at: end,
10070
10164
  mode: "lowest",
10071
10165
  match: (node, path) => Element$1.isElement(node) && path.length <= end.path.length
10072
10166
  })).at(0) ?? [void 0, void 0];
10073
10167
  if (!startBlock || !startBlockPath || !endBlock || !endBlockPath)
10074
10168
  throw new Error("Unable to insert block without a start and end block");
10169
+ if (placement === "before") {
10170
+ insertNodeAt(editor, startBlockPath, block, select);
10171
+ return;
10172
+ }
10173
+ if (placement === "after") {
10174
+ insertNodeAt(editor, Path.next(endBlockPath), block, select);
10175
+ return;
10176
+ }
10075
10177
  if (!at) {
10076
- if (placement === "before")
10077
- Transforms.insertNodes(editor, [block], {
10078
- at: [0]
10079
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, [0])) : select === "end" && Transforms.select(editor, Editor.end(editor, [0]));
10080
- else if (placement === "after") {
10081
- const nextPath = Path.next(endBlockPath);
10082
- Transforms.insertNodes(editor, [block], {
10083
- at: nextPath
10084
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
10085
- } else {
10086
- if (isEmptyTextBlock(context, endBlock)) {
10087
- Transforms.insertNodes(editor, [block], {
10088
- at: endBlockPath,
10089
- select: !1
10090
- }), Transforms.removeNodes(editor, {
10091
- at: Path.next(endBlockPath)
10092
- }), Transforms.deselect(editor), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
10093
- return;
10178
+ if (isEmptyTextBlock(context, endBlock)) {
10179
+ replaceEmptyTextBlock(editor, endBlockPath, block, select);
10180
+ return;
10181
+ }
10182
+ if (editor.isTextBlock(block) && editor.isTextBlock(endBlock)) {
10183
+ const selectionBefore = Editor.end(editor, endBlockPath);
10184
+ insertTextBlockFragment(editor, block, selectionBefore), select === "start" ? setSelectionToPoint(editor, selectionBefore) : select === "none" && clearSelection(editor);
10185
+ return;
10186
+ }
10187
+ insertNodeAt(editor, Path.next(endBlockPath), block, select);
10188
+ return;
10189
+ }
10190
+ if (Range.isExpanded(at) && !editor.isTextBlock(block)) {
10191
+ const atBeforeDelete = Editor.rangeRef(editor, at, {
10192
+ affinity: "inward"
10193
+ }), start2 = Range.start(at), startBlock2 = Node.get(editor, [start2.path[0]]), startOfBlock = Editor.start(editor, [start2.path[0]]), isAtStartOfBlock = Element$1.isElement(startBlock2) && Point.equals(start2, startOfBlock);
10194
+ deleteExpandedRange(editor, at);
10195
+ const atAfterDelete = atBeforeDelete.unref() ?? editor.selection, atBeforeInsert = atAfterDelete ? Editor.rangeRef(editor, atAfterDelete, {
10196
+ affinity: "inward"
10197
+ }) : void 0;
10198
+ if (atAfterDelete) {
10199
+ const insertPath = isAtStartOfBlock ? [atAfterDelete.anchor.path[0]] : [atAfterDelete.anchor.path[0] + 1];
10200
+ if (editor.apply({
10201
+ type: "insert_node",
10202
+ path: insertPath,
10203
+ node: block
10204
+ }), select !== "none") {
10205
+ const point = Editor.start(editor, insertPath);
10206
+ editor.apply({
10207
+ type: "set_selection",
10208
+ properties: editor.selection,
10209
+ newProperties: {
10210
+ anchor: point,
10211
+ focus: point
10212
+ }
10213
+ });
10094
10214
  }
10095
- if (editor.isTextBlock(block) && endBlock && editor.isTextBlock(endBlock)) {
10096
- const selectionBefore = Editor.end(editor, endBlockPath);
10097
- Transforms.insertFragment(editor, [block], {
10098
- at: Editor.end(editor, endBlockPath)
10099
- }), select === "start" ? Transforms.select(editor, selectionBefore) : select === "none" && Transforms.deselect(editor);
10100
- return;
10215
+ }
10216
+ const atAfterInsert = atBeforeInsert?.unref() ?? editor.selection;
10217
+ if (select === "none" && atAfterInsert && editor.apply({
10218
+ type: "set_selection",
10219
+ properties: editor.selection,
10220
+ newProperties: atAfterInsert
10221
+ }), !editor.isTextBlock(block) && atAfterDelete) {
10222
+ const emptyBlockPath = isAtStartOfBlock ? [atAfterDelete.anchor.path[0] + 1] : [atAfterDelete.anchor.path[0]];
10223
+ try {
10224
+ const potentiallyEmptyBlock = Node.get(editor, emptyBlockPath);
10225
+ Element$1.isElement(potentiallyEmptyBlock) && isEmptyTextBlock(context, potentiallyEmptyBlock) && editor.apply({
10226
+ type: "remove_node",
10227
+ path: emptyBlockPath,
10228
+ node: potentiallyEmptyBlock
10229
+ });
10230
+ } catch {
10101
10231
  }
10102
- const nextPath = Path.next(endBlockPath);
10103
- Transforms.insertNodes(editor, [block], {
10104
- at: nextPath,
10105
- select: !1
10106
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
10107
10232
  }
10108
10233
  return;
10109
10234
  }
10110
- if (!at)
10111
- throw new Error("Unable to insert block without a selection");
10112
- if (placement === "before")
10113
- Transforms.insertNodes(editor, [block], {
10114
- at: startBlockPath,
10115
- select: !1
10116
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, startBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, startBlockPath));
10117
- else if (placement === "after") {
10118
- const nextPath = Path.next(endBlockPath);
10119
- Transforms.insertNodes(editor, [block], {
10120
- at: nextPath,
10121
- select: !1
10122
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
10123
- } else {
10124
- const endBlockEndPoint = Editor.start(editor, endBlockPath);
10125
- if (Range.isExpanded(at) && !editor.isTextBlock(block)) {
10126
- const atBeforeDelete = Editor.rangeRef(editor, at, {
10127
- affinity: "inward"
10128
- });
10129
- Transforms.delete(editor, {
10130
- at
10131
- });
10132
- const [focusBlock, focusBlockPath] = getFocusBlock({
10133
- editor
10134
- }), atAfterDelete = atBeforeDelete.unref() ?? editor.selection, atBeforeInsert = atAfterDelete ? Editor.rangeRef(editor, atAfterDelete, {
10135
- affinity: "inward"
10136
- }) : void 0;
10137
- Transforms.insertNodes(editor, [block], {
10138
- voids: !0,
10139
- at: atAfterDelete ?? void 0,
10140
- select: select !== "none"
10141
- });
10142
- const atAfterInsert = atBeforeInsert?.unref() ?? editor.selection;
10143
- select === "none" && atAfterInsert && Transforms.select(editor, atAfterInsert), isEmptyTextBlock(context, focusBlock) && Transforms.removeNodes(editor, {
10144
- at: focusBlockPath
10235
+ if (!editor.isTextBlock(block) && editor.isTextBlock(endBlock) && !Range.isExpanded(at)) {
10236
+ const selectionPoint = Range.start(at), blockPath = [selectionPoint.path[0]], blockStartPoint = Editor.start(editor, blockPath), blockEndPoint = Editor.end(editor, blockPath), isAtBlockStart = Point.equals(selectionPoint, blockStartPoint), isAtBlockEnd = Point.equals(selectionPoint, blockEndPoint);
10237
+ if (!isAtBlockStart && !isAtBlockEnd) {
10238
+ const currentBlock = Node.get(editor, blockPath), childIndex = selectionPoint.path[1], childOffset = selectionPoint.offset;
10239
+ if (childOffset > 0) {
10240
+ const textNode = Node.get(editor, selectionPoint.path);
10241
+ if (childOffset < textNode.text.length) {
10242
+ const {
10243
+ text: _2,
10244
+ ...properties
10245
+ } = textNode;
10246
+ editor.apply({
10247
+ type: "split_node",
10248
+ path: selectionPoint.path,
10249
+ position: childOffset,
10250
+ properties
10251
+ });
10252
+ }
10253
+ }
10254
+ const splitAtIndex = childOffset > 0 ? childIndex + 1 : childIndex, {
10255
+ children: _,
10256
+ ...blockProperties
10257
+ } = currentBlock;
10258
+ editor.apply({
10259
+ type: "split_node",
10260
+ path: blockPath,
10261
+ position: splitAtIndex,
10262
+ properties: blockProperties
10145
10263
  });
10264
+ const insertPath = [blockPath[0] + 1];
10265
+ if (editor.apply({
10266
+ type: "insert_node",
10267
+ path: insertPath,
10268
+ node: block
10269
+ }), select === "none") {
10270
+ const firstBlockEndPoint = Editor.end(editor, blockPath);
10271
+ editor.apply({
10272
+ type: "set_selection",
10273
+ properties: editor.selection,
10274
+ newProperties: {
10275
+ anchor: firstBlockEndPoint,
10276
+ focus: firstBlockEndPoint
10277
+ }
10278
+ });
10279
+ } else if (select === "start") {
10280
+ const point = Editor.start(editor, insertPath);
10281
+ editor.apply({
10282
+ type: "set_selection",
10283
+ properties: editor.selection,
10284
+ newProperties: {
10285
+ anchor: point,
10286
+ focus: point
10287
+ }
10288
+ });
10289
+ } else if (select === "end") {
10290
+ const point = Editor.end(editor, insertPath);
10291
+ editor.apply({
10292
+ type: "set_selection",
10293
+ properties: editor.selection,
10294
+ newProperties: {
10295
+ anchor: point,
10296
+ focus: point
10297
+ }
10298
+ });
10299
+ }
10146
10300
  return;
10147
10301
  }
10148
- if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
10149
- const selectionStartPoint = Range.start(at);
10150
- if (isEmptyTextBlock(context, endBlock)) {
10151
- Transforms.insertNodes(editor, [block], {
10152
- at: endBlockPath,
10153
- select: !1
10154
- }), Transforms.removeNodes(editor, {
10155
- at: Path.next(endBlockPath)
10156
- }), select === "start" ? Transforms.select(editor, selectionStartPoint) : select === "end" ? Transforms.select(editor, Editor.end(editor, endBlockPath)) : Transforms.select(editor, at);
10157
- return;
10158
- }
10159
- const endBlockChildKeys = endBlock.children.map((child) => child._key), endBlockMarkDefsKeys = endBlock.markDefs?.map((markDef) => markDef._key) ?? [], markDefKeyMap = /* @__PURE__ */ new Map(), adjustedMarkDefs = block.markDefs?.map((markDef) => {
10160
- if (endBlockMarkDefsKeys.includes(markDef._key)) {
10161
- const newKey = context.keyGenerator();
10162
- return markDefKeyMap.set(markDef._key, newKey), {
10163
- ...markDef,
10164
- _key: newKey
10302
+ }
10303
+ if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
10304
+ let selectionStartPoint = Range.start(at), wasCrossBlockDeletion = !1;
10305
+ if (Range.isExpanded(at)) {
10306
+ const [start2, end2] = Range.edges(at), isCrossBlock = start2.path[0] !== end2.path[0];
10307
+ if (deleteExpandedRange(editor, at), isCrossBlock) {
10308
+ wasCrossBlockDeletion = !0;
10309
+ const startBlockPath2 = [start2.path[0]], mergedBlock = Node.get(editor, startBlockPath2);
10310
+ if (editor.isTextBlock(mergedBlock)) {
10311
+ const mergePoint = {
10312
+ path: [...startBlockPath2, start2.path[1]],
10313
+ offset: start2.offset
10165
10314
  };
10315
+ setSelectionToPoint(editor, mergePoint), selectionStartPoint = mergePoint;
10166
10316
  }
10167
- return markDef;
10168
- }), adjustedChildren = block.children.map((child) => {
10169
- if (isSpan(context, child)) {
10170
- const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
10171
- if (!isEqualMarks(child.marks, marks))
10172
- return {
10173
- ...child,
10174
- _key: endBlockChildKeys.includes(child._key) ? context.keyGenerator() : child._key,
10175
- marks
10176
- };
10177
- }
10178
- return endBlockChildKeys.includes(child._key) ? {
10179
- ...child,
10180
- _key: context.keyGenerator()
10181
- } : child;
10182
- });
10183
- Transforms.setNodes(editor, {
10317
+ }
10318
+ const [newEndBlock, newEndBlockPath] = Array.from(Editor.nodes(editor, {
10319
+ at: Editor.end(editor, []),
10320
+ mode: "lowest",
10321
+ match: (node, path) => Element$1.isElement(node) && path.length === 1
10322
+ })).at(-1) ?? [void 0, void 0];
10323
+ newEndBlock && newEndBlockPath && Element$1.isElement(newEndBlock) && (endBlock = newEndBlock, endBlockPath = newEndBlockPath);
10324
+ }
10325
+ if (!editor.isTextBlock(endBlock))
10326
+ return;
10327
+ if (isEmptyTextBlock(context, endBlock)) {
10328
+ replaceEmptyTextBlock(editor, endBlockPath, block, select);
10329
+ return;
10330
+ }
10331
+ const endBlockChildKeys = endBlock.children.map((child) => child._key), endBlockMarkDefsKeys = endBlock.markDefs?.map((markDef) => markDef._key) ?? [], markDefKeyMap = /* @__PURE__ */ new Map(), adjustedMarkDefs = block.markDefs?.map((markDef) => {
10332
+ if (endBlockMarkDefsKeys.includes(markDef._key)) {
10333
+ const newKey = context.keyGenerator();
10334
+ return markDefKeyMap.set(markDef._key, newKey), {
10335
+ ...markDef,
10336
+ _key: newKey
10337
+ };
10338
+ }
10339
+ return markDef;
10340
+ }), adjustedChildren = block.children.map((child) => {
10341
+ if (isSpan(context, child)) {
10342
+ const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
10343
+ if (!isEqualMarks(child.marks, marks))
10344
+ return {
10345
+ ...child,
10346
+ _key: endBlockChildKeys.includes(child._key) ? context.keyGenerator() : child._key,
10347
+ marks
10348
+ };
10349
+ }
10350
+ return endBlockChildKeys.includes(child._key) ? {
10351
+ ...child,
10352
+ _key: context.keyGenerator()
10353
+ } : child;
10354
+ }), endBlockNode = Node.get(editor, endBlockPath);
10355
+ if (Element$1.isElement(endBlockNode) && editor.isTextBlock(endBlockNode)) {
10356
+ const properties = {
10357
+ markDefs: endBlockNode.markDefs
10358
+ }, newProperties = {
10184
10359
  markDefs: [...endBlock.markDefs ?? [], ...adjustedMarkDefs ?? []]
10185
- }, {
10186
- at: endBlockPath
10187
- });
10188
- const adjustedBlock = isEqualChildren(block.children, adjustedChildren) ? block : {
10189
- ...block,
10190
- children: adjustedChildren
10191
10360
  };
10192
- if (select === "end") {
10193
- Transforms.insertFragment(editor, [adjustedBlock], {
10194
- voids: !0
10195
- });
10196
- return;
10197
- }
10198
- Transforms.insertFragment(editor, [adjustedBlock], {
10199
- at,
10200
- voids: !0
10201
- }), select === "start" ? Transforms.select(editor, selectionStartPoint) : Point.equals(selectionStartPoint, endBlockEndPoint) || Transforms.select(editor, selectionStartPoint);
10202
- } else if (editor.isTextBlock(endBlock)) {
10203
- const endBlockStartPoint = Editor.start(editor, endBlockPath), endBlockEndPoint2 = Editor.end(editor, endBlockPath), selectionStartPoint = Range.start(at), selectionEndPoint = Range.end(at);
10204
- if (Range.isCollapsed(at) && Point.equals(selectionStartPoint, endBlockStartPoint))
10205
- Transforms.insertNodes(editor, [block], {
10206
- at: endBlockPath,
10207
- select: !1
10208
- }), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, endBlockPath)), isEmptyTextBlock(context, endBlock) && Transforms.removeNodes(editor, {
10209
- at: Path.next(endBlockPath)
10210
- });
10211
- else if (Range.isCollapsed(at) && Point.equals(selectionEndPoint, endBlockEndPoint2)) {
10212
- const nextPath = [endBlockPath[0] + 1];
10213
- Transforms.insertNodes(editor, [block], {
10214
- at: nextPath,
10215
- select: !1
10216
- }), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, nextPath));
10217
- } else if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint) && Point.equals(selectionEndPoint, endBlockEndPoint2))
10218
- Transforms.insertFragment(editor, [block], {
10219
- at
10220
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
10221
- else if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint))
10222
- Transforms.insertFragment(editor, [block], {
10223
- at
10224
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
10225
- else if (Range.isExpanded(at) && Point.equals(selectionEndPoint, endBlockEndPoint2))
10226
- Transforms.insertFragment(editor, [block], {
10227
- at
10228
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, Path.next(endBlockPath))) : select === "end" && Transforms.select(editor, Editor.end(editor, Path.next(endBlockPath)));
10361
+ editor.apply({
10362
+ type: "set_node",
10363
+ path: endBlockPath,
10364
+ properties,
10365
+ newProperties
10366
+ });
10367
+ }
10368
+ const adjustedBlock = isEqualChildren(block.children, adjustedChildren) ? block : {
10369
+ ...block,
10370
+ children: adjustedChildren
10371
+ };
10372
+ if (select === "end") {
10373
+ const insertAt = editor.selection ? Range.end(editor.selection) : Editor.end(editor, endBlockPath);
10374
+ insertTextBlockFragment(editor, adjustedBlock, insertAt);
10375
+ return;
10376
+ }
10377
+ if (insertTextBlockFragment(editor, adjustedBlock, selectionStartPoint), select === "start")
10378
+ setSelectionToPoint(editor, selectionStartPoint);
10379
+ else if (select === "none")
10380
+ if (wasCrossBlockDeletion)
10381
+ setSelectionToPoint(editor, selectionStartPoint);
10229
10382
  else {
10230
- const [focusChild] = getFocusChild({
10231
- editor
10232
- });
10233
- if (focusChild && editor.isTextSpan(focusChild))
10234
- Transforms.splitNodes(editor, {
10235
- at
10236
- }), Transforms.insertFragment(editor, [block], {
10237
- at
10238
- }), select === "start" || select === "end" ? Transforms.select(editor, [endBlockPath[0] + 1]) : Transforms.select(editor, at);
10239
- else {
10240
- const nextPath = [endBlockPath[0] + 1];
10241
- Transforms.insertNodes(editor, [block], {
10242
- at: nextPath,
10243
- select: !1
10244
- }), Transforms.select(editor, at), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
10383
+ const endBlockStartPoint = Editor.start(editor, endBlockPath);
10384
+ Point.equals(selectionStartPoint, endBlockStartPoint) || setSelectionToPoint(editor, selectionStartPoint);
10385
+ }
10386
+ } else {
10387
+ if (!editor.isTextBlock(endBlock)) {
10388
+ insertNodeAt(editor, [endBlockPath[0] + 1], block, select);
10389
+ return;
10390
+ }
10391
+ const endBlockStartPoint = Editor.start(editor, endBlockPath), endBlockEndPoint = Editor.end(editor, endBlockPath), selectionStartPoint = Range.start(at), selectionEndPoint = Range.end(at);
10392
+ if (Range.isCollapsed(at) && Point.equals(selectionStartPoint, endBlockStartPoint)) {
10393
+ editor.apply({
10394
+ type: "insert_node",
10395
+ path: endBlockPath,
10396
+ node: block
10397
+ }), select !== "none" && setSelection(editor, endBlockPath, "start"), isEmptyTextBlock(context, endBlock) && removeNodeAt(editor, Path.next(endBlockPath));
10398
+ return;
10399
+ }
10400
+ if (Range.isCollapsed(at) && Point.equals(selectionEndPoint, endBlockEndPoint)) {
10401
+ const nextPath = [endBlockPath[0] + 1];
10402
+ editor.apply({
10403
+ type: "insert_node",
10404
+ path: nextPath,
10405
+ node: block
10406
+ }), select !== "none" && setSelection(editor, nextPath, "start");
10407
+ return;
10408
+ }
10409
+ if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint) && Point.equals(selectionEndPoint, endBlockEndPoint)) {
10410
+ editor.apply({
10411
+ type: "insert_node",
10412
+ path: endBlockPath,
10413
+ node: block
10414
+ }), removeNodeAt(editor, Path.next(endBlockPath)), select !== "none" && setSelection(editor, endBlockPath, select);
10415
+ return;
10416
+ }
10417
+ if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint)) {
10418
+ const [, end2] = Range.edges(at), endNode = Node.get(editor, end2.path);
10419
+ end2.offset > 0 && editor.apply({
10420
+ type: "remove_text",
10421
+ path: end2.path,
10422
+ offset: 0,
10423
+ text: endNode.text.slice(0, end2.offset)
10424
+ });
10425
+ for (let i = end2.path[1] - 1; i >= 0; i--)
10426
+ removeNodeAt(editor, [...endBlockPath, i]);
10427
+ insertTextBlockFragment(editor, block, Editor.start(editor, endBlockPath)), select !== "none" && setSelection(editor, endBlockPath, select);
10428
+ return;
10429
+ }
10430
+ if (Range.isExpanded(at) && Point.equals(selectionEndPoint, endBlockEndPoint)) {
10431
+ const [start2] = Range.edges(at), blockNode = Node.get(editor, endBlockPath);
10432
+ for (let i = blockNode.children.length - 1; i > start2.path[1]; i--)
10433
+ removeNodeAt(editor, [...endBlockPath, i]);
10434
+ const startNode = Node.get(editor, start2.path);
10435
+ start2.offset < startNode.text.length && editor.apply({
10436
+ type: "remove_text",
10437
+ path: start2.path,
10438
+ offset: start2.offset,
10439
+ text: startNode.text.slice(start2.offset)
10440
+ }), insertTextBlockFragment(editor, block, start2), select !== "none" && setSelection(editor, Path.next(endBlockPath), select);
10441
+ return;
10442
+ }
10443
+ const [focusChild] = getFocusChild({
10444
+ editor
10445
+ });
10446
+ if (focusChild && editor.isTextSpan(focusChild)) {
10447
+ const startPoint = Range.start(at);
10448
+ if (editor.isTextBlock(block)) {
10449
+ const nodeToSplit = Node.get(editor, startPoint.path);
10450
+ if (Text.isText(nodeToSplit)) {
10451
+ const {
10452
+ text: _,
10453
+ ...properties
10454
+ } = nodeToSplit;
10455
+ editor.apply({
10456
+ type: "split_node",
10457
+ path: startPoint.path,
10458
+ position: startPoint.offset,
10459
+ properties
10460
+ });
10461
+ }
10462
+ insertTextBlockFragment(editor, block, startPoint), select === "none" ? setSelectionToRange(editor, at) : setSelection(editor, [endBlockPath[0] + 1], "start");
10463
+ } else {
10464
+ let currentPath = startPoint.path, currentOffset = startPoint.offset;
10465
+ const cursorPositionRef = Editor.pointRef(editor, startPoint, {
10466
+ affinity: "backward"
10467
+ }), blockPath = [currentPath[0]], firstBlockPathRef = Editor.pathRef(editor, blockPath), textNode = Node.get(editor, currentPath);
10468
+ if (Text.isText(textNode) && currentOffset > 0 && currentOffset < textNode.text.length) {
10469
+ const {
10470
+ text: _,
10471
+ ...properties
10472
+ } = textNode;
10473
+ editor.apply({
10474
+ type: "split_node",
10475
+ path: currentPath,
10476
+ position: currentOffset,
10477
+ properties
10478
+ }), currentPath = Path.next(currentPath), currentOffset = 0;
10479
+ }
10480
+ const splitAtIndex = currentOffset > 0 ? currentPath[1] + 1 : currentPath[1], blockToSplit = Node.get(editor, blockPath);
10481
+ if (splitAtIndex < blockToSplit.children.length && Element$1.isElement(blockToSplit)) {
10482
+ const {
10483
+ children: _,
10484
+ ...blockProperties
10485
+ } = blockToSplit;
10486
+ editor.apply({
10487
+ type: "split_node",
10488
+ path: blockPath,
10489
+ position: splitAtIndex,
10490
+ properties: blockProperties
10491
+ });
10492
+ }
10493
+ const currentFirstBlockPath = firstBlockPathRef.unref(), insertPath = currentFirstBlockPath ? [currentFirstBlockPath[0] + 1] : [blockPath[0] + 1];
10494
+ if (editor.apply({
10495
+ type: "insert_node",
10496
+ path: insertPath,
10497
+ node: block
10498
+ }), select === "start" || select === "end") {
10499
+ const point = Editor.start(editor, insertPath);
10500
+ editor.apply({
10501
+ type: "set_selection",
10502
+ properties: editor.selection,
10503
+ newProperties: {
10504
+ anchor: point,
10505
+ focus: point
10506
+ }
10507
+ });
10508
+ } else {
10509
+ const point = cursorPositionRef.unref();
10510
+ point && editor.apply({
10511
+ type: "set_selection",
10512
+ properties: editor.selection,
10513
+ newProperties: {
10514
+ anchor: point,
10515
+ focus: point
10516
+ }
10517
+ });
10245
10518
  }
10246
10519
  }
10247
10520
  } else {
10248
10521
  const nextPath = [endBlockPath[0] + 1];
10249
- Transforms.insertNodes(editor, [block], {
10250
- select: !1,
10251
- at: nextPath
10252
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
10522
+ editor.apply({
10523
+ type: "insert_node",
10524
+ path: nextPath,
10525
+ node: block
10526
+ }), select === "none" ? setSelectionToRange(editor, at) : setSelection(editor, nextPath, select);
10527
+ }
10528
+ }
10529
+ }
10530
+ function setSelection(editor, path, position) {
10531
+ const point = position === "start" ? Editor.start(editor, path) : Editor.end(editor, path);
10532
+ editor.apply({
10533
+ type: "set_selection",
10534
+ properties: editor.selection,
10535
+ newProperties: {
10536
+ anchor: point,
10537
+ focus: point
10538
+ }
10539
+ });
10540
+ }
10541
+ function clearSelection(editor) {
10542
+ editor.selection && editor.apply({
10543
+ type: "set_selection",
10544
+ properties: editor.selection,
10545
+ newProperties: null
10546
+ });
10547
+ }
10548
+ function setSelectionToPoint(editor, point) {
10549
+ editor.apply({
10550
+ type: "set_selection",
10551
+ properties: editor.selection,
10552
+ newProperties: {
10553
+ anchor: point,
10554
+ focus: point
10555
+ }
10556
+ });
10557
+ }
10558
+ function setSelectionToRange(editor, range) {
10559
+ editor.apply({
10560
+ type: "set_selection",
10561
+ properties: editor.selection,
10562
+ newProperties: range
10563
+ });
10564
+ }
10565
+ function insertNodeAt(editor, path, node, select) {
10566
+ editor.apply({
10567
+ type: "insert_node",
10568
+ path,
10569
+ node
10570
+ }), select !== "none" && setSelection(editor, path, select);
10571
+ }
10572
+ function removeNodeAt(editor, path) {
10573
+ const node = Node.get(editor, path);
10574
+ editor.apply({
10575
+ type: "remove_node",
10576
+ path,
10577
+ node
10578
+ });
10579
+ }
10580
+ function replaceEmptyTextBlock(editor, blockPath, newBlock, select) {
10581
+ const hadSelection = editor.selection !== null;
10582
+ if (editor.apply({
10583
+ type: "insert_node",
10584
+ path: blockPath,
10585
+ node: newBlock
10586
+ }), removeNodeAt(editor, Path.next(blockPath)), select === "none" && !hadSelection)
10587
+ return;
10588
+ const point = select === "end" ? Editor.end(editor, blockPath) : Editor.start(editor, blockPath);
10589
+ clearSelection(editor), editor.apply({
10590
+ type: "set_selection",
10591
+ properties: null,
10592
+ newProperties: {
10593
+ anchor: point,
10594
+ focus: point
10253
10595
  }
10596
+ });
10597
+ }
10598
+ function deleteSameBlockRange(editor, start, end) {
10599
+ const blockPath = [start.path[0]];
10600
+ if (Path.equals(start.path, end.path)) {
10601
+ const textToRemove = Node.get(editor, start.path).text.slice(start.offset, end.offset);
10602
+ editor.apply({
10603
+ type: "remove_text",
10604
+ path: start.path,
10605
+ offset: start.offset,
10606
+ text: textToRemove
10607
+ });
10608
+ return;
10609
+ }
10610
+ const startNode = Node.get(editor, start.path);
10611
+ if (start.offset < startNode.text.length) {
10612
+ const textToRemove = startNode.text.slice(start.offset);
10613
+ editor.apply({
10614
+ type: "remove_text",
10615
+ path: start.path,
10616
+ offset: start.offset,
10617
+ text: textToRemove
10618
+ });
10619
+ }
10620
+ for (let i = end.path[1] - 1; i > start.path[1]; i--)
10621
+ removeNodeAt(editor, [...blockPath, i]);
10622
+ const newEndPath = [...blockPath, start.path[1] + 1], endNode = Node.get(editor, newEndPath);
10623
+ if (end.offset > 0) {
10624
+ const textToRemove = endNode.text.slice(0, end.offset);
10625
+ editor.apply({
10626
+ type: "remove_text",
10627
+ path: newEndPath,
10628
+ offset: 0,
10629
+ text: textToRemove
10630
+ });
10631
+ }
10632
+ const startNodeAfter = Node.get(editor, start.path), endNodeAfter = Node.get(editor, newEndPath);
10633
+ if (Text.isText(startNodeAfter) && Text.isText(endNodeAfter)) {
10634
+ const {
10635
+ text: _,
10636
+ ...properties
10637
+ } = endNodeAfter;
10638
+ editor.apply({
10639
+ type: "merge_node",
10640
+ path: newEndPath,
10641
+ position: startNodeAfter.text.length,
10642
+ properties
10643
+ });
10644
+ }
10645
+ }
10646
+ function deleteCrossBlockRange(editor, start, end) {
10647
+ const startBlockPath = [start.path[0]];
10648
+ if (start.path.length > 1) {
10649
+ const startNode = Node.get(editor, start.path);
10650
+ if (start.offset < startNode.text.length) {
10651
+ const textToRemove = startNode.text.slice(start.offset);
10652
+ editor.apply({
10653
+ type: "remove_text",
10654
+ path: start.path,
10655
+ offset: start.offset,
10656
+ text: textToRemove
10657
+ });
10658
+ }
10659
+ const startBlock2 = Node.get(editor, startBlockPath);
10660
+ for (let i = startBlock2.children.length - 1; i > start.path[1]; i--)
10661
+ removeNodeAt(editor, [...startBlockPath, i]);
10662
+ }
10663
+ for (let i = end.path[0] - 1; i > start.path[0]; i--)
10664
+ removeNodeAt(editor, [i]);
10665
+ const adjustedEndBlockPath = [start.path[0] + 1];
10666
+ if (end.path.length > 1) {
10667
+ for (let i = 0; i < end.path[1]; i++)
10668
+ removeNodeAt(editor, [...adjustedEndBlockPath, 0]);
10669
+ const endNodePath = [...adjustedEndBlockPath, 0], endNode = Node.get(editor, endNodePath);
10670
+ if (end.offset > 0) {
10671
+ const textToRemove = endNode.text.slice(0, end.offset);
10672
+ editor.apply({
10673
+ type: "remove_text",
10674
+ path: endNodePath,
10675
+ offset: 0,
10676
+ text: textToRemove
10677
+ });
10678
+ }
10679
+ }
10680
+ const startBlock = Node.get(editor, startBlockPath), endBlock = Node.get(editor, adjustedEndBlockPath);
10681
+ if (editor.isTextBlock(startBlock) && editor.isTextBlock(endBlock)) {
10682
+ const {
10683
+ children: _,
10684
+ ...properties
10685
+ } = endBlock;
10686
+ editor.apply({
10687
+ type: "merge_node",
10688
+ path: adjustedEndBlockPath,
10689
+ position: startBlock.children.length,
10690
+ properties
10691
+ });
10692
+ }
10693
+ }
10694
+ function deleteExpandedRange(editor, range) {
10695
+ const [start, end] = Range.edges(range);
10696
+ start.path[0] === end.path[0] ? deleteSameBlockRange(editor, start, end) : deleteCrossBlockRange(editor, start, end);
10697
+ }
10698
+ function insertTextBlockFragment(editor, block, at) {
10699
+ if (!Element$1.isElement(block) || !editor.isTextBlock(block))
10700
+ return;
10701
+ if (at.offset > 0) {
10702
+ const textNode = Node.get(editor, at.path);
10703
+ if (Text.isText(textNode)) {
10704
+ const {
10705
+ text: _,
10706
+ ...properties
10707
+ } = textNode;
10708
+ editor.apply({
10709
+ type: "split_node",
10710
+ path: at.path,
10711
+ position: at.offset,
10712
+ properties
10713
+ });
10714
+ }
10715
+ }
10716
+ const parentPath = Path.parent(at.path);
10717
+ let insertIndex = at.path[at.path.length - 1] + (at.offset > 0 ? 1 : 0);
10718
+ for (const child of block.children) {
10719
+ const childPath = [...parentPath, insertIndex];
10720
+ editor.apply({
10721
+ type: "insert_node",
10722
+ path: childPath,
10723
+ node: child
10724
+ }), insertIndex++;
10254
10725
  }
10255
10726
  }
10256
10727
  const insertChildOperationImplementation = ({
@@ -10585,9 +11056,10 @@ function performEvent({
10585
11056
  forwardFromBehaviors,
10586
11057
  event,
10587
11058
  editor,
11059
+ converters,
10588
11060
  keyGenerator,
11061
+ readOnly,
10589
11062
  schema,
10590
- getSnapshot,
10591
11063
  nativeEvent,
10592
11064
  sendBack
10593
11065
  }) {
@@ -10605,10 +11077,16 @@ function performEvent({
10605
11077
  editor
10606
11078
  }
10607
11079
  });
10608
- }), editor.onChange();
11080
+ }), mode === "send" && editor.onChange();
10609
11081
  return;
10610
11082
  }
10611
- const guardSnapshot = getSnapshot();
11083
+ const guardSnapshot = createEditorSnapshot({
11084
+ converters,
11085
+ editor,
11086
+ keyGenerator,
11087
+ readOnly,
11088
+ schema
11089
+ });
10612
11090
  let nativeEventPrevented = !1, defaultBehaviorOverwritten = !1, eventBehaviorIndex = -1;
10613
11091
  for (const eventBehavior of eventBehaviors) {
10614
11092
  eventBehaviorIndex++;
@@ -10628,7 +11106,13 @@ function performEvent({
10628
11106
  let actionSetIndex = -1;
10629
11107
  for (const actionSet of eventBehavior.actions) {
10630
11108
  actionSetIndex++;
10631
- const actionsSnapshot = getSnapshot();
11109
+ const actionsSnapshot = createEditorSnapshot({
11110
+ converters,
11111
+ editor,
11112
+ keyGenerator,
11113
+ readOnly,
11114
+ schema
11115
+ });
10632
11116
  let actions = [];
10633
11117
  try {
10634
11118
  actions = actionSet({
@@ -10666,9 +11150,10 @@ function performEvent({
10666
11150
  forwardFromBehaviors: remainingBehaviors,
10667
11151
  event: action.event,
10668
11152
  editor,
11153
+ converters,
10669
11154
  keyGenerator,
11155
+ readOnly,
10670
11156
  schema,
10671
- getSnapshot,
10672
11157
  nativeEvent,
10673
11158
  sendBack
10674
11159
  });
@@ -10681,9 +11166,10 @@ function performEvent({
10681
11166
  abstractBehaviorIndex,
10682
11167
  event: action.event,
10683
11168
  editor,
11169
+ converters,
10684
11170
  keyGenerator,
11171
+ readOnly,
10685
11172
  schema,
10686
- getSnapshot,
10687
11173
  nativeEvent,
10688
11174
  sendBack
10689
11175
  });
@@ -10695,9 +11181,10 @@ function performEvent({
10695
11181
  abstractBehaviorIndex,
10696
11182
  event: action.event,
10697
11183
  editor,
11184
+ converters,
10698
11185
  keyGenerator,
11186
+ readOnly,
10699
11187
  schema,
10700
- getSnapshot,
10701
11188
  nativeEvent: void 0,
10702
11189
  sendBack
10703
11190
  });
@@ -10717,7 +11204,7 @@ function performEvent({
10717
11204
  editor
10718
11205
  }
10719
11206
  });
10720
- }), editor.onChange()) : nativeEventPrevented && nativeEvent?.preventDefault();
11207
+ }), mode === "send" && editor.onChange()) : nativeEventPrevented && (nativeEvent?.preventDefault(), mode === "send" && editor.onChange());
10721
11208
  }
10722
11209
  function sortByPriority(items) {
10723
11210
  if (items.length === 0)
@@ -10762,31 +11249,6 @@ function sortByPriority(items) {
10762
11249
  result.includes(item) || result.push(item);
10763
11250
  return [...result, ...itemsWithoutPriority];
10764
11251
  }
10765
- function createEditorSnapshot({
10766
- converters,
10767
- editor,
10768
- keyGenerator,
10769
- readOnly,
10770
- schema
10771
- }) {
10772
- const selection = editor.selection ? slateRangeToSelection({
10773
- schema,
10774
- editor,
10775
- range: editor.selection
10776
- }) : null, context = {
10777
- converters,
10778
- keyGenerator,
10779
- readOnly,
10780
- schema,
10781
- selection,
10782
- value: editor.value
10783
- };
10784
- return {
10785
- blockIndexMap: editor.blockIndexMap,
10786
- context,
10787
- decoratorState: editor.decoratorState
10788
- };
10789
- }
10790
11252
  function rerouteExternalBehaviorEvent({
10791
11253
  event,
10792
11254
  slateEditor
@@ -10937,16 +11399,11 @@ const editorMachine = setup({
10937
11399
  abstractBehaviorIndex: context.abstractBehaviorIndex,
10938
11400
  event: event.behaviorEvent,
10939
11401
  editor: event.editor,
11402
+ converters: [...context.converters],
10940
11403
  keyGenerator: context.keyGenerator,
10941
11404
  schema: context.schema,
10942
- getSnapshot: () => createEditorSnapshot({
10943
- converters: [...context.converters],
10944
- editor: event.editor,
10945
- keyGenerator: context.keyGenerator,
10946
- readOnly: self.getSnapshot().matches({
10947
- "edit mode": "read only"
10948
- }),
10949
- schema: context.schema
11405
+ readOnly: self.getSnapshot().matches({
11406
+ "edit mode": "read only"
10950
11407
  }),
10951
11408
  nativeEvent: event.nativeEvent,
10952
11409
  sendBack: (eventSentBack) => {
@@ -13260,12 +13717,12 @@ const usePortableTextEditorSelection = () => {
13260
13717
  const $ = c(5), editorActor = useContext(EditorActorContext);
13261
13718
  let t0;
13262
13719
  $[0] !== editorActor ? (t0 = editorActor.getSnapshot(), $[0] = editorActor, $[1] = t0) : t0 = $[1];
13263
- const [selection, setSelection] = useState(t0.context.selection);
13720
+ const [selection, setSelection2] = useState(t0.context.selection);
13264
13721
  let t1, t2;
13265
13722
  return $[2] !== editorActor ? (t1 = () => {
13266
13723
  const subscription = editorActor.on("selection", (event) => {
13267
13724
  startTransition(() => {
13268
- setSelection(event.selection);
13725
+ setSelection2(event.selection);
13269
13726
  });
13270
13727
  });
13271
13728
  return () => {