|
1 | | -import type { Editor, Range } from '@tiptap/core'; |
| 1 | +import type { Editor, Extensions, Range } from '@tiptap/core'; |
2 | 2 | import { Extension } from '@tiptap/core'; |
3 | 3 | import { PluginKey } from '@tiptap/pm/state'; |
4 | 4 | import { ReactRenderer } from '@tiptap/react'; |
5 | 5 | import type { SuggestionKeyDownProps, SuggestionProps } from '@tiptap/suggestion'; |
6 | 6 | import Suggestion from '@tiptap/suggestion'; |
7 | 7 | import tippy from 'tippy.js'; |
8 | 8 |
|
9 | | -import { renderGroups } from './groups'; |
10 | 9 | import CommandsList from '@/extensions/SlashCommand/components/CommandsList'; |
11 | 10 |
|
| 11 | +import { renderGroups } from './groups'; |
| 12 | +import { type Group } from './types'; |
| 13 | + |
| 14 | +export interface SlashCommandOptions { |
| 15 | + renderGroupItem?: (extension: Extensions[number], groups:Group[]) => void |
| 16 | +} |
| 17 | + |
12 | 18 | const extensionName = 'slashCommand'; |
13 | 19 | let popup: any; |
14 | | -export const SlashCommand = Extension.create({ |
| 20 | +export const SlashCommand = Extension.create<SlashCommandOptions>({ |
15 | 21 | name: extensionName, |
16 | 22 | priority: 200, |
17 | 23 | onCreate() { |
@@ -68,7 +74,7 @@ export const SlashCommand = Extension.create({ |
68 | 74 | items: ({ query, editor }: { query: string, editor: Editor }) => { |
69 | 75 | // get options |
70 | 76 | // Filter commands |
71 | | - const groups = renderGroups(editor.extensionManager.extensions); |
| 77 | + const groups = renderGroups(editor.extensionManager.extensions, this.options.renderGroupItem); |
72 | 78 | const withFilteredCommands = groups.map(group => ({ |
73 | 79 | ...group, |
74 | 80 | commands: group.commands |
|
0 commit comments