forked from vuejs/devtools-v6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.ts
More file actions
185 lines (179 loc) · 6.5 KB
/
hooks.ts
File metadata and controls
185 lines (179 loc) · 6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import type { ComponentTreeNode, InspectedComponentData, ComponentInstance, ComponentDevtoolsOptions } from './component.js'
import type { App } from './app.js'
import type { CustomInspectorNode, CustomInspectorState, TimelineEvent } from './api.js'
export const enum Hooks {
TRANSFORM_CALL = 'transformCall',
GET_APP_RECORD_NAME = 'getAppRecordName',
GET_APP_ROOT_INSTANCE = 'getAppRootInstance',
REGISTER_APPLICATION = 'registerApplication',
WALK_COMPONENT_TREE = 'walkComponentTree',
VISIT_COMPONENT_TREE = 'visitComponentTree',
WALK_COMPONENT_PARENTS = 'walkComponentParents',
INSPECT_COMPONENT = 'inspectComponent',
GET_COMPONENT_BOUNDS = 'getComponentBounds',
GET_COMPONENT_NAME = 'getComponentName',
GET_COMPONENT_INSTANCES = 'getComponentInstances',
GET_ELEMENT_COMPONENT = 'getElementComponent',
GET_COMPONENT_ROOT_ELEMENTS = 'getComponentRootElements',
EDIT_COMPONENT_STATE = 'editComponentState',
GET_COMPONENT_DEVTOOLS_OPTIONS = 'getAppDevtoolsOptions',
GET_COMPONENT_RENDER_CODE = 'getComponentRenderCode',
INSPECT_TIMELINE_EVENT = 'inspectTimelineEvent',
TIMELINE_CLEARED = 'timelineCleared',
GET_INSPECTOR_TREE = 'getInspectorTree',
GET_INSPECTOR_STATE = 'getInspectorState',
EDIT_INSPECTOR_STATE = 'editInspectorState',
SET_PLUGIN_SETTINGS = 'setPluginSettings',
}
export interface ComponentBounds {
left: number
top: number
width: number
height: number
}
export type HookPayloads = {
[Hooks.TRANSFORM_CALL]: {
callName: string
inArgs: any[]
outArgs: any[]
}
[Hooks.GET_APP_RECORD_NAME]: {
app: App
name: string
}
[Hooks.GET_APP_ROOT_INSTANCE]: {
app: App
root: ComponentInstance
}
[Hooks.REGISTER_APPLICATION]: {
app: App
}
[Hooks.WALK_COMPONENT_TREE]: {
componentInstance: ComponentInstance
componentTreeData: ComponentTreeNode[]
maxDepth: number
filter: string
}
[Hooks.VISIT_COMPONENT_TREE]: {
app: App
componentInstance: ComponentInstance
treeNode: ComponentTreeNode
filter: string
}
[Hooks.WALK_COMPONENT_PARENTS]: {
componentInstance: ComponentInstance
parentInstances: ComponentInstance[]
}
[Hooks.INSPECT_COMPONENT]: {
app: App
componentInstance: ComponentInstance
instanceData: InspectedComponentData
}
[Hooks.GET_COMPONENT_BOUNDS]: {
componentInstance: ComponentInstance
bounds: ComponentBounds
}
[Hooks.GET_COMPONENT_NAME]: {
componentInstance: ComponentInstance
name: string
}
[Hooks.GET_COMPONENT_INSTANCES]: {
app: App
componentInstances: ComponentInstance[]
}
[Hooks.GET_ELEMENT_COMPONENT]: {
element: HTMLElement | any
componentInstance: ComponentInstance
}
[Hooks.GET_COMPONENT_ROOT_ELEMENTS]: {
componentInstance: ComponentInstance
rootElements: (HTMLElement | any)[]
}
[Hooks.EDIT_COMPONENT_STATE]: {
app: App
componentInstance: ComponentInstance
path: string[]
type: string
state: EditStatePayload
set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void
}
[Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS]: {
componentInstance: ComponentInstance
options: ComponentDevtoolsOptions
}
[Hooks.GET_COMPONENT_RENDER_CODE]: {
componentInstance: ComponentInstance
code: string
}
[Hooks.INSPECT_TIMELINE_EVENT]: {
app: App
layerId: string
event: TimelineEvent
all?: boolean
data: any
}
[Hooks.TIMELINE_CLEARED]: Record<string, never>
[Hooks.GET_INSPECTOR_TREE]: {
app: App
inspectorId: string
filter: string
rootNodes: CustomInspectorNode[]
}
[Hooks.GET_INSPECTOR_STATE]: {
app: App
inspectorId: string
nodeId: string
state: CustomInspectorState
}
[Hooks.EDIT_INSPECTOR_STATE]: {
app: App
inspectorId: string
nodeId: string
path: string[]
type: string
state: EditStatePayload
set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void
}
[Hooks.SET_PLUGIN_SETTINGS]: {
app: App
pluginId: string
key: string
newValue: any
oldValue: any
settings: any
}
}
export type EditStatePayload = {
value: any
newKey?: string | null
remove?: undefined | false
} | {
value?: undefined
newKey?: undefined
remove: true
}
export type HookHandler<TPayload, TContext> = (payload: TPayload, ctx: TContext) => void | Promise<void>
export interface Hookable<TContext> {
transformCall (handler: HookHandler<HookPayloads[Hooks.TRANSFORM_CALL], TContext>)
getAppRecordName (handler: HookHandler<HookPayloads[Hooks.GET_APP_RECORD_NAME], TContext>)
getAppRootInstance (handler: HookHandler<HookPayloads[Hooks.GET_APP_ROOT_INSTANCE], TContext>)
registerApplication (handler: HookHandler<HookPayloads[Hooks.REGISTER_APPLICATION], TContext>)
walkComponentTree (handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_TREE], TContext>)
visitComponentTree (handler: HookHandler<HookPayloads[Hooks.VISIT_COMPONENT_TREE], TContext>)
walkComponentParents (handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_PARENTS], TContext>)
inspectComponent (handler: HookHandler<HookPayloads[Hooks.INSPECT_COMPONENT], TContext>)
getComponentBounds (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_BOUNDS], TContext>)
getComponentName (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_NAME], TContext>)
getComponentInstances (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_INSTANCES], TContext>)
getElementComponent (handler: HookHandler<HookPayloads[Hooks.GET_ELEMENT_COMPONENT], TContext>)
getComponentRootElements (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_ROOT_ELEMENTS], TContext>)
editComponentState (handler: HookHandler<HookPayloads[Hooks.EDIT_COMPONENT_STATE], TContext>)
getComponentDevtoolsOptions (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS], TContext>)
getComponentRenderCode (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_RENDER_CODE], TContext>)
inspectTimelineEvent (handler: HookHandler<HookPayloads[Hooks.INSPECT_TIMELINE_EVENT], TContext>)
timelineCleared (handler: HookHandler<HookPayloads[Hooks.TIMELINE_CLEARED], TContext>)
getInspectorTree (handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_TREE], TContext>)
getInspectorState (handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_STATE], TContext>)
editInspectorState (handler: HookHandler<HookPayloads[Hooks.EDIT_INSPECTOR_STATE], TContext>)
setPluginSettings (handler: HookHandler<HookPayloads[Hooks.SET_PLUGIN_SETTINGS], TContext>)
}