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
|
|
|
|
2019-09-22 16:02:33 +12:00
|
|
|
export const loadBudibase = async (componentLibraries, props) => {
|
2019-09-19 15:35:40 +12:00
|
|
|
|
2019-09-22 16:02:33 +12:00
|
|
|
const appDefinition = window["##BUDIBASE_APPDEFINITION##"];
|
2019-09-23 17:08:06 +12:00
|
|
|
const user = localStorage.getItem("budibase:user") || {
|
|
|
|
name: "annonymous",
|
|
|
|
permissions : [],
|
|
|
|
isUser:false,
|
|
|
|
temp:false
|
|
|
|
}
|
2019-09-19 15:35:40 +12:00
|
|
|
|
2019-09-22 16:02:33 +12:00
|
|
|
if(!componentLibraries) {
|
|
|
|
|
|
|
|
const componentLibraryUrl = (lib) => "./" + trimSlash(lib)
|
|
|
|
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
|
|
|
|
2019-09-29 18:40:06 +13:00
|
|
|
const _app = createApp(componentLibraries, appDefinition, user);
|
2019-10-16 17:38:45 +13:00
|
|
|
_app.hydrateComponent(
|
2019-09-19 15:35:40 +12:00
|
|
|
props,
|
|
|
|
document.body);
|
|
|
|
|
2019-09-22 16:02:33 +12:00
|
|
|
};
|
|
|
|
|
|
|
|
window.loadBudibase = loadBudibase;
|