@@ -17,7 +17,6 @@ import type { App } from 'vue'
1717import type {
1818 DevtoolsPluginApi ,
1919 InspectedComponentData ,
20- CustomInspectorNode ,
2120 CustomInspectorState ,
2221 ComponentStateBase ,
2322 HookPayloads
@@ -34,43 +33,6 @@ type _I18n<
3433 Legacy extends boolean
3534> = I18n < Messages , DateTimeFormats , NumberFormats , Legacy > & I18nInternal
3635
37- interface I18nRecord {
38- id : number
39- version : string
40- }
41-
42- const enum DevtoolsHooks {
43- REGISTER = 'intlify:register'
44- }
45-
46- interface DevtoolsHook {
47- emit ( event : string , ...payload : unknown [ ] ) : void
48- on ( event : string , handler : Function ) : void
49- off ( event : string , handler : Function ) : void
50- i18nRecords : I18nRecord [ ]
51- }
52-
53- export let devtools : DevtoolsHook
54-
55- export function setDevtoolsHook ( hook : DevtoolsHook ) : void {
56- devtools = hook
57- }
58-
59- export function devtoolsRegisterI18n <
60- Messages ,
61- DateTimeFormats ,
62- NumberFormats ,
63- Legacy extends boolean
64- > (
65- i18n : I18n < Messages , DateTimeFormats , NumberFormats , Legacy > ,
66- version : string
67- ) : void {
68- if ( ! devtools ) {
69- return
70- }
71- devtools . emit ( DevtoolsHooks . REGISTER , i18n , version )
72- }
73-
7436let devtoolsApi : DevtoolsPluginApi
7537
7638export async function enableDevTools <
@@ -96,7 +58,8 @@ export async function enableDevTools<
9658 api . on . walkComponentTree ( ( payload , ctx ) => {
9759 updateComponentTreeDataTags (
9860 ctx . currentAppRecord ,
99- payload . componentTreeData
61+ payload . componentTreeData ,
62+ i18n
10063 )
10164 } )
10265
@@ -106,10 +69,23 @@ export async function enableDevTools<
10669 componentInstance . vnode . el . __INTLIFY__ &&
10770 payload . instanceData
10871 ) {
109- inspectComposer (
110- payload . instanceData ,
111- componentInstance . vnode . el . __INTLIFY__ as Composer
112- )
72+ if ( i18n . mode === 'legacy' ) {
73+ // ignore global scope on legacy mode
74+ if (
75+ componentInstance . vnode . el . __INTLIFY__ !==
76+ ( ( i18n . global as unknown ) as VueI18nInternal ) . __composer
77+ ) {
78+ inspectComposer (
79+ payload . instanceData ,
80+ componentInstance . vnode . el . __INTLIFY__ as Composer
81+ )
82+ }
83+ } else {
84+ inspectComposer (
85+ payload . instanceData ,
86+ componentInstance . vnode . el . __INTLIFY__ as Composer
87+ )
88+ }
11389 }
11490 } )
11591
@@ -155,23 +131,36 @@ export async function enableDevTools<
155131 } )
156132}
157133
158- function updateComponentTreeDataTags (
134+ function updateComponentTreeDataTags <
135+ Messages ,
136+ DateTimeFormats ,
137+ NumberFormats ,
138+ Legacy extends boolean
139+ > (
159140 appRecord : AppRecord ,
160- treeData : ComponentTreeNode
141+ treeData : ComponentTreeNode ,
142+ i18n : _I18n < Messages , DateTimeFormats , NumberFormats , Legacy >
161143) : void {
162144 const instance = appRecord . instanceMap . get ( treeData . id )
163145 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
146+ // prettier-ignore
147+ const global = i18n . mode === 'composition'
148+ ? i18n . global
149+ : ( i18n . global as unknown as VueI18nInternal ) . __composer
150+ // add custom tags local scope only
151+ if ( instance . vnode . el . __INTLIFY__ !== global ) {
152+ const label =
153+ instance . type . name || instance . type . displayName || instance . type . __file
154+ const tag = {
155+ label : `i18n (${ label } Scope)` ,
156+ textColor : 0x000000 ,
157+ backgroundColor : 0xffcd19
158+ }
159+ treeData . tags = [ tag ]
170160 }
171- treeData . tags = [ tag ]
172161 }
173162 for ( const node of treeData . children ) {
174- updateComponentTreeDataTags ( appRecord , node )
163+ updateComponentTreeDataTags ( appRecord , node , i18n )
175164 }
176165}
177166
@@ -275,26 +264,31 @@ function registerScope<
275264 payload : HookPayloads [ Hooks . GET_INSPECTOR_TREE ] ,
276265 i18n : _I18n < Messages , DateTimeFormats , NumberFormats , Legacy >
277266) : void {
278- const children : CustomInspectorNode [ ] = [ ]
267+ payload . rootNodes . push ( {
268+ id : 'global' ,
269+ label : 'Global Scope'
270+ } )
271+ // prettier-ignore
272+ const global = i18n . mode === 'composition'
273+ ? i18n . global
274+ : ( i18n . global as unknown as VueI18nInternal ) . __composer
279275 for ( const [ keyInstance , instance ] of i18n . __instances ) {
280276 // prettier-ignore
281277 const composer = i18n . mode === 'composition'
282278 ? instance
283279 : ( instance as unknown as VueI18nInternal ) . __composer
280+ if ( global === composer ) {
281+ continue
282+ }
284283 const label =
285284 keyInstance . type . name ||
286285 keyInstance . type . displayName ||
287286 keyInstance . type . __file
288- children . push ( {
287+ payload . rootNodes . push ( {
289288 id : composer . id . toString ( ) ,
290289 label : `${ label } Scope`
291290 } )
292291 }
293- payload . rootNodes . push ( {
294- id : 'global' ,
295- label : 'Global Scope' ,
296- children
297- } )
298292}
299293
300294function inspectScope <
0 commit comments