@vuepress/theme-default 2.0.0-beta.5 → 2.0.0-beta.50

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 (142) hide show
  1. package/lib/client/components/AutoLink.vue +114 -0
  2. package/lib/client/components/DropdownTransition.vue +21 -0
  3. package/lib/client/components/Home.vue +15 -0
  4. package/lib/client/components/HomeContent.vue +5 -0
  5. package/lib/client/components/HomeFeatures.vue +23 -0
  6. package/lib/client/components/HomeFooter.vue +17 -0
  7. package/lib/client/components/HomeHero.vue +97 -0
  8. package/lib/client/components/Navbar.vue +75 -0
  9. package/lib/client/components/NavbarBrand.vue +55 -0
  10. package/lib/client/components/NavbarDropdown.vue +126 -0
  11. package/lib/{components/NavbarLinks.vue → client/components/NavbarItems.vue} +41 -52
  12. package/lib/{components → client/components}/Page.vue +9 -15
  13. package/lib/{components → client/components}/PageMeta.vue +51 -66
  14. package/lib/{components → client/components}/PageNav.vue +44 -57
  15. package/lib/client/components/Sidebar.vue +13 -0
  16. package/lib/client/components/SidebarItem.vue +87 -0
  17. package/lib/client/components/SidebarItems.vue +57 -0
  18. package/lib/client/components/ToggleColorModeButton.vue +57 -0
  19. package/lib/client/components/ToggleSidebarButton.vue +24 -0
  20. package/lib/client/components/global/Badge.vue +31 -0
  21. package/lib/{components → client/components}/global/CodeGroup.d.ts +2 -3
  22. package/lib/client/components/global/CodeGroup.js +106 -0
  23. package/lib/client/components/global/CodeGroupItem.vue +31 -0
  24. package/lib/client/components/global/index.d.ts +4 -0
  25. package/lib/client/components/global/index.js +4 -0
  26. package/lib/client/composables/index.d.ts +6 -0
  27. package/lib/client/composables/index.js +6 -0
  28. package/lib/client/composables/useDarkMode.d.ts +12 -0
  29. package/lib/client/composables/useDarkMode.js +57 -0
  30. package/lib/{composables → client/composables}/useNavLink.d.ts +6 -1
  31. package/lib/{composables → client/composables}/useNavLink.js +5 -2
  32. package/lib/{composables → client/composables}/useResolveRouteWithRedirect.d.ts +1 -1
  33. package/lib/{composables → client/composables}/useResolveRouteWithRedirect.js +2 -2
  34. package/lib/{composables → client/composables}/useScrollPromise.d.ts +0 -0
  35. package/lib/{composables → client/composables}/useScrollPromise.js +1 -1
  36. package/lib/{composables → client/composables}/useSidebarItems.d.ts +12 -7
  37. package/lib/client/composables/useSidebarItems.js +118 -0
  38. package/lib/{composables → client/composables}/useThemeData.d.ts +2 -2
  39. package/lib/{composables → client/composables}/useThemeData.js +1 -1
  40. package/lib/client/config.d.ts +3 -0
  41. package/lib/client/config.js +38 -0
  42. package/lib/client/index.d.ts +3 -0
  43. package/lib/client/index.js +3 -0
  44. package/lib/client/layouts/404.vue +27 -0
  45. package/lib/client/layouts/Layout.vue +134 -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 +26 -37
  53. package/lib/client/styles/custom-container.scss +88 -0
  54. package/lib/{styles → client/styles}/home.scss +32 -24
  55. package/lib/{styles → client/styles}/index.scss +4 -4
  56. package/lib/{styles → client/styles}/layout.scss +70 -66
  57. package/lib/{styles/dropdown.scss → client/styles/navbar-dropdown.scss} +37 -47
  58. package/lib/{styles → client/styles}/navbar.scss +70 -34
  59. package/lib/client/styles/normalize.scss +177 -0
  60. package/lib/{styles → client/styles}/page.scss +20 -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/client/utils/index.d.ts +3 -0
  67. package/lib/client/utils/index.js +3 -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 +2 -2
  71. package/lib/{utils → client/utils}/resolveEditLink.js +15 -9
  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 +5 -17
  78. package/lib/node/utils/assignDefaultLocaleOptions.d.ts +7 -0
  79. package/lib/node/{assignDefaultLocaleOptions.js → utils/assignDefaultLocaleOptions.js} +13 -13
  80. package/lib/node/utils/index.d.ts +2 -0
  81. package/lib/node/utils/index.js +2 -0
  82. package/lib/node/utils/resolveContainerPluginOptions.d.ts +8 -0
  83. package/lib/node/utils/resolveContainerPluginOptions.js +17 -0
  84. package/lib/shared/index.d.ts +3 -0
  85. package/lib/shared/index.js +3 -0
  86. package/lib/{types → shared}/nav.d.ts +11 -12
  87. package/lib/shared/nav.js +1 -0
  88. package/lib/{types → shared}/options.d.ts +49 -11
  89. package/lib/shared/options.js +1 -0
  90. package/lib/{types → shared}/page.d.ts +14 -6
  91. package/lib/shared/page.js +1 -0
  92. package/package.json +47 -29
  93. package/templates/build.html +33 -0
  94. package/CHANGELOG.md +0 -368
  95. package/lib/clientAppEnhance.d.ts +0 -3
  96. package/lib/clientAppEnhance.js +0 -30
  97. package/lib/clientAppSetup.d.ts +0 -2
  98. package/lib/clientAppSetup.js +0 -11
  99. package/lib/components/DropdownLink.vue +0 -141
  100. package/lib/components/DropdownTransition.vue +0 -34
  101. package/lib/components/Home.vue +0 -133
  102. package/lib/components/NavLink.vue +0 -115
  103. package/lib/components/Navbar.vue +0 -114
  104. package/lib/components/Sidebar.vue +0 -38
  105. package/lib/components/SidebarChild.d.ts +0 -6
  106. package/lib/components/SidebarChild.js +0 -91
  107. package/lib/components/ToggleSidebarButton.vue +0 -27
  108. package/lib/components/global/Badge.vue +0 -37
  109. package/lib/components/global/CodeGroup.js +0 -52
  110. package/lib/components/global/CodeGroupItem.vue +0 -25
  111. package/lib/components/global/OutboundLink.vue +0 -30
  112. package/lib/composables/index.d.ts +0 -5
  113. package/lib/composables/index.js +0 -5
  114. package/lib/composables/useSidebarItems.js +0 -114
  115. package/lib/index.d.ts +0 -6
  116. package/lib/index.js +0 -67
  117. package/lib/layouts/404.vue +0 -38
  118. package/lib/layouts/Layout.vue +0 -152
  119. package/lib/node/assignDefaultLocaleOptions.d.ts +0 -5
  120. package/lib/node/resolveActiveHeaderLinksPluginOptions.d.ts +0 -6
  121. package/lib/node/resolveActiveHeaderLinksPluginOptions.js +0 -16
  122. package/lib/node/resolveContainerPluginOptions.d.ts +0 -26
  123. package/lib/node/resolveContainerPluginOptions.js +0 -79
  124. package/lib/node/resolveGitPluginOptions.d.ts +0 -6
  125. package/lib/node/resolveGitPluginOptions.js +0 -22
  126. package/lib/node/resolveMediumZoomPluginOptions.d.ts +0 -6
  127. package/lib/node/resolveMediumZoomPluginOptions.js +0 -17
  128. package/lib/styles/_normalize.scss +0 -148
  129. package/lib/styles/_variables.scss +0 -34
  130. package/lib/styles/custom-container.scss +0 -78
  131. package/lib/styles/plugins.scss +0 -18
  132. package/lib/styles/sidebar.scss +0 -152
  133. package/lib/styles/sr-only.scss +0 -12
  134. package/lib/styles/transitions.scss +0 -13
  135. package/lib/types/index.d.ts +0 -3
  136. package/lib/types/index.js +0 -15
  137. package/lib/types/nav.js +0 -2
  138. package/lib/types/options.js +0 -2
  139. package/lib/types/page.js +0 -2
  140. package/lib/utils/index.d.ts +0 -2
  141. package/lib/utils/index.js +0 -2
  142. package/lib/utils/resolveRepoType.d.ts +0 -2
@@ -0,0 +1,114 @@
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
+ <script setup lang="ts">
12
+ import { useSiteData } from '@vuepress/client'
13
+ import { isLinkHttp, isLinkMailto, isLinkTel } from '@vuepress/shared'
14
+ import { computed, toRefs } from 'vue'
15
+ import type { PropType } from 'vue'
16
+ import { useRoute } from 'vue-router'
17
+ import type { NavLink } from '../../shared/index.js'
18
+
19
+ const props = defineProps({
20
+ item: {
21
+ type: Object as PropType<NavLink>,
22
+ required: true,
23
+ },
24
+ })
25
+
26
+ const route = useRoute()
27
+ const site = useSiteData()
28
+ const { item } = toRefs(props)
29
+
30
+ // if the link has http protocol
31
+ const hasHttpProtocol = computed(() => isLinkHttp(item.value.link))
32
+ // if the link has non-http protocol
33
+ const hasNonHttpProtocol = computed(
34
+ () => isLinkMailto(item.value.link) || isLinkTel(item.value.link)
35
+ )
36
+ // resolve the `target` attr
37
+ const linkTarget = computed(() => {
38
+ if (hasNonHttpProtocol.value) return undefined
39
+ if (item.value.target) return item.value.target
40
+ if (hasHttpProtocol.value) return '_blank'
41
+ return undefined
42
+ })
43
+ // if the `target` attr is '_blank'
44
+ const isBlankTarget = computed(() => linkTarget.value === '_blank')
45
+ // is `<RouterLink>` or not
46
+ const isRouterLink = computed(
47
+ () =>
48
+ !hasHttpProtocol.value && !hasNonHttpProtocol.value && !isBlankTarget.value
49
+ )
50
+ // resolve the `rel` attr
51
+ const linkRel = computed(() => {
52
+ if (hasNonHttpProtocol.value) return undefined
53
+ if (item.value.rel) return item.value.rel
54
+ if (isBlankTarget.value) return 'noopener noreferrer'
55
+ return undefined
56
+ })
57
+ // resolve the `aria-label` attr
58
+ const linkAriaLabel = computed(() => item.value.ariaLabel || item.value.text)
59
+
60
+ // should be active when current route is a subpath of this link
61
+ const shouldBeActiveInSubpath = computed(() => {
62
+ const localeKeys = Object.keys(site.value.locales)
63
+ if (localeKeys.length) {
64
+ return !localeKeys.some((key) => key === item.value.link)
65
+ }
66
+ return item.value.link !== '/'
67
+ })
68
+ // if this link is active in subpath
69
+ const isActiveInSubpath = computed(() => {
70
+ if (!shouldBeActiveInSubpath.value) {
71
+ return false
72
+ }
73
+ return route.path.startsWith(item.value.link)
74
+ })
75
+
76
+ // if this link is active
77
+ const isActive = computed(() => {
78
+ if (!isRouterLink.value) {
79
+ return false
80
+ }
81
+ if (item.value.activeMatch) {
82
+ return new RegExp(item.value.activeMatch).test(route.path)
83
+ }
84
+ return isActiveInSubpath.value
85
+ })
86
+ </script>
87
+
88
+ <template>
89
+ <RouterLink
90
+ v-if="isRouterLink"
91
+ :class="{ 'router-link-active': isActive }"
92
+ :to="item.link"
93
+ :aria-label="linkAriaLabel"
94
+ v-bind="$attrs"
95
+ >
96
+ <slot name="before" />
97
+ {{ item.text }}
98
+ <slot name="after" />
99
+ </RouterLink>
100
+ <a
101
+ v-else
102
+ class="external-link"
103
+ :href="item.link"
104
+ :rel="linkRel"
105
+ :target="linkTarget"
106
+ :aria-label="linkAriaLabel"
107
+ v-bind="$attrs"
108
+ >
109
+ <slot name="before" />
110
+ {{ item.text }}
111
+ <AutoLinkExternalIcon v-if="isBlankTarget" />
112
+ <slot name="after" />
113
+ </a>
114
+ </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">
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/index.js'
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/index.js'
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/index.js'
13
+ import { useDarkMode } from '../composables/index.js'
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,75 @@
1
+ <script setup lang="ts">
2
+ import NavbarBrand from '@theme/NavbarBrand.vue'
3
+ import NavbarItems from '@theme/NavbarItems.vue'
4
+ import ToggleColorModeButton from '@theme/ToggleColorModeButton.vue'
5
+ import ToggleSidebarButton from '@theme/ToggleSidebarButton.vue'
6
+ import { computed, onMounted, ref } from 'vue'
7
+ import { useThemeLocaleData } from '../composables/index.js'
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
+
26
+ // avoid overlapping of long title and long navbar links
27
+ onMounted(() => {
28
+ // TODO: migrate to css var
29
+ // refer to _variables.scss
30
+ const MOBILE_DESKTOP_BREAKPOINT = 719
31
+ const navbarHorizontalPadding =
32
+ getCssValue(navbar.value, 'paddingLeft') +
33
+ getCssValue(navbar.value, 'paddingRight')
34
+ const handleLinksWrapWidth = (): void => {
35
+ if (window.innerWidth <= MOBILE_DESKTOP_BREAKPOINT) {
36
+ linksWrapperMaxWidth.value = 0
37
+ } else {
38
+ linksWrapperMaxWidth.value =
39
+ navbar.value!.offsetWidth -
40
+ navbarHorizontalPadding -
41
+ (navbarBrand.value?.offsetWidth || 0)
42
+ }
43
+ }
44
+ handleLinksWrapWidth()
45
+ window.addEventListener('resize', handleLinksWrapWidth, false)
46
+ window.addEventListener('orientationchange', handleLinksWrapWidth, false)
47
+ })
48
+
49
+ function getCssValue(el: HTMLElement | null, property: string): number {
50
+ // NOTE: Known bug, will return 'auto' if style value is 'auto'
51
+ const val = el?.ownerDocument?.defaultView?.getComputedStyle(el, null)?.[
52
+ property
53
+ ]
54
+ const num = Number.parseInt(val, 10)
55
+ return Number.isNaN(num) ? 0 : num
56
+ }
57
+ </script>
58
+
59
+ <template>
60
+ <header ref="navbar" class="navbar">
61
+ <ToggleSidebarButton @toggle="$emit('toggle-sidebar')" />
62
+
63
+ <span ref="navbarBrand">
64
+ <NavbarBrand />
65
+ </span>
66
+
67
+ <div class="navbar-items-wrapper" :style="linksWrapperStyle">
68
+ <slot name="before" />
69
+ <NavbarItems class="can-hide" />
70
+ <slot name="after" />
71
+ <ToggleColorModeButton v-if="themeLocale.colorModeSwitch" />
72
+ <NavbarSearch />
73
+ </div>
74
+ </header>
75
+ </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/index.js'
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/index.js'
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>
@@ -1,28 +1,18 @@
1
- <template>
2
- <nav v-if="navbarLinks.length" class="navbar-links">
3
- <div v-for="item in navbarLinks" :key="item.link" class="navbar-links-item">
4
- <template v-if="item.children">
5
- <DropdownLink :item="item" />
6
- </template>
7
-
8
- <template v-else>
9
- <NavLink :item="item" />
10
- </template>
11
- </div>
12
- </nav>
13
- </template>
14
-
15
- <script lang="ts">
16
- import { computed, defineComponent } from 'vue'
1
+ <script setup lang="ts">
2
+ import AutoLink from '@theme/AutoLink.vue'
3
+ import NavbarDropdown from '@theme/NavbarDropdown.vue'
4
+ import { useRouteLocale, useSiteLocaleData } from '@vuepress/client'
5
+ import { isLinkHttp, isString } from '@vuepress/shared'
6
+ import { computed } from 'vue'
17
7
  import type { ComputedRef } from 'vue'
18
8
  import { useRouter } from 'vue-router'
19
- import { useRouteLocale, useSiteLocaleData } from '@vuepress/client'
20
- import { isString } from '@vuepress/shared'
21
- import { useNavLink, useThemeLocaleData } from '../composables'
22
- import type { NavbarItem, NavbarGroup, ResolvedNavbarItem } from '../types'
23
- import { resolveRepoType } from '../utils'
24
- import DropdownLink from './DropdownLink.vue'
25
- import NavLink from './NavLink.vue'
9
+ import type {
10
+ NavbarGroup,
11
+ NavbarItem,
12
+ ResolvedNavbarItem,
13
+ } from '../../shared/index.js'
14
+ import { useNavLink, useThemeLocaleData } from '../composables/index.js'
15
+ import { resolveRepoType } from '../utils/index.js'
26
16
 
27
17
  /**
28
18
  * Get navbar config of select language dropdown
@@ -41,12 +31,16 @@ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
41
31
  }
42
32
  const currentPath = router.currentRoute.value.path
43
33
  const currentFullPath = router.currentRoute.value.fullPath
34
+ const currentHash = router.currentRoute.value.hash
44
35
 
45
36
  const languageDropdown: ResolvedNavbarItem = {
46
- text: themeLocale.value.selectLanguageText ?? 'unkown language',
47
- ariaLabel: themeLocale.value.selectLanguageAriaLabel ?? 'unkown language',
37
+ text: themeLocale.value.selectLanguageText ?? 'unknown language',
38
+ ariaLabel:
39
+ themeLocale.value.selectLanguageAriaLabel ??
40
+ themeLocale.value.selectLanguageText ??
41
+ 'unknown language',
48
42
  children: localePaths.map((targetLocalePath) => {
49
- // target locale config of this langauge link
43
+ // target locale config of this language link
50
44
  const targetSiteLocale =
51
45
  siteLocale.value.locales?.[targetLocalePath] ?? {}
52
46
  const targetThemeLocale =
@@ -71,7 +65,8 @@ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
71
65
  if (
72
66
  router.getRoutes().some((item) => item.path === targetLocalePage)
73
67
  ) {
74
- link = targetLocalePage
68
+ // try to keep current hash across languages
69
+ link = `${targetLocalePage}${currentHash}`
75
70
  } else {
76
71
  link = targetThemeLocale.home ?? targetLocalePath
77
72
  }
@@ -100,9 +95,10 @@ const useNavbarRepo = (): ComputedRef<ResolvedNavbarItem[]> => {
100
95
  )
101
96
 
102
97
  const repoLink = computed(() => {
103
- if (repoType.value === 'GitHub') {
98
+ if (repo.value && !isLinkHttp(repo.value)) {
104
99
  return `https://github.com/${repo.value}`
105
100
  }
101
+
106
102
  return repo.value
107
103
  })
108
104
 
@@ -147,28 +143,21 @@ const useNavbarConfig = (): ComputedRef<ResolvedNavbarItem[]> => {
147
143
  return computed(() => (themeLocale.value.navbar || []).map(resolveNavbarItem))
148
144
  }
149
145
 
150
- export default defineComponent({
151
- name: 'NavbarLinks',
152
-
153
- components: {
154
- NavLink,
155
- DropdownLink,
156
- },
157
-
158
- setup() {
159
- const navbarConfig = useNavbarConfig()
160
- const navbarSelectLanguage = useNavbarSelectLanguage()
161
- const navbarRepo = useNavbarRepo()
162
-
163
- const navbarLinks = computed(() => [
164
- ...navbarConfig.value,
165
- ...navbarSelectLanguage.value,
166
- ...navbarRepo.value,
167
- ])
168
-
169
- return {
170
- navbarLinks,
171
- }
172
- },
173
- })
146
+ const navbarConfig = useNavbarConfig()
147
+ const navbarSelectLanguage = useNavbarSelectLanguage()
148
+ const navbarRepo = useNavbarRepo()
149
+ const navbarLinks = computed(() => [
150
+ ...navbarConfig.value,
151
+ ...navbarSelectLanguage.value,
152
+ ...navbarRepo.value,
153
+ ])
174
154
  </script>
155
+
156
+ <template>
157
+ <nav v-if="navbarLinks.length" class="navbar-items">
158
+ <div v-for="item in navbarLinks" :key="item.text" class="navbar-item">
159
+ <NavbarDropdown v-if="item.children" :item="item" />
160
+ <AutoLink v-else :item="item" />
161
+ </div>
162
+ </nav>
163
+ </template>