@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.
- package/lib/_chunks-cjs/{util.slice-blocks.cjs → selection-point.cjs} +26 -18
- package/lib/_chunks-cjs/selection-point.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +13 -10
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +46 -46
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +21 -17
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +10 -10
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +5 -5
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +7 -14
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/{util.slice-blocks.js → selection-point.js} +26 -18
- package/lib/_chunks-es/selection-point.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +13 -10
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +21 -21
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +14 -10
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +2 -2
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +4 -11
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +25 -2010
- package/lib/behaviors/index.d.ts +25 -2010
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +515 -393
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +361 -34
- package/lib/index.d.ts +361 -34
- package/lib/index.js +471 -349
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +11 -11
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +32 -1986
- package/lib/plugins/index.d.ts +32 -1986
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +11 -7
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2 -2648
- package/lib/selectors/index.d.ts +2 -2648
- package/lib/selectors/index.js +7 -3
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +25 -14
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +0 -2647
- package/lib/utils/index.d.ts +0 -2647
- package/lib/utils/index.js +14 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +14 -14
- package/src/behaviors/behavior.abstract.delete.ts +0 -2
- package/src/behaviors/behavior.abstract.insert.ts +8 -8
- package/src/behaviors/behavior.abstract.ts +0 -113
- package/src/behaviors/behavior.core.block-element.ts +9 -3
- package/src/behaviors/behavior.core.dnd.ts +328 -1
- package/src/behaviors/behavior.perform-event.ts +10 -0
- package/src/behaviors/behavior.types.action.ts +2 -0
- package/src/behaviors/behavior.types.event.ts +5 -0
- package/src/behaviors/behavior.types.guard.ts +2 -0
- package/src/converters/converter.portable-text.ts +2 -7
- package/src/converters/converter.text-html.ts +1 -3
- package/src/converters/converter.text-plain.ts +3 -5
- package/src/editor/Editable.tsx +6 -133
- package/src/editor/editor-machine.ts +15 -10
- package/src/editor/editor-selector.ts +0 -2
- package/src/editor/editor-snapshot.ts +0 -18
- package/src/internal-utils/create-test-snapshot.ts +0 -2
- package/src/internal-utils/event-position.ts +42 -30
- package/src/internal-utils/selection-block-keys.ts +7 -7
- package/src/internal-utils/selection-elements.ts +108 -0
- package/src/internal-utils/selection-focus-text.ts +13 -9
- package/src/internal-utils/selection-text.ts +9 -78
- package/src/internal-utils/terse-pt.test.ts +108 -26
- package/src/internal-utils/terse-pt.ts +132 -14
- package/src/operations/behavior.operation.decorator.add.ts +0 -2
- package/src/operations/behavior.operation.delete.ts +18 -13
- package/src/operations/behavior.operation.insert.block.ts +5 -1
- package/src/selection/selection-point.ts +22 -0
- package/src/selectors/selector.get-anchor-block.ts +6 -6
- package/src/selectors/selector.get-anchor-child.ts +6 -6
- package/src/selectors/selector.get-selected-spans.ts +16 -19
- package/src/selectors/selector.get-selected-text-blocks.ts +11 -19
- package/src/selectors/selector.get-selection-end-block.ts +30 -0
- package/src/selectors/selector.get-selection-start-block.ts +30 -0
- package/src/selectors/selector.get-text-before.ts +15 -16
- package/src/selectors/selector.get-trimmed-selection.ts +15 -21
- package/src/selectors/selector.is-point-after-selection.ts +11 -19
- package/src/selectors/selector.is-point-before-selection.ts +11 -19
- package/src/selectors/selectors.ts +23 -39
- package/src/utils/util.block-offset.ts +6 -7
- package/src/utils/util.child-selection-point-to-block-offset.ts +6 -7
- package/src/utils/util.selection-point-to-block-offset.ts +5 -6
- package/src/utils/util.slice-blocks.ts +11 -20
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
- package/src/internal-utils/inline-object-selection.ts +0 -115
package/lib/index.js
CHANGED
|
@@ -8,16 +8,16 @@ import noop from "lodash/noop.js";
|
|
|
8
8
|
import { Element as Element$1, Text, Range, Editor, Node, Point, Transforms, Path, Operation, createEditor } from "slate";
|
|
9
9
|
import { useSlateStatic, useSelected, withReact, ReactEditor, Slate, useSlate, Editable } from "slate-react";
|
|
10
10
|
import debug$h from "debug";
|
|
11
|
-
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-equal-selection-points.js";
|
|
12
|
-
import { getBlockStartPoint, isKeyedSegment, parseInlineObject, parseTextBlock, parseBlockObject, parseBlock, sliceBlocks, isTextBlock, parseAnnotation, blockOffsetToSpanSelectionPoint, isSpan$1 as isSpan, isListBlock, isTypedObject, getTextBlockText, parseBlocks } from "./_chunks-es/util.slice-blocks.js";
|
|
13
|
-
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan as getFocusSpan$1, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, getFocusBlock as getFocusBlock$1, getFocusBlockObject, getPreviousBlock, getNextBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock } from "./_chunks-es/selector.is-selection-expanded.js";
|
|
14
|
-
import { getFocusInlineObject, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getCaretWordSelection, isAtTheEndOfBlock, isAtTheStartOfBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations as getActiveAnnotations$1 } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
15
11
|
import { DOMEditor, isDOMNode } from "slate-dom";
|
|
16
|
-
import {
|
|
12
|
+
import { getBlockStartPoint, getBlockKeyFromSelectionPoint, parseInlineObject, parseTextBlock, parseBlockObject, parseBlock, sliceBlocks, isTextBlock, parseAnnotation, blockOffsetToSpanSelectionPoint, isKeyedSegment, isSpan$1 as isSpan, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText, parseBlocks } from "./_chunks-es/selection-point.js";
|
|
13
|
+
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-equal-selection-points.js";
|
|
14
|
+
import { isSelectionCollapsed, selectionPointToBlockOffset } from "./_chunks-es/util.selection-point-to-block-offset.js";
|
|
17
15
|
import isEqual from "lodash/isEqual.js";
|
|
18
16
|
import { isKeySegment, defineType, defineField, isPortableTextSpan as isPortableTextSpan$1 } from "@sanity/types";
|
|
17
|
+
import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, getFocusBlock as getFocusBlock$1, getFocusBlockObject, getPreviousBlock, getNextBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock } from "./_chunks-es/selector.is-selection-expanded.js";
|
|
18
|
+
import { getFocusInlineObject, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getCaretWordSelection, isAtTheEndOfBlock, isAtTheStartOfBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations as getActiveAnnotations$1 } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
19
19
|
import getRandomValues from "get-random-values-esm";
|
|
20
|
-
import { defineBehavior, forward, raise } from "./behaviors/index.js";
|
|
20
|
+
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
21
21
|
import uniq from "lodash/uniq.js";
|
|
22
22
|
import { Subject } from "rxjs";
|
|
23
23
|
import { setup, assign, enqueueActions, emit, assertEvent, stateIn, fromCallback, and, not, raise as raise$1, createActor } from "xstate";
|
|
@@ -46,91 +46,12 @@ function EditorEventListener(props) {
|
|
|
46
46
|
let t1;
|
|
47
47
|
return $[3] !== editor ? (t1 = [editor], $[3] = editor, $[4] = t1) : t1 = $[4], useEffect(t0, t1), null;
|
|
48
48
|
}
|
|
49
|
-
function getCompoundClientRect(nodes) {
|
|
50
|
-
if (nodes.length === 0)
|
|
51
|
-
return new DOMRect(0, 0, 0, 0);
|
|
52
|
-
const elements = nodes.filter((node) => node instanceof Element), firstRect = elements.at(0)?.getBoundingClientRect();
|
|
53
|
-
if (!firstRect)
|
|
54
|
-
return new DOMRect(0, 0, 0, 0);
|
|
55
|
-
let left = firstRect.left, top = firstRect.top, right = firstRect.right, bottom = firstRect.bottom;
|
|
56
|
-
for (let i = 1; i < elements.length; i++) {
|
|
57
|
-
const rect = elements[i].getBoundingClientRect();
|
|
58
|
-
left = Math.min(left, rect.left), top = Math.min(top, rect.top), right = Math.max(right, rect.right), bottom = Math.max(bottom, rect.bottom);
|
|
59
|
-
}
|
|
60
|
-
return new DOMRect(left, top, right - left, bottom - top);
|
|
61
|
-
}
|
|
62
49
|
const rootName = "sanity-pte:";
|
|
63
50
|
debug$h(rootName);
|
|
64
51
|
function debugWithName(name) {
|
|
65
52
|
const namespace = `${rootName}${name}`;
|
|
66
53
|
return debug$h && debug$h.enabled(namespace) ? debug$h(namespace) : debug$h(rootName);
|
|
67
54
|
}
|
|
68
|
-
function getDragSelection({
|
|
69
|
-
eventSelection,
|
|
70
|
-
snapshot
|
|
71
|
-
}) {
|
|
72
|
-
let dragSelection = eventSelection;
|
|
73
|
-
if (getFocusInlineObject({
|
|
74
|
-
context: {
|
|
75
|
-
...snapshot.context,
|
|
76
|
-
selection: eventSelection
|
|
77
|
-
}
|
|
78
|
-
}))
|
|
79
|
-
return dragSelection;
|
|
80
|
-
const draggingCollapsedSelection = isSelectionCollapsed({
|
|
81
|
-
context: {
|
|
82
|
-
...snapshot.context,
|
|
83
|
-
selection: eventSelection
|
|
84
|
-
}
|
|
85
|
-
}), draggedTextBlock = getFocusTextBlock({
|
|
86
|
-
context: {
|
|
87
|
-
...snapshot.context,
|
|
88
|
-
selection: eventSelection
|
|
89
|
-
}
|
|
90
|
-
}), draggedSpan = getFocusSpan$1({
|
|
91
|
-
context: {
|
|
92
|
-
...snapshot.context,
|
|
93
|
-
selection: eventSelection
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
draggingCollapsedSelection && draggedTextBlock && draggedSpan && (dragSelection = {
|
|
97
|
-
anchor: getBlockStartPoint({
|
|
98
|
-
context: snapshot.context,
|
|
99
|
-
block: draggedTextBlock
|
|
100
|
-
}),
|
|
101
|
-
focus: getBlockEndPoint({
|
|
102
|
-
context: snapshot.context,
|
|
103
|
-
block: draggedTextBlock
|
|
104
|
-
})
|
|
105
|
-
});
|
|
106
|
-
const selectedBlocks = getSelectedBlocks(snapshot);
|
|
107
|
-
if (snapshot.context.selection && isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
108
|
-
const selectionStartBlock = getSelectionStartBlock$1(snapshot), selectionEndBlock = getSelectionEndBlock$1(snapshot);
|
|
109
|
-
if (!selectionStartBlock || !selectionEndBlock)
|
|
110
|
-
return dragSelection;
|
|
111
|
-
const selectionStartPoint = getBlockStartPoint({
|
|
112
|
-
context: snapshot.context,
|
|
113
|
-
block: selectionStartBlock
|
|
114
|
-
}), selectionEndPoint = getBlockEndPoint({
|
|
115
|
-
context: snapshot.context,
|
|
116
|
-
block: selectionEndBlock
|
|
117
|
-
});
|
|
118
|
-
isOverlappingSelection(eventSelection)({
|
|
119
|
-
...snapshot,
|
|
120
|
-
context: {
|
|
121
|
-
...snapshot.context,
|
|
122
|
-
selection: {
|
|
123
|
-
anchor: selectionStartPoint,
|
|
124
|
-
focus: selectionEndPoint
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}) && (dragSelection = {
|
|
128
|
-
anchor: selectionStartPoint,
|
|
129
|
-
focus: selectionEndPoint
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return dragSelection;
|
|
133
|
-
}
|
|
134
55
|
const VOID_CHILD_KEY = "void-child";
|
|
135
56
|
function keepObjectEquality(object, keyMap) {
|
|
136
57
|
const value = keyMap[object._key];
|
|
@@ -491,81 +412,81 @@ function getEventPosition({
|
|
|
491
412
|
setup: "setting up"
|
|
492
413
|
}))
|
|
493
414
|
return;
|
|
494
|
-
const
|
|
415
|
+
const eventNode = getEventNode({
|
|
495
416
|
slateEditor,
|
|
496
417
|
event
|
|
497
418
|
});
|
|
498
|
-
if (!
|
|
419
|
+
if (!eventNode)
|
|
499
420
|
return;
|
|
500
|
-
const
|
|
421
|
+
const eventBlock = getNodeBlock({
|
|
501
422
|
editor: slateEditor,
|
|
502
423
|
schema: editorActor.getSnapshot().context.schema,
|
|
503
|
-
node
|
|
504
|
-
}),
|
|
505
|
-
node,
|
|
424
|
+
node: eventNode
|
|
425
|
+
}), eventPositionBlock = getEventPositionBlock({
|
|
426
|
+
node: eventNode,
|
|
506
427
|
slateEditor,
|
|
507
428
|
event
|
|
508
|
-
}),
|
|
429
|
+
}), eventSelection = getEventSelection({
|
|
509
430
|
schema: editorActor.getSnapshot().context.schema,
|
|
510
431
|
slateEditor,
|
|
511
432
|
event
|
|
512
433
|
});
|
|
513
|
-
if (
|
|
434
|
+
if (eventBlock && eventPositionBlock && !eventSelection && !Editor.isEditor(eventNode))
|
|
514
435
|
return {
|
|
515
|
-
block:
|
|
436
|
+
block: eventPositionBlock,
|
|
516
437
|
isEditor: !1,
|
|
517
438
|
selection: {
|
|
518
439
|
anchor: getBlockStartPoint({
|
|
519
440
|
context: editorActor.getSnapshot().context,
|
|
520
441
|
block: {
|
|
521
|
-
node:
|
|
442
|
+
node: eventBlock,
|
|
522
443
|
path: [{
|
|
523
|
-
_key:
|
|
444
|
+
_key: eventBlock._key
|
|
524
445
|
}]
|
|
525
446
|
}
|
|
526
447
|
}),
|
|
527
448
|
focus: getBlockEndPoint({
|
|
528
449
|
context: editorActor.getSnapshot().context,
|
|
529
450
|
block: {
|
|
530
|
-
node:
|
|
451
|
+
node: eventBlock,
|
|
531
452
|
path: [{
|
|
532
|
-
_key:
|
|
453
|
+
_key: eventBlock._key
|
|
533
454
|
}]
|
|
534
455
|
}
|
|
535
456
|
})
|
|
536
457
|
}
|
|
537
458
|
};
|
|
538
|
-
if (!
|
|
459
|
+
if (!eventPositionBlock || !eventSelection)
|
|
539
460
|
return;
|
|
540
|
-
const
|
|
541
|
-
if (
|
|
542
|
-
return isSelectionCollapsed
|
|
543
|
-
block:
|
|
461
|
+
const eventSelectionFocusBlockKey = getBlockKeyFromSelectionPoint(eventSelection.focus);
|
|
462
|
+
if (eventSelectionFocusBlockKey !== void 0)
|
|
463
|
+
return isSelectionCollapsed(eventSelection) && eventBlock && eventSelectionFocusBlockKey !== eventBlock._key ? {
|
|
464
|
+
block: eventPositionBlock,
|
|
544
465
|
isEditor: !1,
|
|
545
466
|
selection: {
|
|
546
467
|
anchor: getBlockStartPoint({
|
|
547
468
|
context: editorActor.getSnapshot().context,
|
|
548
469
|
block: {
|
|
549
|
-
node:
|
|
470
|
+
node: eventBlock,
|
|
550
471
|
path: [{
|
|
551
|
-
_key:
|
|
472
|
+
_key: eventBlock._key
|
|
552
473
|
}]
|
|
553
474
|
}
|
|
554
475
|
}),
|
|
555
476
|
focus: getBlockEndPoint({
|
|
556
477
|
context: editorActor.getSnapshot().context,
|
|
557
478
|
block: {
|
|
558
|
-
node:
|
|
479
|
+
node: eventBlock,
|
|
559
480
|
path: [{
|
|
560
|
-
_key:
|
|
481
|
+
_key: eventBlock._key
|
|
561
482
|
}]
|
|
562
483
|
}
|
|
563
484
|
})
|
|
564
485
|
}
|
|
565
486
|
} : {
|
|
566
|
-
block:
|
|
567
|
-
isEditor: Editor.isEditor(
|
|
568
|
-
selection
|
|
487
|
+
block: eventPositionBlock,
|
|
488
|
+
isEditor: Editor.isEditor(eventNode),
|
|
489
|
+
selection: eventSelection
|
|
569
490
|
};
|
|
570
491
|
}
|
|
571
492
|
function getEventNode({
|
|
@@ -729,35 +650,6 @@ function normalizeSelection(selection, value) {
|
|
|
729
650
|
backward: selection.backward
|
|
730
651
|
} : null;
|
|
731
652
|
}
|
|
732
|
-
function getSelectionDomNodes({
|
|
733
|
-
slateEditor,
|
|
734
|
-
snapshot
|
|
735
|
-
}) {
|
|
736
|
-
if (!snapshot.context.selection)
|
|
737
|
-
return {
|
|
738
|
-
blockNodes: [],
|
|
739
|
-
childNodes: []
|
|
740
|
-
};
|
|
741
|
-
const range = toSlateRange(snapshot.context.selection, slateEditor);
|
|
742
|
-
if (!range)
|
|
743
|
-
return {
|
|
744
|
-
blockNodes: [],
|
|
745
|
-
childNodes: []
|
|
746
|
-
};
|
|
747
|
-
const blockEntries = Array.from(Editor.nodes(slateEditor, {
|
|
748
|
-
at: range,
|
|
749
|
-
mode: "highest",
|
|
750
|
-
match: (n) => !Editor.isEditor(n)
|
|
751
|
-
})), childEntries = Array.from(Editor.nodes(slateEditor, {
|
|
752
|
-
at: range,
|
|
753
|
-
mode: "lowest",
|
|
754
|
-
match: (n) => !Editor.isEditor(n) && slateEditor.isTextSpan(n) || !slateEditor.isBlock(n)
|
|
755
|
-
}));
|
|
756
|
-
return {
|
|
757
|
-
blockNodes: blockEntries.map(([blockNode]) => DOMEditor.toDOMNode(slateEditor, blockNode)),
|
|
758
|
-
childNodes: childEntries.map(([childNode]) => DOMEditor.toDOMNode(slateEditor, childNode))
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
653
|
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 = createContext({});
|
|
762
654
|
function DropIndicator() {
|
|
763
655
|
const $ = c(1);
|
|
@@ -800,6 +692,72 @@ function RenderDefaultInlineObject(props) {
|
|
|
800
692
|
"]"
|
|
801
693
|
] }), $[1] = props.inlineObject._key, $[2] = props.inlineObject._type, $[3] = t1) : t1 = $[3], t1;
|
|
802
694
|
}
|
|
695
|
+
function getDragSelection({
|
|
696
|
+
eventSelection,
|
|
697
|
+
snapshot
|
|
698
|
+
}) {
|
|
699
|
+
let dragSelection = eventSelection;
|
|
700
|
+
if (getFocusInlineObject({
|
|
701
|
+
context: {
|
|
702
|
+
...snapshot.context,
|
|
703
|
+
selection: eventSelection
|
|
704
|
+
}
|
|
705
|
+
}))
|
|
706
|
+
return dragSelection;
|
|
707
|
+
const draggingCollapsedSelection = isSelectionCollapsed$1({
|
|
708
|
+
context: {
|
|
709
|
+
...snapshot.context,
|
|
710
|
+
selection: eventSelection
|
|
711
|
+
}
|
|
712
|
+
}), draggedTextBlock = getFocusTextBlock({
|
|
713
|
+
context: {
|
|
714
|
+
...snapshot.context,
|
|
715
|
+
selection: eventSelection
|
|
716
|
+
}
|
|
717
|
+
}), draggedSpan = getFocusSpan$1({
|
|
718
|
+
context: {
|
|
719
|
+
...snapshot.context,
|
|
720
|
+
selection: eventSelection
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
draggingCollapsedSelection && draggedTextBlock && draggedSpan && (dragSelection = {
|
|
724
|
+
anchor: getBlockStartPoint({
|
|
725
|
+
context: snapshot.context,
|
|
726
|
+
block: draggedTextBlock
|
|
727
|
+
}),
|
|
728
|
+
focus: getBlockEndPoint({
|
|
729
|
+
context: snapshot.context,
|
|
730
|
+
block: draggedTextBlock
|
|
731
|
+
})
|
|
732
|
+
});
|
|
733
|
+
const selectedBlocks = getSelectedBlocks(snapshot);
|
|
734
|
+
if (snapshot.context.selection && isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
735
|
+
const selectionStartBlock = getSelectionStartBlock$1(snapshot), selectionEndBlock = getSelectionEndBlock$1(snapshot);
|
|
736
|
+
if (!selectionStartBlock || !selectionEndBlock)
|
|
737
|
+
return dragSelection;
|
|
738
|
+
const selectionStartPoint = getBlockStartPoint({
|
|
739
|
+
context: snapshot.context,
|
|
740
|
+
block: selectionStartBlock
|
|
741
|
+
}), selectionEndPoint = getBlockEndPoint({
|
|
742
|
+
context: snapshot.context,
|
|
743
|
+
block: selectionEndBlock
|
|
744
|
+
});
|
|
745
|
+
isOverlappingSelection(eventSelection)({
|
|
746
|
+
...snapshot,
|
|
747
|
+
context: {
|
|
748
|
+
...snapshot.context,
|
|
749
|
+
selection: {
|
|
750
|
+
anchor: selectionStartPoint,
|
|
751
|
+
focus: selectionEndPoint
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}) && (dragSelection = {
|
|
755
|
+
anchor: selectionStartPoint,
|
|
756
|
+
focus: selectionEndPoint
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
return dragSelection;
|
|
760
|
+
}
|
|
803
761
|
const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
|
|
804
762
|
let table;
|
|
805
763
|
return () => {
|
|
@@ -848,16 +806,22 @@ function createCoreBlockElementBehaviorsConfig({
|
|
|
848
806
|
});
|
|
849
807
|
if (!dropFocusBlock || dropFocusBlock.node._key !== key)
|
|
850
808
|
return !1;
|
|
851
|
-
const dragOrigin =
|
|
852
|
-
|
|
809
|
+
const dragOrigin = event.dragOrigin;
|
|
810
|
+
if (!dragOrigin)
|
|
811
|
+
return !1;
|
|
812
|
+
const dragSelection = getDragSelection({
|
|
813
|
+
eventSelection: dragOrigin.selection,
|
|
814
|
+
snapshot
|
|
815
|
+
});
|
|
816
|
+
return getSelectedBlocks({
|
|
853
817
|
context: {
|
|
854
818
|
...snapshot.context,
|
|
855
|
-
selection:
|
|
819
|
+
selection: dragSelection
|
|
856
820
|
}
|
|
857
821
|
}).some((draggedBlock) => draggedBlock.node._key === key) ? !1 : isSelectingEntireBlocks({
|
|
858
822
|
context: {
|
|
859
823
|
...snapshot.context,
|
|
860
|
-
selection:
|
|
824
|
+
selection: dragSelection
|
|
861
825
|
}
|
|
862
826
|
});
|
|
863
827
|
},
|
|
@@ -1206,7 +1170,7 @@ const converterJson = {
|
|
|
1206
1170
|
snapshot,
|
|
1207
1171
|
event
|
|
1208
1172
|
}) => {
|
|
1209
|
-
const selection = snapshot.
|
|
1173
|
+
const selection = snapshot.context.selection;
|
|
1210
1174
|
if (!selection)
|
|
1211
1175
|
return {
|
|
1212
1176
|
type: "serialization.failure",
|
|
@@ -1249,11 +1213,7 @@ const converterJson = {
|
|
|
1249
1213
|
context: snapshot.context,
|
|
1250
1214
|
block,
|
|
1251
1215
|
options: {
|
|
1252
|
-
|
|
1253
|
-
* If we are dragging internally then we would like to keep the
|
|
1254
|
-
* dropped portable text as is.
|
|
1255
|
-
*/
|
|
1256
|
-
refreshKeys: !snapshot.beta.hasTag?.("dragging internally"),
|
|
1216
|
+
refreshKeys: !0,
|
|
1257
1217
|
validateFields: !1
|
|
1258
1218
|
}
|
|
1259
1219
|
});
|
|
@@ -1277,7 +1237,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
1277
1237
|
snapshot,
|
|
1278
1238
|
event
|
|
1279
1239
|
}) => {
|
|
1280
|
-
const selection = snapshot.
|
|
1240
|
+
const selection = snapshot.context.selection;
|
|
1281
1241
|
if (!selection)
|
|
1282
1242
|
return {
|
|
1283
1243
|
type: "serialization.failure",
|
|
@@ -1348,7 +1308,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
1348
1308
|
snapshot,
|
|
1349
1309
|
event
|
|
1350
1310
|
}) => {
|
|
1351
|
-
const selection = snapshot.
|
|
1311
|
+
const selection = snapshot.context.selection;
|
|
1352
1312
|
return selection ? {
|
|
1353
1313
|
type: "serialization.success",
|
|
1354
1314
|
data: sliceBlocks({
|
|
@@ -1357,7 +1317,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
1357
1317
|
schema: snapshot.context.schema
|
|
1358
1318
|
},
|
|
1359
1319
|
blocks: snapshot.context.value
|
|
1360
|
-
}).map((block) => isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text :
|
|
1320
|
+
}).map((block) => 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(`
|
|
1361
1321
|
|
|
1362
1322
|
`),
|
|
1363
1323
|
mimeType: "text/plain",
|
|
@@ -1592,9 +1552,7 @@ function getEditorSnapshot({
|
|
|
1592
1552
|
decoratorState: slateEditorInstance.decoratorState,
|
|
1593
1553
|
markState: slateEditorInstance.markState,
|
|
1594
1554
|
schema: editorActorSnapshot.context.schema
|
|
1595
|
-
})
|
|
1596
|
-
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
1597
|
-
internalDrag: editorActorSnapshot.context.internalDrag
|
|
1555
|
+
})
|
|
1598
1556
|
}
|
|
1599
1557
|
};
|
|
1600
1558
|
}
|
|
@@ -3209,12 +3167,12 @@ const addAnnotationOperationImplementation = ({
|
|
|
3209
3167
|
}, deleteOperationImplementation = ({
|
|
3210
3168
|
operation
|
|
3211
3169
|
}) => {
|
|
3212
|
-
const
|
|
3170
|
+
const anchorBlockKey = getBlockKeyFromSelectionPoint(operation.at.anchor), focusBlockKey = getBlockKeyFromSelectionPoint(operation.at.focus), anchorBlockPath = anchorBlockKey !== void 0 ? getBlockPath({
|
|
3213
3171
|
editor: operation.editor,
|
|
3214
|
-
_key:
|
|
3215
|
-
}) : void 0, focusBlockPath =
|
|
3172
|
+
_key: anchorBlockKey
|
|
3173
|
+
}) : void 0, focusBlockPath = focusBlockKey !== void 0 ? getBlockPath({
|
|
3216
3174
|
editor: operation.editor,
|
|
3217
|
-
_key:
|
|
3175
|
+
_key: focusBlockKey
|
|
3218
3176
|
}) : void 0;
|
|
3219
3177
|
if (operation.at.anchor.path.length === 1 && operation.at.focus.path.length === 1 && anchorBlockPath && focusBlockPath && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
3220
3178
|
Transforms.removeNodes(operation.editor, {
|
|
@@ -3351,8 +3309,7 @@ function insertBlock({
|
|
|
3351
3309
|
else if (placement === "after") {
|
|
3352
3310
|
const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
|
|
3353
3311
|
Transforms.insertNodes(editor, [block], {
|
|
3354
|
-
at: nextPath
|
|
3355
|
-
select: !1
|
|
3312
|
+
at: nextPath
|
|
3356
3313
|
}), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
3357
3314
|
} else {
|
|
3358
3315
|
if (lastBlock && isEqualToEmptyEditor([lastBlock], schema)) {
|
|
@@ -3465,7 +3422,9 @@ function insertBlock({
|
|
|
3465
3422
|
editor
|
|
3466
3423
|
});
|
|
3467
3424
|
if (focusChild && editor.isTextSpan(focusChild))
|
|
3468
|
-
Transforms.
|
|
3425
|
+
Transforms.splitNodes(editor, {
|
|
3426
|
+
at: currentSelection2
|
|
3427
|
+
}), Transforms.insertFragment(editor, [block], {
|
|
3469
3428
|
at: currentSelection2
|
|
3470
3429
|
}), select === "start" || select === "end" ? Transforms.select(editor, [endBlockPath[0] + 1]) : Transforms.select(editor, currentSelection2);
|
|
3471
3430
|
else {
|
|
@@ -5203,7 +5162,7 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
5203
5162
|
guard: ({
|
|
5204
5163
|
snapshot
|
|
5205
5164
|
}) => {
|
|
5206
|
-
if (!isSelectionCollapsed(snapshot))
|
|
5165
|
+
if (!isSelectionCollapsed$1(snapshot))
|
|
5207
5166
|
return !1;
|
|
5208
5167
|
const caretWordSelection = getCaretWordSelection(snapshot);
|
|
5209
5168
|
return !caretWordSelection || !isSelectionExpanded({
|
|
@@ -5346,7 +5305,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5346
5305
|
snapshot,
|
|
5347
5306
|
event
|
|
5348
5307
|
}) => {
|
|
5349
|
-
if (!isHotkey("ArrowDown", event.originEvent) || !isSelectionCollapsed(snapshot))
|
|
5308
|
+
if (!isHotkey("ArrowDown", event.originEvent) || !isSelectionCollapsed$1(snapshot))
|
|
5350
5309
|
return !1;
|
|
5351
5310
|
const focusBlockObject = getFocusBlockObject(snapshot), nextBlock = getNextBlock(snapshot);
|
|
5352
5311
|
return focusBlockObject && !nextBlock;
|
|
@@ -5366,7 +5325,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5366
5325
|
snapshot,
|
|
5367
5326
|
event
|
|
5368
5327
|
}) => {
|
|
5369
|
-
if (!isHotkey("ArrowUp", event.originEvent) || !isSelectionCollapsed(snapshot))
|
|
5328
|
+
if (!isHotkey("ArrowUp", event.originEvent) || !isSelectionCollapsed$1(snapshot))
|
|
5370
5329
|
return !1;
|
|
5371
5330
|
const focusBlockObject = getFocusBlockObject(snapshot), previousBlock = getPreviousBlock(snapshot);
|
|
5372
5331
|
return focusBlockObject && !previousBlock;
|
|
@@ -5386,7 +5345,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5386
5345
|
snapshot
|
|
5387
5346
|
}) => {
|
|
5388
5347
|
const focusBlockObject = getFocusBlockObject(snapshot);
|
|
5389
|
-
return isSelectionCollapsed(snapshot) && focusBlockObject !== void 0;
|
|
5348
|
+
return isSelectionCollapsed$1(snapshot) && focusBlockObject !== void 0;
|
|
5390
5349
|
},
|
|
5391
5350
|
actions: [({
|
|
5392
5351
|
snapshot
|
|
@@ -5403,7 +5362,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5403
5362
|
snapshot,
|
|
5404
5363
|
event
|
|
5405
5364
|
}) => {
|
|
5406
|
-
if (snapshot.context.readOnly || snapshot.context.selection && !isSelectionCollapsed(snapshot))
|
|
5365
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !isSelectionCollapsed$1(snapshot))
|
|
5407
5366
|
return !1;
|
|
5408
5367
|
const focusBlockObject = getFocusBlockObject({
|
|
5409
5368
|
context: {
|
|
@@ -5438,7 +5397,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5438
5397
|
snapshot,
|
|
5439
5398
|
event
|
|
5440
5399
|
}) => {
|
|
5441
|
-
if (snapshot.context.readOnly || snapshot.context.selection && !isSelectionCollapsed(snapshot))
|
|
5400
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !isSelectionCollapsed$1(snapshot))
|
|
5442
5401
|
return !1;
|
|
5443
5402
|
const focusBlockObject = getFocusBlockObject({
|
|
5444
5403
|
context: {
|
|
@@ -5472,7 +5431,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5472
5431
|
guard: ({
|
|
5473
5432
|
snapshot
|
|
5474
5433
|
}) => {
|
|
5475
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot), previousBlock = getPreviousBlock(snapshot);
|
|
5434
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot), previousBlock = getPreviousBlock(snapshot);
|
|
5476
5435
|
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !isTextBlock(snapshot.context, previousBlock.node) ? {
|
|
5477
5436
|
focusTextBlock,
|
|
5478
5437
|
previousBlock
|
|
@@ -5502,7 +5461,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5502
5461
|
guard: ({
|
|
5503
5462
|
snapshot
|
|
5504
5463
|
}) => {
|
|
5505
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot), nextBlock = getNextBlock(snapshot);
|
|
5464
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot), nextBlock = getNextBlock(snapshot);
|
|
5506
5465
|
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !isTextBlock(snapshot.context, nextBlock.node) ? {
|
|
5507
5466
|
focusTextBlock,
|
|
5508
5467
|
nextBlock
|
|
@@ -5580,7 +5539,131 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5580
5539
|
decorator: "code"
|
|
5581
5540
|
})]]
|
|
5582
5541
|
})
|
|
5583
|
-
}
|
|
5542
|
+
};
|
|
5543
|
+
function getCompoundClientRect(nodes) {
|
|
5544
|
+
if (nodes.length === 0)
|
|
5545
|
+
return new DOMRect(0, 0, 0, 0);
|
|
5546
|
+
const elements = nodes.filter((node) => node instanceof Element), firstRect = elements.at(0)?.getBoundingClientRect();
|
|
5547
|
+
if (!firstRect)
|
|
5548
|
+
return new DOMRect(0, 0, 0, 0);
|
|
5549
|
+
let left = firstRect.left, top = firstRect.top, right = firstRect.right, bottom = firstRect.bottom;
|
|
5550
|
+
for (let i = 1; i < elements.length; i++) {
|
|
5551
|
+
const rect = elements[i].getBoundingClientRect();
|
|
5552
|
+
left = Math.min(left, rect.left), top = Math.min(top, rect.top), right = Math.max(right, rect.right), bottom = Math.max(bottom, rect.bottom);
|
|
5553
|
+
}
|
|
5554
|
+
return new DOMRect(left, top, right - left, bottom - top);
|
|
5555
|
+
}
|
|
5556
|
+
const coreDndBehaviors = [
|
|
5557
|
+
/**
|
|
5558
|
+
* Core Behavior that:
|
|
5559
|
+
* 1. Calculates and selects a "drag selection"
|
|
5560
|
+
* 2. Constructs and sets a drag ghost element
|
|
5561
|
+
* 3. Forwards the dragstart event
|
|
5562
|
+
*/
|
|
5563
|
+
defineBehavior({
|
|
5564
|
+
on: "drag.dragstart",
|
|
5565
|
+
guard: ({
|
|
5566
|
+
snapshot,
|
|
5567
|
+
dom,
|
|
5568
|
+
event
|
|
5569
|
+
}) => {
|
|
5570
|
+
const dragSelection = getDragSelection({
|
|
5571
|
+
snapshot,
|
|
5572
|
+
eventSelection: event.position.selection
|
|
5573
|
+
}), selectingEntireBlocks = isSelectingEntireBlocks({
|
|
5574
|
+
context: {
|
|
5575
|
+
...snapshot.context,
|
|
5576
|
+
selection: dragSelection
|
|
5577
|
+
}
|
|
5578
|
+
}), draggedDomNodes = {
|
|
5579
|
+
blockNodes: dom.getBlockNodes({
|
|
5580
|
+
...snapshot,
|
|
5581
|
+
context: {
|
|
5582
|
+
...snapshot.context,
|
|
5583
|
+
selection: dragSelection
|
|
5584
|
+
}
|
|
5585
|
+
}),
|
|
5586
|
+
childNodes: dom.getChildNodes({
|
|
5587
|
+
...snapshot,
|
|
5588
|
+
context: {
|
|
5589
|
+
...snapshot.context,
|
|
5590
|
+
selection: dragSelection
|
|
5591
|
+
}
|
|
5592
|
+
})
|
|
5593
|
+
};
|
|
5594
|
+
return {
|
|
5595
|
+
dragSelection,
|
|
5596
|
+
draggedDomNodes,
|
|
5597
|
+
selectingEntireBlocks
|
|
5598
|
+
};
|
|
5599
|
+
},
|
|
5600
|
+
actions: [({
|
|
5601
|
+
dom,
|
|
5602
|
+
event
|
|
5603
|
+
}, {
|
|
5604
|
+
dragSelection,
|
|
5605
|
+
draggedDomNodes,
|
|
5606
|
+
selectingEntireBlocks
|
|
5607
|
+
}) => {
|
|
5608
|
+
const dragGhost = document.createElement("div");
|
|
5609
|
+
if (selectingEntireBlocks) {
|
|
5610
|
+
const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) => node.cloneNode(!0));
|
|
5611
|
+
for (const block of clonedBlockNodes)
|
|
5612
|
+
block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
|
|
5613
|
+
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
5614
|
+
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) {
|
|
5615
|
+
const customGhostRect = customGhost.getBoundingClientRect(), x = event.originEvent.clientX - customGhostRect.left, y = event.originEvent.clientY - customGhostRect.top;
|
|
5616
|
+
return dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, [raise({
|
|
5617
|
+
type: "select",
|
|
5618
|
+
at: dragSelection
|
|
5619
|
+
}), effect(() => {
|
|
5620
|
+
dom.setDragGhost({
|
|
5621
|
+
event,
|
|
5622
|
+
ghost: {
|
|
5623
|
+
element: dragGhost,
|
|
5624
|
+
x,
|
|
5625
|
+
y
|
|
5626
|
+
}
|
|
5627
|
+
});
|
|
5628
|
+
}), forward(event)];
|
|
5629
|
+
} else {
|
|
5630
|
+
const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x = event.originEvent.clientX - blocksDomRect.left, y = event.originEvent.clientY - blocksDomRect.top;
|
|
5631
|
+
return dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, [raise({
|
|
5632
|
+
type: "select",
|
|
5633
|
+
at: dragSelection
|
|
5634
|
+
}), effect(() => {
|
|
5635
|
+
dom.setDragGhost({
|
|
5636
|
+
event,
|
|
5637
|
+
ghost: {
|
|
5638
|
+
element: dragGhost,
|
|
5639
|
+
x,
|
|
5640
|
+
y
|
|
5641
|
+
}
|
|
5642
|
+
});
|
|
5643
|
+
}), forward(event)];
|
|
5644
|
+
}
|
|
5645
|
+
} else {
|
|
5646
|
+
const clonedChildNodes = draggedDomNodes.childNodes.map((node) => node.cloneNode(!0));
|
|
5647
|
+
for (const child of clonedChildNodes)
|
|
5648
|
+
dragGhost.appendChild(child);
|
|
5649
|
+
dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
5650
|
+
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x = event.originEvent.clientX - childrenDomRect.left, y = event.originEvent.clientY - childrenDomRect.top;
|
|
5651
|
+
return dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, [raise({
|
|
5652
|
+
type: "select",
|
|
5653
|
+
at: dragSelection
|
|
5654
|
+
}), effect(() => {
|
|
5655
|
+
dom.setDragGhost({
|
|
5656
|
+
event,
|
|
5657
|
+
ghost: {
|
|
5658
|
+
element: dragGhost,
|
|
5659
|
+
x,
|
|
5660
|
+
y
|
|
5661
|
+
}
|
|
5662
|
+
});
|
|
5663
|
+
}), forward(event)];
|
|
5664
|
+
}
|
|
5665
|
+
}]
|
|
5666
|
+
}),
|
|
5584
5667
|
/**
|
|
5585
5668
|
* When dragging over the drag origin, we don't want to show the caret in the
|
|
5586
5669
|
* text.
|
|
@@ -5591,7 +5674,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5591
5674
|
snapshot,
|
|
5592
5675
|
event
|
|
5593
5676
|
}) => {
|
|
5594
|
-
const dragOrigin =
|
|
5677
|
+
const dragOrigin = event.dragOrigin;
|
|
5595
5678
|
return dragOrigin ? isOverlappingSelection(event.position.selection)({
|
|
5596
5679
|
...snapshot,
|
|
5597
5680
|
context: {
|
|
@@ -5601,13 +5684,128 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5601
5684
|
}) : !1;
|
|
5602
5685
|
},
|
|
5603
5686
|
actions: []
|
|
5687
|
+
}),
|
|
5688
|
+
/**
|
|
5689
|
+
* If the drop position overlaps the drag origin, then the event should be
|
|
5690
|
+
* cancelled.
|
|
5691
|
+
*/
|
|
5692
|
+
defineBehavior({
|
|
5693
|
+
on: "drag.drop",
|
|
5694
|
+
guard: ({
|
|
5695
|
+
snapshot,
|
|
5696
|
+
event
|
|
5697
|
+
}) => {
|
|
5698
|
+
const dragOrigin = event.dragOrigin, dropPosition = event.position.selection;
|
|
5699
|
+
return dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
5700
|
+
...snapshot,
|
|
5701
|
+
context: {
|
|
5702
|
+
...snapshot.context,
|
|
5703
|
+
selection: dragOrigin.selection
|
|
5704
|
+
}
|
|
5705
|
+
}) : !1;
|
|
5706
|
+
},
|
|
5707
|
+
actions: []
|
|
5708
|
+
}),
|
|
5709
|
+
/**
|
|
5710
|
+
* If we drop and have access to a drag origin, then we can deserialize
|
|
5711
|
+
* without creating a new selection.
|
|
5712
|
+
*/
|
|
5713
|
+
defineBehavior({
|
|
5714
|
+
on: "drag.drop",
|
|
5715
|
+
guard: ({
|
|
5716
|
+
event
|
|
5717
|
+
}) => event.dragOrigin !== void 0,
|
|
5718
|
+
actions: [({
|
|
5719
|
+
event
|
|
5720
|
+
}) => [raise({
|
|
5721
|
+
type: "deserialize",
|
|
5722
|
+
originEvent: event
|
|
5723
|
+
})]]
|
|
5724
|
+
}),
|
|
5725
|
+
/**
|
|
5726
|
+
* Otherwise, we should to create a new selection.
|
|
5727
|
+
*/
|
|
5728
|
+
defineBehavior({
|
|
5729
|
+
on: "drag.drop",
|
|
5730
|
+
actions: [({
|
|
5731
|
+
event
|
|
5732
|
+
}) => [raise({
|
|
5733
|
+
type: "select",
|
|
5734
|
+
at: event.position.selection
|
|
5735
|
+
}), raise({
|
|
5736
|
+
type: "deserialize",
|
|
5737
|
+
originEvent: event
|
|
5738
|
+
})]]
|
|
5739
|
+
}),
|
|
5740
|
+
/**
|
|
5741
|
+
* Core Behavior that uses the drag origin to mimic a move operation during
|
|
5742
|
+
* internal dragging.
|
|
5743
|
+
*/
|
|
5744
|
+
defineBehavior({
|
|
5745
|
+
on: "deserialization.success",
|
|
5746
|
+
guard: ({
|
|
5747
|
+
snapshot,
|
|
5748
|
+
event
|
|
5749
|
+
}) => {
|
|
5750
|
+
if (event.originEvent.type !== "drag.drop" || event.originEvent.dragOrigin === void 0)
|
|
5751
|
+
return !1;
|
|
5752
|
+
const dragOrigin = event.originEvent.dragOrigin, dragSelection = getDragSelection({
|
|
5753
|
+
eventSelection: dragOrigin.selection,
|
|
5754
|
+
snapshot
|
|
5755
|
+
}), dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
5756
|
+
...snapshot,
|
|
5757
|
+
context: {
|
|
5758
|
+
...snapshot.context,
|
|
5759
|
+
selection: dragSelection
|
|
5760
|
+
}
|
|
5761
|
+
}) : !1, draggingEntireBlocks = isSelectingEntireBlocks({
|
|
5762
|
+
context: {
|
|
5763
|
+
...snapshot.context,
|
|
5764
|
+
selection: dragSelection
|
|
5765
|
+
}
|
|
5766
|
+
}), draggedBlocks = getSelectedBlocks({
|
|
5767
|
+
context: {
|
|
5768
|
+
...snapshot.context,
|
|
5769
|
+
selection: dragSelection
|
|
5770
|
+
}
|
|
5771
|
+
});
|
|
5772
|
+
return droppingOnDragOrigin ? !1 : {
|
|
5773
|
+
dropPosition,
|
|
5774
|
+
draggingEntireBlocks,
|
|
5775
|
+
draggedBlocks,
|
|
5776
|
+
dragOrigin,
|
|
5777
|
+
originEvent: event.originEvent
|
|
5778
|
+
};
|
|
5779
|
+
},
|
|
5780
|
+
actions: [({
|
|
5781
|
+
event
|
|
5782
|
+
}, {
|
|
5783
|
+
draggingEntireBlocks,
|
|
5784
|
+
draggedBlocks,
|
|
5785
|
+
dragOrigin,
|
|
5786
|
+
dropPosition,
|
|
5787
|
+
originEvent
|
|
5788
|
+
}) => [...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
|
|
5789
|
+
type: "delete.block",
|
|
5790
|
+
at: block.path
|
|
5791
|
+
})) : [raise({
|
|
5792
|
+
type: "delete",
|
|
5793
|
+
at: dragOrigin.selection
|
|
5794
|
+
})], raise({
|
|
5795
|
+
type: "select",
|
|
5796
|
+
at: dropPosition
|
|
5797
|
+
}), raise({
|
|
5798
|
+
type: "insert.blocks",
|
|
5799
|
+
blocks: event.data,
|
|
5800
|
+
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
5801
|
+
})]]
|
|
5604
5802
|
})
|
|
5605
5803
|
], breakingAtTheEndOfTextBlock = defineBehavior({
|
|
5606
5804
|
on: "insert.break",
|
|
5607
5805
|
guard: ({
|
|
5608
5806
|
snapshot
|
|
5609
5807
|
}) => {
|
|
5610
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
5808
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
5611
5809
|
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
5612
5810
|
return !1;
|
|
5613
5811
|
const atTheEndOfBlock = isAtTheEndOfBlock(focusTextBlock)(snapshot), focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
@@ -5642,7 +5840,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5642
5840
|
guard: ({
|
|
5643
5841
|
snapshot
|
|
5644
5842
|
}) => {
|
|
5645
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
5843
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
5646
5844
|
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
5647
5845
|
return !1;
|
|
5648
5846
|
const focusSpan = getFocusSpan$1(snapshot), focusDecorators = focusSpan?.node.marks?.filter((mark) => snapshot.context.schema.decorators.some((decorator) => decorator.name === mark) ?? []), focusAnnotations = focusSpan?.node.marks?.filter((mark) => !snapshot.context.schema.decorators.some((decorator) => decorator.name === mark)) ?? [], focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
@@ -5754,7 +5952,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5754
5952
|
guard: ({
|
|
5755
5953
|
snapshot
|
|
5756
5954
|
}) => {
|
|
5757
|
-
const selectionCollapsed = isSelectionCollapsed(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5955
|
+
const selectionCollapsed = isSelectionCollapsed$1(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5758
5956
|
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
5759
5957
|
focusTextBlock
|
|
5760
5958
|
} : !1;
|
|
@@ -5771,7 +5969,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5771
5969
|
guard: ({
|
|
5772
5970
|
snapshot
|
|
5773
5971
|
}) => {
|
|
5774
|
-
const selectionCollapsed = isSelectionCollapsed(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5972
|
+
const selectionCollapsed = isSelectionCollapsed$1(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5775
5973
|
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
|
|
5776
5974
|
focusTextBlock,
|
|
5777
5975
|
level: focusTextBlock.node.level - 1
|
|
@@ -5792,7 +5990,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5792
5990
|
guard: ({
|
|
5793
5991
|
snapshot
|
|
5794
5992
|
}) => {
|
|
5795
|
-
const selectionCollapsed = isSelectionCollapsed(snapshot), focusListBlock = getFocusListBlock(snapshot);
|
|
5993
|
+
const selectionCollapsed = isSelectionCollapsed$1(snapshot), focusListBlock = getFocusListBlock(snapshot);
|
|
5796
5994
|
return !selectionCollapsed || !focusListBlock || !isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
|
|
5797
5995
|
focusListBlock
|
|
5798
5996
|
};
|
|
@@ -5863,7 +6061,52 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5863
6061
|
}, 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) => ({
|
|
5864
6062
|
behavior,
|
|
5865
6063
|
priority: corePriority
|
|
5866
|
-
}))
|
|
6064
|
+
}));
|
|
6065
|
+
function createEditorDom(sendBack, slateEditor) {
|
|
6066
|
+
return {
|
|
6067
|
+
getBlockNodes: (snapshot) => getBlockNodes(slateEditor, snapshot),
|
|
6068
|
+
getChildNodes: (snapshot) => getChildNodes(slateEditor, snapshot),
|
|
6069
|
+
setDragGhost: ({
|
|
6070
|
+
event,
|
|
6071
|
+
ghost
|
|
6072
|
+
}) => setDragGhost({
|
|
6073
|
+
sendBack,
|
|
6074
|
+
event,
|
|
6075
|
+
ghost
|
|
6076
|
+
})
|
|
6077
|
+
};
|
|
6078
|
+
}
|
|
6079
|
+
function getBlockNodes(slateEditor, snapshot) {
|
|
6080
|
+
if (!snapshot.context.selection)
|
|
6081
|
+
return [];
|
|
6082
|
+
const range = toSlateRange(snapshot.context.selection, slateEditor);
|
|
6083
|
+
return range ? Array.from(Editor.nodes(slateEditor, {
|
|
6084
|
+
at: range,
|
|
6085
|
+
mode: "highest",
|
|
6086
|
+
match: (n) => !Editor.isEditor(n)
|
|
6087
|
+
})).map(([blockNode]) => DOMEditor.toDOMNode(slateEditor, blockNode)) : [];
|
|
6088
|
+
}
|
|
6089
|
+
function getChildNodes(slateEditor, snapshot) {
|
|
6090
|
+
if (!snapshot.context.selection)
|
|
6091
|
+
return [];
|
|
6092
|
+
const range = toSlateRange(snapshot.context.selection, slateEditor);
|
|
6093
|
+
return range ? Array.from(Editor.nodes(slateEditor, {
|
|
6094
|
+
at: range,
|
|
6095
|
+
mode: "lowest",
|
|
6096
|
+
match: (n) => !Editor.isEditor(n)
|
|
6097
|
+
})).map(([childNode]) => DOMEditor.toDOMNode(slateEditor, childNode)) : [];
|
|
6098
|
+
}
|
|
6099
|
+
function setDragGhost({
|
|
6100
|
+
sendBack,
|
|
6101
|
+
event,
|
|
6102
|
+
ghost
|
|
6103
|
+
}) {
|
|
6104
|
+
event.originEvent.dataTransfer.setDragImage(ghost.element, ghost.x, ghost.y), sendBack({
|
|
6105
|
+
type: "set drag ghost",
|
|
6106
|
+
ghost: ghost.element
|
|
6107
|
+
});
|
|
6108
|
+
}
|
|
6109
|
+
const abstractAnnotationBehaviors = [defineBehavior({
|
|
5867
6110
|
on: "annotation.toggle",
|
|
5868
6111
|
guard: ({
|
|
5869
6112
|
snapshot,
|
|
@@ -6017,7 +6260,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6017
6260
|
type: "insert.block",
|
|
6018
6261
|
block,
|
|
6019
6262
|
placement: index === 0 ? "before" : "after",
|
|
6020
|
-
select: "end"
|
|
6263
|
+
select: event.select ?? "end"
|
|
6021
6264
|
}))]
|
|
6022
6265
|
}), defineBehavior({
|
|
6023
6266
|
on: "insert.blocks",
|
|
@@ -6030,7 +6273,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6030
6273
|
type: "insert.block",
|
|
6031
6274
|
block,
|
|
6032
6275
|
placement: "after",
|
|
6033
|
-
select: "end"
|
|
6276
|
+
select: event.select ?? "end"
|
|
6034
6277
|
}))]
|
|
6035
6278
|
}), defineBehavior({
|
|
6036
6279
|
on: "insert.blocks",
|
|
@@ -6054,12 +6297,12 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6054
6297
|
type: "insert.block",
|
|
6055
6298
|
block: event.blocks[0],
|
|
6056
6299
|
placement: "auto",
|
|
6057
|
-
select: "end"
|
|
6300
|
+
select: event.select ?? "end"
|
|
6058
6301
|
})] : isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) => raise({
|
|
6059
6302
|
type: "insert.block",
|
|
6060
6303
|
block,
|
|
6061
6304
|
placement: index === 0 ? "auto" : "after",
|
|
6062
|
-
select: "end"
|
|
6305
|
+
select: event.select ?? "end"
|
|
6063
6306
|
})) : event.blocks.flatMap((block, index) => index === 0 ? [raise({
|
|
6064
6307
|
type: "split"
|
|
6065
6308
|
}), raise({
|
|
@@ -6069,7 +6312,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6069
6312
|
type: "insert.block",
|
|
6070
6313
|
block,
|
|
6071
6314
|
placement: "auto",
|
|
6072
|
-
select: "end"
|
|
6315
|
+
select: event.select ?? "end"
|
|
6073
6316
|
})] : index === event.blocks.length - 1 ? [raise({
|
|
6074
6317
|
type: "select.next block",
|
|
6075
6318
|
select: "start"
|
|
@@ -6077,12 +6320,12 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6077
6320
|
type: "insert.block",
|
|
6078
6321
|
block,
|
|
6079
6322
|
placement: "auto",
|
|
6080
|
-
select: "end"
|
|
6323
|
+
select: event.select ?? "end"
|
|
6081
6324
|
})] : [raise({
|
|
6082
6325
|
type: "insert.block",
|
|
6083
6326
|
block,
|
|
6084
6327
|
placement: "after",
|
|
6085
|
-
select: "end"
|
|
6328
|
+
select: event.select ?? "end"
|
|
6086
6329
|
})])]
|
|
6087
6330
|
}), defineBehavior({
|
|
6088
6331
|
on: "insert.blocks",
|
|
@@ -6095,7 +6338,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6095
6338
|
type: "insert.block",
|
|
6096
6339
|
block,
|
|
6097
6340
|
placement: index === 0 ? "auto" : "after",
|
|
6098
|
-
select: "end"
|
|
6341
|
+
select: event.select ?? "end"
|
|
6099
6342
|
}))]
|
|
6100
6343
|
}), defineBehavior({
|
|
6101
6344
|
on: "insert.break",
|
|
@@ -6389,7 +6632,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6389
6632
|
actions: [(_, {
|
|
6390
6633
|
newTextBlock,
|
|
6391
6634
|
selection
|
|
6392
|
-
}) => isSelectionCollapsed
|
|
6635
|
+
}) => isSelectionCollapsed(selection) ? [raise({
|
|
6393
6636
|
type: "insert.block",
|
|
6394
6637
|
block: newTextBlock,
|
|
6395
6638
|
placement: "after",
|
|
@@ -6525,7 +6768,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6525
6768
|
guard: ({
|
|
6526
6769
|
snapshot
|
|
6527
6770
|
}) => {
|
|
6528
|
-
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6771
|
+
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
6529
6772
|
return focusSpan && selectionCollapsed;
|
|
6530
6773
|
},
|
|
6531
6774
|
actions: []
|
|
@@ -6544,7 +6787,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6544
6787
|
guard: ({
|
|
6545
6788
|
snapshot
|
|
6546
6789
|
}) => {
|
|
6547
|
-
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6790
|
+
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
6548
6791
|
return focusSpan && selectionCollapsed;
|
|
6549
6792
|
},
|
|
6550
6793
|
actions: []
|
|
@@ -6599,86 +6842,6 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6599
6842
|
}
|
|
6600
6843
|
}]]
|
|
6601
6844
|
}),
|
|
6602
|
-
defineBehavior({
|
|
6603
|
-
on: "drag.drop",
|
|
6604
|
-
guard: ({
|
|
6605
|
-
snapshot,
|
|
6606
|
-
event
|
|
6607
|
-
}) => {
|
|
6608
|
-
const dragOrigin = snapshot.beta.internalDrag?.origin, dropPosition = event.position.selection;
|
|
6609
|
-
return dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
6610
|
-
...snapshot,
|
|
6611
|
-
context: {
|
|
6612
|
-
...snapshot.context,
|
|
6613
|
-
selection: dragOrigin.selection
|
|
6614
|
-
}
|
|
6615
|
-
}) : !1;
|
|
6616
|
-
},
|
|
6617
|
-
actions: []
|
|
6618
|
-
}),
|
|
6619
|
-
defineBehavior({
|
|
6620
|
-
on: "drag.drop",
|
|
6621
|
-
actions: [({
|
|
6622
|
-
event
|
|
6623
|
-
}) => [raise({
|
|
6624
|
-
type: "select",
|
|
6625
|
-
at: event.position.selection
|
|
6626
|
-
}), raise({
|
|
6627
|
-
type: "deserialize",
|
|
6628
|
-
originEvent: event
|
|
6629
|
-
})]]
|
|
6630
|
-
}),
|
|
6631
|
-
defineBehavior({
|
|
6632
|
-
on: "deserialization.success",
|
|
6633
|
-
guard: ({
|
|
6634
|
-
snapshot,
|
|
6635
|
-
event
|
|
6636
|
-
}) => {
|
|
6637
|
-
if (event.originEvent.type !== "drag.drop" || snapshot.beta.internalDrag === void 0)
|
|
6638
|
-
return !1;
|
|
6639
|
-
const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
6640
|
-
...snapshot,
|
|
6641
|
-
context: {
|
|
6642
|
-
...snapshot.context,
|
|
6643
|
-
selection: dragOrigin.selection
|
|
6644
|
-
}
|
|
6645
|
-
}) : !1, draggingEntireBlocks = isSelectingEntireBlocks({
|
|
6646
|
-
context: {
|
|
6647
|
-
...snapshot.context,
|
|
6648
|
-
selection: dragOrigin.selection
|
|
6649
|
-
}
|
|
6650
|
-
}), draggedBlocks = getSelectedBlocks({
|
|
6651
|
-
context: {
|
|
6652
|
-
...snapshot.context,
|
|
6653
|
-
selection: dragOrigin.selection
|
|
6654
|
-
}
|
|
6655
|
-
});
|
|
6656
|
-
return droppingOnDragOrigin ? !1 : {
|
|
6657
|
-
draggingEntireBlocks,
|
|
6658
|
-
draggedBlocks,
|
|
6659
|
-
dragOrigin,
|
|
6660
|
-
originEvent: event.originEvent
|
|
6661
|
-
};
|
|
6662
|
-
},
|
|
6663
|
-
actions: [({
|
|
6664
|
-
event
|
|
6665
|
-
}, {
|
|
6666
|
-
draggingEntireBlocks,
|
|
6667
|
-
draggedBlocks,
|
|
6668
|
-
dragOrigin,
|
|
6669
|
-
originEvent
|
|
6670
|
-
}) => [...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
|
|
6671
|
-
type: "delete.block",
|
|
6672
|
-
at: block.path
|
|
6673
|
-
})) : [raise({
|
|
6674
|
-
type: "delete",
|
|
6675
|
-
at: dragOrigin.selection
|
|
6676
|
-
})], raise({
|
|
6677
|
-
type: "insert.blocks",
|
|
6678
|
-
blocks: event.data,
|
|
6679
|
-
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
6680
|
-
})]]
|
|
6681
|
-
}),
|
|
6682
6845
|
/**
|
|
6683
6846
|
* If we are pasting text/plain into a text block then we can probably
|
|
6684
6847
|
* assume that the intended behavior is that the pasted text inherits
|
|
@@ -6830,7 +6993,8 @@ function performEvent({
|
|
|
6830
6993
|
keyGenerator,
|
|
6831
6994
|
schema,
|
|
6832
6995
|
getSnapshot,
|
|
6833
|
-
nativeEvent
|
|
6996
|
+
nativeEvent,
|
|
6997
|
+
sendBack
|
|
6834
6998
|
}) {
|
|
6835
6999
|
debug$9(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
6836
7000
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
@@ -6862,7 +7026,8 @@ function performEvent({
|
|
|
6862
7026
|
try {
|
|
6863
7027
|
shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
|
|
6864
7028
|
snapshot: guardSnapshot,
|
|
6865
|
-
event
|
|
7029
|
+
event,
|
|
7030
|
+
dom: createEditorDom(sendBack, editor)
|
|
6866
7031
|
});
|
|
6867
7032
|
} catch (error) {
|
|
6868
7033
|
console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
|
|
@@ -6875,7 +7040,8 @@ function performEvent({
|
|
|
6875
7040
|
try {
|
|
6876
7041
|
actions = actionSet({
|
|
6877
7042
|
snapshot: actionsSnapshot,
|
|
6878
|
-
event
|
|
7043
|
+
event,
|
|
7044
|
+
dom: createEditorDom(sendBack, editor)
|
|
6879
7045
|
}, shouldRun);
|
|
6880
7046
|
} catch (error) {
|
|
6881
7047
|
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
@@ -6904,7 +7070,8 @@ function performEvent({
|
|
|
6904
7070
|
keyGenerator,
|
|
6905
7071
|
schema,
|
|
6906
7072
|
getSnapshot,
|
|
6907
|
-
nativeEvent
|
|
7073
|
+
nativeEvent,
|
|
7074
|
+
sendBack
|
|
6908
7075
|
});
|
|
6909
7076
|
continue;
|
|
6910
7077
|
}
|
|
@@ -6918,7 +7085,8 @@ function performEvent({
|
|
|
6918
7085
|
keyGenerator,
|
|
6919
7086
|
schema,
|
|
6920
7087
|
getSnapshot,
|
|
6921
|
-
nativeEvent
|
|
7088
|
+
nativeEvent,
|
|
7089
|
+
sendBack
|
|
6922
7090
|
});
|
|
6923
7091
|
continue;
|
|
6924
7092
|
}
|
|
@@ -6931,7 +7099,8 @@ function performEvent({
|
|
|
6931
7099
|
keyGenerator,
|
|
6932
7100
|
schema,
|
|
6933
7101
|
getSnapshot,
|
|
6934
|
-
nativeEvent: void 0
|
|
7102
|
+
nativeEvent: void 0,
|
|
7103
|
+
sendBack
|
|
6935
7104
|
});
|
|
6936
7105
|
}
|
|
6937
7106
|
});
|
|
@@ -6958,7 +7127,8 @@ function performEvent({
|
|
|
6958
7127
|
keyGenerator,
|
|
6959
7128
|
schema,
|
|
6960
7129
|
getSnapshot,
|
|
6961
|
-
nativeEvent
|
|
7130
|
+
nativeEvent,
|
|
7131
|
+
sendBack
|
|
6962
7132
|
});
|
|
6963
7133
|
continue;
|
|
6964
7134
|
}
|
|
@@ -6972,7 +7142,8 @@ function performEvent({
|
|
|
6972
7142
|
keyGenerator,
|
|
6973
7143
|
schema,
|
|
6974
7144
|
getSnapshot,
|
|
6975
|
-
nativeEvent
|
|
7145
|
+
nativeEvent,
|
|
7146
|
+
sendBack
|
|
6976
7147
|
});
|
|
6977
7148
|
continue;
|
|
6978
7149
|
}
|
|
@@ -7044,9 +7215,7 @@ function createEditorSnapshot({
|
|
|
7044
7215
|
editor,
|
|
7045
7216
|
keyGenerator,
|
|
7046
7217
|
readOnly,
|
|
7047
|
-
schema
|
|
7048
|
-
hasTag,
|
|
7049
|
-
internalDrag
|
|
7218
|
+
schema
|
|
7050
7219
|
}) {
|
|
7051
7220
|
const selection = editor.selection ? slateRangeToSelection({
|
|
7052
7221
|
schema,
|
|
@@ -7071,9 +7240,7 @@ function createEditorSnapshot({
|
|
|
7071
7240
|
decoratorState: editor.decoratorState,
|
|
7072
7241
|
markState: editor.markState,
|
|
7073
7242
|
schema
|
|
7074
|
-
})
|
|
7075
|
-
hasTag,
|
|
7076
|
-
internalDrag
|
|
7243
|
+
})
|
|
7077
7244
|
}
|
|
7078
7245
|
};
|
|
7079
7246
|
}
|
|
@@ -7195,11 +7362,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7195
7362
|
readOnly: self.getSnapshot().matches({
|
|
7196
7363
|
"edit mode": "read only"
|
|
7197
7364
|
}),
|
|
7198
|
-
schema: context.schema
|
|
7199
|
-
hasTag: (tag) => self.getSnapshot().hasTag(tag),
|
|
7200
|
-
internalDrag: context.internalDrag
|
|
7365
|
+
schema: context.schema
|
|
7201
7366
|
}),
|
|
7202
|
-
nativeEvent: event.nativeEvent
|
|
7367
|
+
nativeEvent: event.nativeEvent,
|
|
7368
|
+
sendBack: (event2) => self.send(event2)
|
|
7203
7369
|
});
|
|
7204
7370
|
} catch (error) {
|
|
7205
7371
|
console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
@@ -7253,6 +7419,13 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7253
7419
|
...event,
|
|
7254
7420
|
type: "selection"
|
|
7255
7421
|
}))]
|
|
7422
|
+
},
|
|
7423
|
+
"set drag ghost": {
|
|
7424
|
+
actions: assign({
|
|
7425
|
+
dragGhost: ({
|
|
7426
|
+
event
|
|
7427
|
+
}) => event.ghost
|
|
7428
|
+
})
|
|
7256
7429
|
}
|
|
7257
7430
|
},
|
|
7258
7431
|
type: "parallel",
|
|
@@ -7347,7 +7520,6 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7347
7520
|
internalDrag: ({
|
|
7348
7521
|
event
|
|
7349
7522
|
}) => ({
|
|
7350
|
-
ghost: event.ghost,
|
|
7351
7523
|
origin: event.origin
|
|
7352
7524
|
})
|
|
7353
7525
|
})],
|
|
@@ -7397,13 +7569,15 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7397
7569
|
}, ({
|
|
7398
7570
|
context
|
|
7399
7571
|
}) => {
|
|
7400
|
-
if (context.
|
|
7572
|
+
if (context.dragGhost)
|
|
7401
7573
|
try {
|
|
7402
|
-
context.
|
|
7574
|
+
context.dragGhost.parentNode?.removeChild(context.dragGhost);
|
|
7403
7575
|
} catch (error) {
|
|
7404
|
-
console.error(new Error(`Removing the
|
|
7576
|
+
console.error(new Error(`Removing the drag ghost failed due to: ${error.message}`));
|
|
7405
7577
|
}
|
|
7406
7578
|
}, assign({
|
|
7579
|
+
dragGhost: void 0
|
|
7580
|
+
}), assign({
|
|
7407
7581
|
internalDrag: void 0
|
|
7408
7582
|
})],
|
|
7409
7583
|
tags: ["dragging internally"],
|
|
@@ -10784,73 +10958,19 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10784
10958
|
console.warn("Could not find position for dragstart event");
|
|
10785
10959
|
return;
|
|
10786
10960
|
}
|
|
10787
|
-
const snapshot = getEditorSnapshot({
|
|
10788
|
-
editorActorSnapshot: editorActor.getSnapshot(),
|
|
10789
|
-
slateEditorInstance: slateEditor
|
|
10790
|
-
}), dragSelection = getDragSelection({
|
|
10791
|
-
eventSelection: position_4.selection,
|
|
10792
|
-
snapshot
|
|
10793
|
-
}), selectingEntireBlocks = isSelectingEntireBlocks({
|
|
10794
|
-
context: {
|
|
10795
|
-
...snapshot.context,
|
|
10796
|
-
selection: dragSelection
|
|
10797
|
-
}
|
|
10798
|
-
}), dragGhost = document.createElement("div"), draggedDomNodes = getSelectionDomNodes({
|
|
10799
|
-
snapshot: {
|
|
10800
|
-
context: {
|
|
10801
|
-
...snapshot.context,
|
|
10802
|
-
selection: dragSelection
|
|
10803
|
-
}
|
|
10804
|
-
},
|
|
10805
|
-
slateEditor
|
|
10806
|
-
});
|
|
10807
|
-
if (selectingEntireBlocks) {
|
|
10808
|
-
const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) => node.cloneNode(!0));
|
|
10809
|
-
for (const block of clonedBlockNodes)
|
|
10810
|
-
block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
|
|
10811
|
-
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
10812
|
-
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) {
|
|
10813
|
-
const customGhostRect = customGhost.getBoundingClientRect(), x = event_8.clientX - customGhostRect.left, y = event_8.clientY - customGhostRect.top;
|
|
10814
|
-
dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x, y);
|
|
10815
|
-
} else {
|
|
10816
|
-
const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x_0 = event_8.clientX - blocksDomRect.left, y_0 = event_8.clientY - blocksDomRect.top;
|
|
10817
|
-
dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_0, y_0);
|
|
10818
|
-
}
|
|
10819
|
-
} else {
|
|
10820
|
-
const clonedChildNodes = draggedDomNodes.childNodes.map((node_0) => node_0.cloneNode(!0));
|
|
10821
|
-
for (const child of clonedChildNodes)
|
|
10822
|
-
dragGhost.appendChild(child);
|
|
10823
|
-
dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
10824
|
-
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
|
|
10825
|
-
dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
|
|
10826
|
-
}
|
|
10827
10961
|
return editorActor.send({
|
|
10828
|
-
type: "behavior event",
|
|
10829
|
-
behaviorEvent: {
|
|
10830
|
-
type: "select",
|
|
10831
|
-
at: isSelectionCollapsed$1(dragSelection) ? dragSelection : {
|
|
10832
|
-
anchor: getSelectionEndPoint(dragSelection),
|
|
10833
|
-
focus: getSelectionEndPoint(dragSelection),
|
|
10834
|
-
backward: !1
|
|
10835
|
-
}
|
|
10836
|
-
},
|
|
10837
|
-
editor: slateEditor
|
|
10838
|
-
}), editorActor.send({
|
|
10839
10962
|
type: "dragstart",
|
|
10840
|
-
origin:
|
|
10841
|
-
selection: dragSelection
|
|
10842
|
-
},
|
|
10843
|
-
ghost: dragGhost
|
|
10963
|
+
origin: position_4
|
|
10844
10964
|
}), editorActor.send({
|
|
10845
10965
|
type: "behavior event",
|
|
10846
10966
|
behaviorEvent: {
|
|
10847
10967
|
type: "drag.dragstart",
|
|
10848
10968
|
originEvent: {
|
|
10969
|
+
clientX: event_8.clientX,
|
|
10970
|
+
clientY: event_8.clientY,
|
|
10849
10971
|
dataTransfer: event_8.dataTransfer
|
|
10850
10972
|
},
|
|
10851
|
-
position:
|
|
10852
|
-
selection: dragSelection
|
|
10853
|
-
}
|
|
10973
|
+
position: position_4
|
|
10854
10974
|
},
|
|
10855
10975
|
editor: slateEditor
|
|
10856
10976
|
}), !0;
|
|
@@ -10918,6 +11038,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10918
11038
|
originEvent: {
|
|
10919
11039
|
dataTransfer: event_12.dataTransfer
|
|
10920
11040
|
},
|
|
11041
|
+
dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
|
|
10921
11042
|
position: position_7
|
|
10922
11043
|
},
|
|
10923
11044
|
editor: slateEditor,
|
|
@@ -10942,6 +11063,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10942
11063
|
originEvent: {
|
|
10943
11064
|
dataTransfer: event_13.dataTransfer
|
|
10944
11065
|
},
|
|
11066
|
+
dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
|
|
10945
11067
|
position: position_8
|
|
10946
11068
|
},
|
|
10947
11069
|
editor: slateEditor,
|