@openconsole/shadcn 0.2.4 → 0.2.5

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 (117) hide show
  1. package/README.md +460 -380
  2. package/components/ai-elements/agent.tsx +141 -0
  3. package/components/ai-elements/artifact.tsx +148 -0
  4. package/components/ai-elements/attachments.tsx +426 -0
  5. package/components/ai-elements/audio-player.tsx +231 -0
  6. package/components/ai-elements/canvas.tsx +26 -0
  7. package/components/ai-elements/chain-of-thought.tsx +222 -0
  8. package/components/ai-elements/checkpoint.tsx +71 -0
  9. package/components/ai-elements/code-block.tsx +562 -0
  10. package/components/ai-elements/commit.tsx +458 -0
  11. package/components/ai-elements/confirmation.tsx +174 -0
  12. package/components/ai-elements/connection.tsx +28 -0
  13. package/components/ai-elements/context.tsx +409 -0
  14. package/components/ai-elements/controls.tsx +18 -0
  15. package/components/ai-elements/conversation.tsx +168 -0
  16. package/components/ai-elements/edge.tsx +143 -0
  17. package/components/ai-elements/environment-variables.tsx +324 -0
  18. package/components/ai-elements/file-tree.tsx +304 -0
  19. package/components/ai-elements/image.tsx +24 -0
  20. package/components/ai-elements/index.ts +51 -0
  21. package/components/ai-elements/inline-citation.tsx +296 -0
  22. package/components/ai-elements/jsx-preview.tsx +310 -0
  23. package/components/ai-elements/message.tsx +360 -0
  24. package/components/ai-elements/mic-selector.tsx +375 -0
  25. package/components/ai-elements/model-selector.tsx +213 -0
  26. package/components/ai-elements/node.tsx +71 -0
  27. package/components/ai-elements/open-in-chat.tsx +370 -0
  28. package/components/ai-elements/package-info.tsx +239 -0
  29. package/components/ai-elements/panel.tsx +15 -0
  30. package/components/ai-elements/persona.tsx +306 -0
  31. package/components/ai-elements/plan.tsx +147 -0
  32. package/components/ai-elements/prompt-input.tsx +1463 -0
  33. package/components/ai-elements/queue.tsx +274 -0
  34. package/components/ai-elements/reasoning.tsx +228 -0
  35. package/components/ai-elements/sandbox.tsx +132 -0
  36. package/components/ai-elements/schema-display.tsx +471 -0
  37. package/components/ai-elements/shimmer.tsx +77 -0
  38. package/components/ai-elements/snippet.tsx +145 -0
  39. package/components/ai-elements/sources.tsx +77 -0
  40. package/components/ai-elements/speech-input.tsx +323 -0
  41. package/components/ai-elements/stack-trace.tsx +528 -0
  42. package/components/ai-elements/suggestion.tsx +57 -0
  43. package/components/ai-elements/task.tsx +87 -0
  44. package/components/ai-elements/terminal.tsx +273 -0
  45. package/components/ai-elements/test-results.tsx +496 -0
  46. package/components/ai-elements/tool.tsx +173 -0
  47. package/components/ai-elements/toolbar.tsx +16 -0
  48. package/components/ai-elements/transcription.tsx +125 -0
  49. package/components/ai-elements/voice-selector.tsx +524 -0
  50. package/components/ai-elements/web-preview.tsx +281 -0
  51. package/components/index.ts +3 -0
  52. package/{accordion.tsx → components/ui/accordion.tsx} +66 -66
  53. package/{alert-dialog.tsx → components/ui/alert-dialog.tsx} +196 -196
  54. package/{alert.tsx → components/ui/alert.tsx} +66 -66
  55. package/{aspect-ratio.tsx → components/ui/aspect-ratio.tsx} +11 -11
  56. package/{avatar.tsx → components/ui/avatar.tsx} +53 -53
  57. package/{badge.tsx → components/ui/badge.tsx} +46 -46
  58. package/{breadcrumb.tsx → components/ui/breadcrumb.tsx} +109 -109
  59. package/{button-group.tsx → components/ui/button-group.tsx} +83 -83
  60. package/{button.tsx → components/ui/button.tsx} +60 -60
  61. package/{calendar.tsx → components/ui/calendar.tsx} +219 -219
  62. package/{card.tsx → components/ui/card.tsx} +92 -92
  63. package/{carousel.tsx → components/ui/carousel.tsx} +241 -241
  64. package/{chart.tsx → components/ui/chart.tsx} +374 -374
  65. package/{checkbox.tsx → components/ui/checkbox.tsx} +32 -32
  66. package/{collapsible.tsx → components/ui/collapsible.tsx} +33 -33
  67. package/{command.tsx → components/ui/command.tsx} +184 -184
  68. package/{context-menu.tsx → components/ui/context-menu.tsx} +252 -252
  69. package/{dialog.tsx → components/ui/dialog.tsx} +143 -143
  70. package/{direction.tsx → components/ui/direction.tsx} +22 -22
  71. package/{drawer.tsx → components/ui/drawer.tsx} +135 -135
  72. package/{dropdown-menu.tsx → components/ui/dropdown-menu.tsx} +257 -257
  73. package/{empty.tsx → components/ui/empty.tsx} +104 -104
  74. package/{field.tsx → components/ui/field.tsx} +248 -248
  75. package/{form.tsx → components/ui/form.tsx} +167 -167
  76. package/{hover-card.tsx → components/ui/hover-card.tsx} +44 -44
  77. package/{icon.tsx → components/ui/icon.tsx} +55 -55
  78. package/components/ui/index.ts +59 -0
  79. package/{input-group.tsx → components/ui/input-group.tsx} +170 -170
  80. package/{input-otp.tsx → components/ui/input-otp.tsx} +77 -77
  81. package/{input.tsx → components/ui/input.tsx} +21 -21
  82. package/{item.tsx → components/ui/item.tsx} +193 -193
  83. package/{kbd.tsx → components/ui/kbd.tsx} +28 -28
  84. package/{label.tsx → components/ui/label.tsx} +24 -24
  85. package/{menubar.tsx → components/ui/menubar.tsx} +276 -276
  86. package/{native-select.tsx → components/ui/native-select.tsx} +62 -62
  87. package/{navigation-menu.tsx → components/ui/navigation-menu.tsx} +168 -168
  88. package/{pagination.tsx → components/ui/pagination.tsx} +127 -127
  89. package/{popover.tsx → components/ui/popover.tsx} +89 -89
  90. package/{progress.tsx → components/ui/progress.tsx} +31 -31
  91. package/{radio-group.tsx → components/ui/radio-group.tsx} +45 -45
  92. package/{resizable.tsx → components/ui/resizable.tsx} +53 -53
  93. package/{scroll-area.tsx → components/ui/scroll-area.tsx} +58 -58
  94. package/{select.tsx → components/ui/select.tsx} +187 -187
  95. package/{separator.tsx → components/ui/separator.tsx} +28 -28
  96. package/{sheet.tsx → components/ui/sheet.tsx} +139 -139
  97. package/{sidebar.tsx → components/ui/sidebar.tsx} +724 -724
  98. package/{skeleton.tsx → components/ui/skeleton.tsx} +13 -13
  99. package/{slider.tsx → components/ui/slider.tsx} +63 -63
  100. package/{sonner.tsx → components/ui/sonner.tsx} +40 -40
  101. package/{spinner.tsx → components/ui/spinner.tsx} +16 -16
  102. package/{switch.tsx → components/ui/switch.tsx} +35 -35
  103. package/{table.tsx → components/ui/table.tsx} +116 -116
  104. package/{tabs.tsx → components/ui/tabs.tsx} +66 -66
  105. package/{textarea.tsx → components/ui/textarea.tsx} +18 -18
  106. package/{toggle-group.tsx → components/ui/toggle-group.tsx} +83 -83
  107. package/{toggle.tsx → components/ui/toggle.tsx} +47 -47
  108. package/{tooltip.tsx → components/ui/tooltip.tsx} +61 -61
  109. package/hooks/index.ts +1 -1
  110. package/hooks/use-mobile.ts +19 -19
  111. package/index.ts +3 -59
  112. package/lib/index.ts +1 -1
  113. package/lib/utils.ts +6 -6
  114. package/package.json +79 -1
  115. package/styles.css +124 -124
  116. package/tsconfig.json +0 -12
  117. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,143 @@
1
+ import type { EdgeProps, InternalNode, Node } from "@xyflow/react";
2
+ import {
3
+ BaseEdge,
4
+ getBezierPath,
5
+ getSimpleBezierPath,
6
+ Position,
7
+ useInternalNode,
8
+ } from "@xyflow/react";
9
+
10
+ const Temporary = ({
11
+ id,
12
+ sourceX,
13
+ sourceY,
14
+ targetX,
15
+ targetY,
16
+ sourcePosition,
17
+ targetPosition,
18
+ }: EdgeProps) => {
19
+ const [edgePath] = getSimpleBezierPath({
20
+ sourcePosition,
21
+ sourceX,
22
+ sourceY,
23
+ targetPosition,
24
+ targetX,
25
+ targetY,
26
+ });
27
+
28
+ return (
29
+ <BaseEdge
30
+ className="stroke-1 stroke-ring"
31
+ id={id}
32
+ path={edgePath}
33
+ style={{
34
+ strokeDasharray: "5, 5",
35
+ }}
36
+ />
37
+ );
38
+ };
39
+
40
+ const getHandleCoordsByPosition = (
41
+ node: InternalNode<Node>,
42
+ handlePosition: Position
43
+ ) => {
44
+ // Choose the handle type based on position - Left is for target, Right is for source
45
+ const handleType = handlePosition === Position.Left ? "target" : "source";
46
+
47
+ const handle = node.internals.handleBounds?.[handleType]?.find(
48
+ (h) => h.position === handlePosition
49
+ );
50
+
51
+ if (!handle) {
52
+ return [0, 0] as const;
53
+ }
54
+
55
+ let offsetX = handle.width / 2;
56
+ let offsetY = handle.height / 2;
57
+
58
+ // this is a tiny detail to make the markerEnd of an edge visible.
59
+ // The handle position that gets calculated has the origin top-left, so depending which side we are using, we add a little offset
60
+ // when the handlePosition is Position.Right for example, we need to add an offset as big as the handle itself in order to get the correct position
61
+ switch (handlePosition) {
62
+ case Position.Left: {
63
+ offsetX = 0;
64
+ break;
65
+ }
66
+ case Position.Right: {
67
+ offsetX = handle.width;
68
+ break;
69
+ }
70
+ case Position.Top: {
71
+ offsetY = 0;
72
+ break;
73
+ }
74
+ case Position.Bottom: {
75
+ offsetY = handle.height;
76
+ break;
77
+ }
78
+ default: {
79
+ throw new Error(`Invalid handle position: ${handlePosition}`);
80
+ }
81
+ }
82
+
83
+ const x = node.internals.positionAbsolute.x + handle.x + offsetX;
84
+ const y = node.internals.positionAbsolute.y + handle.y + offsetY;
85
+
86
+ return [x, y] as const;
87
+ };
88
+
89
+ const getEdgeParams = (
90
+ source: InternalNode<Node>,
91
+ target: InternalNode<Node>
92
+ ) => {
93
+ const sourcePos = Position.Right;
94
+ const [sx, sy] = getHandleCoordsByPosition(source, sourcePos);
95
+ const targetPos = Position.Left;
96
+ const [tx, ty] = getHandleCoordsByPosition(target, targetPos);
97
+
98
+ return {
99
+ sourcePos,
100
+ sx,
101
+ sy,
102
+ targetPos,
103
+ tx,
104
+ ty,
105
+ };
106
+ };
107
+
108
+ const Animated = ({ id, source, target, markerEnd, style }: EdgeProps) => {
109
+ const sourceNode = useInternalNode(source);
110
+ const targetNode = useInternalNode(target);
111
+
112
+ if (!(sourceNode && targetNode)) {
113
+ return null;
114
+ }
115
+
116
+ const { sx, sy, tx, ty, sourcePos, targetPos } = getEdgeParams(
117
+ sourceNode,
118
+ targetNode
119
+ );
120
+
121
+ const [edgePath] = getBezierPath({
122
+ sourcePosition: sourcePos,
123
+ sourceX: sx,
124
+ sourceY: sy,
125
+ targetPosition: targetPos,
126
+ targetX: tx,
127
+ targetY: ty,
128
+ });
129
+
130
+ return (
131
+ <>
132
+ <BaseEdge id={id} markerEnd={markerEnd} path={edgePath} style={style} />
133
+ <circle fill="var(--primary)" r="4">
134
+ <animateMotion dur="2s" path={edgePath} repeatCount="indefinite" />
135
+ </circle>
136
+ </>
137
+ );
138
+ };
139
+
140
+ export const Edge = {
141
+ Animated,
142
+ Temporary,
143
+ };
@@ -0,0 +1,324 @@
1
+ "use client";
2
+
3
+ import { Badge } from "../ui/badge";
4
+ import { Button } from "../ui/button";
5
+ import { Switch } from "../ui/switch";
6
+ import { cn } from "../../lib/utils";
7
+ import { CheckIcon, CopyIcon, EyeIcon, EyeOffIcon } from "lucide-react";
8
+ import type { ComponentProps, HTMLAttributes } from "react";
9
+ import {
10
+ createContext,
11
+ useCallback,
12
+ useContext,
13
+ useEffect,
14
+ useMemo,
15
+ useRef,
16
+ useState,
17
+ } from "react";
18
+
19
+ interface EnvironmentVariablesContextType {
20
+ showValues: boolean;
21
+ setShowValues: (show: boolean) => void;
22
+ }
23
+
24
+ // Default noop for context default value
25
+ // oxlint-disable-next-line eslint(no-empty-function)
26
+ const noop = () => {};
27
+
28
+ const EnvironmentVariablesContext =
29
+ 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] =
49
+ useState(defaultShowValues);
50
+ const showValues = controlledShowValues ?? internalShowValues;
51
+
52
+ const setShowValues = useCallback(
53
+ (show: boolean) => {
54
+ setInternalShowValues(show);
55
+ onShowValuesChange?.(show);
56
+ },
57
+ [onShowValuesChange]
58
+ );
59
+
60
+ const contextValue = useMemo(
61
+ () => ({ setShowValues, showValues }),
62
+ [setShowValues, showValues]
63
+ );
64
+
65
+ return (
66
+ <EnvironmentVariablesContext.Provider value={contextValue}>
67
+ <div
68
+ className={cn("rounded-lg border bg-background", className)}
69
+ {...props}
70
+ >
71
+ {children}
72
+ </div>
73
+ </EnvironmentVariablesContext.Provider>
74
+ );
75
+ };
76
+
77
+ export type EnvironmentVariablesHeaderProps = HTMLAttributes<HTMLDivElement>;
78
+
79
+ export const EnvironmentVariablesHeader = ({
80
+ className,
81
+ children,
82
+ ...props
83
+ }: EnvironmentVariablesHeaderProps) => (
84
+ <div
85
+ className={cn(
86
+ "flex items-center justify-between border-b px-4 py-3",
87
+ className
88
+ )}
89
+ {...props}
90
+ >
91
+ {children}
92
+ </div>
93
+ );
94
+
95
+ export type EnvironmentVariablesTitleProps = HTMLAttributes<HTMLHeadingElement>;
96
+
97
+ export const EnvironmentVariablesTitle = ({
98
+ className,
99
+ children,
100
+ ...props
101
+ }: EnvironmentVariablesTitleProps) => (
102
+ <h3 className={cn("font-medium text-sm", className)} {...props}>
103
+ {children ?? "Environment Variables"}
104
+ </h3>
105
+ );
106
+
107
+ export type EnvironmentVariablesToggleProps = ComponentProps<typeof Switch>;
108
+
109
+ export const EnvironmentVariablesToggle = ({
110
+ className,
111
+ ...props
112
+ }: EnvironmentVariablesToggleProps) => {
113
+ const { showValues, setShowValues } = useContext(EnvironmentVariablesContext);
114
+
115
+ return (
116
+ <div className={cn("flex items-center gap-2", className)}>
117
+ <span className="text-muted-foreground text-xs">
118
+ {showValues ? <EyeIcon size={14} /> : <EyeOffIcon size={14} />}
119
+ </span>
120
+ <Switch
121
+ aria-label="Toggle value visibility"
122
+ checked={showValues}
123
+ onCheckedChange={setShowValues}
124
+ {...props}
125
+ />
126
+ </div>
127
+ );
128
+ };
129
+
130
+ export type EnvironmentVariablesContentProps = HTMLAttributes<HTMLDivElement>;
131
+
132
+ export const EnvironmentVariablesContent = ({
133
+ className,
134
+ children,
135
+ ...props
136
+ }: EnvironmentVariablesContentProps) => (
137
+ <div className={cn("divide-y", className)} {...props}>
138
+ {children}
139
+ </div>
140
+ );
141
+
142
+ interface EnvironmentVariableContextType {
143
+ name: string;
144
+ value: string;
145
+ }
146
+
147
+ const EnvironmentVariableContext =
148
+ createContext<EnvironmentVariableContextType>({
149
+ name: "",
150
+ value: "",
151
+ });
152
+
153
+ export type EnvironmentVariableGroupProps = HTMLAttributes<HTMLDivElement>;
154
+
155
+ export const EnvironmentVariableGroup = ({
156
+ className,
157
+ children,
158
+ ...props
159
+ }: EnvironmentVariableGroupProps) => (
160
+ <div className={cn("flex items-center gap-2", className)} {...props}>
161
+ {children}
162
+ </div>
163
+ );
164
+
165
+ export type EnvironmentVariableNameProps = HTMLAttributes<HTMLSpanElement>;
166
+
167
+ export const EnvironmentVariableName = ({
168
+ className,
169
+ children,
170
+ ...props
171
+ }: EnvironmentVariableNameProps) => {
172
+ const { name } = useContext(EnvironmentVariableContext);
173
+
174
+ return (
175
+ <span className={cn("font-mono text-sm", className)} {...props}>
176
+ {children ?? name}
177
+ </span>
178
+ );
179
+ };
180
+
181
+ export type EnvironmentVariableValueProps = HTMLAttributes<HTMLSpanElement>;
182
+
183
+ export const EnvironmentVariableValue = ({
184
+ className,
185
+ children,
186
+ ...props
187
+ }: EnvironmentVariableValueProps) => {
188
+ const { value } = useContext(EnvironmentVariableContext);
189
+ const { showValues } = useContext(EnvironmentVariablesContext);
190
+
191
+ const displayValue = showValues
192
+ ? value
193
+ : "•".repeat(Math.min(value.length, 20));
194
+
195
+ return (
196
+ <span
197
+ className={cn(
198
+ "font-mono text-muted-foreground text-sm",
199
+ !showValues && "select-none",
200
+ className
201
+ )}
202
+ {...props}
203
+ >
204
+ {children ?? displayValue}
205
+ </span>
206
+ );
207
+ };
208
+
209
+ export type EnvironmentVariableProps = HTMLAttributes<HTMLDivElement> & {
210
+ name: string;
211
+ value: string;
212
+ };
213
+
214
+ export const EnvironmentVariable = ({
215
+ name,
216
+ value,
217
+ className,
218
+ children,
219
+ ...props
220
+ }: EnvironmentVariableProps) => {
221
+ const envVarContextValue = useMemo(() => ({ name, value }), [name, value]);
222
+
223
+ return (
224
+ <EnvironmentVariableContext.Provider value={envVarContextValue}>
225
+ <div
226
+ className={cn(
227
+ "flex items-center justify-between gap-4 px-4 py-3",
228
+ className
229
+ )}
230
+ {...props}
231
+ >
232
+ {children ?? (
233
+ <>
234
+ <div className="flex items-center gap-2">
235
+ <EnvironmentVariableName />
236
+ </div>
237
+ <EnvironmentVariableValue />
238
+ </>
239
+ )}
240
+ </div>
241
+ </EnvironmentVariableContext.Provider>
242
+ );
243
+ };
244
+
245
+ export type EnvironmentVariableCopyButtonProps = ComponentProps<
246
+ typeof Button
247
+ > & {
248
+ onCopy?: () => void;
249
+ onError?: (error: Error) => void;
250
+ timeout?: number;
251
+ copyFormat?: "name" | "value" | "export";
252
+ };
253
+
254
+ export const EnvironmentVariableCopyButton = ({
255
+ onCopy,
256
+ onError,
257
+ timeout = 2000,
258
+ copyFormat = "value",
259
+ children,
260
+ className,
261
+ ...props
262
+ }: EnvironmentVariableCopyButtonProps) => {
263
+ const [isCopied, setIsCopied] = useState(false);
264
+ const timeoutRef = useRef<number>(0);
265
+ const { name, value } = useContext(EnvironmentVariableContext);
266
+
267
+ const getTextToCopy = useCallback((): string => {
268
+ const formatMap = {
269
+ export: () => `export ${name}="${value}"`,
270
+ name: () => name,
271
+ value: () => value,
272
+ };
273
+ return formatMap[copyFormat]();
274
+ }, [name, value, copyFormat]);
275
+
276
+ const copyToClipboard = useCallback(async () => {
277
+ if (typeof window === "undefined" || !navigator?.clipboard?.writeText) {
278
+ onError?.(new Error("Clipboard API not available"));
279
+ return;
280
+ }
281
+
282
+ try {
283
+ await navigator.clipboard.writeText(getTextToCopy());
284
+ setIsCopied(true);
285
+ onCopy?.();
286
+ timeoutRef.current = window.setTimeout(() => setIsCopied(false), timeout);
287
+ } catch (error) {
288
+ onError?.(error as Error);
289
+ }
290
+ }, [getTextToCopy, onCopy, onError, timeout]);
291
+
292
+ useEffect(
293
+ () => () => {
294
+ window.clearTimeout(timeoutRef.current);
295
+ },
296
+ []
297
+ );
298
+
299
+ const Icon = isCopied ? CheckIcon : CopyIcon;
300
+
301
+ return (
302
+ <Button
303
+ className={cn("size-6 shrink-0", className)}
304
+ onClick={copyToClipboard}
305
+ size="icon"
306
+ variant="ghost"
307
+ {...props}
308
+ >
309
+ {children ?? <Icon size={12} />}
310
+ </Button>
311
+ );
312
+ };
313
+
314
+ export type EnvironmentVariableRequiredProps = ComponentProps<typeof Badge>;
315
+
316
+ export const EnvironmentVariableRequired = ({
317
+ className,
318
+ children,
319
+ ...props
320
+ }: EnvironmentVariableRequiredProps) => (
321
+ <Badge className={cn("text-xs", className)} variant="secondary" {...props}>
322
+ {children ?? "Required"}
323
+ </Badge>
324
+ );