Spaces:
Running
Running
| import { BlockDefinition } from '../types/blocks'; | |
| import { FrameworkType } from '../types'; | |
| let blocks: Map<string, BlockDefinition> = new Map(); | |
| let blocksByFramework: Map<string, BlockDefinition[]> = new Map(); | |
| export function registerBlock(block: BlockDefinition): void { | |
| blocks.set(block.id, block); | |
| const key = block.framework; | |
| if (!blocksByFramework.has(key)) { | |
| blocksByFramework.set(key, []); | |
| } | |
| blocksByFramework.get(key)!.push(block); | |
| } | |
| export function registerBlocks(blockList: BlockDefinition[]): void { | |
| blockList.forEach(registerBlock); | |
| } | |
| export function getBlock(id: string): BlockDefinition | undefined { | |
| return blocks.get(id); | |
| } | |
| export function getBlocksForFramework(framework: FrameworkType): BlockDefinition[] { | |
| const frameworkBlocks = blocksByFramework.get(framework) || []; | |
| const allBlocks = blocksByFramework.get('all') || []; | |
| return [...frameworkBlocks, ...allBlocks]; | |
| } | |
| export function getBlocksByCategory(framework: FrameworkType): Map<string, BlockDefinition[]> { | |
| const all = getBlocksForFramework(framework); | |
| const categorized = new Map<string, BlockDefinition[]>(); | |
| for (const block of all) { | |
| const cat = block.category; | |
| if (!categorized.has(cat)) { | |
| categorized.set(cat, []); | |
| } | |
| categorized.get(cat)!.push(block); | |
| } | |
| return categorized; | |
| } | |