bhd-components 0.10.11 → 0.10.12

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 (116) hide show
  1. package/README.md +1 -1
  2. package/dist/index.esm.es5.development.css +0 -766
  3. package/dist/index.esm.es5.development.js +162 -3085
  4. package/dist/index.esm.es5.production.css +1 -1
  5. package/dist/index.esm.es5.production.js +1 -1
  6. package/dist/vendor.esm.es5.development.js +1100 -2515
  7. package/dist/vendor.esm.es5.production.js +136 -136
  8. package/es2017/customerService/index.js +3 -1
  9. package/es2017/index.d.ts +0 -1
  10. package/es2017/index.js +0 -1
  11. package/es2017/utils/Date.d.ts +1 -2
  12. package/es2017/utils/Date.js +1 -2
  13. package/es2017/utils/dom.d.ts +1 -4
  14. package/es2017/utils/dom.js +1 -44
  15. package/esm/customerService/index.js +3 -1
  16. package/esm/index.d.ts +0 -1
  17. package/esm/index.js +0 -1
  18. package/esm/utils/Date.d.ts +1 -2
  19. package/esm/utils/Date.js +1 -2
  20. package/esm/utils/dom.d.ts +1 -4
  21. package/esm/utils/dom.js +1 -45
  22. package/package.json +1 -2
  23. package/es2017/AIMessageList/components/content/index.d.ts +0 -4
  24. package/es2017/AIMessageList/components/content/index.js +0 -29
  25. package/es2017/AIMessageList/components/content/index.module.less +0 -8
  26. package/es2017/AIMessageList/components/copyIcon/index.d.ts +0 -7
  27. package/es2017/AIMessageList/components/copyIcon/index.js +0 -73
  28. package/es2017/AIMessageList/components/copyIcon/index.module.less +0 -22
  29. package/es2017/AIMessageList/components/errorCallback/index.d.ts +0 -3
  30. package/es2017/AIMessageList/components/errorCallback/index.js +0 -6
  31. package/es2017/AIMessageList/components/fileList/fileIcon.d.ts +0 -3
  32. package/es2017/AIMessageList/components/fileList/fileIcon.js +0 -970
  33. package/es2017/AIMessageList/components/fileList/index.d.ts +0 -4
  34. package/es2017/AIMessageList/components/fileList/index.js +0 -315
  35. package/es2017/AIMessageList/components/fileList/index.module.less +0 -95
  36. package/es2017/AIMessageList/components/footer/index.d.ts +0 -10
  37. package/es2017/AIMessageList/components/footer/index.js +0 -360
  38. package/es2017/AIMessageList/components/footer/index.module.less +0 -51
  39. package/es2017/AIMessageList/components/header/index.d.ts +0 -9
  40. package/es2017/AIMessageList/components/header/index.js +0 -94
  41. package/es2017/AIMessageList/components/header/index.module.less +0 -31
  42. package/es2017/AIMessageList/components/referencesIcon/index.d.ts +0 -9
  43. package/es2017/AIMessageList/components/referencesIcon/index.js +0 -63
  44. package/es2017/AIMessageList/components/referencesIcon/index.module.less +0 -13
  45. package/es2017/AIMessageList/components/refreshBtn/index.d.ts +0 -4
  46. package/es2017/AIMessageList/components/refreshBtn/index.js +0 -29
  47. package/es2017/AIMessageList/components/refreshBtn/index.module.less +0 -12
  48. package/es2017/AIMessageList/components/remarkBtn/index.d.ts +0 -4
  49. package/es2017/AIMessageList/components/remarkBtn/index.js +0 -51
  50. package/es2017/AIMessageList/components/remarkBtn/index.module.less +0 -13
  51. package/es2017/AIMessageList/components/renderReferrnce/index.d.ts +0 -10
  52. package/es2017/AIMessageList/components/renderReferrnce/index.js +0 -68
  53. package/es2017/AIMessageList/components/renderReferrnce/index.module.less +0 -64
  54. package/es2017/AIMessageList/components/sendBtn/index.d.ts +0 -4
  55. package/es2017/AIMessageList/components/sendBtn/index.js +0 -51
  56. package/es2017/AIMessageList/components/sendBtn/index.module.less +0 -25
  57. package/es2017/AIMessageList/components/uplodaFileBtn/index.d.ts +0 -4
  58. package/es2017/AIMessageList/components/uplodaFileBtn/index.js +0 -33
  59. package/es2017/AIMessageList/components/uplodaFileBtn/index.module.less +0 -5
  60. package/es2017/AIMessageList/components/virtuosoList/index.d.ts +0 -5
  61. package/es2017/AIMessageList/components/virtuosoList/index.js +0 -689
  62. package/es2017/AIMessageList/components/virtuosoList/index.module.less +0 -467
  63. package/es2017/AIMessageList/index.d.ts +0 -4
  64. package/es2017/AIMessageList/index.js +0 -58
  65. package/es2017/AIMessageList/index.module.less +0 -20
  66. package/es2017/AIMessageList/type.d.ts +0 -306
  67. package/es2017/images/loading2.js +0 -2
  68. package/es2017/utils/number.d.ts +0 -1
  69. package/es2017/utils/number.js +0 -9
  70. package/esm/AIMessageList/components/content/index.d.ts +0 -4
  71. package/esm/AIMessageList/components/content/index.js +0 -29
  72. package/esm/AIMessageList/components/content/index.module.less +0 -8
  73. package/esm/AIMessageList/components/copyIcon/index.d.ts +0 -7
  74. package/esm/AIMessageList/components/copyIcon/index.js +0 -76
  75. package/esm/AIMessageList/components/copyIcon/index.module.less +0 -22
  76. package/esm/AIMessageList/components/errorCallback/index.d.ts +0 -3
  77. package/esm/AIMessageList/components/errorCallback/index.js +0 -6
  78. package/esm/AIMessageList/components/fileList/fileIcon.d.ts +0 -3
  79. package/esm/AIMessageList/components/fileList/fileIcon.js +0 -970
  80. package/esm/AIMessageList/components/fileList/index.d.ts +0 -4
  81. package/esm/AIMessageList/components/fileList/index.js +0 -337
  82. package/esm/AIMessageList/components/fileList/index.module.less +0 -95
  83. package/esm/AIMessageList/components/footer/index.d.ts +0 -10
  84. package/esm/AIMessageList/components/footer/index.js +0 -376
  85. package/esm/AIMessageList/components/footer/index.module.less +0 -51
  86. package/esm/AIMessageList/components/header/index.d.ts +0 -9
  87. package/esm/AIMessageList/components/header/index.js +0 -96
  88. package/esm/AIMessageList/components/header/index.module.less +0 -31
  89. package/esm/AIMessageList/components/referencesIcon/index.d.ts +0 -9
  90. package/esm/AIMessageList/components/referencesIcon/index.js +0 -65
  91. package/esm/AIMessageList/components/referencesIcon/index.module.less +0 -13
  92. package/esm/AIMessageList/components/refreshBtn/index.d.ts +0 -4
  93. package/esm/AIMessageList/components/refreshBtn/index.js +0 -31
  94. package/esm/AIMessageList/components/refreshBtn/index.module.less +0 -12
  95. package/esm/AIMessageList/components/remarkBtn/index.d.ts +0 -4
  96. package/esm/AIMessageList/components/remarkBtn/index.js +0 -51
  97. package/esm/AIMessageList/components/remarkBtn/index.module.less +0 -13
  98. package/esm/AIMessageList/components/renderReferrnce/index.d.ts +0 -10
  99. package/esm/AIMessageList/components/renderReferrnce/index.js +0 -72
  100. package/esm/AIMessageList/components/renderReferrnce/index.module.less +0 -64
  101. package/esm/AIMessageList/components/sendBtn/index.d.ts +0 -4
  102. package/esm/AIMessageList/components/sendBtn/index.js +0 -53
  103. package/esm/AIMessageList/components/sendBtn/index.module.less +0 -25
  104. package/esm/AIMessageList/components/uplodaFileBtn/index.d.ts +0 -4
  105. package/esm/AIMessageList/components/uplodaFileBtn/index.js +0 -33
  106. package/esm/AIMessageList/components/uplodaFileBtn/index.module.less +0 -5
  107. package/esm/AIMessageList/components/virtuosoList/index.d.ts +0 -5
  108. package/esm/AIMessageList/components/virtuosoList/index.js +0 -666
  109. package/esm/AIMessageList/components/virtuosoList/index.module.less +0 -467
  110. package/esm/AIMessageList/index.d.ts +0 -4
  111. package/esm/AIMessageList/index.js +0 -58
  112. package/esm/AIMessageList/index.module.less +0 -20
  113. package/esm/AIMessageList/type.d.ts +0 -306
  114. package/esm/images/loading2.js +0 -2
  115. package/esm/utils/number.d.ts +0 -1
  116. package/esm/utils/number.js +0 -9
@@ -1,689 +0,0 @@
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
- import { UpVoteBtn, DownVoteBtn } from "../remarkBtn";
15
- import RefreshBtn from "../refreshBtn";
16
- import { fileIconRender } from "../fileList/fileIcon";
17
- const Header = ({ context })=>{
18
- const { prefix, loading } = context;
19
- if (!loading) return null;
20
- const getCls = (clsName)=>{
21
- return styles[clsName] + " " + prefix + "-" + clsName;
22
- };
23
- return /*#__PURE__*/ _jsx("div", {
24
- className: `${getCls("loadingIcon")}`,
25
- children: /*#__PURE__*/ _jsx("img", {
26
- src: loading2Gif,
27
- alt: ""
28
- })
29
- });
30
- };
31
- const remarkable = new Remarkable({
32
- highlight: function(str, lang) {
33
- if (lang && hljs.getLanguage(lang)) {
34
- try {
35
- return hljs.highlight(lang, str).value;
36
- } catch (err) {}
37
- }
38
- try {
39
- return hljs.highlightAuto(str).value;
40
- } catch (err) {}
41
- return ""; // use external default escaping
42
- }
43
- });
44
- const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
45
- const { prefix, contentConfig, apiRef } = props;
46
- const { getList, coverRenderText, msgAction = [
47
- "copy",
48
- "reference"
49
- ], coverRenderReferences, onRecordMessage = ()=>{}, onVoteChange = ()=>{}, onRefresh = ()=>{}, helloMsg, fileCustomRender = {} } = contentConfig;
50
- const loadMoreProps = contentConfig.loadMore || true;
51
- const virtuosoRef = useRef(null);
52
- const [loading, setLoading] = useState(false); // 是否加载中
53
- const [dataSource, setDataSource] = useState([]);
54
- const [firstItemIndex, setFirstItemIndex] = useState(0);
55
- const [page, setPage] = useState(1);
56
- const [sendingId, setSendingId] = useState("");
57
- const [pageSize, setPageSize] = useState(contentConfig.pageSize || 30);
58
- const [total, setTotal] = useState(0);
59
- const timerRef = useRef({
60
- loadMore: null,
61
- scrollTimer: null
62
- });
63
- const wrapperRef = useRef(null);
64
- const recordRef = useRef({
65
- page: page,
66
- pageSize: pageSize,
67
- total: total,
68
- dataSource: dataSource,
69
- maxPage: Math.ceil(total / pageSize),
70
- sendingId: ""
71
- });
72
- const timeRenderCache = useRef(new Map()).current;
73
- const htmlRenderCache = useRef(new Map()).current;
74
- useImperativeHandle(ref, ()=>{
75
- return {
76
- addMsg,
77
- updateMsg: (id, obj)=>{
78
- setDataSource((data)=>{
79
- return data.map((item)=>{
80
- if (item.id === id) {
81
- return _object_spread({}, item, obj);
82
- }
83
- return item;
84
- });
85
- });
86
- },
87
- clearInputing () {
88
- setDataSource((data)=>{
89
- return data.filter((item)=>item.id !== "inputing");
90
- });
91
- },
92
- recordMsg: (msg)=>{
93
- onRecordMessage(msg);
94
- },
95
- getDataSource: ()=>{
96
- return recordRef.current.dataSource;
97
- },
98
- upateDataSource: (id, obj)=>{
99
- setDataSource((list)=>{
100
- return list.map((item)=>{
101
- if (item.id === id) {
102
- return _object_spread({}, item, obj);
103
- }
104
- return item;
105
- });
106
- });
107
- },
108
- changeDataSource: (data)=>{
109
- setDataSource(data);
110
- },
111
- scrollToBottom,
112
- setSendingId: (id)=>{
113
- setSendingId(id);
114
- }
115
- };
116
- });
117
- useEffect(()=>{
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
- });
131
- let removeFn = delegate(wrapperRef.current, "click", `.${styles.copyCode}`, (event, target)=>{
132
- findCopyContent(event);
133
- });
134
- return ()=>{
135
- removeFn();
136
- clearTimeout(timerRef.current.loadMore);
137
- clearTimeout(timerRef.current.scrollTimer);
138
- };
139
- }, []);
140
- useEffect(()=>{
141
- if (!virtuosoRef.current) return;
142
- // virtuosoRef.current.scrollToIndex({
143
- // index: "LAST", // 或者使用 dataSource.length - 1
144
- // behavior: "auto", // 可以是 "smooth" 实现平滑滚动
145
- // });
146
- // clearTimeout(timerRef.current.scrollTimer);
147
- // timerRef.current.scrollTimer = setTimeout(() => {
148
- // virtuosoRef.current.scrollToIndex({
149
- // index: "LAST", // 或者使用 dataSource.length - 1
150
- // behavior: "auto", // 可以是 "smooth" 实现平滑滚动
151
- // align: "end",
152
- // });
153
- // }, 500);
154
- }, [
155
- dataSource
156
- ]);
157
- useEffect(()=>{
158
- recordRef.current.page = page;
159
- recordRef.current.pageSize = pageSize;
160
- recordRef.current.total = total;
161
- recordRef.current.dataSource = dataSource;
162
- recordRef.current.maxPage = Math.ceil(total / pageSize);
163
- recordRef.current.sendingId = sendingId;
164
- }, [
165
- page,
166
- pageSize,
167
- total,
168
- dataSource,
169
- sendingId
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
- fileTitle: item.name
190
- });
191
- });
192
- }
193
- list.push(msg);
194
- setDataSource((data)=>{
195
- return [
196
- ...data,
197
- ...list
198
- ];
199
- });
200
- timerRef.current.scrollTimer = setTimeout(()=>{
201
- scrollToBottom();
202
- }, 100);
203
- };
204
- const scrollToBottom = ()=>{
205
- if (!virtuosoRef.current) return;
206
- virtuosoRef.current.scrollToIndex({
207
- index: "LAST",
208
- behavior: "auto"
209
- });
210
- };
211
- const getData = (page, pageSize)=>{
212
- setLoading(true);
213
- return getList(page, pageSize).then((listObj)=>{
214
- setLoading(false);
215
- console.log("listObjlistObj", listObj);
216
- setDataSource((data)=>{
217
- return [
218
- ...data,
219
- ...listObj.dataSource
220
- ];
221
- });
222
- setTotal(listObj.total);
223
- setPage(page);
224
- setPageSize(pageSize);
225
- setFirstItemIndex(listObj.total - pageSize * (page - 1));
226
- });
227
- };
228
- const getCls = (clsName)=>{
229
- return styles[clsName] + " " + prefix + "-" + clsName;
230
- };
231
- const loadMore = useCallback(()=>{
232
- if (!loadMoreProps) return;
233
- if (recordRef.current.page >= recordRef.current.maxPage) return;
234
- getData(page + 1, pageSize);
235
- }, [
236
- page,
237
- pageSize
238
- ]);
239
- const itemContent = (index, item)=>{
240
- const timeNode = renderTime(item);
241
- let contentNode = null;
242
- const html = markToHtml(item.content, item.id);
243
- contentNode = /*#__PURE__*/ _jsx("div", {
244
- dangerouslySetInnerHTML: {
245
- __html: html
246
- }
247
- });
248
- if (coverRenderText) {
249
- contentNode = coverRenderText(item, html);
250
- }
251
- if (item.type === "file") {
252
- let renderFileObj = _object_spread({
253
- fileTitleRender: (item)=>{
254
- return /*#__PURE__*/ _jsx(_Fragment, {
255
- children: item.fileTitle
256
- });
257
- }
258
- }, fileCustomRender);
259
- if (renderFileObj.fileRender) {
260
- contentNode = renderFileObj.fileRender(item);
261
- } else {
262
- contentNode = /*#__PURE__*/ _jsxs("div", {
263
- className: `${getCls("msgItem-file")}`,
264
- children: [
265
- /*#__PURE__*/ _jsx("div", {
266
- className: `${getCls("msgItem-file-left")}`,
267
- children: fileIconRender(item.suffix, renderFileObj.iconFileRender)
268
- }),
269
- /*#__PURE__*/ _jsx("div", {
270
- className: `${getCls("msgItem-file-right")}`,
271
- children: /*#__PURE__*/ _jsx("p", {
272
- children: renderFileObj.fileTitleRender(item)
273
- })
274
- })
275
- ]
276
- });
277
- }
278
- }
279
- // 是否显示时间
280
- let itemNode = /*#__PURE__*/ _jsx("div", {
281
- className: `${getCls("msgItem")} ${item.location === "left" ? getCls("msgItem-left") : getCls("msgItem-right")}`,
282
- children: /*#__PURE__*/ _jsxs("div", {
283
- className: `${getCls("msgItem-box")}`,
284
- "data-id": item.id,
285
- onMouseEnter: ()=>onMouseEnter(item),
286
- onMouseLeave: ()=>onMouseLeave(item),
287
- children: [
288
- renderAction("floatTop", item),
289
- /*#__PURE__*/ _jsxs("div", {
290
- className: `${getCls("msgItem-content")}`,
291
- children: [
292
- /*#__PURE__*/ _jsx("div", {
293
- className: `${getCls("msgItem-text")}`,
294
- children: contentNode
295
- }),
296
- renderAction("bottom", item)
297
- ]
298
- }),
299
- item.location === "left" && renderAction("floatBottom", item),
300
- renderReference(item)
301
- ]
302
- })
303
- });
304
- return /*#__PURE__*/ _jsxs(_Fragment, {
305
- children: [
306
- timeNode,
307
- itemNode
308
- ]
309
- });
310
- };
311
- const renderReference = (item)=>{
312
- const { reference } = item;
313
- if (!item.reference) return null;
314
- let referenceNode = null;
315
- if (reference.type === "text") {
316
- referenceNode = /*#__PURE__*/ _jsx("div", {
317
- className: `${getCls("msgItem-reference-text")}`,
318
- children: /*#__PURE__*/ _jsx("div", {
319
- children: reference.value
320
- })
321
- });
322
- }
323
- if (reference.type === "file") {
324
- referenceNode = /*#__PURE__*/ _jsx("div", {
325
- className: `${getCls("msgItem-reference-file")}`,
326
- children: /*#__PURE__*/ _jsxs("div", {
327
- className: `${getCls("msgItem-reference-file-box")}`,
328
- children: [
329
- /*#__PURE__*/ _jsx("div", {
330
- className: `${getCls("msgItem-reference-file-left")}`,
331
- children: fileIconRender(reference.value.suffix, fileCustomRender.iconFileRender)
332
- }),
333
- /*#__PURE__*/ _jsx("div", {
334
- className: `${getCls("msgItem-reference-file-right")}`,
335
- children: reference.value.name
336
- })
337
- ]
338
- })
339
- });
340
- }
341
- if (coverRenderReferences) {
342
- return coverRenderReferences(item, referenceNode);
343
- } else {
344
- return referenceNode;
345
- }
346
- };
347
- const onMouseEnter = (item)=>{
348
- let dom = document.querySelector(`[data-id="${item.id}"]`);
349
- let container = wrapperRef.current;
350
- if (!dom) return;
351
- const topDom = dom.querySelector("." + styles["msgItem-action-popover-floatTop"]);
352
- const bottomDom = dom.querySelector("." + styles["msgItem-action-popover-floatBottom"]);
353
- if (!topDom || !bottomDom) return;
354
- console.log("itemitem", dom, container);
355
- let con_obj = container.getBoundingClientRect(); // 外层盒子
356
- let dom_obj = dom.getBoundingClientRect(); // 鼠标滑过元素
357
- let y = dom_obj.y - con_obj.y;
358
- if (y > 0) {
359
- // 元素tou在可视区域内
360
- // 判断底部是否在可视区域内
361
- if (y + dom_obj.height < con_obj.height) {
362
- // 底部在可视区域内
363
- // 显示在下边
364
- bottomDom.style.cssText = "display:flex";
365
- } else {
366
- // 显示在上
367
- topDom.style.cssText = "display:flex";
368
- }
369
- } else {
370
- console.log("yyyy", y, dom_obj, con_obj, y + dom_obj.height < con_obj.height);
371
- // 元素top不在可视区域内
372
- if (y + dom_obj.height < con_obj.height) {
373
- // 底部在可视区域内
374
- // 显示在下边
375
- bottomDom.style.cssText = "display:flex";
376
- } else {
377
- // 头部和底部都不在可视区域内 移动 topDom到可视区域
378
- topDom.style.cssText = `display:flex;top:${-1 * y + 24}px;bottom:auto;`;
379
- }
380
- }
381
- };
382
- const onMouseLeave = (item)=>{
383
- let dom = document.querySelector(`[data-id="${item.id}"]`);
384
- if (!dom) return;
385
- const topDom = dom.querySelector("." + styles["msgItem-action-popover-floatTop"]);
386
- const bottomDom = dom.querySelector("." + styles["msgItem-action-popover-floatBottom"]);
387
- if (!topDom || !bottomDom) return;
388
- bottomDom.style.cssText = "";
389
- topDom.style.cssText = "";
390
- };
391
- const renderAction = (location, item)=>{
392
- if (item.id === "inputing" || item.id === "helloMsg" || item.id === recordRef.current.sendingId) return null;
393
- let copyNode = /*#__PURE__*/ _jsx(CopyIcon, {
394
- prefix: prefix,
395
- content: item.content
396
- });
397
- let referencesNode = /*#__PURE__*/ _jsx(ReferencesIcon, {
398
- prefix: prefix,
399
- apiRef: apiRef,
400
- item: item
401
- });
402
- let UpVoteNode = /*#__PURE__*/ _jsx(UpVoteBtn, {
403
- prefix: prefix,
404
- isActive: item.vote === "up",
405
- clickFn: ()=>{
406
- onVoteChange(item.vote === "up" ? "" : "up", item);
407
- setDataSource((data)=>{
408
- return data.map((ite)=>{
409
- if (item.id === ite.id) {
410
- ite.vote = item.vote === "up" ? "" : "up";
411
- }
412
- return ite;
413
- });
414
- });
415
- }
416
- });
417
- let DownVoteNode = /*#__PURE__*/ _jsx(DownVoteBtn, {
418
- prefix: prefix,
419
- isActive: item.vote === "down",
420
- clickFn: ()=>{
421
- onVoteChange(item.vote === "down" ? "" : "down", item);
422
- setDataSource((data)=>{
423
- return data.map((ite)=>{
424
- if (item.id === ite.id) {
425
- ite.vote = ite.vote === "down" ? "" : "down";
426
- }
427
- return ite;
428
- });
429
- });
430
- }
431
- });
432
- let RefreshNode = /*#__PURE__*/ _jsx(RefreshBtn, {
433
- prefix: prefix,
434
- clickFn: ()=>onRefresh(item)
435
- });
436
- if (item.location === "right") {
437
- UpVoteNode = null;
438
- DownVoteNode = null;
439
- }
440
- if (item.type === "file") {
441
- copyNode = null;
442
- UpVoteNode = null;
443
- DownVoteNode = null;
444
- RefreshNode = null;
445
- }
446
- let leftNodes = null;
447
- let rightNodes = /*#__PURE__*/ _jsxs(_Fragment, {
448
- children: [
449
- copyNode,
450
- referencesNode,
451
- UpVoteNode,
452
- DownVoteNode
453
- ]
454
- });
455
- if (msgAction instanceof Array) {
456
- if (msgAction.length == 0) return null;
457
- // 数组
458
- if (!msgAction.includes("copy")) {
459
- copyNode = null;
460
- }
461
- if (!msgAction.includes("reference")) {
462
- referencesNode = null;
463
- }
464
- if (!msgAction.includes("upVite")) {
465
- UpVoteNode = null;
466
- }
467
- if (!msgAction.includes("downVote")) {
468
- DownVoteNode = null;
469
- }
470
- if (!msgAction.includes("refresh")) {
471
- RefreshNode = null;
472
- }
473
- } else if (typeof msgAction === "object") {
474
- if (msgAction.renderLeft) {
475
- leftNodes = msgAction.renderLeft(copyNode, referencesNode, UpVoteNode, DownVoteNode, RefreshNode);
476
- }
477
- if (msgAction.renderRight) {
478
- rightNodes = msgAction.renderRight(copyNode, referencesNode, UpVoteNode, DownVoteNode, RefreshNode);
479
- }
480
- }
481
- let index = recordRef.current.dataSource.findIndex((ite)=>ite.id == item.id);
482
- if (location === "bottom") {
483
- if (item.location === "left" && item.id !== "helloMsg" && item.id !== "inputing") {
484
- if (index === recordRef.current.dataSource.length - 1) {
485
- return /*#__PURE__*/ _jsxs("div", {
486
- className: `${getCls("msgItem-action")}`,
487
- children: [
488
- /*#__PURE__*/ _jsx("div", {
489
- className: `${getCls("msgItem-action-left")}`,
490
- children: leftNodes
491
- }),
492
- /*#__PURE__*/ _jsxs("div", {
493
- className: `${getCls("msgItem-action-right")}`,
494
- children: [
495
- RefreshNode,
496
- rightNodes
497
- ]
498
- })
499
- ]
500
- });
501
- }
502
- }
503
- // 只有最后一条才显示底部操作啦 且是左侧消息 且不是招呼语
504
- }
505
- if (location === "floatTop" || location === "floatBottom") {
506
- if (item.location === "left" && item.id !== "helloMsg" && item.id !== "inputing" && index === recordRef.current.dataSource.length - 1) return null;
507
- // 浮框
508
- return /*#__PURE__*/ _jsx("div", {
509
- className: `${getCls("msgItem-action-operate")}`,
510
- children: /*#__PURE__*/ _jsxs("div", {
511
- className: `${getCls("msgItem-action")} ${getCls("msgItem-action-popover")} ${getCls("msgItem-action-popover-" + location)}`,
512
- children: [
513
- /*#__PURE__*/ _jsx("div", {
514
- className: `${getCls("msgItem-action-left")}`,
515
- children: leftNodes
516
- }),
517
- /*#__PURE__*/ _jsx("div", {
518
- className: `${getCls("msgItem-action-right")}`,
519
- children: rightNodes
520
- })
521
- ]
522
- })
523
- });
524
- }
525
- return null;
526
- };
527
- const markToHtml = (markStr, id)=>{
528
- let html = remarkable.render(markStr);
529
- let position = 0;
530
- html = html.replace(new RegExp(`<pre`, "ig"), ()=>{
531
- position++;
532
- return `<p class='${getCls("copyCode")} ${styles.copyCodeFun}' data-id=${id} data-position=${position}>
533
- <span class='${getCls("icon")} ${getCls("copy")}'>
534
- <svg
535
- width="1em"
536
- height="1em"
537
- viewBox="0 0 14 14"
538
- shape-rendering="geometricPrecision"
539
- fill="currentColor"
540
- xmlns="http://www.w3.org/2000/svg"
541
- >
542
- <g clip-path="url(#clip0_518_8403)">
543
- <path
544
- 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"
545
- />
546
- </g>
547
- <defs>
548
- <clipPath id="clip0_518_8403">
549
- <rect width="16" height="16" />
550
- </clipPath>
551
- </defs>
552
- </svg>
553
- </span>
554
- <span class='${getCls("icon")} ${getCls("copy_success_flag")}'>
555
- <svg
556
- width="1em"
557
- height="1em"
558
- shape-rendering="geometricPrecision"
559
- fill="currentColor"
560
- viewBox="0 0 12 7"
561
- xmlns="http://www.w3.org/2000/svg"
562
- >
563
- <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" />
564
- </svg>
565
- </span><span class="${getCls("copyCodeText")}">复制代码</span></p><pre`;
566
- });
567
- return html;
568
- };
569
- const renderTime = (item)=>{
570
- // 生成缓存键
571
- const cacheKey = `${item.id}`;
572
- // 检查缓存中是否已有结果
573
- if (timeRenderCache.has(cacheKey)) {
574
- return timeRenderCache.get(cacheKey);
575
- }
576
- let index = recordRef.current.dataSource.findIndex((i)=>i.id === item.id);
577
- let timeObj = parseDate(item.createTime);
578
- let time = null;
579
- if (index === 0) {
580
- // 第一项 显示年月日 时分
581
- time = `${timeObj.year}-${timeObj.month}-${timeObj.day} ${timeObj.hours}:${timeObj.minutes}`;
582
- } else {
583
- // 非第一项 与上一项进行对比
584
- const prevItem = recordRef.current.dataSource[index - 1];
585
- if (prevItem) {
586
- let beforeTime = prevItem.createTime;
587
- let beforeTimeObj = parseDate(beforeTime);
588
- // 判断与上一条数据 是否跨天
589
- if (timeObj.year !== beforeTimeObj.year || timeObj.month !== beforeTimeObj.month || timeObj.day !== beforeTimeObj.day) {
590
- // 显示 年月日 时分
591
- time = `${timeObj.year}-${timeObj.month}-${timeObj.day} ${timeObj.hours}:${timeObj.minutes}`;
592
- } else {
593
- // 没有跨天 判断是否相隔超过10分钟
594
- if (timeObj.timestamp - beforeTimeObj.timestamp > 10 * 60 * 1000) {
595
- // 超过10分钟 显示 时分
596
- time = `${timeObj.hours}:${timeObj.minutes}`;
597
- }
598
- }
599
- }
600
- }
601
- const result = time ? /*#__PURE__*/ _jsx("div", {
602
- className: `${getCls("msg-date")}`,
603
- children: time
604
- }) : null;
605
- // 将结果存入缓存
606
- timeRenderCache.set(cacheKey, result);
607
- return result;
608
- };
609
- const findCopyContent = (e)=>{
610
- let source = findParent(e.target, styles.copyCode);
611
- if (!source) return;
612
- let id = source.getAttribute("data-id");
613
- let position = source.getAttribute("data-position");
614
- if (!id && !position) return;
615
- let message = "";
616
- recordRef.current.dataSource.forEach((item)=>{
617
- if (item.id === id) {
618
- message = item.content;
619
- }
620
- });
621
- if (!message) return;
622
- let codeConment = "";
623
- let i = 0;
624
- message.replaceAll(new RegExp(/```(?:.|\n)*?```/, "ig"), (con)=>{
625
- i++;
626
- if (i == position) {
627
- // 异常标记
628
- con = con.replace(/^```[\s\S]*?\n/, "").replace(/\n```$/, "");
629
- codeConment = con;
630
- return con;
631
- } else {
632
- return null;
633
- }
634
- });
635
- resetStyles();
636
- source.classList.add(styles.copy_success);
637
- source.children[2].innerText = "复制成功";
638
- copyText(codeConment);
639
- setTimeout(()=>{
640
- try {
641
- resetStyles();
642
- } catch (error) {}
643
- }, 3000);
644
- };
645
- //初始化样式
646
- const resetStyles = ()=>{
647
- let dom_list = document.getElementsByClassName(styles.copy_success);
648
- for(var i = 0; i < dom_list.length; i++){
649
- dom_list[i].classList.remove(styles.copy_success);
650
- }
651
- let dom_list2 = document.getElementsByClassName(styles.copyCodeFun);
652
- for(var i = 0; i < dom_list2.length; i++){
653
- let p = dom_list2[i].getElementsByClassName(styles.copyCodeText);
654
- p[0].innerText = "复制代码";
655
- }
656
- };
657
- const onScroll = ()=>{
658
- console.log("滚动滚动");
659
- };
660
- return /*#__PURE__*/ _jsx("div", {
661
- className: `${getCls("virtuosoList-wrapper")}`,
662
- ref: wrapperRef,
663
- children: /*#__PURE__*/ _jsx(Virtuoso, {
664
- ref: virtuosoRef,
665
- style: {
666
- height: "100%"
667
- },
668
- data: dataSource,
669
- initialTopMostItemIndex: {
670
- index: "LAST",
671
- align: "end"
672
- },
673
- startReached: loadMore,
674
- firstItemIndex: firstItemIndex,
675
- context: {
676
- loading,
677
- prefix
678
- },
679
- itemContent: itemContent,
680
- components: {
681
- Header: Header
682
- },
683
- increaseViewportBy: 200,
684
- overscan: 10,
685
- onScroll: onScroll
686
- })
687
- });
688
- });
689
- export default VirtuosoList;