@xapp/chat-widget 1.57.5 → 1.58.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
@@ -6694,7 +6694,7 @@ var ChatChipsContainer = function (_) {
6694
6694
  };
6695
6695
 
6696
6696
  var CancelButton = function (props) {
6697
- return (React__default$1["default"].createElement("button", { id: "xapp-widget-close", "aria-label": "close widget", "aria-hidden": true, tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, className: "cancel-button", onClick: props.onClick }));
6697
+ return (React__default$1["default"].createElement("button", { id: "xapp-widget-close", "aria-label": "close widget", "aria-hidden": false, tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, className: "cancel-button", onClick: props.onClick }));
6698
6698
  };
6699
6699
 
6700
6700
  var lib = {};
@@ -6830,15 +6830,15 @@ var DrawerBars = function (props) {
6830
6830
  }
6831
6831
  return barElements;
6832
6832
  }
6833
- return (React__default$1["default"].createElement("button", { className: "drawer-bars", tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, "aria-label": "open menu", "aria-hidden": true, onClick: props.onToggle }, getBars()));
6833
+ return (React__default$1["default"].createElement("button", { className: "drawer-bars", tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, "aria-label": "open menu", "aria-hidden": false, onClick: props.onToggle }, getBars()));
6834
6834
  };
6835
6835
 
6836
6836
  var MinimizeButton = function (props) {
6837
- return (React__default$1["default"].createElement("button", { id: "xapp-widget-minimize", "aria-label": "minimize widget", "aria-hidden": true, tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, className: "minimize-button ".concat(props.showInRight ? "positionRight" : ""), onClick: props.onClick }));
6837
+ return (React__default$1["default"].createElement("button", { id: "xapp-widget-minimize", "aria-label": "minimize widget", "aria-hidden": false, tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, className: "minimize-button ".concat(props.showInRight ? "positionRight" : ""), onClick: props.onClick }));
6838
6838
  };
6839
6839
 
6840
6840
  var RefreshButton = function (props) {
6841
- return (React__default$1["default"].createElement("button", { id: "xapp-widget-refresh", "aria-label": "refresh chat", "aria-hidden": true, tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, className: "refresh-button ".concat(props.showInRight ? "positionRight" : props.showInLeft ? "positionLeft" : ""), onClick: props.onClick }));
6841
+ return (React__default$1["default"].createElement("button", { id: "xapp-widget-refresh", "aria-label": "refresh chat", "aria-hidden": false, tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, className: "refresh-button ".concat(props.showInRight ? "positionRight" : props.showInLeft ? "positionLeft" : ""), onClick: props.onClick }));
6842
6842
  };
6843
6843
 
6844
6844
  var DEFAULT_STATUS_CONFIG = {
@@ -6885,8 +6885,19 @@ var ChatHeader = function (props) {
6885
6885
  setDrawerState(false);
6886
6886
  onSubmit(label);
6887
6887
  }
6888
+ var ariaLabel = "";
6889
+ var canRefresh = props.canRefresh, canMinimize = props.canMinimize, canCancel = props.canCancel;
6890
+ if (canRefresh) {
6891
+ ariaLabel = refreshButtonAriaLabel;
6892
+ }
6893
+ if (canMinimize) {
6894
+ ariaLabel = "".concat(ariaLabel).concat(minimizeButtonAriaLabel);
6895
+ }
6896
+ if (canCancel) {
6897
+ ariaLabel = "".concat(ariaLabel).concat(closeButtonAriaLabel);
6898
+ }
6888
6899
  return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null,
6889
- React__default$1["default"].createElement("div", { className: "status-container background-header", "aria-label": props.canRefresh ? refreshButtonAriaLabel : "" + props.canMinimize ? minimizeButtonAriaLabel : "" + props.canCancel ? closeButtonAriaLabel : "", "aria-hidden": true },
6900
+ React__default$1["default"].createElement("div", { className: "status-container background-header", "aria-label": ariaLabel, "aria-hidden": false },
6890
6901
  showMenu && menuItems.length ? (React__default$1["default"].createElement(React__default$1["default"].Fragment, null,
6891
6902
  React__default$1["default"].createElement("div", { className: "chat-footer__menu-icon" },
6892
6903
  React__default$1["default"].createElement(DrawerBars, { bars: 3, tabIndex: menuButtonTabIndex, onToggle: toggleDrawer })))) : React__default$1["default"].createElement(React__default$1["default"].Fragment, null),
@@ -7823,10 +7834,10 @@ var Input = function (props) {
7823
7834
  }, [suggestion, onChange, onSuggestionCommand]);
7824
7835
  return (React__default$1["default"].createElement("div", { className: "xappw-input-container ".concat(props.addClass, " ").concat(dragover ? "drag-drop-zone" : ""), "aria-label": "To start typing click on rounded rectangle at the bottom of widget. To send your message click icon on right side of rounded rectangle at the bottom of widget" +
7825
7836
  value.text
7826
- ? "To clear ipnut field click on clear icon on the left of send button"
7827
- : "", "aria-hidden": true, onDrop: onDrop, onDragOver: onDragOver, onDragLeave: onDragLeave },
7837
+ ? "To clear input field click on clear icon on the left of send button"
7838
+ : "", "aria-hidden": false, onDrop: onDrop, onDragOver: onDragOver, onDragLeave: onDragLeave },
7828
7839
  React__default$1["default"].createElement("form", { className: "xappw-input-form", onSubmit: handleOnSubmit },
7829
- React__default$1["default"].createElement(RichInput_1, { key: "input", id: "chatWidgetInput", className: "xappw-input", placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : "Type your question here...", tabIndex: inputConfig === null || inputConfig === void 0 ? void 0 : inputConfig.tabIndex, onInput: onChange, onChange: onChange, onKeyDown: handleKeyDown,
7840
+ React__default$1["default"].createElement(RichInput_1, { key: "input", id: "chatWidgetInput", className: "xappw-input", placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : "type your question here", tabIndex: inputConfig === null || inputConfig === void 0 ? void 0 : inputConfig.tabIndex, onInput: onChange, onChange: onChange, onKeyDown: handleKeyDown,
7830
7841
  // onFocus={onFocus}
7831
7842
  value: value, spellCheck: true }),
7832
7843
  React__default$1["default"].createElement("div", { className: "xappw-input-form__buttons" },
@@ -7937,7 +7948,7 @@ var ChatFooter = function (props) {
7937
7948
  setInput(data);
7938
7949
  setSuggestionSearch(data.text);
7939
7950
  }, []);
7940
- return (React__default$1["default"].createElement("div", { className: "chat-footer background-footer", "aria-label": menuItems.length ? "to open menu click a button above the rounded rectangle at the bottom of widget" : "", "aria-hidden": true },
7951
+ return (React__default$1["default"].createElement("div", { className: "chat-footer background-footer", "aria-label": menuItems.length ? "to open menu click a button above the rounded rectangle at the bottom of widget" : "", "aria-hidden": false },
7941
7952
  showMenu && menuItems.length ?
7942
7953
  React__default$1["default"].createElement(React__default$1["default"].Fragment, null,
7943
7954
  drawerOpen ? React__default$1["default"].createElement(ChatMenu, { opened: drawerOpen, tabIndex: menuItemsTabIndex, onItemClick: handleMenuItem, items: menuItems }) : React__default$1["default"].createElement(React__default$1["default"].Fragment, null),
@@ -30832,28 +30843,25 @@ var ChatWidgetWrapper = function (props) {
30832
30843
  React__default$1["default"].createElement(ChatWidget, __assign({}, props)))));
30833
30844
  };
30834
30845
  var ChatWidget = function (props) {
30835
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
30846
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
30836
30847
  var innerDispatch = useChatDispatch();
30837
30848
  var dispatch = useChatServerDispatch();
30838
30849
  // From Redux
30839
30850
  var chatState = reactRedux.useSelector(function (state) { return state; });
30851
+ // Refresh modalReference
30840
30852
  var modalRef = React$1.useRef({});
30841
- function openModal() {
30842
- modalRef.current.style.display = "block";
30843
- }
30844
- function closeModal() {
30845
- modalRef.current.style.display = "none";
30846
- }
30847
30853
  var mode = (_a = props.mode) !== null && _a !== void 0 ? _a : "normal";
30848
30854
  var dockedMode = mode === "docked";
30849
30855
  var staticMode = mode === "static";
30850
30856
  var modeClass = "widget-container--".concat(mode);
30851
30857
  var canRefresh = (_c = (_b = props.config.header) === null || _b === void 0 ? void 0 : _b.actions) === null || _c === void 0 ? void 0 : _c.refresh;
30858
+ // can't minimize in docked mode or static mode.
30852
30859
  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);
30860
+ console.log("".concat(dockedMode, " ").concat(staticMode, " ").concat((_g = (_f = props.config.header) === null || _f === void 0 ? void 0 : _f.actions) === null || _g === void 0 ? void 0 : _g.minimize));
30853
30861
  var canCancel;
30854
30862
  // To preserve legacy behavior, cancel needs a little more checks
30855
- if (typeof ((_g = (_f = props.config.header) === null || _f === void 0 ? void 0 : _f.actions) === null || _g === void 0 ? void 0 : _g.cancel) === "boolean") {
30856
- canCancel = !dockedMode && !staticMode && ((_j = (_h = props.config.header) === null || _h === void 0 ? void 0 : _h.actions) === null || _j === void 0 ? void 0 : _j.cancel);
30863
+ if (typeof ((_j = (_h = props.config.header) === null || _h === void 0 ? void 0 : _h.actions) === null || _j === void 0 ? void 0 : _j.cancel) === "boolean") {
30864
+ canCancel = !dockedMode && !staticMode && ((_l = (_k = props.config.header) === null || _k === void 0 ? void 0 : _k.actions) === null || _l === void 0 ? void 0 : _l.cancel);
30857
30865
  }
30858
30866
  else {
30859
30867
  canCancel = !dockedMode && !staticMode;
@@ -30863,18 +30871,18 @@ var ChatWidget = function (props) {
30863
30871
  chatState.visuals = {};
30864
30872
  }
30865
30873
  // Our state - pull from storage
30866
- var _1 = React$1.useState((!canMinimize && !canCancel) ||
30874
+ var _3 = React$1.useState((!canMinimize && !canCancel) ||
30867
30875
  // !!get("visible") ||
30868
30876
  chatState.visuals.visible ||
30869
- (((_k = props.config) === null || _k === void 0 ? void 0 : _k.autoOpenOnWidth) &&
30870
- window.matchMedia("(min-width: ".concat((_l = props.config) === null || _l === void 0 ? void 0 : _l.autoOpenOnWidth, ")")).matches)), visible = _1[0], setVisibleState = _1[1];
30871
- var _2 = React$1.useState(false), typing = _2[0], setTypingState = _2[1]; // false initially
30877
+ (((_m = props.config) === null || _m === void 0 ? void 0 : _m.autoOpenOnWidth) &&
30878
+ window.matchMedia("(min-width: ".concat((_o = props.config) === null || _o === void 0 ? void 0 : _o.autoOpenOnWidth, ")")).matches)), visible = _3[0], setVisibleState = _3[1];
30879
+ var _4 = React$1.useState(false), typing = _4[0], setTypingState = _4[1]; // false initially
30872
30880
  var chatServer = React$1.useContext(ChatServerContext);
30873
- var patternsConfig = (_o = (_m = props.config) === null || _m === void 0 ? void 0 : _m.autoOpenOnPattern) === null || _o === void 0 ? void 0 : _o.patterns;
30881
+ var patternsConfig = (_q = (_p = props.config) === null || _p === void 0 ? void 0 : _p.autoOpenOnPattern) === null || _q === void 0 ? void 0 : _q.patterns;
30874
30882
  var currentUrl = window.location.href;
30875
30883
  var patternExist = patternsConfig && patternsConfig.length > 0;
30876
30884
  var patternMatches = patternsConfig === null || patternsConfig === void 0 ? void 0 : patternsConfig.some(function (pattern) { return currentUrl.includes(pattern); });
30877
- var configWidth = (_q = (_p = props.config) === null || _p === void 0 ? void 0 : _p.autoOpenOnPattern) === null || _q === void 0 ? void 0 : _q.minimumWidth;
30885
+ var configWidth = (_s = (_r = props.config) === null || _r === void 0 ? void 0 : _r.autoOpenOnPattern) === null || _s === void 0 ? void 0 : _s.minimumWidth;
30878
30886
  // eslint-disable-next-line no-restricted-globals
30879
30887
  var currentWidth = screen.width;
30880
30888
  var setVisible = React$1.useCallback(function (newVisible) {
@@ -30961,17 +30969,38 @@ var ChatWidget = function (props) {
30961
30969
  function getVisibilityClass() {
30962
30970
  return visible ? "visible" : "";
30963
30971
  }
30964
- function refreshOnClick() {
30965
- closeModal();
30972
+ function openRestartConfirmationModal() {
30973
+ // Interesting, this call the modalRef of the restart modal
30974
+ modalRef.current.style.display = "block";
30975
+ }
30976
+ function closeRestartConfirmationModal() {
30977
+ modalRef.current.style.display = "none";
30978
+ }
30979
+ function handleReset() {
30966
30980
  innerDispatch(reset());
30967
30981
  }
30968
- function minimizeOnClick() {
30982
+ function handleRestartClick() {
30983
+ if (config.header.actions.refreshShowConfirmation) {
30984
+ // show the modal
30985
+ openRestartConfirmationModal();
30986
+ // we will close when
30987
+ }
30988
+ else {
30989
+ handleReset();
30990
+ }
30991
+ }
30992
+ function handleRestartModalCloseClick() {
30993
+ closeRestartConfirmationModal();
30994
+ }
30995
+ /** Called when minimize button is clicked */
30996
+ function handleMinimizeClick() {
30969
30997
  innerDispatch(setVisualStatus({
30970
30998
  opened: false
30971
30999
  }));
30972
31000
  setVisible(false);
30973
31001
  }
30974
- function cancelOnClick() {
31002
+ /** Called when cancel is clicked */
31003
+ function handleCancelClick() {
30975
31004
  //set("opened", false);
30976
31005
  innerDispatch(setVisualStatus({
30977
31006
  opened: false
@@ -31030,22 +31059,22 @@ var ChatWidget = function (props) {
31030
31059
  onConnectionStatusChange(connectionStatus);
31031
31060
  }
31032
31061
  }, [connectionStatus, onConnectionStatusChange]);
31033
- useExternalScript((_r = props.config) === null || _r === void 0 ? void 0 : _r.middlewareUrl);
31062
+ useExternalScript((_t = props.config) === null || _t === void 0 ? void 0 : _t.middlewareUrl);
31034
31063
  // This is a pseudo agent. It represent's the widget (shown in the header avatar for instance)
31035
- var widgetAgent = ((_s = chatState.agents["agent:robot"]) === null || _s === void 0 ? void 0 : _s.user) || (config === null || config === void 0 ? void 0 : config.agent)
31064
+ var widgetAgent = ((_u = chatState.agents["agent:robot"]) === null || _u === void 0 ? void 0 : _u.user) || (config === null || config === void 0 ? void 0 : config.agent)
31036
31065
  || { nick: "agent:robot", avatarPath: config.avatarUrl, display_name: "Agent" };
31037
31066
  return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null,
31038
31067
  React__default$1["default"].createElement("div", { className: "widget-container ".concat(modeClass, " ").concat(getVisibilityClass()) },
31039
31068
  React__default$1["default"].createElement(WidgetStylesheet, { theme: config === null || config === void 0 ? void 0 : config.theme }),
31040
- React__default$1["default"].createElement(ChatHeader, { accountStatus: chatState.accountStatus, refreshOnClick: openModal, minimizeOnClick: minimizeOnClick, cancelOnClick: cancelOnClick, agent: widgetAgent, canRefresh: canRefresh, canMinimize: canMinimize, canCancel: canCancel, config: config === null || config === void 0 ? void 0 : config.header, menuConfig: config.menu, onSubmit: handleOnSubmit }),
31041
- React__default$1["default"].createElement(MessageList, { visible: visible, queuePosition: chatState.queuePosition, isChatting: chatState.isChatting, isOffline: isOffline, messages: messages, agents: chatState.agents, agent: config === null || config === void 0 ? void 0 : config.agent, lastRatingRequestTimestamp: chatState.lastRatingRequestTimestamp, hasRating: chatState.hasRating, visitorId: chatState.visitorId, messageMiddleware: props.messageMiddleware, textTypingStatusEnabled: (_u = (_t = props.config) === null || _t === void 0 ? void 0 : _t.typingStatus) === null || _u === void 0 ? void 0 : _u.textTypingStatusEnabled, onSend: handleSendMessage, onWrite: handleWriteMessage, onOpenUrl: handleOpenUrl }),
31069
+ React__default$1["default"].createElement(ChatHeader, { accountStatus: chatState.accountStatus, refreshOnClick: handleRestartClick, minimizeOnClick: handleMinimizeClick, cancelOnClick: handleCancelClick, agent: widgetAgent, canRefresh: canRefresh, canMinimize: canMinimize, canCancel: canCancel, config: config === null || config === void 0 ? void 0 : config.header, menuConfig: config.menu, onSubmit: handleOnSubmit }),
31070
+ React__default$1["default"].createElement(MessageList, { visible: visible, queuePosition: chatState.queuePosition, isChatting: chatState.isChatting, isOffline: isOffline, messages: messages, agents: chatState.agents, agent: config === null || config === void 0 ? void 0 : config.agent, lastRatingRequestTimestamp: chatState.lastRatingRequestTimestamp, hasRating: chatState.hasRating, visitorId: chatState.visitorId, messageMiddleware: props.messageMiddleware, textTypingStatusEnabled: (_w = (_v = props.config) === null || _v === void 0 ? void 0 : _v.typingStatus) === null || _w === void 0 ? void 0 : _w.textTypingStatusEnabled, onSend: handleSendMessage, onWrite: handleWriteMessage, onOpenUrl: handleOpenUrl }),
31042
31071
  React__default$1["default"].createElement("div", { className: "xa-spinner-container ".concat(visible && connectionStatus === "pending" ? "visible" : "") },
31043
31072
  React__default$1["default"].createElement("div", { className: "xa-spinner" })),
31044
31073
  connectionStatus === "offline" && React__default$1["default"].createElement(ServerOffline, null),
31045
- React__default$1["default"].createElement(ChatFooter, { isAdmin: config === null || config === void 0 ? void 0 : config.isAdmin, isChatting: chatState.isChatting, placeholder: (_v = config === null || config === void 0 ? void 0 : config.input) === null || _v === void 0 ? void 0 : _v.placeholder, sendButtonIcon: (_x = (_w = config === null || config === void 0 ? void 0 : config.footer) === null || _w === void 0 ? void 0 : _w.sendButton) === null || _x === void 0 ? void 0 : _x.icon, visible: visible, menuConfig: props.config.menu, footerConfig: (_y = props.config) === null || _y === void 0 ? void 0 : _y.footer, inputConfig: (_z = props.config) === null || _z === void 0 ? void 0 : _z.input, onChange: handleOnChange, onSubmit: handleOnSubmit, onFileUpload: handleFileUpload }),
31046
- React__default$1["default"].createElement("div", { className: "restartModal", ref: modalRef, onClick: closeModal },
31047
- React__default$1["default"].createElement(ModalContent, { onClose: closeModal, onReset: refreshOnClick }))),
31048
- React__default$1["default"].createElement(ChatButton, { addClass: getVisibilityClass(), onClick: chatButtonOnClick, config: (_0 = props.config) === null || _0 === void 0 ? void 0 : _0.cta, visible: visible })));
31074
+ React__default$1["default"].createElement(ChatFooter, { isAdmin: config === null || config === void 0 ? void 0 : config.isAdmin, isChatting: chatState.isChatting, placeholder: (_x = config === null || config === void 0 ? void 0 : config.input) === null || _x === void 0 ? void 0 : _x.placeholder, sendButtonIcon: (_z = (_y = config === null || config === void 0 ? void 0 : config.footer) === null || _y === void 0 ? void 0 : _y.sendButton) === null || _z === void 0 ? void 0 : _z.icon, visible: visible, menuConfig: props.config.menu, footerConfig: (_0 = props.config) === null || _0 === void 0 ? void 0 : _0.footer, inputConfig: (_1 = props.config) === null || _1 === void 0 ? void 0 : _1.input, onChange: handleOnChange, onSubmit: handleOnSubmit, onFileUpload: handleFileUpload }),
31075
+ React__default$1["default"].createElement("div", { className: "restartModal", ref: modalRef, onClick: handleRestartModalCloseClick },
31076
+ React__default$1["default"].createElement(ModalContent, { onClose: handleRestartModalCloseClick, onReset: handleReset }))),
31077
+ React__default$1["default"].createElement(ChatButton, { addClass: getVisibilityClass(), onClick: chatButtonOnClick, config: (_2 = props.config) === null || _2 === void 0 ? void 0 : _2.cta, visible: visible })));
31049
31078
  };
31050
31079
 
31051
31080
  function tryParseJson(str) {