diff --git a/changelog.d/explorer-app.md b/changelog.d/explorer-app.md new file mode 100644 index 0000000000..2536a21b47 --- /dev/null +++ b/changelog.d/explorer-app.md @@ -0,0 +1,21 @@ +- **docs-site: the model explorer is one browser app.** `docsSiteFile()` now writes the + explorer as a few files (a shell, the app, the theme, Cytoscape and three data files: + `explorer.json`, `explorer-model.js`, `explorer-stamp.js`) in place of a page per screen. + The app draws every page when it is visited, with the same page code and templates, so each + page is byte-for-byte the one the static site wrote. It runs from `file://` with no server, + addresses each page as `index.html#/`, and follows the model while it is open: it polls + the stamp file about once a second and draws the current page again when `meta gen` rewrites + the model. Cytoscape 3.30.2 (MIT) ships with the site, so the graphs draw offline and the + CDN notice is gone. `docsSiteFile({ output: "static" })` (and `generateExplorerSite({ output: + "static" })`) writes the earlier page-per-screen site from the same code, for publishing + without scripts or for Pagefind; `assetBase` now applies to that export only, which given one + loads Cytoscape from it and ships no copy. The app's files live once at `explorer-app/` and + in every port's package (`scripts/sync-explorer-app.sh`, gated by `explorer app copies`); + the other ports' docs-site generators are still to write them. Generated-output change: the + next `meta gen` replaces the explorer's pages with the app's files, and `meta verify + --codegen` holds the new files to the model as before. + If you ejected the theme on a 1.3.0 candidate, your `codegen/docs-site/assets/explorer.js` + predates the app, which calls `window.MO_THEME` each time it draws a page: without that hook + search, the theme toggle and the graphs do nothing. Copy it again with `meta eject docs-site + --force` and carry your edits into the new copy (the app also needs its `window.MO_APP` link, + query and listener hooks, so adding the one line is not enough). diff --git a/docs/features/explorer-site.md b/docs/features/explorer-site.md index 9bf9aa9556..d380c6b082 100644 --- a/docs/features/explorer-site.md +++ b/docs/features/explorer-site.md @@ -1,10 +1,14 @@ # The model explorer site -`docsSiteFile()` builds a static site that shows one project: what the software does, how the +`docsSiteFile()` builds a site that shows one project: what the software does, how the model is put together, and whether each requirement claim holds. Every page is drawn from one data file, [`explorer.json`](docs-view.md) (the docs view), which the generator builds during the same `meta gen` run. A page never works a model fact out for itself. +By default the site is one browser app: a handful of files that draw every page when it is +visited, from `file://` with no server, and follow the model while it is open. `output: +"static"` writes every page as its own HTML file instead, from the same page code. + The explorer is the default site. The earlier site (package navigation, a page per object, the Mermaid ER diagrams) is still there as `docsSiteFile({ site: "classic" })`. @@ -35,26 +39,61 @@ generator in the run, wherever it appears in the list, because it reads what the | Generated files per node | The files this run wrote, with the node each came from. Files under a target whose `outDir` lies outside the project are left out, under `meta gen` and `verify --codegen` alike | | Routes per node | The REST routes this run's routes generator mounts; none if the run has no routes generator | -Open `site/index.html` in a browser, or serve the directory. The pages use relative links, so -the site works from any path and from `file://`. +Open `site/index.html` in a browser, or serve the directory. The site uses relative links, so +it works from any path and from `file://`. + +### What it writes + +| File | What it is | +|---|---| +| `index.html` | The app's shell | +| `assets/explorer-app.js` | The app: the explorer's page code and templates, and a router | +| `assets/explorer.css`, `assets/explorer.js` | The theme (yours, when you own it) | +| `assets/cytoscape.min.js` | [Cytoscape.js](https://js.cytoscape.org/) 3.30.2 (MIT), so the graphs draw offline | +| `explorer.json` | The docs view | +| `explorer-model.js` | The view, the prompt texts, the title and any owned templates, as a script | +| `explorer-stamp.js` | A hash of the model file | + +Every page is an address inside the app: `index.html#/model/acme/shop/Order.html`, with the +map's and the trace's query and a member's anchor after it +(`#/map.html?slice=…`, `#/model/acme/shop/Order.html#m-total`). Back, forward, bookmarks and +opening a link in a new tab work as they do on a static site. The app files are the same in +every port; `explorer-app/README.md` at the repository root describes them and the two data +files a port writes beside them. + +### The live view + +Leave the explorer open while you work. About once a second it reloads `explorer-stamp.js`, +and when the stamp has moved (a `meta gen` rewrote the model) it reloads `explorer-model.js` +and draws the page you are on again, keeping the address and the scroll position. A model +file caught half-written is not taken: the app waits for one that carries the new stamp. + +### The static export + +`docsSiteFile({ output: "static" })` writes the earlier layout: a page per screen, the theme, +`assets/cytoscape.min.js`, `assets/explorer-data.js` (the map's data) and `explorer.json`. It +draws its pages with the same code as the app, and the two are held to each other page for +page. Use it to publish the site where scripts are not wanted, or to index it for full-text +search. ### Options | Option | Default | What it does | |---|---|---| | `site` | `"explorer"` | `"classic"` builds the earlier site instead | +| `output` | `"app"` | The explorer only: `"static"` writes a page per screen (see "The static export") | | `subDir` | `"site"` | The directory under the `docs` target | | `title` | the project directory's name | The name in the header and the page titles | | `prompts` | none | An extra directory of prompt `.mustache` sources, so the prompt pages can show the text | | `stamp` | none | Footer text. With none, the pages depend on the model alone | -| `assetBase` | `https://cdn.jsdelivr.net/npm` | Where the graph library loads from (see "Offline use") | +| `assetBase` | none | A static explorer only: load the graph library from this base and ship no copy (see "Offline use"). The classic site's CDN base | | `target` | `"docs"` | The output target | ### Search Every page has a search box over a built-in index of objects, fields, prompts and -requirements; press `/` to jump to it. For full-text search, run -[Pagefind](https://pagefind.app/) over the output after `meta gen`: +requirements; press `/` to jump to it. For full-text search, build the static export and run +[Pagefind](https://pagefind.app/) over it after `meta gen`: ```bash npx pagefind --site docs/generated/site @@ -70,15 +109,17 @@ Pagefind's output is not generated by `meta gen`, so leave `pagefind/` out of th ### Offline use The map, the mini-maps and the trace draw with [Cytoscape.js](https://js.cytoscape.org/), -loaded from `${assetBase}/cytoscape@3.30.2/dist/cytoscape.min.js`. Only those three kinds of -page load it. Opened without network access, every page still renders and the graphs show a -notice in their place. To serve the file yourself, put -`cytoscape@3.30.2/dist/cytoscape.min.js` under a path of your own and pass that path: +which the site ships as `assets/cytoscape.min.js`, so the explorer needs no network access. +A static export loads it only on those three kinds of page. To load it from a mirror of your +own instead, give a static export an `assetBase`: its pages then load +`${assetBase}/cytoscape@3.30.2/dist/cytoscape.min.js` and the site ships no copy. ```ts -docsSiteFile({ assetBase: "/vendor/npm" }) +docsSiteFile({ output: "static", assetBase: "/vendor/npm" }) ``` +If the library does not load, every page still renders and the graphs show a notice. + ## The screens | Screen | Page | What it shows | @@ -130,16 +171,27 @@ copies the templates of both sites to `codegen/docs-site/templates/` (the explor `explorer-*.mustache` files) and their CSS and JS to `codegen/docs-site/assets/` (`explorer.css`, `explorer.js`). Only files that are not there yet are written (`--force` overwrites). `docsSiteFile()` renders with your copies, and a file you did not copy falls back -to the packaged one. A project that ejected the theme before the explorer existed has only the +to the packaged one. The app carries your templates in `explorer-model.js` and draws every +page with them, and writes your CSS and JS in place of its own. The app keeps only each drawn +page's title and body, so what an owned `explorer-head.mustache` adds to `` (a stylesheet, +a `