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

@uppy/core: add PluginTarget type and mark options as optional #4874

Merged
merged 1 commit into from
Jan 19, 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
4 changes: 2 additions & 2 deletions packages/@uppy/core/src/BasePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export default class BasePlugin<

VERSION: string

constructor(uppy: Uppy<M, B>, opts: Opts) {
constructor(uppy: Uppy<M, B>, opts?: Partial<Opts>) {
this.uppy = uppy
this.opts = opts ?? {}
this.opts = (opts ?? {}) as Opts
}

getPluginState(): PluginState {
Expand Down
17 changes: 13 additions & 4 deletions packages/@uppy/core/src/UIPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class UIPlugin<

title: string

getTargetPlugin(target: unknown): UIPlugin<any, any, any> | undefined {
getTargetPlugin<Me extends Meta, Bo extends Body>(
target: PluginTarget<Me, Bo>, // eslint-disable-line no-use-before-define
): UIPlugin<any, Me, Bo> | undefined {
let targetPlugin
if (typeof target === 'object' && target instanceof UIPlugin) {
// Targeting a plugin *instance*
Expand All @@ -84,9 +86,9 @@ class UIPlugin<
* If it’s an object — target is a plugin, and we search `plugins`
* for a plugin with same name and return its target.
*/
mount(
target: HTMLElement | string,
plugin: UIPlugin<any, any, any>,
mount<Me extends Meta, Bo extends Body>(
target: PluginTarget<Me, Bo>, // eslint-disable-line no-use-before-define
plugin: UIPlugin<any, Me, Bo>,
): HTMLElement {
const callerPluginName = plugin.id

Expand Down Expand Up @@ -196,3 +198,10 @@ class UIPlugin<
}

export default UIPlugin

export type PluginTarget<M extends Meta, B extends Body> =
| string
| Element
| typeof BasePlugin
| typeof UIPlugin
| BasePlugin<any, M, B>
Loading