File size: 786 Bytes
561e6f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// ---------------------------------------------------------------------------
// 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();
      },
    };
  });
}