@vuepress/theme-default 2.0.0-beta.28 → 2.0.0-beta.32

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 (49) hide show
  1. package/lib/client/clientAppEnhance.js +4 -5
  2. package/lib/client/components/{NavLink.vue → AutoLink.vue} +28 -29
  3. package/lib/client/components/DropdownTransition.vue +11 -11
  4. package/lib/client/components/Home.vue +12 -110
  5. package/lib/client/components/HomeContent.vue +5 -0
  6. package/lib/client/components/HomeFeatures.vue +23 -0
  7. package/lib/client/components/HomeFooter.vue +17 -0
  8. package/lib/client/components/HomeHero.vue +97 -0
  9. package/lib/client/components/Navbar.vue +24 -58
  10. package/lib/client/components/NavbarBrand.vue +55 -0
  11. package/lib/client/components/{DropdownLink.vue → NavbarDropdown.vue} +64 -64
  12. package/lib/client/components/{NavbarLinks.vue → NavbarItems.vue} +12 -13
  13. package/lib/client/components/Page.vue +5 -5
  14. package/lib/client/components/PageMeta.vue +33 -33
  15. package/lib/client/components/PageNav.vue +20 -20
  16. package/lib/client/components/Sidebar.vue +7 -19
  17. package/lib/client/components/SidebarItem.vue +74 -0
  18. package/lib/client/components/SidebarItems.vue +16 -0
  19. package/lib/client/components/ToggleDarkModeButton.vue +11 -11
  20. package/lib/client/components/ToggleSidebarButton.vue +8 -8
  21. package/lib/client/components/global/Badge.vue +12 -12
  22. package/lib/client/components/global/CodeGroupItem.vue +10 -10
  23. package/lib/client/components/global/{OutboundLink.vue → ExternalLinkIcon.vue} +7 -10
  24. package/lib/client/index.d.ts +2 -2
  25. package/lib/client/layouts/404.vue +12 -12
  26. package/lib/client/layouts/Layout.vue +54 -54
  27. package/lib/client/styles/{_wrapper.scss → _mixins.scss} +6 -1
  28. package/lib/client/styles/code.scss +2 -1
  29. package/lib/client/styles/index.scss +1 -1
  30. package/lib/client/styles/layout.scss +2 -2
  31. package/lib/client/styles/{dropdown.scss → navbar-dropdown.scss} +25 -33
  32. package/lib/client/styles/navbar.scss +8 -8
  33. package/lib/client/styles/normalize.scss +4 -0
  34. package/lib/client/styles/page.scss +5 -5
  35. package/lib/client/styles/sidebar.scss +67 -70
  36. package/lib/client/styles/transitions.scss +11 -2
  37. package/lib/client/styles/vars.scss +5 -0
  38. package/lib/client/utils/index.d.ts +1 -0
  39. package/lib/client/utils/index.js +1 -0
  40. package/lib/client/utils/isActiveSidebarItem.d.ts +3 -0
  41. package/lib/client/utils/isActiveSidebarItem.js +20 -0
  42. package/lib/node/defaultTheme.js +1 -0
  43. package/lib/node/utils/assignDefaultLocaleOptions.d.ts +3 -1
  44. package/lib/node/utils/assignDefaultLocaleOptions.js +5 -5
  45. package/lib/shared/nav.d.ts +10 -4
  46. package/lib/shared/options.d.ts +5 -1
  47. package/package.json +16 -15
  48. package/lib/client/components/SidebarChild.d.ts +0 -6
  49. package/lib/client/components/SidebarChild.js +0 -76
@@ -3,17 +3,16 @@ import { h } from 'vue';
3
3
  import Badge from './components/global/Badge.vue';
4
4
  import CodeGroup from './components/global/CodeGroup';
5
5
  import CodeGroupItem from './components/global/CodeGroupItem.vue';
6
- import OutboundLink from './components/global/OutboundLink.vue';
6
+ import ExternalLinkIcon from './components/global/ExternalLinkIcon.vue';
7
7
  import { useScrollPromise } from './composables';
8
8
  import './styles/index.scss';
9
9
  export default defineClientAppEnhance(({ app, router }) => {
10
10
  app.component('Badge', Badge);
11
11
  app.component('CodeGroup', CodeGroup);
12
12
  app.component('CodeGroupItem', CodeGroupItem);
13
- // unregister the built-in `<OutboundLink>` to avoid warning
14
- delete app._context.components.OutboundLink;
15
- // override the built-in `<OutboundLink>`
16
- app.component('OutboundLink', OutboundLink);
13
+ // override the `<ExternalLinkIcon>` provided by @vuepress/plugin-external-link-icon
14
+ delete app._context.components.ExternalLinkIcon;
15
+ app.component('ExternalLinkIcon', ExternalLinkIcon);
17
16
  // compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
18
17
  app.component('NavbarSearch', () => {
19
18
  const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
@@ -1,32 +1,3 @@
1
- <template>
2
- <RouterLink
3
- v-if="isRouterLink"
4
- class="nav-link"
5
- :class="{ 'router-link-active': isActive }"
6
- :to="item.link"
7
- :aria-label="linkAriaLabel"
8
- v-bind="$attrs"
9
- >
10
- <slot name="before" />
11
- {{ item.text }}
12
- <slot name="after" />
13
- </RouterLink>
14
- <a
15
- v-else
16
- class="nav-link external"
17
- :href="item.link"
18
- :rel="linkRel"
19
- :target="linkTarget"
20
- :aria-label="linkAriaLabel"
21
- v-bind="$attrs"
22
- >
23
- <slot name="before" />
24
- {{ item.text }}
25
- <OutboundLink v-if="isBlankTarget" />
26
- <slot name="after" />
27
- </a>
28
- </template>
29
-
30
1
  <script lang="ts">
31
2
  /* eslint-disable import/first, import/no-duplicates, import/order */
32
3
  import { defineComponent } from 'vue'
@@ -112,3 +83,31 @@ const isActive = computed(() => {
112
83
  return isActiveInSubpath.value
113
84
  })
114
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
+ <ExternalLinkIcon v-if="isBlankTarget" />
111
+ <slot name="after" />
112
+ </a>
113
+ </template>
@@ -1,14 +1,3 @@
1
- <template>
2
- <Transition
3
- name="dropdown"
4
- @enter="setHeight"
5
- @after-enter="unsetHeight"
6
- @before-leave="setHeight"
7
- >
8
- <slot />
9
- </Transition>
10
- </template>
11
-
12
1
  <script setup lang="ts">
13
2
  const setHeight = (items): void => {
14
3
  // explicitly set height so that it can be transitioned
@@ -19,3 +8,14 @@ const unsetHeight = (items): void => {
19
8
  items.style.height = ''
20
9
  }
21
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>
@@ -1,113 +1,15 @@
1
- <template>
2
- <main class="home" :aria-labelledby="heroText ? 'main-title' : undefined">
3
- <header class="hero">
4
- <ClientOnly>
5
- <img v-if="heroImage" :src="withBase(heroImage)" :alt="heroAlt" />
6
- </ClientOnly>
7
-
8
- <h1 v-if="heroText" id="main-title">
9
- {{ heroText }}
10
- </h1>
11
-
12
- <p v-if="tagline" class="description">
13
- {{ tagline }}
14
- </p>
15
-
16
- <p v-if="actions.length" class="actions">
17
- <NavLink
18
- v-for="action in actions"
19
- :key="action.text"
20
- class="action-button"
21
- :class="[action.type]"
22
- :item="action"
23
- />
24
- </p>
25
- </header>
26
-
27
- <div v-if="features.length" class="features">
28
- <div v-for="feature in features" :key="feature.title" class="feature">
29
- <h2>{{ feature.title }}</h2>
30
- <p>{{ feature.details }}</p>
31
- </div>
32
- </div>
33
-
34
- <div class="theme-default-content custom">
35
- <Content />
36
- </div>
1
+ <script setup lang="ts">
2
+ import HomeContent from './HomeContent.vue'
3
+ import HomeFeatures from './HomeFeatures.vue'
4
+ import HomeFooter from './HomeFooter.vue'
5
+ import HomeHero from './HomeHero.vue'
6
+ </script>
37
7
 
38
- <template v-if="footer">
39
- <!-- eslint-disable-next-line vue/no-v-html -->
40
- <div v-if="footerHtml" class="footer" v-html="footer" />
41
- <div v-else class="footer" v-text="footer" />
42
- </template>
8
+ <template>
9
+ <main class="home">
10
+ <HomeHero />
11
+ <HomeFeatures />
12
+ <HomeContent />
13
+ <HomeFooter />
43
14
  </main>
44
15
  </template>
45
-
46
- <script setup lang="ts">
47
- import {
48
- usePageFrontmatter,
49
- useSiteLocaleData,
50
- withBase,
51
- } from '@vuepress/client'
52
- import { isArray } from '@vuepress/shared'
53
- import { computed } from 'vue'
54
- import type { DefaultThemeHomePageFrontmatter } from '../../shared'
55
- import { useDarkMode } from '../composables'
56
- import NavLink from './NavLink.vue'
57
-
58
- const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
59
- const siteLocale = useSiteLocaleData()
60
- const isDarkMode = useDarkMode()
61
-
62
- // hero image and title
63
- const heroImage = computed(() => {
64
- if (isDarkMode.value && frontmatter.value.heroImageDark !== undefined) {
65
- return frontmatter.value.heroImageDark
66
- }
67
- return frontmatter.value.heroImage
68
- })
69
- const heroText = computed(() => {
70
- if (frontmatter.value.heroText === null) {
71
- return null
72
- }
73
- return frontmatter.value.heroText || siteLocale.value.title || 'Hello'
74
- })
75
- const heroAlt = computed(
76
- () => frontmatter.value.heroAlt || heroText.value || 'hero'
77
- )
78
- const tagline = computed(() => {
79
- if (frontmatter.value.tagline === null) {
80
- return null
81
- }
82
- return (
83
- frontmatter.value.tagline ||
84
- siteLocale.value.description ||
85
- 'Welcome to your VuePress site'
86
- )
87
- })
88
-
89
- // action buttons
90
- const actions = computed(() => {
91
- if (!isArray(frontmatter.value.actions)) {
92
- return []
93
- }
94
-
95
- return frontmatter.value.actions.map(({ text, link, type = 'primary' }) => ({
96
- text,
97
- link,
98
- type,
99
- }))
100
- })
101
-
102
- // feature list
103
- const features = computed(() => {
104
- if (isArray(frontmatter.value.features)) {
105
- return frontmatter.value.features
106
- }
107
- return []
108
- })
109
-
110
- // footer
111
- const footer = computed(() => frontmatter.value.footer)
112
- const footerHtml = computed(() => frontmatter.value.footerHtml)
113
- </script>
@@ -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 {
3
+ ClientOnly,
4
+ usePageFrontmatter,
5
+ useSiteLocaleData,
6
+ withBase,
7
+ } from '@vuepress/client'
8
+ import { isArray } from '@vuepress/shared'
9
+ import type { FunctionalComponent } from 'vue'
10
+ import { computed, h } from 'vue'
11
+ import type { DefaultThemeHomePageFrontmatter } from '../../shared'
12
+ import { useDarkMode } from '../composables'
13
+ import AutoLink from './AutoLink.vue'
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>
@@ -1,70 +1,18 @@
1
- <template>
2
- <header ref="navbar" class="navbar">
3
- <ToggleSidebarButton @toggle="$emit('toggle-sidebar')" />
4
-
5
- <span ref="siteBrand">
6
- <RouterLink :to="siteBrandLink">
7
- <!-- logo could be different in dark mode, so we make it client-only to avoid ssr-mismatch -->
8
- <ClientOnly>
9
- <img
10
- v-if="siteBrandLogo"
11
- class="logo"
12
- :src="withBase(siteBrandLogo)"
13
- :alt="siteBrandTitle"
14
- />
15
- </ClientOnly>
16
-
17
- <span
18
- v-if="siteBrandTitle"
19
- class="site-name"
20
- :class="{ 'can-hide': siteBrandLogo }"
21
- >
22
- {{ siteBrandTitle }}
23
- </span>
24
- </RouterLink>
25
- </span>
26
-
27
- <div class="navbar-links-wrapper" :style="linksWrapperStyle">
28
- <slot name="before" />
29
-
30
- <NavbarLinks class="can-hide" />
31
-
32
- <slot name="after" />
33
-
34
- <ToggleDarkModeButton v-if="enableDarkMode" />
35
-
36
- <NavbarSearch />
37
- </div>
38
- </header>
39
- </template>
40
-
41
1
  <script setup lang="ts">
42
- import { useRouteLocale, useSiteLocaleData, withBase } from '@vuepress/client'
43
2
  import { computed, onMounted, ref } from 'vue'
44
- import { useDarkMode, useThemeLocaleData } from '../composables'
45
- import NavbarLinks from './NavbarLinks.vue'
3
+ import { useThemeLocaleData } from '../composables'
4
+ import NavbarBrand from './NavbarBrand.vue'
5
+ import NavbarItems from './NavbarItems.vue'
46
6
  import ToggleDarkModeButton from './ToggleDarkModeButton.vue'
47
7
  import ToggleSidebarButton from './ToggleSidebarButton.vue'
48
8
 
49
9
  defineEmits(['toggle-sidebar'])
50
10
 
51
- const routeLocale = useRouteLocale()
52
- const siteLocale = useSiteLocaleData()
53
11
  const themeLocale = useThemeLocaleData()
54
- const isDarkMode = useDarkMode()
55
12
 
56
13
  const navbar = ref<HTMLElement | null>(null)
57
- const siteBrand = ref<HTMLElement | null>(null)
58
- const siteBrandLink = computed(
59
- () => themeLocale.value.home || routeLocale.value
60
- )
61
- const siteBrandLogo = computed(() => {
62
- if (isDarkMode.value && themeLocale.value.logoDark !== undefined) {
63
- return themeLocale.value.logoDark
64
- }
65
- return themeLocale.value.logo
66
- })
67
- const siteBrandTitle = computed(() => siteLocale.value.title)
14
+ const navbarBrand = ref<HTMLElement | null>(null)
15
+
68
16
  const linksWrapperMaxWidth = ref(0)
69
17
  const linksWrapperStyle = computed(() => {
70
18
  if (!linksWrapperMaxWidth.value) {
@@ -91,7 +39,7 @@ onMounted(() => {
91
39
  linksWrapperMaxWidth.value =
92
40
  navbar.value!.offsetWidth -
93
41
  navbarHorizontalPadding -
94
- (siteBrand.value?.offsetWidth || 0)
42
+ (navbarBrand.value?.offsetWidth || 0)
95
43
  }
96
44
  }
97
45
  handleLinksWrapWidth()
@@ -108,3 +56,21 @@ function getCssValue(el: HTMLElement | null, property: string): number {
108
56
  return Number.isNaN(num) ? 0 : num
109
57
  }
110
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>