@portabletext/editor 2.20.0 → 2.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1750,6 +1750,7 @@ declare const editorMachine: xstate229.StateMachine<{
1750
1750
  block: BlockWithOptionalKey;
1751
1751
  placement: InsertPlacement;
1752
1752
  select?: "start" | "end" | "none";
1753
+ at?: NonNullable<EditorSelection>;
1753
1754
  } | {
1754
1755
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "insert.child">;
1755
1756
  child: ChildWithOptionalKey;
@@ -3269,6 +3270,7 @@ type SyntheticBehaviorEvent = {
3269
3270
  block: BlockWithOptionalKey;
3270
3271
  placement: InsertPlacement;
3271
3272
  select?: 'start' | 'end' | 'none';
3273
+ at?: NonNullable<EditorSelection>;
3272
3274
  } | {
3273
3275
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.child'>;
3274
3276
  child: ChildWithOptionalKey;
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, 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";
@@ -190,28 +190,6 @@ function getFocusSpan({
190
190
  }
191
191
  return [void 0, void 0];
192
192
  }
193
- function getSelectionStartBlock({
194
- editor
195
- }) {
196
- if (!editor.selection)
197
- return [void 0, void 0];
198
- const selectionStartPoint = Range.start(editor.selection);
199
- return getPointBlock({
200
- editor,
201
- point: selectionStartPoint
202
- });
203
- }
204
- function getSelectionEndBlock({
205
- editor
206
- }) {
207
- if (!editor.selection)
208
- return [void 0, void 0];
209
- const selectionEndPoint = Range.end(editor.selection);
210
- return getPointBlock({
211
- editor,
212
- point: selectionEndPoint
213
- });
214
- }
215
193
  function getPointBlock({
216
194
  editor,
217
195
  point
@@ -750,7 +728,7 @@ function getDragSelection({
750
728
  });
751
729
  const selectedBlocks = getSelectedBlocks(snapshot);
752
730
  if (snapshot.context.selection && isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
753
- const selectionStartBlock = getSelectionStartBlock$1(snapshot), selectionEndBlock = getSelectionEndBlock$1(snapshot);
731
+ const selectionStartBlock = getSelectionStartBlock(snapshot), selectionEndBlock = getSelectionEndBlock(snapshot);
754
732
  if (!selectionStartBlock || !selectionEndBlock)
755
733
  return dragSelection;
756
734
  const selectionStartPoint = getBlockStartPoint({
@@ -4676,112 +4654,125 @@ const insertBlockOperationImplementation = ({
4676
4654
  });
4677
4655
  if (!parsedBlock)
4678
4656
  throw new Error(`Failed to parse block ${JSON.stringify(operation.block)}`);
4679
- const fragment = toSlateValue([parsedBlock], {
4657
+ const block = toSlateBlock(parsedBlock, {
4680
4658
  schemaTypes: context.schema
4681
- })[0];
4682
- if (!fragment)
4683
- throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
4659
+ });
4684
4660
  insertBlock({
4685
4661
  context,
4686
- block: fragment,
4662
+ block,
4687
4663
  placement: operation.placement,
4688
4664
  select: operation.select ?? "start",
4665
+ at: operation.at,
4689
4666
  editor: operation.editor
4690
4667
  });
4691
4668
  };
4692
- function insertBlock({
4693
- context,
4694
- block,
4695
- placement,
4696
- select,
4697
- editor
4698
- }) {
4699
- const [startBlock, startBlockPath] = getSelectionStartBlock({
4700
- editor
4701
- }), [endBlock, endBlockPath] = getSelectionEndBlock({
4669
+ function insertBlock(options) {
4670
+ const {
4671
+ context,
4672
+ block,
4673
+ placement,
4674
+ select,
4702
4675
  editor
4703
- });
4704
- if (!editor.selection || !startBlock || !startBlockPath || !endBlock || !endBlockPath) {
4705
- select !== "none" && DOMEditor.focus(editor);
4706
- const [lastBlock, lastBlockPath] = getLastBlock({
4707
- editor
4708
- });
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) {
4709
4695
  if (placement === "before")
4710
4696
  Transforms.insertNodes(editor, [block], {
4711
4697
  at: [0]
4712
4698
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, [0])) : select === "end" && Transforms.select(editor, Editor.end(editor, [0]));
4713
4699
  else if (placement === "after") {
4714
- const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
4700
+ const nextPath = Path.next(endBlockPath);
4715
4701
  Transforms.insertNodes(editor, [block], {
4716
4702
  at: nextPath
4717
4703
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4718
4704
  } else {
4719
- if (lastBlock && isEqualToEmptyEditor([lastBlock], context.schema)) {
4720
- Transforms.removeNodes(editor, {
4721
- at: lastBlockPath
4722
- }), Transforms.insertNodes(editor, [block], {
4723
- at: lastBlockPath,
4705
+ if (endBlock && isEqualToEmptyEditor([endBlock], context.schema)) {
4706
+ Transforms.insertNodes(editor, [block], {
4707
+ at: endBlockPath,
4724
4708
  select: !1
4725
- }), Transforms.deselect(editor), select === "start" ? Transforms.select(editor, Editor.start(editor, lastBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, lastBlockPath));
4709
+ }), Transforms.removeNodes(editor, {
4710
+ at: Path.next(endBlockPath)
4711
+ }), Transforms.deselect(editor), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
4726
4712
  return;
4727
4713
  }
4728
- if (editor.isTextBlock(block) && lastBlock && editor.isTextBlock(lastBlock)) {
4729
- const selectionBefore = Editor.end(editor, lastBlockPath);
4714
+ if (editor.isTextBlock(block) && endBlock && editor.isTextBlock(endBlock)) {
4715
+ const selectionBefore = Editor.end(editor, endBlockPath);
4730
4716
  Transforms.insertFragment(editor, [block], {
4731
- at: Editor.end(editor, lastBlockPath)
4717
+ at: Editor.end(editor, endBlockPath)
4732
4718
  }), select === "start" ? Transforms.select(editor, selectionBefore) : select === "none" && Transforms.deselect(editor);
4733
4719
  return;
4734
4720
  }
4735
- const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
4721
+ const nextPath = Path.next(endBlockPath);
4736
4722
  Transforms.insertNodes(editor, [block], {
4737
4723
  at: nextPath,
4738
4724
  select: !1
4739
4725
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4740
4726
  }
4741
- } else if (placement === "before") {
4742
- 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")
4743
4732
  Transforms.insertNodes(editor, [block], {
4744
- at: [selectionStartPoint.path[0]],
4733
+ at: startBlockPath,
4745
4734
  select: !1
4746
- }), select === "start" ? Transforms.select(editor, Editor.start(editor, [selectionStartPoint.path[0]])) : select === "end" && Transforms.select(editor, Editor.end(editor, [selectionStartPoint.path[0]]));
4747
- } else if (placement === "after") {
4748
- 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);
4749
4738
  Transforms.insertNodes(editor, [block], {
4750
4739
  at: nextPath,
4751
4740
  select: !1
4752
4741
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4753
4742
  } else {
4754
- const currentSelection = editor.selection, endBlockEndPoint = Editor.start(editor, endBlockPath);
4755
- 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
+ });
4756
4748
  Transforms.delete(editor, {
4757
- at: currentSelection
4749
+ at
4758
4750
  });
4759
- const newSelection = editor.selection, [focusBlock, focusBlockPath] = getFocusBlock({
4751
+ const [focusBlock, focusBlockPath] = getFocusBlock({
4760
4752
  editor
4761
- });
4753
+ }), atAfterDelete = atBeforeDelete.unref() ?? editor.selection, atBeforeInsert = atAfterDelete ? Editor.rangeRef(editor, atAfterDelete, {
4754
+ affinity: "inward"
4755
+ }) : void 0;
4762
4756
  Transforms.insertNodes(editor, [block], {
4763
- voids: !0
4757
+ voids: !0,
4758
+ at: atAfterDelete ?? void 0,
4759
+ select: select !== "none"
4764
4760
  });
4765
- const adjustedSelection = newSelection.anchor.offset === 0 ? Range.transform(newSelection, {
4766
- type: "insert_node",
4767
- node: block,
4768
- path: [newSelection.anchor.path[0]]
4769
- }) : newSelection;
4770
- 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, {
4771
4763
  at: focusBlockPath
4772
4764
  });
4773
4765
  return;
4774
4766
  }
4775
4767
  if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
4776
- const selectionStartPoint = Range.start(currentSelection);
4768
+ const selectionStartPoint = Range.start(at);
4777
4769
  if (isEqualToEmptyEditor([endBlock], context.schema)) {
4778
- const currentSelection2 = editor.selection;
4779
4770
  Transforms.insertNodes(editor, [block], {
4780
4771
  at: endBlockPath,
4781
4772
  select: !1
4782
4773
  }), Transforms.removeNodes(editor, {
4783
4774
  at: Path.next(endBlockPath)
4784
- }), 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);
4785
4776
  return;
4786
4777
  }
4787
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) => {
@@ -4824,52 +4815,52 @@ function insertBlock({
4824
4815
  return;
4825
4816
  }
4826
4817
  Transforms.insertFragment(editor, [adjustedBlock], {
4827
- at: currentSelection,
4818
+ at,
4828
4819
  voids: !0
4829
4820
  }), select === "start" ? Transforms.select(editor, selectionStartPoint) : Point.equals(selectionStartPoint, endBlockEndPoint) || Transforms.select(editor, selectionStartPoint);
4830
4821
  } else if (editor.isTextBlock(endBlock)) {
4831
- const endBlockStartPoint = Editor.start(editor, endBlockPath), endBlockEndPoint2 = Editor.end(editor, endBlockPath), selectionStartPoint = Range.start(currentSelection), selectionEndPoint = Range.end(currentSelection);
4832
- 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))
4833
4824
  Transforms.insertNodes(editor, [block], {
4834
4825
  at: endBlockPath,
4835
4826
  select: !1
4836
4827
  }), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, endBlockPath)), isEmptyTextBlock(context, endBlock) && Transforms.removeNodes(editor, {
4837
4828
  at: Path.next(endBlockPath)
4838
4829
  });
4839
- else if (Range.isCollapsed(currentSelection) && Point.equals(selectionEndPoint, endBlockEndPoint2)) {
4830
+ else if (Range.isCollapsed(at) && Point.equals(selectionEndPoint, endBlockEndPoint2)) {
4840
4831
  const nextPath = [endBlockPath[0] + 1];
4841
4832
  Transforms.insertNodes(editor, [block], {
4842
4833
  at: nextPath,
4843
4834
  select: !1
4844
4835
  }), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, nextPath));
4845
- } 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))
4846
4837
  Transforms.insertFragment(editor, [block], {
4847
- at: currentSelection
4838
+ at
4848
4839
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
4849
- else if (Range.isExpanded(currentSelection) && Point.equals(selectionStartPoint, endBlockStartPoint))
4840
+ else if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint))
4850
4841
  Transforms.insertFragment(editor, [block], {
4851
- at: currentSelection
4842
+ at
4852
4843
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
4853
- else if (Range.isExpanded(currentSelection) && Point.equals(selectionEndPoint, endBlockEndPoint2))
4844
+ else if (Range.isExpanded(at) && Point.equals(selectionEndPoint, endBlockEndPoint2))
4854
4845
  Transforms.insertFragment(editor, [block], {
4855
- at: currentSelection
4846
+ at
4856
4847
  }), select === "start" ? Transforms.select(editor, Editor.start(editor, Path.next(endBlockPath))) : select === "end" && Transforms.select(editor, Editor.end(editor, Path.next(endBlockPath)));
4857
4848
  else {
4858
- const currentSelection2 = editor.selection, [focusChild] = getFocusChild({
4849
+ const [focusChild] = getFocusChild({
4859
4850
  editor
4860
4851
  });
4861
4852
  if (focusChild && editor.isTextSpan(focusChild))
4862
4853
  Transforms.splitNodes(editor, {
4863
- at: currentSelection2
4854
+ at
4864
4855
  }), Transforms.insertFragment(editor, [block], {
4865
- at: currentSelection2
4866
- }), 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);
4867
4858
  else {
4868
4859
  const nextPath = [endBlockPath[0] + 1];
4869
4860
  Transforms.insertNodes(editor, [block], {
4870
4861
  at: nextPath,
4871
4862
  select: !1
4872
- }), 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));
4873
4864
  }
4874
4865
  }
4875
4866
  } else {
@@ -6387,7 +6378,7 @@ function createWithUtils({
6387
6378
  editorActor
6388
6379
  }) {
6389
6380
  return function(editor) {
6390
- return editor.pteCreateTextBlock = (options) => toSlateValue([{
6381
+ return editor.pteCreateTextBlock = (options) => toSlateBlock({
6391
6382
  _type: editorActor.getSnapshot().context.schema.block.name,
6392
6383
  _key: editorActor.getSnapshot().context.keyGenerator(),
6393
6384
  style: editorActor.getSnapshot().context.schema.styles[0].name || "normal",
@@ -6406,9 +6397,9 @@ function createWithUtils({
6406
6397
  name
6407
6398
  }) => name === decorator))
6408
6399
  }]
6409
- }], {
6400
+ }, {
6410
6401
  schemaTypes: editorActor.getSnapshot().context.schema
6411
- })[0], editor;
6402
+ }), editor;
6412
6403
  };
6413
6404
  }
6414
6405
  function pluginUpdateSelection({
@@ -6851,7 +6842,7 @@ function getSelectionRect(snapshot) {
6851
6842
  }
6852
6843
  }
6853
6844
  function getStartBlockElement(slateEditor, snapshot) {
6854
- const startBlock = getSelectionStartBlock$1(snapshot);
6845
+ const startBlock = getSelectionStartBlock(snapshot);
6855
6846
  if (!startBlock)
6856
6847
  return null;
6857
6848
  const startBlockNode = getBlockNodes(slateEditor, {
@@ -6873,7 +6864,7 @@ function getStartBlockElement(slateEditor, snapshot) {
6873
6864
  return startBlockNode && startBlockNode instanceof Element ? startBlockNode : null;
6874
6865
  }
6875
6866
  function getEndBlockElement(slateEditor, snapshot) {
6876
- const endBlock = getSelectionEndBlock$1(snapshot);
6867
+ const endBlock = getSelectionEndBlock(snapshot);
6877
6868
  if (!endBlock)
6878
6869
  return null;
6879
6870
  const endBlockNode = getBlockNodes(slateEditor, {
@@ -7708,7 +7699,7 @@ const coreDndBehaviors = [
7708
7699
  }) => {
7709
7700
  if (!snapshot.context.selection || !isSelectionExpanded(snapshot))
7710
7701
  return !1;
7711
- const selectedBlocks = getSelectedBlocks(snapshot), selectionStartBlock = getSelectionStartBlock$1(snapshot), selectionEndBlock = getSelectionEndBlock$1(snapshot);
7702
+ const selectedBlocks = getSelectedBlocks(snapshot), selectionStartBlock = getSelectionStartBlock(snapshot), selectionEndBlock = getSelectionEndBlock(snapshot);
7712
7703
  if (!selectionStartBlock || !selectionEndBlock)
7713
7704
  return !1;
7714
7705
  const startBlockStartPoint = getBlockStartPoint({
@@ -9597,7 +9588,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
9597
9588
  const startPoint = getSelectionStartPoint(selection), endPoint = getSelectionEndPoint(selection);
9598
9589
  if (!startPoint || !endPoint)
9599
9590
  return !1;
9600
- const startBlock = getSelectionStartBlock$1(snapshot), endBlock = getSelectionEndBlock$1(snapshot);
9591
+ const startBlock = getSelectionStartBlock(snapshot), endBlock = getSelectionEndBlock(snapshot);
9601
9592
  if (!startBlock || !endBlock)
9602
9593
  return !1;
9603
9594
  const startBlockStartPoint = getBlockStartPoint({
@@ -10922,56 +10913,21 @@ function createEditableAPI(editor, editorActor) {
10922
10913
  return fromSlateValue([block], types.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0].children[editor.selection.focus.path[1]];
10923
10914
  }
10924
10915
  },
10925
- insertChild: (type, value) => {
10926
- if (type.name !== types.span.name)
10927
- return editorActor.send({
10928
- type: "behavior event",
10929
- behaviorEvent: {
10930
- type: "insert.inline object",
10931
- inlineObject: {
10932
- name: type.name,
10933
- value
10934
- }
10935
- },
10936
- editor
10937
- }), editor.selection ? slateRangeToSelection({
10938
- schema: editorActor.getSnapshot().context.schema,
10939
- editor,
10940
- range: editor.selection
10941
- })?.focus.path ?? [] : [];
10942
- if (!editor.selection)
10943
- throw new Error("The editor has no selection");
10944
- const [focusBlock] = Array.from(Editor.nodes(editor, {
10945
- at: editor.selection.focus.path.slice(0, 1),
10946
- match: (n) => n._type === types.block.name
10947
- }))[0] || [void 0];
10948
- if (!focusBlock)
10949
- throw new Error("No focused text block");
10950
- if (type.name !== types.span.name && !types.inlineObjects.some((t) => t.name === type.name))
10951
- throw new Error("This type cannot be inserted as a child to a text block");
10952
- const child = toSlateValue([{
10953
- _key: editorActor.getSnapshot().context.keyGenerator(),
10954
- _type: types.block.name,
10955
- children: [{
10956
- _key: editorActor.getSnapshot().context.keyGenerator(),
10916
+ insertChild: (type, value) => (editorActor.send({
10917
+ type: "behavior event",
10918
+ behaviorEvent: {
10919
+ type: "insert.child",
10920
+ child: {
10957
10921
  _type: type.name,
10958
10922
  ...value || {}
10959
- }]
10960
- }], {
10961
- schemaTypes: editorActor.getSnapshot().context.schema
10962
- })[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode2 = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
10963
- return isSpanNode2 && focusNode._type !== types.span.name && (debug$3("Inserting span child next to inline object child, moving selection + 1"), editor.move({
10964
- distance: 1,
10965
- unit: "character"
10966
- })), Transforms.insertNodes(editor, child, {
10967
- select: !0,
10968
- at: editor.selection
10969
- }), editor.onChange(), editor.selection ? slateRangeToSelection({
10970
- schema: editorActor.getSnapshot().context.schema,
10971
- editor,
10972
- range: editor.selection
10973
- })?.focus.path ?? [] : [];
10974
- },
10923
+ }
10924
+ },
10925
+ editor
10926
+ }), editor.selection ? slateRangeToSelection({
10927
+ schema: editorActor.getSnapshot().context.schema,
10928
+ editor,
10929
+ range: editor.selection
10930
+ })?.focus.path ?? [] : []),
10975
10931
  insertBlock: (type, value) => (editorActor.send({
10976
10932
  type: "behavior event",
10977
10933
  behaviorEvent: {