@portabletext/editor 1.40.4 → 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 +11 -6
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +4 -0
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +11 -6
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +4 -0
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -1
- package/lib/index.cjs +260 -131
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +262 -133
- package/lib/index.js.map +1 -1
- package/lib/utils/index.cjs +5 -0
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +22 -0
- package/lib/utils/index.d.ts +22 -0
- package/lib/utils/index.js +6 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +2 -2
- 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/dragging-on-drag-origin.ts +22 -0
- package/src/internal-utils/event-position.ts +32 -4
- package/src/internal-utils/slate-utils.ts +18 -9
- 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/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getNodeBlock, toPortableTextRange, fromSlateValue, toSlateRange, debugWithName, EditorActorContext, KEY_TO_VALUE_ELEMENT, usePortableTextEditor, PortableTextEditor, moveRangeByOperation, isEqualToEmptyEditor, getEditorSnapshot, useEditor } from "./_chunks-es/editor-provider.js";
|
|
1
|
+
import { getNodeBlock, getFirstBlock, getLastBlock, toPortableTextRange, fromSlateValue, toSlateRange, debugWithName, EditorActorContext, KEY_TO_VALUE_ELEMENT, usePortableTextEditor, PortableTextEditor, moveRangeByOperation, isEqualToEmptyEditor, getEditorSnapshot, useEditor } from "./_chunks-es/editor-provider.js";
|
|
2
2
|
import { EditorProvider, defineSchema, defaultKeyGenerator, useEditorSelector, usePortableTextEditorSelection } from "./_chunks-es/editor-provider.js";
|
|
3
3
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
4
4
|
import { useSelector } from "@xstate/react";
|
|
@@ -11,7 +11,7 @@ import { getBlockEndPoint, getBlockStartPoint, isKeyedSegment } from "./_chunks-
|
|
|
11
11
|
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, getFocusBlock } from "./_chunks-es/selector.is-at-the-start-of-block.js";
|
|
12
12
|
import { isOverlappingSelection, isSelectingEntireBlocks } from "./_chunks-es/selector.is-overlapping-selection.js";
|
|
13
13
|
import { DOMEditor, isDOMNode } from "slate-dom";
|
|
14
|
-
import { isSelectionCollapsed as isSelectionCollapsed$1 } from "./_chunks-es/util.is-selection-collapsed.js";
|
|
14
|
+
import { isSelectionCollapsed as isSelectionCollapsed$1, getSelectionEndPoint } from "./_chunks-es/util.is-selection-collapsed.js";
|
|
15
15
|
import { parseBlocks } from "./_chunks-es/util.selection-point-to-block-offset.js";
|
|
16
16
|
import { defineBehavior, isHotkey } from "./_chunks-es/behavior.core.js";
|
|
17
17
|
import { c } from "react-compiler-runtime";
|
|
@@ -77,6 +77,19 @@ function getDragSelection({
|
|
|
77
77
|
}
|
|
78
78
|
return dragSelection;
|
|
79
79
|
}
|
|
80
|
+
function draggingOnDragOrigin({
|
|
81
|
+
snapshot,
|
|
82
|
+
position
|
|
83
|
+
}) {
|
|
84
|
+
const dragOrigin = snapshot.beta.internalDrag?.origin;
|
|
85
|
+
return dragOrigin ? isOverlappingSelection(position.selection)({
|
|
86
|
+
...snapshot,
|
|
87
|
+
context: {
|
|
88
|
+
...snapshot.context,
|
|
89
|
+
selection: dragOrigin.selection
|
|
90
|
+
}
|
|
91
|
+
}) : !1;
|
|
92
|
+
}
|
|
80
93
|
function getEventPosition({
|
|
81
94
|
schema,
|
|
82
95
|
slateEditor,
|
|
@@ -158,6 +171,22 @@ function getEventPositionBlock({
|
|
|
158
171
|
slateEditor,
|
|
159
172
|
event
|
|
160
173
|
}) {
|
|
174
|
+
const [firstBlock] = getFirstBlock({
|
|
175
|
+
editor: slateEditor
|
|
176
|
+
});
|
|
177
|
+
if (!firstBlock)
|
|
178
|
+
return;
|
|
179
|
+
const firstBlockRect = DOMEditor.toDOMNode(slateEditor, firstBlock).getBoundingClientRect();
|
|
180
|
+
if (event.pageY < firstBlockRect.top)
|
|
181
|
+
return "start";
|
|
182
|
+
const [lastBlock] = getLastBlock({
|
|
183
|
+
editor: slateEditor
|
|
184
|
+
});
|
|
185
|
+
if (!lastBlock)
|
|
186
|
+
return;
|
|
187
|
+
const lastBlockRef = DOMEditor.toDOMNode(slateEditor, lastBlock).getBoundingClientRect();
|
|
188
|
+
if (event.pageY > lastBlockRef.bottom)
|
|
189
|
+
return "end";
|
|
161
190
|
const elementRect = DOMEditor.toDOMNode(slateEditor, node).getBoundingClientRect(), top = elementRect.top, height = elementRect.height;
|
|
162
191
|
return Math.abs(top - event.pageY) < height / 2 ? "start" : "end";
|
|
163
192
|
}
|
|
@@ -176,7 +205,11 @@ function getSlateRangeFromEvent(editor, event) {
|
|
|
176
205
|
let domRange;
|
|
177
206
|
if (window2.document.caretPositionFromPoint !== void 0) {
|
|
178
207
|
const position = window2.document.caretPositionFromPoint(event.clientX, event.clientY);
|
|
179
|
-
|
|
208
|
+
if (position)
|
|
209
|
+
try {
|
|
210
|
+
domRange = window2.document.createRange(), domRange.setStart(position.offsetNode, position.offset), domRange.setEnd(position.offsetNode, position.offset);
|
|
211
|
+
} catch {
|
|
212
|
+
}
|
|
180
213
|
} else if (window2.document.caretRangeFromPoint !== void 0)
|
|
181
214
|
domRange = window2.document.caretRangeFromPoint(event.clientX, event.clientY) ?? void 0;
|
|
182
215
|
else {
|
|
@@ -304,13 +337,13 @@ function DefaultInlineObject(props) {
|
|
|
304
337
|
function DropIndicator() {
|
|
305
338
|
const $ = c(1);
|
|
306
339
|
let t0;
|
|
307
|
-
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx("div", { className: "pt-drop-indicator", style: {
|
|
340
|
+
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx("div", { contentEditable: !1, className: "pt-drop-indicator", style: {
|
|
308
341
|
position: "absolute",
|
|
309
342
|
width: "100%",
|
|
310
343
|
height: 1,
|
|
311
344
|
borderBottom: "1px solid currentColor",
|
|
312
345
|
zIndex: 5
|
|
313
|
-
} }), $[0] = t0) : t0 = $[0], t0;
|
|
346
|
+
}, children: /* @__PURE__ */ jsx("span", {}) }), $[0] = t0) : t0 = $[0], t0;
|
|
314
347
|
}
|
|
315
348
|
debugWithName("components:Element");
|
|
316
349
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
@@ -1123,78 +1156,111 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1123
1156
|
};
|
|
1124
1157
|
}, [slateEditor, editorActor]);
|
|
1125
1158
|
const handleDragStart = useCallback((event_8) => {
|
|
1126
|
-
if (onDragStart?.(event_8),
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1159
|
+
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
1160
|
+
return;
|
|
1161
|
+
event_8.stopPropagation();
|
|
1162
|
+
const position_4 = getEventPosition({
|
|
1163
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1164
|
+
slateEditor,
|
|
1165
|
+
event: event_8.nativeEvent
|
|
1166
|
+
});
|
|
1167
|
+
if (!position_4) {
|
|
1168
|
+
console.warn("Could not find position for dragstart event");
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
const snapshot = getEditorSnapshot({
|
|
1172
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1173
|
+
slateEditorInstance: slateEditor
|
|
1174
|
+
}), dragSelection = getDragSelection({
|
|
1175
|
+
eventSelection: position_4.selection,
|
|
1176
|
+
snapshot
|
|
1177
|
+
}), selectingEntireBlocks = isSelectingEntireBlocks({
|
|
1178
|
+
context: {
|
|
1179
|
+
...snapshot.context,
|
|
1180
|
+
selection: dragSelection
|
|
1135
1181
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
slateEditorInstance: slateEditor
|
|
1139
|
-
}), dragSelection = getDragSelection({
|
|
1140
|
-
eventSelection: position_4.selection,
|
|
1141
|
-
snapshot
|
|
1142
|
-
}), selectingEntireBlocks = isSelectingEntireBlocks({
|
|
1182
|
+
}), dragGhost = document.createElement("div"), draggedDomNodes = getSelectionDomNodes({
|
|
1183
|
+
snapshot: {
|
|
1143
1184
|
context: {
|
|
1144
1185
|
...snapshot.context,
|
|
1145
1186
|
selection: dragSelection
|
|
1146
1187
|
}
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
for (const block of clonedBlockNodes)
|
|
1159
|
-
block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
|
|
1160
|
-
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
1161
|
-
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) {
|
|
1162
|
-
const customGhostRect = customGhost.getBoundingClientRect(), x = event_8.clientX - customGhostRect.left, y = event_8.clientY - customGhostRect.top;
|
|
1163
|
-
dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x, y);
|
|
1164
|
-
} else {
|
|
1165
|
-
const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x_0 = event_8.clientX - blocksDomRect.left, y_0 = event_8.clientY - blocksDomRect.top;
|
|
1166
|
-
dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_0, y_0);
|
|
1167
|
-
}
|
|
1188
|
+
},
|
|
1189
|
+
slateEditor
|
|
1190
|
+
});
|
|
1191
|
+
if (selectingEntireBlocks) {
|
|
1192
|
+
const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) => node.cloneNode(!0));
|
|
1193
|
+
for (const block of clonedBlockNodes)
|
|
1194
|
+
block instanceof HTMLElement && (block.style.position = "relative"), dragGhost.appendChild(block);
|
|
1195
|
+
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
1196
|
+
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) {
|
|
1197
|
+
const customGhostRect = customGhost.getBoundingClientRect(), x = event_8.clientX - customGhostRect.left, y = event_8.clientY - customGhostRect.top;
|
|
1198
|
+
dragGhost.style.width = `${customGhostRect.width}px`, dragGhost.style.height = `${customGhostRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x, y);
|
|
1168
1199
|
} else {
|
|
1169
|
-
const
|
|
1170
|
-
|
|
1171
|
-
dragGhost.appendChild(child);
|
|
1172
|
-
dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
1173
|
-
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
|
|
1174
|
-
dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
|
|
1200
|
+
const blocksDomRect = getCompoundClientRect(draggedDomNodes.blockNodes), x_0 = event_8.clientX - blocksDomRect.left, y_0 = event_8.clientY - blocksDomRect.top;
|
|
1201
|
+
dragGhost.style.width = `${blocksDomRect.width}px`, dragGhost.style.height = `${blocksDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_0, y_0);
|
|
1175
1202
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
}
|
|
1183
|
-
type: "behavior event",
|
|
1184
|
-
behaviorEvent: {
|
|
1185
|
-
type: "drag.dragstart",
|
|
1186
|
-
originEvent: {
|
|
1187
|
-
dataTransfer: event_8.dataTransfer
|
|
1188
|
-
},
|
|
1189
|
-
position: {
|
|
1190
|
-
selection: dragSelection
|
|
1191
|
-
}
|
|
1192
|
-
},
|
|
1193
|
-
editor: slateEditor
|
|
1194
|
-
}), event_8.stopPropagation();
|
|
1203
|
+
} else {
|
|
1204
|
+
const clonedChildNodes = draggedDomNodes.childNodes.map((node_0) => node_0.cloneNode(!0));
|
|
1205
|
+
for (const child of clonedChildNodes)
|
|
1206
|
+
dragGhost.appendChild(child);
|
|
1207
|
+
dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
1208
|
+
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
|
|
1209
|
+
dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
|
|
1195
1210
|
}
|
|
1211
|
+
editorActor.send({
|
|
1212
|
+
type: "behavior event",
|
|
1213
|
+
behaviorEvent: {
|
|
1214
|
+
type: "select",
|
|
1215
|
+
selection: isSelectionCollapsed$1(dragSelection) ? dragSelection : {
|
|
1216
|
+
anchor: getSelectionEndPoint(dragSelection),
|
|
1217
|
+
focus: getSelectionEndPoint(dragSelection),
|
|
1218
|
+
backward: !1
|
|
1219
|
+
}
|
|
1220
|
+
},
|
|
1221
|
+
editor: slateEditor
|
|
1222
|
+
}), editorActor.send({
|
|
1223
|
+
type: "dragstart",
|
|
1224
|
+
origin: {
|
|
1225
|
+
selection: dragSelection
|
|
1226
|
+
},
|
|
1227
|
+
ghost: dragGhost
|
|
1228
|
+
}), editorActor.send({
|
|
1229
|
+
type: "behavior event",
|
|
1230
|
+
behaviorEvent: {
|
|
1231
|
+
type: "drag.dragstart",
|
|
1232
|
+
originEvent: {
|
|
1233
|
+
dataTransfer: event_8.dataTransfer
|
|
1234
|
+
},
|
|
1235
|
+
position: {
|
|
1236
|
+
selection: dragSelection
|
|
1237
|
+
}
|
|
1238
|
+
},
|
|
1239
|
+
editor: slateEditor
|
|
1240
|
+
});
|
|
1196
1241
|
}, [onDragStart, editorActor, slateEditor]), handleDrag = useCallback((event_9) => {
|
|
1197
|
-
onDrag?.(event_9),
|
|
1242
|
+
if (onDrag?.(event_9), event_9.isDefaultPrevented() || event_9.isPropagationStopped())
|
|
1243
|
+
return;
|
|
1244
|
+
event_9.stopPropagation();
|
|
1245
|
+
const position_5 = getEventPosition({
|
|
1246
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1247
|
+
slateEditor,
|
|
1248
|
+
event: event_9.nativeEvent
|
|
1249
|
+
});
|
|
1250
|
+
if (!position_5)
|
|
1251
|
+
return;
|
|
1252
|
+
const snapshot_0 = getEditorSnapshot({
|
|
1253
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1254
|
+
slateEditorInstance: slateEditor
|
|
1255
|
+
});
|
|
1256
|
+
if (draggingOnDragOrigin({
|
|
1257
|
+
snapshot: snapshot_0,
|
|
1258
|
+
position: position_5
|
|
1259
|
+
})) {
|
|
1260
|
+
event_9.preventDefault();
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
editorActor.send({
|
|
1198
1264
|
type: "behavior event",
|
|
1199
1265
|
behaviorEvent: {
|
|
1200
1266
|
type: "drag.drag",
|
|
@@ -1203,9 +1269,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1203
1269
|
}
|
|
1204
1270
|
},
|
|
1205
1271
|
editor: slateEditor
|
|
1206
|
-
})
|
|
1272
|
+
});
|
|
1207
1273
|
}, [onDrag, editorActor, slateEditor]), handleDragEnd = useCallback((event_10) => {
|
|
1208
|
-
onDragEnd?.(event_10), !event_10.isDefaultPrevented()
|
|
1274
|
+
onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()) && (event_10.stopPropagation(), editorActor.send({
|
|
1209
1275
|
type: "behavior event",
|
|
1210
1276
|
behaviorEvent: {
|
|
1211
1277
|
type: "drag.dragend",
|
|
@@ -1214,76 +1280,139 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1214
1280
|
}
|
|
1215
1281
|
},
|
|
1216
1282
|
editor: slateEditor
|
|
1217
|
-
})
|
|
1283
|
+
}));
|
|
1218
1284
|
}, [onDragEnd, editorActor, slateEditor]), handleDragEnter = useCallback((event_11) => {
|
|
1219
|
-
if (onDragEnter?.(event_11),
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1285
|
+
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
1286
|
+
return;
|
|
1287
|
+
event_11.stopPropagation();
|
|
1288
|
+
const position_6 = getEventPosition({
|
|
1289
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1290
|
+
slateEditor,
|
|
1291
|
+
event: event_11.nativeEvent
|
|
1292
|
+
});
|
|
1293
|
+
if (!position_6)
|
|
1294
|
+
return;
|
|
1295
|
+
const snapshot_1 = getEditorSnapshot({
|
|
1296
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1297
|
+
slateEditorInstance: slateEditor
|
|
1298
|
+
});
|
|
1299
|
+
if (draggingOnDragOrigin({
|
|
1300
|
+
snapshot: snapshot_1,
|
|
1301
|
+
position: position_6
|
|
1302
|
+
})) {
|
|
1303
|
+
event_11.preventDefault();
|
|
1304
|
+
return;
|
|
1238
1305
|
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
});
|
|
1246
|
-
if (!position_6)
|
|
1247
|
-
return;
|
|
1248
|
-
editorActor.send({
|
|
1249
|
-
type: "behavior event",
|
|
1250
|
-
behaviorEvent: {
|
|
1251
|
-
type: "drag.dragover",
|
|
1252
|
-
originEvent: {
|
|
1253
|
-
dataTransfer: event_12.dataTransfer
|
|
1254
|
-
},
|
|
1255
|
-
position: position_6
|
|
1306
|
+
editorActor.send({
|
|
1307
|
+
type: "behavior event",
|
|
1308
|
+
behaviorEvent: {
|
|
1309
|
+
type: "drag.dragenter",
|
|
1310
|
+
originEvent: {
|
|
1311
|
+
dataTransfer: event_11.dataTransfer
|
|
1256
1312
|
},
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1313
|
+
position: position_6
|
|
1314
|
+
},
|
|
1315
|
+
editor: slateEditor
|
|
1316
|
+
});
|
|
1317
|
+
}, [onDragEnter, editorActor, slateEditor]), handleDragOver = useCallback((event_12) => {
|
|
1318
|
+
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
1319
|
+
return;
|
|
1320
|
+
event_12.stopPropagation();
|
|
1321
|
+
const position_7 = getEventPosition({
|
|
1322
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1323
|
+
slateEditor,
|
|
1324
|
+
event: event_12.nativeEvent
|
|
1325
|
+
});
|
|
1326
|
+
if (!position_7)
|
|
1327
|
+
return;
|
|
1328
|
+
const snapshot_2 = getEditorSnapshot({
|
|
1329
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1330
|
+
slateEditorInstance: slateEditor
|
|
1331
|
+
});
|
|
1332
|
+
if (draggingOnDragOrigin({
|
|
1333
|
+
snapshot: snapshot_2,
|
|
1334
|
+
position: position_7
|
|
1335
|
+
})) {
|
|
1336
|
+
event_12.preventDefault();
|
|
1337
|
+
return;
|
|
1260
1338
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
});
|
|
1268
|
-
if (!position_7) {
|
|
1269
|
-
console.warn("Could not find position for drop event");
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
const range = ReactEditor.findEventRange(slateEditor, event_13);
|
|
1273
|
-
slateEditor.select(range), editorActor.send({
|
|
1274
|
-
type: "behavior event",
|
|
1275
|
-
behaviorEvent: {
|
|
1276
|
-
type: "drag.drop",
|
|
1277
|
-
originEvent: {
|
|
1278
|
-
dataTransfer: event_13.dataTransfer
|
|
1279
|
-
},
|
|
1280
|
-
position: position_7
|
|
1339
|
+
editorActor.send({
|
|
1340
|
+
type: "behavior event",
|
|
1341
|
+
behaviorEvent: {
|
|
1342
|
+
type: "drag.dragover",
|
|
1343
|
+
originEvent: {
|
|
1344
|
+
dataTransfer: event_12.dataTransfer
|
|
1281
1345
|
},
|
|
1282
|
-
|
|
1283
|
-
}
|
|
1346
|
+
position: position_7
|
|
1347
|
+
},
|
|
1348
|
+
editor: slateEditor,
|
|
1349
|
+
nativeEvent: event_12
|
|
1350
|
+
});
|
|
1351
|
+
}, [onDragOver, editorActor, slateEditor]), handleDrop = useCallback((event_13) => {
|
|
1352
|
+
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
1353
|
+
return;
|
|
1354
|
+
event_13.preventDefault();
|
|
1355
|
+
const position_8 = getEventPosition({
|
|
1356
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1357
|
+
slateEditor,
|
|
1358
|
+
event: event_13.nativeEvent
|
|
1359
|
+
});
|
|
1360
|
+
if (!position_8) {
|
|
1361
|
+
console.warn("Could not find position for drop event");
|
|
1362
|
+
return;
|
|
1284
1363
|
}
|
|
1364
|
+
const snapshot_3 = getEditorSnapshot({
|
|
1365
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1366
|
+
slateEditorInstance: slateEditor
|
|
1367
|
+
});
|
|
1368
|
+
if (draggingOnDragOrigin({
|
|
1369
|
+
snapshot: snapshot_3,
|
|
1370
|
+
position: position_8
|
|
1371
|
+
})) {
|
|
1372
|
+
event_13.preventDefault();
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
editorActor.send({
|
|
1376
|
+
type: "behavior event",
|
|
1377
|
+
behaviorEvent: {
|
|
1378
|
+
type: "select",
|
|
1379
|
+
selection: position_8.selection
|
|
1380
|
+
},
|
|
1381
|
+
editor: slateEditor
|
|
1382
|
+
}), editorActor.send({
|
|
1383
|
+
type: "behavior event",
|
|
1384
|
+
behaviorEvent: {
|
|
1385
|
+
type: "drag.drop",
|
|
1386
|
+
originEvent: {
|
|
1387
|
+
dataTransfer: event_13.dataTransfer
|
|
1388
|
+
},
|
|
1389
|
+
position: position_8
|
|
1390
|
+
},
|
|
1391
|
+
editor: slateEditor
|
|
1392
|
+
});
|
|
1285
1393
|
}, [onDrop, editorActor, slateEditor]), handleDragLeave = useCallback((event_14) => {
|
|
1286
|
-
onDragLeave?.(event_14),
|
|
1394
|
+
if (onDragLeave?.(event_14), event_14.isDefaultPrevented() || event_14.isPropagationStopped())
|
|
1395
|
+
return;
|
|
1396
|
+
event_14.stopPropagation();
|
|
1397
|
+
const position_9 = getEventPosition({
|
|
1398
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1399
|
+
slateEditor,
|
|
1400
|
+
event: event_14.nativeEvent
|
|
1401
|
+
});
|
|
1402
|
+
if (!position_9)
|
|
1403
|
+
return;
|
|
1404
|
+
const snapshot_4 = getEditorSnapshot({
|
|
1405
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1406
|
+
slateEditorInstance: slateEditor
|
|
1407
|
+
});
|
|
1408
|
+
if (draggingOnDragOrigin({
|
|
1409
|
+
snapshot: snapshot_4,
|
|
1410
|
+
position: position_9
|
|
1411
|
+
})) {
|
|
1412
|
+
event_14.preventDefault();
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
editorActor.send({
|
|
1287
1416
|
type: "behavior event",
|
|
1288
1417
|
behaviorEvent: {
|
|
1289
1418
|
type: "drag.dragleave",
|