diff --git a/types/braft-editor/braft-editor-tests.tsx b/types/braft-editor/braft-editor-tests.tsx new file mode 100644 index 0000000000..354c4cbb5b --- /dev/null +++ b/types/braft-editor/braft-editor-tests.tsx @@ -0,0 +1,31 @@ +import * as React from "react"; +import * as BraftEditor from "braft-editor"; +import { + RawDraftContentState, +} from 'draft-js'; +class BraftEditorTest extends React.Component { + state = { + content: null + }; + render() { + const editorProps = { + height: 500, + initialContent: this.state.content, + onChange: this.handleChange, + onHTMLChange: this.handleHTMLChange + }; + return ( +
+ +
+ ); + } + private handleChange = (content: RawDraftContentState) => { + console.log(content); + } + private handleHTMLChange = (html: string) => { + console.log(html); + } +} diff --git a/types/braft-editor/index.d.ts b/types/braft-editor/index.d.ts new file mode 100644 index 0000000000..225d32722d --- /dev/null +++ b/types/braft-editor/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for braft-editor 1.1 +// Project: https://github.com/margox/braft#readme +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import * as React from "react"; +import { RawDraftContentState } from 'draft-js'; +export as namespace BraftEditor; +export = BraftEditor; +declare namespace BraftEditor { + interface fontFamiliesRange { + name: string; + family: string; + } + interface editorProps { + editorState?: any; + contentFormat?: RawDraftContentState; + initialContent?: RawDraftContentState | null; + onChange?: (content: RawDraftContentState) => void; + onRawChange?: (content: RawDraftContentState) => void; + onHTMLChange?: (content: string) => void; + controls?: string[]; + extendControls?: any[]; + height?: number; + language?: string; + placeholder?: string; + viewWrapper?: string; + colors?: string[]; + fontSizes?: number[]; + fontFamilies?: fontFamiliesRange[]; + media?: { [key: string]: any }; + getContent?: (format?: string) => RawDraftContentState; + setContent?: (content: RawDraftContentState, format?: string) => void; + toggleSelectionBlockType?: (blockquote: string) => any; + toggleSelectionInlineStyle?: (style: string, stylesToBeRemoved?: string[]) => any; + insertMedias?: (medias: Array<{ type: string, name: string, url: string }>) => void; + insertText?: (text: string, replace?: boolean) => void; + toggleSelectionLink?: (href: string, target: string) => void; + toggleSelectionAlignment?: (alignment: string) => any; + toggleSelectionColor?: (hexColor: string) => void; + toggleSelectionBackgroundColor?: (hexColor: string) => void; + toggleSelectionFontSize?: (fontSize: number) => void; + toggleSelectionFontFamily?: (fontFamily: string) => void; + selectionCollapsed?: () => boolean; + selectionHasInlineStyle?: () => boolean; + getSelectionBlockType?: () => string; + getEditorState?: () => void; + forceRender?: () => void; + getDraftInstance?: () => any; + getMediaLibraryInstance?: () => any; + getSelectionInlineStyle?: () => any; + undo?: () => any; + redo?: () => any; + focus?: () => void; + blur?: () => void; + } +} +declare class BraftEditor extends React.Component { } diff --git a/types/braft-editor/tsconfig.json b/types/braft-editor/tsconfig.json new file mode 100644 index 0000000000..f04b8febfe --- /dev/null +++ b/types/braft-editor/tsconfig.json @@ -0,0 +1,25 @@ +{ + "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", + "braft-editor-tests.tsx" + ] +} \ No newline at end of file diff --git a/types/braft-editor/tslint.json b/types/braft-editor/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/braft-editor/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }