Skip to content

Commit

Permalink
Dashboard - convert some files to typescript (#5367)
Browse files Browse the repository at this point in the history
Co-authored-by: Murderlon <[email protected]>
  • Loading branch information
lakesare and Murderlon authored Oct 15, 2024
1 parent 9a4b8ef commit 922e7fb
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 97 deletions.
2 changes: 1 addition & 1 deletion packages/@uppy/core/src/UIPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class UIPlugin<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
state: Record<string, unknown>,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
container: HTMLElement,
container?: HTMLElement,
): any {
throw new Error(
'Extend the render method to add your plugin to a DOM element',
Expand Down
50 changes: 33 additions & 17 deletions packages/@uppy/dashboard/src/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ interface Target {
type: string
}

interface TargetWithRender extends Target {
icon: ComponentChild
export interface TargetWithRender extends Target {
icon: () => ComponentChild
render: () => ComponentChild
}

Expand All @@ -110,6 +110,12 @@ export interface DashboardState<M extends Meta, B extends Body> {
fileCardFor: string | null
showFileEditor: boolean
metaFields?: MetaField[] | ((file: UppyFile<M, B>) => MetaField[])
isHidden: boolean
isClosing: boolean
containerWidth: number
containerHeight: number
areInsidesReadyToBeVisible: boolean
isDraggingOver: boolean
[key: string]: unknown
}

Expand Down Expand Up @@ -146,7 +152,7 @@ interface DashboardMiscOptions<M extends Meta, B extends Body>
hideRetryButton?: boolean
hideUploadButton?: boolean
metaFields?: MetaField[] | ((file: UppyFile<M, B>) => MetaField[])
nativeCameraFacingMode?: ConstrainDOMString
nativeCameraFacingMode?: 'user' | 'environment' | ''
note?: string | null
onDragLeave?: (event: DragEvent) => void
onDragOver?: (event: DragEvent) => void
Expand All @@ -165,7 +171,7 @@ interface DashboardMiscOptions<M extends Meta, B extends Body>
thumbnailHeight?: number
thumbnailType?: string
thumbnailWidth?: number
trigger?: string | Element
trigger?: string | Element | null
waitForThumbnailsBeforeUpload?: boolean
}

Expand All @@ -178,9 +184,6 @@ export type DashboardOptions<
const defaultOptions = {
target: 'body',
metaFields: [],
inline: false as boolean,
width: 750,
height: 550,
thumbnailWidth: 280,
thumbnailType: 'image/jpeg',
waitForThumbnailsBeforeUpload: false,
Expand All @@ -193,31 +196,44 @@ const defaultOptions = {
hidePauseResumeButton: false,
hideProgressAfterFinish: false,
note: null,
closeModalOnClickOutside: false,
closeAfterFinish: false,
singleFileFullScreen: true,
disableStatusBar: false,
disableInformer: false,
disableThumbnailGenerator: false,
disablePageScrollWhenModalOpen: true,
animateOpenClose: true,
fileManagerSelectionType: 'files',
proudlyDisplayPoweredByUppy: true,
showSelectedFiles: true,
showRemoveButtonAfterComplete: false,
browserBackButtonClose: false,
showNativePhotoCameraButton: false,
showNativeVideoCameraButton: false,
theme: 'light',
autoOpen: null,
disabled: false,
disableLocalFiles: false,
nativeCameraFacingMode: '',
onDragLeave: () => {},
onDragOver: () => {},
onDrop: () => {},
plugins: [],

// Dynamic default options, they have to be defined in the constructor (because
// they require access to the `this` keyword), but we still want them to
// appear in the default options so TS knows they'll be defined.
doneButtonHandler: undefined as any,
onRequestCloseModal: null as any,

// defaultModalOptions
inline: false as boolean,
animateOpenClose: true,
browserBackButtonClose: false,
closeAfterFinish: false,
closeModalOnClickOutside: false,
disablePageScrollWhenModalOpen: true,
trigger: null,

// defaultInlineOptions
width: 750,
height: 550,
} satisfies Partial<DashboardOptions<any, any>>

/**
Expand Down Expand Up @@ -824,7 +840,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<

this.setPluginState({ isDraggingOver: true })

this.opts.onDragOver?.(event)
this.opts.onDragOver(event)
}

private handleDragLeave = (event: DragEvent) => {
Expand All @@ -833,7 +849,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<

this.setPluginState({ isDraggingOver: false })

this.opts.onDragLeave?.(event)
this.opts.onDragLeave(event)
}

private handleDrop = async (event: DragEvent) => {
Expand Down Expand Up @@ -872,7 +888,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
this.addFiles(files)
}

this.opts.onDrop?.(event)
this.opts.onDrop(event)
}

private handleRequestThumbnail = (file: UppyFile<M, B>) => {
Expand Down Expand Up @@ -1260,7 +1276,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
}

#addSpecifiedPluginsFromOptions = () => {
const plugins = this.opts.plugins || []
const { plugins } = this.opts

plugins.forEach((pluginID) => {
const plugin = this.uppy.getPlugin(pluginID)
Expand Down Expand Up @@ -1466,7 +1482,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
if (thumbnail) this.uppy.removePlugin(thumbnail)
}

const plugins = this.opts.plugins || []
const { plugins } = this.opts
plugins.forEach((pluginID) => {
const plugin = this.uppy.getPlugin(pluginID)
if (plugin) (plugin as any).unmount()
Expand Down
Loading

0 comments on commit 922e7fb

Please sign in to comment.