@xapp/chat-widget 1.43.0 → 1.45.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/dist/index.js CHANGED
@@ -30447,15 +30447,16 @@ var TypingIndicator = function (_) {
30447
30447
  * Show the agent is typing (or the bot - for fun)
30448
30448
  */
30449
30449
  var TypingStatus = function (props) {
30450
- var agent_names = Object.values(props.agents)
30451
- .filter(function (agent) { return agent.typing; });
30450
+ var agent_names = Object.values(props.agents).filter(function (agent) { return agent.typing; });
30452
30451
  return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null, agent_names.map(function (agent) {
30453
- return (React__default$1["default"].createElement("div", { className: "chat-msg-container-wrapper", key: "typing-status-".concat(agent.user.nick) },
30452
+ var _a, _b;
30453
+ return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null, !props.textTypingStatusEnabled ? (React__default$1["default"].createElement("div", { className: "chat-msg-container-wrapper", key: "typing-status-".concat(agent.user.nick) },
30454
30454
  React__default$1["default"].createElement("div", { key: agent.user.nick, className: "chat-msg-container agent chat-typing-progress" },
30455
30455
  React__default$1["default"].createElement(ChatMessagePart, { user: agent.user, showAvatar: true },
30456
30456
  React__default$1["default"].createElement("div", { className: "chat-msg" },
30457
30457
  React__default$1["default"].createElement(ChatMessageBubble, { owner: "others", hasTail: true },
30458
- React__default$1["default"].createElement(TypingIndicator, null)))))));
30458
+ React__default$1["default"].createElement(TypingIndicator, null))))))) : (React__default$1["default"].createElement("div", { key: agent.user.nick, className: "chat-msg-agent-typing" }, (_b = (_a = agent.user) === null || _a === void 0 ? void 0 : _a.display_name) !== null && _b !== void 0 ? _b : "Bot",
30459
+ " is typing"))));
30459
30460
  })));
30460
30461
  };
30461
30462
 
@@ -30548,7 +30549,7 @@ var MessageList = function (props) {
30548
30549
  renderAll(),
30549
30550
  React__default$1["default"].createElement("div", { ref: messagesEndRef, style: { float: "left", clear: "both" } }),
30550
30551
  React__default$1["default"].createElement(QueuePosition, { position: queuePosition }),
30551
- React__default$1["default"].createElement(TypingStatus, { agents: agents })),
30552
+ React__default$1["default"].createElement(TypingStatus, { agents: agents, textTypingStatusEnabled: props.textTypingStatusEnabled })),
30552
30553
  React__default$1["default"].createElement(ChatChipsContainer, null)));
30553
30554
  };
30554
30555
 
@@ -30566,6 +30567,10 @@ var MinimizeButton = function (props) {
30566
30567
  return (React__default$1["default"].createElement("div", { id: "xapp-widget-minimize", className: "minimize-button ".concat(props.showInRight ? "positionRight" : ""), onClick: props.onClick }));
30567
30568
  };
30568
30569
 
30570
+ var RefreshButton = function (props) {
30571
+ return (React__default$1["default"].createElement("div", { id: "xapp-widget-refresh", className: "refresh-button ".concat(props.showInRight ? "positionRight" : props.showInLeft ? "positionLeft" : ""), onClick: props.onClick }));
30572
+ };
30573
+
30569
30574
  var DEFAULT_STATUS_CONFIG = {
30570
30575
  online: "Virtual Assistant",
30571
30576
  offline: "Leave us a message",
@@ -30582,12 +30587,15 @@ function getStatusText(status, config) {
30582
30587
  }
30583
30588
  }
30584
30589
  var StatusContainer = function (props) {
30585
- var _a;
30590
+ var _a, _b, _c, _d, _e, _f, _g;
30586
30591
  return (React__default$1["default"].createElement("div", { className: "status-container" },
30587
30592
  React__default$1["default"].createElement("div", { className: "status-container__avatar" },
30588
30593
  React__default$1["default"].createElement(Avatar, { entity: props.agent })),
30589
- React__default$1["default"].createElement("div", { className: "status-text" },
30590
- React__default$1["default"].createElement("span", null, getStatusText(props.accountStatus, (_a = props.config) === null || _a === void 0 ? void 0 : _a.status))),
30594
+ React__default$1["default"].createElement("div", { className: "".concat("status-text", " ").concat(((_a = props.config) === null || _a === void 0 ? void 0 : _a.alignTextCenter) ? "status-text-positionCenter" : "status-text-positionLeft") },
30595
+ React__default$1["default"].createElement("span", { className: "status-text-title" }, getStatusText(props.accountStatus, (_b = props.config) === null || _b === void 0 ? void 0 : _b.status)),
30596
+ ((_d = (_c = props.config) === null || _c === void 0 ? void 0 : _c.subtitle) === null || _d === void 0 ? void 0 : _d.enabled) && React__default$1["default"].createElement("span", { className: "status-text-subtitle" }, (_g = (_f = (_e = props.config) === null || _e === void 0 ? void 0 : _e.subtitle) === null || _f === void 0 ? void 0 : _f.text) !== null && _g !== void 0 ? _g : "")),
30597
+ props.canRefresh &&
30598
+ React__default$1["default"].createElement(RefreshButton, { onClick: props.refreshOnClick, showInLeft: props.canMinimize && props.canCancel, showInRight: !props.canMinimize && !props.canCancel }),
30591
30599
  props.canMinimize &&
30592
30600
  React__default$1["default"].createElement(MinimizeButton, { onClick: props.minimizeOnClick, showInRight: !props.canCancel }),
30593
30601
  props.canCancel &&
@@ -30595,8 +30603,8 @@ var StatusContainer = function (props) {
30595
30603
  };
30596
30604
 
30597
30605
  function buildStyleContent(theme) {
30598
- var _a, _b, _c, _d;
30599
- return "\n:root {\n".concat(buildVariables(withPrefix("\t--xapp-", union(single("primary-color", theme === null || theme === void 0 ? void 0 : theme.primaryColor), withPrefix("widget-", union(getSize(theme === null || theme === void 0 ? void 0 : theme.size), getMargins(theme === null || theme === void 0 ? void 0 : theme.margin), getBorderStyle(theme === null || theme === void 0 ? void 0 : theme.border))), getChatButtonStyle(theme === null || theme === void 0 ? void 0 : theme.chatButton), withPrefix("header-", getHeaderStyle(theme === null || theme === void 0 ? void 0 : theme.header)), withPrefix("footer-", getFooterStyle(theme === null || theme === void 0 ? void 0 : theme.footer)), withPrefix("content-", union(getBackgroundStyle((_a = theme === null || theme === void 0 ? void 0 : theme.content) === null || _a === void 0 ? void 0 : _a.background))), withPrefix("messages-", getMessagesStyle(theme === null || theme === void 0 ? void 0 : theme.messages)), withPrefix("send-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.sendButton)), withPrefix("menu-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.menuButton)), withPrefix("menu-", getMenuStyle(theme === null || theme === void 0 ? void 0 : theme.menu)), withPrefix("minimize-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.minimizeButton)), withPrefix("cancel-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.cancelButton)), withPrefix("carousel-", union(withPrefix("title-", getTextStyle((_b = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _b === void 0 ? void 0 : _b.title)), withPrefix("subtitle-", getTextStyle((_c = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _c === void 0 ? void 0 : _c.subtitle)), withPrefix("action-", getButtonStyle((_d = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _d === void 0 ? void 0 : _d.button)))), withPrefix("input-", getInputStyle(theme === null || theme === void 0 ? void 0 : theme.input)), withPrefix("cta-", getCtaStyle(theme === null || theme === void 0 ? void 0 : theme.cta))))), "\n}");
30606
+ var _a, _b, _c, _d, _e;
30607
+ return "\n:root {\n".concat(buildVariables(withPrefix("\t--xapp-", union(single("primary-color", theme === null || theme === void 0 ? void 0 : theme.primaryColor), withPrefix("widget-", union(getSize(theme === null || theme === void 0 ? void 0 : theme.size), getMargins(theme === null || theme === void 0 ? void 0 : theme.margin), getBorderStyle(theme === null || theme === void 0 ? void 0 : theme.border), getZIndex(theme === null || theme === void 0 ? void 0 : theme.zIndex))), getChatButtonStyle(theme === null || theme === void 0 ? void 0 : theme.chatButton), withPrefix("header-", getHeaderStyle(theme === null || theme === void 0 ? void 0 : theme.header)), withPrefix("footer-", getFooterStyle(theme === null || theme === void 0 ? void 0 : theme.footer)), withPrefix("content-", union(getBackgroundStyle((_a = theme === null || theme === void 0 ? void 0 : theme.content) === null || _a === void 0 ? void 0 : _a.background))), withPrefix("messages-", getMessagesStyle(theme === null || theme === void 0 ? void 0 : theme.messages)), withPrefix("text-typing-status-", getTextStyle((_b = theme === null || theme === void 0 ? void 0 : theme.textTypingStatus) === null || _b === void 0 ? void 0 : _b.text)), withPrefix("send-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.sendButton)), withPrefix("menu-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.menuButton)), withPrefix("menu-", getMenuStyle(theme === null || theme === void 0 ? void 0 : theme.menu)), withPrefix("refresh-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.refreshButton)), withPrefix("minimize-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.minimizeButton)), withPrefix("cancel-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.cancelButton)), withPrefix("carousel-", union(withPrefix("title-", getTextStyle((_c = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _c === void 0 ? void 0 : _c.title)), withPrefix("subtitle-", getTextStyle((_d = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _d === void 0 ? void 0 : _d.subtitle)), withPrefix("action-", getButtonStyle((_e = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _e === void 0 ? void 0 : _e.button)))), withPrefix("input-", getInputStyle(theme === null || theme === void 0 ? void 0 : theme.input)), withPrefix("cta-", getCtaStyle(theme === null || theme === void 0 ? void 0 : theme.cta))))), "\n}");
30600
30608
  }
30601
30609
  function WidgetStylesheet(props) {
30602
30610
  var theme = props.theme;
@@ -30706,6 +30714,19 @@ function getSize(style) {
30706
30714
  }
30707
30715
  });
30708
30716
  }
30717
+ function getZIndex(style) {
30718
+ return __generator$1(this, function (_a) {
30719
+ switch (_a.label) {
30720
+ case 0:
30721
+ if (!style) return [3 /*break*/, 2];
30722
+ return [4 /*yield*/, ['z-index', style]];
30723
+ case 1:
30724
+ _a.sent();
30725
+ _a.label = 2;
30726
+ case 2: return [2 /*return*/];
30727
+ }
30728
+ });
30729
+ }
30709
30730
  function getMargins(style) {
30710
30731
  return __generator$1(this, function (_a) {
30711
30732
  switch (_a.label) {
@@ -30824,7 +30845,7 @@ function getHeaderStyle(style) {
30824
30845
  if (!style) {
30825
30846
  return empty();
30826
30847
  }
30827
- return union(getBackgroundStyle(style.background), getTextStyle(style.text), getBorderStyle(style.border));
30848
+ return union(getBackgroundStyle(style.background), getTextStyle(style.text), withPrefix("subtitle-", getTextStyle(style.subtitle)), getBorderStyle(style.border));
30828
30849
  }
30829
30850
  function getFooterStyle(style) {
30830
30851
  var _a;
@@ -30875,7 +30896,7 @@ var ChatWidgetWrapper = function (props) {
30875
30896
  React__default$1["default"].createElement(ChatWidget, __assign({}, props)))));
30876
30897
  };
30877
30898
  var ChatWidget = function (props) {
30878
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
30899
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
30879
30900
  var innerDispatch = useChatDispatch();
30880
30901
  var dispatch = useChatServerDispatch();
30881
30902
  // From Redux
@@ -30884,18 +30905,19 @@ var ChatWidget = function (props) {
30884
30905
  var dockedMode = mode === "docked";
30885
30906
  var staticMode = mode === "static";
30886
30907
  var modeClass = "widget-container--".concat(mode);
30887
- var canMinimize = !dockedMode && !staticMode && ((_c = (_b = props.config.header) === null || _b === void 0 ? void 0 : _b.actions) === null || _c === void 0 ? void 0 : _c.minimize);
30908
+ var canRefresh = (_c = (_b = props.config.header) === null || _b === void 0 ? void 0 : _b.actions) === null || _c === void 0 ? void 0 : _c.refresh;
30909
+ var canMinimize = !dockedMode && !staticMode && ((_e = (_d = props.config.header) === null || _d === void 0 ? void 0 : _d.actions) === null || _e === void 0 ? void 0 : _e.minimize);
30888
30910
  var canCancel;
30889
30911
  // To preserve legacy behavior, cancel needs a little more checks
30890
- if (typeof ((_e = (_d = props.config.header) === null || _d === void 0 ? void 0 : _d.actions) === null || _e === void 0 ? void 0 : _e.cancel) === "boolean") {
30891
- canCancel = !dockedMode && !staticMode && ((_g = (_f = props.config.header) === null || _f === void 0 ? void 0 : _f.actions) === null || _g === void 0 ? void 0 : _g.cancel);
30912
+ if (typeof ((_g = (_f = props.config.header) === null || _f === void 0 ? void 0 : _f.actions) === null || _g === void 0 ? void 0 : _g.cancel) === "boolean") {
30913
+ canCancel = !dockedMode && !staticMode && ((_j = (_h = props.config.header) === null || _h === void 0 ? void 0 : _h.actions) === null || _j === void 0 ? void 0 : _j.cancel);
30892
30914
  }
30893
30915
  else {
30894
30916
  canCancel = !dockedMode && !staticMode;
30895
30917
  }
30896
30918
  // Our state - pull from storage
30897
- var _p = React$1.useState((!canMinimize && !canCancel) || !!get("visible") || (((_h = props.config) === null || _h === void 0 ? void 0 : _h.autoOpenOnWidth) && window.matchMedia("(min-width: ".concat((_j = props.config) === null || _j === void 0 ? void 0 : _j.autoOpenOnWidth, ")")).matches)), visible = _p[0], setVisibleState = _p[1];
30898
- var _q = React$1.useState(false), typing = _q[0], setTypingState = _q[1]; // false initially
30919
+ var _t = React$1.useState((!canMinimize && !canCancel) || !!get("visible") || (((_k = props.config) === null || _k === void 0 ? void 0 : _k.autoOpenOnWidth) && window.matchMedia("(min-width: ".concat((_l = props.config) === null || _l === void 0 ? void 0 : _l.autoOpenOnWidth, ")")).matches)), visible = _t[0], setVisibleState = _t[1];
30920
+ var _u = React$1.useState(false), typing = _u[0], setTypingState = _u[1]; // false initially
30899
30921
  var chatServer = React$1.useContext(ChatServerContext);
30900
30922
  var setVisible = React$1.useCallback(function (newVisible) {
30901
30923
  if (staticMode) {
@@ -30961,6 +30983,9 @@ var ChatWidget = function (props) {
30961
30983
  function getVisibilityClass() {
30962
30984
  return visible ? "visible" : "";
30963
30985
  }
30986
+ function refreshOnClick() {
30987
+ innerDispatch(reset());
30988
+ }
30964
30989
  function minimizeOnClick() {
30965
30990
  set$1("opened", false);
30966
30991
  setVisible(false);
@@ -31014,17 +31039,17 @@ var ChatWidget = function (props) {
31014
31039
  onConnectionStatusChange(connectionStatus);
31015
31040
  }
31016
31041
  }, [connectionStatus, onConnectionStatusChange]);
31017
- useExternalScript((_k = props.config) === null || _k === void 0 ? void 0 : _k.middlewareUrl);
31042
+ useExternalScript((_m = props.config) === null || _m === void 0 ? void 0 : _m.middlewareUrl);
31018
31043
  return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null,
31019
31044
  React__default$1["default"].createElement("div", { className: "widget-container ".concat(modeClass, " ").concat(getVisibilityClass()) },
31020
31045
  React__default$1["default"].createElement(WidgetStylesheet, { theme: config === null || config === void 0 ? void 0 : config.theme }),
31021
- React__default$1["default"].createElement(StatusContainer, { accountStatus: chatState.accountStatus, minimizeOnClick: minimizeOnClick, cancelOnClick: cancelOnClick, agent: (_l = chatState.agents["agent:robot"]) === null || _l === void 0 ? void 0 : _l.user, canMinimize: canMinimize, canCancel: canCancel, config: config === null || config === void 0 ? void 0 : config.header }),
31022
- React__default$1["default"].createElement(MessageList, { visible: visible, queuePosition: chatState.queuePosition, isChatting: chatState.isChatting, isOffline: isOffline, messages: messages, agents: chatState.agents, lastRatingRequestTimestamp: chatState.lastRatingRequestTimestamp, hasRating: chatState.hasRating, visitorId: chatState.visitorId, messageMiddleware: props.messageMiddleware, onSend: handleSendMessage, onWrite: handleWriteMessage, onOpenUrl: handleOpenUrl }),
31046
+ React__default$1["default"].createElement(StatusContainer, { accountStatus: chatState.accountStatus, refreshOnClick: refreshOnClick, minimizeOnClick: minimizeOnClick, cancelOnClick: cancelOnClick, agent: (_o = chatState.agents["agent:robot"]) === null || _o === void 0 ? void 0 : _o.user, canRefresh: canRefresh, canMinimize: canMinimize, canCancel: canCancel, config: config === null || config === void 0 ? void 0 : config.header }),
31047
+ React__default$1["default"].createElement(MessageList, { visible: visible, queuePosition: chatState.queuePosition, isChatting: chatState.isChatting, isOffline: isOffline, messages: messages, agents: chatState.agents, lastRatingRequestTimestamp: chatState.lastRatingRequestTimestamp, hasRating: chatState.hasRating, visitorId: chatState.visitorId, messageMiddleware: props.messageMiddleware, textTypingStatusEnabled: (_q = (_p = props.config) === null || _p === void 0 ? void 0 : _p.typingStatus) === null || _q === void 0 ? void 0 : _q.textTypingStatusEnabled, onSend: handleSendMessage, onWrite: handleWriteMessage, onOpenUrl: handleOpenUrl }),
31023
31048
  React__default$1["default"].createElement("div", { className: "spinner-container ".concat(visible && connectionStatus === "pending" ? "visible" : "") },
31024
31049
  React__default$1["default"].createElement("div", { className: "spinner" })),
31025
31050
  connectionStatus === "offline" && React__default$1["default"].createElement(ServerOffline, null),
31026
- React__default$1["default"].createElement(ChatFooter, { isChatting: chatState.isChatting, placeholder: (_m = config === null || config === void 0 ? void 0 : config.input) === null || _m === void 0 ? void 0 : _m.placeholder, visible: visible, onChange: handleOnChange, onSubmit: handleOnSubmit, onFileUpload: handleFileUpload })),
31027
- React__default$1["default"].createElement(ChatButton, { addClass: getVisibilityClass(), onClick: chatButtonOnClick, config: (_o = props.config) === null || _o === void 0 ? void 0 : _o.cta, visible: visible })));
31051
+ React__default$1["default"].createElement(ChatFooter, { isChatting: chatState.isChatting, placeholder: (_r = config === null || config === void 0 ? void 0 : config.input) === null || _r === void 0 ? void 0 : _r.placeholder, visible: visible, onChange: handleOnChange, onSubmit: handleOnSubmit, onFileUpload: handleFileUpload })),
31052
+ React__default$1["default"].createElement(ChatButton, { addClass: getVisibilityClass(), onClick: chatButtonOnClick, config: (_s = props.config) === null || _s === void 0 ? void 0 : _s.cta, visible: visible })));
31028
31053
  };
31029
31054
 
31030
31055
  function tryParseJson(str) {