only show delete confirmation when no input or textarea is focussed
This commit is contained in:
parent
7173be59c6
commit
378760074f
|
@ -95,8 +95,18 @@
|
||||||
{ once: true }
|
{ once: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add listener for events sent by cliebt library in preview
|
// Add listener for events sent by client library in preview
|
||||||
iframe.contentWindow.addEventListener("bb-event", event => {
|
iframe.contentWindow.addEventListener("bb-event", handleBudibaseEvent)
|
||||||
|
iframe.contentWindow.addEventListener("keydown", handleKeydownEvent)
|
||||||
|
})
|
||||||
|
|
||||||
|
// remove all iframe event listeners on component destroy
|
||||||
|
onDestroy(() => {
|
||||||
|
iframe.contentWindow.removeEventListener("bb-event", handleBudibaseEvent)
|
||||||
|
iframe.contentWindow.removeEventListener("keydown", handleKeydownEvent)
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleBudibaseEvent = event => {
|
||||||
const { type, data } = event.detail
|
const { type, data } = event.detail
|
||||||
if (type === "select-component" && data.id) {
|
if (type === "select-component" && data.id) {
|
||||||
store.actions.components.select({ _id: data.id })
|
store.actions.components.select({ _id: data.id })
|
||||||
|
@ -111,22 +121,15 @@
|
||||||
} else {
|
} else {
|
||||||
console.warning(`Client sent unknown event type: ${type}`)
|
console.warning(`Client sent unknown event type: ${type}`)
|
||||||
}
|
}
|
||||||
})
|
};
|
||||||
|
|
||||||
iframe.contentWindow.addEventListener("keydown", event => {
|
const handleKeydownEvent = event => {
|
||||||
if ((event.key === "Delete" || event.key === "Backspace") && selectedComponentId) {
|
if ((event.key === "Delete" || event.key === "Backspace") &&
|
||||||
|
selectedComponentId &&
|
||||||
|
['input', 'textarea'].indexOf(iframe.contentWindow.document.activeElement?.tagName.toLowerCase()) === -1) {
|
||||||
confirmDeleteComponent(selectedComponentId);
|
confirmDeleteComponent(selectedComponentId);
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
})
|
|
||||||
|
|
||||||
// remove all iframe event listeners on component destroy
|
|
||||||
onDestroy(() => {
|
|
||||||
iframe.contentWindow.removeEventListener("ready")
|
|
||||||
iframe.contentWindow.removeEventListener("error")
|
|
||||||
iframe.contentWindow.removeEventListener("bb-event")
|
|
||||||
iframe.contentWindow.removeEventListener("keydown")
|
|
||||||
})
|
|
||||||
|
|
||||||
const confirmDeleteComponent = (componentId) => {
|
const confirmDeleteComponent = (componentId) => {
|
||||||
idToDelete = componentId
|
idToDelete = componentId
|
||||||
|
|
Loading…
Reference in New Issue