@fe-free/ai 4.0.0 → 4.0.1

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,14 @@
1
1
  # @fe-free/ai
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: ai
8
+ - @fe-free/core@4.0.1
9
+ - @fe-free/icons@4.0.1
10
+ - @fe-free/tool@4.0.1
11
+
3
12
  ## 4.0.0
4
13
 
5
14
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/ai",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -12,14 +12,14 @@
12
12
  "dependencies": {
13
13
  "ahooks": "^3.7.8",
14
14
  "classnames": "^2.5.1",
15
- "@fe-free/core": "4.0.0"
15
+ "@fe-free/core": "4.0.1"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "antd": "^5.27.1",
19
19
  "dayjs": "~1.11.10",
20
20
  "react": "^19.2.0",
21
- "@fe-free/icons": "4.0.0",
22
- "@fe-free/tool": "4.0.0"
21
+ "@fe-free/icons": "4.0.1",
22
+ "@fe-free/tool": "4.0.1"
23
23
  },
24
24
  "scripts": {
25
25
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,6 +1,7 @@
1
1
  import Icons from '@fe-free/icons';
2
+ import type { UploadFile } from 'antd';
2
3
  import { Button, Divider } from 'antd';
3
- import type { RefObject } from 'react';
4
+ import { useCallback, type RefObject } from 'react';
4
5
  import SendIcon from '../svgs/send.svg?react';
5
6
  import { FileAction } from './files';
6
7
  import { RecordAction } from './record';
@@ -11,6 +12,8 @@ function Actions(
11
12
  props: SenderProps & {
12
13
  refUpload: RefObject<HTMLDivElement>;
13
14
  isUploading: boolean;
15
+ fileList: UploadFile[];
16
+ setFileList: (fileList: UploadFile[]) => void;
14
17
  fileUrls: string[];
15
18
  setFileUrls: (fileUrls: string[]) => void;
16
19
  },
@@ -19,8 +22,11 @@ function Actions(
19
22
  loading,
20
23
  onSubmit,
21
24
  value,
25
+ onChange,
22
26
  refUpload,
23
27
  isUploading,
28
+ fileList,
29
+ setFileList,
24
30
  fileUrls,
25
31
  setFileUrls,
26
32
  allowUpload,
@@ -29,6 +35,26 @@ function Actions(
29
35
 
30
36
  const isLoading = loading || isUploading;
31
37
 
38
+ const handleSubmit = useCallback(async () => {
39
+ if (isLoading) {
40
+ return;
41
+ }
42
+
43
+ const newValue = {
44
+ ...value,
45
+ text: value?.text?.trim(),
46
+ };
47
+
48
+ // 有内容才提交
49
+ if (newValue.text || (newValue.files && newValue.files.length > 0)) {
50
+ await Promise.resolve(onSubmit?.(newValue));
51
+ setFileList([]);
52
+ setFileUrls([]);
53
+
54
+ onChange?.({});
55
+ }
56
+ }, [isLoading, value, onSubmit, setFileList, setFileUrls, onChange]);
57
+
32
58
  return (
33
59
  <div className="flex items-center gap-2">
34
60
  <div className="flex flex-1 gap-1">
@@ -50,21 +76,7 @@ function Actions(
50
76
  icon={<Icons component={SendIcon} className="!text-lg" />}
51
77
  loading={isLoading}
52
78
  // disabled={loading}
53
- onClick={() => {
54
- if (isLoading) {
55
- return;
56
- }
57
-
58
- const newValue = {
59
- ...value,
60
- text: value?.text?.trim(),
61
- };
62
-
63
- // 有内容才提交
64
- if (newValue.text || (newValue.files && newValue.files.length > 0)) {
65
- onSubmit?.(newValue);
66
- }
67
- }}
79
+ onClick={handleSubmit}
68
80
  />
69
81
  </div>
70
82
  </div>
@@ -37,7 +37,8 @@ function Sender(originProps: SenderProps) {
37
37
  };
38
38
  }, [originProps]);
39
39
 
40
- const { value, onChange, filesMaxCount } = props;
40
+ const { value, onChange, allowUpload } = props;
41
+ const { filesMaxCount } = allowUpload || {};
41
42
 
42
43
  const refContainer = useRef<HTMLDivElement>(null);
43
44
  const refUpload = useRef<HTMLDivElement>(null);
@@ -75,7 +76,7 @@ function Sender(originProps: SenderProps) {
75
76
  originSetFileUrls(fileUrls);
76
77
  handleFilesChange({ fileUrls, fileList });
77
78
  },
78
- [fileList],
79
+ [fileList, handleFilesChange],
79
80
  );
80
81
 
81
82
  const setFileList = useCallback(
@@ -83,7 +84,7 @@ function Sender(originProps: SenderProps) {
83
84
  originSetFileList(fileList);
84
85
  handleFilesChange({ fileUrls, fileList });
85
86
  },
86
- [fileUrls],
87
+ [fileUrls, handleFilesChange],
87
88
  );
88
89
 
89
90
  const isUploading = useMemo(() => {
@@ -113,6 +114,8 @@ function Sender(originProps: SenderProps) {
113
114
  {...props}
114
115
  refUpload={refUpload}
115
116
  isUploading={isUploading}
117
+ fileList={fileList}
118
+ setFileList={setFileList}
116
119
  fileUrls={fileUrls}
117
120
  setFileUrls={setFileUrls}
118
121
  />
@@ -11,7 +11,7 @@ const meta: Meta<typeof Sender> = {
11
11
 
12
12
  type Story = StoryObj<typeof Sender>;
13
13
 
14
- function Component(props: Omit<SenderProps, 'value' | 'onChange'>) {
14
+ function Component(props: Omit<SenderProps, 'value' | 'onChange' | 'onSubmit'>) {
15
15
  const [v, setV] = useState<SenderValue | undefined>(undefined);
16
16
 
17
17
  return (
@@ -21,6 +21,9 @@ function Component(props: Omit<SenderProps, 'value' | 'onChange'>) {
21
21
  console.log('newValue', v);
22
22
  setV(v);
23
23
  }}
24
+ onSubmit={(value) => {
25
+ console.log('onSubmit', value);
26
+ }}
24
27
  {...props}
25
28
  />
26
29
  );
@@ -12,7 +12,7 @@ interface SenderProps {
12
12
  onChange: (value?: SenderValue) => void;
13
13
 
14
14
  loading?: boolean;
15
- onSubmit: (value?: SenderValue) => void;
15
+ onSubmit: (value?: SenderValue) => void | Promise<void>;
16
16
 
17
17
  placeholder?: string;
18
18