@levo-so/react 0.1.77 → 0.1.79

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.
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import { jsx as r } from "react/jsx-runtime";
3
+ import { useLevoOAuth as c } from "./Container.js";
4
+ import m from "./Core.js";
5
+ import { Spinner as a } from "../../components/Spinner.js";
6
+ const A = ({ children: o, provider: t }) => {
7
+ const { title: n, urls: s, isLoading: u, onSuccess: i, onError: l } = c(), e = s?.[t];
8
+ return e ? /* @__PURE__ */ r(m, { title: n, provider: t, url: e, onSuccess: i, onError: l, children: u ? /* @__PURE__ */ r("div", { className: "w-full items-center justify-center", children: /* @__PURE__ */ r(a, { className: "h-5 w-5 bg-brand" }) }) : o }) : null;
9
+ };
10
+ export {
11
+ A as LevoOAuthButton,
12
+ A as default
13
+ };
@@ -0,0 +1,52 @@
1
+ "use client";
2
+ import { jsx as y } from "react/jsx-runtime";
3
+ import w, { useState as g, useEffect as p, useMemo as C, useContext as _ } from "react";
4
+ import { useLevo as R } from "../../providers/LevoProvider.js";
5
+ const L = w.createContext({
6
+ urls: null,
7
+ title: "",
8
+ isLoading: !1,
9
+ onSuccess: () => {
10
+ },
11
+ onError: () => {
12
+ }
13
+ }), S = ({ title: c, onSuccess: i, onError: o, children: O }) => {
14
+ const s = R(), n = typeof window < "u" ? window.location.href : "", [t, u] = g(null), [a, f] = g(!1);
15
+ p(() => {
16
+ s.membership && (f(!0), s.membership?.getOAuthURL().then((e) => {
17
+ u(e);
18
+ }).catch((e) => {
19
+ o({
20
+ code: e?.code || "SOMETHING_WENT_WRONG",
21
+ message: e?.message || "We could not connect with our service for your sign-in."
22
+ });
23
+ }).finally(() => {
24
+ f(!1);
25
+ }));
26
+ }, []);
27
+ const x = C(
28
+ () => ({ title: c, urls: t, isLoading: a, onSuccess: i, onError: o }),
29
+ [c, t, i, o, a]
30
+ );
31
+ return p(() => {
32
+ if (t && n) {
33
+ const e = {}, v = Object.keys(t);
34
+ for (const l of v)
35
+ try {
36
+ const r = t[l];
37
+ if (r) {
38
+ const m = new URL(r), h = m.searchParams;
39
+ h.set("redirect_uri", n);
40
+ const d = s.pageContext;
41
+ d && h.set("page_context", JSON.stringify(d)), e[l] = m.toString();
42
+ }
43
+ } catch {
44
+ }
45
+ u(e);
46
+ }
47
+ }, [n]), /* @__PURE__ */ y(L.Provider, { value: x, children: O });
48
+ }, U = () => _(L);
49
+ export {
50
+ S as default,
51
+ U as useLevoOAuth
52
+ };
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ import { jsx as i } from "react/jsx-runtime";
3
+ import { useCallback as m } from "react";
4
+ import p from "./Popup.js";
5
+ const x = ({
6
+ title: e = "Levo",
7
+ url: r,
8
+ children: t,
9
+ onSuccess: s,
10
+ onError: u,
11
+ width: n = 500,
12
+ height: c = 700
13
+ }) => {
14
+ const l = m((f, o) => {
15
+ f.toLowerCase() === "success" ? s(o) : u(o);
16
+ }, []);
17
+ return /* @__PURE__ */ i(
18
+ p,
19
+ {
20
+ title: e,
21
+ width: n,
22
+ height: c,
23
+ onClose: () => {
24
+ },
25
+ url: r,
26
+ onCode: l,
27
+ children: t
28
+ }
29
+ );
30
+ };
31
+ export {
32
+ x as default
33
+ };
@@ -0,0 +1,56 @@
1
+ "use client";
2
+ import { jsx as m } from "react/jsx-runtime";
3
+ import { useState as x, useRef as h, useEffect as v } from "react";
4
+ const P = ({ url: o, title: c, height: t, width: n }) => {
5
+ const i = window.screenX + (window.outerWidth - n) / 2, s = window.screenY + (window.outerHeight - t) / 2.5;
6
+ return window.open(
7
+ o,
8
+ c,
9
+ `width=${n},height=${t},left=${i},top=${s}`
10
+ );
11
+ }, W = ({
12
+ title: o = "",
13
+ width: c = 500,
14
+ height: t = 500,
15
+ url: n,
16
+ children: i,
17
+ onCode: s,
18
+ onClose: r
19
+ }) => {
20
+ const [e, f] = x(), a = h(void 0), l = () => {
21
+ window.clearInterval(a.current);
22
+ }, p = () => {
23
+ f(
24
+ P({
25
+ url: n,
26
+ title: o,
27
+ width: c,
28
+ height: t
29
+ })
30
+ );
31
+ };
32
+ return v(() => (e && (a.current = window.setInterval(() => {
33
+ try {
34
+ const u = e.location.href, w = new URL(u).searchParams, d = w.get("code");
35
+ if (!d)
36
+ return;
37
+ s(d, w), l(), e.close();
38
+ } catch {
39
+ } finally {
40
+ (!e || e.closed) && (r(), l());
41
+ }
42
+ }, 700)), () => {
43
+ e && e.close(), r && r();
44
+ }), [e]), /* @__PURE__ */ m(
45
+ "div",
46
+ {
47
+ onClick: () => {
48
+ p();
49
+ },
50
+ children: i
51
+ }
52
+ );
53
+ };
54
+ export {
55
+ W as default
56
+ };
@@ -0,0 +1,9 @@
1
+ import { LevoOAuthButton as t } from "./components/Button.js";
2
+ import o from "./components/Container.js";
3
+ class n {
4
+ static Container = o;
5
+ static Button = t;
6
+ }
7
+ export {
8
+ n as LevoOAuth
9
+ };
@@ -0,0 +1,76 @@
1
+ import { getLevoError as W } from "@levo-so/core";
2
+ import { useState as i, useRef as x, useCallback as h, useEffect as g, useMemo as y } from "react";
3
+ import { useLevo as I } from "../providers/LevoProvider.js";
4
+ const P = ({ url: u, title: a, height: s, width: c }) => {
5
+ const n = window.screenX + (window.outerWidth - c) / 2, f = window.screenY + (window.outerHeight - s) / 2.5;
6
+ return window.open(
7
+ u,
8
+ a,
9
+ `width=${c},height=${s},left=${n},top=${f}`
10
+ );
11
+ }, C = ({
12
+ title: u = "Levo",
13
+ width: a = 500,
14
+ height: s = 700,
15
+ onSuccess: c
16
+ }) => {
17
+ const n = I(), [f, w] = i(!1), [t, v] = i(null), [L, l] = i(null), [r, E] = i(), d = x(void 0), p = () => {
18
+ window.clearInterval(d.current);
19
+ }, O = h((e, o) => {
20
+ e.toLowerCase() === "success" ? (l(null), c(o)) : l(o);
21
+ }, []);
22
+ g(() => {
23
+ n.membership && (w(!0), n.membership?.getOAuthURL().then((e) => {
24
+ if (e)
25
+ return v(e), e;
26
+ throw new Error();
27
+ }).catch((e) => {
28
+ const o = W(e);
29
+ n.logger?.error("Failed to get OAuth URL", o.message), l({
30
+ code: o?.code || "SOMETHING_WENT_WRONG",
31
+ message: o?.message || "We could not connect with our service for your sign-in."
32
+ });
33
+ }).finally(() => {
34
+ w(!1);
35
+ }));
36
+ }, []), g(() => (r && (d.current = window.setInterval(() => {
37
+ try {
38
+ const e = r.location.href, o = new URL(e).searchParams, m = o.get("code");
39
+ if (!m)
40
+ return;
41
+ O(m, o), p(), r.close();
42
+ } catch {
43
+ } finally {
44
+ (!r || r.closed) && (p(), l(null));
45
+ }
46
+ }, 700)), () => {
47
+ r && r.close();
48
+ }), [r]);
49
+ const R = h(
50
+ (e) => {
51
+ if (e && t !== null) {
52
+ const o = t?.[e];
53
+ o && (r && r.close(), E(
54
+ P({
55
+ url: o,
56
+ title: u,
57
+ width: a,
58
+ height: s
59
+ })
60
+ ));
61
+ }
62
+ },
63
+ [t, r]
64
+ );
65
+ return {
66
+ providers: y(() => t !== null ? Object.keys(t).filter(
67
+ (e) => !!t[e]
68
+ ) : [], [t]),
69
+ isLoading: f,
70
+ error: L,
71
+ launchPopup: R
72
+ };
73
+ };
74
+ export {
75
+ C as useLevoOAuth
76
+ };
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { jsx as s } from "react/jsx-runtime";
3
+ import { createContext as i, useContext as o } from "react";
4
+ const t = i({
5
+ client: null,
6
+ insights: null
7
+ }), v = ({ children: e, client: n, insights: r = null }) => /* @__PURE__ */ s(t.Provider, { value: { client: n, insights: r }, children: e }), l = () => {
8
+ const e = o(t);
9
+ if (!e.client)
10
+ throw new Error(
11
+ "useLevo must be used within a LevoProvider. Please ensure you have wrapped your component tree with LevoProvider."
12
+ );
13
+ return e.client;
14
+ }, x = () => o(t).insights;
15
+ export {
16
+ v as LevoProvider,
17
+ l as useLevo,
18
+ x as useLevoInsights
19
+ };
@@ -0,0 +1,9 @@
1
+ const s = (t, o = 2) => {
2
+ if (t === 0) return "0 B";
3
+ const B = 1024, r = o < 0 ? 0 : o, n = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], e = Math.floor(Math.log(t) / Math.log(B));
4
+ return `${Number.parseFloat((t / B ** e).toFixed(r))} ${n[e]}`;
5
+ };
6
+ export {
7
+ s as byteToSize,
8
+ s as default
9
+ };
@@ -0,0 +1,7 @@
1
+ import { clsx as t } from "clsx";
2
+ import { twMerge as o } from "tailwind-merge";
3
+ const c = (...r) => o(t(r));
4
+ export {
5
+ c as cn,
6
+ c as default
7
+ };
@@ -0,0 +1,11 @@
1
+ import { getLevoError as s } from "@levo-so/core";
2
+ import { errorToast as t } from "../components/Sonner.js";
3
+ const E = (o) => {
4
+ const r = s(o);
5
+ return r?.code === "REQUEST_TIMEOUT" || r?.code === "NETWORK_ERROR" || r?.status === 408 || r?.status === 0 || t(r?.message || "", r?.title || "Error", {
6
+ id: `${r?.title || ""}-${r?.message || ""}`
7
+ }), r;
8
+ };
9
+ export {
10
+ E as errorHandler
11
+ };
@@ -0,0 +1,4 @@
1
+ const e = (t) => t instanceof Date;
2
+ export {
3
+ e as isDateObject
4
+ };
@@ -0,0 +1,5 @@
1
+ import { isObject as e } from "./isObject.js";
2
+ const o = (t) => e(t) && !Object.keys(t).length;
3
+ export {
4
+ o as isEmptyObject
5
+ };
@@ -0,0 +1,4 @@
1
+ const n = (l) => l == null;
2
+ export {
3
+ n as isNullOrUndefined
4
+ };
@@ -0,0 +1,7 @@
1
+ import { isDateObject as r } from "./isDateObject.js";
2
+ import { isNullOrUndefined as o } from "./isNullOrUndefined.js";
3
+ const i = (t) => typeof t == "object", c = (t) => !o(t) && !Array.isArray(t) && i(t) && !r(t);
4
+ export {
5
+ c as isObject,
6
+ i as isObjectType
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levo-so/react",
3
- "version": "0.1.77",
3
+ "version": "0.1.79",
4
4
  "author": "Levo Engineering <devs@theinternetfolks.com>",
5
5
  "description": "Levo suite for React based applications",
6
6
  "type": "module",
@@ -16,8 +16,8 @@
16
16
  "peerDependencies": {
17
17
  "react": ">=18",
18
18
  "react-dom": ">=18",
19
- "@levo-so/core": "0.1.76",
20
- "@levo-so/insights": "0.1.76"
19
+ "@levo-so/core": "0.1.79",
20
+ "@levo-so/insights": "0.1.79"
21
21
  },
22
22
  "dependencies": {
23
23
  "class-variance-authority": "0.7.0",
@@ -42,16 +42,17 @@
42
42
  "typescript": "5.9.3",
43
43
  "vite": "7.2.4",
44
44
  "vite-plugin-dts": "4.1.0",
45
+ "vite-plugin-externalize-deps": "0.10.0",
46
+ "@levo-so/core": "0.1.79",
45
47
  "@levo/ts-config": "0.0.0",
46
48
  "@levo/tw-config": "0.0.0",
47
- "@levo-so/core": "0.1.76",
48
- "@levo-so/insights": "0.1.76"
49
+ "@levo-so/insights": "0.1.79"
49
50
  },
50
51
  "main": "./dist/index.js",
51
52
  "module": "./dist/index.js",
52
53
  "types": "./dist/index.d.ts",
53
54
  "exports": {
54
- "./index.css": "./dist/index.css",
55
+ "./index.css": "./dist/styles/index.css",
55
56
  ".": {
56
57
  "types": "./dist/index.d.ts",
57
58
  "default": "./dist/index.js"
File without changes