@portabletext/editor 1.53.0 → 1.54.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/selection-point.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +144 -6
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +6 -140
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
- package/lib/_chunks-es/selection-point.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +148 -10
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +6 -140
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +68 -9
- package/lib/behaviors/index.d.ts +68 -9
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +553 -313
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +69 -13
- package/lib/index.d.ts +69 -13
- package/lib/index.js +534 -294
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +69 -9
- package/lib/plugins/index.d.ts +69 -9
- package/lib/selectors/index.cjs +10 -10
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +42 -27
- package/lib/selectors/index.d.ts +42 -27
- package/lib/selectors/index.js +4 -4
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +27 -5
- package/lib/utils/index.d.ts +27 -5
- package/package.json +14 -14
- package/src/behaviors/behavior.abstract.annotation.ts +51 -0
- package/src/behaviors/behavior.abstract.delete.ts +55 -0
- package/src/behaviors/behavior.perform-event.ts +6 -15
- package/src/behaviors/behavior.types.action.ts +1 -1
- package/src/behaviors/behavior.types.event.ts +32 -8
- package/src/behaviors/behavior.types.guard.ts +1 -1
- package/src/editor/Editable.tsx +3 -0
- package/src/editor/PortableTextEditor.tsx +1 -6
- package/src/editor/create-editor.ts +5 -0
- package/src/{internal-utils/selection-elements.ts → editor/editor-dom.ts} +29 -21
- package/src/editor/editor-provider.tsx +1 -6
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +6 -46
- package/src/editor/plugins/createWithPatches.ts +1 -5
- package/src/editor.ts +2 -0
- package/src/index.ts +2 -0
- package/src/operations/behavior.operation.child.set.ts +103 -0
- package/src/operations/behavior.operation.child.unset.ts +89 -0
- package/src/operations/behavior.operations.ts +18 -0
- package/src/selectors/index.ts +13 -1
- package/src/selectors/selector.get-active-annotations.ts +2 -1
- package/src/selectors/selector.get-active-list-item.ts +1 -1
- package/src/selectors/selector.get-active-style.ts +1 -1
- package/src/selectors/selector.get-anchor-block.ts +3 -2
- package/src/selectors/selector.get-anchor-child.ts +2 -2
- package/src/selectors/selector.get-anchor-span.ts +2 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -2
- package/src/selectors/selector.get-caret-word-selection.ts +1 -1
- package/src/selectors/selector.get-first-block.ts +14 -0
- package/src/selectors/selector.get-focus-block-object.ts +18 -0
- package/src/selectors/selector.get-focus-block.ts +23 -0
- package/src/selectors/selector.get-focus-child.ts +36 -0
- package/src/selectors/selector.get-focus-inline-object.ts +4 -8
- package/src/selectors/selector.get-focus-list-block.ts +18 -0
- package/src/selectors/selector.get-focus-span.ts +18 -0
- package/src/selectors/selector.get-focus-text-block.ts +18 -0
- package/src/selectors/selector.get-last-block.ts +16 -0
- package/src/selectors/selector.get-list-state.ts +2 -1
- package/src/selectors/selector.get-next-block.ts +38 -0
- package/src/selectors/selector.get-next-inline-object.ts +5 -8
- package/src/selectors/selector.get-previous-block.ts +35 -0
- package/src/selectors/selector.get-previous-inline-object.ts +5 -8
- package/src/selectors/selector.get-selected-blocks.ts +49 -0
- package/src/selectors/selector.get-selected-spans.test.ts +96 -0
- package/src/selectors/selector.get-selected-spans.ts +4 -3
- package/src/selectors/selector.get-selected-text-blocks.ts +4 -3
- package/src/selectors/selector.get-selection-end-block.ts +4 -1
- package/src/selectors/selector.get-selection-start-block.ts +4 -1
- package/src/selectors/selector.get-text-before.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.ts +1 -1
- package/src/selectors/selector.is-active-annotation.ts +1 -1
- package/src/selectors/selector.is-at-the-end-of-block.ts +3 -2
- package/src/selectors/selector.is-at-the-start-of-block.ts +3 -2
- package/src/selectors/selector.is-selecting-entire-blocks.ts +2 -1
- package/src/types/block-offset.ts +2 -2
- package/src/types/paths.ts +13 -0
- package/src/utils/util.block-offset.ts +2 -4
- package/src/utils/util.get-block-end-point.ts +3 -2
- package/src/utils/util.get-block-start-point.ts +3 -2
- package/src/selectors/selectors.ts +0 -299
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {KeyedSegment as KeyedSegment_2} from '@portabletext/patches'
|
|
2
|
-
import {KeyedSegment, PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
3
1
|
import type {
|
|
4
2
|
Path,
|
|
5
3
|
PortableTextBlock,
|
|
6
4
|
PortableTextListBlock,
|
|
7
5
|
PortableTextTextBlock,
|
|
8
6
|
} from '@sanity/types'
|
|
7
|
+
import {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* @public
|
|
@@ -19,16 +18,32 @@ declare type BaseDefinition = {
|
|
|
19
18
|
* @beta
|
|
20
19
|
*/
|
|
21
20
|
declare type BlockOffset = {
|
|
22
|
-
path:
|
|
21
|
+
path: BlockPath
|
|
23
22
|
offset: number
|
|
24
23
|
}
|
|
25
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
26
28
|
declare type BlockPath = [
|
|
27
29
|
{
|
|
28
30
|
_key: string
|
|
29
31
|
},
|
|
30
32
|
]
|
|
31
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
declare type ChildPath = [
|
|
38
|
+
{
|
|
39
|
+
_key: string
|
|
40
|
+
},
|
|
41
|
+
'children',
|
|
42
|
+
{
|
|
43
|
+
_key: string
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
|
|
32
47
|
declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
|
|
33
48
|
mimeType: TMIMEType
|
|
34
49
|
serialize: Serializer<TMIMEType>
|
|
@@ -214,7 +229,7 @@ export declare const getActiveStyle: EditorSelector<
|
|
|
214
229
|
export declare const getAnchorBlock: EditorSelector<
|
|
215
230
|
| {
|
|
216
231
|
node: PortableTextBlock
|
|
217
|
-
path:
|
|
232
|
+
path: BlockPath
|
|
218
233
|
}
|
|
219
234
|
| undefined
|
|
220
235
|
>
|
|
@@ -225,7 +240,7 @@ export declare const getAnchorBlock: EditorSelector<
|
|
|
225
240
|
export declare const getAnchorChild: EditorSelector<
|
|
226
241
|
| {
|
|
227
242
|
node: PortableTextObject | PortableTextSpan
|
|
228
|
-
path:
|
|
243
|
+
path: ChildPath
|
|
229
244
|
}
|
|
230
245
|
| undefined
|
|
231
246
|
>
|
|
@@ -236,7 +251,7 @@ export declare const getAnchorChild: EditorSelector<
|
|
|
236
251
|
export declare const getAnchorSpan: EditorSelector<
|
|
237
252
|
| {
|
|
238
253
|
node: PortableTextSpan
|
|
239
|
-
path:
|
|
254
|
+
path: ChildPath
|
|
240
255
|
}
|
|
241
256
|
| undefined
|
|
242
257
|
>
|
|
@@ -247,7 +262,7 @@ export declare const getAnchorSpan: EditorSelector<
|
|
|
247
262
|
export declare const getAnchorTextBlock: EditorSelector<
|
|
248
263
|
| {
|
|
249
264
|
node: PortableTextTextBlock
|
|
250
|
-
path:
|
|
265
|
+
path: BlockPath
|
|
251
266
|
}
|
|
252
267
|
| undefined
|
|
253
268
|
>
|
|
@@ -281,7 +296,7 @@ export declare const getCaretWordSelection: EditorSelector<EditorSelection>
|
|
|
281
296
|
export declare const getFirstBlock: EditorSelector<
|
|
282
297
|
| {
|
|
283
298
|
node: PortableTextBlock
|
|
284
|
-
path:
|
|
299
|
+
path: BlockPath
|
|
285
300
|
}
|
|
286
301
|
| undefined
|
|
287
302
|
>
|
|
@@ -292,7 +307,7 @@ export declare const getFirstBlock: EditorSelector<
|
|
|
292
307
|
export declare const getFocusBlock: EditorSelector<
|
|
293
308
|
| {
|
|
294
309
|
node: PortableTextBlock
|
|
295
|
-
path:
|
|
310
|
+
path: BlockPath
|
|
296
311
|
}
|
|
297
312
|
| undefined
|
|
298
313
|
>
|
|
@@ -303,7 +318,7 @@ export declare const getFocusBlock: EditorSelector<
|
|
|
303
318
|
export declare const getFocusBlockObject: EditorSelector<
|
|
304
319
|
| {
|
|
305
320
|
node: PortableTextObject
|
|
306
|
-
path:
|
|
321
|
+
path: BlockPath
|
|
307
322
|
}
|
|
308
323
|
| undefined
|
|
309
324
|
>
|
|
@@ -314,7 +329,7 @@ export declare const getFocusBlockObject: EditorSelector<
|
|
|
314
329
|
export declare const getFocusChild: EditorSelector<
|
|
315
330
|
| {
|
|
316
331
|
node: PortableTextObject | PortableTextSpan
|
|
317
|
-
path:
|
|
332
|
+
path: ChildPath
|
|
318
333
|
}
|
|
319
334
|
| undefined
|
|
320
335
|
>
|
|
@@ -325,7 +340,7 @@ export declare const getFocusChild: EditorSelector<
|
|
|
325
340
|
export declare const getFocusInlineObject: EditorSelector<
|
|
326
341
|
| {
|
|
327
342
|
node: PortableTextObject
|
|
328
|
-
path:
|
|
343
|
+
path: ChildPath
|
|
329
344
|
}
|
|
330
345
|
| undefined
|
|
331
346
|
>
|
|
@@ -336,7 +351,7 @@ export declare const getFocusInlineObject: EditorSelector<
|
|
|
336
351
|
export declare const getFocusListBlock: EditorSelector<
|
|
337
352
|
| {
|
|
338
353
|
node: PortableTextListBlock
|
|
339
|
-
path:
|
|
354
|
+
path: BlockPath
|
|
340
355
|
}
|
|
341
356
|
| undefined
|
|
342
357
|
>
|
|
@@ -347,7 +362,7 @@ export declare const getFocusListBlock: EditorSelector<
|
|
|
347
362
|
export declare const getFocusSpan: EditorSelector<
|
|
348
363
|
| {
|
|
349
364
|
node: PortableTextSpan
|
|
350
|
-
path:
|
|
365
|
+
path: ChildPath
|
|
351
366
|
}
|
|
352
367
|
| undefined
|
|
353
368
|
>
|
|
@@ -358,7 +373,7 @@ export declare const getFocusSpan: EditorSelector<
|
|
|
358
373
|
export declare const getFocusTextBlock: EditorSelector<
|
|
359
374
|
| {
|
|
360
375
|
node: PortableTextTextBlock
|
|
361
|
-
path:
|
|
376
|
+
path: BlockPath
|
|
362
377
|
}
|
|
363
378
|
| undefined
|
|
364
379
|
>
|
|
@@ -369,7 +384,7 @@ export declare const getFocusTextBlock: EditorSelector<
|
|
|
369
384
|
export declare const getLastBlock: EditorSelector<
|
|
370
385
|
| {
|
|
371
386
|
node: PortableTextBlock
|
|
372
|
-
path:
|
|
387
|
+
path: BlockPath
|
|
373
388
|
}
|
|
374
389
|
| undefined
|
|
375
390
|
>
|
|
@@ -391,7 +406,7 @@ export declare function getListIndex({
|
|
|
391
406
|
export declare const getNextBlock: EditorSelector<
|
|
392
407
|
| {
|
|
393
408
|
node: PortableTextBlock
|
|
394
|
-
path:
|
|
409
|
+
path: BlockPath
|
|
395
410
|
}
|
|
396
411
|
| undefined
|
|
397
412
|
>
|
|
@@ -402,7 +417,7 @@ export declare const getNextBlock: EditorSelector<
|
|
|
402
417
|
export declare const getNextInlineObject: EditorSelector<
|
|
403
418
|
| {
|
|
404
419
|
node: PortableTextObject
|
|
405
|
-
path:
|
|
420
|
+
path: ChildPath
|
|
406
421
|
}
|
|
407
422
|
| undefined
|
|
408
423
|
>
|
|
@@ -413,7 +428,7 @@ export declare const getNextInlineObject: EditorSelector<
|
|
|
413
428
|
export declare const getPreviousBlock: EditorSelector<
|
|
414
429
|
| {
|
|
415
430
|
node: PortableTextBlock
|
|
416
|
-
path:
|
|
431
|
+
path: BlockPath
|
|
417
432
|
}
|
|
418
433
|
| undefined
|
|
419
434
|
>
|
|
@@ -424,7 +439,7 @@ export declare const getPreviousBlock: EditorSelector<
|
|
|
424
439
|
export declare const getPreviousInlineObject: EditorSelector<
|
|
425
440
|
| {
|
|
426
441
|
node: PortableTextObject
|
|
427
|
-
path:
|
|
442
|
+
path: ChildPath
|
|
428
443
|
}
|
|
429
444
|
| undefined
|
|
430
445
|
>
|
|
@@ -435,7 +450,7 @@ export declare const getPreviousInlineObject: EditorSelector<
|
|
|
435
450
|
export declare const getSelectedBlocks: EditorSelector<
|
|
436
451
|
Array<{
|
|
437
452
|
node: PortableTextBlock
|
|
438
|
-
path:
|
|
453
|
+
path: BlockPath
|
|
439
454
|
}>
|
|
440
455
|
>
|
|
441
456
|
|
|
@@ -450,7 +465,7 @@ export declare const getSelectedSlice: EditorSelector<Array<PortableTextBlock>>
|
|
|
450
465
|
export declare const getSelectedSpans: EditorSelector<
|
|
451
466
|
Array<{
|
|
452
467
|
node: PortableTextSpan
|
|
453
|
-
path:
|
|
468
|
+
path: ChildPath
|
|
454
469
|
}>
|
|
455
470
|
>
|
|
456
471
|
|
|
@@ -460,7 +475,7 @@ export declare const getSelectedSpans: EditorSelector<
|
|
|
460
475
|
export declare const getSelectedTextBlocks: EditorSelector<
|
|
461
476
|
Array<{
|
|
462
477
|
node: PortableTextTextBlock
|
|
463
|
-
path:
|
|
478
|
+
path: BlockPath
|
|
464
479
|
}>
|
|
465
480
|
>
|
|
466
481
|
|
|
@@ -476,7 +491,7 @@ export {getSelection_2 as getSelection}
|
|
|
476
491
|
export declare const getSelectionEndBlock: EditorSelector<
|
|
477
492
|
| {
|
|
478
493
|
node: PortableTextBlock
|
|
479
|
-
path:
|
|
494
|
+
path: BlockPath
|
|
480
495
|
}
|
|
481
496
|
| undefined
|
|
482
497
|
>
|
|
@@ -494,7 +509,7 @@ export declare const getSelectionEndPoint: EditorSelector<
|
|
|
494
509
|
export declare const getSelectionStartBlock: EditorSelector<
|
|
495
510
|
| {
|
|
496
511
|
node: PortableTextBlock
|
|
497
|
-
path:
|
|
512
|
+
path: BlockPath
|
|
498
513
|
}
|
|
499
514
|
| undefined
|
|
500
515
|
>
|
|
@@ -552,7 +567,7 @@ export declare function isActiveStyle(style: string): EditorSelector<boolean>
|
|
|
552
567
|
*/
|
|
553
568
|
export declare function isAtTheEndOfBlock(block: {
|
|
554
569
|
node: PortableTextBlock
|
|
555
|
-
path:
|
|
570
|
+
path: BlockPath
|
|
556
571
|
}): EditorSelector<boolean>
|
|
557
572
|
|
|
558
573
|
/**
|
|
@@ -560,7 +575,7 @@ export declare function isAtTheEndOfBlock(block: {
|
|
|
560
575
|
*/
|
|
561
576
|
export declare function isAtTheStartOfBlock(block: {
|
|
562
577
|
node: PortableTextBlock
|
|
563
|
-
path:
|
|
578
|
+
path: BlockPath
|
|
564
579
|
}): EditorSelector<boolean>
|
|
565
580
|
|
|
566
581
|
/**
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {KeyedSegment as KeyedSegment_2} from '@portabletext/patches'
|
|
2
|
-
import {KeyedSegment, PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
3
1
|
import type {
|
|
4
2
|
Path,
|
|
5
3
|
PortableTextBlock,
|
|
6
4
|
PortableTextListBlock,
|
|
7
5
|
PortableTextTextBlock,
|
|
8
6
|
} from '@sanity/types'
|
|
7
|
+
import {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* @public
|
|
@@ -19,16 +18,32 @@ declare type BaseDefinition = {
|
|
|
19
18
|
* @beta
|
|
20
19
|
*/
|
|
21
20
|
declare type BlockOffset = {
|
|
22
|
-
path:
|
|
21
|
+
path: BlockPath
|
|
23
22
|
offset: number
|
|
24
23
|
}
|
|
25
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
26
28
|
declare type BlockPath = [
|
|
27
29
|
{
|
|
28
30
|
_key: string
|
|
29
31
|
},
|
|
30
32
|
]
|
|
31
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
declare type ChildPath = [
|
|
38
|
+
{
|
|
39
|
+
_key: string
|
|
40
|
+
},
|
|
41
|
+
'children',
|
|
42
|
+
{
|
|
43
|
+
_key: string
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
|
|
32
47
|
declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
|
|
33
48
|
mimeType: TMIMEType
|
|
34
49
|
serialize: Serializer<TMIMEType>
|
|
@@ -214,7 +229,7 @@ export declare const getActiveStyle: EditorSelector<
|
|
|
214
229
|
export declare const getAnchorBlock: EditorSelector<
|
|
215
230
|
| {
|
|
216
231
|
node: PortableTextBlock
|
|
217
|
-
path:
|
|
232
|
+
path: BlockPath
|
|
218
233
|
}
|
|
219
234
|
| undefined
|
|
220
235
|
>
|
|
@@ -225,7 +240,7 @@ export declare const getAnchorBlock: EditorSelector<
|
|
|
225
240
|
export declare const getAnchorChild: EditorSelector<
|
|
226
241
|
| {
|
|
227
242
|
node: PortableTextObject | PortableTextSpan
|
|
228
|
-
path:
|
|
243
|
+
path: ChildPath
|
|
229
244
|
}
|
|
230
245
|
| undefined
|
|
231
246
|
>
|
|
@@ -236,7 +251,7 @@ export declare const getAnchorChild: EditorSelector<
|
|
|
236
251
|
export declare const getAnchorSpan: EditorSelector<
|
|
237
252
|
| {
|
|
238
253
|
node: PortableTextSpan
|
|
239
|
-
path:
|
|
254
|
+
path: ChildPath
|
|
240
255
|
}
|
|
241
256
|
| undefined
|
|
242
257
|
>
|
|
@@ -247,7 +262,7 @@ export declare const getAnchorSpan: EditorSelector<
|
|
|
247
262
|
export declare const getAnchorTextBlock: EditorSelector<
|
|
248
263
|
| {
|
|
249
264
|
node: PortableTextTextBlock
|
|
250
|
-
path:
|
|
265
|
+
path: BlockPath
|
|
251
266
|
}
|
|
252
267
|
| undefined
|
|
253
268
|
>
|
|
@@ -281,7 +296,7 @@ export declare const getCaretWordSelection: EditorSelector<EditorSelection>
|
|
|
281
296
|
export declare const getFirstBlock: EditorSelector<
|
|
282
297
|
| {
|
|
283
298
|
node: PortableTextBlock
|
|
284
|
-
path:
|
|
299
|
+
path: BlockPath
|
|
285
300
|
}
|
|
286
301
|
| undefined
|
|
287
302
|
>
|
|
@@ -292,7 +307,7 @@ export declare const getFirstBlock: EditorSelector<
|
|
|
292
307
|
export declare const getFocusBlock: EditorSelector<
|
|
293
308
|
| {
|
|
294
309
|
node: PortableTextBlock
|
|
295
|
-
path:
|
|
310
|
+
path: BlockPath
|
|
296
311
|
}
|
|
297
312
|
| undefined
|
|
298
313
|
>
|
|
@@ -303,7 +318,7 @@ export declare const getFocusBlock: EditorSelector<
|
|
|
303
318
|
export declare const getFocusBlockObject: EditorSelector<
|
|
304
319
|
| {
|
|
305
320
|
node: PortableTextObject
|
|
306
|
-
path:
|
|
321
|
+
path: BlockPath
|
|
307
322
|
}
|
|
308
323
|
| undefined
|
|
309
324
|
>
|
|
@@ -314,7 +329,7 @@ export declare const getFocusBlockObject: EditorSelector<
|
|
|
314
329
|
export declare const getFocusChild: EditorSelector<
|
|
315
330
|
| {
|
|
316
331
|
node: PortableTextObject | PortableTextSpan
|
|
317
|
-
path:
|
|
332
|
+
path: ChildPath
|
|
318
333
|
}
|
|
319
334
|
| undefined
|
|
320
335
|
>
|
|
@@ -325,7 +340,7 @@ export declare const getFocusChild: EditorSelector<
|
|
|
325
340
|
export declare const getFocusInlineObject: EditorSelector<
|
|
326
341
|
| {
|
|
327
342
|
node: PortableTextObject
|
|
328
|
-
path:
|
|
343
|
+
path: ChildPath
|
|
329
344
|
}
|
|
330
345
|
| undefined
|
|
331
346
|
>
|
|
@@ -336,7 +351,7 @@ export declare const getFocusInlineObject: EditorSelector<
|
|
|
336
351
|
export declare const getFocusListBlock: EditorSelector<
|
|
337
352
|
| {
|
|
338
353
|
node: PortableTextListBlock
|
|
339
|
-
path:
|
|
354
|
+
path: BlockPath
|
|
340
355
|
}
|
|
341
356
|
| undefined
|
|
342
357
|
>
|
|
@@ -347,7 +362,7 @@ export declare const getFocusListBlock: EditorSelector<
|
|
|
347
362
|
export declare const getFocusSpan: EditorSelector<
|
|
348
363
|
| {
|
|
349
364
|
node: PortableTextSpan
|
|
350
|
-
path:
|
|
365
|
+
path: ChildPath
|
|
351
366
|
}
|
|
352
367
|
| undefined
|
|
353
368
|
>
|
|
@@ -358,7 +373,7 @@ export declare const getFocusSpan: EditorSelector<
|
|
|
358
373
|
export declare const getFocusTextBlock: EditorSelector<
|
|
359
374
|
| {
|
|
360
375
|
node: PortableTextTextBlock
|
|
361
|
-
path:
|
|
376
|
+
path: BlockPath
|
|
362
377
|
}
|
|
363
378
|
| undefined
|
|
364
379
|
>
|
|
@@ -369,7 +384,7 @@ export declare const getFocusTextBlock: EditorSelector<
|
|
|
369
384
|
export declare const getLastBlock: EditorSelector<
|
|
370
385
|
| {
|
|
371
386
|
node: PortableTextBlock
|
|
372
|
-
path:
|
|
387
|
+
path: BlockPath
|
|
373
388
|
}
|
|
374
389
|
| undefined
|
|
375
390
|
>
|
|
@@ -391,7 +406,7 @@ export declare function getListIndex({
|
|
|
391
406
|
export declare const getNextBlock: EditorSelector<
|
|
392
407
|
| {
|
|
393
408
|
node: PortableTextBlock
|
|
394
|
-
path:
|
|
409
|
+
path: BlockPath
|
|
395
410
|
}
|
|
396
411
|
| undefined
|
|
397
412
|
>
|
|
@@ -402,7 +417,7 @@ export declare const getNextBlock: EditorSelector<
|
|
|
402
417
|
export declare const getNextInlineObject: EditorSelector<
|
|
403
418
|
| {
|
|
404
419
|
node: PortableTextObject
|
|
405
|
-
path:
|
|
420
|
+
path: ChildPath
|
|
406
421
|
}
|
|
407
422
|
| undefined
|
|
408
423
|
>
|
|
@@ -413,7 +428,7 @@ export declare const getNextInlineObject: EditorSelector<
|
|
|
413
428
|
export declare const getPreviousBlock: EditorSelector<
|
|
414
429
|
| {
|
|
415
430
|
node: PortableTextBlock
|
|
416
|
-
path:
|
|
431
|
+
path: BlockPath
|
|
417
432
|
}
|
|
418
433
|
| undefined
|
|
419
434
|
>
|
|
@@ -424,7 +439,7 @@ export declare const getPreviousBlock: EditorSelector<
|
|
|
424
439
|
export declare const getPreviousInlineObject: EditorSelector<
|
|
425
440
|
| {
|
|
426
441
|
node: PortableTextObject
|
|
427
|
-
path:
|
|
442
|
+
path: ChildPath
|
|
428
443
|
}
|
|
429
444
|
| undefined
|
|
430
445
|
>
|
|
@@ -435,7 +450,7 @@ export declare const getPreviousInlineObject: EditorSelector<
|
|
|
435
450
|
export declare const getSelectedBlocks: EditorSelector<
|
|
436
451
|
Array<{
|
|
437
452
|
node: PortableTextBlock
|
|
438
|
-
path:
|
|
453
|
+
path: BlockPath
|
|
439
454
|
}>
|
|
440
455
|
>
|
|
441
456
|
|
|
@@ -450,7 +465,7 @@ export declare const getSelectedSlice: EditorSelector<Array<PortableTextBlock>>
|
|
|
450
465
|
export declare const getSelectedSpans: EditorSelector<
|
|
451
466
|
Array<{
|
|
452
467
|
node: PortableTextSpan
|
|
453
|
-
path:
|
|
468
|
+
path: ChildPath
|
|
454
469
|
}>
|
|
455
470
|
>
|
|
456
471
|
|
|
@@ -460,7 +475,7 @@ export declare const getSelectedSpans: EditorSelector<
|
|
|
460
475
|
export declare const getSelectedTextBlocks: EditorSelector<
|
|
461
476
|
Array<{
|
|
462
477
|
node: PortableTextTextBlock
|
|
463
|
-
path:
|
|
478
|
+
path: BlockPath
|
|
464
479
|
}>
|
|
465
480
|
>
|
|
466
481
|
|
|
@@ -476,7 +491,7 @@ export {getSelection_2 as getSelection}
|
|
|
476
491
|
export declare const getSelectionEndBlock: EditorSelector<
|
|
477
492
|
| {
|
|
478
493
|
node: PortableTextBlock
|
|
479
|
-
path:
|
|
494
|
+
path: BlockPath
|
|
480
495
|
}
|
|
481
496
|
| undefined
|
|
482
497
|
>
|
|
@@ -494,7 +509,7 @@ export declare const getSelectionEndPoint: EditorSelector<
|
|
|
494
509
|
export declare const getSelectionStartBlock: EditorSelector<
|
|
495
510
|
| {
|
|
496
511
|
node: PortableTextBlock
|
|
497
|
-
path:
|
|
512
|
+
path: BlockPath
|
|
498
513
|
}
|
|
499
514
|
| undefined
|
|
500
515
|
>
|
|
@@ -552,7 +567,7 @@ export declare function isActiveStyle(style: string): EditorSelector<boolean>
|
|
|
552
567
|
*/
|
|
553
568
|
export declare function isAtTheEndOfBlock(block: {
|
|
554
569
|
node: PortableTextBlock
|
|
555
|
-
path:
|
|
570
|
+
path: BlockPath
|
|
556
571
|
}): EditorSelector<boolean>
|
|
557
572
|
|
|
558
573
|
/**
|
|
@@ -560,7 +575,7 @@ export declare function isAtTheEndOfBlock(block: {
|
|
|
560
575
|
*/
|
|
561
576
|
export declare function isAtTheStartOfBlock(block: {
|
|
562
577
|
node: PortableTextBlock
|
|
563
|
-
path:
|
|
578
|
+
path: BlockPath
|
|
564
579
|
}): EditorSelector<boolean>
|
|
565
580
|
|
|
566
581
|
/**
|
package/lib/selectors/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { getSelectionEndPoint } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
2
|
-
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFocusInlineObject, getNextInlineObject, getSelectedSpans, getSelectedTextBlocks, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
1
|
+
import { getSelectionEndPoint, getPreviousBlock } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
2
|
+
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getNextBlock, getNextInlineObject, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
3
3
|
import { getBlockKeyFromSelectionPoint, isTextBlock, getChildKeyFromSelectionPoint, spanSelectionPointToBlockOffset } from "../_chunks-es/selection-point.js";
|
|
4
4
|
import { isPortableTextSpan } from "@sanity/types";
|
|
5
|
-
import { getSelectionStartPoint, getFocusTextBlock
|
|
6
|
-
import {
|
|
5
|
+
import { getSelectionStartPoint, getFocusTextBlock } from "../_chunks-es/selector.is-selection-expanded.js";
|
|
6
|
+
import { getFocusBlock, getFocusChild, getFocusSpan, getPreviousInlineObject, getSelectedSlice, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
|
|
7
7
|
import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
|
|
8
8
|
const getAnchorBlock = (snapshot) => {
|
|
9
9
|
if (!snapshot.context.selection)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\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: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock, getPreviousBlock} from './selectors'\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return 1\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return 1\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return 1\n }\n\n const previousListItemListState = getListIndex({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return 1\n }\n\n return previousListItemListState + 1\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","node","value","find","block","_key","undefined","path","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","previousListItemListState","previousBlock","getPreviousBlock","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GAErEC,OAAOH,MACTH,SAASC,QAAQM,MAAMC,KAAMC,WAAUA,MAAMC,SAASP,GAAG,IACzDQ;AAEJ,SAAOL,QAAQH,MAAM;AAAA,IAACG;AAAAA,IAAMM,MAAM,CAAC;AAAA,MAACF,MAAMP;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKQ;AACrD,GCbaE,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASC,SAASa,YAAYR,IAAI,IAChE;AAAA,IAACA,MAAMQ,YAAYR;AAAAA,IAAMM,MAAME,YAAYF;AAAAA,EAAAA,IAC3CD;AACN,GCPaK,iBAMRhB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGIY,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMX,MAAMc,8BAA8BjB,SAASC,QAAQC,UAAU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gC,QAAQA;AAI/B,eAAOE,oBAAoB;AAAA,UACzBH;AAAAA,UACAC;AAAAA,QAAAA,CACD,EAAE;AAAA,UACD,GAAGtC;AAAAA,UACHC,SAAS;AAAA,YACP,GAAGD,SAASC;AAAAA,YACZC,WAAW;AAAA,cACTG,QAAQ;AAAA,gBACNO,MAAM8B,cAAc9B;AAAAA,gBACpBqB,QAAQ;AAAA,cACV;AAAA,cACAC,OAAO;AAAA,gBACLtB,MAAM8B,cAAc9B;AAAAA,gBACpBqB,QAAQ;AAAA,cAAA;AAAA,YACV;AAAA,UACF;AAAA,QACF,CACD;AAAA,IAAA;AAAA,EACH;AACF;ACtJaW,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQM;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\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: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getPreviousBlock} from './selector.get-previous-block'\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return 1\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return 1\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return 1\n }\n\n const previousListItemListState = getListIndex({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return 1\n }\n\n return previousListItemListState + 1\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","node","value","find","block","_key","undefined","path","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","previousListItemListState","previousBlock","getPreviousBlock","getSelection","getValue"],"mappings":";;;;;;;AAQO,MAAMA,iBAERC,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GAErEC,OAAOH,MACTH,SAASC,QAAQM,MAAMC,KAAMC,WAAUA,MAAMC,SAASP,GAAG,IACzDQ;AAEJ,SAAOL,QAAQH,MAAM;AAAA,IAACG;AAAAA,IAAMM,MAAM,CAAC;AAAA,MAACF,MAAMP;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKQ;AACrD,GCbaE,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASC,SAASa,YAAYR,IAAI,IAChE;AAAA,IAACA,MAAMQ,YAAYR;AAAAA,IAAMM,MAAME,YAAYF;AAAAA,EAAAA,IAC3CD;AACN,GCRaK,iBAMRhB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGIY,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMX,MAAMc,8BAA8BjB,SAASC,QAAQC,UAAUG,MAAM,GAErEC,OAAOH,MACTW,YAAYR,KAAKY,SAASV,KAAMW,UAASA,KAAKT,SAASP,GAAG,IAC1DQ;AAEJ,SAAOL,QAAQH,MACX;AAAA,IAACG;AAAAA,IAAMM,MAAM,CAAC,GAAGE,YAAYF,MAAM,YAAY;AAAA,MAACF,MAAMP;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DQ;AACN,GC3BaS,gBAERpB,CAAa,aAAA;AACVqB,QAAAA,cAAcL,eAAehB,QAAQ;AAE3C,SAAOqB,eAAeC,mBAAmBD,YAAYf,IAAI,IACrD;AAAA,IAACA,MAAMe,YAAYf;AAAAA,IAAMM,M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W,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQM;"}
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -19,7 +19,7 @@ declare type BaseDefinition = {
|
|
|
19
19
|
* @beta
|
|
20
20
|
*/
|
|
21
21
|
declare type BlockOffset = {
|
|
22
|
-
path:
|
|
22
|
+
path: BlockPath
|
|
23
23
|
offset: number
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -76,11 +76,33 @@ export declare function blockOffsetToSpanSelectionPoint({
|
|
|
76
76
|
direction: 'forward' | 'backward'
|
|
77
77
|
}):
|
|
78
78
|
| {
|
|
79
|
-
path:
|
|
79
|
+
path: ChildPath
|
|
80
80
|
offset: number
|
|
81
81
|
}
|
|
82
82
|
| undefined
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
declare type BlockPath = [
|
|
88
|
+
{
|
|
89
|
+
_key: string
|
|
90
|
+
},
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
declare type ChildPath = [
|
|
97
|
+
{
|
|
98
|
+
_key: string
|
|
99
|
+
},
|
|
100
|
+
'children',
|
|
101
|
+
{
|
|
102
|
+
_key: string
|
|
103
|
+
},
|
|
104
|
+
]
|
|
105
|
+
|
|
84
106
|
/**
|
|
85
107
|
* @public
|
|
86
108
|
*/
|
|
@@ -255,7 +277,7 @@ export declare function getBlockEndPoint({
|
|
|
255
277
|
context: Pick<EditorContext, 'schema'>
|
|
256
278
|
block: {
|
|
257
279
|
node: PortableTextBlock
|
|
258
|
-
path:
|
|
280
|
+
path: BlockPath
|
|
259
281
|
}
|
|
260
282
|
}): EditorSelectionPoint
|
|
261
283
|
|
|
@@ -269,7 +291,7 @@ export declare function getBlockStartPoint({
|
|
|
269
291
|
context: Pick<EditorContext, 'schema'>
|
|
270
292
|
block: {
|
|
271
293
|
node: PortableTextBlock
|
|
272
|
-
path:
|
|
294
|
+
path: BlockPath
|
|
273
295
|
}
|
|
274
296
|
}): EditorSelectionPoint
|
|
275
297
|
|
|
@@ -365,7 +387,7 @@ export declare function mergeTextBlocks({
|
|
|
365
387
|
context: Pick<EditorContext, 'keyGenerator' | 'schema'>
|
|
366
388
|
targetBlock: PortableTextTextBlock
|
|
367
389
|
incomingBlock: PortableTextTextBlock
|
|
368
|
-
}): PortableTextTextBlock<
|
|
390
|
+
}): PortableTextTextBlock<PortableTextSpan | PortableTextObject>
|
|
369
391
|
|
|
370
392
|
declare type MIMEType = `${string}/${string}`
|
|
371
393
|
|