2020-11-13 16:42:32 +01:00
|
|
|
import ClientApp from "./components/ClientApp.svelte"
|
2022-06-09 16:03:43 +02:00
|
|
|
import { builderStore, appStore, devToolsStore } from "./stores"
|
2021-09-01 12:41:48 +02:00
|
|
|
import loadSpectrumIcons from "@budibase/bbui/spectrum-icons-rollup.js"
|
2022-06-09 16:03:43 +02:00
|
|
|
import { get } from "svelte/store"
|
2021-09-01 12:41:48 +02:00
|
|
|
|
|
|
|
// Initialise spectrum icons
|
|
|
|
loadSpectrumIcons()
|
2019-09-07 07:50:35 +02:00
|
|
|
|
2020-11-23 15:28:02 +01:00
|
|
|
let app
|
|
|
|
|
2020-11-13 16:42:32 +01:00
|
|
|
const loadBudibase = () => {
|
2020-11-24 10:31:54 +01:00
|
|
|
// Update builder store with any builder flags
|
|
|
|
builderStore.set({
|
|
|
|
inBuilder: !!window["##BUDIBASE_IN_BUILDER##"],
|
2020-11-27 17:36:31 +01:00
|
|
|
layout: window["##BUDIBASE_PREVIEW_LAYOUT##"],
|
2020-11-24 10:31:54 +01:00
|
|
|
screen: window["##BUDIBASE_PREVIEW_SCREEN##"],
|
2020-11-30 13:11:50 +01:00
|
|
|
selectedComponentId: window["##BUDIBASE_SELECTED_COMPONENT_ID##"],
|
|
|
|
previewId: window["##BUDIBASE_PREVIEW_ID##"],
|
2021-06-28 13:55:11 +02:00
|
|
|
theme: window["##BUDIBASE_PREVIEW_THEME##"],
|
2021-09-02 12:38:41 +02:00
|
|
|
customTheme: window["##BUDIBASE_PREVIEW_CUSTOM_THEME##"],
|
2021-09-08 10:40:25 +02:00
|
|
|
previewDevice: window["##BUDIBASE_PREVIEW_DEVICE##"],
|
2022-04-28 18:30:48 +02:00
|
|
|
navigation: window["##BUDIBASE_PREVIEW_NAVIGATION##"],
|
2020-05-29 15:06:10 +02:00
|
|
|
})
|
2020-11-24 10:31:54 +01:00
|
|
|
|
2021-06-30 21:35:02 +02:00
|
|
|
// Set app ID - this window flag is set by both the preview and the real
|
|
|
|
// server rendered app HTML
|
2022-06-09 16:03:43 +02:00
|
|
|
appStore.actions.setAppId(window["##BUDIBASE_APP_ID##"])
|
|
|
|
|
|
|
|
// Enable dev tools or not. We need to be using a dev app and not inside
|
|
|
|
// the builder preview to enable them.
|
|
|
|
const enableDevTools = !get(builderStore).inBuilder && get(appStore).isDevApp
|
|
|
|
devToolsStore.actions.setEnabled(enableDevTools)
|
2021-06-30 21:35:02 +02:00
|
|
|
|
2020-11-24 10:31:54 +01:00
|
|
|
// Create app if one hasn't been created yet
|
|
|
|
if (!app) {
|
|
|
|
app = new ClientApp({
|
|
|
|
target: window.document.body,
|
|
|
|
})
|
|
|
|
}
|
2020-02-03 10:24:25 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 16:42:32 +01:00
|
|
|
// Attach to window so the HTML template can call this when it loads
|
|
|
|
window.loadBudibase = loadBudibase
|