@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.
- package/.turbo/turbo-build.log +23 -0
- package/.turbo/turbo-prepare$colon$type.log +6 -0
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/index.cjs +18394 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +304 -0
- package/dist/index.d.ts +304 -0
- package/dist/index.js +18350 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
- package/src/adapter.ts +1257 -0
- package/src/index.ts +134 -0
- package/src/plugin.ts +638 -0
- package/src/types.ts +271 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +22 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React DevTools Scan - Integration layer for react-scan
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { IntegrationMode, ReactDevtoolsScanOptions, ScanInstance } from './types'
|
|
8
|
+
import { getOptions, ReactScanInternals, scan, setOptions } from 'react-scan'
|
|
9
|
+
import { getScanInstance, resetScanInstance } from './adapter'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Initialize React Scan with DevTools integration
|
|
13
|
+
*
|
|
14
|
+
* @param options - Configuration options for React Scan
|
|
15
|
+
* @returns Scan instance for further control
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { initScan } from '@react-devtools-plus/scan';
|
|
20
|
+
*
|
|
21
|
+
* // Initialize with default options
|
|
22
|
+
* const scanInstance = initScan();
|
|
23
|
+
*
|
|
24
|
+
* // Initialize with custom options
|
|
25
|
+
* const scanInstance = initScan({
|
|
26
|
+
* enabled: true,
|
|
27
|
+
* showToolbar: true,
|
|
28
|
+
* animationSpeed: 'fast',
|
|
29
|
+
* trackUnnecessaryRenders: true,
|
|
30
|
+
* integrationMode: 'overlay'
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function initScan(options: ReactDevtoolsScanOptions = {}): ScanInstance {
|
|
35
|
+
// Set default options
|
|
36
|
+
const defaultOptions: ReactDevtoolsScanOptions = {
|
|
37
|
+
enabled: process.env.NODE_ENV === 'development',
|
|
38
|
+
integrationMode: 'overlay',
|
|
39
|
+
syncWithDevtools: true,
|
|
40
|
+
...options,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (typeof window !== 'undefined') {
|
|
44
|
+
// Check if already initialized (Singleton pattern)
|
|
45
|
+
if ((window as any).__REACT_SCAN_INTERNALS__) {
|
|
46
|
+
// Ensure runInAllEnvironments is true on existing instance
|
|
47
|
+
const existingInternals = (window as any).__REACT_SCAN_INTERNALS__
|
|
48
|
+
if (existingInternals) {
|
|
49
|
+
existingInternals.runInAllEnvironments = true
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Update options on existing instance
|
|
53
|
+
const setOpts = (window as any).__REACT_SCAN_SET_OPTIONS__
|
|
54
|
+
if (setOpts) {
|
|
55
|
+
setOpts(defaultOptions)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Return adapter for existing instance
|
|
59
|
+
return getScanInstance(defaultOptions)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Manually expose internals to window for DevTools integration
|
|
63
|
+
;(window as any).__REACT_SCAN_INTERNALS__ = ReactScanInternals
|
|
64
|
+
;(window as any).__REACT_SCAN_SET_OPTIONS__ = setOptions
|
|
65
|
+
;(window as any).__REACT_SCAN_GET_OPTIONS__ = getOptions
|
|
66
|
+
;(window as any).__REACT_SCAN_SCAN__ = scan
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Initialize scan with the options
|
|
70
|
+
scan(defaultOptions)
|
|
71
|
+
|
|
72
|
+
// Return the scan instance for further control
|
|
73
|
+
return getScanInstance(defaultOptions)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get the current scan instance
|
|
78
|
+
*
|
|
79
|
+
* @returns Current scan instance or null if not initialized
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* import { getScan } from '@react-devtools-plus/scan';
|
|
84
|
+
*
|
|
85
|
+
* const scanInstance = getScan();
|
|
86
|
+
* if (scanInstance) {
|
|
87
|
+
* // Check if scan is active
|
|
88
|
+
* scanInstance.isActive();
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export function getScan(): ScanInstance | null {
|
|
93
|
+
try {
|
|
94
|
+
return getScanInstance()
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return null
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Reset the scan instance (useful for testing)
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* import { resetScan } from '@react-devtools-plus/scan';
|
|
107
|
+
*
|
|
108
|
+
* // Reset for testing
|
|
109
|
+
* resetScan();
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export function resetScan(): void {
|
|
113
|
+
resetScanInstance()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Re-export types
|
|
117
|
+
export type { IntegrationMode, ReactDevtoolsScanOptions, ScanInstance }
|
|
118
|
+
|
|
119
|
+
// Re-export plugin
|
|
120
|
+
export { createScanPlugin, scanPlugin } from './plugin'
|
|
121
|
+
export type { ScanPluginConfig } from './plugin'
|
|
122
|
+
|
|
123
|
+
// Re-export react-scan exports for convenience
|
|
124
|
+
export {
|
|
125
|
+
getOptions,
|
|
126
|
+
onRender,
|
|
127
|
+
ReactScanInternals, // Export Internals for advanced integration
|
|
128
|
+
scan,
|
|
129
|
+
setOptions,
|
|
130
|
+
useScan,
|
|
131
|
+
} from 'react-scan'
|
|
132
|
+
|
|
133
|
+
// Re-export react-scan types
|
|
134
|
+
export type { Options } from 'react-scan'
|