Skip to content

Instantly share code, notes, and snippets.

@gwillz
Created July 5, 2018 08:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwillz/1e23b573af3db71aad268d41a988d3d6 to your computer and use it in GitHub Desktop.
Save gwillz/1e23b573af3db71aad268d41a988d3d6 to your computer and use it in GitHub Desktop.
Naive TypeScript support for draft-js-plugins
/// <resources type="react" />
/// <resources type="draft-js" />
declare module "draft-js-plugins-editor" {
export type PluginsEditorProps = Draft.EditorProps | {
plugins: any,
}
export default class PluginsEditor
extends React.Component<PluginsEditorProps, Draft.EditorState> {}
export function createEditorStateWithText(text: string): PluginsEditor;
export function composeDecorators(...func: any[]): (...args: any[]) => any;
}
// @todo flesh out component type
declare module "draft-js-emoji-plugin" {
function createEmojiPlugin(config?: object): any;
export type EmojiSuggestions = any;
export default createEmojiPlugin;
}
declare module "draft-js-mention-plugin" {
// @todo missing defaultTheme
// @todo missing defaultSuggestionsFilter
type Props = {
suggestions: any[],
onAddMention: (mention: any) => void,
entryComponent: (...props: any[]) => JSX.Element,
entityMutability: string,
}
type State = {
isActive: boolean,
focusedOptionIndex: number,
}
export type MentionSuggestions<T> = React.Component<Props, State>;
export default function createMentionPlugin(config?: object): any;
}
@agungsb
Copy link

agungsb commented Jun 2, 2019

This gist was exactly what I was looking for. Thanks, @gwillz.

And also thanks to @iomal for your help on how to make this working.

@Nitin2392
Copy link

This is very helpful! Thanks @gwillz and @iomal

@shoebmogal
Copy link

Thank you so much!

@anders0l
Copy link

awesome!
thanks!

Simple defaultSuggestionsFilter

 export type defaultSuggestionsFilter = (searchValue: string, suggestions: any[]) => any[]

@evilartnboy
Copy link

How do we use this to enable plugins for typescript editors?

@milovanderlinden
Copy link

Nice start! I have a small addition:

export function defaultSuggestionsFilter<T>(value: string, suggestions: T[]): any;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment