index.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. // Type definitions for uppy 0.24
  2. // Project: https://uppy.io
  3. // Definitions by: My Self <https://github.com/me>
  4. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  5. // TypeScript Version: 2.3
  6. // export as namespace Uppy;
  7. declare module 'uppy' {
  8. export const Core: Core;
  9. export const Dashboard: plugins.Dashboard;
  10. export const DragDrop: plugins.DragDrop;
  11. export const XHRUpload: plugins.XHRUpload;
  12. export const GoogleDrive: plugins.GoogleDrive;
  13. export const Instagram: plugins.Instagram;
  14. export const Webcam: plugins.Webcam;
  15. export const Tus: plugins.Tus;
  16. export const StatusBar: plugins.StatusBar;
  17. export const Url: plugins.Url;
  18. export const Dropbox: plugins.Dropbox;
  19. export const AwsS3: plugins.AwsS3;
  20. export const GoldenRetriever: plugins.GoldenRetriever;
  21. export const ThumbnailGenerator: plugins.ThumbnailGenerator;
  22. export const Transloadit: plugins.Transloadit;
  23. export const Dummy: plugins.Dummy;
  24. export const FileInput: plugins.FileInput;
  25. export const Form: plugins.Form;
  26. export const Informer: plugins.Informer;
  27. export const MagicLog: plugins.MagicLog;
  28. export const ProgressBar: plugins.ProgressBar;
  29. export const ReduxDevTools: plugins.ReduxDevTools;
  30. }
  31. declare module 'uppy/lib/core' {
  32. export = Core;
  33. }
  34. declare module 'uppy/lib/plugins/Dashboard' {
  35. const Dashboard: plugins.Dashboard;
  36. export = Dashboard;
  37. }
  38. declare module 'uppy/lib/plugins/DragDrop' {
  39. const DragDrop: plugins.DragDrop;
  40. export = DragDrop;
  41. }
  42. declare module 'uppy/lib/plugins/XHRUpload' {
  43. const XHRUpload: plugins.XHRUpload;
  44. export = XHRUpload;
  45. }
  46. declare module 'uppy/lib/plugins/GoogleDrive' {
  47. const GoogleDrive: plugins.GoogleDrive;
  48. export = GoogleDrive;
  49. }
  50. declare module 'uppy/lib/plugins/Instagram' {
  51. const Instagram: plugins.Instagram;
  52. export = Instagram;
  53. }
  54. declare module 'uppy/lib/plugins/Webcam' {
  55. const Webcam: plugins.Webcam;
  56. export = Webcam;
  57. }
  58. declare module 'uppy/lib/plugins/Tus' {
  59. const Tus: plugins.Tus;
  60. export = Tus;
  61. }
  62. declare module 'uppy/lib/plugins/StatusBar' {
  63. const StatusBar: plugins.StatusBar;
  64. export = StatusBar;
  65. }
  66. declare module 'uppy/lib/plugins/Url' {
  67. const Url: plugins.Url;
  68. export = Url;
  69. }
  70. declare module 'uppy/lib/plugins/Dropbox' {
  71. const Dropbox: plugins.Dropbox;
  72. export = Dropbox;
  73. }
  74. declare module 'uppy/lib/plugins/AwsS3' {
  75. const AwsS3: plugins.AwsS3;
  76. export = AwsS3;
  77. }
  78. declare module 'uppy/lib/plugins/GoldenRetriever' {
  79. const GoldenRetriever: plugins.GoldenRetriever;
  80. export = GoldenRetriever;
  81. }
  82. declare module 'uppy/lib/plugins/ThumbnailGenerator' {
  83. const ThumbnailGenerator: plugins.ThumbnailGenerator;
  84. export = ThumbnailGenerator;
  85. }
  86. declare module 'uppy/lib/plugins/Transloadit' {
  87. const Transloadit: plugins.Transloadit;
  88. export = Transloadit;
  89. }
  90. declare module 'uppy/lib/plugins/Dummy' {
  91. const Dummy: plugins.Dummy;
  92. export = Dummy;
  93. }
  94. declare module 'uppy/lib/plugins/FileInput' {
  95. const FileInput: plugins.FileInput;
  96. export = FileInput;
  97. }
  98. declare module 'uppy/lib/plugins/Form' {
  99. const Form: plugins.Form;
  100. export = Form;
  101. }
  102. declare module 'uppy/lib/plugins/Informer' {
  103. const Informer: plugins.Informer;
  104. export = Informer;
  105. }
  106. declare module 'uppy/lib/plugins/MagicLog' {
  107. const MagicLog: plugins.MagicLog;
  108. export = MagicLog;
  109. }
  110. declare module 'uppy/lib/plugins/ProgressBar' {
  111. const ProgressBar: plugins.ProgressBar;
  112. export = ProgressBar;
  113. }
  114. declare module 'uppy/lib/plugins/ReduxDevTools' {
  115. const ReduxDevTools: plugins.ReduxDevTools;
  116. export = ReduxDevTools;
  117. }
  118. declare namespace Store {
  119. // todo
  120. type State = any;
  121. type EventRemover = () => void;
  122. interface Store {
  123. getState(): State;
  124. setState(patch: State): void;
  125. subscribe(listener: any): EventRemover;
  126. }
  127. // todo
  128. type DefaultStore = Store;
  129. // todo
  130. type ReduxStore = Store;
  131. }
  132. declare interface Local {
  133. strings: {
  134. youCanOnlyUploadX: {
  135. 0: string;
  136. 1: string;
  137. },
  138. youHaveToAtLeastSelectX: {
  139. 0: string;
  140. 1: string;
  141. },
  142. exceedsSize: string;
  143. youCanOnlyUploadFileTypes: string;
  144. uppyServerError: string;
  145. failedToUpload: string;
  146. noInternetConnection: string;
  147. connectedToInternet: string;
  148. };
  149. }
  150. declare namespace plugins {
  151. interface DashboardOptions extends core.CoreConfig {
  152. onRequestCloseModal: () => any;
  153. disablePageScrollWhenModalOpen: boolean;
  154. closeModalOnClickOutside: boolean;
  155. trigger: string | HTMLElement;
  156. inline: boolean;
  157. defaultTabIcon: string;
  158. hideUploadButton: boolean;
  159. width: string;
  160. height: string;
  161. note: string;
  162. showLinkToFileUploadResult: boolean;
  163. proudlyDisplayPoweredByUppy: boolean;
  164. metaFields: string[];
  165. plugins: core.Plugin[];
  166. disableStatusBar: boolean;
  167. showProgressDetails: boolean;
  168. hideProgressAfterFinish: boolean;
  169. disableInformer: boolean;
  170. disableThumbnailGenerator: boolean;
  171. }
  172. class Dashboard extends core.Plugin {
  173. constructor(uppy: core.Uppy, opts: Partial<DashboardOptions>);
  174. addTarget(plugin: core.Plugin): HTMLElement;
  175. hideAllPanels(): void;
  176. showPanel(id: string): void;
  177. requestCloseModal(): void;
  178. getFocusableNodes(): HTMLElement[];
  179. setFocusToFirstNode(): void;
  180. setFocusToBrowse(): void;
  181. maintainFocus(): void;
  182. openModal(): void;
  183. closeModal(): void;
  184. isModalOpen(): boolean;
  185. onKeydown(event: KeyboardEvent): void;
  186. handleClickOutside(): void;
  187. handlePaste(ev: ClipboardEvent): void;
  188. handleInputChange(ev: Event): void;
  189. initEvents(): void;
  190. removeEvents(): void;
  191. updateDashboardElWidth(): void;
  192. toggleFileCard(fileId: string): void;
  193. handleDrop(files: File[] | FileList): void;
  194. render(state: Store.State): void;
  195. discoverProviderPlugins(): void;
  196. install(): void;
  197. uninstall(): void;
  198. }
  199. interface DragDropOptions extends core.CoreConfig {
  200. inputName: string;
  201. allowMultipleFiles: boolean;
  202. width: string;
  203. height: string;
  204. note: string;
  205. }
  206. class DragDrop extends core.Plugin {
  207. constructor(uppy: core.Uppy, opts: Partial<DragDropOptions>);
  208. checkDragDropSupport(): void;
  209. handleDrop(files: File[] | FileList): void;
  210. handleInputChange(ev: Event): void;
  211. }
  212. interface FileOptions {
  213. headers: any;
  214. [key: string]: any;
  215. }
  216. interface ProcessTimeout {
  217. done(): void;
  218. process(): void;
  219. }
  220. interface FormDataUploadOptions {
  221. metaFields: string[];
  222. fieldName: string;
  223. }
  224. interface XHRUploadOptions extends core.CoreConfig {
  225. limit: string;
  226. bundle: boolean;
  227. formData: FormData;
  228. headers: any;
  229. metaFields: string[];
  230. fieldName: string;
  231. timeout: number;
  232. responseUrlFieldName: string;
  233. endpoint: string;
  234. method: 'GET' | 'POST' | 'HEAD';
  235. }
  236. class XHRUpload extends core.Plugin {
  237. constructor(uppy: core.Uppy, opts: Partial<XHRUploadOptions>);
  238. getOptions(file: File): FileOptions;
  239. createProgressTimeout(timeout: number, timeoutHandler: any): ProcessTimeout;
  240. createFormDataUpload(file: File, opts: Partial<FormDataUploadOptions>): FormData;
  241. createBareUpload(file: File): any;
  242. upload(file: File, current: number, total: number): Promise<File>;
  243. uploadRemote(file: File, current: number, total: number): Promise<File>;
  244. uploadBundle(files: File[] | FileList): Promise<void>;
  245. uploadBundle(files: File[] | FileList): Promise<{
  246. successful: File[];
  247. failed: any;
  248. }>;
  249. handleUpload(fileIDs: string[]): Promise<null>;
  250. }
  251. interface GoogleDriveOptions extends core.CoreConfig {
  252. expires: number;
  253. serviceWorker: boolean;
  254. indexedDB: any;
  255. serverUrl: string;
  256. }
  257. class GoogleDrive extends core.Plugin {
  258. constructor(uppy: core.Uppy, opts: Partial<GoogleDriveOptions>);
  259. loadFilesStateFromLocalStorage(): void;
  260. getWaitingFiles(): { [fileID: string]: File };
  261. getUploadingFiles(): { [fileID: string]: File };
  262. saveFilesStateToLocalStorage(): void;
  263. loadFileBlobsFromServiceWorker(): void;
  264. loadFileBlobsFromIndexedDB(): void;
  265. deleteBlobs(): Promise<any>;
  266. }
  267. interface InstagramOptions extends core.CoreConfig {
  268. serverUrl: string;
  269. }
  270. class Instagram extends core.Plugin {
  271. constructor(uppy: core.Uppy, opts: Partial<InstagramOptions>);
  272. }
  273. interface WebcamOptions extends core.CoreConfig {
  274. countdown: boolean;
  275. }
  276. interface WebcamMedia {
  277. source: string;
  278. name: string;
  279. data: File;
  280. type: string;
  281. }
  282. class Webcam extends core.Plugin {
  283. constructor(uppy: core.Uppy, opts: Partial<WebcamOptions>);
  284. isSupported(): boolean;
  285. getConstraints(): { audio: boolean; video: boolean; };
  286. start(): Promise<void>;
  287. startRecording(): void;
  288. stopRecording(): Promise<void>;
  289. stop(): void;
  290. getVideoElement(): HTMLVideoElement;
  291. oneTwoThreeSmile(): Promise<void>;
  292. takeSnapshot(): void;
  293. getImage(): Promise<WebcamMedia>;
  294. getVideo(): Promise<WebcamMedia>;
  295. focus(): void;
  296. }
  297. interface TusOptions extends core.CoreConfig {
  298. limit: number;
  299. endpoint: string;
  300. uploadUrl: string;
  301. useFastRemoteRetry: boolean;
  302. resume: boolean;
  303. autoRetry: boolean;
  304. }
  305. class Tus extends core.Plugin {
  306. constructor(uppy: core.Uppy, opts: Partial<TusOptions>);
  307. }
  308. interface StatusBarOptions extends core.CoreConfig {
  309. showProgressDetails: boolean;
  310. hideUploadButton: boolean;
  311. hideAfterFinish: boolean;
  312. }
  313. class StatusBar extends core.Plugin {
  314. constructor(uppy: core.Uppy, opts: Partial<StatusBarOptions>);
  315. }
  316. interface UrlOptions extends core.CoreConfig {
  317. serverUrl: string;
  318. }
  319. class Url extends core.Plugin {
  320. constructor(uppy: core.Uppy, opts: Partial<UrlOptions>);
  321. }
  322. interface DropboxOptions extends core.CoreConfig {
  323. serverUrl: string;
  324. }
  325. class Dropbox extends core.Plugin {
  326. constructor(uppy: core.Uppy, opts: Partial<DropboxOptions>);
  327. }
  328. interface AwsS3Options extends core.CoreConfig {
  329. limit: number;
  330. serverUrl: string;
  331. timeout: number;
  332. }
  333. class AwsS3 extends core.Plugin {
  334. constructor(uppy: core.Uppy, opts: Partial<AwsS3Options>);
  335. }
  336. interface GoldenRetrieverOptions extends core.CoreConfig {
  337. expires: number;
  338. serviceWorker: boolean;
  339. indexedDB: any;
  340. }
  341. class GoldenRetriever extends core.Plugin {
  342. constructor(uppy: core.Uppy, opts: Partial<GoldenRetrieverOptions>);
  343. }
  344. interface ThumbnailGeneratorOptions extends core.CoreConfig {
  345. thumbnailWidth: number;
  346. }
  347. class ThumbnailGenerator extends core.Plugin {
  348. constructor(uppy: core.Uppy, opts: Partial<ThumbnailGeneratorOptions>);
  349. }
  350. interface TransloaditOptions extends core.CoreConfig {
  351. params: any;
  352. service: string;
  353. waitForEncoding: boolean;
  354. waitForMetadata: boolean;
  355. importFromUploadURLs: boolean;
  356. alwaysRunAssembly: boolean;
  357. }
  358. class Transloadit extends core.Plugin {
  359. constructor(uppy: core.Uppy, opts: Partial<TransloaditOptions>);
  360. }
  361. interface DummyOptions extends core.CoreConfig {
  362. }
  363. class Dummy extends core.Plugin {
  364. constructor(uppy: core.Uppy, opts: Partial<DummyOptions>);
  365. }
  366. interface FileInputOptions extends core.CoreConfig {
  367. pretty: boolean;
  368. inputName: string;
  369. }
  370. class FileInput extends core.Plugin {
  371. constructor(uppy: core.Uppy, opts: Partial<FileInputOptions>);
  372. }
  373. interface FormOptions extends core.CoreConfig {
  374. getMetaFromForm: boolean;
  375. addResultToForm: boolean;
  376. submitOnSuccess: boolean;
  377. triggerUploadOnSubmit: boolean;
  378. resultName: string;
  379. }
  380. class Form extends core.Plugin {
  381. constructor(uppy: core.Uppy, opts: Partial<FormOptions>);
  382. }
  383. interface TypeColor {
  384. [type: string]: {
  385. bg: string | number;
  386. text: string | number;
  387. };
  388. }
  389. interface InformerOptions extends core.CoreConfig {
  390. typeColors: TypeColor;
  391. }
  392. class Informer extends core.Plugin {
  393. constructor(uppy: core.Uppy, opts: Partial<InformerOptions>);
  394. }
  395. interface MagicLogOptions extends core.CoreConfig {
  396. }
  397. class MagicLog extends core.Plugin {
  398. constructor(uppy: core.Uppy, opts: Partial<MagicLogOptions>);
  399. }
  400. interface ProgressBarOptions extends core.CoreConfig {
  401. hideAfterFinish: boolean;
  402. fixed: boolean;
  403. }
  404. class ProgressBar extends core.Plugin {
  405. constructor(uppy: core.Uppy, opts: Partial<ProgressBarOptions>);
  406. }
  407. interface ReduxDevToolsOptions extends core.CoreConfig {
  408. }
  409. class ReduxDevTools extends core.Plugin {
  410. constructor(uppy: core.Uppy, opts: Partial<ReduxDevToolsOptions>);
  411. }
  412. }
  413. declare namespace core {
  414. interface CoreConfig {
  415. id: string;
  416. autoProceed: boolean;
  417. debug: boolean;
  418. restrictions: {
  419. maxFileSize: false,
  420. maxNumberOfFiles: false,
  421. minNumberOfFiles: false,
  422. allowedFileTypes: false
  423. };
  424. target: string | Plugin;
  425. meta: any;
  426. // onBeforeFileAdded: (currentFile, files) => currentFile,
  427. // onBeforeUpload: (files) => files,
  428. locale: Local;
  429. store: Store.Store;
  430. }
  431. class Plugin {
  432. constructor(uppy: Uppy, opts?: {
  433. replaceTargetContent?: boolean;
  434. });
  435. getPluginState(): Store.State;
  436. setPluginState(update: any): Store.State;
  437. update(state?: Store.State): void;
  438. mount(target: any, plugin: any): void;
  439. render(state: Store.State): void;
  440. addTarget(plugin: any): void;
  441. unmount(): void;
  442. install(): void;
  443. uninstall(): void;
  444. }
  445. type LogType = 'info' | 'warning' | 'error';
  446. interface SuccessedFile {
  447. data: File;
  448. extension: string;
  449. id: string;
  450. isPaused: boolean;
  451. isRemote: boolean;
  452. meta: {
  453. name: string;
  454. type: string;
  455. };
  456. name: string;
  457. preview: string;
  458. progress: {
  459. uploadStarted: number;
  460. uploadComplete: boolean;
  461. percentage: number;
  462. bytesUploaded: number;
  463. bytesTotal: number;
  464. };
  465. remote: string;
  466. size: number;
  467. source: string;
  468. type: string;
  469. uploadURL: string;
  470. }
  471. interface Result {
  472. failed: any[];
  473. successful: SuccessedFile[];
  474. }
  475. class Uppy {
  476. constructor(conf: Partial<CoreConfig>);
  477. on(event: string, callback: (...args: any[]) => any): Uppy;
  478. on(event: 'upload-success', callback: (fileCount: File, body: any, uploadurl: string) => any): Uppy;
  479. on(event: 'complete', callback: (result: Result) => void): Uppy;
  480. off(event: string, callback: any): Uppy;
  481. updateAll(state: Store.State): void;
  482. setState(patch: Store.State): void;
  483. getState(): Store.State;
  484. readonly state: Store.State;
  485. setFileState(fileID: string, state: Store.State): void;
  486. resetProgress(): void;
  487. addPreProcessor(fn: any): void;
  488. removePreProcessor(fn: any): void;
  489. addPostProcessor(fn: any): void;
  490. removePostProcessor(fn: any): void;
  491. addUploader(fn: any): void;
  492. removeUploader(fn: any): void;
  493. setMeta(data: any): void;
  494. setFileMeta(fileID: string, data: any): void;
  495. getFile(fileID: string): File;
  496. getFiles(): File[];
  497. addFile(file: File): void;
  498. removeFile(fileID: string): void;
  499. pauseResume(fileID: string): boolean;
  500. pauseAll(): void;
  501. resumeAll(): void;
  502. retryAll(): void;
  503. cancelAll(): void;
  504. retryUpload(fileID: string): any;
  505. reset(): void;
  506. actions(): void;
  507. updateOnlineStatus(): void;
  508. getID(): string;
  509. // use<T extends Plugin>(Plugin: T, opts: any): Uppy;
  510. use(Plugin: plugins.Dashboard, opts: Partial<plugins.DashboardOptions>): Uppy;
  511. use(Plugin: plugins.DragDrop, opts: Partial<plugins.DragDropOptions>): Uppy;
  512. use(Plugin: plugins.XHRUpload, opts: Partial<plugins.XHRUploadOptions>): Uppy;
  513. use(Plugin: plugins.GoogleDrive, opts: Partial<plugins.GoogleDriveOptions>): Uppy;
  514. use(Plugin: plugins.Instagram, opts: Partial<plugins.InstagramOptions>): Uppy;
  515. use(Plugin: plugins.Webcam, opts: Partial<plugins.WebcamOptions>): Uppy;
  516. use(Plugin: plugins.Tus, opts: Partial<plugins.TusOptions>): Uppy;
  517. use(Plugin: plugins.StatusBar, opts: Partial<plugins.StatusBarOptions>): Uppy;
  518. use(Plugin: plugins.Url, opts: Partial<plugins.UrlOptions>): Uppy;
  519. use(Plugin: plugins.Dropbox, opts: Partial<plugins.DropboxOptions>): Uppy;
  520. use(Plugin: plugins.AwsS3, opts: Partial<plugins.AwsS3Options>): Uppy;
  521. use(Plugin: plugins.GoldenRetriever, opts: Partial<plugins.GoldenRetrieverOptions>): Uppy;
  522. use(Plugin: plugins.ThumbnailGenerator, opts: Partial<plugins.ThumbnailGeneratorOptions>): Uppy;
  523. use(Plugin: plugins.Transloadit, opts: Partial<plugins.TransloaditOptions>): Uppy;
  524. use(Plugin: plugins.Dummy, opts: Partial<plugins.DummyOptions>): Uppy;
  525. use(Plugin: plugins.FileInput, opts: Partial<plugins.FileInputOptions>): Uppy;
  526. use(Plugin: plugins.Form, opts: Partial<plugins.FormOptions>): Uppy;
  527. use(Plugin: plugins.Informer, opts: Partial<plugins.InformerOptions>): Uppy;
  528. use(Plugin: plugins.MagicLog, opts: Partial<plugins.MagicLogOptions>): Uppy;
  529. use(Plugin: plugins.ProgressBar, opts: Partial<plugins.ProgressBarOptions>): Uppy;
  530. use(Plugin: plugins.ReduxDevTools, opts: Partial<plugins.ReduxDevToolsOptions>): Uppy;
  531. getPlugin(name: string): Plugin;
  532. iteratePlugins(method: any): void;
  533. removePlugin(instance: Plugin): void;
  534. close(): void;
  535. info(message: string | { message: string; details: string; }, type?: LogType, duration?: number): void;
  536. hideInfo(): void;
  537. log(msg: string, type?: LogType): void;
  538. run(): Uppy;
  539. restore(uploadID: string): Promise<any>;
  540. addResultData(uploadID: string, data: any): void;
  541. upload(): Promise<any>;
  542. }
  543. }
  544. interface Core {
  545. (conf?: Partial<core.CoreConfig>): core.Uppy;
  546. }
  547. declare function Core(conf?: Partial<core.CoreConfig>): core.Uppy;