@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
@@ -15,16 +15,29 @@
15
15
  import { useTheme } from '@principal-ade/industry-theme';
16
16
  import { AppWindow, Component, Database, Maximize2 } from 'lucide-react';
17
17
  import type { LucideIcon } from 'lucide-react';
18
- import { TechMark, technologyBrand } from './techIcons';
18
+ import { technologyBrand } from './techIcons';
19
19
  import type { C4Element } from './c4';
20
-
21
- /**
22
- * Card box for a container: a wide rectangle. A container carries four things
23
- * at once (technology row, label, description, and the notation gap it still
24
- * has), and a strip would force the last two to wrap hard.
25
- */
26
- export const NODE_W = 250;
27
- export const NODE_H = 150;
20
+ import {
21
+ CARD_GAP,
22
+ CARD_PAD_Y,
23
+ ContainerCardHeader,
24
+ LABEL_SLOT_H,
25
+ NODE_H,
26
+ NODE_W,
27
+ TECH_SLOT_H,
28
+ TOGGLE_INSET,
29
+ TOGGLE_SIZE,
30
+ } from './containerCard';
31
+
32
+ // The card metrics live in `containerCard` so the component graph's frames can
33
+ // share them; re-exported here so the C4 canvas keeps one import.
34
+ export {
35
+ NODE_H,
36
+ NODE_W,
37
+ OPEN_FOOTER_PAD,
38
+ OPEN_HEADER_PAD,
39
+ OPEN_SIDE_PAD,
40
+ } from './containerCard';
28
41
 
29
42
  /**
30
43
  * A component has to *read* as a square, and equal sides do not manage that.
@@ -69,28 +82,6 @@ export function nodeSize(node: C4Element): { width: number; height: number } {
69
82
  : { width: NODE_W, height: NODE_H };
70
83
  }
71
84
 
72
- /**
73
- * Fixed label slot, so the description below sits at the same y on every card
74
- * even when a label is one line rather than two.
75
- */
76
- const LABEL_SLOT_H = 40;
77
-
78
- /**
79
- * The technology row's height, pinned for the same reason as the label slot: the
80
- * row is a line of text plus an optional 16px brand mark, so its natural height
81
- * depends on which of those are present. Pinning it makes the card's chrome a
82
- * known quantity, which is what lets `descriptionLineBudget` below say how many
83
- * description lines fit — and lets the footer pad and the header pad agree about
84
- * where the card's content actually ends.
85
- */
86
- const TECH_SLOT_H = 18;
87
-
88
- /** The card's own vertical padding (`padding: '10px 12px'`). */
89
- const CARD_PAD_Y = 10;
90
-
91
- /** The card's flex `gap`, between each of its rows. */
92
- const CARD_GAP = 3;
93
-
94
85
  /**
95
86
  * Space a component card reserves above and below the constructs nested inside
96
87
  * it when it is grown (a component with constructs becomes an ELK parent, the
@@ -102,37 +93,6 @@ export const COMPONENT_FOOTER_PAD = CARD_PAD_Y;
102
93
 
103
94
  /** The description's line height, as a multiple of its font size. */
104
95
  const DESC_LINE_HEIGHT = 1.35;
105
-
106
- /**
107
- * Breathing room between a grown container's own chrome and the components nested
108
- * inside it.
109
- *
110
- * The description is hidden while grown, so the components land where the
111
- * description would have been — immediately under the technology row. Without
112
- * this the gap is the width of one row gap, which reads as the components being
113
- * crowded against the header while the sides and footer sit `OPEN_SIDE_PAD` away.
114
- * This is not chrome: nothing is drawn in it.
115
- */
116
- const OPEN_HEADER_AIR = 16;
117
-
118
- /**
119
- * Space a *grown* container reserves above its nested components: the card's own
120
- * padding, its label slot, its technology row, the gaps between them, and a little
121
- * air. The description is hidden while grown, so it is not part of this.
122
- *
123
- * Derived from the same constants the card is built from, rather than written as
124
- * a literal, so it cannot drift from `descriptionLineBudget` — which subtracts
125
- * exactly this chrome (and no air) to decide how much description a closed card
126
- * can show. Those two disagreeing is how a card ends up taller than the box ELK
127
- * laid out for it.
128
- *
129
- * The graph hands this to ELK as the compound parent's top padding rather than
130
- * nudging the children down itself — so the parent's size and the children's
131
- * placement are still one ELK fit, not our arithmetic layered on top of it.
132
- */
133
- export const OPEN_HEADER_PAD =
134
- CARD_PAD_Y * 2 + LABEL_SLOT_H + CARD_GAP + TECH_SLOT_H + CARD_GAP + OPEN_HEADER_AIR;
135
-
136
96
  /**
137
97
  * How many description lines fit in a card of this height before the drawn box
138
98
  * would grow past the box the layout reserved for it.
@@ -173,39 +133,6 @@ export function descriptionLineBudget(opts: {
173
133
  return Math.max(0, Math.floor((reservedHeight - topChrome - bottomChrome) / lineHeight));
174
134
  }
175
135
 
176
- /**
177
- * The drill-down affordance, in the card's own box. Extracted from the button's
178
- * style so the reserved footer below cannot drift from the thing it is reserving
179
- * for — the two numbers are the same number.
180
- */
181
- const TOGGLE_SIZE = 22;
182
- const TOGGLE_INSET = 6;
183
-
184
- /**
185
- * Space a *grown* container reserves below its nested components, so the last row
186
- * does not sit under the collapse affordance.
187
- *
188
- * The toggle is absolutely positioned, so it takes no space in the card's flow and
189
- * ELK knows nothing about it: without this the parent is fitted to its children
190
- * alone and the final row is drawn straight through the button. Reserving the
191
- * toggle's own reach plus a little air keeps that an ELK fit too, rather than
192
- * something we nudge afterwards.
193
- */
194
- export const OPEN_FOOTER_PAD = TOGGLE_INSET + TOGGLE_SIZE + 8;
195
-
196
- /**
197
- * Space a *grown* container reserves to the left and right of its nested
198
- * components.
199
- *
200
- * Deliberately the footer's number rather than its own: the nested cards should
201
- * sit in one uniform inset, not a wider one at the bottom than at the sides. Both
202
- * are wider than the card's own 12px text inset — the label and technology row are
203
- * the container's chrome and sit flush with its padding, while the nested cards
204
- * are separate boxes it contains, and at the same inset they read as part of that
205
- * chrome rather than held inside it.
206
- */
207
- export const OPEN_SIDE_PAD = OPEN_FOOTER_PAD;
208
-
209
136
  type Theme = ReturnType<typeof useTheme>['theme'];
210
137
 
211
138
  export interface NodeStyle {
@@ -511,112 +438,17 @@ export function C4NodeCard({ node, selected = false, handles, onClick, component
511
438
  fontFamily: theme.fonts.body,
512
439
  }}
513
440
  >
514
- {/* The label row: the kind mark, then the name. Two lines rather than an
515
- ellipsis — a truncated label hides the very thing that distinguishes
516
- two containers from each other. The fixed height reserves both lines
517
- even for a one-line label, so the subtitle below sits at the same y on
518
- every card. */}
519
- <span
520
- style={{
521
- display: 'flex',
522
- alignItems: 'flex-start',
523
- justifyContent: centered ? 'center' : 'space-between',
524
- gap: 6,
525
- height: LABEL_SLOT_H,
526
- // Without this the slot shrinks when the content exceeds the card's fixed
527
- // height, and `descriptionLineBudget`'s chrome stops being the chrome —
528
- // measured at 39.11px instead of 40 the moment the description ran long.
529
- flexShrink: 0,
530
- minWidth: 0,
531
- }}
532
- >
533
- <span
534
- style={{
535
- fontFamily: theme.fonts.body,
536
- fontWeight: 600,
537
- fontSize: theme.fontSizes[2],
538
- color: theme.colors.text,
539
- lineHeight: 1.25,
540
- maxHeight: LABEL_SLOT_H,
541
- display: '-webkit-box',
542
- WebkitLineClamp: 2,
543
- WebkitBoxOrient: 'vertical',
544
- overflow: 'hidden',
545
- textAlign: centered ? 'center' : 'left',
546
- minWidth: 0,
547
- }}
548
- >
549
- {node.label}
550
- </span>
551
- {Icon && (
552
- <span
553
- aria-label={node.kind === 'container' ? node.containerKind : node.kind}
554
- style={{
555
- display: 'inline-flex',
556
- flexShrink: 0,
557
- color: style.color,
558
- // Nudge down so the glyph optically centres on the first text line.
559
- marginTop: 3,
560
- }}
561
- >
562
- <Icon size={16} strokeWidth={2.25} />
563
- </span>
564
- )}
565
- </span>
566
- {/* The technology row: the brand mark when we hold the official one, then
567
- the technology. For a container, right-aligned, the number of members
568
- it groups. The kind itself stays on the shape, confirmation on the
569
- border (see `nodeShape`, `nodeStyle`). */}
570
- <span
571
- style={{
572
- display: 'flex',
573
- alignItems: 'center',
574
- justifyContent: centered ? 'center' : 'space-between',
575
- gap: 6,
576
- fontFamily: theme.fonts.monospace,
577
- fontSize: theme.fontSizes[0],
578
- color: muted,
579
- letterSpacing: 0.5,
580
- textTransform: 'uppercase',
581
- minWidth: 0,
582
- // Pinned, like the label slot above it: an empty row would otherwise be
583
- // zero-height and the description budget would have to guess which cards
584
- // have a technology row. Empty stays zero — a person has no technology.
585
- ...(hasTechRow ? { height: TECH_SLOT_H, flexShrink: 0 } : {}),
586
- }}
587
- >
588
- {topLabel && (
589
- <span style={{ display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 }}>
590
- {brand && <TechMark brand={brand} />}
591
- <span
592
- style={{
593
- fontWeight: 600,
594
- whiteSpace: 'nowrap',
595
- overflow: 'hidden',
596
- textOverflow: 'ellipsis',
597
- minWidth: 0,
598
- }}
599
- >
600
- {topLabel}
601
- </span>
602
- </span>
603
- )}
604
- {node.kind === 'container' && (
605
- <span
606
- style={{
607
- flexShrink: 0,
608
- letterSpacing: 0,
609
- display: 'inline-flex',
610
- alignItems: 'center',
611
- gap: 4,
612
- }}
613
- >
614
- {componentCount}
615
- <Component size={12} strokeWidth={2.25} />
616
- </span>
617
- )}
618
- </span>
619
- {showDescription && subtitle && descLines > 0 && (
441
+ <ContainerCardHeader
442
+ label={node.label}
443
+ Icon={Icon}
444
+ iconLabel={node.kind === 'container' ? node.containerKind : node.kind}
445
+ color={style.color}
446
+ topLabel={topLabel}
447
+ brand={brand}
448
+ hasTechRow={hasTechRow}
449
+ count={node.kind === 'container' ? { value: componentCount, Icon: Component } : undefined}
450
+ centered={centered}
451
+ /> {showDescription && subtitle && descLines > 0 && (
620
452
  <span
621
453
  style={{
622
454
  fontFamily: theme.fonts.monospace,
@@ -675,4 +507,4 @@ export function C4NodeCard({ node, selected = false, handles, onClick, component
675
507
  {handles}
676
508
  </div>
677
509
  );
678
- }
510
+ }
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Sidebar list of the graph's container frames — the process and package
3
+ * regions drawn as container cards.
4
+ *
5
+ * One row per frame, nested the way the frames nest on the canvas. A row click
6
+ * frames the container on the canvas; the trailing button opens or closes it
7
+ * (members folded away into the card, or laid back out). The header's
8
+ * "Open all" / "Close all" set every frame at once.
9
+ */
10
+
11
+ import { useTheme } from '@principal-ade/industry-theme';
12
+ import { AppWindow, Component, Database, Maximize2, Minimize2, Package } from 'lucide-react';
13
+ import type { CSSProperties } from 'react';
14
+ import type { SubsystemProcessRegion } from './model';
15
+ import { TechMark, technologyBrand } from './techIcons';
16
+
17
+ export interface ContainerListItem {
18
+ /** Boundary group node id — what the canvas toggles and frames. */
19
+ id: string;
20
+ region: SubsystemProcessRegion;
21
+ /** Drawn as a closed card. */
22
+ collapsed: boolean;
23
+ /** Nesting depth under other container frames (0 = top level). */
24
+ depth: number;
25
+ /** Frame colour as drawn on the canvas. */
26
+ color: string;
27
+ }
28
+
29
+ export interface ContainersPanelProps {
30
+ containers: readonly ContainerListItem[];
31
+ /** The container last framed from this list. */
32
+ activeId?: string | null;
33
+ onFocus: (id: string) => void;
34
+ onToggle: (id: string) => void;
35
+ onOpenAll: () => void;
36
+ onCloseAll: () => void;
37
+ }
38
+
39
+ export function ContainersPanel({
40
+ containers,
41
+ activeId,
42
+ onFocus,
43
+ onToggle,
44
+ onOpenAll,
45
+ onCloseAll,
46
+ }: ContainersPanelProps) {
47
+ const { theme } = useTheme();
48
+ const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
49
+ const anyOpen = containers.some((c) => !c.collapsed);
50
+ const anyClosed = containers.some((c) => c.collapsed);
51
+ const bulkStyle = (enabled: boolean): CSSProperties => ({
52
+ padding: '2px 8px',
53
+ border: `1px solid ${theme.colors.border}`,
54
+ borderRadius: 4,
55
+ background: 'transparent',
56
+ color: enabled ? theme.colors.textSecondary : muted,
57
+ fontFamily: theme.fonts.monospace,
58
+ fontSize: theme.fontSizes[0],
59
+ cursor: enabled ? 'pointer' : 'default',
60
+ opacity: enabled ? 1 : 0.5,
61
+ });
62
+
63
+ if (containers.length === 0) {
64
+ return (
65
+ <div style={{ padding: 16, color: theme.colors.textSecondary }}>No container frames.</div>
66
+ );
67
+ }
68
+
69
+ return (
70
+ <div style={{ display: 'flex', flexDirection: 'column', minHeight: 0 }}>
71
+ <div
72
+ style={{
73
+ display: 'flex',
74
+ alignItems: 'center',
75
+ gap: 6,
76
+ padding: '8px 12px',
77
+ borderBottom: `1px solid ${theme.colors.border}`,
78
+ flexShrink: 0,
79
+ }}
80
+ >
81
+ <span
82
+ style={{
83
+ flex: 1,
84
+ fontFamily: theme.fonts.monospace,
85
+ fontSize: theme.fontSizes[0],
86
+ color: muted,
87
+ textTransform: 'uppercase',
88
+ letterSpacing: 0.5,
89
+ }}
90
+ >
91
+ {containers.length} {containers.length === 1 ? 'container' : 'containers'}
92
+ </span>
93
+ <button type="button" onClick={onOpenAll} disabled={!anyClosed} style={bulkStyle(anyClosed)}>
94
+ Open all
95
+ </button>
96
+ <button type="button" onClick={onCloseAll} disabled={!anyOpen} style={bulkStyle(anyOpen)}>
97
+ Close all
98
+ </button>
99
+ </div>
100
+ <ul
101
+ role="list"
102
+ aria-label="Containers"
103
+ style={{ listStyle: 'none', margin: 0, padding: '6px 0', overflow: 'auto', minHeight: 0 }}
104
+ >
105
+ {containers.map((c) => (
106
+ <ContainerRow
107
+ key={c.id}
108
+ item={c}
109
+ active={c.id === activeId}
110
+ onFocus={() => onFocus(c.id)}
111
+ onToggle={() => onToggle(c.id)}
112
+ />
113
+ ))}
114
+ </ul>
115
+ </div>
116
+ );
117
+ }
118
+
119
+ function ContainerRow({
120
+ item,
121
+ active,
122
+ onFocus,
123
+ onToggle,
124
+ }: {
125
+ item: ContainerListItem;
126
+ active: boolean;
127
+ onFocus: () => void;
128
+ onToggle: () => void;
129
+ }) {
130
+ const { theme } = useTheme();
131
+ const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
132
+ const { region, collapsed, depth, color } = item;
133
+ const isPackage = region.kind === 'package' || region.chrome === 'package';
134
+ const containerKind = region.containerKind ?? 'application';
135
+ const Icon = isPackage ? Package : containerKind === 'data-store' ? Database : AppWindow;
136
+ const brand = technologyBrand(region.technology);
137
+ const topLabel = region.technology ?? (isPackage ? 'package' : containerKind);
138
+ const ToggleIcon = collapsed ? Maximize2 : Minimize2;
139
+
140
+ return (
141
+ <li
142
+ style={{
143
+ display: 'flex',
144
+ alignItems: 'center',
145
+ gap: 8,
146
+ padding: `6px 12px 6px ${12 + depth * 16}px`,
147
+ background: active ? theme.colors.backgroundSecondary : 'transparent',
148
+ }}
149
+ >
150
+ <button
151
+ type="button"
152
+ onClick={onFocus}
153
+ title={region.description}
154
+ aria-current={active || undefined}
155
+ style={{
156
+ flex: 1,
157
+ minWidth: 0,
158
+ display: 'flex',
159
+ alignItems: 'center',
160
+ gap: 8,
161
+ padding: 0,
162
+ border: 'none',
163
+ background: 'transparent',
164
+ color: theme.colors.text,
165
+ textAlign: 'left',
166
+ cursor: 'pointer',
167
+ fontFamily: theme.fonts.body,
168
+ }}
169
+ >
170
+ <span
171
+ aria-hidden
172
+ style={{
173
+ width: 3,
174
+ alignSelf: 'stretch',
175
+ borderRadius: 2,
176
+ background: color,
177
+ flexShrink: 0,
178
+ }}
179
+ />
180
+ <Icon size={14} color={color} aria-hidden />
181
+ <span style={{ minWidth: 0, display: 'flex', flexDirection: 'column', gap: 1 }}>
182
+ <span
183
+ style={{
184
+ fontSize: theme.fontSizes[1],
185
+ fontWeight: 600,
186
+ overflow: 'hidden',
187
+ textOverflow: 'ellipsis',
188
+ whiteSpace: 'nowrap',
189
+ }}
190
+ >
191
+ {region.label}
192
+ </span>
193
+ <span
194
+ style={{
195
+ display: 'inline-flex',
196
+ alignItems: 'center',
197
+ gap: 5,
198
+ fontFamily: theme.fonts.monospace,
199
+ fontSize: theme.fontSizes[0],
200
+ color: muted,
201
+ textTransform: 'uppercase',
202
+ letterSpacing: 0.5,
203
+ whiteSpace: 'nowrap',
204
+ }}
205
+ >
206
+ {brand && <TechMark brand={brand} size={10} />}
207
+ <span>{topLabel}</span>
208
+ <span aria-hidden>·</span>
209
+ <Component size={10} aria-hidden />
210
+ <span>{region.memberAliases.length}</span>
211
+ </span>
212
+ </span>
213
+ </button>
214
+ <button
215
+ type="button"
216
+ onClick={onToggle}
217
+ aria-label={collapsed ? `Show members of ${region.label}` : `Hide members of ${region.label}`}
218
+ aria-pressed={collapsed}
219
+ style={{
220
+ display: 'inline-flex',
221
+ alignItems: 'center',
222
+ justifyContent: 'center',
223
+ width: 22,
224
+ height: 22,
225
+ padding: 0,
226
+ flexShrink: 0,
227
+ borderRadius: 4,
228
+ border: `1px solid ${color}`,
229
+ background: 'transparent',
230
+ color,
231
+ cursor: 'pointer',
232
+ lineHeight: 1,
233
+ }}
234
+ >
235
+ <ToggleIcon size={12} strokeWidth={2.25} />
236
+ </button>
237
+ </li>
238
+ );
239
+ }