@xapp/chat-widget 1.76.1 → 1.78.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
@@ -782,34 +782,35 @@ var ChatButton = function (_a) {
782
782
  clearTimeout(timeoutTimer);
783
783
  };
784
784
  }, [configToApply, setAnimate]);
785
- var animation = animate ? ((configToApply === null || configToApply === void 0 ? void 0 : configToApply.animation) || "wiggle") : "none";
785
+ var animation = animate ? (configToApply === null || configToApply === void 0 ? void 0 : configToApply.animation) || "wiggle" : "none";
786
786
  React$1.useEffect(function () {
787
787
  var handleResize = function () {
788
788
  var screenWidth = window.innerWidth;
789
- var newButtonWidth = screenWidth < (parseInt(mobileWidth, 10))
790
- ? defaultMobileWidgetButtonWidth : defaultWidgetButtonWidth;
789
+ var newButtonWidth = screenWidth < parseInt(mobileWidth, 10)
790
+ ? defaultMobileWidgetButtonWidth
791
+ : defaultWidgetButtonWidth;
791
792
  setButtonWidth(newButtonWidth);
792
793
  };
793
794
  handleResize();
794
- window.addEventListener('resize', handleResize);
795
+ window.addEventListener("resize", handleResize);
795
796
  return function () {
796
- window.removeEventListener('resize', handleResize);
797
+ window.removeEventListener("resize", handleResize);
797
798
  };
798
799
  }, [mobileWidth]);
799
800
  var maxSvgSize = 22;
800
- var svgSize = Math.min(maxSvgSize, (+buttonWidth / 48) * maxSvgSize);
801
+ var svgSize = Math.min(maxSvgSize, (+buttonWidth / +defaultWidgetButtonWidth) * maxSvgSize);
801
802
  return (React$1.createElement("button", { "aria-label": "open chat", className: "xapp-chat-button ".concat(addClass || "").trim(), onClick: onClick },
802
803
  React$1.createElement("div", { id: "xapp-widget-button", className: "xapp-chat-button__btn", style: {
803
804
  width: "".concat(buttonWidth, "px"),
804
805
  height: "".concat(buttonWidth, "px"),
805
806
  borderRadius: "".concat(+buttonWidth / 2, "px"),
806
- border: borderStyle && borderStyle.width ? 'solid' : 'none',
807
- borderWidth: (borderStyle === null || borderStyle === void 0 ? void 0 : borderStyle.width) || '0px',
808
- borderColor: (borderStyle === null || borderStyle === void 0 ? void 0 : borderStyle.color) || 'transparent',
807
+ border: borderStyle && borderStyle.width ? "solid" : "none",
808
+ borderWidth: (borderStyle === null || borderStyle === void 0 ? void 0 : borderStyle.width) || "0px",
809
+ borderColor: (borderStyle === null || borderStyle === void 0 ? void 0 : borderStyle.color) || "transparent",
809
810
  animation: "".concat(animation, " 1s infinite"),
810
811
  } }, imageUrl ? (
811
812
  // Display image from URL
812
- React$1.createElement("img", { src: imageUrl, alt: "Chat Icon", width: "22", height: "22" })) : (
813
+ React$1.createElement("img", { src: imageUrl, alt: "Chat Icon" })) : (
813
814
  // Fallback to default SVG
814
815
  React$1.createElement("svg", { width: svgSize, height: svgSize, viewBox: "0 0 22 22" },
815
816
  React$1.createElement("path", { d: "M13 22l-4-6H2c-1.11-.043-2-.935-2-2V2C0 .89.89 0 2 0h18c1.11 0 2 .892 2 2v12c0 1.067-.89 1.957-2 2h-3l-4 6zm3-8h4c-.005.3-.01-12 0-12-.01.004-18 .006-18 0 .005.006 0 12 0 12h8l3 5 3-5z", fill: "#FFF", fillRule: "evenodd" })))),
@@ -7704,6 +7705,11 @@ var ChatChipsContainer = function (_) {
7704
7705
  React$1.createElement(ChatChips, { options: chips, onOptionClick: optionOnChange })));
7705
7706
  };
7706
7707
 
7708
+ var ButtonGroup = function (_a) {
7709
+ var children = _a.children, _b = _a.className, className = _b === void 0 ? "" : _b;
7710
+ return (React$1.createElement("div", { className: "button-group ".concat(className) }, children));
7711
+ };
7712
+
7707
7713
  var CancelButton = function (props) {
7708
7714
  return (React$1.createElement("div", { id: "xapp-widget-close", "aria-label": "close widget", "aria-hidden": false, tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, className: "cancel-button", onClick: props.onClick }));
7709
7715
  };
@@ -7843,6 +7849,10 @@ var DrawerBars = function (props) {
7843
7849
  return (React$1.createElement("button", { className: "drawer-bars", tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, "aria-label": "open menu", "aria-hidden": false, onClick: props.onToggle }, getBars()));
7844
7850
  };
7845
7851
 
7852
+ var MenuButton = function (props) {
7853
+ return (React$1.createElement("div", { id: "xapp-widget-menu", "aria-label": "open menu", "aria-hidden": false, tabIndex: props.tabIndex ? Number(props.tabIndex) : 0, className: "menu-button", onClick: props.onClick }));
7854
+ };
7855
+
7846
7856
  var MinimizeButton = function (props) {
7847
7857
  return (React$1.createElement("div", { 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 }));
7848
7858
  };
@@ -7879,16 +7889,19 @@ var ChatHeader = function (props) {
7879
7889
  var menuConfig = props.menuConfig, onSubmit = props.onSubmit;
7880
7890
  var _s = React$1.useState(false), drawerOpen = _s[0], setDrawerState = _s[1]; // false initially
7881
7891
  var menuPosition = (menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.menuButtonLocation) || "FOOTER";
7882
- var showMenu = menuPosition === "HEADER_LEFT";
7883
- var menuItemsRaw = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.items; // useWidgetEnv()?.menu?.items;
7884
- var menuItemsTabIndex = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.itemsTabIndex; // useWidgetEnv()?.menu?.itemsTabIndex;
7885
- var menuButtonTabIndex = (_a = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.button) === null || _a === void 0 ? void 0 : _a.tabIndex; // useWidgetEnv()?.menu?.button?.tabIndex;
7886
- var menuItems = React$1.useMemo(function () { return menuItemsRaw ? menuItemsRaw : []; }, [menuItemsRaw]);
7892
+ var showMenuLeft = menuPosition === "HEADER_LEFT";
7893
+ var showMenuRight = menuPosition === "HEADER_RIGHT";
7894
+ var menuItemsRaw = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.items;
7895
+ var menuItemsTabIndex = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.itemsTabIndex;
7896
+ var menuButtonTabIndex = (_a = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.button) === null || _a === void 0 ? void 0 : _a.tabIndex;
7897
+ var menuItems = React$1.useMemo(function () { return (menuItemsRaw ? menuItemsRaw : []); }, [menuItemsRaw]);
7898
+ // Check if we have a right-side menu
7899
+ var hasRightMenu = showMenuRight && menuItems.length > 0;
7887
7900
  function toggleDrawer() {
7888
7901
  var newDrawer = !drawerOpen;
7889
7902
  setDrawerState(newDrawer);
7890
7903
  innerDispatch(setVisualStatus({
7891
- drawer: newDrawer
7904
+ drawer: newDrawer,
7892
7905
  }));
7893
7906
  }
7894
7907
  function handleMenuItem(label) {
@@ -7908,20 +7921,27 @@ var ChatHeader = function (props) {
7908
7921
  }
7909
7922
  return (React$1.createElement(React$1.Fragment, null,
7910
7923
  React$1.createElement("div", { className: "status-container background-header", "aria-label": ariaLabel, "aria-hidden": false },
7911
- showMenu && menuItems.length ? (React$1.createElement(React$1.Fragment, null,
7924
+ showMenuLeft && menuItems.length ? (React$1.createElement(React$1.Fragment, null,
7912
7925
  React$1.createElement("div", { className: "chat-footer__menu-icon" },
7913
- React$1.createElement(DrawerBars, { bars: 3, tabIndex: menuButtonTabIndex, onToggle: toggleDrawer })))) : React$1.createElement(React$1.Fragment, null),
7914
- ((_b = props === null || props === void 0 ? void 0 : props.agent) === null || _b === void 0 ? void 0 : _b.avatarPath) === undefined ? React$1.createElement("div", null) :
7915
- React$1.createElement("div", { className: "status-container__avatar" },
7916
- React$1.createElement(Avatar, { entity: props.agent })),
7917
- React$1.createElement("div", { className: "\n ".concat("status-text", "\n ").concat(((_c = props === null || props === void 0 ? void 0 : props.agent) === null || _c === void 0 ? void 0 : _c.avatarPath) === undefined ? "status-text-positionLeftNoAvatar" : "status-text-positionLeft", "\n ").concat(((_d = props.config) === null || _d === void 0 ? void 0 : _d.alignTextCenter) ? "status-text-positionCenter" : "status-text-positionLeft", " \n ") },
7926
+ React$1.createElement(DrawerBars, { bars: 3, tabIndex: menuButtonTabIndex, onToggle: toggleDrawer })))) : (React$1.createElement(React$1.Fragment, null)),
7927
+ ((_b = props === null || props === void 0 ? void 0 : props.agent) === null || _b === void 0 ? void 0 : _b.avatarPath) === undefined ? (React$1.createElement("div", null)) : (React$1.createElement("div", { className: "status-container__avatar" },
7928
+ React$1.createElement(Avatar, { entity: props.agent }))),
7929
+ React$1.createElement("div", { className: "\n ".concat("status-text", "\n ").concat(showMenuLeft && menuItems.length
7930
+ ? "status-text-positionWithMenu"
7931
+ : ((_c = props === null || props === void 0 ? void 0 : props.agent) === null || _c === void 0 ? void 0 : _c.avatarPath) === undefined
7932
+ ? "status-text-positionLeftNoAvatar"
7933
+ : "status-text-positionLeft", "\n ").concat(((_d = props.config) === null || _d === void 0 ? void 0 : _d.alignTextCenter)
7934
+ ? "status-text-positionCenter"
7935
+ : "", " \n ") },
7918
7936
  React$1.createElement("span", { className: "status-text-title" }, getStatusText(props.accountStatus, (_e = props.config) === null || _e === void 0 ? void 0 : _e.status)),
7919
7937
  ((_g = (_f = props.config) === null || _f === void 0 ? void 0 : _f.subtitle) === null || _g === void 0 ? void 0 : _g.enabled) && (React$1.createElement("span", { className: "status-text-subtitle" }, (_k = (_j = (_h = props.config) === null || _h === void 0 ? void 0 : _h.subtitle) === null || _j === void 0 ? void 0 : _j.text) !== null && _k !== void 0 ? _k : ""))),
7920
- props.canRefresh && (React$1.createElement(RefreshButton, { onClick: props.refreshOnClick, tabIndex: (_m = (_l = props.config) === null || _l === void 0 ? void 0 : _l.actions) === null || _m === void 0 ? void 0 : _m.refreshTabIndex, showInLeft: props.canMinimize && props.canCancel, showInRight: !props.canMinimize && !props.canCancel })),
7921
- props.canMinimize && (React$1.createElement(MinimizeButton, { onClick: props.minimizeOnClick, tabIndex: (_p = (_o = props.config) === null || _o === void 0 ? void 0 : _o.actions) === null || _p === void 0 ? void 0 : _p.minimizeTabIndex, showInRight: !props.canCancel })),
7922
- props.canCancel && (React$1.createElement(CancelButton, { onClick: props.cancelOnClick, tabIndex: (_r = (_q = props.config) === null || _q === void 0 ? void 0 : _q.actions) === null || _r === void 0 ? void 0 : _r.cancelTabIndex }))),
7938
+ React$1.createElement(ButtonGroup, null,
7939
+ hasRightMenu && (React$1.createElement(MenuButton, { onClick: toggleDrawer, tabIndex: menuButtonTabIndex })),
7940
+ props.canRefresh && (React$1.createElement(RefreshButton, { onClick: props.refreshOnClick, tabIndex: (_m = (_l = props.config) === null || _l === void 0 ? void 0 : _l.actions) === null || _m === void 0 ? void 0 : _m.refreshTabIndex, showInLeft: false, showInRight: false })),
7941
+ props.canMinimize && (React$1.createElement(MinimizeButton, { onClick: props.minimizeOnClick, tabIndex: (_p = (_o = props.config) === null || _o === void 0 ? void 0 : _o.actions) === null || _p === void 0 ? void 0 : _p.minimizeTabIndex, showInRight: false })),
7942
+ props.canCancel && (React$1.createElement(CancelButton, { onClick: props.cancelOnClick, tabIndex: (_r = (_q = props.config) === null || _q === void 0 ? void 0 : _q.actions) === null || _r === void 0 ? void 0 : _r.cancelTabIndex })))),
7923
7943
  drawerOpen ? (React$1.createElement("div", { className: "xa-chat-menu-container" },
7924
- React$1.createElement(ChatMenu, { openFrom: "left", opened: drawerOpen, tabIndex: menuItemsTabIndex, onItemClick: handleMenuItem, items: menuItems }))) : React$1.createElement(React$1.Fragment, null)));
7944
+ React$1.createElement(ChatMenu, { openFrom: showMenuRight ? "right" : "left", opened: drawerOpen, tabIndex: menuItemsTabIndex, onItemClick: handleMenuItem, items: menuItems }))) : (React$1.createElement(React$1.Fragment, null))));
7925
7945
  };
7926
7946
 
7927
7947
  var UnknownMessage = function () { return React$1.createElement(React$1.Fragment, null); };
@@ -31089,7 +31109,7 @@ function buildStyleContent(theme) {
31089
31109
  function WidgetStylesheet(props) {
31090
31110
  var theme = props.theme;
31091
31111
  var stylesContent = buildStyleContent(theme);
31092
- return (React$1.createElement("style", null, stylesContent));
31112
+ return React$1.createElement("style", null, stylesContent);
31093
31113
  }
31094
31114
  function buildVariables(gen) {
31095
31115
  var result = gen.next();
@@ -31161,16 +31181,14 @@ function single(key, value) {
31161
31181
  }
31162
31182
  });
31163
31183
  }
31164
- function empty() {
31165
- return __generator$1(this, function (_a) {
31166
- return [2 /*return*/];
31167
- });
31168
- }
31184
+ function empty() { return __generator$1(this, function (_a) {
31185
+ return [2 /*return*/];
31186
+ }); }
31169
31187
  function getChatButtonStyle(style) {
31170
31188
  if (!style) {
31171
31189
  return empty();
31172
31190
  }
31173
- return withPrefix("chat-button-", union(getMargins(style.margin), getBackgroundStyle(style.background)));
31191
+ return withPrefix("chat-button-", union(getMargins(style.margin), getBackgroundStyle(style.background), withPrefix("image-", getSize(style.imageSize)), getAnimationStyle(style.animation)));
31174
31192
  }
31175
31193
  function getMessagesStyle(style) {
31176
31194
  if (!style) {
@@ -31179,16 +31197,58 @@ function getMessagesStyle(style) {
31179
31197
  return union(withPrefix("mine-", getMessageStyle(style.mine)), withPrefix("others-", getMessageStyle(style.others)), getPaddings(style === null || style === void 0 ? void 0 : style.padding), single("max-width", style === null || style === void 0 ? void 0 : style.maxWidth));
31180
31198
  }
31181
31199
  function getMessageStyle(style) {
31182
- return union(single('bubble-color', style === null || style === void 0 ? void 0 : style.bubbleColor), getTextStyle(style === null || style === void 0 ? void 0 : style.text));
31200
+ return union(single("bubble-color", style === null || style === void 0 ? void 0 : style.bubbleColor), getTextStyle(style === null || style === void 0 ? void 0 : style.text));
31183
31201
  }
31184
31202
  function getSize(style) {
31185
31203
  return __generator$1(this, function (_a) {
31186
31204
  switch (_a.label) {
31187
- case 0: return [4 /*yield*/, ['width', style === null || style === void 0 ? void 0 : style.width]];
31205
+ case 0: return [4 /*yield*/, ["width", style === null || style === void 0 ? void 0 : style.width]];
31206
+ case 1:
31207
+ _a.sent();
31208
+ return [4 /*yield*/, ["height", style === null || style === void 0 ? void 0 : style.height]];
31209
+ case 2:
31210
+ _a.sent();
31211
+ return [2 /*return*/];
31212
+ }
31213
+ });
31214
+ }
31215
+ function getAnimationStyle(style) {
31216
+ var primaryColor, secondaryColor, opacity, intenseBackground, lessIntenseBackground;
31217
+ return __generator$1(this, function (_a) {
31218
+ switch (_a.label) {
31219
+ case 0:
31220
+ if (!style) {
31221
+ return [2 /*return*/];
31222
+ }
31223
+ primaryColor = style.primaryColor || "0, 117, 170";
31224
+ secondaryColor = style.secondaryColor || "110, 178, 209";
31225
+ opacity = style.opacity || 0.75;
31226
+ // Generate CSS variables that can be used by any animation type
31227
+ return [4 /*yield*/, ["animation-primary-color", "".concat(primaryColor)]];
31188
31228
  case 1:
31229
+ // Generate CSS variables that can be used by any animation type
31189
31230
  _a.sent();
31190
- return [4 /*yield*/, ['height', style === null || style === void 0 ? void 0 : style.height]];
31231
+ return [4 /*yield*/, ["animation-secondary-color", "".concat(secondaryColor)]];
31191
31232
  case 2:
31233
+ _a.sent();
31234
+ return [4 /*yield*/, ["animation-opacity", "".concat(opacity)]];
31235
+ case 3:
31236
+ _a.sent();
31237
+ // Generate colors for box-shadow halo effects
31238
+ return [4 /*yield*/, ["animation-primary-rgba", "rgba(".concat(primaryColor, ", ").concat(opacity, ")")]];
31239
+ case 4:
31240
+ // Generate colors for box-shadow halo effects
31241
+ _a.sent();
31242
+ return [4 /*yield*/, ["animation-secondary-rgba", "rgba(".concat(secondaryColor, ", ").concat(opacity, ")")]];
31243
+ case 5:
31244
+ _a.sent();
31245
+ intenseBackground = "radial-gradient(40.83% 40.83% at 47.92% 52.5%, rgba(".concat(primaryColor, ", ").concat(opacity, ") 78.85%, rgba(").concat(secondaryColor, ", ").concat(opacity, ") 92.07%)");
31246
+ lessIntenseBackground = "radial-gradient(40.83% 40.83% at 47.92% 52.5%, rgba(".concat(primaryColor, ", ").concat(opacity, ") 20.46%, rgba(").concat(secondaryColor, ", ").concat(opacity, ") 92.07%)");
31247
+ return [4 /*yield*/, ["animation-pulse-intense", intenseBackground]];
31248
+ case 6:
31249
+ _a.sent();
31250
+ return [4 /*yield*/, ["animation-pulse-less-intense", lessIntenseBackground]];
31251
+ case 7:
31192
31252
  _a.sent();
31193
31253
  return [2 /*return*/];
31194
31254
  }
@@ -31199,7 +31259,7 @@ function getZIndex(style) {
31199
31259
  switch (_a.label) {
31200
31260
  case 0:
31201
31261
  if (!style) return [3 /*break*/, 2];
31202
- return [4 /*yield*/, ['z-index', style]];
31262
+ return [4 /*yield*/, ["z-index", style]];
31203
31263
  case 1:
31204
31264
  _a.sent();
31205
31265
  _a.label = 2;
@@ -31256,19 +31316,19 @@ function getTextStyle(style) {
31256
31316
  switch (_a.label) {
31257
31317
  case 0:
31258
31318
  if (!style) return [3 /*break*/, 6];
31259
- return [4 /*yield*/, ['text-color', style.color]];
31319
+ return [4 /*yield*/, ["text-color", style.color]];
31260
31320
  case 1:
31261
31321
  _a.sent();
31262
- return [4 /*yield*/, ['font-size', style.fontSize]];
31322
+ return [4 /*yield*/, ["font-size", style.fontSize]];
31263
31323
  case 2:
31264
31324
  _a.sent();
31265
- return [4 /*yield*/, ['font-family', style.fontFamily]];
31325
+ return [4 /*yield*/, ["font-family", style.fontFamily]];
31266
31326
  case 3:
31267
31327
  _a.sent();
31268
- return [4 /*yield*/, ['font-weight', style.fontWeight]];
31328
+ return [4 /*yield*/, ["font-weight", style.fontWeight]];
31269
31329
  case 4:
31270
31330
  _a.sent();
31271
- return [4 /*yield*/, ['font-style', style.fontStyle]];
31331
+ return [4 /*yield*/, ["font-style", style.fontStyle]];
31272
31332
  case 5:
31273
31333
  _a.sent();
31274
31334
  _a.label = 6;
@@ -31289,11 +31349,17 @@ function getBackgroundStyle(style) {
31289
31349
  function getButtonStyle(style) {
31290
31350
  return __generator$1(this, function (_a) {
31291
31351
  switch (_a.label) {
31292
- case 0: return [4 /*yield*/, ['button-color', style === null || style === void 0 ? void 0 : style.color]];
31352
+ case 0: return [4 /*yield*/, ["button-color", style === null || style === void 0 ? void 0 : style.color]];
31293
31353
  case 1:
31294
31354
  _a.sent();
31295
- return [4 /*yield*/, ['button-width', style === null || style === void 0 ? void 0 : style.width]];
31355
+ return [4 /*yield*/, ["button-width", style === null || style === void 0 ? void 0 : style.width]];
31296
31356
  case 2:
31357
+ _a.sent();
31358
+ return [4 /*yield*/, ["button-bg", style === null || style === void 0 ? void 0 : style.background]];
31359
+ case 3:
31360
+ _a.sent();
31361
+ return [4 /*yield*/, ["button-hover-bg", style === null || style === void 0 ? void 0 : style.hoverBackground]];
31362
+ case 4:
31297
31363
  _a.sent();
31298
31364
  return [2 /*return*/];
31299
31365
  }
@@ -31310,13 +31376,13 @@ function getBorderStyle(style) {
31310
31376
  switch (_a.label) {
31311
31377
  case 0:
31312
31378
  if (!style) return [3 /*break*/, 4];
31313
- return [4 /*yield*/, ['border-color', style.color]];
31379
+ return [4 /*yield*/, ["border-color", style.color]];
31314
31380
  case 1:
31315
31381
  _a.sent();
31316
- return [4 /*yield*/, ['border-width', style.width]];
31382
+ return [4 /*yield*/, ["border-width", style.width]];
31317
31383
  case 2:
31318
31384
  _a.sent();
31319
- return [4 /*yield*/, ['border-radius', style.radius]];
31385
+ return [4 /*yield*/, ["border-radius", style.radius]];
31320
31386
  case 3:
31321
31387
  _a.sent();
31322
31388
  _a.label = 4;
@@ -31328,7 +31394,7 @@ function getHeaderStyle(style) {
31328
31394
  if (!style) {
31329
31395
  return empty();
31330
31396
  }
31331
- return union(getBackgroundStyle(style.background), getTextStyle(style.text), withPrefix("subtitle-", getTextStyle(style.subtitle)), getBorderStyle(style.border));
31397
+ return union(getBackgroundStyle(style.background), getTextStyle(style.text), withPrefix("subtitle-", getTextStyle(style.subtitle)), getBorderStyle(style.border), getPaddings(style.padding), single("avatar-background", style.avatarBackground));
31332
31398
  }
31333
31399
  function getFooterStyle(style) {
31334
31400
  var _a;