From 7e5bf935937099b70d4bfb99cb5a7639fafd4f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Sun, 4 Oct 2026 00:29:54 +0200 Subject: [PATCH 01/12] WIP: the shell's Organization rail, Environment picker and contract in place (F36 addendum, DEV-6639) Co-Authored-By: Claude Opus 5.5 (1M context) --- src/launchpad/shell-document.ts | 69 +++- src/shell/contract.ts | 72 ++-- src/shell/elements.ts | 596 ++++++++++++++++++++++---------- src/shell/icons.ts | 5 + src/shell/messages.ts | 138 +++++--- src/shell/styles.ts | 103 ++++-- src/shell/view.ts | 464 +++++++++++++++---------- 7 files changed, 962 insertions(+), 485 deletions(-) diff --git a/src/launchpad/shell-document.ts b/src/launchpad/shell-document.ts index 3cdc9c9cb..1e5026388 100644 --- a/src/launchpad/shell-document.ts +++ b/src/launchpad/shell-document.ts @@ -10,16 +10,23 @@ import { } from "../shell/contract"; import { initialsOf } from "../shell/view"; -// The producer of `/.lazurio/shell.json` (decision F36): what this -// Environment knows about itself today, in the shape of `lazurio.shell.v1`. -// One Environment, its own; its Organizations from the catalog of this -// Folder; its apps from the recorded hosted entry. Nothing here is a grant: -// the document names places, and every place admits by its own rules. The +// The producer of `/.lazurio/shell.json` (decision F36 and its addendum of +// 2026-10-04): what this Environment knows about itself today, in the shape +// of `lazurio.shell.v1`. One Environment, its own, named by what it is for +// (its Team, its persona, or its kind) and never by the machine's name; its +// Organizations from the catalog of this Folder, each with its Dashboard; +// its apps from the recorded hosted entry. Nothing here is a grant: the +// document names places, and every place admits by its own rules. The // Dashboard fills the other Environments later through the Lazurio account. -/** The Lazurio Dashboard and its account settings (root decision 0179). */ +/** The Lazurio Dashboard: the personal one, the account settings, adding an + * Organization, and an Organization's page `/orgs/` (by the + * Organization's slug, the Dashboard's canonical `org_slug`). */ export const dashboardUrl = "https://dashboard.lazurio.ai/"; export const accountUrl = "https://dashboard.lazurio.ai/settings"; +export const addOrganizationUrl = "https://dashboard.lazurio.ai/add-organization"; +export const organizationDashboardUrl = (slug: string): string => + `https://dashboard.lazurio.ai/orgs/${encodeURIComponent(slug)}`; /** The kind of Environment a preset sets up (decisions 0165, 0169). */ export const presetKinds: Readonly> = { @@ -69,7 +76,7 @@ export function shellOrganizations( Object.freeze({ slug, name: shellName(organization.displayName, slug), - accent: null, + dashboard: organizationDashboardUrl(slug), avatar: organization.forgeLogin === undefined ? null @@ -101,6 +108,49 @@ export function shellName(name: string | null, slug: string): string { } const origin = (value: string) => `${value}/`; +const githubPhoto = (login: string) => + `https://github.com/${encodeURIComponent(login)}.png?size=96`; + +/** The name of a Team-bound Environment: a Team Environment is its Team's + * ("Team Sales"), an Automated Environment its persona's Team ("Steward"), + * by the Team's display name in the catalog of the Organization that owns + * the Environment. Null when the binding names no Team or the catalog does + * not know it: the elements then name it by its kind. */ +export function teamLabel( + machine: MachineBinding | null, + kind: ShellEnvironmentKind, + catalog: Catalog, +): string | null { + if (machine === null || machine.owner.kind !== "organization") return null; + const { organization, team } = machine.owner; + if (team === null || (kind !== "team" && kind !== "automated")) return null; + const same = (left: string | null | undefined, right: string) => + typeof left === "string" && left.toLowerCase() === right.toLowerCase(); + const owner = catalog.organizations.find( + (entry) => + same(entry.forgeLogin, organization) || + same(entry.organization, organization), + ); + const declared = owner?.teams.find((entry) => same(entry.slug, team)); + if (declared === undefined) return null; + const name = shellName(declared.displayName, declared.slug); + return kind === "team" && !/^team\b/i.test(name) + ? shellName(`Team ${name}`, declared.slug) + : name; +} + +/** The person a work Environment is assigned to, for its "who" line. */ +export function assigneeLogin( + machine: MachineBinding | null, + kind: ShellEnvironmentKind, +): string | null { + if (kind !== "work" || machine === null) return null; + if (machine.owner.kind !== "organization") return null; + const assignment = machine.owner.assignment; + return assignment !== undefined && assignment.kind === "operator" + ? assignment.githubLogin + : null; +} /** This Environment's shell document. */ export function shellDocument( @@ -124,11 +174,12 @@ export function shellDocument( operator: { initials: login === null ? null : initialsOf(login).slice(0, 2) || null, login, + avatar: login === null ? null : githubPhoto(login), }, environments: [ { id, - label: machine?.name ?? null, + label: teamLabel(machine, kind, input.catalog), kind, // A personal Environment belongs to no Organization, whatever its // Folder holds. @@ -136,6 +187,7 @@ export function shellDocument( kind === "personal" ? [] : organizations.map((organization) => organization.slug), + assignee: assigneeLogin(machine, kind), apps: entry === undefined ? { apps: "/", chat: null, automate: null } @@ -152,6 +204,7 @@ export function shellDocument( organizations, dashboard: dashboardUrl, account: accountUrl, + addOrganization: addOrganizationUrl, }; // The producer's own output passes the same parser as every consumer's. const parsed = parseShell(document); diff --git a/src/shell/contract.ts b/src/shell/contract.ts index 5fbb463f7..f5b4097e7 100644 --- a/src/shell/contract.ts +++ b/src/shell/contract.ts @@ -1,11 +1,14 @@ -// The data contract of the Lazurio shell (decision F36): `lazurio.shell.v1`, -// the document the Launchpad serves at `/.lazurio/shell.json` on the -// Environment's origin and the elements of `/.lazurio/shell.js` draw. It names -// the Environment the page is served from, the other Environments the rail may -// show, their Organizations and the addresses of the apps. Today the Launchpad -// knows one Environment, its own; the Dashboard fills the others later through -// the Lazurio account, in this same shape, so the elements do not change. -// Pure: no DOM and no I/O, shared by the producer, the page and the elements. +// The data contract of the Lazurio shell (decision F36 and its addendum of +// 2026-10-04): `lazurio.shell.v1`, the document the Launchpad serves at +// `/.lazurio/shell.json` on the Environment's origin and the elements of +// `/.lazurio/shell.js` draw. It names the Environment the page is served +// from, the other Environments the person may enter, their Organizations +// with their Dashboards, and the addresses of the apps. Today the Launchpad +// knows one Environment, its own; the Dashboard fills the others later +// through the Lazurio account, in this same shape, so the elements do not +// change. Pure: no DOM and no I/O, shared by the producer, the page and the +// elements. The producer and the elements ship in one binary and no fork +// reads it yet, so the shape changes in place, without a compatibility layer. export const shellSchema = "lazurio.shell.v1"; @@ -35,13 +38,17 @@ export type ShellApps = Readonly<{ export type ShellEnvironment = Readonly<{ /** Stable within the document; `current` names one of them. */ id: string; - /** The name the rail shows; null for the workstation, which the elements - * name in the person's language. */ + /** Its own name when it has one: a Team Environment's Team, an Automated + * Environment's persona. Null: the elements name it by its kind + * (Pracovní, Osobní, Tento počítač). Never the machine's technical name. */ label: string | null; kind: ShellEnvironmentKind; /** The slugs of `organizations` it holds, in order; empty for a personal - * one. An Organization's Environment sits in that Organization's folder. */ + * one. A workstation may hold several. */ organizations: readonly string[]; + /** The GitHub login of the one person a work Environment is assigned to, + * for its "who" line; null otherwise. */ + assignee: string | null; apps: ShellApps; }>; @@ -49,20 +56,21 @@ export type ShellOrganization = Readonly<{ /** The Organization slug, as the catalog names it. */ slug: string; name: string; - /** The Organization's accent colour (`#rrggbb`), from data, never from the - * design system; null until a source records it, and the elements then use - * the design system's accent. */ - accent: string | null; /** An https URL of the GitHub Organization's avatar; null shows its * initials. */ avatar: string | null; + /** The Organization's page in the Dashboard (the head of the picker). */ + dashboard: string; }>; export type ShellOperator = Readonly<{ - /** Up to three letters for the account mark; null shows a person icon. */ + /** Up to three letters for the personal space; null shows a person icon. */ initials: string | null; /** The GitHub login, when the Environment knows whose it is. */ login: string | null; + /** An https URL of the person's GitHub photo, for the account; null shows + * the initials. */ + avatar: string | null; }>; export type Shell = Readonly<{ @@ -74,10 +82,13 @@ export type Shell = Readonly<{ operator: ShellOperator; environments: readonly ShellEnvironment[]; organizations: readonly ShellOrganization[]; - /** The Lazurio Dashboard (the logo at the top of the rail). */ + /** The personal Dashboard (the logo at the top of the rail). */ dashboard: string; /** The account settings in the Dashboard (the account at the bottom). */ account: string; + /** Where an Organization is added (the "+" under the Organizations); null + * hides it. */ + addOrganization: string | null; }>; type Data = Readonly>; @@ -120,6 +131,8 @@ const isAppsUrl = (value: unknown): value is string => const slug = /^[A-Za-z0-9](?:[A-Za-z0-9_.-]{0,98}[A-Za-z0-9])?$/; const initials = /^[\p{Lu}\p{N}]{1,3}$/u; const login = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/; +const isLogin = (value: unknown): value is string => + typeof value === "string" && login.test(value); function apps(value: unknown): ShellApps | null { if (!isRecord(value)) return null; @@ -139,7 +152,7 @@ function apps(value: unknown): ShellApps | null { function environment(value: unknown): ShellEnvironment | null { if (!isRecord(value)) return null; - const { id, label, kind, organizations } = value; + const { id, label, kind, organizations, assignee } = value; const own = apps(value.apps); if ( !text(id, 128) || @@ -147,6 +160,7 @@ function environment(value: unknown): ShellEnvironment | null { !(shellEnvironmentKinds as readonly unknown[]).includes(kind) || !Array.isArray(organizations) || !organizations.every((entry) => typeof entry === "string") || + !(assignee === null || isLogin(assignee)) || own === null ) return null; @@ -155,29 +169,27 @@ function environment(value: unknown): ShellEnvironment | null { label: label as string | null, kind: kind as ShellEnvironmentKind, organizations: Object.freeze([...(organizations as string[])]), + assignee: assignee as string | null, apps: own, }); } function organization(value: unknown): ShellOrganization | null { if (!isRecord(value)) return null; - const { accent, avatar, name } = value; + const { avatar, name, dashboard } = value; if ( typeof value.slug !== "string" || !slug.test(value.slug) || !text(name, 128) || - !( - accent === null || - (typeof accent === "string" && /^#[0-9a-f]{6}$/i.test(accent)) - ) || - !(avatar === null || isShellUrl(avatar)) + !(avatar === null || isShellUrl(avatar)) || + !isShellUrl(dashboard) ) return null; return Object.freeze({ slug: value.slug, name, - accent: accent as string | null, avatar: avatar as string | null, + dashboard, }); } @@ -190,6 +202,8 @@ export function parseShell(input: unknown): Shell | null { if (!isRecord(input) || input.schema !== shellSchema) return null; if (input.locale !== "cs" && input.locale !== "en") return null; if (!isShellUrl(input.dashboard) || !isShellUrl(input.account)) return null; + if (!(input.addOrganization === null || isShellUrl(input.addOrganization))) + return null; const operator = input.operator; if ( !isRecord(operator) || @@ -198,10 +212,8 @@ export function parseShell(input: unknown): Shell | null { (typeof operator.initials === "string" && initials.test(operator.initials)) ) || - !( - operator.login === null || - (typeof operator.login === "string" && login.test(operator.login)) - ) + !(operator.login === null || isLogin(operator.login)) || + !(operator.avatar === null || isShellUrl(operator.avatar)) ) return null; if (!Array.isArray(input.environments) || !Array.isArray(input.organizations)) @@ -229,11 +241,13 @@ export function parseShell(input: unknown): Shell | null { operator: Object.freeze({ initials: operator.initials as string | null, login: operator.login as string | null, + avatar: operator.avatar as string | null, }), environments: Object.freeze(envs), organizations: Object.freeze(orgs), dashboard: input.dashboard, account: input.account, + addOrganization: input.addOrganization as string | null, }); } diff --git a/src/shell/elements.ts b/src/shell/elements.ts index 6e354e737..f5f3a8185 100644 --- a/src/shell/elements.ts +++ b/src/shell/elements.ts @@ -1,26 +1,31 @@ -import { parseShell, type Shell } from "./contract"; +import { currentEnvironment, parseShell, type Shell } from "./contract"; import { installShellFonts } from "./fonts"; import { icon } from "./icons"; -import { type ShellCopy, shellMessages } from "./messages"; +import { fillShell, type ShellCopy, shellMessages } from "./messages"; import { columnHeadCss, railCss, railWidth } from "./styles"; import { vendorText } from "./vendor-text" with { type: "macro" }; import { - jumpList, - moreText, - type RailFolder, - type RailItem, - railModel, + environmentGlyph, + environmentName, + environmentWho, + hereOf, + initialsOf, + railSpaces, type ShellApp, shellApps, + type SwitcherSection, + switcherSections, switchTabs, } from "./view"; -// The Lazurio shell as framework-free custom elements (decision F36): -// `` (level 1: the logo to the Dashboard, the jump to an -// Environment, the personal Environments, the Organization folders, the -// gear and the account) and `` (the switch -// Chat · Apps · Automate at the top of an app's left column). Each draws into -// its own shadow root, so neither the host's styles nor these leak across. +// The Lazurio shell as framework-free custom elements (decision F36, +// addendum of 2026-10-04): `` (level 1: the logo to the +// Dashboard, the jump to an Environment, your personal space, one avatar per +// Organization, the account) and `` (the head of an +// app's left column: the Environment picker with the gear of this +// Environment's Settings beside it, then the switch Chat · Apps · Automate). +// Each draws into its own shadow root, so neither the host's styles nor these +// leak across. The panel below the head stays the app's own. // `` is reserved for Buddy's bubble (decision 0180) and not // defined here. // @@ -29,11 +34,16 @@ import { // their own origin once (the forks). A host that provides it marks // `` so nothing is fetched twice. // +// Attributes: `app` on the rail (`chat`, `apps`, `automate`: a click on a +// space stays in that app), `space` on both (the space you are in, when the +// host knows it better than the document: a workstation opened for one +// Organization), `active` (`chat`, `apps`, `automate` or `settings`) and +// `settings` (the Settings address) on the head. +// // Events, both cancelable and composed, so a host can take a click over: // `lazurio-navigate` (detail `{ href }`) for a link on the document's own -// origin (the gear, the Apps tab, the current Environment), and -// `lazurio-app` (detail `{ app, href }`) for a switch tab. Without a -// listener that cancels them, the links simply navigate. +// origin, and `lazurio-app` (detail `{ app, href }`) for a switch tab. +// Without a listener that cancels them, the links simply navigate. const logo = vendorText("symbol-color.svg"); @@ -67,6 +77,30 @@ function requestShell(): void { .catch(() => undefined); } +// Where you last were in each space, in this browser: a click on a space in +// the rail returns there. Only Environment ids of the document are kept. +const lastKey = "lazurio.shell.last"; +function lastBySpace(): Record { + try { + const value: unknown = JSON.parse(localStorage.getItem(lastKey) ?? "{}"); + return value && typeof value === "object" && !Array.isArray(value) + ? (value as Record) + : {}; + } catch { + return {}; + } +} +function remember(space: string, environment: string) { + try { + const last = lastBySpace(); + if (last[space] === environment) return; + localStorage.setItem( + lastKey, + JSON.stringify({ ...last, [space]: environment }), + ); + } catch {} +} + const sameOrigin = (href: string) => href.startsWith("/") && !href.startsWith("//"); @@ -88,6 +122,26 @@ function element( return node; } +/** An Organization's avatar, or its initials when there is none or it does + * not load. */ +function organizationMark( + avatar: string | null, + initials: string, +): HTMLSpanElement { + const mark = element("span", "org-mark"); + const fallback = () => mark.replaceChildren(initials); + if (avatar === null) fallback(); + else { + const image = element("img"); + image.alt = ""; + image.referrerPolicy = "no-referrer"; + image.src = avatar; + image.addEventListener("error", fallback, { once: true }); + mark.append(image); + } + return mark; +} + abstract class ShellElement extends HTMLElement { protected readonly root: ShadowRoot; private readonly redraw = () => this.render(); @@ -113,9 +167,18 @@ abstract class ShellElement extends HTMLElement { const lang = this.getAttribute("lang"); return shellMessages(lang === "cs" || lang === "en" ? lang : shell.locale); } + protected here(shell: Shell): string { + return hereOf(shell, this.getAttribute("space")); + } + protected app(): ShellApp { + const app = this.getAttribute("app"); + return (shellApps as readonly string[]).includes(app ?? "") + ? (app as ShellApp) + : "apps"; + } /** A link the host may take over: same-origin links announce * `lazurio-navigate` before they navigate. */ - protected link(href: string, className: string): HTMLAnchorElement { + link(href: string, className: string): HTMLAnchorElement { const anchor = element("a", className); anchor.href = href; if (sameOrigin(href)) @@ -136,6 +199,165 @@ abstract class ShellElement extends HTMLElement { protected abstract render(): void; } +/** The list of Environments, as a popover under the picker (one space, + * widened by "Všechny Organizace") or as the ⌘⇧E dialog (every space). */ +class Switcher { + readonly box = element("div", "switcher-box"); + private readonly input = element("input"); + private readonly list = element("div", "switcher-list"); + private readonly foot = element("div", "switcher-foot"); + private query = ""; + private cursor = 0; + private links: HTMLAnchorElement[] = []; + constructor( + private readonly host: ShellElement, + private readonly shell: Shell, + private readonly copy: ShellCopy, + private readonly options: { + here: string; + app: ShellApp; + all: boolean; + popover: boolean; + close: () => void; + }, + ) { + const search = element("label", "switcher-search"); + this.input.type = "search"; + this.input.setAttribute("aria-label", copy.switcher); + this.input.addEventListener("input", () => { + this.query = this.input.value; + this.cursor = 0; + this.fill(); + }); + this.input.addEventListener("keydown", (event) => this.key(event)); + search.append(icon("search", 16), this.input, element("span", "kbd", "⌘⇧E")); + this.box.setAttribute("role", "dialog"); + this.box.setAttribute("aria-label", copy.switcher); + this.box.append(search, this.list, this.foot); + this.fill(); + } + focus() { + this.input.focus(); + } + private key(event: KeyboardEvent) { + if (event.key === "Escape") { + event.preventDefault(); + this.options.close(); + return; + } + if (event.key === "ArrowDown" || event.key === "ArrowUp") { + event.preventDefault(); + const count = this.links.length; + if (count === 0) return; + this.cursor = + (this.cursor + (event.key === "ArrowDown" ? 1 : -1) + count) % count; + this.mark(); + return; + } + if (event.key === "Enter") { + event.preventDefault(); + this.links[this.cursor]?.click(); + } + } + private mark() { + this.links.forEach((link, index) => + link.classList.toggle("is-cursor", index === this.cursor), + ); + this.links[this.cursor]?.scrollIntoView({ block: "nearest" }); + } + private fill() { + const { copy, shell, options } = this; + const sections = switcherSections(shell, copy, { + here: options.here, + all: options.all, + app: options.app, + query: this.query, + }); + const scope = sections[0]?.title ?? copy.personal; + this.input.placeholder = options.all + ? copy.searchAll + : fillShell(copy.searchIn, { name: scope }); + this.links = []; + this.list.replaceChildren( + ...sections.map((section) => this.section(section)), + ); + if (this.links.length === 0 && (options.all || this.query.trim() !== "")) + this.list.append(element("p", "switcher-empty", copy.nothing)); + this.cursor = Math.min(this.cursor, Math.max(0, this.links.length - 1)); + this.mark(); + const hints: Node[] = []; + if (!options.all) { + const widen = element("button", "switcher-widen"); + widen.type = "button"; + widen.append(icon("globe", 14), copy.widen); + widen.addEventListener("click", () => { + options.all = true; + this.cursor = 0; + this.fill(); + this.input.focus(); + }); + hints.push(widen); + } + const hint = (key: string, word: string) => { + const span = element("span"); + span.append(element("span", "kbd", key), ` ${word}`); + return span; + }; + hints.push(hint("↑↓", copy.choose), hint("Enter", copy.go)); + if (!options.popover) hints.push(hint("Esc", copy.close)); + this.foot.replaceChildren(...hints); + } + private track(link: HTMLAnchorElement) { + const at = this.links.length; + this.links.push(link); + link.addEventListener("mouseenter", () => { + this.cursor = at; + this.mark(); + }); + link.addEventListener("click", () => this.options.close()); + return link; + } + private section(section: SwitcherSection): HTMLElement { + const { copy } = this; + const group = element("div", "switcher-group"); + if (section.head !== null) { + const { organization, href } = section.head; + const head = this.track(this.host.link(href, "switcher-head")); + head.append( + organizationMark(organization.avatar, initialsOf(organization.name)), + element("span", "", organization.name), + element("span", "switcher-head-meta", copy.organizationDashboard), + ); + group.append(head); + } else group.append(element("div", "switcher-title", section.title)); + for (const row of section.rows) { + const link = this.track(this.host.link(row.href, "switcher-row")); + if (row.current) link.setAttribute("aria-current", "page"); + const glyph = element("span", "switcher-glyph"); + if (row.glyph.kind === "initials") glyph.textContent = row.glyph.text; + else glyph.append(icon(row.glyph.icon, 16)); + link.append( + glyph, + element("span", "switcher-name", row.name), + element("span", "switcher-who", row.who), + ); + if (row.current) { + const here = element("span", "switcher-here"); + here.append(icon("check", 14), copy.here); + link.append(here); + } + group.append(link); + } + if ( + section.head !== null && + section.rows.length === 0 && + this.query.trim() === "" + ) + group.append(element("p", "switcher-empty", copy.noEnvironment)); + return group; + } +} + // One rail at a time answers ⌘⇧E / Ctrl+Shift+E: the last one connected. let jumpTarget: LazurioRail | null = null; let shortcutInstalled = false; @@ -158,8 +380,7 @@ function installShortcut() { } export class LazurioRail extends ShellElement { - static observedAttributes = ["settings", "lang"]; - private readonly expanded = new Set(); + static observedAttributes = ["app", "space", "lang"]; private tip: HTMLDivElement | null = null; private jump: HTMLDialogElement | null = null; constructor() { @@ -179,49 +400,21 @@ export class LazurioRail extends ShellElement { if (jumpTarget === this) jumpTarget = null; } - /** Opens the jump list of Environments (⌘⇧E). */ + /** Opens the jump to any Environment (⌘⇧E). */ openJump() { - if (current === null || this.jump === null) return; - if (!this.jump.open) this.jump.showModal(); - const input = this.jump.querySelector("input"); - if (input) { - input.value = ""; - this.fillJump(""); - input.focus(); - } - } - - private fillJump(query: string) { - if (current === null || this.jump === null) return; - const copy = this.copy(current); - const list = this.jump.querySelector("ul"); - const empty = this.jump.querySelector(".jump-empty"); - if (!list || !empty) return; - const entries = jumpList(current, copy, query); - list.replaceChildren( - ...entries.map((entry) => { - const item = element("li"); - const anchor = this.link(entry.href, ""); - if (entry.active) anchor.setAttribute("aria-current", "page"); - anchor.append( - element("strong", "", entry.label), - element("span", "", entry.sub), - ); - anchor.addEventListener("click", () => this.jump?.close()); - item.append(anchor); - return item; - }), - ); - empty.hidden = entries.length > 0; - } - - private settingsHref(shell: Shell): string { - const own = this.getAttribute("settings"); - if (own) return own; - const apps = shell.environments.find((entry) => entry.id === shell.current) - ?.apps.apps; - if (apps === undefined || sameOrigin(apps)) return "/settings"; - return new URL("settings", apps).href; + const shell = current; + if (shell === null || this.jump === null) return; + const dialog = this.jump; + const switcher = new Switcher(this, shell, this.copy(shell), { + here: this.here(shell), + app: this.app(), + all: true, + popover: false, + close: () => dialog.close(), + }); + dialog.replaceChildren(switcher.box); + if (!dialog.open) dialog.showModal(); + switcher.focus(); } private withTip(node: T, title: string, sub: string) { @@ -230,67 +423,6 @@ export class LazurioRail extends ShellElement { return node; } - private envItem(entry: RailItem): HTMLAnchorElement { - const anchor = this.withTip( - this.link(entry.href, "item env"), - entry.label, - entry.sub, - ); - anchor.setAttribute("aria-label", entry.label); - if (entry.active) anchor.setAttribute("aria-current", "page"); - if (entry.accent !== null) - anchor.style.setProperty("--env-accent", entry.accent); - anchor.append( - entry.mark.kind === "initials" - ? element("span", "initials", entry.mark.text) - : icon(entry.mark.icon, 20), - ); - return anchor; - } - - private folder(entry: RailFolder, copy: ShellCopy): HTMLDivElement { - const box = element("div", `folder${entry.hasActive ? " has-active" : ""}`); - box.style.setProperty( - "--env-accent", - entry.organization.accent ?? "var(--lz-accent-strong)", - ); - const head = this.withTip( - element("span", "folder-head"), - entry.organization.name, - copy.organizationSub, - ); - const mark = element("span", "mark"); - const fallback = () => mark.replaceChildren(entry.initials); - if (entry.organization.avatar !== null) { - const image = element("img"); - image.alt = ""; - image.referrerPolicy = "no-referrer"; - image.src = entry.organization.avatar; - image.addEventListener("error", fallback, { once: true }); - mark.append(image); - } else fallback(); - head.append(mark, element("span", "sr-only", entry.organization.name)); - box.append(head, ...entry.items.map((item) => this.envItem(item))); - if (entry.hidden > 0 || entry.expanded) { - const words = moreText(copy, entry); - const more = this.withTip( - element("button", "more", words.text), - words.label, - "", - ); - more.type = "button"; - more.setAttribute("aria-label", words.label); - more.setAttribute("aria-expanded", String(entry.expanded)); - more.addEventListener("click", () => { - if (entry.expanded) this.expanded.delete(entry.organization.slug); - else this.expanded.add(entry.organization.slug); - this.render(); - }); - box.append(more); - } - return box; - } - protected render() { const shell = current; if (shell === null) { @@ -298,7 +430,14 @@ export class LazurioRail extends ShellElement { return; } const copy = this.copy(shell); - const model = railModel(shell, copy, this.expanded); + const here = this.here(shell); + remember(here, shell.current); + const last = lastBySpace(); + const spaces = railSpaces(shell, copy, { + here, + app: this.app(), + last: (space) => last[space] ?? null, + }); const nav = element("nav"); nav.setAttribute("aria-label", copy.rail); @@ -315,7 +454,7 @@ export class LazurioRail extends ShellElement { home.append(image); const search = this.withTip( - element("button", "item utility search"), + element("button", "item search"), copy.jump, copy.jumpShortcut, ); @@ -326,18 +465,35 @@ export class LazurioRail extends ShellElement { search.addEventListener("click", () => this.openJump()); const scroll = element("div", "scroll"); - scroll.append(...model.personal.map((entry) => this.envItem(entry))); - if (model.personal.length > 0 && model.folders.length > 0) - scroll.append(element("div", "divider")); - scroll.append(...model.folders.map((entry) => this.folder(entry, copy))); - - const gear = this.withTip( - this.link(this.settingsHref(shell), "item utility"), - copy.settings, - copy.settingsSub, - ); - gear.setAttribute("aria-label", copy.settings); - gear.append(icon("settings", 20)); + spaces.forEach((space, index) => { + if (index === 1) scroll.append(element("div", "divider")); + const link = this.withTip( + this.link(space.href, "item space"), + space.title, + space.sub, + ); + link.setAttribute("aria-label", space.title); + if (space.active) link.setAttribute("aria-current", "true"); + if (index === 0) { + const mark = element("span", "initials"); + if (space.initials !== null) mark.textContent = space.initials; + else mark.append(icon("user", 18)); + link.append(mark); + } else + link.append(organizationMark(space.avatar, space.initials ?? "")); + scroll.append(link); + }); + if (shell.addOrganization !== null) { + const add = this.withTip( + element("a", "item add"), + copy.addOrganization, + "", + ); + add.href = shell.addOrganization; + add.setAttribute("aria-label", copy.addOrganization); + add.append(icon("plus", 18)); + scroll.append(add); + } const account = this.withTip( element("a", "item account"), @@ -346,11 +502,23 @@ export class LazurioRail extends ShellElement { ); account.href = shell.account; account.setAttribute("aria-label", copy.account); - const avatar = element("span", "avatar"); - if (shell.operator.initials !== null) - avatar.textContent = shell.operator.initials; - else avatar.append(icon("user", 18)); - account.append(avatar); + const photo = () => { + const mark = element("span", "avatar"); + if (shell.operator.initials !== null) + mark.textContent = shell.operator.initials; + else mark.append(icon("user", 18)); + return mark; + }; + if (shell.operator.avatar !== null) { + const picture = element("img", "avatar"); + picture.alt = ""; + picture.referrerPolicy = "no-referrer"; + picture.src = shell.operator.avatar; + picture.addEventListener("error", () => picture.replaceWith(photo()), { + once: true, + }); + account.append(picture); + } else account.append(photo()); // The rail's own label: at once, beside the item, two lines. const tip = element("div", "tip"); @@ -359,38 +527,13 @@ export class LazurioRail extends ShellElement { tip.append(element("strong"), element("span")); this.tip = tip; - const jump = element("dialog"); - jump.setAttribute("aria-label", copy.jumpTitle); - const head = element("label", "jump-head"); - const input = element("input"); - input.type = "search"; - input.placeholder = copy.jumpTitle; - input.setAttribute("aria-label", copy.jumpTitle); - input.addEventListener("input", () => this.fillJump(input.value)); - input.addEventListener("keydown", (event) => { - if (event.key !== "Enter") return; - jump.querySelector("ul a")?.click(); - }); - head.append(icon("search", 16), input); - jump.append( - head, - element("ul", "jump-list"), - element("p", "jump-empty", copy.jumpEmpty), - ); + const jump = element("dialog", "switcher-dialog"); jump.addEventListener("click", (event) => { if (event.target === jump) jump.close(); }); this.jump = jump; - nav.append( - home, - search, - element("div", "divider"), - scroll, - gear, - account, - tip, - ); + nav.append(home, search, element("div", "divider"), scroll, account, tip); const show = (event: Event) => { const target = event .composedPath() @@ -420,26 +563,121 @@ export class LazurioRail extends ShellElement { } export class LazurioColumnHead extends ShellElement { - static observedAttributes = ["active", "lang"]; + static observedAttributes = ["active", "settings", "space", "lang"]; + private open: { close: () => void } | null = null; constructor() { super(columnHeadCss); } + override disconnectedCallback() { + super.disconnectedCallback(); + this.open?.close(); + } + + private settingsHref(shell: Shell): string { + const own = this.getAttribute("settings"); + if (own) return own; + const apps = currentEnvironment(shell).apps.apps; + if (sameOrigin(apps)) return "/settings"; + return new URL("settings", apps).href; + } + + /** Opens the list of this space's Environments under the picker. */ + private toggle(picker: HTMLButtonElement, shell: Shell) { + if (this.open !== null) { + this.open.close(); + return; + } + const copy = this.copy(shell); + const backdrop = element("div", "switcher-backdrop"); + const close = () => { + backdrop.remove(); + switcher.box.remove(); + picker.setAttribute("aria-expanded", "false"); + document.removeEventListener("keydown", escape, true); + this.open = null; + }; + const escape = (event: KeyboardEvent) => { + if (event.key !== "Escape") return; + event.preventDefault(); + close(); + picker.focus(); + }; + const switcher = new Switcher(this, shell, copy, { + here: this.here(shell), + app: this.activeApp() ?? "apps", + all: false, + popover: true, + close, + }); + const rect = picker.getBoundingClientRect(); + switcher.box.classList.add("switcher-popover"); + switcher.box.style.top = `${rect.bottom + 6}px`; + switcher.box.style.left = `${rect.left}px`; + switcher.box.style.width = `${Math.min(Math.max(rect.width, 400), window.innerWidth - rect.left - 8)}px`; + backdrop.addEventListener("click", close); + document.addEventListener("keydown", escape, true); + this.root.append(backdrop, switcher.box); + picker.setAttribute("aria-expanded", "true"); + this.open = { close }; + switcher.focus(); + } + + private activeApp(): ShellApp | null { + const active = this.getAttribute("active"); + return (shellApps as readonly string[]).includes(active ?? "") + ? (active as ShellApp) + : null; + } + protected render() { + this.open?.close(); const shell = current; if (shell === null) { this.root.replaceChildren(); return; } const copy = this.copy(shell); - const active = this.getAttribute("active"); - const tabs = switchTabs( - shell, - copy, - (shellApps as readonly string[]).includes(active ?? "") - ? (active as ShellApp) - : null, + const here = this.here(shell); + const environment = currentEnvironment(shell); + const name = environmentName(environment, copy); + + const picker = element("button", "pick"); + picker.type = "button"; + picker.setAttribute("aria-haspopup", "dialog"); + picker.setAttribute("aria-expanded", "false"); + picker.setAttribute("aria-label", fillShell(copy.pick, { name })); + const glyph = element("span", "pick-glyph"); + const look = environmentGlyph(shell, environment, here); + if (look.kind === "avatar") + glyph.append( + organizationMark( + look.organization.avatar, + initialsOf(look.organization.name), + ), + ); + else if (look.kind === "initials") + glyph.append(element("span", "initials", look.text)); + else glyph.append(icon(look.icon, 18)); + const text = element("span", "pick-text"); + text.append( + element("span", "pick-title", name), + element("span", "pick-who", environmentWho(environment, copy)), ); - const nav = element("nav"); + picker.append(glyph, text, icon("chevron-down", 14)); + picker.addEventListener("click", () => this.toggle(picker, shell)); + + const gear = this.link(this.settingsHref(shell), "gear"); + gear.setAttribute("aria-label", copy.settings); + gear.title = copy.settings; + if (this.getAttribute("active") === "settings") + gear.setAttribute("aria-current", "page"); + gear.append(icon("settings", 18)); + + const row = element("div", "row"); + row.append(picker, gear); + + const tabs = switchTabs(shell, copy, this.activeApp()); + const nav = element("nav", "switch"); nav.setAttribute("aria-label", copy.switchLabel); nav.append( ...tabs.map((tab) => { @@ -473,7 +711,9 @@ export class LazurioColumnHead extends ShellElement { return anchor; }), ); - this.root.replaceChildren(nav); + const head = element("div", "head"); + head.append(row, nav); + this.root.replaceChildren(head); } } diff --git a/src/shell/icons.ts b/src/shell/icons.ts index 6864d1ded..d35ca353f 100644 --- a/src/shell/icons.ts +++ b/src/shell/icons.ts @@ -15,6 +15,11 @@ const paths = { apps: '', automate: '', + "chevron-down": '', + check: '', + globe: + '', + plus: '', } as const; export type ShellIcon = keyof typeof paths; diff --git a/src/shell/messages.ts b/src/shell/messages.ts index 649a2149b..88d267371 100644 --- a/src/shell/messages.ts +++ b/src/shell/messages.ts @@ -11,100 +11,136 @@ export type ShellCopy = Readonly<{ dashboardSub: string; jump: string; jumpShortcut: string; - jumpTitle: string; - jumpEmpty: string; - settings: string; - settingsSub: string; + personal: string; + addOrganization: string; account: string; accountSub: string; - thisComputer: string; - personal: string; - organizationSub: string; - more: string; - moreNamed: string; - less: string; - lessNamed: string; - current: string; - kinds: Readonly>; + /** "{count} Environment(s)" by the Czech plural. */ + environmentsOne: string; + environmentsFew: string; + environmentsMany: string; + last: string; + /** The name of an Environment without its own name, by kind. */ + names: Readonly>; + /** Who an Environment is for, by kind. */ + who: Readonly>; + pick: string; + settings: string; + switcher: string; + searchIn: string; + searchAll: string; + organizationDashboard: string; + here: string; + noEnvironment: string; + nothing: string; + widen: string; + choose: string; + go: string; + close: string; switchLabel: string; chat: string; apps: string; automate: string; chatMissing: string; automateMissing: string; - close: string; }>; const en: ShellCopy = { - rail: "Environments and Organizations", + rail: "Organizations", dashboard: "Dashboard", dashboardSub: "Your overview across Organizations", jump: "Go to an Environment", jumpShortcut: "⌘⇧E", - jumpTitle: "Go to an Environment", - jumpEmpty: "No Environment matches.", - settings: "Environment Settings", - settingsSub: "Settings of this Environment", + personal: "Personal", + addOrganization: "Add an Organization", account: "Lazurio account", accountSub: "Account settings in the Dashboard", - thisComputer: "This computer", - personal: "Personal", - organizationSub: "Organization", - more: "+{count}", - moreNamed: "Show {count} more Environments of {name}", - less: "less", - lessNamed: "Show fewer Environments of {name}", - current: "you are here", - kinds: { - personal: "personal", - work: "work", + environmentsOne: "{count} Environment", + environmentsFew: "{count} Environments", + environmentsMany: "{count} Environments", + last: "last {name}", + names: { + personal: "Personal", + work: "Work", team: "Team", - automated: "automated", + automated: "Automated", + workstation: "This computer", + }, + who: { + personal: "only yours", + work: "work", + team: "shared by the Team", + automated: "automation", workstation: "this computer", }, + pick: "{name}, switch Environment", + settings: "Environment Settings", + switcher: "Go to an Environment", + searchIn: "Search in {name}…", + searchAll: "Environment or Organization…", + organizationDashboard: "Organization Dashboard", + here: "you are here", + noEnvironment: "You have no Environment here.", + nothing: "Nothing like that here.", + widen: "All Organizations", + choose: "choose", + go: "go", + close: "close", switchLabel: "Apps of this Environment", chat: "Chat", apps: "Apps", automate: "Automate", chatMissing: "Chat does not run on this Environment", automateMissing: "MausBot does not run on this Environment", - close: "Close", }; const cs: ShellCopy = { - rail: "Environmenty a Organizace", + rail: "Organizace", dashboard: "Dashboard", - dashboardSub: "Tvůj přehled napříč Organizacemi", + dashboardSub: "tvůj přehled napříč Organizacemi", jump: "Přejít na Environment", jumpShortcut: "⌘⇧E", - jumpTitle: "Přejít na Environment", - jumpEmpty: "Žádný Environment neodpovídá.", - settings: "Nastavení Environmentu", - settingsSub: "Nastavení tohoto Environmentu", + personal: "Osobní", + addOrganization: "Přidat organizaci", account: "Lazurio účet", accountSub: "Nastavení účtu v Dashboardu", - thisComputer: "Tento počítač", - personal: "Osobní", - organizationSub: "Organizace", - more: "+{count}", - moreNamed: "Ukázat dalších {count} Environmentů v {name}", - less: "méně", - lessNamed: "Ukázat méně Environmentů v {name}", - current: "tady jsi", - kinds: { - personal: "osobní", + environmentsOne: "{count} Environment", + environmentsFew: "{count} Environmenty", + environmentsMany: "{count} Environmentů", + last: "naposledy {name}", + names: { + personal: "Osobní", + work: "Pracovní", + team: "Týmový", + automated: "Automatizovaný", + workstation: "Tento počítač", + }, + who: { + personal: "jen tvůj", work: "pracovní", - team: "týmový", - automated: "automatizovaný", + team: "sdílený Teamem", + automated: "automatizace", workstation: "tento počítač", }, + pick: "{name}, přepnout Environment", + settings: "Nastavení Environmentu", + switcher: "Přejít na Environment", + searchIn: "Hledat v {name}…", + searchAll: "Environment nebo Organizace…", + organizationDashboard: "Dashboard Organizace", + here: "tady jsi", + noEnvironment: "Tady nemáš žádný Environment.", + nothing: "Nic takového tu není.", + widen: "Všechny Organizace", + choose: "vybrat", + go: "přejít", + close: "zavřít", switchLabel: "Aplikace Environmentu", chat: "Chat", apps: "Apps", automate: "Automate", chatMissing: "Chat na tomto Environmentu neběží", automateMissing: "MausBot na tomto Environmentu neběží", - close: "Zavřít", }; export const shellMessages = (locale: "cs" | "en"): ShellCopy => diff --git a/src/shell/styles.ts b/src/shell/styles.ts index 4bb8fce20..91d0dfb35 100644 --- a/src/shell/styles.ts +++ b/src/shell/styles.ts @@ -5,73 +5,112 @@ const tokens = vendorText("tokens.css"); // The styles of the shell elements, inside their shadow roots: the Lazurio // design system's tokens (vendored byte-for-byte, declared on `:root`, here // applied to `:host` so they hold inside the shadow root and nowhere else), -// and the components of the rail and the app switch after the shell -// wireframe (prototypes-lazurio, DEV-6639). Nothing here reaches the host -// page, and the host page's styles do not reach in. +// and the components of the rail, the Environment picker and the app switch +// after the shell wireframe (prototypes-lazurio 1cbad15, the Organization +// rail) and the design system's selection rule (design-system-lazurio +// 5bbc1f7, `lz-picker`, `lz-menu__head`: a quiet surface one step darker, +// full-weight text, a check with a word; no left edge, no shadow, no +// capitals). Nothing here reaches the host page, and the host page's styles +// do not reach in. /** The tokens, scoped to the element. */ export const hostTokens = tokens.replace(":root", ":host"); /** The width the rail takes; the host lays its content beside it with - * `margin-left: var(--lazurio-rail-width, 0)`. */ + * `padding-left: var(--lazurio-rail-width, 0px)`. */ export const railWidth = "72px"; const base = ` -:host { --env-accent: var(--lz-ink); font-family: var(--lz-font-sans); font-size: 15px; font-weight: 400; line-height: 1.4; letter-spacing: normal; text-align: left; text-transform: none; color: var(--lz-ink); -webkit-font-smoothing: antialiased; } +:host { font-family: var(--lz-font-sans); font-size: 15px; font-weight: 400; line-height: 1.4; letter-spacing: normal; text-align: left; text-transform: none; color: var(--lz-ink); -webkit-font-smoothing: antialiased; } *, *::before, *::after { box-sizing: border-box; } [hidden] { display: none !important; } -a, button { font: inherit; color: inherit; } +a, button, input { font: inherit; color: inherit; } :focus-visible { outline: 2px solid var(--lz-accent); outline-offset: 2px; } .sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } +.org-mark { display: grid; flex: none; place-items: center; overflow: hidden; border-radius: var(--lz-radius-sm); background: var(--lz-white); box-shadow: inset 0 0 0 1px var(--lz-line); color: var(--lz-ink); font-weight: var(--lz-weight-akce); letter-spacing: 0.02em; } +.org-mark img { display: block; width: 100%; height: 100%; object-fit: cover; } +`; + +/** The list of Environments: under the picker (one space) and as the ⌘⇧E + * dialog (every space). */ +const switcherCss = ` +.switcher-backdrop { position: fixed; inset: 0; z-index: 70; } +dialog.switcher-dialog { width: min(560px, 92vw); max-height: 64vh; margin: 12vh auto auto; padding: 0; border: 1px solid var(--lz-gray-300); border-radius: 14px; background: var(--lz-white); color: var(--lz-ink); } +dialog.switcher-dialog::backdrop { background: rgb(0 0 0 / 25%); } +.switcher-box { display: flex; flex-direction: column; max-height: inherit; overflow: hidden; background: var(--lz-white); } +.switcher-popover { position: fixed; z-index: 71; max-height: min(72vh, 600px); border: 1px solid var(--lz-gray-300); border-radius: 12px; } +.switcher-search { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--lz-line); color: var(--lz-ink-muted); } +.switcher-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--lz-ink); font-size: 15px; } +.kbd { padding: 1px 6px; border: 1px solid var(--lz-line); border-radius: 6px; color: var(--lz-ink-muted); font-family: var(--lz-font-mono); font-size: 11px; } +.switcher-list { overflow: auto; padding: 6px 8px 10px; } +.switcher-title { padding: 8px 8px 4px; color: var(--lz-ink-muted); font-size: 12px; font-weight: var(--lz-weight-akce); } +.switcher-head { display: flex; width: 100%; align-items: center; gap: 8px; margin: 4px 0 2px; padding: 7px 8px; border-bottom: 1px solid var(--lz-line-faint); border-radius: 8px 8px 0 0; color: var(--lz-ink); font-size: 13px; font-weight: var(--lz-weight-akce); text-decoration: none; } +.switcher-head .org-mark { width: 20px; height: 20px; border-radius: 5px; font-size: 8px; } +.switcher-head-meta { margin-left: auto; color: var(--lz-ink-muted); font-weight: 400; } +.switcher-row { display: flex; width: 100%; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; color: var(--lz-ink); font-size: 14px; text-decoration: none; } +.is-cursor { background: var(--lz-gray-50); } +.switcher-row[aria-current="page"], .switcher-head[aria-current="page"] { background: var(--lz-gray-100); } +.switcher-glyph { display: grid; width: 26px; height: 26px; flex: none; place-items: center; border-radius: 7px; background: var(--lz-gray-50); color: var(--lz-ink-muted); font-size: 11px; font-weight: 700; } +.switcher-row[aria-current="page"] .switcher-glyph { background: var(--lz-white); color: var(--lz-ink); } +.switcher-name { flex: none; font-weight: 550; white-space: nowrap; } +.switcher-row[aria-current="page"] .switcher-name { font-weight: var(--lz-weight-akce); } +.switcher-who { flex: 1; min-width: 0; overflow: hidden; color: var(--lz-ink-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; } +.switcher-here { display: flex; flex: none; align-items: center; gap: 4px; color: var(--lz-ink); font-size: 12px; font-weight: var(--lz-weight-akce); } +.switcher-empty { margin: 0; padding: 6px 8px; color: var(--lz-ink-muted); font-size: 13px; } +.switcher-foot { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--lz-line); color: var(--lz-ink-muted); font-size: 12px; white-space: nowrap; } +.switcher-widen { display: flex; align-items: center; gap: 6px; margin-right: auto; padding: 3px 8px; border: 1px solid var(--lz-line); border-radius: 8px; background: var(--lz-white); color: var(--lz-ink); font-size: 12px; font-weight: 550; cursor: pointer; } +.switcher-widen:hover { background: var(--lz-gray-50); } `; export const railCss = `${hostTokens} ${base} +${switcherCss} :host { position: fixed; inset: 0 auto 0 0; z-index: 40; display: block; width: ${railWidth}; background: var(--lz-gray-50); } nav { display: flex; height: 100%; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; } -.item { position: relative; display: grid; width: 44px; height: 44px; flex: none; place-items: center; padding: 0; border: 0; border-radius: var(--lz-radius-md); background: var(--lz-gray-100); color: var(--lz-ink-muted); cursor: pointer; text-decoration: none; transition: border-radius 120ms ease; } +.item { position: relative; display: grid; width: 44px; height: 44px; flex: none; place-items: center; padding: 0; border: 0; border-radius: var(--lz-radius-md); background: transparent; color: var(--lz-ink-muted); cursor: pointer; text-decoration: none; transition: border-radius 120ms ease; } .item:hover { color: var(--lz-ink); border-radius: 14px; } -.home, .utility, .account { background: transparent; } .home img { width: 30px; height: 30px; display: block; } .search { width: 36px; height: 32px; } .divider { width: 32px; height: 1px; margin: 4px 0; flex: none; background: var(--lz-line); } .scroll { display: flex; width: 100%; min-height: 0; flex: 1; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0 10px; overflow-x: hidden; overflow-y: auto; scrollbar-width: none; } .scroll::-webkit-scrollbar { display: none; } -.env .initials { font-size: 13px; font-weight: 700; letter-spacing: 0.02em; } -.folder { display: flex; flex: none; flex-direction: column; align-items: center; gap: 4px; padding: 4px; border-radius: 14px; background: color-mix(in srgb, var(--env-accent) 18%, var(--lz-white)); } -.folder.has-active { box-shadow: inset 0 0 0 2px var(--env-accent); } -.folder .env { width: 40px; height: 40px; background: var(--lz-white); } -.env[aria-current="page"], .folder .env[aria-current="page"] { background: var(--env-accent); color: var(--lz-white); box-shadow: 0 0 0 2px var(--lz-white), 0 0 0 4.5px var(--env-accent), 0 4px 14px color-mix(in srgb, var(--env-accent) 45%, transparent); } -.env[aria-current="page"]::before { position: absolute; left: -14px; width: 5px; height: 36px; border-radius: 0 4px 4px 0; background: var(--env-accent); content: ""; } -.folder .env[aria-current="page"]::before { left: -18px; } -.folder-head { display: grid; width: 40px; height: 32px; place-items: center; } -.mark { display: grid; width: 24px; height: 24px; place-items: center; overflow: hidden; border-radius: var(--lz-radius-sm); background: var(--lz-white); box-shadow: inset 0 0 0 1px var(--lz-line); color: var(--lz-ink); font-size: 10px; font-weight: 600; letter-spacing: 0.02em; } -.mark img { display: block; width: 100%; height: 100%; object-fit: cover; } -.more { display: grid; width: 40px; height: 22px; place-items: center; padding: 0; border: 0; border-radius: 999px; background: var(--lz-white); color: var(--lz-ink-muted); cursor: pointer; font-size: 11px; font-weight: 650; } -.avatar { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 50%; background: var(--lz-ink); color: var(--lz-white); font-size: 13px; font-weight: 600; } +.space .org-mark, .space .initials { width: 40px; height: 40px; border-radius: 12px; transition: border-radius 120ms ease; } +.space:hover .org-mark, .space:hover .initials { border-radius: 14px; } +.space .org-mark { font-size: 12px; } +.space .initials { display: grid; place-items: center; background: var(--lz-ink); color: var(--lz-white); font-size: 13px; font-weight: 700; letter-spacing: 0.02em; } +.space[aria-current="true"] .org-mark, .space[aria-current="true"] .initials { box-shadow: 0 0 0 2px var(--lz-paper), 0 0 0 4px var(--lz-ink); } +.add { border: 1px dashed var(--lz-line); } +.account .avatar { display: grid; width: 36px; height: 36px; place-items: center; overflow: hidden; border-radius: 50%; background: var(--lz-ink); color: var(--lz-white); font-size: 13px; font-weight: var(--lz-weight-akce); object-fit: cover; } .tip { position: fixed; z-index: 60; display: grid; max-width: 260px; padding: 6px 10px; border-radius: var(--lz-radius-sm); background: var(--lz-ink); color: var(--lz-white); font-size: 13px; line-height: 1.3; pointer-events: none; transform: translateY(-50%); box-shadow: 0 4px 14px rgb(0 0 0 / 18%); } .tip strong { font-weight: 600; } .tip span { color: rgb(255 255 255 / 70%); font-size: 12px; } .tip span:empty { display: none; } -dialog { width: min(28rem, calc(100vw - 2rem)); padding: 0; border: 1px solid var(--lz-line); border-radius: 14px; background: var(--lz-white); color: var(--lz-ink); box-shadow: 0 24px 64px -24px rgb(0 0 0 / 55%); font-family: var(--lz-font-sans); } -dialog::backdrop { background: rgb(0 0 0 / 28%); } -.jump-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--lz-line-faint); color: var(--lz-ink-muted); } -.jump-head input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--lz-ink); font: inherit; font-size: 15px; } -.jump-list { display: grid; gap: 2px; max-height: 50vh; margin: 0; padding: 6px; overflow-y: auto; list-style: none; } -.jump-list a { display: grid; gap: 1px; padding: 8px 10px; border-radius: var(--lz-radius-sm); text-decoration: none; } -.jump-list a:hover, .jump-list a:focus-visible { background: var(--lz-gray-100); outline: none; } -.jump-list strong { font-size: 14px; font-weight: 600; } -.jump-list span { color: var(--lz-ink-muted); font-size: 12.5px; } -.jump-empty { padding: 10px 14px 14px; color: var(--lz-ink-muted); font-size: 13px; } -@media (prefers-reduced-motion: reduce) { .item { transition: none; } } +@media (prefers-reduced-motion: reduce) { .item, .space .org-mark, .space .initials { transition: none; } } `; export const columnHeadCss = `${hostTokens} ${base} +${switcherCss} :host { display: block; } -nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; border-radius: var(--lz-radius-md); background: var(--lz-gray-100); } +.head { display: flex; flex-direction: column; gap: 8px; } +.row { display: flex; align-items: stretch; gap: 6px; } +.pick { display: flex; flex: 1; min-width: 0; align-items: center; gap: 10px; padding: 7px 8px; border: 0; border-radius: var(--lz-radius-md); background: transparent; color: var(--lz-ink); text-align: left; cursor: pointer; } +.pick:hover, .pick[aria-expanded="true"] { background: var(--lz-gray-100); } +.pick-glyph { display: grid; width: 30px; height: 30px; flex: none; place-items: center; border-radius: 8px; color: var(--lz-ink); font-size: 11px; font-weight: 700; } +.pick-glyph .org-mark { width: 24px; height: 24px; font-size: 9px; } +.pick-glyph .initials { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 6px; background: var(--lz-ink); color: var(--lz-white); } +.pick-text { display: grid; flex: 1; min-width: 0; line-height: 1.25; } +.pick-title, .pick-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.pick-title { font-size: 14px; font-weight: 650; } +.pick-who { color: var(--lz-ink-muted); font-size: 12px; } +.pick > svg { flex: none; color: var(--lz-ink-muted); transition: transform 0.15s; } +.pick[aria-expanded="true"] > svg { transform: rotate(180deg); } +.gear { display: grid; width: 40px; flex: none; place-items: center; border-radius: var(--lz-radius-md); color: var(--lz-ink-muted); text-decoration: none; } +.gear:hover, .gear[aria-current="page"] { background: var(--lz-gray-100); color: var(--lz-ink); } +nav.switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; border-radius: var(--lz-radius-md); background: var(--lz-gray-100); } .tab { display: flex; min-width: 0; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px 5px; border-radius: calc(var(--lz-radius-md) - 2px); color: var(--lz-ink-muted); font-size: 11px; font-weight: 550; line-height: 1.25; text-decoration: none; } a.tab:hover { color: var(--lz-ink); } .tab[aria-current="page"] { background: var(--lz-white); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); color: var(--lz-ink); } .tab[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; } +@media (prefers-reduced-motion: reduce) { .pick > svg { transition: none; } } `; diff --git a/src/shell/view.ts b/src/shell/view.ts index 4043f32c5..a0445a1b3 100644 --- a/src/shell/view.ts +++ b/src/shell/view.ts @@ -2,66 +2,24 @@ import { currentEnvironment, type Shell, type ShellEnvironment, - type ShellEnvironmentKind, type ShellOrganization, } from "./contract"; import { fillShell, type ShellCopy } from "./messages"; -// Pure presentation of the shell document for the rail and the app switch -// (decision F36, the target shell of docs/launchpad-development.md): what -// each element shows, in which order, linked where. The elements in -// elements.ts only draw it. +// Pure presentation of the shell document (decision F36, addendum of +// 2026-10-04): the rail of spaces (your personal space, then one avatar per +// Organization), the Environment picker at the head of the left column with +// its list, and the switch Chat · Apps · Automate. The elements in +// elements.ts only draw it. Every Environment is named one way everywhere: +// by its own name or its kind, with a line saying who it is for, never by +// the machine's technical name. -/** At most this many Environments of one folder show before "+N". */ -export const folderLimit = 6; +/** A space of the rail: your personal space or one Organization. */ +export const personalSpace = "personal"; -export type RailMark = - | Readonly<{ kind: "initials"; text: string }> - | Readonly<{ - kind: "icon"; - icon: "laptop" | "user" | "users" | "bot"; - }>; - -export type RailItem = Readonly<{ - id: string; - /** The first line of the label. */ - label: string; - /** The second line: Organization · kind (· you are here). */ - sub: string; - href: string; - active: boolean; - mark: RailMark; - /** The fill of the active item: the Organization's accent, or null for - * the design system's ink (personal) or accent (Organization). */ - accent: string | null; -}>; - -export type RailFolder = Readonly<{ - organization: ShellOrganization; - /** The avatar, or the initials when there is none. */ - initials: string; - items: readonly RailItem[]; - /** How many are folded behind "+N" (0 when all show). */ - hidden: number; - /** Whether "less" folds them again. */ - expanded: boolean; - hasActive: boolean; -}>; - -export type RailModel = Readonly<{ - personal: readonly RailItem[]; - folders: readonly RailFolder[]; -}>; - -const kindIcons: Readonly< - Record -> = { - personal: "user", - work: "user", - team: "users", - automated: "bot", - workstation: "laptop", -}; +/** The app a link of the shell leads into. */ +export const shellApps = ["chat", "apps", "automate"] as const; +export type ShellApp = (typeof shellApps)[number]; /** Up to two letters of a name: the first letters of its first two words, * else its first two letters. */ @@ -79,109 +37,285 @@ export function initialsOf(name: string): string { .toLocaleUpperCase(); } -/** The name an Environment is shown under. */ -export function environmentLabel( +/** The name an Environment is shown under: its own, else its kind's. */ +export const environmentName = ( environment: ShellEnvironment, copy: ShellCopy, -): string { - return environment.label ?? copy.thisComputer; +): string => environment.label ?? copy.names[environment.kind]; + +/** Who an Environment is for: a work Environment's person, otherwise its + * kind's word. */ +export const environmentWho = ( + environment: ShellEnvironment, + copy: ShellCopy, +): string => + environment.kind === "work" && environment.assignee !== null + ? `@${environment.assignee}` + : copy.who[environment.kind]; + +const sameSlug = (left: string, right: string) => + left.toLowerCase() === right.toLowerCase(); + +/** The Organization of a slug the document lists. */ +export const organizationOf = ( + shell: Shell, + slug: string, +): ShellOrganization | undefined => + shell.organizations.find((entry) => sameSlug(entry.slug, slug)); + +/** The space you are in: the one the host names (`space`, a workstation + * opened for one Organization), otherwise the current Environment's: a + * personal one or a workstation is personal, any other its first + * Organization's. */ +export function hereOf(shell: Shell, space: string | null): string { + if ( + space !== null && + (space === personalSpace || organizationOf(shell, space) !== undefined) + ) + return space === personalSpace + ? space + : (organizationOf(shell, space)?.slug ?? space); + const current = currentEnvironment(shell); + return current.kind === "personal" || + current.kind === "workstation" || + current.organizations.length === 0 + ? personalSpace + : (current.organizations[0] ?? personalSpace); } -function item( +/** The Environments of a space, in document order: your personal ones and + * workstations for the personal space, and for an Organization those that + * hold it (a workstation holding it among them). */ +export function spaceEnvironments( shell: Shell, + space: string, +): readonly ShellEnvironment[] { + if (space === personalSpace) + return shell.environments.filter( + (entry) => + entry.kind === "personal" || + entry.kind === "workstation" || + entry.organizations.length === 0, + ); + const own = shell.environments.filter( + (entry) => + entry.kind !== "workstation" && + entry.organizations.some((slug) => sameSlug(slug, space)), + ); + const workstations = shell.environments.filter( + (entry) => + entry.kind === "workstation" && + entry.organizations.some((slug) => sameSlug(slug, space)), + ); + return [...own, ...workstations]; +} + +/** Where a link to an Environment leads, in a space and an app: the app's + * origin, Apps where the Environment has not that app; a workstation holding + * several Organizations opens Apps for the space's (`o/`, the + * Launchpad's route of one Organization). */ +export function environmentHref( environment: ShellEnvironment, - copy: ShellCopy, - accent: string | null, -): RailItem { - const active = environment.id === shell.current; - const where = environment.organizations - .map( - (slug) => - shell.organizations.find( - (entry) => entry.slug.toLowerCase() === slug.toLowerCase(), - )?.name ?? slug, - ) - .join(", "); - const personal = environment.kind === "personal"; - const mark: RailMark = - personal && shell.operator.initials !== null - ? { kind: "initials", text: shell.operator.initials } - : { kind: "icon", icon: kindIcons[environment.kind] }; - return Object.freeze({ - id: environment.id, - label: environmentLabel(environment, copy), - sub: [ - personal && shell.operator.login !== null - ? `@${shell.operator.login}` - : where, - copy.kinds[environment.kind], - active ? copy.current : "", - ] - .filter((part) => part !== "") - .join(" · "), - href: environment.apps.apps, - active, - mark, - accent, - }); + space: string, + app: ShellApp, +): string { + const base = + app === "chat" + ? environment.apps.chat + : app === "automate" + ? environment.apps.automate + : null; + if (base !== null) return base; + const apps = environment.apps.apps; + if (space === personalSpace || environment.organizations.length < 2) + return apps; + const root = apps.endsWith("/") ? apps : `${apps}/`; + return `${root}o/${encodeURIComponent(space)}`; } -/** The rail: first the personal Environments (personal Remote Environments - * and workstations, in document order), then one folder per Organization - * with the Environments that belong to it, in the order of - * `organizations`. A workstation holding several Organizations is personal: - * it is the person's own computer. A folder shows the first `folderLimit` - * Environments, plus the active one if it is further down; `expanded` lists - * the folders the person unfolded. An Organization without an Environment - * in the document has no folder. */ -export function railModel( +const pluralKey = (count: number) => + count === 1 + ? "environmentsOne" + : count >= 2 && count <= 4 + ? "environmentsFew" + : "environmentsMany"; + +export type RailSpace = Readonly<{ + space: string; + /** The label's first line. */ + title: string; + /** Its second line: how many Environments, and the last one. */ + sub: string; + href: string; + active: boolean; + /** The Organization's avatar or initials; the personal space's initials. */ + avatar: string | null; + initials: string | null; +}>; + +/** The rail: your personal space, then every Organization of the document + * in its order. A click leads to the space's last Environment (`last`, by + * space, what this browser remembers), else its first, in the same app; + * a space without one leads to its Dashboard. */ +export function railSpaces( shell: Shell, copy: ShellCopy, - expanded: ReadonlySet = new Set(), -): RailModel { - const personal = shell.environments - .filter( - (environment) => - environment.kind === "personal" || - environment.kind === "workstation" || - environment.organizations.length === 0, - ) - .map((environment) => item(shell, environment, copy, null)); - const folders = shell.organizations.flatMap((organization): RailFolder[] => { - const own = shell.environments.filter( - (environment) => - environment.kind !== "personal" && - environment.kind !== "workstation" && - environment.organizations[0]?.toLowerCase() === - organization.slug.toLowerCase(), - ); - if (own.length === 0) return []; - const items = own.map((environment) => - item(shell, environment, copy, organization.accent), - ); - const open = expanded.has(organization.slug); - const visible = open - ? items - : items.filter((entry, index) => index < folderLimit || entry.active); - return [ - Object.freeze({ - organization, + options: Readonly<{ + here: string; + app: ShellApp; + last: (space: string) => string | null; + }>, +): readonly RailSpace[] { + const space = ( + id: string, + title: string, + dashboard: string, + marks: Readonly<{ avatar: string | null; initials: string | null }>, + ): RailSpace => { + const environments = spaceEnvironments(shell, id); + const remembered = options.last(id); + const last = environments.find((entry) => entry.id === remembered); + const target = last ?? environments[0]; + return Object.freeze({ + space: id, + title, + sub: [ + fillShell(copy[pluralKey(environments.length)], { + count: environments.length, + }), + last === undefined + ? null + : fillShell(copy.last, { name: environmentName(last, copy) }), + ] + .filter((part) => part !== null) + .join(" · "), + href: + target === undefined + ? dashboard + : environmentHref(target, id, options.app), + active: options.here === id, + ...marks, + }); + }; + return [ + space(personalSpace, copy.personal, shell.dashboard, { + avatar: null, + initials: shell.operator.initials, + }), + ...shell.organizations.map((organization) => + space(organization.slug, organization.name, organization.dashboard, { + avatar: organization.avatar, initials: initialsOf(organization.name), - items: Object.freeze(visible), - hidden: items.length - visible.length, - expanded: open && items.length > folderLimit, - hasActive: items.some((entry) => entry.active), }), - ]; - }); - return Object.freeze({ - personal: Object.freeze(personal), - folders: Object.freeze(folders), - }); + ), + ]; } -export const shellApps = ["chat", "apps", "automate"] as const; -export type ShellApp = (typeof shellApps)[number]; +/** What the picker shows of an Environment: its glyph, its name and who it + * is for. The glyph is the Organization's avatar where it belongs to one, + * your initials for a personal one, and the kind's icon otherwise. */ +export type EnvironmentGlyph = + | Readonly<{ kind: "avatar"; organization: ShellOrganization }> + | Readonly<{ kind: "initials"; text: string }> + | Readonly<{ kind: "icon"; icon: "laptop" | "user" | "users" | "bot" }>; + +const kindIcons = { + personal: "user", + work: "user", + team: "users", + automated: "bot", + workstation: "laptop", +} as const; + +export function environmentGlyph( + shell: Shell, + environment: ShellEnvironment, + space: string, +): EnvironmentGlyph { + if (environment.kind === "personal" && shell.operator.initials !== null) + return { kind: "initials", text: shell.operator.initials }; + const organization = + space === personalSpace ? undefined : organizationOf(shell, space); + return organization !== undefined + ? { kind: "avatar", organization } + : { kind: "icon", icon: kindIcons[environment.kind] }; +} + +export type SwitcherRow = Readonly<{ + id: string; + name: string; + who: string; + href: string; + current: boolean; + /** A row's glyph: your initials for a personal Environment, otherwise its + * kind's icon (the Organization stands in the head above). */ + glyph: Exclude; +}>; + +export type SwitcherSection = Readonly<{ + space: string; + title: string; + /** An Organization's head above its Environments: its Dashboard. */ + head: Readonly<{ + organization: ShellOrganization; + href: string; + }> | null; + rows: readonly SwitcherRow[]; +}>; + +/** The list of the picker (one space, `all` false) and of ⌘⇧E (every space, + * `all` true): your personal Environments, then each Organization with its + * head and its Environments, the current one marked, filtered by `query` + * against the space, the name and who it is for. A space keeps its head + * while it matches and stays listed empty only when it is the one asked + * for. */ +export function switcherSections( + shell: Shell, + copy: ShellCopy, + options: Readonly<{ + here: string; + all: boolean; + app: ShellApp; + query: string; + }>, +): readonly SwitcherSection[] { + const words = options.query.trim().toLocaleLowerCase(); + const matches = (...parts: string[]) => + words === "" || parts.join(" ").toLocaleLowerCase().includes(words); + const row = (environment: ShellEnvironment, space: string): SwitcherRow => { + const glyph: SwitcherRow["glyph"] = + environment.kind === "personal" && shell.operator.initials !== null + ? { kind: "initials", text: shell.operator.initials } + : { kind: "icon", icon: kindIcons[environment.kind] }; + return Object.freeze({ + id: environment.id, + name: environmentName(environment, copy), + who: environmentWho(environment, copy), + href: environmentHref(environment, space, options.app), + current: environment.id === shell.current && options.here === space, + glyph, + }); + }; + const spaces = options.all + ? [personalSpace, ...shell.organizations.map((entry) => entry.slug)] + : [options.here]; + return spaces.flatMap((space): SwitcherSection[] => { + const organization = + space === personalSpace ? undefined : organizationOf(shell, space); + const title = organization?.name ?? copy.personal; + const rows = spaceEnvironments(shell, space) + .map((environment) => row(environment, space)) + .filter((entry) => matches(title, entry.name, entry.who)); + const head = + organization !== undefined && + matches(organization.name, copy.organizationDashboard) + ? { organization, href: organization.dashboard } + : null; + if (rows.length === 0 && head === null && (options.all || words !== "")) + return []; + return [Object.freeze({ space, title, head, rows: Object.freeze(rows) })]; + }); +} export type SwitchTab = Readonly<{ app: ShellApp; @@ -221,47 +355,3 @@ export function switchTabs( }), ); } - -/** The jump list of ⌘⇧E: every Environment of the document whose label, - * Organization or kind contains the query, the current one first. */ -export function jumpList( - shell: Shell, - copy: ShellCopy, - query: string, -): readonly RailItem[] { - const model = railModel( - shell, - copy, - new Set(shell.organizations.map((organization) => organization.slug)), - ); - const all = [ - ...model.personal, - ...model.folders.flatMap((folder) => folder.items), - ]; - const needle = query.trim().toLocaleLowerCase(); - return all - .filter( - (entry) => - needle === "" || - `${entry.label} ${entry.sub}`.toLocaleLowerCase().includes(needle), - ) - .sort((left, right) => Number(right.active) - Number(left.active)); -} - -/** The "+N" button's words. */ -export const moreText = ( - copy: ShellCopy, - folder: RailFolder, -): Readonly<{ text: string; label: string }> => - folder.expanded - ? { - text: copy.less, - label: fillShell(copy.lessNamed, { name: folder.organization.name }), - } - : { - text: fillShell(copy.more, { count: folder.hidden }), - label: fillShell(copy.moreNamed, { - count: folder.hidden, - name: folder.organization.name, - }), - }; From b81537952e8c4652d9990e35324031f13af2368f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Sun, 4 Oct 2026 00:41:34 +0200 Subject: [PATCH 02/12] =?UTF-8?q?WIP:=20the=20Launchpad=20on=20the=20Organ?= =?UTF-8?q?ization=20rail:=20Apps=20column=20with=20favourites=20and=20Mar?= =?UTF-8?q?ketplace,=20clean=20tiles=20with=20the=20=E2=8B=AF=20menu,=20to?= =?UTF-8?q?asts,=20+=20Nov=C3=BD=20modul=20behind=20GitHub's=20Owner=20ans?= =?UTF-8?q?wer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) --- src/launchpad/apps-view.ts | 238 ++++++++---- src/launchpad/catalog-panel.ts | 575 +++++++++++++++++----------- src/launchpad/catalog-view.ts | 3 +- src/launchpad/favorites.ts | 62 +++ src/launchpad/index.html | 132 ++++--- src/launchpad/messages.ts | 102 +++-- src/launchpad/organization-owner.ts | 87 +++++ src/launchpad/routes.ts | 25 +- src/launchpad/server.ts | 33 ++ src/launchpad/shell-document.ts | 3 +- src/launchpad/ui.ts | 109 +++++- src/shell/elements.ts | 29 +- 12 files changed, 984 insertions(+), 414 deletions(-) create mode 100644 src/launchpad/favorites.ts create mode 100644 src/launchpad/organization-owner.ts diff --git a/src/launchpad/apps-view.ts b/src/launchpad/apps-view.ts index f67224591..b3c31e2e9 100644 --- a/src/launchpad/apps-view.ts +++ b/src/launchpad/apps-view.ts @@ -20,21 +20,27 @@ import { moduleRoute, } from "./catalog-view"; import type { PublicEntry } from "./chat"; +import { + favoritesFirst, + moduleFavorite, + repositoryFavorite, +} from "./favorites"; import { moduleOrigin } from "./hosted-entry"; import type { MessageKey } from "./messages"; import type { PageRoute } from "./routes"; type Copy = Readonly>; -// Pure presentation of the Apps home and its left column (decision F36, the -// target shell's "Apps home"): one Organization at a time, its name on top -// (a picker when the Folder holds several), its modules in the section -// Workspace and its production repositories, read-only, in the section -// Productionspace (decision F32's addendum of 2026-10-03, final), each a pill -// with a count over a grid of tiles. A tile opens the module's app in a new -// tab; a module that has no app or cannot start opens its overview; a -// production repository's tile is at most its GitHub page. The DOM lives in -// catalog-panel.ts. +// Pure presentation of the Apps home and its column (decision F36 and its +// addendum of 2026-10-04): one Organization at a time, its name on top and +// the Environment under it, its modules in the section Workspace and its +// production repositories in Productionspace (decision F32's final +// addendum), each a pill with a count over a grid of clean tiles: stone, +// name, a short description, a star when favourite. A module's tile opens its +// app in a new tab; one without an app, one that cannot start and a +// repository only say so in a short message. Its "⋯" menu stars it and leads +// to the module's overview (a repository's GitHub page). Favourites come +// first, in the column's order. The DOM lives in catalog-panel.ts. /** The groups the Apps home offers (Organizations, then the Personalspace * group), in the catalog's order. */ @@ -175,37 +181,48 @@ export function pluralKey( return keys.many; } +/** What a click on a tile does: open the module's app (hosted on its own + * origin, locally through the lifecycle), or say in a short message why + * there is nothing to open. */ +export type TileAction = + | Readonly<{ + kind: "open"; + target: Extract; + }> + | Readonly<{ kind: "say"; text: string }>; + export type AppsTile = | Readonly<{ kind: "module"; + /** Its favourite key (`m:`). */ + key: string; entry: CatalogModuleEntry; name: string; description: string; /** Its Lazurio stone (decision F36). */ stone: Readonly<{ key: StoneKey; src: string; accent: string }>; - /** The exception the tile reports, or null: status only by - * exception (the design system's `lz-status--plain`). */ - note: Readonly<{ tone: "warn"; text: string; title: string }> | null; - target: TileTarget; + action: TileAction; + /** The module's overview, from its menu ("Informace o modulu"). */ + info: string | null; + favorite: boolean; }> - /** A production repository: read-only, no status dot, no action, no - * page (F32 addendum of 2026-10-03). */ + /** A production repository: read-only, no app, no page of its own + * (decision F32's final addendum); its menu leads to its GitHub page. */ | Readonly<{ kind: "repository"; + key: string; repository: CatalogRepository; name: string; description: string; - /** "Not checked out" as plain text, or null when it is. */ - note: Readonly<{ tone: "muted"; text: string; title: string }> | null; - /** Its GitHub page, in a new tab, or null. */ - href: string | null; + action: TileAction; + info: string | null; + favorite: boolean; }>; export type AppsSection = Readonly<{ kind: CatalogSectionKind | "personal"; title: string; count: string; - subtitle: string | null; tiles: readonly AppsTile[]; }>; @@ -222,72 +239,149 @@ const countKeys = { }, } as const; -/** The sections of one group, in order, each with what it holds; empty +/** What a click on a module's tile does. */ +export function moduleAction( + target: TileTarget, + module: CatalogModule, + copy: Copy, +): TileAction { + if (target.kind === "hosted" || target.kind === "start") + return { kind: "open", target }; + return { + kind: "say", + text: (module.defaultApp === null + ? copy.appsSayNoApp + : copy.appsSayCannotStart + ).replace("{name}", moduleName(module)), + }; +} + +/** Every tile of one group, in the catalog's order: its modules, then its + * production repositories. */ +export function appsTiles( + catalog: Catalog, + group: CatalogGroupEntry, + copy: Copy, + entry: PublicEntry | null, + favorites: readonly string[], +): Readonly<{ + modules: readonly AppsTile[]; + repositories: readonly AppsTile[]; +}> { + const moduleTile = (item: CatalogModuleEntry): AppsTile => { + const target = tileTarget(catalog, group.organization, item.module, entry); + const key = moduleFavorite(item.module.module); + return { + kind: "module", + key, + entry: item, + name: moduleName(item.module), + description: moduleDescription(item.module, copy), + stone: moduleStone(item.module), + action: moduleAction(target, item.module, copy), + info: item.href, + favorite: favorites.includes(key), + }; + }; + const modules = + group.sections === null + ? group.modules + : group.sections.flatMap((section) => + section.kind === "workspace" ? section.modules : [], + ); + const repositories = + group.sections === null + ? [] + : group.sections.flatMap((section) => + section.kind === "productionspace" ? section.repositories : [], + ); + return { + modules: modules.map(moduleTile), + repositories: repositories.map(({ repository }): AppsTile => { + const key = repositoryFavorite(repository.slug); + return { + kind: "repository", + key, + repository, + name: repository.slug, + description: repository.path, + action: { + kind: "say", + text: copy.appsSayRepository.replace("{name}", repository.slug), + }, + info: repository.url, + favorite: favorites.includes(key), + }; + }), + }; +} + +/** The sections of one group, in order, favourites first in each; empty * sections are left out. The Personalspace group is one section. */ export function appsSections( catalog: Catalog, group: CatalogGroupEntry, copy: Copy, entry: PublicEntry | null, + favorites: readonly string[] = [], ): readonly AppsSection[] { - const moduleTile = (item: CatalogModuleEntry): AppsTile => ({ - kind: "module", - entry: item, - name: moduleName(item.module), - description: moduleDescription(item.module, copy), - stone: moduleStone(item.module), - // A module without an app is not one that cannot start: its tile says - // "No app" and nothing more. - note: - item.status.state === "blocked" && item.module.reason !== "no-app" - ? { tone: "warn", text: copy.appsCannotStart, title: item.status.text } - : null, - target: tileTarget(catalog, group.organization, item.module, entry), - }); - const count = (tiles: number, kind: keyof typeof countKeys) => - copy[pluralKey(tiles, countKeys[kind])].replace("{count}", String(tiles)); + const tiles = appsTiles(catalog, group, copy, entry, favorites); + const count = (length: number, kind: keyof typeof countKeys) => + copy[pluralKey(length, countKeys[kind])].replace("{count}", String(length)); if (group.sections === null) - return group.modules.length === 0 + return tiles.modules.length === 0 ? [] : [ { kind: "personal", title: copy.appsPersonal, - count: count(group.modules.length, "modules"), - subtitle: null, - tiles: group.modules.map(moduleTile), + count: count(tiles.modules.length, "modules"), + tiles: favoritesFirst(tiles.modules, favorites), }, ]; - return group.sections.map((section): AppsSection => { - if (section.kind === "workspace") - return { - kind: section.kind, - title: section.title, - count: count(section.modules.length, "modules"), - subtitle: copy.appsWorkspaceSubtitle.replace("{name}", group.name), - tiles: section.modules.map(moduleTile), - }; - return { - kind: section.kind, - title: section.title, - count: count(section.repositories.length, "repositories"), - subtitle: copy.appsProductionspaceSubtitle, - tiles: section.repositories.map( - ({ repository, checkout }): AppsTile => ({ - kind: "repository", - repository, - name: repository.slug, - description: repository.path, - note: repository.checkedOut - ? null - : { tone: "muted", text: checkout, title: checkout }, - href: repository.url, - }), - ), - }; - }); + return group.sections.map( + (section): AppsSection => + section.kind === "workspace" + ? { + kind: section.kind, + title: section.title, + count: count(tiles.modules.length, "modules"), + tiles: favoritesFirst(tiles.modules, favorites), + } + : { + kind: section.kind, + title: section.title, + count: count(tiles.repositories.length, "repositories"), + tiles: favoritesFirst(tiles.repositories, favorites), + }, + ); } -/** Whether a tile or column item matches the column's search. */ -export const appsMatch = (name: string, query: string): boolean => - name.toLocaleLowerCase().includes(query.trim().toLocaleLowerCase()); +/** The favourites of the Apps column, in their order, only those this + * Environment's catalog has. */ +export function favoriteTiles( + catalog: Catalog, + group: CatalogGroupEntry, + copy: Copy, + entry: PublicEntry | null, + favorites: readonly string[], +): readonly AppsTile[] { + const tiles = appsTiles(catalog, group, copy, entry, favorites); + return favoritesFirst( + [...tiles.modules, ...tiles.repositories], + favorites, + ).filter((tile) => tile.favorite); +} + +/** The prompt "+ Nový modul" hands to Chat (the wireframe's + * `newModulePrompt`): the agent first asks what the module is for, then + * founds it by the Lazurio Module Standard with the scaffold, never by + * hand, and hands it over as a pull request. */ +export const newModulePrompt = ( + name: string, + login: string, + copy: Copy, +): string => + copy.appsNewModulePrompt + .replaceAll("{name}", name) + .replaceAll("{login}", login); diff --git a/src/launchpad/catalog-panel.ts b/src/launchpad/catalog-panel.ts index 5b27d5201..f36160774 100644 --- a/src/launchpad/catalog-panel.ts +++ b/src/launchpad/catalog-panel.ts @@ -9,13 +9,14 @@ import { initialsOf } from "../shell/view"; import { type AppsSection, type AppsTile, - appsMatch, appsScope, appsScopes, appsSections, + favoriteTiles, moduleDescription, moduleName, moduleStone, + newModulePrompt, type TileTarget, tileTarget, } from "./apps-view"; @@ -32,6 +33,7 @@ import { routeOrganization, } from "./catalog-view"; import type { PublicEntry } from "./chat"; +import { favoritesKey, parseFavorites, toggleFavorite } from "./favorites"; import type { MessageKey } from "./messages"; import { moduleLink, @@ -44,23 +46,31 @@ import type { PageRoute } from "./routes"; type Copy = Readonly>; -// The Apps home of the Lazurio shell (decision F36; the target shell's "Apps -// home"): the left column lists one Organization's modules under the section -// Workspace and its production repositories, read-only, under the section -// Productionspace (F32 addendum of 2026-10-03, final), with a search; the -// main view shows that -// Organization's name on top (a picker when the Folder holds several) and -// the same sections as pills with counts over grids of tiles. A tile opens -// the module's app in a new tab: hosted on the module's own origin, where the -// gateway starts it; locally through the lifecycle (start, then open the link -// it reports). A module with no app, or one that cannot start, opens its -// overview, and so does choosing it in the column. The overview carries the -// module lifecycle (slice P5): the status of its app with a dot, the one -// primary action (Start or Stop) and Open while the app reports a link, over -// `/api/modules///…`, the same core as `lazurio module`. A -// production repository has no dot, no action and no page: its tile is its -// GitHub page when known, else plain text. Teams are shown nowhere (decision -// F32). Every value from the server is drawn with textContent. +/** The current Environment as the Apps home names it under the + * Organization: its name by what it is for and its kind's icon. */ +export type HomeEnvironment = Readonly<{ + name: string; + icon: "laptop" | "user" | "users" | "bot"; +}>; + +// The Apps home of the Lazurio shell (decision F36 and its addendum of +// 2026-10-04): the left column holds "Všechny moduly", "Soubory", your +// favourite modules and, at its foot, the Marketplace; no module list and no +// search. The main view names the Organization and, under it, the +// Environment, then the sections Workspace (every module) and +// Productionspace (production repositories, read-only, decision F32's final +// addendum) as pills with counts over grids of clean tiles: stone, name, a +// short description, a star when favourite. A tile opens the module's app in +// a new tab: hosted on the module's own origin, where the gateway starts it; +// locally through the lifecycle (start, then open the link it reports). A +// module without an app, one that cannot start and a repository only say so +// in a short message. The "⋯" menu at a tile's top right stars it and leads +// to the module's overview (a repository's GitHub page), which carries the +// module lifecycle (slice P5) over `/api/modules///…`, the same +// core as `lazurio module`. Where this Environment's GitHub identity is an +// Owner of the Organization, Workspace ends with "+ Nový modul". Teams are +// shown nowhere (decision F32). Every value from the server is drawn with +// textContent. export function createCatalogPanel( options: Readonly<{ post: ( @@ -80,6 +90,15 @@ export function createCatalogPanel( entry: () => PublicEntry | null; /** The avatar of an Organization slug, as the shell document names it. */ avatar: (slug: string) => string | null; + /** The current Environment's name and icon, once the shell document is + * read. */ + environment: () => HomeEnvironment | null; + /** The Organization (or `personal`) the Apps home now shows: the shell + * marks it as the space you are in. */ + space: (space: string) => void; + /** "+ Nový modul": hands the prepared prompt to Chat; resolves to + * whether it reached the clipboard. */ + newModule: (prompt: string) => Promise; }>, ) { const find = (selector: string): T => { @@ -87,19 +106,21 @@ export function createCatalogPanel( if (!element) throw new Error("Missing catalog UI"); return element; }; - const tree = find("#catalog-tree"); const home = find("#catalog-home"); - const search = find("#catalog-search"); + const favoritesBox = find("#catalog-favorites"); const head = find("#catalog-head"); const headName = find("#catalog-head-name"); const body = find("#catalog-body"); const status = find("#catalog-status"); - const refreshButton = find("#catalog-refresh"); + const toastRegion = find("#toast"); let catalog: Catalog | null = null; let state: "loading" | "loaded" | "failed" = "loading"; // A sentence about the last tile opened on a workstation (starting, // failed), shown in the status line until the next move. let notice: string | null = null; + // Whether this Environment's GitHub identity is an Owner of an + // Organization, by its route key: read once per page, never assumed. + const owners = new Map(); // The lifecycle of the module the page shows: its last status, the // sentence after the last action, and whether a request is under way. // Nothing of it is kept beyond the page; the service manager is the truth. @@ -152,7 +173,7 @@ export function createCatalogPanel( return line; }; // An Organization's mark: its GitHub avatar, or its initials when there - // is none or it does not load. + // is none or it does not load; the Personalspace group's is round. const orgMark = (group: CatalogGroupEntry, className: string) => { const mark = element("span", className); const initials = () => mark.replaceChildren(initialsOf(group.name)); @@ -183,10 +204,14 @@ export function createCatalogPanel( image.setAttribute("aria-hidden", "true"); return image; }; - const tileMark = (stone: Readonly<{ src: string }> | null) => { - if (stone !== null) return stoneImage(stone.src, 48, "tile-stone"); - const mark = element("span", "tile-mark"); - mark.dataset.kind = "repository"; + const tileMark = (tile: AppsTile, size: number) => { + if (tile.kind === "module") + return stoneImage( + tile.stone.src, + size, + size > 24 ? "tile-stone" : "menu-stone", + ); + const mark = element("span", size > 24 ? "tile-mark" : "menu-mark"); mark.append(svg("folder")); mark.setAttribute("aria-hidden", "true"); return mark; @@ -195,6 +220,40 @@ export function createCatalogPanel( group === null || group === appsScopes(value, options.copy())[0] ? "/" : (organizationRoute(value, group.organization) ?? "/"); + // The favourites of one group live per Organization in this browser + // (favorites.ts): never in the Folder, which a Team Environment shares. + const scopeKey = (group: CatalogGroupEntry) => + group.sections === null + ? "personalspace" + : (group.organization.organization ?? group.organization.directory); + const favoritesOf = (group: CatalogGroupEntry): readonly string[] => { + try { + return parseFavorites( + localStorage.getItem(favoritesKey(scopeKey(group))), + ); + } catch { + return []; + } + }; + const toggle = (group: CatalogGroupEntry, key: string) => { + try { + localStorage.setItem( + favoritesKey(scopeKey(group)), + JSON.stringify(toggleFavorite(favoritesOf(group), key)), + ); + } catch {} + render(); + }; + + // --- A short message at the foot of the page (the wireframe's toast) -- + let toastTimer: ReturnType | undefined; + function say(text: string) { + clearTimeout(toastTimer); + const toast = element("div", "toast"); + toast.append(svg("info"), text); + toastRegion.replaceChildren(toast); + toastTimer = setTimeout(() => toastRegion.replaceChildren(), 3500); + } // --- Opening a module's app ------------------------------------------- @@ -245,19 +304,15 @@ export function createCatalogPanel( options.navigate(target.overview); } - // The tile's or the overview button's link for a target. - function targetLink( - target: TileTarget, + // A link that opens a module's app in a new tab: the module's own origin + // hosted; locally a plain click starts it first (without the script the + // link is the overview). + function openLink( + target: Extract, name: string, className: string, - ): HTMLElement { + ): HTMLAnchorElement { const copy = options.copy(); - if (target.kind === "none") return element("div", className); - if (target.kind === "overview") { - const link = routeLink(target.href, className); - link.title = copy.appsOverviewNamed.replace("{name}", name); - return link; - } const link = element("a", className); link.title = copy.appsOpenAppNamed.replace("{name}", name); if (target.kind === "hosted") { @@ -266,7 +321,6 @@ export function createCatalogPanel( link.rel = "noopener noreferrer"; return link; } - // Without the script it is the overview; with it, a plain click starts. link.href = target.overview; link.dataset.route = ""; link.addEventListener("click", (event) => { @@ -285,104 +339,271 @@ export function createCatalogPanel( return link; } - function tile(item: AppsTile): HTMLElement { + // What a tile, or a favourite in the column, is: a link that opens the + // app, or a button that says why there is nothing to open. + function actionNode(item: AppsTile, className: string): HTMLElement { + if (item.action.kind === "open") + return openLink(item.action.target, item.name, className); + const text = item.action.text; + const button = element("button", `${className} is-button`); + button.type = "button"; + button.addEventListener("click", () => say(text)); + return button; + } + + // --- The "⋯" menu of a tile ------------------------------------------- + + let openMenu: (() => void) | null = null; + document.addEventListener("click", (event) => { + if (openMenu === null) return; + const target = event.target; + if (target instanceof Element && target.closest(".tile-menu")) return; + openMenu(); + }); + document.addEventListener("keydown", (event) => { + if (event.key === "Escape" && openMenu !== null) { + event.preventDefault(); + openMenu(); + } + }); + + function tileMenu(item: AppsTile, group: CatalogGroupEntry): HTMLElement { const copy = options.copy(); - let node: HTMLElement; - if (item.kind === "module") - node = targetLink(item.target, item.name, "tile"); - else if (item.href !== null) { - const link = element("a", "tile"); - link.href = item.href; - link.target = "_blank"; - link.rel = "noopener noreferrer"; - link.title = copy.appsRepositoryNamed.replace("{name}", item.name); - node = link; - } else node = element("div", "tile"); + const box = element("div", "tile-menu"); + const button = element("button", "tile-menu-button"); + button.type = "button"; + button.setAttribute("aria-haspopup", "menu"); + button.setAttribute("aria-expanded", "false"); + button.setAttribute( + "aria-label", + copy.appsMore.replace("{name}", item.name), + ); + button.append(svg("more")); + const list = element("div", "tile-menu-list"); + list.setAttribute("role", "menu"); + list.hidden = true; + const close = () => { + list.hidden = true; + box.classList.remove("is-open"); + button.setAttribute("aria-expanded", "false"); + openMenu = null; + }; + const star = element("button", "tile-menu-item"); + star.type = "button"; + star.setAttribute("role", "menuitem"); + if (item.favorite) star.classList.add("is-favorite"); + star.append( + svg("star"), + item.favorite ? copy.appsFavoriteRemove : copy.appsFavoriteAdd, + ); + star.addEventListener("click", () => { + close(); + toggle(group, item.key); + }); + list.append(star); + if (item.info !== null) { + const info = + item.kind === "module" + ? routeLink(item.info, "tile-menu-item") + : element("a", "tile-menu-item"); + if (item.kind === "repository") { + info.href = item.info; + info.target = "_blank"; + info.rel = "noopener noreferrer"; + } + info.setAttribute("role", "menuitem"); + info.append( + svg("info"), + item.kind === "module" ? copy.appsInfoModule : copy.appsInfoRepository, + ); + info.addEventListener("click", close); + list.append(info); + } + button.addEventListener("click", (event) => { + event.stopPropagation(); + if (!list.hidden) { + close(); + return; + } + openMenu?.(); + list.hidden = false; + box.classList.add("is-open"); + button.setAttribute("aria-expanded", "true"); + openMenu = close; + list.querySelector(".tile-menu-item")?.focus(); + }); + box.append(button, list); + return box; + } + + function tile(item: AppsTile, group: CatalogGroupEntry): HTMLElement { + const copy = options.copy(); + const wrap = element("div", "tile-wrap"); + const node = actionNode(item, "tile"); node.dataset.kind = item.kind; + if (item.kind === "module") + node.style.setProperty("--stone-accent", item.stone.accent); + const name = element("span", "tile-name", item.name); + if (item.favorite) { + const star = element("span", "tile-star"); + star.title = copy.appsFavoriteMark; + star.append( + svg("star-filled"), + element("span", "sr-only", copy.appsFavoriteMark), + ); + name.append(star); + } + const text = element("span", "tile-body"); + text.append(name, element("span", "tile-desc", item.description)); + node.append(tileMark(item, 48), text); + wrap.append(node, tileMenu(item, group)); + return wrap; + } + + // "+ Nový modul" (2026-10-04): the last tile of Workspace, only where this + // Environment's GitHub identity is an Owner of the Organization. It hands + // the wireframe's prompt to Chat: until the T3 Code fork takes a prompt + // draft by link (Lazurio/t3code#35) the prompt goes to the clipboard and + // Chat opens, where the person pastes it into a new chat. + function newModuleTile(group: CatalogGroupEntry): HTMLElement { + const copy = options.copy(); + const button = element("button", "tile tile--new is-button"); + button.type = "button"; + const mark = element("span", "tile-mark tile-mark--new"); + mark.append(svg("plus")); const text = element("span", "tile-body"); text.append( - element("span", "tile-name", item.name), - element("span", "tile-desc", item.description), + element("span", "tile-name", copy.appsNewModule), + element("span", "tile-desc", copy.appsNewModuleSub), ); - if (item.note !== null) { - const note = element("span", "tile-note", item.note.text); - note.dataset.tone = item.note.tone; - note.title = item.note.title; - // A status dot only on a module: a production repository has none. - if (item.kind === "module") note.prepend(dot("blocked-warn")); - text.append(note); + button.append(mark, text); + const login = group.organization.forgeLogin; + button.addEventListener("click", async () => { + if (login === undefined) return; + const copied = await options.newModule( + newModulePrompt(group.name, login, copy), + ); + say(copied ? copy.appsNewModuleCopied : copy.appsNewModuleCopyFailed); + }); + return button; + } + + // Reads once whether this Environment may found modules in an + // Organization: GitHub's own answer through the Launchpad, fail closed. + function ownerOf(value: Catalog, group: CatalogGroupEntry): boolean { + if (group.sections === null || group.organization.forgeLogin === undefined) + return false; + const key = catalogOrganizationKey(value, group.organization); + if (key === null) return false; + const known = owners.get(key); + if (known === true || known === false) return known; + if (known === undefined) { + owners.set(key, "reading"); + void options + .get(`/api/organizations/${encodeURIComponent(key)}/owner`) + .then(({ value: answer, ok }) => { + owners.set( + key, + ok && + !!answer && + typeof answer === "object" && + (answer as { owner?: unknown }).owner === true, + ); + }) + .catch(() => owners.set(key, false)) + .finally(() => render()); } - node.append(tileMark(item.kind === "module" ? item.stone : null), text); - if (item.kind === "module") - node.style.setProperty("--stone-accent", item.stone.accent); - const opensTab = - (item.kind === "module" && - (item.target.kind === "hosted" || item.target.kind === "start")) || - (item.kind === "repository" && item.href !== null); - if (opensTab) node.append(svg("external", "icon tile-open")); - return node; + return false; } - function section(value: AppsSection): HTMLElement { + function section( + value: AppsSection, + group: CatalogGroupEntry, + owner: boolean, + ): HTMLElement { const part = element("section", "apps-section"); part.dataset.section = value.kind; const top = element("div", "section-head"); const title = element("h2", "section-pill", value.title); top.append(title, element("span", "section-count", value.count)); - part.append(top); - if (value.subtitle !== null) - part.append(element("p", "section-subtitle", value.subtitle)); const grid = element("div", "tile-grid"); - grid.append(...value.tiles.map(tile)); - part.append(grid); + grid.append(...value.tiles.map((item) => tile(item, group))); + if (value.kind === "workspace" && owner) grid.append(newModuleTile(group)); + part.append(top, grid); return part; } - // --- The head: the Organization's name, or a picker ------------------- + // --- The column: favourites ------------------------------------------- - function drawHead(value: Catalog, group: CatalogGroupEntry | null) { + function drawFavorites(value: Catalog, group: CatalogGroupEntry | null) { const copy = options.copy(); - const groups = appsScopes(value, copy); if (group === null) { - const heading = element("h1", "apps-title", copy.homeTitle); - heading.tabIndex = -1; - heading.dataset.pageHeading = ""; - headName.replaceChildren(heading); + favoritesBox.replaceChildren(); return; } - const heading = element("h1", "apps-title", group.name); - heading.tabIndex = -1; - heading.dataset.pageHeading = ""; - if (groups.length < 2) { - headName.replaceChildren(orgMark(group, "org-mark"), heading); + const label = element("p", "column-label", copy.appsFavorites); + label.id = "column-favorites"; + const items = favoriteTiles( + value, + group, + copy, + options.entry(), + favoritesOf(group), + ); + if (items.length === 0) { + favoritesBox.replaceChildren( + label, + element("p", "column-hint", copy.appsFavoritesHint), + ); return; } - // Several Organizations in this Folder: the name opens a list of them. - const picker = element("details", "org-picker"); - const summary = element("summary"); - summary.setAttribute( - "aria-label", - `${group.name}, ${copy.appsOrganizationPick}`, - ); - summary.append(heading, svg("chevron-down", "icon org-picker-chevron")); - const list = element("ul", "org-picker-list"); + const list = element("ul", "menu"); + list.setAttribute("aria-labelledby", label.id); list.append( - ...groups.map((entry) => { - const item = element("li"); - const href = scopeRoute(value, entry); - const link = routeLink(href, "org-picker-item"); + ...items.map((item) => { + const entry = element("li"); + // A favourite opens the app straight away, like its tile. + const link = actionNode(item, "menu-item"); link.append( - orgMark(entry, "org-mark small"), - element("span", "", entry.name), + tileMark(item, 20), + element("span", "menu-name", item.name), ); - if (entry === group) link.setAttribute("aria-current", "true"); - link.addEventListener("click", () => picker.removeAttribute("open")); - item.append(link); - return item; + if (item.action.kind === "open") + link.append(svg("external", "icon menu-external")); + entry.append(link); + return entry; }), ); - picker.append(summary, list); - headName.replaceChildren(orgMark(group, "org-mark"), picker); + favoritesBox.replaceChildren(label, list); + } + + // --- The head: the Organization, and the Environment under it --------- + + function drawHead(group: CatalogGroupEntry | null) { + const copy = options.copy(); + const heading = element( + "h1", + "apps-title", + group === null + ? copy.homeTitle + : group.sections === null + ? copy.appsPersonal + : group.name, + ); + heading.tabIndex = -1; + heading.dataset.pageHeading = ""; + const where = element("div", "apps-where"); + where.append(heading); + const environment = options.environment(); + if (environment !== null) { + const line = element("span", "apps-environment"); + line.append(svg(environment.icon), environment.name); + where.append(line); + } + headName.replaceChildren( + ...(group === null ? [] : [orgMark(group, "org-mark")]), + where, + ); } // --- The main views ----------------------------------------------------- @@ -396,10 +617,17 @@ export function createCatalogPanel( group.organization.reason !== undefined ) parts.push(statusLine(group.status)); - const sections = appsSections(value, group, copy, options.entry()); + const sections = appsSections( + value, + group, + copy, + options.entry(), + favoritesOf(group), + ); + const owner = ownerOf(value, group); if (sections.length === 0 && group.organization.reason === undefined) parts.push(element("p", "intro", copy.catalogNoModules)); - parts.push(...sections.map(section)); + parts.push(...sections.map((part) => section(part, group, owner))); return parts; } @@ -480,7 +708,7 @@ export function createCatalogPanel( top.append(stoneImage(moduleStone(module).src, 64, "module-stone"), text); const target = tileTarget(value, organization, module, options.entry()); if (target.kind === "hosted" || target.kind === "start") { - const open = targetLink( + const open = openLink( target, moduleName(module), "button primary module-open", @@ -658,98 +886,10 @@ export function createCatalogPanel( // --- The left column ---------------------------------------------------- - // One Organization's modules and production repositories in the column, - // under the section labels Workspace and Productionspace, filtered by the - // search; the current module is marked. - function drawTree( - value: Catalog, - scope: CatalogGroupEntry | null, - route: PageRoute, - ) { - const copy = options.copy(); - const query = search.value; - const selection = catalogSelection(value, route); - if (scope === null) { - tree.replaceChildren(); - return; - } - tree.setAttribute( - "aria-label", - copy.appsColumn.replace("{name}", scope.name), - ); - const sections = appsSections(value, scope, copy, options.entry()); - const parts = sections.flatMap((part) => { - const items = part.tiles.filter((item) => appsMatch(item.name, query)); - if (items.length === 0) return []; - const box = element("div", "column-group"); - box.dataset.section = part.kind; - const label = element("p", "column-label", part.title); - label.id = `column-${part.kind}`; - const list = element("ul", "menu"); - list.setAttribute("aria-labelledby", label.id); - list.append( - ...items.map((item) => { - const entry = element("li"); - let link: HTMLElement; - if (item.kind === "module") { - link = - item.entry.href === null - ? element("span", "menu-item") - : routeLink(item.entry.href, "menu-item"); - if ( - selection.kind === "module" && - selection.module === item.entry.module - ) - link.setAttribute("aria-current", "page"); - } else if (item.href !== null) { - const anchor = element("a", "menu-item"); - anchor.href = item.href; - anchor.target = "_blank"; - anchor.rel = "noopener noreferrer"; - anchor.title = copy.appsRepositoryNamed.replace( - "{name}", - item.name, - ); - link = anchor; - } else link = element("span", "menu-item"); - let mark: HTMLElement; - if (item.kind === "module") - mark = stoneImage(item.stone.src, 20, "menu-stone"); - else { - mark = element("span", "menu-mark"); - mark.dataset.kind = "repository"; - mark.append(svg("folder")); - } - link.append(mark, element("span", "menu-name", item.name)); - if (item.note !== null) { - // A status dot only on a module: a production repository has - // none, its state is said in words. - if (item.kind === "module") { - const tail = dot("blocked-warn"); - tail.classList.add("menu-tail"); - link.append(tail); - } - link.append(element("span", "sr-only", `, ${item.note.text}`)); - } - entry.append(link); - return entry; - }), - ); - box.append(label, list); - return [box]; - }); - tree.replaceChildren( - ...(parts.length === 0 && query.trim() !== "" - ? [element("p", "column-empty", copy.appsNoMatch)] - : parts), - ); - } - /** Draws the route now shown from the catalog last read. */ function render(route: PageRoute = options.route()) { const copy = options.copy(); - search.placeholder = copy.appsSearch; - search.setAttribute("aria-label", copy.appsSearchLabel); + openMenu?.(); status.textContent = notice ?? (state === "loading" @@ -758,13 +898,20 @@ export function createCatalogPanel( ? copy.catalogLoadFailed : ""); if (catalog === null) { - tree.replaceChildren(); + favoritesBox.replaceChildren(); body.replaceChildren(); - drawHeadless(); + drawHead(null); + head.hidden = false; return; } const scope = appsScope(catalog, route, copy); const selection = catalogSelection(catalog, route); + if (scope !== null) + options.space( + scope.sections === null + ? "personal" + : (scope.organization.organization ?? "personal"), + ); home.href = scopeRoute(catalog, scope); if ( (route.view === "home" || route.view === "organization") && @@ -772,7 +919,7 @@ export function createCatalogPanel( ) home.setAttribute("aria-current", "page"); else home.removeAttribute("aria-current"); - drawTree(catalog, scope, route); + drawFavorites(catalog, scope); if ( route.view !== "home" && route.view !== "organization" && @@ -781,7 +928,7 @@ export function createCatalogPanel( return; if (selection.kind === "missing") { head.hidden = false; - drawHead(catalog, null); + drawHead(null); const missing = element("p", "callout"); missing.append( copy.catalogNotFound, @@ -798,7 +945,7 @@ export function createCatalogPanel( document.activeElement.dataset.moduleAction !== undefined; if (selection.kind !== "module") lifecycle = null; head.hidden = selection.kind === "module"; - if (selection.kind !== "module") drawHead(catalog, scope); + if (selection.kind !== "module") drawHead(scope); body.replaceChildren( ...(selection.kind === "ambiguous" ? ambiguousView(catalog, selection.candidates) @@ -815,18 +962,9 @@ export function createCatalogPanel( } } - // Before the catalog is read: the head names the Launchpad. - function drawHeadless() { - const heading = element("h1", "apps-title", options.copy().homeTitle); - heading.tabIndex = -1; - heading.dataset.pageHeading = ""; - headName.replaceChildren(heading); - head.hidden = false; - } - - /** Reads the catalog again (on load, Refresh and a language change). */ + /** Reads the catalog again (on load, on the way back to "Všechny moduly" + * and on a language change). */ async function refresh() { - refreshButton.disabled = true; state = catalog === null ? "loading" : state; render(); try { @@ -838,13 +976,10 @@ export function createCatalogPanel( } catch { state = "failed"; } finally { - refreshButton.disabled = false; render(); options.loaded(); } } - refreshButton.addEventListener("click", () => void refresh()); - search.addEventListener("input", () => render()); return { render(route?: PageRoute) { @@ -862,5 +997,11 @@ export function createCatalogPanel( ? undefined : organizationName(organization); }, + /** The Organization a route shows, for the Marketplace's sentence. */ + scopeName(route: PageRoute): string | null { + if (catalog === null) return null; + const scope = appsScope(catalog, route, options.copy()); + return scope === null || scope.sections === null ? null : scope.name; + }, }; } diff --git a/src/launchpad/catalog-view.ts b/src/launchpad/catalog-view.ts index 800e6a687..149c88e9d 100644 --- a/src/launchpad/catalog-view.ts +++ b/src/launchpad/catalog-view.ts @@ -149,7 +149,8 @@ export function catalogSelection( if ( route.view === "home" || route.view === "settings" || - route.view === "files" + route.view === "files" || + route.view === "marketplace" ) return { kind: "overview" }; const selection = selectCatalogOrganization(catalog, route.organization); diff --git a/src/launchpad/favorites.ts b/src/launchpad/favorites.ts new file mode 100644 index 000000000..68605479d --- /dev/null +++ b/src/launchpad/favorites.ts @@ -0,0 +1,62 @@ +// Favourite modules and repositories (decision F36 addendum of 2026-10-04, +// Anička 2026-10-03): starred from a tile's "⋯" menu, listed in the Apps +// column under "Všechny moduly" and "Soubory" and first in their section of +// the Apps home, in the column's order. They belong to the person and the +// Organization; until the Dashboard account holds them they live in this +// browser's `localStorage`, one list per Organization. Never in the Folder: +// on a Team Environment that would share one person's favourites with the +// whole Team. An Environment shows only those its catalog has. Pure but for +// the storage passed in. + +/** A favourite: a module (`m:`) or a production repository + * (`r:`), so the two never collide. */ +export const moduleFavorite = (id: string): string => `m:${id}`; +export const repositoryFavorite = (slug: string): string => `r:${slug}`; + +/** The storage key of one Organization's list (the Personalspace group is + * `personalspace`); slugs are compared case-insensitively. */ +export const favoritesKey = (scope: string): string => + `lazurio.favorites:${scope.toLowerCase()}`; + +const entry = /^[mr]:[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/; + +/** A stored list, read defensively: anything that is not a list of + * favourites is none; duplicates keep their first place; at most 200. */ +export function parseFavorites(raw: string | null): readonly string[] { + if (raw === null) return []; + let value: unknown; + try { + value = JSON.parse(raw); + } catch { + return []; + } + if (!Array.isArray(value)) return []; + return [ + ...new Set( + value.filter( + (item): item is string => typeof item === "string" && entry.test(item), + ), + ), + ].slice(0, 200); +} + +/** The list with `favorite` added at its end, or removed. */ +export const toggleFavorite = ( + list: readonly string[], + favorite: string, +): readonly string[] => + list.includes(favorite) + ? list.filter((item) => item !== favorite) + : [...list, favorite]; + +/** Favourites first, in the list's order, then the rest in their own. */ +export function favoritesFirst>( + items: readonly T[], + list: readonly string[], +): readonly T[] { + const starred = list.flatMap((key) => { + const found = items.find((item) => item.key === key); + return found === undefined ? [] : [found]; + }); + return [...starred, ...items.filter((item) => !list.includes(item.key))]; +} diff --git a/src/launchpad/index.html b/src/launchpad/index.html index 62456bb90..a9935de5b 100644 --- a/src/launchpad/index.html +++ b/src/launchpad/index.html @@ -61,20 +61,17 @@ .app { display: flex; min-height: 100vh; margin-left: var(--lazurio-rail-width, 72px); background: var(--bg); border-left: 1px solid var(--lz-line); } .column { position: sticky; top: 0; z-index: 20; display: flex; flex: none; flex-direction: column; gap: 10px; width: var(--column-width); height: 100vh; padding: 16px 10px 10px; background: var(--lz-gray-25); border-right: 1px solid var(--lz-line-faint); } .column-apps, .column-settings { display: flex; flex: 1; min-height: 0; flex-direction: column; gap: 10px; } -.column-search { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: var(--lz-radius-pill); background: var(--lz-gray-100); color: var(--muted-fg); } -.column-search:focus-within { box-shadow: 0 0 0 2px var(--lz-accent); } -.column-search input { flex: 1; min-width: 0; width: auto; height: auto; padding: 0; border: 0; outline: 0; background: transparent; color: var(--fg); font: 13.5px var(--font-sans); } -.column-search input::-webkit-search-cancel-button { display: none; } .column-scroll { display: flex; flex: 1; min-height: 0; flex-direction: column; gap: 14px; overflow-y: auto; } .column-title { padding: 0 8px; font-size: 18px; font-weight: var(--lz-weight-title); letter-spacing: var(--lz-track-title); } .column-label { padding: 4px 10px 6px; color: var(--muted-fg); font-size: 13px; } -.column-group { display: grid; gap: 1px; } -.column-empty { padding: 4px 10px; color: var(--muted-fg); font-size: 13px; } +.column-favorites { display: grid; gap: 1px; padding-bottom: 8px; border-bottom: 1px solid var(--lz-line-faint); } +.column-hint { padding: 2px 10px 4px; color: var(--muted-fg); font-size: 13px; } .column-foot { display: grid; gap: 8px; padding-top: 8px; border-top: 1px solid var(--lz-line-faint); } .column-foot:not(:has(> :not([hidden]))) { display: none; } .menu { display: grid; gap: 1px; margin: 0; padding: 0; list-style: none; } .menu-item { display: flex; align-items: center; gap: 10px; min-width: 0; height: 34px; padding: 0 10px; border-radius: var(--lz-radius-sm); color: var(--fg); font-size: 14px; text-decoration: none; } -a.menu-item:hover { background: var(--hover); } +a.menu-item:hover, button.menu-item:hover { background: var(--lz-gray-50); } +button.menu-item { width: 100%; border: 0; background: transparent; font-weight: 400; cursor: pointer; } .menu-item[aria-current="page"] { background: var(--hover); font-weight: var(--lz-weight-akce); } .menu-item .icon { width: 17px; height: 17px; } .column-top .menu-item { font-weight: var(--lz-weight-akce); } @@ -82,7 +79,9 @@ .menu-stone { display: block; flex: none; width: 20px; height: 20px; } .menu-mark { display: grid; flex: none; width: 20px; height: 20px; place-items: center; color: var(--muted-fg); } .menu-mark .icon { width: 15px; height: 15px; } -.menu-tail { margin-left: auto; } +.menu-external { margin-left: auto; width: 13px; height: 13px; color: var(--lz-ink-faint); opacity: 0; } +.menu-item:hover .menu-external { opacity: 1; } +.menu-soon { margin-left: auto; padding: 1px 7px; border: 1px solid var(--lz-line); border-radius: var(--lz-radius-pill); color: var(--muted-fg); font-size: 11.5px; font-weight: 400; } .sidebar-notice, .update { display: grid; gap: 0.35rem; padding: 0.625rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--card); font-size: 12px; } .sidebar-notice { color: var(--muted-fg); overflow-wrap: anywhere; } .sidebar-notice code { display: block; margin-top: 0.35rem; padding: 0.25rem 0.4rem; border-radius: var(--lz-radius-xs); background: var(--muted); border: 1px solid var(--border); color: var(--fg); font-size: 11px; user-select: all; white-space: pre-wrap; overflow-wrap: anywhere; } @@ -117,37 +116,55 @@ wireframe LaunchpadHome.tsx). */ .apps-head { display: flex; align-items: center; gap: 12px; min-height: 34px; margin: 4px 0 -4px; } .apps-head-name { display: flex; align-items: center; gap: 12px; min-width: 0; } +.apps-where { display: grid; gap: 2px; min-width: 0; } +.apps-environment { display: inline-flex; align-items: center; gap: 6px; color: var(--fg); font-size: 15px; font-weight: var(--lz-weight-akce); } +.apps-environment .icon { width: 15px; height: 15px; } .apps-title, .module-title { font-size: 28px; font-weight: var(--lz-weight-title); letter-spacing: var(--lz-track-title); line-height: 1.2; } -.apps-head > button { margin-left: auto; } +.apps-guide { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; color: var(--muted-fg); font-size: 14px; font-weight: var(--lz-weight-akce); text-decoration: none; } +.apps-guide:hover { color: var(--fg); } .org-mark { display: grid; flex: none; width: 32px; height: 32px; place-items: center; overflow: hidden; border-radius: var(--lz-radius-sm); background: var(--lz-white); box-shadow: inset 0 0 0 1px var(--lz-line); color: var(--fg); font-size: 12px; font-weight: var(--lz-weight-akce); letter-spacing: 0.02em; } -.org-mark.small { width: 22px; height: 22px; font-size: 9.5px; } .org-mark[data-personal] { border-radius: 50%; background: var(--lz-ink); color: var(--lz-white); box-shadow: none; } .org-mark img { display: block; width: 100%; height: 100%; object-fit: cover; } -.org-picker { position: relative; } -.org-picker summary { display: flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; border-radius: var(--radius-control); } -.org-picker summary::-webkit-details-marker { display: none; } -.org-picker-chevron { width: 20px; height: 20px; color: var(--muted-fg); } -.org-picker-list { position: absolute; z-index: 10; top: calc(100% + 6px); left: 0; display: grid; gap: 2px; min-width: 16rem; margin: 0; padding: 6px; list-style: none; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); box-shadow: 0 16px 40px -20px rgb(0 0 0 / 45%); } -.org-picker-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-control); color: var(--fg); font-size: 14px; text-decoration: none; } -.org-picker-item:hover, .org-picker-item[aria-current] { background: var(--hover); } .apps-section { display: grid; gap: 12px; min-width: 0; } .section-head { display: flex; align-items: center; gap: 10px; border-bottom: 2px solid var(--lz-blue-500); } .section-pill { padding: 5px 12px; border-radius: 7px 7px 0 0; background: var(--lz-blue-500); color: var(--lz-on-accent); font-size: 14px; font-weight: var(--lz-weight-akce); } .section-count { color: var(--muted-fg); font-size: 13px; } -.section-subtitle { margin-top: 0; font-size: 15px; font-weight: var(--lz-weight-akce); } -.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr)); gap: 16px; } -.tile { position: relative; display: flex; align-items: center; gap: 16px; min-width: 0; min-height: 88px; padding: 16px 18px; border: 1px solid var(--lz-line-faint); border-radius: var(--lz-radius-md); background: var(--card); color: var(--fg); text-decoration: none; transition: border-color 120ms ease, box-shadow 120ms ease; } -a.tile:hover, a.tile:focus-visible { border-color: color-mix(in srgb, var(--stone-accent, var(--lz-ink-faint)) 60%, var(--lz-line)); box-shadow: 0 6px 18px -12px rgb(0 0 0 / 35%); } +.tile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; } +@media (max-width: 1100px) { .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } } +@media (max-width: 640px) { .tile-grid { grid-template-columns: minmax(0, 1fr); } } +.tile-wrap { position: relative; display: grid; min-width: 0; } +.tile { position: relative; display: flex; align-items: center; gap: 16px; width: 100%; min-width: 0; min-height: 88px; padding: 16px 40px 16px 18px; border: 1px solid var(--lz-line-faint); border-radius: var(--lz-radius-md); background: var(--card); color: var(--fg); font: inherit; text-align: left; text-decoration: none; cursor: pointer; transition: border-color 120ms ease, box-shadow 120ms ease; } +button.tile { height: auto; justify-content: flex-start; white-space: normal; box-shadow: none; } +.tile:hover, .tile:focus-visible { border-color: color-mix(in srgb, var(--stone-accent, var(--lz-ink-faint)) 60%, var(--lz-line)); background: var(--card); box-shadow: 0 6px 18px -12px rgb(0 0 0 / 35%); } +.tile--new { border-style: dashed; border-color: var(--lz-line); } +.tile-mark--new { border-radius: var(--lz-radius-md); background: var(--lz-gray-50); } .tile-stone { display: block; flex: none; width: 48px; height: 48px; } .tile-mark { display: grid; flex: none; width: 48px; height: 48px; place-items: center; color: var(--muted-fg); } .tile-mark .icon { width: 22px; height: 22px; } .tile-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; } -.tile-name { overflow: hidden; font-size: 16px; font-weight: var(--lz-weight-akce); text-overflow: ellipsis; white-space: nowrap; } +.tile-name { display: flex; align-items: center; gap: 6px; overflow: hidden; font-size: 16px; font-weight: var(--lz-weight-akce); text-overflow: ellipsis; white-space: nowrap; } +.tile-star { display: inline-grid; flex: none; color: var(--fg); } +.tile-star .icon { width: 13px; height: 13px; } .tile-desc { overflow: hidden; color: var(--muted-fg); font-size: 14px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; } -.tile-note { display: inline-flex; align-items: center; gap: 6px; color: var(--muted-fg); font-size: 13px; } -.tile-note[data-tone="warn"] { color: var(--warning-fg); } -.tile-open { position: absolute; top: 12px; right: 12px; width: 14px; height: 14px; color: var(--lz-ink-faint); } -a.tile:hover .tile-open { color: var(--fg); } +/* The "⋯" menu at a tile's top right, always visible but quiet; it lists + the star and the way to the module's overview (design system lz-menu, + selection variant A). */ +.tile-menu { position: absolute; top: 6px; right: 6px; } +.tile-menu-button { display: grid; width: 30px; height: 30px; padding: 0; place-items: center; border: 0; border-radius: var(--lz-radius-sm); background: transparent; box-shadow: none; color: var(--lz-ink-faint); } +.tile-wrap:hover .tile-menu-button { color: var(--muted-fg); } +.tile-menu-button:hover, .tile-menu.is-open .tile-menu-button { background: var(--lz-gray-100); color: var(--fg); } +.tile-menu-button .icon { width: 18px; height: 18px; } +.tile-menu-list { position: absolute; z-index: 30; top: 34px; right: 0; display: grid; min-width: 250px; padding: 6px; border: 1px solid var(--lz-gray-300); border-radius: var(--lz-radius-md); background: var(--lz-white); } +.tile-menu-item { display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; height: auto; padding: 8px 10px; border: 0; border-radius: var(--lz-radius-sm); background: transparent; box-shadow: none; color: var(--fg); font: 400 14px/1.4 var(--font-sans); text-align: left; text-decoration: none; cursor: pointer; } +.tile-menu-item:hover, .tile-menu-item:focus-visible { background: var(--lz-gray-25); } +.tile-menu-item.is-favorite .icon { fill: currentColor; } +/* A short message at the foot of the page (the wireframe's toast). */ +.toast-region { position: fixed; z-index: 60; bottom: 28px; left: 50%; transform: translateX(-50%); } +.toast { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border: 1px solid var(--lz-gray-300); border-radius: var(--lz-radius-md); background: var(--lz-white); color: var(--fg); font-size: 14px; white-space: nowrap; } +.market-head { display: flex; align-items: center; gap: 14px; } +.market-icon { display: grid; width: 52px; height: 52px; place-items: center; border-radius: var(--lz-radius-md); background: var(--lz-gray-100); color: var(--fg); } +.market-icon .icon { width: 26px; height: 26px; } +.empty { padding: 28px; border: 1px dashed var(--lz-line); border-radius: var(--lz-radius-md); background: var(--lz-paper); color: var(--muted-fg); font-size: 14px; text-align: center; } /* The module overview: back, head, then the cards of Settings. */ .back { display: inline-flex; align-items: center; gap: 4px; align-self: flex-start; margin-bottom: -12px; color: var(--muted-fg); font-size: 14px; font-weight: var(--lz-weight-akce); text-decoration: none; } @@ -204,7 +221,7 @@ colour never carries a state alone). */ .dot { display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 999px; background: var(--success); } .dot[data-state="blocked"], .dot[data-state="stopped"], .dot[data-state="unknown"] { background: var(--lz-gray-300); } -.dot[data-state="starting"], .dot[data-state="blocked-warn"] { background: var(--lz-warning); } +.dot[data-state="starting"] { background: var(--lz-warning); } .dot[data-state="failed"] { background: var(--lz-red-500); } .module-status[data-state="running"] { color: var(--success-fg); } .catalog-status { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; } @@ -373,38 +390,47 @@ - - - - + + + + + + + + + + + - - + +
@@ -453,16 +480,24 @@

Product updat

-
-
+
Guide

Reading Organizations…

+ +
+

Marketplace

Coming soon

+

+
+
@@ -534,6 +569,7 @@

Product updat +

diff --git a/src/launchpad/messages.ts b/src/launchpad/messages.ts index 0473117c6..8f205a490 100644 --- a/src/launchpad/messages.ts +++ b/src/launchpad/messages.ts @@ -364,13 +364,9 @@ const en = { toolsMcpPromptHint: "Copy this prompt and paste it into a new chat in T3 Code in this Environment. The agent asks which app you want, sets the server up and lets you sign in in your browser. You never copy an API key.", // The Apps home and its left column (decision F36). + appsTitle: "Apps", appsAll: "All modules", - appsSearch: "Search", - appsSearchLabel: "Search modules", appsPersonal: "Personal", - appsWorkspaceSubtitle: "{name} Workspace", - appsProductionspaceSubtitle: - "The Organization's repositories with their own release, read-only", appsModulesOne: "{count} module", appsModulesFew: "{count} modules", appsModulesMany: "{count} modules", @@ -379,21 +375,13 @@ const en = { appsRepositoriesMany: "{count} repositories", appsOpenApp: "Open app", appsOpenAppNamed: "Open the app of {name} in a new tab", - appsOverviewNamed: "Overview of the module {name}", - appsCannotStart: "Cannot start", appsNoApp: "No app", - appsRunning: "running", - appsRepositoryNamed: "The repository {name} on GitHub, in a new tab", - appsOrganizationPick: "Choose an Organization", appsAbout: "About the module", - appsFolder: "Folder", appsLog: "App log", appsLogHint: "The Launchpad does not show the log yet. Its last lines are read on the command line of this Environment:", appsStarting: "Starting {name}…", appsStartFailed: "{name} could not be opened. Its overview says why.", - appsNoMatch: "No module matches.", - appsColumn: "Modules of {name}", // The org-agnostic description of a module by its stone's semantic key, // when its app declares none (decision F36; the root Launchpad's // `description.`). @@ -419,13 +407,38 @@ const en = { appsDescriptionSystem: "Operations tools and technical infrastructure.", appsDescriptionDefault: "An application for day-to-day work in the {module} module.", + // The Apps home and column of the Organization rail (decision F36 + // addendum of 2026-10-04): the wireframe's words. + appsSayNoApp: "The module {name} has no app yet.", + appsSayCannotStart: "The app of the module {name} cannot start right now.", + appsSayRepository: "The repository {name} has no app.", + appsMore: "More options for {name}", + appsFavorites: "Favourites", + appsFavoritesHint: "Star a module to pin it here.", + appsFavoriteAdd: "Add to favourites", + appsFavoriteRemove: "Remove from favourites", + appsFavoriteMark: "In favourites", + appsInfoModule: "Module information", + appsInfoRepository: "Repository information", + appsNewModule: "New module", + appsNewModuleSub: "You found it with an agent in Chat", + appsNewModuleCopied: + "The new module's brief is in your clipboard: paste it into a new chat.", + appsNewModuleCopyFailed: + "The brief could not be copied; open Chat and describe the new module to the agent.", + appsNewModulePrompt: + "I want to found a new module in the Organization {name} (GitHub {login}).\n\nBefore you create anything, ask me one question at a time:\n1. What the module is for and who will use it.\n2. What it should be called (a name and a short slug).\n3. Whether it should have an app and which (vite-react, astro, astro-starlight, bun-service, python-uv), or none.\n4. Which Teams should have access to it.\n\nThen follow the Lazurio Module Standard (skill lazurio-module-standard):\n- found the module with the scaffold `lazurio module create {login}/ --stack --teams ` from a task worktree of the Organization's root, never by hand, and first show me the plan with --dry-run;\n- check that the module's repository exists on GitHub in the Organization {login} and that the chosen Teams have access to it;\n- prepare the result as a pull request and ask me before Publication.", + appsGuide: "Guide", + appsMarketplace: "Marketplace", + appsSoon: "coming soon", + appsMarketplaceSoon: "Coming soon", + appsMarketplaceText: + "This is where you will add more modules to the Environment. We are preparing it.", + appsMarketplaceOrganization: + " Until then, modules are added in the Dashboard of the Organization {name}.", title: "Lazurio Launchpad", homeTitle: "Launchpad", - catalogNavigation: "Organizations", catalogBreadcrumb: "Where you are in the Launchpad", - catalogIntro: - "The Organizations and modules of this Folder, read from its organizations/ directory each time. A module's page starts, stops and opens its app.", - catalogRefresh: "Refresh", catalogLoading: "Reading Organizations…", catalogLoadFailed: "The Organizations could not be read. Try Refresh; if it keeps failing, run lazurio organization list in the CLI.", @@ -433,11 +446,8 @@ const en = { "No Organizations in this Folder. An Organization appears here once its repository is in organizations/.", catalogNotFound: "This Organization or module is not in this Folder. It may have been renamed or removed; see all Organizations.", - catalogAll: "All Organizations", chat: "Chat", - chatTitle: "Open T3 Code in this Environment", mausbot: "Lazurio MausBot", - mausbotTitle: "Open Lazurio MausBot in this Environment", catalogModules: "Modules", catalogNoModules: "This Organization declares no modules.", catalogSectionWorkspace: "Workspace", @@ -449,7 +459,6 @@ const en = { catalogState: "Resolution state", catalogIssues: "Issues", catalogApps: "Apps", - catalogDefaultApp: "Default app", catalogDefaultMark: "default", catalogPath: "Path", catalogStatus: "Can it run", @@ -1075,13 +1084,9 @@ const cs: Record = { toolsMcpPromptHint: "Zkopírujte tenhle prompt a vložte ho do nového chatu v T3 Code na tomhle Environmentu. Agent se zeptá, kterou aplikaci chcete, server nastaví a přihlášení necháte proběhnout ve svém prohlížeči. Žádný API klíč nikdy nekopírujete.", // The Apps home and its left column (decision F36). + appsTitle: "Apps", appsAll: "Všechny moduly", - appsSearch: "Hledat", - appsSearchLabel: "Hledat moduly", appsPersonal: "Osobní", - appsWorkspaceSubtitle: "{name} Workspace", - appsProductionspaceSubtitle: - "Repozitáře Organizace s vlastním releasem, jen pro čtení", appsModulesOne: "{count} modul", appsModulesFew: "{count} moduly", appsModulesMany: "{count} modulů", @@ -1090,21 +1095,13 @@ const cs: Record = { appsRepositoriesMany: "{count} repozitářů", appsOpenApp: "Otevřít aplikaci", appsOpenAppNamed: "Otevřít aplikaci modulu {name} v nové záložce", - appsOverviewNamed: "Přehled modulu {name}", - appsCannotStart: "Nelze spustit", appsNoApp: "Bez aplikace", - appsRunning: "běží", - appsRepositoryNamed: "Repozitář {name} na GitHubu v nové záložce", - appsOrganizationPick: "Vybrat Organizaci", appsAbout: "O modulu", - appsFolder: "Složka", appsLog: "Log aplikace", appsLogHint: "Launchpad log zatím neukazuje. Jeho poslední řádky přečteš v příkazové řádce tohoto Environmentu:", appsStarting: "Spouštím {name}…", appsStartFailed: "{name} se nepodařilo otevřít. Proč, říká přehled modulu.", - appsNoMatch: "Žádný modul neodpovídá.", - appsColumn: "Moduly {name}", // The org-agnostic description of a module by its stone's semantic key, // when its app declares none (decision F36; the root Launchpad's // `description.`). @@ -1129,13 +1126,38 @@ const cs: Record = { appsDescriptionApp: "Pracovní podklady a soubory tohoto modulu.", appsDescriptionSystem: "Provozní nástroje a technické zázemí.", appsDescriptionDefault: "Aplikace pro každodenní práci v modulu {module}.", + // The Apps home and column of the Organization rail (decision F36 + // addendum of 2026-10-04): the wireframe's words. + appsSayNoApp: "Modul {name} zatím nemá aplikaci.", + appsSayCannotStart: "Aplikace modulu {name} teď nejde spustit.", + appsSayRepository: "Repozitář {name} nemá aplikaci.", + appsMore: "Další volby pro {name}", + appsFavorites: "Oblíbené", + appsFavoritesHint: "Hvězdičkou u modulu si ho připneš sem.", + appsFavoriteAdd: "Přidat do oblíbených", + appsFavoriteRemove: "Odebrat z oblíbených", + appsFavoriteMark: "V oblíbených", + appsInfoModule: "Informace o modulu", + appsInfoRepository: "Informace o repozitáři", + appsNewModule: "Nový modul", + appsNewModuleSub: "Založíš ho s agentem v Chatu", + appsNewModuleCopied: + "Zadání nového modulu je ve schránce: vlož ho v Chatu do nového vlákna.", + appsNewModuleCopyFailed: + "Zadání se nepodařilo zkopírovat; otevři Chat a popiš agentovi nový modul.", + appsNewModulePrompt: + "Chci založit nový modul v Organizaci {name} (GitHub {login}).\n\nNež cokoli vytvoříš, zeptej se mě postupně, jednu otázku po druhé:\n1. K čemu modul je a kdo ho bude používat.\n2. Jak se má jmenovat (název a krátký slug).\n3. Jestli má mít aplikaci a jakou (vite-react, astro, astro-starlight, bun-service, python-uv), nebo žádnou.\n4. Které Teamy k němu mají mít přístup.\n\nPak postupuj podle Lazurio Module Standard (skill lazurio-module-standard):\n- modul založ scaffoldem `lazurio module create {login}/ --stack --teams ` z task worktree rootu Organizace, nikdy ručně, a nejdřív mi ukaž plán přes --dry-run;\n- ověř, že repozitář modulu existuje na GitHubu v Organizaci {login} a že k němu mají přístup vybrané Teamy;\n- výsledek připrav jako pull request a před Publikací se mě zeptej.", + appsGuide: "Guide", + appsMarketplace: "Marketplace", + appsSoon: "již brzy", + appsMarketplaceSoon: "Již brzy", + appsMarketplaceText: + "Tady si do Environmentu budeš přidávat další moduly. Připravujeme to.", + appsMarketplaceOrganization: + " Do té doby přibývají moduly v Dashboardu Organizace {name}.", title: "Lazurio Launchpad", homeTitle: "Launchpad", - catalogNavigation: "Organizace", catalogBreadcrumb: "Kde v Launchpadu jste", - catalogIntro: - "Organizace a moduly tohoto Folderu, pokaždé znovu načtené z jeho složky organizations/. Stránka modulu jeho aplikaci spouští, zastavuje a otevírá.", - catalogRefresh: "Načíst znovu", catalogLoading: "Načítám Organizace…", catalogLoadFailed: "Organizace nelze načíst. Zkuste Načíst znovu; když to nepomůže, spusťte v CLI lazurio organization list.", @@ -1143,11 +1165,8 @@ const cs: Record = { "V tomhle Folderu nejsou žádné Organizace. Organizace se tu objeví, jakmile je její repozitář v organizations/.", catalogNotFound: "Tahle Organizace nebo modul v tomhle Folderu není. Možná byl přejmenován nebo odstraněn; podívejte se na všechny Organizace.", - catalogAll: "Všechny Organizace", chat: "Chat", - chatTitle: "Otevřít T3 Code na tomto Environmentu", mausbot: "Lazurio MausBot", - mausbotTitle: "Otevřít Lazurio MausBot na tomto Environmentu", catalogModules: "Moduly", catalogNoModules: "Tahle Organizace nedeklaruje žádné moduly.", catalogSectionWorkspace: "Workspace", @@ -1159,7 +1178,6 @@ const cs: Record = { catalogState: "Stav rozlišení", catalogIssues: "Problémy", catalogApps: "Aplikace", - catalogDefaultApp: "Výchozí aplikace", catalogDefaultMark: "výchozí", catalogPath: "Cesta", catalogStatus: "Lze spustit", diff --git a/src/launchpad/organization-owner.ts b/src/launchpad/organization-owner.ts new file mode 100644 index 000000000..191ef0290 --- /dev/null +++ b/src/launchpad/organization-owner.ts @@ -0,0 +1,87 @@ +import type { PresetName } from "../folder/presets"; +import type { ToolsEnvironment } from "../tools/overview"; +import { resolveOnPath } from "../tools/status"; + +// Whether this Environment's GitHub identity is an Owner of an Organization +// (decision F36 addendum of 2026-10-04): GitHub's own, live answer, read +// with the Environment's `gh` (`gh api user/memberships/orgs/`: an +// active membership with the role `admin`). It decides only whether the +// Apps home offers "+ Nový modul"; it grants nothing, and no local rule +// stands in for it. A Team Environment acts under the Team's brokered +// identity and never founds modules for a person, and an Organization +// without a bound GitHub login has none to ask: both are no, without a +// call. Every failure is no (fail closed). An answer is kept a few +// minutes per login. + +export const ownerCheck = Object.freeze({ + timeoutMs: 10_000, + cacheMs: 5 * 60_000, +}); + +const login = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/; + +/** Whether a membership answer of the GitHub API is an active Owner's. */ +export function isOwnerMembership(stdout: string): boolean { + try { + const value = JSON.parse(stdout) as { state?: unknown; role?: unknown }; + return value?.state === "active" && value?.role === "admin"; + } catch { + return false; + } +} + +export function createOwnerCheck( + environment: ToolsEnvironment, + now: () => number = Date.now, +) { + const answers = new Map< + string, + Readonly<{ owner: boolean; until: number }> + >(); + async function ask(organization: string): Promise { + const gh = await resolveOnPath( + "gh", + environment.path, + environment.platform, + ); + if (gh === undefined || !environment.home) return false; + const env: Record = { HOME: environment.home }; + if (environment.path) env.PATH = environment.path; + for (const [name, value] of Object.entries(environment.xdg ?? {})) + env[name] = value; + try { + const result = await environment.run( + [gh, "api", `user/memberships/orgs/${organization}`], + ownerCheck.timeoutMs, + env, + ); + return ( + result !== "timeout" && + result.exitCode === 0 && + isOwnerMembership(result.stdout) + ); + } catch { + return false; + } + } + return { + /** The answer for a bound GitHub login on this Folder's preset. */ + async owner( + organization: string | undefined, + preset: PresetName, + ): Promise { + if ( + organization === undefined || + !login.test(organization) || + preset === "hosted-organization-team" + ) + return false; + const key = organization.toLowerCase(); + const known = answers.get(key); + if (known !== undefined && known.until > now()) return known.owner; + const owner = await ask(organization); + answers.set(key, { owner, until: now() + ownerCheck.cacheMs }); + return owner; + }, + }; +} diff --git a/src/launchpad/routes.ts b/src/launchpad/routes.ts index baa998378..03615eeb0 100644 --- a/src/launchpad/routes.ts +++ b/src/launchpad/routes.ts @@ -30,18 +30,23 @@ export type PageRoute = | Readonly<{ view: "settings"; section: SettingsSection }> /** A folder of the Documents folder (decision F35): `/files` is the * folder itself, `/files//` one below it. */ - | Readonly<{ view: "files"; path: readonly string[] }>; + | Readonly<{ view: "files"; path: readonly string[] }> + /** The Marketplace of the Environment, at the foot of the Apps column + * (decision F36 addendum of 2026-10-04): for now it says it is coming. */ + | Readonly<{ view: "marketplace" }>; -/** The three frames of the page: the catalog (home, Organization, module) - * with the Organizations in the sidebar, the Files page beside the same - * sidebar, and Settings with its navigation. */ -export type PageFrame = "catalog" | "files" | "settings"; +/** The frames of the page: the Apps home (home, Organization, module), the + * Files page and the Marketplace beside the same Apps column, and Settings + * with its navigation. */ +export type PageFrame = "catalog" | "files" | "marketplace" | "settings"; export const routeFrame = (route: PageRoute): PageFrame => route.view === "settings" ? "settings" : route.view === "files" ? "files" - : "catalog"; + : route.view === "marketplace" + ? "marketplace" + : "catalog"; /** Every path the server answers with the page. The two catalog patterns are * the server's route parameters; the page reads its segments itself. */ @@ -51,6 +56,7 @@ export const pagePaths: readonly string[] = [ "/o/:organization/:module", "/files", "/files/*", + "/marketplace", "/settings", ...settingsSections.map((section) => `/settings/${section}`), ]; @@ -91,6 +97,7 @@ export function pageRoute(pathname: string): PageRoute { return { view: "files", path: "segments" in parsed ? parsed.segments : [] }; } const path = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname; + if (path === "/marketplace") return { view: "marketplace" }; if (path.startsWith("/o/")) { const parts = path.slice("/o/".length).split("/"); const organization = segment(parts[0]); @@ -120,6 +127,7 @@ export function routePath(route: PageRoute): string { if (route.view === "module") return modulePath(route.organization, route.module); if (route.view === "files") return filesUrlPath(route.path); + if (route.view === "marketplace") return "/marketplace"; return settingsPath(route.section); } @@ -153,6 +161,11 @@ export function routeTitle( document: `${route.module} · ${organization} — ${copy.title}`, }; } + if (route.view === "marketplace") + return { + heading: copy.appsMarketplace, + document: `${copy.appsMarketplace} — ${copy.title}`, + }; if (route.view === "files") { const folder = route.path.at(-1); return { diff --git a/src/launchpad/server.ts b/src/launchpad/server.ts index 0aec8fc9d..fa3518cfe 100644 --- a/src/launchpad/server.ts +++ b/src/launchpad/server.ts @@ -24,6 +24,7 @@ import { processModuleHost, } from "../modules/module-operations"; import { readFolderCatalog } from "../organizations/catalog"; +import { selectCatalogOrganization } from "../organizations/catalog-selection"; import { readOrganizationApplications } from "../organizations/read-applications"; import type { RecoveryResult } from "../recover/recover"; import { activatableTools, toolSelection } from "../tools/catalog"; @@ -51,6 +52,7 @@ import { serveHealthSocket } from "./health-socket"; import { type AuthFetcher, createHostedTrust } from "./hosted-trust"; import { BodyTooLarge, readJsonBody } from "./json-body"; import { issueMausbotLink } from "./mausbot"; +import { createOwnerCheck } from "./organization-owner"; import { admitLocal, pageRoutes, privatePage, serveShell } from "./page"; import { shellDocument } from "./shell-document"; import { @@ -78,6 +80,11 @@ export type HostedOptions = Readonly<{ /** The Lazurio shell's data document (decision F36). */ export const shellDocumentPath = "/.lazurio/shell.json"; +// Whether this Environment's GitHub identity is an Owner of an Organization +// (decision F36 addendum of 2026-10-04): `` names it as the catalog's +// routes do. +const ownerRoute = /^\/api\/organizations\/([^/]+)\/owner$/; + // The module lifecycle routes (launchpad-parity B3): `` and `` // are URL-encoded segments naming the module as `lazurio module` does. const moduleRoute = @@ -245,6 +252,7 @@ export async function startLaunchpad( githubLoginRefused(await folderPreset(folder), tool, action), }); const installing = new Set(); + const owners = createOwnerCheck(toolsEnvironment); let closing = false; const headers = { "Cache-Control": "no-store", @@ -344,6 +352,31 @@ export async function startLaunchpad( return response({ error: "operation-failed" }, 500); } } + const ownerRequest = ownerRoute.exec(url.pathname); + if (ownerRequest !== null) { + // Read-only and behind the same admission as every read: GitHub's + // own answer, never a local rule (organization-owner.ts). + if (request.method !== "GET") + return response({ error: "method-not-allowed" }, 405); + if (closing) return response({ error: "closing" }, 503); + try { + const name = decodeURIComponent(ownerRequest[1] as string); + const selection = selectCatalogOrganization( + await readFolderCatalog(folder), + name, + ); + server.timeout(request, 30); + const owner = + selection.kind === "found" && + (await owners.owner( + selection.organization.forgeLogin, + await folderPreset(folder), + )); + return response({ kind: "organization-owner", owner }); + } catch { + return response({ kind: "organization-owner", owner: false }); + } + } if (url.pathname.startsWith("/api/files/")) { if (closing) return response({ error: "closing" }, 503); try { diff --git a/src/launchpad/shell-document.ts b/src/launchpad/shell-document.ts index 1e5026388..ab846fbfa 100644 --- a/src/launchpad/shell-document.ts +++ b/src/launchpad/shell-document.ts @@ -24,7 +24,8 @@ import { initialsOf } from "../shell/view"; * Organization's slug, the Dashboard's canonical `org_slug`). */ export const dashboardUrl = "https://dashboard.lazurio.ai/"; export const accountUrl = "https://dashboard.lazurio.ai/settings"; -export const addOrganizationUrl = "https://dashboard.lazurio.ai/add-organization"; +export const addOrganizationUrl = + "https://dashboard.lazurio.ai/add-organization"; export const organizationDashboardUrl = (slug: string): string => `https://dashboard.lazurio.ai/orgs/${encodeURIComponent(slug)}`; diff --git a/src/launchpad/ui.ts b/src/launchpad/ui.ts index 495ee4312..c3b1c6253 100644 --- a/src/launchpad/ui.ts +++ b/src/launchpad/ui.ts @@ -1,5 +1,7 @@ -import { parseShell, type Shell } from "../shell/contract"; +import { currentEnvironment, parseShell, type Shell } from "../shell/contract"; import { defineShellElements, provideShell } from "../shell/elements"; +import { shellMessages } from "../shell/messages"; +import { environmentName } from "../shell/view"; import { createCatalogPanel } from "./catalog-panel"; import type { PublicEntry } from "./chat"; import { @@ -61,6 +63,12 @@ let entry: PublicEntry | null = null; // own credential and hands over (the forks let the elements read it). defineShellElements(); const columnHead = document.querySelector("#column-head"); +const rail = document.querySelector("#rail"); +// The documentation of the Launchpad's "Guide" (the root Launchpad's +// `guideDocumentationUrl`), in the page's language. +const guide = document.querySelector("#catalog-guide"); +const marketplaceText = + document.querySelector("#marketplace-text"); let shellDocument: Shell | null = null; async function readShell() { try { @@ -92,6 +100,30 @@ const catalog = createCatalogPanel({ shellDocument?.organizations.find( (organization) => organization.slug.toLowerCase() === slug.toLowerCase(), )?.avatar ?? null, + environment: () => { + if (shellDocument === null) return null; + const current = currentEnvironment(shellDocument); + return { + name: environmentName(current, shellMessages(locale)), + icon: ( + { + personal: "user", + work: "user", + team: "users", + automated: "bot", + workstation: "laptop", + } as const + )[current.kind], + }; + }, + // The space the Apps home shows: on a workstation with several + // Organizations the rail and the picker name the one opened. + space: (space) => { + for (const element of [rail, columnHead]) + if (element !== null && element.getAttribute("space") !== space) + element.setAttribute("space", space); + }, + newModule: (prompt) => handOver(prompt), }); // The Files page (decision F35): the Documents folder of this Environment. // Behind a gateway a download is a plain link the session cookie admits; @@ -126,10 +158,23 @@ const shell = createShell({ copy: () => copy, displayName: (organization) => catalog.displayName(organization), onRoute: (route) => { - // The switch marks Apps, except inside Settings (the target shell). - if (route.view === "settings") columnHead?.removeAttribute("active"); - else columnHead?.setAttribute("active", "apps"); - catalog.render(route); + // The switch marks Apps, the gear Settings (the Organization rail). + columnHead?.setAttribute( + "active", + route.view === "settings" ? "settings" : "apps", + ); + // Back on "Všechny moduly" the catalog is read again. + if (route.view === "home" || route.view === "organization") + void catalog.refresh(); + else catalog.render(route); + if (route.view === "marketplace" && marketplaceText !== null) { + const name = catalog.scopeName(route); + marketplaceText.textContent = + copy.appsMarketplaceText + + (name === null + ? "" + : copy.appsMarketplaceOrganization.replace("{name}", name)); + } files.show(route); if ( route.view === "settings" && @@ -270,6 +315,8 @@ function relabel() { if (key && Object.hasOwn(copy, key)) element.textContent = copy[key as MessageKey]; } + if (guide !== null) + guide.href = `https://documentation.lazurio.ai/${locale === "en" ? "en" : "cs"}/guide/?utm_source=launchpad&utm_medium=product&utm_campaign=guide`; shell.relabel(); recovery.render(); files.relabel(); @@ -467,6 +514,45 @@ const pairing: Readonly< accept: mausbotPairLink, }, }; +// The address to follow into Chat or Automate: a one-time pairing link on +// its origin when the server mints one, otherwise the plain origin. +async function pairedHref(app: string): Promise { + const pair = Object.hasOwn(pairing, app) ? pairing[app] : undefined; + const plain = + entry === null || pair === undefined ? undefined : pair.origin(entry); + if (pair === undefined || plain === undefined) return null; + try { + const { value, ok } = await post(pair.path, {}); + return (ok && pair.accept(value, plain)) || plain; + } catch { + return plain; + } +} +// "+ Nový modul" (decision F36 addendum of 2026-10-04): the prepared prompt +// goes to the clipboard and this Environment's Chat opens in a new tab, where +// the person pastes it into a new chat. The T3 Code fork cannot take a +// prompt draft by link yet (Lazurio/t3code#35); once it can, Chat opens with +// the prompt in its composer instead. A workstation has no Chat origin: the +// prompt is copied all the same. +async function handOver(prompt: string): Promise { + const tab = entry === null ? null : window.open("about:blank", "_blank"); + let copied = false; + try { + await navigator.clipboard.writeText(prompt); + copied = true; + } catch { + copied = false; + } + if (tab !== null) { + const next = await pairedHref("chat"); + if (next === null) tab.close(); + else { + tab.opener = null; + tab.location.href = next; + } + } + return copied; +} let following = false; document.addEventListener("lazurio-app", (event) => { const detail = (event as CustomEvent<{ app?: unknown; href?: unknown }>) @@ -482,19 +568,14 @@ document.addEventListener("lazurio-app", (event) => { const pair = Object.hasOwn(pairing, detail.app) ? pairing[detail.app] : undefined; - const plain = - entry === null || pair === undefined ? undefined : pair.origin(entry); - if (pair === undefined || plain === undefined) return; + if (entry === null || pair === undefined || pair.origin(entry) === undefined) + return; event.preventDefault(); if (following) return; following = true; + const { app, href } = detail; void (async () => { - let next = plain; - try { - const { value, ok } = await post(pair.path, {}); - next = (ok && pair.accept(value, plain)) || next; - } catch {} - location.assign(next); + location.assign((await pairedHref(app)) ?? href); })(); }); // Back from the app restores this page from the bfcache with the click that diff --git a/src/shell/elements.ts b/src/shell/elements.ts index f5f3a8185..ad4c00a4e 100644 --- a/src/shell/elements.ts +++ b/src/shell/elements.ts @@ -12,8 +12,8 @@ import { initialsOf, railSpaces, type ShellApp, - shellApps, type SwitcherSection, + shellApps, switcherSections, switchTabs, } from "./view"; @@ -230,7 +230,11 @@ class Switcher { this.fill(); }); this.input.addEventListener("keydown", (event) => this.key(event)); - search.append(icon("search", 16), this.input, element("span", "kbd", "⌘⇧E")); + search.append( + icon("search", 16), + this.input, + element("span", "kbd", "⌘⇧E"), + ); this.box.setAttribute("role", "dialog"); this.box.setAttribute("aria-label", copy.switcher); this.box.append(search, this.list, this.foot); @@ -260,14 +264,14 @@ class Switcher { } } private mark() { - this.links.forEach((link, index) => - link.classList.toggle("is-cursor", index === this.cursor), - ); + for (const [index, link] of this.links.entries()) + link.classList.toggle("is-cursor", index === this.cursor); this.links[this.cursor]?.scrollIntoView({ block: "nearest" }); } private fill() { - const { copy, shell, options } = this; - const sections = switcherSections(shell, copy, { + const copy = this.copy; + const options = this.options; + const sections = switcherSections(this.shell, copy, { here: options.here, all: options.all, app: options.app, @@ -318,7 +322,7 @@ class Switcher { return link; } private section(section: SwitcherSection): HTMLElement { - const { copy } = this; + const copy = this.copy; const group = element("div", "switcher-group"); if (section.head !== null) { const { organization, href } = section.head; @@ -479,8 +483,7 @@ export class LazurioRail extends ShellElement { if (space.initials !== null) mark.textContent = space.initials; else mark.append(icon("user", 18)); link.append(mark); - } else - link.append(organizationMark(space.avatar, space.initials ?? "")); + } else link.append(organizationMark(space.avatar, space.initials ?? "")); scroll.append(link); }); if (shell.addOrganization !== null) { @@ -593,10 +596,10 @@ export class LazurioColumnHead extends ShellElement { backdrop.remove(); switcher.box.remove(); picker.setAttribute("aria-expanded", "false"); - document.removeEventListener("keydown", escape, true); + document.removeEventListener("keydown", onEscape, true); this.open = null; }; - const escape = (event: KeyboardEvent) => { + const onEscape = (event: KeyboardEvent) => { if (event.key !== "Escape") return; event.preventDefault(); close(); @@ -615,7 +618,7 @@ export class LazurioColumnHead extends ShellElement { switcher.box.style.left = `${rect.left}px`; switcher.box.style.width = `${Math.min(Math.max(rect.width, 400), window.innerWidth - rect.left - 8)}px`; backdrop.addEventListener("click", close); - document.addEventListener("keydown", escape, true); + document.addEventListener("keydown", onEscape, true); this.root.append(backdrop, switcher.box); picker.setAttribute("aria-expanded", "true"); this.open = { close }; From ef0057f9704b43ca31c2e0a40f608af442696e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Sun, 4 Oct 2026 00:43:58 +0200 Subject: [PATCH 03/12] WIP: preview answers the Owner question; frame-safe first read Co-Authored-By: Claude Opus 5.5 (1M context) --- scripts/preview-launchpad.ts | 25 +++++++++++++++++++++---- src/launchpad/ui.ts | 13 +++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/scripts/preview-launchpad.ts b/scripts/preview-launchpad.ts index e5ac77b89..917aee660 100644 --- a/scripts/preview-launchpad.ts +++ b/scripts/preview-launchpad.ts @@ -2,9 +2,8 @@ // Folder, never a live one: `bun scripts/preview-launchpad.ts local|hosted // cs|en [port]`. One Organization with root-level and workspace modules in // Workspace, production repositories in Productionspace and an `infra` the -// Launchpad does not list (and a second Organization locally, for the -// picker), a -// synthetic home for Files and Tools. Prints one JSON line: `url` to open +// Launchpad does not list (and a second Organization locally, for the rail), +// a synthetic home for Files and Tools. Prints one JSON line: `url` to open // (local: with the fragment token) and, hosted, `proxy`: a loopback listener // that adds the gateway's Host and cookie, which a browser automation routes // the entry's origin through. Synthetic names only; stop it with Ctrl-C. @@ -25,6 +24,7 @@ import { executionOs } from "../src/folder/platform"; import { presetProfile } from "../src/folder/presets"; import { startLaunchpad } from "../src/launchpad/server"; import { toolsEnvironmentOf } from "../src/tools/overview"; +import { runTool } from "../src/tools/status"; import { writeModule, writeOrganization, @@ -134,6 +134,8 @@ if (mode === "local") // A synthetic home: the Files page shows its Documents, never the account's, // and the Tools page reads no real tool or sign-in. const home = join(parent, "home"); +await mkdir(join(home, "bin"), { recursive: true }); +await writeFile(join(home, "bin", "gh"), "#!/bin/sh\nexit 1\n", { mode: 0o755 }); await mkdir(join(home, "Documents", "Nabídky"), { recursive: true }); await mkdir(join(home, "Documents", "Smlouvy"), { recursive: true }); await writeFile( @@ -151,7 +153,22 @@ const app = await startLaunchpad( undefined, undefined, mode === "hosted" ? { fetcher: async () => new Response("ok") } : {}, - toolsEnvironmentOf({ PATH: "", HOME: home }, process.platform), + // The preview's GitHub identity answers the Owner question of the Apps + // home ("+ Nový modul") as an Owner of the example Organization; no real + // account is asked. + toolsEnvironmentOf( + { PATH: join(home, "bin"), HOME: home }, + process.platform, + async (command, timeoutMs, env) => + command[1] === "api" && + command[2]?.startsWith("user/memberships/orgs/example") + ? { + exitCode: 0, + stdout: JSON.stringify({ state: "active", role: "admin" }), + stderr: "", + } + : runTool(command, timeoutMs, env), + ), {}, undefined, undefined, diff --git a/src/launchpad/ui.ts b/src/launchpad/ui.ts index c3b1c6253..ea09dc338 100644 --- a/src/launchpad/ui.ts +++ b/src/launchpad/ui.ts @@ -153,7 +153,9 @@ const recovery = createRecoveryPanel({ t3codeOrigin: () => chatHref(entry), }); // The frame: routes, the catalog and settings navigation, the breadcrumb and -// the sheet of a narrow viewport. +// the sheet of a narrow viewport. It shows its first route while it is +// created; `framed` says it exists. +let framed = false; const shell = createShell({ copy: () => copy, displayName: (organization) => catalog.displayName(organization), @@ -163,10 +165,11 @@ const shell = createShell({ "active", route.view === "settings" ? "settings" : "apps", ); - // Back on "Všechny moduly" the catalog is read again. - if (route.view === "home" || route.view === "organization") + catalog.render(route); + // Back on "Všechny moduly" the catalog is read again (the first read + // starts below, once the frame exists). + if (framed && (route.view === "home" || route.view === "organization")) void catalog.refresh(); - else catalog.render(route); if (route.view === "marketplace" && marketplaceText !== null) { const name = catalog.scopeName(route); marketplaceText.textContent = @@ -184,6 +187,8 @@ const shell = createShell({ void recovery.refresh(); }, }); +framed = true; + type MachinePeer = { name: string; kind: string; From 8021f94946f0af82a5c9916e58021a2545144b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Sun, 4 Oct 2026 00:46:13 +0200 Subject: [PATCH 04/12] Tests: the shell's Organization rail, picker list and contract; tiles, actions and favourites; GitHub's Owner answer, fail closed Co-Authored-By: Claude Opus 5.5 (1M context) --- tests/apps-view.test.ts | 147 +++++++--- tests/launchpad-shell-routes.test.ts | 14 +- tests/organization-owner.test.ts | 111 ++++++++ tests/shell.test.ts | 402 ++++++++++++++++++--------- 4 files changed, 506 insertions(+), 168 deletions(-) create mode 100644 tests/organization-owner.test.ts diff --git a/tests/apps-view.test.ts b/tests/apps-view.test.ts index 178830e7d..1c1f2c313 100644 --- a/tests/apps-view.test.ts +++ b/tests/apps-view.test.ts @@ -3,17 +3,26 @@ import { createHash } from "node:crypto"; import { readFile } from "node:fs/promises"; import { join } from "node:path"; import { - appsMatch, appsScope, appsSections, + favoriteTiles, moduleDescription, moduleName, moduleStone, + newModulePrompt, pluralKey, tileTarget, } from "../src/launchpad/apps-view"; import { parseCatalog } from "../src/launchpad/catalog-view"; import type { PublicEntry } from "../src/launchpad/chat"; +import { + favoritesFirst, + favoritesKey, + moduleFavorite, + parseFavorites, + repositoryFavorite, + toggleFavorite, +} from "../src/launchpad/favorites"; import { messages } from "../src/launchpad/messages"; import type { Catalog, @@ -22,11 +31,13 @@ import type { CatalogRepository, } from "../src/organizations/catalog"; -// Decision F36: the Apps home as pure functions, like the catalog's view -// tests. One Organization at a time, its two sections Workspace (every -// module) and Productionspace (production repositories, read-only) with -// counts, and where each tile leads: the module's own origin hosted, -// start-then-open locally, the overview without an app. +// Decision F36 and its addendum of 2026-10-04: the Apps home as pure +// functions, like the catalog's view tests. One Organization at a time, its +// two sections Workspace (every module) and Productionspace (production +// repositories, read-only) with counts, clean tiles, favourites first, and +// what a tile does: the module's app on its own origin hosted, +// start-then-open locally, otherwise a short message in the wireframe's +// words. const cs = messages("cs"); const en = messages("en"); @@ -137,7 +148,7 @@ test("the home shows the first Organization; an Organization or module route its ).toBeNull(); }); -test("two sections, Workspace with every module in catalog order and Productionspace read-only, with Czech counts; status only by exception; a module without an app is no failure", () => { +test("two sections, Workspace with every module in catalog order and Productionspace read-only, with Czech counts and no subtitles; clean tiles", () => { const group = appsScope(catalog, { view: "home" }, cs); if (group === null) throw new Error("The fixture has an Organization"); const sections = appsSections(catalog, group, cs, null); @@ -146,7 +157,6 @@ test("two sections, Workspace with every module in catalog order and Productions section.kind, section.title, section.count, - section.subtitle, section.tiles.map((tile) => tile.name), ]), ).toEqual([ @@ -154,26 +164,14 @@ test("two sections, Workspace with every module in catalog order and Productions "workspace", "Workspace", "5 modulů", - "Example Company Workspace", ["Mission Control", "Knowledgebase", "deals", "website", "notes"], ], - [ - "productionspace", - "Productionspace", - "1 repozitář", - "Repozitáře Organizace s vlastním releasem, jen pro čtení", - ["firmware"], - ], + ["productionspace", "Productionspace", "1 repozitář", ["firmware"]], ]); + expect(sections.some((section) => "subtitle" in section)).toBe(false); const [mission, ...workspace] = sections[0]?.tiles ?? []; - expect(workspace.map((tile) => tile.note?.text ?? null)).toEqual([ - null, - null, - "Nelze spustit", - null, - ]); // The declared description first, otherwise the org-agnostic sentence of - // the stone's key; "No app" without an app. + // the stone's key; "No app" without an app. No status row on a tile. expect( workspace.map((tile) => [ tile.name, @@ -198,19 +196,41 @@ test("two sections, Workspace with every module in catalog order and Productions ], ["notes", "Bez aplikace", "/.lazurio/stones/clients-96.png"], ]); + expect(workspace.some((tile) => "note" in tile)).toBe(false); expect(mission?.name).toBe("Mission Control"); expect(mission?.kind === "module" && mission.stone).toEqual({ key: "control", src: "/.lazurio/stones/mission-control-96.png", accent: "var(--lz-blue-500)", }); - const firmware = sections[1]?.tiles[0]; - expect(firmware?.kind === "repository" && firmware.href).toBe(null); - expect(firmware?.note?.text).toBe("Nenaklonovaný"); - expect(firmware?.note?.tone).toBe("muted"); + // The menu's "Informace o modulu" is the module's overview. + expect(mission?.info).toBe("/o/example/mission-control"); +}); + +test("what a tile does: open the app, or say why not, in the wireframe's words", () => { + const group = appsScope(catalog, { view: "home" }, cs); + if (group === null) throw new Error("The fixture has an Organization"); + const [workspace, productionspace] = appsSections(catalog, group, cs, entry); + expect( + workspace?.tiles.map((tile) => + tile.action.kind === "open" ? tile.action.target.kind : tile.action.text, + ), + ).toEqual([ + "hosted", + "hosted", + "hosted", + "Aplikace modulu website teď nejde spustit.", + "Modul notes zatím nemá aplikaci.", + ]); + expect(productionspace?.tiles[0]?.action).toEqual({ + kind: "say", + text: "Repozitář firmware nemá aplikaci.", + }); + // A repository has no page: its menu leads at most to its GitHub page. + expect(productionspace?.tiles[0]?.info).toBeNull(); }); -test("a production repository's tile has no action: no lifecycle target, no page, no status dot; at most its GitHub page", () => { +test("a production repository's tile: read-only, no stone, its GitHub page as its information", () => { const connect: CatalogRepository = { slug: "connect", path: "productionspace/connect", @@ -229,20 +249,75 @@ test("a production repository's tile has no action: no lifecycle target, no page expect(productionspace?.tiles).toEqual([ { kind: "repository", + key: "r:connect", repository: connect, name: "connect", description: "productionspace/connect", - note: null, - href: "https://github.com/example/connect", + action: { kind: "say", text: "The repository connect has no app." }, + info: "https://github.com/example/connect", + favorite: false, }, ]); - // Nothing a module tile has: no target to start or open, no stone. - const [tile] = productionspace?.tiles ?? []; - expect(tile && "target" in tile).toBe(false); - expect(tile && "stone" in tile).toBe(false); } }); +test("favourites: first in their section in the column's order, in the column only those the catalog has, kept per Organization in the browser", () => { + const group = appsScope(catalog, { view: "home" }, cs); + if (group === null) throw new Error("The fixture has an Organization"); + const favorites = [ + moduleFavorite("deals"), + repositoryFavorite("firmware"), + moduleFavorite("gone"), + moduleFavorite("mission-control"), + ]; + const [workspace, productionspace] = appsSections( + catalog, + group, + cs, + null, + favorites, + ); + expect(workspace?.tiles.map((tile) => [tile.name, tile.favorite])).toEqual([ + ["deals", true], + ["Mission Control", true], + ["Knowledgebase", false], + ["website", false], + ["notes", false], + ]); + expect(productionspace?.tiles[0]?.favorite).toBe(true); + expect( + favoriteTiles(catalog, group, cs, null, favorites).map((tile) => tile.key), + ).toEqual(["m:deals", "r:firmware", "m:mission-control"]); + // The stored list: one per Organization, read defensively. + expect(favoritesKey("Example")).toBe("lazurio.favorites:example"); + expect(parseFavorites(null)).toEqual([]); + expect(parseFavorites("{ not json")).toEqual([]); + expect(parseFavorites('{"m:deals": true}')).toEqual([]); + expect( + parseFavorites('["m:deals", "m:deals", "x:other", 7, "r:firmware"]'), + ).toEqual(["m:deals", "r:firmware"]); + expect(toggleFavorite(["m:a"], "m:b")).toEqual(["m:a", "m:b"]); + expect(toggleFavorite(["m:a", "m:b"], "m:a")).toEqual(["m:b"]); + expect( + favoritesFirst( + [{ key: "a" }, { key: "b" }, { key: "c" }], + ["c", "x", "a"], + ).map((item) => item.key), + ).toEqual(["c", "a", "b"]); +}); + +test("the new module's prompt names the Organization and its GitHub login, in the person's language", () => { + const prompt = newModulePrompt("Example Company", "example-org", cs); + expect(prompt).toStartWith( + "Chci založit nový modul v Organizaci Example Company (GitHub example-org).", + ); + expect(prompt).toContain("lazurio module create example-org/"); + expect(prompt).not.toContain("{"); + expect(newModulePrompt("Example Company", "example-org", en)).toContain( + "in the Organization Example Company (GitHub example-org)", + ); +}); + test("a tile opens the app on its own origin hosted, starts it locally, and falls back to the overview", () => { const [mission, knowledgebase, , website, notes] = example.modules as [ CatalogModule, @@ -299,7 +374,7 @@ test("a tile opens the app on its own origin hosted, starts it locally, and fall }); }); -test("Czech plural forms, app directories and the column's search", () => { +test("Czech plural forms, module names and descriptions", () => { const keys = { one: "appsModulesOne", few: "appsModulesFew", @@ -333,8 +408,6 @@ test("Czech plural forms, app directories and the column's search", () => { ), ).toBe("Data, records, and their safe management."); expect(moduleStone(module("ledger")).key).toBe("database"); - expect(appsMatch("knowledgebase", " KNOW ")).toBe(true); - expect(appsMatch("deals", "know")).toBe(false); }); // The vendored brand assets are the pinned bytes (src/shell/vendor/README.md). diff --git a/tests/launchpad-shell-routes.test.ts b/tests/launchpad-shell-routes.test.ts index de3ecc7c4..2ce03f3e4 100644 --- a/tests/launchpad-shell-routes.test.ts +++ b/tests/launchpad-shell-routes.test.ts @@ -193,15 +193,27 @@ posixTest( expect(shell?.locale).toBe("cs"); expect(shell?.environments[0]).toEqual({ id: machine.name, - label: machine.name, + // Named by its kind, never by its machine. + label: null, kind: "work", organizations: [], + assignee: null, apps: { apps: "https://launchpad.workspace.example.lazurio.io/", chat: "https://t3code.workspace.example.lazurio.io/", automate: null, }, }); + // The Owner question of "+ Nový modul": behind the same admission, + // and no for an Organization the Folder does not hold. + const owner = `${base}/api/organizations/example/owner`; + expect((await fetch(owner, { headers: { host } })).status).toBe(401); + const answered = await fetch(owner, { headers: valid }); + expect(answered.status).toBe(200); + expect(await answered.json()).toEqual({ + kind: "organization-owner", + owner: false, + }); } finally { await app.close(); await rm(parent, { recursive: true, force: true }); diff --git a/tests/organization-owner.test.ts b/tests/organization-owner.test.ts new file mode 100644 index 000000000..c45d43543 --- /dev/null +++ b/tests/organization-owner.test.ts @@ -0,0 +1,111 @@ +import { expect, test } from "bun:test"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { + createOwnerCheck, + isOwnerMembership, + ownerCheck, +} from "../src/launchpad/organization-owner"; +import type { ToolRunner } from "../src/tools/status"; + +// Decision F36 addendum of 2026-10-04: whether this Environment's GitHub +// identity is an Owner of an Organization comes only from GitHub +// (`gh api user/memberships/orgs/`), fails closed, is never asked on a +// Team Environment or without a bound login, and is kept a few minutes. + +const posixTest = test.skipIf(process.platform === "win32"); + +async function withGh( + answer: (command: readonly string[]) => Awaited>, + run: ( + check: ReturnType, + calls: string[][], + clock: { now: number }, + ) => Promise, +) { + const home = await mkdtemp(join(tmpdir(), "owner-check-")); + try { + await mkdir(join(home, "bin")); + await writeFile(join(home, "bin", "gh"), "#!/bin/sh\nexit 1\n", { + mode: 0o755, + }); + const calls: string[][] = []; + const clock = { now: 1_000 }; + const check = createOwnerCheck( + { + path: join(home, "bin"), + home, + platform: process.platform, + run: async (command) => { + calls.push([...command.slice(1)]); + return answer(command); + }, + }, + () => clock.now, + ); + await run(check, calls, clock); + } finally { + await rm(home, { recursive: true, force: true }); + } +} + +test("only an active admin membership is an Owner's", () => { + expect(isOwnerMembership('{"state":"active","role":"admin"}')).toBe(true); + expect(isOwnerMembership('{"state":"pending","role":"admin"}')).toBe(false); + expect(isOwnerMembership('{"state":"active","role":"member"}')).toBe(false); + expect(isOwnerMembership("not json")).toBe(false); +}); + +posixTest("GitHub's answer, kept a few minutes per login", async () => { + await withGh( + () => ({ + exitCode: 0, + stdout: '{"state":"active","role":"admin"}', + stderr: "", + }), + async (check, calls, clock) => { + expect( + await check.owner("Example-Org", "hosted-organization-personal"), + ).toBe(true); + expect(calls).toEqual([["api", "user/memberships/orgs/Example-Org"]]); + expect(await check.owner("example-org", "local")).toBe(true); + expect(calls).toHaveLength(1); + clock.now += ownerCheck.cacheMs + 1; + expect(await check.owner("example-org", "local")).toBe(true); + expect(calls).toHaveLength(2); + }, + ); +}); + +posixTest( + "fail closed: a member, a refusal, a timeout; never asked on a Team Environment or without a login", + async () => { + for (const answer of [ + { exitCode: 0, stdout: '{"state":"active","role":"member"}', stderr: "" }, + { exitCode: 1, stdout: "", stderr: "Not Found" }, + "timeout" as const, + ]) + await withGh( + () => answer, + async (check) => { + expect(await check.owner("example-org", "local")).toBe(false); + }, + ); + await withGh( + () => ({ + exitCode: 0, + stdout: '{"state":"active","role":"admin"}', + stderr: "", + }), + async (check, calls) => { + expect( + await check.owner("example-org", "hosted-organization-team"), + ).toBe(false); + expect(await check.owner(undefined, "local")).toBe(false); + expect(await check.owner("not/a/login", "local")).toBe(false); + expect(calls).toEqual([]); + }, + ); + }, +); diff --git a/tests/shell.test.ts b/tests/shell.test.ts index 238c73f05..175461690 100644 --- a/tests/shell.test.ts +++ b/tests/shell.test.ts @@ -9,10 +9,14 @@ import { import { parseShell, type Shell } from "../src/shell/contract"; import { shellMessages } from "../src/shell/messages"; import { - folderLimit, + environmentHref, + environmentName, + environmentWho, + hereOf, initialsOf, - jumpList, - railModel, + railSpaces, + spaceEnvironments, + switcherSections, switchTabs, } from "../src/shell/view"; import { folderFixture, writeOrganization } from "./fixtures/catalog-folder"; @@ -22,9 +26,10 @@ import { personalWithEntry, } from "./fixtures/machine-bindings"; -// Decision F36: the Lazurio shell's data contract `lazurio.shell.v1`, its -// producer for what this Environment knows today, and the rail and switch -// as the elements draw them. Fixtures use example names only. +// Decision F36 and its addendum of 2026-10-04: the Lazurio shell's data +// contract `lazurio.shell.v1`, its producer for what this Environment knows +// today, and the rail of Organizations, the Environment picker and the +// switch as the elements draw them. Fixtures use example names only. const organization = ( slug: string, @@ -47,8 +52,9 @@ const catalog = (...organizations: CatalogOrganization[]): Catalog => ({ }); const en = shellMessages("en"); const cs = shellMessages("cs"); +const noLast = () => null; -test("a workstation's document: this computer, every Organization of the Folder, Apps on its own origin, no Chat or Automate", () => { +test("a workstation's document: this computer, every Organization of the Folder with its Dashboard, Apps on its own origin", () => { const shell = shellDocument({ preset: "local", machine: null, @@ -64,13 +70,14 @@ test("a workstation's document: this computer, every Organization of the Folder, schema: "lazurio.shell.v1", locale: "cs", current: "local", - operator: { initials: null, login: null }, + operator: { initials: null, login: null, avatar: null }, environments: [ { id: "local", label: null, kind: "workstation", organizations: ["alpha", "beta"], + assignee: null, apps: { apps: "/", chat: null, automate: null }, }, ], @@ -78,29 +85,48 @@ test("a workstation's document: this computer, every Organization of the Folder, { slug: "alpha", name: "Alpha Example", - accent: null, // The avatar of the bound login, never of the slug. avatar: "https://github.com/alpha-forge.png?size=96", + dashboard: "https://dashboard.lazurio.ai/orgs/alpha", }, { slug: "beta", name: "Beta Example", - accent: null, // No bound login: no avatar, the rail shows initials. avatar: null, + dashboard: "https://dashboard.lazurio.ai/orgs/beta", }, ], dashboard: "https://dashboard.lazurio.ai/", account: "https://dashboard.lazurio.ai/settings", + addOrganization: "https://dashboard.lazurio.ai/add-organization", }); - // The rail: this computer is personal, so no folder; Organizations - // without an Environment in the document have none. - const rail = railModel(shell, cs); - expect(rail.personal.map((entry) => [entry.label, entry.active])).toEqual([ - ["Tento počítač", true], + const current = shell.environments[0]; + if (current === undefined) throw new Error("The document has one"); + expect(environmentName(current, cs)).toBe("Tento počítač"); + expect(environmentWho(current, cs)).toBe("tento počítač"); + // On its own the workstation is personal; opened for an Organization it + // stands in that Organization's space, Apps scoped to it. + expect(hereOf(shell, null)).toBe("personal"); + expect(hereOf(shell, "BETA")).toBe("beta"); + expect(environmentHref(current, "beta", "apps")).toBe("/o/beta"); + expect(environmentHref(current, "personal", "apps")).toBe("/"); + // The rail: your space, then each Organization; the space a click on + // Beta leads to is this computer opened for Beta. + const spaces = railSpaces(shell, cs, { + here: "beta", + app: "apps", + last: noLast, + }); + expect( + spaces.map((space) => [space.space, space.href, space.active, space.sub]), + ).toEqual([ + ["personal", "/", false, "1 Environment"], + ["alpha", "/o/alpha", false, "1 Environment"], + ["beta", "/o/beta", true, "1 Environment"], ]); - expect(rail.personal[0]?.mark).toEqual({ kind: "icon", icon: "laptop" }); - expect(rail.folders).toEqual([]); + expect(spaces[1]?.avatar).toBe("https://github.com/alpha-forge.png?size=96"); + expect(spaces[2]?.initials).toBe("BE"); // The switch: Apps on this origin, the two others disabled with a reason. expect( switchTabs(shell, cs, "apps").map((tab) => [ @@ -116,64 +142,135 @@ test("a workstation's document: this computer, every Organization of the Folder, ]); }); -test("a hosted work Environment: its Machine name, the assigned operator's initials, the entry's origins, one Organization folder with it active", () => { +test("a hosted work Environment is named by its kind and its person, never by its machine; its Organization's space is the active one", () => { const machine = organizationWithEntry(20000, "workspace.example.lazurio.io"); const shell = shellDocument({ preset: "hosted-organization-personal", machine, locale: "en", - catalog: catalog(organization("example")), + catalog: catalog(organization("example", { forgeLogin: "example" })), }); const [environment] = shell.environments; - expect(environment?.kind).toBe("work"); - expect(environment?.label).toBe(machine.name); - expect(shell.current).toBe(machine.name); - expect(environment?.apps).toEqual({ + if (environment === undefined) throw new Error("The document has one"); + expect(environment.kind).toBe("work"); + // The machine's name is the id the document keys it by, never a label. + expect(environment.id).toBe(machine.name); + expect(environment.label).toBeNull(); + expect(environmentName(environment, cs)).toBe("Pracovní"); + expect(environment.apps).toEqual({ apps: "https://launchpad.workspace.example.lazurio.io/", chat: "https://t3code.workspace.example.lazurio.io/", automate: null, }); - const rail = railModel(shell, en); - expect(rail.personal).toEqual([]); - expect(rail.folders).toHaveLength(1); - expect(rail.folders[0]?.hasActive).toBe(true); - expect(rail.folders[0]?.items[0]?.sub).toBe( - "Example Example · work · you are here", - ); - expect(rail.folders[0]?.initials).toBe("EE"); - expect(switchTabs(shell, en, "apps").map((tab) => tab.href)).toEqual([ - "https://t3code.workspace.example.lazurio.io/", - "https://launchpad.workspace.example.lazurio.io/", - null, + expect(hereOf(shell, null)).toBe("example"); + const spaces = railSpaces(shell, en, { + here: "example", + app: "chat", + last: noLast, + }); + // Your personal space has no Environment here: its Dashboard. + expect( + spaces.map((space) => [space.space, space.href, space.active]), + ).toEqual([ + ["personal", "https://dashboard.lazurio.ai/", false], + // A click stays in the app the rail sits in (Chat). + ["example", "https://t3code.workspace.example.lazurio.io/", true], ]); + // The picker's list: the Organization's head (its Dashboard), then its + // Environments, the current one marked. + const [section] = switcherSections(shell, cs, { + here: "example", + all: false, + app: "apps", + query: "", + }); + expect(section?.head?.href).toBe("https://dashboard.lazurio.ai/orgs/example"); + expect(section?.rows.map((row) => [row.name, row.who, row.current])).toEqual([ + ["Pracovní", "pracovní", true], + ]); +}); + +test("an assigned work Environment says whose it is; an Automated one is its persona's; a Team one its Team's", () => { + const work = shellDocument({ + preset: "hosted-organization-personal", + machine: bindings.assignedOperator as MachineBinding, + locale: "en", + catalog: catalog(organization("example")), + }); + expect(work.environments[0]?.assignee).toBe("example"); + const [assigned] = work.environments; + if (assigned === undefined) throw new Error("The document has one"); + expect(environmentWho(assigned, cs)).toBe("@example"); + // The Team the binding names, by its display name in the catalog of the + // Organization that owns the Environment. + const teams = catalog( + organization("example", { + forgeLogin: "example", + teams: [{ slug: "sample-team", displayName: "Sample" }], + }), + ); + const team = shellDocument({ + preset: "hosted-organization-team", + machine: bindings.assignedTeam as MachineBinding, + locale: "en", + catalog: teams, + }); + expect(team.operator).toEqual({ initials: null, login: null, avatar: null }); + expect(team.environments[0]?.label).toBe("Team Sample"); + expect(team.environments[0]?.assignee).toBeNull(); + const [shared] = team.environments; + if (shared === undefined) throw new Error("The document has one"); + expect(environmentWho(shared, cs)).toBe("sdílený Teamem"); + const automated = shellDocument({ + preset: "hosted-organization-steward", + machine: bindings.automated as MachineBinding, + locale: "en", + catalog: catalog( + organization("example", { + forgeLogin: "example", + teams: [{ slug: "sample-team", displayName: "Steward" }], + }), + ), + }); + expect(automated.environments[0]?.kind).toBe("automated"); + expect(automated.environments[0]?.label).toBe("Steward"); + expect(automated.operator.login).toBe("example"); + // A Team the catalog does not know: named by its kind. + const unknown = shellDocument({ + preset: "hosted-organization-team", + machine: bindings.assignedTeam as MachineBinding, + locale: "en", + catalog: catalog(organization("example")), + }); + expect(unknown.environments[0]?.label).toBeNull(); }); -test("a personal Remote Environment carries its owner's initials and belongs to no Organization", () => { - const machine = personalWithEntry(); +test("a personal Remote Environment carries its owner's initials and photo and belongs to no Organization", () => { const shell = shellDocument({ preset: "hosted-personal", - machine, + machine: personalWithEntry(), locale: "en", catalog: catalog(organization("example")), }); expect(shell.environments[0]?.organizations).toEqual([]); - expect(shell.operator.login).not.toBeNull(); - expect(shell.operator.initials).toBe( - initialsOf(shell.operator.login ?? "").slice(0, 2), - ); - const rail = railModel(shell, en); - expect(rail.personal[0]?.mark).toEqual({ - kind: "initials", - text: shell.operator.initials ?? "", + expect(shell.operator.login).toBe("example"); + expect(shell.operator.initials).toBe("EX"); + expect(shell.operator.avatar).toBe("https://github.com/example.png?size=96"); + expect(hereOf(shell, null)).toBe("personal"); + const [personal] = switcherSections(shell, en, { + here: "personal", + all: false, + app: "apps", + query: "", }); - expect(rail.personal[0]?.sub).toStartWith(`@${shell.operator.login}`); - expect(rail.folders).toEqual([]); + expect(personal?.rows[0]?.glyph).toEqual({ kind: "initials", text: "EX" }); + expect(personal?.rows[0]?.name).toBe("Personal"); }); -test("a Team Environment names no operator; a template or a duplicate slug is no Organization of the shell", () => { +test("a template or a duplicate slug is no Organization of the shell", () => { const shell = shellDocument({ - preset: "hosted-organization-team", - machine: bindings.assignedTeam as MachineBinding, + preset: "local", + machine: null, locale: "en", catalog: catalog( organization("example"), @@ -188,25 +285,7 @@ test("a Team Environment names no operator; a template or a duplicate slug is no organization("broken", { organization: null, displayName: null }), ), }); - expect(shell.operator).toEqual({ initials: null, login: null }); - expect(shell.environments[0]?.kind).toBe("team"); expect(shell.organizations.map((entry) => entry.slug)).toEqual(["example"]); - expect(railModel(shell, en).folders[0]?.items[0]?.mark).toEqual({ - kind: "icon", - icon: "users", - }); -}); - -test("the Automated Environment names its responsible operator", () => { - const shell = shellDocument({ - preset: "hosted-organization-steward", - machine: bindings.assignedOperator as MachineBinding, - locale: "en", - catalog: catalog(organization("example")), - }); - expect(shell.environments[0]?.kind).toBe("automated"); - expect(shell.operator.login).toBe("example"); - expect(shell.operator.initials).toBe("EX"); }); // A document as the Dashboard will fill it: more Environments, several @@ -216,31 +295,38 @@ const filled = (): Shell => { schema: "lazurio.shell.v1", locale: "en", current: "work-3", - operator: { initials: "OP", login: "operator" }, + operator: { + initials: "OP", + login: "operator", + avatar: "https://avatars.example.invalid/operator.png", + }, environments: [ { id: "laptop", label: null, kind: "workstation", organizations: ["north"], + assignee: null, apps: { apps: "/", chat: null, automate: null }, }, { id: "personal", - label: "operator", + label: null, kind: "personal", organizations: [], + assignee: null, apps: { apps: "https://launchpad.operator.example.lazurio.io/", chat: "https://t3code.operator.example.lazurio.io/", automate: null, }, }, - ...Array.from({ length: 8 }, (_, index) => ({ + ...Array.from({ length: 4 }, (_, index) => ({ id: `work-${index}`, - label: `vm-${index}`, + label: index === 0 ? "Team North" : null, kind: index === 0 ? "team" : "work", organizations: ["north"], + assignee: index === 0 ? null : `person-${index}`, apps: { apps: `https://launchpad.vm-${index}.north.example.lazurio.io/`, chat: null, @@ -249,9 +335,10 @@ const filled = (): Shell => { })), { id: "south-1", - label: "vm-1", + label: "Steward", kind: "automated", organizations: ["South"], + assignee: null, apps: { apps: "https://launchpad.vm-1.south.example.lazurio.io/", chat: null, @@ -260,16 +347,22 @@ const filled = (): Shell => { }, ], organizations: [ - { slug: "north", name: "North Example", accent: "#0b0eb4", avatar: null }, + { + slug: "north", + name: "North Example", + avatar: null, + dashboard: "https://dashboard.example.invalid/orgs/north", + }, { slug: "south", name: "South Example", - accent: null, avatar: "https://avatars.example.invalid/south.png", + dashboard: "https://dashboard.example.invalid/orgs/south", }, ], dashboard: "https://dashboard.example.invalid/", account: "https://dashboard.example.invalid/settings", + addOrganization: null, // A member a later producer adds is ignored. buddy: { origin: "https://buddy.example.invalid" }, }); @@ -277,36 +370,86 @@ const filled = (): Shell => { return value; }; -test("several Organizations: personal first, a folder each, six then +N, the active one always shown, less folds again", () => { +test("several Organizations: a space's Environments, its last one remembered, the picker's list widened to all, filtered", () => { const shell = filled(); - const rail = railModel(shell, en); - expect(rail.personal.map((entry) => entry.id)).toEqual([ + expect(hereOf(shell, null)).toBe("north"); + expect(spaceEnvironments(shell, "north").map((entry) => entry.id)).toEqual([ + "work-0", + "work-1", + "work-2", + "work-3", "laptop", - "personal", ]); - expect(rail.folders.map((folder) => folder.organization.slug)).toEqual([ - "north", - "south", + expect(spaceEnvironments(shell, "personal").map((entry) => entry.id)).toEqual( + ["laptop", "personal"], + ); + // A click on a space: the last Environment this browser was in there, + // else its first; in Automate an Environment without it opens Apps. + const spaces = railSpaces(shell, en, { + here: "north", + app: "automate", + last: (space) => (space === "north" ? "work-2" : null), + }); + expect(spaces.map((space) => [space.space, space.href, space.sub])).toEqual([ + ["personal", "/", "2 Environments"], + [ + "north", + "https://launchpad.vm-2.north.example.lazurio.io/", + "5 Environments · last Work", + ], + [ + "south", + "https://mausbot.vm-1.south.example.lazurio.io/", + "1 Environment", + ], ]); - const [north, south] = rail.folders; - // Six first, plus the active one further down; two folded behind +N. - expect(north?.items.map((entry) => entry.id)).toEqual([ - ...Array.from({ length: folderLimit }, (_, index) => `work-${index}`), + // The list under the picker: this space only. + const one = switcherSections(shell, en, { + here: "north", + all: false, + app: "apps", + query: "", + }); + expect(one.map((section) => section.space)).toEqual(["north"]); + expect( + one[0]?.rows.map((row) => [row.id, row.name, row.who, row.current]), + ).toEqual([ + ["work-0", "Team North", "shared by the Team", false], + ["work-1", "Work", "@person-1", false], + ["work-2", "Work", "@person-2", false], + ["work-3", "Work", "@person-3", true], + ["laptop", "This computer", "this computer", false], ]); - expect(north?.hidden).toBe(2); - expect(north?.items.find((entry) => entry.active)?.id).toBe("work-3"); - expect(north?.items[0]?.accent).toBe("#0b0eb4"); - expect(south?.items[0]?.mark).toEqual({ kind: "icon", icon: "bot" }); - const open = railModel(shell, en, new Set(["north"])); - expect(open.folders[0]?.items).toHaveLength(8); - expect(open.folders[0]?.hidden).toBe(0); - expect(open.folders[0]?.expanded).toBe(true); - // The jump list: every Environment, the current one first, filtered. - expect(jumpList(shell, en, "")[0]?.id).toBe("work-3"); - expect(jumpList(shell, en, "")).toHaveLength(11); - expect(jumpList(shell, en, "south").map((entry) => entry.id)).toEqual([ - "south-1", + // "All Organizations" (and ⌘⇧E): every space, each Organization with its + // head; a query keeps what matches. + const all = switcherSections(shell, en, { + here: "north", + all: true, + app: "apps", + query: "", + }); + expect(all.map((section) => [section.space, section.head !== null])).toEqual([ + ["personal", false], + ["north", true], + ["south", true], ]); + const found = switcherSections(shell, en, { + here: "north", + all: true, + app: "apps", + query: "steward", + }); + expect( + found.map((section) => [section.space, section.rows.map((row) => row.id)]), + ).toEqual([["south", ["south-1"]]]); + expect( + switcherSections(shell, en, { + here: "north", + all: true, + app: "apps", + query: "nothing like that", + }), + ).toEqual([]); }); test("the parser refuses what the elements could not draw safely", () => { @@ -316,6 +459,8 @@ test("the parser refuses what the elements could not draw safely", () => { change(copy); return parseShell(copy); }; + const first = (value: Record, key: string) => + (value[key] as Record[])[0] as Record; expect(parseShell(valid)).not.toBeNull(); expect(variant((value) => (value.schema = "lazurio.shell.v2"))).toBeNull(); expect(variant((value) => (value.current = "missing"))).toBeNull(); @@ -327,40 +472,41 @@ test("the parser refuses what the elements could not draw safely", () => { expect( variant((value) => (value.account = "http://dashboard.example.invalid/")), ).toBeNull(); + expect( + variant((value) => (value.addOrganization = "/add-organization")), + ).toBeNull(); expect( variant((value) => { - const [first] = value.environments as Record[]; - if (first) - first.apps = { - apps: "//other.example.invalid/", - chat: null, - automate: null, - }; + first(value, "environments").apps = { + apps: "//other.example.invalid/", + chat: null, + automate: null, + }; }), ).toBeNull(); expect( variant((value) => { - const [first] = value.environments as Record[]; - if (first) - first.apps = { - apps: "/", - chat: "https://user:secret@t3.example.invalid/", - automate: null, - }; + first(value, "environments").apps = { + apps: "/", + chat: "https://user:secret@t3.example.invalid/", + automate: null, + }; + }), + ).toBeNull(); + expect( + variant((value) => { + first(value, "organizations").dashboard = "javascript:alert(1)"; }), ).toBeNull(); - // The accent is a colour, never CSS. expect( variant((value) => { - const [first] = value.organizations as Record[]; - if (first) first.accent = "red; background: url(x)"; + first(value, "environments").assignee = "not a login"; }), ).toBeNull(); // Every Organization an Environment names is listed, each id once. expect( variant((value) => { - const [first] = value.environments as Record[]; - if (first) first.organizations = ["east"]; + first(value, "environments").organizations = ["east"]; }), ).toBeNull(); expect( @@ -374,10 +520,15 @@ test("the parser refuses what the elements could not draw safely", () => { (value) => ((value.operator as Record).initials = ""), ), ).toBeNull(); + expect( + variant( + (value) => + ((value.operator as Record).avatar = "data:image/png"), + ), + ).toBeNull(); expect( variant((value) => { - const [first] = value.environments as Record[]; - if (first) first.kind = "server"; + first(value, "environments").kind = "server"; }), ).toBeNull(); }); @@ -413,15 +564,6 @@ test.skipIf(process.platform === "win32")( expect( shell.organizations.find((entry) => entry.slug === "north")?.avatar, ).toBe("https://github.com/north-forge-login.png?size=96"); - // No avatar of any slug: every avatar is a bound login's. - for (const entry of shell.organizations) - expect(entry.avatar).toBe( - `https://github.com/${ - read.organizations.find( - (candidate) => candidate.organization === entry.slug, - )?.forgeLogin - }.png?size=96`, - ); }); }, 30_000, From 54e43e8385b290366cd7378a59cf2113cb6f1deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Sun, 4 Oct 2026 00:46:51 +0200 Subject: [PATCH 05/12] Tests follow the column head's settings attribute and the Marketplace route Co-Authored-By: Claude Opus 5.5 (1M context) --- src/launchpad/index.html | 20 ++++++++++---------- tests/launchpad-chat.test.ts | 7 ++++--- tests/launchpad-mausbot.test.ts | 2 +- tests/launchpad-routes.test.ts | 4 ++++ tests/launchpad.test.ts | 2 +- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/launchpad/index.html b/src/launchpad/index.html index a9935de5b..a1e23ad3d 100644 --- a/src/launchpad/index.html +++ b/src/launchpad/index.html @@ -3,16 +3,16 @@ Lazurio Launchpad - +