@vuepress/theme-default 2.0.0-rc.33 → 2.0.0-rc.34
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.
- package/lib/client/components/VPDarkIcon.vue +8 -0
- package/lib/client/components/{DropdownTransition.vue → VPDropdownTransition.vue} +10 -1
- package/lib/client/components/VPEditIcon.vue +12 -0
- package/lib/client/components/VPHome.vue +38 -0
- package/lib/client/components/VPHomeFeatures.vue +68 -0
- package/lib/client/components/{HomeFooter.vue → VPHomeFooter.vue} +16 -2
- package/lib/client/components/{HomeHero.vue → VPHomeHero.vue} +107 -5
- package/lib/client/components/VPLightIcon.vue +28 -0
- package/lib/client/components/VPNavbar.vue +127 -0
- package/lib/client/components/{NavbarBrand.vue → VPNavbarBrand.vue} +36 -4
- package/lib/client/components/VPNavbarDropdown.vue +319 -0
- package/lib/client/components/VPNavbarItems.vue +110 -0
- package/lib/client/components/VPPage.vue +66 -0
- package/lib/client/components/VPPageMeta.vue +132 -0
- package/lib/client/components/VPPageNav.vue +118 -0
- package/lib/client/components/VPSidebar.vue +112 -0
- package/lib/client/components/VPSidebarItem.vue +169 -0
- package/lib/client/components/{SidebarItems.vue → VPSidebarItems.vue} +30 -6
- package/lib/client/components/VPToggleColorModeButton.vue +54 -0
- package/lib/client/components/VPToggleSidebarButton.vue +92 -0
- package/lib/client/components/global/Badge.vue +60 -18
- package/lib/client/components/global/CodeGroup.d.ts +1 -0
- package/lib/client/components/global/CodeGroup.js +4 -3
- package/lib/client/components/global/CodeGroupItem.vue +5 -16
- package/lib/client/composables/index.d.ts +4 -0
- package/lib/client/composables/index.js +4 -0
- package/lib/client/composables/useContributors.d.ts +3 -0
- package/lib/client/composables/useContributors.js +14 -0
- package/lib/client/composables/useDarkMode.js +1 -1
- package/lib/client/composables/useEditLink.d.ts +3 -0
- package/lib/client/composables/useEditLink.js +31 -0
- package/lib/client/composables/useLastUpdated.d.ts +2 -0
- package/lib/client/composables/useLastUpdated.js +17 -0
- package/lib/client/composables/useNavbarConfig.d.ts +2 -2
- package/lib/client/composables/useNavbarConfig.js +1 -1
- package/lib/client/composables/useNavbarRepo.d.ts +2 -2
- package/lib/client/composables/useNavbarRepo.js +1 -1
- package/lib/client/composables/useNavbarSelectLanguage.d.ts +2 -2
- package/lib/client/composables/useNavbarSelectLanguage.js +2 -2
- package/lib/client/composables/useNavigate.js +4 -7
- package/lib/client/composables/useRelatedLinks.d.ts +8 -0
- package/lib/client/composables/useRelatedLinks.js +73 -0
- package/lib/client/composables/useSidebarItems.d.ts +10 -9
- package/lib/client/composables/useSidebarItems.js +14 -14
- package/lib/client/config.js +1 -1
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +1 -0
- package/lib/client/layouts/Layout.vue +111 -18
- package/lib/client/layouts/NotFound.vue +1 -1
- package/lib/client/styles/_mixins.scss +4 -4
- package/lib/client/styles/_variables.module.scss +1 -1
- package/lib/client/styles/_variables.scss +1 -0
- package/lib/client/styles/code-group.scss +32 -29
- package/lib/client/styles/{code.scss → content/code.scss} +55 -31
- package/lib/client/styles/{custom-container.scss → content/custom-container.scss} +9 -5
- package/lib/client/styles/content/index.scss +4 -0
- package/lib/client/styles/content/normalize.scss +39 -0
- package/lib/client/styles/{toc.scss → content/toc.scss} +1 -1
- package/lib/client/styles/external-link-icon.scss +7 -3
- package/lib/client/styles/index.scss +2 -13
- package/lib/client/styles/layout.scss +3 -203
- package/lib/client/styles/normalize.scss +4 -3
- package/lib/client/styles/plugins.scss +20 -0
- package/lib/client/styles/vars-dark.scss +17 -16
- package/lib/client/styles/vars.scss +19 -23
- package/lib/client/typings.d.ts +13 -0
- package/lib/client/typings.js +1 -0
- package/lib/client/utils/{getNavLink.d.ts → getAutoLink.d.ts} +2 -2
- package/lib/client/utils/index.d.ts +1 -1
- package/lib/client/utils/index.js +1 -1
- package/lib/client/utils/isActiveSidebarItem.d.ts +2 -2
- package/lib/client/utils/isActiveSidebarItem.js +3 -3
- package/lib/node/defaultTheme.js +9 -1
- package/lib/node/utils/assignDefaultLocaleOptions.js +1 -1
- package/lib/shared/index.d.ts +2 -0
- package/lib/shared/index.js +2 -0
- package/lib/shared/nav.d.ts +21 -30
- package/lib/shared/navbar.d.ts +21 -0
- package/lib/shared/navbar.js +1 -0
- package/lib/shared/options.d.ts +4 -3
- package/lib/shared/page.d.ts +2 -2
- package/lib/shared/sidebar.d.ts +26 -0
- package/lib/shared/sidebar.js +1 -0
- package/package.json +18 -18
- package/templates/build.html +2 -0
- package/lib/client/components/Home.vue +0 -15
- package/lib/client/components/HomeContent.vue +0 -5
- package/lib/client/components/HomeFeatures.vue +0 -22
- package/lib/client/components/Navbar.vue +0 -80
- package/lib/client/components/NavbarDropdown.vue +0 -125
- package/lib/client/components/NavbarItems.vue +0 -51
- package/lib/client/components/Page.vue +0 -31
- package/lib/client/components/PageMeta.vue +0 -220
- package/lib/client/components/PageNav.vue +0 -228
- package/lib/client/components/Sidebar.vue +0 -18
- package/lib/client/components/SidebarItem.vue +0 -86
- package/lib/client/components/ToggleColorModeButton.vue +0 -57
- package/lib/client/components/ToggleSidebarButton.vue +0 -24
- package/lib/client/styles/badge.scss +0 -36
- package/lib/client/styles/home.scss +0 -168
- package/lib/client/styles/navbar-dropdown.scss +0 -177
- package/lib/client/styles/navbar.scss +0 -197
- package/lib/client/styles/page.scss +0 -11
- package/lib/client/styles/sidebar.scss +0 -128
- package/lib/client/styles/transitions.scss +0 -22
- /package/lib/client/utils/{getNavLink.js → getAutoLink.js} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useStorage } from '@vueuse/core';
|
|
2
2
|
import { computed, defineComponent, h, onBeforeUpdate, onMounted, ref, watch, } from 'vue';
|
|
3
|
+
import '../../styles/code-group.scss';
|
|
3
4
|
export const CodeGroup = defineComponent({
|
|
4
5
|
name: 'CodeGroup',
|
|
5
6
|
slots: Object,
|
|
@@ -95,7 +96,7 @@ export const CodeGroup = defineComponent({
|
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
return h('div', { class: 'code-group' }, [
|
|
98
|
-
h('div', { class: 'code-
|
|
99
|
+
h('div', { class: 'code-group-nav', role: 'tablist' }, items.map((vnode, i) => {
|
|
99
100
|
const isActive = i === activeIndex.value;
|
|
100
101
|
return h('button', {
|
|
101
102
|
ref: (element) => {
|
|
@@ -104,8 +105,8 @@ export const CodeGroup = defineComponent({
|
|
|
104
105
|
}
|
|
105
106
|
},
|
|
106
107
|
class: {
|
|
107
|
-
'code-
|
|
108
|
-
'
|
|
108
|
+
'code-group-nav-tab': true,
|
|
109
|
+
'active': isActive,
|
|
109
110
|
},
|
|
110
111
|
role: 'tab',
|
|
111
112
|
ariaSelected: isActive,
|
|
@@ -3,25 +3,14 @@ defineOptions({
|
|
|
3
3
|
name: 'CodeGroupItem',
|
|
4
4
|
})
|
|
5
5
|
|
|
6
|
-
defineProps
|
|
7
|
-
title:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
active: {
|
|
12
|
-
type: Boolean,
|
|
13
|
-
required: false,
|
|
14
|
-
default: false,
|
|
15
|
-
},
|
|
16
|
-
})
|
|
6
|
+
defineProps<{
|
|
7
|
+
title: string
|
|
8
|
+
active?: boolean
|
|
9
|
+
}>()
|
|
17
10
|
</script>
|
|
18
11
|
|
|
19
12
|
<template>
|
|
20
|
-
<div
|
|
21
|
-
class="code-group-item"
|
|
22
|
-
:class="{ 'code-group-item__active': active }"
|
|
23
|
-
role="tabpanel"
|
|
24
|
-
>
|
|
13
|
+
<div class="code-group-item" :class="{ active }" role="tabpanel">
|
|
25
14
|
<slot />
|
|
26
15
|
</div>
|
|
27
16
|
</template>
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
export * from './useContributors.js';
|
|
1
2
|
export * from './useDarkMode.js';
|
|
3
|
+
export * from './useEditLink.js';
|
|
4
|
+
export * from './useLastUpdated.js';
|
|
2
5
|
export * from './useNavigate.js';
|
|
3
6
|
export * from './useNavbarConfig.js';
|
|
4
7
|
export * from './useNavbarRepo.js';
|
|
5
8
|
export * from './useNavbarSelectLanguage.js';
|
|
9
|
+
export * from './useRelatedLinks.js';
|
|
6
10
|
export * from './useScrollPromise.js';
|
|
7
11
|
export * from './useSidebarItems.js';
|
|
8
12
|
export * from './useThemeData.js';
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
export * from './useContributors.js';
|
|
1
2
|
export * from './useDarkMode.js';
|
|
3
|
+
export * from './useEditLink.js';
|
|
4
|
+
export * from './useLastUpdated.js';
|
|
2
5
|
export * from './useNavigate.js';
|
|
3
6
|
export * from './useNavbarConfig.js';
|
|
4
7
|
export * from './useNavbarRepo.js';
|
|
5
8
|
export * from './useNavbarSelectLanguage.js';
|
|
9
|
+
export * from './useRelatedLinks.js';
|
|
6
10
|
export * from './useScrollPromise.js';
|
|
7
11
|
export * from './useSidebarItems.js';
|
|
8
12
|
export * from './useThemeData.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { usePageData, usePageFrontmatter } from 'vuepress/client';
|
|
4
|
+
export const useContributors = () => {
|
|
5
|
+
const themeLocale = useThemeLocaleData();
|
|
6
|
+
const page = usePageData();
|
|
7
|
+
const frontmatter = usePageFrontmatter();
|
|
8
|
+
return computed(() => {
|
|
9
|
+
const showContributors = frontmatter.value.contributors ?? themeLocale.value.contributors ?? true;
|
|
10
|
+
if (!showContributors)
|
|
11
|
+
return null;
|
|
12
|
+
return page.value.git?.contributors ?? null;
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
1
2
|
import { usePreferredDark, useStorage } from '@vueuse/core';
|
|
2
3
|
import { computed, inject, onMounted, onUnmounted, provide, watch } from 'vue';
|
|
3
|
-
import { useThemeLocaleData } from './useThemeData.js';
|
|
4
4
|
export const darkModeSymbol = Symbol(__VUEPRESS_DEV__ ? 'darkMode' : '');
|
|
5
5
|
/**
|
|
6
6
|
* Inject dark mode global computed
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { usePageData, usePageFrontmatter } from 'vuepress/client';
|
|
4
|
+
import { resolveEditLink } from '../utils/index.js';
|
|
5
|
+
export const useEditLink = () => {
|
|
6
|
+
const themeLocale = useThemeLocaleData();
|
|
7
|
+
const page = usePageData();
|
|
8
|
+
const frontmatter = usePageFrontmatter();
|
|
9
|
+
return computed(() => {
|
|
10
|
+
const showEditLink = frontmatter.value.editLink ?? themeLocale.value.editLink ?? true;
|
|
11
|
+
if (!showEditLink) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const { repo, docsRepo = repo, docsBranch = 'main', docsDir = '', editLinkText, } = themeLocale.value;
|
|
15
|
+
if (!docsRepo)
|
|
16
|
+
return null;
|
|
17
|
+
const editLink = resolveEditLink({
|
|
18
|
+
docsRepo,
|
|
19
|
+
docsBranch,
|
|
20
|
+
docsDir,
|
|
21
|
+
filePathRelative: page.value.filePathRelative,
|
|
22
|
+
editLinkPattern: frontmatter.value.editLinkPattern ?? themeLocale.value.editLinkPattern,
|
|
23
|
+
});
|
|
24
|
+
if (!editLink)
|
|
25
|
+
return null;
|
|
26
|
+
return {
|
|
27
|
+
text: editLinkText ?? 'Edit this page',
|
|
28
|
+
link: editLink,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { usePageData, usePageFrontmatter } from 'vuepress/client';
|
|
4
|
+
export const useLastUpdated = () => {
|
|
5
|
+
const themeLocale = useThemeLocaleData();
|
|
6
|
+
const page = usePageData();
|
|
7
|
+
const frontmatter = usePageFrontmatter();
|
|
8
|
+
return computed(() => {
|
|
9
|
+
const showLastUpdated = frontmatter.value.lastUpdated ?? themeLocale.value.lastUpdated ?? true;
|
|
10
|
+
if (!showLastUpdated)
|
|
11
|
+
return null;
|
|
12
|
+
if (!page.value.git?.updatedTime)
|
|
13
|
+
return null;
|
|
14
|
+
const updatedDate = new Date(page.value.git?.updatedTime);
|
|
15
|
+
return updatedDate.toLocaleString();
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const useNavbarConfig: () => ComputedRef<
|
|
2
|
+
import type { NavbarItem } from '../typings.js';
|
|
3
|
+
export declare const useNavbarConfig: () => ComputedRef<NavbarItem[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
1
2
|
import { computed } from 'vue';
|
|
2
3
|
import { isString } from 'vuepress/shared';
|
|
3
4
|
import { getAutoLink, isLinkInternal, resolvePrefix } from '../utils/index.js';
|
|
4
|
-
import { useThemeLocaleData } from './useThemeData.js';
|
|
5
5
|
const resolveNavbarItem = (item, prefix = '') => {
|
|
6
6
|
if (isString(item)) {
|
|
7
7
|
return getAutoLink(resolvePrefix(prefix, item));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue';
|
|
2
|
-
import type {
|
|
2
|
+
import type { NavbarItem } from '../typings.js';
|
|
3
3
|
/**
|
|
4
4
|
* Get navbar config of repository link
|
|
5
5
|
*/
|
|
6
|
-
export declare const useNavbarRepo: () => ComputedRef<
|
|
6
|
+
export declare const useNavbarRepo: () => ComputedRef<NavbarItem[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
1
2
|
import { computed } from 'vue';
|
|
2
3
|
import { isLinkHttp } from 'vuepress/shared';
|
|
3
4
|
import { resolveRepoType } from '../utils/index.js';
|
|
4
|
-
import { useThemeLocaleData } from './useThemeData.js';
|
|
5
5
|
/**
|
|
6
6
|
* Get navbar config of repository link
|
|
7
7
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue';
|
|
2
|
-
import type {
|
|
2
|
+
import type { NavbarItem } from '../typings.js';
|
|
3
3
|
/**
|
|
4
4
|
* Get navbar config of select language dropdown
|
|
5
5
|
*/
|
|
6
|
-
export declare const useNavbarSelectLanguage: () => ComputedRef<
|
|
6
|
+
export declare const useNavbarSelectLanguage: () => ComputedRef<NavbarItem[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { useThemeData, useThemeLocaleData } from '@theme/useThemeData';
|
|
1
2
|
import { useRoutePaths } from '@vuepress/helper/client';
|
|
2
3
|
import { computed } from 'vue';
|
|
3
4
|
import { useRoute, useRouteLocale, useSiteData, useSiteLocaleData, } from 'vuepress/client';
|
|
4
|
-
import { useThemeData, useThemeLocaleData } from './useThemeData.js';
|
|
5
5
|
/**
|
|
6
6
|
* Get navbar config of select language dropdown
|
|
7
7
|
*/
|
|
@@ -36,7 +36,7 @@ export const useNavbarSelectLanguage = () => {
|
|
|
36
36
|
if (targetLang === siteLocale.value.lang) {
|
|
37
37
|
return {
|
|
38
38
|
text,
|
|
39
|
-
activeMatch:
|
|
39
|
+
activeMatch: '.',
|
|
40
40
|
link: route.fullPath,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isLinkAbsolute, isLinkWithProtocol } from '@vuepress/helper/client';
|
|
2
2
|
import { useRoute, useRouter } from 'vuepress/client';
|
|
3
|
-
const FAKE_HOST = 'http://.';
|
|
4
3
|
export const useNavigate = () => {
|
|
5
4
|
const router = useRouter();
|
|
6
5
|
const route = useRoute();
|
|
@@ -12,14 +11,12 @@ export const useNavigate = () => {
|
|
|
12
11
|
router.push(url);
|
|
13
12
|
}
|
|
14
13
|
else if (isLinkWithProtocol(url)) {
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
window.open(url);
|
|
14
|
+
// external url
|
|
15
|
+
window?.open(url);
|
|
18
16
|
}
|
|
19
17
|
else {
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
router.push(new URL(`${loc}/${encodeURI(url)}`, FAKE_HOST).pathname);
|
|
18
|
+
// relative url
|
|
19
|
+
router.push(encodeURI(url));
|
|
23
20
|
}
|
|
24
21
|
};
|
|
25
22
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
|
+
import type { AutoLinkConfig } from 'vuepress/client';
|
|
3
|
+
interface RelatedLinks {
|
|
4
|
+
prevLink: ComputedRef<AutoLinkConfig | null>;
|
|
5
|
+
nextLink: ComputedRef<AutoLinkConfig | null>;
|
|
6
|
+
}
|
|
7
|
+
export declare const useRelatedLinks: () => RelatedLinks;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useSidebarItems } from '@theme/useSidebarItems';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { resolveRoute, usePageFrontmatter, useRoute } from 'vuepress/client';
|
|
4
|
+
import { isPlainObject, isString } from 'vuepress/shared';
|
|
5
|
+
/**
|
|
6
|
+
* Resolve `prev` or `next` config from frontmatter
|
|
7
|
+
*/
|
|
8
|
+
const resolveFromFrontmatterConfig = (conf, current) => {
|
|
9
|
+
if (conf === false) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (isString(conf)) {
|
|
13
|
+
const { notFound, meta, path } = resolveRoute(conf, current);
|
|
14
|
+
return notFound
|
|
15
|
+
? { text: path, link: path }
|
|
16
|
+
: {
|
|
17
|
+
text: meta.title || path,
|
|
18
|
+
link: path,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (isPlainObject(conf)) {
|
|
22
|
+
return {
|
|
23
|
+
...conf,
|
|
24
|
+
link: resolveRoute(conf.link, current).path,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Resolve `prev` or `next` config from sidebar items
|
|
31
|
+
*/
|
|
32
|
+
const resolveFromSidebarItems = (sidebarItems, currentPath, offset) => {
|
|
33
|
+
const index = sidebarItems.findIndex((item) => item.link === currentPath);
|
|
34
|
+
if (index !== -1) {
|
|
35
|
+
const targetItem = sidebarItems[index + offset];
|
|
36
|
+
if (!targetItem?.link) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return targetItem;
|
|
40
|
+
}
|
|
41
|
+
for (const item of sidebarItems) {
|
|
42
|
+
if ('children' in item) {
|
|
43
|
+
const childResult = resolveFromSidebarItems(item.children, currentPath, offset);
|
|
44
|
+
if (childResult) {
|
|
45
|
+
return childResult;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
export const useRelatedLinks = () => {
|
|
52
|
+
const frontmatter = usePageFrontmatter();
|
|
53
|
+
const sidebarItems = useSidebarItems();
|
|
54
|
+
const route = useRoute();
|
|
55
|
+
const prevLink = computed(() => {
|
|
56
|
+
const prevConfig = resolveFromFrontmatterConfig(frontmatter.value.prev, route.path);
|
|
57
|
+
if (prevConfig !== false) {
|
|
58
|
+
return prevConfig;
|
|
59
|
+
}
|
|
60
|
+
return resolveFromSidebarItems(sidebarItems.value, route.path, -1);
|
|
61
|
+
});
|
|
62
|
+
const nextLink = computed(() => {
|
|
63
|
+
const nextConfig = resolveFromFrontmatterConfig(frontmatter.value.next, route.path);
|
|
64
|
+
if (nextConfig !== false) {
|
|
65
|
+
return nextConfig;
|
|
66
|
+
}
|
|
67
|
+
return resolveFromSidebarItems(sidebarItems.value, route.path, 1);
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
prevLink,
|
|
71
|
+
nextLink,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ComputedRef, InjectionKey } from 'vue';
|
|
2
2
|
import type { PageData, PageHeader } from 'vuepress/client';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type { SidebarArrayOptions, SidebarObjectOptions, SidebarOptions } from '../../shared/index.js';
|
|
4
|
+
import type { SidebarHeaderItem, SidebarItem } from '../typings.js';
|
|
5
|
+
export type SidebarItemsRef = ComputedRef<SidebarItem[]>;
|
|
5
6
|
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
6
7
|
/**
|
|
7
8
|
* Inject sidebar items global computed
|
|
@@ -16,21 +17,21 @@ export declare const setupSidebarItems: () => void;
|
|
|
16
17
|
*
|
|
17
18
|
* It should only be resolved and provided once
|
|
18
19
|
*/
|
|
19
|
-
export declare const resolveSidebarItems: (sidebarConfig:
|
|
20
|
+
export declare const resolveSidebarItems: (sidebarConfig: false | SidebarOptions, sidebarDepth: number, page: PageData, path: string, routeLocale: string) => SidebarItem[];
|
|
20
21
|
/**
|
|
21
22
|
* Util to transform page header to sidebar item
|
|
22
23
|
*/
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
24
|
+
export declare const resolveSidebarHeaderItem: (sidebarDepth: number, header: PageHeader) => SidebarHeaderItem;
|
|
25
|
+
export declare const resolveSidebarHeaderItems: (sidebarDepth: number, headers: PageHeader[]) => SidebarHeaderItem[];
|
|
25
26
|
/**
|
|
26
|
-
* Resolve sidebar items if the config is `
|
|
27
|
+
* Resolve current page and its header to sidebar items if the config is `heading`
|
|
27
28
|
*/
|
|
28
|
-
export declare const
|
|
29
|
+
export declare const resolveSidebarHeadingItem: (sidebarDepth: number, page: PageData) => SidebarItem[];
|
|
29
30
|
/**
|
|
30
31
|
* Resolve sidebar items if the config is an array
|
|
31
32
|
*/
|
|
32
|
-
export declare const resolveArraySidebarItems: (sidebarConfig:
|
|
33
|
+
export declare const resolveArraySidebarItems: (sidebarConfig: SidebarArrayOptions, sidebarDepth: number, page: PageData, path: string, prefix?: string) => SidebarItem[];
|
|
33
34
|
/**
|
|
34
35
|
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
35
36
|
*/
|
|
36
|
-
export declare const resolveMultiSidebarItems: (sidebarConfig:
|
|
37
|
+
export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarObjectOptions, sidebarDepth: number, page: PageData, path: string) => SidebarItem[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
1
2
|
import { keys, startsWith } from '@vuepress/helper/client';
|
|
2
3
|
import { computed, inject, provide } from 'vue';
|
|
3
4
|
import { usePageData, usePageFrontmatter, useRoute, useRouteLocale, } from 'vuepress/client';
|
|
4
5
|
import { isPlainObject, isString } from 'vuepress/shared';
|
|
5
6
|
import { getAutoLink, isLinkInternal, resolvePrefix } from '../utils/index.js';
|
|
6
|
-
import { useThemeLocaleData } from './useThemeData.js';
|
|
7
7
|
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
8
8
|
/**
|
|
9
9
|
* Inject sidebar items global computed
|
|
@@ -26,7 +26,7 @@ export const setupSidebarItems = () => {
|
|
|
26
26
|
const routeLocale = useRouteLocale();
|
|
27
27
|
const sidebarConfig = computed(() => frontmatter.value.home
|
|
28
28
|
? false
|
|
29
|
-
: frontmatter.value.sidebar ?? themeLocale.value.sidebar ?? '
|
|
29
|
+
: frontmatter.value.sidebar ?? themeLocale.value.sidebar ?? 'heading');
|
|
30
30
|
const sidebarDepth = computed(() => frontmatter.value.sidebarDepth ?? themeLocale.value.sidebarDepth ?? 2);
|
|
31
31
|
const sidebarItems = computed(() => resolveSidebarItems(sidebarConfig.value, sidebarDepth.value, page.value, route.path, routeLocale.value));
|
|
32
32
|
provide(sidebarItemsSymbol, sidebarItems);
|
|
@@ -41,8 +41,8 @@ export const resolveSidebarItems = (sidebarConfig, sidebarDepth, page, path, rou
|
|
|
41
41
|
if (sidebarConfig === false) {
|
|
42
42
|
return [];
|
|
43
43
|
}
|
|
44
|
-
if (sidebarConfig === '
|
|
45
|
-
return
|
|
44
|
+
if (sidebarConfig === 'heading') {
|
|
45
|
+
return resolveSidebarHeadingItem(sidebarDepth, page);
|
|
46
46
|
}
|
|
47
47
|
if (Array.isArray(sidebarConfig)) {
|
|
48
48
|
return resolveArraySidebarItems(sidebarConfig, sidebarDepth, page, path, routeLocale);
|
|
@@ -55,21 +55,21 @@ export const resolveSidebarItems = (sidebarConfig, sidebarDepth, page, path, rou
|
|
|
55
55
|
/**
|
|
56
56
|
* Util to transform page header to sidebar item
|
|
57
57
|
*/
|
|
58
|
-
export const
|
|
58
|
+
export const resolveSidebarHeaderItem = (sidebarDepth, header) => ({
|
|
59
59
|
text: header.title,
|
|
60
60
|
link: header.link,
|
|
61
|
-
children:
|
|
61
|
+
children: resolveSidebarHeaderItems(sidebarDepth, header.children),
|
|
62
62
|
});
|
|
63
|
-
export const
|
|
64
|
-
? headers.map((header) =>
|
|
63
|
+
export const resolveSidebarHeaderItems = (sidebarDepth, headers) => sidebarDepth > 0
|
|
64
|
+
? headers.map((header) => resolveSidebarHeaderItem(sidebarDepth - 1, header))
|
|
65
65
|
: [];
|
|
66
66
|
/**
|
|
67
|
-
* Resolve sidebar items if the config is `
|
|
67
|
+
* Resolve current page and its header to sidebar items if the config is `heading`
|
|
68
68
|
*/
|
|
69
|
-
export const
|
|
69
|
+
export const resolveSidebarHeadingItem = (sidebarDepth, page) => [
|
|
70
70
|
{
|
|
71
71
|
text: page.title,
|
|
72
|
-
children:
|
|
72
|
+
children: resolveSidebarHeaderItems(sidebarDepth, page.headers),
|
|
73
73
|
},
|
|
74
74
|
];
|
|
75
75
|
/**
|
|
@@ -87,7 +87,7 @@ export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth, page, path
|
|
|
87
87
|
: item.link,
|
|
88
88
|
}
|
|
89
89
|
: item;
|
|
90
|
-
if (childItem
|
|
90
|
+
if ('children' in childItem) {
|
|
91
91
|
return {
|
|
92
92
|
...childItem,
|
|
93
93
|
children: childItem.children.map((item) => handleChildItem(item, resolvePrefix(pathPrefix, childItem.prefix))),
|
|
@@ -100,7 +100,7 @@ export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth, page, path
|
|
|
100
100
|
const headers = page.headers[0]?.level === 1 ? page.headers[0].children : page.headers;
|
|
101
101
|
return {
|
|
102
102
|
...childItem,
|
|
103
|
-
children:
|
|
103
|
+
children: resolveSidebarHeaderItems(sidebarDepth, headers),
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
return childItem;
|
|
@@ -118,7 +118,7 @@ export const resolveMultiSidebarItems = (sidebarConfig, sidebarDepth, page, path
|
|
|
118
118
|
const matched = sidebarConfig[base];
|
|
119
119
|
return matched
|
|
120
120
|
? matched === 'heading'
|
|
121
|
-
?
|
|
121
|
+
? resolveSidebarHeadingItem(sidebarDepth, page)
|
|
122
122
|
: resolveArraySidebarItems(matched, sidebarDepth, page, path, base)
|
|
123
123
|
: [];
|
|
124
124
|
}
|
package/lib/client/config.js
CHANGED
|
@@ -16,7 +16,7 @@ export default defineClientConfig({
|
|
|
16
16
|
if (!hasGlobalComponent('CodeGroupItem'))
|
|
17
17
|
app.component('CodeGroupItem', CodeGroupItem);
|
|
18
18
|
// compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
|
|
19
|
-
app.component('
|
|
19
|
+
app.component('VPSearch', () => {
|
|
20
20
|
const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
|
|
21
21
|
if (SearchComponent) {
|
|
22
22
|
return h(SearchComponent);
|
package/lib/client/index.d.ts
CHANGED
package/lib/client/index.js
CHANGED