-
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/unsplash: refactor to TypeScript
- Loading branch information
Showing
7 changed files
with
176 additions
and
70 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,108 @@ | ||
import { | ||
getAllowedHosts, | ||
tokenStorage, | ||
type CompanionPluginOptions, | ||
SearchProvider, | ||
} from '@uppy/companion-client' | ||
import { UIPlugin, Uppy } from '@uppy/core' | ||
import { SearchProviderViews } from '@uppy/provider-views' | ||
import { h, type ComponentChild } from 'preact' | ||
|
||
import type { UppyFile, Body, Meta } from '@uppy/utils/lib/UppyFile' | ||
import type { UnknownSearchProviderPluginState } from '@uppy/core/lib/Uppy.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 UnsplashOptions = CompanionPluginOptions | ||
|
||
export default class Unsplash<M extends Meta, B extends Body> extends UIPlugin< | ||
UnsplashOptions, | ||
M, | ||
B, | ||
UnknownSearchProviderPluginState | ||
> { | ||
static VERSION = packageJson.version | ||
|
||
icon: () => JSX.Element | ||
|
||
provider: SearchProvider<M, B> | ||
|
||
view: SearchProviderViews<M, B> | ||
|
||
storage: typeof tokenStorage | ||
|
||
files: UppyFile<M, B>[] | ||
|
||
hostname: string | ||
|
||
constructor(uppy: Uppy<M, B>, opts: UnsplashOptions) { | ||
super(uppy, opts) | ||
this.type = 'acquirer' | ||
this.files = [] | ||
this.storage = this.opts.storage || tokenStorage | ||
this.id = this.opts.id || 'Unsplash' | ||
this.title = this.opts.title || 'Unsplash' | ||
|
||
this.icon = () => ( | ||
<svg | ||
className="uppy-DashboardTab-iconUnsplash" | ||
viewBox="0 0 32 32" | ||
height="32" | ||
width="32" | ||
aria-hidden="true" | ||
> | ||
<g fill="currentcolor"> | ||
<path d="M46.575 10.883v-9h12v9zm12 5h10v18h-32v-18h10v9h12z" /> | ||
<path d="M13 12.5V8h6v4.5zm6 2.5h5v9H8v-9h5v4.5h6z" /> | ||
</g> | ||
</svg> | ||
) | ||
|
||
if (!this.opts.companionUrl) { | ||
throw new Error( | ||
'Companion hostname is required, please consult https://uppy.io/docs/companion', | ||
) | ||
} | ||
|
||
this.hostname = this.opts.companionUrl | ||
|
||
this.opts.companionAllowedHosts = getAllowedHosts( | ||
this.opts.companionAllowedHosts, | ||
this.opts.companionUrl, | ||
) | ||
this.provider = new SearchProvider(uppy, { | ||
companionUrl: this.opts.companionUrl, | ||
companionHeaders: this.opts.companionHeaders, | ||
companionCookiesRule: this.opts.companionCookiesRule, | ||
provider: 'unsplash', | ||
pluginId: this.id, | ||
}) | ||
} | ||
|
||
install(): void { | ||
this.view = new SearchProviderViews(this, { | ||
provider: this.provider, | ||
viewType: 'unsplash', | ||
showFilter: true, | ||
}) | ||
|
||
const { target } = this.opts | ||
if (target) { | ||
this.mount(target, this) | ||
} | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
async onFirstRender(): Promise<void> { | ||
// do nothing | ||
} | ||
|
||
render(state: unknown): ComponentChild { | ||
return this.view.render(state) | ||
} | ||
|
||
uninstall(): void { | ||
this.unmount() | ||
} | ||
} |
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 './Unsplash.tsx' |
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", | ||
}, | ||
], | ||
} |