addDashboardPlugin.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const Dashboard = require('@uppy/dashboard')
  2. const has = require('@uppy/utils/lib/hasProperty')
  3. const dashboardOptionNames = [
  4. 'metaFields',
  5. 'width',
  6. 'height',
  7. 'thumbnailWidth',
  8. 'showLinkToFileUploadResult',
  9. 'showProgressDetails',
  10. 'hideRetryButton',
  11. 'hidePauseResumeCancelButtons',
  12. 'hideUploadButton',
  13. 'hideProgressAfterFinish',
  14. 'note',
  15. 'disableStatusBar',
  16. 'disableInformer',
  17. 'disableThumbnailGenerator',
  18. 'showSelectedFiles',
  19. 'proudlyDisplayPoweredByUppy',
  20. 'theme'
  21. ]
  22. const modalDashboardOptionNames = [
  23. 'trigger',
  24. 'closeModalOnClickOutside',
  25. 'closeAfterFinish',
  26. 'disablePageScrollWhenModalOpen',
  27. 'animateOpenClose',
  28. 'onRequestCloseModal',
  29. 'browserBackButtonClose'
  30. ]
  31. function addDashboardPlugin (uppy, opts, overrideOpts) {
  32. const dashboardOpts = {}
  33. dashboardOptionNames.forEach((key) => {
  34. if (has(opts, key)) {
  35. dashboardOpts[key] = opts[key]
  36. }
  37. })
  38. const inline = overrideOpts.inline == null ? dashboardOpts.inline : overrideOpts.inline
  39. if (!inline) {
  40. modalDashboardOptionNames.forEach((key) => {
  41. if (has(opts, key)) {
  42. dashboardOpts[key] = opts[key]
  43. }
  44. })
  45. }
  46. uppy.use(Dashboard, {
  47. ...dashboardOpts,
  48. ...overrideOpts
  49. })
  50. }
  51. module.exports = addDashboardPlugin