@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.cjs CHANGED
@@ -49185,7 +49185,8 @@ var SideMenu = ({
49185
49185
  search = false,
49186
49186
  searchValue,
49187
49187
  onSearchChange,
49188
- searchPlaceholder
49188
+ searchPlaceholder,
49189
+ searchScope = "all"
49189
49190
  }) => {
49190
49191
  const t = useKitT();
49191
49192
  const location = (0, import_react_router_dom2.useLocation)();
@@ -49331,6 +49332,8 @@ var SideMenu = ({
49331
49332
  const query = searchQuery.trim().toLowerCase();
49332
49333
  const matchesItem = (item) => !query || item.label.toLowerCase().includes(query) || (item.description ?? "").toLowerCase().includes(query);
49333
49334
  const matchesSubtree = (item) => matchesItem(item) || (item.children ?? []).some(matchesSubtree);
49335
+ const searchTopOnly = searchScope === "top";
49336
+ const matchesScope = (item) => searchTopOnly ? matchesItem(item) : matchesSubtree(item);
49334
49337
  const passesGuard = (0, import_react294.useCallback)(
49335
49338
  (item) => {
49336
49339
  if (item.hidden) return false;
@@ -49358,13 +49361,13 @@ var SideMenu = ({
49358
49361
  const visibleItems2 = (0, import_react294.useMemo)(() => {
49359
49362
  const groupsWithVisibleLinks = /* @__PURE__ */ new Set();
49360
49363
  items.forEach((item) => {
49361
- if (item.type !== "group" && item.type !== "divider" && passesGuard(item) && matchesSubtree(item)) {
49364
+ if (item.type !== "group" && item.type !== "divider" && passesGuard(item) && matchesScope(item)) {
49362
49365
  if (item.groupName) groupsWithVisibleLinks.add(item.groupName);
49363
49366
  }
49364
49367
  });
49365
49368
  return items.filter((item) => {
49366
49369
  if (!passesGuard(item)) return false;
49367
- if (item.type !== "group" && item.type !== "divider" && !matchesSubtree(item)) {
49370
+ if (item.type !== "group" && item.type !== "divider" && !matchesScope(item)) {
49368
49371
  return false;
49369
49372
  }
49370
49373
  if (item.type === "group") return groupsWithVisibleLinks.has(item.slug);
@@ -49372,7 +49375,7 @@ var SideMenu = ({
49372
49375
  return !item.groupName || groupsWithVisibleLinks.has(item.groupName);
49373
49376
  return true;
49374
49377
  });
49375
- }, [items, passesGuard, query]);
49378
+ }, [items, passesGuard, query, searchTopOnly]);
49376
49379
  const visibleCtas = (0, import_react294.useMemo)(
49377
49380
  () => ctas ? ctas.filter(passesGuard) : [],
49378
49381
  [ctas, passesGuard]
@@ -49429,7 +49432,7 @@ var SideMenu = ({
49429
49432
  const hasChildren = !!link.children?.length;
49430
49433
  const selfActive = isActiveItem(link);
49431
49434
  const childActive = hasChildren ? hasActiveDescendant(link) : false;
49432
- const visibleChildren = searchActive ? (link.children ?? []).filter(matchesSubtree) : link.children ?? [];
49435
+ const visibleChildren = searchActive && !searchTopOnly ? (link.children ?? []).filter(matchesSubtree) : link.children ?? [];
49433
49436
  const showChildren = hasChildren && (searchActive || openSubmenus.has(link.slug)) && visibleChildren.length > 0;
49434
49437
  const pageSize = link.childrenPageSize;
49435
49438
  const paged = !searchActive && pageSize !== void 0 && pageSize > 0;
@@ -82852,6 +82855,98 @@ function layoutProjectsHorizontally(items, height, gap = 18, scattered = false)
82852
82855
  const layout = layoutProjects(items, height, gap, scattered);
82853
82856
  return { circles: layout.circles.map((circle) => ({ ...circle, x: circle.y, y: circle.x })), width: layout.height };
82854
82857
  }
82858
+ var SCATTER_MIN_SCALE = 0.7;
82859
+ var SCATTER_SCALE_STEP = 0.05;
82860
+ var SCATTER_JITTER = 0.4;
82861
+ var SCATTER_WIDTH_STEPS = 3;
82862
+ function hashId(id) {
82863
+ let hash2 = 2166136261;
82864
+ for (const char of id) hash2 = Math.imul(hash2 ^ char.charCodeAt(0), 16777619);
82865
+ return hash2 >>> 0;
82866
+ }
82867
+ function seedGrid(items, width, height, gap, scale, base) {
82868
+ const count = items.length;
82869
+ let columns = 1, bestDelta = Infinity;
82870
+ for (let candidate = 1; candidate <= count; candidate++) {
82871
+ const rows2 = Math.ceil(count / candidate);
82872
+ const delta = Math.abs(width / candidate - height / rows2);
82873
+ if (delta < bestDelta) {
82874
+ bestDelta = delta;
82875
+ columns = candidate;
82876
+ }
82877
+ }
82878
+ const rows = Math.ceil(count / columns);
82879
+ const circles = [];
82880
+ for (let row = 0; row < rows; row++) {
82881
+ const rowStart = Math.floor(row * count / rows), rowEnd = Math.floor((row + 1) * count / rows);
82882
+ const rowCount = rowEnd - rowStart;
82883
+ if (rowCount <= 0) continue;
82884
+ const cellWidth = width / rowCount, cellHeight = height / rows;
82885
+ for (let column = 0; column < rowCount; column++) {
82886
+ const item = items[rowStart + column];
82887
+ const radius = item.radius > base ? item.radius : item.radius * scale;
82888
+ const hash2 = hashId(item.id);
82889
+ const jitterX = (hash2 % 89 / 89 - 0.5) * SCATTER_JITTER * cellWidth;
82890
+ const jitterY = ((hash2 >>> 8 >>> 0) % 89 / 89 - 0.5) * SCATTER_JITTER * cellHeight;
82891
+ const loX = radius + gap, hiX = width - radius - gap, loY = radius + gap, hiY = height - radius - gap;
82892
+ const x = (column + 0.5) * cellWidth + jitterX, y = (row + 0.5) * cellHeight + jitterY;
82893
+ 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)) });
82894
+ }
82895
+ }
82896
+ return circles;
82897
+ }
82898
+ function relaxInside(circles, width, height, gap) {
82899
+ let maxOverlap = Infinity;
82900
+ for (let step = 0; step < 400 && maxOverlap >= 0.05; step++) {
82901
+ maxOverlap = 0;
82902
+ for (let i = 0; i < circles.length; i++) {
82903
+ const a = circles[i];
82904
+ for (let j = i + 1; j < circles.length; j++) {
82905
+ const b = circles[j];
82906
+ let dx = b.x - a.x;
82907
+ let dy = b.y - a.y;
82908
+ let distance = Math.hypot(dx, dy);
82909
+ if (distance < 1e-3) {
82910
+ dx = 1;
82911
+ dy = 0;
82912
+ distance = 1;
82913
+ }
82914
+ const overlap = a.radius + b.radius + gap - distance;
82915
+ if (overlap > 0) {
82916
+ maxOverlap = Math.max(maxOverlap, overlap);
82917
+ const shift = overlap / 2;
82918
+ const ux = dx / distance;
82919
+ const uy = dy / distance;
82920
+ a.x -= ux * shift;
82921
+ a.y -= uy * shift;
82922
+ b.x += ux * shift;
82923
+ b.y += uy * shift;
82924
+ }
82925
+ }
82926
+ }
82927
+ for (const circle of circles) {
82928
+ circle.x = Math.max(circle.radius + gap, Math.min(width - circle.radius - gap, circle.x));
82929
+ circle.y = Math.max(circle.radius + gap, Math.min(height - circle.radius - gap, circle.y));
82930
+ }
82931
+ }
82932
+ return maxOverlap < 0.05;
82933
+ }
82934
+ function scatterProjects(items, width, height, gap = 18) {
82935
+ const safeWidth = Math.max(1, width), safeHeight = Math.max(1, height);
82936
+ if (items.length === 0) return { circles: [], width: safeWidth, scale: 1 };
82937
+ const base = Math.min(...items.map((item) => item.radius));
82938
+ for (let stretch = 0; stretch <= SCATTER_WIDTH_STEPS; stretch++) {
82939
+ const boxWidth = safeWidth * (1 + stretch * 0.5);
82940
+ for (let level = 0; ; level++) {
82941
+ const scale = Math.max(SCATTER_MIN_SCALE, 1 - level * SCATTER_SCALE_STEP);
82942
+ const circles = seedGrid(items, boxWidth, safeHeight, gap, scale, base);
82943
+ if (relaxInside(circles, boxWidth, safeHeight, gap)) return { circles, width: boxWidth, scale };
82944
+ if (scale === SCATTER_MIN_SCALE) break;
82945
+ }
82946
+ }
82947
+ const packed = packProjects(items, safeHeight, gap);
82948
+ return { circles: packed.circles.map((circle) => ({ ...circle, x: circle.y, y: circle.x })), width: Math.max(safeWidth, packed.height), scale: 1 };
82949
+ }
82855
82950
 
82856
82951
  // src/components/AgentMap/AgentMap.tsx
82857
82952
  var import_jsx_runtime402 = require("react/jsx-runtime");
@@ -82909,7 +83004,10 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
82909
83004
  const focused = !narrow && !!expandedProject && expandedProject.agents.length > MAX_ORBIT_AGENTS && expandedProject.agents.length <= MAX_FOCUS_AGENTS;
82910
83005
  const showLargeAgentList = !!expandedProject && expandedProject.agents.length > MAX_FOCUS_AGENTS;
82911
83006
  const graphHeight = fullHeight && !narrow ? showLargeAgentList ? Math.max(160, Math.floor(viewportHeight * 0.45)) : Math.max(364, viewportHeight) : 420;
82912
- const layout = (0, import_react374.useMemo)(() => 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]);
83007
+ const layout = (0, import_react374.useMemo)(() => {
83008
+ const items = projects.map((p) => ({ id: p.id, radius: p.id === expanded && p.agents.length <= MAX_ORBIT_AGENTS ? EXPANDED_RADIUS : COLLAPSED_RADIUS }));
83009
+ return scattered && !narrow ? scatterProjects(items, width, graphHeight, 18) : { ...layoutProjectsHorizontally(items, graphHeight, 18, scattered), scale: 1 };
83010
+ }, [projects, expanded, graphHeight, scattered, narrow, width]);
82913
83011
  const canvasWidth = Math.max(width, layout.width, focused ? scrollLeft + width : 0);
82914
83012
  (0, import_react374.useEffect)(() => {
82915
83013
  const viewport = orbsViewportRef.current;
@@ -83036,10 +83134,11 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
83036
83134
  const completed = project.agents.filter((a) => a.status === "completed").length;
83037
83135
  const points = orbit ? agentPositions(project.agents.length, focused) : [];
83038
83136
  const scale = focused ? 0.7 : project.agents.length > 8 ? Math.max(0.72, 8 / project.agents.length) : 1;
83137
+ const hubScale = open ? scale : layout.scale;
83039
83138
  const color2 = attention ? COLORS2.attention : completed === project.agents.length && completed > 0 ? COLORS2.completed : COLORS2.working;
83040
- return /* @__PURE__ */ (0, import_jsx_runtime402.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 }, "aria-hidden": focused && !open ? true : void 0, children: [
83139
+ return /* @__PURE__ */ (0, import_jsx_runtime402.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: [
83041
83140
  orbit && /* @__PURE__ */ (0, import_jsx_runtime402.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_runtime402.jsx)("line", { x1: "0", y1: "0", x2: points[j].x, y2: points[j].y, stroke: COLORS2[agent.status] }, agent.id)) }),
83042
- /* @__PURE__ */ (0, import_jsx_runtime402.jsxs)("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: [
83141
+ /* @__PURE__ */ (0, import_jsx_runtime402.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: [
83043
83142
  /* @__PURE__ */ (0, import_jsx_runtime402.jsx)("strong", { children: project.name }),
83044
83143
  /* @__PURE__ */ (0, import_jsx_runtime402.jsxs)("span", { children: [
83045
83144
  project.agents.length,