@vetta-org/theme-ui 0.2.0 → 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 (54) hide show
  1. package/package.json +1 -1
  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/BackgroundTasksTabPanelView.tsx +18 -2
  7. package/src/activity/BrowserPanelView.tsx +15 -1
  8. package/src/activity/BrowserSelectionView.tsx +199 -0
  9. package/src/activity/index.ts +1 -0
  10. package/src/chat/EditDiffView.tsx +4 -4
  11. package/src/chat/HeaderActionBarView.tsx +16 -4
  12. package/src/chat/streaming-reveal.test.ts +1 -74
  13. package/src/chat/streaming-reveal.ts +0 -3
  14. package/src/file-preview/FilePreviewDialogView.tsx +2 -1
  15. package/src/layout/ResizeHandle.tsx +4 -1
  16. package/src/layout/resize-handle-reset.test.tsx +50 -0
  17. package/src/markdown/MarkdownContent.tsx +49 -26
  18. package/src/markdown/UrlLinkBadge.tsx +84 -0
  19. package/src/markdown/index.ts +1 -0
  20. package/src/markdown/nodes.ts +6 -1
  21. package/src/markdown/rich-labels.ts +3 -0
  22. package/src/markdown/streaming-fade.test.ts +83 -0
  23. package/src/markdown/streaming-fade.tsx +141 -0
  24. package/src/markdown/streaming-reveal.ts +0 -67
  25. package/src/markdown/streaming.ts +64 -131
  26. package/src/overlays/CommandMenuRow.tsx +4 -14
  27. package/src/overlays/CommandMenuView.tsx +11 -4
  28. package/src/overlays/ReleaseNoteImage.test.tsx +105 -0
  29. package/src/overlays/ReleaseNoteMarkdown.test.tsx +25 -0
  30. package/src/overlays/ReleaseNoteMarkdown.tsx +94 -7
  31. package/src/overlays/UpdateCheckerView.tsx +17 -15
  32. package/src/overlays/UpdateRestartDialogView.tsx +14 -5
  33. package/src/overlays/command-menu-types.ts +2 -0
  34. package/src/overlays/index.ts +1 -0
  35. package/src/plugin-ui/index.ts +2 -0
  36. package/src/project/DefaultConversationSectionView.tsx +4 -0
  37. package/src/project/ManageSessionsSplashView.tsx +0 -2
  38. package/src/settings/GeneralSettingsView.tsx +19 -0
  39. package/src/settings/LauncherSettingsView.tsx +0 -1
  40. package/src/settings/StorageBar.tsx +70 -0
  41. package/src/settings/StorageExplorer.tsx +488 -0
  42. package/src/settings/StorageReadout.tsx +64 -0
  43. package/src/settings/StorageSettingsView.test.tsx +181 -0
  44. package/src/settings/StorageSettingsView.tsx +458 -0
  45. package/src/settings/index.ts +10 -0
  46. package/src/settings/storage-treemap-layout.test.ts +32 -0
  47. package/src/settings/storage-treemap-layout.ts +55 -0
  48. package/src/shared/SegmentedControl.tsx +10 -11
  49. package/src/shared/StageDialogContent.test.tsx +61 -0
  50. package/src/shared/StageDialogContent.tsx +80 -0
  51. package/src/shared/index.ts +2 -0
  52. package/src/sidebar/AddProjectMenuTriggerView.tsx +4 -2
  53. package/src/styles.css +5 -0
  54. package/src/markdown/streaming.test.ts +0 -57
@@ -0,0 +1,55 @@
1
+ export interface TreemapTile {
2
+ readonly x: number;
3
+ readonly y: number;
4
+ readonly width: number;
5
+ readonly height: number;
6
+ }
7
+
8
+ /** 再小就点不到;极小的项按这个占比画。 */
9
+ const MIN_SHARE = 0.012;
10
+
11
+ /** 按体积把画布切成矩形(squarified):逐行填入,让每块尽量接近正方形。sizes 从大到小排列时效果最好。 */
12
+ export function layoutTreemap(sizes: readonly number[], width: number, height: number): TreemapTile[] {
13
+ const total = sizes.reduce((sum, size) => sum + size, 0);
14
+ if (sizes.length === 0 || total <= 0) return [];
15
+ const weights = sizes.map((size) => Math.max(size / total, MIN_SHARE));
16
+ const scale = (width * height) / weights.reduce((sum, weight) => sum + weight, 0);
17
+ const areas = weights.map((weight) => weight * scale);
18
+
19
+ const tiles: TreemapTile[] = [];
20
+ let free = { x: 0, y: 0, width, height };
21
+ for (let start = 0; start < areas.length; ) {
22
+ const side = Math.min(free.width, free.height);
23
+ let end = start + 1;
24
+ while (
25
+ end < areas.length &&
26
+ worstRatio(areas.slice(start, end + 1), side) <= worstRatio(areas.slice(start, end), side)
27
+ ) {
28
+ end += 1;
29
+ }
30
+ const row = areas.slice(start, end);
31
+ const thickness = row.reduce((sum, area) => sum + area, 0) / side;
32
+ const horizontal = free.width >= free.height;
33
+ let offset = 0;
34
+ for (const area of row) {
35
+ const length = area / thickness;
36
+ tiles.push(
37
+ horizontal
38
+ ? { x: free.x, y: free.y + offset, width: thickness, height: length }
39
+ : { x: free.x + offset, y: free.y, width: length, height: thickness },
40
+ );
41
+ offset += length;
42
+ }
43
+ free = horizontal
44
+ ? { ...free, x: free.x + thickness, width: free.width - thickness }
45
+ : { ...free, y: free.y + thickness, height: free.height - thickness };
46
+ start = end;
47
+ }
48
+ return tiles;
49
+ }
50
+
51
+ /** 一行里最扁的那块的长宽比。 */
52
+ function worstRatio(row: readonly number[], side: number): number {
53
+ const sum = row.reduce((total, area) => total + area, 0);
54
+ return Math.max((side * side * Math.max(...row)) / (sum * sum), (sum * sum) / (side * side * Math.min(...row)));
55
+ }
@@ -12,7 +12,7 @@ export interface SegmentedControlItem<T extends string> {
12
12
  /** 可选未读小红点(>0 显示)。表达「有待处理的新内容」,与 count 的语义不同。 */
13
13
  badge?: number;
14
14
  /**
15
- * 可选计数(0 不显示):跟在标题后面的灰字数字,用于「这一栏里有多少条」这类
15
+ * 可选计数(0 不显示):跟在标题后面的灰字小胶囊,用于「这一栏里有多少条」这类
16
16
  * 中性的量,例如变更数、任务数。需要告警语气时用 badge。
17
17
  */
18
18
  count?: number;
@@ -38,10 +38,7 @@ export function SegmentedControl<T extends string>({
38
38
 
39
39
  return (
40
40
  <div
41
- className={cn(
42
- "relative inline-flex shrink-0 rounded-[8px] bg-black/[0.06] p-[2px] dark:bg-white/[0.08]",
43
- className,
44
- )}
41
+ className={cn("relative inline-flex shrink-0 gap-1", className)}
45
42
  >
46
43
  {items.map(({ key, label, icon, badge, count }) => {
47
44
  const active = value === key;
@@ -51,14 +48,14 @@ export function SegmentedControl<T extends string>({
51
48
  type="button"
52
49
  onClick={() => onChange(key)}
53
50
  className={cn(
54
- "relative flex shrink-0 items-center justify-center gap-1 whitespace-nowrap rounded-[6px] px-2.5 py-[3px] text-[11px] font-medium leading-[16px] transition-colors duration-150 select-none",
55
- active ? "text-foreground" : "text-muted-foreground hover:text-foreground/70",
51
+ "relative flex h-7 shrink-0 items-center justify-center whitespace-nowrap rounded-full px-2.5 text-[0.8rem] font-medium outline-none transition-colors duration-150 select-none focus-visible:ring-2 focus-visible:ring-ring",
52
+ active ? "text-foreground" : "text-muted-foreground hover:bg-accent/50 hover:text-foreground",
56
53
  )}
57
54
  >
58
55
  {active && (
59
56
  <motion.span
60
57
  layoutId={`seg-indicator-${layoutId}`}
61
- className="absolute inset-0 rounded-[6px] bg-background shadow-[0_1px_2px_rgba(0,0,0,0.06),0_0_0_0.5px_rgba(0,0,0,0.04)] ring-[0.5px] ring-inset ring-primary/30 dark:bg-white/[0.12] dark:shadow-[0_1px_2px_rgba(0,0,0,0.2)]"
58
+ className="absolute inset-0 rounded-full bg-secondary"
62
59
  transition={
63
60
  suppressLayoutAnimation
64
61
  ? { duration: 0 }
@@ -67,14 +64,16 @@ export function SegmentedControl<T extends string>({
67
64
  />
68
65
  )}
69
66
  <motion.span
70
- className="relative z-10 flex items-center gap-1"
67
+ className="relative z-10 flex items-center gap-1.5"
71
68
  whileTap={{ scale: 0.93 }}
72
69
  transition={{ type: "spring", stiffness: 500, damping: 24 }}
73
70
  >
74
- {icon && <span className={cn(icon, "h-3 w-3")} />}
71
+ {icon && <span className={cn(icon, "h-3.5 w-3.5")} />}
75
72
  {label}
76
73
  {count && count > 0 ? (
77
- <span className="text-[10px] font-medium tabular-nums text-muted-foreground">{count}</span>
74
+ <span className="rounded-full bg-background/60 px-1.5 text-[11px] leading-4 tabular-nums text-muted-foreground">
75
+ {count}
76
+ </span>
78
77
  ) : null}
79
78
  {badge && badge > 0 ? (
80
79
  <span className="ml-0.5 inline-flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-red-500 px-1 text-[9px] font-semibold leading-none text-white">
@@ -0,0 +1,61 @@
1
+ // @vitest-environment jsdom
2
+
3
+ import { Dialog, DialogDescription, DialogTitle, DialogTrigger } from "@vetta-org/ui";
4
+ import { act } from "react";
5
+ import { createRoot, type Root } from "react-dom/client";
6
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
7
+ import { StageDialogContent } from "./StageDialogContent";
8
+
9
+ /** Uses the `@vetta-org/ui` Dialog parts, the same combination plugins are told to use. */
10
+ describe("StageDialogContent", () => {
11
+ let root: Root;
12
+ let host: HTMLDivElement;
13
+
14
+ function openStage(closeLabel?: string): void {
15
+ act(() =>
16
+ root.render(
17
+ <Dialog>
18
+ <DialogTrigger>Open poster</DialogTrigger>
19
+ <StageDialogContent closeLabel={closeLabel} artwork={<p>Poster</p>}>
20
+ <DialogTitle>Share poster</DialogTitle>
21
+ <DialogDescription>Save it as an image.</DialogDescription>
22
+ </StageDialogContent>
23
+ </Dialog>,
24
+ ),
25
+ );
26
+ act(() => host.querySelector("button")?.click());
27
+ }
28
+
29
+ const stage = () => document.querySelector<HTMLElement>('[role="dialog"]');
30
+ const closeButton = () => stage()?.querySelector<HTMLButtonElement>('button[aria-label="Close poster"]') ?? null;
31
+
32
+ beforeEach(() => {
33
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
34
+ host = document.createElement("div");
35
+ document.body.append(host);
36
+ root = createRoot(host);
37
+ });
38
+
39
+ afterEach(() => {
40
+ act(() => root.unmount());
41
+ host.remove();
42
+ });
43
+
44
+ it("opens from the ui Dialog trigger and closes with the labelled close button", () => {
45
+ openStage("Close poster");
46
+ expect(stage()?.textContent).toContain("Poster");
47
+ expect(stage()?.textContent).toContain("Share poster");
48
+
49
+ act(() => closeButton()?.click());
50
+ expect(stage()).toBeNull();
51
+ });
52
+
53
+ it("shows no close button without a label, and still closes on a backdrop click", () => {
54
+ openStage();
55
+ expect(stage()?.textContent).toContain("Poster");
56
+ expect(stage()?.querySelectorAll('button:not([aria-hidden="true"])')).toHaveLength(0);
57
+
58
+ act(() => stage()?.querySelector<HTMLButtonElement>('button[aria-hidden="true"]')?.click());
59
+ expect(stage()).toBeNull();
60
+ });
61
+ });
@@ -0,0 +1,80 @@
1
+ import { Dialog } from "radix-ui";
2
+ import { type ComponentProps, type ReactNode, useRef } from "react";
3
+
4
+ type ContentProps = ComponentProps<typeof Dialog.Content>;
5
+
6
+ export interface StageDialogContentProps {
7
+ artwork: ReactNode;
8
+ /** Caption column beside the artwork; leave it out to let the artwork stand alone. */
9
+ children?: ReactNode;
10
+ /**
11
+ * Accessible name of the round close button in the top-right corner of the window.
12
+ * Leave it out when the caption column already offers a way to close.
13
+ */
14
+ closeLabel?: string;
15
+ /**
16
+ * Call `preventDefault()` to keep focus off the first control when the stage opens.
17
+ * Focus then lands on the stage itself, so it never stays on the opener outside the modal.
18
+ */
19
+ onOpenAutoFocus?: ContentProps["onOpenAutoFocus"];
20
+ /** Needed when the dialog is opened without a `Dialog.Trigger`, so focus can return to the opener. */
21
+ onCloseAutoFocus?: ContentProps["onCloseAutoFocus"];
22
+ }
23
+
24
+ /**
25
+ * Full-window stage for one piece of artwork: no card, just a blurred backdrop that closes on click.
26
+ * Render it inside a Dialog root, and give it a Dialog title and description (visually hidden is fine).
27
+ */
28
+ export function StageDialogContent({
29
+ artwork,
30
+ children,
31
+ closeLabel,
32
+ onOpenAutoFocus,
33
+ onCloseAutoFocus,
34
+ }: StageDialogContentProps) {
35
+ const contentRef = useRef<HTMLDivElement>(null);
36
+ return (
37
+ <Dialog.Portal>
38
+ <Dialog.Overlay
39
+ data-slot="dialog-overlay"
40
+ className="no-drag fixed inset-0 z-50 bg-background/80 backdrop-blur-md"
41
+ />
42
+ <Dialog.Content
43
+ data-slot="dialog-stage"
44
+ ref={contentRef}
45
+ onOpenAutoFocus={(event) => {
46
+ onOpenAutoFocus?.(event);
47
+ // Radix skips its own container fallback once the event is cancelled.
48
+ if (event.defaultPrevented) contentRef.current?.focus({ preventScroll: true });
49
+ }}
50
+ onCloseAutoFocus={onCloseAutoFocus}
51
+ className="no-drag fixed inset-0 z-50 overflow-y-auto outline-none"
52
+ >
53
+ <Dialog.Close asChild>
54
+ <button type="button" tabIndex={-1} aria-hidden="true" className="fixed inset-0 cursor-default" />
55
+ </Dialog.Close>
56
+ <div className="pointer-events-none relative flex min-h-full items-center justify-center px-8 py-10">
57
+ <div className="flex max-w-full flex-wrap items-start justify-center gap-x-10 gap-y-6">
58
+ <div className="pointer-events-auto min-w-0 max-w-full">{artwork}</div>
59
+ {children ? (
60
+ <div className="pointer-events-auto flex w-[240px] max-w-full flex-col pt-1">{children}</div>
61
+ ) : null}
62
+ </div>
63
+ </div>
64
+ {/* 48px from the top: clears the Windows caption buttons in the same corner. */}
65
+ {closeLabel ? (
66
+ <Dialog.Close asChild>
67
+ <button
68
+ type="button"
69
+ title={closeLabel}
70
+ aria-label={closeLabel}
71
+ className="fixed top-12 right-6 flex h-9 w-9 items-center justify-center rounded-full bg-white text-black shadow-md outline-none transition-transform hover:scale-105 active:scale-95 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
72
+ >
73
+ <span aria-hidden className="icon-[mdi--close] h-5 w-5" />
74
+ </button>
75
+ </Dialog.Close>
76
+ ) : null}
77
+ </Dialog.Content>
78
+ </Dialog.Portal>
79
+ );
80
+ }
@@ -34,6 +34,8 @@ export type { ScrollFadeProps } from "./ScrollFade";
34
34
  export { ScrollFade } from "./ScrollFade";
35
35
  export type { SegmentedControlItem, SegmentedControlProps } from "./SegmentedControl";
36
36
  export { SegmentedControl } from "./SegmentedControl";
37
+ export type { StageDialogContentProps } from "./StageDialogContent";
38
+ export { StageDialogContent } from "./StageDialogContent";
37
39
  export type { SyntaxHighlightedCodeProps } from "./SyntaxHighlightedCode";
38
40
  export { SyntaxHighlightedCode } from "./SyntaxHighlightedCode";
39
41
  export type { TabBarDragEvent, TabBarItem, TabBarProps } from "./TabBar";
@@ -12,11 +12,13 @@ export interface AddProjectMenuTriggerViewProps extends ComponentPropsWithoutRef
12
12
  variant: "icon" | "navItem" | "primary" | "secondary";
13
13
  /** 仅 `icon` 变体生效:还没有项目时常驻引导,有项目后改为悬停标题行才出现。 */
14
14
  reveal?: "hover" | "always";
15
+ /** 仅 `icon` 变体生效:与同一标题行上的其他「+」区分时换图标。 */
16
+ iconClassName?: string;
15
17
  }
16
18
 
17
19
  // 作为 PopoverTrigger asChild 的子节点:需要转发 ref 并透传 Radix 注入的属性。
18
20
  export const AddProjectMenuTriggerView = forwardRef<HTMLButtonElement, AddProjectMenuTriggerViewProps>(
19
- function AddProjectMenuTriggerView({ label, open, reveal = "hover", variant, ...props }, ref): JSX.Element {
21
+ function AddProjectMenuTriggerView({ iconClassName = "icon-[solar--add-linear]", label, open, reveal = "hover", variant, ...props }, ref): JSX.Element {
20
22
  if (variant === "secondary") {
21
23
  return (
22
24
  <Button variant="secondary" size="lg" className="no-drag w-full text-[13px]" ref={ref}
@@ -50,7 +52,7 @@ export const AddProjectMenuTriggerView = forwardRef<HTMLButtonElement, AddProjec
50
52
  ref={ref}
51
53
  {...props}
52
54
  expanded={open}
53
- iconClassName="icon-[solar--add-linear]"
55
+ iconClassName={iconClassName}
54
56
  label={label}
55
57
  reveal={reveal}
56
58
  />
package/src/styles.css CHANGED
@@ -66,6 +66,11 @@ textarea::placeholder {
66
66
  opacity: 0.5;
67
67
  }
68
68
 
69
+ /* Capture markers must stay vivid over guest pages, independently of the app theme. */
70
+ @theme {
71
+ --color-browser-selection: #008cff;
72
+ }
73
+
69
74
  @theme inline {
70
75
  --color-accent: var(--accent);
71
76
  --color-accent-foreground: var(--accent-foreground);
@@ -1,57 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import type { HastElement, HastRoot, HastText } from "./nodes";
3
- import { rehypeStreamingChunks } from "./streaming";
4
-
5
- function text(value: string): HastText {
6
- return { type: "text", value } as HastText;
7
- }
8
-
9
- function paragraph(...children: Array<HastText | HastElement>): HastElement {
10
- return { type: "element", tagName: "p", properties: {}, children } as HastElement;
11
- }
12
-
13
- function chunkClasses(root: HastRoot): string[][] {
14
- const out: string[][] = [];
15
- const walk = (node: HastRoot | HastElement): void => {
16
- for (const child of node.children) {
17
- if (child.type !== "element") continue;
18
- const className = (child.properties?.className as string[] | undefined) ?? [];
19
- if (className.includes("streaming-chunk")) out.push(className);
20
- walk(child);
21
- }
22
- };
23
- walk(root);
24
- return out;
25
- }
26
-
27
- describe("rehypeStreamingChunks", () => {
28
- test("marks only the newest two phrases so brightness follows the reveal cadence without animation", () => {
29
- const tree = { type: "root", children: [paragraph(text("One, two, three, four."))] } as HastRoot;
30
- rehypeStreamingChunks()(tree);
31
- expect(chunkClasses(tree)).toEqual([
32
- ["streaming-chunk"],
33
- ["streaming-chunk"],
34
- ["streaming-chunk", "streaming-chunk-recent"],
35
- ["streaming-chunk", "streaming-chunk-latest"],
36
- ]);
37
- });
38
-
39
- test("a single phrase is the latest one and there is no recent phrase", () => {
40
- const tree = { type: "root", children: [paragraph(text("Hello."))] } as HastRoot;
41
- rehypeStreamingChunks()(tree);
42
- expect(chunkClasses(tree)).toEqual([["streaming-chunk", "streaming-chunk-latest"]]);
43
- });
44
-
45
- test("the newest phrase is found across block boundaries", () => {
46
- const tree = {
47
- type: "root",
48
- children: [paragraph(text("First, second.")), paragraph(text("Third."))],
49
- } as HastRoot;
50
- rehypeStreamingChunks()(tree);
51
- expect(chunkClasses(tree)).toEqual([
52
- ["streaming-chunk"],
53
- ["streaming-chunk", "streaming-chunk-recent"],
54
- ["streaming-chunk", "streaming-chunk-latest"],
55
- ]);
56
- });
57
- });