update GBadge to fix
All checks were successful
Build and Deploy Next.js + Nginx Docker Image / build-and-deploy (push) Successful in 50s
Build and Deploy Next.js + Nginx Docker Image / deploy (push) Successful in 7s

This commit is contained in:
Mohamadzadeh 2026-07-09 18:10:07 +03:30
parent 89c00bcf5f
commit b21b07953b
4 changed files with 3862 additions and 3794 deletions

60
dist/remote-ui.js vendored
View File

@ -1,37 +1,45 @@
import { jsx as c } from "react/jsx-runtime";
import { useRef as s, useEffect as i } from "react";
const a = "https://uikit.d.aiengines.ir/GBadge.js";
import { jsx as a } from "react/jsx-runtime";
import { useRef as i, useEffect as l } from "react";
const f = "https://uikit.d.aiengines.ir/GBadge.js";
let n = null;
function u() {
function m() {
return n || (n = import(
/* webpackIgnore: true */
/* @vite-ignore */
a
)), n;
f
).catch((e) => {
throw n = null, e;
})), n;
}
const m = (o) => {
const r = s(null);
return i(() => {
let e = !0;
return u().then((t) => {
e && r.current && t.mount(r.current, o);
}).catch((t) => {
console.error("[uikit/remote/ui] Failed to load GBadge:", t);
function p(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 R = ({ children: e, ...s }) => {
const o = i(null), t = i(null), u = i(null);
return u.current = {
...s,
children: p(e)
}, l(() => {
let c = !0;
return m().then(() => {
if (!c || !o.current) return;
const r = document.createElement("uikit-g-badge");
r.componentProps = u.current, o.current.appendChild(r), t.current = r;
}).catch((r) => {
console.error("[uikit/remote/ui] Failed to load GBadge:", r);
}), () => {
e = !1;
c = !1, t.current && (t.current.remove(), t.current = null);
};
}, [o]), i(() => {
const e = r.current;
return () => {
e && u().then((t) => {
t.unmount(e);
}).catch(() => {
});
};
}, []), /* @__PURE__ */ c(
}, []), l(() => {
t.current && (t.current.componentProps = u.current);
}), /* @__PURE__ */ a(
"span",
{
ref: r,
ref: o,
style: {
display: "contents"
}
@ -39,5 +47,5 @@ const m = (o) => {
);
};
export {
m as GBadge
R as GBadge
};

7467
dist/remote/GBadge.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,6 @@ import React from "react";
import { createRoot } from "react-dom/client";
import { Badge, ChakraProvider } from "@chakra-ui/react";
const roots = new WeakMap();
const GBadge = ({ children, ...props }) => {
return (
<Badge
@ -23,26 +21,52 @@ const GBadge = ({ children, ...props }) => {
);
};
export function mount(container, props) {
let root = roots.get(container);
class GBadgeElement extends HTMLElement {
constructor() {
super();
if (!root) {
root = createRoot(container);
roots.set(container, root);
this._props = {};
this._root = null;
}
root.render(
<ChakraProvider>
<GBadge {...props} />
</ChakraProvider>,
);
connectedCallback() {
if (!this._root) {
this._root = createRoot(this);
}
this.renderComponent();
}
disconnectedCallback() {
if (this._root) {
this._root.unmount();
this._root = null;
}
}
set componentProps(value) {
this._props = value ?? {};
if (this.isConnected) {
this.renderComponent();
}
}
get componentProps() {
return this._props;
}
renderComponent() {
if (!this._root) return;
this._root.render(
<ChakraProvider>
<GBadge {...this._props} />
</ChakraProvider>,
);
}
}
export function unmount(container) {
const root = roots.get(container);
if (!root) return;
root.unmount();
roots.delete(container);
if (!customElements.get("uikit-g-badge")) {
customElements.define("uikit-g-badge", GBadgeElement);
}

View File

@ -10,25 +10,56 @@ function loadRemote() {
/* webpackIgnore: true */
/* @vite-ignore */
REMOTE_URL
);
).catch((error) => {
remotePromise = null;
throw error;
});
}
return remotePromise;
}
export const GBadge = (props) => {
const containerRef = useRef(null);
function normalizeChildren(children) {
if (typeof children === "string" || typeof children === "number") {
return children;
}
if (children === null || children === undefined) {
return undefined;
}
console.warn(
"[uikit/remote/ui] GBadge only accepts text/number children across the remote boundary.",
);
return undefined;
}
export const GBadge = ({ children, ...props }) => {
const containerRef = useRef(null);
const elementRef = useRef(null);
const latestPropsRef = useRef(null);
latestPropsRef.current = {
...props,
children: normalizeChildren(children),
};
// mount و update
useEffect(() => {
let active = true;
loadRemote()
.then((remote) => {
.then(() => {
if (!active) return;
if (!containerRef.current) return;
remote.mount(containerRef.current, props);
const element = document.createElement("uikit-g-badge");
element.componentProps = latestPropsRef.current;
containerRef.current.appendChild(element);
elementRef.current = element;
})
.catch((error) => {
console.error("[uikit/remote/ui] Failed to load GBadge:", error);
@ -36,24 +67,20 @@ export const GBadge = (props) => {
return () => {
active = false;
};
}, [props]);
// unmount نهایی
useEffect(() => {
const container = containerRef.current;
return () => {
if (!container) return;
loadRemote()
.then((remote) => {
remote.unmount(container);
})
.catch(() => {});
if (elementRef.current) {
elementRef.current.remove();
elementRef.current = null;
}
};
}, []);
useEffect(() => {
if (!elementRef.current) return;
elementRef.current.componentProps = latestPropsRef.current;
});
return (
<span
ref={containerRef}