@portabletext/editor 1.41.3 → 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 +2 -2
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
- 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 +1 -1
- 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 +75 -102
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +66 -93
- 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 +36 -36
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +4 -4
- 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/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
|
@@ -1,234 +1,299 @@
|
|
|
1
|
-
import { getBlockStartPoint, getBlockEndPoint,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { isSpan, sliceBlocks, spanSelectionPointToBlockOffset, getBlockStartPoint, getBlockEndPoint, blockOffsetToSpanSelectionPoint, isEqualSelectionPoints, reverseSelection } from "./util.slice-blocks.js";
|
|
2
|
+
import { isPortableTextTextBlock, isPortableTextListBlock, isPortableTextSpan, isKeySegment } from "@sanity/types";
|
|
3
|
+
function createGuards({
|
|
4
|
+
schema
|
|
5
|
+
}) {
|
|
6
|
+
function isListBlock(block) {
|
|
7
|
+
return isPortableTextListBlock(block) && block._type === schema.block.name;
|
|
8
|
+
}
|
|
9
|
+
function isTextBlock(block) {
|
|
10
|
+
return isPortableTextTextBlock(block) && block._type === schema.block.name;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
isListBlock,
|
|
14
|
+
isTextBlock
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const getFocusBlock = (snapshot) => {
|
|
18
|
+
const key = snapshot.context.selection && isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
19
|
+
return node && key ? {
|
|
20
|
+
node,
|
|
21
|
+
path: [{
|
|
22
|
+
_key: key
|
|
23
|
+
}]
|
|
24
|
+
} : void 0;
|
|
25
|
+
}, getFocusListBlock = (snapshot) => {
|
|
26
|
+
const guards = createGuards(snapshot.context), focusBlock = getFocusBlock(snapshot);
|
|
27
|
+
return focusBlock && guards.isListBlock(focusBlock.node) ? {
|
|
28
|
+
node: focusBlock.node,
|
|
29
|
+
path: focusBlock.path
|
|
30
|
+
} : void 0;
|
|
31
|
+
}, getFocusTextBlock = (snapshot) => {
|
|
32
|
+
const focusBlock = getFocusBlock(snapshot);
|
|
33
|
+
return focusBlock && isPortableTextTextBlock(focusBlock.node) ? {
|
|
34
|
+
node: focusBlock.node,
|
|
35
|
+
path: focusBlock.path
|
|
36
|
+
} : void 0;
|
|
37
|
+
}, getFocusBlockObject = (snapshot) => {
|
|
38
|
+
const focusBlock = getFocusBlock(snapshot);
|
|
39
|
+
return focusBlock && !isPortableTextTextBlock(focusBlock.node) ? {
|
|
40
|
+
node: focusBlock.node,
|
|
41
|
+
path: focusBlock.path
|
|
42
|
+
} : void 0;
|
|
43
|
+
}, getFocusChild = (snapshot) => {
|
|
44
|
+
const focusBlock = getFocusTextBlock(snapshot);
|
|
45
|
+
if (!focusBlock)
|
|
46
|
+
return;
|
|
47
|
+
const key = snapshot.context.selection && isKeySegment(snapshot.context.selection.focus.path[2]) ? snapshot.context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
48
|
+
return node && key ? {
|
|
49
|
+
node,
|
|
50
|
+
path: [...focusBlock.path, "children", {
|
|
51
|
+
_key: key
|
|
52
|
+
}]
|
|
53
|
+
} : void 0;
|
|
54
|
+
}, getFocusSpan = (snapshot) => {
|
|
55
|
+
const focusChild = getFocusChild(snapshot);
|
|
56
|
+
return focusChild && isPortableTextSpan(focusChild.node) ? {
|
|
57
|
+
node: focusChild.node,
|
|
58
|
+
path: focusChild.path
|
|
59
|
+
} : void 0;
|
|
60
|
+
}, getFirstBlock = (snapshot) => {
|
|
61
|
+
const node = snapshot.context.value[0];
|
|
62
|
+
return node ? {
|
|
63
|
+
node,
|
|
64
|
+
path: [{
|
|
65
|
+
_key: node._key
|
|
66
|
+
}]
|
|
67
|
+
} : void 0;
|
|
68
|
+
}, getLastBlock = (snapshot) => {
|
|
69
|
+
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
70
|
+
return node ? {
|
|
71
|
+
node,
|
|
72
|
+
path: [{
|
|
73
|
+
_key: node._key
|
|
74
|
+
}]
|
|
75
|
+
} : void 0;
|
|
76
|
+
}, getSelectedBlocks = (snapshot) => {
|
|
13
77
|
if (!snapshot.context.selection)
|
|
14
78
|
return [];
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
17
|
-
return
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (startPoint.offset < child.text.length && selectedSpans.push({
|
|
27
|
-
node: child,
|
|
28
|
-
path: [{
|
|
29
|
-
_key: block._key
|
|
30
|
-
}, "children", {
|
|
31
|
-
_key: child._key
|
|
32
|
-
}]
|
|
33
|
-
}), startSpanKey === endSpanKey)
|
|
34
|
-
break;
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (endSpanKey && child._key === endSpanKey) {
|
|
38
|
-
endPoint.offset > 0 && selectedSpans.push({
|
|
39
|
-
node: child,
|
|
40
|
-
path: [{
|
|
41
|
-
_key: block._key
|
|
42
|
-
}, "children", {
|
|
43
|
-
_key: child._key
|
|
44
|
-
}]
|
|
45
|
-
});
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
selectedSpans.length > 0 && selectedSpans.push({
|
|
49
|
-
node: child,
|
|
50
|
-
path: [{
|
|
51
|
-
_key: block._key
|
|
52
|
-
}, "children", {
|
|
53
|
-
_key: child._key
|
|
54
|
-
}]
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
if (startBlockKey === endBlockKey)
|
|
58
|
-
break;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (block._key === endBlockKey) {
|
|
62
|
-
for (const child of block.children)
|
|
63
|
-
if (isPortableTextSpan(child)) {
|
|
64
|
-
if (endSpanKey && child._key === endSpanKey) {
|
|
65
|
-
endPoint.offset > 0 && selectedSpans.push({
|
|
66
|
-
node: child,
|
|
67
|
-
path: [{
|
|
68
|
-
_key: block._key
|
|
69
|
-
}, "children", {
|
|
70
|
-
_key: child._key
|
|
71
|
-
}]
|
|
72
|
-
});
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
selectedSpans.push({
|
|
76
|
-
node: child,
|
|
77
|
-
path: [{
|
|
78
|
-
_key: block._key
|
|
79
|
-
}, "children", {
|
|
80
|
-
_key: child._key
|
|
81
|
-
}]
|
|
82
|
-
});
|
|
83
|
-
}
|
|
79
|
+
const selectedBlocks = [], startKey = snapshot.context.selection.backward ? isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, endKey = snapshot.context.selection.backward ? isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0;
|
|
80
|
+
if (!startKey || !endKey)
|
|
81
|
+
return selectedBlocks;
|
|
82
|
+
for (const block of snapshot.context.value) {
|
|
83
|
+
if (block._key === startKey) {
|
|
84
|
+
if (selectedBlocks.push({
|
|
85
|
+
node: block,
|
|
86
|
+
path: [{
|
|
87
|
+
_key: block._key
|
|
88
|
+
}]
|
|
89
|
+
}), startKey === endKey)
|
|
84
90
|
break;
|
|
85
|
-
|
|
86
|
-
if (startBlockFound)
|
|
87
|
-
for (const child of block.children)
|
|
88
|
-
isPortableTextSpan(child) && selectedSpans.push({
|
|
89
|
-
node: child,
|
|
90
|
-
path: [{
|
|
91
|
-
_key: block._key
|
|
92
|
-
}, "children", {
|
|
93
|
-
_key: child._key
|
|
94
|
-
}]
|
|
95
|
-
});
|
|
91
|
+
continue;
|
|
96
92
|
}
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
if (block._key === endKey) {
|
|
94
|
+
selectedBlocks.push({
|
|
95
|
+
node: block,
|
|
96
|
+
path: [{
|
|
97
|
+
_key: block._key
|
|
98
|
+
}]
|
|
99
|
+
});
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
103
|
+
node: block,
|
|
104
|
+
path: [{
|
|
105
|
+
_key: block._key
|
|
106
|
+
}]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return selectedBlocks;
|
|
110
|
+
}, getSelectionStartBlock = (snapshot) => {
|
|
99
111
|
if (!snapshot.context.selection)
|
|
100
112
|
return;
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
113
|
+
const key = snapshot.context.selection.backward ? isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
114
|
+
return node && key ? {
|
|
115
|
+
node,
|
|
116
|
+
path: [{
|
|
117
|
+
_key: key
|
|
118
|
+
}]
|
|
119
|
+
} : void 0;
|
|
120
|
+
}, getSelectionEndBlock = (snapshot) => {
|
|
108
121
|
if (!snapshot.context.selection)
|
|
109
122
|
return;
|
|
110
|
-
const
|
|
111
|
-
|
|
123
|
+
const key = snapshot.context.selection.backward ? isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
124
|
+
return node && key ? {
|
|
125
|
+
node,
|
|
126
|
+
path: [{
|
|
127
|
+
_key: key
|
|
128
|
+
}]
|
|
129
|
+
} : void 0;
|
|
130
|
+
}, getPreviousBlock = (snapshot) => {
|
|
131
|
+
let previousBlock;
|
|
132
|
+
const selectionStartBlock = getSelectionStartBlock(snapshot);
|
|
133
|
+
if (!selectionStartBlock)
|
|
112
134
|
return;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
135
|
+
let foundSelectionStartBlock = !1;
|
|
136
|
+
for (const block of snapshot.context.value) {
|
|
137
|
+
if (block._key === selectionStartBlock.node._key) {
|
|
138
|
+
foundSelectionStartBlock = !0;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
previousBlock = {
|
|
142
|
+
node: block,
|
|
143
|
+
path: [{
|
|
144
|
+
_key: block._key
|
|
145
|
+
}]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (foundSelectionStartBlock && previousBlock)
|
|
149
|
+
return previousBlock;
|
|
150
|
+
}, getNextBlock = (snapshot) => {
|
|
151
|
+
let nextBlock;
|
|
152
|
+
const selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
153
|
+
if (!selectionEndBlock)
|
|
154
|
+
return;
|
|
155
|
+
let foundSelectionEndBlock = !1;
|
|
156
|
+
for (const block of snapshot.context.value) {
|
|
157
|
+
if (block._key === selectionEndBlock.node._key) {
|
|
158
|
+
foundSelectionEndBlock = !0;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (foundSelectionEndBlock) {
|
|
162
|
+
nextBlock = {
|
|
163
|
+
node: block,
|
|
164
|
+
path: [{
|
|
165
|
+
_key: block._key
|
|
166
|
+
}]
|
|
167
|
+
};
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (foundSelectionEndBlock && nextBlock)
|
|
172
|
+
return nextBlock;
|
|
173
|
+
}, getSelectionEndPoint = (snapshot) => {
|
|
174
|
+
if (snapshot.context.selection)
|
|
175
|
+
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
176
|
+
}, getSelectionStartPoint = (snapshot) => {
|
|
177
|
+
if (snapshot.context.selection)
|
|
178
|
+
return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
|
|
179
|
+
}, getNextInlineObject = (snapshot) => {
|
|
180
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
181
|
+
if (!focusTextBlock || !selectionEndPointChildKey)
|
|
182
|
+
return;
|
|
183
|
+
let endPointChildFound = !1, inlineObject;
|
|
184
|
+
for (const child of focusTextBlock.node.children) {
|
|
185
|
+
if (child._key === selectionEndPointChildKey) {
|
|
186
|
+
endPointChildFound = !0;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (!isSpan(snapshot.context, child) && endPointChildFound) {
|
|
190
|
+
inlineObject = {
|
|
191
|
+
node: child,
|
|
192
|
+
path: [...focusTextBlock.path, "children", {
|
|
193
|
+
_key: child._key
|
|
194
|
+
}]
|
|
195
|
+
};
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return inlineObject;
|
|
200
|
+
}, getPreviousInlineObject = (snapshot) => {
|
|
201
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
|
|
202
|
+
if (!focusTextBlock || !selectionStartPointChildKey)
|
|
203
|
+
return;
|
|
204
|
+
let inlineObject;
|
|
205
|
+
for (const child of focusTextBlock.node.children) {
|
|
206
|
+
if (child._key === selectionStartPointChildKey)
|
|
207
|
+
break;
|
|
208
|
+
isSpan(snapshot.context, child) || (inlineObject = {
|
|
209
|
+
node: child,
|
|
210
|
+
path: [...focusTextBlock.path, "children", {
|
|
211
|
+
_key: child._key
|
|
212
|
+
}]
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return inlineObject;
|
|
216
|
+
}, getSelectedSlice = (snapshot) => sliceBlocks({
|
|
217
|
+
blocks: snapshot.context.value,
|
|
218
|
+
selection: snapshot.context.selection
|
|
219
|
+
}), getSelectionText = (snapshot) => getSelectedSlice(snapshot).reduce((text, block) => isPortableTextTextBlock(block) ? text + block.children.reduce((text2, child) => isPortableTextSpan(child) ? text2 + child.text : text2, "") : text, ""), isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot), getCaretWordSelection = (snapshot) => {
|
|
220
|
+
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
221
|
+
return null;
|
|
222
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? spanSelectionPointToBlockOffset({
|
|
223
|
+
value: snapshot.context.value,
|
|
224
|
+
selectionPoint: selectionStartPoint
|
|
225
|
+
}) : void 0;
|
|
226
|
+
if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset)
|
|
227
|
+
return null;
|
|
228
|
+
const previousInlineObject = getPreviousInlineObject(snapshot), blockStartPoint = getBlockStartPoint(focusTextBlock), textDirectlyBefore = getSelectionText({
|
|
229
|
+
context: {
|
|
230
|
+
...snapshot.context,
|
|
231
|
+
selection: {
|
|
232
|
+
anchor: previousInlineObject ? {
|
|
233
|
+
path: previousInlineObject.path,
|
|
234
|
+
offset: 0
|
|
235
|
+
} : blockStartPoint,
|
|
236
|
+
focus: selectionStartPoint
|
|
174
237
|
}
|
|
175
|
-
if (block._key === endBlockKey)
|
|
176
|
-
break;
|
|
177
238
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
239
|
+
}).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = getBlockEndPoint(focusTextBlock), textDirectlyAfter = getSelectionText({
|
|
240
|
+
context: {
|
|
241
|
+
...snapshot.context,
|
|
242
|
+
selection: {
|
|
243
|
+
anchor: selectionStartPoint,
|
|
244
|
+
focus: nextInlineObject ? {
|
|
245
|
+
path: nextInlineObject.path,
|
|
246
|
+
offset: 0
|
|
247
|
+
} : blockEndPoint
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}).split(/\s+/).at(0);
|
|
251
|
+
if ((textDirectlyBefore === void 0 || textDirectlyBefore === "") && (textDirectlyAfter === void 0 || textDirectlyAfter === ""))
|
|
252
|
+
return null;
|
|
253
|
+
const caretWordStartOffset = textDirectlyBefore ? {
|
|
254
|
+
...selectionStartOffset,
|
|
255
|
+
offset: selectionStartOffset.offset - textDirectlyBefore.length
|
|
256
|
+
} : selectionStartOffset, caretWordEndOffset = textDirectlyAfter ? {
|
|
257
|
+
...selectionStartOffset,
|
|
258
|
+
offset: selectionStartOffset.offset + textDirectlyAfter.length
|
|
259
|
+
} : selectionStartOffset, caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({
|
|
260
|
+
value: snapshot.context.value,
|
|
261
|
+
blockOffset: caretWordStartOffset,
|
|
262
|
+
direction: "backward"
|
|
263
|
+
}), caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({
|
|
264
|
+
value: snapshot.context.value,
|
|
265
|
+
blockOffset: caretWordEndOffset,
|
|
266
|
+
direction: "forward"
|
|
267
|
+
});
|
|
268
|
+
if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint)
|
|
269
|
+
return null;
|
|
270
|
+
const caretWordSelection = {
|
|
271
|
+
anchor: caretWordStartSelectionPoint,
|
|
272
|
+
focus: caretWordEndSelectionPoint
|
|
185
273
|
};
|
|
186
|
-
|
|
274
|
+
return isSelectionExpanded({
|
|
187
275
|
context: {
|
|
188
276
|
...snapshot.context,
|
|
189
|
-
selection:
|
|
277
|
+
selection: caretWordSelection
|
|
190
278
|
}
|
|
191
|
-
})
|
|
192
|
-
const focusTextBlock = getFocusTextBlock({
|
|
193
|
-
context: {
|
|
194
|
-
...snapshot.context,
|
|
195
|
-
selection: trimmedSelection
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
if (focusTextBlock && !isEmptyTextBlock(focusTextBlock.node))
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
return trimmedSelection;
|
|
279
|
+
}) ? caretWordSelection : null;
|
|
202
280
|
};
|
|
203
|
-
function
|
|
281
|
+
function isAtTheEndOfBlock(block) {
|
|
204
282
|
return (snapshot) => {
|
|
205
|
-
if (!snapshot.context.selection)
|
|
283
|
+
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
206
284
|
return !1;
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
return !1;
|
|
210
|
-
const selectionMarkDefs = selectedBlocks.flatMap((block) => isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []);
|
|
211
|
-
return selectedSpans.every((span) => (span.node.marks?.flatMap((mark) => {
|
|
212
|
-
const markDef = selectionMarkDefs.find((markDef2) => markDef2._key === mark);
|
|
213
|
-
return markDef ? [markDef._type] : [];
|
|
214
|
-
}) ?? []).includes(annotation));
|
|
285
|
+
const blockEndPoint = getBlockEndPoint(block);
|
|
286
|
+
return isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
|
|
215
287
|
};
|
|
216
288
|
}
|
|
217
|
-
function
|
|
289
|
+
function isAtTheStartOfBlock(block) {
|
|
218
290
|
return (snapshot) => {
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return snapshot.context.activeDecorators.includes(decorator);
|
|
291
|
+
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
292
|
+
return !1;
|
|
293
|
+
const blockStartPoint = getBlockStartPoint(block);
|
|
294
|
+
return isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
|
|
224
295
|
};
|
|
225
296
|
}
|
|
226
|
-
function isActiveListItem(listItem) {
|
|
227
|
-
return (snapshot) => getActiveListItem(snapshot) === listItem;
|
|
228
|
-
}
|
|
229
|
-
function isActiveStyle(style) {
|
|
230
|
-
return (snapshot) => getActiveStyle(snapshot) === style;
|
|
231
|
-
}
|
|
232
297
|
function isPointAfterSelection(point) {
|
|
233
298
|
return (snapshot) => {
|
|
234
299
|
if (!snapshot.context.selection)
|
|
@@ -357,17 +422,33 @@ function isOverlappingSelection(selection) {
|
|
|
357
422
|
};
|
|
358
423
|
}
|
|
359
424
|
export {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
425
|
+
createGuards,
|
|
426
|
+
getCaretWordSelection,
|
|
427
|
+
getFirstBlock,
|
|
428
|
+
getFocusBlock,
|
|
429
|
+
getFocusBlockObject,
|
|
430
|
+
getFocusChild,
|
|
431
|
+
getFocusListBlock,
|
|
432
|
+
getFocusSpan,
|
|
433
|
+
getFocusTextBlock,
|
|
434
|
+
getLastBlock,
|
|
435
|
+
getNextBlock,
|
|
436
|
+
getNextInlineObject,
|
|
437
|
+
getPreviousBlock,
|
|
438
|
+
getPreviousInlineObject,
|
|
439
|
+
getSelectedBlocks,
|
|
440
|
+
getSelectedSlice,
|
|
441
|
+
getSelectionEndBlock,
|
|
442
|
+
getSelectionEndPoint,
|
|
443
|
+
getSelectionStartBlock,
|
|
444
|
+
getSelectionStartPoint,
|
|
445
|
+
getSelectionText,
|
|
446
|
+
isAtTheEndOfBlock,
|
|
447
|
+
isAtTheStartOfBlock,
|
|
368
448
|
isOverlappingSelection,
|
|
369
449
|
isPointAfterSelection,
|
|
370
450
|
isPointBeforeSelection,
|
|
371
|
-
|
|
451
|
+
isSelectionCollapsed,
|
|
452
|
+
isSelectionExpanded
|
|
372
453
|
};
|
|
373
454
|
//# sourceMappingURL=selector.is-overlapping-selection.js.map
|