Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42a3474

Browse files
committed
fix(plugin-theme-data): fix devtools plugin
1 parent 57bf3dd commit 42a3474

File tree

1 file changed

+75
-8
lines changed
  • plugins/development/plugin-theme-data/src/client

1 file changed

+75
-8
lines changed

plugins/development/plugin-theme-data/src/client/config.ts

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { setupDevtoolsPlugin } from '@vue/devtools-api'
2-
import { computed } from 'vue'
2+
import { computed, watch } from 'vue'
33
import type { ClientData } from 'vuepress/client'
44
import { clientDataSymbol, defineClientConfig } from 'vuepress/client'
55
import {
@@ -8,6 +8,14 @@ import {
88
useThemeData,
99
} from './composables/index.js'
1010

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+
1119
export default defineClientConfig({
1220
enhance({ app }) {
1321
// provide theme data & theme locale data
@@ -38,14 +46,13 @@ export default defineClientConfig({
3846
setupDevtoolsPlugin(
3947
{
4048
// 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,
4552
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],
4956
},
5057
(api) => {
5158
api.on.inspectComponent((payload) => {
@@ -64,6 +71,66 @@ export default defineClientConfig({
6471
},
6572
)
6673
})
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+
})
67134
},
68135
)
69136
}

0 commit comments

Comments
 (0)