@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
@@ -0,0 +1,163 @@
1
+ // @vitest-environment jsdom
2
+
3
+ import { act } from "react";
4
+ import { createRoot, type Root } from "react-dom/client";
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
+ import { PetActionGalleryView, type PetActionGalleryViewProps } from "./PetActionGalleryView";
7
+
8
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
9
+
10
+ const mounted: Array<{ root: Root; container: HTMLDivElement }> = [];
11
+ let play: ReturnType<typeof vi.fn>;
12
+ let pause: ReturnType<typeof vi.fn>;
13
+ let reducedMotion = false;
14
+
15
+ beforeEach(() => {
16
+ vi.useFakeTimers();
17
+ reducedMotion = false;
18
+ // Playback state lands on the element itself, so tests read what the preview is doing.
19
+ play = vi.fn(function (this: HTMLMediaElement) {
20
+ this.dataset.playback = "playing";
21
+ this.dataset.everPlayed = "true";
22
+ return Promise.resolve();
23
+ });
24
+ pause = vi.fn(function (this: HTMLMediaElement) {
25
+ this.dataset.playback = "paused";
26
+ });
27
+ Object.defineProperty(HTMLMediaElement.prototype, "play", { configurable: true, value: play });
28
+ Object.defineProperty(HTMLMediaElement.prototype, "pause", { configurable: true, value: pause });
29
+ Object.defineProperty(window, "matchMedia", {
30
+ configurable: true,
31
+ value: (query: string) => ({ matches: reducedMotion && query.includes("reduce"), media: query }),
32
+ });
33
+ });
34
+
35
+ afterEach(() => {
36
+ for (const { root, container } of mounted.splice(0)) {
37
+ act(() => root.unmount());
38
+ container.remove();
39
+ }
40
+ vi.useRealTimers();
41
+ });
42
+
43
+ const labels: PetActionGalleryViewProps["labels"] = {
44
+ play: "播放",
45
+ played: "已开始",
46
+ previewHint: "动作",
47
+ needShowPet: "先打开显示桌宠",
48
+ videoMissing: "缺少动画素材",
49
+ };
50
+
51
+ const groups: PetActionGalleryViewProps["groups"] = [
52
+ {
53
+ id: "resting",
54
+ label: "休息",
55
+ actions: [
56
+ { id: "sleep", label: "睡觉", description: "趴着睡", videoUrl: "vetta-media://sleep.webm" },
57
+ { id: "tea", label: "喝茶", description: "慢慢喝", videoUrl: "vetta-media://tea.webm" },
58
+ ],
59
+ },
60
+ {
61
+ id: "feedback",
62
+ label: "反馈",
63
+ actions: [{ id: "bye", label: "再见", description: "挥手", videoUrl: undefined }],
64
+ },
65
+ ];
66
+
67
+ function renderGallery(overrides: Partial<PetActionGalleryViewProps> = {}) {
68
+ // Actions handed to the desktop pet, in order.
69
+ const played: string[] = [];
70
+ const onPlay = vi.fn((actionId: string) => {
71
+ played.push(actionId);
72
+ });
73
+ const container = document.createElement("div");
74
+ document.body.append(container);
75
+ const root = createRoot(container);
76
+ mounted.push({ root, container });
77
+ act(() => {
78
+ root.render(
79
+ <PetActionGalleryView groups={groups} labels={labels} playDisabled={false} onPlay={onPlay} {...overrides} />,
80
+ );
81
+ });
82
+ const chip = (name: string) =>
83
+ [...container.querySelectorAll<HTMLButtonElement>("button[aria-pressed]")].find(
84
+ (button) => button.textContent === name,
85
+ ) as HTMLButtonElement;
86
+ const playButton = () => container.querySelector<HTMLButtonElement>('button[aria-label^="播放"]') as HTMLButtonElement;
87
+ const video = () => container.querySelector("video");
88
+ return { container, played, chip, playButton, video };
89
+ }
90
+
91
+ describe("桌宠动作画廊", () => {
92
+ it("每个动作是一个紧凑标签,整页只有一个预览视频和一个播放按钮,打开时不播放", () => {
93
+ const { container, video } = renderGallery();
94
+
95
+ expect(container.querySelectorAll("button[aria-pressed]")).toHaveLength(3);
96
+ expect(container.querySelectorAll('button[aria-label^="播放"]')).toHaveLength(1);
97
+ expect(container.querySelectorAll("video")).toHaveLength(1);
98
+ expect(video()?.getAttribute("src")).toBe("vetta-media://sleep.webm");
99
+ expect(video()?.dataset.everPlayed).toBeUndefined();
100
+ });
101
+
102
+ it("聚焦某个动作时预览它并显示说明,焦点离开画廊后暂停", () => {
103
+ const { container, chip, video } = renderGallery();
104
+
105
+ act(() => chip("喝茶").focus());
106
+ act(() => vi.advanceTimersByTime(200));
107
+
108
+ expect(video()?.getAttribute("src")).toBe("vetta-media://tea.webm");
109
+ expect(container.textContent).toContain("慢慢喝");
110
+ expect(video()?.dataset.playback).toBe("playing");
111
+
112
+ act(() => chip("喝茶").blur());
113
+ expect(video()?.dataset.playback).toBe("paused");
114
+ });
115
+
116
+ it("只是划过不选中时,播放的仍是已选动作,预览回到它", () => {
117
+ const { chip, playButton, video, played } = renderGallery();
118
+
119
+ act(() => chip("喝茶").focus());
120
+ act(() => vi.advanceTimersByTime(200));
121
+ act(() => chip("喝茶").blur());
122
+ act(() => vi.advanceTimersByTime(200));
123
+
124
+ expect(video()?.getAttribute("src")).toBe("vetta-media://sleep.webm");
125
+ act(() => playButton().click());
126
+ expect(played).toEqual(["sleep"]);
127
+ });
128
+
129
+ it("点选动作后播放交给桌宠,并短暂显示已开始", () => {
130
+ const { chip, playButton, played } = renderGallery();
131
+
132
+ act(() => chip("喝茶").click());
133
+ expect(chip("喝茶").getAttribute("aria-pressed")).toBe("true");
134
+
135
+ act(() => playButton().click());
136
+ expect(played).toEqual(["tea"]);
137
+ expect(playButton().textContent).toContain("已开始");
138
+ act(() => vi.advanceTimersByTime(2000));
139
+ expect(playButton().textContent).toContain("播放");
140
+ });
141
+
142
+ it("系统开启减少动态效果时只切换画面,不播放", () => {
143
+ reducedMotion = true;
144
+ const { chip, video } = renderGallery();
145
+
146
+ act(() => chip("喝茶").click());
147
+
148
+ expect(video()?.getAttribute("src")).toBe("vetta-media://tea.webm");
149
+ expect(video()?.dataset.everPlayed).toBeUndefined();
150
+ });
151
+
152
+ it("桌宠没显示或选中的动作缺素材时不能播放", () => {
153
+ const hidden = renderGallery({ playDisabled: true });
154
+ expect(hidden.playButton().disabled).toBe(true);
155
+ expect(hidden.container.textContent).toContain("先打开显示桌宠");
156
+
157
+ const shown = renderGallery();
158
+ expect(shown.playButton().disabled).toBe(false);
159
+ act(() => shown.chip("再见").click());
160
+ expect(shown.playButton().disabled).toBe(true);
161
+ expect(shown.container.textContent).toContain("缺少动画素材");
162
+ });
163
+ });
@@ -0,0 +1,216 @@
1
+ import type { FocusEvent, JSX } from "react";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { Button, cn } from "@vetta-org/ui";
4
+
5
+ export interface PetActionView {
6
+ readonly id: string;
7
+ readonly label: string;
8
+ readonly description: string;
9
+ /** 缺素材时为空,预览区显示占位文字。 */
10
+ readonly videoUrl?: string;
11
+ }
12
+
13
+ export interface PetActionGroupView {
14
+ readonly id: string;
15
+ readonly label: string;
16
+ readonly actions: readonly PetActionView[];
17
+ }
18
+
19
+ export interface PetActionGalleryViewLabels {
20
+ readonly play: string;
21
+ readonly played: string;
22
+ readonly previewHint: string;
23
+ readonly needShowPet: string;
24
+ readonly videoMissing: string;
25
+ }
26
+
27
+ export interface PetActionGalleryViewProps {
28
+ readonly groups: readonly PetActionGroupView[];
29
+ readonly labels: PetActionGalleryViewLabels;
30
+ /** 桌宠没显示时不能播放,只能预览。 */
31
+ readonly playDisabled: boolean;
32
+ readonly onPlay: (actionId: string) => void;
33
+ }
34
+
35
+ /** 悬停切换预览前的等待时间:鼠标快速划过多个动作时不逐个加载视频。 */
36
+ const PREVIEW_SWITCH_DELAY_MS = 90;
37
+ const PLAYED_FEEDBACK_MS = 1600;
38
+
39
+ function prefersReducedMotion(): boolean {
40
+ return typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
41
+ }
42
+
43
+ /**
44
+ * 预览区 + 当前动作说明 + 紧凑的动作标签。
45
+ *
46
+ * 动作再多也只是多一行标签,右侧高度和预览区基本一致。
47
+ * 性能约束:整页只有一个 `<video>`,平时停在当前帧,只在指针位于画廊内或键盘聚焦动作时播放,
48
+ * 离开即暂停;系统开启「减少动态效果」时不播放。
49
+ */
50
+ export function PetActionGalleryView({
51
+ groups,
52
+ labels,
53
+ playDisabled,
54
+ onPlay,
55
+ }: PetActionGalleryViewProps): JSX.Element {
56
+ const entries = groups.flatMap((group) => group.actions.map((action) => ({ action, groupLabel: group.label })));
57
+ const [selectedId, setSelectedId] = useState(
58
+ () => (entries.find((entry) => entry.action.videoUrl) ?? entries[0])?.action.id,
59
+ );
60
+ const [hoverId, setHoverId] = useState<string>();
61
+ const [active, setActive] = useState(false);
62
+ const [playedId, setPlayedId] = useState<string>();
63
+ const videoRef = useRef<HTMLVideoElement>(null);
64
+ const switchTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
65
+ const playedTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
66
+
67
+ const shownId = hoverId ?? selectedId;
68
+ const shown = entries.find((entry) => entry.action.id === shownId) ?? entries[0];
69
+ const selected = entries.find((entry) => entry.action.id === selectedId) ?? entries[0];
70
+ const previewUrl = shown?.action.videoUrl;
71
+
72
+ useEffect(() => {
73
+ const video = videoRef.current;
74
+ if (!video) return;
75
+ if (active && !prefersReducedMotion()) {
76
+ void video.play().catch(() => undefined);
77
+ } else {
78
+ video.pause();
79
+ }
80
+ }, [active, previewUrl]);
81
+
82
+ useEffect(
83
+ () => () => {
84
+ clearTimeout(switchTimerRef.current);
85
+ clearTimeout(playedTimerRef.current);
86
+ },
87
+ [],
88
+ );
89
+
90
+ const schedulePreview = (actionId: string | undefined): void => {
91
+ clearTimeout(switchTimerRef.current);
92
+ switchTimerRef.current = setTimeout(() => setHoverId(actionId), PREVIEW_SWITCH_DELAY_MS);
93
+ };
94
+
95
+ const deactivate = (): void => {
96
+ clearTimeout(switchTimerRef.current);
97
+ setHoverId(undefined);
98
+ setActive(false);
99
+ };
100
+
101
+ const handleBlur = (event: FocusEvent<HTMLDivElement>): void => {
102
+ if (event.currentTarget.contains(event.relatedTarget as Node | null)) return;
103
+ deactivate();
104
+ };
105
+
106
+ const select = (actionId: string): void => {
107
+ clearTimeout(switchTimerRef.current);
108
+ setSelectedId(actionId);
109
+ setHoverId(undefined);
110
+ setActive(true);
111
+ };
112
+
113
+ const play = (): void => {
114
+ if (!selected) return;
115
+ onPlay(selected.action.id);
116
+ setPlayedId(selected.action.id);
117
+ clearTimeout(playedTimerRef.current);
118
+ playedTimerRef.current = setTimeout(() => setPlayedId(undefined), PLAYED_FEEDBACK_MS);
119
+ };
120
+
121
+ const justPlayed = playedId !== undefined && playedId === selected?.action.id;
122
+
123
+ return (
124
+ <div
125
+ className="grid grid-cols-[148px_minmax(0,1fr)] gap-4 p-4"
126
+ onPointerEnter={() => setActive(true)}
127
+ onPointerLeave={deactivate}
128
+ onFocus={() => setActive(true)}
129
+ onBlur={handleBlur}
130
+ >
131
+ <div
132
+ className="flex aspect-square items-center justify-center overflow-hidden rounded-lg bg-muted/60"
133
+ data-testid="pet-action-preview"
134
+ >
135
+ {previewUrl ? (
136
+ <video
137
+ ref={videoRef}
138
+ src={previewUrl}
139
+ className="size-full object-contain"
140
+ muted
141
+ loop
142
+ playsInline
143
+ preload="auto"
144
+ disablePictureInPicture
145
+ aria-label={shown?.action.label}
146
+ />
147
+ ) : (
148
+ <div className="px-3 text-center text-[12px] text-muted-foreground">{labels.videoMissing}</div>
149
+ )}
150
+ </div>
151
+
152
+ <div className="flex min-w-0 flex-col gap-3">
153
+ <div className="flex min-h-[60px] items-start gap-3">
154
+ <div className="min-w-0 flex-1">
155
+ <div className="flex items-center gap-2">
156
+ <span className="truncate text-[14px] font-semibold text-foreground">{shown?.action.label}</span>
157
+ {shown && (
158
+ <span className="shrink-0 rounded-md bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground">
159
+ {shown.groupLabel}
160
+ </span>
161
+ )}
162
+ </div>
163
+ <p className="mt-1 line-clamp-2 text-[12px] text-muted-foreground">
164
+ {playDisabled ? labels.needShowPet : shown?.action.description}
165
+ </p>
166
+ </div>
167
+ <Button
168
+ type="button"
169
+ variant="field"
170
+ size="sm"
171
+ className="shrink-0"
172
+ disabled={playDisabled || !selected?.action.videoUrl}
173
+ aria-label={selected ? `${labels.play} ${selected.action.label}` : labels.play}
174
+ onClick={play}
175
+ >
176
+ <span
177
+ aria-hidden
178
+ className={cn(
179
+ "size-3.5",
180
+ justPlayed ? "icon-[solar--check-circle-linear]" : "icon-[solar--play-linear]",
181
+ )}
182
+ />
183
+ {justPlayed ? labels.played : labels.play}
184
+ </Button>
185
+ </div>
186
+
187
+ <div className="flex flex-wrap gap-1.5" role="group" aria-label={labels.previewHint}>
188
+ {entries.map(({ action }) => {
189
+ const isSelected = action.id === selectedId;
190
+ return (
191
+ <button
192
+ key={action.id}
193
+ type="button"
194
+ aria-pressed={isSelected}
195
+ className={cn(
196
+ "h-7 rounded-lg px-2.5 text-[12px] transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring/50",
197
+ isSelected
198
+ ? "bg-foreground text-background"
199
+ : "bg-muted text-foreground hover:bg-accent",
200
+ !action.videoUrl && "text-muted-foreground",
201
+ )}
202
+ onPointerEnter={() => schedulePreview(action.id)}
203
+ onPointerLeave={() => schedulePreview(undefined)}
204
+ onFocus={() => schedulePreview(action.id)}
205
+ onBlur={() => schedulePreview(undefined)}
206
+ onClick={() => select(action.id)}
207
+ >
208
+ {action.label}
209
+ </button>
210
+ );
211
+ })}
212
+ </div>
213
+ </div>
214
+ </div>
215
+ );
216
+ }
@@ -0,0 +1,117 @@
1
+ // @vitest-environment jsdom
2
+
3
+ import { act } from "react";
4
+ import { createRoot, type Root } from "react-dom/client";
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+ import { PetSettingsView, type PetSettingsViewProps } from "./PetSettingsView";
7
+
8
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
9
+
10
+ const mounted: Array<{ root: Root; container: HTMLDivElement }> = [];
11
+
12
+ afterEach(() => {
13
+ for (const { root, container } of mounted.splice(0)) {
14
+ act(() => root.unmount());
15
+ container.remove();
16
+ }
17
+ });
18
+
19
+ const section = (id: string) => ({ id });
20
+
21
+ function renderView(overrides: Partial<PetSettingsViewProps> = {}) {
22
+ // Sizes the view committed, in order.
23
+ const committedSizes: number[] = [];
24
+ const onCommit = vi.fn((value: number) => {
25
+ committedSizes.push(value);
26
+ });
27
+ const onChangeAutoMode = vi.fn();
28
+ const props: PetSettingsViewProps = {
29
+ labels: {
30
+ pageTitle: "Vetta Vivi",
31
+ materialMissing: "",
32
+ decorationAvailable: "",
33
+ decorationMissing: "",
34
+ showPet: "显示桌宠",
35
+ showPetDescription: "",
36
+ alwaysOnTop: "保持在最前",
37
+ alwaysOnTopDescription: "",
38
+ decorationSectionDescription: "",
39
+ developerDescription: "",
40
+ debugFrame: "调试边框",
41
+ debugFrameDescription: "",
42
+ size: "大小",
43
+ sizeDescription: "",
44
+ autoMode: "自动切换动作",
45
+ autoModeDescription: "",
46
+ actionsSectionDescription: "",
47
+ sections: {
48
+ display: "显示与窗口",
49
+ behavior: "行为",
50
+ actions: "动作",
51
+ decoration: "装饰",
52
+ developer: "开发调试",
53
+ },
54
+ },
55
+ sections: {
56
+ display: section("pet-display"),
57
+ behavior: section("pet-behavior"),
58
+ actions: section("pet-actions"),
59
+ decoration: section("pet-decoration"),
60
+ developer: section("pet-developer"),
61
+ },
62
+ enabled: true,
63
+ autoMode: true,
64
+ alwaysOnTop: true,
65
+ debugFrame: false,
66
+ size: { value: 1, min: 0.4, max: 2.5, step: 0.05, onCommit },
67
+ actionGallery: <div>动作画廊</div>,
68
+ decorations: [],
69
+ showDecorationSection: false,
70
+ aiAssistSlot: null,
71
+ onChangeEnabled: vi.fn(),
72
+ onChangeAlwaysOnTop: vi.fn(),
73
+ onChangeAutoMode,
74
+ onChangeDebugFrame: vi.fn(),
75
+ ...overrides,
76
+ };
77
+ const container = document.createElement("div");
78
+ document.body.append(container);
79
+ const root = createRoot(container);
80
+ mounted.push({ root, container });
81
+ act(() => root.render(<PetSettingsView {...props} />));
82
+ return { container, committedSizes, onChangeAutoMode };
83
+ }
84
+
85
+ describe("Vetta Vivi 设置页", () => {
86
+ it("展示显示、行为、动作与开发调试分区", () => {
87
+ const { container } = renderView();
88
+
89
+ for (const title of ["显示与窗口", "行为", "动作", "开发调试"]) {
90
+ expect(container.textContent).toContain(title);
91
+ }
92
+ expect(container.textContent).toContain("动作画廊");
93
+ expect(container.textContent).toContain("100%");
94
+ expect(container.textContent).not.toContain("气泡样式");
95
+ expect(container.textContent).not.toContain("互动方式");
96
+ });
97
+
98
+ it("键盘调整大小时提交新的缩放值", () => {
99
+ const { container, committedSizes } = renderView();
100
+ const slider = container.querySelector<HTMLInputElement>('input[type="range"][aria-label="大小"]');
101
+
102
+ act(() => {
103
+ slider?.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true }));
104
+ });
105
+
106
+ expect(committedSizes).toHaveLength(1);
107
+ expect(committedSizes[0]).toBeCloseTo(1.05);
108
+ });
109
+
110
+ it("桌宠隐藏时大小与自动切换不可调", () => {
111
+ const { container } = renderView({ enabled: false });
112
+
113
+ expect(container.querySelector<HTMLInputElement>('input[aria-label="大小"]')?.disabled).toBe(true);
114
+ const autoModeSwitch = container.querySelector<HTMLButtonElement>('[data-setting-section-id="pet-behavior"] button');
115
+ expect(autoModeSwitch?.disabled).toBe(true);
116
+ });
117
+ });
@@ -1,5 +1,6 @@
1
1
  import type { JSX, ReactNode } from "react";
2
- import { Switch } from "@vetta-org/ui";
2
+ import { useState } from "react";
3
+ import { Slider, Switch } from "@vetta-org/ui";
3
4
  import { SettingRow, SettingSection, type SettingSectionMeta } from "./SettingChrome";
4
5
 
5
6
  export interface PetDecorationView {
@@ -9,13 +10,6 @@ export interface PetDecorationView {
9
10
  readonly url: string;
10
11
  }
11
12
 
12
- export interface PetBubbleStyleOptionView {
13
- readonly id: string;
14
- readonly label: string;
15
- readonly description: string;
16
- readonly decorUrl?: string;
17
- }
18
-
19
13
  export interface PetSettingsViewLabels {
20
14
  readonly pageTitle: string;
21
15
  readonly materialMissing: string;
@@ -26,51 +20,112 @@ export interface PetSettingsViewLabels {
26
20
  readonly alwaysOnTop: string;
27
21
  readonly alwaysOnTopDescription: string;
28
22
  readonly decorationSectionDescription: string;
29
- readonly bubbleSectionDescription: string;
30
23
  readonly developerDescription: string;
31
24
  readonly debugFrame: string;
32
25
  readonly debugFrameDescription: string;
26
+ readonly size: string;
27
+ readonly sizeDescription: string;
28
+ readonly autoMode: string;
29
+ readonly autoModeDescription: string;
30
+ readonly actionsSectionDescription: string;
33
31
  readonly sections: {
34
32
  readonly display: string;
33
+ readonly behavior: string;
34
+ readonly actions: string;
35
35
  readonly decoration: string;
36
- readonly bubble: string;
37
36
  readonly developer: string;
38
37
  };
39
38
  }
40
39
 
40
+ export interface PetSizeControlView {
41
+ readonly value: number;
42
+ readonly min: number;
43
+ readonly max: number;
44
+ readonly step: number;
45
+ /** 松手或键盘调整后触发;拖动过程只在本地预览数值。 */
46
+ readonly onCommit: (value: number) => void;
47
+ }
48
+
41
49
  export interface PetSettingsViewProps {
42
50
  readonly labels: PetSettingsViewLabels;
43
51
  readonly sections: {
44
52
  readonly display: SettingSectionMeta;
53
+ readonly behavior: SettingSectionMeta;
54
+ readonly actions: SettingSectionMeta;
45
55
  readonly decoration: SettingSectionMeta;
46
- readonly bubble: SettingSectionMeta;
47
56
  readonly developer: SettingSectionMeta;
48
57
  };
49
58
  readonly enabled: boolean;
59
+ readonly autoMode: boolean;
60
+ readonly size: PetSizeControlView;
61
+ /** 动作预览与播放,通常放 `PetActionGalleryView`。 */
62
+ readonly actionGallery: ReactNode;
50
63
  readonly alwaysOnTop: boolean;
51
64
  readonly debugFrame: boolean;
52
65
  readonly decorations: readonly PetDecorationView[];
53
66
  /** 是否展示「桌宠装饰」分区;组件与数据链路保留,默认 true。 */
54
67
  readonly showDecorationSection?: boolean;
55
68
  readonly aiAssistSlot: ReactNode;
56
- readonly bubbleGrid: ReactNode;
57
69
  readonly onChangeEnabled: (value: boolean) => void;
58
70
  readonly onChangeAlwaysOnTop: (value: boolean) => void;
71
+ readonly onChangeAutoMode: (value: boolean) => void;
59
72
  readonly onChangeDebugFrame: (value: boolean) => void;
60
73
  }
61
74
 
75
+ function formatPercent(value: number): string {
76
+ return `${Math.round(value * 100)}%`;
77
+ }
78
+
79
+ function PetSizeSlider({
80
+ size,
81
+ label,
82
+ disabled,
83
+ }: {
84
+ size: PetSizeControlView;
85
+ label: string;
86
+ disabled: boolean;
87
+ }): JSX.Element {
88
+ const [draft, setDraft] = useState<number>();
89
+ const shown = draft ?? size.value;
90
+ return (
91
+ <div className="flex w-56 items-center gap-3">
92
+ <Slider
93
+ className="flex-1"
94
+ value={[shown]}
95
+ min={size.min}
96
+ max={size.max}
97
+ step={size.step}
98
+ disabled={disabled}
99
+ aria-label={label}
100
+ aria-valuetext={formatPercent(shown)}
101
+ onValueChange={([next]) => setDraft(next)}
102
+ onValueCommit={([next]) => {
103
+ setDraft(undefined);
104
+ if (next !== undefined && next !== size.value) size.onCommit(next);
105
+ }}
106
+ />
107
+ <span className="w-10 shrink-0 text-right text-[12px] tabular-nums text-muted-foreground">
108
+ {formatPercent(shown)}
109
+ </span>
110
+ </div>
111
+ );
112
+ }
113
+
62
114
  export function PetSettingsView({
63
115
  labels,
64
116
  sections,
65
117
  enabled,
118
+ autoMode,
119
+ size,
120
+ actionGallery,
66
121
  alwaysOnTop,
67
122
  debugFrame,
68
123
  decorations,
69
124
  showDecorationSection = true,
70
125
  aiAssistSlot,
71
- bubbleGrid,
72
126
  onChangeEnabled,
73
127
  onChangeAlwaysOnTop,
128
+ onChangeAutoMode,
74
129
  onChangeDebugFrame,
75
130
  }: PetSettingsViewProps): JSX.Element {
76
131
  return (
@@ -84,13 +139,30 @@ export function PetSettingsView({
84
139
  <SettingRow title={labels.showPet} description={labels.showPetDescription}>
85
140
  <Switch checked={enabled} onCheckedChange={onChangeEnabled} />
86
141
  </SettingRow>
87
- <SettingRow title={labels.alwaysOnTop} description={labels.alwaysOnTopDescription} border={false}>
142
+ <SettingRow title={labels.alwaysOnTop} description={labels.alwaysOnTopDescription}>
88
143
  <Switch
89
144
  checked={alwaysOnTop}
90
145
  onCheckedChange={onChangeAlwaysOnTop}
91
146
  disabled={!enabled}
92
147
  />
93
148
  </SettingRow>
149
+ <SettingRow title={labels.size} description={labels.sizeDescription} border={false}>
150
+ <PetSizeSlider size={size} label={labels.size} disabled={!enabled} />
151
+ </SettingRow>
152
+ </SettingSection>
153
+
154
+ <SettingSection title={labels.sections.behavior} section={sections.behavior}>
155
+ <SettingRow title={labels.autoMode} description={labels.autoModeDescription} border={false}>
156
+ <Switch checked={autoMode} onCheckedChange={onChangeAutoMode} disabled={!enabled} />
157
+ </SettingRow>
158
+ </SettingSection>
159
+
160
+ <SettingSection
161
+ title={labels.sections.actions}
162
+ section={sections.actions}
163
+ description={labels.actionsSectionDescription}
164
+ >
165
+ {actionGallery}
94
166
  </SettingSection>
95
167
 
96
168
  {showDecorationSection && (
@@ -135,14 +207,6 @@ export function PetSettingsView({
135
207
  </SettingSection>
136
208
  )}
137
209
 
138
- <SettingSection
139
- title={labels.sections.bubble}
140
- section={sections.bubble}
141
- description={labels.bubbleSectionDescription}
142
- >
143
- {bubbleGrid}
144
- </SettingSection>
145
-
146
210
  <SettingSection
147
211
  title={labels.sections.developer}
148
212
  section={sections.developer}