status-bar.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import StatusBarPlugin from '@uppy/status-bar'
  2. import { shallowEqualObjects } from 'shallow-equal'
  3. // Cross compatibility dependencies
  4. import * as Vue from 'vue'
  5. import { isVue2 } from './utils.js'
  6. export default {
  7. data () {
  8. return {
  9. plugin: {},
  10. }
  11. },
  12. props: {
  13. uppy: {
  14. required: true,
  15. },
  16. props: {
  17. type: Object,
  18. },
  19. },
  20. mounted () {
  21. this.installPlugin()
  22. },
  23. methods: {
  24. installPlugin () {
  25. const { uppy } = this
  26. const options = {
  27. id: 'vue:StatusBar',
  28. ...this.props,
  29. target: this.$refs.container,
  30. }
  31. uppy.use(StatusBarPlugin, options)
  32. this.plugin = uppy.getPlugin(options.id)
  33. },
  34. uninstallPlugin (uppy) {
  35. uppy.removePlugin(this.plugin)
  36. },
  37. },
  38. beforeDestroy () {
  39. this.uninstallPlugin(this.uppy)
  40. },
  41. beforeUnmount () {
  42. this.uninstallPlugin(this.uppy)
  43. },
  44. watch: {
  45. uppy (current, old) {
  46. if (old !== current) {
  47. this.uninstallPlugin(old)
  48. this.installPlugin()
  49. }
  50. },
  51. props (current, old) {
  52. if (!shallowEqualObjects(current, old)) {
  53. this.plugin.setOptions({ ...current })
  54. }
  55. },
  56. },
  57. render (...args) {
  58. // Hack to allow support for Vue 2 and 3
  59. if (isVue2(...args)) {
  60. // If it's first argument is a function, then it's a Vue 2 App
  61. const [createElement] = args
  62. return createElement('div', {
  63. ref: 'container',
  64. })
  65. }
  66. // Other wise, we import the `h` function from the Vue package (in Vue 3 fashion)
  67. return Vue.h('div', {
  68. ref: 'container',
  69. })
  70. },
  71. }