@fe-free/ai 4.1.20 → 4.1.22

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @fe-free/ai
2
2
 
3
+ ## 4.1.22
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: ai
8
+ - @fe-free/core@4.1.22
9
+ - @fe-free/icons@4.1.22
10
+ - @fe-free/tool@4.1.22
11
+
12
+ ## 4.1.21
13
+
14
+ ### Patch Changes
15
+
16
+ - feat: ai
17
+ - @fe-free/core@4.1.21
18
+ - @fe-free/icons@4.1.21
19
+ - @fe-free/tool@4.1.21
20
+
3
21
  ## 4.1.20
4
22
 
5
23
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/ai",
3
- "version": "4.1.20",
3
+ "version": "4.1.22",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -19,7 +19,7 @@
19
19
  "lodash-es": "^4.17.21",
20
20
  "uuid": "^13.0.0",
21
21
  "zustand": "^4.5.7",
22
- "@fe-free/core": "4.1.20"
22
+ "@fe-free/core": "4.1.22"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "antd": "^5.27.1",
@@ -29,8 +29,8 @@
29
29
  "i18next-icu": "^2.4.1",
30
30
  "react": "^19.2.0",
31
31
  "react-i18next": "^16.4.0",
32
- "@fe-free/icons": "4.1.20",
33
- "@fe-free/tool": "4.1.20"
32
+ "@fe-free/icons": "4.1.22",
33
+ "@fe-free/tool": "4.1.22"
34
34
  },
35
35
  "scripts": {
36
36
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -121,7 +121,7 @@ function Component() {
121
121
  Add New Session
122
122
  </Button>
123
123
  </div>
124
- <div className="h-[500px] w-[500px] border border-red-500">
124
+ <div className="h-[800px] w-[500px] border border-red-500">
125
125
  <Chat
126
126
  end={
127
127
  <div
@@ -28,26 +28,34 @@ function useScrollWidth() {
28
28
  }
29
29
 
30
30
  function useScrollToBottom({ ref }) {
31
- const [isNearBottom, setIsNearBottom] = useState(false);
31
+ const [showScrollBottom, setShowScrollBottom] = useState(false);
32
32
 
33
33
  useEffect(() => {
34
- if (!ref.current) {
35
- return;
36
- }
37
-
38
34
  const handleScroll = () => {
35
+ if (!ref.current) {
36
+ return;
37
+ }
38
+
39
+ const { scrollTop, clientHeight, scrollHeight } = ref.current;
40
+
39
41
  const isNearBottom =
40
- ref.current?.scrollTop + ref.current?.clientHeight >= ref.current?.scrollHeight - 200;
41
- setIsNearBottom(isNearBottom);
42
+ scrollHeight > clientHeight && scrollTop + clientHeight + 200 <= scrollHeight;
43
+ setShowScrollBottom(isNearBottom);
42
44
  };
43
- ref.current.addEventListener('scroll', handleScroll);
45
+
46
+ if (ref.current) {
47
+ ref.current.addEventListener('scroll', handleScroll);
48
+ }
49
+
50
+ // first
51
+ handleScroll();
44
52
 
45
53
  return () => {
46
- ref.current.removeEventListener('scroll', handleScroll);
54
+ ref.current?.removeEventListener('scroll', handleScroll);
47
55
  };
48
- }, []);
56
+ }, [ref]);
49
57
 
50
- return isNearBottom;
58
+ return showScrollBottom;
51
59
  }
52
60
 
53
61
  function Messages<AIData>(props: MessagesProps<AIData>) {
@@ -83,8 +91,10 @@ function Messages<AIData>(props: MessagesProps<AIData>) {
83
91
 
84
92
  // 首次和更新时滚动到最新消息
85
93
  useEffect(() => {
86
- scrollToBottom();
87
- }, [scrollToBottom]);
94
+ if (lastMessage?.uuid) {
95
+ scrollToBottom();
96
+ }
97
+ }, [scrollToBottom, lastMessage?.uuid]);
88
98
 
89
99
  // 数据更新是,如果 dom 处于可视区域,则滚动
90
100
  useEffect(() => {
@@ -112,7 +122,7 @@ function Messages<AIData>(props: MessagesProps<AIData>) {
112
122
 
113
123
  const scrollWidth = useScrollWidth();
114
124
 
115
- const isNearBottom = useScrollToBottom({ ref });
125
+ const showScrollBottom = useScrollToBottom({ ref });
116
126
 
117
127
  return (
118
128
  <PageLayout>
@@ -153,7 +163,7 @@ function Messages<AIData>(props: MessagesProps<AIData>) {
153
163
  </div>
154
164
  );
155
165
  })}
156
- <div className="sticky bottom-2 left-0 right-0 flex justify-center">
166
+ <div className="sticky bottom-2 mx-auto flex justify-center">
157
167
  <Button
158
168
  shape="circle"
159
169
  icon={<AngleLeftOutlined rotate={-90} />}
@@ -162,7 +172,7 @@ function Messages<AIData>(props: MessagesProps<AIData>) {
162
172
  }}
163
173
  className="bg-white shadow-lg"
164
174
  style={{
165
- transform: `translateY(${isNearBottom ? 30 : 0}px) scale(${isNearBottom ? 0.1 : 1})`,
175
+ transform: `translateY(${showScrollBottom ? 0 : 30}px) scale(${showScrollBottom ? 1 : 0.1})`,
166
176
  }}
167
177
  />
168
178
  </div>