@getwidgets/live-chat-widget 1.0.8 → 1.1.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.
@@ -19750,7 +19750,7 @@
19750
19750
  }
19751
19751
  return sessionId;
19752
19752
  };
19753
- const LiveChatWidget = ({ widgetId, apiKey, name: name2 = null, email = null, unique_id = null }) => {
19753
+ const LiveChatWidget = ({ widgetId, name: name2 = null, email = null, unique_id = null }) => {
19754
19754
  var _a, _b;
19755
19755
  const [config, setConfig] = reactExports.useState(null);
19756
19756
  const [messages, setMessages] = reactExports.useState([]);
@@ -19843,6 +19843,7 @@
19843
19843
  const stored = localStorage.getItem("widgetkraft_livechat_authtoken");
19844
19844
  setLocalStorageToken(stored);
19845
19845
  if (stored && !authToken) setAuthToken(stored);
19846
+ if (stored) setShowContactFields(false);
19846
19847
  } catch (e) {
19847
19848
  }
19848
19849
  const handleStorageChange = (e) => {
@@ -19851,6 +19852,7 @@
19851
19852
  const stored = localStorage.getItem("widgetkraft_livechat_authtoken");
19852
19853
  setLocalStorageToken(stored);
19853
19854
  if (stored && !authToken) setAuthToken(stored);
19855
+ if (stored) setShowContactFields(false);
19854
19856
  } catch (err) {
19855
19857
  }
19856
19858
  }
@@ -19873,6 +19875,7 @@
19873
19875
  } catch (e) {
19874
19876
  }
19875
19877
  setAuthToken(token);
19878
+ setShowContactFields(false);
19876
19879
  }
19877
19880
  } catch (e) {
19878
19881
  console.warn("Failed to create auth token", e);
@@ -19907,7 +19910,7 @@
19907
19910
  reactExports.useEffect(() => {
19908
19911
  if (!widgetId) return;
19909
19912
  fetchWidgetConfig(widgetId).then((data) => setConfig(data)).catch((err) => console.error("Failed to load widget config:", err));
19910
- }, [widgetId, apiKey]);
19913
+ }, [widgetId]);
19911
19914
  reactExports.useEffect(() => {
19912
19915
  const checkAndInitializeSession = async () => {
19913
19916
  var _a2;
@@ -20299,12 +20302,17 @@
20299
20302
  const isMobile = windowWidth < 768;
20300
20303
  reactExports.useEffect(() => {
20301
20304
  if (inputAreaConfig == null ? void 0 : inputAreaConfig.allow_chat_with_email) {
20302
- const hasToken = authToken || localStorageToken;
20305
+ let hasToken = false;
20306
+ try {
20307
+ hasToken = !!(authToken || localStorage.getItem("widgetkraft_livechat_authtoken"));
20308
+ } catch (e) {
20309
+ hasToken = !!authToken;
20310
+ }
20303
20311
  setShowContactFields(!hasToken);
20304
20312
  } else {
20305
20313
  setShowContactFields(false);
20306
20314
  }
20307
- }, [inputAreaConfig == null ? void 0 : inputAreaConfig.allow_chat_with_email, authToken, localStorageToken, isOpen]);
20315
+ }, [inputAreaConfig == null ? void 0 : inputAreaConfig.allow_chat_with_email, authToken, isOpen]);
20308
20316
  const isContactValid = !(inputAreaConfig == null ? void 0 : inputAreaConfig.allow_chat_with_email) || (!showContactFields ? true : contactName.trim() && contactEmail.trim());
20309
20317
  const createAndStoreAuthToken = () => {
20310
20318
  const payload = { name: contactName.trim(), email: contactEmail.trim(), unique_id };
@@ -20789,7 +20797,7 @@
20789
20797
  }
20790
20798
  `));
20791
20799
  };
20792
- function init({ widgetId, apiKey, mode = "inline", name: name2 = null, email = null, unique_id = null }) {
20800
+ function init({ widgetId, mode = "inline", name: name2 = null, email = null, unique_id = null }) {
20793
20801
  const container = document.getElementById("livechat-root");
20794
20802
  if (!container) {
20795
20803
  console.error("Live Chat Widget root element (#livechat-root) not found.");
@@ -20813,7 +20821,6 @@
20813
20821
  LiveChatWidget,
20814
20822
  {
20815
20823
  widgetId,
20816
- apiKey,
20817
20824
  name: name2,
20818
20825
  email,
20819
20826
  unique_id
@@ -20833,7 +20840,34 @@
20833
20840
  mountPoint.appendChild(errDiv);
20834
20841
  }
20835
20842
  }
20836
- window.LiveChatWidget = { init };
20843
+ let userDetails = { name: null, email: null, unique_id: null };
20844
+ function setUser({ name: name2, email, unique_id }) {
20845
+ if (userDetails.name !== name2 || userDetails.email !== email || userDetails.unique_id !== unique_id) {
20846
+ userDetails = { name: name2, email, unique_id };
20847
+ const container = document.getElementById("livechat-root");
20848
+ if (container && container.__livechat_mounted) {
20849
+ const shadowRoot = container.shadowRoot;
20850
+ if (shadowRoot) {
20851
+ const mountPoint = shadowRoot.getElementById("live-chat-widget-mount") || shadowRoot.querySelector("#live-chat-widget-mount");
20852
+ if (mountPoint) {
20853
+ const root2 = client.createRoot(mountPoint);
20854
+ root2.render(
20855
+ /* @__PURE__ */ React.createElement(React.StrictMode, null, /* @__PURE__ */ React.createElement(
20856
+ LiveChatWidget,
20857
+ {
20858
+ widgetId: container.dataset.widgetId,
20859
+ name: name2,
20860
+ email,
20861
+ unique_id
20862
+ }
20863
+ ))
20864
+ );
20865
+ }
20866
+ }
20867
+ }
20868
+ }
20869
+ }
20870
+ window.LiveChatWidget = { init, setUser };
20837
20871
  exports2.init = init;
20838
20872
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
20839
20873
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getwidgets/live-chat-widget",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "main": "dist/live-chat-widget.umd.js",
5
5
  "unpkg": "dist/live-chat-widget.umd.js",
6
6
  "type": "module",