listpage-next 0.0.78 → 0.0.79

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,7 +1,7 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useEffect, useState } from "react";
2
+ import { useState } from "react";
3
3
  import { EditOutlined, MenuUnfoldOutlined } from "@ant-design/icons";
4
- import { Button, Divider, Input, Modal } from "antd";
4
+ import { Button, Divider } from "antd";
5
5
  import { styled } from "styled-components";
6
6
  import { useChatClientContext } from "../../context/index.js";
7
7
  const Header = (props)=>{
@@ -19,12 +19,15 @@ const Header = (props)=>{
19
19
  };
20
20
  const HeaderLeft = (props)=>{
21
21
  const { onClickNewConversation, onTitleChange } = props;
22
- const { collapsed, setCollapsed } = useChatClientContext();
23
- const [open, setOpen] = useState(false);
22
+ const { collapsed, setCollapsed, showUpdateTitleModal } = useChatClientContext();
24
23
  const [title, setTitle] = useState(props.defaultTitle);
25
24
  const onCollapsed = ()=>{
26
25
  setCollapsed(!collapsed);
27
26
  };
27
+ const onSubmitTitleChange = async (newTitle)=>{
28
+ await onTitleChange?.(newTitle);
29
+ setTitle(newTitle);
30
+ };
28
31
  const showActions = !!collapsed;
29
32
  const showTitle = !!title;
30
33
  return /*#__PURE__*/ jsxs(Left, {
@@ -58,7 +61,7 @@ const HeaderLeft = (props)=>{
58
61
  children: [
59
62
  /*#__PURE__*/ jsx(NameText, {
60
63
  children: /*#__PURE__*/ jsx(Button, {
61
- onClick: ()=>setOpen(true),
64
+ onClick: ()=>showUpdateTitleModal(title, onSubmitTitleChange),
62
65
  size: "small",
63
66
  type: "text",
64
67
  iconPosition: "end",
@@ -70,43 +73,10 @@ const HeaderLeft = (props)=>{
70
73
  children: "内容由 AI 生成"
71
74
  })
72
75
  ]
73
- }),
74
- /*#__PURE__*/ jsx(UpdateTitleModal, {
75
- defaultName: title,
76
- open: open,
77
- onClose: ()=>setOpen(false),
78
- onSubmit: async (value)=>{
79
- await onTitleChange?.(value);
80
- setTitle(value);
81
- }
82
76
  })
83
77
  ]
84
78
  });
85
79
  };
86
- const UpdateTitleModal = (props)=>{
87
- const { defaultName, open, onSubmit, onClose } = props;
88
- const [name, setName] = useState(defaultName);
89
- useEffect(()=>{
90
- if (open) setName(defaultName);
91
- }, [
92
- open
93
- ]);
94
- return /*#__PURE__*/ jsx(Modal, {
95
- title: "编辑对话名称",
96
- open: open,
97
- okText: "确定",
98
- cancelText: "取消",
99
- onCancel: ()=>onClose?.(),
100
- onOk: async ()=>{
101
- await onSubmit?.(name);
102
- onClose?.();
103
- },
104
- children: /*#__PURE__*/ jsx(Input, {
105
- value: name,
106
- onChange: (e)=>setName(e.target.value)
107
- })
108
- });
109
- };
110
80
  const ActionContainer = styled.div`
111
81
  display: flex;
112
82
  align-items: center;
@@ -4,7 +4,7 @@ export interface ClientContentProps {
4
4
  className?: string;
5
5
  style?: React.CSSProperties;
6
6
  children?: React.ReactNode;
7
- headerProps: HeaderProps;
7
+ headerProps?: HeaderProps;
8
8
  footerProps?: FooterProps;
9
9
  loading?: boolean;
10
10
  }
@@ -1,10 +1,10 @@
1
- import { InfiniteListProps, RenderActions } from "../../../../components/InfiniteList";
1
+ import { InfiniteListProps } from "../../../../components/InfiniteList";
2
2
  export interface HistoryConversationProps<T = any> {
3
3
  rowKey?: string;
4
4
  request: InfiniteListProps<T>['request'];
5
5
  activeKey?: string;
6
- onDelete?: (key: string, item: T, actions: RenderActions<T>) => Promise<void>;
7
- onRename?: (key: string, item: T, actions: RenderActions<T>) => Promise<void>;
6
+ onDelete?: (key: string, item: T) => Promise<void>;
7
+ onRename?: (key: string, item: T) => Promise<void>;
8
8
  onSelect?: (key: string, item: T) => void;
9
9
  }
10
10
  export declare const HistoryConversation: <T extends ItemData = any>(props: HistoryConversationProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -5,11 +5,11 @@ import { useHover } from "ahooks";
5
5
  import { ClockCircleOutlined, MessageOutlined, MoreOutlined } from "@ant-design/icons";
6
6
  import { InfiniteList } from "../../../../components/InfiniteList/index.js";
7
7
  import { HeaderContainer, HeaderTitle, HistoryConversationContainer, ListContainer, ListItemContainer, ListText } from "./styles.js";
8
+ import { useChatClientContext } from "../../context/index.js";
8
9
  const HistoryConversation = (props)=>{
9
- const { request, activeKey, rowKey = "id", onDelete, onRename, onSelect } = props;
10
- const ref = useRef(null);
10
+ const { rowKey = "id", request, activeKey, onDelete, onRename, onSelect } = props;
11
+ const { showUpdateTitleModal } = useChatClientContext();
11
12
  return /*#__PURE__*/ jsxs(HistoryConversationContainer, {
12
- ref: ref,
13
13
  children: [
14
14
  /*#__PURE__*/ jsx(Header, {}),
15
15
  /*#__PURE__*/ jsx(ListContainer, {
@@ -23,13 +23,25 @@ const HistoryConversation = (props)=>{
23
23
  {
24
24
  key: 'rename',
25
25
  label: '重命名',
26
- onClick: ()=>onRename?.(key, item, actions)
26
+ onClick: ()=>{
27
+ showUpdateTitleModal(item.title, async (newTitle)=>{
28
+ const newItem = {
29
+ ...item,
30
+ title: newTitle
31
+ };
32
+ await onRename?.(key, newItem);
33
+ actions.updateItem(key, newItem);
34
+ });
35
+ }
27
36
  },
28
37
  {
29
38
  key: 'delete',
30
39
  danger: true,
31
40
  label: '删除',
32
- onClick: ()=>onDelete?.(key, item, actions)
41
+ onClick: async ()=>{
42
+ await onDelete?.(key, item);
43
+ actions.deleteItem(key);
44
+ }
33
45
  }
34
46
  ];
35
47
  return /*#__PURE__*/ jsxs(ListItemContainer, {
@@ -8,7 +8,7 @@ export interface ChatPageProps<T = any> {
8
8
  onClickConversation?: (key: string, item: T) => void;
9
9
  onClickNewConversation?: () => void;
10
10
  onClickMoreAgent?: () => void;
11
- onRenameConversation?: (key: string, item: T, actions: any) => Promise<void>;
12
- onDeleteConversation?: (key: string, item: T, actions: any) => Promise<void>;
11
+ onRenameConversation?: (key: string, item: T) => Promise<void>;
12
+ onDeleteConversation?: (key: string, item: T) => Promise<void>;
13
13
  }
14
14
  export declare const ChatPage: (props: ChatPageProps) => import("react/jsx-runtime").JSX.Element;
@@ -2,6 +2,7 @@ import { ReactNode } from "react";
2
2
  export interface ChatClientContextProps {
3
3
  collapsed: boolean;
4
4
  setCollapsed: (collapsed: boolean) => void;
5
+ showUpdateTitleModal: (title: string, onSubmit?: (title: string) => any) => void;
5
6
  }
6
7
  export interface ChatClientProviderProps {
7
8
  children: ReactNode;
@@ -1,15 +1,21 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { jsxs } from "react/jsx-runtime";
2
2
  import { createContext, useContext, useState } from "react";
3
+ import { useUpdateTitleModal } from "./useUpdateTitleModal.js";
3
4
  const ChatClientContext = /*#__PURE__*/ createContext({});
4
5
  const ChatClientProvider = (props)=>{
5
6
  const { children } = props;
7
+ const { updateTitleModalEle, showUpdateTitleModal } = useUpdateTitleModal();
6
8
  const [collapsed, setCollapsed] = useState(false);
7
- return /*#__PURE__*/ jsx(ChatClientContext.Provider, {
9
+ return /*#__PURE__*/ jsxs(ChatClientContext.Provider, {
8
10
  value: {
9
11
  collapsed,
10
- setCollapsed
12
+ setCollapsed,
13
+ showUpdateTitleModal
11
14
  },
12
- children: children
15
+ children: [
16
+ children,
17
+ updateTitleModalEle
18
+ ]
13
19
  });
14
20
  };
15
21
  function useChatClientContext() {
@@ -0,0 +1,4 @@
1
+ export declare function useUpdateTitleModal(): {
2
+ updateTitleModalEle: import("react/jsx-runtime").JSX.Element;
3
+ showUpdateTitleModal: (title: string, onSubmit?: (title: string) => any) => void;
4
+ };
@@ -0,0 +1,33 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Input, Modal } from "antd";
3
+ import { useRef, useState } from "react";
4
+ function useUpdateTitleModal() {
5
+ const [open, setOpen] = useState(false);
6
+ const [title, setTitle] = useState("");
7
+ const callbackRef = useRef((title)=>{});
8
+ const updateTitleModalEle = /*#__PURE__*/ jsx(Modal, {
9
+ title: "编辑对话名称",
10
+ open: open,
11
+ okText: "确定",
12
+ cancelText: "取消",
13
+ onCancel: ()=>setOpen(false),
14
+ onOk: async ()=>{
15
+ await callbackRef.current(title);
16
+ setOpen(false);
17
+ },
18
+ children: /*#__PURE__*/ jsx(Input, {
19
+ value: title,
20
+ onChange: (e)=>setTitle(e.target.value)
21
+ })
22
+ });
23
+ const showUpdateTitleModal = (title, onSubmit)=>{
24
+ setTitle(title);
25
+ setOpen(true);
26
+ callbackRef.current = onSubmit || (()=>{});
27
+ };
28
+ return {
29
+ updateTitleModalEle,
30
+ showUpdateTitleModal
31
+ };
32
+ }
33
+ export { useUpdateTitleModal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next",
3
- "version": "0.0.78",
3
+ "version": "0.0.79",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",