@transitrix/diagrams 1.4.0 → 1.6.0

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 (90) hide show
  1. package/dist/activities/__tests__/gantt.test.js +39 -0
  2. package/dist/capability-map/CapabilityCardNode.d.ts +19 -0
  3. package/dist/capability-map/CapabilityCardNode.js +66 -0
  4. package/dist/capability-map/CapabilityMapView.d.ts +59 -0
  5. package/dist/capability-map/CapabilityMapView.js +204 -0
  6. package/dist/capability-map/CapabilityRootNode.d.ts +12 -0
  7. package/dist/capability-map/CapabilityRootNode.js +23 -0
  8. package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +1 -0
  9. package/dist/capability-map/__tests__/CapabilityMapView.test.js +217 -0
  10. package/dist/capability-map/__tests__/address.test.d.ts +1 -0
  11. package/dist/capability-map/__tests__/address.test.js +49 -0
  12. package/dist/capability-map/__tests__/dsm-layout.test.d.ts +1 -0
  13. package/dist/capability-map/__tests__/dsm-layout.test.js +46 -0
  14. package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +1 -0
  15. package/dist/capability-map/__tests__/dsm-mutations.test.js +125 -0
  16. package/dist/capability-map/__tests__/dsm-validate.test.d.ts +1 -0
  17. package/dist/capability-map/__tests__/dsm-validate.test.js +56 -0
  18. package/dist/capability-map/address.d.ts +12 -0
  19. package/dist/capability-map/address.js +48 -0
  20. package/dist/capability-map/dsm-layout.d.ts +9 -0
  21. package/dist/capability-map/dsm-layout.js +125 -0
  22. package/dist/capability-map/dsm-mutations.d.ts +28 -0
  23. package/dist/capability-map/dsm-mutations.js +196 -0
  24. package/dist/capability-map/dsm-schema.d.ts +71 -0
  25. package/dist/capability-map/dsm-schema.js +14 -0
  26. package/dist/capability-map/dsm-theme.d.ts +20 -0
  27. package/dist/capability-map/dsm-theme.js +36 -0
  28. package/dist/capability-map/dsm-validate.d.ts +2 -0
  29. package/dist/capability-map/dsm-validate.js +93 -0
  30. package/dist/capability-map/index.d.ts +9 -0
  31. package/dist/capability-map/index.js +6 -0
  32. package/dist/compliance/__tests__/trace.test.d.ts +1 -0
  33. package/dist/compliance/__tests__/trace.test.js +144 -0
  34. package/dist/compliance/classify.js +7 -1
  35. package/dist/compliance/index.d.ts +2 -1
  36. package/dist/compliance/index.js +1 -0
  37. package/dist/compliance/reverse-index.js +4 -1
  38. package/dist/compliance/trace.d.ts +26 -0
  39. package/dist/compliance/trace.js +89 -0
  40. package/dist/compliance/types.d.ts +94 -1
  41. package/dist/goals/GoalNode.d.ts +18 -0
  42. package/dist/goals/GoalNode.js +91 -0
  43. package/dist/goals/GoalTreeView.d.ts +57 -0
  44. package/dist/goals/GoalTreeView.js +228 -0
  45. package/dist/goals/__tests__/GoalTreeView.test.d.ts +1 -0
  46. package/dist/goals/__tests__/GoalTreeView.test.js +296 -0
  47. package/dist/goals/index.d.ts +3 -0
  48. package/dist/goals/index.js +1 -0
  49. package/dist/goals/theme.d.ts +22 -0
  50. package/dist/goals/theme.js +32 -0
  51. package/dist/index.d.ts +2 -1
  52. package/dist/index.js +1 -1
  53. package/dist/webview/__tests__/render-blocks.test.js +48 -0
  54. package/dist/webview/notation-style.d.ts +11 -0
  55. package/dist/webview/notation-style.js +11 -0
  56. package/dist/webview/render-blocks.js +8 -4
  57. package/dist/webview/render-goals.js +2 -1
  58. package/package.json +4 -1
  59. package/src/activities/__tests__/gantt.test.ts +45 -0
  60. package/src/capability-map/CapabilityCardNode.tsx +146 -0
  61. package/src/capability-map/CapabilityMapView.tsx +331 -0
  62. package/src/capability-map/CapabilityRootNode.tsx +38 -0
  63. package/src/capability-map/__tests__/CapabilityMapView.test.tsx +232 -0
  64. package/src/capability-map/__tests__/address.test.ts +59 -0
  65. package/src/capability-map/__tests__/dsm-layout.test.ts +52 -0
  66. package/src/capability-map/__tests__/dsm-mutations.test.ts +141 -0
  67. package/src/capability-map/__tests__/dsm-validate.test.ts +65 -0
  68. package/src/capability-map/address.ts +48 -0
  69. package/src/capability-map/dsm-layout.ts +142 -0
  70. package/src/capability-map/dsm-mutations.ts +208 -0
  71. package/src/capability-map/dsm-schema.ts +80 -0
  72. package/src/capability-map/dsm-theme.ts +53 -0
  73. package/src/capability-map/dsm-validate.ts +103 -0
  74. package/src/capability-map/index.ts +35 -0
  75. package/src/compliance/__tests__/trace.test.ts +157 -0
  76. package/src/compliance/classify.ts +7 -1
  77. package/src/compliance/index.ts +6 -0
  78. package/src/compliance/reverse-index.ts +3 -1
  79. package/src/compliance/trace.ts +118 -0
  80. package/src/compliance/types.ts +101 -1
  81. package/src/goals/GoalNode.tsx +212 -0
  82. package/src/goals/GoalTreeView.tsx +350 -0
  83. package/src/goals/__tests__/GoalTreeView.test.tsx +313 -0
  84. package/src/goals/index.ts +4 -0
  85. package/src/goals/theme.ts +54 -0
  86. package/src/index.ts +29 -1
  87. package/src/webview/__tests__/render-blocks.test.ts +54 -0
  88. package/src/webview/notation-style.ts +12 -0
  89. package/src/webview/render-blocks.ts +8 -4
  90. package/src/webview/render-goals.ts +2 -1
@@ -0,0 +1,146 @@
1
+ import React, { memo } from 'react';
2
+ import { Handle, Position } from 'reactflow';
3
+ import type { Capability } from './dsm-schema.js';
4
+ import type { ThemeTokens } from './dsm-theme.js';
5
+
6
+ const CARD_WIDTH = 250;
7
+ const CARD_HEIGHT = 64;
8
+
9
+ function latestMaturityLevel(cap: Capability): number | undefined {
10
+ if (!cap.maturity || cap.maturity.length === 0) return undefined;
11
+ return [...cap.maturity].sort((a, b) => b.date.localeCompare(a.date))[0].level;
12
+ }
13
+
14
+ export interface CapabilityCardNodeData {
15
+ capability: Capability;
16
+ theme: Required<ThemeTokens>;
17
+ maturityColours: Record<number, string>;
18
+ readOnly: boolean;
19
+ isDropTarget: boolean;
20
+ hasHiddenChildren: boolean;
21
+ isCollapsed: boolean;
22
+ onAddChild: (parentId: number) => void;
23
+ onDelete: (id: number) => void;
24
+ onToggleCollapse: (id: number) => void;
25
+ }
26
+
27
+ const CapabilityCardNode = memo(({ data }: { data: CapabilityCardNodeData }) => {
28
+ const { capability, theme, maturityColours, readOnly, isDropTarget, hasHiddenChildren, isCollapsed } = data;
29
+ const maturity = latestMaturityLevel(capability);
30
+ const dotColour = maturity !== undefined ? maturityColours[maturity] : undefined;
31
+
32
+ return (
33
+ <div
34
+ style={{
35
+ position: 'relative',
36
+ width: CARD_WIDTH,
37
+ height: CARD_HEIGHT,
38
+ background: theme.cardFill,
39
+ borderRadius: 8,
40
+ borderStyle: 'solid',
41
+ borderWidth: isDropTarget ? 2 : theme.cardBorderWidth,
42
+ borderColor: isDropTarget ? theme.dropTargetBorderColor : theme.cardBorderColor,
43
+ boxShadow: '0 1px 4px rgba(0,0,0,0.12)',
44
+ padding: '6px 10px',
45
+ display: 'flex',
46
+ flexDirection: 'column',
47
+ justifyContent: 'center',
48
+ }}
49
+ >
50
+ <Handle type="target" position={Position.Left} style={{ opacity: 0 }} />
51
+ <Handle type="source" position={Position.Right} style={{ opacity: 0 }} />
52
+
53
+ {dotColour && (
54
+ <span
55
+ title={`Maturity ${maturity}`}
56
+ aria-label={`Maturity ${maturity}`}
57
+ style={{
58
+ position: 'absolute', top: 6, left: 6, width: 8, height: 8, borderRadius: '50%', background: dotColour,
59
+ }}
60
+ />
61
+ )}
62
+
63
+ <div
64
+ title={capability.name}
65
+ style={{
66
+ fontWeight: 600,
67
+ fontSize: 12,
68
+ color: theme.cardTextColor,
69
+ marginLeft: dotColour ? 12 : 0,
70
+ overflow: 'hidden',
71
+ display: '-webkit-box',
72
+ WebkitLineClamp: 2,
73
+ WebkitBoxOrient: 'vertical',
74
+ wordBreak: 'break-word',
75
+ lineHeight: 1.2,
76
+ }}
77
+ >
78
+ {capability.name}
79
+ </div>
80
+ <div style={{ fontSize: 10, color: theme.cardMetaColor, marginTop: 2, marginLeft: dotColour ? 12 : 0 }}>
81
+ {capability.address}
82
+ </div>
83
+
84
+ {!readOnly && (
85
+ <button
86
+ type="button"
87
+ aria-label="Add child capability"
88
+ title="Add child capability"
89
+ onClick={(e) => {
90
+ e.stopPropagation();
91
+ data.onAddChild(capability.id);
92
+ }}
93
+ style={{
94
+ position: 'absolute', top: -8, right: -8, width: 16, height: 16,
95
+ borderRadius: '50%', border: '1px solid #86efac', background: '#ffffff',
96
+ color: '#16a34a', fontSize: 11, lineHeight: '14px', padding: 0, cursor: 'pointer',
97
+ }}
98
+ >
99
+ +
100
+ </button>
101
+ )}
102
+
103
+ {!readOnly && (
104
+ <button
105
+ type="button"
106
+ aria-label="Delete capability"
107
+ title="Delete capability and descendants"
108
+ onClick={(e) => {
109
+ e.stopPropagation();
110
+ data.onDelete(capability.id);
111
+ }}
112
+ style={{
113
+ position: 'absolute', bottom: -8, right: -8, width: 16, height: 16,
114
+ borderRadius: '50%', border: '1px solid #fca5a5', background: '#ffffff',
115
+ color: '#dc2626', fontSize: 11, lineHeight: '14px', padding: 0, cursor: 'pointer',
116
+ }}
117
+ >
118
+ &times;
119
+ </button>
120
+ )}
121
+
122
+ {hasHiddenChildren && (
123
+ <button
124
+ type="button"
125
+ aria-label={isCollapsed ? 'Expand branch' : 'Collapse branch'}
126
+ title={isCollapsed ? 'Expand branch' : 'Collapse branch'}
127
+ onClick={(e) => {
128
+ e.stopPropagation();
129
+ data.onToggleCollapse(capability.id);
130
+ }}
131
+ style={{
132
+ position: 'absolute', top: '50%', right: -8, transform: 'translateY(-50%)',
133
+ width: 16, height: 16, borderRadius: '50%', border: `1px solid ${theme.cardBorderColor}`,
134
+ background: '#ffffff', color: theme.cardBorderColor, fontSize: 11, lineHeight: '14px', padding: 0, cursor: 'pointer',
135
+ }}
136
+ >
137
+ {isCollapsed ? '+' : '−'}
138
+ </button>
139
+ )}
140
+ </div>
141
+ );
142
+ });
143
+
144
+ CapabilityCardNode.displayName = 'CapabilityCardNode';
145
+
146
+ export default CapabilityCardNode;
@@ -0,0 +1,331 @@
1
+ import React, { useCallback, useMemo, useState, useEffect } from 'react';
2
+ import ReactFlow, {
3
+ Controls,
4
+ MiniMap,
5
+ Background,
6
+ Panel,
7
+ ConnectionLineType,
8
+ useNodesState,
9
+ useEdgesState,
10
+ type Node,
11
+ type Edge,
12
+ type NodeMouseHandler,
13
+ type NodeDragHandler,
14
+ } from 'reactflow';
15
+ import 'reactflow/dist/style.css';
16
+ import type { Capability, CapabilityMap, CapabilityMapLayout, LayoutOptions } from './dsm-schema.js';
17
+ import { layoutCapabilityMap } from './dsm-layout.js';
18
+ import { reparent, addChild, deleteWithDescendants, moveBranchToBacklog, restoreFromBacklog, normaliseAddresses } from './dsm-mutations.js';
19
+ import type { ThemeTokens } from './dsm-theme.js';
20
+ import { resolveTheme, DEFAULT_MATURITY_COLOURS } from './dsm-theme.js';
21
+ import CapabilityCardNode, { type CapabilityCardNodeData } from './CapabilityCardNode.js';
22
+ import CapabilityRootNode, { type CapabilityRootNodeData } from './CapabilityRootNode.js';
23
+
24
+ export type { ThemeTokens } from './dsm-theme.js';
25
+
26
+ export interface CapabilityMapViewProps {
27
+ map: CapabilityMap;
28
+ layout?: CapabilityMapLayout;
29
+ layoutOptions?: LayoutOptions;
30
+ theme?: ThemeTokens;
31
+ readOnly?: boolean;
32
+ showBacklog?: boolean;
33
+ showMiniMap?: boolean;
34
+ maturityColours?: Record<number, string>;
35
+ selectedSet?: string;
36
+ onChange?: (event: CapabilityMapChange) => void;
37
+ onEditRequest?: (cap: Capability) => void;
38
+ }
39
+
40
+ export type CapabilityMapChange =
41
+ | { kind: 'reparent'; sourceId: number; targetId: number; result: CapabilityMap }
42
+ | { kind: 'addChild'; parentId: number; newCap: Capability; result: CapabilityMap }
43
+ | { kind: 'delete'; id: number; result: CapabilityMap }
44
+ | { kind: 'moveBranchToBacklog'; id: number; result: CapabilityMap }
45
+ | { kind: 'restoreFromBacklog'; id: number; parentId: number; result: CapabilityMap }
46
+ | { kind: 'normaliseAddresses'; result: CapabilityMap };
47
+
48
+ const BACKLOG_DRAG_MIME = 'application/x-transitrix-capability-id';
49
+ const ROOT_NODE_ID = '__root__';
50
+ const nodeTypes = { capabilityCard: CapabilityCardNode, capabilityRoot: CapabilityRootNode };
51
+
52
+ /** Where a card was dropped, as classified from the pointer position at
53
+ * drag-stop — mirrors goals' computeDragOutcome split (see GoalTreeView.tsx)
54
+ * so the reparent/moveBranchToBacklog decision is unit-testable without a
55
+ * live drag through reactflow's DOM-measurement-gated dragging. */
56
+ export type DropTarget = { kind: 'node'; id: number } | { kind: 'root' } | { kind: 'backlog' } | null;
57
+
58
+ export function computeDragOutcome(map: CapabilityMap, sourceId: number, dropTarget: DropTarget): CapabilityMapChange | null {
59
+ if (!dropTarget) return null;
60
+ if (dropTarget.kind === 'backlog') {
61
+ const mutation = moveBranchToBacklog(map, sourceId);
62
+ if (!mutation.ok || !mutation.result) return null;
63
+ return { kind: 'moveBranchToBacklog', id: sourceId, result: mutation.result };
64
+ }
65
+ const targetId = dropTarget.kind === 'root' ? 0 : dropTarget.id;
66
+ if (targetId === sourceId) return null;
67
+ const mutation = reparent(map, sourceId, targetId);
68
+ if (!mutation.ok || !mutation.result) return null;
69
+ return { kind: 'reparent', sourceId, targetId, result: mutation.result };
70
+ }
71
+
72
+ function CapabilityMapViewInner({
73
+ map,
74
+ layout: layoutProp,
75
+ layoutOptions,
76
+ theme: themeProp,
77
+ readOnly = false,
78
+ showBacklog = false,
79
+ showMiniMap = false,
80
+ maturityColours = DEFAULT_MATURITY_COLOURS,
81
+ onChange,
82
+ onEditRequest,
83
+ }: CapabilityMapViewProps): React.ReactElement {
84
+ const theme = useMemo(() => resolveTheme(themeProp), [themeProp]);
85
+ const [collapsedIds, setCollapsedIds] = useState<Set<number>>(new Set());
86
+ const [hoveredId, setHoveredId] = useState<number | 'root' | null>(null);
87
+
88
+ const backlogCaps = useMemo(() => map.capabilities.filter((c) => c.backlog), [map.capabilities]);
89
+
90
+ const layout = useMemo<CapabilityMapLayout>(() => {
91
+ if (layoutProp) return layoutProp;
92
+ const hideCollapsed = [...(layoutOptions?.hideCollapsed ?? []), ...collapsedIds];
93
+ return layoutCapabilityMap(map, { ...layoutOptions, hideCollapsed });
94
+ }, [layoutProp, layoutOptions, collapsedIds, map]);
95
+
96
+ const rootLabel = layoutOptions?.organisationLabel ?? map.organisation;
97
+
98
+ const onAddChild = useCallback(
99
+ (parentId: number) => {
100
+ if (readOnly) return;
101
+ const before = new Set(map.capabilities.map((c) => c.id));
102
+ const mutation = addChild(map, parentId, { name: 'New capability' });
103
+ if (!mutation.ok || !mutation.result) return;
104
+ const newCap = mutation.result.capabilities.find((c) => !before.has(c.id));
105
+ if (!newCap) return;
106
+ onChange?.({ kind: 'addChild', parentId, newCap, result: mutation.result });
107
+ },
108
+ [map, readOnly, onChange],
109
+ );
110
+
111
+ const onDeleteNode = useCallback(
112
+ (id: number) => {
113
+ if (readOnly) return;
114
+ const mutation = deleteWithDescendants(map, id);
115
+ if (!mutation.ok || !mutation.result) return;
116
+ onChange?.({ kind: 'delete', id, result: mutation.result });
117
+ },
118
+ [map, readOnly, onChange],
119
+ );
120
+
121
+ const onRestoreFromBacklog = useCallback(
122
+ (id: number, parentId: number) => {
123
+ if (readOnly) return;
124
+ const mutation = restoreFromBacklog(map, id, parentId);
125
+ if (!mutation.ok || !mutation.result) return;
126
+ onChange?.({ kind: 'restoreFromBacklog', id, parentId, result: mutation.result });
127
+ },
128
+ [map, readOnly, onChange],
129
+ );
130
+
131
+ const onNormalise = useCallback(() => {
132
+ if (readOnly) return;
133
+ onChange?.({ kind: 'normaliseAddresses', result: normaliseAddresses(map) });
134
+ }, [map, readOnly, onChange]);
135
+
136
+ const onToggleCollapse = useCallback((id: number) => {
137
+ setCollapsedIds((prev) => {
138
+ const next = new Set(prev);
139
+ if (next.has(id)) next.delete(id);
140
+ else next.add(id);
141
+ return next;
142
+ });
143
+ }, []);
144
+
145
+ const buildNodes = useCallback((): Node[] => {
146
+ const rootNode: Node<CapabilityRootNodeData> = {
147
+ id: ROOT_NODE_ID,
148
+ type: 'capabilityRoot',
149
+ position: { x: layout.rootNode.x, y: layout.rootNode.y },
150
+ draggable: false,
151
+ data: { label: rootLabel, theme },
152
+ };
153
+ const cardNodes: Node<CapabilityCardNodeData>[] = layout.nodes.map((n) => ({
154
+ id: String(n.id),
155
+ type: 'capabilityCard',
156
+ position: { x: n.x, y: n.y },
157
+ draggable: !readOnly,
158
+ data: {
159
+ capability: n.data!,
160
+ theme,
161
+ maturityColours,
162
+ readOnly,
163
+ isDropTarget: hoveredId === n.id,
164
+ hasHiddenChildren: n.hasHiddenChildren,
165
+ isCollapsed: collapsedIds.has(n.id),
166
+ onAddChild,
167
+ onDelete: onDeleteNode,
168
+ onToggleCollapse,
169
+ },
170
+ }));
171
+ return [rootNode, ...cardNodes];
172
+ }, [layout, theme, rootLabel, readOnly, hoveredId, collapsedIds, maturityColours, onAddChild, onDeleteNode, onToggleCollapse]);
173
+
174
+ const buildEdges = useCallback((): Edge[] => {
175
+ return layout.edges.map((e) => ({
176
+ id: `e${e.source}-${e.target}`,
177
+ source: e.source === 'root' ? ROOT_NODE_ID : String(e.source),
178
+ target: String(e.target),
179
+ type: 'default',
180
+ style: { stroke: theme.edgeColor, strokeWidth: theme.edgeWidth },
181
+ }));
182
+ }, [layout.edges, theme]);
183
+
184
+ const [nodes, setNodes, onNodesChange] = useNodesState(buildNodes());
185
+ const [edges, setEdges, onEdgesChange] = useEdgesState(buildEdges());
186
+
187
+ useEffect(() => {
188
+ setNodes(buildNodes());
189
+ setEdges(buildEdges());
190
+ // eslint-disable-next-line react-hooks/exhaustive-deps
191
+ }, [layout, theme, readOnly, hoveredId, collapsedIds, maturityColours]);
192
+
193
+ const checkIntersection = useCallback((a: Node, b: Node): boolean => {
194
+ const midX = a.position.x + 125;
195
+ const midY = a.position.y + 32;
196
+ return midX > b.position.x && midX < b.position.x + 250 && midY > b.position.y && midY < b.position.y + 64;
197
+ }, []);
198
+
199
+ const onNodeDrag: NodeDragHandler = useCallback(
200
+ (_event, node) => {
201
+ if (readOnly) return;
202
+ const hit = nodes.find((n) => n.id !== node.id && checkIntersection(node, n));
203
+ if (!hit) {
204
+ setHoveredId(null);
205
+ } else {
206
+ setHoveredId(hit.id === ROOT_NODE_ID ? 'root' : Number(hit.id));
207
+ }
208
+ },
209
+ [readOnly, nodes, checkIntersection],
210
+ );
211
+
212
+ const onNodeDragStop: NodeDragHandler = useCallback(
213
+ (event, node) => {
214
+ if (readOnly) {
215
+ setHoveredId(null);
216
+ return;
217
+ }
218
+ const sourceId = Number(node.id);
219
+ const mouseEvent = event as unknown as MouseEvent;
220
+ const dropEl = typeof document !== 'undefined' && 'clientX' in mouseEvent
221
+ ? document.elementFromPoint(mouseEvent.clientX, mouseEvent.clientY)
222
+ : null;
223
+ let dropTarget: DropTarget;
224
+ if (dropEl?.closest('[data-capmap-backlog-zone]')) dropTarget = { kind: 'backlog' };
225
+ else if (hoveredId === 'root') dropTarget = { kind: 'root' };
226
+ else if (hoveredId != null) dropTarget = { kind: 'node', id: hoveredId };
227
+ else dropTarget = null;
228
+ const change = computeDragOutcome(map, sourceId, dropTarget);
229
+ if (change) onChange?.(change);
230
+ setHoveredId(null);
231
+ },
232
+ [readOnly, hoveredId, map, onChange],
233
+ );
234
+
235
+ const onNodeDoubleClick: NodeMouseHandler = useCallback(
236
+ (_event, node) => {
237
+ const cap = map.capabilities.find((c) => c.id === Number(node.id));
238
+ if (cap) onEditRequest?.(cap);
239
+ },
240
+ [map.capabilities, onEditRequest],
241
+ );
242
+
243
+ const onBacklogItemDragStart = useCallback((event: React.DragEvent, capId: number) => {
244
+ event.dataTransfer.setData(BACKLOG_DRAG_MIME, String(capId));
245
+ event.dataTransfer.effectAllowed = 'move';
246
+ }, []);
247
+
248
+ const onCanvasDragOver = useCallback(
249
+ (event: React.DragEvent) => {
250
+ if (readOnly) return;
251
+ event.preventDefault();
252
+ },
253
+ [readOnly],
254
+ );
255
+
256
+ const onCanvasDrop = useCallback(
257
+ (event: React.DragEvent) => {
258
+ if (readOnly) return;
259
+ event.preventDefault();
260
+ const idStr = event.dataTransfer.getData(BACKLOG_DRAG_MIME);
261
+ if (!idStr) return;
262
+ const capId = Number(idStr);
263
+ const targetEl = document.elementFromPoint(event.clientX, event.clientY);
264
+ const nodeEl = targetEl?.closest('.react-flow__node');
265
+ const targetIdAttr = nodeEl?.getAttribute('data-id');
266
+ if (targetIdAttr == null) return;
267
+ const parentId = targetIdAttr === ROOT_NODE_ID ? 0 : Number(targetIdAttr);
268
+ onRestoreFromBacklog(capId, parentId);
269
+ },
270
+ [readOnly, onRestoreFromBacklog],
271
+ );
272
+
273
+ const showBacklogPanel = showBacklog && backlogCaps.length > 0;
274
+
275
+ return (
276
+ <div style={{ display: 'flex', width: '100%', height: '100%' }}>
277
+ {showBacklogPanel && (
278
+ <div
279
+ data-capmap-backlog-zone
280
+ style={{ width: 220, flexShrink: 0, borderRight: '1px solid #e2e8f0', padding: 10, overflowY: 'auto', background: '#f8fafc' }}
281
+ >
282
+ <div style={{ fontWeight: 700, fontSize: 12, color: '#334155', marginBottom: 8 }}>Backlog</div>
283
+ {backlogCaps.map((cap) => (
284
+ <div
285
+ key={cap.id}
286
+ draggable={!readOnly}
287
+ onDragStart={(e) => onBacklogItemDragStart(e, cap.id)}
288
+ onDoubleClick={() => onEditRequest?.(cap)}
289
+ title="Drag onto a card (or the root) to set its parent"
290
+ style={{ padding: 8, marginBottom: 6, background: '#ffffff', border: '1px solid #cbd5e1', borderRadius: 6, fontSize: 11, cursor: readOnly ? 'default' : 'grab' }}
291
+ >
292
+ <div style={{ fontWeight: 600 }}>{cap.name}</div>
293
+ </div>
294
+ ))}
295
+ </div>
296
+ )}
297
+
298
+ <div style={{ flex: 1, position: 'relative' }} onDragOver={onCanvasDragOver} onDrop={onCanvasDrop}>
299
+ <ReactFlow
300
+ nodes={nodes}
301
+ edges={edges}
302
+ onNodesChange={readOnly ? undefined : onNodesChange}
303
+ onEdgesChange={readOnly ? undefined : onEdgesChange}
304
+ nodeTypes={nodeTypes}
305
+ nodesDraggable={!readOnly}
306
+ nodesConnectable={false}
307
+ onNodeDrag={onNodeDrag}
308
+ onNodeDragStop={onNodeDragStop}
309
+ onNodeDoubleClick={onNodeDoubleClick}
310
+ connectionLineType={ConnectionLineType.Bezier}
311
+ fitView
312
+ >
313
+ <Background />
314
+ <Controls />
315
+ {showMiniMap && <MiniMap pannable zoomable />}
316
+ {!readOnly && (
317
+ <Panel position="top-right">
318
+ <button type="button" onClick={onNormalise} style={{ fontSize: 11, padding: '4px 8px', cursor: 'pointer' }}>
319
+ Normalise addresses
320
+ </button>
321
+ </Panel>
322
+ )}
323
+ </ReactFlow>
324
+ </div>
325
+ </div>
326
+ );
327
+ }
328
+
329
+ export function CapabilityMapView(props: CapabilityMapViewProps): React.ReactElement {
330
+ return <CapabilityMapViewInner {...props} />;
331
+ }
@@ -0,0 +1,38 @@
1
+ import React, { memo } from 'react';
2
+ import { Handle, Position } from 'reactflow';
3
+ import type { ThemeTokens } from './dsm-theme.js';
4
+
5
+ export interface CapabilityRootNodeData {
6
+ label: string;
7
+ theme: Required<ThemeTokens>;
8
+ }
9
+
10
+ /** The virtual organisation root — single node, no maturity dot, no
11
+ * add/delete/collapse affordances (it isn't a mutable Capability). */
12
+ const CapabilityRootNode = memo(({ data }: { data: CapabilityRootNodeData }) => (
13
+ <div
14
+ style={{
15
+ width: 200,
16
+ height: 64,
17
+ background: data.theme.rootFill,
18
+ color: data.theme.rootTextColor,
19
+ borderRadius: 8,
20
+ border: `1px solid ${data.theme.cardBorderColor}`,
21
+ boxShadow: '0 1px 4px rgba(0,0,0,0.12)',
22
+ display: 'flex',
23
+ alignItems: 'center',
24
+ justifyContent: 'center',
25
+ textAlign: 'center',
26
+ fontWeight: 700,
27
+ fontSize: 12,
28
+ padding: '4px 10px',
29
+ }}
30
+ >
31
+ <Handle type="source" position={Position.Right} style={{ opacity: 0 }} />
32
+ {data.label}
33
+ </div>
34
+ ));
35
+
36
+ CapabilityRootNode.displayName = 'CapabilityRootNode';
37
+
38
+ export default CapabilityRootNode;