budibase/packages/client/src/index.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

import { createApp } from "./createApp";
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-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-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-22 06:02:33 +02:00
if(!props) {
props = appDefinition.props;
}
const _app = createApp(componentLibraries, appDefinition, user);
_app.hydrateComponent(
props,
document.body);
2019-09-22 06:02:33 +02:00
};
window.loadBudibase = loadBudibase;