Skip to content

Instantly share code, notes, and snippets.

@bmingles
Created June 4, 2019 12:49
Show Gist options
  • Save bmingles/120e1b3d1dec4c77ef0a58045b1e97af to your computer and use it in GitHub Desktop.
Save bmingles/120e1b3d1dec4c77ef0a58045b1e97af to your computer and use it in GitHub Desktop.
Draft.js
module 'draft-js-plugins-editor' {
import React from 'react';
import {
CompositeDecorator,
DraftEditorCommand,
Editor,
EditorProps,
EditorState
} from 'draft-js';
interface PluginEditorProps extends EditorProps {
plugins: Plugin[]
}
class PluginEditor extends React.Component<PluginEditorProps, {}> {
blur(): void;
focus(): void;
}
export { PluginEditor as default };
export interface HandleKeyCommandHelpers {
getEditorRef: () => unknown,
getEditorState: () => EditorState,
getPlugins: () => Plugin[],
getProps: () => unknown,
getReadOnly: () => boolean,
setEditorState: (editorState: EditorState) => void,
setReadOnly: unknown,
}
type FirstArgument<T> = T extends new (a: Array<infer U>) => any ? U : any;
type Decorator = FirstArgument<typeof CompositeDecorator>;
export interface DecoratorComponentProps {
children: React.ReactNode,
contentState: ContentState,
decoratedText: string,
getEditorState: () => EditorState,
setEditorState: (editorState: EditorState) => void,
}
export interface Plugin {
customStyleMap?: Record<string, Record<string, string>>,
decorators?: Decorator[],
initialize?: (init: {
getEditorState: () => EditorState,
setEditorState: (editorState: EditorState) => void
}) => void,
keyBindingFn?: (e: React.KeyboardEvent<{}>) => string | undefined,
handleKeyCommand?: (
command: string,
editorState: EditorState,
helpers: HandleKeyCommandHelpers
) => boolean | undefined,
onChange?: (editorState: EditorState) => EditorState,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment