forked from BeOnAuto/auto-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblocks.ts
More file actions
28 lines (23 loc) · 912 Bytes
/
blocks.ts
File metadata and controls
28 lines (23 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use server';
import { registryItemSchema } from 'shadcn/registry';
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-'),
);
}