@portabletext/editor 1.51.0 → 1.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/selection-point.cjs +2 -25
- package/lib/_chunks-cjs/selection-point.cjs.map +1 -1
- package/lib/_chunks-es/selection-point.js +2 -25
- package/lib/_chunks-es/selection-point.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +26 -5
- package/lib/behaviors/index.d.ts +26 -5
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +465 -384
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +360 -31
- package/lib/index.d.ts +360 -31
- package/lib/index.js +486 -405
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +26 -5
- package/lib/plugins/index.d.ts +26 -5
- package/lib/selectors/index.d.cts +0 -14
- package/lib/selectors/index.d.ts +0 -14
- package/lib/utils/index.d.cts +0 -14
- package/lib/utils/index.d.ts +0 -14
- package/package.json +11 -11
- package/src/behaviors/behavior.abstract.delete.ts +0 -1
- 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 +4 -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/components/render-element.tsx +27 -46
- package/src/editor/editor-machine.ts +15 -8
- package/src/editor/editor-selector.ts +0 -1
- package/src/editor/editor-snapshot.ts +0 -13
- package/src/editor/plugins/createWithSchemaTypes.ts +21 -1
- package/src/internal-utils/create-test-snapshot.ts +0 -1
- package/src/internal-utils/event-position.ts +41 -27
- package/src/internal-utils/parse-blocks.ts +26 -15
- package/src/internal-utils/selection-elements.ts +108 -0
- package/src/operations/behavior.operation.decorator.add.ts +0 -1
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, 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 { 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, isTextBlock, parseBlock, sliceBlocks, parseAnnotation, blockOffsetToSpanSelectionPoint, parseInlineObject, 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
|
},
|
|
@@ -1049,93 +1013,49 @@ function RenderTextBlock(props) {
|
|
|
1049
1013
|
] });
|
|
1050
1014
|
}
|
|
1051
1015
|
function RenderElement(props) {
|
|
1052
|
-
const $ = c(
|
|
1016
|
+
const $ = c(43), editorActor = useContext(EditorActorContext), schema = useSelector(editorActor, _temp$1);
|
|
1053
1017
|
if ("__inline" in props.element && props.element.__inline === !0) {
|
|
1054
1018
|
let t02;
|
|
1055
|
-
|
|
1056
|
-
let t13;
|
|
1057
|
-
$[3] !== props.element ? (t13 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[3] = props.element, $[4] = t13) : t13 = $[4], t02 = parseInlineObject({
|
|
1058
|
-
context: {
|
|
1059
|
-
keyGenerator: _temp2,
|
|
1060
|
-
schema
|
|
1061
|
-
},
|
|
1062
|
-
options: {
|
|
1063
|
-
refreshKeys: !1,
|
|
1064
|
-
validateFields: !1
|
|
1065
|
-
},
|
|
1066
|
-
inlineObject: {
|
|
1067
|
-
_key: props.element._key,
|
|
1068
|
-
_type: props.element._type,
|
|
1069
|
-
...t13
|
|
1070
|
-
}
|
|
1071
|
-
}), $[0] = props.element, $[1] = schema, $[2] = t02;
|
|
1072
|
-
} else
|
|
1073
|
-
t02 = $[2];
|
|
1074
|
-
const inlineObject = t02;
|
|
1075
|
-
inlineObject || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
|
|
1019
|
+
$[0] !== props.element ? (t02 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[0] = props.element, $[1] = t02) : t02 = $[1];
|
|
1076
1020
|
let t12;
|
|
1077
|
-
$[
|
|
1021
|
+
$[2] !== props.element._key || $[3] !== props.element._type || $[4] !== t02 ? (t12 = {
|
|
1078
1022
|
_key: props.element._key,
|
|
1079
|
-
_type: props.element._type
|
|
1080
|
-
|
|
1023
|
+
_type: props.element._type,
|
|
1024
|
+
...t02
|
|
1025
|
+
}, $[2] = props.element._key, $[3] = props.element._type, $[4] = t02, $[5] = t12) : t12 = $[5];
|
|
1026
|
+
const inlineObject = t12;
|
|
1027
|
+
schema.inlineObjects.find((inlineObject_0) => inlineObject_0.name === props.element._type) || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
|
|
1081
1028
|
let t22;
|
|
1082
|
-
|
|
1029
|
+
$[6] !== inlineObject || $[7] !== props.element._key || $[8] !== props.element._type ? (t22 = inlineObject ?? {
|
|
1030
|
+
_key: props.element._key,
|
|
1031
|
+
_type: props.element._type
|
|
1032
|
+
}, $[6] = inlineObject, $[7] = props.element._key, $[8] = props.element._type, $[9] = t22) : t22 = $[9];
|
|
1033
|
+
let t32;
|
|
1034
|
+
return $[10] !== props.attributes || $[11] !== props.children || $[12] !== props.element || $[13] !== props.readOnly || $[14] !== props.renderChild || $[15] !== t22 ? (t32 = /* @__PURE__ */ jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, inlineObject: t22, readOnly: props.readOnly, renderChild: props.renderChild, children: props.children }), $[10] = props.attributes, $[11] = props.children, $[12] = props.element, $[13] = props.readOnly, $[14] = props.renderChild, $[15] = t22, $[16] = t32) : t32 = $[16], t32;
|
|
1083
1035
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
},
|
|
1090
|
-
options: {
|
|
1091
|
-
refreshKeys: !1,
|
|
1092
|
-
validateFields: !1
|
|
1093
|
-
},
|
|
1094
|
-
block: props.element
|
|
1095
|
-
}), $[16] = props.element, $[17] = schema, $[18] = t0) : t0 = $[18];
|
|
1096
|
-
const textBlock = t0;
|
|
1097
|
-
if (textBlock) {
|
|
1098
|
-
let t12;
|
|
1099
|
-
return $[19] !== props.attributes || $[20] !== props.children || $[21] !== props.element || $[22] !== props.readOnly || $[23] !== props.renderBlock || $[24] !== props.renderListItem || $[25] !== props.renderStyle || $[26] !== props.spellCheck || $[27] !== textBlock ? (t12 = /* @__PURE__ */ jsx(RenderTextBlock, { attributes: props.attributes, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, spellCheck: props.spellCheck, textBlock, children: props.children }), $[19] = props.attributes, $[20] = props.children, $[21] = props.element, $[22] = props.readOnly, $[23] = props.renderBlock, $[24] = props.renderListItem, $[25] = props.renderStyle, $[26] = props.spellCheck, $[27] = textBlock, $[28] = t12) : t12 = $[28], t12;
|
|
1036
|
+
if (isTextBlock({
|
|
1037
|
+
schema
|
|
1038
|
+
}, props.element)) {
|
|
1039
|
+
let t02;
|
|
1040
|
+
return $[17] !== props.attributes || $[18] !== props.children || $[19] !== props.element || $[20] !== props.readOnly || $[21] !== props.renderBlock || $[22] !== props.renderListItem || $[23] !== props.renderStyle || $[24] !== props.spellCheck ? (t02 = /* @__PURE__ */ jsx(RenderTextBlock, { attributes: props.attributes, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, spellCheck: props.spellCheck, textBlock: props.element, children: props.children }), $[17] = props.attributes, $[18] = props.children, $[19] = props.element, $[20] = props.readOnly, $[21] = props.renderBlock, $[22] = props.renderListItem, $[23] = props.renderStyle, $[24] = props.spellCheck, $[25] = t02) : t02 = $[25], t02;
|
|
1100
1041
|
}
|
|
1042
|
+
let t0;
|
|
1043
|
+
$[26] !== props.element ? (t0 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[26] = props.element, $[27] = t0) : t0 = $[27];
|
|
1101
1044
|
let t1;
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
schema
|
|
1108
|
-
},
|
|
1109
|
-
options: {
|
|
1110
|
-
refreshKeys: !1,
|
|
1111
|
-
validateFields: !1
|
|
1112
|
-
},
|
|
1113
|
-
blockObject: {
|
|
1114
|
-
_key: props.element._key,
|
|
1115
|
-
_type: props.element._type,
|
|
1116
|
-
...t22
|
|
1117
|
-
}
|
|
1118
|
-
}), $[29] = props.element, $[30] = schema, $[31] = t1;
|
|
1119
|
-
} else
|
|
1120
|
-
t1 = $[31];
|
|
1045
|
+
$[28] !== props.element._key || $[29] !== props.element._type || $[30] !== t0 ? (t1 = {
|
|
1046
|
+
_key: props.element._key,
|
|
1047
|
+
_type: props.element._type,
|
|
1048
|
+
...t0
|
|
1049
|
+
}, $[28] = props.element._key, $[29] = props.element._type, $[30] = t0, $[31] = t1) : t1 = $[31];
|
|
1121
1050
|
const blockObject = t1;
|
|
1122
|
-
|
|
1051
|
+
schema.blockObjects.find((blockObject_0) => blockObject_0.name === props.element._type) || console.error(`Unable to find Block Object "${props.element._type}" in Schema`);
|
|
1123
1052
|
let t2;
|
|
1124
|
-
$[
|
|
1053
|
+
$[32] !== blockObject || $[33] !== props.element._key || $[34] !== props.element._type ? (t2 = blockObject ?? {
|
|
1125
1054
|
_key: props.element._key,
|
|
1126
1055
|
_type: props.element._type
|
|
1127
|
-
}, $[
|
|
1056
|
+
}, $[32] = blockObject, $[33] = props.element._key, $[34] = props.element._type, $[35] = t2) : t2 = $[35];
|
|
1128
1057
|
let t3;
|
|
1129
|
-
return $[
|
|
1130
|
-
}
|
|
1131
|
-
function _temp4() {
|
|
1132
|
-
return "";
|
|
1133
|
-
}
|
|
1134
|
-
function _temp3() {
|
|
1135
|
-
return "";
|
|
1136
|
-
}
|
|
1137
|
-
function _temp2() {
|
|
1138
|
-
return "";
|
|
1058
|
+
return $[36] !== props.attributes || $[37] !== props.children || $[38] !== props.element || $[39] !== props.readOnly || $[40] !== props.renderBlock || $[41] !== t2 ? (t3 = /* @__PURE__ */ jsx(RenderBlockObject, { attributes: props.attributes, blockObject: t2, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, children: props.children }), $[36] = props.attributes, $[37] = props.children, $[38] = props.element, $[39] = props.readOnly, $[40] = props.renderBlock, $[41] = t2, $[42] = t3) : t3 = $[42], t3;
|
|
1139
1059
|
}
|
|
1140
1060
|
function _temp$1(s) {
|
|
1141
1061
|
return s.context.schema;
|
|
@@ -1206,7 +1126,7 @@ const converterJson = {
|
|
|
1206
1126
|
snapshot,
|
|
1207
1127
|
event
|
|
1208
1128
|
}) => {
|
|
1209
|
-
const selection = snapshot.
|
|
1129
|
+
const selection = snapshot.context.selection;
|
|
1210
1130
|
if (!selection)
|
|
1211
1131
|
return {
|
|
1212
1132
|
type: "serialization.failure",
|
|
@@ -1249,11 +1169,7 @@ const converterJson = {
|
|
|
1249
1169
|
context: snapshot.context,
|
|
1250
1170
|
block,
|
|
1251
1171
|
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.internalDrag,
|
|
1172
|
+
refreshKeys: !0,
|
|
1257
1173
|
validateFields: !1
|
|
1258
1174
|
}
|
|
1259
1175
|
});
|
|
@@ -1277,7 +1193,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
1277
1193
|
snapshot,
|
|
1278
1194
|
event
|
|
1279
1195
|
}) => {
|
|
1280
|
-
const selection = snapshot.
|
|
1196
|
+
const selection = snapshot.context.selection;
|
|
1281
1197
|
if (!selection)
|
|
1282
1198
|
return {
|
|
1283
1199
|
type: "serialization.failure",
|
|
@@ -1348,7 +1264,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
1348
1264
|
snapshot,
|
|
1349
1265
|
event
|
|
1350
1266
|
}) => {
|
|
1351
|
-
const selection = snapshot.
|
|
1267
|
+
const selection = snapshot.context.selection;
|
|
1352
1268
|
return selection ? {
|
|
1353
1269
|
type: "serialization.success",
|
|
1354
1270
|
data: sliceBlocks({
|
|
@@ -1357,7 +1273,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
1357
1273
|
schema: snapshot.context.schema
|
|
1358
1274
|
},
|
|
1359
1275
|
blocks: snapshot.context.value
|
|
1360
|
-
}).map((block) => isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text :
|
|
1276
|
+
}).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
1277
|
|
|
1362
1278
|
`),
|
|
1363
1279
|
mimeType: "text/plain",
|
|
@@ -1592,8 +1508,7 @@ function getEditorSnapshot({
|
|
|
1592
1508
|
decoratorState: slateEditorInstance.decoratorState,
|
|
1593
1509
|
markState: slateEditorInstance.markState,
|
|
1594
1510
|
schema: editorActorSnapshot.context.schema
|
|
1595
|
-
})
|
|
1596
|
-
internalDrag: editorActorSnapshot.context.internalDrag
|
|
1511
|
+
})
|
|
1597
1512
|
}
|
|
1598
1513
|
};
|
|
1599
1514
|
}
|
|
@@ -4724,7 +4639,7 @@ function createWithSchemaTypes({
|
|
|
4724
4639
|
editorActor
|
|
4725
4640
|
}) {
|
|
4726
4641
|
return function(editor) {
|
|
4727
|
-
editor.isTextBlock = (value) => isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => isSpan(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
4642
|
+
editor.isTextBlock = (value) => Editor.isEditor(value) ? !1 : isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => Editor.isEditor(value) ? !1 : isSpan(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => Editor.isEditor(value) ? !1 : isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => Editor.isEditor(element) ? !1 : editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => Editor.isEditor(element) ? !1 : editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
4728
4643
|
const {
|
|
4729
4644
|
normalizeNode
|
|
4730
4645
|
} = editor;
|
|
@@ -5203,7 +5118,7 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
5203
5118
|
guard: ({
|
|
5204
5119
|
snapshot
|
|
5205
5120
|
}) => {
|
|
5206
|
-
if (!isSelectionCollapsed(snapshot))
|
|
5121
|
+
if (!isSelectionCollapsed$1(snapshot))
|
|
5207
5122
|
return !1;
|
|
5208
5123
|
const caretWordSelection = getCaretWordSelection(snapshot);
|
|
5209
5124
|
return !caretWordSelection || !isSelectionExpanded({
|
|
@@ -5346,7 +5261,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5346
5261
|
snapshot,
|
|
5347
5262
|
event
|
|
5348
5263
|
}) => {
|
|
5349
|
-
if (!isHotkey("ArrowDown", event.originEvent) || !isSelectionCollapsed(snapshot))
|
|
5264
|
+
if (!isHotkey("ArrowDown", event.originEvent) || !isSelectionCollapsed$1(snapshot))
|
|
5350
5265
|
return !1;
|
|
5351
5266
|
const focusBlockObject = getFocusBlockObject(snapshot), nextBlock = getNextBlock(snapshot);
|
|
5352
5267
|
return focusBlockObject && !nextBlock;
|
|
@@ -5366,7 +5281,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5366
5281
|
snapshot,
|
|
5367
5282
|
event
|
|
5368
5283
|
}) => {
|
|
5369
|
-
if (!isHotkey("ArrowUp", event.originEvent) || !isSelectionCollapsed(snapshot))
|
|
5284
|
+
if (!isHotkey("ArrowUp", event.originEvent) || !isSelectionCollapsed$1(snapshot))
|
|
5370
5285
|
return !1;
|
|
5371
5286
|
const focusBlockObject = getFocusBlockObject(snapshot), previousBlock = getPreviousBlock(snapshot);
|
|
5372
5287
|
return focusBlockObject && !previousBlock;
|
|
@@ -5386,7 +5301,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5386
5301
|
snapshot
|
|
5387
5302
|
}) => {
|
|
5388
5303
|
const focusBlockObject = getFocusBlockObject(snapshot);
|
|
5389
|
-
return isSelectionCollapsed(snapshot) && focusBlockObject !== void 0;
|
|
5304
|
+
return isSelectionCollapsed$1(snapshot) && focusBlockObject !== void 0;
|
|
5390
5305
|
},
|
|
5391
5306
|
actions: [({
|
|
5392
5307
|
snapshot
|
|
@@ -5403,7 +5318,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5403
5318
|
snapshot,
|
|
5404
5319
|
event
|
|
5405
5320
|
}) => {
|
|
5406
|
-
if (snapshot.context.readOnly || snapshot.context.selection && !isSelectionCollapsed(snapshot))
|
|
5321
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !isSelectionCollapsed$1(snapshot))
|
|
5407
5322
|
return !1;
|
|
5408
5323
|
const focusBlockObject = getFocusBlockObject({
|
|
5409
5324
|
context: {
|
|
@@ -5438,7 +5353,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5438
5353
|
snapshot,
|
|
5439
5354
|
event
|
|
5440
5355
|
}) => {
|
|
5441
|
-
if (snapshot.context.readOnly || snapshot.context.selection && !isSelectionCollapsed(snapshot))
|
|
5356
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !isSelectionCollapsed$1(snapshot))
|
|
5442
5357
|
return !1;
|
|
5443
5358
|
const focusBlockObject = getFocusBlockObject({
|
|
5444
5359
|
context: {
|
|
@@ -5472,7 +5387,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5472
5387
|
guard: ({
|
|
5473
5388
|
snapshot
|
|
5474
5389
|
}) => {
|
|
5475
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot), previousBlock = getPreviousBlock(snapshot);
|
|
5390
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot), previousBlock = getPreviousBlock(snapshot);
|
|
5476
5391
|
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !isTextBlock(snapshot.context, previousBlock.node) ? {
|
|
5477
5392
|
focusTextBlock,
|
|
5478
5393
|
previousBlock
|
|
@@ -5502,7 +5417,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5502
5417
|
guard: ({
|
|
5503
5418
|
snapshot
|
|
5504
5419
|
}) => {
|
|
5505
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot), nextBlock = getNextBlock(snapshot);
|
|
5420
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot), nextBlock = getNextBlock(snapshot);
|
|
5506
5421
|
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !isTextBlock(snapshot.context, nextBlock.node) ? {
|
|
5507
5422
|
focusTextBlock,
|
|
5508
5423
|
nextBlock
|
|
@@ -5580,7 +5495,131 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5580
5495
|
decorator: "code"
|
|
5581
5496
|
})]]
|
|
5582
5497
|
})
|
|
5583
|
-
}
|
|
5498
|
+
};
|
|
5499
|
+
function getCompoundClientRect(nodes) {
|
|
5500
|
+
if (nodes.length === 0)
|
|
5501
|
+
return new DOMRect(0, 0, 0, 0);
|
|
5502
|
+
const elements = nodes.filter((node) => node instanceof Element), firstRect = elements.at(0)?.getBoundingClientRect();
|
|
5503
|
+
if (!firstRect)
|
|
5504
|
+
return new DOMRect(0, 0, 0, 0);
|
|
5505
|
+
let left = firstRect.left, top = firstRect.top, right = firstRect.right, bottom = firstRect.bottom;
|
|
5506
|
+
for (let i = 1; i < elements.length; i++) {
|
|
5507
|
+
const rect = elements[i].getBoundingClientRect();
|
|
5508
|
+
left = Math.min(left, rect.left), top = Math.min(top, rect.top), right = Math.max(right, rect.right), bottom = Math.max(bottom, rect.bottom);
|
|
5509
|
+
}
|
|
5510
|
+
return new DOMRect(left, top, right - left, bottom - top);
|
|
5511
|
+
}
|
|
5512
|
+
const coreDndBehaviors = [
|
|
5513
|
+
/**
|
|
5514
|
+
* Core Behavior that:
|
|
5515
|
+
* 1. Calculates and selects a "drag selection"
|
|
5516
|
+
* 2. Constructs and sets a drag ghost element
|
|
5517
|
+
* 3. Forwards the dragstart event
|
|
5518
|
+
*/
|
|
5519
|
+
defineBehavior({
|
|
5520
|
+
on: "drag.dragstart",
|
|
5521
|
+
guard: ({
|
|
5522
|
+
snapshot,
|
|
5523
|
+
dom,
|
|
5524
|
+
event
|
|
5525
|
+
}) => {
|
|
5526
|
+
const dragSelection = getDragSelection({
|
|
5527
|
+
snapshot,
|
|
5528
|
+
eventSelection: event.position.selection
|
|
5529
|
+
}), selectingEntireBlocks = isSelectingEntireBlocks({
|
|
5530
|
+
context: {
|
|
5531
|
+
...snapshot.context,
|
|
5532
|
+
selection: dragSelection
|
|
5533
|
+
}
|
|
5534
|
+
}), draggedDomNodes = {
|
|
5535
|
+
blockNodes: dom.getBlockNodes({
|
|
5536
|
+
...snapshot,
|
|
5537
|
+
context: {
|
|
5538
|
+
...snapshot.context,
|
|
5539
|
+
selection: dragSelection
|
|
5540
|
+
}
|
|
5541
|
+
}),
|
|
5542
|
+
childNodes: dom.getChildNodes({
|
|
5543
|
+
...snapshot,
|
|
5544
|
+
context: {
|
|
5545
|
+
...snapshot.context,
|
|
5546
|
+
selection: dragSelection
|
|
5547
|
+
}
|
|
5548
|
+
})
|
|
5549
|
+
};
|
|
5550
|
+
return {
|
|
5551
|
+
dragSelection,
|
|
5552
|
+
draggedDomNodes,
|
|
5553
|
+
selectingEntireBlocks
|
|
5554
|
+
};
|
|
5555
|
+
},
|
|
5556
|
+
actions: [({
|
|
5557
|
+
dom,
|
|
5558
|
+
event
|
|
5559
|
+
}, {
|
|
5560
|
+
dragSelection,
|
|
5561
|
+
draggedDomNodes,
|
|
5562
|
+
selectingEntireBlocks
|
|
5563
|
+
}) => {
|
|
5564
|
+
const dragGhost = document.createElement("div");
|
|
5565
|
+
if (selectingEntireBlocks) {
|
|
5566
|
+
const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) => node.cloneNode(!0));
|
|
5567
|
+
for (const block of clonedBlockNodes)
|
|
5568
|
+
block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
|
|
5569
|
+
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
5570
|
+
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) {
|
|
5571
|
+
const customGhostRect = customGhost.getBoundingClientRect(), x = event.originEvent.clientX - customGhostRect.left, y = event.originEvent.clientY - customGhostRect.top;
|
|
5572
|
+
return dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, [raise({
|
|
5573
|
+
type: "select",
|
|
5574
|
+
at: dragSelection
|
|
5575
|
+
}), effect(() => {
|
|
5576
|
+
dom.setDragGhost({
|
|
5577
|
+
event,
|
|
5578
|
+
ghost: {
|
|
5579
|
+
element: dragGhost,
|
|
5580
|
+
x,
|
|
5581
|
+
y
|
|
5582
|
+
}
|
|
5583
|
+
});
|
|
5584
|
+
}), forward(event)];
|
|
5585
|
+
} else {
|
|
5586
|
+
const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x = event.originEvent.clientX - blocksDomRect.left, y = event.originEvent.clientY - blocksDomRect.top;
|
|
5587
|
+
return dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, [raise({
|
|
5588
|
+
type: "select",
|
|
5589
|
+
at: dragSelection
|
|
5590
|
+
}), effect(() => {
|
|
5591
|
+
dom.setDragGhost({
|
|
5592
|
+
event,
|
|
5593
|
+
ghost: {
|
|
5594
|
+
element: dragGhost,
|
|
5595
|
+
x,
|
|
5596
|
+
y
|
|
5597
|
+
}
|
|
5598
|
+
});
|
|
5599
|
+
}), forward(event)];
|
|
5600
|
+
}
|
|
5601
|
+
} else {
|
|
5602
|
+
const clonedChildNodes = draggedDomNodes.childNodes.map((node) => node.cloneNode(!0));
|
|
5603
|
+
for (const child of clonedChildNodes)
|
|
5604
|
+
dragGhost.appendChild(child);
|
|
5605
|
+
dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
5606
|
+
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x = event.originEvent.clientX - childrenDomRect.left, y = event.originEvent.clientY - childrenDomRect.top;
|
|
5607
|
+
return dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, [raise({
|
|
5608
|
+
type: "select",
|
|
5609
|
+
at: dragSelection
|
|
5610
|
+
}), effect(() => {
|
|
5611
|
+
dom.setDragGhost({
|
|
5612
|
+
event,
|
|
5613
|
+
ghost: {
|
|
5614
|
+
element: dragGhost,
|
|
5615
|
+
x,
|
|
5616
|
+
y
|
|
5617
|
+
}
|
|
5618
|
+
});
|
|
5619
|
+
}), forward(event)];
|
|
5620
|
+
}
|
|
5621
|
+
}]
|
|
5622
|
+
}),
|
|
5584
5623
|
/**
|
|
5585
5624
|
* When dragging over the drag origin, we don't want to show the caret in the
|
|
5586
5625
|
* text.
|
|
@@ -5591,7 +5630,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5591
5630
|
snapshot,
|
|
5592
5631
|
event
|
|
5593
5632
|
}) => {
|
|
5594
|
-
const dragOrigin =
|
|
5633
|
+
const dragOrigin = event.dragOrigin;
|
|
5595
5634
|
return dragOrigin ? isOverlappingSelection(event.position.selection)({
|
|
5596
5635
|
...snapshot,
|
|
5597
5636
|
context: {
|
|
@@ -5601,13 +5640,128 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5601
5640
|
}) : !1;
|
|
5602
5641
|
},
|
|
5603
5642
|
actions: []
|
|
5643
|
+
}),
|
|
5644
|
+
/**
|
|
5645
|
+
* If the drop position overlaps the drag origin, then the event should be
|
|
5646
|
+
* cancelled.
|
|
5647
|
+
*/
|
|
5648
|
+
defineBehavior({
|
|
5649
|
+
on: "drag.drop",
|
|
5650
|
+
guard: ({
|
|
5651
|
+
snapshot,
|
|
5652
|
+
event
|
|
5653
|
+
}) => {
|
|
5654
|
+
const dragOrigin = event.dragOrigin, dropPosition = event.position.selection;
|
|
5655
|
+
return dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
5656
|
+
...snapshot,
|
|
5657
|
+
context: {
|
|
5658
|
+
...snapshot.context,
|
|
5659
|
+
selection: dragOrigin.selection
|
|
5660
|
+
}
|
|
5661
|
+
}) : !1;
|
|
5662
|
+
},
|
|
5663
|
+
actions: []
|
|
5664
|
+
}),
|
|
5665
|
+
/**
|
|
5666
|
+
* If we drop and have access to a drag origin, then we can deserialize
|
|
5667
|
+
* without creating a new selection.
|
|
5668
|
+
*/
|
|
5669
|
+
defineBehavior({
|
|
5670
|
+
on: "drag.drop",
|
|
5671
|
+
guard: ({
|
|
5672
|
+
event
|
|
5673
|
+
}) => event.dragOrigin !== void 0,
|
|
5674
|
+
actions: [({
|
|
5675
|
+
event
|
|
5676
|
+
}) => [raise({
|
|
5677
|
+
type: "deserialize",
|
|
5678
|
+
originEvent: event
|
|
5679
|
+
})]]
|
|
5680
|
+
}),
|
|
5681
|
+
/**
|
|
5682
|
+
* Otherwise, we should to create a new selection.
|
|
5683
|
+
*/
|
|
5684
|
+
defineBehavior({
|
|
5685
|
+
on: "drag.drop",
|
|
5686
|
+
actions: [({
|
|
5687
|
+
event
|
|
5688
|
+
}) => [raise({
|
|
5689
|
+
type: "select",
|
|
5690
|
+
at: event.position.selection
|
|
5691
|
+
}), raise({
|
|
5692
|
+
type: "deserialize",
|
|
5693
|
+
originEvent: event
|
|
5694
|
+
})]]
|
|
5695
|
+
}),
|
|
5696
|
+
/**
|
|
5697
|
+
* Core Behavior that uses the drag origin to mimic a move operation during
|
|
5698
|
+
* internal dragging.
|
|
5699
|
+
*/
|
|
5700
|
+
defineBehavior({
|
|
5701
|
+
on: "deserialization.success",
|
|
5702
|
+
guard: ({
|
|
5703
|
+
snapshot,
|
|
5704
|
+
event
|
|
5705
|
+
}) => {
|
|
5706
|
+
if (event.originEvent.type !== "drag.drop" || event.originEvent.dragOrigin === void 0)
|
|
5707
|
+
return !1;
|
|
5708
|
+
const dragOrigin = event.originEvent.dragOrigin, dragSelection = getDragSelection({
|
|
5709
|
+
eventSelection: dragOrigin.selection,
|
|
5710
|
+
snapshot
|
|
5711
|
+
}), dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
5712
|
+
...snapshot,
|
|
5713
|
+
context: {
|
|
5714
|
+
...snapshot.context,
|
|
5715
|
+
selection: dragSelection
|
|
5716
|
+
}
|
|
5717
|
+
}) : !1, draggingEntireBlocks = isSelectingEntireBlocks({
|
|
5718
|
+
context: {
|
|
5719
|
+
...snapshot.context,
|
|
5720
|
+
selection: dragSelection
|
|
5721
|
+
}
|
|
5722
|
+
}), draggedBlocks = getSelectedBlocks({
|
|
5723
|
+
context: {
|
|
5724
|
+
...snapshot.context,
|
|
5725
|
+
selection: dragSelection
|
|
5726
|
+
}
|
|
5727
|
+
});
|
|
5728
|
+
return droppingOnDragOrigin ? !1 : {
|
|
5729
|
+
dropPosition,
|
|
5730
|
+
draggingEntireBlocks,
|
|
5731
|
+
draggedBlocks,
|
|
5732
|
+
dragOrigin,
|
|
5733
|
+
originEvent: event.originEvent
|
|
5734
|
+
};
|
|
5735
|
+
},
|
|
5736
|
+
actions: [({
|
|
5737
|
+
event
|
|
5738
|
+
}, {
|
|
5739
|
+
draggingEntireBlocks,
|
|
5740
|
+
draggedBlocks,
|
|
5741
|
+
dragOrigin,
|
|
5742
|
+
dropPosition,
|
|
5743
|
+
originEvent
|
|
5744
|
+
}) => [...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
|
|
5745
|
+
type: "delete.block",
|
|
5746
|
+
at: block.path
|
|
5747
|
+
})) : [raise({
|
|
5748
|
+
type: "delete",
|
|
5749
|
+
at: dragOrigin.selection
|
|
5750
|
+
})], raise({
|
|
5751
|
+
type: "select",
|
|
5752
|
+
at: dropPosition
|
|
5753
|
+
}), raise({
|
|
5754
|
+
type: "insert.blocks",
|
|
5755
|
+
blocks: event.data,
|
|
5756
|
+
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
5757
|
+
})]]
|
|
5604
5758
|
})
|
|
5605
5759
|
], breakingAtTheEndOfTextBlock = defineBehavior({
|
|
5606
5760
|
on: "insert.break",
|
|
5607
5761
|
guard: ({
|
|
5608
5762
|
snapshot
|
|
5609
5763
|
}) => {
|
|
5610
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
5764
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
5611
5765
|
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
5612
5766
|
return !1;
|
|
5613
5767
|
const atTheEndOfBlock = isAtTheEndOfBlock(focusTextBlock)(snapshot), focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
@@ -5642,7 +5796,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5642
5796
|
guard: ({
|
|
5643
5797
|
snapshot
|
|
5644
5798
|
}) => {
|
|
5645
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
5799
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
5646
5800
|
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
5647
5801
|
return !1;
|
|
5648
5802
|
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 +5908,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5754
5908
|
guard: ({
|
|
5755
5909
|
snapshot
|
|
5756
5910
|
}) => {
|
|
5757
|
-
const selectionCollapsed = isSelectionCollapsed(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5911
|
+
const selectionCollapsed = isSelectionCollapsed$1(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5758
5912
|
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
5759
5913
|
focusTextBlock
|
|
5760
5914
|
} : !1;
|
|
@@ -5771,7 +5925,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5771
5925
|
guard: ({
|
|
5772
5926
|
snapshot
|
|
5773
5927
|
}) => {
|
|
5774
|
-
const selectionCollapsed = isSelectionCollapsed(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5928
|
+
const selectionCollapsed = isSelectionCollapsed$1(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5775
5929
|
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
5930
|
focusTextBlock,
|
|
5777
5931
|
level: focusTextBlock.node.level - 1
|
|
@@ -5792,7 +5946,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5792
5946
|
guard: ({
|
|
5793
5947
|
snapshot
|
|
5794
5948
|
}) => {
|
|
5795
|
-
const selectionCollapsed = isSelectionCollapsed(snapshot), focusListBlock = getFocusListBlock(snapshot);
|
|
5949
|
+
const selectionCollapsed = isSelectionCollapsed$1(snapshot), focusListBlock = getFocusListBlock(snapshot);
|
|
5796
5950
|
return !selectionCollapsed || !focusListBlock || !isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
|
|
5797
5951
|
focusListBlock
|
|
5798
5952
|
};
|
|
@@ -5863,7 +6017,52 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5863
6017
|
}, 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
6018
|
behavior,
|
|
5865
6019
|
priority: corePriority
|
|
5866
|
-
}))
|
|
6020
|
+
}));
|
|
6021
|
+
function createEditorDom(sendBack, slateEditor) {
|
|
6022
|
+
return {
|
|
6023
|
+
getBlockNodes: (snapshot) => getBlockNodes(slateEditor, snapshot),
|
|
6024
|
+
getChildNodes: (snapshot) => getChildNodes(slateEditor, snapshot),
|
|
6025
|
+
setDragGhost: ({
|
|
6026
|
+
event,
|
|
6027
|
+
ghost
|
|
6028
|
+
}) => setDragGhost({
|
|
6029
|
+
sendBack,
|
|
6030
|
+
event,
|
|
6031
|
+
ghost
|
|
6032
|
+
})
|
|
6033
|
+
};
|
|
6034
|
+
}
|
|
6035
|
+
function getBlockNodes(slateEditor, snapshot) {
|
|
6036
|
+
if (!snapshot.context.selection)
|
|
6037
|
+
return [];
|
|
6038
|
+
const range = toSlateRange(snapshot.context.selection, slateEditor);
|
|
6039
|
+
return range ? Array.from(Editor.nodes(slateEditor, {
|
|
6040
|
+
at: range,
|
|
6041
|
+
mode: "highest",
|
|
6042
|
+
match: (n) => !Editor.isEditor(n)
|
|
6043
|
+
})).map(([blockNode]) => DOMEditor.toDOMNode(slateEditor, blockNode)) : [];
|
|
6044
|
+
}
|
|
6045
|
+
function getChildNodes(slateEditor, snapshot) {
|
|
6046
|
+
if (!snapshot.context.selection)
|
|
6047
|
+
return [];
|
|
6048
|
+
const range = toSlateRange(snapshot.context.selection, slateEditor);
|
|
6049
|
+
return range ? Array.from(Editor.nodes(slateEditor, {
|
|
6050
|
+
at: range,
|
|
6051
|
+
mode: "lowest",
|
|
6052
|
+
match: (n) => !Editor.isEditor(n)
|
|
6053
|
+
})).map(([childNode]) => DOMEditor.toDOMNode(slateEditor, childNode)) : [];
|
|
6054
|
+
}
|
|
6055
|
+
function setDragGhost({
|
|
6056
|
+
sendBack,
|
|
6057
|
+
event,
|
|
6058
|
+
ghost
|
|
6059
|
+
}) {
|
|
6060
|
+
event.originEvent.dataTransfer.setDragImage(ghost.element, ghost.x, ghost.y), sendBack({
|
|
6061
|
+
type: "set drag ghost",
|
|
6062
|
+
ghost: ghost.element
|
|
6063
|
+
});
|
|
6064
|
+
}
|
|
6065
|
+
const abstractAnnotationBehaviors = [defineBehavior({
|
|
5867
6066
|
on: "annotation.toggle",
|
|
5868
6067
|
guard: ({
|
|
5869
6068
|
snapshot,
|
|
@@ -6389,7 +6588,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6389
6588
|
actions: [(_, {
|
|
6390
6589
|
newTextBlock,
|
|
6391
6590
|
selection
|
|
6392
|
-
}) => isSelectionCollapsed
|
|
6591
|
+
}) => isSelectionCollapsed(selection) ? [raise({
|
|
6393
6592
|
type: "insert.block",
|
|
6394
6593
|
block: newTextBlock,
|
|
6395
6594
|
placement: "after",
|
|
@@ -6525,7 +6724,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6525
6724
|
guard: ({
|
|
6526
6725
|
snapshot
|
|
6527
6726
|
}) => {
|
|
6528
|
-
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6727
|
+
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
6529
6728
|
return focusSpan && selectionCollapsed;
|
|
6530
6729
|
},
|
|
6531
6730
|
actions: []
|
|
@@ -6544,7 +6743,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6544
6743
|
guard: ({
|
|
6545
6744
|
snapshot
|
|
6546
6745
|
}) => {
|
|
6547
|
-
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6746
|
+
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
6548
6747
|
return focusSpan && selectionCollapsed;
|
|
6549
6748
|
},
|
|
6550
6749
|
actions: []
|
|
@@ -6599,86 +6798,6 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6599
6798
|
}
|
|
6600
6799
|
}]]
|
|
6601
6800
|
}),
|
|
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
6801
|
/**
|
|
6683
6802
|
* If we are pasting text/plain into a text block then we can probably
|
|
6684
6803
|
* assume that the intended behavior is that the pasted text inherits
|
|
@@ -6830,7 +6949,8 @@ function performEvent({
|
|
|
6830
6949
|
keyGenerator,
|
|
6831
6950
|
schema,
|
|
6832
6951
|
getSnapshot,
|
|
6833
|
-
nativeEvent
|
|
6952
|
+
nativeEvent,
|
|
6953
|
+
sendBack
|
|
6834
6954
|
}) {
|
|
6835
6955
|
debug$9(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
6836
6956
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
@@ -6862,7 +6982,8 @@ function performEvent({
|
|
|
6862
6982
|
try {
|
|
6863
6983
|
shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
|
|
6864
6984
|
snapshot: guardSnapshot,
|
|
6865
|
-
event
|
|
6985
|
+
event,
|
|
6986
|
+
dom: createEditorDom(sendBack, editor)
|
|
6866
6987
|
});
|
|
6867
6988
|
} catch (error) {
|
|
6868
6989
|
console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
|
|
@@ -6875,7 +6996,8 @@ function performEvent({
|
|
|
6875
6996
|
try {
|
|
6876
6997
|
actions = actionSet({
|
|
6877
6998
|
snapshot: actionsSnapshot,
|
|
6878
|
-
event
|
|
6999
|
+
event,
|
|
7000
|
+
dom: createEditorDom(sendBack, editor)
|
|
6879
7001
|
}, shouldRun);
|
|
6880
7002
|
} catch (error) {
|
|
6881
7003
|
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
@@ -6904,7 +7026,8 @@ function performEvent({
|
|
|
6904
7026
|
keyGenerator,
|
|
6905
7027
|
schema,
|
|
6906
7028
|
getSnapshot,
|
|
6907
|
-
nativeEvent
|
|
7029
|
+
nativeEvent,
|
|
7030
|
+
sendBack
|
|
6908
7031
|
});
|
|
6909
7032
|
continue;
|
|
6910
7033
|
}
|
|
@@ -6918,7 +7041,8 @@ function performEvent({
|
|
|
6918
7041
|
keyGenerator,
|
|
6919
7042
|
schema,
|
|
6920
7043
|
getSnapshot,
|
|
6921
|
-
nativeEvent
|
|
7044
|
+
nativeEvent,
|
|
7045
|
+
sendBack
|
|
6922
7046
|
});
|
|
6923
7047
|
continue;
|
|
6924
7048
|
}
|
|
@@ -6931,7 +7055,8 @@ function performEvent({
|
|
|
6931
7055
|
keyGenerator,
|
|
6932
7056
|
schema,
|
|
6933
7057
|
getSnapshot,
|
|
6934
|
-
nativeEvent: void 0
|
|
7058
|
+
nativeEvent: void 0,
|
|
7059
|
+
sendBack
|
|
6935
7060
|
});
|
|
6936
7061
|
}
|
|
6937
7062
|
});
|
|
@@ -6958,7 +7083,8 @@ function performEvent({
|
|
|
6958
7083
|
keyGenerator,
|
|
6959
7084
|
schema,
|
|
6960
7085
|
getSnapshot,
|
|
6961
|
-
nativeEvent
|
|
7086
|
+
nativeEvent,
|
|
7087
|
+
sendBack
|
|
6962
7088
|
});
|
|
6963
7089
|
continue;
|
|
6964
7090
|
}
|
|
@@ -6972,7 +7098,8 @@ function performEvent({
|
|
|
6972
7098
|
keyGenerator,
|
|
6973
7099
|
schema,
|
|
6974
7100
|
getSnapshot,
|
|
6975
|
-
nativeEvent
|
|
7101
|
+
nativeEvent,
|
|
7102
|
+
sendBack
|
|
6976
7103
|
});
|
|
6977
7104
|
continue;
|
|
6978
7105
|
}
|
|
@@ -7044,8 +7171,7 @@ function createEditorSnapshot({
|
|
|
7044
7171
|
editor,
|
|
7045
7172
|
keyGenerator,
|
|
7046
7173
|
readOnly,
|
|
7047
|
-
schema
|
|
7048
|
-
internalDrag
|
|
7174
|
+
schema
|
|
7049
7175
|
}) {
|
|
7050
7176
|
const selection = editor.selection ? slateRangeToSelection({
|
|
7051
7177
|
schema,
|
|
@@ -7070,8 +7196,7 @@ function createEditorSnapshot({
|
|
|
7070
7196
|
decoratorState: editor.decoratorState,
|
|
7071
7197
|
markState: editor.markState,
|
|
7072
7198
|
schema
|
|
7073
|
-
})
|
|
7074
|
-
internalDrag
|
|
7199
|
+
})
|
|
7075
7200
|
}
|
|
7076
7201
|
};
|
|
7077
7202
|
}
|
|
@@ -7193,10 +7318,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7193
7318
|
readOnly: self.getSnapshot().matches({
|
|
7194
7319
|
"edit mode": "read only"
|
|
7195
7320
|
}),
|
|
7196
|
-
schema: context.schema
|
|
7197
|
-
internalDrag: context.internalDrag
|
|
7321
|
+
schema: context.schema
|
|
7198
7322
|
}),
|
|
7199
|
-
nativeEvent: event.nativeEvent
|
|
7323
|
+
nativeEvent: event.nativeEvent,
|
|
7324
|
+
sendBack: (event2) => self.send(event2)
|
|
7200
7325
|
});
|
|
7201
7326
|
} catch (error) {
|
|
7202
7327
|
console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
@@ -7250,6 +7375,13 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7250
7375
|
...event,
|
|
7251
7376
|
type: "selection"
|
|
7252
7377
|
}))]
|
|
7378
|
+
},
|
|
7379
|
+
"set drag ghost": {
|
|
7380
|
+
actions: assign({
|
|
7381
|
+
dragGhost: ({
|
|
7382
|
+
event
|
|
7383
|
+
}) => event.ghost
|
|
7384
|
+
})
|
|
7253
7385
|
}
|
|
7254
7386
|
},
|
|
7255
7387
|
type: "parallel",
|
|
@@ -7344,7 +7476,6 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7344
7476
|
internalDrag: ({
|
|
7345
7477
|
event
|
|
7346
7478
|
}) => ({
|
|
7347
|
-
ghost: event.ghost,
|
|
7348
7479
|
origin: event.origin
|
|
7349
7480
|
})
|
|
7350
7481
|
})],
|
|
@@ -7394,13 +7525,15 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7394
7525
|
}, ({
|
|
7395
7526
|
context
|
|
7396
7527
|
}) => {
|
|
7397
|
-
if (context.
|
|
7528
|
+
if (context.dragGhost)
|
|
7398
7529
|
try {
|
|
7399
|
-
context.
|
|
7530
|
+
context.dragGhost.parentNode?.removeChild(context.dragGhost);
|
|
7400
7531
|
} catch (error) {
|
|
7401
|
-
console.error(new Error(`Removing the
|
|
7532
|
+
console.error(new Error(`Removing the drag ghost failed due to: ${error.message}`));
|
|
7402
7533
|
}
|
|
7403
7534
|
}, assign({
|
|
7535
|
+
dragGhost: void 0
|
|
7536
|
+
}), assign({
|
|
7404
7537
|
internalDrag: void 0
|
|
7405
7538
|
})],
|
|
7406
7539
|
tags: ["dragging internally"],
|
|
@@ -10781,73 +10914,19 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10781
10914
|
console.warn("Could not find position for dragstart event");
|
|
10782
10915
|
return;
|
|
10783
10916
|
}
|
|
10784
|
-
const snapshot = getEditorSnapshot({
|
|
10785
|
-
editorActorSnapshot: editorActor.getSnapshot(),
|
|
10786
|
-
slateEditorInstance: slateEditor
|
|
10787
|
-
}), dragSelection = getDragSelection({
|
|
10788
|
-
eventSelection: position_4.selection,
|
|
10789
|
-
snapshot
|
|
10790
|
-
}), selectingEntireBlocks = isSelectingEntireBlocks({
|
|
10791
|
-
context: {
|
|
10792
|
-
...snapshot.context,
|
|
10793
|
-
selection: dragSelection
|
|
10794
|
-
}
|
|
10795
|
-
}), dragGhost = document.createElement("div"), draggedDomNodes = getSelectionDomNodes({
|
|
10796
|
-
snapshot: {
|
|
10797
|
-
context: {
|
|
10798
|
-
...snapshot.context,
|
|
10799
|
-
selection: dragSelection
|
|
10800
|
-
}
|
|
10801
|
-
},
|
|
10802
|
-
slateEditor
|
|
10803
|
-
});
|
|
10804
|
-
if (selectingEntireBlocks) {
|
|
10805
|
-
const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) => node.cloneNode(!0));
|
|
10806
|
-
for (const block of clonedBlockNodes)
|
|
10807
|
-
block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
|
|
10808
|
-
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
10809
|
-
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) {
|
|
10810
|
-
const customGhostRect = customGhost.getBoundingClientRect(), x = event_8.clientX - customGhostRect.left, y = event_8.clientY - customGhostRect.top;
|
|
10811
|
-
dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x, y);
|
|
10812
|
-
} else {
|
|
10813
|
-
const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x_0 = event_8.clientX - blocksDomRect.left, y_0 = event_8.clientY - blocksDomRect.top;
|
|
10814
|
-
dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_0, y_0);
|
|
10815
|
-
}
|
|
10816
|
-
} else {
|
|
10817
|
-
const clonedChildNodes = draggedDomNodes.childNodes.map((node_0) => node_0.cloneNode(!0));
|
|
10818
|
-
for (const child of clonedChildNodes)
|
|
10819
|
-
dragGhost.appendChild(child);
|
|
10820
|
-
dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
10821
|
-
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
|
|
10822
|
-
dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
|
|
10823
|
-
}
|
|
10824
10917
|
return editorActor.send({
|
|
10825
|
-
type: "behavior event",
|
|
10826
|
-
behaviorEvent: {
|
|
10827
|
-
type: "select",
|
|
10828
|
-
at: isSelectionCollapsed$1(dragSelection) ? dragSelection : {
|
|
10829
|
-
anchor: getSelectionEndPoint(dragSelection),
|
|
10830
|
-
focus: getSelectionEndPoint(dragSelection),
|
|
10831
|
-
backward: !1
|
|
10832
|
-
}
|
|
10833
|
-
},
|
|
10834
|
-
editor: slateEditor
|
|
10835
|
-
}), editorActor.send({
|
|
10836
10918
|
type: "dragstart",
|
|
10837
|
-
origin:
|
|
10838
|
-
selection: dragSelection
|
|
10839
|
-
},
|
|
10840
|
-
ghost: dragGhost
|
|
10919
|
+
origin: position_4
|
|
10841
10920
|
}), editorActor.send({
|
|
10842
10921
|
type: "behavior event",
|
|
10843
10922
|
behaviorEvent: {
|
|
10844
10923
|
type: "drag.dragstart",
|
|
10845
10924
|
originEvent: {
|
|
10925
|
+
clientX: event_8.clientX,
|
|
10926
|
+
clientY: event_8.clientY,
|
|
10846
10927
|
dataTransfer: event_8.dataTransfer
|
|
10847
10928
|
},
|
|
10848
|
-
position:
|
|
10849
|
-
selection: dragSelection
|
|
10850
|
-
}
|
|
10929
|
+
position: position_4
|
|
10851
10930
|
},
|
|
10852
10931
|
editor: slateEditor
|
|
10853
10932
|
}), !0;
|
|
@@ -10915,6 +10994,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10915
10994
|
originEvent: {
|
|
10916
10995
|
dataTransfer: event_12.dataTransfer
|
|
10917
10996
|
},
|
|
10997
|
+
dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
|
|
10918
10998
|
position: position_7
|
|
10919
10999
|
},
|
|
10920
11000
|
editor: slateEditor,
|
|
@@ -10939,6 +11019,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10939
11019
|
originEvent: {
|
|
10940
11020
|
dataTransfer: event_13.dataTransfer
|
|
10941
11021
|
},
|
|
11022
|
+
dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
|
|
10942
11023
|
position: position_8
|
|
10943
11024
|
},
|
|
10944
11025
|
editor: slateEditor,
|