@vetta-org/theme-ui 0.1.1 → 0.1.2

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 (301) hide show
  1. package/package.json +733 -5
  2. package/src/action-approval/AppearanceActionPickerView.tsx +2 -78
  3. package/src/action-approval/AppearanceApprovalDrawerView.tsx +2 -9
  4. package/src/action-approval/BatchTasksApprovalFrameView.tsx +4 -1
  5. package/src/action-approval/GenericActionApprovalView.tsx +2 -9
  6. package/src/action-approval/ManageActionApprovalFrameView.tsx +4 -1
  7. package/src/action-approval/NavigationOpenApprovalView.tsx +2 -9
  8. package/src/action-approval/SchedulerActionApprovalDialogView.tsx +3 -1
  9. package/src/action-approval/SchedulerEditApprovalDrawerView.tsx +3 -10
  10. package/src/action-approval/index.ts +0 -1
  11. package/src/activity/ActivityPanel.tsx +13 -10
  12. package/src/activity/ActivityPanelFrame.test.tsx +32 -0
  13. package/src/activity/ActivityPanelFrame.tsx +3 -2
  14. package/src/activity/BackgroundTasksTabPanelView.tsx +1 -1
  15. package/src/activity/BrowserPanelView.tsx +48 -49
  16. package/src/activity/DebugTabPanelView.tsx +1 -1
  17. package/src/activity/MarkdownPreviewView.tsx +56 -59
  18. package/src/activity/PluginTabPickerView.tsx +5 -3
  19. package/src/activity/PortsTabPanelView.tsx +911 -0
  20. package/src/activity/ToolCallsSubTabView.tsx +1 -1
  21. package/src/activity/WorkflowTabPanelView.tsx +1 -1
  22. package/src/activity/index.ts +9 -0
  23. package/src/app/AppBackground.tsx +1 -1
  24. package/src/app/AppBootLoadingView.tsx +4 -2
  25. package/src/app-shell/DefaultWindowControls.tsx +1 -1
  26. package/src/app-shell/PageHeaderActionGroup.tsx +1 -1
  27. package/src/app-shell/PageHeaderContent.tsx +36 -7
  28. package/src/app-shell/PageHeaderFrame.tsx +15 -3
  29. package/src/app-shell/PageHeaderSidebarTrigger.tsx +1 -1
  30. package/src/app-shell/PageHeaderTitle.tsx +1 -1
  31. package/src/app-shell/WindowControlButton.tsx +1 -1
  32. package/src/app-shell/header-crowding.test.ts +62 -0
  33. package/src/app-shell/header-crowding.tsx +137 -0
  34. package/src/appearance/BackgroundImageFrame.tsx +1 -1
  35. package/src/appearance/CenterSliceImageFrame.tsx +1 -1
  36. package/src/appearance/CornerImageFrame.tsx +1 -1
  37. package/src/appearance/HorizontalSliceImageFrame.tsx +1 -1
  38. package/src/appearance/NineSliceImageFrame.tsx +1 -1
  39. package/src/appearance/ThemeSurface.tsx +1 -1
  40. package/src/batch-tasks/BatchProjectFoldersFieldView.tsx +2 -1
  41. package/src/batch-tasks/BatchTaskProjectActionsView.test.tsx +97 -0
  42. package/src/batch-tasks/BatchTaskProjectActionsView.tsx +45 -35
  43. package/src/batch-tasks/batchTaskUi.tsx +0 -29
  44. package/src/bottom-panel/BottomPanelView.test.tsx +43 -0
  45. package/src/bottom-panel/BottomPanelView.tsx +222 -0
  46. package/src/bottom-panel/index.ts +26 -0
  47. package/src/chat/AgentAvatarView.tsx +1 -1
  48. package/src/chat/AnnotationViews.tsx +107 -0
  49. package/src/chat/AskUserQuestionView.tsx +18 -11
  50. package/src/chat/AssistantMessageView.tsx +48 -13
  51. package/src/chat/AtPanelView.test.tsx +61 -0
  52. package/src/chat/AtPanelView.tsx +63 -38
  53. package/src/chat/BashTerminalCard.tsx +1 -2
  54. package/src/chat/ChatHeaderActionsView.tsx +74 -18
  55. package/src/chat/CompactionStepView.test.tsx +34 -0
  56. package/src/chat/CompactionStepView.tsx +85 -0
  57. package/src/chat/ExecutionModeSelectorView.tsx +20 -5
  58. package/src/chat/HeaderActionBarView.tsx +731 -0
  59. package/src/chat/HeaderActionOverflowMenu.tsx +137 -0
  60. package/src/chat/InlineModelPicker.test.tsx +81 -0
  61. package/src/chat/InlineModelPicker.tsx +201 -0
  62. package/src/chat/InlineTokenChip.tsx +2 -68
  63. package/src/chat/InputBarBackground.tsx +1 -1
  64. package/src/chat/InputBarPlaceholder.tsx +26 -3
  65. package/src/chat/LiveThinkingView.tsx +51 -37
  66. package/src/chat/MessageBoundaryViews.tsx +21 -0
  67. package/src/chat/MessageFeedContext.tsx +13 -5
  68. package/src/chat/MessageFeedLayoutView.tsx +28 -3
  69. package/src/chat/MessageFeedView.test.tsx +81 -0
  70. package/src/chat/MessageFeedView.tsx +72 -152
  71. package/src/chat/MessageInputView.tsx +1 -1
  72. package/src/chat/MessageLayoutView.tsx +1 -1
  73. package/src/chat/MessageSelectionContextMenuView.tsx +4 -1
  74. package/src/chat/MessageTimelineView.tsx +1 -1
  75. package/src/chat/MessageView.tsx +1 -1
  76. package/src/chat/MessageVisualView.tsx +1 -1
  77. package/src/chat/ModelConfiguration.tsx +283 -0
  78. package/src/chat/ModelSelectorTrigger.tsx +63 -0
  79. package/src/chat/ModelSelectorView.tsx +1037 -223
  80. package/src/chat/NewSession.ts +1 -37
  81. package/src/chat/NewSessionPicker.tsx +3 -2
  82. package/src/chat/ProjectSelectorView.tsx +3 -2
  83. package/src/chat/ReasoningStepSlider.tsx +61 -0
  84. package/src/chat/RemoteSessionBadgeView.tsx +24 -0
  85. package/src/chat/SkillPromptAreaView.tsx +5 -19
  86. package/src/chat/TeamMemberReplyCardView.test.tsx +33 -0
  87. package/src/chat/TeamMemberReplyCardView.tsx +133 -0
  88. package/src/chat/TextBlockView.tsx +7 -770
  89. package/src/chat/TodoProgress.tsx +25 -53
  90. package/src/chat/TodoStatusBarView.tsx +14 -5
  91. package/src/chat/UserMessageView.tsx +113 -33
  92. package/src/chat/header-action-narrow.test.ts +21 -0
  93. package/src/chat/header-action-narrow.ts +38 -0
  94. package/src/chat/index.ts +32 -27
  95. package/src/chat/markdown-link.ts +7 -279
  96. package/src/chat/send-button.css +4 -22
  97. package/src/chat/streaming-reveal.test.ts +218 -0
  98. package/src/chat/streaming-reveal.ts +13 -0
  99. package/src/file-explorer/ConfirmDeleteDialogView.tsx +2 -1
  100. package/src/file-explorer/FileContextMenuView.tsx +44 -11
  101. package/src/file-explorer/FileExplorerSettingsView.tsx +97 -0
  102. package/src/file-explorer/FileTreeCreateRow.tsx +1 -1
  103. package/src/file-explorer/FileTreeNodeView.tsx +59 -18
  104. package/src/file-explorer/FileTreeView.tsx +236 -129
  105. package/src/file-explorer/file-tree-dom.ts +23 -0
  106. package/src/file-explorer/file-tree-rows.test.ts +74 -0
  107. package/src/file-explorer/file-tree-rows.ts +168 -0
  108. package/src/file-explorer/index.ts +17 -0
  109. package/src/file-explorer/types.ts +3 -0
  110. package/src/file-explorer/useFileTreeMarqueeSelection.ts +24 -16
  111. package/src/file-preview/FilePreviewDialogView.tsx +2 -2
  112. package/src/file-preview/FilePreviewView.tsx +12 -2
  113. package/src/file-preview/TextFileEditorView.tsx +2 -1
  114. package/src/index.ts +1 -0
  115. package/src/knowledge/KnowledgeHowItWorksDialogView.tsx +1 -1
  116. package/src/layout/AppFrame.tsx +3 -2
  117. package/src/layout/MainContentFrame.tsx +7 -2
  118. package/src/layout/ResizeHandle.tsx +68 -17
  119. package/src/layout/SidebarDock.tsx +75 -19
  120. package/src/layout/SidebarOverlay.tsx +1 -1
  121. package/src/layout/index.ts +1 -1
  122. package/src/layout/resize-handle-axis.test.ts +51 -0
  123. package/src/live-indicators.test.ts +43 -0
  124. package/src/markdown/CodeBlock.tsx +123 -0
  125. package/src/markdown/InlineTokenChip.tsx +68 -0
  126. package/src/markdown/MarkdownContent.tsx +411 -0
  127. package/src/markdown/MarkdownImage.tsx +51 -0
  128. package/src/markdown/MathFormula.tsx +46 -0
  129. package/src/markdown/MermaidBlock.tsx +43 -0
  130. package/src/markdown/RichCodeBlock.tsx +127 -0
  131. package/src/markdown/SvgPreview.tsx +45 -0
  132. package/src/markdown/WebsiteIcon.tsx +94 -0
  133. package/src/markdown/builtin-renderers.tsx +43 -0
  134. package/src/markdown/definition.tsx +49 -0
  135. package/src/markdown/host.tsx +18 -0
  136. package/src/markdown/index.ts +11 -0
  137. package/src/markdown/inline-tokens.ts +187 -0
  138. package/src/markdown/markdown-link.ts +279 -0
  139. package/src/markdown/math-client.ts +116 -0
  140. package/src/markdown/math-render.ts +23 -0
  141. package/src/markdown/math-syntax.ts +80 -0
  142. package/src/markdown/math.worker.ts +16 -0
  143. package/src/markdown/nodes.ts +15 -0
  144. package/src/markdown/preview-policy.ts +43 -0
  145. package/src/markdown/rich-labels.ts +49 -0
  146. package/src/markdown/rich-syntax.ts +93 -0
  147. package/src/markdown/stable-blocks.test.ts +90 -0
  148. package/src/markdown/stable-blocks.ts +124 -0
  149. package/src/markdown/streaming-reveal.ts +297 -0
  150. package/src/markdown/streaming.test.ts +57 -0
  151. package/src/markdown/streaming.ts +211 -0
  152. package/src/markdown/use-render-snapshot.ts +24 -0
  153. package/src/markdown/use-rich-visibility.ts +24 -0
  154. package/src/overlays/CommandMenuRow.tsx +38 -9
  155. package/src/overlays/CommandMenuView.tsx +77 -117
  156. package/src/overlays/ConfirmDialogView.tsx +25 -20
  157. package/src/overlays/ReleaseNoteMarkdown.tsx +29 -0
  158. package/src/overlays/SplashOptionRow.tsx +46 -0
  159. package/src/overlays/SplashPanel.tsx +85 -0
  160. package/src/overlays/SplashParts.tsx +213 -0
  161. package/src/overlays/UpdateCheckerView.tsx +34 -18
  162. package/src/overlays/UpdateRestartDialogView.tsx +139 -54
  163. package/src/overlays/command-menu-types.ts +2 -0
  164. package/src/overlays/command-menu.css +1 -20
  165. package/src/overlays/index.ts +14 -1
  166. package/src/plugin-ui/index.ts +8 -0
  167. package/src/project/ConversationTagDotsView.tsx +1 -1
  168. package/src/project/ConversationTagEditorDialogView.tsx +4 -1
  169. package/src/project/DefaultConversationSectionView.tsx +4 -4
  170. package/src/project/DefaultSessionListView.tsx +5 -31
  171. package/src/project/DefaultSessionRowView.tsx +106 -55
  172. package/src/project/ManageSessionsSplashView.tsx +439 -0
  173. package/src/project/NewProjectDialogView.tsx +3 -10
  174. package/src/project/ProjectContextMenuView.tsx +30 -139
  175. package/src/project/ProjectDetailPageView.test.tsx +140 -0
  176. package/src/project/ProjectDetailPageView.tsx +372 -165
  177. package/src/project/ProjectGroupView.tsx +1 -1
  178. package/src/project/ProjectRowView.tsx +29 -12
  179. package/src/project/ProjectSessionsView.tsx +25 -47
  180. package/src/project/QuickScrollOverlay.tsx +1 -1
  181. package/src/project/SessionContextMenuView.tsx +15 -7
  182. package/src/project/SessionRowMoreButton.tsx +50 -0
  183. package/src/project/SessionRowView.tsx +106 -63
  184. package/src/project/SessionTitleMarquee.tsx +54 -0
  185. package/src/project/SidebarProjectDisclosure.tsx +60 -0
  186. package/src/project/SidebarProjectsSectionView.tsx +6 -1
  187. package/src/project/index.ts +12 -0
  188. package/src/project/session-row-transition.ts +9 -0
  189. package/src/project/types.ts +4 -2
  190. package/src/project/useActiveSessionAutoScroll.ts +10 -4
  191. package/src/registry.ts +0 -2
  192. package/src/scheduler/AutomationDetailPaneView.tsx +68 -0
  193. package/src/scheduler/AutomationPageView.tsx +118 -121
  194. package/src/scheduler/ExecutionHistoryView.tsx +7 -5
  195. package/src/scheduler/TaskListView.tsx +52 -201
  196. package/src/scheduler/index.ts +7 -12
  197. package/src/settings/AchievementSettingsView.tsx +0 -1
  198. package/src/settings/AppshotSettingsView.tsx +0 -1
  199. package/src/settings/BuiltinMcpSectionView.tsx +1 -1
  200. package/src/settings/EnvironmentGitRowView.tsx +156 -0
  201. package/src/settings/EnvironmentSettingsView.tsx +25 -3
  202. package/src/settings/GeneralSettingsView.tsx +17 -20
  203. package/src/settings/ImChannelGuideDialogView.tsx +2 -2
  204. package/src/settings/ImFeishuDialogView.tsx +1 -1
  205. package/src/settings/ImLegacyImportBannerView.tsx +1 -1
  206. package/src/settings/ImLogDrawerView.tsx +2 -1
  207. package/src/settings/JsonConfigInputView.tsx +171 -0
  208. package/src/settings/ModelsFetchedModelsDrawerView.tsx +292 -0
  209. package/src/settings/ModelsProvidersSectionView.tsx +26 -23
  210. package/src/settings/MotionSelect.tsx +9 -7
  211. package/src/settings/NotificationSettingsView.tsx +79 -0
  212. package/src/settings/PermissionsSettingsView.tsx +3 -7
  213. package/src/settings/PresetProviderModelsListView.tsx +141 -24
  214. package/src/settings/PresetProviderRowView.tsx +205 -182
  215. package/src/settings/ProxySettingsSectionView.tsx +182 -0
  216. package/src/settings/QrBindDialogView.tsx +1 -1
  217. package/src/settings/QuickPanelSettingsSectionView.tsx +0 -2
  218. package/src/settings/RemoteMcpSectionView.tsx +1 -1
  219. package/src/settings/SettingChrome.tsx +2 -2
  220. package/src/settings/SettingsAiAssistButtonView.tsx +9 -119
  221. package/src/settings/SettingsFormFields.tsx +4 -7
  222. package/src/settings/SettingsSidebarView.tsx +64 -3
  223. package/src/settings/ShortcutRecorderView.test.tsx +108 -0
  224. package/src/settings/ShortcutRecorderView.tsx +15 -9
  225. package/src/settings/ShortcutsSettingsView.tsx +1 -1
  226. package/src/settings/SpaceEditorDialogView.tsx +120 -0
  227. package/src/settings/SpacesSettingsView.tsx +105 -0
  228. package/src/settings/WebhookEndpointListView.tsx +4 -5
  229. package/src/settings/index.ts +41 -29
  230. package/src/shared/ActivityStatusDot.tsx +69 -0
  231. package/src/shared/AvatarStackView.tsx +13 -13
  232. package/src/shared/BotAvatar.tsx +11 -9
  233. package/src/shared/CodeBlockCopyButton.tsx +1 -1
  234. package/src/shared/ContextMenuView.tsx +4 -11
  235. package/src/shared/MarkdownTable.tsx +2 -2
  236. package/src/shared/SyntaxHighlightedCode.tsx +0 -0
  237. package/src/shared/TabBar.outline.test.tsx +59 -0
  238. package/src/shared/TabBar.tsx +22 -17
  239. package/src/shared/VettaKbd.test.tsx +52 -0
  240. package/src/shared/VettaKbd.tsx +81 -0
  241. package/src/shared/connected-tab-outline.test.ts +2 -2
  242. package/src/shared/connected-tab-outline.ts +2 -1
  243. package/src/shared/index.ts +6 -0
  244. package/src/shared/kbd-keys.test.ts +61 -0
  245. package/src/shared/kbd-keys.ts +253 -0
  246. package/src/shared/provider-icon/icons.ts +4 -2
  247. package/src/shared/provider-icon/index.tsx +1 -1
  248. package/src/shared/provider-icon/magpie.svg +1 -0
  249. package/src/sidebar/AddProjectMenuTriggerView.tsx +25 -15
  250. package/src/sidebar/DefaultSidebar.tsx +3 -1
  251. package/src/sidebar/MessageCenterDialogView.tsx +3 -2
  252. package/src/sidebar/MessageCenterEmptyState.tsx +1 -1
  253. package/src/sidebar/MessageCenterTabs.tsx +1 -1
  254. package/src/sidebar/MessageCenterToolbarButton.tsx +1 -1
  255. package/src/sidebar/MessageCenterTriggerView.tsx +2 -2
  256. package/src/sidebar/ProjectsPanelEmptyState.tsx +26 -7
  257. package/src/sidebar/SessionStatusIcon.tsx +16 -1
  258. package/src/sidebar/SettingsMenuThemeSection.tsx +1 -1
  259. package/src/sidebar/SettingsMenuTriggerView.test.tsx +42 -0
  260. package/src/sidebar/SettingsMenuTriggerView.tsx +28 -50
  261. package/src/sidebar/ShowMoreSessionsButton.tsx +1 -1
  262. package/src/sidebar/SidebarFilterSelectView.tsx +8 -16
  263. package/src/sidebar/SidebarNavBadgeView.tsx +1 -1
  264. package/src/sidebar/SidebarNavIcon.tsx +1 -1
  265. package/src/sidebar/SidebarNavItemButton.tsx +1 -1
  266. package/src/sidebar/SidebarNavMorePanel.tsx +19 -7
  267. package/src/sidebar/SidebarNavigation.tsx +24 -15
  268. package/src/sidebar/SidebarPanel.tsx +11 -2
  269. package/src/sidebar/SidebarSectionTriggerLabel.tsx +20 -0
  270. package/src/sidebar/SidebarTopBar.tsx +10 -7
  271. package/src/sidebar/WaitingPulseBadge.tsx +19 -0
  272. package/src/sidebar/index.ts +1 -16
  273. package/src/skills/index.ts +0 -19
  274. package/src/skills/skill-icon.tsx +4 -8
  275. package/src/styles.css +24 -6
  276. package/src/chat/DefaultSceneCarousel.tsx +0 -113
  277. package/src/chat/SceneCard.tsx +0 -138
  278. package/src/scheduler/HistoryDrawerView.tsx +0 -149
  279. package/src/scheduler/TaskFormDialogView.tsx +0 -60
  280. package/src/settings/SubscriptionActionsView.tsx +0 -63
  281. package/src/settings/SubscriptionCardsView.tsx +0 -212
  282. package/src/settings/TeamDetailView.tsx +0 -148
  283. package/src/settings/TeamDialogsView.tsx +0 -151
  284. package/src/settings/TeamListView.tsx +0 -57
  285. package/src/settings/TeamSettingsView.tsx +0 -51
  286. package/src/settings/TokenActivityChartView.tsx +0 -286
  287. package/src/settings/UsageStatsView.tsx +0 -101
  288. package/src/settings/shouldCloseEmptyApiKeyEditor.test.ts +0 -135
  289. package/src/settings/shouldCloseEmptyApiKeyEditor.ts +0 -40
  290. package/src/settings/token-activity.test.ts +0 -195
  291. package/src/settings/token-activity.ts +0 -320
  292. package/src/sidebar/AddProjectMenuItem.tsx +0 -21
  293. package/src/sidebar/AddProjectMenuPopoverView.tsx +0 -52
  294. package/src/sidebar/NotificationMessageListView.tsx +0 -136
  295. package/src/sidebar/SettingsMenuAccountSection.tsx +0 -32
  296. package/src/sidebar/SettingsMenuQuotaSection.tsx +0 -45
  297. package/src/skills/SceneCardView.tsx +0 -194
  298. package/src/skills/SkillCardView.tsx +0 -186
  299. package/src/skills/SkillDetailDialogView.tsx +0 -138
  300. package/src/skills/SkillTagGroupView.tsx +0 -56
  301. package/src/skills/SkillToggleSwitch.tsx +0 -31
@@ -1,286 +0,0 @@
1
- import { useEffect, useId, useMemo, useRef, useState, type JSX } from "react";
2
- import {
3
- activityBlockCount,
4
- activityIntensityLevel,
5
- activityMatrixHeightPx,
6
- buildActivityColumns,
7
- buildAreaGeometry,
8
- buildHoverZones,
9
- columnCapacity,
10
- fitActivityColumns,
11
- fitCurveColumns,
12
- formatTokenCount,
13
- trimLeadingIdleColumns,
14
- TOKEN_ACTIVITY_GAP_PX,
15
- TOKEN_ACTIVITY_MAX_ROWS,
16
- type TokenActivityMode,
17
- type UsageSeriesPointLike,
18
- } from "./token-activity";
19
-
20
- function cn(...parts: Array<string | false | null | undefined>): string {
21
- return parts.filter(Boolean).join(" ");
22
- }
23
-
24
- export interface TokenActivityChartViewProps {
25
- points: UsageSeriesPointLike[];
26
- loading?: boolean;
27
- /** When true, omit outer card chrome (for nesting inside another panel). */
28
- embedded?: boolean;
29
- labels: {
30
- title: string;
31
- daily: string;
32
- weekly: string;
33
- rolling: string;
34
- empty: string;
35
- tokens: (count: string) => string;
36
- month: (yearMonth: string) => string;
37
- };
38
- }
39
-
40
- const MODES: TokenActivityMode[] = ["daily", "weekly", "rolling"];
41
-
42
- /** 相邻月份刻度的最小水平间距(px),小于此值只保留前一个刻度。 */
43
- const MONTH_TICK_MIN_GAP_PX = 34;
44
-
45
- /** 1..4 light → dark; index 0 unused. Alpha values from DESIGN token whitelist. */
46
- const FILLED_CLASS: Record<number, string> = {
47
- 1: "bg-primary/25",
48
- 2: "bg-primary/40",
49
- 3: "bg-primary/60",
50
- 4: "bg-primary/80",
51
- };
52
- const FILLED_ACTIVE_CLASS: Record<number, string> = {
53
- 1: "bg-primary/40",
54
- 2: "bg-primary/60",
55
- 3: "bg-primary/80",
56
- 4: "bg-primary",
57
- };
58
-
59
- export function TokenActivityChartView({
60
- points,
61
- loading,
62
- embedded,
63
- labels,
64
- }: TokenActivityChartViewProps): JSX.Element {
65
- const [mode, setMode] = useState<TokenActivityMode>("rolling");
66
- const [hoverKey, setHoverKey] = useState<string | null>(null);
67
- const trackRef = useRef<HTMLDivElement>(null);
68
- const gradientId = useId();
69
- const [width, setWidth] = useState(0);
70
-
71
- useEffect(() => {
72
- const el = trackRef.current;
73
- if (!el) return;
74
- const measure = () => setWidth(el.clientWidth);
75
- measure();
76
- const ro = new ResizeObserver(measure);
77
- ro.observe(el);
78
- return () => ro.disconnect();
79
- }, [loading]);
80
-
81
- const rawColumns = useMemo(() => buildActivityColumns(points, mode), [points, mode]);
82
- const capacity = useMemo(() => columnCapacity(width), [width]);
83
- const isCurve = mode === "rolling";
84
- const columns = useMemo(
85
- () =>
86
- isCurve
87
- ? fitCurveColumns(trimLeadingIdleColumns(rawColumns), capacity)
88
- : fitActivityColumns(rawColumns, capacity),
89
- [rawColumns, capacity, isCurve],
90
- );
91
- const maxTokens = useMemo(() => {
92
- const values = columns.filter((c) => !c.isPad).map((c) => c.tokens);
93
- return Math.max(1, ...values, 0);
94
- }, [columns]);
95
- const hoverCol = hoverKey ? columns.find((c) => c.key === hoverKey && !c.isPad) : null;
96
- const geometry = useMemo(
97
- // 顶部留 8% 余量,否则最高点正好压在 viewBox 边缘、描边会被裁掉一半
98
- () => (isCurve ? buildAreaGeometry(columns, maxTokens * 1.08) : null),
99
- [isCurve, columns, maxTokens],
100
- );
101
- const curveHeight = useMemo(() => activityMatrixHeightPx(width, capacity), [width, capacity]);
102
- const hoverPoint = hoverCol ? geometry?.points.find((p) => p.key === hoverCol.key) : undefined;
103
- const hoverZones = useMemo(() => (geometry ? buildHoverZones(geometry.points) : []), [geometry]);
104
- /** 月份刻度按列下标定位,相邻月份起始列可能只差一两列 —— 太近就跳过,避免文字叠在一起。 */
105
- const monthTicks = useMemo(() => {
106
- const ticks: Array<{ key: string; leftPercent: number; monthKey: string }> = [];
107
- let lastLeftPx = Number.NEGATIVE_INFINITY;
108
- columns.forEach((col, i) => {
109
- if (!col.monthKey) return;
110
- const ratio = isCurve
111
- ? (geometry?.points[i]?.x ?? 0) / 100
112
- : i / Math.max(columns.length, 1);
113
- if (width > 0 && width * ratio - lastLeftPx < MONTH_TICK_MIN_GAP_PX) return;
114
- lastLeftPx = width * ratio;
115
- ticks.push({ key: col.key, leftPercent: ratio * 100, monthKey: col.monthKey });
116
- });
117
- return ticks;
118
- }, [columns, width, isCurve, geometry]);
119
-
120
- const modeLabel = (m: TokenActivityMode): string => {
121
- if (m === "daily") return labels.daily;
122
- if (m === "weekly") return labels.weekly;
123
- return labels.rolling;
124
- };
125
-
126
- return (
127
- <div
128
- className={
129
- embedded
130
- ? undefined
131
- : "rounded-xl border border-border/50 bg-card/40 p-4 backdrop-blur-sm"
132
- }
133
- >
134
- <div className="mb-3 flex flex-wrap items-center justify-between gap-2">
135
- <h3 className="text-[13px] font-semibold text-foreground">{labels.title}</h3>
136
- <div className="flex rounded-lg border border-border/50 bg-muted/30 p-0.5">
137
- {MODES.map((m) => (
138
- <button
139
- key={m}
140
- type="button"
141
- onClick={() => setMode(m)}
142
- className={cn(
143
- "rounded-md px-2.5 py-1 text-[11px] font-medium transition-colors",
144
- mode === m
145
- ? "bg-background text-foreground ring-1 ring-inset ring-border/60"
146
- : "text-muted-foreground hover:text-foreground",
147
- )}
148
- >
149
- {modeLabel(m)}
150
- </button>
151
- ))}
152
- </div>
153
- </div>
154
-
155
- {loading ? (
156
- <div className="h-[132px] animate-pulse rounded-lg bg-muted/40" />
157
- ) : (
158
- <div className="relative">
159
- {hoverCol && (
160
- <div className="pointer-events-none absolute left-1/2 top-0 z-10 -translate-x-1/2 -translate-y-0.5 rounded-lg border border-border/60 bg-popover/95 px-2.5 py-1 text-[11px] text-popover-foreground">
161
- <span className="text-muted-foreground">
162
- {hoverCol.windowStart
163
- ? `${hoverCol.windowStart} → ${hoverCol.date}`
164
- : hoverCol.date === hoverCol.endDate
165
- ? hoverCol.date
166
- : `${hoverCol.date} → ${hoverCol.endDate}`}
167
- </span>
168
- {" · "}
169
- {labels.tokens(formatTokenCount(hoverCol.tokens))}
170
- </div>
171
- )}
172
-
173
- <div ref={trackRef} className="w-full overflow-hidden pt-5" onMouseLeave={() => setHoverKey(null)}>
174
- {capacity > 0 && (
175
- <div className="flex w-full flex-col gap-1.5">
176
- {isCurve && geometry ? (
177
- <div
178
- className="relative w-full text-primary"
179
- style={{ height: curveHeight || undefined }}
180
- >
181
- <svg
182
- className="absolute inset-0 h-full w-full"
183
- viewBox="0 0 100 100"
184
- preserveAspectRatio="none"
185
- aria-hidden="true"
186
- focusable="false"
187
- >
188
- <defs>
189
- <linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
190
- <stop offset="0%" stopColor="currentColor" stopOpacity="0.35" />
191
- <stop offset="100%" stopColor="currentColor" stopOpacity="0.02" />
192
- </linearGradient>
193
- </defs>
194
- {geometry.areaPath && <path d={geometry.areaPath} fill={`url(#${gradientId})`} />}
195
- {geometry.linePath && (
196
- <path
197
- d={geometry.linePath}
198
- fill="none"
199
- stroke="currentColor"
200
- strokeWidth={1.5}
201
- strokeLinecap="round"
202
- strokeLinejoin="round"
203
- vectorEffect="non-scaling-stroke"
204
- />
205
- )}
206
- </svg>
207
- {hoverPoint && (
208
- <>
209
- <span
210
- className="pointer-events-none absolute top-0 bottom-0 w-px bg-primary/30"
211
- style={{ left: `${hoverPoint.x}%` }}
212
- />
213
- <span
214
- className="pointer-events-none absolute size-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary"
215
- style={{ left: `${hoverPoint.x}%`, top: `${hoverPoint.y}%` }}
216
- />
217
- </>
218
- )}
219
- {/* 曲线本身不可命中,用覆盖在数据点上的透明分区复用矩阵那套悬停逻辑 */}
220
- {hoverZones.map((zone) => (
221
- <div
222
- key={zone.key}
223
- className="absolute top-0 bottom-0"
224
- style={{ left: `${zone.left}%`, width: `${zone.width}%` }}
225
- onMouseEnter={() => setHoverKey(zone.key)}
226
- />
227
- ))}
228
- </div>
229
- ) : (
230
- <div className="flex w-full items-end" style={{ gap: TOKEN_ACTIVITY_GAP_PX }}>
231
- {columns.map((col) => {
232
- const filled = activityBlockCount(col.tokens, maxTokens);
233
- const level = activityIntensityLevel(col.tokens, maxTokens);
234
- const active = hoverKey === col.key;
235
- const fillClass =
236
- level > 0
237
- ? active
238
- ? FILLED_ACTIVE_CLASS[level]
239
- : FILLED_CLASS[level]
240
- : undefined;
241
- return (
242
- <div
243
- key={col.key}
244
- className="flex min-w-0 flex-1 flex-col-reverse"
245
- style={{ gap: TOKEN_ACTIVITY_GAP_PX }}
246
- onMouseEnter={() => {
247
- if (!col.isPad) setHoverKey(col.key);
248
- }}
249
- >
250
- {Array.from({ length: TOKEN_ACTIVITY_MAX_ROWS }, (_, row) => {
251
- const isFilled = row < filled;
252
- return (
253
- <div
254
- key={row}
255
- className={cn(
256
- "aspect-square w-full rounded-[2px] transition-colors",
257
- isFilled ? fillClass : "bg-muted",
258
- )}
259
- />
260
- );
261
- })}
262
- </div>
263
- );
264
- })}
265
- </div>
266
- )}
267
-
268
- <div className="relative mt-0.5 h-4">
269
- {monthTicks.map((tick) => (
270
- <span
271
- key={tick.key}
272
- className="absolute whitespace-nowrap text-[10px] text-muted-foreground"
273
- style={{ left: `${tick.leftPercent}%` }}
274
- >
275
- {labels.month(tick.monthKey)}
276
- </span>
277
- ))}
278
- </div>
279
- </div>
280
- )}
281
- </div>
282
- </div>
283
- )}
284
- </div>
285
- );
286
- }
@@ -1,101 +0,0 @@
1
- import type { JSX } from "react";
2
- import { formatTokenCount } from "./token-activity";
3
-
4
- function cn(...parts: Array<string | false | null | undefined>): string {
5
- return parts.filter(Boolean).join(" ");
6
- }
7
-
8
- export type UsageStatsRange = "7d" | "30d" | "all";
9
-
10
- export const USAGE_STATS_RANGES: UsageStatsRange[] = ["7d", "30d", "all"];
11
-
12
- /** 可按区间下钻的指标:单位跟在数值后,卡片下方只留区间切换。 */
13
- export interface UsageStatsMetric {
14
- onRangeChange: (range: UsageStatsRange) => void;
15
- range: UsageStatsRange;
16
- total: number;
17
- unit: string;
18
- }
19
-
20
- export interface UsageStatsViewProps {
21
- loading?: boolean;
22
- requests: UsageStatsMetric;
23
- /** 连续使用天数与区间无关。 */
24
- streakDays: number;
25
- tokens: UsageStatsMetric;
26
- labels: {
27
- days: (count: number) => string;
28
- range: (range: UsageStatsRange) => string;
29
- streak: string;
30
- };
31
- }
32
-
33
- function StatTile({
34
- children,
35
- unit,
36
- value,
37
- }: {
38
- children: JSX.Element;
39
- unit?: string;
40
- value: string;
41
- }): JSX.Element {
42
- return (
43
- <div className="min-w-0 rounded-lg border border-border/50 bg-background/40 px-3 py-2.5 text-center">
44
- <div className="truncate text-[18px] font-semibold tabular-nums text-foreground">
45
- {value}
46
- {unit && <span className="ml-1 text-[11px] font-normal text-muted-foreground">{unit}</span>}
47
- </div>
48
- <div className="mt-1 flex items-center justify-center gap-2 text-[10px]">{children}</div>
49
- </div>
50
- );
51
- }
52
-
53
- function MetricTile({
54
- metric,
55
- rangeLabel,
56
- }: {
57
- metric: UsageStatsMetric;
58
- rangeLabel: (range: UsageStatsRange) => string;
59
- }): JSX.Element {
60
- return (
61
- <StatTile unit={metric.unit} value={formatTokenCount(metric.total)}>
62
- <>
63
- {USAGE_STATS_RANGES.map((item) => (
64
- <button
65
- key={item}
66
- type="button"
67
- onClick={() => metric.onRangeChange(item)}
68
- className={cn(
69
- "whitespace-nowrap transition-colors",
70
- metric.range === item
71
- ? "font-medium text-primary"
72
- : "text-muted-foreground/60 hover:text-foreground",
73
- )}
74
- >
75
- {rangeLabel(item)}
76
- </button>
77
- ))}
78
- </>
79
- </StatTile>
80
- );
81
- }
82
-
83
- export function UsageStatsView({
84
- loading,
85
- requests,
86
- streakDays,
87
- tokens,
88
- labels,
89
- }: UsageStatsViewProps): JSX.Element {
90
- if (loading) return <div className="h-[70px] animate-pulse rounded-lg bg-muted/40" />;
91
-
92
- return (
93
- <div className="grid grid-cols-3 gap-3">
94
- <MetricTile metric={tokens} rangeLabel={labels.range} />
95
- <MetricTile metric={requests} rangeLabel={labels.range} />
96
- <StatTile value={labels.days(streakDays)}>
97
- <span className="text-muted-foreground">{labels.streak}</span>
98
- </StatTile>
99
- </div>
100
- );
101
- }
@@ -1,135 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { type FocusContainmentRoot, shouldCloseEmptyApiKeyEditor } from "./shouldCloseEmptyApiKeyEditor";
3
-
4
- /** 轻量 contains 替身,不依赖任何 DOM 环境。 */
5
- function makeRoot(contained: object[]): FocusContainmentRoot {
6
- const set = new Set(contained);
7
- return {
8
- contains(node: object | null): boolean {
9
- return node != null && set.has(node);
10
- },
11
- };
12
- }
13
-
14
- describe("shouldCloseEmptyApiKeyEditor", () => {
15
- const outside = { id: "outside" };
16
- const insideButton = { id: "inside-btn" };
17
- const inputEl = { id: "input" };
18
-
19
- it("closes when draft is empty and focus left the editor", () => {
20
- const root = makeRoot([inputEl, insideButton]);
21
- expect(
22
- shouldCloseEmptyApiKeyEditor({
23
- draftKey: "",
24
- saving: false,
25
- editorRoot: root,
26
- relatedTarget: outside,
27
- activeElement: outside,
28
- }),
29
- ).toBe(true);
30
- });
31
-
32
- it("treats whitespace-only draft as empty and closes", () => {
33
- const root = makeRoot([inputEl]);
34
- expect(
35
- shouldCloseEmptyApiKeyEditor({
36
- draftKey: " \t ",
37
- saving: false,
38
- editorRoot: root,
39
- relatedTarget: null,
40
- activeElement: outside,
41
- }),
42
- ).toBe(true);
43
- });
44
-
45
- it("keeps open when draft has content even if focus left", () => {
46
- const root = makeRoot([inputEl]);
47
- expect(
48
- shouldCloseEmptyApiKeyEditor({
49
- draftKey: "sk-abc",
50
- saving: false,
51
- editorRoot: root,
52
- relatedTarget: null,
53
- activeElement: outside,
54
- }),
55
- ).toBe(false);
56
- });
57
-
58
- it("keeps open while saving", () => {
59
- const root = makeRoot([inputEl]);
60
- expect(
61
- shouldCloseEmptyApiKeyEditor({
62
- draftKey: "",
63
- saving: true,
64
- editorRoot: root,
65
- relatedTarget: null,
66
- activeElement: outside,
67
- }),
68
- ).toBe(false);
69
- });
70
-
71
- it("keeps open when relatedTarget stays inside the editor actions", () => {
72
- const root = makeRoot([inputEl, insideButton]);
73
- expect(
74
- shouldCloseEmptyApiKeyEditor({
75
- draftKey: "",
76
- saving: false,
77
- editorRoot: root,
78
- relatedTarget: insideButton,
79
- activeElement: insideButton,
80
- }),
81
- ).toBe(false);
82
- });
83
-
84
- it("keeps open when relatedTarget is null but activeElement is still inside", () => {
85
- // 常见:点同行取消/复制时 relatedTarget=null,但焦点实际落到了区内按钮。
86
- const root = makeRoot([inputEl, insideButton]);
87
- expect(
88
- shouldCloseEmptyApiKeyEditor({
89
- draftKey: "",
90
- saving: false,
91
- editorRoot: root,
92
- relatedTarget: null,
93
- activeElement: insideButton,
94
- }),
95
- ).toBe(false);
96
- });
97
-
98
- it("closes when relatedTarget is null and activeElement is outside", () => {
99
- const root = makeRoot([inputEl, insideButton]);
100
- expect(
101
- shouldCloseEmptyApiKeyEditor({
102
- draftKey: "",
103
- saving: false,
104
- editorRoot: root,
105
- relatedTarget: null,
106
- activeElement: outside,
107
- }),
108
- ).toBe(true);
109
- });
110
-
111
- it("closes when relatedTarget is null and activeElement is null", () => {
112
- const root = makeRoot([inputEl]);
113
- expect(
114
- shouldCloseEmptyApiKeyEditor({
115
- draftKey: "",
116
- saving: false,
117
- editorRoot: root,
118
- relatedTarget: null,
119
- activeElement: null,
120
- }),
121
- ).toBe(true);
122
- });
123
-
124
- it("closes when editorRoot is missing (unmounted mid-blur)", () => {
125
- expect(
126
- shouldCloseEmptyApiKeyEditor({
127
- draftKey: "",
128
- saving: false,
129
- editorRoot: null,
130
- relatedTarget: null,
131
- activeElement: null,
132
- }),
133
- ).toBe(true);
134
- });
135
- });
@@ -1,40 +0,0 @@
1
- /**
2
- * 可做 contains 判定的编辑区根(浏览器里是 HTMLElement,测试里可替身)。
3
- * 不绑 DOM 全局,便于 node 单测。
4
- */
5
- export interface FocusContainmentRoot {
6
- contains(node: object | null): boolean;
7
- }
8
-
9
- /**
10
- * 预设服务商行内 API Key 编辑:空内容失焦是否应收起。
11
- *
12
- * 不用 relatedTarget 单点判定——点按钮时部分环境 relatedTarget 为 null,
13
- * 需结合 editorRoot.contains(activeElement) 判断焦点是否仍在编辑区内。
14
- */
15
- export function shouldCloseEmptyApiKeyEditor(input: {
16
- readonly draftKey: string;
17
- readonly saving: boolean;
18
- readonly editorRoot: FocusContainmentRoot | null;
19
- /** blur 的 relatedTarget;点到非 focusable 时经常是 null。 */
20
- readonly relatedTarget: object | null;
21
- /** 失焦后已落定的 activeElement(可在 microtask 里再读)。 */
22
- readonly activeElement: object | null;
23
- }): boolean {
24
- if (input.saving) return false;
25
- if (input.draftKey.trim().length > 0) return false;
26
-
27
- const root = input.editorRoot;
28
- if (!root) return true;
29
-
30
- if (input.relatedTarget != null && root.contains(input.relatedTarget)) {
31
- return false;
32
- }
33
-
34
- // relatedTarget 不可靠时,以已落定的 activeElement 为准。
35
- if (input.activeElement != null && root.contains(input.activeElement)) {
36
- return false;
37
- }
38
-
39
- return true;
40
- }