feat(HEL-728): establish approved themes and compatible studio navigation

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-21 20:13:03 +08:00
co-authored by multica-agent
parent 35fd07af24
commit 8e84e4c21f
38 changed files with 7567 additions and 2415 deletions
File diff suppressed because it is too large Load Diff
@@ -1,218 +1,232 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { createQuery } from '@tanstack/svelte-query';
import { toStore } from 'svelte/store';
import { projects } from '$lib/api';
import { t } from '$lib/i18n.svelte';
import Icon from '$lib/components/ui/Icon.svelte';
import Modal from '$lib/components/ui/Modal.svelte';
import type { IconName } from '$lib/components/ui/icons';
import { NAV } from './nav';
import { goto } from "$app/navigation";
import { createQuery } from "@tanstack/svelte-query";
import { toStore } from "svelte/store";
import { projects } from "$lib/api";
import { t } from "$lib/i18n.svelte";
import Icon from "$lib/components/ui/Icon.svelte";
import Modal from "$lib/components/ui/Modal.svelte";
import type { IconName } from "$lib/components/ui/icons";
import { NAV } from "./nav";
/** Ctrl/⌘K 搜索:跳到任一页面或项目(↑↓ 选择,Enter 打开,Esc 关闭). */
let { open = $bindable(false) }: { open?: boolean } = $props();
/** Ctrl/⌘K 搜索:跳到任一页面或项目(↑↓ 选择,Enter 打开,Esc 关闭). */
let { open = $bindable(false) }: { open?: boolean } = $props();
interface Entry {
key: string;
group: 'pages' | 'projects';
label: string;
icon: IconName;
href: string;
}
interface Entry {
key: string;
group: "pages" | "projects";
label: string;
icon: IconName;
href: string;
}
const listId = `palette-${Math.random().toString(36).slice(2, 9)}`;
let query = $state('');
let activeIndex = $state(0);
let list = $state<HTMLDivElement | null>(null);
const listId = `palette-${Math.random().toString(36).slice(2, 9)}`;
let query = $state("");
let activeIndex = $state(0);
let list = $state<HTMLDivElement | null>(null);
const projectsQuery = createQuery(
toStore(() => ({
queryKey: ['projects'],
queryFn: projects.list,
enabled: open,
staleTime: 30_000,
})),
);
const projectsQuery = createQuery(
toStore(() => ({
queryKey: ["projects"],
queryFn: projects.list,
enabled: open,
staleTime: 30_000,
})),
);
const entries = $derived.by<Entry[]>(() => {
const pages: Entry[] = NAV.map((item) => ({
key: `page-${item.id}`,
group: 'pages',
label: t(item.labelKey),
icon: item.icon,
href: item.href,
}));
const projectEntries: Entry[] = ($projectsQuery.data ?? []).map((p) => ({
key: `project-${p.id}`,
group: 'projects',
label: p.title,
icon: 'story',
href: `/workbench/${p.id}`,
}));
const q = query.trim().toLowerCase();
const all = [...pages, ...projectEntries];
return q ? all.filter((e) => e.label.toLowerCase().includes(q)) : all;
});
const entries = $derived.by<Entry[]>(() => {
const pages: Entry[] = NAV.map((item) => ({
key: `page-${item.href}`,
group: "pages",
label: item.label,
icon: item.icon,
href: item.href,
}));
const projectEntries: Entry[] = ($projectsQuery.data ?? []).map((p) => ({
key: `project-${p.id}`,
group: "projects",
label: p.title,
icon: "story",
href: `/workbench/${p.id}`,
}));
const q = query.trim().toLowerCase();
const all = [...pages, ...projectEntries];
return q ? all.filter((e) => e.label.toLowerCase().includes(q)) : all;
});
$effect(() => {
void query;
activeIndex = 0;
});
$effect(() => {
void query;
activeIndex = 0;
});
$effect(() => {
if (!open) query = '';
});
$effect(() => {
if (!open) query = "";
});
function optionId(index: number) {
return `${listId}-${index}`;
}
function optionId(index: number) {
return `${listId}-${index}`;
}
function go(entry: Entry) {
open = false;
void goto(entry.href);
}
function go(entry: Entry) {
open = false;
void goto(entry.href);
}
function move(step: number) {
if (entries.length === 0) return;
activeIndex = (activeIndex + step + entries.length) % entries.length;
list?.querySelector(`#${optionId(activeIndex)}`)?.scrollIntoView({ block: 'nearest' });
}
function move(step: number) {
if (entries.length === 0) return;
activeIndex = (activeIndex + step + entries.length) % entries.length;
list
?.querySelector(`#${optionId(activeIndex)}`)
?.scrollIntoView({ block: "nearest" });
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'ArrowDown') {
event.preventDefault();
move(1);
} else if (event.key === 'ArrowUp') {
event.preventDefault();
move(-1);
} else if (event.key === 'Enter') {
const entry = entries[activeIndex];
if (entry) {
event.preventDefault();
go(entry);
}
}
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === "ArrowDown") {
event.preventDefault();
move(1);
} else if (event.key === "ArrowUp") {
event.preventDefault();
move(-1);
} else if (event.key === "Enter") {
const entry = entries[activeIndex];
if (entry) {
event.preventDefault();
go(entry);
}
}
}
function focusOnMount(node: HTMLInputElement) {
requestAnimationFrame(() => node.focus());
}
function focusOnMount(node: HTMLInputElement) {
requestAnimationFrame(() => node.focus());
}
</script>
<Modal bind:open title={t('shell.searchTitle')}>
<div class="palette">
<div class="palette-search">
<Icon name="search" size={16} />
<input
use:focusOnMount
class="palette-input"
type="text"
bind:value={query}
placeholder={t('shell.searchPlaceholder')}
role="combobox"
aria-expanded="true"
aria-controls={listId}
aria-autocomplete="list"
aria-activedescendant={entries.length ? optionId(activeIndex) : undefined}
aria-label={t('shell.searchTitle')}
onkeydown={handleKeydown}
/>
</div>
<div class="palette-list" id={listId} role="listbox" bind:this={list} aria-label={t('shell.searchTitle')}>
{#if entries.length === 0}
<p class="palette-empty">{t('shell.searchEmpty', { q: query.trim() })}</p>
{/if}
{#each entries as entry, i (entry.key)}
{#if i === 0 || entries[i - 1].group !== entry.group}
<div class="a-menu-group" role="presentation">
{entry.group === 'pages' ? t('shell.searchGroupPages') : t('shell.searchGroupProjects')}
</div>
{/if}
<div
id={optionId(i)}
class="a-menu-item"
class:active={i === activeIndex}
role="option"
tabindex="-1"
aria-selected={i === activeIndex}
onpointermove={() => (activeIndex = i)}
onmousedown={(e) => e.preventDefault()}
onclick={() => go(entry)}
onkeydown={handleKeydown}
>
<Icon name={entry.icon} size={15} />
<span class="a-menu-label">{entry.label}</span>
<span class="a-menu-meta mono">{entry.href}</span>
</div>
{/each}
</div>
<p class="palette-hint">
<span class="a-kbd">↑↓</span>{t('shell.searchHintMove')}
<span class="a-kbd">Enter</span>{t('shell.searchHintOpen')}
<span class="a-kbd">Esc</span>{t('shell.searchHintClose')}
</p>
</div>
<Modal bind:open title={t("shell.searchTitle")}>
<div class="palette">
<div class="palette-search">
<Icon name="search" size={16} />
<input
use:focusOnMount
class="palette-input"
type="text"
bind:value={query}
placeholder={t("shell.searchPlaceholder")}
role="combobox"
aria-expanded="true"
aria-controls={listId}
aria-autocomplete="list"
aria-activedescendant={entries.length
? optionId(activeIndex)
: undefined}
aria-label={t("shell.searchTitle")}
onkeydown={handleKeydown}
/>
</div>
<div
class="palette-list"
id={listId}
role="listbox"
bind:this={list}
aria-label={t("shell.searchTitle")}
>
{#if entries.length === 0}
<p class="palette-empty">
{t("shell.searchEmpty", { q: query.trim() })}
</p>
{/if}
{#each entries as entry, i (entry.key)}
{#if i === 0 || entries[i - 1].group !== entry.group}
<div class="a-menu-group" role="presentation">
{entry.group === "pages"
? t("shell.searchGroupPages")
: t("shell.searchGroupProjects")}
</div>
{/if}
<div
id={optionId(i)}
class="a-menu-item"
class:active={i === activeIndex}
role="option"
tabindex="-1"
aria-selected={i === activeIndex}
onpointermove={() => (activeIndex = i)}
onmousedown={(e) => e.preventDefault()}
onclick={() => go(entry)}
onkeydown={handleKeydown}
>
<Icon name={entry.icon} size={15} />
<span class="a-menu-label">{entry.label}</span>
<span class="a-menu-meta mono">{entry.href}</span>
</div>
{/each}
</div>
<p class="palette-hint">
<span class="a-kbd">↑↓</span>{t("shell.searchHintMove")}
<span class="a-kbd">Enter</span>{t("shell.searchHintOpen")}
<span class="a-kbd">Esc</span>{t("shell.searchHintClose")}
</p>
</div>
</Modal>
<style>
.palette {
display: flex;
flex-direction: column;
gap: var(--sp-3);
}
.palette-search {
display: flex;
align-items: center;
gap: var(--sp-3);
padding: 0 var(--sp-5);
border: 1px solid var(--line);
border-radius: var(--r-md);
background: var(--bg-3);
color: var(--text-3);
transition: border-color var(--d-state) ease;
}
.palette-search:focus-within {
border-color: var(--accent-line);
}
.palette-input {
flex: 1;
min-width: 0;
height: 40px;
border: 0;
outline: 0;
background: transparent;
color: var(--text);
font-family: inherit;
font-size: var(--fs-section);
}
.palette-input::placeholder {
color: var(--text-3);
}
.palette-list {
max-height: min(360px, 50vh);
overflow-y: auto;
}
.palette-empty {
margin: 0;
padding: var(--sp-6) var(--sp-4);
font-size: var(--fs-aux);
color: var(--text-3);
text-align: center;
}
.palette-hint {
display: flex;
align-items: center;
gap: var(--sp-2);
margin: 0;
font-size: var(--fs-mini);
color: var(--text-3);
}
.palette-hint .a-kbd:not(:first-child) {
margin-left: var(--sp-3);
}
@media (hover: none) {
.palette-hint {
display: none;
}
}
.palette {
display: flex;
flex-direction: column;
gap: var(--sp-3);
}
.palette-search {
display: flex;
align-items: center;
gap: var(--sp-3);
padding: 0 var(--sp-5);
border: 1px solid var(--line);
border-radius: var(--r-md);
background: var(--bg-3);
color: var(--text-3);
transition: border-color var(--d-state) ease;
}
.palette-search:focus-within {
border-color: var(--accent-line);
}
.palette-input {
flex: 1;
min-width: 0;
height: 40px;
border: 0;
outline: 0;
background: transparent;
color: var(--text);
font-family: inherit;
font-size: var(--fs-section);
}
.palette-input::placeholder {
color: var(--text-3);
}
.palette-list {
max-height: min(360px, 50vh);
overflow-y: auto;
}
.palette-empty {
margin: 0;
padding: var(--sp-6) var(--sp-4);
font-size: var(--fs-aux);
color: var(--text-3);
text-align: center;
}
.palette-hint {
display: flex;
align-items: center;
gap: var(--sp-2);
margin: 0;
font-size: var(--fs-mini);
color: var(--text-3);
}
.palette-hint .a-kbd:not(:first-child) {
margin-left: var(--sp-3);
}
@media (hover: none) {
.palette-hint {
display: none;
}
}
</style>
@@ -0,0 +1,189 @@
<script lang="ts">
import { THEMES, theme, setTheme, themeStorageUnavailable } from "$lib/theme";
let { compact = false }: { compact?: boolean } = $props();
function move(event: KeyboardEvent) {
const steps: Record<string, number> = {
ArrowRight: 1,
ArrowDown: 1,
ArrowLeft: -1,
ArrowUp: -1,
};
const step = steps[event.key];
if (!step && event.key !== "Home" && event.key !== "End") return;
event.preventDefault();
const group = (event.currentTarget as HTMLElement).closest(
".choices",
) as HTMLElement;
const buttons = [...group.querySelectorAll<HTMLButtonElement>("button")];
const current = buttons.indexOf(
document.activeElement as HTMLButtonElement,
);
const next =
event.key === "Home"
? 0
: event.key === "End"
? buttons.length - 1
: (current + step + buttons.length) % buttons.length;
buttons[next]?.focus();
}
</script>
<div class="choices" class:compact role="group" aria-label="外观主题">
{#each THEMES as item}
<button
class="choice"
class:selected={$theme === item.id}
aria-pressed={$theme === item.id}
onkeydown={move}
onclick={() => setTheme(item.id)}
>
<span class="preview" data-theme={item.id} aria-hidden="true"
><span class="rail"></span><span class="list"
><i></i><i></i><i></i></span
><span class="stage"><i></i><b></b></span></span
>
<span class="copy"
><strong>{item.name}</strong><small>{item.english}</small><span
>{item.description}</span
></span
>
<span class="check" aria-hidden="true"
>{$theme === item.id ? "✓" : ""}</span
>
</button>
{/each}
</div>
{#if $themeStorageUnavailable}<p class="notice" role="status">
浏览器禁止本地存储:本次有效,其他操作不受影响
</p>{/if}
<style>
.choices {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px;
}
.choices.compact {
grid-template-columns: 1fr;
}
.choice {
display: grid;
grid-template-columns: minmax(0, 1fr) 18px;
gap: 8px;
padding: 8px;
border: 1px solid var(--line-2);
border-radius: var(--r-md);
background: var(--bg-2);
color: var(--tx-1);
text-align: left;
cursor: pointer;
}
.choice:hover {
border-color: var(--line-3);
background: var(--bg-3);
}
.choice.selected {
border-color: var(--gold);
}
.choice:focus-visible {
outline: 2px solid var(--info);
outline-offset: 2px;
}
.compact .choice {
grid-template-columns: 76px minmax(0, 1fr) 18px;
align-items: center;
}
.preview {
grid-column: 1 / -1;
height: 64px;
border-radius: var(--r-sm);
overflow: hidden;
display: grid;
grid-template-columns: 12px 22px 1fr;
background: var(--bg-0);
border: 1px solid var(--line-2);
}
.compact .preview {
grid-column: auto;
height: 48px;
}
.rail,
.list {
background: var(--bg-1);
border-right: 1px solid var(--line);
}
.rail::before {
content: "";
display: block;
width: 4px;
height: 4px;
margin: 6px auto;
border-radius: 50%;
background: var(--gold);
}
.list {
display: flex;
flex-direction: column;
gap: 3px;
padding: 6px 3px;
}
.list i {
height: 4px;
border-radius: 2px;
background: var(--line-3);
}
.list i:first-child {
background: var(--sc-image);
}
.stage {
padding: 5px 6px;
display: flex;
flex-direction: column;
gap: 4px;
}
.stage i {
flex: 1;
border-radius: 3px;
background: var(--bg-3);
border: 1px solid var(--line-2);
}
.stage b {
height: 9px;
width: 18px;
align-self: end;
border-radius: 2px;
background: var(--grad-gold);
}
.copy {
display: flex;
flex-wrap: wrap;
gap: 2px 6px;
min-width: 0;
}
.copy strong {
font-size: 13px;
}
.copy small {
font: 10px var(--mono);
color: var(--tx-3);
align-self: center;
}
.copy > span {
width: 100%;
font-size: 11px;
color: var(--tx-2);
}
.check {
color: var(--gold);
}
.notice {
font-size: 12px;
color: var(--tx-2);
margin: 12px 0 0;
}
@media (max-width: 1366px) {
.choices:not(.compact) {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
</style>
+122 -115
View File
@@ -1,123 +1,130 @@
import type { IconName } from '$lib/components/ui/icons';
import type { IconName } from "$lib/components/ui/icons";
// IDs are retained for the existing page contracts while B1–B4 replace layouts.
export type NavId =
| 'projects'
| 'workbench'
| 'image'
| 'video'
| 'tasks'
| 'agents'
| 'connections'
| 'models'
| 'library'
| 'settings'
| 'canvas'
| 'workflows';
| "projects"
| "workbench"
| "image"
| "video"
| "tasks"
| "agents"
| "connections"
| "models"
| "library"
| "settings"
| "canvas"
| "workflows";
export interface NavItem {
id: NavId;
labelKey: string;
icon: IconName;
href: string;
id: NavId;
label: string;
icon: IconName;
href: string;
scene: "project" | "image" | "agent" | "manage" | "asset";
matches: (path: string) => boolean;
}
// Order is fixed by spec-v2 §3: 项目 / 创作工作台 / 生图 / 生视频 / 生成任务 /
// 智能体 / ComfyUI 连接 / 模型设置 / 设置. HEL-649 §二 puts the connection
// and settings entries at the foot of the 60px rail.
export const NAV_MAIN: NavItem[] = [
{ id: 'projects', labelKey: 'shell.navProjects', icon: 'home', href: '/' },
{
id: 'workbench',
labelKey: 'shell.navWorkbench',
icon: 'story',
href: '/workbench',
},
{ id: 'image', labelKey: 'shell.navImage', icon: 'image', href: '/image' },
{ id: 'video', labelKey: 'shell.navVideo', icon: 'film', href: '/video' },
{ id: 'tasks', labelKey: 'shell.navTasks', icon: 'queue', href: '/tasks' },
{ id: 'canvas', labelKey: 'nav.canvas', icon: 'story', href: '/canvas' },
{
id: 'agents',
labelKey: 'shell.navAgents',
icon: 'sparkle',
href: '/agents',
},
{
id: "projects",
label: "工作室",
icon: "home",
href: "/",
scene: "project",
matches: (p) => p === "/",
},
{
id: "workbench",
label: "项目",
icon: "folder",
href: "/workbench",
scene: "project",
matches: (p) => /^\/(workbench|project)(\/|$)/.test(p),
},
{
id: "image",
label: "创作台",
icon: "image",
href: "/create",
scene: "image",
matches: (p) =>
["/create", "/image", "/video", "/playground", "/build-scene"].includes(
p,
),
},
{
id: "agents",
label: "智能体",
icon: "sparkle",
href: "/agents",
scene: "agent",
matches: (p) => p === "/agents",
},
{
id: "canvas",
label: "画布",
icon: "story",
href: "/canvas",
scene: "manage",
matches: (p) => p.startsWith("/canvas"),
},
{
id: "library",
label: "素材库",
icon: "assets",
href: "/library",
scene: "asset",
matches: (p) => p === "/library",
},
];
export const NAV_MANAGE: NavItem[] = [
{
id: "tasks",
label: "任务",
icon: "clock",
href: "/tasks",
scene: "manage",
matches: (p) => p === "/tasks",
},
{
id: "workflows",
label: "工作流",
icon: "playground",
href: "/workflows",
scene: "manage",
matches: (p) => p === "/workflows",
},
{
id: "connections",
label: "模型连接",
icon: "link",
href: "/model-connections",
scene: "manage",
matches: (p) =>
["/connections", "/models", "/model-connections"].includes(p),
},
];
export const NAV_FOOT: NavItem[] = [
{
id: 'connections',
labelKey: 'shell.navConnections',
icon: 'link',
href: '/connections',
},
{
id: 'models',
labelKey: 'shell.navModels',
icon: 'assets',
href: '/models',
},
{
id: 'workflows',
labelKey: 'connections.wfTitle',
icon: 'playground',
href: '/workflows',
},
{
id: 'library',
labelKey: 'shell.navLibrary',
icon: 'folder',
href: '/library',
},
{
id: 'settings',
labelKey: 'shell.navSettings',
icon: 'settings',
href: '/settings',
},
{
id: "settings",
label: "设置",
icon: "settings",
href: "/settings",
scene: "manage",
matches: (p) => p === "/settings",
},
];
export const NAV: NavItem[] = [...NAV_MAIN, ...NAV_FOOT];
export interface TabItem {
id: 'projects' | 'workbench' | 'generate';
labelKey: string;
icon: IconName;
href: string;
/** Pages that light this tab up. */
covers: NavId[];
}
/** ≤760px bottom tab bar (§二): 项目 / 创作 / 生成 / 更多. */
export const TABS: TabItem[] = [
{
id: 'projects',
labelKey: 'shell.tabProjects',
icon: 'home',
href: '/',
covers: ['projects'],
},
{
id: 'workbench',
labelKey: 'shell.tabCreate',
icon: 'story',
href: '/workbench',
covers: ['workbench'],
},
{
id: 'generate',
labelKey: 'shell.tabGenerate',
icon: 'image',
href: '/image',
covers: ['image', 'video'],
},
];
/**
* Every page a tab does not link to directly lives in the 更多 sheet. 生视频
* is still its own route, so it is listed there too until the two
* generation pages merge.
*/
export const MORE_ITEMS: NavItem[] = NAV.filter(
(item) => !TABS.some((tab) => tab.href === item.href),
);
// Tools awaiting their replacement keep reachable entries in global search.
export const NAV = [
...NAV_MAIN,
...NAV_MANAGE,
...NAV_FOOT,
{ id: "video", label: "视频创作", icon: "film", href: "/video" },
{ id: "models", label: "大语言模型", icon: "assets", href: "/models" },
{
id: "connections",
label: "ComfyUI 连接",
icon: "link",
href: "/connections",
},
{ id: "image", label: "试验台", icon: "playground", href: "/playground" },
{ id: "video", label: "三维搭景", icon: "story", href: "/build-scene" },
] as const;