@react-devtools-plus/kit 0.2.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.
@@ -0,0 +1,466 @@
1
+ import { BirpcGroup, BirpcOptions, BirpcReturn } from "birpc";
2
+
3
+ //#region src/core/timeline/index.d.ts
4
+ interface TimelineEvent<TData = any> {
5
+ id: number;
6
+ time: number;
7
+ data: TData;
8
+ title?: string;
9
+ subtitle?: string;
10
+ groupId?: number | string;
11
+ logType?: 'default' | 'warning' | 'error';
12
+ }
13
+ interface TimelineLayer {
14
+ id: string;
15
+ label: string;
16
+ color: string;
17
+ enabled: boolean;
18
+ }
19
+ interface TimelineLayersState {
20
+ recordingState: boolean;
21
+ mouseEventEnabled: boolean;
22
+ keyboardEventEnabled: boolean;
23
+ componentEventEnabled: boolean;
24
+ performanceEventEnabled: boolean;
25
+ selected: string;
26
+ }
27
+ declare const TIMELINE_LAYERS: TimelineLayer[];
28
+ type TimelineEventCallback = (layerId: string, event: TimelineEvent) => void;
29
+ declare function onTimelineEvent(callback: TimelineEventCallback): () => void;
30
+ declare function getTimelineState(): TimelineLayersState;
31
+ declare function updateTimelineState(state: Partial<TimelineLayersState>): void;
32
+ declare function clearTimeline(): void;
33
+ declare function addComponentEvent(componentName: string, eventName: string, params?: any): void;
34
+ declare function addPerformanceEvent(type: 'render' | 'mount' | 'update' | 'unmount' | 'patch' | 'init', componentName: string, measure: 'start' | 'end', duration?: number, groupKey?: string): void;
35
+ declare function trackFiberPerformanceStart(fiber: FiberNode, type: 'render' | 'mount' | 'update'): void;
36
+ declare function trackFiberPerformanceEnd(fiber: FiberNode, type: 'render' | 'mount' | 'update'): void;
37
+ declare function installTimelineEventListeners(): void;
38
+ //#endregion
39
+ //#region src/types/index.d.ts
40
+ interface FiberNode {
41
+ key: null | string;
42
+ elementType: any;
43
+ type: any;
44
+ stateNode: any;
45
+ child: FiberNode | null;
46
+ sibling: FiberNode | null;
47
+ return: FiberNode | null;
48
+ tag: number;
49
+ pendingProps: any;
50
+ memoizedProps: any;
51
+ memoizedState: any;
52
+ _debugSource?: {
53
+ fileName: string;
54
+ lineNumber: number;
55
+ columnNumber: number;
56
+ };
57
+ _debugHookTypes?: string[];
58
+ }
59
+ interface FiberRoot {
60
+ current: FiberNode;
61
+ containerInfo?: any;
62
+ }
63
+ interface ComponentTreeNode {
64
+ id: string;
65
+ name: string;
66
+ children: ComponentTreeNode[];
67
+ meta?: {
68
+ tag: number;
69
+ };
70
+ }
71
+ /**
72
+ * Serializable prop value for display
73
+ */
74
+ interface PropValue {
75
+ type: 'string' | 'number' | 'boolean' | 'null' | 'undefined' | 'object' | 'array' | 'function' | 'symbol' | 'element' | 'unknown';
76
+ value: string;
77
+ preview?: string;
78
+ /** For objects and arrays, contains the nested properties */
79
+ children?: Record<string, PropValue>;
80
+ }
81
+ /**
82
+ * Hook information extracted from fiber
83
+ */
84
+ interface HookInfo {
85
+ name: string;
86
+ value: PropValue;
87
+ subHooks?: HookInfo[];
88
+ }
89
+ /**
90
+ * Parent component in the render chain
91
+ */
92
+ interface RenderedByInfo {
93
+ id: string;
94
+ name: string;
95
+ tag?: number;
96
+ }
97
+ /**
98
+ * Source location information
99
+ */
100
+ interface SourceInfo {
101
+ fileName: string;
102
+ lineNumber: number;
103
+ columnNumber: number;
104
+ }
105
+ /**
106
+ * Detailed component information for the inspector panel
107
+ */
108
+ interface ComponentDetails {
109
+ id: string;
110
+ name: string;
111
+ tag?: number;
112
+ props: Record<string, PropValue>;
113
+ hooks: HookInfo[];
114
+ renderedBy: RenderedByInfo[];
115
+ source?: SourceInfo;
116
+ key?: string | null;
117
+ }
118
+ type TreeListener = (tree: ComponentTreeNode | null) => void;
119
+ interface ReactDevToolsHook {
120
+ renderers: Map<number, any>;
121
+ supportsFiber: boolean;
122
+ inject: (renderer: any) => number;
123
+ onCommitFiberRoot: (rendererID: number, root: FiberRoot) => void;
124
+ onCommitFiberUnmount: (rendererID: number, fiber: FiberNode) => void;
125
+ getFiberRoots?: (rendererID: number) => Set<FiberRoot>;
126
+ sub?: (event: string, fn: (...args: any[]) => void) => () => void;
127
+ }
128
+ declare const REACT_TAGS: {
129
+ readonly FunctionComponent: 0;
130
+ readonly ClassComponent: 1;
131
+ readonly IndeterminateComponent: 2;
132
+ readonly HostRoot: 3;
133
+ readonly HostComponent: 5;
134
+ readonly HostText: 6;
135
+ readonly Fragment: 7;
136
+ readonly Mode: 8;
137
+ readonly ContextConsumer: 9;
138
+ readonly ContextProvider: 10;
139
+ readonly ForwardRef: 11;
140
+ readonly SuspenseComponent: 13;
141
+ readonly MemoComponent: 14;
142
+ readonly SimpleMemoComponent: 15;
143
+ };
144
+ declare global {
145
+ interface Window {
146
+ __REACT_DEVTOOLS_GLOBAL_HOOK__?: ReactDevToolsHook;
147
+ }
148
+ }
149
+ //#endregion
150
+ //#region src/core/context/index.d.ts
151
+ /**
152
+ * Information about a Context Provider
153
+ */
154
+ interface ContextProviderInfo {
155
+ id: string;
156
+ /** Display name of the context (e.g., "ThemeContext") */
157
+ name: string;
158
+ /** Current value of the context */
159
+ value: PropValue;
160
+ /** Fiber ID of the provider component */
161
+ fiberId: string;
162
+ /** Number of consumers using this context */
163
+ consumerCount: number;
164
+ /** List of consumer component names */
165
+ consumers: ContextConsumerInfo[];
166
+ /** Nested providers (same context type) */
167
+ children: ContextProviderInfo[];
168
+ /** Source location if available */
169
+ source?: {
170
+ fileName: string;
171
+ lineNumber: number;
172
+ columnNumber: number;
173
+ };
174
+ }
175
+ /**
176
+ * Information about a Context Consumer
177
+ */
178
+ interface ContextConsumerInfo {
179
+ id: string;
180
+ name: string;
181
+ fiberId: string;
182
+ }
183
+ /**
184
+ * Context tree structure for visualization
185
+ */
186
+ interface ContextTree {
187
+ providers: ContextProviderInfo[];
188
+ totalProviders: number;
189
+ totalConsumers: number;
190
+ }
191
+ /**
192
+ * Get the context tree from a fiber root
193
+ */
194
+ declare function getContextTree(root: FiberRoot): ContextTree;
195
+ /**
196
+ * Get context info for a specific provider by fiber ID
197
+ */
198
+ declare function getContextProviderInfo(root: FiberRoot, fiberId: string): ContextProviderInfo | null;
199
+ /**
200
+ * Get all contexts available in the application
201
+ */
202
+ declare function getAllContexts(root: FiberRoot): ContextTree;
203
+ //#endregion
204
+ //#region src/core/fiber/details.d.ts
205
+ /**
206
+ * Get detailed information about a component from its fiber
207
+ */
208
+ declare function getComponentDetails(fiber: FiberNode): ComponentDetails;
209
+ //#endregion
210
+ //#region src/core/fiber/highlight.d.ts
211
+ interface SourceInfo$1 {
212
+ fileName: string;
213
+ lineNumber: number;
214
+ columnNumber: number;
215
+ }
216
+ declare function hideHighlight(): void;
217
+ declare function showHighlight(rect: DOMRect, name: string, source?: SourceInfo$1): void;
218
+ declare function mergeClientRects(rects: DOMRect[]): DOMRect | null;
219
+ declare function highlightNode(fiber: FiberNode | null, source?: SourceInfo$1): void;
220
+ declare function cleanupHighlight(): void;
221
+ /**
222
+ * Scroll the page to make the component visible
223
+ */
224
+ declare function scrollToNode(fiber: FiberNode | null): void;
225
+ //#endregion
226
+ //#region src/core/fiber/props.d.ts
227
+ /**
228
+ * Props and Context manipulation utilities for React components
229
+ *
230
+ * This module provides functionality to modify component props and context values
231
+ * at runtime for debugging purposes. Changes are NOT persisted to code.
232
+ *
233
+ * Key features:
234
+ * - Props editing using React's official overrideProps API
235
+ * - Context editing via Context Provider's value prop
236
+ * - Automatic type inference for null/undefined values
237
+ * - Fallback mechanisms when official APIs are unavailable
238
+ */
239
+ /**
240
+ * Parse a string value to the appropriate JavaScript type
241
+ *
242
+ * @param value - The string representation of the value
243
+ * @param expectedType - The expected type of the value
244
+ * @returns The parsed value in the correct type
245
+ */
246
+ declare function parseValue(value: string, expectedType: string): any;
247
+ /**
248
+ * Set a prop value on a component
249
+ *
250
+ * Uses React's official overrideProps API when available,
251
+ * falls back to direct fiber manipulation otherwise.
252
+ *
253
+ * @param fiberId - The fiber ID of the component
254
+ * @param propPath - Dot-separated path to the prop (e.g., "user.name")
255
+ * @param value - The string representation of the new value
256
+ * @param valueType - The expected type of the value
257
+ * @returns Whether the operation succeeded
258
+ */
259
+ declare function setComponentProp(fiberId: string, propPath: string, value: string, valueType: string): boolean;
260
+ /**
261
+ * Get an overridden prop value for UI display
262
+ */
263
+ declare function getOverriddenProp(fiberId: string, propPath: string): any;
264
+ /**
265
+ * Check if a prop is editable
266
+ *
267
+ * Some props cannot be edited (children, key, ref, etc.)
268
+ * Some types cannot be edited (functions, symbols, elements)
269
+ */
270
+ declare function isEditableProp(propName: string, valueType: string): boolean;
271
+ /**
272
+ * Set a Context Provider's value
273
+ *
274
+ * @param fiberId - The fiber ID of the Context Provider
275
+ * @param value - The string representation of the new value
276
+ * @param valueType - The expected type of the value
277
+ * @returns Whether the operation succeeded
278
+ */
279
+ declare function setContextValue(fiberId: string, value: string, valueType: string): boolean;
280
+ /**
281
+ * Set a Context Provider's value from a JSON string
282
+ *
283
+ * Used for complex objects where JSON editing is more convenient.
284
+ */
285
+ declare function setContextValueFromJson(fiberId: string, jsonValue: string): boolean;
286
+ /**
287
+ * Set a nested property within a Context Provider's value
288
+ *
289
+ * @param fiberId - The fiber ID of the Context Provider
290
+ * @param path - Dot-separated path to the property (e.g., "theme.mode")
291
+ * @param value - The string representation of the new value
292
+ * @param valueType - The expected type of the value
293
+ * @returns Whether the operation succeeded
294
+ */
295
+ declare function setContextValueAtPath(fiberId: string, path: string, value: string, valueType: string): boolean;
296
+ /**
297
+ * Get an overridden context value for UI display
298
+ */
299
+ declare function getOverriddenContext(fiberId: string): any;
300
+ /**
301
+ * Clear all overrides
302
+ *
303
+ * Should be called when the page refreshes or DevTools disconnects.
304
+ */
305
+ declare function clearOverrides(): void;
306
+ //#endregion
307
+ //#region src/core/fiber/state.d.ts
308
+ /**
309
+ * State manipulation utilities for React components
310
+ * 直接编辑组件的 useState/useReducer 状态(这是最可靠的调试方式)
311
+ */
312
+ interface HookStateInfo {
313
+ index: number;
314
+ name: string;
315
+ value: any;
316
+ type: string;
317
+ canEdit: boolean;
318
+ }
319
+ /**
320
+ * Get all useState/useReducer hooks from a component
321
+ */
322
+ declare function getComponentHookStates(fiberId: string): HookStateInfo[];
323
+ /**
324
+ * Set a hook state value
325
+ * This directly calls the useState setter, which is the most reliable way to update React state
326
+ */
327
+ declare function setHookState(fiberId: string, hookIndex: number, value: string, valueType: string): boolean;
328
+ /**
329
+ * Set a hook state value using JSON (for objects/arrays)
330
+ */
331
+ declare function setHookStateFromJson(fiberId: string, hookIndex: number, jsonValue: string): boolean;
332
+ //#endregion
333
+ //#region src/core/fiber/tree.d.ts
334
+ declare function getFiberById(id: string): FiberNode | undefined;
335
+ declare function buildTree(root: FiberRoot, showHostComponents: boolean): ComponentTreeNode | null;
336
+ declare function clearFiberRegistry(): void;
337
+ //#endregion
338
+ //#region src/core/fiber/utils.d.ts
339
+ declare function getDisplayName(fiber: FiberNode): string;
340
+ declare function shouldIncludeFiber(fiber: FiberNode, showHostComponents: boolean): boolean;
341
+ declare function getFiberId(fiber: FiberNode): string;
342
+ declare function getFiberFromElement(element: Element): FiberNode | null;
343
+ //#endregion
344
+ //#region src/core/hook/index.d.ts
345
+ type TreeUpdateCallback = (tree: ComponentTreeNode | null) => void;
346
+ declare function onTreeUpdated(callback: TreeUpdateCallback): () => void;
347
+ /**
348
+ * Get the current app fiber root (exported for context debugging)
349
+ */
350
+ declare function getAppFiberRoot(): FiberRoot | null;
351
+ declare function rebuildTree(showHostComponents: boolean): void;
352
+ /**
353
+ * Get the React version from the renderer
354
+ */
355
+ declare function getReactVersion(): string | null;
356
+ declare function installReactHook(showHostComponents: () => boolean): void;
357
+ //#endregion
358
+ //#region src/core/inspector/index.d.ts
359
+ declare function onInspectorSelect(callback: (fiberId: string) => void): () => boolean;
360
+ declare function onOpenInEditor(callback: (fileName: string, line: number, column: number) => void): () => boolean;
361
+ interface ToggleInspectorOptions {
362
+ mode?: 'select-component' | 'open-in-editor';
363
+ }
364
+ declare function toggleInspector(enabled: boolean, options?: ToggleInspectorOptions): void;
365
+ //#endregion
366
+ //#region src/core/open-in-editor/index.d.ts
367
+ declare function openInEditor(fileName: string, line: number, column: number): void;
368
+ //#endregion
369
+ //#region src/core/router/index.d.ts
370
+ interface RouteInfo {
371
+ path: string;
372
+ name?: string;
373
+ element?: string;
374
+ children?: RouteInfo[];
375
+ /** Whether this is an index route (renders at parent's path) */
376
+ isIndex?: boolean;
377
+ /** Whether this is a layout route (has children but may not add URL segment) */
378
+ isLayout?: boolean;
379
+ /** Whether this route has a loader function */
380
+ hasLoader?: boolean;
381
+ /** Whether this route has an action function */
382
+ hasAction?: boolean;
383
+ /** Whether this route uses lazy loading */
384
+ isLazy?: boolean;
385
+ /** Whether this route has an error boundary */
386
+ hasErrorBoundary?: boolean;
387
+ /** Dynamic segments in the path (e.g., :id, :userId) */
388
+ params?: string[];
389
+ }
390
+ interface MatchedRoute {
391
+ path: string;
392
+ params: Record<string, string>;
393
+ element?: string;
394
+ }
395
+ interface NavigationEntry {
396
+ path: string;
397
+ search: string;
398
+ hash: string;
399
+ timestamp: number;
400
+ duration?: number;
401
+ }
402
+ interface RouterState {
403
+ currentPath: string;
404
+ search: string;
405
+ hash: string;
406
+ routes: RouteInfo[];
407
+ routerType: 'react-router' | 'unknown' | null;
408
+ /** Current matched route chain */
409
+ matchedRoutes: MatchedRoute[];
410
+ /** Current route params */
411
+ params: Record<string, string>;
412
+ /** Navigation history */
413
+ history: NavigationEntry[];
414
+ /** Last navigation duration in ms */
415
+ lastNavigationDuration?: number;
416
+ }
417
+ /**
418
+ * Set the fiber root reference (called from hook)
419
+ */
420
+ declare function setFiberRoot(root: FiberRoot | null): void;
421
+ /**
422
+ * Get the current fiber root
423
+ */
424
+ declare function getFiberRoot(): FiberRoot | null;
425
+ /**
426
+ * Get router information from the current React app
427
+ */
428
+ declare function getRouterInfo(): RouterState | null;
429
+ /**
430
+ * Navigate to a path using various methods
431
+ */
432
+ declare function navigateTo(path: string): boolean;
433
+ /**
434
+ * Clear navigation history
435
+ */
436
+ declare function clearNavigationHistory(): void;
437
+ //#endregion
438
+ //#region src/messaging/types/channel.d.ts
439
+ interface MergeableChannelOptions {
440
+ post: (data: any) => void;
441
+ on: (handler: (data: any) => void) => void;
442
+ }
443
+ //#endregion
444
+ //#region src/messaging/presets/index.d.ts
445
+ type Presets = 'iframe' | 'broadcast';
446
+ //#endregion
447
+ //#region src/messaging/index.d.ts
448
+ interface CreateRpcClientOptions<RemoteFunctions> {
449
+ preset?: Presets;
450
+ channel?: MergeableChannelOptions;
451
+ options?: BirpcOptions<RemoteFunctions>;
452
+ }
453
+ interface CreateRpcServerOptions<RemoteFunctions> {
454
+ preset?: Presets;
455
+ channel?: MergeableChannelOptions;
456
+ }
457
+ declare function setRpcServerToGlobal<R, L>(rpc: BirpcGroup<R, L>): void;
458
+ declare function getRpcClient<RemoteFunctions = Record<string, never>, LocalFunctions extends object = Record<string, (arg: any) => void>>(): BirpcReturn<RemoteFunctions, LocalFunctions> | null;
459
+ declare function getRpcServer<RemoteFunctions = Record<string, never>, LocalFunctions extends object = Record<string, (arg: any) => void>>(): BirpcGroup<RemoteFunctions, LocalFunctions> | null;
460
+ declare function createRpcClient<RemoteFunctions = Record<string, never>, LocalFunctions extends object = Record<string, (arg: any) => void>>(functions: LocalFunctions, options?: CreateRpcClientOptions<RemoteFunctions>): BirpcReturn<RemoteFunctions, LocalFunctions>;
461
+ declare function createRpcServer<RemoteFunctions = Record<string, never>, LocalFunctions extends object = Record<string, (arg: any) => void>>(functions: LocalFunctions, options?: CreateRpcServerOptions<RemoteFunctions>): void;
462
+ //#endregion
463
+ //#region src/messaging/presets/iframe/context.d.ts
464
+ declare function setIframeServerContext(iframe: HTMLIFrameElement | null): void;
465
+ //#endregion
466
+ export { ComponentDetails, ComponentTreeNode, ContextConsumerInfo, ContextProviderInfo, ContextTree, CreateRpcClientOptions, CreateRpcServerOptions, FiberNode, FiberRoot, HookInfo, HookStateInfo, MatchedRoute, NavigationEntry, PropValue, REACT_TAGS, ReactDevToolsHook, RenderedByInfo, RouteInfo, RouterState, SourceInfo, TIMELINE_LAYERS, type TimelineEvent, type TimelineLayer, type TimelineLayersState, ToggleInspectorOptions, TreeListener, addComponentEvent, addPerformanceEvent, buildTree, cleanupHighlight, clearFiberRegistry, clearNavigationHistory, clearOverrides, clearTimeline, createRpcClient, createRpcServer, getAllContexts, getAppFiberRoot, getComponentDetails, getComponentHookStates, getContextProviderInfo, getContextTree, getDisplayName, getFiberById, getFiberFromElement, getFiberId, getFiberRoot, getOverriddenContext, getOverriddenProp, getReactVersion, getRouterInfo, getRpcClient, getRpcServer, getTimelineState, hideHighlight, highlightNode, installReactHook, installTimelineEventListeners, isEditableProp, mergeClientRects, navigateTo, onInspectorSelect, onOpenInEditor, onTimelineEvent, onTreeUpdated, openInEditor, parseValue, rebuildTree, scrollToNode, setComponentProp, setContextValue, setContextValueAtPath, setContextValueFromJson, setFiberRoot, setHookState, setHookStateFromJson, setIframeServerContext, setRpcServerToGlobal, shouldIncludeFiber, showHighlight, toggleInspector, trackFiberPerformanceEnd, trackFiberPerformanceStart, updateTimelineState };