@botonic/react 0.20.8 → 0.21.0
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.
- package/lib/components/image.js +3 -3
- package/lib/components/image.js.map +1 -1
- package/lib/components/index.d.ts +2 -2
- package/lib/components/message.js +3 -1
- package/lib/components/message.js.map +1 -1
- package/lib/components/timestamps.js +4 -1
- package/lib/components/timestamps.js.map +1 -1
- package/lib/index.d.ts +6 -5
- package/lib/webchat/components/emoji-picker.js +6 -1
- package/lib/webchat/components/emoji-picker.js.map +1 -1
- package/lib/webchat/devices/scrollbar-controller.js +1 -1
- package/lib/webchat/devices/scrollbar-controller.js.map +1 -1
- package/lib/webchat/hooks.js +1 -1
- package/lib/webchat/hooks.js.map +1 -1
- package/lib/webchat/use-storage-state-hook.js +47 -16
- package/lib/webchat/use-storage-state-hook.js.map +1 -1
- package/lib/webchat/webchat.js +135 -68
- package/lib/webchat/webchat.js.map +1 -1
- package/lib/webchat-app.js +13 -6
- package/lib/webchat-app.js.map +1 -1
- package/lib/webview.js +41 -25
- package/lib/webview.js.map +1 -1
- package/package.json +2 -2
- package/src/components/message.jsx +3 -1
- package/src/webchat/components/emoji-picker.jsx +14 -7
- package/src/webchat/devices/scrollbar-controller.js +4 -1
- package/src/webchat/hooks.js +1 -1
- package/src/webchat/webchat.jsx +49 -1
package/lib/webchat/webchat.js
CHANGED
|
@@ -181,10 +181,10 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
181
181
|
customComponent = _useState2[0],
|
|
182
182
|
setCustomComponent = _useState2[1];
|
|
183
183
|
|
|
184
|
-
var storage = props.storage
|
|
184
|
+
var storage = props.storage;
|
|
185
185
|
var storageKey = typeof props.storageKey === 'function' ? props.storageKey() : props.storageKey;
|
|
186
186
|
|
|
187
|
-
var _useStorageState = (0, _useStorageStateHook.useStorageState)(storage, storageKey
|
|
187
|
+
var _useStorageState = (0, _useStorageStateHook.useStorageState)(storage, storageKey),
|
|
188
188
|
_useStorageState2 = (0, _slicedToArray2["default"])(_useStorageState, 2),
|
|
189
189
|
botonicState = _useStorageState2[0],
|
|
190
190
|
saveState = _useStorageState2[1];
|
|
@@ -244,6 +244,38 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
244
244
|
return function sendUserInput(_x) {
|
|
245
245
|
return _ref2.apply(this, arguments);
|
|
246
246
|
};
|
|
247
|
+
}();
|
|
248
|
+
|
|
249
|
+
var sendChatEvent = /*#__PURE__*/function () {
|
|
250
|
+
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(chatEvent) {
|
|
251
|
+
var chatEventInput;
|
|
252
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
253
|
+
while (1) {
|
|
254
|
+
switch (_context2.prev = _context2.next) {
|
|
255
|
+
case 0:
|
|
256
|
+
chatEventInput = {
|
|
257
|
+
id: (0, _uuid.v4)(),
|
|
258
|
+
type: _core.INPUT.CHAT_EVENT,
|
|
259
|
+
data: chatEvent
|
|
260
|
+
};
|
|
261
|
+
props.onUserInput && props.onUserInput({
|
|
262
|
+
user: webchatState.session.user,
|
|
263
|
+
input: chatEventInput,
|
|
264
|
+
session: webchatState.session,
|
|
265
|
+
lastRoutePath: webchatState.lastRoutePath
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
case 2:
|
|
269
|
+
case "end":
|
|
270
|
+
return _context2.stop();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}, _callee2);
|
|
274
|
+
}));
|
|
275
|
+
|
|
276
|
+
return function sendChatEvent(_x2) {
|
|
277
|
+
return _ref3.apply(this, arguments);
|
|
278
|
+
};
|
|
247
279
|
}(); // Load styles stored in window._botonicInsertStyles by Webpack
|
|
248
280
|
|
|
249
281
|
|
|
@@ -291,13 +323,13 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
291
323
|
}); // Load initial state from storage
|
|
292
324
|
|
|
293
325
|
(0, _react.useEffect)(function () {
|
|
294
|
-
var
|
|
295
|
-
messages =
|
|
296
|
-
session =
|
|
297
|
-
lastRoutePath =
|
|
298
|
-
devSettings =
|
|
299
|
-
lastMessageUpdate =
|
|
300
|
-
themeUpdates =
|
|
326
|
+
var _ref4 = botonicState || {},
|
|
327
|
+
messages = _ref4.messages,
|
|
328
|
+
session = _ref4.session,
|
|
329
|
+
lastRoutePath = _ref4.lastRoutePath,
|
|
330
|
+
devSettings = _ref4.devSettings,
|
|
331
|
+
lastMessageUpdate = _ref4.lastMessageUpdate,
|
|
332
|
+
themeUpdates = _ref4.themeUpdates;
|
|
301
333
|
|
|
302
334
|
session = (0, _webchat.initSession)(session);
|
|
303
335
|
updateSession(session);
|
|
@@ -340,10 +372,10 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
340
372
|
if (onStateChange && typeof onStateChange === 'function') onStateChange(webchatState);
|
|
341
373
|
saveWebchatState(webchatState);
|
|
342
374
|
}, [webchatState.messagesJSON, webchatState.session, webchatState.lastRoutePath, webchatState.devSettings, webchatState.lastMessageUpdate]);
|
|
343
|
-
(0, _useAsyncEffect.useAsyncEffect)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
344
|
-
return _regenerator["default"].wrap(function
|
|
375
|
+
(0, _useAsyncEffect.useAsyncEffect)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
|
376
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
345
377
|
while (1) {
|
|
346
|
-
switch (
|
|
378
|
+
switch (_context3.prev = _context3.next) {
|
|
347
379
|
case 0:
|
|
348
380
|
if (!webchatState.online) {
|
|
349
381
|
setError({
|
|
@@ -357,10 +389,10 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
357
389
|
|
|
358
390
|
case 1:
|
|
359
391
|
case "end":
|
|
360
|
-
return
|
|
392
|
+
return _context3.stop();
|
|
361
393
|
}
|
|
362
394
|
}
|
|
363
|
-
},
|
|
395
|
+
}, _callee3);
|
|
364
396
|
})), [webchatState.online]);
|
|
365
397
|
(0, _hooks.useTyping)({
|
|
366
398
|
webchatState: webchatState,
|
|
@@ -511,34 +543,34 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
511
543
|
};
|
|
512
544
|
|
|
513
545
|
var sendInput = /*#__PURE__*/function () {
|
|
514
|
-
var
|
|
546
|
+
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(input) {
|
|
515
547
|
var messageComponent;
|
|
516
|
-
return _regenerator["default"].wrap(function
|
|
548
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
517
549
|
while (1) {
|
|
518
|
-
switch (
|
|
550
|
+
switch (_context4.prev = _context4.next) {
|
|
519
551
|
case 0:
|
|
520
552
|
if (!(!input || Object.keys(input).length == 0)) {
|
|
521
|
-
|
|
553
|
+
_context4.next = 2;
|
|
522
554
|
break;
|
|
523
555
|
}
|
|
524
556
|
|
|
525
|
-
return
|
|
557
|
+
return _context4.abrupt("return");
|
|
526
558
|
|
|
527
559
|
case 2:
|
|
528
560
|
if (!((0, _messageUtils.isText)(input) && (!input.data || !input.data.trim()))) {
|
|
529
|
-
|
|
561
|
+
_context4.next = 4;
|
|
530
562
|
break;
|
|
531
563
|
}
|
|
532
564
|
|
|
533
|
-
return
|
|
565
|
+
return _context4.abrupt("return");
|
|
534
566
|
|
|
535
567
|
case 4:
|
|
536
568
|
if (!((0, _messageUtils.isText)(input) && checkBlockInput(input))) {
|
|
537
|
-
|
|
569
|
+
_context4.next = 6;
|
|
538
570
|
break;
|
|
539
571
|
}
|
|
540
572
|
|
|
541
|
-
return
|
|
573
|
+
return _context4.abrupt("return");
|
|
542
574
|
|
|
543
575
|
case 6:
|
|
544
576
|
if (!input.id) input.id = (0, _uuid.v4)();
|
|
@@ -546,15 +578,15 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
546
578
|
if (messageComponent) addMessageComponent(messageComponent);
|
|
547
579
|
|
|
548
580
|
if (!(0, _messageUtils.isMedia)(input)) {
|
|
549
|
-
|
|
581
|
+
_context4.next = 13;
|
|
550
582
|
break;
|
|
551
583
|
}
|
|
552
584
|
|
|
553
|
-
|
|
585
|
+
_context4.next = 12;
|
|
554
586
|
return (0, _messageUtils.readDataURL)(input.data);
|
|
555
587
|
|
|
556
588
|
case 12:
|
|
557
|
-
input.data =
|
|
589
|
+
input.data = _context4.sent;
|
|
558
590
|
|
|
559
591
|
case 13:
|
|
560
592
|
sendUserInput(input);
|
|
@@ -566,14 +598,14 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
566
598
|
|
|
567
599
|
case 19:
|
|
568
600
|
case "end":
|
|
569
|
-
return
|
|
601
|
+
return _context4.stop();
|
|
570
602
|
}
|
|
571
603
|
}
|
|
572
|
-
},
|
|
604
|
+
}, _callee4);
|
|
573
605
|
}));
|
|
574
606
|
|
|
575
|
-
return function sendInput(
|
|
576
|
-
return
|
|
607
|
+
return function sendInput(_x3) {
|
|
608
|
+
return _ref6.apply(this, arguments);
|
|
577
609
|
};
|
|
578
610
|
}();
|
|
579
611
|
/* This is the public API this component exposes to its parents
|
|
@@ -589,10 +621,10 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
589
621
|
|
|
590
622
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
591
623
|
return {
|
|
592
|
-
addBotResponse: function addBotResponse(
|
|
593
|
-
var response =
|
|
594
|
-
session =
|
|
595
|
-
lastRoutePath =
|
|
624
|
+
addBotResponse: function addBotResponse(_ref7) {
|
|
625
|
+
var response = _ref7.response,
|
|
626
|
+
session = _ref7.session,
|
|
627
|
+
lastRoutePath = _ref7.lastRoutePath;
|
|
596
628
|
updateTyping(false);
|
|
597
629
|
if (Array.isArray(response)) response.map(function (r) {
|
|
598
630
|
return addMessageComponent(r);
|
|
@@ -692,18 +724,18 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
692
724
|
}, [webchatState.session._botonic_action]);
|
|
693
725
|
|
|
694
726
|
var sendText = /*#__PURE__*/function () {
|
|
695
|
-
var
|
|
727
|
+
var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(text, payload) {
|
|
696
728
|
var input;
|
|
697
|
-
return _regenerator["default"].wrap(function
|
|
729
|
+
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
698
730
|
while (1) {
|
|
699
|
-
switch (
|
|
731
|
+
switch (_context5.prev = _context5.next) {
|
|
700
732
|
case 0:
|
|
701
733
|
if (text) {
|
|
702
|
-
|
|
734
|
+
_context5.next = 2;
|
|
703
735
|
break;
|
|
704
736
|
}
|
|
705
737
|
|
|
706
|
-
return
|
|
738
|
+
return _context5.abrupt("return");
|
|
707
739
|
|
|
708
740
|
case 2:
|
|
709
741
|
input = {
|
|
@@ -711,84 +743,84 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
711
743
|
data: text,
|
|
712
744
|
payload: payload
|
|
713
745
|
};
|
|
714
|
-
|
|
746
|
+
_context5.next = 5;
|
|
715
747
|
return sendInput(input);
|
|
716
748
|
|
|
717
749
|
case 5:
|
|
718
750
|
case "end":
|
|
719
|
-
return
|
|
751
|
+
return _context5.stop();
|
|
720
752
|
}
|
|
721
753
|
}
|
|
722
|
-
},
|
|
754
|
+
}, _callee5);
|
|
723
755
|
}));
|
|
724
756
|
|
|
725
|
-
return function sendText(
|
|
726
|
-
return
|
|
757
|
+
return function sendText(_x4, _x5) {
|
|
758
|
+
return _ref8.apply(this, arguments);
|
|
727
759
|
};
|
|
728
760
|
}();
|
|
729
761
|
|
|
730
762
|
var sendPayload = /*#__PURE__*/function () {
|
|
731
|
-
var
|
|
763
|
+
var _ref9 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(payload) {
|
|
732
764
|
var input;
|
|
733
|
-
return _regenerator["default"].wrap(function
|
|
765
|
+
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
734
766
|
while (1) {
|
|
735
|
-
switch (
|
|
767
|
+
switch (_context6.prev = _context6.next) {
|
|
736
768
|
case 0:
|
|
737
769
|
if (payload) {
|
|
738
|
-
|
|
770
|
+
_context6.next = 2;
|
|
739
771
|
break;
|
|
740
772
|
}
|
|
741
773
|
|
|
742
|
-
return
|
|
774
|
+
return _context6.abrupt("return");
|
|
743
775
|
|
|
744
776
|
case 2:
|
|
745
777
|
input = {
|
|
746
778
|
type: _core.INPUT.POSTBACK,
|
|
747
779
|
payload: payload
|
|
748
780
|
};
|
|
749
|
-
|
|
781
|
+
_context6.next = 5;
|
|
750
782
|
return sendInput(input);
|
|
751
783
|
|
|
752
784
|
case 5:
|
|
753
785
|
case "end":
|
|
754
|
-
return
|
|
786
|
+
return _context6.stop();
|
|
755
787
|
}
|
|
756
788
|
}
|
|
757
|
-
},
|
|
789
|
+
}, _callee6);
|
|
758
790
|
}));
|
|
759
791
|
|
|
760
|
-
return function sendPayload(
|
|
761
|
-
return
|
|
792
|
+
return function sendPayload(_x6) {
|
|
793
|
+
return _ref9.apply(this, arguments);
|
|
762
794
|
};
|
|
763
795
|
}();
|
|
764
796
|
|
|
765
797
|
var sendAttachment = /*#__PURE__*/function () {
|
|
766
|
-
var
|
|
798
|
+
var _ref10 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(attachment) {
|
|
767
799
|
var attachmentType, input;
|
|
768
|
-
return _regenerator["default"].wrap(function
|
|
800
|
+
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
769
801
|
while (1) {
|
|
770
|
-
switch (
|
|
802
|
+
switch (_context7.prev = _context7.next) {
|
|
771
803
|
case 0:
|
|
772
804
|
if (!attachment.file) {
|
|
773
|
-
|
|
805
|
+
_context7.next = 8;
|
|
774
806
|
break;
|
|
775
807
|
}
|
|
776
808
|
|
|
777
809
|
attachmentType = (0, _messageUtils.getMediaType)(attachment.file.type);
|
|
778
810
|
|
|
779
811
|
if (attachmentType) {
|
|
780
|
-
|
|
812
|
+
_context7.next = 4;
|
|
781
813
|
break;
|
|
782
814
|
}
|
|
783
815
|
|
|
784
|
-
return
|
|
816
|
+
return _context7.abrupt("return");
|
|
785
817
|
|
|
786
818
|
case 4:
|
|
787
819
|
input = {
|
|
788
820
|
type: attachmentType,
|
|
789
821
|
data: attachment.file
|
|
790
822
|
};
|
|
791
|
-
|
|
823
|
+
_context7.next = 7;
|
|
792
824
|
return sendInput(input);
|
|
793
825
|
|
|
794
826
|
case 7:
|
|
@@ -796,14 +828,14 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
796
828
|
|
|
797
829
|
case 8:
|
|
798
830
|
case "end":
|
|
799
|
-
return
|
|
831
|
+
return _context7.stop();
|
|
800
832
|
}
|
|
801
833
|
}
|
|
802
|
-
},
|
|
834
|
+
}, _callee7);
|
|
803
835
|
}));
|
|
804
836
|
|
|
805
|
-
return function sendAttachment(
|
|
806
|
-
return
|
|
837
|
+
return function sendAttachment(_x7) {
|
|
838
|
+
return _ref10.apply(this, arguments);
|
|
807
839
|
};
|
|
808
840
|
}();
|
|
809
841
|
|
|
@@ -812,13 +844,47 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
812
844
|
textArea.current.value = '';
|
|
813
845
|
};
|
|
814
846
|
|
|
847
|
+
var isTyping = false;
|
|
848
|
+
var typingTimeout = null;
|
|
849
|
+
|
|
850
|
+
function clearTimeoutWithReset(reset) {
|
|
851
|
+
var waitTime = 20 * 1000;
|
|
852
|
+
if (typingTimeout) clearTimeout(typingTimeout);
|
|
853
|
+
if (reset) typingTimeout = setTimeout(stopTyping, waitTime);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
function startTyping() {
|
|
857
|
+
isTyping = true;
|
|
858
|
+
sendChatEvent('typing_on');
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
function stopTyping() {
|
|
862
|
+
clearTimeoutWithReset(false);
|
|
863
|
+
isTyping = false;
|
|
864
|
+
sendChatEvent('typing_off');
|
|
865
|
+
}
|
|
866
|
+
|
|
815
867
|
var _onKeyDown = function onKeyDown(event) {
|
|
816
|
-
if (event.keyCode
|
|
868
|
+
if (event.keyCode === 13 && event.shiftKey === false) {
|
|
817
869
|
event.preventDefault();
|
|
818
870
|
sendTextAreaText();
|
|
871
|
+
stopTyping();
|
|
819
872
|
}
|
|
820
873
|
};
|
|
821
874
|
|
|
875
|
+
var onKeyUp = function onKeyUp() {
|
|
876
|
+
if (textArea.current.value === '') {
|
|
877
|
+
stopTyping();
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if (!isTyping) {
|
|
882
|
+
startTyping();
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
clearTimeoutWithReset(true);
|
|
886
|
+
};
|
|
887
|
+
|
|
822
888
|
var webviewRequestContext = {
|
|
823
889
|
getString: function getString(stringId) {
|
|
824
890
|
return props.getString(stringId, webchatState.session);
|
|
@@ -940,6 +1006,7 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
940
1006
|
onKeyDown: function onKeyDown(e) {
|
|
941
1007
|
return _onKeyDown(e);
|
|
942
1008
|
},
|
|
1009
|
+
onKeyUp: onKeyUp,
|
|
943
1010
|
style: _objectSpread({
|
|
944
1011
|
display: 'flex',
|
|
945
1012
|
fontSize: deviceAdapter.fontSize(14),
|
|
@@ -1000,8 +1067,8 @@ var Webchat = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
1000
1067
|
}, [webchatState.messagesJSON]);
|
|
1001
1068
|
};
|
|
1002
1069
|
|
|
1003
|
-
var DarkenBackground = function DarkenBackground(
|
|
1004
|
-
var component =
|
|
1070
|
+
var DarkenBackground = function DarkenBackground(_ref11) {
|
|
1071
|
+
var component = _ref11.component;
|
|
1005
1072
|
return /*#__PURE__*/_react["default"].createElement("div", null, darkBackgroundMenu && /*#__PURE__*/_react["default"].createElement(DarkBackgroundMenu, {
|
|
1006
1073
|
style: {
|
|
1007
1074
|
borderRadius: webchatState.theme.style.borderRadius
|