@xapp/chat-widget 1.94.4 → 1.96.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
@@ -6,10 +6,6 @@ var reactRedux = require('react-redux');
6
6
 
7
7
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
8
 
9
- function getDefaultExportFromCjs (x) {
10
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
11
- }
12
-
13
9
  var lib = {};
14
10
 
15
11
  var ActionBar$1 = {};
@@ -397,6 +393,17 @@ var ActionBarCta = function (_a) {
397
393
 
398
394
  var DEFAULT_MOBILE_BREAKPOINT = 768;
399
395
  var RESIZE_DEBOUNCE_MS = 150;
396
+ /**
397
+ * ChatWidget.scss sizes the chat panel against this variable. Nothing used to set it, so it always
398
+ * fell back to the hardcoded 80px in the SCSS - and the real mobile bar is taller than that once
399
+ * env(safe-area-inset-bottom) applies, which pushed the chat input row behind the bar. Measure the
400
+ * bar instead of guessing, so it also stays correct when a customer restyles it.
401
+ *
402
+ * This is written on documentElement, so it assumes one ActionBar per page - the same
403
+ * single-instance assumption the widget already makes for --xapp-widget-z-index and friends.
404
+ * Two concurrent bars would fight over it, and either one unmounting would clear it.
405
+ */
406
+ var ACTION_BAR_HEIGHT_VAR = "--xapp-action-bar-height";
400
407
  var ActionBar = function (_a) {
401
408
  var _b, _c, _d;
402
409
  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;
@@ -404,6 +411,7 @@ var ActionBar = function (_a) {
404
411
  var mobileBreakpoint = (_b = config.mobileBreakpoint) !== null && _b !== void 0 ? _b : DEFAULT_MOBILE_BREAKPOINT;
405
412
  var position = (_c = config.position) !== null && _c !== void 0 ? _c : "right";
406
413
  var resizeTimeoutRef = React.useRef(null);
414
+ var barRef = React.useRef(null);
407
415
  // Debounced resize handler
408
416
  var handleResize = React.useCallback(function () {
409
417
  if (resizeTimeoutRef.current) {
@@ -424,6 +432,41 @@ var ActionBar = function (_a) {
424
432
  }
425
433
  };
426
434
  }, [mobileBreakpoint, handleResize]);
435
+ // Publish the bar's real height so the chat panel can size around it.
436
+ //
437
+ // useLayoutEffect, not useEffect: this commits before paint, so the panel never gets a
438
+ // frame laid out against the 80px SCSS fallback. useEffect would run after paint and
439
+ // reintroduce a one-frame version of the very misalignment this is here to remove.
440
+ React.useLayoutEffect(function () {
441
+ var bar = barRef.current;
442
+ if (!bar) {
443
+ return undefined;
444
+ }
445
+ var publishHeight = function () {
446
+ // getBoundingClientRect covers the whole border box, including the safe-area padding
447
+ // the mobile bar adds - which is exactly the space the chat panel has to clear.
448
+ var height = bar.getBoundingClientRect().height;
449
+ // A zero height means the bar is hidden or not laid out yet. Publishing 0px would
450
+ // be worse than the SCSS fallback, so leave whatever is already there alone.
451
+ if (height <= 0) {
452
+ return;
453
+ }
454
+ document.documentElement.style.setProperty(ACTION_BAR_HEIGHT_VAR, "".concat(height, "px"));
455
+ };
456
+ publishHeight();
457
+ // Older browsers without ResizeObserver keep the mount-time measurement above.
458
+ if (typeof ResizeObserver === "undefined") {
459
+ return function () {
460
+ document.documentElement.style.removeProperty(ACTION_BAR_HEIGHT_VAR);
461
+ };
462
+ }
463
+ var observer = new ResizeObserver(publishHeight);
464
+ observer.observe(bar);
465
+ return function () {
466
+ observer.disconnect();
467
+ document.documentElement.style.removeProperty(ACTION_BAR_HEIGHT_VAR);
468
+ };
469
+ }, [isMobile]);
427
470
  // Filter out chat buttons if chat is disabled
428
471
  var filteredButtons = chatDisabled
429
472
  ? config.buttons.filter(function (button) { return !lib.isActionBarChatButton(button); })
@@ -448,7 +491,7 @@ var ActionBar = function (_a) {
448
491
  var handleCtaDismiss = function () {
449
492
  onCtaDismiss === null || onCtaDismiss === void 0 ? void 0 : onCtaDismiss();
450
493
  };
451
- return (require$$0.jsxs("div", { className: classNames, role: "toolbar", "aria-label": "Chat actions", children: [showCta && (require$$0.jsx("div", { className: "xapp-action-bar-cta-wrapper", children: require$$0.jsx(ActionBarCta, { config: config.cta, isMobile: isMobile, onClick: handleCtaClick, onDismiss: handleCtaDismiss, hasUserInteracted: hasUserInteracted }) })), require$$0.jsx("div", { className: "xapp-action-bar__buttons", children: filteredButtons.map(function (button) { return (require$$0.jsx(ActionBarButton, { button: button, chatActive: visible, onChatClick: onChatClick, onChatMinimize: onChatMinimize, onFormClick: onFormClick, isMobile: isMobile }, button.id)); }) })] }));
494
+ return (require$$0.jsxs("div", { ref: barRef, className: classNames, role: "toolbar", "aria-label": "Chat actions", children: [showCta && (require$$0.jsx("div", { className: "xapp-action-bar-cta-wrapper", children: require$$0.jsx(ActionBarCta, { config: config.cta, isMobile: isMobile, onClick: handleCtaClick, onDismiss: handleCtaDismiss, hasUserInteracted: hasUserInteracted }) })), require$$0.jsx("div", { className: "xapp-action-bar__buttons", children: filteredButtons.map(function (button) { return (require$$0.jsx(ActionBarButton, { button: button, chatActive: visible, onChatClick: onChatClick, onChatMinimize: onChatMinimize, onFormClick: onFormClick, isMobile: isMobile }, button.id)); }) })] }));
452
495
  };
453
496
 
454
497
  /**
@@ -2306,8 +2349,9 @@ var RichText = function (props) {
2306
2349
  };
2307
2350
 
2308
2351
  var RichInput = function (props) {
2309
- var id = props.id, value = props.value, type = props.type, autoFocus = props.autoFocus, spellCheck = props.spellCheck, tabIndex = props.tabIndex, maxLength = props.maxLength, onChange = props.onChange, onInput = props.onInput, onKeyDown = props.onKeyDown, onSearch = props.onSearch;
2352
+ var id = props.id, value = props.value, type = props.type, autoFocus = props.autoFocus, spellCheck = props.spellCheck, tabIndex = props.tabIndex, maxLength = props.maxLength, enterKeyHint = props.enterKeyHint, onChange = props.onChange, onInput = props.onInput, onKeyDown = props.onKeyDown, onSearch = props.onSearch;
2310
2353
  var rich = value.formats.some(function (f) { return f.type === "inputText"; });
2354
+ var keyHint = enterKeyHint || (type === "search" ? "search" : "send");
2311
2355
  var handleChange = react.useCallback(function (ev) {
2312
2356
  if (onChange) {
2313
2357
  onChange({
@@ -2359,7 +2403,7 @@ var RichInput = function (props) {
2359
2403
  }
2360
2404
  return undefined;
2361
2405
  }, [inputNode, onSearch]);
2362
- return (jsxRuntime.jsx("div", { className: "xappw-rich-input ".concat(props.className), children: rich ? (jsxRuntime.jsx(RichText, { id: id, value: value, onChange: handleRichChange, onInput: handleRichInput, onKeyDown: handleKeyDown, className: "xappw-rich-input__input ".concat(props.className, "__input") })) : (jsxRuntime.jsx("input", { id: id, ref: inputRef, type: type, value: value.text, autoComplete: "off", autoFocus: autoFocus, placeholder: props.placeholder, spellCheck: spellCheck, tabIndex: tabIndex ? Number(tabIndex) : 0, maxLength: maxLength, className: "xappw-rich-input__input ".concat(props.className, "__input"), onFocus: props.onFocus, onChange: handleChange, onInput: handleInput, onKeyDown: handleKeyDown })) }));
2406
+ return (jsxRuntime.jsx("div", { className: "xappw-rich-input ".concat(props.className), children: rich ? (jsxRuntime.jsx(RichText, { id: id, value: value, onChange: handleRichChange, onInput: handleRichInput, onKeyDown: handleKeyDown, className: "xappw-rich-input__input ".concat(props.className, "__input") })) : (jsxRuntime.jsx("input", { id: id, ref: inputRef, type: type, value: value.text, autoComplete: "off", enterKeyHint: keyHint, autoFocus: autoFocus, placeholder: props.placeholder, spellCheck: spellCheck, tabIndex: tabIndex ? Number(tabIndex) : 0, maxLength: maxLength, className: "xappw-rich-input__input ".concat(props.className, "__input"), onFocus: props.onFocus, onChange: handleChange, onInput: handleInput, onKeyDown: handleKeyDown })) }));
2363
2407
  };
2364
2408
 
2365
2409
  var SuggestionsGroupHeading = function (props) {
@@ -2703,6 +2747,268 @@ function useSuggestionsFetch$1(options) {
2703
2747
  return response;
2704
2748
  }
2705
2749
 
2750
+ /**
2751
+ * Stop the host page scrolling behind an open overlay.
2752
+ *
2753
+ * `body { overflow: hidden }` is the obvious way to do this, and is what both widgets used
2754
+ * to do — but **iOS Safari ignores `overflow: hidden` on the body**, so the customer's page
2755
+ * carried on scrolling under the modal. The technique that does work there is to take the
2756
+ * body out of flow at a negative offset equal to the current scroll position, then put it
2757
+ * back and re-scroll to that exact position on release.
2758
+ *
2759
+ * Reference counted rather than a plain on/off flag, and the count lives on the `<body>`
2760
+ * element rather than in module scope. That is deliberate: the chat widget's `FormModal`
2761
+ * loads the **standalone** form widget bundle, which carries its own copy of this module,
2762
+ * so the two overlays that can be open at once are not sharing any JS state. With a module
2763
+ * counter, the second lock would read the already-pinned scroll position (which the browser
2764
+ * reports as 0), the first release would unpin the body while the second overlay was still
2765
+ * open, and the second release would then re-apply `position: fixed` and leave the host page
2766
+ * stuck. The DOM is the only thing both bundles can agree on.
2767
+ */
2768
+ /** How many overlays currently hold the lock. Absent means unlocked. */
2769
+ var COUNT_ATTRIBUTE$1 = "data-xapp-scroll-lock";
2770
+ /** What to put back when the last one lets go, as JSON. */
2771
+ var RESTORE_ATTRIBUTE = "data-xapp-scroll-lock-restore";
2772
+ var PINNED_PROPERTIES = ["position", "top", "left", "right", "width", "overflow"];
2773
+ function readCount$1(body) {
2774
+ var count = Number(body.getAttribute(COUNT_ATTRIBUTE$1));
2775
+ return Number.isFinite(count) && count > 0 ? count : 0;
2776
+ }
2777
+ function captureRestorePoint(body) {
2778
+ var inlineStyles = PINNED_PROPERTIES.reduce(function (styles, property) {
2779
+ styles[property] = body.style.getPropertyValue(property);
2780
+ return styles;
2781
+ }, {});
2782
+ return { scrollY: window.scrollY || window.pageYOffset || 0, inlineStyles: inlineStyles };
2783
+ }
2784
+ function takeRestorePoint(body) {
2785
+ var serialized = body.getAttribute(RESTORE_ATTRIBUTE);
2786
+ body.removeAttribute(RESTORE_ATTRIBUTE);
2787
+ try {
2788
+ var parsed = JSON.parse(serialized || "");
2789
+ if (parsed && typeof parsed.scrollY === "number" && parsed.inlineStyles) {
2790
+ return parsed;
2791
+ }
2792
+ }
2793
+ catch (_a) {
2794
+ // Fall through: something else rewrote the attribute. Better to clear our own
2795
+ // properties and leave the page usable than to throw and leave it pinned.
2796
+ }
2797
+ return { scrollY: 0, inlineStyles: {} };
2798
+ }
2799
+ /**
2800
+ * Lock the body and return the release function.
2801
+ *
2802
+ * The returned function is idempotent — calling it twice is a no-op, which matters because
2803
+ * React StrictMode runs an effect's cleanup more than once.
2804
+ */
2805
+ function lockBodyScroll() {
2806
+ if (typeof document === "undefined" || typeof window === "undefined") {
2807
+ return function () { return undefined; };
2808
+ }
2809
+ var body = document.body;
2810
+ if (readCount$1(body) === 0) {
2811
+ var restorePoint = captureRestorePoint(body);
2812
+ body.setAttribute(RESTORE_ATTRIBUTE, JSON.stringify(restorePoint));
2813
+ body.style.position = "fixed";
2814
+ body.style.top = "-".concat(restorePoint.scrollY, "px");
2815
+ body.style.left = "0";
2816
+ body.style.right = "0";
2817
+ body.style.width = "100%";
2818
+ // Redundant next to `position: fixed`, but harmless, and it keeps the behaviour the
2819
+ // widgets already had on the browsers that do honour it.
2820
+ body.style.overflow = "hidden";
2821
+ }
2822
+ body.setAttribute(COUNT_ATTRIBUTE$1, String(readCount$1(body) + 1));
2823
+ var released = false;
2824
+ return function releaseBodyScroll() {
2825
+ if (released) {
2826
+ return;
2827
+ }
2828
+ released = true;
2829
+ var remaining = readCount$1(body) - 1;
2830
+ if (remaining > 0) {
2831
+ body.setAttribute(COUNT_ATTRIBUTE$1, String(remaining));
2832
+ return;
2833
+ }
2834
+ if (remaining < 0) {
2835
+ return;
2836
+ }
2837
+ body.removeAttribute(COUNT_ATTRIBUTE$1);
2838
+ var _a = takeRestorePoint(body), scrollY = _a.scrollY, inlineStyles = _a.inlineStyles;
2839
+ PINNED_PROPERTIES.forEach(function (property) {
2840
+ if (inlineStyles[property]) {
2841
+ body.style.setProperty(property, inlineStyles[property]);
2842
+ }
2843
+ else {
2844
+ body.style.removeProperty(property);
2845
+ }
2846
+ });
2847
+ // An empty `style=""` on the host page's body is untidy and is not what we found.
2848
+ if (!body.style.length) {
2849
+ body.removeAttribute("style");
2850
+ }
2851
+ window.scrollTo(0, scrollY);
2852
+ };
2853
+ }
2854
+ /**
2855
+ * Lock the body scroll for as long as the calling component is mounted.
2856
+ *
2857
+ * The cleanup runs on unmount, so a modal that disappears without a clean close — a route
2858
+ * change, a parent re-render, an error boundary — still leaves the page scrollable.
2859
+ */
2860
+ function useBodyScrollLock(enabled) {
2861
+ if (enabled === void 0) { enabled = true; }
2862
+ react.useEffect(function () {
2863
+ if (!enabled) {
2864
+ return undefined;
2865
+ }
2866
+ return lockBodyScroll();
2867
+ }, [enabled]);
2868
+ }
2869
+
2870
+ /**
2871
+ * Publish the visual viewport's geometry as CSS custom properties, so overlays can size
2872
+ * themselves around the soft keyboard.
2873
+ *
2874
+ * We are an **embedded** widget: the customer owns the host page's `<meta name="viewport">`,
2875
+ * so we cannot add `interactive-widget=resizes-content` and let the browser solve this for
2876
+ * us. Reading `window.visualViewport` ourselves is the only mechanism we control. (Injecting
2877
+ * or mutating the host's viewport meta is not an option — it is not ours, and breaking it
2878
+ * breaks the whole page in ways nobody would attribute to us.)
2879
+ *
2880
+ * Three properties are published on `<html>`:
2881
+ *
2882
+ * --xapp-viewport-height the visible height, in px
2883
+ * --xapp-viewport-offset-top how far the visual viewport has been scrolled down within
2884
+ * the layout viewport — nonzero on iOS when the keyboard
2885
+ * pushes the page up
2886
+ * --xapp-keyboard-inset layout height minus visual height: how much the keyboard
2887
+ * (or any other browser UI) is covering
2888
+ *
2889
+ * `--xapp-keyboard-inset` is the one worth having. It is what a `padding-bottom` wants, and
2890
+ * deriving it here means the consuming CSS does not have to do arithmetic across two
2891
+ * variables that update at slightly different moments.
2892
+ *
2893
+ * Reference counted on the DOM, for the same reason `bodyScrollLock` is: chat-widget's
2894
+ * `FormModal` loads the **standalone** form-widget bundle, which carries its own copy of
2895
+ * this module. Two independent copies can be live at once, and a module-scope counter would
2896
+ * not see across them. Without counting, closing the form modal while the chat panel is
2897
+ * still open (with the keyboard still up) would clear the properties out from under the
2898
+ * panel and snap it back to its fallback height mid-interaction.
2899
+ */
2900
+ var HEIGHT_PROPERTY = "--xapp-viewport-height";
2901
+ var OFFSET_TOP_PROPERTY = "--xapp-viewport-offset-top";
2902
+ var KEYBOARD_INSET_PROPERTY = "--xapp-keyboard-inset";
2903
+ /** How many subscribers currently want these properties maintained. */
2904
+ var COUNT_ATTRIBUTE = "data-xapp-viewport-subscribers";
2905
+ /**
2906
+ * Below this, a shrunken viewport is treated as browser chrome rather than a keyboard.
2907
+ * Address bars collapse and expand by ~60-90px during normal scrolling, and reacting to
2908
+ * that would make the layout twitch while the user is only reading.
2909
+ */
2910
+ var KEYBOARD_THRESHOLD_PX = 120;
2911
+ function readCount(root) {
2912
+ var count = Number(root.getAttribute(COUNT_ATTRIBUTE));
2913
+ return Number.isFinite(count) && count > 0 ? count : 0;
2914
+ }
2915
+ /**
2916
+ * Write the current geometry to `<html>`.
2917
+ *
2918
+ * Deliberately does nothing when `visualViewport` is unavailable: the consuming CSS falls
2919
+ * back to `100dvh`, which is correct-ish and certainly better than a zero height. Publishing
2920
+ * `0px` would collapse the widget entirely — a worse failure than the one being fixed.
2921
+ */
2922
+ function publish(root) {
2923
+ var viewport = typeof window === "undefined" ? undefined : window.visualViewport;
2924
+ if (!viewport) {
2925
+ return;
2926
+ }
2927
+ var height = viewport.height, offsetTop = viewport.offsetTop;
2928
+ if (!(height > 0)) {
2929
+ // Mid-transition, or a browser reporting nonsense. Keep the last good values.
2930
+ return;
2931
+ }
2932
+ // window.innerHeight is the LAYOUT viewport, which the keyboard does not shrink on iOS.
2933
+ // The difference between the two is the occluded strip.
2934
+ var layoutHeight = window.innerHeight || height;
2935
+ var rawInset = Math.max(0, layoutHeight - height);
2936
+ var inset = rawInset >= KEYBOARD_THRESHOLD_PX ? rawInset : 0;
2937
+ root.style.setProperty(HEIGHT_PROPERTY, "".concat(Math.round(height), "px"));
2938
+ root.style.setProperty(OFFSET_TOP_PROPERTY, "".concat(Math.round(offsetTop), "px"));
2939
+ root.style.setProperty(KEYBOARD_INSET_PROPERTY, "".concat(Math.round(inset), "px"));
2940
+ }
2941
+ function clear(root) {
2942
+ root.style.removeProperty(HEIGHT_PROPERTY);
2943
+ root.style.removeProperty(OFFSET_TOP_PROPERTY);
2944
+ root.style.removeProperty(KEYBOARD_INSET_PROPERTY);
2945
+ }
2946
+ /**
2947
+ * Start publishing viewport geometry. Returns a release function.
2948
+ *
2949
+ * Imperative twin of {@link useVisualViewportProperties}, for callers outside React.
2950
+ */
2951
+ function trackVisualViewport() {
2952
+ if (typeof document === "undefined") {
2953
+ return function () { return undefined; };
2954
+ }
2955
+ var root = document.documentElement;
2956
+ root.setAttribute(COUNT_ATTRIBUTE, String(readCount(root) + 1));
2957
+ publish(root);
2958
+ var viewport = typeof window === "undefined" ? undefined : window.visualViewport;
2959
+ var frame;
2960
+ var onChange = function () {
2961
+ // These fire many times per second through the keyboard animation. Coalescing to one
2962
+ // write per frame keeps us off the layout-thrash path.
2963
+ if (frame !== undefined) {
2964
+ return;
2965
+ }
2966
+ frame = window.requestAnimationFrame(function () {
2967
+ frame = undefined;
2968
+ publish(root);
2969
+ });
2970
+ };
2971
+ // `scroll` matters as much as `resize`: on iOS the keyboard scrolls the visual viewport
2972
+ // within the layout viewport, and offsetTop only changes on that event.
2973
+ viewport === null || viewport === void 0 ? void 0 : viewport.addEventListener("resize", onChange);
2974
+ viewport === null || viewport === void 0 ? void 0 : viewport.addEventListener("scroll", onChange);
2975
+ var released = false;
2976
+ return function () {
2977
+ if (released) {
2978
+ return;
2979
+ }
2980
+ released = true;
2981
+ viewport === null || viewport === void 0 ? void 0 : viewport.removeEventListener("resize", onChange);
2982
+ viewport === null || viewport === void 0 ? void 0 : viewport.removeEventListener("scroll", onChange);
2983
+ if (frame !== undefined) {
2984
+ window.cancelAnimationFrame(frame);
2985
+ frame = undefined;
2986
+ }
2987
+ var remaining = readCount(root) - 1;
2988
+ if (remaining > 0) {
2989
+ root.setAttribute(COUNT_ATTRIBUTE, String(remaining));
2990
+ return;
2991
+ }
2992
+ root.removeAttribute(COUNT_ATTRIBUTE);
2993
+ clear(root);
2994
+ };
2995
+ }
2996
+ /**
2997
+ * Publish viewport geometry for as long as this component is mounted.
2998
+ *
2999
+ * @param enabled pass `false` to opt out — e.g. above the mobile breakpoint, where there is
3000
+ * no soft keyboard to work around and the desktop sizing should stand.
3001
+ */
3002
+ function useVisualViewportProperties(enabled) {
3003
+ if (enabled === void 0) { enabled = true; }
3004
+ react.useEffect(function () {
3005
+ if (!enabled) {
3006
+ return undefined;
3007
+ }
3008
+ return trackVisualViewport();
3009
+ }, [enabled]);
3010
+ }
3011
+
2706
3012
  /**
2707
3013
  * Quicker configurable uuid
2708
3014
  *
@@ -2729,7 +3035,9 @@ var SuggestionsList_1 = SuggestionsList;
2729
3035
  var findItemByIndex_1 = findItemByIndex;
2730
3036
  var getItemsLength_1 = getItemsLength;
2731
3037
  var parseSuggestionsResponse_1 = parseSuggestionsResponse;
3038
+ var useBodyScrollLock_1 = useBodyScrollLock;
2732
3039
  var useSuggestionsFetch_1 = useSuggestionsFetch$1;
3040
+ var useVisualViewportProperties_1 = useVisualViewportProperties;
2733
3041
  var uuid_1 = uuid;
2734
3042
 
2735
3043
  var cjs = {};
@@ -12117,85 +12425,15 @@ var AdminBar = function (_a) {
12117
12425
  return (require$$0.jsx("div", { className: "xappw-admin-input-container visible", children: joined ? renderLeave() : renderJoin() }));
12118
12426
  };
12119
12427
 
12120
- var classnames = {exports: {}};
12121
-
12122
- /*!
12123
- Copyright (c) 2018 Jed Watson.
12124
- Licensed under the MIT License (MIT), see
12125
- http://jedwatson.github.io/classnames
12126
- */
12127
-
12128
- (function (module) {
12129
- /* global define */
12130
-
12131
- (function () {
12132
-
12133
- var hasOwn = {}.hasOwnProperty;
12134
-
12135
- function classNames () {
12136
- var classes = '';
12137
-
12138
- for (var i = 0; i < arguments.length; i++) {
12139
- var arg = arguments[i];
12140
- if (arg) {
12141
- classes = appendClass(classes, parseValue(arg));
12142
- }
12143
- }
12144
-
12145
- return classes;
12146
- }
12147
-
12148
- function parseValue (arg) {
12149
- if (typeof arg === 'string' || typeof arg === 'number') {
12150
- return arg;
12151
- }
12152
-
12153
- if (typeof arg !== 'object') {
12154
- return '';
12155
- }
12156
-
12157
- if (Array.isArray(arg)) {
12158
- return classNames.apply(null, arg);
12159
- }
12160
-
12161
- if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {
12162
- return arg.toString();
12163
- }
12164
-
12165
- var classes = '';
12166
-
12167
- for (var key in arg) {
12168
- if (hasOwn.call(arg, key) && arg[key]) {
12169
- classes = appendClass(classes, key);
12170
- }
12171
- }
12172
-
12173
- return classes;
12174
- }
12175
-
12176
- function appendClass (value, newClass) {
12177
- if (!newClass) {
12178
- return value;
12179
- }
12180
-
12181
- if (value) {
12182
- return value + ' ' + newClass;
12183
- }
12184
-
12185
- return value + newClass;
12186
- }
12187
-
12188
- if (module.exports) {
12189
- classNames.default = classNames;
12190
- module.exports = classNames;
12191
- } else {
12192
- window.classNames = classNames;
12193
- }
12194
- }());
12195
- } (classnames));
12196
-
12197
- var classnamesExports = classnames.exports;
12198
- var classNames = /*@__PURE__*/getDefaultExportFromCjs(classnamesExports);
12428
+ /**
12429
+ * Joins the keys of `classes` whose value is truthy into a single
12430
+ * space-separated string. Local replacement for the `classnames` package.
12431
+ */
12432
+ function classNames(classes) {
12433
+ return Object.keys(classes)
12434
+ .filter(function (key) { return classes[key]; })
12435
+ .join(" ");
12436
+ }
12199
12437
 
12200
12438
  var MarkdownBuilder = function (_a) {
12201
12439
  var text = _a.text, applyBrandingClass = _a.applyBrandingClass, linkColor = _a.linkColor;
@@ -12545,14 +12783,11 @@ var FormModal = function (_a) {
12545
12783
  document.removeEventListener("keydown", handleKeyDown);
12546
12784
  };
12547
12785
  }, [onClose]);
12548
- // Prevent body scroll when modal is open
12549
- React.useEffect(function () {
12550
- var originalOverflow = document.body.style.overflow;
12551
- document.body.style.overflow = "hidden";
12552
- return function () {
12553
- document.body.style.overflow = originalOverflow;
12554
- };
12555
- }, []);
12786
+ // Prevent body scroll when modal is open.
12787
+ //
12788
+ // This used to set `body { overflow: hidden }` directly, which iOS Safari ignores - the
12789
+ // host page scrolled on underneath the open modal.
12790
+ useBodyScrollLock_1();
12556
12791
  // Focus trap - focus the modal content on mount
12557
12792
  React.useEffect(function () {
12558
12793
  if (contentRef.current) {
@@ -35543,6 +35778,20 @@ var createQueueWithTimer = (timeout) => {
35543
35778
  setTimeout(notify, timeout);
35544
35779
  };
35545
35780
  };
35781
+ var createRafWithFallbackTimer = (raf, timeout) => {
35782
+ return (notify) => {
35783
+ let called = false;
35784
+ const callback = () => {
35785
+ if (called) return;
35786
+ called = true;
35787
+ cancelAnimationFrame(rafId);
35788
+ clearTimeout(timerId);
35789
+ notify();
35790
+ };
35791
+ const rafId = raf(callback);
35792
+ const timerId = setTimeout(callback, timeout);
35793
+ };
35794
+ };
35546
35795
  var autoBatchEnhancer = (options = {
35547
35796
  type: "raf"
35548
35797
  }) => (next) => (...args) => {
@@ -35553,7 +35802,7 @@ var autoBatchEnhancer = (options = {
35553
35802
  const listeners = /* @__PURE__ */ new Set();
35554
35803
  const queueCallback = options.type === "tick" ? queueMicrotask : options.type === "raf" ? (
35555
35804
  // requestAnimationFrame won't exist in SSR environments. Fall back to a vague approximation just to keep from erroring.
35556
- typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame : createQueueWithTimer(10)
35805
+ typeof window !== "undefined" && window.requestAnimationFrame ? createRafWithFallbackTimer(window.requestAnimationFrame, 100) : createQueueWithTimer(10)
35557
35806
  ) : options.type === "callback" ? options.queueNotification : createQueueWithTimer(options.timeout);
35558
35807
  const notifyListeners = () => {
35559
35808
  notificationQueued = false;
@@ -35875,6 +36124,14 @@ var ChatWidgetUI = function (props) {
35875
36124
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13;
35876
36125
  var innerDispatch = useChatDispatch();
35877
36126
  var dispatch = useChatServerDispatch();
36127
+ // Publish the visual viewport's geometry so the panel can size around the soft keyboard.
36128
+ //
36129
+ // Mounted unconditionally rather than behind a width check, and the mobile-only scoping
36130
+ // lives in ChatWidget.scss instead: only the max-width: 640px block reads
36131
+ // --xapp-keyboard-inset, so on desktop this publishes properties nothing consumes and
36132
+ // behaviour is unchanged. A width check here would mean a fourth hardcoded 640 in a
36133
+ // codebase where that duplication is already an open issue (#1561).
36134
+ useVisualViewportProperties_1();
35878
36135
  // From Redux
35879
36136
  var chatState = reactRedux.useSelector(function (state) { return state; });
35880
36137
  // Refresh modalReference