@cjlapao/ui-kit 0.2.42 → 0.2.43

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 CHANGED
@@ -48650,7 +48650,8 @@ var SideMenu = ({
48650
48650
  search = false,
48651
48651
  searchValue,
48652
48652
  onSearchChange,
48653
- searchPlaceholder
48653
+ searchPlaceholder,
48654
+ searchScope = "all"
48654
48655
  }) => {
48655
48656
  const t = useKitT();
48656
48657
  const location = useLocation();
@@ -48796,6 +48797,8 @@ var SideMenu = ({
48796
48797
  const query = searchQuery.trim().toLowerCase();
48797
48798
  const matchesItem = (item) => !query || item.label.toLowerCase().includes(query) || (item.description ?? "").toLowerCase().includes(query);
48798
48799
  const matchesSubtree = (item) => matchesItem(item) || (item.children ?? []).some(matchesSubtree);
48800
+ const searchTopOnly = searchScope === "top";
48801
+ const matchesScope = (item) => searchTopOnly ? matchesItem(item) : matchesSubtree(item);
48799
48802
  const passesGuard = useCallback33(
48800
48803
  (item) => {
48801
48804
  if (item.hidden) return false;
@@ -48823,13 +48826,13 @@ var SideMenu = ({
48823
48826
  const visibleItems2 = useMemo32(() => {
48824
48827
  const groupsWithVisibleLinks = /* @__PURE__ */ new Set();
48825
48828
  items.forEach((item) => {
48826
- if (item.type !== "group" && item.type !== "divider" && passesGuard(item) && matchesSubtree(item)) {
48829
+ if (item.type !== "group" && item.type !== "divider" && passesGuard(item) && matchesScope(item)) {
48827
48830
  if (item.groupName) groupsWithVisibleLinks.add(item.groupName);
48828
48831
  }
48829
48832
  });
48830
48833
  return items.filter((item) => {
48831
48834
  if (!passesGuard(item)) return false;
48832
- if (item.type !== "group" && item.type !== "divider" && !matchesSubtree(item)) {
48835
+ if (item.type !== "group" && item.type !== "divider" && !matchesScope(item)) {
48833
48836
  return false;
48834
48837
  }
48835
48838
  if (item.type === "group") return groupsWithVisibleLinks.has(item.slug);
@@ -48837,7 +48840,7 @@ var SideMenu = ({
48837
48840
  return !item.groupName || groupsWithVisibleLinks.has(item.groupName);
48838
48841
  return true;
48839
48842
  });
48840
- }, [items, passesGuard, query]);
48843
+ }, [items, passesGuard, query, searchTopOnly]);
48841
48844
  const visibleCtas = useMemo32(
48842
48845
  () => ctas ? ctas.filter(passesGuard) : [],
48843
48846
  [ctas, passesGuard]
@@ -48894,7 +48897,7 @@ var SideMenu = ({
48894
48897
  const hasChildren = !!link.children?.length;
48895
48898
  const selfActive = isActiveItem(link);
48896
48899
  const childActive = hasChildren ? hasActiveDescendant(link) : false;
48897
- const visibleChildren = searchActive ? (link.children ?? []).filter(matchesSubtree) : link.children ?? [];
48900
+ const visibleChildren = searchActive && !searchTopOnly ? (link.children ?? []).filter(matchesSubtree) : link.children ?? [];
48898
48901
  const showChildren = hasChildren && (searchActive || openSubmenus.has(link.slug)) && visibleChildren.length > 0;
48899
48902
  const pageSize = link.childrenPageSize;
48900
48903
  const paged = !searchActive && pageSize !== void 0 && pageSize > 0;
@@ -82428,6 +82431,98 @@ function layoutProjectsHorizontally(items, height, gap = 18, scattered = false)
82428
82431
  const layout = layoutProjects(items, height, gap, scattered);
82429
82432
  return { circles: layout.circles.map((circle) => ({ ...circle, x: circle.y, y: circle.x })), width: layout.height };
82430
82433
  }
82434
+ var SCATTER_MIN_SCALE = 0.7;
82435
+ var SCATTER_SCALE_STEP = 0.05;
82436
+ var SCATTER_JITTER = 0.4;
82437
+ var SCATTER_WIDTH_STEPS = 3;
82438
+ function hashId(id) {
82439
+ let hash2 = 2166136261;
82440
+ for (const char of id) hash2 = Math.imul(hash2 ^ char.charCodeAt(0), 16777619);
82441
+ return hash2 >>> 0;
82442
+ }
82443
+ function seedGrid(items, width, height, gap, scale, base) {
82444
+ const count = items.length;
82445
+ let columns = 1, bestDelta = Infinity;
82446
+ for (let candidate = 1; candidate <= count; candidate++) {
82447
+ const rows2 = Math.ceil(count / candidate);
82448
+ const delta = Math.abs(width / candidate - height / rows2);
82449
+ if (delta < bestDelta) {
82450
+ bestDelta = delta;
82451
+ columns = candidate;
82452
+ }
82453
+ }
82454
+ const rows = Math.ceil(count / columns);
82455
+ const circles = [];
82456
+ for (let row = 0; row < rows; row++) {
82457
+ const rowStart = Math.floor(row * count / rows), rowEnd = Math.floor((row + 1) * count / rows);
82458
+ const rowCount = rowEnd - rowStart;
82459
+ if (rowCount <= 0) continue;
82460
+ const cellWidth = width / rowCount, cellHeight = height / rows;
82461
+ for (let column = 0; column < rowCount; column++) {
82462
+ const item = items[rowStart + column];
82463
+ const radius = item.radius > base ? item.radius : item.radius * scale;
82464
+ const hash2 = hashId(item.id);
82465
+ const jitterX = (hash2 % 89 / 89 - 0.5) * SCATTER_JITTER * cellWidth;
82466
+ const jitterY = ((hash2 >>> 8 >>> 0) % 89 / 89 - 0.5) * SCATTER_JITTER * cellHeight;
82467
+ const loX = radius + gap, hiX = width - radius - gap, loY = radius + gap, hiY = height - radius - gap;
82468
+ const x = (column + 0.5) * cellWidth + jitterX, y = (row + 0.5) * cellHeight + jitterY;
82469
+ circles.push({ id: item.id, radius, x: loX > hiX ? width / 2 : Math.min(hiX, Math.max(loX, x)), y: loY > hiY ? height / 2 : Math.min(hiY, Math.max(loY, y)) });
82470
+ }
82471
+ }
82472
+ return circles;
82473
+ }
82474
+ function relaxInside(circles, width, height, gap) {
82475
+ let maxOverlap = Infinity;
82476
+ for (let step = 0; step < 400 && maxOverlap >= 0.05; step++) {
82477
+ maxOverlap = 0;
82478
+ for (let i = 0; i < circles.length; i++) {
82479
+ const a = circles[i];
82480
+ for (let j = i + 1; j < circles.length; j++) {
82481
+ const b = circles[j];
82482
+ let dx = b.x - a.x;
82483
+ let dy = b.y - a.y;
82484
+ let distance = Math.hypot(dx, dy);
82485
+ if (distance < 1e-3) {
82486
+ dx = 1;
82487
+ dy = 0;
82488
+ distance = 1;
82489
+ }
82490
+ const overlap = a.radius + b.radius + gap - distance;
82491
+ if (overlap > 0) {
82492
+ maxOverlap = Math.max(maxOverlap, overlap);
82493
+ const shift = overlap / 2;
82494
+ const ux = dx / distance;
82495
+ const uy = dy / distance;
82496
+ a.x -= ux * shift;
82497
+ a.y -= uy * shift;
82498
+ b.x += ux * shift;
82499
+ b.y += uy * shift;
82500
+ }
82501
+ }
82502
+ }
82503
+ for (const circle of circles) {
82504
+ circle.x = Math.max(circle.radius + gap, Math.min(width - circle.radius - gap, circle.x));
82505
+ circle.y = Math.max(circle.radius + gap, Math.min(height - circle.radius - gap, circle.y));
82506
+ }
82507
+ }
82508
+ return maxOverlap < 0.05;
82509
+ }
82510
+ function scatterProjects(items, width, height, gap = 18) {
82511
+ const safeWidth = Math.max(1, width), safeHeight = Math.max(1, height);
82512
+ if (items.length === 0) return { circles: [], width: safeWidth, scale: 1 };
82513
+ const base = Math.min(...items.map((item) => item.radius));
82514
+ for (let stretch = 0; stretch <= SCATTER_WIDTH_STEPS; stretch++) {
82515
+ const boxWidth = safeWidth * (1 + stretch * 0.5);
82516
+ for (let level = 0; ; level++) {
82517
+ const scale = Math.max(SCATTER_MIN_SCALE, 1 - level * SCATTER_SCALE_STEP);
82518
+ const circles = seedGrid(items, boxWidth, safeHeight, gap, scale, base);
82519
+ if (relaxInside(circles, boxWidth, safeHeight, gap)) return { circles, width: boxWidth, scale };
82520
+ if (scale === SCATTER_MIN_SCALE) break;
82521
+ }
82522
+ }
82523
+ const packed = packProjects(items, safeHeight, gap);
82524
+ return { circles: packed.circles.map((circle) => ({ ...circle, x: circle.y, y: circle.x })), width: Math.max(safeWidth, packed.height), scale: 1 };
82525
+ }
82431
82526
 
82432
82527
  // src/components/AgentMap/AgentMap.tsx
82433
82528
  import { Fragment as Fragment66, jsx as jsx402, jsxs as jsxs251 } from "react/jsx-runtime";
@@ -82485,7 +82580,10 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
82485
82580
  const focused = !narrow && !!expandedProject && expandedProject.agents.length > MAX_ORBIT_AGENTS && expandedProject.agents.length <= MAX_FOCUS_AGENTS;
82486
82581
  const showLargeAgentList = !!expandedProject && expandedProject.agents.length > MAX_FOCUS_AGENTS;
82487
82582
  const graphHeight = fullHeight && !narrow ? showLargeAgentList ? Math.max(160, Math.floor(viewportHeight * 0.45)) : Math.max(364, viewportHeight) : 420;
82488
- const layout = useMemo75(() => layoutProjectsHorizontally(projects.map((p) => ({ id: p.id, radius: p.id === expanded && p.agents.length <= MAX_ORBIT_AGENTS ? EXPANDED_RADIUS : COLLAPSED_RADIUS })), graphHeight, 18, scattered), [projects, expanded, graphHeight, scattered]);
82583
+ const layout = useMemo75(() => {
82584
+ const items = projects.map((p) => ({ id: p.id, radius: p.id === expanded && p.agents.length <= MAX_ORBIT_AGENTS ? EXPANDED_RADIUS : COLLAPSED_RADIUS }));
82585
+ return scattered && !narrow ? scatterProjects(items, width, graphHeight, 18) : { ...layoutProjectsHorizontally(items, graphHeight, 18, scattered), scale: 1 };
82586
+ }, [projects, expanded, graphHeight, scattered, narrow, width]);
82489
82587
  const canvasWidth = Math.max(width, layout.width, focused ? scrollLeft + width : 0);
82490
82588
  useEffect93(() => {
82491
82589
  const viewport = orbsViewportRef.current;
@@ -82612,10 +82710,11 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
82612
82710
  const completed = project.agents.filter((a) => a.status === "completed").length;
82613
82711
  const points = orbit ? agentPositions(project.agents.length, focused) : [];
82614
82712
  const scale = focused ? 0.7 : project.agents.length > 8 ? Math.max(0.72, 8 / project.agents.length) : 1;
82713
+ const hubScale = open ? scale : layout.scale;
82615
82714
  const color2 = attention ? COLORS2.attention : completed === project.agents.length && completed > 0 ? COLORS2.completed : COLORS2.working;
82616
- return /* @__PURE__ */ jsxs251("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 }, "aria-hidden": focused && !open ? true : void 0, children: [
82715
+ return /* @__PURE__ */ jsxs251("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: [
82617
82716
  orbit && /* @__PURE__ */ jsx402("svg", { className: "cj-agent-map__lines", "aria-hidden": "true", viewBox: "-164 -164 328 328", children: project.agents.map((agent, j) => /* @__PURE__ */ jsx402("line", { x1: "0", y1: "0", x2: points[j].x, y2: points[j].y, stroke: COLORS2[agent.status] }, agent.id)) }),
82618
- /* @__PURE__ */ jsxs251("button", { type: "button", className: ["cj-agent-map__hub", attention && "cj-agent-map__hub--attention"].filter(Boolean).join(" "), style: { "--agent-color": color2, "--hub-scale": open ? scale : 1 }, 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: [
82717
+ /* @__PURE__ */ jsxs251("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: [
82619
82718
  /* @__PURE__ */ jsx402("strong", { children: project.name }),
82620
82719
  /* @__PURE__ */ jsxs251("span", { children: [
82621
82720
  project.agents.length,