-
Notifications
You must be signed in to change notification settings - Fork 922
/
config.ts
88 lines (84 loc) · 2.37 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { setupDevtoolsPlugin } from '@vue/devtools-api'
import { defineClientConfig, routeLocaleSymbol } from '@vuepress/client'
import { ref, watch } from 'vue'
import {
resolveThemeLocaleData,
themeLocaleDataSymbol,
useThemeData,
} from './composables/index.js'
export default defineClientConfig({
enhance({ app }) {
// provide theme data & theme locale data
const themeData = useThemeData()
const routeLocale =
app._context.provides[routeLocaleSymbol as unknown as symbol]
const themeLocaleData = ref(
resolveThemeLocaleData(themeData.value, routeLocale.value)
)
watch(
() => routeLocale.value,
(newRouteLocale, oldRouteLocale) => {
if (newRouteLocale !== oldRouteLocale)
themeLocaleData.value = resolveThemeLocaleData(
themeData.value,
routeLocale.value
)
}
)
watch(
() => themeData.value,
() => {
themeLocaleData.value = resolveThemeLocaleData(
themeData.value,
routeLocale.value
)
}
)
app.provide(themeLocaleDataSymbol, themeLocaleData)
Object.defineProperties(app.config.globalProperties, {
$theme: {
get() {
return themeData.value
},
},
$themeLocale: {
get() {
return themeLocaleData.value
},
},
})
// setup devtools in dev mode
if (__VUEPRESS_DEV__ || __VUE_PROD_DEVTOOLS__) {
setupDevtoolsPlugin(
{
// fix recursive reference
app: app as any,
id: 'org.vuejs.vuepress.plugin-theme-data',
label: 'VuePress Theme Data Plugin',
packageName: '@vuepress/plugin-theme-data',
homepage: 'https://v2.vuepress.vuejs.org',
logo: 'https://v2.vuepress.vuejs.org/images/hero.png',
componentStateTypes: ['VuePress'],
},
(api) => {
api.on.inspectComponent((payload) => {
payload.instanceData.state.push(
{
type: 'VuePress',
key: 'themeData',
editable: false,
value: themeData.value,
},
{
type: 'VuePress',
key: 'themeLocaleData',
editable: false,
value: themeLocaleData.value,
}
)
})
}
)
}
},
})