@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,77 @@
1
+ "use client";
2
+
3
+ import {
4
+ Collapsible,
5
+ CollapsibleContent,
6
+ CollapsibleTrigger,
7
+ } from "../ui/collapsible";
8
+ import { cn } from "../../lib/utils";
9
+ import { BookIcon, ChevronDownIcon } from "lucide-react";
10
+ import type { ComponentProps } from "react";
11
+
12
+ export type SourcesProps = ComponentProps<"div">;
13
+
14
+ export const Sources = ({ className, ...props }: SourcesProps) => (
15
+ <Collapsible
16
+ className={cn("not-prose mb-4 text-primary text-xs", className)}
17
+ {...props}
18
+ />
19
+ );
20
+
21
+ export type SourcesTriggerProps = ComponentProps<typeof CollapsibleTrigger> & {
22
+ count: number;
23
+ };
24
+
25
+ export const SourcesTrigger = ({
26
+ className,
27
+ count,
28
+ children,
29
+ ...props
30
+ }: SourcesTriggerProps) => (
31
+ <CollapsibleTrigger
32
+ className={cn("flex items-center gap-2", className)}
33
+ {...props}
34
+ >
35
+ {children ?? (
36
+ <>
37
+ <p className="font-medium">Used {count} sources</p>
38
+ <ChevronDownIcon className="h-4 w-4" />
39
+ </>
40
+ )}
41
+ </CollapsibleTrigger>
42
+ );
43
+
44
+ export type SourcesContentProps = ComponentProps<typeof CollapsibleContent>;
45
+
46
+ export const SourcesContent = ({
47
+ className,
48
+ ...props
49
+ }: SourcesContentProps) => (
50
+ <CollapsibleContent
51
+ className={cn(
52
+ "mt-3 flex w-fit flex-col gap-2",
53
+ "data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",
54
+ className
55
+ )}
56
+ {...props}
57
+ />
58
+ );
59
+
60
+ export type SourceProps = ComponentProps<"a">;
61
+
62
+ export const Source = ({ href, title, children, ...props }: SourceProps) => (
63
+ <a
64
+ className="flex items-center gap-2"
65
+ href={href}
66
+ rel="noreferrer"
67
+ target="_blank"
68
+ {...props}
69
+ >
70
+ {children ?? (
71
+ <>
72
+ <BookIcon className="h-4 w-4" />
73
+ <span className="block font-medium">{title}</span>
74
+ </>
75
+ )}
76
+ </a>
77
+ );
@@ -0,0 +1,323 @@
1
+ "use client";
2
+
3
+ import { Button } from "../ui/button";
4
+ import { Spinner } from "../ui/spinner";
5
+ import { cn } from "../../lib/utils";
6
+ import { MicIcon, SquareIcon } from "lucide-react";
7
+ import type { ComponentProps } from "react";
8
+ import { useCallback, useEffect, useRef, useState } from "react";
9
+
10
+ interface SpeechRecognition extends EventTarget {
11
+ continuous: boolean;
12
+ interimResults: boolean;
13
+ lang: string;
14
+ start(): void;
15
+ stop(): void;
16
+ onstart: ((this: SpeechRecognition, ev: Event) => void) | null;
17
+ onend: ((this: SpeechRecognition, ev: Event) => void) | null;
18
+ onresult:
19
+ | ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => void)
20
+ | null;
21
+ onerror:
22
+ | ((this: SpeechRecognition, ev: SpeechRecognitionErrorEvent) => void)
23
+ | null;
24
+ }
25
+
26
+ interface SpeechRecognitionEvent extends Event {
27
+ results: SpeechRecognitionResultList;
28
+ resultIndex: number;
29
+ }
30
+
31
+ interface SpeechRecognitionResultList {
32
+ readonly length: number;
33
+ item(index: number): SpeechRecognitionResult;
34
+ [index: number]: SpeechRecognitionResult;
35
+ }
36
+
37
+ interface SpeechRecognitionResult {
38
+ readonly length: number;
39
+ item(index: number): SpeechRecognitionAlternative;
40
+ [index: number]: SpeechRecognitionAlternative;
41
+ isFinal: boolean;
42
+ }
43
+
44
+ interface SpeechRecognitionAlternative {
45
+ transcript: string;
46
+ confidence: number;
47
+ }
48
+
49
+ interface SpeechRecognitionErrorEvent extends Event {
50
+ error: string;
51
+ }
52
+
53
+ declare global {
54
+ interface Window {
55
+ SpeechRecognition: new () => SpeechRecognition;
56
+ webkitSpeechRecognition: new () => SpeechRecognition;
57
+ }
58
+ }
59
+
60
+ type SpeechInputMode = "speech-recognition" | "media-recorder" | "none";
61
+
62
+ export type SpeechInputProps = ComponentProps<typeof Button> & {
63
+ onTranscriptionChange?: (text: string) => void;
64
+ /**
65
+ * Callback for when audio is recorded using MediaRecorder fallback.
66
+ * This is called in browsers that don't support the Web Speech API (Firefox, Safari).
67
+ * The callback receives an audio Blob that should be sent to a transcription service.
68
+ * Return the transcribed text, which will be passed to onTranscriptionChange.
69
+ */
70
+ onAudioRecorded?: (audioBlob: Blob) => Promise<string>;
71
+ lang?: string;
72
+ };
73
+
74
+ const detectSpeechInputMode = (): SpeechInputMode => {
75
+ if (typeof window === "undefined") {
76
+ return "none";
77
+ }
78
+
79
+ if ("SpeechRecognition" in window || "webkitSpeechRecognition" in window) {
80
+ return "speech-recognition";
81
+ }
82
+
83
+ if ("MediaRecorder" in window && "mediaDevices" in navigator) {
84
+ return "media-recorder";
85
+ }
86
+
87
+ return "none";
88
+ };
89
+
90
+ export const SpeechInput = ({
91
+ className,
92
+ onTranscriptionChange,
93
+ onAudioRecorded,
94
+ lang = "en-US",
95
+ ...props
96
+ }: SpeechInputProps) => {
97
+ const [isListening, setIsListening] = useState(false);
98
+ const [isProcessing, setIsProcessing] = useState(false);
99
+ const [mode] = useState<SpeechInputMode>(detectSpeechInputMode);
100
+ const [isRecognitionReady, setIsRecognitionReady] = useState(false);
101
+ const recognitionRef = useRef<SpeechRecognition | null>(null);
102
+ const mediaRecorderRef = useRef<MediaRecorder | null>(null);
103
+ const streamRef = useRef<MediaStream | null>(null);
104
+ const audioChunksRef = useRef<Blob[]>([]);
105
+ const onTranscriptionChangeRef = useRef<
106
+ SpeechInputProps["onTranscriptionChange"]
107
+ >(onTranscriptionChange);
108
+ const onAudioRecordedRef =
109
+ useRef<SpeechInputProps["onAudioRecorded"]>(onAudioRecorded);
110
+
111
+ // Keep refs in sync
112
+ onTranscriptionChangeRef.current = onTranscriptionChange;
113
+ onAudioRecordedRef.current = onAudioRecorded;
114
+
115
+ // Initialize Speech Recognition when mode is speech-recognition
116
+ useEffect(() => {
117
+ if (mode !== "speech-recognition") {
118
+ return;
119
+ }
120
+
121
+ const SpeechRecognition =
122
+ window.SpeechRecognition || window.webkitSpeechRecognition;
123
+ const speechRecognition = new SpeechRecognition();
124
+
125
+ speechRecognition.continuous = true;
126
+ speechRecognition.interimResults = true;
127
+ speechRecognition.lang = lang;
128
+
129
+ const handleStart = () => {
130
+ setIsListening(true);
131
+ };
132
+
133
+ const handleEnd = () => {
134
+ setIsListening(false);
135
+ };
136
+
137
+ const handleResult = (event: Event) => {
138
+ const speechEvent = event as SpeechRecognitionEvent;
139
+ let finalTranscript = "";
140
+
141
+ for (
142
+ let i = speechEvent.resultIndex;
143
+ i < speechEvent.results.length;
144
+ i += 1
145
+ ) {
146
+ const result = speechEvent.results[i];
147
+ if (result.isFinal) {
148
+ finalTranscript += result[0]?.transcript ?? "";
149
+ }
150
+ }
151
+
152
+ if (finalTranscript) {
153
+ onTranscriptionChangeRef.current?.(finalTranscript);
154
+ }
155
+ };
156
+
157
+ const handleError = () => {
158
+ setIsListening(false);
159
+ };
160
+
161
+ speechRecognition.addEventListener("start", handleStart);
162
+ speechRecognition.addEventListener("end", handleEnd);
163
+ speechRecognition.addEventListener("result", handleResult);
164
+ speechRecognition.addEventListener("error", handleError);
165
+
166
+ recognitionRef.current = speechRecognition;
167
+ setIsRecognitionReady(true);
168
+
169
+ return () => {
170
+ speechRecognition.removeEventListener("start", handleStart);
171
+ speechRecognition.removeEventListener("end", handleEnd);
172
+ speechRecognition.removeEventListener("result", handleResult);
173
+ speechRecognition.removeEventListener("error", handleError);
174
+ speechRecognition.stop();
175
+ recognitionRef.current = null;
176
+ setIsRecognitionReady(false);
177
+ };
178
+ }, [mode, lang]);
179
+
180
+ // Cleanup MediaRecorder and stream on unmount
181
+ useEffect(
182
+ () => () => {
183
+ if (mediaRecorderRef.current?.state === "recording") {
184
+ mediaRecorderRef.current.stop();
185
+ }
186
+ if (streamRef.current) {
187
+ for (const track of streamRef.current.getTracks()) {
188
+ track.stop();
189
+ }
190
+ }
191
+ },
192
+ []
193
+ );
194
+
195
+ // Start MediaRecorder recording
196
+ const startMediaRecorder = useCallback(async () => {
197
+ if (!onAudioRecordedRef.current) {
198
+ return;
199
+ }
200
+
201
+ try {
202
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
203
+ streamRef.current = stream;
204
+ const mediaRecorder = new MediaRecorder(stream);
205
+ audioChunksRef.current = [];
206
+
207
+ const handleDataAvailable = (event: BlobEvent) => {
208
+ if (event.data.size > 0) {
209
+ audioChunksRef.current.push(event.data);
210
+ }
211
+ };
212
+
213
+ const handleStop = async () => {
214
+ for (const track of stream.getTracks()) {
215
+ track.stop();
216
+ }
217
+ streamRef.current = null;
218
+
219
+ const audioBlob = new Blob(audioChunksRef.current, {
220
+ type: "audio/webm",
221
+ });
222
+
223
+ if (audioBlob.size > 0 && onAudioRecordedRef.current) {
224
+ setIsProcessing(true);
225
+ try {
226
+ const transcript = await onAudioRecordedRef.current(audioBlob);
227
+ if (transcript) {
228
+ onTranscriptionChangeRef.current?.(transcript);
229
+ }
230
+ } catch {
231
+ // Error handling delegated to the onAudioRecorded caller
232
+ } finally {
233
+ setIsProcessing(false);
234
+ }
235
+ }
236
+ };
237
+
238
+ const handleError = () => {
239
+ setIsListening(false);
240
+ for (const track of stream.getTracks()) {
241
+ track.stop();
242
+ }
243
+ streamRef.current = null;
244
+ };
245
+
246
+ mediaRecorder.addEventListener("dataavailable", handleDataAvailable);
247
+ mediaRecorder.addEventListener("stop", handleStop);
248
+ mediaRecorder.addEventListener("error", handleError);
249
+
250
+ mediaRecorderRef.current = mediaRecorder;
251
+ mediaRecorder.start();
252
+ setIsListening(true);
253
+ } catch {
254
+ setIsListening(false);
255
+ }
256
+ }, []);
257
+
258
+ // Stop MediaRecorder recording
259
+ const stopMediaRecorder = useCallback(() => {
260
+ if (mediaRecorderRef.current?.state === "recording") {
261
+ mediaRecorderRef.current.stop();
262
+ }
263
+ setIsListening(false);
264
+ }, []);
265
+
266
+ const toggleListening = useCallback(() => {
267
+ if (mode === "speech-recognition" && recognitionRef.current) {
268
+ if (isListening) {
269
+ recognitionRef.current.stop();
270
+ } else {
271
+ recognitionRef.current.start();
272
+ }
273
+ } else if (mode === "media-recorder") {
274
+ if (isListening) {
275
+ stopMediaRecorder();
276
+ } else {
277
+ startMediaRecorder();
278
+ }
279
+ }
280
+ }, [mode, isListening, startMediaRecorder, stopMediaRecorder]);
281
+
282
+ // Determine if button should be disabled
283
+ const isDisabled =
284
+ mode === "none" ||
285
+ (mode === "speech-recognition" && !isRecognitionReady) ||
286
+ (mode === "media-recorder" && !onAudioRecorded) ||
287
+ isProcessing;
288
+
289
+ return (
290
+ <div className="relative inline-flex items-center justify-center">
291
+ {/* Animated pulse rings */}
292
+ {isListening &&
293
+ [0, 1, 2].map((index) => (
294
+ <div
295
+ className="absolute inset-0 animate-ping rounded-full border-2 border-red-400/30"
296
+ key={index}
297
+ style={{
298
+ animationDelay: `${index * 0.3}s`,
299
+ animationDuration: "2s",
300
+ }}
301
+ />
302
+ ))}
303
+
304
+ {/* Main record button */}
305
+ <Button
306
+ className={cn(
307
+ "relative z-10 rounded-full transition-all duration-300",
308
+ isListening
309
+ ? "bg-destructive text-white hover:bg-destructive/80 hover:text-white"
310
+ : "bg-primary text-primary-foreground hover:bg-primary/80 hover:text-primary-foreground",
311
+ className
312
+ )}
313
+ disabled={isDisabled}
314
+ onClick={toggleListening}
315
+ {...props}
316
+ >
317
+ {isProcessing && <Spinner />}
318
+ {!isProcessing && isListening && <SquareIcon className="size-4" />}
319
+ {!(isProcessing || isListening) && <MicIcon className="size-4" />}
320
+ </Button>
321
+ </div>
322
+ );
323
+ };