@principal-ai/subsystems-react 0.56.35 → 0.56.36

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 (43) hide show
  1. package/dist/subsystem/SubsystemComponentGraph.d.ts +50 -8
  2. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  3. package/dist/subsystem/SubsystemComponentGraph.js +291 -50
  4. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  5. package/dist/subsystem/TrailStepsNav.d.ts +1 -1
  6. package/dist/subsystem/TrailStepsNav.d.ts.map +1 -1
  7. package/dist/subsystem/TrailStepsNav.js +2 -1
  8. package/dist/subsystem/TrailStepsNav.js.map +1 -1
  9. package/dist/subsystem/TrailsPanel.d.ts +5 -5
  10. package/dist/subsystem/TrailsPanel.d.ts.map +1 -1
  11. package/dist/subsystem/TrailsPanel.js +23 -43
  12. package/dist/subsystem/TrailsPanel.js.map +1 -1
  13. package/dist/subsystem/model.d.ts +21 -6
  14. package/dist/subsystem/model.d.ts.map +1 -1
  15. package/dist/subsystem/model.js +48 -45
  16. package/dist/subsystem/model.js.map +1 -1
  17. package/dist/subsystem/nodeIconography.d.ts +25 -0
  18. package/dist/subsystem/nodeIconography.d.ts.map +1 -0
  19. package/dist/subsystem/nodeIconography.js +55 -0
  20. package/dist/subsystem/nodeIconography.js.map +1 -0
  21. package/dist/subsystem/nodes.d.ts +4 -3
  22. package/dist/subsystem/nodes.d.ts.map +1 -1
  23. package/dist/subsystem/nodes.js +125 -211
  24. package/dist/subsystem/nodes.js.map +1 -1
  25. package/dist/subsystem/stepEmphasis.d.ts +5 -0
  26. package/dist/subsystem/stepEmphasis.d.ts.map +1 -1
  27. package/dist/subsystem/stepEmphasis.js +7 -0
  28. package/dist/subsystem/stepEmphasis.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/stories/Canvases/Subsystem/AgentDrivenWalkthrough.stories.tsx +229 -157
  31. package/src/stories/Canvases/Subsystem/Deprecated.stories.tsx +1 -1
  32. package/src/stories/Canvases/Subsystem/NodeAnatomy.stories.tsx +17 -21
  33. package/src/stories/Canvases/Subsystem/NodeIconography.stories.tsx +791 -21
  34. package/src/stories/Canvases/Subsystem/Spotlights.stories.tsx +1 -1
  35. package/src/subsystem/SubsystemComponentGraph.tsx +359 -62
  36. package/src/subsystem/TrailStepsNav.tsx +2 -2
  37. package/src/subsystem/TrailsPanel.tsx +35 -89
  38. package/src/subsystem/model.test.ts +17 -13
  39. package/src/subsystem/model.ts +60 -48
  40. package/src/subsystem/nodeIconography.ts +88 -0
  41. package/src/subsystem/nodes.component.test.tsx +177 -0
  42. package/src/subsystem/nodes.tsx +225 -268
  43. package/src/subsystem/stepEmphasis.ts +8 -0
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useState } from 'react';
2
2
  import type { CSSProperties, ReactNode } from 'react';
3
3
  import { ChevronRight, Route, X } from 'lucide-react';
4
4
  import { useTheme } from '@principal-ade/industry-theme';
5
- import type { SubsystemTrail } from './model';
5
+ import { HOST_PROPOSAL_COLOR, type SubsystemTrail } from './model';
6
6
  import {
7
7
  trailStepDisplay,
8
8
  type TrailComponentLabels,
@@ -246,7 +246,7 @@ export function TrailStepsNav({
246
246
  flexShrink: 0,
247
247
  marginTop: 3,
248
248
  color: proposed
249
- ? (theme.colors.warning ?? '#d4a017')
249
+ ? HOST_PROPOSAL_COLOR
250
250
  : theme.colors.primary,
251
251
  }}
252
252
  />
@@ -19,6 +19,7 @@ import {
19
19
  reorderTargetIndex,
20
20
  reorderTrails,
21
21
  trailStepGraphEdgeId,
22
+ HOST_PROPOSAL_COLOR,
22
23
  type SubsystemTrail,
23
24
  type SubsystemTrailStep,
24
25
  } from './model';
@@ -95,9 +96,9 @@ function TrailFlow({
95
96
  hideHeader = false,
96
97
  proposed = false,
97
98
  proposedStepKeys,
99
+ focusedVariationStepIndexes,
100
+ stepNumberLabels,
98
101
  stepChange,
99
- showPreviousStep = true,
100
- onTogglePreviousStep,
101
102
  }: {
102
103
  trail: SubsystemTrail;
103
104
  collapsed: boolean;
@@ -142,15 +143,15 @@ function TrailFlow({
142
143
  proposed?: boolean;
143
144
  /** Host-local proposed steps, keyed by `emphasisKey(trailId, step)`. */
144
145
  proposedStepKeys?: Set<string>;
146
+ /** Step indexes that belong to one focused variation group in this flow. */
147
+ focusedVariationStepIndexes?: ReadonlySet<number>;
148
+ /** Display labels overriding the default `i + 1`, keyed by `emphasisKey`. */
149
+ stepNumberLabels?: ReadonlyMap<string, string>;
145
150
  /** Host-local before/after view for an accepted step replacement. */
146
151
  stepChange?: TrailsStepChange | null;
147
- /** Whether the previous-state ghost is visible. @default true */
148
- showPreviousStep?: boolean;
149
- /** Dismiss or restore just the previous-state ghost. */
150
- onTogglePreviousStep?: () => void;
151
152
  }) {
152
153
  const { theme } = useTheme();
153
- const proposalColor = theme.colors.warning ?? '#d4a017';
154
+ const proposalColor = HOST_PROPOSAL_COLOR;
154
155
  const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
155
156
  const hoverBg = theme.colors.background;
156
157
  const wholeFlowActive = active !== null && active.stepIndex === null;
@@ -536,19 +537,23 @@ function TrailFlow({
536
537
  }}
537
538
  >
538
539
  {trail.steps.map((step, i) => {
539
- const stepActive = active !== null && active.stepIndex === i;
540
+ // A staged variation and the step it would replace are focused as
541
+ // one group, even though the host only names one active step.
542
+ const stepActive =
543
+ (active !== null && active.stepIndex === i) ||
544
+ (focusedVariationStepIndexes?.has(i) ?? false);
540
545
  const copied = copiedStep === i;
541
- const record = stepEmphasis?.get(emphasisKey(trail.id, step));
542
- const stepProposed =
543
- proposed || (proposedStepKeys?.has(emphasisKey(trail.id, step)) ?? false);
546
+ const stepKey = emphasisKey(trail.id, step);
547
+ const record = stepEmphasis?.get(stepKey);
548
+ const stepProposed = proposed || (proposedStepKeys?.has(stepKey) ?? false);
549
+ const stepNumber = stepNumberLabels?.get(stepKey) ?? String(i + 1);
544
550
  const display = trailStepDisplay(step, componentByAlias);
551
+ // The original step keeps its row after acceptance; only its
552
+ // annotation is greyed. Its `2a` variation stays beside it.
545
553
  const previousStep =
546
554
  stepChange?.trailId === trail.id && stepChange.stepIndex === i
547
555
  ? stepChange.previous
548
556
  : null;
549
- const previousDisplay = previousStep
550
- ? trailStepDisplay(previousStep, componentByAlias)
551
- : null;
552
557
  // Calls nest; uses/data steps sit at their anchor frame's depth.
553
558
  const stackDepth = buildTrailStack(
554
559
  trail,
@@ -627,7 +632,7 @@ function TrailFlow({
627
632
  : muted,
628
633
  }}
629
634
  >
630
- {copied ? <Check size={12} strokeWidth={2} aria-hidden /> : i + 1}
635
+ {copied ? <Check size={12} strokeWidth={2} aria-hidden /> : stepNumber}
631
636
  </span>
632
637
  <span
633
638
  style={{
@@ -647,7 +652,11 @@ function TrailFlow({
647
652
  overflowWrap: 'anywhere',
648
653
  fontSize: theme.fontSizes[1],
649
654
  fontFamily: theme.fonts.monospace,
650
- color: stepProposed ? proposalColor : theme.colors.primary,
655
+ color: previousStep
656
+ ? muted
657
+ : stepProposed
658
+ ? proposalColor
659
+ : theme.colors.primary,
651
660
  lineHeight: 1.35,
652
661
  }}
653
662
  >
@@ -667,69 +676,6 @@ function TrailFlow({
667
676
  </span>
668
677
  </span>
669
678
  </button>
670
- {previousStep && previousDisplay && (
671
- <div
672
- style={{
673
- display: 'flex',
674
- alignItems: 'flex-start',
675
- gap: 8,
676
- padding: `0 12px 10px ${stepInset + 14 + 8}px`,
677
- }}
678
- >
679
- {showPreviousStep ? (
680
- <span
681
- aria-label="previous step state"
682
- style={{
683
- flex: 1,
684
- minWidth: 0,
685
- borderLeft: `1px dashed ${theme.colors.border ?? '#2d3034'}`,
686
- paddingLeft: 8,
687
- color: muted,
688
- fontFamily: theme.fonts.monospace,
689
- fontSize: theme.fontSizes[0],
690
- lineHeight: 1.5,
691
- opacity: 0.85,
692
- }}
693
- >
694
- <span style={{ textDecoration: 'line-through' }}>
695
- Was: {previousStep.annotation ?? previousDisplay.primary}
696
- </span>
697
- {previousStep.annotation && (
698
- <span
699
- style={{ display: 'block', textDecoration: 'line-through' }}
700
- >
701
- {previousDisplay.primary}
702
- </span>
703
- )}
704
- </span>
705
- ) : null}
706
- {onTogglePreviousStep && (
707
- <button
708
- type="button"
709
- onClick={onTogglePreviousStep}
710
- aria-label={
711
- showPreviousStep
712
- ? 'Hide previous step state'
713
- : 'Show previous step state'
714
- }
715
- style={{
716
- flexShrink: 0,
717
- padding: '2px 6px',
718
- borderRadius: 4,
719
- border: `1px solid ${theme.colors.border ?? '#2d3034'}`,
720
- background: 'transparent',
721
- color: muted,
722
- fontFamily: theme.fonts.monospace,
723
- fontSize: theme.fontSizes[0],
724
- cursor: 'pointer',
725
- whiteSpace: 'nowrap',
726
- }}
727
- >
728
- {showPreviousStep ? 'Hide old' : 'Show old'}
729
- </button>
730
- )}
731
- </div>
732
- )}
733
679
  {record && (
734
680
  <span
735
681
  aria-hidden
@@ -847,12 +793,12 @@ export interface TrailsPanelProps {
847
793
  proposedTrailIds?: Set<string>;
848
794
  /** Host-local steps awaiting confirmation, keyed by `emphasisKey`. */
849
795
  proposedStepKeys?: Set<string>;
796
+ /** Step indexes that belong to one focused variation group, by trail id. */
797
+ focusedVariationStepIndexes?: ReadonlyMap<string, ReadonlySet<number>>;
798
+ /** Display labels overriding the default `i + 1`, keyed by `emphasisKey`. */
799
+ stepNumberLabels?: ReadonlyMap<string, string>;
850
800
  /** Host-local before/after view for an accepted step replacement. */
851
801
  stepChange?: TrailsStepChange | null;
852
- /** Whether the previous-state ghost is visible. @default true */
853
- showPreviousStep?: boolean;
854
- /** Dismiss or restore just the previous-state ghost. */
855
- onTogglePreviousStep?: () => void;
856
802
  }
857
803
 
858
804
  /**
@@ -883,9 +829,9 @@ export function TrailsPanel({
883
829
  detailContent,
884
830
  proposedTrailIds,
885
831
  proposedStepKeys,
832
+ focusedVariationStepIndexes,
833
+ stepNumberLabels,
886
834
  stepChange,
887
- showPreviousStep,
888
- onTogglePreviousStep,
889
835
  }: TrailsPanelProps) {
890
836
  const { theme } = useTheme();
891
837
  // Reordering is offered only while every row is collapsed: the compact list
@@ -1075,9 +1021,9 @@ export function TrailsPanel({
1075
1021
  onRemoveStepEmphasis={onRemoveStepEmphasis}
1076
1022
  proposed={proposedTrailIds?.has(tl.id) ?? false}
1077
1023
  proposedStepKeys={proposedStepKeys}
1024
+ focusedVariationStepIndexes={focusedVariationStepIndexes?.get(tl.id)}
1025
+ stepNumberLabels={stepNumberLabels}
1078
1026
  stepChange={stepChange}
1079
- showPreviousStep={showPreviousStep}
1080
- onTogglePreviousStep={onTogglePreviousStep}
1081
1027
  />
1082
1028
  </div>
1083
1029
  );
@@ -1129,9 +1075,9 @@ export function TrailsPanel({
1129
1075
  onRemoveStepEmphasis={onRemoveStepEmphasis}
1130
1076
  proposed={proposedTrailIds?.has(trail.id) ?? false}
1131
1077
  proposedStepKeys={proposedStepKeys}
1078
+ focusedVariationStepIndexes={focusedVariationStepIndexes?.get(trail.id)}
1079
+ stepNumberLabels={stepNumberLabels}
1132
1080
  stepChange={stepChange}
1133
- showPreviousStep={showPreviousStep}
1134
- onTogglePreviousStep={onTogglePreviousStep}
1135
1081
  />
1136
1082
  )}
1137
1083
  />
@@ -36,7 +36,7 @@ import {
36
36
  rightBadgeLabel,
37
37
  nodeMinWidthForBadges,
38
38
  estimateBadgeLabelWidth,
39
- BADGE_EDGE_INSET,
39
+ COMPONENT_NODE_HEIGHT,
40
40
  formatPurl,
41
41
  packageColor,
42
42
  subsystemGraphLayoutKey,
@@ -86,6 +86,7 @@ describe('subsystem graph model', () => {
86
86
  const components = nodes.filter((n) => n.type === 'subsystem-component');
87
87
  expect(components).toHaveLength(comps.length);
88
88
  expect(components.every((n) => n.type === 'subsystem-component')).toBe(true);
89
+ expect(components.every((n) => n.height === COMPONENT_NODE_HEIGHT)).toBe(true);
89
90
  });
90
91
 
91
92
  test('converts edges with directed markers', () => {
@@ -193,7 +194,7 @@ describe('subsystem graph model', () => {
193
194
  ).toBe('Person');
194
195
  expect(
195
196
  constructBadgeLabel({ construct: 'custom_entity' }),
196
- ).toBe('custom_entity');
197
+ ).toBe('custom entity');
197
198
  });
198
199
 
199
200
  test('constructBadgeColor uses React brand only for framework stereotype badges', () => {
@@ -205,16 +206,16 @@ describe('subsystem graph model', () => {
205
206
  expect(constructBadgeColor({ framework: 'vue', stereotype: 'component' })).toBeNull();
206
207
  });
207
208
 
208
- test('nodeMinWidthForBadges widens for long construct badges and role pairs', () => {
209
+ test('nodeMinWidthForBadges sizes primary and secondary rows independently', () => {
209
210
  const plain = nodeMinWidthForBadges({ construct: 'function' });
210
- expect(plain).toBe(150);
211
+ expect(plain).toBe(200);
211
212
 
212
213
  const stereotype = nodeMinWidthForBadges({
213
214
  construct: 'function',
214
215
  framework: 'react',
215
216
  stereotype: 'component',
216
217
  });
217
- expect(stereotype).toBeGreaterThan(150);
218
+ expect(stereotype).toBeGreaterThan(plain);
218
219
 
219
220
  const withRole = nodeMinWidthForBadges({
220
221
  construct: 'function',
@@ -222,14 +223,17 @@ describe('subsystem graph model', () => {
222
223
  stereotype: 'component',
223
224
  role: 'entry',
224
225
  });
225
- expect(withRole).toBeGreaterThan(stereotype);
226
-
227
- // The pair floor must leave a real gap between the left and right badge,
228
- // over and above both insets — regression: the node border was omitted from
229
- // the floor, and the char width was underestimated, so the two badges met.
230
- const left = estimateBadgeLabelWidth(constructBadgeLabel({ construct: 'function' }));
231
- const right = estimateBadgeLabelWidth(rightBadgeLabel({ role: 'entry' })!);
232
- expect(withRole).toBeGreaterThan(left + right + 2 * BADGE_EDGE_INSET);
226
+ // The secondary role chip is narrower than the React primary row, so it
227
+ // must not widen the node merely by being present.
228
+ expect(withRole).toBe(stereotype);
229
+
230
+ const withSecondaryCluster = nodeMinWidthForBadges({
231
+ construct: 'store',
232
+ role: 'service',
233
+ declaration: { kind: 'store', storage: 'memory', properties: [] },
234
+ });
235
+ expect(withSecondaryCluster).toBeGreaterThan(plain);
236
+ expect(estimateBadgeLabelWidth('MEMORY')).toBeGreaterThan(estimateBadgeLabelWidth('DB'));
233
237
  });
234
238
 
235
239
  test('rightBadgeLabel reports the role', () => {
@@ -1346,6 +1346,12 @@ export interface SubsystemGraphEdgeData extends Record<string, unknown> {
1346
1346
  /** True while another edge is selected — render this edge (and its label)
1347
1347
  * dimmed to focus the selected relationship. */
1348
1348
  dimmed?: boolean;
1349
+ /** Host-local previous state of a changed/removed step. Still laid out and
1350
+ * focused with its replacement, but rendered as a dim dashed ghost. */
1351
+ ghost?: boolean;
1352
+ /** Host-local step change awaiting confirmation. Laid out and focused with
1353
+ * the existing step, but rendered as a proposal-colored dashed edge. */
1354
+ proposed?: boolean;
1349
1355
  /**
1350
1356
  * How many edges this line stands for, when a collapsed frame rolled them up
1351
1357
  * (one line per source/target/mechanism). Absent on an ordinary edge.
@@ -1406,6 +1412,14 @@ export const MECHANISM_COLOR: Record<SubsystemEdgeMechanism, string> = {
1406
1412
  'registers-into': '#ff6b35', // orange
1407
1413
  };
1408
1414
 
1415
+ /**
1416
+ * Host-local proposal chrome. A proposal is agent/UI state, not a mechanism,
1417
+ * so it must not borrow a mechanism or warning hue. This is a deeper standard
1418
+ * purple: clear of `writes` orange (the old collision), and darker than the
1419
+ * light `produces` violet so the two still separate at a glance.
1420
+ */
1421
+ export const HOST_PROPOSAL_COLOR = '#9333ea';
1422
+
1409
1423
  export const MECHANISM_STYLE: Record<SubsystemEdgeMechanism, 'solid' | 'dashed' | 'dotted'> = {
1410
1424
  calls: 'solid',
1411
1425
  uses: 'solid',
@@ -1742,7 +1756,11 @@ export function constructBadgeLabel(component: {
1742
1756
  return component.entityKind;
1743
1757
  }
1744
1758
  const constructLabel =
1745
- component.construct === 'type_alias' ? 'type alias' : component.construct;
1759
+ component.construct === 'type_alias'
1760
+ ? 'type alias'
1761
+ : component.construct === 'custom_entity'
1762
+ ? 'custom entity'
1763
+ : component.construct;
1746
1764
  if (component.stereotype && component.framework) {
1747
1765
  return `${component.framework} · ${component.stereotype}`;
1748
1766
  }
@@ -1764,37 +1782,33 @@ export function constructBadgeColor(component: {
1764
1782
  }
1765
1783
 
1766
1784
  /** Default CSS floor for component nodes (padding aside). */
1767
- export const NODE_CSS_MIN_WIDTH = 150;
1768
- /** Inset of each top badge from the node edge (`left` / `right` style). */
1785
+ export const NODE_CSS_MIN_WIDTH = 200;
1786
+ /** @deprecated Retained for deep-import compatibility; the new layout uses inline rows. */
1769
1787
  export const BADGE_EDGE_INSET = 5;
1770
- /** Minimum gap between left construct badge and right role badge. */
1771
- const BADGE_PAIR_GAP = 8;
1772
- /**
1773
- * Node border thickness reserved on each side of the badge span. Top badges are
1774
- * positioned from the padding edge (inside the border), so a `left: 5px` badge
1775
- * starts `border + inset` from the border-box edge. Reserve the widest border
1776
- * (4px when selected / file-matched) so the pair gap survives selection.
1777
- */
1778
- const BADGE_NODE_BORDER = 4;
1779
- /** Badge box chrome: padding 8+8 + border 2+2. */
1780
- const BADGE_BOX_CHROME = 20;
1781
- /**
1782
- * Approx monospace uppercase advance incl. letter-spacing. Badge font is
1783
- * 13.2px; Fira Code / SF Mono / Courier all sit at ~0.6em (7.9px) plus 0.5px
1784
- * tracking ≈ 8.4px. Rounded up so estimates never undershoot — an undershoot
1785
- * eats into BADGE_PAIR_GAP and lets the left/right badges touch.
1786
- */
1788
+ /** Measured component-node height: primary icon row, name, and optional identity. */
1789
+ export const COMPONENT_NODE_HEIGHT = 96;
1790
+ /** Horizontal padding (16px per side) plus the widest border (4px). */
1791
+ const NODE_HORIZONTAL_CHROME = 36;
1792
+ /** Primary icon slot and the gap before its inline label. */
1793
+ const PRIMARY_ICON_SLOT = 24;
1794
+ const PRIMARY_LABEL_GAP = 6;
1795
+ /** Secondary icon, label gap, and box chrome (padding + border). */
1796
+ const SECONDARY_ICON_SIZE = 14;
1797
+ const SECONDARY_LABEL_GAP = 5;
1798
+ const SECONDARY_BOX_CHROME = 20;
1799
+ const SECONDARY_BADGE_GAP = 6;
1800
+ /** Approx monospace uppercase advance incl. letter-spacing. */
1787
1801
  const BADGE_CHAR_WIDTH = 8.5;
1788
1802
 
1789
- /** Estimated rendered width of a top tab badge label. */
1803
+ /** Estimated rendered width of a secondary text badge, including its box. */
1790
1804
  export function estimateBadgeLabelWidth(label: string): number {
1791
- return (label?.length ?? 0) * BADGE_CHAR_WIDTH + BADGE_BOX_CHROME;
1805
+ return (label?.length ?? 0) * BADGE_CHAR_WIDTH + SECONDARY_BOX_CHROME;
1792
1806
  }
1793
1807
 
1794
1808
  /**
1795
- * Minimum node width so top badges stay on one line and (when both are
1796
- * present) don't overlap — badges are absolutely positioned, so they don't
1797
- * contribute to layout unless we widen the node explicitly.
1809
+ * Minimum node width for the new icon-plus-label layout. The primary row and
1810
+ * secondary cluster are on different edges, so their widths are independent
1811
+ * constraints rather than one combined left/right pair.
1798
1812
  */
1799
1813
  export function nodeMinWidthForBadges(component: {
1800
1814
  construct: SubsystemComponentConstruct;
@@ -1805,30 +1819,28 @@ export function nodeMinWidthForBadges(component: {
1805
1819
  entityKind?: string;
1806
1820
  declaration?: AnyComponentDetail;
1807
1821
  }): number {
1808
- const left = estimateBadgeLabelWidth(constructBadgeLabel(component));
1809
- const rightBadges = [
1822
+ const primaryLabel = constructBadgeLabel(component);
1823
+ const primaryTextWidth = Math.max(0, estimateBadgeLabelWidth(primaryLabel) - SECONDARY_BOX_CHROME);
1824
+ const primaryWidth = PRIMARY_ICON_SLOT + PRIMARY_LABEL_GAP + primaryTextWidth;
1825
+ const secondaryLabels = [
1810
1826
  storageBadgeLabel(component),
1811
1827
  rightBadgeLabel(component),
1812
1828
  deprecatedBadgeLabel(component),
1813
- ].filter((l): l is string => l != null);
1814
- if (rightBadges.length === 0) {
1815
- return Math.max(
1816
- NODE_CSS_MIN_WIDTH,
1817
- BADGE_NODE_BORDER + BADGE_EDGE_INSET + left + BADGE_EDGE_INSET + BADGE_NODE_BORDER,
1818
- );
1819
- }
1820
- const right = rightBadges
1821
- .map(estimateBadgeLabelWidth)
1822
- .reduce((acc, w) => acc + BADGE_PAIR_GAP + w);
1829
+ ].filter((label): label is string => label != null);
1830
+ const secondaryWidth = secondaryLabels.reduce(
1831
+ (width, label) =>
1832
+ width +
1833
+ SECONDARY_BADGE_GAP +
1834
+ SECONDARY_ICON_SIZE +
1835
+ SECONDARY_LABEL_GAP +
1836
+ Math.max(0, estimateBadgeLabelWidth(label) - SECONDARY_BOX_CHROME) +
1837
+ SECONDARY_BOX_CHROME,
1838
+ 0,
1839
+ );
1823
1840
  return Math.max(
1824
1841
  NODE_CSS_MIN_WIDTH,
1825
- BADGE_NODE_BORDER +
1826
- BADGE_EDGE_INSET +
1827
- left +
1828
- BADGE_PAIR_GAP +
1829
- right +
1830
- BADGE_EDGE_INSET +
1831
- BADGE_NODE_BORDER,
1842
+ primaryWidth + NODE_HORIZONTAL_CHROME,
1843
+ secondaryWidth + NODE_HORIZONTAL_CHROME,
1832
1844
  );
1833
1845
  }
1834
1846
 
@@ -1878,10 +1890,10 @@ export function convertSubsystemToNodes(
1878
1890
  .sort((a, b) => b.length - a.length)[0];
1879
1891
  const cap = maxNodeWidth ?? 300;
1880
1892
  const textWidth = Math.min(cap, Math.max(60, (text?.length ?? 10) * 8));
1881
- // Account for CSS minWidth (incl. top badges) and padding/border so ELK's
1882
- // port positions match the actual rendered node boundaries.
1893
+ // Account for the primary icon row, secondary badge cluster, and the
1894
+ // node's horizontal padding/border so ELK ports match rendered bounds.
1883
1895
  const cssMinWidth = nodeMinWidthForBadges(c);
1884
- const cssPadding = 20; // horizontal padding (left + right)
1896
+ const cssPadding = 32; // 16px horizontal padding per side
1885
1897
  const cssBorder = 4; // 2px border each side
1886
1898
  const rawWidth = Math.max(cssMinWidth, textWidth + cssPadding + cssBorder);
1887
1899
  const nodeWidth = Math.max(cssMinWidth, Math.min(cap, rawWidth));
@@ -1898,7 +1910,7 @@ export function convertSubsystemToNodes(
1898
1910
  ...(parentId ? { parentId } : {}),
1899
1911
  position: { x: PAD + col * COL_W, y: cursorY + row * ROW_H },
1900
1912
  width: nodeWidth,
1901
- height: 84,
1913
+ height: COMPONENT_NODE_HEIGHT,
1902
1914
  data: { component: c },
1903
1915
  });
1904
1916
  });
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Shared icon vocabulary for subsystem component nodes.
3
+ *
4
+ * Primary icons identify what a node is. Secondary icons identify orthogonal
5
+ * facts (role, storage backing, deprecation), and state icons identify
6
+ * host-local lifecycle markers. Keeping the mappings here prevents the canvas,
7
+ * stories, and tests from drifting apart.
8
+ */
9
+
10
+ import {
11
+ Archive,
12
+ Bot,
13
+ Database,
14
+ HardDrive,
15
+ Layers3,
16
+ List,
17
+ LogIn,
18
+ MemoryStick,
19
+ Network,
20
+ Server,
21
+ SquareFunction,
22
+ Type,
23
+ Unplug,
24
+ UserRound,
25
+ Workflow,
26
+ createLucideIcon,
27
+ type LucideIcon,
28
+ } from 'lucide-react';
29
+ import type {
30
+ SubsystemComponentConstruct,
31
+ SubsystemComponentRole,
32
+ } from './model';
33
+
34
+ /** The curled standalone `f` from Lucide's SquareFunction, without its box. */
35
+ export const FunctionLetter = createLucideIcon('FunctionLetter', [
36
+ ['path', { d: 'M9 17c2 0 2.8-1 2.8-2.8V10c0-2 1-3.3 3.2-3', key: 'f-stem' }],
37
+ ['path', { d: 'M9 11.2h5.7', key: 'f-crossbar' }],
38
+ ]);
39
+
40
+ /** A class declaration: an outlined box with a `C`. */
41
+ export const ClassGlyph = createLucideIcon('ClassGlyph', [
42
+ ['rect', { x: '3', y: '3', width: '18', height: '18', rx: '2', key: 'class-box' }],
43
+ ['path', { d: 'M16 7.5a5.5 5.5 0 1 0 0 9', key: 'class-c' }],
44
+ ]);
45
+
46
+ export const CONSTRUCT_ICON: Record<SubsystemComponentConstruct, LucideIcon> = {
47
+ function: FunctionLetter,
48
+ class: ClassGlyph,
49
+ method: SquareFunction,
50
+ interface: Unplug,
51
+ type_alias: Type,
52
+ enum: List,
53
+ store: Layers3,
54
+ external: Network,
55
+ custom_entity: UserRound,
56
+ };
57
+
58
+ const ENTITY_ICON: Record<string, LucideIcon> = {
59
+ person: UserRound,
60
+ agent: Bot,
61
+ service: Server,
62
+ queue: List,
63
+ };
64
+
65
+ /** Custom entities use their authored kind when it has a known glyph. */
66
+ export function iconForComponent(component: {
67
+ construct: SubsystemComponentConstruct;
68
+ entityKind?: string;
69
+ }): LucideIcon {
70
+ if (component.construct !== 'custom_entity') {
71
+ return CONSTRUCT_ICON[component.construct];
72
+ }
73
+ const kind = component.entityKind?.trim().toLowerCase() ?? '';
74
+ return ENTITY_ICON[kind] ?? CONSTRUCT_ICON.custom_entity;
75
+ }
76
+
77
+ export const ROLE_ICON: Record<SubsystemComponentRole, LucideIcon> = {
78
+ entry: LogIn,
79
+ service: Workflow,
80
+ };
81
+
82
+ export const STORAGE_ICON: Record<string, LucideIcon> = {
83
+ memory: MemoryStick,
84
+ disk: HardDrive,
85
+ external: Database,
86
+ };
87
+
88
+ export const DEPRECATED_ICON = Archive;