@vuepress/theme-default 2.0.0-rc.70 → 2.0.0-rc.72
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/VPPage.vue +0 -3
- package/lib/client/composables/useHeaders.d.ts +9 -0
- package/lib/client/composables/useHeaders.js +37 -0
- package/lib/client/composables/useSidebarItems.d.ts +1 -5
- package/lib/client/composables/useSidebarItems.js +4 -28
- package/lib/client/config.js +2 -0
- package/package.json +14 -14
|
@@ -3,7 +3,6 @@ import VPPageMeta from '@theme/VPPageMeta.vue'
|
|
|
3
3
|
import VPPageNav from '@theme/VPPageNav.vue'
|
|
4
4
|
import type { VNode } from 'vue'
|
|
5
5
|
import { Content } from 'vuepress/client'
|
|
6
|
-
import { setupHeaders } from '../composables/index.js'
|
|
7
6
|
|
|
8
7
|
defineSlots<{
|
|
9
8
|
'top'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
@@ -11,8 +10,6 @@ defineSlots<{
|
|
|
11
10
|
'content-top'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
12
11
|
'content-bottom'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
13
12
|
}>()
|
|
14
|
-
|
|
15
|
-
setupHeaders()
|
|
16
13
|
</script>
|
|
17
14
|
|
|
18
15
|
<template>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MenuItem } from '@vuepress/helper/client';
|
|
2
|
+
import type { InjectionKey, Ref } from 'vue';
|
|
3
|
+
export type HeadersRef = Ref<MenuItem[]>;
|
|
4
|
+
export declare const headersSymbol: InjectionKey<HeadersRef>;
|
|
5
|
+
/**
|
|
6
|
+
* Inject headers
|
|
7
|
+
*/
|
|
8
|
+
export declare const useHeaders: () => HeadersRef;
|
|
9
|
+
export declare const setupHeaders: () => void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { getHeaders } from '@vuepress/helper/client';
|
|
3
|
+
import { injectLocal, provideLocal, watchImmediate } from '@vueuse/core';
|
|
4
|
+
import { computed, onMounted, ref } from 'vue';
|
|
5
|
+
import { usePageFrontmatter, useRoutePath } from 'vuepress/client';
|
|
6
|
+
export const headersSymbol = Symbol('headers');
|
|
7
|
+
/**
|
|
8
|
+
* Inject headers
|
|
9
|
+
*/
|
|
10
|
+
export const useHeaders = () => {
|
|
11
|
+
const headers = injectLocal(headersSymbol);
|
|
12
|
+
if (!headers) {
|
|
13
|
+
throw new Error('useHeaders() is called without provider.');
|
|
14
|
+
}
|
|
15
|
+
return headers;
|
|
16
|
+
};
|
|
17
|
+
export const setupHeaders = () => {
|
|
18
|
+
const headersRef = ref([]);
|
|
19
|
+
const routePath = useRoutePath();
|
|
20
|
+
const themeLocale = useThemeLocaleData();
|
|
21
|
+
const frontmatter = usePageFrontmatter();
|
|
22
|
+
const levels = computed(() => frontmatter.value.sidebarDepth ?? themeLocale.value.sidebarDepth ?? 2);
|
|
23
|
+
const updateHeaders = () => {
|
|
24
|
+
if (levels.value <= 0) {
|
|
25
|
+
headersRef.value = [];
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
headersRef.value = getHeaders({
|
|
29
|
+
levels: [2, levels.value + 1],
|
|
30
|
+
ignore: ['.vp-badge'],
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
provideLocal(headersSymbol, headersRef);
|
|
34
|
+
onMounted(() => {
|
|
35
|
+
watchImmediate(() => [levels, routePath], updateHeaders);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { MenuItem } from '@vuepress/helper/client';
|
|
2
|
-
import type { ComputedRef, InjectionKey
|
|
2
|
+
import type { ComputedRef, InjectionKey } from 'vue';
|
|
3
3
|
import type { PageData } from 'vuepress/client';
|
|
4
4
|
import type { SidebarArrayOptions, SidebarObjectOptions, SidebarOptions } from '../../shared/index.js';
|
|
5
5
|
import type { SidebarHeaderItem, SidebarItem } from '../typings.js';
|
|
6
|
-
export type HeadersRef = Ref<MenuItem[]>;
|
|
7
|
-
export declare const headersRef: HeadersRef;
|
|
8
|
-
export declare const setupHeaders: () => void;
|
|
9
|
-
export declare const useHeaders: () => HeadersRef;
|
|
10
6
|
/**
|
|
11
7
|
* Util to transform page header to sidebar item
|
|
12
8
|
*/
|
|
@@ -1,35 +1,11 @@
|
|
|
1
1
|
import { resolveAutoLink } from '@theme/resolveAutoLink';
|
|
2
2
|
import { resolvePrefix } from '@theme/resolvePrefix';
|
|
3
|
+
import { useHeaders } from '@theme/useHeaders';
|
|
3
4
|
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
4
|
-
import {
|
|
5
|
-
import { computed, inject,
|
|
6
|
-
import { usePageData, usePageFrontmatter, useRoute, useRouteLocale,
|
|
5
|
+
import { isLinkRelative, keys, startsWith } from '@vuepress/helper/client';
|
|
6
|
+
import { computed, inject, provide } from 'vue';
|
|
7
|
+
import { usePageData, usePageFrontmatter, useRoute, useRouteLocale, } from 'vuepress/client';
|
|
7
8
|
import { isPlainObject, isString } from 'vuepress/shared';
|
|
8
|
-
export const headersRef = ref([]);
|
|
9
|
-
export const setupHeaders = () => {
|
|
10
|
-
const router = useRouter();
|
|
11
|
-
const themeLocale = useThemeLocaleData();
|
|
12
|
-
const frontmatter = usePageFrontmatter();
|
|
13
|
-
const levels = computed(() => frontmatter.value.sidebarDepth ?? themeLocale.value.sidebarDepth ?? 2);
|
|
14
|
-
router.beforeEach((to, from) => {
|
|
15
|
-
if (to.path !== from.path) {
|
|
16
|
-
headersRef.value = [];
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const updateHeaders = () => {
|
|
20
|
-
if (levels.value <= 0) {
|
|
21
|
-
headersRef.value = [];
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
headersRef.value = getHeaders({
|
|
25
|
-
levels: [2, levels.value + 1],
|
|
26
|
-
ignore: ['.vp-badge'],
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
watch(levels, updateHeaders);
|
|
30
|
-
onMounted(updateHeaders);
|
|
31
|
-
};
|
|
32
|
-
export const useHeaders = () => headersRef;
|
|
33
9
|
/**
|
|
34
10
|
* Util to transform page header to sidebar item
|
|
35
11
|
*/
|
package/lib/client/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { setupDarkMode } from '@theme/useDarkMode';
|
|
2
|
+
import { setupHeaders } from '@theme/useHeaders';
|
|
2
3
|
import { useScrollPromise } from '@theme/useScrollPromise';
|
|
3
4
|
import { setupSidebarItems } from '@theme/useSidebarItems';
|
|
4
5
|
import { hasGlobalComponent } from '@vuepress/helper/client';
|
|
@@ -22,6 +23,7 @@ export default defineClientConfig({
|
|
|
22
23
|
},
|
|
23
24
|
setup() {
|
|
24
25
|
setupDarkMode();
|
|
26
|
+
setupHeaders();
|
|
25
27
|
setupSidebarItems();
|
|
26
28
|
},
|
|
27
29
|
layouts: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/theme-default",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.72",
|
|
4
4
|
"description": "Default theme of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-theme",
|
|
@@ -37,20 +37,20 @@
|
|
|
37
37
|
"templates"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@vuepress/helper": "2.0.0-rc.
|
|
40
|
+
"@vuepress/helper": "2.0.0-rc.71",
|
|
41
41
|
"@vuepress/plugin-active-header-links": "2.0.0-rc.70",
|
|
42
|
-
"@vuepress/plugin-back-to-top": "2.0.0-rc.
|
|
43
|
-
"@vuepress/plugin-copy-code": "2.0.0-rc.
|
|
42
|
+
"@vuepress/plugin-back-to-top": "2.0.0-rc.71",
|
|
43
|
+
"@vuepress/plugin-copy-code": "2.0.0-rc.71",
|
|
44
44
|
"@vuepress/plugin-git": "2.0.0-rc.68",
|
|
45
|
-
"@vuepress/plugin-links-check": "2.0.0-rc.
|
|
46
|
-
"@vuepress/plugin-markdown-hint": "2.0.0-rc.
|
|
47
|
-
"@vuepress/plugin-markdown-tab": "2.0.0-rc.
|
|
48
|
-
"@vuepress/plugin-medium-zoom": "2.0.0-rc.
|
|
49
|
-
"@vuepress/plugin-nprogress": "2.0.0-rc.
|
|
50
|
-
"@vuepress/plugin-palette": "2.0.0-rc.
|
|
51
|
-
"@vuepress/plugin-prismjs": "2.0.0-rc.
|
|
52
|
-
"@vuepress/plugin-seo": "2.0.0-rc.
|
|
53
|
-
"@vuepress/plugin-sitemap": "2.0.0-rc.
|
|
45
|
+
"@vuepress/plugin-links-check": "2.0.0-rc.71",
|
|
46
|
+
"@vuepress/plugin-markdown-hint": "2.0.0-rc.71",
|
|
47
|
+
"@vuepress/plugin-markdown-tab": "2.0.0-rc.71",
|
|
48
|
+
"@vuepress/plugin-medium-zoom": "2.0.0-rc.71",
|
|
49
|
+
"@vuepress/plugin-nprogress": "2.0.0-rc.71",
|
|
50
|
+
"@vuepress/plugin-palette": "2.0.0-rc.71",
|
|
51
|
+
"@vuepress/plugin-prismjs": "2.0.0-rc.71",
|
|
52
|
+
"@vuepress/plugin-seo": "2.0.0-rc.71",
|
|
53
|
+
"@vuepress/plugin-sitemap": "2.0.0-rc.71",
|
|
54
54
|
"@vuepress/plugin-theme-data": "2.0.0-rc.70",
|
|
55
55
|
"@vueuse/core": "^12.4.0",
|
|
56
56
|
"vue": "^3.5.13"
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "bcf4a894271f9673b01dd1b7b19182aecdb5c00f"
|
|
79
79
|
}
|