import { BlockDefinition } from '../types/blocks'; import { FrameworkType } from '../types'; let blocks: Map = new Map(); let blocksByFramework: Map = 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 { const all = getBlocksForFramework(framework); const categorized = new Map(); for (const block of all) { const cat = block.category; if (!categorized.has(cat)) { categorized.set(cat, []); } categorized.get(cat)!.push(block); } return categorized; }