import { SchemaBase } from './dsl.js'; import { FrontAppSchema } from './project.js'; import type { PageDef } from './page-def.js'; import type { RouteDataSchema } from './route.js'; // Page definitions: standalone page schemas and the page node type used by // page-driven flows. Kept separate from page-flow.ts (the flow graph itself). // Module-level registry: every definePage/defineTabPage call registers its // result so definePageFlow can check that no page is left out. const _pageRegistry = new Set(); export function getRegisteredPages(): ReadonlySet { return _pageRegistry; } export function clearRegisteredPages(): void { _pageRegistry.clear(); } /** Standalone page definition. A page is a shared value object: it belongs to * exactly one frontend app. Actions live in the page skeleton (PageDef.actions), * not on the page itself — the page only carries what the flow/topology needs. */ export interface PageSchema extends SchemaBase { /** Short display name for topology diagrams. */ label: string; /** The frontend app this page belongs to (shared instance from project.config). */ app: FrontAppSchema; /** Full page skeleton definition (optional). */ pageDef?: PageDef; /** Route params this page expects (e.g. detail page expects productId). */ params?: RouteDataSchema; } export function definePage(schema: { name: string; label: string; description?: string; app: FrontAppSchema; pageDef?: PageDef; params?: RouteDataSchema; }): PageSchema { const p: PageSchema = { ...schema }; _pageRegistry.add(p); return p; } /** Page with bottom tab navigation. tabs collects the child pages reachable via tab switch. */ export interface TabPageSchema extends PageSchema { tabs: PageSchema[]; } export function defineTabPage(schema: { name: string; label: string; description?: string; app: FrontAppSchema; tabs: PageSchema[]; pageDef?: PageDef; params?: RouteDataSchema; }): TabPageSchema { const p: TabPageSchema = { ...schema }; _pageRegistry.add(p); return p; } /** A page node in a page-driven flow: every node is a page, and a page belongs to an app. */ export interface Page extends SchemaBase { /** Short display name for topology diagrams. */ label?: string; /** The frontend app this page belongs to (shared instance from project.config). */ app: FrontAppSchema; } export function page(app: FrontAppSchema, name: string, description?: string, label?: string): Page { return { name, label, app, description }; }