@portabletext/editor 1.0.2 → 1.0.4
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/README.md +9 -2
- package/lib/index.d.mts +22 -97
- package/lib/index.d.ts +22 -97
- package/lib/index.esm.js +42 -58
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +42 -58
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +42 -58
- package/lib/index.mjs.map +1 -1
- package/package.json +38 -20
- package/src/editor/Editable.tsx +32 -38
- package/src/editor/components/Synchronizer.tsx +1 -1
- package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +166 -0
- package/src/editor/plugins/createWithInsertData.ts +34 -1
- package/src/editor/plugins/createWithPatches.ts +2 -2
- package/src/editor/plugins/createWithUndoRedo.ts +1 -1
- package/src/index.ts +1 -2
- package/src/types/editor.ts +4 -3
- package/src/utils/__tests__/dmpToOperations.test.ts +1 -1
- package/src/utils/applyPatch.ts +8 -8
- package/src/utils/operationToPatches.ts +2 -2
- package/src/utils/validateValue.ts +1 -1
- package/src/patch/PatchEvent.ts +0 -33
- package/src/patch/applyPatch.ts +0 -29
- package/src/patch/array.ts +0 -89
- package/src/patch/arrayInsert.ts +0 -27
- package/src/patch/object.ts +0 -39
- package/src/patch/patches.ts +0 -53
- package/src/patch/primitive.ts +0 -43
- package/src/patch/string.ts +0 -51
- package/src/types/patch.ts +0 -65
- package/src/utils/patches.ts +0 -36
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
<picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/portabletext/portabletext/master/logo-white.svg?sanitize=true">
|
|
3
|
+
<img alt="Portable Text Logo" src="https://raw.githubusercontent.com/portabletext/portabletext/master/logo.svg?sanitize=true">
|
|
4
|
+
</picture>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
<div align="center">
|
|
7
|
+
<h1>Portable Text Editor</h1>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
> The official editor for editing [Portable Text](https://github.com/portabletext/portabletext) – the JSON based rich text specification for modern content editing platforms.
|
package/lib/index.d.mts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
|
|
3
1
|
import {ArrayDefinition} from '@sanity/types'
|
|
4
2
|
import {ArraySchemaType} from '@sanity/types'
|
|
5
3
|
import {BaseSyntheticEvent} from 'react'
|
|
@@ -21,6 +19,7 @@ import {Node as Node_2} from 'slate'
|
|
|
21
19
|
import {ObjectSchemaType} from '@sanity/types'
|
|
22
20
|
import {Observable} from 'rxjs'
|
|
23
21
|
import {Operation} from 'slate'
|
|
22
|
+
import {Patch} from '@portabletext/patches/types'
|
|
24
23
|
import {Path} from '@sanity/types'
|
|
25
24
|
import {PortableTextBlock} from '@sanity/types'
|
|
26
25
|
import {PortableTextChild} from '@sanity/types'
|
|
@@ -31,7 +30,6 @@ import {PortableTextTextBlock} from '@sanity/types'
|
|
|
31
30
|
import {PropsWithChildren} from 'react'
|
|
32
31
|
import {ReactEditor} from 'slate-react'
|
|
33
32
|
import {ReactElement} from 'react'
|
|
34
|
-
import {ReactNode} from 'react'
|
|
35
33
|
import {RefAttributes} from 'react'
|
|
36
34
|
import {RefObject} from 'react'
|
|
37
35
|
import {SpanSchemaType} from '@sanity/types'
|
|
@@ -129,12 +127,6 @@ export declare type BlurChange = {
|
|
|
129
127
|
event: FocusEvent_2<HTMLDivElement, Element>
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
/**
|
|
133
|
-
* Try to compact a set of patches
|
|
134
|
-
*
|
|
135
|
-
*/
|
|
136
|
-
export declare function compactPatches(patches: Patch[]): Patch[]
|
|
137
|
-
|
|
138
130
|
/**
|
|
139
131
|
* The editor was either connected or disconnected to the network
|
|
140
132
|
* To show out of sync warnings etc when in collaborative mode.
|
|
@@ -152,20 +144,6 @@ export declare type createEditorOptions = {
|
|
|
152
144
|
maxBlocks?: number
|
|
153
145
|
}
|
|
154
146
|
|
|
155
|
-
export declare type DecPatch = {
|
|
156
|
-
path: Path
|
|
157
|
-
origin?: Origin
|
|
158
|
-
type: 'dec'
|
|
159
|
-
value: JSONValue
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export declare type DiffMatchPatch = {
|
|
163
|
-
path: Path
|
|
164
|
-
type: 'diffMatchPatch'
|
|
165
|
-
origin?: Origin
|
|
166
|
-
value: string
|
|
167
|
-
}
|
|
168
|
-
|
|
169
147
|
/** @beta */
|
|
170
148
|
export declare interface EditableAPI {
|
|
171
149
|
activeAnnotations: () => PortableTextObject[]
|
|
@@ -303,24 +281,6 @@ export declare type HotkeyOptions = {
|
|
|
303
281
|
custom?: Record<string, (event: BaseSyntheticEvent, editor: PortableTextEditor) => void>
|
|
304
282
|
}
|
|
305
283
|
|
|
306
|
-
export declare type IncPatch = {
|
|
307
|
-
path: Path
|
|
308
|
-
origin?: Origin
|
|
309
|
-
type: 'inc'
|
|
310
|
-
value: JSONValue
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export declare type InsertPatch = {
|
|
314
|
-
path: Path
|
|
315
|
-
origin?: Origin
|
|
316
|
-
type: 'insert'
|
|
317
|
-
position: InsertPosition_2
|
|
318
|
-
items: JSONValue[]
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
declare type InsertPosition_2 = 'before' | 'after' | 'replace'
|
|
322
|
-
export {InsertPosition_2 as InsertPosition}
|
|
323
|
-
|
|
324
284
|
/**
|
|
325
285
|
* The editor has an invalid value
|
|
326
286
|
* @beta */
|
|
@@ -353,15 +313,6 @@ export declare type InvalidValueResolution = {
|
|
|
353
313
|
}
|
|
354
314
|
}
|
|
355
315
|
|
|
356
|
-
export declare type JSONValue =
|
|
357
|
-
| number
|
|
358
|
-
| string
|
|
359
|
-
| boolean
|
|
360
|
-
| {
|
|
361
|
-
[key: string]: JSONValue
|
|
362
|
-
}
|
|
363
|
-
| JSONValue[]
|
|
364
|
-
|
|
365
316
|
export declare const keyGenerator: () => string
|
|
366
317
|
|
|
367
318
|
/**
|
|
@@ -403,8 +354,6 @@ export declare type OnPasteResult =
|
|
|
403
354
|
|
|
404
355
|
export declare type OnPasteResultOrPromise = OnPasteResult | Promise<OnPasteResult>
|
|
405
356
|
|
|
406
|
-
export declare type Origin = 'remote' | 'local' | 'internal'
|
|
407
|
-
|
|
408
357
|
/** @beta */
|
|
409
358
|
export declare interface PasteData {
|
|
410
359
|
event: ClipboardEvent_2
|
|
@@ -413,15 +362,6 @@ export declare interface PasteData {
|
|
|
413
362
|
value: PortableTextBlock[] | undefined
|
|
414
363
|
}
|
|
415
364
|
|
|
416
|
-
export declare type Patch =
|
|
417
|
-
| SetPatch
|
|
418
|
-
| SetIfMissingPatch
|
|
419
|
-
| UnsetPatch
|
|
420
|
-
| InsertPatch
|
|
421
|
-
| DiffMatchPatch
|
|
422
|
-
| IncPatch
|
|
423
|
-
| DecPatch
|
|
424
|
-
|
|
425
365
|
/**
|
|
426
366
|
* The editor has produced a patch
|
|
427
367
|
* @beta */
|
|
@@ -442,22 +382,22 @@ export declare type PatchObservable = Observable<{
|
|
|
442
382
|
export declare const PortableTextEditable: ForwardRefExoticComponent<
|
|
443
383
|
Omit<
|
|
444
384
|
Omit<TextareaHTMLAttributes<HTMLDivElement>, 'onPaste' | 'onCopy' | 'onBeforeInput'> & {
|
|
445
|
-
hotkeys?: HotkeyOptions
|
|
446
|
-
onBeforeInput?: (
|
|
447
|
-
onPaste?: OnPasteFn
|
|
448
|
-
onCopy?: OnCopyFn
|
|
385
|
+
hotkeys?: HotkeyOptions
|
|
386
|
+
onBeforeInput?: (event: InputEvent) => void
|
|
387
|
+
onPaste?: OnPasteFn
|
|
388
|
+
onCopy?: OnCopyFn
|
|
449
389
|
ref: MutableRefObject<HTMLDivElement | null>
|
|
450
|
-
rangeDecorations?: RangeDecoration[]
|
|
451
|
-
renderAnnotation?: RenderAnnotationFunction
|
|
452
|
-
renderBlock?: RenderBlockFunction
|
|
453
|
-
renderChild?: RenderChildFunction
|
|
454
|
-
renderDecorator?: RenderDecoratorFunction
|
|
455
|
-
renderListItem?: RenderListItemFunction
|
|
456
|
-
renderPlaceholder?:
|
|
457
|
-
renderStyle?: RenderStyleFunction
|
|
458
|
-
scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
|
|
459
|
-
selection?: EditorSelection
|
|
460
|
-
spellCheck?: boolean
|
|
390
|
+
rangeDecorations?: RangeDecoration[]
|
|
391
|
+
renderAnnotation?: RenderAnnotationFunction
|
|
392
|
+
renderBlock?: RenderBlockFunction
|
|
393
|
+
renderChild?: RenderChildFunction
|
|
394
|
+
renderDecorator?: RenderDecoratorFunction
|
|
395
|
+
renderListItem?: RenderListItemFunction
|
|
396
|
+
renderPlaceholder?: RenderPlaceholderFunction
|
|
397
|
+
renderStyle?: RenderStyleFunction
|
|
398
|
+
scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
|
|
399
|
+
selection?: EditorSelection
|
|
400
|
+
spellCheck?: boolean
|
|
461
401
|
} & Omit<HTMLProps<HTMLDivElement>, 'onPaste' | 'onBeforeInput' | 'as'>,
|
|
462
402
|
'ref'
|
|
463
403
|
> &
|
|
@@ -482,7 +422,7 @@ export declare type PortableTextEditableProps = Omit<
|
|
|
482
422
|
renderChild?: RenderChildFunction
|
|
483
423
|
renderDecorator?: RenderDecoratorFunction
|
|
484
424
|
renderListItem?: RenderListItemFunction
|
|
485
|
-
renderPlaceholder?:
|
|
425
|
+
renderPlaceholder?: RenderPlaceholderFunction
|
|
486
426
|
renderStyle?: RenderStyleFunction
|
|
487
427
|
scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
|
|
488
428
|
selection?: EditorSelection
|
|
@@ -838,6 +778,9 @@ export declare type RenderEditableFunction = (props: PortableTextEditableProps)
|
|
|
838
778
|
/** @beta */
|
|
839
779
|
export declare type RenderListItemFunction = (props: BlockListItemRenderProps) => JSX.Element
|
|
840
780
|
|
|
781
|
+
/** @beta */
|
|
782
|
+
export declare type RenderPlaceholderFunction = () => React.ReactNode
|
|
783
|
+
|
|
841
784
|
/** @beta */
|
|
842
785
|
export declare type RenderStyleFunction = (props: BlockStyleRenderProps) => JSX.Element
|
|
843
786
|
|
|
@@ -855,20 +798,6 @@ export declare type SelectionChange = {
|
|
|
855
798
|
selection: EditorSelection
|
|
856
799
|
}
|
|
857
800
|
|
|
858
|
-
export declare type SetIfMissingPatch = {
|
|
859
|
-
path: Path
|
|
860
|
-
origin?: Origin
|
|
861
|
-
type: 'setIfMissing'
|
|
862
|
-
value: JSONValue
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
export declare type SetPatch = {
|
|
866
|
-
path: Path
|
|
867
|
-
type: 'set'
|
|
868
|
-
origin?: Origin
|
|
869
|
-
value: JSONValue
|
|
870
|
-
}
|
|
871
|
-
|
|
872
801
|
/**
|
|
873
802
|
* The editor performed a undo history step
|
|
874
803
|
* @beta */
|
|
@@ -884,12 +813,6 @@ export declare type UnsetChange = {
|
|
|
884
813
|
previousValue: PortableTextBlock[]
|
|
885
814
|
}
|
|
886
815
|
|
|
887
|
-
export declare type UnsetPatch = {
|
|
888
|
-
path: Path
|
|
889
|
-
origin?: Origin
|
|
890
|
-
type: 'unset'
|
|
891
|
-
}
|
|
892
|
-
|
|
893
816
|
/**
|
|
894
817
|
* Get the current editor object from the React context.
|
|
895
818
|
*/
|
|
@@ -908,4 +831,6 @@ export declare type ValueChange = {
|
|
|
908
831
|
value: PortableTextBlock[] | undefined
|
|
909
832
|
}
|
|
910
833
|
|
|
834
|
+
export * from '@portabletext/patches/types'
|
|
835
|
+
|
|
911
836
|
export {}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
|
|
3
1
|
import {ArrayDefinition} from '@sanity/types'
|
|
4
2
|
import {ArraySchemaType} from '@sanity/types'
|
|
5
3
|
import {BaseSyntheticEvent} from 'react'
|
|
@@ -21,6 +19,7 @@ import {Node as Node_2} from 'slate'
|
|
|
21
19
|
import {ObjectSchemaType} from '@sanity/types'
|
|
22
20
|
import {Observable} from 'rxjs'
|
|
23
21
|
import {Operation} from 'slate'
|
|
22
|
+
import {Patch} from '@portabletext/patches/types'
|
|
24
23
|
import {Path} from '@sanity/types'
|
|
25
24
|
import {PortableTextBlock} from '@sanity/types'
|
|
26
25
|
import {PortableTextChild} from '@sanity/types'
|
|
@@ -31,7 +30,6 @@ import {PortableTextTextBlock} from '@sanity/types'
|
|
|
31
30
|
import {PropsWithChildren} from 'react'
|
|
32
31
|
import {ReactEditor} from 'slate-react'
|
|
33
32
|
import {ReactElement} from 'react'
|
|
34
|
-
import {ReactNode} from 'react'
|
|
35
33
|
import {RefAttributes} from 'react'
|
|
36
34
|
import {RefObject} from 'react'
|
|
37
35
|
import {SpanSchemaType} from '@sanity/types'
|
|
@@ -129,12 +127,6 @@ export declare type BlurChange = {
|
|
|
129
127
|
event: FocusEvent_2<HTMLDivElement, Element>
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
/**
|
|
133
|
-
* Try to compact a set of patches
|
|
134
|
-
*
|
|
135
|
-
*/
|
|
136
|
-
export declare function compactPatches(patches: Patch[]): Patch[]
|
|
137
|
-
|
|
138
130
|
/**
|
|
139
131
|
* The editor was either connected or disconnected to the network
|
|
140
132
|
* To show out of sync warnings etc when in collaborative mode.
|
|
@@ -152,20 +144,6 @@ export declare type createEditorOptions = {
|
|
|
152
144
|
maxBlocks?: number
|
|
153
145
|
}
|
|
154
146
|
|
|
155
|
-
export declare type DecPatch = {
|
|
156
|
-
path: Path
|
|
157
|
-
origin?: Origin
|
|
158
|
-
type: 'dec'
|
|
159
|
-
value: JSONValue
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export declare type DiffMatchPatch = {
|
|
163
|
-
path: Path
|
|
164
|
-
type: 'diffMatchPatch'
|
|
165
|
-
origin?: Origin
|
|
166
|
-
value: string
|
|
167
|
-
}
|
|
168
|
-
|
|
169
147
|
/** @beta */
|
|
170
148
|
export declare interface EditableAPI {
|
|
171
149
|
activeAnnotations: () => PortableTextObject[]
|
|
@@ -303,24 +281,6 @@ export declare type HotkeyOptions = {
|
|
|
303
281
|
custom?: Record<string, (event: BaseSyntheticEvent, editor: PortableTextEditor) => void>
|
|
304
282
|
}
|
|
305
283
|
|
|
306
|
-
export declare type IncPatch = {
|
|
307
|
-
path: Path
|
|
308
|
-
origin?: Origin
|
|
309
|
-
type: 'inc'
|
|
310
|
-
value: JSONValue
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export declare type InsertPatch = {
|
|
314
|
-
path: Path
|
|
315
|
-
origin?: Origin
|
|
316
|
-
type: 'insert'
|
|
317
|
-
position: InsertPosition_2
|
|
318
|
-
items: JSONValue[]
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
declare type InsertPosition_2 = 'before' | 'after' | 'replace'
|
|
322
|
-
export {InsertPosition_2 as InsertPosition}
|
|
323
|
-
|
|
324
284
|
/**
|
|
325
285
|
* The editor has an invalid value
|
|
326
286
|
* @beta */
|
|
@@ -353,15 +313,6 @@ export declare type InvalidValueResolution = {
|
|
|
353
313
|
}
|
|
354
314
|
}
|
|
355
315
|
|
|
356
|
-
export declare type JSONValue =
|
|
357
|
-
| number
|
|
358
|
-
| string
|
|
359
|
-
| boolean
|
|
360
|
-
| {
|
|
361
|
-
[key: string]: JSONValue
|
|
362
|
-
}
|
|
363
|
-
| JSONValue[]
|
|
364
|
-
|
|
365
316
|
export declare const keyGenerator: () => string
|
|
366
317
|
|
|
367
318
|
/**
|
|
@@ -403,8 +354,6 @@ export declare type OnPasteResult =
|
|
|
403
354
|
|
|
404
355
|
export declare type OnPasteResultOrPromise = OnPasteResult | Promise<OnPasteResult>
|
|
405
356
|
|
|
406
|
-
export declare type Origin = 'remote' | 'local' | 'internal'
|
|
407
|
-
|
|
408
357
|
/** @beta */
|
|
409
358
|
export declare interface PasteData {
|
|
410
359
|
event: ClipboardEvent_2
|
|
@@ -413,15 +362,6 @@ export declare interface PasteData {
|
|
|
413
362
|
value: PortableTextBlock[] | undefined
|
|
414
363
|
}
|
|
415
364
|
|
|
416
|
-
export declare type Patch =
|
|
417
|
-
| SetPatch
|
|
418
|
-
| SetIfMissingPatch
|
|
419
|
-
| UnsetPatch
|
|
420
|
-
| InsertPatch
|
|
421
|
-
| DiffMatchPatch
|
|
422
|
-
| IncPatch
|
|
423
|
-
| DecPatch
|
|
424
|
-
|
|
425
365
|
/**
|
|
426
366
|
* The editor has produced a patch
|
|
427
367
|
* @beta */
|
|
@@ -442,22 +382,22 @@ export declare type PatchObservable = Observable<{
|
|
|
442
382
|
export declare const PortableTextEditable: ForwardRefExoticComponent<
|
|
443
383
|
Omit<
|
|
444
384
|
Omit<TextareaHTMLAttributes<HTMLDivElement>, 'onPaste' | 'onCopy' | 'onBeforeInput'> & {
|
|
445
|
-
hotkeys?: HotkeyOptions
|
|
446
|
-
onBeforeInput?: (
|
|
447
|
-
onPaste?: OnPasteFn
|
|
448
|
-
onCopy?: OnCopyFn
|
|
385
|
+
hotkeys?: HotkeyOptions
|
|
386
|
+
onBeforeInput?: (event: InputEvent) => void
|
|
387
|
+
onPaste?: OnPasteFn
|
|
388
|
+
onCopy?: OnCopyFn
|
|
449
389
|
ref: MutableRefObject<HTMLDivElement | null>
|
|
450
|
-
rangeDecorations?: RangeDecoration[]
|
|
451
|
-
renderAnnotation?: RenderAnnotationFunction
|
|
452
|
-
renderBlock?: RenderBlockFunction
|
|
453
|
-
renderChild?: RenderChildFunction
|
|
454
|
-
renderDecorator?: RenderDecoratorFunction
|
|
455
|
-
renderListItem?: RenderListItemFunction
|
|
456
|
-
renderPlaceholder?:
|
|
457
|
-
renderStyle?: RenderStyleFunction
|
|
458
|
-
scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
|
|
459
|
-
selection?: EditorSelection
|
|
460
|
-
spellCheck?: boolean
|
|
390
|
+
rangeDecorations?: RangeDecoration[]
|
|
391
|
+
renderAnnotation?: RenderAnnotationFunction
|
|
392
|
+
renderBlock?: RenderBlockFunction
|
|
393
|
+
renderChild?: RenderChildFunction
|
|
394
|
+
renderDecorator?: RenderDecoratorFunction
|
|
395
|
+
renderListItem?: RenderListItemFunction
|
|
396
|
+
renderPlaceholder?: RenderPlaceholderFunction
|
|
397
|
+
renderStyle?: RenderStyleFunction
|
|
398
|
+
scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
|
|
399
|
+
selection?: EditorSelection
|
|
400
|
+
spellCheck?: boolean
|
|
461
401
|
} & Omit<HTMLProps<HTMLDivElement>, 'onPaste' | 'onBeforeInput' | 'as'>,
|
|
462
402
|
'ref'
|
|
463
403
|
> &
|
|
@@ -482,7 +422,7 @@ export declare type PortableTextEditableProps = Omit<
|
|
|
482
422
|
renderChild?: RenderChildFunction
|
|
483
423
|
renderDecorator?: RenderDecoratorFunction
|
|
484
424
|
renderListItem?: RenderListItemFunction
|
|
485
|
-
renderPlaceholder?:
|
|
425
|
+
renderPlaceholder?: RenderPlaceholderFunction
|
|
486
426
|
renderStyle?: RenderStyleFunction
|
|
487
427
|
scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
|
|
488
428
|
selection?: EditorSelection
|
|
@@ -838,6 +778,9 @@ export declare type RenderEditableFunction = (props: PortableTextEditableProps)
|
|
|
838
778
|
/** @beta */
|
|
839
779
|
export declare type RenderListItemFunction = (props: BlockListItemRenderProps) => JSX.Element
|
|
840
780
|
|
|
781
|
+
/** @beta */
|
|
782
|
+
export declare type RenderPlaceholderFunction = () => React.ReactNode
|
|
783
|
+
|
|
841
784
|
/** @beta */
|
|
842
785
|
export declare type RenderStyleFunction = (props: BlockStyleRenderProps) => JSX.Element
|
|
843
786
|
|
|
@@ -855,20 +798,6 @@ export declare type SelectionChange = {
|
|
|
855
798
|
selection: EditorSelection
|
|
856
799
|
}
|
|
857
800
|
|
|
858
|
-
export declare type SetIfMissingPatch = {
|
|
859
|
-
path: Path
|
|
860
|
-
origin?: Origin
|
|
861
|
-
type: 'setIfMissing'
|
|
862
|
-
value: JSONValue
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
export declare type SetPatch = {
|
|
866
|
-
path: Path
|
|
867
|
-
type: 'set'
|
|
868
|
-
origin?: Origin
|
|
869
|
-
value: JSONValue
|
|
870
|
-
}
|
|
871
|
-
|
|
872
801
|
/**
|
|
873
802
|
* The editor performed a undo history step
|
|
874
803
|
* @beta */
|
|
@@ -884,12 +813,6 @@ export declare type UnsetChange = {
|
|
|
884
813
|
previousValue: PortableTextBlock[]
|
|
885
814
|
}
|
|
886
815
|
|
|
887
|
-
export declare type UnsetPatch = {
|
|
888
|
-
path: Path
|
|
889
|
-
origin?: Origin
|
|
890
|
-
type: 'unset'
|
|
891
|
-
}
|
|
892
|
-
|
|
893
816
|
/**
|
|
894
817
|
* Get the current editor object from the React context.
|
|
895
818
|
*/
|
|
@@ -908,4 +831,6 @@ export declare type ValueChange = {
|
|
|
908
831
|
value: PortableTextBlock[] | undefined
|
|
909
832
|
}
|
|
910
833
|
|
|
834
|
+
export * from '@portabletext/patches/types'
|
|
835
|
+
|
|
911
836
|
export {}
|
package/lib/index.esm.js
CHANGED
|
@@ -2306,16 +2306,16 @@ function apply$1(value, patch) {
|
|
|
2306
2306
|
return OPERATIONS$1[patch.type](value, patch.value);
|
|
2307
2307
|
}
|
|
2308
2308
|
const OPERATIONS = {
|
|
2309
|
-
replace(
|
|
2309
|
+
replace(_currentValue, nextValue) {
|
|
2310
2310
|
return nextValue;
|
|
2311
2311
|
},
|
|
2312
|
-
set(
|
|
2312
|
+
set(_currentValue, nextValue) {
|
|
2313
2313
|
return nextValue;
|
|
2314
2314
|
},
|
|
2315
2315
|
setIfMissing(currentValue, nextValue) {
|
|
2316
2316
|
return currentValue === void 0 ? nextValue : currentValue;
|
|
2317
2317
|
},
|
|
2318
|
-
unset(
|
|
2318
|
+
unset(_currentValue, _nextValue) {
|
|
2319
2319
|
},
|
|
2320
2320
|
diffMatchPatch(currentValue, nextValue) {
|
|
2321
2321
|
const [result] = apply$4(parse(nextValue), currentValue, {
|
|
@@ -3772,7 +3772,8 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3772
3772
|
editor,
|
|
3773
3773
|
toSlateValue(parsed, { schemaTypes }),
|
|
3774
3774
|
keyGenerator,
|
|
3775
|
-
spanTypeName
|
|
3775
|
+
spanTypeName,
|
|
3776
|
+
schemaTypes
|
|
3776
3777
|
), validation = validateValue(parsed, schemaTypes, keyGenerator);
|
|
3777
3778
|
if (!validation.valid && !((_a = validation.resolution) != null && _a.autoResolve)) {
|
|
3778
3779
|
const errorDescription = `${(_b = validation.resolution) == null ? void 0 : _b.description}`;
|
|
@@ -3853,21 +3854,32 @@ const entityMap = {
|
|
|
3853
3854
|
function escapeHtml(str) {
|
|
3854
3855
|
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
3855
3856
|
}
|
|
3856
|
-
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName) {
|
|
3857
|
+
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
3857
3858
|
return fragment.map((node) => {
|
|
3858
3859
|
const newNode = { ...node };
|
|
3859
|
-
editor.isTextBlock(newNode)
|
|
3860
|
-
const
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3860
|
+
if (editor.isTextBlock(newNode)) {
|
|
3861
|
+
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
3862
|
+
if (annotations.length === 0) {
|
|
3863
|
+
const { markDefs, ...NewNodeNoDefs } = newNode;
|
|
3864
|
+
return { ...NewNodeNoDefs, _key: keyGenerator() };
|
|
3865
|
+
}
|
|
3866
|
+
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
3867
|
+
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
3868
|
+
return { ...newNode, markDefs: allowedAnnotations, _key: keyGenerator() };
|
|
3869
|
+
}
|
|
3870
|
+
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
3871
|
+
const oldKey = def._key, newKey = keyGenerator();
|
|
3872
|
+
return newNode.children = newNode.children.map(
|
|
3873
|
+
(child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
3874
|
+
...child,
|
|
3875
|
+
marks: child.marks && child.marks.includes(oldKey) ? (
|
|
3876
|
+
// eslint-disable-next-line max-nested-callbacks
|
|
3877
|
+
[...child.marks].filter((mark) => mark !== oldKey).concat(newKey)
|
|
3878
|
+
) : child.marks
|
|
3879
|
+
} : child
|
|
3880
|
+
), { ...def, _key: newKey };
|
|
3881
|
+
});
|
|
3882
|
+
}
|
|
3871
3883
|
const nodeWithNewKeys = { ...newNode, _key: keyGenerator() };
|
|
3872
3884
|
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
3873
3885
|
...child,
|
|
@@ -4720,35 +4732,20 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4720
4732
|
[onCopy]
|
|
4721
4733
|
), handlePaste = useCallback(
|
|
4722
4734
|
(event) => {
|
|
4723
|
-
if (event.preventDefault(),
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
new Promise((resolve) => {
|
|
4729
|
-
const value = PortableTextEditor.getValue(portableTextEditor), ptRange = toPortableTextRange(value, slateEditor.selection, schemaTypes), path = (ptRange == null ? void 0 : ptRange.focus.path) || [];
|
|
4730
|
-
resolve(
|
|
4731
|
-
onPaste({
|
|
4732
|
-
event,
|
|
4733
|
-
value,
|
|
4734
|
-
path,
|
|
4735
|
-
schemaTypes
|
|
4736
|
-
})
|
|
4737
|
-
);
|
|
4738
|
-
}).then((result) => {
|
|
4739
|
-
if (debug("Custom paste function from client resolved", result), change$.next({ type: "loading", isLoading: !0 }), !result || !result.insert) {
|
|
4740
|
-
debug("No result from custom paste handler, pasting normally"), slateEditor.insertData(event.clipboardData);
|
|
4741
|
-
return;
|
|
4742
|
-
}
|
|
4743
|
-
if (result && result.insert) {
|
|
4744
|
-
slateEditor.insertFragment(
|
|
4745
|
-
toSlateValue(result.insert, { schemaTypes })
|
|
4746
|
-
), change$.next({ type: "loading", isLoading: !1 });
|
|
4747
|
-
return;
|
|
4748
|
-
}
|
|
4749
|
-
console.warn("Your onPaste function returned something unexpected:", result);
|
|
4750
|
-
}).catch((error) => (change$.next({ type: "loading", isLoading: !1 }), console.error(error), error));
|
|
4735
|
+
if (event.preventDefault(), !slateEditor.selection)
|
|
4736
|
+
return;
|
|
4737
|
+
if (!onPaste) {
|
|
4738
|
+
debug("Pasting normally"), slateEditor.insertData(event.clipboardData);
|
|
4739
|
+
return;
|
|
4751
4740
|
}
|
|
4741
|
+
const value = PortableTextEditor.getValue(portableTextEditor), ptRange = toPortableTextRange(value, slateEditor.selection, schemaTypes), path = (ptRange == null ? void 0 : ptRange.focus.path) || [], onPasteResult = onPaste({ event, value, path, schemaTypes });
|
|
4742
|
+
onPasteResult === void 0 ? (debug("No result from custom paste handler, pasting normally"), slateEditor.insertData(event.clipboardData)) : (change$.next({ type: "loading", isLoading: !0 }), Promise.resolve(onPasteResult).then((result) => {
|
|
4743
|
+
debug("Custom paste function from client resolved", result), result && result.insert ? slateEditor.insertFragment(
|
|
4744
|
+
toSlateValue(result.insert, { schemaTypes })
|
|
4745
|
+
) : console.warn("Your onPaste function returned something unexpected:", result);
|
|
4746
|
+
}).catch((error) => (console.error(error), error)).finally(() => {
|
|
4747
|
+
change$.next({ type: "loading", isLoading: !1 });
|
|
4748
|
+
}));
|
|
4752
4749
|
},
|
|
4753
4750
|
[change$, onPaste, portableTextEditor, schemaTypes, slateEditor]
|
|
4754
4751
|
), handleOnFocus = useCallback(
|
|
@@ -4873,22 +4870,9 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4873
4870
|
}
|
|
4874
4871
|
) : null;
|
|
4875
4872
|
});
|
|
4876
|
-
function compactPatches(patches) {
|
|
4877
|
-
const lastPatch = patches.slice(-1)[0];
|
|
4878
|
-
if (lastPatch && lastPatch.type === "unset" && lastPatch.path.length === 0)
|
|
4879
|
-
return [lastPatch];
|
|
4880
|
-
let finalPatches = patches;
|
|
4881
|
-
return finalPatches = finalPatches.filter((patch, index) => {
|
|
4882
|
-
if (!patch)
|
|
4883
|
-
return !1;
|
|
4884
|
-
const nextPatch = finalPatches[index + 1];
|
|
4885
|
-
return !(nextPatch && nextPatch.type === "set" && patch.type === "set" && isEqual(patch.path, nextPatch.path));
|
|
4886
|
-
}), finalPatches.length !== patches.length ? finalPatches : patches;
|
|
4887
|
-
}
|
|
4888
4873
|
export {
|
|
4889
4874
|
PortableTextEditable,
|
|
4890
4875
|
PortableTextEditor,
|
|
4891
|
-
compactPatches,
|
|
4892
4876
|
defaultKeyGenerator as keyGenerator,
|
|
4893
4877
|
usePortableTextEditor,
|
|
4894
4878
|
usePortableTextEditorSelection
|