@logaflow/next
Version:
This library was generated with [Nx](https://nx.dev).
74 lines (73 loc) • 1.96 kB
JavaScript
"use client";
import { jsx as g } from "react/jsx-runtime";
import { useState as u, useCallback as i, useEffect as d } from "react";
var p = { VITE_CJS_IGNORE_WARNING: "true", BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 };
const { VITE_ENVRIOMENT: m } = p, E = "logaflow-webcomponent-js", _ = m === "development" ? "http://localhost:4001" : "https://widget.logaflow.com";
function O({
projectKey: e,
useCustomTrigger: n,
userId: o,
name: a,
email: s,
avatar: r,
triggerText: f
}) {
const [w, l] = u(!1), c = i(() => {
if (document.querySelector("#" + E)) {
l(!0);
return;
}
const t = document.createElement("script");
t.crossOrigin = "true", t.async = !0, t.type = "module", t.src = `${_}/addons/logaflow-widget.es.js?version=3.0.0`, t.onload = function() {
l(!0);
}, document.head.appendChild(t);
}, []);
return d(() => {
e && c();
}, [c, e]), w ? /* @__PURE__ */ g(
"logaflow-widget",
{
"project-key": e,
"use-custom-trigger": n,
avatar: r,
email: s,
name: a,
"user-id": o,
"trigger-text": f
}
) : null;
}
function I() {
const [e, n] = u(!1), o = i((s) => {
const { data: r } = s;
r.from === "logaflowwidget" && r.state && n(r.state.open);
}, []), a = i(() => {
const s = {
from: "logaflowlib",
action: "open"
};
window.postMessage(s, window.location.origin);
}, []);
return d(() => (window.removeEventListener("message", o), window.addEventListener("message", o), () => {
window.removeEventListener("message", o);
}), [o]), { isOpen: e, open: a };
}
function R() {
return { setUser: i((n) => {
window.postMessage(
{
from: "logaflowlib",
action: "setuser",
payload: {
user: n
}
},
window.location.origin
);
}, []) };
}
export {
O as LogaflowWidget,
I as useLogaflowPopup,
R as useLogaflowUser
};