@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.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"),
|
|
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_isOverlappingSelection = require("./_chunks-cjs/selector.is-overlapping-selection.cjs"), selector_getFocusInlineObject = require("./_chunks-cjs/selector.get-focus-inline-object.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"), selector_isActiveStyle = require("./_chunks-cjs/selector.is-active-style.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
|
}
|
|
@@ -23,29 +23,36 @@ function getDragSelection({
|
|
|
23
23
|
snapshot
|
|
24
24
|
}) {
|
|
25
25
|
let dragSelection = eventSelection;
|
|
26
|
-
|
|
26
|
+
if (selector_getFocusInlineObject.getFocusInlineObject({
|
|
27
27
|
context: {
|
|
28
28
|
...snapshot.context,
|
|
29
29
|
selection: eventSelection
|
|
30
30
|
}
|
|
31
|
-
})
|
|
31
|
+
}))
|
|
32
|
+
return dragSelection;
|
|
33
|
+
const draggingCollapsedSelection = selector_isOverlappingSelection.isSelectionCollapsed({
|
|
32
34
|
context: {
|
|
33
35
|
...snapshot.context,
|
|
34
36
|
selection: eventSelection
|
|
35
37
|
}
|
|
36
|
-
}),
|
|
38
|
+
}), draggedTextBlock = selector_isOverlappingSelection.getFocusTextBlock({
|
|
39
|
+
context: {
|
|
40
|
+
...snapshot.context,
|
|
41
|
+
selection: eventSelection
|
|
42
|
+
}
|
|
43
|
+
}), draggedSpan = selector_isOverlappingSelection.getFocusSpan({
|
|
37
44
|
context: {
|
|
38
45
|
...snapshot.context,
|
|
39
46
|
selection: eventSelection
|
|
40
47
|
}
|
|
41
48
|
});
|
|
42
|
-
|
|
43
|
-
anchor: util_sliceBlocks.getBlockStartPoint(
|
|
44
|
-
focus: util_sliceBlocks.getBlockEndPoint(
|
|
49
|
+
draggingCollapsedSelection && draggedTextBlock && draggedSpan && (dragSelection = {
|
|
50
|
+
anchor: util_sliceBlocks.getBlockStartPoint(draggedTextBlock),
|
|
51
|
+
focus: util_sliceBlocks.getBlockEndPoint(draggedTextBlock)
|
|
45
52
|
});
|
|
46
|
-
const selectedBlocks =
|
|
47
|
-
if (snapshot.context.selection &&
|
|
48
|
-
const selectionStartBlock =
|
|
53
|
+
const selectedBlocks = selector_isOverlappingSelection.getSelectedBlocks(snapshot);
|
|
54
|
+
if (snapshot.context.selection && selector_isOverlappingSelection.isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
55
|
+
const selectionStartBlock = selector_isOverlappingSelection.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isOverlappingSelection.getSelectionEndBlock(snapshot);
|
|
49
56
|
if (!selectionStartBlock || !selectionEndBlock)
|
|
50
57
|
return dragSelection;
|
|
51
58
|
const selectionStartPoint = util_sliceBlocks.getBlockStartPoint(selectionStartBlock), selectionEndPoint = util_sliceBlocks.getBlockEndPoint(selectionEndBlock);
|
|
@@ -65,19 +72,6 @@ function getDragSelection({
|
|
|
65
72
|
}
|
|
66
73
|
return dragSelection;
|
|
67
74
|
}
|
|
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
|
-
}
|
|
81
75
|
function getEventPosition({
|
|
82
76
|
schema,
|
|
83
77
|
slateEditor,
|
|
@@ -356,7 +350,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
356
350
|
snapshot,
|
|
357
351
|
event
|
|
358
352
|
}) => {
|
|
359
|
-
const dropFocusBlock =
|
|
353
|
+
const dropFocusBlock = selector_isOverlappingSelection.getFocusBlock({
|
|
360
354
|
context: {
|
|
361
355
|
...snapshot.context,
|
|
362
356
|
selection: event.position.selection
|
|
@@ -365,12 +359,12 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
365
359
|
if (!dropFocusBlock || dropFocusBlock.node._key !== element._key)
|
|
366
360
|
return !1;
|
|
367
361
|
const dragOrigin = snapshot.beta.internalDrag?.origin;
|
|
368
|
-
return !dragOrigin ||
|
|
362
|
+
return !dragOrigin || selector_isOverlappingSelection.getSelectedBlocks({
|
|
369
363
|
context: {
|
|
370
364
|
...snapshot.context,
|
|
371
365
|
selection: dragOrigin.selection
|
|
372
366
|
}
|
|
373
|
-
}).some((draggedBlock) => draggedBlock.node._key === element._key) ? !1 :
|
|
367
|
+
}).some((draggedBlock) => draggedBlock.node._key === element._key) ? !1 : selector_isActiveStyle.isSelectingEntireBlocks({
|
|
374
368
|
context: {
|
|
375
369
|
...snapshot.context,
|
|
376
370
|
selection: dragOrigin.selection
|
|
@@ -1146,7 +1140,6 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1146
1140
|
const handleDragStart = React.useCallback((event_8) => {
|
|
1147
1141
|
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
1148
1142
|
return;
|
|
1149
|
-
event_8.stopPropagation();
|
|
1150
1143
|
const position_4 = getEventPosition({
|
|
1151
1144
|
schema: editorActor.getSnapshot().context.schema,
|
|
1152
1145
|
slateEditor,
|
|
@@ -1162,7 +1155,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1162
1155
|
}), dragSelection = getDragSelection({
|
|
1163
1156
|
eventSelection: position_4.selection,
|
|
1164
1157
|
snapshot
|
|
1165
|
-
}), selectingEntireBlocks =
|
|
1158
|
+
}), selectingEntireBlocks = selector_isActiveStyle.isSelectingEntireBlocks({
|
|
1166
1159
|
context: {
|
|
1167
1160
|
...snapshot.context,
|
|
1168
1161
|
selection: dragSelection
|
|
@@ -1196,7 +1189,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1196
1189
|
const childrenDomRect = getCompoundClientRect(draggedDomNodes.childNodes), x_1 = event_8.clientX - childrenDomRect.left, y_1 = event_8.clientY - childrenDomRect.top;
|
|
1197
1190
|
dragGhost.style.width = `${childrenDomRect.width}px`, dragGhost.style.height = `${childrenDomRect.height}px`, event_8.dataTransfer.setDragImage(dragGhost, x_1, y_1);
|
|
1198
1191
|
}
|
|
1199
|
-
editorActor.send({
|
|
1192
|
+
return editorActor.send({
|
|
1200
1193
|
type: "behavior event",
|
|
1201
1194
|
behaviorEvent: {
|
|
1202
1195
|
type: "select",
|
|
@@ -1225,87 +1218,79 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1225
1218
|
}
|
|
1226
1219
|
},
|
|
1227
1220
|
editor: slateEditor
|
|
1228
|
-
});
|
|
1221
|
+
}), !0;
|
|
1229
1222
|
}, [onDragStart, editorActor, slateEditor]), handleDrag = React.useCallback((event_9) => {
|
|
1230
|
-
onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() ||
|
|
1223
|
+
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
1231
1224
|
schema: editorActor.getSnapshot().context.schema,
|
|
1232
1225
|
slateEditor,
|
|
1233
1226
|
event: event_9.nativeEvent
|
|
1234
|
-
})))
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1227
|
+
})))
|
|
1228
|
+
return editorActor.send({
|
|
1229
|
+
type: "behavior event",
|
|
1230
|
+
behaviorEvent: {
|
|
1231
|
+
type: "drag.drag",
|
|
1232
|
+
originEvent: {
|
|
1233
|
+
dataTransfer: event_9.dataTransfer
|
|
1234
|
+
}
|
|
1235
|
+
},
|
|
1236
|
+
editor: slateEditor
|
|
1237
|
+
}), !0;
|
|
1244
1238
|
}, [onDrag, editorActor, slateEditor]), handleDragEnd = React.useCallback((event_10) => {
|
|
1245
|
-
onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped())
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1239
|
+
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
1240
|
+
return editorActor.send({
|
|
1241
|
+
type: "behavior event",
|
|
1242
|
+
behaviorEvent: {
|
|
1243
|
+
type: "drag.dragend",
|
|
1244
|
+
originEvent: {
|
|
1245
|
+
dataTransfer: event_10.dataTransfer
|
|
1246
|
+
}
|
|
1247
|
+
},
|
|
1248
|
+
editor: slateEditor
|
|
1249
|
+
}), !0;
|
|
1255
1250
|
}, [onDragEnd, editorActor, slateEditor]), handleDragEnter = React.useCallback((event_11) => {
|
|
1256
1251
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
1257
1252
|
return;
|
|
1258
|
-
event_11.stopPropagation();
|
|
1259
1253
|
const position_6 = getEventPosition({
|
|
1260
1254
|
schema: editorActor.getSnapshot().context.schema,
|
|
1261
1255
|
slateEditor,
|
|
1262
1256
|
event: event_11.nativeEvent
|
|
1263
1257
|
});
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1258
|
+
if (position_6)
|
|
1259
|
+
return editorActor.send({
|
|
1260
|
+
type: "behavior event",
|
|
1261
|
+
behaviorEvent: {
|
|
1262
|
+
type: "drag.dragenter",
|
|
1263
|
+
originEvent: {
|
|
1264
|
+
dataTransfer: event_11.dataTransfer
|
|
1265
|
+
},
|
|
1266
|
+
position: position_6
|
|
1270
1267
|
},
|
|
1271
|
-
|
|
1272
|
-
},
|
|
1273
|
-
editor: slateEditor
|
|
1274
|
-
});
|
|
1268
|
+
editor: slateEditor
|
|
1269
|
+
}), !0;
|
|
1275
1270
|
}, [onDragEnter, editorActor, slateEditor]), handleDragOver = React.useCallback((event_12) => {
|
|
1276
1271
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
1277
1272
|
return;
|
|
1278
|
-
event_12.stopPropagation();
|
|
1279
1273
|
const position_7 = getEventPosition({
|
|
1280
1274
|
schema: editorActor.getSnapshot().context.schema,
|
|
1281
1275
|
slateEditor,
|
|
1282
1276
|
event: event_12.nativeEvent
|
|
1283
1277
|
});
|
|
1284
|
-
if (
|
|
1285
|
-
return
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
}) && event_12.preventDefault(), editorActor.send({
|
|
1294
|
-
type: "behavior event",
|
|
1295
|
-
behaviorEvent: {
|
|
1296
|
-
type: "drag.dragover",
|
|
1297
|
-
originEvent: {
|
|
1298
|
-
dataTransfer: event_12.dataTransfer
|
|
1278
|
+
if (position_7)
|
|
1279
|
+
return editorActor.send({
|
|
1280
|
+
type: "behavior event",
|
|
1281
|
+
behaviorEvent: {
|
|
1282
|
+
type: "drag.dragover",
|
|
1283
|
+
originEvent: {
|
|
1284
|
+
dataTransfer: event_12.dataTransfer
|
|
1285
|
+
},
|
|
1286
|
+
position: position_7
|
|
1299
1287
|
},
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
nativeEvent: event_12
|
|
1304
|
-
});
|
|
1288
|
+
editor: slateEditor,
|
|
1289
|
+
nativeEvent: event_12
|
|
1290
|
+
}), !0;
|
|
1305
1291
|
}, [onDragOver, editorActor, slateEditor]), handleDrop = React.useCallback((event_13) => {
|
|
1306
1292
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
1307
1293
|
return;
|
|
1308
|
-
event_13.preventDefault();
|
|
1309
1294
|
const position_8 = getEventPosition({
|
|
1310
1295
|
schema: editorActor.getSnapshot().context.schema,
|
|
1311
1296
|
slateEditor,
|
|
@@ -1315,14 +1300,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1315
1300
|
console.warn("Could not find position for drop event");
|
|
1316
1301
|
return;
|
|
1317
1302
|
}
|
|
1318
|
-
editorActor.send({
|
|
1319
|
-
type: "behavior event",
|
|
1320
|
-
behaviorEvent: {
|
|
1321
|
-
type: "select",
|
|
1322
|
-
selection: position_8.selection
|
|
1323
|
-
},
|
|
1324
|
-
editor: slateEditor
|
|
1325
|
-
}), editorActor.send({
|
|
1303
|
+
return editorActor.send({
|
|
1326
1304
|
type: "behavior event",
|
|
1327
1305
|
behaviorEvent: {
|
|
1328
1306
|
type: "drag.drop",
|
|
@@ -1331,23 +1309,25 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1331
1309
|
},
|
|
1332
1310
|
position: position_8
|
|
1333
1311
|
},
|
|
1334
|
-
editor: slateEditor
|
|
1335
|
-
|
|
1312
|
+
editor: slateEditor,
|
|
1313
|
+
nativeEvent: event_13
|
|
1314
|
+
}), !0;
|
|
1336
1315
|
}, [onDrop, editorActor, slateEditor]), handleDragLeave = React.useCallback((event_14) => {
|
|
1337
|
-
onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() ||
|
|
1316
|
+
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
1338
1317
|
schema: editorActor.getSnapshot().context.schema,
|
|
1339
1318
|
slateEditor,
|
|
1340
1319
|
event: event_14.nativeEvent
|
|
1341
|
-
})))
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1320
|
+
})))
|
|
1321
|
+
return editorActor.send({
|
|
1322
|
+
type: "behavior event",
|
|
1323
|
+
behaviorEvent: {
|
|
1324
|
+
type: "drag.dragleave",
|
|
1325
|
+
originEvent: {
|
|
1326
|
+
dataTransfer: event_14.dataTransfer
|
|
1327
|
+
}
|
|
1328
|
+
},
|
|
1329
|
+
editor: slateEditor
|
|
1330
|
+
}), !0;
|
|
1351
1331
|
}, [onDragLeave, editorActor, slateEditor]);
|
|
1352
1332
|
return portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1353
1333
|
slateReact.Editable,
|