@portabletext/editor 1.40.3 → 1.40.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/editor-provider.cjs +66 -33
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +6 -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 +67 -34
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +7 -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 +47 -13
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +49 -14
- package/lib/index.js.map +1 -1
- package/lib/utils/index.cjs +2 -5
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +1 -2
- package/lib/utils/index.d.ts +1 -2
- package/lib/utils/index.js +1 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +3 -3
- package/src/behavior-actions/behavior.action.insert-blocks.ts +5 -1
- package/src/internal-utils/drag-selection.test.ts +74 -1
- package/src/internal-utils/drag-selection.ts +20 -4
- package/src/internal-utils/event-position.ts +38 -7
- package/src/internal-utils/slate-utils.ts +60 -1
- package/src/utils/util.is-keyed-segment.ts +2 -2
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getNodeBlock, 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";
|
|
@@ -7,10 +7,11 @@ import noop from "lodash/noop.js";
|
|
|
7
7
|
import { useContext, useRef, useState, useEffect, useMemo, startTransition, useCallback, forwardRef, useImperativeHandle } from "react";
|
|
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
|
-
import { getBlockEndPoint, getBlockStartPoint } from "./_chunks-es/util.slice-blocks.js";
|
|
10
|
+
import { getBlockEndPoint, getBlockStartPoint, isKeyedSegment } from "./_chunks-es/util.slice-blocks.js";
|
|
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
15
|
import { parseBlocks } from "./_chunks-es/util.selection-point-to-block-offset.js";
|
|
15
16
|
import { defineBehavior, isHotkey } from "./_chunks-es/behavior.core.js";
|
|
16
17
|
import { c } from "react-compiler-runtime";
|
|
@@ -55,11 +56,23 @@ function getDragSelection({
|
|
|
55
56
|
focus: getBlockEndPoint(focusTextBlock)
|
|
56
57
|
});
|
|
57
58
|
const selectedBlocks = getSelectedBlocks(snapshot);
|
|
58
|
-
if (snapshot.context.selection && isSelectionExpanded(snapshot) &&
|
|
59
|
+
if (snapshot.context.selection && isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
59
60
|
const selectionStartBlock = getSelectionStartBlock(snapshot), selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
60
|
-
selectionStartBlock
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
if (!selectionStartBlock || !selectionEndBlock)
|
|
62
|
+
return dragSelection;
|
|
63
|
+
const selectionStartPoint = getBlockStartPoint(selectionStartBlock), selectionEndPoint = getBlockEndPoint(selectionEndBlock);
|
|
64
|
+
isOverlappingSelection(eventSelection)({
|
|
65
|
+
...snapshot,
|
|
66
|
+
context: {
|
|
67
|
+
...snapshot.context,
|
|
68
|
+
selection: {
|
|
69
|
+
anchor: selectionStartPoint,
|
|
70
|
+
focus: selectionEndPoint
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}) && (dragSelection = {
|
|
74
|
+
anchor: selectionStartPoint,
|
|
75
|
+
focus: selectionEndPoint
|
|
63
76
|
});
|
|
64
77
|
}
|
|
65
78
|
return dragSelection;
|
|
@@ -75,7 +88,11 @@ function getEventPosition({
|
|
|
75
88
|
});
|
|
76
89
|
if (!node)
|
|
77
90
|
return;
|
|
78
|
-
const
|
|
91
|
+
const block = getNodeBlock({
|
|
92
|
+
editor: slateEditor,
|
|
93
|
+
schema,
|
|
94
|
+
node
|
|
95
|
+
}), positionBlock = getEventPositionBlock({
|
|
79
96
|
node,
|
|
80
97
|
slateEditor,
|
|
81
98
|
event
|
|
@@ -84,9 +101,8 @@ function getEventPosition({
|
|
|
84
101
|
slateEditor,
|
|
85
102
|
event
|
|
86
103
|
});
|
|
87
|
-
if (positionBlock && !selection && !Editor.isEditor(node))
|
|
88
|
-
|
|
89
|
-
return block ? {
|
|
104
|
+
if (block && positionBlock && !selection && !Editor.isEditor(node))
|
|
105
|
+
return {
|
|
90
106
|
block: positionBlock,
|
|
91
107
|
isEditor: !1,
|
|
92
108
|
selection: {
|
|
@@ -103,10 +119,29 @@ function getEventPosition({
|
|
|
103
119
|
}]
|
|
104
120
|
})
|
|
105
121
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
};
|
|
123
|
+
if (!positionBlock || !selection)
|
|
124
|
+
return;
|
|
125
|
+
const focusBlockPath = selection.focus.path.at(0), focusBlockKey = isKeyedSegment(focusBlockPath) ? focusBlockPath._key : void 0;
|
|
126
|
+
if (focusBlockKey)
|
|
127
|
+
return isSelectionCollapsed$1(selection) && block && focusBlockKey !== block._key ? {
|
|
128
|
+
block: positionBlock,
|
|
129
|
+
isEditor: !1,
|
|
130
|
+
selection: {
|
|
131
|
+
anchor: getBlockStartPoint({
|
|
132
|
+
node: block,
|
|
133
|
+
path: [{
|
|
134
|
+
_key: block._key
|
|
135
|
+
}]
|
|
136
|
+
}),
|
|
137
|
+
focus: getBlockEndPoint({
|
|
138
|
+
node: block,
|
|
139
|
+
path: [{
|
|
140
|
+
_key: block._key
|
|
141
|
+
}]
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
} : {
|
|
110
145
|
block: positionBlock,
|
|
111
146
|
isEditor: Editor.isEditor(node),
|
|
112
147
|
selection
|