From de163567f5b1cc9266b222b1af0a94da19149a4f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 28 Oct 2021 13:00:55 +0100 Subject: [PATCH] Move keyboard handling into client library so that component deletion via keyboard can reference client app state --- .../AppPreview/CurrentItemPreview.svelte | 14 -------- .../client/src/components/ClientApp.svelte | 6 ++-- .../components/preview/KeyboardManager.svelte | 35 +++++++++++++++++++ 3 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 packages/client/src/components/preview/KeyboardManager.svelte diff --git a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte index d2d67bf99f..94339e15e9 100644 --- a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte +++ b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte @@ -107,14 +107,12 @@ // Add listener for events sent by client library in preview iframe.contentWindow.addEventListener("bb-event", handleBudibaseEvent) - iframe.contentWindow.addEventListener("keydown", handleKeydownEvent) }) // Remove all iframe event listeners on component destroy onDestroy(() => { if (iframe.contentWindow) { iframe.contentWindow.removeEventListener("bb-event", handleBudibaseEvent) - iframe.contentWindow.removeEventListener("keydown", handleKeydownEvent) } }) @@ -155,18 +153,6 @@ } } - const handleKeydownEvent = event => { - if ( - (event.key === "Delete" || event.key === "Backspace") && - selectedComponentId && - ["input", "textarea"].indexOf( - iframe.contentWindow.document.activeElement?.tagName.toLowerCase() - ) === -1 - ) { - confirmDeleteComponent(selectedComponentId) - } - } - const confirmDeleteComponent = componentId => { idToDelete = componentId confirmDeleteDialog.show() diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index cc16570992..119a26800f 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -1,5 +1,5 @@