@vuepress/theme-default 2.0.0-beta.4 → 2.0.0-beta.40

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 (132) hide show
  1. package/lib/{clientAppEnhance.d.ts → client/clientAppEnhance.d.ts} +0 -0
  2. package/lib/client/clientAppEnhance.js +34 -0
  3. package/lib/{clientAppSetup.d.ts → client/clientAppSetup.d.ts} +0 -0
  4. package/lib/client/clientAppSetup.js +6 -0
  5. package/lib/client/components/AutoLink.vue +113 -0
  6. package/lib/client/components/DropdownTransition.vue +21 -0
  7. package/lib/client/components/Home.vue +15 -0
  8. package/lib/client/components/HomeContent.vue +5 -0
  9. package/lib/client/components/HomeFeatures.vue +23 -0
  10. package/lib/client/components/HomeFooter.vue +17 -0
  11. package/lib/client/components/HomeHero.vue +97 -0
  12. package/lib/client/components/Navbar.vue +76 -0
  13. package/lib/client/components/NavbarBrand.vue +55 -0
  14. package/lib/client/components/NavbarDropdown.vue +126 -0
  15. package/lib/{components/NavbarLinks.vue → client/components/NavbarItems.vue} +27 -47
  16. package/lib/{components → client/components}/Page.vue +5 -15
  17. package/lib/{components → client/components}/PageMeta.vue +48 -59
  18. package/lib/{components → client/components}/PageNav.vue +43 -56
  19. package/lib/client/components/Sidebar.vue +13 -0
  20. package/lib/client/components/SidebarItem.vue +80 -0
  21. package/lib/client/components/SidebarItems.vue +54 -0
  22. package/lib/client/components/ToggleDarkModeButton.vue +57 -0
  23. package/lib/client/components/ToggleSidebarButton.vue +24 -0
  24. package/lib/client/components/global/Badge.vue +31 -0
  25. package/lib/client/components/global/CodeGroup.d.ts +5 -0
  26. package/lib/client/components/global/CodeGroup.js +107 -0
  27. package/lib/client/components/global/CodeGroupItem.vue +31 -0
  28. package/lib/{composables → client/composables}/index.d.ts +2 -0
  29. package/lib/{composables → client/composables}/index.js +2 -0
  30. package/lib/client/composables/useDarkMode.d.ts +12 -0
  31. package/lib/client/composables/useDarkMode.js +57 -0
  32. package/lib/{composables → client/composables}/useNavLink.d.ts +6 -1
  33. package/lib/{composables → client/composables}/useNavLink.js +0 -0
  34. package/lib/{composables → client/composables}/useResolveRouteWithRedirect.d.ts +1 -1
  35. package/lib/{composables → client/composables}/useResolveRouteWithRedirect.js +1 -1
  36. package/lib/client/composables/useScrollPromise.d.ts +6 -0
  37. package/lib/client/composables/useScrollPromise.js +14 -0
  38. package/lib/{composables → client/composables}/useSidebarItems.d.ts +12 -7
  39. package/lib/client/composables/useSidebarItems.js +120 -0
  40. package/lib/{composables → client/composables}/useThemeData.d.ts +2 -2
  41. package/lib/{composables → client/composables}/useThemeData.js +1 -1
  42. package/lib/client/index.d.ts +4 -0
  43. package/lib/client/index.js +2 -0
  44. package/lib/client/layouts/404.vue +25 -0
  45. package/lib/client/layouts/Layout.vue +128 -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 +21 -33
  53. package/lib/client/styles/custom-container.scss +88 -0
  54. package/lib/{styles → client/styles}/home.scss +27 -24
  55. package/lib/{styles → client/styles}/index.scss +4 -4
  56. package/lib/{styles → client/styles}/layout.scss +52 -35
  57. package/lib/{styles/dropdown.scss → client/styles/navbar-dropdown.scss} +37 -47
  58. package/lib/client/styles/navbar.scss +177 -0
  59. package/lib/client/styles/normalize.scss +172 -0
  60. package/lib/{styles → client/styles}/page.scss +15 -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/{utils → client/utils}/index.d.ts +1 -0
  67. package/lib/{utils → client/utils}/index.js +1 -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 +1 -1
  71. package/lib/{utils → client/utils}/resolveEditLink.js +14 -8
  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 +122 -0
  76. package/lib/node/index.d.ts +5 -5
  77. package/lib/node/index.js +10 -6
  78. package/lib/node/utils/assignDefaultLocaleOptions.d.ts +7 -0
  79. package/lib/node/{assignDefaultLocaleOptions.js → utils/assignDefaultLocaleOptions.js} +11 -9
  80. package/lib/node/utils/index.d.ts +2 -0
  81. package/lib/node/utils/index.js +18 -0
  82. package/lib/node/utils/resolveContainerPluginOptions.d.ts +8 -0
  83. package/lib/node/utils/resolveContainerPluginOptions.js +22 -0
  84. package/lib/{types → shared}/index.d.ts +0 -0
  85. package/lib/{types → shared}/index.js +5 -1
  86. package/lib/{types → shared}/nav.d.ts +11 -12
  87. package/lib/{types → shared}/nav.js +0 -0
  88. package/lib/{types → shared}/options.d.ts +42 -10
  89. package/lib/{types → shared}/options.js +0 -0
  90. package/lib/{types → shared}/page.d.ts +13 -5
  91. package/lib/{types → shared}/page.js +0 -0
  92. package/package.json +38 -29
  93. package/templates/build.html +33 -0
  94. package/CHANGELOG.md +0 -353
  95. package/lib/clientAppEnhance.js +0 -23
  96. package/lib/clientAppSetup.js +0 -11
  97. package/lib/components/DropdownLink.vue +0 -141
  98. package/lib/components/DropdownTransition.vue +0 -34
  99. package/lib/components/Home.vue +0 -133
  100. package/lib/components/NavLink.vue +0 -105
  101. package/lib/components/Navbar.vue +0 -113
  102. package/lib/components/Sidebar.vue +0 -38
  103. package/lib/components/SidebarChild.d.ts +0 -6
  104. package/lib/components/SidebarChild.js +0 -83
  105. package/lib/components/ToggleSidebarButton.vue +0 -27
  106. package/lib/components/global/Badge.vue +0 -37
  107. package/lib/components/global/CodeGroup.vue +0 -85
  108. package/lib/components/global/CodeGroupItem.vue +0 -25
  109. package/lib/components/global/OutboundLink.vue +0 -30
  110. package/lib/composables/useSidebarItems.js +0 -108
  111. package/lib/index.d.ts +0 -6
  112. package/lib/index.js +0 -67
  113. package/lib/layouts/404.vue +0 -38
  114. package/lib/layouts/Layout.vue +0 -132
  115. package/lib/node/assignDefaultLocaleOptions.d.ts +0 -5
  116. package/lib/node/resolveActiveHeaderLinksPluginOptions.d.ts +0 -6
  117. package/lib/node/resolveActiveHeaderLinksPluginOptions.js +0 -16
  118. package/lib/node/resolveContainerPluginOptions.d.ts +0 -26
  119. package/lib/node/resolveContainerPluginOptions.js +0 -79
  120. package/lib/node/resolveGitPluginOptions.d.ts +0 -6
  121. package/lib/node/resolveGitPluginOptions.js +0 -22
  122. package/lib/node/resolveMediumZoomPluginOptions.d.ts +0 -6
  123. package/lib/node/resolveMediumZoomPluginOptions.js +0 -17
  124. package/lib/styles/_normalize.scss +0 -148
  125. package/lib/styles/_variables.scss +0 -34
  126. package/lib/styles/custom-container.scss +0 -78
  127. package/lib/styles/navbar.scss +0 -140
  128. package/lib/styles/plugins.scss +0 -18
  129. package/lib/styles/sidebar.scss +0 -147
  130. package/lib/styles/sr-only.scss +0 -12
  131. package/lib/styles/transitions.scss +0 -13
  132. package/lib/utils/resolveRepoType.d.ts +0 -2
@@ -0,0 +1,31 @@
1
+ <script setup lang="ts">
2
+ defineProps({
3
+ type: {
4
+ type: String,
5
+ required: false,
6
+ default: 'tip',
7
+ },
8
+ text: {
9
+ type: String,
10
+ required: false,
11
+ default: '',
12
+ },
13
+ vertical: {
14
+ type: String,
15
+ required: false,
16
+ default: undefined,
17
+ },
18
+ })
19
+ </script>
20
+
21
+ <template>
22
+ <span
23
+ class="badge"
24
+ :class="type"
25
+ :style="{
26
+ verticalAlign: vertical,
27
+ }"
28
+ >
29
+ <slot>{{ text }}</slot>
30
+ </span>
31
+ </template>
@@ -0,0 +1,5 @@
1
+ import type { VNode } from 'vue';
2
+ declare const _default: import("vue").DefineComponent<{}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
3
+ [key: string]: any;
4
+ }> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;
5
+ export default _default;
@@ -0,0 +1,107 @@
1
+ import { defineComponent, h, onBeforeUpdate, ref } from 'vue';
2
+ export default 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
+ var _a;
56
+ // get children code-group-item
57
+ const items = (((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)) || [])
58
+ .filter((vnode) => vnode.type.name === 'CodeGroupItem')
59
+ .map((vnode) => {
60
+ if (vnode.props === null) {
61
+ vnode.props = {};
62
+ }
63
+ return vnode;
64
+ });
65
+ // do not render anything if there is no code-group-item
66
+ if (items.length === 0) {
67
+ return null;
68
+ }
69
+ if (activeIndex.value < 0 || activeIndex.value > items.length - 1) {
70
+ // if `activeIndex` is invalid
71
+ // find the index of the code-group-item with `active` props
72
+ activeIndex.value = items.findIndex((vnode) => vnode.props.active === '' || vnode.props.active === true);
73
+ // if there is no `active` props on code-group-item, set the first item active
74
+ if (activeIndex.value === -1) {
75
+ activeIndex.value = 0;
76
+ }
77
+ }
78
+ else {
79
+ // set the active item
80
+ items.forEach((vnode, i) => {
81
+ vnode.props.active = i === activeIndex.value;
82
+ });
83
+ }
84
+ return h('div', { class: 'code-group' }, [
85
+ h('div', { class: 'code-group__nav' }, h('ul', { class: 'code-group__ul' }, items.map((vnode, i) => {
86
+ const isActive = i === activeIndex.value;
87
+ return h('li', { class: 'code-group__li' }, h('button', {
88
+ ref: (element) => {
89
+ if (element) {
90
+ tabRefs.value[i] = element;
91
+ }
92
+ },
93
+ class: {
94
+ 'code-group__nav-tab': true,
95
+ 'code-group__nav-tab-active': isActive,
96
+ },
97
+ ariaPressed: isActive,
98
+ ariaExpanded: isActive,
99
+ onClick: () => (activeIndex.value = i),
100
+ onKeydown: (e) => keyboardHandler(e, i),
101
+ }, vnode.props.title));
102
+ }))),
103
+ items,
104
+ ]);
105
+ };
106
+ },
107
+ });
@@ -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>
@@ -1,4 +1,6 @@
1
+ export * from './useDarkMode';
1
2
  export * from './useNavLink';
2
3
  export * from './useResolveRouteWithRedirect';
4
+ export * from './useScrollPromise';
3
5
  export * from './useSidebarItems';
4
6
  export * from './useThemeData';
@@ -1,4 +1,6 @@
1
+ export * from './useDarkMode';
1
2
  export * from './useNavLink';
2
3
  export * from './useResolveRouteWithRedirect';
4
+ export * from './useScrollPromise';
3
5
  export * from './useSidebarItems';
4
6
  export * from './useThemeData';
@@ -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 '.';
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', 'auto');
22
+ const isDarkMode = computed({
23
+ get() {
24
+ // disable dark mode
25
+ if (!themeLocale.value.darkMode) {
26
+ return false;
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 === null || window === void 0 ? void 0 : window.document.querySelector('html');
51
+ htmlEl === null || htmlEl === void 0 ? void 0 : 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';
2
+ declare module 'vue-router' {
3
+ interface RouteMeta {
4
+ title?: string;
5
+ }
6
+ }
2
7
  /**
3
8
  * Resolve NavLink props from string
4
9
  *
@@ -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
  */
@@ -0,0 +1,6 @@
1
+ export interface ScrollPromise {
2
+ wait(): Promise<void> | null;
3
+ pending: () => void;
4
+ resolve: () => void;
5
+ }
6
+ export declare const useScrollPromise: () => ScrollPromise;
@@ -0,0 +1,14 @@
1
+ let promise = null;
2
+ let promiseResolve = null;
3
+ const scrollPromise = {
4
+ wait: () => promise,
5
+ pending: () => {
6
+ promise = new Promise((resolve) => (promiseResolve = resolve));
7
+ },
8
+ resolve: () => {
9
+ promiseResolve === null || promiseResolve === void 0 ? void 0 : promiseResolve();
10
+ promise = null;
11
+ promiseResolve = null;
12
+ },
13
+ };
14
+ export const useScrollPromise = () => scrollPromise;
@@ -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';
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,120 @@
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, useThemeLocaleData } from '.';
6
+ export const sidebarItemsSymbol = Symbol('sidebarItems');
7
+ /**
8
+ * Inject sidebar items global computed
9
+ */
10
+ export const useSidebarItems = () => {
11
+ const sidebarItems = inject(sidebarItemsSymbol);
12
+ if (!sidebarItems) {
13
+ throw new Error('useSidebarItems() is called without provider.');
14
+ }
15
+ return sidebarItems;
16
+ };
17
+ /**
18
+ * Create sidebar items ref and provide as global computed in setup
19
+ */
20
+ export const setupSidebarItems = () => {
21
+ const themeLocale = useThemeLocaleData();
22
+ const frontmatter = usePageFrontmatter();
23
+ const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value));
24
+ provide(sidebarItemsSymbol, sidebarItems);
25
+ };
26
+ /**
27
+ * Resolve sidebar items global computed
28
+ *
29
+ * It should only be resolved and provided once
30
+ */
31
+ export const resolveSidebarItems = (frontmatter, themeLocale) => {
32
+ var _a, _b, _c, _d;
33
+ // get sidebar config from frontmatter > theme data
34
+ const sidebarConfig = (_b = (_a = frontmatter.sidebar) !== null && _a !== void 0 ? _a : themeLocale.sidebar) !== null && _b !== void 0 ? _b : 'auto';
35
+ const sidebarDepth = (_d = (_c = frontmatter.sidebarDepth) !== null && _c !== void 0 ? _c : themeLocale.sidebarDepth) !== null && _d !== void 0 ? _d : 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
+ var _a;
82
+ let childItem;
83
+ if (isString(item)) {
84
+ childItem = useNavLink(item);
85
+ }
86
+ else {
87
+ childItem = item;
88
+ }
89
+ if (childItem.children) {
90
+ return {
91
+ ...childItem,
92
+ children: childItem.children.map((item) => handleChildItem(item)),
93
+ };
94
+ }
95
+ // if the sidebar item is current page and children is not set
96
+ // use headers of current page as children
97
+ if (childItem.link === route.path) {
98
+ // skip h1 header
99
+ const headers = ((_a = page.value.headers[0]) === null || _a === void 0 ? void 0 : _a.level) === 1
100
+ ? page.value.headers[0].children
101
+ : page.value.headers;
102
+ return {
103
+ ...childItem,
104
+ children: headersToSidebarItemChildren(headers, sidebarDepth),
105
+ };
106
+ }
107
+ return childItem;
108
+ };
109
+ return sidebarConfig.map((item) => handleChildItem(item));
110
+ };
111
+ /**
112
+ * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
113
+ */
114
+ export const resolveMultiSidebarItems = (sidebarConfig, sidebarDepth) => {
115
+ var _a;
116
+ const route = useRoute();
117
+ const sidebarPath = resolveLocalePath(sidebarConfig, route.path);
118
+ const matchedSidebarConfig = (_a = sidebarConfig[sidebarPath]) !== null && _a !== void 0 ? _a : [];
119
+ return resolveArraySidebarItems(matchedSidebarConfig, sidebarDepth);
120
+ };
@@ -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/lib/client';
2
+ import type { DefaultThemeData } from '../../shared';
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/lib/client';
2
2
  export const useThemeData = () => _useThemeData();
3
3
  export const useThemeLocaleData = () => _useThemeLocaleData();
@@ -0,0 +1,4 @@
1
+ import type { DefaultThemeData, DefaultThemeHomePageFrontmatter, DefaultThemeLocaleData, DefaultThemeLocaleOptions, DefaultThemeNormalPageFrontmatter, DefaultThemePageData, DefaultThemePageFrontmatter, DefaultThemePluginsOptions, NavbarConfig, NavbarGroup, NavbarItem, NavGroup, NavItem, NavLink, ResolvedNavbarItem, ResolvedSidebarItem, SidebarConfig, SidebarConfigArray, SidebarConfigObject, SidebarGroup, SidebarGroupCollapsible, SidebarItem } from '../shared';
2
+ export type { DefaultThemeData, DefaultThemeHomePageFrontmatter, DefaultThemeLocaleData, DefaultThemeLocaleOptions, DefaultThemeNormalPageFrontmatter, DefaultThemePageData, DefaultThemePageFrontmatter, DefaultThemePluginsOptions, NavbarConfig, NavbarGroup, NavbarItem, NavGroup, NavItem, NavLink, ResolvedNavbarItem, ResolvedSidebarItem, SidebarConfig, SidebarConfigArray, SidebarConfigObject, SidebarGroup, SidebarGroupCollapsible, SidebarItem, };
3
+ export * from './composables';
4
+ export * from './utils';
@@ -0,0 +1,2 @@
1
+ export * from './composables';
2
+ export * from './utils';
@@ -0,0 +1,25 @@
1
+ <script setup lang="ts">
2
+ import { useRouteLocale } from '@vuepress/client'
3
+ import { useThemeLocaleData } from '../composables'
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
+ <div class="theme-default-content">
18
+ <h1>404</h1>
19
+
20
+ <blockquote>{{ getMsg() }}</blockquote>
21
+
22
+ <RouterLink :to="homeLink">{{ homeText }}</RouterLink>
23
+ </div>
24
+ </div>
25
+ </template>
@@ -0,0 +1,128 @@
1
+ <script setup lang="ts">
2
+ import Home from '@theme/Home.vue'
3
+ import Navbar from '@theme/Navbar.vue'
4
+ import Page from '@theme/Page.vue'
5
+ import Sidebar from '@theme/Sidebar.vue'
6
+ import { usePageData, usePageFrontmatter } from '@vuepress/client'
7
+ import { computed, onMounted, onUnmounted, ref, Transition } from 'vue'
8
+ import { useRouter } from 'vue-router'
9
+ import type { DefaultThemePageFrontmatter } from '../../shared'
10
+ import {
11
+ useScrollPromise,
12
+ useSidebarItems,
13
+ useThemeLocaleData,
14
+ } from '../composables'
15
+
16
+ const page = usePageData()
17
+ const frontmatter = usePageFrontmatter<DefaultThemePageFrontmatter>()
18
+ const themeLocale = useThemeLocaleData()
19
+
20
+ // navbar
21
+ const shouldShowNavbar = computed(
22
+ () => frontmatter.value.navbar !== false && themeLocale.value.navbar !== false
23
+ )
24
+
25
+ // sidebar
26
+ const sidebarItems = useSidebarItems()
27
+ const isSidebarOpen = ref(false)
28
+ const toggleSidebar = (to?: boolean): void => {
29
+ isSidebarOpen.value = typeof to === 'boolean' ? to : !isSidebarOpen.value
30
+ }
31
+ const touchStart = { x: 0, y: 0 }
32
+ const onTouchStart = (e): void => {
33
+ touchStart.x = e.changedTouches[0].clientX
34
+ touchStart.y = e.changedTouches[0].clientY
35
+ }
36
+ const onTouchEnd = (e): void => {
37
+ const dx = e.changedTouches[0].clientX - touchStart.x
38
+ const dy = e.changedTouches[0].clientY - touchStart.y
39
+ if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 40) {
40
+ if (dx > 0 && touchStart.x <= 80) {
41
+ toggleSidebar(true)
42
+ } else {
43
+ toggleSidebar(false)
44
+ }
45
+ }
46
+ }
47
+
48
+ // classes
49
+ const containerClass = computed(() => [
50
+ {
51
+ 'no-navbar': !shouldShowNavbar.value,
52
+ 'no-sidebar': !sidebarItems.value.length,
53
+ 'sidebar-open': isSidebarOpen.value,
54
+ },
55
+ frontmatter.value.pageClass,
56
+ ])
57
+
58
+ // close sidebar after navigation
59
+ let unregisterRouterHook
60
+ onMounted(() => {
61
+ const router = useRouter()
62
+ unregisterRouterHook = router.afterEach(() => {
63
+ toggleSidebar(false)
64
+ })
65
+ })
66
+ onUnmounted(() => {
67
+ unregisterRouterHook()
68
+ })
69
+
70
+ // handle scrollBehavior with transition
71
+ const scrollPromise = useScrollPromise()
72
+ const onBeforeEnter = scrollPromise.resolve
73
+ const onBeforeLeave = scrollPromise.pending
74
+ </script>
75
+
76
+ <template>
77
+ <div
78
+ class="theme-container"
79
+ :class="containerClass"
80
+ @touchstart="onTouchStart"
81
+ @touchend="onTouchEnd"
82
+ >
83
+ <slot name="navbar">
84
+ <Navbar v-if="shouldShowNavbar" @toggle-sidebar="toggleSidebar">
85
+ <template #before>
86
+ <slot name="navbar-before" />
87
+ </template>
88
+ <template #after>
89
+ <slot name="navbar-after" />
90
+ </template>
91
+ </Navbar>
92
+ </slot>
93
+
94
+ <div class="sidebar-mask" @click="toggleSidebar(false)" />
95
+
96
+ <slot name="sidebar">
97
+ <Sidebar>
98
+ <template #top>
99
+ <slot name="sidebar-top" />
100
+ </template>
101
+ <template #bottom>
102
+ <slot name="sidebar-bottom" />
103
+ </template>
104
+ </Sidebar>
105
+ </slot>
106
+
107
+ <slot name="page">
108
+ <Home v-if="frontmatter.home" />
109
+
110
+ <Transition
111
+ v-else
112
+ name="fade-slide-y"
113
+ mode="out-in"
114
+ @before-enter="onBeforeEnter"
115
+ @before-leave="onBeforeLeave"
116
+ >
117
+ <Page :key="page.path">
118
+ <template #top>
119
+ <slot name="page-top" />
120
+ </template>
121
+ <template #bottom>
122
+ <slot name="page-bottom" />
123
+ </template>
124
+ </Page>
125
+ </Transition>
126
+ </slot>
127
+ </div>
128
+ </template>
File without changes