@portabletext/editor 1.53.1 → 1.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/selection-point.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
- package/lib/_chunks-es/selection-point.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +68 -9
- package/lib/behaviors/index.d.ts +68 -9
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +526 -286
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +69 -13
- package/lib/index.d.ts +69 -13
- package/lib/index.js +530 -290
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +69 -9
- package/lib/plugins/index.d.ts +69 -9
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +31 -16
- package/lib/selectors/index.d.ts +31 -16
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +27 -5
- package/lib/utils/index.d.ts +27 -5
- package/package.json +3 -3
- package/src/behaviors/behavior.abstract.annotation.ts +51 -0
- package/src/behaviors/behavior.abstract.delete.ts +55 -0
- package/src/behaviors/behavior.perform-event.ts +6 -11
- package/src/behaviors/behavior.types.action.ts +1 -1
- package/src/behaviors/behavior.types.event.ts +32 -8
- package/src/behaviors/behavior.types.guard.ts +1 -1
- package/src/editor/PortableTextEditor.tsx +1 -6
- package/src/editor/create-editor.ts +5 -0
- package/src/{internal-utils/selection-elements.ts → editor/editor-dom.ts} +29 -21
- package/src/editor/editor-provider.tsx +1 -6
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +6 -46
- package/src/editor/plugins/createWithPatches.ts +1 -5
- package/src/editor.ts +2 -0
- package/src/index.ts +2 -0
- package/src/operations/behavior.operation.child.set.ts +103 -0
- package/src/operations/behavior.operation.child.unset.ts +89 -0
- package/src/operations/behavior.operations.ts +18 -0
- package/src/selectors/selector.get-anchor-block.ts +3 -2
- package/src/selectors/selector.get-anchor-child.ts +2 -2
- package/src/selectors/selector.get-anchor-span.ts +2 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -2
- package/src/selectors/selector.get-focus-child.ts +3 -6
- package/src/selectors/selector.get-focus-inline-object.ts +3 -7
- package/src/selectors/selector.get-focus-span.ts +3 -3
- package/src/selectors/selector.get-next-inline-object.ts +4 -7
- package/src/selectors/selector.get-previous-block.ts +2 -2
- package/src/selectors/selector.get-previous-inline-object.ts +4 -7
- package/src/selectors/selector.get-selected-blocks.ts +2 -3
- package/src/selectors/selector.get-selected-spans.test.ts +96 -0
- package/src/selectors/selector.get-selected-spans.ts +4 -3
- package/src/selectors/selector.get-selected-text-blocks.ts +4 -3
- package/src/selectors/selector.is-at-the-end-of-block.ts +3 -2
- package/src/selectors/selector.is-at-the-start-of-block.ts +3 -2
- package/src/types/block-offset.ts +2 -2
- package/src/types/paths.ts +13 -0
- package/src/utils/util.block-offset.ts +2 -4
- package/src/utils/util.get-block-end-point.ts +3 -2
- package/src/utils/util.get-block-start-point.ts +3 -2
package/lib/index.d.cts
CHANGED
|
@@ -5,16 +5,15 @@ import type {
|
|
|
5
5
|
BlockDecoratorDefinition,
|
|
6
6
|
BlockListDefinition,
|
|
7
7
|
BlockStyleDefinition,
|
|
8
|
-
KeyedSegment,
|
|
9
8
|
ObjectSchemaType,
|
|
10
9
|
Path,
|
|
11
10
|
PortableTextListBlock,
|
|
12
|
-
PortableTextObject,
|
|
13
11
|
TypedObject,
|
|
14
12
|
} from '@sanity/types'
|
|
15
13
|
import {
|
|
16
14
|
PortableTextBlock,
|
|
17
15
|
PortableTextChild,
|
|
16
|
+
PortableTextObject,
|
|
18
17
|
PortableTextSpan,
|
|
19
18
|
PortableTextTextBlock,
|
|
20
19
|
} from '@sanity/types'
|
|
@@ -69,6 +68,11 @@ import {
|
|
|
69
68
|
} from '..'
|
|
70
69
|
|
|
71
70
|
declare type AbstractBehaviorEvent =
|
|
71
|
+
| {
|
|
72
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
|
|
73
|
+
at: AnnotationPath
|
|
74
|
+
props: Record<string, unknown>
|
|
75
|
+
}
|
|
72
76
|
| {
|
|
73
77
|
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
|
|
74
78
|
annotation: {
|
|
@@ -92,7 +96,11 @@ declare type AbstractBehaviorEvent =
|
|
|
92
96
|
}
|
|
93
97
|
| {
|
|
94
98
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
|
|
95
|
-
at:
|
|
99
|
+
at: BlockPath
|
|
100
|
+
}
|
|
101
|
+
| {
|
|
102
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
|
|
103
|
+
at: ChildPath
|
|
96
104
|
}
|
|
97
105
|
| {
|
|
98
106
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
@@ -193,11 +201,11 @@ declare type AbstractBehaviorEvent =
|
|
|
193
201
|
}
|
|
194
202
|
| {
|
|
195
203
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
|
|
196
|
-
at:
|
|
204
|
+
at: BlockPath
|
|
197
205
|
}
|
|
198
206
|
| {
|
|
199
207
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
|
|
200
|
-
at:
|
|
208
|
+
at: BlockPath
|
|
201
209
|
}
|
|
202
210
|
| {
|
|
203
211
|
type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
|
|
@@ -227,10 +235,12 @@ declare type AbstractBehaviorEvent =
|
|
|
227
235
|
* Abstract events
|
|
228
236
|
**************************************/
|
|
229
237
|
declare const abstractBehaviorEventTypes: readonly [
|
|
238
|
+
'annotation.set',
|
|
230
239
|
'annotation.toggle',
|
|
231
240
|
'decorator.toggle',
|
|
232
241
|
'delete.backward',
|
|
233
242
|
'delete.block',
|
|
243
|
+
'delete.child',
|
|
234
244
|
'delete.forward',
|
|
235
245
|
'delete.text',
|
|
236
246
|
'deserialize',
|
|
@@ -273,6 +283,19 @@ export declare type AddedAnnotationPaths = {
|
|
|
273
283
|
spanPath: Path
|
|
274
284
|
}
|
|
275
285
|
|
|
286
|
+
/**
|
|
287
|
+
* @public
|
|
288
|
+
*/
|
|
289
|
+
export declare type AnnotationPath = [
|
|
290
|
+
{
|
|
291
|
+
_key: string
|
|
292
|
+
},
|
|
293
|
+
'markDefs',
|
|
294
|
+
{
|
|
295
|
+
_key: string
|
|
296
|
+
},
|
|
297
|
+
]
|
|
298
|
+
|
|
276
299
|
/**
|
|
277
300
|
* @public
|
|
278
301
|
*/
|
|
@@ -431,11 +454,14 @@ export declare interface BlockListItemRenderProps {
|
|
|
431
454
|
* @beta
|
|
432
455
|
*/
|
|
433
456
|
export declare type BlockOffset = {
|
|
434
|
-
path:
|
|
457
|
+
path: BlockPath
|
|
435
458
|
offset: number
|
|
436
459
|
}
|
|
437
460
|
|
|
438
|
-
|
|
461
|
+
/**
|
|
462
|
+
* @public
|
|
463
|
+
*/
|
|
464
|
+
export declare type BlockPath = [
|
|
439
465
|
{
|
|
440
466
|
_key: string
|
|
441
467
|
},
|
|
@@ -481,6 +507,19 @@ export declare type BlurChange = {
|
|
|
481
507
|
event: FocusEvent_2<HTMLDivElement, Element>
|
|
482
508
|
}
|
|
483
509
|
|
|
510
|
+
/**
|
|
511
|
+
* @public
|
|
512
|
+
*/
|
|
513
|
+
export declare type ChildPath = [
|
|
514
|
+
{
|
|
515
|
+
_key: string
|
|
516
|
+
},
|
|
517
|
+
'children',
|
|
518
|
+
{
|
|
519
|
+
_key: string
|
|
520
|
+
},
|
|
521
|
+
]
|
|
522
|
+
|
|
484
523
|
declare type ClipboardBehaviorEvent =
|
|
485
524
|
| {
|
|
486
525
|
type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
|
|
@@ -761,6 +800,7 @@ export declare interface EditableAPIDeleteOptions {
|
|
|
761
800
|
* @public
|
|
762
801
|
*/
|
|
763
802
|
export declare type Editor = {
|
|
803
|
+
dom: EditorDom
|
|
764
804
|
getSnapshot: () => EditorSnapshot
|
|
765
805
|
/**
|
|
766
806
|
* @beta
|
|
@@ -3666,9 +3706,9 @@ export declare class PortableTextEditor extends Component<
|
|
|
3666
3706
|
path: Path,
|
|
3667
3707
|
) => [
|
|
3668
3708
|
(
|
|
3669
|
-
| PortableTextTextBlock<PortableTextObject | PortableTextSpan>
|
|
3670
|
-
| PortableTextObject
|
|
3671
3709
|
| PortableTextSpan
|
|
3710
|
+
| PortableTextObject
|
|
3711
|
+
| PortableTextTextBlock<PortableTextSpan | PortableTextObject>
|
|
3672
3712
|
| undefined
|
|
3673
3713
|
),
|
|
3674
3714
|
Path | undefined,
|
|
@@ -4079,6 +4119,8 @@ export declare type PortableTextMemberSchemaTypes = {
|
|
|
4079
4119
|
lists: BlockListDefinition[]
|
|
4080
4120
|
}
|
|
4081
4121
|
|
|
4122
|
+
export {PortableTextObject}
|
|
4123
|
+
|
|
4082
4124
|
declare interface PortableTextSlateEditor extends ReactEditor {
|
|
4083
4125
|
_key: 'editor'
|
|
4084
4126
|
_type: 'editor'
|
|
@@ -4321,12 +4363,24 @@ declare type SyntheticBehaviorEvent =
|
|
|
4321
4363
|
}
|
|
4322
4364
|
| {
|
|
4323
4365
|
type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
|
|
4324
|
-
at:
|
|
4366
|
+
at: BlockPath
|
|
4325
4367
|
props: Record<string, unknown>
|
|
4326
4368
|
}
|
|
4327
4369
|
| {
|
|
4328
4370
|
type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
|
|
4329
|
-
at:
|
|
4371
|
+
at: BlockPath
|
|
4372
|
+
props: Array<string>
|
|
4373
|
+
}
|
|
4374
|
+
| {
|
|
4375
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'child.set'>
|
|
4376
|
+
at: ChildPath
|
|
4377
|
+
props: {
|
|
4378
|
+
[prop: string]: unknown
|
|
4379
|
+
}
|
|
4380
|
+
}
|
|
4381
|
+
| {
|
|
4382
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'child.unset'>
|
|
4383
|
+
at: ChildPath
|
|
4330
4384
|
props: Array<string>
|
|
4331
4385
|
}
|
|
4332
4386
|
| {
|
|
@@ -4395,8 +4449,8 @@ declare type SyntheticBehaviorEvent =
|
|
|
4395
4449
|
}
|
|
4396
4450
|
| {
|
|
4397
4451
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
4398
|
-
at:
|
|
4399
|
-
to:
|
|
4452
|
+
at: BlockPath
|
|
4453
|
+
to: BlockPath
|
|
4400
4454
|
}
|
|
4401
4455
|
| {
|
|
4402
4456
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
@@ -4423,6 +4477,8 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
4423
4477
|
'annotation.remove',
|
|
4424
4478
|
'block.set',
|
|
4425
4479
|
'block.unset',
|
|
4480
|
+
'child.set',
|
|
4481
|
+
'child.unset',
|
|
4426
4482
|
'decorator.add',
|
|
4427
4483
|
'decorator.remove',
|
|
4428
4484
|
'delete',
|
package/lib/index.d.ts
CHANGED
|
@@ -5,16 +5,15 @@ import type {
|
|
|
5
5
|
BlockDecoratorDefinition,
|
|
6
6
|
BlockListDefinition,
|
|
7
7
|
BlockStyleDefinition,
|
|
8
|
-
KeyedSegment,
|
|
9
8
|
ObjectSchemaType,
|
|
10
9
|
Path,
|
|
11
10
|
PortableTextListBlock,
|
|
12
|
-
PortableTextObject,
|
|
13
11
|
TypedObject,
|
|
14
12
|
} from '@sanity/types'
|
|
15
13
|
import {
|
|
16
14
|
PortableTextBlock,
|
|
17
15
|
PortableTextChild,
|
|
16
|
+
PortableTextObject,
|
|
18
17
|
PortableTextSpan,
|
|
19
18
|
PortableTextTextBlock,
|
|
20
19
|
} from '@sanity/types'
|
|
@@ -69,6 +68,11 @@ import {
|
|
|
69
68
|
} from '..'
|
|
70
69
|
|
|
71
70
|
declare type AbstractBehaviorEvent =
|
|
71
|
+
| {
|
|
72
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
|
|
73
|
+
at: AnnotationPath
|
|
74
|
+
props: Record<string, unknown>
|
|
75
|
+
}
|
|
72
76
|
| {
|
|
73
77
|
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
|
|
74
78
|
annotation: {
|
|
@@ -92,7 +96,11 @@ declare type AbstractBehaviorEvent =
|
|
|
92
96
|
}
|
|
93
97
|
| {
|
|
94
98
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
|
|
95
|
-
at:
|
|
99
|
+
at: BlockPath
|
|
100
|
+
}
|
|
101
|
+
| {
|
|
102
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
|
|
103
|
+
at: ChildPath
|
|
96
104
|
}
|
|
97
105
|
| {
|
|
98
106
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
@@ -193,11 +201,11 @@ declare type AbstractBehaviorEvent =
|
|
|
193
201
|
}
|
|
194
202
|
| {
|
|
195
203
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
|
|
196
|
-
at:
|
|
204
|
+
at: BlockPath
|
|
197
205
|
}
|
|
198
206
|
| {
|
|
199
207
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
|
|
200
|
-
at:
|
|
208
|
+
at: BlockPath
|
|
201
209
|
}
|
|
202
210
|
| {
|
|
203
211
|
type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
|
|
@@ -227,10 +235,12 @@ declare type AbstractBehaviorEvent =
|
|
|
227
235
|
* Abstract events
|
|
228
236
|
**************************************/
|
|
229
237
|
declare const abstractBehaviorEventTypes: readonly [
|
|
238
|
+
'annotation.set',
|
|
230
239
|
'annotation.toggle',
|
|
231
240
|
'decorator.toggle',
|
|
232
241
|
'delete.backward',
|
|
233
242
|
'delete.block',
|
|
243
|
+
'delete.child',
|
|
234
244
|
'delete.forward',
|
|
235
245
|
'delete.text',
|
|
236
246
|
'deserialize',
|
|
@@ -273,6 +283,19 @@ export declare type AddedAnnotationPaths = {
|
|
|
273
283
|
spanPath: Path
|
|
274
284
|
}
|
|
275
285
|
|
|
286
|
+
/**
|
|
287
|
+
* @public
|
|
288
|
+
*/
|
|
289
|
+
export declare type AnnotationPath = [
|
|
290
|
+
{
|
|
291
|
+
_key: string
|
|
292
|
+
},
|
|
293
|
+
'markDefs',
|
|
294
|
+
{
|
|
295
|
+
_key: string
|
|
296
|
+
},
|
|
297
|
+
]
|
|
298
|
+
|
|
276
299
|
/**
|
|
277
300
|
* @public
|
|
278
301
|
*/
|
|
@@ -431,11 +454,14 @@ export declare interface BlockListItemRenderProps {
|
|
|
431
454
|
* @beta
|
|
432
455
|
*/
|
|
433
456
|
export declare type BlockOffset = {
|
|
434
|
-
path:
|
|
457
|
+
path: BlockPath
|
|
435
458
|
offset: number
|
|
436
459
|
}
|
|
437
460
|
|
|
438
|
-
|
|
461
|
+
/**
|
|
462
|
+
* @public
|
|
463
|
+
*/
|
|
464
|
+
export declare type BlockPath = [
|
|
439
465
|
{
|
|
440
466
|
_key: string
|
|
441
467
|
},
|
|
@@ -481,6 +507,19 @@ export declare type BlurChange = {
|
|
|
481
507
|
event: FocusEvent_2<HTMLDivElement, Element>
|
|
482
508
|
}
|
|
483
509
|
|
|
510
|
+
/**
|
|
511
|
+
* @public
|
|
512
|
+
*/
|
|
513
|
+
export declare type ChildPath = [
|
|
514
|
+
{
|
|
515
|
+
_key: string
|
|
516
|
+
},
|
|
517
|
+
'children',
|
|
518
|
+
{
|
|
519
|
+
_key: string
|
|
520
|
+
},
|
|
521
|
+
]
|
|
522
|
+
|
|
484
523
|
declare type ClipboardBehaviorEvent =
|
|
485
524
|
| {
|
|
486
525
|
type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
|
|
@@ -761,6 +800,7 @@ export declare interface EditableAPIDeleteOptions {
|
|
|
761
800
|
* @public
|
|
762
801
|
*/
|
|
763
802
|
export declare type Editor = {
|
|
803
|
+
dom: EditorDom
|
|
764
804
|
getSnapshot: () => EditorSnapshot
|
|
765
805
|
/**
|
|
766
806
|
* @beta
|
|
@@ -3666,9 +3706,9 @@ export declare class PortableTextEditor extends Component<
|
|
|
3666
3706
|
path: Path,
|
|
3667
3707
|
) => [
|
|
3668
3708
|
(
|
|
3669
|
-
| PortableTextTextBlock<PortableTextObject | PortableTextSpan>
|
|
3670
|
-
| PortableTextObject
|
|
3671
3709
|
| PortableTextSpan
|
|
3710
|
+
| PortableTextObject
|
|
3711
|
+
| PortableTextTextBlock<PortableTextSpan | PortableTextObject>
|
|
3672
3712
|
| undefined
|
|
3673
3713
|
),
|
|
3674
3714
|
Path | undefined,
|
|
@@ -4079,6 +4119,8 @@ export declare type PortableTextMemberSchemaTypes = {
|
|
|
4079
4119
|
lists: BlockListDefinition[]
|
|
4080
4120
|
}
|
|
4081
4121
|
|
|
4122
|
+
export {PortableTextObject}
|
|
4123
|
+
|
|
4082
4124
|
declare interface PortableTextSlateEditor extends ReactEditor {
|
|
4083
4125
|
_key: 'editor'
|
|
4084
4126
|
_type: 'editor'
|
|
@@ -4321,12 +4363,24 @@ declare type SyntheticBehaviorEvent =
|
|
|
4321
4363
|
}
|
|
4322
4364
|
| {
|
|
4323
4365
|
type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
|
|
4324
|
-
at:
|
|
4366
|
+
at: BlockPath
|
|
4325
4367
|
props: Record<string, unknown>
|
|
4326
4368
|
}
|
|
4327
4369
|
| {
|
|
4328
4370
|
type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
|
|
4329
|
-
at:
|
|
4371
|
+
at: BlockPath
|
|
4372
|
+
props: Array<string>
|
|
4373
|
+
}
|
|
4374
|
+
| {
|
|
4375
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'child.set'>
|
|
4376
|
+
at: ChildPath
|
|
4377
|
+
props: {
|
|
4378
|
+
[prop: string]: unknown
|
|
4379
|
+
}
|
|
4380
|
+
}
|
|
4381
|
+
| {
|
|
4382
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'child.unset'>
|
|
4383
|
+
at: ChildPath
|
|
4330
4384
|
props: Array<string>
|
|
4331
4385
|
}
|
|
4332
4386
|
| {
|
|
@@ -4395,8 +4449,8 @@ declare type SyntheticBehaviorEvent =
|
|
|
4395
4449
|
}
|
|
4396
4450
|
| {
|
|
4397
4451
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
4398
|
-
at:
|
|
4399
|
-
to:
|
|
4452
|
+
at: BlockPath
|
|
4453
|
+
to: BlockPath
|
|
4400
4454
|
}
|
|
4401
4455
|
| {
|
|
4402
4456
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
@@ -4423,6 +4477,8 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
4423
4477
|
'annotation.remove',
|
|
4424
4478
|
'block.set',
|
|
4425
4479
|
'block.unset',
|
|
4480
|
+
'child.set',
|
|
4481
|
+
'child.unset',
|
|
4426
4482
|
'decorator.add',
|
|
4427
4483
|
'decorator.remove',
|
|
4428
4484
|
'delete',
|