bhd-components 0.10.4 → 0.10.5

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.
@@ -114,7 +114,11 @@ const Footer = /*#__PURE__*/ forwardRef((props, ref)=>{
114
114
  prefix: prefix,
115
115
  canSendMsg: canSendMsg,
116
116
  sending: sending,
117
- stopMessage: stopMessage
117
+ stopMessage: stopMessage,
118
+ clickFn: ()=>{
119
+ if (textValue.trim().length === 0) return;
120
+ sendMsg(textValue);
121
+ }
118
122
  });
119
123
  if (fileUpload) {
120
124
  let fileNode = /*#__PURE__*/ _jsx(UploadFileBtn, {
@@ -183,7 +187,7 @@ const Footer = /*#__PURE__*/ forwardRef((props, ref)=>{
183
187
  });
184
188
  sendMsgAjax();
185
189
  };
186
- const sendMsgAjax = async ()=>{
190
+ const sendMsgAjax = ()=>{
187
191
  const { url, method = "POST", headers = {}, params = ()=>"", onOpen = ()=>{}, onMessage = (ev)=>ev, onClose = ()=>{}, onError = ()=>{}, coverProps = {}, beforeSendMsg = ()=>Promise.resolve() } = sendMsgAjaxParams;
188
192
  ctrl.current = new AbortController();
189
193
  // apiRef
@@ -208,53 +212,56 @@ const Footer = /*#__PURE__*/ forwardRef((props, ref)=>{
208
212
  recordRef.current.referencesSource,
209
213
  fileListRef.current ? fileListRef.current.getFileList() : []
210
214
  ];
211
- let beforeInfo = await beforeSendMsg(...arg);
212
- fetchEventSource(url, _object_spread({
213
- method,
214
- headers: _object_spread({
215
- "Content-Type": "application/json",
216
- Accept: "text/event-stream,application/json"
217
- }, headers),
218
- body: params(...arg, beforeInfo),
219
- openWhenHidden: true,
220
- signal: ctrl.current.signal,
221
- onopen: (res)=>{
222
- onOpen(res);
223
- if (res.status === 200) {}
224
- return null;
225
- },
226
- onmessage: (ev)=>{
227
- let data = onMessage(ev);
228
- msgContent += data.content;
229
- delete data.content;
230
- recordMsgObj = _object_spread({
231
- createTime: createTime,
232
- content: msgContent,
233
- location: "left",
234
- reference: null,
235
- source: null
236
- }, data);
237
- updateMsgRef.current = setTimeout(()=>{
238
- apiRef.contentApi.updateMsg(msgId, recordMsgObj);
239
- msgId = data.id;
240
- }, 100);
241
- },
242
- onclose: ()=>{
243
- onClose();
244
- setSending(false);
245
- if (recordMsgObj.id) {
246
- apiRef.contentApi.recordMsg(recordMsgObj);
215
+ beforeSendMsg(...arg).then((beforeInfo)=>{
216
+ fetchEventSource(url, _object_spread({
217
+ method,
218
+ headers: _object_spread({
219
+ "Content-Type": "application/json",
220
+ Accept: "text/event-stream,application/json"
221
+ }, headers),
222
+ body: params(...arg, beforeInfo),
223
+ openWhenHidden: true,
224
+ signal: ctrl.current.signal,
225
+ onopen: (res)=>{
226
+ onOpen(res);
227
+ if (res.status === 200) {}
228
+ return null;
229
+ },
230
+ onmessage: (ev)=>{
231
+ let data = onMessage(ev);
232
+ msgContent += data.content;
233
+ delete data.content;
234
+ recordMsgObj = _object_spread({
235
+ createTime: createTime,
236
+ content: msgContent,
237
+ location: "left",
238
+ reference: null,
239
+ source: null
240
+ }, data);
241
+ updateMsgRef.current = setTimeout(()=>{
242
+ apiRef.contentApi.updateMsg(msgId, recordMsgObj);
243
+ msgId = data.id;
244
+ }, 100);
245
+ },
246
+ onclose: ()=>{
247
+ onClose();
248
+ setSending(false);
249
+ if (recordMsgObj.id) {
250
+ apiRef.contentApi.recordMsg(recordMsgObj);
251
+ }
252
+ console.log("onclose: ", recordMsgObj);
253
+ },
254
+ onerror: (err)=>{
255
+ onError(err);
256
+ if (recordMsgObj.id) {
257
+ apiRef.contentApi.recordMsg(recordMsgObj);
258
+ }
259
+ console.log("onerror: ", err);
247
260
  }
248
- console.log("onclose: ", recordMsgObj);
249
- },
250
- onerror: (err)=>{
251
- onError(err);
252
- if (recordMsgObj.id) {
253
- apiRef.contentApi.recordMsg(recordMsgObj);
254
- }
255
- console.log("onerror: ", err);
256
- }
257
- }, coverProps));
261
+ }, coverProps));
262
+ }).catch(()=>{
263
+ stopMessage();
264
+ });
258
265
  };
259
266
  // 判断是否超出最大字数
260
267
  const judegTextLengthWarn = ()=>{
@@ -23,7 +23,7 @@ const sendingSvg = /*#__PURE__*/ _jsx("svg", {
23
23
  })
24
24
  });
25
25
  const SendBtn = (props)=>{
26
- const { prefix, canSendMsg, sending, stopMessage } = props;
26
+ const { prefix, canSendMsg, sending, stopMessage, clickFn = ()=>{} } = props;
27
27
  const getCls = (clsName)=>{
28
28
  return styles[clsName] + " " + prefix + "-" + clsName;
29
29
  };
@@ -40,6 +40,11 @@ const SendBtn = (props)=>{
40
40
  }
41
41
  return /*#__PURE__*/ _jsx("i", {
42
42
  className: `${getCls("sendBtnIcon")} ${canSendMsg ? "" : getCls("disabled")}`,
43
+ onClick: ()=>{
44
+ if (canSendMsg) {
45
+ clickFn();
46
+ }
47
+ },
43
48
  children: sendBtnSvg
44
49
  });
45
50
  };
@@ -151,6 +151,7 @@ export interface sendBtnProps {
151
151
  canSendMsg: boolean;
152
152
  sending: boolean;
153
153
  stopMessage: () => void;
154
+ clickFn?: () => void;
154
155
  }
155
156
 
156
157
  // uploadFileBtn Props
@@ -1,8 +1,6 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
1
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
2
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
4
3
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
6
4
  import { jsx as _jsx, jsxs as _jsxs } from "@ice/jsx-runtime/jsx-runtime";
7
5
  import React, { useState, useEffect, useImperativeHandle, forwardRef, useRef, useMemo } from "react";
8
6
  import styles from "./index.module.less";
@@ -118,7 +116,11 @@ var Footer = /*#__PURE__*/ forwardRef(function(props, ref) {
118
116
  prefix: prefix,
119
117
  canSendMsg: canSendMsg,
120
118
  sending: sending,
121
- stopMessage: stopMessage
119
+ stopMessage: stopMessage,
120
+ clickFn: function() {
121
+ if (textValue.trim().length === 0) return;
122
+ sendMsg(textValue);
123
+ }
122
124
  });
123
125
  if (fileUpload) {
124
126
  var fileNode = /*#__PURE__*/ _jsx(UploadFileBtn, {
@@ -188,105 +190,89 @@ var Footer = /*#__PURE__*/ forwardRef(function(props, ref) {
188
190
  sendMsgAjax();
189
191
  };
190
192
  var sendMsgAjax = function() {
191
- var _ref = _async_to_generator(function() {
192
- var url, _sendMsgAjaxParams_method, method, _sendMsgAjaxParams_headers, headers, _sendMsgAjaxParams_params, params, _sendMsgAjaxParams_onOpen, onOpen, _sendMsgAjaxParams_onMessage, onMessage, _sendMsgAjaxParams_onClose, onClose, _sendMsgAjaxParams_onError, onError, _sendMsgAjaxParams_coverProps, coverProps, _sendMsgAjaxParams_beforeSendMsg, beforeSendMsg, msgId, createTime, msgContent, recordMsgObj, arg, beforeInfo;
193
- return _ts_generator(this, function(_state) {
194
- switch(_state.label){
195
- case 0:
196
- url = sendMsgAjaxParams.url, _sendMsgAjaxParams_method = sendMsgAjaxParams.method, method = _sendMsgAjaxParams_method === void 0 ? "POST" : _sendMsgAjaxParams_method, _sendMsgAjaxParams_headers = sendMsgAjaxParams.headers, headers = _sendMsgAjaxParams_headers === void 0 ? {} : _sendMsgAjaxParams_headers, _sendMsgAjaxParams_params = sendMsgAjaxParams.params, params = _sendMsgAjaxParams_params === void 0 ? function() {
197
- return "";
198
- } : _sendMsgAjaxParams_params, _sendMsgAjaxParams_onOpen = sendMsgAjaxParams.onOpen, onOpen = _sendMsgAjaxParams_onOpen === void 0 ? function() {} : _sendMsgAjaxParams_onOpen, _sendMsgAjaxParams_onMessage = sendMsgAjaxParams.onMessage, onMessage = _sendMsgAjaxParams_onMessage === void 0 ? function(ev) {
199
- return ev;
200
- } : _sendMsgAjaxParams_onMessage, _sendMsgAjaxParams_onClose = sendMsgAjaxParams.onClose, onClose = _sendMsgAjaxParams_onClose === void 0 ? function() {} : _sendMsgAjaxParams_onClose, _sendMsgAjaxParams_onError = sendMsgAjaxParams.onError, onError = _sendMsgAjaxParams_onError === void 0 ? function() {} : _sendMsgAjaxParams_onError, _sendMsgAjaxParams_coverProps = sendMsgAjaxParams.coverProps, coverProps = _sendMsgAjaxParams_coverProps === void 0 ? {} : _sendMsgAjaxParams_coverProps, _sendMsgAjaxParams_beforeSendMsg = sendMsgAjaxParams.beforeSendMsg, beforeSendMsg = _sendMsgAjaxParams_beforeSendMsg === void 0 ? function() {
201
- return Promise.resolve();
202
- } : _sendMsgAjaxParams_beforeSendMsg;
203
- ctrl.current = new AbortController();
204
- // apiRef
205
- console.log("apiRef", apiRef);
206
- msgId = "inputing";
207
- createTime = new Date().getTime();
208
- apiRef.contentApi.addMsg({
209
- id: msgId,
210
- createTime: createTime,
211
- content: "正在输入...",
212
- location: "left",
213
- reference: null,
214
- source: null
215
- });
216
- msgContent = "";
217
- setSending(true);
218
- setTextValue("");
219
- setReferencesSource(null);
220
- recordMsgObj = {};
221
- arg = [
222
- recordRef.current.value,
223
- recordRef.current.referencesSource,
224
- fileListRef.current ? fileListRef.current.getFileList() : []
225
- ];
226
- return [
227
- 4,
228
- beforeSendMsg.apply(void 0, _to_consumable_array(arg))
229
- ];
230
- case 1:
231
- beforeInfo = _state.sent();
232
- fetchEventSource(url, _object_spread({
233
- method: method,
234
- headers: _object_spread({
235
- "Content-Type": "application/json",
236
- Accept: "text/event-stream,application/json"
237
- }, headers),
238
- body: params.apply(void 0, _to_consumable_array(arg).concat([
239
- beforeInfo
240
- ])),
241
- openWhenHidden: true,
242
- signal: ctrl.current.signal,
243
- onopen: function(res) {
244
- onOpen(res);
245
- if (res.status === 200) {}
246
- return null;
247
- },
248
- onmessage: function(ev) {
249
- var data = onMessage(ev);
250
- msgContent += data.content;
251
- delete data.content;
252
- recordMsgObj = _object_spread({
253
- createTime: createTime,
254
- content: msgContent,
255
- location: "left",
256
- reference: null,
257
- source: null
258
- }, data);
259
- updateMsgRef.current = setTimeout(function() {
260
- apiRef.contentApi.updateMsg(msgId, recordMsgObj);
261
- msgId = data.id;
262
- }, 100);
263
- },
264
- onclose: function() {
265
- onClose();
266
- setSending(false);
267
- if (recordMsgObj.id) {
268
- apiRef.contentApi.recordMsg(recordMsgObj);
269
- }
270
- console.log("onclose: ", recordMsgObj);
271
- },
272
- onerror: function(err) {
273
- onError(err);
274
- if (recordMsgObj.id) {
275
- apiRef.contentApi.recordMsg(recordMsgObj);
276
- }
277
- console.log("onerror: ", err);
278
- }
279
- }, coverProps));
280
- return [
281
- 2
282
- ];
193
+ var url = sendMsgAjaxParams.url, _sendMsgAjaxParams_method = sendMsgAjaxParams.method, method = _sendMsgAjaxParams_method === void 0 ? "POST" : _sendMsgAjaxParams_method, _sendMsgAjaxParams_headers = sendMsgAjaxParams.headers, headers = _sendMsgAjaxParams_headers === void 0 ? {} : _sendMsgAjaxParams_headers, _sendMsgAjaxParams_params = sendMsgAjaxParams.params, params = _sendMsgAjaxParams_params === void 0 ? function() {
194
+ return "";
195
+ } : _sendMsgAjaxParams_params, _sendMsgAjaxParams_onOpen = sendMsgAjaxParams.onOpen, onOpen = _sendMsgAjaxParams_onOpen === void 0 ? function() {} : _sendMsgAjaxParams_onOpen, _sendMsgAjaxParams_onMessage = sendMsgAjaxParams.onMessage, onMessage = _sendMsgAjaxParams_onMessage === void 0 ? function(ev) {
196
+ return ev;
197
+ } : _sendMsgAjaxParams_onMessage, _sendMsgAjaxParams_onClose = sendMsgAjaxParams.onClose, onClose = _sendMsgAjaxParams_onClose === void 0 ? function() {} : _sendMsgAjaxParams_onClose, _sendMsgAjaxParams_onError = sendMsgAjaxParams.onError, onError = _sendMsgAjaxParams_onError === void 0 ? function() {} : _sendMsgAjaxParams_onError, _sendMsgAjaxParams_coverProps = sendMsgAjaxParams.coverProps, coverProps = _sendMsgAjaxParams_coverProps === void 0 ? {} : _sendMsgAjaxParams_coverProps, _sendMsgAjaxParams_beforeSendMsg = sendMsgAjaxParams.beforeSendMsg, beforeSendMsg = _sendMsgAjaxParams_beforeSendMsg === void 0 ? function() {
198
+ return Promise.resolve();
199
+ } : _sendMsgAjaxParams_beforeSendMsg;
200
+ ctrl.current = new AbortController();
201
+ // apiRef
202
+ console.log("apiRef", apiRef);
203
+ var msgId = "inputing";
204
+ var createTime = new Date().getTime();
205
+ apiRef.contentApi.addMsg({
206
+ id: msgId,
207
+ createTime: createTime,
208
+ content: "正在输入...",
209
+ location: "left",
210
+ reference: null,
211
+ source: null
212
+ });
213
+ var msgContent = "";
214
+ setSending(true);
215
+ setTextValue("");
216
+ setReferencesSource(null);
217
+ var recordMsgObj = {};
218
+ var arg = [
219
+ recordRef.current.value,
220
+ recordRef.current.referencesSource,
221
+ fileListRef.current ? fileListRef.current.getFileList() : []
222
+ ];
223
+ beforeSendMsg.apply(void 0, _to_consumable_array(arg)).then(function(beforeInfo) {
224
+ fetchEventSource(url, _object_spread({
225
+ method: method,
226
+ headers: _object_spread({
227
+ "Content-Type": "application/json",
228
+ Accept: "text/event-stream,application/json"
229
+ }, headers),
230
+ body: params.apply(void 0, _to_consumable_array(arg).concat([
231
+ beforeInfo
232
+ ])),
233
+ openWhenHidden: true,
234
+ signal: ctrl.current.signal,
235
+ onopen: function(res) {
236
+ onOpen(res);
237
+ if (res.status === 200) {}
238
+ return null;
239
+ },
240
+ onmessage: function(ev) {
241
+ var data = onMessage(ev);
242
+ msgContent += data.content;
243
+ delete data.content;
244
+ recordMsgObj = _object_spread({
245
+ createTime: createTime,
246
+ content: msgContent,
247
+ location: "left",
248
+ reference: null,
249
+ source: null
250
+ }, data);
251
+ updateMsgRef.current = setTimeout(function() {
252
+ apiRef.contentApi.updateMsg(msgId, recordMsgObj);
253
+ msgId = data.id;
254
+ }, 100);
255
+ },
256
+ onclose: function() {
257
+ onClose();
258
+ setSending(false);
259
+ if (recordMsgObj.id) {
260
+ apiRef.contentApi.recordMsg(recordMsgObj);
261
+ }
262
+ console.log("onclose: ", recordMsgObj);
263
+ },
264
+ onerror: function(err) {
265
+ onError(err);
266
+ if (recordMsgObj.id) {
267
+ apiRef.contentApi.recordMsg(recordMsgObj);
268
+ }
269
+ console.log("onerror: ", err);
283
270
  }
284
- });
271
+ }, coverProps));
272
+ }).catch(function() {
273
+ stopMessage();
285
274
  });
286
- return function sendMsgAjax() {
287
- return _ref.apply(this, arguments);
288
- };
289
- }();
275
+ };
290
276
  // 判断是否超出最大字数
291
277
  var judegTextLengthWarn = function() {
292
278
  if (typeof maxLength === "function") {
@@ -23,7 +23,7 @@ var sendingSvg = /*#__PURE__*/ _jsx("svg", {
23
23
  })
24
24
  });
25
25
  var SendBtn = function(props) {
26
- var prefix = props.prefix, canSendMsg = props.canSendMsg, sending = props.sending, stopMessage = props.stopMessage;
26
+ var prefix = props.prefix, canSendMsg = props.canSendMsg, sending = props.sending, stopMessage = props.stopMessage, _props_clickFn = props.clickFn, clickFn = _props_clickFn === void 0 ? function() {} : _props_clickFn;
27
27
  var getCls = function(clsName) {
28
28
  return styles[clsName] + " " + prefix + "-" + clsName;
29
29
  };
@@ -42,6 +42,11 @@ var SendBtn = function(props) {
42
42
  }
43
43
  return /*#__PURE__*/ _jsx("i", {
44
44
  className: "".concat(getCls("sendBtnIcon"), " ").concat(canSendMsg ? "" : getCls("disabled")),
45
+ onClick: function() {
46
+ if (canSendMsg) {
47
+ clickFn();
48
+ }
49
+ },
45
50
  children: sendBtnSvg
46
51
  });
47
52
  };
@@ -151,6 +151,7 @@ export interface sendBtnProps {
151
151
  canSendMsg: boolean;
152
152
  sending: boolean;
153
153
  stopMessage: () => void;
154
+ clickFn?: () => void;
154
155
  }
155
156
 
156
157
  // uploadFileBtn Props
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bhd-components",
3
- "version": "0.10.4",
3
+ "version": "0.10.5",
4
4
  "description": "组件功能描述",
5
5
  "config": {
6
6
  "commitizen": {