Merge pull request #3294 from Budibase/fix/feature-flag-safari

Fix/feature flag safari
This commit is contained in:
Martin McKeaveney 2021-11-09 13:29:50 +01:00 committed by GitHub
commit bbf3b04d17
4 changed files with 52 additions and 29 deletions

View File

@ -44,6 +44,7 @@ const INITIAL_FRONTEND_STATE = {
state: false, state: false,
customThemes: false, customThemes: false,
devicePreview: false, devicePreview: false,
messagePassing: false,
}, },
currentFrontEndType: "none", currentFrontEndType: "none",
selectedScreenId: "", selectedScreenId: "",

View File

@ -96,7 +96,9 @@
// Initialise the app when mounted // Initialise the app when mounted
// Display preview immediately if the intelligent loading feature // Display preview immediately if the intelligent loading feature
// is not supported // is not supported
if ($store.clientFeatures.messagePassing) {
if (!loading) return if (!loading) return
}
if (!$store.clientFeatures.intelligentLoading) { if (!$store.clientFeatures.intelligentLoading) {
loading = false loading = false
@ -116,18 +118,37 @@
} }
onMount(() => { onMount(() => {
if ($store.clientFeatures.messagePassing) {
window.addEventListener("message", receiveMessage) 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 // Remove all iframe event listeners on component destroy
onDestroy(() => { onDestroy(() => {
if (iframe.contentWindow) { 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 handleBudibaseEvent = event => {
const { type, data } = event.data const { type, data } = event.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 })
} else if (type === "update-prop") { } else if (type === "update-prop") {
@ -164,7 +185,7 @@
} }
const handleKeydownEvent = event => { const handleKeydownEvent = event => {
const { key } = event.data const { key } = event.data || event
if ( if (
(key === "Delete" || key === "Backspace") && (key === "Delete" || key === "Backspace") &&
selectedComponentId && selectedComponentId &&

View File

@ -37,6 +37,10 @@
<p class="detail">{template?.category?.toUpperCase()}</p> <p class="detail">{template?.category?.toUpperCase()}</p>
</div> </div>
{/each} {/each}
</div>
{:catch err}
<h1 style="color:red">{err}</h1>
{/await}
<div class="template start-from-scratch" on:click={() => onSelect(null)}> <div class="template start-from-scratch" on:click={() => onSelect(null)}>
<div <div
class="background-icon" class="background-icon"
@ -60,10 +64,6 @@
<Heading size="XS">Import an app</Heading> <Heading size="XS">Import an app</Heading>
<p class="detail">BLANK</p> <p class="detail">BLANK</p>
</div> </div>
</div>
{:catch err}
<h1 style="color:red">{err}</h1>
{/await}
</Layout> </Layout>
<style> <style>

View File

@ -5,7 +5,8 @@
"deviceAwareness": true, "deviceAwareness": true,
"state": true, "state": true,
"customThemes": true, "customThemes": true,
"devicePreview": true "devicePreview": true,
"messagePassing": true
}, },
"layout": { "layout": {
"name": "Layout", "name": "Layout",