import type { BlockEditor } from "./editor.type.js"; /** * Editor registry — the DOM-side counterpart of `block/registry.ts`. * * Kept separate on purpose: if editors were stored in the block registry, * their `HTMLElement` parameters would reappear in the emitted types of the * pure `./block` entry point and re-create the leak this split removes. */ const editors: Record = {}; /** Register an editor for a block type. Overwrites any existing editor. */ export function registerEditor(type: string, editor: BlockEditor): void { editors[type] = editor; } /** * Resolve the editor for a block type. * * `html:*` share one editor, so the prefix is matched after an exact lookup * fails. Block types with no editor (hr, widget, router-slot) return * undefined and stay read-only. */ export function resolveEditor(type: string): BlockEditor | undefined { if (type in editors) return editors[type]; if (type.startsWith("html:")) return editors["html:*"]; return undefined; } /** List all registered editor type names. */ export function listEditors(): string[] { return Object.keys(editors); } /** * Remove a previously registered editor. * Returns `true` if the editor existed, `false` otherwise. */ export function unregisterEditor(type: string): boolean { if (type in editors) { delete editors[type]; return true; } return false; }