@principal-ai/subsystems-react 0.17.0 → 0.18.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 (98) hide show
  1. package/dist/index.d.ts +7 -44
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +6 -32
  4. package/dist/index.js.map +1 -1
  5. package/package.json +2 -2
  6. package/src/index.ts +9 -199
  7. package/src/components/ConfigurationSelector.tsx +0 -133
  8. package/src/components/GraphRenderer.tsx +0 -3195
  9. package/src/components/MultiCanvasRenderer.tsx +0 -295
  10. package/src/components/NodeTooltip.tsx +0 -279
  11. package/src/components/PendingChanges.test.tsx +0 -375
  12. package/src/components/SelectionSidebar.tsx +0 -352
  13. package/src/components/SequenceDiagramRenderer.tsx +0 -1156
  14. package/src/components/WorkflowSequenceDiagram.tsx +0 -270
  15. package/src/components/dashboard/DashboardRenderer.tsx +0 -317
  16. package/src/components/dashboard/MetricPanel.tsx +0 -254
  17. package/src/components/dashboard/MockDataProvider.ts +0 -330
  18. package/src/components/dashboard/components/BarChart.tsx +0 -299
  19. package/src/components/dashboard/components/LineChart.tsx +0 -279
  20. package/src/components/dashboard/components/MetricCard.tsx +0 -270
  21. package/src/components/dashboard/components/SourceLink.tsx +0 -63
  22. package/src/components/dashboard/components/TimeRangeSelector.tsx +0 -280
  23. package/src/components/dashboard/components/index.ts +0 -5
  24. package/src/components/dashboard/index.ts +0 -47
  25. package/src/components/dashboard/types.ts +0 -126
  26. package/src/components/state-view/PipelineView.tsx +0 -347
  27. package/src/components/state-view/index.ts +0 -14
  28. package/src/components/state-view/types.ts +0 -261
  29. package/src/components/state-view/useStateView.ts +0 -205
  30. package/src/contexts/GraphEditContext.tsx +0 -27
  31. package/src/contexts/TooltipPortalContext.ts +0 -8
  32. package/src/edges/CustomEdge.tsx +0 -402
  33. package/src/edges/GenericEdge.tsx +0 -36
  34. package/src/hooks/usePathBasedEvents.ts +0 -192
  35. package/src/hooks/useSequenceLayout.ts +0 -543
  36. package/src/hooks/useUndoRedo.ts +0 -144
  37. package/src/nodes/CustomNode.tsx +0 -1231
  38. package/src/nodes/GenericNode.tsx +0 -55
  39. package/src/nodes/otel/OtelBoundaryNode.tsx +0 -224
  40. package/src/nodes/otel/OtelEventNode.tsx +0 -225
  41. package/src/nodes/otel/OtelResourceNode.tsx +0 -251
  42. package/src/nodes/otel/OtelScopeNode.tsx +0 -221
  43. package/src/nodes/otel/OtelSpanConventionNode.tsx +0 -295
  44. package/src/nodes/otel/index.ts +0 -23
  45. package/src/nodes/otel/shared/NodeBadges.tsx +0 -295
  46. package/src/nodes/otel/shared/NodeContent.tsx +0 -204
  47. package/src/nodes/otel/shared/index.ts +0 -8
  48. package/src/nodes/otel/shared/types.ts +0 -138
  49. package/src/nodes/otel/shared/useNodeBehavior.ts +0 -114
  50. package/src/stories/Audit/BoundaryNodes.stories.tsx +0 -385
  51. package/src/stories/Audit/CanvasEdgeTypes.stories.tsx +0 -1448
  52. package/src/stories/Audit/CanvasNodeTypes.stories.tsx +0 -1049
  53. package/src/stories/Audit/ColorPriority.stories.tsx +0 -895
  54. package/src/stories/Audit/DiamondBadges.stories.tsx +0 -629
  55. package/src/stories/Audit/NodeDimensionsTesting.stories.tsx +0 -724
  56. package/src/stories/Audit/NodeFieldsAudit.stories.tsx +0 -996
  57. package/src/stories/Audit/NodeFontSizeTesting.stories.tsx +0 -715
  58. package/src/stories/Audit/NodeShapes.stories.tsx +0 -1208
  59. package/src/stories/Audit/WideNodesTesting.stories.tsx +0 -1045
  60. package/src/stories/Components/DashboardRenderer.stories.tsx +0 -263
  61. package/src/stories/Components/GraphRenderer.stories.tsx +0 -3236
  62. package/src/stories/Components/MultiCanvasRenderer.stories.tsx +0 -370
  63. package/src/stories/Components/SequenceDiagram.stories.tsx +0 -255
  64. package/src/stories/Components/StateView.stories.tsx +0 -417
  65. package/src/stories/Components/TraceViewer.stories.tsx +0 -442
  66. package/src/stories/Components/WorkflowSequenceDiagram.stories.tsx +0 -802
  67. package/src/stories/Features/AnimationWorkshop.stories.tsx +0 -727
  68. package/src/stories/Features/ChangeTypeVisual.stories.tsx +0 -67
  69. package/src/stories/Features/EventDrivenAnimations.stories.tsx +0 -513
  70. package/src/stories/Features/MultiConfig.stories.tsx +0 -539
  71. package/src/stories/Layout/ElkEdgeRouting.stories.tsx +0 -539
  72. package/src/stories/Layout/GraphOrientation.stories.tsx +0 -500
  73. package/src/stories/Layout/MultiDirectionalConnections.stories.tsx +0 -352
  74. package/src/stories/Nodes/NodeDefinitionComparison.stories.tsx +0 -560
  75. package/src/stories/Nodes/NodeNameFallbacks.stories.tsx +0 -491
  76. package/src/stories/Nodes/NumericColors.stories.tsx +0 -440
  77. package/src/stories/OTEL/EventNameDisplay.stories.tsx +0 -694
  78. package/src/stories/OTEL/EventNameFallback.stories.tsx +0 -578
  79. package/src/stories/OTEL/OtelComponents.stories.tsx +0 -422
  80. package/src/stories/OTEL/OtelNodeTypesPrototype.stories.tsx +0 -806
  81. package/src/stories/OTEL/RawEventCards.stories.tsx +0 -57
  82. package/src/stories/OTEL/SpanBadges.stories.tsx +0 -840
  83. package/src/stories/OTEL/ValidationEventsCanvas.stories.tsx +0 -209
  84. package/src/stories/RealWorld/BacklogMdCanvases.stories.tsx +0 -721
  85. package/src/stories/RealWorld/FileCitySequence.stories.tsx +0 -516
  86. package/src/stories/RealWorld/RealCanvasFiles.stories.tsx +0 -336
  87. package/src/stories/__traces__/test-run.canvas.json +0 -241
  88. package/src/stories/data/activity-feed-analytics.dashboard.json +0 -300
  89. package/src/stories/data/file-city-images-transformed.otel.canvas.json +0 -295
  90. package/src/stories/data/file-city-workflows.json +0 -269
  91. package/src/stories/data/graph-converter-test-execution.json +0 -443
  92. package/src/stories/data/graph-converter-test.workflow.json +0 -105
  93. package/src/stories/data/graph-converter-validated-execution.json +0 -58
  94. package/src/utils/animationMapping.ts +0 -166
  95. package/src/utils/canvasBounds.ts +0 -146
  96. package/src/utils/graphConverter.ts +0 -148
  97. package/src/utils/iconResolver.tsx +0 -53
  98. package/src/utils/orientationUtils.ts +0 -73
@@ -1,543 +0,0 @@
1
- /**
2
- * React hook for sequence diagram layout
3
- *
4
- * Computes swimlane-based positioning for events. Lanes default to the first
5
- * dotted segment of each event name. Callers can drill deeper by passing
6
- * `openedNamespaces`: any prefix listed there has its events pushed one level
7
- * deeper, so its children appear as their own lanes instead of being grouped
8
- * under the parent.
9
- */
10
-
11
- import { useMemo } from 'react';
12
- import type { Node, Edge } from '@xyflow/react';
13
-
14
- /**
15
- * Input event for sequence layout
16
- */
17
- export interface SequenceEvent {
18
- /** Unique event identifier */
19
- id: string;
20
- /** Event name with namespace (e.g., "auth.validation.started") */
21
- name: string;
22
- /** Optional display label (defaults to name) */
23
- label?: string;
24
- /** Optional event type for styling */
25
- type?: string;
26
- /** Whether this is a move event (crosses participant boundaries) */
27
- moveEvent?: boolean;
28
- /** Participant this event belongs to (for move events, this is the target) */
29
- participant?: string;
30
- /**
31
- * Optional source-file path this event originated from, expressed
32
- * relative to the repository root (e.g.
33
- * `auth-server/src/lib/auth-provider.ts`). Surfaced on the React Flow
34
- * node `data` so downstream renderers (file-city overlays, jump-to-source,
35
- * IDE bridges) can react to selection without reaching into `data`.
36
- */
37
- sourcePath?: string;
38
- /** Additional data to pass through to the node */
39
- data?: Record<string, unknown>;
40
- }
41
-
42
- /**
43
- * Input edge for sequence layout
44
- */
45
- export interface SequenceEdge {
46
- /** Unique edge identifier */
47
- id: string;
48
- /** Source event ID */
49
- fromEvent: string;
50
- /** Target event ID */
51
- toEvent: string;
52
- /** Optional edge label */
53
- label?: string;
54
- /** Optional edge type for styling */
55
- type?: string;
56
- }
57
-
58
- /**
59
- * Swimlane information computed from events
60
- */
61
- export interface Swimlane {
62
- /** Namespace identifier for this lane */
63
- namespace: string;
64
- /** Display label for the lane header (last segment of the namespace) */
65
- label: string;
66
- /** X position of the lane center */
67
- x: number;
68
- /** Parent namespace (one segment shallower), if any */
69
- parentNamespace?: string;
70
- /** Whether this lane's namespace is in `openedNamespaces` (its events have been drilled deeper) */
71
- isOpened: boolean;
72
- /** Whether the immediate parent namespace is opened (this lane only exists because its parent was drilled into) */
73
- isParentOpened: boolean;
74
- /** Whether any event extends strictly past this lane's namespace (so opening would split it further) */
75
- canExpand: boolean;
76
- /** Events directly assigned to this lane */
77
- eventIds: string[];
78
- }
79
-
80
- /**
81
- * Options for sequence layout
82
- */
83
- export interface UseSequenceLayoutOptions {
84
- /**
85
- * Namespace prefixes whose events should be drilled one segment deeper.
86
- * Pass an array or a Set. Each entry is a dotted prefix (e.g. `auth` or
87
- * `auth.user`). When listed, events under that prefix land in lanes one
88
- * level deeper than the prefix, instead of all sharing the prefix lane.
89
- * Drilling is recursive: list both `auth` and `auth.user` to drill twice.
90
- */
91
- openedNamespaces?: string[] | Set<string>;
92
-
93
- /**
94
- * Explicit left-to-right order for lanes, by resolved namespace. Listed
95
- * namespaces are placed first in the given order; any lanes not present in
96
- * the list fall back to first-event order (the order in which their first
97
- * event appears in `events`). Unknown entries are ignored.
98
- */
99
- laneOrder?: string[];
100
-
101
- /**
102
- * Width of each swimlane
103
- * @default 250
104
- */
105
- laneWidth?: number;
106
-
107
- /**
108
- * Gap between swimlanes
109
- * @default 10
110
- */
111
- laneGap?: number;
112
-
113
- /**
114
- * Vertical spacing between events
115
- * @default 80
116
- */
117
- eventSpacing?: number;
118
-
119
- /**
120
- * Height reserved for lane headers
121
- * @default 60
122
- */
123
- headerHeight?: number;
124
-
125
- /**
126
- * Node marker width
127
- * @default 14
128
- */
129
- nodeWidth?: number;
130
-
131
- /**
132
- * Node marker height
133
- * @default 14
134
- */
135
- nodeHeight?: number;
136
- }
137
-
138
- /**
139
- * A header cell for an opened ancestor namespace, sitting above the leaf
140
- * lanes it groups. Rendered as a row in the header strip.
141
- */
142
- export interface ParentHeader {
143
- /** Full ancestor namespace (always in `openedNamespaces`) */
144
- namespace: string;
145
- /** Last segment, for display */
146
- label: string;
147
- /** Center x of the cell */
148
- x: number;
149
- /** Total span width across the leaf lanes underneath */
150
- width: number;
151
- /** 1-based depth in the header strip (1 = topmost row) */
152
- depth: number;
153
- }
154
-
155
- /**
156
- * Result from sequence layout computation
157
- */
158
- export interface UseSequenceLayoutResult {
159
- /** Positioned nodes for React Flow */
160
- nodes: Node[];
161
- /** Edges for React Flow */
162
- edges: Edge[];
163
- /** Leaf swimlanes — each gets a lifeline and a leaf header row */
164
- swimlanes: Swimlane[];
165
- /**
166
- * Header cells for opened ancestor namespaces. Stack above the leaf
167
- * headers; depth 1 sits at the top of the header strip.
168
- */
169
- parentHeaders: ParentHeader[];
170
- /** Number of header rows (= max leaf depth). At least 1. */
171
- headerRows: number;
172
- /** Total width of the diagram */
173
- totalWidth: number;
174
- /** Total height of the diagram */
175
- totalHeight: number;
176
- }
177
-
178
- /**
179
- * Resolve the lane (namespace prefix) for a given event name, given the set
180
- * of opened namespaces. Walks segments from depth 1 outward, descending while
181
- * the current prefix is opened, and stopping at the first prefix that isn't.
182
- */
183
- function resolveLane(name: string, opened: Set<string>): string {
184
- const segs = name.split('.');
185
- let depth = 1;
186
- while (depth < segs.length) {
187
- const prefix = segs.slice(0, depth).join('.');
188
- if (opened.has(prefix)) {
189
- depth++;
190
- } else {
191
- break;
192
- }
193
- }
194
- return segs.slice(0, depth).join('.');
195
- }
196
-
197
- /**
198
- * useSequenceLayout
199
- *
200
- * @param events - Events to lay out
201
- * @param sequenceEdges - Edges connecting events
202
- * @param options - Layout options (lane sizing, openedNamespaces)
203
- *
204
- * @example
205
- * ```tsx
206
- * const { nodes, edges, swimlanes } = useSequenceLayout(
207
- * [
208
- * { id: '1', name: 'auth.validation.started' },
209
- * { id: '2', name: 'auth.validation.completed' },
210
- * { id: '3', name: 'database.query.executed' },
211
- * ],
212
- * [
213
- * { id: 'e1', fromEvent: '1', toEvent: '2' },
214
- * { id: 'e2', fromEvent: '2', toEvent: '3' },
215
- * ],
216
- * { openedNamespaces: ['auth'] }, // drill `auth` to show validation/token as separate lanes
217
- * );
218
- * ```
219
- */
220
- export function useSequenceLayout(
221
- events: SequenceEvent[],
222
- sequenceEdges: SequenceEdge[],
223
- options: UseSequenceLayoutOptions = {}
224
- ): UseSequenceLayoutResult {
225
- const {
226
- openedNamespaces,
227
- laneOrder,
228
- laneWidth = 250,
229
- laneGap = 0,
230
- eventSpacing = 80,
231
- headerHeight = 60,
232
- nodeWidth = 14,
233
- nodeHeight = 14,
234
- } = options;
235
-
236
- const laneOrderKey = useMemo(
237
- () => (laneOrder ? laneOrder.join('|') : ''),
238
- [laneOrder]
239
- );
240
-
241
- // Normalize openedNamespaces into a stable string for memo dependency
242
- const openedKey = useMemo(() => {
243
- if (!openedNamespaces) return '';
244
- const arr = Array.from(openedNamespaces);
245
- arr.sort();
246
- return arr.join('|');
247
- }, [openedNamespaces]);
248
-
249
- return useMemo(() => {
250
- if (events.length === 0) {
251
- return {
252
- nodes: [],
253
- edges: [],
254
- swimlanes: [],
255
- parentHeaders: [],
256
- headerRows: 1,
257
- totalWidth: 0,
258
- totalHeight: 0,
259
- };
260
- }
261
-
262
- const opened = new Set<string>(
263
- openedKey ? openedKey.split('|') : []
264
- );
265
-
266
- // Step 1: Resolve each event to a lane prefix
267
- const eventLane = new Map<string, string>();
268
- const laneEvents = new Map<string, string[]>();
269
-
270
- for (const event of events) {
271
- const lane = resolveLane(event.name, opened);
272
- eventLane.set(event.id, lane);
273
- if (!laneEvents.has(lane)) {
274
- laneEvents.set(lane, []);
275
- }
276
- laneEvents.get(lane)!.push(event.id);
277
- }
278
-
279
- // Step 2: Order lanes by first-event appearance (Map preserves insertion
280
- // order from Step 1). If `laneOrder` is provided, listed namespaces are
281
- // placed first in the given order; unlisted lanes follow in first-event
282
- // order. Unknown entries in `laneOrder` are ignored.
283
- const firstEventOrder = Array.from(laneEvents.keys());
284
- let laneNames: string[];
285
- if (laneOrder && laneOrder.length > 0) {
286
- const seen = new Set<string>();
287
- const ordered: string[] = [];
288
- for (const ns of laneOrder) {
289
- if (laneEvents.has(ns) && !seen.has(ns)) {
290
- ordered.push(ns);
291
- seen.add(ns);
292
- }
293
- }
294
- for (const ns of firstEventOrder) {
295
- if (!seen.has(ns)) ordered.push(ns);
296
- }
297
- laneNames = ordered;
298
- } else {
299
- laneNames = firstEventOrder;
300
- }
301
-
302
- // canExpand is meaningful only when opening would actually fork the lane
303
- // into multiple child lanes. If every event in the lane would drill into
304
- // the same child, drilling is a relabel — hide the chevron.
305
- const eventsById = new Map<string, SequenceEvent>();
306
- for (const event of events) eventsById.set(event.id, event);
307
-
308
- const canExpandLane = (laneNs: string, eventIds: string[]): boolean => {
309
- const augmented = new Set(opened);
310
- augmented.add(laneNs);
311
- const seen = new Set<string>();
312
- for (const eid of eventIds) {
313
- const event = eventsById.get(eid);
314
- if (!event) continue;
315
- seen.add(resolveLane(event.name, augmented));
316
- if (seen.size > 1) return true;
317
- }
318
- return false;
319
- };
320
-
321
- // Step 3: Build Swimlane records
322
- const swimlanes: Swimlane[] = laneNames.map((namespace, index) => {
323
- const x = index * (laneWidth + laneGap) + laneWidth / 2;
324
- const segs = namespace.split('.');
325
- const parentNamespace =
326
- segs.length > 1 ? segs.slice(0, -1).join('.') : undefined;
327
- const eventIds = laneEvents.get(namespace)!;
328
-
329
- return {
330
- namespace,
331
- label: segs[segs.length - 1] || namespace,
332
- x,
333
- parentNamespace,
334
- isOpened: opened.has(namespace),
335
- isParentOpened: parentNamespace ? opened.has(parentNamespace) : false,
336
- canExpand: canExpandLane(namespace, eventIds),
337
- eventIds,
338
- };
339
- });
340
-
341
- const laneByNamespace = new Map<string, Swimlane>();
342
- for (const lane of swimlanes) {
343
- laneByNamespace.set(lane.namespace, lane);
344
- }
345
-
346
- // Step 3b: Build parent header cells for opened ancestors. For every leaf
347
- // lane at depth > 1, walk depths 1..d-1 and aggregate the leaf x-extent
348
- // under each ancestor.
349
- const ancestorBounds = new Map<
350
- string,
351
- { xMin: number; xMax: number; depth: number }
352
- >();
353
- for (const lane of swimlanes) {
354
- const segs = lane.namespace.split('.');
355
- const left = lane.x - laneWidth / 2;
356
- const right = lane.x + laneWidth / 2;
357
- for (let d = 1; d < segs.length; d++) {
358
- const ancestorNs = segs.slice(0, d).join('.');
359
- const existing = ancestorBounds.get(ancestorNs);
360
- if (existing) {
361
- existing.xMin = Math.min(existing.xMin, left);
362
- existing.xMax = Math.max(existing.xMax, right);
363
- } else {
364
- ancestorBounds.set(ancestorNs, { xMin: left, xMax: right, depth: d });
365
- }
366
- }
367
- }
368
-
369
- const parentHeaders: ParentHeader[] = Array.from(ancestorBounds.entries())
370
- .map(([namespace, { xMin, xMax, depth }]) => {
371
- const segs = namespace.split('.');
372
- return {
373
- namespace,
374
- label: segs[segs.length - 1] || namespace,
375
- x: (xMin + xMax) / 2,
376
- width: xMax - xMin,
377
- depth,
378
- };
379
- })
380
- .sort((a, b) => a.depth - b.depth || a.x - b.x);
381
-
382
- const headerRows = swimlanes.reduce(
383
- (max, lane) => Math.max(max, lane.namespace.split('.').length),
384
- 1
385
- );
386
- const totalHeaderHeight = headerHeight * headerRows;
387
-
388
- // Step 4: Position events on global time layers, below the full header strip
389
- const nodes: Node[] = [];
390
- for (let i = 0; i < events.length; i++) {
391
- const event = events[i];
392
- const laneNs = eventLane.get(event.id)!;
393
- const lane = laneByNamespace.get(laneNs)!;
394
-
395
- const y = totalHeaderHeight + 40 + i * eventSpacing;
396
-
397
- nodes.push({
398
- id: event.id,
399
- type: 'sequenceMarker',
400
- position: {
401
- x: lane.x - nodeWidth / 2,
402
- y: y - nodeHeight / 2,
403
- },
404
- data: {
405
- label: event.label || event.name.split('.').pop() || event.name,
406
- fullName: event.name,
407
- namespace: laneNs,
408
- timeLayer: i,
409
- isMoveEvent: event.moveEvent === true,
410
- sourcePath: event.sourcePath,
411
- ...event.data,
412
- },
413
- style: {
414
- width: nodeWidth,
415
- height: nodeHeight,
416
- },
417
- });
418
- }
419
-
420
- // Step 5: Edges — one per event, looking ahead to the next
421
- const edges: Edge[] = [];
422
- for (let i = 0; i < events.length; i++) {
423
- const currentEvent = events[i];
424
- const currentLaneNs = eventLane.get(currentEvent.id)!;
425
- const currentLane = laneByNamespace.get(currentLaneNs)!;
426
-
427
- if (i < events.length - 1) {
428
- const nextEvent = events[i + 1];
429
- const nextLaneNs = eventLane.get(nextEvent.id)!;
430
- const nextLane = laneByNamespace.get(nextLaneNs)!;
431
- const nextIsMoveEvent = nextEvent.moveEvent === true;
432
- const crossesLanes = currentLaneNs !== nextLaneNs;
433
-
434
- const edgeLabel =
435
- currentEvent.label ||
436
- currentEvent.name.split('.').pop() ||
437
- currentEvent.name;
438
-
439
- edges.push({
440
- id: `edge-${currentEvent.id}-to-${nextEvent.id}`,
441
- source: currentEvent.id,
442
- target: nextEvent.id,
443
- type: 'sequenceArrowParticipant',
444
- label: edgeLabel,
445
- labelStyle: { fontSize: 12, fontWeight: 500 },
446
- labelBgStyle: { fill: 'white', fillOpacity: 0.8 },
447
- data: {
448
- crossesLanes,
449
- sourceNamespace: currentLaneNs,
450
- targetNamespace: nextLaneNs,
451
- isMoveEvent: nextIsMoveEvent,
452
- sourceEvent: currentEvent,
453
- targetEvent: nextEvent,
454
- sourceParticipantX: currentLane.x,
455
- targetParticipantX: nextLane.x,
456
- },
457
- });
458
- } else {
459
- const currentIsMoveEvent = currentEvent.moveEvent === true;
460
- const edgeLabel =
461
- currentEvent.label ||
462
- currentEvent.name.split('.').pop() ||
463
- currentEvent.name;
464
-
465
- edges.push({
466
- id: `edge-${currentEvent.id}-end`,
467
- source: currentEvent.id,
468
- target: currentEvent.id,
469
- type: 'sequenceArrowParticipant',
470
- label: edgeLabel,
471
- labelStyle: { fontSize: 12, fontWeight: 500 },
472
- labelBgStyle: { fill: 'white', fillOpacity: 0.8 },
473
- data: {
474
- crossesLanes: false,
475
- sourceNamespace: currentLaneNs,
476
- targetNamespace: currentLaneNs,
477
- isMoveEvent: currentIsMoveEvent,
478
- sourceEvent: currentEvent,
479
- targetEvent: currentEvent,
480
- sourceParticipantX: currentLane.x,
481
- targetParticipantX: currentLane.x,
482
- isLastEvent: true,
483
- eventSpacing,
484
- },
485
- });
486
- }
487
- }
488
-
489
- // Step 6: Compute total dimensions
490
- const totalWidth =
491
- swimlanes.length * laneWidth + (swimlanes.length - 1) * laneGap;
492
- const totalHeight = totalHeaderHeight + 40 + events.length * eventSpacing;
493
-
494
- // Step 7: Boundary nodes so React Flow's fitView covers full width
495
- if (swimlanes.length > 0) {
496
- const leftmostLane = swimlanes[0];
497
- const rightmostLane = swimlanes[swimlanes.length - 1];
498
-
499
- nodes.push(
500
- {
501
- id: '__boundary_left__',
502
- type: 'default',
503
- position: { x: leftmostLane.x - laneWidth / 2, y: 0 },
504
- data: {},
505
- style: { width: 1, height: 1, opacity: 0 },
506
- draggable: false,
507
- selectable: false,
508
- },
509
- {
510
- id: '__boundary_right__',
511
- type: 'default',
512
- position: { x: rightmostLane.x + laneWidth / 2, y: totalHeight },
513
- data: {},
514
- style: { width: 1, height: 1, opacity: 0 },
515
- draggable: false,
516
- selectable: false,
517
- }
518
- );
519
- }
520
-
521
- return {
522
- nodes,
523
- edges,
524
- swimlanes,
525
- parentHeaders,
526
- headerRows,
527
- totalWidth,
528
- totalHeight,
529
- };
530
- }, [
531
- events,
532
- sequenceEdges,
533
- openedKey,
534
- laneOrderKey,
535
- laneOrder,
536
- laneWidth,
537
- laneGap,
538
- eventSpacing,
539
- headerHeight,
540
- nodeWidth,
541
- nodeHeight,
542
- ]);
543
- }
@@ -1,144 +0,0 @@
1
- /**
2
- * Hook for managing undo/redo history in the graph editor
3
- *
4
- * Tracks position changes, dimension changes, edge operations, and node deletions
5
- * Supports batch operations (e.g., moving multiple selected nodes = single undo)
6
- */
7
-
8
- import { useRef, useState, useCallback } from 'react';
9
- import type { NodeState, EdgeState } from '@principal-ai/subsystems-core';
10
-
11
- const MAX_HISTORY_SIZE = 50;
12
-
13
- /**
14
- * Individual history entry types
15
- */
16
- export type HistoryEntry =
17
- | {
18
- type: 'position';
19
- nodeId: string;
20
- before: { x: number; y: number };
21
- after: { x: number; y: number };
22
- }
23
- | {
24
- type: 'dimension';
25
- nodeId: string;
26
- before: { width: number; height: number };
27
- after: { width: number; height: number };
28
- }
29
- | {
30
- type: 'text';
31
- nodeId: string;
32
- before: string;
33
- after: string;
34
- }
35
- | {
36
- type: 'nodeDelete';
37
- nodeId: string;
38
- nodeData: NodeState;
39
- }
40
- | {
41
- type: 'edgeCreate';
42
- edge: EdgeState & { sourceHandle?: string; targetHandle?: string };
43
- }
44
- | {
45
- type: 'edgeDelete';
46
- edge: EdgeState & { sourceHandle?: string; targetHandle?: string };
47
- };
48
-
49
- /**
50
- * A batch of history entries that should be undone/redone together
51
- */
52
- export type HistoryBatch = HistoryEntry[];
53
-
54
- export interface UseUndoRedoReturn {
55
- /** Whether there are entries to undo */
56
- canUndo: boolean;
57
- /** Whether there are entries to redo */
58
- canRedo: boolean;
59
- /** Undo the last batch of changes, returns the entries to reverse */
60
- undo: () => HistoryBatch | null;
61
- /** Redo the last undone batch, returns the entries to re-apply */
62
- redo: () => HistoryBatch | null;
63
- /** Push a new batch of entries to the undo stack (clears redo stack) */
64
- pushHistory: (entries: HistoryBatch) => void;
65
- /** Clear all history (both undo and redo stacks) */
66
- clearHistory: () => void;
67
- }
68
-
69
- /**
70
- * Hook for managing undo/redo history
71
- *
72
- * Uses refs for stacks to avoid re-renders on every push,
73
- * with state for canUndo/canRedo to trigger UI updates
74
- */
75
- export function useUndoRedo(): UseUndoRedoReturn {
76
- // Use refs for stacks to avoid re-renders on every push
77
- const undoStackRef = useRef<HistoryBatch[]>([]);
78
- const redoStackRef = useRef<HistoryBatch[]>([]);
79
-
80
- // State for UI updates (canUndo/canRedo)
81
- const [canUndo, setCanUndo] = useState(false);
82
- const [canRedo, setCanRedo] = useState(false);
83
-
84
- const updateCanStates = useCallback(() => {
85
- setCanUndo(undoStackRef.current.length > 0);
86
- setCanRedo(redoStackRef.current.length > 0);
87
- }, []);
88
-
89
- const pushHistory = useCallback(
90
- (entries: HistoryBatch) => {
91
- if (entries.length === 0) return;
92
-
93
- undoStackRef.current.push(entries);
94
-
95
- // Limit stack size
96
- if (undoStackRef.current.length > MAX_HISTORY_SIZE) {
97
- undoStackRef.current.shift();
98
- }
99
-
100
- // Clear redo stack when new changes are made
101
- redoStackRef.current = [];
102
-
103
- updateCanStates();
104
- },
105
- [updateCanStates]
106
- );
107
-
108
- const undo = useCallback((): HistoryBatch | null => {
109
- const batch = undoStackRef.current.pop();
110
- if (!batch) return null;
111
-
112
- // Push to redo stack
113
- redoStackRef.current.push(batch);
114
-
115
- updateCanStates();
116
- return batch;
117
- }, [updateCanStates]);
118
-
119
- const redo = useCallback((): HistoryBatch | null => {
120
- const batch = redoStackRef.current.pop();
121
- if (!batch) return null;
122
-
123
- // Push back to undo stack
124
- undoStackRef.current.push(batch);
125
-
126
- updateCanStates();
127
- return batch;
128
- }, [updateCanStates]);
129
-
130
- const clearHistory = useCallback(() => {
131
- undoStackRef.current = [];
132
- redoStackRef.current = [];
133
- updateCanStates();
134
- }, [updateCanStates]);
135
-
136
- return {
137
- canUndo,
138
- canRedo,
139
- undo,
140
- redo,
141
- pushHistory,
142
- clearHistory,
143
- };
144
- }