@xapp/chat-widget 1.63.0 → 1.64.2

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/dist/index.js CHANGED
@@ -719,10 +719,11 @@ var ChatButton = function (_a) {
719
719
  var onClick = _a.onClick, addClass = _a.addClass, config = _a.config, visible = _a.visible, borderStyle = _a.borderStyle, imageUrl = _a.imageUrl;
720
720
  var _c = React$1.useState(defaultWidgetButtonWidth), buttonWidth = _c[0], setButtonWidth = _c[1];
721
721
  var _d = React$1.useState(false), animate = _d[0], setAnimate = _d[1];
722
- var mobileWidht = ((_b = config === null || config === void 0 ? void 0 : config.mobile) === null || _b === void 0 ? void 0 : _b.applyAtLessThanWidth) || defaultNonMobileScreenWidth;
722
+ var mobileWidth = ((_b = config === null || config === void 0 ? void 0 : config.mobile) === null || _b === void 0 ? void 0 : _b.applyAtLessThanWidth) || defaultNonMobileScreenWidth;
723
+ // Determines mobile or normal
723
724
  var getConfigToApply = function () {
724
725
  var screenWidth = window.innerWidth;
725
- if (screenWidth <= parseInt(mobileWidht, 10) && (config === null || config === void 0 ? void 0 : config.mobile)) {
726
+ if (screenWidth <= parseInt(mobileWidth, 10) && (config === null || config === void 0 ? void 0 : config.mobile)) {
726
727
  return config.mobile;
727
728
  }
728
729
  else {
@@ -731,27 +732,44 @@ var ChatButton = function (_a) {
731
732
  };
732
733
  var configToApply = getConfigToApply();
733
734
  React$1.useEffect(function () {
734
- if ((configToApply === null || configToApply === void 0 ? void 0 : configToApply.delay) && (configToApply === null || configToApply === void 0 ? void 0 : configToApply.timeout)) {
735
- var delayTimer_1 = setTimeout(function () {
735
+ var delayTimer;
736
+ var timeoutTimer;
737
+ if (configToApply === null || configToApply === void 0 ? void 0 : configToApply.delay) {
738
+ // Set a delay for the animation to start
739
+ delayTimer = setTimeout(function () {
736
740
  setAnimate(true);
737
- var timeoutTimer = setTimeout(function () {
738
- setAnimate(false);
739
- }, configToApply.timeout);
740
- return function () {
741
- clearTimeout(timeoutTimer);
742
- };
741
+ if (configToApply.animationTimeout) {
742
+ // Stop the animation after the specified timeout
743
+ timeoutTimer = setTimeout(function () {
744
+ setAnimate(false);
745
+ }, configToApply.animationTimeout);
746
+ }
743
747
  }, configToApply.delay);
744
- return function () {
745
- clearTimeout(delayTimer_1);
746
- };
747
748
  }
748
- return function () { };
749
- }, [configToApply]);
749
+ else if (configToApply === null || configToApply === void 0 ? void 0 : configToApply.animationTimeout) {
750
+ // Start animation immediately and set a timeout to stop it
751
+ setAnimate(true);
752
+ timeoutTimer = setTimeout(function () {
753
+ setAnimate(false);
754
+ }, configToApply.animationTimeout);
755
+ }
756
+ else {
757
+ // No delay or timeout, start animation immediately
758
+ setAnimate(true);
759
+ }
760
+ return function () {
761
+ // Clear timers on unmount or when dependencies change
762
+ if (delayTimer)
763
+ clearTimeout(delayTimer);
764
+ if (timeoutTimer)
765
+ clearTimeout(timeoutTimer);
766
+ };
767
+ }, [configToApply, setAnimate]);
750
768
  var animation = animate ? ((configToApply === null || configToApply === void 0 ? void 0 : configToApply.animation) || "wiggle") : "none";
751
769
  React$1.useEffect(function () {
752
770
  var handleResize = function () {
753
771
  var screenWidth = window.innerWidth;
754
- var newButtonWidth = screenWidth < (parseInt(mobileWidht, 10))
772
+ var newButtonWidth = screenWidth < (parseInt(mobileWidth, 10))
755
773
  ? defaultMobileWidgetButtonWidth : defaultWidgetButtonWidth;
756
774
  setButtonWidth(newButtonWidth);
757
775
  };
@@ -760,7 +778,7 @@ var ChatButton = function (_a) {
760
778
  return function () {
761
779
  window.removeEventListener('resize', handleResize);
762
780
  };
763
- }, [mobileWidht]);
781
+ }, [mobileWidth]);
764
782
  var maxSvgSize = 22;
765
783
  var svgSize = Math.min(maxSvgSize, (+buttonWidth / +defaultWidgetButtonWidth) * maxSvgSize);
766
784
  return (React__default$1["default"].createElement("button", { "aria-label": "open chat", className: "xapp-chat-button ".concat(addClass || "").trim(), onClick: onClick },
@@ -30766,16 +30784,16 @@ var MessageList = function (props) {
30766
30784
  switch (msg.type) {
30767
30785
  case "chat.file":
30768
30786
  case "chat.msg":
30769
- return (React__default$1["default"].createElement(ChatMessage, { key: msg.type + msg.timestamp, message: msg, sibling: sibling, agent: user, messageMiddleware: props.messageMiddleware, middlewareContext: ctxCache.resolve(user) }));
30787
+ return (React__default$1["default"].createElement(ChatMessage, { key: "cm-".concat(msg.type, "-").concat(msg.timestamp), message: msg, sibling: sibling, agent: user, messageMiddleware: props.messageMiddleware, middlewareContext: ctxCache.resolve(user) }));
30770
30788
  case "chat.failureMsg":
30771
- return (React__default$1["default"].createElement(FailureMessage, __assign({ key: msg.type + msg.timestamp, agents: props.agents, time: time }, msg.failureMsg)));
30789
+ return (React__default$1["default"].createElement(FailureMessage, __assign({ key: "fm-".concat(msg.type, "-").concat(msg.timestamp), agents: props.agents, time: time }, msg.failureMsg)));
30772
30790
  case "chat.memberjoin":
30773
30791
  case "chat.memberleave":
30774
30792
  case "chat.rating":
30775
30793
  case "chat.typing":
30776
- return (React__default$1["default"].createElement(SystemMessage, { key: msg.type + msg.timestamp, time: time, message: msg }));
30794
+ return (React__default$1["default"].createElement(SystemMessage, { key: "sm-".concat(msg.type, "-").concat(msg.timestamp), time: time, message: msg }));
30777
30795
  case "chat.request.rating":
30778
- return (React__default$1["default"].createElement(ChatRatingContainer, { key: msg.type + msg.timestamp, agent: user, hasRating: props.hasRating, time: time, shouldDisplay: msg.timestamp === props.lastRatingRequestTimestamp }));
30796
+ return (React__default$1["default"].createElement(ChatRatingContainer, { key: "cr-".concat(msg.type, "-").concat(msg.timestamp), agent: user, hasRating: props.hasRating, time: time, shouldDisplay: msg.timestamp === props.lastRatingRequestTimestamp }));
30779
30797
  case "chat.offline":
30780
30798
  return React__default$1["default"].createElement(OfflineFormContainer, { key: "offline-".concat(msg.timestamp), time: time });
30781
30799
  case "chat.prechat":
@@ -30783,7 +30801,7 @@ var MessageList = function (props) {
30783
30801
  default:
30784
30802
  return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null,
30785
30803
  React__default$1["default"].createElement("span", { className: "message-sr-only" }, "at " + time + " system message"),
30786
- React__default$1["default"].createElement("div", { key: +new Date() },
30804
+ React__default$1["default"].createElement("div", { key: "uhm-".concat(+new Date()) },
30787
30805
  "Unhandled message: ",
30788
30806
  JSON.stringify(msg))));
30789
30807
  }