@sanvika/ui 0.2.0 → 0.3.1
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/EmailIcon-ssF1iAVu.js +782 -0
- package/dist/icons/index.js +4 -0
- package/dist/index.js +583 -0
- package/package.json +7 -6
- package/src/context/ThemeContext.jsx +30 -21
- package/src/layouts/Layout.jsx +2 -2
- package/src/server/index.js +21 -7
|
@@ -15,29 +15,38 @@ export const ThemeProvider = ({ children }) => {
|
|
|
15
15
|
const [theme, setTheme] = useState("light"); // SSR fallback
|
|
16
16
|
|
|
17
17
|
// Step 1: On mount, load theme from localStorage. Default = dark.
|
|
18
|
+
// Defer state updates so this effect is not classified as synchronous setState-in-effect (react-hooks/set-state-in-effect).
|
|
18
19
|
useEffect(() => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
let cancelled = false;
|
|
21
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
22
|
+
const onSystemChange = (e) => {
|
|
23
|
+
if (!localStorage.getItem("theme")) {
|
|
24
|
+
const sys = e.matches ? "dark" : "light";
|
|
25
|
+
setTheme(sys);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
29
|
+
queueMicrotask(() => {
|
|
30
|
+
if (cancelled) return;
|
|
31
|
+
try {
|
|
32
|
+
const saved = localStorage.getItem("theme");
|
|
33
|
+
const resolved = saved ?? "dark"; // First visit = dark
|
|
34
|
+
setTheme(resolved);
|
|
35
|
+
document.documentElement.setAttribute("data-theme", resolved);
|
|
36
|
+
mq.addEventListener("change", onSystemChange);
|
|
37
|
+
setMounted(true);
|
|
38
|
+
} catch {
|
|
39
|
+
if (cancelled) return;
|
|
40
|
+
setTheme("dark");
|
|
41
|
+
document.documentElement.setAttribute("data-theme", "dark");
|
|
42
|
+
setMounted(true);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
cancelled = true;
|
|
48
|
+
mq.removeEventListener("change", onSystemChange);
|
|
49
|
+
};
|
|
41
50
|
}, []);
|
|
42
51
|
|
|
43
52
|
// Step 2: Apply theme with smooth transition class
|
package/src/layouts/Layout.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/layouts/Layout.jsx
|
|
2
|
-
import Navbar from "../components/layout/Navbar";
|
|
3
|
-
import Footer from "../components/layout/Footer";
|
|
2
|
+
import Navbar from "../components/layout/Navbar.jsx";
|
|
3
|
+
import Footer from "../components/layout/Footer.jsx";
|
|
4
4
|
import styles from "../styles/components/layouts/Layout.module.css";
|
|
5
5
|
|
|
6
6
|
/**
|
package/src/server/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
// @sanvika/ui/server v0.
|
|
1
|
+
// @sanvika/ui/server v0.3.0
|
|
2
2
|
// HTTP client for ui.sanvikaproduction.com — cloud-driven Navbar configs and Theme presets.
|
|
3
|
-
//
|
|
3
|
+
// Universal S2S Auth Pattern (ecosystem rule §21):
|
|
4
|
+
// PROJECT_NAME — clientId
|
|
5
|
+
// SANVIKA_SERVICE_KEY — Tier 1 trust
|
|
6
|
+
// UI_URL — service endpoint
|
|
7
|
+
// UI_CLIENT_SECRET — (optional, Tier 2 fallback for 3rd-party)
|
|
4
8
|
|
|
5
9
|
const DEFAULT_TIMEOUT_MS = 8000;
|
|
6
10
|
|
|
@@ -14,15 +18,21 @@ function _readEnv(key) {
|
|
|
14
18
|
|
|
15
19
|
export class SanvikaUI {
|
|
16
20
|
#url;
|
|
21
|
+
#clientId;
|
|
22
|
+
#serviceKey;
|
|
17
23
|
#secret;
|
|
18
24
|
|
|
19
|
-
constructor({ url, secret } = {}) {
|
|
25
|
+
constructor({ url, clientId, serviceKey, secret } = {}) {
|
|
20
26
|
const finalUrl = url || _readEnv("UI_URL");
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
const finalClientId = clientId || _readEnv("PROJECT_NAME") || _readEnv("UI_CLIENT_ID");
|
|
28
|
+
const finalServiceKey = serviceKey || _readEnv("SANVIKA_SERVICE_KEY") || "";
|
|
29
|
+
const finalSecret = secret || _readEnv("UI_CLIENT_SECRET") || ""; // Tier 2 fallback (optional)
|
|
30
|
+
if (!finalUrl || !finalClientId) {
|
|
31
|
+
throw new Error("@sanvika/ui/server: UI_URL and PROJECT_NAME are required");
|
|
24
32
|
}
|
|
25
33
|
this.#url = finalUrl.replace(/\/$/, "");
|
|
34
|
+
this.#clientId = finalClientId;
|
|
35
|
+
this.#serviceKey = finalServiceKey;
|
|
26
36
|
this.#secret = finalSecret;
|
|
27
37
|
}
|
|
28
38
|
|
|
@@ -37,7 +47,11 @@ export class SanvikaUI {
|
|
|
37
47
|
const qs = query ? "?" + new URLSearchParams(query).toString() : "";
|
|
38
48
|
const init = {
|
|
39
49
|
method,
|
|
40
|
-
headers: {
|
|
50
|
+
headers: {
|
|
51
|
+
"x-client-id": this.#clientId,
|
|
52
|
+
"x-service-key": this.#serviceKey,
|
|
53
|
+
"x-client-secret": this.#secret,
|
|
54
|
+
},
|
|
41
55
|
signal: controller.signal,
|
|
42
56
|
};
|
|
43
57
|
if (body !== undefined) {
|