bhd-components 0.9.29 → 0.10.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.
Files changed (103) hide show
  1. package/dist/index.esm.es5.development.css +662 -0
  2. package/dist/index.esm.es5.development.js +2694 -159
  3. package/dist/index.esm.es5.production.css +1 -1
  4. package/dist/index.esm.es5.production.js +1 -1
  5. package/dist/vendor.esm.es5.development.js +2515 -1100
  6. package/dist/vendor.esm.es5.production.js +136 -136
  7. package/es2017/AIMessageList/components/content/index.d.ts +4 -0
  8. package/es2017/AIMessageList/components/content/index.js +29 -0
  9. package/es2017/AIMessageList/components/content/index.module.less +8 -0
  10. package/es2017/AIMessageList/components/copyIcon/index.d.ts +7 -0
  11. package/es2017/AIMessageList/components/copyIcon/index.js +58 -0
  12. package/es2017/AIMessageList/components/copyIcon/index.module.less +22 -0
  13. package/es2017/AIMessageList/components/errorCallback/index.d.ts +3 -0
  14. package/es2017/AIMessageList/components/errorCallback/index.js +6 -0
  15. package/es2017/AIMessageList/components/fileList/fileIcon.d.ts +3 -0
  16. package/es2017/AIMessageList/components/fileList/fileIcon.js +970 -0
  17. package/es2017/AIMessageList/components/fileList/index.d.ts +4 -0
  18. package/es2017/AIMessageList/components/fileList/index.js +299 -0
  19. package/es2017/AIMessageList/components/fileList/index.module.less +95 -0
  20. package/es2017/AIMessageList/components/footer/index.d.ts +10 -0
  21. package/es2017/AIMessageList/components/footer/index.js +296 -0
  22. package/es2017/AIMessageList/components/footer/index.module.less +51 -0
  23. package/es2017/AIMessageList/components/header/index.d.ts +9 -0
  24. package/es2017/AIMessageList/components/header/index.js +94 -0
  25. package/es2017/AIMessageList/components/header/index.module.less +31 -0
  26. package/es2017/AIMessageList/components/referencesIcon/index.d.ts +9 -0
  27. package/es2017/AIMessageList/components/referencesIcon/index.js +37 -0
  28. package/es2017/AIMessageList/components/referencesIcon/index.module.less +13 -0
  29. package/es2017/AIMessageList/components/renderReferrnce/index.d.ts +10 -0
  30. package/es2017/AIMessageList/components/renderReferrnce/index.js +68 -0
  31. package/es2017/AIMessageList/components/renderReferrnce/index.module.less +64 -0
  32. package/es2017/AIMessageList/components/sendBtn/index.d.ts +4 -0
  33. package/es2017/AIMessageList/components/sendBtn/index.js +46 -0
  34. package/es2017/AIMessageList/components/sendBtn/index.module.less +25 -0
  35. package/es2017/AIMessageList/components/uplodaFileBtn/index.d.ts +4 -0
  36. package/es2017/AIMessageList/components/uplodaFileBtn/index.js +33 -0
  37. package/es2017/AIMessageList/components/uplodaFileBtn/index.module.less +5 -0
  38. package/es2017/AIMessageList/components/virtuosoList/index.d.ts +5 -0
  39. package/es2017/AIMessageList/components/virtuosoList/index.js +507 -0
  40. package/es2017/AIMessageList/components/virtuosoList/index.module.less +381 -0
  41. package/es2017/AIMessageList/index.d.ts +4 -0
  42. package/es2017/AIMessageList/index.js +58 -0
  43. package/es2017/AIMessageList/index.module.less +20 -0
  44. package/es2017/AIMessageList/type.d.ts +242 -0
  45. package/es2017/customerService/index.js +1 -0
  46. package/es2017/images/loading2.js +2 -0
  47. package/es2017/index.d.ts +1 -0
  48. package/es2017/index.js +1 -0
  49. package/es2017/utils/Date.d.ts +2 -1
  50. package/es2017/utils/Date.js +2 -1
  51. package/es2017/utils/dom.d.ts +4 -1
  52. package/es2017/utils/dom.js +44 -1
  53. package/es2017/utils/number.d.ts +1 -0
  54. package/es2017/utils/number.js +9 -0
  55. package/esm/AIMessageList/components/content/index.d.ts +4 -0
  56. package/esm/AIMessageList/components/content/index.js +29 -0
  57. package/esm/AIMessageList/components/content/index.module.less +8 -0
  58. package/esm/AIMessageList/components/copyIcon/index.d.ts +7 -0
  59. package/esm/AIMessageList/components/copyIcon/index.js +61 -0
  60. package/esm/AIMessageList/components/copyIcon/index.module.less +22 -0
  61. package/esm/AIMessageList/components/errorCallback/index.d.ts +3 -0
  62. package/esm/AIMessageList/components/errorCallback/index.js +6 -0
  63. package/esm/AIMessageList/components/fileList/fileIcon.d.ts +3 -0
  64. package/esm/AIMessageList/components/fileList/fileIcon.js +970 -0
  65. package/esm/AIMessageList/components/fileList/index.d.ts +4 -0
  66. package/esm/AIMessageList/components/fileList/index.js +325 -0
  67. package/esm/AIMessageList/components/fileList/index.module.less +95 -0
  68. package/esm/AIMessageList/components/footer/index.d.ts +10 -0
  69. package/esm/AIMessageList/components/footer/index.js +304 -0
  70. package/esm/AIMessageList/components/footer/index.module.less +51 -0
  71. package/esm/AIMessageList/components/header/index.d.ts +9 -0
  72. package/esm/AIMessageList/components/header/index.js +96 -0
  73. package/esm/AIMessageList/components/header/index.module.less +31 -0
  74. package/esm/AIMessageList/components/referencesIcon/index.d.ts +9 -0
  75. package/esm/AIMessageList/components/referencesIcon/index.js +39 -0
  76. package/esm/AIMessageList/components/referencesIcon/index.module.less +13 -0
  77. package/esm/AIMessageList/components/renderReferrnce/index.d.ts +10 -0
  78. package/esm/AIMessageList/components/renderReferrnce/index.js +72 -0
  79. package/esm/AIMessageList/components/renderReferrnce/index.module.less +64 -0
  80. package/esm/AIMessageList/components/sendBtn/index.d.ts +4 -0
  81. package/esm/AIMessageList/components/sendBtn/index.js +48 -0
  82. package/esm/AIMessageList/components/sendBtn/index.module.less +25 -0
  83. package/esm/AIMessageList/components/uplodaFileBtn/index.d.ts +4 -0
  84. package/esm/AIMessageList/components/uplodaFileBtn/index.js +33 -0
  85. package/esm/AIMessageList/components/uplodaFileBtn/index.module.less +5 -0
  86. package/esm/AIMessageList/components/virtuosoList/index.d.ts +5 -0
  87. package/esm/AIMessageList/components/virtuosoList/index.js +484 -0
  88. package/esm/AIMessageList/components/virtuosoList/index.module.less +381 -0
  89. package/esm/AIMessageList/index.d.ts +4 -0
  90. package/esm/AIMessageList/index.js +58 -0
  91. package/esm/AIMessageList/index.module.less +20 -0
  92. package/esm/AIMessageList/type.d.ts +242 -0
  93. package/esm/customerService/index.js +1 -0
  94. package/esm/images/loading2.js +2 -0
  95. package/esm/index.d.ts +1 -0
  96. package/esm/index.js +1 -0
  97. package/esm/utils/Date.d.ts +2 -1
  98. package/esm/utils/Date.js +2 -1
  99. package/esm/utils/dom.d.ts +4 -1
  100. package/esm/utils/dom.js +45 -1
  101. package/esm/utils/number.d.ts +1 -0
  102. package/esm/utils/number.js +9 -0
  103. package/package.json +2 -1
@@ -0,0 +1,507 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@ice/jsx-runtime/jsx-runtime";
3
+ import React, { useRef, useState, useCallback, useEffect, forwardRef, useImperativeHandle } from "react";
4
+ import styles from "./index.module.less";
5
+ import { copyText, findParent, delegate } from "../../../utils/dom";
6
+ import { Virtuoso } from "react-virtuoso";
7
+ import loading2Gif from "../../../images/loading2";
8
+ import { parseDate } from "../../../utils/Date";
9
+ import { Remarkable } from "remarkable";
10
+ import hljs from "highlight.js";
11
+ import "highlight.js/styles/github.css";
12
+ import CopyIcon from "../copyIcon";
13
+ import ReferencesIcon from "../referencesIcon";
14
+ const Header = ({ context })=>{
15
+ const { prefix, loading } = context;
16
+ if (!loading) return null;
17
+ const getCls = (clsName)=>{
18
+ return styles[clsName] + " " + prefix + "-" + clsName;
19
+ };
20
+ return /*#__PURE__*/ _jsx("div", {
21
+ className: `${getCls("loadingIcon")}`,
22
+ children: /*#__PURE__*/ _jsx("img", {
23
+ src: loading2Gif,
24
+ alt: ""
25
+ })
26
+ });
27
+ };
28
+ const remarkable = new Remarkable({
29
+ highlight: function(str, lang) {
30
+ if (lang && hljs.getLanguage(lang)) {
31
+ try {
32
+ return hljs.highlight(lang, str).value;
33
+ } catch (err) {}
34
+ }
35
+ try {
36
+ return hljs.highlightAuto(str).value;
37
+ } catch (err) {}
38
+ return ""; // use external default escaping
39
+ }
40
+ });
41
+ const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
42
+ const { prefix, contentConfig, apiRef } = props;
43
+ const { getList, coverRenderText, msgAction = [
44
+ "copy",
45
+ "references"
46
+ ], coverRenderReferences } = contentConfig;
47
+ const loadMoreProps = contentConfig.loadMore || true;
48
+ const virtuosoRef = useRef(null);
49
+ const [loading, setLoading] = useState(false); // 是否加载中
50
+ const [dataSource, setDataSource] = useState([]);
51
+ const [firstItemIndex, setFirstItemIndex] = useState(0);
52
+ const [page, setPage] = useState(1);
53
+ const [pageSize, setPageSize] = useState(30);
54
+ const [total, setTotal] = useState(0);
55
+ const timerRef = useRef({
56
+ loadMore: null,
57
+ scrollTimer: null
58
+ });
59
+ const wrapperRef = useRef(null);
60
+ const recordRef = useRef({
61
+ page: page,
62
+ pageSize: pageSize,
63
+ total: total,
64
+ dataSource: dataSource,
65
+ maxPage: Math.ceil(total / pageSize)
66
+ });
67
+ const timeRenderCache = useRef(new Map()).current;
68
+ useImperativeHandle(ref, ()=>{
69
+ return {
70
+ addMsg: (msg)=>{
71
+ setDataSource((data)=>{
72
+ return [
73
+ ...data,
74
+ msg
75
+ ];
76
+ });
77
+ },
78
+ updateMsg: (id, obj)=>{
79
+ setDataSource((data)=>{
80
+ return data.map((item)=>{
81
+ if (item.id === id) {
82
+ return _object_spread({}, item, obj);
83
+ }
84
+ return item;
85
+ });
86
+ });
87
+ },
88
+ clearInputing () {
89
+ setDataSource((data)=>{
90
+ return data.filter((item)=>item.id !== "inputing");
91
+ });
92
+ }
93
+ };
94
+ });
95
+ useEffect(()=>{
96
+ getData(page, pageSize);
97
+ let removeFn = delegate(wrapperRef.current, "click", `.${styles.copyCode}`, (event, target)=>{
98
+ findCopyContent(event);
99
+ });
100
+ return ()=>{
101
+ removeFn();
102
+ clearTimeout(timerRef.current.loadMore);
103
+ clearTimeout(timerRef.current.scrollTimer);
104
+ };
105
+ }, []);
106
+ useEffect(()=>{
107
+ if (!virtuosoRef.current) return;
108
+ virtuosoRef.current.scrollToIndex({
109
+ index: "LAST",
110
+ behavior: "auto"
111
+ });
112
+ clearTimeout(timerRef.current.scrollTimer);
113
+ timerRef.current.scrollTimer = setTimeout(()=>{
114
+ virtuosoRef.current.scrollToIndex({
115
+ index: "LAST",
116
+ behavior: "auto",
117
+ align: "end"
118
+ });
119
+ }, 500);
120
+ }, [
121
+ dataSource
122
+ ]);
123
+ useEffect(()=>{
124
+ recordRef.current.page = page;
125
+ recordRef.current.pageSize = pageSize;
126
+ recordRef.current.total = total;
127
+ recordRef.current.dataSource = dataSource;
128
+ recordRef.current.maxPage = Math.ceil(total / pageSize);
129
+ }, [
130
+ page,
131
+ pageSize,
132
+ total,
133
+ dataSource
134
+ ]);
135
+ const getData = (page, pageSize)=>{
136
+ setLoading(true);
137
+ clearTimeout(timerRef.current.loadMore);
138
+ timerRef.current.loadMore = setTimeout(()=>{
139
+ setLoading(false);
140
+ getList(page, pageSize).then((listObj)=>{
141
+ setLoading(false);
142
+ console.log("listObjlistObj", listObj);
143
+ setDataSource((data)=>{
144
+ return [
145
+ ...data,
146
+ ...listObj.dataSource
147
+ ];
148
+ });
149
+ setTotal(listObj.total);
150
+ setPage(page);
151
+ setPageSize(pageSize);
152
+ setFirstItemIndex(listObj.total - pageSize * (page - 1));
153
+ });
154
+ }, 500);
155
+ };
156
+ const getCls = (clsName)=>{
157
+ return styles[clsName] + " " + prefix + "-" + clsName;
158
+ };
159
+ const loadMore = useCallback(()=>{
160
+ if (!loadMoreProps) return;
161
+ if (recordRef.current.page >= recordRef.current.maxPage) return;
162
+ getData(page + 1, pageSize);
163
+ }, [
164
+ page,
165
+ pageSize
166
+ ]);
167
+ const itemContent = (index, item)=>{
168
+ const timeNode = renderTime(item);
169
+ const html = markToHtml(item.content, item.id);
170
+ let contentNode = /*#__PURE__*/ _jsx("div", {
171
+ dangerouslySetInnerHTML: {
172
+ __html: html
173
+ }
174
+ });
175
+ if (coverRenderText) {
176
+ contentNode = coverRenderText(item, html);
177
+ }
178
+ // 是否显示时间
179
+ let itemNode = /*#__PURE__*/ _jsx("div", {
180
+ className: `${getCls("msgItem")} ${item.location === "left" ? getCls("msgItem-left") : getCls("msgItem-right")}`,
181
+ children: /*#__PURE__*/ _jsxs("div", {
182
+ className: `${getCls("msgItem-box")}`,
183
+ "data-id": item.id,
184
+ onMouseEnter: ()=>onMouseEnter(item),
185
+ onMouseLeave: ()=>onMouseLeave(item),
186
+ children: [
187
+ renderAction("floatTop", item),
188
+ /*#__PURE__*/ _jsxs("div", {
189
+ className: `${getCls("msgItem-content")}`,
190
+ children: [
191
+ /*#__PURE__*/ _jsx("div", {
192
+ className: `${getCls("msgItem-text")}`,
193
+ children: contentNode
194
+ }),
195
+ renderAction("bottom", item)
196
+ ]
197
+ }),
198
+ item.location === "left" && renderAction("floatBottom", item),
199
+ renderReference(item)
200
+ ]
201
+ })
202
+ });
203
+ return /*#__PURE__*/ _jsxs(_Fragment, {
204
+ children: [
205
+ timeNode,
206
+ itemNode
207
+ ]
208
+ });
209
+ };
210
+ const renderReference = (item)=>{
211
+ const { reference } = item;
212
+ if (!item.reference) return null;
213
+ let referenceNode = null;
214
+ if (reference.type === "text") {
215
+ referenceNode = /*#__PURE__*/ _jsx("div", {
216
+ className: `${getCls("msgItem-references-text")}`,
217
+ children: /*#__PURE__*/ _jsx("div", {
218
+ children: reference.value
219
+ })
220
+ });
221
+ }
222
+ if (coverRenderReferences) {
223
+ return coverRenderReferences(item, referenceNode);
224
+ } else {
225
+ return referenceNode;
226
+ }
227
+ };
228
+ const onMouseEnter = (item)=>{
229
+ let dom = document.querySelector(`[data-id="${item.id}"]`);
230
+ let container = wrapperRef.current;
231
+ if (!dom) return;
232
+ const topDom = dom.querySelector("." + styles["msgItem-action-popover-floatTop"]);
233
+ const bottomDom = dom.querySelector("." + styles["msgItem-action-popover-floatBottom"]);
234
+ if (!topDom || !bottomDom) return;
235
+ console.log("itemitem", dom, container);
236
+ let con_obj = container.getBoundingClientRect(); // 外层盒子
237
+ let dom_obj = dom.getBoundingClientRect(); // 鼠标滑过元素
238
+ let y = dom_obj.y - con_obj.y;
239
+ if (y > 0) {
240
+ // 元素tou在可视区域内
241
+ // 判断底部是否在可视区域内
242
+ if (y + dom_obj.height < con_obj.height) {
243
+ // 底部在可视区域内
244
+ // 显示在下边
245
+ bottomDom.style.cssText = "display:flex";
246
+ } else {
247
+ // 显示在上
248
+ topDom.style.cssText = "display:flex";
249
+ }
250
+ } else {
251
+ console.log("yyyy", y, dom_obj, con_obj, y + dom_obj.height < con_obj.height);
252
+ // 元素top不在可视区域内
253
+ if (y + dom_obj.height < con_obj.height) {
254
+ // 底部在可视区域内
255
+ // 显示在下边
256
+ bottomDom.style.cssText = "display:flex";
257
+ } else {
258
+ // 头部和底部都不在可视区域内 移动 topDom到可视区域
259
+ topDom.style.cssText = `display:flex;top:${-1 * y + 24}px;bottom:auto;`;
260
+ }
261
+ }
262
+ };
263
+ const onMouseLeave = (item)=>{
264
+ let dom = document.querySelector(`[data-id="${item.id}"]`);
265
+ if (!dom) return;
266
+ const topDom = dom.querySelector("." + styles["msgItem-action-popover-floatTop"]);
267
+ const bottomDom = dom.querySelector("." + styles["msgItem-action-popover-floatBottom"]);
268
+ if (!topDom || !bottomDom) return;
269
+ bottomDom.style.cssText = "";
270
+ topDom.style.cssText = "";
271
+ };
272
+ const renderAction = (location, item)=>{
273
+ let copyNode = /*#__PURE__*/ _jsx(CopyIcon, {
274
+ prefix: prefix,
275
+ content: item.content
276
+ });
277
+ let referencesNode = /*#__PURE__*/ _jsx(ReferencesIcon, {
278
+ prefix: prefix,
279
+ apiRef: apiRef,
280
+ item: item
281
+ });
282
+ let leftNodes = null;
283
+ let rightNodes = /*#__PURE__*/ _jsxs(_Fragment, {
284
+ children: [
285
+ copyNode,
286
+ referencesNode
287
+ ]
288
+ });
289
+ if (msgAction instanceof Array) {
290
+ if (msgAction.length == 0) return null;
291
+ // 数组
292
+ if (!msgAction.includes("copy")) {
293
+ copyNode = null;
294
+ }
295
+ if (!msgAction.includes("references")) {
296
+ referencesNode = null;
297
+ }
298
+ } else if (typeof msgAction === "object") {
299
+ if (msgAction.renderLeft) {
300
+ leftNodes = msgAction.renderLeft(copyNode, referencesNode);
301
+ }
302
+ if (msgAction.renderRight) {
303
+ rightNodes = msgAction.renderRight(copyNode, referencesNode);
304
+ }
305
+ }
306
+ let index = recordRef.current.dataSource.findIndex((ite)=>ite.id == item.id);
307
+ if (location === "bottom") {
308
+ if (item.location === "left" && item.id !== "helloMsg" && item.id !== "inputing") {
309
+ if (index === recordRef.current.dataSource.length - 1) {
310
+ return /*#__PURE__*/ _jsxs("div", {
311
+ className: `${getCls("msgItem-action")}`,
312
+ children: [
313
+ /*#__PURE__*/ _jsx("div", {
314
+ className: `${getCls("msgItem-action-left")}`,
315
+ children: leftNodes
316
+ }),
317
+ /*#__PURE__*/ _jsx("div", {
318
+ className: `${getCls("msgItem-action-right")}`,
319
+ children: rightNodes
320
+ })
321
+ ]
322
+ });
323
+ }
324
+ }
325
+ // 只有最后一条才显示底部操作啦 且是左侧消息 且不是招呼语
326
+ }
327
+ if (location === "floatTop" || location === "floatBottom") {
328
+ if (item.location === "left" && item.id !== "helloMsg" && item.id !== "inputing" && index === recordRef.current.dataSource.length - 1) return null;
329
+ // 浮框
330
+ return /*#__PURE__*/ _jsx("div", {
331
+ className: `${getCls("msgItem-action-operate")}`,
332
+ children: /*#__PURE__*/ _jsxs("div", {
333
+ className: `${getCls("msgItem-action")} ${getCls("msgItem-action-popover")} ${getCls("msgItem-action-popover-" + location)}`,
334
+ children: [
335
+ /*#__PURE__*/ _jsx("div", {
336
+ className: `${getCls("msgItem-action-left")}`,
337
+ children: leftNodes
338
+ }),
339
+ /*#__PURE__*/ _jsx("div", {
340
+ className: `${getCls("msgItem-action-right")}`,
341
+ children: rightNodes
342
+ })
343
+ ]
344
+ })
345
+ });
346
+ }
347
+ return null;
348
+ };
349
+ const markToHtml = (markStr, id)=>{
350
+ let html = remarkable.render(markStr);
351
+ let position = 0;
352
+ html = html.replace(new RegExp(`<pre`, "ig"), ()=>{
353
+ position++;
354
+ return `<p class='${getCls("copyCode")} ${styles.copyCodeFun}' data-id=${id} data-position=${position}>
355
+ <span class='${getCls("icon")} ${getCls("copy")}'>
356
+ <svg
357
+ width="1em"
358
+ height="1em"
359
+ viewBox="0 0 14 14"
360
+ shape-rendering="geometricPrecision"
361
+ fill="currentColor"
362
+ xmlns="http://www.w3.org/2000/svg"
363
+ >
364
+ <g clip-path="url(#clip0_518_8403)">
365
+ <path
366
+ d="M6.16666 1.66666H13.1667C13.4761 1.66666 13.7728 1.78957 13.9916 2.00837C14.2104 2.22716 14.3333 2.5239 14.3333 2.83332V9.83332C14.3333 10.1427 14.2104 10.4395 13.9916 10.6583C13.7728 10.8771 13.4761 11 13.1667 11H6.16666C5.85724 11 5.5605 10.8771 5.34171 10.6583C5.12291 10.4395 5 10.1427 5 9.83332V2.83332C5 2.5239 5.12291 2.22716 5.34171 2.00837C5.5605 1.78957 5.85724 1.66666 6.16666 1.66666ZM6.16666 2.66666C6.12246 2.66666 6.08007 2.68422 6.04881 2.71547C6.01756 2.74673 6 2.78912 6 2.83332V9.83332C6 9.85521 6.00431 9.87688 6.01268 9.8971C6.02106 9.91732 6.03334 9.9357 6.04881 9.95117C6.06429 9.96665 6.08266 9.97893 6.10288 9.9873C6.1231 9.99568 6.14478 9.99999 6.16666 9.99999H13.1667C13.2109 9.99999 13.2533 9.98243 13.2845 9.95117C13.3158 9.91992 13.3333 9.87753 13.3333 9.83332V2.83332C13.3333 2.78912 13.3158 2.74673 13.2845 2.71547C13.2533 2.68422 13.2109 2.66666 13.1667 2.66666H6.16666ZM10 12C10 11.8674 10.0527 11.7402 10.1464 11.6464C10.2402 11.5527 10.3674 11.5 10.5 11.5C10.6326 11.5 10.7598 11.5527 10.8536 11.6464C10.9473 11.7402 11 11.8674 11 12V13.1667C11 13.4761 10.8771 13.7728 10.6583 13.9916C10.4395 14.2104 10.1427 14.3333 9.83333 14.3333H2.83333C2.52391 14.3333 2.22717 14.2104 2.00837 13.9916C1.78958 13.7728 1.66666 13.4761 1.66666 13.1667V6.16666C1.66666 5.85724 1.78958 5.56049 2.00837 5.3417C2.22717 5.12291 2.52391 4.99999 2.83333 4.99999H4C4.13261 4.99999 4.25978 5.05267 4.35355 5.14644C4.44732 5.2402 4.5 5.36738 4.5 5.49999C4.5 5.6326 4.44732 5.75978 4.35355 5.85354C4.25978 5.94731 4.13261 5.99999 4 5.99999H2.83333C2.78913 5.99999 2.74674 6.01755 2.71548 6.04881C2.68422 6.08006 2.66666 6.12245 2.66666 6.16666V13.1667C2.66666 13.2109 2.68422 13.2533 2.71548 13.2845C2.74674 13.3158 2.78913 13.3333 2.83333 13.3333H9.83333C9.87753 13.3333 9.91993 13.3158 9.95118 13.2845C9.98244 13.2533 10 13.2109 10 13.1667V12Z"
367
+ />
368
+ </g>
369
+ <defs>
370
+ <clipPath id="clip0_518_8403">
371
+ <rect width="16" height="16" />
372
+ </clipPath>
373
+ </defs>
374
+ </svg>
375
+ </span>
376
+ <span class='${getCls("icon")} ${getCls("copy_success_flag")}'>
377
+ <svg
378
+ width="1em"
379
+ height="1em"
380
+ shape-rendering="geometricPrecision"
381
+ fill="currentColor"
382
+ viewBox="0 0 12 7"
383
+ xmlns="http://www.w3.org/2000/svg"
384
+ >
385
+ <path d="M11.2242 0.375687C11.4586 0.610002 11.4586 0.989901 11.2242 1.22422L4.82424 7.62422C4.58992 7.85853 4.21003 7.85853 3.97571 7.62422L0.775712 4.42422C0.541397 4.1899 0.541397 3.81 0.775712 3.57569C1.01003 3.34137 1.38993 3.34137 1.62424 3.57569L4.39998 6.35142L10.3757 0.375687C10.61 0.141373 10.9899 0.141373 11.2242 0.375687Z" />
386
+ </svg>
387
+ </span><span class="${getCls("copyCodeText")}">复制代码</span></p><pre`;
388
+ });
389
+ return html;
390
+ };
391
+ const renderTime = (item)=>{
392
+ // 生成缓存键
393
+ const cacheKey = `${item.id}`;
394
+ // 检查缓存中是否已有结果
395
+ if (timeRenderCache.has(cacheKey)) {
396
+ return timeRenderCache.get(cacheKey);
397
+ }
398
+ let index = recordRef.current.dataSource.findIndex((i)=>i.id === item.id);
399
+ let timeObj = parseDate(item.createTime);
400
+ let time = null;
401
+ if (index === 0) {
402
+ // 第一项 显示年月日 时分
403
+ time = `${timeObj.year}-${timeObj.month}-${timeObj.day} ${timeObj.hours}:${timeObj.minutes}`;
404
+ } else {
405
+ // 非第一项 与上一项进行对比
406
+ const prevItem = recordRef.current.dataSource[index - 1];
407
+ if (prevItem) {
408
+ let beforeTime = prevItem.createTime;
409
+ let beforeTimeObj = parseDate(beforeTime);
410
+ // 判断与上一条数据 是否跨天
411
+ if (timeObj.year !== beforeTimeObj.year || timeObj.month !== beforeTimeObj.month || timeObj.day !== beforeTimeObj.day) {
412
+ // 显示 年月日 时分
413
+ time = `${timeObj.year}-${timeObj.month}-${timeObj.day} ${timeObj.hours}:${timeObj.minutes}`;
414
+ } else {
415
+ // 没有跨天 判断是否相隔超过10分钟
416
+ if (timeObj.timestamp - beforeTimeObj.timestamp > 10 * 60 * 1000) {
417
+ // 超过10分钟 显示 时分
418
+ time = `${timeObj.hours}:${timeObj.minutes}`;
419
+ }
420
+ }
421
+ }
422
+ }
423
+ const result = time ? /*#__PURE__*/ _jsx("div", {
424
+ className: `${getCls("msg-date")}`,
425
+ children: time
426
+ }) : null;
427
+ // 将结果存入缓存
428
+ timeRenderCache.set(cacheKey, result);
429
+ return result;
430
+ };
431
+ const findCopyContent = (e)=>{
432
+ let source = findParent(e.target, styles.copyCode);
433
+ if (!source) return;
434
+ let id = source.getAttribute("data-id");
435
+ let position = source.getAttribute("data-position");
436
+ if (!id && !position) return;
437
+ let message = "";
438
+ recordRef.current.dataSource.forEach((item)=>{
439
+ if (item.id === id) {
440
+ message = item.content;
441
+ }
442
+ });
443
+ if (!message) return;
444
+ let codeConment = "";
445
+ let i = 0;
446
+ message.replaceAll(new RegExp(/```(?:.|\n)*?```/, "ig"), (con)=>{
447
+ i++;
448
+ if (i == position) {
449
+ // 异常标记
450
+ con = con.replace(/^```[\s\S]*?\n/, "").replace(/\n```$/, "");
451
+ codeConment = con;
452
+ return con;
453
+ } else {
454
+ return null;
455
+ }
456
+ });
457
+ resetStyles();
458
+ source.classList.add(styles.copy_success);
459
+ source.children[2].innerText = "复制成功";
460
+ copyText(codeConment);
461
+ setTimeout(()=>{
462
+ try {
463
+ resetStyles();
464
+ } catch (error) {}
465
+ }, 3000);
466
+ };
467
+ //初始化样式
468
+ const resetStyles = ()=>{
469
+ let dom_list = document.getElementsByClassName(styles.copy_success);
470
+ for(var i = 0; i < dom_list.length; i++){
471
+ dom_list[i].classList.remove(styles.copy_success);
472
+ }
473
+ let dom_list2 = document.getElementsByClassName(styles.copyCodeFun);
474
+ for(var i = 0; i < dom_list2.length; i++){
475
+ let p = dom_list2[i].getElementsByClassName(styles.copyCodeText);
476
+ p[0].innerText = "复制代码";
477
+ }
478
+ };
479
+ return /*#__PURE__*/ _jsx("div", {
480
+ className: `${getCls("virtuosoList-wrapper")}`,
481
+ ref: wrapperRef,
482
+ children: /*#__PURE__*/ _jsx(Virtuoso, {
483
+ ref: virtuosoRef,
484
+ style: {
485
+ height: "100%"
486
+ },
487
+ data: dataSource,
488
+ initialTopMostItemIndex: {
489
+ index: "LAST",
490
+ align: "end"
491
+ },
492
+ startReached: loadMore,
493
+ firstItemIndex: firstItemIndex,
494
+ context: {
495
+ loading,
496
+ prefix
497
+ },
498
+ itemContent: itemContent,
499
+ components: {
500
+ Header: Header
501
+ },
502
+ increaseViewportBy: 200,
503
+ overscan: 10
504
+ })
505
+ });
506
+ });
507
+ export default VirtuosoList;