Skip to content

Commit

Permalink
@uppy/status-bar: refactor to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Dec 27, 2023
1 parent 35314b6 commit 7599087
Show file tree
Hide file tree
Showing 17 changed files with 405 additions and 130 deletions.
6 changes: 5 additions & 1 deletion packages/@uppy/core/src/BasePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import type { I18n, Locale } from '@uppy/utils/lib/Translator'
import type { Body, Meta } from '@uppy/utils/lib/UppyFile'
import type { Uppy } from '.'

export type PluginOpts = { locale?: Locale; [key: string]: unknown }
export type PluginOpts = {
locale?: Locale
id?: string
[key: string]: unknown
}

export default class BasePlugin<
Opts extends PluginOpts,
Expand Down
9 changes: 8 additions & 1 deletion packages/@uppy/core/src/UIPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ function debounce<T extends (...args: any[]) => any>(
}
}

export interface UIPluginOptions extends PluginOpts {
replaceTargetContent?: boolean
direction?: 'ltr' | 'rtl'
}

/**
* UIPlugin is the extended version of BasePlugin to incorporate rendering with Preact.
* Use this for plugins that need a user interface.
*
* For plugins without an user interface, see BasePlugin.
*/
class UIPlugin<
Opts extends PluginOpts & { direction?: 'ltr' | 'rtl' },
Opts extends UIPluginOptions,
M extends Meta,
B extends Body,
> extends BasePlugin<Opts, M, B> {
Expand All @@ -51,6 +56,8 @@ class UIPlugin<

parent: unknown

title: string

getTargetPlugin(target: unknown): UIPlugin<any, any, any> | undefined {
let targetPlugin
if (typeof target === 'object' && target instanceof UIPlugin) {
Expand Down
17 changes: 9 additions & 8 deletions packages/@uppy/core/src/Uppy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface State<M extends Meta, B extends Body>
}
currentUploads: Record<string, CurrentUpload<M, B>>
allowNewUpload: boolean
recoveredState: null
recoveredState: null | State<M, B>
error: string | null
files: {
[key: string]: UppyFile<M, B>
Expand Down Expand Up @@ -251,6 +251,7 @@ export interface _UppyEventMap<M extends Meta, B extends Body> {
progress: ProgressCallback
'reset-progress': GenericEventCallback
restored: GenericEventCallback
'restore-confirmed': GenericEventCallback
'restriction-failed': RestrictionFailedCallback<M, B>
'resume-all': GenericEventCallback
'retry-all': RetryAllCallback
Expand Down Expand Up @@ -546,7 +547,7 @@ export class Uppy<M extends Meta, B extends Body> {
resetProgress(): void {
const defaultProgress: Omit<FileProgressNotStarted, 'bytesTotal'> = {
percentage: 0,
bytesUploaded: 0,
bytesUploaded: false,
uploadComplete: false,
uploadStarted: null,
}
Expand Down Expand Up @@ -842,7 +843,9 @@ export class Uppy<M extends Meta, B extends Body> {
meta.type = fileType

// `null` means the size is unknown.
const size = Number.isFinite(file.data.size) ? file.data.size : null
const size = Number.isFinite(file.data.size)
? file.data.size
: (null as never)

return {
source: file.source || '',
Expand All @@ -857,17 +860,15 @@ export class Uppy<M extends Meta, B extends Body> {
data: file.data,
progress: {
percentage: 0,
bytesUploaded: 0,
bytesUploaded: false,
bytesTotal: size,
uploadComplete: false,
uploadStarted: null,
} as FileProgressNotStarted,
},
size,
isGhost: false,
isRemote: file.isRemote || false,
// TODO: this should not be a string
// @ts-expect-error wrong
remote: file.remote || '',
remote: file.remote,
preview: file.preview,
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export { default as Uppy } from './Uppy.ts'
export { default as UIPlugin } from './UIPlugin.ts'
export { default as BasePlugin } from './BasePlugin.ts'
export { debugLogger } from './loggers.ts'

export type { UIPluginOptions } from './UIPlugin.ts'
Loading

0 comments on commit 7599087

Please sign in to comment.