1
1
import { setupDevtoolsPlugin } from '@vue/devtools-api'
2
- import { computed } from 'vue'
2
+ import { computed , watch } from 'vue'
3
3
import type { ClientData } from 'vuepress/client'
4
4
import { clientDataSymbol , defineClientConfig } from 'vuepress/client'
5
5
import {
@@ -8,6 +8,14 @@ import {
8
8
useThemeData ,
9
9
} from './composables/index.js'
10
10
11
+ const PLUGIN_ID = 'org.vuejs.vuepress.plugin-theme-data'
12
+ const PLUGIN_LABEL = 'VuePress Theme Data'
13
+ const PLUGIN_COMPONENT_STATE_TYPE = PLUGIN_LABEL
14
+ const INSPECTOR_ID = 'org.vuejs.vuepress'
15
+ const INSPECTOR_LABEL = 'VuePress'
16
+ const INSPECTOR_CLIENT_DATA_ID = 'client-data'
17
+ const INSPECTOR_CLIENT_DATA_LABEL = 'Client Data'
18
+
11
19
export default defineClientConfig ( {
12
20
enhance ( { app } ) {
13
21
// provide theme data & theme locale data
@@ -38,14 +46,13 @@ export default defineClientConfig({
38
46
setupDevtoolsPlugin (
39
47
{
40
48
// fix recursive reference
41
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
42
- app : app as any ,
43
- id : 'org.vuejs.vuepress.plugin-theme-data' ,
44
- label : 'VuePress Theme Data Plugin' ,
49
+ app : app as never ,
50
+ id : PLUGIN_ID ,
51
+ label : PLUGIN_LABEL ,
45
52
packageName : '@vuepress/plugin-theme-data' ,
46
- homepage : 'https://v2. vuepress.vuejs.org' ,
47
- logo : 'https://v2. vuepress.vuejs.org/images/hero.png' ,
48
- componentStateTypes : [ 'VuePress' ] ,
53
+ homepage : 'https://vuepress.vuejs.org' ,
54
+ logo : 'https://vuepress.vuejs.org/images/hero.png' ,
55
+ componentStateTypes : [ PLUGIN_COMPONENT_STATE_TYPE ] ,
49
56
} ,
50
57
( api ) => {
51
58
api . on . inspectComponent ( ( payload ) => {
@@ -64,6 +71,66 @@ export default defineClientConfig({
64
71
} ,
65
72
)
66
73
} )
74
+
75
+ // setup custom inspector
76
+ api . addInspector ( {
77
+ id : INSPECTOR_ID ,
78
+ label : INSPECTOR_LABEL ,
79
+ icon : 'article' ,
80
+ } )
81
+ api . on . getInspectorTree ( ( payload ) => {
82
+ if ( payload . inspectorId !== INSPECTOR_ID ) return
83
+
84
+ payload . rootNodes
85
+ . find ( ( item ) => item . id === INSPECTOR_CLIENT_DATA_ID )
86
+ ?. children ! . push (
87
+ {
88
+ id : 'themeData' ,
89
+ label : 'themeData' ,
90
+ } ,
91
+ {
92
+ id : 'themeLocaleData' ,
93
+ label : 'themeLocaleData' ,
94
+ } ,
95
+ )
96
+ } )
97
+
98
+ api . on . getInspectorState ( ( payload ) => {
99
+ if ( payload . inspectorId !== INSPECTOR_ID ) return
100
+
101
+ if ( payload . nodeId === INSPECTOR_CLIENT_DATA_ID ) {
102
+ payload . state [ INSPECTOR_CLIENT_DATA_LABEL ] . push (
103
+ {
104
+ key : 'themeData' ,
105
+ value : themeData . value ,
106
+ } ,
107
+ {
108
+ key : 'themeLocaleData' ,
109
+ value : themeLocaleData . value ,
110
+ } ,
111
+ )
112
+ }
113
+
114
+ if ( [ 'themeData' , 'themeLocaleData' ] . includes ( payload . nodeId ) ) {
115
+ payload . state = {
116
+ [ INSPECTOR_CLIENT_DATA_LABEL ] : [
117
+ {
118
+ key : payload . nodeId ,
119
+ value :
120
+ payload . nodeId === 'themeData'
121
+ ? themeData . value
122
+ : themeLocaleData . value ,
123
+ } ,
124
+ ] ,
125
+ }
126
+ }
127
+ } )
128
+
129
+ // refresh the component state and inspector state
130
+ watch ( [ themeData , themeLocaleData ] , ( ) => {
131
+ api . notifyComponentUpdate ( )
132
+ api . sendInspectorState ( INSPECTOR_ID )
133
+ } )
67
134
} ,
68
135
)
69
136
}
0 commit comments