@noxickon/onyx 6.1.2 → 6.2.0
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/context/Auth/Auth.js +72 -59
- package/dist/context/Auth/Auth.types.d.ts +2 -0
- package/dist/internal/tv.js +4 -26
- package/dist/internal/twMergeConfig.d.ts +2 -0
- package/dist/internal/twMergeConfig.js +27 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/utils/cn.js +6 -0
- package/dist/utils/cn.test.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils.js +2 -0
- package/package.json +5 -1
|
@@ -1,76 +1,89 @@
|
|
|
1
1
|
import { createCompoundContext as e } from "../../internal/context/createCompoundContext/createCompoundContext.js";
|
|
2
2
|
import { c as t } from "react/compiler-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import { jsx as
|
|
3
|
+
import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
|
|
4
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
5
5
|
//#region src/context/Auth/Auth.tsx
|
|
6
|
-
var
|
|
7
|
-
function
|
|
8
|
-
if (e
|
|
9
|
-
let t = e
|
|
6
|
+
var s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new WeakMap(), l = 1;
|
|
7
|
+
function u(e) {
|
|
8
|
+
if (typeof e != "object" || !e) return !1;
|
|
9
|
+
let t = e;
|
|
10
|
+
return t.name === "AbortError" || t.networkError?.name === "AbortError";
|
|
11
|
+
}
|
|
12
|
+
function d(e) {
|
|
13
|
+
if (e === null) return s;
|
|
14
|
+
let t = e, n = c.get(t);
|
|
10
15
|
if (n) return n;
|
|
11
16
|
let r = e.permissions ?? [], i = new Set(r);
|
|
12
|
-
return
|
|
17
|
+
return c.set(t, i), i;
|
|
13
18
|
}
|
|
14
|
-
var { Provider:
|
|
15
|
-
function
|
|
16
|
-
let [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
var { Provider: f, useRequiredContext: p } = e("OxAuthProvider");
|
|
20
|
+
function m({ children: e, fetchUser: t, initialUser: s, onLogout: c, performLogout: d, refreshIntervalMs: p, revalidateOnFocus: m = !1 }) {
|
|
21
|
+
let [h, g] = a(s ?? null), [_, v] = a(s === void 0), [y, b] = a(!1), [x, S] = a(null), C = i(t), w = i(d), T = i(c), E = i(s ?? null), D = i(0), O = i(null);
|
|
22
|
+
r(() => {
|
|
23
|
+
C.current = t, w.current = d, T.current = c;
|
|
19
24
|
});
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
let k = n(async () => {
|
|
26
|
+
let e = async (t) => {
|
|
27
|
+
O.current?.abort();
|
|
28
|
+
let n = new AbortController();
|
|
29
|
+
O.current = n;
|
|
30
|
+
let r = ++D.current;
|
|
31
|
+
b(!0);
|
|
32
|
+
try {
|
|
33
|
+
let e = await C.current(n.signal);
|
|
34
|
+
if (n.signal.aborted || r !== D.current) return;
|
|
35
|
+
g(e), E.current = e, S(null);
|
|
36
|
+
} catch (i) {
|
|
37
|
+
if (n.signal.aborted || r !== D.current) return;
|
|
38
|
+
if (u(i) && t < l) {
|
|
39
|
+
await e(t + 1);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
S(i), console.error("[OxAuthProvider] refresh failed", i);
|
|
43
|
+
} finally {
|
|
44
|
+
r === D.current && (v(!1), b(!1));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
await e(0);
|
|
48
|
+
}, []);
|
|
49
|
+
return r(() => {
|
|
50
|
+
k();
|
|
51
|
+
}, [k]), r(() => {
|
|
52
|
+
if (p === void 0) return;
|
|
41
53
|
let e, t = () => {
|
|
42
54
|
e !== void 0 && (globalThis.clearInterval(e), e = void 0);
|
|
43
55
|
}, n = () => {
|
|
44
56
|
t(), e = globalThis.setInterval(() => {
|
|
45
|
-
|
|
46
|
-
},
|
|
57
|
+
k();
|
|
58
|
+
}, p);
|
|
47
59
|
}, r = () => {
|
|
48
60
|
document.visibilityState === "visible" ? n() : t();
|
|
49
61
|
};
|
|
50
62
|
return document.visibilityState === "visible" && n(), document.addEventListener("visibilitychange", r), () => {
|
|
51
63
|
t(), document.removeEventListener("visibilitychange", r);
|
|
52
64
|
};
|
|
53
|
-
}, [
|
|
54
|
-
if (!
|
|
65
|
+
}, [p, k]), r(() => {
|
|
66
|
+
if (!m) return;
|
|
55
67
|
let e = () => {
|
|
56
|
-
document.visibilityState === "visible" &&
|
|
68
|
+
document.visibilityState === "visible" && k();
|
|
57
69
|
}, t = () => {
|
|
58
|
-
|
|
70
|
+
k();
|
|
59
71
|
};
|
|
60
72
|
return document.addEventListener("visibilitychange", e), globalThis.addEventListener("online", t), () => {
|
|
61
73
|
document.removeEventListener("visibilitychange", e), globalThis.removeEventListener("online", t);
|
|
62
74
|
};
|
|
63
|
-
}, [
|
|
75
|
+
}, [m, k]), /* @__PURE__ */ o(f, {
|
|
64
76
|
value: {
|
|
65
|
-
user:
|
|
66
|
-
isAuthenticated:
|
|
67
|
-
isLoading:
|
|
68
|
-
isRefreshing:
|
|
69
|
-
|
|
77
|
+
user: h,
|
|
78
|
+
isAuthenticated: h !== null,
|
|
79
|
+
isLoading: _,
|
|
80
|
+
isRefreshing: y,
|
|
81
|
+
error: x,
|
|
82
|
+
refresh: k,
|
|
70
83
|
logout: async () => {
|
|
71
|
-
|
|
84
|
+
O.current?.abort(), D.current++, g(null), E.current = null, v(!1), b(!1), S(null), T.current?.();
|
|
72
85
|
try {
|
|
73
|
-
await
|
|
86
|
+
await w.current?.();
|
|
74
87
|
} catch (e) {
|
|
75
88
|
console.error("[OxAuthProvider] performLogout failed", e);
|
|
76
89
|
}
|
|
@@ -79,25 +92,25 @@ function d({ children: e, fetchUser: t, initialUser: o, onLogout: s, performLogo
|
|
|
79
92
|
children: e
|
|
80
93
|
});
|
|
81
94
|
}
|
|
82
|
-
function
|
|
83
|
-
return
|
|
95
|
+
function h() {
|
|
96
|
+
return p("useOxAuth");
|
|
84
97
|
}
|
|
85
|
-
function
|
|
86
|
-
let { user: e } =
|
|
98
|
+
function g() {
|
|
99
|
+
let { user: e } = h();
|
|
87
100
|
if (e === null) throw Error("useOxAuthUser must be used inside <OxAuthRequired> or in components that only render when authenticated");
|
|
88
101
|
return e;
|
|
89
102
|
}
|
|
90
|
-
function
|
|
91
|
-
let n = t(3), { user: r } =
|
|
92
|
-
return n[0] !== e || n[1] !== r ? (i =
|
|
103
|
+
function _(e) {
|
|
104
|
+
let n = t(3), { user: r } = h(), i;
|
|
105
|
+
return n[0] !== e || n[1] !== r ? (i = d(r).has(e), n[0] = e, n[1] = r, n[2] = i) : i = n[2], i;
|
|
93
106
|
}
|
|
94
|
-
function
|
|
95
|
-
let { children: t, fallback: n, loading: r } = e, i = n === void 0 ? null : n, a = r === void 0 ? null : r, { isAuthenticated: o, isLoading: s } =
|
|
107
|
+
function v(e) {
|
|
108
|
+
let { children: t, fallback: n, loading: r } = e, i = n === void 0 ? null : n, a = r === void 0 ? null : r, { isAuthenticated: o, isLoading: s } = h();
|
|
96
109
|
return s ? a : o ? t : i;
|
|
97
110
|
}
|
|
98
|
-
function
|
|
99
|
-
let { children: t, fallback: n, loading: r } = e, i = n === void 0 ? null : n, a = r === void 0 ? null : r, { isAuthenticated: o, isLoading: s } =
|
|
111
|
+
function y(e) {
|
|
112
|
+
let { children: t, fallback: n, loading: r } = e, i = n === void 0 ? null : n, a = r === void 0 ? null : r, { isAuthenticated: o, isLoading: s } = h();
|
|
100
113
|
return s ? a : o ? i : t;
|
|
101
114
|
}
|
|
102
115
|
//#endregion
|
|
103
|
-
export {
|
|
116
|
+
export { m as OxAuthProvider, v as OxAuthRequired, y as OxGuestOnly, h as useOxAuth, g as useOxAuthUser, _ as useOxPermission };
|
|
@@ -10,6 +10,8 @@ interface OxAuthProviderProps {
|
|
|
10
10
|
revalidateOnFocus?: boolean;
|
|
11
11
|
}
|
|
12
12
|
interface OxAuthContextValue {
|
|
13
|
+
/** Last refresh failure — session state unknown, NOT "logged out". */
|
|
14
|
+
error: unknown;
|
|
13
15
|
isAuthenticated: boolean;
|
|
14
16
|
isLoading: boolean;
|
|
15
17
|
isRefreshing: boolean;
|
package/dist/internal/tv.js
CHANGED
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { twMergeConfig as e } from "./twMergeConfig.js";
|
|
2
|
+
import { createTV as t } from "tailwind-variants";
|
|
2
3
|
//#region src/internal/tv.ts
|
|
3
|
-
var
|
|
4
|
-
theme: {
|
|
5
|
-
radius: ["control", "card"],
|
|
6
|
-
text: [
|
|
7
|
-
"control",
|
|
8
|
-
"3xs",
|
|
9
|
-
"2xs",
|
|
10
|
-
"body"
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
classGroups: {
|
|
14
|
-
h: [{ h: ["control"] }],
|
|
15
|
-
"min-h": [{ "min-h": ["control"] }],
|
|
16
|
-
px: [{ px: ["control"] }],
|
|
17
|
-
size: [{ size: ["icon"] }],
|
|
18
|
-
"bg-color": [{ bg: ["tone", "tone-soft"] }],
|
|
19
|
-
"text-color": [{ text: [
|
|
20
|
-
"tone-fg",
|
|
21
|
-
"tone-ink",
|
|
22
|
-
"tone-soft-fg"
|
|
23
|
-
] }],
|
|
24
|
-
"border-color": [{ border: ["tone-outline"] }]
|
|
25
|
-
}
|
|
26
|
-
} } });
|
|
4
|
+
var n = t({ twMergeConfig: e });
|
|
27
5
|
//#endregion
|
|
28
|
-
export {
|
|
6
|
+
export { n as tv };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/internal/twMergeConfig.ts
|
|
2
|
+
var e = { extend: {
|
|
3
|
+
theme: {
|
|
4
|
+
radius: ["control", "card"],
|
|
5
|
+
text: [
|
|
6
|
+
"control",
|
|
7
|
+
"3xs",
|
|
8
|
+
"2xs",
|
|
9
|
+
"body"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
classGroups: {
|
|
13
|
+
h: [{ h: ["control"] }],
|
|
14
|
+
"min-h": [{ "min-h": ["control"] }],
|
|
15
|
+
px: [{ px: ["control"] }],
|
|
16
|
+
size: [{ size: ["icon"] }],
|
|
17
|
+
"bg-color": [{ bg: ["tone", "tone-soft"] }],
|
|
18
|
+
"text-color": [{ text: [
|
|
19
|
+
"tone-fg",
|
|
20
|
+
"tone-ink",
|
|
21
|
+
"tone-soft-fg"
|
|
22
|
+
] }],
|
|
23
|
+
"border-color": [{ border: ["tone-outline"] }]
|
|
24
|
+
}
|
|
25
|
+
} };
|
|
26
|
+
//#endregion
|
|
27
|
+
export { e as twMergeConfig };
|
package/dist/utils/cn.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cn';
|
package/dist/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noxickon/onyx",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"types": "./dist/code-block/index.d.ts",
|
|
39
39
|
"import": "./dist/code-block.js"
|
|
40
40
|
},
|
|
41
|
+
"./utils": {
|
|
42
|
+
"types": "./dist/utils/index.d.ts",
|
|
43
|
+
"import": "./dist/utils.js"
|
|
44
|
+
},
|
|
41
45
|
"./styles": "./dist/index.css"
|
|
42
46
|
},
|
|
43
47
|
"files": [
|