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