@portabletext/editor 1.41.2 → 1.41.4
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/behavior.core.cjs +52 -28
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +11 -11
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +24 -21
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +11 -0
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +240 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +300 -218
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +27 -3
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/editor-provider.js +5 -2
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +13 -0
- package/lib/_chunks-es/selector.get-focus-inline-object.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +243 -0
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/_chunks-es/selector.is-overlapping-selection.js +298 -217
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/behaviors/index.cjs +9 -9
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +85 -105
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +80 -99
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +6 -6
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +37 -43
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +5 -10
- package/lib/selectors/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.core.dnd.ts +27 -0
- package/src/behaviors/behavior.core.ts +2 -0
- package/src/behaviors/behavior.default.ts +4 -0
- package/src/editor/Editable.tsx +22 -40
- package/src/internal-utils/drag-selection.test.ts +1 -1
- package/src/internal-utils/drag-selection.ts +23 -6
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +0 -322
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +0 -324
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +0 -1
- package/src/internal-utils/dragging-on-drag-origin.ts +0 -22
package/lib/index.js
CHANGED
|
@@ -8,11 +8,12 @@ import { useContext, useRef, useState, useEffect, useMemo, startTransition, useC
|
|
|
8
8
|
import { Editor, Range, Element as Element$2, Text, Transforms, Path } from "slate";
|
|
9
9
|
import { useSlateStatic, useSelected, ReactEditor, useSlate, Editable } from "slate-react";
|
|
10
10
|
import { getBlockEndPoint, getBlockStartPoint, isKeyedSegment } from "./_chunks-es/util.slice-blocks.js";
|
|
11
|
-
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, getFocusBlock } from "./_chunks-es/selector.is-
|
|
12
|
-
import {
|
|
11
|
+
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, getFocusBlock } from "./_chunks-es/selector.is-overlapping-selection.js";
|
|
12
|
+
import { getFocusInlineObject } from "./_chunks-es/selector.get-focus-inline-object.js";
|
|
13
13
|
import { DOMEditor, isDOMNode } from "slate-dom";
|
|
14
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
|
+
import { isSelectingEntireBlocks } from "./_chunks-es/selector.is-active-style.js";
|
|
16
17
|
import { defineBehavior, isHotkey } from "./_chunks-es/behavior.core.js";
|
|
17
18
|
import { c } from "react-compiler-runtime";
|
|
18
19
|
import uniq from "lodash/uniq.js";
|
|
@@ -35,25 +36,32 @@ function getDragSelection({
|
|
|
35
36
|
snapshot
|
|
36
37
|
}) {
|
|
37
38
|
let dragSelection = eventSelection;
|
|
38
|
-
|
|
39
|
+
if (getFocusInlineObject({
|
|
39
40
|
context: {
|
|
40
41
|
...snapshot.context,
|
|
41
42
|
selection: eventSelection
|
|
42
43
|
}
|
|
43
|
-
})
|
|
44
|
+
}))
|
|
45
|
+
return dragSelection;
|
|
46
|
+
const draggingCollapsedSelection = isSelectionCollapsed({
|
|
44
47
|
context: {
|
|
45
48
|
...snapshot.context,
|
|
46
49
|
selection: eventSelection
|
|
47
50
|
}
|
|
48
|
-
}),
|
|
51
|
+
}), draggedTextBlock = getFocusTextBlock({
|
|
52
|
+
context: {
|
|
53
|
+
...snapshot.context,
|
|
54
|
+
selection: eventSelection
|
|
55
|
+
}
|
|
56
|
+
}), draggedSpan = getFocusSpan({
|
|
49
57
|
context: {
|
|
50
58
|
...snapshot.context,
|
|
51
59
|
selection: eventSelection
|
|
52
60
|
}
|
|
53
61
|
});
|
|
54
|
-
|
|
55
|
-
anchor: getBlockStartPoint(
|
|
56
|
-
focus: getBlockEndPoint(
|
|
62
|
+
draggingCollapsedSelection && draggedTextBlock && draggedSpan && (dragSelection = {
|
|
63
|
+
anchor: getBlockStartPoint(draggedTextBlock),
|
|
64
|
+
focus: getBlockEndPoint(draggedTextBlock)
|
|
57
65
|
});
|
|
58
66
|
const selectedBlocks = getSelectedBlocks(snapshot);
|
|
59
67
|
if (snapshot.context.selection && isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
@@ -77,19 +85,6 @@ function getDragSelection({
|
|
|
77
85
|
}
|
|
78
86
|
return dragSelection;
|
|
79
87
|
}
|
|
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
|
-
}
|
|
93
88
|
function getEventPosition({
|
|
94
89
|
schema,
|
|
95
90
|
slateEditor,
|
|
@@ -1158,7 +1153,6 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1158
1153
|
const handleDragStart = useCallback((event_8) => {
|
|
1159
1154
|
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
1160
1155
|
return;
|
|
1161
|
-
event_8.stopPropagation();
|
|
1162
1156
|
const position_4 = getEventPosition({
|
|
1163
1157
|
schema: editorActor.getSnapshot().context.schema,
|
|
1164
1158
|
slateEditor,
|
|
@@ -1208,7 +1202,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1208
1202
|
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
|
|
1209
1203
|
dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
|
|
1210
1204
|
}
|
|
1211
|
-
editorActor.send({
|
|
1205
|
+
return editorActor.send({
|
|
1212
1206
|
type: "behavior event",
|
|
1213
1207
|
behaviorEvent: {
|
|
1214
1208
|
type: "select",
|
|
@@ -1237,87 +1231,79 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1237
1231
|
}
|
|
1238
1232
|
},
|
|
1239
1233
|
editor: slateEditor
|
|
1240
|
-
});
|
|
1234
|
+
}), !0;
|
|
1241
1235
|
}, [onDragStart, editorActor, slateEditor]), handleDrag = useCallback((event_9) => {
|
|
1242
|
-
onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() ||
|
|
1236
|
+
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
1243
1237
|
schema: editorActor.getSnapshot().context.schema,
|
|
1244
1238
|
slateEditor,
|
|
1245
1239
|
event: event_9.nativeEvent
|
|
1246
|
-
})))
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1240
|
+
})))
|
|
1241
|
+
return editorActor.send({
|
|
1242
|
+
type: "behavior event",
|
|
1243
|
+
behaviorEvent: {
|
|
1244
|
+
type: "drag.drag",
|
|
1245
|
+
originEvent: {
|
|
1246
|
+
dataTransfer: event_9.dataTransfer
|
|
1247
|
+
}
|
|
1248
|
+
},
|
|
1249
|
+
editor: slateEditor
|
|
1250
|
+
}), !0;
|
|
1256
1251
|
}, [onDrag, editorActor, slateEditor]), handleDragEnd = useCallback((event_10) => {
|
|
1257
|
-
onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped())
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1252
|
+
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
1253
|
+
return editorActor.send({
|
|
1254
|
+
type: "behavior event",
|
|
1255
|
+
behaviorEvent: {
|
|
1256
|
+
type: "drag.dragend",
|
|
1257
|
+
originEvent: {
|
|
1258
|
+
dataTransfer: event_10.dataTransfer
|
|
1259
|
+
}
|
|
1260
|
+
},
|
|
1261
|
+
editor: slateEditor
|
|
1262
|
+
}), !0;
|
|
1267
1263
|
}, [onDragEnd, editorActor, slateEditor]), handleDragEnter = useCallback((event_11) => {
|
|
1268
1264
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
1269
1265
|
return;
|
|
1270
|
-
event_11.stopPropagation();
|
|
1271
1266
|
const position_6 = getEventPosition({
|
|
1272
1267
|
schema: editorActor.getSnapshot().context.schema,
|
|
1273
1268
|
slateEditor,
|
|
1274
1269
|
event: event_11.nativeEvent
|
|
1275
1270
|
});
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1271
|
+
if (position_6)
|
|
1272
|
+
return editorActor.send({
|
|
1273
|
+
type: "behavior event",
|
|
1274
|
+
behaviorEvent: {
|
|
1275
|
+
type: "drag.dragenter",
|
|
1276
|
+
originEvent: {
|
|
1277
|
+
dataTransfer: event_11.dataTransfer
|
|
1278
|
+
},
|
|
1279
|
+
position: position_6
|
|
1282
1280
|
},
|
|
1283
|
-
|
|
1284
|
-
},
|
|
1285
|
-
editor: slateEditor
|
|
1286
|
-
});
|
|
1281
|
+
editor: slateEditor
|
|
1282
|
+
}), !0;
|
|
1287
1283
|
}, [onDragEnter, editorActor, slateEditor]), handleDragOver = useCallback((event_12) => {
|
|
1288
1284
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
1289
1285
|
return;
|
|
1290
|
-
event_12.stopPropagation();
|
|
1291
1286
|
const position_7 = getEventPosition({
|
|
1292
1287
|
schema: editorActor.getSnapshot().context.schema,
|
|
1293
1288
|
slateEditor,
|
|
1294
1289
|
event: event_12.nativeEvent
|
|
1295
1290
|
});
|
|
1296
|
-
if (
|
|
1297
|
-
return
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
}) && event_12.preventDefault(), editorActor.send({
|
|
1306
|
-
type: "behavior event",
|
|
1307
|
-
behaviorEvent: {
|
|
1308
|
-
type: "drag.dragover",
|
|
1309
|
-
originEvent: {
|
|
1310
|
-
dataTransfer: event_12.dataTransfer
|
|
1291
|
+
if (position_7)
|
|
1292
|
+
return editorActor.send({
|
|
1293
|
+
type: "behavior event",
|
|
1294
|
+
behaviorEvent: {
|
|
1295
|
+
type: "drag.dragover",
|
|
1296
|
+
originEvent: {
|
|
1297
|
+
dataTransfer: event_12.dataTransfer
|
|
1298
|
+
},
|
|
1299
|
+
position: position_7
|
|
1311
1300
|
},
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
nativeEvent: event_12
|
|
1316
|
-
});
|
|
1301
|
+
editor: slateEditor,
|
|
1302
|
+
nativeEvent: event_12
|
|
1303
|
+
}), !0;
|
|
1317
1304
|
}, [onDragOver, editorActor, slateEditor]), handleDrop = useCallback((event_13) => {
|
|
1318
1305
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
1319
1306
|
return;
|
|
1320
|
-
event_13.preventDefault();
|
|
1321
1307
|
const position_8 = getEventPosition({
|
|
1322
1308
|
schema: editorActor.getSnapshot().context.schema,
|
|
1323
1309
|
slateEditor,
|
|
@@ -1327,14 +1313,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1327
1313
|
console.warn("Could not find position for drop event");
|
|
1328
1314
|
return;
|
|
1329
1315
|
}
|
|
1330
|
-
editorActor.send({
|
|
1331
|
-
type: "behavior event",
|
|
1332
|
-
behaviorEvent: {
|
|
1333
|
-
type: "select",
|
|
1334
|
-
selection: position_8.selection
|
|
1335
|
-
},
|
|
1336
|
-
editor: slateEditor
|
|
1337
|
-
}), editorActor.send({
|
|
1316
|
+
return editorActor.send({
|
|
1338
1317
|
type: "behavior event",
|
|
1339
1318
|
behaviorEvent: {
|
|
1340
1319
|
type: "drag.drop",
|
|
@@ -1343,23 +1322,25 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1343
1322
|
},
|
|
1344
1323
|
position: position_8
|
|
1345
1324
|
},
|
|
1346
|
-
editor: slateEditor
|
|
1347
|
-
|
|
1325
|
+
editor: slateEditor,
|
|
1326
|
+
nativeEvent: event_13
|
|
1327
|
+
}), !0;
|
|
1348
1328
|
}, [onDrop, editorActor, slateEditor]), handleDragLeave = useCallback((event_14) => {
|
|
1349
|
-
onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() ||
|
|
1329
|
+
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
1350
1330
|
schema: editorActor.getSnapshot().context.schema,
|
|
1351
1331
|
slateEditor,
|
|
1352
1332
|
event: event_14.nativeEvent
|
|
1353
|
-
})))
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1333
|
+
})))
|
|
1334
|
+
return editorActor.send({
|
|
1335
|
+
type: "behavior event",
|
|
1336
|
+
behaviorEvent: {
|
|
1337
|
+
type: "drag.dragleave",
|
|
1338
|
+
originEvent: {
|
|
1339
|
+
dataTransfer: event_14.dataTransfer
|
|
1340
|
+
}
|
|
1341
|
+
},
|
|
1342
|
+
editor: slateEditor
|
|
1343
|
+
}), !0;
|
|
1363
1344
|
}, [onDragLeave, editorActor, slateEditor]);
|
|
1364
1345
|
return portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsx(
|
|
1365
1346
|
Editable,
|