@principal-ai/subsystems-react 0.56.21 → 0.56.23

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 (70) hide show
  1. package/dist/index.d.ts +5 -2
  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/stories/Canvases/Aggregate/aggregateViewLargeFixture.d.ts +12 -0
  6. package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.d.ts.map +1 -0
  7. package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.js +4 -0
  8. package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.js.map +1 -0
  9. package/dist/subsystem/C4Graph.d.ts +2 -69
  10. package/dist/subsystem/C4Graph.d.ts.map +1 -1
  11. package/dist/subsystem/C4Graph.js +8 -154
  12. package/dist/subsystem/C4Graph.js.map +1 -1
  13. package/dist/subsystem/C4NodeCard.d.ts +1 -47
  14. package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
  15. package/dist/subsystem/C4NodeCard.js +6 -141
  16. package/dist/subsystem/C4NodeCard.js.map +1 -1
  17. package/dist/subsystem/ContainersPanel.d.ts +33 -0
  18. package/dist/subsystem/ContainersPanel.d.ts.map +1 -0
  19. package/dist/subsystem/ContainersPanel.js +116 -0
  20. package/dist/subsystem/ContainersPanel.js.map +1 -0
  21. package/dist/subsystem/SubsystemAggregateGraph.d.ts +14 -0
  22. package/dist/subsystem/SubsystemAggregateGraph.d.ts.map +1 -1
  23. package/dist/subsystem/SubsystemAggregateGraph.js +116 -69
  24. package/dist/subsystem/SubsystemAggregateGraph.js.map +1 -1
  25. package/dist/subsystem/SubsystemComponentGraph.d.ts +18 -1
  26. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  27. package/dist/subsystem/SubsystemComponentGraph.js +143 -21
  28. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  29. package/dist/subsystem/containerCard.d.ts +132 -0
  30. package/dist/subsystem/containerCard.d.ts.map +1 -0
  31. package/dist/subsystem/containerCard.js +167 -0
  32. package/dist/subsystem/containerCard.js.map +1 -0
  33. package/dist/subsystem/graphChrome.d.ts +11 -8
  34. package/dist/subsystem/graphChrome.d.ts.map +1 -1
  35. package/dist/subsystem/graphChrome.js +11 -9
  36. package/dist/subsystem/graphChrome.js.map +1 -1
  37. package/dist/subsystem/graphMorph.d.ts +142 -0
  38. package/dist/subsystem/graphMorph.d.ts.map +1 -0
  39. package/dist/subsystem/graphMorph.js +177 -0
  40. package/dist/subsystem/graphMorph.js.map +1 -0
  41. package/dist/subsystem/model.d.ts +89 -0
  42. package/dist/subsystem/model.d.ts.map +1 -1
  43. package/dist/subsystem/model.js +224 -15
  44. package/dist/subsystem/model.js.map +1 -1
  45. package/dist/subsystem/nodes.d.ts +9 -3
  46. package/dist/subsystem/nodes.d.ts.map +1 -1
  47. package/dist/subsystem/nodes.js +134 -82
  48. package/dist/subsystem/nodes.js.map +1 -1
  49. package/dist/utils/elkLayout.d.ts +11 -0
  50. package/dist/utils/elkLayout.d.ts.map +1 -1
  51. package/dist/utils/elkLayout.js +4 -3
  52. package/dist/utils/elkLayout.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/index.ts +6 -0
  55. package/src/stories/Canvases/Aggregate/AggregateFrameGraph.stories.tsx +140 -2
  56. package/src/stories/Canvases/Aggregate/aggregateViewLargeFixture.ts +14 -0
  57. package/src/stories/Canvases/Subsystem/ContainerFrames.stories.tsx +132 -0
  58. package/src/subsystem/C4Graph.tsx +20 -180
  59. package/src/subsystem/C4NodeCard.tsx +34 -202
  60. package/src/subsystem/ContainersPanel.tsx +239 -0
  61. package/src/subsystem/SubsystemAggregateGraph.tsx +146 -78
  62. package/src/subsystem/SubsystemComponentGraph.tsx +222 -25
  63. package/src/subsystem/containerCard.tsx +264 -0
  64. package/src/subsystem/graphChrome.tsx +11 -9
  65. package/src/subsystem/graphMorph.tsx +212 -0
  66. package/src/subsystem/model.collapse.test.ts +128 -0
  67. package/src/subsystem/model.ts +306 -16
  68. package/src/subsystem/nodes.group.test.tsx +125 -16
  69. package/src/subsystem/nodes.tsx +201 -91
  70. package/src/utils/elkLayout.ts +16 -2
@@ -0,0 +1,132 @@
1
+ import '@xyflow/react/dist/style.css';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+ import { ThemeProvider, defaultEditorTheme } from '@principal-ade/industry-theme';
4
+ import { SubsystemComponentGraph } from '../../../subsystem/SubsystemComponentGraph';
5
+ import type { SubsystemComponent } from '../../../subsystem/model';
6
+ import { components, graphSpecFromSteps } from './fixtures';
7
+
8
+ const meta = {
9
+ title: 'Canvases/Subsystem/ContainerFrames',
10
+ component: SubsystemComponentGraph,
11
+ parameters: { layout: 'fullscreen' },
12
+ tags: ['autodocs'],
13
+ decorators: [
14
+ (Story) => (
15
+ <ThemeProvider theme={defaultEditorTheme}>
16
+ <Story />
17
+ </ThemeProvider>
18
+ ),
19
+ ],
20
+ } satisfies Meta<typeof SubsystemComponentGraph>;
21
+
22
+ export default meta;
23
+ type Story = StoryObj<typeof meta>;
24
+
25
+ const HOST = 'principal-studio/host';
26
+ const RENDERER = 'principal-studio/renderer';
27
+ const DB = 'principal-studio/db';
28
+
29
+ const PROCESS_OF: Record<string, string> = {
30
+ main: HOST,
31
+ store: HOST,
32
+ view: RENDERER,
33
+ bridge: RENDERER,
34
+ panel: RENDERER,
35
+ db: DB,
36
+ };
37
+
38
+ /**
39
+ * Process frames drawn as container cards — the same header a C4 container
40
+ * wears: label, kind glyph, technology row, member count. The renderer states
41
+ * no technology through `regionDetails`, so it reads React off its members'
42
+ * `framework`; the database is a data store, so it wears the database glyph.
43
+ */
44
+ const containerComponents: SubsystemComponent[] = [
45
+ ...components([
46
+ ['main', 'main', 'function', 'src/host/main.ts', 'pkg:github/principal-ai/principal-studio', 'boots the host process', 'main'],
47
+ ['store', 'SessionStore', 'store', 'src/host/store.ts', 'pkg:github/principal-ai/principal-studio', 'retained host state', 'SessionStore'],
48
+ ['view', 'TrailView', 'function', 'src/renderer/view.tsx', 'pkg:github/principal-ai/principal-studio', 'renders the trail', 'TrailView'],
49
+ ['panel', 'DetailPanel', 'function', 'src/renderer/panel.tsx', 'pkg:github/principal-ai/principal-studio', 'inspects the selected step', 'DetailPanel'],
50
+ ['bridge', 'bridge', 'function', 'src/renderer/bridge.ts', 'pkg:github/principal-ai/principal-studio', 'IPC bridge to the host', 'bridge'],
51
+ ['db', 'sessions', 'store', 'src/db/sessions.ts', 'pkg:github/principal-ai/principal-studio', 'session rows', 'sessions'],
52
+ ]).map((c) => {
53
+ const process: string | undefined = PROCESS_OF[c.alias];
54
+ const withProcess = process ? { ...c, process } : c;
55
+ return c.alias === 'view' || c.alias === 'panel'
56
+ ? { ...withProcess, framework: 'react', stereotype: 'component' }
57
+ : withProcess;
58
+ }),
59
+ {
60
+ alias: 'svc',
61
+ name: 'telemetry',
62
+ construct: 'external' as const,
63
+ file: '',
64
+ purl: 'external',
65
+ purpose: 'external telemetry sink (no process, never framed)',
66
+ role: 'service' as const,
67
+ },
68
+ ];
69
+
70
+ const containerEdges = graphSpecFromSteps([
71
+ ['main', 'store', 'writes'],
72
+ ['main', 'bridge', 'calls'],
73
+ ['bridge', 'view', 'feeds'],
74
+ ['view', 'panel', 'calls'],
75
+ ['store', 'db', 'writes'],
76
+ ['main', 'svc', 'uses'],
77
+ ]);
78
+
79
+ export const ProcessCards: Story = {
80
+ render: () => (
81
+ <div style={{ width: '100%', height: '100vh' }}>
82
+ <SubsystemComponentGraph
83
+ title="Container frames"
84
+ description="Process frames draw as container cards. The host states Bun through `regionDetails` and takes the Bun hue; the renderer derives React from its members' `framework`; the database is a data store and wears the database glyph."
85
+ components={containerComponents}
86
+ trails={containerEdges.trails}
87
+ regionDetails={{
88
+ [HOST]: {
89
+ technology: 'Bun + Electrobun',
90
+ description: 'Owns the session store and brokers IPC for the renderer.',
91
+ },
92
+ [DB]: {
93
+ technology: 'SQLite',
94
+ containerKind: 'data-store',
95
+ description: 'Local session database.',
96
+ },
97
+ }}
98
+ />
99
+ </div>
100
+ ),
101
+ };
102
+
103
+ export const UnstatedTechnology: Story = {
104
+ render: () => (
105
+ <div style={{ width: '100%', height: '100vh' }}>
106
+ <SubsystemComponentGraph
107
+ title="Unstated technology"
108
+ description="No `regionDetails`: frames with no known member framework fall back to their kind in the technology row and keep the per-key hue, so several unstated processes stay distinguishable."
109
+ components={containerComponents}
110
+ trails={containerEdges.trails}
111
+ />
112
+ </div>
113
+ ),
114
+ };
115
+
116
+ export const StartOpen: Story = {
117
+ render: () => (
118
+ <div style={{ width: '100%', height: '100vh' }}>
119
+ <SubsystemComponentGraph
120
+ title="Start open"
121
+ description="Frames start closed by default; `defaultFramesCollapsed={false}` lays every process frame out from the start. Close one from its card, by double-click, or from the Containers list in the sidebar switch."
122
+ components={containerComponents}
123
+ trails={containerEdges.trails}
124
+ defaultFramesCollapsed={false}
125
+ regionDetails={{
126
+ [HOST]: { technology: 'Bun + Electrobun' },
127
+ [DB]: { technology: 'SQLite', containerKind: 'data-store' },
128
+ }}
129
+ />
130
+ </div>
131
+ ),
132
+ };
@@ -46,6 +46,22 @@ import {
46
46
  nodeStyle,
47
47
  } from './C4NodeCard';
48
48
  import { TechMark, technologyBrand } from './techIcons';
49
+ import {
50
+ absoluteRectOf,
51
+ diffLayoutRects,
52
+ FADE_MS,
53
+ MORPH_MS,
54
+ shouldRefitCamera,
55
+ useFade,
56
+ useFlip,
57
+ useMorphStyle,
58
+ } from './graphMorph';
59
+ import type { FlowRect, FrameGrow, MorphNodeData } from './graphMorph';
60
+
61
+ // The morph vocabulary moved to `graphMorph` so the component graph can share
62
+ // it; re-exported here for callers written against this module.
63
+ export { absoluteRectOf, shouldRefitCamera } from './graphMorph';
64
+ export type { FlowRect, FrameGrow } from './graphMorph';
49
65
  import type { TechBrand } from './techIcons';
50
66
  import { GRAPH_CANVAS_CLASS, GRAPH_NAV_PROPS, GraphChrome, GraphLayerStyle } from './graphChrome';
51
67
  import type { C4Component, C4Edge, C4Element, C4Model, C4TrailRef } from './c4';
@@ -770,29 +786,9 @@ function C4GroupView(
770
786
  const SubsystemNode = SubsystemComponentNode as unknown as ComponentType<NodeProps>;
771
787
 
772
788
  function C4SubsystemNodeView(props: NodeProps) {
773
- const { growFrom, frameRect, entering, leaving, moveDelayMs = 0 } = props.data as {
774
- growFrom?: FlowRect;
775
- frameRect?: FlowRect;
776
- entering?: boolean;
777
- leaving?: boolean;
778
- moveDelayMs?: number;
779
- };
780
- const { flipping, placed, dx, dy } = useFlip(growFrom, frameRect);
781
- const sliding = flipping && (dx !== 0 || dy !== 0);
782
- const fade = useFade(entering, leaving);
783
- const transitions = [
784
- ...(fade.transition ? [fade.transition] : []),
785
- ...(sliding && placed ? [`transform ${MORPH_MS}ms ease-out ${moveDelayMs}ms`] : []),
786
- ];
789
+ const morph = useMorphStyle(props.data as MorphNodeData);
787
790
  return (
788
- <div
789
- style={{
790
- transformOrigin: 'top left',
791
- transform: sliding && !placed ? `translate(${dx}px, ${dy}px)` : 'none',
792
- transition: transitions.length > 0 ? transitions.join(', ') : 'none',
793
- opacity: fade.opacity,
794
- }}
795
- >
791
+ <div style={morph}>
796
792
  <SubsystemNode {...props} />
797
793
  </div>
798
794
  );
@@ -811,16 +807,8 @@ const edgeTypes = {
811
807
  'subsystem-edge': SubsystemEdge as never,
812
808
  };
813
809
 
814
- /** Drill-down animation durations, in ms. */
815
- const MORPH_MS = 420;
810
+ /** Camera re-frame duration, in ms. The morph's own clocks live in `graphMorph`. */
816
811
  const CAMERA_MS = 520;
817
- /**
818
- * How long cards arriving or leaving take to fade, in ms. The morph is
819
- * sequenced: the fade runs first, and the surviving cards wait it out before
820
- * they move and grow (`moveDelayMs` below). So the reveal clock is
821
- * `FADE_MS + MORPH_MS`, not just `MORPH_MS`.
822
- */
823
- const FADE_MS = 200;
824
812
  /**
825
813
  * When to re-frame the camera after a drill-down: the sequenced morph (fade,
826
814
  * then move), plus a beat.
@@ -864,80 +852,6 @@ interface Rendered {
864
852
  groupBounds: Map<string, { x: number; y: number; width: number; height: number }>;
865
853
  }
866
854
 
867
- /** Flow-space rect of a box node or a frame, for the drill-down morph. */
868
- export interface FlowRect { x: number; y: number; width: number; height: number }
869
-
870
- /** A frame's growth for the drill-down morph: its flow rect before → after. */
871
- export interface FrameGrow { from: FlowRect; to: FlowRect }
872
-
873
- /**
874
- * A node's rect in **absolute** flow space, walking the parent chain.
875
- *
876
- * `groupBounds` is already absolute; a leaf's `position` is relative to its
877
- * parent, so each ancestor's origin is added in turn.
878
- *
879
- * The FLIP needs absolute rects, not parent-relative ones. React Flow places a
880
- * node at its new absolute position (parent origin + relative position) and
881
- * moves children along with the parent's *wrapper* — while our FLIP transform
882
- * lives on the node's inner div, which the children do not inherit. So a node's
883
- * own transform must cover its full absolute delta; rebasing it to the parent
884
- * would leave it short by exactly the parent's movement (the "subtle drift"
885
- * before a leaving box disappears).
886
- */
887
- export function absoluteRectOf(
888
- layout: {
889
- nodes: ReadonlyArray<{
890
- id: string;
891
- position: { x: number; y: number };
892
- parentId?: string;
893
- width?: number | null;
894
- height?: number | null;
895
- }>;
896
- groupBounds: Map<string, { x: number; y: number; width: number; height: number }>;
897
- },
898
- id: string,
899
- ): FlowRect | null {
900
- const frame = layout.groupBounds.get(id);
901
- if (frame) return { x: frame.x, y: frame.y, width: frame.width, height: frame.height };
902
- const node = layout.nodes.find((n) => n.id === id);
903
- if (!node) return null;
904
- const origin = node.parentId ? absoluteRectOf(layout, node.parentId) : null;
905
- return {
906
- x: (origin?.x ?? 0) + node.position.x,
907
- y: (origin?.y ?? 0) + node.position.y,
908
- width: node.width ?? 0,
909
- height: node.height ?? 0,
910
- };
911
- }
912
-
913
- /**
914
- * Whether committing a layout should also move the camera.
915
- *
916
- * A morph — a commit that has rects to FLIP from — must not. Every element
917
- * already on screen is sliding from the rect the reader last saw it at, and that
918
- * anchoring *is* the morph; a viewport move on top of it makes each card's
919
- * on-screen path the sum of two independent animations, so nothing lands where
920
- * the FLIP said it would. `CAMERA_MS` also outlasts `MORPH_MS`, so the camera
921
- * would still be drifting for 100ms after the cards had settled — which is what
922
- * reads as the cards "still moving".
923
- *
924
- * A commit with no `grows` is a genuine change: the first paint, a new system, a
925
- * different element set, or the grid fallback after an ELK failure. There is no
926
- * continuity to preserve there and the content may genuinely not be on screen, so
927
- * fit.
928
- *
929
- * An *empty* map fits for the same reason — no element is anchoring, so there is
930
- * nothing a camera move could contradict. Testing the size rather than the
931
- * identity keeps that total over the whole input domain instead of leaning on a
932
- * caller convention (`growsFor` happens to hand back `null` rather than an empty
933
- * map, but nothing forces it to).
934
- *
935
- * @param grows the rects to animate from, exactly as `injectGrow` received them.
936
- */
937
- export function shouldRefitCamera(grows: Map<string, FrameGrow> | null): boolean {
938
- return !grows || grows.size === 0;
939
- }
940
-
941
855
  /**
942
856
  * Whether a card shows its description line.
943
857
  *
@@ -1093,58 +1007,6 @@ export function c4GroupDefs(
1093
1007
  return { frames, groups };
1094
1008
  }
1095
1009
 
1096
- /**
1097
- * FLIP between two absolute flow rects: render transformed back onto `from`,
1098
- * then release onto `to`.
1099
- *
1100
- * The step back **must** happen while rendering, not in an effect. An effect runs
1101
- * after the browser has already painted, so the element is painted at its new
1102
- * position for one frame and only then jumps back — a visible teleport, which is
1103
- * the exact thing this hook exists to remove. Adjusting state during render lets
1104
- * React apply the transform in the same commit, so the new position is never
1105
- * painted untransformed.
1106
- *
1107
- * The rects are keyed by value: `injectGrow` mints fresh objects each layout, so
1108
- * comparing identity would re-fire the whole morph on unrelated re-renders.
1109
- */
1110
- function useFlip(from: FlowRect | undefined, to: FlowRect | undefined) {
1111
- const key = from && to ? `${from.x},${from.y},${to.x},${to.y}` : '';
1112
- const [lastKey, setLastKey] = useState(key);
1113
- const [placed, setPlaced] = useState(!key);
1114
- if (key !== lastKey) {
1115
- setLastKey(key);
1116
- setPlaced(false);
1117
- }
1118
- useEffect(() => {
1119
- if (!key) return;
1120
- const raf = requestAnimationFrame(() => setPlaced(true));
1121
- return () => cancelAnimationFrame(raf);
1122
- }, [key]);
1123
- return {
1124
- flipping: key !== '',
1125
- placed,
1126
- dx: from && to ? from.x - to.x : 0,
1127
- dy: from && to ? from.y - to.y : 0,
1128
- };
1129
- }
1130
-
1131
- /**
1132
- * Opacity for a card arriving or leaving the layout. An arriving card mounts
1133
- * hidden and fades in; a leaving card is kept (out of the new layout) for the
1134
- * morph, then fades out — a removal reads as a fade, not a pop.
1135
- */
1136
- function useFade(entering?: boolean, leaving?: boolean) {
1137
- const animate = entering === true || leaving === true;
1138
- const [shown, setShown] = useState(entering !== true);
1139
- useEffect(() => {
1140
- if (!animate) return;
1141
- const raf = requestAnimationFrame(() => setShown(leaving !== true));
1142
- return () => cancelAnimationFrame(raf);
1143
- }, [animate, entering, leaving]);
1144
- if (!animate) return { opacity: 1, transition: undefined as string | undefined };
1145
- return { opacity: shown ? 1 : 0, transition: `opacity ${FADE_MS}ms ease` };
1146
- }
1147
-
1148
1010
  /**
1149
1011
  * Whether a nested component is withheld while the diagram is mid-morph.
1150
1012
  *
@@ -1812,29 +1674,7 @@ function Inner({ model, containerFocus, selectedNodeId, selectedEdgeId: controll
1812
1674
  if (!paintedRef.current) return null;
1813
1675
  const prevLayout = layoutCache.current.get(prevCacheKey);
1814
1676
  if (!prevLayout) return null;
1815
- const grows = new Map<string, FrameGrow>();
1816
- const cardIds = (l: Rendered) => l.nodes.map((n) => n.id);
1817
- const ids = new Set([
1818
- ...prevLayout.groupBounds.keys(),
1819
- ...next.groupBounds.keys(),
1820
- ...cardIds(prevLayout),
1821
- ...cardIds(next),
1822
- ]);
1823
- for (const id of ids) {
1824
- const fromRect = absoluteRectOf(prevLayout, id);
1825
- const to = absoluteRectOf(next, id);
1826
- if (!fromRect || !to) continue;
1827
- if (
1828
- fromRect.x === to.x &&
1829
- fromRect.y === to.y &&
1830
- fromRect.width === to.width &&
1831
- fromRect.height === to.height
1832
- ) {
1833
- continue;
1834
- }
1835
- grows.set(id, { from: fromRect, to });
1836
- }
1837
- return grows.size > 0 ? grows : null;
1677
+ return diffLayoutRects(prevLayout, next);
1838
1678
  };
1839
1679
 
1840
1680
  // Commit a new layout: keep the survivors gliding (FLIP), fade in cards the
@@ -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
+ }