mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-22 20:25:44 +00:00
36 lines
933 B
TypeScript
36 lines
933 B
TypeScript
"use server"
|
|
|
|
import { registryItemSchema } from "shadcn/schema"
|
|
import { z } from "zod"
|
|
|
|
export async function getAllBlockIds(
|
|
types: z.infer<typeof registryItemSchema>["type"][] = [
|
|
"registry:block",
|
|
"registry:internal",
|
|
],
|
|
categories: string[] = []
|
|
): Promise<string[]> {
|
|
const blocks = await getAllBlocks(types, categories)
|
|
|
|
return blocks.map((block) => block.name)
|
|
}
|
|
|
|
export async function getAllBlocks(
|
|
types: z.infer<typeof registryItemSchema>["type"][] = [
|
|
"registry:block",
|
|
"registry:internal",
|
|
],
|
|
categories: string[] = []
|
|
) {
|
|
const { Index } = await import("@/registry/__index__")
|
|
const index = z.record(registryItemSchema).parse(Index)
|
|
|
|
return Object.values(index).filter(
|
|
(block) =>
|
|
types.includes(block.type) &&
|
|
(categories.length === 0 ||
|
|
block.categories?.some((category) => categories.includes(category))) &&
|
|
!block.name.startsWith("chart-")
|
|
)
|
|
}
|