Browse Source

Add dashboard and UIPlugin types (#3426)

Merlijn Vos 3 năm trước cách đây
mục cha
commit
7fdad73d6e

+ 1 - 0
packages/@uppy/core/types/index.d.ts

@@ -55,6 +55,7 @@ export interface AddFileOptions<
 
 export interface PluginOptions {
   id?: string
+  replaceTargetContent?: boolean
 }
 
 export interface DefaultPluginOptions extends PluginOptions {

+ 1 - 0
packages/@uppy/dashboard/src/index.js

@@ -1060,6 +1060,7 @@ module.exports = class Dashboard extends UIPlugin {
       this.uppy.use(ThumbnailGenerator, {
         id: `${this.id}:ThumbnailGenerator`,
         thumbnailWidth: this.opts.thumbnailWidth,
+        thumbnailHeight: this.opts.thumbnailHeight,
         thumbnailType: this.opts.thumbnailType,
         waitForThumbnailsBeforeUpload: this.opts.waitForThumbnailsBeforeUpload,
         // If we don't block on thumbnails, we can lazily generate them

+ 4 - 2
packages/@uppy/dashboard/types/index.d.ts

@@ -1,5 +1,6 @@
 import type { PluginOptions, UIPlugin, PluginTarget, UppyFile, GenericEventCallback } from '@uppy/core'
 import type { StatusBarLocale } from '@uppy/status-bar'
+import type { ThumbnailOptions } from '@uppy/thumbnail-generator'
 import DashboardLocale from './generatedLocale'
 
 type FieldRenderOptions = {
@@ -19,7 +20,9 @@ interface MetaField {
   render?: (field: FieldRenderOptions, h: PreactRender) => any
 }
 
-export interface DashboardOptions extends PluginOptions {
+type Options = PluginOptions & ThumbnailOptions
+
+export interface DashboardOptions extends Options {
   animateOpenClose?: boolean
   browserBackButtonClose?: boolean
   closeAfterFinish?: boolean
@@ -47,7 +50,6 @@ export interface DashboardOptions extends PluginOptions {
   showRemoveButtonAfterComplete?: boolean
   target?: PluginTarget
   theme?: 'auto' | 'dark' | 'light'
-  thumbnailWidth?: number
   trigger?: string
   width?: string | number
   autoOpenFileEditor?: boolean

+ 18 - 12
packages/@uppy/thumbnail-generator/types/index.d.ts

@@ -2,25 +2,31 @@ import type { PluginOptions, UIPlugin, UppyFile } from '@uppy/core'
 
 import ThumbnailGeneratorLocale from './generatedLocale'
 
-interface ThumbnailGeneratorOptions extends PluginOptions {
-    thumbnailWidth?: number,
-    thumbnailHeight?: number,
-    thumbnailType?: string,
-    waitForThumbnailsBeforeUpload?: boolean,
-    lazy?: boolean,
-    locale?: ThumbnailGeneratorLocale,
+export interface ThumbnailOptions {
+  thumbnailWidth?: number
+  thumbnailHeight?: number
+  thumbnailType?: string
+  waitForThumbnailsBeforeUpload?: boolean
+  lazy?: boolean
 }
 
-declare class ThumbnailGenerator extends UIPlugin<ThumbnailGeneratorOptions> { }
+interface Options extends ThumbnailOptions {
+  locale?: ThumbnailGeneratorLocale
+}
+
+declare class ThumbnailGenerator extends UIPlugin<PluginOptions & Options> {}
 
 export default ThumbnailGenerator
 
 // Events
 
-export type ThumbnailGeneratedCallback<TMeta> = (file: UppyFile<TMeta>, preview: string) => void;
+export type ThumbnailGeneratedCallback<TMeta> = (
+  file: UppyFile<TMeta>,
+  preview: string
+) => void
 
 declare module '@uppy/core' {
-    export interface UppyEventMap<TMeta> {
-        'thumbnail:generated' : ThumbnailGeneratedCallback<TMeta>
-    }
+  export interface UppyEventMap<TMeta> {
+    'thumbnail:generated': ThumbnailGeneratedCallback<TMeta>
+  }
 }