Skip to content

Commit

Permalink
@uppy/zoom: refactor to ESM (#3699)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored May 10, 2022
1 parent a3465f7 commit 010a6b1
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 72 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ module.exports = {
'packages/@uppy/url/src/**/*.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

0 comments on commit 010a6b1

Please sign in to comment.