@levo-so/react 0.1.27 → 0.1.29

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.
@@ -1,130 +1,146 @@
1
1
  "use client";
2
- var O = Object.defineProperty;
3
- var R = (e, t, n) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
4
- var f = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
5
- import { j as a } from "../jsx-runtime-B6kdoens.js";
6
- import j, { useState as v, useEffect as C, useMemo as P, useContext as W, useRef as g, useCallback as A } from "react";
7
- import { u as E } from "../LevoProvider-BAZy7_tP.js";
8
- const m = j.createContext({
2
+ var P = Object.defineProperty;
3
+ var R = (e, t, n) => t in e ? P(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
4
+ var x = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
5
+ import { j as h } from "../jsx-runtime-B6kdoens.js";
6
+ import j, { useState as L, useEffect as C, useMemo as y, useContext as U, useRef as W, useCallback as _ } from "react";
7
+ import { u as k } from "../LevoProvider-BAZy7_tP.js";
8
+ const O = j.createContext({
9
9
  urls: null,
10
10
  title: "",
11
11
  onSuccess: () => {
12
12
  },
13
13
  onError: () => {
14
14
  }
15
- }), U = ({
15
+ }), A = ({
16
16
  title: e,
17
17
  onSuccess: t,
18
18
  onError: n,
19
- children: r
19
+ children: c
20
20
  }) => {
21
- const { membership: o } = E(), [u, c] = v(null);
21
+ const { membership: r, client: u } = k(), s = typeof window < "u" ? window.location.href : "", [o, l] = L(null);
22
22
  C(() => {
23
- o && (o == null || o.getOAuthURL().then((i) => {
24
- c(i);
23
+ r && (r == null || r.getOAuthURL().then((a) => {
24
+ l(a);
25
25
  }).catch(() => {
26
26
  n({
27
27
  code: "SOMETHING_WENT_WRONG",
28
28
  message: "We could not connect with our service for your sign-in."
29
29
  });
30
30
  }));
31
- }, [o]);
32
- const s = P(
33
- () => ({ title: e, urls: u, onSuccess: t, onError: n }),
34
- [e, u, t, n]
31
+ }, [r]);
32
+ const i = y(
33
+ () => ({ title: e, urls: o, onSuccess: t, onError: n }),
34
+ [e, o, t, n]
35
35
  );
36
- return /* @__PURE__ */ a.jsx(m.Provider, { value: s, children: r });
37
- }, _ = () => W(m), $ = ({ url: e, title: t, height: n, width: r }) => {
38
- const o = window.screenX + (window.outerWidth - r) / 2, u = window.screenY + (window.outerHeight - n) / 2.5;
36
+ return C(() => {
37
+ if (o && s) {
38
+ const a = {}, p = Object.keys(o);
39
+ for (const w of p)
40
+ try {
41
+ const f = o[w];
42
+ if (f) {
43
+ const d = new URL(f), m = d.searchParams;
44
+ m.set("redirect_uri", s);
45
+ const g = u.getPageContext();
46
+ g && m.set("page_context", JSON.stringify(g)), a[w] = d.toString();
47
+ }
48
+ } catch {
49
+ }
50
+ l(a);
51
+ }
52
+ }, [s]), /* @__PURE__ */ h.jsx(O.Provider, { value: i, children: c });
53
+ }, E = () => U(O), S = ({ url: e, title: t, height: n, width: c }) => {
54
+ const r = window.screenX + (window.outerWidth - c) / 2, u = window.screenY + (window.outerHeight - n) / 2.5;
39
55
  return window.open(
40
56
  e,
41
57
  t,
42
- `width=${r},height=${n},left=${o},top=${u}`
58
+ `width=${c},height=${n},left=${r},top=${u}`
43
59
  );
44
- }, k = ({
60
+ }, N = ({
45
61
  title: e = "",
46
62
  width: t = 500,
47
63
  height: n = 500,
48
- url: r,
49
- children: o,
64
+ url: c,
65
+ children: r,
50
66
  onCode: u,
51
- onClose: c
67
+ onClose: s
52
68
  }) => {
53
- const [s, i] = v(), l = g(), w = () => {
54
- window.clearInterval(l.current);
55
- }, L = () => {
56
- i(
57
- $({
58
- url: r,
69
+ const [o, l] = L(), i = W(), a = () => {
70
+ window.clearInterval(i.current);
71
+ }, p = () => {
72
+ l(
73
+ S({
74
+ url: c,
59
75
  title: e,
60
76
  width: t,
61
77
  height: n
62
78
  })
63
79
  );
64
80
  };
65
- return C(() => (s && (l.current = window.setInterval(() => {
81
+ return C(() => (o && (i.current = window.setInterval(() => {
66
82
  try {
67
- const d = s.location.href, p = new URL(d).searchParams, x = p.get("code");
68
- if (!x)
83
+ const w = o.location.href, f = new URL(w).searchParams, d = f.get("code");
84
+ if (!d)
69
85
  return;
70
- u(x, p), w(), s.close();
86
+ u(d, f), a(), o.close();
71
87
  } catch {
72
88
  } finally {
73
- (!s || s.closed) && (c(), w());
89
+ (!o || o.closed) && (s(), a());
74
90
  }
75
91
  }, 700)), () => {
76
- s && s.close(), c && c();
77
- }), [s]), /* @__PURE__ */ a.jsx(
92
+ o && o.close(), s && s();
93
+ }), [o]), /* @__PURE__ */ h.jsx(
78
94
  "div",
79
95
  {
80
96
  onClick: () => {
81
- L();
97
+ p();
82
98
  },
83
- children: o
99
+ children: r
84
100
  }
85
101
  );
86
- }, y = ({
102
+ }, $ = ({
87
103
  title: e = "Levo",
88
104
  url: t,
89
105
  children: n,
90
- onSuccess: r,
91
- onError: o,
106
+ onSuccess: c,
107
+ onError: r,
92
108
  width: u = 500,
93
- height: c = 700
109
+ height: s = 700
94
110
  }) => {
95
- const s = A((i, l) => {
96
- i.toLowerCase() === "success" ? r(l) : o(l);
111
+ const o = _((l, i) => {
112
+ l.toLowerCase() === "success" ? c(i) : r(i);
97
113
  }, []);
98
- return /* @__PURE__ */ a.jsx(
99
- k,
114
+ return /* @__PURE__ */ h.jsx(
115
+ N,
100
116
  {
101
117
  title: e,
102
118
  width: u,
103
- height: c,
119
+ height: s,
104
120
  onClose: () => {
105
121
  },
106
122
  url: t,
107
- onCode: s,
123
+ onCode: o,
108
124
  children: n
109
125
  }
110
126
  );
111
127
  }, I = ({ children: e, provider: t }) => {
112
- const { title: n, urls: r, onSuccess: o, onError: u } = _(), c = r == null ? void 0 : r[t];
113
- return c ? /* @__PURE__ */ a.jsx(
114
- y,
128
+ const { title: n, urls: c, onSuccess: r, onError: u } = E(), s = c == null ? void 0 : c[t];
129
+ return s ? /* @__PURE__ */ h.jsx(
130
+ $,
115
131
  {
116
132
  title: n,
117
133
  provider: t,
118
- url: c,
119
- onSuccess: o,
134
+ url: s,
135
+ onSuccess: r,
120
136
  onError: u,
121
137
  children: e
122
138
  }
123
139
  ) : null;
124
140
  };
125
- class h {
141
+ class v {
126
142
  }
127
- f(h, "Container", U), f(h, "Button", I);
143
+ x(v, "Container", A), x(v, "Button", I);
128
144
  export {
129
- h as LevoOAuth
145
+ v as LevoOAuth
130
146
  };
@@ -0,0 +1,449 @@
1
+ "use client";
2
+ var se = Object.defineProperty;
3
+ var ie = (e, n, t) => n in e ? se(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
4
+ var U = (e, n, t) => ie(e, typeof n != "symbol" ? n + "" : n, t);
5
+ import { j as ce } from "./jsx-runtime-B6kdoens.js";
6
+ import { useEffect as f, useState as T } from "react";
7
+ import { useInView as ae } from "react-intersection-observer";
8
+ import { u as x } from "./LevoProvider-BAZy7_tP.js";
9
+ import { usePageLifecycle as ue, LifecycleState as S } from "use-page-lifecycle";
10
+ const ft = ({ id: e, properties: n = {} }) => {
11
+ const { audience: t } = x(), { ref: r, inView: o } = ae({
12
+ triggerOnce: !0
13
+ });
14
+ return f(() => {
15
+ t != null && t.instance && o && (t == null || t.track("block.view", {
16
+ ...n,
17
+ resource: "block",
18
+ identifier: e
19
+ }));
20
+ }, [o]), /* @__PURE__ */ ce.jsx("div", { ref: r, style: { height: "0px" } });
21
+ }, dt = ({ event: e, properties: n }) => {
22
+ const { audience: t } = x();
23
+ return f(() => {
24
+ t != null && t.instance && (t == null || t.track(e, n));
25
+ }, [t == null ? void 0 : t.instance, e, n]), null;
26
+ };
27
+ function A(e) {
28
+ var n = typeof e;
29
+ return e != null && (n == "object" || n == "function");
30
+ }
31
+ var le = typeof global == "object" && global && global.Object === Object && global, fe = typeof self == "object" && self && self.Object === Object && self, G = le || fe || Function("return this")(), _ = function() {
32
+ return G.Date.now();
33
+ }, de = /\s/;
34
+ function ge(e) {
35
+ for (var n = e.length; n-- && de.test(e.charAt(n)); )
36
+ ;
37
+ return n;
38
+ }
39
+ var me = /^\s+/;
40
+ function pe(e) {
41
+ return e && e.slice(0, ge(e) + 1).replace(me, "");
42
+ }
43
+ var E = G.Symbol, K = Object.prototype, he = K.hasOwnProperty, be = K.toString, b = E ? E.toStringTag : void 0;
44
+ function we(e) {
45
+ var n = he.call(e, b), t = e[b];
46
+ try {
47
+ e[b] = void 0;
48
+ var r = !0;
49
+ } catch {
50
+ }
51
+ var o = be.call(e);
52
+ return r && (n ? e[b] = t : delete e[b]), o;
53
+ }
54
+ var ye = Object.prototype, Se = ye.toString;
55
+ function ve(e) {
56
+ return Se.call(e);
57
+ }
58
+ var Te = "[object Null]", Ee = "[object Undefined]", M = E ? E.toStringTag : void 0;
59
+ function Le(e) {
60
+ return e == null ? e === void 0 ? Ee : Te : M && M in Object(e) ? we(e) : ve(e);
61
+ }
62
+ function Ce(e) {
63
+ return e != null && typeof e == "object";
64
+ }
65
+ var xe = "[object Symbol]";
66
+ function Ne(e) {
67
+ return typeof e == "symbol" || Ce(e) && Le(e) == xe;
68
+ }
69
+ var F = NaN, ke = /^[-+]0x[0-9a-f]+$/i, Oe = /^0b[01]+$/i, _e = /^0o[0-7]+$/i, Ie = parseInt;
70
+ function B(e) {
71
+ if (typeof e == "number")
72
+ return e;
73
+ if (Ne(e))
74
+ return F;
75
+ if (A(e)) {
76
+ var n = typeof e.valueOf == "function" ? e.valueOf() : e;
77
+ e = A(n) ? n + "" : n;
78
+ }
79
+ if (typeof e != "string")
80
+ return e === 0 ? e : +e;
81
+ e = pe(e);
82
+ var t = Oe.test(e);
83
+ return t || _e.test(e) ? Ie(e.slice(2), t ? 2 : 8) : ke.test(e) ? F : +e;
84
+ }
85
+ var Re = "Expected a function", Ae = Math.max, je = Math.min;
86
+ function $e(e, n, t) {
87
+ var r, o, i, c, s, a, l = 0, p = !1, g = !1, m = !0;
88
+ if (typeof e != "function")
89
+ throw new TypeError(Re);
90
+ n = B(n) || 0, A(t) && (p = !!t.leading, g = "maxWait" in t, i = g ? Ae(B(t.maxWait) || 0, n) : i, m = "trailing" in t ? !!t.trailing : m);
91
+ function k(u) {
92
+ var d = r, h = o;
93
+ return r = o = void 0, l = u, c = e.apply(h, d), c;
94
+ }
95
+ function te(u) {
96
+ return l = u, s = setTimeout(y, n), p ? k(u) : c;
97
+ }
98
+ function ne(u) {
99
+ var d = u - a, h = u - l, P = n - d;
100
+ return g ? je(P, i - h) : P;
101
+ }
102
+ function $(u) {
103
+ var d = u - a, h = u - l;
104
+ return a === void 0 || d >= n || d < 0 || g && h >= i;
105
+ }
106
+ function y() {
107
+ var u = _();
108
+ if ($(u))
109
+ return D(u);
110
+ s = setTimeout(y, ne(u));
111
+ }
112
+ function D(u) {
113
+ return s = void 0, m && r ? k(u) : (r = o = void 0, c);
114
+ }
115
+ function re() {
116
+ s !== void 0 && clearTimeout(s), l = 0, r = a = o = s = void 0;
117
+ }
118
+ function oe() {
119
+ return s === void 0 ? c : D(_());
120
+ }
121
+ function O() {
122
+ var u = _(), d = $(u);
123
+ if (r = arguments, o = this, a = u, d) {
124
+ if (s === void 0)
125
+ return te(a);
126
+ if (g)
127
+ return clearTimeout(s), s = setTimeout(y, n), k(a);
128
+ }
129
+ return s === void 0 && (s = setTimeout(y, n)), c;
130
+ }
131
+ return O.cancel = re, O.flush = oe, O;
132
+ }
133
+ const De = () => {
134
+ const [e, n] = T(0), [t, r] = T(0), o = $e((i) => {
135
+ r(i), n(i);
136
+ }, 250);
137
+ return f(() => {
138
+ const i = () => {
139
+ const c = window.scrollY, s = document.documentElement.scrollHeight, a = window.innerHeight, l = Math.round(
140
+ c / (s - a) * 100
141
+ );
142
+ l % 10 === 0 && l > t && o(l);
143
+ };
144
+ return window.addEventListener("scroll", i), () => window.removeEventListener("scroll", i);
145
+ }, [t]), e;
146
+ }, w = "lv_insights_ot", Pe = () => {
147
+ const [e, n] = T(0);
148
+ return f(() => {
149
+ const t = Number(localStorage.getItem(w)) || 0;
150
+ n(t), localStorage.setItem(w, (t + 1).toString());
151
+ const r = (i) => {
152
+ i.key === w && n(Number(i.newValue) || 0);
153
+ };
154
+ window.addEventListener("storage", r);
155
+ const o = () => {
156
+ const i = Number(localStorage.getItem(w)) || 0;
157
+ i > 0 && localStorage.setItem(w, (i - 1).toString());
158
+ };
159
+ return window.addEventListener("beforeunload", o), () => {
160
+ window.removeEventListener("storage", r), window.removeEventListener("beforeunload", o);
161
+ };
162
+ }, []), e;
163
+ }, H = "lv_insights_ct", I = "lv_insights_at", Ue = () => {
164
+ const [e, n] = T(null);
165
+ return f(() => {
166
+ let t = sessionStorage.getItem(H);
167
+ const r = JSON.parse(
168
+ localStorage.getItem(I) || "[]"
169
+ );
170
+ t && r.includes(t) && (t = null), t || (t = `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, sessionStorage.setItem(H, t)), r.includes(t) || (r.push(t), localStorage.setItem(
171
+ I,
172
+ JSON.stringify(r)
173
+ )), n(t);
174
+ const o = () => {
175
+ const i = r.filter(
176
+ (c) => c !== t
177
+ );
178
+ localStorage.setItem(
179
+ I,
180
+ JSON.stringify(i)
181
+ );
182
+ };
183
+ return window.addEventListener("beforeunload", o), () => {
184
+ window.removeEventListener("beforeunload", o);
185
+ };
186
+ }, []), e;
187
+ }, L = (e) => Object.prototype.toString.call(e) == "[object String]", Me = (e, n) => e.indexOf(n) !== -1, N = (e) => e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""), V = (e) => e === void 0, Fe = (e) => e === null, Y = (e) => V(e) || Fe(e), J = (e) => !!e && e.nodeType === 3;
188
+ function Be(e) {
189
+ return !!e && e.nodeType === 1;
190
+ }
191
+ function v(e, n) {
192
+ return !!e && !!e.tagName && e.tagName.toLowerCase() === n.toLowerCase();
193
+ }
194
+ function He(e) {
195
+ return e ? N(e).split(/\s+/) : [];
196
+ }
197
+ function We(e) {
198
+ let n = "";
199
+ switch (typeof e.className) {
200
+ case "string":
201
+ n = e.className;
202
+ break;
203
+ case "object":
204
+ n = (e.className && "baseVal" in e.className ? e.className.baseVal : null) || e.getAttribute("class") || "";
205
+ break;
206
+ default:
207
+ n = "";
208
+ }
209
+ return He(n);
210
+ }
211
+ const X = (e) => Y(e) ? null : N(e).split(/(\s+)/).filter((n) => j(n)).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, 255), C = (e) => {
212
+ let n = "";
213
+ if (Ve(e) && !z(e) && e.childNodes && e.childNodes.length)
214
+ for (const t of e.childNodes)
215
+ J(t) && t.textContent && (n += X(t.textContent) ?? "");
216
+ return N(n);
217
+ }, Ge = (e) => {
218
+ var n;
219
+ return V(e.target) ? e.srcElement || null : (n = e.target) != null && n.shadowRoot ? e.composedPath()[0] || null : e.target || null;
220
+ }, Ke = (e, n) => {
221
+ if (!window || !e || v(e, "html") || !Be(e))
222
+ return !1;
223
+ const t = window.getComputedStyle(e);
224
+ if (t && t.getPropertyValue("cursor") === "pointer" && n.type === "click")
225
+ return !0;
226
+ switch (e.tagName.toLowerCase()) {
227
+ case "html":
228
+ return !1;
229
+ case "form":
230
+ return n.type === "submit";
231
+ case "input":
232
+ case "select":
233
+ case "textarea":
234
+ return ["change", "click"].includes(n.type);
235
+ default:
236
+ return n.type === "click";
237
+ }
238
+ };
239
+ function Ve(e) {
240
+ if (Me(We(e), "ph-include"))
241
+ return !0;
242
+ const n = e.type || "";
243
+ if (L(n))
244
+ switch (n.toLowerCase()) {
245
+ case "hidden":
246
+ return !1;
247
+ case "password":
248
+ return !1;
249
+ }
250
+ const t = e.name || e.id || "";
251
+ return !(L(t) && /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(t.replace(/[^a-zA-Z0-9]/g, "")));
252
+ }
253
+ const z = (e) => {
254
+ const n = ["button", "checkbox", "submit", "reset"];
255
+ return !!(v(e, "input") && !n.includes(e.type) || v(e, "select") || v(e, "textarea") || e.getAttribute("contenteditable") === "true");
256
+ }, Z = "(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11})", Ye = new RegExp(`^(?:${Z})$`), Je = new RegExp(Z), q = "\\d{3}-?\\d{2}-?\\d{4}", Xe = new RegExp(`^(${q})$`), ze = new RegExp(`(${q})`), j = (e, n = !0) => !(Y(e) || L(e) && (e = N(e), (n ? Ye : Je).test((e || "").replace(/[- ]/g, "")) || (n ? Xe : ze).test(e))), Ze = (e) => L(e) ? e.substring(0, 10) === "_ngcontent" || e.substring(0, 7) === "_nghost" : !1, W = (e) => {
257
+ let n = C(e);
258
+ return n = `${n} ${Q(e)}`.trim(), j(n) ? n : "";
259
+ };
260
+ function Q(e) {
261
+ var t;
262
+ let n = "";
263
+ if (e != null && e.childNodes.length) {
264
+ for (const r of e.childNodes)
265
+ if (r && ((t = r.tagName) == null ? void 0 : t.toLowerCase()) === "span")
266
+ try {
267
+ const o = C(r);
268
+ n = `${n} ${o}`.trim(), r != null && r.childNodes.length && (n = `${n} ${Q(r)}`.trim());
269
+ } catch (o) {
270
+ console.error("[AutoCapture]", o);
271
+ }
272
+ }
273
+ return n;
274
+ }
275
+ const qe = ["input", "textarea", "select"], ee = (e) => {
276
+ var o, i, c;
277
+ const n = e.tagName.toLowerCase(), t = {
278
+ element: n
279
+ };
280
+ n.toLowerCase() === "a" || n.toLowerCase() === "button" ? t.text = W(e) : t.text = C(e);
281
+ const r = Array.from(e.attributes).reduce(
282
+ (s, a) => {
283
+ if (z(e) && !["name", "id", "class", "aria-label"].includes(a.name))
284
+ return s;
285
+ if (j(a.value) && !Ze(a.name)) {
286
+ if (a.name === "class")
287
+ return s;
288
+ s[a.name] = a.value;
289
+ }
290
+ return s;
291
+ },
292
+ {}
293
+ );
294
+ if (t.attributes = r, e.tagName.toLowerCase() === "a" || e.tagName.toLowerCase() === "button" ? t.text = W(e) || void 0 : t.text = C(e) || void 0, qe.includes(n)) {
295
+ let s = "";
296
+ t != null && t.attributes.id && (s = ((i = (o = document.querySelector(`label[for="${t == null ? void 0 : t.attributes.id}"]`)) == null ? void 0 : o.textContent) == null ? void 0 : i.trim()) || "");
297
+ const a = e.closest("label");
298
+ s || (s = ((c = a == null ? void 0 : a.textContent) == null ? void 0 : c.trim()) || ""), t.label = s || void 0;
299
+ }
300
+ return t;
301
+ }, Qe = (e, n) => {
302
+ var o;
303
+ let t = Ge(e);
304
+ J(t) && (t = t.parentNode || null);
305
+ const r = ["copy", "cut"].includes(n);
306
+ if (t && (Ke(t, e) || r)) {
307
+ const i = ee(t);
308
+ if (r) {
309
+ const c = X((o = window == null ? void 0 : window.getSelection()) == null ? void 0 : o.toString()), s = e.type || "clipboard";
310
+ if (!c)
311
+ return !1;
312
+ i.copy_text = c, i.copy_type = s;
313
+ }
314
+ return i;
315
+ }
316
+ return null;
317
+ }, et = 30, tt = 1e3, nt = 3;
318
+ class rt {
319
+ constructor() {
320
+ U(this, "clicks");
321
+ this.clicks = [];
322
+ }
323
+ isRageClick(n, t, r) {
324
+ const o = this.clicks[this.clicks.length - 1];
325
+ if (o && Math.abs(n - o.x) + Math.abs(t - o.y) < et && r - o.timestamp < tt) {
326
+ if (this.clicks.push({ x: n, y: t, timestamp: r }), this.clicks.length === nt)
327
+ return !0;
328
+ } else
329
+ this.clicks = [{ x: n, y: t, timestamp: r }];
330
+ return !1;
331
+ }
332
+ }
333
+ const R = new rt(), ot = () => {
334
+ const { audience: e } = x();
335
+ f(() => {
336
+ const n = (t) => {
337
+ let r = {
338
+ hostname: window.location.hostname,
339
+ pathname: window.location.pathname,
340
+ page_title: document.title,
341
+ url: window.location.href,
342
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
343
+ event_type: t.type,
344
+ button_type: t.button
345
+ };
346
+ if (t.target instanceof HTMLElement) {
347
+ const o = t.target;
348
+ r.rage_click = R == null ? void 0 : R.isRageClick(
349
+ t.clientX,
350
+ t.clientY,
351
+ (/* @__PURE__ */ new Date()).getTime()
352
+ ), r = {
353
+ ...r,
354
+ ...ee(o)
355
+ };
356
+ let i = o.getAttribute("href");
357
+ if (!i) {
358
+ let c = o.parentNode, s = 0;
359
+ for (; c && s < 8; ) {
360
+ const a = c == null ? void 0 : c.getAttribute("href");
361
+ if (a) {
362
+ i = a;
363
+ break;
364
+ }
365
+ c = c.parentNode, s++;
366
+ }
367
+ }
368
+ e == null || e.track("page.click", {
369
+ ...r,
370
+ href: i || void 0
371
+ });
372
+ }
373
+ };
374
+ return document.addEventListener("click", n), () => {
375
+ document.removeEventListener("click", n);
376
+ };
377
+ }, [e]);
378
+ }, gt = ({ id: e, properties: n = {} }) => {
379
+ const { client: t, audience: r } = x();
380
+ f(() => {
381
+ t && typeof window < "u" && (window.levo_client = t);
382
+ }, [t]), f(() => {
383
+ r && typeof window < "u" && (window.levo_audience = r);
384
+ }, [r]);
385
+ const o = typeof window < "u" ? window.location.href : void 0;
386
+ Pe(), Ue(), ot();
387
+ const i = De();
388
+ f(() => {
389
+ r != null && r.instance && i > 0 && r.track("page.scroll", {
390
+ resource: "page",
391
+ identifier: e,
392
+ percent: i
393
+ });
394
+ }, [r == null ? void 0 : r.instance, i, e]), f(() => {
395
+ const s = () => {
396
+ r == null || r.track("page.bounce", {
397
+ resource: "page",
398
+ identifier: e
399
+ });
400
+ };
401
+ return window && window.addEventListener("beforeunload", s), () => {
402
+ window && window.removeEventListener("beforeunload", s);
403
+ };
404
+ }, [r, e]);
405
+ const [c] = ue();
406
+ return f(() => {
407
+ (c === S.TERMINATED || c === S.HIDDEN || c === S.UNKNOWN || c === S.FROZEN) && (r == null || r.track("page.bounce", {
408
+ resource: "page",
409
+ identifier: e,
410
+ state: c
411
+ }));
412
+ }, [c, r, e]), f(() => {
413
+ (() => {
414
+ t != null && t.insightsUrl && t.workspace && o && (r != null && r.instance ? r.instance.page({
415
+ resource: "page",
416
+ identifier: e
417
+ }) : r == null || r.initiate({
418
+ ...n,
419
+ id: e,
420
+ created_at: (/* @__PURE__ */ new Date()).toISOString()
421
+ }));
422
+ })();
423
+ }, [t == null ? void 0 : t.insightsUrl, t == null ? void 0 : t.workspace, o]), f(() => {
424
+ const s = {
425
+ change: "form.change",
426
+ submit: "form.submit",
427
+ copy: "page.copy",
428
+ cut: "page.copy"
429
+ }, a = (p) => (g) => {
430
+ const m = Qe(g, p);
431
+ m && (r == null || r.track(s[p], m));
432
+ }, l = {
433
+ change: a("change"),
434
+ copy: a("copy"),
435
+ cut: a("cut"),
436
+ submit: a("submit")
437
+ };
438
+ return document.addEventListener("change", l.change), document.addEventListener("copy", l.copy), document.addEventListener("cut", l.cut), document.addEventListener("submit", l.submit), () => {
439
+ document.removeEventListener("change", l.change), document.removeEventListener("copy", l.copy), document.removeEventListener("cut", l.cut), document.removeEventListener("submit", l.submit);
440
+ };
441
+ }, []), (!(t != null && t.insightsUrl) || !t.workspace || !t.workspace.startsWith("W")) && console.error(
442
+ "[@levo-so/react] The utility could not be initialized, due to missing workspace, or endpoint for insights."
443
+ ), null;
444
+ };
445
+ export {
446
+ ft as L,
447
+ dt as a,
448
+ gt as b
449
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levo-so/react",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "author": "Levo Engineering <devs@theinternetfolks.com>",
5
5
  "description": "Levo suite for React based applications",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  "peerDependencies": {
17
17
  "react": ">=18",
18
18
  "react-dom": ">=18",
19
- "@levo-so/core": "0.1.27"
19
+ "@levo-so/core": "0.1.29"
20
20
  },
21
21
  "dependencies": {
22
22
  "@radix-ui/react-checkbox": "1.1.1",