| // --------------------------------------------------------------------------- | |
| // Auto-generate slash-menu items from the component registry. | |
| // --------------------------------------------------------------------------- | |
| import { COMPONENTS } from "./registry"; | |
| import type { Editor } from "@tiptap/core"; | |
| export interface SlashItem { | |
| title: string; | |
| description: string; | |
| icon: string; | |
| command: (editor: Editor) => void; | |
| } | |
| export function getComponentSlashItems(): SlashItem[] { | |
| return COMPONENTS.map((def) => { | |
| const commandName = `insert${def.tag}`; | |
| return { | |
| title: def.label, | |
| description: def.description, | |
| icon: def.icon, | |
| command: (editor: Editor) => { | |
| (editor.chain().focus() as any)[commandName]().run(); | |
| }, | |
| }; | |
| }); | |
| } | |