@visitorquery/react 0.0.14 → 0.0.16

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/index.js CHANGED
@@ -1,89 +1,85 @@
1
- import { jsx as E } from "react/jsx-runtime";
2
- import * as m from "react";
3
- import { createContext as v, useState as y, useMemo as l, useEffect as S, useContext as p } from "react";
4
- function w(t, i = {}) {
5
- const [d, n] = m.useState("loading"), a = m.useRef(i);
6
- return m.useEffect(() => {
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import * as c from "react";
3
+ import { createContext as v, useState as y, useEffect as E, useMemo as S, useContext as w } from "react";
4
+ function V(t, u = {}) {
5
+ const [i, r] = c.useState("loading"), d = c.useRef(u);
6
+ return c.useEffect(() => {
7
7
  let e = document.querySelector(`script[src="${t}"]`);
8
- const s = e == null ? void 0 : e.getAttribute("data-status");
9
- if (s) {
10
- n(s);
8
+ const n = e == null ? void 0 : e.getAttribute("data-status");
9
+ if (n) {
10
+ r(n);
11
11
  return;
12
12
  }
13
13
  if (e === null) {
14
14
  e = document.createElement("script"), e.src = t, e.async = !0, e.setAttribute("data-status", "loading"), document.body.appendChild(e);
15
15
  const o = () => {
16
- e == null || e.setAttribute("data-status", "ready"), n("ready"), u();
17
- }, r = () => {
18
- e == null || e.setAttribute("data-status", "error"), n("error"), u();
19
- }, u = () => {
20
- e == null || e.removeEventListener("load", o), e == null || e.removeEventListener("error", r);
16
+ e == null || e.setAttribute("data-status", "ready"), r("ready"), s();
17
+ }, a = () => {
18
+ e == null || e.setAttribute("data-status", "error"), r("error"), s();
19
+ }, s = () => {
20
+ e == null || e.removeEventListener("load", o), e == null || e.removeEventListener("error", a);
21
21
  };
22
- e.addEventListener("load", o), e.addEventListener("error", r);
23
- const c = a.current.removeOnUnmount;
22
+ e.addEventListener("load", o), e.addEventListener("error", a);
23
+ const m = d.current.removeOnUnmount;
24
24
  return () => {
25
- c === !0 && (e == null || e.remove(), u());
25
+ m === !0 && (e == null || e.remove(), s());
26
26
  };
27
27
  } else
28
- n("unknown");
29
- }, [t]), d;
28
+ r("unknown");
29
+ }, [t]), i;
30
30
  }
31
- const f = v(null);
32
- function x({
31
+ const l = v(null);
32
+ function L({
33
33
  apiKey: t,
34
- sessionId: i,
35
- endpoint: d,
36
- children: n
34
+ sessionId: u,
35
+ endpoint: i,
36
+ children: r
37
37
  }) {
38
- const a = "main.check.visitorquery.com", e = w("https://cdn.visitorquery.com/visitorquery.js", {
38
+ const d = "main.check.visitorquery.com", e = V("https://cdn.visitorquery.com/visitorquery.js", {
39
39
  removeOnUnmount: !1
40
- }), [s, o] = y({
41
- Started: !1,
42
- Ended: !1
43
- }), r = l(() => ({
44
- ApiKey: t,
45
- SessionId: i,
46
- Endpoint: d || a
47
- }), [t, i, d, a]);
48
- S(() => {
40
+ }), [n, o] = y({
41
+ started: !1,
42
+ ended: !1
43
+ });
44
+ E(() => {
49
45
  typeof window.VisitorQuery < "u" && window.VisitorQuery.run({
50
- ApiKey: r.ApiKey,
51
- Endpoint: r.Endpoint,
52
- SessionId: r.SessionId,
46
+ ApiKey: t,
47
+ Endpoint: i || d,
48
+ SessionId: u,
53
49
  onOpen: () => {
54
50
  o({
55
- Started: !0,
56
- Ended: !1
51
+ started: !0,
52
+ ended: !1
57
53
  });
58
54
  },
59
55
  onClose: () => {
60
56
  o({
61
- Started: !0,
62
- Ended: !0
57
+ started: !0,
58
+ ended: !0
63
59
  });
64
60
  },
65
- onError: (c) => {
61
+ onError: (s) => {
66
62
  o({
67
- Started: !0,
68
- Ended: !0,
69
- Errored: !0
70
- }), console.error(c);
63
+ started: !0,
64
+ ended: !0,
65
+ errored: !0
66
+ }), console.error(s);
71
67
  }
72
68
  });
73
- }, [r, e]);
74
- const u = l(() => ({
75
- ...s,
69
+ }, [t, i, u, e]);
70
+ const a = S(() => ({
71
+ ...n,
76
72
  isLoading: e === "loading"
77
- }), [s, e]);
78
- return /* @__PURE__ */ E(f.Provider, { value: u, children: n });
73
+ }), [n, e]);
74
+ return /* @__PURE__ */ f(l.Provider, { value: a, children: r });
79
75
  }
80
- function A() {
81
- const t = p(f);
76
+ function Q() {
77
+ const t = w(l);
82
78
  if (!t)
83
79
  throw new Error("useVisitorQuery must be used within a VisitorQueryProvider");
84
80
  return t;
85
81
  }
86
82
  export {
87
- x as VisitorQueryProvider,
88
- A as useVisitorQuery
83
+ L as VisitorQueryProvider,
84
+ Q as useVisitorQuery
89
85
  };
@@ -5,9 +5,9 @@ declare global {
5
5
  }
6
6
  }
7
7
  type VisitorQueryState = {
8
- Started: boolean;
9
- Ended: boolean;
10
- Errored?: boolean;
8
+ started: boolean;
9
+ ended: boolean;
10
+ errored?: boolean;
11
11
  };
12
12
  type VisitorQueryContextType = VisitorQueryState & {
13
13
  isLoading: boolean;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.14",
2
+ "version": "0.0.16",
3
3
  "name": "@visitorquery/react",
4
4
  "module": "./dist/index.js",
5
5
  "type": "module",