bhd-components 0.10.7 → 0.10.8

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.
@@ -16,6 +16,7 @@ import CopyIcon from "../copyIcon";
16
16
  import ReferencesIcon from "../referencesIcon";
17
17
  import { UpVoteBtn, DownVoteBtn } from "../remarkBtn";
18
18
  import RefreshBtn from "../refreshBtn";
19
+ import { fileIconRender } from "../fileList/fileIcon";
19
20
  var Header = function(param) {
20
21
  var context = param.context;
21
22
  var prefix = context.prefix, loading = context.loading;
@@ -49,15 +50,16 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
49
50
  var getList = contentConfig.getList, coverRenderText = contentConfig.coverRenderText, _contentConfig_msgAction = contentConfig.msgAction, msgAction = _contentConfig_msgAction === void 0 ? [
50
51
  "copy",
51
52
  "references"
52
- ] : _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;
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, iconFileRender = contentConfig.iconFileRender;
53
54
  var loadMoreProps = contentConfig.loadMore || true;
54
55
  var virtuosoRef = useRef(null);
55
56
  var _useState = _sliced_to_array(useState(false), 2), loading = _useState[0], setLoading = _useState[1]; // 是否加载中
56
57
  var _useState1 = _sliced_to_array(useState([]), 2), dataSource = _useState1[0], setDataSource = _useState1[1];
57
58
  var _useState2 = _sliced_to_array(useState(0), 2), firstItemIndex = _useState2[0], setFirstItemIndex = _useState2[1];
58
59
  var _useState3 = _sliced_to_array(useState(1), 2), page = _useState3[0], setPage = _useState3[1];
59
- var _useState4 = _sliced_to_array(useState(contentConfig.pageSize || 30), 2), pageSize = _useState4[0], setPageSize = _useState4[1];
60
- var _useState5 = _sliced_to_array(useState(0), 2), total = _useState5[0], setTotal = _useState5[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];
61
63
  var timerRef = useRef({
62
64
  loadMore: null,
63
65
  scrollTimer: null
@@ -68,7 +70,8 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
68
70
  pageSize: pageSize,
69
71
  total: total,
70
72
  dataSource: dataSource,
71
- maxPage: Math.ceil(total / pageSize)
73
+ maxPage: Math.ceil(total / pageSize),
74
+ sendingId: ""
72
75
  });
73
76
  var timeRenderCache = useRef(new Map()).current;
74
77
  var htmlRenderCache = useRef(new Map()).current;
@@ -84,6 +87,9 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
84
87
  msg
85
88
  ]);
86
89
  });
90
+ timerRef.current.scrollTimer = setTimeout(function() {
91
+ scrollToBottom();
92
+ }, 100);
87
93
  },
88
94
  updateMsg: function(id, obj) {
89
95
  setDataSource(function(data) {
@@ -121,12 +127,9 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
121
127
  changeDataSource: function(data) {
122
128
  setDataSource(data);
123
129
  },
124
- scrollToBottom: function scrollToBottom() {
125
- if (!virtuosoRef.current) return;
126
- virtuosoRef.current.scrollToIndex({
127
- index: "LAST",
128
- behavior: "auto"
129
- });
130
+ scrollToBottom: scrollToBottom,
131
+ setSendingId: function(id) {
132
+ setSendingId(id);
130
133
  }
131
134
  };
132
135
  });
@@ -164,12 +167,21 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
164
167
  recordRef.current.total = total;
165
168
  recordRef.current.dataSource = dataSource;
166
169
  recordRef.current.maxPage = Math.ceil(total / pageSize);
170
+ recordRef.current.sendingId = sendingId;
167
171
  }, [
168
172
  page,
169
173
  pageSize,
170
174
  total,
171
- dataSource
175
+ dataSource,
176
+ sendingId
172
177
  ]);
178
+ var scrollToBottom = function() {
179
+ if (!virtuosoRef.current) return;
180
+ virtuosoRef.current.scrollToIndex({
181
+ index: "LAST",
182
+ behavior: "auto"
183
+ });
184
+ };
173
185
  var getData = function(page, pageSize) {
174
186
  setLoading(true);
175
187
  clearTimeout(timerRef.current.loadMore);
@@ -201,18 +213,7 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
201
213
  ]);
202
214
  var itemContent = function(index, item) {
203
215
  var timeNode = renderTime(item);
204
- var cahceKey = item.id + "-" + item.content;
205
216
  var contentNode = null;
206
- // if (htmlRenderCache.has(cahceKey)) {
207
- // contentNode = htmlRenderCache.get(cahceKey);
208
- // } else {
209
- // const html = markToHtml(item.content, item.id);
210
- // contentNode = <div dangerouslySetInnerHTML={{ __html: html }}></div>;
211
- // if (coverRenderText) {
212
- // contentNode = coverRenderText(item, html);
213
- // }
214
- // htmlRenderCache.set(cahceKey, contentNode);
215
- // }
216
217
  var html = markToHtml(item.content, item.id);
217
218
  contentNode = /*#__PURE__*/ _jsx("div", {
218
219
  dangerouslySetInnerHTML: {
@@ -222,6 +223,32 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
222
223
  if (coverRenderText) {
223
224
  contentNode = coverRenderText(item, html);
224
225
  }
226
+ // item.type = "file";
227
+ // item.suffix = "docx";
228
+ // item.fileTitle = "这是一个文件名称.docx";
229
+ // item.fileSize = "5Mb";
230
+ if (item.type === "file") {
231
+ contentNode = /*#__PURE__*/ _jsxs("div", {
232
+ className: "".concat(getCls("msgItem-file")),
233
+ children: [
234
+ /*#__PURE__*/ _jsx("div", {
235
+ className: "".concat(getCls("msgItem-file-left")),
236
+ children: fileIconRender(item.suffix, iconFileRender)
237
+ }),
238
+ /*#__PURE__*/ _jsxs("div", {
239
+ className: "".concat(getCls("msgItem-file-right")),
240
+ children: [
241
+ /*#__PURE__*/ _jsx("p", {
242
+ children: item.fileTitle
243
+ }),
244
+ /*#__PURE__*/ _jsx("p", {
245
+ children: item.fileSize
246
+ })
247
+ ]
248
+ })
249
+ ]
250
+ });
251
+ }
225
252
  // 是否显示时间
226
253
  var itemNode = /*#__PURE__*/ _jsx("div", {
227
254
  className: "".concat(getCls("msgItem"), " ").concat(item.location === "left" ? getCls("msgItem-left") : getCls("msgItem-right")),
@@ -321,6 +348,7 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
321
348
  topDom.style.cssText = "";
322
349
  };
323
350
  var renderAction = function(location, item) {
351
+ if (item.id === "inputing" || item.id === "helloMsg" || item.id === recordRef.current.sendingId) return null;
324
352
  var copyNode = /*#__PURE__*/ _jsx(CopyIcon, {
325
353
  prefix: prefix,
326
354
  content: item.content
@@ -334,6 +362,7 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
334
362
  prefix: prefix,
335
363
  isActive: item.vote === "up",
336
364
  clickFn: function() {
365
+ onVoteChange(item.vote === "up" ? "" : "up", item);
337
366
  setDataSource(function(data) {
338
367
  return data.map(function(ite) {
339
368
  if (item.id === ite.id) {
@@ -342,13 +371,13 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
342
371
  return ite;
343
372
  });
344
373
  });
345
- onVoteChange(item.vote === "up" ? "" : "up", item);
346
374
  }
347
375
  });
348
376
  var DownVoteNode = /*#__PURE__*/ _jsx(DownVoteBtn, {
349
377
  prefix: prefix,
350
378
  isActive: item.vote === "down",
351
379
  clickFn: function() {
380
+ onVoteChange(item.vote === "down" ? "" : "down", item);
352
381
  setDataSource(function(data) {
353
382
  return data.map(function(ite) {
354
383
  if (item.id === ite.id) {
@@ -357,7 +386,6 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
357
386
  return ite;
358
387
  });
359
388
  });
360
- onVoteChange(item.vote === "down" ? "" : "down", item);
361
389
  }
362
390
  });
363
391
  var RefreshNode = /*#__PURE__*/ _jsx(RefreshBtn, {
@@ -370,6 +398,12 @@ var VirtuosoList = /*#__PURE__*/ forwardRef(function(props, ref) {
370
398
  UpVoteNode = null;
371
399
  DownVoteNode = null;
372
400
  }
401
+ if (item.type === "file") {
402
+ copyNode = null;
403
+ UpVoteNode = null;
404
+ DownVoteNode = null;
405
+ RefreshNode = null;
406
+ }
373
407
  var leftNodes = null;
374
408
  var rightNodes = /*#__PURE__*/ _jsxs(_Fragment, {
375
409
  children: [
@@ -71,11 +71,11 @@
71
71
  text-align: right;
72
72
  height: 37px;
73
73
  line-height: 37px;
74
- padding: 0 ;
75
- padding-right: 16px ;
74
+ padding: 0;
75
+ padding-right: 16px;
76
76
  position: relative;
77
77
  cursor: pointer;
78
- font-weight: 400 ;
78
+ font-weight: 400;
79
79
  top: 6px;
80
80
  &.copyCodeFun {
81
81
  display: flex;
@@ -266,6 +266,41 @@
266
266
  border-radius: 0 0 4px 4px;
267
267
  }
268
268
  }
269
+ .msgItem-file {
270
+ display: flex;
271
+ align-items: center;
272
+ padding: 8px 12px;
273
+ background: #fafafa;
274
+ border-radius: 8px;
275
+ border: 1px solid #ebebeb;
276
+ gap: 12px;
277
+ .msgItem-file-left{
278
+ font-size: 24px;
279
+ display: flex;
280
+ justify-content: center;
281
+ align-items: center;
282
+ padding: 0;
283
+ margin: 0;
284
+ &>i{
285
+ display: flex;
286
+ font-size: 24px;
287
+ }
288
+ }
289
+ .msgItem-file-right{
290
+ font-size: 14px;
291
+ font-weight: 400;
292
+ color: rgba(0, 0, 0, 0.65);
293
+ &>p{
294
+ &:nth-child(1){
295
+ margin-bottom: 4px;
296
+ }
297
+ &:nth-child(2){
298
+ font-size: 12px;
299
+ color: rgba(0, 0, 0, 0.25);
300
+ }
301
+ }
302
+ }
303
+ }
269
304
  }
270
305
  .msgItem-action {
271
306
  border-top: 1px solid rgba(0, 0, 0, 0.06);
@@ -62,6 +62,7 @@ export interface contentConfigProps {
62
62
  onRecordMessage?: (item: dataItemType) => void; // 发送和接收的消息记录
63
63
  onVoteChange?: (type:string,item: dataItemType) => void; // 点赞 或踩
64
64
  onRefresh?: (item:dataItemType) => void;// 刷新
65
+ iconFileRender?: (suffix: string) => React.ReactNode; // 文件上传的 icon。参数 文件对象file 返回值为图标
65
66
  }
66
67
 
67
68
  // content props
@@ -271,6 +272,7 @@ export interface VirtuosoListRefProps {
271
272
  upateDataSource:(id:string,obj:dataItemType)=>void;
272
273
  changeDataSource:(list:dataItemType[])=>void;
273
274
  scrollToBottom: () => void;
275
+ setSendingId:(id:string)=>void;
274
276
  }
275
277
 
276
278
  export interface contentRefProps extends VirtuosoListRefProps {}
@@ -290,4 +292,9 @@ export interface dataItemType {
290
292
  reference: referenceType | null; // 引用数据
291
293
  source: any; //原消息对象
292
294
  vote?:string;// "up":点赞。"down":踩
295
+ type?:"file"|"text",
296
+ suffix?:string;
297
+ fileSize?:string;
298
+ fileTitle?:string;
299
+ fileList?:fileCustomProps[];
293
300
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bhd-components",
3
- "version": "0.10.7",
3
+ "version": "0.10.8",
4
4
  "description": "组件功能描述",
5
5
  "config": {
6
6
  "commitizen": {