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
|
|
|
|
2019-09-22 06:02:33 +02:00
|
|
|
export const loadBudibase = async (componentLibraries, props) => {
|
2019-09-19 05:35:40 +02:00
|
|
|
|
2019-09-22 06:02:33 +02:00
|
|
|
const appDefinition = window["##BUDIBASE_APPDEFINITION##"];
|
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
|
|
|
|
2019-09-29 07:40:06 +02:00
|
|
|
const _app = createApp(componentLibraries, appDefinition, user);
|
2019-10-16 06:38:45 +02:00
|
|
|
_app.hydrateComponent(
|
2019-09-19 05:35:40 +02:00
|
|
|
props,
|
|
|
|
document.body);
|
|
|
|
|
2019-09-22 06:02:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
window.loadBudibase = loadBudibase;
|