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/dropbox: refactor to ESM #3651

Merged
merged 1 commit into from
Apr 21, 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 @@ -202,6 +202,7 @@ module.exports = {
'packages/@uppy/box/src/**/*.js',
'packages/@uppy/drag-drop/src/**/*.js',
'packages/@uppy/drop-target/src/**/*.js',
'packages/@uppy/dropbox/src/**/*.js',
'packages/@uppy/compressor/src/**/*.js',
'packages/@uppy/vue/src/**/*.js',
],
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/dropbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "2.0.5",
"license": "MIT",
"main": "lib/index.js",
"type": "module",
"types": "types/index.d.ts",
"keywords": [
"file uploader",
Expand Down
70 changes: 70 additions & 0 deletions packages/@uppy/dropbox/src/Dropbox.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { UIPlugin } from '@uppy/core'
import { Provider } from '@uppy/companion-client'
import { ProviderViews } from '@uppy/provider-views'
import { h } from 'preact'

import packageJson from '../package.json'
import locale from './locale.js'

export default class Dropbox extends UIPlugin {
static VERSION = packageJson.version

constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'Dropbox'
Provider.initPlugin(this, opts)
this.title = this.opts.title || 'Dropbox'
this.icon = () => (
<svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
<g fill="none" fillRule="evenodd">
<rect className="uppy-ProviderIconBg" fill="#0D2481" width="32" height="32" rx="16" />
<path d="M11 8l5 3.185-5 3.186-5-3.186L11 8zm10 0l5 3.185-5 3.186-5-3.186L21 8zM6 17.556l5-3.185 5 3.185-5 3.186-5-3.186zm15-3.185l5 3.185-5 3.186-5-3.186 5-3.185zm-10 7.432l5-3.185 5 3.185-5 3.186-5-3.186z" fill="#FFF" fillRule="nonzero" />
</g>
</svg>
)

this.provider = new Provider(uppy, {
companionUrl: this.opts.companionUrl,
companionHeaders: this.opts.companionHeaders,
companionKeysParams: this.opts.companionKeysParams,
companionCookiesRule: this.opts.companionCookiesRule,
provider: 'dropbox',
pluginId: this.id,
})

this.defaultLocale = locale

this.i18nInit()
this.title = this.i18n('pluginNameDropbox')

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)
}
}
70 changes: 1 addition & 69 deletions packages/@uppy/dropbox/src/index.js
Original file line number Diff line number Diff line change
@@ -1,69 +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 Dropbox extends UIPlugin {
static VERSION = require('../package.json').version

constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'Dropbox'
Provider.initPlugin(this, opts)
this.title = this.opts.title || 'Dropbox'
this.icon = () => (
<svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
<g fill="none" fillRule="evenodd">
<rect className="uppy-ProviderIconBg" fill="#0D2481" width="32" height="32" rx="16" />
<path d="M11 8l5 3.185-5 3.186-5-3.186L11 8zm10 0l5 3.185-5 3.186-5-3.186L21 8zM6 17.556l5-3.185 5 3.185-5 3.186-5-3.186zm15-3.185l5 3.185-5 3.186-5-3.186 5-3.185zm-10 7.432l5-3.185 5 3.185-5 3.186-5-3.186z" fill="#FFF" fillRule="nonzero" />
</g>
</svg>
)

this.provider = new Provider(uppy, {
companionUrl: this.opts.companionUrl,
companionHeaders: this.opts.companionHeaders,
companionKeysParams: this.opts.companionKeysParams,
companionCookiesRule: this.opts.companionCookiesRule,
provider: 'dropbox',
pluginId: this.id,
})

this.defaultLocale = locale

this.i18nInit()
this.title = this.i18n('pluginNameDropbox')

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 './Dropbox.jsx'
2 changes: 1 addition & 1 deletion packages/@uppy/dropbox/src/locale.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
strings: {
pluginNameDropbox: 'Dropbox',
},
Expand Down
2 changes: 1 addition & 1 deletion website/src/docs/dropbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,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: {
pluginNameDropbox: 'Dropbox',
},
Expand Down