@principal-ai/subsystems-react 0.17.0 → 0.19.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.
- package/README.md +11 -85
- package/dist/index.d.ts +7 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -32
- package/dist/index.js.map +1 -1
- package/dist/subsystem/SubsystemCarousel.d.ts +36 -0
- package/dist/subsystem/SubsystemCarousel.d.ts.map +1 -0
- package/dist/subsystem/SubsystemCarousel.js +163 -0
- package/dist/subsystem/SubsystemCarousel.js.map +1 -0
- package/dist/subsystem/SubsystemComponentGraph.d.ts +25 -0
- package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.js +329 -68
- package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +9 -199
- package/src/subsystem/SubsystemComponentGraph.tsx +396 -50
- package/src/components/ConfigurationSelector.tsx +0 -133
- package/src/components/GraphRenderer.tsx +0 -3195
- package/src/components/MultiCanvasRenderer.tsx +0 -295
- package/src/components/NodeTooltip.tsx +0 -279
- package/src/components/PendingChanges.test.tsx +0 -375
- package/src/components/SelectionSidebar.tsx +0 -352
- package/src/components/SequenceDiagramRenderer.tsx +0 -1156
- package/src/components/WorkflowSequenceDiagram.tsx +0 -270
- package/src/components/dashboard/DashboardRenderer.tsx +0 -317
- package/src/components/dashboard/MetricPanel.tsx +0 -254
- package/src/components/dashboard/MockDataProvider.ts +0 -330
- package/src/components/dashboard/components/BarChart.tsx +0 -299
- package/src/components/dashboard/components/LineChart.tsx +0 -279
- package/src/components/dashboard/components/MetricCard.tsx +0 -270
- package/src/components/dashboard/components/SourceLink.tsx +0 -63
- package/src/components/dashboard/components/TimeRangeSelector.tsx +0 -280
- package/src/components/dashboard/components/index.ts +0 -5
- package/src/components/dashboard/index.ts +0 -47
- package/src/components/dashboard/types.ts +0 -126
- package/src/components/state-view/PipelineView.tsx +0 -347
- package/src/components/state-view/index.ts +0 -14
- package/src/components/state-view/types.ts +0 -261
- package/src/components/state-view/useStateView.ts +0 -205
- package/src/contexts/GraphEditContext.tsx +0 -27
- package/src/contexts/TooltipPortalContext.ts +0 -8
- package/src/edges/CustomEdge.tsx +0 -402
- package/src/edges/GenericEdge.tsx +0 -36
- package/src/hooks/usePathBasedEvents.ts +0 -192
- package/src/hooks/useSequenceLayout.ts +0 -543
- package/src/hooks/useUndoRedo.ts +0 -144
- package/src/nodes/CustomNode.tsx +0 -1231
- package/src/nodes/GenericNode.tsx +0 -55
- package/src/nodes/otel/OtelBoundaryNode.tsx +0 -224
- package/src/nodes/otel/OtelEventNode.tsx +0 -225
- package/src/nodes/otel/OtelResourceNode.tsx +0 -251
- package/src/nodes/otel/OtelScopeNode.tsx +0 -221
- package/src/nodes/otel/OtelSpanConventionNode.tsx +0 -295
- package/src/nodes/otel/index.ts +0 -23
- package/src/nodes/otel/shared/NodeBadges.tsx +0 -295
- package/src/nodes/otel/shared/NodeContent.tsx +0 -204
- package/src/nodes/otel/shared/index.ts +0 -8
- package/src/nodes/otel/shared/types.ts +0 -138
- package/src/nodes/otel/shared/useNodeBehavior.ts +0 -114
- package/src/stories/Audit/BoundaryNodes.stories.tsx +0 -385
- package/src/stories/Audit/CanvasEdgeTypes.stories.tsx +0 -1448
- package/src/stories/Audit/CanvasNodeTypes.stories.tsx +0 -1049
- package/src/stories/Audit/ColorPriority.stories.tsx +0 -895
- package/src/stories/Audit/DiamondBadges.stories.tsx +0 -629
- package/src/stories/Audit/NodeDimensionsTesting.stories.tsx +0 -724
- package/src/stories/Audit/NodeFieldsAudit.stories.tsx +0 -996
- package/src/stories/Audit/NodeFontSizeTesting.stories.tsx +0 -715
- package/src/stories/Audit/NodeShapes.stories.tsx +0 -1208
- package/src/stories/Audit/WideNodesTesting.stories.tsx +0 -1045
- package/src/stories/Components/DashboardRenderer.stories.tsx +0 -263
- package/src/stories/Components/GraphRenderer.stories.tsx +0 -3236
- package/src/stories/Components/MultiCanvasRenderer.stories.tsx +0 -370
- package/src/stories/Components/SequenceDiagram.stories.tsx +0 -255
- package/src/stories/Components/StateView.stories.tsx +0 -417
- package/src/stories/Components/TraceViewer.stories.tsx +0 -442
- package/src/stories/Components/WorkflowSequenceDiagram.stories.tsx +0 -802
- package/src/stories/Features/AnimationWorkshop.stories.tsx +0 -727
- package/src/stories/Features/ChangeTypeVisual.stories.tsx +0 -67
- package/src/stories/Features/EventDrivenAnimations.stories.tsx +0 -513
- package/src/stories/Features/MultiConfig.stories.tsx +0 -539
- package/src/stories/Layout/ElkEdgeRouting.stories.tsx +0 -539
- package/src/stories/Layout/GraphOrientation.stories.tsx +0 -500
- package/src/stories/Layout/MultiDirectionalConnections.stories.tsx +0 -352
- package/src/stories/Nodes/NodeDefinitionComparison.stories.tsx +0 -560
- package/src/stories/Nodes/NodeNameFallbacks.stories.tsx +0 -491
- package/src/stories/Nodes/NumericColors.stories.tsx +0 -440
- package/src/stories/OTEL/EventNameDisplay.stories.tsx +0 -694
- package/src/stories/OTEL/EventNameFallback.stories.tsx +0 -578
- package/src/stories/OTEL/OtelComponents.stories.tsx +0 -422
- package/src/stories/OTEL/OtelNodeTypesPrototype.stories.tsx +0 -806
- package/src/stories/OTEL/RawEventCards.stories.tsx +0 -57
- package/src/stories/OTEL/SpanBadges.stories.tsx +0 -840
- package/src/stories/OTEL/ValidationEventsCanvas.stories.tsx +0 -209
- package/src/stories/RealWorld/BacklogMdCanvases.stories.tsx +0 -721
- package/src/stories/RealWorld/FileCitySequence.stories.tsx +0 -516
- package/src/stories/RealWorld/RealCanvasFiles.stories.tsx +0 -336
- package/src/stories/__traces__/test-run.canvas.json +0 -241
- package/src/stories/data/activity-feed-analytics.dashboard.json +0 -300
- package/src/stories/data/file-city-images-transformed.otel.canvas.json +0 -295
- package/src/stories/data/file-city-workflows.json +0 -269
- package/src/stories/data/graph-converter-test-execution.json +0 -443
- package/src/stories/data/graph-converter-test.workflow.json +0 -105
- package/src/stories/data/graph-converter-validated-execution.json +0 -58
- package/src/utils/animationMapping.ts +0 -166
- package/src/utils/canvasBounds.ts +0 -146
- package/src/utils/graphConverter.ts +0 -148
- package/src/utils/iconResolver.tsx +0 -53
- package/src/utils/orientationUtils.ts +0 -73
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* State View Types
|
|
3
|
-
*
|
|
4
|
-
* A state-based visualization system where:
|
|
5
|
-
* - Telemetry events are processed into state changes
|
|
6
|
-
* - State has a defined shape
|
|
7
|
-
* - State changes trigger animations/transitions
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// =============================================================================
|
|
11
|
-
// Core Event Types
|
|
12
|
-
// =============================================================================
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A state event extracted from telemetry (OTEL spans, etc.)
|
|
16
|
-
*/
|
|
17
|
-
export interface StateEvent<TPayload = Record<string, unknown>> {
|
|
18
|
-
/** Event type identifier */
|
|
19
|
-
type: string;
|
|
20
|
-
/** When this event occurred */
|
|
21
|
-
timestamp: number;
|
|
22
|
-
/** Event-specific data */
|
|
23
|
-
payload: TPayload;
|
|
24
|
-
/** Optional trace correlation */
|
|
25
|
-
traceId?: string;
|
|
26
|
-
spanId?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Source of events - can be live (IPC/WebSocket) or replay (from storage)
|
|
31
|
-
*/
|
|
32
|
-
export interface EventSource<TEvent extends StateEvent = StateEvent> {
|
|
33
|
-
/** Subscribe to events, returns unsubscribe function */
|
|
34
|
-
subscribe(handler: (event: TEvent) => void): () => void;
|
|
35
|
-
/** Optional: current mode */
|
|
36
|
-
mode?: 'live' | 'replay';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// =============================================================================
|
|
40
|
-
// State Types
|
|
41
|
-
// =============================================================================
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* A reducer that applies events to state
|
|
45
|
-
*/
|
|
46
|
-
export type StateReducer<TState, TEvent extends StateEvent> = (
|
|
47
|
-
state: TState,
|
|
48
|
-
event: TEvent
|
|
49
|
-
) => TState;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Describes what changed between two states (for animations)
|
|
53
|
-
*/
|
|
54
|
-
export interface StateDiff<TState> {
|
|
55
|
-
/** Previous state */
|
|
56
|
-
prev: TState;
|
|
57
|
-
/** New state */
|
|
58
|
-
next: TState;
|
|
59
|
-
/** Which paths changed (dot notation) */
|
|
60
|
-
changedPaths: string[];
|
|
61
|
-
/** The event that caused this change */
|
|
62
|
-
event: StateEvent;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// =============================================================================
|
|
66
|
-
// Animation/Transition Types
|
|
67
|
-
// =============================================================================
|
|
68
|
-
|
|
69
|
-
export type AnimationType =
|
|
70
|
-
| 'pulse'
|
|
71
|
-
| 'glow'
|
|
72
|
-
| 'flash'
|
|
73
|
-
| 'shake'
|
|
74
|
-
| 'slide-in'
|
|
75
|
-
| 'slide-out'
|
|
76
|
-
| 'fade-in'
|
|
77
|
-
| 'fade-out'
|
|
78
|
-
| 'particle-flow'
|
|
79
|
-
| 'increment'
|
|
80
|
-
| 'decrement'
|
|
81
|
-
| 'bar-change';
|
|
82
|
-
|
|
83
|
-
export interface TransitionDefinition {
|
|
84
|
-
/** Condition: which state path to watch */
|
|
85
|
-
watch: string;
|
|
86
|
-
/** Condition type */
|
|
87
|
-
condition: 'changed' | 'increased' | 'decreased' | 'added' | 'removed';
|
|
88
|
-
/** Animation to trigger */
|
|
89
|
-
animate: AnimationType;
|
|
90
|
-
/** Target element (CSS selector or element ID) */
|
|
91
|
-
target?: string;
|
|
92
|
-
/** Duration in ms */
|
|
93
|
-
duration?: number;
|
|
94
|
-
/** Additional params */
|
|
95
|
-
params?: Record<string, unknown>;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface ActiveAnimation {
|
|
99
|
-
id: string;
|
|
100
|
-
type: AnimationType;
|
|
101
|
-
target: string;
|
|
102
|
-
startTime: number;
|
|
103
|
-
duration: number;
|
|
104
|
-
params?: Record<string, unknown>;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// =============================================================================
|
|
108
|
-
// Replay Types
|
|
109
|
-
// =============================================================================
|
|
110
|
-
|
|
111
|
-
export interface ReplayControls {
|
|
112
|
-
/** Current playback state */
|
|
113
|
-
state: 'playing' | 'paused' | 'stopped';
|
|
114
|
-
/** Playback speed multiplier */
|
|
115
|
-
speed: number;
|
|
116
|
-
/** Current replay time (event time, not wall time) */
|
|
117
|
-
currentTime: number;
|
|
118
|
-
/** Start of replay range */
|
|
119
|
-
startTime: number;
|
|
120
|
-
/** End of replay range */
|
|
121
|
-
endTime: number;
|
|
122
|
-
/** Control methods */
|
|
123
|
-
play: () => void;
|
|
124
|
-
pause: () => void;
|
|
125
|
-
stop: () => void;
|
|
126
|
-
seek: (time: number) => void;
|
|
127
|
-
setSpeed: (speed: number) => void;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// =============================================================================
|
|
131
|
-
// Pipeline View Specific Types (Case Study 1)
|
|
132
|
-
// =============================================================================
|
|
133
|
-
|
|
134
|
-
export interface PipelineStage {
|
|
135
|
-
id: string;
|
|
136
|
-
label: string;
|
|
137
|
-
lastEventTime: number | null;
|
|
138
|
-
isActive: boolean;
|
|
139
|
-
count?: number;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export interface PipelineRepoState {
|
|
143
|
-
path: string;
|
|
144
|
-
lastEventTime: number;
|
|
145
|
-
lastEventType: string;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface PipelineState {
|
|
149
|
-
stages: Record<string, PipelineStage>;
|
|
150
|
-
repos: Map<string, PipelineRepoState>;
|
|
151
|
-
totalEvents: number;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export type PipelineEventType =
|
|
155
|
-
| 'FS_CHANGE'
|
|
156
|
-
| 'WATCH_DETECTED'
|
|
157
|
-
| 'CACHE_REBUILD'
|
|
158
|
-
| 'CACHE_HIT'
|
|
159
|
-
| 'EVENT_BROADCAST';
|
|
160
|
-
|
|
161
|
-
export interface PipelineEvent extends StateEvent {
|
|
162
|
-
type: PipelineEventType;
|
|
163
|
-
payload: {
|
|
164
|
-
repo?: string;
|
|
165
|
-
stage?: string;
|
|
166
|
-
slice?: string;
|
|
167
|
-
eventType?: string;
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// =============================================================================
|
|
172
|
-
// Activity View Specific Types (Case Study 2)
|
|
173
|
-
// =============================================================================
|
|
174
|
-
|
|
175
|
-
export interface RoomState {
|
|
176
|
-
id: string;
|
|
177
|
-
userCount: number;
|
|
178
|
-
users: Set<string>;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export interface ActivityState {
|
|
182
|
-
rooms: Map<string, RoomState>;
|
|
183
|
-
totalUsers: number;
|
|
184
|
-
syncRatePerMinute: number;
|
|
185
|
-
recentSyncs: number[];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export type ActivityEventType =
|
|
189
|
-
| 'ROOM_JOIN'
|
|
190
|
-
| 'ROOM_LEAVE'
|
|
191
|
-
| 'SYNC_BROADCAST';
|
|
192
|
-
|
|
193
|
-
export interface ActivityEvent extends StateEvent {
|
|
194
|
-
type: ActivityEventType;
|
|
195
|
-
payload: {
|
|
196
|
-
roomId?: string;
|
|
197
|
-
userId?: string;
|
|
198
|
-
userLogin?: string;
|
|
199
|
-
syncType?: string;
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// =============================================================================
|
|
204
|
-
// Quota View Specific Types (Case Study 3)
|
|
205
|
-
// =============================================================================
|
|
206
|
-
|
|
207
|
-
export interface UserQuotaState {
|
|
208
|
-
userId: number;
|
|
209
|
-
userLogin: string;
|
|
210
|
-
remaining: number;
|
|
211
|
-
limit: number;
|
|
212
|
-
resetTime: number;
|
|
213
|
-
callsThisHour: number;
|
|
214
|
-
cacheHits: number;
|
|
215
|
-
byOperation: Map<string, { total: number; apiCalls: number }>;
|
|
216
|
-
byRepo: Map<string, { total: number; apiCalls: number }>;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export interface QuotaDistributionState {
|
|
220
|
-
users: Map<number, UserQuotaState>;
|
|
221
|
-
serverRemaining: number;
|
|
222
|
-
serverResetTime: number;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export type QuotaEventType = 'GITHUB_REQUEST';
|
|
226
|
-
|
|
227
|
-
export interface QuotaEvent extends StateEvent {
|
|
228
|
-
type: QuotaEventType;
|
|
229
|
-
payload: {
|
|
230
|
-
userId?: number;
|
|
231
|
-
userLogin?: string;
|
|
232
|
-
tokenType: 'user' | 'server';
|
|
233
|
-
operation: string;
|
|
234
|
-
repoOwner?: string;
|
|
235
|
-
repoName?: string;
|
|
236
|
-
cacheHit: boolean;
|
|
237
|
-
cacheTier?: string;
|
|
238
|
-
ratelimitRemaining?: number;
|
|
239
|
-
ratelimitLimit?: number;
|
|
240
|
-
ratelimitReset?: number;
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// =============================================================================
|
|
245
|
-
// View Definition (Schema)
|
|
246
|
-
// =============================================================================
|
|
247
|
-
|
|
248
|
-
export interface StateViewDefinition<TState, TEvent extends StateEvent> {
|
|
249
|
-
id: string;
|
|
250
|
-
name: string;
|
|
251
|
-
description?: string;
|
|
252
|
-
|
|
253
|
-
/** Initial state */
|
|
254
|
-
initialState: TState;
|
|
255
|
-
|
|
256
|
-
/** Reducer function or reference */
|
|
257
|
-
reducer: StateReducer<TState, TEvent>;
|
|
258
|
-
|
|
259
|
-
/** Transition definitions for animations */
|
|
260
|
-
transitions?: TransitionDefinition[];
|
|
261
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useStateView Hook
|
|
3
|
-
*
|
|
4
|
-
* Manages state accumulation from events and provides replay controls.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
8
|
-
import type {
|
|
9
|
-
StateEvent,
|
|
10
|
-
EventSource,
|
|
11
|
-
StateReducer,
|
|
12
|
-
StateDiff,
|
|
13
|
-
ReplayControls,
|
|
14
|
-
ActiveAnimation,
|
|
15
|
-
TransitionDefinition,
|
|
16
|
-
} from './types';
|
|
17
|
-
|
|
18
|
-
export interface UseStateViewOptions<TState, TEvent extends StateEvent> {
|
|
19
|
-
/** Initial state */
|
|
20
|
-
initialState: TState;
|
|
21
|
-
/** Reducer to apply events */
|
|
22
|
-
reducer: StateReducer<TState, TEvent>;
|
|
23
|
-
/** Event source (live or replay) */
|
|
24
|
-
eventSource: EventSource<TEvent>;
|
|
25
|
-
/** Transition definitions for animations */
|
|
26
|
-
transitions?: TransitionDefinition[];
|
|
27
|
-
/** Callback when state changes */
|
|
28
|
-
onStateChange?: (diff: StateDiff<TState>) => void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface UseStateViewResult<TState> {
|
|
32
|
-
/** Current state */
|
|
33
|
-
state: TState;
|
|
34
|
-
/** Active animations */
|
|
35
|
-
animations: ActiveAnimation[];
|
|
36
|
-
/** Whether we're in replay mode */
|
|
37
|
-
isReplay: boolean;
|
|
38
|
-
/** Replay controls (if in replay mode) */
|
|
39
|
-
replayControls?: ReplayControls;
|
|
40
|
-
/** Reset state to initial */
|
|
41
|
-
reset: () => void;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Get changed paths between two objects (shallow comparison)
|
|
46
|
-
*/
|
|
47
|
-
function getChangedPaths(prev: unknown, next: unknown, prefix = ''): string[] {
|
|
48
|
-
const paths: string[] = [];
|
|
49
|
-
|
|
50
|
-
if (prev === next) return paths;
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
typeof prev !== 'object' ||
|
|
54
|
-
typeof next !== 'object' ||
|
|
55
|
-
prev === null ||
|
|
56
|
-
next === null
|
|
57
|
-
) {
|
|
58
|
-
return prefix ? [prefix] : [];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const prevObj = prev as Record<string, unknown>;
|
|
62
|
-
const nextObj = next as Record<string, unknown>;
|
|
63
|
-
|
|
64
|
-
const allKeys = new Set([...Object.keys(prevObj), ...Object.keys(nextObj)]);
|
|
65
|
-
|
|
66
|
-
for (const key of allKeys) {
|
|
67
|
-
const path = prefix ? `${prefix}.${key}` : key;
|
|
68
|
-
if (prevObj[key] !== nextObj[key]) {
|
|
69
|
-
paths.push(path);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return paths;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Check if a transition should fire based on state change
|
|
78
|
-
*/
|
|
79
|
-
function shouldTriggerTransition(
|
|
80
|
-
transition: TransitionDefinition,
|
|
81
|
-
prev: unknown,
|
|
82
|
-
next: unknown,
|
|
83
|
-
changedPaths: string[]
|
|
84
|
-
): boolean {
|
|
85
|
-
// Check if the watched path changed
|
|
86
|
-
if (!changedPaths.some((p) => p.startsWith(transition.watch))) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const prevValue = getValueAtPath(prev, transition.watch);
|
|
91
|
-
const nextValue = getValueAtPath(next, transition.watch);
|
|
92
|
-
|
|
93
|
-
switch (transition.condition) {
|
|
94
|
-
case 'changed':
|
|
95
|
-
return prevValue !== nextValue;
|
|
96
|
-
case 'increased':
|
|
97
|
-
return typeof nextValue === 'number' && typeof prevValue === 'number' && nextValue > prevValue;
|
|
98
|
-
case 'decreased':
|
|
99
|
-
return typeof nextValue === 'number' && typeof prevValue === 'number' && nextValue < prevValue;
|
|
100
|
-
case 'added':
|
|
101
|
-
return prevValue === undefined && nextValue !== undefined;
|
|
102
|
-
case 'removed':
|
|
103
|
-
return prevValue !== undefined && nextValue === undefined;
|
|
104
|
-
default:
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function getValueAtPath(obj: unknown, path: string): unknown {
|
|
110
|
-
const parts = path.split('.');
|
|
111
|
-
let current = obj;
|
|
112
|
-
for (const part of parts) {
|
|
113
|
-
if (current === null || current === undefined) return undefined;
|
|
114
|
-
current = (current as Record<string, unknown>)[part];
|
|
115
|
-
}
|
|
116
|
-
return current;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function useStateView<TState, TEvent extends StateEvent>({
|
|
120
|
-
initialState,
|
|
121
|
-
reducer,
|
|
122
|
-
eventSource,
|
|
123
|
-
transitions = [],
|
|
124
|
-
onStateChange,
|
|
125
|
-
}: UseStateViewOptions<TState, TEvent>): UseStateViewResult<TState> {
|
|
126
|
-
const [state, setState] = useState<TState>(initialState);
|
|
127
|
-
const [animations, setAnimations] = useState<ActiveAnimation[]>([]);
|
|
128
|
-
const prevStateRef = useRef<TState>(initialState);
|
|
129
|
-
const animationIdRef = useRef(0);
|
|
130
|
-
|
|
131
|
-
const triggerAnimation = useCallback(
|
|
132
|
-
(transition: TransitionDefinition, _event: StateEvent) => {
|
|
133
|
-
const id = `anim-${++animationIdRef.current}`;
|
|
134
|
-
const duration = transition.duration ?? 500;
|
|
135
|
-
|
|
136
|
-
const animation: ActiveAnimation = {
|
|
137
|
-
id,
|
|
138
|
-
type: transition.animate,
|
|
139
|
-
target: transition.target ?? transition.watch,
|
|
140
|
-
startTime: Date.now(),
|
|
141
|
-
duration,
|
|
142
|
-
params: transition.params,
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
setAnimations((prev) => [...prev, animation]);
|
|
146
|
-
|
|
147
|
-
// Auto-remove after duration
|
|
148
|
-
setTimeout(() => {
|
|
149
|
-
setAnimations((prev) => prev.filter((a) => a.id !== id));
|
|
150
|
-
}, duration);
|
|
151
|
-
},
|
|
152
|
-
[]
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
const handleEvent = useCallback(
|
|
156
|
-
(event: TEvent) => {
|
|
157
|
-
setState((prevState) => {
|
|
158
|
-
const nextState = reducer(prevState, event);
|
|
159
|
-
const changedPaths = getChangedPaths(prevState, nextState);
|
|
160
|
-
|
|
161
|
-
// Trigger animations based on transitions
|
|
162
|
-
for (const transition of transitions) {
|
|
163
|
-
if (shouldTriggerTransition(transition, prevState, nextState, changedPaths)) {
|
|
164
|
-
triggerAnimation(transition, event);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Notify listener
|
|
169
|
-
if (onStateChange && changedPaths.length > 0) {
|
|
170
|
-
onStateChange({
|
|
171
|
-
prev: prevState,
|
|
172
|
-
next: nextState,
|
|
173
|
-
changedPaths,
|
|
174
|
-
event,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
prevStateRef.current = nextState;
|
|
179
|
-
return nextState;
|
|
180
|
-
});
|
|
181
|
-
},
|
|
182
|
-
[reducer, transitions, onStateChange, triggerAnimation]
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
// Subscribe to event source
|
|
186
|
-
useEffect(() => {
|
|
187
|
-
const unsubscribe = eventSource.subscribe(handleEvent);
|
|
188
|
-
return unsubscribe;
|
|
189
|
-
}, [eventSource, handleEvent]);
|
|
190
|
-
|
|
191
|
-
const reset = useCallback(() => {
|
|
192
|
-
setState(initialState);
|
|
193
|
-
setAnimations([]);
|
|
194
|
-
prevStateRef.current = initialState;
|
|
195
|
-
}, [initialState]);
|
|
196
|
-
|
|
197
|
-
const isReplay = eventSource.mode === 'replay';
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
state,
|
|
201
|
-
animations,
|
|
202
|
-
isReplay,
|
|
203
|
-
reset,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
export interface GraphEditContextValue {
|
|
4
|
-
/** Called when a node resize operation completes */
|
|
5
|
-
onNodeResizeEnd?: (nodeId: string, dimensions: { width: number; height: number }) => void;
|
|
6
|
-
/** Called when node text is edited (for text and group nodes) */
|
|
7
|
-
onNodeTextChange?: (nodeId: string, text: string) => void;
|
|
8
|
-
/** Called to toggle node hidden state (Cmd/Ctrl+click) */
|
|
9
|
-
onToggleNodeHidden?: (nodeId: string) => void;
|
|
10
|
-
/** Called to hide all nodes not directly connected to the given node (Cmd/Ctrl+Shift+click) */
|
|
11
|
-
onHideUnconnectedNodes?: (nodeId: string) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const GraphEditContext = createContext<GraphEditContextValue>({});
|
|
15
|
-
|
|
16
|
-
export const GraphEditProvider: React.FC<{
|
|
17
|
-
children: React.ReactNode;
|
|
18
|
-
value: GraphEditContextValue;
|
|
19
|
-
}> = ({ children, value }) => {
|
|
20
|
-
return (
|
|
21
|
-
<GraphEditContext.Provider value={value}>
|
|
22
|
-
{children}
|
|
23
|
-
</GraphEditContext.Provider>
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const useGraphEdit = () => useContext(GraphEditContext);
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Context for providing a portal target for tooltips.
|
|
5
|
-
* This allows tooltips to be rendered within the graph container
|
|
6
|
-
* instead of document.body, so they hide properly when tabs switch.
|
|
7
|
-
*/
|
|
8
|
-
export const TooltipPortalContext = createContext<HTMLElement | null>(null);
|