import * as React from "react" import { type registryItemSchema } from "shadcn/schema" import { type z } from "zod" import { highlightCode } from "@/lib/highlight-code" import { getRegistryItem } from "@/lib/registry" import { cn } from "@/lib/utils" import { ChartToolbar } from "@/components/chart-toolbar" import { type Style } from "@/registry/_legacy-styles" export type Chart = z.infer & { highlightedCode: string } export async function ChartDisplay({ name, styleName, children, className, }: { name: string styleName: Style["name"] } & React.ComponentProps<"div">) { const chart = await getCachedRegistryItem(name, styleName) const highlightedCode = await getChartHighlightedCode( chart?.files?.[0]?.content ?? "" ) if (!chart || !highlightedCode) { return null } return (
{children}
{children}
) } const getCachedRegistryItem = React.cache( async (name: string, styleName: Style["name"]) => { return await getRegistryItem(name, styleName) } ) const getChartHighlightedCode = React.cache(async (content: string) => { return await highlightCode(content) })