@openconsole/shadcn 0.2.5 → 0.2.7

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 (113) hide show
  1. package/components/index.ts +1 -2
  2. package/components/ui/accordion.tsx +66 -66
  3. package/components/ui/alert-dialog.tsx +196 -196
  4. package/components/ui/alert.tsx +66 -66
  5. package/components/ui/aspect-ratio.tsx +11 -11
  6. package/components/ui/avatar.tsx +53 -53
  7. package/components/ui/badge.tsx +46 -46
  8. package/components/ui/breadcrumb.tsx +109 -109
  9. package/components/ui/button-group.tsx +83 -83
  10. package/components/ui/button.tsx +60 -60
  11. package/components/ui/calendar.tsx +219 -219
  12. package/components/ui/card.tsx +92 -92
  13. package/components/ui/carousel.tsx +241 -241
  14. package/components/ui/chart.tsx +374 -374
  15. package/components/ui/checkbox.tsx +32 -32
  16. package/components/ui/collapsible.tsx +33 -33
  17. package/components/ui/command.tsx +184 -184
  18. package/components/ui/context-menu.tsx +252 -252
  19. package/components/ui/dialog.tsx +143 -143
  20. package/components/ui/direction.tsx +22 -22
  21. package/components/ui/drawer.tsx +135 -135
  22. package/components/ui/dropdown-menu.tsx +257 -257
  23. package/components/ui/empty.tsx +104 -104
  24. package/components/ui/field.tsx +248 -248
  25. package/components/ui/form.tsx +167 -167
  26. package/components/ui/hover-card.tsx +44 -44
  27. package/components/ui/index.ts +59 -59
  28. package/components/ui/input-group.tsx +170 -170
  29. package/components/ui/input-otp.tsx +77 -77
  30. package/components/ui/input.tsx +21 -21
  31. package/components/ui/item.tsx +193 -193
  32. package/components/ui/kbd.tsx +28 -28
  33. package/components/ui/label.tsx +24 -24
  34. package/components/ui/menubar.tsx +276 -276
  35. package/components/ui/native-select.tsx +62 -62
  36. package/components/ui/navigation-menu.tsx +168 -168
  37. package/components/ui/pagination.tsx +127 -127
  38. package/components/ui/popover.tsx +89 -89
  39. package/components/ui/progress.tsx +31 -31
  40. package/components/ui/radio-group.tsx +45 -45
  41. package/components/ui/resizable.tsx +53 -53
  42. package/components/ui/scroll-area.tsx +58 -58
  43. package/components/ui/select.tsx +187 -187
  44. package/components/ui/separator.tsx +28 -28
  45. package/components/ui/sheet.tsx +139 -139
  46. package/components/ui/sidebar.tsx +724 -724
  47. package/components/ui/skeleton.tsx +13 -13
  48. package/components/ui/slider.tsx +63 -63
  49. package/components/ui/sonner.tsx +40 -40
  50. package/components/ui/spinner.tsx +16 -16
  51. package/components/ui/switch.tsx +35 -35
  52. package/components/ui/table.tsx +116 -116
  53. package/components/ui/tabs.tsx +66 -66
  54. package/components/ui/textarea.tsx +18 -18
  55. package/components/ui/toggle-group.tsx +83 -83
  56. package/components/ui/toggle.tsx +47 -47
  57. package/components/ui/tooltip.tsx +61 -61
  58. package/hooks/index.ts +1 -1
  59. package/hooks/use-mobile.ts +19 -19
  60. package/index.ts +3 -3
  61. package/lib/index.ts +1 -1
  62. package/lib/utils.ts +6 -6
  63. package/package.json +1 -1
  64. package/styles.css +124 -124
  65. package/components/ai-elements/agent.tsx +0 -141
  66. package/components/ai-elements/artifact.tsx +0 -148
  67. package/components/ai-elements/attachments.tsx +0 -426
  68. package/components/ai-elements/audio-player.tsx +0 -231
  69. package/components/ai-elements/canvas.tsx +0 -26
  70. package/components/ai-elements/chain-of-thought.tsx +0 -222
  71. package/components/ai-elements/checkpoint.tsx +0 -71
  72. package/components/ai-elements/code-block.tsx +0 -562
  73. package/components/ai-elements/commit.tsx +0 -458
  74. package/components/ai-elements/confirmation.tsx +0 -174
  75. package/components/ai-elements/connection.tsx +0 -28
  76. package/components/ai-elements/context.tsx +0 -409
  77. package/components/ai-elements/controls.tsx +0 -18
  78. package/components/ai-elements/conversation.tsx +0 -168
  79. package/components/ai-elements/edge.tsx +0 -143
  80. package/components/ai-elements/environment-variables.tsx +0 -324
  81. package/components/ai-elements/file-tree.tsx +0 -304
  82. package/components/ai-elements/image.tsx +0 -24
  83. package/components/ai-elements/index.ts +0 -51
  84. package/components/ai-elements/inline-citation.tsx +0 -296
  85. package/components/ai-elements/jsx-preview.tsx +0 -310
  86. package/components/ai-elements/message.tsx +0 -360
  87. package/components/ai-elements/mic-selector.tsx +0 -375
  88. package/components/ai-elements/model-selector.tsx +0 -213
  89. package/components/ai-elements/node.tsx +0 -71
  90. package/components/ai-elements/open-in-chat.tsx +0 -370
  91. package/components/ai-elements/package-info.tsx +0 -239
  92. package/components/ai-elements/panel.tsx +0 -15
  93. package/components/ai-elements/persona.tsx +0 -306
  94. package/components/ai-elements/plan.tsx +0 -147
  95. package/components/ai-elements/prompt-input.tsx +0 -1463
  96. package/components/ai-elements/queue.tsx +0 -274
  97. package/components/ai-elements/reasoning.tsx +0 -228
  98. package/components/ai-elements/sandbox.tsx +0 -132
  99. package/components/ai-elements/schema-display.tsx +0 -471
  100. package/components/ai-elements/shimmer.tsx +0 -77
  101. package/components/ai-elements/snippet.tsx +0 -145
  102. package/components/ai-elements/sources.tsx +0 -77
  103. package/components/ai-elements/speech-input.tsx +0 -323
  104. package/components/ai-elements/stack-trace.tsx +0 -528
  105. package/components/ai-elements/suggestion.tsx +0 -57
  106. package/components/ai-elements/task.tsx +0 -87
  107. package/components/ai-elements/terminal.tsx +0 -273
  108. package/components/ai-elements/test-results.tsx +0 -496
  109. package/components/ai-elements/tool.tsx +0 -173
  110. package/components/ai-elements/toolbar.tsx +0 -16
  111. package/components/ai-elements/transcription.tsx +0 -125
  112. package/components/ai-elements/voice-selector.tsx +0 -524
  113. package/components/ai-elements/web-preview.tsx +0 -281
@@ -1,562 +0,0 @@
1
- "use client";
2
-
3
- import { Button } from "../ui/button";
4
- import {
5
- Select,
6
- SelectContent,
7
- SelectItem,
8
- SelectTrigger,
9
- SelectValue,
10
- } from "../ui/select";
11
- import { cn } from "../../lib/utils";
12
- import { CheckIcon, CopyIcon } from "lucide-react";
13
- import type { ComponentProps, CSSProperties, HTMLAttributes } from "react";
14
- import {
15
- createContext,
16
- memo,
17
- useCallback,
18
- useContext,
19
- useEffect,
20
- useMemo,
21
- useRef,
22
- useState,
23
- } from "react";
24
- import type {
25
- BundledLanguage,
26
- BundledTheme,
27
- HighlighterGeneric,
28
- ThemedToken,
29
- } from "shiki";
30
- import { createHighlighter } from "shiki";
31
-
32
- // Shiki uses bitflags for font styles: 1=italic, 2=bold, 4=underline
33
- // oxlint-disable-next-line eslint(no-bitwise)
34
- const isItalic = (fontStyle: number | undefined) => fontStyle && fontStyle & 1;
35
- // oxlint-disable-next-line eslint(no-bitwise)
36
- const isBold = (fontStyle: number | undefined) => fontStyle && fontStyle & 2;
37
- const isUnderline = (fontStyle: number | undefined) =>
38
- // oxlint-disable-next-line eslint(no-bitwise)
39
- fontStyle && fontStyle & 4;
40
-
41
- // Transform tokens to include pre-computed keys to avoid noArrayIndexKey lint
42
- interface KeyedToken {
43
- token: ThemedToken;
44
- key: string;
45
- }
46
- interface KeyedLine {
47
- tokens: KeyedToken[];
48
- key: string;
49
- }
50
-
51
- const addKeysToTokens = (lines: ThemedToken[][]): KeyedLine[] =>
52
- lines.map((line, lineIdx) => ({
53
- key: `line-${lineIdx}`,
54
- tokens: line.map((token, tokenIdx) => ({
55
- key: `line-${lineIdx}-${tokenIdx}`,
56
- token,
57
- })),
58
- }));
59
-
60
- // Token rendering component
61
- const TokenSpan = ({ token }: { token: ThemedToken }) => (
62
- <span
63
- className="dark:!bg-[var(--shiki-dark-bg)] dark:!text-[var(--shiki-dark)]"
64
- style={
65
- {
66
- backgroundColor: token.bgColor,
67
- color: token.color,
68
- fontStyle: isItalic(token.fontStyle) ? "italic" : undefined,
69
- fontWeight: isBold(token.fontStyle) ? "bold" : undefined,
70
- textDecoration: isUnderline(token.fontStyle) ? "underline" : undefined,
71
- ...token.htmlStyle,
72
- } as CSSProperties
73
- }
74
- >
75
- {token.content}
76
- </span>
77
- );
78
-
79
- // Line number styles using CSS counters
80
- const LINE_NUMBER_CLASSES = cn(
81
- "block",
82
- "before:content-[counter(line)]",
83
- "before:inline-block",
84
- "before:[counter-increment:line]",
85
- "before:w-8",
86
- "before:mr-4",
87
- "before:text-right",
88
- "before:text-muted-foreground/50",
89
- "before:font-mono",
90
- "before:select-none"
91
- );
92
-
93
- // Line rendering component
94
- const LineSpan = ({
95
- keyedLine,
96
- showLineNumbers,
97
- }: {
98
- keyedLine: KeyedLine;
99
- showLineNumbers: boolean;
100
- }) => (
101
- <span className={showLineNumbers ? LINE_NUMBER_CLASSES : "block"}>
102
- {keyedLine.tokens.length === 0
103
- ? "\n"
104
- : keyedLine.tokens.map(({ token, key }) => (
105
- <TokenSpan key={key} token={token} />
106
- ))}
107
- </span>
108
- );
109
-
110
- // Types
111
- type CodeBlockProps = HTMLAttributes<HTMLDivElement> & {
112
- code: string;
113
- language: BundledLanguage;
114
- showLineNumbers?: boolean;
115
- };
116
-
117
- interface TokenizedCode {
118
- tokens: ThemedToken[][];
119
- fg: string;
120
- bg: string;
121
- }
122
-
123
- interface CodeBlockContextType {
124
- code: string;
125
- }
126
-
127
- // Context
128
- const CodeBlockContext = createContext<CodeBlockContextType>({
129
- code: "",
130
- });
131
-
132
- // Highlighter cache (singleton per language)
133
- const highlighterCache = new Map<
134
- string,
135
- Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>
136
- >();
137
-
138
- // Token cache
139
- const tokensCache = new Map<string, TokenizedCode>();
140
-
141
- // Subscribers for async token updates
142
- const subscribers = new Map<string, Set<(result: TokenizedCode) => void>>();
143
-
144
- const getTokensCacheKey = (code: string, language: BundledLanguage) => {
145
- const start = code.slice(0, 100);
146
- const end = code.length > 100 ? code.slice(-100) : "";
147
- return `${language}:${code.length}:${start}:${end}`;
148
- };
149
-
150
- const getHighlighter = (
151
- language: BundledLanguage
152
- ): Promise<HighlighterGeneric<BundledLanguage, BundledTheme>> => {
153
- const cached = highlighterCache.get(language);
154
- if (cached) {
155
- return cached;
156
- }
157
-
158
- const highlighterPromise = createHighlighter({
159
- langs: [language],
160
- themes: ["github-light", "github-dark"],
161
- });
162
-
163
- highlighterCache.set(language, highlighterPromise);
164
- return highlighterPromise;
165
- };
166
-
167
- // Create raw tokens for immediate display while highlighting loads
168
- const createRawTokens = (code: string): TokenizedCode => ({
169
- bg: "transparent",
170
- fg: "inherit",
171
- tokens: code.split("\n").map((line) =>
172
- line === ""
173
- ? []
174
- : [
175
- {
176
- color: "inherit",
177
- content: line,
178
- } as ThemedToken,
179
- ]
180
- ),
181
- });
182
-
183
- // Synchronous highlight with callback for async results
184
- export const highlightCode = (
185
- code: string,
186
- language: BundledLanguage,
187
- // oxlint-disable-next-line eslint-plugin-promise(prefer-await-to-callbacks)
188
- callback?: (result: TokenizedCode) => void
189
- ): TokenizedCode | null => {
190
- const tokensCacheKey = getTokensCacheKey(code, language);
191
-
192
- // Return cached result if available
193
- const cached = tokensCache.get(tokensCacheKey);
194
- if (cached) {
195
- return cached;
196
- }
197
-
198
- // Subscribe callback if provided
199
- if (callback) {
200
- if (!subscribers.has(tokensCacheKey)) {
201
- subscribers.set(tokensCacheKey, new Set());
202
- }
203
- subscribers.get(tokensCacheKey)?.add(callback);
204
- }
205
-
206
- // Start highlighting in background - fire-and-forget async pattern
207
- getHighlighter(language)
208
- // oxlint-disable-next-line eslint-plugin-promise(prefer-await-to-then)
209
- .then((highlighter) => {
210
- const availableLangs = highlighter.getLoadedLanguages();
211
- const langToUse = availableLangs.includes(language) ? language : "text";
212
-
213
- const result = highlighter.codeToTokens(code, {
214
- lang: langToUse,
215
- themes: {
216
- dark: "github-dark",
217
- light: "github-light",
218
- },
219
- });
220
-
221
- const tokenized: TokenizedCode = {
222
- bg: result.bg ?? "transparent",
223
- fg: result.fg ?? "inherit",
224
- tokens: result.tokens,
225
- };
226
-
227
- // Cache the result
228
- tokensCache.set(tokensCacheKey, tokenized);
229
-
230
- // Notify all subscribers
231
- const subs = subscribers.get(tokensCacheKey);
232
- if (subs) {
233
- for (const sub of subs) {
234
- sub(tokenized);
235
- }
236
- subscribers.delete(tokensCacheKey);
237
- }
238
- })
239
- // oxlint-disable-next-line eslint-plugin-promise(prefer-await-to-then), eslint-plugin-promise(prefer-await-to-callbacks)
240
- .catch((error) => {
241
- console.error("Failed to highlight code:", error);
242
- subscribers.delete(tokensCacheKey);
243
- });
244
-
245
- return null;
246
- };
247
-
248
- const CodeBlockBody = memo(
249
- ({
250
- tokenized,
251
- showLineNumbers,
252
- className,
253
- }: {
254
- tokenized: TokenizedCode;
255
- showLineNumbers: boolean;
256
- className?: string;
257
- }) => {
258
- const preStyle = useMemo(
259
- () => ({
260
- backgroundColor: tokenized.bg,
261
- color: tokenized.fg,
262
- }),
263
- [tokenized.bg, tokenized.fg]
264
- );
265
-
266
- const keyedLines = useMemo(
267
- () => addKeysToTokens(tokenized.tokens),
268
- [tokenized.tokens]
269
- );
270
-
271
- return (
272
- <pre
273
- className={cn(
274
- "dark:!bg-[var(--shiki-dark-bg)] dark:!text-[var(--shiki-dark)] m-0 p-4 text-sm",
275
- className
276
- )}
277
- style={preStyle}
278
- >
279
- <code
280
- className={cn(
281
- "font-mono text-sm",
282
- showLineNumbers && "[counter-increment:line_0] [counter-reset:line]"
283
- )}
284
- >
285
- {keyedLines.map((keyedLine) => (
286
- <LineSpan
287
- key={keyedLine.key}
288
- keyedLine={keyedLine}
289
- showLineNumbers={showLineNumbers}
290
- />
291
- ))}
292
- </code>
293
- </pre>
294
- );
295
- },
296
- (prevProps, nextProps) =>
297
- prevProps.tokenized === nextProps.tokenized &&
298
- prevProps.showLineNumbers === nextProps.showLineNumbers &&
299
- prevProps.className === nextProps.className
300
- );
301
-
302
- CodeBlockBody.displayName = "CodeBlockBody";
303
-
304
- export const CodeBlockContainer = ({
305
- className,
306
- language,
307
- style,
308
- ...props
309
- }: HTMLAttributes<HTMLDivElement> & { language: string }) => (
310
- <div
311
- className={cn(
312
- "group relative w-full overflow-hidden rounded-md border bg-background text-foreground",
313
- className
314
- )}
315
- data-language={language}
316
- style={{
317
- containIntrinsicSize: "auto 200px",
318
- contentVisibility: "auto",
319
- ...style,
320
- }}
321
- {...props}
322
- />
323
- );
324
-
325
- export const CodeBlockHeader = ({
326
- children,
327
- className,
328
- ...props
329
- }: HTMLAttributes<HTMLDivElement>) => (
330
- <div
331
- className={cn(
332
- "flex items-center justify-between border-b bg-muted/80 px-3 py-2 text-muted-foreground text-xs",
333
- className
334
- )}
335
- {...props}
336
- >
337
- {children}
338
- </div>
339
- );
340
-
341
- export const CodeBlockTitle = ({
342
- children,
343
- className,
344
- ...props
345
- }: HTMLAttributes<HTMLDivElement>) => (
346
- <div className={cn("flex items-center gap-2", className)} {...props}>
347
- {children}
348
- </div>
349
- );
350
-
351
- export const CodeBlockFilename = ({
352
- children,
353
- className,
354
- ...props
355
- }: HTMLAttributes<HTMLSpanElement>) => (
356
- <span className={cn("font-mono", className)} {...props}>
357
- {children}
358
- </span>
359
- );
360
-
361
- export const CodeBlockActions = ({
362
- children,
363
- className,
364
- ...props
365
- }: HTMLAttributes<HTMLDivElement>) => (
366
- <div
367
- className={cn("-my-1 -mr-1 flex items-center gap-2", className)}
368
- {...props}
369
- >
370
- {children}
371
- </div>
372
- );
373
-
374
- export const CodeBlockContent = ({
375
- code,
376
- language,
377
- showLineNumbers = false,
378
- }: {
379
- code: string;
380
- language: BundledLanguage;
381
- showLineNumbers?: boolean;
382
- }) => {
383
- // Memoized raw tokens for immediate display
384
- const rawTokens = useMemo(() => createRawTokens(code), [code]);
385
-
386
- // Synchronous cache lookup — avoids setState in effect for cached results
387
- const syncTokens = useMemo(
388
- () => highlightCode(code, language) ?? rawTokens,
389
- [code, language, rawTokens]
390
- );
391
-
392
- // Async highlighting result (populated after shiki loads)
393
- const [asyncTokens, setAsyncTokens] = useState<TokenizedCode | null>(null);
394
- const asyncKeyRef = useRef({ code, language });
395
-
396
- // Invalidate stale async tokens synchronously during render
397
- if (
398
- asyncKeyRef.current.code !== code ||
399
- asyncKeyRef.current.language !== language
400
- ) {
401
- asyncKeyRef.current = { code, language };
402
- setAsyncTokens(null);
403
- }
404
-
405
- useEffect(() => {
406
- let cancelled = false;
407
-
408
- highlightCode(code, language, (result) => {
409
- if (!cancelled) {
410
- setAsyncTokens(result);
411
- }
412
- });
413
-
414
- return () => {
415
- cancelled = true;
416
- };
417
- }, [code, language]);
418
-
419
- const tokenized = asyncTokens ?? syncTokens;
420
-
421
- return (
422
- <div className="relative overflow-auto">
423
- <CodeBlockBody showLineNumbers={showLineNumbers} tokenized={tokenized} />
424
- </div>
425
- );
426
- };
427
-
428
- export const CodeBlock = ({
429
- code,
430
- language,
431
- showLineNumbers = false,
432
- className,
433
- children,
434
- ...props
435
- }: CodeBlockProps) => {
436
- const contextValue = useMemo(() => ({ code }), [code]);
437
-
438
- return (
439
- <CodeBlockContext.Provider value={contextValue}>
440
- <CodeBlockContainer className={className} language={language} {...props}>
441
- {children}
442
- <CodeBlockContent
443
- code={code}
444
- language={language}
445
- showLineNumbers={showLineNumbers}
446
- />
447
- </CodeBlockContainer>
448
- </CodeBlockContext.Provider>
449
- );
450
- };
451
-
452
- export type CodeBlockCopyButtonProps = ComponentProps<typeof Button> & {
453
- onCopy?: () => void;
454
- onError?: (error: Error) => void;
455
- timeout?: number;
456
- };
457
-
458
- export const CodeBlockCopyButton = ({
459
- onCopy,
460
- onError,
461
- timeout = 2000,
462
- children,
463
- className,
464
- ...props
465
- }: CodeBlockCopyButtonProps) => {
466
- const [isCopied, setIsCopied] = useState(false);
467
- const timeoutRef = useRef<number>(0);
468
- const { code } = useContext(CodeBlockContext);
469
-
470
- const copyToClipboard = useCallback(async () => {
471
- if (typeof window === "undefined" || !navigator?.clipboard?.writeText) {
472
- onError?.(new Error("Clipboard API not available"));
473
- return;
474
- }
475
-
476
- try {
477
- if (!isCopied) {
478
- await navigator.clipboard.writeText(code);
479
- setIsCopied(true);
480
- onCopy?.();
481
- timeoutRef.current = window.setTimeout(
482
- () => setIsCopied(false),
483
- timeout
484
- );
485
- }
486
- } catch (error) {
487
- onError?.(error as Error);
488
- }
489
- }, [code, onCopy, onError, timeout, isCopied]);
490
-
491
- useEffect(
492
- () => () => {
493
- window.clearTimeout(timeoutRef.current);
494
- },
495
- []
496
- );
497
-
498
- const Icon = isCopied ? CheckIcon : CopyIcon;
499
-
500
- return (
501
- <Button
502
- className={cn("shrink-0", className)}
503
- onClick={copyToClipboard}
504
- size="icon"
505
- variant="ghost"
506
- {...props}
507
- >
508
- {children ?? <Icon size={14} />}
509
- </Button>
510
- );
511
- };
512
-
513
- export type CodeBlockLanguageSelectorProps = ComponentProps<typeof Select>;
514
-
515
- export const CodeBlockLanguageSelector = (
516
- props: CodeBlockLanguageSelectorProps
517
- ) => <Select {...props} />;
518
-
519
- export type CodeBlockLanguageSelectorTriggerProps = ComponentProps<
520
- typeof SelectTrigger
521
- >;
522
-
523
- export const CodeBlockLanguageSelectorTrigger = ({
524
- className,
525
- ...props
526
- }: CodeBlockLanguageSelectorTriggerProps) => (
527
- <SelectTrigger
528
- className={cn(
529
- "h-7 border-none bg-transparent px-2 text-xs shadow-none",
530
- className
531
- )}
532
- size="sm"
533
- {...props}
534
- />
535
- );
536
-
537
- export type CodeBlockLanguageSelectorValueProps = ComponentProps<
538
- typeof SelectValue
539
- >;
540
-
541
- export const CodeBlockLanguageSelectorValue = (
542
- props: CodeBlockLanguageSelectorValueProps
543
- ) => <SelectValue {...props} />;
544
-
545
- export type CodeBlockLanguageSelectorContentProps = ComponentProps<
546
- typeof SelectContent
547
- >;
548
-
549
- export const CodeBlockLanguageSelectorContent = ({
550
- align = "end",
551
- ...props
552
- }: CodeBlockLanguageSelectorContentProps) => (
553
- <SelectContent align={align} {...props} />
554
- );
555
-
556
- export type CodeBlockLanguageSelectorItemProps = ComponentProps<
557
- typeof SelectItem
558
- >;
559
-
560
- export const CodeBlockLanguageSelectorItem = (
561
- props: CodeBlockLanguageSelectorItemProps
562
- ) => <SelectItem {...props} />;