@atolis-hq/corum 0.1.40 → 0.1.42
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.
- package/dist/src/adapters/asyncapi/index.js +1 -1
- package/dist/src/adapters/asyncapi/mapper.js +29 -4
- package/dist/src/adapters/corum/index.js +2 -2
- package/dist/src/adapters/corum/mapper.js +37 -17
- package/dist/src/adapters/openapi/index.js +1 -1
- package/dist/src/adapters/openapi/mapper.js +67 -14
- package/dist/src/adapters/shared/schema-reuse.js +23 -0
- package/dist/src/import/config.js +3 -0
- package/dist/src/import/edge-casing.js +47 -0
- package/dist/src/import/runner.js +28 -3
- package/dist/src/import/schema-promotion.js +103 -0
- package/dist/src/linter/index.js +26 -0
- package/package.json +1 -1
- package/web/app.jsx +6 -2
- package/web/graph-utils.js +67 -2
- package/web/graph-utils.test.js +38 -0
- package/web/graph.jsx +498 -59
- package/web/index.html +1 -1
- package/web/style.css +121 -0
package/web/graph.jsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/* Graph view: interactive three-level canvas using React Flow +
|
|
1
|
+
/* Graph view: interactive three-level canvas using React Flow + ELK.js. */
|
|
2
2
|
|
|
3
3
|
const { useState, useEffect, useMemo, useCallback, useRef } = React;
|
|
4
4
|
const { navigate, Icon, TemplateBadge, StateTag, StabilityTag } = window.CorumPrimitives;
|
|
5
5
|
const { buildRoute, parseRoute } = window.CorumRouter;
|
|
6
|
-
const { buildComponentMap, applyEdgeTypeFilter, getDisplayName } = window.CorumGraphUtils;
|
|
6
|
+
const { buildComponentMap, applyEdgeTypeFilter, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope } = window.CorumGraphUtils;
|
|
7
7
|
|
|
8
8
|
const RF = window.ReactFlow;
|
|
9
9
|
const ReactFlowCanvas = RF.ReactFlow || RF.default;
|
|
@@ -15,6 +15,7 @@ const EDGE_STYLES = {
|
|
|
15
15
|
'calls': { stroke: '#6d28d9', strokeWidth: 1.5 },
|
|
16
16
|
'implements': { stroke: '#475569', strokeWidth: 1.5 },
|
|
17
17
|
'reads': { stroke: '#1d4ed8', strokeWidth: 1.5 },
|
|
18
|
+
'uses-type': { stroke: '#0891b2', strokeWidth: 1.5 },
|
|
18
19
|
'maps-to': { stroke: '#be185d', strokeWidth: 1.5 },
|
|
19
20
|
'derived-from': { stroke: '#6b7280', strokeWidth: 1.5, strokeDasharray: '5,5' },
|
|
20
21
|
};
|
|
@@ -25,11 +26,12 @@ const EDGE_PILL_STYLES = {
|
|
|
25
26
|
'calls': { background: '#ede9fe', color: '#6d28d9' },
|
|
26
27
|
'implements': { background: '#f1f5f9', color: '#475569' },
|
|
27
28
|
'reads': { background: '#dbeafe', color: '#1d4ed8' },
|
|
29
|
+
'uses-type': { background: '#cffafe', color: '#0891b2' },
|
|
28
30
|
'maps-to': { background: '#fce7f3', color: '#be185d' },
|
|
29
31
|
'derived-from': { background: '#f3f4f6', color: '#6b7280' },
|
|
30
32
|
};
|
|
31
33
|
|
|
32
|
-
const ALL_EDGE_TYPES = ['triggers', 'produces', 'reads', 'calls', 'implements', 'maps-to', 'derived-from'];
|
|
34
|
+
const ALL_EDGE_TYPES = ['triggers', 'produces', 'reads', 'uses-type', 'calls', 'implements', 'maps-to', 'derived-from'];
|
|
33
35
|
const DEPTH_STEPS = [1, 2, 3, 4, 5, Infinity];
|
|
34
36
|
|
|
35
37
|
const NODE_W = 210;
|
|
@@ -49,20 +51,263 @@ function saveVisibleEdgeTypes(types) {
|
|
|
49
51
|
try { localStorage.setItem('corum:graphEdgeTypes', JSON.stringify([...types])); } catch {}
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
function
|
|
54
|
+
function loadLayoutMode() {
|
|
55
|
+
try {
|
|
56
|
+
const stored = localStorage.getItem('corum:graphLayoutMode');
|
|
57
|
+
if (stored === 'flat' || stored === 'grouped') return stored;
|
|
58
|
+
} catch {}
|
|
59
|
+
return 'flat';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function saveLayoutMode(mode) {
|
|
63
|
+
try { localStorage.setItem('corum:graphLayoutMode', mode); } catch {}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const elk = new ELK();
|
|
67
|
+
|
|
68
|
+
const ELK_BASE_OPTIONS = {
|
|
69
|
+
'elk.algorithm': 'layered',
|
|
70
|
+
'elk.direction': 'RIGHT',
|
|
71
|
+
'elk.layered.spacing.nodeNodeBetweenLayers': '90',
|
|
72
|
+
'elk.spacing.nodeNode': '40',
|
|
73
|
+
'elk.layered.nodePlacement.strategy': 'NETWORK_SIMPLEX',
|
|
74
|
+
'elk.layered.crossingMinimization.strategy': 'LAYER_SWEEP',
|
|
75
|
+
// Disconnected sub-graphs are separated and stacked by computeLayout, not ELK.
|
|
76
|
+
'elk.separateConnectedComponents': 'false',
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const STACK_GAP = 100;
|
|
80
|
+
const FRAGMENT_GAP = 40;
|
|
81
|
+
|
|
82
|
+
// Flat ELK layout: every node is a direct child of the root.
|
|
83
|
+
async function computeFlatLayout(rfNodes, rfEdges, nodeW, nodeH) {
|
|
53
84
|
if (!rfNodes.length) return rfNodes;
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
85
|
+
const nodeIds = new Set(rfNodes.map(n => n.id));
|
|
86
|
+
const elkGraph = {
|
|
87
|
+
id: 'root',
|
|
88
|
+
layoutOptions: ELK_BASE_OPTIONS,
|
|
89
|
+
children: rfNodes.map(n => ({ id: n.id, width: nodeW, height: nodeH })),
|
|
90
|
+
edges: rfEdges
|
|
91
|
+
.filter(e => nodeIds.has(e.source) && nodeIds.has(e.target))
|
|
92
|
+
.map(e => ({ id: e.id, sources: [e.source], targets: [e.target] })),
|
|
93
|
+
};
|
|
94
|
+
const result = await elk.layout(elkGraph);
|
|
95
|
+
const posById = new Map(result.children.map(c => [c.id, c]));
|
|
60
96
|
return rfNodes.map(n => {
|
|
61
|
-
const pos =
|
|
62
|
-
return { ...n, position: { x: pos.x
|
|
97
|
+
const pos = posById.get(n.id);
|
|
98
|
+
return pos ? { ...n, position: { x: pos.x, y: pos.y } } : n;
|
|
63
99
|
});
|
|
64
100
|
}
|
|
65
101
|
|
|
102
|
+
// Grouped ELK layout: nodes sharing a parentId (2+ visible siblings) are
|
|
103
|
+
// clustered into a compound "group:<parentId>" container node.
|
|
104
|
+
async function computeGroupedLayout(rfNodes, rfEdges, nodeW, nodeH) {
|
|
105
|
+
if (!rfNodes.length) return rfNodes;
|
|
106
|
+
|
|
107
|
+
const parentCounts = new Map();
|
|
108
|
+
for (const n of rfNodes) {
|
|
109
|
+
const pid = n.data?.parentId;
|
|
110
|
+
if (!pid) continue;
|
|
111
|
+
parentCounts.set(pid, (parentCounts.get(pid) ?? 0) + 1);
|
|
112
|
+
}
|
|
113
|
+
const groupParentIds = new Set([...parentCounts.entries()].filter(([, c]) => c >= 2).map(([pid]) => pid));
|
|
114
|
+
|
|
115
|
+
if (!groupParentIds.size) return computeFlatLayout(rfNodes, rfEdges, nodeW, nodeH);
|
|
116
|
+
|
|
117
|
+
const nodeIds = new Set(rfNodes.map(n => n.id));
|
|
118
|
+
const groupChildrenMap = new Map([...groupParentIds].map(pid => [pid, []]));
|
|
119
|
+
const rootChildren = [];
|
|
120
|
+
|
|
121
|
+
for (const n of rfNodes) {
|
|
122
|
+
const pid = n.data?.parentId;
|
|
123
|
+
if (pid && groupParentIds.has(pid)) {
|
|
124
|
+
groupChildrenMap.get(pid).push({ id: n.id, width: nodeW, height: nodeH });
|
|
125
|
+
} else {
|
|
126
|
+
rootChildren.push({ id: n.id, width: nodeW, height: nodeH });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (const pid of groupParentIds) {
|
|
131
|
+
rootChildren.push({
|
|
132
|
+
id: 'group:' + pid,
|
|
133
|
+
layoutOptions: { 'elk.padding': '[top=36,left=16,bottom=16,right=16]' },
|
|
134
|
+
children: groupChildrenMap.get(pid),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const elkGraph = {
|
|
139
|
+
id: 'root',
|
|
140
|
+
layoutOptions: { ...ELK_BASE_OPTIONS, 'elk.hierarchyHandling': 'INCLUDE_CHILDREN' },
|
|
141
|
+
children: rootChildren,
|
|
142
|
+
edges: rfEdges
|
|
143
|
+
.filter(e => nodeIds.has(e.source) && nodeIds.has(e.target))
|
|
144
|
+
.map(e => ({ id: e.id, sources: [e.source], targets: [e.target] })),
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const result = await elk.layout(elkGraph);
|
|
148
|
+
|
|
149
|
+
const groupNodeIds = new Set([...groupParentIds].map(pid => 'group:' + pid));
|
|
150
|
+
const groupBoxes = new Map();
|
|
151
|
+
const nodePositions = new Map();
|
|
152
|
+
|
|
153
|
+
for (const child of result.children) {
|
|
154
|
+
if (groupNodeIds.has(child.id)) {
|
|
155
|
+
groupBoxes.set(child.id, { x: child.x, y: child.y, width: child.width, height: child.height });
|
|
156
|
+
for (const gc of child.children ?? []) {
|
|
157
|
+
nodePositions.set(gc.id, { x: gc.x, y: gc.y });
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
nodePositions.set(child.id, { x: child.x, y: child.y });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const groupNodes = [...groupBoxes.entries()].map(([gid, box]) => ({
|
|
165
|
+
id: gid,
|
|
166
|
+
type: 'groupCard',
|
|
167
|
+
position: { x: box.x, y: box.y },
|
|
168
|
+
style: { width: box.width, height: box.height },
|
|
169
|
+
data: { label: getDisplayName(gid.slice('group:'.length)) },
|
|
170
|
+
}));
|
|
171
|
+
|
|
172
|
+
const memberNodes = rfNodes.map(n => {
|
|
173
|
+
const pos = nodePositions.get(n.id) ?? { x: 0, y: 0 };
|
|
174
|
+
const pid = n.data?.parentId;
|
|
175
|
+
if (pid && groupParentIds.has(pid)) {
|
|
176
|
+
// The group box already shows the owner; drop the per-card owner chip.
|
|
177
|
+
// No extent constraint: members drag freely and the box refits around them.
|
|
178
|
+
return { ...n, position: pos, parentNode: 'group:' + pid, data: { ...n.data, parentLabel: null } };
|
|
179
|
+
}
|
|
180
|
+
return { ...n, position: pos };
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Parent/group nodes must precede their children in the React Flow nodes array.
|
|
184
|
+
return [...groupNodes, ...memberNodes];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const GROUP_PAD = { top: 36, right: 16, bottom: 16, left: 16 };
|
|
188
|
+
|
|
189
|
+
// Fit each group box around its children. With shiftOrigin the box origin
|
|
190
|
+
// moves and children are re-based (full normalise, safe after a drag ends);
|
|
191
|
+
// without it the box only grows right/down, which avoids fighting React
|
|
192
|
+
// Flow's pointer tracking mid-drag.
|
|
193
|
+
function fitGroupsToChildren(nodes, shiftOrigin) {
|
|
194
|
+
const fits = new Map();
|
|
195
|
+
for (const g of nodes) {
|
|
196
|
+
if (g.type !== 'groupCard') continue;
|
|
197
|
+
const children = nodes.filter(n => n.parentNode === g.id);
|
|
198
|
+
if (!children.length) continue;
|
|
199
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
200
|
+
for (const c of children) {
|
|
201
|
+
minX = Math.min(minX, c.position.x);
|
|
202
|
+
minY = Math.min(minY, c.position.y);
|
|
203
|
+
maxX = Math.max(maxX, c.position.x + (c.width ?? NODE_W));
|
|
204
|
+
maxY = Math.max(maxY, c.position.y + (c.height ?? NODE_H));
|
|
205
|
+
}
|
|
206
|
+
fits.set(g.id, shiftOrigin
|
|
207
|
+
? {
|
|
208
|
+
dx: minX - GROUP_PAD.left,
|
|
209
|
+
dy: minY - GROUP_PAD.top,
|
|
210
|
+
width: (maxX - minX) + GROUP_PAD.left + GROUP_PAD.right,
|
|
211
|
+
height: (maxY - minY) + GROUP_PAD.top + GROUP_PAD.bottom,
|
|
212
|
+
}
|
|
213
|
+
: {
|
|
214
|
+
dx: 0,
|
|
215
|
+
dy: 0,
|
|
216
|
+
width: Math.max(g.style?.width ?? 0, maxX + GROUP_PAD.right),
|
|
217
|
+
height: Math.max(g.style?.height ?? 0, maxY + GROUP_PAD.bottom),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (!fits.size) return nodes;
|
|
221
|
+
return nodes.map(n => {
|
|
222
|
+
if (n.type === 'groupCard' && fits.has(n.id)) {
|
|
223
|
+
const f = fits.get(n.id);
|
|
224
|
+
return { ...n, position: { x: n.position.x + f.dx, y: n.position.y + f.dy }, style: { ...n.style, width: f.width, height: f.height } };
|
|
225
|
+
}
|
|
226
|
+
if (n.parentNode && fits.has(n.parentNode)) {
|
|
227
|
+
const f = fits.get(n.parentNode);
|
|
228
|
+
if (!f.dx && !f.dy) return n;
|
|
229
|
+
return { ...n, position: { x: n.position.x - f.dx, y: n.position.y - f.dy } };
|
|
230
|
+
}
|
|
231
|
+
return n;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Lay out each connected component independently, then stack them as
|
|
236
|
+
// left-aligned rows so every flow reads left-to-right from a common edge.
|
|
237
|
+
// Small fragments (pairs/singletons) are packed into a compact grid below.
|
|
238
|
+
async function computeLayout(rfNodes, rfEdges, nodeW, nodeH, mode) {
|
|
239
|
+
if (!rfNodes.length) return rfNodes;
|
|
240
|
+
|
|
241
|
+
// In grouped mode, group co-membership must not split across components.
|
|
242
|
+
const extraLinks = [];
|
|
243
|
+
if (mode === 'grouped') {
|
|
244
|
+
const byParent = new Map();
|
|
245
|
+
for (const n of rfNodes) {
|
|
246
|
+
const pid = n.data?.parentId;
|
|
247
|
+
if (!pid) continue;
|
|
248
|
+
if (!byParent.has(pid)) byParent.set(pid, []);
|
|
249
|
+
byParent.get(pid).push(n.id);
|
|
250
|
+
}
|
|
251
|
+
for (const ids of byParent.values()) {
|
|
252
|
+
for (let i = 1; i < ids.length; i++) extraLinks.push({ from: ids[0], to: ids[i] });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const links = rfEdges.map(e => ({ from: e.source, to: e.target }));
|
|
257
|
+
const components = computeConnectedComponents(rfNodes, links, extraLinks)
|
|
258
|
+
.sort((a, b) => b.length - a.length);
|
|
259
|
+
const flows = components.filter(c => c.length >= 3);
|
|
260
|
+
const fragments = components.filter(c => c.length < 3);
|
|
261
|
+
const nodeById = new Map(rfNodes.map(n => [n.id, n]));
|
|
262
|
+
|
|
263
|
+
const layouts = await Promise.all(flows.map(ids => {
|
|
264
|
+
const idSet = new Set(ids);
|
|
265
|
+
const subNodes = ids.map(id => nodeById.get(id));
|
|
266
|
+
const subEdges = rfEdges.filter(e => idSet.has(e.source) && idSet.has(e.target));
|
|
267
|
+
return mode === 'grouped'
|
|
268
|
+
? computeGroupedLayout(subNodes, subEdges, nodeW, nodeH)
|
|
269
|
+
: computeFlatLayout(subNodes, subEdges, nodeW, nodeH);
|
|
270
|
+
}));
|
|
271
|
+
|
|
272
|
+
const out = [];
|
|
273
|
+
let offsetY = 0;
|
|
274
|
+
let maxWidth = 0;
|
|
275
|
+
for (const layoutNodes of layouts) {
|
|
276
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
277
|
+
for (const n of layoutNodes) {
|
|
278
|
+
if (n.parentNode) continue; // group members are positioned relative to their group
|
|
279
|
+
const w = n.style?.width ?? nodeW;
|
|
280
|
+
const h = n.style?.height ?? nodeH;
|
|
281
|
+
minX = Math.min(minX, n.position.x);
|
|
282
|
+
minY = Math.min(minY, n.position.y);
|
|
283
|
+
maxX = Math.max(maxX, n.position.x + w);
|
|
284
|
+
maxY = Math.max(maxY, n.position.y + h);
|
|
285
|
+
}
|
|
286
|
+
for (const n of layoutNodes) {
|
|
287
|
+
out.push(n.parentNode ? n : { ...n, position: { x: n.position.x - minX, y: n.position.y - minY + offsetY } });
|
|
288
|
+
}
|
|
289
|
+
offsetY += (maxY - minY) + STACK_GAP;
|
|
290
|
+
maxWidth = Math.max(maxWidth, maxX - minX);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const wrapWidth = Math.max(maxWidth, 1600);
|
|
294
|
+
let gx = 0, gy = offsetY;
|
|
295
|
+
for (const ids of fragments) {
|
|
296
|
+
const idSet = new Set(ids);
|
|
297
|
+
const subEdges = rfEdges.filter(e => idSet.has(e.source) && idSet.has(e.target));
|
|
298
|
+
// Order pairs source-first so the arrow reads left-to-right.
|
|
299
|
+
const ordered = ids.length === 2 && subEdges.length ? [subEdges[0].source, subEdges[0].target] : ids;
|
|
300
|
+
const fragW = ordered.length * nodeW + (ordered.length - 1) * FRAGMENT_GAP;
|
|
301
|
+
if (gx > 0 && gx + fragW > wrapWidth) { gx = 0; gy += nodeH + FRAGMENT_GAP; }
|
|
302
|
+
ordered.forEach((id, i) => {
|
|
303
|
+
out.push({ ...nodeById.get(id), position: { x: gx + i * (nodeW + FRAGMENT_GAP), y: gy } });
|
|
304
|
+
});
|
|
305
|
+
gx += fragW + FRAGMENT_GAP * 2;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
|
|
66
311
|
function makeRFEdge(edge, edgeStyles) {
|
|
67
312
|
const style = edgeStyles[edge.type] || { stroke: '#a8acb5', strokeWidth: 1.5 };
|
|
68
313
|
return {
|
|
@@ -78,7 +323,7 @@ function makeRFEdge(edge, edgeStyles) {
|
|
|
78
323
|
};
|
|
79
324
|
}
|
|
80
325
|
|
|
81
|
-
function buildRFNodesForNodes(graphNodes, templateMap, onNodeClick, viewingRef) {
|
|
326
|
+
function buildRFNodesForNodes(graphNodes, templateMap, onNodeClick, viewingRef, fadedIds) {
|
|
82
327
|
return graphNodes.map(n => {
|
|
83
328
|
const tmpl = templateMap.get(n.template);
|
|
84
329
|
const colour = tmpl?.ui?.colour ?? 'var(--ink-4)';
|
|
@@ -98,6 +343,8 @@ function buildRFNodesForNodes(graphNodes, templateMap, onNodeClick, viewingRef)
|
|
|
98
343
|
onClick: () => onNodeClick(n.id),
|
|
99
344
|
viewingRef,
|
|
100
345
|
parentLabel,
|
|
346
|
+
parentId: n.parentId ?? null,
|
|
347
|
+
faded: fadedIds?.has(n.id) ?? false,
|
|
101
348
|
},
|
|
102
349
|
};
|
|
103
350
|
});
|
|
@@ -123,7 +370,7 @@ function ComponentCardNode({ data }) {
|
|
|
123
370
|
function NodeCardNode({ data }) {
|
|
124
371
|
const colour = data.colour ?? 'var(--ink-4)';
|
|
125
372
|
return (
|
|
126
|
-
<div className=
|
|
373
|
+
<div className={`graph-node-card${data.faded ? ' faded' : ''}${data.focal ? ' focal' : ''}`} onClick={data.onClick}>
|
|
127
374
|
{data.parentLabel && (
|
|
128
375
|
<div className="graph-node-card-owner">{data.parentLabel}</div>
|
|
129
376
|
)}
|
|
@@ -154,7 +401,16 @@ function NodeCardNode({ data }) {
|
|
|
154
401
|
);
|
|
155
402
|
}
|
|
156
403
|
|
|
157
|
-
|
|
404
|
+
// Grouped-mode compound container: label only, member nodes render as children.
|
|
405
|
+
function GroupCardNode({ data }) {
|
|
406
|
+
return (
|
|
407
|
+
<div className="graph-group-card">
|
|
408
|
+
<div className="graph-group-card-label">{data.label}</div>
|
|
409
|
+
</div>
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const nodeTypes = { componentCard: ComponentCardNode, nodeCard: NodeCardNode, groupCard: GroupCardNode };
|
|
158
414
|
|
|
159
415
|
function GraphBreadcrumb({ level, selectedComponent, focalNodeId, onNavigateToRoot, onNavigateToComponent }) {
|
|
160
416
|
return (
|
|
@@ -179,10 +435,91 @@ function GraphBreadcrumb({ level, selectedComponent, focalNodeId, onNavigateToRo
|
|
|
179
435
|
);
|
|
180
436
|
}
|
|
181
437
|
|
|
182
|
-
function
|
|
438
|
+
function ScopePopover({ scope, onScope, scopeOptions, onClose }) {
|
|
439
|
+
const [edgeType, setEdgeType] = useState(scope?.edgeType ?? '');
|
|
440
|
+
const [fromTemplate, setFromTemplate] = useState(scope?.fromTemplate ?? '');
|
|
441
|
+
const [toTemplate, setToTemplate] = useState(scope?.toTemplate ?? '');
|
|
442
|
+
const [owner, setOwner] = useState(scope?.owner ?? '');
|
|
443
|
+
|
|
444
|
+
function apply() {
|
|
445
|
+
if (!edgeType && !owner) { onScope(null); onClose(); return; }
|
|
446
|
+
onScope({
|
|
447
|
+
edgeType: edgeType || null,
|
|
448
|
+
fromTemplate: edgeType ? (fromTemplate || null) : null,
|
|
449
|
+
toTemplate: edgeType ? (toTemplate || null) : null,
|
|
450
|
+
owner: owner || null,
|
|
451
|
+
});
|
|
452
|
+
onClose();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return (
|
|
456
|
+
<div className="graph-scope-popover">
|
|
457
|
+
<div className="graph-scope-row">
|
|
458
|
+
<label className="graph-scope-label">Interaction</label>
|
|
459
|
+
<select className="graph-scope-select" value={edgeType} onChange={e => setEdgeType(e.target.value)}>
|
|
460
|
+
<option value="">any</option>
|
|
461
|
+
{scopeOptions.edgeTypes.map(t => <option key={t} value={t}>{t}</option>)}
|
|
462
|
+
</select>
|
|
463
|
+
</div>
|
|
464
|
+
<div className="graph-scope-row">
|
|
465
|
+
<label className="graph-scope-label">From</label>
|
|
466
|
+
<select className="graph-scope-select" value={fromTemplate} onChange={e => setFromTemplate(e.target.value)} disabled={!edgeType}>
|
|
467
|
+
<option value="">any template</option>
|
|
468
|
+
{scopeOptions.templates.map(t => <option key={t.name} value={t.name}>{t.label}</option>)}
|
|
469
|
+
</select>
|
|
470
|
+
</div>
|
|
471
|
+
<div className="graph-scope-row">
|
|
472
|
+
<label className="graph-scope-label">To</label>
|
|
473
|
+
<select className="graph-scope-select" value={toTemplate} onChange={e => setToTemplate(e.target.value)} disabled={!edgeType}>
|
|
474
|
+
<option value="">any template</option>
|
|
475
|
+
{scopeOptions.templates.map(t => <option key={t.name} value={t.name}>{t.label}</option>)}
|
|
476
|
+
</select>
|
|
477
|
+
</div>
|
|
478
|
+
<div className="graph-scope-row">
|
|
479
|
+
<label className="graph-scope-label">Owner</label>
|
|
480
|
+
<select className="graph-scope-select" value={owner} onChange={e => setOwner(e.target.value)}>
|
|
481
|
+
<option value="">any</option>
|
|
482
|
+
{scopeOptions.owners.map(o => <option key={o.id} value={o.id}>{o.label}</option>)}
|
|
483
|
+
</select>
|
|
484
|
+
</div>
|
|
485
|
+
<div className="graph-scope-actions">
|
|
486
|
+
<button className="graph-toolbar-btn" onClick={() => { onScope(null); onClose(); }}>Clear</button>
|
|
487
|
+
<button className="graph-toolbar-btn active" onClick={apply}>Apply</button>
|
|
488
|
+
</div>
|
|
489
|
+
</div>
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function describeScope(scope, scopeOptions) {
|
|
494
|
+
const parts = [];
|
|
495
|
+
if (scope.edgeType) {
|
|
496
|
+
const from = scope.fromTemplate
|
|
497
|
+
? (scopeOptions.templates.find(t => t.name === scope.fromTemplate)?.label ?? scope.fromTemplate)
|
|
498
|
+
: 'any';
|
|
499
|
+
const to = scope.toTemplate
|
|
500
|
+
? (scopeOptions.templates.find(t => t.name === scope.toTemplate)?.label ?? scope.toTemplate)
|
|
501
|
+
: 'any';
|
|
502
|
+
parts.push(`${scope.edgeType} · ${from} → ${to}`);
|
|
503
|
+
}
|
|
504
|
+
if (scope.owner) parts.push(getDisplayName(scope.owner));
|
|
505
|
+
return parts.join(' · ');
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function GraphToolbar({ visibleEdgeTypes, onToggleEdgeType, showMinimap, onToggleMinimap, onResetLayout, level, depth, onDepth, allNodes, focalNodeId, onFocalNode, layoutMode, onLayoutMode, scope, onScope, scopeOptions, scopeInfo }) {
|
|
183
509
|
const [searchQuery, setSearchQuery] = useState('');
|
|
184
510
|
const [searchOpen, setSearchOpen] = useState(false);
|
|
511
|
+
const [scopeOpen, setScopeOpen] = useState(false);
|
|
185
512
|
const searchRef = useRef(null);
|
|
513
|
+
const scopeRef = useRef(null);
|
|
514
|
+
|
|
515
|
+
useEffect(() => {
|
|
516
|
+
if (!scopeOpen) return;
|
|
517
|
+
function handleClick(e) {
|
|
518
|
+
if (scopeRef.current && !scopeRef.current.contains(e.target)) setScopeOpen(false);
|
|
519
|
+
}
|
|
520
|
+
document.addEventListener('mousedown', handleClick);
|
|
521
|
+
return () => document.removeEventListener('mousedown', handleClick);
|
|
522
|
+
}, [scopeOpen]);
|
|
186
523
|
|
|
187
524
|
const searchResults = useMemo(() => {
|
|
188
525
|
if (!searchQuery.trim()) return [];
|
|
@@ -259,6 +596,46 @@ function GraphToolbar({ visibleEdgeTypes, onToggleEdgeType, showMinimap, onToggl
|
|
|
259
596
|
<div className="graph-toolbar-sep" />
|
|
260
597
|
</>
|
|
261
598
|
)}
|
|
599
|
+
{level === 'interior' && scopeOptions && (
|
|
600
|
+
<>
|
|
601
|
+
<div className="graph-scope" ref={scopeRef}>
|
|
602
|
+
<button
|
|
603
|
+
className={`graph-toolbar-btn${scope ? ' active' : ''}`}
|
|
604
|
+
onClick={() => setScopeOpen(v => !v)}
|
|
605
|
+
>Scope</button>
|
|
606
|
+
{scopeOpen && (
|
|
607
|
+
<ScopePopover
|
|
608
|
+
key={scope ? describeScope(scope, scopeOptions) : 'empty'}
|
|
609
|
+
scope={scope}
|
|
610
|
+
onScope={onScope}
|
|
611
|
+
scopeOptions={scopeOptions}
|
|
612
|
+
onClose={() => setScopeOpen(false)}
|
|
613
|
+
/>
|
|
614
|
+
)}
|
|
615
|
+
</div>
|
|
616
|
+
{scope && (
|
|
617
|
+
<span className="graph-scope-pill">
|
|
618
|
+
{describeScope(scope, scopeOptions)}
|
|
619
|
+
<span className="graph-scope-pill-clear" onClick={() => onScope(null)}>×</span>
|
|
620
|
+
</span>
|
|
621
|
+
)}
|
|
622
|
+
{scope && scopeInfo && (
|
|
623
|
+
<span className="graph-scope-count">{scopeInfo.matchCount} of {scopeInfo.threadCount} threads</span>
|
|
624
|
+
)}
|
|
625
|
+
</>
|
|
626
|
+
)}
|
|
627
|
+
{level !== 'component' && (
|
|
628
|
+
<div className="graph-layout-toggle">
|
|
629
|
+
<button
|
|
630
|
+
className={`graph-toolbar-btn${layoutMode === 'flat' ? ' active' : ''}`}
|
|
631
|
+
onClick={() => onLayoutMode('flat')}
|
|
632
|
+
>Flat</button>
|
|
633
|
+
<button
|
|
634
|
+
className={`graph-toolbar-btn${layoutMode === 'grouped' ? ' active' : ''}`}
|
|
635
|
+
onClick={() => onLayoutMode('grouped')}
|
|
636
|
+
>Grouped</button>
|
|
637
|
+
</div>
|
|
638
|
+
)}
|
|
262
639
|
<button className="graph-toolbar-btn" onClick={onResetLayout}>Reset layout</button>
|
|
263
640
|
<button className={`graph-toolbar-btn${showMinimap ? ' active' : ''}`} onClick={onToggleMinimap}>Minimap</button>
|
|
264
641
|
</div>
|
|
@@ -272,6 +649,8 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
272
649
|
const [showMinimap, setShowMinimap] = useState(false);
|
|
273
650
|
const [depth, setDepth] = useState(2);
|
|
274
651
|
const [layoutKey, setLayoutKey] = useState(0);
|
|
652
|
+
const [layoutMode, setLayoutMode] = useState(loadLayoutMode);
|
|
653
|
+
const [scope, setScope] = useState(null);
|
|
275
654
|
const [focusData, setFocusData] = useState(null);
|
|
276
655
|
const [reactFlowInstance, setReactFlowInstance] = useState(null);
|
|
277
656
|
const pendingViewportRef = useRef(null);
|
|
@@ -285,6 +664,8 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
285
664
|
const focalNodeId = route.params.get('focus') ?? null;
|
|
286
665
|
const level = focalNodeId ? 'focus' : selectedComponent ? 'interior' : 'component';
|
|
287
666
|
|
|
667
|
+
useEffect(() => { setScope(null); }, [selectedComponent]);
|
|
668
|
+
|
|
288
669
|
const navToRoot = useCallback(() => {
|
|
289
670
|
navigate(buildRoute({ pathname: '/graph', params: {}, branch: viewingRef }));
|
|
290
671
|
}, [viewingRef]);
|
|
@@ -354,15 +735,20 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
354
735
|
label: e.types.join(', '),
|
|
355
736
|
};
|
|
356
737
|
});
|
|
357
|
-
return { rfN
|
|
738
|
+
return { rfN, rfE };
|
|
358
739
|
}, [graphData, visibleEdgeTypes, layoutKey, navToComponent]);
|
|
359
740
|
|
|
360
741
|
useEffect(() => {
|
|
361
742
|
if (level !== 'component' || !level1) return;
|
|
743
|
+
let cancelled = false;
|
|
362
744
|
pendingViewportRef.current = { type: 'full' };
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
745
|
+
computeLayout(level1.rfN, level1.rfE, COMP_W, COMP_H, layoutMode).then(positioned => {
|
|
746
|
+
if (cancelled) return;
|
|
747
|
+
setRfNodes(positioned);
|
|
748
|
+
setRfEdges(level1.rfE);
|
|
749
|
+
});
|
|
750
|
+
return () => { cancelled = true; };
|
|
751
|
+
}, [level, level1, layoutMode]);
|
|
366
752
|
|
|
367
753
|
// Level 2: component interior
|
|
368
754
|
const level2 = useMemo(() => {
|
|
@@ -381,20 +767,64 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
381
767
|
const externalNodes = graphData.nodes.filter(n => externalNodeIds.has(n.id));
|
|
382
768
|
const allVisibleNodes = [...compNodes, ...externalNodes];
|
|
383
769
|
const allVisibleEdges = [...internalEdges, ...crossEdges];
|
|
384
|
-
|
|
385
|
-
|
|
770
|
+
|
|
771
|
+
// Options for the scope popover reflect the unscoped view.
|
|
772
|
+
const typedEdges = applyEdgeTypeFilter(allVisibleEdges, visibleEdgeTypes);
|
|
773
|
+
const parentCounts = new Map();
|
|
774
|
+
for (const n of allVisibleNodes) {
|
|
775
|
+
if (!n.parentId) continue;
|
|
776
|
+
parentCounts.set(n.parentId, (parentCounts.get(n.parentId) ?? 0) + 1);
|
|
777
|
+
}
|
|
778
|
+
const scopeOptions = {
|
|
779
|
+
edgeTypes: ALL_EDGE_TYPES.filter(t => visibleEdgeTypes.has(t) && typedEdges.some(e => e.type === t)),
|
|
780
|
+
templates: [...new Set(allVisibleNodes.map(n => n.template))].sort()
|
|
781
|
+
.map(name => ({ name, label: templateMap.get(name)?.ui?.displayName ?? name })),
|
|
782
|
+
owners: [...parentCounts.entries()].filter(([, c]) => c >= 2).map(([pid]) => pid).sort()
|
|
783
|
+
.map(pid => ({ id: pid, label: getDisplayName(pid) })),
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
// Apply the active scope: threads containing an interaction, then owner.
|
|
787
|
+
let visibleNodes = allVisibleNodes;
|
|
788
|
+
let visibleEdges = allVisibleEdges;
|
|
789
|
+
let scopeInfo = null;
|
|
790
|
+
if (scope) {
|
|
791
|
+
let keep = null;
|
|
792
|
+
if (scope.edgeType) {
|
|
793
|
+
const result = filterThreadScope(visibleNodes, typedEdges, scope);
|
|
794
|
+
keep = result.nodeIds;
|
|
795
|
+
scopeInfo = { matchCount: result.matchCount, threadCount: result.threadCount };
|
|
796
|
+
}
|
|
797
|
+
if (scope.owner) {
|
|
798
|
+
const baseNodes = keep ? visibleNodes.filter(n => keep.has(n.id)) : visibleNodes;
|
|
799
|
+
const baseEdges = typedEdges.filter(e => !keep || (keep.has(e.from) && keep.has(e.to)));
|
|
800
|
+
keep = filterOwnerScope(baseNodes, baseEdges, scope.owner);
|
|
801
|
+
}
|
|
802
|
+
if (keep) {
|
|
803
|
+
const keepIds = keep;
|
|
804
|
+
visibleNodes = visibleNodes.filter(n => keepIds.has(n.id));
|
|
805
|
+
visibleEdges = visibleEdges.filter(e => keepIds.has(e.from) && keepIds.has(e.to));
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const rfN = buildRFNodesForNodes(visibleNodes, templateMap, navToFocus, viewingRef, externalNodeIds);
|
|
810
|
+
const rfE = buildRFEdgesForEdges(visibleEdges, visibleEdgeTypes).map(e => {
|
|
386
811
|
const isCross = crossEdges.some(ce => ce.id === e.id);
|
|
387
812
|
return isCross ? { ...e, style: { ...e.style, opacity: 0.45 }, labelStyle: { ...e.labelStyle, opacity: 0.45 } } : e;
|
|
388
813
|
});
|
|
389
|
-
return { rfN
|
|
390
|
-
}, [graphData, selectedComponent, visibleEdgeTypes, templateMap, layoutKey, navToFocus]);
|
|
814
|
+
return { rfN, rfE, scopeOptions, scopeInfo };
|
|
815
|
+
}, [graphData, selectedComponent, visibleEdgeTypes, templateMap, layoutKey, navToFocus, scope]);
|
|
391
816
|
|
|
392
817
|
useEffect(() => {
|
|
393
818
|
if (level !== 'interior' || !level2) return;
|
|
819
|
+
let cancelled = false;
|
|
394
820
|
pendingViewportRef.current = { type: 'full' };
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
821
|
+
computeLayout(level2.rfN, level2.rfE, NODE_W, NODE_H, layoutMode).then(positioned => {
|
|
822
|
+
if (cancelled) return;
|
|
823
|
+
setRfNodes(positioned);
|
|
824
|
+
setRfEdges(level2.rfE);
|
|
825
|
+
});
|
|
826
|
+
return () => { cancelled = true; };
|
|
827
|
+
}, [level, level2, layoutMode]);
|
|
398
828
|
|
|
399
829
|
useEffect(() => {
|
|
400
830
|
if (level === 'focus') return;
|
|
@@ -415,30 +845,27 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
415
845
|
...(focalNode && !focusData.nodes.some(n => n.id === focalNodeId) ? [focalNode] : []),
|
|
416
846
|
...focusData.nodes,
|
|
417
847
|
].map(n => ({ ...n, parentId: parentIdMap.get(n.id) ?? null }));
|
|
418
|
-
const rfN = buildRFNodesForNodes(lineageNodes, templateMap,
|
|
419
|
-
|
|
420
|
-
}, viewingRef);
|
|
848
|
+
const rfN = buildRFNodesForNodes(lineageNodes, templateMap, navToFocus, viewingRef)
|
|
849
|
+
.map(n => n.id === focalNodeId ? { ...n, data: { ...n.data, focal: true } } : n);
|
|
421
850
|
const rfE = buildRFEdgesForEdges(applyEdgeTypeFilter(focusData.edges, visibleEdgeTypes), visibleEdgeTypes);
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
rfN: layoutedN.map(n => n.id === focalNodeId
|
|
425
|
-
? { ...n, style: { outline: '2px solid var(--accent)', outlineOffset: '2px', borderRadius: 'var(--radius)' } }
|
|
426
|
-
: n
|
|
427
|
-
),
|
|
428
|
-
rfE,
|
|
429
|
-
};
|
|
430
|
-
}, [focusData, focalNodeId, visibleEdgeTypes, templateMap, layoutKey, viewingRef, graphData, nodeById]);
|
|
851
|
+
return { rfN, rfE };
|
|
852
|
+
}, [focusData, focalNodeId, visibleEdgeTypes, templateMap, layoutKey, viewingRef, graphData, nodeById, navToFocus]);
|
|
431
853
|
|
|
432
854
|
useEffect(() => {
|
|
433
855
|
if (level !== 'focus' || !level3) return;
|
|
856
|
+
let cancelled = false;
|
|
434
857
|
const focalChanged = lastFocusedNodeIdRef.current !== focalNodeId;
|
|
435
858
|
if (focalChanged) {
|
|
436
859
|
pendingViewportRef.current = { type: 'focus', nodeId: focalNodeId };
|
|
437
860
|
}
|
|
438
861
|
lastFocusedNodeIdRef.current = focalNodeId;
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
862
|
+
computeLayout(level3.rfN, level3.rfE, NODE_W, NODE_H, layoutMode).then(positioned => {
|
|
863
|
+
if (cancelled) return;
|
|
864
|
+
setRfNodes(positioned);
|
|
865
|
+
setRfEdges(level3.rfE);
|
|
866
|
+
});
|
|
867
|
+
return () => { cancelled = true; };
|
|
868
|
+
}, [level, level3, focalNodeId, layoutMode]);
|
|
442
869
|
|
|
443
870
|
useEffect(() => {
|
|
444
871
|
if (!reactFlowInstance || !rfNodes.length) return;
|
|
@@ -447,22 +874,16 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
447
874
|
const pending = pendingViewportRef.current;
|
|
448
875
|
if (!pending) return;
|
|
449
876
|
if (pending.type === 'focus' && !rfNodes.some(node => node.id === pending.nodeId)) return;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
reactFlowInstance.fitView({
|
|
457
|
-
duration: 0,
|
|
458
|
-
padding: 0.2,
|
|
459
|
-
});
|
|
460
|
-
} else {
|
|
461
|
-
reactFlowInstance.fitView({
|
|
462
|
-
duration: 0,
|
|
463
|
-
padding: 0.2,
|
|
464
|
-
});
|
|
877
|
+
const measuredId = pending.type === 'focus' ? pending.nodeId : rfNodes[0]?.id;
|
|
878
|
+
const measuredNode = measuredId ? reactFlowInstance.getNode(measuredId) : null;
|
|
879
|
+
if (!measuredNode?.width || !measuredNode?.height) {
|
|
880
|
+
frameId = requestAnimationFrame(fitPendingViewport);
|
|
881
|
+
return;
|
|
465
882
|
}
|
|
883
|
+
reactFlowInstance.fitView({
|
|
884
|
+
duration: 0,
|
|
885
|
+
padding: 0.2,
|
|
886
|
+
});
|
|
466
887
|
pendingViewportRef.current = null;
|
|
467
888
|
}
|
|
468
889
|
frameId = requestAnimationFrame(fitPendingViewport);
|
|
@@ -471,6 +892,16 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
471
892
|
};
|
|
472
893
|
}, [reactFlowInstance, rfNodes, rfEdges]);
|
|
473
894
|
|
|
895
|
+
const handleNodeDrag = useCallback((event, node) => {
|
|
896
|
+
if (!node.parentNode) return;
|
|
897
|
+
setRfNodes(ns => fitGroupsToChildren(ns, false));
|
|
898
|
+
}, [setRfNodes]);
|
|
899
|
+
|
|
900
|
+
const handleNodeDragStop = useCallback((event, node) => {
|
|
901
|
+
if (!node.parentNode) return;
|
|
902
|
+
setRfNodes(ns => fitGroupsToChildren(ns, true));
|
|
903
|
+
}, [setRfNodes]);
|
|
904
|
+
|
|
474
905
|
function handleToggleEdgeType(type) {
|
|
475
906
|
setVisibleEdgeTypes(prev => {
|
|
476
907
|
const next = new Set(prev);
|
|
@@ -487,7 +918,7 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
487
918
|
<div className="graph-section">
|
|
488
919
|
<GraphBreadcrumb
|
|
489
920
|
level={level}
|
|
490
|
-
selectedComponent={selectedComponent}
|
|
921
|
+
selectedComponent={selectedComponent ?? (focalNodeId ? nodeById.get(focalNodeId)?.component ?? null : null)}
|
|
491
922
|
focalNodeId={focalNodeId}
|
|
492
923
|
onNavigateToRoot={navToRoot}
|
|
493
924
|
onNavigateToComponent={navToComponent}
|
|
@@ -497,13 +928,19 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
497
928
|
onToggleEdgeType={handleToggleEdgeType}
|
|
498
929
|
showMinimap={showMinimap}
|
|
499
930
|
onToggleMinimap={() => setShowMinimap(v => !v)}
|
|
500
|
-
onResetLayout={() => setLayoutKey(k => k + 1)}
|
|
931
|
+
onResetLayout={() => { pendingViewportRef.current = { type: 'full' }; setLayoutKey(k => k + 1); }}
|
|
501
932
|
level={level}
|
|
502
933
|
depth={depth}
|
|
503
934
|
onDepth={setDepth}
|
|
504
935
|
allNodes={graphData?.nodes ?? []}
|
|
505
936
|
focalNodeId={focalNodeId}
|
|
506
937
|
onFocalNode={navToFocus}
|
|
938
|
+
layoutMode={layoutMode}
|
|
939
|
+
onLayoutMode={mode => { saveLayoutMode(mode); setLayoutMode(mode); }}
|
|
940
|
+
scope={scope}
|
|
941
|
+
onScope={setScope}
|
|
942
|
+
scopeOptions={level === 'interior' ? level2?.scopeOptions : null}
|
|
943
|
+
scopeInfo={level === 'interior' ? level2?.scopeInfo : null}
|
|
507
944
|
/>
|
|
508
945
|
<div className="graph-canvas-wrap">
|
|
509
946
|
<ReactFlowProvider>
|
|
@@ -512,6 +949,8 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
512
949
|
edges={rfEdges}
|
|
513
950
|
onNodesChange={onNodesChange}
|
|
514
951
|
onEdgesChange={onEdgesChange}
|
|
952
|
+
onNodeDrag={handleNodeDrag}
|
|
953
|
+
onNodeDragStop={handleNodeDragStop}
|
|
515
954
|
onInit={setReactFlowInstance}
|
|
516
955
|
nodeTypes={nodeTypes}
|
|
517
956
|
fitView
|