@fe-free/ai 4.1.21 → 4.1.23
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/message_think.tsx +21 -2
- package/src/messages/messages.tsx +15 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @fe-free/ai
|
|
2
2
|
|
|
3
|
+
## 4.1.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: ai
|
|
8
|
+
- @fe-free/core@4.1.23
|
|
9
|
+
- @fe-free/icons@4.1.23
|
|
10
|
+
- @fe-free/tool@4.1.23
|
|
11
|
+
|
|
12
|
+
## 4.1.22
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- feat: ai
|
|
17
|
+
- @fe-free/core@4.1.22
|
|
18
|
+
- @fe-free/icons@4.1.22
|
|
19
|
+
- @fe-free/tool@4.1.22
|
|
20
|
+
|
|
3
21
|
## 4.1.21
|
|
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.23",
|
|
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.23"
|
|
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.23",
|
|
33
|
+
"@fe-free/tool": "4.1.23"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"test": "echo \"Error: no test specified\" && exit 1",
|
package/src/ai.stories.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Think } from '@ant-design/x';
|
|
2
2
|
import Icons from '@fe-free/icons';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
4
5
|
import ThinkIcon from '../svgs/think.svg?react';
|
|
5
6
|
|
|
6
7
|
interface MessageThinkProps {
|
|
@@ -18,10 +19,28 @@ function MessageThink({
|
|
|
18
19
|
icon,
|
|
19
20
|
loading,
|
|
20
21
|
children,
|
|
21
|
-
expanded,
|
|
22
|
+
expanded: propsExpanded,
|
|
22
23
|
onClick,
|
|
23
24
|
className,
|
|
24
25
|
}: MessageThinkProps) {
|
|
26
|
+
const [expanded, setExpanded] = useState(propsExpanded || false);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
setExpanded(propsExpanded || false);
|
|
30
|
+
}, [propsExpanded]);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
// 如果 propsExpanded 未定义,则根据 loading 状态设置 expanded
|
|
34
|
+
if (propsExpanded === undefined && loading !== undefined) {
|
|
35
|
+
setExpanded(loading ? true : false);
|
|
36
|
+
}
|
|
37
|
+
}, [propsExpanded, loading]);
|
|
38
|
+
|
|
39
|
+
const handleClick = useCallback(() => {
|
|
40
|
+
setExpanded(!expanded);
|
|
41
|
+
onClick?.();
|
|
42
|
+
}, [expanded, onClick]);
|
|
43
|
+
|
|
25
44
|
return (
|
|
26
45
|
<Think
|
|
27
46
|
title={title}
|
|
@@ -29,7 +48,7 @@ function MessageThink({
|
|
|
29
48
|
loading={loading}
|
|
30
49
|
blink={loading}
|
|
31
50
|
expanded={expanded}
|
|
32
|
-
onClick={
|
|
51
|
+
onClick={handleClick}
|
|
33
52
|
className={classNames('fea-message-think', className)}
|
|
34
53
|
>
|
|
35
54
|
{children}
|
|
@@ -28,25 +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
34
|
const handleScroll = () => {
|
|
35
|
+
if (!ref.current) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { scrollTop, clientHeight, scrollHeight } = ref.current;
|
|
40
|
+
|
|
35
41
|
const isNearBottom =
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
scrollHeight > clientHeight && scrollTop + clientHeight + 200 <= scrollHeight;
|
|
43
|
+
setShowScrollBottom(isNearBottom);
|
|
38
44
|
};
|
|
39
45
|
|
|
40
46
|
if (ref.current) {
|
|
41
47
|
ref.current.addEventListener('scroll', handleScroll);
|
|
42
48
|
}
|
|
43
49
|
|
|
50
|
+
// first
|
|
51
|
+
handleScroll();
|
|
52
|
+
|
|
44
53
|
return () => {
|
|
45
54
|
ref.current?.removeEventListener('scroll', handleScroll);
|
|
46
55
|
};
|
|
47
56
|
}, [ref]);
|
|
48
57
|
|
|
49
|
-
return
|
|
58
|
+
return showScrollBottom;
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
function Messages<AIData>(props: MessagesProps<AIData>) {
|
|
@@ -113,7 +122,7 @@ function Messages<AIData>(props: MessagesProps<AIData>) {
|
|
|
113
122
|
|
|
114
123
|
const scrollWidth = useScrollWidth();
|
|
115
124
|
|
|
116
|
-
const
|
|
125
|
+
const showScrollBottom = useScrollToBottom({ ref });
|
|
117
126
|
|
|
118
127
|
return (
|
|
119
128
|
<PageLayout>
|
|
@@ -163,7 +172,7 @@ function Messages<AIData>(props: MessagesProps<AIData>) {
|
|
|
163
172
|
}}
|
|
164
173
|
className="bg-white shadow-lg"
|
|
165
174
|
style={{
|
|
166
|
-
transform: `translateY(${
|
|
175
|
+
transform: `translateY(${showScrollBottom ? 0 : 30}px) scale(${showScrollBottom ? 1 : 0.1})`,
|
|
167
176
|
}}
|
|
168
177
|
/>
|
|
169
178
|
</div>
|