|
@@ -143,28 +143,28 @@ module.exports = class Dashboard extends Plugin {
|
|
|
this.removeTarget = this.removeTarget.bind(this)
|
|
|
this.hideAllPanels = this.hideAllPanels.bind(this)
|
|
|
this.showPanel = this.showPanel.bind(this)
|
|
|
- this.handlePopState = this.handlePopState.bind(this)
|
|
|
+ this.toggleFileCard = this.toggleFileCard.bind(this)
|
|
|
+ this.toggleAddFilesPanel = this.toggleAddFilesPanel.bind(this)
|
|
|
|
|
|
this.initEvents = this.initEvents.bind(this)
|
|
|
+ this.handlePopState = this.handlePopState.bind(this)
|
|
|
this.handleKeyDownInModal = this.handleKeyDownInModal.bind(this)
|
|
|
this.handleKeyDownInInline = this.handleKeyDownInInline.bind(this)
|
|
|
- this.handleFileAdded = this.handleFileAdded.bind(this)
|
|
|
this.handleComplete = this.handleComplete.bind(this)
|
|
|
this.handleClickOutside = this.handleClickOutside.bind(this)
|
|
|
- this.toggleFileCard = this.toggleFileCard.bind(this)
|
|
|
- this.toggleAddFilesPanel = this.toggleAddFilesPanel.bind(this)
|
|
|
this.handlePaste = this.handlePaste.bind(this)
|
|
|
this.handlePasteOnBody = this.handlePasteOnBody.bind(this)
|
|
|
this.handleInputChange = this.handleInputChange.bind(this)
|
|
|
- this.render = this.render.bind(this)
|
|
|
- this.install = this.install.bind(this)
|
|
|
-
|
|
|
this.handleDragOver = this.handleDragOver.bind(this)
|
|
|
this.handleDragLeave = this.handleDragLeave.bind(this)
|
|
|
this.handleDrop = this.handleDrop.bind(this)
|
|
|
+
|
|
|
this.superFocusOnEachUpdate = this.superFocusOnEachUpdate.bind(this)
|
|
|
this.recordIfFocusedOnUppyRecently = this.recordIfFocusedOnUppyRecently.bind(this)
|
|
|
|
|
|
+ this.render = this.render.bind(this)
|
|
|
+ this.install = this.install.bind(this)
|
|
|
+
|
|
|
this.superFocus = createSuperFocus()
|
|
|
this.ifFocusedOnUppyRecently = false
|
|
|
|
|
@@ -234,41 +234,6 @@ module.exports = class Dashboard extends Plugin {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- requestCloseModal () {
|
|
|
- if (this.opts.onRequestCloseModal) {
|
|
|
- return this.opts.onRequestCloseModal()
|
|
|
- }
|
|
|
- return this.closeModal()
|
|
|
- }
|
|
|
-
|
|
|
- updateBrowserHistory () {
|
|
|
-
|
|
|
- if (!history.state || !history.state[this.modalName]) {
|
|
|
-
|
|
|
- history.pushState({
|
|
|
- ...history.state,
|
|
|
- [this.modalName]: true
|
|
|
- }, '')
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- window.addEventListener('popstate', this.handlePopState, false)
|
|
|
- }
|
|
|
-
|
|
|
- handlePopState (event) {
|
|
|
-
|
|
|
- if (this.isModalOpen() && (!event.state || !event.state[this.modalName])) {
|
|
|
- this.closeModal({ manualClose: false })
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (!this.isModalOpen() && event.state && event.state[this.modalName]) {
|
|
|
- history.go(-1)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
openModal () {
|
|
|
const { promise, resolve } = createPromise()
|
|
|
|
|
@@ -303,6 +268,8 @@ module.exports = class Dashboard extends Plugin {
|
|
|
|
|
|
document.addEventListener('keydown', this.handleKeyDownInModal)
|
|
|
|
|
|
+ this.uppy.emit('dashboard:modal-open')
|
|
|
+
|
|
|
return promise
|
|
|
}
|
|
|
|
|
@@ -364,6 +331,8 @@ module.exports = class Dashboard extends Plugin {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ this.uppy.emit('dashboard:modal-closed')
|
|
|
+
|
|
|
return promise
|
|
|
}
|
|
|
|
|
@@ -371,40 +340,25 @@ module.exports = class Dashboard extends Plugin {
|
|
|
return !this.getPluginState().isHidden || false
|
|
|
}
|
|
|
|
|
|
- handleKeyDownInModal (event) {
|
|
|
-
|
|
|
- if (event.keyCode === ESC_KEY) this.requestCloseModal(event)
|
|
|
-
|
|
|
- if (event.keyCode === TAB_KEY) trapFocus.forModal(event, this.getPluginState().activeOverlayType, this.el)
|
|
|
- }
|
|
|
-
|
|
|
- handleClickOutside () {
|
|
|
- if (this.opts.closeModalOnClickOutside) this.requestCloseModal()
|
|
|
+ requestCloseModal () {
|
|
|
+ if (this.opts.onRequestCloseModal) {
|
|
|
+ return this.opts.onRequestCloseModal()
|
|
|
+ }
|
|
|
+ return this.closeModal()
|
|
|
}
|
|
|
|
|
|
- handlePaste (event) {
|
|
|
-
|
|
|
- this.uppy.iteratePlugins((plugin) => {
|
|
|
- if (plugin.type === 'acquirer') {
|
|
|
-
|
|
|
- plugin.handleRootPaste && plugin.handleRootPaste(event)
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
- const files = toArray(event.clipboardData.files)
|
|
|
- files.forEach((file) => {
|
|
|
- this.uppy.log('[Dashboard] File pasted')
|
|
|
- this.addFile(file)
|
|
|
+ toggleFileCard (fileId) {
|
|
|
+ this.setPluginState({
|
|
|
+ fileCardFor: fileId || null,
|
|
|
+ activeOverlayType: fileId ? 'FileCard' : null
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- handleInputChange (event) {
|
|
|
- event.preventDefault()
|
|
|
- const files = toArray(event.target.files)
|
|
|
- files.forEach((file) =>
|
|
|
- this.addFile(file)
|
|
|
- )
|
|
|
+ toggleAddFilesPanel (show) {
|
|
|
+ this.setPluginState({
|
|
|
+ showAddFilesPanel: show,
|
|
|
+ activeOverlayType: show ? 'AddFiles' : null
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
addFile (file) {
|
|
@@ -467,6 +421,83 @@ module.exports = class Dashboard extends Plugin {
|
|
|
clearTimeout(this.makeDashboardInsidesVisibleAnywayTimeout)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ recordIfFocusedOnUppyRecently (event) {
|
|
|
+ if (this.el.contains(event.target)) {
|
|
|
+ this.ifFocusedOnUppyRecently = true
|
|
|
+ } else {
|
|
|
+ this.ifFocusedOnUppyRecently = false
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.superFocus.cancel()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateBrowserHistory () {
|
|
|
+
|
|
|
+ if (!history.state || !history.state[this.modalName]) {
|
|
|
+
|
|
|
+ history.pushState({
|
|
|
+ ...history.state,
|
|
|
+ [this.modalName]: true
|
|
|
+ }, '')
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ window.addEventListener('popstate', this.handlePopState, false)
|
|
|
+ }
|
|
|
+
|
|
|
+ handlePopState (event) {
|
|
|
+
|
|
|
+ if (this.isModalOpen() && (!event.state || !event.state[this.modalName])) {
|
|
|
+ this.closeModal({ manualClose: false })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!this.isModalOpen() && event.state && event.state[this.modalName]) {
|
|
|
+ history.go(-1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ handleKeyDownInModal (event) {
|
|
|
+
|
|
|
+ if (event.keyCode === ESC_KEY) this.requestCloseModal(event)
|
|
|
+
|
|
|
+ if (event.keyCode === TAB_KEY) trapFocus.forModal(event, this.getPluginState().activeOverlayType, this.el)
|
|
|
+ }
|
|
|
+
|
|
|
+ handleClickOutside () {
|
|
|
+ if (this.opts.closeModalOnClickOutside) this.requestCloseModal()
|
|
|
+ }
|
|
|
+
|
|
|
+ handlePaste (event) {
|
|
|
+
|
|
|
+ this.uppy.iteratePlugins((plugin) => {
|
|
|
+ if (plugin.type === 'acquirer') {
|
|
|
+
|
|
|
+ plugin.handleRootPaste && plugin.handleRootPaste(event)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ const files = toArray(event.clipboardData.files)
|
|
|
+ files.forEach((file) => {
|
|
|
+ this.uppy.log('[Dashboard] File pasted')
|
|
|
+ this.addFile(file)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ handleInputChange (event) {
|
|
|
+ event.preventDefault()
|
|
|
+ const files = toArray(event.target.files)
|
|
|
+ files.forEach((file) =>
|
|
|
+ this.addFile(file)
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
handleDragOver (event) {
|
|
|
event.preventDefault()
|
|
|
event.stopPropagation()
|
|
@@ -516,6 +547,31 @@ module.exports = class Dashboard extends Plugin {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ handleKeyDownInInline (event) {
|
|
|
+
|
|
|
+ if (event.keyCode === TAB_KEY) trapFocus.forInline(event, this.getPluginState().activeOverlayType, this.el)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ handlePasteOnBody (event) {
|
|
|
+ const isFocusInOverlay = this.el.contains(document.activeElement)
|
|
|
+ if (isFocusInOverlay) {
|
|
|
+ this.handlePaste(event)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ handleComplete ({ failed, uploadID }) {
|
|
|
+ if (this.opts.closeAfterFinish && failed.length === 0) {
|
|
|
+
|
|
|
+ this.requestCloseModal()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
initEvents () {
|
|
|
|
|
|
const showModalTrigger = findAllDOMElements(this.opts.trigger)
|
|
@@ -531,7 +587,8 @@ module.exports = class Dashboard extends Plugin {
|
|
|
document.addEventListener('paste', this.handlePasteOnBody)
|
|
|
|
|
|
this.uppy.on('plugin-remove', this.removeTarget)
|
|
|
- this.uppy.on('file-added', this.handleFileAdded)
|
|
|
+ this.uppy.on('file-added', this.hideAllPanels)
|
|
|
+ this.uppy.on('dashboard:modal-closed', this.hideAllPanels)
|
|
|
this.uppy.on('complete', this.handleComplete)
|
|
|
|
|
|
|
|
@@ -544,48 +601,6 @@ module.exports = class Dashboard extends Plugin {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- handleKeyDownInInline (event) {
|
|
|
-
|
|
|
- if (event.keyCode === TAB_KEY) trapFocus.forInline(event, this.getPluginState().activeOverlayType, this.el)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- recordIfFocusedOnUppyRecently (event) {
|
|
|
- if (this.el.contains(event.target)) {
|
|
|
- this.ifFocusedOnUppyRecently = true
|
|
|
- } else {
|
|
|
- this.ifFocusedOnUppyRecently = false
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- this.superFocus.cancel()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- handlePasteOnBody (event) {
|
|
|
- const isFocusInOverlay = this.el.contains(document.activeElement)
|
|
|
- if (isFocusInOverlay) {
|
|
|
- this.handlePaste(event)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- handleFileAdded () {
|
|
|
- this.hideAllPanels()
|
|
|
- }
|
|
|
-
|
|
|
- handleComplete ({ failed, uploadID }) {
|
|
|
- if (this.opts.closeAfterFinish && failed.length === 0) {
|
|
|
-
|
|
|
- this.requestCloseModal()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
removeEvents () {
|
|
|
const showModalTrigger = findAllDOMElements(this.opts.trigger)
|
|
|
if (!this.opts.inline && showModalTrigger) {
|
|
@@ -597,7 +612,8 @@ module.exports = class Dashboard extends Plugin {
|
|
|
|
|
|
window.removeEventListener('popstate', this.handlePopState, false)
|
|
|
this.uppy.off('plugin-remove', this.removeTarget)
|
|
|
- this.uppy.off('file-added', this.handleFileAdded)
|
|
|
+ this.uppy.off('file-added', this.hideAllPanels)
|
|
|
+ this.uppy.off('dashboard:modal-closed', this.hideAllPanels)
|
|
|
this.uppy.off('complete', this.handleComplete)
|
|
|
|
|
|
document.removeEventListener('focus', this.recordIfFocusedOnUppyRecently)
|
|
@@ -608,20 +624,6 @@ module.exports = class Dashboard extends Plugin {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- toggleFileCard (fileId) {
|
|
|
- this.setPluginState({
|
|
|
- fileCardFor: fileId || null,
|
|
|
- activeOverlayType: fileId ? 'FileCard' : null
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- toggleAddFilesPanel (show) {
|
|
|
- this.setPluginState({
|
|
|
- showAddFilesPanel: show,
|
|
|
- activeOverlayType: show ? 'AddFiles' : null
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
superFocusOnEachUpdate () {
|
|
|
const isFocusInUppy = this.el.contains(document.activeElement)
|
|
|
|