@vetta-org/theme-ui 0.1.1 → 0.2.0
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 +740 -20
- package/src/action-approval/AppearanceActionPickerView.tsx +2 -78
- package/src/action-approval/AppearanceApprovalDrawerView.tsx +2 -9
- package/src/action-approval/BatchTasksApprovalFrameView.tsx +4 -1
- package/src/action-approval/GenericActionApprovalView.tsx +2 -9
- package/src/action-approval/ManageActionApprovalFrameView.tsx +4 -1
- package/src/action-approval/NavigationOpenApprovalView.tsx +2 -9
- package/src/action-approval/SchedulerActionApprovalDialogView.tsx +3 -1
- package/src/action-approval/SchedulerEditApprovalDrawerView.tsx +3 -10
- package/src/action-approval/index.ts +0 -1
- package/src/activity/ActivityPanel.tsx +13 -10
- package/src/activity/ActivityPanelFrame.test.tsx +32 -0
- package/src/activity/ActivityPanelFrame.tsx +3 -2
- package/src/activity/BackgroundTasksTabPanelView.tsx +1 -1
- package/src/activity/BrowserPanelView.tsx +48 -49
- package/src/activity/CodePreview.tsx +15 -1
- package/src/activity/DebugTabPanelView.tsx +1 -1
- package/src/activity/MarkdownPreviewView.test.tsx +53 -0
- package/src/activity/MarkdownPreviewView.tsx +135 -62
- package/src/activity/PluginTabPickerView.tsx +5 -3
- package/src/activity/PortsTabPanelView.tsx +911 -0
- package/src/activity/ToolCallsSubTabView.tsx +1 -1
- package/src/activity/WorkflowTabPanelView.tsx +1 -1
- package/src/activity/index.ts +9 -0
- package/src/app/AppBackground.tsx +1 -1
- package/src/app/AppBootLoadingView.tsx +4 -2
- package/src/app-shell/DefaultWindowControls.tsx +1 -1
- package/src/app-shell/PageHeaderActionGroup.tsx +1 -1
- package/src/app-shell/PageHeaderContent.tsx +36 -7
- package/src/app-shell/PageHeaderFrame.tsx +15 -3
- package/src/app-shell/PageHeaderSidebarTrigger.tsx +1 -1
- package/src/app-shell/PageHeaderTitle.tsx +1 -1
- package/src/app-shell/WindowControlButton.tsx +1 -1
- package/src/app-shell/header-crowding.test.ts +62 -0
- package/src/app-shell/header-crowding.tsx +137 -0
- package/src/appearance/BackgroundImageFrame.tsx +1 -1
- package/src/appearance/CenterSliceImageFrame.tsx +1 -1
- package/src/appearance/CornerImageFrame.tsx +1 -1
- package/src/appearance/HorizontalSliceImageFrame.tsx +1 -1
- package/src/appearance/NineSliceImageFrame.tsx +1 -1
- package/src/appearance/ThemeSurface.tsx +1 -1
- package/src/batch-tasks/BatchProjectFoldersFieldView.tsx +2 -1
- package/src/batch-tasks/BatchTaskProjectActionsView.test.tsx +97 -0
- package/src/batch-tasks/BatchTaskProjectActionsView.tsx +45 -35
- package/src/batch-tasks/batchTaskUi.tsx +0 -29
- package/src/bottom-panel/BottomPanelView.test.tsx +43 -0
- package/src/bottom-panel/BottomPanelView.tsx +222 -0
- package/src/bottom-panel/index.ts +26 -0
- package/src/chat/AgentAvatarView.tsx +1 -1
- package/src/chat/AnnotationViews.tsx +107 -0
- package/src/chat/AskUserQuestionView.tsx +18 -11
- package/src/chat/AssistantMessageView.tsx +48 -13
- package/src/chat/AtPanelView.test.tsx +61 -0
- package/src/chat/AtPanelView.tsx +63 -38
- package/src/chat/BashTerminalCard.tsx +1 -2
- package/src/chat/ChatHeaderActionsView.tsx +74 -18
- package/src/chat/CompactionStepView.test.tsx +34 -0
- package/src/chat/CompactionStepView.tsx +85 -0
- package/src/chat/ContextRingView.test.tsx +81 -0
- package/src/chat/ContextRingView.tsx +78 -62
- package/src/chat/ExecutionModeSelectorView.tsx +20 -5
- package/src/chat/HeaderActionBarView.tsx +806 -0
- package/src/chat/HeaderActionOverflowMenu.tsx +128 -0
- package/src/chat/InlineModelPicker.test.tsx +81 -0
- package/src/chat/InlineModelPicker.tsx +201 -0
- package/src/chat/InlineTokenChip.tsx +2 -68
- package/src/chat/InputBarBackground.tsx +1 -1
- package/src/chat/InputBarPlaceholder.tsx +26 -3
- package/src/chat/LiveThinkingView.tsx +51 -37
- package/src/chat/MessageBoundaryViews.tsx +21 -0
- package/src/chat/MessageFeedContext.tsx +13 -5
- package/src/chat/MessageFeedLayoutView.tsx +29 -3
- package/src/chat/MessageFeedView.test.tsx +81 -0
- package/src/chat/MessageFeedView.tsx +72 -152
- package/src/chat/MessageInputView.tsx +6 -2
- package/src/chat/MessageLayoutView.tsx +1 -1
- package/src/chat/MessageSelectionContextMenuView.tsx +4 -1
- package/src/chat/MessageTimelineView.tsx +1 -1
- package/src/chat/MessageView.tsx +1 -1
- package/src/chat/MessageVisualView.tsx +1 -1
- package/src/chat/ModelConfiguration.tsx +283 -0
- package/src/chat/ModelSelectorTrigger.tsx +63 -0
- package/src/chat/ModelSelectorView.tsx +1037 -223
- package/src/chat/NewSession.ts +1 -37
- package/src/chat/NewSessionPicker.tsx +3 -2
- package/src/chat/ProjectSelectorView.tsx +3 -2
- package/src/chat/ReasoningStepSlider.tsx +61 -0
- package/src/chat/RemoteSessionBadgeView.tsx +24 -0
- package/src/chat/SkillPromptAreaView.tsx +5 -19
- package/src/chat/TeamMemberReplyCardView.test.tsx +33 -0
- package/src/chat/TeamMemberReplyCardView.tsx +133 -0
- package/src/chat/TextBlockView.tsx +7 -770
- package/src/chat/TodoProgress.tsx +25 -53
- package/src/chat/TodoStatusBarView.tsx +14 -5
- package/src/chat/UserMessageView.tsx +113 -33
- package/src/chat/header-action-narrow.test.ts +21 -0
- package/src/chat/header-action-narrow.ts +38 -0
- package/src/chat/index.ts +33 -27
- package/src/chat/markdown-link.ts +7 -279
- package/src/chat/message-feed-fade.css +80 -0
- package/src/chat/message-feed-fade.test.tsx +75 -0
- package/src/chat/send-button.css +4 -22
- package/src/chat/streaming-reveal.test.ts +218 -0
- package/src/chat/streaming-reveal.ts +13 -0
- package/src/file-explorer/ConfirmDeleteDialogView.tsx +2 -1
- package/src/file-explorer/FileContextMenuView.tsx +44 -11
- package/src/file-explorer/FileExplorerSettingsView.tsx +97 -0
- package/src/file-explorer/FileTreeCreateRow.tsx +1 -1
- package/src/file-explorer/FileTreeNodeView.tsx +59 -18
- package/src/file-explorer/FileTreeView.tsx +236 -129
- package/src/file-explorer/file-tree-dom.ts +23 -0
- package/src/file-explorer/file-tree-rows.test.ts +74 -0
- package/src/file-explorer/file-tree-rows.ts +168 -0
- package/src/file-explorer/index.ts +17 -0
- package/src/file-explorer/types.ts +3 -0
- package/src/file-explorer/useFileTreeMarqueeSelection.ts +24 -16
- package/src/file-preview/FilePreviewDialogView.tsx +2 -2
- package/src/file-preview/FilePreviewView.tsx +12 -2
- package/src/file-preview/ReadonlyCodeView.tsx +46 -0
- package/src/file-preview/TextFileEditorView.tsx +2 -1
- package/src/file-preview/syntax-tokens.css +1 -1
- package/src/image-assets.d.ts +4 -0
- package/src/index.ts +1 -0
- package/src/knowledge/KnowledgeHowItWorksDialogView.tsx +1 -1
- package/src/layout/AppFrame.tsx +3 -2
- package/src/layout/MainContentFrame.tsx +7 -2
- package/src/layout/ResizeHandle.tsx +68 -17
- package/src/layout/SidebarDock.tsx +75 -19
- package/src/layout/SidebarOverlay.tsx +1 -1
- package/src/layout/index.ts +1 -1
- package/src/layout/resize-handle-axis.test.ts +51 -0
- package/src/live-indicators.test.ts +43 -0
- package/src/markdown/CodeBlock.tsx +123 -0
- package/src/markdown/FileLinkBadge.tsx +77 -0
- package/src/markdown/InlineTokenChip.tsx +68 -0
- package/src/markdown/MarkdownContent.tsx +418 -0
- package/src/markdown/MarkdownImage.tsx +41 -0
- package/src/markdown/MathFormula.tsx +46 -0
- package/src/markdown/MermaidBlock.tsx +82 -0
- package/src/markdown/RichCodeBlock.tsx +127 -0
- package/src/markdown/SvgPreview.tsx +45 -0
- package/src/markdown/WebsiteIcon.tsx +94 -0
- package/src/markdown/builtin-renderers.tsx +43 -0
- package/src/markdown/definition.tsx +49 -0
- package/src/markdown/host.tsx +18 -0
- package/src/markdown/image-actions.ts +29 -0
- package/src/markdown/index.ts +12 -0
- package/src/markdown/inline-tokens.ts +187 -0
- package/src/markdown/markdown-link.ts +279 -0
- package/src/markdown/math-client.ts +116 -0
- package/src/markdown/math-render.ts +23 -0
- package/src/markdown/math-syntax.ts +80 -0
- package/src/markdown/math.worker.ts +16 -0
- package/src/markdown/nodes.ts +15 -0
- package/src/markdown/preview-policy.test.ts +31 -0
- package/src/markdown/preview-policy.ts +76 -0
- package/src/markdown/progressive-chunks.test.ts +43 -0
- package/src/markdown/progressive-chunks.ts +58 -0
- package/src/markdown/rich-labels.ts +55 -0
- package/src/markdown/rich-syntax.ts +93 -0
- package/src/markdown/stable-blocks.test.ts +90 -0
- package/src/markdown/stable-blocks.ts +124 -0
- package/src/markdown/streaming-reveal.ts +297 -0
- package/src/markdown/streaming.test.ts +57 -0
- package/src/markdown/streaming.ts +211 -0
- package/src/markdown/use-render-snapshot.ts +24 -0
- package/src/markdown/use-rich-visibility.ts +24 -0
- package/src/overlays/CommandMenuRow.tsx +77 -17
- package/src/overlays/CommandMenuView.tsx +163 -118
- package/src/overlays/ConfirmDialogView.tsx +25 -20
- package/src/overlays/DiagnosticsExportDialogView.tsx +236 -0
- package/src/overlays/MagpieHandoverDialogView.tsx +217 -0
- package/src/overlays/ReleaseNoteMarkdown.test.tsx +24 -0
- package/src/overlays/ReleaseNoteMarkdown.tsx +55 -0
- package/src/overlays/SplashOptionRow.tsx +46 -0
- package/src/overlays/SplashPanel.tsx +85 -0
- package/src/overlays/SplashParts.tsx +217 -0
- package/src/overlays/UpdateCheckerView.tsx +34 -18
- package/src/overlays/UpdateRestartDialogView.tsx +203 -53
- package/src/overlays/assets/diagnostics-banner.webp +0 -0
- package/src/overlays/command-menu-types.ts +15 -1
- package/src/overlays/command-menu.css +1 -20
- package/src/overlays/index.ts +26 -1
- package/src/plugin-ui/index.ts +10 -0
- package/src/project/ConversationTagDotsView.tsx +1 -1
- package/src/project/ConversationTagEditorDialogView.tsx +4 -1
- package/src/project/DefaultConversationSectionView.tsx +15 -24
- package/src/project/DefaultSessionListView.tsx +5 -31
- package/src/project/DefaultSessionRowView.tsx +114 -55
- package/src/project/ManageSessionsSplashView.tsx +439 -0
- package/src/project/NewProjectDialogView.tsx +3 -10
- package/src/project/ProjectContextMenuView.tsx +30 -139
- package/src/project/ProjectDetailPageView.test.tsx +140 -0
- package/src/project/ProjectDetailPageView.tsx +372 -165
- package/src/project/ProjectGroupView.tsx +1 -1
- package/src/project/ProjectRowView.tsx +29 -12
- package/src/project/ProjectSessionsView.tsx +25 -47
- package/src/project/QuickScrollOverlay.tsx +1 -1
- package/src/project/SessionContextMenuView.tsx +15 -7
- package/src/project/SessionRowMoreButton.tsx +50 -0
- package/src/project/SessionRowView.tsx +106 -63
- package/src/project/SessionTitleMarquee.tsx +54 -0
- package/src/project/SidebarProjectDisclosure.tsx +60 -0
- package/src/project/SidebarProjectsSectionView.tsx +6 -1
- package/src/project/index.ts +12 -0
- package/src/project/session-row-transition.ts +9 -0
- package/src/project/types.ts +4 -2
- package/src/project/useActiveSessionAutoScroll.ts +10 -4
- package/src/registry.ts +0 -2
- package/src/scheduler/AutomationDetailPaneView.tsx +68 -0
- package/src/scheduler/AutomationPageView.tsx +118 -121
- package/src/scheduler/ExecutionHistoryView.tsx +7 -5
- package/src/scheduler/TaskListView.tsx +52 -201
- package/src/scheduler/index.ts +7 -12
- package/src/settings/AppshotSettingsView.tsx +0 -1
- package/src/settings/ArchivedProjectsSettingsView.tsx +122 -1
- package/src/settings/BuiltinMcpSectionView.tsx +1 -1
- package/src/settings/EnvironmentGitRowView.tsx +156 -0
- package/src/settings/EnvironmentSettingsView.tsx +25 -3
- package/src/settings/GeneralSettingsView.tsx +18 -24
- package/src/settings/ImChannelGuideDialogView.tsx +2 -2
- package/src/settings/ImFeishuDialogView.tsx +1 -1
- package/src/settings/ImLegacyImportBannerView.tsx +1 -1
- package/src/settings/ImLogDrawerView.tsx +2 -1
- package/src/settings/JsonConfigInputView.tsx +171 -0
- package/src/settings/LauncherSettingsView.test.tsx +95 -0
- package/src/settings/LauncherSettingsView.tsx +273 -0
- package/src/settings/ModelsFetchedModelsDrawerView.tsx +292 -0
- package/src/settings/ModelsProvidersSectionView.tsx +26 -23
- package/src/settings/MotionSelect.tsx +9 -7
- package/src/settings/NotificationSettingsView.tsx +79 -0
- package/src/settings/PermissionsSettingsView.tsx +3 -7
- 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/PresetProviderModelsListView.tsx +141 -24
- package/src/settings/PresetProviderRowView.tsx +147 -185
- package/src/settings/ProxySettingsSectionView.tsx +182 -0
- package/src/settings/QrBindDialogView.tsx +1 -1
- package/src/settings/RemoteMcpSectionView.tsx +1 -1
- package/src/settings/SettingChrome.tsx +2 -2
- package/src/settings/SettingsAiAssistButtonView.tsx +9 -119
- package/src/settings/SettingsFormFields.tsx +4 -7
- package/src/settings/SettingsSidebarView.tsx +64 -3
- package/src/settings/ShortcutRecorderView.test.tsx +108 -0
- package/src/settings/ShortcutRecorderView.tsx +15 -9
- package/src/settings/ShortcutsSettingsView.tsx +1 -5
- package/src/settings/SpaceEditorDialogView.tsx +158 -0
- package/src/settings/SpacesSettingsView.tsx +150 -0
- package/src/settings/WebhookEndpointListView.tsx +4 -5
- package/src/settings/assets/space-editor-illustration.webp +0 -0
- package/src/settings/index.ts +59 -68
- package/src/shared/ActivityStatusDot.tsx +69 -0
- package/src/shared/AvatarStackView.tsx +13 -13
- package/src/shared/BotAvatar.tsx +11 -9
- package/src/shared/CodeBlockCopyButton.tsx +1 -1
- package/src/shared/ContextMenuView.tsx +4 -11
- package/src/shared/MarkdownTable.tsx +2 -2
- package/src/shared/SegmentedControl.test.tsx +68 -0
- package/src/shared/SegmentedControl.tsx +10 -2
- package/src/shared/SyntaxHighlightedCode.tsx +0 -0
- package/src/shared/TabBar.outline.test.tsx +59 -0
- package/src/shared/TabBar.tsx +23 -18
- package/src/shared/VettaKbd.test.tsx +52 -0
- package/src/shared/VettaKbd.tsx +100 -0
- package/src/shared/connected-tab-outline.test.ts +2 -2
- package/src/shared/connected-tab-outline.ts +2 -1
- package/src/shared/index.ts +7 -0
- package/src/shared/kbd-keys.test.ts +61 -0
- package/src/shared/kbd-keys.ts +253 -0
- package/src/shared/platform.ts +9 -0
- package/src/shared/provider-icon/icons.ts +4 -2
- package/src/shared/provider-icon/index.tsx +1 -1
- package/src/shared/provider-icon/magpie.svg +1 -0
- package/src/sidebar/AddProjectMenuTriggerView.tsx +33 -24
- package/src/sidebar/DefaultSidebar.tsx +3 -1
- package/src/sidebar/MessageCenterDialogView.tsx +3 -2
- package/src/sidebar/MessageCenterEmptyState.tsx +1 -1
- package/src/sidebar/MessageCenterTabs.tsx +1 -1
- package/src/sidebar/MessageCenterToolbarButton.tsx +1 -1
- package/src/sidebar/MessageCenterTriggerView.tsx +2 -2
- package/src/sidebar/ProjectsPanelEmptyState.tsx +26 -7
- package/src/sidebar/SessionStatusIcon.tsx +16 -1
- package/src/sidebar/SettingsMenuThemeSection.tsx +1 -1
- package/src/sidebar/SettingsMenuTriggerView.test.tsx +42 -0
- package/src/sidebar/SettingsMenuTriggerView.tsx +29 -50
- package/src/sidebar/ShowMoreSessionsButton.tsx +1 -1
- package/src/sidebar/SidebarFilterSelectView.tsx +8 -16
- package/src/sidebar/SidebarNavBadgeView.tsx +1 -1
- package/src/sidebar/SidebarNavIcon.tsx +1 -1
- package/src/sidebar/SidebarNavItemButton.tsx +1 -1
- package/src/sidebar/SidebarNavMorePanel.tsx +19 -7
- package/src/sidebar/SidebarNavigation.tsx +24 -15
- package/src/sidebar/SidebarPanel.tsx +11 -2
- package/src/sidebar/SidebarSectionActionButton.test.tsx +91 -0
- package/src/sidebar/SidebarSectionActionButton.tsx +52 -0
- package/src/sidebar/SidebarSectionTriggerLabel.tsx +20 -0
- package/src/sidebar/SidebarTopBar.tsx +10 -7
- package/src/sidebar/WaitingPulseBadge.tsx +19 -0
- package/src/sidebar/index.ts +1 -16
- package/src/skills/index.ts +0 -19
- package/src/skills/skill-icon.tsx +4 -8
- package/src/styles.css +26 -6
- package/src/chat/DefaultSceneCarousel.tsx +0 -113
- package/src/chat/SceneCard.tsx +0 -138
- package/src/scheduler/HistoryDrawerView.tsx +0 -149
- package/src/scheduler/TaskFormDialogView.tsx +0 -60
- package/src/settings/AchievementNavigationButtonView.tsx +0 -90
- package/src/settings/AchievementPromotionDialogView.tsx +0 -91
- package/src/settings/AchievementSettingsView.tsx +0 -44
- package/src/settings/PetBubbleStylePreviewView.tsx +0 -44
- package/src/settings/QuickPanelSettingsSectionView.tsx +0 -66
- package/src/settings/SubscriptionActionsView.tsx +0 -63
- package/src/settings/SubscriptionCardsView.tsx +0 -212
- package/src/settings/TeamDetailView.tsx +0 -148
- package/src/settings/TeamDialogsView.tsx +0 -151
- package/src/settings/TeamListView.tsx +0 -57
- package/src/settings/TeamSettingsView.tsx +0 -51
- package/src/settings/TokenActivityChartView.tsx +0 -286
- package/src/settings/UsageStatsView.tsx +0 -101
- 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
- package/src/settings/shouldCloseEmptyApiKeyEditor.test.ts +0 -135
- package/src/settings/shouldCloseEmptyApiKeyEditor.ts +0 -40
- package/src/settings/token-activity.test.ts +0 -195
- package/src/settings/token-activity.ts +0 -320
- package/src/sidebar/AddProjectMenuItem.tsx +0 -21
- package/src/sidebar/AddProjectMenuPopoverView.tsx +0 -52
- package/src/sidebar/NotificationMessageListView.tsx +0 -136
- package/src/sidebar/SettingsMenuAccountSection.tsx +0 -32
- package/src/sidebar/SettingsMenuQuotaSection.tsx +0 -45
- package/src/skills/SceneCardView.tsx +0 -194
- package/src/skills/SkillCardView.tsx +0 -186
- package/src/skills/SkillDetailDialogView.tsx +0 -138
- package/src/skills/SkillTagGroupView.tsx +0 -56
- package/src/skills/SkillToggleSwitch.tsx +0 -31
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import { Button, Switch } from "@vetta-org/ui";
|
|
3
|
+
import { MotionSelect } from "./MotionSelect";
|
|
4
|
+
import { SettingRow, SettingSection, type SettingSectionMeta } from "./SettingChrome";
|
|
5
|
+
|
|
6
|
+
export type NotificationScopeView = "background-only" | "away-from-session" | "always";
|
|
7
|
+
|
|
8
|
+
export interface NotificationSettingsViewLabels {
|
|
9
|
+
systemNotifications: string;
|
|
10
|
+
systemNotificationsDescription: string;
|
|
11
|
+
soundNotifications: string;
|
|
12
|
+
soundNotificationsDescription: string;
|
|
13
|
+
soundTiming: string;
|
|
14
|
+
preview: string;
|
|
15
|
+
previewAction?: string;
|
|
16
|
+
scopes: Record<NotificationScopeView, string>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface NotificationSettingsViewProps {
|
|
20
|
+
section: SettingSectionMeta;
|
|
21
|
+
sectionTitle: string;
|
|
22
|
+
labels: NotificationSettingsViewLabels;
|
|
23
|
+
notificationsEnabled: boolean;
|
|
24
|
+
soundEnabled: boolean;
|
|
25
|
+
soundScope: NotificationScopeView;
|
|
26
|
+
onNotificationsEnabledChange: (enabled: boolean) => void;
|
|
27
|
+
onSoundEnabledChange: (enabled: boolean) => void;
|
|
28
|
+
onSoundScopeChange: (scope: NotificationScopeView) => void;
|
|
29
|
+
onPreview: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function NotificationSettingsView({
|
|
33
|
+
section,
|
|
34
|
+
sectionTitle,
|
|
35
|
+
labels,
|
|
36
|
+
notificationsEnabled,
|
|
37
|
+
soundEnabled,
|
|
38
|
+
soundScope,
|
|
39
|
+
onNotificationsEnabledChange,
|
|
40
|
+
onSoundEnabledChange,
|
|
41
|
+
onSoundScopeChange,
|
|
42
|
+
onPreview,
|
|
43
|
+
}: NotificationSettingsViewProps): JSX.Element {
|
|
44
|
+
const scopeOptions = (Object.keys(labels.scopes) as NotificationScopeView[]).map((scope) => ({
|
|
45
|
+
value: scope,
|
|
46
|
+
label: labels.scopes[scope],
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<SettingSection title={sectionTitle} section={section}>
|
|
51
|
+
<SettingRow title={labels.systemNotifications} description={labels.systemNotificationsDescription}>
|
|
52
|
+
<Switch checked={notificationsEnabled} onCheckedChange={onNotificationsEnabledChange} />
|
|
53
|
+
</SettingRow>
|
|
54
|
+
<SettingRow
|
|
55
|
+
title={labels.soundNotifications}
|
|
56
|
+
description={labels.soundNotificationsDescription}
|
|
57
|
+
border={soundEnabled}
|
|
58
|
+
>
|
|
59
|
+
<Switch checked={soundEnabled} onCheckedChange={onSoundEnabledChange} />
|
|
60
|
+
</SettingRow>
|
|
61
|
+
{soundEnabled ? (
|
|
62
|
+
<>
|
|
63
|
+
<SettingRow title={labels.soundTiming}>
|
|
64
|
+
<MotionSelect
|
|
65
|
+
value={soundScope}
|
|
66
|
+
onValueChange={(scope) => onSoundScopeChange(scope as NotificationScopeView)}
|
|
67
|
+
options={scopeOptions}
|
|
68
|
+
/>
|
|
69
|
+
</SettingRow>
|
|
70
|
+
<SettingRow title={labels.preview} border={false}>
|
|
71
|
+
<Button variant="field" onClick={onPreview}>
|
|
72
|
+
{labels.previewAction ?? labels.preview}
|
|
73
|
+
</Button>
|
|
74
|
+
</SettingRow>
|
|
75
|
+
</>
|
|
76
|
+
) : null}
|
|
77
|
+
</SettingSection>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JSX } from "react";
|
|
2
|
-
import { cn } from "@vetta-org/ui";
|
|
2
|
+
import { Button, cn } from "@vetta-org/ui";
|
|
3
3
|
import { SettingRow, SettingSection, type SettingSectionMeta } from "./SettingChrome";
|
|
4
4
|
|
|
5
5
|
export type PermissionStatusView = "granted" | "denied" | "unknown";
|
|
@@ -88,14 +88,10 @@ export function PermissionsSettingsView({
|
|
|
88
88
|
>
|
|
89
89
|
<div className="flex items-center gap-3">
|
|
90
90
|
{!item.hideStatus && <StatusBadge status={item.status} labels={labels.status} />}
|
|
91
|
-
<
|
|
92
|
-
type="button"
|
|
93
|
-
onClick={() => onOpen(item.id)}
|
|
94
|
-
className="flex items-center gap-1.5 rounded-lg border border-input bg-secondary px-3 py-1.5 text-[12px] text-foreground transition-colors hover:bg-accent"
|
|
95
|
-
>
|
|
91
|
+
<Button variant="field" onClick={() => onOpen(item.id)}>
|
|
96
92
|
<span className="icon-[mdi--open-in-new] h-3.5 w-3.5 text-muted-foreground" />
|
|
97
93
|
{buttonLabel}
|
|
98
|
-
</
|
|
94
|
+
</Button>
|
|
99
95
|
</div>
|
|
100
96
|
</SettingRow>
|
|
101
97
|
);
|
|
@@ -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
|
+
});
|