@getwidgets/live-chat-widget 1.1.0 → 1.1.1

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.
@@ -20797,74 +20797,71 @@
20797
20797
  }
20798
20798
  `));
20799
20799
  };
20800
- function init({ widgetId, mode = "inline", name: name2 = null, email = null, unique_id = null }) {
20800
+ let reactRoot = null;
20801
+ let userDetails = { name: null, email: null, unique_id: null };
20802
+ let currentWidgetId = null;
20803
+ function init({
20804
+ widgetId,
20805
+ mode = "inline",
20806
+ name: name2 = null,
20807
+ email = null,
20808
+ unique_id = null
20809
+ }) {
20801
20810
  const container = document.getElementById("livechat-root");
20802
20811
  if (!container) {
20803
- console.error("Live Chat Widget root element (#livechat-root) not found.");
20812
+ console.error(
20813
+ "Live Chat Widget root element (#livechat-root) not found."
20814
+ );
20804
20815
  return;
20805
20816
  }
20806
- container.innerHTML = "";
20807
- delete container.__livechat_mounted;
20808
- const shadowRoot = container.attachShadow({ mode: "open" });
20809
- const mountPoint = document.createElement("div");
20810
- mountPoint.id = "live-chat-widget-mount";
20811
- shadowRoot.appendChild(mountPoint);
20812
- const styles = document.createElement("style");
20813
- styles.textContent = `
20814
- @import url("https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css");
20815
- `;
20816
- shadowRoot.appendChild(styles);
20817
- const root2 = client.createRoot(mountPoint);
20818
- try {
20819
- root2.render(
20817
+ currentWidgetId = widgetId;
20818
+ container.dataset.widgetId = widgetId;
20819
+ if (!container.__livechat_mounted) {
20820
+ container.innerHTML = "";
20821
+ const shadowRoot = container.attachShadow({ mode: "open" });
20822
+ const mountPoint = document.createElement("div");
20823
+ mountPoint.id = "live-chat-widget-mount";
20824
+ shadowRoot.appendChild(mountPoint);
20825
+ const styles = document.createElement("style");
20826
+ styles.textContent = `
20827
+ @import url("https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css");
20828
+ `;
20829
+ shadowRoot.appendChild(styles);
20830
+ reactRoot = client.createRoot(mountPoint);
20831
+ container.__livechat_mounted = true;
20832
+ }
20833
+ userDetails = { name: name2, email, unique_id };
20834
+ if (reactRoot) {
20835
+ reactRoot.render(
20820
20836
  /* @__PURE__ */ React.createElement(React.StrictMode, null, /* @__PURE__ */ React.createElement(
20821
20837
  LiveChatWidget,
20822
20838
  {
20823
- widgetId,
20824
- name: name2,
20825
- email,
20826
- unique_id
20839
+ widgetId: currentWidgetId,
20840
+ name: userDetails.name,
20841
+ email: userDetails.email,
20842
+ unique_id: userDetails.unique_id
20827
20843
  }
20828
20844
  ))
20829
20845
  );
20830
- container.__livechat_mounted = true;
20831
- } catch (err) {
20832
- console.error("❌ LiveChatWidget render failed:", err);
20833
- const errDiv = document.createElement("div");
20834
- errDiv.style.cssText = "padding:20px; border:2px solid #f00; background:#fee; color:#c00; font-family:monospace; border-radius:8px; margin:20px;";
20835
- errDiv.innerHTML = `
20836
- <h3 style="margin:0 0 10px 0;">Live Chat Widget Error</h3>
20837
- <pre style="white-space: pre-wrap; margin:0;">${(err == null ? void 0 : err.message) || String(err)}</pre>
20838
- <p style="margin:10px 0 0 0;">Check console for details.</p>
20839
- `;
20840
- mountPoint.appendChild(errDiv);
20841
20846
  }
20842
20847
  }
20843
- let userDetails = { name: null, email: null, unique_id: null };
20844
20848
  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
- );
20849
+ if (userDetails.name === name2 && userDetails.email === email && userDetails.unique_id === unique_id) {
20850
+ return;
20851
+ }
20852
+ userDetails = { name: name2, email, unique_id };
20853
+ if (reactRoot) {
20854
+ reactRoot.render(
20855
+ /* @__PURE__ */ React.createElement(React.StrictMode, null, /* @__PURE__ */ React.createElement(
20856
+ LiveChatWidget,
20857
+ {
20858
+ widgetId: currentWidgetId,
20859
+ name: userDetails.name,
20860
+ email: userDetails.email,
20861
+ unique_id: userDetails.unique_id
20865
20862
  }
20866
- }
20867
- }
20863
+ ))
20864
+ );
20868
20865
  }
20869
20866
  }
20870
20867
  window.LiveChatWidget = { init, setUser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getwidgets/live-chat-widget",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "main": "dist/live-chat-widget.umd.js",
5
5
  "unpkg": "dist/live-chat-widget.umd.js",
6
6
  "type": "module",