@@ -21,7 +21,6 @@ import { ContentEditable } from '@lexical/react/LexicalContentEditable';
2121import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin' ;
2222import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary'
2323import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin'
24- import ToolbarPlugin from './plugins/ToolbarPlugin' ;
2524
2625import { $convertToMarkdownString } from '@lexical/markdown' ;
2726import { Typography } from 'antd' ;
@@ -49,27 +48,35 @@ import TabFocusPlugin from './plugins/TabFocusPlugin';
4948import { TabIndentationPlugin } from '@lexical/react/LexicalTabIndentationPlugin' ;
5049import { ClearEditorPlugin } from '@lexical/react/LexicalClearEditorPlugin' ;
5150import { useSharedHistoryContext } from './context/SharedHistoryContext' ;
51+ import { USER_FAVORITE } from '@/services/user/favorite/typings' ;
5252
5353export interface LexicalInnerEditorRefProperty {
5454 getEditor : ( ) => LexicalEditor ;
5555 getMarkdownContent : ( ) => string ;
5656}
5757
58+ export type BotMentionOptions = {
59+ enable ?: boolean ,
60+ trigger ?: string ,
61+ onSelect ?: ( botFavorite : USER_FAVORITE . BotFavoriteEntity ) => void ;
62+ }
63+
5864/**
5965 * 需要保证该组件无状态
6066 */
61- const LexicalInnerEditor : React . FC < {
67+ const LexicalInnerEditor = forwardRef < LexicalInnerEditorRefProperty , {
6268 placeholder ?: string ,
6369 showToolbar ?: boolean ,
6470 onChange ?: ( markdown : string ) => void ,
65- } > = forwardRef ( ( { placeholder, showToolbar = true , onChange } , ref ) => {
71+ botMentionOptions ?: BotMentionOptions
72+ } > ( ( { placeholder, showToolbar = true , onChange, botMentionOptions } , ref ) => {
6673 const [ floatingAnchorElem , setFloatingAnchorElem ] = useState < HTMLDivElement | null > ( null ) ;
6774 const [ isSmallWidthViewport , setIsSmallWidthViewport ] = useState < boolean > ( false ) ;
6875 const [ editor ] = useLexicalComposerContext ( ) ;
6976 const [ isLinkEditMode , setIsLinkEditMode ] = useState < boolean > ( false ) ;
7077 const { historyState } = useSharedHistoryContext ( ) ;
7178
72- const [ markdown , setMarkdown ] = useState < string > ( ) ;
79+ const [ markdown , setMarkdown ] = useState < string > ( '' ) ;
7380
7481 useImperativeHandle ( ref , ( ) => ( {
7582 getEditor ( ) {
@@ -105,14 +112,15 @@ const LexicalInnerEditor: React.FC<{
105112
106113 return < >
107114 { /* 工具栏 */ }
108- { showToolbar &&
109- < ToolbarPlugin
115+ { showToolbar && ( ( ) => {
116+ const ToolbarPlugin = require ( './plugins/ToolbarPlugin' ) . default ;
117+ return < ToolbarPlugin
110118 editor = { editor }
111119 activeEditor = { editor }
112120 setActiveEditor = { ( ) => { } }
113121 setIsLinkEditMode = { setIsLinkEditMode }
114- />
115- }
122+ /> ;
123+ } ) ( ) }
116124
117125 { /* 键盘事件监听 */ }
118126 { /* <KeyboardEventPlugin editor={editor} onKeyboardEvent={(event: KeyboardEvent) => {
@@ -177,7 +185,16 @@ const LexicalInnerEditor: React.FC<{
177185 < SelectionAlwaysOnDisplay />
178186
179187 { /* 斜杠青年 */ }
180- < ComponentPickerPlugin trigger = "/" />
188+ < ComponentPickerPlugin />
189+
190+ { /* @BOT */ }
191+ { botMentionOptions ?. enable && ( ( ) => {
192+ const BotMentionsPlugin = require ( './plugins/BotMentionsPlugin' ) . default ;
193+ return < BotMentionsPlugin
194+ trigger = { botMentionOptions . trigger }
195+ onSelect = { botMentionOptions . onSelect }
196+ /> ;
197+ } ) ( ) }
181198
182199 { floatingAnchorElem && ! isSmallWidthViewport && ( < >
183200 { /* 代码块工具 */ }
0 commit comments