2020-02-03 10:24:25 +01:00
|
|
|
import { createApp } from "./createApp"
|
|
|
|
import { trimSlash } from "./common/trimSlash"
|
2019-09-07 07:50:35 +02:00
|
|
|
|
2020-01-28 15:14:53 +01:00
|
|
|
export const loadBudibase = async ({
|
2020-02-03 10:24:25 +01:00
|
|
|
componentLibraries,
|
|
|
|
props,
|
|
|
|
window,
|
|
|
|
localStorage,
|
|
|
|
uiFunctions,
|
|
|
|
}) => {
|
|
|
|
const appDefinition = window["##BUDIBASE_APPDEFINITION##"]
|
|
|
|
const uiFunctionsFromWindow = window["##BUDIBASE_APPDEFINITION##"]
|
|
|
|
uiFunctions = uiFunctionsFromWindow || uiFunctions
|
|
|
|
|
|
|
|
const userFromStorage = localStorage.getItem("budibase:user")
|
|
|
|
|
|
|
|
const user = userFromStorage
|
|
|
|
? JSON.parse(userFromStorage)
|
|
|
|
: {
|
2019-09-23 07:08:06 +02:00
|
|
|
name: "annonymous",
|
2020-02-03 10:24:25 +01:00
|
|
|
permissions: [],
|
|
|
|
isUser: false,
|
|
|
|
temp: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!componentLibraries) {
|
|
|
|
const rootPath =
|
|
|
|
appDefinition.appRootPath === ""
|
|
|
|
? ""
|
|
|
|
: "/" + trimSlash(appDefinition.appRootPath)
|
|
|
|
const componentLibraryUrl = lib => rootPath + "/" + trimSlash(lib)
|
|
|
|
componentLibraries = {}
|
|
|
|
|
|
|
|
for (let lib of appDefinition.componentLibraries) {
|
|
|
|
componentLibraries[lib.libName] = await import(
|
|
|
|
componentLibraryUrl(lib.importPath)
|
|
|
|
)
|
2019-09-19 05:35:40 +02:00
|
|
|
}
|
2020-02-03 10:24:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!props) {
|
|
|
|
props = appDefinition.props
|
|
|
|
}
|
|
|
|
|
|
|
|
const app = createApp(
|
|
|
|
window.document,
|
|
|
|
componentLibraries,
|
|
|
|
appDefinition,
|
|
|
|
user,
|
|
|
|
uiFunctions || {}
|
|
|
|
)
|
|
|
|
app.hydrateChildren([props], window.document.body)
|
|
|
|
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window) {
|
|
|
|
window.loadBudibase = loadBudibase
|
|
|
|
}
|