@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.
Files changed (111) hide show
  1. package/package.json +8 -16
  2. package/src/action-approval/StorageCleanListView.test.tsx +36 -0
  3. package/src/action-approval/StorageCleanListView.tsx +52 -0
  4. package/src/action-approval/index.ts +2 -0
  5. package/src/activity/ActivityPanel.tsx +7 -1
  6. package/src/activity/ActivityPanelFrame.tsx +1 -1
  7. package/src/activity/BackgroundTasksTabPanelView.tsx +18 -2
  8. package/src/activity/BrowserPanelView.tsx +15 -1
  9. package/src/activity/BrowserSelectionView.tsx +199 -0
  10. package/src/activity/CodePreview.tsx +15 -1
  11. package/src/activity/MarkdownPreviewView.test.tsx +53 -0
  12. package/src/activity/MarkdownPreviewView.tsx +86 -10
  13. package/src/activity/index.ts +1 -0
  14. package/src/chat/ContextRingView.test.tsx +81 -0
  15. package/src/chat/ContextRingView.tsx +78 -62
  16. package/src/chat/EditDiffView.tsx +4 -4
  17. package/src/chat/HeaderActionBarView.tsx +135 -48
  18. package/src/chat/HeaderActionOverflowMenu.tsx +11 -20
  19. package/src/chat/MessageFeedLayoutView.tsx +6 -5
  20. package/src/chat/MessageInputView.tsx +5 -1
  21. package/src/chat/index.ts +2 -1
  22. package/src/chat/message-feed-fade.css +80 -0
  23. package/src/chat/message-feed-fade.test.tsx +75 -0
  24. package/src/chat/streaming-reveal.test.ts +1 -74
  25. package/src/chat/streaming-reveal.ts +0 -3
  26. package/src/file-preview/FilePreviewDialogView.tsx +2 -1
  27. package/src/file-preview/ReadonlyCodeView.tsx +46 -0
  28. package/src/file-preview/syntax-tokens.css +1 -1
  29. package/src/image-assets.d.ts +4 -0
  30. package/src/layout/ResizeHandle.tsx +4 -1
  31. package/src/layout/resize-handle-reset.test.tsx +50 -0
  32. package/src/markdown/FileLinkBadge.tsx +77 -0
  33. package/src/markdown/MarkdownContent.tsx +61 -31
  34. package/src/markdown/MarkdownImage.tsx +6 -16
  35. package/src/markdown/MermaidBlock.tsx +50 -11
  36. package/src/markdown/UrlLinkBadge.tsx +84 -0
  37. package/src/markdown/image-actions.ts +29 -0
  38. package/src/markdown/index.ts +2 -0
  39. package/src/markdown/nodes.ts +6 -1
  40. package/src/markdown/preview-policy.test.ts +31 -0
  41. package/src/markdown/preview-policy.ts +33 -0
  42. package/src/markdown/progressive-chunks.test.ts +43 -0
  43. package/src/markdown/progressive-chunks.ts +58 -0
  44. package/src/markdown/rich-labels.ts +9 -0
  45. package/src/markdown/streaming-fade.test.ts +83 -0
  46. package/src/markdown/streaming-fade.tsx +141 -0
  47. package/src/markdown/streaming-reveal.ts +0 -67
  48. package/src/markdown/streaming.ts +64 -131
  49. package/src/overlays/CommandMenuRow.tsx +47 -26
  50. package/src/overlays/CommandMenuView.tsx +107 -15
  51. package/src/overlays/DiagnosticsExportDialogView.tsx +236 -0
  52. package/src/overlays/MagpieHandoverDialogView.tsx +217 -0
  53. package/src/overlays/ReleaseNoteImage.test.tsx +105 -0
  54. package/src/overlays/ReleaseNoteMarkdown.test.tsx +49 -0
  55. package/src/overlays/ReleaseNoteMarkdown.tsx +120 -7
  56. package/src/overlays/SplashPanel.tsx +4 -4
  57. package/src/overlays/SplashParts.tsx +6 -2
  58. package/src/overlays/UpdateCheckerView.tsx +17 -15
  59. package/src/overlays/UpdateRestartDialogView.tsx +76 -2
  60. package/src/overlays/assets/diagnostics-banner.webp +0 -0
  61. package/src/overlays/command-menu-types.ts +15 -1
  62. package/src/overlays/index.ts +13 -0
  63. package/src/plugin-ui/index.ts +4 -0
  64. package/src/project/DefaultConversationSectionView.tsx +17 -22
  65. package/src/project/DefaultSessionRowView.tsx +8 -0
  66. package/src/project/ManageSessionsSplashView.tsx +0 -2
  67. package/src/settings/ArchivedProjectsSettingsView.tsx +122 -1
  68. package/src/settings/GeneralSettingsView.tsx +21 -5
  69. package/src/settings/LauncherSettingsView.test.tsx +95 -0
  70. package/src/settings/LauncherSettingsView.tsx +272 -0
  71. package/src/settings/PetActionGalleryView.test.tsx +163 -0
  72. package/src/settings/PetActionGalleryView.tsx +216 -0
  73. package/src/settings/PetSettingsView.test.tsx +117 -0
  74. package/src/settings/PetSettingsView.tsx +86 -22
  75. package/src/settings/PresetProviderRowView.tsx +37 -98
  76. package/src/settings/ShortcutsSettingsView.tsx +0 -4
  77. package/src/settings/SpaceEditorDialogView.tsx +94 -56
  78. package/src/settings/SpacesSettingsView.tsx +53 -8
  79. package/src/settings/StorageBar.tsx +70 -0
  80. package/src/settings/StorageExplorer.tsx +488 -0
  81. package/src/settings/StorageReadout.tsx +64 -0
  82. package/src/settings/StorageSettingsView.test.tsx +181 -0
  83. package/src/settings/StorageSettingsView.tsx +458 -0
  84. package/src/settings/assets/space-editor-illustration.webp +0 -0
  85. package/src/settings/index.ts +28 -39
  86. package/src/settings/storage-treemap-layout.test.ts +32 -0
  87. package/src/settings/storage-treemap-layout.ts +55 -0
  88. package/src/shared/SegmentedControl.test.tsx +68 -0
  89. package/src/shared/SegmentedControl.tsx +18 -11
  90. package/src/shared/StageDialogContent.test.tsx +61 -0
  91. package/src/shared/StageDialogContent.tsx +80 -0
  92. package/src/shared/TabBar.tsx +2 -2
  93. package/src/shared/VettaKbd.tsx +20 -1
  94. package/src/shared/index.ts +4 -1
  95. package/src/shared/platform.ts +9 -0
  96. package/src/sidebar/AddProjectMenuTriggerView.tsx +13 -12
  97. package/src/sidebar/SettingsMenuTriggerView.tsx +2 -1
  98. package/src/sidebar/SidebarSectionActionButton.test.tsx +91 -0
  99. package/src/sidebar/SidebarSectionActionButton.tsx +52 -0
  100. package/src/styles.css +7 -0
  101. package/src/markdown/streaming.test.ts +0 -57
  102. package/src/settings/AchievementNavigationButtonView.tsx +0 -90
  103. package/src/settings/AchievementPromotionDialogView.tsx +0 -91
  104. package/src/settings/AchievementSettingsView.tsx +0 -43
  105. package/src/settings/PetBubbleStylePreviewView.tsx +0 -44
  106. package/src/settings/QuickPanelSettingsSectionView.tsx +0 -64
  107. package/src/settings/achievements/AchievementCurtains.tsx +0 -50
  108. package/src/settings/achievements/AchievementPromotionBadge3D.tsx +0 -350
  109. package/src/settings/achievements/AchievementPromotionConfetti.tsx +0 -71
  110. package/src/settings/achievements/AchievementTitle.tsx +0 -52
  111. package/src/settings/achievements/index.ts +0 -13
@@ -8,7 +8,6 @@
8
8
  * - 未闭合的行内语法(`[链接](…)`、行内代码、加粗)先扣着不放,闭合后整体出现,
9
9
  * 避免先看到原始标记再翻转成徽标;扣太久或太长就当普通文字放出。
10
10
  * - 尾部未写完的词先不显示;停顿太久就不再等。
11
- * - 分段给 rehype 用的短语切分(`splitStreamingSegments`)保持按标点切,供「最新短语略暗」使用。
12
11
  */
13
12
 
14
13
  /** 放出 tick 的兜底间隔,与宿主增量刷新同周期(100ms)。 */
@@ -26,80 +25,14 @@ const MIN_RATE_PER_MS = 0.02;
26
25
  /** 未闭合行内语法最多扣这么久 / 这么长,之后当普通文字放出。 */
27
26
  export const HOLD_MAX_MS = 800;
28
27
  const HOLD_MAX_CHARS = 240;
29
- /** 无标点长片段的切分上限(UTF-16 code units),供 rehype 分段。 */
30
- const MAX_PHRASE_LENGTH = 48;
31
- /** 按上限切分时,优先在这个长度之后的最后一个空白处断开。 */
32
- const MIN_SOFT_BREAK_LENGTH = 16;
33
28
 
34
- /** 最后一个片放出后,等这么久再撤掉「最新短语略暗」的包裹类。 */
35
- export const STREAMING_SETTLE_MS = 150;
36
- /**
37
- * 流还没结束、但已全部放出且这么久没有新文本时,也撤掉暗色:正文写完到回合结束事件之间常有
38
- * 近一秒的空档,不能让末尾短语一直暗着。新文本到达时会重新挂上包裹类。
39
- */
40
- export const STREAMING_IDLE_SETTLE_MS = 300;
41
29
  /** 尾部未完成的词超过这么久没有新内容,就不再等,直接放出,避免模型停顿时文字「卡住」。 */
42
30
  export const STREAMING_STALL_FLUSH_MS = 800;
43
31
 
44
- const CJK_BREAK = new Set([",", "。", ";", ":", "!", "?", "、", "…"]);
45
- const CJK_TRAILING = new Set([",", "。", ";", ":", "!", "?", "、", "…", "”", "’", ")", "」", "』", "》", "】"]);
46
- const LATIN_BREAK = new Set([",", ".", ";", ":", "!", "?"]);
47
- const WHITESPACE = /\s/;
48
-
49
32
  function isHighSurrogate(code: number): boolean {
50
33
  return code >= 0xd800 && code <= 0xdbff;
51
34
  }
52
35
 
53
- /**
54
- * 从 `from` 开始的下一个短语的结束位置;尾部还没写完时返回 null。
55
- * `final` 表示文本不会再增长,此时末尾剩余内容也算一个完整短语。
56
- */
57
- export function nextPhraseEnd(text: string, from: number, final: boolean): number | null {
58
- const length = text.length;
59
- if (from >= length) return null;
60
-
61
- for (let index = from; index < length; index++) {
62
- const char = text[index] as string;
63
- if (char === "\n") return index + 1;
64
-
65
- if (CJK_BREAK.has(char)) {
66
- let end = index + 1;
67
- while (end < length && CJK_TRAILING.has(text[end] as string)) end++;
68
- return end;
69
- }
70
-
71
- // 英文标点只有后面跟着空白才算断句:`3.14`、`e.g.x`、URL 里的点都不断开;
72
- // 标点正好在末尾时还不知道后面是什么,先当作未完成。
73
- if (LATIN_BREAK.has(char)) {
74
- if (index + 1 < length) {
75
- if (WHITESPACE.test(text[index + 1] as string)) return index + 1;
76
- } else if (!final) {
77
- return null;
78
- }
79
- }
80
-
81
- if (index + 1 - from >= MAX_PHRASE_LENGTH) {
82
- for (let back = index; back >= from + MIN_SOFT_BREAK_LENGTH; back--) {
83
- if (WHITESPACE.test(text[back] as string)) return back;
84
- }
85
- return isHighSurrogate(text.charCodeAt(index)) ? index + 2 : index + 1;
86
- }
87
- }
88
-
89
- return final ? length : null;
90
- }
91
-
92
- /** 把一段文本切成可逐个淡入的短语;拼接结果恒等于输入,文本末尾总是结束最后一个短语。 */
93
- export function splitStreamingSegments(value: string): string[] {
94
- const segments: string[] = [];
95
- for (let start = 0; start < value.length; ) {
96
- const end = nextPhraseEnd(value, start, true) ?? value.length;
97
- segments.push(value.slice(start, end));
98
- start = end;
99
- }
100
- return segments;
101
- }
102
-
103
36
  function isWordChar(char: string | undefined): boolean {
104
37
  return char !== undefined && /[\p{L}\p{N}_]/u.test(char) && !isCjk(char);
105
38
  }
@@ -1,68 +1,6 @@
1
1
  import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
2
- import type { HastElement, HastRoot, HastText } from "./nodes";
3
- import {
4
- DEFAULT_RATE_PER_MS,
5
- planReveal,
6
- REVEAL_TICK_MS,
7
- STREAMING_IDLE_SETTLE_MS,
8
- STREAMING_SETTLE_MS,
9
- STREAMING_STALL_FLUSH_MS,
10
- splitStreamingSegments,
11
- } from "./streaming-reveal";
12
-
13
- const WHITESPACE_ONLY = /^\s+$/;
14
-
15
- /**
16
- * 把流式尾块的正文按短语包成 `.streaming-chunk`,最新的两个短语再加 `-latest` / `-recent`:
17
- * 宿主 CSS 让它们略暗,下一次放出短语时随重渲染一起变亮。不用 CSS 淡入动画——每个短语各跑一段
18
- * 动画意味着流式全程连续出帧,毛玻璃窗口每帧都要整窗重合成;这样亮度只随放出节奏变,不多一帧。
19
- */
20
- export function rehypeStreamingChunks() {
21
- return (tree: HastRoot): void => {
22
- const chunks: HastElement[] = [];
23
- function visit(node: HastRoot | HastElement, inCode: boolean): void {
24
- const newChildren: Array<(typeof node.children)[number]> = [];
25
- for (const child of node.children) {
26
- if (child.type === "text" && !inCode) {
27
- for (const segment of splitStreamingSegments((child as HastText).value)) {
28
- if (WHITESPACE_ONLY.test(segment)) {
29
- newChildren.push({ type: "text", value: segment } as HastText);
30
- continue;
31
- }
32
- const chunk: HastElement = {
33
- type: "element",
34
- tagName: "span",
35
- properties: { className: ["streaming-chunk"] },
36
- children: [{ type: "text", value: segment } as HastText],
37
- };
38
- chunks.push(chunk);
39
- newChildren.push(chunk);
40
- }
41
- } else {
42
- newChildren.push(child);
43
- if (child.type === "element") {
44
- const tag = child.tagName;
45
- // 表格也当字面量:单元格文字被拆成片段再逐步增长会反复触发列宽重算,
46
- // 流式期表格会抖动。
47
- visit(child, inCode || tag === "code" || tag === "pre" || tag === "table" || tag === "vetta-svg");
48
- }
49
- }
50
- }
51
- node.children = newChildren as typeof node.children;
52
- }
53
-
54
- visit(tree, false);
55
- const latest = chunks.at(-1);
56
- const recent = chunks.at(-2);
57
- if (latest) latest.properties = { className: ["streaming-chunk", "streaming-chunk-latest"] };
58
- if (recent) recent.properties = { className: ["streaming-chunk", "streaming-chunk-recent"] };
59
- };
60
- }
61
-
62
- interface StreamingDisplayState {
63
- displayText: string;
64
- animateChunks: boolean;
65
- }
2
+ import { pruneReveals, STREAMING_FADE_MS, type StreamingReveal } from "./streaming-fade";
3
+ import { DEFAULT_RATE_PER_MS, planReveal, REVEAL_TICK_MS, STREAMING_STALL_FLUSH_MS } from "./streaming-reveal";
66
4
 
67
5
  function clearTimeoutRef(ref: { current: number | null }): void {
68
6
  if (ref.current !== null) {
@@ -87,16 +25,24 @@ function estimateRate(samples: readonly ArrivalSample[], now: number): number {
87
25
  return (last.length - first.length) / (last.at - first.at);
88
26
  }
89
27
 
28
+ export interface StreamingDisplay {
29
+ readonly text: string;
30
+ /** 仍在淡入期的放出区间,供尾块给新文字挂淡入(见 streaming-fade)。 */
31
+ readonly reveals: readonly StreamingReveal[];
32
+ }
33
+
34
+ const NO_REVEALS: readonly StreamingReveal[] = [];
35
+
90
36
  /**
91
- * 流式尾块:把显示文本匀速追向宿主文本(节奏见 streaming-reveal),配合 rehype 分段做「最新短语略暗」。
37
+ * 流式尾块:把显示文本匀速追向宿主文本(节奏见 streaming-reveal),并记下每次放出的区间与时刻,
38
+ * 让新文字平滑淡入(streaming-fade)。
92
39
  * 放出由 `text` 变化(宿主每 100ms 一次的增量刷新)驱动,在布局效果里同步更新,与那次渲染落在同一帧;
93
- * 没有新文本时由兜底 tick 收尾。尾部未写完的词、未闭合的行内语法先扣着;流结束后按节奏放完再撤掉分段。
40
+ * 没有新文本时由兜底 tick 收尾。尾部未写完的词、未闭合的行内语法先扣着;流结束后一次放完。
94
41
  *
95
- * 从未作为尾块流式过的实例(历史消息、产品故事等由宿主自己驱动逐字的场景)直接镜像 `text`。
42
+ * 从未作为尾块流式过的实例(历史消息、产品故事等由宿主自己驱动逐字的场景)直接镜像 `text`,不淡入。
96
43
  */
97
- export function useStreamingDisplayText(text: string, active: boolean): StreamingDisplayState {
98
- const [displayText, setDisplayText] = useState(() => (active ? "" : text));
99
- const [animateChunks, setAnimateChunks] = useState(active);
44
+ export function useStreamingDisplayText(text: string, active: boolean): StreamingDisplay {
45
+ const [display, setDisplay] = useState<StreamingDisplay>(() => ({ text: active ? "" : text, reveals: NO_REVEALS }));
100
46
  const displayRef = useRef(active ? "" : text);
101
47
  const targetRef = useRef(text);
102
48
  const activeRef = useRef(active);
@@ -108,67 +54,58 @@ export function useStreamingDisplayText(text: string, active: boolean): Streamin
108
54
  /** 扣留开始的时间;null 表示当前没有扣留。 */
109
55
  const heldSinceRef = useRef<number | null>(null);
110
56
  const tickTimerRef = useRef<number | null>(null);
111
- const settleTimerRef = useRef<number | null>(null);
57
+ /** 最后一段淡入结束后撤掉包裹,让尾块回到纯文本节点。 */
58
+ const fadeClearTimerRef = useRef<number | null>(null);
112
59
 
113
- const settle = useCallback((): void => {
114
- if (settleTimerRef.current !== null) return;
115
- settleTimerRef.current = window.setTimeout(() => {
116
- settleTimerRef.current = null;
60
+ const reveal = useCallback(function reveal(): void {
61
+ clearTimeoutRef(tickTimerRef);
62
+ const now = Date.now();
63
+ const target = targetRef.current;
64
+ const shown = displayRef.current.length;
65
+ const final = !activeRef.current;
66
+ const stalled = !final && now - lastArrivalAtRef.current >= STREAMING_STALL_FLUSH_MS;
67
+ const step = planReveal({
68
+ text: target,
69
+ revealed: shown,
70
+ final,
71
+ ratePerMs: estimateRate(samplesRef.current, now),
72
+ elapsedMs: lastAdvanceAtRef.current ? now - lastAdvanceAtRef.current : REVEAL_TICK_MS,
73
+ stalled,
74
+ heldMs: heldSinceRef.current === null ? 0 : now - heldSinceRef.current,
75
+ });
76
+ if (step?.held) heldSinceRef.current ??= now;
77
+ else heldSinceRef.current = null;
78
+ if (step && step.end > shown) {
79
+ const next = target.slice(0, step.end);
80
+ displayRef.current = next;
81
+ const at = performance.now();
82
+ setDisplay((current) => ({
83
+ text: next,
84
+ reveals: [...pruneReveals(current.reveals, at), { start: shown, end: next.length, at }],
85
+ }));
86
+ clearTimeoutRef(fadeClearTimerRef);
87
+ fadeClearTimerRef.current = window.setTimeout(() => {
88
+ fadeClearTimerRef.current = null;
89
+ // 计时从最后一次放出算起,到点时所有记录都已淡入完。
90
+ setDisplay((current) =>
91
+ current.reveals.length === 0 ? current : { text: current.text, reveals: NO_REVEALS },
92
+ );
93
+ }, STREAMING_FADE_MS);
94
+ lastAdvanceAtRef.current = now;
95
+ }
96
+ if (displayRef.current.length >= target.length) lastAdvanceAtRef.current = now;
97
+ if (displayRef.current.length < target.length) {
98
+ tickTimerRef.current = window.setTimeout(reveal, REVEAL_TICK_MS);
99
+ } else if (final) {
100
+ // 流已结束且已放完:之后的文本变化直接镜像。
117
101
  streamedRef.current = false;
118
- setAnimateChunks(false);
119
- }, STREAMING_SETTLE_MS);
120
- }, []);
121
-
122
- /** 已追平但流未结束:静默一会儿后只撤暗色,保留 streamedRef,新文本到达时布局效果会重新挂上。 */
123
- const settleIdle = useCallback((): void => {
124
- if (settleTimerRef.current !== null) return;
125
- settleTimerRef.current = window.setTimeout(() => {
126
- settleTimerRef.current = null;
127
- setAnimateChunks(false);
128
- }, STREAMING_IDLE_SETTLE_MS);
102
+ }
129
103
  }, []);
130
104
 
131
- const reveal = useCallback(
132
- function reveal(): void {
133
- clearTimeoutRef(tickTimerRef);
134
- const now = Date.now();
135
- const target = targetRef.current;
136
- const shown = displayRef.current.length;
137
- const final = !activeRef.current;
138
- const stalled = !final && now - lastArrivalAtRef.current >= STREAMING_STALL_FLUSH_MS;
139
- const step = planReveal({
140
- text: target,
141
- revealed: shown,
142
- final,
143
- ratePerMs: estimateRate(samplesRef.current, now),
144
- elapsedMs: lastAdvanceAtRef.current ? now - lastAdvanceAtRef.current : REVEAL_TICK_MS,
145
- stalled,
146
- heldMs: heldSinceRef.current === null ? 0 : now - heldSinceRef.current,
147
- });
148
- if (step?.held) heldSinceRef.current ??= now;
149
- else heldSinceRef.current = null;
150
- if (step && step.end > shown) {
151
- const next = target.slice(0, step.end);
152
- displayRef.current = next;
153
- setDisplayText(next);
154
- lastAdvanceAtRef.current = now;
155
- }
156
- if (displayRef.current.length >= target.length) lastAdvanceAtRef.current = now;
157
- if (displayRef.current.length < target.length) {
158
- tickTimerRef.current = window.setTimeout(reveal, REVEAL_TICK_MS);
159
- } else if (final) {
160
- settle();
161
- } else {
162
- settleIdle();
163
- }
164
- },
165
- [settle, settleIdle],
166
- );
167
-
168
105
  useEffect(
169
106
  () => () => {
170
107
  clearTimeoutRef(tickTimerRef);
171
- clearTimeoutRef(settleTimerRef);
108
+ clearTimeoutRef(fadeClearTimerRef);
172
109
  },
173
110
  [],
174
111
  );
@@ -184,19 +121,15 @@ export function useStreamingDisplayText(text: string, active: boolean): Streamin
184
121
  if (!streamedRef.current || !text.startsWith(shown)) {
185
122
  // 从未流式过,或宿主改写了已显示内容(不是追加):直接对齐,不做节奏。
186
123
  clearTimeoutRef(tickTimerRef);
187
- clearTimeoutRef(settleTimerRef);
124
+ clearTimeoutRef(fadeClearTimerRef);
188
125
  samplesRef.current = [];
189
126
  heldSinceRef.current = null;
190
127
  displayRef.current = text;
191
- setDisplayText(text);
192
- setAnimateChunks(false);
128
+ setDisplay({ text, reveals: NO_REVEALS });
193
129
  streamedRef.current = active;
194
130
  return;
195
131
  }
196
132
 
197
- clearTimeoutRef(settleTimerRef);
198
- // 只在有新内容要放时挂暗色:空闲撤暗后回合才结束(文本没变)时不能再暗一下。
199
- if (textChanged || shown.length < text.length) setAnimateChunks(true);
200
133
  const now = Date.now();
201
134
  if (textChanged || lastArrivalAtRef.current === 0) {
202
135
  lastArrivalAtRef.current = now;
@@ -207,5 +140,5 @@ export function useStreamingDisplayText(text: string, active: boolean): Streamin
207
140
  reveal();
208
141
  }, [text, active, reveal]);
209
142
 
210
- return { displayText, animateChunks };
143
+ return display;
211
144
  }
@@ -1,12 +1,12 @@
1
- import { motion } from "motion/react";
2
1
  import { memo, type JSX } from "react";
3
2
  import { cn } from "@vetta-org/ui/utils";
4
3
  import { ConversationTagDotsView } from "../project/ConversationTagDotsView";
4
+ import { SessionStatusIcon } from "../sidebar/SessionStatusIcon";
5
5
  import type { CommandMenuHighlightRange, CommandMenuItemView } from "./command-menu-types";
6
6
 
7
7
  /**
8
- * 结果行。选中态由**静态 CSS 背景**表达,只有 2px 的左侧指示条参与 layout 动画
9
- * ——对齐 `chat/AtPanelView` 的既有做法:整行背景每次都做布局动画在低端机上代价过高。
8
+ * 结果行。选中态是一块与 ButtonGroup 选中项同语言的玻璃圆角底(前景色低透明度叠层 + 上沿亮线),
9
+ * 只在用户上下移动选中项时让这块底滑过去;结果重算时直接落位,不逐击键播放。
10
10
  */
11
11
 
12
12
  /** 把命中区间渲染成高亮片段;区间由调用方保证已排序且互不重叠。 */
@@ -38,8 +38,6 @@ function Highlighted({
38
38
  export interface CommandMenuRowProps {
39
39
  readonly item: CommandMenuItemView;
40
40
  readonly active: boolean;
41
- /** 结果集刚变化时抑制指示条的位移动画,避免逐击键抖动。 */
42
- readonly suppressSelectionAnimation: boolean;
43
41
  readonly onActivate: (id: string) => void;
44
42
  readonly onHover: (id: string) => void;
45
43
  /** 给了就在悬停 / 选中时于行尾显示「更多」按钮,给不爱用键盘的人。 */
@@ -51,7 +49,6 @@ export interface CommandMenuRowProps {
51
49
  export const CommandMenuRow = memo(function CommandMenuRow({
52
50
  item,
53
51
  active,
54
- suppressSelectionAnimation,
55
52
  onActivate,
56
53
  onHover,
57
54
  onMore,
@@ -79,34 +76,41 @@ export const CommandMenuRow = memo(function CommandMenuRow({
79
76
  "group relative flex h-9 w-full items-center gap-2.5 rounded-lg px-2.5 text-left outline-none transition-colors",
80
77
  disabled ? "cursor-not-allowed opacity-45" : "cursor-pointer",
81
78
  )}
82
- style={{
83
- background: active ? "color-mix(in srgb, var(--primary) 9%, transparent)" : "transparent",
84
- }}
85
79
  >
86
80
  {active && (
87
- <motion.span
88
- layoutId="command-menu-active-marker"
89
- // 结果重算时 layout 动画会把指示条从旧行“弹”到新行,逐击键播放既抖又费;
90
- // 只有用户主动上下移动选中项时才让它滑动。
91
- layout={!suppressSelectionAnimation}
92
- transition={
93
- suppressSelectionAnimation
94
- ? { duration: 0 }
95
- : { type: "spring", stiffness: 500, damping: 32 }
96
- }
97
- className="absolute inset-y-1.5 left-0 w-0.5 rounded-full bg-primary"
81
+ // 选中底色由当前行直接画,换行即换,不做行间滑动:连按方向键时滑动动画会被反复打断,
82
+ // 再叠上列表滚动跟随,指示条会落后、回跳,手感发飘。
83
+ <span
84
+ aria-hidden="true"
85
+ data-slot="command-menu-active-marker"
86
+ className="absolute inset-0 rounded-lg bg-foreground/[0.06] dark:bg-white/[0.08] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.08)]"
98
87
  />
99
88
  )}
100
- {item.tagColors && item.tagColors.length > 0 ? (
89
+ {item.status === "unread" ? (
90
+ // 跑完未看:保留会话图标,右上角叠一颗强调色圆点,和「在转 / 问号」区分开。
91
+ <span aria-hidden="true" data-session-unread="true" className="relative flex size-4 shrink-0 items-center justify-center">
92
+ <span className={cn(item.icon, "size-4", active ? "text-foreground" : "text-muted-foreground")} />
93
+ <span className="absolute -right-0.5 -top-0.5 size-1.5 rounded-full bg-primary" />
94
+ </span>
95
+ ) : item.status ? (
96
+ <span aria-hidden="true" className="relative flex size-4 shrink-0 items-center justify-center">
97
+ <SessionStatusIcon
98
+ active={active}
99
+ running={item.status === "running"}
100
+ waiting={item.status === "waiting"}
101
+ scheduled={false}
102
+ />
103
+ </span>
104
+ ) : item.tagColors && item.tagColors.length > 0 ? (
101
105
  // 与侧栏会话一致:标签色点占据行首图标的位置,多个标签就画多个。
102
- <ConversationTagDotsView colors={item.tagColors} className="size-4" />
106
+ <ConversationTagDotsView colors={item.tagColors} className="relative size-4" />
103
107
  ) : (
104
108
  <span
105
109
  aria-hidden="true"
106
- className={cn(item.icon, "size-4 shrink-0", active ? "text-foreground" : "text-muted-foreground")}
110
+ className={cn(item.icon, "relative size-4 shrink-0", active ? "text-foreground" : "text-muted-foreground")}
107
111
  />
108
112
  )}
109
- <span className="flex min-w-0 flex-1 items-baseline gap-2">
113
+ <span className="relative flex min-w-0 flex-1 items-baseline gap-2">
110
114
  {/*
111
115
  * 标题不参与收缩(shrink-0),只受 max-w 约束:标题和副标题都可收缩时,
112
116
  * flex 会按内容等比压缩,一条长描述能把名字挤成两三个字。让副标题先让位。
@@ -120,8 +124,25 @@ export const CommandMenuRow = memo(function CommandMenuRow({
120
124
  </span>
121
125
  )}
122
126
  </span>
127
+ {item.status && item.statusLabel && (
128
+ <span
129
+ className={cn(
130
+ "relative shrink-0 text-[11px]",
131
+ item.status === "waiting" ? "text-amber-600 dark:text-amber-400" : "text-muted-foreground",
132
+ )}
133
+ >
134
+ {item.statusLabel}
135
+ </span>
136
+ )}
123
137
  {item.badge && (
124
- <span className="shrink-0 rounded-full bg-secondary px-1.5 py-0.5 text-[10px] font-medium text-secondary-foreground">
138
+ <span
139
+ className={cn(
140
+ "relative max-w-[40%] shrink-0 truncate rounded-[5px] px-1.5 py-px text-[10px] font-medium leading-4",
141
+ item.badgeTone === "accent"
142
+ ? "bg-primary/15 text-primary"
143
+ : "bg-foreground/[0.06] text-muted-foreground dark:bg-white/[0.08]",
144
+ )}
145
+ >
125
146
  {item.badge}
126
147
  </span>
127
148
  )}
@@ -136,7 +157,7 @@ export const CommandMenuRow = memo(function CommandMenuRow({
136
157
  onMore(item.id);
137
158
  }}
138
159
  className={cn(
139
- "-mr-1 flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-opacity hover:bg-accent hover:text-foreground",
160
+ "relative -mr-1 flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-opacity hover:bg-accent hover:text-foreground",
140
161
  active ? "opacity-100" : "opacity-0 group-hover:opacity-100",
141
162
  )}
142
163
  >
@@ -1,7 +1,10 @@
1
+ import { ButtonGroup, ButtonGroupItem } from "@vetta-org/ui/button-group";
1
2
  import { useCallback, useEffect, useRef, type JSX, type RefObject } from "react";
3
+ import { detectKbdPlatform, resolveKbdKeys } from "../shared/kbd-keys";
4
+ import { VettaKbd } from "../shared/VettaKbd";
2
5
  import { CommandMenuRow } from "./CommandMenuRow";
3
6
  import type { CommandMenuGroupView, CommandMenuViewLabels } from "./command-menu-types";
4
- import { SplashFooter, SplashInputHeader } from "./SplashParts";
7
+ import { SplashInputHeader } from "./SplashParts";
5
8
  import { SplashPanel } from "./SplashPanel";
6
9
  import "./command-menu.css";
7
10
 
@@ -12,14 +15,34 @@ import "./command-menu.css";
12
15
  * 面板顶部对齐而非垂直居中:结果条数会变,垂直居中会让输入框随每次击键上下跳。
13
16
  */
14
17
 
18
+ /**
19
+ * 浮在列表上的按钮组在浅色下补一层玻璃:通用 ButtonGroup 的浅色只有一层淡灰底(贴在普通页面上够用),
20
+ * 压在白色玻璃面板和列表内容上就成了一块灰片。这里只覆盖浅色的底色与阴影(深色沿用 ButtonGroup
21
+ * 自带的 dark: 样式不变),不改通用组件。
22
+ */
23
+ export const COMMAND_MENU_FLOATING_GROUP_CLASS =
24
+ "pointer-events-auto bg-white/65 shadow-[inset_0_1px_0_rgb(255_255_255/0.95),0_0_0_1px_rgb(0_0_0/0.07),0_6px_18px_-6px_rgb(0_0_0/0.18)]";
25
+
26
+ /** 悬停提示里的快捷键文字,例如 mac 上的「⌘N」、Windows 上的「Ctrl N」。 */
27
+ function formatKbdTitle(keys: string): string {
28
+ const platform = detectKbdPlatform();
29
+ return resolveKbdKeys(keys, platform).join(platform === "mac" ? "" : " ");
30
+ }
31
+
15
32
  export interface CommandMenuViewProps {
16
33
  readonly open: boolean;
17
34
  readonly query: string;
18
35
  readonly groups: readonly CommandMenuGroupView[];
19
36
  readonly selectedId: string | null;
20
37
  readonly labels: CommandMenuViewLabels;
21
- /** 结果集因击键刚变化:抑制选中指示条的位移动画。 */
22
- readonly suppressSelectionAnimation: boolean;
38
+ /** 唤起 / 关闭面板的快捷键(例如 "mod+t"),显示在输入框右侧。 */
39
+ readonly toggleShortcut?: string;
40
+ /** 给了就在左下角显示「新会话」按钮,与右下角操作按钮组对称。 */
41
+ readonly onNewSession?: () => void;
42
+ /** 新建会话的生效快捷键,显示在按钮里。 */
43
+ readonly newSessionShortcut?: string;
44
+ /** 给了就在「新会话」同一组里追加「全部已读」;宿主只在有跑完未看的会话时传。 */
45
+ readonly onMarkAllRead?: () => void;
23
46
  readonly inputRef?: RefObject<HTMLInputElement | null>;
24
47
  readonly onQueryChange: (value: string) => void;
25
48
  readonly onHoverItem: (id: string) => void;
@@ -33,7 +56,10 @@ export function CommandMenuView({
33
56
  groups,
34
57
  selectedId,
35
58
  labels,
36
- suppressSelectionAnimation,
59
+ toggleShortcut,
60
+ onNewSession,
61
+ newSessionShortcut,
62
+ onMarkAllRead,
37
63
  inputRef,
38
64
  onQueryChange,
39
65
  onHoverItem,
@@ -47,10 +73,28 @@ export function CommandMenuView({
47
73
  else rowRefs.current.delete(id);
48
74
  }, []);
49
75
 
50
- // 选中项滚动跟随。用 "nearest" 且不带 smooth:连续按方向键时平滑滚动会排队堆积。
76
+ // 鼠标悬停也会改选中项,但指针指着的行本来就在眼前,此时滚动只会让列表从指针下溜走。
77
+ const selectedByPointerRef = useRef(false);
78
+ const handleHoverItem = useCallback(
79
+ (id: string) => {
80
+ // mousemove 会在同一行上反复触发;选中项没变就不会有滚动副作用,别留下标记吞掉下一次键盘跟随。
81
+ if (id !== selectedId) selectedByPointerRef.current = true;
82
+ onHoverItem(id);
83
+ },
84
+ [onHoverItem, selectedId],
85
+ );
86
+
87
+ // 键盘选中项滚动跟随。用 "nearest" 且不带 smooth:连续按方向键时平滑滚动会排队堆积。
88
+ // 留白靠列表的 scroll-padding(见下方 className):底部要越过渐隐区和浮动按钮组再多留一行,
89
+ // 选中行才不会沉到按钮后面,往下按时也总能看到下一行是什么;顶部同样多留一行。
90
+ // 不用 "center":那样每按一下整张列表都要挪动,眼睛跟不住。
51
91
  // 可选链到方法本身:jsdom 与部分老 webview 没有实现 scrollIntoView,不能让它把渲染打断。
52
92
  useEffect(() => {
53
93
  if (!open || !selectedId) return;
94
+ if (selectedByPointerRef.current) {
95
+ selectedByPointerRef.current = false;
96
+ return;
97
+ }
54
98
  rowRefs.current.get(selectedId)?.scrollIntoView?.({ block: "nearest" });
55
99
  }, [open, selectedId]);
56
100
 
@@ -72,6 +116,7 @@ export function CommandMenuView({
72
116
  onChange={onQueryChange}
73
117
  // 打开后的聚焦由宿主在 open 变化时负责(见 desktop CommandMenu)。
74
118
  autoFocus={false}
119
+ trailing={toggleShortcut ? <VettaKbd keys={toggleShortcut} size="sm" variant="flat" /> : undefined}
75
120
  inputProps={{
76
121
  role: "combobox",
77
122
  "aria-expanded": hasResults,
@@ -80,19 +125,15 @@ export function CommandMenuView({
80
125
  }}
81
126
  />
82
127
  }
83
- footer={
84
- <SplashFooter>
85
- <span>{labels.hintNavigate}</span>
86
- <span>{labels.hintSelect}</span>
87
- <span className="ml-auto">{labels.hintClose}</span>
88
- </SplashFooter>
89
- }
90
128
  >
129
+ <div className="relative flex min-h-0 flex-col">
91
130
  <div
92
131
  id="command-menu-list"
93
132
  role="listbox"
94
133
  aria-label={labels.title}
95
- className="min-h-0 max-h-[min(420px,56vh)] overflow-y-auto overscroll-contain px-1.5 py-1.5"
134
+ // 底部留出浮动按钮组的高度,最后一行滚到底时不会被它盖住;同一段高度做渐隐,
135
+ // 滚动中的内容在按钮后面淡出,而不是被按钮生硬地截断。
136
+ className="min-h-0 max-h-[min(460px,60vh)] overflow-y-auto overscroll-contain px-1.5 pt-1.5 pb-14 scroll-pt-10 scroll-pb-24 [mask-image:linear-gradient(to_bottom,black_calc(100%-56px),transparent)]"
96
137
  >
97
138
  {groups.map((group) => {
98
139
  if (group.items.length === 0 && !group.loading) return null;
@@ -106,9 +147,8 @@ export function CommandMenuView({
106
147
  key={item.id}
107
148
  item={item}
108
149
  active={item.id === selectedId}
109
- suppressSelectionAnimation={suppressSelectionAnimation}
110
150
  onActivate={onActivateItem}
111
- onHover={onHoverItem}
151
+ onHover={handleHoverItem}
112
152
  registerRef={registerRef}
113
153
  />
114
154
  ))}
@@ -138,6 +178,58 @@ export function CommandMenuView({
138
178
  </div>
139
179
  )}
140
180
  </div>
181
+ {/*
182
+ * 操作提示做成浮在列表底部的两组按钮(复用通用 ButtonGroup 的玻璃胶囊),既是提示也能点:
183
+ * 左边「新会话」(只有图标),右边「打开」作用于当前选中项、「关闭」等同 esc;左右对称。
184
+ * 上下选择只靠方向键,不占一个按钮。外层不接收指针,按钮之间的空隙仍能滚动 / 点到列表。
185
+ */}
186
+ <div className="pointer-events-none absolute inset-x-2.5 bottom-2.5 z-10 flex items-center justify-between gap-2">
187
+ {onNewSession ? (
188
+ // 只有图标的圆形按钮:胶囊里单个纯图标项正好是一颗与右侧按钮组等高的圆。
189
+ // 有跑完未看的会话时同组追加「全部已读」,胶囊随之拉长,不另起一组。
190
+ <ButtonGroup className={COMMAND_MENU_FLOATING_GROUP_CLASS}>
191
+ <ButtonGroupItem
192
+ onClick={onNewSession}
193
+ aria-label={labels.newSession}
194
+ title={newSessionShortcut ? `${labels.newSession} (${formatKbdTitle(newSessionShortcut)})` : labels.newSession}
195
+ icon={<span aria-hidden="true" className="icon-[solar--pen-new-square-linear] size-4" />}
196
+ />
197
+ {onMarkAllRead && labels.markAllRead ? (
198
+ <ButtonGroupItem
199
+ onClick={onMarkAllRead}
200
+ icon={<span aria-hidden="true" className="icon-[solar--check-read-linear] size-4" />}
201
+ label={labels.markAllRead}
202
+ />
203
+ ) : null}
204
+ </ButtonGroup>
205
+ ) : (
206
+ <span />
207
+ )}
208
+ <ButtonGroup className={COMMAND_MENU_FLOATING_GROUP_CLASS} aria-label={labels.actionsLabel}>
209
+ <ButtonGroupItem
210
+ disabled={!selectedId}
211
+ onClick={() => {
212
+ if (selectedId) onActivateItem(selectedId);
213
+ }}
214
+ label={
215
+ <span className="inline-flex items-center gap-2">
216
+ {labels.hintSelect}
217
+ <VettaKbd keys="enter" size="sm" variant="flat" />
218
+ </span>
219
+ }
220
+ />
221
+ <ButtonGroupItem
222
+ onClick={onClose}
223
+ label={
224
+ <span className="inline-flex items-center gap-2">
225
+ {labels.hintClose}
226
+ <VettaKbd keys="esc" size="sm" variant="flat" />
227
+ </span>
228
+ }
229
+ />
230
+ </ButtonGroup>
231
+ </div>
232
+ </div>
141
233
  </SplashPanel>
142
234
  );
143
235
  }