@portabletext/editor 1.50.8 → 1.52.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.
Files changed (104) hide show
  1. package/lib/_chunks-cjs/{util.slice-blocks.cjs → selection-point.cjs} +26 -18
  2. package/lib/_chunks-cjs/selection-point.cjs.map +1 -0
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +13 -10
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +46 -46
  6. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +21 -17
  8. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  9. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +10 -10
  10. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
  11. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +5 -5
  12. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
  13. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
  14. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +7 -14
  16. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  17. package/lib/_chunks-es/{util.slice-blocks.js → selection-point.js} +26 -18
  18. package/lib/_chunks-es/selection-point.js.map +1 -0
  19. package/lib/_chunks-es/selector.get-text-before.js +13 -10
  20. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  21. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +21 -21
  22. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  23. package/lib/_chunks-es/selector.is-selection-expanded.js +14 -10
  24. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  25. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +2 -2
  26. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
  27. package/lib/_chunks-es/util.is-equal-selection-points.js +1 -1
  28. package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
  29. package/lib/_chunks-es/util.selection-point-to-block-offset.js +4 -11
  30. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  31. package/lib/behaviors/index.cjs.map +1 -1
  32. package/lib/behaviors/index.d.cts +25 -2010
  33. package/lib/behaviors/index.d.ts +25 -2010
  34. package/lib/behaviors/index.js.map +1 -1
  35. package/lib/index.cjs +515 -393
  36. package/lib/index.cjs.map +1 -1
  37. package/lib/index.d.cts +361 -34
  38. package/lib/index.d.ts +361 -34
  39. package/lib/index.js +471 -349
  40. package/lib/index.js.map +1 -1
  41. package/lib/plugins/index.cjs +11 -11
  42. package/lib/plugins/index.cjs.map +1 -1
  43. package/lib/plugins/index.d.cts +32 -1986
  44. package/lib/plugins/index.d.ts +32 -1986
  45. package/lib/plugins/index.js +1 -1
  46. package/lib/selectors/index.cjs +11 -7
  47. package/lib/selectors/index.cjs.map +1 -1
  48. package/lib/selectors/index.d.cts +2 -2648
  49. package/lib/selectors/index.d.ts +2 -2648
  50. package/lib/selectors/index.js +7 -3
  51. package/lib/selectors/index.js.map +1 -1
  52. package/lib/utils/index.cjs +25 -14
  53. package/lib/utils/index.cjs.map +1 -1
  54. package/lib/utils/index.d.cts +0 -2647
  55. package/lib/utils/index.d.ts +0 -2647
  56. package/lib/utils/index.js +14 -3
  57. package/lib/utils/index.js.map +1 -1
  58. package/package.json +14 -14
  59. package/src/behaviors/behavior.abstract.delete.ts +0 -2
  60. package/src/behaviors/behavior.abstract.insert.ts +8 -8
  61. package/src/behaviors/behavior.abstract.ts +0 -113
  62. package/src/behaviors/behavior.core.block-element.ts +9 -3
  63. package/src/behaviors/behavior.core.dnd.ts +328 -1
  64. package/src/behaviors/behavior.perform-event.ts +10 -0
  65. package/src/behaviors/behavior.types.action.ts +2 -0
  66. package/src/behaviors/behavior.types.event.ts +5 -0
  67. package/src/behaviors/behavior.types.guard.ts +2 -0
  68. package/src/converters/converter.portable-text.ts +2 -7
  69. package/src/converters/converter.text-html.ts +1 -3
  70. package/src/converters/converter.text-plain.ts +3 -5
  71. package/src/editor/Editable.tsx +6 -133
  72. package/src/editor/editor-machine.ts +15 -10
  73. package/src/editor/editor-selector.ts +0 -2
  74. package/src/editor/editor-snapshot.ts +0 -18
  75. package/src/internal-utils/create-test-snapshot.ts +0 -2
  76. package/src/internal-utils/event-position.ts +42 -30
  77. package/src/internal-utils/selection-block-keys.ts +7 -7
  78. package/src/internal-utils/selection-elements.ts +108 -0
  79. package/src/internal-utils/selection-focus-text.ts +13 -9
  80. package/src/internal-utils/selection-text.ts +9 -78
  81. package/src/internal-utils/terse-pt.test.ts +108 -26
  82. package/src/internal-utils/terse-pt.ts +132 -14
  83. package/src/operations/behavior.operation.decorator.add.ts +0 -2
  84. package/src/operations/behavior.operation.delete.ts +18 -13
  85. package/src/operations/behavior.operation.insert.block.ts +5 -1
  86. package/src/selection/selection-point.ts +22 -0
  87. package/src/selectors/selector.get-anchor-block.ts +6 -6
  88. package/src/selectors/selector.get-anchor-child.ts +6 -6
  89. package/src/selectors/selector.get-selected-spans.ts +16 -19
  90. package/src/selectors/selector.get-selected-text-blocks.ts +11 -19
  91. package/src/selectors/selector.get-selection-end-block.ts +30 -0
  92. package/src/selectors/selector.get-selection-start-block.ts +30 -0
  93. package/src/selectors/selector.get-text-before.ts +15 -16
  94. package/src/selectors/selector.get-trimmed-selection.ts +15 -21
  95. package/src/selectors/selector.is-point-after-selection.ts +11 -19
  96. package/src/selectors/selector.is-point-before-selection.ts +11 -19
  97. package/src/selectors/selectors.ts +23 -39
  98. package/src/utils/util.block-offset.ts +6 -7
  99. package/src/utils/util.child-selection-point-to-block-offset.ts +6 -7
  100. package/src/utils/util.selection-point-to-block-offset.ts +5 -6
  101. package/src/utils/util.slice-blocks.ts +11 -20
  102. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
  103. package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
  104. package/src/internal-utils/inline-object-selection.ts +0 -115
package/lib/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$h = require("debug"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
3
+ var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$h = require("debug"), slateDom = require("slate-dom"), selectionPoint = require("./_chunks-cjs/selection-point.cjs"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
@@ -17,91 +17,12 @@ function EditorEventListener(props) {
17
17
  let t1;
18
18
  return $[3] !== editor ? (t1 = [editor], $[3] = editor, $[4] = t1) : t1 = $[4], React.useEffect(t0, t1), null;
19
19
  }
20
- function getCompoundClientRect(nodes) {
21
- if (nodes.length === 0)
22
- return new DOMRect(0, 0, 0, 0);
23
- const elements = nodes.filter((node) => node instanceof Element), firstRect = elements.at(0)?.getBoundingClientRect();
24
- if (!firstRect)
25
- return new DOMRect(0, 0, 0, 0);
26
- let left = firstRect.left, top = firstRect.top, right = firstRect.right, bottom = firstRect.bottom;
27
- for (let i = 1; i < elements.length; i++) {
28
- const rect = elements[i].getBoundingClientRect();
29
- left = Math.min(left, rect.left), top = Math.min(top, rect.top), right = Math.max(right, rect.right), bottom = Math.max(bottom, rect.bottom);
30
- }
31
- return new DOMRect(left, top, right - left, bottom - top);
32
- }
33
20
  const rootName = "sanity-pte:";
34
21
  debug__default.default(rootName);
35
22
  function debugWithName(name) {
36
23
  const namespace = `${rootName}${name}`;
37
24
  return debug__default.default && debug__default.default.enabled(namespace) ? debug__default.default(namespace) : debug__default.default(rootName);
38
25
  }
39
- function getDragSelection({
40
- eventSelection,
41
- snapshot
42
- }) {
43
- let dragSelection = eventSelection;
44
- if (selector_isSelectingEntireBlocks.getFocusInlineObject({
45
- context: {
46
- ...snapshot.context,
47
- selection: eventSelection
48
- }
49
- }))
50
- return dragSelection;
51
- const draggingCollapsedSelection = selector_isSelectionExpanded.isSelectionCollapsed({
52
- context: {
53
- ...snapshot.context,
54
- selection: eventSelection
55
- }
56
- }), draggedTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
57
- context: {
58
- ...snapshot.context,
59
- selection: eventSelection
60
- }
61
- }), draggedSpan = selector_isSelectionExpanded.getFocusSpan({
62
- context: {
63
- ...snapshot.context,
64
- selection: eventSelection
65
- }
66
- });
67
- draggingCollapsedSelection && draggedTextBlock && draggedSpan && (dragSelection = {
68
- anchor: util_sliceBlocks.getBlockStartPoint({
69
- context: snapshot.context,
70
- block: draggedTextBlock
71
- }),
72
- focus: util_isEqualSelectionPoints.getBlockEndPoint({
73
- context: snapshot.context,
74
- block: draggedTextBlock
75
- })
76
- });
77
- const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot);
78
- if (snapshot.context.selection && selector_isSelectionExpanded.isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
79
- const selectionStartBlock = selector_isSelectionExpanded.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectionExpanded.getSelectionEndBlock(snapshot);
80
- if (!selectionStartBlock || !selectionEndBlock)
81
- return dragSelection;
82
- const selectionStartPoint = util_sliceBlocks.getBlockStartPoint({
83
- context: snapshot.context,
84
- block: selectionStartBlock
85
- }), selectionEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
86
- context: snapshot.context,
87
- block: selectionEndBlock
88
- });
89
- selector_isSelectingEntireBlocks.isOverlappingSelection(eventSelection)({
90
- ...snapshot,
91
- context: {
92
- ...snapshot.context,
93
- selection: {
94
- anchor: selectionStartPoint,
95
- focus: selectionEndPoint
96
- }
97
- }
98
- }) && (dragSelection = {
99
- anchor: selectionStartPoint,
100
- focus: selectionEndPoint
101
- });
102
- }
103
- return dragSelection;
104
- }
105
26
  const VOID_CHILD_KEY = "void-child";
106
27
  function keepObjectEquality(object, keyMap) {
107
28
  const value = keyMap[object._key];
@@ -462,81 +383,81 @@ function getEventPosition({
462
383
  setup: "setting up"
463
384
  }))
464
385
  return;
465
- const node = getEventNode({
386
+ const eventNode = getEventNode({
466
387
  slateEditor,
467
388
  event
468
389
  });
469
- if (!node)
390
+ if (!eventNode)
470
391
  return;
471
- const block = getNodeBlock({
392
+ const eventBlock = getNodeBlock({
472
393
  editor: slateEditor,
473
394
  schema: editorActor.getSnapshot().context.schema,
474
- node
475
- }), positionBlock = getEventPositionBlock({
476
- node,
395
+ node: eventNode
396
+ }), eventPositionBlock = getEventPositionBlock({
397
+ node: eventNode,
477
398
  slateEditor,
478
399
  event
479
- }), selection = getEventSelection({
400
+ }), eventSelection = getEventSelection({
480
401
  schema: editorActor.getSnapshot().context.schema,
481
402
  slateEditor,
482
403
  event
483
404
  });
484
- if (block && positionBlock && !selection && !slate.Editor.isEditor(node))
405
+ if (eventBlock && eventPositionBlock && !eventSelection && !slate.Editor.isEditor(eventNode))
485
406
  return {
486
- block: positionBlock,
407
+ block: eventPositionBlock,
487
408
  isEditor: !1,
488
409
  selection: {
489
- anchor: util_sliceBlocks.getBlockStartPoint({
410
+ anchor: selectionPoint.getBlockStartPoint({
490
411
  context: editorActor.getSnapshot().context,
491
412
  block: {
492
- node: block,
413
+ node: eventBlock,
493
414
  path: [{
494
- _key: block._key
415
+ _key: eventBlock._key
495
416
  }]
496
417
  }
497
418
  }),
498
419
  focus: util_isEqualSelectionPoints.getBlockEndPoint({
499
420
  context: editorActor.getSnapshot().context,
500
421
  block: {
501
- node: block,
422
+ node: eventBlock,
502
423
  path: [{
503
- _key: block._key
424
+ _key: eventBlock._key
504
425
  }]
505
426
  }
506
427
  })
507
428
  }
508
429
  };
509
- if (!positionBlock || !selection)
430
+ if (!eventPositionBlock || !eventSelection)
510
431
  return;
511
- const focusBlockPath = selection.focus.path.at(0), focusBlockKey = util_sliceBlocks.isKeyedSegment(focusBlockPath) ? focusBlockPath._key : void 0;
512
- if (focusBlockKey)
513
- return util_selectionPointToBlockOffset.isSelectionCollapsed(selection) && block && focusBlockKey !== block._key ? {
514
- block: positionBlock,
432
+ const eventSelectionFocusBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(eventSelection.focus);
433
+ if (eventSelectionFocusBlockKey !== void 0)
434
+ return util_selectionPointToBlockOffset.isSelectionCollapsed(eventSelection) && eventBlock && eventSelectionFocusBlockKey !== eventBlock._key ? {
435
+ block: eventPositionBlock,
515
436
  isEditor: !1,
516
437
  selection: {
517
- anchor: util_sliceBlocks.getBlockStartPoint({
438
+ anchor: selectionPoint.getBlockStartPoint({
518
439
  context: editorActor.getSnapshot().context,
519
440
  block: {
520
- node: block,
441
+ node: eventBlock,
521
442
  path: [{
522
- _key: block._key
443
+ _key: eventBlock._key
523
444
  }]
524
445
  }
525
446
  }),
526
447
  focus: util_isEqualSelectionPoints.getBlockEndPoint({
527
448
  context: editorActor.getSnapshot().context,
528
449
  block: {
529
- node: block,
450
+ node: eventBlock,
530
451
  path: [{
531
- _key: block._key
452
+ _key: eventBlock._key
532
453
  }]
533
454
  }
534
455
  })
535
456
  }
536
457
  } : {
537
- block: positionBlock,
538
- isEditor: slate.Editor.isEditor(node),
539
- selection
458
+ block: eventPositionBlock,
459
+ isEditor: slate.Editor.isEditor(eventNode),
460
+ selection: eventSelection
540
461
  };
541
462
  }
542
463
  function getEventNode({
@@ -700,35 +621,6 @@ function normalizeSelection(selection, value) {
700
621
  backward: selection.backward
701
622
  } : null;
702
623
  }
703
- function getSelectionDomNodes({
704
- slateEditor,
705
- snapshot
706
- }) {
707
- if (!snapshot.context.selection)
708
- return {
709
- blockNodes: [],
710
- childNodes: []
711
- };
712
- const range = toSlateRange(snapshot.context.selection, slateEditor);
713
- if (!range)
714
- return {
715
- blockNodes: [],
716
- childNodes: []
717
- };
718
- const blockEntries = Array.from(slate.Editor.nodes(slateEditor, {
719
- at: range,
720
- mode: "highest",
721
- match: (n) => !slate.Editor.isEditor(n)
722
- })), childEntries = Array.from(slate.Editor.nodes(slateEditor, {
723
- at: range,
724
- mode: "lowest",
725
- match: (n) => !slate.Editor.isEditor(n) && slateEditor.isTextSpan(n) || !slateEditor.isBlock(n)
726
- }));
727
- return {
728
- blockNodes: blockEntries.map(([blockNode]) => slateDom.DOMEditor.toDOMNode(slateEditor, blockNode)),
729
- childNodes: childEntries.map(([childNode]) => slateDom.DOMEditor.toDOMNode(slateEditor, childNode))
730
- };
731
- }
732
624
  const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), EditorActorContext = React.createContext({});
733
625
  function DropIndicator() {
734
626
  const $ = reactCompilerRuntime.c(1);
@@ -771,6 +663,72 @@ function RenderDefaultInlineObject(props) {
771
663
  "]"
772
664
  ] }), $[1] = props.inlineObject._key, $[2] = props.inlineObject._type, $[3] = t1) : t1 = $[3], t1;
773
665
  }
666
+ function getDragSelection({
667
+ eventSelection,
668
+ snapshot
669
+ }) {
670
+ let dragSelection = eventSelection;
671
+ if (selector_isSelectingEntireBlocks.getFocusInlineObject({
672
+ context: {
673
+ ...snapshot.context,
674
+ selection: eventSelection
675
+ }
676
+ }))
677
+ return dragSelection;
678
+ const draggingCollapsedSelection = selector_isSelectionExpanded.isSelectionCollapsed({
679
+ context: {
680
+ ...snapshot.context,
681
+ selection: eventSelection
682
+ }
683
+ }), draggedTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
684
+ context: {
685
+ ...snapshot.context,
686
+ selection: eventSelection
687
+ }
688
+ }), draggedSpan = selector_isSelectionExpanded.getFocusSpan({
689
+ context: {
690
+ ...snapshot.context,
691
+ selection: eventSelection
692
+ }
693
+ });
694
+ draggingCollapsedSelection && draggedTextBlock && draggedSpan && (dragSelection = {
695
+ anchor: selectionPoint.getBlockStartPoint({
696
+ context: snapshot.context,
697
+ block: draggedTextBlock
698
+ }),
699
+ focus: util_isEqualSelectionPoints.getBlockEndPoint({
700
+ context: snapshot.context,
701
+ block: draggedTextBlock
702
+ })
703
+ });
704
+ const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot);
705
+ if (snapshot.context.selection && selector_isSelectionExpanded.isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
706
+ const selectionStartBlock = selector_isSelectionExpanded.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectionExpanded.getSelectionEndBlock(snapshot);
707
+ if (!selectionStartBlock || !selectionEndBlock)
708
+ return dragSelection;
709
+ const selectionStartPoint = selectionPoint.getBlockStartPoint({
710
+ context: snapshot.context,
711
+ block: selectionStartBlock
712
+ }), selectionEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
713
+ context: snapshot.context,
714
+ block: selectionEndBlock
715
+ });
716
+ selector_isSelectingEntireBlocks.isOverlappingSelection(eventSelection)({
717
+ ...snapshot,
718
+ context: {
719
+ ...snapshot.context,
720
+ selection: {
721
+ anchor: selectionStartPoint,
722
+ focus: selectionEndPoint
723
+ }
724
+ }
725
+ }) && (dragSelection = {
726
+ anchor: selectionStartPoint,
727
+ focus: selectionEndPoint
728
+ });
729
+ }
730
+ return dragSelection;
731
+ }
774
732
  const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
775
733
  let table;
776
734
  return () => {
@@ -819,16 +777,22 @@ function createCoreBlockElementBehaviorsConfig({
819
777
  });
820
778
  if (!dropFocusBlock || dropFocusBlock.node._key !== key)
821
779
  return !1;
822
- const dragOrigin = snapshot.beta.internalDrag?.origin;
823
- return !dragOrigin || selector_isSelectionExpanded.getSelectedBlocks({
780
+ const dragOrigin = event.dragOrigin;
781
+ if (!dragOrigin)
782
+ return !1;
783
+ const dragSelection = getDragSelection({
784
+ eventSelection: dragOrigin.selection,
785
+ snapshot
786
+ });
787
+ return selector_isSelectionExpanded.getSelectedBlocks({
824
788
  context: {
825
789
  ...snapshot.context,
826
- selection: dragOrigin.selection
790
+ selection: dragSelection
827
791
  }
828
792
  }).some((draggedBlock) => draggedBlock.node._key === key) ? !1 : selector_isSelectingEntireBlocks.isSelectingEntireBlocks({
829
793
  context: {
830
794
  ...snapshot.context,
831
- selection: dragOrigin.selection
795
+ selection: dragSelection
832
796
  }
833
797
  });
834
798
  },
@@ -1025,7 +989,7 @@ function RenderElement(props) {
1025
989
  let t02;
1026
990
  if ($[0] !== props.element || $[1] !== schema2) {
1027
991
  let t13;
1028
- $[3] !== props.element ? (t13 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[3] = props.element, $[4] = t13) : t13 = $[4], t02 = util_sliceBlocks.parseInlineObject({
992
+ $[3] !== props.element ? (t13 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[3] = props.element, $[4] = t13) : t13 = $[4], t02 = selectionPoint.parseInlineObject({
1029
993
  context: {
1030
994
  keyGenerator: _temp2,
1031
995
  schema: schema2
@@ -1053,7 +1017,7 @@ function RenderElement(props) {
1053
1017
  return $[9] !== props.attributes || $[10] !== props.children || $[11] !== props.element || $[12] !== props.readOnly || $[13] !== props.renderChild || $[14] !== t12 ? (t22 = /* @__PURE__ */ jsxRuntime.jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, inlineObject: t12, readOnly: props.readOnly, renderChild: props.renderChild, children: props.children }), $[9] = props.attributes, $[10] = props.children, $[11] = props.element, $[12] = props.readOnly, $[13] = props.renderChild, $[14] = t12, $[15] = t22) : t22 = $[15], t22;
1054
1018
  }
1055
1019
  let t0;
1056
- $[16] !== props.element || $[17] !== schema2 ? (t0 = util_sliceBlocks.parseTextBlock({
1020
+ $[16] !== props.element || $[17] !== schema2 ? (t0 = selectionPoint.parseTextBlock({
1057
1021
  context: {
1058
1022
  keyGenerator: _temp3,
1059
1023
  schema: schema2
@@ -1072,7 +1036,7 @@ function RenderElement(props) {
1072
1036
  let t1;
1073
1037
  if ($[29] !== props.element || $[30] !== schema2) {
1074
1038
  let t22;
1075
- $[32] !== props.element ? (t22 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[32] = props.element, $[33] = t22) : t22 = $[33], t1 = util_sliceBlocks.parseBlockObject({
1039
+ $[32] !== props.element ? (t22 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[32] = props.element, $[33] = t22) : t22 = $[33], t1 = selectionPoint.parseBlockObject({
1076
1040
  context: {
1077
1041
  keyGenerator: _temp4,
1078
1042
  schema: schema2
@@ -1177,7 +1141,7 @@ const converterJson = {
1177
1141
  snapshot,
1178
1142
  event
1179
1143
  }) => {
1180
- const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
1144
+ const selection = snapshot.context.selection;
1181
1145
  if (!selection)
1182
1146
  return {
1183
1147
  type: "serialization.failure",
@@ -1185,7 +1149,7 @@ const converterJson = {
1185
1149
  originEvent: event.originEvent,
1186
1150
  reason: "No selection"
1187
1151
  };
1188
- const blocks = util_sliceBlocks.sliceBlocks({
1152
+ const blocks = selectionPoint.sliceBlocks({
1189
1153
  context: {
1190
1154
  selection,
1191
1155
  schema: snapshot.context.schema
@@ -1216,15 +1180,11 @@ const converterJson = {
1216
1180
  reason: "Data is not an array"
1217
1181
  };
1218
1182
  const parsedBlocks = blocks.flatMap((block) => {
1219
- const parsedBlock = util_sliceBlocks.parseBlock({
1183
+ const parsedBlock = selectionPoint.parseBlock({
1220
1184
  context: snapshot.context,
1221
1185
  block,
1222
1186
  options: {
1223
- /**
1224
- * If we are dragging internally then we would like to keep the
1225
- * dropped portable text as is.
1226
- */
1227
- refreshKeys: !snapshot.beta.hasTag?.("dragging internally"),
1187
+ refreshKeys: !0,
1228
1188
  validateFields: !1
1229
1189
  }
1230
1190
  });
@@ -1248,7 +1208,7 @@ function createConverterTextHtml(legacySchema) {
1248
1208
  snapshot,
1249
1209
  event
1250
1210
  }) => {
1251
- const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
1211
+ const selection = snapshot.context.selection;
1252
1212
  if (!selection)
1253
1213
  return {
1254
1214
  type: "serialization.failure",
@@ -1256,7 +1216,7 @@ function createConverterTextHtml(legacySchema) {
1256
1216
  originEvent: event.originEvent,
1257
1217
  reason: "No selection"
1258
1218
  };
1259
- const blocks = util_sliceBlocks.sliceBlocks({
1219
+ const blocks = selectionPoint.sliceBlocks({
1260
1220
  context: {
1261
1221
  selection,
1262
1222
  schema: snapshot.context.schema
@@ -1290,7 +1250,7 @@ function createConverterTextHtml(legacySchema) {
1290
1250
  keyGenerator: snapshot.context.keyGenerator,
1291
1251
  unstable_whitespaceOnPasteMode: legacySchema.block.options.unstable_whitespaceOnPasteMode
1292
1252
  }).flatMap((block) => {
1293
- const parsedBlock = util_sliceBlocks.parseBlock({
1253
+ const parsedBlock = selectionPoint.parseBlock({
1294
1254
  context: snapshot.context,
1295
1255
  block,
1296
1256
  options: {
@@ -1319,16 +1279,16 @@ function createConverterTextPlain(legacySchema) {
1319
1279
  snapshot,
1320
1280
  event
1321
1281
  }) => {
1322
- const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
1282
+ const selection = snapshot.context.selection;
1323
1283
  return selection ? {
1324
1284
  type: "serialization.success",
1325
- data: util_sliceBlocks.sliceBlocks({
1285
+ data: selectionPoint.sliceBlocks({
1326
1286
  context: {
1327
1287
  selection,
1328
1288
  schema: snapshot.context.schema
1329
1289
  },
1330
1290
  blocks: snapshot.context.value
1331
- }).map((block) => util_sliceBlocks.isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
1291
+ }).map((block) => selectionPoint.isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : event.originEvent === "drag.dragstart" ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : event.originEvent === "drag.dragstart" ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
1332
1292
 
1333
1293
  `),
1334
1294
  mimeType: "text/plain",
@@ -1347,7 +1307,7 @@ function createConverterTextPlain(legacySchema) {
1347
1307
  const textToHtml = `<html><body>${escapeHtml(event.data).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`, parsedBlocks = blockTools.htmlToBlocks(textToHtml, legacySchema.portableText, {
1348
1308
  keyGenerator: snapshot.context.keyGenerator
1349
1309
  }).flatMap((block) => {
1350
- const parsedBlock = util_sliceBlocks.parseBlock({
1310
+ const parsedBlock = selectionPoint.parseBlock({
1351
1311
  context: snapshot.context,
1352
1312
  block,
1353
1313
  options: {
@@ -1563,9 +1523,7 @@ function getEditorSnapshot({
1563
1523
  decoratorState: slateEditorInstance.decoratorState,
1564
1524
  markState: slateEditorInstance.markState,
1565
1525
  schema: editorActorSnapshot.context.schema
1566
- }),
1567
- hasTag: (tag) => editorActorSnapshot.hasTag(tag),
1568
- internalDrag: editorActorSnapshot.context.internalDrag
1526
+ })
1569
1527
  }
1570
1528
  };
1571
1529
  }
@@ -2819,7 +2777,7 @@ const addAnnotationOperationImplementation = ({
2819
2777
  context,
2820
2778
  operation
2821
2779
  }) => {
2822
- const parsedAnnotation = util_sliceBlocks.parseAnnotation({
2780
+ const parsedAnnotation = selectionPoint.parseAnnotation({
2823
2781
  annotation: {
2824
2782
  _type: operation.annotation.name,
2825
2783
  ...operation.annotation.value
@@ -2975,7 +2933,7 @@ const addAnnotationOperationImplementation = ({
2975
2933
  const {
2976
2934
  _type,
2977
2935
  ...filteredProps
2978
- } = operation.props, updatedBlock = util_sliceBlocks.parseBlock({
2936
+ } = operation.props, updatedBlock = selectionPoint.parseBlock({
2979
2937
  context,
2980
2938
  block: {
2981
2939
  ...parsedBlock,
@@ -3020,8 +2978,8 @@ const addAnnotationOperationImplementation = ({
3020
2978
  const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
3021
2979
  if (!parsedBlock)
3022
2980
  throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
3023
- if (util_sliceBlocks.isTextBlock(context, parsedBlock)) {
3024
- const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_sliceBlocks.parseBlock({
2981
+ if (selectionPoint.isTextBlock(context, parsedBlock)) {
2982
+ const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock = selectionPoint.parseBlock({
3025
2983
  context,
3026
2984
  block: omit__default.default(parsedBlock, propsToRemove),
3027
2985
  options: {
@@ -3039,7 +2997,7 @@ const addAnnotationOperationImplementation = ({
3039
2997
  });
3040
2998
  return;
3041
2999
  }
3042
- const updatedBlockObject = util_sliceBlocks.parseBlock({
3000
+ const updatedBlockObject = selectionPoint.parseBlock({
3043
3001
  context,
3044
3002
  block: omit__default.default(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
3045
3003
  options: {
@@ -3065,14 +3023,14 @@ const addAnnotationOperationImplementation = ({
3065
3023
  context,
3066
3024
  operation
3067
3025
  }) => {
3068
- 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 ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3026
+ 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 ? selectionPoint.blockOffsetToSpanSelectionPoint({
3069
3027
  context: {
3070
3028
  ...context,
3071
3029
  value
3072
3030
  },
3073
3031
  blockOffset: operation.at.anchor,
3074
3032
  direction: "backward"
3075
- }) : void 0, manualFocus = operation.at?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3033
+ }) : void 0, manualFocus = operation.at?.focus ? selectionPoint.blockOffsetToSpanSelectionPoint({
3076
3034
  context: {
3077
3035
  ...context,
3078
3036
  value
@@ -3180,12 +3138,12 @@ const addAnnotationOperationImplementation = ({
3180
3138
  }, deleteOperationImplementation = ({
3181
3139
  operation
3182
3140
  }) => {
3183
- const anchorBlockPath = util_sliceBlocks.isKeyedSegment(operation.at.anchor.path[0]) ? getBlockPath({
3141
+ const anchorBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(operation.at.anchor), focusBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(operation.at.focus), anchorBlockPath = anchorBlockKey !== void 0 ? getBlockPath({
3184
3142
  editor: operation.editor,
3185
- _key: operation.at.anchor.path[0]._key
3186
- }) : void 0, focusBlockPath = util_sliceBlocks.isKeyedSegment(operation.at.focus.path[0]) ? getBlockPath({
3143
+ _key: anchorBlockKey
3144
+ }) : void 0, focusBlockPath = focusBlockKey !== void 0 ? getBlockPath({
3187
3145
  editor: operation.editor,
3188
- _key: operation.at.focus.path[0]._key
3146
+ _key: focusBlockKey
3189
3147
  }) : void 0;
3190
3148
  if (operation.at.anchor.path.length === 1 && operation.at.focus.path.length === 1 && anchorBlockPath && focusBlockPath && anchorBlockPath[0] === focusBlockPath[0]) {
3191
3149
  slate.Transforms.removeNodes(operation.editor, {
@@ -3205,7 +3163,7 @@ const addAnnotationOperationImplementation = ({
3205
3163
  context,
3206
3164
  operation
3207
3165
  }) => {
3208
- const parsedInlineObject = util_sliceBlocks.parseInlineObject({
3166
+ const parsedInlineObject = selectionPoint.parseInlineObject({
3209
3167
  context,
3210
3168
  inlineObject: {
3211
3169
  _type: operation.inlineObject.name,
@@ -3275,7 +3233,7 @@ const addAnnotationOperationImplementation = ({
3275
3233
  context,
3276
3234
  operation
3277
3235
  }) => {
3278
- const parsedBlock = util_sliceBlocks.parseBlock({
3236
+ const parsedBlock = selectionPoint.parseBlock({
3279
3237
  block: operation.block,
3280
3238
  context,
3281
3239
  options: {
@@ -3322,8 +3280,7 @@ function insertBlock({
3322
3280
  else if (placement === "after") {
3323
3281
  const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
3324
3282
  slate.Transforms.insertNodes(editor, [block], {
3325
- at: nextPath,
3326
- select: !1
3283
+ at: nextPath
3327
3284
  }), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
3328
3285
  } else {
3329
3286
  if (lastBlock && isEqualToEmptyEditor([lastBlock], schema2)) {
@@ -3436,7 +3393,9 @@ function insertBlock({
3436
3393
  editor
3437
3394
  });
3438
3395
  if (focusChild && editor.isTextSpan(focusChild))
3439
- slate.Transforms.insertFragment(editor, [block], {
3396
+ slate.Transforms.splitNodes(editor, {
3397
+ at: currentSelection2
3398
+ }), slate.Transforms.insertFragment(editor, [block], {
3440
3399
  at: currentSelection2
3441
3400
  }), select === "start" || select === "end" ? slate.Transforms.select(editor, [endBlockPath[0] + 1]) : slate.Transforms.select(editor, currentSelection2);
3442
3401
  else {
@@ -4212,7 +4171,7 @@ function unsetPatch(editor, patch) {
4212
4171
  function findBlock(children, path) {
4213
4172
  let blockIndex = -1;
4214
4173
  const block = children.find((node, index) => {
4215
- const isMatch = util_sliceBlocks.isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
4174
+ const isMatch = selectionPoint.isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
4216
4175
  return isMatch && (blockIndex = index), isMatch;
4217
4176
  });
4218
4177
  if (block)
@@ -4227,7 +4186,7 @@ function findBlockChild(block, path) {
4227
4186
  return;
4228
4187
  let childIndex = -1;
4229
4188
  const child = blockNode.children.find((node, index) => {
4230
- const isMatch = util_sliceBlocks.isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
4189
+ const isMatch = selectionPoint.isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
4231
4190
  return isMatch && (childIndex = index), isMatch;
4232
4191
  });
4233
4192
  if (child)
@@ -4237,14 +4196,14 @@ function findBlockChild(block, path) {
4237
4196
  };
4238
4197
  }
4239
4198
  function insertTextPatch(schema2, children, operation, beforeValue) {
4240
- const block = util_sliceBlocks.isTextBlock({
4199
+ const block = selectionPoint.isTextBlock({
4241
4200
  schema: schema2
4242
4201
  }, children[operation.path[0]]) && children[operation.path[0]];
4243
4202
  if (!block)
4244
4203
  throw new Error("Could not find block");
4245
- const textChild = util_sliceBlocks.isTextBlock({
4204
+ const textChild = selectionPoint.isTextBlock({
4246
4205
  schema: schema2
4247
- }, block) && util_sliceBlocks.isSpan$1({
4206
+ }, block) && selectionPoint.isSpan$1({
4248
4207
  schema: schema2
4249
4208
  }, block.children[operation.path[1]]) && block.children[operation.path[1]];
4250
4209
  if (!textChild)
@@ -4253,9 +4212,9 @@ function insertTextPatch(schema2, children, operation, beforeValue) {
4253
4212
  _key: block._key
4254
4213
  }, "children", {
4255
4214
  _key: textChild._key
4256
- }, "text"], prevBlock = beforeValue[operation.path[0]], prevChild = util_sliceBlocks.isTextBlock({
4215
+ }, "text"], prevBlock = beforeValue[operation.path[0]], prevChild = selectionPoint.isTextBlock({
4257
4216
  schema: schema2
4258
- }, prevBlock) && prevBlock.children[operation.path[1]], prevText = util_sliceBlocks.isSpan$1({
4217
+ }, prevBlock) && prevBlock.children[operation.path[1]], prevText = selectionPoint.isSpan$1({
4259
4218
  schema: schema2
4260
4219
  }, prevChild) ? prevChild.text : "", patch = patches.diffMatchPatch(prevText, textChild.text, path);
4261
4220
  return patch.value.length ? [patch] : [];
@@ -4264,9 +4223,9 @@ function removeTextPatch(schema2, children, operation, beforeValue) {
4264
4223
  const block = children[operation.path[0]];
4265
4224
  if (!block)
4266
4225
  throw new Error("Could not find block");
4267
- const child = util_sliceBlocks.isTextBlock({
4226
+ const child = selectionPoint.isTextBlock({
4268
4227
  schema: schema2
4269
- }, block) && block.children[operation.path[1]] || void 0, textChild = util_sliceBlocks.isSpan$1({
4228
+ }, block) && block.children[operation.path[1]] || void 0, textChild = selectionPoint.isSpan$1({
4270
4229
  schema: schema2
4271
4230
  }, child) ? child : void 0;
4272
4231
  if (child && !textChild)
@@ -4277,9 +4236,9 @@ function removeTextPatch(schema2, children, operation, beforeValue) {
4277
4236
  _key: block._key
4278
4237
  }, "children", {
4279
4238
  _key: textChild._key
4280
- }, "text"], beforeBlock = beforeValue[operation.path[0]], prevTextChild = util_sliceBlocks.isTextBlock({
4239
+ }, "text"], beforeBlock = beforeValue[operation.path[0]], prevTextChild = selectionPoint.isTextBlock({
4281
4240
  schema: schema2
4282
- }, beforeBlock) && beforeBlock.children[operation.path[1]], prevText = util_sliceBlocks.isSpan$1({
4241
+ }, beforeBlock) && beforeBlock.children[operation.path[1]], prevText = selectionPoint.isSpan$1({
4283
4242
  schema: schema2
4284
4243
  }, prevTextChild) && prevTextChild.text, patch = patches.diffMatchPatch(prevText || "", textChild.text, path);
4285
4244
  return patch.value ? [patch] : [];
@@ -4298,7 +4257,7 @@ function setNodePatch(schema2, children, operation) {
4298
4257
  }])];
4299
4258
  } else if (operation.path.length === 2) {
4300
4259
  const block = children[operation.path[0]];
4301
- if (util_sliceBlocks.isTextBlock({
4260
+ if (selectionPoint.isTextBlock({
4302
4261
  schema: schema2
4303
4262
  }, block)) {
4304
4263
  const child = block.children[operation.path[1]];
@@ -4333,7 +4292,7 @@ function insertNodePatch(schema2, children, operation, beforeValue) {
4333
4292
  return targetKey ? [patches.insert([fromSlateValue([operation.node], schema2.block.name)[0]], position, [{
4334
4293
  _key: targetKey
4335
4294
  }])] : [patches.setIfMissing(beforeValue, []), patches.insert([fromSlateValue([operation.node], schema2.block.name)[0]], "before", [operation.path[0]])];
4336
- } else if (util_sliceBlocks.isTextBlock({
4295
+ } else if (selectionPoint.isTextBlock({
4337
4296
  schema: schema2
4338
4297
  }, block) && operation.path.length === 2 && children[operation.path[0]]) {
4339
4298
  const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
@@ -4355,13 +4314,13 @@ function insertNodePatch(schema2, children, operation, beforeValue) {
4355
4314
  }
4356
4315
  function splitNodePatch(schema2, children, operation, beforeValue) {
4357
4316
  const patches$1 = [], splitBlock = children[operation.path[0]];
4358
- if (!util_sliceBlocks.isTextBlock({
4317
+ if (!selectionPoint.isTextBlock({
4359
4318
  schema: schema2
4360
4319
  }, splitBlock))
4361
4320
  throw new Error(`Block with path ${JSON.stringify(operation.path[0])} is not a text block and can't be split`);
4362
4321
  if (operation.path.length === 1) {
4363
4322
  const oldBlock = beforeValue[operation.path[0]];
4364
- if (util_sliceBlocks.isTextBlock({
4323
+ if (selectionPoint.isTextBlock({
4365
4324
  schema: schema2
4366
4325
  }, oldBlock)) {
4367
4326
  const targetValue = fromSlateValue([children[operation.path[0] + 1]], schema2.block.name)[0];
@@ -4380,7 +4339,7 @@ function splitNodePatch(schema2, children, operation, beforeValue) {
4380
4339
  }
4381
4340
  if (operation.path.length === 2) {
4382
4341
  const splitSpan = splitBlock.children[operation.path[1]];
4383
- if (util_sliceBlocks.isSpan$1({
4342
+ if (selectionPoint.isSpan$1({
4384
4343
  schema: schema2
4385
4344
  }, splitSpan)) {
4386
4345
  const targetSpans = fromSlateValue([{
@@ -4409,7 +4368,7 @@ function removeNodePatch(schema2, beforeValue, operation) {
4409
4368
  _key: block._key
4410
4369
  }])];
4411
4370
  throw new Error("Block not found");
4412
- } else if (util_sliceBlocks.isTextBlock({
4371
+ } else if (selectionPoint.isTextBlock({
4413
4372
  schema: schema2
4414
4373
  }, block) && operation.path.length === 2) {
4415
4374
  const spanToRemove = block.children[operation.path[1]];
@@ -4433,14 +4392,14 @@ function mergeNodePatch(schema2, children, operation, beforeValue) {
4433
4392
  }]));
4434
4393
  } else
4435
4394
  throw new Error("Target key not found!");
4436
- else if (util_sliceBlocks.isTextBlock({
4395
+ else if (selectionPoint.isTextBlock({
4437
4396
  schema: schema2
4438
- }, block) && util_sliceBlocks.isTextBlock({
4397
+ }, block) && selectionPoint.isTextBlock({
4439
4398
  schema: schema2
4440
4399
  }, updatedBlock) && operation.path.length === 2) {
4441
- const updatedSpan = updatedBlock.children[operation.path[1] - 1] && util_sliceBlocks.isSpan$1({
4400
+ const updatedSpan = updatedBlock.children[operation.path[1] - 1] && selectionPoint.isSpan$1({
4442
4401
  schema: schema2
4443
- }, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && util_sliceBlocks.isSpan$1({
4402
+ }, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && selectionPoint.isSpan$1({
4444
4403
  schema: schema2
4445
4404
  }, block.children[operation.path[1]]) ? block.children[operation.path[1]] : void 0;
4446
4405
  updatedSpan && (block.children.filter((span) => span._key === updatedSpan._key).length === 1 ? patches$1.push(patches.set(updatedSpan.text, [{
@@ -4466,9 +4425,9 @@ function moveNodePatch(schema2, beforeValue, operation) {
4466
4425
  }])), patches$1.push(patches.insert([fromSlateValue([block], schema2.block.name)[0]], position, [{
4467
4426
  _key: targetBlock._key
4468
4427
  }]));
4469
- } else if (operation.path.length === 2 && util_sliceBlocks.isTextBlock({
4428
+ } else if (operation.path.length === 2 && selectionPoint.isTextBlock({
4470
4429
  schema: schema2
4471
- }, block) && util_sliceBlocks.isTextBlock({
4430
+ }, block) && selectionPoint.isTextBlock({
4472
4431
  schema: schema2
4473
4432
  }, targetBlock)) {
4474
4433
  const child = block.children[operation.path[1]], targetChild = targetBlock.children[operation.newPath[1]], position = operation.newPath[1] === targetBlock.children.length ? "after" : "before", childToInsert = fromSlateValue([block], schema2.block.name)[0].children[operation.path[1]];
@@ -4695,7 +4654,7 @@ function createWithSchemaTypes({
4695
4654
  editorActor
4696
4655
  }) {
4697
4656
  return function(editor) {
4698
- editor.isTextBlock = (value) => util_sliceBlocks.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => util_sliceBlocks.isSpan$1(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => util_sliceBlocks.isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
4657
+ editor.isTextBlock = (value) => selectionPoint.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => selectionPoint.isSpan$1(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => selectionPoint.isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
4699
4658
  const {
4700
4659
  normalizeNode
4701
4660
  } = editor;
@@ -4859,7 +4818,7 @@ function isEditorNode(node) {
4859
4818
  return typeof node == "object" && node !== null ? !("_type" in node) && "children" in node && Array.isArray(node.children) : !1;
4860
4819
  }
4861
4820
  function isTextBlockNode(context, node) {
4862
- return util_sliceBlocks.isTypedObject(node) && node._type === context.schema.block.name;
4821
+ return selectionPoint.isTypedObject(node) && node._type === context.schema.block.name;
4863
4822
  }
4864
4823
  function isSpanNode(context, node) {
4865
4824
  return typeof node != "object" || node === null || "children" in node ? !1 : "_type" in node ? node._type === context.schema.span.name : "text" in node;
@@ -5444,7 +5403,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5444
5403
  snapshot
5445
5404
  }) => {
5446
5405
  const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), previousBlock = selector_isSelectionExpanded.getPreviousBlock(snapshot);
5447
- return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, previousBlock.node) ? {
5406
+ return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !selectionPoint.isTextBlock(snapshot.context, previousBlock.node) ? {
5448
5407
  focusTextBlock,
5449
5408
  previousBlock
5450
5409
  } : !1;
@@ -5474,7 +5433,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5474
5433
  snapshot
5475
5434
  }) => {
5476
5435
  const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), nextBlock = selector_isSelectionExpanded.getNextBlock(snapshot);
5477
- return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, nextBlock.node) ? {
5436
+ return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !selectionPoint.isTextBlock(snapshot.context, nextBlock.node) ? {
5478
5437
  focusTextBlock,
5479
5438
  nextBlock
5480
5439
  } : !1;
@@ -5551,7 +5510,131 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5551
5510
  decorator: "code"
5552
5511
  })]]
5553
5512
  })
5554
- }, coreDndBehaviors = [
5513
+ };
5514
+ function getCompoundClientRect(nodes) {
5515
+ if (nodes.length === 0)
5516
+ return new DOMRect(0, 0, 0, 0);
5517
+ const elements = nodes.filter((node) => node instanceof Element), firstRect = elements.at(0)?.getBoundingClientRect();
5518
+ if (!firstRect)
5519
+ return new DOMRect(0, 0, 0, 0);
5520
+ let left = firstRect.left, top = firstRect.top, right = firstRect.right, bottom = firstRect.bottom;
5521
+ for (let i = 1; i < elements.length; i++) {
5522
+ const rect = elements[i].getBoundingClientRect();
5523
+ left = Math.min(left, rect.left), top = Math.min(top, rect.top), right = Math.max(right, rect.right), bottom = Math.max(bottom, rect.bottom);
5524
+ }
5525
+ return new DOMRect(left, top, right - left, bottom - top);
5526
+ }
5527
+ const coreDndBehaviors = [
5528
+ /**
5529
+ * Core Behavior that:
5530
+ * 1. Calculates and selects a "drag selection"
5531
+ * 2. Constructs and sets a drag ghost element
5532
+ * 3. Forwards the dragstart event
5533
+ */
5534
+ behaviors_index.defineBehavior({
5535
+ on: "drag.dragstart",
5536
+ guard: ({
5537
+ snapshot,
5538
+ dom,
5539
+ event
5540
+ }) => {
5541
+ const dragSelection = getDragSelection({
5542
+ snapshot,
5543
+ eventSelection: event.position.selection
5544
+ }), selectingEntireBlocks = selector_isSelectingEntireBlocks.isSelectingEntireBlocks({
5545
+ context: {
5546
+ ...snapshot.context,
5547
+ selection: dragSelection
5548
+ }
5549
+ }), draggedDomNodes = {
5550
+ blockNodes: dom.getBlockNodes({
5551
+ ...snapshot,
5552
+ context: {
5553
+ ...snapshot.context,
5554
+ selection: dragSelection
5555
+ }
5556
+ }),
5557
+ childNodes: dom.getChildNodes({
5558
+ ...snapshot,
5559
+ context: {
5560
+ ...snapshot.context,
5561
+ selection: dragSelection
5562
+ }
5563
+ })
5564
+ };
5565
+ return {
5566
+ dragSelection,
5567
+ draggedDomNodes,
5568
+ selectingEntireBlocks
5569
+ };
5570
+ },
5571
+ actions: [({
5572
+ dom,
5573
+ event
5574
+ }, {
5575
+ dragSelection,
5576
+ draggedDomNodes,
5577
+ selectingEntireBlocks
5578
+ }) => {
5579
+ const dragGhost = document.createElement("div");
5580
+ if (selectingEntireBlocks) {
5581
+ const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) => node.cloneNode(!0));
5582
+ for (const block of clonedBlockNodes)
5583
+ block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
5584
+ const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
5585
+ if (customGhost && dragGhost.replaceChildren(customGhost), dragGhost.setAttribute("data-dragged", ""), dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost), customGhost) {
5586
+ const customGhostRect = customGhost.getBoundingClientRect(), x = event.originEvent.clientX - customGhostRect.left, y = event.originEvent.clientY - customGhostRect.top;
5587
+ return dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, [behaviors_index.raise({
5588
+ type: "select",
5589
+ at: dragSelection
5590
+ }), behaviors_index.effect(() => {
5591
+ dom.setDragGhost({
5592
+ event,
5593
+ ghost: {
5594
+ element: dragGhost,
5595
+ x,
5596
+ y
5597
+ }
5598
+ });
5599
+ }), behaviors_index.forward(event)];
5600
+ } else {
5601
+ const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x = event.originEvent.clientX - blocksDomRect.left, y = event.originEvent.clientY - blocksDomRect.top;
5602
+ return dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, [behaviors_index.raise({
5603
+ type: "select",
5604
+ at: dragSelection
5605
+ }), behaviors_index.effect(() => {
5606
+ dom.setDragGhost({
5607
+ event,
5608
+ ghost: {
5609
+ element: dragGhost,
5610
+ x,
5611
+ y
5612
+ }
5613
+ });
5614
+ }), behaviors_index.forward(event)];
5615
+ }
5616
+ } else {
5617
+ const clonedChildNodes = draggedDomNodes.childNodes.map((node) => node.cloneNode(!0));
5618
+ for (const child of clonedChildNodes)
5619
+ dragGhost.appendChild(child);
5620
+ dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
5621
+ const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x = event.originEvent.clientX - childrenDomRect.left, y = event.originEvent.clientY - childrenDomRect.top;
5622
+ return dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, [behaviors_index.raise({
5623
+ type: "select",
5624
+ at: dragSelection
5625
+ }), behaviors_index.effect(() => {
5626
+ dom.setDragGhost({
5627
+ event,
5628
+ ghost: {
5629
+ element: dragGhost,
5630
+ x,
5631
+ y
5632
+ }
5633
+ });
5634
+ }), behaviors_index.forward(event)];
5635
+ }
5636
+ }]
5637
+ }),
5555
5638
  /**
5556
5639
  * When dragging over the drag origin, we don't want to show the caret in the
5557
5640
  * text.
@@ -5562,7 +5645,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5562
5645
  snapshot,
5563
5646
  event
5564
5647
  }) => {
5565
- const dragOrigin = snapshot.beta.internalDrag?.origin;
5648
+ const dragOrigin = event.dragOrigin;
5566
5649
  return dragOrigin ? selector_isSelectingEntireBlocks.isOverlappingSelection(event.position.selection)({
5567
5650
  ...snapshot,
5568
5651
  context: {
@@ -5572,6 +5655,121 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5572
5655
  }) : !1;
5573
5656
  },
5574
5657
  actions: []
5658
+ }),
5659
+ /**
5660
+ * If the drop position overlaps the drag origin, then the event should be
5661
+ * cancelled.
5662
+ */
5663
+ behaviors_index.defineBehavior({
5664
+ on: "drag.drop",
5665
+ guard: ({
5666
+ snapshot,
5667
+ event
5668
+ }) => {
5669
+ const dragOrigin = event.dragOrigin, dropPosition = event.position.selection;
5670
+ return dragOrigin ? selector_isSelectingEntireBlocks.isOverlappingSelection(dropPosition)({
5671
+ ...snapshot,
5672
+ context: {
5673
+ ...snapshot.context,
5674
+ selection: dragOrigin.selection
5675
+ }
5676
+ }) : !1;
5677
+ },
5678
+ actions: []
5679
+ }),
5680
+ /**
5681
+ * If we drop and have access to a drag origin, then we can deserialize
5682
+ * without creating a new selection.
5683
+ */
5684
+ behaviors_index.defineBehavior({
5685
+ on: "drag.drop",
5686
+ guard: ({
5687
+ event
5688
+ }) => event.dragOrigin !== void 0,
5689
+ actions: [({
5690
+ event
5691
+ }) => [behaviors_index.raise({
5692
+ type: "deserialize",
5693
+ originEvent: event
5694
+ })]]
5695
+ }),
5696
+ /**
5697
+ * Otherwise, we should to create a new selection.
5698
+ */
5699
+ behaviors_index.defineBehavior({
5700
+ on: "drag.drop",
5701
+ actions: [({
5702
+ event
5703
+ }) => [behaviors_index.raise({
5704
+ type: "select",
5705
+ at: event.position.selection
5706
+ }), behaviors_index.raise({
5707
+ type: "deserialize",
5708
+ originEvent: event
5709
+ })]]
5710
+ }),
5711
+ /**
5712
+ * Core Behavior that uses the drag origin to mimic a move operation during
5713
+ * internal dragging.
5714
+ */
5715
+ behaviors_index.defineBehavior({
5716
+ on: "deserialization.success",
5717
+ guard: ({
5718
+ snapshot,
5719
+ event
5720
+ }) => {
5721
+ if (event.originEvent.type !== "drag.drop" || event.originEvent.dragOrigin === void 0)
5722
+ return !1;
5723
+ const dragOrigin = event.originEvent.dragOrigin, dragSelection = getDragSelection({
5724
+ eventSelection: dragOrigin.selection,
5725
+ snapshot
5726
+ }), dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? selector_isSelectingEntireBlocks.isOverlappingSelection(dropPosition)({
5727
+ ...snapshot,
5728
+ context: {
5729
+ ...snapshot.context,
5730
+ selection: dragSelection
5731
+ }
5732
+ }) : !1, draggingEntireBlocks = selector_isSelectingEntireBlocks.isSelectingEntireBlocks({
5733
+ context: {
5734
+ ...snapshot.context,
5735
+ selection: dragSelection
5736
+ }
5737
+ }), draggedBlocks = selector_isSelectionExpanded.getSelectedBlocks({
5738
+ context: {
5739
+ ...snapshot.context,
5740
+ selection: dragSelection
5741
+ }
5742
+ });
5743
+ return droppingOnDragOrigin ? !1 : {
5744
+ dropPosition,
5745
+ draggingEntireBlocks,
5746
+ draggedBlocks,
5747
+ dragOrigin,
5748
+ originEvent: event.originEvent
5749
+ };
5750
+ },
5751
+ actions: [({
5752
+ event
5753
+ }, {
5754
+ draggingEntireBlocks,
5755
+ draggedBlocks,
5756
+ dragOrigin,
5757
+ dropPosition,
5758
+ originEvent
5759
+ }) => [...draggingEntireBlocks ? draggedBlocks.map((block) => behaviors_index.raise({
5760
+ type: "delete.block",
5761
+ at: block.path
5762
+ })) : [behaviors_index.raise({
5763
+ type: "delete",
5764
+ at: dragOrigin.selection
5765
+ })], behaviors_index.raise({
5766
+ type: "select",
5767
+ at: dropPosition
5768
+ }), behaviors_index.raise({
5769
+ type: "insert.blocks",
5770
+ blocks: event.data,
5771
+ placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
5772
+ })]]
5575
5773
  })
5576
5774
  ], breakingAtTheEndOfTextBlock = behaviors_index.defineBehavior({
5577
5775
  on: "insert.break",
@@ -5657,13 +5855,13 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5657
5855
  const firstBlock = selector_isSelectionExpanded.getFirstBlock(snapshot), lastBlock = selector_isSelectionExpanded.getLastBlock(snapshot);
5658
5856
  if (!firstBlock || !lastBlock)
5659
5857
  return !1;
5660
- const firstBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
5858
+ const firstBlockStartPoint = selectionPoint.getBlockStartPoint({
5661
5859
  context: snapshot.context,
5662
5860
  block: firstBlock
5663
- }), selectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
5861
+ }), selectionStartPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
5664
5862
  context: snapshot.context,
5665
5863
  block: lastBlock
5666
- }), selectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint(snapshot.context.selection);
5864
+ }), selectionEndPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection);
5667
5865
  return util_isEqualSelectionPoints.isEqualSelectionPoints(firstBlockStartPoint, selectionStartPoint) && util_isEqualSelectionPoints.isEqualSelectionPoints(lastBlockEndPoint, selectionEndPoint) ? {
5668
5866
  selection: snapshot.context.selection
5669
5867
  } : !1;
@@ -5684,13 +5882,13 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5684
5882
  const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectionStartBlock = selector_isSelectionExpanded.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectionExpanded.getSelectionEndBlock(snapshot);
5685
5883
  if (!selectionStartBlock || !selectionEndBlock)
5686
5884
  return !1;
5687
- const startBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
5885
+ const startBlockStartPoint = selectionPoint.getBlockStartPoint({
5688
5886
  context: snapshot.context,
5689
5887
  block: selectionStartBlock
5690
- }), selectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint(snapshot.context.selection), endBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
5888
+ }), selectionStartPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), endBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
5691
5889
  context: snapshot.context,
5692
5890
  block: selectionEndBlock
5693
- }), selectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint(snapshot.context.selection);
5891
+ }), selectionEndPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection);
5694
5892
  return util_isEqualSelectionPoints.isEqualSelectionPoints(selectionStartPoint, startBlockStartPoint) && util_isEqualSelectionPoints.isEqualSelectionPoints(selectionEndPoint, endBlockEndPoint) ? {
5695
5893
  selectedBlocks
5696
5894
  } : !1;
@@ -5783,7 +5981,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5783
5981
  }) => {
5784
5982
  if (!isHotkey("Tab", event.originEvent))
5785
5983
  return !1;
5786
- const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => util_sliceBlocks.isListBlock(snapshot.context, block.node) ? [{
5984
+ const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => selectionPoint.isListBlock(snapshot.context, block.node) ? [{
5787
5985
  node: block.node,
5788
5986
  path: block.path
5789
5987
  }] : []);
@@ -5808,7 +6006,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5808
6006
  }) => {
5809
6007
  if (!isHotkey("Shift+Tab", event.originEvent))
5810
6008
  return !1;
5811
- const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => util_sliceBlocks.isListBlock(snapshot.context, block.node) ? [{
6009
+ const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => selectionPoint.isListBlock(snapshot.context, block.node) ? [{
5812
6010
  node: block.node,
5813
6011
  path: block.path
5814
6012
  }] : []);
@@ -5834,7 +6032,52 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5834
6032
  }, coreBehaviorsConfig = [coreAnnotationBehaviors.addAnnotationOnCollapsedSelection, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks].map((behavior) => ({
5835
6033
  behavior,
5836
6034
  priority: corePriority
5837
- })), abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
6035
+ }));
6036
+ function createEditorDom(sendBack, slateEditor) {
6037
+ return {
6038
+ getBlockNodes: (snapshot) => getBlockNodes(slateEditor, snapshot),
6039
+ getChildNodes: (snapshot) => getChildNodes(slateEditor, snapshot),
6040
+ setDragGhost: ({
6041
+ event,
6042
+ ghost
6043
+ }) => setDragGhost({
6044
+ sendBack,
6045
+ event,
6046
+ ghost
6047
+ })
6048
+ };
6049
+ }
6050
+ function getBlockNodes(slateEditor, snapshot) {
6051
+ if (!snapshot.context.selection)
6052
+ return [];
6053
+ const range = toSlateRange(snapshot.context.selection, slateEditor);
6054
+ return range ? Array.from(slate.Editor.nodes(slateEditor, {
6055
+ at: range,
6056
+ mode: "highest",
6057
+ match: (n) => !slate.Editor.isEditor(n)
6058
+ })).map(([blockNode]) => slateDom.DOMEditor.toDOMNode(slateEditor, blockNode)) : [];
6059
+ }
6060
+ function getChildNodes(slateEditor, snapshot) {
6061
+ if (!snapshot.context.selection)
6062
+ return [];
6063
+ const range = toSlateRange(snapshot.context.selection, slateEditor);
6064
+ return range ? Array.from(slate.Editor.nodes(slateEditor, {
6065
+ at: range,
6066
+ mode: "lowest",
6067
+ match: (n) => !slate.Editor.isEditor(n)
6068
+ })).map(([childNode]) => slateDom.DOMEditor.toDOMNode(slateEditor, childNode)) : [];
6069
+ }
6070
+ function setDragGhost({
6071
+ sendBack,
6072
+ event,
6073
+ ghost
6074
+ }) {
6075
+ event.originEvent.dataTransfer.setDragImage(ghost.element, ghost.x, ghost.y), sendBack({
6076
+ type: "set drag ghost",
6077
+ ghost: ghost.element
6078
+ });
6079
+ }
6080
+ const abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
5838
6081
  on: "annotation.toggle",
5839
6082
  guard: ({
5840
6083
  snapshot,
@@ -5988,7 +6231,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
5988
6231
  type: "insert.block",
5989
6232
  block,
5990
6233
  placement: index === 0 ? "before" : "after",
5991
- select: "end"
6234
+ select: event.select ?? "end"
5992
6235
  }))]
5993
6236
  }), behaviors_index.defineBehavior({
5994
6237
  on: "insert.blocks",
@@ -6001,7 +6244,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6001
6244
  type: "insert.block",
6002
6245
  block,
6003
6246
  placement: "after",
6004
- select: "end"
6247
+ select: event.select ?? "end"
6005
6248
  }))]
6006
6249
  }), behaviors_index.defineBehavior({
6007
6250
  on: "insert.blocks",
@@ -6025,12 +6268,12 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6025
6268
  type: "insert.block",
6026
6269
  block: event.blocks[0],
6027
6270
  placement: "auto",
6028
- select: "end"
6271
+ select: event.select ?? "end"
6029
6272
  })] : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) => behaviors_index.raise({
6030
6273
  type: "insert.block",
6031
6274
  block,
6032
6275
  placement: index === 0 ? "auto" : "after",
6033
- select: "end"
6276
+ select: event.select ?? "end"
6034
6277
  })) : event.blocks.flatMap((block, index) => index === 0 ? [behaviors_index.raise({
6035
6278
  type: "split"
6036
6279
  }), behaviors_index.raise({
@@ -6040,7 +6283,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6040
6283
  type: "insert.block",
6041
6284
  block,
6042
6285
  placement: "auto",
6043
- select: "end"
6286
+ select: event.select ?? "end"
6044
6287
  })] : index === event.blocks.length - 1 ? [behaviors_index.raise({
6045
6288
  type: "select.next block",
6046
6289
  select: "start"
@@ -6048,12 +6291,12 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6048
6291
  type: "insert.block",
6049
6292
  block,
6050
6293
  placement: "auto",
6051
- select: "end"
6294
+ select: event.select ?? "end"
6052
6295
  })] : [behaviors_index.raise({
6053
6296
  type: "insert.block",
6054
6297
  block,
6055
6298
  placement: "after",
6056
- select: "end"
6299
+ select: event.select ?? "end"
6057
6300
  })])]
6058
6301
  }), behaviors_index.defineBehavior({
6059
6302
  on: "insert.blocks",
@@ -6066,7 +6309,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6066
6309
  type: "insert.block",
6067
6310
  block,
6068
6311
  placement: index === 0 ? "auto" : "after",
6069
- select: "end"
6312
+ select: event.select ?? "end"
6070
6313
  }))]
6071
6314
  }), behaviors_index.defineBehavior({
6072
6315
  on: "insert.break",
@@ -6234,7 +6477,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6234
6477
  const point = event.select === "end" ? util_isEqualSelectionPoints.getBlockEndPoint({
6235
6478
  context: snapshot.context,
6236
6479
  block: previousBlock
6237
- }) : util_sliceBlocks.getBlockStartPoint({
6480
+ }) : selectionPoint.getBlockStartPoint({
6238
6481
  context: snapshot.context,
6239
6482
  block: previousBlock
6240
6483
  });
@@ -6263,7 +6506,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6263
6506
  const point = event.select === "end" ? util_isEqualSelectionPoints.getBlockEndPoint({
6264
6507
  context: snapshot.context,
6265
6508
  block: nextBlock
6266
- }) : util_sliceBlocks.getBlockStartPoint({
6509
+ }) : selectionPoint.getBlockStartPoint({
6267
6510
  context: snapshot.context,
6268
6511
  block: nextBlock
6269
6512
  });
@@ -6287,7 +6530,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6287
6530
  }) => {
6288
6531
  if (!snapshot.context.selection)
6289
6532
  return !1;
6290
- const selectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint(snapshot.context.selection), selectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint(snapshot.context.selection), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
6533
+ const selectionStartPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), selectionEndPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
6291
6534
  context: {
6292
6535
  ...snapshot.context,
6293
6536
  selection: {
@@ -6303,8 +6546,8 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6303
6546
  }), newTextBlockSelection = {
6304
6547
  anchor: selectionEndPoint,
6305
6548
  focus: blockEndPoint
6306
- }, newTextBlock = util_sliceBlocks.parseBlock({
6307
- block: util_sliceBlocks.sliceBlocks({
6549
+ }, newTextBlock = selectionPoint.parseBlock({
6550
+ block: selectionPoint.sliceBlocks({
6308
6551
  context: {
6309
6552
  ...snapshot.context,
6310
6553
  selection: newTextBlockSelection
@@ -6317,7 +6560,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6317
6560
  validateFields: !0
6318
6561
  }
6319
6562
  });
6320
- return !newTextBlock || !util_sliceBlocks.isTextBlock(snapshot.context, newTextBlock) ? !1 : {
6563
+ return !newTextBlock || !selectionPoint.isTextBlock(snapshot.context, newTextBlock) ? !1 : {
6321
6564
  newTextBlock,
6322
6565
  newTextBlockSelection,
6323
6566
  selection: {
@@ -6335,7 +6578,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6335
6578
  }
6336
6579
  }
6337
6580
  })) {
6338
- const newTextBlock = util_sliceBlocks.parseBlock({
6581
+ const newTextBlock = selectionPoint.parseBlock({
6339
6582
  block: {
6340
6583
  _type: snapshot.context.schema.block.name,
6341
6584
  children: []
@@ -6570,86 +6813,6 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6570
6813
  }
6571
6814
  }]]
6572
6815
  }),
6573
- behaviors_index.defineBehavior({
6574
- on: "drag.drop",
6575
- guard: ({
6576
- snapshot,
6577
- event
6578
- }) => {
6579
- const dragOrigin = snapshot.beta.internalDrag?.origin, dropPosition = event.position.selection;
6580
- return dragOrigin ? selector_isSelectingEntireBlocks.isOverlappingSelection(dropPosition)({
6581
- ...snapshot,
6582
- context: {
6583
- ...snapshot.context,
6584
- selection: dragOrigin.selection
6585
- }
6586
- }) : !1;
6587
- },
6588
- actions: []
6589
- }),
6590
- behaviors_index.defineBehavior({
6591
- on: "drag.drop",
6592
- actions: [({
6593
- event
6594
- }) => [behaviors_index.raise({
6595
- type: "select",
6596
- at: event.position.selection
6597
- }), behaviors_index.raise({
6598
- type: "deserialize",
6599
- originEvent: event
6600
- })]]
6601
- }),
6602
- behaviors_index.defineBehavior({
6603
- on: "deserialization.success",
6604
- guard: ({
6605
- snapshot,
6606
- event
6607
- }) => {
6608
- if (event.originEvent.type !== "drag.drop" || snapshot.beta.internalDrag === void 0)
6609
- return !1;
6610
- const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? selector_isSelectingEntireBlocks.isOverlappingSelection(dropPosition)({
6611
- ...snapshot,
6612
- context: {
6613
- ...snapshot.context,
6614
- selection: dragOrigin.selection
6615
- }
6616
- }) : !1, draggingEntireBlocks = selector_isSelectingEntireBlocks.isSelectingEntireBlocks({
6617
- context: {
6618
- ...snapshot.context,
6619
- selection: dragOrigin.selection
6620
- }
6621
- }), draggedBlocks = selector_isSelectionExpanded.getSelectedBlocks({
6622
- context: {
6623
- ...snapshot.context,
6624
- selection: dragOrigin.selection
6625
- }
6626
- });
6627
- return droppingOnDragOrigin ? !1 : {
6628
- draggingEntireBlocks,
6629
- draggedBlocks,
6630
- dragOrigin,
6631
- originEvent: event.originEvent
6632
- };
6633
- },
6634
- actions: [({
6635
- event
6636
- }, {
6637
- draggingEntireBlocks,
6638
- draggedBlocks,
6639
- dragOrigin,
6640
- originEvent
6641
- }) => [...draggingEntireBlocks ? draggedBlocks.map((block) => behaviors_index.raise({
6642
- type: "delete.block",
6643
- at: block.path
6644
- })) : [behaviors_index.raise({
6645
- type: "delete",
6646
- at: dragOrigin.selection
6647
- })], behaviors_index.raise({
6648
- type: "insert.blocks",
6649
- blocks: event.data,
6650
- placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
6651
- })]]
6652
- }),
6653
6816
  /**
6654
6817
  * If we are pasting text/plain into a text block then we can probably
6655
6818
  * assume that the intended behavior is that the pasted text inherits
@@ -6666,7 +6829,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6666
6829
  return {
6667
6830
  activeAnnotations: selector_isSelectingEntireBlocks.getActiveAnnotations(snapshot),
6668
6831
  activeDecorators,
6669
- textRuns: event.data.flatMap((block) => util_sliceBlocks.isTextBlock(snapshot.context, block) ? [util_sliceBlocks.getTextBlockText(block)] : [])
6832
+ textRuns: event.data.flatMap((block) => selectionPoint.isTextBlock(snapshot.context, block) ? [selectionPoint.getTextBlockText(block)] : [])
6670
6833
  };
6671
6834
  }
6672
6835
  return !1;
@@ -6801,7 +6964,8 @@ function performEvent({
6801
6964
  keyGenerator,
6802
6965
  schema: schema2,
6803
6966
  getSnapshot,
6804
- nativeEvent
6967
+ nativeEvent,
6968
+ sendBack
6805
6969
  }) {
6806
6970
  debug$9(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
6807
6971
  const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
@@ -6833,7 +6997,8 @@ function performEvent({
6833
6997
  try {
6834
6998
  shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
6835
6999
  snapshot: guardSnapshot,
6836
- event
7000
+ event,
7001
+ dom: createEditorDom(sendBack, editor)
6837
7002
  });
6838
7003
  } catch (error) {
6839
7004
  console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
@@ -6846,7 +7011,8 @@ function performEvent({
6846
7011
  try {
6847
7012
  actions = actionSet({
6848
7013
  snapshot: actionsSnapshot,
6849
- event
7014
+ event,
7015
+ dom: createEditorDom(sendBack, editor)
6850
7016
  }, shouldRun);
6851
7017
  } catch (error) {
6852
7018
  console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
@@ -6875,7 +7041,8 @@ function performEvent({
6875
7041
  keyGenerator,
6876
7042
  schema: schema2,
6877
7043
  getSnapshot,
6878
- nativeEvent
7044
+ nativeEvent,
7045
+ sendBack
6879
7046
  });
6880
7047
  continue;
6881
7048
  }
@@ -6889,7 +7056,8 @@ function performEvent({
6889
7056
  keyGenerator,
6890
7057
  schema: schema2,
6891
7058
  getSnapshot,
6892
- nativeEvent
7059
+ nativeEvent,
7060
+ sendBack
6893
7061
  });
6894
7062
  continue;
6895
7063
  }
@@ -6902,7 +7070,8 @@ function performEvent({
6902
7070
  keyGenerator,
6903
7071
  schema: schema2,
6904
7072
  getSnapshot,
6905
- nativeEvent: void 0
7073
+ nativeEvent: void 0,
7074
+ sendBack
6906
7075
  });
6907
7076
  }
6908
7077
  });
@@ -6929,7 +7098,8 @@ function performEvent({
6929
7098
  keyGenerator,
6930
7099
  schema: schema2,
6931
7100
  getSnapshot,
6932
- nativeEvent
7101
+ nativeEvent,
7102
+ sendBack
6933
7103
  });
6934
7104
  continue;
6935
7105
  }
@@ -6943,7 +7113,8 @@ function performEvent({
6943
7113
  keyGenerator,
6944
7114
  schema: schema2,
6945
7115
  getSnapshot,
6946
- nativeEvent
7116
+ nativeEvent,
7117
+ sendBack
6947
7118
  });
6948
7119
  continue;
6949
7120
  }
@@ -7015,9 +7186,7 @@ function createEditorSnapshot({
7015
7186
  editor,
7016
7187
  keyGenerator,
7017
7188
  readOnly,
7018
- schema: schema2,
7019
- hasTag,
7020
- internalDrag
7189
+ schema: schema2
7021
7190
  }) {
7022
7191
  const selection = editor.selection ? slateRangeToSelection({
7023
7192
  schema: schema2,
@@ -7042,9 +7211,7 @@ function createEditorSnapshot({
7042
7211
  decoratorState: editor.decoratorState,
7043
7212
  markState: editor.markState,
7044
7213
  schema: schema2
7045
- }),
7046
- hasTag,
7047
- internalDrag
7214
+ })
7048
7215
  }
7049
7216
  };
7050
7217
  }
@@ -7166,11 +7333,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
7166
7333
  readOnly: self.getSnapshot().matches({
7167
7334
  "edit mode": "read only"
7168
7335
  }),
7169
- schema: context.schema,
7170
- hasTag: (tag) => self.getSnapshot().hasTag(tag),
7171
- internalDrag: context.internalDrag
7336
+ schema: context.schema
7172
7337
  }),
7173
- nativeEvent: event.nativeEvent
7338
+ nativeEvent: event.nativeEvent,
7339
+ sendBack: (event2) => self.send(event2)
7174
7340
  });
7175
7341
  } catch (error) {
7176
7342
  console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`));
@@ -7224,6 +7390,13 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
7224
7390
  ...event,
7225
7391
  type: "selection"
7226
7392
  }))]
7393
+ },
7394
+ "set drag ghost": {
7395
+ actions: xstate.assign({
7396
+ dragGhost: ({
7397
+ event
7398
+ }) => event.ghost
7399
+ })
7227
7400
  }
7228
7401
  },
7229
7402
  type: "parallel",
@@ -7318,7 +7491,6 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
7318
7491
  internalDrag: ({
7319
7492
  event
7320
7493
  }) => ({
7321
- ghost: event.ghost,
7322
7494
  origin: event.origin
7323
7495
  })
7324
7496
  })],
@@ -7368,13 +7540,15 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
7368
7540
  }, ({
7369
7541
  context
7370
7542
  }) => {
7371
- if (context.internalDrag?.ghost)
7543
+ if (context.dragGhost)
7372
7544
  try {
7373
- context.internalDrag.ghost.parentNode?.removeChild(context.internalDrag.ghost);
7545
+ context.dragGhost.parentNode?.removeChild(context.dragGhost);
7374
7546
  } catch (error) {
7375
- console.error(new Error(`Removing the internal drag ghost failed due to: ${error.message}`));
7547
+ console.error(new Error(`Removing the drag ghost failed due to: ${error.message}`));
7376
7548
  }
7377
7549
  }, xstate.assign({
7550
+ dragGhost: void 0
7551
+ }), xstate.assign({
7378
7552
  internalDrag: void 0
7379
7553
  })],
7380
7554
  tags: ["dragging internally"],
@@ -8409,7 +8583,7 @@ function validateValue(value, types2, keyGenerator) {
8409
8583
  }
8410
8584
  }, !0;
8411
8585
  }
8412
- return !blk._type && util_sliceBlocks.isTextBlock({
8586
+ return !blk._type && selectionPoint.isTextBlock({
8413
8587
  schema: types2
8414
8588
  }, {
8415
8589
  ...blk,
@@ -10574,7 +10748,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10574
10748
  type: "behavior event",
10575
10749
  behaviorEvent: {
10576
10750
  type: "insert.blocks",
10577
- blocks: util_sliceBlocks.parseBlocks({
10751
+ blocks: selectionPoint.parseBlocks({
10578
10752
  context: {
10579
10753
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
10580
10754
  schema: editorActor.getSnapshot().context.schema
@@ -10755,73 +10929,19 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10755
10929
  console.warn("Could not find position for dragstart event");
10756
10930
  return;
10757
10931
  }
10758
- const snapshot = getEditorSnapshot({
10759
- editorActorSnapshot: editorActor.getSnapshot(),
10760
- slateEditorInstance: slateEditor
10761
- }), dragSelection = getDragSelection({
10762
- eventSelection: position_4.selection,
10763
- snapshot
10764
- }), selectingEntireBlocks = selector_isSelectingEntireBlocks.isSelectingEntireBlocks({
10765
- context: {
10766
- ...snapshot.context,
10767
- selection: dragSelection
10768
- }
10769
- }), dragGhost = document.createElement("div"), draggedDomNodes = getSelectionDomNodes({
10770
- snapshot: {
10771
- context: {
10772
- ...snapshot.context,
10773
- selection: dragSelection
10774
- }
10775
- },
10776
- slateEditor
10777
- });
10778
- if (selectingEntireBlocks) {
10779
- const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) => node.cloneNode(!0));
10780
- for (const block of clonedBlockNodes)
10781
- block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
10782
- const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
10783
- if (customGhost && dragGhost.replaceChildren(customGhost), dragGhost.setAttribute("data-dragged", ""), dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost), customGhost) {
10784
- const customGhostRect = customGhost.getBoundingClientRect(), x = event_8.clientX - customGhostRect.left, y = event_8.clientY - customGhostRect.top;
10785
- dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x, y);
10786
- } else {
10787
- const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x_0 = event_8.clientX - blocksDomRect.left, y_0 = event_8.clientY - blocksDomRect.top;
10788
- dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_0, y_0);
10789
- }
10790
- } else {
10791
- const clonedChildNodes = draggedDomNodes.childNodes.map((node_0) => node_0.cloneNode(!0));
10792
- for (const child of clonedChildNodes)
10793
- dragGhost.appendChild(child);
10794
- dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
10795
- const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
10796
- dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
10797
- }
10798
10932
  return editorActor.send({
10799
- type: "behavior event",
10800
- behaviorEvent: {
10801
- type: "select",
10802
- at: util_selectionPointToBlockOffset.isSelectionCollapsed(dragSelection) ? dragSelection : {
10803
- anchor: util_selectionPointToBlockOffset.getSelectionEndPoint(dragSelection),
10804
- focus: util_selectionPointToBlockOffset.getSelectionEndPoint(dragSelection),
10805
- backward: !1
10806
- }
10807
- },
10808
- editor: slateEditor
10809
- }), editorActor.send({
10810
10933
  type: "dragstart",
10811
- origin: {
10812
- selection: dragSelection
10813
- },
10814
- ghost: dragGhost
10934
+ origin: position_4
10815
10935
  }), editorActor.send({
10816
10936
  type: "behavior event",
10817
10937
  behaviorEvent: {
10818
10938
  type: "drag.dragstart",
10819
10939
  originEvent: {
10940
+ clientX: event_8.clientX,
10941
+ clientY: event_8.clientY,
10820
10942
  dataTransfer: event_8.dataTransfer
10821
10943
  },
10822
- position: {
10823
- selection: dragSelection
10824
- }
10944
+ position: position_4
10825
10945
  },
10826
10946
  editor: slateEditor
10827
10947
  }), !0;
@@ -10889,6 +11009,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10889
11009
  originEvent: {
10890
11010
  dataTransfer: event_12.dataTransfer
10891
11011
  },
11012
+ dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
10892
11013
  position: position_7
10893
11014
  },
10894
11015
  editor: slateEditor,
@@ -10913,6 +11034,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10913
11034
  originEvent: {
10914
11035
  dataTransfer: event_13.dataTransfer
10915
11036
  },
11037
+ dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
10916
11038
  position: position_8
10917
11039
  },
10918
11040
  editor: slateEditor,