@vetta-org/theme-ui 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -16
- package/src/action-approval/StorageCleanListView.test.tsx +36 -0
- package/src/action-approval/StorageCleanListView.tsx +52 -0
- package/src/action-approval/index.ts +2 -0
- package/src/activity/ActivityPanel.tsx +7 -1
- package/src/activity/ActivityPanelFrame.tsx +1 -1
- package/src/activity/BackgroundTasksTabPanelView.tsx +18 -2
- package/src/activity/BrowserPanelView.tsx +15 -1
- package/src/activity/BrowserSelectionView.tsx +199 -0
- package/src/activity/CodePreview.tsx +15 -1
- package/src/activity/MarkdownPreviewView.test.tsx +53 -0
- package/src/activity/MarkdownPreviewView.tsx +86 -10
- package/src/activity/index.ts +1 -0
- package/src/chat/ContextRingView.test.tsx +81 -0
- package/src/chat/ContextRingView.tsx +78 -62
- package/src/chat/EditDiffView.tsx +4 -4
- package/src/chat/HeaderActionBarView.tsx +135 -48
- package/src/chat/HeaderActionOverflowMenu.tsx +11 -20
- package/src/chat/MessageFeedLayoutView.tsx +6 -5
- package/src/chat/MessageInputView.tsx +5 -1
- package/src/chat/index.ts +2 -1
- package/src/chat/message-feed-fade.css +80 -0
- package/src/chat/message-feed-fade.test.tsx +75 -0
- package/src/chat/streaming-reveal.test.ts +1 -74
- package/src/chat/streaming-reveal.ts +0 -3
- package/src/file-preview/FilePreviewDialogView.tsx +2 -1
- package/src/file-preview/ReadonlyCodeView.tsx +46 -0
- package/src/file-preview/syntax-tokens.css +1 -1
- package/src/image-assets.d.ts +4 -0
- package/src/layout/ResizeHandle.tsx +4 -1
- package/src/layout/resize-handle-reset.test.tsx +50 -0
- package/src/markdown/FileLinkBadge.tsx +77 -0
- package/src/markdown/MarkdownContent.tsx +61 -31
- package/src/markdown/MarkdownImage.tsx +6 -16
- package/src/markdown/MermaidBlock.tsx +50 -11
- package/src/markdown/UrlLinkBadge.tsx +84 -0
- package/src/markdown/image-actions.ts +29 -0
- package/src/markdown/index.ts +2 -0
- package/src/markdown/nodes.ts +6 -1
- package/src/markdown/preview-policy.test.ts +31 -0
- package/src/markdown/preview-policy.ts +33 -0
- package/src/markdown/progressive-chunks.test.ts +43 -0
- package/src/markdown/progressive-chunks.ts +58 -0
- package/src/markdown/rich-labels.ts +9 -0
- package/src/markdown/streaming-fade.test.ts +83 -0
- package/src/markdown/streaming-fade.tsx +141 -0
- package/src/markdown/streaming-reveal.ts +0 -67
- package/src/markdown/streaming.ts +64 -131
- package/src/overlays/CommandMenuRow.tsx +47 -26
- package/src/overlays/CommandMenuView.tsx +107 -15
- package/src/overlays/DiagnosticsExportDialogView.tsx +236 -0
- package/src/overlays/MagpieHandoverDialogView.tsx +217 -0
- package/src/overlays/ReleaseNoteImage.test.tsx +105 -0
- package/src/overlays/ReleaseNoteMarkdown.test.tsx +49 -0
- package/src/overlays/ReleaseNoteMarkdown.tsx +120 -7
- package/src/overlays/SplashPanel.tsx +4 -4
- package/src/overlays/SplashParts.tsx +6 -2
- package/src/overlays/UpdateCheckerView.tsx +17 -15
- package/src/overlays/UpdateRestartDialogView.tsx +76 -2
- package/src/overlays/assets/diagnostics-banner.webp +0 -0
- package/src/overlays/command-menu-types.ts +15 -1
- package/src/overlays/index.ts +13 -0
- package/src/plugin-ui/index.ts +4 -0
- package/src/project/DefaultConversationSectionView.tsx +17 -22
- package/src/project/DefaultSessionRowView.tsx +8 -0
- package/src/project/ManageSessionsSplashView.tsx +0 -2
- package/src/settings/ArchivedProjectsSettingsView.tsx +122 -1
- package/src/settings/GeneralSettingsView.tsx +21 -5
- package/src/settings/LauncherSettingsView.test.tsx +95 -0
- package/src/settings/LauncherSettingsView.tsx +272 -0
- package/src/settings/PetActionGalleryView.test.tsx +163 -0
- package/src/settings/PetActionGalleryView.tsx +216 -0
- package/src/settings/PetSettingsView.test.tsx +117 -0
- package/src/settings/PetSettingsView.tsx +86 -22
- package/src/settings/PresetProviderRowView.tsx +37 -98
- package/src/settings/ShortcutsSettingsView.tsx +0 -4
- package/src/settings/SpaceEditorDialogView.tsx +94 -56
- package/src/settings/SpacesSettingsView.tsx +53 -8
- package/src/settings/StorageBar.tsx +70 -0
- package/src/settings/StorageExplorer.tsx +488 -0
- package/src/settings/StorageReadout.tsx +64 -0
- package/src/settings/StorageSettingsView.test.tsx +181 -0
- package/src/settings/StorageSettingsView.tsx +458 -0
- package/src/settings/assets/space-editor-illustration.webp +0 -0
- package/src/settings/index.ts +28 -39
- package/src/settings/storage-treemap-layout.test.ts +32 -0
- package/src/settings/storage-treemap-layout.ts +55 -0
- package/src/shared/SegmentedControl.test.tsx +68 -0
- package/src/shared/SegmentedControl.tsx +18 -11
- package/src/shared/StageDialogContent.test.tsx +61 -0
- package/src/shared/StageDialogContent.tsx +80 -0
- package/src/shared/TabBar.tsx +2 -2
- package/src/shared/VettaKbd.tsx +20 -1
- package/src/shared/index.ts +4 -1
- package/src/shared/platform.ts +9 -0
- package/src/sidebar/AddProjectMenuTriggerView.tsx +13 -12
- package/src/sidebar/SettingsMenuTriggerView.tsx +2 -1
- package/src/sidebar/SidebarSectionActionButton.test.tsx +91 -0
- package/src/sidebar/SidebarSectionActionButton.tsx +52 -0
- package/src/styles.css +7 -0
- package/src/markdown/streaming.test.ts +0 -57
- package/src/settings/AchievementNavigationButtonView.tsx +0 -90
- package/src/settings/AchievementPromotionDialogView.tsx +0 -91
- package/src/settings/AchievementSettingsView.tsx +0 -43
- package/src/settings/PetBubbleStylePreviewView.tsx +0 -44
- package/src/settings/QuickPanelSettingsSectionView.tsx +0 -64
- package/src/settings/achievements/AchievementCurtains.tsx +0 -50
- package/src/settings/achievements/AchievementPromotionBadge3D.tsx +0 -350
- package/src/settings/achievements/AchievementPromotionConfetti.tsx +0 -71
- package/src/settings/achievements/AchievementTitle.tsx +0 -52
- package/src/settings/achievements/index.ts +0 -13
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { Button } from "@vetta-org/ui/button";
|
|
2
|
+
import { cn } from "@vetta-org/ui/utils";
|
|
3
|
+
import { type JSX, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { formatFileSize } from "../knowledge/types";
|
|
5
|
+
import { hatch } from "./StorageBar";
|
|
6
|
+
import { StorageReadout } from "./StorageReadout";
|
|
7
|
+
import { layoutTreemap, type TreemapTile } from "./storage-treemap-layout";
|
|
8
|
+
|
|
9
|
+
export interface StorageEntryView {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly bytes: number;
|
|
12
|
+
readonly directory: boolean;
|
|
13
|
+
/** 较大的子项,从大到小;没有时不能继续展开。 */
|
|
14
|
+
readonly children?: readonly StorageEntryView[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface StorageOwnerView {
|
|
18
|
+
/** 相对数据目录的路径。 */
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly kind: "conversations" | "projects";
|
|
21
|
+
readonly title: string;
|
|
22
|
+
readonly meta: string;
|
|
23
|
+
readonly bytes: number;
|
|
24
|
+
readonly children: readonly StorageEntryView[];
|
|
25
|
+
/** 有会话记录时才能打开。 */
|
|
26
|
+
readonly onOpen?: () => void;
|
|
27
|
+
/** 正在运行的对话没有。 */
|
|
28
|
+
readonly onDelete?: () => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface StorageExplorerLabels {
|
|
32
|
+
readonly scanning: string;
|
|
33
|
+
readonly rescan: string;
|
|
34
|
+
readonly open: string;
|
|
35
|
+
readonly reveal: string;
|
|
36
|
+
readonly delete: string;
|
|
37
|
+
readonly view: string;
|
|
38
|
+
readonly all: string;
|
|
39
|
+
readonly rest: string;
|
|
40
|
+
readonly empty: string;
|
|
41
|
+
readonly largestDescription: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface StorageExplorerProps {
|
|
45
|
+
readonly labels: StorageExplorerLabels;
|
|
46
|
+
/** owners 是全部对话与项目,从大到小。 */
|
|
47
|
+
readonly explorer: { readonly totalBytes: number; readonly owners: readonly StorageOwnerView[] } | null;
|
|
48
|
+
readonly scanning: boolean;
|
|
49
|
+
readonly cleaning: boolean;
|
|
50
|
+
readonly onRescan: () => void;
|
|
51
|
+
readonly onReveal: (path: string) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type ItemKind = "conversations" | "projects" | "folder" | "file" | "rest";
|
|
55
|
+
|
|
56
|
+
interface Item {
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly kind: ItemKind;
|
|
59
|
+
readonly title: string;
|
|
60
|
+
readonly meta?: string;
|
|
61
|
+
readonly bytes: number;
|
|
62
|
+
readonly color: string;
|
|
63
|
+
/** 下一层的内容;为空时不能展开。 */
|
|
64
|
+
readonly children: readonly Item[];
|
|
65
|
+
readonly owner?: StorageOwnerView;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface Level {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly title: string;
|
|
71
|
+
readonly bytes: number;
|
|
72
|
+
readonly items: readonly Item[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 正在离开的一层;缩放以被点开(或被收起)的那一块为中心。 */
|
|
76
|
+
interface Transition {
|
|
77
|
+
readonly leaving: Level;
|
|
78
|
+
readonly origin: string;
|
|
79
|
+
readonly deeper: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const STAGE_WIDTH = 616;
|
|
83
|
+
const STAGE_HEIGHT = 360;
|
|
84
|
+
const TILE_GAP = 4;
|
|
85
|
+
/** 每层先列这么多,其余合成一块,点开再看。 */
|
|
86
|
+
const LEVEL_LIMIT = 12;
|
|
87
|
+
/** 合并项展开后清单列出全部,图上只画这么多。 */
|
|
88
|
+
const TILE_LIMIT = 24;
|
|
89
|
+
const REST_ID = "#rest";
|
|
90
|
+
const REST_COLOR = "var(--muted-foreground)";
|
|
91
|
+
const OWNER_COLORS = { conversations: "var(--context-segment-1)", projects: "var(--context-segment-2)" } as const;
|
|
92
|
+
const ICONS: Record<ItemKind, string> = {
|
|
93
|
+
conversations: "icon-[solar--chat-round-line-linear]",
|
|
94
|
+
projects: "icon-[solar--folder-linear]",
|
|
95
|
+
folder: "icon-[solar--folder-linear]",
|
|
96
|
+
file: "icon-[solar--file-linear]",
|
|
97
|
+
rest: "icon-[solar--layers-minimalistic-linear]",
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const percent = (value: number, whole: number) => `${(value / whole) * 100}%`;
|
|
101
|
+
|
|
102
|
+
function entryItems(
|
|
103
|
+
parentId: string,
|
|
104
|
+
parentBytes: number,
|
|
105
|
+
entries: readonly StorageEntryView[],
|
|
106
|
+
color: string,
|
|
107
|
+
restLabel: string,
|
|
108
|
+
): Item[] {
|
|
109
|
+
if (entries.length === 0) return [];
|
|
110
|
+
const items = entries.map((entry): Item => {
|
|
111
|
+
const id = `${parentId}/${entry.name}`;
|
|
112
|
+
return {
|
|
113
|
+
id,
|
|
114
|
+
kind: entry.directory ? "folder" : "file",
|
|
115
|
+
title: entry.name,
|
|
116
|
+
bytes: entry.bytes,
|
|
117
|
+
color,
|
|
118
|
+
children: entryItems(id, entry.bytes, entry.children ?? [], color, restLabel),
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
// 扫描只保留较大的子项,差额合成一块;它没有明细,不能展开。
|
|
122
|
+
const rest = parentBytes - items.reduce((sum, item) => sum + item.bytes, 0);
|
|
123
|
+
if (rest < parentBytes * 0.005) return items;
|
|
124
|
+
return [...items, restItem(`${parentId}/${REST_ID}`, restLabel, rest, [])];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const restItem = (id: string, title: string, bytes: number, children: readonly Item[]): Item => ({
|
|
128
|
+
id,
|
|
129
|
+
kind: "rest",
|
|
130
|
+
title,
|
|
131
|
+
bytes,
|
|
132
|
+
color: REST_COLOR,
|
|
133
|
+
children,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
function rootLevel(explorer: NonNullable<StorageExplorerProps["explorer"]>, labels: StorageExplorerLabels): Level {
|
|
137
|
+
const owners = explorer.owners.map((owner): Item => {
|
|
138
|
+
const color = OWNER_COLORS[owner.kind];
|
|
139
|
+
return {
|
|
140
|
+
id: owner.id,
|
|
141
|
+
kind: owner.kind,
|
|
142
|
+
title: owner.title,
|
|
143
|
+
meta: owner.meta,
|
|
144
|
+
bytes: owner.bytes,
|
|
145
|
+
color,
|
|
146
|
+
children: entryItems(owner.id, owner.bytes, owner.children, color, labels.rest),
|
|
147
|
+
owner,
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
const small = owners.slice(LEVEL_LIMIT);
|
|
151
|
+
const items =
|
|
152
|
+
small.length > 1
|
|
153
|
+
? [...owners.slice(0, LEVEL_LIMIT), restItem(REST_ID, labels.rest, sumBytes(small), small)]
|
|
154
|
+
: owners;
|
|
155
|
+
return { id: "", title: labels.all, bytes: explorer.totalBytes, items };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const sumBytes = (items: readonly Item[]) => items.reduce((sum, item) => sum + item.bytes, 0);
|
|
159
|
+
|
|
160
|
+
/** 从「全部」到当前位置的每一层;重新计算后已经不存在的层自动略去。 */
|
|
161
|
+
function resolveLevels(root: Level, path: readonly string[]): Level[] {
|
|
162
|
+
const levels = [root];
|
|
163
|
+
for (const id of path) {
|
|
164
|
+
const parent = levels.at(-1)?.items.find((item) => item.id === id);
|
|
165
|
+
if (!parent || parent.children.length === 0) break;
|
|
166
|
+
levels.push({ id: parent.id, title: parent.title, bytes: parent.bytes, items: parent.children });
|
|
167
|
+
}
|
|
168
|
+
return levels;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** 图上的块;超出上限的并成最后一块,它只示意,不能点。 */
|
|
172
|
+
function tilesOf(level: Level): { item: Item; tile: TreemapTile }[] {
|
|
173
|
+
const hidden = level.items.slice(TILE_LIMIT);
|
|
174
|
+
const shown =
|
|
175
|
+
hidden.length > 0
|
|
176
|
+
? [...level.items.slice(0, TILE_LIMIT), restItem(`${level.id}/#hidden`, "", sumBytes(hidden), [])]
|
|
177
|
+
: level.items;
|
|
178
|
+
// 画布各边多算一个间隙再从每块里扣掉,外缘就能与正文左右对齐。
|
|
179
|
+
const tiles = layoutTreemap(
|
|
180
|
+
shown.map((item) => item.bytes),
|
|
181
|
+
STAGE_WIDTH + TILE_GAP,
|
|
182
|
+
STAGE_HEIGHT + TILE_GAP,
|
|
183
|
+
);
|
|
184
|
+
return tiles.flatMap((tile, index) => {
|
|
185
|
+
const item = shown[index];
|
|
186
|
+
return item
|
|
187
|
+
? [{ item, tile: { ...tile, width: tile.width - TILE_GAP, height: tile.height - TILE_GAP } }]
|
|
188
|
+
: [];
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** 逐层查看对话与项目的占用:矩形越大占用越多,点开进入下一层。矩形是指针快捷方式,键盘与读屏走下面的清单。 */
|
|
193
|
+
export function StorageExplorer(props: StorageExplorerProps): JSX.Element {
|
|
194
|
+
const { labels, explorer, onReveal } = props;
|
|
195
|
+
const topRef = useRef<HTMLDivElement>(null);
|
|
196
|
+
const [path, setPath] = useState<readonly string[]>([]);
|
|
197
|
+
const [activeId, setActiveId] = useState<string | null>(null);
|
|
198
|
+
const [transition, setTransition] = useState<Transition | null>(null);
|
|
199
|
+
const root = useMemo(() => (explorer ? rootLevel(explorer, labels) : null), [explorer, labels]);
|
|
200
|
+
const levels = useMemo(() => (root ? resolveLevels(root, path) : []), [root, path]);
|
|
201
|
+
const level = levels.at(-1);
|
|
202
|
+
const active = level?.items.find((item) => item.id === activeId);
|
|
203
|
+
|
|
204
|
+
const goTo = (depth: number, next?: Item) => {
|
|
205
|
+
if (!level) return;
|
|
206
|
+
const target = levels[depth];
|
|
207
|
+
// 深入时从被点的那块放大;返回时向当前目录在上一层里的那块收拢。
|
|
208
|
+
const pivotLevel = next ? level : target;
|
|
209
|
+
const pivotId = next?.id ?? levels[depth + 1]?.id;
|
|
210
|
+
const pivot = pivotLevel && tilesOf(pivotLevel).find(({ item }) => item.id === pivotId)?.tile;
|
|
211
|
+
setTransition({
|
|
212
|
+
leaving: level,
|
|
213
|
+
origin: pivot ? `${percent(pivot.x + pivot.width / 2, STAGE_WIDTH)} ${percent(pivot.y + pivot.height / 2, STAGE_HEIGHT)}` : "50% 50%",
|
|
214
|
+
deeper: next !== undefined,
|
|
215
|
+
});
|
|
216
|
+
setPath([...levels.slice(1, depth + 1).map((item) => item.id), ...(next ? [next.id] : [])]);
|
|
217
|
+
setActiveId(null);
|
|
218
|
+
// 从清单下方点开时,图可能已经滚出视野。
|
|
219
|
+
topRef.current?.scrollIntoView?.({ block: "nearest" });
|
|
220
|
+
};
|
|
221
|
+
const select = (item: Item) => {
|
|
222
|
+
if (item.children.length > 0) goTo(levels.length - 1, item);
|
|
223
|
+
else if (item.kind !== "rest") onReveal(item.id);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<>
|
|
228
|
+
<div ref={topRef} className="scroll-mt-8" />
|
|
229
|
+
<StorageReadout
|
|
230
|
+
title={
|
|
231
|
+
<nav className="flex min-w-0 items-center">
|
|
232
|
+
{levels.map((item, index) => {
|
|
233
|
+
const current = index === levels.length - 1;
|
|
234
|
+
return (
|
|
235
|
+
<span key={item.id} className="flex min-w-0 items-center">
|
|
236
|
+
{index > 0 && (
|
|
237
|
+
<span
|
|
238
|
+
aria-hidden="true"
|
|
239
|
+
className="icon-[solar--alt-arrow-right-linear] mx-1 h-3 w-3 shrink-0 opacity-50"
|
|
240
|
+
/>
|
|
241
|
+
)}
|
|
242
|
+
<Button
|
|
243
|
+
variant="link"
|
|
244
|
+
aria-current={current ? "page" : undefined}
|
|
245
|
+
disabled={current}
|
|
246
|
+
className={cn(
|
|
247
|
+
"h-5 min-w-0 shrink p-0 text-[12px] font-normal hover:text-foreground hover:no-underline disabled:opacity-100",
|
|
248
|
+
current && levels.length > 1 ? "text-foreground" : "text-muted-foreground",
|
|
249
|
+
)}
|
|
250
|
+
onClick={() => goTo(index)}
|
|
251
|
+
>
|
|
252
|
+
<span className="max-w-40 truncate">{item.title}</span>
|
|
253
|
+
</Button>
|
|
254
|
+
</span>
|
|
255
|
+
);
|
|
256
|
+
})}
|
|
257
|
+
</nav>
|
|
258
|
+
}
|
|
259
|
+
bytes={level ? (active?.bytes ?? level.bytes) : null}
|
|
260
|
+
share={active && level && level.bytes > 0 ? active.bytes / level.bytes : undefined}
|
|
261
|
+
hint={active?.title ?? (levels.length === 1 ? labels.largestDescription : "")}
|
|
262
|
+
scanning={props.scanning}
|
|
263
|
+
disabled={props.cleaning}
|
|
264
|
+
scanningLabel={labels.scanning}
|
|
265
|
+
rescanLabel={labels.rescan}
|
|
266
|
+
onRescan={props.onRescan}
|
|
267
|
+
/>
|
|
268
|
+
|
|
269
|
+
<div
|
|
270
|
+
aria-hidden="true"
|
|
271
|
+
className="relative mt-6 w-full overflow-clip [contain:layout] [overflow-clip-margin:24px]"
|
|
272
|
+
style={{ aspectRatio: `${STAGE_WIDTH} / ${STAGE_HEIGHT}` }}
|
|
273
|
+
onMouseLeave={() => setActiveId(null)}
|
|
274
|
+
>
|
|
275
|
+
{transition && (
|
|
276
|
+
<TileLayer
|
|
277
|
+
key={`leaving:${transition.leaving.id}`}
|
|
278
|
+
level={transition.leaving}
|
|
279
|
+
activeId={null}
|
|
280
|
+
origin={transition.origin}
|
|
281
|
+
className={cn(
|
|
282
|
+
"pointer-events-none animate-out fade-out-0 fill-mode-forwards motion-reduce:hidden",
|
|
283
|
+
transition.deeper ? "zoom-out-115" : "zoom-out-80",
|
|
284
|
+
)}
|
|
285
|
+
onAnimationEnd={() => setTransition((current) => (current === transition ? null : current))}
|
|
286
|
+
/>
|
|
287
|
+
)}
|
|
288
|
+
{level && (
|
|
289
|
+
<TileLayer
|
|
290
|
+
key={level.id}
|
|
291
|
+
level={level}
|
|
292
|
+
activeId={activeId}
|
|
293
|
+
origin={transition?.origin}
|
|
294
|
+
className={cn(
|
|
295
|
+
"animate-in fade-in-0 motion-reduce:animate-none",
|
|
296
|
+
transition && !transition.deeper ? "zoom-in-110" : "zoom-in-80",
|
|
297
|
+
)}
|
|
298
|
+
onActiveChange={setActiveId}
|
|
299
|
+
onSelect={select}
|
|
300
|
+
/>
|
|
301
|
+
)}
|
|
302
|
+
</div>
|
|
303
|
+
|
|
304
|
+
{level && level.items.length === 0 && (
|
|
305
|
+
<p className="text-center text-[12px] text-muted-foreground">{labels.empty}</p>
|
|
306
|
+
)}
|
|
307
|
+
<ul className="-mx-3 mt-6" onMouseLeave={() => setActiveId(null)}>
|
|
308
|
+
{level?.items.map((item) => (
|
|
309
|
+
<ItemRow
|
|
310
|
+
key={item.id}
|
|
311
|
+
item={item}
|
|
312
|
+
labels={labels}
|
|
313
|
+
active={item.id === activeId}
|
|
314
|
+
onActive={() => setActiveId(item.id)}
|
|
315
|
+
onSelect={() => select(item)}
|
|
316
|
+
onReveal={() => onReveal(item.id)}
|
|
317
|
+
/>
|
|
318
|
+
))}
|
|
319
|
+
</ul>
|
|
320
|
+
</>
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** 一层矩形。层切换只动整层的 transform 与 opacity,不给每块单独做动画。 */
|
|
325
|
+
function TileLayer({
|
|
326
|
+
level,
|
|
327
|
+
activeId,
|
|
328
|
+
origin,
|
|
329
|
+
className,
|
|
330
|
+
onAnimationEnd,
|
|
331
|
+
onActiveChange,
|
|
332
|
+
onSelect,
|
|
333
|
+
}: {
|
|
334
|
+
readonly level: Level;
|
|
335
|
+
readonly activeId: string | null;
|
|
336
|
+
readonly origin?: string;
|
|
337
|
+
readonly className: string;
|
|
338
|
+
readonly onAnimationEnd?: () => void;
|
|
339
|
+
readonly onActiveChange?: (id: string) => void;
|
|
340
|
+
readonly onSelect?: (item: Item) => void;
|
|
341
|
+
}): JSX.Element {
|
|
342
|
+
const tiles = useMemo(() => tilesOf(level), [level]);
|
|
343
|
+
return (
|
|
344
|
+
<div
|
|
345
|
+
className={cn("absolute inset-0 duration-300 ease-out", className)}
|
|
346
|
+
style={{ transformOrigin: origin }}
|
|
347
|
+
onAnimationEnd={onAnimationEnd}
|
|
348
|
+
>
|
|
349
|
+
{tiles.map(({ item, tile }) => {
|
|
350
|
+
const strength = item.id === activeId ? (item.kind === "rest" ? 22 : 46) : item.kind === "rest" ? 10 : 28;
|
|
351
|
+
const inert = item.kind === "rest" && item.children.length === 0;
|
|
352
|
+
return (
|
|
353
|
+
<Button
|
|
354
|
+
key={item.id}
|
|
355
|
+
variant="ghost"
|
|
356
|
+
tabIndex={-1}
|
|
357
|
+
className={cn(
|
|
358
|
+
"absolute h-auto flex-col items-start justify-start gap-0.5 overflow-hidden rounded-lg px-2.5 py-2 font-normal transition-colors duration-200 active:not-aria-[haspopup]:translate-y-0",
|
|
359
|
+
inert && "cursor-default",
|
|
360
|
+
)}
|
|
361
|
+
style={{
|
|
362
|
+
left: percent(tile.x, STAGE_WIDTH),
|
|
363
|
+
top: percent(tile.y, STAGE_HEIGHT),
|
|
364
|
+
width: percent(tile.width, STAGE_WIDTH),
|
|
365
|
+
height: percent(tile.height, STAGE_HEIGHT),
|
|
366
|
+
backgroundColor: `color-mix(in srgb, ${item.color} ${strength}%, var(--background))`,
|
|
367
|
+
...(item.kind === "rest"
|
|
368
|
+
? { backgroundImage: hatch(`color-mix(in srgb, ${item.color} 14%, transparent)`) }
|
|
369
|
+
: {}),
|
|
370
|
+
}}
|
|
371
|
+
onMouseEnter={() => onActiveChange?.(item.id)}
|
|
372
|
+
onClick={() => onSelect?.(item)}
|
|
373
|
+
>
|
|
374
|
+
{tile.width >= 56 && tile.height >= 32 && (
|
|
375
|
+
<span className="max-w-full truncate text-[12px] text-foreground">{item.title}</span>
|
|
376
|
+
)}
|
|
377
|
+
{tile.width >= 72 && tile.height >= 52 && (
|
|
378
|
+
<span className="text-[11px] text-muted-foreground tabular-nums">{formatFileSize(item.bytes)}</span>
|
|
379
|
+
)}
|
|
380
|
+
</Button>
|
|
381
|
+
);
|
|
382
|
+
})}
|
|
383
|
+
</div>
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function ItemRow({
|
|
388
|
+
item,
|
|
389
|
+
labels,
|
|
390
|
+
active,
|
|
391
|
+
onActive,
|
|
392
|
+
onSelect,
|
|
393
|
+
onReveal,
|
|
394
|
+
}: {
|
|
395
|
+
readonly item: Item;
|
|
396
|
+
readonly labels: StorageExplorerLabels;
|
|
397
|
+
readonly active: boolean;
|
|
398
|
+
readonly onActive: () => void;
|
|
399
|
+
readonly onSelect: () => void;
|
|
400
|
+
readonly onReveal: () => void;
|
|
401
|
+
}): JSX.Element {
|
|
402
|
+
const expandable = item.children.length > 0;
|
|
403
|
+
const { owner } = item;
|
|
404
|
+
return (
|
|
405
|
+
<li
|
|
406
|
+
className={cn(
|
|
407
|
+
"group relative flex items-center gap-3.5 rounded-lg px-3 py-2.5 transition-colors duration-200",
|
|
408
|
+
active && "bg-accent/40",
|
|
409
|
+
)}
|
|
410
|
+
onMouseEnter={onActive}
|
|
411
|
+
onFocus={onActive}
|
|
412
|
+
>
|
|
413
|
+
<span aria-hidden="true" className={cn("h-[18px] w-[18px] shrink-0", ICONS[item.kind])} style={{ color: item.color }} />
|
|
414
|
+
<div className="min-w-0 flex-1">
|
|
415
|
+
{item.kind === "rest" && !expandable ? (
|
|
416
|
+
<span className="text-[13px] text-muted-foreground">{item.title}</span>
|
|
417
|
+
) : (
|
|
418
|
+
// 整行都能点:按钮的热区铺满整行,右侧操作浮在它上面。
|
|
419
|
+
<Button
|
|
420
|
+
variant="link"
|
|
421
|
+
className="h-auto max-w-full justify-start p-0 text-[13px] text-foreground after:absolute after:inset-0 hover:no-underline active:not-aria-[haspopup]:translate-y-0"
|
|
422
|
+
aria-label={`${expandable ? labels.view : labels.reveal} ${item.title}`}
|
|
423
|
+
onClick={onSelect}
|
|
424
|
+
>
|
|
425
|
+
<span className="truncate" title={item.title}>
|
|
426
|
+
{item.title}
|
|
427
|
+
</span>
|
|
428
|
+
</Button>
|
|
429
|
+
)}
|
|
430
|
+
{item.meta && <div className="mt-0.5 truncate text-[12px] text-muted-foreground">{item.meta}</div>}
|
|
431
|
+
</div>
|
|
432
|
+
<div className="relative flex shrink-0 items-center opacity-0 transition-opacity duration-200 group-focus-within:opacity-100 group-hover:opacity-100">
|
|
433
|
+
{owner?.onOpen && (
|
|
434
|
+
<RowAction
|
|
435
|
+
icon="icon-[solar--chat-round-line-linear]"
|
|
436
|
+
label={labels.open}
|
|
437
|
+
title={item.title}
|
|
438
|
+
onClick={owner.onOpen}
|
|
439
|
+
/>
|
|
440
|
+
)}
|
|
441
|
+
{expandable && item.kind !== "rest" && (
|
|
442
|
+
<RowAction
|
|
443
|
+
icon="icon-[solar--folder-open-linear]"
|
|
444
|
+
label={labels.reveal}
|
|
445
|
+
title={item.title}
|
|
446
|
+
onClick={onReveal}
|
|
447
|
+
/>
|
|
448
|
+
)}
|
|
449
|
+
{owner?.onDelete && (
|
|
450
|
+
<RowAction
|
|
451
|
+
icon="icon-[solar--trash-bin-trash-linear]"
|
|
452
|
+
label={labels.delete}
|
|
453
|
+
title={item.title}
|
|
454
|
+
onClick={owner.onDelete}
|
|
455
|
+
/>
|
|
456
|
+
)}
|
|
457
|
+
</div>
|
|
458
|
+
<span className="w-16 shrink-0 text-right text-[13px] font-medium text-foreground tabular-nums">
|
|
459
|
+
{formatFileSize(item.bytes)}
|
|
460
|
+
</span>
|
|
461
|
+
<span
|
|
462
|
+
aria-hidden="true"
|
|
463
|
+
className={cn(
|
|
464
|
+
"-mx-1.5 h-3.5 w-3.5 shrink-0 text-muted-foreground",
|
|
465
|
+
expandable && "icon-[solar--alt-arrow-right-linear]",
|
|
466
|
+
)}
|
|
467
|
+
/>
|
|
468
|
+
</li>
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function RowAction({
|
|
473
|
+
icon,
|
|
474
|
+
label,
|
|
475
|
+
title,
|
|
476
|
+
onClick,
|
|
477
|
+
}: {
|
|
478
|
+
readonly icon: string;
|
|
479
|
+
readonly label: string;
|
|
480
|
+
readonly title: string;
|
|
481
|
+
readonly onClick: () => void;
|
|
482
|
+
}): JSX.Element {
|
|
483
|
+
return (
|
|
484
|
+
<Button variant="ghost" size="icon-sm" title={label} aria-label={`${label} ${title}`} onClick={onClick}>
|
|
485
|
+
<span aria-hidden="true" className={cn(icon, "h-4 w-4")} />
|
|
486
|
+
</Button>
|
|
487
|
+
);
|
|
488
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Button } from "@vetta-org/ui/button";
|
|
2
|
+
import { cn } from "@vetta-org/ui/utils";
|
|
3
|
+
import type { JSX, ReactNode } from "react";
|
|
4
|
+
import { formatFileSize } from "../knowledge/types";
|
|
5
|
+
|
|
6
|
+
/** 图上方的读数:指到哪一项就读哪一项,不用浮层;三行高度固定,内容变化时不会跳动。 */
|
|
7
|
+
export function StorageReadout({
|
|
8
|
+
title,
|
|
9
|
+
bytes,
|
|
10
|
+
share,
|
|
11
|
+
hint,
|
|
12
|
+
scanning,
|
|
13
|
+
disabled,
|
|
14
|
+
scanningLabel,
|
|
15
|
+
rescanLabel,
|
|
16
|
+
onRescan,
|
|
17
|
+
}: {
|
|
18
|
+
readonly title: ReactNode;
|
|
19
|
+
/** null 表示首次扫描还没有结果。 */
|
|
20
|
+
readonly bytes: number | null;
|
|
21
|
+
/** 占整体的比例;不需要时不传。 */
|
|
22
|
+
readonly share?: number;
|
|
23
|
+
readonly hint: string;
|
|
24
|
+
readonly scanning: boolean;
|
|
25
|
+
readonly disabled: boolean;
|
|
26
|
+
readonly scanningLabel: string;
|
|
27
|
+
readonly rescanLabel: string;
|
|
28
|
+
readonly onRescan: () => void;
|
|
29
|
+
}): JSX.Element {
|
|
30
|
+
const [amount, unit] = bytes === null ? [] : formatFileSize(bytes).split(" ");
|
|
31
|
+
const refreshLabel = scanning ? scanningLabel : rescanLabel;
|
|
32
|
+
return (
|
|
33
|
+
<div className="flex items-start justify-between gap-4">
|
|
34
|
+
<div className="min-w-0 flex-1">
|
|
35
|
+
<div className="flex h-5 items-center text-[12px] text-muted-foreground">{title}</div>
|
|
36
|
+
<div className="mt-1.5 -ml-0.5 flex items-baseline gap-1.5">
|
|
37
|
+
{bytes === null ? (
|
|
38
|
+
<span className="ml-0.5 text-[20px] leading-10 text-muted-foreground">{scanning ? scanningLabel : "—"}</span>
|
|
39
|
+
) : (
|
|
40
|
+
<span className="text-[40px] leading-none font-semibold tracking-tight text-foreground">{amount}</span>
|
|
41
|
+
)}
|
|
42
|
+
<span className="text-[15px] text-muted-foreground">{unit}</span>
|
|
43
|
+
{share !== undefined && (
|
|
44
|
+
<span className="ml-1.5 text-[13px] text-muted-foreground">
|
|
45
|
+
{share < 0.01 ? "<1%" : `${Math.round(share * 100)}%`}
|
|
46
|
+
</span>
|
|
47
|
+
)}
|
|
48
|
+
</div>
|
|
49
|
+
<div className="mt-2.5 h-4 truncate text-[12px] text-muted-foreground">{hint}</div>
|
|
50
|
+
</div>
|
|
51
|
+
<Button
|
|
52
|
+
variant="ghost"
|
|
53
|
+
size="icon-sm"
|
|
54
|
+
className="-mr-1.5"
|
|
55
|
+
title={refreshLabel}
|
|
56
|
+
aria-label={refreshLabel}
|
|
57
|
+
disabled={scanning || disabled}
|
|
58
|
+
onClick={onRescan}
|
|
59
|
+
>
|
|
60
|
+
<span aria-hidden="true" className={cn("icon-[solar--refresh-linear] h-4 w-4", scanning && "animate-spin")} />
|
|
61
|
+
</Button>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|