Created
July 5, 2018 08:53
-
-
Save gwillz/1e23b573af3db71aad268d41a988d3d6 to your computer and use it in GitHub Desktop.
Naive TypeScript support for draft-js-plugins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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; | |
} |
Hello @gwillz, I am wondering where is createMentionPlugin defined in the module. I searched the project src, but could not find it.
Because I am trying to add some missing declarations , but no idea where to begin with.
@wenx1 I believe createMentionPlugin
is from draft-js-mention-plugin
package. So you have to install that package first. If you don't need that package, you can remove these lines:
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;
}
Thank you so much!
awesome!
thanks!
Simple defaultSuggestionsFilter
export type defaultSuggestionsFilter = (searchValue: string, suggestions: any[]) => any[]
How do we use this to enable plugins for typescript editors?
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
Hello @gwillz, I am wondering where is createMentionPlugin defined in the module. I searched the project src, but could not find it.
Because I am trying to add some missing declarations , but no idea where to begin with.