2024-02-21 19:22:01 +00:00
|
|
|
import {get as getBrowserGlobals} from 'app/client/lib/browserGlobals';
|
|
|
|
import {setupLocale} from 'app/client/lib/localization';
|
2024-03-04 21:22:47 +00:00
|
|
|
import {AppModel, TopAppModelImpl, TopAppModelOptions} from 'app/client/models/AppModel';
|
2024-02-21 19:22:01 +00:00
|
|
|
import {reportError, setUpErrorHandling} from 'app/client/models/errors';
|
|
|
|
import {buildSnackbarDom} from 'app/client/ui/NotifyUI';
|
|
|
|
import {addViewportTag} from 'app/client/ui/viewport';
|
2024-04-26 20:34:16 +00:00
|
|
|
import {attachCssRootVars} from 'app/client/ui2018/cssVars';
|
|
|
|
import {attachTheme} from 'app/client/ui2018/theme';
|
2024-02-21 19:22:01 +00:00
|
|
|
import {BaseAPI} from 'app/common/BaseAPI';
|
|
|
|
import {dom, DomContents} from 'grainjs';
|
|
|
|
|
|
|
|
const G = getBrowserGlobals('document', 'window');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the application model, error handling, and global styles, and replaces
|
|
|
|
* the DOM body with the result of calling `buildAppPage`.
|
|
|
|
*/
|
2024-03-04 21:22:47 +00:00
|
|
|
export function createAppPage(
|
|
|
|
buildAppPage: (appModel: AppModel) => DomContents,
|
2024-04-26 20:34:16 +00:00
|
|
|
modelOptions: TopAppModelOptions = {}
|
|
|
|
) {
|
2024-02-21 19:22:01 +00:00
|
|
|
setUpErrorHandling();
|
|
|
|
|
2024-03-04 21:22:47 +00:00
|
|
|
const topAppModel = TopAppModelImpl.create(null, {}, undefined, modelOptions);
|
2024-02-21 19:22:01 +00:00
|
|
|
|
|
|
|
addViewportTag();
|
|
|
|
attachCssRootVars(topAppModel.productFlavor);
|
2024-04-26 20:34:16 +00:00
|
|
|
attachTheme();
|
2024-02-21 19:22:01 +00:00
|
|
|
setupLocale().catch(reportError);
|
|
|
|
|
|
|
|
// Add globals needed by test utils.
|
|
|
|
G.window.gristApp = {
|
|
|
|
testNumPendingApiRequests: () => BaseAPI.numPendingRequests(),
|
|
|
|
};
|
2024-04-26 20:34:16 +00:00
|
|
|
dom.update(document.body, dom.maybe(topAppModel.appObs, (appModel) => {
|
2024-02-21 19:22:01 +00:00
|
|
|
return [
|
|
|
|
buildAppPage(appModel),
|
|
|
|
buildSnackbarDom(appModel.notifier, appModel),
|
|
|
|
];
|
|
|
|
}));
|
|
|
|
}
|