import type { JSONValue } from "@valbuild/core/patch"; /** * A Val demo, as the page hands it to the Studio. * * In a demo the Studio talks to Val's own server running in the same tab * (`@valbuild/server/browser`) instead of to an API route, and the page that * starts that server is the app's (``) while the Studio is a * separate bundle loaded by a script tag. A window property is how the two * meet, the same way `window.__VAL_MODULES__` hands the Studio the project's * modules. See `docs/plans/demo-mode.md`. */ export type ValDemoRuntime = { /** * Sends a Studio request to the in-tab server. Passed to `createValClient`. * * The server holds its edits in memory, so starting the demo over is * reloading the page: there is nothing stored to clear. */ fetch: (input: string, init: RequestInit) => Promise; /** * Whether uploads work here. They need the demo's service worker, which * relays the upload and the unpublished files to this tab's server, and a * service worker needs a secure context. Where it cannot run the Studio * refuses uploads before sending anything, and says why. */ uploads: boolean; /** * The tour the site wrote, in place of the Studio's own demo tour. See * `ValDemoTourStep`. Absent: the Studio's. */ tour?: ValDemoTourStep[]; /** The demo script. See `ValDemoOptions.tours`. */ tours?: ValDemoTour[]; /** "What brings you here?". See `ValDemoOptions.audiences`. */ audiences?: ValDemoAudience[]; }; /** * What the site starts the demo with: ``. * * `demo` alone (`true`) is the same with nothing given. */ export type ValDemoOptions = { /** * One tour, behind the demo card's Tour button, opened on a first visit. * `tours` replaces it: given both, `tours` is used. */ tour?: ValDemoTourStep[]; /** * The demo script: short tours the visitor picks from on the demo card, * each ticked off once done. A tour can be started from a link too: * `/val?tour=`. */ tours?: ValDemoTour[]; /** * What the demo card asks first, "What brings you here?": each answer is a * list of `tours`, by id, and the card shows the list for the answer. With * two or more, the Studio adds "Show me everything", all of them in order. * Absent: every tour, in the order given. */ audiences?: ValDemoAudience[]; }; /** One item of the demo script. */ export type ValDemoTour = { /** Stable: the answer's list names it, and `?tour=` starts it. */ id: string; title: string; /** How long it takes, as the card says it: "30 s", "1 min". */ duration?: string; /** * Where the tour starts, as a source path: a page of the site (a page * router's module and the page's key). The Studio goes there first, so a * tour about the home page is not started on whatever page the last one * left open. */ start?: string; steps: ValDemoTourStep[]; }; /** * An answer to "What brings you here?". * * The first tour of its list is the one the card offers first, with a * button of its own: the one to start with. */ export type ValDemoAudience = { id: string; /** "I write and edit content". */ title: string; /** What the list has in it, in a line: "Pages, photos, languages". */ description?: string; /** Tours by id, in order. */ tours: string[]; }; /** * A control of the Studio's a step can point at. * * The `data-val-tour` markers the Studio puts on them. One that is not on * screen (the rail on a phone) leaves the card on its own, so a step's words * must work without the arrow: never "this button here". */ export type ValDemoTourTarget = "canvas" | "pages" | "media" | "data" | "review" | "preview" | "publish" | "ai" | "locale" | "demo" | "utility" | "new-page"; /** A panel a step opens, so what it is about is on screen behind the card. */ export type ValDemoTourPanel = "pages" | "media" | "data" | "settings" | "ai"; /** * What moves a step on by itself. A step without one has Next. * * Each is something the visitor does, because doing it is the lesson, and * each has a "Do it for me" that does it the way the Studio would: * * - `open`: a field at or below this source path is opened -- by clicking it * on the page, or anywhere else. Do it for me opens it. * - `edit`: a change is made. Do it for me writes `value` at `path` -- * replacing what is there, or with `add: true` adding it, as a new entry of * a record or a new item of a list at that index; without them, it is * offered nowhere and the step waits for the visitor. * - `newPage`: a page is added. Do it for me adds the page this source path * names (a page router's module and the new page's key, `?p="/journal/x"`) * the way the New page form does, empty, and opens it. * - `panel`: that panel is opened. Do it for me opens it. * - `locale`: the language shown is changed. Do it for me picks the next one. */ export type ValDemoTourMoveOn = { open: string; } | { edit: true; path?: string; value?: JSONValue; add?: boolean; } | { newPage: string; } | { panel: ValDemoTourPanel; } | { locale: true; }; /** * One stop of the demo's tour, as the site writes it. * * Data rather than components, so the tour can be rewritten -- and tried on * people -- without a Val release: the Studio draws it, the site says what it * says. Written for someone who has never seen Val. */ export type ValDemoTourStep = { /** Stable, so a test can name a step without matching its words. */ id: string; title: string; body: string; /** The control this step is about. */ target?: ValDemoTourTarget; /** * A field this step is about, as a source path: ringed wherever the Studio * shows it -- the page's fields, or the module open in the editor. Takes * precedence over `target`, which is what is ringed when the field is not * on screen. */ field?: string; /** * A place on the page this step is about, as a source path: the page * outlines it and brings it into view. */ page?: string; panel?: ValDemoTourPanel; moveOn?: ValDemoTourMoveOn; /** * Code to show in the card: the line of a `.val.ts` behind what the step is * about, for a visitor who builds sites. Written by the site, so it has to * be kept the same as the file; `file` says which one. */ code?: { file: string; text: string; }; }; declare global { var __VAL_DEMO__: ValDemoRuntime | undefined; } /** The demo this page was started with, or null outside a demo. */ export declare function getValDemo(): ValDemoRuntime | null;