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/zoom: refactor to ESM #3699

Merged
merged 1 commit into from
May 10, 2022
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ module.exports = {
'packages/@uppy/svelte/rollup.config.js',
'packages/@uppy/vue/src/**/*.js',
'packages/@uppy/webcam/src/**/*.js',
'packages/@uppy/zoom/src/**/*.js',
],
parser: 'espree',
parserOptions: {
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/zoom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "MIT",
"main": "lib/index.js",
"types": "types/index.d.ts",
"type": "module",
"keywords": [
"file uploader",
"uppy",
Expand Down
72 changes: 72 additions & 0 deletions packages/@uppy/zoom/src/Zoom.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { h } from 'preact'

import { UIPlugin } from '@uppy/core'
import { Provider } 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.id = this.opts.id || 'Zoom'
Provider.initPlugin(this, opts)
this.title = this.opts.title || 'Zoom'
this.icon = () => (
<svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
<rect className="uppy-ProviderIconBg" width="32" height="32" rx="16" fill="#0E71EB" />
<g fill="none" fillRule="evenodd">
<path fill="#fff" d="M29,31H14c-1.657,0-3-1.343-3-3V17h15c1.657,0,3,1.343,3,3V31z" style={{ transform: 'translate(-5px, -5px) scale(0.9)' }} />
<polygon fill="#fff" points="37,31 31,27 31,21 37,17" style={{ transform: 'translate(-5px, -5px) scale(0.9)' }} />
</g>
</svg>
)

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,
})

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)
}
}
71 changes: 1 addition & 70 deletions packages/@uppy/zoom/src/index.js
Original file line number Diff line number Diff line change
@@ -1,70 +1 @@
const { UIPlugin } = require('@uppy/core')
const { Provider } = require('@uppy/companion-client')
const { ProviderViews } = require('@uppy/provider-views')
const { h } = require('preact')

const locale = require('./locale')

module.exports = class Zoom extends UIPlugin {
static VERSION = require('../package.json').version

constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'Zoom'
Provider.initPlugin(this, opts)
this.title = this.opts.title || 'Zoom'
this.icon = () => (
<svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
<rect className="uppy-ProviderIconBg" width="32" height="32" rx="16" fill="#0E71EB" />
<g fill="none" fillRule="evenodd">
<path fill="#fff" d="M29,31H14c-1.657,0-3-1.343-3-3V17h15c1.657,0,3,1.343,3,3V31z" style={{ transform: 'translate(-5px, -5px) scale(0.9)' }} />
<polygon fill="#fff" points="37,31 31,27 31,21 37,17" style={{ transform: 'translate(-5px, -5px) scale(0.9)' }} />
</g>
</svg>
)

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,
})

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)
}
}
export { default } from './Zoom.jsx'
2 changes: 1 addition & 1 deletion packages/@uppy/zoom/src/locale.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
strings: {
pluginNameZoom: 'Zoom',
},
Expand Down
2 changes: 1 addition & 1 deletion website/src/docs/zoom.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ This option correlates to the [RequestCredentials value](https://developer.mozil
<!-- eslint-disable no-restricted-globals, no-multiple-empty-lines -->

```js
module.exports = {
export default {
strings: {
pluginNameZoom: 'Zoom',
},
Expand Down