Files
shadcn-ui/apps/www/lib/blocks.ts
shadcn 8f0c26f22a feat(www): code for blocks (#5756)
* feat: update blocks

* fix: scrollbars

* fix: code viewer

* test(shadcn): fix
2024-11-07 17:09:41 +04:00

31 lines
880 B
TypeScript

"use server"
import { Index } from "@/__registry__"
import { z } from "zod"
import { Style } from "@/registry/registry-styles"
import { registryEntrySchema } from "@/registry/schema"
const DEFAULT_BLOCKS_STYLE = "new-york" satisfies Style["name"]
const BLOCKS_WHITELIST_PREFIXES = ["sidebar", "login"]
const REGISTRY_BLOCK_TYPES = ["registry:block"]
export async function getAllBlockIds(
style: Style["name"] = DEFAULT_BLOCKS_STYLE
) {
const blocks = await _getAllBlocks(style)
return blocks.map((block) => block.name)
}
async function _getAllBlocks(style: Style["name"] = DEFAULT_BLOCKS_STYLE) {
const index = z.record(registryEntrySchema).parse(Index[style])
return Object.values(index).filter((block) =>
BLOCKS_WHITELIST_PREFIXES.some(
(prefix) =>
block.name.startsWith(prefix) &&
REGISTRY_BLOCK_TYPES.includes(block.type)
)
)
}