Skip to content

Commit a4ea207

Browse files
committed
feat: SlashCommand support renderGroupItem
1 parent 7ccf62c commit a4ea207

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/extensions/SlashCommand/SlashCommand.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
import type { Editor, Range } from '@tiptap/core';
1+
import type { Editor, Extensions, Range } from '@tiptap/core';
22
import { Extension } from '@tiptap/core';
33
import { PluginKey } from '@tiptap/pm/state';
44
import { ReactRenderer } from '@tiptap/react';
55
import type { SuggestionKeyDownProps, SuggestionProps } from '@tiptap/suggestion';
66
import Suggestion from '@tiptap/suggestion';
77
import tippy from 'tippy.js';
88

9-
import { renderGroups } from './groups';
109
import CommandsList from '@/extensions/SlashCommand/components/CommandsList';
1110

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+
1218
const extensionName = 'slashCommand';
1319
let popup: any;
14-
export const SlashCommand = Extension.create({
20+
export const SlashCommand = Extension.create<SlashCommandOptions>({
1521
name: extensionName,
1622
priority: 200,
1723
onCreate() {
@@ -68,7 +74,7 @@ export const SlashCommand = Extension.create({
6874
items: ({ query, editor }: { query: string, editor: Editor }) => {
6975
// get options
7076
// Filter commands
71-
const groups = renderGroups(editor.extensionManager.extensions);
77+
const groups = renderGroups(editor.extensionManager.extensions, this.options.renderGroupItem);
7278
const withFilteredCommands = groups.map(group => ({
7379
...group,
7480
commands: group.commands

src/extensions/SlashCommand/groups.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { actionDialogImage } from '@/extensions/Image/store';
55
import { actionDialogVideo } from '@/extensions/Video/store';
66
import { localeActions } from '@/locales';
77

8+
import type { SlashCommandOptions } from './SlashCommand';
89
import type { Group } from './types';
910

10-
export function renderGroups(extensions: Extensions) {
11+
export function renderGroups(extensions: Extensions, renderGroupItem?: SlashCommandOptions['renderGroupItem']) {
1112
const groups: Group[] = [
1213
{
1314
name: 'format',
@@ -175,6 +176,7 @@ export function renderGroups(extensions: Extensions) {
175176
},
176177
});
177178
}
179+
renderGroupItem?.(extension, groups);
178180
});
179181

180182
return groups;

0 commit comments

Comments
 (0)