English
A plan card in five minutes
A page that shows what a run would install, asks for the owner's yes, follows the run and says what the proof found. First with the fake client of the library (nothing runs anywhere), then against the owner's server.
You need the repository and its dependencies (npm install). The packages are not published yet: the example imports them from packages/.
1. The page
Three elements inside an <alta-provider>, which gives them a theme, a colour scheme and a language:
examples/ui/plan-card/index.html
html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>A plan card</title>
<style>body { margin: 0; padding: 32px; font-family: system-ui, sans-serif; } main { max-width: 520px; display: grid; gap: 16px; }</style>
</head>
<body>
<main>
<alta-provider theme="alta" scheme="light" lang="en">
<alta-plan-card></alta-plan-card>
<alta-run-progress what="the install"></alta-run-progress>
<alta-proof-badge proof-role="installed"></alta-proof-badge>
</alta-provider>
</main>
<script type="module" src="./main.ts"></script>
</body>
</html>examples/ui/plan-card/index.html
2. One run, three views
The card, the progress and the badge draw the same run: one store, made by createRunStore, given to each with use(store). auto: true asks for the plan at once. The card draws its own agreement: nothing runs before the click.
examples/ui/plan-card/main.ts
ts
// A plan card on a page (docs-site/ui/quickstart.md). Run it from the repository: npx vite examples/ui/plan-card
// With ?server=1&t=<token> it talks to the owner's server that serves the page; without it, to the fake client of the
// library, which plays a whole run: plan, agree, run, proof.
import "../../../packages/ui/styles/index.css";
import "../../../packages/ui/styles/themes/alta.css";
import "../../../packages/ui/src/register";
import { createAltaClient, createRunStore } from "../../../packages/ui-core/src/index";
import { createFakeClient } from "../../../packages/ui-core/src/testing/fake-client";
const q = new URLSearchParams(location.search);
const client = q.get("server") ? createAltaClient({ token: q.get("t") ?? "" }) : createFakeClient("ok");
// One run, three views of it: the card plans at once (auto), its agreement starts the run, the progress follows it,
// the badge says what the proof found.
const store = createRunStore({ client, target: { executor: "setup.base", args: {} }, auto: true });
for (const tag of ["alta-plan-card", "alta-run-progress", "alta-proof-badge"]) {
(document.querySelector(tag) as HTMLElement & { use(s: unknown): void }).use(store);
}
// What they say, as events.
for (const name of ["alta-plan", "alta-agreed", "alta-run-done", "alta-proof"]) {
document.addEventListener(name, e => console.log(name, (e as CustomEvent).detail));
}3. Run it
sh
npx vite examples/ui/plan-cardOpen the address Vite prints. The card lists what it installs and what it costs; Install starts the fake run; the progress goes to Done.; the badge says Proven by the machine. The console shows alta-plan, alta-run-done and alta-proof.
4. Against the owner's server
On a page served by the owner's own server, the client is createAltaClient({ token }): the same routes the game uses (/api/runs/plan, /api/runs/run, /api/runs/:id), the token in the X-World-Token header. Open the example with ?server=1&t=<token> from a page of that server. The target can be an executor with its arguments, as here, or a quest step: { quest: "core.wake", step: "base" }, and the server reads the step's arguments itself.
Nothing changes in the page: the same elements, the same events.
Next
- Theming: the same card in your own look.
- Secrets: a step that needs a key.
- Every component.