Plugin.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import yo from 'yo-yo'
  2. /**
  3. * Boilerplate that all Plugins share - and should not be used
  4. * directly. It also shows which methods final plugins should implement/override,
  5. * this deciding on structure.
  6. *
  7. * @param {object} main Uppy core object
  8. * @param {object} object with plugin options
  9. * @return {array | string} files or success/fail message
  10. */
  11. export default class Plugin {
  12. constructor (core, opts) {
  13. this.core = core
  14. this.opts = opts
  15. this.type = 'none'
  16. this.name = this.constructor.name
  17. }
  18. update () {
  19. if (typeof this.el === 'undefined') {
  20. return
  21. }
  22. const newEl = this.render(this.core.state)
  23. yo.update(this.el, newEl)
  24. }
  25. /**
  26. * Check if supplied `target` is a `string` or an `object`.
  27. * If it’s an object — target is a plugin, and we search `plugins`
  28. * for a plugin with same name and return its target.
  29. *
  30. * @param {String|Object} target
  31. *
  32. */
  33. getTarget (target, caller, el, render) {
  34. if (typeof target === 'string') {
  35. this.core.log(`Installing ${caller.name} to ${target}`)
  36. // clear everything inside the target selector
  37. // if (replaceTargetContent) {
  38. // document.querySelector(target).innerHTML = ''
  39. // }
  40. document.querySelector(target).appendChild(el)
  41. return target
  42. } else {
  43. this.core.log(`Installing ${caller.name} to ${target.name}`)
  44. let targetPlugin = this.core.getPlugin(target.name)
  45. let selectorTarget = targetPlugin.addTarget(caller, render)
  46. return selectorTarget
  47. }
  48. }
  49. focus () {
  50. return
  51. }
  52. install () {
  53. return
  54. }
  55. run () {
  56. return
  57. }
  58. }