@getwidgets/live-chat-widget 1.0.9 → 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 +56 -55
- package/package.json +1 -1
|
@@ -19750,7 +19750,7 @@
|
|
|
19750
19750
|
}
|
|
19751
19751
|
return sessionId;
|
|
19752
19752
|
};
|
|
19753
|
-
const LiveChatWidget = ({ widgetId,
|
|
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
|
}
|
|
@@ -19908,7 +19910,7 @@
|
|
|
19908
19910
|
reactExports.useEffect(() => {
|
|
19909
19911
|
if (!widgetId) return;
|
|
19910
19912
|
fetchWidgetConfig(widgetId).then((data) => setConfig(data)).catch((err) => console.error("Failed to load widget config:", err));
|
|
19911
|
-
}, [widgetId
|
|
19913
|
+
}, [widgetId]);
|
|
19912
19914
|
reactExports.useEffect(() => {
|
|
19913
19915
|
const checkAndInitializeSession = async () => {
|
|
19914
19916
|
var _a2;
|
|
@@ -20795,72 +20797,71 @@
|
|
|
20795
20797
|
}
|
|
20796
20798
|
`));
|
|
20797
20799
|
};
|
|
20798
|
-
|
|
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
|
+
}) {
|
|
20799
20810
|
const container = document.getElementById("livechat-root");
|
|
20800
20811
|
if (!container) {
|
|
20801
|
-
console.error(
|
|
20812
|
+
console.error(
|
|
20813
|
+
"Live Chat Widget root element (#livechat-root) not found."
|
|
20814
|
+
);
|
|
20802
20815
|
return;
|
|
20803
20816
|
}
|
|
20804
|
-
|
|
20805
|
-
|
|
20806
|
-
|
|
20807
|
-
|
|
20808
|
-
|
|
20809
|
-
|
|
20810
|
-
|
|
20811
|
-
|
|
20812
|
-
|
|
20813
|
-
|
|
20814
|
-
|
|
20815
|
-
|
|
20816
|
-
|
|
20817
|
-
|
|
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(
|
|
20818
20836
|
/* @__PURE__ */ React.createElement(React.StrictMode, null, /* @__PURE__ */ React.createElement(
|
|
20819
20837
|
LiveChatWidget,
|
|
20820
20838
|
{
|
|
20821
|
-
widgetId,
|
|
20822
|
-
|
|
20823
|
-
|
|
20824
|
-
|
|
20825
|
-
unique_id
|
|
20839
|
+
widgetId: currentWidgetId,
|
|
20840
|
+
name: userDetails.name,
|
|
20841
|
+
email: userDetails.email,
|
|
20842
|
+
unique_id: userDetails.unique_id
|
|
20826
20843
|
}
|
|
20827
20844
|
))
|
|
20828
20845
|
);
|
|
20829
|
-
container.__livechat_mounted = true;
|
|
20830
|
-
} catch (err) {
|
|
20831
|
-
console.error("❌ LiveChatWidget render failed:", err);
|
|
20832
|
-
const errDiv = document.createElement("div");
|
|
20833
|
-
errDiv.style.cssText = "padding:20px; border:2px solid #f00; background:#fee; color:#c00; font-family:monospace; border-radius:8px; margin:20px;";
|
|
20834
|
-
errDiv.innerHTML = `
|
|
20835
|
-
<h3 style="margin:0 0 10px 0;">Live Chat Widget Error</h3>
|
|
20836
|
-
<pre style="white-space: pre-wrap; margin:0;">${(err == null ? void 0 : err.message) || String(err)}</pre>
|
|
20837
|
-
<p style="margin:10px 0 0 0;">Check console for details.</p>
|
|
20838
|
-
`;
|
|
20839
|
-
mountPoint.appendChild(errDiv);
|
|
20840
20846
|
}
|
|
20841
20847
|
}
|
|
20842
20848
|
function setUser({ name: name2, email, unique_id }) {
|
|
20843
|
-
|
|
20844
|
-
|
|
20845
|
-
|
|
20846
|
-
|
|
20847
|
-
|
|
20848
|
-
|
|
20849
|
-
|
|
20850
|
-
|
|
20851
|
-
|
|
20852
|
-
|
|
20853
|
-
|
|
20854
|
-
|
|
20855
|
-
|
|
20856
|
-
|
|
20857
|
-
|
|
20858
|
-
|
|
20859
|
-
}
|
|
20860
|
-
))
|
|
20861
|
-
);
|
|
20862
|
-
}
|
|
20863
|
-
}
|
|
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
|
|
20862
|
+
}
|
|
20863
|
+
))
|
|
20864
|
+
);
|
|
20864
20865
|
}
|
|
20865
20866
|
}
|
|
20866
20867
|
window.LiveChatWidget = { init, setUser };
|