1 | import UppyUtils = require('@uppy/utils')
|
2 |
|
3 | declare module Uppy {
|
4 |
|
5 | type OmitKey<T, Key> = Pick<T, Exclude<keyof T, Key>>
|
6 |
|
7 |
|
8 | export type UppyFile<
|
9 | TMeta extends IndexedObject<any> = {},
|
10 | TBody extends IndexedObject<any> = {}
|
11 | > = UppyUtils.UppyFile<TMeta, TBody>
|
12 | export type Store = UppyUtils.Store
|
13 | export type InternalMetadata = UppyUtils.InternalMetadata
|
14 |
|
15 | interface IndexedObject<T> {
|
16 | [key: string]: T
|
17 | [key: number]: T
|
18 | }
|
19 |
|
20 | interface UploadedUppyFile<TMeta, TBody> extends UppyFile<TMeta, TBody> {
|
21 | uploadURL: string
|
22 | }
|
23 |
|
24 | interface FailedUppyFile<TMeta, TBody> extends UppyFile<TMeta, TBody> {
|
25 | error: string
|
26 | }
|
27 |
|
28 |
|
29 | type UppyFileWithoutMeta<TMeta, TBody> = OmitKey<
|
30 | UppyFile<TMeta, TBody>,
|
31 | 'meta'
|
32 | >
|
33 | interface AddFileOptions<
|
34 | TMeta = IndexedObject<any>,
|
35 | TBody = IndexedObject<any>
|
36 | > extends Partial<UppyFileWithoutMeta<TMeta, TBody>> {
|
37 |
|
38 | data: Blob | File
|
39 | meta?: Partial<InternalMetadata> & TMeta
|
40 | }
|
41 |
|
42 | interface PluginOptions {
|
43 | id?: string
|
44 | }
|
45 | interface DefaultPluginOptions extends PluginOptions {
|
46 | [prop: string]: any
|
47 | }
|
48 |
|
49 | type PluginTarget = string | Element | typeof Plugin
|
50 |
|
51 | class Plugin<TOptions extends PluginOptions = DefaultPluginOptions> {
|
52 | id: string
|
53 | uppy: Uppy
|
54 | type: string
|
55 | constructor(uppy: Uppy, opts?: TOptions)
|
56 | setOptions(update: Partial<TOptions>): void
|
57 | getPluginState(): object
|
58 | setPluginState(update: IndexedObject<any>): object
|
59 | update(state?: object): void
|
60 | mount(target: PluginTarget, plugin: typeof Plugin): void
|
61 | render(state: object): void
|
62 | addTarget<TPlugin extends Plugin>(plugin: TPlugin): void
|
63 | unmount(): void
|
64 | install(): void
|
65 | uninstall(): void
|
66 | }
|
67 |
|
68 | type LocaleStrings<TNames extends string> = {
|
69 | [K in TNames]?: string | { [n: number]: string }
|
70 | }
|
71 | interface Locale<TNames extends string = string> {
|
72 | strings: LocaleStrings<TNames>
|
73 | pluralize?: (n: number) => number
|
74 | }
|
75 |
|
76 | interface Restrictions {
|
77 | maxFileSize?: number | null
|
78 | minFileSize?: number | null
|
79 | maxNumberOfFiles?: number | null
|
80 | minNumberOfFiles?: number | null
|
81 | allowedFileTypes?: string[] | null
|
82 | }
|
83 |
|
84 | interface UppyOptions<TMeta extends IndexedObject<any> = {}> {
|
85 | id?: string
|
86 | autoProceed?: boolean
|
87 | allowMultipleUploads?: boolean
|
88 | debug?: boolean
|
89 | restrictions?: Restrictions
|
90 | meta?: TMeta
|
91 | onBeforeFileAdded?: (
|
92 | currentFile: UppyFile<TMeta>,
|
93 | files: { [key: string]: UppyFile<TMeta> }
|
94 | ) => UppyFile<TMeta> | boolean | undefined
|
95 | onBeforeUpload?: (files: {
|
96 | [key: string]: UppyFile<TMeta>
|
97 | }) => { [key: string]: UppyFile<TMeta> } | boolean
|
98 | locale?: Locale
|
99 | store?: Store
|
100 | }
|
101 |
|
102 | interface UploadResult<
|
103 | TMeta extends IndexedObject<any> = {},
|
104 | TBody extends IndexedObject<any> = {}
|
105 | > {
|
106 | successful: UploadedUppyFile<TMeta, TBody>[]
|
107 | failed: FailedUppyFile<TMeta, TBody>[]
|
108 | }
|
109 |
|
110 | interface State<
|
111 | TMeta extends IndexedObject<any> = {},
|
112 | TBody extends IndexedObject<any> = {}
|
113 | > extends IndexedObject<any> {
|
114 | capabilities?: { resumableUploads?: boolean }
|
115 | currentUploads: {}
|
116 | error?: string
|
117 | files: {
|
118 | [key: string]:
|
119 | | UploadedUppyFile<TMeta, TBody>
|
120 | | FailedUppyFile<TMeta, TBody>
|
121 | }
|
122 | info?: {
|
123 | isHidden: boolean
|
124 | type: string
|
125 | message: string
|
126 | details: string
|
127 | }
|
128 | plugins?: IndexedObject<any>
|
129 | totalProgress: number
|
130 | }
|
131 |
|
132 | type LogLevel = 'info' | 'warning' | 'error'
|
133 |
|
134 |
|
135 | type LooseTypes = 'loose'
|
136 |
|
137 | type StrictTypes = 'strict'
|
138 | type TypeChecking = LooseTypes | StrictTypes
|
139 |
|
140 |
|
141 |
|
142 | type LiteralUnion<T extends U, U = string> = T | (U & { });
|
143 | type Event = LiteralUnion<'file-added' | 'file-removed' | 'upload' | 'upload-progress' | 'upload-success' | 'complete' | 'error' | 'upload-error' |
|
144 | 'upload-retry' | 'info-visible' | 'info-hidden' | 'cancel-all' | 'restriction-failed' | 'reset-progress'>;
|
145 |
|
146 | type UploadHandler = (fileIDs: string[]) => Promise<void>
|
147 |
|
148 | class Uppy<TUseStrictTypes extends TypeChecking = TypeChecking> {
|
149 | constructor(opts?: UppyOptions)
|
150 | on<TMeta extends IndexedObject<any> = {}>(
|
151 | event: 'upload-success',
|
152 | callback: (file: UppyFile<TMeta>, body: any, uploadURL: string) => void
|
153 | ): this
|
154 | on<TMeta extends IndexedObject<any> = {}>(
|
155 | event: 'complete',
|
156 | callback: (result: UploadResult<TMeta>) => void
|
157 | ): this
|
158 | on(event: Event, callback: (...args: any[]) => void): this
|
159 | off(event: Event, callback: (...args: any[]) => void): this
|
160 | |
161 |
|
162 |
|
163 | emit(event: Event, ...args: any[]): void
|
164 | updateAll(state: object): void
|
165 | setOptions(update: Partial<UppyOptions>): void
|
166 | setState(patch: object): void
|
167 | getState<TMeta extends IndexedObject<any> = {}>(): State<TMeta>
|
168 | readonly state: State
|
169 | setFileState(fileID: string, state: object): void
|
170 | resetProgress(): void
|
171 | addPreProcessor(fn: UploadHandler): void
|
172 | removePreProcessor(fn: UploadHandler): void
|
173 | addPostProcessor(fn: UploadHandler): void
|
174 | removePostProcessor(fn: UploadHandler): void
|
175 | addUploader(fn: UploadHandler): void
|
176 | removeUploader(fn: UploadHandler): void
|
177 | setMeta<TMeta extends IndexedObject<any> = {}>(data: TMeta): void
|
178 | setFileMeta<TMeta extends IndexedObject<any> = {}>(
|
179 | fileID: string,
|
180 | data: TMeta
|
181 | ): void
|
182 | getFile<
|
183 | TMeta extends IndexedObject<any> = {},
|
184 | TBody extends IndexedObject<any> = {}
|
185 | >(fileID: string): UppyFile<TMeta, TBody>
|
186 | getFiles<
|
187 | TMeta extends IndexedObject<any> = {},
|
188 | TBody extends IndexedObject<any> = {}
|
189 | >(): Array<UppyFile<TMeta, TBody>>
|
190 | addFile<TMeta extends IndexedObject<any> = {}>(
|
191 | file: AddFileOptions<TMeta>
|
192 | ): void
|
193 | removeFile(fileID: string): void
|
194 | pauseResume(fileID: string): boolean
|
195 | pauseAll(): void
|
196 | resumeAll(): void
|
197 | retryAll<TMeta extends IndexedObject<any> = {}>(): Promise<UploadResult<TMeta>>
|
198 | cancelAll(): void
|
199 | retryUpload<TMeta extends IndexedObject<any> = {}>(fileID: string): Promise<UploadResult<TMeta>>
|
200 | reset(): void
|
201 | getID(): string
|
202 | |
203 |
|
204 |
|
205 | use<TOptions, TInstance extends Plugin<TOptions>>(
|
206 | pluginClass: new (uppy: this, opts: TOptions) => TInstance,
|
207 | opts?: TOptions
|
208 | ): this
|
209 | |
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | use(pluginClass: TUseStrictTypes extends StrictTypes ? never : new (uppy: this, opts: any) => Plugin<any>, opts?: object): this
|
217 | getPlugin(name: string): Plugin
|
218 | iteratePlugins(callback: (plugin: Plugin) => void): void
|
219 | removePlugin(instance: Plugin): void
|
220 | close(): void
|
221 | info(
|
222 | message: string | { message: string; details: string },
|
223 | type?: LogLevel,
|
224 | duration?: number
|
225 | ): void
|
226 | hideInfo(): void
|
227 | log(msg: string, type?: LogLevel): void
|
228 | |
229 |
|
230 |
|
231 | run(): this
|
232 | restore<TMeta extends IndexedObject<any> = {}>(
|
233 | uploadID: string
|
234 | ): Promise<UploadResult<TMeta>>
|
235 | addResultData(uploadID: string, data: object): void
|
236 | upload<TMeta extends IndexedObject<any> = {}>(): Promise<UploadResult<TMeta>>
|
237 | }
|
238 | }
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | declare function Uppy<TUseStrictTypes extends Uppy.TypeChecking = Uppy.TypeChecking>(opts?: Uppy.UppyOptions): Uppy.Uppy<TUseStrictTypes>
|
254 |
|
255 | export = Uppy
|
256 |
|
\ | No newline at end of file |