1 | import {
|
2 | ContentBlock,
|
3 | DraftDecorator,
|
4 | DraftDragType,
|
5 | DraftEditorCommand,
|
6 | DraftHandleValue,
|
7 | DraftInlineStyle,
|
8 | DraftStyleMap,
|
9 | Editor,
|
10 | EditorProps,
|
11 | EditorState,
|
12 | SelectionState
|
13 | } from "draft-js";
|
14 | import { Component, Ref, SyntheticEvent, KeyboardEvent } from "react";
|
15 |
|
16 | export interface PluginFunctions {
|
17 | getPlugins(): EditorPlugin[];
|
18 | getProps(): any;
|
19 | setEditorState(editorState: EditorState): void;
|
20 | getEditorState(): EditorState;
|
21 | getReadOnly(): boolean;
|
22 | setReadOnly(readOnly: boolean): void;
|
23 | getEditorRef(): Ref<any>;
|
24 | }
|
25 |
|
26 | export interface EditorPlugin {
|
27 | decorators?: DraftDecorator[];
|
28 | getAccessibilityProps?: () => {
|
29 | ariaHasPopup: string;
|
30 | ariaExpanded: string;
|
31 | };
|
32 | initialize?: (pluginFunctions: PluginFunctions) => void;
|
33 | onChange?: (
|
34 | editorState: EditorState,
|
35 | pluginFunctions: PluginFunctions
|
36 | ) => EditorState;
|
37 | willUnmount?: (pluginFunctions: PluginFunctions) => void;
|
38 |
|
39 |
|
40 | blockRendererFn?(block: ContentBlock, pluginFunctions: PluginFunctions): any;
|
41 | blockStyleFn?(block: ContentBlock, pluginFunctions: PluginFunctions): string;
|
42 | customStyleFn?: (
|
43 | style: DraftInlineStyle,
|
44 | block: ContentBlock,
|
45 | pluginFunctions: PluginFunctions
|
46 | ) => DraftStyleMap;
|
47 | keyBindingFn?(
|
48 | e: KeyboardEvent,
|
49 | pluginFunctions: PluginFunctions
|
50 | ): DraftEditorCommand | null;
|
51 | handleReturn?(
|
52 | e: KeyboardEvent,
|
53 | editorState: EditorState,
|
54 | pluginFunctions: PluginFunctions
|
55 | ): DraftHandleValue;
|
56 | handleKeyCommand?(
|
57 | command: DraftEditorCommand,
|
58 | editorState: EditorState,
|
59 | eventTimeStamp: number,
|
60 | pluginFunctions: PluginFunctions
|
61 | ): DraftHandleValue;
|
62 | handleBeforeInput?(
|
63 | chars: string,
|
64 | editorState: EditorState,
|
65 | eventTimeStamp: number,
|
66 | pluginFunctions: PluginFunctions
|
67 | ): DraftHandleValue;
|
68 | handlePastedText?(
|
69 | text: string,
|
70 | html: string | undefined,
|
71 | editorState: EditorState,
|
72 | pluginFunctions: PluginFunctions
|
73 | ): DraftHandleValue;
|
74 | handlePastedFiles?(
|
75 | files: Array<Blob>,
|
76 | pluginFunctions: PluginFunctions
|
77 | ): DraftHandleValue;
|
78 | handleDroppedFiles?(
|
79 | selection: SelectionState,
|
80 | files: Array<Blob>,
|
81 | pluginFunctions: PluginFunctions
|
82 | ): DraftHandleValue;
|
83 | handleDrop?(
|
84 | selection: SelectionState,
|
85 | dataTransfer: Object,
|
86 | isInternal: DraftDragType,
|
87 | pluginFunctions: PluginFunctions
|
88 | ): DraftHandleValue;
|
89 | onEscape?(e: KeyboardEvent, pluginFunctions: PluginFunctions): void;
|
90 | onTab?(e: KeyboardEvent, pluginFunctions: PluginFunctions): void;
|
91 | onUpArrow?(e: KeyboardEvent, pluginFunctions: PluginFunctions): void;
|
92 | onDownArrow?(e: KeyboardEvent, pluginFunctions: PluginFunctions): void;
|
93 | onRightArrow?(e: KeyboardEvent, pluginFunctions: PluginFunctions): void;
|
94 | onLeftArrow?(e: KeyboardEvent, pluginFunctions: PluginFunctions): void;
|
95 | onBlur?(e: SyntheticEvent, pluginFunctions: PluginFunctions): void;
|
96 | onFocus?(e: SyntheticEvent, pluginFunctions: PluginFunctions): void;
|
97 | }
|
98 |
|
99 | export const composeDecorators: (
|
100 | ...decorators: DraftDecorator[]
|
101 | ) => DraftDecorator;
|
102 |
|
103 | export interface PluginEditorProps extends EditorProps {
|
104 | plugins?: EditorPlugin[];
|
105 | defaultKeyBindings?: boolean;
|
106 | defaultKeyCommands?: boolean;
|
107 | defaultBlockRenderMap?: boolean;
|
108 |
|
109 |
|
110 | decorators?: DraftDecorator[];
|
111 | }
|
112 |
|
113 | declare class PluginEditor extends Component<PluginEditorProps> {
|
114 | focus(): void;
|
115 | blur(): void;
|
116 | getPlugins(): EditorPlugin[];
|
117 | getPluginMethods(): PluginFunctions;
|
118 | getEditorRef(): Editor | undefined;
|
119 | }
|
120 |
|
121 | export default PluginEditor;
|