@portabletext/editor 2.19.3 → 2.21.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
@@ -13,7 +13,7 @@ import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelec
13
13
  import isEqual from "lodash/isEqual.js";
14
14
  import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
15
15
  import { defineSchema } from "@portabletext/schema";
16
- import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getActiveDecorators, getTrimmedSelection, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
16
+ import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, isSelectingEntireBlocks, getActiveDecorators, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
17
17
  import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getSelectedValue, getSelectionStartPoint as getSelectionStartPoint$1, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.get-selection-text.js";
18
18
  import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
19
19
  import uniq from "lodash/uniq.js";
@@ -25,10 +25,9 @@ import { Schema } from "@sanity/schema";
25
25
  import flatten from "lodash/flatten.js";
26
26
  import omit from "lodash/omit.js";
27
27
  import { applyAll, unset, insert, set, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
28
- import { blockOffsetsToSelection } from "./_chunks-es/util.child-selection-point-to-block-offset.js";
29
- import { selectionPointToBlockOffset, sliceTextBlock } from "./_chunks-es/util.slice-text-block.js";
30
28
  import { createDraft, finishDraft } from "immer";
31
29
  import { createKeyboardShortcut, code, underline, italic, bold, undo, redo } from "@portabletext/keyboard-shortcuts";
30
+ import { sliceTextBlock } from "./_chunks-es/util.slice-text-block.js";
32
31
  import isPlainObject from "lodash/isPlainObject.js";
33
32
  import { Subject } from "rxjs";
34
33
  function EditorEventListener(props) {
@@ -191,28 +190,6 @@ function getFocusSpan({
191
190
  }
192
191
  return [void 0, void 0];
193
192
  }
194
- function getSelectionStartBlock({
195
- editor
196
- }) {
197
- if (!editor.selection)
198
- return [void 0, void 0];
199
- const selectionStartPoint = Range.start(editor.selection);
200
- return getPointBlock({
201
- editor,
202
- point: selectionStartPoint
203
- });
204
- }
205
- function getSelectionEndBlock({
206
- editor
207
- }) {
208
- if (!editor.selection)
209
- return [void 0, void 0];
210
- const selectionEndPoint = Range.end(editor.selection);
211
- return getPointBlock({
212
- editor,
213
- point: selectionEndPoint
214
- });
215
- }
216
193
  function getPointBlock({
217
194
  editor,
218
195
  point
@@ -751,7 +728,7 @@ function getDragSelection({
751
728
  });
752
729
  const selectedBlocks = getSelectedBlocks(snapshot);
753
730
  if (snapshot.context.selection && isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
754
- const selectionStartBlock = getSelectionStartBlock$1(snapshot), selectionEndBlock = getSelectionEndBlock$1(snapshot);
731
+ const selectionStartBlock = getSelectionStartBlock(snapshot), selectionEndBlock = getSelectionEndBlock(snapshot);
755
732
  if (!selectionStartBlock || !selectionEndBlock)
756
733
  return dragSelection;
757
734
  const selectionStartPoint = getBlockStartPoint({
@@ -4494,97 +4471,42 @@ const addAnnotationOperationImplementation = ({
4494
4471
  context,
4495
4472
  operation
4496
4473
  }) => {
4497
- const editor = operation.editor, mark = operation.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = operation.at?.anchor ? blockOffsetToSpanSelectionPoint({
4498
- context: {
4499
- ...context,
4500
- value
4501
- },
4502
- blockOffset: operation.at.anchor,
4503
- direction: "backward"
4504
- }) : void 0, manualFocus = operation.at?.focus ? blockOffsetToSpanSelectionPoint({
4505
- context: {
4506
- ...context,
4507
- value
4508
- },
4509
- blockOffset: operation.at.focus,
4510
- direction: "forward"
4511
- }) : void 0, manualSelection = manualAnchor && manualFocus ? {
4512
- anchor: manualAnchor,
4513
- focus: manualFocus
4514
- } : void 0, selection = manualSelection ? toSlateRange({
4474
+ const editor = operation.editor, mark = operation.decorator;
4475
+ let at = operation.at ? toSlateRange({
4515
4476
  context: {
4516
4477
  schema: context.schema,
4517
4478
  value: operation.editor.value,
4518
- selection: manualSelection
4479
+ selection: operation.at
4519
4480
  },
4520
4481
  blockIndexMap: operation.editor.blockIndexMap
4521
- }) ?? editor.selection : editor.selection;
4522
- if (!selection)
4523
- return;
4524
- const editorSelection = slateRangeToSelection({
4525
- schema: context.schema,
4526
- editor,
4527
- range: selection
4528
- }), anchorOffset = editorSelection ? selectionPointToBlockOffset({
4529
- context: {
4530
- ...context,
4531
- value
4532
- },
4533
- selectionPoint: editorSelection.anchor
4534
- }) : void 0, focusOffset = editorSelection ? selectionPointToBlockOffset({
4535
- context: {
4536
- ...context,
4537
- value
4538
- },
4539
- selectionPoint: editorSelection.focus
4540
- }) : void 0;
4541
- if (!anchorOffset || !focusOffset)
4542
- throw new Error("Unable to find anchor or focus offset");
4543
- if (Range.isExpanded(selection)) {
4544
- Transforms.setNodes(editor, {}, {
4545
- at: selection,
4482
+ }) : operation.editor.selection;
4483
+ if (!at)
4484
+ throw new Error("Unable to add decorator without a selection");
4485
+ if (Range.isExpanded(at)) {
4486
+ const rangeRef = Editor.rangeRef(editor, at, {
4487
+ affinity: "inward"
4488
+ }), [start, end] = Range.edges(at), endAtEndOfNode = Editor.isEnd(editor, end, end.path);
4489
+ Transforms.splitNodes(editor, {
4490
+ at: end,
4546
4491
  match: Text.isText,
4547
- split: !0,
4548
- hanging: !0
4549
- });
4550
- const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = blockOffsetsToSelection({
4551
- context: {
4552
- ...context,
4553
- value: newValue
4554
- },
4555
- offsets: {
4556
- anchor: anchorOffset,
4557
- focus: focusOffset
4558
- },
4559
- backward: editorSelection?.backward
4560
- }), trimmedSelection = getTrimmedSelection({
4561
- blockIndexMap: editor.blockIndexMap,
4562
- context: {
4563
- converters: [],
4564
- keyGenerator: context.keyGenerator,
4565
- readOnly: !1,
4566
- schema: context.schema,
4567
- selection: newSelection,
4568
- value: newValue
4569
- },
4570
- decoratorState: editor.decoratorState
4492
+ mode: "lowest",
4493
+ voids: !1,
4494
+ always: !endAtEndOfNode
4571
4495
  });
4572
- if (!trimmedSelection)
4573
- throw new Error("Unable to find trimmed selection");
4574
- const newRange = toSlateRange({
4575
- context: {
4576
- schema: context.schema,
4577
- value: operation.editor.value,
4578
- selection: trimmedSelection
4579
- },
4580
- blockIndexMap: operation.editor.blockIndexMap
4496
+ const startAtStartOfNode = Editor.isStart(editor, start, start.path);
4497
+ if (Transforms.splitNodes(editor, {
4498
+ at: start,
4499
+ match: Text.isText,
4500
+ mode: "lowest",
4501
+ voids: !1,
4502
+ always: !startAtStartOfNode
4503
+ }), at = rangeRef.unref(), !at)
4504
+ throw new Error("Unable to add decorator without a selection");
4505
+ operation.at || Transforms.select(editor, at);
4506
+ const splitTextNodes = Editor.nodes(editor, {
4507
+ at,
4508
+ match: Text.isText
4581
4509
  });
4582
- if (!newRange)
4583
- throw new Error("Unable to find new selection");
4584
- const splitTextNodes = Range.isRange(newRange) ? [...Editor.nodes(editor, {
4585
- at: newRange,
4586
- match: (node) => Text.isText(node)
4587
- })] : [];
4588
4510
  for (const [node, path] of splitTextNodes) {
4589
4511
  const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
4590
4512
  Transforms.setNodes(editor, {
@@ -4598,11 +4520,11 @@ const addAnnotationOperationImplementation = ({
4598
4520
  }
4599
4521
  } else {
4600
4522
  if (!Array.from(Editor.nodes(editor, {
4601
- at: selection,
4523
+ at,
4602
4524
  match: (node) => editor.isTextSpan(node)
4603
4525
  }))?.at(0))
4604
4526
  return;
4605
- const [block, blockPath] = Editor.node(editor, selection, {
4527
+ const [block, blockPath] = Editor.node(editor, at, {
4606
4528
  depth: 1
4607
4529
  }), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
4608
4530
  if (lonelyEmptySpan) {
@@ -4617,9 +4539,9 @@ const addAnnotationOperationImplementation = ({
4617
4539
  editor.decoratorState[mark] = !0;
4618
4540
  }
4619
4541
  if (editor.selection) {
4620
- const selection2 = editor.selection;
4542
+ const selection = editor.selection;
4621
4543
  editor.selection = {
4622
- ...selection2
4544
+ ...selection
4623
4545
  };
4624
4546
  }
4625
4547
  }, deleteOperationImplementation = ({
@@ -4732,112 +4654,125 @@ const insertBlockOperationImplementation = ({
4732
4654
  });
4733
4655
  if (!parsedBlock)
4734
4656
  throw new Error(`Failed to parse block ${JSON.stringify(operation.block)}`);
4735
- const fragment = toSlateValue([parsedBlock], {
4657
+ const block = toSlateBlock(parsedBlock, {
4736
4658
  schemaTypes: context.schema
4737
- })[0];
4738
- if (!fragment)
4739
- throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
4659
+ });
4740
4660
  insertBlock({
4741
4661
  context,
4742
- block: fragment,
4662
+ block,
4743
4663
  placement: operation.placement,
4744
4664
  select: operation.select ?? "start",
4665
+ at: operation.at,
4745
4666
  editor: operation.editor
4746
4667
  });
4747
4668
  };
4748
- function insertBlock({
4749
- context,
4750
- block,
4751
- placement,
4752
- select,
4753
- editor
4754
- }) {
4755
- const [startBlock, startBlockPath] = getSelectionStartBlock({
4756
- editor
4757
- }), [endBlock, endBlockPath] = getSelectionEndBlock({
4669
+ function insertBlock(options) {
4670
+ const {
4671
+ context,
4672
+ block,
4673
+ placement,
4674
+ select,
4758
4675
  editor
4759
- });
4760
- if (!editor.selection || !startBlock || !startBlockPath || !endBlock || !endBlockPath) {
4761
- select !== "none" && DOMEditor.focus(editor);
4762
- const [lastBlock, lastBlockPath] = getLastBlock({
4763
- editor
4764
- });
4676
+ } = options, at = options.at ? toSlateRange({
4677
+ context: {
4678
+ schema: context.schema,
4679
+ value: editor.value,
4680
+ selection: options.at
4681
+ },
4682
+ blockIndexMap: editor.blockIndexMap
4683
+ }) : editor.selection, start = at ? Range.start(at) : Editor.start(editor, []), end = at ? Range.end(at) : Editor.end(editor, []), [startBlock, startBlockPath] = Array.from(Editor.nodes(editor, {
4684
+ at: start,
4685
+ mode: "lowest",
4686
+ match: (node, path) => Element$1.isElement(node) && path.length <= start.path.length
4687
+ })).at(0) ?? [void 0, void 0], [endBlock, endBlockPath] = Array.from(Editor.nodes(editor, {
4688
+ at: end,
4689
+ mode: "lowest",
4690
+ match: (node, path) => Element$1.isElement(node) && path.length <= end.path.length
4691
+ })).at(0) ?? [void 0, void 0];
4692
+ if (!startBlock || !startBlockPath || !endBlock || !endBlockPath)
4693
+ throw new Error("Unable to insert block without a start and end block");
4694
+ if (!editor.selection && select !== "none" && DOMEditor.focus(editor), !at) {
4765
4695
  if (placement === "before")
4766
4696
  Transforms.insertNodes(editor, [block], {
4767
4697
  at: [0]
4768
4698
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, [0])) : select === "end" && Transforms.select(editor, Editor.end(editor, [0]));
4769
4699
  else if (placement === "after") {
4770
- const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
4700
+ const nextPath = Path.next(endBlockPath);
4771
4701
  Transforms.insertNodes(editor, [block], {
4772
4702
  at: nextPath
4773
4703
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4774
4704
  } else {
4775
- if (lastBlock && isEqualToEmptyEditor([lastBlock], context.schema)) {
4705
+ if (endBlock && isEqualToEmptyEditor([endBlock], context.schema)) {
4776
4706
  Transforms.removeNodes(editor, {
4777
- at: lastBlockPath
4707
+ at: endBlockPath
4778
4708
  }), Transforms.insertNodes(editor, [block], {
4779
- at: lastBlockPath,
4709
+ at: endBlockPath,
4780
4710
  select: !1
4781
- }), Transforms.deselect(editor), select === "start" ? Transforms.select(editor, Editor.start(editor, lastBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, lastBlockPath));
4711
+ }), Transforms.deselect(editor), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
4782
4712
  return;
4783
4713
  }
4784
- if (editor.isTextBlock(block) && lastBlock && editor.isTextBlock(lastBlock)) {
4785
- const selectionBefore = Editor.end(editor, lastBlockPath);
4714
+ if (editor.isTextBlock(block) && endBlock && editor.isTextBlock(endBlock)) {
4715
+ const selectionBefore = Editor.end(editor, endBlockPath);
4786
4716
  Transforms.insertFragment(editor, [block], {
4787
- at: Editor.end(editor, lastBlockPath)
4717
+ at: Editor.end(editor, endBlockPath)
4788
4718
  }), select === "start" ? Transforms.select(editor, selectionBefore) : select === "none" && Transforms.deselect(editor);
4789
4719
  return;
4790
4720
  }
4791
- const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
4721
+ const nextPath = Path.next(endBlockPath);
4792
4722
  Transforms.insertNodes(editor, [block], {
4793
4723
  at: nextPath,
4794
4724
  select: !1
4795
4725
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4796
4726
  }
4797
- } else if (placement === "before") {
4798
- const currentSelection = editor.selection, selectionStartPoint = Range.start(currentSelection);
4727
+ return;
4728
+ }
4729
+ if (!at)
4730
+ throw new Error("Unable to insert block without a selection");
4731
+ if (placement === "before")
4799
4732
  Transforms.insertNodes(editor, [block], {
4800
- at: [selectionStartPoint.path[0]],
4733
+ at: startBlockPath,
4801
4734
  select: !1
4802
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, [selectionStartPoint.path[0]])) : select === "end" && Transforms.select(editor, Editor.end(editor, [selectionStartPoint.path[0]]));
4803
- } else if (placement === "after") {
4804
- const currentSelection = editor.selection, nextPath = [Range.end(currentSelection).path[0] + 1];
4735
+ }), select === "start" ? Transforms.select(editor, Editor.start(editor, startBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, startBlockPath));
4736
+ else if (placement === "after") {
4737
+ const nextPath = Path.next(endBlockPath);
4805
4738
  Transforms.insertNodes(editor, [block], {
4806
4739
  at: nextPath,
4807
4740
  select: !1
4808
4741
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4809
4742
  } else {
4810
- const currentSelection = editor.selection, endBlockEndPoint = Editor.start(editor, endBlockPath);
4811
- if (Range.isExpanded(currentSelection) && !editor.isTextBlock(block)) {
4743
+ const endBlockEndPoint = Editor.start(editor, endBlockPath);
4744
+ if (Range.isExpanded(at) && !editor.isTextBlock(block)) {
4745
+ const atBeforeDelete = Editor.rangeRef(editor, at, {
4746
+ affinity: "inward"
4747
+ });
4812
4748
  Transforms.delete(editor, {
4813
- at: currentSelection
4749
+ at
4814
4750
  });
4815
- const newSelection = editor.selection, [focusBlock, focusBlockPath] = getFocusBlock({
4751
+ const [focusBlock, focusBlockPath] = getFocusBlock({
4816
4752
  editor
4817
- });
4753
+ }), atAfterDelete = atBeforeDelete.unref() ?? editor.selection, atBeforeInsert = atAfterDelete ? Editor.rangeRef(editor, atAfterDelete, {
4754
+ affinity: "inward"
4755
+ }) : void 0;
4818
4756
  Transforms.insertNodes(editor, [block], {
4819
- voids: !0
4757
+ voids: !0,
4758
+ at: atAfterDelete ?? void 0,
4759
+ select: select !== "none"
4820
4760
  });
4821
- const adjustedSelection = newSelection.anchor.offset === 0 ? Range.transform(newSelection, {
4822
- type: "insert_node",
4823
- node: block,
4824
- path: [newSelection.anchor.path[0]]
4825
- }) : newSelection;
4826
- select === "none" && adjustedSelection && Transforms.select(editor, adjustedSelection), focusBlock && isEqualToEmptyEditor([focusBlock], context.schema) && Transforms.removeNodes(editor, {
4761
+ const atAfterInsert = atBeforeInsert?.unref() ?? editor.selection;
4762
+ select === "none" && atAfterInsert && Transforms.select(editor, atAfterInsert), focusBlock && isEqualToEmptyEditor([focusBlock], context.schema) && Transforms.removeNodes(editor, {
4827
4763
  at: focusBlockPath
4828
4764
  });
4829
4765
  return;
4830
4766
  }
4831
4767
  if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
4832
- const selectionStartPoint = Range.start(currentSelection);
4768
+ const selectionStartPoint = Range.start(at);
4833
4769
  if (isEqualToEmptyEditor([endBlock], context.schema)) {
4834
- const currentSelection2 = editor.selection;
4835
4770
  Transforms.insertNodes(editor, [block], {
4836
4771
  at: endBlockPath,
4837
4772
  select: !1
4838
4773
  }), Transforms.removeNodes(editor, {
4839
4774
  at: Path.next(endBlockPath)
4840
- }), select === "start" ? Transforms.select(editor, selectionStartPoint) : select === "end" ? Transforms.select(editor, Editor.end(editor, endBlockPath)) : Transforms.select(editor, currentSelection2);
4775
+ }), select === "start" ? Transforms.select(editor, selectionStartPoint) : select === "end" ? Transforms.select(editor, Editor.end(editor, endBlockPath)) : Transforms.select(editor, at);
4841
4776
  return;
4842
4777
  }
4843
4778
  const endBlockChildKeys = endBlock.children.map((child) => child._key), endBlockMarkDefsKeys = endBlock.markDefs?.map((markDef) => markDef._key) ?? [], markDefKeyMap = /* @__PURE__ */ new Map(), adjustedMarkDefs = block.markDefs?.map((markDef) => {
@@ -4880,52 +4815,52 @@ function insertBlock({
4880
4815
  return;
4881
4816
  }
4882
4817
  Transforms.insertFragment(editor, [adjustedBlock], {
4883
- at: currentSelection,
4818
+ at,
4884
4819
  voids: !0
4885
4820
  }), select === "start" ? Transforms.select(editor, selectionStartPoint) : Point.equals(selectionStartPoint, endBlockEndPoint) || Transforms.select(editor, selectionStartPoint);
4886
4821
  } else if (editor.isTextBlock(endBlock)) {
4887
- const endBlockStartPoint = Editor.start(editor, endBlockPath), endBlockEndPoint2 = Editor.end(editor, endBlockPath), selectionStartPoint = Range.start(currentSelection), selectionEndPoint = Range.end(currentSelection);
4888
- if (Range.isCollapsed(currentSelection) && Point.equals(selectionStartPoint, endBlockStartPoint))
4822
+ const endBlockStartPoint = Editor.start(editor, endBlockPath), endBlockEndPoint2 = Editor.end(editor, endBlockPath), selectionStartPoint = Range.start(at), selectionEndPoint = Range.end(at);
4823
+ if (Range.isCollapsed(at) && Point.equals(selectionStartPoint, endBlockStartPoint))
4889
4824
  Transforms.insertNodes(editor, [block], {
4890
4825
  at: endBlockPath,
4891
4826
  select: !1
4892
4827
  }), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, endBlockPath)), isEmptyTextBlock(context, endBlock) && Transforms.removeNodes(editor, {
4893
4828
  at: Path.next(endBlockPath)
4894
4829
  });
4895
- else if (Range.isCollapsed(currentSelection) && Point.equals(selectionEndPoint, endBlockEndPoint2)) {
4830
+ else if (Range.isCollapsed(at) && Point.equals(selectionEndPoint, endBlockEndPoint2)) {
4896
4831
  const nextPath = [endBlockPath[0] + 1];
4897
4832
  Transforms.insertNodes(editor, [block], {
4898
4833
  at: nextPath,
4899
4834
  select: !1
4900
4835
  }), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, nextPath));
4901
- } else if (Range.isExpanded(currentSelection) && Point.equals(selectionStartPoint, endBlockStartPoint) && Point.equals(selectionEndPoint, endBlockEndPoint2))
4836
+ } else if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint) && Point.equals(selectionEndPoint, endBlockEndPoint2))
4902
4837
  Transforms.insertFragment(editor, [block], {
4903
- at: currentSelection
4838
+ at
4904
4839
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
4905
- else if (Range.isExpanded(currentSelection) && Point.equals(selectionStartPoint, endBlockStartPoint))
4840
+ else if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint))
4906
4841
  Transforms.insertFragment(editor, [block], {
4907
- at: currentSelection
4842
+ at
4908
4843
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
4909
- else if (Range.isExpanded(currentSelection) && Point.equals(selectionEndPoint, endBlockEndPoint2))
4844
+ else if (Range.isExpanded(at) && Point.equals(selectionEndPoint, endBlockEndPoint2))
4910
4845
  Transforms.insertFragment(editor, [block], {
4911
- at: currentSelection
4846
+ at
4912
4847
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, Path.next(endBlockPath))) : select === "end" && Transforms.select(editor, Editor.end(editor, Path.next(endBlockPath)));
4913
4848
  else {
4914
- const currentSelection2 = editor.selection, [focusChild] = getFocusChild({
4849
+ const [focusChild] = getFocusChild({
4915
4850
  editor
4916
4851
  });
4917
4852
  if (focusChild && editor.isTextSpan(focusChild))
4918
4853
  Transforms.splitNodes(editor, {
4919
- at: currentSelection2
4854
+ at
4920
4855
  }), Transforms.insertFragment(editor, [block], {
4921
- at: currentSelection2
4922
- }), select === "start" || select === "end" ? Transforms.select(editor, [endBlockPath[0] + 1]) : Transforms.select(editor, currentSelection2);
4856
+ at
4857
+ }), select === "start" || select === "end" ? Transforms.select(editor, [endBlockPath[0] + 1]) : Transforms.select(editor, at);
4923
4858
  else {
4924
4859
  const nextPath = [endBlockPath[0] + 1];
4925
4860
  Transforms.insertNodes(editor, [block], {
4926
4861
  at: nextPath,
4927
4862
  select: !1
4928
- }), Transforms.select(editor, currentSelection2), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4863
+ }), Transforms.select(editor, at), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4929
4864
  }
4930
4865
  }
4931
4866
  } else {
@@ -6907,7 +6842,7 @@ function getSelectionRect(snapshot) {
6907
6842
  }
6908
6843
  }
6909
6844
  function getStartBlockElement(slateEditor, snapshot) {
6910
- const startBlock = getSelectionStartBlock$1(snapshot);
6845
+ const startBlock = getSelectionStartBlock(snapshot);
6911
6846
  if (!startBlock)
6912
6847
  return null;
6913
6848
  const startBlockNode = getBlockNodes(slateEditor, {
@@ -6929,7 +6864,7 @@ function getStartBlockElement(slateEditor, snapshot) {
6929
6864
  return startBlockNode && startBlockNode instanceof Element ? startBlockNode : null;
6930
6865
  }
6931
6866
  function getEndBlockElement(slateEditor, snapshot) {
6932
- const endBlock = getSelectionEndBlock$1(snapshot);
6867
+ const endBlock = getSelectionEndBlock(snapshot);
6933
6868
  if (!endBlock)
6934
6869
  return null;
6935
6870
  const endBlockNode = getBlockNodes(slateEditor, {
@@ -7764,7 +7699,7 @@ const coreDndBehaviors = [
7764
7699
  }) => {
7765
7700
  if (!snapshot.context.selection || !isSelectionExpanded(snapshot))
7766
7701
  return !1;
7767
- const selectedBlocks = getSelectedBlocks(snapshot), selectionStartBlock = getSelectionStartBlock$1(snapshot), selectionEndBlock = getSelectionEndBlock$1(snapshot);
7702
+ const selectedBlocks = getSelectedBlocks(snapshot), selectionStartBlock = getSelectionStartBlock(snapshot), selectionEndBlock = getSelectionEndBlock(snapshot);
7768
7703
  if (!selectionStartBlock || !selectionEndBlock)
7769
7704
  return !1;
7770
7705
  const startBlockStartPoint = getBlockStartPoint({
@@ -8317,19 +8252,13 @@ const abstractAnnotationBehaviors = [defineBehavior({
8317
8252
  guard: ({
8318
8253
  snapshot,
8319
8254
  event
8320
- }) => {
8321
- const manualSelection = event.at ? blockOffsetsToSelection({
8322
- context: snapshot.context,
8323
- offsets: event.at
8324
- }) : null;
8325
- return manualSelection ? !isActiveDecorator(event.decorator)({
8326
- ...snapshot,
8327
- context: {
8328
- ...snapshot.context,
8329
- selection: manualSelection
8330
- }
8331
- }) : !isActiveDecorator(event.decorator)(snapshot);
8332
- },
8255
+ }) => event.at ? !isActiveDecorator(event.decorator)({
8256
+ ...snapshot,
8257
+ context: {
8258
+ ...snapshot.context,
8259
+ selection: event.at
8260
+ }
8261
+ }) : !isActiveDecorator(event.decorator)(snapshot),
8333
8262
  actions: [({
8334
8263
  event
8335
8264
  }) => [raise({
@@ -8542,33 +8471,11 @@ const abstractAnnotationBehaviors = [defineBehavior({
8542
8471
  })]]
8543
8472
  }), defineBehavior({
8544
8473
  on: "delete.text",
8545
- guard: ({
8546
- snapshot,
8474
+ actions: [({
8547
8475
  event
8548
- }) => {
8549
- const selection = blockOffsetsToSelection({
8550
- context: snapshot.context,
8551
- offsets: event.at
8552
- });
8553
- if (!selection)
8554
- return !1;
8555
- const trimmedSelection = getTrimmedSelection({
8556
- ...snapshot,
8557
- context: {
8558
- ...snapshot.context,
8559
- value: snapshot.context.value,
8560
- selection
8561
- }
8562
- });
8563
- return trimmedSelection ? {
8564
- selection: trimmedSelection
8565
- } : !1;
8566
- },
8567
- actions: [(_, {
8568
- selection
8569
8476
  }) => [raise({
8570
- type: "delete",
8571
- at: selection
8477
+ ...event,
8478
+ type: "delete"
8572
8479
  })]]
8573
8480
  })], abstractDeserializeBehaviors = [
8574
8481
  defineBehavior({
@@ -9681,7 +9588,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
9681
9588
  const startPoint = getSelectionStartPoint(selection), endPoint = getSelectionEndPoint(selection);
9682
9589
  if (!startPoint || !endPoint)
9683
9590
  return !1;
9684
- const startBlock = getSelectionStartBlock$1(snapshot), endBlock = getSelectionEndBlock$1(snapshot);
9591
+ const startBlock = getSelectionStartBlock(snapshot), endBlock = getSelectionEndBlock(snapshot);
9685
9592
  if (!startBlock || !endBlock)
9686
9593
  return !1;
9687
9594
  const startBlockStartPoint = getBlockStartPoint({