@myun/gimi-chat 0.9.25 → 0.9.27
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/dist/components/chat-input/index.js +60 -7
- package/dist/components/chat-input/index.module.css +2 -2
- package/dist/components/file-upload/index.d.ts +1 -0
- package/dist/components/file-upload/index.js +14 -3
- package/dist/components/upload-list/ImageFile.js +1 -1
- package/dist/components/upload-list/imageFile.module.css +6 -0
- package/dist/i18n/locales/en-US.js +1 -1
- package/dist/i18n/locales/zh-CN.js +1 -1
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -181,6 +181,41 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
181
181
|
handleQuickInput(props.asrText, false);
|
|
182
182
|
}
|
|
183
183
|
}, [props.asrText, props.isRecording, props.isVoiceGetting, handleQuickInput]);
|
|
184
|
+
|
|
185
|
+
// 粘贴图片支持
|
|
186
|
+
React.useEffect(function () {
|
|
187
|
+
var el = inputWrapRef.current;
|
|
188
|
+
if (!el) return;
|
|
189
|
+
var handlePaste = function handlePaste(e) {
|
|
190
|
+
var _e$clipboardData, _agentObjRef$current, _fileList$length, _uploadFileRef$curren;
|
|
191
|
+
var items = Array.from(((_e$clipboardData = e.clipboardData) === null || _e$clipboardData === void 0 ? void 0 : _e$clipboardData.items) || []);
|
|
192
|
+
var imageItem = items.find(function (item) {
|
|
193
|
+
return item.kind === 'file' && item.type.startsWith('image/');
|
|
194
|
+
});
|
|
195
|
+
if (!imageItem) return;
|
|
196
|
+
|
|
197
|
+
// 有图片时阻止 tiptap 默认行为(避免图片被插入编辑器)
|
|
198
|
+
e.stopPropagation();
|
|
199
|
+
e.preventDefault();
|
|
200
|
+
|
|
201
|
+
// 前置校验:上传功能是否开启
|
|
202
|
+
if (!props.enableFileUpload || ((_agentObjRef$current = agentObjRef.current) === null || _agentObjRef$current === void 0 ? void 0 : _agentObjRef$current.openUploadFile) === 0) return;
|
|
203
|
+
if (props.disabled || isAskProcess) return;
|
|
204
|
+
if (((_fileList$length = fileList === null || fileList === void 0 ? void 0 : fileList.length) !== null && _fileList$length !== void 0 ? _fileList$length : 0) >= 10) {
|
|
205
|
+
Toast.info(t('chatInput.uploadLimitTen'));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
var file = imageItem.getAsFile();
|
|
209
|
+
if (!file) return;
|
|
210
|
+
(_uploadFileRef$curren = uploadFileRef.current) === null || _uploadFileRef$curren === void 0 || _uploadFileRef$curren.uploadFileByRaw(file);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// capture: true 确保在 tiptap 处理前拦截
|
|
214
|
+
el.addEventListener('paste', handlePaste, true);
|
|
215
|
+
return function () {
|
|
216
|
+
return el.removeEventListener('paste', handlePaste, true);
|
|
217
|
+
};
|
|
218
|
+
}, [props.enableFileUpload, props.disabled, isAskProcess, fileList, t]);
|
|
184
219
|
var handleTip = function handleTip() {
|
|
185
220
|
if ((fileList === null || fileList === void 0 ? void 0 : fileList.length) >= 10) {
|
|
186
221
|
return Toast.info(t('chatInput.uploadLimitTen'));
|
|
@@ -444,8 +479,26 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
444
479
|
var _props$onSend;
|
|
445
480
|
var inputContents = content.inputContents || [];
|
|
446
481
|
var text = extractText(inputContents);
|
|
482
|
+
|
|
483
|
+
// 检查是否有文件正在上传或解析中
|
|
484
|
+
var uploadingFile = fileList === null || fileList === void 0 ? void 0 : fileList.find(function (file) {
|
|
485
|
+
return file.status === FileStatus.UPLOADING || file.status === FileStatus.PADDING || file.status === FileStatus.RETRING;
|
|
486
|
+
});
|
|
487
|
+
if (uploadingFile) {
|
|
488
|
+
var _inputRef$current7;
|
|
489
|
+
// 文件处理中,恢复输入内容,不发送
|
|
490
|
+
var message = '';
|
|
491
|
+
if (uploadingFile.status === FileStatus.UPLOADING || uploadingFile.status === FileStatus.RETRING) {
|
|
492
|
+
message = t('fileValidation.uploading');
|
|
493
|
+
} else if (uploadingFile.status === FileStatus.PADDING) {
|
|
494
|
+
message = t('fileValidation.parsing');
|
|
495
|
+
}
|
|
496
|
+
Toast.info(message);
|
|
497
|
+
(_inputRef$current7 = inputRef.current) === null || _inputRef$current7 === void 0 || _inputRef$current7.setContent(text);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
447
500
|
(_props$onSend = props.onSend) === null || _props$onSend === void 0 || _props$onSend.call(props, text);
|
|
448
|
-
}, [props]);
|
|
501
|
+
}, [props, fileList, t]);
|
|
449
502
|
var renderConfigureArea = React.useCallback(function () {
|
|
450
503
|
return /*#__PURE__*/React.createElement("div", {
|
|
451
504
|
className: styles.configureArea
|
|
@@ -471,8 +524,8 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
471
524
|
}, [UploadFileTool, props.hiddenDeepThink, AgentContainer]);
|
|
472
525
|
var stopSSe = function stopSSe() {
|
|
473
526
|
if (uploadFileRef.current) {
|
|
474
|
-
var _uploadFileRef$
|
|
475
|
-
(_uploadFileRef$
|
|
527
|
+
var _uploadFileRef$curren2;
|
|
528
|
+
(_uploadFileRef$curren2 = uploadFileRef.current) === null || _uploadFileRef$curren2 === void 0 || _uploadFileRef$curren2.abortUpload();
|
|
476
529
|
}
|
|
477
530
|
};
|
|
478
531
|
var handleDelFile = React.useCallback(function (uid) {
|
|
@@ -491,11 +544,11 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
491
544
|
return item.uid === file.uid;
|
|
492
545
|
});
|
|
493
546
|
if ((_file === null || _file === void 0 ? void 0 : _file.status) === FileStatus.ANALYSE_FAILED) {
|
|
494
|
-
var _uploadFileRef$curren2;
|
|
495
|
-
(_uploadFileRef$curren2 = uploadFileRef.current) === null || _uploadFileRef$curren2 === void 0 || _uploadFileRef$curren2.handleSSEFileAnalyize(_file);
|
|
496
|
-
} else {
|
|
497
547
|
var _uploadFileRef$curren3;
|
|
498
|
-
(_uploadFileRef$curren3 = uploadFileRef.current) === null || _uploadFileRef$curren3 === void 0 || _uploadFileRef$curren3.
|
|
548
|
+
(_uploadFileRef$curren3 = uploadFileRef.current) === null || _uploadFileRef$curren3 === void 0 || _uploadFileRef$curren3.handleSSEFileAnalyize(_file);
|
|
549
|
+
} else {
|
|
550
|
+
var _uploadFileRef$curren4;
|
|
551
|
+
(_uploadFileRef$curren4 = uploadFileRef.current) === null || _uploadFileRef$curren4 === void 0 || _uploadFileRef$curren4.retryUpload(_file === null || _file === void 0 ? void 0 : _file.uid);
|
|
499
552
|
}
|
|
500
553
|
}, [fileList]);
|
|
501
554
|
var renderReference = React.useCallback(function () {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
box-shadow: inset 0 2px #fff, 0 2px 10px rgba(84, 105, 140, 0.15);
|
|
9
9
|
border-radius: 10px;
|
|
10
10
|
}
|
|
11
|
-
@media (min-width:
|
|
11
|
+
@media (min-width: 1920px) {
|
|
12
12
|
.inputWrap {
|
|
13
13
|
max-width: 1000px;
|
|
14
14
|
}
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
scrollbar-width: thin;
|
|
66
66
|
scrollbar-color: #d1d1d1 transparent;
|
|
67
67
|
}
|
|
68
|
-
@media (min-width:
|
|
68
|
+
@media (min-width: 1920px) {
|
|
69
69
|
.chatInput {
|
|
70
70
|
max-width: 1000px;
|
|
71
71
|
}
|
|
@@ -12,6 +12,7 @@ export interface IFileUploadRef {
|
|
|
12
12
|
abortUpload: () => void;
|
|
13
13
|
handleSSEFileAnalyize: (file: FileItem) => void;
|
|
14
14
|
retryUpload: (uid: string) => void;
|
|
15
|
+
uploadFileByRaw: (file: File) => void;
|
|
15
16
|
}
|
|
16
17
|
declare const FileUpload: React.ForwardRefExoticComponent<IProps & React.RefAttributes<unknown>>;
|
|
17
18
|
export default FileUpload;
|
|
@@ -22,7 +22,7 @@ var IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif', 'image/w
|
|
|
22
22
|
var MAX_IMAGE_COUNT = 10;
|
|
23
23
|
var MAX_FILE_COUNT = 1;
|
|
24
24
|
var MAX_TOTAL_COUNT = 10;
|
|
25
|
-
var MAX_IMAGE_SIZE =
|
|
25
|
+
var MAX_IMAGE_SIZE = 10; // MB
|
|
26
26
|
|
|
27
27
|
/** Redux FileItem → Semi Upload FileItem */
|
|
28
28
|
var transformFileItem = function transformFileItem(list) {
|
|
@@ -308,7 +308,18 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
308
308
|
(_fileUploadAbortRef$c = fileUploadAbortRef.current) === null || _fileUploadAbortRef$c === void 0 || _fileUploadAbortRef$c.abort();
|
|
309
309
|
},
|
|
310
310
|
handleSSEFileAnalyize: handleSSEFileAnalyize,
|
|
311
|
-
retryUpload: retryUpload
|
|
311
|
+
retryUpload: retryUpload,
|
|
312
|
+
uploadFileByRaw: function uploadFileByRaw(file) {
|
|
313
|
+
var uid = "paste_".concat(Date.now(), "_").concat(Math.random().toString(36).slice(2));
|
|
314
|
+
customRequest({
|
|
315
|
+
file: {
|
|
316
|
+
uid: uid,
|
|
317
|
+
name: file.name,
|
|
318
|
+
size: file.size,
|
|
319
|
+
fileInstance: file
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
312
323
|
};
|
|
313
324
|
});
|
|
314
325
|
var trigger = /*#__PURE__*/React.createElement(Button, {
|
|
@@ -324,7 +335,7 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
324
335
|
limit: MAX_TOTAL_COUNT
|
|
325
336
|
}));
|
|
326
337
|
},
|
|
327
|
-
multiple:
|
|
338
|
+
multiple: false,
|
|
328
339
|
accept: (accept === null || accept === void 0 ? void 0 : accept.join(',')) || DEFAULT_ACCEPT,
|
|
329
340
|
maxSize: maxSize * 1024,
|
|
330
341
|
onSizeError: function onSizeError() {
|
|
@@ -31,7 +31,7 @@ var ImageFile = function ImageFile(_ref) {
|
|
|
31
31
|
var isError = file.status === FileStatus.UPLOAD_FAILED || file.status === FileStatus.ANALYSE_FAILED || file.status === FileStatus.NETWORK_ERROR;
|
|
32
32
|
var isLoading = [FileStatus.PADDING, FileStatus.RETRING, FileStatus.UPLOADING].includes(file.status);
|
|
33
33
|
return /*#__PURE__*/React.createElement("div", {
|
|
34
|
-
className: classNames(styles.uploadBox, isMessage ? styles.messageImg :
|
|
34
|
+
className: classNames(styles.uploadBox, isMessage ? styles.messageImg : styles.inputImg, isSingle ? styles.singleImg : '')
|
|
35
35
|
}, /*#__PURE__*/React.createElement("img", {
|
|
36
36
|
src: file.fileUrl,
|
|
37
37
|
alt: "file-icon",
|
|
@@ -15,7 +15,7 @@ var enUS = {
|
|
|
15
15
|
'chatInput.uploadLimitFive': 'Upload limit is 5 files',
|
|
16
16
|
'chatInput.uploadLimitTen': 'Upload limit is 10 files',
|
|
17
17
|
'chatInput.flowUnsupported': 'This button is not supported in the current flow. Please wait for the current flow to finish or follow the instructions on the chat card.',
|
|
18
|
-
'chatInput.uploadFile': 'Supports Word, Excel, images\nUp to 10 files (max
|
|
18
|
+
'chatInput.uploadFile': 'Supports Word, Excel, images\nUp to 10 files (max 10MB each)',
|
|
19
19
|
'chatInput.newConversation': 'New conversation',
|
|
20
20
|
'chatInput.deepThinkTip': 'System intelligently switches thinking mode',
|
|
21
21
|
'chatInput.deepThinkModeAuto': 'Thinking',
|
|
@@ -15,7 +15,7 @@ var zhCN = {
|
|
|
15
15
|
'chatInput.uploadLimitFive': '最多上传5个文件哦',
|
|
16
16
|
'chatInput.uploadLimitTen': '最多上传10个文件哦',
|
|
17
17
|
'chatInput.flowUnsupported': '当前流程不支持该按钮的使用,请等待正在进行的流程结束或按对话卡片指示继续流程',
|
|
18
|
-
'chatInput.uploadFile': '支持Word、Excel、图片\n最多10个文件(单个不超过
|
|
18
|
+
'chatInput.uploadFile': '支持Word、Excel、图片\n最多10个文件(单个不超过10M)',
|
|
19
19
|
'chatInput.newConversation': '新对话',
|
|
20
20
|
'chatInput.deepThinkTip': '系统智能切换思考模式',
|
|
21
21
|
'chatInput.deepThinkModeAuto': '思考',
|