@fe-free/ai 4.0.0 → 4.0.2
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/sender/actions.tsx +33 -16
- package/src/sender/index.tsx +20 -9
- package/src/sender/sender.stories.tsx +4 -1
- package/src/sender/types.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @fe-free/ai
|
|
2
2
|
|
|
3
|
+
## 4.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix: ai
|
|
8
|
+
- @fe-free/core@4.0.2
|
|
9
|
+
- @fe-free/icons@4.0.2
|
|
10
|
+
- @fe-free/tool@4.0.2
|
|
11
|
+
|
|
12
|
+
## 4.0.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- fix: ai
|
|
17
|
+
- @fe-free/core@4.0.1
|
|
18
|
+
- @fe-free/icons@4.0.1
|
|
19
|
+
- @fe-free/tool@4.0.1
|
|
20
|
+
|
|
3
21
|
## 4.0.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/ai",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
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.
|
|
15
|
+
"@fe-free/core": "4.0.2"
|
|
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.
|
|
22
|
-
"@fe-free/tool": "4.0.
|
|
21
|
+
"@fe-free/icons": "4.0.2",
|
|
22
|
+
"@fe-free/tool": "4.0.2"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/src/sender/actions.tsx
CHANGED
|
@@ -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
|
|
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';
|
|
@@ -9,18 +10,24 @@ import type { SenderProps } from './types';
|
|
|
9
10
|
|
|
10
11
|
function Actions(
|
|
11
12
|
props: SenderProps & {
|
|
13
|
+
refText: RefObject<HTMLTextAreaElement>;
|
|
12
14
|
refUpload: RefObject<HTMLDivElement>;
|
|
13
15
|
isUploading: boolean;
|
|
16
|
+
fileList: UploadFile[];
|
|
17
|
+
setFileList: (fileList: UploadFile[]) => void;
|
|
14
18
|
fileUrls: string[];
|
|
15
19
|
setFileUrls: (fileUrls: string[]) => void;
|
|
16
20
|
},
|
|
17
21
|
) {
|
|
18
22
|
const {
|
|
23
|
+
refText,
|
|
19
24
|
loading,
|
|
20
25
|
onSubmit,
|
|
21
26
|
value,
|
|
27
|
+
onChange,
|
|
22
28
|
refUpload,
|
|
23
29
|
isUploading,
|
|
30
|
+
setFileList,
|
|
24
31
|
fileUrls,
|
|
25
32
|
setFileUrls,
|
|
26
33
|
allowUpload,
|
|
@@ -29,6 +36,30 @@ function Actions(
|
|
|
29
36
|
|
|
30
37
|
const isLoading = loading || isUploading;
|
|
31
38
|
|
|
39
|
+
const handleSubmit = useCallback(async () => {
|
|
40
|
+
if (isLoading) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const newValue = {
|
|
45
|
+
...value,
|
|
46
|
+
text: value?.text?.trim(),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 有内容才提交
|
|
50
|
+
if (newValue.text || (newValue.files && newValue.files.length > 0)) {
|
|
51
|
+
await Promise.resolve(onSubmit?.(newValue));
|
|
52
|
+
|
|
53
|
+
// reset
|
|
54
|
+
setFileList([]);
|
|
55
|
+
setFileUrls([]);
|
|
56
|
+
onChange?.({});
|
|
57
|
+
|
|
58
|
+
// focus
|
|
59
|
+
refText.current?.focus();
|
|
60
|
+
}
|
|
61
|
+
}, [isLoading, value, onSubmit, setFileList, setFileUrls, onChange, refText]);
|
|
62
|
+
|
|
32
63
|
return (
|
|
33
64
|
<div className="flex items-center gap-2">
|
|
34
65
|
<div className="flex flex-1 gap-1">
|
|
@@ -50,21 +81,7 @@ function Actions(
|
|
|
50
81
|
icon={<Icons component={SendIcon} className="!text-lg" />}
|
|
51
82
|
loading={isLoading}
|
|
52
83
|
// 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
|
-
}}
|
|
84
|
+
onClick={handleSubmit}
|
|
68
85
|
/>
|
|
69
86
|
</div>
|
|
70
87
|
</div>
|
package/src/sender/index.tsx
CHANGED
|
@@ -2,17 +2,19 @@ import { useDrop } from 'ahooks';
|
|
|
2
2
|
import { Input } from 'antd';
|
|
3
3
|
import type { UploadFile } from 'antd/lib';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
|
+
import type { RefObject } from 'react';
|
|
5
6
|
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
6
7
|
import { Actions } from './actions';
|
|
7
8
|
import { FileUpload, Files } from './files';
|
|
8
9
|
import './style.scss';
|
|
9
10
|
import type { SenderProps, SenderRef } from './types';
|
|
10
11
|
|
|
11
|
-
function Text(props: SenderProps) {
|
|
12
|
-
const { value, onChange, placeholder } = props;
|
|
12
|
+
function Text(props: SenderProps & { refText: RefObject<HTMLTextAreaElement> }) {
|
|
13
|
+
const { value, onChange, placeholder, refText } = props;
|
|
13
14
|
|
|
14
15
|
return (
|
|
15
16
|
<Input.TextArea
|
|
17
|
+
ref={refText}
|
|
16
18
|
value={value?.text}
|
|
17
19
|
onChange={(e) => {
|
|
18
20
|
onChange?.({ ...value, text: e.target.value });
|
|
@@ -37,7 +39,10 @@ function Sender(originProps: SenderProps) {
|
|
|
37
39
|
};
|
|
38
40
|
}, [originProps]);
|
|
39
41
|
|
|
40
|
-
const
|
|
42
|
+
const refText = useRef<HTMLTextAreaElement>(null);
|
|
43
|
+
|
|
44
|
+
const { value, onChange, allowUpload } = props;
|
|
45
|
+
const { filesMaxCount } = allowUpload || {};
|
|
41
46
|
|
|
42
47
|
const refContainer = useRef<HTMLDivElement>(null);
|
|
43
48
|
const refUpload = useRef<HTMLDivElement>(null);
|
|
@@ -75,7 +80,7 @@ function Sender(originProps: SenderProps) {
|
|
|
75
80
|
originSetFileUrls(fileUrls);
|
|
76
81
|
handleFilesChange({ fileUrls, fileList });
|
|
77
82
|
},
|
|
78
|
-
[fileList],
|
|
83
|
+
[fileList, handleFilesChange],
|
|
79
84
|
);
|
|
80
85
|
|
|
81
86
|
const setFileList = useCallback(
|
|
@@ -83,7 +88,7 @@ function Sender(originProps: SenderProps) {
|
|
|
83
88
|
originSetFileList(fileList);
|
|
84
89
|
handleFilesChange({ fileUrls, fileList });
|
|
85
90
|
},
|
|
86
|
-
[fileUrls],
|
|
91
|
+
[fileUrls, handleFilesChange],
|
|
87
92
|
);
|
|
88
93
|
|
|
89
94
|
const isUploading = useMemo(() => {
|
|
@@ -95,9 +100,12 @@ function Sender(originProps: SenderProps) {
|
|
|
95
100
|
<div className="fea-sender-wrap">
|
|
96
101
|
<div
|
|
97
102
|
ref={refContainer}
|
|
98
|
-
className={classNames(
|
|
99
|
-
'fea-sender-
|
|
100
|
-
|
|
103
|
+
className={classNames(
|
|
104
|
+
'fea-sender relative flex flex-col rounded-lg border border-01 bg-white p-2',
|
|
105
|
+
{
|
|
106
|
+
'fea-sender-drag-hover': dragHover,
|
|
107
|
+
},
|
|
108
|
+
)}
|
|
101
109
|
>
|
|
102
110
|
<Files
|
|
103
111
|
{...props}
|
|
@@ -107,12 +115,15 @@ function Sender(originProps: SenderProps) {
|
|
|
107
115
|
setFileUrls={setFileUrls}
|
|
108
116
|
/>
|
|
109
117
|
<div className="flex">
|
|
110
|
-
<Text {...props} />
|
|
118
|
+
<Text {...props} refText={refText} />
|
|
111
119
|
</div>
|
|
112
120
|
<Actions
|
|
113
121
|
{...props}
|
|
122
|
+
refText={refText}
|
|
114
123
|
refUpload={refUpload}
|
|
115
124
|
isUploading={isUploading}
|
|
125
|
+
fileList={fileList}
|
|
126
|
+
setFileList={setFileList}
|
|
116
127
|
fileUrls={fileUrls}
|
|
117
128
|
setFileUrls={setFileUrls}
|
|
118
129
|
/>
|
|
@@ -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
|
);
|
package/src/sender/types.ts
CHANGED