@portabletext/editor 6.6.4 → 7.0.1
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-dts/behavior.types.action.d.ts +683 -512
- package/lib/_chunks-dts/behavior.types.action.d.ts.map +1 -1
- package/lib/_chunks-dts/resolve-containers.d.ts +688 -0
- package/lib/_chunks-dts/resolve-containers.d.ts.map +1 -0
- package/lib/_chunks-es/get-ancestor.js +192 -0
- package/lib/_chunks-es/get-ancestor.js.map +1 -0
- package/lib/_chunks-es/get-first-child.js +130 -0
- package/lib/_chunks-es/get-first-child.js.map +1 -0
- package/lib/_chunks-es/get-path-sub-schema.js +266 -0
- package/lib/_chunks-es/get-path-sub-schema.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1021 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/_chunks-es/use-editor.js +4 -13
- package/lib/_chunks-es/use-editor.js.map +1 -1
- package/lib/_chunks-es/util.is-empty-text-block.js +15 -0
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +347 -198
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.ts +2 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.js +5457 -5611
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +18 -2
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/plugins/index.js +18 -2
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.ts +220 -5
- package/lib/selectors/index.d.ts.map +1 -1
- package/lib/selectors/index.js +62 -71
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.d.ts +235 -0
- package/lib/traversal/index.d.ts.map +1 -0
- package/lib/traversal/index.js +30 -0
- package/lib/traversal/index.js.map +1 -0
- package/lib/utils/index.d.ts +11 -57
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +36 -107
- package/lib/utils/index.js.map +1 -1
- package/package.json +19 -17
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +0 -806
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
- package/lib/_chunks-es/util.slice-text-block.js +0 -60
- package/lib/_chunks-es/util.slice-text-block.js.map +0 -1
|
@@ -1,806 +0,0 @@
|
|
|
1
|
-
import { isTextBlock, isSpan } from "@portabletext/schema";
|
|
2
|
-
import { isTypedObject, isSelectionCollapsed as isSelectionCollapsed$1, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, getSelectionEndPoint as getSelectionEndPoint$1, getSelectionStartPoint as getSelectionStartPoint$1, blockOffsetToSpanSelectionPoint, isKeyedSegment, sliceBlocks, isEqualPaths, spanSelectionPointToBlockOffset, getBlockStartPoint, getBlockEndPoint, isListBlock, isEqualSelectionPoints } from "./util.slice-blocks.js";
|
|
3
|
-
function isTextBlockNode(context, node) {
|
|
4
|
-
return isTypedObject(node) && node._type === context.schema.block.name;
|
|
5
|
-
}
|
|
6
|
-
function isSpanNode(context, node) {
|
|
7
|
-
return isTypedObject(node) && node._type === context.schema.span.name;
|
|
8
|
-
}
|
|
9
|
-
function isBlockPath(path) {
|
|
10
|
-
const firstSegment = path.at(0);
|
|
11
|
-
return path.length === 1 && firstSegment !== void 0 && isRecord(firstSegment) && "_key" in firstSegment && typeof firstSegment._key == "string";
|
|
12
|
-
}
|
|
13
|
-
function isRecord(value) {
|
|
14
|
-
return !!value && (typeof value == "object" || typeof value == "function");
|
|
15
|
-
}
|
|
16
|
-
function isSelectionExpanded$1(selection) {
|
|
17
|
-
return selection ? !isSelectionCollapsed$1(selection) : !1;
|
|
18
|
-
}
|
|
19
|
-
const getFocusBlock = (snapshot) => {
|
|
20
|
-
if (!snapshot.context.selection)
|
|
21
|
-
return;
|
|
22
|
-
const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus), index = key ? snapshot.blockIndexMap.get(key) : void 0, node = index !== void 0 ? snapshot.context.value.at(index) : void 0;
|
|
23
|
-
return node && key ? {
|
|
24
|
-
node,
|
|
25
|
-
path: [{
|
|
26
|
-
_key: key
|
|
27
|
-
}]
|
|
28
|
-
} : void 0;
|
|
29
|
-
}, getFocusTextBlock = (snapshot) => {
|
|
30
|
-
const focusBlock = getFocusBlock(snapshot);
|
|
31
|
-
return focusBlock && isTextBlock(snapshot.context, focusBlock.node) ? {
|
|
32
|
-
node: focusBlock.node,
|
|
33
|
-
path: focusBlock.path
|
|
34
|
-
} : void 0;
|
|
35
|
-
}, getFocusChild = (snapshot) => {
|
|
36
|
-
if (!snapshot.context.selection)
|
|
37
|
-
return;
|
|
38
|
-
const focusBlock = getFocusTextBlock(snapshot);
|
|
39
|
-
if (!focusBlock)
|
|
40
|
-
return;
|
|
41
|
-
const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus), node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
42
|
-
return node && key ? {
|
|
43
|
-
node,
|
|
44
|
-
path: [...focusBlock.path, "children", {
|
|
45
|
-
_key: key
|
|
46
|
-
}]
|
|
47
|
-
} : void 0;
|
|
48
|
-
}, getFocusSpan = (snapshot) => {
|
|
49
|
-
const focusChild = getFocusChild(snapshot);
|
|
50
|
-
return focusChild && isSpan(snapshot.context, focusChild.node) ? {
|
|
51
|
-
node: focusChild.node,
|
|
52
|
-
path: focusChild.path
|
|
53
|
-
} : void 0;
|
|
54
|
-
}, getSelectionEndBlock = (snapshot) => {
|
|
55
|
-
const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
56
|
-
if (endPoint)
|
|
57
|
-
return getFocusBlock({
|
|
58
|
-
...snapshot,
|
|
59
|
-
context: {
|
|
60
|
-
...snapshot.context,
|
|
61
|
-
selection: {
|
|
62
|
-
anchor: endPoint,
|
|
63
|
-
focus: endPoint
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}, getSelectionEndPoint = (snapshot) => {
|
|
68
|
-
if (snapshot.context.selection)
|
|
69
|
-
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
70
|
-
}, getNextSpan = (snapshot) => {
|
|
71
|
-
const selectionEndBlock = getSelectionEndBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
|
|
72
|
-
if (!selectionEndBlock || !selectionEndPoint || !isTextBlock(snapshot.context, selectionEndBlock.node))
|
|
73
|
-
return;
|
|
74
|
-
const selectionEndPointChildKey = getChildKeyFromSelectionPoint(selectionEndPoint);
|
|
75
|
-
let endPointChildFound = !1, nextSpan;
|
|
76
|
-
for (const child of selectionEndBlock.node.children) {
|
|
77
|
-
if (child._key === selectionEndPointChildKey) {
|
|
78
|
-
endPointChildFound = !0;
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
if (isSpan(snapshot.context, child) && endPointChildFound) {
|
|
82
|
-
nextSpan = {
|
|
83
|
-
node: child,
|
|
84
|
-
path: [...selectionEndBlock.path, "children", {
|
|
85
|
-
_key: child._key
|
|
86
|
-
}]
|
|
87
|
-
};
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return nextSpan;
|
|
92
|
-
}, getSelectionStartBlock = (snapshot) => {
|
|
93
|
-
const startPoint = getSelectionStartPoint$1(snapshot.context.selection);
|
|
94
|
-
if (startPoint)
|
|
95
|
-
return getFocusBlock({
|
|
96
|
-
...snapshot,
|
|
97
|
-
context: {
|
|
98
|
-
...snapshot.context,
|
|
99
|
-
selection: {
|
|
100
|
-
anchor: startPoint,
|
|
101
|
-
focus: startPoint
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}, getSelectionStartPoint = (snapshot) => {
|
|
106
|
-
if (snapshot.context.selection)
|
|
107
|
-
return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
|
|
108
|
-
}, getPreviousSpan = (snapshot) => {
|
|
109
|
-
const selectionStartBlock = getSelectionStartBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot);
|
|
110
|
-
if (!selectionStartBlock || !selectionStartPoint || !isTextBlock(snapshot.context, selectionStartBlock.node))
|
|
111
|
-
return;
|
|
112
|
-
const selectionStartPointChildKey = getChildKeyFromSelectionPoint(selectionStartPoint);
|
|
113
|
-
let previousSpan;
|
|
114
|
-
for (const child of selectionStartBlock.node.children) {
|
|
115
|
-
if (child._key === selectionStartPointChildKey)
|
|
116
|
-
break;
|
|
117
|
-
isSpan(snapshot.context, child) && (previousSpan = {
|
|
118
|
-
node: child,
|
|
119
|
-
path: [...selectionStartBlock.path, "children", {
|
|
120
|
-
_key: child._key
|
|
121
|
-
}]
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
return previousSpan;
|
|
125
|
-
};
|
|
126
|
-
function getSelectedChildren(options) {
|
|
127
|
-
const filter = options?.filter;
|
|
128
|
-
return (snapshot) => {
|
|
129
|
-
const startPoint = getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
|
|
130
|
-
if (!startPoint || !endPoint)
|
|
131
|
-
return [];
|
|
132
|
-
const startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint);
|
|
133
|
-
if (!startBlockKey || !endBlockKey)
|
|
134
|
-
return [];
|
|
135
|
-
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
136
|
-
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
137
|
-
return [];
|
|
138
|
-
const selectedChildren = [], minBlockIndex = Math.min(startBlockIndex, endBlockIndex), maxBlockIndex = Math.max(startBlockIndex, endBlockIndex), blocks = snapshot.context.value.slice(minBlockIndex, maxBlockIndex + 1);
|
|
139
|
-
let startChildFound = !1;
|
|
140
|
-
for (const block of blocks) {
|
|
141
|
-
if (!isTextBlock(snapshot.context, block))
|
|
142
|
-
continue;
|
|
143
|
-
const isStartBlock = block._key === startBlockKey, isEndBlock = block._key === endBlockKey, isMiddleBlock = !isStartBlock && !isEndBlock;
|
|
144
|
-
for (const child of block.children) {
|
|
145
|
-
const isStartChild = child._key === startChildKey, isEndChild = child._key === endChildKey, addChild = () => {
|
|
146
|
-
(!filter || filter(child)) && selectedChildren.push({
|
|
147
|
-
node: child,
|
|
148
|
-
path: [{
|
|
149
|
-
_key: block._key
|
|
150
|
-
}, "children", {
|
|
151
|
-
_key: child._key
|
|
152
|
-
}]
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
if (isMiddleBlock) {
|
|
156
|
-
addChild();
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (isStartChild) {
|
|
160
|
-
if (startChildFound = !0, isSpan(snapshot.context, child) ? startPoint.offset < child.text.length && addChild() : addChild(), startChildKey === endChildKey)
|
|
161
|
-
break;
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (isEndChild) {
|
|
165
|
-
isSpan(snapshot.context, child) ? endPoint.offset > 0 && addChild() : addChild();
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
startChildFound && addChild();
|
|
169
|
-
}
|
|
170
|
-
if (isStartBlock && startBlockKey === endBlockKey)
|
|
171
|
-
break;
|
|
172
|
-
isStartBlock && (startChildFound = !0);
|
|
173
|
-
}
|
|
174
|
-
return selectedChildren;
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
const getSelectedSpans = (snapshot) => snapshot.context.selection ? getSelectedChildren({
|
|
178
|
-
filter: (child) => isSpan(snapshot.context, child)
|
|
179
|
-
})(snapshot) : [], getMarkState = (snapshot) => {
|
|
180
|
-
if (!snapshot.context.selection)
|
|
181
|
-
return;
|
|
182
|
-
let selection = snapshot.context.selection;
|
|
183
|
-
if (!getFocusTextBlock(snapshot))
|
|
184
|
-
return;
|
|
185
|
-
if (isBlockPath(selection.anchor.path)) {
|
|
186
|
-
const spanSelectionPoint = blockOffsetToSpanSelectionPoint({
|
|
187
|
-
context: snapshot.context,
|
|
188
|
-
blockOffset: {
|
|
189
|
-
path: selection.anchor.path,
|
|
190
|
-
offset: selection.anchor.offset
|
|
191
|
-
},
|
|
192
|
-
direction: selection.backward ? "backward" : "forward"
|
|
193
|
-
});
|
|
194
|
-
selection = spanSelectionPoint ? {
|
|
195
|
-
...selection,
|
|
196
|
-
anchor: spanSelectionPoint
|
|
197
|
-
} : selection;
|
|
198
|
-
}
|
|
199
|
-
if (isBlockPath(selection.focus.path)) {
|
|
200
|
-
const spanSelectionPoint = blockOffsetToSpanSelectionPoint({
|
|
201
|
-
context: snapshot.context,
|
|
202
|
-
blockOffset: {
|
|
203
|
-
path: selection.focus.path,
|
|
204
|
-
offset: selection.focus.offset
|
|
205
|
-
},
|
|
206
|
-
direction: selection.backward ? "backward" : "forward"
|
|
207
|
-
});
|
|
208
|
-
selection = spanSelectionPoint ? {
|
|
209
|
-
...selection,
|
|
210
|
-
focus: spanSelectionPoint
|
|
211
|
-
} : selection;
|
|
212
|
-
}
|
|
213
|
-
const focusSpan = getFocusSpan({
|
|
214
|
-
...snapshot,
|
|
215
|
-
context: {
|
|
216
|
-
...snapshot.context,
|
|
217
|
-
selection
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
if (!focusSpan)
|
|
221
|
-
return;
|
|
222
|
-
if (isSelectionExpanded$1(selection)) {
|
|
223
|
-
const selectedSpans = getSelectedSpans({
|
|
224
|
-
...snapshot,
|
|
225
|
-
context: {
|
|
226
|
-
...snapshot.context,
|
|
227
|
-
selection
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
let index = 0, marks2 = [];
|
|
231
|
-
for (const span of selectedSpans) {
|
|
232
|
-
if (index === 0)
|
|
233
|
-
marks2 = span.node.marks ?? [];
|
|
234
|
-
else {
|
|
235
|
-
if (span.node.marks?.length === 0) {
|
|
236
|
-
marks2 = [];
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
marks2 = marks2.filter((mark) => (span.node.marks ?? []).some((spanMark) => spanMark === mark));
|
|
240
|
-
}
|
|
241
|
-
index++;
|
|
242
|
-
}
|
|
243
|
-
return {
|
|
244
|
-
state: "unchanged",
|
|
245
|
-
marks: marks2
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
const decorators = snapshot.context.schema.decorators.map((decorator) => decorator.name), marks = focusSpan.node.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = focusSpan.node.text.length === 0, atTheBeginningOfSpan = snapshot.context.selection.anchor.offset === 0, atTheEndOfSpan = snapshot.context.selection.anchor.offset === focusSpan.node.text.length, previousSpan = getPreviousSpan({
|
|
249
|
-
...snapshot,
|
|
250
|
-
context: {
|
|
251
|
-
...snapshot.context,
|
|
252
|
-
selection
|
|
253
|
-
}
|
|
254
|
-
}), nextSpan = getNextSpan({
|
|
255
|
-
...snapshot,
|
|
256
|
-
context: {
|
|
257
|
-
...snapshot.context,
|
|
258
|
-
selection
|
|
259
|
-
}
|
|
260
|
-
}), nextSpanAnnotations = nextSpan?.node?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.node.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.node.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
|
|
261
|
-
if (spanHasAnnotations && !spanIsEmpty) {
|
|
262
|
-
if (atTheBeginningOfSpan) {
|
|
263
|
-
if (previousSpanHasSameMarks)
|
|
264
|
-
return {
|
|
265
|
-
state: "changed",
|
|
266
|
-
previousMarks: marks,
|
|
267
|
-
marks: previousSpan?.node.marks ?? []
|
|
268
|
-
};
|
|
269
|
-
if (previousSpanHasSameAnnotations)
|
|
270
|
-
return {
|
|
271
|
-
state: "changed",
|
|
272
|
-
previousMarks: marks,
|
|
273
|
-
marks: previousSpan?.node.marks ?? []
|
|
274
|
-
};
|
|
275
|
-
if (previousSpanHasSameAnnotation)
|
|
276
|
-
return {
|
|
277
|
-
state: "unchanged",
|
|
278
|
-
marks: focusSpan.node.marks ?? []
|
|
279
|
-
};
|
|
280
|
-
if (!previousSpan)
|
|
281
|
-
return {
|
|
282
|
-
state: "changed",
|
|
283
|
-
previousMarks: marks,
|
|
284
|
-
marks: []
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
if (atTheEndOfSpan) {
|
|
288
|
-
if (!nextSpan)
|
|
289
|
-
return {
|
|
290
|
-
state: "changed",
|
|
291
|
-
previousMarks: marks,
|
|
292
|
-
marks: []
|
|
293
|
-
};
|
|
294
|
-
if (nextSpanAnnotations.length > 0 && !nextSpanSharesSomeAnnotations)
|
|
295
|
-
return {
|
|
296
|
-
state: "changed",
|
|
297
|
-
previousMarks: marks,
|
|
298
|
-
marks: []
|
|
299
|
-
};
|
|
300
|
-
if (nextSpanSharesSomeAnnotations && nextSpanAnnotations.length < spanAnnotations.length || !nextSpanSharesSomeAnnotations)
|
|
301
|
-
return {
|
|
302
|
-
state: "changed",
|
|
303
|
-
previousMarks: marks,
|
|
304
|
-
marks: nextSpan?.node.marks ?? []
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return atTheBeginningOfSpan && !spanIsEmpty && previousSpan ? previousSpanHasAnnotations ? {
|
|
309
|
-
state: "changed",
|
|
310
|
-
marks,
|
|
311
|
-
previousMarks: previousSpan?.node.marks ?? []
|
|
312
|
-
} : {
|
|
313
|
-
state: "changed",
|
|
314
|
-
previousMarks: marks,
|
|
315
|
-
marks: (previousSpan?.node.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
316
|
-
} : {
|
|
317
|
-
state: "unchanged",
|
|
318
|
-
marks
|
|
319
|
-
};
|
|
320
|
-
}, getSelectedBlocks = (snapshot) => {
|
|
321
|
-
if (!snapshot.context.selection)
|
|
322
|
-
return [];
|
|
323
|
-
const selectedBlocks = [], startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startKey = getBlockKeyFromSelectionPoint(startPoint), endKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
324
|
-
if (!startKey || !endKey)
|
|
325
|
-
return selectedBlocks;
|
|
326
|
-
const startBlockIndex = snapshot.blockIndexMap.get(startKey), endBlockIndex = snapshot.blockIndexMap.get(endKey);
|
|
327
|
-
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
328
|
-
return selectedBlocks;
|
|
329
|
-
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
330
|
-
for (const block of slicedValue) {
|
|
331
|
-
if (block._key === startKey) {
|
|
332
|
-
if (selectedBlocks.push({
|
|
333
|
-
node: block,
|
|
334
|
-
path: [{
|
|
335
|
-
_key: block._key
|
|
336
|
-
}]
|
|
337
|
-
}), startKey === endKey)
|
|
338
|
-
break;
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
if (block._key === endKey) {
|
|
342
|
-
selectedBlocks.push({
|
|
343
|
-
node: block,
|
|
344
|
-
path: [{
|
|
345
|
-
_key: block._key
|
|
346
|
-
}]
|
|
347
|
-
});
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
351
|
-
node: block,
|
|
352
|
-
path: [{
|
|
353
|
-
_key: block._key
|
|
354
|
-
}]
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
return selectedBlocks;
|
|
358
|
-
}, getActiveAnnotations = (snapshot) => {
|
|
359
|
-
if (!snapshot.context.selection)
|
|
360
|
-
return [];
|
|
361
|
-
const selectedBlocks = getSelectedBlocks(snapshot), activeAnnotations = (getMarkState(snapshot)?.marks ?? []).filter((mark) => !snapshot.context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
362
|
-
return selectedBlocks.flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => activeAnnotations.includes(markDef._key));
|
|
363
|
-
}, getActiveListItem = (snapshot) => {
|
|
364
|
-
if (!snapshot.context.selection)
|
|
365
|
-
return;
|
|
366
|
-
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => isTextBlockNode(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
367
|
-
if (!firstTextBlock)
|
|
368
|
-
return;
|
|
369
|
-
const firstListItem = firstTextBlock.listItem;
|
|
370
|
-
if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
|
|
371
|
-
return firstListItem;
|
|
372
|
-
}, getActiveStyle = (snapshot) => {
|
|
373
|
-
if (!snapshot.context.selection)
|
|
374
|
-
return;
|
|
375
|
-
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => isTextBlockNode(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
376
|
-
if (!firstTextBlock)
|
|
377
|
-
return;
|
|
378
|
-
const firstStyle = firstTextBlock.style;
|
|
379
|
-
if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
|
|
380
|
-
return firstStyle;
|
|
381
|
-
}, getNextInlineObject = (snapshot) => {
|
|
382
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && isKeyedSegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
383
|
-
if (!focusTextBlock || !selectionEndPointChildKey)
|
|
384
|
-
return;
|
|
385
|
-
let endPointChildFound = !1, inlineObject;
|
|
386
|
-
for (const child of focusTextBlock.node.children) {
|
|
387
|
-
if (child._key === selectionEndPointChildKey) {
|
|
388
|
-
endPointChildFound = !0;
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
if (!isSpanNode(snapshot.context, child) && endPointChildFound) {
|
|
392
|
-
inlineObject = {
|
|
393
|
-
node: child,
|
|
394
|
-
path: [...focusTextBlock.path, "children", {
|
|
395
|
-
_key: child._key
|
|
396
|
-
}]
|
|
397
|
-
};
|
|
398
|
-
break;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
return inlineObject;
|
|
402
|
-
}, getPreviousInlineObject = (snapshot) => {
|
|
403
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && isKeyedSegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
|
|
404
|
-
if (!focusTextBlock || !selectionStartPointChildKey)
|
|
405
|
-
return;
|
|
406
|
-
let inlineObject;
|
|
407
|
-
for (const child of focusTextBlock.node.children) {
|
|
408
|
-
if (child._key === selectionStartPointChildKey)
|
|
409
|
-
break;
|
|
410
|
-
isSpanNode(snapshot.context, child) || (inlineObject = {
|
|
411
|
-
node: child,
|
|
412
|
-
path: [...focusTextBlock.path, "children", {
|
|
413
|
-
_key: child._key
|
|
414
|
-
}]
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
return inlineObject;
|
|
418
|
-
}, getSelectedValue = (snapshot) => {
|
|
419
|
-
const selection = snapshot.context.selection;
|
|
420
|
-
if (!selection)
|
|
421
|
-
return [];
|
|
422
|
-
const startPoint = getSelectionStartPoint$1(selection), endPoint = getSelectionEndPoint$1(selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
423
|
-
if (!startBlockKey || !endBlockKey)
|
|
424
|
-
return [];
|
|
425
|
-
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
426
|
-
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
427
|
-
return [];
|
|
428
|
-
const startBlock = snapshot.context.value.at(startBlockIndex), slicedStartBlock = startBlock ? sliceBlocks({
|
|
429
|
-
context: snapshot.context,
|
|
430
|
-
blocks: [startBlock]
|
|
431
|
-
}).at(0) : void 0;
|
|
432
|
-
if (startBlockIndex === endBlockIndex)
|
|
433
|
-
return slicedStartBlock ? [slicedStartBlock] : [];
|
|
434
|
-
const endBlock = snapshot.context.value.at(endBlockIndex), slicedEndBlock = endBlock ? sliceBlocks({
|
|
435
|
-
context: snapshot.context,
|
|
436
|
-
blocks: [endBlock]
|
|
437
|
-
}).at(0) : void 0, middleBlocks = snapshot.context.value.slice(startBlockIndex + 1, endBlockIndex);
|
|
438
|
-
return [...slicedStartBlock ? [slicedStartBlock] : [], ...middleBlocks, ...slicedEndBlock ? [slicedEndBlock] : []];
|
|
439
|
-
}, getSelectionText = (snapshot) => getSelectedValue(snapshot).reduce((text, block) => isTextBlock(snapshot.context, block) ? text + block.children.reduce((text2, child) => isSpan(snapshot.context, child) ? text2 + child.text : text2, "") : text, ""), isSelectionCollapsed = (snapshot) => snapshot.context.selection ? isEqualPaths(snapshot.context.selection.anchor.path, snapshot.context.selection.focus.path) && snapshot.context.selection.anchor.offset === snapshot.context.selection.focus.offset : !1, isSelectionExpanded = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), getCaretWordSelection = (snapshot) => {
|
|
440
|
-
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
441
|
-
return null;
|
|
442
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? spanSelectionPointToBlockOffset({
|
|
443
|
-
context: snapshot.context,
|
|
444
|
-
selectionPoint: selectionStartPoint
|
|
445
|
-
}) : void 0;
|
|
446
|
-
if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset)
|
|
447
|
-
return null;
|
|
448
|
-
const previousInlineObject = getPreviousInlineObject(snapshot), blockStartPoint = getBlockStartPoint({
|
|
449
|
-
context: snapshot.context,
|
|
450
|
-
block: focusTextBlock
|
|
451
|
-
}), textDirectlyBefore = getSelectionText({
|
|
452
|
-
...snapshot,
|
|
453
|
-
context: {
|
|
454
|
-
...snapshot.context,
|
|
455
|
-
selection: {
|
|
456
|
-
anchor: previousInlineObject ? {
|
|
457
|
-
path: previousInlineObject.path,
|
|
458
|
-
offset: 0
|
|
459
|
-
} : blockStartPoint,
|
|
460
|
-
focus: selectionStartPoint
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = getBlockEndPoint({
|
|
464
|
-
context: snapshot.context,
|
|
465
|
-
block: focusTextBlock
|
|
466
|
-
}), textDirectlyAfter = getSelectionText({
|
|
467
|
-
...snapshot,
|
|
468
|
-
context: {
|
|
469
|
-
...snapshot.context,
|
|
470
|
-
selection: {
|
|
471
|
-
anchor: selectionStartPoint,
|
|
472
|
-
focus: nextInlineObject ? {
|
|
473
|
-
path: nextInlineObject.path,
|
|
474
|
-
offset: 0
|
|
475
|
-
} : blockEndPoint
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}).split(/\s+/).at(0);
|
|
479
|
-
if ((textDirectlyBefore === void 0 || textDirectlyBefore === "") && (textDirectlyAfter === void 0 || textDirectlyAfter === ""))
|
|
480
|
-
return null;
|
|
481
|
-
const caretWordStartOffset = textDirectlyBefore ? {
|
|
482
|
-
...selectionStartOffset,
|
|
483
|
-
offset: selectionStartOffset.offset - textDirectlyBefore.length
|
|
484
|
-
} : selectionStartOffset, caretWordEndOffset = textDirectlyAfter ? {
|
|
485
|
-
...selectionStartOffset,
|
|
486
|
-
offset: selectionStartOffset.offset + textDirectlyAfter.length
|
|
487
|
-
} : selectionStartOffset, caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({
|
|
488
|
-
context: snapshot.context,
|
|
489
|
-
blockOffset: caretWordStartOffset,
|
|
490
|
-
direction: "backward"
|
|
491
|
-
}), caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({
|
|
492
|
-
context: snapshot.context,
|
|
493
|
-
blockOffset: caretWordEndOffset,
|
|
494
|
-
direction: "forward"
|
|
495
|
-
});
|
|
496
|
-
if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint)
|
|
497
|
-
return null;
|
|
498
|
-
const caretWordSelection = {
|
|
499
|
-
anchor: caretWordStartSelectionPoint,
|
|
500
|
-
focus: caretWordEndSelectionPoint
|
|
501
|
-
};
|
|
502
|
-
return isSelectionExpanded({
|
|
503
|
-
context: {
|
|
504
|
-
...snapshot.context,
|
|
505
|
-
selection: caretWordSelection
|
|
506
|
-
}
|
|
507
|
-
}) ? caretWordSelection : null;
|
|
508
|
-
}, getFocusBlockObject = (snapshot) => {
|
|
509
|
-
const focusBlock = getFocusBlock(snapshot);
|
|
510
|
-
return focusBlock && !isTextBlockNode(snapshot.context, focusBlock.node) ? {
|
|
511
|
-
node: focusBlock.node,
|
|
512
|
-
path: focusBlock.path
|
|
513
|
-
} : void 0;
|
|
514
|
-
}, getFocusInlineObject = (snapshot) => {
|
|
515
|
-
const focusChild = getFocusChild(snapshot);
|
|
516
|
-
return focusChild && !isSpanNode(snapshot.context, focusChild.node) ? {
|
|
517
|
-
node: focusChild.node,
|
|
518
|
-
path: focusChild.path
|
|
519
|
-
} : void 0;
|
|
520
|
-
}, getFocusListBlock = (snapshot) => {
|
|
521
|
-
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
522
|
-
return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node) ? {
|
|
523
|
-
node: focusTextBlock.node,
|
|
524
|
-
path: focusTextBlock.path
|
|
525
|
-
} : void 0;
|
|
526
|
-
}, getLastBlock = (snapshot) => {
|
|
527
|
-
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
528
|
-
return node ? {
|
|
529
|
-
node,
|
|
530
|
-
path: [{
|
|
531
|
-
_key: node._key
|
|
532
|
-
}]
|
|
533
|
-
} : void 0;
|
|
534
|
-
}, getNextBlock = (snapshot) => {
|
|
535
|
-
const selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
536
|
-
if (!selectionEndBlock)
|
|
537
|
-
return;
|
|
538
|
-
const index = snapshot.blockIndexMap.get(selectionEndBlock.node._key);
|
|
539
|
-
if (index === void 0 || index === snapshot.context.value.length - 1)
|
|
540
|
-
return;
|
|
541
|
-
const nextBlock = snapshot.context.value.at(index + 1);
|
|
542
|
-
return nextBlock ? {
|
|
543
|
-
node: nextBlock,
|
|
544
|
-
path: [{
|
|
545
|
-
_key: nextBlock._key
|
|
546
|
-
}]
|
|
547
|
-
} : void 0;
|
|
548
|
-
}, getPreviousBlock = (snapshot) => {
|
|
549
|
-
const selectionStartBlock = getSelectionStartBlock(snapshot);
|
|
550
|
-
if (!selectionStartBlock)
|
|
551
|
-
return;
|
|
552
|
-
const index = snapshot.blockIndexMap.get(selectionStartBlock.node._key);
|
|
553
|
-
if (index === void 0 || index === 0)
|
|
554
|
-
return;
|
|
555
|
-
const previousBlock = snapshot.context.value.at(index - 1);
|
|
556
|
-
return previousBlock ? {
|
|
557
|
-
node: previousBlock,
|
|
558
|
-
path: [{
|
|
559
|
-
_key: previousBlock._key
|
|
560
|
-
}]
|
|
561
|
-
} : void 0;
|
|
562
|
-
}, getSelectedTextBlocks = (snapshot) => {
|
|
563
|
-
if (!snapshot.context.selection)
|
|
564
|
-
return [];
|
|
565
|
-
const selectedTextBlocks = [], startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
566
|
-
if (!startBlockKey || !endBlockKey)
|
|
567
|
-
return selectedTextBlocks;
|
|
568
|
-
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
569
|
-
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
570
|
-
return selectedTextBlocks;
|
|
571
|
-
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
572
|
-
for (const block of slicedValue) {
|
|
573
|
-
if (block._key === startBlockKey) {
|
|
574
|
-
if (isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
|
|
575
|
-
node: block,
|
|
576
|
-
path: [{
|
|
577
|
-
_key: block._key
|
|
578
|
-
}]
|
|
579
|
-
}), startBlockKey === endBlockKey)
|
|
580
|
-
break;
|
|
581
|
-
continue;
|
|
582
|
-
}
|
|
583
|
-
if (block._key === endBlockKey) {
|
|
584
|
-
isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
|
|
585
|
-
node: block,
|
|
586
|
-
path: [{
|
|
587
|
-
_key: block._key
|
|
588
|
-
}]
|
|
589
|
-
});
|
|
590
|
-
break;
|
|
591
|
-
}
|
|
592
|
-
selectedTextBlocks.length > 0 && isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
|
|
593
|
-
node: block,
|
|
594
|
-
path: [{
|
|
595
|
-
_key: block._key
|
|
596
|
-
}]
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
return selectedTextBlocks;
|
|
600
|
-
}, getSelectionEndChild = (snapshot) => {
|
|
601
|
-
const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
602
|
-
if (endPoint)
|
|
603
|
-
return getFocusChild({
|
|
604
|
-
...snapshot,
|
|
605
|
-
context: {
|
|
606
|
-
...snapshot.context,
|
|
607
|
-
selection: {
|
|
608
|
-
anchor: endPoint,
|
|
609
|
-
focus: endPoint
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
}, getSelectionStartChild = (snapshot) => {
|
|
614
|
-
const startPoint = getSelectionStartPoint$1(snapshot.context.selection);
|
|
615
|
-
if (startPoint)
|
|
616
|
-
return getFocusChild({
|
|
617
|
-
...snapshot,
|
|
618
|
-
context: {
|
|
619
|
-
...snapshot.context,
|
|
620
|
-
selection: {
|
|
621
|
-
anchor: startPoint,
|
|
622
|
-
focus: startPoint
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
};
|
|
627
|
-
function getActiveAnnotationsMarks(snapshot) {
|
|
628
|
-
const schema = snapshot.context.schema;
|
|
629
|
-
return (getMarkState(snapshot)?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
630
|
-
}
|
|
631
|
-
function isActiveAnnotation(annotation, options) {
|
|
632
|
-
return (snapshot) => {
|
|
633
|
-
if ((options?.mode ?? "full") === "partial")
|
|
634
|
-
return getSelectedValue(snapshot).flatMap((block) => isTextBlock(snapshot.context, block) ? block.markDefs ?? [] : []).some((markDef) => markDef._type === annotation);
|
|
635
|
-
const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
|
|
636
|
-
return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
function getActiveDecorators(snapshot) {
|
|
640
|
-
const schema = snapshot.context.schema, decoratorState = snapshot.decoratorState, markState = getMarkState(snapshot), decorators = schema.decorators.map((decorator) => decorator.name);
|
|
641
|
-
let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
642
|
-
for (const decorator in decoratorState)
|
|
643
|
-
decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
|
|
644
|
-
return activeDecorators;
|
|
645
|
-
}
|
|
646
|
-
function isActiveDecorator(decorator) {
|
|
647
|
-
return (snapshot) => {
|
|
648
|
-
if (isSelectionExpanded(snapshot)) {
|
|
649
|
-
const selectedSpans = getSelectedSpans(snapshot);
|
|
650
|
-
return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
|
|
651
|
-
}
|
|
652
|
-
return getActiveDecorators(snapshot).includes(decorator);
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
function isActiveListItem(listItem) {
|
|
656
|
-
return (snapshot) => getActiveListItem(snapshot) === listItem;
|
|
657
|
-
}
|
|
658
|
-
function isActiveStyle(style) {
|
|
659
|
-
return (snapshot) => getActiveStyle(snapshot) === style;
|
|
660
|
-
}
|
|
661
|
-
function isAtTheEndOfBlock(block) {
|
|
662
|
-
return (snapshot) => {
|
|
663
|
-
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
664
|
-
return !1;
|
|
665
|
-
const blockEndPoint = getBlockEndPoint({
|
|
666
|
-
context: snapshot.context,
|
|
667
|
-
block
|
|
668
|
-
});
|
|
669
|
-
return isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
|
|
670
|
-
};
|
|
671
|
-
}
|
|
672
|
-
function isAtTheStartOfBlock(block) {
|
|
673
|
-
return (snapshot) => {
|
|
674
|
-
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
675
|
-
return !1;
|
|
676
|
-
const blockStartPoint = getBlockStartPoint({
|
|
677
|
-
context: snapshot.context,
|
|
678
|
-
block
|
|
679
|
-
});
|
|
680
|
-
return isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
function comparePoints(snapshot, pointA, pointB) {
|
|
684
|
-
const blockKeyA = getBlockKeyFromSelectionPoint(pointA), blockKeyB = getBlockKeyFromSelectionPoint(pointB);
|
|
685
|
-
if (!blockKeyA)
|
|
686
|
-
throw new Error(`Cannot compare points: no block key found for ${pointA}`);
|
|
687
|
-
if (!blockKeyB)
|
|
688
|
-
throw new Error(`Cannot compare points: no block key found for ${pointB}`);
|
|
689
|
-
const blockIndexA = snapshot.blockIndexMap.get(blockKeyA), blockIndexB = snapshot.blockIndexMap.get(blockKeyB);
|
|
690
|
-
if (blockIndexA === void 0)
|
|
691
|
-
throw new Error(`Cannot compare points: block "${blockKeyA}" not found`);
|
|
692
|
-
if (blockIndexB === void 0)
|
|
693
|
-
throw new Error(`Cannot compare points: block "${blockKeyB}" not found`);
|
|
694
|
-
if (blockIndexA < blockIndexB)
|
|
695
|
-
return -1;
|
|
696
|
-
if (blockIndexA > blockIndexB)
|
|
697
|
-
return 1;
|
|
698
|
-
const block = snapshot.context.value.at(blockIndexA);
|
|
699
|
-
if (!block || !isTextBlock(snapshot.context, block))
|
|
700
|
-
return 0;
|
|
701
|
-
const childKeyA = getChildKeyFromSelectionPoint(pointA), childKeyB = getChildKeyFromSelectionPoint(pointB);
|
|
702
|
-
if (!childKeyA)
|
|
703
|
-
throw new Error(`Cannot compare points: no child key found for ${pointA}`);
|
|
704
|
-
if (!childKeyB)
|
|
705
|
-
throw new Error(`Cannot compare points: no child key found for ${pointB}`);
|
|
706
|
-
let childIndexA, childIndexB;
|
|
707
|
-
for (let i = 0; i < block.children.length; i++) {
|
|
708
|
-
const child = block.children.at(i);
|
|
709
|
-
if (child) {
|
|
710
|
-
if (child._key === childKeyA && child._key === childKeyB)
|
|
711
|
-
return pointA.offset < pointB.offset ? -1 : pointA.offset > pointB.offset ? 1 : 0;
|
|
712
|
-
if (child._key === childKeyA && (childIndexA = i), child._key === childKeyB && (childIndexB = i), childIndexA !== void 0 && childIndexB !== void 0)
|
|
713
|
-
break;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
if (childIndexA === void 0)
|
|
717
|
-
throw new Error(`Cannot compare points: child "${childKeyA}" not found`);
|
|
718
|
-
if (childIndexB === void 0)
|
|
719
|
-
throw new Error(`Cannot compare points: child "${childKeyB}" not found`);
|
|
720
|
-
return childIndexA < childIndexB ? -1 : childIndexA > childIndexB ? 1 : 0;
|
|
721
|
-
}
|
|
722
|
-
function isOverlappingSelection(selection) {
|
|
723
|
-
return (snapshot) => {
|
|
724
|
-
const editorSelection = snapshot.context.selection;
|
|
725
|
-
if (!selection || !editorSelection)
|
|
726
|
-
return !1;
|
|
727
|
-
const selectionStart = getSelectionStartPoint$1(selection), selectionEnd = getSelectionEndPoint$1(selection), editorSelectionStart = getSelectionStartPoint$1(editorSelection), editorSelectionEnd = getSelectionEndPoint$1(editorSelection), selectionStartBlockKey = getBlockKeyFromSelectionPoint(selectionStart), selectionEndBlockKey = getBlockKeyFromSelectionPoint(selectionEnd), editorSelectionStartBlockKey = getBlockKeyFromSelectionPoint(editorSelectionStart), editorSelectionEndBlockKey = getBlockKeyFromSelectionPoint(editorSelectionEnd);
|
|
728
|
-
if (!selectionStartBlockKey || !selectionEndBlockKey || !editorSelectionStartBlockKey || !editorSelectionEndBlockKey)
|
|
729
|
-
return !1;
|
|
730
|
-
const selectionStartBlockIndex = snapshot.blockIndexMap.get(selectionStartBlockKey), selectionEndBlockIndex = snapshot.blockIndexMap.get(selectionEndBlockKey), editorSelectionStartBlockIndex = snapshot.blockIndexMap.get(editorSelectionStartBlockKey), editorSelectionEndBlockIndex = snapshot.blockIndexMap.get(editorSelectionEndBlockKey);
|
|
731
|
-
if (selectionStartBlockIndex === void 0 || selectionEndBlockIndex === void 0 || editorSelectionStartBlockIndex === void 0 || editorSelectionEndBlockIndex === void 0)
|
|
732
|
-
return !1;
|
|
733
|
-
const [selectionMinBlockIndex, selectionMaxBlockIndex] = selectionStartBlockIndex <= selectionEndBlockIndex ? [selectionStartBlockIndex, selectionEndBlockIndex] : [selectionEndBlockIndex, selectionStartBlockIndex], [editorSelectionMinBlockIndex, editorSelectionMaxBlockIndex] = editorSelectionStartBlockIndex <= editorSelectionEndBlockIndex ? [editorSelectionStartBlockIndex, editorSelectionEndBlockIndex] : [editorSelectionEndBlockIndex, editorSelectionStartBlockIndex];
|
|
734
|
-
return selectionMaxBlockIndex < editorSelectionMinBlockIndex || selectionMinBlockIndex > editorSelectionMaxBlockIndex ? !1 : hasPointLevelOverlap(snapshot, selectionStart, selectionEnd, editorSelectionStart, editorSelectionEnd);
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
function hasPointLevelOverlap(snapshot, selectionStart, selectionEnd, editorSelectionStart, editorSelectionEnd) {
|
|
738
|
-
if (isEqualSelectionPoints(selectionStart, editorSelectionStart) && isEqualSelectionPoints(selectionEnd, editorSelectionEnd))
|
|
739
|
-
return !0;
|
|
740
|
-
const selectionStartVsEditorSelectionStart = comparePoints(snapshot, selectionStart, editorSelectionStart), selectionStartVsEditorSelectionEnd = comparePoints(snapshot, selectionStart, editorSelectionEnd), selectionEndVsEditorSelectionStart = comparePoints(snapshot, selectionEnd, editorSelectionStart), selectionEndVsEditorSelectionEnd = comparePoints(snapshot, selectionEnd, editorSelectionEnd), editorSelectionStartVsSelectionStart = comparePoints(snapshot, editorSelectionStart, selectionStart), editorSelectionEndVsSelectionEnd = comparePoints(snapshot, editorSelectionEnd, selectionEnd), selectionStartBeforeEditorSelectionStart = selectionStartVsEditorSelectionStart === -1, selectionStartAfterEditorSelectionEnd = selectionStartVsEditorSelectionEnd === 1, selectionEndBeforeEditorSelectionStart = selectionEndVsEditorSelectionStart === -1, selectionEndAfterEditorSelectionEnd = selectionEndVsEditorSelectionEnd === 1, editorSelectionStartBeforeSelectionStart = editorSelectionStartVsSelectionStart === -1, editorSelectionStartAfterSelectionStart = editorSelectionStartVsSelectionStart === 1, editorSelectionEndBeforeSelectionEnd = editorSelectionEndVsSelectionEnd === -1, editorSelectionEndAfterSelectionEnd = editorSelectionEndVsSelectionEnd === 1, selectionStartEqualEditorSelectionEnd = isEqualSelectionPoints(selectionStart, editorSelectionEnd), selectionEndEqualEditorSelectionStart = isEqualSelectionPoints(selectionEnd, editorSelectionStart);
|
|
741
|
-
return !selectionEndEqualEditorSelectionStart && !selectionStartEqualEditorSelectionEnd && !editorSelectionStartBeforeSelectionStart && !editorSelectionStartAfterSelectionStart && !editorSelectionEndBeforeSelectionEnd && !editorSelectionEndAfterSelectionEnd || selectionEndBeforeEditorSelectionStart && !selectionEndEqualEditorSelectionStart || selectionStartAfterEditorSelectionEnd && !selectionStartEqualEditorSelectionEnd ? !1 : !editorSelectionStartBeforeSelectionStart && editorSelectionStartAfterSelectionStart && !editorSelectionEndBeforeSelectionEnd && editorSelectionEndAfterSelectionEnd ? !selectionEndEqualEditorSelectionStart : editorSelectionStartBeforeSelectionStart && !editorSelectionStartAfterSelectionStart && editorSelectionEndBeforeSelectionEnd && !editorSelectionEndAfterSelectionEnd ? !selectionStartEqualEditorSelectionEnd : !selectionStartAfterEditorSelectionEnd || !selectionStartBeforeEditorSelectionStart || !selectionEndAfterEditorSelectionEnd || !selectionEndBeforeEditorSelectionStart;
|
|
742
|
-
}
|
|
743
|
-
const isSelectingEntireBlocks = (snapshot) => {
|
|
744
|
-
if (!snapshot.context.selection)
|
|
745
|
-
return !1;
|
|
746
|
-
const startPoint = snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor, endPoint = snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus, startBlock = getSelectionStartBlock(snapshot), endBlock = getSelectionEndBlock(snapshot);
|
|
747
|
-
if (!startBlock || !endBlock)
|
|
748
|
-
return !1;
|
|
749
|
-
const startBlockStartPoint = getBlockStartPoint({
|
|
750
|
-
context: snapshot.context,
|
|
751
|
-
block: startBlock
|
|
752
|
-
}), endBlockEndPoint = getBlockEndPoint({
|
|
753
|
-
context: snapshot.context,
|
|
754
|
-
block: endBlock
|
|
755
|
-
});
|
|
756
|
-
return isEqualSelectionPoints(startBlockStartPoint, startPoint) && isEqualSelectionPoints(endBlockEndPoint, endPoint);
|
|
757
|
-
};
|
|
758
|
-
export {
|
|
759
|
-
comparePoints,
|
|
760
|
-
getActiveAnnotations,
|
|
761
|
-
getActiveAnnotationsMarks,
|
|
762
|
-
getActiveDecorators,
|
|
763
|
-
getActiveListItem,
|
|
764
|
-
getActiveStyle,
|
|
765
|
-
getCaretWordSelection,
|
|
766
|
-
getFocusBlock,
|
|
767
|
-
getFocusBlockObject,
|
|
768
|
-
getFocusChild,
|
|
769
|
-
getFocusInlineObject,
|
|
770
|
-
getFocusListBlock,
|
|
771
|
-
getFocusSpan,
|
|
772
|
-
getFocusTextBlock,
|
|
773
|
-
getLastBlock,
|
|
774
|
-
getMarkState,
|
|
775
|
-
getNextBlock,
|
|
776
|
-
getNextInlineObject,
|
|
777
|
-
getNextSpan,
|
|
778
|
-
getPreviousBlock,
|
|
779
|
-
getPreviousInlineObject,
|
|
780
|
-
getPreviousSpan,
|
|
781
|
-
getSelectedBlocks,
|
|
782
|
-
getSelectedChildren,
|
|
783
|
-
getSelectedSpans,
|
|
784
|
-
getSelectedTextBlocks,
|
|
785
|
-
getSelectedValue,
|
|
786
|
-
getSelectionEndBlock,
|
|
787
|
-
getSelectionEndChild,
|
|
788
|
-
getSelectionEndPoint,
|
|
789
|
-
getSelectionStartBlock,
|
|
790
|
-
getSelectionStartChild,
|
|
791
|
-
getSelectionStartPoint,
|
|
792
|
-
getSelectionText,
|
|
793
|
-
isActiveAnnotation,
|
|
794
|
-
isActiveDecorator,
|
|
795
|
-
isActiveListItem,
|
|
796
|
-
isActiveStyle,
|
|
797
|
-
isAtTheEndOfBlock,
|
|
798
|
-
isAtTheStartOfBlock,
|
|
799
|
-
isOverlappingSelection,
|
|
800
|
-
isSelectingEntireBlocks,
|
|
801
|
-
isSelectionCollapsed,
|
|
802
|
-
isSelectionExpanded,
|
|
803
|
-
isSpanNode,
|
|
804
|
-
isTextBlockNode
|
|
805
|
-
};
|
|
806
|
-
//# sourceMappingURL=selector.is-selecting-entire-blocks.js.map
|