@cjlapao/ui-kit 0.2.45 → 0.2.46
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.cjs +399 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +6 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +102 -23
- package/dist/index.d.ts +102 -23
- package/dist/index.js +399 -48
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -83466,6 +83466,10 @@ function KnowledgeMap({
|
|
|
83466
83466
|
hoverHighlight = true,
|
|
83467
83467
|
grid = true,
|
|
83468
83468
|
gridTone = "blue",
|
|
83469
|
+
autoRevealSelected = true,
|
|
83470
|
+
autoCenterSelected = true,
|
|
83471
|
+
autoFitOnInspector = false,
|
|
83472
|
+
onViewportChange,
|
|
83469
83473
|
size: controlSize = "sm",
|
|
83470
83474
|
controlsTone = "auto",
|
|
83471
83475
|
onDiagnostics,
|
|
@@ -83537,16 +83541,7 @@ function KnowledgeMap({
|
|
|
83537
83541
|
(0, import_react388.useEffect)(() => {
|
|
83538
83542
|
onDiagnostics?.(geometry.diagnostics);
|
|
83539
83543
|
}, [geometry.diagnostics, onDiagnostics]);
|
|
83540
|
-
(0, import_react388.
|
|
83541
|
-
const host = hostRef.current;
|
|
83542
|
-
if (!host) return;
|
|
83543
|
-
const update = () => setSize({ width: Math.max(1, host.clientWidth), height: Math.max(120, height) });
|
|
83544
|
-
update();
|
|
83545
|
-
if (typeof ResizeObserver === "undefined") return;
|
|
83546
|
-
const observer = new ResizeObserver(update);
|
|
83547
|
-
observer.observe(host);
|
|
83548
|
-
return () => observer.disconnect();
|
|
83549
|
-
}, [height]);
|
|
83544
|
+
const sizeRef = (0, import_react388.useRef)(size);
|
|
83550
83545
|
const bounds = (0, import_react388.useMemo)(() => {
|
|
83551
83546
|
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
83552
83547
|
for (const point of scene.points) {
|
|
@@ -83649,14 +83644,124 @@ function KnowledgeMap({
|
|
|
83649
83644
|
for (let node = hostRef.current; node; node = node.parentElement) observer.observe(node, { attributes: true, attributeFilter: ["class", "data-color-scheme", "style"] });
|
|
83650
83645
|
return () => observer.disconnect();
|
|
83651
83646
|
}, []);
|
|
83652
|
-
const
|
|
83653
|
-
|
|
83654
|
-
|
|
83655
|
-
|
|
83656
|
-
|
|
83657
|
-
|
|
83647
|
+
const cameraRef = (0, import_react388.useRef)(camera);
|
|
83648
|
+
const commitCamera = (0, import_react388.useCallback)((next) => {
|
|
83649
|
+
setCamera((current) => {
|
|
83650
|
+
const value = typeof next === "function" ? next(current) : next;
|
|
83651
|
+
cameraRef.current = value;
|
|
83652
|
+
return value;
|
|
83653
|
+
});
|
|
83654
|
+
}, []);
|
|
83655
|
+
(0, import_react388.useEffect)(() => {
|
|
83656
|
+
onViewportChange?.({ ...camera });
|
|
83657
|
+
}, [camera, onViewportChange]);
|
|
83658
|
+
(0, import_react388.useEffect)(() => {
|
|
83659
|
+
const host = hostRef.current;
|
|
83660
|
+
if (!host) return;
|
|
83661
|
+
const update = () => {
|
|
83662
|
+
const rect = host.getBoundingClientRect();
|
|
83663
|
+
const next = { width: Math.max(1, rect.width), height: Math.max(120, height) };
|
|
83664
|
+
const prev = sizeRef.current;
|
|
83665
|
+
if (prev.width === next.width && prev.height === next.height) return;
|
|
83666
|
+
const cam = cameraRef.current;
|
|
83667
|
+
if (Math.abs(cam.zoom - 1) > 1e-6 && scene.points.length) {
|
|
83668
|
+
const fit = (w, h) => Math.max(1e-6, Math.min((w - 100) / bounds.width, (h - 100) / bounds.height, 3));
|
|
83669
|
+
const oldFit = fit(prev.width, prev.height), newFit = fit(next.width, next.height);
|
|
83670
|
+
if (oldFit !== newFit) commitCamera((current) => ({ zoom: current.zoom * (oldFit / newFit), x: current.x + (prev.width - next.width) / 2, y: current.y + (prev.height - next.height) / 2 }));
|
|
83671
|
+
}
|
|
83672
|
+
sizeRef.current = next;
|
|
83673
|
+
setSize(next);
|
|
83674
|
+
};
|
|
83675
|
+
update();
|
|
83676
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
83677
|
+
const observer = new ResizeObserver(update);
|
|
83678
|
+
observer.observe(host);
|
|
83679
|
+
return () => observer.disconnect();
|
|
83680
|
+
}, [height, bounds, scene.points.length, commitCamera]);
|
|
83681
|
+
const panFrame = (0, import_react388.useRef)(null);
|
|
83682
|
+
const cancelPan = (0, import_react388.useCallback)(() => {
|
|
83683
|
+
if (panFrame.current !== null) {
|
|
83684
|
+
cancelAnimationFrame(panFrame.current);
|
|
83685
|
+
panFrame.current = null;
|
|
83686
|
+
}
|
|
83687
|
+
}, []);
|
|
83688
|
+
const animateView = (0, import_react388.useCallback)((target, onDone) => {
|
|
83689
|
+
cancelPan();
|
|
83690
|
+
const from = cameraRef.current;
|
|
83691
|
+
if (from.x === target.x && from.y === target.y && from.zoom === target.zoom) {
|
|
83692
|
+
onDone?.();
|
|
83693
|
+
return;
|
|
83694
|
+
}
|
|
83695
|
+
const commit = (v) => {
|
|
83696
|
+
cameraRef.current = v;
|
|
83697
|
+
setCamera(v);
|
|
83658
83698
|
};
|
|
83659
|
-
|
|
83699
|
+
if (typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
83700
|
+
commit(target);
|
|
83701
|
+
onDone?.();
|
|
83702
|
+
return;
|
|
83703
|
+
}
|
|
83704
|
+
const start = Date.now();
|
|
83705
|
+
const step = () => {
|
|
83706
|
+
panFrame.current = requestAnimationFrame(() => {
|
|
83707
|
+
const t = Math.min(1, (Date.now() - start) / 300), e = 1 - Math.pow(1 - t, 3);
|
|
83708
|
+
commit({ x: from.x + (target.x - from.x) * e, y: from.y + (target.y - from.y) * e, zoom: from.zoom + (target.zoom - from.zoom) * e });
|
|
83709
|
+
if (t < 1) step();
|
|
83710
|
+
else {
|
|
83711
|
+
panFrame.current = null;
|
|
83712
|
+
onDone?.();
|
|
83713
|
+
}
|
|
83714
|
+
});
|
|
83715
|
+
};
|
|
83716
|
+
step();
|
|
83717
|
+
}, [cancelPan]);
|
|
83718
|
+
const revealPoint = (0, import_react388.useCallback)((point, center = false) => {
|
|
83719
|
+
const v = cameraRef.current, margin = 18;
|
|
83720
|
+
if (center) {
|
|
83721
|
+
animateView({ zoom: v.zoom, x: -(point.x - bounds.x) * fitZoom * v.zoom, y: -(point.y - bounds.y) * fitZoom * v.zoom });
|
|
83722
|
+
return;
|
|
83723
|
+
}
|
|
83724
|
+
const sx = (point.x - bounds.x) * fitZoom * v.zoom + size.width / 2 + v.x;
|
|
83725
|
+
const sy = (point.y - bounds.y) * fitZoom * v.zoom + size.height / 2 + v.y;
|
|
83726
|
+
let dx = 0, dy = 0;
|
|
83727
|
+
if (sx < margin) dx = margin - sx;
|
|
83728
|
+
else if (sx > size.width - margin) dx = size.width - margin - sx;
|
|
83729
|
+
if (sy < margin) dy = margin - sy;
|
|
83730
|
+
else if (sy > size.height - margin) dy = size.height - margin - sy;
|
|
83731
|
+
if (dx === 0 && dy === 0) return;
|
|
83732
|
+
animateView({ x: v.x + dx, y: v.y + dy, zoom: v.zoom });
|
|
83733
|
+
}, [animateView, bounds, fitZoom, size]);
|
|
83734
|
+
const zoom = (0, import_react388.useCallback)((factor, anchor = { x: size.width / 2, y: size.height / 2 }) => {
|
|
83735
|
+
cancelPan();
|
|
83736
|
+
commitCamera((current) => {
|
|
83737
|
+
const next = Math.max(0.25, Math.min(24, current.zoom * factor)), scale = next / current.zoom;
|
|
83738
|
+
return {
|
|
83739
|
+
zoom: next,
|
|
83740
|
+
x: anchor.x - size.width / 2 - (anchor.x - size.width / 2 - current.x) * scale,
|
|
83741
|
+
y: anchor.y - size.height / 2 - (anchor.y - size.height / 2 - current.y) * scale
|
|
83742
|
+
};
|
|
83743
|
+
});
|
|
83744
|
+
}, [cancelPan, commitCamera, size.width, size.height]);
|
|
83745
|
+
const cameraMove = (0, import_react388.useRef)({ reveal: revealPoint, fit: animateView });
|
|
83746
|
+
cameraMove.current = { reveal: revealPoint, fit: animateView };
|
|
83747
|
+
const wasSelected = (0, import_react388.useRef)(false);
|
|
83748
|
+
(0, import_react388.useEffect)(() => {
|
|
83749
|
+
const opening = !!selection && !wasSelected.current;
|
|
83750
|
+
wasSelected.current = !!selection;
|
|
83751
|
+
if (!selection || disabled || loading) return;
|
|
83752
|
+
if (!autoRevealSelected && !autoFitOnInspector) return;
|
|
83753
|
+
const positioned = scene.points.find((point) => point.memoryId === selection);
|
|
83754
|
+
if (!positioned) return;
|
|
83755
|
+
const reduced = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
83756
|
+
const timer = setTimeout(() => {
|
|
83757
|
+
if (opening && autoFitOnInspector) cameraMove.current.fit(INITIAL_CAMERA, () => {
|
|
83758
|
+
if (autoRevealSelected) cameraMove.current.reveal(positioned, autoCenterSelected);
|
|
83759
|
+
});
|
|
83760
|
+
else if (autoRevealSelected) cameraMove.current.reveal(positioned, autoCenterSelected);
|
|
83761
|
+
}, reduced ? 0 : 260);
|
|
83762
|
+
return () => clearTimeout(timer);
|
|
83763
|
+
}, [selection, disabled, loading, autoRevealSelected, autoCenterSelected, autoFitOnInspector, scene]);
|
|
83764
|
+
(0, import_react388.useEffect)(() => cancelPan, [cancelPan]);
|
|
83660
83765
|
(0, import_react388.useEffect)(() => {
|
|
83661
83766
|
const canvas = canvasRef.current;
|
|
83662
83767
|
if (!canvas) return;
|
|
@@ -83725,15 +83830,17 @@ function KnowledgeMap({
|
|
|
83725
83830
|
"aria-describedby": helpId,
|
|
83726
83831
|
onKeyDown: (event) => {
|
|
83727
83832
|
if (disabled || loading) return;
|
|
83833
|
+
cancelPan();
|
|
83728
83834
|
if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "+", "=", "-", "Home", "Escape"].includes(event.key)) event.preventDefault();
|
|
83729
83835
|
if (event.key === "+" || event.key === "=") zoom(1.3);
|
|
83730
83836
|
else if (event.key === "-") zoom(1 / 1.3);
|
|
83731
|
-
else if (event.key === "Home")
|
|
83837
|
+
else if (event.key === "Home") commitCamera(INITIAL_CAMERA);
|
|
83732
83838
|
else if (event.key === "Escape") select(null);
|
|
83733
|
-
else if (event.key.startsWith("Arrow"))
|
|
83839
|
+
else if (event.key.startsWith("Arrow")) commitCamera((current) => ({ ...current, x: current.x + (event.key === "ArrowLeft" ? 32 : event.key === "ArrowRight" ? -32 : 0), y: current.y + (event.key === "ArrowUp" ? 32 : event.key === "ArrowDown" ? -32 : 0) }));
|
|
83734
83840
|
},
|
|
83735
83841
|
onPointerDown: (event) => {
|
|
83736
83842
|
if (disabled || loading || event.button !== 0) return;
|
|
83843
|
+
cancelPan();
|
|
83737
83844
|
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
83738
83845
|
drag.current = { x: event.clientX, y: event.clientY, camera, moved: false };
|
|
83739
83846
|
},
|
|
@@ -83745,7 +83852,7 @@ function KnowledgeMap({
|
|
|
83745
83852
|
if (Math.hypot(dx, dy) > 4) start.moved = true;
|
|
83746
83853
|
if (start.moved) {
|
|
83747
83854
|
setHovered(null);
|
|
83748
|
-
|
|
83855
|
+
commitCamera({ ...start.camera, x: start.camera.x + dx, y: start.camera.y + dy });
|
|
83749
83856
|
}
|
|
83750
83857
|
return;
|
|
83751
83858
|
}
|
|
@@ -83771,7 +83878,10 @@ function KnowledgeMap({
|
|
|
83771
83878
|
),
|
|
83772
83879
|
!loading && !scene.points.length && /* @__PURE__ */ (0, import_jsx_runtime416.jsx)("p", { className: "kit-knowledge-map-empty", role: "status", children: copy("empty") }),
|
|
83773
83880
|
showControls && !loading && /* @__PURE__ */ (0, import_jsx_runtime416.jsxs)("div", { className: "absolute bottom-3 right-3 z-10 flex items-center gap-0.5 rounded-lg border border-neutral-200 bg-white/90 p-1 shadow-sm backdrop-blur dark:border-neutral-700 dark:bg-neutral-900/90", children: [
|
|
83774
|
-
/* @__PURE__ */ (0, import_jsx_runtime416.jsx)(IconButton_default, { size: "xs", variant: "ghost", color: chain.controlsTone, disabled, srLabel: copy("fit"), tooltip: copy("fit"), onClick: () =>
|
|
83881
|
+
/* @__PURE__ */ (0, import_jsx_runtime416.jsx)(IconButton_default, { size: "xs", variant: "ghost", color: chain.controlsTone, disabled, srLabel: copy("fit"), tooltip: copy("fit"), onClick: () => {
|
|
83882
|
+
cancelPan();
|
|
83883
|
+
commitCamera(INITIAL_CAMERA);
|
|
83884
|
+
}, icon: /* @__PURE__ */ (0, import_jsx_runtime416.jsxs)("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
83775
83885
|
/* @__PURE__ */ (0, import_jsx_runtime416.jsx)("path", { d: "M4 9V5a1 1 0 0 1 1-1h4" }),
|
|
83776
83886
|
/* @__PURE__ */ (0, import_jsx_runtime416.jsx)("path", { d: "M15 4h4a1 1 0 0 1 1 1v4" }),
|
|
83777
83887
|
/* @__PURE__ */ (0, import_jsx_runtime416.jsx)("path", { d: "M20 15v4a1 1 0 0 1-1 1h-4" }),
|
|
@@ -83784,8 +83894,9 @@ function KnowledgeMap({
|
|
|
83784
83894
|
] }),
|
|
83785
83895
|
/* @__PURE__ */ (0, import_jsx_runtime416.jsx)(IconButton_default, { size: "xs", variant: "ghost", color: chain.controlsTone, disabled: disabled || camera.zoom >= 24, srLabel: copy("zoomIn"), tooltip: copy("zoomIn"), onClick: () => zoom(1.3), icon: "Add" }),
|
|
83786
83896
|
/* @__PURE__ */ (0, import_jsx_runtime416.jsx)(IconButton_default, { size: "xs", variant: "ghost", color: chain.controlsTone, disabled, srLabel: copy("reset"), tooltip: copy("reset"), onClick: () => {
|
|
83897
|
+
cancelPan();
|
|
83787
83898
|
select(null);
|
|
83788
|
-
|
|
83899
|
+
commitCamera(INITIAL_CAMERA);
|
|
83789
83900
|
}, icon: "Reset" })
|
|
83790
83901
|
] })
|
|
83791
83902
|
] }),
|
|
@@ -83815,7 +83926,6 @@ var import_jsx_runtime417 = require("react/jsx-runtime");
|
|
|
83815
83926
|
var INSPECTOR_WIDTH_DEFAULT = 340;
|
|
83816
83927
|
var INSPECTOR_WIDTH_MIN = 180;
|
|
83817
83928
|
var INSPECTOR_WIDTH_MAX = 480;
|
|
83818
|
-
var INSPECTOR_GAP = 16;
|
|
83819
83929
|
var INSPECTOR_MIN_MAIN_WIDTH_DEFAULT = 360;
|
|
83820
83930
|
function compact2(props) {
|
|
83821
83931
|
return Object.fromEntries(Object.entries(props).filter(([, value]) => value !== void 0));
|
|
@@ -83880,7 +83990,7 @@ function KnowledgeExplorer({
|
|
|
83880
83990
|
const inspectorOpen = inspectorVisible && !loading && !!selectedMemory;
|
|
83881
83991
|
const gridRef = (0, import_react389.useRef)(null);
|
|
83882
83992
|
const width = Math.min(INSPECTOR_WIDTH_MAX, Math.max(INSPECTOR_WIDTH_MIN, inspectorWidth ?? INSPECTOR_WIDTH_DEFAULT));
|
|
83883
|
-
const threshold = inspectorStackBelow ??
|
|
83993
|
+
const threshold = inspectorStackBelow ?? (inspectorMinMainWidth ?? INSPECTOR_MIN_MAIN_WIDTH_DEFAULT);
|
|
83884
83994
|
const [stacked, setStacked] = (0, import_react389.useState)(false);
|
|
83885
83995
|
(0, import_react389.useEffect)(() => {
|
|
83886
83996
|
const el = gridRef.current;
|
|
@@ -84370,27 +84480,33 @@ var MAX_ORBIT_AGENTS = 12;
|
|
|
84370
84480
|
var MAX_FOCUS_AGENTS = 20;
|
|
84371
84481
|
var EXPANDED_RADIUS = 164;
|
|
84372
84482
|
var COLLAPSED_RADIUS = 62;
|
|
84483
|
+
var NARROW_BELOW_DEFAULT = 400;
|
|
84484
|
+
var ZOOM_MIN = 0.25;
|
|
84485
|
+
var ZOOM_MAX = 3;
|
|
84373
84486
|
var INSPECTOR_WIDTH = 280;
|
|
84374
|
-
var
|
|
84487
|
+
var INSPECTOR_GAP = 16;
|
|
84375
84488
|
var INSPECTOR_MIN_MAIN_WIDTH_DEFAULT2 = 360;
|
|
84376
84489
|
var AgentMapSkeleton = ({ projects: count }) => /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("div", { "aria-hidden": "true", className: "cj-agent-map__skeleton animate-pulse motion-reduce:animate-none", children: Array.from({ length: Math.max(1, count) }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("div", { className: "cj-agent-map__skeleton-project", children: [
|
|
84377
84490
|
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)("span", { className: "cj-agent-map__skeleton-hub" }),
|
|
84378
84491
|
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)(SkeletonBar, { width: "4.5rem" }),
|
|
84379
84492
|
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)(SkeletonBar, { width: "3rem", height: "h-2.5" })
|
|
84380
84493
|
] }, i)) });
|
|
84381
|
-
function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null, onExpandedProjectChange, selectedAgentId, defaultSelectedAgentId = null, onAgentSelect, onSelectionClear, renderAgentDetails, ariaLabel = "Agent activity", live = false, scattered = false, grid, panelVariant = "elevated", detailsVariant = "elevated", listVariant = "subtle", panelTone = "none", detailsTone = "none", listTone = "none", gridTone = "blue", glowTone = "blue", emptyProjects, noActiveAgentsMessage, robotVariant = "solid", loading = false, loadingMessage, loaderType = "spinner", loaderProgress, skeletonProjects = 3, inspectorTitle = "Inspector", inspectorMinMainWidth = INSPECTOR_MIN_MAIN_WIDTH_DEFAULT2, inspectorStackBelow, fullHeight = false, fullWidth = true, className, style }) {
|
|
84494
|
+
function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null, onExpandedProjectChange, selectedAgentId, defaultSelectedAgentId = null, onAgentSelect, onSelectionClear, renderAgentDetails, ariaLabel = "Agent activity", live = false, scattered = false, grid, panelVariant = "elevated", detailsVariant = "elevated", listVariant = "subtle", panelTone = "none", detailsTone = "none", listTone = "none", gridTone = "blue", glowTone = "blue", emptyProjects, noActiveAgentsMessage, robotVariant = "solid", loading = false, loadingMessage, loaderType = "spinner", loaderProgress, skeletonProjects = 3, inspectorTitle = "Inspector", inspectorMinMainWidth = INSPECTOR_MIN_MAIN_WIDTH_DEFAULT2, inspectorStackBelow, narrowBelow = NARROW_BELOW_DEFAULT, zoomable = true, fullHeight = false, fullWidth = true, className, style }) {
|
|
84382
84495
|
const [internalExpanded, setInternalExpanded] = (0, import_react392.useState)(defaultExpandedProjectId);
|
|
84383
84496
|
const [internalSelected, setInternalSelected] = (0, import_react392.useState)(defaultSelectedAgentId);
|
|
84384
84497
|
const [width, setWidth] = (0, import_react392.useState)(720);
|
|
84385
84498
|
const [viewportHeight, setViewportHeight] = (0, import_react392.useState)(420);
|
|
84386
84499
|
const [scrollLeft, setScrollLeft] = (0, import_react392.useState)(0);
|
|
84387
84500
|
const [stacked, setStacked] = (0, import_react392.useState)(false);
|
|
84501
|
+
const [zoom, setZoom] = (0, import_react392.useState)(1);
|
|
84502
|
+
const zoomRef = (0, import_react392.useRef)(1);
|
|
84388
84503
|
const rootRef = (0, import_react392.useRef)(null);
|
|
84504
|
+
const panelRef = (0, import_react392.useRef)(null);
|
|
84389
84505
|
const viewportRef = (0, import_react392.useRef)(null);
|
|
84390
84506
|
const orbsViewportRef = (0, import_react392.useRef)(null);
|
|
84391
84507
|
const expanded = expandedProjectId === void 0 ? internalExpanded : expandedProjectId;
|
|
84392
84508
|
const selected = selectedAgentId === void 0 ? internalSelected : selectedAgentId;
|
|
84393
|
-
const narrow = width <
|
|
84509
|
+
const narrow = width < narrowBelow;
|
|
84394
84510
|
(0, import_react392.useEffect)(() => {
|
|
84395
84511
|
const el = viewportRef.current;
|
|
84396
84512
|
if (!el) return;
|
|
@@ -84409,28 +84525,49 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
|
|
|
84409
84525
|
return () => observer.disconnect();
|
|
84410
84526
|
}, [fullHeight, projects]);
|
|
84411
84527
|
(0, import_react392.useEffect)(() => {
|
|
84412
|
-
const
|
|
84413
|
-
if (!
|
|
84414
|
-
const
|
|
84528
|
+
const main = panelRef.current;
|
|
84529
|
+
if (!main) return;
|
|
84530
|
+
const squeeze = fullWidth && !!selected && !stacked ? 0 : fullWidth ? INSPECTOR_WIDTH + INSPECTOR_GAP : 0;
|
|
84531
|
+
const threshold = inspectorStackBelow ?? inspectorMinMainWidth;
|
|
84415
84532
|
const measure = () => {
|
|
84416
|
-
const w =
|
|
84417
|
-
if (w > 0) setStacked(w < threshold);
|
|
84533
|
+
const w = main.getBoundingClientRect().width;
|
|
84534
|
+
if (w > 0) setStacked(w - squeeze < threshold);
|
|
84418
84535
|
};
|
|
84419
84536
|
measure();
|
|
84420
84537
|
if (typeof ResizeObserver === "undefined") return;
|
|
84421
84538
|
const observer = new ResizeObserver(measure);
|
|
84422
|
-
observer.observe(
|
|
84539
|
+
observer.observe(main);
|
|
84423
84540
|
return () => observer.disconnect();
|
|
84424
|
-
}, [inspectorMinMainWidth, inspectorStackBelow]);
|
|
84541
|
+
}, [inspectorMinMainWidth, inspectorStackBelow, fullWidth, selected, stacked, projects.length]);
|
|
84425
84542
|
const expandedProject = projects.find((project) => project.id === expanded);
|
|
84426
84543
|
const focused = !narrow && !!expandedProject && expandedProject.agents.length > MAX_ORBIT_AGENTS && expandedProject.agents.length <= MAX_FOCUS_AGENTS;
|
|
84427
84544
|
const showLargeAgentList = !!expandedProject && expandedProject.agents.length > MAX_FOCUS_AGENTS;
|
|
84428
|
-
const graphHeight = fullHeight && !narrow ? showLargeAgentList ? Math.max(160, Math.floor(viewportHeight * 0.45)) : Math.max(
|
|
84545
|
+
const graphHeight = fullHeight && !narrow ? showLargeAgentList ? Math.max(160, Math.floor(viewportHeight * 0.45)) : Math.max(160, viewportHeight) : 420;
|
|
84429
84546
|
const layout = (0, import_react392.useMemo)(() => {
|
|
84430
84547
|
const items = projects.map((p) => ({ id: p.id, radius: p.id === expanded && p.agents.length <= MAX_ORBIT_AGENTS ? EXPANDED_RADIUS : COLLAPSED_RADIUS }));
|
|
84431
84548
|
return scattered && !narrow ? scatterProjects(items, width, graphHeight, 18) : { ...layoutProjectsHorizontally(items, graphHeight, 18, scattered), scale: 1 };
|
|
84432
84549
|
}, [projects, expanded, graphHeight, scattered, narrow, width]);
|
|
84433
|
-
const canvasWidth = Math.max(width, layout.width, focused ? scrollLeft + width : 0);
|
|
84550
|
+
const canvasWidth = Math.max(width, layout.width, focused ? (scrollLeft + width) / zoom : 0);
|
|
84551
|
+
function zoomTo(next) {
|
|
84552
|
+
const clamped = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, Math.round(next * 1e3) / 1e3));
|
|
84553
|
+
const z = zoomRef.current;
|
|
84554
|
+
if (clamped === z) return;
|
|
84555
|
+
const vp = orbsViewportRef.current;
|
|
84556
|
+
const half = (vp?.clientWidth ?? 0) / 2;
|
|
84557
|
+
const world = (vp ? vp.scrollLeft + half : 0) / z;
|
|
84558
|
+
zoomRef.current = clamped;
|
|
84559
|
+
setZoom(clamped);
|
|
84560
|
+
if (vp) requestAnimationFrame(() => {
|
|
84561
|
+
vp.scrollLeft = Math.max(0, world * clamped - half);
|
|
84562
|
+
});
|
|
84563
|
+
}
|
|
84564
|
+
function zoomBy(factor) {
|
|
84565
|
+
zoomTo(zoomRef.current * factor);
|
|
84566
|
+
}
|
|
84567
|
+
function fitToView() {
|
|
84568
|
+
const vp = orbsViewportRef.current;
|
|
84569
|
+
zoomTo(canvasWidth > 0 ? (vp?.clientWidth || width) / canvasWidth : 1);
|
|
84570
|
+
}
|
|
84434
84571
|
(0, import_react392.useEffect)(() => {
|
|
84435
84572
|
const viewport = orbsViewportRef.current;
|
|
84436
84573
|
if (!viewport) return;
|
|
@@ -84442,21 +84579,92 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
|
|
|
84442
84579
|
const selection = projects.flatMap((project) => project.agents.map((agent) => ({ project, agent }))).find((item) => item.agent.id === selected);
|
|
84443
84580
|
(0, import_react392.useEffect)(() => {
|
|
84444
84581
|
if (!selection) return;
|
|
84582
|
+
let origin = null;
|
|
84445
84583
|
const handlePointerDown = (event) => {
|
|
84584
|
+
origin = { x: event.clientX, y: event.clientY };
|
|
84585
|
+
};
|
|
84586
|
+
const handlePointerUp = (event) => {
|
|
84587
|
+
const start = origin;
|
|
84588
|
+
origin = null;
|
|
84589
|
+
if (!start || Math.hypot(event.clientX - start.x, event.clientY - start.y) > 4) return;
|
|
84446
84590
|
const target = event.target;
|
|
84447
84591
|
if (!(target instanceof Element)) return;
|
|
84448
84592
|
const root = rootRef.current;
|
|
84449
|
-
if (root?.contains(target) && (target.closest(".cj-agent-map__inspector") || target.closest(".cj-agent-map__agent, .cj-agent-map__list-agent, .cj-agent-map__hub, .cj-agent-map__list-project"))) return;
|
|
84593
|
+
if (root?.contains(target) && (target.closest(".cj-agent-map__inspector") || target.closest(".cj-agent-map__agent, .cj-agent-map__list-agent, .cj-agent-map__hub, .cj-agent-map__list-project, .cj-agent-map__zoom") || target.closest('[data-slot="scrollarea-scrollbar"]'))) return;
|
|
84450
84594
|
if (selectedAgentId === void 0) setInternalSelected(null);
|
|
84451
84595
|
onSelectionClear?.();
|
|
84452
84596
|
};
|
|
84597
|
+
const handlePointerCancel = () => {
|
|
84598
|
+
origin = null;
|
|
84599
|
+
};
|
|
84453
84600
|
document.addEventListener("pointerdown", handlePointerDown);
|
|
84454
|
-
|
|
84601
|
+
document.addEventListener("pointerup", handlePointerUp);
|
|
84602
|
+
document.addEventListener("pointercancel", handlePointerCancel);
|
|
84603
|
+
return () => {
|
|
84604
|
+
document.removeEventListener("pointerdown", handlePointerDown);
|
|
84605
|
+
document.removeEventListener("pointerup", handlePointerUp);
|
|
84606
|
+
document.removeEventListener("pointercancel", handlePointerCancel);
|
|
84607
|
+
};
|
|
84455
84608
|
}, [selection, selectedAgentId, onSelectionClear]);
|
|
84456
84609
|
const agents = projects.flatMap((project) => project.agents);
|
|
84457
84610
|
const activeCount = agents.filter((agent) => agent.status === "working").length;
|
|
84458
84611
|
const attentionCount = agents.filter((agent) => agent.status === "attention").length;
|
|
84459
84612
|
const showSkeleton = loading && loaderType === "skeleton";
|
|
84613
|
+
const pan = (0, import_react392.useRef)(null);
|
|
84614
|
+
const suppressPanClick = (0, import_react392.useRef)(false);
|
|
84615
|
+
const [panning, setPanning] = (0, import_react392.useState)(false);
|
|
84616
|
+
const [pannable, setPannable] = (0, import_react392.useState)(false);
|
|
84617
|
+
(0, import_react392.useEffect)(() => {
|
|
84618
|
+
const vp = orbsViewportRef.current;
|
|
84619
|
+
if (!vp) {
|
|
84620
|
+
setPannable(false);
|
|
84621
|
+
return;
|
|
84622
|
+
}
|
|
84623
|
+
const check = () => setPannable(vp.scrollWidth > vp.clientWidth + 1 || vp.scrollHeight > vp.clientHeight + 1);
|
|
84624
|
+
check();
|
|
84625
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
84626
|
+
const observer = new ResizeObserver(check);
|
|
84627
|
+
observer.observe(vp);
|
|
84628
|
+
const frame = vp.querySelector(".cj-agent-map__canvas-frame");
|
|
84629
|
+
if (frame) observer.observe(frame);
|
|
84630
|
+
return () => observer.disconnect();
|
|
84631
|
+
}, [width, zoom, graphHeight, canvasWidth, focused, narrow, loading, showSkeleton, projects.length]);
|
|
84632
|
+
function beginPan(event) {
|
|
84633
|
+
if (event.button !== 0 || event.pointerType === "touch" || pan.current) return;
|
|
84634
|
+
const vp = orbsViewportRef.current;
|
|
84635
|
+
if (!vp || vp.scrollWidth <= vp.clientWidth + 1 && vp.scrollHeight <= vp.clientHeight + 1) return;
|
|
84636
|
+
pan.current = { id: event.pointerId, x: event.clientX, y: event.clientY, originX: event.clientX, originY: event.clientY, left: vp.scrollLeft, top: vp.scrollTop, moved: false };
|
|
84637
|
+
}
|
|
84638
|
+
function movePan(event) {
|
|
84639
|
+
const p = pan.current;
|
|
84640
|
+
const vp = orbsViewportRef.current;
|
|
84641
|
+
if (!p || p.id !== event.pointerId || !vp) return;
|
|
84642
|
+
p.moved || (p.moved = Math.hypot(event.clientX - p.originX, event.clientY - p.originY) > 4);
|
|
84643
|
+
if (!p.moved) return;
|
|
84644
|
+
setPanning(true);
|
|
84645
|
+
const frame = event.currentTarget;
|
|
84646
|
+
if (!frame.hasPointerCapture?.(event.pointerId)) frame.setPointerCapture?.(event.pointerId);
|
|
84647
|
+
vp.scrollLeft = p.left - (event.clientX - p.originX);
|
|
84648
|
+
vp.scrollTop = p.top - (event.clientY - p.originY);
|
|
84649
|
+
}
|
|
84650
|
+
function endPan(event) {
|
|
84651
|
+
const p = pan.current;
|
|
84652
|
+
if (!p || p.id !== event.pointerId) return;
|
|
84653
|
+
pan.current = null;
|
|
84654
|
+
setPanning(false);
|
|
84655
|
+
if (p.moved) suppressPanClick.current = true;
|
|
84656
|
+
}
|
|
84657
|
+
(0, import_react392.useEffect)(() => {
|
|
84658
|
+
const el = orbsViewportRef.current;
|
|
84659
|
+
if (!el || !zoomable || narrow || loading || showSkeleton || projects.length === 0) return;
|
|
84660
|
+
const onWheel = (event) => {
|
|
84661
|
+
if (!(event.ctrlKey || event.metaKey)) return;
|
|
84662
|
+
event.preventDefault();
|
|
84663
|
+
zoomBy(event.deltaY < 0 ? 1.12 : 1 / 1.12);
|
|
84664
|
+
};
|
|
84665
|
+
el.addEventListener("wheel", onWheel, { passive: false });
|
|
84666
|
+
return () => el.removeEventListener("wheel", onWheel);
|
|
84667
|
+
}, [zoomable, narrow, loading, showSkeleton, projects.length]);
|
|
84460
84668
|
function toggle(project) {
|
|
84461
84669
|
const next = expanded === project.id ? null : project.id;
|
|
84462
84670
|
if (selection) {
|
|
@@ -84500,7 +84708,7 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
|
|
|
84500
84708
|
}
|
|
84501
84709
|
const inactiveMessage = noActiveAgentsMessage === void 0 ? agents.length === 0 ? "No agents are assigned to these projects yet." : "No agents are currently working." : noActiveAgentsMessage;
|
|
84502
84710
|
return /* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("div", { ref: rootRef, className: ["cj-agent-map", (stacked || projects.length === 0) && "cj-agent-map--stacked", selection && "cj-agent-map--inspector-open", fullHeight && "cj-agent-map--full-height", fullWidth ? "cj-agent-map--full-width" : "cj-agent-map--intrinsic-width", className].filter(Boolean).join(" "), style, children: [
|
|
84503
|
-
/* @__PURE__ */ (0, import_jsx_runtime421.jsxs)(Panel_default, { variant: panelVariant, tone: panelTone, padding: "none", scrollable: false, flexBody: true, className: "cj-agent-map__panel", children: [
|
|
84711
|
+
/* @__PURE__ */ (0, import_jsx_runtime421.jsxs)(Panel_default, { ref: panelRef, variant: panelVariant, tone: panelTone, padding: "none", scrollable: false, flexBody: true, className: "cj-agent-map__panel", children: [
|
|
84504
84712
|
/* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("div", { className: "cj-agent-map__header", children: [
|
|
84505
84713
|
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)("strong", { children: ariaLabel }),
|
|
84506
84714
|
live && /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("span", { className: "cj-agent-map__live", children: "\u25CF Live" }),
|
|
@@ -84549,7 +84757,13 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
|
|
|
84549
84757
|
expanded === project.id && agentList(project)
|
|
84550
84758
|
] }, project.id);
|
|
84551
84759
|
}) })
|
|
84552
|
-
] }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime421.jsx)(ScrollArea, { vertical:
|
|
84760
|
+
] }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime421.jsx)(ScrollArea, { vertical: zoom > 1, variant: "auto", className: "cj-agent-map__orbs-scroll", contentClassName: "cj-agent-map__orbs-content", viewportRef: orbsViewportRef, "aria-label": "Project map", style: { height: graphHeight }, children: /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("div", { className: `cj-agent-map__canvas-frame${panning ? " cursor-grabbing" : pannable ? " cursor-grab" : ""}`, style: { width: Math.round(canvasWidth * zoom), height: Math.round(graphHeight * zoom), userSelect: panning ? "none" : void 0 }, onPointerDown: beginPan, onPointerMove: movePan, onPointerUp: endPan, onPointerCancel: endPan, onClickCapture: (event) => {
|
|
84761
|
+
if (suppressPanClick.current) {
|
|
84762
|
+
suppressPanClick.current = false;
|
|
84763
|
+
event.preventDefault();
|
|
84764
|
+
event.stopPropagation();
|
|
84765
|
+
}
|
|
84766
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("div", { className: "cj-agent-map__canvas", style: { width: canvasWidth, height: graphHeight, transform: `scale(${zoom})`, transformOrigin: "0 0" }, children: [
|
|
84553
84767
|
projects.map((project, i) => {
|
|
84554
84768
|
const pos = layout.circles[i];
|
|
84555
84769
|
const open = expanded === project.id;
|
|
@@ -84560,7 +84774,7 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
|
|
|
84560
84774
|
const scale = focused ? 0.7 : project.agents.length > 8 ? Math.max(0.72, 8 / project.agents.length) : 1;
|
|
84561
84775
|
const hubScale = open ? scale : layout.scale;
|
|
84562
84776
|
const color2 = attention ? COLORS2.attention : completed === project.agents.length && completed > 0 ? COLORS2.completed : COLORS2.working;
|
|
84563
|
-
return /* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("div", { className: ["cj-agent-map__project", focused && !open && "cj-agent-map__project--background", focused && open && "cj-agent-map__project--focused"].filter(Boolean).join(" "), style: { left: focused && open ? scrollLeft + width / 2 : pos.x, top: focused && open ? graphHeight / 2 : pos.y, ...open ? {} : { "--overflow-offset": `${58 * layout.scale}px` } }, "aria-hidden": focused && !open ? true : void 0, children: [
|
|
84777
|
+
return /* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("div", { className: ["cj-agent-map__project", focused && !open && "cj-agent-map__project--background", focused && open && "cj-agent-map__project--focused"].filter(Boolean).join(" "), style: { left: focused && open ? (scrollLeft + width / 2) / zoom : pos.x, top: focused && open ? graphHeight / 2 : pos.y, ...open ? {} : { "--overflow-offset": `${58 * layout.scale}px` } }, "aria-hidden": focused && !open ? true : void 0, children: [
|
|
84564
84778
|
orbit && /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("svg", { className: "cj-agent-map__lines", "aria-hidden": "true", viewBox: "-164 -164 328 328", children: project.agents.map((agent, j) => /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("line", { x1: "0", y1: "0", x2: points[j].x, y2: points[j].y, stroke: COLORS2[agent.status] }, agent.id)) }),
|
|
84565
84779
|
/* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("button", { type: "button", className: ["cj-agent-map__hub", attention && "cj-agent-map__hub--attention"].filter(Boolean).join(" "), style: { "--agent-color": color2, "--hub-scale": hubScale }, disabled: focused && !open, title: project.name, "aria-expanded": open, "aria-label": `${project.name}, ${project.agents.length} agents${attention ? `, ${attention} need attention` : ""}`, onClick: () => toggle(project), children: [
|
|
84566
84780
|
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)("strong", { children: project.name }),
|
|
@@ -84578,8 +84792,22 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
|
|
|
84578
84792
|
open && !orbit && /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("span", { className: "cj-agent-map__overflow", children: "See agents below" })
|
|
84579
84793
|
] }, project.id);
|
|
84580
84794
|
}),
|
|
84581
|
-
focused && expandedProject && /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("button", { type: "button", className: "cj-agent-map__exit-focus", style: { left: scrollLeft + 14 }, onClick: () => toggle(expandedProject), children: "\u2190 All projects" })
|
|
84582
|
-
] }) }),
|
|
84795
|
+
focused && expandedProject && /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("button", { type: "button", className: "cj-agent-map__exit-focus", style: { left: (scrollLeft + 14) / zoom }, onClick: () => toggle(expandedProject), children: "\u2190 All projects" })
|
|
84796
|
+
] }) }) }),
|
|
84797
|
+
zoomable && !narrow && !loading && !showSkeleton && projects.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("div", { className: "cj-agent-map__zoom absolute bottom-3 right-3 z-10 flex items-center gap-0.5 rounded-lg border border-neutral-200 bg-white/90 p-1 shadow-sm backdrop-blur dark:border-neutral-700 dark:bg-neutral-900/90", role: "group", "aria-label": "Map zoom controls", children: [
|
|
84798
|
+
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)(IconButton_default, { icon: /* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
84799
|
+
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)("path", { d: "M4 9V5a1 1 0 0 1 1-1h4" }),
|
|
84800
|
+
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)("path", { d: "M15 4h4a1 1 0 0 1 1 1v4" }),
|
|
84801
|
+
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)("path", { d: "M20 15v4a1 1 0 0 1-1 1h-4" }),
|
|
84802
|
+
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)("path", { d: "M9 20H5a1 1 0 0 1-1-1v-4" })
|
|
84803
|
+
] }), size: "xs", variant: "ghost", color: "slate", srLabel: "Fit map to view", tooltip: "Fit map to view", onClick: fitToView }),
|
|
84804
|
+
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)(IconButton_default, { icon: /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("path", { d: "M6 12h12" }) }), size: "xs", variant: "ghost", color: "slate", disabled: zoom <= ZOOM_MIN, srLabel: "Zoom out", tooltip: "Zoom out", onClick: () => zoomBy(0.8) }),
|
|
84805
|
+
/* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("span", { className: "min-w-[3.5ch] px-1 text-center text-[11px] tabular-nums text-neutral-500 dark:text-neutral-400", "aria-label": "Zoom level", children: [
|
|
84806
|
+
Math.round(zoom * 100),
|
|
84807
|
+
"%"
|
|
84808
|
+
] }),
|
|
84809
|
+
/* @__PURE__ */ (0, import_jsx_runtime421.jsx)(IconButton_default, { icon: "Add", size: "xs", variant: "ghost", color: "slate", disabled: zoom >= ZOOM_MAX, srLabel: "Zoom in", tooltip: "Zoom in", onClick: () => zoomBy(1.25) })
|
|
84810
|
+
] }),
|
|
84583
84811
|
!loading && !narrow && expandedProject && expandedProject.agents.length > MAX_FOCUS_AGENTS && /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("div", { className: "cj-agent-map__list", children: agentList(expandedProject) })
|
|
84584
84812
|
] }),
|
|
84585
84813
|
!loading && projects.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime421.jsx)("div", { className: "cj-agent-map__legend", children: Object.keys(LABELS).map((status) => /* @__PURE__ */ (0, import_jsx_runtime421.jsxs)("span", { children: [
|
|
@@ -85669,14 +85897,93 @@ function useNetworkCanvas(options) {
|
|
|
85669
85897
|
draw();
|
|
85670
85898
|
});
|
|
85671
85899
|
}, [draw]);
|
|
85900
|
+
const panFrame = (0, import_react394.useRef)(null);
|
|
85901
|
+
const cancelPan = (0, import_react394.useCallback)(() => {
|
|
85902
|
+
if (panFrame.current !== null) {
|
|
85903
|
+
cancelAnimationFrame(panFrame.current);
|
|
85904
|
+
panFrame.current = null;
|
|
85905
|
+
}
|
|
85906
|
+
}, []);
|
|
85672
85907
|
const update = (0, import_react394.useCallback)(
|
|
85673
85908
|
(next) => {
|
|
85909
|
+
cancelPan();
|
|
85674
85910
|
view.current = next;
|
|
85675
85911
|
setZoom(next.zoom);
|
|
85676
85912
|
requestDraw();
|
|
85677
85913
|
latest.current.onViewportChange?.({ ...next });
|
|
85678
85914
|
},
|
|
85679
|
-
[requestDraw]
|
|
85915
|
+
[requestDraw, cancelPan]
|
|
85916
|
+
);
|
|
85917
|
+
const animateView = (0, import_react394.useCallback)(
|
|
85918
|
+
(target, onDone) => {
|
|
85919
|
+
cancelPan();
|
|
85920
|
+
const from = { ...view.current };
|
|
85921
|
+
if (from.x === target.x && from.y === target.y && from.zoom === target.zoom) {
|
|
85922
|
+
onDone?.();
|
|
85923
|
+
return;
|
|
85924
|
+
}
|
|
85925
|
+
const commit = (v) => {
|
|
85926
|
+
view.current = v;
|
|
85927
|
+
setZoom(v.zoom);
|
|
85928
|
+
requestDraw();
|
|
85929
|
+
latest.current.onViewportChange?.({ ...v });
|
|
85930
|
+
};
|
|
85931
|
+
if (typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
85932
|
+
commit(target);
|
|
85933
|
+
onDone?.();
|
|
85934
|
+
return;
|
|
85935
|
+
}
|
|
85936
|
+
const start = Date.now();
|
|
85937
|
+
const step = () => {
|
|
85938
|
+
panFrame.current = requestAnimationFrame(() => {
|
|
85939
|
+
const t = Math.min(1, (Date.now() - start) / 300);
|
|
85940
|
+
const e = 1 - Math.pow(1 - t, 3);
|
|
85941
|
+
commit({
|
|
85942
|
+
x: from.x + (target.x - from.x) * e,
|
|
85943
|
+
y: from.y + (target.y - from.y) * e,
|
|
85944
|
+
zoom: from.zoom + (target.zoom - from.zoom) * e
|
|
85945
|
+
});
|
|
85946
|
+
if (t < 1) step();
|
|
85947
|
+
else {
|
|
85948
|
+
panFrame.current = null;
|
|
85949
|
+
onDone?.();
|
|
85950
|
+
}
|
|
85951
|
+
});
|
|
85952
|
+
};
|
|
85953
|
+
step();
|
|
85954
|
+
},
|
|
85955
|
+
[cancelPan, requestDraw]
|
|
85956
|
+
);
|
|
85957
|
+
const revealNode = (0, import_react394.useCallback)(
|
|
85958
|
+
(node, center = false) => {
|
|
85959
|
+
const v = view.current;
|
|
85960
|
+
const { width, height } = size.current;
|
|
85961
|
+
if (center) {
|
|
85962
|
+
animateView({
|
|
85963
|
+
...v,
|
|
85964
|
+
x: width / 2 - node.x * v.zoom,
|
|
85965
|
+
y: height / 2 - node.y * v.zoom
|
|
85966
|
+
});
|
|
85967
|
+
return;
|
|
85968
|
+
}
|
|
85969
|
+
const margin = 8 + Math.max(node.radius, 1.5 / v.zoom) * v.zoom;
|
|
85970
|
+
const sx = node.x * v.zoom + v.x, sy = node.y * v.zoom + v.y;
|
|
85971
|
+
let dx = 0, dy = 0;
|
|
85972
|
+
if (sx < margin) dx = margin - sx;
|
|
85973
|
+
else if (sx > width - margin) dx = width - margin - sx;
|
|
85974
|
+
if (sy < margin) dy = margin - sy;
|
|
85975
|
+
else if (sy > height - margin) dy = height - margin - sy;
|
|
85976
|
+
if (dx === 0 && dy === 0) return;
|
|
85977
|
+
animateView({ ...v, x: v.x + dx, y: v.y + dy });
|
|
85978
|
+
},
|
|
85979
|
+
[animateView]
|
|
85980
|
+
);
|
|
85981
|
+
const animateFit = (0, import_react394.useCallback)(
|
|
85982
|
+
(onDone) => animateView(
|
|
85983
|
+
fitNetwork(latest.current.nodes, size.current.width, size.current.height),
|
|
85984
|
+
onDone
|
|
85985
|
+
),
|
|
85986
|
+
[animateView]
|
|
85680
85987
|
);
|
|
85681
85988
|
const fit = (0, import_react394.useCallback)(
|
|
85682
85989
|
() => update(
|
|
@@ -85755,17 +86062,27 @@ function useNetworkCanvas(options) {
|
|
|
85755
86062
|
theme.disconnect();
|
|
85756
86063
|
window.removeEventListener("resize", measure);
|
|
85757
86064
|
if (frame.current !== null) cancelAnimationFrame(frame.current);
|
|
86065
|
+
if (panFrame.current !== null) cancelAnimationFrame(panFrame.current);
|
|
85758
86066
|
frame.current = null;
|
|
85759
86067
|
};
|
|
85760
86068
|
}, [fit, update, requestDraw, options.active]);
|
|
85761
|
-
return {
|
|
86069
|
+
return {
|
|
86070
|
+
canvasRef,
|
|
86071
|
+
view,
|
|
86072
|
+
zoom,
|
|
86073
|
+
update,
|
|
86074
|
+
fit,
|
|
86075
|
+
zoomBy,
|
|
86076
|
+
focusNode,
|
|
86077
|
+
revealNode,
|
|
86078
|
+
animateFit
|
|
86079
|
+
};
|
|
85762
86080
|
}
|
|
85763
86081
|
|
|
85764
86082
|
// src/components/NetworkGraph/NetworkGraph.tsx
|
|
85765
86083
|
var import_jsx_runtime424 = require("react/jsx-runtime");
|
|
85766
86084
|
var NO_COMMUNITIES = [];
|
|
85767
86085
|
var NO_HIGHLIGHTS = [];
|
|
85768
|
-
var INSPECTOR_GAP3 = 16;
|
|
85769
86086
|
var INSPECTOR_WIDTH_DEFAULT2 = 280;
|
|
85770
86087
|
var INSPECTOR_WIDTH_MIN2 = 180;
|
|
85771
86088
|
var INSPECTOR_WIDTH_MAX2 = 480;
|
|
@@ -85809,6 +86126,9 @@ function NetworkGraph({
|
|
|
85809
86126
|
hoverHighlight = true,
|
|
85810
86127
|
fullHeight = false,
|
|
85811
86128
|
fullWidth = true,
|
|
86129
|
+
autoRevealSelected = true,
|
|
86130
|
+
autoCenterSelected = true,
|
|
86131
|
+
autoFitOnInspector = false,
|
|
85812
86132
|
ariaLabel,
|
|
85813
86133
|
emptyMessage,
|
|
85814
86134
|
onViewportChange,
|
|
@@ -85839,13 +86159,13 @@ function NetworkGraph({
|
|
|
85839
86159
|
(0, import_react395.useEffect)(() => {
|
|
85840
86160
|
const element = rootRef.current;
|
|
85841
86161
|
if (!element || !inspector) return;
|
|
85842
|
-
const threshold = inspectorStackBelow ??
|
|
86162
|
+
const threshold = inspectorStackBelow ?? inspectorMinMainWidth;
|
|
85843
86163
|
const measure = () => setInspectorStacked(element.getBoundingClientRect().width < threshold);
|
|
85844
86164
|
measure();
|
|
85845
86165
|
const observer = new ResizeObserver(measure);
|
|
85846
86166
|
observer.observe(element);
|
|
85847
86167
|
return () => observer.disconnect();
|
|
85848
|
-
}, [inspector,
|
|
86168
|
+
}, [inspector, inspectorMinMainWidth, inspectorStackBelow]);
|
|
85849
86169
|
const model = (0, import_react395.useMemo)(
|
|
85850
86170
|
() => buildNetwork(nodes, edges, communities),
|
|
85851
86171
|
[nodes, edges, communities]
|
|
@@ -85920,6 +86240,37 @@ function NetworkGraph({
|
|
|
85920
86240
|
onViewportChange
|
|
85921
86241
|
});
|
|
85922
86242
|
const locked = disabled || loading;
|
|
86243
|
+
const { revealNode, animateFit } = canvas;
|
|
86244
|
+
const inspectorOpen = !!inspector && selected !== null;
|
|
86245
|
+
const inspectorWasOpen = (0, import_react395.useRef)(false);
|
|
86246
|
+
(0, import_react395.useEffect)(() => {
|
|
86247
|
+
const opening = inspectorOpen && !inspectorWasOpen.current;
|
|
86248
|
+
inspectorWasOpen.current = inspectorOpen;
|
|
86249
|
+
if (!inspectorOpen || locked) return;
|
|
86250
|
+
if (!autoRevealSelected && !autoFitOnInspector) return;
|
|
86251
|
+
const positioned = selected !== null ? model.byId.get(selected) : void 0;
|
|
86252
|
+
const reduced = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
86253
|
+
const timer = setTimeout(() => {
|
|
86254
|
+
if (opening && autoFitOnInspector)
|
|
86255
|
+
animateFit(() => {
|
|
86256
|
+
if (positioned && autoRevealSelected)
|
|
86257
|
+
revealNode(positioned, autoCenterSelected);
|
|
86258
|
+
});
|
|
86259
|
+
else if (positioned && autoRevealSelected)
|
|
86260
|
+
revealNode(positioned, autoCenterSelected);
|
|
86261
|
+
}, reduced ? 0 : 260);
|
|
86262
|
+
return () => clearTimeout(timer);
|
|
86263
|
+
}, [
|
|
86264
|
+
inspectorOpen,
|
|
86265
|
+
selected,
|
|
86266
|
+
locked,
|
|
86267
|
+
autoRevealSelected,
|
|
86268
|
+
autoCenterSelected,
|
|
86269
|
+
autoFitOnInspector,
|
|
86270
|
+
model,
|
|
86271
|
+
revealNode,
|
|
86272
|
+
animateFit
|
|
86273
|
+
]);
|
|
85923
86274
|
const drag = (0, import_react395.useRef)(null);
|
|
85924
86275
|
const select = (id) => {
|
|
85925
86276
|
if (locked) return;
|