index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const { UIPlugin } = require('@uppy/core')
  2. const { Provider } = require('@uppy/companion-client')
  3. const { ProviderViews } = require('@uppy/provider-views')
  4. const { h } = require('preact')
  5. module.exports = class Box extends UIPlugin {
  6. static VERSION = require('../package.json').version
  7. constructor (uppy, opts) {
  8. super(uppy, opts)
  9. this.id = this.opts.id || 'Box'
  10. Provider.initPlugin(this, opts)
  11. this.title = this.opts.title || 'Box'
  12. this.icon = () => (
  13. <svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
  14. <g fill="none" fillRule="evenodd">
  15. <rect className="uppy-ProviderIconBg" fill="#0061D5" width="32" height="32" rx="16" />
  16. <g fill="#fff" fillRule="nonzero">
  17. <path d="m16.4 13.5c-1.6 0-3 0.9-3.7 2.2-0.7-1.3-2.1-2.2-3.7-2.2-1 0-1.8 0.3-2.5 0.8v-3.6c-0.1-0.3-0.5-0.7-1-0.7s-0.8 0.4-0.8 0.8v7c0 2.3 1.9 4.2 4.2 4.2 1.6 0 3-0.9 3.7-2.2 0.7 1.3 2.1 2.2 3.7 2.2 2.3 0 4.2-1.9 4.2-4.2 0.1-2.4-1.8-4.3-4.1-4.3m-7.5 6.8c-1.4 0-2.5-1.1-2.5-2.5s1.1-2.5 2.5-2.5 2.5 1.1 2.5 2.5-1.1 2.5-2.5 2.5m7.5 0c-1.4 0-2.5-1.1-2.5-2.5s1.1-2.5 2.5-2.5 2.5 1.1 2.5 2.5-1.1 2.5-2.5 2.5" />
  18. <path d="m27.2 20.6l-2.3-2.8 2.3-2.8c0.3-0.4 0.2-0.9-0.2-1.2s-1-0.2-1.3 0.2l-2 2.4-2-2.4c-0.3-0.4-0.9-0.4-1.3-0.2-0.4 0.3-0.5 0.8-0.2 1.2l2.3 2.8-2.3 2.8c-0.3 0.4-0.2 0.9 0.2 1.2s1 0.2 1.3-0.2l2-2.4 2 2.4c0.3 0.4 0.9 0.4 1.3 0.2 0.4-0.3 0.4-0.8 0.2-1.2" />
  19. </g>
  20. </g>
  21. </svg>
  22. )
  23. this.provider = new Provider(uppy, {
  24. companionUrl: this.opts.companionUrl,
  25. companionHeaders: this.opts.companionHeaders,
  26. companionKeysParams: this.opts.companionKeysParams,
  27. companionCookiesRule: this.opts.companionCookiesRule,
  28. provider: 'box',
  29. pluginId: this.id,
  30. })
  31. this.defaultLocale = {
  32. strings: {
  33. pluginNameBox: 'Box',
  34. },
  35. }
  36. this.i18nInit()
  37. this.title = this.i18n('pluginNameBox')
  38. this.onFirstRender = this.onFirstRender.bind(this)
  39. this.render = this.render.bind(this)
  40. }
  41. install () {
  42. this.view = new ProviderViews(this, {
  43. provider: this.provider,
  44. })
  45. const { target } = this.opts
  46. if (target) {
  47. this.mount(target, this)
  48. }
  49. }
  50. uninstall () {
  51. this.view.tearDown()
  52. this.unmount()
  53. }
  54. onFirstRender () {
  55. return this.view.getFolder()
  56. }
  57. render (state) {
  58. return this.view.render(state)
  59. }
  60. }