@react-devtools-plus/core 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/LICENSE +21 -0
- package/dist/client/index.cjs +165 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +91 -0
- package/dist/client/index.d.ts +91 -0
- package/dist/client/index.js +133 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.cjs +730 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +67 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +686 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/index.cjs +306 -0
- package/dist/plugin/index.cjs.map +1 -0
- package/dist/plugin/index.d.cts +94 -0
- package/dist/plugin/index.d.ts +94 -0
- package/dist/plugin/index.js +278 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/rpc/index.cjs +309 -0
- package/dist/rpc/index.cjs.map +1 -0
- package/dist/rpc/index.d.cts +124 -0
- package/dist/rpc/index.d.ts +124 -0
- package/dist/rpc/index.js +277 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/types-BU_SaMGj.d.cts +182 -0
- package/dist/types-BU_SaMGj.d.ts +182 -0
- package/package.json +61 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for React DevTools
|
|
3
|
+
* React DevTools 核心类型定义
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Component tree node information
|
|
7
|
+
* 组件树节点信息
|
|
8
|
+
*/
|
|
9
|
+
interface ComponentNode {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
type: 'function' | 'class' | 'memo' | 'forward-ref' | 'context' | 'provider' | 'consumer';
|
|
13
|
+
props: Record<string, any>;
|
|
14
|
+
state?: Record<string, any>;
|
|
15
|
+
hooks?: HookInfo[];
|
|
16
|
+
children: string[];
|
|
17
|
+
parent?: string;
|
|
18
|
+
source?: SourceLocation;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Hook information
|
|
22
|
+
* Hook 信息
|
|
23
|
+
*/
|
|
24
|
+
interface HookInfo {
|
|
25
|
+
index: number;
|
|
26
|
+
name: string;
|
|
27
|
+
value: any;
|
|
28
|
+
subHooks?: HookInfo[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Source code location
|
|
32
|
+
* 源码位置
|
|
33
|
+
*/
|
|
34
|
+
interface SourceLocation {
|
|
35
|
+
fileName: string;
|
|
36
|
+
lineNumber: number;
|
|
37
|
+
columnNumber: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Performance metrics
|
|
41
|
+
* 性能指标
|
|
42
|
+
*/
|
|
43
|
+
interface PerformanceMetrics {
|
|
44
|
+
componentId: string;
|
|
45
|
+
renderTime: number;
|
|
46
|
+
updateCount: number;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* DevTools state
|
|
51
|
+
* DevTools 状态
|
|
52
|
+
*/
|
|
53
|
+
interface DevToolsState {
|
|
54
|
+
connected: boolean;
|
|
55
|
+
selectedComponent?: string;
|
|
56
|
+
expandedComponents: Set<string>;
|
|
57
|
+
highlightedComponent?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Event types
|
|
61
|
+
* 事件类型
|
|
62
|
+
*/
|
|
63
|
+
type DevToolsEvent = {
|
|
64
|
+
type: 'component-selected';
|
|
65
|
+
componentId: string;
|
|
66
|
+
} | {
|
|
67
|
+
type: 'component-updated';
|
|
68
|
+
componentId: string;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'component-mounted';
|
|
71
|
+
componentId: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: 'component-unmounted';
|
|
74
|
+
componentId: string;
|
|
75
|
+
} | {
|
|
76
|
+
type: 'connection-changed';
|
|
77
|
+
connected: boolean;
|
|
78
|
+
} | {
|
|
79
|
+
type: 'highlight-changed';
|
|
80
|
+
componentId?: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* RPC function definitions
|
|
84
|
+
* RPC 函数定义
|
|
85
|
+
*/
|
|
86
|
+
interface ClientFunctions {
|
|
87
|
+
getComponentTree: () => Promise<ComponentNode[]>;
|
|
88
|
+
getComponentDetails: (componentId: string) => Promise<ComponentNode | null>;
|
|
89
|
+
updateComponentProps: (componentId: string, props: Record<string, any>) => Promise<void>;
|
|
90
|
+
updateComponentState: (componentId: string, state: Record<string, any>) => Promise<void>;
|
|
91
|
+
openInEditor: (source: SourceLocation) => Promise<void>;
|
|
92
|
+
startProfiling: () => Promise<void>;
|
|
93
|
+
stopProfiling: () => Promise<PerformanceMetrics[]>;
|
|
94
|
+
selectComponent: (componentId: string) => Promise<void>;
|
|
95
|
+
highlightComponent: (componentId?: string) => Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
interface ServerFunctions {
|
|
98
|
+
onComponentTreeChanged: () => void;
|
|
99
|
+
onComponentSelected: (componentId: string) => void;
|
|
100
|
+
onPerformanceData: (metrics: PerformanceMetrics) => void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Plugin types
|
|
104
|
+
* 插件类型
|
|
105
|
+
*/
|
|
106
|
+
interface DevToolsPlugin {
|
|
107
|
+
/**
|
|
108
|
+
* Plugin unique identifier
|
|
109
|
+
* 插件唯一标识符
|
|
110
|
+
*/
|
|
111
|
+
id: string;
|
|
112
|
+
/**
|
|
113
|
+
* Plugin name
|
|
114
|
+
* 插件名称
|
|
115
|
+
*/
|
|
116
|
+
name: string;
|
|
117
|
+
/**
|
|
118
|
+
* Plugin description
|
|
119
|
+
* 插件描述
|
|
120
|
+
*/
|
|
121
|
+
description?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Plugin initialization
|
|
124
|
+
* 插件初始化
|
|
125
|
+
*/
|
|
126
|
+
setup?: (context: PluginContext) => void | Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Plugin cleanup
|
|
129
|
+
* 插件清理
|
|
130
|
+
*/
|
|
131
|
+
teardown?: () => void | Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Custom RPC functions
|
|
134
|
+
* 自定义 RPC 函数
|
|
135
|
+
*/
|
|
136
|
+
rpc?: Record<string, (...args: any[]) => any>;
|
|
137
|
+
/**
|
|
138
|
+
* Event handlers
|
|
139
|
+
* 事件处理器
|
|
140
|
+
*/
|
|
141
|
+
on?: Partial<Record<DevToolsEvent['type'], (event: DevToolsEvent) => void>>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Plugin context
|
|
145
|
+
* 插件上下文
|
|
146
|
+
*/
|
|
147
|
+
interface PluginContext {
|
|
148
|
+
/**
|
|
149
|
+
* Get component tree
|
|
150
|
+
* 获取组件树
|
|
151
|
+
*/
|
|
152
|
+
getComponentTree: () => Promise<ComponentNode[]>;
|
|
153
|
+
/**
|
|
154
|
+
* Get component details
|
|
155
|
+
* 获取组件详情
|
|
156
|
+
*/
|
|
157
|
+
getComponentDetails: (componentId: string) => Promise<ComponentNode | null>;
|
|
158
|
+
/**
|
|
159
|
+
* Emit event
|
|
160
|
+
* 发送事件
|
|
161
|
+
*/
|
|
162
|
+
emit: (event: DevToolsEvent) => void;
|
|
163
|
+
/**
|
|
164
|
+
* Subscribe to events
|
|
165
|
+
* 订阅事件
|
|
166
|
+
*/
|
|
167
|
+
on: <T extends DevToolsEvent['type']>(type: T, handler: (event: Extract<DevToolsEvent, {
|
|
168
|
+
type: T;
|
|
169
|
+
}>) => void) => () => void;
|
|
170
|
+
/**
|
|
171
|
+
* Register custom RPC function
|
|
172
|
+
* 注册自定义 RPC 函数
|
|
173
|
+
*/
|
|
174
|
+
registerRPC: <T extends (...args: any[]) => any>(name: string, fn: T) => void;
|
|
175
|
+
/**
|
|
176
|
+
* Call RPC function
|
|
177
|
+
* 调用 RPC 函数
|
|
178
|
+
*/
|
|
179
|
+
callRPC: <T = any>(name: string, ...args: any[]) => Promise<T>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export type { ComponentNode as C, DevToolsEvent as D, HookInfo as H, PluginContext as P, SourceLocation as S, DevToolsPlugin as a, PerformanceMetrics as b, DevToolsState as c, ClientFunctions as d, ServerFunctions as e };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for React DevTools
|
|
3
|
+
* React DevTools 核心类型定义
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Component tree node information
|
|
7
|
+
* 组件树节点信息
|
|
8
|
+
*/
|
|
9
|
+
interface ComponentNode {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
type: 'function' | 'class' | 'memo' | 'forward-ref' | 'context' | 'provider' | 'consumer';
|
|
13
|
+
props: Record<string, any>;
|
|
14
|
+
state?: Record<string, any>;
|
|
15
|
+
hooks?: HookInfo[];
|
|
16
|
+
children: string[];
|
|
17
|
+
parent?: string;
|
|
18
|
+
source?: SourceLocation;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Hook information
|
|
22
|
+
* Hook 信息
|
|
23
|
+
*/
|
|
24
|
+
interface HookInfo {
|
|
25
|
+
index: number;
|
|
26
|
+
name: string;
|
|
27
|
+
value: any;
|
|
28
|
+
subHooks?: HookInfo[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Source code location
|
|
32
|
+
* 源码位置
|
|
33
|
+
*/
|
|
34
|
+
interface SourceLocation {
|
|
35
|
+
fileName: string;
|
|
36
|
+
lineNumber: number;
|
|
37
|
+
columnNumber: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Performance metrics
|
|
41
|
+
* 性能指标
|
|
42
|
+
*/
|
|
43
|
+
interface PerformanceMetrics {
|
|
44
|
+
componentId: string;
|
|
45
|
+
renderTime: number;
|
|
46
|
+
updateCount: number;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* DevTools state
|
|
51
|
+
* DevTools 状态
|
|
52
|
+
*/
|
|
53
|
+
interface DevToolsState {
|
|
54
|
+
connected: boolean;
|
|
55
|
+
selectedComponent?: string;
|
|
56
|
+
expandedComponents: Set<string>;
|
|
57
|
+
highlightedComponent?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Event types
|
|
61
|
+
* 事件类型
|
|
62
|
+
*/
|
|
63
|
+
type DevToolsEvent = {
|
|
64
|
+
type: 'component-selected';
|
|
65
|
+
componentId: string;
|
|
66
|
+
} | {
|
|
67
|
+
type: 'component-updated';
|
|
68
|
+
componentId: string;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'component-mounted';
|
|
71
|
+
componentId: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: 'component-unmounted';
|
|
74
|
+
componentId: string;
|
|
75
|
+
} | {
|
|
76
|
+
type: 'connection-changed';
|
|
77
|
+
connected: boolean;
|
|
78
|
+
} | {
|
|
79
|
+
type: 'highlight-changed';
|
|
80
|
+
componentId?: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* RPC function definitions
|
|
84
|
+
* RPC 函数定义
|
|
85
|
+
*/
|
|
86
|
+
interface ClientFunctions {
|
|
87
|
+
getComponentTree: () => Promise<ComponentNode[]>;
|
|
88
|
+
getComponentDetails: (componentId: string) => Promise<ComponentNode | null>;
|
|
89
|
+
updateComponentProps: (componentId: string, props: Record<string, any>) => Promise<void>;
|
|
90
|
+
updateComponentState: (componentId: string, state: Record<string, any>) => Promise<void>;
|
|
91
|
+
openInEditor: (source: SourceLocation) => Promise<void>;
|
|
92
|
+
startProfiling: () => Promise<void>;
|
|
93
|
+
stopProfiling: () => Promise<PerformanceMetrics[]>;
|
|
94
|
+
selectComponent: (componentId: string) => Promise<void>;
|
|
95
|
+
highlightComponent: (componentId?: string) => Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
interface ServerFunctions {
|
|
98
|
+
onComponentTreeChanged: () => void;
|
|
99
|
+
onComponentSelected: (componentId: string) => void;
|
|
100
|
+
onPerformanceData: (metrics: PerformanceMetrics) => void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Plugin types
|
|
104
|
+
* 插件类型
|
|
105
|
+
*/
|
|
106
|
+
interface DevToolsPlugin {
|
|
107
|
+
/**
|
|
108
|
+
* Plugin unique identifier
|
|
109
|
+
* 插件唯一标识符
|
|
110
|
+
*/
|
|
111
|
+
id: string;
|
|
112
|
+
/**
|
|
113
|
+
* Plugin name
|
|
114
|
+
* 插件名称
|
|
115
|
+
*/
|
|
116
|
+
name: string;
|
|
117
|
+
/**
|
|
118
|
+
* Plugin description
|
|
119
|
+
* 插件描述
|
|
120
|
+
*/
|
|
121
|
+
description?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Plugin initialization
|
|
124
|
+
* 插件初始化
|
|
125
|
+
*/
|
|
126
|
+
setup?: (context: PluginContext) => void | Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Plugin cleanup
|
|
129
|
+
* 插件清理
|
|
130
|
+
*/
|
|
131
|
+
teardown?: () => void | Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Custom RPC functions
|
|
134
|
+
* 自定义 RPC 函数
|
|
135
|
+
*/
|
|
136
|
+
rpc?: Record<string, (...args: any[]) => any>;
|
|
137
|
+
/**
|
|
138
|
+
* Event handlers
|
|
139
|
+
* 事件处理器
|
|
140
|
+
*/
|
|
141
|
+
on?: Partial<Record<DevToolsEvent['type'], (event: DevToolsEvent) => void>>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Plugin context
|
|
145
|
+
* 插件上下文
|
|
146
|
+
*/
|
|
147
|
+
interface PluginContext {
|
|
148
|
+
/**
|
|
149
|
+
* Get component tree
|
|
150
|
+
* 获取组件树
|
|
151
|
+
*/
|
|
152
|
+
getComponentTree: () => Promise<ComponentNode[]>;
|
|
153
|
+
/**
|
|
154
|
+
* Get component details
|
|
155
|
+
* 获取组件详情
|
|
156
|
+
*/
|
|
157
|
+
getComponentDetails: (componentId: string) => Promise<ComponentNode | null>;
|
|
158
|
+
/**
|
|
159
|
+
* Emit event
|
|
160
|
+
* 发送事件
|
|
161
|
+
*/
|
|
162
|
+
emit: (event: DevToolsEvent) => void;
|
|
163
|
+
/**
|
|
164
|
+
* Subscribe to events
|
|
165
|
+
* 订阅事件
|
|
166
|
+
*/
|
|
167
|
+
on: <T extends DevToolsEvent['type']>(type: T, handler: (event: Extract<DevToolsEvent, {
|
|
168
|
+
type: T;
|
|
169
|
+
}>) => void) => () => void;
|
|
170
|
+
/**
|
|
171
|
+
* Register custom RPC function
|
|
172
|
+
* 注册自定义 RPC 函数
|
|
173
|
+
*/
|
|
174
|
+
registerRPC: <T extends (...args: any[]) => any>(name: string, fn: T) => void;
|
|
175
|
+
/**
|
|
176
|
+
* Call RPC function
|
|
177
|
+
* 调用 RPC 函数
|
|
178
|
+
*/
|
|
179
|
+
callRPC: <T = any>(name: string, ...args: any[]) => Promise<T>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export type { ComponentNode as C, DevToolsEvent as D, HookInfo as H, PluginContext as P, SourceLocation as S, DevToolsPlugin as a, PerformanceMetrics as b, DevToolsState as c, ClientFunctions as d, ServerFunctions as e };
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-devtools-plus/core",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"description": "Core functionality for React DevTools including RPC, client management, and plugin system",
|
|
6
|
+
"author": "wzc520pyfm",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./rpc": {
|
|
15
|
+
"types": "./dist/rpc.d.ts",
|
|
16
|
+
"import": "./dist/rpc.js",
|
|
17
|
+
"require": "./dist/rpc.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./client": {
|
|
20
|
+
"types": "./dist/client.d.ts",
|
|
21
|
+
"import": "./dist/client.js",
|
|
22
|
+
"require": "./dist/client.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./plugin": {
|
|
25
|
+
"types": "./dist/plugin.d.ts",
|
|
26
|
+
"import": "./dist/plugin.js",
|
|
27
|
+
"require": "./dist/plugin.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/index.cjs",
|
|
31
|
+
"module": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"vite": ">=5.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"vite": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"birpc": "^0.2.19",
|
|
46
|
+
"@react-devtools-plus/shared": "0.2.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^24.7.2",
|
|
50
|
+
"tsup": "^8.5.1",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"vite": "^7.1.10"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsup",
|
|
56
|
+
"dev": "tsup --watch",
|
|
57
|
+
"prepare:type": "tsup --dts-only",
|
|
58
|
+
"stub": "tsup --watch --dts-only",
|
|
59
|
+
"typecheck": "tsc --noEmit"
|
|
60
|
+
}
|
|
61
|
+
}
|