Pass preview type to client app so it can decide whether components are selectable
This commit is contained in:
parent
0e6c3d1aff
commit
c101715c0e
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { store, currentAsset } from "builderStore"
|
import { store, currentAsset, selectedComponent } from "builderStore"
|
||||||
import iframeTemplate from "./iframeTemplate"
|
import iframeTemplate from "./iframeTemplate"
|
||||||
import { Screen } from "builderStore/store/screenTemplates/utils/Screen"
|
import { Screen } from "builderStore/store/screenTemplates/utils/Screen"
|
||||||
import { FrontendTypes } from "../../../constants"
|
import { FrontendTypes } from "../../../constants"
|
||||||
|
@ -33,6 +33,7 @@
|
||||||
layout,
|
layout,
|
||||||
screen,
|
screen,
|
||||||
selectedComponentId,
|
selectedComponentId,
|
||||||
|
previewType: $store.currentFrontEndType,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Saving pages and screens to the DB causes them to have _revs.
|
// Saving pages and screens to the DB causes them to have _revs.
|
||||||
|
@ -54,17 +55,18 @@
|
||||||
// Refresh the preview when required
|
// Refresh the preview when required
|
||||||
$: refreshContent(strippedJson)
|
$: refreshContent(strippedJson)
|
||||||
|
|
||||||
// Initialise the app when mounted
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
// Initialise the app when mounted
|
||||||
iframe.contentWindow.addEventListener(
|
iframe.contentWindow.addEventListener(
|
||||||
"bb-ready",
|
"bb-ready",
|
||||||
() => {
|
() => refreshContent(strippedJson),
|
||||||
refreshContent(strippedJson)
|
{ once: true }
|
||||||
},
|
|
||||||
{
|
|
||||||
once: true,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Add listener to select components
|
||||||
|
iframe.contentWindow.addEventListener("bb-select-component", data => {
|
||||||
|
store.actions.components.select({ _id: data.detail })
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
*, *:before, *:after {
|
*, *:before, *:after {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
* {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src='/assets/budibase-client.js'></script>
|
<script src='/assets/budibase-client.js'></script>
|
||||||
<script>
|
<script>
|
||||||
|
@ -19,7 +22,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract data from message
|
// Extract data from message
|
||||||
const { selectedComponentId, layout, screen } = JSON.parse(event.data)
|
const { selectedComponentId, layout, screen, previewType } = JSON.parse(event.data)
|
||||||
|
|
||||||
// Set some flags so the app knows we're in the builder
|
// Set some flags so the app knows we're in the builder
|
||||||
window["##BUDIBASE_IN_BUILDER##"] = true
|
window["##BUDIBASE_IN_BUILDER##"] = true
|
||||||
|
@ -27,21 +30,13 @@
|
||||||
window["##BUDIBASE_PREVIEW_SCREEN##"] = screen
|
window["##BUDIBASE_PREVIEW_SCREEN##"] = screen
|
||||||
window["##BUDIBASE_SELECTED_COMPONENT_ID##"] = selectedComponentId
|
window["##BUDIBASE_SELECTED_COMPONENT_ID##"] = selectedComponentId
|
||||||
window["##BUDIBASE_PREVIEW_ID##"] = Math.random()
|
window["##BUDIBASE_PREVIEW_ID##"] = Math.random()
|
||||||
|
window["##BUDIBASE_PREVIEW_TYPE##"] = previewType
|
||||||
|
|
||||||
// Initialise app
|
// Initialise app
|
||||||
if (window.loadBudibase) {
|
if (window.loadBudibase) {
|
||||||
loadBudibase()
|
loadBudibase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore clicks
|
|
||||||
["click", "mousedown"].forEach(type => {
|
|
||||||
document.addEventListener(type, function(e) {
|
|
||||||
e.preventDefault()
|
|
||||||
e.stopPropagation()
|
|
||||||
return false
|
|
||||||
}, true)
|
|
||||||
})
|
|
||||||
|
|
||||||
window.addEventListener("message", receiveMessage)
|
window.addEventListener("message", receiveMessage)
|
||||||
window.dispatchEvent(new Event("bb-ready"))
|
window.dispatchEvent(new Event("bb-ready"))
|
||||||
|
|
|
@ -7,8 +7,20 @@ const createBuilderStore = () => {
|
||||||
screen: null,
|
screen: null,
|
||||||
selectedComponentId: null,
|
selectedComponentId: null,
|
||||||
previewId: null,
|
previewId: null,
|
||||||
|
previewType: null,
|
||||||
|
}
|
||||||
|
const store = writable(initialState)
|
||||||
|
const actions = {
|
||||||
|
selectComponent: id => {
|
||||||
|
window.dispatchEvent(
|
||||||
|
new CustomEvent("bb-select-component", { detail: id })
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...store,
|
||||||
|
actions,
|
||||||
}
|
}
|
||||||
return writable(initialState)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const builderStore = createBuilderStore()
|
export const builderStore = createBuilderStore()
|
||||||
|
|
Loading…
Reference in New Issue