listpage-next 0.0.108 → 0.0.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,12 @@
1
+ import { RefObject } from "react";
1
2
  import { BaseMessageInfo, ChatRender, ChatRequest } from "../../context";
3
+ import { ChatInstance } from "../../context/useChatContext";
2
4
  export interface SimplifyChatPageProps<SessionData = any, MessageInfo extends BaseMessageInfo = any> {
3
5
  request: ChatRequest<SessionData, MessageInfo>;
4
6
  render: ChatRender<MessageInfo>;
5
7
  style?: React.CSSProperties;
6
8
  initialMessages?: MessageInfo[];
9
+ chatRef?: RefObject<ChatInstance>;
7
10
  }
11
+ export declare const SimplifyChatPageComponent: <T = any>(props: SimplifyChatPageProps<T>) => import("react/jsx-runtime").JSX.Element;
8
12
  export declare const SimplifyChatPage: <T = any>(props: SimplifyChatPageProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,15 +1,27 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import { useImperativeHandle } from "react";
2
3
  import { ChatClientProvider, MessageProvider } from "../../context/index.js";
4
+ import { useChatContext } from "../../context/useChatContext.js";
3
5
  import { SimplifyClientContentBody } from "../ChatContent/ClientContentBody.js";
6
+ const SimplifyChatPageComponent = (props)=>{
7
+ const { chatRef } = props;
8
+ const context = useChatContext();
9
+ useImperativeHandle(chatRef, ()=>context, [
10
+ context
11
+ ]);
12
+ return /*#__PURE__*/ jsx(SimplifyClientContentBody, {
13
+ style: props.style
14
+ });
15
+ };
4
16
  const SimplifyChatPage = (props)=>/*#__PURE__*/ jsx(ChatClientProvider, {
5
17
  request: props.request,
6
18
  render: props.render,
7
19
  children: /*#__PURE__*/ jsx(MessageProvider, {
8
20
  request: props.request.chat,
9
21
  initialMessages: props.initialMessages ?? [],
10
- children: /*#__PURE__*/ jsx(SimplifyClientContentBody, {
11
- style: props.style
22
+ children: /*#__PURE__*/ jsx(SimplifyChatPageComponent, {
23
+ ...props
12
24
  })
13
25
  })
14
26
  });
15
- export { SimplifyChatPage };
27
+ export { SimplifyChatPage, SimplifyChatPageComponent };
@@ -73,6 +73,7 @@ const MessageProvider = ({ initialMessages, children, request })=>{
73
73
  setMessages([
74
74
  ...messagesRef.current
75
75
  ]);
76
+ const currentMsgs = messagesRef.current.map((msg)=>msg.info);
76
77
  request(info, {
77
78
  onCreated: (info)=>{
78
79
  completeUserMessage(info);
@@ -104,7 +105,7 @@ const MessageProvider = ({ initialMessages, children, request })=>{
104
105
  setIsRequesting(false);
105
106
  onUpdate?.(info);
106
107
  }
107
- });
108
+ }, currentMsgs);
108
109
  }, [
109
110
  completeAssistantMessage,
110
111
  completeUserMessage,
@@ -16,4 +16,4 @@ export type SendMessageRequest<MessageInfo extends BaseMessageInfo = any> = (inf
16
16
  onUpdate: (id: string, info: MessageInfo) => void;
17
17
  onSuccess: (id: string, info: MessageInfo) => void;
18
18
  onError: (id: string, info: MessageInfo) => void;
19
- }) => Promise<void>;
19
+ }, messages: MessageInfo[]) => Promise<void>;
@@ -5,3 +5,4 @@ export declare function useChatContext(): {
5
5
  updateConversation: ((key: string, item: any) => void) | undefined;
6
6
  scrollToBottom: () => void;
7
7
  };
8
+ export type ChatInstance = ReturnType<typeof useChatContext>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next",
3
- "version": "0.0.108",
3
+ "version": "0.0.109",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",