@portabletext/editor 1.34.0 → 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.
Files changed (113) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +57 -118
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +27 -67
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/plugin.event-listener.cjs +53 -71
  6. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.get-text-before.cjs +5 -7
  8. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  9. package/lib/_chunks-cjs/selector.is-active-style.cjs +22 -36
  10. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
  11. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +68 -153
  12. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  13. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
  14. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  15. package/lib/_chunks-es/behavior.core.js +57 -118
  16. package/lib/_chunks-es/behavior.core.js.map +1 -1
  17. package/lib/_chunks-es/behavior.markdown.js +27 -67
  18. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  19. package/lib/_chunks-es/plugin.event-listener.js +53 -71
  20. package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
  21. package/lib/_chunks-es/selector.get-text-before.js +5 -7
  22. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  23. package/lib/_chunks-es/selector.is-active-style.js +22 -36
  24. package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
  25. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +68 -153
  26. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  27. package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
  28. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  29. package/lib/behaviors/index.cjs +18 -48
  30. package/lib/behaviors/index.cjs.map +1 -1
  31. package/lib/behaviors/index.d.cts +28 -16
  32. package/lib/behaviors/index.d.ts +28 -16
  33. package/lib/behaviors/index.js +18 -48
  34. package/lib/behaviors/index.js.map +1 -1
  35. package/lib/index.d.cts +132 -71
  36. package/lib/index.d.ts +132 -71
  37. package/lib/plugins/index.cjs +182 -186
  38. package/lib/plugins/index.cjs.map +1 -1
  39. package/lib/plugins/index.d.cts +147 -82
  40. package/lib/plugins/index.d.ts +147 -82
  41. package/lib/plugins/index.js +182 -186
  42. package/lib/plugins/index.js.map +1 -1
  43. package/lib/selectors/index.cjs +22 -50
  44. package/lib/selectors/index.cjs.map +1 -1
  45. package/lib/selectors/index.d.cts +9 -200
  46. package/lib/selectors/index.d.ts +9 -200
  47. package/lib/selectors/index.js +22 -50
  48. package/lib/selectors/index.js.map +1 -1
  49. package/lib/utils/index.cjs.map +1 -1
  50. package/lib/utils/index.d.cts +15 -7
  51. package/lib/utils/index.d.ts +15 -7
  52. package/lib/utils/index.js.map +1 -1
  53. package/package.json +6 -6
  54. package/src/behaviors/behavior.code-editor.ts +6 -6
  55. package/src/behaviors/behavior.core.annotations.ts +5 -4
  56. package/src/behaviors/behavior.core.block-objects.ts +17 -17
  57. package/src/behaviors/behavior.core.decorators.ts +12 -8
  58. package/src/behaviors/behavior.core.insert-break.ts +27 -29
  59. package/src/behaviors/behavior.core.lists.ts +19 -19
  60. package/src/behaviors/behavior.decorator-pair.ts +200 -0
  61. package/src/behaviors/behavior.default.ts +35 -30
  62. package/src/behaviors/behavior.emoji-picker.ts +12 -12
  63. package/src/behaviors/behavior.links.ts +7 -7
  64. package/src/behaviors/behavior.markdown.ts +41 -42
  65. package/src/behaviors/behavior.types.ts +15 -18
  66. package/src/behaviors/index.ts +0 -1
  67. package/src/converters/converter.json.ts +6 -6
  68. package/src/converters/converter.portable-text.deserialize.test.ts +28 -26
  69. package/src/converters/converter.portable-text.ts +6 -6
  70. package/src/converters/converter.text-html.deserialize.test.ts +17 -15
  71. package/src/converters/converter.text-html.serialize.test.ts +57 -53
  72. package/src/converters/converter.text-html.ts +14 -10
  73. package/src/converters/converter.text-plain.test.ts +17 -15
  74. package/src/converters/converter.text-plain.ts +15 -11
  75. package/src/converters/converter.types.ts +8 -7
  76. package/src/editor/editor-machine.ts +6 -1
  77. package/src/editor/plugins/create-with-event-listeners.ts +0 -5
  78. package/src/index.ts +3 -3
  79. package/src/internal-utils/get-text-to-emphasize.ts +29 -7
  80. package/src/plugins/plugin.decorator-shortcut.ts +235 -0
  81. package/src/plugins/plugin.markdown.tsx +56 -8
  82. package/src/plugins/plugin.one-line.tsx +17 -17
  83. package/src/selectors/selector.get-active-list-item.ts +4 -4
  84. package/src/selectors/selector.get-active-style.ts +6 -6
  85. package/src/selectors/selector.get-anchor-block.ts +5 -5
  86. package/src/selectors/selector.get-anchor-child.ts +5 -5
  87. package/src/selectors/selector.get-anchor-span.ts +2 -2
  88. package/src/selectors/selector.get-anchor-text-block.ts +2 -2
  89. package/src/selectors/selector.get-block-offsets.ts +8 -7
  90. package/src/selectors/selector.get-caret-word-selection.ts +19 -16
  91. package/src/selectors/selector.get-next-inline-object.ts +4 -4
  92. package/src/selectors/selector.get-previous-inline-object.ts +4 -4
  93. package/src/selectors/selector.get-selected-slice.ts +7 -4
  94. package/src/selectors/selector.get-selected-spans.ts +9 -9
  95. package/src/selectors/selector.get-selection-end-point.ts +5 -5
  96. package/src/selectors/selector.get-selection-start-point.ts +5 -5
  97. package/src/selectors/selector.get-selection-text.ts +2 -2
  98. package/src/selectors/selector.get-selection.ts +2 -2
  99. package/src/selectors/selector.get-text-before.ts +8 -8
  100. package/src/selectors/selector.get-trimmed-selection.ts +15 -13
  101. package/src/selectors/selector.get-value.ts +4 -4
  102. package/src/selectors/selector.is-at-the-end-of-block.ts +6 -3
  103. package/src/selectors/selector.is-at-the-start-of-block.ts +3 -3
  104. package/src/selectors/selector.is-overlapping-selection.ts +8 -6
  105. package/src/selectors/selector.is-selection-collapsed.ts +6 -5
  106. package/src/selectors/selector.is-selection-expanded.ts +2 -2
  107. package/src/selectors/selectors.ts +59 -59
  108. package/src/types/block-offset.ts +9 -0
  109. package/src/utils/index.ts +0 -1
  110. package/src/utils/util.block-offset.ts +1 -1
  111. package/src/utils/util.block-offsets-to-selection.ts +1 -1
  112. package/src/utils/util.child-selection-point-to-block-offset.ts +1 -1
  113. 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>
@@ -80,18 +33,19 @@ declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
80
33
  declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
81
34
  | {
82
35
  type: 'serialize'
83
- originEvent: 'copy' | 'cut' | 'unknown'
36
+ originEvent: 'copy' | 'cut' | 'drag' | 'unknown'
84
37
  }
85
38
  | {
86
39
  type: 'serialization.failure'
87
40
  mimeType: TMIMEType
41
+ originEvent: 'copy' | 'cut' | 'drag' | 'unknown'
88
42
  reason: string
89
43
  }
90
44
  | {
91
45
  type: 'serialization.success'
92
46
  data: string
93
47
  mimeType: TMIMEType
94
- originEvent: 'copy' | 'cut' | 'unknown'
48
+ originEvent: 'copy' | 'cut' | 'drag' | 'unknown'
95
49
  }
96
50
  | {
97
51
  type: 'deserialize'
@@ -109,10 +63,10 @@ declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
109
63
  }
110
64
 
111
65
  declare type Deserializer<TMIMEType extends MIMEType> = ({
112
- context,
66
+ snapshot,
113
67
  event,
114
68
  }: {
115
- context: EditorContext
69
+ snapshot: EditorSnapshot
116
70
  event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>
117
71
  }) => PickFromUnion<
118
72
  ConverterEvent<TMIMEType>,
@@ -229,39 +183,17 @@ export declare const getAnchorTextBlock: EditorSelector<
229
183
  | undefined
230
184
  >
231
185
 
232
- /**
233
- * @public
234
- */
235
- declare function getBlockEndPoint({
236
- node,
237
- path,
238
- }: {
239
- node: PortableTextBlock
240
- path: [KeyedSegment]
241
- }): EditorSelectionPoint
242
-
243
186
  /**
244
187
  * @public
245
188
  */
246
189
  export declare const getBlockOffsets: EditorSelector<
247
190
  | {
248
- start: utils.BlockOffset
249
- end: utils.BlockOffset
191
+ start: BlockOffset
192
+ end: BlockOffset
250
193
  }
251
194
  | undefined
252
195
  >
253
196
 
254
- /**
255
- * @public
256
- */
257
- declare function getBlockStartPoint({
258
- node,
259
- path,
260
- }: {
261
- node: PortableTextBlock
262
- path: [KeyedSegment]
263
- }): EditorSelectionPoint
264
-
265
197
  /**
266
198
  * @public
267
199
  */
@@ -478,11 +410,6 @@ export declare const getSelectionStartPoint: EditorSelector<
478
410
  */
479
411
  export declare const getSelectionText: EditorSelector<string>
480
412
 
481
- /**
482
- * @public
483
- */
484
- declare function getTextBlockText(block: PortableTextTextBlock): string
485
-
486
413
  /**
487
414
  * @public
488
415
  */
@@ -535,24 +462,6 @@ export declare function isAtTheStartOfBlock(block: {
535
462
  path: [KeyedSegment]
536
463
  }): EditorSelector<boolean>
537
464
 
538
- /**
539
- * @public
540
- */
541
- declare function isEmptyTextBlock(block: PortableTextBlock): boolean
542
-
543
- /**
544
- * @public
545
- */
546
- declare function isEqualSelectionPoints(
547
- a: EditorSelectionPoint,
548
- b: EditorSelectionPoint,
549
- ): boolean
550
-
551
- /**
552
- * @public
553
- */
554
- declare function isKeyedSegment(segment: PathSegment): segment is KeyedSegment
555
-
556
465
  /**
557
466
  * @public
558
467
  */
@@ -584,35 +493,6 @@ export declare const isSelectionCollapsed: EditorSelector<boolean>
584
493
  */
585
494
  export declare const isSelectionExpanded: EditorSelector<boolean>
586
495
 
587
- /**
588
- * @public
589
- */
590
- declare function isSpan(
591
- context: Pick<EditorContext, 'schema'>,
592
- child: PortableTextChild,
593
- ): child is PortableTextSpan
594
-
595
- /**
596
- * @public
597
- */
598
- declare function isTextBlock(
599
- context: Pick<EditorContext, 'schema'>,
600
- block: PortableTextBlock,
601
- ): block is PortableTextTextBlock
602
-
603
- /**
604
- * @beta
605
- */
606
- declare function mergeTextBlocks({
607
- context,
608
- targetBlock,
609
- incomingBlock,
610
- }: {
611
- context: Pick<EditorContext, 'keyGenerator' | 'schema'>
612
- targetBlock: PortableTextTextBlock
613
- incomingBlock: PortableTextTextBlock
614
- }): PortableTextTextBlock<PortableTextSpan | PortableTextObject>
615
-
616
496
  declare type MIMEType = `${string}/${string}`
617
497
 
618
498
  /**
@@ -639,18 +519,11 @@ export declare type PortableTextMemberSchemaTypes = {
639
519
  lists: BlockListDefinition[]
640
520
  }
641
521
 
642
- /**
643
- * @public
644
- */
645
- declare function reverseSelection(
646
- selection: NonNullable<EditorSelection>,
647
- ): NonNullable<EditorSelection>
648
-
649
522
  declare type Serializer<TMIMEType extends MIMEType> = ({
650
- context,
523
+ snapshot,
651
524
  event,
652
525
  }: {
653
- context: EditorContext
526
+ snapshot: EditorSnapshot
654
527
  event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>
655
528
  }) => PickFromUnion<
656
529
  ConverterEvent<TMIMEType>,
@@ -658,68 +531,4 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
658
531
  'serialization.success' | 'serialization.failure'
659
532
  >
660
533
 
661
- /**
662
- * @public
663
- */
664
- declare function sliceBlocks({
665
- blocks,
666
- selection,
667
- }: {
668
- blocks: Array<PortableTextBlock>
669
- selection: EditorSelection
670
- }): Array<PortableTextBlock>
671
-
672
- /**
673
- * @public
674
- */
675
- declare function spanSelectionPointToBlockOffset({
676
- value,
677
- selectionPoint,
678
- }: {
679
- value: Array<PortableTextBlock>
680
- selectionPoint: EditorSelectionPoint
681
- }): BlockOffset | undefined
682
-
683
- /**
684
- * @beta
685
- */
686
- declare function splitTextBlock({
687
- context,
688
- block,
689
- point,
690
- }: {
691
- context: Pick<EditorContext, 'schema'>
692
- block: PortableTextTextBlock
693
- point: EditorSelectionPoint
694
- }):
695
- | {
696
- before: PortableTextTextBlock
697
- after: PortableTextTextBlock
698
- }
699
- | undefined
700
-
701
- declare namespace utils {
702
- export {
703
- BlockOffset,
704
- EditorSelection,
705
- EditorSelectionPoint,
706
- blockOffsetToSpanSelectionPoint,
707
- spanSelectionPointToBlockOffset,
708
- blockOffsetsToSelection,
709
- childSelectionPointToBlockOffset,
710
- getBlockEndPoint,
711
- getBlockStartPoint,
712
- getTextBlockText,
713
- isEmptyTextBlock,
714
- isEqualSelectionPoints,
715
- isKeyedSegment,
716
- isSpan,
717
- isTextBlock,
718
- mergeTextBlocks,
719
- reverseSelection,
720
- sliceBlocks,
721
- splitTextBlock,
722
- }
723
- }
724
-
725
534
  export {}
@@ -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>
@@ -80,18 +33,19 @@ declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
80
33
  declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
81
34
  | {
82
35
  type: 'serialize'
83
- originEvent: 'copy' | 'cut' | 'unknown'
36
+ originEvent: 'copy' | 'cut' | 'drag' | 'unknown'
84
37
  }
85
38
  | {
86
39
  type: 'serialization.failure'
87
40
  mimeType: TMIMEType
41
+ originEvent: 'copy' | 'cut' | 'drag' | 'unknown'
88
42
  reason: string
89
43
  }
90
44
  | {
91
45
  type: 'serialization.success'
92
46
  data: string
93
47
  mimeType: TMIMEType
94
- originEvent: 'copy' | 'cut' | 'unknown'
48
+ originEvent: 'copy' | 'cut' | 'drag' | 'unknown'
95
49
  }
96
50
  | {
97
51
  type: 'deserialize'
@@ -109,10 +63,10 @@ declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
109
63
  }
110
64
 
111
65
  declare type Deserializer<TMIMEType extends MIMEType> = ({
112
- context,
66
+ snapshot,
113
67
  event,
114
68
  }: {
115
- context: EditorContext
69
+ snapshot: EditorSnapshot
116
70
  event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>
117
71
  }) => PickFromUnion<
118
72
  ConverterEvent<TMIMEType>,
@@ -229,39 +183,17 @@ export declare const getAnchorTextBlock: EditorSelector<
229
183
  | undefined
230
184
  >
231
185
 
232
- /**
233
- * @public
234
- */
235
- declare function getBlockEndPoint({
236
- node,
237
- path,
238
- }: {
239
- node: PortableTextBlock
240
- path: [KeyedSegment]
241
- }): EditorSelectionPoint
242
-
243
186
  /**
244
187
  * @public
245
188
  */
246
189
  export declare const getBlockOffsets: EditorSelector<
247
190
  | {
248
- start: utils.BlockOffset
249
- end: utils.BlockOffset
191
+ start: BlockOffset
192
+ end: BlockOffset
250
193
  }
251
194
  | undefined
252
195
  >
253
196
 
254
- /**
255
- * @public
256
- */
257
- declare function getBlockStartPoint({
258
- node,
259
- path,
260
- }: {
261
- node: PortableTextBlock
262
- path: [KeyedSegment]
263
- }): EditorSelectionPoint
264
-
265
197
  /**
266
198
  * @public
267
199
  */
@@ -478,11 +410,6 @@ export declare const getSelectionStartPoint: EditorSelector<
478
410
  */
479
411
  export declare const getSelectionText: EditorSelector<string>
480
412
 
481
- /**
482
- * @public
483
- */
484
- declare function getTextBlockText(block: PortableTextTextBlock): string
485
-
486
413
  /**
487
414
  * @public
488
415
  */
@@ -535,24 +462,6 @@ export declare function isAtTheStartOfBlock(block: {
535
462
  path: [KeyedSegment]
536
463
  }): EditorSelector<boolean>
537
464
 
538
- /**
539
- * @public
540
- */
541
- declare function isEmptyTextBlock(block: PortableTextBlock): boolean
542
-
543
- /**
544
- * @public
545
- */
546
- declare function isEqualSelectionPoints(
547
- a: EditorSelectionPoint,
548
- b: EditorSelectionPoint,
549
- ): boolean
550
-
551
- /**
552
- * @public
553
- */
554
- declare function isKeyedSegment(segment: PathSegment): segment is KeyedSegment
555
-
556
465
  /**
557
466
  * @public
558
467
  */
@@ -584,35 +493,6 @@ export declare const isSelectionCollapsed: EditorSelector<boolean>
584
493
  */
585
494
  export declare const isSelectionExpanded: EditorSelector<boolean>
586
495
 
587
- /**
588
- * @public
589
- */
590
- declare function isSpan(
591
- context: Pick<EditorContext, 'schema'>,
592
- child: PortableTextChild,
593
- ): child is PortableTextSpan
594
-
595
- /**
596
- * @public
597
- */
598
- declare function isTextBlock(
599
- context: Pick<EditorContext, 'schema'>,
600
- block: PortableTextBlock,
601
- ): block is PortableTextTextBlock
602
-
603
- /**
604
- * @beta
605
- */
606
- declare function mergeTextBlocks({
607
- context,
608
- targetBlock,
609
- incomingBlock,
610
- }: {
611
- context: Pick<EditorContext, 'keyGenerator' | 'schema'>
612
- targetBlock: PortableTextTextBlock
613
- incomingBlock: PortableTextTextBlock
614
- }): PortableTextTextBlock<PortableTextSpan | PortableTextObject>
615
-
616
496
  declare type MIMEType = `${string}/${string}`
617
497
 
618
498
  /**
@@ -639,18 +519,11 @@ export declare type PortableTextMemberSchemaTypes = {
639
519
  lists: BlockListDefinition[]
640
520
  }
641
521
 
642
- /**
643
- * @public
644
- */
645
- declare function reverseSelection(
646
- selection: NonNullable<EditorSelection>,
647
- ): NonNullable<EditorSelection>
648
-
649
522
  declare type Serializer<TMIMEType extends MIMEType> = ({
650
- context,
523
+ snapshot,
651
524
  event,
652
525
  }: {
653
- context: EditorContext
526
+ snapshot: EditorSnapshot
654
527
  event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>
655
528
  }) => PickFromUnion<
656
529
  ConverterEvent<TMIMEType>,
@@ -658,68 +531,4 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
658
531
  'serialization.success' | 'serialization.failure'
659
532
  >
660
533
 
661
- /**
662
- * @public
663
- */
664
- declare function sliceBlocks({
665
- blocks,
666
- selection,
667
- }: {
668
- blocks: Array<PortableTextBlock>
669
- selection: EditorSelection
670
- }): Array<PortableTextBlock>
671
-
672
- /**
673
- * @public
674
- */
675
- declare function spanSelectionPointToBlockOffset({
676
- value,
677
- selectionPoint,
678
- }: {
679
- value: Array<PortableTextBlock>
680
- selectionPoint: EditorSelectionPoint
681
- }): BlockOffset | undefined
682
-
683
- /**
684
- * @beta
685
- */
686
- declare function splitTextBlock({
687
- context,
688
- block,
689
- point,
690
- }: {
691
- context: Pick<EditorContext, 'schema'>
692
- block: PortableTextTextBlock
693
- point: EditorSelectionPoint
694
- }):
695
- | {
696
- before: PortableTextTextBlock
697
- after: PortableTextTextBlock
698
- }
699
- | undefined
700
-
701
- declare namespace utils {
702
- export {
703
- BlockOffset,
704
- EditorSelection,
705
- EditorSelectionPoint,
706
- blockOffsetToSpanSelectionPoint,
707
- spanSelectionPointToBlockOffset,
708
- blockOffsetsToSelection,
709
- childSelectionPointToBlockOffset,
710
- getBlockEndPoint,
711
- getBlockStartPoint,
712
- getTextBlockText,
713
- isEmptyTextBlock,
714
- isEqualSelectionPoints,
715
- isKeyedSegment,
716
- isSpan,
717
- isTextBlock,
718
- mergeTextBlocks,
719
- reverseSelection,
720
- sliceBlocks,
721
- splitTextBlock,
722
- }
723
- }
724
-
725
534
  export {}
@@ -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
- context
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
- context
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
- context
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 {