@principal-ai/subsystems-react 0.56.15 → 0.56.17

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 (62) hide show
  1. package/dist/index.d.ts +4 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/pierre/PierreFileView.d.ts.map +1 -1
  6. package/dist/pierre/PierreFileView.js +7 -5
  7. package/dist/pierre/PierreFileView.js.map +1 -1
  8. package/dist/pierre/PierreSnippetView.d.ts.map +1 -1
  9. package/dist/pierre/PierreSnippetView.js +4 -2
  10. package/dist/pierre/PierreSnippetView.js.map +1 -1
  11. package/dist/pierre/PierreTrailCodeView.d.ts.map +1 -1
  12. package/dist/pierre/PierreTrailCodeView.js +4 -1
  13. package/dist/pierre/PierreTrailCodeView.js.map +1 -1
  14. package/dist/pierre/pierreBackground.d.ts +12 -0
  15. package/dist/pierre/pierreBackground.d.ts.map +1 -1
  16. package/dist/pierre/pierreBackground.js +12 -0
  17. package/dist/pierre/pierreBackground.js.map +1 -1
  18. package/dist/subsystem/C4Graph.d.ts +17 -0
  19. package/dist/subsystem/C4Graph.d.ts.map +1 -1
  20. package/dist/subsystem/C4Graph.js +128 -61
  21. package/dist/subsystem/C4Graph.js.map +1 -1
  22. package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
  23. package/dist/subsystem/C4NodeCard.js +7 -2
  24. package/dist/subsystem/C4NodeCard.js.map +1 -1
  25. package/dist/subsystem/DecorationPanel.d.ts +32 -3
  26. package/dist/subsystem/DecorationPanel.d.ts.map +1 -1
  27. package/dist/subsystem/DecorationPanel.js +162 -89
  28. package/dist/subsystem/DecorationPanel.js.map +1 -1
  29. package/dist/subsystem/SubsystemComponentGraph.d.ts +2 -0
  30. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  31. package/dist/subsystem/SubsystemComponentGraph.js +1 -1
  32. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  33. package/dist/subsystem/c4.d.ts +2 -0
  34. package/dist/subsystem/c4.d.ts.map +1 -1
  35. package/dist/subsystem/c4.js.map +1 -1
  36. package/dist/subsystem/decoration.d.ts +19 -0
  37. package/dist/subsystem/decoration.d.ts.map +1 -1
  38. package/dist/subsystem/decoration.js.map +1 -1
  39. package/dist/subsystem/decorationC4.d.ts +9 -0
  40. package/dist/subsystem/decorationC4.d.ts.map +1 -0
  41. package/dist/subsystem/decorationC4.js +55 -0
  42. package/dist/subsystem/decorationC4.js.map +1 -0
  43. package/package.json +3 -3
  44. package/src/index.ts +6 -1
  45. package/src/pierre/PierreFileView.tsx +13 -5
  46. package/src/pierre/PierreSnippetView.tsx +10 -2
  47. package/src/pierre/PierreTrailCodeView.tsx +8 -4
  48. package/src/pierre/pierreBackground.ts +14 -0
  49. package/src/stories/Components/DecorationPanel.stories.tsx +344 -36
  50. package/src/stories/Pierre/CodeView.stories.tsx +4 -2
  51. package/src/subsystem/C4Graph.groups.test.ts +46 -0
  52. package/src/subsystem/C4Graph.tsx +96 -16
  53. package/src/subsystem/C4NodeCard.test.ts +35 -1
  54. package/src/subsystem/C4NodeCard.tsx +7 -2
  55. package/src/subsystem/DecorationPanel.test.tsx +228 -4
  56. package/src/subsystem/DecorationPanel.tsx +248 -82
  57. package/src/subsystem/SubsystemComponentGraph.sidebar.test.tsx +11 -0
  58. package/src/subsystem/SubsystemComponentGraph.tsx +4 -1
  59. package/src/subsystem/c4.ts +2 -0
  60. package/src/subsystem/decoration.ts +25 -0
  61. package/src/subsystem/decorationC4.test.ts +134 -0
  62. package/src/subsystem/decorationC4.ts +60 -0
@@ -95,6 +95,17 @@ export interface C4ConstructGraph {
95
95
 
96
96
  export interface C4GraphProps {
97
97
  model: C4Model;
98
+ /**
99
+ * Camera focus request. Components resolve to their containers; external
100
+ * endpoints are framed directly. Use `ids` for both ends of a relationship.
101
+ * The host opens the containers; this graph waits for their layout/morph.
102
+ * Pass a new object to refocus, or null for the overview. Omit for default camera policy.
103
+ */
104
+ containerFocus?: { id: string } | { ids: readonly string[] } | null;
105
+ /** Controlled element selection, independent of the camera target. Omit for local selection. */
106
+ selectedNodeId?: string | null;
107
+ /** Controlled relationship selection. Omit for local selection. */
108
+ selectedEdgeId?: string | null;
98
109
  onSelectNode?: (id: string | null) => void;
99
110
  /**
100
111
  * Click an edge. Fires with the rolled-up line (and its `trailRefs`
@@ -356,6 +367,24 @@ function C4EdgeLabels({
356
367
  zIndex: 5,
357
368
  }}
358
369
  >
370
+ <style>{`
371
+ @keyframes subsystem-c4-edge-label-pulse {
372
+ 0%, 100% { opacity: 0.2; }
373
+ 50% { opacity: 1; }
374
+ }
375
+ .subsystem-c4-edge-label-selected {
376
+ box-shadow:
377
+ 0 0 12px color-mix(in srgb, currentColor 65%, transparent),
378
+ 0 0 22px color-mix(in srgb, currentColor 25%, transparent);
379
+ opacity: 0.6;
380
+ animation: subsystem-c4-edge-label-pulse 2200ms ease-in-out infinite;
381
+ }
382
+ @media (prefers-reduced-motion: reduce) {
383
+ .subsystem-c4-edge-label-selected {
384
+ animation: none;
385
+ }
386
+ }
387
+ `}</style>
359
388
  {[...positions].map(([id, p]) => {
360
389
  const edge = byId.get(id);
361
390
  if (!edge) return null;
@@ -385,16 +414,22 @@ function C4EdgeLabels({
385
414
  transition: 'opacity 220ms ease',
386
415
  }}
387
416
  >
417
+ {selected && (
418
+ <span
419
+ aria-hidden
420
+ className="subsystem-c4-edge-label-selected"
421
+ style={{ position: 'absolute', inset: 0, borderRadius: 4, color }}
422
+ />
423
+ )}
388
424
  <span
389
425
  aria-hidden
390
426
  style={{
391
427
  position: 'absolute',
392
428
  inset: 0,
393
429
  borderRadius: 4,
394
- border: `0.5px solid ${color}`,
430
+ border: `${selected ? 2 : edge.draft ? 1 : 0.5}px ${edge.draft ? 'dashed' : 'solid'} ${color}`,
395
431
  background: surface,
396
- // The selected chip echoes the edge's heavier stroke.
397
- outline: selected ? `1.5px solid ${color}` : 'none',
432
+ color,
398
433
  }}
399
434
  />
400
435
  <span
@@ -798,6 +833,29 @@ const FADE_MS = 200;
798
833
  */
799
834
  const CAMERA_AFTER_MORPH_MS = FADE_MS + MORPH_MS + 60;
800
835
 
836
+ /** Containers frame their contents; an overview also includes outside actors/systems. */
837
+ export function c4CameraNodeIds(model: C4Model, targetIds?: string | readonly string[] | null): string[] {
838
+ const requested = typeof targetIds === 'string' ? [targetIds] : targetIds ?? [];
839
+ const byId = new Map(model.nodes.map((node) => [node.id, node]));
840
+ const targets = new Set<string>();
841
+ for (const id of requested) {
842
+ const node = byId.get(id);
843
+ if (!node) continue;
844
+ if (node.kind === 'component') {
845
+ if (byId.get(node.container)?.kind === 'container') targets.add(node.container);
846
+ } else {
847
+ targets.add(node.id);
848
+ }
849
+ }
850
+ if (targets.size > 0) return [...targets];
851
+ return [
852
+ model.system.id,
853
+ ...model.nodes
854
+ .filter((node) => node.kind === 'external-system' || node.kind === 'person')
855
+ .map((node) => node.id),
856
+ ];
857
+ }
858
+
801
859
  /** A fully laid-out open state: the RF nodes/edges and label anchors. */
802
860
  interface Rendered {
803
861
  nodes: Node[];
@@ -1112,7 +1170,7 @@ export function hidesComponentDuringMorph(
1112
1170
  return morphTargets.has(owner);
1113
1171
  }
1114
1172
 
1115
- function Inner({ model, onSelectNode, onSelectEdge, onTrailClick, onToggleContainer, onOpenContainer, onCloseContainer, gutter = 28, dimmedElementIds, dimmedEdgeIds, hiddenElementIds, hiddenEdgeIds, dimmedConstructIds, dimmedConstructEdgeIds, constructGraphByContainer, focusedStep, onCloseStep, renderFileViewer, renderTrailViewer, hideDrawer = false }: C4GraphProps) {
1173
+ function Inner({ model, containerFocus, selectedNodeId, selectedEdgeId: controlledSelectedEdgeId, onSelectNode, onSelectEdge, onTrailClick, onToggleContainer, onOpenContainer, onCloseContainer, gutter = 28, dimmedElementIds, dimmedEdgeIds, hiddenElementIds, hiddenEdgeIds, dimmedConstructIds, dimmedConstructEdgeIds, constructGraphByContainer, focusedStep, onCloseStep, renderFileViewer, renderTrailViewer, hideDrawer = false }: C4GraphProps) {
1116
1174
  const { theme, mode } = useTheme();
1117
1175
  const { fitView, fitBounds } = useReactFlow();
1118
1176
  const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
@@ -1121,14 +1179,29 @@ function Inner({ model, onSelectNode, onSelectEdge, onTrailClick, onToggleContai
1121
1179
  * every layout change. */
1122
1180
  const nodesRef = useRef<Node[]>([]);
1123
1181
  nodesRef.current = nodes;
1182
+ // Post-morph timers must use the latest request, not the selection that armed them.
1183
+ const containerFocusRef = useRef(containerFocus);
1184
+ containerFocusRef.current = containerFocus;
1124
1185
  const [rfEdges, setRfEdges] = useState<Edge[]>([]);
1125
1186
  const [ready, setReady] = useState(false);
1126
- const [selectedId, setSelectedId] = useState<string | null>(null);
1127
- const [selectedEdgeId, setSelectedEdgeId] = useState<string | null>(null);
1187
+ const [localSelectedId, setSelectedId] = useState<string | null>(null);
1188
+ const selectedId = selectedNodeId === undefined ? localSelectedId : selectedNodeId;
1189
+ const [localSelectedEdgeId, setSelectedEdgeId] = useState<string | null>(null);
1190
+ const selectedEdgeId = controlledSelectedEdgeId === undefined ? localSelectedEdgeId : controlledSelectedEdgeId;
1128
1191
  // The construct (subsystem component alias) whose functionality (declaration
1129
1192
  // + purpose) is open. Its own panel, so opening a construct never disturbs the
1130
1193
  // node/edge inspector.
1131
1194
  const [selectedConstructAlias, setSelectedConstructAlias] = useState<string | null>(null);
1195
+ useEffect(() => {
1196
+ if (!selectedNodeId) return;
1197
+ setSelectedEdgeId(null);
1198
+ setSelectedConstructAlias(null);
1199
+ }, [selectedNodeId]);
1200
+ useEffect(() => {
1201
+ if (!controlledSelectedEdgeId) return;
1202
+ setSelectedId(null);
1203
+ setSelectedConstructAlias(null);
1204
+ }, [controlledSelectedEdgeId]);
1132
1205
  const [labelPositions, setLabelPositions] = useState<Map<string, { x: number; y: number }>>(
1133
1206
  () => new Map(),
1134
1207
  );
@@ -1217,8 +1290,7 @@ function Inner({ model, onSelectNode, onSelectEdge, onTrailClick, onToggleContai
1217
1290
  const morphTargetsRef = useRef<Set<string>>(new Set());
1218
1291
 
1219
1292
  /**
1220
- * Frame the whole diagram: the system boundary *and* everything drawn outside
1221
- * it.
1293
+ * Frame the requested endpoint containers, or the system and everything outside it.
1222
1294
  *
1223
1295
  * Named explicitly rather than left to the drawn nodes, because on a drill-down
1224
1296
  * those include the opened container's components — fitting all of them would
@@ -1227,15 +1299,14 @@ function Inner({ model, onSelectNode, onSelectEdge, onTrailClick, onToggleContai
1227
1299
  * it by definition, so fitting the frame alone crops exactly the things the
1228
1300
  * boundary is drawn in contrast to.
1229
1301
  */
1230
- const fitSystem = useCallback(() => {
1231
- const outside = model.nodes
1232
- .filter((n) => n.kind === 'external-system' || n.kind === 'person')
1233
- .map((n) => ({ id: n.id }));
1302
+ const fitCamera = useCallback(() => {
1303
+ const focus = containerFocusRef.current;
1304
+ const targets = focus ? ('ids' in focus ? focus.ids : focus.id) : null;
1234
1305
  fitView({
1235
1306
  padding: 0.15,
1236
1307
  duration: CAMERA_MS,
1237
1308
  maxZoom: 1,
1238
- nodes: [{ id: model.system.id }, ...outside],
1309
+ nodes: c4CameraNodeIds(model, targets).map((id) => ({ id })),
1239
1310
  });
1240
1311
  }, [fitView, model.system.id, model.nodes]);
1241
1312
 
@@ -1264,8 +1335,8 @@ function Inner({ model, onSelectNode, onSelectEdge, onTrailClick, onToggleContai
1264
1335
  useEffect(() => {
1265
1336
  if (!ready || !pendingFitRef.current) return;
1266
1337
  pendingFitRef.current = false;
1267
- fitSystem();
1268
- }, [ready, fitSystem]);
1338
+ fitCamera();
1339
+ }, [ready, fitCamera]);
1269
1340
 
1270
1341
  /** Called once the new layout is committed, from the layout effect. */
1271
1342
  const afterLayout = (grows: Map<string, FrameGrow> | null) => {
@@ -1719,7 +1790,7 @@ function Inner({ model, onSelectNode, onSelectEdge, onTrailClick, onToggleContai
1719
1790
  // instead of the one the FLIP specified (see `shouldRefitCamera`). Waiting
1720
1791
  // out the morph is the honest way to get both.
1721
1792
  if (cameraTimer.current) clearTimeout(cameraTimer.current);
1722
- cameraTimer.current = setTimeout(fitSystem, CAMERA_AFTER_MORPH_MS);
1793
+ cameraTimer.current = setTimeout(fitCamera, CAMERA_AFTER_MORPH_MS);
1723
1794
  } else {
1724
1795
  morphTargetsRef.current = new Set();
1725
1796
  }
@@ -1877,6 +1948,15 @@ function Inner({ model, onSelectNode, onSelectEdge, onTrailClick, onToggleContai
1877
1948
  // eslint-disable-next-line react-hooks/exhaustive-deps
1878
1949
  }, [layoutKey]);
1879
1950
 
1951
+ // A panel click can request a new camera fit without changing the layout.
1952
+ // Wait for the latest layout and its resize animation before measuring the container.
1953
+ useEffect(() => {
1954
+ if (containerFocus === undefined || !ready || !settled) return;
1955
+ if (prevCacheKeyRef.current !== currentCacheKeyRef.current) return;
1956
+ const timer = setTimeout(fitCamera, 60);
1957
+ return () => clearTimeout(timer);
1958
+ }, [containerFocus, ready, settled, nodes, fitCamera]);
1959
+
1880
1960
  // Remember this render's dim set for the *next* commit's leavers. Declared
1881
1961
  // after the layout effect so it runs after it: the layout effect reads the
1882
1962
  // value the previous render left here (a hover dim), before this overwrites
@@ -44,9 +44,26 @@ function node(over: Partial<C4Container> = {}): C4Element {
44
44
  }
45
45
 
46
46
  describe('nodeStyle — one axis per channel', () => {
47
- test('selected overrides everything', () => {
47
+ test('selected highlights the border colour and weight', () => {
48
48
  expect(nodeStyle(node({ state: 'accepted' }), theme, true).width).toBe(3);
49
49
  expect(nodeStyle(node({ state: 'accepted' }), theme, true).dash).toBe('solid');
50
+ expect(nodeStyle(node({ state: 'accepted', technology: 'React' }), theme, true).color)
51
+ .toBe(theme.colors.accent);
52
+ });
53
+
54
+ test('selected draft elements keep their dashed border', () => {
55
+ expect(nodeStyle(node({ state: 'proposed' }), theme, true)).toEqual({
56
+ color: theme.colors.accent,
57
+ dash: 'dashed',
58
+ width: 3,
59
+ });
60
+ });
61
+
62
+ test('selected uses the same accent fallback as the decoration panel', () => {
63
+ const primaryOnly = { colors: { primary: '#123456' } } as Parameters<typeof nodeStyle>[1];
64
+ const textOnly = { colors: { text: '#abcdef' } } as Parameters<typeof nodeStyle>[1];
65
+ expect(nodeStyle(node(), primaryOnly, true).color).toBe('#123456');
66
+ expect(nodeStyle(node(), textOnly, true).color).toBe('#abcdef');
50
67
  });
51
68
 
52
69
  test('accepted is solid', () => {
@@ -98,6 +115,23 @@ describe('nodeStyle — one axis per channel', () => {
98
115
  expect(nodeStyle(node({ kind: 'component', state: 'accepted' }), theme).width).toBe(1);
99
116
  });
100
117
 
118
+ test('unselected components use primary without changing their draft/accepted encoding', () => {
119
+ for (const state of ['accepted', 'proposed'] as const) {
120
+ const component = node({ kind: 'component', technology: 'React', state });
121
+ expect(nodeStyle(component, theme)).toEqual({
122
+ color: theme.colors.primary,
123
+ dash: state === 'proposed' ? 'dashed' : 'solid',
124
+ width: 1,
125
+ });
126
+ expect(nodeStyle(component, theme, true).color).toBe(theme.colors.accent);
127
+ }
128
+ });
129
+
130
+ test('components fall back to the border color when primary is absent', () => {
131
+ const borderOnly = { colors: { border: '#555' } } as Parameters<typeof nodeStyle>[1];
132
+ expect(nodeStyle(node({ kind: 'component' }), borderOnly).color).toBe('#555');
133
+ });
134
+
101
135
  test('falls back safely when the theme has no colour', () => {
102
136
  const bare = { colors: {} } as Parameters<typeof nodeStyle>[1];
103
137
  expect(() => nodeStyle(node({ state: 'accepted' }), bare)).not.toThrow();
@@ -245,12 +245,17 @@ export function nodeTechnology(node: C4Element): string | undefined {
245
245
  export function nodeStyle(node: C4Element, theme: Theme, selected = false): NodeStyle {
246
246
  const muted = theme.colors.border ?? '#555';
247
247
  const techColor = technologyBrand(nodeTechnology(node))?.color;
248
- if (selected) return { color: theme.colors.primary ?? '#5aa', dash: 'solid', width: 3 };
248
+ if (selected) return {
249
+ color: theme.colors.accent ?? theme.colors.primary ?? theme.colors.text ?? '#5aa',
250
+ dash: node.state === 'proposed' ? 'dashed' : node.state === 'rejected' ? 'dotted' : 'solid',
251
+ width: 3,
252
+ };
249
253
 
250
254
  // Border weight carries the level, so a component stays a component even
251
255
  // in grayscale or for a reader who cannot separate the hues.
252
256
  const weight = node.kind === 'component' ? 1 : 2;
253
- const color = techColor ?? muted;
257
+ // Components use primary for contrast; containers retain their technology hue.
258
+ const color = node.kind === 'component' ? (theme.colors.primary ?? muted) : (techColor ?? muted);
254
259
 
255
260
  switch (node.state) {
256
261
  case 'accepted':
@@ -1,8 +1,8 @@
1
1
  import { afterEach, describe, expect, mock, test } from 'bun:test';
2
2
  import { Window } from 'happy-dom';
3
- import { cleanup, fireEvent, render } from '@testing-library/react/pure';
3
+ import { cleanup, fireEvent, render, within } from '@testing-library/react/pure';
4
4
  import { ThemeProvider, defaultEditorTheme } from '@principal-ade/industry-theme';
5
- import { DecorationPanel, type DecorationPanelProps } from './DecorationPanel';
5
+ import { DecorationHeader, DecorationPanel, type DecorationPanelProps } from './DecorationPanel';
6
6
  import { decorationTrailKey, type SubsystemDecoration } from './decoration';
7
7
 
8
8
  // Same DOM shim as TrailsPanel.test: happy-dom lacks ResizeObserver, which
@@ -85,9 +85,9 @@ function renderPanel(overrides: Partial<DecorationPanelProps> = {}) {
85
85
 
86
86
  describe('DecorationPanel', () => {
87
87
  test('renders the description, grouped trails, and draft structure', () => {
88
- const { getByText, container } = renderPanel();
88
+ const { getByText, getAllByText, container } = renderPanel();
89
89
  expect(container.textContent).toContain('reading path');
90
- expect(getByText('desktop-app')).not.toBeNull();
90
+ expect(getAllByText('desktop-app')).toHaveLength(2);
91
91
  expect(getByText('sync-service')).not.toBeNull();
92
92
  expect(getByText('Save drawing')).not.toBeNull();
93
93
  expect(getByText('Persist file')).not.toBeNull();
@@ -97,6 +97,47 @@ describe('DecorationPanel', () => {
97
97
  expect(getByText('+ 1 draft edge')).not.toBeNull();
98
98
  });
99
99
 
100
+ test('shows proposed flows and draft structure before context trails', () => {
101
+ const onSelectTrail = mock(() => {});
102
+ const { getByRole, container } = renderPanel({ onSelectTrail });
103
+ const proposed = getByRole('region', { name: 'Proposed flows' });
104
+ const context = getByRole('region', { name: 'Context trails' });
105
+ expect(within(proposed).getByText('Proposed flows · 1')).not.toBeNull();
106
+ expect(within(proposed).getByText('Planned sync')).not.toBeNull();
107
+ expect(within(proposed).queryByText('Save drawing')).toBeNull();
108
+ expect(within(context).getByText('Context trails · 2')).not.toBeNull();
109
+ expect(within(context).getByText('Save drawing')).not.toBeNull();
110
+ expect(within(context).getByText('Persist file')).not.toBeNull();
111
+ expect(within(context).queryByText('Planned sync')).toBeNull();
112
+ const text = container.textContent!;
113
+ expect(text.indexOf('Proposed flows')).toBeLessThan(text.indexOf('Draft structure'));
114
+ expect(text.indexOf('Draft structure')).toBeLessThan(text.indexOf('Context trails'));
115
+ fireEvent.click(within(proposed).getByText('Planned sync'));
116
+ expect(onSelectTrail).toHaveBeenCalledWith(decoration.trails[2]);
117
+ });
118
+
119
+ test('omits the proposed section for a context-only decoration', () => {
120
+ const { queryByRole, getByRole } = renderPanel({
121
+ decoration: { ...decoration, trails: decoration.trails.filter((ref) => ref.kind === 'base') },
122
+ });
123
+ expect(queryByRole('region', { name: 'Proposed flows' })).toBeNull();
124
+ expect(getByRole('region', { name: 'Context trails' })).not.toBeNull();
125
+ });
126
+
127
+ test('omits the context section for a draft-only decoration', () => {
128
+ const { queryByRole, getByRole } = renderPanel({
129
+ decoration: { ...decoration, trails: decoration.trails.filter((ref) => ref.kind === 'draft') },
130
+ });
131
+ expect(getByRole('region', { name: 'Proposed flows' })).not.toBeNull();
132
+ expect(queryByRole('region', { name: 'Context trails' })).toBeNull();
133
+ });
134
+
135
+ test('omits both trail sections when there are no trails', () => {
136
+ const { queryByRole } = renderPanel({ decoration: { ...decoration, trails: [] } });
137
+ expect(queryByRole('region', { name: 'Proposed flows' })).toBeNull();
138
+ expect(queryByRole('region', { name: 'Context trails' })).toBeNull();
139
+ });
140
+
100
141
  test('the toggle reports the next active state', () => {
101
142
  const onToggleActive = mock(() => {});
102
143
  const { getByLabelText } = renderPanel({ onToggleActive });
@@ -104,6 +145,31 @@ describe('DecorationPanel', () => {
104
145
  expect(onToggleActive).toHaveBeenCalledWith(false);
105
146
  });
106
147
 
148
+ test('can omit the panel header when the host provides a full-width header', () => {
149
+ const { queryByRole, queryByLabelText, getByText } = renderPanel({ hideHeader: true });
150
+ expect(queryByRole('heading', { name: decoration.title })).toBeNull();
151
+ expect(queryByLabelText('Turn decoration off')).toBeNull();
152
+ expect(getByText('Save drawing')).not.toBeNull();
153
+ });
154
+
155
+ test('the standalone header renders actions and toggles the decoration', () => {
156
+ const onToggleActive = mock(() => {});
157
+ const { getByRole, getByLabelText, getByText } = render(
158
+ <ThemeProvider theme={defaultEditorTheme}>
159
+ <DecorationHeader
160
+ decoration={decoration}
161
+ active={false}
162
+ onToggleActive={onToggleActive}
163
+ actions={<span>Base architecture only</span>}
164
+ />
165
+ </ThemeProvider>,
166
+ );
167
+ expect(getByRole('heading', { name: decoration.title })).not.toBeNull();
168
+ expect(getByText('Base architecture only')).not.toBeNull();
169
+ fireEvent.click(getByLabelText('Turn decoration on'));
170
+ expect(onToggleActive).toHaveBeenCalledWith(true);
171
+ });
172
+
107
173
  test('selecting a trail hands the ref back to the host', () => {
108
174
  const onSelectTrail = mock(() => {});
109
175
  const { getByText } = renderPanel({ onSelectTrail });
@@ -125,4 +191,162 @@ describe('DecorationPanel', () => {
125
191
  construct: 'class',
126
192
  });
127
193
  });
194
+
195
+ test('styles the selected class or C4 row and clears the previous selection', () => {
196
+ const withC4: SubsystemDecoration = {
197
+ ...decoration,
198
+ draft: {
199
+ ...decoration.draft,
200
+ c4: {
201
+ elements: [{
202
+ kind: 'component', id: 'component:sync', label: 'Sync coordinator',
203
+ container: 'container:desktop', technology: 'TypeScript', members: ['sync-agent'],
204
+ }],
205
+ },
206
+ },
207
+ };
208
+ const panel = (selectedDraftItem: DecorationPanelProps['selectedDraftItem']) => (
209
+ <ThemeProvider theme={defaultEditorTheme}>
210
+ <DecorationPanel
211
+ decoration={withC4}
212
+ active
213
+ onToggleActive={() => {}}
214
+ selectedDraftItem={selectedDraftItem}
215
+ />
216
+ </ThemeProvider>
217
+ );
218
+ const { getByText, container, rerender } = render(panel(null));
219
+ const classRow = getByText('SyncAgent').closest('button')!;
220
+ const c4Row = getByText('Sync coordinator').closest('button')!;
221
+ expect(container.querySelectorAll('[aria-current="true"]')).toHaveLength(0);
222
+
223
+ rerender(panel({ kind: 'component', alias: 'sync-agent' }));
224
+ expect(classRow.getAttribute('aria-current')).toBe('true');
225
+ expect(classRow.style.background).not.toBe('');
226
+ expect(classRow.style.boxShadow).toBe('');
227
+ expect(classRow.classList.contains('subsystem-decoration-draft-row')).toBe(true);
228
+ expect(c4Row.getAttribute('aria-current')).toBeNull();
229
+
230
+ rerender(panel({ kind: 'c4', id: 'component:sync' }));
231
+ expect(c4Row.getAttribute('aria-current')).toBe('true');
232
+ expect(c4Row.style.background).not.toBe('');
233
+ expect(c4Row.style.boxShadow).toBe('');
234
+ expect(c4Row.classList.contains('subsystem-decoration-draft-row')).toBe(true);
235
+ expect(classRow.getAttribute('aria-current')).toBeNull();
236
+ expect(classRow.style.background).toBe('');
237
+ expect(container.querySelectorAll('[aria-current="true"]')).toHaveLength(1);
238
+
239
+ rerender(panel(null));
240
+ expect(container.querySelectorAll('[aria-current="true"]')).toHaveLength(0);
241
+ expect(c4Row.style.background).toBe('');
242
+ });
243
+
244
+ test('renders and selects C4-only draft structure', () => {
245
+ const element = {
246
+ kind: 'container' as const, id: 'container:worker', label: 'Background sync',
247
+ containerKind: 'application' as const, technology: 'Bun', process: 'sync-worker',
248
+ };
249
+ const onSelectDraftC4Element = mock(() => {});
250
+ const { getByText, getByRole } = renderPanel({
251
+ decoration: {
252
+ ...decoration,
253
+ draft: {
254
+ c4: {
255
+ elements: [element],
256
+ edges: [{
257
+ id: 'draft:dispatch', source: 'container:desktop', target: element.id,
258
+ label: 'Dispatches upload', mechanisms: ['calls'], count: 1,
259
+ }],
260
+ },
261
+ },
262
+ },
263
+ onSelectDraftC4Element,
264
+ });
265
+ expect(getByText('Draft structure · not verified')).not.toBeNull();
266
+ expect(getByText('C4 container')).not.toBeNull();
267
+ const relationships = getByRole('list', { name: 'Draft C4 relationships' });
268
+ expect(within(relationships).getAllByRole('listitem')).toHaveLength(1);
269
+ expect(within(relationships).getByText('Dispatches upload')).not.toBeNull();
270
+ expect(within(relationships).getByText('container:desktop → Background sync')).not.toBeNull();
271
+ fireEvent.click(getByText('Background sync'));
272
+ expect(onSelectDraftC4Element).toHaveBeenCalledWith(element);
273
+ });
274
+
275
+ test('enumerates relationships in authored order with resolved endpoints and id fallbacks', () => {
276
+ const { getByRole } = renderPanel({
277
+ decoration: {
278
+ ...decoration,
279
+ draft: {
280
+ c4: {
281
+ elements: [{
282
+ kind: 'component', id: 'component:sync', label: 'Sync coordinator',
283
+ container: 'container:desktop', technology: 'TypeScript',
284
+ }],
285
+ edges: [
286
+ { id: 'enqueue', source: 'component:save', target: 'component:sync', label: 'Queues drawing', mechanisms: ['produces'], count: 1 },
287
+ { id: 'dispatch', source: 'component:sync', target: 'container:worker', label: 'Dispatches upload', mechanisms: ['calls'], count: 1 },
288
+ { id: 'upload', source: 'container:worker', target: 'component:persist', label: 'Uploads drawing', mechanisms: ['calls'], count: 1 },
289
+ ],
290
+ },
291
+ },
292
+ },
293
+ c4ElementLabels: new Map([
294
+ ['component:save', 'Drawing save'],
295
+ ['container:worker', 'Background worker'],
296
+ ]),
297
+ });
298
+ const items = within(getByRole('list', { name: 'Draft C4 relationships' })).getAllByRole('listitem');
299
+ expect(items).toHaveLength(3);
300
+ expect(items.map((item) => within(item).getByRole('button').firstElementChild?.textContent))
301
+ .toEqual(['Queues drawing', 'Dispatches upload', 'Uploads drawing']);
302
+ expect(within(items[0]!).getByText('Drawing save → Sync coordinator')).not.toBeNull();
303
+ expect(within(items[1]!).getByText('Sync coordinator → Background worker')).not.toBeNull();
304
+ expect(within(items[2]!).getByText('Background worker → component:persist')).not.toBeNull();
305
+ });
306
+
307
+ test('relationship buttons report clicks and share the selected and hover row styles', () => {
308
+ const edges = [
309
+ { id: 'enqueue', source: 'component:save', target: 'component:sync', label: 'Queues drawing', mechanisms: ['produces'], count: 1 },
310
+ { id: 'dispatch', source: 'component:sync', target: 'container:worker', label: 'Dispatches upload', mechanisms: ['calls'], count: 1 },
311
+ ];
312
+ const onSelectDraftC4Edge = mock(() => {});
313
+ const withEdges: SubsystemDecoration = {
314
+ ...decoration,
315
+ draft: { ...decoration.draft, c4: { edges } },
316
+ };
317
+ const panel = (selectedDraftItem: DecorationPanelProps['selectedDraftItem']) => (
318
+ <ThemeProvider theme={defaultEditorTheme}>
319
+ <DecorationPanel
320
+ decoration={withEdges}
321
+ active
322
+ onToggleActive={() => {}}
323
+ onSelectDraftC4Edge={onSelectDraftC4Edge}
324
+ selectedDraftItem={selectedDraftItem}
325
+ />
326
+ </ThemeProvider>
327
+ );
328
+ const { getByRole, container, rerender } = render(panel(null));
329
+ const rows = within(getByRole('list', { name: 'Draft C4 relationships' })).getAllByRole('button');
330
+ expect(rows).toHaveLength(2);
331
+ expect(rows[0]!.classList.contains('subsystem-decoration-draft-row')).toBe(true);
332
+ expect(rows[0]!.style.cursor).toBe('pointer');
333
+ fireEvent.click(rows[0]!);
334
+ expect(onSelectDraftC4Edge).toHaveBeenCalledWith(edges[0]);
335
+
336
+ rerender(panel({ kind: 'c4-edge', id: 'enqueue' }));
337
+ expect(rows[0]!.getAttribute('aria-current')).toBe('true');
338
+ expect(rows[0]!.style.background).not.toBe('');
339
+ expect(rows[0]!.style.boxShadow).toBe('');
340
+ expect(rows[1]!.getAttribute('aria-current')).toBeNull();
341
+
342
+ rerender(panel({ kind: 'c4-edge', id: 'dispatch' }));
343
+ expect(rows[0]!.getAttribute('aria-current')).toBeNull();
344
+ expect(rows[0]!.style.background).toBe('');
345
+ expect(rows[1]!.getAttribute('aria-current')).toBe('true');
346
+ expect(container.querySelectorAll('[aria-current="true"]')).toHaveLength(1);
347
+
348
+ rerender(panel(null));
349
+ expect(container.querySelectorAll('[aria-current="true"]')).toHaveLength(0);
350
+ expect(rows[1]!.style.background).toBe('');
351
+ });
128
352
  });