2020-02-03 22:24:25 +13:00
|
|
|
import { createApp } from "./createApp"
|
|
|
|
import { trimSlash } from "./common/trimSlash"
|
2020-02-11 04:51:09 +13:00
|
|
|
import { builtins, builtinLibName } from "./render/builtinComponents"
|
2019-09-07 17:50:35 +12:00
|
|
|
|
2020-01-29 03:14:53 +13:00
|
|
|
export const loadBudibase = async ({
|
2020-02-03 22:24:25 +13:00
|
|
|
componentLibraries,
|
2020-02-11 04:51:09 +13:00
|
|
|
page,
|
|
|
|
screens,
|
2020-02-03 22:24:25 +13:00
|
|
|
window,
|
|
|
|
localStorage,
|
|
|
|
uiFunctions,
|
|
|
|
}) => {
|
2020-02-11 10:35:51 +13:00
|
|
|
const backendDefinition = window["##BUDIBASE_BACKEND_DEFINITION##"]
|
|
|
|
const frontendDefinition = window["##BUDIBASE_FRONTEND_DEFINITION##"]
|
|
|
|
const uiFunctionsFromWindow = window["##BUDIBASE_FRONTEND_FUNCTIONS##"]
|
2020-02-03 22:24:25 +13:00
|
|
|
uiFunctions = uiFunctionsFromWindow || uiFunctions
|
|
|
|
|
|
|
|
const userFromStorage = localStorage.getItem("budibase:user")
|
|
|
|
|
|
|
|
const user = userFromStorage
|
|
|
|
? JSON.parse(userFromStorage)
|
|
|
|
: {
|
2019-09-23 17:08:06 +12:00
|
|
|
name: "annonymous",
|
2020-02-03 22:24:25 +13:00
|
|
|
permissions: [],
|
|
|
|
isUser: false,
|
|
|
|
temp: false,
|
|
|
|
}
|
|
|
|
|
2020-02-11 04:51:09 +13:00
|
|
|
const rootPath =
|
2020-02-11 10:35:51 +13:00
|
|
|
frontendDefinition.appRootPath === ""
|
2020-02-11 04:51:09 +13:00
|
|
|
? ""
|
2020-02-11 10:35:51 +13:00
|
|
|
: "/" + trimSlash(frontendDefinition.appRootPath)
|
2020-02-11 04:51:09 +13:00
|
|
|
|
2020-02-03 22:24:25 +13:00
|
|
|
if (!componentLibraries) {
|
2020-02-11 04:51:09 +13:00
|
|
|
|
2020-02-03 22:24:25 +13:00
|
|
|
const componentLibraryUrl = lib => rootPath + "/" + trimSlash(lib)
|
|
|
|
componentLibraries = {}
|
|
|
|
|
2020-02-11 10:35:51 +13:00
|
|
|
for (let lib of frontendDefinition.componentLibraries) {
|
2020-02-03 22:24:25 +13:00
|
|
|
componentLibraries[lib.libName] = await import(
|
|
|
|
componentLibraryUrl(lib.importPath)
|
|
|
|
)
|
2019-09-19 15:35:40 +12:00
|
|
|
}
|
2020-02-03 22:24:25 +13:00
|
|
|
}
|
|
|
|
|
2020-02-11 04:51:09 +13:00
|
|
|
componentLibraries[builtinLibName] = builtins(window)
|
|
|
|
|
|
|
|
if (!page) {
|
2020-02-11 10:35:51 +13:00
|
|
|
page = frontendDefinition.page
|
2020-02-11 04:51:09 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!screens) {
|
2020-02-11 10:35:51 +13:00
|
|
|
screens = frontendDefinition.screens
|
2020-02-03 22:24:25 +13:00
|
|
|
}
|
|
|
|
|
2020-02-11 04:51:09 +13:00
|
|
|
const { initialisePage, screenStore, pageStore, routeTo, rootNode } = createApp(
|
2020-02-03 22:24:25 +13:00
|
|
|
window.document,
|
|
|
|
componentLibraries,
|
2020-02-11 10:35:51 +13:00
|
|
|
frontendDefinition,
|
|
|
|
backendDefinition,
|
2020-02-03 22:24:25 +13:00
|
|
|
user,
|
2020-02-11 04:51:09 +13:00
|
|
|
uiFunctions || {},
|
|
|
|
screens
|
2020-02-03 22:24:25 +13:00
|
|
|
)
|
|
|
|
|
2020-02-11 04:51:09 +13:00
|
|
|
const route = window.location
|
|
|
|
? window.location.pathname.replace(rootPath, "")
|
|
|
|
: "";
|
|
|
|
|
|
|
|
return {
|
|
|
|
rootNode: initialisePage(page, window.document.body, route),
|
|
|
|
screenStore,
|
|
|
|
pageStore,
|
|
|
|
routeTo,
|
|
|
|
rootNode
|
|
|
|
}
|
2020-02-03 22:24:25 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
if (window) {
|
|
|
|
window.loadBudibase = loadBudibase
|
|
|
|
}
|