index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const { Plugin } = 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 Facebook extends Plugin {
  6. static VERSION = require('../package.json').version
  7. constructor (uppy, opts) {
  8. super(uppy, opts)
  9. this.id = this.opts.id || 'Facebook'
  10. Provider.initPlugin(this, opts)
  11. this.title = this.opts.title || 'Facebook'
  12. this.icon = () => (
  13. <svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
  14. <g fill="none" fill-rule="evenodd">
  15. <rect width="32" height="32" rx="16" fill="#3C5A99" />
  16. <path d="M17.842 26v-8.667h2.653l.398-3.377h-3.051v-2.157c0-.978.248-1.644 1.527-1.644H21V7.132A19.914 19.914 0 0 0 18.623 7c-2.352 0-3.963 1.574-3.963 4.465v2.49H12v3.378h2.66V26h3.182z" fill="#FFF" fill-rule="nonzero" />
  17. </g>
  18. </svg>
  19. )
  20. this.provider = new Provider(uppy, {
  21. companionUrl: this.opts.companionUrl,
  22. companionHeaders: this.opts.companionHeaders || this.opts.serverHeaders,
  23. companionCookiesRule: this.opts.companionCookiesRule,
  24. provider: 'facebook',
  25. pluginId: this.id
  26. })
  27. this.onFirstRender = this.onFirstRender.bind(this)
  28. this.render = this.render.bind(this)
  29. }
  30. install () {
  31. this.view = new ProviderViews(this, {
  32. provider: this.provider
  33. })
  34. const target = this.opts.target
  35. if (target) {
  36. this.mount(target, this)
  37. }
  38. }
  39. uninstall () {
  40. this.view.tearDown()
  41. this.unmount()
  42. }
  43. onFirstRender () {
  44. return this.view.getFolder()
  45. }
  46. render (state) {
  47. const viewOptions = {}
  48. if (this.getPluginState().files.length && !this.getPluginState().folders.length) {
  49. viewOptions.viewType = 'grid'
  50. viewOptions.showFilter = false
  51. viewOptions.showTitles = false
  52. }
  53. return this.view.render(state, viewOptions)
  54. }
  55. }