mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-11 09:51:40 +00:00
* feat: init * fix * fix * fix * feat * feat * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * feat: implement icons * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * feat: update init command * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * feat: dialog * feat * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * feat: add registry:base item type * feat: rename frame to canva * fix * feat * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fi * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * feat: add all colors * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * feat: add outfit font * fix * fix * fix * fix * fix * chore: changeset * fix * fix * fix * fix * fix * fix * fix * fix
79 lines
1.9 KiB
TypeScript
79 lines
1.9 KiB
TypeScript
import * as React from "react"
|
|
import { type registryItemFileSchema } from "shadcn/schema"
|
|
import { type z } from "zod"
|
|
|
|
import { highlightCode } from "@/lib/highlight-code"
|
|
import {
|
|
createFileTreeForRegistryItemFiles,
|
|
getRegistryItem,
|
|
} from "@/lib/registry"
|
|
import { cn } from "@/lib/utils"
|
|
import { BlockViewer } from "@/components/block-viewer"
|
|
import { ComponentPreview } from "@/components/component-preview"
|
|
import { type Style } from "@/registry/_legacy-styles"
|
|
|
|
export async function BlockDisplay({
|
|
name,
|
|
styleName,
|
|
}: {
|
|
name: string
|
|
styleName: Style["name"]
|
|
}) {
|
|
const item = await getCachedRegistryItem(name, styleName)
|
|
|
|
if (!item?.files) {
|
|
return null
|
|
}
|
|
|
|
const [tree, highlightedFiles] = await Promise.all([
|
|
getCachedFileTree(item.files),
|
|
getCachedHighlightedFiles(item.files),
|
|
])
|
|
|
|
return (
|
|
<BlockViewer
|
|
item={item}
|
|
tree={tree}
|
|
highlightedFiles={highlightedFiles}
|
|
styleName={styleName}
|
|
>
|
|
<ComponentPreview
|
|
name={item.name}
|
|
styleName={styleName}
|
|
hideCode
|
|
className={cn(
|
|
"my-0 **:[.preview]:h-auto **:[.preview]:p-4 **:[.preview>.p-6]:p-0",
|
|
item.meta?.containerClassName
|
|
)}
|
|
/>
|
|
</BlockViewer>
|
|
)
|
|
}
|
|
|
|
const getCachedRegistryItem = React.cache(
|
|
async (name: string, styleName: Style["name"]) => {
|
|
return await getRegistryItem(name, styleName)
|
|
}
|
|
)
|
|
|
|
const getCachedFileTree = React.cache(
|
|
async (files: Array<{ path: string; target?: string }>) => {
|
|
if (!files) {
|
|
return null
|
|
}
|
|
|
|
return await createFileTreeForRegistryItemFiles(files)
|
|
}
|
|
)
|
|
|
|
const getCachedHighlightedFiles = React.cache(
|
|
async (files: z.infer<typeof registryItemFileSchema>[]) => {
|
|
return await Promise.all(
|
|
files.map(async (file) => ({
|
|
...file,
|
|
highlightedContent: await highlightCode(file.content ?? ""),
|
|
}))
|
|
)
|
|
}
|
|
)
|