@react-devtools-plus/scan 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,304 @@
1
+ import { Options } from 'react-scan';
2
+ export { Options, ReactScanInternals, getOptions, onRender, scan, setOptions, useScan } from 'react-scan';
3
+
4
+ /**
5
+ * Type definitions for React DevTools Scan integration
6
+ */
7
+
8
+ /**
9
+ * Integration modes for React Scan
10
+ */
11
+ type IntegrationMode = 'overlay' | 'panel' | 'both';
12
+ /**
13
+ * Extended options for React DevTools Scan integration
14
+ */
15
+ interface ReactDevtoolsScanOptions extends Options {
16
+ /**
17
+ * Integration mode - how scan should be displayed
18
+ * - 'overlay': Show as overlay on the page (default react-scan behavior)
19
+ * - 'panel': Integrate into DevTools panel
20
+ * - 'both': Show both overlay and panel integration
21
+ *
22
+ * @default 'overlay'
23
+ */
24
+ integrationMode?: IntegrationMode;
25
+ /**
26
+ * Whether to sync state with DevTools panel
27
+ *
28
+ * @default true
29
+ */
30
+ syncWithDevtools?: boolean;
31
+ }
32
+ /**
33
+ * Scan instance interface
34
+ */
35
+ /**
36
+ * Performance metrics for a component
37
+ */
38
+ interface ComponentPerformanceData {
39
+ componentName: string;
40
+ renderCount: number;
41
+ totalTime: number;
42
+ averageTime: number;
43
+ unnecessaryRenders: number;
44
+ lastRenderTime: number | null;
45
+ }
46
+ /**
47
+ * Aggregated performance summary
48
+ */
49
+ interface PerformanceSummary {
50
+ totalRenders: number;
51
+ totalComponents: number;
52
+ unnecessaryRenders: number;
53
+ averageRenderTime: number;
54
+ slowestComponents: ComponentPerformanceData[];
55
+ }
56
+ /**
57
+ * Component info for selection
58
+ */
59
+ interface ComponentInfo {
60
+ componentName: string;
61
+ fiber: any;
62
+ domElement: Element | null;
63
+ }
64
+ /**
65
+ * Change info for a single prop/state/context value
66
+ */
67
+ interface ChangeInfo {
68
+ name: string;
69
+ previousValue: any;
70
+ currentValue: any;
71
+ count: number;
72
+ }
73
+ /**
74
+ * Aggregated changes for a component render
75
+ */
76
+ interface AggregatedChanges {
77
+ propsChanges: ChangeInfo[];
78
+ stateChanges: ChangeInfo[];
79
+ contextChanges: ChangeInfo[];
80
+ }
81
+ /**
82
+ * Focused component render info with changes
83
+ */
84
+ interface FocusedComponentRenderInfo {
85
+ componentName: string;
86
+ renderCount: number;
87
+ changes: AggregatedChanges;
88
+ timestamp: number;
89
+ }
90
+ interface ScanInstance {
91
+ /**
92
+ * Get current scan options
93
+ */
94
+ getOptions: () => ReactDevtoolsScanOptions;
95
+ /**
96
+ * Update scan options at runtime
97
+ */
98
+ setOptions: (options: Partial<ReactDevtoolsScanOptions>) => void;
99
+ /**
100
+ * Start scanning
101
+ */
102
+ start: () => void;
103
+ /**
104
+ * Stop scanning
105
+ */
106
+ stop: () => void;
107
+ /**
108
+ * Check if scanning is active
109
+ */
110
+ isActive: () => boolean;
111
+ /**
112
+ * Hide the React Scan toolbar
113
+ */
114
+ hideToolbar: () => void;
115
+ /**
116
+ * Show the React Scan toolbar
117
+ */
118
+ showToolbar: () => void;
119
+ /**
120
+ * Get toolbar visibility state
121
+ */
122
+ getToolbarVisibility: () => boolean;
123
+ /**
124
+ * Get performance data for all components
125
+ */
126
+ getPerformanceData: () => ComponentPerformanceData[];
127
+ /**
128
+ * Get aggregated performance summary
129
+ */
130
+ getPerformanceSummary: () => PerformanceSummary;
131
+ /**
132
+ * Clear all performance data
133
+ */
134
+ clearPerformanceData: () => void;
135
+ /**
136
+ * Start component inspection mode
137
+ */
138
+ startInspecting: () => void;
139
+ /**
140
+ * Stop component inspection mode
141
+ */
142
+ stopInspecting: () => void;
143
+ /**
144
+ * Check if inspection mode is active
145
+ */
146
+ isInspecting: () => boolean;
147
+ /**
148
+ * Focus on a specific component by fiber
149
+ */
150
+ focusComponent: (fiber: any) => void;
151
+ /**
152
+ * Get currently focused component
153
+ */
154
+ getFocusedComponent: () => ComponentInfo | null;
155
+ /**
156
+ * Subscribe to inspection state changes
157
+ */
158
+ onInspectStateChange: (callback: (state: any) => void) => () => void;
159
+ /**
160
+ * Get current FPS
161
+ */
162
+ getFPS: () => number;
163
+ /**
164
+ * Get focused component render info with changes
165
+ */
166
+ getFocusedComponentRenderInfo: () => FocusedComponentRenderInfo | null;
167
+ /**
168
+ * Subscribe to focused component changes (re-renders)
169
+ */
170
+ onFocusedComponentChange: (callback: (info: FocusedComponentRenderInfo) => void) => () => void;
171
+ /**
172
+ * Clear the focused component's change history
173
+ */
174
+ clearFocusedComponentChanges: () => void;
175
+ /**
176
+ * Set the focused component by name for render tracking
177
+ * This is used when inspectState.kind is not 'focused' but we still want to track renders
178
+ */
179
+ setFocusedComponentByName: (componentName: string) => void;
180
+ /**
181
+ * Get the component tree with render counts
182
+ */
183
+ getComponentTree: () => ComponentTreeNode[];
184
+ /**
185
+ * Clear component render count tracking
186
+ */
187
+ clearComponentTree: () => void;
188
+ }
189
+ /**
190
+ * Component tree node
191
+ */
192
+ interface ComponentTreeNode {
193
+ id: string;
194
+ name: string;
195
+ type: string;
196
+ renderCount: number;
197
+ lastRenderTime: number;
198
+ averageTime?: number;
199
+ unnecessary?: number;
200
+ children: ComponentTreeNode[];
201
+ fiber?: any;
202
+ }
203
+
204
+ /**
205
+ * React Scan Plugin for React DevTools
206
+ *
207
+ * This plugin integrates React Scan into the React DevTools plugin system,
208
+ * providing performance monitoring and analysis capabilities.
209
+ */
210
+
211
+ /**
212
+ * React Scan plugin configuration
213
+ */
214
+ interface ScanPluginConfig extends ReactDevtoolsScanOptions {
215
+ /**
216
+ * Whether to auto-start scan on plugin load
217
+ * @default true
218
+ */
219
+ autoStart?: boolean;
220
+ }
221
+ /**
222
+ * Create React Scan plugin
223
+ *
224
+ * @param config - Plugin configuration
225
+ * @returns DevTools plugin instance
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * import { createScanPlugin } from '@react-devtools-plus/scan/plugin';
230
+ *
231
+ * const scanPlugin = createScanPlugin({
232
+ * enabled: true,
233
+ * showToolbar: true,
234
+ * autoStart: true,
235
+ * });
236
+ * ```
237
+ */
238
+ declare function createScanPlugin(config?: ScanPluginConfig): any;
239
+ /**
240
+ * Default React Scan plugin instance
241
+ */
242
+ declare const scanPlugin: any;
243
+
244
+ /**
245
+ * React DevTools Scan - Integration layer for react-scan
246
+ *
247
+ * @packageDocumentation
248
+ */
249
+
250
+ /**
251
+ * Initialize React Scan with DevTools integration
252
+ *
253
+ * @param options - Configuration options for React Scan
254
+ * @returns Scan instance for further control
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * import { initScan } from '@react-devtools-plus/scan';
259
+ *
260
+ * // Initialize with default options
261
+ * const scanInstance = initScan();
262
+ *
263
+ * // Initialize with custom options
264
+ * const scanInstance = initScan({
265
+ * enabled: true,
266
+ * showToolbar: true,
267
+ * animationSpeed: 'fast',
268
+ * trackUnnecessaryRenders: true,
269
+ * integrationMode: 'overlay'
270
+ * });
271
+ * ```
272
+ */
273
+ declare function initScan(options?: ReactDevtoolsScanOptions): ScanInstance;
274
+ /**
275
+ * Get the current scan instance
276
+ *
277
+ * @returns Current scan instance or null if not initialized
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * import { getScan } from '@react-devtools-plus/scan';
282
+ *
283
+ * const scanInstance = getScan();
284
+ * if (scanInstance) {
285
+ * // Check if scan is active
286
+ * scanInstance.isActive();
287
+ * }
288
+ * ```
289
+ */
290
+ declare function getScan(): ScanInstance | null;
291
+ /**
292
+ * Reset the scan instance (useful for testing)
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * import { resetScan } from '@react-devtools-plus/scan';
297
+ *
298
+ * // Reset for testing
299
+ * resetScan();
300
+ * ```
301
+ */
302
+ declare function resetScan(): void;
303
+
304
+ export { type IntegrationMode, type ReactDevtoolsScanOptions, type ScanInstance, type ScanPluginConfig, createScanPlugin, getScan, initScan, resetScan, scanPlugin };
@@ -0,0 +1,304 @@
1
+ import { Options } from 'react-scan';
2
+ export { Options, ReactScanInternals, getOptions, onRender, scan, setOptions, useScan } from 'react-scan';
3
+
4
+ /**
5
+ * Type definitions for React DevTools Scan integration
6
+ */
7
+
8
+ /**
9
+ * Integration modes for React Scan
10
+ */
11
+ type IntegrationMode = 'overlay' | 'panel' | 'both';
12
+ /**
13
+ * Extended options for React DevTools Scan integration
14
+ */
15
+ interface ReactDevtoolsScanOptions extends Options {
16
+ /**
17
+ * Integration mode - how scan should be displayed
18
+ * - 'overlay': Show as overlay on the page (default react-scan behavior)
19
+ * - 'panel': Integrate into DevTools panel
20
+ * - 'both': Show both overlay and panel integration
21
+ *
22
+ * @default 'overlay'
23
+ */
24
+ integrationMode?: IntegrationMode;
25
+ /**
26
+ * Whether to sync state with DevTools panel
27
+ *
28
+ * @default true
29
+ */
30
+ syncWithDevtools?: boolean;
31
+ }
32
+ /**
33
+ * Scan instance interface
34
+ */
35
+ /**
36
+ * Performance metrics for a component
37
+ */
38
+ interface ComponentPerformanceData {
39
+ componentName: string;
40
+ renderCount: number;
41
+ totalTime: number;
42
+ averageTime: number;
43
+ unnecessaryRenders: number;
44
+ lastRenderTime: number | null;
45
+ }
46
+ /**
47
+ * Aggregated performance summary
48
+ */
49
+ interface PerformanceSummary {
50
+ totalRenders: number;
51
+ totalComponents: number;
52
+ unnecessaryRenders: number;
53
+ averageRenderTime: number;
54
+ slowestComponents: ComponentPerformanceData[];
55
+ }
56
+ /**
57
+ * Component info for selection
58
+ */
59
+ interface ComponentInfo {
60
+ componentName: string;
61
+ fiber: any;
62
+ domElement: Element | null;
63
+ }
64
+ /**
65
+ * Change info for a single prop/state/context value
66
+ */
67
+ interface ChangeInfo {
68
+ name: string;
69
+ previousValue: any;
70
+ currentValue: any;
71
+ count: number;
72
+ }
73
+ /**
74
+ * Aggregated changes for a component render
75
+ */
76
+ interface AggregatedChanges {
77
+ propsChanges: ChangeInfo[];
78
+ stateChanges: ChangeInfo[];
79
+ contextChanges: ChangeInfo[];
80
+ }
81
+ /**
82
+ * Focused component render info with changes
83
+ */
84
+ interface FocusedComponentRenderInfo {
85
+ componentName: string;
86
+ renderCount: number;
87
+ changes: AggregatedChanges;
88
+ timestamp: number;
89
+ }
90
+ interface ScanInstance {
91
+ /**
92
+ * Get current scan options
93
+ */
94
+ getOptions: () => ReactDevtoolsScanOptions;
95
+ /**
96
+ * Update scan options at runtime
97
+ */
98
+ setOptions: (options: Partial<ReactDevtoolsScanOptions>) => void;
99
+ /**
100
+ * Start scanning
101
+ */
102
+ start: () => void;
103
+ /**
104
+ * Stop scanning
105
+ */
106
+ stop: () => void;
107
+ /**
108
+ * Check if scanning is active
109
+ */
110
+ isActive: () => boolean;
111
+ /**
112
+ * Hide the React Scan toolbar
113
+ */
114
+ hideToolbar: () => void;
115
+ /**
116
+ * Show the React Scan toolbar
117
+ */
118
+ showToolbar: () => void;
119
+ /**
120
+ * Get toolbar visibility state
121
+ */
122
+ getToolbarVisibility: () => boolean;
123
+ /**
124
+ * Get performance data for all components
125
+ */
126
+ getPerformanceData: () => ComponentPerformanceData[];
127
+ /**
128
+ * Get aggregated performance summary
129
+ */
130
+ getPerformanceSummary: () => PerformanceSummary;
131
+ /**
132
+ * Clear all performance data
133
+ */
134
+ clearPerformanceData: () => void;
135
+ /**
136
+ * Start component inspection mode
137
+ */
138
+ startInspecting: () => void;
139
+ /**
140
+ * Stop component inspection mode
141
+ */
142
+ stopInspecting: () => void;
143
+ /**
144
+ * Check if inspection mode is active
145
+ */
146
+ isInspecting: () => boolean;
147
+ /**
148
+ * Focus on a specific component by fiber
149
+ */
150
+ focusComponent: (fiber: any) => void;
151
+ /**
152
+ * Get currently focused component
153
+ */
154
+ getFocusedComponent: () => ComponentInfo | null;
155
+ /**
156
+ * Subscribe to inspection state changes
157
+ */
158
+ onInspectStateChange: (callback: (state: any) => void) => () => void;
159
+ /**
160
+ * Get current FPS
161
+ */
162
+ getFPS: () => number;
163
+ /**
164
+ * Get focused component render info with changes
165
+ */
166
+ getFocusedComponentRenderInfo: () => FocusedComponentRenderInfo | null;
167
+ /**
168
+ * Subscribe to focused component changes (re-renders)
169
+ */
170
+ onFocusedComponentChange: (callback: (info: FocusedComponentRenderInfo) => void) => () => void;
171
+ /**
172
+ * Clear the focused component's change history
173
+ */
174
+ clearFocusedComponentChanges: () => void;
175
+ /**
176
+ * Set the focused component by name for render tracking
177
+ * This is used when inspectState.kind is not 'focused' but we still want to track renders
178
+ */
179
+ setFocusedComponentByName: (componentName: string) => void;
180
+ /**
181
+ * Get the component tree with render counts
182
+ */
183
+ getComponentTree: () => ComponentTreeNode[];
184
+ /**
185
+ * Clear component render count tracking
186
+ */
187
+ clearComponentTree: () => void;
188
+ }
189
+ /**
190
+ * Component tree node
191
+ */
192
+ interface ComponentTreeNode {
193
+ id: string;
194
+ name: string;
195
+ type: string;
196
+ renderCount: number;
197
+ lastRenderTime: number;
198
+ averageTime?: number;
199
+ unnecessary?: number;
200
+ children: ComponentTreeNode[];
201
+ fiber?: any;
202
+ }
203
+
204
+ /**
205
+ * React Scan Plugin for React DevTools
206
+ *
207
+ * This plugin integrates React Scan into the React DevTools plugin system,
208
+ * providing performance monitoring and analysis capabilities.
209
+ */
210
+
211
+ /**
212
+ * React Scan plugin configuration
213
+ */
214
+ interface ScanPluginConfig extends ReactDevtoolsScanOptions {
215
+ /**
216
+ * Whether to auto-start scan on plugin load
217
+ * @default true
218
+ */
219
+ autoStart?: boolean;
220
+ }
221
+ /**
222
+ * Create React Scan plugin
223
+ *
224
+ * @param config - Plugin configuration
225
+ * @returns DevTools plugin instance
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * import { createScanPlugin } from '@react-devtools-plus/scan/plugin';
230
+ *
231
+ * const scanPlugin = createScanPlugin({
232
+ * enabled: true,
233
+ * showToolbar: true,
234
+ * autoStart: true,
235
+ * });
236
+ * ```
237
+ */
238
+ declare function createScanPlugin(config?: ScanPluginConfig): any;
239
+ /**
240
+ * Default React Scan plugin instance
241
+ */
242
+ declare const scanPlugin: any;
243
+
244
+ /**
245
+ * React DevTools Scan - Integration layer for react-scan
246
+ *
247
+ * @packageDocumentation
248
+ */
249
+
250
+ /**
251
+ * Initialize React Scan with DevTools integration
252
+ *
253
+ * @param options - Configuration options for React Scan
254
+ * @returns Scan instance for further control
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * import { initScan } from '@react-devtools-plus/scan';
259
+ *
260
+ * // Initialize with default options
261
+ * const scanInstance = initScan();
262
+ *
263
+ * // Initialize with custom options
264
+ * const scanInstance = initScan({
265
+ * enabled: true,
266
+ * showToolbar: true,
267
+ * animationSpeed: 'fast',
268
+ * trackUnnecessaryRenders: true,
269
+ * integrationMode: 'overlay'
270
+ * });
271
+ * ```
272
+ */
273
+ declare function initScan(options?: ReactDevtoolsScanOptions): ScanInstance;
274
+ /**
275
+ * Get the current scan instance
276
+ *
277
+ * @returns Current scan instance or null if not initialized
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * import { getScan } from '@react-devtools-plus/scan';
282
+ *
283
+ * const scanInstance = getScan();
284
+ * if (scanInstance) {
285
+ * // Check if scan is active
286
+ * scanInstance.isActive();
287
+ * }
288
+ * ```
289
+ */
290
+ declare function getScan(): ScanInstance | null;
291
+ /**
292
+ * Reset the scan instance (useful for testing)
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * import { resetScan } from '@react-devtools-plus/scan';
297
+ *
298
+ * // Reset for testing
299
+ * resetScan();
300
+ * ```
301
+ */
302
+ declare function resetScan(): void;
303
+
304
+ export { type IntegrationMode, type ReactDevtoolsScanOptions, type ScanInstance, type ScanPluginConfig, createScanPlugin, getScan, initScan, resetScan, scanPlugin };