From e32ea94e933c8d7d426ef4ad9734fe4a2e8bdbdf Mon Sep 17 00:00:00 2001 From: quas94 Date: Fri, 28 Sep 2018 17:53:41 +1000 Subject: [PATCH 1/3] Add definitions for Dropbox Chooser --- .../dropbox-chooser/dropbox-chooser-tests.ts | 20 ++++++ types/dropbox-chooser/index.d.ts | 66 +++++++++++++++++++ types/dropbox-chooser/tsconfig.json | 24 +++++++ types/dropbox-chooser/tslint.json | 1 + 4 files changed, 111 insertions(+) create mode 100644 types/dropbox-chooser/dropbox-chooser-tests.ts create mode 100644 types/dropbox-chooser/index.d.ts create mode 100644 types/dropbox-chooser/tsconfig.json create mode 100644 types/dropbox-chooser/tslint.json diff --git a/types/dropbox-chooser/dropbox-chooser-tests.ts b/types/dropbox-chooser/dropbox-chooser-tests.ts new file mode 100644 index 0000000000..f0930733f8 --- /dev/null +++ b/types/dropbox-chooser/dropbox-chooser-tests.ts @@ -0,0 +1,20 @@ +// Tests for Dropbox Chooser DefinitelyTyped TS definitions + +const options: DropboxChooserOptions = { + success: (files: ReadonlyArray) => { + console.log('Success, selected files were:', files); + }, +}; + +const Dropbox = window.Dropbox!; +Dropbox.choose(options); + +const sampleFile: DropboxChooserFile = { + id: 'SAMPLE_ID', + name: 'HelloBox.jpg', + link: 'http://localhost/1.png', + bytes: 1024, + icon: 'http://localhost/icons/png.png', + thumbnailLink: 'http://localhost/thumbnails/1.png', + isDir: false, +}; diff --git a/types/dropbox-chooser/index.d.ts b/types/dropbox-chooser/index.d.ts new file mode 100644 index 0000000000..8c9db6f72d --- /dev/null +++ b/types/dropbox-chooser/index.d.ts @@ -0,0 +1,66 @@ +// Type definitions for Dropbox Chooser 1.0 +// Project: https://www.dropbox.com/developers/chooser +// Definitions by: Michael Su +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace Dropbox { + interface DropboxChooser { + choose(options: ChooserOptions): void; + } + + interface ChooserOptions { + // alled when a user selects an item in the Chooser + success(files: ReadonlyArray): void; + + // called when the user closes the dialog without selecting a file + cancel?(): void; + + // default: 'preview' + linkType?: 'preview' | 'direct'; + + // default: false + multiselect?: boolean; + + // eg. '.png' + extensions?: string[]; + + // default: false + folderselect?: boolean; + + // any positive number + sizeLimit?: number; + } + + interface File { + // Unique ID for the file, compatible with Dropbox API v2. + id: string; + + // Name of the file. + name: string; + + // URL to access the file, which varies depending on the linkType specified when the + // Chooser was triggered. + link: string; + + // Size of the file in bytes. + bytes: number; + + // URL to a 64x64px icon for the file based on the file's extension. + icon: string; + + // A thumbnail URL generated when the user selects images and videos. + // If the user didn't select an image or video, no thumbnail will be included. + thumbnailLink?: string; + + // whether or not the file is actually a directory + isDir: boolean; + } +} + +type DropboxChooser = Dropbox.DropboxChooser; +type DropboxChooserOptions = Dropbox.ChooserOptions; +type DropboxChooserFile = Dropbox.File; + +interface Window { + Dropbox?: DropboxChooser; +} diff --git a/types/dropbox-chooser/tsconfig.json b/types/dropbox-chooser/tsconfig.json new file mode 100644 index 0000000000..88fb15cc91 --- /dev/null +++ b/types/dropbox-chooser/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "dom", + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "dropbox-chooser-tests.ts" + ] +} diff --git a/types/dropbox-chooser/tslint.json b/types/dropbox-chooser/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/dropbox-chooser/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 82d92693da98494f58dcbaf62b514fa14051fad5 Mon Sep 17 00:00:00 2001 From: quas94 Date: Tue, 27 Nov 2018 16:27:11 +1100 Subject: [PATCH 2/3] Update typedefs --- .../dropbox-chooser/dropbox-chooser-tests.ts | 6 +++--- types/dropbox-chooser/index.d.ts | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/types/dropbox-chooser/dropbox-chooser-tests.ts b/types/dropbox-chooser/dropbox-chooser-tests.ts index f0930733f8..e998bad7bf 100644 --- a/types/dropbox-chooser/dropbox-chooser-tests.ts +++ b/types/dropbox-chooser/dropbox-chooser-tests.ts @@ -1,7 +1,7 @@ // Tests for Dropbox Chooser DefinitelyTyped TS definitions -const options: DropboxChooserOptions = { - success: (files: ReadonlyArray) => { +const options: Dropbox.ChooserOptions = { + success: (files: ReadonlyArray) => { console.log('Success, selected files were:', files); }, }; @@ -9,7 +9,7 @@ const options: DropboxChooserOptions = { const Dropbox = window.Dropbox!; Dropbox.choose(options); -const sampleFile: DropboxChooserFile = { +const sampleFile: Dropbox.ChooserFile = { id: 'SAMPLE_ID', name: 'HelloBox.jpg', link: 'http://localhost/1.png', diff --git a/types/dropbox-chooser/index.d.ts b/types/dropbox-chooser/index.d.ts index 8c9db6f72d..c9a9db4d70 100644 --- a/types/dropbox-chooser/index.d.ts +++ b/types/dropbox-chooser/index.d.ts @@ -4,13 +4,14 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace Dropbox { - interface DropboxChooser { + + interface Chooser { choose(options: ChooserOptions): void; } interface ChooserOptions { - // alled when a user selects an item in the Chooser - success(files: ReadonlyArray): void; + // called when a user selects an item in the Chooser + success(files: ReadonlyArray): void; // called when the user closes the dialog without selecting a file cancel?(): void; @@ -31,7 +32,7 @@ declare namespace Dropbox { sizeLimit?: number; } - interface File { + interface ChooserFile { // Unique ID for the file, compatible with Dropbox API v2. id: string; @@ -55,12 +56,12 @@ declare namespace Dropbox { // whether or not the file is actually a directory isDir: boolean; } -} -type DropboxChooser = Dropbox.DropboxChooser; -type DropboxChooserOptions = Dropbox.ChooserOptions; -type DropboxChooserFile = Dropbox.File; + // Refer to "Handling the response" section of: https://www.dropbox.com/developers/chooser + type ChooserFileBoundingBox = 75 | 256 | 800 | 1280 | 2048; + type ChooserFileMode = 'fit' | 'crop' | 'fit_one_and_overflow'; +} interface Window { - Dropbox?: DropboxChooser; + Dropbox?: Dropbox.Chooser; } From e0b6335bbc3545f111bf199e52f4364569b806f1 Mon Sep 17 00:00:00 2001 From: quas94 Date: Tue, 27 Nov 2018 16:55:24 +1100 Subject: [PATCH 3/3] Remove newline --- types/dropbox-chooser/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/dropbox-chooser/index.d.ts b/types/dropbox-chooser/index.d.ts index c9a9db4d70..c5fd8a6cd6 100644 --- a/types/dropbox-chooser/index.d.ts +++ b/types/dropbox-chooser/index.d.ts @@ -4,7 +4,6 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace Dropbox { - interface Chooser { choose(options: ChooserOptions): void; }