@jxrstudios/jxr 1.0.9 → 1.0.11

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 (89) hide show
  1. package/bin/jxr.js +6 -0
  2. package/dist/index.d.ts +43 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +57 -2
  5. package/dist/jxr-server-manager.d.ts.map +1 -1
  6. package/package.json +1 -1
  7. package/src/jxr-server-manager.ts +57 -1
  8. package/zzz_react_template/App.tsx +43 -156
  9. package/zzz_react_template/components/ErrorBoundary.tsx +62 -0
  10. package/zzz_react_template/components/ManusDialog.tsx +85 -0
  11. package/zzz_react_template/components/Map.tsx +155 -0
  12. package/zzz_react_template/components/jxr/CodeEditor.tsx +313 -0
  13. package/zzz_react_template/components/jxr/FileExplorer.tsx +230 -0
  14. package/zzz_react_template/components/jxr/IDEShell.tsx +159 -0
  15. package/zzz_react_template/components/jxr/LandingPage.tsx +414 -0
  16. package/zzz_react_template/components/jxr/LivePreview.tsx +169 -0
  17. package/zzz_react_template/components/jxr/PerformanceDashboard.tsx +379 -0
  18. package/zzz_react_template/components/jxr/TopBar.tsx +149 -0
  19. package/zzz_react_template/components/ui/accordion.tsx +64 -0
  20. package/zzz_react_template/components/ui/alert-dialog.tsx +155 -0
  21. package/zzz_react_template/components/ui/alert.tsx +66 -0
  22. package/zzz_react_template/components/ui/aspect-ratio.tsx +9 -0
  23. package/zzz_react_template/components/ui/avatar.tsx +51 -0
  24. package/zzz_react_template/components/ui/badge.tsx +46 -0
  25. package/zzz_react_template/components/ui/breadcrumb.tsx +109 -0
  26. package/zzz_react_template/components/ui/button-group.tsx +83 -0
  27. package/zzz_react_template/components/ui/button.tsx +60 -0
  28. package/zzz_react_template/components/ui/calendar.tsx +211 -0
  29. package/zzz_react_template/components/ui/card.tsx +92 -0
  30. package/zzz_react_template/components/ui/carousel.tsx +239 -0
  31. package/zzz_react_template/components/ui/chart.tsx +355 -0
  32. package/zzz_react_template/components/ui/checkbox.tsx +30 -0
  33. package/zzz_react_template/components/ui/collapsible.tsx +31 -0
  34. package/zzz_react_template/components/ui/command.tsx +184 -0
  35. package/zzz_react_template/components/ui/context-menu.tsx +250 -0
  36. package/zzz_react_template/components/ui/dialog.tsx +209 -0
  37. package/zzz_react_template/components/ui/drawer.tsx +133 -0
  38. package/zzz_react_template/components/ui/dropdown-menu.tsx +255 -0
  39. package/zzz_react_template/components/ui/empty.tsx +104 -0
  40. package/zzz_react_template/components/ui/field.tsx +242 -0
  41. package/zzz_react_template/components/ui/form.tsx +168 -0
  42. package/zzz_react_template/components/ui/hover-card.tsx +42 -0
  43. package/zzz_react_template/components/ui/input-group.tsx +168 -0
  44. package/zzz_react_template/components/ui/input-otp.tsx +75 -0
  45. package/zzz_react_template/components/ui/input.tsx +70 -0
  46. package/zzz_react_template/components/ui/item.tsx +193 -0
  47. package/zzz_react_template/components/ui/kbd.tsx +28 -0
  48. package/zzz_react_template/components/ui/label.tsx +22 -0
  49. package/zzz_react_template/components/ui/menubar.tsx +274 -0
  50. package/zzz_react_template/components/ui/navigation-menu.tsx +168 -0
  51. package/zzz_react_template/components/ui/pagination.tsx +127 -0
  52. package/zzz_react_template/components/ui/popover.tsx +46 -0
  53. package/zzz_react_template/components/ui/progress.tsx +29 -0
  54. package/zzz_react_template/components/ui/radio-group.tsx +43 -0
  55. package/zzz_react_template/components/ui/resizable.tsx +54 -0
  56. package/zzz_react_template/components/ui/scroll-area.tsx +56 -0
  57. package/zzz_react_template/components/ui/select.tsx +185 -0
  58. package/zzz_react_template/components/ui/separator.tsx +26 -0
  59. package/zzz_react_template/components/ui/sheet.tsx +139 -0
  60. package/zzz_react_template/components/ui/sidebar.tsx +734 -0
  61. package/zzz_react_template/components/ui/skeleton.tsx +13 -0
  62. package/zzz_react_template/components/ui/slider.tsx +61 -0
  63. package/zzz_react_template/components/ui/sonner.tsx +23 -0
  64. package/zzz_react_template/components/ui/spinner.tsx +16 -0
  65. package/zzz_react_template/components/ui/switch.tsx +29 -0
  66. package/zzz_react_template/components/ui/table.tsx +114 -0
  67. package/zzz_react_template/components/ui/tabs.tsx +64 -0
  68. package/zzz_react_template/components/ui/textarea.tsx +67 -0
  69. package/zzz_react_template/components/ui/toggle-group.tsx +73 -0
  70. package/zzz_react_template/components/ui/toggle.tsx +45 -0
  71. package/zzz_react_template/components/ui/tooltip.tsx +59 -0
  72. package/zzz_react_template/const.ts +17 -0
  73. package/zzz_react_template/contexts/JXRContext.tsx +264 -0
  74. package/zzz_react_template/contexts/ThemeContext.tsx +64 -0
  75. package/zzz_react_template/hooks/useComposition.ts +81 -0
  76. package/zzz_react_template/hooks/useMobile.tsx +21 -0
  77. package/zzz_react_template/hooks/usePersistFn.ts +20 -0
  78. package/zzz_react_template/index.css +518 -11
  79. package/zzz_react_template/lib/jxr-runtime/index.ts +201 -0
  80. package/zzz_react_template/lib/jxr-runtime/module-resolver.ts +520 -0
  81. package/zzz_react_template/lib/jxr-runtime/moq-transport.ts +267 -0
  82. package/zzz_react_template/lib/jxr-runtime/web-crypto.ts +279 -0
  83. package/zzz_react_template/lib/jxr-runtime/worker-pool.ts +321 -0
  84. package/zzz_react_template/lib/utils.ts +6 -0
  85. package/zzz_react_template/main.tsx +4 -9
  86. package/zzz_react_template/pages/Docs.tsx +955 -0
  87. package/zzz_react_template/pages/Home.tsx +1080 -0
  88. package/zzz_react_template/pages/NotFound.tsx +105 -0
  89. package/zzz_react_template/tsconfig.json +24 -0
@@ -0,0 +1,734 @@
1
+ "use client";
2
+
3
+ import { Button } from "@/components/ui/button";
4
+ import { Input } from "@/components/ui/input";
5
+ import { Separator } from "@/components/ui/separator";
6
+ import {
7
+ Sheet,
8
+ SheetContent,
9
+ SheetDescription,
10
+ SheetHeader,
11
+ SheetTitle,
12
+ } from "@/components/ui/sheet";
13
+ import { Skeleton } from "@/components/ui/skeleton";
14
+ import {
15
+ Tooltip,
16
+ TooltipContent,
17
+ TooltipProvider,
18
+ TooltipTrigger,
19
+ } from "@/components/ui/tooltip";
20
+ import { useIsMobile } from "@/hooks/useMobile";
21
+ import { cn } from "@/lib/utils";
22
+ import { Slot } from "@radix-ui/react-slot";
23
+ import { cva, VariantProps } from "class-variance-authority";
24
+ import { PanelLeftIcon } from "lucide-react";
25
+ import * as React from "react";
26
+
27
+ const SIDEBAR_COOKIE_NAME = "sidebar_state";
28
+ const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
29
+ const SIDEBAR_WIDTH = "16rem";
30
+ const SIDEBAR_WIDTH_MOBILE = "18rem";
31
+ const SIDEBAR_WIDTH_ICON = "3rem";
32
+ const SIDEBAR_KEYBOARD_SHORTCUT = "b";
33
+
34
+ type SidebarContextProps = {
35
+ state: "expanded" | "collapsed";
36
+ open: boolean;
37
+ setOpen: (open: boolean) => void;
38
+ openMobile: boolean;
39
+ setOpenMobile: (open: boolean) => void;
40
+ isMobile: boolean;
41
+ toggleSidebar: () => void;
42
+ };
43
+
44
+ const SidebarContext = React.createContext<SidebarContextProps | null>(null);
45
+
46
+ function useSidebar() {
47
+ const context = React.useContext(SidebarContext);
48
+ if (!context) {
49
+ throw new Error("useSidebar must be used within a SidebarProvider.");
50
+ }
51
+
52
+ return context;
53
+ }
54
+
55
+ function SidebarProvider({
56
+ defaultOpen = true,
57
+ open: openProp,
58
+ onOpenChange: setOpenProp,
59
+ className,
60
+ style,
61
+ children,
62
+ ...props
63
+ }: React.ComponentProps<"div"> & {
64
+ defaultOpen?: boolean;
65
+ open?: boolean;
66
+ onOpenChange?: (open: boolean) => void;
67
+ }) {
68
+ const isMobile = useIsMobile();
69
+ const [openMobile, setOpenMobile] = React.useState(false);
70
+
71
+ // This is the internal state of the sidebar.
72
+ // We use openProp and setOpenProp for control from outside the component.
73
+ const [_open, _setOpen] = React.useState(defaultOpen);
74
+ const open = openProp ?? _open;
75
+ const setOpen = React.useCallback(
76
+ (value: boolean | ((value: boolean) => boolean)) => {
77
+ const openState = typeof value === "function" ? value(open) : value;
78
+ if (setOpenProp) {
79
+ setOpenProp(openState);
80
+ } else {
81
+ _setOpen(openState);
82
+ }
83
+
84
+ // This sets the cookie to keep the sidebar state.
85
+ document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
86
+ },
87
+ [setOpenProp, open]
88
+ );
89
+
90
+ // Helper to toggle the sidebar.
91
+ const toggleSidebar = React.useCallback(() => {
92
+ return isMobile ? setOpenMobile(open => !open) : setOpen(open => !open);
93
+ }, [isMobile, setOpen, setOpenMobile]);
94
+
95
+ // Adds a keyboard shortcut to toggle the sidebar.
96
+ React.useEffect(() => {
97
+ const handleKeyDown = (event: KeyboardEvent) => {
98
+ if (
99
+ event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
100
+ (event.metaKey || event.ctrlKey)
101
+ ) {
102
+ event.preventDefault();
103
+ toggleSidebar();
104
+ }
105
+ };
106
+
107
+ window.addEventListener("keydown", handleKeyDown);
108
+ return () => window.removeEventListener("keydown", handleKeyDown);
109
+ }, [toggleSidebar]);
110
+
111
+ // We add a state so that we can do data-state="expanded" or "collapsed".
112
+ // This makes it easier to style the sidebar with Tailwind classes.
113
+ const state = open ? "expanded" : "collapsed";
114
+
115
+ const contextValue = React.useMemo<SidebarContextProps>(
116
+ () => ({
117
+ state,
118
+ open,
119
+ setOpen,
120
+ isMobile,
121
+ openMobile,
122
+ setOpenMobile,
123
+ toggleSidebar,
124
+ }),
125
+ [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
126
+ );
127
+
128
+ return (
129
+ <SidebarContext.Provider value={contextValue}>
130
+ <TooltipProvider delayDuration={0}>
131
+ <div
132
+ data-slot="sidebar-wrapper"
133
+ style={
134
+ {
135
+ "--sidebar-width": SIDEBAR_WIDTH,
136
+ "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
137
+ ...style,
138
+ } as React.CSSProperties
139
+ }
140
+ className={cn(
141
+ "group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
142
+ className
143
+ )}
144
+ {...props}
145
+ >
146
+ {children}
147
+ </div>
148
+ </TooltipProvider>
149
+ </SidebarContext.Provider>
150
+ );
151
+ }
152
+
153
+ function Sidebar({
154
+ side = "left",
155
+ variant = "sidebar",
156
+ collapsible = "offcanvas",
157
+ disableTransition = false,
158
+ className,
159
+ children,
160
+ ...props
161
+ }: React.ComponentProps<"div"> & {
162
+ side?: "left" | "right";
163
+ variant?: "sidebar" | "floating" | "inset";
164
+ collapsible?: "offcanvas" | "icon" | "none";
165
+ disableTransition?: boolean;
166
+ }) {
167
+ const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
168
+
169
+ if (collapsible === "none") {
170
+ return (
171
+ <div
172
+ data-slot="sidebar"
173
+ className={cn(
174
+ "bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
175
+ className
176
+ )}
177
+ {...props}
178
+ >
179
+ {children}
180
+ </div>
181
+ );
182
+ }
183
+
184
+ if (isMobile) {
185
+ return (
186
+ <Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
187
+ <SheetContent
188
+ data-sidebar="sidebar"
189
+ data-slot="sidebar"
190
+ data-mobile="true"
191
+ className="bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden"
192
+ style={
193
+ {
194
+ "--sidebar-width": SIDEBAR_WIDTH_MOBILE,
195
+ } as React.CSSProperties
196
+ }
197
+ side={side}
198
+ >
199
+ <SheetHeader className="sr-only">
200
+ <SheetTitle>Sidebar</SheetTitle>
201
+ <SheetDescription>Displays the mobile sidebar.</SheetDescription>
202
+ </SheetHeader>
203
+ <div className="flex h-full w-full flex-col">{children}</div>
204
+ </SheetContent>
205
+ </Sheet>
206
+ );
207
+ }
208
+
209
+ return (
210
+ <div
211
+ className="group peer text-sidebar-foreground hidden md:block"
212
+ data-state={state}
213
+ data-collapsible={state === "collapsed" ? collapsible : ""}
214
+ data-variant={variant}
215
+ data-side={side}
216
+ data-slot="sidebar"
217
+ >
218
+ {/* This is what handles the sidebar gap on desktop */}
219
+ <div
220
+ data-slot="sidebar-gap"
221
+ className={cn(
222
+ "relative w-(--sidebar-width) bg-transparent",
223
+ disableTransition
224
+ ? "transition-none"
225
+ : "transition-[width] duration-200 ease-linear",
226
+ "group-data-[collapsible=offcanvas]:w-0",
227
+ "group-data-[side=right]:rotate-180",
228
+ variant === "floating" || variant === "inset"
229
+ ? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
230
+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
231
+ )}
232
+ />
233
+ <div
234
+ data-slot="sidebar-container"
235
+ className={cn(
236
+ "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) md:flex",
237
+ disableTransition
238
+ ? "transition-none"
239
+ : "transition-[left,right,width] duration-200 ease-linear",
240
+ side === "left"
241
+ ? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
242
+ : "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
243
+ // Adjust the padding for floating and inset variants.
244
+ variant === "floating" || variant === "inset"
245
+ ? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
246
+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
247
+ className
248
+ )}
249
+ {...props}
250
+ >
251
+ <div
252
+ data-sidebar="sidebar"
253
+ data-slot="sidebar-inner"
254
+ className="bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm"
255
+ >
256
+ {children}
257
+ </div>
258
+ </div>
259
+ </div>
260
+ );
261
+ }
262
+
263
+ function SidebarTrigger({
264
+ className,
265
+ onClick,
266
+ ...props
267
+ }: React.ComponentProps<typeof Button>) {
268
+ const { toggleSidebar } = useSidebar();
269
+
270
+ return (
271
+ <Button
272
+ data-sidebar="trigger"
273
+ data-slot="sidebar-trigger"
274
+ variant="ghost"
275
+ size="icon"
276
+ className={cn("size-7", className)}
277
+ onClick={event => {
278
+ onClick?.(event);
279
+ toggleSidebar();
280
+ }}
281
+ {...props}
282
+ >
283
+ <PanelLeftIcon />
284
+ <span className="sr-only">Toggle Sidebar</span>
285
+ </Button>
286
+ );
287
+ }
288
+
289
+ function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
290
+ const { toggleSidebar } = useSidebar();
291
+
292
+ return (
293
+ <button
294
+ data-sidebar="rail"
295
+ data-slot="sidebar-rail"
296
+ aria-label="Toggle Sidebar"
297
+ tabIndex={-1}
298
+ onClick={toggleSidebar}
299
+ title="Toggle Sidebar"
300
+ className={cn(
301
+ "hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex",
302
+ "in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
303
+ "[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
304
+ "hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
305
+ "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
306
+ "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
307
+ className
308
+ )}
309
+ {...props}
310
+ />
311
+ );
312
+ }
313
+
314
+ function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
315
+ return (
316
+ <main
317
+ data-slot="sidebar-inset"
318
+ className={cn(
319
+ "bg-background relative flex w-full flex-1 flex-col",
320
+ "md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
321
+ className
322
+ )}
323
+ {...props}
324
+ />
325
+ );
326
+ }
327
+
328
+ function SidebarInput({
329
+ className,
330
+ ...props
331
+ }: React.ComponentProps<typeof Input>) {
332
+ return (
333
+ <Input
334
+ data-slot="sidebar-input"
335
+ data-sidebar="input"
336
+ className={cn("bg-background h-8 w-full shadow-none", className)}
337
+ {...props}
338
+ />
339
+ );
340
+ }
341
+
342
+ function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
343
+ return (
344
+ <div
345
+ data-slot="sidebar-header"
346
+ data-sidebar="header"
347
+ className={cn("flex flex-col gap-2 p-2", className)}
348
+ {...props}
349
+ />
350
+ );
351
+ }
352
+
353
+ function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
354
+ return (
355
+ <div
356
+ data-slot="sidebar-footer"
357
+ data-sidebar="footer"
358
+ className={cn("flex flex-col gap-2 p-2", className)}
359
+ {...props}
360
+ />
361
+ );
362
+ }
363
+
364
+ function SidebarSeparator({
365
+ className,
366
+ ...props
367
+ }: React.ComponentProps<typeof Separator>) {
368
+ return (
369
+ <Separator
370
+ data-slot="sidebar-separator"
371
+ data-sidebar="separator"
372
+ className={cn("bg-sidebar-border mx-2 w-auto", className)}
373
+ {...props}
374
+ />
375
+ );
376
+ }
377
+
378
+ function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
379
+ return (
380
+ <div
381
+ data-slot="sidebar-content"
382
+ data-sidebar="content"
383
+ className={cn(
384
+ "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
385
+ className
386
+ )}
387
+ {...props}
388
+ />
389
+ );
390
+ }
391
+
392
+ function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
393
+ return (
394
+ <div
395
+ data-slot="sidebar-group"
396
+ data-sidebar="group"
397
+ className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
398
+ {...props}
399
+ />
400
+ );
401
+ }
402
+
403
+ function SidebarGroupLabel({
404
+ className,
405
+ asChild = false,
406
+ ...props
407
+ }: React.ComponentProps<"div"> & { asChild?: boolean }) {
408
+ const Comp = asChild ? Slot : "div";
409
+
410
+ return (
411
+ <Comp
412
+ data-slot="sidebar-group-label"
413
+ data-sidebar="group-label"
414
+ className={cn(
415
+ "text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
416
+ "group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
417
+ className
418
+ )}
419
+ {...props}
420
+ />
421
+ );
422
+ }
423
+
424
+ function SidebarGroupAction({
425
+ className,
426
+ asChild = false,
427
+ ...props
428
+ }: React.ComponentProps<"button"> & { asChild?: boolean }) {
429
+ const Comp = asChild ? Slot : "button";
430
+
431
+ return (
432
+ <Comp
433
+ data-slot="sidebar-group-action"
434
+ data-sidebar="group-action"
435
+ className={cn(
436
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
437
+ // Increases the hit area of the button on mobile.
438
+ "after:absolute after:-inset-2 md:after:hidden",
439
+ "group-data-[collapsible=icon]:hidden",
440
+ className
441
+ )}
442
+ {...props}
443
+ />
444
+ );
445
+ }
446
+
447
+ function SidebarGroupContent({
448
+ className,
449
+ ...props
450
+ }: React.ComponentProps<"div">) {
451
+ return (
452
+ <div
453
+ data-slot="sidebar-group-content"
454
+ data-sidebar="group-content"
455
+ className={cn("w-full text-sm", className)}
456
+ {...props}
457
+ />
458
+ );
459
+ }
460
+
461
+ function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
462
+ return (
463
+ <ul
464
+ data-slot="sidebar-menu"
465
+ data-sidebar="menu"
466
+ className={cn("flex w-full min-w-0 flex-col gap-1", className)}
467
+ {...props}
468
+ />
469
+ );
470
+ }
471
+
472
+ function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
473
+ return (
474
+ <li
475
+ data-slot="sidebar-menu-item"
476
+ data-sidebar="menu-item"
477
+ className={cn("group/menu-item relative", className)}
478
+ {...props}
479
+ />
480
+ );
481
+ }
482
+
483
+ const sidebarMenuButtonVariants = cva(
484
+ "peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
485
+ {
486
+ variants: {
487
+ variant: {
488
+ default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
489
+ outline:
490
+ "bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
491
+ },
492
+ size: {
493
+ default: "h-8 text-sm",
494
+ sm: "h-7 text-xs",
495
+ lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
496
+ },
497
+ },
498
+ defaultVariants: {
499
+ variant: "default",
500
+ size: "default",
501
+ },
502
+ }
503
+ );
504
+
505
+ function SidebarMenuButton({
506
+ asChild = false,
507
+ isActive = false,
508
+ variant = "default",
509
+ size = "default",
510
+ tooltip,
511
+ className,
512
+ ...props
513
+ }: React.ComponentProps<"button"> & {
514
+ asChild?: boolean;
515
+ isActive?: boolean;
516
+ tooltip?: string | React.ComponentProps<typeof TooltipContent>;
517
+ } & VariantProps<typeof sidebarMenuButtonVariants>) {
518
+ const Comp = asChild ? Slot : "button";
519
+ const { isMobile, state } = useSidebar();
520
+
521
+ const button = (
522
+ <Comp
523
+ data-slot="sidebar-menu-button"
524
+ data-sidebar="menu-button"
525
+ data-size={size}
526
+ data-active={isActive}
527
+ className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
528
+ {...props}
529
+ />
530
+ );
531
+
532
+ if (!tooltip) {
533
+ return button;
534
+ }
535
+
536
+ if (typeof tooltip === "string") {
537
+ tooltip = {
538
+ children: tooltip,
539
+ };
540
+ }
541
+
542
+ return (
543
+ <Tooltip>
544
+ <TooltipTrigger asChild>{button}</TooltipTrigger>
545
+ <TooltipContent
546
+ side="right"
547
+ align="center"
548
+ hidden={state !== "collapsed" || isMobile}
549
+ {...tooltip}
550
+ />
551
+ </Tooltip>
552
+ );
553
+ }
554
+
555
+ function SidebarMenuAction({
556
+ className,
557
+ asChild = false,
558
+ showOnHover = false,
559
+ ...props
560
+ }: React.ComponentProps<"button"> & {
561
+ asChild?: boolean;
562
+ showOnHover?: boolean;
563
+ }) {
564
+ const Comp = asChild ? Slot : "button";
565
+
566
+ return (
567
+ <Comp
568
+ data-slot="sidebar-menu-action"
569
+ data-sidebar="menu-action"
570
+ className={cn(
571
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
572
+ // Increases the hit area of the button on mobile.
573
+ "after:absolute after:-inset-2 md:after:hidden",
574
+ "peer-data-[size=sm]/menu-button:top-1",
575
+ "peer-data-[size=default]/menu-button:top-1.5",
576
+ "peer-data-[size=lg]/menu-button:top-2.5",
577
+ "group-data-[collapsible=icon]:hidden",
578
+ showOnHover &&
579
+ "peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",
580
+ className
581
+ )}
582
+ {...props}
583
+ />
584
+ );
585
+ }
586
+
587
+ function SidebarMenuBadge({
588
+ className,
589
+ ...props
590
+ }: React.ComponentProps<"div">) {
591
+ return (
592
+ <div
593
+ data-slot="sidebar-menu-badge"
594
+ data-sidebar="menu-badge"
595
+ className={cn(
596
+ "text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none",
597
+ "peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
598
+ "peer-data-[size=sm]/menu-button:top-1",
599
+ "peer-data-[size=default]/menu-button:top-1.5",
600
+ "peer-data-[size=lg]/menu-button:top-2.5",
601
+ "group-data-[collapsible=icon]:hidden",
602
+ className
603
+ )}
604
+ {...props}
605
+ />
606
+ );
607
+ }
608
+
609
+ function SidebarMenuSkeleton({
610
+ className,
611
+ showIcon = false,
612
+ ...props
613
+ }: React.ComponentProps<"div"> & {
614
+ showIcon?: boolean;
615
+ }) {
616
+ // Random width between 50 to 90%.
617
+ const width = React.useMemo(() => {
618
+ return `${Math.floor(Math.random() * 40) + 50}%`;
619
+ }, []);
620
+
621
+ return (
622
+ <div
623
+ data-slot="sidebar-menu-skeleton"
624
+ data-sidebar="menu-skeleton"
625
+ className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
626
+ {...props}
627
+ >
628
+ {showIcon && (
629
+ <Skeleton
630
+ className="size-4 rounded-md"
631
+ data-sidebar="menu-skeleton-icon"
632
+ />
633
+ )}
634
+ <Skeleton
635
+ className="h-4 max-w-(--skeleton-width) flex-1"
636
+ data-sidebar="menu-skeleton-text"
637
+ style={
638
+ {
639
+ "--skeleton-width": width,
640
+ } as React.CSSProperties
641
+ }
642
+ />
643
+ </div>
644
+ );
645
+ }
646
+
647
+ function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
648
+ return (
649
+ <ul
650
+ data-slot="sidebar-menu-sub"
651
+ data-sidebar="menu-sub"
652
+ className={cn(
653
+ "border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5",
654
+ "group-data-[collapsible=icon]:hidden",
655
+ className
656
+ )}
657
+ {...props}
658
+ />
659
+ );
660
+ }
661
+
662
+ function SidebarMenuSubItem({
663
+ className,
664
+ ...props
665
+ }: React.ComponentProps<"li">) {
666
+ return (
667
+ <li
668
+ data-slot="sidebar-menu-sub-item"
669
+ data-sidebar="menu-sub-item"
670
+ className={cn("group/menu-sub-item relative", className)}
671
+ {...props}
672
+ />
673
+ );
674
+ }
675
+
676
+ function SidebarMenuSubButton({
677
+ asChild = false,
678
+ size = "md",
679
+ isActive = false,
680
+ className,
681
+ ...props
682
+ }: React.ComponentProps<"a"> & {
683
+ asChild?: boolean;
684
+ size?: "sm" | "md";
685
+ isActive?: boolean;
686
+ }) {
687
+ const Comp = asChild ? Slot : "a";
688
+
689
+ return (
690
+ <Comp
691
+ data-slot="sidebar-menu-sub-button"
692
+ data-sidebar="menu-sub-button"
693
+ data-size={size}
694
+ data-active={isActive}
695
+ className={cn(
696
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-hidden focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
697
+ "data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
698
+ size === "sm" && "text-xs",
699
+ size === "md" && "text-sm",
700
+ "group-data-[collapsible=icon]:hidden",
701
+ className
702
+ )}
703
+ {...props}
704
+ />
705
+ );
706
+ }
707
+
708
+ export {
709
+ Sidebar,
710
+ SidebarContent,
711
+ SidebarFooter,
712
+ SidebarGroup,
713
+ SidebarGroupAction,
714
+ SidebarGroupContent,
715
+ SidebarGroupLabel,
716
+ SidebarHeader,
717
+ SidebarInput,
718
+ SidebarInset,
719
+ SidebarMenu,
720
+ SidebarMenuAction,
721
+ SidebarMenuBadge,
722
+ SidebarMenuButton,
723
+ SidebarMenuItem,
724
+ SidebarMenuSkeleton,
725
+ SidebarMenuSub,
726
+ SidebarMenuSubButton,
727
+ SidebarMenuSubItem,
728
+ SidebarProvider,
729
+ SidebarRail,
730
+ SidebarSeparator,
731
+ SidebarTrigger,
732
+ useSidebar
733
+ };
734
+