@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 +18 -0
- package/package.json +4 -4
- package/src/ai.stories.tsx +1 -1
- package/src/messages/messages.tsx +26 -16
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.
|
|
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.
|
|
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.
|
|
33
|
-
"@fe-free/tool": "4.1.
|
|
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",
|
package/src/ai.stories.tsx
CHANGED
|
@@ -28,26 +28,34 @@ function useScrollWidth() {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function useScrollToBottom({ ref }) {
|
|
31
|
-
const [
|
|
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
|
-
|
|
41
|
-
|
|
42
|
+
scrollHeight > clientHeight && scrollTop + clientHeight + 200 <= scrollHeight;
|
|
43
|
+
setShowScrollBottom(isNearBottom);
|
|
42
44
|
};
|
|
43
|
-
|
|
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
|
|
54
|
+
ref.current?.removeEventListener('scroll', handleScroll);
|
|
47
55
|
};
|
|
48
|
-
}, []);
|
|
56
|
+
}, [ref]);
|
|
49
57
|
|
|
50
|
-
return
|
|
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
|
-
|
|
87
|
-
|
|
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
|
|
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
|
|
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(${
|
|
175
|
+
transform: `translateY(${showScrollBottom ? 0 : 30}px) scale(${showScrollBottom ? 1 : 0.1})`,
|
|
166
176
|
}}
|
|
167
177
|
/>
|
|
168
178
|
</div>
|