@portabletext/editor 1.53.1 → 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.
Files changed (66) hide show
  1. package/lib/_chunks-cjs/selection-point.cjs.map +1 -1
  2. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  4. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
  5. package/lib/_chunks-es/selection-point.js.map +1 -1
  6. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  7. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  8. package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -1
  9. package/lib/behaviors/index.cjs.map +1 -1
  10. package/lib/behaviors/index.d.cts +68 -9
  11. package/lib/behaviors/index.d.ts +68 -9
  12. package/lib/behaviors/index.js.map +1 -1
  13. package/lib/index.cjs +529 -289
  14. package/lib/index.cjs.map +1 -1
  15. package/lib/index.d.cts +69 -13
  16. package/lib/index.d.ts +69 -13
  17. package/lib/index.js +533 -293
  18. package/lib/index.js.map +1 -1
  19. package/lib/plugins/index.d.cts +69 -9
  20. package/lib/plugins/index.d.ts +69 -9
  21. package/lib/selectors/index.cjs.map +1 -1
  22. package/lib/selectors/index.d.cts +31 -16
  23. package/lib/selectors/index.d.ts +31 -16
  24. package/lib/selectors/index.js.map +1 -1
  25. package/lib/utils/index.d.cts +27 -5
  26. package/lib/utils/index.d.ts +27 -5
  27. package/package.json +3 -3
  28. package/src/behaviors/behavior.abstract.annotation.ts +51 -0
  29. package/src/behaviors/behavior.abstract.delete.ts +55 -0
  30. package/src/behaviors/behavior.perform-event.ts +6 -15
  31. package/src/behaviors/behavior.types.action.ts +1 -1
  32. package/src/behaviors/behavior.types.event.ts +32 -8
  33. package/src/behaviors/behavior.types.guard.ts +1 -1
  34. package/src/editor/Editable.tsx +3 -0
  35. package/src/editor/PortableTextEditor.tsx +1 -6
  36. package/src/editor/create-editor.ts +5 -0
  37. package/src/{internal-utils/selection-elements.ts → editor/editor-dom.ts} +29 -21
  38. package/src/editor/editor-provider.tsx +1 -6
  39. package/src/editor/hooks/usePortableTextEditorSelection.tsx +6 -46
  40. package/src/editor/plugins/createWithPatches.ts +1 -5
  41. package/src/editor.ts +2 -0
  42. package/src/index.ts +2 -0
  43. package/src/operations/behavior.operation.child.set.ts +103 -0
  44. package/src/operations/behavior.operation.child.unset.ts +89 -0
  45. package/src/operations/behavior.operations.ts +18 -0
  46. package/src/selectors/selector.get-anchor-block.ts +3 -2
  47. package/src/selectors/selector.get-anchor-child.ts +2 -2
  48. package/src/selectors/selector.get-anchor-span.ts +2 -3
  49. package/src/selectors/selector.get-anchor-text-block.ts +3 -2
  50. package/src/selectors/selector.get-focus-child.ts +3 -6
  51. package/src/selectors/selector.get-focus-inline-object.ts +3 -7
  52. package/src/selectors/selector.get-focus-span.ts +3 -3
  53. package/src/selectors/selector.get-next-inline-object.ts +4 -7
  54. package/src/selectors/selector.get-previous-block.ts +2 -2
  55. package/src/selectors/selector.get-previous-inline-object.ts +4 -7
  56. package/src/selectors/selector.get-selected-blocks.ts +2 -3
  57. package/src/selectors/selector.get-selected-spans.test.ts +96 -0
  58. package/src/selectors/selector.get-selected-spans.ts +4 -3
  59. package/src/selectors/selector.get-selected-text-blocks.ts +4 -3
  60. package/src/selectors/selector.is-at-the-end-of-block.ts +3 -2
  61. package/src/selectors/selector.is-at-the-start-of-block.ts +3 -2
  62. package/src/types/block-offset.ts +2 -2
  63. package/src/types/paths.ts +13 -0
  64. package/src/utils/util.block-offset.ts +2 -4
  65. package/src/utils/util.get-block-end-point.ts +3 -2
  66. package/src/utils/util.get-block-start-point.ts +3 -2
@@ -1,6 +1,5 @@
1
1
  import type {Patch} from '@portabletext/patches'
2
2
  import type {
3
- KeyedSegment,
4
3
  Path,
5
4
  PortableTextBlock,
6
5
  PortableTextChild,
@@ -12,6 +11,11 @@ import {JSX, default as React_2} from 'react'
12
11
  import type {ActorRef, EventObject, Snapshot} from 'xstate'
13
12
 
14
13
  declare type AbstractBehaviorEvent =
14
+ | {
15
+ type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
16
+ at: AnnotationPath
17
+ props: Record<string, unknown>
18
+ }
15
19
  | {
16
20
  type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
17
21
  annotation: {
@@ -35,7 +39,11 @@ declare type AbstractBehaviorEvent =
35
39
  }
36
40
  | {
37
41
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
38
- at: [KeyedSegment]
42
+ at: BlockPath
43
+ }
44
+ | {
45
+ type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
46
+ at: ChildPath
39
47
  }
40
48
  | {
41
49
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
@@ -136,11 +144,11 @@ declare type AbstractBehaviorEvent =
136
144
  }
137
145
  | {
138
146
  type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
139
- at: [KeyedSegment]
147
+ at: BlockPath
140
148
  }
141
149
  | {
142
150
  type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
143
- at: [KeyedSegment]
151
+ at: BlockPath
144
152
  }
145
153
  | {
146
154
  type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
@@ -170,10 +178,12 @@ declare type AbstractBehaviorEvent =
170
178
  * Abstract events
171
179
  **************************************/
172
180
  declare const abstractBehaviorEventTypes: readonly [
181
+ 'annotation.set',
173
182
  'annotation.toggle',
174
183
  'decorator.toggle',
175
184
  'delete.backward',
176
185
  'delete.block',
186
+ 'delete.child',
177
187
  'delete.forward',
178
188
  'delete.text',
179
189
  'deserialize',
@@ -198,6 +208,19 @@ declare const abstractBehaviorEventTypes: readonly [
198
208
  'style.toggle',
199
209
  ]
200
210
 
211
+ /**
212
+ * @public
213
+ */
214
+ declare type AnnotationPath = [
215
+ {
216
+ _key: string
217
+ },
218
+ 'markDefs',
219
+ {
220
+ _key: string
221
+ },
222
+ ]
223
+
201
224
  /**
202
225
  * @public
203
226
  */
@@ -304,14 +327,36 @@ export declare function BehaviorPlugin(props: {
304
327
  * @beta
305
328
  */
306
329
  declare type BlockOffset = {
307
- path: [KeyedSegment]
330
+ path: BlockPath
308
331
  offset: number
309
332
  }
310
333
 
334
+ /**
335
+ * @public
336
+ */
337
+ declare type BlockPath = [
338
+ {
339
+ _key: string
340
+ },
341
+ ]
342
+
311
343
  declare type BlockWithOptionalKey =
312
344
  | TextBlockWithOptionalKey
313
345
  | ObjectBlockWithOptionalKey
314
346
 
347
+ /**
348
+ * @public
349
+ */
350
+ declare type ChildPath = [
351
+ {
352
+ _key: string
353
+ },
354
+ 'children',
355
+ {
356
+ _key: string
357
+ },
358
+ ]
359
+
315
360
  declare type ClipboardBehaviorEvent =
316
361
  | {
317
362
  type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
@@ -477,6 +522,7 @@ declare type DragBehaviorEvent =
477
522
  * @public
478
523
  */
479
524
  declare type Editor = {
525
+ dom: EditorDom
480
526
  getSnapshot: () => EditorSnapshot
481
527
  /**
482
528
  * @beta
@@ -1102,12 +1148,24 @@ declare type SyntheticBehaviorEvent =
1102
1148
  }
1103
1149
  | {
1104
1150
  type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
1105
- at: [KeyedSegment]
1151
+ at: BlockPath
1106
1152
  props: Record<string, unknown>
1107
1153
  }
1108
1154
  | {
1109
1155
  type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
1110
- at: [KeyedSegment]
1156
+ at: BlockPath
1157
+ props: Array<string>
1158
+ }
1159
+ | {
1160
+ type: StrictExtract<SyntheticBehaviorEventType, 'child.set'>
1161
+ at: ChildPath
1162
+ props: {
1163
+ [prop: string]: unknown
1164
+ }
1165
+ }
1166
+ | {
1167
+ type: StrictExtract<SyntheticBehaviorEventType, 'child.unset'>
1168
+ at: ChildPath
1111
1169
  props: Array<string>
1112
1170
  }
1113
1171
  | {
@@ -1176,8 +1234,8 @@ declare type SyntheticBehaviorEvent =
1176
1234
  }
1177
1235
  | {
1178
1236
  type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
1179
- at: [KeyedSegment]
1180
- to: [KeyedSegment]
1237
+ at: BlockPath
1238
+ to: BlockPath
1181
1239
  }
1182
1240
  | {
1183
1241
  type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
@@ -1204,6 +1262,8 @@ declare const syntheticBehaviorEventTypes: readonly [
1204
1262
  'annotation.remove',
1205
1263
  'block.set',
1206
1264
  'block.unset',
1265
+ 'child.set',
1266
+ 'child.unset',
1207
1267
  'decorator.add',
1208
1268
  'decorator.remove',
1209
1269
  'delete',
@@ -1,6 +1,5 @@
1
1
  import type {Patch} from '@portabletext/patches'
2
2
  import type {
3
- KeyedSegment,
4
3
  Path,
5
4
  PortableTextBlock,
6
5
  PortableTextChild,
@@ -12,6 +11,11 @@ import {JSX, default as React_2} from 'react'
12
11
  import type {ActorRef, EventObject, Snapshot} from 'xstate'
13
12
 
14
13
  declare type AbstractBehaviorEvent =
14
+ | {
15
+ type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
16
+ at: AnnotationPath
17
+ props: Record<string, unknown>
18
+ }
15
19
  | {
16
20
  type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
17
21
  annotation: {
@@ -35,7 +39,11 @@ declare type AbstractBehaviorEvent =
35
39
  }
36
40
  | {
37
41
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
38
- at: [KeyedSegment]
42
+ at: BlockPath
43
+ }
44
+ | {
45
+ type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
46
+ at: ChildPath
39
47
  }
40
48
  | {
41
49
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
@@ -136,11 +144,11 @@ declare type AbstractBehaviorEvent =
136
144
  }
137
145
  | {
138
146
  type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
139
- at: [KeyedSegment]
147
+ at: BlockPath
140
148
  }
141
149
  | {
142
150
  type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
143
- at: [KeyedSegment]
151
+ at: BlockPath
144
152
  }
145
153
  | {
146
154
  type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
@@ -170,10 +178,12 @@ declare type AbstractBehaviorEvent =
170
178
  * Abstract events
171
179
  **************************************/
172
180
  declare const abstractBehaviorEventTypes: readonly [
181
+ 'annotation.set',
173
182
  'annotation.toggle',
174
183
  'decorator.toggle',
175
184
  'delete.backward',
176
185
  'delete.block',
186
+ 'delete.child',
177
187
  'delete.forward',
178
188
  'delete.text',
179
189
  'deserialize',
@@ -198,6 +208,19 @@ declare const abstractBehaviorEventTypes: readonly [
198
208
  'style.toggle',
199
209
  ]
200
210
 
211
+ /**
212
+ * @public
213
+ */
214
+ declare type AnnotationPath = [
215
+ {
216
+ _key: string
217
+ },
218
+ 'markDefs',
219
+ {
220
+ _key: string
221
+ },
222
+ ]
223
+
201
224
  /**
202
225
  * @public
203
226
  */
@@ -304,14 +327,36 @@ export declare function BehaviorPlugin(props: {
304
327
  * @beta
305
328
  */
306
329
  declare type BlockOffset = {
307
- path: [KeyedSegment]
330
+ path: BlockPath
308
331
  offset: number
309
332
  }
310
333
 
334
+ /**
335
+ * @public
336
+ */
337
+ declare type BlockPath = [
338
+ {
339
+ _key: string
340
+ },
341
+ ]
342
+
311
343
  declare type BlockWithOptionalKey =
312
344
  | TextBlockWithOptionalKey
313
345
  | ObjectBlockWithOptionalKey
314
346
 
347
+ /**
348
+ * @public
349
+ */
350
+ declare type ChildPath = [
351
+ {
352
+ _key: string
353
+ },
354
+ 'children',
355
+ {
356
+ _key: string
357
+ },
358
+ ]
359
+
315
360
  declare type ClipboardBehaviorEvent =
316
361
  | {
317
362
  type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
@@ -477,6 +522,7 @@ declare type DragBehaviorEvent =
477
522
  * @public
478
523
  */
479
524
  declare type Editor = {
525
+ dom: EditorDom
480
526
  getSnapshot: () => EditorSnapshot
481
527
  /**
482
528
  * @beta
@@ -1102,12 +1148,24 @@ declare type SyntheticBehaviorEvent =
1102
1148
  }
1103
1149
  | {
1104
1150
  type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
1105
- at: [KeyedSegment]
1151
+ at: BlockPath
1106
1152
  props: Record<string, unknown>
1107
1153
  }
1108
1154
  | {
1109
1155
  type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
1110
- at: [KeyedSegment]
1156
+ at: BlockPath
1157
+ props: Array<string>
1158
+ }
1159
+ | {
1160
+ type: StrictExtract<SyntheticBehaviorEventType, 'child.set'>
1161
+ at: ChildPath
1162
+ props: {
1163
+ [prop: string]: unknown
1164
+ }
1165
+ }
1166
+ | {
1167
+ type: StrictExtract<SyntheticBehaviorEventType, 'child.unset'>
1168
+ at: ChildPath
1111
1169
  props: Array<string>
1112
1170
  }
1113
1171
  | {
@@ -1176,8 +1234,8 @@ declare type SyntheticBehaviorEvent =
1176
1234
  }
1177
1235
  | {
1178
1236
  type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
1179
- at: [KeyedSegment]
1180
- to: [KeyedSegment]
1237
+ at: BlockPath
1238
+ to: BlockPath
1181
1239
  }
1182
1240
  | {
1183
1241
  type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
@@ -1204,6 +1262,8 @@ declare const syntheticBehaviorEventTypes: readonly [
1204
1262
  'annotation.remove',
1205
1263
  'block.set',
1206
1264
  'block.unset',
1265
+ 'child.set',
1266
+ 'child.unset',
1207
1267
  'decorator.add',
1208
1268
  'decorator.remove',
1209
1269
  'delete',
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","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} 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":";;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,eAA8BJ,8BAAAA,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,eAAAA,YAAYf,SAASC,SAASa,YAAYR,IAAI,IAChE;AAAA,IAACA,MAAMQ,YAAYR;AAAAA,IAAMM,MAAME,YAAYF;AAAAA,EAAAA,IAC3CD;AACN,GC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B,cAAcpC,KAAKgC,UAAU3B,WAK3B+B,cAAcpC,KAAK+B,aAAaA,UAIpC;AAAIK,UAAAA,cAAcpC,KAAKgC,UAAUA;AACxB,eAAA;AAAA,UACLhC,MAAMoC,cAAcpC;AAAAA,UACpBM,MAAM8B,cAAc9B;AAAAA,QACtB;AAGE8B,UAAAA,EAAAA,cAAcpC,KAAKgC,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;ACvJaW,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","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,eAA8BJ,8BAAAA,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,eAAAA,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,eAA8BjB,8BAAAA,SAASC,QAAQC,UAAUG,MAAM,GAErEC,OAAOH,MACTW,YAAYR,KAAKY,SAASV,KAAMW,UAASA,KAAKT,SAASP,GAAG,IAC1DQ;AAEJ,SAAOL,Q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AAAA,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;ACvJaW,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -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: [KeyedSegment]
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: [KeyedSegment]
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: [KeyedSegment_2, 'children', KeyedSegment_2]
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: [KeyedSegment_2, 'children', KeyedSegment_2]
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: [KeyedSegment]
265
+ path: BlockPath
251
266
  }
252
267
  | undefined
253
268
  >
@@ -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: [KeyedSegment, 'children', KeyedSegment]
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: [KeyedSegment, 'children', KeyedSegment]
343
+ path: ChildPath
329
344
  }
330
345
  | undefined
331
346
  >
@@ -347,7 +362,7 @@ export declare const getFocusListBlock: EditorSelector<
347
362
  export declare const getFocusSpan: EditorSelector<
348
363
  | {
349
364
  node: PortableTextSpan
350
- path: [KeyedSegment, 'children', KeyedSegment]
365
+ path: ChildPath
351
366
  }
352
367
  | undefined
353
368
  >
@@ -402,7 +417,7 @@ export declare const getNextBlock: EditorSelector<
402
417
  export declare const getNextInlineObject: EditorSelector<
403
418
  | {
404
419
  node: PortableTextObject
405
- path: [KeyedSegment, 'children', KeyedSegment]
420
+ path: ChildPath
406
421
  }
407
422
  | undefined
408
423
  >
@@ -424,7 +439,7 @@ export declare const getPreviousBlock: EditorSelector<
424
439
  export declare const getPreviousInlineObject: EditorSelector<
425
440
  | {
426
441
  node: PortableTextObject
427
- path: [KeyedSegment, 'children', KeyedSegment]
442
+ path: ChildPath
428
443
  }
429
444
  | undefined
430
445
  >
@@ -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: [KeyedSegment, 'children', KeyedSegment]
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: [KeyedSegment]
478
+ path: BlockPath
464
479
  }>
465
480
  >
466
481
 
@@ -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: [KeyedSegment]
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: [KeyedSegment]
578
+ path: BlockPath
564
579
  }): EditorSelector<boolean>
565
580
 
566
581
  /**