mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-19 01:24:18 +00:00
* What is happening "*" * Instead of re-creating i18nInit, we could just make it part of the BasePlugin * set plugin title and allow changing it from locale * remove i18nInit method, since we now include it in BasePlugin * All provider titles should come from locale * Update en_US.js * make translator private //cc @aduh95 * init locale after calling setOptions * Update en_US.js * Update packages/@uppy/core/src/BasePlugin.js Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> * Update packages/@uppy/core/src/index.js Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> * Bind `i18n` functions * Remove duplicate i18nInit — it’s in BasePlugin already * fix formatting * fix name * Update en_US.js Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
65 lines
1.5 KiB
JavaScript
65 lines
1.5 KiB
JavaScript
const { UIPlugin } = require('@uppy/core')
|
|
const { Provider } = require('@uppy/companion-client')
|
|
const { ProviderViews } = require('@uppy/provider-views')
|
|
const { h } = require('preact')
|
|
|
|
module.exports = class MyCustomProvider extends UIPlugin {
|
|
constructor (uppy, opts) {
|
|
super(uppy, opts)
|
|
this.type = 'acquirer'
|
|
this.id = this.opts.id || 'MyCustomProvider'
|
|
Provider.initPlugin(this, opts)
|
|
|
|
this.icon = () => (
|
|
<svg width="32" height="32" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M10 9V0h12v9H10zm12 5h10v18H0V14h10v9h12v-9z" fill="#000000" fillRule="nonzero" />
|
|
</svg>
|
|
)
|
|
|
|
this.provider = new Provider(uppy, {
|
|
companionUrl: this.opts.companionUrl,
|
|
companionHeaders: this.opts.companionHeaders,
|
|
provider: 'myunsplash',
|
|
pluginId: this.id,
|
|
})
|
|
|
|
this.defaultLocale = {
|
|
strings: {
|
|
pluginNameMyUnsplash: 'MyUnsplash',
|
|
},
|
|
}
|
|
this.i18nInit()
|
|
this.title = this.i18n('MyUnsplash')
|
|
|
|
this.files = []
|
|
this.onFirstRender = this.onFirstRender.bind(this)
|
|
this.render = this.render.bind(this)
|
|
|
|
// merge default options with the ones set by user
|
|
this.opts = { ...opts }
|
|
}
|
|
|
|
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 this.view.getFolder()
|
|
}
|
|
|
|
render (state) {
|
|
return this.view.render(state)
|
|
}
|
|
}
|