From 558191e922371ab172609370da0c7a823851bbee Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 23 Jun 2026 18:33:59 +0800 Subject: [PATCH] refactor(tiptap): type CommandItem.editor as Editor, explicit SlashPopup return type --- libs/tiptap-editor/src/slash-command.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libs/tiptap-editor/src/slash-command.ts b/libs/tiptap-editor/src/slash-command.ts index beb5e2a..58c6d56 100644 --- a/libs/tiptap-editor/src/slash-command.ts +++ b/libs/tiptap-editor/src/slash-command.ts @@ -1,4 +1,4 @@ -import { Extension, type Range } from '@tiptap/core' +import { Extension, type Editor, type Range } from '@tiptap/core' import { Suggestion, type SuggestionProps, type SuggestionKeyDownProps } from '@tiptap/suggestion' import { PluginKey } from '@tiptap/pm/state' @@ -6,7 +6,7 @@ interface CommandItem { title: string description: string icon: string - command: (props: { editor: any; range: Range }) => void + command: (props: { editor: Editor; range: Range }) => void } /** @@ -198,7 +198,7 @@ export const SlashCommand = Extension.create({ ) }, render() { - let popup: ReturnType | null = null + let popup: SlashPopup | null = null return { onStart(props) { @@ -229,7 +229,16 @@ export const SlashCommand = Extension.create({ }, }) -function createPopup(props: SuggestionProps) { +/** 斜杠命令浮层实例:供 Suggestion render 生命周期驱动。 */ +interface SlashPopup { + component: HTMLElement + updateItems(items: CommandItem[]): void + updatePosition(): void + onKeyDown(props: SuggestionKeyDownProps): boolean + destroy(): void +} + +function createPopup(props: SuggestionProps): SlashPopup { const component = document.createElement('div') component.classList.add('slash-command')