@portabletext/editor 1.39.0 → 1.39.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/behavior.core.cjs +4 -1
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +37 -52
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +0 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +0 -3
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +0 -4
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +5 -2
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +41 -56
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +1 -2
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1 -4
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +1 -5
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/behaviors/index.d.cts +1134 -801
- package/lib/behaviors/index.d.ts +1134 -801
- package/lib/index.cjs +0 -6
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +902 -627
- package/lib/index.d.ts +902 -627
- package/lib/index.js +0 -6
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +0 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +902 -627
- package/lib/plugins/index.d.ts +902 -627
- package/lib/plugins/index.js +1 -2
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +902 -627
- package/lib/selectors/index.d.ts +902 -627
- package/lib/utils/index.d.cts +902 -627
- package/lib/utils/index.d.ts +902 -627
- package/package.json +5 -5
- package/src/behaviors/behavior.default.ts +23 -4
- package/src/behaviors/behavior.types.ts +62 -26
- package/src/editor/editor-machine.ts +7 -1
- package/src/editor/plugins/create-with-event-listeners.ts +18 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.39.
|
|
3
|
+
"version": "1.39.1",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -79,13 +79,13 @@
|
|
|
79
79
|
"slate-react": "0.112.1",
|
|
80
80
|
"use-effect-event": "^1.0.2",
|
|
81
81
|
"xstate": "^5.19.2",
|
|
82
|
-
"@portabletext/
|
|
83
|
-
"@portabletext/
|
|
82
|
+
"@portabletext/patches": "1.1.3",
|
|
83
|
+
"@portabletext/block-tools": "1.1.13"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@portabletext/toolkit": "^2.0.17",
|
|
87
87
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
88
|
-
"@sanity/pkg-utils": "^7.0
|
|
88
|
+
"@sanity/pkg-utils": "^7.1.0",
|
|
89
89
|
"@sanity/schema": "^3.79.0",
|
|
90
90
|
"@sanity/types": "^3.79.0",
|
|
91
91
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"react": "^19.0.0",
|
|
109
109
|
"react-dom": "^19.0.0",
|
|
110
110
|
"rxjs": "^7.8.2",
|
|
111
|
-
"typescript": "5.
|
|
111
|
+
"typescript": "5.8.2",
|
|
112
112
|
"vite": "^6.2.0",
|
|
113
113
|
"vitest": "^3.0.8",
|
|
114
114
|
"vitest-browser-react": "^0.1.1",
|
|
@@ -316,20 +316,28 @@ export const defaultBehaviors = [
|
|
|
316
316
|
})
|
|
317
317
|
|
|
318
318
|
if (!droppingOnDragOrigin) {
|
|
319
|
-
return {
|
|
319
|
+
return {
|
|
320
|
+
draggingEntireBlocks,
|
|
321
|
+
draggedBlocks,
|
|
322
|
+
dragOrigin,
|
|
323
|
+
originEvent: event.originEvent,
|
|
324
|
+
}
|
|
320
325
|
}
|
|
321
326
|
|
|
322
327
|
return false
|
|
323
328
|
},
|
|
324
329
|
actions: [
|
|
325
|
-
(
|
|
330
|
+
(
|
|
331
|
+
{event},
|
|
332
|
+
{draggingEntireBlocks, draggedBlocks, dragOrigin, originEvent},
|
|
333
|
+
) => [
|
|
326
334
|
raise({
|
|
327
335
|
type: 'insert.blocks',
|
|
328
336
|
blocks: event.data,
|
|
329
337
|
placement: draggingEntireBlocks
|
|
330
|
-
?
|
|
338
|
+
? originEvent.position.block === 'start'
|
|
331
339
|
? 'before'
|
|
332
|
-
:
|
|
340
|
+
: originEvent.position.block === 'end'
|
|
333
341
|
? 'after'
|
|
334
342
|
: 'auto'
|
|
335
343
|
: 'auto',
|
|
@@ -394,6 +402,17 @@ export const defaultBehaviors = [
|
|
|
394
402
|
],
|
|
395
403
|
],
|
|
396
404
|
}),
|
|
405
|
+
defineBehavior({
|
|
406
|
+
on: 'input.*',
|
|
407
|
+
actions: [
|
|
408
|
+
({event}) => [
|
|
409
|
+
raise({
|
|
410
|
+
type: 'deserialize',
|
|
411
|
+
originEvent: event,
|
|
412
|
+
}),
|
|
413
|
+
],
|
|
414
|
+
],
|
|
415
|
+
}),
|
|
397
416
|
toggleAnnotationOff,
|
|
398
417
|
toggleAnnotationOn,
|
|
399
418
|
toggleDecoratorOff,
|
|
@@ -206,11 +206,13 @@ export type SyntheticBehaviorEvent =
|
|
|
206
206
|
'type',
|
|
207
207
|
'deserialization.failure' | 'deserialization.success'
|
|
208
208
|
> & {
|
|
209
|
-
originEvent:
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
originEvent:
|
|
210
|
+
| PickFromUnion<
|
|
211
|
+
NativeBehaviorEvent,
|
|
212
|
+
'type',
|
|
213
|
+
'drag.drop' | 'clipboard.paste'
|
|
214
|
+
>
|
|
215
|
+
| InputBehaviorEvent
|
|
214
216
|
})
|
|
215
217
|
| {
|
|
216
218
|
type: 'serialization.success'
|
|
@@ -318,6 +320,30 @@ export function isDragBehaviorEvent(
|
|
|
318
320
|
return event.type.startsWith('drag.')
|
|
319
321
|
}
|
|
320
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Used to represent native InputEvents that hold a DataTransfer object.
|
|
325
|
+
*
|
|
326
|
+
* These can either be one of:
|
|
327
|
+
*
|
|
328
|
+
* - insertFromPaste
|
|
329
|
+
* - insertFromPasteAsQuotation
|
|
330
|
+
* - insertFromDrop
|
|
331
|
+
* - insertReplacementText
|
|
332
|
+
* - insertFromYank
|
|
333
|
+
*/
|
|
334
|
+
export type InputBehaviorEvent = {
|
|
335
|
+
type: 'input.*'
|
|
336
|
+
originEvent: {
|
|
337
|
+
dataTransfer: DataTransfer
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export function isInputBehaviorEvent(
|
|
342
|
+
event: BehaviorEvent,
|
|
343
|
+
): event is InputBehaviorEvent {
|
|
344
|
+
return event.type.startsWith('input.')
|
|
345
|
+
}
|
|
346
|
+
|
|
321
347
|
export type KeyboardBehaviorEvent =
|
|
322
348
|
| {
|
|
323
349
|
type: 'keyboard.keydown'
|
|
@@ -343,11 +369,13 @@ export function isKeyboardBehaviorEvent(
|
|
|
343
369
|
export type DataBehaviorEvent =
|
|
344
370
|
| {
|
|
345
371
|
type: 'deserialize'
|
|
346
|
-
originEvent:
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
372
|
+
originEvent:
|
|
373
|
+
| PickFromUnion<
|
|
374
|
+
NativeBehaviorEvent,
|
|
375
|
+
'type',
|
|
376
|
+
'drag.drop' | 'clipboard.paste'
|
|
377
|
+
>
|
|
378
|
+
| InputBehaviorEvent
|
|
351
379
|
}
|
|
352
380
|
| {
|
|
353
381
|
type: 'serialize'
|
|
@@ -374,9 +402,10 @@ export function isMouseBehaviorEvent(
|
|
|
374
402
|
*/
|
|
375
403
|
export type NativeBehaviorEvent =
|
|
376
404
|
| ClipboardBehaviorEvent
|
|
405
|
+
| DragBehaviorEvent
|
|
406
|
+
| InputBehaviorEvent
|
|
377
407
|
| KeyboardBehaviorEvent
|
|
378
408
|
| MouseBehaviorEvent
|
|
379
|
-
| DragBehaviorEvent
|
|
380
409
|
|
|
381
410
|
/**
|
|
382
411
|
* @beta
|
|
@@ -440,6 +469,7 @@ export type BehaviorEvent =
|
|
|
440
469
|
| {type: '*'}
|
|
441
470
|
| {type: 'clipboard.*'}
|
|
442
471
|
| {type: 'drag.*'}
|
|
472
|
+
| {type: 'input.*'}
|
|
443
473
|
| {type: 'keyboard.*'}
|
|
444
474
|
| {type: 'mouse.*'}
|
|
445
475
|
|
|
@@ -455,11 +485,13 @@ export type Behavior<
|
|
|
455
485
|
? ClipboardBehaviorEvent
|
|
456
486
|
: TBehaviorEventType extends 'drag.*'
|
|
457
487
|
? DragBehaviorEvent
|
|
458
|
-
: TBehaviorEventType extends '
|
|
459
|
-
?
|
|
460
|
-
: TBehaviorEventType extends '
|
|
461
|
-
?
|
|
462
|
-
:
|
|
488
|
+
: TBehaviorEventType extends 'input.*'
|
|
489
|
+
? InputBehaviorEvent
|
|
490
|
+
: TBehaviorEventType extends 'keyboard.*'
|
|
491
|
+
? KeyboardBehaviorEvent
|
|
492
|
+
: TBehaviorEventType extends 'mouse.*'
|
|
493
|
+
? MouseBehaviorEvent
|
|
494
|
+
: PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>,
|
|
463
495
|
> = {
|
|
464
496
|
/**
|
|
465
497
|
* The internal editor event that triggers this behavior.
|
|
@@ -541,11 +573,13 @@ export function defineBehavior<
|
|
|
541
573
|
? ClipboardBehaviorEvent
|
|
542
574
|
: TBehaviorEventType extends `drag.*`
|
|
543
575
|
? DragBehaviorEvent
|
|
544
|
-
: TBehaviorEventType extends '
|
|
545
|
-
?
|
|
546
|
-
: TBehaviorEventType extends '
|
|
547
|
-
?
|
|
548
|
-
:
|
|
576
|
+
: TBehaviorEventType extends 'input.*'
|
|
577
|
+
? InputBehaviorEvent
|
|
578
|
+
: TBehaviorEventType extends 'keyboard.*'
|
|
579
|
+
? KeyboardBehaviorEvent
|
|
580
|
+
: TBehaviorEventType extends 'mouse.*'
|
|
581
|
+
? MouseBehaviorEvent
|
|
582
|
+
: PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
|
|
549
583
|
>,
|
|
550
584
|
): Behavior
|
|
551
585
|
export function defineBehavior<
|
|
@@ -561,11 +595,13 @@ export function defineBehavior<
|
|
|
561
595
|
? ClipboardBehaviorEvent
|
|
562
596
|
: TBehaviorEventType extends `drag.*`
|
|
563
597
|
? DragBehaviorEvent
|
|
564
|
-
: TBehaviorEventType extends '
|
|
565
|
-
?
|
|
566
|
-
: TBehaviorEventType extends '
|
|
567
|
-
?
|
|
568
|
-
:
|
|
598
|
+
: TBehaviorEventType extends 'input.*'
|
|
599
|
+
? InputBehaviorEvent
|
|
600
|
+
: TBehaviorEventType extends 'keyboard.*'
|
|
601
|
+
? KeyboardBehaviorEvent
|
|
602
|
+
: TBehaviorEventType extends 'mouse.*'
|
|
603
|
+
? MouseBehaviorEvent
|
|
604
|
+
: PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>,
|
|
569
605
|
>(
|
|
570
606
|
behavior: Behavior<TBehaviorEventType, TGuardResponse, TBehaviorEvent>,
|
|
571
607
|
): Behavior {
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
isClipboardBehaviorEvent,
|
|
17
17
|
isCustomBehaviorEvent,
|
|
18
18
|
isDragBehaviorEvent,
|
|
19
|
+
isInputBehaviorEvent,
|
|
19
20
|
isKeyboardBehaviorEvent,
|
|
20
21
|
isMouseBehaviorEvent,
|
|
21
22
|
type Behavior,
|
|
@@ -328,9 +329,10 @@ export const editorMachine = setup({
|
|
|
328
329
|
event.type === 'custom behavior event' ||
|
|
329
330
|
isClipboardBehaviorEvent(event.behaviorEvent) ||
|
|
330
331
|
isDragBehaviorEvent(event.behaviorEvent) ||
|
|
332
|
+
isInputBehaviorEvent(event.behaviorEvent) ||
|
|
331
333
|
isKeyboardBehaviorEvent(event.behaviorEvent) ||
|
|
332
|
-
event.behaviorEvent.type === 'deserialize' ||
|
|
333
334
|
isMouseBehaviorEvent(event.behaviorEvent) ||
|
|
335
|
+
event.behaviorEvent.type === 'deserialize' ||
|
|
334
336
|
event.behaviorEvent.type === 'serialize'
|
|
335
337
|
? undefined
|
|
336
338
|
: ({
|
|
@@ -364,6 +366,10 @@ export const editorMachine = setup({
|
|
|
364
366
|
)
|
|
365
367
|
}
|
|
366
368
|
|
|
369
|
+
if (isInputBehaviorEvent(event.behaviorEvent)) {
|
|
370
|
+
return behavior.on === 'input.*'
|
|
371
|
+
}
|
|
372
|
+
|
|
367
373
|
if (isKeyboardBehaviorEvent(event.behaviorEvent)) {
|
|
368
374
|
return (
|
|
369
375
|
behavior.on === 'keyboard.*' ||
|
|
@@ -114,9 +114,24 @@ export function createWithEventListeners(
|
|
|
114
114
|
return
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
editor.insertData = () => {
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
editor.insertData = (dataTransfer) => {
|
|
118
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
119
|
+
throw new Error('Unexpected call to .insertData(...)')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
editorActor.send({
|
|
123
|
+
type: 'behavior event',
|
|
124
|
+
behaviorEvent: {
|
|
125
|
+
type: 'deserialize',
|
|
126
|
+
originEvent: {
|
|
127
|
+
type: 'input.*',
|
|
128
|
+
originEvent: {
|
|
129
|
+
dataTransfer,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
editor,
|
|
134
|
+
})
|
|
120
135
|
}
|
|
121
136
|
|
|
122
137
|
editor.insertSoftBreak = () => {
|