@principal-ai/subsystems-react 0.53.0 → 0.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/subsystem/C4Graph.d.ts +8 -1
- package/dist/subsystem/C4Graph.d.ts.map +1 -1
- package/dist/subsystem/C4Graph.js +454 -171
- package/dist/subsystem/C4Graph.js.map +1 -1
- package/dist/subsystem/C4NodeCard.d.ts +36 -1
- package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
- package/dist/subsystem/C4NodeCard.js +45 -10
- package/dist/subsystem/C4NodeCard.js.map +1 -1
- package/dist/subsystem/IssueList.d.ts.map +1 -1
- package/dist/subsystem/IssueList.js +13 -4
- package/dist/subsystem/IssueList.js.map +1 -1
- package/dist/subsystem/c4.d.ts +27 -3
- package/dist/subsystem/c4.d.ts.map +1 -1
- package/dist/subsystem/c4.js +48 -0
- package/dist/subsystem/c4.js.map +1 -1
- package/dist/utils/elkLayout.d.ts +26 -2
- package/dist/utils/elkLayout.d.ts.map +1 -1
- package/dist/utils/elkLayout.js +40 -8
- package/dist/utils/elkLayout.js.map +1 -1
- package/package.json +2 -1
- package/src/stories/Subsystem/C4Graph/C4CardGrow.stories.tsx +125 -0
- package/src/stories/Subsystem/C4Graph/C4Component.stories.tsx +21 -11
- package/src/stories/Subsystem/C4Graph/C4Container.stories.tsx +1 -9
- package/src/stories/Subsystem/C4Graph/C4Transition.stories.tsx +131 -0
- package/src/subsystem/C4Graph.tsx +561 -217
- package/src/subsystem/C4NodeCard.test.ts +6 -3
- package/src/subsystem/C4NodeCard.tsx +92 -20
- package/src/subsystem/IssueList.category.test.ts +39 -0
- package/src/subsystem/IssueList.tsx +14 -3
- package/src/subsystem/c4.ts +74 -3
- package/src/utils/elkLayout.ts +60 -10
|
@@ -150,18 +150,21 @@ describe('nodeTopLabel — the technology, or the kind when none is stated', ()
|
|
|
150
150
|
expect(
|
|
151
151
|
nodeTopLabel(node({ containerKind: 'application', technology: 'Bun + Electrobun' })),
|
|
152
152
|
).toBe('Bun + Electrobun');
|
|
153
|
-
expect(nodeTopLabel(node({ kind: 'component', technology: 'React + ELK' }))).toBe('React + ELK');
|
|
154
153
|
});
|
|
155
154
|
|
|
156
155
|
test('a container with no technology falls back to its kind', () => {
|
|
157
156
|
expect(nodeTopLabel(node({ containerKind: 'data-store', technology: '' }))).toBe('data-store');
|
|
158
157
|
});
|
|
159
158
|
|
|
160
|
-
test('
|
|
161
|
-
expect(nodeTopLabel(node({ kind: 'component' }))).toBe('component');
|
|
159
|
+
test('an external system / person falls back to its C4 kind', () => {
|
|
162
160
|
expect(nodeTopLabel(node({ kind: 'external-system' }))).toBe('external-system');
|
|
163
161
|
expect(nodeTopLabel(node({ kind: 'person' }))).toBe('person');
|
|
164
162
|
});
|
|
163
|
+
|
|
164
|
+
test('a component has no top label — its technology is the container’s', () => {
|
|
165
|
+
expect(nodeTopLabel(node({ kind: 'component', technology: 'React + ELK' }))).toBe('');
|
|
166
|
+
expect(nodeTopLabel(node({ kind: 'component' }))).toBe('');
|
|
167
|
+
});
|
|
165
168
|
});
|
|
166
169
|
|
|
167
170
|
describe('nodeShape — kind without relying on colour or dash', () => {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { useTheme } from '@principal-ade/industry-theme';
|
|
16
|
-
import { AppWindow, Component, Database } from 'lucide-react';
|
|
16
|
+
import { AppWindow, Component, Database, Maximize2 } from 'lucide-react';
|
|
17
17
|
import type { LucideIcon } from 'lucide-react';
|
|
18
18
|
import { TechMark, technologyBrand } from './techIcons';
|
|
19
19
|
import type { C4Element } from './c4';
|
|
@@ -50,6 +50,17 @@ export function nodeSize(node: C4Element): { width: number; height: number } {
|
|
|
50
50
|
*/
|
|
51
51
|
const LABEL_SLOT_H = 40;
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Space a *grown* container reserves above its nested components: the card's own
|
|
55
|
+
* top padding + the label slot + the row gap + the technology row, plus a little
|
|
56
|
+
* air. The description is hidden while grown, so it is not part of this.
|
|
57
|
+
*
|
|
58
|
+
* The graph hands this to ELK as the compound parent's top padding rather than
|
|
59
|
+
* nudging the children down itself — so the parent's size and the children's
|
|
60
|
+
* placement are still one ELK fit, not our arithmetic layered on top of it.
|
|
61
|
+
*/
|
|
62
|
+
export const OPEN_HEADER_PAD = 84;
|
|
63
|
+
|
|
53
64
|
type Theme = ReturnType<typeof useTheme>['theme'];
|
|
54
65
|
|
|
55
66
|
export interface NodeStyle {
|
|
@@ -151,14 +162,17 @@ export function nodeKindIcon(node: C4Element): LucideIcon | undefined {
|
|
|
151
162
|
* The text on the top row: the technology the box is built with (Bun, React,
|
|
152
163
|
* Postgres…). Falls back to the container kind / C4 kind when no technology is
|
|
153
164
|
* stated, so the row is never blank.
|
|
165
|
+
*
|
|
166
|
+
* A component returns `''`: its technology is almost always the container's, so
|
|
167
|
+
* restating it is noise. The container frame already carries it.
|
|
154
168
|
*/
|
|
155
169
|
export function nodeTopLabel(node: C4Element): string {
|
|
170
|
+
if (node.kind === 'component') return '';
|
|
156
171
|
const technology = nodeTechnology(node);
|
|
157
172
|
if (technology) return technology;
|
|
158
173
|
switch (node.kind) {
|
|
159
174
|
case 'container':
|
|
160
175
|
return node.containerKind;
|
|
161
|
-
case 'component':
|
|
162
176
|
case 'external-system':
|
|
163
177
|
case 'person':
|
|
164
178
|
return node.kind;
|
|
@@ -231,9 +245,31 @@ export interface C4NodeCardProps {
|
|
|
231
245
|
* row for containers. Omitted/0 → no count.
|
|
232
246
|
*/
|
|
233
247
|
componentCount?: number;
|
|
248
|
+
/**
|
|
249
|
+
* When set, the card draws an expand affordance (bottom-right) that calls
|
|
250
|
+
* this — the drill-down trigger. Only containers with components pass it.
|
|
251
|
+
*/
|
|
252
|
+
onExpand?: () => void;
|
|
253
|
+
/**
|
|
254
|
+
* Explicit box size, overriding the kind's default. Lets a host animate the
|
|
255
|
+
* card (the drill-down grow) without the card owning that state.
|
|
256
|
+
*/
|
|
257
|
+
width?: number;
|
|
258
|
+
height?: number;
|
|
259
|
+
/**
|
|
260
|
+
* Show the description line under the label. Off when the card is grown to
|
|
261
|
+
* host components — the internals occupy that space.
|
|
262
|
+
* @default true
|
|
263
|
+
*/
|
|
264
|
+
showDescription?: boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Content drawn below the header (label / technology / description). Used by
|
|
267
|
+
* the grown card to host its component cards.
|
|
268
|
+
*/
|
|
269
|
+
children?: React.ReactNode;
|
|
234
270
|
}
|
|
235
271
|
|
|
236
|
-
export function C4NodeCard({ node, selected = false, handles, onClick, componentCount = 0 }: C4NodeCardProps) {
|
|
272
|
+
export function C4NodeCard({ node, selected = false, handles, onClick, componentCount = 0, onExpand, width, height, showDescription = true, children }: C4NodeCardProps) {
|
|
237
273
|
const { theme } = useTheme();
|
|
238
274
|
const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
|
|
239
275
|
const style = nodeStyle(node, theme, selected);
|
|
@@ -252,8 +288,10 @@ export function C4NodeCard({ node, selected = false, handles, onClick, component
|
|
|
252
288
|
<div
|
|
253
289
|
onClick={onClick}
|
|
254
290
|
style={{
|
|
255
|
-
|
|
256
|
-
|
|
291
|
+
position: 'relative',
|
|
292
|
+
width: width ?? size.width,
|
|
293
|
+
minHeight: height ?? size.height,
|
|
294
|
+
transition: 'width 420ms ease-out, min-height 420ms ease-out',
|
|
257
295
|
boxSizing: 'border-box',
|
|
258
296
|
display: 'flex',
|
|
259
297
|
flexDirection: 'column',
|
|
@@ -280,7 +318,7 @@ export function C4NodeCard({ node, selected = false, handles, onClick, component
|
|
|
280
318
|
style={{
|
|
281
319
|
display: 'flex',
|
|
282
320
|
alignItems: 'flex-start',
|
|
283
|
-
justifyContent: centered ? 'center' : '
|
|
321
|
+
justifyContent: centered ? 'center' : 'space-between',
|
|
284
322
|
gap: 6,
|
|
285
323
|
height: LABEL_SLOT_H,
|
|
286
324
|
minWidth: 0,
|
|
@@ -337,20 +375,22 @@ export function C4NodeCard({ node, selected = false, handles, onClick, component
|
|
|
337
375
|
minWidth: 0,
|
|
338
376
|
}}
|
|
339
377
|
>
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
378
|
+
{topLabel && (
|
|
379
|
+
<span style={{ display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 }}>
|
|
380
|
+
{brand && <TechMark brand={brand} />}
|
|
381
|
+
<span
|
|
382
|
+
style={{
|
|
383
|
+
fontWeight: 600,
|
|
384
|
+
whiteSpace: 'nowrap',
|
|
385
|
+
overflow: 'hidden',
|
|
386
|
+
textOverflow: 'ellipsis',
|
|
387
|
+
minWidth: 0,
|
|
388
|
+
}}
|
|
389
|
+
>
|
|
390
|
+
{topLabel}
|
|
391
|
+
</span>
|
|
352
392
|
</span>
|
|
353
|
-
|
|
393
|
+
)}
|
|
354
394
|
{node.kind === 'container' && (
|
|
355
395
|
<span
|
|
356
396
|
style={{
|
|
@@ -366,7 +406,7 @@ export function C4NodeCard({ node, selected = false, handles, onClick, component
|
|
|
366
406
|
</span>
|
|
367
407
|
)}
|
|
368
408
|
</span>
|
|
369
|
-
{subtitle && (
|
|
409
|
+
{showDescription && subtitle && (
|
|
370
410
|
<span
|
|
371
411
|
style={{
|
|
372
412
|
fontFamily: theme.fonts.monospace,
|
|
@@ -381,6 +421,38 @@ export function C4NodeCard({ node, selected = false, handles, onClick, component
|
|
|
381
421
|
{subtitle}
|
|
382
422
|
</span>
|
|
383
423
|
)}
|
|
424
|
+
{children}
|
|
425
|
+
{/* Drill-down affordance: bottom-right, its own hit target so the card's
|
|
426
|
+
own click (select) is unaffected. */}
|
|
427
|
+
{onExpand && (
|
|
428
|
+
<button
|
|
429
|
+
type="button"
|
|
430
|
+
onClick={(e) => {
|
|
431
|
+
e.stopPropagation();
|
|
432
|
+
onExpand();
|
|
433
|
+
}}
|
|
434
|
+
aria-label="Show components"
|
|
435
|
+
style={{
|
|
436
|
+
position: 'absolute',
|
|
437
|
+
right: 6,
|
|
438
|
+
bottom: 6,
|
|
439
|
+
display: 'inline-flex',
|
|
440
|
+
alignItems: 'center',
|
|
441
|
+
justifyContent: 'center',
|
|
442
|
+
width: 22,
|
|
443
|
+
height: 22,
|
|
444
|
+
padding: 0,
|
|
445
|
+
borderRadius: 4,
|
|
446
|
+
border: `1px solid ${style.color}`,
|
|
447
|
+
background: theme.colors.backgroundSecondary ?? theme.colors.background,
|
|
448
|
+
color: style.color,
|
|
449
|
+
cursor: 'pointer',
|
|
450
|
+
lineHeight: 1,
|
|
451
|
+
}}
|
|
452
|
+
>
|
|
453
|
+
<Maximize2 size={13} strokeWidth={2.25} />
|
|
454
|
+
</button>
|
|
455
|
+
)}
|
|
384
456
|
{handles}
|
|
385
457
|
</div>
|
|
386
458
|
);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { issueCategory, issueKindLabel } from './IssueList';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every C4 process-verification kind must land in the dynamic-topology
|
|
6
|
+
* category. These kinds are emitted by new audit passes over time, and an
|
|
7
|
+
* unmapped kind silently falls through to `construct` — the list then files a
|
|
8
|
+
* process finding under Constructs while the maintenance lane tally counts it
|
|
9
|
+
* as dynamic-topology, so the construct lane reads verified (green) beside a
|
|
10
|
+
* process issue. The regressions are real: `boundary_process_missing` shipped
|
|
11
|
+
* unmapped long before the container-first kinds joined it.
|
|
12
|
+
*/
|
|
13
|
+
describe('issueCategory — C4 process kinds', () => {
|
|
14
|
+
const processKinds = [
|
|
15
|
+
'boundary_process_missing',
|
|
16
|
+
'boundary_process_nest_disagree',
|
|
17
|
+
'boundary_process_unassigned',
|
|
18
|
+
'boundary_process_proposed',
|
|
19
|
+
'boundary_process_rejected',
|
|
20
|
+
'boundary_process_unbacked',
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
for (const kind of processKinds) {
|
|
24
|
+
test(`${kind} categorizes as dynamic-topology`, () => {
|
|
25
|
+
expect(issueCategory({ id: 'x', severity: 'info', kind, message: '' })).toBe(
|
|
26
|
+
'dynamic-topology',
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
test('mapped kinds get human labels, not the humanized fallback', () => {
|
|
32
|
+
expect(issueKindLabel({ id: 'x', severity: 'info', kind: 'boundary_process_missing', message: '' })).toBe(
|
|
33
|
+
'Process claim missing',
|
|
34
|
+
);
|
|
35
|
+
expect(issueKindLabel({ id: 'x', severity: 'info', kind: 'boundary_process_unbacked', message: '' })).toBe(
|
|
36
|
+
'Process claim unbacked',
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -20,12 +20,14 @@ import {
|
|
|
20
20
|
CircleDashed,
|
|
21
21
|
CircleEllipsis,
|
|
22
22
|
CircleHelp,
|
|
23
|
+
CircleSlash,
|
|
23
24
|
CircleX,
|
|
24
25
|
Component,
|
|
25
26
|
FileX,
|
|
26
27
|
FolderGit2,
|
|
27
28
|
Footprints,
|
|
28
29
|
History,
|
|
30
|
+
Link2Off,
|
|
29
31
|
MapPin,
|
|
30
32
|
Network,
|
|
31
33
|
Route,
|
|
@@ -112,9 +114,11 @@ const KIND_CATEGORY: Record<string, SubsystemIssueCategory> = {
|
|
|
112
114
|
// C4 process verification (verifyProcessBoundaries): a boundary whose
|
|
113
115
|
// container claim is not an accepted one. `verified` reports nothing —
|
|
114
116
|
// the audit reports absence only.
|
|
117
|
+
boundary_process_missing: 'dynamic-topology',
|
|
115
118
|
boundary_process_unassigned: 'dynamic-topology',
|
|
116
119
|
boundary_process_proposed: 'dynamic-topology',
|
|
117
120
|
boundary_process_rejected: 'dynamic-topology',
|
|
121
|
+
boundary_process_unbacked: 'dynamic-topology',
|
|
118
122
|
trail: 'trail',
|
|
119
123
|
step_unconfirmed: 'trail',
|
|
120
124
|
step_stale: 'trail',
|
|
@@ -180,9 +184,12 @@ export const ISSUE_KIND_ICON: Record<string, LucideIcon> = {
|
|
|
180
184
|
boundary_process_nest_disagree: Split,
|
|
181
185
|
// C4 process verification: unclaimed = no container at all, proposed = an
|
|
182
186
|
// agent scaffold awaits a decision, rejected = a container was declined.
|
|
187
|
+
boundary_process_missing: CircleSlash,
|
|
183
188
|
boundary_process_unassigned: CircleEllipsis,
|
|
184
189
|
boundary_process_proposed: CircleDashed,
|
|
185
190
|
boundary_process_rejected: CircleX,
|
|
191
|
+
// Container-first gate: a claim cites a key no accepted container owns.
|
|
192
|
+
boundary_process_unbacked: Link2Off,
|
|
186
193
|
// Trail step verification: unconfirmed = no augmentation yet, stale = code changed
|
|
187
194
|
step_unconfirmed: CircleHelp,
|
|
188
195
|
step_stale: History,
|
|
@@ -267,9 +274,11 @@ const KIND_LABEL: Record<string, string> = {
|
|
|
267
274
|
boundary_process_nest_disagree: 'Module spans multiple process contexts',
|
|
268
275
|
// C4 process verification (labels read as boundary states, since the layer
|
|
269
276
|
// scopes them to process frames).
|
|
277
|
+
boundary_process_missing: 'Process claim missing',
|
|
270
278
|
boundary_process_unassigned: 'Process boundary unclaimed',
|
|
271
279
|
boundary_process_proposed: 'Container awaiting decision',
|
|
272
280
|
boundary_process_rejected: 'Container rejected',
|
|
281
|
+
boundary_process_unbacked: 'Process claim unbacked',
|
|
273
282
|
trail: 'Step issue',
|
|
274
283
|
step_unconfirmed: 'Call site not verified',
|
|
275
284
|
step_stale: 'Call site changed',
|
|
@@ -304,9 +313,11 @@ const KIND_ORDER: Record<string, number> = {
|
|
|
304
313
|
boundary_module_file_mismatch: 23,
|
|
305
314
|
// Runtime topology — process containment
|
|
306
315
|
boundary_process_nest_disagree: 30,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
316
|
+
boundary_process_missing: 31,
|
|
317
|
+
boundary_process_unassigned: 32,
|
|
318
|
+
boundary_process_unbacked: 33,
|
|
319
|
+
boundary_process_proposed: 34,
|
|
320
|
+
boundary_process_rejected: 35,
|
|
310
321
|
// Trail — mechanical issues first, then step verification
|
|
311
322
|
trail: 40,
|
|
312
323
|
step_unconfirmed: 41,
|
package/src/subsystem/c4.ts
CHANGED
|
@@ -153,7 +153,11 @@ export interface C4ElementSet {
|
|
|
153
153
|
/** Which level to draw. Determines which frames are drawn. */
|
|
154
154
|
export type C4View = 'container' | 'component';
|
|
155
155
|
|
|
156
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* A compound frame the renderer draws: the system, or a container holding its
|
|
158
|
+
* components. Never authored — `deriveC4Groups` produces these from the element
|
|
159
|
+
* `parentId` chains and the current scope.
|
|
160
|
+
*/
|
|
157
161
|
export interface C4Group {
|
|
158
162
|
id: string;
|
|
159
163
|
kind: 'system' | 'container';
|
|
@@ -162,6 +166,63 @@ export interface C4Group {
|
|
|
162
166
|
memberIds: string[];
|
|
163
167
|
}
|
|
164
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Derive the frames to draw from the elements and the current scope.
|
|
171
|
+
*
|
|
172
|
+
* A container becomes a frame whenever its components are on screen — in the
|
|
173
|
+
* component view, or when it is the opened container. The system frame wraps
|
|
174
|
+
* whichever containers are drawn. No frame is authored; this is the view of the
|
|
175
|
+
* element set, so a container's identity (id, label, technology, colour) lives
|
|
176
|
+
* only on the element.
|
|
177
|
+
*/
|
|
178
|
+
export function deriveC4Groups(
|
|
179
|
+
model: Pick<C4Model, 'view' | 'system' | 'nodes' | 'openContainerId'>,
|
|
180
|
+
): C4Group[] {
|
|
181
|
+
const groups: C4Group[] = [];
|
|
182
|
+
const containers = model.nodes.filter((n): n is C4Container => n.kind === 'container');
|
|
183
|
+
const components = model.nodes.filter((n): n is C4Component => n.kind === 'component');
|
|
184
|
+
|
|
185
|
+
const opened = model.openContainerId ?? null;
|
|
186
|
+
// Component view shows every container's components; container view shows a
|
|
187
|
+
// container's components only when it is opened.
|
|
188
|
+
const framing = (containerId: string): boolean =>
|
|
189
|
+
model.view === 'component' || opened === containerId;
|
|
190
|
+
|
|
191
|
+
const framedContainers: string[] = [];
|
|
192
|
+
for (const c of containers) {
|
|
193
|
+
const members = components
|
|
194
|
+
.filter((comp) => (comp.container ?? comp.parentId) === c.id)
|
|
195
|
+
.map((comp) => comp.id);
|
|
196
|
+
if (members.length > 0 && framing(c.id)) {
|
|
197
|
+
groups.push({
|
|
198
|
+
id: c.id,
|
|
199
|
+
kind: 'container',
|
|
200
|
+
label: c.label,
|
|
201
|
+
parentId: model.system.id,
|
|
202
|
+
memberIds: members,
|
|
203
|
+
});
|
|
204
|
+
framedContainers.push(c.id);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// The system frame wraps the framed containers (component view) or the whole
|
|
209
|
+
// set of containers (container view) — the boundary is the system, so it must
|
|
210
|
+
// NOT shrink to the opened container. Opening one adds a nested container
|
|
211
|
+
// frame inside it; the system frame still spans everything.
|
|
212
|
+
const systemMembers =
|
|
213
|
+
model.view === 'component' ? framedContainers : containers.map((c) => c.id);
|
|
214
|
+
if (systemMembers.length > 0) {
|
|
215
|
+
groups.push({
|
|
216
|
+
id: model.system.id,
|
|
217
|
+
kind: 'system',
|
|
218
|
+
label: model.system.label,
|
|
219
|
+
memberIds: systemMembers,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return groups;
|
|
224
|
+
}
|
|
225
|
+
|
|
165
226
|
/**
|
|
166
227
|
* A line between two elements. Authored, like the boxes.
|
|
167
228
|
*
|
|
@@ -229,13 +290,23 @@ export function protocolColor(protocol: string | undefined): string {
|
|
|
229
290
|
return best ? PROTOCOL_COLOR[best]! : PROTOCOL_COLOR_FALLBACK;
|
|
230
291
|
}
|
|
231
292
|
|
|
232
|
-
/**
|
|
293
|
+
/**
|
|
294
|
+
* A drawable C4 projection. Authored: the boxes and lines, nothing drawn for
|
|
295
|
+
* you. Frames are derived by the renderer from the elements' `parentId` chains
|
|
296
|
+
* — a container is a frame when its components are being shown (component view,
|
|
297
|
+
* or opened via `openContainerId`), never a separately-authored thing.
|
|
298
|
+
*/
|
|
233
299
|
export interface C4Model {
|
|
234
300
|
view: C4View;
|
|
235
301
|
system: { id: string; label: string; repoKey?: string };
|
|
236
302
|
nodes: C4Element[];
|
|
237
|
-
groups: C4Group[];
|
|
238
303
|
edges: C4Edge[];
|
|
304
|
+
/**
|
|
305
|
+
* Drill-down scope: the id of a container whose components should be shown
|
|
306
|
+
* inside it as a frame. Absent/null → the container is drawn as a box and its
|
|
307
|
+
* components are hidden. The renderer derives the frames either way.
|
|
308
|
+
*/
|
|
309
|
+
openContainerId?: string | null;
|
|
239
310
|
}
|
|
240
311
|
|
|
241
312
|
/**
|
package/src/utils/elkLayout.ts
CHANGED
|
@@ -150,9 +150,16 @@ export interface ElkLayoutOptions {
|
|
|
150
150
|
* decoration drawn around wherever the members landed.
|
|
151
151
|
*
|
|
152
152
|
* Only for groups whose members need no parent-relative positioning (C4's
|
|
153
|
-
* system frame).
|
|
153
|
+
* system frame).
|
|
154
|
+
*
|
|
155
|
+
* A set names specific groups to flatten, leaving the rest as real ELK
|
|
156
|
+
* parents — the drill-down needs this, because the opened container must be
|
|
157
|
+
* *sized by ELK to fit its nested components* while the system frame around
|
|
158
|
+
* it stays decorative. Descendants of a flattened group are flattened too.
|
|
159
|
+
*
|
|
160
|
+
* @default false
|
|
154
161
|
*/
|
|
155
|
-
flatGroups?: boolean
|
|
162
|
+
flatGroups?: boolean | ReadonlySet<string>;
|
|
156
163
|
|
|
157
164
|
/**
|
|
158
165
|
* ELK partition per node id. Nodes are banded by `partition` — ELK places all
|
|
@@ -520,6 +527,21 @@ export interface CompoundGroupDef {
|
|
|
520
527
|
id: string;
|
|
521
528
|
memberIds: string[];
|
|
522
529
|
minWidth?: number;
|
|
530
|
+
/**
|
|
531
|
+
* ELK partition for this group. Partitioning is activated on the root and
|
|
532
|
+
* inherited, so a compound parent must be told its band explicitly —
|
|
533
|
+
* otherwise it falls to partition 0 and lays out away from the siblings it is
|
|
534
|
+
* supposed to sit among (which, for a flat frame around those siblings, drags
|
|
535
|
+
* the frame across an unrelated band).
|
|
536
|
+
*/
|
|
537
|
+
partition?: number;
|
|
538
|
+
/**
|
|
539
|
+
* Space reserved above the first child, in px. Set it when the parent draws
|
|
540
|
+
* its own chrome at the top (C4's grown container draws a label slot and a
|
|
541
|
+
* technology row) so ELK still owns the fit — it pads the parent by this and
|
|
542
|
+
* the children land below the chrome rather than under it.
|
|
543
|
+
*/
|
|
544
|
+
padTop?: number;
|
|
523
545
|
}
|
|
524
546
|
|
|
525
547
|
/** Which groups ELK builds, and which it drops. */
|
|
@@ -528,7 +550,7 @@ export interface CompoundGroupPlan {
|
|
|
528
550
|
* Built groups in build order — a group's children always appear before it,
|
|
529
551
|
* so callers can map ids to shells in one forward pass.
|
|
530
552
|
*/
|
|
531
|
-
built: Array<{ id: string; childIds: string[]; minWidth?: number }>;
|
|
553
|
+
built: Array<{ id: string; childIds: string[]; minWidth?: number; padTop?: number; partition?: number }>;
|
|
532
554
|
/**
|
|
533
555
|
* Dropped groups. Their members are promoted into the nearest built
|
|
534
556
|
* ancestor, so callers must clear those members' `parentId`.
|
|
@@ -864,11 +886,27 @@ export async function computeElkLayout(
|
|
|
864
886
|
// and the frame is synthesized from the members' bounds after layout. This
|
|
865
887
|
// keeps every edge on one spacing instead of inheriting a nested frame's.
|
|
866
888
|
const flatGroupIds = new Set<string>();
|
|
867
|
-
if (flatGroups) {
|
|
889
|
+
if (flatGroups === true) {
|
|
868
890
|
for (const g of plan.built) flatGroupIds.add(g.id);
|
|
891
|
+
} else if (flatGroups) {
|
|
892
|
+
for (const g of plan.built) if (flatGroups.has(g.id)) flatGroupIds.add(g.id);
|
|
893
|
+
// A group inside a flat frame can't be an ELK parent either — its members
|
|
894
|
+
// lay out at the root alongside the frame's other members.
|
|
895
|
+
let grew = true;
|
|
896
|
+
while (grew) {
|
|
897
|
+
grew = false;
|
|
898
|
+
for (const g of plan.built) {
|
|
899
|
+
if (flatGroupIds.has(g.id)) continue;
|
|
900
|
+
const parentId = groupById.get(g.id)?.parentId;
|
|
901
|
+
if (parentId && flatGroupIds.has(parentId)) {
|
|
902
|
+
flatGroupIds.add(g.id);
|
|
903
|
+
grew = true;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
869
907
|
}
|
|
870
908
|
for (const g of plan.built) {
|
|
871
|
-
if (
|
|
909
|
+
if (flatGroupIds.has(g.id)) continue;
|
|
872
910
|
const children: ElkNode[] = [];
|
|
873
911
|
for (const cid of g.childIds) {
|
|
874
912
|
const leaf = elkById.get(cid);
|
|
@@ -878,14 +916,26 @@ export async function computeElkLayout(
|
|
|
878
916
|
if (nested) children.push(nested);
|
|
879
917
|
}
|
|
880
918
|
}
|
|
919
|
+
const sizeOptions: Record<string, string> = {};
|
|
920
|
+
if (g.minWidth != null) {
|
|
921
|
+
// MINIMUM_SIZE, not a forced size: ELK grows the parent past it when the
|
|
922
|
+
// children need more, but never shrinks it below it.
|
|
923
|
+
sizeOptions['elk.nodeSize.constraints'] = 'MINIMUM_SIZE';
|
|
924
|
+
sizeOptions['elk.nodeSize.minimum'] = `(${g.minWidth},0)`;
|
|
925
|
+
}
|
|
926
|
+
if (g.padTop != null) {
|
|
927
|
+
// Reserving the parent's own chrome. Children then start below it, and
|
|
928
|
+
// the parent's height still comes from ELK's fit.
|
|
929
|
+
sizeOptions['elk.padding'] = `[top=${g.padTop},left=12,bottom=12,right=12]`;
|
|
930
|
+
}
|
|
931
|
+
if (g.partition != null) sizeOptions['partition'] = String(g.partition);
|
|
881
932
|
builtGroups.set(g.id, {
|
|
882
933
|
id: g.id,
|
|
883
934
|
children,
|
|
884
|
-
layoutOptions:
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
},
|
|
935
|
+
layoutOptions:
|
|
936
|
+
Object.keys(sizeOptions).length > 0
|
|
937
|
+
? { ...compoundLayoutOptions, ...sizeOptions }
|
|
938
|
+
: compoundLayoutOptions,
|
|
889
939
|
});
|
|
890
940
|
}
|
|
891
941
|
|