- 216px 文字侧栏改为 60px 图标轨:金色渐变 Logo、当前页金色指示条滑动、350ms 延迟悬停提示,底部连接/模型/设置/语言 - 顶栏:标题+副标题、项目范围胶囊(全部项目列表/最近项目)、Ctrl/⌘K 搜索、减少动态开关、任务托盘胶囊、本次连接胶囊(名称+延迟) - ≤760px:隐藏图标轨,底部 项目/创作/生成/更多 四个标签,更多为底部抽屉(其余页面、搜索、减少动态、语言);删除「手机端暂不适配」拦截 - 新增 ShellPop(Esc/↑↓/Tab 循环/外部点击关闭、焦点归还)与 CommandPalette(复用 Modal) - 减少动态:跟随系统设置,另可手动开启并持久化(data-reduce) - .a-darkroom 背景接入 --page-glow;新增壳层尺寸 token 与 .a-kbd/.a-menu-* 公共类 - 生图/生视频顶栏去掉与全局胶囊重复的连接状态(参数栏仍显示所选连接与队列) - 路由 URL 不变(/projects 仍重定向到项目总览 /) Co-authored-by: multica-agent <github@multica.ai> Co-authored-by: Cursor <cursoragent@cursor.com>
219 lines
5.4 KiB
Svelte
219 lines
5.4 KiB
Svelte
<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';
|
|
|
|
/** Ctrl/⌘K 搜索:跳到任一页面或项目(↑↓ 选择,Enter 打开,Esc 关闭). */
|
|
let { open = $bindable(false) }: { open?: boolean } = $props();
|
|
|
|
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 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;
|
|
});
|
|
|
|
$effect(() => {
|
|
void query;
|
|
activeIndex = 0;
|
|
});
|
|
|
|
$effect(() => {
|
|
if (!open) query = '';
|
|
});
|
|
|
|
function optionId(index: number) {
|
|
return `${listId}-${index}`;
|
|
}
|
|
|
|
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 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());
|
|
}
|
|
</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>
|
|
|
|
<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;
|
|
}
|
|
}
|
|
</style>
|