Insert script tags for custom component bundles to app preview

This commit is contained in:
Andrew Kingston 2022-08-11 15:27:09 +01:00
parent e6303fb4ec
commit 152e8271da
2 changed files with 19 additions and 7 deletions

View File

@ -41,10 +41,23 @@
}
// Construct iframe template
$: template = iframeTemplate.replace(
/\{\{ CLIENT_LIB_PATH }}/,
$store.clientLibPath
)
$: pluginLinks = generatePluginLinks($store.usedPlugins)
$: template = iframeTemplate
.replace(/\{\{ CLIENT_LIB_PATH }}/, $store.clientLibPath)
.replace(/\{\{ PLUGINS }}/, pluginLinks)
const generatePluginLinks = plugins => {
if (!plugins?.length) {
return ""
}
return plugins
.map(plugin => {
// Split up like this as otherwise parsing fails because the script
// tags confuse svelte
return `<` + `script src="/plugins/${plugin.jsUrl}"></` + `script>`
})
.join("")
}
const placeholderScreen = new Screen()
.name("Screen Placeholder")
@ -92,6 +105,7 @@
? [$store.componentToPaste?._id]
: [],
isBudibaseEvent: true,
usedPlugins: $store.usedPlugins,
}
// Refresh the preview when required

View File

@ -37,9 +37,7 @@ export default `
}
</style>
<script src='{{ CLIENT_LIB_PATH }}'></script>
<script
type="application/javascript"
src="https://cdn.kingston.dev/plugin.min.js"></script>
{{ PLUGINS }}
<script>
function receiveMessage(event) {
if (!event.data) {