@principal-ai/subsystems-react 0.56.20 → 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 +27 -1
  18. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  19. package/dist/subsystem/SubsystemComponentGraph.js +147 -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 +232 -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
@@ -37,6 +37,7 @@ import {
37
37
  packageColor,
38
38
  FOLDER_FRAME_COLOR,
39
39
  isFolderFrame,
40
+ isCardFrame,
40
41
  type SubsystemGraphNodeData,
41
42
  type SubsystemGroupNodeData,
42
43
  type SubsystemGraphEdge,
@@ -45,7 +46,19 @@ import {
45
46
  import { componentColor } from '../pierre/constructColors';
46
47
  import { resolvePierreSyntaxThemeName } from '../pierre/pierreSyntaxTheme';
47
48
  import { ISSUE_KIND_ICON, ISSUE_RUNG_ICON } from './IssueList';
48
- import { Package, Search } from 'lucide-react';
49
+ import {
50
+ CARD_GAP,
51
+ CARD_PAD_X,
52
+ CARD_PAD_Y,
53
+ ContainerCardHeader,
54
+ NODE_H,
55
+ NODE_W,
56
+ TOGGLE_INSET,
57
+ TOGGLE_SIZE,
58
+ } from './containerCard';
59
+ import { MORPH_MS } from './graphMorph';
60
+ import { technologyBrand } from './techIcons';
61
+ import { AppWindow, Component, Database, Maximize2, Minimize2, Package, Search } from 'lucide-react';
49
62
  import type { LucideIcon } from 'lucide-react';
50
63
 
51
64
  export const CONSTRUCT_LABEL: Record<string, string> = {
@@ -555,11 +568,166 @@ export function SubsystemComponentNode(props: NodeProps<Node<SubsystemGraphNodeD
555
568
  }
556
569
 
557
570
  /**
558
- * Boundary frame — a React Flow parent node for a process or module region.
559
- * Members render inside via `parentId`; this draws the labeled container only
560
- * (no handles, no selection). Border color derives from the region key.
571
+ * Boundary frame — a React Flow parent node for a process, package or module
572
+ * region. Members render inside via `parentId`; this draws the container only
573
+ * (no handles, no selection).
574
+ *
575
+ * Two chromes. A process or package is a container in the C4 sense, so it draws
576
+ * as a container *card*: filled body, and the same header a `C4NodeCard` wears —
577
+ * label, kind glyph, technology row, member count. A module or directory is a
578
+ * code folder, not a container, so it keeps the bare dashed frame with a
579
+ * collapsible path badge.
561
580
  */
562
581
  export function SubsystemGroupNode(props: NodeProps<Node<SubsystemGroupNodeData, 'subsystem-group'>>) {
582
+ const region = props.data.region;
583
+ if (!region) return null;
584
+ return isCardFrame(region) ? <CardFrame {...props} /> : <BadgeFrame {...props} />;
585
+ }
586
+
587
+ /**
588
+ * The container-card chrome for a process / package frame.
589
+ *
590
+ * Colour follows the technology when we hold its mark (the C4 card's rule), so a
591
+ * Bun process and a React renderer read apart at a glance; a region with no known
592
+ * technology keeps the per-key hash, which is what keeps several unstated
593
+ * processes distinguishable. Dash and radius keep the component graph's own
594
+ * encoding: a process is a deployment unit (solid, slight radius), a package is
595
+ * code organisation (dashed, rounded).
596
+ */
597
+ function CardFrame(props: NodeProps<Node<SubsystemGroupNodeData, 'subsystem-group'>>) {
598
+ const { theme } = useTheme();
599
+ const { data, width, height, selected } = props as unknown as {
600
+ data: SubsystemGroupNodeData;
601
+ width?: number;
602
+ height?: number;
603
+ selected?: boolean;
604
+ };
605
+ const region = data.region;
606
+ const brand = technologyBrand(region.technology);
607
+ // Explicit host override wins; then the technology's brand hue; then the hash.
608
+ const color = data.color ?? brand?.color ?? packageColor(region.key);
609
+ const dimmed = data.dimmed === true;
610
+ const hidden = (data as { hidden?: boolean }).hidden === true;
611
+ const collapsed = data.collapsed === true;
612
+ const isPackage = region.kind === 'package' || region.chrome === 'package';
613
+ const frameStyle = !isPackage || selected ? 'solid' : 'dashed';
614
+ const frameRadius = isPackage ? 12 : 4;
615
+ const containerKind = region.containerKind ?? 'application';
616
+ const Icon = isPackage ? Package : containerKind === 'data-store' ? Database : AppWindow;
617
+ // The technology row falls back to the kind so it is never blank — the same
618
+ // fallback the C4 card uses.
619
+ const topLabel = region.technology ?? (isPackage ? 'package' : containerKind);
620
+ const ToggleIcon = collapsed ? Maximize2 : Minimize2;
621
+
622
+ return (
623
+ <div
624
+ title={region.description}
625
+ style={{
626
+ position: 'relative',
627
+ width: width ?? (collapsed ? NODE_W : 400),
628
+ height: height ?? (collapsed ? NODE_H : 300),
629
+ boxSizing: 'border-box',
630
+ borderRadius: frameRadius,
631
+ border: `2px ${frameStyle} ${color}`,
632
+ background: theme.colors.backgroundSecondary ?? theme.colors.background,
633
+ boxShadow: '0 1px 4px rgba(0,0,0,0.25)',
634
+ opacity: hidden ? 0 : dimmed ? 0.35 : 1,
635
+ // React Flow snaps the wrapper to the new size; this box eases between
636
+ // the open frame and the closed card so the toggle reads as a grow /
637
+ // shrink rather than a swap.
638
+ transition: `opacity 150ms ease, width ${MORPH_MS}ms ease, height ${MORPH_MS}ms ease`,
639
+ pointerEvents: 'none',
640
+ fontFamily: theme.fonts.body,
641
+ }}
642
+ >
643
+ {/* The header sits in the band ELK reserved above the members
644
+ (`OPEN_HEADER_PAD`), inset by the card's own padding. */}
645
+ <div
646
+ style={{
647
+ position: 'absolute',
648
+ top: 0,
649
+ left: 0,
650
+ right: 0,
651
+ display: 'flex',
652
+ flexDirection: 'column',
653
+ gap: CARD_GAP,
654
+ padding: `${CARD_PAD_Y}px ${CARD_PAD_X}px`,
655
+ boxSizing: 'border-box',
656
+ }}
657
+ >
658
+ <ContainerCardHeader
659
+ label={region.label}
660
+ Icon={Icon}
661
+ iconLabel={isPackage ? 'package' : containerKind}
662
+ color={color}
663
+ topLabel={topLabel}
664
+ brand={brand}
665
+ hasTechRow
666
+ count={{ value: region.memberAliases.length, Icon: Component }}
667
+ />
668
+ </div>
669
+ {data.onToggleCollapse && (
670
+ <button
671
+ type="button"
672
+ className="nodrag nopan"
673
+ onClick={(e) => {
674
+ e.stopPropagation();
675
+ data.onToggleCollapse?.();
676
+ }}
677
+ onDoubleClick={(e) => e.stopPropagation()}
678
+ aria-label={collapsed ? 'Show members' : 'Hide members'}
679
+ aria-pressed={collapsed}
680
+ style={{
681
+ position: 'absolute',
682
+ right: TOGGLE_INSET,
683
+ bottom: TOGGLE_INSET,
684
+ display: 'inline-flex',
685
+ alignItems: 'center',
686
+ justifyContent: 'center',
687
+ width: TOGGLE_SIZE,
688
+ height: TOGGLE_SIZE,
689
+ padding: 0,
690
+ borderRadius: 4,
691
+ border: `1px solid ${color}`,
692
+ background: theme.colors.backgroundSecondary ?? theme.colors.background,
693
+ color,
694
+ cursor: 'pointer',
695
+ lineHeight: 1,
696
+ pointerEvents: 'auto',
697
+ }}
698
+ >
699
+ <ToggleIcon size={13} strokeWidth={2.25} />
700
+ </button>
701
+ )}
702
+ {data.issue && ISSUE_KIND_ICON[data.issue.kind] && (
703
+ <IssueChip
704
+ color={
705
+ data.issue.severity === 'error'
706
+ ? (theme.colors.error ?? '#e5534b')
707
+ : (theme.colors.warning ?? '#d4a017')
708
+ }
709
+ Icon={ISSUE_KIND_ICON[data.issue.kind]!}
710
+ count={data.issue.count}
711
+ anchor={{ right: -9, bottom: -8 }}
712
+ />
713
+ )}
714
+ {/* A closed card is an edge endpoint: the lines its members carried roll
715
+ up onto it, and React Flow needs a handle on each end to draw them. */}
716
+ {collapsed && (
717
+ <>
718
+ <Handle type="target" position={Position.Left} style={{ opacity: 0 }} />
719
+ <Handle type="source" position={Position.Right} style={{ opacity: 0 }} />
720
+ </>
721
+ )}
722
+ </div>
723
+ );
724
+ }
725
+ /**
726
+ * The bare-frame chrome for a module / directory region: dashed border,
727
+ * transparent body, and a path badge astride the top edge that collapses a long
728
+ * path to `first/…/last` and expands on click.
729
+ */
730
+ function BadgeFrame(props: NodeProps<Node<SubsystemGroupNodeData, 'subsystem-group'>>) {
563
731
  const { theme } = useTheme();
564
732
  const { data, width, height, selected } = props as unknown as {
565
733
  data: SubsystemGroupNodeData;
@@ -572,54 +740,27 @@ export function SubsystemGroupNode(props: NodeProps<Node<SubsystemGroupNodeData,
572
740
  // (directory, or a module whose key names a folder) share one neutral hue;
573
741
  // everything else hashes per key.
574
742
  const color =
575
- data.color ??
576
- (isFolderFrame(region ?? undefined)
577
- ? FOLDER_FRAME_COLOR
578
- : packageColor(region?.key ?? 'process'));
743
+ data.color ?? (isFolderFrame(region) ? FOLDER_FRAME_COLOR : packageColor(region.key));
579
744
  const dimmed = data.dimmed === true;
580
745
  const hidden = (data as { hidden?: boolean }).hidden === true;
581
- // Label is the region identity alone (path / process key / owner/name).
582
- // Kind is carried by frame chrome (square = process; rounded = module/package)
583
- // — don't prefix `module ·` / `package ·` or the path reads twice.
584
- const label = region?.label ?? '';
746
+ // Label is the region identity alone (the path). Kind is carried by the
747
+ // frame chrome — don't prefix `module ·` or the path reads twice.
748
+ const label = region.label;
585
749
  const [expandedLabel, setExpandedLabel] = useState<string | null>(null);
586
- // Directory frames (path-derived nesting) render like modules — dashed,
587
- // collapsible path badge.
588
- const isModule = region?.kind === 'module' || region?.kind === 'directory';
589
- // Runtime chrome asserts "deployment unit" — a process region the host
590
- // marked `chrome: 'package'` groups code organisation instead (a library,
591
- // an area, a proposal) and forgoes it, drawing like a package frame.
592
- // Presentation only: `kind` still says process, so ids and issue targets
593
- // key off the claim unchanged.
594
- const isProcess = region?.kind === 'process' && region?.chrome !== 'package';
595
- // A frame renders as a package boundary two ways: it IS a package (repo
596
- // identity from `purl`) or the host demoted a process claim to package
597
- // chrome (a library, an area, a proposal). Both wear the Package glyph, so
598
- // "code organisation, not a deployment unit" reads off the canvas instead
599
- // of hiding in the shared rounded/dashed chrome.
600
- const isPackageFrame = region?.kind === 'package' || region?.chrome === 'package';
601
- const expanded = isModule && expandedLabel === label;
750
+ const expanded = expandedLabel === label;
602
751
  const availableBadgeWidth = Math.max(0, (width ?? 400) - MODULE_BADGE_INSET * 2 - 4);
603
- const collapsedLabel = isModule ? moduleBadgeLabel(label, availableBadgeWidth) : label;
752
+ const collapsedLabel = moduleBadgeLabel(label, availableBadgeWidth);
604
753
  // A module badge is collapsible while something collapsed, and stays
605
754
  // togglable while expanded (so the full path can collapse back).
606
- const canToggle = isModule && (expanded || collapsedLabel !== label);
755
+ const canToggle = expanded || collapsedLabel !== label;
607
756
  // Hover affords clickability by revealing more of the path — the badge
608
757
  // widens to fit real text (never stretched), hinting before the click.
609
758
  const [hover, setHover] = useState(false);
610
- const hoveredLabel =
611
- isModule && canToggle ? moduleBadgeHoverLabel(label, availableBadgeWidth) : label;
612
- const frameRadius = isProcess ? 0 : 12;
613
- const badgeRadius = isProcess ? 0 : 4;
759
+ const hoveredLabel = canToggle ? moduleBadgeHoverLabel(label, availableBadgeWidth) : label;
614
760
  const badgeBg = theme.colors.backgroundSecondary ?? theme.colors.background;
615
- // Processes are deployment units — solid frame. Modules/packages stay dashed
616
- // until selected.
617
- const frameStyle = isProcess || selected ? 'solid' : 'dashed';
618
- // Process keeps a tinted fill; module / package bodies stay transparent so
619
- // nested frames don't stack washes.
620
- const frameFill = isProcess ? `${color}14` : 'transparent';
621
-
622
- if (!region) return null;
761
+ // Code folders stay dashed until selected; the body is transparent so nested
762
+ // frames don't stack washes.
763
+ const frameStyle = selected ? 'solid' : 'dashed';
623
764
 
624
765
  return (
625
766
  <div
@@ -628,21 +769,20 @@ export function SubsystemGroupNode(props: NodeProps<Node<SubsystemGroupNodeData,
628
769
  width: width ?? 400,
629
770
  height: height ?? 300,
630
771
  boxSizing: 'border-box',
631
- borderRadius: frameRadius,
772
+ borderRadius: 12,
632
773
  border: `2px ${frameStyle} ${color}`,
633
- background: frameFill,
774
+ background: 'transparent',
634
775
  opacity: hidden ? 0 : dimmed ? 0.35 : 1,
635
776
  transition: 'opacity 150ms ease',
636
777
  pointerEvents: 'none',
637
778
  }}
638
779
  >
639
780
  <div
640
- className={isModule ? 'nodrag nopan' : undefined}
781
+ className="nodrag nopan"
641
782
  role={canToggle ? 'button' : undefined}
642
783
  tabIndex={canToggle && !hidden ? 0 : undefined}
643
784
  aria-expanded={canToggle ? expanded : undefined}
644
785
  aria-label={canToggle ? `${expanded ? 'Collapse' : 'Expand'} module path: ${label}` : undefined}
645
- title={isProcess ? 'Double-click to focus this process' : undefined}
646
786
  onMouseEnter={canToggle ? () => setHover(true) : undefined}
647
787
  onMouseLeave={canToggle ? () => setHover(false) : undefined}
648
788
  onClick={canToggle ? (event) => {
@@ -661,33 +801,26 @@ export function SubsystemGroupNode(props: NodeProps<Node<SubsystemGroupNodeData,
661
801
  } : undefined}
662
802
  style={{
663
803
  position: 'absolute',
664
- // Process: the tab sits flush over the frame's top border (`top:
665
- // -2` — the frame border is 2px) and carries its own full border, so
666
- // the two read as one piece. Module/package are centred astride the
667
- // top edge like component badges. Always set left/transform
668
- // explicitly — React Flow reuses group DOM nodes and `undefined`
669
- // does not clear a prior value.
670
- top: isProcess ? -2 : 0,
671
- left: isProcess ? '50%' : 12,
672
- transform: isProcess ? 'translateX(-50%)' : 'translateY(-50%)',
804
+ // Centred astride the top edge like component badges. Always set
805
+ // left/transform explicitly — React Flow reuses group DOM nodes and
806
+ // `undefined` does not clear a prior value.
807
+ top: 0,
808
+ left: 12,
809
+ transform: 'translateY(-50%)',
673
810
  zIndex: canToggle ? 10 : undefined,
674
811
  // Width is explicit while collapsible so hover-reveal of more path
675
812
  // text animates; the cap keeps both states inside the frame.
676
813
  width:
677
- isModule && canToggle && !expanded
814
+ canToggle && !expanded
678
815
  ? hover
679
816
  ? Math.min(availableBadgeWidth, moduleBadgeWidth(hoveredLabel))
680
817
  : Math.min(availableBadgeWidth, moduleBadgeWidth(collapsedLabel))
681
818
  : undefined,
682
819
  transition: 'width 140ms ease, box-shadow 120ms ease',
683
- cursor: canToggle || isProcess ? 'pointer' : undefined,
820
+ cursor: canToggle ? 'pointer' : undefined,
684
821
  // The trailing halo squares the rounded corners back off in the fill
685
822
  // colour, so an edge crossing a corner can't show through the notch.
686
- // Square (process) badges have no notch, and the halo would erase the
687
- // frame border they now sit flush on, so they skip it.
688
- boxShadow: isProcess
689
- ? undefined
690
- : `${canToggle && hover ? `0 2px 10px ${color}55, ` : ''}0 0 0 1.5px ${badgeBg}`,
823
+ boxShadow: `${canToggle && hover ? `0 2px 10px ${color}55, ` : ''}0 0 0 1.5px ${badgeBg}`,
691
824
  fontFamily: theme.fonts.monospace,
692
825
  fontSize: theme.fontSizes[3],
693
826
  fontWeight: 700,
@@ -695,42 +828,20 @@ export function SubsystemGroupNode(props: NodeProps<Node<SubsystemGroupNodeData,
695
828
  color,
696
829
  background: badgeBg,
697
830
  border: `2px solid ${color}`,
698
- borderTopWidth: 2,
699
- borderRadius: badgeRadius,
831
+ borderRadius: 4,
700
832
  padding: '3px 9px',
701
833
  whiteSpace: 'nowrap',
702
834
  overflow: 'hidden',
703
835
  textOverflow: 'ellipsis',
704
836
  boxSizing: 'border-box',
705
837
  pointerEvents: hidden ? 'none' : 'auto',
706
- ...(isModule
707
- ? {
708
- // Cap the collapsed badge at the frame's inner width so it
709
- // never spills past the module — it gets the `…`/click-to-
710
- // expand treatment instead. Expanding lifts the cap so the
711
- // full path grows the badge past the frame's edge.
712
- maxWidth: expanded ? undefined : availableBadgeWidth,
713
- }
714
- : undefined),
715
- ...(isPackageFrame
716
- ? {
717
- // Icon + key on one row: the Package glyph leads the label
718
- // so package chrome reads as code organisation at a glance.
719
- display: 'inline-flex',
720
- alignItems: 'center',
721
- gap: 5,
722
- }
723
- : undefined),
838
+ // Cap the collapsed badge at the frame's inner width so it never
839
+ // spills past the module — it gets the `…`/click-to-expand treatment
840
+ // instead. Expanding lifts the cap so the full path grows the badge
841
+ // past the frame's edge.
842
+ maxWidth: expanded ? undefined : availableBadgeWidth,
724
843
  }}
725
844
  >
726
- {isPackageFrame && (
727
- <Package
728
- size={13}
729
- strokeWidth={2}
730
- aria-hidden="true"
731
- style={{ flexShrink: 0 }}
732
- />
733
- )}
734
845
  {canToggle ? (
735
846
  <span style={{ whiteSpace: 'nowrap' }}>
736
847
  {expanded ? label : hover ? hoveredLabel : collapsedLabel}
@@ -756,7 +867,6 @@ export function SubsystemGroupNode(props: NodeProps<Node<SubsystemGroupNodeData,
756
867
  </div>
757
868
  );
758
869
  }
759
-
760
870
  /** `#rrggbb` + alpha → `#rrggbbaa`. Used to dim a stroke/marker by color so
761
871
  * each opacity gets its own SVG marker id — path `opacity` leaks across every
762
872
  * edge that shares a `url(#marker)` (the focused edge's arrowhead dims). */