bhd-components 0.10.8 → 0.10.10
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/index.esm.es5.development.css +123 -92
- package/dist/index.esm.es5.development.js +115 -58
- package/dist/index.esm.es5.production.css +1 -1
- package/dist/index.esm.es5.production.js +1 -1
- package/dist/vendor.esm.es5.development.js +1 -1
- package/dist/vendor.esm.es5.production.js +1 -1
- package/es2017/AIMessageList/components/fileList/index.js +6 -3
- package/es2017/AIMessageList/components/referencesIcon/index.js +1 -1
- package/es2017/AIMessageList/components/referencesIcon/index.module.less +1 -1
- package/es2017/AIMessageList/components/virtuosoList/index.js +112 -56
- package/es2017/AIMessageList/components/virtuosoList/index.module.less +53 -11
- package/es2017/AIMessageList/type.d.ts +8 -2
- package/esm/AIMessageList/components/fileList/index.js +6 -3
- package/esm/AIMessageList/components/referencesIcon/index.js +1 -1
- package/esm/AIMessageList/components/referencesIcon/index.module.less +1 -1
- package/esm/AIMessageList/components/virtuosoList/index.js +106 -52
- package/esm/AIMessageList/components/virtuosoList/index.module.less +53 -11
- package/esm/AIMessageList/type.d.ts +8 -2
- package/package.json +1 -1
|
@@ -129,7 +129,8 @@ const FileList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
129
129
|
fileId: fileId,
|
|
130
130
|
url: "",
|
|
131
131
|
status: "waiting",
|
|
132
|
-
source: file
|
|
132
|
+
source: file,
|
|
133
|
+
size: file.size
|
|
133
134
|
};
|
|
134
135
|
}
|
|
135
136
|
return item;
|
|
@@ -152,7 +153,8 @@ const FileList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
152
153
|
fileId: fileId,
|
|
153
154
|
url: "",
|
|
154
155
|
status: "uploading",
|
|
155
|
-
source: file
|
|
156
|
+
source: file,
|
|
157
|
+
size: file.size
|
|
156
158
|
};
|
|
157
159
|
}
|
|
158
160
|
return item;
|
|
@@ -234,7 +236,8 @@ const FileList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
234
236
|
fileId: params.fileId || guidGenerator(),
|
|
235
237
|
url: params.url || "",
|
|
236
238
|
status: params.status || "waiting",
|
|
237
|
-
source: file
|
|
239
|
+
source: file,
|
|
240
|
+
size: file.size
|
|
238
241
|
};
|
|
239
242
|
return customFile;
|
|
240
243
|
};
|
|
@@ -45,8 +45,8 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
45
45
|
const { prefix, contentConfig, apiRef } = props;
|
|
46
46
|
const { getList, coverRenderText, msgAction = [
|
|
47
47
|
"copy",
|
|
48
|
-
"
|
|
49
|
-
], coverRenderReferences, onRecordMessage = ()=>{}, onVoteChange = ()=>{}, onRefresh = ()=>{},
|
|
48
|
+
"reference"
|
|
49
|
+
], coverRenderReferences, onRecordMessage = ()=>{}, onVoteChange = ()=>{}, onRefresh = ()=>{}, helloMsg, fileCustomRender = {} } = contentConfig;
|
|
50
50
|
const loadMoreProps = contentConfig.loadMore || true;
|
|
51
51
|
const virtuosoRef = useRef(null);
|
|
52
52
|
const [loading, setLoading] = useState(false); // 是否加载中
|
|
@@ -73,21 +73,7 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
73
73
|
const htmlRenderCache = useRef(new Map()).current;
|
|
74
74
|
useImperativeHandle(ref, ()=>{
|
|
75
75
|
return {
|
|
76
|
-
addMsg
|
|
77
|
-
if (msg.id !== "inputing") {
|
|
78
|
-
// 不记录"正在输入..."的消息
|
|
79
|
-
onRecordMessage(msg);
|
|
80
|
-
}
|
|
81
|
-
setDataSource((data)=>{
|
|
82
|
-
return [
|
|
83
|
-
...data,
|
|
84
|
-
msg
|
|
85
|
-
];
|
|
86
|
-
});
|
|
87
|
-
timerRef.current.scrollTimer = setTimeout(()=>{
|
|
88
|
-
scrollToBottom();
|
|
89
|
-
}, 100);
|
|
90
|
-
},
|
|
76
|
+
addMsg,
|
|
91
77
|
updateMsg: (id, obj)=>{
|
|
92
78
|
setDataSource((data)=>{
|
|
93
79
|
return data.map((item)=>{
|
|
@@ -129,7 +115,19 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
129
115
|
};
|
|
130
116
|
});
|
|
131
117
|
useEffect(()=>{
|
|
132
|
-
getData(page, pageSize)
|
|
118
|
+
getData(page, pageSize).then(()=>{
|
|
119
|
+
if (helloMsg) {
|
|
120
|
+
addMsg({
|
|
121
|
+
id: "helloMsg",
|
|
122
|
+
createTime: new Date().getTime(),
|
|
123
|
+
content: helloMsg,
|
|
124
|
+
location: "left",
|
|
125
|
+
reference: null,
|
|
126
|
+
source: null,
|
|
127
|
+
fileList: []
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
133
131
|
let removeFn = delegate(wrapperRef.current, "click", `.${styles.copyCode}`, (event, target)=>{
|
|
134
132
|
findCopyContent(event);
|
|
135
133
|
});
|
|
@@ -170,6 +168,40 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
170
168
|
dataSource,
|
|
171
169
|
sendingId
|
|
172
170
|
]);
|
|
171
|
+
const addMsg = (msg)=>{
|
|
172
|
+
if (msg.id !== "inputing" && msg.id !== "helloMsg") {
|
|
173
|
+
// 不记录"正在输入..."的消息
|
|
174
|
+
onRecordMessage(msg);
|
|
175
|
+
}
|
|
176
|
+
let list = [];
|
|
177
|
+
if (msg.location === "right" && msg.fileList && msg.fileList.length > 0) {
|
|
178
|
+
console.log("fileList", msg, msg.fileList);
|
|
179
|
+
msg.fileList.map((item)=>{
|
|
180
|
+
list.push({
|
|
181
|
+
type: "file",
|
|
182
|
+
id: item.fileId,
|
|
183
|
+
createTime: msg.createTime,
|
|
184
|
+
content: "",
|
|
185
|
+
location: "right",
|
|
186
|
+
reference: null,
|
|
187
|
+
source: null,
|
|
188
|
+
suffix: item.suffix,
|
|
189
|
+
fileSize: item.size || 0,
|
|
190
|
+
fileTitle: item.name
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
list.push(msg);
|
|
195
|
+
setDataSource((data)=>{
|
|
196
|
+
return [
|
|
197
|
+
...data,
|
|
198
|
+
...list
|
|
199
|
+
];
|
|
200
|
+
});
|
|
201
|
+
timerRef.current.scrollTimer = setTimeout(()=>{
|
|
202
|
+
scrollToBottom();
|
|
203
|
+
}, 100);
|
|
204
|
+
};
|
|
173
205
|
const scrollToBottom = ()=>{
|
|
174
206
|
if (!virtuosoRef.current) return;
|
|
175
207
|
virtuosoRef.current.scrollToIndex({
|
|
@@ -179,24 +211,20 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
179
211
|
};
|
|
180
212
|
const getData = (page, pageSize)=>{
|
|
181
213
|
setLoading(true);
|
|
182
|
-
|
|
183
|
-
timerRef.current.loadMore = setTimeout(()=>{
|
|
214
|
+
return getList(page, pageSize).then((listObj)=>{
|
|
184
215
|
setLoading(false);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
...listObj.dataSource
|
|
192
|
-
];
|
|
193
|
-
});
|
|
194
|
-
setTotal(listObj.total);
|
|
195
|
-
setPage(page);
|
|
196
|
-
setPageSize(pageSize);
|
|
197
|
-
setFirstItemIndex(listObj.total - pageSize * (page - 1));
|
|
216
|
+
console.log("listObjlistObj", listObj);
|
|
217
|
+
setDataSource((data)=>{
|
|
218
|
+
return [
|
|
219
|
+
...data,
|
|
220
|
+
...listObj.dataSource
|
|
221
|
+
];
|
|
198
222
|
});
|
|
199
|
-
|
|
223
|
+
setTotal(listObj.total);
|
|
224
|
+
setPage(page);
|
|
225
|
+
setPageSize(pageSize);
|
|
226
|
+
setFirstItemIndex(listObj.total - pageSize * (page - 1));
|
|
227
|
+
});
|
|
200
228
|
};
|
|
201
229
|
const getCls = (clsName)=>{
|
|
202
230
|
return styles[clsName] + " " + prefix + "-" + clsName;
|
|
@@ -226,26 +254,32 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
226
254
|
// item.fileTitle = "这是一个文件名称.docx";
|
|
227
255
|
// item.fileSize = "5Mb";
|
|
228
256
|
if (item.type === "file") {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
257
|
+
let renderFileObj = _object_spread({
|
|
258
|
+
fileTitleRender: (item)=>{
|
|
259
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
260
|
+
children: item.fileTitle
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}, fileCustomRender);
|
|
264
|
+
if (renderFileObj.fileRender) {
|
|
265
|
+
contentNode = renderFileObj.fileRender(item);
|
|
266
|
+
} else {
|
|
267
|
+
contentNode = /*#__PURE__*/ _jsxs("div", {
|
|
268
|
+
className: `${getCls("msgItem-file")}`,
|
|
269
|
+
children: [
|
|
270
|
+
/*#__PURE__*/ _jsx("div", {
|
|
271
|
+
className: `${getCls("msgItem-file-left")}`,
|
|
272
|
+
children: fileIconRender(item.suffix, renderFileObj.iconFileRender)
|
|
273
|
+
}),
|
|
274
|
+
/*#__PURE__*/ _jsx("div", {
|
|
275
|
+
className: `${getCls("msgItem-file-right")}`,
|
|
276
|
+
children: /*#__PURE__*/ _jsx("p", {
|
|
277
|
+
children: renderFileObj.fileTitleRender(item)
|
|
244
278
|
})
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
279
|
+
})
|
|
280
|
+
]
|
|
281
|
+
});
|
|
282
|
+
}
|
|
249
283
|
}
|
|
250
284
|
// 是否显示时间
|
|
251
285
|
let itemNode = /*#__PURE__*/ _jsx("div", {
|
|
@@ -285,12 +319,30 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
285
319
|
let referenceNode = null;
|
|
286
320
|
if (reference.type === "text") {
|
|
287
321
|
referenceNode = /*#__PURE__*/ _jsx("div", {
|
|
288
|
-
className: `${getCls("msgItem-
|
|
322
|
+
className: `${getCls("msgItem-reference-text")}`,
|
|
289
323
|
children: /*#__PURE__*/ _jsx("div", {
|
|
290
324
|
children: reference.value
|
|
291
325
|
})
|
|
292
326
|
});
|
|
293
327
|
}
|
|
328
|
+
if (reference.type === "file") {
|
|
329
|
+
referenceNode = /*#__PURE__*/ _jsx("div", {
|
|
330
|
+
className: `${getCls("msgItem-reference-file")}`,
|
|
331
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
332
|
+
className: `${getCls("msgItem-reference-file-box")}`,
|
|
333
|
+
children: [
|
|
334
|
+
/*#__PURE__*/ _jsx("div", {
|
|
335
|
+
className: `${getCls("msgItem-reference-file-left")}`,
|
|
336
|
+
children: fileIconRender(reference.value.suffix, fileCustomRender.iconFileRender)
|
|
337
|
+
}),
|
|
338
|
+
/*#__PURE__*/ _jsx("div", {
|
|
339
|
+
className: `${getCls("msgItem-reference-file-right")}`,
|
|
340
|
+
children: reference.value.name
|
|
341
|
+
})
|
|
342
|
+
]
|
|
343
|
+
})
|
|
344
|
+
});
|
|
345
|
+
}
|
|
294
346
|
if (coverRenderReferences) {
|
|
295
347
|
return coverRenderReferences(item, referenceNode);
|
|
296
348
|
} else {
|
|
@@ -411,7 +463,7 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
411
463
|
if (!msgAction.includes("copy")) {
|
|
412
464
|
copyNode = null;
|
|
413
465
|
}
|
|
414
|
-
if (!msgAction.includes("
|
|
466
|
+
if (!msgAction.includes("reference")) {
|
|
415
467
|
referencesNode = null;
|
|
416
468
|
}
|
|
417
469
|
if (!msgAction.includes("upVite")) {
|
|
@@ -607,6 +659,9 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
607
659
|
p[0].innerText = "复制代码";
|
|
608
660
|
}
|
|
609
661
|
};
|
|
662
|
+
const onScroll = ()=>{
|
|
663
|
+
console.log("滚动滚动");
|
|
664
|
+
};
|
|
610
665
|
return /*#__PURE__*/ _jsx("div", {
|
|
611
666
|
className: `${getCls("virtuosoList-wrapper")}`,
|
|
612
667
|
ref: wrapperRef,
|
|
@@ -631,7 +686,8 @@ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
631
686
|
Header: Header
|
|
632
687
|
},
|
|
633
688
|
increaseViewportBy: 200,
|
|
634
|
-
overscan: 10
|
|
689
|
+
overscan: 10,
|
|
690
|
+
onScroll: onScroll
|
|
635
691
|
})
|
|
636
692
|
});
|
|
637
693
|
});
|
|
@@ -274,30 +274,33 @@
|
|
|
274
274
|
border-radius: 8px;
|
|
275
275
|
border: 1px solid #ebebeb;
|
|
276
276
|
gap: 12px;
|
|
277
|
-
|
|
277
|
+
min-width: 216px;
|
|
278
|
+
.msgItem-file-left {
|
|
278
279
|
font-size: 24px;
|
|
279
280
|
display: flex;
|
|
280
281
|
justify-content: center;
|
|
281
282
|
align-items: center;
|
|
282
283
|
padding: 0;
|
|
283
284
|
margin: 0;
|
|
284
|
-
|
|
285
|
+
& > i {
|
|
285
286
|
display: flex;
|
|
286
287
|
font-size: 24px;
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
|
-
.msgItem-file-right{
|
|
290
|
+
.msgItem-file-right {
|
|
290
291
|
font-size: 14px;
|
|
291
292
|
font-weight: 400;
|
|
292
293
|
color: rgba(0, 0, 0, 0.65);
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
font-size: 12px;
|
|
299
|
-
color: rgba(0, 0, 0, 0.25);
|
|
294
|
+
margin: 0;
|
|
295
|
+
padding: 0;
|
|
296
|
+
& > p {
|
|
297
|
+
&:nth-child(1) {
|
|
298
|
+
// margin-bottom: 4px;
|
|
300
299
|
}
|
|
300
|
+
// &:nth-child(2) {
|
|
301
|
+
// font-size: 12px;
|
|
302
|
+
// color: rgba(0, 0, 0, 0.25);
|
|
303
|
+
// }
|
|
301
304
|
}
|
|
302
305
|
}
|
|
303
306
|
}
|
|
@@ -356,7 +359,7 @@
|
|
|
356
359
|
}
|
|
357
360
|
}
|
|
358
361
|
|
|
359
|
-
.msgItem-
|
|
362
|
+
.msgItem-reference-text {
|
|
360
363
|
padding: 8px;
|
|
361
364
|
border-radius: 2px;
|
|
362
365
|
background: #e7e7e7;
|
|
@@ -375,6 +378,45 @@
|
|
|
375
378
|
word-wrap: break-word;
|
|
376
379
|
}
|
|
377
380
|
}
|
|
381
|
+
.msgItem-reference-file {
|
|
382
|
+
padding: 8px;
|
|
383
|
+
border-radius: 2px;
|
|
384
|
+
background: #e7e7e7;
|
|
385
|
+
font-size: 12px;
|
|
386
|
+
color: rgba(0, 0, 0, 0.65);
|
|
387
|
+
margin-top: 8px;
|
|
388
|
+
|
|
389
|
+
.msgItem-reference-file-box {
|
|
390
|
+
display: flex;
|
|
391
|
+
align-items: center;
|
|
392
|
+
gap: 12px;
|
|
393
|
+
background: #fafafa;
|
|
394
|
+
border-radius: 8px;
|
|
395
|
+
border: 1px solid #ebebeb;
|
|
396
|
+
display: flex;
|
|
397
|
+
align-items: center;
|
|
398
|
+
gap: 12px;
|
|
399
|
+
padding: 8px 12px;
|
|
400
|
+
min-width: 216px;
|
|
401
|
+
.msgItem-reference-file-left {
|
|
402
|
+
font-size: 24px;
|
|
403
|
+
display: flex;
|
|
404
|
+
justify-content: center;
|
|
405
|
+
align-items: center;
|
|
406
|
+
padding: 0;
|
|
407
|
+
margin: 0;
|
|
408
|
+
& > i {
|
|
409
|
+
display: flex;
|
|
410
|
+
font-size: 24px;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
.msgItem-reference-file-right {
|
|
414
|
+
font-size: 14px;
|
|
415
|
+
font-weight: 400;
|
|
416
|
+
color: rgba(0, 0, 0, 0.65);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
378
420
|
&.msgItem-left {
|
|
379
421
|
justify-content: flex-start;
|
|
380
422
|
.msgItem-box {
|
|
@@ -62,7 +62,12 @@ export interface contentConfigProps {
|
|
|
62
62
|
onRecordMessage?: (item: dataItemType) => void; // 发送和接收的消息记录
|
|
63
63
|
onVoteChange?: (type:string,item: dataItemType) => void; // 点赞 或踩
|
|
64
64
|
onRefresh?: (item:dataItemType) => void;// 刷新
|
|
65
|
-
|
|
65
|
+
fileCustomRender?: {// 文件对象的自定义渲染
|
|
66
|
+
iconFileRender?: (suffix: string) => React.ReactNode; // 文件上传的 icon。参数 文件对象file 返回值为图标
|
|
67
|
+
fileTitleRender?: (item: dataItemType) => React.ReactNode;
|
|
68
|
+
fileBottomRender?: (item: dataItemType) => React.ReactNode;
|
|
69
|
+
fileRender?: (item: dataItemType) => React.ReactNode;
|
|
70
|
+
};
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
// content props
|
|
@@ -206,6 +211,7 @@ export interface fileCustomProps {
|
|
|
206
211
|
url: string;
|
|
207
212
|
status: fileStatus | undefined;
|
|
208
213
|
source: File | undefined;
|
|
214
|
+
size:number
|
|
209
215
|
}
|
|
210
216
|
|
|
211
217
|
// FileList 组件 ref props
|
|
@@ -294,7 +300,7 @@ export interface dataItemType {
|
|
|
294
300
|
vote?:string;// "up":点赞。"down":踩
|
|
295
301
|
type?:"file"|"text",
|
|
296
302
|
suffix?:string;
|
|
297
|
-
fileSize?:
|
|
303
|
+
fileSize?:number;
|
|
298
304
|
fileTitle?:string;
|
|
299
305
|
fileList?:fileCustomProps[];
|
|
300
306
|
}
|
|
@@ -139,7 +139,8 @@ var FileList = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
139
139
|
fileId: fileId,
|
|
140
140
|
url: "",
|
|
141
141
|
status: "waiting",
|
|
142
|
-
source: file
|
|
142
|
+
source: file,
|
|
143
|
+
size: file.size
|
|
143
144
|
};
|
|
144
145
|
}
|
|
145
146
|
return item;
|
|
@@ -161,7 +162,8 @@ var FileList = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
161
162
|
fileId: fileId,
|
|
162
163
|
url: "",
|
|
163
164
|
status: "uploading",
|
|
164
|
-
source: file
|
|
165
|
+
source: file,
|
|
166
|
+
size: file.size
|
|
165
167
|
};
|
|
166
168
|
}
|
|
167
169
|
return item;
|
|
@@ -248,7 +250,8 @@ var FileList = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
248
250
|
fileId: params.fileId || guidGenerator(),
|
|
249
251
|
url: params.url || "",
|
|
250
252
|
status: params.status || "waiting",
|
|
251
|
-
source: file
|
|
253
|
+
source: file,
|
|
254
|
+
size: file.size
|
|
252
255
|
};
|
|
253
256
|
return customFile;
|
|
254
257
|
};
|
|
@@ -55,7 +55,7 @@ var ReferencesIcon = function(props) {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
return /*#__PURE__*/ _jsx("div", {
|
|
58
|
-
className: "".concat(getCls("msgItem-action-
|
|
58
|
+
className: "".concat(getCls("msgItem-action-reference")),
|
|
59
59
|
onClick: function() {
|
|
60
60
|
return clickFn();
|
|
61
61
|
},
|