@vuepress/theme-default 2.0.0-rc.103 → 2.0.0-rc.104

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.
@@ -3,7 +3,7 @@ import type { RequiredSlot, Slot } from '@vuepress/helper/client'
3
3
  import type { AutoLinkConfig } from 'vuepress/client'
4
4
  import { AutoLink } from 'vuepress/client'
5
5
 
6
- defineProps<{
6
+ const { config } = defineProps<{
7
7
  /**
8
8
  * The auto link config
9
9
  */
@@ -2,24 +2,20 @@
2
2
  import VPAutoLink from '@theme/VPAutoLink.vue'
3
3
  import { FadeInExpandTransition } from '@vuepress/helper/client'
4
4
  import { useToggle } from '@vueuse/core'
5
- import { computed, toRefs } from 'vue'
5
+ import { computed } from 'vue'
6
6
  import { onContentUpdated } from 'vuepress/client'
7
7
  import type { AutoLinkOptions, NavGroup } from '../../shared/index.js'
8
8
 
9
9
  import '@vuepress/helper/transition/fade-in-height-expand.css'
10
10
 
11
- const props = defineProps<{
11
+ const { config } = defineProps<{
12
12
  /** dropdown config */
13
13
  config: NavGroup<AutoLinkOptions | NavGroup<AutoLinkOptions>>
14
14
  }>()
15
15
 
16
- const { config } = toRefs(props)
17
-
18
16
  const [open, toggleOpen] = useToggle()
19
17
 
20
- const dropdownAriaLabel = computed(
21
- () => config.value.ariaLabel || config.value.text,
22
- )
18
+ const dropdownAriaLabel = computed(() => config.ariaLabel || config.text)
23
19
 
24
20
  const isLastItemOfArray = (arrayItem: unknown, array: unknown[]): boolean =>
25
21
  array[array.length - 1] === arrayItem
@@ -3,33 +3,29 @@ import VPAutoLink from '@theme/VPAutoLink.vue'
3
3
  import VPDropdownTransition from '@theme/VPDropdownTransition.vue'
4
4
  import { isActiveSidebarItem } from '@theme/isActiveSidebarItem'
5
5
  import { useToggle } from '@vueuse/core'
6
- import { computed, nextTick, onBeforeUnmount, toRefs } from 'vue'
6
+ import { computed, nextTick, onBeforeUnmount } from 'vue'
7
7
  import { useRoute, useRouter } from 'vuepress/client'
8
8
  import type { SidebarGroupItem, SidebarItem } from '../typings.js'
9
9
 
10
- const props = withDefaults(
11
- defineProps<{
12
- /**
13
- * The sidebar item to be rendered
14
- */
15
- item: SidebarItem
16
- /**
17
- * The depth of the current sidebar item
18
- */
19
- depth?: number
20
- }>(),
21
- { depth: 0 },
22
- )
10
+ const { item, depth = 0 } = defineProps<{
11
+ /**
12
+ * The sidebar item to be rendered
13
+ */
14
+ item: SidebarItem
15
+ /**
16
+ * The depth of the current sidebar item
17
+ */
18
+ depth?: number
19
+ }>()
23
20
 
24
- const { item, depth } = toRefs(props)
25
21
  const route = useRoute()
26
22
  const router = useRouter()
27
23
 
28
- const collapsible = computed(() => (item.value as SidebarGroupItem).collapsible)
29
- const isActive = computed(() => isActiveSidebarItem(item.value, route))
24
+ const collapsible = computed(() => (item as SidebarGroupItem).collapsible)
25
+ const isActive = computed(() => isActiveSidebarItem(item, route))
30
26
  const itemClass = computed(() => ({
31
27
  'vp-sidebar-item': true,
32
- 'vp-sidebar-heading': depth.value === 0,
28
+ 'vp-sidebar-heading': depth === 0,
33
29
  'active': isActive.value,
34
30
  'collapsible': collapsible.value,
35
31
  }))
@@ -1,27 +1,24 @@
1
1
  <script setup lang="ts">
2
2
  import type { Slot } from '@vuepress/helper/client'
3
3
 
4
- withDefaults(
5
- defineProps<{
6
- /**
7
- * The type of the badge
8
- */
9
- type?: string
10
- /**
11
- * The text of the badge
12
- */
13
- text?: string
14
- /**
15
- * The vertical align of the badge
16
- */
17
- vertical?: string
18
- }>(),
19
- {
20
- type: 'tip',
21
- text: '',
22
- vertical: undefined,
23
- },
24
- )
4
+ const {
5
+ type = 'tip',
6
+ text = '',
7
+ vertical = '',
8
+ } = defineProps<{
9
+ /**
10
+ * The type of the badge
11
+ */
12
+ type?: string
13
+ /**
14
+ * The text of the badge
15
+ */
16
+ text?: string
17
+ /**
18
+ * The vertical align of the badge
19
+ */
20
+ vertical?: string
21
+ }>()
25
22
 
26
23
  defineSlots<{
27
24
  default?: Slot
@@ -32,9 +29,7 @@ defineSlots<{
32
29
  <span
33
30
  class="vp-badge"
34
31
  :class="type"
35
- :style="{
36
- verticalAlign: vertical,
37
- }"
32
+ :style="vertical ? { verticalAlign: vertical } : ''"
38
33
  >
39
34
  <slot>{{ text }}</slot>
40
35
  </span>
@@ -1,6 +1,6 @@
1
1
  import { useData } from '@theme/useData';
2
2
  import { useRoutePaths } from '@vuepress/helper/client';
3
- import { computed } from 'vue';
3
+ import { computed, onMounted, ref } from 'vue';
4
4
  import { useRoute } from 'vuepress/client';
5
5
  /**
6
6
  * Get navbar config of select language dropdown
@@ -9,6 +9,10 @@ export const useNavbarSelectLanguage = () => {
9
9
  const route = useRoute();
10
10
  const routePaths = useRoutePaths();
11
11
  const { routeLocale, site, siteLocale, theme, themeLocale } = useData();
12
+ const isMounted = ref(false);
13
+ onMounted(() => {
14
+ isMounted.value = true;
15
+ });
12
16
  return computed(() => {
13
17
  const localePaths = Object.keys(site.value.locales);
14
18
  // do not display language selection dropdown if there is only one language
@@ -34,7 +38,7 @@ export const useNavbarSelectLanguage = () => {
34
38
  return {
35
39
  text,
36
40
  activeMatch: '.',
37
- link: route.fullPath,
41
+ link: isMounted.value ? currentFullPath : currentPath,
38
42
  };
39
43
  }
40
44
  // if the target language is not current language
@@ -45,7 +49,9 @@ export const useNavbarSelectLanguage = () => {
45
49
  text,
46
50
  // try to keep current hash and params across languages
47
51
  link: routePaths.value.some((item) => item === targetLocalePage)
48
- ? currentFullPath.replace(currentPath, targetLocalePage)
52
+ ? isMounted.value
53
+ ? currentFullPath.replace(currentPath, targetLocalePage)
54
+ : targetLocalePage
49
55
  : (targetThemeLocale.home ?? targetLocalePath),
50
56
  };
51
57
  }),
@@ -1,17 +1,53 @@
1
1
  <script setup lang="ts">
2
2
  import { useData } from '@theme/useData'
3
- import { computed } from 'vue'
3
+ import { computed, onMounted, ref } from 'vue'
4
4
  import { RouteLink } from 'vuepress/client'
5
5
 
6
- const { routeLocale, themeLocale } = useData()
6
+ const { routeLocale, theme, themeLocale } = useData()
7
7
 
8
- const messages = computed(() => themeLocale.value.notFound ?? ['Not Found'])
8
+ const isMounted = ref(false)
9
9
 
10
- const getMsg = (): string =>
11
- messages.value[Math.floor(Math.random() * messages.value.length)]
10
+ // 404 page will fall back to root locale,
11
+ // so we shall use the '/' to avoid SSR mismatch
12
+ const expectedRouteLocale = computed(() =>
13
+ isMounted.value ? routeLocale.value : '/',
14
+ )
12
15
 
13
- const homeLink = computed(() => themeLocale.value.home ?? routeLocale.value)
14
- const homeText = computed(() => themeLocale.value.backToHome ?? 'Back to home')
16
+ // 404 page will fall back to root locale,
17
+ // so we shall use the root theme locale to avoid SSR mismatch
18
+ const expectedThemeLocale = computed(() => {
19
+ if (isMounted.value) return themeLocale.value
20
+
21
+ const { locales, ...baseOptions } = theme.value
22
+
23
+ return {
24
+ ...baseOptions,
25
+ ...locales?.['/'],
26
+ }
27
+ })
28
+
29
+ const homeLink = computed(
30
+ () => expectedThemeLocale.value.home ?? expectedRouteLocale.value,
31
+ )
32
+ const homeText = computed(
33
+ () => expectedThemeLocale.value.backToHome ?? 'Back to home',
34
+ )
35
+
36
+ const messages = computed(
37
+ () => expectedThemeLocale.value.notFound ?? ['Not Found'],
38
+ )
39
+
40
+ const notFoundMsg = computed(() => {
41
+ if (isMounted.value) {
42
+ return messages.value[Math.floor(Math.random() * messages.value.length)]
43
+ }
44
+
45
+ return messages.value[0]
46
+ })
47
+
48
+ onMounted(() => {
49
+ isMounted.value = true
50
+ })
15
51
  </script>
16
52
 
17
53
  <template>
@@ -20,7 +56,7 @@ const homeText = computed(() => themeLocale.value.backToHome ?? 'Back to home')
20
56
  <div vp-content>
21
57
  <h1>404</h1>
22
58
 
23
- <blockquote>{{ getMsg() }}</blockquote>
59
+ <blockquote>{{ notFoundMsg }}</blockquote>
24
60
 
25
61
  <RouteLink :to="homeLink">{{ homeText }}</RouteLink>
26
62
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/theme-default",
3
- "version": "2.0.0-rc.103",
3
+ "version": "2.0.0-rc.104",
4
4
  "description": "Default theme of VuePress",
5
5
  "keywords": [
6
6
  "vuepress-theme",
@@ -42,20 +42,20 @@
42
42
  "templates"
43
43
  ],
44
44
  "dependencies": {
45
- "@vuepress/helper": "2.0.0-rc.103",
45
+ "@vuepress/helper": "2.0.0-rc.104",
46
46
  "@vuepress/plugin-active-header-links": "2.0.0-rc.103",
47
- "@vuepress/plugin-back-to-top": "2.0.0-rc.103",
48
- "@vuepress/plugin-copy-code": "2.0.0-rc.103",
49
- "@vuepress/plugin-git": "2.0.0-rc.103",
50
- "@vuepress/plugin-links-check": "2.0.0-rc.103",
51
- "@vuepress/plugin-markdown-hint": "2.0.0-rc.103",
52
- "@vuepress/plugin-markdown-tab": "2.0.0-rc.103",
53
- "@vuepress/plugin-medium-zoom": "2.0.0-rc.103",
54
- "@vuepress/plugin-nprogress": "2.0.0-rc.103",
55
- "@vuepress/plugin-palette": "2.0.0-rc.103",
56
- "@vuepress/plugin-prismjs": "2.0.0-rc.103",
57
- "@vuepress/plugin-seo": "2.0.0-rc.103",
58
- "@vuepress/plugin-sitemap": "2.0.0-rc.103",
47
+ "@vuepress/plugin-back-to-top": "2.0.0-rc.104",
48
+ "@vuepress/plugin-copy-code": "2.0.0-rc.104",
49
+ "@vuepress/plugin-git": "2.0.0-rc.104",
50
+ "@vuepress/plugin-links-check": "2.0.0-rc.104",
51
+ "@vuepress/plugin-markdown-hint": "2.0.0-rc.104",
52
+ "@vuepress/plugin-markdown-tab": "2.0.0-rc.104",
53
+ "@vuepress/plugin-medium-zoom": "2.0.0-rc.104",
54
+ "@vuepress/plugin-nprogress": "2.0.0-rc.104",
55
+ "@vuepress/plugin-palette": "2.0.0-rc.104",
56
+ "@vuepress/plugin-prismjs": "2.0.0-rc.104",
57
+ "@vuepress/plugin-seo": "2.0.0-rc.104",
58
+ "@vuepress/plugin-sitemap": "2.0.0-rc.104",
59
59
  "@vuepress/plugin-theme-data": "2.0.0-rc.103",
60
60
  "@vueuse/core": "^13.1.0",
61
61
  "vue": "^3.5.13"
@@ -80,5 +80,5 @@
80
80
  "publishConfig": {
81
81
  "access": "public"
82
82
  },
83
- "gitHead": "b730bbcfea25d3b41390e137f086884149e2399e"
83
+ "gitHead": "34f6cf13f83e5c0bd758f44c0a1b372413c6ded9"
84
84
  }