"use client"; import { toast } from "sonner"; import { findFormValue, getByPath } from "@json-render/core"; import { useStateStore, defineRegistry } from "@json-render/react"; import { Bar, BarChart as RechartsBarChart, CartesianGrid, Line, LineChart as RechartsLineChart, XAxis, } from "recharts"; import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig, } from "@/components/ui/chart"; // shadcn components import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Badge } from "@/components/ui/badge"; import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert"; import { Separator } from "@/components/ui/separator"; import { Accordion, AccordionItem, AccordionTrigger, AccordionContent, } from "@/components/ui/accordion"; import { Table, TableHeader, TableBody, TableHead, TableRow, TableCell, } from "@/components/ui/table"; import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"; import { Checkbox } from "@/components/ui/checkbox"; import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, } from "@/components/ui/dialog"; import { Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerTitle, DrawerDescription, } from "@/components/ui/drawer"; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, } from "@/components/ui/dropdown-menu"; import { Pagination, PaginationContent, PaginationItem, PaginationPrevious, PaginationNext, PaginationLink, } from "@/components/ui/pagination"; import { Popover, PopoverTrigger, PopoverContent, } from "@/components/ui/popover"; import { Progress } from "@/components/ui/progress"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem, } from "@/components/ui/select"; import { Skeleton } from "@/components/ui/skeleton"; import { Switch } from "@/components/ui/switch"; import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; import { Textarea } from "@/components/ui/textarea"; import { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider, } from "@/components/ui/tooltip"; import { dashboardCatalog } from "./catalog"; // ============================================================================= // Registry // ============================================================================= export const { registry, handlers, executeAction } = defineRegistry( dashboardCatalog, { components: { Stack: ({ props, children }) => { const gapClass = { sm: "gap-2", md: "gap-4", lg: "gap-6" }[props.gap ?? "md"] ?? "gap-4"; return (
{children}
); }, Accordion: ({ props, children }) => ( {children} ), AccordionItem: ({ props, children }) => ( {props.title} {children} ), Button: ({ props, emit, loading }) => ( ), Input: ({ props }) => { const { state, set } = useStateStore(); return (
{props.label ? : null} set(props.valuePath, e.target.value)} />
); }, Form: ({ children, emit }) => (
{ e.preventDefault(); emit?.("submit"); }} className="flex flex-col gap-4" > {children}
), Badge: ({ props }) => ( {props.text} ), Alert: ({ props }) => ( {props.title} {props.description ? ( {props.description} ) : null} ), Separator: () => , Avatar: ({ props }) => ( {props.src ? ( ) : null} {props.fallback} ), Checkbox: ({ props }) => { const { state, set } = useStateStore(); const checked = (getByPath(state, props.valuePath) as boolean) ?? props.defaultChecked ?? false; return (
set(props.valuePath, value)} /> {props.label ? ( ) : null}
); }, Dialog: ({ props, children }) => ( {props.title} {props.description ? ( {props.description} ) : null} {children} ), Drawer: ({ props, children }) => ( {props.title} {props.description ? ( {props.description} ) : null}
{children}
), DropdownMenu: ({ props }) => ( {props.items.map((item, i) => ( {item.label} ))} ), Label: ({ props }) => ( ), Pagination: ({ props }) => { const pages = Array.from({ length: props.totalPages }, (_, i) => i + 1); return ( {pages.map((page) => ( {page} ))} ); }, Popover: ({ props, children }) => ( {children} ), Progress: ({ props }) => ( ), RadioGroup: ({ props }) => { const { state, set } = useStateStore(); const value = (getByPath(state, props.valuePath) as string) ?? props.defaultValue ?? ""; return ( set(props.valuePath, v)} > {props.options.map((option) => (
))}
); }, Select: ({ props }) => { const { state, set } = useStateStore(); const value = (getByPath(state, props.valuePath) as string) ?? ""; return ( ); }, Skeleton: ({ props }) => ( ), Spinner: ({ props }) => { const sizes = { sm: "h-4 w-4", md: "h-6 w-6", lg: "h-8 w-8" }; const size = sizes[props.size ?? "md"]; return (
); }, Switch: ({ props }) => { const { state, set } = useStateStore(); const checked = (getByPath(state, props.valuePath) as boolean) ?? props.defaultChecked ?? false; return (
set(props.valuePath, value)} /> {props.label ? ( ) : null}
); }, Tabs: ({ props, children }) => ( {props.tabs.map((tab) => ( {tab.label} ))} {children} ), TabContent: ({ props, children }) => ( {children} ), Textarea: ({ props }) => { const { state, set } = useStateStore(); return (
{props.label ? : null}