@portabletext/editor 1.34.1 → 1.35.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 +57 -118
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +27 -67
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/plugin.event-listener.cjs +53 -67
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +5 -7
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +22 -36
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +68 -153
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +57 -118
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +27 -67
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +53 -67
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +5 -7
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +22 -36
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +68 -153
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.cjs +18 -48
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +24 -13
- package/lib/behaviors/index.d.ts +24 -13
- package/lib/behaviors/index.js +18 -48
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.d.cts +16 -12
- package/lib/index.d.ts +16 -12
- package/lib/plugins/index.cjs +182 -186
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +31 -23
- package/lib/plugins/index.d.ts +31 -23
- package/lib/plugins/index.js +182 -186
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +22 -50
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +6 -198
- package/lib/selectors/index.d.ts +6 -198
- package/lib/selectors/index.js +22 -50
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +12 -5
- package/lib/utils/index.d.ts +12 -5
- package/lib/utils/index.js.map +1 -1
- package/package.json +7 -7
- package/src/behaviors/behavior.code-editor.ts +6 -6
- package/src/behaviors/behavior.core.annotations.ts +5 -4
- package/src/behaviors/behavior.core.block-objects.ts +17 -17
- package/src/behaviors/behavior.core.decorators.ts +12 -8
- package/src/behaviors/behavior.core.insert-break.ts +27 -29
- package/src/behaviors/behavior.core.lists.ts +19 -19
- package/src/behaviors/behavior.decorator-pair.ts +200 -0
- package/src/behaviors/behavior.default.ts +35 -30
- package/src/behaviors/behavior.emoji-picker.ts +12 -12
- package/src/behaviors/behavior.links.ts +7 -7
- package/src/behaviors/behavior.markdown.ts +41 -42
- package/src/behaviors/behavior.types.ts +14 -17
- package/src/behaviors/index.ts +0 -1
- package/src/converters/converter.json.ts +6 -6
- package/src/converters/converter.portable-text.deserialize.test.ts +28 -26
- package/src/converters/converter.portable-text.ts +6 -6
- package/src/converters/converter.text-html.deserialize.test.ts +17 -15
- package/src/converters/converter.text-html.serialize.test.ts +57 -53
- package/src/converters/converter.text-html.ts +14 -10
- package/src/converters/converter.text-plain.test.ts +17 -15
- package/src/converters/converter.text-plain.ts +15 -11
- package/src/converters/converter.types.ts +5 -5
- package/src/editor/editor-machine.ts +6 -1
- package/src/index.ts +3 -3
- package/src/internal-utils/get-text-to-emphasize.ts +29 -7
- package/src/plugins/plugin.decorator-shortcut.ts +235 -0
- package/src/plugins/plugin.markdown.tsx +56 -8
- package/src/plugins/plugin.one-line.tsx +17 -17
- package/src/selectors/selector.get-active-list-item.ts +4 -4
- package/src/selectors/selector.get-active-style.ts +6 -6
- package/src/selectors/selector.get-anchor-block.ts +5 -5
- package/src/selectors/selector.get-anchor-child.ts +5 -5
- package/src/selectors/selector.get-anchor-span.ts +2 -2
- package/src/selectors/selector.get-anchor-text-block.ts +2 -2
- package/src/selectors/selector.get-block-offsets.ts +8 -7
- package/src/selectors/selector.get-caret-word-selection.ts +19 -16
- package/src/selectors/selector.get-next-inline-object.ts +4 -4
- package/src/selectors/selector.get-previous-inline-object.ts +4 -4
- package/src/selectors/selector.get-selected-slice.ts +7 -4
- package/src/selectors/selector.get-selected-spans.ts +9 -9
- package/src/selectors/selector.get-selection-end-point.ts +5 -5
- package/src/selectors/selector.get-selection-start-point.ts +5 -5
- package/src/selectors/selector.get-selection-text.ts +2 -2
- package/src/selectors/selector.get-selection.ts +2 -2
- package/src/selectors/selector.get-text-before.ts +8 -8
- package/src/selectors/selector.get-trimmed-selection.ts +15 -13
- package/src/selectors/selector.get-value.ts +4 -4
- package/src/selectors/selector.is-at-the-end-of-block.ts +6 -3
- package/src/selectors/selector.is-at-the-start-of-block.ts +3 -3
- package/src/selectors/selector.is-overlapping-selection.ts +8 -6
- package/src/selectors/selector.is-selection-collapsed.ts +6 -5
- package/src/selectors/selector.is-selection-expanded.ts +2 -2
- package/src/selectors/selectors.ts +59 -59
- package/src/types/block-offset.ts +9 -0
- package/src/utils/index.ts +0 -1
- package/src/utils/util.block-offset.ts +1 -1
- package/src/utils/util.block-offsets-to-selection.ts +1 -1
- package/src/utils/util.child-selection-point-to-block-offset.ts +1 -1
- package/src/behaviors/behavior.markdown-emphasis.ts +0 -437
|
@@ -6,8 +6,6 @@ import type {
|
|
|
6
6
|
BlockStyleDefinition,
|
|
7
7
|
ObjectSchemaType,
|
|
8
8
|
Path,
|
|
9
|
-
PathSegment,
|
|
10
|
-
PortableTextChild,
|
|
11
9
|
} from '@sanity/types'
|
|
12
10
|
import {
|
|
13
11
|
KeyedSegment,
|
|
@@ -26,51 +24,6 @@ declare type BlockOffset = {
|
|
|
26
24
|
offset: number
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
/**
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
declare function blockOffsetsToSelection({
|
|
33
|
-
value,
|
|
34
|
-
offsets,
|
|
35
|
-
backward,
|
|
36
|
-
}: {
|
|
37
|
-
value: Array<PortableTextBlock>
|
|
38
|
-
offsets: {
|
|
39
|
-
anchor: BlockOffset
|
|
40
|
-
focus: BlockOffset
|
|
41
|
-
}
|
|
42
|
-
backward?: boolean
|
|
43
|
-
}): EditorSelection
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
declare function blockOffsetToSpanSelectionPoint({
|
|
49
|
-
value,
|
|
50
|
-
blockOffset,
|
|
51
|
-
direction,
|
|
52
|
-
}: {
|
|
53
|
-
value: Array<PortableTextBlock>
|
|
54
|
-
blockOffset: BlockOffset
|
|
55
|
-
direction: 'forward' | 'backward'
|
|
56
|
-
}):
|
|
57
|
-
| {
|
|
58
|
-
path: [KeyedSegment, 'children', KeyedSegment]
|
|
59
|
-
offset: number
|
|
60
|
-
}
|
|
61
|
-
| undefined
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @public
|
|
65
|
-
*/
|
|
66
|
-
declare function childSelectionPointToBlockOffset({
|
|
67
|
-
value,
|
|
68
|
-
selectionPoint,
|
|
69
|
-
}: {
|
|
70
|
-
value: Array<PortableTextBlock>
|
|
71
|
-
selectionPoint: EditorSelectionPoint
|
|
72
|
-
}): BlockOffset | undefined
|
|
73
|
-
|
|
74
27
|
declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
|
|
75
28
|
mimeType: TMIMEType
|
|
76
29
|
serialize: Serializer<TMIMEType>
|
|
@@ -110,10 +63,10 @@ declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
|
|
|
110
63
|
}
|
|
111
64
|
|
|
112
65
|
declare type Deserializer<TMIMEType extends MIMEType> = ({
|
|
113
|
-
|
|
66
|
+
snapshot,
|
|
114
67
|
event,
|
|
115
68
|
}: {
|
|
116
|
-
|
|
69
|
+
snapshot: EditorSnapshot
|
|
117
70
|
event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>
|
|
118
71
|
}) => PickFromUnion<
|
|
119
72
|
ConverterEvent<TMIMEType>,
|
|
@@ -230,39 +183,17 @@ export declare const getAnchorTextBlock: EditorSelector<
|
|
|
230
183
|
| undefined
|
|
231
184
|
>
|
|
232
185
|
|
|
233
|
-
/**
|
|
234
|
-
* @public
|
|
235
|
-
*/
|
|
236
|
-
declare function getBlockEndPoint({
|
|
237
|
-
node,
|
|
238
|
-
path,
|
|
239
|
-
}: {
|
|
240
|
-
node: PortableTextBlock
|
|
241
|
-
path: [KeyedSegment]
|
|
242
|
-
}): EditorSelectionPoint
|
|
243
|
-
|
|
244
186
|
/**
|
|
245
187
|
* @public
|
|
246
188
|
*/
|
|
247
189
|
export declare const getBlockOffsets: EditorSelector<
|
|
248
190
|
| {
|
|
249
|
-
start:
|
|
250
|
-
end:
|
|
191
|
+
start: BlockOffset
|
|
192
|
+
end: BlockOffset
|
|
251
193
|
}
|
|
252
194
|
| undefined
|
|
253
195
|
>
|
|
254
196
|
|
|
255
|
-
/**
|
|
256
|
-
* @public
|
|
257
|
-
*/
|
|
258
|
-
declare function getBlockStartPoint({
|
|
259
|
-
node,
|
|
260
|
-
path,
|
|
261
|
-
}: {
|
|
262
|
-
node: PortableTextBlock
|
|
263
|
-
path: [KeyedSegment]
|
|
264
|
-
}): EditorSelectionPoint
|
|
265
|
-
|
|
266
197
|
/**
|
|
267
198
|
* @public
|
|
268
199
|
*/
|
|
@@ -479,11 +410,6 @@ export declare const getSelectionStartPoint: EditorSelector<
|
|
|
479
410
|
*/
|
|
480
411
|
export declare const getSelectionText: EditorSelector<string>
|
|
481
412
|
|
|
482
|
-
/**
|
|
483
|
-
* @public
|
|
484
|
-
*/
|
|
485
|
-
declare function getTextBlockText(block: PortableTextTextBlock): string
|
|
486
|
-
|
|
487
413
|
/**
|
|
488
414
|
* @public
|
|
489
415
|
*/
|
|
@@ -536,24 +462,6 @@ export declare function isAtTheStartOfBlock(block: {
|
|
|
536
462
|
path: [KeyedSegment]
|
|
537
463
|
}): EditorSelector<boolean>
|
|
538
464
|
|
|
539
|
-
/**
|
|
540
|
-
* @public
|
|
541
|
-
*/
|
|
542
|
-
declare function isEmptyTextBlock(block: PortableTextBlock): boolean
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* @public
|
|
546
|
-
*/
|
|
547
|
-
declare function isEqualSelectionPoints(
|
|
548
|
-
a: EditorSelectionPoint,
|
|
549
|
-
b: EditorSelectionPoint,
|
|
550
|
-
): boolean
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* @public
|
|
554
|
-
*/
|
|
555
|
-
declare function isKeyedSegment(segment: PathSegment): segment is KeyedSegment
|
|
556
|
-
|
|
557
465
|
/**
|
|
558
466
|
* @public
|
|
559
467
|
*/
|
|
@@ -585,35 +493,6 @@ export declare const isSelectionCollapsed: EditorSelector<boolean>
|
|
|
585
493
|
*/
|
|
586
494
|
export declare const isSelectionExpanded: EditorSelector<boolean>
|
|
587
495
|
|
|
588
|
-
/**
|
|
589
|
-
* @public
|
|
590
|
-
*/
|
|
591
|
-
declare function isSpan(
|
|
592
|
-
context: Pick<EditorContext, 'schema'>,
|
|
593
|
-
child: PortableTextChild,
|
|
594
|
-
): child is PortableTextSpan
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* @public
|
|
598
|
-
*/
|
|
599
|
-
declare function isTextBlock(
|
|
600
|
-
context: Pick<EditorContext, 'schema'>,
|
|
601
|
-
block: PortableTextBlock,
|
|
602
|
-
): block is PortableTextTextBlock
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* @beta
|
|
606
|
-
*/
|
|
607
|
-
declare function mergeTextBlocks({
|
|
608
|
-
context,
|
|
609
|
-
targetBlock,
|
|
610
|
-
incomingBlock,
|
|
611
|
-
}: {
|
|
612
|
-
context: Pick<EditorContext, 'keyGenerator' | 'schema'>
|
|
613
|
-
targetBlock: PortableTextTextBlock
|
|
614
|
-
incomingBlock: PortableTextTextBlock
|
|
615
|
-
}): PortableTextTextBlock<PortableTextSpan | PortableTextObject>
|
|
616
|
-
|
|
617
496
|
declare type MIMEType = `${string}/${string}`
|
|
618
497
|
|
|
619
498
|
/**
|
|
@@ -640,18 +519,11 @@ export declare type PortableTextMemberSchemaTypes = {
|
|
|
640
519
|
lists: BlockListDefinition[]
|
|
641
520
|
}
|
|
642
521
|
|
|
643
|
-
/**
|
|
644
|
-
* @public
|
|
645
|
-
*/
|
|
646
|
-
declare function reverseSelection(
|
|
647
|
-
selection: NonNullable<EditorSelection>,
|
|
648
|
-
): NonNullable<EditorSelection>
|
|
649
|
-
|
|
650
522
|
declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
651
|
-
|
|
523
|
+
snapshot,
|
|
652
524
|
event,
|
|
653
525
|
}: {
|
|
654
|
-
|
|
526
|
+
snapshot: EditorSnapshot
|
|
655
527
|
event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>
|
|
656
528
|
}) => PickFromUnion<
|
|
657
529
|
ConverterEvent<TMIMEType>,
|
|
@@ -659,68 +531,4 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
|
659
531
|
'serialization.success' | 'serialization.failure'
|
|
660
532
|
>
|
|
661
533
|
|
|
662
|
-
/**
|
|
663
|
-
* @public
|
|
664
|
-
*/
|
|
665
|
-
declare function sliceBlocks({
|
|
666
|
-
blocks,
|
|
667
|
-
selection,
|
|
668
|
-
}: {
|
|
669
|
-
blocks: Array<PortableTextBlock>
|
|
670
|
-
selection: EditorSelection
|
|
671
|
-
}): Array<PortableTextBlock>
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* @public
|
|
675
|
-
*/
|
|
676
|
-
declare function spanSelectionPointToBlockOffset({
|
|
677
|
-
value,
|
|
678
|
-
selectionPoint,
|
|
679
|
-
}: {
|
|
680
|
-
value: Array<PortableTextBlock>
|
|
681
|
-
selectionPoint: EditorSelectionPoint
|
|
682
|
-
}): BlockOffset | undefined
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* @beta
|
|
686
|
-
*/
|
|
687
|
-
declare function splitTextBlock({
|
|
688
|
-
context,
|
|
689
|
-
block,
|
|
690
|
-
point,
|
|
691
|
-
}: {
|
|
692
|
-
context: Pick<EditorContext, 'schema'>
|
|
693
|
-
block: PortableTextTextBlock
|
|
694
|
-
point: EditorSelectionPoint
|
|
695
|
-
}):
|
|
696
|
-
| {
|
|
697
|
-
before: PortableTextTextBlock
|
|
698
|
-
after: PortableTextTextBlock
|
|
699
|
-
}
|
|
700
|
-
| undefined
|
|
701
|
-
|
|
702
|
-
declare namespace utils {
|
|
703
|
-
export {
|
|
704
|
-
BlockOffset,
|
|
705
|
-
EditorSelection,
|
|
706
|
-
EditorSelectionPoint,
|
|
707
|
-
blockOffsetToSpanSelectionPoint,
|
|
708
|
-
spanSelectionPointToBlockOffset,
|
|
709
|
-
blockOffsetsToSelection,
|
|
710
|
-
childSelectionPointToBlockOffset,
|
|
711
|
-
getBlockEndPoint,
|
|
712
|
-
getBlockStartPoint,
|
|
713
|
-
getTextBlockText,
|
|
714
|
-
isEmptyTextBlock,
|
|
715
|
-
isEqualSelectionPoints,
|
|
716
|
-
isKeyedSegment,
|
|
717
|
-
isSpan,
|
|
718
|
-
isTextBlock,
|
|
719
|
-
mergeTextBlocks,
|
|
720
|
-
reverseSelection,
|
|
721
|
-
sliceBlocks,
|
|
722
|
-
splitTextBlock,
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
|
|
726
534
|
export {}
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -6,8 +6,6 @@ import type {
|
|
|
6
6
|
BlockStyleDefinition,
|
|
7
7
|
ObjectSchemaType,
|
|
8
8
|
Path,
|
|
9
|
-
PathSegment,
|
|
10
|
-
PortableTextChild,
|
|
11
9
|
} from '@sanity/types'
|
|
12
10
|
import {
|
|
13
11
|
KeyedSegment,
|
|
@@ -26,51 +24,6 @@ declare type BlockOffset = {
|
|
|
26
24
|
offset: number
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
/**
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
declare function blockOffsetsToSelection({
|
|
33
|
-
value,
|
|
34
|
-
offsets,
|
|
35
|
-
backward,
|
|
36
|
-
}: {
|
|
37
|
-
value: Array<PortableTextBlock>
|
|
38
|
-
offsets: {
|
|
39
|
-
anchor: BlockOffset
|
|
40
|
-
focus: BlockOffset
|
|
41
|
-
}
|
|
42
|
-
backward?: boolean
|
|
43
|
-
}): EditorSelection
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
declare function blockOffsetToSpanSelectionPoint({
|
|
49
|
-
value,
|
|
50
|
-
blockOffset,
|
|
51
|
-
direction,
|
|
52
|
-
}: {
|
|
53
|
-
value: Array<PortableTextBlock>
|
|
54
|
-
blockOffset: BlockOffset
|
|
55
|
-
direction: 'forward' | 'backward'
|
|
56
|
-
}):
|
|
57
|
-
| {
|
|
58
|
-
path: [KeyedSegment, 'children', KeyedSegment]
|
|
59
|
-
offset: number
|
|
60
|
-
}
|
|
61
|
-
| undefined
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @public
|
|
65
|
-
*/
|
|
66
|
-
declare function childSelectionPointToBlockOffset({
|
|
67
|
-
value,
|
|
68
|
-
selectionPoint,
|
|
69
|
-
}: {
|
|
70
|
-
value: Array<PortableTextBlock>
|
|
71
|
-
selectionPoint: EditorSelectionPoint
|
|
72
|
-
}): BlockOffset | undefined
|
|
73
|
-
|
|
74
27
|
declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
|
|
75
28
|
mimeType: TMIMEType
|
|
76
29
|
serialize: Serializer<TMIMEType>
|
|
@@ -110,10 +63,10 @@ declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
|
|
|
110
63
|
}
|
|
111
64
|
|
|
112
65
|
declare type Deserializer<TMIMEType extends MIMEType> = ({
|
|
113
|
-
|
|
66
|
+
snapshot,
|
|
114
67
|
event,
|
|
115
68
|
}: {
|
|
116
|
-
|
|
69
|
+
snapshot: EditorSnapshot
|
|
117
70
|
event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>
|
|
118
71
|
}) => PickFromUnion<
|
|
119
72
|
ConverterEvent<TMIMEType>,
|
|
@@ -230,39 +183,17 @@ export declare const getAnchorTextBlock: EditorSelector<
|
|
|
230
183
|
| undefined
|
|
231
184
|
>
|
|
232
185
|
|
|
233
|
-
/**
|
|
234
|
-
* @public
|
|
235
|
-
*/
|
|
236
|
-
declare function getBlockEndPoint({
|
|
237
|
-
node,
|
|
238
|
-
path,
|
|
239
|
-
}: {
|
|
240
|
-
node: PortableTextBlock
|
|
241
|
-
path: [KeyedSegment]
|
|
242
|
-
}): EditorSelectionPoint
|
|
243
|
-
|
|
244
186
|
/**
|
|
245
187
|
* @public
|
|
246
188
|
*/
|
|
247
189
|
export declare const getBlockOffsets: EditorSelector<
|
|
248
190
|
| {
|
|
249
|
-
start:
|
|
250
|
-
end:
|
|
191
|
+
start: BlockOffset
|
|
192
|
+
end: BlockOffset
|
|
251
193
|
}
|
|
252
194
|
| undefined
|
|
253
195
|
>
|
|
254
196
|
|
|
255
|
-
/**
|
|
256
|
-
* @public
|
|
257
|
-
*/
|
|
258
|
-
declare function getBlockStartPoint({
|
|
259
|
-
node,
|
|
260
|
-
path,
|
|
261
|
-
}: {
|
|
262
|
-
node: PortableTextBlock
|
|
263
|
-
path: [KeyedSegment]
|
|
264
|
-
}): EditorSelectionPoint
|
|
265
|
-
|
|
266
197
|
/**
|
|
267
198
|
* @public
|
|
268
199
|
*/
|
|
@@ -479,11 +410,6 @@ export declare const getSelectionStartPoint: EditorSelector<
|
|
|
479
410
|
*/
|
|
480
411
|
export declare const getSelectionText: EditorSelector<string>
|
|
481
412
|
|
|
482
|
-
/**
|
|
483
|
-
* @public
|
|
484
|
-
*/
|
|
485
|
-
declare function getTextBlockText(block: PortableTextTextBlock): string
|
|
486
|
-
|
|
487
413
|
/**
|
|
488
414
|
* @public
|
|
489
415
|
*/
|
|
@@ -536,24 +462,6 @@ export declare function isAtTheStartOfBlock(block: {
|
|
|
536
462
|
path: [KeyedSegment]
|
|
537
463
|
}): EditorSelector<boolean>
|
|
538
464
|
|
|
539
|
-
/**
|
|
540
|
-
* @public
|
|
541
|
-
*/
|
|
542
|
-
declare function isEmptyTextBlock(block: PortableTextBlock): boolean
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* @public
|
|
546
|
-
*/
|
|
547
|
-
declare function isEqualSelectionPoints(
|
|
548
|
-
a: EditorSelectionPoint,
|
|
549
|
-
b: EditorSelectionPoint,
|
|
550
|
-
): boolean
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* @public
|
|
554
|
-
*/
|
|
555
|
-
declare function isKeyedSegment(segment: PathSegment): segment is KeyedSegment
|
|
556
|
-
|
|
557
465
|
/**
|
|
558
466
|
* @public
|
|
559
467
|
*/
|
|
@@ -585,35 +493,6 @@ export declare const isSelectionCollapsed: EditorSelector<boolean>
|
|
|
585
493
|
*/
|
|
586
494
|
export declare const isSelectionExpanded: EditorSelector<boolean>
|
|
587
495
|
|
|
588
|
-
/**
|
|
589
|
-
* @public
|
|
590
|
-
*/
|
|
591
|
-
declare function isSpan(
|
|
592
|
-
context: Pick<EditorContext, 'schema'>,
|
|
593
|
-
child: PortableTextChild,
|
|
594
|
-
): child is PortableTextSpan
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* @public
|
|
598
|
-
*/
|
|
599
|
-
declare function isTextBlock(
|
|
600
|
-
context: Pick<EditorContext, 'schema'>,
|
|
601
|
-
block: PortableTextBlock,
|
|
602
|
-
): block is PortableTextTextBlock
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* @beta
|
|
606
|
-
*/
|
|
607
|
-
declare function mergeTextBlocks({
|
|
608
|
-
context,
|
|
609
|
-
targetBlock,
|
|
610
|
-
incomingBlock,
|
|
611
|
-
}: {
|
|
612
|
-
context: Pick<EditorContext, 'keyGenerator' | 'schema'>
|
|
613
|
-
targetBlock: PortableTextTextBlock
|
|
614
|
-
incomingBlock: PortableTextTextBlock
|
|
615
|
-
}): PortableTextTextBlock<PortableTextSpan | PortableTextObject>
|
|
616
|
-
|
|
617
496
|
declare type MIMEType = `${string}/${string}`
|
|
618
497
|
|
|
619
498
|
/**
|
|
@@ -640,18 +519,11 @@ export declare type PortableTextMemberSchemaTypes = {
|
|
|
640
519
|
lists: BlockListDefinition[]
|
|
641
520
|
}
|
|
642
521
|
|
|
643
|
-
/**
|
|
644
|
-
* @public
|
|
645
|
-
*/
|
|
646
|
-
declare function reverseSelection(
|
|
647
|
-
selection: NonNullable<EditorSelection>,
|
|
648
|
-
): NonNullable<EditorSelection>
|
|
649
|
-
|
|
650
522
|
declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
651
|
-
|
|
523
|
+
snapshot,
|
|
652
524
|
event,
|
|
653
525
|
}: {
|
|
654
|
-
|
|
526
|
+
snapshot: EditorSnapshot
|
|
655
527
|
event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>
|
|
656
528
|
}) => PickFromUnion<
|
|
657
529
|
ConverterEvent<TMIMEType>,
|
|
@@ -659,68 +531,4 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
|
659
531
|
'serialization.success' | 'serialization.failure'
|
|
660
532
|
>
|
|
661
533
|
|
|
662
|
-
/**
|
|
663
|
-
* @public
|
|
664
|
-
*/
|
|
665
|
-
declare function sliceBlocks({
|
|
666
|
-
blocks,
|
|
667
|
-
selection,
|
|
668
|
-
}: {
|
|
669
|
-
blocks: Array<PortableTextBlock>
|
|
670
|
-
selection: EditorSelection
|
|
671
|
-
}): Array<PortableTextBlock>
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* @public
|
|
675
|
-
*/
|
|
676
|
-
declare function spanSelectionPointToBlockOffset({
|
|
677
|
-
value,
|
|
678
|
-
selectionPoint,
|
|
679
|
-
}: {
|
|
680
|
-
value: Array<PortableTextBlock>
|
|
681
|
-
selectionPoint: EditorSelectionPoint
|
|
682
|
-
}): BlockOffset | undefined
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* @beta
|
|
686
|
-
*/
|
|
687
|
-
declare function splitTextBlock({
|
|
688
|
-
context,
|
|
689
|
-
block,
|
|
690
|
-
point,
|
|
691
|
-
}: {
|
|
692
|
-
context: Pick<EditorContext, 'schema'>
|
|
693
|
-
block: PortableTextTextBlock
|
|
694
|
-
point: EditorSelectionPoint
|
|
695
|
-
}):
|
|
696
|
-
| {
|
|
697
|
-
before: PortableTextTextBlock
|
|
698
|
-
after: PortableTextTextBlock
|
|
699
|
-
}
|
|
700
|
-
| undefined
|
|
701
|
-
|
|
702
|
-
declare namespace utils {
|
|
703
|
-
export {
|
|
704
|
-
BlockOffset,
|
|
705
|
-
EditorSelection,
|
|
706
|
-
EditorSelectionPoint,
|
|
707
|
-
blockOffsetToSpanSelectionPoint,
|
|
708
|
-
spanSelectionPointToBlockOffset,
|
|
709
|
-
blockOffsetsToSelection,
|
|
710
|
-
childSelectionPointToBlockOffset,
|
|
711
|
-
getBlockEndPoint,
|
|
712
|
-
getBlockStartPoint,
|
|
713
|
-
getTextBlockText,
|
|
714
|
-
isEmptyTextBlock,
|
|
715
|
-
isEqualSelectionPoints,
|
|
716
|
-
isKeyedSegment,
|
|
717
|
-
isSpan,
|
|
718
|
-
isTextBlock,
|
|
719
|
-
mergeTextBlocks,
|
|
720
|
-
reverseSelection,
|
|
721
|
-
sliceBlocks,
|
|
722
|
-
splitTextBlock,
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
|
|
726
534
|
export {}
|
package/lib/selectors/index.js
CHANGED
|
@@ -11,79 +11,55 @@ const getActiveAnnotations = (snapshot) => {
|
|
|
11
11
|
return [];
|
|
12
12
|
const selectedBlocks = getSelectedBlocks(snapshot), selectedSpans = getSelectedSpans(snapshot);
|
|
13
13
|
return selectedSpans.length === 0 ? [] : selectedBlocks.flatMap((block) => isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => selectedSpans.some((span) => span.node.marks?.includes(markDef._key)));
|
|
14
|
-
}, getAnchorBlock = ({
|
|
15
|
-
context
|
|
16
|
-
}) => {
|
|
17
|
-
const key = context.selection && isKeyedSegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
14
|
+
}, getAnchorBlock = (snapshot) => {
|
|
15
|
+
const key = snapshot.context.selection && isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
18
16
|
return node && key ? {
|
|
19
17
|
node,
|
|
20
18
|
path: [{
|
|
21
19
|
_key: key
|
|
22
20
|
}]
|
|
23
21
|
} : void 0;
|
|
24
|
-
}, getAnchorTextBlock = ({
|
|
25
|
-
|
|
26
|
-
}) => {
|
|
27
|
-
const anchorBlock = getAnchorBlock({
|
|
28
|
-
context
|
|
29
|
-
});
|
|
22
|
+
}, getAnchorTextBlock = (snapshot) => {
|
|
23
|
+
const anchorBlock = getAnchorBlock(snapshot);
|
|
30
24
|
return anchorBlock && isPortableTextTextBlock(anchorBlock.node) ? {
|
|
31
25
|
node: anchorBlock.node,
|
|
32
26
|
path: anchorBlock.path
|
|
33
27
|
} : void 0;
|
|
34
|
-
}, getAnchorChild = ({
|
|
35
|
-
|
|
36
|
-
}) => {
|
|
37
|
-
const anchorBlock = getAnchorTextBlock({
|
|
38
|
-
context
|
|
39
|
-
});
|
|
28
|
+
}, getAnchorChild = (snapshot) => {
|
|
29
|
+
const anchorBlock = getAnchorTextBlock(snapshot);
|
|
40
30
|
if (!anchorBlock)
|
|
41
31
|
return;
|
|
42
|
-
const key = context.selection && isKeyedSegment(context.selection.anchor.path[2]) ? context.selection.anchor.path[2]._key : void 0, node = key ? anchorBlock.node.children.find((span) => span._key === key) : void 0;
|
|
32
|
+
const key = snapshot.context.selection && isKeyedSegment(snapshot.context.selection.anchor.path[2]) ? snapshot.context.selection.anchor.path[2]._key : void 0, node = key ? anchorBlock.node.children.find((span) => span._key === key) : void 0;
|
|
43
33
|
return node && key ? {
|
|
44
34
|
node,
|
|
45
35
|
path: [...anchorBlock.path, "children", {
|
|
46
36
|
_key: key
|
|
47
37
|
}]
|
|
48
38
|
} : void 0;
|
|
49
|
-
}, getAnchorSpan = ({
|
|
50
|
-
|
|
51
|
-
}) => {
|
|
52
|
-
const anchorChild = getAnchorChild({
|
|
53
|
-
context
|
|
54
|
-
});
|
|
39
|
+
}, getAnchorSpan = (snapshot) => {
|
|
40
|
+
const anchorChild = getAnchorChild(snapshot);
|
|
55
41
|
return anchorChild && isPortableTextSpan(anchorChild.node) ? {
|
|
56
42
|
node: anchorChild.node,
|
|
57
43
|
path: anchorChild.path
|
|
58
44
|
} : void 0;
|
|
59
|
-
}, getBlockOffsets = ({
|
|
60
|
-
context
|
|
61
|
-
}) => {
|
|
62
|
-
if (!context.selection)
|
|
45
|
+
}, getBlockOffsets = (snapshot) => {
|
|
46
|
+
if (!snapshot.context.selection)
|
|
63
47
|
return;
|
|
64
|
-
const selectionStartPoint = getSelectionStartPoint(
|
|
65
|
-
context
|
|
66
|
-
}), selectionEndPoint = getSelectionEndPoint({
|
|
67
|
-
context
|
|
68
|
-
});
|
|
48
|
+
const selectionStartPoint = getSelectionStartPoint(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
|
|
69
49
|
if (!selectionStartPoint || !selectionEndPoint)
|
|
70
50
|
return;
|
|
71
51
|
const start = spanSelectionPointToBlockOffset({
|
|
72
|
-
value: context.value,
|
|
52
|
+
value: snapshot.context.value,
|
|
73
53
|
selectionPoint: selectionStartPoint
|
|
74
54
|
}), end = spanSelectionPointToBlockOffset({
|
|
75
|
-
value: context.value,
|
|
55
|
+
value: snapshot.context.value,
|
|
76
56
|
selectionPoint: selectionEndPoint
|
|
77
57
|
});
|
|
78
58
|
return start && end ? {
|
|
79
59
|
start,
|
|
80
60
|
end
|
|
81
61
|
} : void 0;
|
|
82
|
-
}, getSelection = (
|
|
83
|
-
context
|
|
84
|
-
}) => context.selection, getValue = ({
|
|
85
|
-
context
|
|
86
|
-
}) => context.value;
|
|
62
|
+
}, getSelection = (snapshot) => snapshot.context.selection, getValue = (snapshot) => snapshot.context.value;
|
|
87
63
|
function isPointAfterSelection(point) {
|
|
88
64
|
return (snapshot) => {
|
|
89
65
|
if (!snapshot.context.selection)
|
|
@@ -155,27 +131,23 @@ function isPointBeforeSelection(point) {
|
|
|
155
131
|
};
|
|
156
132
|
}
|
|
157
133
|
function isOverlappingSelection(selection) {
|
|
158
|
-
return ({
|
|
159
|
-
context
|
|
160
|
-
}) => {
|
|
161
|
-
if (!selection || !context.selection)
|
|
134
|
+
return (snapshot) => {
|
|
135
|
+
if (!selection || !snapshot.context.selection)
|
|
162
136
|
return !1;
|
|
163
137
|
const selectionStartPoint = getSelectionStartPoint({
|
|
138
|
+
...snapshot,
|
|
164
139
|
context: {
|
|
165
|
-
...context,
|
|
140
|
+
...snapshot.context,
|
|
166
141
|
selection
|
|
167
142
|
}
|
|
168
143
|
}), selectionEndPoint = getSelectionEndPoint({
|
|
144
|
+
...snapshot,
|
|
169
145
|
context: {
|
|
170
|
-
...context,
|
|
146
|
+
...snapshot.context,
|
|
171
147
|
selection
|
|
172
148
|
}
|
|
173
149
|
});
|
|
174
|
-
return !(!selectionStartPoint || !selectionEndPoint || !isPointAfterSelection(selectionStartPoint)(
|
|
175
|
-
context
|
|
176
|
-
}) || !isPointBeforeSelection(selectionEndPoint)({
|
|
177
|
-
context
|
|
178
|
-
}));
|
|
150
|
+
return !(!selectionStartPoint || !selectionEndPoint || !isPointAfterSelection(selectionStartPoint)(snapshot) || !isPointBeforeSelection(selectionEndPoint)(snapshot));
|
|
179
151
|
};
|
|
180
152
|
}
|
|
181
153
|
export {
|