2020-02-03 22:24:25 +13:00
|
|
|
import { createApp } from "./createApp"
|
2020-02-11 04:51:09 +13:00
|
|
|
import { builtins, builtinLibName } from "./render/builtinComponents"
|
2020-11-03 09:14:10 +13:00
|
|
|
import { getAppIdFromPath } from "./render/getAppId"
|
2019-09-07 17:50:35 +12:00
|
|
|
|
2020-02-21 09:19:24 +13:00
|
|
|
/**
|
|
|
|
* create a web application from static budibase definition files.
|
|
|
|
* @param {object} opts - configuration options for budibase client libary
|
|
|
|
*/
|
2020-02-26 04:21:23 +13:00
|
|
|
export const loadBudibase = async opts => {
|
2020-02-13 01:45:24 +13:00
|
|
|
const _window = (opts && opts.window) || window
|
2020-05-07 21:53:34 +12:00
|
|
|
// const _localStorage = (opts && opts.localStorage) || localStorage
|
2020-11-03 09:14:10 +13:00
|
|
|
const appId = getAppIdFromPath()
|
2020-02-13 01:45:24 +13:00
|
|
|
const frontendDefinition = _window["##BUDIBASE_FRONTEND_DEFINITION##"]
|
2020-02-26 04:21:23 +13:00
|
|
|
|
2020-05-07 21:53:34 +12:00
|
|
|
const user = {}
|
2020-02-03 22:24:25 +13:00
|
|
|
|
2020-05-18 22:01:09 +12:00
|
|
|
const componentLibraryModules = (opts && opts.componentLibraries) || {}
|
2020-02-03 22:24:25 +13:00
|
|
|
|
2020-05-08 09:25:27 +12:00
|
|
|
const libraries = frontendDefinition.libraries || []
|
2020-05-07 21:53:34 +12:00
|
|
|
|
2020-05-06 23:17:15 +12:00
|
|
|
for (let library of libraries) {
|
2020-05-07 21:53:34 +12:00
|
|
|
// fetch the JavaScript for the component libraries from the server
|
2020-07-07 06:43:40 +12:00
|
|
|
componentLibraryModules[library] = await import(
|
2020-10-19 09:45:46 +13:00
|
|
|
`/componentlibrary?library=${encodeURI(library)}&appId=${appId}`
|
2020-07-07 06:43:40 +12:00
|
|
|
)
|
2020-05-07 21:53:34 +12:00
|
|
|
}
|
2020-04-30 07:29:42 +12:00
|
|
|
|
2020-05-06 23:17:15 +12:00
|
|
|
componentLibraryModules[builtinLibName] = builtins(_window)
|
2020-02-03 22:24:25 +13:00
|
|
|
|
2020-02-26 05:23:45 +13:00
|
|
|
const {
|
|
|
|
initialisePage,
|
|
|
|
screenStore,
|
|
|
|
pageStore,
|
|
|
|
routeTo,
|
|
|
|
rootNode,
|
2020-05-30 01:06:10 +12:00
|
|
|
} = createApp({
|
|
|
|
componentLibraries: componentLibraryModules,
|
2020-02-11 10:35:51 +13:00
|
|
|
frontendDefinition,
|
2020-02-03 22:24:25 +13:00
|
|
|
user,
|
2020-06-15 07:30:23 +12:00
|
|
|
window: _window,
|
2020-05-30 01:06:10 +12:00
|
|
|
})
|
2020-02-03 22:24:25 +13:00
|
|
|
|
2020-02-26 04:21:23 +13:00
|
|
|
const route = _window.location
|
2020-06-13 07:42:55 +12:00
|
|
|
? _window.location.pathname.replace(`${appId}/`, "").replace(appId, "")
|
2020-02-26 04:21:23 +13:00
|
|
|
: ""
|
2020-02-11 04:51:09 +13:00
|
|
|
|
2020-02-26 05:23:45 +13:00
|
|
|
initialisePage(frontendDefinition.page, _window.document.body, route)
|
|
|
|
|
2020-02-11 04:51:09 +13:00
|
|
|
return {
|
|
|
|
screenStore,
|
|
|
|
pageStore,
|
|
|
|
routeTo,
|
2020-02-26 05:23:45 +13:00
|
|
|
rootNode,
|
2020-02-11 04:51:09 +13:00
|
|
|
}
|
2020-02-03 22:24:25 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
if (window) {
|
|
|
|
window.loadBudibase = loadBudibase
|
|
|
|
}
|