1- import { setupDevtoolsPlugin , Hooks } from '@vue/devtools-api'
1+ import {
2+ setupDevtoolsPlugin ,
3+ Hooks ,
4+ AppRecord ,
5+ ComponentTreeNode
6+ } from '@vue/devtools-api'
27import {
38 DevToolsIDs ,
49 DevToolsTimelineColors ,
510 DevToolsLabels ,
611 DevToolsPlaceholders ,
7- DevToolsTimelineEvents ,
8- DevToolsTimelineLayerMaps
12+ DevToolsTimelineEvents
913} from '@intlify/core-base'
1014import { isFunction , isObject } from '@intlify/shared'
1115
@@ -89,6 +93,13 @@ export async function enableDevTools<
8993 api => {
9094 devtoolsApi = api
9195
96+ api . on . walkComponentTree ( ( payload , ctx ) => {
97+ updateComponentTreeDataTags (
98+ ctx . currentAppRecord ,
99+ payload . componentTreeData
100+ )
101+ } )
102+
92103 api . on . inspectComponent ( payload => {
93104 const componentInstance = payload . componentInstance
94105 if (
@@ -129,27 +140,9 @@ export async function enableDevTools<
129140 } )
130141
131142 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 ]
153146 } )
154147
155148 resolve ( true )
@@ -162,6 +155,26 @@ export async function enableDevTools<
162155 } )
163156}
164157
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+
165178function inspectComposer (
166179 instanceData : InspectedComponentData ,
167180 composer : Composer
@@ -386,12 +399,26 @@ export function addTimelineEvent(
386399 payload ?: DevToolsTimelineEventPayloads [ DevToolsTimelineEvents ]
387400) : void {
388401 if ( devtoolsApi ) {
402+ let groupId : string | undefined
403+ if ( payload && 'groupId' in payload ) {
404+ groupId = payload . groupId
405+ delete payload . groupId
406+ }
389407 devtoolsApi . addTimelineEvent ( {
390- layerId : DevToolsTimelineLayerMaps [ event ] ,
408+ layerId : DevToolsIDs . TIMELINE ,
391409 event : {
410+ title : event ,
411+ groupId,
392412 time : Date . now ( ) ,
393413 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'
395422 }
396423 } )
397424 }
0 commit comments