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/onedrive: refactor to ESM #3694

Merged
merged 2 commits into from
May 11, 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 @@ -210,6 +210,7 @@ module.exports = {
'packages/@uppy/image-editor/src/**/*.js',
'packages/@uppy/locales/src/**/*.js',
'packages/@uppy/locales/template.js',
'packages/@uppy/onedrive/src/**/*.js',
'packages/@uppy/progress-bar/src/**/*.js',
'packages/@uppy/svelte/src/**/*.js',
'packages/@uppy/svelte/rollup.config.js',
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/onedrive/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
73 changes: 73 additions & 0 deletions packages/@uppy/onedrive/src/OneDrive.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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 OneDrive extends UIPlugin {
static VERSION = packageJson.version

constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'OneDrive'
Provider.initPlugin(this, opts)
this.title = this.opts.title || 'OneDrive'
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" width="32" height="32" rx="16" fill="#0262C0" />
<g fill="#FFF" fillRule="nonzero">
<path d="M24.157 22s1.492-.205 1.79-1.655a2.624 2.624 0 0 0 .03-.878c-.22-1.64-1.988-2.01-1.988-2.01s.307-1.765-1.312-2.69c-1.62-.925-3.1 0-3.1 0S18.711 13 16.366 13c-3.016 0-3.519 3.448-3.519 3.448S10 16.618 10 19.14c0 2.523 2.597 2.86 2.597 2.86h11.56z" />
<path d="M9.421 19.246c0-2.197 1.606-3.159 2.871-3.472.44-1.477 1.654-3.439 4.135-3.439H16.445c1.721 0 2.79.823 3.368 1.476a3.99 3.99 0 0 1 1.147-.171h.01l.03.002C21.017 13.5 20.691 10 16.757 10c-2.69 0-3.639 2.345-3.639 2.345s-1.95-1.482-3.955.567c-1.028 1.052-.79 2.669-.79 2.669S6 15.824 6 18.412C6 20.757 8.452 21 8.452 21h1.372a3.77 3.77 0 0 1-.403-1.754z" />
</g>
</g>
</svg>
)

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

this.defaultLocale = locale

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

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

constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'OneDrive'
Provider.initPlugin(this, opts)
this.title = this.opts.title || 'OneDrive'
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" width="32" height="32" rx="16" fill="#0262C0" />
<g fill="#FFF" fillRule="nonzero">
<path d="M24.157 22s1.492-.205 1.79-1.655a2.624 2.624 0 0 0 .03-.878c-.22-1.64-1.988-2.01-1.988-2.01s.307-1.765-1.312-2.69c-1.62-.925-3.1 0-3.1 0S18.711 13 16.366 13c-3.016 0-3.519 3.448-3.519 3.448S10 16.618 10 19.14c0 2.523 2.597 2.86 2.597 2.86h11.56z" />
<path d="M9.421 19.246c0-2.197 1.606-3.159 2.871-3.472.44-1.477 1.654-3.439 4.135-3.439H16.445c1.721 0 2.79.823 3.368 1.476a3.99 3.99 0 0 1 1.147-.171h.01l.03.002C21.017 13.5 20.691 10 16.757 10c-2.69 0-3.639 2.345-3.639 2.345s-1.95-1.482-3.955.567c-1.028 1.052-.79 2.669-.79 2.669S6 15.824 6 18.412C6 20.757 8.452 21 8.452 21h1.372a3.77 3.77 0 0 1-.403-1.754z" />
</g>
</g>
</svg>
)

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

this.defaultLocale = locale

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

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