@principal-ai/subsystems-react 0.56.15 → 0.56.17
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 +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/pierre/PierreFileView.d.ts.map +1 -1
- package/dist/pierre/PierreFileView.js +7 -5
- package/dist/pierre/PierreFileView.js.map +1 -1
- package/dist/pierre/PierreSnippetView.d.ts.map +1 -1
- package/dist/pierre/PierreSnippetView.js +4 -2
- package/dist/pierre/PierreSnippetView.js.map +1 -1
- package/dist/pierre/PierreTrailCodeView.d.ts.map +1 -1
- package/dist/pierre/PierreTrailCodeView.js +4 -1
- package/dist/pierre/PierreTrailCodeView.js.map +1 -1
- package/dist/pierre/pierreBackground.d.ts +12 -0
- package/dist/pierre/pierreBackground.d.ts.map +1 -1
- package/dist/pierre/pierreBackground.js +12 -0
- package/dist/pierre/pierreBackground.js.map +1 -1
- package/dist/subsystem/C4Graph.d.ts +17 -0
- package/dist/subsystem/C4Graph.d.ts.map +1 -1
- package/dist/subsystem/C4Graph.js +128 -61
- package/dist/subsystem/C4Graph.js.map +1 -1
- package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
- package/dist/subsystem/C4NodeCard.js +7 -2
- package/dist/subsystem/C4NodeCard.js.map +1 -1
- package/dist/subsystem/DecorationPanel.d.ts +32 -3
- package/dist/subsystem/DecorationPanel.d.ts.map +1 -1
- package/dist/subsystem/DecorationPanel.js +162 -89
- package/dist/subsystem/DecorationPanel.js.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.d.ts +2 -0
- package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.js +1 -1
- package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
- package/dist/subsystem/c4.d.ts +2 -0
- package/dist/subsystem/c4.d.ts.map +1 -1
- package/dist/subsystem/c4.js.map +1 -1
- package/dist/subsystem/decoration.d.ts +19 -0
- package/dist/subsystem/decoration.d.ts.map +1 -1
- package/dist/subsystem/decoration.js.map +1 -1
- package/dist/subsystem/decorationC4.d.ts +9 -0
- package/dist/subsystem/decorationC4.d.ts.map +1 -0
- package/dist/subsystem/decorationC4.js +55 -0
- package/dist/subsystem/decorationC4.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +6 -1
- package/src/pierre/PierreFileView.tsx +13 -5
- package/src/pierre/PierreSnippetView.tsx +10 -2
- package/src/pierre/PierreTrailCodeView.tsx +8 -4
- package/src/pierre/pierreBackground.ts +14 -0
- package/src/stories/Components/DecorationPanel.stories.tsx +344 -36
- package/src/stories/Pierre/CodeView.stories.tsx +4 -2
- package/src/subsystem/C4Graph.groups.test.ts +46 -0
- package/src/subsystem/C4Graph.tsx +96 -16
- package/src/subsystem/C4NodeCard.test.ts +35 -1
- package/src/subsystem/C4NodeCard.tsx +7 -2
- package/src/subsystem/DecorationPanel.test.tsx +228 -4
- package/src/subsystem/DecorationPanel.tsx +248 -82
- package/src/subsystem/SubsystemComponentGraph.sidebar.test.tsx +11 -0
- package/src/subsystem/SubsystemComponentGraph.tsx +4 -1
- package/src/subsystem/c4.ts +2 -0
- package/src/subsystem/decoration.ts +25 -0
- package/src/subsystem/decorationC4.test.ts +134 -0
- package/src/subsystem/decorationC4.ts +60 -0
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import '@xyflow/react/dist/style.css';
|
|
2
3
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
4
|
import { ThemeProvider, defaultEditorTheme } from '@principal-ade/industry-theme';
|
|
4
5
|
import {
|
|
6
|
+
DecorationHeader,
|
|
5
7
|
DecorationPanel,
|
|
6
8
|
type DecorationPanelProps,
|
|
9
|
+
type DecorationPanelSelection,
|
|
7
10
|
} from '../../subsystem/DecorationPanel';
|
|
8
11
|
import {
|
|
9
12
|
decorationTrailKey,
|
|
13
|
+
type DecorationDraftC4Element,
|
|
14
|
+
type DecorationTrailRef,
|
|
10
15
|
type SubsystemDecoration,
|
|
11
16
|
} from '../../subsystem/decoration';
|
|
17
|
+
import { applyDecorationC4 } from '../../subsystem/decorationC4';
|
|
18
|
+
import { C4Graph, type C4GraphProps } from '../../subsystem/C4Graph';
|
|
19
|
+
import type { C4Edge, C4Model } from '../../subsystem/c4';
|
|
12
20
|
|
|
13
21
|
/**
|
|
14
|
-
* PROTOTYPE:
|
|
22
|
+
* PROTOTYPE: a reading surface alongside an additive C4 projection.
|
|
15
23
|
*
|
|
16
24
|
* The fixture deliberately spans two models (desktop + sync service) and
|
|
17
25
|
* includes one draft trail + draft structure, to show that a decoration is
|
|
@@ -43,7 +51,7 @@ const decoration: SubsystemDecoration = {
|
|
|
43
51
|
'- The desktop stays the source of truth for the open tab.',
|
|
44
52
|
'- The service is a projection; it never blocks the save.',
|
|
45
53
|
'',
|
|
46
|
-
'>
|
|
54
|
+
'> Dashed boxes and segmented relationship labels are proposals, not verified model claims.',
|
|
47
55
|
].join('\n'),
|
|
48
56
|
trails: [
|
|
49
57
|
{
|
|
@@ -70,12 +78,20 @@ const decoration: SubsystemDecoration = {
|
|
|
70
78
|
},
|
|
71
79
|
{
|
|
72
80
|
from: 'sync-agent',
|
|
73
|
-
to: 'sync-
|
|
81
|
+
to: 'sync-worker',
|
|
74
82
|
mechanism: 'calls',
|
|
75
83
|
file: 'src/sync/syncAgent.ts',
|
|
76
84
|
purl: 'pkg:github/principal-ai/desktop-app#src/sync/syncAgent.ts',
|
|
77
85
|
symbol: 'SyncAgent.push',
|
|
78
86
|
},
|
|
87
|
+
{
|
|
88
|
+
from: 'sync-worker',
|
|
89
|
+
to: 'sync-service',
|
|
90
|
+
mechanism: 'calls',
|
|
91
|
+
file: 'src/sync/uploadWorker.ts',
|
|
92
|
+
purl: 'pkg:github/principal-ai/desktop-app#src/sync/uploadWorker.ts',
|
|
93
|
+
symbol: 'UploadWorker.upload',
|
|
94
|
+
},
|
|
79
95
|
],
|
|
80
96
|
},
|
|
81
97
|
},
|
|
@@ -90,16 +106,81 @@ const decoration: SubsystemDecoration = {
|
|
|
90
106
|
process: 'draw-host',
|
|
91
107
|
},
|
|
92
108
|
{
|
|
93
|
-
alias: 'sync-
|
|
94
|
-
name: '
|
|
95
|
-
construct: '
|
|
96
|
-
purpose: '
|
|
109
|
+
alias: 'sync-worker',
|
|
110
|
+
name: 'UploadWorker',
|
|
111
|
+
construct: 'class',
|
|
112
|
+
purpose: 'retries uploads without blocking local saves',
|
|
113
|
+
process: 'sync-worker',
|
|
97
114
|
},
|
|
98
115
|
],
|
|
99
116
|
edges: [
|
|
100
117
|
{ from: 'tab', to: 'sync-agent', mechanism: 'produces' },
|
|
101
|
-
{ from: 'sync-agent', to: 'sync-
|
|
118
|
+
{ from: 'sync-agent', to: 'sync-worker', mechanism: 'calls' },
|
|
119
|
+
{ from: 'sync-worker', to: 'sync-service', mechanism: 'calls' },
|
|
102
120
|
],
|
|
121
|
+
c4: {
|
|
122
|
+
elements: [
|
|
123
|
+
{
|
|
124
|
+
kind: 'component',
|
|
125
|
+
id: 'component:sync-agent',
|
|
126
|
+
label: 'Sync coordinator',
|
|
127
|
+
container: 'container:desktop',
|
|
128
|
+
technology: 'TypeScript',
|
|
129
|
+
description: 'Queues saved drawings for background upload.',
|
|
130
|
+
members: ['sync-agent'],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
kind: 'container',
|
|
134
|
+
id: 'container:sync-worker',
|
|
135
|
+
label: 'Background sync worker',
|
|
136
|
+
containerKind: 'application',
|
|
137
|
+
technology: 'Bun',
|
|
138
|
+
process: 'sync-worker',
|
|
139
|
+
description: 'Uploads independently of the open desktop tab.',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
kind: 'component',
|
|
143
|
+
id: 'component:upload-worker',
|
|
144
|
+
label: 'Upload queue',
|
|
145
|
+
container: 'container:sync-worker',
|
|
146
|
+
technology: 'TypeScript',
|
|
147
|
+
description: 'Retries pending uploads to the sync service.',
|
|
148
|
+
members: ['sync-worker'],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
edges: [
|
|
152
|
+
{
|
|
153
|
+
id: 'draft:enqueue',
|
|
154
|
+
source: 'component:save',
|
|
155
|
+
target: 'component:sync-agent',
|
|
156
|
+
label: 'Queues saved drawing',
|
|
157
|
+
protocol: 'event',
|
|
158
|
+
mechanisms: ['produces'],
|
|
159
|
+
count: 1,
|
|
160
|
+
trailRefs: [{ trailId: 'sg-desktop:tl-planned-sync', stepIndices: [0] }],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: 'draft:dispatch',
|
|
164
|
+
source: 'component:sync-agent',
|
|
165
|
+
target: 'component:upload-worker',
|
|
166
|
+
label: 'Dispatches upload',
|
|
167
|
+
protocol: 'RPC',
|
|
168
|
+
mechanisms: ['calls'],
|
|
169
|
+
count: 1,
|
|
170
|
+
trailRefs: [{ trailId: 'sg-desktop:tl-planned-sync', stepIndices: [1] }],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: 'draft:upload',
|
|
174
|
+
source: 'component:upload-worker',
|
|
175
|
+
target: 'component:persist',
|
|
176
|
+
label: 'Uploads drawing',
|
|
177
|
+
protocol: 'HTTPS',
|
|
178
|
+
mechanisms: ['calls'],
|
|
179
|
+
count: 1,
|
|
180
|
+
trailRefs: [{ trailId: 'sg-desktop:tl-planned-sync', stepIndices: [2] }],
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
103
184
|
},
|
|
104
185
|
provenance: {
|
|
105
186
|
source: 'author',
|
|
@@ -111,8 +192,8 @@ const decoration: SubsystemDecoration = {
|
|
|
111
192
|
const resolveTrail: NonNullable<DecorationPanelProps['resolveTrail']> = (ref) => {
|
|
112
193
|
if (ref.kind === 'draft') return undefined;
|
|
113
194
|
const key = decorationTrailKey(ref);
|
|
114
|
-
if (key === 'sg-desktop:tl-save') return { title: 'Save drawing', stepCount:
|
|
115
|
-
if (key === 'sg-server:tl-persist') return { title: 'Persist file', stepCount:
|
|
195
|
+
if (key === 'sg-desktop:tl-save') return { title: 'Save drawing', stepCount: 1 };
|
|
196
|
+
if (key === 'sg-server:tl-persist') return { title: 'Persist file', stepCount: 1 };
|
|
116
197
|
return undefined;
|
|
117
198
|
};
|
|
118
199
|
|
|
@@ -121,40 +202,267 @@ const modelLabels = new Map([
|
|
|
121
202
|
['sg-server', 'sync-service'],
|
|
122
203
|
]);
|
|
123
204
|
|
|
205
|
+
const baseC4: C4Model = {
|
|
206
|
+
view: 'container',
|
|
207
|
+
system: { id: 'system:drawings', label: 'Drawing save and sync' },
|
|
208
|
+
nodes: [
|
|
209
|
+
{
|
|
210
|
+
kind: 'container', id: 'container:desktop', label: 'Desktop app',
|
|
211
|
+
containerKind: 'application', technology: 'React', process: 'draw-host',
|
|
212
|
+
description: 'Owns the open drawing and saves locally.', state: 'accepted',
|
|
213
|
+
parentId: 'system:drawings',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
kind: 'component', id: 'component:save', label: 'Drawing save',
|
|
217
|
+
container: 'container:desktop', technology: 'TypeScript',
|
|
218
|
+
members: ['tab'], description: 'Writes the current drawing to disk.', state: 'accepted',
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
kind: 'container', id: 'container:server', label: 'Sync service',
|
|
222
|
+
containerKind: 'application', technology: 'Bun', process: 'sync-service',
|
|
223
|
+
description: 'Persists remote drawing projections.', state: 'accepted',
|
|
224
|
+
parentId: 'system:drawings',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
kind: 'component', id: 'component:persist', label: 'Drawing persistence',
|
|
228
|
+
container: 'container:server', technology: 'TypeScript',
|
|
229
|
+
members: ['sync-service'], description: 'Persists an uploaded drawing.', state: 'accepted',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
kind: 'external-system', id: 'external:disk', label: 'File storage',
|
|
233
|
+
technology: 'File I/O', members: ['disk'],
|
|
234
|
+
description: 'Local and server-side drawing files.', state: 'accepted',
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
edges: [
|
|
238
|
+
{
|
|
239
|
+
id: 'base:save', source: 'component:save', target: 'external:disk',
|
|
240
|
+
label: 'Saves locally', protocol: 'File I/O', mechanisms: ['writes'], count: 1,
|
|
241
|
+
trailRefs: [{ trailId: 'sg-desktop:tl-save', stepIndices: [0] }],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: 'base:persist', source: 'component:persist', target: 'external:disk',
|
|
245
|
+
label: 'Persists projection', protocol: 'File I/O', mechanisms: ['writes'], count: 1,
|
|
246
|
+
trailRefs: [{ trailId: 'sg-server:tl-persist', stepIndices: [0] }],
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const c4ElementLabels = new Map(baseC4.nodes.map((element) => [element.id, element.label]));
|
|
252
|
+
|
|
124
253
|
function Demo() {
|
|
125
254
|
const [active, setActive] = useState(true);
|
|
126
|
-
const [selected, setSelected] = useState<string>(
|
|
255
|
+
const [selected, setSelected] = useState<string | null>(null);
|
|
256
|
+
const [selectedElementId, setSelectedElementId] = useState<string | null>(null);
|
|
257
|
+
const [selectedEdgeId, setSelectedEdgeId] = useState<string | null>(null);
|
|
258
|
+
const [selectedDraftItem, setSelectedDraftItem] = useState<DecorationPanelSelection | null>(null);
|
|
259
|
+
const [focusedIds, setFocusedIds] = useState<ReadonlySet<string> | null>(null);
|
|
260
|
+
const [containerFocus, setContainerFocus] = useState<C4GraphProps['containerFocus']>(null);
|
|
261
|
+
const [openIds, setOpenIds] = useState<string[]>([]);
|
|
262
|
+
const projection = useMemo(() => applyDecorationC4(baseC4, decoration, active), [active]);
|
|
263
|
+
const model = useMemo<C4Model>(() => {
|
|
264
|
+
const opened = new Set(openIds);
|
|
265
|
+
const visibleId = (id: string) => {
|
|
266
|
+
const node = projection.nodes.find((element) => element.id === id);
|
|
267
|
+
return node?.kind === 'component' && !opened.has(node.container) ? node.container : id;
|
|
268
|
+
};
|
|
269
|
+
return {
|
|
270
|
+
...projection,
|
|
271
|
+
openContainerIds: openIds,
|
|
272
|
+
// Fold component relationships onto their container while it is closed.
|
|
273
|
+
edges: projection.edges
|
|
274
|
+
.map((edge) => ({ ...edge, source: visibleId(edge.source), target: visibleId(edge.target) }))
|
|
275
|
+
.filter((edge) => edge.source !== edge.target),
|
|
276
|
+
};
|
|
277
|
+
}, [projection, openIds]);
|
|
278
|
+
|
|
279
|
+
const dimmedElementIds = focusedIds
|
|
280
|
+
? new Set(model.nodes.filter((node) => !focusedIds.has(node.id)).map((node) => node.id))
|
|
281
|
+
: null;
|
|
282
|
+
const dimmedEdgeIds = selectedEdgeId
|
|
283
|
+
? new Set(model.edges.filter((edge) => edge.id !== selectedEdgeId).map((edge) => edge.id))
|
|
284
|
+
: selected
|
|
285
|
+
? new Set(model.edges
|
|
286
|
+
.filter((edge) => !edge.trailRefs?.some((ref) => ref.trailId === selected))
|
|
287
|
+
.map((edge) => edge.id))
|
|
288
|
+
: null;
|
|
289
|
+
|
|
290
|
+
function focusElements(ids: Iterable<string>, source = projection) {
|
|
291
|
+
const focus = new Set(ids);
|
|
292
|
+
const containers = new Set<string>();
|
|
293
|
+
for (const id of focus) {
|
|
294
|
+
const node = source.nodes.find((element) => element.id === id);
|
|
295
|
+
if (node?.kind === 'component') {
|
|
296
|
+
focus.add(node.container);
|
|
297
|
+
containers.add(node.container);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
setFocusedIds(focus);
|
|
301
|
+
setOpenIds((previous) => [...new Set([...previous, ...containers])]);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function selectTrail(ref: DecorationTrailRef) {
|
|
305
|
+
setSelectedEdgeId(null);
|
|
306
|
+
setSelectedElementId(null);
|
|
307
|
+
setContainerFocus(null);
|
|
308
|
+
setSelectedDraftItem(null);
|
|
309
|
+
if (!active && ref.kind === 'draft') setActive(true);
|
|
310
|
+
// Use the active projection when selecting a draft while the overlay is off.
|
|
311
|
+
const all = applyDecorationC4(baseC4, decoration);
|
|
312
|
+
const key = decorationTrailKey(ref);
|
|
313
|
+
const edges = all.edges.filter((edge) => edge.trailRefs?.some((trail) => trail.trailId === key));
|
|
314
|
+
setSelected(key);
|
|
315
|
+
focusElements(edges.flatMap((edge) => [edge.source, edge.target]), all);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function selectC4Element(element: DecorationDraftC4Element) {
|
|
319
|
+
setSelectedEdgeId(null);
|
|
320
|
+
setSelectedElementId(element.id);
|
|
321
|
+
setSelectedDraftItem({ kind: 'c4', id: element.id });
|
|
322
|
+
setActive(true);
|
|
323
|
+
setSelected(null);
|
|
324
|
+
const containerId = element.kind === 'component' ? element.container : element.id;
|
|
325
|
+
focusContainer(containerId, applyDecorationC4(baseC4, decoration));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function focusContainer(id: string, source = projection) {
|
|
329
|
+
const container = source.nodes.find((node) => node.id === id && node.kind === 'container');
|
|
330
|
+
if (!container) {
|
|
331
|
+
setContainerFocus(null);
|
|
332
|
+
focusElements([id], source);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
setContainerFocus({ id });
|
|
336
|
+
setFocusedIds(new Set([
|
|
337
|
+
id,
|
|
338
|
+
...source.nodes
|
|
339
|
+
.filter((node) => node.kind === 'component' && node.container === id)
|
|
340
|
+
.map((node) => node.id),
|
|
341
|
+
]));
|
|
342
|
+
setOpenIds((previous) => [...new Set([...previous, id])]);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function toggleActive(next: boolean) {
|
|
346
|
+
setSelectedEdgeId(null);
|
|
347
|
+
setActive(next);
|
|
348
|
+
setSelected(null);
|
|
349
|
+
setFocusedIds(null);
|
|
350
|
+
setSelectedDraftItem(null);
|
|
351
|
+
setContainerFocus(null);
|
|
352
|
+
setSelectedElementId(null);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function clearFocus() {
|
|
356
|
+
setSelectedEdgeId(null);
|
|
357
|
+
setSelected(null);
|
|
358
|
+
setFocusedIds(null);
|
|
359
|
+
setSelectedDraftItem(null);
|
|
360
|
+
setContainerFocus(null);
|
|
361
|
+
setSelectedElementId(null);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function selectC4Edge(edge: C4Edge) {
|
|
365
|
+
const all = applyDecorationC4(baseC4, decoration);
|
|
366
|
+
const original = all.edges.find((candidate) => candidate.id === edge.id) ?? edge;
|
|
367
|
+
const isDraft = decoration.draft?.c4?.edges?.some((candidate) => candidate.id === edge.id);
|
|
368
|
+
if (isDraft) setActive(true);
|
|
369
|
+
setSelectedEdgeId(edge.id);
|
|
370
|
+
setSelectedElementId(null);
|
|
371
|
+
setSelected(null);
|
|
372
|
+
setContainerFocus({ ids: [original.source, original.target] });
|
|
373
|
+
setSelectedDraftItem(isDraft ? { kind: 'c4-edge', id: edge.id } : null);
|
|
374
|
+
focusElements([original.source, original.target], all);
|
|
375
|
+
}
|
|
127
376
|
|
|
128
377
|
return (
|
|
129
|
-
<div style={{ display: 'flex', height: '100vh', background: '#0f1115' }}>
|
|
130
|
-
<
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
378
|
+
<div style={{ display: 'flex', flexDirection: 'column', height: '100vh', background: '#0f1115' }}>
|
|
379
|
+
<DecorationHeader
|
|
380
|
+
decoration={decoration}
|
|
381
|
+
active={active}
|
|
382
|
+
onToggleActive={toggleActive}
|
|
383
|
+
actions={
|
|
384
|
+
<div style={{ display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: 16, color: '#9aa4b2', fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: 12 }}>
|
|
385
|
+
<span>{active ? 'Base + decoration' : 'Base architecture only'}</span>
|
|
386
|
+
<span>Solid boxes: base · dashed boxes: draft</span>
|
|
387
|
+
{focusedIds && (
|
|
388
|
+
<button type="button" onClick={clearFocus}>
|
|
389
|
+
Clear focus
|
|
390
|
+
</button>
|
|
391
|
+
)}
|
|
392
|
+
</div>
|
|
393
|
+
}
|
|
394
|
+
/>
|
|
395
|
+
<div style={{ display: 'flex', flex: 1, minHeight: 0 }}>
|
|
396
|
+
<div style={{ width: 360, flexShrink: 0, height: '100%', borderRight: '1px solid #2a2f3a' }}>
|
|
397
|
+
<DecorationPanel
|
|
398
|
+
decoration={decoration}
|
|
399
|
+
active={active}
|
|
400
|
+
onToggleActive={toggleActive}
|
|
401
|
+
hideHeader
|
|
402
|
+
resolveTrail={resolveTrail}
|
|
403
|
+
modelLabels={modelLabels}
|
|
404
|
+
c4ElementLabels={c4ElementLabels}
|
|
405
|
+
onSelectTrail={selectTrail}
|
|
406
|
+
onSelectDraftC4Element={selectC4Element}
|
|
407
|
+
onSelectDraftC4Edge={selectC4Edge}
|
|
408
|
+
selectedDraftItem={selectedDraftItem}
|
|
409
|
+
onSelectDraftComponent={(component) => {
|
|
410
|
+
const owner = decoration.draft?.c4?.elements?.find(
|
|
411
|
+
(element) => element.kind === 'component' && element.members?.includes(component.alias),
|
|
412
|
+
);
|
|
413
|
+
if (owner) selectC4Element(owner);
|
|
414
|
+
setSelectedDraftItem({ kind: 'component', alias: component.alias });
|
|
415
|
+
}}
|
|
416
|
+
/>
|
|
417
|
+
</div>
|
|
418
|
+
<div style={{ flex: 1, minWidth: 0, minHeight: 0 }}>
|
|
419
|
+
<C4Graph
|
|
420
|
+
model={model}
|
|
421
|
+
containerFocus={containerFocus}
|
|
422
|
+
selectedNodeId={selectedElementId}
|
|
423
|
+
selectedEdgeId={selectedEdgeId}
|
|
424
|
+
dimmedElementIds={dimmedElementIds}
|
|
425
|
+
dimmedEdgeIds={dimmedEdgeIds}
|
|
426
|
+
onToggleContainer={(id) => setOpenIds((previous) =>
|
|
427
|
+
previous.includes(id) ? previous.filter((value) => value !== id) : [...previous, id])}
|
|
428
|
+
onSelectNode={(id) => {
|
|
429
|
+
setSelectedEdgeId(null);
|
|
430
|
+
setSelectedElementId(id);
|
|
431
|
+
setSelected(null);
|
|
432
|
+
setSelectedDraftItem(
|
|
433
|
+
id && decoration.draft?.c4?.elements?.some((element) => element.id === id)
|
|
434
|
+
? { kind: 'c4', id }
|
|
435
|
+
: null,
|
|
436
|
+
);
|
|
437
|
+
const element = projection.nodes.find((node) => node.id === id);
|
|
438
|
+
if (element) {
|
|
439
|
+
focusContainer(element.kind === 'component' ? element.container : element.id);
|
|
440
|
+
} else {
|
|
441
|
+
setFocusedIds(null);
|
|
442
|
+
setContainerFocus(null);
|
|
443
|
+
}
|
|
444
|
+
}}
|
|
445
|
+
onSelectEdge={(edge) => {
|
|
446
|
+
if (!edge) {
|
|
447
|
+
setSelectedEdgeId(null);
|
|
448
|
+
setSelectedDraftItem((current) => current?.kind === 'c4-edge' ? null : current);
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
selectC4Edge(edge);
|
|
452
|
+
}}
|
|
453
|
+
onTrailClick={(ref) => {
|
|
454
|
+
const trail = decoration.trails.find((candidate) => decorationTrailKey(candidate) === ref.trailId);
|
|
455
|
+
if (trail) selectTrail(trail);
|
|
456
|
+
}}
|
|
457
|
+
hideDrawer
|
|
458
|
+
/>
|
|
459
|
+
</div>
|
|
153
460
|
</div>
|
|
154
461
|
</div>
|
|
155
462
|
);
|
|
156
463
|
}
|
|
157
464
|
|
|
158
465
|
export const TwoModels: Story = {
|
|
466
|
+
args: { decoration, active: true, onToggleActive: () => {} },
|
|
159
467
|
render: () => <Demo />,
|
|
160
468
|
};
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from '@pierre/diffs/react';
|
|
14
14
|
import { ThemeProvider, defaultEditorTheme, useTheme } from '@principal-ade/industry-theme';
|
|
15
15
|
import { sliceSnippetWindow } from '../../pierre/sliceSnippet';
|
|
16
|
+
import { PIERRE_PREFERRED_HIGHLIGHTER } from '../../pierre/pierreBackground';
|
|
16
17
|
import { resolvePierreSyntaxThemeName } from '../../pierre/pierreSyntaxTheme';
|
|
17
18
|
import componentDeclarationSource from '../../subsystem/ComponentDeclaration.tsx?raw';
|
|
18
19
|
import resolveSource from '../../graphify/resolve.ts?raw';
|
|
@@ -78,7 +79,7 @@ type Story = StoryObj;
|
|
|
78
79
|
|
|
79
80
|
function MultiFileSnippetsDemo() {
|
|
80
81
|
const { theme, mode } = useTheme();
|
|
81
|
-
const viewRef = useRef<CodeViewHandle
|
|
82
|
+
const viewRef = useRef<CodeViewHandle<undefined, undefined>>(null);
|
|
82
83
|
const [activeId, setActiveId] = React.useState<string | null>(SNIPPETS[0]?.id ?? null);
|
|
83
84
|
|
|
84
85
|
const sliced = useMemo(() => {
|
|
@@ -94,7 +95,7 @@ function MultiFileSnippetsDemo() {
|
|
|
94
95
|
});
|
|
95
96
|
}, []);
|
|
96
97
|
|
|
97
|
-
const items = useMemo((): CodeViewItem[] => {
|
|
98
|
+
const items = useMemo((): CodeViewItem<undefined>[] => {
|
|
98
99
|
return sliced.map(({ spec, slice }) => ({
|
|
99
100
|
id: spec.id,
|
|
100
101
|
type: 'file' as const,
|
|
@@ -131,6 +132,7 @@ function MultiFileSnippetsDemo() {
|
|
|
131
132
|
light: resolvePierreSyntaxThemeName('light'),
|
|
132
133
|
} as const,
|
|
133
134
|
stickyHeaders: true,
|
|
135
|
+
preferredHighlighter: PIERRE_PREFERRED_HIGHLIGHTER,
|
|
134
136
|
layout: { paddingTop: 12, paddingBottom: 24, gap: 16 },
|
|
135
137
|
...(mode === 'light' || mode === 'dark' ? { themeType: mode as 'light' | 'dark' } : {}),
|
|
136
138
|
}),
|
|
@@ -15,6 +15,7 @@ import { describe, expect, test } from 'bun:test';
|
|
|
15
15
|
import {
|
|
16
16
|
absoluteRectOf,
|
|
17
17
|
c4GroupDefs,
|
|
18
|
+
c4CameraNodeIds,
|
|
18
19
|
hidesComponentDuringMorph,
|
|
19
20
|
rebaseGroupBoundsAbsolute,
|
|
20
21
|
showDescriptionFor,
|
|
@@ -62,6 +63,51 @@ const base = model([
|
|
|
62
63
|
const groupById = (defs: ReturnType<typeof c4GroupDefs>['groups']) =>
|
|
63
64
|
new Map(defs.map((g) => [g.id, g]));
|
|
64
65
|
|
|
66
|
+
describe('C4 camera targets', () => {
|
|
67
|
+
const withOutside = model([
|
|
68
|
+
...base.nodes,
|
|
69
|
+
{ id: 'external:github', kind: 'external-system', label: 'GitHub' },
|
|
70
|
+
{ id: 'person:dev', kind: 'person', label: 'Dev' },
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
test('focuses a container without fitting siblings or outside systems', () => {
|
|
74
|
+
expect(c4CameraNodeIds(withOutside, HOST)).toEqual([HOST]);
|
|
75
|
+
expect(c4CameraNodeIds({ ...withOutside, openContainerIds: [HOST] }, HOST)).toEqual([HOST]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('restores the system and outside elements for the overview', () => {
|
|
79
|
+
expect(c4CameraNodeIds(withOutside, null)).toEqual([SYSTEM, 'external:github', 'person:dev']);
|
|
80
|
+
expect(c4CameraNodeIds(withOutside)).toEqual([SYSTEM, 'external:github', 'person:dev']);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('falls back to the overview for missing targets', () => {
|
|
84
|
+
const overview = [SYSTEM, 'external:github', 'person:dev'];
|
|
85
|
+
expect(c4CameraNodeIds(withOutside, 'missing')).toEqual(overview);
|
|
86
|
+
expect(c4CameraNodeIds(withOutside, ['missing', 'also-missing'])).toEqual(overview);
|
|
87
|
+
expect(c4CameraNodeIds(withOutside, [])).toEqual(overview);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('frames both endpoint containers and excludes unrelated elements', () => {
|
|
91
|
+
expect(c4CameraNodeIds(withOutside, ['cmp:a', NOTES])).toEqual([HOST, NOTES]);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('deduplicates endpoints in the same container', () => {
|
|
95
|
+
expect(c4CameraNodeIds(withOutside, ['cmp:a', 'cmp:b'])).toEqual([HOST]);
|
|
96
|
+
expect(c4CameraNodeIds(withOutside, ['cmp:a', HOST])).toEqual([HOST]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('keeps external endpoints in the relationship frame', () => {
|
|
100
|
+
expect(c4CameraNodeIds(withOutside, ['cmp:a', 'external:github']))
|
|
101
|
+
.toEqual([HOST, 'external:github']);
|
|
102
|
+
expect(c4CameraNodeIds(withOutside, ['person:dev', NOTES]))
|
|
103
|
+
.toEqual(['person:dev', NOTES]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('ignores missing endpoints when a valid target remains', () => {
|
|
107
|
+
expect(c4CameraNodeIds(withOutside, ['cmp:a', 'missing'])).toEqual([HOST]);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
65
111
|
describe('c4GroupDefs — the system boundary', () => {
|
|
66
112
|
test('is a group of its own, even with nothing open', () => {
|
|
67
113
|
const { groups } = c4GroupDefs(base, []);
|