@principal-ai/subsystems-react 0.56.20 → 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 +27 -1
  18. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  19. package/dist/subsystem/SubsystemComponentGraph.js +147 -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 +232 -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, 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);
@@ -150,6 +162,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
150
162
  onLayoutReadyRef.current = onLayoutReady;
151
163
  const onNodeRectsRef = useRef(onNodeRects);
152
164
  onNodeRectsRef.current = onNodeRects;
165
+ const onAutoPlayStepRef = useRef(onAutoPlayStep);
166
+ onAutoPlayStepRef.current = onAutoPlayStep;
153
167
  useEffect(() => {
154
168
  if (layoutReady)
155
169
  onLayoutReadyRef.current?.();
@@ -193,6 +207,32 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
193
207
  /** Solo layout: only this trail's components and edges are laid out. */
194
208
  const [layoutTrailId, setLayoutTrailId] = useState(null);
195
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(',')}`;
196
236
  const changeLayoutDirection = useCallback((next) => {
197
237
  if (next === requestedDirection)
198
238
  return;
@@ -207,8 +247,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
207
247
  setLayoutTrailId(null);
208
248
  }
209
249
  }, [trails, layoutTrailId]);
210
- const requestedLayoutKey = `${requestedDirection}|${layoutTrailId ?? ''}`;
211
- const committedLayoutKey = `${committedDirection}|${committedTrailId ?? ''}`;
250
+ const requestedLayoutKey = `${requestedDirection}|${layoutTrailId ?? ''}|${collapsedKey}`;
251
+ const committedLayoutKey = `${committedDirection}|${committedTrailId ?? ''}|${committedCollapsedKey}`;
212
252
  // Beat 1: request → fade the edges out, then commit the direction / focus
213
253
  // (which re-runs ELK). Reduced-motion users get the new layout immediately.
214
254
  useEffect(() => {
@@ -233,6 +273,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
233
273
  if (reduceMotion) {
234
274
  setCommittedDirection(requestedDirection);
235
275
  setCommittedTrailId(layoutTrailId);
276
+ setCommittedCollapsed({ framesCollapsed, toggled: toggledGroupIds });
236
277
  return;
237
278
  }
238
279
  flipSawPendingLayoutRef.current = false;
@@ -241,6 +282,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
241
282
  flipFadeTimerRef.current = null;
242
283
  setCommittedDirection(requestedDirection);
243
284
  setCommittedTrailId(layoutTrailId);
285
+ setCommittedCollapsed({ framesCollapsed, toggled: toggledGroupIds });
244
286
  }, LAYOUT_FLIP_EDGE_MS);
245
287
  return () => {
246
288
  if (flipFadeTimerRef.current != null) {
@@ -254,6 +296,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
254
296
  refocusOnLayoutFlip,
255
297
  requestedDirection,
256
298
  layoutTrailId,
299
+ framesCollapsed,
300
+ toggledGroupIds,
257
301
  ]);
258
302
  // Beat 3: the committed layout has settled → the node slide is over, fade
259
303
  // the edges back in. The ref keeps the OLD `layoutReady` (still true until
@@ -296,6 +340,11 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
296
340
  return;
297
341
  writeViewState(persistKey, { layoutDirection: requestedDirection });
298
342
  }, [persistKey, requestedDirection]);
343
+ useEffect(() => {
344
+ if (!persistKey)
345
+ return;
346
+ writeViewState(persistKey, { framesCollapsed, toggledFrames: Array.from(toggledGroupIds) });
347
+ }, [persistKey, framesCollapsed, toggledGroupIds]);
299
348
  // Safety net: never leave the canvas edge-less if a layout pass stalls
300
349
  // (measurement never lands, ELK hangs). The edges come back; the layout
301
350
  // stays wherever it got to.
@@ -555,11 +604,13 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
555
604
  components: layoutDoc.components,
556
605
  trails: layoutDoc.trails,
557
606
  graphifyRelations: layoutRelations,
558
- }), [layoutDoc, layoutRelations]);
607
+ }) + `|collapsed:${committedCollapsedKey}`, [layoutDoc, layoutRelations, committedCollapsedKey]);
559
608
  const layoutDocRef = useRef(layoutDoc);
560
609
  const layoutRelationsRef = useRef(layoutRelations);
610
+ const committedCollapsedRef = useRef(committedCollapsed);
561
611
  layoutDocRef.current = layoutDoc;
562
612
  layoutRelationsRef.current = layoutRelations;
613
+ committedCollapsedRef.current = committedCollapsed;
563
614
  // Track measured dimensions from React Flow's dimension changes.
564
615
  // These arrive as { type: 'dimensions', id, dimensions } in onNodesChange.
565
616
  // Retained across same-id layoutKey updates so Pass 2 can run without a remount.
@@ -584,6 +635,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
584
635
  orderByLine,
585
636
  layoutDirection: committedDirection,
586
637
  codeProcessKeys,
638
+ regionDetails,
639
+ collapsedGroupIds: committedCollapsedRef.current.toggled,
640
+ cardFramesCollapsed: committedCollapsedRef.current.framesCollapsed,
587
641
  })
588
642
  .then(({ nodes, edges: e, absoluteRects }) => {
589
643
  if (!alive)
@@ -634,7 +688,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
634
688
  const measuredWidths = new Map(leafNodes.map((n) => [n.id, dims.get(n.id).width]));
635
689
  const measuredHeights = new Map(leafNodes.map((n) => [n.id, dims.get(n.id).height]));
636
690
  const gen = ++pass2GenRef.current;
637
- 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 })
638
692
  .then(({ nodes, edges: e, absoluteRects }) => {
639
693
  if (gen !== pass2GenRef.current)
640
694
  return;
@@ -648,7 +702,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
648
702
  // Reveal Pass 1 layout rather than leaving the cover up forever.
649
703
  setLayoutReady(true);
650
704
  });
651
- }, [built.nodes, layoutDoc, layoutRelations, orderByLine, maxNodeWidth, showEdgeLabels, moduleNesting, committedDirection]);
705
+ }, [built.nodes, layoutDoc, layoutRelations, orderByLine, maxNodeWidth, showEdgeLabels, moduleNesting, committedDirection, committedCollapsed]);
652
706
  // After Pass 1 commits, try Pass 2 immediately with retained measurements.
653
707
  // Same-id live updates often get no new React Flow `dimensions` events, so
654
708
  // waiting only on onNodesChange leaves the cover stuck.
@@ -1052,7 +1106,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1052
1106
  return null;
1053
1107
  const ids = new Set();
1054
1108
  for (const e of baseEdges) {
1055
- if (!edgeIds.has(e.id))
1109
+ if (!edgeMatches(edgeIds, e))
1056
1110
  continue;
1057
1111
  ids.add(e.source);
1058
1112
  ids.add(e.target);
@@ -1132,7 +1186,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1132
1186
  // visible, dimmed when members are dimmed. Never selectable.
1133
1187
  if (n.type === 'subsystem-group') {
1134
1188
  const region = n.data?.region;
1135
- 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 ?? [])];
1136
1192
  // `brightNodeIds` is the focused step's endpoints. It has to be a
1137
1193
  // spotlight member as well as a bright set: without an expanded flow
1138
1194
  // there is no opened set, so dimming has to be driven from the
@@ -1161,6 +1217,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1161
1217
  ...(color != null && { color }),
1162
1218
  ...(dimmed && { dimmed: true }),
1163
1219
  ...(regionIssue && { issue: regionIssue }),
1220
+ ...(region && isCardFrame(region) && { onToggleCollapse: () => toggleCollapsed(n.id) }),
1164
1221
  },
1165
1222
  };
1166
1223
  }
@@ -1200,7 +1257,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1200
1257
  },
1201
1258
  };
1202
1259
  });
1203
- }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors]);
1260
+ }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors, toggleCollapsed]);
1204
1261
  const baseNodesKey = useMemo(() => nodes.map((n) => n.id).sort().join(','), [nodes]);
1205
1262
  const baseEdgesKey = useMemo(() => convertedEdges.map((e) => e.id).sort().join(','), [convertedEdges]);
1206
1263
  const dispEdges = useMemo(() => {
@@ -1226,16 +1283,17 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1226
1283
  }
1227
1284
  return isTrailMechanism(mechanism);
1228
1285
  };
1286
+ const inSet = (set, e) => set != null && edgeMatches(set, e);
1229
1287
  if (openedEdgeIds || focusEdgeIds || previewEdgeIds || issueFocusEdgeIds) {
1230
1288
  return baseEdges.map((e) => {
1231
1289
  const vis = flowElementVisibility({
1232
- inOpened: openedEdgeIds?.has(e.id) === true,
1233
- inSelected: focusEdgeIds?.has(e.id) === true,
1290
+ inOpened: inSet(openedEdgeIds, e),
1291
+ inSelected: inSet(focusEdgeIds, e),
1234
1292
  anyOpened: openedEdgeIds != null,
1235
1293
  anySelected: focusEdgeIds != null,
1236
1294
  });
1237
1295
  const dimSource = previewEdgeIds ?? issueFocusEdgeIds;
1238
- const dimmed = dimSource ? vis.hidden || !dimSource.has(e.id) : vis.dimmed;
1296
+ const dimmed = dimSource ? vis.hidden || !inSet(dimSource, e) : vis.dimmed;
1239
1297
  const hidden = vis.hidden || !edgeInView(e);
1240
1298
  return { ...paint(e, dimmed), hidden };
1241
1299
  });
@@ -1353,7 +1411,14 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1353
1411
  // Boundary frame → frame its members on the canvas; double-click again to
1354
1412
  // zoom back out. User-initiated, so it ignores the trail zoom gate.
1355
1413
  if (node.type === 'subsystem-group') {
1356
- 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;
1357
1422
  if (!key)
1358
1423
  return;
1359
1424
  if (focusedBoundaryKey === key) {
@@ -1434,7 +1499,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1434
1499
  const nodeIds = new Set();
1435
1500
  const points = [];
1436
1501
  for (const e of baseEdges) {
1437
- if (!ids.has(e.id))
1502
+ if (!edgeMatches(ids, e))
1438
1503
  continue;
1439
1504
  nodeIds.add(e.source);
1440
1505
  nodeIds.add(e.target);
@@ -1534,6 +1599,54 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1534
1599
  height: Math.max(1, maxY - minY),
1535
1600
  }, { padding, duration: trailFocusDurationMs });
1536
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]);
1537
1650
  // Zoom back out to the full diagram after the last expanded trail
1538
1651
  // closes (visibility restores non-flow nodes that were hidden).
1539
1652
  const fitOverview = useCallback(() => {
@@ -1792,6 +1905,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1792
1905
  setFocusedStepIndex(null);
1793
1906
  setHoveredTrailStep({ trailId: tl.id, stepIndex: stepIdx });
1794
1907
  }
1908
+ onAutoPlayStepRef.current?.({ trailId: tl.id, stepIndex: stepIdx });
1795
1909
  stepIdx += 1;
1796
1910
  if (stepIdx >= tl.steps.length) {
1797
1911
  stepIdx = 0;
@@ -1808,6 +1922,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1808
1922
  setFocusedTrailId(null);
1809
1923
  setFocusedStepIndex(null);
1810
1924
  setAutoPlayFocus(null);
1925
+ onAutoPlayStepRef.current?.(null);
1811
1926
  };
1812
1927
  return cleanup;
1813
1928
  }, [
@@ -2078,7 +2193,12 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2078
2193
  midX: d?.labelX ?? 0,
2079
2194
  midY: d?.labelY ?? 0,
2080
2195
  pathLength: d?.pathLength ?? 0,
2081
- 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,
2082
2202
  stepIssue,
2083
2203
  };
2084
2204
  });
@@ -2099,9 +2219,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2099
2219
  // trail, diagnostics tab) because the canvas dims from
2100
2220
  // the same facts the sidebar renders.
2101
2221
  const sidebarVisible = !hideSidebar &&
2102
- (description || filesActive || issuesActive || sidebarExtra || sidebarAfterDescription ||
2222
+ (description || filesActive || containersActive || issuesActive || sidebarExtra || sidebarAfterDescription ||
2103
2223
  hasTrails);
2104
- const sidebarBodyVisible = hasTrails || filesActive || issuesActive;
2224
+ const sidebarBodyVisible = hasTrails || filesActive || containersActive || issuesActive;
2105
2225
  const sidebarTabs = issuesActive && !sidebarTrail
2106
2226
  ? agentsPanel
2107
2227
  ? [
@@ -2129,7 +2249,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2129
2249
  cursor: 'pointer',
2130
2250
  }, children: "More" })] })), sidebarAfterDescription] }));
2131
2251
  // Lower panel: diagnostics, the file tree, or the trail flow list.
2132
- 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) => {
2133
2253
  const file = treePaths.toFile.get(path);
2134
2254
  if (file)
2135
2255
  onOpenDeclarationFile(file);
@@ -2465,6 +2585,10 @@ export function SubsystemComponentGraph(props) {
2465
2585
  });
2466
2586
  const sidebarScope = useMemo(() => buildTrailSidebarScope(props.components, props.trails, props.issues, sidebarTrailId), [props.components, props.trails, props.issues, sidebarTrailId]);
2467
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);
2468
2592
  const trailViewLabel = sidebarScope.trail ? 'Trail' : 'Trails';
2469
2593
  const trailCount = props.trails?.length ?? 0;
2470
2594
  const hasFiles = fileCount > 0 || sidebarScope.trail != null;
@@ -2487,9 +2611,11 @@ export function SubsystemComponentGraph(props) {
2487
2611
  const issuesRequested = props.showIssues ?? diagnosticsOpen;
2488
2612
  const issuesActive = hasIssues && issuesRequested;
2489
2613
  const filesActive = filesOpen && hasFiles && !issuesActive;
2614
+ const containersActive = containersOpen && containerCount > 0 && !issuesActive && !filesActive;
2490
2615
  const selectSidebarView = (view) => {
2491
2616
  const nextIssuesActive = view === 'issues';
2492
2617
  setFilesOpen(view === 'files');
2618
+ setContainersOpen(view === 'containers');
2493
2619
  if (nextIssuesActive !== issuesRequested) {
2494
2620
  if (props.showIssues === undefined)
2495
2621
  setDiagnosticsOpen(nextIssuesActive);
@@ -2570,6 +2696,6 @@ export function SubsystemComponentGraph(props) {
2570
2696
  padding: 2,
2571
2697
  border: `1px solid ${theme.colors.border}`,
2572
2698
  borderRadius: 6,
2573
- }, 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 }) })) })] }));
2574
2700
  }
2575
2701
  //# sourceMappingURL=SubsystemComponentGraph.js.map