Use server-provided client lib URL in iframe preview

This commit is contained in:
Andrew Kingston 2021-04-01 14:10:49 +01:00
parent 5ebb31e472
commit dab183cc8a
3 changed files with 11 additions and 3 deletions

View File

@ -42,6 +42,7 @@ const INITIAL_FRONTEND_STATE = {
libraries: null, libraries: null,
appId: "", appId: "",
routes: {}, routes: {},
clientLibPath: "",
} }
export const getFrontendStore = () => { export const getFrontendStore = () => {
@ -49,7 +50,7 @@ export const getFrontendStore = () => {
store.actions = { store.actions = {
initialise: async pkg => { initialise: async pkg => {
const { layouts, screens, application } = pkg const { layouts, screens, application, clientLibPath } = pkg
const components = await fetchComponentLibDefinitions(application._id) const components = await fetchComponentLibDefinitions(application._id)
store.update(state => ({ store.update(state => ({
...state, ...state,
@ -63,6 +64,7 @@ export const getFrontendStore = () => {
screens, screens,
hasAppPackage: true, hasAppPackage: true,
appInstance: application.instance, appInstance: application.instance,
clientLibPath,
})) }))
await hostingStore.actions.fetch() await hostingStore.actions.fetch()

View File

@ -18,6 +18,12 @@
.instanceName("Content Placeholder") .instanceName("Content Placeholder")
.json() .json()
// Construct iframe template
$: template = iframeTemplate.replace(
/\{\{ CLIENT_LIB_PATH }}/,
$store.clientLibPath
)
// Extract data to pass to the iframe // Extract data to pass to the iframe
$: { $: {
if ($store.currentFrontEndType === FrontendTypes.LAYOUT) { if ($store.currentFrontEndType === FrontendTypes.LAYOUT) {
@ -76,7 +82,7 @@
style="height: 100%; width: 100%" style="height: 100%; width: 100%"
title="componentPreview" title="componentPreview"
bind:this={iframe} bind:this={iframe}
srcdoc={iframeTemplate} /> srcdoc={template} />
</div> </div>
<style> <style>

View File

@ -13,7 +13,7 @@ export default `
box-sizing: border-box; box-sizing: border-box;
} }
</style> </style>
<script src='/assets/budibase-client.js'></script> <script src='{{ CLIENT_LIB_PATH }}'></script>
<script> <script>
function receiveMessage(event) { function receiveMessage(event) {
if (!event.data) { if (!event.data) {