@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,106 @@
1
+ import { defineComponent, h, onBeforeUpdate, ref } from 'vue';
2
+ export const CodeGroup = defineComponent({
3
+ name: 'CodeGroup',
4
+ setup(_, { slots }) {
5
+ // index of current active item
6
+ const activeIndex = ref(-1);
7
+ // refs of the tab buttons
8
+ const tabRefs = ref([]);
9
+ if (__VUEPRESS_DEV__) {
10
+ // after removing a code-group-item, we need to clear the ref
11
+ // of the removed item to avoid issues caused by HMR
12
+ onBeforeUpdate(() => {
13
+ tabRefs.value = [];
14
+ });
15
+ }
16
+ // activate next tab
17
+ const activateNext = (i = activeIndex.value) => {
18
+ if (i < tabRefs.value.length - 1) {
19
+ activeIndex.value = i + 1;
20
+ }
21
+ else {
22
+ activeIndex.value = 0;
23
+ }
24
+ tabRefs.value[activeIndex.value].focus();
25
+ };
26
+ // activate previous tab
27
+ const activatePrev = (i = activeIndex.value) => {
28
+ if (i > 0) {
29
+ activeIndex.value = i - 1;
30
+ }
31
+ else {
32
+ activeIndex.value = tabRefs.value.length - 1;
33
+ }
34
+ tabRefs.value[activeIndex.value].focus();
35
+ };
36
+ // handle keyboard event
37
+ const keyboardHandler = (event, i) => {
38
+ if (event.key === ' ' || event.key === 'Enter') {
39
+ event.preventDefault();
40
+ activeIndex.value = i;
41
+ }
42
+ else if (event.key === 'ArrowRight') {
43
+ event.preventDefault();
44
+ activateNext(i);
45
+ }
46
+ else if (event.key === 'ArrowLeft') {
47
+ event.preventDefault();
48
+ activatePrev(i);
49
+ }
50
+ };
51
+ return () => {
52
+ // NOTICE: here we put the `slots.default()` inside the render function to make
53
+ // the slots reactive, otherwise the slot content won't be changed once the
54
+ // `setup()` function of current component is called
55
+ // get children code-group-item
56
+ const items = (slots.default?.() || [])
57
+ .filter((vnode) => vnode.type.name === 'CodeGroupItem')
58
+ .map((vnode) => {
59
+ if (vnode.props === null) {
60
+ vnode.props = {};
61
+ }
62
+ return vnode;
63
+ });
64
+ // do not render anything if there is no code-group-item
65
+ if (items.length === 0) {
66
+ return null;
67
+ }
68
+ if (activeIndex.value < 0 || activeIndex.value > items.length - 1) {
69
+ // if `activeIndex` is invalid
70
+ // find the index of the code-group-item with `active` props
71
+ activeIndex.value = items.findIndex((vnode) => vnode.props.active === '' || vnode.props.active === true);
72
+ // if there is no `active` props on code-group-item, set the first item active
73
+ if (activeIndex.value === -1) {
74
+ activeIndex.value = 0;
75
+ }
76
+ }
77
+ else {
78
+ // set the active item
79
+ items.forEach((vnode, i) => {
80
+ vnode.props.active = i === activeIndex.value;
81
+ });
82
+ }
83
+ return h('div', { class: 'code-group' }, [
84
+ h('div', { class: 'code-group__nav' }, h('ul', { class: 'code-group__ul' }, items.map((vnode, i) => {
85
+ const isActive = i === activeIndex.value;
86
+ return h('li', { class: 'code-group__li' }, h('button', {
87
+ ref: (element) => {
88
+ if (element) {
89
+ tabRefs.value[i] = element;
90
+ }
91
+ },
92
+ class: {
93
+ 'code-group__nav-tab': true,
94
+ 'code-group__nav-tab-active': isActive,
95
+ },
96
+ ariaPressed: isActive,
97
+ ariaExpanded: isActive,
98
+ onClick: () => (activeIndex.value = i),
99
+ onKeydown: (e) => keyboardHandler(e, i),
100
+ }, vnode.props.title));
101
+ }))),
102
+ items,
103
+ ]);
104
+ };
105
+ },
106
+ });
@@ -0,0 +1,31 @@
1
+ <script lang="ts">
2
+ import { defineComponent } from 'vue'
3
+
4
+ export default defineComponent({
5
+ name: 'CodeGroupItem',
6
+ })
7
+ </script>
8
+
9
+ <script setup lang="ts">
10
+ defineProps({
11
+ title: {
12
+ type: String,
13
+ required: true,
14
+ },
15
+ active: {
16
+ type: Boolean,
17
+ required: false,
18
+ default: false,
19
+ },
20
+ })
21
+ </script>
22
+
23
+ <template>
24
+ <div
25
+ class="code-group-item"
26
+ :class="{ 'code-group-item__active': active }"
27
+ :aria-selected="active"
28
+ >
29
+ <slot />
30
+ </div>
31
+ </template>
@@ -0,0 +1,4 @@
1
+ import Badge from './Badge.vue';
2
+ import { CodeGroup } from './CodeGroup.js';
3
+ import CodeGroupItem from './CodeGroupItem.vue';
4
+ export { Badge, CodeGroup, CodeGroupItem };
@@ -0,0 +1,4 @@
1
+ import Badge from './Badge.vue';
2
+ import { CodeGroup } from './CodeGroup.js';
3
+ import CodeGroupItem from './CodeGroupItem.vue';
4
+ export { Badge, CodeGroup, CodeGroupItem };
@@ -0,0 +1,6 @@
1
+ export * from './useDarkMode.js';
2
+ export * from './useNavLink.js';
3
+ export * from './useResolveRouteWithRedirect.js';
4
+ export * from './useScrollPromise.js';
5
+ export * from './useSidebarItems.js';
6
+ export * from './useThemeData.js';
@@ -0,0 +1,6 @@
1
+ export * from './useDarkMode.js';
2
+ export * from './useNavLink.js';
3
+ export * from './useResolveRouteWithRedirect.js';
4
+ export * from './useScrollPromise.js';
5
+ export * from './useSidebarItems.js';
6
+ export * from './useThemeData.js';
@@ -0,0 +1,12 @@
1
+ import type { InjectionKey, WritableComputedRef } from 'vue';
2
+ export declare type DarkModeRef = WritableComputedRef<boolean>;
3
+ export declare const darkModeSymbol: InjectionKey<DarkModeRef>;
4
+ /**
5
+ * Inject dark mode global computed
6
+ */
7
+ export declare const useDarkMode: () => DarkModeRef;
8
+ /**
9
+ * Create dark mode ref and provide as global computed in setup
10
+ */
11
+ export declare const setupDarkMode: () => void;
12
+ export declare const updateHtmlDarkClass: (isDarkMode: DarkModeRef) => void;
@@ -0,0 +1,57 @@
1
+ import { usePreferredDark, useStorage } from '@vueuse/core';
2
+ import { computed, inject, onMounted, onUnmounted, provide, watch } from 'vue';
3
+ import { useThemeLocaleData } from './useThemeData.js';
4
+ export const darkModeSymbol = Symbol(__VUEPRESS_DEV__ ? 'darkMode' : '');
5
+ /**
6
+ * Inject dark mode global computed
7
+ */
8
+ export const useDarkMode = () => {
9
+ const isDarkMode = inject(darkModeSymbol);
10
+ if (!isDarkMode) {
11
+ throw new Error('useDarkMode() is called without provider.');
12
+ }
13
+ return isDarkMode;
14
+ };
15
+ /**
16
+ * Create dark mode ref and provide as global computed in setup
17
+ */
18
+ export const setupDarkMode = () => {
19
+ const themeLocale = useThemeLocaleData();
20
+ const isDarkPreferred = usePreferredDark();
21
+ const darkStorage = useStorage('vuepress-color-scheme', themeLocale.value.colorMode);
22
+ const isDarkMode = computed({
23
+ get() {
24
+ // disable color mode switching
25
+ if (!themeLocale.value.colorModeSwitch) {
26
+ return themeLocale.value.colorMode === 'dark';
27
+ }
28
+ // auto detected from prefers-color-scheme
29
+ if (darkStorage.value === 'auto') {
30
+ return isDarkPreferred.value;
31
+ }
32
+ // storage value
33
+ return darkStorage.value === 'dark';
34
+ },
35
+ set(val) {
36
+ if (val === isDarkPreferred.value) {
37
+ darkStorage.value = 'auto';
38
+ }
39
+ else {
40
+ darkStorage.value = val ? 'dark' : 'light';
41
+ }
42
+ },
43
+ });
44
+ provide(darkModeSymbol, isDarkMode);
45
+ updateHtmlDarkClass(isDarkMode);
46
+ };
47
+ export const updateHtmlDarkClass = (isDarkMode) => {
48
+ const update = (value = isDarkMode.value) => {
49
+ // set `class="dark"` on `<html>` element
50
+ const htmlEl = window?.document.querySelector('html');
51
+ htmlEl?.classList.toggle('dark', value);
52
+ };
53
+ onMounted(() => {
54
+ watch(isDarkMode, update, { immediate: true });
55
+ });
56
+ onUnmounted(() => update());
57
+ };
@@ -1,4 +1,9 @@
1
- import type { NavLink } from '../types';
1
+ import type { NavLink } from '../../shared/index.js';
2
+ declare module 'vue-router' {
3
+ interface RouteMeta {
4
+ title?: string;
5
+ }
6
+ }
2
7
  /**
3
8
  * Resolve NavLink props from string
4
9
  *
@@ -1,4 +1,4 @@
1
- import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect';
1
+ import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect.js';
2
2
  /**
3
3
  * Resolve NavLink props from string
4
4
  *
@@ -7,7 +7,10 @@ import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect';
7
7
  * - Output: { text: 'Home', link: '/' }
8
8
  */
9
9
  export const useNavLink = (item) => {
10
- const resolved = useResolveRouteWithRedirect(item);
10
+ // the route path of vue-router is url-encoded, and we expect users are using
11
+ // non-url-encoded string in theme config, so we need to url-encode it first to
12
+ // resolve the route correctly
13
+ const resolved = useResolveRouteWithRedirect(encodeURI(item));
11
14
  return {
12
15
  text: resolved.meta.title || item,
13
16
  link: resolved.name === '404' ? item : resolved.fullPath,
@@ -2,4 +2,4 @@ import type { Router } from 'vue-router';
2
2
  /**
3
3
  * Resolve a route with redirection
4
4
  */
5
- export declare const useResolveRouteWithRedirect: (to: import("vue-router").RouteLocationRaw) => ReturnType<Router['resolve']>;
5
+ export declare const useResolveRouteWithRedirect: (to: import("vue-router").RouteLocationRaw, currentLocation?: import("vue-router").RouteLocationNormalizedLoaded | undefined) => ReturnType<Router['resolve']>;
@@ -1,5 +1,5 @@
1
- import { useRouter } from 'vue-router';
2
1
  import { isFunction, isString } from '@vuepress/shared';
2
+ import { useRouter } from 'vue-router';
3
3
  /**
4
4
  * Resolve a route with redirection
5
5
  */
@@ -7,7 +7,7 @@ export const useResolveRouteWithRedirect = (...args) => {
7
7
  const router = useRouter();
8
8
  const route = router.resolve(...args);
9
9
  const lastMatched = route.matched[route.matched.length - 1];
10
- if (!(lastMatched === null || lastMatched === void 0 ? void 0 : lastMatched.redirect)) {
10
+ if (!lastMatched?.redirect) {
11
11
  return route;
12
12
  }
13
13
  const { redirect } = lastMatched;
@@ -6,7 +6,7 @@ const scrollPromise = {
6
6
  promise = new Promise((resolve) => (promiseResolve = resolve));
7
7
  },
8
8
  resolve: () => {
9
- promiseResolve === null || promiseResolve === void 0 ? void 0 : promiseResolve();
9
+ promiseResolve?.();
10
10
  promise = null;
11
11
  promiseResolve = null;
12
12
  },
@@ -1,31 +1,36 @@
1
- import type { ComputedRef, InjectionKey } from 'vue';
2
1
  import type { PageHeader } from '@vuepress/client';
3
- import type { DefaultThemeData, DefaultThemePageFrontmatter, SidebarConfigArray, SidebarConfigObject, ResolvedSidebarItem } from '../types';
2
+ import type { ComputedRef, InjectionKey } from 'vue';
3
+ import type { DefaultThemeData, DefaultThemeNormalPageFrontmatter, ResolvedSidebarItem, SidebarConfigArray, SidebarConfigObject } from '../../shared/index.js';
4
4
  export declare type SidebarItemsRef = ComputedRef<ResolvedSidebarItem[]>;
5
5
  export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
6
6
  /**
7
7
  * Inject sidebar items global computed
8
8
  */
9
9
  export declare const useSidebarItems: () => SidebarItemsRef;
10
+ /**
11
+ * Create sidebar items ref and provide as global computed in setup
12
+ */
13
+ export declare const setupSidebarItems: () => void;
10
14
  /**
11
15
  * Resolve sidebar items global computed
12
16
  *
13
17
  * It should only be resolved and provided once
14
18
  */
15
- export declare const resolveSidebarItems: (frontmatter: DefaultThemePageFrontmatter, themeLocale: DefaultThemeData) => ResolvedSidebarItem[];
19
+ export declare const resolveSidebarItems: (frontmatter: DefaultThemeNormalPageFrontmatter, themeLocale: DefaultThemeData) => ResolvedSidebarItem[];
16
20
  /**
17
21
  * Util to transform page header to sidebar item
18
22
  */
19
- export declare const headerToSidebarItem: (header: PageHeader) => ResolvedSidebarItem;
23
+ export declare const headerToSidebarItem: (header: PageHeader, sidebarDepth: number) => ResolvedSidebarItem;
24
+ export declare const headersToSidebarItemChildren: (headers: PageHeader[], sidebarDepth: number) => ResolvedSidebarItem[];
20
25
  /**
21
26
  * Resolve sidebar items if the config is `auto`
22
27
  */
23
- export declare const resolveAutoSidebarItems: () => ResolvedSidebarItem[];
28
+ export declare const resolveAutoSidebarItems: (sidebarDepth: number) => ResolvedSidebarItem[];
24
29
  /**
25
30
  * Resolve sidebar items if the config is an array
26
31
  */
27
- export declare const resolveArraySidebarItems: (sidebarConfig: SidebarConfigArray) => ResolvedSidebarItem[];
32
+ export declare const resolveArraySidebarItems: (sidebarConfig: SidebarConfigArray, sidebarDepth: number) => ResolvedSidebarItem[];
28
33
  /**
29
34
  * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
30
35
  */
31
- export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarConfigObject) => ResolvedSidebarItem[];
36
+ export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarConfigObject, sidebarDepth: number) => ResolvedSidebarItem[];
@@ -0,0 +1,118 @@
1
+ import { usePageData, usePageFrontmatter } from '@vuepress/client';
2
+ import { isArray, isPlainObject, isString, resolveLocalePath, } from '@vuepress/shared';
3
+ import { computed, inject, provide } from 'vue';
4
+ import { useRoute } from 'vue-router';
5
+ import { useNavLink } from './useNavLink.js';
6
+ import { useThemeLocaleData } from './useThemeData.js';
7
+ export const sidebarItemsSymbol = Symbol('sidebarItems');
8
+ /**
9
+ * Inject sidebar items global computed
10
+ */
11
+ export const useSidebarItems = () => {
12
+ const sidebarItems = inject(sidebarItemsSymbol);
13
+ if (!sidebarItems) {
14
+ throw new Error('useSidebarItems() is called without provider.');
15
+ }
16
+ return sidebarItems;
17
+ };
18
+ /**
19
+ * Create sidebar items ref and provide as global computed in setup
20
+ */
21
+ export const setupSidebarItems = () => {
22
+ const themeLocale = useThemeLocaleData();
23
+ const frontmatter = usePageFrontmatter();
24
+ const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value));
25
+ provide(sidebarItemsSymbol, sidebarItems);
26
+ };
27
+ /**
28
+ * Resolve sidebar items global computed
29
+ *
30
+ * It should only be resolved and provided once
31
+ */
32
+ export const resolveSidebarItems = (frontmatter, themeLocale) => {
33
+ // get sidebar config from frontmatter > theme data
34
+ const sidebarConfig = frontmatter.sidebar ?? themeLocale.sidebar ?? 'auto';
35
+ const sidebarDepth = frontmatter.sidebarDepth ?? themeLocale.sidebarDepth ?? 2;
36
+ // resolve sidebar items according to the config
37
+ if (frontmatter.home || sidebarConfig === false) {
38
+ return [];
39
+ }
40
+ if (sidebarConfig === 'auto') {
41
+ return resolveAutoSidebarItems(sidebarDepth);
42
+ }
43
+ if (isArray(sidebarConfig)) {
44
+ return resolveArraySidebarItems(sidebarConfig, sidebarDepth);
45
+ }
46
+ if (isPlainObject(sidebarConfig)) {
47
+ return resolveMultiSidebarItems(sidebarConfig, sidebarDepth);
48
+ }
49
+ return [];
50
+ };
51
+ /**
52
+ * Util to transform page header to sidebar item
53
+ */
54
+ export const headerToSidebarItem = (header, sidebarDepth) => ({
55
+ text: header.title,
56
+ link: `#${header.slug}`,
57
+ children: headersToSidebarItemChildren(header.children, sidebarDepth),
58
+ });
59
+ export const headersToSidebarItemChildren = (headers, sidebarDepth) => sidebarDepth > 0
60
+ ? headers.map((header) => headerToSidebarItem(header, sidebarDepth - 1))
61
+ : [];
62
+ /**
63
+ * Resolve sidebar items if the config is `auto`
64
+ */
65
+ export const resolveAutoSidebarItems = (sidebarDepth) => {
66
+ const page = usePageData();
67
+ return [
68
+ {
69
+ text: page.value.title,
70
+ children: headersToSidebarItemChildren(page.value.headers, sidebarDepth),
71
+ },
72
+ ];
73
+ };
74
+ /**
75
+ * Resolve sidebar items if the config is an array
76
+ */
77
+ export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth) => {
78
+ const route = useRoute();
79
+ const page = usePageData();
80
+ const handleChildItem = (item) => {
81
+ let childItem;
82
+ if (isString(item)) {
83
+ childItem = useNavLink(item);
84
+ }
85
+ else {
86
+ childItem = item;
87
+ }
88
+ if (childItem.children) {
89
+ return {
90
+ ...childItem,
91
+ children: childItem.children.map((item) => handleChildItem(item)),
92
+ };
93
+ }
94
+ // if the sidebar item is current page and children is not set
95
+ // use headers of current page as children
96
+ if (childItem.link === route.path) {
97
+ // skip h1 header
98
+ const headers = page.value.headers[0]?.level === 1
99
+ ? page.value.headers[0].children
100
+ : page.value.headers;
101
+ return {
102
+ ...childItem,
103
+ children: headersToSidebarItemChildren(headers, sidebarDepth),
104
+ };
105
+ }
106
+ return childItem;
107
+ };
108
+ return sidebarConfig.map((item) => handleChildItem(item));
109
+ };
110
+ /**
111
+ * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
112
+ */
113
+ export const resolveMultiSidebarItems = (sidebarConfig, sidebarDepth) => {
114
+ const route = useRoute();
115
+ const sidebarPath = resolveLocalePath(sidebarConfig, route.path);
116
+ const matchedSidebarConfig = sidebarConfig[sidebarPath] ?? [];
117
+ return resolveArraySidebarItems(matchedSidebarConfig, sidebarDepth);
118
+ };
@@ -1,4 +1,4 @@
1
- import type { ThemeDataRef, ThemeLocaleDataRef } from '@vuepress/plugin-theme-data/lib/composables';
2
- import type { DefaultThemeData } from '../types';
1
+ import type { ThemeDataRef, ThemeLocaleDataRef } from '@vuepress/plugin-theme-data/client';
2
+ import type { DefaultThemeData } from '../../shared/index.js';
3
3
  export declare const useThemeData: () => ThemeDataRef<DefaultThemeData>;
4
4
  export declare const useThemeLocaleData: () => ThemeLocaleDataRef<DefaultThemeData>;
@@ -1,3 +1,3 @@
1
- import { useThemeData as _useThemeData, useThemeLocaleData as _useThemeLocaleData, } from '@vuepress/plugin-theme-data/lib/composables';
1
+ import { useThemeData as _useThemeData, useThemeLocaleData as _useThemeLocaleData, } from '@vuepress/plugin-theme-data/client';
2
2
  export const useThemeData = () => _useThemeData();
3
3
  export const useThemeLocaleData = () => _useThemeLocaleData();
@@ -0,0 +1,3 @@
1
+ import './styles/index.scss';
2
+ declare const _default: import("@vuepress/client").ClientConfig;
3
+ export default _default;
@@ -0,0 +1,38 @@
1
+ import { defineClientConfig } from '@vuepress/client';
2
+ import { h } from 'vue';
3
+ import { Badge, CodeGroup, CodeGroupItem } from './components/global/index.js';
4
+ import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables/index.js';
5
+ import './styles/index.scss';
6
+ export default defineClientConfig({
7
+ enhance({ app, router }) {
8
+ app.component('Badge', Badge);
9
+ app.component('CodeGroup', CodeGroup);
10
+ app.component('CodeGroupItem', CodeGroupItem);
11
+ // compat with @vuepress/plugin-external-link-icon
12
+ app.component('AutoLinkExternalIcon', () => {
13
+ const ExternalLinkIcon = app.component('ExternalLinkIcon');
14
+ if (ExternalLinkIcon) {
15
+ return h(ExternalLinkIcon);
16
+ }
17
+ return null;
18
+ });
19
+ // compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
20
+ app.component('NavbarSearch', () => {
21
+ const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
22
+ if (SearchComponent) {
23
+ return h(SearchComponent);
24
+ }
25
+ return null;
26
+ });
27
+ // handle scrollBehavior with transition
28
+ const scrollBehavior = router.options.scrollBehavior;
29
+ router.options.scrollBehavior = async (...args) => {
30
+ await useScrollPromise().wait();
31
+ return scrollBehavior(...args);
32
+ };
33
+ },
34
+ setup() {
35
+ setupDarkMode();
36
+ setupSidebarItems();
37
+ },
38
+ });
@@ -0,0 +1,3 @@
1
+ export * from '../shared/index.js';
2
+ export * from './composables/index.js';
3
+ export * from './utils/index.js';
@@ -0,0 +1,3 @@
1
+ export * from '../shared/index.js';
2
+ export * from './composables/index.js';
3
+ export * from './utils/index.js';
@@ -0,0 +1,27 @@
1
+ <script setup lang="ts">
2
+ import { useRouteLocale } from '@vuepress/client'
3
+ import { useThemeLocaleData } from '../composables/index.js'
4
+
5
+ const routeLocale = useRouteLocale()
6
+ const themeLocale = useThemeLocaleData()
7
+
8
+ const messages = themeLocale.value.notFound ?? ['Not Found']
9
+ const getMsg = (): string =>
10
+ messages[Math.floor(Math.random() * messages.length)]
11
+ const homeLink = themeLocale.value.home ?? routeLocale.value
12
+ const homeText = themeLocale.value.backToHome ?? 'Back to home'
13
+ </script>
14
+
15
+ <template>
16
+ <div class="theme-container">
17
+ <main class="page">
18
+ <div class="theme-default-content">
19
+ <h1>404</h1>
20
+
21
+ <blockquote>{{ getMsg() }}</blockquote>
22
+
23
+ <RouterLink :to="homeLink">{{ homeText }}</RouterLink>
24
+ </div>
25
+ </main>
26
+ </div>
27
+ </template>