Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard - convert some files to typescript - 2 #5367

Merged
merged 17 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' | ''
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading