@getwidgets/live-chat-widget 1.1.3 → 1.1.4

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.
@@ -19753,6 +19753,7 @@
19753
19753
  const LiveChatWidget = ({ widgetId, name: name2 = null, email = null, unique_id = null }) => {
19754
19754
  var _a, _b;
19755
19755
  const [showMenu, setShowMenu] = reactExports.useState(false);
19756
+ const endChatButtonRef = reactExports.useRef(null);
19756
19757
  const [config, setConfig] = reactExports.useState(null);
19757
19758
  const [messages, setMessages] = reactExports.useState([]);
19758
19759
  const [inputMessage, setInputMessage] = reactExports.useState("");
@@ -20340,14 +20341,38 @@
20340
20341
  };
20341
20342
  reactExports.useEffect(() => {
20342
20343
  if (!showMenu) return;
20343
- const handler = (e) => {
20344
- if (!e.target.closest(".livechat-menu-trigger") && !e.target.closest(".livechat-menu-popup")) {
20345
- setShowMenu(false);
20344
+ const handleClickOutside = (e) => {
20345
+ try {
20346
+ const composedPath = e.composedPath ? e.composedPath() : [e.target];
20347
+ const hasMenuElement = composedPath.some((el2) => {
20348
+ if (!el2.classList) return false;
20349
+ const isMenuTrigger = el2.classList.contains("livechat-menu-trigger");
20350
+ const isMenuPopup = el2.classList.contains("livechat-menu-popup");
20351
+ return isMenuTrigger || isMenuPopup;
20352
+ });
20353
+ if (!hasMenuElement) {
20354
+ setShowMenu(false);
20355
+ }
20356
+ } catch (err) {
20346
20357
  }
20347
20358
  };
20348
- document.addEventListener("mousedown", handler);
20349
- return () => document.removeEventListener("mousedown", handler);
20359
+ document.addEventListener("click", handleClickOutside, false);
20360
+ return () => {
20361
+ document.removeEventListener("click", handleClickOutside, false);
20362
+ };
20350
20363
  }, [showMenu]);
20364
+ reactExports.useEffect(() => {
20365
+ const btn = endChatButtonRef.current;
20366
+ if (!btn) return;
20367
+ const handleClick = (e) => {
20368
+ e.preventDefault();
20369
+ e.stopPropagation();
20370
+ handleEndChat();
20371
+ setShowMenu(false);
20372
+ };
20373
+ btn.addEventListener("click", handleClick, true);
20374
+ return () => btn.removeEventListener("click", handleClick, true);
20375
+ }, []);
20351
20376
  if (!config) return null;
20352
20377
  const handleStartNewChat = () => {
20353
20378
  try {
@@ -20370,6 +20395,9 @@
20370
20395
  setInputMessage("");
20371
20396
  setIsSessionInitialized(false);
20372
20397
  setShowMenu(false);
20398
+ setContactName("");
20399
+ setContactEmail("");
20400
+ setShowContactFields(!!(inputAreaConfig == null ? void 0 : inputAreaConfig.allow_chat_with_email));
20373
20401
  } catch (e) {
20374
20402
  }
20375
20403
  };
@@ -20575,21 +20603,35 @@
20575
20603
  /* @__PURE__ */ React.createElement(
20576
20604
  "button",
20577
20605
  {
20606
+ ref: endChatButtonRef,
20578
20607
  className: "transition-all duration-200 hover:bg-red-50",
20608
+ type: "button",
20609
+ tabIndex: "0",
20579
20610
  style: {
20580
20611
  background: "none",
20581
20612
  border: "none",
20582
20613
  width: "100%",
20583
20614
  cursor: "pointer",
20584
- // padding: isMobile ? '8px 12px' : '6px 12px',
20585
- minHeight: "auto",
20615
+ padding: isMobile ? "8px 12px" : "6px 12px",
20616
+ minHeight: "32px",
20586
20617
  fontSize: isMobile ? "14px" : "13px",
20587
20618
  color: "#DC2626",
20588
20619
  fontWeight: "500",
20589
- borderRadius: "6px"
20590
- // margin: '4px 0'
20620
+ borderRadius: "6px",
20621
+ margin: "0",
20622
+ display: "flex",
20623
+ alignItems: "center",
20624
+ justifyContent: "center",
20625
+ userSelect: "none"
20591
20626
  },
20592
- onClick: handleEndChat
20627
+ onClick: (e) => {
20628
+ var _a2, _b2;
20629
+ e.preventDefault();
20630
+ e.stopPropagation();
20631
+ (_b2 = (_a2 = e.nativeEvent) == null ? void 0 : _a2.stopImmediatePropagation) == null ? void 0 : _b2.call(_a2);
20632
+ handleEndChat();
20633
+ setTimeout(() => setShowMenu(false), 0);
20634
+ }
20593
20635
  },
20594
20636
  "End Chat"
20595
20637
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getwidgets/live-chat-widget",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "main": "dist/live-chat-widget.umd.js",
5
5
  "unpkg": "dist/live-chat-widget.umd.js",
6
6
  "type": "module",