@portabletext/editor 1.58.0 → 2.0.0-canary.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.
@@ -1,487 +1,193 @@
1
- import type {
2
- KeyedSegment,
3
- Path,
4
- PortableTextBlock,
5
- PortableTextChild,
6
- PortableTextTextBlock,
7
- } from '@sanity/types'
8
- import {PortableTextObject, PortableTextSpan} from '@sanity/types'
9
-
1
+ import { BlockOffset, BlockPath, ChildPath, EditorContext, EditorSelection, EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.js";
2
+ import * as _sanity_types8 from "@sanity/types";
3
+ import { KeyedSegment, PortableTextBlock, PortableTextChild, PortableTextSpan, PortableTextTextBlock } from "@sanity/types";
10
4
  /**
11
5
  * @public
12
6
  */
13
- declare type AnnotationSchemaType = BaseDefinition & {
14
- fields: ReadonlyArray<FieldDefinition>
15
- }
16
-
17
- /**
18
- * @public
19
- */
20
- declare type BaseDefinition = {
21
- name: string
22
- title?: string
23
- }
24
-
25
- /**
26
- * @public
27
- */
28
- declare type BlockObjectSchemaType = BaseDefinition & {
29
- fields: ReadonlyArray<FieldDefinition>
30
- }
31
-
32
- /**
33
- * @beta
34
- */
35
- declare type BlockOffset = {
36
- path: BlockPath
37
- offset: number
38
- }
39
-
40
- /**
41
- * @public
42
- */
43
- export declare function blockOffsetsToSelection({
7
+ declare function blockOffsetToSpanSelectionPoint({
44
8
  context,
45
- offsets,
46
- backward,
9
+ blockOffset,
10
+ direction
47
11
  }: {
48
- context: Pick<EditorContext, 'schema' | 'value'>
49
- offsets: {
50
- anchor: BlockOffset
51
- focus: BlockOffset
52
- }
53
- backward?: boolean
54
- }): EditorSelection
55
-
12
+ context: Pick<EditorContext, 'schema' | 'value'>;
13
+ blockOffset: BlockOffset;
14
+ direction: 'forward' | 'backward';
15
+ }): {
16
+ path: ChildPath;
17
+ offset: number;
18
+ } | undefined;
56
19
  /**
57
20
  * @public
58
21
  */
59
- export declare function blockOffsetToBlockSelectionPoint({
22
+ declare function spanSelectionPointToBlockOffset({
60
23
  context,
61
- blockOffset,
24
+ selectionPoint
62
25
  }: {
63
- context: Pick<EditorContext, 'value'>
64
- blockOffset: BlockOffset
65
- }): EditorSelectionPoint | undefined
66
-
26
+ context: Pick<EditorContext, 'schema' | 'value'>;
27
+ selectionPoint: EditorSelectionPoint;
28
+ }): BlockOffset | undefined;
67
29
  /**
68
30
  * @public
69
31
  */
70
- export declare function blockOffsetToSelectionPoint({
32
+ declare function blockOffsetToBlockSelectionPoint({
71
33
  context,
72
- blockOffset,
73
- direction,
34
+ blockOffset
74
35
  }: {
75
- context: Pick<EditorContext, 'schema' | 'value'>
76
- blockOffset: BlockOffset
77
- direction: 'forward' | 'backward'
78
- }): EditorSelectionPoint | undefined
79
-
36
+ context: Pick<EditorContext, 'value'>;
37
+ blockOffset: BlockOffset;
38
+ }): EditorSelectionPoint | undefined;
80
39
  /**
81
40
  * @public
82
41
  */
83
- export declare function blockOffsetToSpanSelectionPoint({
42
+ declare function blockOffsetToSelectionPoint({
84
43
  context,
85
44
  blockOffset,
86
- direction,
45
+ direction
87
46
  }: {
88
- context: Pick<EditorContext, 'schema' | 'value'>
89
- blockOffset: BlockOffset
90
- direction: 'forward' | 'backward'
91
- }):
92
- | {
93
- path: ChildPath
94
- offset: number
95
- }
96
- | undefined
97
-
98
- /**
99
- * @public
100
- */
101
- declare type BlockPath = [
102
- {
103
- _key: string
104
- },
105
- ]
106
-
107
- /**
108
- * @public
109
- */
110
- declare type ChildPath = [
111
- {
112
- _key: string
113
- },
114
- 'children',
115
- {
116
- _key: string
117
- },
118
- ]
119
-
47
+ context: Pick<EditorContext, 'schema' | 'value'>;
48
+ blockOffset: BlockOffset;
49
+ direction: 'forward' | 'backward';
50
+ }): EditorSelectionPoint | undefined;
120
51
  /**
121
52
  * @public
122
53
  */
123
- export declare function childSelectionPointToBlockOffset({
54
+ declare function blockOffsetsToSelection({
124
55
  context,
125
- selectionPoint,
56
+ offsets,
57
+ backward
126
58
  }: {
127
- context: Pick<EditorContext, 'schema' | 'value'>
128
- selectionPoint: EditorSelectionPoint
129
- }): BlockOffset | undefined
130
-
131
- declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
132
- mimeType: TMIMEType
133
- serialize: Serializer<TMIMEType>
134
- deserialize: Deserializer<TMIMEType>
135
- }
136
-
137
- declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
138
- | {
139
- type: 'serialize'
140
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
141
- }
142
- | {
143
- type: 'serialization.failure'
144
- mimeType: TMIMEType
145
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
146
- reason: string
147
- }
148
- | {
149
- type: 'serialization.success'
150
- data: string
151
- mimeType: TMIMEType
152
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
153
- }
154
- | {
155
- type: 'deserialize'
156
- data: string
157
- }
158
- | {
159
- type: 'deserialization.failure'
160
- mimeType: TMIMEType
161
- reason: string
162
- }
163
- | {
164
- type: 'deserialization.success'
165
- data: Array<PortableTextBlock>
166
- mimeType: TMIMEType
167
- }
168
-
59
+ context: Pick<EditorContext, 'schema' | 'value'>;
60
+ offsets: {
61
+ anchor: BlockOffset;
62
+ focus: BlockOffset;
63
+ };
64
+ backward?: boolean;
65
+ }): EditorSelection;
169
66
  /**
170
67
  * @public
171
68
  */
172
- declare type DecoratorSchemaType = BaseDefinition & {
173
- /**
174
- * @deprecated
175
- * Use `name` instead
176
- */
177
- value: string
178
- }
179
-
180
- declare type Deserializer<TMIMEType extends MIMEType> = ({
181
- snapshot,
182
- event,
69
+ declare function childSelectionPointToBlockOffset({
70
+ context,
71
+ selectionPoint
183
72
  }: {
184
- snapshot: EditorSnapshot
185
- event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>
186
- }) => PickFromUnion<
187
- ConverterEvent<TMIMEType>,
188
- 'type',
189
- 'deserialization.success' | 'deserialization.failure'
190
- >
191
-
192
- /**
193
- * @public
194
- */
195
- declare type EditorContext = {
196
- converters: Array<Converter>
197
- keyGenerator: () => string
198
- readOnly: boolean
199
- schema: EditorSchema
200
- selection: EditorSelection
201
- value: Array<PortableTextBlock>
202
- }
203
-
73
+ context: Pick<EditorContext, 'schema' | 'value'>;
74
+ selectionPoint: EditorSelectionPoint;
75
+ }): BlockOffset | undefined;
204
76
  /**
205
77
  * @public
206
78
  */
207
- declare type EditorSchema = {
208
- annotations: ReadonlyArray<AnnotationSchemaType>
209
- block: {
210
- name: string
211
- }
212
- blockObjects: ReadonlyArray<BlockObjectSchemaType>
213
- decorators: ReadonlyArray<DecoratorSchemaType>
214
- inlineObjects: ReadonlyArray<InlineObjectSchemaType>
215
- span: {
216
- name: string
217
- }
218
- styles: ReadonlyArray<StyleSchemaType>
219
- lists: ReadonlyArray<ListSchemaType>
220
- }
221
-
222
- /** @public */
223
- declare type EditorSelection = {
224
- anchor: EditorSelectionPoint
225
- focus: EditorSelectionPoint
226
- backward?: boolean
227
- } | null
228
-
229
- /** @public */
230
- declare type EditorSelectionPoint = {
231
- path: Path
232
- offset: number
233
- }
234
-
235
- /**
236
- * @public
237
- */
238
- declare type EditorSnapshot = {
239
- context: EditorContext
240
- blockIndexMap: Map<string, number>
241
- /**
242
- * @beta
243
- * Subject to change
244
- */
245
- decoratorState: Record<string, boolean | undefined>
246
- }
247
-
248
- /**
249
- * @public
250
- */
251
- declare type FieldDefinition = BaseDefinition & {
252
- type: 'string' | 'number' | 'boolean' | 'array' | 'object'
253
- }
254
-
255
- /**
256
- * @public
257
- */
258
- export declare function getBlockEndPoint({
79
+ declare function getBlockEndPoint({
259
80
  context,
260
- block,
81
+ block
261
82
  }: {
262
- context: Pick<EditorContext, 'schema'>
83
+ context: Pick<EditorContext, 'schema'>;
263
84
  block: {
264
- node: PortableTextBlock
265
- path: BlockPath
266
- }
267
- }): EditorSelectionPoint
268
-
85
+ node: PortableTextBlock;
86
+ path: BlockPath;
87
+ };
88
+ }): EditorSelectionPoint;
269
89
  /**
270
90
  * @public
271
91
  */
272
- export declare function getBlockStartPoint({
92
+ declare function getBlockStartPoint({
273
93
  context,
274
- block,
94
+ block
275
95
  }: {
276
- context: Pick<EditorContext, 'schema'>
96
+ context: Pick<EditorContext, 'schema'>;
277
97
  block: {
278
- node: PortableTextBlock
279
- path: BlockPath
280
- }
281
- }): EditorSelectionPoint
282
-
283
- /**
284
- * @public
285
- */
286
- export declare function getSelectionEndPoint<
287
- TEditorSelection extends NonNullable<EditorSelection> | null,
288
- TEditorSelectionPoint extends
289
- EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>
290
- ? EditorSelectionPoint
291
- : null,
292
- >(selection: TEditorSelection): TEditorSelectionPoint
293
-
98
+ node: PortableTextBlock;
99
+ path: BlockPath;
100
+ };
101
+ }): EditorSelectionPoint;
294
102
  /**
295
103
  * @public
296
104
  */
297
- export declare function getSelectionStartPoint<
298
- TEditorSelection extends NonNullable<EditorSelection> | null,
299
- TEditorSelectionPoint extends
300
- EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>
301
- ? EditorSelectionPoint
302
- : null,
303
- >(selection: TEditorSelection): TEditorSelectionPoint
304
-
105
+ declare function getSelectionEndPoint<TEditorSelection extends NonNullable<EditorSelection> | null, TEditorSelectionPoint extends EditorSelectionPoint | null = (TEditorSelection extends NonNullable<EditorSelection> ? EditorSelectionPoint : null)>(selection: TEditorSelection): TEditorSelectionPoint;
305
106
  /**
306
107
  * @public
307
108
  */
308
- export declare function getTextBlockText(block: PortableTextTextBlock): string
309
-
109
+ declare function getSelectionStartPoint<TEditorSelection extends NonNullable<EditorSelection> | null, TEditorSelectionPoint extends EditorSelectionPoint | null = (TEditorSelection extends NonNullable<EditorSelection> ? EditorSelectionPoint : null)>(selection: TEditorSelection): TEditorSelectionPoint;
310
110
  /**
311
111
  * @public
312
112
  */
313
- declare type InlineObjectSchemaType = BaseDefinition & {
314
- fields: ReadonlyArray<FieldDefinition>
315
- }
316
-
113
+ declare function getTextBlockText(block: PortableTextTextBlock): string;
317
114
  /**
318
115
  * @public
319
116
  */
320
- export declare function isEmptyTextBlock(
321
- context: Pick<EditorContext, 'schema'>,
322
- block: PortableTextBlock,
323
- ): boolean
324
-
117
+ declare function isEmptyTextBlock(context: Pick<EditorContext, 'schema'>, block: PortableTextBlock): boolean;
325
118
  /**
326
119
  * @public
327
120
  */
328
- export declare function isEqualSelectionPoints(
329
- a: EditorSelectionPoint,
330
- b: EditorSelectionPoint,
331
- ): boolean
332
-
121
+ declare function isEqualSelectionPoints(a: EditorSelectionPoint, b: EditorSelectionPoint): boolean;
333
122
  /**
334
123
  * @public
335
124
  */
336
- export declare function isEqualSelections(
337
- a: EditorSelection,
338
- b: EditorSelection,
339
- ): boolean
340
-
125
+ declare function isEqualSelections(a: EditorSelection, b: EditorSelection): boolean;
341
126
  /**
342
127
  * @public
343
128
  */
344
- export declare function isKeyedSegment(
345
- segment: unknown,
346
- ): segment is KeyedSegment
347
-
129
+ declare function isKeyedSegment(segment: unknown): segment is KeyedSegment;
348
130
  /**
349
131
  * @public
350
132
  */
351
- export declare function isSelectionCollapsed(
352
- selection: EditorSelection,
353
- ): boolean
354
-
133
+ declare function isSelectionCollapsed(selection: EditorSelection): boolean;
355
134
  /**
356
135
  * @public
357
136
  */
358
- export declare function isSpan(
359
- context: Pick<EditorContext, 'schema'>,
360
- child: PortableTextChild,
361
- ): child is PortableTextSpan
362
-
137
+ declare function isSpan(context: Pick<EditorContext, 'schema'>, child: PortableTextChild): child is PortableTextSpan;
363
138
  /**
364
139
  * @public
365
140
  */
366
- export declare function isTextBlock(
367
- context: Pick<EditorContext, 'schema'>,
368
- block: unknown,
369
- ): block is PortableTextTextBlock
370
-
371
- /**
372
- * @public
373
- */
374
- declare type ListSchemaType = BaseDefinition & {
375
- /**
376
- * @deprecated
377
- * Use `name` instead
378
- */
379
- value: string
380
- }
381
-
141
+ declare function isTextBlock(context: Pick<EditorContext, 'schema'>, block: unknown): block is PortableTextTextBlock;
382
142
  /**
383
143
  * @beta
384
144
  */
385
- export declare function mergeTextBlocks({
145
+ declare function mergeTextBlocks({
386
146
  context,
387
147
  targetBlock,
388
- incomingBlock,
148
+ incomingBlock
389
149
  }: {
390
- context: Pick<EditorContext, 'keyGenerator' | 'schema'>
391
- targetBlock: PortableTextTextBlock
392
- incomingBlock: PortableTextTextBlock
393
- }): PortableTextTextBlock<PortableTextObject | PortableTextSpan>
394
-
395
- declare type MIMEType = `${string}/${string}`
396
-
397
- /**
398
- * @internal
399
- */
400
- declare type PickFromUnion<
401
- TUnion,
402
- TTagKey extends keyof TUnion,
403
- TPickedTags extends TUnion[TTagKey],
404
- > = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
405
-
406
- /**
407
- * @public
408
- */
409
- export declare function reverseSelection<
410
- TEditorSelection extends NonNullable<EditorSelection> | null,
411
- >(selection: TEditorSelection): TEditorSelection
412
-
150
+ context: Pick<EditorContext, 'keyGenerator' | 'schema'>;
151
+ targetBlock: PortableTextTextBlock;
152
+ incomingBlock: PortableTextTextBlock;
153
+ }): PortableTextTextBlock<_sanity_types8.PortableTextObject | _sanity_types8.PortableTextSpan>;
413
154
  /**
414
155
  * @public
415
156
  */
416
- export declare function selectionPointToBlockOffset({
417
- context,
418
- selectionPoint,
419
- }: {
420
- context: Pick<EditorContext, 'schema' | 'value'>
421
- selectionPoint: EditorSelectionPoint
422
- }): BlockOffset | undefined
423
-
424
- declare type Serializer<TMIMEType extends MIMEType> = ({
425
- snapshot,
426
- event,
427
- }: {
428
- snapshot: EditorSnapshot
429
- event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>
430
- }) => PickFromUnion<
431
- ConverterEvent<TMIMEType>,
432
- 'type',
433
- 'serialization.success' | 'serialization.failure'
434
- >
435
-
157
+ declare function reverseSelection<TEditorSelection extends NonNullable<EditorSelection> | null>(selection: TEditorSelection): TEditorSelection;
436
158
  /**
437
159
  * @public
438
160
  */
439
- export declare function sliceBlocks({
161
+ declare function selectionPointToBlockOffset({
440
162
  context,
441
- blocks,
163
+ selectionPoint
442
164
  }: {
443
- context: Pick<EditorContext, 'schema' | 'selection'>
444
- blocks: Array<PortableTextBlock>
445
- }): Array<PortableTextBlock>
446
-
165
+ context: Pick<EditorContext, 'schema' | 'value'>;
166
+ selectionPoint: EditorSelectionPoint;
167
+ }): BlockOffset | undefined;
447
168
  /**
448
169
  * @public
449
170
  */
450
- export declare function spanSelectionPointToBlockOffset({
171
+ declare function sliceBlocks({
451
172
  context,
452
- selectionPoint,
173
+ blocks
453
174
  }: {
454
- context: Pick<EditorContext, 'schema' | 'value'>
455
- selectionPoint: EditorSelectionPoint
456
- }): BlockOffset | undefined
457
-
175
+ context: Pick<EditorContext, 'schema' | 'selection'>;
176
+ blocks: Array<PortableTextBlock>;
177
+ }): Array<PortableTextBlock>;
458
178
  /**
459
179
  * @beta
460
180
  */
461
- export declare function splitTextBlock({
181
+ declare function splitTextBlock({
462
182
  context,
463
183
  block,
464
- point,
184
+ point
465
185
  }: {
466
- context: Pick<EditorContext, 'schema'>
467
- block: PortableTextTextBlock
468
- point: EditorSelectionPoint
469
- }):
470
- | {
471
- before: PortableTextTextBlock
472
- after: PortableTextTextBlock
473
- }
474
- | undefined
475
-
476
- /**
477
- * @public
478
- */
479
- declare type StyleSchemaType = BaseDefinition & {
480
- /**
481
- * @deprecated
482
- * Use `name` instead
483
- */
484
- value: string
485
- }
486
-
487
- export {}
186
+ context: Pick<EditorContext, 'schema'>;
187
+ block: PortableTextTextBlock;
188
+ point: EditorSelectionPoint;
189
+ }): {
190
+ before: PortableTextTextBlock;
191
+ after: PortableTextTextBlock;
192
+ } | undefined;
193
+ export { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetToSpanSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset, getBlockEndPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isEmptyTextBlock, isEqualSelectionPoints, isEqualSelections, isKeyedSegment, isSelectionCollapsed, isSpan, isTextBlock, mergeTextBlocks, reverseSelection, selectionPointToBlockOffset, sliceBlocks, spanSelectionPointToBlockOffset, splitTextBlock };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.58.0",
3
+ "version": "2.0.0-canary.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -80,16 +80,16 @@
80
80
  "slate-react": "0.117.3",
81
81
  "use-effect-event": "^1.0.2",
82
82
  "xstate": "^5.20.1",
83
- "@portabletext/block-tools": "1.1.38",
84
- "@portabletext/keyboard-shortcuts": "1.1.0",
85
- "@portabletext/patches": "1.1.5"
83
+ "@portabletext/block-tools": "2.0.0-canary.0",
84
+ "@portabletext/keyboard-shortcuts": "2.0.0-canary.0",
85
+ "@portabletext/patches": "2.0.0-canary.0"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@portabletext/toolkit": "^2.0.17",
89
89
  "@sanity/diff-match-patch": "^3.2.0",
90
- "@sanity/pkg-utils": "^7.9.3",
91
- "@sanity/schema": "^3.98.1",
92
- "@sanity/types": "^3.98.1",
90
+ "@sanity/pkg-utils": "^7.9.6",
91
+ "@sanity/schema": "^4.0.1",
92
+ "@sanity/types": "^4.0.1",
93
93
  "@testing-library/react": "^16.3.0",
94
94
  "@types/debug": "^4.1.12",
95
95
  "@types/lodash": "^4.17.16",
@@ -103,7 +103,7 @@
103
103
  "@vitest/coverage-istanbul": "^3.2.4",
104
104
  "babel-plugin-react-compiler": "19.1.0-rc.2",
105
105
  "eslint": "8.57.1",
106
- "eslint-plugin-react-hooks": "0.0.0-experimental-cee7939b-20250625",
106
+ "eslint-plugin-react-hooks": "0.0.0-experimental-97cdd5d3-20250710",
107
107
  "jsdom": "^26.0.0",
108
108
  "react": "^19.1.0",
109
109
  "react-dom": "^19.1.0",
@@ -115,13 +115,13 @@
115
115
  "racejar": "1.2.10"
116
116
  },
117
117
  "peerDependencies": {
118
- "@sanity/schema": "^3.98.0 || ^4.0.0-0",
119
- "@sanity/types": "^3.98.0 || ^4.0.0-0",
120
- "react": "^16.9 || ^17 || ^18 || ^19",
118
+ "@sanity/schema": "^4.0.1",
119
+ "@sanity/types": "^4.0.1",
120
+ "react": "^18.3 || ^19",
121
121
  "rxjs": "^7.8.2"
122
122
  },
123
123
  "engines": {
124
- "node": ">=18"
124
+ "node": ">=20.19"
125
125
  },
126
126
  "publishConfig": {
127
127
  "access": "public"