Skip to content

Commit bffbb31

Browse files
authored
Adding Typescript Definitions (#429)
1 parent ab133ba commit bffbb31

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"license": "MIT",
77
"main": "dist/draftail.cjs.js",
88
"module": "dist/draftail.esm.js",
9+
"types": "./types/draftail.d.ts",
910
"keywords": [
1011
"draftjs",
1112
"draft.js",

types/draftail.d.ts

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
declare module 'draftail' {
2+
import { EditorState, RawDraftContentState } from 'draft-js';
3+
import * as React from 'react';
4+
5+
export interface DrafTailEditorProps {
6+
// Initial content of the editor. Use this to edit pre-existing content.
7+
rawContentState: RawDraftContentState | null;
8+
// Called when changes occured. Use this to persist editor content.
9+
onSave: (rawContent: RawDraftContentState | null) => void;
10+
// Content of the editor; when using the editor as a controlled component. Incompatible with `rawContentState` and `onSave`.
11+
editorState: EditorState;
12+
// Called whenever the editor state is updated. Use this to manage the content of a controlled editor. Incompatible with `rawContentState` and `onSave`.
13+
onChange: (editorState: EditorState) => void;
14+
// Called when the editor receives focus.
15+
onFocus: () => {};
16+
// Called when the editor loses focus.
17+
onBlur: () => {};
18+
// Displayed when the editor is empty. Hidden if the user changes styling.
19+
placeholder: string;
20+
// Enable the use of horizontal rules in the editor.
21+
enableHorizontalRule: boolean;
22+
// Enable the use of line breaks in the editor.
23+
enableLineBreak: boolean;
24+
// Show undo control in the toolbar.
25+
showUndoControl: boolean;
26+
// Show redo control in the toolbar.
27+
showRedoControl: boolean;
28+
// Disable copy/paste of rich text in the editor.
29+
stripPastedStyles: boolean;
30+
// Set whether spellcheck is turned on for your editor.
31+
// See https://draftjs.org/docs/api-reference-editor.html#spellcheck.
32+
spellCheck: boolean;
33+
// Set whether the editor should be rendered in readOnly mode.
34+
// See https://draftjs.org/docs/api-reference-editor.html#readonly
35+
readOnly: boolean;
36+
// Optionally set the overriding text alignment for this editor.
37+
// See https://draftjs.org/docs/api-reference-editor.html#textalignment.
38+
textAlignment: 'left' | 'center' | 'right';
39+
// Optionally set the overriding text directionality for this editor.
40+
// See https://draftjs.org/docs/api-reference-editor.html#textdirectionality.
41+
textDirectionality: 'left' | 'center' | 'right';
42+
// Set if auto capitalization is turned on and how it behaves.
43+
// See https://draftjs.org/docs/api-reference-editor.html#autocapitalize-string.
44+
autoCapitalize: boolean;
45+
// Set if auto complete is turned on and how it behaves.
46+
// See https://draftjs.org/docs/api-reference-editor.html#autocomplete-string.
47+
autoComplete: boolean;
48+
// Set if auto correct is turned on and how it behaves.
49+
// See https://draftjs.org/docs/api-reference-editor.html#autocorrect-string.
50+
autoCorrect: boolean;
51+
// See https://draftjs.org/docs/api-reference-editor.html#aria-props.
52+
ariaDescribedBy: null;
53+
// List of the available block types.
54+
blockTypes: any[];
55+
// List of the available inline styles.
56+
inlineStyles: any[];
57+
// List of the available entity types.
58+
entityTypes: any[];
59+
// List of active decorators.
60+
decorators: any[];
61+
// Additional React components to render in the toolbar.
62+
controls: any[];
63+
// List of plugins of the draft-js-plugins architecture.
64+
plugins: any[];
65+
// Optionally override the default Draftail toolbar; removing or replacing it.
66+
topToolbar: Toolbar;
67+
// Optionally add a custom toolbar underneath the editor; e.g. for metrics.
68+
bottomToolbar: Toolbar;
69+
// Max level of nesting for list items. 0 = no nesting. Maximum = 10.
70+
maxListNesting: number;
71+
// Frequency at which to call the save callback (ms).
72+
stateSaveInterval: number;
73+
}
74+
75+
export const BLOCK_TYPE = {
76+
// This is used to represent a normal text block (paragraph).
77+
UNSTYLED: 'unstyled',
78+
HEADER_ONE: 'header-one',
79+
HEADER_TWO: 'header-two',
80+
HEADER_THREE: 'header-three',
81+
HEADER_FOUR: 'header-four',
82+
HEADER_FIVE: 'header-five',
83+
HEADER_SIX: 'header-six',
84+
UNORDERED_LIST_ITEM: 'unordered-list-item',
85+
ORDERED_LIST_ITEM: 'ordered-list-item',
86+
BLOCKQUOTE: 'blockquote',
87+
CODE: 'code-block',
88+
// This represents a "custom" block, not for rich text, with arbitrary content.
89+
ATOMIC: 'atomic',
90+
};
91+
export const ENTITY_TYPE = {
92+
LINK: 'LINK',
93+
IMAGE: 'IMAGE',
94+
HORIZONTAL_RULE: 'HORIZONTAL_RULE',
95+
};
96+
97+
export const INLINE_STYLE = {
98+
BOLD: 'BOLD',
99+
ITALIC: 'ITALIC',
100+
CODE: 'CODE',
101+
UNDERLINE: 'UNDERLINE',
102+
STRIKETHROUGH: 'STRIKETHROUGH',
103+
MARK: 'MARK',
104+
QUOTATION: 'QUOTATION',
105+
SMALL: 'SMALL',
106+
SAMPLE: 'SAMPLE',
107+
INSERT: 'INSERT',
108+
DELETE: 'DELETE',
109+
KEYBOARD: 'KEYBOARD',
110+
SUPERSCRIPT: 'SUPERSCRIPT',
111+
SUBSCRIPT: 'SUBSCRIPT',
112+
};
113+
114+
export class DraftailEditor extends React.PureComponent<Partial<DrafTailEditorProps>> {}
115+
}

0 commit comments

Comments
 (0)