@principal-ai/subsystems-react 0.56.21 → 0.56.22

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.
Files changed (54) hide show
  1. package/dist/index.d.ts +4 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/subsystem/C4Graph.d.ts +2 -69
  6. package/dist/subsystem/C4Graph.d.ts.map +1 -1
  7. package/dist/subsystem/C4Graph.js +8 -154
  8. package/dist/subsystem/C4Graph.js.map +1 -1
  9. package/dist/subsystem/C4NodeCard.d.ts +1 -47
  10. package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
  11. package/dist/subsystem/C4NodeCard.js +6 -141
  12. package/dist/subsystem/C4NodeCard.js.map +1 -1
  13. package/dist/subsystem/ContainersPanel.d.ts +33 -0
  14. package/dist/subsystem/ContainersPanel.d.ts.map +1 -0
  15. package/dist/subsystem/ContainersPanel.js +116 -0
  16. package/dist/subsystem/ContainersPanel.js.map +1 -0
  17. package/dist/subsystem/SubsystemComponentGraph.d.ts +18 -1
  18. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  19. package/dist/subsystem/SubsystemComponentGraph.js +143 -21
  20. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  21. package/dist/subsystem/containerCard.d.ts +132 -0
  22. package/dist/subsystem/containerCard.d.ts.map +1 -0
  23. package/dist/subsystem/containerCard.js +167 -0
  24. package/dist/subsystem/containerCard.js.map +1 -0
  25. package/dist/subsystem/graphChrome.d.ts +11 -8
  26. package/dist/subsystem/graphChrome.d.ts.map +1 -1
  27. package/dist/subsystem/graphChrome.js +11 -9
  28. package/dist/subsystem/graphChrome.js.map +1 -1
  29. package/dist/subsystem/graphMorph.d.ts +142 -0
  30. package/dist/subsystem/graphMorph.d.ts.map +1 -0
  31. package/dist/subsystem/graphMorph.js +177 -0
  32. package/dist/subsystem/graphMorph.js.map +1 -0
  33. package/dist/subsystem/model.d.ts +89 -0
  34. package/dist/subsystem/model.d.ts.map +1 -1
  35. package/dist/subsystem/model.js +224 -15
  36. package/dist/subsystem/model.js.map +1 -1
  37. package/dist/subsystem/nodes.d.ts +9 -3
  38. package/dist/subsystem/nodes.d.ts.map +1 -1
  39. package/dist/subsystem/nodes.js +134 -82
  40. package/dist/subsystem/nodes.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/index.ts +5 -0
  43. package/src/stories/Canvases/Subsystem/ContainerFrames.stories.tsx +132 -0
  44. package/src/subsystem/C4Graph.tsx +20 -180
  45. package/src/subsystem/C4NodeCard.tsx +34 -202
  46. package/src/subsystem/ContainersPanel.tsx +239 -0
  47. package/src/subsystem/SubsystemComponentGraph.tsx +222 -25
  48. package/src/subsystem/containerCard.tsx +264 -0
  49. package/src/subsystem/graphChrome.tsx +11 -9
  50. package/src/subsystem/graphMorph.tsx +212 -0
  51. package/src/subsystem/model.collapse.test.ts +128 -0
  52. package/src/subsystem/model.ts +306 -16
  53. package/src/subsystem/nodes.group.test.tsx +125 -16
  54. package/src/subsystem/nodes.tsx +201 -91
@@ -18,10 +18,12 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
18
18
  import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
19
19
  import { ReactFlow, ReactFlowProvider, useReactFlow, useViewport, applyNodeChanges, } from '@xyflow/react';
20
20
  import { useTheme } from '@principal-ade/industry-theme';
21
- import { ArrowDown, ArrowRight, Files, Route, Unlink, X } from 'lucide-react';
21
+ import { ArrowDown, ArrowRight, Boxes, Files, Route, Unlink, X } from 'lucide-react';
22
22
  import { IndustryMarkdownSlide } from 'themed-markdown';
23
- import { buildSubsystemGraph, deriveGraphEdges, isConstructsOnlyModel, moduleGroupNodeId, processGroupNodeId, isTrailMechanism, edgeColor, MECHANISM_DESCRIPTIONS, subsystemGraphLayoutKey, trailStepGraphEdgeId, unroutedEdgeIds, } from './model';
23
+ import { buildSubsystemGraph, deriveGraphEdges, buildBoundaryLayoutGroups, isCardFrame, isConstructsOnlyModel, packageColor, moduleGroupNodeId, processGroupNodeId, isTrailMechanism, edgeColor, MECHANISM_DESCRIPTIONS, subsystemGraphLayoutKey, trailStepGraphEdgeId, unroutedEdgeIds, } from './model';
24
24
  import { ConstructsCatalog } from './ConstructsCatalog';
25
+ import { ContainersPanel } from './ContainersPanel';
26
+ import { technologyBrand } from './techIcons';
25
27
  import { SubsystemAgentsPanel, } from './AgentsPanel';
26
28
  import { MaintainLivePanel, } from '../components/maintain-events/MaintainLivePanel';
27
29
  import { SubsystemComponentNode, SubsystemGroupNode, SubsystemEdge, SUBSYSTEM_CALLBACKS, hexWithAlpha, EDGE_DIM_ALPHA, fileMatchForNode, flowElementVisibility, flowNodeVisibility } from './nodes';
@@ -79,6 +81,16 @@ function writeViewState(key, patch) {
79
81
  // Best-effort: private mode / quota — view state is non-critical.
80
82
  }
81
83
  }
84
+ /**
85
+ * Whether an edge is one of `set`. A line a collapsed frame rolled up stands in
86
+ * for each edge it absorbed, so it matches when any of those ids is in the set.
87
+ */
88
+ function edgeMatches(set, e) {
89
+ if (set.has(e.id))
90
+ return true;
91
+ const ids = e.data?.rolledUpIds;
92
+ return ids?.some((id) => set.has(id)) === true;
93
+ }
82
94
  const nodeTypes = {
83
95
  'subsystem-component': SubsystemComponentNode,
84
96
  'subsystem-group': SubsystemGroupNode,
@@ -128,7 +140,7 @@ const TrailDrawerContent = memo(function TrailDrawerContent({ render, trail, ste
128
140
  onVisibleStepChange,
129
141
  }) }));
130
142
  });
131
- function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirection: layoutDirectionProp, defaultLayoutDirection = 'horizontal', onLayoutDirectionChange, hideLayoutToggle = false, refocusOnLayoutFlip = true, initialTrailId, onTrailSelect, onTrailStepHover, onReorderTrails, stepEmphasis, onRemoveStepEmphasis, onSelect, onEdgeSelect, measured: _measured, maxNodeWidth, showEdgeLabels, showSingletonFrames = true, moduleNesting, edgeView, hideSidebar, trailStepMode = 'focus', autoPlayTrails = false, trailAutoPlayIntervalMs = TRAIL_PLAY_PAUSE_MS, onAutoPlayStep, zoomOnTrailFocus = true, trailFocusDurationMs = 300, graphTitle, showTrailTitle = false, description, canvasOverlay, interactive = true, canvasBackground = 'theme', onLayoutReady, onNodeRects, sidebarExtra, sidebarAfterDescription, issues, showIssues, filesActive, sidebarScope, onSidebarTrailChange, focusIssueCategory, laneStatus, onSelectIssue, onApplyIssueFix, onHoverIssue, renderFileViewer, renderTrailViewer, onFileSelect, componentVerification, onInspectSymbol, boundaryColors, codeProcessKeys, hideDrawer = false, persistKey, liveEvents, agentsPanel }) {
143
+ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirection: layoutDirectionProp, defaultLayoutDirection = 'horizontal', onLayoutDirectionChange, hideLayoutToggle = false, refocusOnLayoutFlip = true, initialTrailId, onTrailSelect, onTrailStepHover, onReorderTrails, stepEmphasis, onRemoveStepEmphasis, onSelect, onEdgeSelect, measured: _measured, maxNodeWidth, showEdgeLabels, showSingletonFrames = true, moduleNesting, edgeView, hideSidebar, trailStepMode = 'focus', autoPlayTrails = false, trailAutoPlayIntervalMs = TRAIL_PLAY_PAUSE_MS, onAutoPlayStep, zoomOnTrailFocus = true, trailFocusDurationMs = 300, graphTitle, showTrailTitle = false, description, canvasOverlay, interactive = true, canvasBackground = 'theme', onLayoutReady, onNodeRects, sidebarExtra, sidebarAfterDescription, issues, showIssues, filesActive, sidebarScope, onSidebarTrailChange, focusIssueCategory, laneStatus, onSelectIssue, onApplyIssueFix, onHoverIssue, renderFileViewer, renderTrailViewer, onFileSelect, componentVerification, onInspectSymbol, boundaryColors, codeProcessKeys, regionDetails, defaultFramesCollapsed = true, containersActive, hideDrawer = false, persistKey, liveEvents, agentsPanel }) {
132
144
  const { theme } = useTheme();
133
145
  const { fitView, fitBounds } = useReactFlow();
134
146
  const [descriptionOpen, setDescriptionOpen] = useState(false);
@@ -195,6 +207,32 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
195
207
  /** Solo layout: only this trail's components and edges are laid out. */
196
208
  const [layoutTrailId, setLayoutTrailId] = useState(null);
197
209
  const [committedTrailId, setCommittedTrailId] = useState(null);
210
+ // Closed container cards. A frame folds its members away and rolls their
211
+ // lines up onto the card; opening it again lays the members back out. Each
212
+ // toggle is a layout flip like a direction change: ELK re-runs behind the
213
+ // edge fade while the frames slide to their new slots.
214
+ // Stored as a default plus exceptions so "close all" needs no knowledge of
215
+ // which frames the layout will produce: `framesCollapsed` is the default
216
+ // every card frame takes, `toggledGroupIds` the frames flipped away from it.
217
+ const [framesCollapsed, setFramesCollapsed] = useState(() => persisted.framesCollapsed ?? defaultFramesCollapsed);
218
+ const [toggledGroupIds, setToggledGroupIds] = useState(() => new Set(persisted.toggledFrames ?? []));
219
+ const [committedCollapsed, setCommittedCollapsed] = useState({ framesCollapsed, toggled: toggledGroupIds });
220
+ const toggleCollapsed = useCallback((groupId) => {
221
+ setToggledGroupIds((prev) => {
222
+ const next = new Set(prev);
223
+ if (next.has(groupId))
224
+ next.delete(groupId);
225
+ else
226
+ next.add(groupId);
227
+ return next;
228
+ });
229
+ }, []);
230
+ const setAllFramesCollapsed = useCallback((collapsed) => {
231
+ setFramesCollapsed(collapsed);
232
+ setToggledGroupIds(new Set());
233
+ }, []);
234
+ const collapsedKey = `${framesCollapsed ? 'closed' : 'open'}:${Array.from(toggledGroupIds).sort().join(',')}`;
235
+ const committedCollapsedKey = `${committedCollapsed.framesCollapsed ? 'closed' : 'open'}:${Array.from(committedCollapsed.toggled).sort().join(',')}`;
198
236
  const changeLayoutDirection = useCallback((next) => {
199
237
  if (next === requestedDirection)
200
238
  return;
@@ -209,8 +247,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
209
247
  setLayoutTrailId(null);
210
248
  }
211
249
  }, [trails, layoutTrailId]);
212
- const requestedLayoutKey = `${requestedDirection}|${layoutTrailId ?? ''}`;
213
- const committedLayoutKey = `${committedDirection}|${committedTrailId ?? ''}`;
250
+ const requestedLayoutKey = `${requestedDirection}|${layoutTrailId ?? ''}|${collapsedKey}`;
251
+ const committedLayoutKey = `${committedDirection}|${committedTrailId ?? ''}|${committedCollapsedKey}`;
214
252
  // Beat 1: request → fade the edges out, then commit the direction / focus
215
253
  // (which re-runs ELK). Reduced-motion users get the new layout immediately.
216
254
  useEffect(() => {
@@ -235,6 +273,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
235
273
  if (reduceMotion) {
236
274
  setCommittedDirection(requestedDirection);
237
275
  setCommittedTrailId(layoutTrailId);
276
+ setCommittedCollapsed({ framesCollapsed, toggled: toggledGroupIds });
238
277
  return;
239
278
  }
240
279
  flipSawPendingLayoutRef.current = false;
@@ -243,6 +282,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
243
282
  flipFadeTimerRef.current = null;
244
283
  setCommittedDirection(requestedDirection);
245
284
  setCommittedTrailId(layoutTrailId);
285
+ setCommittedCollapsed({ framesCollapsed, toggled: toggledGroupIds });
246
286
  }, LAYOUT_FLIP_EDGE_MS);
247
287
  return () => {
248
288
  if (flipFadeTimerRef.current != null) {
@@ -256,6 +296,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
256
296
  refocusOnLayoutFlip,
257
297
  requestedDirection,
258
298
  layoutTrailId,
299
+ framesCollapsed,
300
+ toggledGroupIds,
259
301
  ]);
260
302
  // Beat 3: the committed layout has settled → the node slide is over, fade
261
303
  // the edges back in. The ref keeps the OLD `layoutReady` (still true until
@@ -298,6 +340,11 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
298
340
  return;
299
341
  writeViewState(persistKey, { layoutDirection: requestedDirection });
300
342
  }, [persistKey, requestedDirection]);
343
+ useEffect(() => {
344
+ if (!persistKey)
345
+ return;
346
+ writeViewState(persistKey, { framesCollapsed, toggledFrames: Array.from(toggledGroupIds) });
347
+ }, [persistKey, framesCollapsed, toggledGroupIds]);
301
348
  // Safety net: never leave the canvas edge-less if a layout pass stalls
302
349
  // (measurement never lands, ELK hangs). The edges come back; the layout
303
350
  // stays wherever it got to.
@@ -557,11 +604,13 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
557
604
  components: layoutDoc.components,
558
605
  trails: layoutDoc.trails,
559
606
  graphifyRelations: layoutRelations,
560
- }), [layoutDoc, layoutRelations]);
607
+ }) + `|collapsed:${committedCollapsedKey}`, [layoutDoc, layoutRelations, committedCollapsedKey]);
561
608
  const layoutDocRef = useRef(layoutDoc);
562
609
  const layoutRelationsRef = useRef(layoutRelations);
610
+ const committedCollapsedRef = useRef(committedCollapsed);
563
611
  layoutDocRef.current = layoutDoc;
564
612
  layoutRelationsRef.current = layoutRelations;
613
+ committedCollapsedRef.current = committedCollapsed;
565
614
  // Track measured dimensions from React Flow's dimension changes.
566
615
  // These arrive as { type: 'dimensions', id, dimensions } in onNodesChange.
567
616
  // Retained across same-id layoutKey updates so Pass 2 can run without a remount.
@@ -586,6 +635,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
586
635
  orderByLine,
587
636
  layoutDirection: committedDirection,
588
637
  codeProcessKeys,
638
+ regionDetails,
639
+ collapsedGroupIds: committedCollapsedRef.current.toggled,
640
+ cardFramesCollapsed: committedCollapsedRef.current.framesCollapsed,
589
641
  })
590
642
  .then(({ nodes, edges: e, absoluteRects }) => {
591
643
  if (!alive)
@@ -636,7 +688,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
636
688
  const measuredWidths = new Map(leafNodes.map((n) => [n.id, dims.get(n.id).width]));
637
689
  const measuredHeights = new Map(leafNodes.map((n) => [n.id, dims.get(n.id).height]));
638
690
  const gen = ++pass2GenRef.current;
639
- void buildSubsystemGraph(layoutDoc, { maxNodeWidth, showEdgeLabels, measuredWidths, measuredHeights, showSingletonFrames, moduleNesting, graphifyRelations: layoutRelations, orderByLine, layoutDirection: committedDirection, codeProcessKeys })
691
+ void buildSubsystemGraph(layoutDoc, { maxNodeWidth, showEdgeLabels, measuredWidths, measuredHeights, showSingletonFrames, moduleNesting, graphifyRelations: layoutRelations, orderByLine, layoutDirection: committedDirection, codeProcessKeys, regionDetails, collapsedGroupIds: committedCollapsed.toggled, cardFramesCollapsed: committedCollapsed.framesCollapsed })
640
692
  .then(({ nodes, edges: e, absoluteRects }) => {
641
693
  if (gen !== pass2GenRef.current)
642
694
  return;
@@ -650,7 +702,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
650
702
  // Reveal Pass 1 layout rather than leaving the cover up forever.
651
703
  setLayoutReady(true);
652
704
  });
653
- }, [built.nodes, layoutDoc, layoutRelations, orderByLine, maxNodeWidth, showEdgeLabels, moduleNesting, committedDirection]);
705
+ }, [built.nodes, layoutDoc, layoutRelations, orderByLine, maxNodeWidth, showEdgeLabels, moduleNesting, committedDirection, committedCollapsed]);
654
706
  // After Pass 1 commits, try Pass 2 immediately with retained measurements.
655
707
  // Same-id live updates often get no new React Flow `dimensions` events, so
656
708
  // waiting only on onNodesChange leaves the cover stuck.
@@ -1054,7 +1106,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1054
1106
  return null;
1055
1107
  const ids = new Set();
1056
1108
  for (const e of baseEdges) {
1057
- if (!edgeIds.has(e.id))
1109
+ if (!edgeMatches(edgeIds, e))
1058
1110
  continue;
1059
1111
  ids.add(e.source);
1060
1112
  ids.add(e.target);
@@ -1134,7 +1186,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1134
1186
  // visible, dimmed when members are dimmed. Never selectable.
1135
1187
  if (n.type === 'subsystem-group') {
1136
1188
  const region = n.data?.region;
1137
- const memberAliases = region?.memberAliases ?? [];
1189
+ // A collapsed card is an edge endpoint in its own right, so its own id
1190
+ // joins its members' when deciding whether the frame is on an open flow.
1191
+ const memberAliases = [n.id, ...(region?.memberAliases ?? [])];
1138
1192
  // `brightNodeIds` is the focused step's endpoints. It has to be a
1139
1193
  // spotlight member as well as a bright set: without an expanded flow
1140
1194
  // there is no opened set, so dimming has to be driven from the
@@ -1163,6 +1217,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1163
1217
  ...(color != null && { color }),
1164
1218
  ...(dimmed && { dimmed: true }),
1165
1219
  ...(regionIssue && { issue: regionIssue }),
1220
+ ...(region && isCardFrame(region) && { onToggleCollapse: () => toggleCollapsed(n.id) }),
1166
1221
  },
1167
1222
  };
1168
1223
  }
@@ -1202,7 +1257,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1202
1257
  },
1203
1258
  };
1204
1259
  });
1205
- }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors]);
1260
+ }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors, toggleCollapsed]);
1206
1261
  const baseNodesKey = useMemo(() => nodes.map((n) => n.id).sort().join(','), [nodes]);
1207
1262
  const baseEdgesKey = useMemo(() => convertedEdges.map((e) => e.id).sort().join(','), [convertedEdges]);
1208
1263
  const dispEdges = useMemo(() => {
@@ -1228,16 +1283,17 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1228
1283
  }
1229
1284
  return isTrailMechanism(mechanism);
1230
1285
  };
1286
+ const inSet = (set, e) => set != null && edgeMatches(set, e);
1231
1287
  if (openedEdgeIds || focusEdgeIds || previewEdgeIds || issueFocusEdgeIds) {
1232
1288
  return baseEdges.map((e) => {
1233
1289
  const vis = flowElementVisibility({
1234
- inOpened: openedEdgeIds?.has(e.id) === true,
1235
- inSelected: focusEdgeIds?.has(e.id) === true,
1290
+ inOpened: inSet(openedEdgeIds, e),
1291
+ inSelected: inSet(focusEdgeIds, e),
1236
1292
  anyOpened: openedEdgeIds != null,
1237
1293
  anySelected: focusEdgeIds != null,
1238
1294
  });
1239
1295
  const dimSource = previewEdgeIds ?? issueFocusEdgeIds;
1240
- const dimmed = dimSource ? vis.hidden || !dimSource.has(e.id) : vis.dimmed;
1296
+ const dimmed = dimSource ? vis.hidden || !inSet(dimSource, e) : vis.dimmed;
1241
1297
  const hidden = vis.hidden || !edgeInView(e);
1242
1298
  return { ...paint(e, dimmed), hidden };
1243
1299
  });
@@ -1355,7 +1411,14 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1355
1411
  // Boundary frame → frame its members on the canvas; double-click again to
1356
1412
  // zoom back out. User-initiated, so it ignores the trail zoom gate.
1357
1413
  if (node.type === 'subsystem-group') {
1358
- const key = node.data?.region?.key;
1414
+ const region = node.data?.region;
1415
+ // Card frames (process / package) grow and shrink on double-click, the
1416
+ // way a C4 container does; module frames keep the zoom-to-frame.
1417
+ if (region && isCardFrame(region)) {
1418
+ toggleCollapsed(node.id);
1419
+ return;
1420
+ }
1421
+ const key = region?.key;
1359
1422
  if (!key)
1360
1423
  return;
1361
1424
  if (focusedBoundaryKey === key) {
@@ -1436,7 +1499,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1436
1499
  const nodeIds = new Set();
1437
1500
  const points = [];
1438
1501
  for (const e of baseEdges) {
1439
- if (!ids.has(e.id))
1502
+ if (!edgeMatches(ids, e))
1440
1503
  continue;
1441
1504
  nodeIds.add(e.source);
1442
1505
  nodeIds.add(e.target);
@@ -1536,6 +1599,54 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1536
1599
  height: Math.max(1, maxY - minY),
1537
1600
  }, { padding, duration: trailFocusDurationMs });
1538
1601
  }, [rectForNode, fitBounds, trailFocusDurationMs]);
1602
+ // The Containers list: every card frame in the laid-out graph, parents before
1603
+ // their children, with the colour the canvas draws it in. Rows keep the
1604
+ // grouping's declaration order — the layout moves closed cards after open
1605
+ // frames, and a row must not jump when its frame is toggled.
1606
+ const containerOrder = useMemo(() => {
1607
+ const ids = buildBoundaryLayoutGroups({ components }, { showSingletonFrames, moduleNesting, codeProcessKeys }).map((g) => g.id);
1608
+ return new Map(ids.map((id, i) => [id, i]));
1609
+ }, [components, showSingletonFrames, moduleNesting, codeProcessKeys]);
1610
+ const containerItems = useMemo(() => {
1611
+ const frames = built.nodes
1612
+ .filter((n) => n.type === 'subsystem-group' &&
1613
+ isCardFrame(n.data.region))
1614
+ .sort((a, b) => (containerOrder.get(a.id) ?? Number.MAX_SAFE_INTEGER) -
1615
+ (containerOrder.get(b.id) ?? Number.MAX_SAFE_INTEGER));
1616
+ const byId = new Map(frames.map((n) => [n.id, n]));
1617
+ const children = new Map();
1618
+ for (const n of frames) {
1619
+ const parent = n.parentId && byId.has(n.parentId) ? n.parentId : undefined;
1620
+ const list = children.get(parent) ?? [];
1621
+ list.push(n);
1622
+ children.set(parent, list);
1623
+ }
1624
+ const out = [];
1625
+ const walk = (parent, depth) => {
1626
+ for (const n of children.get(parent) ?? []) {
1627
+ const region = n.data.region;
1628
+ out.push({
1629
+ id: n.id,
1630
+ region,
1631
+ collapsed: n.data.collapsed === true,
1632
+ depth,
1633
+ color: boundaryColors?.[region.key] ??
1634
+ technologyBrand(region.technology)?.color ??
1635
+ packageColor(region.key),
1636
+ });
1637
+ walk(n.id, depth + 1);
1638
+ }
1639
+ };
1640
+ walk(undefined, 0);
1641
+ return out;
1642
+ }, [built.nodes, boundaryColors, containerOrder]);
1643
+ const focusContainer = useCallback((id) => {
1644
+ const item = containerItems.find((c) => c.id === id);
1645
+ if (!item)
1646
+ return;
1647
+ setFocusedBoundaryKey(item.region.key);
1648
+ requestAnimationFrame(() => fitNodeRects(new Set([id]), 0.25));
1649
+ }, [containerItems, fitNodeRects]);
1539
1650
  // Zoom back out to the full diagram after the last expanded trail
1540
1651
  // closes (visibility restores non-flow nodes that were hidden).
1541
1652
  const fitOverview = useCallback(() => {
@@ -2082,7 +2193,12 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2082
2193
  midX: d?.labelX ?? 0,
2083
2194
  midY: d?.labelY ?? 0,
2084
2195
  pathLength: d?.pathLength ?? 0,
2085
- stepNos: selectedFlowStepNos?.get(e.id),
2196
+ // A rolled-up line numbers every step it absorbed.
2197
+ stepNos: selectedFlowStepNos
2198
+ ? [e.id, ...(d?.rolledUpIds ?? [])]
2199
+ .flatMap((id) => selectedFlowStepNos.get(id) ?? [])
2200
+ .sort((a, b) => a - b)
2201
+ : undefined,
2086
2202
  stepIssue,
2087
2203
  };
2088
2204
  });
@@ -2103,9 +2219,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2103
2219
  // trail, diagnostics tab) because the canvas dims from
2104
2220
  // the same facts the sidebar renders.
2105
2221
  const sidebarVisible = !hideSidebar &&
2106
- (description || filesActive || issuesActive || sidebarExtra || sidebarAfterDescription ||
2222
+ (description || filesActive || containersActive || issuesActive || sidebarExtra || sidebarAfterDescription ||
2107
2223
  hasTrails);
2108
- const sidebarBodyVisible = hasTrails || filesActive || issuesActive;
2224
+ const sidebarBodyVisible = hasTrails || filesActive || containersActive || issuesActive;
2109
2225
  const sidebarTabs = issuesActive && !sidebarTrail
2110
2226
  ? agentsPanel
2111
2227
  ? [
@@ -2133,7 +2249,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2133
2249
  cursor: 'pointer',
2134
2250
  }, children: "More" })] })), sidebarAfterDescription] }));
2135
2251
  // Lower panel: diagnostics, the file tree, or the trail flow list.
2136
- const sidebarPanel = issuesActive ? (diagnosticsTab === 'agents' && agentsPanel && !sidebarTrail ? (_jsx(SubsystemAgentsPanel, { ...agentsPanel })) : (_jsx(SubsystemIssueList, { issues: sidebarScope.issues, focusCategory: focusIssueCategory, laneStatus: sidebarTrail ? undefined : laneStatus, onSelectIssue: focusIssueTarget, onDeselectIssue: unfocusIssueTarget, onApplyFix: onApplyIssueFix, onHoverIssue: onHoverIssue, onExpandedCategoriesChange: handleExpandedCategoriesChange }))) : filesActive ? treePaths.entries.length === 0 ? (_jsx("div", { style: { padding: 16, color: theme.colors.textSecondary }, children: "No files for this trail." })) : (_jsx(SubsystemFileTree, { headerless: true, files: treeFilePaths, selectedFile: openFile ? treePaths.toDisplay.get(openFile) : null, onSelectFile: (path) => {
2252
+ const sidebarPanel = issuesActive ? (diagnosticsTab === 'agents' && agentsPanel && !sidebarTrail ? (_jsx(SubsystemAgentsPanel, { ...agentsPanel })) : (_jsx(SubsystemIssueList, { issues: sidebarScope.issues, focusCategory: focusIssueCategory, laneStatus: sidebarTrail ? undefined : laneStatus, onSelectIssue: focusIssueTarget, onDeselectIssue: unfocusIssueTarget, onApplyFix: onApplyIssueFix, onHoverIssue: onHoverIssue, onExpandedCategoriesChange: handleExpandedCategoriesChange }))) : containersActive ? (_jsx(ContainersPanel, { containers: containerItems, activeId: containerItems.find((c) => c.region.key === focusedBoundaryKey)?.id ?? null, onFocus: focusContainer, onToggle: toggleCollapsed, onOpenAll: () => setAllFramesCollapsed(false), onCloseAll: () => setAllFramesCollapsed(true) })) : filesActive ? treePaths.entries.length === 0 ? (_jsx("div", { style: { padding: 16, color: theme.colors.textSecondary }, children: "No files for this trail." })) : (_jsx(SubsystemFileTree, { headerless: true, files: treeFilePaths, selectedFile: openFile ? treePaths.toDisplay.get(openFile) : null, onSelectFile: (path) => {
2137
2253
  const file = treePaths.toFile.get(path);
2138
2254
  if (file)
2139
2255
  onOpenDeclarationFile(file);
@@ -2469,6 +2585,10 @@ export function SubsystemComponentGraph(props) {
2469
2585
  });
2470
2586
  const sidebarScope = useMemo(() => buildTrailSidebarScope(props.components, props.trails, props.issues, sidebarTrailId), [props.components, props.trails, props.issues, sidebarTrailId]);
2471
2587
  const fileCount = sidebarScope.treePaths.entries.length;
2588
+ // Card frames the layout will draw — the same grouping `buildSubsystemGraph`
2589
+ // runs, so the count matches the canvas.
2590
+ const containerCount = useMemo(() => buildBoundaryLayoutGroups({ components: props.components }, { showSingletonFrames: props.showSingletonFrames ?? true, moduleNesting: props.moduleNesting, codeProcessKeys: props.codeProcessKeys }).filter((g) => isCardFrame(g.region)).length, [props.components, props.showSingletonFrames, props.moduleNesting, props.codeProcessKeys]);
2591
+ const [containersOpen, setContainersOpen] = useState(false);
2472
2592
  const trailViewLabel = sidebarScope.trail ? 'Trail' : 'Trails';
2473
2593
  const trailCount = props.trails?.length ?? 0;
2474
2594
  const hasFiles = fileCount > 0 || sidebarScope.trail != null;
@@ -2491,9 +2611,11 @@ export function SubsystemComponentGraph(props) {
2491
2611
  const issuesRequested = props.showIssues ?? diagnosticsOpen;
2492
2612
  const issuesActive = hasIssues && issuesRequested;
2493
2613
  const filesActive = filesOpen && hasFiles && !issuesActive;
2614
+ const containersActive = containersOpen && containerCount > 0 && !issuesActive && !filesActive;
2494
2615
  const selectSidebarView = (view) => {
2495
2616
  const nextIssuesActive = view === 'issues';
2496
2617
  setFilesOpen(view === 'files');
2618
+ setContainersOpen(view === 'containers');
2497
2619
  if (nextIssuesActive !== issuesRequested) {
2498
2620
  if (props.showIssues === undefined)
2499
2621
  setDiagnosticsOpen(nextIssuesActive);
@@ -2574,6 +2696,6 @@ export function SubsystemComponentGraph(props) {
2574
2696
  padding: 2,
2575
2697
  border: `1px solid ${theme.colors.border}`,
2576
2698
  borderRadius: 6,
2577
- }, children: [_jsxs("button", { type: "button", "aria-label": sidebarScope.trail ? 'Trail' : `Trails (${trailCount} ${trailCount === 1 ? 'trail' : 'trails'})`, "aria-pressed": !filesActive && !issuesActive, onClick: () => selectSidebarView('trails'), style: viewButtonStyle(!filesActive && !issuesActive), children: [_jsx(Route, { size: 14, "aria-hidden": true }), _jsx("span", { children: trailViewLabel }), !sidebarScope.trail && _jsx("span", { style: { fontWeight: 600, marginLeft: 4 }, children: trailCount })] }), hasFiles && (_jsxs("button", { type: "button", "aria-label": `Files (${fileCount} files)`, title: "Show files", "aria-pressed": filesActive, onClick: () => selectSidebarView('files'), style: viewButtonStyle(filesActive), children: [_jsx(Files, { size: 14, "aria-hidden": true }), _jsx("span", { children: "Files" }), _jsx("span", { style: { fontWeight: 600, marginLeft: 4 }, children: fileCount })] })), hasIssues && (_jsx(SubsystemDiagnosticToggle, { ...sidebarDiagnostic, labelText: "Issues", segmented: true, active: issuesActive, onToggle: () => selectSidebarView('issues') }))] }), props.headerActions] })), _jsx("div", { ref: wrapRef, style: { flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }, children: constructsOnly ? (_jsx(ConstructsCatalog, { components: props.components, onSelect: props.onSelect, title: props.title, hideSidebar: props.hideSidebar, description: props.description, descriptionOpen: props.descriptionOpen, onDescriptionOpenChange: props.onDescriptionOpenChange, diagnostic: props.diagnostic, sidebarExtra: props.headerActions ? _jsxs(_Fragment, { children: [props.headerActions, props.sidebarExtra] }) : props.sidebarExtra, sidebarAfterDescription: props.sidebarAfterDescription, renderFileViewer: props.renderFileViewer, onFileSelect: props.onFileSelect, componentVerification: props.componentVerification, onInspectSymbol: props.onInspectSymbol })) : (_jsx(ReactFlowProvider, { children: _jsx(Inner, { ...props, showIssues: issuesActive, filesActive: filesActive, measured: size, sidebarScope: sidebarScope, onSidebarTrailChange: setSidebarTrailId }) })) })] }));
2699
+ }, children: [containerCount > 0 && (_jsxs("button", { type: "button", "aria-label": `Containers (${containerCount} ${containerCount === 1 ? 'container' : 'containers'})`, title: "Show containers", "aria-pressed": containersActive, onClick: () => selectSidebarView('containers'), style: viewButtonStyle(containersActive), children: [_jsx(Boxes, { size: 14, "aria-hidden": true }), _jsx("span", { children: "Containers" }), _jsx("span", { style: { fontWeight: 600, marginLeft: 4 }, children: containerCount })] })), _jsxs("button", { type: "button", "aria-label": sidebarScope.trail ? 'Trail' : `Trails (${trailCount} ${trailCount === 1 ? 'trail' : 'trails'})`, "aria-pressed": !filesActive && !containersActive && !issuesActive, onClick: () => selectSidebarView('trails'), style: viewButtonStyle(!filesActive && !containersActive && !issuesActive), children: [_jsx(Route, { size: 14, "aria-hidden": true }), _jsx("span", { children: trailViewLabel }), !sidebarScope.trail && _jsx("span", { style: { fontWeight: 600, marginLeft: 4 }, children: trailCount })] }), hasFiles && (_jsxs("button", { type: "button", "aria-label": `Files (${fileCount} files)`, title: "Show files", "aria-pressed": filesActive, onClick: () => selectSidebarView('files'), style: viewButtonStyle(filesActive), children: [_jsx(Files, { size: 14, "aria-hidden": true }), _jsx("span", { children: "Files" }), _jsx("span", { style: { fontWeight: 600, marginLeft: 4 }, children: fileCount })] })), hasIssues && (_jsx(SubsystemDiagnosticToggle, { ...sidebarDiagnostic, labelText: "Issues", segmented: true, active: issuesActive, onToggle: () => selectSidebarView('issues') }))] }), props.headerActions] })), _jsx("div", { ref: wrapRef, style: { flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }, children: constructsOnly ? (_jsx(ConstructsCatalog, { components: props.components, onSelect: props.onSelect, title: props.title, hideSidebar: props.hideSidebar, description: props.description, descriptionOpen: props.descriptionOpen, onDescriptionOpenChange: props.onDescriptionOpenChange, diagnostic: props.diagnostic, sidebarExtra: props.headerActions ? _jsxs(_Fragment, { children: [props.headerActions, props.sidebarExtra] }) : props.sidebarExtra, sidebarAfterDescription: props.sidebarAfterDescription, renderFileViewer: props.renderFileViewer, onFileSelect: props.onFileSelect, componentVerification: props.componentVerification, onInspectSymbol: props.onInspectSymbol })) : (_jsx(ReactFlowProvider, { children: _jsx(Inner, { ...props, showIssues: issuesActive, filesActive: filesActive, containersActive: containersActive, measured: size, sidebarScope: sidebarScope, onSidebarTrailChange: setSidebarTrailId }) })) })] }));
2578
2700
  }
2579
2701
  //# sourceMappingURL=SubsystemComponentGraph.js.map