uikit/dist/chunks/BiProvider-Bnbwo_Mg.js
Mohamadzadeh 2d770da511
All checks were successful
Build and Deploy Next.js + Nginx Docker Image / build-and-deploy (push) Successful in 1m2s
Build and Deploy Next.js + Nginx Docker Image / deploy (push) Successful in 8s
uikit-v1.3.2-variable-font-complete
2026-10-27 18:49:01 +03:30

455 lines
12 KiB
JavaScript

import { jsx as d, jsxs as U } from "react/jsx-runtime";
import G, { useState as E, useRef as q, useCallback as v, useEffect as x, useMemo as A, createContext as N } from "react";
import { createRoot as V } from "react-dom/client";
import { extendTheme as W, withDefaultColorScheme as Y, ChakraProvider as L, Spinner as H, Badge as J } from "@chakra-ui/react";
import { useQuery as X, QueryClient as Z, QueryClientProvider as ee } from "@tanstack/react-query";
import * as F from "next-query-params/pages";
import * as te from "use-query-params";
import re from "keycloak-js";
import { setKeycloakLogoutHandler as ne, usePermission as D, PermissionContext as oe } from "../core-runtime.js";
import se from "axios";
import { Global as ie } from "@emotion/react";
import { e as ae } from "./estedad-B1AoGIKy.js";
let C = null, o = null, _ = null, T = !1;
const ce = N(null), le = ({ url: e, realm: r, clientId: t }) => (o || (o = new re({
url: e,
realm: r,
clientId: t
})), o), ue = (e) => (C = e, C), de = () => T, j = () => !!(o != null && o.authenticated), b = () => (o == null ? void 0 : o.token) ?? null, z = async (e = 30) => o ? o.updateToken(e) : !1, I = (e) => o == null ? void 0 : o.logout(e);
ne(I);
const Me = (e) => o == null ? void 0 : o.login(e), Q = ({ config: e, initOptions: r = {} } = {}) => {
const t = e ?? C;
if (!(t != null && t.url) || !(t != null && t.realm) || !(t != null && t.clientId))
throw new Error("Keycloak config is required.");
ue(t);
const n = le(t);
return _ || (_ = n.init({
onLoad: "login-required",
checkLoginIframe: !1,
flow: "implicit",
...r
}).then((a) => (T = !0, a)).catch((a) => {
throw T = !0, a;
})), _;
}, fe = ({
children: e,
config: r,
initOptions: t,
loading: n = null
}) => {
const [a, f] = E(!1), [c, s] = E(!1), [i, l] = E(null), u = q(!1), h = v(() => {
o && (s(!!o.authenticated), l(o.token ?? null));
}, []);
x(() => (u.current = !0, Q({ config: r, initOptions: t }).then((p) => {
u.current && (s(!!p), l((o == null ? void 0 : o.token) ?? null), f(!0));
}).catch(() => {
u.current && (s(!1), l(null), f(!0));
}), () => {
u.current = !1;
}), [r, t]);
const w = v(() => o == null ? void 0 : o.login(), []), m = v((p) => o == null ? void 0 : o.logout(p), []), y = v(
async (p = 30) => {
if (!o) return !1;
const g = await o.updateToken(p);
return h(), g;
},
[h]
), P = A(
() => ({
initialized: a,
authenticated: c,
token: i,
login: w,
logout: m,
updateToken: y
}),
[a, c, i, w, m, y]
);
return a ? /* @__PURE__ */ d(ce.Provider, { value: P, children: e }) : n;
};
let S = null;
const he = (e) => {
const { api: r } = e, t = se.create({
baseURL: r.baseUrl
}), n = async () => {
(!de() || !j()) && await Q();
}, a = !!e.keycloak, f = async (s) => {
if (!a) return s;
await n();
let i = b();
if (i) {
try {
await z(5), i = b();
} catch {
}
s.headers = {
...s.headers,
Authorization: `Bearer ${i}`
};
}
return s;
}, c = async (s) => {
var l;
const i = s.config;
if (((l = s == null ? void 0 : s.response) == null ? void 0 : l.status) === 401 && !(i != null && i._retry)) {
i._retry = !0;
try {
await z(30);
const u = b();
return i.headers = {
...i.headers,
Authorization: `Bearer ${u}`
}, t(i);
} catch {
I({ redirectUri: window.location.origin });
}
}
return Promise.reject(s);
};
return t.interceptors.request.use(f), t.interceptors.response.use(
(s) => s,
c
), {
api: t
};
}, pe = (e) => (S = he(e), S), me = () => {
if (!S)
throw new Error("api is not configured. Call configureApi(config) first.");
return S.api;
}, we = new Proxy(
{},
{
get(e, r) {
return me()[r];
}
}
), $e = async (e) => (await we.get(e)).data, B = "permissions", ye = (e) => (e == null ? void 0 : e.storageKey) || B, Pe = ({
user: e = null,
children: r,
config: t,
loading: n = /* @__PURE__ */ d("div", { children: "Loading permissions..." }),
errorFallback: a = /* @__PURE__ */ d("div", { children: "Error loading permissions" })
}) => {
const f = ye(t), [c, s] = E(
() => ve(f)
), { data: i, isLoading: l, error: u } = ke(t), h = i ?? c;
x(() => {
i && (Ee(f, i), s(i));
}, [i, f]);
const w = A(
() => xe(h),
[h]
), m = v(
(p = "") => ge(w, p),
[w]
), y = v((p = "") => !m(p), [m]), P = A(
() => ({
user: e,
can: m,
cannot: y,
permissions: h,
isLoading: l,
error: u
}),
[e, m, y, h, l, u]
);
return u && !h ? a : l && !h ? n : /* @__PURE__ */ d(oe.Provider, { value: P, children: r });
}, ve = (e = B) => {
if (!(typeof window > "u"))
try {
const r = localStorage.getItem(e);
return r ? JSON.parse(r) : void 0;
} catch {
return;
}
}, Ee = (e = B, r) => {
if (!(typeof window > "u"))
try {
localStorage.setItem(e, JSON.stringify(r));
} catch {
}
}, Ge = (e = B) => {
if (!(typeof window > "u"))
try {
localStorage.removeItem(e);
} catch {
}
}, xe = (e) => e ? new Set(e.map((r) => r.name)) : /* @__PURE__ */ new Set(), ge = (e, r = "") => {
if (!r) return !1;
if (e.has(r) || [...e].some((n) => n.startsWith(r))) return !0;
let t = r;
for (; t.includes(":"); )
if (t = t.slice(0, t.lastIndexOf(":")), e.has(`${t}:*`)) return !0;
return !1;
}, M = {
all: ["permissions"],
list: (e) => [...M.all, e]
}, Ke = async (e) => {
if (!(e != null && e.url) || !(e != null && e.clientId))
throw new Error("Permission config requires url and clientId.");
const r = b(), t = new URL(e.url);
t.searchParams.set("client_id", e.clientId);
const n = await fetch(t.toString(), {
method: "GET",
headers: {
...r ? { Authorization: `Bearer ${r}` } : {}
}
});
if (!n.ok)
throw new Error("Failed to load permissions");
return n.json();
}, ke = (e) => X({
queryKey: M.list(e == null ? void 0 : e.clientId),
queryFn: () => Ke(e),
enabled: !!(e != null && e.url) && !!(e != null && e.clientId) && j(),
staleTime: 1 / 0,
refetchOnWindowFocus: !1,
refetchOnReconnect: !1
}), Ne = ({
perm: e,
children: r,
fallback: t = /* @__PURE__ */ d("div", { children: "You are not allowed to do this" })
}) => {
const { can: n } = D();
return n(e) ? r : t;
}, Ve = ({ children: e }) => {
const { can: r, permissions: t } = D();
return t && r("admin") ? e : null;
}, We = ({ children: e, forceNoAccess: r = !1 }) => {
const { can: t, isLoading: n } = D();
return x(() => {
n || (r || !t("panel_access")) && I();
}, [n, t, r]), e;
};
function be() {
const [e, r] = E(!1), t = q(null);
return x(() => {
if (process.env.NODE_ENV !== "production") return;
let n;
const a = async () => {
const c = await fetch(`/version.json?t=${Date.now()}`, {
cache: "no-store"
});
if (!c.ok)
throw new Error(`Failed to fetch version: ${c.status}`);
const s = await c.json();
return String(s.version);
};
return (async () => {
try {
t.current = await a(), n = setInterval(async () => {
try {
const c = await a();
t.current && c !== t.current && (r(!0), clearInterval(n));
} catch (c) {
console.error("Update check failed:", c);
}
}, 3e4);
} catch (c) {
console.error("Initial version fetch failed:", c);
}
})(), () => {
n && clearInterval(n);
};
}, []), e ? /* @__PURE__ */ d(
"div",
{
style: {
position: "fixed",
bottom: "16px",
right: "16px",
background: "#111",
color: "#fff",
padding: "12px 16px",
borderRadius: "8px",
zIndex: 9999,
cursor: "pointer"
},
onClick: () => window.location.reload(),
children: "نسخه جدید سامانه در دسترس است"
}
) : null;
}
const Ae = new Z({
defaultOptions: {
queries: {
retry: 1,
refetchOnWindowFocus: !1
}
}
}), Se = W(
{
direction: "rtl",
styles: {
global: {
html: {
fontSize: "14px",
direction: "rtl"
},
body: {
bg: "white",
direction: "rtl"
},
"*": {
boxSizing: "border-box"
}
}
},
fonts: {
heading: "Estedad",
body: "Estedad"
},
colors: {
facebook: {
50: "#E8F4F9",
100: "#D9DEE9",
200: "#B7C2DA",
300: "#6482C0",
400: "#4267B2",
500: "#385898",
600: "#314E89",
700: "#29487D",
800: "#223B67",
900: "#1E355B"
}
}
},
Y({ colorScheme: "facebook" })
), Be = () => /* @__PURE__ */ d(
ie,
{
styles: `
@font-face {
font-family: Estedad;
src: url("${ae}") format("woff2");
font-weight: 100 900;
font-style: normal;
font-display: swap;
}
`
}
), $ = (e, r) => {
let t = e;
for (let n = 0; n < 4 && t; n += 1) {
const a = Reflect.get(t, r);
if (a !== void 0) return a;
t = Reflect.get(t, "default");
}
}, Re = (e) => {
let r = e;
for (let t = 0; t < 4 && r; t += 1) {
const n = Reflect.get(r, "default");
if (n === void 0) break;
r = n;
}
return r;
}, _e = $(
te,
"QueryParamProvider"
), Ce = $(F, "NextAdapterPages") ?? Re(F), O = "__UIKIT_REMOTE_DEPS__";
function Te({ theme: e, chakraProviderProps: r } = {}) {
if (typeof window > "u") return;
const t = window[O] || {};
window[O] = {
...t,
React: t.React || G,
createRoot: t.createRoot || V,
ChakraProvider: t.ChakraProvider || L,
Badge: t.Badge || J,
theme: e ?? t.theme,
chakraProviderProps: {
...t.chakraProviderProps || {},
...r || {}
}
};
}
function Ye({
children: e,
apiBaseUrl: r,
keycloakClientId: t,
permissionClientId: n,
loading: a = /* @__PURE__ */ d(H, {}),
updateChecker: f = !1,
updateCheckerProps: c,
keycloakUrl: s = "https://auth.ibagher.ir",
keycloakRealm: i = "bi",
permissionUrl: l = "https://api.d.aiengines.ir/user_api/v1/permissions/list",
keycloakEnabled: u,
permissionEnabled: h,
theme: w = Se,
remoteUiEnabled: m = !0,
remoteUiChakraProviderProps: y
}) {
const [P, p] = E(!1), g = u ?? !!t, R = h ?? !!n, k = A(
() => ({
api: {
baseUrl: r || ""
},
keycloak: g ? {
url: s,
realm: i,
clientId: t
} : null,
permission: R ? {
url: l,
clientId: n
} : null
}),
[
r,
g,
R,
s,
i,
t,
l,
n
]
);
if (x(() => {
p(!0);
}, []), x(() => {
P && pe(k);
}, [P, k]), !P)
return null;
m && Te({
theme: w,
chakraProviderProps: y
});
let K = e;
return R && (K = /* @__PURE__ */ d(Pe, { config: k.permission, loading: a, children: K })), g && (K = /* @__PURE__ */ d(fe, { config: k.keycloak, loading: a, children: K })), /* @__PURE__ */ U(L, { theme: w, children: [
/* @__PURE__ */ d(Be, {}),
/* @__PURE__ */ U(ee, { client: Ae, children: [
f && /* @__PURE__ */ d(be, { ...c }),
/* @__PURE__ */ d(_e, { adapter: Ce, children: K })
] })
] });
}
export {
Ve as A,
Ye as B,
Ne as C,
fe as K,
We as P,
we as a,
Pe as b,
ge as c,
Ge as d,
pe as e,
$e as f,
xe as g,
me as h,
ve as i,
b as j,
Ke as k,
Q as l,
j as m,
de as n,
Me as o,
I as p,
M as q,
ke as r,
Ee as s,
z as u
};