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