From dcaef3173fab680a4247e0febd7b6998e6ef0b1d Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 9 Jul 2021 11:18:03 +0200 Subject: [PATCH] core: fix types --- .../dashboard-modal.component.ts | 5 +- .../dashboard/dashboard.component.ts | 5 +- .../drag-drop/drag-drop.component.ts | 5 +- .../progress-bar/progress-bar.component.ts | 5 +- .../status-bar/status-bar.component.ts | 5 +- .../projects/angular/src/lib/utils/wrapper.ts | 4 +- packages/@uppy/dashboard/types/index.d.ts | 78 +++++++++---------- packages/@uppy/drag-drop/types/index.d.ts | 28 ++++--- packages/@uppy/progress-bar/types/index.d.ts | 15 ++-- packages/@uppy/react/src/Dashboard.d.ts | 4 +- packages/@uppy/react/src/DashboardModal.d.ts | 4 +- packages/@uppy/react/src/DragDrop.d.ts | 4 +- packages/@uppy/react/src/ProgressBar.d.ts | 4 +- packages/@uppy/react/src/StatusBar.d.ts | 4 +- packages/@uppy/status-bar/types/index.d.ts | 28 ++++--- test/endtoend/typescript/main.ts | 2 +- 16 files changed, 99 insertions(+), 101 deletions(-) diff --git a/packages/@uppy/angular/projects/angular/src/lib/components/dashboard-modal/dashboard-modal.component.ts b/packages/@uppy/angular/projects/angular/src/lib/components/dashboard-modal/dashboard-modal.component.ts index 79631af77..84a448d93 100644 --- a/packages/@uppy/angular/projects/angular/src/lib/components/dashboard-modal/dashboard-modal.component.ts +++ b/packages/@uppy/angular/projects/angular/src/lib/components/dashboard-modal/dashboard-modal.component.ts @@ -1,5 +1,6 @@ import { Component, ChangeDetectionStrategy, ElementRef, Input, OnDestroy, OnChanges, SimpleChanges } from '@angular/core'; -import * as Dashboard from '@uppy/dashboard'; +import Dashboard from '@uppy/dashboard'; +import type { DashboardOptions } from '@uppy/dashboard'; import { Uppy } from '@uppy/core'; import { UppyAngularWrapper } from '../../utils/wrapper'; @@ -10,7 +11,7 @@ import { UppyAngularWrapper } from '../../utils/wrapper'; }) export class DashboardModalComponent extends UppyAngularWrapper implements OnDestroy, OnChanges { @Input() uppy: Uppy; - @Input() props: Dashboard.DashboardOptions; + @Input() props: DashboardOptions; @Input() open: boolean; constructor(public el: ElementRef) { diff --git a/packages/@uppy/angular/projects/angular/src/lib/components/dashboard/dashboard.component.ts b/packages/@uppy/angular/projects/angular/src/lib/components/dashboard/dashboard.component.ts index 9a69dd539..24d7893a8 100644 --- a/packages/@uppy/angular/projects/angular/src/lib/components/dashboard/dashboard.component.ts +++ b/packages/@uppy/angular/projects/angular/src/lib/components/dashboard/dashboard.component.ts @@ -1,5 +1,6 @@ import { Component, ChangeDetectionStrategy, ElementRef, Input, OnDestroy, OnChanges, SimpleChanges } from '@angular/core'; -import * as Dashboard from '@uppy/dashboard'; +import Dashboard from '@uppy/dashboard'; +import type { DashboardOptions } from '@uppy/dashboard'; import { Uppy } from '@uppy/core'; import { UppyAngularWrapper } from '../../utils/wrapper'; @@ -10,7 +11,7 @@ import { UppyAngularWrapper } from '../../utils/wrapper'; }) export class DashboardComponent extends UppyAngularWrapper implements OnDestroy, OnChanges { @Input() uppy: Uppy; - @Input() props: Dashboard.DashboardOptions; + @Input() props: DashboardOptions; constructor(public el: ElementRef) { super(); diff --git a/packages/@uppy/angular/projects/angular/src/lib/components/drag-drop/drag-drop.component.ts b/packages/@uppy/angular/projects/angular/src/lib/components/drag-drop/drag-drop.component.ts index 47133c25f..f03a5ea0e 100644 --- a/packages/@uppy/angular/projects/angular/src/lib/components/drag-drop/drag-drop.component.ts +++ b/packages/@uppy/angular/projects/angular/src/lib/components/drag-drop/drag-drop.component.ts @@ -1,6 +1,7 @@ import { Component, ChangeDetectionStrategy, Input, OnDestroy, OnChanges, SimpleChanges, ElementRef } from '@angular/core'; import { Uppy } from '@uppy/core'; -import * as DragDrop from '@uppy/drag-drop'; +import DragDrop from '@uppy/drag-drop'; +import type { DragDropOptions } from '@uppy/drag-drop'; import { UppyAngularWrapper } from '../../utils/wrapper'; @Component({ @@ -10,7 +11,7 @@ import { UppyAngularWrapper } from '../../utils/wrapper'; }) export class DragDropComponent extends UppyAngularWrapper implements OnDestroy, OnChanges { @Input() uppy: Uppy; - @Input() props: DragDrop.DragDropOptions; + @Input() props: DragDropOptions; constructor(public el: ElementRef) { super(); diff --git a/packages/@uppy/angular/projects/angular/src/lib/components/progress-bar/progress-bar.component.ts b/packages/@uppy/angular/projects/angular/src/lib/components/progress-bar/progress-bar.component.ts index ed7891eda..3a41997d2 100644 --- a/packages/@uppy/angular/projects/angular/src/lib/components/progress-bar/progress-bar.component.ts +++ b/packages/@uppy/angular/projects/angular/src/lib/components/progress-bar/progress-bar.component.ts @@ -1,6 +1,7 @@ import { Component, ChangeDetectionStrategy, ElementRef, Input, OnDestroy, OnChanges, SimpleChanges } from '@angular/core'; import { Uppy } from '@uppy/core'; -import * as ProgressBar from '@uppy/progress-bar'; +import ProgressBar from '@uppy/progress-bar'; +import type { ProgressBarOptions } from '@uppy/progress-bar'; import { UppyAngularWrapper } from '../../utils/wrapper'; @Component({ @@ -10,7 +11,7 @@ import { UppyAngularWrapper } from '../../utils/wrapper'; }) export class ProgressBarComponent extends UppyAngularWrapper implements OnDestroy, OnChanges { @Input() uppy: Uppy; - @Input() props: ProgressBar.ProgressBarOptions; + @Input() props: ProgressBarOptions; constructor(public el: ElementRef) { super(); diff --git a/packages/@uppy/angular/projects/angular/src/lib/components/status-bar/status-bar.component.ts b/packages/@uppy/angular/projects/angular/src/lib/components/status-bar/status-bar.component.ts index 42011da60..e00bb4e20 100644 --- a/packages/@uppy/angular/projects/angular/src/lib/components/status-bar/status-bar.component.ts +++ b/packages/@uppy/angular/projects/angular/src/lib/components/status-bar/status-bar.component.ts @@ -1,6 +1,7 @@ import { Component, ChangeDetectionStrategy, Input, ElementRef, SimpleChange, OnDestroy, OnChanges, SimpleChanges } from '@angular/core'; import { Uppy } from '@uppy/core'; -import * as StatusBar from '@uppy/status-bar'; +import StatusBar from '@uppy/status-bar'; +import type { StatusBarOptions } from '@uppy/status-bar'; import { UppyAngularWrapper } from '../../utils/wrapper'; @Component({ @@ -10,7 +11,7 @@ import { UppyAngularWrapper } from '../../utils/wrapper'; }) export class StatusBarComponent extends UppyAngularWrapper implements OnDestroy, OnChanges { @Input() uppy: Uppy; - @Input() props: StatusBar.StatusBarOptions; + @Input() props: StatusBarOptions; constructor(public el: ElementRef) { super(); diff --git a/packages/@uppy/angular/projects/angular/src/lib/utils/wrapper.ts b/packages/@uppy/angular/projects/angular/src/lib/utils/wrapper.ts index 26efe95cf..baef3861b 100644 --- a/packages/@uppy/angular/projects/angular/src/lib/utils/wrapper.ts +++ b/packages/@uppy/angular/projects/angular/src/lib/utils/wrapper.ts @@ -1,7 +1,7 @@ -import { Uppy, Plugin } from '@uppy/core'; +import { Uppy, UIPlugin } from '@uppy/core'; import { ElementRef, SimpleChanges } from '@angular/core'; -export abstract class UppyAngularWrapper { +export abstract class UppyAngularWrapper { abstract props; abstract el: ElementRef abstract uppy: Uppy; diff --git a/packages/@uppy/dashboard/types/index.d.ts b/packages/@uppy/dashboard/types/index.d.ts index 411429baa..1b9928f21 100644 --- a/packages/@uppy/dashboard/types/index.d.ts +++ b/packages/@uppy/dashboard/types/index.d.ts @@ -1,5 +1,5 @@ import type { PluginOptions, UIPlugin, PluginTarget, UppyFile } from '@uppy/core' -import type StatusBar from '@uppy/status-bar' +import type { StatusBarLocale } from '@uppy/status-bar' import DashboardLocale from './generatedLocale' type FieldRenderOptions = { @@ -16,48 +16,46 @@ interface MetaField { render?: (field: FieldRenderOptions, h: PreactRender) => any } -declare module Dashboard { - interface DashboardOptions extends PluginOptions { - animateOpenClose?: boolean - browserBackButtonClose?: boolean - closeAfterFinish?: boolean - closeModalOnClickOutside?: boolean - disableInformer?: boolean - disablePageScrollWhenModalOpen?: boolean - disableStatusBar?: boolean - disableThumbnailGenerator?: boolean - doneButtonHandler?: () => void - height?: string | number - hideCancelButton?: boolean - hidePauseResumeButton?: boolean - hideProgressAfterFinish?: boolean - hideRetryButton?: boolean - hideUploadButton?: boolean - inline?: boolean - locale?: DashboardLocale & StatusBar.StatusBarLocale - metaFields?: MetaField[] | ((file: UppyFile) => MetaField[]) - note?: string | null - onRequestCloseModal?: () => void - plugins?: string[] - fileManagerSelectionType?: 'files' | 'folders' | 'both'; - proudlyDisplayPoweredByUppy?: boolean - showLinkToFileUploadResult?: boolean - showProgressDetails?: boolean - showSelectedFiles?: boolean - showRemoveButtonAfterComplete?: boolean - replaceTargetContent?: boolean - target?: PluginTarget - theme?: 'auto' | 'dark' | 'light' - thumbnailWidth?: number - trigger?: string - width?: string | number - autoOpenFileEditor?: boolean - disabled?: boolean +export interface DashboardOptions extends PluginOptions { + animateOpenClose?: boolean + browserBackButtonClose?: boolean + closeAfterFinish?: boolean + closeModalOnClickOutside?: boolean + disableInformer?: boolean + disablePageScrollWhenModalOpen?: boolean + disableStatusBar?: boolean + disableThumbnailGenerator?: boolean + doneButtonHandler?: () => void + height?: string | number + hideCancelButton?: boolean + hidePauseResumeButton?: boolean + hideProgressAfterFinish?: boolean + hideRetryButton?: boolean + hideUploadButton?: boolean + inline?: boolean + locale?: DashboardLocale & StatusBarLocale + metaFields?: MetaField[] | ((file: UppyFile) => MetaField[]) + note?: string | null + onRequestCloseModal?: () => void + plugins?: string[] + fileManagerSelectionType?: 'files' | 'folders' | 'both'; + proudlyDisplayPoweredByUppy?: boolean + showLinkToFileUploadResult?: boolean + showProgressDetails?: boolean + showSelectedFiles?: boolean + showRemoveButtonAfterComplete?: boolean + replaceTargetContent?: boolean + target?: PluginTarget + theme?: 'auto' | 'dark' | 'light' + thumbnailWidth?: number + trigger?: string + width?: string | number + autoOpenFileEditor?: boolean + disabled?: boolean disableLocalFiles?: boolean - } } -declare class Dashboard extends UIPlugin { +declare class Dashboard extends UIPlugin { addTarget (plugin: UIPlugin): HTMLElement hideAllPanels (): void openModal (): void diff --git a/packages/@uppy/drag-drop/types/index.d.ts b/packages/@uppy/drag-drop/types/index.d.ts index 4bf643d90..18ed2e890 100644 --- a/packages/@uppy/drag-drop/types/index.d.ts +++ b/packages/@uppy/drag-drop/types/index.d.ts @@ -1,22 +1,20 @@ import type { PluginOptions, UIPlugin, PluginTarget } from '@uppy/core' import DragDropLocale from './generatedLocale' -declare module DragDrop { - interface DragDropOptions extends PluginOptions { - replaceTargetContent?: boolean - target?: PluginTarget - inputName?: string - allowMultipleFiles?: boolean - width?: string | number - height?: string | number - note?: string - locale?: DragDropLocale - onDragOver?: (event: MouseEvent) => void - onDragLeave?: (event: MouseEvent) => void - onDrop?: (event: MouseEvent) => void - } +export interface DragDropOptions extends PluginOptions { + replaceTargetContent?: boolean + target?: PluginTarget + inputName?: string + allowMultipleFiles?: boolean + width?: string | number + height?: string | number + note?: string + locale?: DragDropLocale + onDragOver?: (event: MouseEvent) => void + onDragLeave?: (event: MouseEvent) => void + onDrop?: (event: MouseEvent) => void } -declare class DragDrop extends UIPlugin {} +declare class DragDrop extends UIPlugin {} export default DragDrop diff --git a/packages/@uppy/progress-bar/types/index.d.ts b/packages/@uppy/progress-bar/types/index.d.ts index b50621ce8..c5da73461 100644 --- a/packages/@uppy/progress-bar/types/index.d.ts +++ b/packages/@uppy/progress-bar/types/index.d.ts @@ -1,14 +1,13 @@ import type { PluginOptions, UIPlugin, PluginTarget } from '@uppy/core' -declare module ProgressBar { - interface ProgressBarOptions extends PluginOptions { - replaceTargetContent?: boolean - target?: PluginTarget - hideAfterFinish?: boolean - fixed?: boolean - } +export interface ProgressBarOptions extends PluginOptions { + replaceTargetContent?: boolean + target?: PluginTarget + hideAfterFinish?: boolean + fixed?: boolean } -declare class ProgressBar extends UIPlugin {} + +declare class ProgressBar extends UIPlugin {} export default ProgressBar diff --git a/packages/@uppy/react/src/Dashboard.d.ts b/packages/@uppy/react/src/Dashboard.d.ts index ace5f2b1a..fbadc9ada 100644 --- a/packages/@uppy/react/src/Dashboard.d.ts +++ b/packages/@uppy/react/src/Dashboard.d.ts @@ -1,10 +1,10 @@ import * as React from 'react' import { Omit, ToUppyProps } from './CommonTypes' -import Dashboard from '@uppy/dashboard' +import type {DashboardOptions} from '@uppy/dashboard' // This type is mapped into `DashboardProps` below so IntelliSense doesn't display this big mess of nested types type DashboardPropsInner = Omit< - ToUppyProps, + ToUppyProps, // Remove the modal-only props 'animateOpenClose' | 'browserBackButtonClose' | 'inline' | 'onRequestCloseModal' | 'trigger' > & React.BaseHTMLAttributes diff --git a/packages/@uppy/react/src/DashboardModal.d.ts b/packages/@uppy/react/src/DashboardModal.d.ts index f7c9d3424..2d012d51a 100644 --- a/packages/@uppy/react/src/DashboardModal.d.ts +++ b/packages/@uppy/react/src/DashboardModal.d.ts @@ -1,12 +1,12 @@ import { Omit, ToUppyProps } from './CommonTypes' -import Dashboard from '@uppy/dashboard' +import type { DashboardOptions } from '@uppy/dashboard' // This type is mapped into `DashboardModalProps` below so IntelliSense doesn't display this big mess of nested types type DashboardModalPropsInner = { open?: boolean onRequestClose?: VoidFunction } & Omit< - ToUppyProps, + ToUppyProps, // Remove the inline-only and force-overridden props 'inline' | 'onRequestCloseModal' > & React.BaseHTMLAttributes diff --git a/packages/@uppy/react/src/DragDrop.d.ts b/packages/@uppy/react/src/DragDrop.d.ts index 3f59ce178..4f4ce0ddd 100644 --- a/packages/@uppy/react/src/DragDrop.d.ts +++ b/packages/@uppy/react/src/DragDrop.d.ts @@ -1,7 +1,7 @@ import { ToUppyProps } from './CommonTypes' -import DragDrop from '@uppy/drag-drop' +import type { DragDropOptions } from '@uppy/drag-drop' -export type DragDropProps = ToUppyProps & React.BaseHTMLAttributes +export type DragDropProps = ToUppyProps & React.BaseHTMLAttributes /** * React component that renders an area in which files can be dropped to be diff --git a/packages/@uppy/react/src/ProgressBar.d.ts b/packages/@uppy/react/src/ProgressBar.d.ts index 3c8872e16..060419d2d 100644 --- a/packages/@uppy/react/src/ProgressBar.d.ts +++ b/packages/@uppy/react/src/ProgressBar.d.ts @@ -1,7 +1,7 @@ import { ToUppyProps } from './CommonTypes' -import ProgressBar from '@uppy/progress-bar' +import type { ProgressBarOptions } from '@uppy/progress-bar' -export type ProgressBarProps = ToUppyProps & React.BaseHTMLAttributes +export type ProgressBarProps = ToUppyProps & React.BaseHTMLAttributes /** * React component that renders a progress bar at the top of the page. diff --git a/packages/@uppy/react/src/StatusBar.d.ts b/packages/@uppy/react/src/StatusBar.d.ts index 01e931f00..f1f07d3bf 100644 --- a/packages/@uppy/react/src/StatusBar.d.ts +++ b/packages/@uppy/react/src/StatusBar.d.ts @@ -1,7 +1,7 @@ import { ToUppyProps } from './CommonTypes' -import StatusBar from '@uppy/status-bar' +import type { StatusBarOptions } from '@uppy/status-bar' -export type StatusBarProps = ToUppyProps & React.BaseHTMLAttributes +export type StatusBarProps = ToUppyProps & React.BaseHTMLAttributes /** * React component that renders a status bar containing upload progress and speed, diff --git a/packages/@uppy/status-bar/types/index.d.ts b/packages/@uppy/status-bar/types/index.d.ts index 36db2ed4d..c0afafd46 100644 --- a/packages/@uppy/status-bar/types/index.d.ts +++ b/packages/@uppy/status-bar/types/index.d.ts @@ -1,23 +1,21 @@ import type { PluginOptions, UIPlugin, PluginTarget } from '@uppy/core' import GeneratedLocale from './generatedLocale' -declare module StatusBar { - export type StatusBarLocale = GeneratedLocale +export type StatusBarLocale = GeneratedLocale - export interface StatusBarOptions extends PluginOptions { - replaceTargetContent?: boolean - target?: PluginTarget - showProgressDetails?: boolean - hideUploadButton?: boolean - hideAfterFinish?: boolean - hideRetryButton?: boolean, - hidePauseResumeButton?: boolean, - hideCancelButton?: boolean, - doneButtonHandler?: () => void, - locale?: StatusBarLocale - } +export interface StatusBarOptions extends PluginOptions { + replaceTargetContent?: boolean + target?: PluginTarget + showProgressDetails?: boolean + hideUploadButton?: boolean + hideAfterFinish?: boolean + hideRetryButton?: boolean, + hidePauseResumeButton?: boolean, + hideCancelButton?: boolean, + doneButtonHandler?: () => void, + locale?: StatusBarLocale } -declare class StatusBar extends UIPlugin {} +declare class StatusBar extends UIPlugin {} export default StatusBar diff --git a/test/endtoend/typescript/main.ts b/test/endtoend/typescript/main.ts index 72143940f..9990df520 100644 --- a/test/endtoend/typescript/main.ts +++ b/test/endtoend/typescript/main.ts @@ -14,7 +14,7 @@ import { const isOnTravis = !!(process.env.TRAVIS && process.env.CI) const TUS_ENDPOINT = `http://${isOnTravis ? 'companion.test' : 'localhost'}:1080/files/` -const uppy = Core({ +const uppy = new Core({ debug: true, meta: { username: 'John',