diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 9110aa1430..97c4f58604 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -44,6 +44,7 @@ const INITIAL_FRONTEND_STATE = { state: false, customThemes: false, devicePreview: false, + messagePassing: false, }, currentFrontEndType: "none", selectedScreenId: "", diff --git a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte index 99de9f7942..ac5e7ef48d 100644 --- a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte +++ b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte @@ -96,7 +96,9 @@ // Initialise the app when mounted // Display preview immediately if the intelligent loading feature // is not supported - if (!loading) return + if ($store.clientFeatures.messagePassing) { + if (!loading) return + } if (!$store.clientFeatures.intelligentLoading) { loading = false @@ -116,18 +118,37 @@ } onMount(() => { - window.addEventListener("message", receiveMessage) + if ($store.clientFeatures.messagePassing) { + window.addEventListener("message", receiveMessage) + } else { + // Legacy - remove in later versions of BB + iframe.contentWindow.addEventListener("ready", () => { + receiveMessage({ data: { type: MessageTypes.READY }}) + }, { once: true }) + iframe.contentWindow.addEventListener("error", event => { + receiveMessage({ data: { type: MessageTypes.ERROR, error: event.detail }}) + }, { once: true }) + // 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) { - window.removeEventListener("message", receiveMessage) // + if ($store.clientFeatures.messagePassing) { + window.removeEventListener("message", receiveMessage) + } else { + // Legacy - remove in later versions of BB + iframe.contentWindow.removeEventListener("bb-event", handleBudibaseEvent) + iframe.contentWindow.removeEventListener("keydown", handleKeydownEvent) + } } }) const handleBudibaseEvent = event => { - const { type, data } = event.data + const { type, data } = event.data || event.detail if (type === "select-component" && data.id) { store.actions.components.select({ _id: data.id }) } else if (type === "update-prop") { @@ -164,7 +185,7 @@ } const handleKeydownEvent = event => { - const { key } = event.data + const { key } = event.data || event if ( (key === "Delete" || key === "Backspace") && selectedComponentId && diff --git a/packages/builder/src/components/start/TemplateList.svelte b/packages/builder/src/components/start/TemplateList.svelte index 7c7eb1f8f9..12f8725bd3 100644 --- a/packages/builder/src/components/start/TemplateList.svelte +++ b/packages/builder/src/components/start/TemplateList.svelte @@ -37,33 +37,33 @@

{template?.category?.toUpperCase()}

{/each} -
onSelect(null)}> -
- -
- Start from scratch -

BLANK

-
-
onSelect(null, { useImport: true })} - > -
- -
- Import an app -

BLANK

-
{:catch err}

{err}

{/await} +
onSelect(null)}> +
+ +
+ Start from scratch +

BLANK

+
+
onSelect(null, { useImport: true })} + > +
+ +
+ Import an app +

BLANK

+