@vuepress/theme-default 2.0.0-rc.0 → 2.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/lib/client/components/AutoLink.vue +13 -19
- package/lib/client/components/HomeFeatures.vue +2 -3
- package/lib/client/components/HomeFooter.vue +1 -1
- package/lib/client/components/HomeHero.vue +4 -5
- package/lib/client/components/NavbarBrand.vue +16 -6
- package/lib/client/components/NavbarItems.vue +25 -20
- package/lib/client/components/PageMeta.vue +1 -1
- package/lib/client/components/PageNav.vue +27 -8
- package/lib/client/components/global/CodeGroup.d.ts +1 -1
- package/lib/client/components/global/CodeGroup.js +6 -6
- package/lib/client/components/global/CodeGroupItem.vue +3 -7
- package/lib/client/composables/index.d.ts +0 -2
- package/lib/client/composables/index.js +0 -2
- package/lib/client/composables/useSidebarItems.d.ts +5 -5
- package/lib/client/composables/useSidebarItems.js +24 -25
- package/lib/client/config.d.ts +2 -1
- package/lib/client/config.js +8 -4
- package/lib/client/index.d.ts +1 -1
- package/lib/client/index.js +0 -1
- package/lib/client/layouts/Layout.vue +1 -1
- package/lib/client/layouts/NotFound.vue +2 -2
- package/lib/client/styles/code-group.scss +4 -11
- package/lib/client/styles/code.scss +1 -1
- package/lib/client/styles/layout.scss +1 -1
- package/lib/client/styles/normalize.scss +24 -24
- package/lib/client/styles/vars.scss +17 -1
- package/lib/client/{composables/useNavLink.d.ts → utils/getNavLink.d.ts} +1 -6
- package/lib/client/utils/getNavLink.js +17 -0
- package/lib/client/utils/index.d.ts +1 -0
- package/lib/client/utils/index.js +1 -0
- package/lib/client/utils/resolveEditLink.js +1 -1
- package/lib/client/utils/resolveRepoType.js +1 -1
- package/lib/node/defaultTheme.d.ts +6 -2
- package/lib/node/defaultTheme.js +33 -3
- package/lib/node/index.d.ts +2 -1
- package/lib/node/index.js +1 -1
- package/lib/shared/nav.d.ts +2 -1
- package/lib/shared/options.d.ts +33 -2
- package/package.json +32 -29
- package/templates/build.html +13 -10
- package/lib/client/composables/useNavLink.js +0 -18
- package/lib/client/composables/useResolveRouteWithRedirect.d.ts +0 -5
- package/lib/client/composables/useResolveRouteWithRedirect.js +0 -24
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2018-present,
|
|
3
|
+
Copyright (c) 2018-present, VuePress Community
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
/* eslint-disable import/first, import/no-duplicates, import/order */
|
|
3
|
-
import { defineComponent } from 'vue'
|
|
4
|
-
|
|
5
|
-
export default defineComponent({
|
|
6
|
-
inheritAttrs: false,
|
|
7
|
-
})
|
|
8
|
-
/* eslint-enable import/order */
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
1
|
<script setup lang="ts">
|
|
12
|
-
import { useSiteData } from '@vuepress/client'
|
|
13
|
-
import { isLinkHttp, isLinkWithProtocol } from '@vuepress/shared'
|
|
14
2
|
import { computed, toRefs } from 'vue'
|
|
15
3
|
import type { PropType } from 'vue'
|
|
16
4
|
import { useRoute } from 'vue-router'
|
|
5
|
+
import { useSiteData } from 'vuepress/client'
|
|
6
|
+
import { isLinkHttp, isLinkWithProtocol } from 'vuepress/shared'
|
|
17
7
|
import type { NavLink } from '../../shared/index.js'
|
|
18
8
|
|
|
9
|
+
defineOptions({
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
})
|
|
12
|
+
|
|
19
13
|
const props = defineProps({
|
|
20
14
|
item: {
|
|
21
15
|
type: Object as PropType<NavLink>,
|
|
@@ -47,8 +41,8 @@ const linkTarget = computed(() => {
|
|
|
47
41
|
})
|
|
48
42
|
// if the `target` attr is '_blank'
|
|
49
43
|
const isBlankTarget = computed(() => linkTarget.value === '_blank')
|
|
50
|
-
// is `<
|
|
51
|
-
const
|
|
44
|
+
// is `<RouteLink>` or not
|
|
45
|
+
const isRouteLink = computed(
|
|
52
46
|
() =>
|
|
53
47
|
!hasHttpProtocol.value && !hasNonHttpProtocol.value && !isBlankTarget.value,
|
|
54
48
|
)
|
|
@@ -80,7 +74,7 @@ const isActiveInSubpath = computed(() => {
|
|
|
80
74
|
|
|
81
75
|
// if this link is active
|
|
82
76
|
const isActive = computed(() => {
|
|
83
|
-
if (!
|
|
77
|
+
if (!isRouteLink.value) {
|
|
84
78
|
return false
|
|
85
79
|
}
|
|
86
80
|
if (item.value.activeMatch) {
|
|
@@ -91,9 +85,9 @@ const isActive = computed(() => {
|
|
|
91
85
|
</script>
|
|
92
86
|
|
|
93
87
|
<template>
|
|
94
|
-
<
|
|
95
|
-
v-if="
|
|
96
|
-
:
|
|
88
|
+
<RouteLink
|
|
89
|
+
v-if="isRouteLink"
|
|
90
|
+
:active="isActive"
|
|
97
91
|
:to="item.link"
|
|
98
92
|
:aria-label="linkAriaLabel"
|
|
99
93
|
v-bind="$attrs"
|
|
@@ -101,7 +95,7 @@ const isActive = computed(() => {
|
|
|
101
95
|
<slot name="before" />
|
|
102
96
|
{{ item.text }}
|
|
103
97
|
<slot name="after" />
|
|
104
|
-
</
|
|
98
|
+
</RouteLink>
|
|
105
99
|
<a
|
|
106
100
|
v-else
|
|
107
101
|
class="external-link"
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { usePageFrontmatter } from '@vuepress/client'
|
|
3
|
-
import { isArray } from '@vuepress/shared'
|
|
4
2
|
import { computed } from 'vue'
|
|
3
|
+
import { usePageFrontmatter } from 'vuepress/client'
|
|
5
4
|
import type { DefaultThemeHomePageFrontmatter } from '../../shared/index.js'
|
|
6
5
|
|
|
7
6
|
const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
|
|
8
7
|
const features = computed(() => {
|
|
9
|
-
if (isArray(frontmatter.value.features)) {
|
|
8
|
+
if (Array.isArray(frontmatter.value.features)) {
|
|
10
9
|
return frontmatter.value.features
|
|
11
10
|
}
|
|
12
11
|
return []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { usePageFrontmatter } from '@vuepress/client'
|
|
3
2
|
import { computed } from 'vue'
|
|
3
|
+
import { usePageFrontmatter } from 'vuepress/client'
|
|
4
4
|
import type { DefaultThemeHomePageFrontmatter } from '../../shared/index.js'
|
|
5
5
|
|
|
6
6
|
const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import AutoLink from '@theme/AutoLink.vue'
|
|
3
|
+
import type { FunctionalComponent } from 'vue'
|
|
4
|
+
import { computed, h } from 'vue'
|
|
3
5
|
import {
|
|
4
6
|
ClientOnly,
|
|
5
7
|
usePageFrontmatter,
|
|
6
8
|
useSiteLocaleData,
|
|
7
9
|
withBase,
|
|
8
|
-
} from '
|
|
9
|
-
import { isArray } from '@vuepress/shared'
|
|
10
|
-
import type { FunctionalComponent } from 'vue'
|
|
11
|
-
import { computed, h } from 'vue'
|
|
10
|
+
} from 'vuepress/client'
|
|
12
11
|
import type { DefaultThemeHomePageFrontmatter } from '../../shared/index.js'
|
|
13
12
|
import { useDarkMode } from '../composables/index.js'
|
|
14
13
|
|
|
@@ -46,7 +45,7 @@ const tagline = computed(() => {
|
|
|
46
45
|
})
|
|
47
46
|
|
|
48
47
|
const actions = computed(() => {
|
|
49
|
-
if (!isArray(frontmatter.value.actions)) {
|
|
48
|
+
if (!Array.isArray(frontmatter.value.actions)) {
|
|
50
49
|
return []
|
|
51
50
|
}
|
|
52
51
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed, h } from 'vue'
|
|
3
|
+
import type { FunctionalComponent } from 'vue'
|
|
2
4
|
import {
|
|
3
5
|
ClientOnly,
|
|
6
|
+
RouteLink,
|
|
4
7
|
useRouteLocale,
|
|
5
8
|
useSiteLocaleData,
|
|
6
9
|
withBase,
|
|
7
|
-
} from '
|
|
8
|
-
import { computed, h } from 'vue'
|
|
9
|
-
import type { FunctionalComponent } from 'vue'
|
|
10
|
+
} from 'vuepress/client'
|
|
10
11
|
import { useDarkMode, useThemeLocaleData } from '../composables/index.js'
|
|
11
12
|
|
|
12
13
|
const routeLocale = useRouteLocale()
|
|
@@ -24,12 +25,20 @@ const navbarBrandLogo = computed(() => {
|
|
|
24
25
|
}
|
|
25
26
|
return themeLocale.value.logo
|
|
26
27
|
})
|
|
28
|
+
const navbarBrandLogoAlt = computed(
|
|
29
|
+
() => themeLocale.value.logoAlt ?? navbarBrandTitle.value,
|
|
30
|
+
)
|
|
31
|
+
const navBarLogoAltMatchesTitle = computed(
|
|
32
|
+
() =>
|
|
33
|
+
navbarBrandTitle.value.toLocaleUpperCase().trim() ===
|
|
34
|
+
navbarBrandLogoAlt.value.toLocaleUpperCase().trim(),
|
|
35
|
+
)
|
|
27
36
|
const NavbarBrandLogo: FunctionalComponent = () => {
|
|
28
37
|
if (!navbarBrandLogo.value) return null
|
|
29
38
|
const img = h('img', {
|
|
30
39
|
class: 'logo',
|
|
31
40
|
src: withBase(navbarBrandLogo.value),
|
|
32
|
-
alt:
|
|
41
|
+
alt: navbarBrandLogoAlt.value,
|
|
33
42
|
})
|
|
34
43
|
if (themeLocale.value.logoDark === undefined) {
|
|
35
44
|
return img
|
|
@@ -41,15 +50,16 @@ const NavbarBrandLogo: FunctionalComponent = () => {
|
|
|
41
50
|
</script>
|
|
42
51
|
|
|
43
52
|
<template>
|
|
44
|
-
<
|
|
53
|
+
<RouteLink :to="navbarBrandLink">
|
|
45
54
|
<NavbarBrandLogo />
|
|
46
55
|
|
|
47
56
|
<span
|
|
48
57
|
v-if="navbarBrandTitle"
|
|
49
58
|
class="site-name"
|
|
50
59
|
:class="{ 'can-hide': navbarBrandLogo }"
|
|
60
|
+
:aria-hidden="navBarLogoAltMatchesTitle"
|
|
51
61
|
>
|
|
52
62
|
{{ navbarBrandTitle }}
|
|
53
63
|
</span>
|
|
54
|
-
</
|
|
64
|
+
</RouteLink>
|
|
55
65
|
</template>
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import AutoLink from '@theme/AutoLink.vue'
|
|
3
3
|
import NavbarDropdown from '@theme/NavbarDropdown.vue'
|
|
4
|
-
import {
|
|
5
|
-
useRouteLocale,
|
|
6
|
-
useSiteData,
|
|
7
|
-
useSiteLocaleData,
|
|
8
|
-
} from '@vuepress/client'
|
|
9
|
-
import { isLinkHttp, isString } from '@vuepress/shared'
|
|
4
|
+
import { useRoutePaths } from '@vuepress/helper/client'
|
|
10
5
|
import { computed, ref } from 'vue'
|
|
11
6
|
import type { ComputedRef } from 'vue'
|
|
12
|
-
import {
|
|
7
|
+
import { useRoute } from 'vue-router'
|
|
8
|
+
import { useRouteLocale, useSiteData, useSiteLocaleData } from 'vuepress/client'
|
|
9
|
+
import { isLinkHttp, isString } from 'vuepress/shared'
|
|
13
10
|
import type {
|
|
14
11
|
NavbarGroup,
|
|
15
12
|
NavbarItem,
|
|
@@ -17,18 +14,18 @@ import type {
|
|
|
17
14
|
} from '../../shared/index.js'
|
|
18
15
|
import {
|
|
19
16
|
DeviceType,
|
|
20
|
-
useNavLink,
|
|
21
17
|
useThemeData,
|
|
22
18
|
useThemeLocaleData,
|
|
23
19
|
useUpdateDeviceStatus,
|
|
24
20
|
} from '../composables/index.js'
|
|
25
|
-
import { resolveRepoType } from '../utils/index.js'
|
|
21
|
+
import { getNavLink, resolveRepoType } from '../utils/index.js'
|
|
26
22
|
|
|
27
23
|
/**
|
|
28
24
|
* Get navbar config of select language dropdown
|
|
29
25
|
*/
|
|
30
26
|
const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
|
|
31
|
-
const
|
|
27
|
+
const route = useRoute()
|
|
28
|
+
const routePaths = useRoutePaths()
|
|
32
29
|
const routeLocale = useRouteLocale()
|
|
33
30
|
const site = useSiteData()
|
|
34
31
|
const siteLocale = useSiteLocaleData()
|
|
@@ -41,8 +38,8 @@ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
|
|
|
41
38
|
if (localePaths.length < 2) {
|
|
42
39
|
return []
|
|
43
40
|
}
|
|
44
|
-
const currentPath =
|
|
45
|
-
const currentFullPath =
|
|
41
|
+
const currentPath = route.path
|
|
42
|
+
const currentFullPath = route.fullPath
|
|
46
43
|
|
|
47
44
|
const languageDropdown: ResolvedNavbarItem = {
|
|
48
45
|
text: `${themeLocale.value.selectLanguageText}`,
|
|
@@ -71,9 +68,7 @@ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
|
|
|
71
68
|
routeLocale.value,
|
|
72
69
|
targetLocalePath,
|
|
73
70
|
)
|
|
74
|
-
if (
|
|
75
|
-
router.getRoutes().some((item) => item.path === targetLocalePage)
|
|
76
|
-
) {
|
|
71
|
+
if (routePaths.value.some((item) => item === targetLocalePage)) {
|
|
77
72
|
// try to keep current hash and params across languages
|
|
78
73
|
link = currentFullPath.replace(currentPath, targetLocalePage)
|
|
79
74
|
} else {
|
|
@@ -136,12 +131,14 @@ const resolveNavbarItem = (
|
|
|
136
131
|
item: NavbarItem | NavbarGroup | string,
|
|
137
132
|
): ResolvedNavbarItem => {
|
|
138
133
|
if (isString(item)) {
|
|
139
|
-
return
|
|
134
|
+
return getNavLink(item)
|
|
140
135
|
}
|
|
141
136
|
if ((item as NavbarGroup).children) {
|
|
142
137
|
return {
|
|
143
138
|
...item,
|
|
144
|
-
children: (item as NavbarGroup).children.map(
|
|
139
|
+
children: (item as NavbarGroup).children.map((item) =>
|
|
140
|
+
resolveNavbarItem(item),
|
|
141
|
+
),
|
|
145
142
|
}
|
|
146
143
|
}
|
|
147
144
|
return item as ResolvedNavbarItem
|
|
@@ -149,7 +146,10 @@ const resolveNavbarItem = (
|
|
|
149
146
|
|
|
150
147
|
const useNavbarConfig = (): ComputedRef<ResolvedNavbarItem[]> => {
|
|
151
148
|
const themeLocale = useThemeLocaleData()
|
|
152
|
-
|
|
149
|
+
|
|
150
|
+
return computed(() =>
|
|
151
|
+
(themeLocale.value.navbar || []).map((item) => resolveNavbarItem(item)),
|
|
152
|
+
)
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
const isMobile = ref(false)
|
|
@@ -173,13 +173,18 @@ useUpdateDeviceStatus(
|
|
|
173
173
|
}
|
|
174
174
|
},
|
|
175
175
|
)
|
|
176
|
+
|
|
177
|
+
const navbarLabel = computed(() => {
|
|
178
|
+
const themeLocale = useThemeLocaleData()
|
|
179
|
+
return themeLocale.value.navbarLabel ?? 'site navigation'
|
|
180
|
+
})
|
|
176
181
|
</script>
|
|
177
182
|
|
|
178
183
|
<template>
|
|
179
|
-
<nav v-if="navbarLinks.length" class="navbar-items">
|
|
184
|
+
<nav v-if="navbarLinks.length" class="navbar-items" :aria-label="navbarLabel">
|
|
180
185
|
<div v-for="item in navbarLinks" :key="item.text" class="navbar-item">
|
|
181
186
|
<NavbarDropdown
|
|
182
|
-
v-if="item
|
|
187
|
+
v-if="'children' in item"
|
|
183
188
|
:item="item"
|
|
184
189
|
:class="isMobile ? 'mobile' : ''"
|
|
185
190
|
/>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import AutoLink from '@theme/AutoLink.vue'
|
|
3
|
-
import { usePageData, usePageFrontmatter } from '@vuepress/client'
|
|
4
3
|
import { computed } from 'vue'
|
|
5
4
|
import type { ComputedRef } from 'vue'
|
|
5
|
+
import { usePageData, usePageFrontmatter } from 'vuepress/client'
|
|
6
6
|
import type {
|
|
7
7
|
DefaultThemeNormalPageFrontmatter,
|
|
8
8
|
DefaultThemePageData,
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import AutoLink from '@theme/AutoLink.vue'
|
|
3
|
-
import { usePageFrontmatter } from '@vuepress/client'
|
|
4
|
-
import { isPlainObject, isString } from '@vuepress/shared'
|
|
5
3
|
import { computed } from 'vue'
|
|
6
|
-
import {
|
|
4
|
+
import type { Router } from 'vue-router'
|
|
5
|
+
import { useRoute, useRouter } from 'vue-router'
|
|
6
|
+
import { usePageFrontmatter } from 'vuepress/client'
|
|
7
|
+
import { isPlainObject, isString } from 'vuepress/shared'
|
|
7
8
|
import type {
|
|
8
9
|
DefaultThemeNormalPageFrontmatter,
|
|
9
10
|
NavLink,
|
|
10
11
|
ResolvedSidebarItem,
|
|
11
12
|
} from '../../shared/index.js'
|
|
12
|
-
import {
|
|
13
|
+
import { useSidebarItems, useThemeLocaleData } from '../composables/index.js'
|
|
14
|
+
import { getNavLink } from '../utils/index.js'
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Resolve `prev` or `next` config from frontmatter
|
|
16
18
|
*/
|
|
17
19
|
const resolveFromFrontmatterConfig = (
|
|
20
|
+
router: Router,
|
|
18
21
|
conf: unknown,
|
|
19
22
|
): null | false | NavLink => {
|
|
20
23
|
if (conf === false) {
|
|
@@ -22,7 +25,7 @@ const resolveFromFrontmatterConfig = (
|
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
if (isString(conf)) {
|
|
25
|
-
return
|
|
28
|
+
return getNavLink(router, conf)
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
if (isPlainObject<NavLink>(conf)) {
|
|
@@ -68,9 +71,13 @@ const resolveFromSidebarItems = (
|
|
|
68
71
|
const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
|
|
69
72
|
const sidebarItems = useSidebarItems()
|
|
70
73
|
const route = useRoute()
|
|
74
|
+
const router = useRouter()
|
|
71
75
|
|
|
72
76
|
const prevNavLink = computed(() => {
|
|
73
|
-
const prevConfig = resolveFromFrontmatterConfig(
|
|
77
|
+
const prevConfig = resolveFromFrontmatterConfig(
|
|
78
|
+
router,
|
|
79
|
+
frontmatter.value.prev,
|
|
80
|
+
)
|
|
74
81
|
if (prevConfig !== false) {
|
|
75
82
|
return prevConfig
|
|
76
83
|
}
|
|
@@ -79,17 +86,29 @@ const prevNavLink = computed(() => {
|
|
|
79
86
|
})
|
|
80
87
|
|
|
81
88
|
const nextNavLink = computed(() => {
|
|
82
|
-
const nextConfig = resolveFromFrontmatterConfig(
|
|
89
|
+
const nextConfig = resolveFromFrontmatterConfig(
|
|
90
|
+
router,
|
|
91
|
+
frontmatter.value.next,
|
|
92
|
+
)
|
|
83
93
|
if (nextConfig !== false) {
|
|
84
94
|
return nextConfig
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
return resolveFromSidebarItems(sidebarItems.value, route.path, 1)
|
|
88
98
|
})
|
|
99
|
+
|
|
100
|
+
const navbarLabel = computed(() => {
|
|
101
|
+
const themeLocale = useThemeLocaleData()
|
|
102
|
+
return themeLocale.value.pageNavbarLabel ?? 'page navigation'
|
|
103
|
+
})
|
|
89
104
|
</script>
|
|
90
105
|
|
|
91
106
|
<template>
|
|
92
|
-
<nav
|
|
107
|
+
<nav
|
|
108
|
+
v-if="prevNavLink || nextNavLink"
|
|
109
|
+
class="page-nav"
|
|
110
|
+
:aria-label="navbarLabel"
|
|
111
|
+
>
|
|
93
112
|
<p class="inner">
|
|
94
113
|
<span v-if="prevNavLink" class="prev">
|
|
95
114
|
<AutoLink :item="prevNavLink" />
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SlotsType, VNode } from 'vue';
|
|
2
2
|
export declare const CodeGroup: import("vue").DefineComponent<{}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
3
3
|
[key: string]: any;
|
|
4
|
-
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").
|
|
4
|
+
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, SlotsType<{
|
|
5
5
|
default: () => VNode[];
|
|
6
6
|
}>>;
|
|
@@ -95,9 +95,9 @@ export const CodeGroup = defineComponent({
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
return h('div', { class: 'code-group' }, [
|
|
98
|
-
h('div', { class: 'code-group__nav'
|
|
98
|
+
h('div', { class: 'code-group__nav', role: 'tablist' }, items.map((vnode, i) => {
|
|
99
99
|
const isActive = i === activeIndex.value;
|
|
100
|
-
return h('
|
|
100
|
+
return h('button', {
|
|
101
101
|
ref: (element) => {
|
|
102
102
|
if (element) {
|
|
103
103
|
tabRefs.value[i] = element;
|
|
@@ -107,12 +107,12 @@ export const CodeGroup = defineComponent({
|
|
|
107
107
|
'code-group__nav-tab': true,
|
|
108
108
|
'code-group__nav-tab-active': isActive,
|
|
109
109
|
},
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
role: 'tab',
|
|
111
|
+
ariaSelected: isActive,
|
|
112
112
|
onClick: () => (activeIndex.value = i),
|
|
113
113
|
onKeydown: (e) => keyboardHandler(e, i),
|
|
114
|
-
}, vnode.props.title)
|
|
115
|
-
}))
|
|
114
|
+
}, vnode.props.title);
|
|
115
|
+
})),
|
|
116
116
|
items,
|
|
117
117
|
]);
|
|
118
118
|
};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export default defineComponent({
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineOptions({
|
|
5
3
|
name: 'CodeGroupItem',
|
|
6
4
|
})
|
|
7
|
-
</script>
|
|
8
5
|
|
|
9
|
-
<script setup lang="ts">
|
|
10
6
|
defineProps({
|
|
11
7
|
title: {
|
|
12
8
|
type: String,
|
|
@@ -24,7 +20,7 @@ defineProps({
|
|
|
24
20
|
<div
|
|
25
21
|
class="code-group-item"
|
|
26
22
|
:class="{ 'code-group-item__active': active }"
|
|
27
|
-
|
|
23
|
+
role="tabpanel"
|
|
28
24
|
>
|
|
29
25
|
<slot />
|
|
30
26
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PageHeader } from '@vuepress/client';
|
|
2
1
|
import type { ComputedRef, InjectionKey } from 'vue';
|
|
2
|
+
import type { PageData, PageHeader } from 'vuepress/client';
|
|
3
3
|
import type { DefaultThemeData, DefaultThemeNormalPageFrontmatter, ResolvedSidebarItem, SidebarConfigArray, SidebarConfigObject } from '../../shared/index.js';
|
|
4
4
|
export type SidebarItemsRef = ComputedRef<ResolvedSidebarItem[]>;
|
|
5
5
|
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
@@ -16,7 +16,7 @@ export declare const setupSidebarItems: () => void;
|
|
|
16
16
|
*
|
|
17
17
|
* It should only be resolved and provided once
|
|
18
18
|
*/
|
|
19
|
-
export declare const resolveSidebarItems: (frontmatter: DefaultThemeNormalPageFrontmatter, themeLocale: DefaultThemeData) => ResolvedSidebarItem[];
|
|
19
|
+
export declare const resolveSidebarItems: (frontmatter: DefaultThemeNormalPageFrontmatter, themeLocale: DefaultThemeData, page: PageData, path: string) => ResolvedSidebarItem[];
|
|
20
20
|
/**
|
|
21
21
|
* Util to transform page header to sidebar item
|
|
22
22
|
*/
|
|
@@ -25,12 +25,12 @@ export declare const headersToSidebarItemChildren: (headers: PageHeader[], sideb
|
|
|
25
25
|
/**
|
|
26
26
|
* Resolve sidebar items if the config is `auto`
|
|
27
27
|
*/
|
|
28
|
-
export declare const resolveAutoSidebarItems: (sidebarDepth: number) => ResolvedSidebarItem[];
|
|
28
|
+
export declare const resolveAutoSidebarItems: (page: PageData, sidebarDepth: number) => ResolvedSidebarItem[];
|
|
29
29
|
/**
|
|
30
30
|
* Resolve sidebar items if the config is an array
|
|
31
31
|
*/
|
|
32
|
-
export declare const resolveArraySidebarItems: (sidebarConfig: SidebarConfigArray, sidebarDepth: number) => ResolvedSidebarItem[];
|
|
32
|
+
export declare const resolveArraySidebarItems: (page: PageData, path: string, sidebarConfig: SidebarConfigArray, sidebarDepth: number) => ResolvedSidebarItem[];
|
|
33
33
|
/**
|
|
34
34
|
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
35
35
|
*/
|
|
36
|
-
export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarConfigObject, sidebarDepth: number) => ResolvedSidebarItem[];
|
|
36
|
+
export declare const resolveMultiSidebarItems: (page: PageData, path: string, sidebarConfig: SidebarConfigObject, sidebarDepth: number) => ResolvedSidebarItem[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { usePageData, usePageFrontmatter } from '@vuepress/client';
|
|
2
|
-
import { isArray, isPlainObject, isString, resolveLocalePath, } from '@vuepress/shared';
|
|
3
1
|
import { computed, inject, provide } from 'vue';
|
|
4
2
|
import { useRoute } from 'vue-router';
|
|
5
|
-
import {
|
|
3
|
+
import { usePageData, usePageFrontmatter } from 'vuepress/client';
|
|
4
|
+
import { isPlainObject, isString, resolveLocalePath } from 'vuepress/shared';
|
|
5
|
+
import { getNavLink } from '../utils/index.js';
|
|
6
6
|
import { useThemeLocaleData } from './useThemeData.js';
|
|
7
7
|
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
8
8
|
/**
|
|
@@ -21,7 +21,9 @@ export const useSidebarItems = () => {
|
|
|
21
21
|
export const setupSidebarItems = () => {
|
|
22
22
|
const themeLocale = useThemeLocaleData();
|
|
23
23
|
const frontmatter = usePageFrontmatter();
|
|
24
|
-
const
|
|
24
|
+
const page = usePageData();
|
|
25
|
+
const route = useRoute();
|
|
26
|
+
const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value, page.value, route.path));
|
|
25
27
|
provide(sidebarItemsSymbol, sidebarItems);
|
|
26
28
|
};
|
|
27
29
|
/**
|
|
@@ -29,7 +31,7 @@ export const setupSidebarItems = () => {
|
|
|
29
31
|
*
|
|
30
32
|
* It should only be resolved and provided once
|
|
31
33
|
*/
|
|
32
|
-
export const resolveSidebarItems = (frontmatter, themeLocale) => {
|
|
34
|
+
export const resolveSidebarItems = (frontmatter, themeLocale, page, path) => {
|
|
33
35
|
// get sidebar config from frontmatter > theme data
|
|
34
36
|
const sidebarConfig = frontmatter.sidebar ?? themeLocale.sidebar ?? 'auto';
|
|
35
37
|
const sidebarDepth = frontmatter.sidebarDepth ?? themeLocale.sidebarDepth ?? 2;
|
|
@@ -38,13 +40,13 @@ export const resolveSidebarItems = (frontmatter, themeLocale) => {
|
|
|
38
40
|
return [];
|
|
39
41
|
}
|
|
40
42
|
if (sidebarConfig === 'auto') {
|
|
41
|
-
return resolveAutoSidebarItems(sidebarDepth);
|
|
43
|
+
return resolveAutoSidebarItems(page, sidebarDepth);
|
|
42
44
|
}
|
|
43
|
-
if (isArray(sidebarConfig)) {
|
|
44
|
-
return resolveArraySidebarItems(sidebarConfig, sidebarDepth);
|
|
45
|
+
if (Array.isArray(sidebarConfig)) {
|
|
46
|
+
return resolveArraySidebarItems(page, path, sidebarConfig, sidebarDepth);
|
|
45
47
|
}
|
|
46
48
|
if (isPlainObject(sidebarConfig)) {
|
|
47
|
-
return resolveMultiSidebarItems(sidebarConfig, sidebarDepth);
|
|
49
|
+
return resolveMultiSidebarItems(page, path, sidebarConfig, sidebarDepth);
|
|
48
50
|
}
|
|
49
51
|
return [];
|
|
50
52
|
};
|
|
@@ -62,25 +64,22 @@ export const headersToSidebarItemChildren = (headers, sidebarDepth) => sidebarDe
|
|
|
62
64
|
/**
|
|
63
65
|
* Resolve sidebar items if the config is `auto`
|
|
64
66
|
*/
|
|
65
|
-
export const resolveAutoSidebarItems = (sidebarDepth) => {
|
|
66
|
-
const page = usePageData();
|
|
67
|
+
export const resolveAutoSidebarItems = (page, sidebarDepth) => {
|
|
67
68
|
return [
|
|
68
69
|
{
|
|
69
|
-
text: page.
|
|
70
|
-
children: headersToSidebarItemChildren(page.
|
|
70
|
+
text: page.title,
|
|
71
|
+
children: headersToSidebarItemChildren(page.headers, sidebarDepth),
|
|
71
72
|
},
|
|
72
73
|
];
|
|
73
74
|
};
|
|
74
75
|
/**
|
|
75
76
|
* Resolve sidebar items if the config is an array
|
|
76
77
|
*/
|
|
77
|
-
export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth) => {
|
|
78
|
-
const route = useRoute();
|
|
79
|
-
const page = usePageData();
|
|
78
|
+
export const resolveArraySidebarItems = (page, path, sidebarConfig, sidebarDepth) => {
|
|
80
79
|
const handleChildItem = (item) => {
|
|
81
80
|
let childItem;
|
|
82
81
|
if (isString(item)) {
|
|
83
|
-
childItem =
|
|
82
|
+
childItem = getNavLink(item);
|
|
84
83
|
}
|
|
85
84
|
else {
|
|
86
85
|
childItem = item;
|
|
@@ -93,11 +92,9 @@ export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth) => {
|
|
|
93
92
|
}
|
|
94
93
|
// if the sidebar item is current page and children is not set
|
|
95
94
|
// use headers of current page as children
|
|
96
|
-
if (childItem.link ===
|
|
95
|
+
if (childItem.link === path) {
|
|
97
96
|
// skip h1 header
|
|
98
|
-
const headers = page.
|
|
99
|
-
? page.value.headers[0].children
|
|
100
|
-
: page.value.headers;
|
|
97
|
+
const headers = page.headers[0]?.level === 1 ? page.headers[0].children : page.headers;
|
|
101
98
|
return {
|
|
102
99
|
...childItem,
|
|
103
100
|
children: headersToSidebarItemChildren(headers, sidebarDepth),
|
|
@@ -110,9 +107,11 @@ export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth) => {
|
|
|
110
107
|
/**
|
|
111
108
|
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
112
109
|
*/
|
|
113
|
-
export const resolveMultiSidebarItems = (sidebarConfig, sidebarDepth) => {
|
|
114
|
-
const
|
|
115
|
-
const sidebarPath = resolveLocalePath(sidebarConfig, route.path);
|
|
110
|
+
export const resolveMultiSidebarItems = (page, path, sidebarConfig, sidebarDepth) => {
|
|
111
|
+
const sidebarPath = resolveLocalePath(sidebarConfig, path);
|
|
116
112
|
const matchedSidebarConfig = sidebarConfig[sidebarPath] ?? [];
|
|
117
|
-
|
|
113
|
+
if (matchedSidebarConfig === 'heading') {
|
|
114
|
+
return resolveAutoSidebarItems(page, sidebarDepth);
|
|
115
|
+
}
|
|
116
|
+
return resolveArraySidebarItems(page, path, matchedSidebarConfig, sidebarDepth);
|
|
118
117
|
};
|
package/lib/client/config.d.ts
CHANGED
package/lib/client/config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasGlobalComponent } from '@vuepress/helper/client';
|
|
2
2
|
import { h } from 'vue';
|
|
3
|
+
import { defineClientConfig } from 'vuepress/client';
|
|
3
4
|
import { Badge, CodeGroup, CodeGroupItem } from './components/global/index.js';
|
|
4
5
|
import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables/index.js';
|
|
5
6
|
import Layout from './layouts/Layout.vue';
|
|
@@ -7,9 +8,12 @@ import NotFound from './layouts/NotFound.vue';
|
|
|
7
8
|
import './styles/index.scss';
|
|
8
9
|
export default defineClientConfig({
|
|
9
10
|
enhance({ app, router }) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
if (!hasGlobalComponent('Badge'))
|
|
12
|
+
app.component('Badge', Badge);
|
|
13
|
+
if (!hasGlobalComponent('CodeGroup'))
|
|
14
|
+
app.component('CodeGroup', CodeGroup);
|
|
15
|
+
if (!hasGlobalComponent('CodeGroupItem'))
|
|
16
|
+
app.component('CodeGroupItem', CodeGroupItem);
|
|
13
17
|
// compat with @vuepress/plugin-external-link-icon
|
|
14
18
|
app.component('AutoLinkExternalIcon', () => {
|
|
15
19
|
const ExternalLinkIcon = app.component('ExternalLinkIcon');
|
package/lib/client/index.d.ts
CHANGED
package/lib/client/index.js
CHANGED