-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@uppy/zoom: refactor to TypeScript (#4979)
- Loading branch information
Showing
8 changed files
with
177 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tsconfig.* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<M extends Meta, B extends Body> extends UIPlugin< | ||
ZoomOptions, | ||
M, | ||
B, | ||
UnknownProviderPluginState | ||
> { | ||
static VERSION = packageJson.version | ||
|
||
icon: () => JSX.Element | ||
|
||
provider: Provider<M, B> | ||
|
||
view: ProviderViews<M, B> | ||
|
||
storage: typeof tokenStorage | ||
|
||
files: UppyFile<M, B>[] | ||
|
||
constructor(uppy: Uppy<M, B>, opts: ZoomOptions) { | ||
super(uppy, opts) | ||
this.type = 'acquirer' | ||
this.files = [] | ||
this.storage = this.opts.storage || tokenStorage | ||
this.id = this.opts.id || 'Zoom' | ||
this.icon = () => ( | ||
<svg | ||
aria-hidden="true" | ||
focusable="false" | ||
width="32" | ||
height="32" | ||
viewBox="0 0 32 32" | ||
> | ||
<path | ||
d="M24.5 11.125l-2.75 2.063c-.473.353-.75.91-.75 1.5v3.124c0 .59.277 1.147.75 1.5l2.75 2.063a.938.938 0 001.5-.75v-8.75a.938.938 0 00-1.5-.75zm-4.75 9.5c0 1.035-.84 1.875-1.875 1.875H9.75A3.75 3.75 0 016 18.75v-6.875C6 10.84 6.84 10 7.875 10H16a3.75 3.75 0 013.75 3.75v6.875z" | ||
fill="#2E8CFF" | ||
fill-rule="evenodd" | ||
/> | ||
</svg> | ||
) | ||
|
||
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<void> { | ||
await Promise.all([ | ||
this.provider.fetchPreAuthToken(), | ||
this.view.getFolder(), | ||
]) | ||
} | ||
|
||
render(state: unknown): ComponentChild { | ||
return this.view.render(state) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Zoom.tsx' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
}, | ||
], | ||
} |