mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-22 17:58:05 +00:00
wip
This commit is contained in:
parent
39bfa4fe77
commit
9564f39895
4 changed files with 36 additions and 4 deletions
|
|
@ -31,6 +31,15 @@ const FOCUSABLE_ELEMENTS = [
|
|||
const TAB_KEY = 9
|
||||
const ESC_KEY = 27
|
||||
|
||||
function createPromise () {
|
||||
const o = {}
|
||||
o.promise = new Promise((resolve, reject) => {
|
||||
o.resolve = resolve
|
||||
o.reject = reject
|
||||
})
|
||||
return o
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard UI with previews, metadata editing, tabs for various services and more
|
||||
*/
|
||||
|
|
@ -298,6 +307,7 @@ module.exports = class Dashboard extends Plugin {
|
|||
}
|
||||
|
||||
openModal () {
|
||||
const { promise, resolve } = createPromise()
|
||||
// save scroll position
|
||||
this.savedScrollPosition = window.scrollY
|
||||
// save active element, so we can restore focus when modal is closed
|
||||
|
|
@ -313,12 +323,14 @@ module.exports = class Dashboard extends Plugin {
|
|||
isHidden: false
|
||||
})
|
||||
this.el.removeEventListener('animationend', handler, false)
|
||||
resolve()
|
||||
}
|
||||
this.el.addEventListener('animationend', handler, false)
|
||||
} else {
|
||||
this.setPluginState({
|
||||
isHidden: false
|
||||
})
|
||||
resolve()
|
||||
}
|
||||
|
||||
if (this.opts.browserBackButtonClose) {
|
||||
|
|
@ -330,6 +342,8 @@ module.exports = class Dashboard extends Plugin {
|
|||
|
||||
// this.rerender(this.uppy.getState())
|
||||
this.setFocusToBrowse()
|
||||
|
||||
return promise
|
||||
}
|
||||
|
||||
closeModal (opts = {}) {
|
||||
|
|
@ -337,6 +351,8 @@ module.exports = class Dashboard extends Plugin {
|
|||
manualClose = true // Whether the modal is being closed by the user (`true`) or by other means (e.g. browser back button)
|
||||
} = opts
|
||||
|
||||
const { promise, resolve } = createPromise()
|
||||
|
||||
if (this.opts.disablePageScrollWhenModalOpen) {
|
||||
document.body.classList.remove('uppy-Dashboard-isFixed')
|
||||
}
|
||||
|
|
@ -351,12 +367,14 @@ module.exports = class Dashboard extends Plugin {
|
|||
isClosing: false
|
||||
})
|
||||
this.el.removeEventListener('animationend', handler, false)
|
||||
resolve()
|
||||
}
|
||||
this.el.addEventListener('animationend', handler, false)
|
||||
} else {
|
||||
this.setPluginState({
|
||||
isHidden: true
|
||||
})
|
||||
resolve()
|
||||
}
|
||||
|
||||
// handle ESC and TAB keys in modal dialog
|
||||
|
|
@ -373,6 +391,8 @@ module.exports = class Dashboard extends Plugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return promise
|
||||
}
|
||||
|
||||
isModalOpen () {
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class TransloaditFormResult extends Uppy.Plugin {
|
|||
|
||||
function form (target, opts) {
|
||||
const uppy = Uppy({
|
||||
allowMultipleUploads: false,
|
||||
restrictions: opts.restrictions
|
||||
})
|
||||
addTransloaditPlugin(uppy, opts)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,21 @@ const Dashboard = require('@uppy/dashboard')
|
|||
const addTransloaditPlugin = require('./addTransloaditPlugin')
|
||||
|
||||
function modal (target, opts) {
|
||||
const uppy = Uppy({})
|
||||
const uppy = Uppy({
|
||||
allowMultipleUploads: false
|
||||
})
|
||||
addTransloaditPlugin(uppy, opts)
|
||||
uppy.use(Dashboard, {
|
||||
target,
|
||||
autoClose: true
|
||||
})
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
}).then(() => {
|
||||
return uppy.upload()
|
||||
uppy.on('complete', resolve)
|
||||
uppy.getPlugin('Dashboard').openModal()
|
||||
}).then((result) => {
|
||||
return uppy.getPlugin('Dashboard').closeModal()
|
||||
.then(() => result)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ const Uppy = require('@uppy/core')
|
|||
const addTransloaditPlugin = require('./addTransloaditPlugin')
|
||||
|
||||
function upload (files, opts) {
|
||||
const uppy = Uppy({})
|
||||
const uppy = Uppy({
|
||||
allowMultipleUploads: false
|
||||
})
|
||||
|
||||
addTransloaditPlugin(uppy, opts)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue