@fe-free/ai 4.0.1 → 4.0.3

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.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: ai
8
+ - @fe-free/core@4.0.3
9
+ - @fe-free/icons@4.0.3
10
+ - @fe-free/tool@4.0.3
11
+
12
+ ## 4.0.2
13
+
14
+ ### Patch Changes
15
+
16
+ - fix: ai
17
+ - @fe-free/core@4.0.2
18
+ - @fe-free/icons@4.0.2
19
+ - @fe-free/tool@4.0.2
20
+
3
21
  ## 4.0.1
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.0.1",
3
+ "version": "4.0.3",
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.1"
15
+ "@fe-free/core": "4.0.3"
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.1",
22
- "@fe-free/tool": "4.0.1"
21
+ "@fe-free/icons": "4.0.3",
22
+ "@fe-free/tool": "4.0.3"
23
23
  },
24
24
  "scripts": {
25
25
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -10,6 +10,7 @@ import type { SenderProps } from './types';
10
10
 
11
11
  function Actions(
12
12
  props: SenderProps & {
13
+ refText: RefObject<HTMLTextAreaElement>;
13
14
  refUpload: RefObject<HTMLDivElement>;
14
15
  isUploading: boolean;
15
16
  fileList: UploadFile[];
@@ -19,13 +20,13 @@ function Actions(
19
20
  },
20
21
  ) {
21
22
  const {
23
+ refText,
22
24
  loading,
23
25
  onSubmit,
24
26
  value,
25
27
  onChange,
26
28
  refUpload,
27
29
  isUploading,
28
- fileList,
29
30
  setFileList,
30
31
  fileUrls,
31
32
  setFileUrls,
@@ -36,7 +37,7 @@ function Actions(
36
37
  const isLoading = loading || isUploading;
37
38
 
38
39
  const handleSubmit = useCallback(async () => {
39
- if (isLoading) {
40
+ if (isLoading || allowSpeech?.recording) {
40
41
  return;
41
42
  }
42
43
 
@@ -48,12 +49,25 @@ function Actions(
48
49
  // 有内容才提交
49
50
  if (newValue.text || (newValue.files && newValue.files.length > 0)) {
50
51
  await Promise.resolve(onSubmit?.(newValue));
52
+
53
+ // reset
51
54
  setFileList([]);
52
55
  setFileUrls([]);
53
-
54
56
  onChange?.({});
57
+
58
+ // focus
59
+ refText.current?.focus();
55
60
  }
56
- }, [isLoading, value, onSubmit, setFileList, setFileUrls, onChange]);
61
+ }, [
62
+ isLoading,
63
+ allowSpeech?.recording,
64
+ value,
65
+ onSubmit,
66
+ setFileList,
67
+ setFileUrls,
68
+ onChange,
69
+ refText,
70
+ ]);
57
71
 
58
72
  return (
59
73
  <div className="flex items-center gap-2">
@@ -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,6 +39,8 @@ function Sender(originProps: SenderProps) {
37
39
  };
38
40
  }, [originProps]);
39
41
 
42
+ const refText = useRef<HTMLTextAreaElement>(null);
43
+
40
44
  const { value, onChange, allowUpload } = props;
41
45
  const { filesMaxCount } = allowUpload || {};
42
46
 
@@ -96,9 +100,12 @@ function Sender(originProps: SenderProps) {
96
100
  <div className="fea-sender-wrap">
97
101
  <div
98
102
  ref={refContainer}
99
- className={classNames('fea-sender relative flex flex-col rounded-lg border border-01 p-2', {
100
- 'fea-sender-drag-hover': dragHover,
101
- })}
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
+ )}
102
109
  >
103
110
  <Files
104
111
  {...props}
@@ -108,10 +115,11 @@ function Sender(originProps: SenderProps) {
108
115
  setFileUrls={setFileUrls}
109
116
  />
110
117
  <div className="flex">
111
- <Text {...props} />
118
+ <Text {...props} refText={refText} />
112
119
  </div>
113
120
  <Actions
114
121
  {...props}
122
+ refText={refText}
115
123
  refUpload={refUpload}
116
124
  isUploading={isUploading}
117
125
  fileList={fileList}
@@ -60,7 +60,8 @@ export const AllowUpload: Story = {
60
60
 
61
61
  export const AllowSpeech: Story = {
62
62
  render: (props) => {
63
- const [recording, setRecording] = useState(false);
63
+ const [recording, setRecording] = useState(true);
64
+
64
65
  return <Component {...props} allowSpeech={{ recording, onRecordingChange: setRecording }} />;
65
66
  },
66
67
  };