@portabletext/editor 1.49.12 → 1.50.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.
@@ -317,6 +317,12 @@ declare type BlockOffset = {
317
317
  offset: number
318
318
  }
319
319
 
320
+ declare type BlockPath = [
321
+ {
322
+ _key: string
323
+ },
324
+ ]
325
+
320
326
  declare type BlockWithOptionalKey =
321
327
  | TextBlockWithOptionalKey
322
328
  | ObjectBlockWithOptionalKey
@@ -1210,6 +1216,142 @@ declare const editorMachine: StateMachine<
1210
1216
  never,
1211
1217
  never
1212
1218
  >,
1219
+ ActionFunction<
1220
+ {
1221
+ behaviors: Set<BehaviorConfig>
1222
+ converters: Set<Converter>
1223
+ getLegacySchema: () => PortableTextMemberSchemaTypes
1224
+ keyGenerator: () => string
1225
+ pendingEvents: Array<InternalPatchEvent | MutationEvent>
1226
+ pendingIncomingPatchesEvents: Array<PatchesEvent>
1227
+ schema: EditorSchema
1228
+ initialReadOnly: boolean
1229
+ maxBlocks: number | undefined
1230
+ selection: EditorSelection
1231
+ initialValue: Array<PortableTextBlock> | undefined
1232
+ internalDrag?: {
1233
+ ghost?: HTMLElement
1234
+ origin: Pick<EventPosition, 'selection'>
1235
+ }
1236
+ slateEditor?: PortableTextSlateEditor
1237
+ },
1238
+ {
1239
+ type: 'update selection'
1240
+ selection: EditorSelection
1241
+ },
1242
+ | InternalPatchEvent
1243
+ | MutationEvent
1244
+ | PatchesEvent
1245
+ | {
1246
+ type: 'update readOnly'
1247
+ readOnly: boolean
1248
+ }
1249
+ | {
1250
+ type: 'update maxBlocks'
1251
+ maxBlocks: number | undefined
1252
+ }
1253
+ | {
1254
+ type: 'add behavior'
1255
+ behaviorConfig: BehaviorConfig
1256
+ }
1257
+ | {
1258
+ type: 'remove behavior'
1259
+ behaviorConfig: BehaviorConfig
1260
+ }
1261
+ | {
1262
+ type: 'blur'
1263
+ editor: PortableTextSlateEditor
1264
+ }
1265
+ | {
1266
+ type: 'focus'
1267
+ editor: PortableTextSlateEditor
1268
+ }
1269
+ | {
1270
+ type: 'normalizing'
1271
+ }
1272
+ | {
1273
+ type: 'update selection'
1274
+ selection: EditorSelection
1275
+ }
1276
+ | {
1277
+ type: 'done normalizing'
1278
+ }
1279
+ | {
1280
+ type: 'done syncing value'
1281
+ }
1282
+ | {
1283
+ type: 'syncing value'
1284
+ }
1285
+ | {
1286
+ type: 'behavior event'
1287
+ behaviorEvent: BehaviorEvent
1288
+ editor: PortableTextSlateEditor
1289
+ nativeEvent?: {
1290
+ preventDefault: () => void
1291
+ }
1292
+ }
1293
+ | {
1294
+ type: 'dragstart'
1295
+ origin: Pick<EventPosition, 'selection'>
1296
+ ghost?: HTMLElement
1297
+ }
1298
+ | {
1299
+ type: 'dragend'
1300
+ }
1301
+ | {
1302
+ type: 'drop'
1303
+ },
1304
+ undefined,
1305
+ never,
1306
+ never,
1307
+ never,
1308
+ never,
1309
+ | InternalPatchEvent
1310
+ | MutationEvent
1311
+ | PatchesEvent
1312
+ | {
1313
+ type: 'blurred'
1314
+ event: FocusEvent_2<HTMLDivElement, Element>
1315
+ }
1316
+ | {
1317
+ type: 'done loading'
1318
+ }
1319
+ | {
1320
+ type: 'editable'
1321
+ }
1322
+ | {
1323
+ type: 'error'
1324
+ name: string
1325
+ description: string
1326
+ data: unknown
1327
+ }
1328
+ | {
1329
+ type: 'focused'
1330
+ event: FocusEvent_2<HTMLDivElement, Element>
1331
+ }
1332
+ | {
1333
+ type: 'invalid value'
1334
+ resolution: InvalidValueResolution | null
1335
+ value: Array<PortableTextBlock> | undefined
1336
+ }
1337
+ | {
1338
+ type: 'loading'
1339
+ }
1340
+ | {
1341
+ type: 'read only'
1342
+ }
1343
+ | {
1344
+ type: 'ready'
1345
+ }
1346
+ | {
1347
+ type: 'selection'
1348
+ selection: EditorSelection
1349
+ }
1350
+ | {
1351
+ type: 'value changed'
1352
+ value: Array<PortableTextBlock> | undefined
1353
+ }
1354
+ >,
1213
1355
  ]
1214
1356
  }
1215
1357
  }
@@ -2494,6 +2636,17 @@ export declare const getLastBlock: EditorSelector<
2494
2636
  | undefined
2495
2637
  >
2496
2638
 
2639
+ /**
2640
+ * @beta
2641
+ * Given the `path` of a block, this selector will return the `ListState` of
2642
+ * the block.
2643
+ */
2644
+ export declare function getListState({
2645
+ path,
2646
+ }: {
2647
+ path: BlockPath
2648
+ }): EditorSelector<ListState | undefined>
2649
+
2497
2650
  /**
2498
2651
  * @public
2499
2652
  */
@@ -2761,6 +2914,14 @@ declare type KeyboardBehaviorEvent =
2761
2914
  >
2762
2915
  }
2763
2916
 
2917
+ /**
2918
+ * @beta
2919
+ * Represents the List state of a block.
2920
+ */
2921
+ declare type ListState = {
2922
+ index: number
2923
+ }
2924
+
2764
2925
  declare type MIMEType = `${string}/${string}`
2765
2926
 
2766
2927
  declare type MouseBehaviorEvent = {
@@ -2,8 +2,8 @@ import { getSelectionEndPoint } from "../_chunks-es/selector.is-selecting-entire
2
2
  import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFocusInlineObject, getNextInlineObject, getSelectedSpans, getSelectedTextBlocks, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
3
3
  import { isKeyedSegment, isTextBlock, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
4
4
  import { isPortableTextSpan } from "@sanity/types";
5
- import { getSelectionStartPoint } from "../_chunks-es/selector.is-selection-expanded.js";
6
- import { getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
5
+ import { getSelectionStartPoint, getFocusTextBlock, getPreviousBlock } from "../_chunks-es/selector.is-selection-expanded.js";
6
+ import { getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getLastBlock, getNextBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
7
7
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
8
8
  const getAnchorBlock = (snapshot) => {
9
9
  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;
@@ -53,7 +53,100 @@ const getAnchorBlock = (snapshot) => {
53
53
  start,
54
54
  end
55
55
  } : void 0;
56
- }, getSelection = (snapshot) => snapshot.context.selection, getValue = (snapshot) => snapshot.context.value;
56
+ };
57
+ function getListState({
58
+ path
59
+ }) {
60
+ return (snapshot) => {
61
+ const selection = {
62
+ anchor: {
63
+ path,
64
+ offset: 0
65
+ },
66
+ focus: {
67
+ path,
68
+ offset: 0
69
+ }
70
+ }, focusTextBlock = getFocusTextBlock({
71
+ context: {
72
+ ...snapshot.context,
73
+ selection
74
+ }
75
+ });
76
+ if (!focusTextBlock || focusTextBlock.node.listItem === void 0 || focusTextBlock.node.level === void 0)
77
+ return;
78
+ const previousListItem = getPreviousListItem({
79
+ listItem: focusTextBlock.node.listItem,
80
+ level: focusTextBlock.node.level
81
+ })({
82
+ ...snapshot,
83
+ context: {
84
+ ...snapshot.context,
85
+ selection
86
+ }
87
+ });
88
+ if (!previousListItem)
89
+ return {
90
+ index: 1
91
+ };
92
+ if (previousListItem.node.listItem !== focusTextBlock.node.listItem)
93
+ return {
94
+ index: 1
95
+ };
96
+ if (previousListItem.node.level !== void 0 && previousListItem.node.level < focusTextBlock.node.level)
97
+ return {
98
+ index: 1
99
+ };
100
+ const previousListItemListState = getListState({
101
+ path: previousListItem.path
102
+ })(snapshot);
103
+ return previousListItemListState === void 0 ? {
104
+ index: 1
105
+ } : {
106
+ index: previousListItemListState.index + 1
107
+ };
108
+ };
109
+ }
110
+ function getPreviousListItem({
111
+ listItem,
112
+ level
113
+ }) {
114
+ return (snapshot) => {
115
+ const previousBlock = getPreviousBlock({
116
+ context: {
117
+ ...snapshot.context
118
+ }
119
+ });
120
+ if (previousBlock && isTextBlock(snapshot.context, previousBlock.node) && !(previousBlock.node.listItem === void 0 || previousBlock.node.level === void 0) && previousBlock.node.listItem === listItem) {
121
+ if (previousBlock.node.level === level)
122
+ return {
123
+ node: previousBlock.node,
124
+ path: previousBlock.path
125
+ };
126
+ if (!(previousBlock.node.level < level))
127
+ return getPreviousListItem({
128
+ listItem,
129
+ level
130
+ })({
131
+ ...snapshot,
132
+ context: {
133
+ ...snapshot.context,
134
+ selection: {
135
+ anchor: {
136
+ path: previousBlock.path,
137
+ offset: 0
138
+ },
139
+ focus: {
140
+ path: previousBlock.path,
141
+ offset: 0
142
+ }
143
+ }
144
+ }
145
+ });
146
+ }
147
+ };
148
+ }
149
+ const getSelection = (snapshot) => snapshot.context.selection, getValue = (snapshot) => snapshot.context.value;
57
150
  export {
58
151
  getActiveAnnotations,
59
152
  getActiveListItem,
@@ -74,6 +167,7 @@ export {
74
167
  getFocusSpan,
75
168
  getFocusTextBlock,
76
169
  getLastBlock,
170
+ getListState,
77
171
  getNextBlock,
78
172
  getNextInlineObject,
79
173
  getPreviousBlock,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\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 {isKeyedSegment} from '../utils'\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 const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\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 {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","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCbaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASE,SAASY,YAAYL,IAAI,IAChE;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCPaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMb,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTa,YAAYL,KAAKQ,SAASN,KAAMO,CAAAA,SAASA,KAAKX,SAASN,GAAG,IAC1DO;AAEJ,SAAOC,QAAQR,MACX;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC,GAAGQ,YAAYR,MAAM,YAAY;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DO;AACN,GC3BaW,gBAGRnB,CAAa,aAAA;AACVoB,QAAAA,cAAcJ,eAAehB,QAAQ;AAE3C,SAAOoB,eAAeC,mBAAmBD,YAAYX,IAAI,IACrD;AAAA,IAACA,MAAMW,YAAYX;AAAAA,IAAMH,MAAMc,YAAYd;AAAAA,EAAAA,IAC3CE;AACN,GCRac,kBAERtB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASE,QAAQC;AACpB;AAGF,QAAMoB,sBAAsBC,uBAAuBxB,QAAQ,GACrDyB,oBAAoBC,qBAAqB1B,QAAQ;AAEnD,MAAA,CAACuB,uBAAuB,CAACE;AAC3B;AAGIE,QAAAA,QAAQC,gCAAsC;AAAA,IAClD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,gCAAsC;AAAA,IAChD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOtB;AACvC,GC3BauB,eAAiD/B,CACrDA,aAAAA,SAASE,QAAQC,WCDb6B,WACXhC,CAEOA,aAAAA,SAASE,QAAQQ;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\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 {isKeyedSegment} from '../utils'\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 const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock, getPreviousBlock} from './selectors'\n\n/**\n * @beta\n * Represents the List state of a block.\n */\nexport type ListState = {\n index: number\n}\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the `ListState` of\n * the block.\n */\nexport function getListState({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<ListState | 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 {\n index: 1,\n }\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return {\n index: 1,\n }\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return {\n index: 1,\n }\n }\n\n const previousListItemListState = getListState({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return {\n index: 1,\n }\n }\n\n return {\n index: previousListItemListState.index + 1,\n }\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","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListState","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","index","previousListItemListState","previousBlock","getPreviousBlock","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCbaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASE,SAASY,YAAYL,IAAI,IAChE;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCPaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AA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AAED,QAAKwC,iBAIA3B,YAAYf,SAASE,SAASwC,cAAcjC,IAAI,KAKnDiC,EAAcjC,cAAAA,KAAK2B,aAAa5B,UAChCkC,cAAcjC,KAAK4B,UAAU7B,WAK3BkC,cAAcjC,KAAK2B,aAAaA,UAIpC;AAAIM,UAAAA,cAAcjC,KAAK4B,UAAUA;AACxB,eAAA;AAAA,UACL5B,MAAMiC,cAAcjC;AAAAA,UACpBH,MAAMoC,cAAcpC;AAAAA,QACtB;AAGEoC,UAAAA,EAAAA,cAAcjC,KAAK4B,QAAQA;AAI/B,eAAOE,oBAAoB;AAAA,UACzBH;AAAAA,UACAC;AAAAA,QAAAA,CACD,EAAE;AAAA,UACD,GAAGrC;AAAAA,UACHE,SAAS;AAAA,YACP,GAAGF,SAASE;AAAAA,YACZC,WAAW;AAAA,cACTE,QAAQ;AAAA,gBACNC,MAAMoC,cAAcpC;AAAAA,gBACpB0B,QAAQ;AAAA,cACV;AAAA,cACAC,OAAO;AAAA,gBACL3B,MAAMoC,cAAcpC;AAAAA,gBACpB0B,QAAQ;AAAA,cAAA;AAAA,YACV;AAAA,UACF;AAAA,QACF,CACD;AAAA,IAAA;AAAA,EACH;AACF;ACxKaY,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASE,QAAQC,WCDb0C,WACX7C,CAEOA,aAAAA,SAASE,QAAQQ;"}
@@ -1280,6 +1280,142 @@ declare const editorMachine: StateMachine<
1280
1280
  never,
1281
1281
  never
1282
1282
  >,
1283
+ ActionFunction<
1284
+ {
1285
+ behaviors: Set<BehaviorConfig>
1286
+ converters: Set<Converter>
1287
+ getLegacySchema: () => PortableTextMemberSchemaTypes
1288
+ keyGenerator: () => string
1289
+ pendingEvents: Array<InternalPatchEvent | MutationEvent>
1290
+ pendingIncomingPatchesEvents: Array<PatchesEvent>
1291
+ schema: EditorSchema
1292
+ initialReadOnly: boolean
1293
+ maxBlocks: number | undefined
1294
+ selection: EditorSelection
1295
+ initialValue: Array<PortableTextBlock> | undefined
1296
+ internalDrag?: {
1297
+ ghost?: HTMLElement
1298
+ origin: Pick<EventPosition, 'selection'>
1299
+ }
1300
+ slateEditor?: PortableTextSlateEditor
1301
+ },
1302
+ {
1303
+ type: 'update selection'
1304
+ selection: EditorSelection
1305
+ },
1306
+ | InternalPatchEvent
1307
+ | MutationEvent
1308
+ | PatchesEvent
1309
+ | {
1310
+ type: 'update readOnly'
1311
+ readOnly: boolean
1312
+ }
1313
+ | {
1314
+ type: 'update maxBlocks'
1315
+ maxBlocks: number | undefined
1316
+ }
1317
+ | {
1318
+ type: 'add behavior'
1319
+ behaviorConfig: BehaviorConfig
1320
+ }
1321
+ | {
1322
+ type: 'remove behavior'
1323
+ behaviorConfig: BehaviorConfig
1324
+ }
1325
+ | {
1326
+ type: 'blur'
1327
+ editor: PortableTextSlateEditor
1328
+ }
1329
+ | {
1330
+ type: 'focus'
1331
+ editor: PortableTextSlateEditor
1332
+ }
1333
+ | {
1334
+ type: 'normalizing'
1335
+ }
1336
+ | {
1337
+ type: 'update selection'
1338
+ selection: EditorSelection
1339
+ }
1340
+ | {
1341
+ type: 'done normalizing'
1342
+ }
1343
+ | {
1344
+ type: 'done syncing value'
1345
+ }
1346
+ | {
1347
+ type: 'syncing value'
1348
+ }
1349
+ | {
1350
+ type: 'behavior event'
1351
+ behaviorEvent: BehaviorEvent
1352
+ editor: PortableTextSlateEditor
1353
+ nativeEvent?: {
1354
+ preventDefault: () => void
1355
+ }
1356
+ }
1357
+ | {
1358
+ type: 'dragstart'
1359
+ origin: Pick<EventPosition, 'selection'>
1360
+ ghost?: HTMLElement
1361
+ }
1362
+ | {
1363
+ type: 'dragend'
1364
+ }
1365
+ | {
1366
+ type: 'drop'
1367
+ },
1368
+ undefined,
1369
+ never,
1370
+ never,
1371
+ never,
1372
+ never,
1373
+ | InternalPatchEvent
1374
+ | MutationEvent
1375
+ | PatchesEvent
1376
+ | {
1377
+ type: 'blurred'
1378
+ event: FocusEvent_2<HTMLDivElement, Element>
1379
+ }
1380
+ | {
1381
+ type: 'done loading'
1382
+ }
1383
+ | {
1384
+ type: 'editable'
1385
+ }
1386
+ | {
1387
+ type: 'error'
1388
+ name: string
1389
+ description: string
1390
+ data: unknown
1391
+ }
1392
+ | {
1393
+ type: 'focused'
1394
+ event: FocusEvent_2<HTMLDivElement, Element>
1395
+ }
1396
+ | {
1397
+ type: 'invalid value'
1398
+ resolution: InvalidValueResolution | null
1399
+ value: Array<PortableTextBlock> | undefined
1400
+ }
1401
+ | {
1402
+ type: 'loading'
1403
+ }
1404
+ | {
1405
+ type: 'read only'
1406
+ }
1407
+ | {
1408
+ type: 'ready'
1409
+ }
1410
+ | {
1411
+ type: 'selection'
1412
+ selection: EditorSelection
1413
+ }
1414
+ | {
1415
+ type: 'value changed'
1416
+ value: Array<PortableTextBlock> | undefined
1417
+ }
1418
+ >,
1283
1419
  ]
1284
1420
  }
1285
1421
  }
@@ -1280,6 +1280,142 @@ declare const editorMachine: StateMachine<
1280
1280
  never,
1281
1281
  never
1282
1282
  >,
1283
+ ActionFunction<
1284
+ {
1285
+ behaviors: Set<BehaviorConfig>
1286
+ converters: Set<Converter>
1287
+ getLegacySchema: () => PortableTextMemberSchemaTypes
1288
+ keyGenerator: () => string
1289
+ pendingEvents: Array<InternalPatchEvent | MutationEvent>
1290
+ pendingIncomingPatchesEvents: Array<PatchesEvent>
1291
+ schema: EditorSchema
1292
+ initialReadOnly: boolean
1293
+ maxBlocks: number | undefined
1294
+ selection: EditorSelection
1295
+ initialValue: Array<PortableTextBlock> | undefined
1296
+ internalDrag?: {
1297
+ ghost?: HTMLElement
1298
+ origin: Pick<EventPosition, 'selection'>
1299
+ }
1300
+ slateEditor?: PortableTextSlateEditor
1301
+ },
1302
+ {
1303
+ type: 'update selection'
1304
+ selection: EditorSelection
1305
+ },
1306
+ | InternalPatchEvent
1307
+ | MutationEvent
1308
+ | PatchesEvent
1309
+ | {
1310
+ type: 'update readOnly'
1311
+ readOnly: boolean
1312
+ }
1313
+ | {
1314
+ type: 'update maxBlocks'
1315
+ maxBlocks: number | undefined
1316
+ }
1317
+ | {
1318
+ type: 'add behavior'
1319
+ behaviorConfig: BehaviorConfig
1320
+ }
1321
+ | {
1322
+ type: 'remove behavior'
1323
+ behaviorConfig: BehaviorConfig
1324
+ }
1325
+ | {
1326
+ type: 'blur'
1327
+ editor: PortableTextSlateEditor
1328
+ }
1329
+ | {
1330
+ type: 'focus'
1331
+ editor: PortableTextSlateEditor
1332
+ }
1333
+ | {
1334
+ type: 'normalizing'
1335
+ }
1336
+ | {
1337
+ type: 'update selection'
1338
+ selection: EditorSelection
1339
+ }
1340
+ | {
1341
+ type: 'done normalizing'
1342
+ }
1343
+ | {
1344
+ type: 'done syncing value'
1345
+ }
1346
+ | {
1347
+ type: 'syncing value'
1348
+ }
1349
+ | {
1350
+ type: 'behavior event'
1351
+ behaviorEvent: BehaviorEvent
1352
+ editor: PortableTextSlateEditor
1353
+ nativeEvent?: {
1354
+ preventDefault: () => void
1355
+ }
1356
+ }
1357
+ | {
1358
+ type: 'dragstart'
1359
+ origin: Pick<EventPosition, 'selection'>
1360
+ ghost?: HTMLElement
1361
+ }
1362
+ | {
1363
+ type: 'dragend'
1364
+ }
1365
+ | {
1366
+ type: 'drop'
1367
+ },
1368
+ undefined,
1369
+ never,
1370
+ never,
1371
+ never,
1372
+ never,
1373
+ | InternalPatchEvent
1374
+ | MutationEvent
1375
+ | PatchesEvent
1376
+ | {
1377
+ type: 'blurred'
1378
+ event: FocusEvent_2<HTMLDivElement, Element>
1379
+ }
1380
+ | {
1381
+ type: 'done loading'
1382
+ }
1383
+ | {
1384
+ type: 'editable'
1385
+ }
1386
+ | {
1387
+ type: 'error'
1388
+ name: string
1389
+ description: string
1390
+ data: unknown
1391
+ }
1392
+ | {
1393
+ type: 'focused'
1394
+ event: FocusEvent_2<HTMLDivElement, Element>
1395
+ }
1396
+ | {
1397
+ type: 'invalid value'
1398
+ resolution: InvalidValueResolution | null
1399
+ value: Array<PortableTextBlock> | undefined
1400
+ }
1401
+ | {
1402
+ type: 'loading'
1403
+ }
1404
+ | {
1405
+ type: 'read only'
1406
+ }
1407
+ | {
1408
+ type: 'ready'
1409
+ }
1410
+ | {
1411
+ type: 'selection'
1412
+ selection: EditorSelection
1413
+ }
1414
+ | {
1415
+ type: 'value changed'
1416
+ value: Array<PortableTextBlock> | undefined
1417
+ }
1418
+ >,
1283
1419
  ]
1284
1420
  }
1285
1421
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.49.12",
3
+ "version": "1.50.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -79,8 +79,8 @@
79
79
  "slate-react": "0.114.2",
80
80
  "use-effect-event": "^1.0.2",
81
81
  "xstate": "^5.19.2",
82
- "@portabletext/block-tools": "1.1.26",
83
- "@portabletext/patches": "1.1.3"
82
+ "@portabletext/patches": "1.1.3",
83
+ "@portabletext/block-tools": "1.1.26"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@portabletext/toolkit": "^2.0.17",