@docyrus/ui-pro-ai-assistant 0.6.3 → 0.6.4
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/index.js +40 -13
- package/dist/index.js.map +1 -1
- package/dist/styles.css +6 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12377,10 +12377,23 @@ function GenerativeActionButton({
|
|
|
12377
12377
|
}
|
|
12378
12378
|
);
|
|
12379
12379
|
}
|
|
12380
|
+
var STREAMING_DEBOUNCE_MS = 250;
|
|
12381
|
+
var mermaidPromise = null;
|
|
12382
|
+
var loadMermaid = () => {
|
|
12383
|
+
if (!mermaidPromise) {
|
|
12384
|
+
mermaidPromise = import('mermaid').then((mod) => {
|
|
12385
|
+
mod.default.initialize({ startOnLoad: false, securityLevel: "loose" });
|
|
12386
|
+
return mod.default;
|
|
12387
|
+
});
|
|
12388
|
+
}
|
|
12389
|
+
return mermaidPromise;
|
|
12390
|
+
};
|
|
12380
12391
|
function MermaidRender({ content, className }) {
|
|
12381
12392
|
const containerRef = useRef(null);
|
|
12382
|
-
const
|
|
12383
|
-
const
|
|
12393
|
+
const svgHostRef = useRef(null);
|
|
12394
|
+
const sandboxRef = useRef(null);
|
|
12395
|
+
const [status, setStatus] = useState("idle");
|
|
12396
|
+
const [errorMessage, setErrorMessage] = useState(null);
|
|
12384
12397
|
const [zoom, setZoom] = useState(1);
|
|
12385
12398
|
const [pan, setPan] = useState({ x: 0, y: 0 });
|
|
12386
12399
|
const isDragging = useRef(false);
|
|
@@ -12388,20 +12401,34 @@ function MermaidRender({ content, className }) {
|
|
|
12388
12401
|
useEffect(() => {
|
|
12389
12402
|
if (!content) return;
|
|
12390
12403
|
let cancelled = false;
|
|
12391
|
-
const
|
|
12404
|
+
const debounce = window.setTimeout(async () => {
|
|
12392
12405
|
try {
|
|
12393
|
-
const
|
|
12394
|
-
|
|
12406
|
+
const mermaid = await loadMermaid();
|
|
12407
|
+
if (cancelled) return;
|
|
12408
|
+
const valid = await mermaid.parse(content, { suppressErrors: true });
|
|
12409
|
+
if (cancelled) return;
|
|
12410
|
+
if (!valid) {
|
|
12411
|
+
setErrorMessage("Invalid mermaid syntax");
|
|
12412
|
+
setStatus("error");
|
|
12413
|
+
return;
|
|
12414
|
+
}
|
|
12395
12415
|
const id = `mermaid-${Math.random().toString(36).slice(2)}`;
|
|
12396
|
-
const
|
|
12397
|
-
|
|
12416
|
+
const sandbox = sandboxRef.current ?? void 0;
|
|
12417
|
+
const { svg } = await mermaid.render(id, content, sandbox);
|
|
12418
|
+
if (cancelled) return;
|
|
12419
|
+
if (svgHostRef.current) svgHostRef.current.innerHTML = svg;
|
|
12420
|
+
setErrorMessage(null);
|
|
12421
|
+
setStatus("rendered");
|
|
12398
12422
|
} catch (err) {
|
|
12423
|
+
if (cancelled) return;
|
|
12399
12424
|
console.error("Mermaid render error:", err);
|
|
12425
|
+
setErrorMessage("Failed to render diagram");
|
|
12426
|
+
setStatus("error");
|
|
12400
12427
|
}
|
|
12401
|
-
};
|
|
12402
|
-
render();
|
|
12428
|
+
}, STREAMING_DEBOUNCE_MS);
|
|
12403
12429
|
return () => {
|
|
12404
12430
|
cancelled = true;
|
|
12431
|
+
window.clearTimeout(debounce);
|
|
12405
12432
|
};
|
|
12406
12433
|
}, [content]);
|
|
12407
12434
|
const zoomIn = () => setZoom((z) => Math.min(z + 0.15, 4));
|
|
@@ -12449,13 +12476,13 @@ function MermaidRender({ content, className }) {
|
|
|
12449
12476
|
onMouseUp,
|
|
12450
12477
|
onMouseLeave: onMouseUp,
|
|
12451
12478
|
children: [
|
|
12452
|
-
/* @__PURE__ */ jsx(
|
|
12479
|
+
/* @__PURE__ */ jsx("div", { ref: sandboxRef, "aria-hidden": true, className: "absolute -left-[99999px] top-0 h-0 w-0 overflow-hidden" }),
|
|
12480
|
+
status === "error" ? /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center p-4 text-xs text-muted-foreground", children: errorMessage }) : /* @__PURE__ */ jsx(
|
|
12453
12481
|
"div",
|
|
12454
12482
|
{
|
|
12455
|
-
ref:
|
|
12483
|
+
ref: svgHostRef,
|
|
12456
12484
|
className: "absolute inset-0 flex items-center justify-center",
|
|
12457
|
-
style: { transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`, transformOrigin: "center" }
|
|
12458
|
-
dangerouslySetInnerHTML: { __html: svg }
|
|
12485
|
+
style: { transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`, transformOrigin: "center" }
|
|
12459
12486
|
}
|
|
12460
12487
|
),
|
|
12461
12488
|
/* @__PURE__ */ jsxs("div", { className: "absolute bottom-3 left-3 z-10 flex gap-1", children: [
|