@principal-ai/subsystems-react 0.56.21 → 0.56.23
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/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.d.ts +12 -0
- package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.d.ts.map +1 -0
- package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.js +4 -0
- package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.js.map +1 -0
- package/dist/subsystem/C4Graph.d.ts +2 -69
- package/dist/subsystem/C4Graph.d.ts.map +1 -1
- package/dist/subsystem/C4Graph.js +8 -154
- package/dist/subsystem/C4Graph.js.map +1 -1
- package/dist/subsystem/C4NodeCard.d.ts +1 -47
- package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
- package/dist/subsystem/C4NodeCard.js +6 -141
- package/dist/subsystem/C4NodeCard.js.map +1 -1
- package/dist/subsystem/ContainersPanel.d.ts +33 -0
- package/dist/subsystem/ContainersPanel.d.ts.map +1 -0
- package/dist/subsystem/ContainersPanel.js +116 -0
- package/dist/subsystem/ContainersPanel.js.map +1 -0
- package/dist/subsystem/SubsystemAggregateGraph.d.ts +14 -0
- package/dist/subsystem/SubsystemAggregateGraph.d.ts.map +1 -1
- package/dist/subsystem/SubsystemAggregateGraph.js +116 -69
- package/dist/subsystem/SubsystemAggregateGraph.js.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.d.ts +18 -1
- package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.js +143 -21
- package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
- package/dist/subsystem/containerCard.d.ts +132 -0
- package/dist/subsystem/containerCard.d.ts.map +1 -0
- package/dist/subsystem/containerCard.js +167 -0
- package/dist/subsystem/containerCard.js.map +1 -0
- package/dist/subsystem/graphChrome.d.ts +11 -8
- package/dist/subsystem/graphChrome.d.ts.map +1 -1
- package/dist/subsystem/graphChrome.js +11 -9
- package/dist/subsystem/graphChrome.js.map +1 -1
- package/dist/subsystem/graphMorph.d.ts +142 -0
- package/dist/subsystem/graphMorph.d.ts.map +1 -0
- package/dist/subsystem/graphMorph.js +177 -0
- package/dist/subsystem/graphMorph.js.map +1 -0
- package/dist/subsystem/model.d.ts +89 -0
- package/dist/subsystem/model.d.ts.map +1 -1
- package/dist/subsystem/model.js +224 -15
- package/dist/subsystem/model.js.map +1 -1
- package/dist/subsystem/nodes.d.ts +9 -3
- package/dist/subsystem/nodes.d.ts.map +1 -1
- package/dist/subsystem/nodes.js +134 -82
- package/dist/subsystem/nodes.js.map +1 -1
- package/dist/utils/elkLayout.d.ts +11 -0
- package/dist/utils/elkLayout.d.ts.map +1 -1
- package/dist/utils/elkLayout.js +4 -3
- package/dist/utils/elkLayout.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/stories/Canvases/Aggregate/AggregateFrameGraph.stories.tsx +140 -2
- package/src/stories/Canvases/Aggregate/aggregateViewLargeFixture.ts +14 -0
- package/src/stories/Canvases/Subsystem/ContainerFrames.stories.tsx +132 -0
- package/src/subsystem/C4Graph.tsx +20 -180
- package/src/subsystem/C4NodeCard.tsx +34 -202
- package/src/subsystem/ContainersPanel.tsx +239 -0
- package/src/subsystem/SubsystemAggregateGraph.tsx +146 -78
- package/src/subsystem/SubsystemComponentGraph.tsx +222 -25
- package/src/subsystem/containerCard.tsx +264 -0
- package/src/subsystem/graphChrome.tsx +11 -9
- package/src/subsystem/graphMorph.tsx +212 -0
- package/src/subsystem/model.collapse.test.ts +128 -0
- package/src/subsystem/model.ts +306 -16
- package/src/subsystem/nodes.group.test.tsx +125 -16
- package/src/subsystem/nodes.tsx +201 -91
- package/src/utils/elkLayout.ts +16 -2
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sidebar list of the graph's container frames — the process and package
|
|
3
|
+
* regions drawn as container cards.
|
|
4
|
+
*
|
|
5
|
+
* One row per frame, nested the way the frames nest on the canvas. A row click
|
|
6
|
+
* frames the container on the canvas; the trailing button opens or closes it
|
|
7
|
+
* (members folded away into the card, or laid back out). The header's
|
|
8
|
+
* "Open all" / "Close all" set every frame at once.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useTheme } from '@principal-ade/industry-theme';
|
|
12
|
+
import { AppWindow, Component, Database, Maximize2, Minimize2, Package } from 'lucide-react';
|
|
13
|
+
import type { CSSProperties } from 'react';
|
|
14
|
+
import type { SubsystemProcessRegion } from './model';
|
|
15
|
+
import { TechMark, technologyBrand } from './techIcons';
|
|
16
|
+
|
|
17
|
+
export interface ContainerListItem {
|
|
18
|
+
/** Boundary group node id — what the canvas toggles and frames. */
|
|
19
|
+
id: string;
|
|
20
|
+
region: SubsystemProcessRegion;
|
|
21
|
+
/** Drawn as a closed card. */
|
|
22
|
+
collapsed: boolean;
|
|
23
|
+
/** Nesting depth under other container frames (0 = top level). */
|
|
24
|
+
depth: number;
|
|
25
|
+
/** Frame colour as drawn on the canvas. */
|
|
26
|
+
color: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ContainersPanelProps {
|
|
30
|
+
containers: readonly ContainerListItem[];
|
|
31
|
+
/** The container last framed from this list. */
|
|
32
|
+
activeId?: string | null;
|
|
33
|
+
onFocus: (id: string) => void;
|
|
34
|
+
onToggle: (id: string) => void;
|
|
35
|
+
onOpenAll: () => void;
|
|
36
|
+
onCloseAll: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function ContainersPanel({
|
|
40
|
+
containers,
|
|
41
|
+
activeId,
|
|
42
|
+
onFocus,
|
|
43
|
+
onToggle,
|
|
44
|
+
onOpenAll,
|
|
45
|
+
onCloseAll,
|
|
46
|
+
}: ContainersPanelProps) {
|
|
47
|
+
const { theme } = useTheme();
|
|
48
|
+
const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
|
|
49
|
+
const anyOpen = containers.some((c) => !c.collapsed);
|
|
50
|
+
const anyClosed = containers.some((c) => c.collapsed);
|
|
51
|
+
const bulkStyle = (enabled: boolean): CSSProperties => ({
|
|
52
|
+
padding: '2px 8px',
|
|
53
|
+
border: `1px solid ${theme.colors.border}`,
|
|
54
|
+
borderRadius: 4,
|
|
55
|
+
background: 'transparent',
|
|
56
|
+
color: enabled ? theme.colors.textSecondary : muted,
|
|
57
|
+
fontFamily: theme.fonts.monospace,
|
|
58
|
+
fontSize: theme.fontSizes[0],
|
|
59
|
+
cursor: enabled ? 'pointer' : 'default',
|
|
60
|
+
opacity: enabled ? 1 : 0.5,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (containers.length === 0) {
|
|
64
|
+
return (
|
|
65
|
+
<div style={{ padding: 16, color: theme.colors.textSecondary }}>No container frames.</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div style={{ display: 'flex', flexDirection: 'column', minHeight: 0 }}>
|
|
71
|
+
<div
|
|
72
|
+
style={{
|
|
73
|
+
display: 'flex',
|
|
74
|
+
alignItems: 'center',
|
|
75
|
+
gap: 6,
|
|
76
|
+
padding: '8px 12px',
|
|
77
|
+
borderBottom: `1px solid ${theme.colors.border}`,
|
|
78
|
+
flexShrink: 0,
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
<span
|
|
82
|
+
style={{
|
|
83
|
+
flex: 1,
|
|
84
|
+
fontFamily: theme.fonts.monospace,
|
|
85
|
+
fontSize: theme.fontSizes[0],
|
|
86
|
+
color: muted,
|
|
87
|
+
textTransform: 'uppercase',
|
|
88
|
+
letterSpacing: 0.5,
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
{containers.length} {containers.length === 1 ? 'container' : 'containers'}
|
|
92
|
+
</span>
|
|
93
|
+
<button type="button" onClick={onOpenAll} disabled={!anyClosed} style={bulkStyle(anyClosed)}>
|
|
94
|
+
Open all
|
|
95
|
+
</button>
|
|
96
|
+
<button type="button" onClick={onCloseAll} disabled={!anyOpen} style={bulkStyle(anyOpen)}>
|
|
97
|
+
Close all
|
|
98
|
+
</button>
|
|
99
|
+
</div>
|
|
100
|
+
<ul
|
|
101
|
+
role="list"
|
|
102
|
+
aria-label="Containers"
|
|
103
|
+
style={{ listStyle: 'none', margin: 0, padding: '6px 0', overflow: 'auto', minHeight: 0 }}
|
|
104
|
+
>
|
|
105
|
+
{containers.map((c) => (
|
|
106
|
+
<ContainerRow
|
|
107
|
+
key={c.id}
|
|
108
|
+
item={c}
|
|
109
|
+
active={c.id === activeId}
|
|
110
|
+
onFocus={() => onFocus(c.id)}
|
|
111
|
+
onToggle={() => onToggle(c.id)}
|
|
112
|
+
/>
|
|
113
|
+
))}
|
|
114
|
+
</ul>
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function ContainerRow({
|
|
120
|
+
item,
|
|
121
|
+
active,
|
|
122
|
+
onFocus,
|
|
123
|
+
onToggle,
|
|
124
|
+
}: {
|
|
125
|
+
item: ContainerListItem;
|
|
126
|
+
active: boolean;
|
|
127
|
+
onFocus: () => void;
|
|
128
|
+
onToggle: () => void;
|
|
129
|
+
}) {
|
|
130
|
+
const { theme } = useTheme();
|
|
131
|
+
const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
|
|
132
|
+
const { region, collapsed, depth, color } = item;
|
|
133
|
+
const isPackage = region.kind === 'package' || region.chrome === 'package';
|
|
134
|
+
const containerKind = region.containerKind ?? 'application';
|
|
135
|
+
const Icon = isPackage ? Package : containerKind === 'data-store' ? Database : AppWindow;
|
|
136
|
+
const brand = technologyBrand(region.technology);
|
|
137
|
+
const topLabel = region.technology ?? (isPackage ? 'package' : containerKind);
|
|
138
|
+
const ToggleIcon = collapsed ? Maximize2 : Minimize2;
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<li
|
|
142
|
+
style={{
|
|
143
|
+
display: 'flex',
|
|
144
|
+
alignItems: 'center',
|
|
145
|
+
gap: 8,
|
|
146
|
+
padding: `6px 12px 6px ${12 + depth * 16}px`,
|
|
147
|
+
background: active ? theme.colors.backgroundSecondary : 'transparent',
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
<button
|
|
151
|
+
type="button"
|
|
152
|
+
onClick={onFocus}
|
|
153
|
+
title={region.description}
|
|
154
|
+
aria-current={active || undefined}
|
|
155
|
+
style={{
|
|
156
|
+
flex: 1,
|
|
157
|
+
minWidth: 0,
|
|
158
|
+
display: 'flex',
|
|
159
|
+
alignItems: 'center',
|
|
160
|
+
gap: 8,
|
|
161
|
+
padding: 0,
|
|
162
|
+
border: 'none',
|
|
163
|
+
background: 'transparent',
|
|
164
|
+
color: theme.colors.text,
|
|
165
|
+
textAlign: 'left',
|
|
166
|
+
cursor: 'pointer',
|
|
167
|
+
fontFamily: theme.fonts.body,
|
|
168
|
+
}}
|
|
169
|
+
>
|
|
170
|
+
<span
|
|
171
|
+
aria-hidden
|
|
172
|
+
style={{
|
|
173
|
+
width: 3,
|
|
174
|
+
alignSelf: 'stretch',
|
|
175
|
+
borderRadius: 2,
|
|
176
|
+
background: color,
|
|
177
|
+
flexShrink: 0,
|
|
178
|
+
}}
|
|
179
|
+
/>
|
|
180
|
+
<Icon size={14} color={color} aria-hidden />
|
|
181
|
+
<span style={{ minWidth: 0, display: 'flex', flexDirection: 'column', gap: 1 }}>
|
|
182
|
+
<span
|
|
183
|
+
style={{
|
|
184
|
+
fontSize: theme.fontSizes[1],
|
|
185
|
+
fontWeight: 600,
|
|
186
|
+
overflow: 'hidden',
|
|
187
|
+
textOverflow: 'ellipsis',
|
|
188
|
+
whiteSpace: 'nowrap',
|
|
189
|
+
}}
|
|
190
|
+
>
|
|
191
|
+
{region.label}
|
|
192
|
+
</span>
|
|
193
|
+
<span
|
|
194
|
+
style={{
|
|
195
|
+
display: 'inline-flex',
|
|
196
|
+
alignItems: 'center',
|
|
197
|
+
gap: 5,
|
|
198
|
+
fontFamily: theme.fonts.monospace,
|
|
199
|
+
fontSize: theme.fontSizes[0],
|
|
200
|
+
color: muted,
|
|
201
|
+
textTransform: 'uppercase',
|
|
202
|
+
letterSpacing: 0.5,
|
|
203
|
+
whiteSpace: 'nowrap',
|
|
204
|
+
}}
|
|
205
|
+
>
|
|
206
|
+
{brand && <TechMark brand={brand} size={10} />}
|
|
207
|
+
<span>{topLabel}</span>
|
|
208
|
+
<span aria-hidden>·</span>
|
|
209
|
+
<Component size={10} aria-hidden />
|
|
210
|
+
<span>{region.memberAliases.length}</span>
|
|
211
|
+
</span>
|
|
212
|
+
</span>
|
|
213
|
+
</button>
|
|
214
|
+
<button
|
|
215
|
+
type="button"
|
|
216
|
+
onClick={onToggle}
|
|
217
|
+
aria-label={collapsed ? `Show members of ${region.label}` : `Hide members of ${region.label}`}
|
|
218
|
+
aria-pressed={collapsed}
|
|
219
|
+
style={{
|
|
220
|
+
display: 'inline-flex',
|
|
221
|
+
alignItems: 'center',
|
|
222
|
+
justifyContent: 'center',
|
|
223
|
+
width: 22,
|
|
224
|
+
height: 22,
|
|
225
|
+
padding: 0,
|
|
226
|
+
flexShrink: 0,
|
|
227
|
+
borderRadius: 4,
|
|
228
|
+
border: `1px solid ${color}`,
|
|
229
|
+
background: 'transparent',
|
|
230
|
+
color,
|
|
231
|
+
cursor: 'pointer',
|
|
232
|
+
lineHeight: 1,
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
<ToggleIcon size={12} strokeWidth={2.25} />
|
|
236
|
+
</button>
|
|
237
|
+
</li>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* renders in a side panel.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
16
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
17
17
|
import {
|
|
18
18
|
Edge,
|
|
19
19
|
Handle,
|
|
@@ -80,6 +80,21 @@ export interface SubsystemAggregateGraphProps {
|
|
|
80
80
|
title?: string;
|
|
81
81
|
onSelectFrame?: (id: string | null) => void;
|
|
82
82
|
onOpenFile?: (path: string) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Fires once per layout pass with how long ELK took and what it laid out.
|
|
85
|
+
* Diagnostic: lets a host separate layout cost from React render cost.
|
|
86
|
+
*/
|
|
87
|
+
onLayoutComplete?: (info: AggregateLayoutInfo) => void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface AggregateLayoutInfo {
|
|
91
|
+
/** Wall time of `computeElkLayout`, in ms. */
|
|
92
|
+
layoutMs: number;
|
|
93
|
+
nodes: number;
|
|
94
|
+
edges: number;
|
|
95
|
+
groups: number;
|
|
96
|
+
/** ELK failed and the grid fallback was used. */
|
|
97
|
+
fallback: boolean;
|
|
83
98
|
}
|
|
84
99
|
|
|
85
100
|
const NODE_W = 232;
|
|
@@ -196,7 +211,7 @@ function AggregateHubNodeView(
|
|
|
196
211
|
|
|
197
212
|
function AggregateFrameNodeView(
|
|
198
213
|
props: NodeProps<
|
|
199
|
-
Node<{ frame: AggregateFrameNode; selected: boolean;
|
|
214
|
+
Node<{ frame: AggregateFrameNode; selected: boolean; nested?: boolean }>
|
|
200
215
|
>,
|
|
201
216
|
) {
|
|
202
217
|
const { theme } = useTheme();
|
|
@@ -237,8 +252,7 @@ function AggregateFrameNodeView(
|
|
|
237
252
|
data.selected ? theme.colors.primary : (theme.colors.border ?? '#333')
|
|
238
253
|
}`,
|
|
239
254
|
boxShadow: boundaryStyled ? 'none' : '0 1px 4px rgba(0,0,0,0.25)',
|
|
240
|
-
|
|
241
|
-
transition: 'opacity 120ms ease, border-color 120ms ease',
|
|
255
|
+
transition: 'border-color 120ms ease',
|
|
242
256
|
cursor: 'pointer',
|
|
243
257
|
fontFamily: theme.fonts.body,
|
|
244
258
|
}}
|
|
@@ -293,6 +307,23 @@ function AggregateFrameNodeView(
|
|
|
293
307
|
);
|
|
294
308
|
}
|
|
295
309
|
|
|
310
|
+
const AGGREGATE_CLASS = 'subsystem-aggregate-graph';
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Focus dimming lives in CSS keyed off a `data-dimmed` attribute that the
|
|
314
|
+
* canvas toggles on React Flow's node/edge wrappers directly. Hovering one
|
|
315
|
+
* frame changes the dim state of nearly every other node and edge, so routing
|
|
316
|
+
* it through React props re-rendered the whole canvas (~200 nodes, ~400 SVG
|
|
317
|
+
* edges) on each mouse move; attribute toggles cost a fraction of that and
|
|
318
|
+
* produce no React commit at all.
|
|
319
|
+
*/
|
|
320
|
+
const AGGREGATE_FOCUS_CSS = `
|
|
321
|
+
.${AGGREGATE_CLASS} .react-flow__node { transition: opacity 120ms ease; }
|
|
322
|
+
.${AGGREGATE_CLASS} .react-flow__node[data-dimmed="true"] { opacity: 0.35; }
|
|
323
|
+
.${AGGREGATE_CLASS} .react-flow__edge { opacity: 0.9; }
|
|
324
|
+
.${AGGREGATE_CLASS} .react-flow__edge[data-dimmed="true"] { opacity: 0.12; }
|
|
325
|
+
`;
|
|
326
|
+
|
|
296
327
|
const nodeTypes = {
|
|
297
328
|
'aggregate-frame': AggregateFrameNodeView,
|
|
298
329
|
'aggregate-frame-group': AggregateFrameGroupView,
|
|
@@ -306,6 +337,7 @@ function Inner({
|
|
|
306
337
|
title,
|
|
307
338
|
onSelectFrame,
|
|
308
339
|
onOpenFile,
|
|
340
|
+
onLayoutComplete,
|
|
309
341
|
}: SubsystemAggregateGraphProps) {
|
|
310
342
|
const { theme } = useTheme();
|
|
311
343
|
const { fitView } = useReactFlow();
|
|
@@ -315,8 +347,10 @@ function Inner({
|
|
|
315
347
|
const [ready, setReady] = useState(false);
|
|
316
348
|
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
317
349
|
const [focusedBoundaryId, setFocusedBoundaryId] = useState<string | null>(null);
|
|
318
|
-
const [hoveredId, setHoveredId] = useState<string | null>(null);
|
|
319
350
|
const [legendOpen, setLegendOpen] = useState(true);
|
|
351
|
+
const hostRef = useRef<HTMLDivElement>(null);
|
|
352
|
+
// Hover is deliberately not React state: see AGGREGATE_FOCUS_CSS.
|
|
353
|
+
const hoveredRef = useRef<string | null>(null);
|
|
320
354
|
|
|
321
355
|
const layoutKey = useMemo(
|
|
322
356
|
() =>
|
|
@@ -373,7 +407,7 @@ function Inner({
|
|
|
373
407
|
width: NODE_W,
|
|
374
408
|
height: NODE_H,
|
|
375
409
|
...(f.group ? { parentId: groupIdFor(f.group.kind, f.group.key) } : {}),
|
|
376
|
-
data: { frame: f, selected: false
|
|
410
|
+
data: { frame: f, selected: false },
|
|
377
411
|
})),
|
|
378
412
|
...hubs.map((h) => ({
|
|
379
413
|
id: h.id,
|
|
@@ -414,11 +448,24 @@ function Inner({
|
|
|
414
448
|
},
|
|
415
449
|
data: { edge: e },
|
|
416
450
|
}));
|
|
451
|
+
const layoutStart = performance.now();
|
|
452
|
+
const report = (fallback: boolean) =>
|
|
453
|
+
onLayoutComplete?.({
|
|
454
|
+
layoutMs: performance.now() - layoutStart,
|
|
455
|
+
nodes: rfNodes.length,
|
|
456
|
+
edges: rfEdges.length,
|
|
457
|
+
groups: groups.length,
|
|
458
|
+
fallback,
|
|
459
|
+
});
|
|
417
460
|
void computeElkLayout(rfNodes, rfEdges, {
|
|
418
461
|
direction: 'RIGHT',
|
|
419
462
|
// Reposition (never keep the placeholder grid) and lay out compound
|
|
420
463
|
// process frames.
|
|
421
464
|
preserveNodePositions: false,
|
|
465
|
+
// Frames are fixed-size boxes with no edge labels, so the extra sweeps
|
|
466
|
+
// buy nothing visible; ELK's default is ~3.5x faster at this scale.
|
|
467
|
+
thoroughness: 7,
|
|
468
|
+
edgeLabels: { enabled: false },
|
|
422
469
|
groups,
|
|
423
470
|
// Every process and external boundary is real, including one holding a
|
|
424
471
|
// single frame — a quiet process still has components in it, and
|
|
@@ -465,6 +512,7 @@ function Inner({
|
|
|
465
512
|
setNodes([...shells, ...leaves]);
|
|
466
513
|
setRfEdges(rfEdges);
|
|
467
514
|
setReady(true);
|
|
515
|
+
report(false);
|
|
468
516
|
requestAnimationFrame(() => fitView({ padding: 0.15 }));
|
|
469
517
|
})
|
|
470
518
|
.catch((err) => {
|
|
@@ -473,6 +521,7 @@ function Inner({
|
|
|
473
521
|
setNodes(rfNodes);
|
|
474
522
|
setRfEdges(rfEdges);
|
|
475
523
|
setReady(true);
|
|
524
|
+
report(true);
|
|
476
525
|
requestAnimationFrame(() => fitView({ padding: 0.15 }));
|
|
477
526
|
});
|
|
478
527
|
return () => {
|
|
@@ -481,36 +530,83 @@ function Inner({
|
|
|
481
530
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
482
531
|
}, [layoutKey]);
|
|
483
532
|
|
|
484
|
-
//
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
const boundaryMembers = useMemo(() => {
|
|
490
|
-
const focus = hoveredId ?? selectedId;
|
|
491
|
-
if (!focus) return null;
|
|
492
|
-
if (nodes.find((n) => n.id === focus)?.type !== 'aggregate-frame-group') {
|
|
493
|
-
return null;
|
|
494
|
-
}
|
|
495
|
-
const members = new Set<string>();
|
|
496
|
-
for (const n of nodes) {
|
|
497
|
-
if ((n as { parentId?: string }).parentId === focus) members.add(n.id);
|
|
498
|
-
}
|
|
499
|
-
return members;
|
|
500
|
-
}, [hoveredId, selectedId, nodes]);
|
|
533
|
+
// Edge wrappers only expose their id in the DOM; endpoints come from here.
|
|
534
|
+
const edgeEndsRef = useRef(new Map<string, { source: string; target: string }>());
|
|
535
|
+
useEffect(() => {
|
|
536
|
+
edgeEndsRef.current = new Map(rfEdges.map((e) => [e.id, { source: e.source, target: e.target }]));
|
|
537
|
+
}, [rfEdges]);
|
|
501
538
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
539
|
+
/**
|
|
540
|
+
* Which nodes/edges a focus (hover, else selection) keeps lit.
|
|
541
|
+
*
|
|
542
|
+
* A boundary is a container, not an endpoint: edges reference frame/hub
|
|
543
|
+
* ids, never the group shell's. Hovering one therefore needs its own rule:
|
|
544
|
+
* keep every node lit and dim only the edges not wholly inside it (treating
|
|
545
|
+
* the shell as a plain focus put *nothing* in its neighbour set, so the
|
|
546
|
+
* boundary's own contents were the ones that dimmed). Otherwise dim
|
|
547
|
+
* everything outside the focused node's neighbourhood.
|
|
548
|
+
*/
|
|
549
|
+
const applyFocus = useCallback(
|
|
550
|
+
(focus: string | null) => {
|
|
551
|
+
const host = hostRef.current;
|
|
552
|
+
if (!host) return;
|
|
553
|
+
let nodeDim: ((id: string) => boolean) | null = null;
|
|
554
|
+
let edgeDim: ((source: string, target: string) => boolean) | null = null;
|
|
555
|
+
if (focus) {
|
|
556
|
+
const focusNode = nodes.find((n) => n.id === focus);
|
|
557
|
+
if (focusNode?.type === 'aggregate-frame-group') {
|
|
558
|
+
const members = new Set<string>();
|
|
559
|
+
for (const n of nodes) {
|
|
560
|
+
if ((n as { parentId?: string }).parentId === focus) members.add(n.id);
|
|
561
|
+
}
|
|
562
|
+
edgeDim = (a, b) => !(members.has(a) && members.has(b));
|
|
563
|
+
} else {
|
|
564
|
+
const near = new Set<string>([focus]);
|
|
565
|
+
for (const e of edges) {
|
|
566
|
+
if (e.from === focus) near.add(e.to);
|
|
567
|
+
if (e.to === focus) near.add(e.from);
|
|
568
|
+
}
|
|
569
|
+
nodeDim = (id) => !near.has(id);
|
|
570
|
+
edgeDim = (a, b) => !(near.has(a) && near.has(b));
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
for (const el of Array.from(host.querySelectorAll<HTMLElement>('.react-flow__node'))) {
|
|
574
|
+
const id = el.dataset.id ?? '';
|
|
575
|
+
const dim = nodeDim ? nodeDim(id) : false;
|
|
576
|
+
if (dim) el.dataset.dimmed = 'true';
|
|
577
|
+
else delete el.dataset.dimmed;
|
|
578
|
+
}
|
|
579
|
+
const ends = edgeEndsRef.current;
|
|
580
|
+
for (const el of Array.from(host.querySelectorAll<SVGGElement>('.react-flow__edge'))) {
|
|
581
|
+
const e = ends.get(el.dataset.id ?? '');
|
|
582
|
+
const dim = e && edgeDim ? edgeDim(e.source, e.target) : false;
|
|
583
|
+
if (dim) el.dataset.dimmed = 'true';
|
|
584
|
+
else delete el.dataset.dimmed;
|
|
585
|
+
}
|
|
586
|
+
},
|
|
587
|
+
[nodes, edges],
|
|
588
|
+
);
|
|
589
|
+
|
|
590
|
+
// Re-apply after layout (fresh DOM), after a selection change, and whenever
|
|
591
|
+
// the data the focus sets are derived from changes.
|
|
592
|
+
useEffect(() => {
|
|
593
|
+
applyFocus(hoveredRef.current ?? selectedId);
|
|
594
|
+
}, [applyFocus, selectedId, rfEdges]);
|
|
595
|
+
|
|
596
|
+
const displayNodes = useMemo(
|
|
597
|
+
() =>
|
|
598
|
+
nodes.map((n) => ({
|
|
599
|
+
...n,
|
|
600
|
+
data: {
|
|
601
|
+
...(n.data as object),
|
|
602
|
+
selected: selectedId === n.id,
|
|
603
|
+
// Surviving parentId means ELK built this node's process frame —
|
|
604
|
+
// the node renders nested, so a process box drops its redundant name.
|
|
605
|
+
nested: (n as { parentId?: string }).parentId != null,
|
|
606
|
+
},
|
|
607
|
+
})),
|
|
608
|
+
[nodes, selectedId],
|
|
609
|
+
);
|
|
514
610
|
|
|
515
611
|
const selected = selectedId ? (frames.find((f) => f.id === selectedId) ?? null) : null;
|
|
516
612
|
|
|
@@ -557,59 +653,31 @@ function Inner({
|
|
|
557
653
|
[focusedBoundaryId, fitView, nodes],
|
|
558
654
|
);
|
|
559
655
|
|
|
560
|
-
const displayNodes = useMemo(
|
|
561
|
-
() =>
|
|
562
|
-
nodes.map((n) => ({
|
|
563
|
-
...n,
|
|
564
|
-
data: {
|
|
565
|
-
...(n.data as object),
|
|
566
|
-
selected: selectedId === n.id,
|
|
567
|
-
// Boundary hover dims everything outside the boundary; otherwise
|
|
568
|
-
// dim anything outside the focused node's neighbourhood.
|
|
569
|
-
dimmed: boundaryMembers
|
|
570
|
-
? !boundaryMembers.has(n.id)
|
|
571
|
-
: neighborIds
|
|
572
|
-
? !neighborIds.has(n.id)
|
|
573
|
-
: false,
|
|
574
|
-
// Surviving parentId means ELK built this node's process frame —
|
|
575
|
-
// the node renders nested, so a process box drops its redundant name.
|
|
576
|
-
nested: (n as { parentId?: string }).parentId != null,
|
|
577
|
-
},
|
|
578
|
-
})),
|
|
579
|
-
[nodes, selectedId, neighborIds, boundaryMembers],
|
|
580
|
-
);
|
|
581
|
-
|
|
582
|
-
const displayEdges = useMemo(
|
|
583
|
-
() =>
|
|
584
|
-
rfEdges.map((e) => {
|
|
585
|
-
// Hovering a boundary keeps only the edges wholly inside it lit — a
|
|
586
|
-
// boundary-crossing edge has an endpoint outside, so it dims with the
|
|
587
|
-
// rest. Otherwise fall back to the node-focus rule.
|
|
588
|
-
const dimmed = boundaryMembers
|
|
589
|
-
? !(boundaryMembers.has(e.source) && boundaryMembers.has(e.target))
|
|
590
|
-
: neighborIds != null &&
|
|
591
|
-
!(neighborIds.has(e.source) && neighborIds.has(e.target));
|
|
592
|
-
return {
|
|
593
|
-
...e,
|
|
594
|
-
style: { ...(e.style as object), opacity: dimmed ? 0.12 : 0.9 },
|
|
595
|
-
};
|
|
596
|
-
}),
|
|
597
|
-
[rfEdges, neighborIds, boundaryMembers],
|
|
598
|
-
);
|
|
599
656
|
|
|
600
657
|
return (
|
|
601
|
-
<div
|
|
658
|
+
<div
|
|
659
|
+
ref={hostRef}
|
|
660
|
+
className={AGGREGATE_CLASS}
|
|
661
|
+
style={{ position: 'relative', width: '100%', height: '100%', background: theme.colors.background }}
|
|
662
|
+
>
|
|
602
663
|
<GraphLayerStyle />
|
|
664
|
+
<style>{AGGREGATE_FOCUS_CSS}</style>
|
|
603
665
|
<ReactFlow
|
|
604
666
|
nodes={displayNodes}
|
|
605
|
-
edges={
|
|
667
|
+
edges={rfEdges}
|
|
606
668
|
nodeTypes={nodeTypes}
|
|
607
669
|
className={GRAPH_CANVAS_CLASS}
|
|
608
670
|
{...GRAPH_NAV_PROPS}
|
|
609
671
|
onNodeClick={onNodeClick}
|
|
610
672
|
onNodeDoubleClick={onNodeDoubleClick}
|
|
611
|
-
onNodeMouseEnter={(_e, node) =>
|
|
612
|
-
|
|
673
|
+
onNodeMouseEnter={(_e, node) => {
|
|
674
|
+
hoveredRef.current = node.id;
|
|
675
|
+
applyFocus(node.id);
|
|
676
|
+
}}
|
|
677
|
+
onNodeMouseLeave={() => {
|
|
678
|
+
hoveredRef.current = null;
|
|
679
|
+
applyFocus(selectedId);
|
|
680
|
+
}}
|
|
613
681
|
onPaneClick={() => {
|
|
614
682
|
setSelectedId(null);
|
|
615
683
|
setFocusedBoundaryId(null);
|