@@ -8,7 +8,7 @@ import { MessageInput } from '@/components/chat/message-input';
8
8
import { SecuritySettingContext , withReCaptcha } from '@/components/security-setting-provider' ;
9
9
import { useSize } from '@/components/use-size' ;
10
10
import { cn } from '@/lib/utils' ;
11
- import { type ChangeEvent , type FormEvent , type ReactNode , useContext , useState } from 'react' ;
11
+ import { type ChangeEvent , type FormEvent , type ReactNode , type Ref , useContext , useImperativeHandle , useState } from 'react' ;
12
12
13
13
export interface ConversationProps {
14
14
chatId ?: string ;
@@ -22,9 +22,10 @@ export interface ConversationProps {
22
22
placeholder ?: ( controller : ChatController , postState : ReturnType < typeof useChatPostState > ) => ReactNode ;
23
23
preventMutateBrowserHistory ?: boolean ;
24
24
preventShiftMessageInput ?: boolean ;
25
+ newChatRef ?: Ref < ChatController [ 'post' ] | undefined > ;
25
26
}
26
27
27
- export function Conversation ( { open, chat, chatId, history, placeholder, preventMutateBrowserHistory = false , preventShiftMessageInput = false , className } : ConversationProps ) {
28
+ export function Conversation ( { open, chat, chatId, history, placeholder, preventMutateBrowserHistory = false , preventShiftMessageInput = false , newChatRef , className } : ConversationProps ) {
28
29
const [ inputElement , setInputElement ] = useState < HTMLTextAreaElement | null > ( null ) ;
29
30
30
31
const controller = useChatController ( chatId , chat , history , inputElement ) ;
@@ -61,6 +62,10 @@ export function Conversation ({ open, chat, chatId, history, placeholder, preven
61
62
const disabled = ! ! postState . params ;
62
63
const actionDisabled = disabled || ! input . trim ( ) ;
63
64
65
+ useImperativeHandle ( newChatRef , ( ) => {
66
+ return controller . post . bind ( controller ) ;
67
+ } , [ controller ] ) ;
68
+
64
69
return (
65
70
< ChatControllerProvider controller = { controller } >
66
71
{ ! postState . params && ! groups . length && placeholder ?.( controller , postState ) }
0 commit comments