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 // Construct iframe template
$: template = iframeTemplate.replace( $: pluginLinks = generatePluginLinks($store.usedPlugins)
/\{\{ CLIENT_LIB_PATH }}/, $: template = iframeTemplate
$store.clientLibPath .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() const placeholderScreen = new Screen()
.name("Screen Placeholder") .name("Screen Placeholder")
@ -92,6 +105,7 @@
? [$store.componentToPaste?._id] ? [$store.componentToPaste?._id]
: [], : [],
isBudibaseEvent: true, isBudibaseEvent: true,
usedPlugins: $store.usedPlugins,
} }
// Refresh the preview when required // Refresh the preview when required

View File

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