fix(desktop): prevent navigation on file drops (#5176)
This commit is contained in:
parent
929bdccc25
commit
5ece4821af
1 changed files with 80 additions and 1 deletions
|
|
@ -126,7 +126,86 @@ async function initApp() {
|
|||
headerPaddingTop.value = "0px"
|
||||
headerPaddingLeft.value = "80px"
|
||||
|
||||
// Add backspace prevention for non-text inputs
|
||||
const ALLOWED_DROP_SELECTORS = [
|
||||
'[draggable="true"]',
|
||||
".draggable-content",
|
||||
".draggable-handle",
|
||||
".sortable-ghost",
|
||||
".sortable-drag",
|
||||
".sortable-chosen",
|
||||
".vue-draggable",
|
||||
|
||||
'input[type="file"]',
|
||||
'label[for*="attachment"]',
|
||||
".file-chips-container",
|
||||
".file-chips-wrapper",
|
||||
|
||||
".cm-editor",
|
||||
".cm-content",
|
||||
".cm-scroller",
|
||||
".ace_editor",
|
||||
|
||||
"[data-allow-drop]",
|
||||
".drop-zone",
|
||||
|
||||
"[ondrop]",
|
||||
"[data-drop-handler]",
|
||||
].join(", ")
|
||||
|
||||
const isAllowedDropTarget = (target: EventTarget | null): boolean => {
|
||||
if (!target || !(target instanceof HTMLElement)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (target.closest(ALLOWED_DROP_SELECTORS)) {
|
||||
return true
|
||||
}
|
||||
|
||||
const element = target as any
|
||||
if (element._vei?.onDrop || element.__vueListeners__?.drop) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
document.addEventListener(
|
||||
"drop",
|
||||
(e) => {
|
||||
if (!isAllowedDropTarget(e.target)) {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
}
|
||||
},
|
||||
false
|
||||
)
|
||||
|
||||
document.addEventListener(
|
||||
"dragover",
|
||||
(e) => {
|
||||
e.preventDefault()
|
||||
},
|
||||
false
|
||||
)
|
||||
|
||||
document.addEventListener(
|
||||
"dragstart",
|
||||
(e) => {
|
||||
if (!e.target || !(e.target instanceof HTMLElement)) {
|
||||
return
|
||||
}
|
||||
|
||||
const target = e.target as HTMLElement
|
||||
if (
|
||||
!target.draggable &&
|
||||
!target.closest('[draggable="true"], .draggable-content')
|
||||
) {
|
||||
e.preventDefault()
|
||||
}
|
||||
},
|
||||
false
|
||||
)
|
||||
|
||||
window.addEventListener(
|
||||
"keydown",
|
||||
function (e) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue