@vuepress/theme-default 2.0.0-beta.4 → 2.0.0-beta.42

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 (132) hide show
  1. package/lib/{clientAppEnhance.d.ts → client/clientAppEnhance.d.ts} +0 -0
  2. package/lib/client/clientAppEnhance.js +34 -0
  3. package/lib/{clientAppSetup.d.ts → client/clientAppSetup.d.ts} +0 -0
  4. package/lib/client/clientAppSetup.js +6 -0
  5. package/lib/client/components/AutoLink.vue +113 -0
  6. package/lib/client/components/DropdownTransition.vue +21 -0
  7. package/lib/client/components/Home.vue +15 -0
  8. package/lib/client/components/HomeContent.vue +5 -0
  9. package/lib/client/components/HomeFeatures.vue +23 -0
  10. package/lib/client/components/HomeFooter.vue +17 -0
  11. package/lib/client/components/HomeHero.vue +97 -0
  12. package/lib/client/components/Navbar.vue +76 -0
  13. package/lib/client/components/NavbarBrand.vue +55 -0
  14. package/lib/client/components/NavbarDropdown.vue +126 -0
  15. package/lib/{components/NavbarLinks.vue → client/components/NavbarItems.vue} +27 -47
  16. package/lib/{components → client/components}/Page.vue +5 -15
  17. package/lib/{components → client/components}/PageMeta.vue +48 -59
  18. package/lib/{components → client/components}/PageNav.vue +43 -56
  19. package/lib/client/components/Sidebar.vue +13 -0
  20. package/lib/client/components/SidebarItem.vue +80 -0
  21. package/lib/client/components/SidebarItems.vue +54 -0
  22. package/lib/client/components/ToggleDarkModeButton.vue +57 -0
  23. package/lib/client/components/ToggleSidebarButton.vue +24 -0
  24. package/lib/client/components/global/Badge.vue +31 -0
  25. package/lib/client/components/global/CodeGroup.d.ts +5 -0
  26. package/lib/client/components/global/CodeGroup.js +106 -0
  27. package/lib/client/components/global/CodeGroupItem.vue +31 -0
  28. package/lib/{composables → client/composables}/index.d.ts +2 -0
  29. package/lib/{composables → client/composables}/index.js +2 -0
  30. package/lib/client/composables/useDarkMode.d.ts +12 -0
  31. package/lib/client/composables/useDarkMode.js +57 -0
  32. package/lib/{composables → client/composables}/useNavLink.d.ts +6 -1
  33. package/lib/{composables → client/composables}/useNavLink.js +0 -0
  34. package/lib/{composables → client/composables}/useResolveRouteWithRedirect.d.ts +1 -1
  35. package/lib/{composables → client/composables}/useResolveRouteWithRedirect.js +2 -2
  36. package/lib/client/composables/useScrollPromise.d.ts +6 -0
  37. package/lib/client/composables/useScrollPromise.js +14 -0
  38. package/lib/{composables → client/composables}/useSidebarItems.d.ts +12 -7
  39. package/lib/client/composables/useSidebarItems.js +117 -0
  40. package/lib/{composables → client/composables}/useThemeData.d.ts +2 -2
  41. package/lib/{composables → client/composables}/useThemeData.js +1 -1
  42. package/lib/client/index.d.ts +4 -0
  43. package/lib/client/index.js +2 -0
  44. package/lib/client/layouts/404.vue +25 -0
  45. package/lib/client/layouts/Layout.vue +128 -0
  46. package/lib/{shim.d.ts → client/shim.d.ts} +0 -0
  47. package/lib/{styles/_wrapper.scss → client/styles/_mixins.scss} +7 -2
  48. package/lib/client/styles/_variables.scss +11 -0
  49. package/lib/{styles → client/styles}/arrow.scss +4 -6
  50. package/lib/{styles → client/styles}/badge.scss +9 -11
  51. package/lib/{styles → client/styles}/code-group.scss +9 -2
  52. package/lib/{styles → client/styles}/code.scss +21 -33
  53. package/lib/client/styles/custom-container.scss +88 -0
  54. package/lib/{styles → client/styles}/home.scss +27 -24
  55. package/lib/{styles → client/styles}/index.scss +4 -4
  56. package/lib/{styles → client/styles}/layout.scss +52 -35
  57. package/lib/{styles/dropdown.scss → client/styles/navbar-dropdown.scss} +37 -47
  58. package/lib/client/styles/navbar.scss +177 -0
  59. package/lib/client/styles/normalize.scss +172 -0
  60. package/lib/{styles → client/styles}/page.scss +15 -8
  61. package/lib/client/styles/sidebar.scss +134 -0
  62. package/lib/{styles → client/styles}/toc.scss +0 -0
  63. package/lib/client/styles/transitions.scss +22 -0
  64. package/lib/client/styles/vars-dark.scss +46 -0
  65. package/lib/client/styles/vars.scss +133 -0
  66. package/lib/{utils → client/utils}/index.d.ts +1 -0
  67. package/lib/{utils → client/utils}/index.js +1 -0
  68. package/lib/client/utils/isActiveSidebarItem.d.ts +3 -0
  69. package/lib/client/utils/isActiveSidebarItem.js +20 -0
  70. package/lib/{utils → client/utils}/resolveEditLink.d.ts +1 -1
  71. package/lib/{utils → client/utils}/resolveEditLink.js +14 -8
  72. package/lib/client/utils/resolveRepoType.d.ts +2 -0
  73. package/lib/{utils → client/utils}/resolveRepoType.js +3 -1
  74. package/lib/node/defaultTheme.d.ts +10 -0
  75. package/lib/node/defaultTheme.js +120 -0
  76. package/lib/node/index.d.ts +5 -5
  77. package/lib/node/index.js +10 -6
  78. package/lib/node/utils/assignDefaultLocaleOptions.d.ts +7 -0
  79. package/lib/node/{assignDefaultLocaleOptions.js → utils/assignDefaultLocaleOptions.js} +11 -9
  80. package/lib/node/utils/index.d.ts +2 -0
  81. package/lib/node/utils/index.js +18 -0
  82. package/lib/node/utils/resolveContainerPluginOptions.d.ts +8 -0
  83. package/lib/node/utils/resolveContainerPluginOptions.js +21 -0
  84. package/lib/{types → shared}/index.d.ts +0 -0
  85. package/lib/{types → shared}/index.js +5 -1
  86. package/lib/{types → shared}/nav.d.ts +11 -12
  87. package/lib/{types → shared}/nav.js +0 -0
  88. package/lib/{types → shared}/options.d.ts +42 -10
  89. package/lib/{types → shared}/options.js +0 -0
  90. package/lib/{types → shared}/page.d.ts +13 -5
  91. package/lib/{types → shared}/page.js +0 -0
  92. package/package.json +38 -29
  93. package/templates/build.html +33 -0
  94. package/CHANGELOG.md +0 -353
  95. package/lib/clientAppEnhance.js +0 -23
  96. package/lib/clientAppSetup.js +0 -11
  97. package/lib/components/DropdownLink.vue +0 -141
  98. package/lib/components/DropdownTransition.vue +0 -34
  99. package/lib/components/Home.vue +0 -133
  100. package/lib/components/NavLink.vue +0 -105
  101. package/lib/components/Navbar.vue +0 -113
  102. package/lib/components/Sidebar.vue +0 -38
  103. package/lib/components/SidebarChild.d.ts +0 -6
  104. package/lib/components/SidebarChild.js +0 -83
  105. package/lib/components/ToggleSidebarButton.vue +0 -27
  106. package/lib/components/global/Badge.vue +0 -37
  107. package/lib/components/global/CodeGroup.vue +0 -85
  108. package/lib/components/global/CodeGroupItem.vue +0 -25
  109. package/lib/components/global/OutboundLink.vue +0 -30
  110. package/lib/composables/useSidebarItems.js +0 -108
  111. package/lib/index.d.ts +0 -6
  112. package/lib/index.js +0 -67
  113. package/lib/layouts/404.vue +0 -38
  114. package/lib/layouts/Layout.vue +0 -132
  115. package/lib/node/assignDefaultLocaleOptions.d.ts +0 -5
  116. package/lib/node/resolveActiveHeaderLinksPluginOptions.d.ts +0 -6
  117. package/lib/node/resolveActiveHeaderLinksPluginOptions.js +0 -16
  118. package/lib/node/resolveContainerPluginOptions.d.ts +0 -26
  119. package/lib/node/resolveContainerPluginOptions.js +0 -79
  120. package/lib/node/resolveGitPluginOptions.d.ts +0 -6
  121. package/lib/node/resolveGitPluginOptions.js +0 -22
  122. package/lib/node/resolveMediumZoomPluginOptions.d.ts +0 -6
  123. package/lib/node/resolveMediumZoomPluginOptions.js +0 -17
  124. package/lib/styles/_normalize.scss +0 -148
  125. package/lib/styles/_variables.scss +0 -34
  126. package/lib/styles/custom-container.scss +0 -78
  127. package/lib/styles/navbar.scss +0 -140
  128. package/lib/styles/plugins.scss +0 -18
  129. package/lib/styles/sidebar.scss +0 -147
  130. package/lib/styles/sr-only.scss +0 -12
  131. package/lib/styles/transitions.scss +0 -13
  132. package/lib/utils/resolveRepoType.d.ts +0 -2
@@ -0,0 +1,34 @@
1
+ import { defineClientAppEnhance } from '@vuepress/client';
2
+ import { h } from 'vue';
3
+ import Badge from './components/global/Badge.vue';
4
+ import CodeGroup from './components/global/CodeGroup';
5
+ import CodeGroupItem from './components/global/CodeGroupItem.vue';
6
+ import { useScrollPromise } from './composables';
7
+ import './styles/index.scss';
8
+ export default defineClientAppEnhance(({ app, router }) => {
9
+ app.component('Badge', Badge);
10
+ app.component('CodeGroup', CodeGroup);
11
+ app.component('CodeGroupItem', CodeGroupItem);
12
+ // compat with @vuepress/plugin-external-link-icon
13
+ app.component('AutoLinkExternalIcon', () => {
14
+ const ExternalLinkIcon = app.component('ExternalLinkIcon');
15
+ if (ExternalLinkIcon) {
16
+ return h(ExternalLinkIcon);
17
+ }
18
+ return null;
19
+ });
20
+ // compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
21
+ app.component('NavbarSearch', () => {
22
+ const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
23
+ if (SearchComponent) {
24
+ return h(SearchComponent);
25
+ }
26
+ return null;
27
+ });
28
+ // handle scrollBehavior with transition
29
+ const scrollBehavior = router.options.scrollBehavior;
30
+ router.options.scrollBehavior = async (...args) => {
31
+ await useScrollPromise().wait();
32
+ return scrollBehavior(...args);
33
+ };
34
+ });
@@ -0,0 +1,6 @@
1
+ import { defineClientAppSetup } from '@vuepress/client';
2
+ import { setupDarkMode, setupSidebarItems } from './composables';
3
+ export default defineClientAppSetup(() => {
4
+ setupDarkMode();
5
+ setupSidebarItems();
6
+ });
@@ -0,0 +1,113 @@
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
+ </script>
9
+
10
+ <script setup lang="ts">
11
+ import { computed, toRefs } from 'vue'
12
+ import type { PropType } from 'vue'
13
+ import { useRoute } from 'vue-router'
14
+ import { useSiteData } from '@vuepress/client'
15
+ import { isLinkHttp, isLinkMailto, isLinkTel } from '@vuepress/shared'
16
+ import type { NavLink } from '../../shared'
17
+
18
+ const props = defineProps({
19
+ item: {
20
+ type: Object as PropType<NavLink>,
21
+ required: true,
22
+ },
23
+ })
24
+
25
+ const route = useRoute()
26
+ const site = useSiteData()
27
+ const { item } = toRefs(props)
28
+
29
+ // if the link has http protocol
30
+ const hasHttpProtocol = computed(() => isLinkHttp(item.value.link))
31
+ // if the link has non-http protocol
32
+ const hasNonHttpProtocol = computed(
33
+ () => isLinkMailto(item.value.link) || isLinkTel(item.value.link)
34
+ )
35
+ // resolve the `target` attr
36
+ const linkTarget = computed(() => {
37
+ if (hasNonHttpProtocol.value) return undefined
38
+ if (item.value.target) return item.value.target
39
+ if (hasHttpProtocol.value) return '_blank'
40
+ return undefined
41
+ })
42
+ // if the `target` attr is '_blank'
43
+ const isBlankTarget = computed(() => linkTarget.value === '_blank')
44
+ // is `<RouterLink>` or not
45
+ const isRouterLink = computed(
46
+ () =>
47
+ !hasHttpProtocol.value && !hasNonHttpProtocol.value && !isBlankTarget.value
48
+ )
49
+ // resolve the `rel` attr
50
+ const linkRel = computed(() => {
51
+ if (hasNonHttpProtocol.value) return undefined
52
+ if (item.value.rel) return item.value.rel
53
+ if (isBlankTarget.value) return 'noopener noreferrer'
54
+ return undefined
55
+ })
56
+ // resolve the `aria-label` attr
57
+ const linkAriaLabel = computed(() => item.value.ariaLabel || item.value.text)
58
+
59
+ // should be active when current route is a subpath of this link
60
+ const shouldBeActiveInSubpath = computed(() => {
61
+ const localeKeys = Object.keys(site.value.locales)
62
+ if (localeKeys.length) {
63
+ return !localeKeys.some((key) => key === item.value.link)
64
+ }
65
+ return item.value.link !== '/'
66
+ })
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
+
75
+ // if this link is active
76
+ const isActive = computed(() => {
77
+ if (!isRouterLink.value) {
78
+ return false
79
+ }
80
+ if (item.value.activeMatch) {
81
+ return new RegExp(item.value.activeMatch).test(route.path)
82
+ }
83
+ return isActiveInSubpath.value
84
+ })
85
+ </script>
86
+
87
+ <template>
88
+ <RouterLink
89
+ v-if="isRouterLink"
90
+ :class="{ 'router-link-active': isActive }"
91
+ :to="item.link"
92
+ :aria-label="linkAriaLabel"
93
+ v-bind="$attrs"
94
+ >
95
+ <slot name="before" />
96
+ {{ item.text }}
97
+ <slot name="after" />
98
+ </RouterLink>
99
+ <a
100
+ v-else
101
+ class="external-link"
102
+ :href="item.link"
103
+ :rel="linkRel"
104
+ :target="linkTarget"
105
+ :aria-label="linkAriaLabel"
106
+ v-bind="$attrs"
107
+ >
108
+ <slot name="before" />
109
+ {{ item.text }}
110
+ <AutoLinkExternalIcon v-if="isBlankTarget" />
111
+ <slot name="after" />
112
+ </a>
113
+ </template>
@@ -0,0 +1,21 @@
1
+ <script setup lang="ts">
2
+ const setHeight = (items): void => {
3
+ // explicitly set height so that it can be transitioned
4
+ items.style.height = items.scrollHeight + 'px'
5
+ }
6
+
7
+ const unsetHeight = (items): void => {
8
+ items.style.height = ''
9
+ }
10
+ </script>
11
+
12
+ <template>
13
+ <Transition
14
+ name="dropdown"
15
+ @enter="setHeight"
16
+ @after-enter="unsetHeight"
17
+ @before-leave="setHeight"
18
+ >
19
+ <slot />
20
+ </Transition>
21
+ </template>
@@ -0,0 +1,15 @@
1
+ <script setup lang="ts">
2
+ import HomeContent from '@theme/HomeContent.vue'
3
+ import HomeFeatures from '@theme/HomeFeatures.vue'
4
+ import HomeFooter from '@theme/HomeFooter.vue'
5
+ import HomeHero from '@theme/HomeHero.vue'
6
+ </script>
7
+
8
+ <template>
9
+ <main class="home">
10
+ <HomeHero />
11
+ <HomeFeatures />
12
+ <HomeContent />
13
+ <HomeFooter />
14
+ </main>
15
+ </template>
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <div class="theme-default-content custom">
3
+ <Content />
4
+ </div>
5
+ </template>
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ import { usePageFrontmatter } from '@vuepress/client'
3
+ import { isArray } from '@vuepress/shared'
4
+ import { computed } from 'vue'
5
+ import type { DefaultThemeHomePageFrontmatter } from '../../shared'
6
+
7
+ const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
8
+ const features = computed(() => {
9
+ if (isArray(frontmatter.value.features)) {
10
+ return frontmatter.value.features
11
+ }
12
+ return []
13
+ })
14
+ </script>
15
+
16
+ <template>
17
+ <div v-if="features.length" class="features">
18
+ <div v-for="feature in features" :key="feature.title" class="feature">
19
+ <h2>{{ feature.title }}</h2>
20
+ <p>{{ feature.details }}</p>
21
+ </div>
22
+ </div>
23
+ </template>
@@ -0,0 +1,17 @@
1
+ <script setup lang="ts">
2
+ import { usePageFrontmatter } from '@vuepress/client'
3
+ import { computed } from 'vue'
4
+ import type { DefaultThemeHomePageFrontmatter } from '../../shared'
5
+
6
+ const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
7
+ const footer = computed(() => frontmatter.value.footer)
8
+ const footerHtml = computed(() => frontmatter.value.footerHtml)
9
+ </script>
10
+
11
+ <template>
12
+ <template v-if="footer">
13
+ <!-- eslint-disable-next-line vue/no-v-html -->
14
+ <div v-if="footerHtml" class="footer" v-html="footer" />
15
+ <div v-else class="footer" v-text="footer" />
16
+ </template>
17
+ </template>
@@ -0,0 +1,97 @@
1
+ <script setup lang="ts">
2
+ import AutoLink from '@theme/AutoLink.vue'
3
+ import {
4
+ ClientOnly,
5
+ usePageFrontmatter,
6
+ useSiteLocaleData,
7
+ withBase,
8
+ } from '@vuepress/client'
9
+ import { isArray } from '@vuepress/shared'
10
+ import type { FunctionalComponent } from 'vue'
11
+ import { computed, h } from 'vue'
12
+ import type { DefaultThemeHomePageFrontmatter } from '../../shared'
13
+ import { useDarkMode } from '../composables'
14
+
15
+ const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
16
+ const siteLocale = useSiteLocaleData()
17
+ const isDarkMode = useDarkMode()
18
+
19
+ const heroImage = computed(() => {
20
+ if (isDarkMode.value && frontmatter.value.heroImageDark !== undefined) {
21
+ return frontmatter.value.heroImageDark
22
+ }
23
+ return frontmatter.value.heroImage
24
+ })
25
+
26
+ const heroText = computed(() => {
27
+ if (frontmatter.value.heroText === null) {
28
+ return null
29
+ }
30
+ return frontmatter.value.heroText || siteLocale.value.title || 'Hello'
31
+ })
32
+
33
+ const heroAlt = computed(
34
+ () => frontmatter.value.heroAlt || heroText.value || 'hero'
35
+ )
36
+
37
+ const tagline = computed(() => {
38
+ if (frontmatter.value.tagline === null) {
39
+ return null
40
+ }
41
+ return (
42
+ frontmatter.value.tagline ||
43
+ siteLocale.value.description ||
44
+ 'Welcome to your VuePress site'
45
+ )
46
+ })
47
+
48
+ const actions = computed(() => {
49
+ if (!isArray(frontmatter.value.actions)) {
50
+ return []
51
+ }
52
+
53
+ return frontmatter.value.actions.map(({ text, link, type = 'primary' }) => ({
54
+ text,
55
+ link,
56
+ type,
57
+ }))
58
+ })
59
+
60
+ const HomeHeroImage: FunctionalComponent = () => {
61
+ if (!heroImage.value) return null
62
+ const img = h('img', {
63
+ src: withBase(heroImage.value),
64
+ alt: heroAlt.value,
65
+ })
66
+ if (frontmatter.value.heroImageDark === undefined) {
67
+ return img
68
+ }
69
+ // wrap hero image with <ClientOnly> to avoid ssr-mismatch
70
+ // when using a different hero image in dark mode
71
+ return h(ClientOnly, () => img)
72
+ }
73
+ </script>
74
+
75
+ <template>
76
+ <header class="hero">
77
+ <HomeHeroImage />
78
+
79
+ <h1 v-if="heroText" id="main-title">
80
+ {{ heroText }}
81
+ </h1>
82
+
83
+ <p v-if="tagline" class="description">
84
+ {{ tagline }}
85
+ </p>
86
+
87
+ <p v-if="actions.length" class="actions">
88
+ <AutoLink
89
+ v-for="action in actions"
90
+ :key="action.text"
91
+ class="action-button"
92
+ :class="[action.type]"
93
+ :item="action"
94
+ />
95
+ </p>
96
+ </header>
97
+ </template>
@@ -0,0 +1,76 @@
1
+ <script setup lang="ts">
2
+ import NavbarBrand from '@theme/NavbarBrand.vue'
3
+ import NavbarItems from '@theme/NavbarItems.vue'
4
+ import ToggleDarkModeButton from '@theme/ToggleDarkModeButton.vue'
5
+ import ToggleSidebarButton from '@theme/ToggleSidebarButton.vue'
6
+ import { computed, onMounted, ref } from 'vue'
7
+ import { useThemeLocaleData } from '../composables'
8
+
9
+ defineEmits(['toggle-sidebar'])
10
+
11
+ const themeLocale = useThemeLocaleData()
12
+
13
+ const navbar = ref<HTMLElement | null>(null)
14
+ const navbarBrand = ref<HTMLElement | null>(null)
15
+
16
+ const linksWrapperMaxWidth = ref(0)
17
+ const linksWrapperStyle = computed(() => {
18
+ if (!linksWrapperMaxWidth.value) {
19
+ return {}
20
+ }
21
+ return {
22
+ maxWidth: linksWrapperMaxWidth.value + 'px',
23
+ }
24
+ })
25
+ const enableDarkMode = computed(() => themeLocale.value.darkMode)
26
+
27
+ // avoid overlapping of long title and long navbar links
28
+ onMounted(() => {
29
+ // TODO: migrate to css var
30
+ // refer to _variables.scss
31
+ const MOBILE_DESKTOP_BREAKPOINT = 719
32
+ const navbarHorizontalPadding =
33
+ getCssValue(navbar.value, 'paddingLeft') +
34
+ getCssValue(navbar.value, 'paddingRight')
35
+ const handleLinksWrapWidth = (): void => {
36
+ if (window.innerWidth <= MOBILE_DESKTOP_BREAKPOINT) {
37
+ linksWrapperMaxWidth.value = 0
38
+ } else {
39
+ linksWrapperMaxWidth.value =
40
+ navbar.value!.offsetWidth -
41
+ navbarHorizontalPadding -
42
+ (navbarBrand.value?.offsetWidth || 0)
43
+ }
44
+ }
45
+ handleLinksWrapWidth()
46
+ window.addEventListener('resize', handleLinksWrapWidth, false)
47
+ window.addEventListener('orientationchange', handleLinksWrapWidth, false)
48
+ })
49
+
50
+ function getCssValue(el: HTMLElement | null, property: string): number {
51
+ // NOTE: Known bug, will return 'auto' if style value is 'auto'
52
+ const val = el?.ownerDocument?.defaultView?.getComputedStyle(el, null)?.[
53
+ property
54
+ ]
55
+ const num = Number.parseInt(val, 10)
56
+ return Number.isNaN(num) ? 0 : num
57
+ }
58
+ </script>
59
+
60
+ <template>
61
+ <header ref="navbar" class="navbar">
62
+ <ToggleSidebarButton @toggle="$emit('toggle-sidebar')" />
63
+
64
+ <span ref="navbarBrand">
65
+ <NavbarBrand />
66
+ </span>
67
+
68
+ <div class="navbar-items-wrapper" :style="linksWrapperStyle">
69
+ <slot name="before" />
70
+ <NavbarItems class="can-hide" />
71
+ <slot name="after" />
72
+ <ToggleDarkModeButton v-if="enableDarkMode" />
73
+ <NavbarSearch />
74
+ </div>
75
+ </header>
76
+ </template>
@@ -0,0 +1,55 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ ClientOnly,
4
+ useRouteLocale,
5
+ useSiteLocaleData,
6
+ withBase,
7
+ } from '@vuepress/client'
8
+ import { computed, h } from 'vue'
9
+ import type { FunctionalComponent } from 'vue'
10
+ import { useDarkMode, useThemeLocaleData } from '../composables'
11
+
12
+ const routeLocale = useRouteLocale()
13
+ const siteLocale = useSiteLocaleData()
14
+ const themeLocale = useThemeLocaleData()
15
+ const isDarkMode = useDarkMode()
16
+
17
+ const navbarBrandLink = computed(
18
+ () => themeLocale.value.home || routeLocale.value
19
+ )
20
+ const navbarBrandTitle = computed(() => siteLocale.value.title)
21
+ const navbarBrandLogo = computed(() => {
22
+ if (isDarkMode.value && themeLocale.value.logoDark !== undefined) {
23
+ return themeLocale.value.logoDark
24
+ }
25
+ return themeLocale.value.logo
26
+ })
27
+ const NavbarBrandLogo: FunctionalComponent = () => {
28
+ if (!navbarBrandLogo.value) return null
29
+ const img = h('img', {
30
+ class: 'logo',
31
+ src: withBase(navbarBrandLogo.value),
32
+ alt: navbarBrandTitle.value,
33
+ })
34
+ if (themeLocale.value.logoDark === undefined) {
35
+ return img
36
+ }
37
+ // wrap brand logo with <ClientOnly> to avoid ssr-mismatch
38
+ // when using a different brand logo in dark mode
39
+ return h(ClientOnly, () => img)
40
+ }
41
+ </script>
42
+
43
+ <template>
44
+ <RouterLink :to="navbarBrandLink">
45
+ <NavbarBrandLogo />
46
+
47
+ <span
48
+ v-if="navbarBrandTitle"
49
+ class="site-name"
50
+ :class="{ 'can-hide': navbarBrandLogo }"
51
+ >
52
+ {{ navbarBrandTitle }}
53
+ </span>
54
+ </RouterLink>
55
+ </template>
@@ -0,0 +1,126 @@
1
+ <script setup lang="ts">
2
+ import AutoLink from '@theme/AutoLink.vue'
3
+ import DropdownTransition from '@theme/DropdownTransition.vue'
4
+ import { computed, ref, toRefs, watch } from 'vue'
5
+ import type { PropType } from 'vue'
6
+ import { useRoute } from 'vue-router'
7
+ import type { NavbarItem, ResolvedNavbarItem } from '../../shared'
8
+
9
+ const props = defineProps({
10
+ item: {
11
+ type: Object as PropType<Exclude<ResolvedNavbarItem, NavbarItem>>,
12
+ required: true,
13
+ },
14
+ })
15
+
16
+ const { item } = toRefs(props)
17
+
18
+ const dropdownAriaLabel = computed(
19
+ () => item.value.ariaLabel || item.value.text
20
+ )
21
+
22
+ const open = ref(false)
23
+ const route = useRoute()
24
+ watch(
25
+ () => route.path,
26
+ () => {
27
+ open.value = false
28
+ }
29
+ )
30
+
31
+ /**
32
+ * Open the dropdown when user tab and click from keyboard.
33
+ *
34
+ * Use event.detail to detect tab and click from keyboard.
35
+ * The Tab + Click is UIEvent > KeyboardEvent, so the detail is 0.
36
+ *
37
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
38
+ */
39
+ const handleDropdown = (e): void => {
40
+ const isTriggerByTab = e.detail === 0
41
+ if (isTriggerByTab) {
42
+ open.value = !open.value
43
+ } else {
44
+ open.value = false
45
+ }
46
+ }
47
+
48
+ const isLastItemOfArray = (item: unknown, arr: unknown[]): boolean =>
49
+ arr[arr.length - 1] === item
50
+ </script>
51
+
52
+ <template>
53
+ <div class="navbar-dropdown-wrapper" :class="{ open }">
54
+ <button
55
+ class="navbar-dropdown-title"
56
+ type="button"
57
+ :aria-label="dropdownAriaLabel"
58
+ @click="handleDropdown"
59
+ >
60
+ <span class="title">{{ item.text }}</span>
61
+ <span class="arrow down" />
62
+ </button>
63
+
64
+ <button
65
+ class="navbar-dropdown-title-mobile"
66
+ type="button"
67
+ :aria-label="dropdownAriaLabel"
68
+ @click="open = !open"
69
+ >
70
+ <span class="title">{{ item.text }}</span>
71
+ <span class="arrow" :class="open ? 'down' : 'right'" />
72
+ </button>
73
+
74
+ <DropdownTransition>
75
+ <ul v-show="open" class="navbar-dropdown">
76
+ <li
77
+ v-for="child in item.children"
78
+ :key="child.text"
79
+ class="navbar-dropdown-item"
80
+ >
81
+ <template v-if="child.children">
82
+ <h4 class="navbar-dropdown-subtitle">
83
+ <AutoLink
84
+ v-if="child.link"
85
+ :item="child"
86
+ @focusout="
87
+ isLastItemOfArray(child, item.children) &&
88
+ child.children.length === 0 &&
89
+ (open = false)
90
+ "
91
+ />
92
+
93
+ <span v-else>{{ child.text }}</span>
94
+ </h4>
95
+
96
+ <ul class="navbar-dropdown-subitem-wrapper">
97
+ <li
98
+ v-for="grandchild in child.children"
99
+ :key="grandchild.link"
100
+ class="navbar-dropdown-subitem"
101
+ >
102
+ <AutoLink
103
+ :item="grandchild"
104
+ @focusout="
105
+ isLastItemOfArray(grandchild, child.children) &&
106
+ isLastItemOfArray(child, item.children) &&
107
+ (open = false)
108
+ "
109
+ />
110
+ </li>
111
+ </ul>
112
+ </template>
113
+
114
+ <template v-else>
115
+ <AutoLink
116
+ :item="child"
117
+ @focusout="
118
+ isLastItemOfArray(child, item.children) && (open = false)
119
+ "
120
+ />
121
+ </template>
122
+ </li>
123
+ </ul>
124
+ </DropdownTransition>
125
+ </div>
126
+ </template>