// The persistent app shell's pure model (L2/L3/L4): the four destinations, the // roving-tabindex arithmetic shared by the destination and section tablists, the // compact connection word shown in the rail/dock, and the view -> destination // mapping. Deliberately DOM-free, so every branch is unit-testable in Node. // // The rail is the wide presentation; the bottom dock is the narrow one. Both // render the same DESTINATIONS model (roles: tablist + tab, aria-current on the // route as well as aria-selected). Templates stays a route but not a // destination: it is reached from Settings, the card that owns its entry point. /** The four destinations, in Android's destination-bar order. */ export const DESTINATIONS = Object.freeze([ Object.freeze({ key: "pipelines", label: "Pipelines", path: "/pipelines", icon: "pipelines" }), Object.freeze({ key: "runs", label: "Runs", path: "/runs", icon: "runs" }), Object.freeze({ key: "chat", label: "Chat", path: "/chat", icon: "chat" }), Object.freeze({ key: "settings", label: "Settings", path: "/settings", icon: "settings" }), ]); /** The destination key that owns a view. Templates is reached from Settings. */ export function destinationForView(view) { switch (view) { case "runs": return "runs"; case "chat": return "chat"; case "settings": case "templates": return "settings"; default: return "pipelines"; } } /** The index of a destination key in DESTINATIONS (0 for an unknown key). */ export function destinationIndex(key) { const index = DESTINATIONS.findIndex((item) => item.key === key); return index < 0 ? 0 : index; } /** Roving tabindex: the selected tab is the only stop in its tablist. */ export function rovingTabindex(selectedIndex, index) { return selectedIndex === index ? "0" : "-1"; } /** * The next index after one of the roving-tablist keys, or -1 when the key is not * one this tablist handles. ArrowLeft/ArrowRight always move (both tablists use * a horizontal axis in the narrow strip); ArrowUp/ArrowDown are also accepted * because the wide rail is vertical. Home/End jump to the ends. Movement wraps, * as WAI-ARIA's tabs pattern recommends. */ export function tabIndexForKey(key, index, count, { vertical = false } = {}) { if (!Number.isInteger(index) || !Number.isInteger(count) || count <= 0 || index < 0 || index >= count) { return -1; } const last = count - 1; switch (key) { case "ArrowRight": return index >= last ? 0 : index + 1; case "ArrowLeft": return index <= 0 ? last : index - 1; case "ArrowDown": return vertical ? (index >= last ? 0 : index + 1) : -1; case "ArrowUp": return vertical ? (index <= 0 ? last : index - 1) : -1; case "Home": return 0; case "End": return last; default: return -1; } } /** * The compact connection word for the shell status control. It deliberately does * not repeat the banner's full sentence: the dot's tone carries the state and * the word always names it, so colour is never the only signal. With no endpoint * configured, the shell says exactly that instead of asking for a URL (Settings * is the only place that asks). */ export function shellStatus(connection, { hasEndpoint = false } = {}) { const c = connection ?? {}; switch (c.kind) { case "connected": return { text: "Connected", tone: "ok", state: "connected" }; case "connecting": return { text: "Connecting\u2026", tone: "warn", state: "connecting" }; case "disconnected": return { text: "Disconnected", tone: "bad", state: "disconnected" }; default: return hasEndpoint ? { text: "Not connected", tone: "idle", state: "idle" } : { text: "Not configured", tone: "idle", state: "unconfigured" }; } } /** * The section tabs for the current detail. `tabs` is the model's own * `{key,label}` list, `active` the selected key. No detail means no tablist. */ export function sectionModel(model) { const tabs = Array.isArray(model?.tabs) ? model.tabs : []; if (!tabs.length) return { tabs: [], active: -1 }; const active = Math.max(0, tabs.findIndex((tab) => tab.key === model.active)); return { tabs, active }; }