Add PoC of using a custom component inside client library

This commit is contained in:
Andrew Kingston 2022-08-10 12:04:58 +01:00
parent 3a340379e9
commit 0ec6ac3372
3 changed files with 21 additions and 0 deletions

View File

@ -85,8 +85,18 @@
builderStore.actions.notifyLoaded() builderStore.actions.notifyLoaded()
} }
}) })
// TODO: remove. this is a test to render the first custom component
console.log(window["##BUDIBASE_CUSTOM_COMPONENTS##"]?.[0])
const custom = window["##BUDIBASE_CUSTOM_COMPONENTS##"]?.[0]?.Component
</script> </script>
{#if custom}
<div style="padding: 20px;">
<svelte:component this={custom} />
</div>
{/if}
{#if dataLoaded} {#if dataLoaded}
<div <div
id="spectrum-root" id="spectrum-root"

View File

@ -3,6 +3,12 @@ import { builderStore, appStore, devToolsStore } from "./stores"
import loadSpectrumIcons from "@budibase/bbui/spectrum-icons-rollup.js" import loadSpectrumIcons from "@budibase/bbui/spectrum-icons-rollup.js"
import { get } from "svelte/store" import { get } from "svelte/store"
// Provide svelte and svelte/internal as globals for custom components
import * as svelte from "svelte"
import * as internal from "svelte/internal"
window.svelte_internal = internal
window.svelte = svelte
// Initialise spectrum icons // Initialise spectrum icons
loadSpectrumIcons() loadSpectrumIcons()

View File

@ -83,6 +83,11 @@
</script> </script>
<script type="application/javascript" src={clientLibPath}> <script type="application/javascript" src={clientLibPath}>
</script> </script>
<!-- Custom components need inserted after the core client library -->
<!-- But before loadBudibase is called -->
<script
type="application/javascript"
src="https://cdn.kingston.dev/plugin.min.js"></script>
<script type="application/javascript"> <script type="application/javascript">
if (window.loadBudibase) { if (window.loadBudibase) {
window.loadBudibase() window.loadBudibase()