@portabletext/editor 1.0.19 → 1.1.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.
- package/lib/index.d.mts +140 -66
- package/lib/index.d.ts +140 -66
- package/lib/index.esm.js +1125 -362
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1125 -362
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1125 -362
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/editor/Editable.tsx +107 -36
- package/src/editor/PortableTextEditor.tsx +47 -12
- package/src/editor/__tests__/PortableTextEditor.test.tsx +42 -15
- package/src/editor/__tests__/PortableTextEditorTester.tsx +50 -38
- package/src/editor/__tests__/RangeDecorations.test.tsx +0 -1
- package/src/editor/__tests__/handleClick.test.tsx +28 -9
- package/src/editor/__tests__/insert-block.test.tsx +22 -6
- package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +30 -62
- package/src/editor/__tests__/utils.ts +10 -3
- package/src/editor/components/DraggableBlock.tsx +36 -13
- package/src/editor/components/Element.tsx +59 -17
- package/src/editor/components/Leaf.tsx +106 -68
- package/src/editor/components/SlateContainer.tsx +12 -5
- package/src/editor/components/Synchronizer.tsx +5 -2
- package/src/editor/hooks/usePortableTextEditor.ts +2 -2
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +9 -3
- package/src/editor/hooks/useSyncValue.test.tsx +9 -4
- package/src/editor/hooks/useSyncValue.ts +199 -130
- package/src/editor/nodes/DefaultAnnotation.tsx +6 -3
- package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +25 -7
- package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +26 -9
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +15 -5
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +60 -19
- package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +4 -2
- package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +4 -2
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +61 -17
- package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +6 -3
- package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +30 -13
- package/src/editor/plugins/createWithEditableAPI.ts +354 -124
- package/src/editor/plugins/createWithHotKeys.ts +41 -121
- package/src/editor/plugins/createWithInsertBreak.ts +166 -27
- package/src/editor/plugins/createWithInsertData.ts +60 -23
- package/src/editor/plugins/createWithMaxBlocks.ts +5 -2
- package/src/editor/plugins/createWithObjectKeys.ts +7 -3
- package/src/editor/plugins/createWithPatches.ts +60 -16
- package/src/editor/plugins/createWithPlaceholderBlock.ts +7 -3
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +17 -7
- package/src/editor/plugins/createWithPortableTextLists.ts +21 -8
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +213 -46
- package/src/editor/plugins/createWithPortableTextSelections.ts +4 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +25 -9
- package/src/editor/plugins/createWithUndoRedo.ts +107 -24
- package/src/editor/plugins/createWithUtils.ts +32 -10
- package/src/editor/plugins/index.ts +31 -10
- package/src/types/editor.ts +44 -15
- package/src/types/options.ts +4 -2
- package/src/types/slate.ts +2 -2
- package/src/utils/__tests__/dmpToOperations.test.ts +38 -13
- package/src/utils/__tests__/operationToPatches.test.ts +3 -2
- package/src/utils/__tests__/patchToOperations.test.ts +15 -4
- package/src/utils/__tests__/ranges.test.ts +8 -3
- package/src/utils/__tests__/valueNormalization.test.tsx +12 -4
- package/src/utils/__tests__/values.test.ts +0 -1
- package/src/utils/applyPatch.ts +71 -20
- package/src/utils/getPortableTextMemberSchemaTypes.ts +30 -15
- package/src/utils/operationToPatches.ts +126 -43
- package/src/utils/paths.ts +24 -7
- package/src/utils/ranges.ts +12 -5
- package/src/utils/selection.ts +19 -7
- package/src/utils/validateValue.ts +118 -45
- package/src/utils/values.ts +31 -9
- package/src/utils/weakMaps.ts +18 -8
- package/src/utils/withChanges.ts +4 -2
package/lib/index.d.mts
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import {ArrayDefinition} from '@sanity/types'
|
|
2
|
-
import {ArraySchemaType} from '@sanity/types'
|
|
3
|
-
import {BaseSyntheticEvent} from 'react'
|
|
4
|
-
import {BlockDecoratorDefinition} from '@sanity/types'
|
|
5
|
-
import {BlockListDefinition} from '@sanity/types'
|
|
6
|
-
import {BlockSchemaType} from '@sanity/types'
|
|
7
|
-
import {BlockStyleDefinition} from '@sanity/types'
|
|
8
|
-
import {ClipboardEvent as ClipboardEvent_2} from 'react'
|
|
9
|
-
import {Component} from 'react'
|
|
10
|
-
import {Descendant} from 'slate'
|
|
11
|
-
import {DOMNode} from 'slate-react/dist/utils/dom'
|
|
12
|
-
import {FocusEvent as FocusEvent_2} from 'react'
|
|
13
|
-
import {ForwardRefExoticComponent} from 'react'
|
|
14
|
-
import {HTMLProps} from 'react'
|
|
15
|
-
import {JSX as JSX_2} from 'react'
|
|
16
|
-
import {KeyboardEvent as KeyboardEvent_2} from 'react'
|
|
17
|
-
import {MutableRefObject} from 'react'
|
|
18
|
-
import {Node as Node_2} from 'slate'
|
|
19
|
-
import {ObjectSchemaType} from '@sanity/types'
|
|
20
|
-
import {Observable} from 'rxjs'
|
|
21
|
-
import {Operation} from 'slate'
|
|
22
1
|
import {Patch} from '@portabletext/patches'
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
2
|
+
import {
|
|
3
|
+
ArrayDefinition,
|
|
4
|
+
ArraySchemaType,
|
|
5
|
+
BlockDecoratorDefinition,
|
|
6
|
+
BlockListDefinition,
|
|
7
|
+
BlockSchemaType,
|
|
8
|
+
BlockStyleDefinition,
|
|
9
|
+
ObjectSchemaType,
|
|
10
|
+
Path,
|
|
11
|
+
PortableTextBlock,
|
|
12
|
+
PortableTextChild,
|
|
13
|
+
PortableTextListBlock,
|
|
14
|
+
PortableTextObject,
|
|
15
|
+
PortableTextSpan,
|
|
16
|
+
PortableTextTextBlock,
|
|
17
|
+
SpanSchemaType,
|
|
18
|
+
TypedObject,
|
|
19
|
+
} from '@sanity/types'
|
|
20
|
+
import {
|
|
21
|
+
BaseSyntheticEvent,
|
|
22
|
+
ClipboardEvent as ClipboardEvent_2,
|
|
23
|
+
Component,
|
|
24
|
+
FocusEvent as FocusEvent_2,
|
|
25
|
+
ForwardRefExoticComponent,
|
|
26
|
+
HTMLProps,
|
|
27
|
+
JSX as JSX_2,
|
|
28
|
+
KeyboardEvent as KeyboardEvent_2,
|
|
29
|
+
MutableRefObject,
|
|
30
|
+
PropsWithChildren,
|
|
31
|
+
ReactElement,
|
|
32
|
+
RefAttributes,
|
|
33
|
+
RefObject,
|
|
34
|
+
TextareaHTMLAttributes,
|
|
35
|
+
} from 'react'
|
|
36
|
+
import {Observable, Subject} from 'rxjs'
|
|
37
|
+
import {Descendant, Node as Node_2, Operation} from 'slate'
|
|
31
38
|
import {ReactEditor} from 'slate-react'
|
|
32
|
-
import {
|
|
33
|
-
import {RefAttributes} from 'react'
|
|
34
|
-
import {RefObject} from 'react'
|
|
35
|
-
import {SpanSchemaType} from '@sanity/types'
|
|
36
|
-
import {Subject} from 'rxjs'
|
|
37
|
-
import {TextareaHTMLAttributes} from 'react'
|
|
38
|
-
import {TypedObject} from '@sanity/types'
|
|
39
|
+
import {DOMNode} from 'slate-react/dist/utils/dom'
|
|
39
40
|
|
|
40
41
|
/** @beta */
|
|
41
42
|
export declare interface BlockAnnotationRenderProps {
|
|
@@ -158,14 +159,22 @@ export declare interface EditableAPI {
|
|
|
158
159
|
},
|
|
159
160
|
) =>
|
|
160
161
|
| {
|
|
161
|
-
spanPath: Path
|
|
162
162
|
markDefPath: Path
|
|
163
|
+
markDefPaths: Array<Path>
|
|
164
|
+
spanPath: Path
|
|
163
165
|
}
|
|
164
166
|
| undefined
|
|
165
167
|
blur: () => void
|
|
166
|
-
delete: (
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
delete: (
|
|
169
|
+
selection: EditorSelection,
|
|
170
|
+
options?: EditableAPIDeleteOptions,
|
|
171
|
+
) => void
|
|
172
|
+
findByPath: (
|
|
173
|
+
path: Path,
|
|
174
|
+
) => [PortableTextBlock | PortableTextChild | undefined, Path | undefined]
|
|
175
|
+
findDOMNode: (
|
|
176
|
+
element: PortableTextBlock | PortableTextChild,
|
|
177
|
+
) => DOMNode | undefined
|
|
169
178
|
focus: () => void
|
|
170
179
|
focusBlock: () => PortableTextBlock | undefined
|
|
171
180
|
focusChild: () => PortableTextChild | undefined
|
|
@@ -190,7 +199,10 @@ export declare interface EditableAPI {
|
|
|
190
199
|
isCollapsedSelection: () => boolean
|
|
191
200
|
isExpandedSelection: () => boolean
|
|
192
201
|
isMarkActive: (mark: string) => boolean
|
|
193
|
-
isSelectionsOverlapping: (
|
|
202
|
+
isSelectionsOverlapping: (
|
|
203
|
+
selectionA: EditorSelection,
|
|
204
|
+
selectionB: EditorSelection,
|
|
205
|
+
) => boolean
|
|
194
206
|
isVoid: (element: PortableTextBlock | PortableTextChild) => boolean
|
|
195
207
|
marks: () => string[]
|
|
196
208
|
redo: () => void
|
|
@@ -287,7 +299,10 @@ export declare type HistoryItem = {
|
|
|
287
299
|
*/
|
|
288
300
|
export declare type HotkeyOptions = {
|
|
289
301
|
marks?: Record<string, string>
|
|
290
|
-
custom?: Record<
|
|
302
|
+
custom?: Record<
|
|
303
|
+
string,
|
|
304
|
+
(event: BaseSyntheticEvent, editor: PortableTextEditor) => void
|
|
305
|
+
>
|
|
291
306
|
}
|
|
292
307
|
|
|
293
308
|
/**
|
|
@@ -372,7 +387,9 @@ export declare type OnPasteResult =
|
|
|
372
387
|
/**
|
|
373
388
|
* @beta
|
|
374
389
|
*/
|
|
375
|
-
export declare type OnPasteResultOrPromise =
|
|
390
|
+
export declare type OnPasteResultOrPromise =
|
|
391
|
+
| OnPasteResult
|
|
392
|
+
| Promise<OnPasteResult>
|
|
376
393
|
|
|
377
394
|
/** @beta */
|
|
378
395
|
export declare interface PasteData {
|
|
@@ -403,7 +420,10 @@ export declare type PatchObservable = Observable<{
|
|
|
403
420
|
*/
|
|
404
421
|
export declare const PortableTextEditable: ForwardRefExoticComponent<
|
|
405
422
|
Omit<
|
|
406
|
-
Omit<
|
|
423
|
+
Omit<
|
|
424
|
+
TextareaHTMLAttributes<HTMLDivElement>,
|
|
425
|
+
'onPaste' | 'onCopy' | 'onBeforeInput'
|
|
426
|
+
> & {
|
|
407
427
|
hotkeys?: HotkeyOptions
|
|
408
428
|
onBeforeInput?: (event: InputEvent) => void
|
|
409
429
|
onPaste?: OnPasteFn
|
|
@@ -486,8 +506,18 @@ export declare class PortableTextEditor extends Component<PortableTextEditorProp
|
|
|
486
506
|
},
|
|
487
507
|
) =>
|
|
488
508
|
| {
|
|
489
|
-
|
|
509
|
+
/**
|
|
510
|
+
* @deprecated An annotation may be applied to multiple blocks, resulting
|
|
511
|
+
* in multiple `markDef`'s being created. Use `markDefPaths` instead.
|
|
512
|
+
*/
|
|
490
513
|
markDefPath: Path
|
|
514
|
+
markDefPaths: Array<Path>
|
|
515
|
+
/**
|
|
516
|
+
* @deprecated Does not return anything meaningful since an annotation
|
|
517
|
+
* can span multiple blocks and spans. If references the span closest
|
|
518
|
+
* to the focus point of the selection.
|
|
519
|
+
*/
|
|
520
|
+
spanPath: Path
|
|
491
521
|
}
|
|
492
522
|
| undefined
|
|
493
523
|
static blur: (editor: PortableTextEditor) => void
|
|
@@ -515,15 +545,34 @@ export declare class PortableTextEditor extends Component<PortableTextEditorProp
|
|
|
515
545
|
Path | undefined,
|
|
516
546
|
]
|
|
517
547
|
static focus: (editor: PortableTextEditor) => void
|
|
518
|
-
static focusBlock: (
|
|
519
|
-
|
|
548
|
+
static focusBlock: (
|
|
549
|
+
editor: PortableTextEditor,
|
|
550
|
+
) => PortableTextBlock | undefined
|
|
551
|
+
static focusChild: (
|
|
552
|
+
editor: PortableTextEditor,
|
|
553
|
+
) => PortableTextChild | undefined
|
|
520
554
|
static getSelection: (editor: PortableTextEditor) => EditorSelection
|
|
521
|
-
static getValue: (
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
static
|
|
525
|
-
|
|
526
|
-
|
|
555
|
+
static getValue: (
|
|
556
|
+
editor: PortableTextEditor,
|
|
557
|
+
) => PortableTextBlock[] | undefined
|
|
558
|
+
static hasBlockStyle: (
|
|
559
|
+
editor: PortableTextEditor,
|
|
560
|
+
blockStyle: string,
|
|
561
|
+
) => boolean | undefined
|
|
562
|
+
static hasListStyle: (
|
|
563
|
+
editor: PortableTextEditor,
|
|
564
|
+
listStyle: string,
|
|
565
|
+
) => boolean | undefined
|
|
566
|
+
static isCollapsedSelection: (
|
|
567
|
+
editor: PortableTextEditor,
|
|
568
|
+
) => boolean | undefined
|
|
569
|
+
static isExpandedSelection: (
|
|
570
|
+
editor: PortableTextEditor,
|
|
571
|
+
) => boolean | undefined
|
|
572
|
+
static isMarkActive: (
|
|
573
|
+
editor: PortableTextEditor,
|
|
574
|
+
mark: string,
|
|
575
|
+
) => boolean | undefined
|
|
527
576
|
static insertChild: (
|
|
528
577
|
editor: PortableTextEditor,
|
|
529
578
|
type: SpanSchemaType | ObjectSchemaType,
|
|
@@ -545,12 +594,23 @@ export declare class PortableTextEditor extends Component<PortableTextEditorProp
|
|
|
545
594
|
) => boolean | undefined
|
|
546
595
|
static isObjectPath: (editor: PortableTextEditor, path: Path) => boolean
|
|
547
596
|
static marks: (editor: PortableTextEditor) => string[] | undefined
|
|
548
|
-
static select: (
|
|
549
|
-
|
|
550
|
-
|
|
597
|
+
static select: (
|
|
598
|
+
editor: PortableTextEditor,
|
|
599
|
+
selection: EditorSelection | null,
|
|
600
|
+
) => void
|
|
601
|
+
static removeAnnotation: (
|
|
602
|
+
editor: PortableTextEditor,
|
|
603
|
+
type: ObjectSchemaType,
|
|
604
|
+
) => void | undefined
|
|
605
|
+
static toggleBlockStyle: (
|
|
606
|
+
editor: PortableTextEditor,
|
|
607
|
+
blockStyle: string,
|
|
608
|
+
) => void | undefined
|
|
551
609
|
static toggleList: (editor: PortableTextEditor, listStyle: string) => void
|
|
552
610
|
static toggleMark: (editor: PortableTextEditor, mark: string) => void
|
|
553
|
-
static getFragment: (
|
|
611
|
+
static getFragment: (
|
|
612
|
+
editor: PortableTextEditor,
|
|
613
|
+
) => PortableTextBlock[] | undefined
|
|
554
614
|
static undo: (editor: PortableTextEditor) => void
|
|
555
615
|
static redo: (editor: PortableTextEditor) => void
|
|
556
616
|
static isSelectionsOverlapping: (
|
|
@@ -706,9 +766,9 @@ export declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
706
766
|
*/
|
|
707
767
|
pteWithHotKeys: (event: KeyboardEvent_2<HTMLDivElement>) => void
|
|
708
768
|
/**
|
|
709
|
-
* Helper function that creates
|
|
769
|
+
* Helper function that creates a text block
|
|
710
770
|
*/
|
|
711
|
-
|
|
771
|
+
pteCreateTextBlock: (options: {decorators: Array<string>}) => Descendant
|
|
712
772
|
/**
|
|
713
773
|
* Undo
|
|
714
774
|
*/
|
|
@@ -779,28 +839,42 @@ export declare type RedoChange = {
|
|
|
779
839
|
}
|
|
780
840
|
|
|
781
841
|
/** @beta */
|
|
782
|
-
export declare type RenderAnnotationFunction = (
|
|
842
|
+
export declare type RenderAnnotationFunction = (
|
|
843
|
+
props: BlockAnnotationRenderProps,
|
|
844
|
+
) => JSX.Element
|
|
783
845
|
|
|
784
846
|
/** @beta */
|
|
785
|
-
export declare type RenderBlockFunction = (
|
|
847
|
+
export declare type RenderBlockFunction = (
|
|
848
|
+
props: BlockRenderProps,
|
|
849
|
+
) => JSX.Element
|
|
786
850
|
|
|
787
851
|
/** @beta */
|
|
788
|
-
export declare type RenderChildFunction = (
|
|
852
|
+
export declare type RenderChildFunction = (
|
|
853
|
+
props: BlockChildRenderProps,
|
|
854
|
+
) => JSX.Element
|
|
789
855
|
|
|
790
856
|
/** @beta */
|
|
791
|
-
export declare type RenderDecoratorFunction = (
|
|
857
|
+
export declare type RenderDecoratorFunction = (
|
|
858
|
+
props: BlockDecoratorRenderProps,
|
|
859
|
+
) => JSX.Element
|
|
792
860
|
|
|
793
861
|
/** @beta */
|
|
794
|
-
export declare type RenderEditableFunction = (
|
|
862
|
+
export declare type RenderEditableFunction = (
|
|
863
|
+
props: PortableTextEditableProps,
|
|
864
|
+
) => JSX.Element
|
|
795
865
|
|
|
796
866
|
/** @beta */
|
|
797
|
-
export declare type RenderListItemFunction = (
|
|
867
|
+
export declare type RenderListItemFunction = (
|
|
868
|
+
props: BlockListItemRenderProps,
|
|
869
|
+
) => JSX.Element
|
|
798
870
|
|
|
799
871
|
/** @beta */
|
|
800
872
|
export declare type RenderPlaceholderFunction = () => React.ReactNode
|
|
801
873
|
|
|
802
874
|
/** @beta */
|
|
803
|
-
export declare type RenderStyleFunction = (
|
|
875
|
+
export declare type RenderStyleFunction = (
|
|
876
|
+
props: BlockStyleRenderProps,
|
|
877
|
+
) => JSX.Element
|
|
804
878
|
|
|
805
879
|
/** @beta */
|
|
806
880
|
export declare type ScrollSelectionIntoViewFunction = (
|
package/lib/index.d.ts
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import {ArrayDefinition} from '@sanity/types'
|
|
2
|
-
import {ArraySchemaType} from '@sanity/types'
|
|
3
|
-
import {BaseSyntheticEvent} from 'react'
|
|
4
|
-
import {BlockDecoratorDefinition} from '@sanity/types'
|
|
5
|
-
import {BlockListDefinition} from '@sanity/types'
|
|
6
|
-
import {BlockSchemaType} from '@sanity/types'
|
|
7
|
-
import {BlockStyleDefinition} from '@sanity/types'
|
|
8
|
-
import {ClipboardEvent as ClipboardEvent_2} from 'react'
|
|
9
|
-
import {Component} from 'react'
|
|
10
|
-
import {Descendant} from 'slate'
|
|
11
|
-
import {DOMNode} from 'slate-react/dist/utils/dom'
|
|
12
|
-
import {FocusEvent as FocusEvent_2} from 'react'
|
|
13
|
-
import {ForwardRefExoticComponent} from 'react'
|
|
14
|
-
import {HTMLProps} from 'react'
|
|
15
|
-
import {JSX as JSX_2} from 'react'
|
|
16
|
-
import {KeyboardEvent as KeyboardEvent_2} from 'react'
|
|
17
|
-
import {MutableRefObject} from 'react'
|
|
18
|
-
import {Node as Node_2} from 'slate'
|
|
19
|
-
import {ObjectSchemaType} from '@sanity/types'
|
|
20
|
-
import {Observable} from 'rxjs'
|
|
21
|
-
import {Operation} from 'slate'
|
|
22
1
|
import {Patch} from '@portabletext/patches'
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
2
|
+
import {
|
|
3
|
+
ArrayDefinition,
|
|
4
|
+
ArraySchemaType,
|
|
5
|
+
BlockDecoratorDefinition,
|
|
6
|
+
BlockListDefinition,
|
|
7
|
+
BlockSchemaType,
|
|
8
|
+
BlockStyleDefinition,
|
|
9
|
+
ObjectSchemaType,
|
|
10
|
+
Path,
|
|
11
|
+
PortableTextBlock,
|
|
12
|
+
PortableTextChild,
|
|
13
|
+
PortableTextListBlock,
|
|
14
|
+
PortableTextObject,
|
|
15
|
+
PortableTextSpan,
|
|
16
|
+
PortableTextTextBlock,
|
|
17
|
+
SpanSchemaType,
|
|
18
|
+
TypedObject,
|
|
19
|
+
} from '@sanity/types'
|
|
20
|
+
import {
|
|
21
|
+
BaseSyntheticEvent,
|
|
22
|
+
ClipboardEvent as ClipboardEvent_2,
|
|
23
|
+
Component,
|
|
24
|
+
FocusEvent as FocusEvent_2,
|
|
25
|
+
ForwardRefExoticComponent,
|
|
26
|
+
HTMLProps,
|
|
27
|
+
JSX as JSX_2,
|
|
28
|
+
KeyboardEvent as KeyboardEvent_2,
|
|
29
|
+
MutableRefObject,
|
|
30
|
+
PropsWithChildren,
|
|
31
|
+
ReactElement,
|
|
32
|
+
RefAttributes,
|
|
33
|
+
RefObject,
|
|
34
|
+
TextareaHTMLAttributes,
|
|
35
|
+
} from 'react'
|
|
36
|
+
import {Observable, Subject} from 'rxjs'
|
|
37
|
+
import {Descendant, Node as Node_2, Operation} from 'slate'
|
|
31
38
|
import {ReactEditor} from 'slate-react'
|
|
32
|
-
import {
|
|
33
|
-
import {RefAttributes} from 'react'
|
|
34
|
-
import {RefObject} from 'react'
|
|
35
|
-
import {SpanSchemaType} from '@sanity/types'
|
|
36
|
-
import {Subject} from 'rxjs'
|
|
37
|
-
import {TextareaHTMLAttributes} from 'react'
|
|
38
|
-
import {TypedObject} from '@sanity/types'
|
|
39
|
+
import {DOMNode} from 'slate-react/dist/utils/dom'
|
|
39
40
|
|
|
40
41
|
/** @beta */
|
|
41
42
|
export declare interface BlockAnnotationRenderProps {
|
|
@@ -158,14 +159,22 @@ export declare interface EditableAPI {
|
|
|
158
159
|
},
|
|
159
160
|
) =>
|
|
160
161
|
| {
|
|
161
|
-
spanPath: Path
|
|
162
162
|
markDefPath: Path
|
|
163
|
+
markDefPaths: Array<Path>
|
|
164
|
+
spanPath: Path
|
|
163
165
|
}
|
|
164
166
|
| undefined
|
|
165
167
|
blur: () => void
|
|
166
|
-
delete: (
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
delete: (
|
|
169
|
+
selection: EditorSelection,
|
|
170
|
+
options?: EditableAPIDeleteOptions,
|
|
171
|
+
) => void
|
|
172
|
+
findByPath: (
|
|
173
|
+
path: Path,
|
|
174
|
+
) => [PortableTextBlock | PortableTextChild | undefined, Path | undefined]
|
|
175
|
+
findDOMNode: (
|
|
176
|
+
element: PortableTextBlock | PortableTextChild,
|
|
177
|
+
) => DOMNode | undefined
|
|
169
178
|
focus: () => void
|
|
170
179
|
focusBlock: () => PortableTextBlock | undefined
|
|
171
180
|
focusChild: () => PortableTextChild | undefined
|
|
@@ -190,7 +199,10 @@ export declare interface EditableAPI {
|
|
|
190
199
|
isCollapsedSelection: () => boolean
|
|
191
200
|
isExpandedSelection: () => boolean
|
|
192
201
|
isMarkActive: (mark: string) => boolean
|
|
193
|
-
isSelectionsOverlapping: (
|
|
202
|
+
isSelectionsOverlapping: (
|
|
203
|
+
selectionA: EditorSelection,
|
|
204
|
+
selectionB: EditorSelection,
|
|
205
|
+
) => boolean
|
|
194
206
|
isVoid: (element: PortableTextBlock | PortableTextChild) => boolean
|
|
195
207
|
marks: () => string[]
|
|
196
208
|
redo: () => void
|
|
@@ -287,7 +299,10 @@ export declare type HistoryItem = {
|
|
|
287
299
|
*/
|
|
288
300
|
export declare type HotkeyOptions = {
|
|
289
301
|
marks?: Record<string, string>
|
|
290
|
-
custom?: Record<
|
|
302
|
+
custom?: Record<
|
|
303
|
+
string,
|
|
304
|
+
(event: BaseSyntheticEvent, editor: PortableTextEditor) => void
|
|
305
|
+
>
|
|
291
306
|
}
|
|
292
307
|
|
|
293
308
|
/**
|
|
@@ -372,7 +387,9 @@ export declare type OnPasteResult =
|
|
|
372
387
|
/**
|
|
373
388
|
* @beta
|
|
374
389
|
*/
|
|
375
|
-
export declare type OnPasteResultOrPromise =
|
|
390
|
+
export declare type OnPasteResultOrPromise =
|
|
391
|
+
| OnPasteResult
|
|
392
|
+
| Promise<OnPasteResult>
|
|
376
393
|
|
|
377
394
|
/** @beta */
|
|
378
395
|
export declare interface PasteData {
|
|
@@ -403,7 +420,10 @@ export declare type PatchObservable = Observable<{
|
|
|
403
420
|
*/
|
|
404
421
|
export declare const PortableTextEditable: ForwardRefExoticComponent<
|
|
405
422
|
Omit<
|
|
406
|
-
Omit<
|
|
423
|
+
Omit<
|
|
424
|
+
TextareaHTMLAttributes<HTMLDivElement>,
|
|
425
|
+
'onPaste' | 'onCopy' | 'onBeforeInput'
|
|
426
|
+
> & {
|
|
407
427
|
hotkeys?: HotkeyOptions
|
|
408
428
|
onBeforeInput?: (event: InputEvent) => void
|
|
409
429
|
onPaste?: OnPasteFn
|
|
@@ -486,8 +506,18 @@ export declare class PortableTextEditor extends Component<PortableTextEditorProp
|
|
|
486
506
|
},
|
|
487
507
|
) =>
|
|
488
508
|
| {
|
|
489
|
-
|
|
509
|
+
/**
|
|
510
|
+
* @deprecated An annotation may be applied to multiple blocks, resulting
|
|
511
|
+
* in multiple `markDef`'s being created. Use `markDefPaths` instead.
|
|
512
|
+
*/
|
|
490
513
|
markDefPath: Path
|
|
514
|
+
markDefPaths: Array<Path>
|
|
515
|
+
/**
|
|
516
|
+
* @deprecated Does not return anything meaningful since an annotation
|
|
517
|
+
* can span multiple blocks and spans. If references the span closest
|
|
518
|
+
* to the focus point of the selection.
|
|
519
|
+
*/
|
|
520
|
+
spanPath: Path
|
|
491
521
|
}
|
|
492
522
|
| undefined
|
|
493
523
|
static blur: (editor: PortableTextEditor) => void
|
|
@@ -515,15 +545,34 @@ export declare class PortableTextEditor extends Component<PortableTextEditorProp
|
|
|
515
545
|
Path | undefined,
|
|
516
546
|
]
|
|
517
547
|
static focus: (editor: PortableTextEditor) => void
|
|
518
|
-
static focusBlock: (
|
|
519
|
-
|
|
548
|
+
static focusBlock: (
|
|
549
|
+
editor: PortableTextEditor,
|
|
550
|
+
) => PortableTextBlock | undefined
|
|
551
|
+
static focusChild: (
|
|
552
|
+
editor: PortableTextEditor,
|
|
553
|
+
) => PortableTextChild | undefined
|
|
520
554
|
static getSelection: (editor: PortableTextEditor) => EditorSelection
|
|
521
|
-
static getValue: (
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
static
|
|
525
|
-
|
|
526
|
-
|
|
555
|
+
static getValue: (
|
|
556
|
+
editor: PortableTextEditor,
|
|
557
|
+
) => PortableTextBlock[] | undefined
|
|
558
|
+
static hasBlockStyle: (
|
|
559
|
+
editor: PortableTextEditor,
|
|
560
|
+
blockStyle: string,
|
|
561
|
+
) => boolean | undefined
|
|
562
|
+
static hasListStyle: (
|
|
563
|
+
editor: PortableTextEditor,
|
|
564
|
+
listStyle: string,
|
|
565
|
+
) => boolean | undefined
|
|
566
|
+
static isCollapsedSelection: (
|
|
567
|
+
editor: PortableTextEditor,
|
|
568
|
+
) => boolean | undefined
|
|
569
|
+
static isExpandedSelection: (
|
|
570
|
+
editor: PortableTextEditor,
|
|
571
|
+
) => boolean | undefined
|
|
572
|
+
static isMarkActive: (
|
|
573
|
+
editor: PortableTextEditor,
|
|
574
|
+
mark: string,
|
|
575
|
+
) => boolean | undefined
|
|
527
576
|
static insertChild: (
|
|
528
577
|
editor: PortableTextEditor,
|
|
529
578
|
type: SpanSchemaType | ObjectSchemaType,
|
|
@@ -545,12 +594,23 @@ export declare class PortableTextEditor extends Component<PortableTextEditorProp
|
|
|
545
594
|
) => boolean | undefined
|
|
546
595
|
static isObjectPath: (editor: PortableTextEditor, path: Path) => boolean
|
|
547
596
|
static marks: (editor: PortableTextEditor) => string[] | undefined
|
|
548
|
-
static select: (
|
|
549
|
-
|
|
550
|
-
|
|
597
|
+
static select: (
|
|
598
|
+
editor: PortableTextEditor,
|
|
599
|
+
selection: EditorSelection | null,
|
|
600
|
+
) => void
|
|
601
|
+
static removeAnnotation: (
|
|
602
|
+
editor: PortableTextEditor,
|
|
603
|
+
type: ObjectSchemaType,
|
|
604
|
+
) => void | undefined
|
|
605
|
+
static toggleBlockStyle: (
|
|
606
|
+
editor: PortableTextEditor,
|
|
607
|
+
blockStyle: string,
|
|
608
|
+
) => void | undefined
|
|
551
609
|
static toggleList: (editor: PortableTextEditor, listStyle: string) => void
|
|
552
610
|
static toggleMark: (editor: PortableTextEditor, mark: string) => void
|
|
553
|
-
static getFragment: (
|
|
611
|
+
static getFragment: (
|
|
612
|
+
editor: PortableTextEditor,
|
|
613
|
+
) => PortableTextBlock[] | undefined
|
|
554
614
|
static undo: (editor: PortableTextEditor) => void
|
|
555
615
|
static redo: (editor: PortableTextEditor) => void
|
|
556
616
|
static isSelectionsOverlapping: (
|
|
@@ -706,9 +766,9 @@ export declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
706
766
|
*/
|
|
707
767
|
pteWithHotKeys: (event: KeyboardEvent_2<HTMLDivElement>) => void
|
|
708
768
|
/**
|
|
709
|
-
* Helper function that creates
|
|
769
|
+
* Helper function that creates a text block
|
|
710
770
|
*/
|
|
711
|
-
|
|
771
|
+
pteCreateTextBlock: (options: {decorators: Array<string>}) => Descendant
|
|
712
772
|
/**
|
|
713
773
|
* Undo
|
|
714
774
|
*/
|
|
@@ -779,28 +839,42 @@ export declare type RedoChange = {
|
|
|
779
839
|
}
|
|
780
840
|
|
|
781
841
|
/** @beta */
|
|
782
|
-
export declare type RenderAnnotationFunction = (
|
|
842
|
+
export declare type RenderAnnotationFunction = (
|
|
843
|
+
props: BlockAnnotationRenderProps,
|
|
844
|
+
) => JSX.Element
|
|
783
845
|
|
|
784
846
|
/** @beta */
|
|
785
|
-
export declare type RenderBlockFunction = (
|
|
847
|
+
export declare type RenderBlockFunction = (
|
|
848
|
+
props: BlockRenderProps,
|
|
849
|
+
) => JSX.Element
|
|
786
850
|
|
|
787
851
|
/** @beta */
|
|
788
|
-
export declare type RenderChildFunction = (
|
|
852
|
+
export declare type RenderChildFunction = (
|
|
853
|
+
props: BlockChildRenderProps,
|
|
854
|
+
) => JSX.Element
|
|
789
855
|
|
|
790
856
|
/** @beta */
|
|
791
|
-
export declare type RenderDecoratorFunction = (
|
|
857
|
+
export declare type RenderDecoratorFunction = (
|
|
858
|
+
props: BlockDecoratorRenderProps,
|
|
859
|
+
) => JSX.Element
|
|
792
860
|
|
|
793
861
|
/** @beta */
|
|
794
|
-
export declare type RenderEditableFunction = (
|
|
862
|
+
export declare type RenderEditableFunction = (
|
|
863
|
+
props: PortableTextEditableProps,
|
|
864
|
+
) => JSX.Element
|
|
795
865
|
|
|
796
866
|
/** @beta */
|
|
797
|
-
export declare type RenderListItemFunction = (
|
|
867
|
+
export declare type RenderListItemFunction = (
|
|
868
|
+
props: BlockListItemRenderProps,
|
|
869
|
+
) => JSX.Element
|
|
798
870
|
|
|
799
871
|
/** @beta */
|
|
800
872
|
export declare type RenderPlaceholderFunction = () => React.ReactNode
|
|
801
873
|
|
|
802
874
|
/** @beta */
|
|
803
|
-
export declare type RenderStyleFunction = (
|
|
875
|
+
export declare type RenderStyleFunction = (
|
|
876
|
+
props: BlockStyleRenderProps,
|
|
877
|
+
) => JSX.Element
|
|
804
878
|
|
|
805
879
|
/** @beta */
|
|
806
880
|
export declare type ScrollSelectionIntoViewFunction = (
|