94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
import { jsx as g } from "react/jsx-runtime";
|
|
import h, { useRef as u, useEffect as m } from "react";
|
|
import { createRoot as _ } from "react-dom/client";
|
|
import { Badge as E, ChakraProvider as P } from "@chakra-ui/react";
|
|
const R = "https://uikit.d.aiengines.ir/GBadge.js", d = "__UIKIT_REMOTE_DEPS__", f = "__UIKIT_REMOTE_CONFIG__", i = /* @__PURE__ */ new Map();
|
|
function w(e = {}) {
|
|
if (typeof window > "u") return;
|
|
const r = window[d] || {}, n = window[f] || {};
|
|
window[d] = {
|
|
...r,
|
|
React: e.React || r.React || h,
|
|
createRoot: e.createRoot || r.createRoot || _,
|
|
ChakraProvider: e.ChakraProvider || r.ChakraProvider || P,
|
|
Badge: e.Badge || r.Badge || E,
|
|
theme: Object.prototype.hasOwnProperty.call(e, "theme") ? e.theme : r.theme,
|
|
chakraProviderProps: {
|
|
...r.chakraProviderProps || {},
|
|
...e.chakraProviderProps || {}
|
|
}
|
|
}, window[f] = {
|
|
...n,
|
|
...e.remoteUrl ? { GBadgeUrl: e.remoteUrl } : {}
|
|
};
|
|
}
|
|
function v() {
|
|
if (typeof window > "u") return;
|
|
const e = window[d];
|
|
(!(e != null && e.React) || !(e != null && e.createRoot) || !(e != null && e.ChakraProvider) || !(e != null && e.Badge)) && w();
|
|
}
|
|
function k() {
|
|
var e;
|
|
return typeof window > "u" ? R : ((e = window[f]) == null ? void 0 : e.GBadgeUrl) || R;
|
|
}
|
|
function y() {
|
|
const e = k();
|
|
return i.has(e) || i.set(
|
|
e,
|
|
import(
|
|
/* webpackIgnore: true */
|
|
/* @vite-ignore */
|
|
e
|
|
).catch((r) => {
|
|
throw i.delete(e), r;
|
|
})
|
|
), i.get(e);
|
|
}
|
|
function B(e) {
|
|
if (typeof e == "string" || typeof e == "number")
|
|
return e;
|
|
e != null && console.warn(
|
|
"[uikit/remote/ui] GBadge only accepts text/number children across the remote boundary."
|
|
);
|
|
}
|
|
const T = ({
|
|
children: e,
|
|
remoteUrl: r,
|
|
theme: n,
|
|
chakraProviderProps: s,
|
|
...p
|
|
}) => {
|
|
const a = u(null), t = u(null), c = u(null);
|
|
return c.current = {
|
|
...p,
|
|
children: B(e),
|
|
...n !== void 0 ? { theme: n } : {},
|
|
...s ? { chakraProviderProps: s } : {}
|
|
}, m(() => {
|
|
let l = !0;
|
|
return v(), r && w({ remoteUrl: r }), y().then(() => {
|
|
if (!l || !a.current) return;
|
|
const o = document.createElement("uikit-g-badge");
|
|
o.componentProps = c.current, a.current.appendChild(o), t.current = o;
|
|
}).catch((o) => {
|
|
console.error("[uikit/remote/ui] Failed to load GBadge:", o);
|
|
}), () => {
|
|
l = !1, t.current && (t.current.remove(), t.current = null);
|
|
};
|
|
}, [r]), m(() => {
|
|
t.current && (t.current.componentProps = c.current);
|
|
}), /* @__PURE__ */ g(
|
|
"span",
|
|
{
|
|
ref: a,
|
|
style: {
|
|
display: "contents"
|
|
}
|
|
}
|
|
);
|
|
};
|
|
export {
|
|
T as GBadge,
|
|
w as setupUikitRemoteDeps
|
|
};
|