@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 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.21",
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.21"
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.21",
33
- "@fe-free/tool": "4.1.21"
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",
@@ -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
@@ -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={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 [isNearBottom, setIsNearBottom] = useState(false);
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
- ref.current?.scrollTop + ref.current?.clientHeight >= ref.current?.scrollHeight - 200;
37
- setIsNearBottom(isNearBottom);
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 isNearBottom;
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 isNearBottom = useScrollToBottom({ ref });
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(${isNearBottom ? 30 : 0}px) scale(${isNearBottom ? 0.1 : 1})`,
175
+ transform: `translateY(${showScrollBottom ? 0 : 30}px) scale(${showScrollBottom ? 1 : 0.1})`,
167
176
  }}
168
177
  />
169
178
  </div>