From 85ca58c460c2759d31eca9d488d7ab4cd187facb Mon Sep 17 00:00:00 2001 From: petitspois Date: Wed, 6 Dec 2017 16:52:20 +0800 Subject: [PATCH 1/3] add braft-editor definition --- types/braft-editor/braft-editor-tests.tsx | 31 +++++++++++ types/braft-editor/index.d.ts | 68 +++++++++++++++++++++++ types/braft-editor/tsconfig.json | 25 +++++++++ types/braft-editor/tslint.json | 1 + 4 files changed, 125 insertions(+) create mode 100644 types/braft-editor/braft-editor-tests.tsx create mode 100644 types/braft-editor/index.d.ts create mode 100644 types/braft-editor/tsconfig.json create mode 100644 types/braft-editor/tslint.json 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..7bb8a39bb8 --- /dev/null +++ b/types/braft-editor/index.d.ts @@ -0,0 +1,68 @@ +// 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?: Array; + media?: { [key: string]: any }; + setState?: Function; + getContent?: (format?: string) => RawDraftContentState; + setContent?: (content: RawDraftContentState, format?: string) => void; + toggleSelectionBlockType?: (blockquote: string) => any; + toggleSelectionInlineStyle?: (style: string, stylesToBeRemoved?: string[]) => any; + insertMedias?: (medias: { 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" } From 985163c9f14b456e186745ecf28cfc499bd4213f Mon Sep 17 00:00:00 2001 From: petitspois Date: Wed, 6 Dec 2017 17:22:33 +0800 Subject: [PATCH 2/3] add braft-editor definition --- types/braft-editor/index.d.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/types/braft-editor/index.d.ts b/types/braft-editor/index.d.ts index 7bb8a39bb8..38086dd06c 100644 --- a/types/braft-editor/index.d.ts +++ b/types/braft-editor/index.d.ts @@ -5,20 +5,14 @@ // TypeScript Version: 2.3 import * as React from "react"; -import { - RawDraftContentState, -} from 'draft-js'; +import {RawDraftContentState} from 'draft-js'; export as namespace BraftEditor; - export = BraftEditor; - -declare namespace BraftEditor { - - interface fontFamiliesRange { +declare namespace BraftEditor{ + interface fontFamiliesRange{ name: string; family: string; } - interface editorProps { editorState?: any; contentFormat?: RawDraftContentState; @@ -34,9 +28,8 @@ declare namespace BraftEditor { viewWrapper?: string; colors?: string[]; fontSizes?: number[]; - fontFamilies?: Array; + fontFamilies?: fontFamiliesRange[]; media?: { [key: string]: any }; - setState?: Function; getContent?: (format?: string) => RawDraftContentState; setContent?: (content: RawDraftContentState, format?: string) => void; toggleSelectionBlockType?: (blockquote: string) => any; @@ -63,6 +56,4 @@ declare namespace BraftEditor { blur?: () => void; } } - - declare class BraftEditor extends React.Component { } From b6a0eabf2b5b448540a4c60d8a8cad6a2037aaf0 Mon Sep 17 00:00:00 2001 From: petitspois Date: Wed, 6 Dec 2017 17:28:33 +0800 Subject: [PATCH 3/3] add braft-editor definition --- types/braft-editor/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/braft-editor/index.d.ts b/types/braft-editor/index.d.ts index 38086dd06c..225d32722d 100644 --- a/types/braft-editor/index.d.ts +++ b/types/braft-editor/index.d.ts @@ -5,11 +5,11 @@ // TypeScript Version: 2.3 import * as React from "react"; -import {RawDraftContentState} from 'draft-js'; +import { RawDraftContentState } from 'draft-js'; export as namespace BraftEditor; export = BraftEditor; -declare namespace BraftEditor{ - interface fontFamiliesRange{ +declare namespace BraftEditor { + interface fontFamiliesRange { name: string; family: string; } @@ -34,7 +34,7 @@ declare namespace BraftEditor{ setContent?: (content: RawDraftContentState, format?: string) => void; toggleSelectionBlockType?: (blockquote: string) => any; toggleSelectionInlineStyle?: (style: string, stylesToBeRemoved?: string[]) => any; - insertMedias?: (medias: { type: string, name: string, url: string }[]) => void; + 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;