@portabletext/editor 1.30.5 → 1.31.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.
- package/lib/_chunks-cjs/behavior.core.cjs +35 -2
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +4 -4
- package/lib/_chunks-cjs/plugin.event-listener.cjs +143 -170
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +5 -41
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +174 -6
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs +1 -58
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.reverse-selection.cjs +105 -0
- package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +36 -3
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +2 -1
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +143 -170
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +4 -41
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +170 -2
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.is-empty-text-block.js +1 -59
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -1
- package/lib/_chunks-es/util.reverse-selection.js +106 -1
- package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
- package/lib/index.d.cts +0 -4
- package/lib/index.d.ts +0 -4
- package/lib/plugins/index.cjs +8 -8
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +0 -4
- package/lib/plugins/index.d.ts +0 -4
- package/lib/plugins/index.js +2 -3
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +33 -6
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +209 -0
- package/lib/selectors/index.d.ts +209 -0
- package/lib/selectors/index.js +31 -5
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +10 -13
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.js +3 -6
- package/lib/utils/index.js.map +1 -1
- package/package.json +3 -3
- package/src/behaviors/behavior.core.annotations.ts +32 -0
- package/src/behaviors/behavior.core.ts +1 -0
- package/src/editor/plugins/createWithEditableAPI.ts +1 -2
- package/src/editor/plugins/createWithUtils.ts +1 -52
- package/src/selectors/index.ts +4 -0
- package/src/selectors/selector.get-block-offsets.ts +33 -0
- package/src/selectors/selector.get-caret-word-selection.test.ts +288 -0
- package/src/selectors/selector.get-caret-word-selection.ts +116 -0
- package/src/selectors/selector.get-next-inline-object.ts +56 -0
- package/src/selectors/selector.get-previous-inline-object.ts +53 -0
- package/src/types/editor.ts +0 -5
- package/lib/_chunks-cjs/selector.get-selection-start-point.cjs +0 -15
- package/lib/_chunks-cjs/selector.get-selection-start-point.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +0 -46
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +0 -1
- package/lib/_chunks-es/selector.get-selection-start-point.js +0 -16
- package/lib/_chunks-es/selector.get-selection-start-point.js.map +0 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js +0 -47
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +0 -1
|
@@ -5,6 +5,8 @@ import type {
|
|
|
5
5
|
BlockStyleDefinition,
|
|
6
6
|
ObjectSchemaType,
|
|
7
7
|
Path,
|
|
8
|
+
PathSegment,
|
|
9
|
+
PortableTextChild,
|
|
8
10
|
} from '@sanity/types'
|
|
9
11
|
import {
|
|
10
12
|
KeyedSegment,
|
|
@@ -15,6 +17,30 @@ import {
|
|
|
15
17
|
PortableTextTextBlock,
|
|
16
18
|
} from '@sanity/types'
|
|
17
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @beta
|
|
22
|
+
*/
|
|
23
|
+
declare type BlockOffset = {
|
|
24
|
+
path: [KeyedSegment]
|
|
25
|
+
offset: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
declare function blockOffsetToSpanSelectionPoint({
|
|
32
|
+
value,
|
|
33
|
+
blockOffset,
|
|
34
|
+
}: {
|
|
35
|
+
value: Array<PortableTextBlock>
|
|
36
|
+
blockOffset: BlockOffset
|
|
37
|
+
}):
|
|
38
|
+
| {
|
|
39
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
40
|
+
offset: number
|
|
41
|
+
}
|
|
42
|
+
| undefined
|
|
43
|
+
|
|
18
44
|
declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
|
|
19
45
|
mimeType: TMIMEType
|
|
20
46
|
serialize: Serializer<TMIMEType>
|
|
@@ -129,11 +155,51 @@ export declare const getActiveStyle: EditorSelector<
|
|
|
129
155
|
PortableTextTextBlock['style']
|
|
130
156
|
>
|
|
131
157
|
|
|
158
|
+
/**
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
declare function getBlockEndPoint({
|
|
162
|
+
node,
|
|
163
|
+
path,
|
|
164
|
+
}: {
|
|
165
|
+
node: PortableTextBlock
|
|
166
|
+
path: [KeyedSegment]
|
|
167
|
+
}): EditorSelectionPoint
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
export declare const getBlockOffsets: EditorSelector<
|
|
173
|
+
| {
|
|
174
|
+
start: utils.BlockOffset
|
|
175
|
+
end: utils.BlockOffset
|
|
176
|
+
}
|
|
177
|
+
| undefined
|
|
178
|
+
>
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @public
|
|
182
|
+
*/
|
|
183
|
+
declare function getBlockStartPoint({
|
|
184
|
+
node,
|
|
185
|
+
path,
|
|
186
|
+
}: {
|
|
187
|
+
node: PortableTextBlock
|
|
188
|
+
path: [KeyedSegment]
|
|
189
|
+
}): EditorSelectionPoint
|
|
190
|
+
|
|
132
191
|
/**
|
|
133
192
|
* @public
|
|
134
193
|
*/
|
|
135
194
|
export declare const getBlockTextBefore: EditorSelector<string>
|
|
136
195
|
|
|
196
|
+
/**
|
|
197
|
+
* @public
|
|
198
|
+
* Returns the selection of the of the word the caret is placed in.
|
|
199
|
+
* Note: Only returns a word selection if the current selection is collapsed
|
|
200
|
+
*/
|
|
201
|
+
export declare const getCaretWordSelection: EditorSelector<EditorSelection>
|
|
202
|
+
|
|
137
203
|
/**
|
|
138
204
|
* @public
|
|
139
205
|
*/
|
|
@@ -233,6 +299,17 @@ export declare const getNextBlock: EditorSelector<
|
|
|
233
299
|
| undefined
|
|
234
300
|
>
|
|
235
301
|
|
|
302
|
+
/**
|
|
303
|
+
* @public
|
|
304
|
+
*/
|
|
305
|
+
export declare const getNextInlineObject: EditorSelector<
|
|
306
|
+
| {
|
|
307
|
+
node: PortableTextObject
|
|
308
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
309
|
+
}
|
|
310
|
+
| undefined
|
|
311
|
+
>
|
|
312
|
+
|
|
236
313
|
/**
|
|
237
314
|
* @public
|
|
238
315
|
*/
|
|
@@ -244,6 +321,17 @@ export declare const getPreviousBlock: EditorSelector<
|
|
|
244
321
|
| undefined
|
|
245
322
|
>
|
|
246
323
|
|
|
324
|
+
/**
|
|
325
|
+
* @public
|
|
326
|
+
*/
|
|
327
|
+
export declare const getPreviousInlineObject: EditorSelector<
|
|
328
|
+
| {
|
|
329
|
+
node: PortableTextObject
|
|
330
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
331
|
+
}
|
|
332
|
+
| undefined
|
|
333
|
+
>
|
|
334
|
+
|
|
247
335
|
/**
|
|
248
336
|
* @public
|
|
249
337
|
*/
|
|
@@ -316,6 +404,11 @@ export declare const getSelectionStartPoint: EditorSelector<
|
|
|
316
404
|
*/
|
|
317
405
|
export declare const getSelectionText: EditorSelector<string>
|
|
318
406
|
|
|
407
|
+
/**
|
|
408
|
+
* @public
|
|
409
|
+
*/
|
|
410
|
+
declare function getTextBlockText(block: PortableTextTextBlock): string
|
|
411
|
+
|
|
319
412
|
/**
|
|
320
413
|
* @public
|
|
321
414
|
*/
|
|
@@ -363,6 +456,24 @@ export declare function isAtTheStartOfBlock(block: {
|
|
|
363
456
|
path: [KeyedSegment]
|
|
364
457
|
}): EditorSelector<boolean>
|
|
365
458
|
|
|
459
|
+
/**
|
|
460
|
+
* @public
|
|
461
|
+
*/
|
|
462
|
+
declare function isEmptyTextBlock(block: PortableTextBlock): boolean
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* @public
|
|
466
|
+
*/
|
|
467
|
+
declare function isEqualSelectionPoints(
|
|
468
|
+
a: EditorSelectionPoint,
|
|
469
|
+
b: EditorSelectionPoint,
|
|
470
|
+
): boolean
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* @public
|
|
474
|
+
*/
|
|
475
|
+
declare function isKeyedSegment(segment: PathSegment): segment is KeyedSegment
|
|
476
|
+
|
|
366
477
|
/**
|
|
367
478
|
* @public
|
|
368
479
|
*/
|
|
@@ -394,6 +505,35 @@ export declare const isSelectionCollapsed: EditorSelector<boolean>
|
|
|
394
505
|
*/
|
|
395
506
|
export declare const isSelectionExpanded: EditorSelector<boolean>
|
|
396
507
|
|
|
508
|
+
/**
|
|
509
|
+
* @public
|
|
510
|
+
*/
|
|
511
|
+
declare function isSpan(
|
|
512
|
+
context: Pick<EditorContext, 'schema'>,
|
|
513
|
+
child: PortableTextChild,
|
|
514
|
+
): child is PortableTextSpan
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* @public
|
|
518
|
+
*/
|
|
519
|
+
declare function isTextBlock(
|
|
520
|
+
context: Pick<EditorContext, 'schema'>,
|
|
521
|
+
block: PortableTextBlock,
|
|
522
|
+
): block is PortableTextTextBlock
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* @beta
|
|
526
|
+
*/
|
|
527
|
+
declare function mergeTextBlocks({
|
|
528
|
+
context,
|
|
529
|
+
targetBlock,
|
|
530
|
+
incomingBlock,
|
|
531
|
+
}: {
|
|
532
|
+
context: Pick<EditorContext, 'keyGenerator' | 'schema'>
|
|
533
|
+
targetBlock: PortableTextTextBlock
|
|
534
|
+
incomingBlock: PortableTextTextBlock
|
|
535
|
+
}): PortableTextTextBlock<PortableTextSpan | PortableTextObject>
|
|
536
|
+
|
|
397
537
|
declare type MIMEType = `${string}/${string}`
|
|
398
538
|
|
|
399
539
|
/**
|
|
@@ -420,6 +560,13 @@ export declare type PortableTextMemberSchemaTypes = {
|
|
|
420
560
|
lists: BlockListDefinition[]
|
|
421
561
|
}
|
|
422
562
|
|
|
563
|
+
/**
|
|
564
|
+
* @public
|
|
565
|
+
*/
|
|
566
|
+
declare function reverseSelection(
|
|
567
|
+
selection: NonNullable<EditorSelection>,
|
|
568
|
+
): NonNullable<EditorSelection>
|
|
569
|
+
|
|
423
570
|
declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
424
571
|
context,
|
|
425
572
|
event,
|
|
@@ -432,4 +579,66 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
|
432
579
|
'serialization.success' | 'serialization.failure'
|
|
433
580
|
>
|
|
434
581
|
|
|
582
|
+
/**
|
|
583
|
+
* @public
|
|
584
|
+
*/
|
|
585
|
+
declare function sliceBlocks({
|
|
586
|
+
blocks,
|
|
587
|
+
selection,
|
|
588
|
+
}: {
|
|
589
|
+
blocks: Array<PortableTextBlock>
|
|
590
|
+
selection: EditorSelection
|
|
591
|
+
}): Array<PortableTextBlock>
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* @public
|
|
595
|
+
*/
|
|
596
|
+
declare function spanSelectionPointToBlockOffset({
|
|
597
|
+
value,
|
|
598
|
+
selectionPoint,
|
|
599
|
+
}: {
|
|
600
|
+
value: Array<PortableTextBlock>
|
|
601
|
+
selectionPoint: EditorSelectionPoint
|
|
602
|
+
}): BlockOffset | undefined
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* @beta
|
|
606
|
+
*/
|
|
607
|
+
declare function splitTextBlock({
|
|
608
|
+
context,
|
|
609
|
+
block,
|
|
610
|
+
point,
|
|
611
|
+
}: {
|
|
612
|
+
context: Pick<EditorContext, 'schema'>
|
|
613
|
+
block: PortableTextTextBlock
|
|
614
|
+
point: EditorSelectionPoint
|
|
615
|
+
}):
|
|
616
|
+
| {
|
|
617
|
+
before: PortableTextTextBlock
|
|
618
|
+
after: PortableTextTextBlock
|
|
619
|
+
}
|
|
620
|
+
| undefined
|
|
621
|
+
|
|
622
|
+
declare namespace utils {
|
|
623
|
+
export {
|
|
624
|
+
BlockOffset,
|
|
625
|
+
EditorSelection,
|
|
626
|
+
EditorSelectionPoint,
|
|
627
|
+
blockOffsetToSpanSelectionPoint,
|
|
628
|
+
spanSelectionPointToBlockOffset,
|
|
629
|
+
getBlockEndPoint,
|
|
630
|
+
getBlockStartPoint,
|
|
631
|
+
getTextBlockText,
|
|
632
|
+
isEmptyTextBlock,
|
|
633
|
+
isEqualSelectionPoints,
|
|
634
|
+
isKeyedSegment,
|
|
635
|
+
isSpan,
|
|
636
|
+
isTextBlock,
|
|
637
|
+
mergeTextBlocks,
|
|
638
|
+
reverseSelection,
|
|
639
|
+
sliceBlocks,
|
|
640
|
+
splitTextBlock,
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
435
644
|
export {}
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import type {
|
|
|
5
5
|
BlockStyleDefinition,
|
|
6
6
|
ObjectSchemaType,
|
|
7
7
|
Path,
|
|
8
|
+
PathSegment,
|
|
9
|
+
PortableTextChild,
|
|
8
10
|
} from '@sanity/types'
|
|
9
11
|
import {
|
|
10
12
|
KeyedSegment,
|
|
@@ -15,6 +17,30 @@ import {
|
|
|
15
17
|
PortableTextTextBlock,
|
|
16
18
|
} from '@sanity/types'
|
|
17
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @beta
|
|
22
|
+
*/
|
|
23
|
+
declare type BlockOffset = {
|
|
24
|
+
path: [KeyedSegment]
|
|
25
|
+
offset: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
declare function blockOffsetToSpanSelectionPoint({
|
|
32
|
+
value,
|
|
33
|
+
blockOffset,
|
|
34
|
+
}: {
|
|
35
|
+
value: Array<PortableTextBlock>
|
|
36
|
+
blockOffset: BlockOffset
|
|
37
|
+
}):
|
|
38
|
+
| {
|
|
39
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
40
|
+
offset: number
|
|
41
|
+
}
|
|
42
|
+
| undefined
|
|
43
|
+
|
|
18
44
|
declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
|
|
19
45
|
mimeType: TMIMEType
|
|
20
46
|
serialize: Serializer<TMIMEType>
|
|
@@ -129,11 +155,51 @@ export declare const getActiveStyle: EditorSelector<
|
|
|
129
155
|
PortableTextTextBlock['style']
|
|
130
156
|
>
|
|
131
157
|
|
|
158
|
+
/**
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
declare function getBlockEndPoint({
|
|
162
|
+
node,
|
|
163
|
+
path,
|
|
164
|
+
}: {
|
|
165
|
+
node: PortableTextBlock
|
|
166
|
+
path: [KeyedSegment]
|
|
167
|
+
}): EditorSelectionPoint
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
export declare const getBlockOffsets: EditorSelector<
|
|
173
|
+
| {
|
|
174
|
+
start: utils.BlockOffset
|
|
175
|
+
end: utils.BlockOffset
|
|
176
|
+
}
|
|
177
|
+
| undefined
|
|
178
|
+
>
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @public
|
|
182
|
+
*/
|
|
183
|
+
declare function getBlockStartPoint({
|
|
184
|
+
node,
|
|
185
|
+
path,
|
|
186
|
+
}: {
|
|
187
|
+
node: PortableTextBlock
|
|
188
|
+
path: [KeyedSegment]
|
|
189
|
+
}): EditorSelectionPoint
|
|
190
|
+
|
|
132
191
|
/**
|
|
133
192
|
* @public
|
|
134
193
|
*/
|
|
135
194
|
export declare const getBlockTextBefore: EditorSelector<string>
|
|
136
195
|
|
|
196
|
+
/**
|
|
197
|
+
* @public
|
|
198
|
+
* Returns the selection of the of the word the caret is placed in.
|
|
199
|
+
* Note: Only returns a word selection if the current selection is collapsed
|
|
200
|
+
*/
|
|
201
|
+
export declare const getCaretWordSelection: EditorSelector<EditorSelection>
|
|
202
|
+
|
|
137
203
|
/**
|
|
138
204
|
* @public
|
|
139
205
|
*/
|
|
@@ -233,6 +299,17 @@ export declare const getNextBlock: EditorSelector<
|
|
|
233
299
|
| undefined
|
|
234
300
|
>
|
|
235
301
|
|
|
302
|
+
/**
|
|
303
|
+
* @public
|
|
304
|
+
*/
|
|
305
|
+
export declare const getNextInlineObject: EditorSelector<
|
|
306
|
+
| {
|
|
307
|
+
node: PortableTextObject
|
|
308
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
309
|
+
}
|
|
310
|
+
| undefined
|
|
311
|
+
>
|
|
312
|
+
|
|
236
313
|
/**
|
|
237
314
|
* @public
|
|
238
315
|
*/
|
|
@@ -244,6 +321,17 @@ export declare const getPreviousBlock: EditorSelector<
|
|
|
244
321
|
| undefined
|
|
245
322
|
>
|
|
246
323
|
|
|
324
|
+
/**
|
|
325
|
+
* @public
|
|
326
|
+
*/
|
|
327
|
+
export declare const getPreviousInlineObject: EditorSelector<
|
|
328
|
+
| {
|
|
329
|
+
node: PortableTextObject
|
|
330
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
331
|
+
}
|
|
332
|
+
| undefined
|
|
333
|
+
>
|
|
334
|
+
|
|
247
335
|
/**
|
|
248
336
|
* @public
|
|
249
337
|
*/
|
|
@@ -316,6 +404,11 @@ export declare const getSelectionStartPoint: EditorSelector<
|
|
|
316
404
|
*/
|
|
317
405
|
export declare const getSelectionText: EditorSelector<string>
|
|
318
406
|
|
|
407
|
+
/**
|
|
408
|
+
* @public
|
|
409
|
+
*/
|
|
410
|
+
declare function getTextBlockText(block: PortableTextTextBlock): string
|
|
411
|
+
|
|
319
412
|
/**
|
|
320
413
|
* @public
|
|
321
414
|
*/
|
|
@@ -363,6 +456,24 @@ export declare function isAtTheStartOfBlock(block: {
|
|
|
363
456
|
path: [KeyedSegment]
|
|
364
457
|
}): EditorSelector<boolean>
|
|
365
458
|
|
|
459
|
+
/**
|
|
460
|
+
* @public
|
|
461
|
+
*/
|
|
462
|
+
declare function isEmptyTextBlock(block: PortableTextBlock): boolean
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* @public
|
|
466
|
+
*/
|
|
467
|
+
declare function isEqualSelectionPoints(
|
|
468
|
+
a: EditorSelectionPoint,
|
|
469
|
+
b: EditorSelectionPoint,
|
|
470
|
+
): boolean
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* @public
|
|
474
|
+
*/
|
|
475
|
+
declare function isKeyedSegment(segment: PathSegment): segment is KeyedSegment
|
|
476
|
+
|
|
366
477
|
/**
|
|
367
478
|
* @public
|
|
368
479
|
*/
|
|
@@ -394,6 +505,35 @@ export declare const isSelectionCollapsed: EditorSelector<boolean>
|
|
|
394
505
|
*/
|
|
395
506
|
export declare const isSelectionExpanded: EditorSelector<boolean>
|
|
396
507
|
|
|
508
|
+
/**
|
|
509
|
+
* @public
|
|
510
|
+
*/
|
|
511
|
+
declare function isSpan(
|
|
512
|
+
context: Pick<EditorContext, 'schema'>,
|
|
513
|
+
child: PortableTextChild,
|
|
514
|
+
): child is PortableTextSpan
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* @public
|
|
518
|
+
*/
|
|
519
|
+
declare function isTextBlock(
|
|
520
|
+
context: Pick<EditorContext, 'schema'>,
|
|
521
|
+
block: PortableTextBlock,
|
|
522
|
+
): block is PortableTextTextBlock
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* @beta
|
|
526
|
+
*/
|
|
527
|
+
declare function mergeTextBlocks({
|
|
528
|
+
context,
|
|
529
|
+
targetBlock,
|
|
530
|
+
incomingBlock,
|
|
531
|
+
}: {
|
|
532
|
+
context: Pick<EditorContext, 'keyGenerator' | 'schema'>
|
|
533
|
+
targetBlock: PortableTextTextBlock
|
|
534
|
+
incomingBlock: PortableTextTextBlock
|
|
535
|
+
}): PortableTextTextBlock<PortableTextSpan | PortableTextObject>
|
|
536
|
+
|
|
397
537
|
declare type MIMEType = `${string}/${string}`
|
|
398
538
|
|
|
399
539
|
/**
|
|
@@ -420,6 +560,13 @@ export declare type PortableTextMemberSchemaTypes = {
|
|
|
420
560
|
lists: BlockListDefinition[]
|
|
421
561
|
}
|
|
422
562
|
|
|
563
|
+
/**
|
|
564
|
+
* @public
|
|
565
|
+
*/
|
|
566
|
+
declare function reverseSelection(
|
|
567
|
+
selection: NonNullable<EditorSelection>,
|
|
568
|
+
): NonNullable<EditorSelection>
|
|
569
|
+
|
|
423
570
|
declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
424
571
|
context,
|
|
425
572
|
event,
|
|
@@ -432,4 +579,66 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
|
432
579
|
'serialization.success' | 'serialization.failure'
|
|
433
580
|
>
|
|
434
581
|
|
|
582
|
+
/**
|
|
583
|
+
* @public
|
|
584
|
+
*/
|
|
585
|
+
declare function sliceBlocks({
|
|
586
|
+
blocks,
|
|
587
|
+
selection,
|
|
588
|
+
}: {
|
|
589
|
+
blocks: Array<PortableTextBlock>
|
|
590
|
+
selection: EditorSelection
|
|
591
|
+
}): Array<PortableTextBlock>
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* @public
|
|
595
|
+
*/
|
|
596
|
+
declare function spanSelectionPointToBlockOffset({
|
|
597
|
+
value,
|
|
598
|
+
selectionPoint,
|
|
599
|
+
}: {
|
|
600
|
+
value: Array<PortableTextBlock>
|
|
601
|
+
selectionPoint: EditorSelectionPoint
|
|
602
|
+
}): BlockOffset | undefined
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* @beta
|
|
606
|
+
*/
|
|
607
|
+
declare function splitTextBlock({
|
|
608
|
+
context,
|
|
609
|
+
block,
|
|
610
|
+
point,
|
|
611
|
+
}: {
|
|
612
|
+
context: Pick<EditorContext, 'schema'>
|
|
613
|
+
block: PortableTextTextBlock
|
|
614
|
+
point: EditorSelectionPoint
|
|
615
|
+
}):
|
|
616
|
+
| {
|
|
617
|
+
before: PortableTextTextBlock
|
|
618
|
+
after: PortableTextTextBlock
|
|
619
|
+
}
|
|
620
|
+
| undefined
|
|
621
|
+
|
|
622
|
+
declare namespace utils {
|
|
623
|
+
export {
|
|
624
|
+
BlockOffset,
|
|
625
|
+
EditorSelection,
|
|
626
|
+
EditorSelectionPoint,
|
|
627
|
+
blockOffsetToSpanSelectionPoint,
|
|
628
|
+
spanSelectionPointToBlockOffset,
|
|
629
|
+
getBlockEndPoint,
|
|
630
|
+
getBlockStartPoint,
|
|
631
|
+
getTextBlockText,
|
|
632
|
+
isEmptyTextBlock,
|
|
633
|
+
isEqualSelectionPoints,
|
|
634
|
+
isKeyedSegment,
|
|
635
|
+
isSpan,
|
|
636
|
+
isTextBlock,
|
|
637
|
+
mergeTextBlocks,
|
|
638
|
+
reverseSelection,
|
|
639
|
+
sliceBlocks,
|
|
640
|
+
splitTextBlock,
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
435
644
|
export {}
|
package/lib/selectors/index.js
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
import { isPortableTextTextBlock, isKeySegment } from "@sanity/types";
|
|
2
|
-
import { getSelectedBlocks, getSelectedSpans } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
3
|
-
import { getActiveListItem, getActiveStyle, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getSelectionEndBlock, getSelectionStartBlock, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
2
|
+
import { getSelectedBlocks, getSelectedSpans, getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
3
|
+
import { getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
4
|
+
import { spanSelectionPointToBlockOffset, reverseSelection } from "../_chunks-es/util.reverse-selection.js";
|
|
4
5
|
import { sliceBlocks } from "../_chunks-es/util.slice-blocks.js";
|
|
5
|
-
import {
|
|
6
|
-
import { getBlockTextBefore, getSelectionText } from "../_chunks-es/selector.get-text-before.js";
|
|
7
|
-
import { reverseSelection } from "../_chunks-es/util.reverse-selection.js";
|
|
6
|
+
import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
|
|
8
7
|
const getActiveAnnotations = (snapshot) => {
|
|
9
8
|
if (!snapshot.context.selection)
|
|
10
9
|
return [];
|
|
11
10
|
const selectedBlocks = getSelectedBlocks(snapshot), selectedSpans = getSelectedSpans(snapshot);
|
|
12
11
|
return selectedSpans.length === 0 ? [] : selectedBlocks.flatMap((block) => isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => selectedSpans.some((span) => span.node.marks?.includes(markDef._key)));
|
|
12
|
+
}, getBlockOffsets = ({
|
|
13
|
+
context
|
|
14
|
+
}) => {
|
|
15
|
+
if (!context.selection)
|
|
16
|
+
return;
|
|
17
|
+
const selectionStartPoint = getSelectionStartPoint({
|
|
18
|
+
context
|
|
19
|
+
}), selectionEndPoint = getSelectionEndPoint({
|
|
20
|
+
context
|
|
21
|
+
});
|
|
22
|
+
if (!selectionStartPoint || !selectionEndPoint)
|
|
23
|
+
return;
|
|
24
|
+
const start = spanSelectionPointToBlockOffset({
|
|
25
|
+
value: context.value,
|
|
26
|
+
selectionPoint: selectionStartPoint
|
|
27
|
+
}), end = spanSelectionPointToBlockOffset({
|
|
28
|
+
value: context.value,
|
|
29
|
+
selectionPoint: selectionEndPoint
|
|
30
|
+
});
|
|
31
|
+
return start && end ? {
|
|
32
|
+
start,
|
|
33
|
+
end
|
|
34
|
+
} : void 0;
|
|
13
35
|
}, getSelectedSlice = ({
|
|
14
36
|
context
|
|
15
37
|
}) => sliceBlocks({
|
|
@@ -118,7 +140,9 @@ export {
|
|
|
118
140
|
getActiveAnnotations,
|
|
119
141
|
getActiveListItem,
|
|
120
142
|
getActiveStyle,
|
|
143
|
+
getBlockOffsets,
|
|
121
144
|
getBlockTextBefore,
|
|
145
|
+
getCaretWordSelection,
|
|
122
146
|
getFirstBlock,
|
|
123
147
|
getFocusBlock,
|
|
124
148
|
getFocusBlockObject,
|
|
@@ -128,7 +152,9 @@ export {
|
|
|
128
152
|
getFocusTextBlock,
|
|
129
153
|
getLastBlock,
|
|
130
154
|
getNextBlock,
|
|
155
|
+
getNextInlineObject,
|
|
131
156
|
getPreviousBlock,
|
|
157
|
+
getPreviousInlineObject,
|
|
132
158
|
getSelectedBlocks,
|
|
133
159
|
getSelectedSlice,
|
|
134
160
|
getSelectedSpans,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts","../../src/selectors/selector.is-overlapping-selection.ts"],"sourcesContent":["import {isPortableTextTextBlock, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return []\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n selectedSpans.some((span) => span.node.marks?.includes(markDef._key)),\n )\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 context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import type {EditorSelection, EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = ({context}) => {\n return context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return context.value\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const endBlockKey = isKeySegment(selection.focus.path[0])\n ? selection.focus.path[0]._key\n : undefined\n const endChildKey = isKeySegment(selection.focus.path[2])\n ? selection.focus.path[2]._key\n : undefined\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n let after = false\n\n for (const block of snapshot.context.value) {\n if (block._key === endBlockKey) {\n if (block._key !== pointBlockKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !endChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (child._key !== pointChildKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this child\n\n after = point.offset > selection.focus.offset\n break\n }\n\n if (child._key === pointChildKey) {\n break\n }\n }\n }\n\n if (block._key === pointBlockKey) {\n break\n }\n }\n\n return after\n }\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const startBlockKey = isKeySegment(selection.anchor.path[0])\n ? selection.anchor.path[0]._key\n : undefined\n const startChildKey = isKeySegment(selection.anchor.path[2])\n ? selection.anchor.path[2]._key\n : undefined\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n let before = false\n\n for (const block of snapshot.context.value) {\n if (block._key === pointBlockKey) {\n if (block._key !== startBlockKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !startChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === pointChildKey) {\n if (child._key !== startChildKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this child\n\n before = point.offset < selection.anchor.offset\n break\n }\n\n if (child._key === startChildKey) {\n break\n }\n }\n }\n\n if (block._key === startBlockKey) {\n break\n }\n }\n\n return before\n }\n}\n","import type {EditorSelection} from '../types/editor'\nimport type {EditorSelector} from './../editor/editor-selector'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {isPointAfterSelection} from './selector.is-point-after-selection'\nimport {isPointBeforeSelection} from './selector.is-point-before-selection'\n\n/**\n * @public\n */\nexport function isOverlappingSelection(\n selection: EditorSelection,\n): EditorSelector<boolean> {\n return ({context}) => {\n if (!selection || !context.selection) {\n return false\n }\n\n const selectionStartPoint = getSelectionStartPoint({\n context: {\n ...context,\n selection,\n },\n })\n const selectionEndPoint = getSelectionEndPoint({\n context: {\n ...context,\n selection,\n },\n })\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return false\n }\n\n if (!isPointAfterSelection(selectionStartPoint)({context})) {\n return false\n }\n\n if (!isPointBeforeSelection(selectionEndPoint)({context})) {\n return false\n }\n\n return true\n }\n}\n"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getSelectedSlice","sliceBlocks","blocks","value","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","path","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before","isOverlappingSelection","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint"],"mappings":";;;;;;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,iBAAiBN,QAAQ;AAE/C,SAAIK,cAAcE,WAAW,IACpB,KAGiBJ,eAAeK,QAASC,CAChDC,UAAAA,wBAAwBD,MAAME,IAAI,IAAKF,MAAME,KAAKC,YAAY,CAAM,IAAA,CACtE,CAAA,EAEyBC,OAAQC,CAAAA,YAC/BT,cAAcU,KAAMC,CAAAA,SAASA,KAAKL,KAAKM,OAAOC,SAASJ,QAAQK,IAAI,CAAC,CACtE;AACF,GCtBaC,mBAA6DA,CAAC;AAAA,EACzEnB;AACF,MACSoB,YAAY;AAAA,EAACC,QAAQrB,QAAQsB;AAAAA,EAAOrB,WAAWD,QAAQC;AAAS,CAAC,GCL7DsB,eAAgDA,CAAC;AAAA,EAACvB;AAAO,MAC7DA,QAAQC,WCAJuB,WAAqDA,CAAC;AAAA,EACjExB;AACF,MACSA,QAAQsB;ACDV,SAASG,sBACdC,OACyB;AACzB,SAAQ3B,CAAa,aAAA;AACf,QAAA,CAACA,SAASC,QAAQC;AACb,aAAA;AAGT,UAAMA,YAAY0B,iBAAiB5B,SAASC,QAAQC,SAAS,GAEvD2B,gBAAgBC,aAAaH,MAAMI,KAAK,CAAC,CAAC,IAC5CJ,MAAMI,KAAK,CAAC,EAAEZ,OACda,QACEC,gBAAgBH,aAAaH,MAAMI,KAAK,C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AACvB,sBAAsBqB,mBAAmB,EAAE;AAAA,MAAC9C;AAAAA,IAAAA,CAAQ,KAIrD,CAACwC,uBAAuBQ,iBAAiB,EAAE;AAAA,MAAChD;AAAAA,IAAAA,CAAQ;AAAA,EAK1D;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts","../../src/selectors/selector.is-overlapping-selection.ts"],"sourcesContent":["import {isPortableTextTextBlock, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return []\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n selectedSpans.some((span) => span.node.marks?.includes(markDef._key)),\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: utils.BlockOffset; end: utils.BlockOffset} | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionEndPoint = getSelectionEndPoint({context})\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\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 context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import type {EditorSelection, EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = ({context}) => {\n return context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return context.value\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const endBlockKey = isKeySegment(selection.focus.path[0])\n ? selection.focus.path[0]._key\n : undefined\n const endChildKey = isKeySegment(selection.focus.path[2])\n ? selection.focus.path[2]._key\n : undefined\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n let after = false\n\n for (const block of snapshot.context.value) {\n if (block._key === endBlockKey) {\n if (block._key !== pointBlockKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !endChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (child._key !== pointChildKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this child\n\n after = point.offset > selection.focus.offset\n break\n }\n\n if (child._key === pointChildKey) {\n break\n }\n }\n }\n\n if (block._key === pointBlockKey) {\n break\n }\n }\n\n return after\n }\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const startBlockKey = isKeySegment(selection.anchor.path[0])\n ? selection.anchor.path[0]._key\n : undefined\n const startChildKey = isKeySegment(selection.anchor.path[2])\n ? selection.anchor.path[2]._key\n : undefined\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n let before = false\n\n for (const block of snapshot.context.value) {\n if (block._key === pointBlockKey) {\n if (block._key !== startBlockKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !startChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === pointChildKey) {\n if (child._key !== startChildKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this child\n\n before = point.offset < selection.anchor.offset\n break\n }\n\n if (child._key === startChildKey) {\n break\n }\n }\n }\n\n if (block._key === startBlockKey) {\n break\n }\n }\n\n return before\n }\n}\n","import type {EditorSelection} from '../types/editor'\nimport type {EditorSelector} from './../editor/editor-selector'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {isPointAfterSelection} from './selector.is-point-after-selection'\nimport {isPointBeforeSelection} from './selector.is-point-before-selection'\n\n/**\n * @public\n */\nexport function isOverlappingSelection(\n selection: EditorSelection,\n): EditorSelector<boolean> {\n return ({context}) => {\n if (!selection || !context.selection) {\n return false\n }\n\n const selectionStartPoint = getSelectionStartPoint({\n context: {\n ...context,\n selection,\n },\n })\n const selectionEndPoint = getSelectionEndPoint({\n context: {\n ...context,\n selection,\n },\n })\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return false\n }\n\n if (!isPointAfterSelection(selectionStartPoint)({context})) {\n return false\n }\n\n if (!isPointBeforeSelection(selectionEndPoint)({context})) {\n return false\n }\n\n return true\n }\n}\n"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","value","selectionPoint","end","undefined","getSelectedSlice","sliceBlocks","blocks","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","path","pointChildKey","endBlockKey","focus","endChildKey","after","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before","isOverlappingSelection"],"mappings":";;;;;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,iBAAiBN,QAAQ;AAE/C,SAAIK,cAAcE,WAAW,IACpB,KAGiBJ,eAAeK,QAASC,CAChDC,UAAAA,wBAAwBD,MAAME,IAAI,IAAKF,MAAME,KAAKC,YAAY,CAAM,IAAA,CACtE,CAAA,EAEyBC,OAAQC,CAAAA,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