@principal-ai/subsystems-react 0.56.14 → 0.56.16

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 (44) hide show
  1. package/dist/index.d.ts +4 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/subsystem/C4Graph.d.ts +17 -0
  6. package/dist/subsystem/C4Graph.d.ts.map +1 -1
  7. package/dist/subsystem/C4Graph.js +128 -61
  8. package/dist/subsystem/C4Graph.js.map +1 -1
  9. package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
  10. package/dist/subsystem/C4NodeCard.js +7 -2
  11. package/dist/subsystem/C4NodeCard.js.map +1 -1
  12. package/dist/subsystem/DecorationPanel.d.ts +32 -3
  13. package/dist/subsystem/DecorationPanel.d.ts.map +1 -1
  14. package/dist/subsystem/DecorationPanel.js +162 -89
  15. package/dist/subsystem/DecorationPanel.js.map +1 -1
  16. package/dist/subsystem/SubsystemComponentGraph.d.ts +2 -0
  17. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  18. package/dist/subsystem/SubsystemComponentGraph.js +1 -1
  19. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  20. package/dist/subsystem/c4.d.ts +2 -0
  21. package/dist/subsystem/c4.d.ts.map +1 -1
  22. package/dist/subsystem/c4.js.map +1 -1
  23. package/dist/subsystem/decoration.d.ts +19 -0
  24. package/dist/subsystem/decoration.d.ts.map +1 -1
  25. package/dist/subsystem/decoration.js.map +1 -1
  26. package/dist/subsystem/decorationC4.d.ts +9 -0
  27. package/dist/subsystem/decorationC4.d.ts.map +1 -0
  28. package/dist/subsystem/decorationC4.js +55 -0
  29. package/dist/subsystem/decorationC4.js.map +1 -0
  30. package/package.json +2 -2
  31. package/src/index.ts +6 -1
  32. package/src/stories/Components/DecorationPanel.stories.tsx +344 -36
  33. package/src/subsystem/C4Graph.groups.test.ts +46 -0
  34. package/src/subsystem/C4Graph.tsx +96 -16
  35. package/src/subsystem/C4NodeCard.test.ts +35 -1
  36. package/src/subsystem/C4NodeCard.tsx +7 -2
  37. package/src/subsystem/DecorationPanel.test.tsx +228 -4
  38. package/src/subsystem/DecorationPanel.tsx +248 -82
  39. package/src/subsystem/SubsystemComponentGraph.sidebar.test.tsx +11 -0
  40. package/src/subsystem/SubsystemComponentGraph.tsx +4 -1
  41. package/src/subsystem/c4.ts +2 -0
  42. package/src/subsystem/decoration.ts +25 -0
  43. package/src/subsystem/decorationC4.test.ts +134 -0
  44. package/src/subsystem/decorationC4.ts +60 -0
@@ -0,0 +1,60 @@
1
+ import type { C4Element, C4Model } from './c4';
2
+ import type { SubsystemDecoration } from './decoration';
3
+
4
+ /**
5
+ * Project a decoration's C4 additions without mutating the base architecture.
6
+ * Hosts resolve trail highlighting and construct membership separately.
7
+ * Invalid additions fail rather than replacing base elements or drawing dangling lines.
8
+ */
9
+ export function applyDecorationC4(
10
+ base: C4Model,
11
+ decoration: SubsystemDecoration,
12
+ active = true,
13
+ ): C4Model {
14
+ const draft = decoration.draft?.c4;
15
+ if (!active || !draft) return base;
16
+
17
+ const ids = new Set([base.system.id, ...base.nodes.map((node) => node.id)]);
18
+ const additions: C4Element[] = (draft.elements ?? []).map((element) => {
19
+ if (ids.has(element.id)) throw new Error(`Duplicate C4 element id: ${element.id}`);
20
+ ids.add(element.id);
21
+ return {
22
+ ...element,
23
+ state: 'proposed',
24
+ ...(element.kind === 'container' ? { parentId: element.parentId ?? base.system.id } : {}),
25
+ };
26
+ });
27
+ const nodes = [...base.nodes, ...additions];
28
+ const byId = new Map(nodes.map((node) => [node.id, node]));
29
+ for (const element of additions) {
30
+ if (element.kind === 'component') {
31
+ if (byId.get(element.container)?.kind !== 'container') {
32
+ throw new Error(`Missing C4 container for ${element.id}: ${element.container}`);
33
+ }
34
+ if (element.parentId && element.parentId !== element.container) {
35
+ throw new Error(`Conflicting C4 parent for ${element.id}`);
36
+ }
37
+ } else if (element.kind === 'container' && element.parentId !== base.system.id) {
38
+ throw new Error(`Unknown C4 system for ${element.id}: ${element.parentId}`);
39
+ } else if (
40
+ (element.kind === 'external-system' || element.kind === 'person') &&
41
+ element.parentId
42
+ ) {
43
+ throw new Error(`External C4 element cannot have a parent: ${element.id}`);
44
+ }
45
+ }
46
+
47
+ const edgeIds = new Set(base.edges.map((edge) => edge.id));
48
+ for (const edge of draft.edges ?? []) {
49
+ if (edgeIds.has(edge.id)) throw new Error(`Duplicate C4 edge id: ${edge.id}`);
50
+ edgeIds.add(edge.id);
51
+ if (!byId.has(edge.source) || !byId.has(edge.target)) {
52
+ throw new Error(`Missing C4 endpoint for edge: ${edge.id}`);
53
+ }
54
+ }
55
+ return {
56
+ ...base,
57
+ nodes,
58
+ edges: [...base.edges, ...(draft.edges ?? []).map((edge) => ({ ...edge, draft: true }))],
59
+ };
60
+ }