bhd-components 0.10.12 → 0.10.13

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