@portabletext/editor 1.51.0 → 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 (37) hide show
  1. package/lib/_chunks-es/selector.is-selection-expanded.js +1 -1
  2. package/lib/behaviors/index.cjs.map +1 -1
  3. package/lib/behaviors/index.d.cts +26 -5
  4. package/lib/behaviors/index.d.ts +26 -5
  5. package/lib/behaviors/index.js.map +1 -1
  6. package/lib/index.cjs +434 -309
  7. package/lib/index.cjs.map +1 -1
  8. package/lib/index.d.cts +360 -31
  9. package/lib/index.d.ts +360 -31
  10. package/lib/index.js +455 -330
  11. package/lib/index.js.map +1 -1
  12. package/lib/plugins/index.d.cts +26 -5
  13. package/lib/plugins/index.d.ts +26 -5
  14. package/lib/selectors/index.d.cts +0 -14
  15. package/lib/selectors/index.d.ts +0 -14
  16. package/lib/utils/index.d.cts +0 -14
  17. package/lib/utils/index.d.ts +0 -14
  18. package/package.json +3 -3
  19. package/src/behaviors/behavior.abstract.delete.ts +0 -1
  20. package/src/behaviors/behavior.abstract.ts +0 -113
  21. package/src/behaviors/behavior.core.block-element.ts +9 -3
  22. package/src/behaviors/behavior.core.dnd.ts +328 -1
  23. package/src/behaviors/behavior.perform-event.ts +10 -0
  24. package/src/behaviors/behavior.types.action.ts +2 -0
  25. package/src/behaviors/behavior.types.event.ts +4 -0
  26. package/src/behaviors/behavior.types.guard.ts +2 -0
  27. package/src/converters/converter.portable-text.ts +2 -7
  28. package/src/converters/converter.text-html.ts +1 -3
  29. package/src/converters/converter.text-plain.ts +3 -5
  30. package/src/editor/Editable.tsx +6 -133
  31. package/src/editor/editor-machine.ts +15 -8
  32. package/src/editor/editor-selector.ts +0 -1
  33. package/src/editor/editor-snapshot.ts +0 -13
  34. package/src/internal-utils/create-test-snapshot.ts +0 -1
  35. package/src/internal-utils/event-position.ts +41 -27
  36. package/src/internal-utils/selection-elements.ts +108 -0
  37. package/src/operations/behavior.operation.decorator.add.ts +0 -1
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"), selectionPoint = require("./_chunks-cjs/selection-point.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: selectionPoint.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 = selectionPoint.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
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 focusBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(selection.focus);
512
- if (focusBlockKey !== void 0)
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
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
  },
@@ -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",
@@ -1220,11 +1184,7 @@ const converterJson = {
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.internalDrag,
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",
@@ -1319,7 +1279,7 @@ 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
1285
  data: selectionPoint.sliceBlocks({
@@ -1328,7 +1288,7 @@ function createConverterTextPlain(legacySchema) {
1328
1288
  schema: snapshot.context.schema
1329
1289
  },
1330
1290
  blocks: snapshot.context.value
1331
- }).map((block) => selectionPoint.isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.internalDrag ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.internalDrag ? `[${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",
@@ -1563,8 +1523,7 @@ function getEditorSnapshot({
1563
1523
  decoratorState: slateEditorInstance.decoratorState,
1564
1524
  markState: slateEditorInstance.markState,
1565
1525
  schema: editorActorSnapshot.context.schema
1566
- }),
1567
- internalDrag: editorActorSnapshot.context.internalDrag
1526
+ })
1568
1527
  }
1569
1528
  };
1570
1529
  }
@@ -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",
@@ -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,
@@ -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
@@ -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,8 +7186,7 @@ function createEditorSnapshot({
7015
7186
  editor,
7016
7187
  keyGenerator,
7017
7188
  readOnly,
7018
- schema: schema2,
7019
- internalDrag
7189
+ schema: schema2
7020
7190
  }) {
7021
7191
  const selection = editor.selection ? slateRangeToSelection({
7022
7192
  schema: schema2,
@@ -7041,8 +7211,7 @@ function createEditorSnapshot({
7041
7211
  decoratorState: editor.decoratorState,
7042
7212
  markState: editor.markState,
7043
7213
  schema: schema2
7044
- }),
7045
- internalDrag
7214
+ })
7046
7215
  }
7047
7216
  };
7048
7217
  }
@@ -7164,10 +7333,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
7164
7333
  readOnly: self.getSnapshot().matches({
7165
7334
  "edit mode": "read only"
7166
7335
  }),
7167
- schema: context.schema,
7168
- internalDrag: context.internalDrag
7336
+ schema: context.schema
7169
7337
  }),
7170
- nativeEvent: event.nativeEvent
7338
+ nativeEvent: event.nativeEvent,
7339
+ sendBack: (event2) => self.send(event2)
7171
7340
  });
7172
7341
  } catch (error) {
7173
7342
  console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`));
@@ -7221,6 +7390,13 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
7221
7390
  ...event,
7222
7391
  type: "selection"
7223
7392
  }))]
7393
+ },
7394
+ "set drag ghost": {
7395
+ actions: xstate.assign({
7396
+ dragGhost: ({
7397
+ event
7398
+ }) => event.ghost
7399
+ })
7224
7400
  }
7225
7401
  },
7226
7402
  type: "parallel",
@@ -7315,7 +7491,6 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
7315
7491
  internalDrag: ({
7316
7492
  event
7317
7493
  }) => ({
7318
- ghost: event.ghost,
7319
7494
  origin: event.origin
7320
7495
  })
7321
7496
  })],
@@ -7365,13 +7540,15 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
7365
7540
  }, ({
7366
7541
  context
7367
7542
  }) => {
7368
- if (context.internalDrag?.ghost)
7543
+ if (context.dragGhost)
7369
7544
  try {
7370
- context.internalDrag.ghost.parentNode?.removeChild(context.internalDrag.ghost);
7545
+ context.dragGhost.parentNode?.removeChild(context.dragGhost);
7371
7546
  } catch (error) {
7372
- 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}`));
7373
7548
  }
7374
7549
  }, xstate.assign({
7550
+ dragGhost: void 0
7551
+ }), xstate.assign({
7375
7552
  internalDrag: void 0
7376
7553
  })],
7377
7554
  tags: ["dragging internally"],
@@ -10752,73 +10929,19 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10752
10929
  console.warn("Could not find position for dragstart event");
10753
10930
  return;
10754
10931
  }
10755
- const snapshot = getEditorSnapshot({
10756
- editorActorSnapshot: editorActor.getSnapshot(),
10757
- slateEditorInstance: slateEditor
10758
- }), dragSelection = getDragSelection({
10759
- eventSelection: position_4.selection,
10760
- snapshot
10761
- }), selectingEntireBlocks = selector_isSelectingEntireBlocks.isSelectingEntireBlocks({
10762
- context: {
10763
- ...snapshot.context,
10764
- selection: dragSelection
10765
- }
10766
- }), dragGhost = document.createElement("div"), draggedDomNodes = getSelectionDomNodes({
10767
- snapshot: {
10768
- context: {
10769
- ...snapshot.context,
10770
- selection: dragSelection
10771
- }
10772
- },
10773
- slateEditor
10774
- });
10775
- if (selectingEntireBlocks) {
10776
- const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) => node.cloneNode(!0));
10777
- for (const block of clonedBlockNodes)
10778
- block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
10779
- const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
10780
- 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) {
10781
- const customGhostRect = customGhost.getBoundingClientRect(), x = event_8.clientX - customGhostRect.left, y = event_8.clientY - customGhostRect.top;
10782
- dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x, y);
10783
- } else {
10784
- const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x_0 = event_8.clientX - blocksDomRect.left, y_0 = event_8.clientY - blocksDomRect.top;
10785
- dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_0, y_0);
10786
- }
10787
- } else {
10788
- const clonedChildNodes = draggedDomNodes.childNodes.map((node_0) => node_0.cloneNode(!0));
10789
- for (const child of clonedChildNodes)
10790
- dragGhost.appendChild(child);
10791
- dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
10792
- const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
10793
- dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
10794
- }
10795
10932
  return editorActor.send({
10796
- type: "behavior event",
10797
- behaviorEvent: {
10798
- type: "select",
10799
- at: util_selectionPointToBlockOffset.isSelectionCollapsed(dragSelection) ? dragSelection : {
10800
- anchor: selectionPoint.getSelectionEndPoint(dragSelection),
10801
- focus: selectionPoint.getSelectionEndPoint(dragSelection),
10802
- backward: !1
10803
- }
10804
- },
10805
- editor: slateEditor
10806
- }), editorActor.send({
10807
10933
  type: "dragstart",
10808
- origin: {
10809
- selection: dragSelection
10810
- },
10811
- ghost: dragGhost
10934
+ origin: position_4
10812
10935
  }), editorActor.send({
10813
10936
  type: "behavior event",
10814
10937
  behaviorEvent: {
10815
10938
  type: "drag.dragstart",
10816
10939
  originEvent: {
10940
+ clientX: event_8.clientX,
10941
+ clientY: event_8.clientY,
10817
10942
  dataTransfer: event_8.dataTransfer
10818
10943
  },
10819
- position: {
10820
- selection: dragSelection
10821
- }
10944
+ position: position_4
10822
10945
  },
10823
10946
  editor: slateEditor
10824
10947
  }), !0;
@@ -10886,6 +11009,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10886
11009
  originEvent: {
10887
11010
  dataTransfer: event_12.dataTransfer
10888
11011
  },
11012
+ dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
10889
11013
  position: position_7
10890
11014
  },
10891
11015
  editor: slateEditor,
@@ -10910,6 +11034,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10910
11034
  originEvent: {
10911
11035
  dataTransfer: event_13.dataTransfer
10912
11036
  },
11037
+ dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
10913
11038
  position: position_8
10914
11039
  },
10915
11040
  editor: slateEditor,