diff --git a/types/react-rte/index.d.ts b/types/react-rte/index.d.ts new file mode 100644 index 0000000000..61cded4934 --- /dev/null +++ b/types/react-rte/index.d.ts @@ -0,0 +1,100 @@ +// Type definitions for react-rte 0.16.1 +// Project: https://github.com/sstur/react-rte +// Definitions by: jclyons52 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { Component, ReactNode } from "react"; +import { ContentBlock, EditorState } from "draft-js"; +import { Options as ImportOptions } from "draft-js-import-html"; +import { Options as ExportOptions } from "draft-js-export-html"; + +type StringMap = { [key: string]: string }; + +export class EditorValue { + constructor(editorState: EditorState, cache: StringMap); + getEditorState(): EditorState; + setEditorState(editorState: EditorState): EditorValue; + toString(format: string, options?: ExportOptions): string; + setContentFromString( + markup: string, + format: string, + options?: ImportOptions + ): EditorValue; + static createEmpty(decorator?: any): EditorValue; + static createFromState(editorState: EditorState): EditorValue; + static createFromString( + markup: string, + format: string, + decorator?: any, + options?: ImportOptions + ): EditorValue; +} + +interface StyleConfig { + label: string; + style: string; + className?: string; +} + +type StyleConfigList = Array; + +type ChangeHandler = (value: EditorValue) => any; + +type GetControlState = (key: string) => string | undefined; + +type SetControlState = (key: string, value: string) => void; + +type CustControlFunc = ( + set: SetControlState, + get: GetControlState, + state: EditorState +) => ReactNode; + +type CustomControl = ReactNode | CustControlFunc; + +type GroupName = + | "INLINE_STYLE_BUTTONS" + | "BLOCK_TYPE_BUTTONS" + | "LINK_BUTTONS" + | "BLOCK_TYPE_DROPDOWN" + | "HISTORY_BUTTONS" + | "IMAGE_BUTTON"; + +interface ToolbarConfig { + display: Array; + extraProps?: Object; + INLINE_STYLE_BUTTONS: StyleConfigList; + BLOCK_TYPE_DROPDOWN: StyleConfigList; + BLOCK_TYPE_BUTTONS: StyleConfigList; +} + +interface IProps { + className?: string; + toolbarClassName?: string; + editorClassName?: string; + value: EditorValue; + onChange?: ChangeHandler; + placeholder?: string; + customStyleMap?: { [style: string]: { [key: string]: any } }; + handleReturn?: (event: Object) => boolean; + customControls?: Array; + readOnly?: boolean; + disabled?: boolean; // Alias of readOnly + toolbarConfig?: ToolbarConfig; + blockStyleFn?: (block: ContentBlock) => string | undefined; + autoFocus?: boolean; + keyBindingFn?: (event: Object) => string | undefined; + rootStyle?: Object; + editorStyle?: Object; + toolbarStyle?: Object; +} + +export default class RichTextEditor extends Component { + public static createEmptyValue(): EditorValue; + public static createValueFromString( + markup: string, + format: string, + options?: ImportOptions + ): EditorValue; +} diff --git a/types/react-rte/package.json b/types/react-rte/package.json new file mode 100644 index 0000000000..54c91a447b --- /dev/null +++ b/types/react-rte/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "dependencies": { + "draft-js-export-html": ">=0.6.0", + "draft-js-import-html": ">=0.4.0" + } +} diff --git a/types/react-rte/tsconfig.json b/types/react-rte/tsconfig.json new file mode 100644 index 0000000000..414a31a0fa --- /dev/null +++ b/types/react-rte/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6", "dom"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "jsx": "react", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts"] +} diff --git a/types/react-rte/tslint.json b/types/react-rte/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/react-rte/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}