@portabletext/editor 4.1.4 → 4.2.0

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.
@@ -1804,6 +1804,7 @@ type AbstractBehaviorEvent = {
1804
1804
  blocks: Array<BlockWithOptionalKey>;
1805
1805
  placement: InsertPlacement;
1806
1806
  select?: 'start' | 'end' | 'none';
1807
+ at?: NonNullable<EditorSelection>;
1807
1808
  } | {
1808
1809
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>;
1809
1810
  } | {
@@ -1,5 +1,15 @@
1
1
  import { isTextBlock, isSpan } from "@portabletext/schema";
2
- import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, isEqualPaths, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, isEqualSelectionPoints, getBlockStartPoint, getBlockEndPoint, sliceBlocks, isSelectionCollapsed as isSelectionCollapsed$1, blockOffsetToSpanSelectionPoint, isKeyedSegment, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
2
+ import { 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 isBlockPath(path) {
4
+ const firstSegment = path.at(0);
5
+ return path.length === 1 && firstSegment !== void 0 && isRecord(firstSegment) && "_key" in firstSegment && typeof firstSegment._key == "string";
6
+ }
7
+ function isRecord(value) {
8
+ return !!value && (typeof value == "object" || typeof value == "function");
9
+ }
10
+ function isSelectionExpanded$1(selection) {
11
+ return selection ? !isSelectionCollapsed$1(selection) : !1;
12
+ }
3
13
  const getFocusBlock = (snapshot) => {
4
14
  if (!snapshot.context.selection)
5
15
  return;
@@ -35,12 +45,77 @@ const getFocusBlock = (snapshot) => {
35
45
  node: focusChild.node,
36
46
  path: focusChild.path
37
47
  } : void 0;
48
+ }, getSelectionEndBlock = (snapshot) => {
49
+ const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
50
+ if (endPoint)
51
+ return getFocusBlock({
52
+ ...snapshot,
53
+ context: {
54
+ ...snapshot.context,
55
+ selection: {
56
+ anchor: endPoint,
57
+ focus: endPoint
58
+ }
59
+ }
60
+ });
38
61
  }, getSelectionEndPoint = (snapshot) => {
39
62
  if (snapshot.context.selection)
40
63
  return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
64
+ }, getNextSpan = (snapshot) => {
65
+ const selectionEndBlock = getSelectionEndBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
66
+ if (!selectionEndBlock || !selectionEndPoint || !isTextBlock(snapshot.context, selectionEndBlock.node))
67
+ return;
68
+ const selectionEndPointChildKey = getChildKeyFromSelectionPoint(selectionEndPoint);
69
+ let endPointChildFound = !1, nextSpan;
70
+ for (const child of selectionEndBlock.node.children) {
71
+ if (child._key === selectionEndPointChildKey) {
72
+ endPointChildFound = !0;
73
+ continue;
74
+ }
75
+ if (isSpan(snapshot.context, child) && endPointChildFound) {
76
+ nextSpan = {
77
+ node: child,
78
+ path: [...selectionEndBlock.path, "children", {
79
+ _key: child._key
80
+ }]
81
+ };
82
+ break;
83
+ }
84
+ }
85
+ return nextSpan;
86
+ }, getSelectionStartBlock = (snapshot) => {
87
+ const startPoint = getSelectionStartPoint$1(snapshot.context.selection);
88
+ if (startPoint)
89
+ return getFocusBlock({
90
+ ...snapshot,
91
+ context: {
92
+ ...snapshot.context,
93
+ selection: {
94
+ anchor: startPoint,
95
+ focus: startPoint
96
+ }
97
+ }
98
+ });
41
99
  }, getSelectionStartPoint = (snapshot) => {
42
100
  if (snapshot.context.selection)
43
101
  return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
102
+ }, getPreviousSpan = (snapshot) => {
103
+ const selectionStartBlock = getSelectionStartBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot);
104
+ if (!selectionStartBlock || !selectionStartPoint || !isTextBlock(snapshot.context, selectionStartBlock.node))
105
+ return;
106
+ const selectionStartPointChildKey = getChildKeyFromSelectionPoint(selectionStartPoint);
107
+ let previousSpan;
108
+ for (const child of selectionStartBlock.node.children) {
109
+ if (child._key === selectionStartPointChildKey)
110
+ break;
111
+ isSpan(snapshot.context, child) && (previousSpan = {
112
+ node: child,
113
+ path: [...selectionStartBlock.path, "children", {
114
+ _key: child._key
115
+ }]
116
+ });
117
+ }
118
+ return previousSpan;
44
119
  };
45
120
  function getSelectedChildren(options) {
46
121
  const filter = options?.filter;
@@ -93,223 +168,7 @@ function getSelectedChildren(options) {
93
168
  return selectedChildren;
94
169
  };
95
170
  }
96
- const 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, getFocusInlineObject = (snapshot) => {
97
- const focusChild = getFocusChild(snapshot);
98
- return focusChild && !isSpan(snapshot.context, focusChild.node) ? {
99
- node: focusChild.node,
100
- path: focusChild.path
101
- } : void 0;
102
- }, getSelectedBlocks = (snapshot) => {
103
- if (!snapshot.context.selection)
104
- return [];
105
- const selectedBlocks = [], startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startKey = getBlockKeyFromSelectionPoint(startPoint), endKey = getBlockKeyFromSelectionPoint(endPoint);
106
- if (!startKey || !endKey)
107
- return selectedBlocks;
108
- const startBlockIndex = snapshot.blockIndexMap.get(startKey), endBlockIndex = snapshot.blockIndexMap.get(endKey);
109
- if (startBlockIndex === void 0 || endBlockIndex === void 0)
110
- return selectedBlocks;
111
- const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
112
- for (const block of slicedValue) {
113
- if (block._key === startKey) {
114
- if (selectedBlocks.push({
115
- node: block,
116
- path: [{
117
- _key: block._key
118
- }]
119
- }), startKey === endKey)
120
- break;
121
- continue;
122
- }
123
- if (block._key === endKey) {
124
- selectedBlocks.push({
125
- node: block,
126
- path: [{
127
- _key: block._key
128
- }]
129
- });
130
- break;
131
- }
132
- selectedBlocks.length > 0 && selectedBlocks.push({
133
- node: block,
134
- path: [{
135
- _key: block._key
136
- }]
137
- });
138
- }
139
- return selectedBlocks;
140
- }, getSelectionEndBlock = (snapshot) => {
141
- const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
142
- if (endPoint)
143
- return getFocusBlock({
144
- ...snapshot,
145
- context: {
146
- ...snapshot.context,
147
- selection: {
148
- anchor: endPoint,
149
- focus: endPoint
150
- }
151
- }
152
- });
153
- }, getSelectionStartBlock = (snapshot) => {
154
- const startPoint = getSelectionStartPoint$1(snapshot.context.selection);
155
- if (startPoint)
156
- return getFocusBlock({
157
- ...snapshot,
158
- context: {
159
- ...snapshot.context,
160
- selection: {
161
- anchor: startPoint,
162
- focus: startPoint
163
- }
164
- }
165
- });
166
- };
167
- function comparePoints(snapshot, pointA, pointB) {
168
- const blockKeyA = getBlockKeyFromSelectionPoint(pointA), blockKeyB = getBlockKeyFromSelectionPoint(pointB);
169
- if (!blockKeyA)
170
- throw new Error(`Cannot compare points: no block key found for ${pointA}`);
171
- if (!blockKeyB)
172
- throw new Error(`Cannot compare points: no block key found for ${pointB}`);
173
- const blockIndexA = snapshot.blockIndexMap.get(blockKeyA), blockIndexB = snapshot.blockIndexMap.get(blockKeyB);
174
- if (blockIndexA === void 0)
175
- throw new Error(`Cannot compare points: block "${blockKeyA}" not found`);
176
- if (blockIndexB === void 0)
177
- throw new Error(`Cannot compare points: block "${blockKeyB}" not found`);
178
- if (blockIndexA < blockIndexB)
179
- return -1;
180
- if (blockIndexA > blockIndexB)
181
- return 1;
182
- const block = snapshot.context.value.at(blockIndexA);
183
- if (!block || !isTextBlock(snapshot.context, block))
184
- return 0;
185
- const childKeyA = getChildKeyFromSelectionPoint(pointA), childKeyB = getChildKeyFromSelectionPoint(pointB);
186
- if (!childKeyA)
187
- throw new Error(`Cannot compare points: no child key found for ${pointA}`);
188
- if (!childKeyB)
189
- throw new Error(`Cannot compare points: no child key found for ${pointB}`);
190
- let childIndexA, childIndexB;
191
- for (let i = 0; i < block.children.length; i++) {
192
- const child = block.children.at(i);
193
- if (child) {
194
- if (child._key === childKeyA && child._key === childKeyB)
195
- return pointA.offset < pointB.offset ? -1 : pointA.offset > pointB.offset ? 1 : 0;
196
- if (child._key === childKeyA && (childIndexA = i), child._key === childKeyB && (childIndexB = i), childIndexA !== void 0 && childIndexB !== void 0)
197
- break;
198
- }
199
- }
200
- if (childIndexA === void 0)
201
- throw new Error(`Cannot compare points: child "${childKeyA}" not found`);
202
- if (childIndexB === void 0)
203
- throw new Error(`Cannot compare points: child "${childKeyB}" not found`);
204
- return childIndexA < childIndexB ? -1 : childIndexA > childIndexB ? 1 : 0;
205
- }
206
- function isOverlappingSelection(selection) {
207
- return (snapshot) => {
208
- const editorSelection = snapshot.context.selection;
209
- if (!selection || !editorSelection)
210
- return !1;
211
- 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);
212
- if (!selectionStartBlockKey || !selectionEndBlockKey || !editorSelectionStartBlockKey || !editorSelectionEndBlockKey)
213
- return !1;
214
- const selectionStartBlockIndex = snapshot.blockIndexMap.get(selectionStartBlockKey), selectionEndBlockIndex = snapshot.blockIndexMap.get(selectionEndBlockKey), editorSelectionStartBlockIndex = snapshot.blockIndexMap.get(editorSelectionStartBlockKey), editorSelectionEndBlockIndex = snapshot.blockIndexMap.get(editorSelectionEndBlockKey);
215
- if (selectionStartBlockIndex === void 0 || selectionEndBlockIndex === void 0 || editorSelectionStartBlockIndex === void 0 || editorSelectionEndBlockIndex === void 0)
216
- return !1;
217
- const [selectionMinBlockIndex, selectionMaxBlockIndex] = selectionStartBlockIndex <= selectionEndBlockIndex ? [selectionStartBlockIndex, selectionEndBlockIndex] : [selectionEndBlockIndex, selectionStartBlockIndex], [editorSelectionMinBlockIndex, editorSelectionMaxBlockIndex] = editorSelectionStartBlockIndex <= editorSelectionEndBlockIndex ? [editorSelectionStartBlockIndex, editorSelectionEndBlockIndex] : [editorSelectionEndBlockIndex, editorSelectionStartBlockIndex];
218
- return selectionMaxBlockIndex < editorSelectionMinBlockIndex || selectionMinBlockIndex > editorSelectionMaxBlockIndex ? !1 : hasPointLevelOverlap(snapshot, selectionStart, selectionEnd, editorSelectionStart, editorSelectionEnd);
219
- };
220
- }
221
- function hasPointLevelOverlap(snapshot, selectionStart, selectionEnd, editorSelectionStart, editorSelectionEnd) {
222
- if (isEqualSelectionPoints(selectionStart, editorSelectionStart) && isEqualSelectionPoints(selectionEnd, editorSelectionEnd))
223
- return !0;
224
- 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);
225
- 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;
226
- }
227
- const isSelectionExpanded$1 = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), isSelectingEntireBlocks = (snapshot) => {
228
- if (!snapshot.context.selection)
229
- return !1;
230
- 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);
231
- if (!startBlock || !endBlock)
232
- return !1;
233
- const startBlockStartPoint = getBlockStartPoint({
234
- context: snapshot.context,
235
- block: startBlock
236
- }), endBlockEndPoint = getBlockEndPoint({
237
- context: snapshot.context,
238
- block: endBlock
239
- });
240
- return isEqualSelectionPoints(startBlockStartPoint, startPoint) && isEqualSelectionPoints(endBlockEndPoint, endPoint);
241
- }, getSelectedValue = (snapshot) => {
242
- const selection = snapshot.context.selection;
243
- if (!selection)
244
- return [];
245
- const startPoint = getSelectionStartPoint$1(selection), endPoint = getSelectionEndPoint$1(selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint);
246
- if (!startBlockKey || !endBlockKey)
247
- return [];
248
- const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
249
- if (startBlockIndex === void 0 || endBlockIndex === void 0)
250
- return [];
251
- const startBlock = snapshot.context.value.at(startBlockIndex), slicedStartBlock = startBlock ? sliceBlocks({
252
- context: snapshot.context,
253
- blocks: [startBlock]
254
- }).at(0) : void 0;
255
- if (startBlockIndex === endBlockIndex)
256
- return slicedStartBlock ? [slicedStartBlock] : [];
257
- const endBlock = snapshot.context.value.at(endBlockIndex), slicedEndBlock = endBlock ? sliceBlocks({
258
- context: snapshot.context,
259
- blocks: [endBlock]
260
- }).at(0) : void 0, middleBlocks = snapshot.context.value.slice(startBlockIndex + 1, endBlockIndex);
261
- return [...slicedStartBlock ? [slicedStartBlock] : [], ...middleBlocks, ...slicedEndBlock ? [slicedEndBlock] : []];
262
- };
263
- function isBlockPath(path) {
264
- const firstSegment = path.at(0);
265
- return path.length === 1 && firstSegment !== void 0 && isRecord(firstSegment) && "_key" in firstSegment && typeof firstSegment._key == "string";
266
- }
267
- function isRecord(value) {
268
- return !!value && (typeof value == "object" || typeof value == "function");
269
- }
270
- function isSelectionExpanded(selection) {
271
- return selection ? !isSelectionCollapsed$1(selection) : !1;
272
- }
273
- const getNextSpan = (snapshot) => {
274
- const selectionEndBlock = getSelectionEndBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
275
- if (!selectionEndBlock || !selectionEndPoint || !isTextBlock(snapshot.context, selectionEndBlock.node))
276
- return;
277
- const selectionEndPointChildKey = getChildKeyFromSelectionPoint(selectionEndPoint);
278
- let endPointChildFound = !1, nextSpan;
279
- for (const child of selectionEndBlock.node.children) {
280
- if (child._key === selectionEndPointChildKey) {
281
- endPointChildFound = !0;
282
- continue;
283
- }
284
- if (isSpan(snapshot.context, child) && endPointChildFound) {
285
- nextSpan = {
286
- node: child,
287
- path: [...selectionEndBlock.path, "children", {
288
- _key: child._key
289
- }]
290
- };
291
- break;
292
- }
293
- }
294
- return nextSpan;
295
- }, getPreviousSpan = (snapshot) => {
296
- const selectionStartBlock = getSelectionStartBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot);
297
- if (!selectionStartBlock || !selectionStartPoint || !isTextBlock(snapshot.context, selectionStartBlock.node))
298
- return;
299
- const selectionStartPointChildKey = getChildKeyFromSelectionPoint(selectionStartPoint);
300
- let previousSpan;
301
- for (const child of selectionStartBlock.node.children) {
302
- if (child._key === selectionStartPointChildKey)
303
- break;
304
- isSpan(snapshot.context, child) && (previousSpan = {
305
- node: child,
306
- path: [...selectionStartBlock.path, "children", {
307
- _key: child._key
308
- }]
309
- });
310
- }
311
- return previousSpan;
312
- }, getSelectedSpans = (snapshot) => snapshot.context.selection ? getSelectedChildren({
171
+ const getSelectedSpans = (snapshot) => snapshot.context.selection ? getSelectedChildren({
313
172
  filter: (child) => isSpan(snapshot.context, child)
314
173
  })(snapshot) : [], getMarkState = (snapshot) => {
315
174
  if (!snapshot.context.selection)
@@ -354,7 +213,7 @@ const getNextSpan = (snapshot) => {
354
213
  });
355
214
  if (!focusSpan)
356
215
  return;
357
- if (isSelectionExpanded(selection)) {
216
+ if (isSelectionExpanded$1(selection)) {
358
217
  const selectedSpans = getSelectedSpans({
359
218
  ...snapshot,
360
219
  context: {
@@ -452,27 +311,45 @@ const getNextSpan = (snapshot) => {
452
311
  state: "unchanged",
453
312
  marks
454
313
  };
455
- };
456
- function getActiveAnnotationsMarks(snapshot) {
457
- const schema = snapshot.context.schema;
458
- return (getMarkState(snapshot)?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
459
- }
460
- function getActiveDecorators(snapshot) {
461
- const schema = snapshot.context.schema, decoratorState = snapshot.decoratorState, markState = getMarkState(snapshot), decorators = schema.decorators.map((decorator) => decorator.name);
462
- let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
463
- for (const decorator in decoratorState)
464
- decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
465
- return activeDecorators;
466
- }
467
- function isActiveAnnotation(annotation, options) {
468
- return (snapshot) => {
469
- if ((options?.mode ?? "full") === "partial")
470
- return getSelectedValue(snapshot).flatMap((block) => isTextBlock(snapshot.context, block) ? block.markDefs ?? [] : []).some((markDef) => markDef._type === annotation);
471
- const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
472
- return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
473
- };
474
- }
475
- const getActiveAnnotations = (snapshot) => {
314
+ }, getSelectedBlocks = (snapshot) => {
315
+ if (!snapshot.context.selection)
316
+ return [];
317
+ const selectedBlocks = [], startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startKey = getBlockKeyFromSelectionPoint(startPoint), endKey = getBlockKeyFromSelectionPoint(endPoint);
318
+ if (!startKey || !endKey)
319
+ return selectedBlocks;
320
+ const startBlockIndex = snapshot.blockIndexMap.get(startKey), endBlockIndex = snapshot.blockIndexMap.get(endKey);
321
+ if (startBlockIndex === void 0 || endBlockIndex === void 0)
322
+ return selectedBlocks;
323
+ const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
324
+ for (const block of slicedValue) {
325
+ if (block._key === startKey) {
326
+ if (selectedBlocks.push({
327
+ node: block,
328
+ path: [{
329
+ _key: block._key
330
+ }]
331
+ }), startKey === endKey)
332
+ break;
333
+ continue;
334
+ }
335
+ if (block._key === endKey) {
336
+ selectedBlocks.push({
337
+ node: block,
338
+ path: [{
339
+ _key: block._key
340
+ }]
341
+ });
342
+ break;
343
+ }
344
+ selectedBlocks.length > 0 && selectedBlocks.push({
345
+ node: block,
346
+ path: [{
347
+ _key: block._key
348
+ }]
349
+ });
350
+ }
351
+ return selectedBlocks;
352
+ }, getActiveAnnotations = (snapshot) => {
476
353
  if (!snapshot.context.selection)
477
354
  return [];
478
355
  const selectedBlocks = getSelectedBlocks(snapshot), activeAnnotations = (getMarkState(snapshot)?.marks ?? []).filter((mark) => !snapshot.context.schema.decorators.map((decorator) => decorator.name).includes(mark));
@@ -532,7 +409,28 @@ const getActiveAnnotations = (snapshot) => {
532
409
  });
533
410
  }
534
411
  return inlineObject;
535
- }, 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, ""), getCaretWordSelection = (snapshot) => {
412
+ }, getSelectedValue = (snapshot) => {
413
+ const selection = snapshot.context.selection;
414
+ if (!selection)
415
+ return [];
416
+ const startPoint = getSelectionStartPoint$1(selection), endPoint = getSelectionEndPoint$1(selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint);
417
+ if (!startBlockKey || !endBlockKey)
418
+ return [];
419
+ const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
420
+ if (startBlockIndex === void 0 || endBlockIndex === void 0)
421
+ return [];
422
+ const startBlock = snapshot.context.value.at(startBlockIndex), slicedStartBlock = startBlock ? sliceBlocks({
423
+ context: snapshot.context,
424
+ blocks: [startBlock]
425
+ }).at(0) : void 0;
426
+ if (startBlockIndex === endBlockIndex)
427
+ return slicedStartBlock ? [slicedStartBlock] : [];
428
+ const endBlock = snapshot.context.value.at(endBlockIndex), slicedEndBlock = endBlock ? sliceBlocks({
429
+ context: snapshot.context,
430
+ blocks: [endBlock]
431
+ }).at(0) : void 0, middleBlocks = snapshot.context.value.slice(startBlockIndex + 1, endBlockIndex);
432
+ return [...slicedStartBlock ? [slicedStartBlock] : [], ...middleBlocks, ...slicedEndBlock ? [slicedEndBlock] : []];
433
+ }, 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) => {
536
434
  if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
537
435
  return null;
538
436
  const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? spanSelectionPointToBlockOffset({
@@ -595,7 +493,7 @@ const getActiveAnnotations = (snapshot) => {
595
493
  anchor: caretWordStartSelectionPoint,
596
494
  focus: caretWordEndSelectionPoint
597
495
  };
598
- return isSelectionExpanded$1({
496
+ return isSelectionExpanded({
599
497
  context: {
600
498
  ...snapshot.context,
601
499
  selection: caretWordSelection
@@ -607,6 +505,12 @@ const getActiveAnnotations = (snapshot) => {
607
505
  node: focusBlock.node,
608
506
  path: focusBlock.path
609
507
  } : void 0;
508
+ }, getFocusInlineObject = (snapshot) => {
509
+ const focusChild = getFocusChild(snapshot);
510
+ return focusChild && !isSpan(snapshot.context, focusChild.node) ? {
511
+ node: focusChild.node,
512
+ path: focusChild.path
513
+ } : void 0;
610
514
  }, getFocusListBlock = (snapshot) => {
611
515
  const focusTextBlock = getFocusTextBlock(snapshot);
612
516
  return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node) ? {
@@ -714,9 +618,28 @@ const getActiveAnnotations = (snapshot) => {
714
618
  }
715
619
  });
716
620
  };
621
+ function getActiveAnnotationsMarks(snapshot) {
622
+ const schema = snapshot.context.schema;
623
+ return (getMarkState(snapshot)?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
624
+ }
625
+ function isActiveAnnotation(annotation, options) {
626
+ return (snapshot) => {
627
+ if ((options?.mode ?? "full") === "partial")
628
+ return getSelectedValue(snapshot).flatMap((block) => isTextBlock(snapshot.context, block) ? block.markDefs ?? [] : []).some((markDef) => markDef._type === annotation);
629
+ const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
630
+ return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
631
+ };
632
+ }
633
+ function getActiveDecorators(snapshot) {
634
+ const schema = snapshot.context.schema, decoratorState = snapshot.decoratorState, markState = getMarkState(snapshot), decorators = schema.decorators.map((decorator) => decorator.name);
635
+ let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
636
+ for (const decorator in decoratorState)
637
+ decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
638
+ return activeDecorators;
639
+ }
717
640
  function isActiveDecorator(decorator) {
718
641
  return (snapshot) => {
719
- if (isSelectionExpanded$1(snapshot)) {
642
+ if (isSelectionExpanded(snapshot)) {
720
643
  const selectedSpans = getSelectedSpans(snapshot);
721
644
  return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
722
645
  }
@@ -751,6 +674,81 @@ function isAtTheStartOfBlock(block) {
751
674
  return isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
752
675
  };
753
676
  }
677
+ function comparePoints(snapshot, pointA, pointB) {
678
+ const blockKeyA = getBlockKeyFromSelectionPoint(pointA), blockKeyB = getBlockKeyFromSelectionPoint(pointB);
679
+ if (!blockKeyA)
680
+ throw new Error(`Cannot compare points: no block key found for ${pointA}`);
681
+ if (!blockKeyB)
682
+ throw new Error(`Cannot compare points: no block key found for ${pointB}`);
683
+ const blockIndexA = snapshot.blockIndexMap.get(blockKeyA), blockIndexB = snapshot.blockIndexMap.get(blockKeyB);
684
+ if (blockIndexA === void 0)
685
+ throw new Error(`Cannot compare points: block "${blockKeyA}" not found`);
686
+ if (blockIndexB === void 0)
687
+ throw new Error(`Cannot compare points: block "${blockKeyB}" not found`);
688
+ if (blockIndexA < blockIndexB)
689
+ return -1;
690
+ if (blockIndexA > blockIndexB)
691
+ return 1;
692
+ const block = snapshot.context.value.at(blockIndexA);
693
+ if (!block || !isTextBlock(snapshot.context, block))
694
+ return 0;
695
+ const childKeyA = getChildKeyFromSelectionPoint(pointA), childKeyB = getChildKeyFromSelectionPoint(pointB);
696
+ if (!childKeyA)
697
+ throw new Error(`Cannot compare points: no child key found for ${pointA}`);
698
+ if (!childKeyB)
699
+ throw new Error(`Cannot compare points: no child key found for ${pointB}`);
700
+ let childIndexA, childIndexB;
701
+ for (let i = 0; i < block.children.length; i++) {
702
+ const child = block.children.at(i);
703
+ if (child) {
704
+ if (child._key === childKeyA && child._key === childKeyB)
705
+ return pointA.offset < pointB.offset ? -1 : pointA.offset > pointB.offset ? 1 : 0;
706
+ if (child._key === childKeyA && (childIndexA = i), child._key === childKeyB && (childIndexB = i), childIndexA !== void 0 && childIndexB !== void 0)
707
+ break;
708
+ }
709
+ }
710
+ if (childIndexA === void 0)
711
+ throw new Error(`Cannot compare points: child "${childKeyA}" not found`);
712
+ if (childIndexB === void 0)
713
+ throw new Error(`Cannot compare points: child "${childKeyB}" not found`);
714
+ return childIndexA < childIndexB ? -1 : childIndexA > childIndexB ? 1 : 0;
715
+ }
716
+ function isOverlappingSelection(selection) {
717
+ return (snapshot) => {
718
+ const editorSelection = snapshot.context.selection;
719
+ if (!selection || !editorSelection)
720
+ return !1;
721
+ 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);
722
+ if (!selectionStartBlockKey || !selectionEndBlockKey || !editorSelectionStartBlockKey || !editorSelectionEndBlockKey)
723
+ return !1;
724
+ const selectionStartBlockIndex = snapshot.blockIndexMap.get(selectionStartBlockKey), selectionEndBlockIndex = snapshot.blockIndexMap.get(selectionEndBlockKey), editorSelectionStartBlockIndex = snapshot.blockIndexMap.get(editorSelectionStartBlockKey), editorSelectionEndBlockIndex = snapshot.blockIndexMap.get(editorSelectionEndBlockKey);
725
+ if (selectionStartBlockIndex === void 0 || selectionEndBlockIndex === void 0 || editorSelectionStartBlockIndex === void 0 || editorSelectionEndBlockIndex === void 0)
726
+ return !1;
727
+ const [selectionMinBlockIndex, selectionMaxBlockIndex] = selectionStartBlockIndex <= selectionEndBlockIndex ? [selectionStartBlockIndex, selectionEndBlockIndex] : [selectionEndBlockIndex, selectionStartBlockIndex], [editorSelectionMinBlockIndex, editorSelectionMaxBlockIndex] = editorSelectionStartBlockIndex <= editorSelectionEndBlockIndex ? [editorSelectionStartBlockIndex, editorSelectionEndBlockIndex] : [editorSelectionEndBlockIndex, editorSelectionStartBlockIndex];
728
+ return selectionMaxBlockIndex < editorSelectionMinBlockIndex || selectionMinBlockIndex > editorSelectionMaxBlockIndex ? !1 : hasPointLevelOverlap(snapshot, selectionStart, selectionEnd, editorSelectionStart, editorSelectionEnd);
729
+ };
730
+ }
731
+ function hasPointLevelOverlap(snapshot, selectionStart, selectionEnd, editorSelectionStart, editorSelectionEnd) {
732
+ if (isEqualSelectionPoints(selectionStart, editorSelectionStart) && isEqualSelectionPoints(selectionEnd, editorSelectionEnd))
733
+ return !0;
734
+ 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);
735
+ 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;
736
+ }
737
+ const isSelectingEntireBlocks = (snapshot) => {
738
+ if (!snapshot.context.selection)
739
+ return !1;
740
+ 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);
741
+ if (!startBlock || !endBlock)
742
+ return !1;
743
+ const startBlockStartPoint = getBlockStartPoint({
744
+ context: snapshot.context,
745
+ block: startBlock
746
+ }), endBlockEndPoint = getBlockEndPoint({
747
+ context: snapshot.context,
748
+ block: endBlock
749
+ });
750
+ return isEqualSelectionPoints(startBlockStartPoint, startPoint) && isEqualSelectionPoints(endBlockEndPoint, endPoint);
751
+ };
754
752
  export {
755
753
  comparePoints,
756
754
  getActiveAnnotations,
@@ -795,6 +793,6 @@ export {
795
793
  isOverlappingSelection,
796
794
  isSelectingEntireBlocks,
797
795
  isSelectionCollapsed,
798
- isSelectionExpanded$1 as isSelectionExpanded
796
+ isSelectionExpanded
799
797
  };
800
- //# sourceMappingURL=selector.is-at-the-start-of-block.js.map
798
+ //# sourceMappingURL=selector.is-selecting-entire-blocks.js.map