60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
import p, { useRef as a, useEffect as R } from "react";
|
|
import { createRoot as d } from "react-dom/client";
|
|
import { R as m } from "./constants-Bq1Au9ih.js";
|
|
const u = /* @__PURE__ */ new Map();
|
|
function E() {
|
|
if (typeof window > "u") return;
|
|
const e = window[m] || {};
|
|
window[m] = {
|
|
...e,
|
|
React: e.React || p,
|
|
createRoot: e.createRoot || d
|
|
};
|
|
}
|
|
function w(e, r) {
|
|
const t = `${e}:${r}`;
|
|
return u.has(t) || u.set(
|
|
t,
|
|
import(
|
|
/* webpackIgnore: true */
|
|
/* @vite-ignore */
|
|
r
|
|
).catch((c) => {
|
|
throw u.delete(t), c;
|
|
})
|
|
), u.get(t);
|
|
}
|
|
function v({
|
|
componentName: e,
|
|
tagName: r,
|
|
defaultRemoteUrl: t,
|
|
normalizeProps: c
|
|
}) {
|
|
return function(f) {
|
|
const s = a(null), n = a(null), i = a(null);
|
|
return i.current = c ? c(f) : f, R(() => {
|
|
let l = !0;
|
|
return E(), w(e, t).then(() => {
|
|
if (!l || !s.current) return;
|
|
const o = document.createElement(r);
|
|
o.componentProps = i.current, s.current.appendChild(o), n.current = o;
|
|
}).catch((o) => {
|
|
console.error(
|
|
`[uikit/remote/ui] Failed to load ${e}:`,
|
|
o
|
|
);
|
|
}), () => {
|
|
l = !1, n.current && (n.current.remove(), n.current = null);
|
|
};
|
|
}, [e, t, r]), R(() => {
|
|
n.current && (n.current.componentProps = i.current);
|
|
}), p.createElement("span", {
|
|
ref: s,
|
|
style: { display: "contents" }
|
|
});
|
|
};
|
|
}
|
|
export {
|
|
v as c
|
|
};
|