/ concept-collection / stan-web-ide
Sign in
concept-collection / stan-web-ide
stan-web-ide / src / main.ts
53 lines · 2.1 KBCodeBlameHistory
e20b703Build on minwebide's project-app shellJeremy Magland 1import { loadBuiltinTheme, registerBuiltinLanguages, startProjectApp, type ProjectAppConfig } from 'minwebide';
2import { openStanWorkbench } from './ide';
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 3import { registerStanLanguage } from './stan/language';
4import { registerStanLsp } from './stan/lsp';
e20b703Build on minwebide's project-app shellJeremy Magland 5import { emptyWorkspace, sampleWorkspace } from './sampleWorkspace';
7const config: ProjectAppConfig = {
8 appId: 'stan-web-ide',
9 appName: 'stan web IDE',
10 assembleWorkbench: openStanWorkbench,
11 startingFiles: ['/fit.sample', '/main.stan', '/README.md'],
12 landing: {
13 subtitle: 'Run Stan sampling in your browser. Projects are stored locally, in your browser.',
14 links: [
15 { label: 'mc-stan.org', href: 'https://mc-stan.org' },
16 { label: 'stan-playground', href: 'https://stan-playground.flatironinstitute.org' },
17 { label: 'github.com/concept-collection/stan-web-ide', href: 'https://github.com/concept-collection/stan-web-ide' },
18 ],
19 sampleWorkspace,
20 sampleButtonTitle: 'Seeded with a linear-regression model, data, and ready-to-run .sample configs',
21 emptyWorkspace: () => emptyWorkspace,
22 },
23};
25async function start(): Promise<void> {
f66b0fbOpen GitHub repos as workspaces via #/github/<spec>Jeremy Magland 26 // this app no longer uses a service worker (pure-WASI sampling needs no
27 // cross-origin isolation) — unregister the coi-serviceworker that earlier
28 // deployed versions registered, since a stale controlling SW keeps
29 // rewriting response headers
30 if ('serviceWorker' in navigator) {
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 31 const registrations = await navigator.serviceWorker.getRegistrations();
32 if (registrations.length > 0) {
33 await Promise.all(registrations.map(r => r.unregister()));
34 if (navigator.serviceWorker.controller) {
35 location.reload();
36 return;
37 }
38 }
39 }
41 // one-time global setup: theme + languages are shared by all views;
42 // Stan registers last so it owns .stan (and .sample maps to YAML)
43 const theme = await loadBuiltinTheme('dark_modern');
44 await registerBuiltinLanguages(theme);
45 registerStanLanguage();
46 // the Stan language server (diagnostics, hover, completion, format) runs
47 // in one worker for the whole session, across projects
48 registerStanLsp();
e20b703Build on minwebide's project-app shellJeremy Magland 50 await startProjectApp(document.getElementById('app')!, theme, config);
53start();
moveopenescclose