@vuepress/theme-default 2.0.0-beta.46 → 2.0.0-beta.49

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.
@@ -5,14 +5,15 @@ import { defineComponent } from 'vue'
5
5
  export default defineComponent({
6
6
  inheritAttrs: false,
7
7
  })
8
+ /* eslint-enable import/order */
8
9
  </script>
9
10
 
10
11
  <script setup lang="ts">
12
+ import { useSiteData } from '@vuepress/client'
13
+ import { isLinkHttp, isLinkMailto, isLinkTel } from '@vuepress/shared'
11
14
  import { computed, toRefs } from 'vue'
12
15
  import type { PropType } from 'vue'
13
16
  import { useRoute } from 'vue-router'
14
- import { useSiteData } from '@vuepress/client'
15
- import { isLinkHttp, isLinkMailto, isLinkTel } from '@vuepress/shared'
16
17
  import type { NavLink } from '../../shared'
17
18
 
18
19
  const props = defineProps({
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="theme-default-content custom">
2
+ <div class="theme-default-content">
3
3
  <Content />
4
4
  </div>
5
5
  </template>
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import NavbarBrand from '@theme/NavbarBrand.vue'
3
3
  import NavbarItems from '@theme/NavbarItems.vue'
4
- import ToggleDarkModeButton from '@theme/ToggleDarkModeButton.vue'
4
+ import ToggleColorModeButton from '@theme/ToggleColorModeButton.vue'
5
5
  import ToggleSidebarButton from '@theme/ToggleSidebarButton.vue'
6
6
  import { computed, onMounted, ref } from 'vue'
7
7
  import { useThemeLocaleData } from '../composables'
@@ -22,7 +22,6 @@ const linksWrapperStyle = computed(() => {
22
22
  maxWidth: linksWrapperMaxWidth.value + 'px',
23
23
  }
24
24
  })
25
- const enableDarkMode = computed(() => themeLocale.value.darkMode)
26
25
 
27
26
  // avoid overlapping of long title and long navbar links
28
27
  onMounted(() => {
@@ -69,7 +68,7 @@ function getCssValue(el: HTMLElement | null, property: string): number {
69
68
  <slot name="before" />
70
69
  <NavbarItems class="can-hide" />
71
70
  <slot name="after" />
72
- <ToggleDarkModeButton v-if="enableDarkMode" />
71
+ <ToggleColorModeButton v-if="themeLocale.colorModeSwitch" />
73
72
  <NavbarSearch />
74
73
  </div>
75
74
  </header>
@@ -27,12 +27,16 @@ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
27
27
  }
28
28
  const currentPath = router.currentRoute.value.path
29
29
  const currentFullPath = router.currentRoute.value.fullPath
30
+ const currentHash = router.currentRoute.value.hash
30
31
 
31
32
  const languageDropdown: ResolvedNavbarItem = {
32
33
  text: themeLocale.value.selectLanguageText ?? 'unknown language',
33
- ariaLabel: themeLocale.value.selectLanguageAriaLabel ?? 'unkown language',
34
+ ariaLabel:
35
+ themeLocale.value.selectLanguageAriaLabel ??
36
+ themeLocale.value.selectLanguageText ??
37
+ 'unknown language',
34
38
  children: localePaths.map((targetLocalePath) => {
35
- // target locale config of this langauge link
39
+ // target locale config of this language link
36
40
  const targetSiteLocale =
37
41
  siteLocale.value.locales?.[targetLocalePath] ?? {}
38
42
  const targetThemeLocale =
@@ -57,7 +61,8 @@ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
57
61
  if (
58
62
  router.getRoutes().some((item) => item.path === targetLocalePage)
59
63
  ) {
60
- link = targetLocalePage
64
+ // try to keep current hash across languages
65
+ link = `${targetLocalePage}${currentHash}`
61
66
  } else {
62
67
  link = targetThemeLocale.home ?? targetLocalePath
63
68
  }
@@ -1,10 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import AutoLink from '@theme/AutoLink.vue'
3
- import {
4
- usePageData,
5
- usePageFrontmatter,
6
- useSiteLocaleData,
7
- } from '@vuepress/client'
3
+ import { usePageData, usePageFrontmatter } from '@vuepress/client'
8
4
  import { computed } from 'vue'
9
5
  import type { ComputedRef } from 'vue'
10
6
  import type {
@@ -1,7 +1,8 @@
1
1
  <script setup lang="ts">
2
2
  import AutoLink from '@theme/AutoLink.vue'
3
3
  import DropdownTransition from '@theme/DropdownTransition.vue'
4
- import { computed, ref, toRefs } from 'vue'
4
+ import { useToggle } from '@vueuse/core'
5
+ import { computed, nextTick, onBeforeUnmount, toRefs } from 'vue'
5
6
  import type { PropType } from 'vue'
6
7
  import { useRoute, useRouter } from 'vue-router'
7
8
  import type { ResolvedSidebarItem } from '../../shared'
@@ -31,21 +32,24 @@ const itemClass = computed(() => ({
31
32
  'collapsible': item.value.collapsible,
32
33
  }))
33
34
 
34
- const isOpen = ref(true)
35
- const onClick = ref<(() => void) | undefined>(undefined)
36
-
37
- if (item.value.collapsible) {
38
- // active item is open by default
39
- isOpen.value = isActive.value
40
- // toggle open status on click
41
- onClick.value = () => {
42
- isOpen.value = !isOpen.value
35
+ const [isOpen, toggleIsOpen] = useToggle(isActive.value)
36
+ const onClick = (e: Event): void => {
37
+ if (item.value.collapsible) {
38
+ e.preventDefault()
39
+ // toggle open status on click
40
+ toggleIsOpen()
43
41
  }
44
- // reset open status after navigation
45
- router.afterEach(() => {
46
- isOpen.value = isActive.value
47
- })
48
42
  }
43
+
44
+ // reset open status after navigation
45
+ const unregisterRouterHook = router.afterEach((to) => {
46
+ nextTick(() => {
47
+ isOpen.value = item.value.collapsible ? isActive.value : true
48
+ })
49
+ })
50
+ onBeforeUnmount(() => {
51
+ unregisterRouterHook()
52
+ })
49
53
  </script>
50
54
 
51
55
  <template>
@@ -50,7 +50,7 @@ onMounted(() => {
50
50
  <ul v-if="sidebarItems.length" class="sidebar-items">
51
51
  <SidebarItem
52
52
  v-for="item in sidebarItems"
53
- :key="item.link || item.text"
53
+ :key="`${item.text}${item.link}`"
54
54
  :item="item"
55
55
  />
56
56
  </ul>
@@ -4,16 +4,16 @@ import { useDarkMode, useThemeLocaleData } from '../composables'
4
4
  const themeLocale = useThemeLocaleData()
5
5
  const isDarkMode = useDarkMode()
6
6
 
7
- const toggleDarkMode = (): void => {
7
+ const toggleColorMode = (): void => {
8
8
  isDarkMode.value = !isDarkMode.value
9
9
  }
10
10
  </script>
11
11
 
12
12
  <template>
13
13
  <button
14
- class="toggle-dark-button"
15
- :title="themeLocale.toggleDarkMode"
16
- @click="toggleDarkMode"
14
+ class="toggle-color-mode-button"
15
+ :title="themeLocale.toggleColorMode"
16
+ @click="toggleColorMode"
17
17
  >
18
18
  <svg
19
19
  v-show="!isDarkMode"
@@ -18,12 +18,12 @@ export const useDarkMode = () => {
18
18
  export const setupDarkMode = () => {
19
19
  const themeLocale = useThemeLocaleData();
20
20
  const isDarkPreferred = usePreferredDark();
21
- const darkStorage = useStorage('vuepress-color-scheme', 'auto');
21
+ const darkStorage = useStorage('vuepress-color-scheme', themeLocale.value.colorMode);
22
22
  const isDarkMode = computed({
23
23
  get() {
24
- // disable dark mode
25
- if (!themeLocale.value.darkMode) {
26
- return false;
24
+ // disable color mode switching
25
+ if (!themeLocale.value.colorModeSwitch) {
26
+ return themeLocale.value.colorMode === 'dark';
27
27
  }
28
28
  // auto detected from prefers-color-scheme
29
29
  if (darkStorage.value === 'auto') {
@@ -14,12 +14,14 @@ const homeText = themeLocale.value.backToHome ?? 'Back to home'
14
14
 
15
15
  <template>
16
16
  <div class="theme-container">
17
- <div class="theme-default-content">
18
- <h1>404</h1>
17
+ <main class="page">
18
+ <div class="theme-default-content">
19
+ <h1>404</h1>
19
20
 
20
- <blockquote>{{ getMsg() }}</blockquote>
21
+ <blockquote>{{ getMsg() }}</blockquote>
21
22
 
22
- <RouterLink :to="homeLink">{{ homeText }}</RouterLink>
23
- </div>
23
+ <RouterLink :to="homeLink">{{ homeText }}</RouterLink>
24
+ </div>
25
+ </main>
24
26
  </div>
25
27
  </template>
@@ -4,7 +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 { usePageData, usePageFrontmatter } from '@vuepress/client'
7
- import { computed, onMounted, onUnmounted, ref, Transition } from 'vue'
7
+ import { computed, onMounted, onUnmounted, ref } from 'vue'
8
8
  import { useRouter } from 'vue-router'
9
9
  import type { DefaultThemePageFrontmatter } from '../../shared'
10
10
  import {
@@ -101,6 +101,11 @@
101
101
  }
102
102
  }
103
103
 
104
+ .theme-default-content {
105
+ padding: 0;
106
+ margin: 0;
107
+ }
108
+
104
109
  .footer {
105
110
  padding: 2.5rem;
106
111
  border-top: 1px solid var(--c-border);
@@ -86,14 +86,16 @@
86
86
  }
87
87
 
88
88
  &.no-navbar {
89
- .theme-default-content:not(.custom) > h1,
90
- h2,
91
- h3,
92
- h4,
93
- h5,
94
- h6 {
95
- margin-top: 1.5rem;
96
- padding-top: 0;
89
+ .theme-default-content {
90
+ h1,
91
+ h2,
92
+ h3,
93
+ h4,
94
+ h5,
95
+ h6 {
96
+ margin-top: 1.5rem;
97
+ padding-top: 0;
98
+ }
97
99
  }
98
100
 
99
101
  .page {
@@ -118,13 +120,21 @@
118
120
  }
119
121
  }
120
122
 
121
- h1,
122
- h2,
123
- h3,
124
- h4,
125
- h5,
126
- h6 {
127
- .theme-default-content:not(.custom) > & {
123
+ .theme-default-content {
124
+ a:hover {
125
+ text-decoration: underline;
126
+ }
127
+
128
+ img {
129
+ max-width: 100%;
130
+ }
131
+
132
+ h1,
133
+ h2,
134
+ h3,
135
+ h4,
136
+ h5,
137
+ h6 {
128
138
  margin-top: calc(0.5rem - var(--navbar-height));
129
139
  padding-top: calc(1rem + var(--navbar-height));
130
140
  margin-bottom: 0;
@@ -141,29 +151,6 @@ h6 {
141
151
  }
142
152
  }
143
153
 
144
- .theme-default-content:not(.custom) {
145
- @include content_wrapper;
146
-
147
- padding-top: 0;
148
-
149
- a:hover {
150
- text-decoration: underline;
151
- }
152
-
153
- img {
154
- max-width: 100%;
155
- }
156
- }
157
-
158
- .theme-default-content.custom {
159
- padding: 0;
160
- margin: 0;
161
-
162
- img {
163
- max-width: 100%;
164
- }
165
- }
166
-
167
154
  // narrow desktop / iPad
168
155
  @media (max-width: $MQNarrow) {
169
156
  .sidebar {
@@ -152,9 +152,9 @@
152
152
  }
153
153
 
154
154
  /**
155
- * toggle dark button
155
+ * toggle color mode button
156
156
  */
157
- .toggle-dark-button {
157
+ .toggle-color-mode-button {
158
158
  display: flex;
159
159
  margin: auto;
160
160
  margin-left: 1rem;
@@ -129,6 +129,7 @@ a.header-anchor {
129
129
  padding-right: 0.23em;
130
130
  margin-top: 0.125em;
131
131
  opacity: 0;
132
+ user-select: none;
132
133
 
133
134
  &:hover {
134
135
  text-decoration: none;
@@ -4,6 +4,11 @@
4
4
  .page {
5
5
  padding-bottom: 2rem;
6
6
  display: block;
7
+
8
+ .theme-default-content {
9
+ @include content_wrapper;
10
+ padding-top: 0;
11
+ }
7
12
  }
8
13
 
9
14
  .page-meta {
@@ -79,20 +79,20 @@
79
79
  box-sizing: border-box;
80
80
  margin: 0;
81
81
 
82
+ + .sidebar-item-children {
83
+ @include dropdown_wrapper;
84
+ margin-bottom: 0.75rem;
85
+ }
86
+
82
87
  &.collapsible {
83
88
  cursor: pointer;
84
89
 
85
- & + .sidebar-item-children {
86
- @include dropdown_wrapper;
87
- margin-bottom: 0.75rem;
90
+ .arrow {
91
+ position: relative;
92
+ top: -0.12em;
93
+ left: 0.5em;
88
94
  }
89
95
  }
90
-
91
- .arrow {
92
- position: relative;
93
- top: -0.12em;
94
- left: 0.5em;
95
- }
96
96
  }
97
97
 
98
98
  &:not(.sidebar-heading) {
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assignDefaultLocaleOptions = exports.DEFAULT_LOCALE_DATA = exports.DEFAULT_LOCALE_OPTIONS = void 0;
4
4
  exports.DEFAULT_LOCALE_OPTIONS = {
5
+ // color mode
6
+ colorMode: 'auto',
7
+ colorModeSwitch: true,
5
8
  // navbar
6
9
  navbar: [],
7
10
  logo: null,
8
- darkMode: true,
9
11
  repo: null,
10
12
  selectLanguageText: 'Languages',
11
13
  selectLanguageAriaLabel: 'Select language',
@@ -29,7 +31,7 @@ exports.DEFAULT_LOCALE_OPTIONS = {
29
31
  backToHome: 'Take me home',
30
32
  // a11y
31
33
  openInNewWindow: 'open in new window',
32
- toggleDarkMode: 'toggle dark mode',
34
+ toggleColorMode: 'toggle color mode',
33
35
  toggleSidebar: 'toggle sidebar',
34
36
  };
35
37
  exports.DEFAULT_LOCALE_DATA = {
@@ -45,6 +45,18 @@ export interface DefaultThemePluginsOptions {
45
45
  export declare type DefaultThemeLocaleOptions = DefaultThemeData;
46
46
  export declare type DefaultThemeData = ThemeData<DefaultThemeLocaleData>;
47
47
  export interface DefaultThemeLocaleData extends LocaleData {
48
+ /**
49
+ * Default color mode
50
+ *
51
+ * @default 'auto'
52
+ */
53
+ colorMode?: 'auto' | 'dark' | 'light';
54
+ /**
55
+ * Enable color mode switching and display a button in navbar or not
56
+ *
57
+ * @default true
58
+ */
59
+ colorModeSwitch?: boolean;
48
60
  /**
49
61
  * Home path of current locale
50
62
  *
@@ -69,12 +81,6 @@ export interface DefaultThemeLocaleData extends LocaleData {
69
81
  * Logo to display in navbar in dark mode
70
82
  */
71
83
  logoDark?: null | string;
72
- /**
73
- * Navbar dark mode button config
74
- *
75
- * Enable dark mode switching and display a button in navbar or not
76
- */
77
- darkMode?: boolean;
78
84
  /**
79
85
  * Navbar repository config
80
86
  *
@@ -122,9 +128,9 @@ export interface DefaultThemeLocaleData extends LocaleData {
122
128
  * - ...
123
129
  *
124
130
  * The max value depends on which headers you have extracted
125
- * via `markdown.extractHeaders.level`.
131
+ * via `markdown.headers.level`.
126
132
  *
127
- * The default value of `markdown.extractHeaders.level` is `[2, 3]`,
133
+ * The default value of `markdown.headers.level` is `[2, 3]`,
128
134
  * so the default max value of `sidebarDepth` is `2`
129
135
  */
130
136
  sidebarDepth?: number;
@@ -227,9 +233,9 @@ export interface DefaultThemeLocaleData extends LocaleData {
227
233
  */
228
234
  openInNewWindow?: string;
229
235
  /**
230
- * A11y text for dark mode toggle button
236
+ * A11y text for color mode toggle button
231
237
  */
232
- toggleDarkMode?: string;
238
+ toggleColorMode?: string;
233
239
  /**
234
240
  * A11y text for sidebar toggle button
235
241
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/theme-default",
3
- "version": "2.0.0-beta.46",
3
+ "version": "2.0.0-beta.49",
4
4
  "description": "Default theme of VuePress",
5
5
  "keywords": [
6
6
  "vuepress-theme",
@@ -25,24 +25,24 @@
25
25
  "templates"
26
26
  ],
27
27
  "dependencies": {
28
- "@vuepress/client": "2.0.0-beta.46",
29
- "@vuepress/core": "2.0.0-beta.46",
30
- "@vuepress/plugin-active-header-links": "2.0.0-beta.46",
31
- "@vuepress/plugin-back-to-top": "2.0.0-beta.46",
32
- "@vuepress/plugin-container": "2.0.0-beta.46",
33
- "@vuepress/plugin-external-link-icon": "2.0.0-beta.46",
34
- "@vuepress/plugin-git": "2.0.0-beta.46",
35
- "@vuepress/plugin-medium-zoom": "2.0.0-beta.46",
36
- "@vuepress/plugin-nprogress": "2.0.0-beta.46",
37
- "@vuepress/plugin-palette": "2.0.0-beta.46",
38
- "@vuepress/plugin-prismjs": "2.0.0-beta.46",
39
- "@vuepress/plugin-theme-data": "2.0.0-beta.46",
40
- "@vuepress/shared": "2.0.0-beta.46",
41
- "@vuepress/utils": "2.0.0-beta.46",
42
- "@vueuse/core": "^8.4.2",
43
- "sass": "^1.51.0",
44
- "vue": "^3.2.35",
45
- "vue-router": "^4.0.15"
28
+ "@vuepress/client": "2.0.0-beta.49",
29
+ "@vuepress/core": "2.0.0-beta.49",
30
+ "@vuepress/plugin-active-header-links": "2.0.0-beta.49",
31
+ "@vuepress/plugin-back-to-top": "2.0.0-beta.49",
32
+ "@vuepress/plugin-container": "2.0.0-beta.49",
33
+ "@vuepress/plugin-external-link-icon": "2.0.0-beta.49",
34
+ "@vuepress/plugin-git": "2.0.0-beta.49",
35
+ "@vuepress/plugin-medium-zoom": "2.0.0-beta.49",
36
+ "@vuepress/plugin-nprogress": "2.0.0-beta.49",
37
+ "@vuepress/plugin-palette": "2.0.0-beta.49",
38
+ "@vuepress/plugin-prismjs": "2.0.0-beta.49",
39
+ "@vuepress/plugin-theme-data": "2.0.0-beta.49",
40
+ "@vuepress/shared": "2.0.0-beta.49",
41
+ "@vuepress/utils": "2.0.0-beta.49",
42
+ "@vueuse/core": "^8.7.5",
43
+ "sass": "^1.53.0",
44
+ "vue": "^3.2.37",
45
+ "vue-router": "^4.1.2"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "sass-loader": "^13.0.0"