adding flags for messagePassing

This commit is contained in:
Martin McKeaveney 2021-11-09 12:15:29 +01:00
parent 3f71768146
commit cb459bc877
3 changed files with 28 additions and 5 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) {
if ($store.clientFeatures.messagePassing) {
window.removeEventListener("message", receiveMessage) // 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

@ -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",