1
- import { setupDevtoolsPlugin , Hooks } from '@vue/devtools-api'
1
+ import {
2
+ setupDevtoolsPlugin ,
3
+ Hooks ,
4
+ AppRecord ,
5
+ ComponentTreeNode
6
+ } from '@vue/devtools-api'
2
7
import {
3
8
DevToolsIDs ,
4
9
DevToolsTimelineColors ,
5
10
DevToolsLabels ,
6
11
DevToolsPlaceholders ,
7
- DevToolsTimelineEvents ,
8
- DevToolsTimelineLayerMaps
12
+ DevToolsTimelineEvents
9
13
} from '@intlify/core-base'
10
14
import { isFunction , isObject } from '@intlify/shared'
11
15
@@ -89,6 +93,13 @@ export async function enableDevTools<
89
93
api => {
90
94
devtoolsApi = api
91
95
96
+ api . on . walkComponentTree ( ( payload , ctx ) => {
97
+ updateComponentTreeDataTags (
98
+ ctx . currentAppRecord ,
99
+ payload . componentTreeData
100
+ )
101
+ } )
102
+
92
103
api . on . inspectComponent ( payload => {
93
104
const componentInstance = payload . componentInstance
94
105
if (
@@ -129,27 +140,9 @@ export async function enableDevTools<
129
140
} )
130
141
131
142
api . addTimelineLayer ( {
132
- id : DevToolsIDs . TIMELINE_COMPILE_ERROR ,
133
- label : DevToolsLabels [ DevToolsIDs . TIMELINE_COMPILE_ERROR ] ,
134
- color : DevToolsTimelineColors [ DevToolsIDs . TIMELINE_COMPILE_ERROR ]
135
- } )
136
-
137
- api . addTimelineLayer ( {
138
- id : DevToolsIDs . TIMELINE_PERFORMANCE ,
139
- label : DevToolsLabels [ DevToolsIDs . TIMELINE_PERFORMANCE ] ,
140
- color : DevToolsTimelineColors [ DevToolsIDs . TIMELINE_PERFORMANCE ]
141
- } )
142
-
143
- api . addTimelineLayer ( {
144
- id : DevToolsIDs . TIMELINE_MISSING ,
145
- label : DevToolsLabels [ DevToolsIDs . TIMELINE_MISSING ] ,
146
- color : DevToolsTimelineColors [ DevToolsIDs . TIMELINE_MISSING ]
147
- } )
148
-
149
- api . addTimelineLayer ( {
150
- id : DevToolsIDs . TIMELINE_FALLBACK ,
151
- label : DevToolsLabels [ DevToolsIDs . TIMELINE_FALLBACK ] ,
152
- color : DevToolsTimelineColors [ DevToolsIDs . TIMELINE_FALLBACK ]
143
+ id : DevToolsIDs . TIMELINE ,
144
+ label : DevToolsLabels [ DevToolsIDs . TIMELINE ] ,
145
+ color : DevToolsTimelineColors [ DevToolsIDs . TIMELINE ]
153
146
} )
154
147
155
148
resolve ( true )
@@ -162,6 +155,26 @@ export async function enableDevTools<
162
155
} )
163
156
}
164
157
158
+ function updateComponentTreeDataTags (
159
+ appRecord : AppRecord ,
160
+ treeData : ComponentTreeNode
161
+ ) : void {
162
+ const instance = appRecord . instanceMap . get ( treeData . id )
163
+ if ( instance && instance . vnode . el . __INTLIFY__ ) {
164
+ const label =
165
+ instance . type . name || instance . type . displayName || instance . type . __file
166
+ const tag = {
167
+ label : `i18n (${ label } Scope)` ,
168
+ textColor : 0x000000 ,
169
+ backgroundColor : 0xffcd19
170
+ }
171
+ treeData . tags = [ tag ]
172
+ }
173
+ for ( const node of treeData . children ) {
174
+ updateComponentTreeDataTags ( appRecord , node )
175
+ }
176
+ }
177
+
165
178
function inspectComposer (
166
179
instanceData : InspectedComponentData ,
167
180
composer : Composer
@@ -386,12 +399,26 @@ export function addTimelineEvent(
386
399
payload ?: DevToolsTimelineEventPayloads [ DevToolsTimelineEvents ]
387
400
) : void {
388
401
if ( devtoolsApi ) {
402
+ let groupId : string | undefined
403
+ if ( payload && 'groupId' in payload ) {
404
+ groupId = payload . groupId
405
+ delete payload . groupId
406
+ }
389
407
devtoolsApi . addTimelineEvent ( {
390
- layerId : DevToolsTimelineLayerMaps [ event ] ,
408
+ layerId : DevToolsIDs . TIMELINE ,
391
409
event : {
410
+ title : event ,
411
+ groupId,
392
412
time : Date . now ( ) ,
393
413
meta : { } ,
394
- data : payload || { }
414
+ data : payload || { } ,
415
+ logType :
416
+ event === DevToolsTimelineEvents . COMPILE_ERROR
417
+ ? 'error'
418
+ : event === DevToolsTimelineEvents . FALBACK ||
419
+ event === DevToolsTimelineEvents . MISSING
420
+ ? 'warning'
421
+ : 'default'
395
422
}
396
423
} )
397
424
}
0 commit comments