@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
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
import { isSpan, sliceBlocks, spanSelectionPointToBlockOffset, getBlockStartPoint, getBlockEndPoint, blockOffsetToSpanSelectionPoint, isEqualSelectionPoints } 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) => {
|
|
77
|
-
if (!snapshot.context.selection)
|
|
78
|
-
return [];
|
|
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)
|
|
90
|
-
break;
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
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) => {
|
|
111
|
-
if (!snapshot.context.selection)
|
|
112
|
-
return;
|
|
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) => {
|
|
121
|
-
if (!snapshot.context.selection)
|
|
122
|
-
return;
|
|
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)
|
|
134
|
-
return;
|
|
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
|
|
237
|
-
}
|
|
238
|
-
}
|
|
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
|
|
273
|
-
};
|
|
274
|
-
return isSelectionExpanded({
|
|
275
|
-
context: {
|
|
276
|
-
...snapshot.context,
|
|
277
|
-
selection: caretWordSelection
|
|
278
|
-
}
|
|
279
|
-
}) ? caretWordSelection : null;
|
|
280
|
-
};
|
|
281
|
-
function isAtTheEndOfBlock(block) {
|
|
282
|
-
return (snapshot) => {
|
|
283
|
-
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
284
|
-
return !1;
|
|
285
|
-
const blockEndPoint = getBlockEndPoint(block);
|
|
286
|
-
return isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
function isAtTheStartOfBlock(block) {
|
|
290
|
-
return (snapshot) => {
|
|
291
|
-
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
292
|
-
return !1;
|
|
293
|
-
const blockStartPoint = getBlockStartPoint(block);
|
|
294
|
-
return isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
export {
|
|
298
|
-
createGuards,
|
|
299
|
-
getCaretWordSelection,
|
|
300
|
-
getFirstBlock,
|
|
301
|
-
getFocusBlock,
|
|
302
|
-
getFocusBlockObject,
|
|
303
|
-
getFocusChild,
|
|
304
|
-
getFocusListBlock,
|
|
305
|
-
getFocusSpan,
|
|
306
|
-
getFocusTextBlock,
|
|
307
|
-
getLastBlock,
|
|
308
|
-
getNextBlock,
|
|
309
|
-
getNextInlineObject,
|
|
310
|
-
getPreviousBlock,
|
|
311
|
-
getPreviousInlineObject,
|
|
312
|
-
getSelectedBlocks,
|
|
313
|
-
getSelectedSlice,
|
|
314
|
-
getSelectionEndBlock,
|
|
315
|
-
getSelectionEndPoint,
|
|
316
|
-
getSelectionStartBlock,
|
|
317
|
-
getSelectionStartPoint,
|
|
318
|
-
getSelectionText,
|
|
319
|
-
isAtTheEndOfBlock,
|
|
320
|
-
isAtTheStartOfBlock,
|
|
321
|
-
isSelectionCollapsed,
|
|
322
|
-
isSelectionExpanded
|
|
323
|
-
};
|
|
324
|
-
//# sourceMappingURL=selector.is-at-the-start-of-block.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-at-the-start-of-block.js","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.get-next-inline-object.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const guards = createGuards(snapshot.context)\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeySegment(snapshot.context.selection.focus.path[2])\n ? snapshot.context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[snapshot.context.value.length - 1]\n ? snapshot.context.value[snapshot.context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = snapshot.context.selection.backward\n ? isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n const endKey = snapshot.context.selection.backward\n ? isKeySegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of snapshot.context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = snapshot.context.selection.backward\n ? isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = snapshot.context.selection.backward\n ? isKeySegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of snapshot.context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of snapshot.context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import type {EditorSelectionPoint} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n}\n","import type {EditorSelectionPoint} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return undefined\n }\n\n let endPointChildFound = false\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(snapshot.context, child) && endPointChildFound) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return inlineObject\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return sliceBlocks({\n blocks: snapshot.context.value,\n selection: snapshot.context.selection,\n })\n}\n","import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSlice} from './selector.get-selected-slice'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedSlice = getSelectedSlice(snapshot)\n\n return selectedSlice.reduce((text, block) => {\n if (!isPortableTextTextBlock(block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isPortableTextSpan(child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return !isSelectionCollapsed(snapshot)\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n getBlockEndPoint,\n getBlockStartPoint,\n spanSelectionPointToBlockOffset,\n} from '../utils'\nimport {getNextInlineObject} from './selector.get-next-inline-object'\nimport {getPreviousInlineObject} from './selector.get-previous-inline-object'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n * Returns the selection of the of the word the caret is placed in.\n * Note: Only returns a word selection if the current selection is collapsed\n */\nexport const getCaretWordSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed(snapshot)) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject(snapshot)\n const blockStartPoint = getBlockStartPoint(focusTextBlock)\n const textBefore = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: previousInlineObject\n ? {path: previousInlineObject.path, offset: 0}\n : blockStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const textDirectlyBefore = textBefore.split(/\\s+/).at(-1)\n\n const nextInlineObject = getNextInlineObject(snapshot)\n const blockEndPoint = getBlockEndPoint(focusTextBlock)\n const textAfter = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: nextInlineObject\n ? {path: nextInlineObject.path, offset: 0}\n : blockEndPoint,\n },\n },\n })\n const textDirectlyAfter = textAfter.split(/\\s+/).at(0)\n\n if (\n (textDirectlyBefore === undefined || textDirectlyBefore === '') &&\n (textDirectlyAfter === undefined || textDirectlyAfter === '')\n ) {\n return null\n }\n\n const caretWordStartOffset: BlockOffset = textDirectlyBefore\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset - textDirectlyBefore.length,\n }\n : selectionStartOffset\n const caretWordEndOffset: BlockOffset = textDirectlyAfter\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset + textDirectlyAfter.length,\n }\n : selectionStartOffset\n\n const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: snapshot.context.value,\n blockOffset: caretWordStartOffset,\n direction: 'backward',\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: snapshot.context.value,\n blockOffset: caretWordEndOffset,\n direction: 'forward',\n })\n\n if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {\n return null\n }\n\n const caretWordSelection = {\n anchor: caretWordStartSelectionPoint,\n focus: caretWordEndSelectionPoint,\n }\n\n return isSelectionExpanded({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockEndPoint = utils.getBlockEndPoint(block)\n\n return utils.isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockEndPoint,\n )\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockStartPoint = utils.getBlockStartPoint(block)\n\n return utils.isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockStartPoint,\n )\n }\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getFocusBlock","snapshot","key","context","selection","isKeySegment","focus","path","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","anchor","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getSelectionEndPoint","getSelectionStartPoint","getNextInlineObject","focusTextBlock","selectionEndPoint","selectionEndPointChildKey","endPointChildFound","inlineObject","child","isSpan","getPreviousInlineObject","selectionStartPoint","selectionStartPointChildKey","getSelectedSlice","sliceBlocks","blocks","getSelectionText","reduce","text","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","blockStartPoint","getBlockStartPoint","textDirectlyBefore","split","at","nextInlineObject","blockEndPoint","getBlockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","direction","caretWordEndSelectionPoint","caretWordSelection","isAtTheEndOfBlock","utils","isAtTheStartOfBlock"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAACC;AAA8B,GAAG;AAC7D,WAASC,YAAYC,OAAgD;AACnE,WAAOC,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACNO,MAAME,gBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,aAAaJ,SAASE,QAAQC,UAAUE,MAAMC,KAAK,CAAC,CAAC,IACnDN,SAASE,QAAQC,UAAUE,MAAMC,KAAK,CAAC,EAAEC,OAE3CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMlB,CAAAA,UAAUA,MAAMc,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GAKaI,oBAERZ,CAAa,aAAA;AAChB,QAAMa,SAASvB,aAAaU,SAASE,OAAO,GACtCY,aAAaf,cAAcC,QAAQ;AAE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1,22 +0,0 @@
|
|
|
1
|
-
import type {EditorSnapshot} from '..'
|
|
2
|
-
import * as selectors from '../selectors'
|
|
3
|
-
import type {EventPosition} from './event-position'
|
|
4
|
-
|
|
5
|
-
export function draggingOnDragOrigin({
|
|
6
|
-
snapshot,
|
|
7
|
-
position,
|
|
8
|
-
}: {
|
|
9
|
-
snapshot: EditorSnapshot
|
|
10
|
-
position: EventPosition
|
|
11
|
-
}) {
|
|
12
|
-
const dragOrigin = snapshot.beta.internalDrag?.origin
|
|
13
|
-
return dragOrigin
|
|
14
|
-
? selectors.isOverlappingSelection(position.selection)({
|
|
15
|
-
...snapshot,
|
|
16
|
-
context: {
|
|
17
|
-
...snapshot.context,
|
|
18
|
-
selection: dragOrigin.selection,
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
: false
|
|
22
|
-
}
|