@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.
- package/dist/live-chat-widget.umd.js +51 -54
- package/package.json +1 -1
|
@@ -20797,74 +20797,71 @@
|
|
|
20797
20797
|
}
|
|
20798
20798
|
`));
|
|
20799
20799
|
};
|
|
20800
|
-
|
|
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(
|
|
20812
|
+
console.error(
|
|
20813
|
+
"Live Chat Widget root element (#livechat-root) not found."
|
|
20814
|
+
);
|
|
20804
20815
|
return;
|
|
20805
20816
|
}
|
|
20806
|
-
|
|
20807
|
-
|
|
20808
|
-
|
|
20809
|
-
|
|
20810
|
-
|
|
20811
|
-
|
|
20812
|
-
|
|
20813
|
-
|
|
20814
|
-
|
|
20815
|
-
|
|
20816
|
-
|
|
20817
|
-
|
|
20818
|
-
|
|
20819
|
-
|
|
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:
|
|
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
|
|
20846
|
-
|
|
20847
|
-
|
|
20848
|
-
|
|
20849
|
-
|
|
20850
|
-
|
|
20851
|
-
|
|
20852
|
-
|
|
20853
|
-
|
|
20854
|
-
|
|
20855
|
-
|
|
20856
|
-
|
|
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 };
|