@xapp/chat-widget 1.94.0 → 1.94.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
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var require$$1 = require('react');
3
+ var React = require('react');
4
4
  var require$$0 = require('react/jsx-runtime');
5
5
  var reactRedux = require('react-redux');
6
6
 
@@ -234,7 +234,7 @@ var defaultLabels = {
234
234
  var ActionBarButton = function (_a) {
235
235
  var _b;
236
236
  var button = _a.button, chatActive = _a.chatActive, onChatClick = _a.onChatClick, onChatMinimize = _a.onChatMinimize, onFormClick = _a.onFormClick, isMobile = _a.isMobile;
237
- var handleClick = require$$1.useCallback(function () {
237
+ var handleClick = React.useCallback(function () {
238
238
  if (lib.isActionBarChatButton(button)) {
239
239
  // Toggle chat: if active, minimize; if not active, open
240
240
  if (chatActive) {
@@ -311,9 +311,9 @@ var ActionBarButton = function (_a) {
311
311
  var ActionBarCta = function (_a) {
312
312
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
313
313
  var config = _a.config, isMobile = _a.isMobile, onClick = _a.onClick, onDismiss = _a.onDismiss, hasUserInteracted = _a.hasUserInteracted;
314
- var _m = require$$1.useState(false), isVisible = _m[0], setIsVisible = _m[1];
315
- var _o = require$$1.useState(false), isAnimating = _o[0], setIsAnimating = _o[1];
316
- var _p = require$$1.useState(false), isDismissed = _p[0], setIsDismissed = _p[1];
314
+ var _m = React.useState(false), isVisible = _m[0], setIsVisible = _m[1];
315
+ var _o = React.useState(false), isAnimating = _o[0], setIsAnimating = _o[1];
316
+ var _p = React.useState(false), isDismissed = _p[0], setIsDismissed = _p[1];
317
317
  // For mobile overrides: null means "explicitly disabled", undefined means "use desktop default"
318
318
  var mobileMessage = isMobile ? (_b = config.mobile) === null || _b === void 0 ? void 0 : _b.message : undefined;
319
319
  var message = mobileMessage !== undefined ? mobileMessage : config.message;
@@ -332,7 +332,7 @@ var ActionBarCta = function (_a) {
332
332
  ? config.mobile.dismissible
333
333
  : ((_l = config.dismissible) !== null && _l !== void 0 ? _l : true);
334
334
  // Show CTA after delay
335
- require$$1.useEffect(function () {
335
+ React.useEffect(function () {
336
336
  if (!message || hasUserInteracted || isDismissed) {
337
337
  setIsVisible(false);
338
338
  return undefined;
@@ -343,7 +343,7 @@ var ActionBarCta = function (_a) {
343
343
  return function () { return clearTimeout(showTimer); };
344
344
  }, [message, delay, hasUserInteracted, isDismissed]);
345
345
  // Hide CTA after timeout
346
- require$$1.useEffect(function () {
346
+ React.useEffect(function () {
347
347
  if (!isVisible || !timeout) {
348
348
  return undefined;
349
349
  }
@@ -353,7 +353,7 @@ var ActionBarCta = function (_a) {
353
353
  return function () { return clearTimeout(hideTimer); };
354
354
  }, [isVisible, timeout]);
355
355
  // Start animation after animationDelay
356
- require$$1.useEffect(function () {
356
+ React.useEffect(function () {
357
357
  if (!animation || hasUserInteracted || isDismissed) {
358
358
  setIsAnimating(false);
359
359
  return undefined;
@@ -364,7 +364,7 @@ var ActionBarCta = function (_a) {
364
364
  return function () { return clearTimeout(animateTimer); };
365
365
  }, [animation, animationDelay, hasUserInteracted, isDismissed]);
366
366
  // Stop animation after animationTimeout
367
- require$$1.useEffect(function () {
367
+ React.useEffect(function () {
368
368
  if (!isAnimating || !animationTimeout) {
369
369
  return undefined;
370
370
  }
@@ -400,12 +400,12 @@ var RESIZE_DEBOUNCE_MS = 150;
400
400
  var ActionBar = function (_a) {
401
401
  var _b, _c, _d;
402
402
  var config = _a.config, visible = _a.visible, chatDisabled = _a.chatDisabled, _e = _a.hasUserInteracted, hasUserInteracted = _e === void 0 ? false : _e, onChatClick = _a.onChatClick, onChatMinimize = _a.onChatMinimize, onFormClick = _a.onFormClick, onCtaDismiss = _a.onCtaDismiss;
403
- var _f = require$$1.useState(false), isMobile = _f[0], setIsMobile = _f[1];
403
+ var _f = React.useState(false), isMobile = _f[0], setIsMobile = _f[1];
404
404
  var mobileBreakpoint = (_b = config.mobileBreakpoint) !== null && _b !== void 0 ? _b : DEFAULT_MOBILE_BREAKPOINT;
405
405
  var position = (_c = config.position) !== null && _c !== void 0 ? _c : "right";
406
- var resizeTimeoutRef = require$$1.useRef(null);
406
+ var resizeTimeoutRef = React.useRef(null);
407
407
  // Debounced resize handler
408
- var handleResize = require$$1.useCallback(function () {
408
+ var handleResize = React.useCallback(function () {
409
409
  if (resizeTimeoutRef.current) {
410
410
  window.clearTimeout(resizeTimeoutRef.current);
411
411
  }
@@ -413,7 +413,7 @@ var ActionBar = function (_a) {
413
413
  setIsMobile(window.innerWidth <= mobileBreakpoint);
414
414
  }, RESIZE_DEBOUNCE_MS);
415
415
  }, [mobileBreakpoint]);
416
- require$$1.useEffect(function () {
416
+ React.useEffect(function () {
417
417
  // Initial check (immediate, not debounced)
418
418
  setIsMobile(window.innerWidth <= mobileBreakpoint);
419
419
  window.addEventListener("resize", handleResize);
@@ -477,13 +477,13 @@ var ActionBar = function (_a) {
477
477
  var ActionBarPreview = function (_a) {
478
478
  var config = _a.config, _b = _a.chatActive, chatActive = _b === void 0 ? false : _b;
479
479
  // No-op handlers for preview mode
480
- var handleChatClick = require$$1.useCallback(function () {
480
+ var handleChatClick = React.useCallback(function () {
481
481
  // Preview only - no action
482
482
  }, []);
483
- var handleChatMinimize = require$$1.useCallback(function () {
483
+ var handleChatMinimize = React.useCallback(function () {
484
484
  // Preview only - no action
485
485
  }, []);
486
- var handleFormClick = require$$1.useCallback(function (_button) {
486
+ var handleFormClick = React.useCallback(function (_button) {
487
487
  // Preview only - no action
488
488
  }, []);
489
489
  return (require$$0.jsx(ActionBar, { config: config, visible: chatActive, chatDisabled: false, onChatClick: handleChatClick, onChatMinimize: handleChatMinimize, onFormClick: handleFormClick }));
@@ -689,14 +689,14 @@ function isAgent(nick) {
689
689
  }
690
690
 
691
691
  function useIsMounted() {
692
- var ref = require$$1.useRef(false);
693
- require$$1.useEffect(function () {
692
+ var ref = React.useRef(false);
693
+ React.useEffect(function () {
694
694
  ref.current = true;
695
695
  return function () {
696
696
  ref.current = false;
697
697
  };
698
698
  }, []);
699
- return require$$1.useCallback(function () { return ref.current; }, []);
699
+ return React.useCallback(function () { return ref.current; }, []);
700
700
  }
701
701
 
702
702
  var RetryOptions = /** @class */ (function () {
@@ -1064,9 +1064,9 @@ var defaultWidgetButtonWidth = "48";
1064
1064
  var defaultMobileWidgetButtonWidth = "30";
1065
1065
  var defaultNonMobileScreenWidth = "400";
1066
1066
  var scheduleWidgetUrl = "ScheduleButton";
1067
- var ChatConfigContext = require$$1.createContext(null);
1067
+ var ChatConfigContext = React.createContext(null);
1068
1068
  function useWidgetEnv() {
1069
- var ctx = require$$1.useContext(ChatConfigContext);
1069
+ var ctx = React.useContext(ChatConfigContext);
1070
1070
  return ctx === null || ctx === void 0 ? void 0 : ctx.env;
1071
1071
  }
1072
1072
  function getServerConfig(env) {
@@ -1085,7 +1085,7 @@ function useServerConfig(env, nonce) {
1085
1085
  // channelId lives at the WidgetEnv level; fold it into the mcp config so MCPChat
1086
1086
  // can send it for event/lead attribution.
1087
1087
  var channelId = env === null || env === void 0 ? void 0 : env.channelId;
1088
- return require$$1.useMemo(function () { return ({
1088
+ return React.useMemo(function () { return ({
1089
1089
  accountKey: accountKey,
1090
1090
  serverUrl: serverUrl,
1091
1091
  timeout: timeout,
@@ -1115,7 +1115,7 @@ var Avatar = function (props) {
1115
1115
  var style = {};
1116
1116
  var child;
1117
1117
  var entity = props.entity;
1118
- var chatConfig = require$$1.useContext(ChatConfigContext);
1118
+ var chatConfig = React.useContext(ChatConfigContext);
1119
1119
  var avatarPath = entity === null || entity === void 0 ? void 0 : entity.avatarPath;
1120
1120
  if (!avatarPath) {
1121
1121
  var avatarImage = GenerateAvatar({
@@ -1150,7 +1150,7 @@ function GenerateAvatar(props) {
1150
1150
  var size = (props === null || props === void 0 ? void 0 : props.size) || 40;
1151
1151
  var backgroundColor = (props === null || props === void 0 ? void 0 : props.backgroundColor) || "#007bff";
1152
1152
  var textColor = (props === null || props === void 0 ? void 0 : props.textColor) || "#ffffff";
1153
- var image = require$$1.useMemo(function () {
1153
+ var image = React.useMemo(function () {
1154
1154
  return generateImage(initials, size, backgroundColor, textColor);
1155
1155
  }, [initials, size, backgroundColor, textColor]);
1156
1156
  return image;
@@ -1194,7 +1194,7 @@ var OptionalLink = function (props) {
1194
1194
  var chatDispatch = useChatDispatch();
1195
1195
  var visuals = reactRedux.useSelector(function (state) { return state.visuals; });
1196
1196
  var url = props.url, className = props.className, onOpen = props.onOpen;
1197
- var handleOpenUrl = require$$1.useCallback(function () {
1197
+ var handleOpenUrl = React.useCallback(function () {
1198
1198
  if (onOpen) {
1199
1199
  onOpen(url, chatDispatch, visuals);
1200
1200
  }
@@ -1211,7 +1211,7 @@ var ActionItem = function (props) {
1211
1211
  var _a;
1212
1212
  var item = props.item, onButtonClick = props.onButtonClick, onExecute = props.onExecute;
1213
1213
  var singleButton = ((_a = item.buttons) === null || _a === void 0 ? void 0 : _a.length) === 1;
1214
- var handleClick = require$$1.useCallback(function () {
1214
+ var handleClick = React.useCallback(function () {
1215
1215
  var _a;
1216
1216
  var btns = (_a = item.buttons) === null || _a === void 0 ? void 0 : _a.length;
1217
1217
  // If there is only one button, it takes precedent
@@ -1255,19 +1255,19 @@ var ActionItemImage = function (props) {
1255
1255
 
1256
1256
  var ChatActionButtonInner = function (props) {
1257
1257
  var button = props.button, onClick = props.onClick;
1258
- var handleButton = require$$1.useCallback(function () {
1258
+ var handleButton = React.useCallback(function () {
1259
1259
  onClick(button);
1260
1260
  }, [button, onClick]);
1261
1261
  return require$$0.jsx(ActionButton, { onClick: handleButton, addClass: "button-card", label: button.label });
1262
1262
  };
1263
- var ChatActionButton = require$$1.memo(ChatActionButtonInner);
1263
+ var ChatActionButton = React.memo(ChatActionButtonInner);
1264
1264
 
1265
1265
  var ChatActionButtonsInner = function (props) {
1266
1266
  return (require$$0.jsx("div", { className: "buttons-container " + (props.className || ""), children: props.buttons.map(function (button, i) {
1267
1267
  return require$$0.jsx(ChatActionButton, { button: button, onClick: props.onClick }, i);
1268
1268
  }) }));
1269
1269
  };
1270
- var ChatActionButtons = require$$1.memo(ChatActionButtonsInner);
1270
+ var ChatActionButtons = React.memo(ChatActionButtonsInner);
1271
1271
 
1272
1272
  var CarouselItem = function (props) {
1273
1273
  var _a;
@@ -1290,8 +1290,8 @@ var ChevronRight = function (props) {
1290
1290
  };
1291
1291
 
1292
1292
  var Carousel = function (props) {
1293
- var listRef = require$$1.useRef(null);
1294
- var _a = require$$1.useState(0), visibleIndex = _a[0], setSetVisibleIndex = _a[1];
1293
+ var listRef = React.useRef(null);
1294
+ var _a = React.useState(0), visibleIndex = _a[0], setSetVisibleIndex = _a[1];
1295
1295
  function scrollMe(direction) {
1296
1296
  var _a, _b;
1297
1297
  var scrollArea = listRef.current;
@@ -1331,9 +1331,9 @@ var Carousel = function (props) {
1331
1331
  };
1332
1332
 
1333
1333
  function useDimensions() {
1334
- var ref = require$$1.useRef(null);
1335
- var _a = require$$1.useState(), dimensions = _a[0], setDimensions = _a[1];
1336
- require$$1.useLayoutEffect(function () {
1334
+ var ref = React.useRef(null);
1335
+ var _a = React.useState(), dimensions = _a[0], setDimensions = _a[1];
1336
+ React.useLayoutEffect(function () {
1337
1337
  var _a, _b;
1338
1338
  setDimensions((_b = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.toJSON());
1339
1339
  }, []);
@@ -1466,14 +1466,14 @@ var CtaBubbleContainer = function (props) {
1466
1466
  hasChildren: !!children,
1467
1467
  childrenContent: children,
1468
1468
  });
1469
- var startTime = require$$1.useMemo(function () {
1469
+ var startTime = React.useMemo(function () {
1470
1470
  var time = visible ? new Date().valueOf() : undefined;
1471
1471
  log("[CtaBubbleContainer] StartTime calculated: visible=".concat(visible, ", startTime=").concat(time));
1472
1472
  return time;
1473
1473
  }, [visible]);
1474
- var _a = require$$1.useState(false), showBubble = _a[0], setShowBubble = _a[1];
1474
+ var _a = React.useState(false), showBubble = _a[0], setShowBubble = _a[1];
1475
1475
  log("[CtaBubbleContainer] Current state: showBubble=".concat(showBubble));
1476
- require$$1.useEffect(function () {
1476
+ React.useEffect(function () {
1477
1477
  log("[CtaBubbleContainer] useEffect triggered with:", {
1478
1478
  startTime: startTime,
1479
1479
  startTimeExists: !!startTime,
@@ -1549,8 +1549,8 @@ var CtaBubbleContainer = function (props) {
1549
1549
  var ChatButton = function (_a) {
1550
1550
  var _b;
1551
1551
  var onClick = _a.onClick, addClass = _a.addClass, config = _a.config, visible = _a.visible, borderStyle = _a.borderStyle, imageUrl = _a.imageUrl, hasInteracted = _a.hasInteracted, onCtaDismiss = _a.onCtaDismiss;
1552
- var _c = require$$1.useState(defaultWidgetButtonWidth), buttonWidth = _c[0], setButtonWidth = _c[1];
1553
- var _d = require$$1.useState(false), animate = _d[0], setAnimate = _d[1];
1552
+ var _c = React.useState(defaultWidgetButtonWidth), buttonWidth = _c[0], setButtonWidth = _c[1];
1553
+ var _d = React.useState(false), animate = _d[0], setAnimate = _d[1];
1554
1554
  var mobileWidth = ((_b = config === null || config === void 0 ? void 0 : config.mobile) === null || _b === void 0 ? void 0 : _b.applyAtLessThanWidth) || defaultNonMobileScreenWidth;
1555
1555
  // Determines mobile or normal
1556
1556
  var getConfigToApply = function () {
@@ -1563,7 +1563,7 @@ var ChatButton = function (_a) {
1563
1563
  }
1564
1564
  };
1565
1565
  var configToApply = getConfigToApply();
1566
- require$$1.useEffect(function () {
1566
+ React.useEffect(function () {
1567
1567
  var _a;
1568
1568
  var delayTimer;
1569
1569
  var timeoutTimer;
@@ -1606,7 +1606,7 @@ var ChatButton = function (_a) {
1606
1606
  };
1607
1607
  }, [configToApply, setAnimate, hasInteracted]);
1608
1608
  var animation = animate && !hasInteracted ? (configToApply === null || configToApply === void 0 ? void 0 : configToApply.animation) || "wiggle" : "none";
1609
- require$$1.useEffect(function () {
1609
+ React.useEffect(function () {
1610
1610
  var handleResize = function () {
1611
1611
  var screenWidth = window.innerWidth;
1612
1612
  var newButtonWidth = screenWidth < parseInt(mobileWidth, 10)
@@ -1788,7 +1788,7 @@ function execute(url, dispatch, visuals, behavior) {
1788
1788
  }
1789
1789
  function useOpenUrlCallback() {
1790
1790
  var env = useWidgetEnv();
1791
- return require$$1.useCallback(function (url, dispatch, visuals, behavior) {
1791
+ return React.useCallback(function (url, dispatch, visuals, behavior) {
1792
1792
  if (!behavior) {
1793
1793
  behavior = (env === null || env === void 0 ? void 0 : env.urls) ? resolveUrlPolicy(url, env.urls) : defaultBehavior;
1794
1794
  }
@@ -2105,7 +2105,7 @@ var LogChat = /** @class */ (function () {
2105
2105
  }());
2106
2106
 
2107
2107
  var jsxRuntime = require$$0;
2108
- var react = require$$1;
2108
+ var react = React;
2109
2109
 
2110
2110
  var IconButton = function (props) {
2111
2111
  var Icon = props.icon;
@@ -4593,7 +4593,9 @@ function convertFromListDisplay(list) {
4593
4593
  token: item.token,
4594
4594
  url: item.url,
4595
4595
  hideUrl: item.hideUrl,
4596
- imageUrl: (_a = item.image) === null || _a === void 0 ? void 0 : _a.url,
4596
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4597
+ // Prefer stentor-models image.url; fall back to server's flat imageUrl
4598
+ imageUrl: ((_a = item.image) === null || _a === void 0 ? void 0 : _a.url) || item.imageUrl,
4597
4599
  imageActionUrl: (_b = item.image) === null || _b === void 0 ? void 0 : _b.imageActionUrl
4598
4600
  };
4599
4601
  // TODO: Remove any when the buttons are defined on the list (ListButton - title + openUrlAction)
@@ -4639,13 +4641,17 @@ function convertToListDisplay(list) {
4639
4641
  };
4640
4642
  }
4641
4643
  function convertFromCardDisplay(card) {
4644
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4645
+ var cardAny = card;
4642
4646
  return {
4643
4647
  content: card.content,
4644
- imageUrl: card.smallImageUrl,
4648
+ // Prefer stentor-models smallImageUrl; fall back to server's flat imageUrl
4649
+ imageUrl: card.smallImageUrl || cardAny.imageUrl,
4645
4650
  title: card.title,
4646
4651
  imageActionUrl: card === null || card === void 0 ? void 0 : card.imageActionUrl,
4647
4652
  buttons: card.buttons ? card.buttons.map(function (button) { return ({
4648
- actionUrl: button.openUrlAction,
4653
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4654
+ actionUrl: button.openUrlAction || button.url,
4649
4655
  label: button.title
4650
4656
  }); }) : undefined
4651
4657
  };
@@ -10586,16 +10592,16 @@ function createChatServerCore(config, options) {
10586
10592
  function createChatServer(config, options) {
10587
10593
  return new LogChat(createChatServerCore(config, options));
10588
10594
  }
10589
- var ChatServerContext = require$$1.createContext(null);
10595
+ var ChatServerContext = React.createContext(null);
10590
10596
  function useChatServer(config, options) {
10591
- var _a = require$$1.useState(), server = _a[0], setServer = _a[1];
10597
+ var _a = React.useState(), server = _a[0], setServer = _a[1];
10592
10598
  var dispatch = useChatDispatch();
10593
10599
  var deps = [options, config, dispatch];
10594
10600
  // Track previous values to detect what changed
10595
- var prevDepsRef = require$$1.useRef(undefined);
10601
+ var prevDepsRef = React.useRef(undefined);
10596
10602
  // Log what caused the "effect"
10597
10603
  // useWhatChanged(deps, "options, config, dispatch");
10598
- require$$1.useEffect(function () {
10604
+ React.useEffect(function () {
10599
10605
  // Log when effect runs and what changed (for debugging connection issues)
10600
10606
  if (prevDepsRef.current) {
10601
10607
  var _a = prevDepsRef.current, prevOptions = _a[0], prevConfig = _a[1], prevDispatch = _a[2];
@@ -10634,8 +10640,8 @@ function useChatServer(config, options) {
10634
10640
 
10635
10641
  function useChatServerDispatch() {
10636
10642
  var inner = useChatDispatch();
10637
- var chatServer = require$$1.useContext(ChatServerContext);
10638
- return require$$1.useCallback(function (action) {
10643
+ var chatServer = React.useContext(ChatServerContext);
10644
+ return React.useCallback(function (action) {
10639
10645
  if (!action) {
10640
10646
  console.warn("react bug? Someone invokes with null");
10641
10647
  return;
@@ -10947,14 +10953,14 @@ var ChatHeader = function (props) {
10947
10953
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
10948
10954
  var innerDispatch = useChatDispatch();
10949
10955
  var menuConfig = props.menuConfig, onSubmit = props.onSubmit, debugMode = props.debugMode;
10950
- var _r = require$$1.useState(false), drawerOpen = _r[0], setDrawerState = _r[1]; // false initially
10956
+ var _r = React.useState(false), drawerOpen = _r[0], setDrawerState = _r[1]; // false initially
10951
10957
  var menuPosition = (menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.menuButtonLocation) || "FOOTER";
10952
10958
  var showMenuLeft = menuPosition === "HEADER_LEFT";
10953
10959
  var showMenuRight = menuPosition === "HEADER_RIGHT";
10954
10960
  var menuItemsRaw = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.items;
10955
10961
  var menuItemsTabIndex = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.itemsTabIndex;
10956
10962
  var menuButtonTabIndex = (_a = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.button) === null || _a === void 0 ? void 0 : _a.tabIndex;
10957
- var menuItems = require$$1.useMemo(function () { return (menuItemsRaw ? menuItemsRaw : []); }, [menuItemsRaw]);
10963
+ var menuItems = React.useMemo(function () { return (menuItemsRaw ? menuItemsRaw : []); }, [menuItemsRaw]);
10958
10964
  // Check if we have a right-side menu
10959
10965
  var hasRightMenu = showMenuRight && menuItems.length > 0;
10960
10966
  function toggleDrawer() {
@@ -11009,7 +11015,7 @@ var ChatMessagePart = function (props) {
11009
11015
 
11010
11016
  function useExecuteActionCallback() {
11011
11017
  var dispatch = useChatServerDispatch();
11012
- return require$$1.useCallback(function (text, meta) {
11018
+ return React.useCallback(function (text, meta) {
11013
11019
  dispatch(executeAction(text, meta));
11014
11020
  }, [dispatch]);
11015
11021
  }
@@ -11019,7 +11025,7 @@ function useButtonCallback() {
11019
11025
  var chatDispatch = useChatDispatch();
11020
11026
  var visuals = reactRedux.useSelector(function (state) { return state.visuals; });
11021
11027
  var executeAction = useExecuteActionCallback();
11022
- return require$$1.useCallback(function (button) {
11028
+ return React.useCallback(function (button) {
11023
11029
  if (button.actionUrl) {
11024
11030
  handleOpenUrl(button.actionUrl, chatDispatch, visuals);
11025
11031
  }
@@ -11060,7 +11066,7 @@ function isTable(display) {
11060
11066
 
11061
11067
  var CardMiddlewareWidget = function (props) {
11062
11068
  var msg = props.msg, ctx = props.ctx;
11063
- var card = require$$1.useMemo(function () { return convertFromCardDisplay(msg); }, [msg]);
11069
+ var card = React.useMemo(function () { return convertFromCardDisplay(msg); }, [msg]);
11064
11070
  var user = ctx.user;
11065
11071
  var handleButton = useButtonCallback();
11066
11072
  return (require$$0.jsx(ChatMessagePart, { showAvatar: true, user: user, children: require$$0.jsx("div", { className: "chat-msg", children: require$$0.jsx(ChatCard, { card: card, onButtonClick: handleButton }) }) }));
@@ -11110,9 +11116,9 @@ function createSubscribableArray(originalValue) {
11110
11116
  };
11111
11117
  }
11112
11118
  function useSubscribableArray(array) {
11113
- var _a = require$$1.useState(array.getArray()), res = _a[0], setRes = _a[1];
11119
+ var _a = React.useState(array.getArray()), res = _a[0], setRes = _a[1];
11114
11120
  var mounted = useIsMounted();
11115
- require$$1.useEffect(function () {
11121
+ React.useEffect(function () {
11116
11122
  var subscription = array.subscribe(function (newVal) {
11117
11123
  if (mounted()) {
11118
11124
  setRes(newVal);
@@ -11144,7 +11150,7 @@ function useGlobalSubscribableArray(storage) {
11144
11150
  }
11145
11151
  function useLateMiddlewaresBuilder(storage) {
11146
11152
  var middlewares = useGlobalSubscribableArray(storage);
11147
- return require$$1.useMemo(function () { return joinMiddlewares(middlewares); }, [middlewares]);
11153
+ return React.useMemo(function () { return joinMiddlewares(middlewares); }, [middlewares]);
11148
11154
  }
11149
11155
  var storage = createStorage(globalThis, "xappMsgMiddlewares");
11150
11156
  function useLateMiddleware() {
@@ -11156,7 +11162,7 @@ function getSvg() {
11156
11162
  }
11157
11163
  var ExternalLink = function (props) {
11158
11164
  var url = props.url;
11159
- var handleClick = require$$1.useCallback(function (ev) {
11165
+ var handleClick = React.useCallback(function (ev) {
11160
11166
  ev.preventDefault();
11161
11167
  }, []);
11162
11168
  return (require$$0.jsx("a", { href: url, "aria-label": "read more", target: "_blank", rel: "noreferrer", className: props.className, onClick: handleClick, children: getSvg() }));
@@ -11269,7 +11275,7 @@ function reduceLink(url, maxLength) {
11269
11275
 
11270
11276
  var SmartLink = function (props) {
11271
11277
  var url = props.url, className = props.className;
11272
- var handleClick = require$$1.useCallback(function (ev) {
11278
+ var handleClick = React.useCallback(function (ev) {
11273
11279
  ev.preventDefault();
11274
11280
  }, []);
11275
11281
  return (require$$0.jsx("a", { href: url, "aria-label": "read more", target: "_blank", rel: "noreferrer", className: className, onClick: handleClick, children: reduceLink(url, 40) }));
@@ -11285,7 +11291,7 @@ var ListItem = function (props) {
11285
11291
 
11286
11292
  var List = function (props) {
11287
11293
  var list = props.list;
11288
- var listRef = require$$1.useRef(null);
11294
+ var listRef = React.useRef(null);
11289
11295
  var hasImage = list.items.some(function (item) { return item.imageUrl; });
11290
11296
  var titlesOnly = !list.items.some(function (item) { var _a; return item.subTitle || ((_a = item.buttons) === null || _a === void 0 ? void 0 : _a.length); });
11291
11297
  var listItems = list.items.map(function (item, itemIndex) {
@@ -11299,9 +11305,9 @@ var ListMiddlewareWidget = function (props) {
11299
11305
  if (!ctx) {
11300
11306
  throw new TypeError("ctx not provided to ".concat(ListMiddlewareWidget.name));
11301
11307
  }
11302
- var list = require$$1.useMemo(function () { return convertFromListDisplay(msg); }, [msg]);
11308
+ var list = React.useMemo(function () { return convertFromListDisplay(msg); }, [msg]);
11303
11309
  var executeActionCallback = useExecuteActionCallback();
11304
- var handleExecute = require$$1.useCallback(function (ui, text, token) {
11310
+ var handleExecute = React.useCallback(function (ui, text, token) {
11305
11311
  executeActionCallback(text, { token: token, action: "click", ui: ui });
11306
11312
  }, [executeActionCallback]);
11307
11313
  var handleButton = useButtonCallback();
@@ -11318,7 +11324,7 @@ var ListMiddleware = function (next) { return function (props) {
11318
11324
 
11319
11325
  var MultiSelect = function (props) {
11320
11326
  var items = props.items, checked = props.checked, onChange = props.onChange;
11321
- var handleToggle = require$$1.useCallback(function (ev) {
11327
+ var handleToggle = React.useCallback(function (ev) {
11322
11328
  var _a;
11323
11329
  var id = ev.target.value;
11324
11330
  onChange(__assign(__assign({}, checked), (_a = {}, _a[id] = !checked[id], _a)));
@@ -11334,10 +11340,10 @@ function convertToMultiSelectItems(display) {
11334
11340
  }
11335
11341
  var MultiSelectMiddlewareWidget = function (props) {
11336
11342
  var msg = props.msg, ctx = props.ctx;
11337
- var items = require$$1.useMemo(function () { return convertToMultiSelectItems(msg); }, [msg]);
11343
+ var items = React.useMemo(function () { return convertToMultiSelectItems(msg); }, [msg]);
11338
11344
  var user = ctx.user;
11339
- var _a = require$$1.useState({}), checked = _a[0], setChecked = _a[1];
11340
- var handleSubmit = require$$1.useCallback(function () {
11345
+ var _a = React.useState({}), checked = _a[0], setChecked = _a[1];
11346
+ var handleSubmit = React.useCallback(function () {
11341
11347
  ctx.send({
11342
11348
  type: "custom",
11343
11349
  payload: JSON.stringify({
@@ -11385,14 +11391,14 @@ var StandardMiddlewaresBuilder = joinMiddlewares([
11385
11391
  ]);
11386
11392
  function useStandardMiddlewareBuilder() {
11387
11393
  var lateMiddleware = useLateMiddleware();
11388
- return require$$1.useMemo(function () { return joinMiddlewares([
11394
+ return React.useMemo(function () { return joinMiddlewares([
11389
11395
  lateMiddleware,
11390
11396
  StandardMiddlewaresBuilder,
11391
11397
  ]); }, [lateMiddleware]);
11392
11398
  }
11393
11399
  function useStandardMiddleware() {
11394
11400
  var builder = useStandardMiddlewareBuilder();
11395
- return require$$1.useMemo(function () { return builder(UnknownMessage); }, [builder]);
11401
+ return React.useMemo(function () { return builder(UnknownMessage); }, [builder]);
11396
11402
  }
11397
11403
  var StandardMiddlewares = StandardMiddlewaresBuilder(UnknownMessage);
11398
11404
 
@@ -11407,7 +11413,7 @@ function getTailSvg(owner) {
11407
11413
  }
11408
11414
  var ChatMessageBubble = function (props) {
11409
11415
  var owner = props.owner, onClick = props.onClick;
11410
- var handleClick = require$$1.useCallback(function () {
11416
+ var handleClick = React.useCallback(function () {
11411
11417
  if (onClick) {
11412
11418
  onClick();
11413
11419
  }
@@ -11418,18 +11424,18 @@ var ChatMessageBubble = function (props) {
11418
11424
  var ChatMarkdownMessage = function (props) {
11419
11425
  var onOpenUrl = props.onOpenUrl;
11420
11426
  var agentMessage = isAgent(props.message.user.nick);
11421
- var ref = require$$1.useRef(null);
11427
+ var ref = React.useRef(null);
11422
11428
  var chatDispatch = useChatDispatch();
11423
11429
  var visuals = reactRedux.useSelector(function (state) { return state.visuals; });
11424
11430
  var html = props.message.msg.html;
11425
- var handleLinkClick = require$$1.useCallback(function (ev) {
11431
+ var handleLinkClick = React.useCallback(function (ev) {
11426
11432
  if (onOpenUrl) {
11427
11433
  var link = ev.target;
11428
11434
  ev.preventDefault();
11429
11435
  onOpenUrl(link.href, chatDispatch, visuals);
11430
11436
  }
11431
11437
  }, [onOpenUrl]);
11432
- require$$1.useEffect(function () {
11438
+ React.useEffect(function () {
11433
11439
  if (ref.current) {
11434
11440
  ref.current.innerHTML = html;
11435
11441
  if (onOpenUrl) {
@@ -11460,21 +11466,21 @@ var ChatPermissionMessage = function (props) {
11460
11466
  var author = message.user;
11461
11467
  var allowLabel = "Allow";
11462
11468
  var denyLabel = "Deny";
11463
- var writeAsAgent = require$$1.useCallback(function (msg) {
11469
+ var writeAsAgent = React.useCallback(function (msg) {
11464
11470
  ctx.write({
11465
11471
  type: "msg",
11466
11472
  user: author,
11467
11473
  msg: msg,
11468
11474
  });
11469
11475
  }, [ctx, author]);
11470
- var writeAsUser = require$$1.useCallback(function (msg) {
11476
+ var writeAsUser = React.useCallback(function (msg) {
11471
11477
  ctx.write({
11472
11478
  type: "msg",
11473
11479
  user: user,
11474
11480
  msg: msg,
11475
11481
  });
11476
11482
  }, [ctx, user]);
11477
- var handleFail = require$$1.useCallback(function () {
11483
+ var handleFail = React.useCallback(function () {
11478
11484
  ctx.send({
11479
11485
  type: "msg",
11480
11486
  user: undefined,
@@ -11483,14 +11489,14 @@ var ChatPermissionMessage = function (props) {
11483
11489
  },
11484
11490
  });
11485
11491
  }, [ctx]);
11486
- var handleSend = require$$1.useCallback(function (msg) {
11492
+ var handleSend = React.useCallback(function (msg) {
11487
11493
  ctx.send({
11488
11494
  type: "permissionGrant",
11489
11495
  user: author,
11490
11496
  msg: msg,
11491
11497
  });
11492
11498
  }, [author, ctx]);
11493
- var handleResult = require$$1.useCallback(function (position, userMsg) {
11499
+ var handleResult = React.useCallback(function (position, userMsg) {
11494
11500
  handleSend({
11495
11501
  text: userMsg,
11496
11502
  location: position
@@ -11509,10 +11515,10 @@ var ChatPermissionMessage = function (props) {
11509
11515
  writeAsAgent(agentMsg);
11510
11516
  }
11511
11517
  }, [permissionRequest, writeAsUser, writeAsAgent, handleSend]);
11512
- var handleDeny = require$$1.useCallback(function (label) {
11518
+ var handleDeny = React.useCallback(function (label) {
11513
11519
  handleResult(undefined, label);
11514
11520
  }, [handleResult]);
11515
- var handleAllow = require$$1.useCallback(function (label) {
11521
+ var handleAllow = React.useCallback(function (label) {
11516
11522
  if (navigator.geolocation) {
11517
11523
  navigator.geolocation.getCurrentPosition(function (position) {
11518
11524
  handleResult(position, label);
@@ -11529,7 +11535,7 @@ var ChatPermissionMessage = function (props) {
11529
11535
 
11530
11536
  var CopyButton = function (_a) {
11531
11537
  var text = _a.text;
11532
- var _b = require$$1.useState(false), copied = _b[0], setCopied = _b[1];
11538
+ var _b = React.useState(false), copied = _b[0], setCopied = _b[1];
11533
11539
  var handleCopy = function (e) { return __awaiter$1(void 0, void 0, void 0, function () {
11534
11540
  var textarea;
11535
11541
  return __generator$1(this, function (_b) {
@@ -11585,7 +11591,7 @@ var ToolProgressItem = function (_a) {
11585
11591
  */
11586
11592
  var ToolCallItem = function (_a) {
11587
11593
  var toolCall = _a.toolCall;
11588
- var _b = require$$1.useState(false), isExpanded = _b[0], setIsExpanded = _b[1];
11594
+ var _b = React.useState(false), isExpanded = _b[0], setIsExpanded = _b[1];
11589
11595
  var toggleExpanded = function () { return setIsExpanded(!isExpanded); };
11590
11596
  var formatJson = function (data) {
11591
11597
  if (data === undefined || data === null)
@@ -11760,7 +11766,7 @@ var ChatTextMessage = function (props) {
11760
11766
  var agentMessage = isAgent((_a = props.message.user) === null || _a === void 0 ? void 0 : _a.nick);
11761
11767
  var isStreaming = message.isStreaming;
11762
11768
  // Parse markdown for agent messages
11763
- var parsedHtml = require$$1.useMemo(function () {
11769
+ var parsedHtml = React.useMemo(function () {
11764
11770
  if (agentMessage && message.msg.text) {
11765
11771
  return parseMarkdown(message.msg.text);
11766
11772
  }
@@ -11815,7 +11821,7 @@ var avaKeys = ["text", "html", "card", "list"];
11815
11821
  var ChatMessage = function (props) {
11816
11822
  var _a, _b, _c;
11817
11823
  var middleware = props.messageMiddleware || StandardMiddlewares;
11818
- var chatConfig = require$$1.useContext(ChatConfigContext);
11824
+ var chatConfig = React.useContext(ChatConfigContext);
11819
11825
  // console.log(`########### chatConfig: ${JSON.stringify(chatConfig, null, 2)}`);
11820
11826
  var ctx = props.middlewareContext;
11821
11827
  var user = props.agent;
@@ -11910,7 +11916,7 @@ function checkSessionExpiration(duration, lastMessageTimestamp, _lastTimestamp)
11910
11916
  }
11911
11917
 
11912
11918
  function useExternalScript(url) {
11913
- require$$1.useEffect(function () {
11919
+ React.useEffect(function () {
11914
11920
  if (!url) {
11915
11921
  return;
11916
11922
  }
@@ -11952,7 +11958,7 @@ function useChatServerVisitorId() {
11952
11958
  });
11953
11959
  var visitorAccessToken = reactRedux.useSelector(function (state) { return state.accessToken; });
11954
11960
  var attributes = reactRedux.useSelector(function (state) { return state.attributes; });
11955
- return require$$1.useMemo(function () { return ({
11961
+ return React.useMemo(function () { return ({
11956
11962
  dispatch: dispatch,
11957
11963
  visitorId: clientVisitorId,
11958
11964
  accessToken: visitorAccessToken,
@@ -11964,12 +11970,12 @@ function useChatServerVisitorId() {
11964
11970
  function useGreeting(active) {
11965
11971
  var _a, _b;
11966
11972
  var curr = useChatServerVisitorId();
11967
- var snapshotRef = require$$1.useRef(null);
11968
- var ctx = require$$1.useContext(ChatConfigContext);
11973
+ var snapshotRef = React.useRef(null);
11974
+ var ctx = React.useContext(ChatConfigContext);
11969
11975
  // Handle null context (e.g., in preview mode)
11970
11976
  var isAdmin = (_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.env) === null || _a === void 0 ? void 0 : _a.isAdmin) !== null && _b !== void 0 ? _b : false;
11971
11977
  var sessionId = reactRedux.useSelector(function (state) { return state.sessionId; });
11972
- require$$1.useEffect(function () {
11978
+ React.useEffect(function () {
11973
11979
  if (active) {
11974
11980
  if (snapshotRef.current !== curr) {
11975
11981
  snapshotRef.current = curr;
@@ -12014,18 +12020,18 @@ function norm(index, len) {
12014
12020
  return (index + len) % len;
12015
12021
  }
12016
12022
  function useSuggestions(search, context) {
12017
- var _a = require$$1.useState(), suggestions = _a[0], setSuggestions = _a[1];
12018
- var _b = require$$1.useState(-1), suggestionIndex = _b[0], setSuggestionIndex = _b[1];
12019
- var _c = require$$1.useState(search), query = _c[0], setQuery = _c[1];
12020
- var _d = require$$1.useState(context), contextState = _d[0], setContextState = _d[1];
12021
- require$$1.useEffect(function () {
12023
+ var _a = React.useState(), suggestions = _a[0], setSuggestions = _a[1];
12024
+ var _b = React.useState(-1), suggestionIndex = _b[0], setSuggestionIndex = _b[1];
12025
+ var _c = React.useState(search), query = _c[0], setQuery = _c[1];
12026
+ var _d = React.useState(context), contextState = _d[0], setContextState = _d[1];
12027
+ React.useEffect(function () {
12022
12028
  setQuery(search);
12023
12029
  }, [search]);
12024
- require$$1.useEffect(function () {
12030
+ React.useEffect(function () {
12025
12031
  setContextState(context);
12026
12032
  }, [context]);
12027
- var suggestionItem = require$$1.useMemo(function () { return suggestions ? findItemByIndex_1(suggestions, suggestionIndex) : undefined; }, [suggestions, suggestionIndex]);
12028
- var shift = require$$1.useCallback(function (delta) {
12033
+ var suggestionItem = React.useMemo(function () { return suggestions ? findItemByIndex_1(suggestions, suggestionIndex) : undefined; }, [suggestions, suggestionIndex]);
12034
+ var shift = React.useCallback(function (delta) {
12029
12035
  if (suggestions) {
12030
12036
  var len_1 = getItemsLength_1(suggestions);
12031
12037
  setSuggestionIndex(function (index) { return norm(index + delta + ((index < 0 && delta <= 0) ? 1 : 0), len_1); });
@@ -12034,7 +12040,7 @@ function useSuggestions(search, context) {
12034
12040
  setSuggestionIndex(-1);
12035
12041
  }
12036
12042
  }, [suggestions]);
12037
- var execute = require$$1.useCallback(function (cmd) {
12043
+ var execute = React.useCallback(function (cmd) {
12038
12044
  switch (cmd) {
12039
12045
  case "prev":
12040
12046
  shift(-1);
@@ -12051,7 +12057,7 @@ function useSuggestions(search, context) {
12051
12057
  }, [shift]);
12052
12058
  var suggestionsResponse = useSuggestionsFetch(query || "", contextState);
12053
12059
  var suggestionsData = suggestionsResponse.state === "success" ? suggestionsResponse.data : undefined;
12054
- var raw = require$$1.useMemo(function () {
12060
+ var raw = React.useMemo(function () {
12055
12061
  return suggestionsData ?
12056
12062
  parseSuggestionsResponse_1(suggestionsData, -1).map(function (suggestion) {
12057
12063
  return {
@@ -12060,14 +12066,14 @@ function useSuggestions(search, context) {
12060
12066
  };
12061
12067
  }) : undefined;
12062
12068
  }, [suggestionsData]);
12063
- require$$1.useEffect(function () {
12069
+ React.useEffect(function () {
12064
12070
  var prev = suggestionItem;
12065
12071
  setSuggestions(raw);
12066
12072
  if (!prev || !raw) {
12067
12073
  setSuggestionIndex(-1);
12068
12074
  }
12069
12075
  }, [raw, suggestionItem]);
12070
- return require$$1.useMemo(function () { return ({
12076
+ return React.useMemo(function () { return ({
12071
12077
  suggestions: suggestions,
12072
12078
  index: suggestionIndex,
12073
12079
  execute: execute,
@@ -12077,11 +12083,11 @@ function useSuggestions(search, context) {
12077
12083
 
12078
12084
  var AdminBar = function (_a) {
12079
12085
  var onAdminJoin = _a.onAdminJoin;
12080
- var name = require$$1.useRef(null);
12086
+ var name = React.useRef(null);
12081
12087
  // We can manage this locally
12082
12088
  // const hasAdminJoined = useSelector<ChatState, boolean | undefined>(state => state.hasAdminJoined);
12083
- var _b = require$$1.useState(false), joined = _b[0], setJoined = _b[1];
12084
- var _c = require$$1.useState(""), inputName = _c[0], setInputName = _c[1];
12089
+ var _b = React.useState(false), joined = _b[0], setJoined = _b[1];
12090
+ var _c = React.useState(""), inputName = _c[0], setInputName = _c[1];
12085
12091
  function handleInputChange(event) {
12086
12092
  setInputName(event.target.value);
12087
12093
  }
@@ -12232,7 +12238,7 @@ var SendIcon = function () {
12232
12238
 
12233
12239
  var SendButton = function (props) {
12234
12240
  var _a = props.disabled, disabled = _a === void 0 ? false : _a;
12235
- var _b = require$$1.useState(false), isHovered = _b[0], setIsHovered = _b[1];
12241
+ var _b = React.useState(false), isHovered = _b[0], setIsHovered = _b[1];
12236
12242
  // Determine which icon to show based on state
12237
12243
  var getIconSrc = function () {
12238
12244
  if (disabled && props.sendButtonIconDisabled) {
@@ -12251,7 +12257,7 @@ var COUNTER_THRESHOLD_PERCENT = 0.8;
12251
12257
  var Input = function (props) {
12252
12258
  var _a, _b;
12253
12259
  var value = props.value, placeholder = props.placeholder, sendButtonIcon = props.sendButtonIcon, sendButtonIconHover = props.sendButtonIconHover, sendButtonIconDisabled = props.sendButtonIconDisabled, suggestion = props.suggestion, footerConfig = props.footerConfig, inputConfig = props.inputConfig, onChange = props.onChange, onSubmit = props.onSubmit, onSuggestionCommand = props.onSuggestionCommand;
12254
- var _c = require$$1.useState(false), dragover = _c[0], setDragover = _c[1];
12260
+ var _c = React.useState(false), dragover = _c[0], setDragover = _c[1];
12255
12261
  var maxLength = inputConfig === null || inputConfig === void 0 ? void 0 : inputConfig.maxLength;
12256
12262
  var currentLength = value.text.length;
12257
12263
  var isAtLimit = maxLength !== undefined && currentLength >= maxLength;
@@ -12268,17 +12274,17 @@ var Input = function (props) {
12268
12274
  function onDragLeave() {
12269
12275
  setDragover(false);
12270
12276
  }
12271
- var handleOnSubmit = require$$1.useCallback(function (event) {
12277
+ var handleOnSubmit = React.useCallback(function (event) {
12272
12278
  event && event.preventDefault();
12273
12279
  onSubmit(value); // send to the widget
12274
12280
  }, [value, onSubmit]);
12275
- var handleClear = require$$1.useCallback(function () {
12281
+ var handleClear = React.useCallback(function () {
12276
12282
  onChange({
12277
12283
  text: "",
12278
12284
  formats: [],
12279
12285
  });
12280
12286
  }, [onChange]);
12281
- var handleKeyDown = require$$1.useCallback(function (event) {
12287
+ var handleKeyDown = React.useCallback(function (event) {
12282
12288
  if (suggestion) {
12283
12289
  if (event.key === "End" || event.key === "ArrowRight" || event.key === "Enter") {
12284
12290
  onChange(suggestion);
@@ -12312,7 +12318,7 @@ function createActions(onItemUse) {
12312
12318
  return function (innerProps) {
12313
12319
  var data = innerProps.data;
12314
12320
  var canUse = data.type !== "FAQ";
12315
- var handleUse = require$$1.useCallback(function (ev) {
12321
+ var handleUse = React.useCallback(function (ev) {
12316
12322
  onItemUse(data);
12317
12323
  ev.stopPropagation();
12318
12324
  }, [data]);
@@ -12324,9 +12330,9 @@ function createActions(onItemUse) {
12324
12330
  }
12325
12331
  var Suggestions = function (props) {
12326
12332
  var data = props.data, onItemUse = props.onItemUse, searchTerms = props.searchTerms;
12327
- var _a = require$$1.useState(), fixedSuggestions = _a[0], setFixedSuggestions = _a[1];
12328
- var _b = require$$1.useState(), activeItem = _b[0], setActiveItem = _b[1];
12329
- require$$1.useEffect(function () {
12333
+ var _a = React.useState(), fixedSuggestions = _a[0], setFixedSuggestions = _a[1];
12334
+ var _b = React.useState(), activeItem = _b[0], setActiveItem = _b[1];
12335
+ React.useEffect(function () {
12330
12336
  if (data) {
12331
12337
  setFixedSuggestions(data);
12332
12338
  }
@@ -12337,8 +12343,8 @@ var Suggestions = function (props) {
12337
12343
  }, [data, searchTerms]);
12338
12344
  var len = data === null || data === void 0 ? void 0 : data.length;
12339
12345
  var currentIndex = len > 0 ? props.index : NaN;
12340
- var item = require$$1.useMemo(function () { return findItemByIndex_1(data, currentIndex); }, [data, currentIndex]);
12341
- var handleSpanClick = require$$1.useCallback(function (target, span) {
12346
+ var item = React.useMemo(function () { return findItemByIndex_1(data, currentIndex); }, [data, currentIndex]);
12347
+ var handleSpanClick = React.useCallback(function (target, span) {
12342
12348
  if (span.type === "inputText") {
12343
12349
  onItemUse(target);
12344
12350
  setActiveItem(undefined);
@@ -12346,10 +12352,10 @@ var Suggestions = function (props) {
12346
12352
  }
12347
12353
  return undefined;
12348
12354
  }, [onItemUse]);
12349
- require$$1.useEffect(function () {
12355
+ React.useEffect(function () {
12350
12356
  setActiveItem(item);
12351
12357
  }, [item]);
12352
- var actions = require$$1.useMemo(function () { return createActions(onItemUse); }, [onItemUse]);
12358
+ var actions = React.useMemo(function () { return createActions(onItemUse); }, [onItemUse]);
12353
12359
  var transformContent = function (content) {
12354
12360
  var lines = content.split('\n');
12355
12361
  return lines.map(function (line) {
@@ -12368,8 +12374,8 @@ var ChatFooter = function (props) {
12368
12374
  var _a, _b, _c;
12369
12375
  var isAdmin = props.isAdmin, isChatting = props.isChatting, visible = props.visible, placeholder = props.placeholder, sendButtonIcon = props.sendButtonIcon, sendButtonIconHover = props.sendButtonIconHover, sendButtonIconDisabled = props.sendButtonIconDisabled, footerConfig = props.footerConfig, menuConfig = props.menuConfig, inputConfig = props.inputConfig, hasWsButton = props.hasWsButton, disabled = props.disabled, onSubmit = props.onSubmit;
12370
12376
  var innerDispatch = useChatDispatch();
12371
- var _d = require$$1.useState(false), drawerOpen = _d[0], setDrawerState = _d[1]; // false initially
12372
- var _e = require$$1.useState(), suggestionSearch = _e[0], setSuggestionSearch = _e[1];
12377
+ var _d = React.useState(false), drawerOpen = _d[0], setDrawerState = _d[1]; // false initially
12378
+ var _e = React.useState(), suggestionSearch = _e[0], setSuggestionSearch = _e[1];
12373
12379
  var contexts = reactRedux.useSelector(function (state) { return state.activeContexts; });
12374
12380
  var suggestions = useSuggestions(suggestionSearch, contexts);
12375
12381
  var menuPosition = (menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.menuButtonLocation) || "FOOTER";
@@ -12377,12 +12383,12 @@ var ChatFooter = function (props) {
12377
12383
  var menuItemsRaw = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.items;
12378
12384
  var menuItemsTabIndex = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.itemsTabIndex;
12379
12385
  var menuButtonTabIndex = (_a = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.button) === null || _a === void 0 ? void 0 : _a.tabIndex;
12380
- var menuItems = require$$1.useMemo(function () { return menuItemsRaw ? menuItemsRaw : []; }, [menuItemsRaw]);
12386
+ var menuItems = React.useMemo(function () { return menuItemsRaw ? menuItemsRaw : []; }, [menuItemsRaw]);
12381
12387
  var brandingEnabled = (_b = footerConfig === null || footerConfig === void 0 ? void 0 : footerConfig.branding) === null || _b === void 0 ? void 0 : _b.enabled;
12382
12388
  var brandingText = (_c = footerConfig === null || footerConfig === void 0 ? void 0 : footerConfig.branding) === null || _c === void 0 ? void 0 : _c.text;
12383
12389
  // If they are NOT an admin, automatically enabled the input
12384
- var _f = require$$1.useState(!isAdmin), enableInput = _f[0], setEnableInput = _f[1];
12385
- var _g = require$$1.useState({
12390
+ var _f = React.useState(!isAdmin), enableInput = _f[0], setEnableInput = _f[1];
12391
+ var _g = React.useState({
12386
12392
  text: "",
12387
12393
  formats: []
12388
12394
  }), input = _g[0], setInput = _g[1];
@@ -12403,7 +12409,7 @@ var ChatFooter = function (props) {
12403
12409
  setSuggestionSearch(val.text);
12404
12410
  }
12405
12411
  // Clears out suggestion and input text
12406
- var handleSubmit = require$$1.useCallback(function (message) {
12412
+ var handleSubmit = React.useCallback(function (message) {
12407
12413
  // Clears out the suggestions
12408
12414
  setSuggestionSearch("");
12409
12415
  // Clears out the input
@@ -12413,10 +12419,10 @@ var ChatFooter = function (props) {
12413
12419
  });
12414
12420
  onSubmit(message.text);
12415
12421
  }, [onSubmit]);
12416
- var handleItemClick = require$$1.useCallback(function (data) {
12422
+ var handleItemClick = React.useCallback(function (data) {
12417
12423
  handleSubmit(data);
12418
12424
  }, [handleSubmit]);
12419
- var handleItemUse = require$$1.useCallback(function (data) {
12425
+ var handleItemUse = React.useCallback(function (data) {
12420
12426
  setInput(data);
12421
12427
  setSuggestionSearch(data.text);
12422
12428
  }, []);
@@ -12459,15 +12465,15 @@ function buildFormConfig(buttonConfig, widgetEnv) {
12459
12465
  var FormModal = function (_a) {
12460
12466
  var _b, _c;
12461
12467
  var config = _a.config, widgetEnv = _a.widgetEnv, onClose = _a.onClose;
12462
- var modalRef = require$$1.useRef(null);
12463
- var contentRef = require$$1.useRef(null);
12468
+ var modalRef = React.useRef(null);
12469
+ var contentRef = React.useRef(null);
12464
12470
  var formConfig = buildFormConfig(config, widgetEnv);
12465
- var _d = require$$1.useState("idle"), loadingState = _d[0], setLoadingState = _d[1];
12466
- var _e = require$$1.useState(""), errorMessage = _e[0], setErrorMessage = _e[1];
12471
+ var _d = React.useState("idle"), loadingState = _d[0], setLoadingState = _d[1];
12472
+ var _e = React.useState(""), errorMessage = _e[0], setErrorMessage = _e[1];
12467
12473
  // Get the form widget key from config or widgetEnv
12468
12474
  var formWidgetKey = ((_c = (_b = config.formConfig) === null || _b === void 0 ? void 0 : _b.api) === null || _c === void 0 ? void 0 : _c.key) || (widgetEnv === null || widgetEnv === void 0 ? void 0 : widgetEnv.formWidgetKey);
12469
12475
  // Attempt to load and open the form widget
12470
- var attemptOpenFormWidget = require$$1.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
12476
+ var attemptOpenFormWidget = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
12471
12477
  var options, opened, options, opened;
12472
12478
  return __generator$1(this, function (_a) {
12473
12479
  switch (_a.label) {
@@ -12524,11 +12530,11 @@ var FormModal = function (_a) {
12524
12530
  });
12525
12531
  }); }, [config.preselectChipLabel, formWidgetKey, onClose]);
12526
12532
  // Attempt to open form widget on mount
12527
- require$$1.useEffect(function () {
12533
+ React.useEffect(function () {
12528
12534
  attemptOpenFormWidget();
12529
12535
  }, [attemptOpenFormWidget]);
12530
12536
  // Handle Escape key to close
12531
- require$$1.useEffect(function () {
12537
+ React.useEffect(function () {
12532
12538
  var handleKeyDown = function (event) {
12533
12539
  if (event.key === "Escape") {
12534
12540
  onClose();
@@ -12540,7 +12546,7 @@ var FormModal = function (_a) {
12540
12546
  };
12541
12547
  }, [onClose]);
12542
12548
  // Prevent body scroll when modal is open
12543
- require$$1.useEffect(function () {
12549
+ React.useEffect(function () {
12544
12550
  var originalOverflow = document.body.style.overflow;
12545
12551
  document.body.style.overflow = "hidden";
12546
12552
  return function () {
@@ -12548,18 +12554,18 @@ var FormModal = function (_a) {
12548
12554
  };
12549
12555
  }, []);
12550
12556
  // Focus trap - focus the modal content on mount
12551
- require$$1.useEffect(function () {
12557
+ React.useEffect(function () {
12552
12558
  if (contentRef.current) {
12553
12559
  contentRef.current.focus();
12554
12560
  }
12555
12561
  }, []);
12556
- var handleBackdropClick = require$$1.useCallback(function (event) {
12562
+ var handleBackdropClick = React.useCallback(function (event) {
12557
12563
  // Only close if clicking the backdrop, not the content
12558
12564
  if (event.target === modalRef.current) {
12559
12565
  onClose();
12560
12566
  }
12561
12567
  }, [onClose]);
12562
- var handleRetry = require$$1.useCallback(function () {
12568
+ var handleRetry = React.useCallback(function () {
12563
12569
  setLoadingState("idle");
12564
12570
  setErrorMessage("");
12565
12571
  attemptOpenFormWidget();
@@ -12613,13 +12619,13 @@ var ChatRating = function (_a) {
12613
12619
  var _b = _a.agent, agent = _b === void 0 ? {} : _b, _c = _a.hasRating, hasRating = _c === void 0 ? false : _c, _d = _a.shouldDisplay, shouldDisplay = _d === void 0 ? true : _d, _e = _a.onRate, onRate = _e === void 0 ? function () {
12614
12620
  // no-op
12615
12621
  } : _e;
12616
- var rateBadButtonOnClick = require$$1.useCallback(function () {
12622
+ var rateBadButtonOnClick = React.useCallback(function () {
12617
12623
  onRate("bad");
12618
12624
  }, [onRate]);
12619
- var rateGoodButtonOnClick = require$$1.useCallback(function () {
12625
+ var rateGoodButtonOnClick = React.useCallback(function () {
12620
12626
  onRate("good");
12621
12627
  }, [onRate]);
12622
- var rateAgainButtonOnClick = require$$1.useCallback(function () {
12628
+ var rateAgainButtonOnClick = React.useCallback(function () {
12623
12629
  onRate(undefined);
12624
12630
  }, [onRate]);
12625
12631
  // Do not think this prop should be here
@@ -12636,7 +12642,7 @@ var ChatRating = function (_a) {
12636
12642
 
12637
12643
  var ChatRatingContainer = function (props) {
12638
12644
  var dispatch = useChatServerDispatch();
12639
- var handleRate = require$$1.useCallback(function (rating) {
12645
+ var handleRate = React.useCallback(function (rating) {
12640
12646
  dispatch(sendChatRating(rating));
12641
12647
  }, [dispatch]);
12642
12648
  return (require$$0.jsxs(require$$0.Fragment, { children: [require$$0.jsx("span", { className: "message-sr-only", children: "at " + props.time + " system message" }), require$$0.jsx(ChatRating, { agent: props.agent, hasRating: props.hasRating, shouldDisplay: props.shouldDisplay, onRate: handleRate })] }));
@@ -34135,9 +34141,9 @@ function compileSlotValues(responseOutput, slots, replaceWhenUndefined) {
34135
34141
 
34136
34142
  var FailureMessage = function (props) {
34137
34143
  var agents = props.agents, text = props.text, delay = props.delay, time = props.time;
34138
- var _a = require$$1.useState(delay), countdown = _a[0], setCountdown = _a[1];
34144
+ var _a = React.useState(delay), countdown = _a[0], setCountdown = _a[1];
34139
34145
  var agent_names = Object.values(agents).filter(function (agent) { return agent.requestFailed; });
34140
- require$$1.useEffect(function () {
34146
+ React.useEffect(function () {
34141
34147
  if (delay !== 0) {
34142
34148
  var countdownValue_1 = delay;
34143
34149
  var myInterval_1 = setInterval(function () {
@@ -34152,7 +34158,7 @@ var FailureMessage = function (props) {
34152
34158
  setCountdown(5);
34153
34159
  }
34154
34160
  }, [delay]);
34155
- var slots = require$$1.useMemo(function () {
34161
+ var slots = React.useMemo(function () {
34156
34162
  return {
34157
34163
  sec: {
34158
34164
  name: "sec",
@@ -34160,7 +34166,7 @@ var FailureMessage = function (props) {
34160
34166
  },
34161
34167
  };
34162
34168
  }, [countdown]);
34163
- var failureMessage = require$$1.useMemo(function () {
34169
+ var failureMessage = React.useMemo(function () {
34164
34170
  return compileSlotValues(text, slots);
34165
34171
  }, [text, slots]);
34166
34172
  if (countdown === 0) {
@@ -34179,11 +34185,11 @@ var MessageSvg = function (_) {
34179
34185
  };
34180
34186
 
34181
34187
  var MessageForm = function (props) {
34182
- var name = require$$1.useRef(null);
34183
- var email = require$$1.useRef(null);
34184
- var message = require$$1.useRef(null);
34185
- var form = require$$1.useRef(null);
34186
- var _a = require$$1.useState(false), sent = _a[0], setSent = _a[1];
34188
+ var name = React.useRef(null);
34189
+ var email = React.useRef(null);
34190
+ var message = React.useRef(null);
34191
+ var form = React.useRef(null);
34192
+ var _a = React.useState(false), sent = _a[0], setSent = _a[1];
34187
34193
  function emailChanged() {
34188
34194
  var _a, _b, _c;
34189
34195
  if ((_a = email.current) === null || _a === void 0 ? void 0 : _a.validity.patternMismatch) {
@@ -34225,16 +34231,16 @@ var OfflineForm = function (props) {
34225
34231
 
34226
34232
  var OfflineFormContainer = function (props) {
34227
34233
  var dispatch = useChatServerDispatch();
34228
- var handleSubmit = require$$1.useCallback(function (data) {
34234
+ var handleSubmit = React.useCallback(function (data) {
34229
34235
  dispatch(sendOfflineMsg(data));
34230
34236
  }, [dispatch]);
34231
34237
  return (require$$0.jsxs(require$$0.Fragment, { children: [require$$0.jsx("span", { className: "message-sr-only", children: "at " + props.time + " system message" }), require$$0.jsx(OfflineForm, { onSubmit: handleSubmit })] }));
34232
34238
  };
34233
34239
 
34234
34240
  var PrechatForm = function (props) {
34235
- var _a = require$$1.useState(false), sent = _a[0], setSent = _a[1];
34241
+ var _a = React.useState(false), sent = _a[0], setSent = _a[1];
34236
34242
  var onSubmit = props.onSubmit;
34237
- var handleSubmit = require$$1.useCallback(function (msg) {
34243
+ var handleSubmit = React.useCallback(function (msg) {
34238
34244
  onSubmit(msg);
34239
34245
  setSent(true);
34240
34246
  }, [onSubmit]);
@@ -34244,7 +34250,7 @@ var PrechatForm = function (props) {
34244
34250
  var PrechatFormContainer = function (props) {
34245
34251
  var dispatch = useChatServerDispatch();
34246
34252
  var sessionId = reactRedux.useSelector(function (state) { return state.sessionId; });
34247
- var handleSubmit = require$$1.useCallback(function (data) {
34253
+ var handleSubmit = React.useCallback(function (data) {
34248
34254
  // Don't send empty messages
34249
34255
  if (!data.message)
34250
34256
  return;
@@ -34329,31 +34335,31 @@ var TypingStatus = function (props) {
34329
34335
 
34330
34336
  var MessageList = function (_a) {
34331
34337
  _a.visible; var _c = _a.messages, messages = _c === void 0 ? [] : _c, _d = _a.agents, agents = _d === void 0 ? {} : _d; _a.isOffline; _a.isChatting; var _g = _a.queuePosition, queuePosition = _g === void 0 ? 0 : _g, _h = _a.lastRatingRequestTimestamp, lastRatingRequestTimestamp = _h === void 0 ? 0 : _h, _j = _a.hasRating, hasRating = _j === void 0 ? false : _j; _a.visitorId; var messageMiddleware = _a.messageMiddleware, textTypingStatusEnabled = _a.textTypingStatusEnabled, agent = _a.agent, hasWsButton = _a.hasWsButton, _l = _a.disableAutoScroll, disableAutoScroll = _l === void 0 ? false : _l, _m = _a.onSend, onSend = _m === void 0 ? function () { return Promise.resolve(); } : _m, _o = _a.onWrite, onWrite = _o === void 0 ? function () { return Promise.resolve(); } : _o, _p = _a.onOpenUrl, onOpenUrl = _p === void 0 ? function () { } : _p, _q = _a.minimizeOnClick, minimizeOnClick = _q === void 0 ? function () { } : _q; _a.children;
34332
- var messagesEndRef = require$$1.useRef(null);
34333
- var containerRef = require$$1.useRef(null);
34334
- var prevHasWsButtonRef = require$$1.useRef(hasWsButton);
34338
+ var messagesEndRef = React.useRef(null);
34339
+ var containerRef = React.useRef(null);
34340
+ var prevHasWsButtonRef = React.useRef(hasWsButton);
34335
34341
  // Check if user is scrolled to bottom
34336
- var isAtBottom = require$$1.useCallback(function () {
34342
+ var isAtBottom = React.useCallback(function () {
34337
34343
  if (!containerRef.current)
34338
34344
  return true;
34339
34345
  var _a = containerRef.current, scrollTop = _a.scrollTop, scrollHeight = _a.scrollHeight, clientHeight = _a.clientHeight;
34340
34346
  return Math.abs(scrollHeight - clientHeight - scrollTop) < 10;
34341
34347
  }, []);
34342
34348
  // Scroll to bottom
34343
- var scrollToBottom = require$$1.useCallback(function (behavior) {
34349
+ var scrollToBottom = React.useCallback(function (behavior) {
34344
34350
  if (behavior === void 0) { behavior = "smooth"; }
34345
34351
  if (messagesEndRef.current) {
34346
34352
  messagesEndRef.current.scrollIntoView({ behavior: behavior });
34347
34353
  }
34348
34354
  }, []);
34349
34355
  // Always scroll to bottom when messages change (unless disabled)
34350
- require$$1.useEffect(function () {
34356
+ React.useEffect(function () {
34351
34357
  if (!disableAutoScroll) {
34352
34358
  scrollToBottom("smooth");
34353
34359
  }
34354
34360
  }, [messages, agents, scrollToBottom, disableAutoScroll]);
34355
34361
  // Handle WS button dismissal - only scroll when button is removed (unless disabled)
34356
- require$$1.useEffect(function () {
34362
+ React.useEffect(function () {
34357
34363
  if (disableAutoScroll) {
34358
34364
  return undefined;
34359
34365
  }
@@ -34374,19 +34380,19 @@ var MessageList = function (_a) {
34374
34380
  }
34375
34381
  return undefined;
34376
34382
  }, [hasWsButton, isAtBottom, scrollToBottom, disableAutoScroll]);
34377
- var handleSend = require$$1.useCallback(function (msg) {
34383
+ var handleSend = React.useCallback(function (msg) {
34378
34384
  onSend(msg);
34379
34385
  if (!disableAutoScroll && messagesEndRef.current) {
34380
34386
  messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
34381
34387
  }
34382
34388
  }, [onSend, disableAutoScroll]);
34383
- var handleWrite = require$$1.useCallback(function (msg) {
34389
+ var handleWrite = React.useCallback(function (msg) {
34384
34390
  onWrite(msg);
34385
34391
  if (!disableAutoScroll && messagesEndRef.current) {
34386
34392
  messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
34387
34393
  }
34388
34394
  }, [onWrite, disableAutoScroll]);
34389
- var ctxCache = require$$1.useMemo(function () {
34395
+ var ctxCache = React.useMemo(function () {
34390
34396
  return new MiddlewareContextFactory({
34391
34397
  send: handleSend,
34392
34398
  write: handleWrite,
@@ -34502,26 +34508,74 @@ var ServerOffline = function () {
34502
34508
  return (require$$0.jsxs("div", { className: "server-offline", children: [require$$0.jsx("h2", { children: "Chat is currently unavailable" }), require$$0.jsx("h3", { children: "Server is offline" })] }));
34503
34509
  };
34504
34510
 
34505
- function buildStyleContent(theme) {
34511
+ /**
34512
+ * Generates the [cssVariableName, value] pairs for a theme, e.g.
34513
+ * ["--xapp-primary-color", "#0096d3"].
34514
+ */
34515
+ function themeVariables(theme) {
34506
34516
  var _a, _b, _c, _d, _e;
34507
- 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)), withPrefix("action-bar-", getActionBarStyle(theme === null || theme === void 0 ? void 0 : theme.actionBar))))), "\n}");
34508
- }
34509
- function WidgetStylesheet(props) {
34510
- var theme = props.theme;
34511
- var stylesContent = buildStyleContent(theme);
34512
- return require$$0.jsx("style", { children: stylesContent });
34517
+ return withPrefix("--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)), withPrefix("action-bar-", getActionBarStyle(theme === null || theme === void 0 ? void 0 : theme.actionBar))));
34513
34518
  }
34514
- function buildVariables(gen) {
34519
+ /**
34520
+ * Collects the defined theme CSS variables as [name, value] entries, skipping
34521
+ * empty values.
34522
+ */
34523
+ function buildStyleVariables(theme) {
34524
+ var entries = [];
34525
+ var gen = themeVariables(theme);
34515
34526
  var result = gen.next();
34516
- var res = "";
34517
34527
  while (result.done === false) {
34518
34528
  var _a = result.value, key = _a[0], value = _a[1];
34519
34529
  if (value !== undefined && value !== null && value !== "") {
34520
- res += "".concat(key, ": ").concat(value, ";\n\r");
34530
+ entries.push([key, value]);
34521
34531
  }
34522
34532
  result = gen.next();
34523
34533
  }
34524
- return res;
34534
+ return entries;
34535
+ }
34536
+ // All instances apply their theme variables to the same target (:root), so a
34537
+ // per-variable ref-count ensures an unmounting instance only removes a variable
34538
+ // when no other mounted instance still relies on it.
34539
+ var appliedVariableCounts = new Map();
34540
+ function applyThemeVariables(entries) {
34541
+ var _a;
34542
+ var root = document.documentElement;
34543
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
34544
+ var _b = entries_1[_i], key = _b[0], value = _b[1];
34545
+ root.style.setProperty(key, value);
34546
+ appliedVariableCounts.set(key, ((_a = appliedVariableCounts.get(key)) !== null && _a !== void 0 ? _a : 0) + 1);
34547
+ }
34548
+ }
34549
+ function removeThemeVariables(entries) {
34550
+ var _a;
34551
+ var root = document.documentElement;
34552
+ for (var _i = 0, entries_2 = entries; _i < entries_2.length; _i++) {
34553
+ var key = entries_2[_i][0];
34554
+ var remaining = ((_a = appliedVariableCounts.get(key)) !== null && _a !== void 0 ? _a : 1) - 1;
34555
+ if (remaining <= 0) {
34556
+ appliedVariableCounts.delete(key);
34557
+ root.style.removeProperty(key);
34558
+ }
34559
+ else {
34560
+ appliedVariableCounts.set(key, remaining);
34561
+ }
34562
+ }
34563
+ }
34564
+ function WidgetStylesheet(props) {
34565
+ var theme = props.theme;
34566
+ // Apply the theme as CSS custom properties on :root via the CSSOM instead of
34567
+ // injecting a <style> tag: setProperty() is not governed by CSP style-src, so
34568
+ // the widget themes correctly under a strict policy (style-src 'self', no
34569
+ // 'unsafe-inline') without needing a nonce.
34570
+ var entriesKey = JSON.stringify(buildStyleVariables(theme));
34571
+ // Keyed on the resolved variables (not the theme reference) so a caller passing
34572
+ // an inline theme object doesn't re-fire the effect on every render.
34573
+ React.useLayoutEffect(function () {
34574
+ var entries = JSON.parse(entriesKey);
34575
+ applyThemeVariables(entries);
34576
+ return function () { return removeThemeVariables(entries); };
34577
+ }, [entriesKey]);
34578
+ return null;
34525
34579
  }
34526
34580
  function withPrefix(prefix, gen) {
34527
34581
  var result;
@@ -34859,13 +34913,13 @@ var safeStringify = function (arg) {
34859
34913
  };
34860
34914
  var ErrorOverlay = function (_a) {
34861
34915
  var enableErrorOverlay = _a.enableErrorOverlay;
34862
- var _b = require$$1.useState([]), errors = _b[0], setErrors = _b[1];
34863
- var _c = require$$1.useState(false), isMinimized = _c[0], setIsMinimized = _c[1];
34864
- var _d = require$$1.useState(true), isVisible = _d[0], setIsVisible = _d[1];
34865
- var _e = require$$1.useState(false), isEnabled = _e[0], setIsEnabled = _e[1];
34866
- var _f = require$$1.useState("bottom"), position = _f[0], setPosition = _f[1];
34916
+ var _b = React.useState([]), errors = _b[0], setErrors = _b[1];
34917
+ var _c = React.useState(false), isMinimized = _c[0], setIsMinimized = _c[1];
34918
+ var _d = React.useState(true), isVisible = _d[0], setIsVisible = _d[1];
34919
+ var _e = React.useState(false), isEnabled = _e[0], setIsEnabled = _e[1];
34920
+ var _f = React.useState("bottom"), position = _f[0], setPosition = _f[1];
34867
34921
  // Check if error overlay should be enabled and load position
34868
- require$$1.useEffect(function () {
34922
+ React.useEffect(function () {
34869
34923
  var _a;
34870
34924
  var checkEnabled = function () {
34871
34925
  var _a;
@@ -34904,7 +34958,7 @@ var ErrorOverlay = function (_a) {
34904
34958
  console.log("[ErrorOverlay] Component mounted, enabled:", enabled, "position:", savedPosition || "bottom");
34905
34959
  }, [enableErrorOverlay]);
34906
34960
  // Define addError with useCallback to prevent stale closures
34907
- var addError = require$$1.useCallback(function (error) {
34961
+ var addError = React.useCallback(function (error) {
34908
34962
  console.log("[ErrorOverlay] Adding error:", error);
34909
34963
  setErrors(function (prev) {
34910
34964
  var timestamp = new Date().toISOString();
@@ -34923,7 +34977,7 @@ var ErrorOverlay = function (_a) {
34923
34977
  return updated.slice(-50);
34924
34978
  });
34925
34979
  }, []);
34926
- require$$1.useEffect(function () {
34980
+ React.useEffect(function () {
34927
34981
  if (!isEnabled) {
34928
34982
  console.log("[ErrorOverlay] Not enabled, skipping error interception");
34929
34983
  return undefined;
@@ -35073,12 +35127,12 @@ var ErrorOverlay = function (_a) {
35073
35127
 
35074
35128
  var WsButton = function (_a) {
35075
35129
  var button = _a.button, onPress = _a.onPress;
35076
- var handleClick = require$$1.useCallback(function () {
35130
+ var handleClick = React.useCallback(function () {
35077
35131
  if (button.pressBehavior !== "disabled" && !button.isPressed) {
35078
35132
  onPress(button.id);
35079
35133
  }
35080
35134
  }, [button.pressBehavior, button.isPressed, button.id, onPress]);
35081
- var className = require$$1.useMemo(function () {
35135
+ var className = React.useMemo(function () {
35082
35136
  var classes = ["ws-button"];
35083
35137
  if (button.pressBehavior === "disabled" || button.isPressed) {
35084
35138
  classes.push("ws-button--disabled");
@@ -35088,7 +35142,7 @@ var WsButton = function (_a) {
35088
35142
  }
35089
35143
  return classes.join(" ");
35090
35144
  }, [button.pressBehavior, button.isPressed]);
35091
- var containerClassName = require$$1.useMemo(function () {
35145
+ var containerClassName = React.useMemo(function () {
35092
35146
  var classes = ["ws-button-container"];
35093
35147
  if (button.isDismissing) {
35094
35148
  classes.push("ws-button-container--dismissing");
@@ -35622,10 +35676,10 @@ function createStaticStore(state) {
35622
35676
 
35623
35677
  var StaticChatWidgetContainer = function (props) {
35624
35678
  var state = props.state;
35625
- var store = require$$1.useMemo(function () {
35679
+ var store = React.useMemo(function () {
35626
35680
  return createStaticStore(state);
35627
35681
  }, [state]);
35628
- var config = require$$1.useMemo(function () {
35682
+ var config = React.useMemo(function () {
35629
35683
  return __assign(__assign({}, props.config), { connection: {
35630
35684
  serverUrl: "",
35631
35685
  type: "local",
@@ -35636,7 +35690,7 @@ var StaticChatWidgetContainer = function (props) {
35636
35690
 
35637
35691
  var StaticMessagesChatWidgetContainer = function (props) {
35638
35692
  var messages = props.messages;
35639
- var state = require$$1.useMemo(function () {
35693
+ var state = React.useMemo(function () {
35640
35694
  return createStateFromMessages(messages);
35641
35695
  }, [messages]);
35642
35696
  return require$$0.jsx(StaticChatWidgetContainer, { state: state, mode: props.mode, config: props.config, disableAutoScroll: props.disableAutoScroll, preview: props.preview });
@@ -35720,7 +35774,7 @@ var ChatWidgetPreview = function (props) {
35720
35774
  var _a;
35721
35775
  var mode = (_a = props.mode) !== null && _a !== void 0 ? _a : "preview";
35722
35776
  // Memoize preview message conversion to avoid recalculating on every render
35723
- var previewChatDetails = require$$1.useMemo(function () {
35777
+ var previewChatDetails = React.useMemo(function () {
35724
35778
  return convertPreviewMessagesToChatDetails(props.previewMessages || [], props.config);
35725
35779
  }, [props.previewMessages, props.config]);
35726
35780
  return (require$$0.jsx(StaticMessagesChatWidgetContainer, { messages: previewChatDetails, mode: mode, config: props.config, disableAutoScroll: props.disableAutoScroll, preview: true }));
@@ -35731,11 +35785,11 @@ var ChatWidgetPreview = function (props) {
35731
35785
  var ChatWidgetConnected = function (props) {
35732
35786
  var _a;
35733
35787
  var mode = (_a = props.mode) !== null && _a !== void 0 ? _a : "normal";
35734
- var _b = require$$1.useState(props.config), rawConfig = _b[0], setRawConfig = _b[1];
35735
- var _c = require$$1.useState(!!props.getConfig), configLoading = _c[0], setConfigLoading = _c[1];
35736
- var _d = require$$1.useState(), configError = _d[0], setConfigError = _d[1];
35788
+ var _b = React.useState(props.config), rawConfig = _b[0], setRawConfig = _b[1];
35789
+ var _c = React.useState(!!props.getConfig), configLoading = _c[0], setConfigLoading = _c[1];
35790
+ var _d = React.useState(), configError = _d[0], setConfigError = _d[1];
35737
35791
  // Load config from callback if provided
35738
- require$$1.useEffect(function () {
35792
+ React.useEffect(function () {
35739
35793
  var cancelled = false;
35740
35794
  if (props.getConfig) {
35741
35795
  setConfigLoading(true);
@@ -35769,12 +35823,12 @@ var ChatWidgetConnected = function (props) {
35769
35823
  // eslint-disable-next-line react-hooks/exhaustive-deps
35770
35824
  }, [props.getConfig, props.config]);
35771
35825
  var connection = useConnectionInfo(rawConfig);
35772
- var config = require$$1.useMemo(function () {
35826
+ var config = React.useMemo(function () {
35773
35827
  var _a;
35774
35828
  return (__assign(__assign({}, rawConfig), { connection: connection, assetUrl: (_a = connection === null || connection === void 0 ? void 0 : connection.serverUrl) !== null && _a !== void 0 ? _a : defaultServerUrl, env: rawConfig }));
35775
35829
  }, [connection, rawConfig]);
35776
35830
  var token = reactRedux.useSelector(function (state) { return state.connection.token; });
35777
- var options = require$$1.useMemo(function () {
35831
+ var options = React.useMemo(function () {
35778
35832
  var configurableMessages = getConfigurableMessages();
35779
35833
  if ((rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.configurableMessages) &&
35780
35834
  Array.isArray(rawConfig.configurableMessages.items) &&
@@ -35824,7 +35878,7 @@ var ChatWidgetUI = function (props) {
35824
35878
  // From Redux
35825
35879
  var chatState = reactRedux.useSelector(function (state) { return state; });
35826
35880
  // Refresh modalReference
35827
- var modalRef = require$$1.useRef({});
35881
+ var modalRef = React.useRef({});
35828
35882
  var mode = (_a = props.mode) !== null && _a !== void 0 ? _a : "normal";
35829
35883
  var dockedMode = mode === "docked";
35830
35884
  var staticMode = mode === "static";
@@ -35855,24 +35909,24 @@ var ChatWidgetUI = function (props) {
35855
35909
  var autoOpenOnWidthMatch = !isNaN(autoOpenOnWidthValue) && window.innerWidth >= autoOpenOnWidthValue;
35856
35910
  // When autoOpenOnWidth is configured, use width check instead of persisted visible state
35857
35911
  // to prevent greeting requests on viewports below the threshold
35858
- var _14 = require$$1.useState((!canMinimize && !canCancel) ||
35912
+ var _14 = React.useState((!canMinimize && !canCancel) ||
35859
35913
  // !!get("visible") ||
35860
35914
  (!isNaN(autoOpenOnWidthValue) ? autoOpenOnWidthMatch : chatState.visuals.visible)), visible = _14[0], setVisibleState = _14[1];
35861
- var _15 = require$$1.useState(false); _15[0]; var setTypingState = _15[1]; // false initially - state kept for potential external observers
35915
+ var _15 = React.useState(false); _15[0]; var setTypingState = _15[1]; // false initially - state kept for potential external observers
35862
35916
  // Ref to track typing state for use in timeout callbacks
35863
- var typingRef = require$$1.useRef(false);
35917
+ var typingRef = React.useRef(false);
35864
35918
  // Timeout ref for debouncing "stop typing" events
35865
- var stopTypingTimeoutRef = require$$1.useRef(null);
35919
+ var stopTypingTimeoutRef = React.useRef(null);
35866
35920
  // Track whether autoOpenOnWidth has already fired so it doesn't re-open after user closes
35867
- var autoOpenFiredRef = require$$1.useRef(autoOpenOnWidthMatch);
35868
- var chatServer = require$$1.useContext(ChatServerContext);
35921
+ var autoOpenFiredRef = React.useRef(autoOpenOnWidthMatch);
35922
+ var chatServer = React.useContext(ChatServerContext);
35869
35923
  var patternsConfig = (_p = (_o = props.config) === null || _o === void 0 ? void 0 : _o.autoOpenOnPattern) === null || _p === void 0 ? void 0 : _p.patterns;
35870
35924
  var currentUrl = window.location.href;
35871
35925
  var patternExist = patternsConfig && patternsConfig.length > 0;
35872
35926
  var patternMatches = patternsConfig === null || patternsConfig === void 0 ? void 0 : patternsConfig.some(function (pattern) { return currentUrl.includes(pattern); });
35873
35927
  var configWidth = (_r = (_q = props.config) === null || _q === void 0 ? void 0 : _q.autoOpenOnPattern) === null || _r === void 0 ? void 0 : _r.minimumWidth;
35874
35928
  var currentWidth = window.innerWidth;
35875
- var setVisible = require$$1.useCallback(function (newVisible) {
35929
+ var setVisible = React.useCallback(function (newVisible) {
35876
35930
  if (staticMode || previewMode) {
35877
35931
  return;
35878
35932
  }
@@ -35882,7 +35936,7 @@ var ChatWidgetUI = function (props) {
35882
35936
  visible: newVisible,
35883
35937
  }));
35884
35938
  }, [innerDispatch, staticMode, previewMode]);
35885
- require$$1.useEffect(function () {
35939
+ React.useEffect(function () {
35886
35940
  var _a, _b;
35887
35941
  var handleKeyDown = function (event) {
35888
35942
  var body = document.getElementsByTagName("body")[0];
@@ -35905,8 +35959,8 @@ var ChatWidgetUI = function (props) {
35905
35959
  };
35906
35960
  // eslint-disable-next-line react-hooks/exhaustive-deps
35907
35961
  }, []);
35908
- var _16 = require$$1.useState(!document.hidden), isTabVisible = _16[0], setIsTabVisible = _16[1];
35909
- require$$1.useEffect(function () {
35962
+ var _16 = React.useState(!document.hidden), isTabVisible = _16[0], setIsTabVisible = _16[1];
35963
+ React.useEffect(function () {
35910
35964
  var handleVisibilityChange = function () {
35911
35965
  setIsTabVisible(!document.hidden);
35912
35966
  };
@@ -35915,7 +35969,7 @@ var ChatWidgetUI = function (props) {
35915
35969
  document.removeEventListener("visibilitychange", handleVisibilityChange);
35916
35970
  };
35917
35971
  }, []);
35918
- require$$1.useEffect(function () {
35972
+ React.useEffect(function () {
35919
35973
  // Too early?
35920
35974
  if (!chatServer) {
35921
35975
  log("Tab visibility changed but no chatServer yet");
@@ -35931,7 +35985,7 @@ var ChatWidgetUI = function (props) {
35931
35985
  }
35932
35986
  }, [chatServer, innerDispatch, isTabVisible]);
35933
35987
  // Handle beforeunload to notify router when user is leaving
35934
- require$$1.useEffect(function () {
35988
+ React.useEffect(function () {
35935
35989
  if (!chatServer) {
35936
35990
  return undefined;
35937
35991
  }
@@ -35946,7 +36000,7 @@ var ChatWidgetUI = function (props) {
35946
36000
  window.removeEventListener("beforeunload", handleBeforeUnload);
35947
36001
  };
35948
36002
  }, [chatServer]);
35949
- require$$1.useEffect(function () {
36003
+ React.useEffect(function () {
35950
36004
  // For reopen widget after move on same window
35951
36005
  // if (get("opened")) {
35952
36006
  // setVisible(true);
@@ -35977,7 +36031,7 @@ var ChatWidgetUI = function (props) {
35977
36031
  mode,
35978
36032
  autoOpenOnWidthMatch,
35979
36033
  ]);
35980
- var stopTyping = require$$1.useCallback(function () {
36034
+ var stopTyping = React.useCallback(function () {
35981
36035
  if (!typingRef.current)
35982
36036
  return;
35983
36037
  // Clear the timeout if it exists
@@ -35989,7 +36043,7 @@ var ChatWidgetUI = function (props) {
35989
36043
  setTypingState(false);
35990
36044
  typingRef.current = false;
35991
36045
  }, [dispatch]);
35992
- var handleOnChange = require$$1.useCallback(function () {
36046
+ var handleOnChange = React.useCallback(function () {
35993
36047
  // Send "typing" event only on first keystroke
35994
36048
  if (!typingRef.current) {
35995
36049
  dispatch(sendTyping(true));
@@ -36123,9 +36177,9 @@ var ChatWidgetUI = function (props) {
36123
36177
  }));
36124
36178
  }
36125
36179
  // Action Bar state and handlers
36126
- var _17 = require$$1.useState(false), formModalOpen = _17[0], setFormModalOpen = _17[1];
36127
- var _18 = require$$1.useState(null), activeFormConfig = _18[0], setActiveFormConfig = _18[1];
36128
- var handleFormButtonClick = require$$1.useCallback(function (formButton) {
36180
+ var _17 = React.useState(false), formModalOpen = _17[0], setFormModalOpen = _17[1];
36181
+ var _18 = React.useState(null), activeFormConfig = _18[0], setActiveFormConfig = _18[1];
36182
+ var handleFormButtonClick = React.useCallback(function (formButton) {
36129
36183
  // If form-widget is configured, use its openForm API
36130
36184
  // The form-widget script should already be pre-loaded
36131
36185
  var options = formButton.preselectChipLabel
@@ -36140,7 +36194,7 @@ var ChatWidgetUI = function (props) {
36140
36194
  }
36141
36195
  });
36142
36196
  }, []);
36143
- var handleFormModalClose = require$$1.useCallback(function () {
36197
+ var handleFormModalClose = React.useCallback(function () {
36144
36198
  setFormModalOpen(false);
36145
36199
  setActiveFormConfig(null);
36146
36200
  }, []);
@@ -36195,21 +36249,21 @@ var ChatWidgetUI = function (props) {
36195
36249
  // Disable greeting in preview mode
36196
36250
  useGreeting(!isOffline && !props.preChatFormEnabled && visible && !previewMode);
36197
36251
  var connectionStatus = chatState.connection.connectionStatus;
36198
- require$$1.useEffect(function () {
36252
+ React.useEffect(function () {
36199
36253
  if (onConnectionStatusChange) {
36200
36254
  onConnectionStatusChange(connectionStatus);
36201
36255
  }
36202
36256
  }, [connectionStatus, onConnectionStatusChange]);
36203
36257
  useExternalScript((_t = props.config) === null || _t === void 0 ? void 0 : _t.middlewareUrl);
36204
36258
  // Pre-load form-widget script if formWidgetKey is provided
36205
- require$$1.useEffect(function () {
36259
+ React.useEffect(function () {
36206
36260
  if (config === null || config === void 0 ? void 0 : config.formWidgetKey) {
36207
36261
  preloadFormWidgetScript(config.formWidgetKey);
36208
36262
  }
36209
36263
  }, [config === null || config === void 0 ? void 0 : config.formWidgetKey]);
36210
36264
  // Set body attribute when actionBar is enabled (used by CSS to hide form-widget side button on mobile)
36211
36265
  // Uses reference counting to handle multiple widget instances
36212
- require$$1.useEffect(function () {
36266
+ React.useEffect(function () {
36213
36267
  if (actionBarEnabled) {
36214
36268
  // Increment reference count
36215
36269
  var currentCount = parseInt(document.body.getAttribute("data-xapp-action-bar-count") || "0", 10);
@@ -36912,7 +36966,7 @@ var ChatWidgetConnectedContainer = function (props) {
36912
36966
  var _a, _b, _c, _d, _e, _f;
36913
36967
  var messageMiddleware = useStandardMiddleware();
36914
36968
  var connection = useServerConfig(props.config);
36915
- var chatStore = require$$1.useMemo(function () {
36969
+ var chatStore = React.useMemo(function () {
36916
36970
  var _a, _b, _c, _d, _e;
36917
36971
  return createChatStore({
36918
36972
  connection: connection,
@@ -36944,7 +36998,7 @@ var ChatWidgetContainer = function (props) {
36944
36998
  return require$$0.jsx(ChatWidgetConnectedContainer, __assign({}, props));
36945
36999
  };
36946
37000
 
36947
- exports.React = require$$1;
37001
+ exports.React = React;
36948
37002
  exports.ActionBar = ActionBar;
36949
37003
  exports.ActionBarPreview = ActionBarPreview;
36950
37004
  exports.ActionButton = ActionButton;