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