budibase/packages/client/src/index.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

import { createApp } from "./createApp";
import { trimSlash } from "./common/trimSlash";
2019-09-07 07:50:35 +02:00
export const loadBudibase = async ({
componentLibraries, props,
window, localStorage, uiFunctions }) => {
2019-09-22 06:02:33 +02:00
const appDefinition = window["##BUDIBASE_APPDEFINITION##"];
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-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(
window.document,
componentLibraries,
appDefinition,
user,
uiFunctions || {});
app.hydrateChildren(
[props],
2020-01-24 14:18:31 +01:00
window.document.body);
return app;
2019-09-22 06:02:33 +02:00
};
2020-01-24 14:18:31 +01:00
if(window) {
window.loadBudibase = loadBudibase;
}