@vuepress/theme-default 2.0.0-rc.2 → 2.0.0-rc.21

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.
Files changed (41) hide show
  1. package/lib/client/components/AutoLink.vue +26 -24
  2. package/lib/client/components/NavbarBrand.vue +13 -3
  3. package/lib/client/components/NavbarDropdown.vue +1 -1
  4. package/lib/client/components/NavbarItems.vue +39 -35
  5. package/lib/client/components/PageNav.vue +116 -14
  6. package/lib/client/components/SidebarItem.vue +1 -1
  7. package/lib/client/components/SidebarItems.vue +1 -1
  8. package/lib/client/composables/index.d.ts +1 -0
  9. package/lib/client/composables/index.js +1 -0
  10. package/lib/client/composables/useNavigate.d.ts +1 -0
  11. package/lib/client/composables/useNavigate.js +25 -0
  12. package/lib/client/composables/useSidebarItems.d.ts +3 -4
  13. package/lib/client/composables/useSidebarItems.js +12 -11
  14. package/lib/client/config.js +7 -3
  15. package/lib/client/index.d.ts +1 -1
  16. package/lib/client/index.js +0 -1
  17. package/lib/client/layouts/Layout.vue +1 -2
  18. package/lib/client/layouts/NotFound.vue +2 -2
  19. package/lib/client/styles/arrow.scss +18 -24
  20. package/lib/client/styles/layout.scss +4 -0
  21. package/lib/client/styles/navbar-dropdown.scss +2 -2
  22. package/lib/client/styles/navbar.scss +4 -4
  23. package/lib/client/styles/page.scss +0 -27
  24. package/lib/client/styles/sidebar.scss +1 -1
  25. package/lib/client/styles/vars-dark.scss +7 -0
  26. package/lib/client/styles/vars.scss +46 -9
  27. package/lib/client/utils/getNavLink.d.ts +1 -7
  28. package/lib/client/utils/getNavLink.js +9 -10
  29. package/lib/client/utils/index.d.ts +0 -1
  30. package/lib/client/utils/index.js +0 -1
  31. package/lib/client/utils/isActiveSidebarItem.d.ts +1 -1
  32. package/lib/node/defaultTheme.d.ts +5 -1
  33. package/lib/node/defaultTheme.js +39 -2
  34. package/lib/node/index.d.ts +2 -1
  35. package/lib/node/index.js +1 -1
  36. package/lib/shared/nav.d.ts +2 -1
  37. package/lib/shared/options.d.ts +45 -1
  38. package/package.json +25 -20
  39. package/templates/build.html +13 -10
  40. package/lib/client/utils/getResolveRouteWithRedirect.d.ts +0 -5
  41. package/lib/client/utils/getResolveRouteWithRedirect.js +0 -22
@@ -1,8 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, toRefs } from 'vue'
3
3
  import type { PropType } from 'vue'
4
- import { useRoute } from 'vue-router'
5
- import { useSiteData } from 'vuepress/client'
4
+ import { useRoute, useSiteData } from 'vuepress/client'
6
5
  import { isLinkHttp, isLinkWithProtocol } from 'vuepress/shared'
7
6
  import type { NavLink } from '../../shared/index.js'
8
7
 
@@ -41,8 +40,8 @@ const linkTarget = computed(() => {
41
40
  })
42
41
  // if the `target` attr is '_blank'
43
42
  const isBlankTarget = computed(() => linkTarget.value === '_blank')
44
- // is `<RouterLink>` or not
45
- const isRouterLink = computed(
43
+ // is `<RouteLink>` or not
44
+ const isRouteLink = computed(
46
45
  () =>
47
46
  !hasHttpProtocol.value && !hasNonHttpProtocol.value && !isBlankTarget.value,
48
47
  )
@@ -64,38 +63,39 @@ const shouldBeActiveInSubpath = computed(() => {
64
63
  }
65
64
  return item.value.link !== '/'
66
65
  })
67
- // if this link is active in subpath
68
- const isActiveInSubpath = computed(() => {
69
- if (!shouldBeActiveInSubpath.value) {
70
- return false
71
- }
72
- return route.path.startsWith(item.value.link)
73
- })
74
66
 
75
67
  // if this link is active
76
68
  const isActive = computed(() => {
77
- if (!isRouterLink.value) {
69
+ if (!isRouteLink.value) {
78
70
  return false
79
71
  }
80
72
  if (item.value.activeMatch) {
81
73
  return new RegExp(item.value.activeMatch).test(route.path)
82
74
  }
83
- return isActiveInSubpath.value
75
+
76
+ if (!shouldBeActiveInSubpath.value) {
77
+ return false
78
+ }
79
+
80
+ // if this link is active in subpath
81
+ return route.path.startsWith(item.value.link)
84
82
  })
85
83
  </script>
86
84
 
87
85
  <template>
88
- <RouterLink
89
- v-if="isRouterLink"
90
- :class="{ 'router-link-active': isActive }"
86
+ <RouteLink
87
+ v-if="isRouteLink"
88
+ :active="isActive"
91
89
  :to="item.link"
92
90
  :aria-label="linkAriaLabel"
93
91
  v-bind="$attrs"
94
92
  >
95
- <slot name="before" />
96
- {{ item.text }}
97
- <slot name="after" />
98
- </RouterLink>
93
+ <slot>
94
+ <slot name="before" />
95
+ {{ item.text }}
96
+ <slot name="after" />
97
+ </slot>
98
+ </RouteLink>
99
99
  <a
100
100
  v-else
101
101
  class="external-link"
@@ -105,9 +105,11 @@ const isActive = computed(() => {
105
105
  :aria-label="linkAriaLabel"
106
106
  v-bind="$attrs"
107
107
  >
108
- <slot name="before" />
109
- {{ item.text }}
110
- <AutoLinkExternalIcon v-if="isBlankTarget" />
111
- <slot name="after" />
108
+ <slot>
109
+ <slot name="before" />
110
+ {{ item.text }}
111
+ <AutoLinkExternalIcon v-if="isBlankTarget" />
112
+ <slot name="after" />
113
+ </slot>
112
114
  </a>
113
115
  </template>
@@ -3,6 +3,7 @@ import { computed, h } from 'vue'
3
3
  import type { FunctionalComponent } from 'vue'
4
4
  import {
5
5
  ClientOnly,
6
+ RouteLink,
6
7
  useRouteLocale,
7
8
  useSiteLocaleData,
8
9
  withBase,
@@ -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
- <RouterLink :to="navbarBrandLink">
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
- </RouterLink>
64
+ </RouteLink>
55
65
  </template>
@@ -3,7 +3,7 @@ import AutoLink from '@theme/AutoLink.vue'
3
3
  import DropdownTransition from '@theme/DropdownTransition.vue'
4
4
  import { computed, ref, toRefs, watch } from 'vue'
5
5
  import type { PropType } from 'vue'
6
- import { useRoute } from 'vue-router'
6
+ import { useRoute } from 'vuepress/client'
7
7
  import type { NavbarItem, ResolvedNavbarItem } from '../../shared/index.js'
8
8
 
9
9
  const props = defineProps({
@@ -1,11 +1,15 @@
1
1
  <script setup lang="ts">
2
2
  import AutoLink from '@theme/AutoLink.vue'
3
3
  import NavbarDropdown from '@theme/NavbarDropdown.vue'
4
+ import { useRoutePaths } from '@vuepress/helper/client'
4
5
  import { computed, ref } from 'vue'
5
6
  import type { ComputedRef } from 'vue'
6
- import { useRouter } from 'vue-router'
7
- import type { Router } from 'vue-router'
8
- import { useRouteLocale, useSiteData, useSiteLocaleData } from 'vuepress/client'
7
+ import {
8
+ useRoute,
9
+ useRouteLocale,
10
+ useSiteData,
11
+ useSiteLocaleData,
12
+ } from 'vuepress/client'
9
13
  import { isLinkHttp, isString } from 'vuepress/shared'
10
14
  import type {
11
15
  NavbarGroup,
@@ -24,7 +28,8 @@ import { getNavLink, resolveRepoType } from '../utils/index.js'
24
28
  * Get navbar config of select language dropdown
25
29
  */
26
30
  const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
27
- const router = useRouter()
31
+ const route = useRoute()
32
+ const routePaths = useRoutePaths()
28
33
  const routeLocale = useRouteLocale()
29
34
  const site = useSiteData()
30
35
  const siteLocale = useSiteLocaleData()
@@ -37,8 +42,8 @@ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
37
42
  if (localePaths.length < 2) {
38
43
  return []
39
44
  }
40
- const currentPath = router.currentRoute.value.path
41
- const currentFullPath = router.currentRoute.value.fullPath
45
+ const currentPath = route.path
46
+ const currentFullPath = route.fullPath
42
47
 
43
48
  const languageDropdown: ResolvedNavbarItem = {
44
49
  text: `${themeLocale.value.selectLanguageText}`,
@@ -53,33 +58,31 @@ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
53
58
  const targetLang = `${targetSiteLocale.lang}`
54
59
 
55
60
  const text = targetThemeLocale.selectLanguageName ?? targetLang
56
- let link
57
61
 
62
+ // if the target language is current language
63
+ // stay at current link
58
64
  if (targetLang === siteLocale.value.lang) {
59
- // if the target language is current language
60
- // stay at current link
61
- link = currentFullPath
62
- } else {
63
- // if the target language is not current language
64
- // try to link to the corresponding page of current page
65
- // or fallback to homepage
66
- const targetLocalePage = currentPath.replace(
67
- routeLocale.value,
68
- targetLocalePath,
69
- )
70
- if (
71
- router.getRoutes().some((item) => item.path === targetLocalePage)
72
- ) {
73
- // try to keep current hash and params across languages
74
- link = currentFullPath.replace(currentPath, targetLocalePage)
75
- } else {
76
- link = targetThemeLocale.home ?? targetLocalePath
65
+ return {
66
+ text,
67
+ activeMatch: /./,
68
+ link: route.hash ?? '#',
77
69
  }
78
70
  }
79
71
 
72
+ // if the target language is not current language
73
+ // try to link to the corresponding page of current page
74
+ // or fallback to homepage
75
+ const targetLocalePage = currentPath.replace(
76
+ routeLocale.value,
77
+ targetLocalePath,
78
+ )
79
+
80
80
  return {
81
81
  text,
82
- link,
82
+ // try to keep current hash and params across languages
83
+ link: routePaths.value.some((item) => item === targetLocalePage)
84
+ ? currentFullPath.replace(currentPath, targetLocalePage)
85
+ : targetThemeLocale.home ?? targetLocalePath,
83
86
  }
84
87
  }),
85
88
  }
@@ -129,17 +132,16 @@ const useNavbarRepo = (): ComputedRef<ResolvedNavbarItem[]> => {
129
132
  }
130
133
 
131
134
  const resolveNavbarItem = (
132
- router: Router,
133
135
  item: NavbarItem | NavbarGroup | string,
134
136
  ): ResolvedNavbarItem => {
135
137
  if (isString(item)) {
136
- return getNavLink(router, item)
138
+ return getNavLink(item)
137
139
  }
138
140
  if ((item as NavbarGroup).children) {
139
141
  return {
140
142
  ...item,
141
143
  children: (item as NavbarGroup).children.map((item) =>
142
- resolveNavbarItem(router, item),
144
+ resolveNavbarItem(item),
143
145
  ),
144
146
  }
145
147
  }
@@ -147,13 +149,10 @@ const resolveNavbarItem = (
147
149
  }
148
150
 
149
151
  const useNavbarConfig = (): ComputedRef<ResolvedNavbarItem[]> => {
150
- const router = useRouter()
151
152
  const themeLocale = useThemeLocaleData()
152
153
 
153
154
  return computed(() =>
154
- (themeLocale.value.navbar || []).map((item) =>
155
- resolveNavbarItem(router, item),
156
- ),
155
+ (themeLocale.value.navbar || []).map((item) => resolveNavbarItem(item)),
157
156
  )
158
157
  }
159
158
 
@@ -178,13 +177,18 @@ useUpdateDeviceStatus(
178
177
  }
179
178
  },
180
179
  )
180
+
181
+ const navbarLabel = computed(() => {
182
+ const themeLocale = useThemeLocaleData()
183
+ return themeLocale.value.navbarLabel ?? 'site navigation'
184
+ })
181
185
  </script>
182
186
 
183
187
  <template>
184
- <nav v-if="navbarLinks.length" class="navbar-items">
188
+ <nav v-if="navbarLinks.length" class="navbar-items" :aria-label="navbarLabel">
185
189
  <div v-for="item in navbarLinks" :key="item.text" class="navbar-item">
186
190
  <NavbarDropdown
187
- v-if="item.children"
191
+ v-if="'children' in item"
188
192
  :item="item"
189
193
  :class="isMobile ? 'mobile' : ''"
190
194
  />
@@ -1,16 +1,20 @@
1
1
  <script setup lang="ts">
2
2
  import AutoLink from '@theme/AutoLink.vue'
3
+ import { useEventListener } from '@vueuse/core'
3
4
  import { computed } from 'vue'
4
- import type { Router } from 'vue-router'
5
- import { useRoute, useRouter } from 'vue-router'
6
- import { usePageFrontmatter } from 'vuepress/client'
5
+ import type { Router } from 'vuepress/client'
6
+ import { usePageFrontmatter, useRoute, useRouter } from 'vuepress/client'
7
7
  import { isPlainObject, isString } from 'vuepress/shared'
8
8
  import type {
9
9
  DefaultThemeNormalPageFrontmatter,
10
10
  NavLink,
11
11
  ResolvedSidebarItem,
12
12
  } from '../../shared/index.js'
13
- import { useSidebarItems } from '../composables/index.js'
13
+ import {
14
+ useNavigate,
15
+ useSidebarItems,
16
+ useThemeLocaleData,
17
+ } from '../composables/index.js'
14
18
  import { getNavLink } from '../utils/index.js'
15
19
 
16
20
  /**
@@ -70,8 +74,10 @@ const resolveFromSidebarItems = (
70
74
 
71
75
  const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
72
76
  const sidebarItems = useSidebarItems()
77
+ const themeLocale = useThemeLocaleData()
73
78
  const route = useRoute()
74
79
  const router = useRouter()
80
+ const navigate = useNavigate()
75
81
 
76
82
  const prevNavLink = computed(() => {
77
83
  const prevConfig = resolveFromFrontmatterConfig(
@@ -96,18 +102,114 @@ const nextNavLink = computed(() => {
96
102
 
97
103
  return resolveFromSidebarItems(sidebarItems.value, route.path, 1)
98
104
  })
105
+
106
+ const navbarLabel = computed(() => {
107
+ const themeLocale = useThemeLocaleData()
108
+ return themeLocale.value.pageNavbarLabel ?? 'page navigation'
109
+ })
110
+
111
+ useEventListener('keydown', (event): void => {
112
+ if (event.altKey)
113
+ if (event.key === 'ArrowRight') {
114
+ if (nextNavLink.value) {
115
+ navigate(nextNavLink.value.link)
116
+ event.preventDefault()
117
+ }
118
+ } else if (event.key === 'ArrowLeft') {
119
+ if (prevNavLink.value) {
120
+ navigate(prevNavLink.value.link)
121
+ event.preventDefault()
122
+ }
123
+ }
124
+ })
99
125
  </script>
100
126
 
101
127
  <template>
102
- <nav v-if="prevNavLink || nextNavLink" class="page-nav">
103
- <p class="inner">
104
- <span v-if="prevNavLink" class="prev">
105
- <AutoLink :item="prevNavLink" />
106
- </span>
107
-
108
- <span v-if="nextNavLink" class="next">
109
- <AutoLink :item="nextNavLink" />
110
- </span>
111
- </p>
128
+ <nav
129
+ v-if="prevNavLink || nextNavLink"
130
+ class="vp-page-nav"
131
+ :aria-label="navbarLabel"
132
+ >
133
+ <AutoLink v-if="prevNavLink" class="prev" :item="prevNavLink">
134
+ <div class="hint">
135
+ <span class="arrow left" />
136
+ {{ themeLocale.prev ?? 'Prev' }}
137
+ </div>
138
+ <div class="link">
139
+ <span>{{ prevNavLink.text }}</span>
140
+ </div>
141
+ </AutoLink>
142
+
143
+ <AutoLink v-if="nextNavLink" class="next" :item="nextNavLink">
144
+ <div class="hint">
145
+ {{ themeLocale.next ?? 'Next' }}
146
+ <span class="arrow right" />
147
+ </div>
148
+ <div class="link">
149
+ <span>{{ nextNavLink.text }}</span>
150
+ </div>
151
+ </AutoLink>
112
152
  </nav>
113
153
  </template>
154
+
155
+ <style lang="scss">
156
+ @import '../styles/_variables';
157
+
158
+ .vp-page-nav {
159
+ display: flex;
160
+ flex-wrap: wrap;
161
+
162
+ max-width: var(--content-width, 740px);
163
+ min-height: 2rem;
164
+ margin-inline: auto;
165
+ margin-top: 0;
166
+ padding-block: 0.5rem;
167
+ padding-inline: 2rem;
168
+ border-top: 1px solid var(--c-border);
169
+
170
+ transition: border-top var(--t-color);
171
+
172
+ @media (max-width: $MQNarrow) {
173
+ padding-inline: 1rem;
174
+ }
175
+
176
+ @media print {
177
+ display: none;
178
+ }
179
+
180
+ padding-top: 1rem;
181
+ padding-bottom: 0;
182
+
183
+ @media print {
184
+ display: none;
185
+ }
186
+
187
+ .route-link {
188
+ display: inline-block;
189
+ flex-grow: 1;
190
+
191
+ margin: 0.25rem;
192
+ padding: 0.25rem 0.5rem;
193
+ border: 1px solid var(--c-border);
194
+ border-radius: 0.25rem;
195
+
196
+ &:hover {
197
+ background: var(--c-bg-light);
198
+ }
199
+
200
+ .hint {
201
+ color: var(--c-text-quote);
202
+ font-size: 0.875rem;
203
+ line-height: 2;
204
+ }
205
+ }
206
+
207
+ .prev {
208
+ text-align: start;
209
+ }
210
+
211
+ .next {
212
+ text-align: end;
213
+ }
214
+ }
215
+ </style>
@@ -4,7 +4,7 @@ import DropdownTransition from '@theme/DropdownTransition.vue'
4
4
  import { useToggle } from '@vueuse/core'
5
5
  import { computed, nextTick, onBeforeUnmount, toRefs } from 'vue'
6
6
  import type { PropType } from 'vue'
7
- import { useRoute, useRouter } from 'vue-router'
7
+ import { useRoute, useRouter } from 'vuepress/client'
8
8
  import type { ResolvedSidebarItem } from '../../shared/index.js'
9
9
  import { isActiveSidebarItem } from '../utils/index.js'
10
10
 
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import SidebarItem from '@theme/SidebarItem.vue'
3
3
  import { onMounted, watch } from 'vue'
4
- import { useRoute } from 'vue-router'
4
+ import { useRoute } from 'vuepress/client'
5
5
  import { useSidebarItems } from '../composables/index.js'
6
6
 
7
7
  const route = useRoute()
@@ -1,4 +1,5 @@
1
1
  export * from './useDarkMode.js';
2
+ export * from './useNavigate.js';
2
3
  export * from './useScrollPromise.js';
3
4
  export * from './useSidebarItems.js';
4
5
  export * from './useThemeData.js';
@@ -1,4 +1,5 @@
1
1
  export * from './useDarkMode.js';
2
+ export * from './useNavigate.js';
2
3
  export * from './useScrollPromise.js';
3
4
  export * from './useSidebarItems.js';
4
5
  export * from './useThemeData.js';
@@ -0,0 +1 @@
1
+ export declare const useNavigate: () => (url: string) => void;
@@ -0,0 +1,25 @@
1
+ import { isLinkAbsolute, isLinkWithProtocol } from '@vuepress/helper/client';
2
+ import { useRoute, useRouter } from 'vuepress/client';
3
+ const FAKE_HOST = 'http://.';
4
+ export const useNavigate = () => {
5
+ const router = useRouter();
6
+ const route = useRoute();
7
+ return (url) => {
8
+ if (url)
9
+ if (isLinkAbsolute(url)) {
10
+ // Inner absolute path
11
+ if (route.path !== url)
12
+ router.push(url);
13
+ }
14
+ else if (isLinkWithProtocol(url)) {
15
+ // Outer url
16
+ if (window)
17
+ window.open(url);
18
+ }
19
+ else {
20
+ // Inner relative path
21
+ const loc = route.path.slice(0, route.path.lastIndexOf('/'));
22
+ router.push(new URL(`${loc}/${encodeURI(url)}`, FAKE_HOST).pathname);
23
+ }
24
+ };
25
+ };
@@ -1,5 +1,4 @@
1
1
  import type { ComputedRef, InjectionKey } from 'vue';
2
- import type { Router } from 'vue-router';
3
2
  import type { PageData, PageHeader } from 'vuepress/client';
4
3
  import type { DefaultThemeData, DefaultThemeNormalPageFrontmatter, ResolvedSidebarItem, SidebarConfigArray, SidebarConfigObject } from '../../shared/index.js';
5
4
  export type SidebarItemsRef = ComputedRef<ResolvedSidebarItem[]>;
@@ -17,7 +16,7 @@ export declare const setupSidebarItems: () => void;
17
16
  *
18
17
  * It should only be resolved and provided once
19
18
  */
20
- export declare const resolveSidebarItems: (frontmatter: DefaultThemeNormalPageFrontmatter, themeLocale: DefaultThemeData, page: PageData, router: Router, path: string) => ResolvedSidebarItem[];
19
+ export declare const resolveSidebarItems: (frontmatter: DefaultThemeNormalPageFrontmatter, themeLocale: DefaultThemeData, page: PageData, path: string) => ResolvedSidebarItem[];
21
20
  /**
22
21
  * Util to transform page header to sidebar item
23
22
  */
@@ -30,8 +29,8 @@ export declare const resolveAutoSidebarItems: (page: PageData, sidebarDepth: num
30
29
  /**
31
30
  * Resolve sidebar items if the config is an array
32
31
  */
33
- export declare const resolveArraySidebarItems: (page: PageData, router: Router, path: string, sidebarConfig: SidebarConfigArray, sidebarDepth: number) => ResolvedSidebarItem[];
32
+ export declare const resolveArraySidebarItems: (page: PageData, path: string, sidebarConfig: SidebarConfigArray, sidebarDepth: number) => ResolvedSidebarItem[];
34
33
  /**
35
34
  * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
36
35
  */
37
- export declare const resolveMultiSidebarItems: (page: PageData, router: Router, path: string, sidebarConfig: SidebarConfigObject, sidebarDepth: number) => ResolvedSidebarItem[];
36
+ export declare const resolveMultiSidebarItems: (page: PageData, path: string, sidebarConfig: SidebarConfigObject, sidebarDepth: number) => ResolvedSidebarItem[];
@@ -1,6 +1,5 @@
1
1
  import { computed, inject, provide } from 'vue';
2
- import { useRoute, useRouter } from 'vue-router';
3
- import { usePageData, usePageFrontmatter } from 'vuepress/client';
2
+ import { usePageData, usePageFrontmatter, useRoute } from 'vuepress/client';
4
3
  import { isPlainObject, isString, resolveLocalePath } from 'vuepress/shared';
5
4
  import { getNavLink } from '../utils/index.js';
6
5
  import { useThemeLocaleData } from './useThemeData.js';
@@ -23,8 +22,7 @@ export const setupSidebarItems = () => {
23
22
  const frontmatter = usePageFrontmatter();
24
23
  const page = usePageData();
25
24
  const route = useRoute();
26
- const router = useRouter();
27
- const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value, page.value, router, route.path));
25
+ const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value, page.value, route.path));
28
26
  provide(sidebarItemsSymbol, sidebarItems);
29
27
  };
30
28
  /**
@@ -32,7 +30,7 @@ export const setupSidebarItems = () => {
32
30
  *
33
31
  * It should only be resolved and provided once
34
32
  */
35
- export const resolveSidebarItems = (frontmatter, themeLocale, page, router, path) => {
33
+ export const resolveSidebarItems = (frontmatter, themeLocale, page, path) => {
36
34
  // get sidebar config from frontmatter > theme data
37
35
  const sidebarConfig = frontmatter.sidebar ?? themeLocale.sidebar ?? 'auto';
38
36
  const sidebarDepth = frontmatter.sidebarDepth ?? themeLocale.sidebarDepth ?? 2;
@@ -44,10 +42,10 @@ export const resolveSidebarItems = (frontmatter, themeLocale, page, router, path
44
42
  return resolveAutoSidebarItems(page, sidebarDepth);
45
43
  }
46
44
  if (Array.isArray(sidebarConfig)) {
47
- return resolveArraySidebarItems(page, router, path, sidebarConfig, sidebarDepth);
45
+ return resolveArraySidebarItems(page, path, sidebarConfig, sidebarDepth);
48
46
  }
49
47
  if (isPlainObject(sidebarConfig)) {
50
- return resolveMultiSidebarItems(page, router, path, sidebarConfig, sidebarDepth);
48
+ return resolveMultiSidebarItems(page, path, sidebarConfig, sidebarDepth);
51
49
  }
52
50
  return [];
53
51
  };
@@ -76,11 +74,11 @@ export const resolveAutoSidebarItems = (page, sidebarDepth) => {
76
74
  /**
77
75
  * Resolve sidebar items if the config is an array
78
76
  */
79
- export const resolveArraySidebarItems = (page, router, path, sidebarConfig, sidebarDepth) => {
77
+ export const resolveArraySidebarItems = (page, path, sidebarConfig, sidebarDepth) => {
80
78
  const handleChildItem = (item) => {
81
79
  let childItem;
82
80
  if (isString(item)) {
83
- childItem = getNavLink(router, item);
81
+ childItem = getNavLink(item);
84
82
  }
85
83
  else {
86
84
  childItem = item;
@@ -108,8 +106,11 @@ export const resolveArraySidebarItems = (page, router, path, sidebarConfig, side
108
106
  /**
109
107
  * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
110
108
  */
111
- export const resolveMultiSidebarItems = (page, router, path, sidebarConfig, sidebarDepth) => {
109
+ export const resolveMultiSidebarItems = (page, path, sidebarConfig, sidebarDepth) => {
112
110
  const sidebarPath = resolveLocalePath(sidebarConfig, path);
113
111
  const matchedSidebarConfig = sidebarConfig[sidebarPath] ?? [];
114
- return resolveArraySidebarItems(page, router, path, matchedSidebarConfig, sidebarDepth);
112
+ if (matchedSidebarConfig === 'heading') {
113
+ return resolveAutoSidebarItems(page, sidebarDepth);
114
+ }
115
+ return resolveArraySidebarItems(page, path, matchedSidebarConfig, sidebarDepth);
115
116
  };
@@ -1,3 +1,4 @@
1
+ import { hasGlobalComponent } from '@vuepress/helper/client';
1
2
  import { h } from 'vue';
2
3
  import { defineClientConfig } from 'vuepress/client';
3
4
  import { Badge, CodeGroup, CodeGroupItem } from './components/global/index.js';
@@ -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
- app.component('Badge', Badge);
11
- app.component('CodeGroup', CodeGroup);
12
- app.component('CodeGroupItem', CodeGroupItem);
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');
@@ -1,3 +1,3 @@
1
- export * from '../shared/index.js';
2
1
  export * from './composables/index.js';
3
2
  export * from './utils/index.js';
3
+ export type * from '../shared/index.js';
@@ -1,3 +1,2 @@
1
- export * from '../shared/index.js';
2
1
  export * from './composables/index.js';
3
2
  export * from './utils/index.js';
@@ -4,8 +4,7 @@ import Navbar from '@theme/Navbar.vue'
4
4
  import Page from '@theme/Page.vue'
5
5
  import Sidebar from '@theme/Sidebar.vue'
6
6
  import { computed, onMounted, onUnmounted, ref } from 'vue'
7
- import { useRouter } from 'vue-router'
8
- import { usePageData, usePageFrontmatter } from 'vuepress/client'
7
+ import { usePageData, usePageFrontmatter, useRouter } from 'vuepress/client'
9
8
  import type { DefaultThemePageFrontmatter } from '../../shared/index.js'
10
9
  import {
11
10
  useScrollPromise,