@elabs-ai/components-ai 4.0.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/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/_audio-player-media-chrome-KA5DY54G.js +81 -0
- package/dist/_audio-player-media-chrome-KA5DY54G.js.map +1 -0
- package/dist/_flow-boundary-D63PJ65S.js +186 -0
- package/dist/_flow-boundary-D63PJ65S.js.map +1 -0
- package/dist/_interactive-terminal-xterm-ATJ5EW3G.js +11 -0
- package/dist/_interactive-terminal-xterm-ATJ5EW3G.js.map +1 -0
- package/dist/_persona-rive-RFR2EUWP.js +164 -0
- package/dist/_persona-rive-RFR2EUWP.js.map +1 -0
- package/dist/index.d.ts +4079 -0
- package/dist/index.js +11770 -0
- package/dist/index.js.map +1 -0
- package/package.json +87 -0
- package/src/_audio-player-media-chrome.tsx +146 -0
- package/src/_chat-shell-rail.tsx +18 -0
- package/src/_code-block-theme.test.ts +134 -0
- package/src/_code-block-theme.ts +184 -0
- package/src/_flow-boundary.tsx +237 -0
- package/src/_flow-lazy.ts +34 -0
- package/src/_interactive-terminal-xterm.ts +32 -0
- package/src/_lazy-mermaid.test.ts +101 -0
- package/src/_lazy-mermaid.ts +117 -0
- package/src/_persona-rive.tsx +252 -0
- package/src/_streamdown-i18n.ts +119 -0
- package/src/agent-timeline.stories.tsx +66 -0
- package/src/agent-timeline.test.tsx +74 -0
- package/src/agent-timeline.tsx +106 -0
- package/src/agent.tsx +113 -0
- package/src/agentic-workspace.stories.tsx +1099 -0
- package/src/artifact.stories.tsx +62 -0
- package/src/artifact.test.tsx +112 -0
- package/src/artifact.tsx +167 -0
- package/src/asset-preview.stories.tsx +100 -0
- package/src/asset-preview.test.tsx +126 -0
- package/src/asset-preview.tsx +218 -0
- package/src/attachments.tsx +393 -0
- package/src/audio-player.stories.tsx +99 -0
- package/src/audio-player.tsx +170 -0
- package/src/blocks-ai-composer.stories.tsx +83 -0
- package/src/canvas.stories.tsx +142 -0
- package/src/canvas.tsx +29 -0
- package/src/chain-of-thought.tsx +193 -0
- package/src/chat-greeting.stories.tsx +96 -0
- package/src/chat-greeting.test.tsx +91 -0
- package/src/chat-greeting.tsx +91 -0
- package/src/chat-shell.stories.tsx +123 -0
- package/src/chat-shell.test.tsx +113 -0
- package/src/chat-shell.tsx +97 -0
- package/src/chat.stories.tsx +99 -0
- package/src/checkpoint.tsx +54 -0
- package/src/code-block.stories.tsx +81 -0
- package/src/code-block.test.tsx +191 -0
- package/src/code-block.tsx +673 -0
- package/src/commit.tsx +343 -0
- package/src/composer.stories.tsx +188 -0
- package/src/composer.test.tsx +182 -0
- package/src/composer.tsx +202 -0
- package/src/confirmation.stories.tsx +61 -0
- package/src/confirmation.test.tsx +136 -0
- package/src/confirmation.tsx +273 -0
- package/src/connection.tsx +23 -0
- package/src/context-panel.stories.tsx +137 -0
- package/src/context-panel.test.tsx +198 -0
- package/src/context-panel.tsx +609 -0
- package/src/context.stories.tsx +16 -0
- package/src/context.tsx +363 -0
- package/src/controls.tsx +20 -0
- package/src/conversation.stories.tsx +26 -0
- package/src/conversation.test.tsx +123 -0
- package/src/conversation.tsx +143 -0
- package/src/dark-theme-variant.test.ts +47 -0
- package/src/edge.tsx +33 -0
- package/src/environment-variables.tsx +304 -0
- package/src/file-tree.stories.tsx +55 -0
- package/src/file-tree.test.tsx +101 -0
- package/src/file-tree.tsx +390 -0
- package/src/gallery.stories.tsx +182 -0
- package/src/gallery.test.tsx +150 -0
- package/src/gallery.tsx +737 -0
- package/src/grouped-parts.stories.tsx +104 -0
- package/src/grouped-parts.test.tsx +167 -0
- package/src/grouped-parts.tsx +247 -0
- package/src/image.stories.tsx +67 -0
- package/src/image.test.tsx +105 -0
- package/src/image.tsx +115 -0
- package/src/index.ts +93 -0
- package/src/inline-citation.stories.tsx +91 -0
- package/src/inline-citation.test.tsx +96 -0
- package/src/inline-citation.tsx +314 -0
- package/src/interactive-terminal.stories.tsx +165 -0
- package/src/interactive-terminal.test.tsx +448 -0
- package/src/interactive-terminal.tsx +444 -0
- package/src/jsx-preview.stories.tsx +265 -0
- package/src/jsx-preview.test.tsx +75 -0
- package/src/jsx-preview.tsx +409 -0
- package/src/markdown-view.stories.tsx +57 -0
- package/src/markdown-view.test.tsx +36 -0
- package/src/markdown-view.tsx +113 -0
- package/src/message-edit.stories.tsx +150 -0
- package/src/message-edit.test.tsx +115 -0
- package/src/message-edit.tsx +336 -0
- package/src/message-feedback.stories.tsx +53 -0
- package/src/message-feedback.test.tsx +62 -0
- package/src/message-feedback.tsx +117 -0
- package/src/message-form-spec.ts +349 -0
- package/src/message-form.stories.tsx +182 -0
- package/src/message-form.test.tsx +227 -0
- package/src/message-form.tsx +845 -0
- package/src/message-table-spec.ts +281 -0
- package/src/message-table.stories.tsx +176 -0
- package/src/message-table.test.tsx +144 -0
- package/src/message-table.tsx +366 -0
- package/src/message.stories.tsx +262 -0
- package/src/message.test.tsx +508 -0
- package/src/message.tsx +619 -0
- package/src/mic-selector.tsx +339 -0
- package/src/microcopy.test.tsx +123 -0
- package/src/model-selector.stories.tsx +73 -0
- package/src/model-selector.test.tsx +55 -0
- package/src/model-selector.tsx +225 -0
- package/src/motion-config.tsx +49 -0
- package/src/node.tsx +71 -0
- package/src/open-in-chat.tsx +340 -0
- package/src/package-info.tsx +205 -0
- package/src/panel.tsx +20 -0
- package/src/part-groups.ts +258 -0
- package/src/persona-sources.ts +59 -0
- package/src/persona.stories.tsx +111 -0
- package/src/persona.test.tsx +67 -0
- package/src/persona.tsx +148 -0
- package/src/plan.tsx +135 -0
- package/src/prompt-input.stories.tsx +261 -0
- package/src/prompt-input.test.tsx +392 -0
- package/src/prompt-input.tsx +1668 -0
- package/src/queue.tsx +237 -0
- package/src/reasoning.stories.tsx +81 -0
- package/src/reasoning.test.tsx +50 -0
- package/src/reasoning.tsx +229 -0
- package/src/sandbox.stories.tsx +62 -0
- package/src/sandbox.test.tsx +42 -0
- package/src/sandbox.tsx +149 -0
- package/src/schema-display.tsx +412 -0
- package/src/selection-toolbar.stories.tsx +86 -0
- package/src/selection-toolbar.test.tsx +89 -0
- package/src/selection-toolbar.tsx +192 -0
- package/src/shimmer.stories.tsx +10 -0
- package/src/shimmer.tsx +81 -0
- package/src/snippet.stories.tsx +19 -0
- package/src/snippet.test.tsx +116 -0
- package/src/snippet.tsx +138 -0
- package/src/sources.stories.tsx +34 -0
- package/src/sources.test.tsx +129 -0
- package/src/sources.tsx +93 -0
- package/src/speech-input.tsx +312 -0
- package/src/stack-trace.tsx +479 -0
- package/src/streamdown-i18n.test.tsx +163 -0
- package/src/suggestion.stories.tsx +75 -0
- package/src/suggestion.test.tsx +72 -0
- package/src/suggestion.tsx +120 -0
- package/src/task.stories.tsx +22 -0
- package/src/task.test.tsx +36 -0
- package/src/task.tsx +89 -0
- package/src/templates-ai-assistant.stories.tsx +142 -0
- package/src/terminal.tsx +244 -0
- package/src/test-results.stories.tsx +177 -0
- package/src/test-results.test.tsx +241 -0
- package/src/test-results.tsx +408 -0
- package/src/tool-result-card.stories.tsx +143 -0
- package/src/tool-result-card.test.tsx +72 -0
- package/src/tool-result-card.tsx +86 -0
- package/src/tool.stories.tsx +60 -0
- package/src/tool.test.tsx +63 -0
- package/src/tool.tsx +235 -0
- package/src/toolbar.tsx +44 -0
- package/src/transcription.tsx +118 -0
- package/src/voice-selector.tsx +469 -0
- package/src/web-preview.stories.tsx +67 -0
- package/src/web-preview.test.tsx +117 -0
- package/src/web-preview.tsx +283 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { BUILT_IN_THEME_META, BUILT_IN_THEMES } from "@elabs-ai/components-tokens";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Regression lock for #3: the Tailwind `dark:` custom variant in themes.css must
|
|
8
|
+
* match EVERY dark-appearance theme. Components like CodeBlock select their dark
|
|
9
|
+
* palette via `dark:` overrides; if a dark theme is missing from the variant it
|
|
10
|
+
* renders light-on-dark (illegible). This catches a new dark theme being added
|
|
11
|
+
* without updating the variant.
|
|
12
|
+
*/
|
|
13
|
+
const themesCssPath = [
|
|
14
|
+
resolve(process.cwd(), "../tokens/src/themes.css"), // cwd = packages/ai
|
|
15
|
+
resolve(process.cwd(), "packages/tokens/src/themes.css"), // cwd = repo root
|
|
16
|
+
resolve(process.cwd(), "../../packages/tokens/src/themes.css"),
|
|
17
|
+
].find((candidate) => existsSync(candidate));
|
|
18
|
+
|
|
19
|
+
if (!themesCssPath) {
|
|
20
|
+
throw new Error(`themes.css not found from ${process.cwd()}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const themesCss = readFileSync(themesCssPath, "utf8");
|
|
24
|
+
|
|
25
|
+
const darkVariant = themesCss.match(/@custom-variant dark \(([^;]*)\)/);
|
|
26
|
+
const darkVariantSelector = darkVariant?.[1] ?? "";
|
|
27
|
+
|
|
28
|
+
// The BUILT-IN dark themes only. A consumer theme cannot be covered here by
|
|
29
|
+
// construction — its `[data-theme]` selector is not in OUR themes.css — which is
|
|
30
|
+
// why a consumer authoring a dark theme must add it to their own `dark:` variant
|
|
31
|
+
// (or, better, rely on semantic tokens, which need no variant at all). See
|
|
32
|
+
// @.claude/rules/theming.md.
|
|
33
|
+
const darkThemes = BUILT_IN_THEMES.filter((name) => BUILT_IN_THEME_META[name].dark);
|
|
34
|
+
|
|
35
|
+
describe("dark: custom variant", () => {
|
|
36
|
+
it("is declared in themes.css", () => {
|
|
37
|
+
expect(darkVariantSelector).not.toBe("");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("covers at least the known dark themes (dark)", () => {
|
|
41
|
+
expect(darkThemes).toEqual(expect.arrayContaining(["dark"]));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it.each(darkThemes)("matches [data-theme=%s]", (name) => {
|
|
45
|
+
expect(darkVariantSelector).toContain(`[data-theme="${name}"]`);
|
|
46
|
+
});
|
|
47
|
+
});
|
package/src/edge.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { EdgeProps } from "@xyflow/react";
|
|
4
|
+
import { Suspense } from "react";
|
|
5
|
+
|
|
6
|
+
import { lazyFlowPart } from "./_flow-lazy";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* React Flow lives behind a dynamic import — see `_flow-lazy.ts` and ADR 0019.
|
|
10
|
+
* `EdgeProps` above is a TYPE import and erases.
|
|
11
|
+
*/
|
|
12
|
+
const AnimatedImpl = lazyFlowPart<EdgeProps>((m) => m.EdgeAnimated);
|
|
13
|
+
const TemporaryImpl = lazyFlowPart<EdgeProps>((m) => m.EdgeTemporary);
|
|
14
|
+
|
|
15
|
+
// Edges render inside React Flow's `<svg>`, so the fallback must be `null` —
|
|
16
|
+
// there is no box to reserve, and the engine chunk is the one the surrounding
|
|
17
|
+
// `<Canvas>` already fetched.
|
|
18
|
+
const Animated = (props: EdgeProps) => (
|
|
19
|
+
<Suspense fallback={null}>
|
|
20
|
+
<AnimatedImpl {...props} />
|
|
21
|
+
</Suspense>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const Temporary = (props: EdgeProps) => (
|
|
25
|
+
<Suspense fallback={null}>
|
|
26
|
+
<TemporaryImpl {...props} />
|
|
27
|
+
</Suspense>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const Edge = {
|
|
31
|
+
Animated,
|
|
32
|
+
Temporary,
|
|
33
|
+
};
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Badge } from "@elabs-ai/components-ui";
|
|
4
|
+
import { Button } from "@elabs-ai/components-ui";
|
|
5
|
+
import { Switch } from "@elabs-ai/components-ui";
|
|
6
|
+
import { cn } from "@elabs-ai/components-ui/lib/cn";
|
|
7
|
+
import { useLocale } from "@elabs-ai/components-ui";
|
|
8
|
+
import { CheckIcon, CopyIcon, EyeIcon, EyeOffIcon } from "lucide-react";
|
|
9
|
+
import type { ComponentProps, HTMLAttributes } from "react";
|
|
10
|
+
import {
|
|
11
|
+
createContext,
|
|
12
|
+
useCallback,
|
|
13
|
+
useContext,
|
|
14
|
+
useEffect,
|
|
15
|
+
useMemo,
|
|
16
|
+
useRef,
|
|
17
|
+
useState,
|
|
18
|
+
} from "react";
|
|
19
|
+
|
|
20
|
+
interface EnvironmentVariablesContextType {
|
|
21
|
+
showValues: boolean;
|
|
22
|
+
setShowValues: (show: boolean) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Default noop for context default value
|
|
26
|
+
// oxlint-disable-next-line eslint(no-empty-function)
|
|
27
|
+
const noop = () => {};
|
|
28
|
+
|
|
29
|
+
const EnvironmentVariablesContext = createContext<EnvironmentVariablesContextType>({
|
|
30
|
+
setShowValues: noop,
|
|
31
|
+
showValues: false,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type EnvironmentVariablesProps = HTMLAttributes<HTMLDivElement> & {
|
|
35
|
+
showValues?: boolean;
|
|
36
|
+
defaultShowValues?: boolean;
|
|
37
|
+
onShowValuesChange?: (show: boolean) => void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const EnvironmentVariables = ({
|
|
41
|
+
showValues: controlledShowValues,
|
|
42
|
+
defaultShowValues = false,
|
|
43
|
+
onShowValuesChange,
|
|
44
|
+
className,
|
|
45
|
+
children,
|
|
46
|
+
...props
|
|
47
|
+
}: EnvironmentVariablesProps) => {
|
|
48
|
+
const [internalShowValues, setInternalShowValues] = useState(defaultShowValues);
|
|
49
|
+
const showValues = controlledShowValues ?? internalShowValues;
|
|
50
|
+
|
|
51
|
+
const setShowValues = useCallback(
|
|
52
|
+
(show: boolean) => {
|
|
53
|
+
setInternalShowValues(show);
|
|
54
|
+
onShowValuesChange?.(show);
|
|
55
|
+
},
|
|
56
|
+
[onShowValuesChange],
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const contextValue = useMemo(() => ({ setShowValues, showValues }), [setShowValues, showValues]);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<EnvironmentVariablesContext.Provider value={contextValue}>
|
|
63
|
+
<div className={cn("rounded-lg border bg-background", className)} {...props}>
|
|
64
|
+
{children}
|
|
65
|
+
</div>
|
|
66
|
+
</EnvironmentVariablesContext.Provider>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type EnvironmentVariablesHeaderProps = HTMLAttributes<HTMLDivElement>;
|
|
71
|
+
|
|
72
|
+
export const EnvironmentVariablesHeader = ({
|
|
73
|
+
className,
|
|
74
|
+
children,
|
|
75
|
+
...props
|
|
76
|
+
}: EnvironmentVariablesHeaderProps) => (
|
|
77
|
+
<div className={cn("flex items-center justify-between border-b px-4 py-3", className)} {...props}>
|
|
78
|
+
{children}
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
export type EnvironmentVariablesTitleProps = HTMLAttributes<HTMLHeadingElement>;
|
|
83
|
+
|
|
84
|
+
export const EnvironmentVariablesTitle = ({
|
|
85
|
+
className,
|
|
86
|
+
children,
|
|
87
|
+
...props
|
|
88
|
+
}: EnvironmentVariablesTitleProps) => (
|
|
89
|
+
<h3 className={cn("font-medium text-sm", className)} {...props}>
|
|
90
|
+
{children ?? "Environment Variables"}
|
|
91
|
+
</h3>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
export type EnvironmentVariablesToggleProps = ComponentProps<typeof Switch>;
|
|
95
|
+
|
|
96
|
+
export const EnvironmentVariablesToggle = ({
|
|
97
|
+
className,
|
|
98
|
+
...props
|
|
99
|
+
}: EnvironmentVariablesToggleProps) => {
|
|
100
|
+
const { t } = useLocale();
|
|
101
|
+
const { showValues, setShowValues } = useContext(EnvironmentVariablesContext);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div className={cn("flex items-center gap-2", className)}>
|
|
105
|
+
<span className="text-muted-foreground text-xs">
|
|
106
|
+
{showValues ? <EyeIcon size={14} /> : <EyeOffIcon size={14} />}
|
|
107
|
+
</span>
|
|
108
|
+
<Switch
|
|
109
|
+
aria-label={t("ai.environmentVariables.toggleVisibility")}
|
|
110
|
+
checked={showValues}
|
|
111
|
+
onCheckedChange={setShowValues}
|
|
112
|
+
{...props}
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export type EnvironmentVariablesContentProps = HTMLAttributes<HTMLDivElement>;
|
|
119
|
+
|
|
120
|
+
export const EnvironmentVariablesContent = ({
|
|
121
|
+
className,
|
|
122
|
+
children,
|
|
123
|
+
...props
|
|
124
|
+
}: EnvironmentVariablesContentProps) => (
|
|
125
|
+
<div className={cn("divide-y", className)} {...props}>
|
|
126
|
+
{children}
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
interface EnvironmentVariableContextType {
|
|
131
|
+
name: string;
|
|
132
|
+
value: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const EnvironmentVariableContext = createContext<EnvironmentVariableContextType>({
|
|
136
|
+
name: "",
|
|
137
|
+
value: "",
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
export type EnvironmentVariableGroupProps = HTMLAttributes<HTMLDivElement>;
|
|
141
|
+
|
|
142
|
+
export const EnvironmentVariableGroup = ({
|
|
143
|
+
className,
|
|
144
|
+
children,
|
|
145
|
+
...props
|
|
146
|
+
}: EnvironmentVariableGroupProps) => (
|
|
147
|
+
<div className={cn("flex items-center gap-2", className)} {...props}>
|
|
148
|
+
{children}
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
export type EnvironmentVariableNameProps = HTMLAttributes<HTMLSpanElement>;
|
|
153
|
+
|
|
154
|
+
export const EnvironmentVariableName = ({
|
|
155
|
+
className,
|
|
156
|
+
children,
|
|
157
|
+
...props
|
|
158
|
+
}: EnvironmentVariableNameProps) => {
|
|
159
|
+
const { name } = useContext(EnvironmentVariableContext);
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<span className={cn("font-mono text-sm", className)} {...props}>
|
|
163
|
+
{children ?? name}
|
|
164
|
+
</span>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export type EnvironmentVariableValueProps = HTMLAttributes<HTMLSpanElement>;
|
|
169
|
+
|
|
170
|
+
export const EnvironmentVariableValue = ({
|
|
171
|
+
className,
|
|
172
|
+
children,
|
|
173
|
+
...props
|
|
174
|
+
}: EnvironmentVariableValueProps) => {
|
|
175
|
+
const { value } = useContext(EnvironmentVariableContext);
|
|
176
|
+
const { showValues } = useContext(EnvironmentVariablesContext);
|
|
177
|
+
|
|
178
|
+
const displayValue = showValues ? value : "•".repeat(Math.min(value.length, 20));
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<span
|
|
182
|
+
className={cn(
|
|
183
|
+
"font-mono text-muted-foreground text-sm",
|
|
184
|
+
!showValues && "select-none",
|
|
185
|
+
className,
|
|
186
|
+
)}
|
|
187
|
+
{...props}
|
|
188
|
+
>
|
|
189
|
+
{children ?? displayValue}
|
|
190
|
+
</span>
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export type EnvironmentVariableProps = HTMLAttributes<HTMLDivElement> & {
|
|
195
|
+
name: string;
|
|
196
|
+
value: string;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export const EnvironmentVariable = ({
|
|
200
|
+
name,
|
|
201
|
+
value,
|
|
202
|
+
className,
|
|
203
|
+
children,
|
|
204
|
+
...props
|
|
205
|
+
}: EnvironmentVariableProps) => {
|
|
206
|
+
const envVarContextValue = useMemo(() => ({ name, value }), [name, value]);
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<EnvironmentVariableContext.Provider value={envVarContextValue}>
|
|
210
|
+
<div
|
|
211
|
+
className={cn("flex items-center justify-between gap-4 px-4 py-3", className)}
|
|
212
|
+
{...props}
|
|
213
|
+
>
|
|
214
|
+
{children ?? (
|
|
215
|
+
<>
|
|
216
|
+
<div className="flex items-center gap-2">
|
|
217
|
+
<EnvironmentVariableName />
|
|
218
|
+
</div>
|
|
219
|
+
<EnvironmentVariableValue />
|
|
220
|
+
</>
|
|
221
|
+
)}
|
|
222
|
+
</div>
|
|
223
|
+
</EnvironmentVariableContext.Provider>
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export type EnvironmentVariableCopyButtonProps = ComponentProps<typeof Button> & {
|
|
228
|
+
onCopy?: () => void;
|
|
229
|
+
onError?: (error: Error) => void;
|
|
230
|
+
timeout?: number;
|
|
231
|
+
copyFormat?: "name" | "value" | "export";
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export const EnvironmentVariableCopyButton = ({
|
|
235
|
+
onCopy,
|
|
236
|
+
onError,
|
|
237
|
+
timeout = 2000,
|
|
238
|
+
copyFormat = "value",
|
|
239
|
+
children,
|
|
240
|
+
className,
|
|
241
|
+
...props
|
|
242
|
+
}: EnvironmentVariableCopyButtonProps) => {
|
|
243
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
244
|
+
const timeoutRef = useRef<number>(0);
|
|
245
|
+
const { name, value } = useContext(EnvironmentVariableContext);
|
|
246
|
+
|
|
247
|
+
const getTextToCopy = useCallback((): string => {
|
|
248
|
+
const formatMap = {
|
|
249
|
+
export: () => `export ${name}="${value}"`,
|
|
250
|
+
name: () => name,
|
|
251
|
+
value: () => value,
|
|
252
|
+
};
|
|
253
|
+
return formatMap[copyFormat]();
|
|
254
|
+
}, [name, value, copyFormat]);
|
|
255
|
+
|
|
256
|
+
const copyToClipboard = useCallback(async () => {
|
|
257
|
+
if (typeof window === "undefined" || !navigator?.clipboard?.writeText) {
|
|
258
|
+
onError?.(new Error("Clipboard API not available"));
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
try {
|
|
263
|
+
await navigator.clipboard.writeText(getTextToCopy());
|
|
264
|
+
setIsCopied(true);
|
|
265
|
+
onCopy?.();
|
|
266
|
+
timeoutRef.current = window.setTimeout(() => setIsCopied(false), timeout);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
onError?.(error as Error);
|
|
269
|
+
}
|
|
270
|
+
}, [getTextToCopy, onCopy, onError, timeout]);
|
|
271
|
+
|
|
272
|
+
useEffect(
|
|
273
|
+
() => () => {
|
|
274
|
+
window.clearTimeout(timeoutRef.current);
|
|
275
|
+
},
|
|
276
|
+
[],
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const Icon = isCopied ? CheckIcon : CopyIcon;
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<Button
|
|
283
|
+
className={cn("size-6 shrink-0", className)}
|
|
284
|
+
onClick={copyToClipboard}
|
|
285
|
+
size="icon"
|
|
286
|
+
variant="ghost"
|
|
287
|
+
{...props}
|
|
288
|
+
>
|
|
289
|
+
{children ?? <Icon size={12} />}
|
|
290
|
+
</Button>
|
|
291
|
+
);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export type EnvironmentVariableRequiredProps = ComponentProps<typeof Badge>;
|
|
295
|
+
|
|
296
|
+
export const EnvironmentVariableRequired = ({
|
|
297
|
+
className,
|
|
298
|
+
children,
|
|
299
|
+
...props
|
|
300
|
+
}: EnvironmentVariableRequiredProps) => (
|
|
301
|
+
<Badge className={cn("text-xs", className)} variant="secondary" {...props}>
|
|
302
|
+
{children ?? "Required"}
|
|
303
|
+
</Badge>
|
|
304
|
+
);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { fn } from "storybook/test";
|
|
3
|
+
import type { ContextAsset } from "./context-panel";
|
|
4
|
+
import { FileTree, FileTreeFile, FileTreeFolder, ProducedAssetTree } from "./file-tree";
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "AI/FileTree",
|
|
8
|
+
component: FileTree,
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
parameters: { layout: "padded" },
|
|
11
|
+
} satisfies Meta<typeof FileTree>;
|
|
12
|
+
export default meta;
|
|
13
|
+
type Story = StoryObj<typeof meta>;
|
|
14
|
+
|
|
15
|
+
/** Default `code` variant — the IDE source tree (mono, boxed). Unchanged look. */
|
|
16
|
+
export const Default: Story = {
|
|
17
|
+
render: () => (
|
|
18
|
+
<FileTree className="max-w-sm" defaultExpanded={new Set(["src"])}>
|
|
19
|
+
<FileTreeFolder path="src" name="src">
|
|
20
|
+
<FileTreeFile path="src/index.ts" name="index.ts" />
|
|
21
|
+
<FileTreeFile path="src/app.tsx" name="app.tsx" />
|
|
22
|
+
</FileTreeFolder>
|
|
23
|
+
<FileTreeFile path="package.json" name="package.json" />
|
|
24
|
+
</FileTree>
|
|
25
|
+
),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** `document` variant — sans, box-free: for trees of documents, not source. */
|
|
29
|
+
export const DocumentVariant: Story = {
|
|
30
|
+
render: () => (
|
|
31
|
+
<FileTree variant="document" className="max-w-sm">
|
|
32
|
+
<FileTreeFile path="board-note.md" name="board-note.md" />
|
|
33
|
+
<FileTreeFile path="summary.md" name="summary.md" />
|
|
34
|
+
</FileTree>
|
|
35
|
+
),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const ASSETS: ContextAsset[] = [
|
|
39
|
+
{ id: "board-note", name: "board-note.md", type: "markdown", content: "# Note" },
|
|
40
|
+
{ id: "variance-query", name: "variance-check.sql", type: "sql", content: "SELECT 1;" },
|
|
41
|
+
{ id: "revenue", name: "revenue.csv", type: "csv", content: "a,b\n1,2" },
|
|
42
|
+
{ id: "trend", name: "trend.png", type: "image" },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* ProducedAssetTree — the document-variant preset (#193, research 04 §4):
|
|
47
|
+
* asset-type icons first-class; selection feeds the ContextPanel drill-in.
|
|
48
|
+
*/
|
|
49
|
+
export const ProducedAssets: Story = {
|
|
50
|
+
render: () => (
|
|
51
|
+
<div className="max-w-80">
|
|
52
|
+
<ProducedAssetTree assets={ASSETS} selectedId="board-note" onSelect={fn()} />
|
|
53
|
+
</div>
|
|
54
|
+
),
|
|
55
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import type { ContextAsset } from "./context-panel";
|
|
5
|
+
import { FileTree, FileTreeFile, FileTreeFolder, ProducedAssetTree } from "./file-tree";
|
|
6
|
+
|
|
7
|
+
describe("FileTree folder icons", () => {
|
|
8
|
+
it("color them with a semantic token, not a raw palette color (theme-safe)", () => {
|
|
9
|
+
const { container } = render(
|
|
10
|
+
<FileTree defaultExpanded={new Set(["src"])}>
|
|
11
|
+
<FileTreeFolder path="src" name="src">
|
|
12
|
+
<FileTreeFile path="src/index.ts" name="index.ts" />
|
|
13
|
+
</FileTreeFolder>
|
|
14
|
+
</FileTree>,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// Regression lock for #4: no raw Tailwind palette color anywhere in the tree.
|
|
18
|
+
expect(container.querySelector('[class*="text-blue-"]')).toBeNull();
|
|
19
|
+
|
|
20
|
+
// The folder glyph adapts per theme via the semantic primary token.
|
|
21
|
+
expect(container.querySelector("svg.text-primary")).not.toBeNull();
|
|
22
|
+
|
|
23
|
+
// The file glyph stays muted-foreground (the contrast that surfaced the bug).
|
|
24
|
+
expect(container.querySelector("svg.text-muted-foreground")).not.toBeNull();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("FileTree variant axis (#193, research 04 §4 ASSET-1)", () => {
|
|
29
|
+
it("keeps the IDE look by default (code variant — non-breaking)", () => {
|
|
30
|
+
const { container } = render(
|
|
31
|
+
<FileTree>
|
|
32
|
+
<FileTreeFile path="index.ts" name="index.ts" />
|
|
33
|
+
</FileTree>,
|
|
34
|
+
);
|
|
35
|
+
const root = container.firstChild as HTMLElement;
|
|
36
|
+
expect(root).toHaveClass("font-mono");
|
|
37
|
+
expect(root).toHaveClass("border");
|
|
38
|
+
expect(root).toHaveClass("bg-background");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("document variant drops the mono font and the hard box", () => {
|
|
42
|
+
const { container } = render(
|
|
43
|
+
<FileTree variant="document">
|
|
44
|
+
<FileTreeFile path="note.md" name="note.md" />
|
|
45
|
+
</FileTree>,
|
|
46
|
+
);
|
|
47
|
+
const root = container.firstChild as HTMLElement;
|
|
48
|
+
expect(root).not.toHaveClass("font-mono");
|
|
49
|
+
expect(root).not.toHaveClass("border");
|
|
50
|
+
expect(root).toHaveClass("text-body");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("ProducedAssetTree (#193 — the document-variant preset)", () => {
|
|
55
|
+
const ASSETS: ContextAsset[] = [
|
|
56
|
+
{ id: "note", name: "board-note.md", type: "markdown", content: "# Note" },
|
|
57
|
+
{ id: "rev", name: "revenue.csv", type: "csv", content: "a,b" },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
it("renders document-variant rows with asset-type icons and selects the ASSET", async () => {
|
|
61
|
+
const onSelect = vi.fn();
|
|
62
|
+
const user = userEvent.setup();
|
|
63
|
+
const { container } = render(<ProducedAssetTree assets={ASSETS} onSelect={onSelect} />);
|
|
64
|
+
|
|
65
|
+
const root = container.firstChild as HTMLElement;
|
|
66
|
+
expect(root).not.toHaveClass("font-mono");
|
|
67
|
+
// One glyph per asset, hidden from AT (decorative — the name labels the row).
|
|
68
|
+
expect(container.querySelectorAll('svg[aria-hidden="true"]')).toHaveLength(2);
|
|
69
|
+
|
|
70
|
+
await user.click(screen.getByText("revenue.csv"));
|
|
71
|
+
expect(onSelect).toHaveBeenCalledWith(ASSETS[1]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("renders a real empty state for no assets", () => {
|
|
75
|
+
render(<ProducedAssetTree assets={[]} />);
|
|
76
|
+
expect(screen.getByText("No assets produced yet.")).toBeInTheDocument();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("draws a FILE-BACKED asset from its own name, not from the closed type union", () => {
|
|
80
|
+
// A PDF reaches the rail through the `renderPreview` seam typed `code`,
|
|
81
|
+
// because `ContextAssetType` is deliberately closed (ADR 0024 §6). The
|
|
82
|
+
// type-keyed glyph would draw it as source; its name knows better.
|
|
83
|
+
const { container } = render(
|
|
84
|
+
<ProducedAssetTree
|
|
85
|
+
assets={[
|
|
86
|
+
{ id: "src", name: "query.ts", type: "code", content: "const a = 1;" },
|
|
87
|
+
{
|
|
88
|
+
id: "pdf",
|
|
89
|
+
name: "audit.pdf",
|
|
90
|
+
type: "code",
|
|
91
|
+
mediaType: "application/pdf",
|
|
92
|
+
source: { kind: "url", url: "/audit.pdf", name: "audit.pdf" },
|
|
93
|
+
},
|
|
94
|
+
]}
|
|
95
|
+
/>,
|
|
96
|
+
);
|
|
97
|
+
const [code, pdf] = [...container.querySelectorAll("svg")];
|
|
98
|
+
expect(code?.getAttribute("class")).toContain("file-code");
|
|
99
|
+
expect(pdf?.getAttribute("class")).toContain("file-text");
|
|
100
|
+
});
|
|
101
|
+
});
|