@portabletext/editor 1.40.3 → 1.41.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/editor-provider.cjs +72 -34
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +10 -0
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +73 -35
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +11 -0
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.cjs +307 -144
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +309 -145
- package/lib/index.js.map +1 -1
- package/lib/utils/index.cjs +7 -5
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +23 -2
- package/lib/utils/index.d.ts +23 -2
- package/lib/utils/index.js +6 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +4 -4
- package/src/behavior-actions/behavior.action.insert-blocks.ts +5 -1
- package/src/converters/converter.text-plain.ts +24 -11
- package/src/editor/Editable.tsx +336 -223
- package/src/editor/components/drop-indicator.tsx +4 -1
- package/src/internal-utils/drag-selection.test.ts +74 -1
- package/src/internal-utils/drag-selection.ts +20 -4
- package/src/internal-utils/dragging-on-drag-origin.ts +22 -0
- package/src/internal-utils/event-position.ts +69 -10
- package/src/internal-utils/slate-utils.ts +74 -6
- package/src/utils/index.ts +2 -0
- package/src/utils/util.get-selection-end-point.ts +20 -0
- package/src/utils/util.get-selection-start-point.ts +20 -0
- package/src/utils/util.is-keyed-segment.ts +2 -2
package/lib/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var editorProvider = require("./_chunks-cjs/editor-provider.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isAtTheStartOfBlock = require("./_chunks-cjs/selector.is-at-the-start-of-block.cjs"), selector_isOverlappingSelection = require("./_chunks-cjs/selector.is-overlapping-selection.cjs"), slateDom = require("slate-dom"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), useEffectEvent = require("use-effect-event");
|
|
3
|
+
var editorProvider = require("./_chunks-cjs/editor-provider.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isAtTheStartOfBlock = require("./_chunks-cjs/selector.is-at-the-start-of-block.cjs"), selector_isOverlappingSelection = require("./_chunks-cjs/selector.is-overlapping-selection.cjs"), slateDom = require("slate-dom"), util_isSelectionCollapsed = require("./_chunks-cjs/util.is-selection-collapsed.cjs"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), useEffectEvent = require("use-effect-event");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -44,15 +44,40 @@ function getDragSelection({
|
|
|
44
44
|
focus: util_sliceBlocks.getBlockEndPoint(focusTextBlock)
|
|
45
45
|
});
|
|
46
46
|
const selectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks(snapshot);
|
|
47
|
-
if (snapshot.context.selection && selector_isAtTheStartOfBlock.isSelectionExpanded(snapshot) &&
|
|
47
|
+
if (snapshot.context.selection && selector_isAtTheStartOfBlock.isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
48
48
|
const selectionStartBlock = selector_isAtTheStartOfBlock.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isAtTheStartOfBlock.getSelectionEndBlock(snapshot);
|
|
49
|
-
selectionStartBlock
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (!selectionStartBlock || !selectionEndBlock)
|
|
50
|
+
return dragSelection;
|
|
51
|
+
const selectionStartPoint = util_sliceBlocks.getBlockStartPoint(selectionStartBlock), selectionEndPoint = util_sliceBlocks.getBlockEndPoint(selectionEndBlock);
|
|
52
|
+
selector_isOverlappingSelection.isOverlappingSelection(eventSelection)({
|
|
53
|
+
...snapshot,
|
|
54
|
+
context: {
|
|
55
|
+
...snapshot.context,
|
|
56
|
+
selection: {
|
|
57
|
+
anchor: selectionStartPoint,
|
|
58
|
+
focus: selectionEndPoint
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}) && (dragSelection = {
|
|
62
|
+
anchor: selectionStartPoint,
|
|
63
|
+
focus: selectionEndPoint
|
|
52
64
|
});
|
|
53
65
|
}
|
|
54
66
|
return dragSelection;
|
|
55
67
|
}
|
|
68
|
+
function draggingOnDragOrigin({
|
|
69
|
+
snapshot,
|
|
70
|
+
position
|
|
71
|
+
}) {
|
|
72
|
+
const dragOrigin = snapshot.beta.internalDrag?.origin;
|
|
73
|
+
return dragOrigin ? selector_isOverlappingSelection.isOverlappingSelection(position.selection)({
|
|
74
|
+
...snapshot,
|
|
75
|
+
context: {
|
|
76
|
+
...snapshot.context,
|
|
77
|
+
selection: dragOrigin.selection
|
|
78
|
+
}
|
|
79
|
+
}) : !1;
|
|
80
|
+
}
|
|
56
81
|
function getEventPosition({
|
|
57
82
|
schema,
|
|
58
83
|
slateEditor,
|
|
@@ -64,7 +89,11 @@ function getEventPosition({
|
|
|
64
89
|
});
|
|
65
90
|
if (!node)
|
|
66
91
|
return;
|
|
67
|
-
const
|
|
92
|
+
const block = editorProvider.getNodeBlock({
|
|
93
|
+
editor: slateEditor,
|
|
94
|
+
schema,
|
|
95
|
+
node
|
|
96
|
+
}), positionBlock = getEventPositionBlock({
|
|
68
97
|
node,
|
|
69
98
|
slateEditor,
|
|
70
99
|
event
|
|
@@ -73,9 +102,8 @@ function getEventPosition({
|
|
|
73
102
|
slateEditor,
|
|
74
103
|
event
|
|
75
104
|
});
|
|
76
|
-
if (positionBlock && !selection && !slate.Editor.isEditor(node))
|
|
77
|
-
|
|
78
|
-
return block ? {
|
|
105
|
+
if (block && positionBlock && !selection && !slate.Editor.isEditor(node))
|
|
106
|
+
return {
|
|
79
107
|
block: positionBlock,
|
|
80
108
|
isEditor: !1,
|
|
81
109
|
selection: {
|
|
@@ -92,10 +120,29 @@ function getEventPosition({
|
|
|
92
120
|
}]
|
|
93
121
|
})
|
|
94
122
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
123
|
+
};
|
|
124
|
+
if (!positionBlock || !selection)
|
|
125
|
+
return;
|
|
126
|
+
const focusBlockPath = selection.focus.path.at(0), focusBlockKey = util_sliceBlocks.isKeyedSegment(focusBlockPath) ? focusBlockPath._key : void 0;
|
|
127
|
+
if (focusBlockKey)
|
|
128
|
+
return util_isSelectionCollapsed.isSelectionCollapsed(selection) && block && focusBlockKey !== block._key ? {
|
|
129
|
+
block: positionBlock,
|
|
130
|
+
isEditor: !1,
|
|
131
|
+
selection: {
|
|
132
|
+
anchor: util_sliceBlocks.getBlockStartPoint({
|
|
133
|
+
node: block,
|
|
134
|
+
path: [{
|
|
135
|
+
_key: block._key
|
|
136
|
+
}]
|
|
137
|
+
}),
|
|
138
|
+
focus: util_sliceBlocks.getBlockEndPoint({
|
|
139
|
+
node: block,
|
|
140
|
+
path: [{
|
|
141
|
+
_key: block._key
|
|
142
|
+
}]
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
} : {
|
|
99
146
|
block: positionBlock,
|
|
100
147
|
isEditor: slate.Editor.isEditor(node),
|
|
101
148
|
selection
|
|
@@ -112,6 +159,22 @@ function getEventPositionBlock({
|
|
|
112
159
|
slateEditor,
|
|
113
160
|
event
|
|
114
161
|
}) {
|
|
162
|
+
const [firstBlock] = editorProvider.getFirstBlock({
|
|
163
|
+
editor: slateEditor
|
|
164
|
+
});
|
|
165
|
+
if (!firstBlock)
|
|
166
|
+
return;
|
|
167
|
+
const firstBlockRect = slateDom.DOMEditor.toDOMNode(slateEditor, firstBlock).getBoundingClientRect();
|
|
168
|
+
if (event.pageY < firstBlockRect.top)
|
|
169
|
+
return "start";
|
|
170
|
+
const [lastBlock] = editorProvider.getLastBlock({
|
|
171
|
+
editor: slateEditor
|
|
172
|
+
});
|
|
173
|
+
if (!lastBlock)
|
|
174
|
+
return;
|
|
175
|
+
const lastBlockRef = slateDom.DOMEditor.toDOMNode(slateEditor, lastBlock).getBoundingClientRect();
|
|
176
|
+
if (event.pageY > lastBlockRef.bottom)
|
|
177
|
+
return "end";
|
|
115
178
|
const elementRect = slateDom.DOMEditor.toDOMNode(slateEditor, node).getBoundingClientRect(), top = elementRect.top, height = elementRect.height;
|
|
116
179
|
return Math.abs(top - event.pageY) < height / 2 ? "start" : "end";
|
|
117
180
|
}
|
|
@@ -130,7 +193,11 @@ function getSlateRangeFromEvent(editor, event) {
|
|
|
130
193
|
let domRange;
|
|
131
194
|
if (window2.document.caretPositionFromPoint !== void 0) {
|
|
132
195
|
const position = window2.document.caretPositionFromPoint(event.clientX, event.clientY);
|
|
133
|
-
|
|
196
|
+
if (position)
|
|
197
|
+
try {
|
|
198
|
+
domRange = window2.document.createRange(), domRange.setStart(position.offsetNode, position.offset), domRange.setEnd(position.offsetNode, position.offset);
|
|
199
|
+
} catch {
|
|
200
|
+
}
|
|
134
201
|
} else if (window2.document.caretRangeFromPoint !== void 0)
|
|
135
202
|
domRange = window2.document.caretRangeFromPoint(event.clientX, event.clientY) ?? void 0;
|
|
136
203
|
else {
|
|
@@ -258,13 +325,13 @@ function DefaultInlineObject(props) {
|
|
|
258
325
|
function DropIndicator() {
|
|
259
326
|
const $ = reactCompilerRuntime.c(1);
|
|
260
327
|
let t0;
|
|
261
|
-
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-drop-indicator", style: {
|
|
328
|
+
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsxRuntime.jsx("div", { contentEditable: !1, className: "pt-drop-indicator", style: {
|
|
262
329
|
position: "absolute",
|
|
263
330
|
width: "100%",
|
|
264
331
|
height: 1,
|
|
265
332
|
borderBottom: "1px solid currentColor",
|
|
266
333
|
zIndex: 5
|
|
267
|
-
} }), $[0] = t0) : t0 = $[0], t0;
|
|
334
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("span", {}) }), $[0] = t0) : t0 = $[0], t0;
|
|
268
335
|
}
|
|
269
336
|
editorProvider.debugWithName("components:Element");
|
|
270
337
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
@@ -1077,78 +1144,111 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1077
1144
|
};
|
|
1078
1145
|
}, [slateEditor, editorActor]);
|
|
1079
1146
|
const handleDragStart = React.useCallback((event_8) => {
|
|
1080
|
-
if (onDragStart?.(event_8),
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1147
|
+
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
1148
|
+
return;
|
|
1149
|
+
event_8.stopPropagation();
|
|
1150
|
+
const position_4 = getEventPosition({
|
|
1151
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1152
|
+
slateEditor,
|
|
1153
|
+
event: event_8.nativeEvent
|
|
1154
|
+
});
|
|
1155
|
+
if (!position_4) {
|
|
1156
|
+
console.warn("Could not find position for dragstart event");
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
const snapshot = editorProvider.getEditorSnapshot({
|
|
1160
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1161
|
+
slateEditorInstance: slateEditor
|
|
1162
|
+
}), dragSelection = getDragSelection({
|
|
1163
|
+
eventSelection: position_4.selection,
|
|
1164
|
+
snapshot
|
|
1165
|
+
}), selectingEntireBlocks = selector_isOverlappingSelection.isSelectingEntireBlocks({
|
|
1166
|
+
context: {
|
|
1167
|
+
...snapshot.context,
|
|
1168
|
+
selection: dragSelection
|
|
1089
1169
|
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
slateEditorInstance: slateEditor
|
|
1093
|
-
}), dragSelection = getDragSelection({
|
|
1094
|
-
eventSelection: position_4.selection,
|
|
1095
|
-
snapshot
|
|
1096
|
-
}), selectingEntireBlocks = selector_isOverlappingSelection.isSelectingEntireBlocks({
|
|
1170
|
+
}), dragGhost = document.createElement("div"), draggedDomNodes = getSelectionDomNodes({
|
|
1171
|
+
snapshot: {
|
|
1097
1172
|
context: {
|
|
1098
1173
|
...snapshot.context,
|
|
1099
1174
|
selection: dragSelection
|
|
1100
1175
|
}
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
for (const block of clonedBlockNodes)
|
|
1113
|
-
block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
|
|
1114
|
-
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
1115
|
-
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) {
|
|
1116
|
-
const customGhostRect = customGhost.getBoundingClientRect(), x = event_8.clientX - customGhostRect.left, y = event_8.clientY - customGhostRect.top;
|
|
1117
|
-
dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x, y);
|
|
1118
|
-
} else {
|
|
1119
|
-
const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x_0 = event_8.clientX - blocksDomRect.left, y_0 = event_8.clientY - blocksDomRect.top;
|
|
1120
|
-
dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_0, y_0);
|
|
1121
|
-
}
|
|
1176
|
+
},
|
|
1177
|
+
slateEditor
|
|
1178
|
+
});
|
|
1179
|
+
if (selectingEntireBlocks) {
|
|
1180
|
+
const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) => node.cloneNode(!0));
|
|
1181
|
+
for (const block of clonedBlockNodes)
|
|
1182
|
+
block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
|
|
1183
|
+
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
1184
|
+
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) {
|
|
1185
|
+
const customGhostRect = customGhost.getBoundingClientRect(), x = event_8.clientX - customGhostRect.left, y = event_8.clientY - customGhostRect.top;
|
|
1186
|
+
dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x, y);
|
|
1122
1187
|
} else {
|
|
1123
|
-
const
|
|
1124
|
-
|
|
1125
|
-
dragGhost.appendChild(child);
|
|
1126
|
-
dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
1127
|
-
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
|
|
1128
|
-
dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
|
|
1188
|
+
const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x_0 = event_8.clientX - blocksDomRect.left, y_0 = event_8.clientY - blocksDomRect.top;
|
|
1189
|
+
dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_0, y_0);
|
|
1129
1190
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
}
|
|
1137
|
-
type: "behavior event",
|
|
1138
|
-
behaviorEvent: {
|
|
1139
|
-
type: "drag.dragstart",
|
|
1140
|
-
originEvent: {
|
|
1141
|
-
dataTransfer: event_8.dataTransfer
|
|
1142
|
-
},
|
|
1143
|
-
position: {
|
|
1144
|
-
selection: dragSelection
|
|
1145
|
-
}
|
|
1146
|
-
},
|
|
1147
|
-
editor: slateEditor
|
|
1148
|
-
}), event_8.stopPropagation();
|
|
1191
|
+
} else {
|
|
1192
|
+
const clonedChildNodes = draggedDomNodes.childNodes.map((node_0) => node_0.cloneNode(!0));
|
|
1193
|
+
for (const child of clonedChildNodes)
|
|
1194
|
+
dragGhost.appendChild(child);
|
|
1195
|
+
dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
1196
|
+
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
|
|
1197
|
+
dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
|
|
1149
1198
|
}
|
|
1199
|
+
editorActor.send({
|
|
1200
|
+
type: "behavior event",
|
|
1201
|
+
behaviorEvent: {
|
|
1202
|
+
type: "select",
|
|
1203
|
+
selection: util_isSelectionCollapsed.isSelectionCollapsed(dragSelection) ? dragSelection : {
|
|
1204
|
+
anchor: util_isSelectionCollapsed.getSelectionEndPoint(dragSelection),
|
|
1205
|
+
focus: util_isSelectionCollapsed.getSelectionEndPoint(dragSelection),
|
|
1206
|
+
backward: !1
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
editor: slateEditor
|
|
1210
|
+
}), editorActor.send({
|
|
1211
|
+
type: "dragstart",
|
|
1212
|
+
origin: {
|
|
1213
|
+
selection: dragSelection
|
|
1214
|
+
},
|
|
1215
|
+
ghost: dragGhost
|
|
1216
|
+
}), editorActor.send({
|
|
1217
|
+
type: "behavior event",
|
|
1218
|
+
behaviorEvent: {
|
|
1219
|
+
type: "drag.dragstart",
|
|
1220
|
+
originEvent: {
|
|
1221
|
+
dataTransfer: event_8.dataTransfer
|
|
1222
|
+
},
|
|
1223
|
+
position: {
|
|
1224
|
+
selection: dragSelection
|
|
1225
|
+
}
|
|
1226
|
+
},
|
|
1227
|
+
editor: slateEditor
|
|
1228
|
+
});
|
|
1150
1229
|
}, [onDragStart, editorActor, slateEditor]), handleDrag = React.useCallback((event_9) => {
|
|
1151
|
-
onDrag?.(event_9),
|
|
1230
|
+
if (onDrag?.(event_9), event_9.isDefaultPrevented() || event_9.isPropagationStopped())
|
|
1231
|
+
return;
|
|
1232
|
+
event_9.stopPropagation();
|
|
1233
|
+
const position_5 = getEventPosition({
|
|
1234
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1235
|
+
slateEditor,
|
|
1236
|
+
event: event_9.nativeEvent
|
|
1237
|
+
});
|
|
1238
|
+
if (!position_5)
|
|
1239
|
+
return;
|
|
1240
|
+
const snapshot_0 = editorProvider.getEditorSnapshot({
|
|
1241
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1242
|
+
slateEditorInstance: slateEditor
|
|
1243
|
+
});
|
|
1244
|
+
if (draggingOnDragOrigin({
|
|
1245
|
+
snapshot: snapshot_0,
|
|
1246
|
+
position: position_5
|
|
1247
|
+
})) {
|
|
1248
|
+
event_9.preventDefault();
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
editorActor.send({
|
|
1152
1252
|
type: "behavior event",
|
|
1153
1253
|
behaviorEvent: {
|
|
1154
1254
|
type: "drag.drag",
|
|
@@ -1157,9 +1257,9 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1157
1257
|
}
|
|
1158
1258
|
},
|
|
1159
1259
|
editor: slateEditor
|
|
1160
|
-
})
|
|
1260
|
+
});
|
|
1161
1261
|
}, [onDrag, editorActor, slateEditor]), handleDragEnd = React.useCallback((event_10) => {
|
|
1162
|
-
onDragEnd?.(event_10), !event_10.isDefaultPrevented()
|
|
1262
|
+
onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()) && (event_10.stopPropagation(), editorActor.send({
|
|
1163
1263
|
type: "behavior event",
|
|
1164
1264
|
behaviorEvent: {
|
|
1165
1265
|
type: "drag.dragend",
|
|
@@ -1168,76 +1268,139 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1168
1268
|
}
|
|
1169
1269
|
},
|
|
1170
1270
|
editor: slateEditor
|
|
1171
|
-
})
|
|
1271
|
+
}));
|
|
1172
1272
|
}, [onDragEnd, editorActor, slateEditor]), handleDragEnter = React.useCallback((event_11) => {
|
|
1173
|
-
if (onDragEnter?.(event_11),
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1273
|
+
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
1274
|
+
return;
|
|
1275
|
+
event_11.stopPropagation();
|
|
1276
|
+
const position_6 = getEventPosition({
|
|
1277
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1278
|
+
slateEditor,
|
|
1279
|
+
event: event_11.nativeEvent
|
|
1280
|
+
});
|
|
1281
|
+
if (!position_6)
|
|
1282
|
+
return;
|
|
1283
|
+
const snapshot_1 = editorProvider.getEditorSnapshot({
|
|
1284
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1285
|
+
slateEditorInstance: slateEditor
|
|
1286
|
+
});
|
|
1287
|
+
if (draggingOnDragOrigin({
|
|
1288
|
+
snapshot: snapshot_1,
|
|
1289
|
+
position: position_6
|
|
1290
|
+
})) {
|
|
1291
|
+
event_11.preventDefault();
|
|
1292
|
+
return;
|
|
1192
1293
|
}
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
});
|
|
1200
|
-
if (!position_6)
|
|
1201
|
-
return;
|
|
1202
|
-
editorActor.send({
|
|
1203
|
-
type: "behavior event",
|
|
1204
|
-
behaviorEvent: {
|
|
1205
|
-
type: "drag.dragover",
|
|
1206
|
-
originEvent: {
|
|
1207
|
-
dataTransfer: event_12.dataTransfer
|
|
1208
|
-
},
|
|
1209
|
-
position: position_6
|
|
1294
|
+
editorActor.send({
|
|
1295
|
+
type: "behavior event",
|
|
1296
|
+
behaviorEvent: {
|
|
1297
|
+
type: "drag.dragenter",
|
|
1298
|
+
originEvent: {
|
|
1299
|
+
dataTransfer: event_11.dataTransfer
|
|
1210
1300
|
},
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1301
|
+
position: position_6
|
|
1302
|
+
},
|
|
1303
|
+
editor: slateEditor
|
|
1304
|
+
});
|
|
1305
|
+
}, [onDragEnter, editorActor, slateEditor]), handleDragOver = React.useCallback((event_12) => {
|
|
1306
|
+
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
1307
|
+
return;
|
|
1308
|
+
event_12.stopPropagation();
|
|
1309
|
+
const position_7 = getEventPosition({
|
|
1310
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1311
|
+
slateEditor,
|
|
1312
|
+
event: event_12.nativeEvent
|
|
1313
|
+
});
|
|
1314
|
+
if (!position_7)
|
|
1315
|
+
return;
|
|
1316
|
+
const snapshot_2 = editorProvider.getEditorSnapshot({
|
|
1317
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1318
|
+
slateEditorInstance: slateEditor
|
|
1319
|
+
});
|
|
1320
|
+
if (draggingOnDragOrigin({
|
|
1321
|
+
snapshot: snapshot_2,
|
|
1322
|
+
position: position_7
|
|
1323
|
+
})) {
|
|
1324
|
+
event_12.preventDefault();
|
|
1325
|
+
return;
|
|
1214
1326
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
});
|
|
1222
|
-
if (!position_7) {
|
|
1223
|
-
console.warn("Could not find position for drop event");
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
const range = slateReact.ReactEditor.findEventRange(slateEditor, event_13);
|
|
1227
|
-
slateEditor.select(range), editorActor.send({
|
|
1228
|
-
type: "behavior event",
|
|
1229
|
-
behaviorEvent: {
|
|
1230
|
-
type: "drag.drop",
|
|
1231
|
-
originEvent: {
|
|
1232
|
-
dataTransfer: event_13.dataTransfer
|
|
1233
|
-
},
|
|
1234
|
-
position: position_7
|
|
1327
|
+
editorActor.send({
|
|
1328
|
+
type: "behavior event",
|
|
1329
|
+
behaviorEvent: {
|
|
1330
|
+
type: "drag.dragover",
|
|
1331
|
+
originEvent: {
|
|
1332
|
+
dataTransfer: event_12.dataTransfer
|
|
1235
1333
|
},
|
|
1236
|
-
|
|
1237
|
-
}
|
|
1334
|
+
position: position_7
|
|
1335
|
+
},
|
|
1336
|
+
editor: slateEditor,
|
|
1337
|
+
nativeEvent: event_12
|
|
1338
|
+
});
|
|
1339
|
+
}, [onDragOver, editorActor, slateEditor]), handleDrop = React.useCallback((event_13) => {
|
|
1340
|
+
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
1341
|
+
return;
|
|
1342
|
+
event_13.preventDefault();
|
|
1343
|
+
const position_8 = getEventPosition({
|
|
1344
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1345
|
+
slateEditor,
|
|
1346
|
+
event: event_13.nativeEvent
|
|
1347
|
+
});
|
|
1348
|
+
if (!position_8) {
|
|
1349
|
+
console.warn("Could not find position for drop event");
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1352
|
+
const snapshot_3 = editorProvider.getEditorSnapshot({
|
|
1353
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1354
|
+
slateEditorInstance: slateEditor
|
|
1355
|
+
});
|
|
1356
|
+
if (draggingOnDragOrigin({
|
|
1357
|
+
snapshot: snapshot_3,
|
|
1358
|
+
position: position_8
|
|
1359
|
+
})) {
|
|
1360
|
+
event_13.preventDefault();
|
|
1361
|
+
return;
|
|
1238
1362
|
}
|
|
1363
|
+
editorActor.send({
|
|
1364
|
+
type: "behavior event",
|
|
1365
|
+
behaviorEvent: {
|
|
1366
|
+
type: "select",
|
|
1367
|
+
selection: position_8.selection
|
|
1368
|
+
},
|
|
1369
|
+
editor: slateEditor
|
|
1370
|
+
}), editorActor.send({
|
|
1371
|
+
type: "behavior event",
|
|
1372
|
+
behaviorEvent: {
|
|
1373
|
+
type: "drag.drop",
|
|
1374
|
+
originEvent: {
|
|
1375
|
+
dataTransfer: event_13.dataTransfer
|
|
1376
|
+
},
|
|
1377
|
+
position: position_8
|
|
1378
|
+
},
|
|
1379
|
+
editor: slateEditor
|
|
1380
|
+
});
|
|
1239
1381
|
}, [onDrop, editorActor, slateEditor]), handleDragLeave = React.useCallback((event_14) => {
|
|
1240
|
-
onDragLeave?.(event_14),
|
|
1382
|
+
if (onDragLeave?.(event_14), event_14.isDefaultPrevented() || event_14.isPropagationStopped())
|
|
1383
|
+
return;
|
|
1384
|
+
event_14.stopPropagation();
|
|
1385
|
+
const position_9 = getEventPosition({
|
|
1386
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1387
|
+
slateEditor,
|
|
1388
|
+
event: event_14.nativeEvent
|
|
1389
|
+
});
|
|
1390
|
+
if (!position_9)
|
|
1391
|
+
return;
|
|
1392
|
+
const snapshot_4 = editorProvider.getEditorSnapshot({
|
|
1393
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1394
|
+
slateEditorInstance: slateEditor
|
|
1395
|
+
});
|
|
1396
|
+
if (draggingOnDragOrigin({
|
|
1397
|
+
snapshot: snapshot_4,
|
|
1398
|
+
position: position_9
|
|
1399
|
+
})) {
|
|
1400
|
+
event_14.preventDefault();
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
editorActor.send({
|
|
1241
1404
|
type: "behavior event",
|
|
1242
1405
|
behaviorEvent: {
|
|
1243
1406
|
type: "drag.dragleave",
|