@visitorquery/react 0.0.20 → 0.0.26

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.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");function y(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(o,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return o.default=t,Object.freeze(o)}const f=y(u);function v(t,o={}){const[r,n]=f.useState("loading"),c=f.useRef(o);return f.useEffect(()=>{let e=document.querySelector(`script[src="${t}"]`);const s=e==null?void 0:e.getAttribute("data-status");if(s){n(s);return}if(e===null){e=document.createElement("script"),e.src=t,e.async=!0,e.setAttribute("data-status","loading"),document.body.appendChild(e);const a=()=>{e==null||e.setAttribute("data-status","ready"),n("ready"),d()},i=()=>{e==null||e.setAttribute("data-status","error"),n("error"),d()},d=()=>{e==null||e.removeEventListener("load",a),e==null||e.removeEventListener("error",i)};e.addEventListener("load",a),e.addEventListener("error",i);const l=c.current.removeOnUnmount;return()=>{l===!0&&(e==null||e.remove(),d())}}else n("unknown")},[t]),r}const m=u.createContext(null);function S({apiKey:t,sessionId:o,endpoint:r,children:n,trigger:c}){const e="main.check.visitorquery.com",s=v("https://cdn.visitorquery.com/visitorquery.js",{removeOnUnmount:!1}),[a,i]=u.useState({started:!1,ended:!1});u.useEffect(()=>{typeof window.VisitorQuery<"u"&&window.VisitorQuery.run({ApiKey:t,Endpoint:r||e,SessionId:o,onOpen:()=>{i({started:!0,ended:!1})},onClose:()=>{i({started:!0,ended:!0})},onError:l=>{i({started:!0,ended:!0,errored:!0}),console.error(l)}})},[t,r,o,s,c]);const d=u.useMemo(()=>({...a,isLoading:s==="loading"}),[a,s]);return u.createElement(m.Provider,{value:d},n)}function b(){const t=u.useContext(m);if(!t)throw new Error("useVisitorQuery must be used within a VisitorQueryProvider");return t}exports.VisitorQueryProvider=S;exports.useVisitorQuery=b;
@@ -1,78 +1,77 @@
1
- import { jsx as f } from "react/jsx-runtime";
2
1
  import * as l 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, i = {}) {
5
- const [a, r] = l.useState("loading"), d = l.useRef(i);
2
+ import f, { createContext as v, useState as y, useEffect as E, useMemo as S, useContext as w } from "react";
3
+ function V(t, a = {}) {
4
+ const [i, r] = l.useState("loading"), d = l.useRef(a);
6
5
  return l.useEffect(() => {
7
6
  let e = document.querySelector(`script[src="${t}"]`);
8
- const o = e == null ? void 0 : e.getAttribute("data-status");
9
- if (o) {
10
- r(o);
7
+ const n = e == null ? void 0 : e.getAttribute("data-status");
8
+ if (n) {
9
+ r(n);
11
10
  return;
12
11
  }
13
12
  if (e === null) {
14
13
  e = document.createElement("script"), e.src = t, e.async = !0, e.setAttribute("data-status", "loading"), document.body.appendChild(e);
15
14
  const s = () => {
16
15
  e == null || e.setAttribute("data-status", "ready"), r("ready"), u();
17
- }, n = () => {
16
+ }, o = () => {
18
17
  e == null || e.setAttribute("data-status", "error"), r("error"), u();
19
18
  }, u = () => {
20
- e == null || e.removeEventListener("load", s), e == null || e.removeEventListener("error", n);
19
+ e == null || e.removeEventListener("load", s), e == null || e.removeEventListener("error", o);
21
20
  };
22
- e.addEventListener("load", s), e.addEventListener("error", n);
21
+ e.addEventListener("load", s), e.addEventListener("error", o);
23
22
  const c = d.current.removeOnUnmount;
24
23
  return () => {
25
24
  c === !0 && (e == null || e.remove(), u());
26
25
  };
27
26
  } else
28
27
  r("unknown");
29
- }, [t]), a;
28
+ }, [t]), i;
30
29
  }
31
30
  const m = v(null);
32
31
  function L({
33
32
  apiKey: t,
34
- sessionId: i,
35
- endpoint: a,
33
+ sessionId: a,
34
+ endpoint: i,
36
35
  children: r,
37
36
  trigger: d
38
37
  }) {
39
- const e = "main.check.visitorquery.com", o = V("https://cdn.visitorquery.com/visitorquery.js", {
38
+ const e = "main.check.visitorquery.com", n = V("https://cdn.visitorquery.com/visitorquery.js", {
40
39
  removeOnUnmount: !1
41
- }), [s, n] = y({
40
+ }), [s, o] = y({
42
41
  started: !1,
43
42
  ended: !1
44
43
  });
45
44
  E(() => {
46
45
  typeof window.VisitorQuery < "u" && window.VisitorQuery.run({
47
46
  ApiKey: t,
48
- Endpoint: a || e,
49
- SessionId: i,
47
+ Endpoint: i || e,
48
+ SessionId: a,
50
49
  onOpen: () => {
51
- n({
50
+ o({
52
51
  started: !0,
53
52
  ended: !1
54
53
  });
55
54
  },
56
55
  onClose: () => {
57
- n({
56
+ o({
58
57
  started: !0,
59
58
  ended: !0
60
59
  });
61
60
  },
62
61
  onError: (c) => {
63
- n({
62
+ o({
64
63
  started: !0,
65
64
  ended: !0,
66
65
  errored: !0
67
66
  }), console.error(c);
68
67
  }
69
68
  });
70
- }, [t, a, i, o, d]);
69
+ }, [t, i, a, n, d]);
71
70
  const u = S(() => ({
72
71
  ...s,
73
- isLoading: o === "loading"
74
- }), [s, o]);
75
- return /* @__PURE__ */ f(m.Provider, { value: u, children: r });
72
+ isLoading: n === "loading"
73
+ }), [s, n]);
74
+ return /* @__PURE__ */ f.createElement(m.Provider, { value: u }, r);
76
75
  }
77
76
  function Q() {
78
77
  const t = w(m);
package/package.json CHANGED
@@ -1,20 +1,27 @@
1
1
  {
2
- "version": "0.0.20",
2
+ "version": "0.0.26",
3
3
  "name": "@visitorquery/react",
4
- "module": "./dist/index.js",
5
4
  "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
6
15
  "devDependencies": {
7
16
  "@vitejs/plugin-react": "^4.3.4",
8
- "vite": "^6.2.1",
17
+ "vite": "^6.2.5",
9
18
  "vite-plugin-dts": "^4.5.3"
10
19
  },
11
20
  "access": "public",
12
- "main": "dist/index.ts",
13
- "types": "dist/index.d.ts",
14
21
  "peerDependencies": {
15
- "@types/react": "^19.0.10",
16
- "react": "^19.0.0",
17
- "react-dom": "^19.0.0",
22
+ "@types/react": ">=16.8.0",
23
+ "react": ">=16.8.0",
24
+ "react-dom": ">=16.8.0",
18
25
  "typescript": "^5.0.0"
19
26
  },
20
27
  "repository": {
@@ -33,9 +40,7 @@
33
40
  "author": "VisitorQuery",
34
41
  "license": "MIT",
35
42
  "files": [
36
- "dist/*.js",
37
- "dist/*.jsx",
38
- "dist/*.d.ts"
43
+ "dist"
39
44
  ],
40
45
  "scripts": {
41
46
  "build": "tsc --p ./tsconfig.build.json && vite build",