@@ -17,7 +17,6 @@ import type { App } from 'vue'
17
17
import type {
18
18
DevtoolsPluginApi ,
19
19
InspectedComponentData ,
20
- CustomInspectorNode ,
21
20
CustomInspectorState ,
22
21
ComponentStateBase ,
23
22
HookPayloads
@@ -34,43 +33,6 @@ type _I18n<
34
33
Legacy extends boolean
35
34
> = I18n < Messages , DateTimeFormats , NumberFormats , Legacy > & I18nInternal
36
35
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
-
74
36
let devtoolsApi : DevtoolsPluginApi
75
37
76
38
export async function enableDevTools <
@@ -96,7 +58,8 @@ export async function enableDevTools<
96
58
api . on . walkComponentTree ( ( payload , ctx ) => {
97
59
updateComponentTreeDataTags (
98
60
ctx . currentAppRecord ,
99
- payload . componentTreeData
61
+ payload . componentTreeData ,
62
+ i18n
100
63
)
101
64
} )
102
65
@@ -106,10 +69,23 @@ export async function enableDevTools<
106
69
componentInstance . vnode . el . __INTLIFY__ &&
107
70
payload . instanceData
108
71
) {
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
+ }
113
89
}
114
90
} )
115
91
@@ -155,23 +131,36 @@ export async function enableDevTools<
155
131
} )
156
132
}
157
133
158
- function updateComponentTreeDataTags (
134
+ function updateComponentTreeDataTags <
135
+ Messages ,
136
+ DateTimeFormats ,
137
+ NumberFormats ,
138
+ Legacy extends boolean
139
+ > (
159
140
appRecord : AppRecord ,
160
- treeData : ComponentTreeNode
141
+ treeData : ComponentTreeNode ,
142
+ i18n : _I18n < Messages , DateTimeFormats , NumberFormats , Legacy >
161
143
) : void {
162
144
const instance = appRecord . instanceMap . get ( treeData . id )
163
145
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 ]
170
160
}
171
- treeData . tags = [ tag ]
172
161
}
173
162
for ( const node of treeData . children ) {
174
- updateComponentTreeDataTags ( appRecord , node )
163
+ updateComponentTreeDataTags ( appRecord , node , i18n )
175
164
}
176
165
}
177
166
@@ -275,26 +264,31 @@ function registerScope<
275
264
payload : HookPayloads [ Hooks . GET_INSPECTOR_TREE ] ,
276
265
i18n : _I18n < Messages , DateTimeFormats , NumberFormats , Legacy >
277
266
) : 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
279
275
for ( const [ keyInstance , instance ] of i18n . __instances ) {
280
276
// prettier-ignore
281
277
const composer = i18n . mode === 'composition'
282
278
? instance
283
279
: ( instance as unknown as VueI18nInternal ) . __composer
280
+ if ( global === composer ) {
281
+ continue
282
+ }
284
283
const label =
285
284
keyInstance . type . name ||
286
285
keyInstance . type . displayName ||
287
286
keyInstance . type . __file
288
- children . push ( {
287
+ payload . rootNodes . push ( {
289
288
id : composer . id . toString ( ) ,
290
289
label : `${ label } Scope`
291
290
} )
292
291
}
293
- payload . rootNodes . push ( {
294
- id : 'global' ,
295
- label : 'Global Scope' ,
296
- children
297
- } )
298
292
}
299
293
300
294
function inspectScope <
0 commit comments