From 7b0f47e977c8252d5bd63761fc37f5d639cd71fb Mon Sep 17 00:00:00 2001 From: Murderlon Date: Mon, 4 Mar 2024 11:33:17 +0100 Subject: [PATCH] @uppy/zoom: refactor to TypeScript --- packages/@uppy/zoom/.npmignore | 1 + packages/@uppy/zoom/src/Zoom.jsx | 71 ------------ packages/@uppy/zoom/src/Zoom.tsx | 109 ++++++++++++++++++ packages/@uppy/zoom/src/index.js | 1 - packages/@uppy/zoom/src/index.ts | 1 + .../@uppy/zoom/src/{locale.js => locale.ts} | 0 packages/@uppy/zoom/tsconfig.build.json | 35 ++++++ packages/@uppy/zoom/tsconfig.json | 31 +++++ 8 files changed, 177 insertions(+), 72 deletions(-) create mode 100644 packages/@uppy/zoom/.npmignore delete mode 100644 packages/@uppy/zoom/src/Zoom.jsx create mode 100644 packages/@uppy/zoom/src/Zoom.tsx delete mode 100644 packages/@uppy/zoom/src/index.js create mode 100644 packages/@uppy/zoom/src/index.ts rename packages/@uppy/zoom/src/{locale.js => locale.ts} (100%) create mode 100644 packages/@uppy/zoom/tsconfig.build.json create mode 100644 packages/@uppy/zoom/tsconfig.json diff --git a/packages/@uppy/zoom/.npmignore b/packages/@uppy/zoom/.npmignore new file mode 100644 index 00000000000..6c816673f08 --- /dev/null +++ b/packages/@uppy/zoom/.npmignore @@ -0,0 +1 @@ +tsconfig.* diff --git a/packages/@uppy/zoom/src/Zoom.jsx b/packages/@uppy/zoom/src/Zoom.jsx deleted file mode 100644 index 30b0f073e9d..00000000000 --- a/packages/@uppy/zoom/src/Zoom.jsx +++ /dev/null @@ -1,71 +0,0 @@ -import { h } from 'preact' - -import { UIPlugin } from '@uppy/core' -import { Provider, tokenStorage, getAllowedHosts } from '@uppy/companion-client' -import { ProviderViews } from '@uppy/provider-views' - -import packageJson from '../package.json' -import locale from './locale.js' - -export default class Zoom extends UIPlugin { - static VERSION = packageJson.version - - constructor (uppy, opts) { - super(uppy, opts) - this.type = 'acquirer' - this.files = [] - this.storage = this.opts.storage || tokenStorage - this.id = this.opts.id || 'Zoom' - this.icon = () => ( - - ) - - this.opts.companionAllowedHosts = getAllowedHosts(this.opts.companionAllowedHosts, this.opts.companionUrl) - this.provider = new Provider(uppy, { - companionUrl: this.opts.companionUrl, - companionHeaders: this.opts.companionHeaders, - companionKeysParams: this.opts.companionKeysParams, - companionCookiesRule: this.opts.companionCookiesRule, - provider: 'zoom', - pluginId: this.id, - supportsRefreshToken: false, - }) - - this.defaultLocale = locale - - this.i18nInit() - this.title = this.i18n('pluginNameZoom') - - this.onFirstRender = this.onFirstRender.bind(this) - this.render = this.render.bind(this) - } - - install () { - this.view = new ProviderViews(this, { - provider: this.provider, - }) - - const { target } = this.opts - if (target) { - this.mount(target, this) - } - } - - uninstall () { - this.view.tearDown() - this.unmount() - } - - onFirstRender () { - return Promise.all([ - this.provider.fetchPreAuthToken(), - this.view.getFolder(), - ]) - } - - render (state) { - return this.view.render(state) - } -} diff --git a/packages/@uppy/zoom/src/Zoom.tsx b/packages/@uppy/zoom/src/Zoom.tsx new file mode 100644 index 00000000000..3bc576fa402 --- /dev/null +++ b/packages/@uppy/zoom/src/Zoom.tsx @@ -0,0 +1,109 @@ +import { + Provider, + getAllowedHosts, + tokenStorage, + type CompanionPluginOptions, +} from '@uppy/companion-client' +import { UIPlugin, Uppy } from '@uppy/core' +import { ProviderViews } from '@uppy/provider-views' +import { h, type ComponentChild } from 'preact' + +import type { UppyFile, Body, Meta } from '@uppy/utils/lib/UppyFile' +import type { UnknownProviderPluginState } from '@uppy/core/lib/Uppy.ts' +import locale from './locale.ts' +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore We don't want TS to generate types for the package.json +import packageJson from '../package.json' + +export type ZoomOptions = CompanionPluginOptions + +export default class Zoom extends UIPlugin< + ZoomOptions, + M, + B, + UnknownProviderPluginState +> { + static VERSION = packageJson.version + + icon: () => JSX.Element + + provider: Provider + + view: ProviderViews + + storage: typeof tokenStorage + + files: UppyFile[] + + constructor(uppy: Uppy, opts: ZoomOptions) { + super(uppy, opts) + this.type = 'acquirer' + this.files = [] + this.storage = this.opts.storage || tokenStorage + this.id = this.opts.id || 'Zoom' + this.icon = () => ( + + ) + + this.opts.companionAllowedHosts = getAllowedHosts( + this.opts.companionAllowedHosts, + this.opts.companionUrl, + ) + this.provider = new Provider(uppy, { + companionUrl: this.opts.companionUrl, + companionHeaders: this.opts.companionHeaders, + companionKeysParams: this.opts.companionKeysParams, + companionCookiesRule: this.opts.companionCookiesRule, + provider: 'zoom', + pluginId: this.id, + supportsRefreshToken: false, + }) + + this.defaultLocale = locale + + this.i18nInit() + this.title = this.i18n('pluginNameZoom') + + this.onFirstRender = this.onFirstRender.bind(this) + this.render = this.render.bind(this) + } + + install(): void { + this.view = new ProviderViews(this, { + provider: this.provider, + }) + + const { target } = this.opts + if (target) { + this.mount(target, this) + } + } + + uninstall(): void { + this.view.tearDown() + this.unmount() + } + + async onFirstRender(): Promise { + await Promise.all([ + this.provider.fetchPreAuthToken(), + this.view.getFolder(), + ]) + } + + render(state: unknown): ComponentChild { + return this.view.render(state) + } +} diff --git a/packages/@uppy/zoom/src/index.js b/packages/@uppy/zoom/src/index.js deleted file mode 100644 index 074dbe50146..00000000000 --- a/packages/@uppy/zoom/src/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from './Zoom.jsx' diff --git a/packages/@uppy/zoom/src/index.ts b/packages/@uppy/zoom/src/index.ts new file mode 100644 index 00000000000..09744198a23 --- /dev/null +++ b/packages/@uppy/zoom/src/index.ts @@ -0,0 +1 @@ +export { default } from './Zoom.tsx' diff --git a/packages/@uppy/zoom/src/locale.js b/packages/@uppy/zoom/src/locale.ts similarity index 100% rename from packages/@uppy/zoom/src/locale.js rename to packages/@uppy/zoom/src/locale.ts diff --git a/packages/@uppy/zoom/tsconfig.build.json b/packages/@uppy/zoom/tsconfig.build.json new file mode 100644 index 00000000000..99aaf378deb --- /dev/null +++ b/packages/@uppy/zoom/tsconfig.build.json @@ -0,0 +1,35 @@ +{ + "extends": "../../../tsconfig.shared", + "compilerOptions": { + "noImplicitAny": false, + "outDir": "./lib", + "paths": { + "@uppy/companion-client": ["../companion-client/src/index.js"], + "@uppy/companion-client/lib/*": ["../companion-client/src/*"], + "@uppy/provider-views": ["../provider-views/src/index.js"], + "@uppy/provider-views/lib/*": ["../provider-views/src/*"], + "@uppy/utils/lib/*": ["../utils/src/*"], + "@uppy/core": ["../core/src/index.js"], + "@uppy/core/lib/*": ["../core/src/*"] + }, + "resolveJsonModule": false, + "rootDir": "./src", + "skipLibCheck": true + }, + "include": ["./src/**/*.*"], + "exclude": ["./src/**/*.test.ts"], + "references": [ + { + "path": "../companion-client/tsconfig.build.json" + }, + { + "path": "../provider-views/tsconfig.build.json" + }, + { + "path": "../utils/tsconfig.build.json" + }, + { + "path": "../core/tsconfig.build.json" + } + ] +} diff --git a/packages/@uppy/zoom/tsconfig.json b/packages/@uppy/zoom/tsconfig.json new file mode 100644 index 00000000000..e5220fb5ab1 --- /dev/null +++ b/packages/@uppy/zoom/tsconfig.json @@ -0,0 +1,31 @@ +{ + "extends": "../../../tsconfig.shared", + "compilerOptions": { + "emitDeclarationOnly": false, + "noEmit": true, + "paths": { + "@uppy/companion-client": ["../companion-client/src/index.js"], + "@uppy/companion-client/lib/*": ["../companion-client/src/*"], + "@uppy/provider-views": ["../provider-views/src/index.js"], + "@uppy/provider-views/lib/*": ["../provider-views/src/*"], + "@uppy/utils/lib/*": ["../utils/src/*"], + "@uppy/core": ["../core/src/index.js"], + "@uppy/core/lib/*": ["../core/src/*"], + }, + }, + "include": ["./package.json", "./src/**/*.*"], + "references": [ + { + "path": "../companion-client/tsconfig.build.json", + }, + { + "path": "../provider-views/tsconfig.build.json", + }, + { + "path": "../utils/tsconfig.build.json", + }, + { + "path": "../core/tsconfig.build.json", + }, + ], +}