@vuepress/theme-default 2.0.0-rc.41 → 2.0.0-rc.42
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/VPDropdownTransition.vue +7 -5
- package/lib/client/components/VPHome.vue +1 -1
- package/lib/client/components/VPHomeFeatures.vue +4 -6
- package/lib/client/components/VPHomeFooter.vue +6 -5
- package/lib/client/components/VPHomeHero.vue +21 -23
- package/lib/client/components/VPNavbar.vue +21 -17
- package/lib/client/components/VPNavbarBrand.vue +2 -2
- package/lib/client/components/VPNavbarDropdown.vue +13 -13
- package/lib/client/components/VPNavbarItems.vue +6 -5
- package/lib/client/components/VPPage.vue +6 -5
- package/lib/client/components/VPPageMeta.vue +3 -3
- package/lib/client/components/VPPageNav.vue +9 -9
- package/lib/client/components/VPSidebar.vue +14 -13
- package/lib/client/components/VPSidebarItem.vue +13 -6
- package/lib/client/components/VPSidebarItems.vue +2 -1
- package/lib/client/components/VPToggleColorModeButton.vue +4 -3
- package/lib/client/components/VPToggleSidebarButton.vue +3 -3
- package/lib/client/components/global/Badge.vue +13 -4
- package/lib/client/components/global/CodeGroup.d.ts +1 -1
- package/lib/client/components/global/CodeGroup.js +14 -10
- package/lib/client/components/global/CodeGroupItem.vue +13 -0
- package/lib/client/composables/useContributors.d.ts +1 -1
- package/lib/client/composables/useDarkMode.js +4 -2
- package/lib/client/composables/useEditLink.d.ts +1 -1
- package/lib/client/composables/useLastUpdated.d.ts +1 -1
- package/lib/client/composables/useLastUpdated.js +1 -1
- package/lib/client/composables/useNavbarConfig.js +3 -1
- package/lib/client/composables/useNavbarSelectLanguage.js +1 -0
- package/lib/client/composables/useNavigate.js +1 -1
- package/lib/client/composables/useScrollPromise.js +3 -1
- package/lib/client/composables/useSidebarItems.d.ts +16 -16
- package/lib/client/composables/useSidebarItems.js +53 -52
- package/lib/client/composables/useUpdateDeviceStatus.d.ts +1 -1
- package/lib/client/composables/useUpdateDeviceStatus.js +8 -4
- package/lib/client/config.d.ts +1 -0
- package/lib/client/config.js +2 -1
- package/lib/client/layouts/Layout.vue +21 -17
- package/lib/client/layouts/NotFound.vue +3 -5
- package/lib/client/shim.d.ts +1 -0
- package/lib/client/styles/arrow.scss +1 -1
- package/lib/client/styles/code-group.scss +4 -4
- package/lib/client/styles/content/code.scss +3 -3
- package/lib/client/styles/content/index.scss +0 -1
- package/lib/client/styles/external-link-icon.scss +1 -1
- package/lib/client/styles/normalize.scss +25 -24
- package/lib/client/styles/plugins.scss +2 -2
- package/lib/client/styles/vars-dark.scss +21 -47
- package/lib/client/styles/vars.scss +54 -154
- package/lib/client/typings.d.ts +3 -3
- package/lib/client/utils/resolveRepoType.d.ts +1 -1
- package/lib/client/utils/resolveRepoType.js +4 -4
- package/lib/node/defaultTheme.js +10 -18
- package/lib/node/utils/assignDefaultLocaleOptions.js +2 -6
- package/lib/node/utils/index.d.ts +1 -1
- package/lib/node/utils/index.js +1 -1
- package/lib/node/utils/resolveMarkdownHintLocales.d.ts +9 -0
- package/lib/node/utils/resolveMarkdownHintLocales.js +19 -0
- package/lib/shared/navbar.d.ts +1 -1
- package/lib/shared/options.d.ts +23 -13
- package/lib/shared/page.d.ts +4 -4
- package/lib/shared/sidebar.d.ts +1 -1
- package/package.json +20 -19
- package/templates/build.html +7 -7
- package/lib/client/styles/content/custom-container.scss +0 -142
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +0 -8
- package/lib/node/utils/resolveContainerPluginOptions.js +0 -17
|
@@ -8,7 +8,13 @@ import { isActiveLinkItem } from '../utils/index.js'
|
|
|
8
8
|
|
|
9
9
|
const props = withDefaults(
|
|
10
10
|
defineProps<{
|
|
11
|
+
/**
|
|
12
|
+
* The sidebar item to be rendered
|
|
13
|
+
*/
|
|
11
14
|
item: SidebarItem
|
|
15
|
+
/**
|
|
16
|
+
* The depth of the current sidebar item
|
|
17
|
+
*/
|
|
12
18
|
depth?: number
|
|
13
19
|
}>(),
|
|
14
20
|
{ depth: 0 },
|
|
@@ -32,6 +38,7 @@ const itemClass = computed(() => ({
|
|
|
32
38
|
const isOpenDefault = computed(() =>
|
|
33
39
|
collapsible.value ? isActive.value : true,
|
|
34
40
|
)
|
|
41
|
+
// eslint-disable-next-line vue/no-ref-object-reactivity-loss
|
|
35
42
|
const [isOpen, toggleIsOpen] = useToggle(isOpenDefault.value)
|
|
36
43
|
const onClick = (e: Event): void => {
|
|
37
44
|
if (collapsible.value) {
|
|
@@ -42,8 +49,8 @@ const onClick = (e: Event): void => {
|
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
// reset open status after navigation
|
|
45
|
-
const unregisterRouterHook = router.afterEach((
|
|
46
|
-
nextTick(() => {
|
|
52
|
+
const unregisterRouterHook = router.afterEach(() => {
|
|
53
|
+
void nextTick(() => {
|
|
47
54
|
isOpen.value = isOpenDefault.value
|
|
48
55
|
})
|
|
49
56
|
})
|
|
@@ -89,7 +96,7 @@ onBeforeUnmount(() => {
|
|
|
89
96
|
|
|
90
97
|
.vp-sidebar-item {
|
|
91
98
|
border-left: 0.25rem solid transparent;
|
|
92
|
-
color: var(--c-text);
|
|
99
|
+
color: var(--vp-c-text);
|
|
93
100
|
cursor: default;
|
|
94
101
|
|
|
95
102
|
&:focus-visible {
|
|
@@ -151,8 +158,8 @@ onBeforeUnmount(() => {
|
|
|
151
158
|
}
|
|
152
159
|
|
|
153
160
|
&.active:not(p.vp-sidebar-heading) {
|
|
154
|
-
border-left-color: var(--c-
|
|
155
|
-
color: var(--c-
|
|
161
|
+
border-left-color: var(--vp-c-accent);
|
|
162
|
+
color: var(--vp-c-accent);
|
|
156
163
|
font-weight: 600;
|
|
157
164
|
}
|
|
158
165
|
}
|
|
@@ -161,7 +168,7 @@ a.vp-sidebar-item {
|
|
|
161
168
|
cursor: pointer;
|
|
162
169
|
|
|
163
170
|
&:hover {
|
|
164
|
-
color: var(--c-
|
|
171
|
+
color: var(--vp-c-accent);
|
|
165
172
|
}
|
|
166
173
|
}
|
|
167
174
|
</style>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { useSidebarItems } from '@theme/useSidebarItems'
|
|
3
2
|
import VPSidebarItem from '@theme/VPSidebarItem.vue'
|
|
3
|
+
import { useSidebarItems } from '@theme/useSidebarItems'
|
|
4
4
|
import { onMounted, watch } from 'vue'
|
|
5
5
|
import { useRoute } from 'vuepress/client'
|
|
6
6
|
|
|
@@ -46,6 +46,7 @@ onMounted(() => {
|
|
|
46
46
|
})
|
|
47
47
|
</script>
|
|
48
48
|
|
|
49
|
+
<!-- eslint-disable-next-line vue/no-root-v-if -->
|
|
49
50
|
<template>
|
|
50
51
|
<ul v-if="sidebarItems.length" class="vp-sidebar-items">
|
|
51
52
|
<VPSidebarItem
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { useDarkMode } from '@theme/useDarkMode'
|
|
3
|
-
import { useThemeLocaleData } from '@theme/useThemeData'
|
|
4
2
|
import VPDarkIcon from '@theme/VPDarkIcon.vue'
|
|
5
3
|
import VPLightIcon from '@theme/VPLightIcon.vue'
|
|
4
|
+
import { useDarkMode } from '@theme/useDarkMode'
|
|
5
|
+
import { useThemeLocaleData } from '@theme/useThemeData'
|
|
6
6
|
|
|
7
7
|
const themeLocale = useThemeLocaleData()
|
|
8
8
|
const isDarkMode = useDarkMode()
|
|
@@ -14,6 +14,7 @@ const toggleColorMode = (): void => {
|
|
|
14
14
|
|
|
15
15
|
<template>
|
|
16
16
|
<button
|
|
17
|
+
type="button"
|
|
17
18
|
class="vp-toggle-color-mode-button"
|
|
18
19
|
:title="themeLocale.toggleColorMode"
|
|
19
20
|
@click="toggleColorMode"
|
|
@@ -32,7 +33,7 @@ const toggleColorMode = (): void => {
|
|
|
32
33
|
border: 0;
|
|
33
34
|
|
|
34
35
|
background: none;
|
|
35
|
-
color: var(--c-text);
|
|
36
|
+
color: var(--vp-c-text);
|
|
36
37
|
|
|
37
38
|
opacity: 0.8;
|
|
38
39
|
cursor: pointer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { useThemeLocaleData } from '@theme/useThemeData'
|
|
3
3
|
|
|
4
|
-
defineEmits<
|
|
4
|
+
defineEmits<{ toggle: [] }>()
|
|
5
5
|
|
|
6
6
|
const themeLocale = useThemeLocaleData()
|
|
7
7
|
</script>
|
|
@@ -60,9 +60,9 @@ const themeLocale = useThemeLocaleData()
|
|
|
60
60
|
height: 2px;
|
|
61
61
|
border-radius: 2px;
|
|
62
62
|
|
|
63
|
-
background-color: var(--c-text);
|
|
63
|
+
background-color: var(--vp-c-text);
|
|
64
64
|
|
|
65
|
-
transition: transform var(--t-transform);
|
|
65
|
+
transition: transform var(--vp-t-transform);
|
|
66
66
|
|
|
67
67
|
&:nth-child(2) {
|
|
68
68
|
margin: 6px 0;
|
|
@@ -3,8 +3,17 @@ import type { VNode } from 'vue'
|
|
|
3
3
|
|
|
4
4
|
withDefaults(
|
|
5
5
|
defineProps<{
|
|
6
|
+
/**
|
|
7
|
+
* The type of the badge
|
|
8
|
+
*/
|
|
6
9
|
type?: string
|
|
10
|
+
/**
|
|
11
|
+
* The text of the badge
|
|
12
|
+
*/
|
|
7
13
|
text?: string
|
|
14
|
+
/**
|
|
15
|
+
* The vertical align of the badge
|
|
16
|
+
*/
|
|
8
17
|
vertical?: string
|
|
9
18
|
}>(),
|
|
10
19
|
{
|
|
@@ -15,7 +24,7 @@ withDefaults(
|
|
|
15
24
|
)
|
|
16
25
|
|
|
17
26
|
defineSlots<{
|
|
18
|
-
default?: () => VNode | VNode | string | null
|
|
27
|
+
default?: () => VNode | VNode[] | string | null
|
|
19
28
|
}>()
|
|
20
29
|
</script>
|
|
21
30
|
|
|
@@ -40,15 +49,15 @@ defineSlots<{
|
|
|
40
49
|
padding: 0 6px;
|
|
41
50
|
border-radius: 3px;
|
|
42
51
|
|
|
43
|
-
color: var(--c-
|
|
52
|
+
color: var(--vp-c-accent-text);
|
|
44
53
|
|
|
45
54
|
font-weight: 600;
|
|
46
55
|
font-size: 14px;
|
|
47
56
|
line-height: 18px;
|
|
48
57
|
|
|
49
58
|
transition:
|
|
50
|
-
color var(--t-color),
|
|
51
|
-
background-color var(--t-color);
|
|
59
|
+
color var(--vp-t-color),
|
|
60
|
+
background-color var(--vp-t-color);
|
|
52
61
|
|
|
53
62
|
&.tip {
|
|
54
63
|
background-color: var(--c-badge-tip);
|
|
@@ -3,5 +3,5 @@ import '../../styles/code-group.scss';
|
|
|
3
3
|
export declare const CodeGroup: import("vue").DefineComponent<{}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, SlotsType<{
|
|
6
|
-
default
|
|
6
|
+
default?: () => VNode[];
|
|
7
7
|
}>>;
|
|
@@ -28,8 +28,8 @@ export const CodeGroup = defineComponent({
|
|
|
28
28
|
const lightBg = codeBlock.style.getPropertyValue('--shiki-light-bg');
|
|
29
29
|
const darkBg = codeBlock.style.getPropertyValue('--shiki-dark-bg');
|
|
30
30
|
watch(isDark, (val) => {
|
|
31
|
-
groupRef.value.style.setProperty('--c-code-
|
|
32
|
-
groupRef.value.style.setProperty('--c-code-
|
|
31
|
+
groupRef.value.style.setProperty('--vp-c-code-tab-bg', val ? darkBg : lightBg);
|
|
32
|
+
groupRef.value.style.setProperty('--vp-c-code-tab-title', val ? darkColor : lightColor);
|
|
33
33
|
}, { immediate: true });
|
|
34
34
|
}
|
|
35
35
|
});
|
|
@@ -86,13 +86,13 @@ export const CodeGroup = defineComponent({
|
|
|
86
86
|
};
|
|
87
87
|
return () => {
|
|
88
88
|
// get children code-group-item from default slots
|
|
89
|
-
const items = (slots.default?.()
|
|
90
|
-
.filter((
|
|
91
|
-
.map((
|
|
92
|
-
if (
|
|
93
|
-
|
|
89
|
+
const items = (slots.default?.() ?? [])
|
|
90
|
+
.filter((vNode) => vNode.type.name === 'CodeGroupItem')
|
|
91
|
+
.map((vNode) => {
|
|
92
|
+
if (vNode.props === null) {
|
|
93
|
+
vNode.props = {};
|
|
94
94
|
}
|
|
95
|
-
return
|
|
95
|
+
return vNode;
|
|
96
96
|
});
|
|
97
97
|
// do not render anything if there is no code-group-item
|
|
98
98
|
if (items.length === 0) {
|
|
@@ -129,8 +129,12 @@ export const CodeGroup = defineComponent({
|
|
|
129
129
|
},
|
|
130
130
|
role: 'tab',
|
|
131
131
|
ariaSelected: isActive,
|
|
132
|
-
onClick: () =>
|
|
133
|
-
|
|
132
|
+
onClick: () => {
|
|
133
|
+
activeIndex.value = i;
|
|
134
|
+
},
|
|
135
|
+
onKeydown: (e) => {
|
|
136
|
+
keyboardHandler(e, i);
|
|
137
|
+
},
|
|
134
138
|
}, vnode.props.title);
|
|
135
139
|
})),
|
|
136
140
|
items,
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import type { VNode } from 'vue'
|
|
3
|
+
|
|
2
4
|
defineOptions({
|
|
3
5
|
name: 'CodeGroupItem',
|
|
4
6
|
})
|
|
5
7
|
|
|
6
8
|
defineProps<{
|
|
9
|
+
/**
|
|
10
|
+
* The title of the code group item
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line vue/no-unused-properties, vue/require-prop-comment
|
|
7
13
|
title: string
|
|
14
|
+
/**
|
|
15
|
+
* Whether the code group item is active
|
|
16
|
+
*/
|
|
8
17
|
active?: boolean
|
|
9
18
|
}>()
|
|
19
|
+
|
|
20
|
+
defineSlots<{
|
|
21
|
+
default?: () => VNode | VNode[] | null
|
|
22
|
+
}>()
|
|
10
23
|
</script>
|
|
11
24
|
|
|
12
25
|
<template>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue';
|
|
2
2
|
import type { DefaultThemePageData } from '../../shared/index.js';
|
|
3
|
-
export declare const useContributors: () => ComputedRef<
|
|
3
|
+
export declare const useContributors: () => ComputedRef<Exclude<DefaultThemePageData["git"], undefined>["contributors"] | null>;
|
|
@@ -6,13 +6,15 @@ const applyDarkmodeToHTML = (isDarkMode) => {
|
|
|
6
6
|
const update = (value = isDarkMode.value) => {
|
|
7
7
|
// set `class="dark"` on `<html>` element
|
|
8
8
|
const el = window.document.documentElement;
|
|
9
|
-
|
|
9
|
+
// set `data-theme="light|dark"` on `<html>` element
|
|
10
10
|
el.dataset.theme = value ? 'dark' : 'light';
|
|
11
11
|
};
|
|
12
12
|
onMounted(() => {
|
|
13
13
|
watch(isDarkMode, update, { immediate: true });
|
|
14
14
|
});
|
|
15
|
-
onUnmounted(() =>
|
|
15
|
+
onUnmounted(() => {
|
|
16
|
+
update();
|
|
17
|
+
});
|
|
16
18
|
};
|
|
17
19
|
/**
|
|
18
20
|
* Inject dark mode global computed
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue';
|
|
2
|
-
export declare const useLastUpdated: () => ComputedRef<
|
|
2
|
+
export declare const useLastUpdated: () => ComputedRef<string | null>;
|
|
@@ -11,7 +11,7 @@ export const useLastUpdated = () => {
|
|
|
11
11
|
return null;
|
|
12
12
|
if (!page.value.git?.updatedTime)
|
|
13
13
|
return null;
|
|
14
|
-
const updatedDate = new Date(page.value.git
|
|
14
|
+
const updatedDate = new Date(page.value.git.updatedTime);
|
|
15
15
|
return updatedDate.toLocaleString();
|
|
16
16
|
});
|
|
17
17
|
};
|
|
@@ -21,5 +21,7 @@ const resolveNavbarItem = (item, prefix = '') => {
|
|
|
21
21
|
};
|
|
22
22
|
export const useNavbarConfig = () => {
|
|
23
23
|
const themeLocale = useThemeLocaleData();
|
|
24
|
-
return computed(() =>
|
|
24
|
+
return computed(() =>
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
26
|
+
(themeLocale.value.navbar || []).map((item) => resolveNavbarItem(item)));
|
|
25
27
|
};
|
|
@@ -27,6 +27,7 @@ export const useNavbarSelectLanguage = () => {
|
|
|
27
27
|
themeLocale.value.selectLanguageText}`,
|
|
28
28
|
children: localePaths.map((targetLocalePath) => {
|
|
29
29
|
// target locale config of this language link
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
30
31
|
const targetSiteLocale = site.value.locales?.[targetLocalePath] ?? {};
|
|
31
32
|
const targetThemeLocale = theme.value.locales?.[targetLocalePath] ?? {};
|
|
32
33
|
const targetLang = `${targetSiteLocale.lang}`;
|
|
@@ -3,7 +3,9 @@ let promiseResolve = null;
|
|
|
3
3
|
const scrollPromise = {
|
|
4
4
|
wait: () => promise,
|
|
5
5
|
pending: () => {
|
|
6
|
-
promise = new Promise((resolve) =>
|
|
6
|
+
promise = new Promise((resolve) => {
|
|
7
|
+
promiseResolve = resolve;
|
|
8
|
+
});
|
|
7
9
|
},
|
|
8
10
|
resolve: () => {
|
|
9
11
|
promiseResolve?.();
|
|
@@ -7,22 +7,6 @@ export type HeadersRef = Ref<MenuItem[]>;
|
|
|
7
7
|
export declare const headersRef: HeadersRef;
|
|
8
8
|
export declare const setupHeaders: () => void;
|
|
9
9
|
export declare const useHeaders: () => HeadersRef;
|
|
10
|
-
export type SidebarItemsRef = ComputedRef<SidebarItem[]>;
|
|
11
|
-
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
12
|
-
/**
|
|
13
|
-
* Inject sidebar items global computed
|
|
14
|
-
*/
|
|
15
|
-
export declare const useSidebarItems: () => SidebarItemsRef;
|
|
16
|
-
/**
|
|
17
|
-
* Create sidebar items ref and provide as global computed in setup
|
|
18
|
-
*/
|
|
19
|
-
export declare const setupSidebarItems: () => void;
|
|
20
|
-
/**
|
|
21
|
-
* Resolve sidebar items global computed
|
|
22
|
-
*
|
|
23
|
-
* It should only be resolved and provided once
|
|
24
|
-
*/
|
|
25
|
-
export declare const resolveSidebarItems: (sidebarConfig: false | SidebarOptions, page: PageData, path: string, routeLocale: string, headers: MenuItem[]) => SidebarItem[];
|
|
26
10
|
/**
|
|
27
11
|
* Util to transform page header to sidebar item
|
|
28
12
|
*/
|
|
@@ -40,3 +24,19 @@ export declare const resolveArraySidebarItems: (sidebarConfig: SidebarArrayOptio
|
|
|
40
24
|
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
41
25
|
*/
|
|
42
26
|
export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarObjectOptions, page: PageData, headers: MenuItem[], path: string) => SidebarItem[];
|
|
27
|
+
export type SidebarItemsRef = ComputedRef<SidebarItem[]>;
|
|
28
|
+
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
29
|
+
/**
|
|
30
|
+
* Inject sidebar items global computed
|
|
31
|
+
*/
|
|
32
|
+
export declare const useSidebarItems: () => SidebarItemsRef;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve sidebar items global computed
|
|
35
|
+
*
|
|
36
|
+
* It should only be resolved and provided once
|
|
37
|
+
*/
|
|
38
|
+
export declare const resolveSidebarItems: (sidebarConfig: SidebarOptions | false, page: PageData, path: string, routeLocale: string, headers: MenuItem[]) => SidebarItem[];
|
|
39
|
+
/**
|
|
40
|
+
* Create sidebar items ref and provide as global computed in setup
|
|
41
|
+
*/
|
|
42
|
+
export declare const setupSidebarItems: () => void;
|
|
@@ -21,9 +21,6 @@ export const setupHeaders = () => {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
headersRef.value = getHeaders({
|
|
24
|
-
selector: [...new Array(6)]
|
|
25
|
-
.map((_, i) => `.theme-default-content h${i + 1}`)
|
|
26
|
-
.join(','),
|
|
27
24
|
levels: [2, levels.value + 1],
|
|
28
25
|
ignore: ['.vp-badge'],
|
|
29
26
|
});
|
|
@@ -32,60 +29,13 @@ export const setupHeaders = () => {
|
|
|
32
29
|
onMounted(updateHeaders);
|
|
33
30
|
};
|
|
34
31
|
export const useHeaders = () => headersRef;
|
|
35
|
-
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
36
|
-
/**
|
|
37
|
-
* Inject sidebar items global computed
|
|
38
|
-
*/
|
|
39
|
-
export const useSidebarItems = () => {
|
|
40
|
-
const sidebarItems = inject(sidebarItemsSymbol);
|
|
41
|
-
if (!sidebarItems) {
|
|
42
|
-
throw new Error('useSidebarItems() is called without provider.');
|
|
43
|
-
}
|
|
44
|
-
return sidebarItems;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Create sidebar items ref and provide as global computed in setup
|
|
48
|
-
*/
|
|
49
|
-
export const setupSidebarItems = () => {
|
|
50
|
-
const themeLocale = useThemeLocaleData();
|
|
51
|
-
const frontmatter = usePageFrontmatter();
|
|
52
|
-
const page = usePageData();
|
|
53
|
-
const route = useRoute();
|
|
54
|
-
const routeLocale = useRouteLocale();
|
|
55
|
-
const headers = useHeaders();
|
|
56
|
-
const sidebarConfig = computed(() => frontmatter.value.home
|
|
57
|
-
? false
|
|
58
|
-
: (frontmatter.value.sidebar ?? themeLocale.value.sidebar ?? 'heading'));
|
|
59
|
-
const sidebarItems = computed(() => resolveSidebarItems(sidebarConfig.value, page.value, route.path, routeLocale.value, headers.value));
|
|
60
|
-
provide(sidebarItemsSymbol, sidebarItems);
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Resolve sidebar items global computed
|
|
64
|
-
*
|
|
65
|
-
* It should only be resolved and provided once
|
|
66
|
-
*/
|
|
67
|
-
export const resolveSidebarItems = (sidebarConfig, page, path, routeLocale, headers) => {
|
|
68
|
-
// resolve sidebar items according to the config
|
|
69
|
-
if (sidebarConfig === false) {
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
if (sidebarConfig === 'heading') {
|
|
73
|
-
return resolveSidebarHeadingItem(page, headers);
|
|
74
|
-
}
|
|
75
|
-
if (Array.isArray(sidebarConfig)) {
|
|
76
|
-
return resolveArraySidebarItems(sidebarConfig, headers, path, routeLocale);
|
|
77
|
-
}
|
|
78
|
-
if (isPlainObject(sidebarConfig)) {
|
|
79
|
-
return resolveMultiSidebarItems(sidebarConfig, page, headers, path);
|
|
80
|
-
}
|
|
81
|
-
return [];
|
|
82
|
-
};
|
|
83
32
|
/**
|
|
84
33
|
* Util to transform page header to sidebar item
|
|
85
34
|
*/
|
|
86
35
|
export const resolveSidebarHeaderItem = (header) => ({
|
|
87
36
|
text: header.title,
|
|
88
37
|
link: header.link,
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
89
39
|
children: resolveSidebarHeaderItems(header.children),
|
|
90
40
|
});
|
|
91
41
|
export const resolveSidebarHeaderItems = (headers) => headers ? headers.map((header) => resolveSidebarHeaderItem(header)) : [];
|
|
@@ -116,7 +66,7 @@ export const resolveArraySidebarItems = (sidebarConfig, headers, path, prefix =
|
|
|
116
66
|
if ('children' in childItem) {
|
|
117
67
|
return {
|
|
118
68
|
...childItem,
|
|
119
|
-
children: childItem.children.map((
|
|
69
|
+
children: childItem.children.map((child) => handleChildItem(child, resolvePrefix(pathPrefix, childItem.prefix))),
|
|
120
70
|
};
|
|
121
71
|
}
|
|
122
72
|
// if the sidebar item is current page and children is not set
|
|
@@ -148,6 +98,57 @@ export const resolveMultiSidebarItems = (sidebarConfig, page, headers, path) =>
|
|
|
148
98
|
: resolveArraySidebarItems(matched, headers, path, base)
|
|
149
99
|
: [];
|
|
150
100
|
}
|
|
101
|
+
// eslint-disable-next-line no-console
|
|
151
102
|
console.warn(`${decodeURI(path)} is missing sidebar config.`);
|
|
152
103
|
return [];
|
|
153
104
|
};
|
|
105
|
+
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
106
|
+
/**
|
|
107
|
+
* Inject sidebar items global computed
|
|
108
|
+
*/
|
|
109
|
+
export const useSidebarItems = () => {
|
|
110
|
+
const sidebarItems = inject(sidebarItemsSymbol);
|
|
111
|
+
if (!sidebarItems) {
|
|
112
|
+
throw new Error('useSidebarItems() is called without provider.');
|
|
113
|
+
}
|
|
114
|
+
return sidebarItems;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Resolve sidebar items global computed
|
|
118
|
+
*
|
|
119
|
+
* It should only be resolved and provided once
|
|
120
|
+
*/
|
|
121
|
+
export const resolveSidebarItems = (sidebarConfig, page, path, routeLocale, headers) => {
|
|
122
|
+
// resolve sidebar items according to the config
|
|
123
|
+
if (sidebarConfig === false) {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
if (sidebarConfig === 'heading') {
|
|
127
|
+
return resolveSidebarHeadingItem(page, headers);
|
|
128
|
+
}
|
|
129
|
+
if (Array.isArray(sidebarConfig)) {
|
|
130
|
+
return resolveArraySidebarItems(sidebarConfig, headers, path, routeLocale);
|
|
131
|
+
}
|
|
132
|
+
if (isPlainObject(sidebarConfig)) {
|
|
133
|
+
return resolveMultiSidebarItems(sidebarConfig, page, headers, path);
|
|
134
|
+
}
|
|
135
|
+
return [];
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Create sidebar items ref and provide as global computed in setup
|
|
139
|
+
*/
|
|
140
|
+
export const setupSidebarItems = () => {
|
|
141
|
+
const themeLocale = useThemeLocaleData();
|
|
142
|
+
const frontmatter = usePageFrontmatter();
|
|
143
|
+
const page = usePageData();
|
|
144
|
+
const route = useRoute();
|
|
145
|
+
const routeLocale = useRouteLocale();
|
|
146
|
+
const headers = useHeaders();
|
|
147
|
+
const sidebarConfig = computed(() => frontmatter.value.home
|
|
148
|
+
? false
|
|
149
|
+
: (frontmatter.value.sidebar ??
|
|
150
|
+
themeLocale.value.sidebar ??
|
|
151
|
+
'heading'));
|
|
152
|
+
const sidebarItems = computed(() => resolveSidebarItems(sidebarConfig.value, page.value, route.path, routeLocale.value, headers.value));
|
|
153
|
+
provide(sidebarItemsSymbol, sidebarItems);
|
|
154
|
+
};
|
|
@@ -3,10 +3,10 @@ import { onMounted } from 'vue';
|
|
|
3
3
|
import cssVariables from '../styles/_variables.module.scss';
|
|
4
4
|
export var DeviceType;
|
|
5
5
|
(function (DeviceType) {
|
|
6
|
-
DeviceType["
|
|
6
|
+
DeviceType["Mobile"] = "mobile";
|
|
7
7
|
})(DeviceType || (DeviceType = {}));
|
|
8
8
|
const DeviceTypeMap = {
|
|
9
|
-
[DeviceType.
|
|
9
|
+
[DeviceType.Mobile]: Number.parseInt(cssVariables.mobile.replace('px', ''), 10),
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* add listener to detect screen though device type
|
|
@@ -18,8 +18,12 @@ export const useUpdateDeviceStatus = (deviceType, callback) => {
|
|
|
18
18
|
throw new Error('device width must be a integer');
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
useEventListener('orientationchange', () =>
|
|
22
|
-
|
|
21
|
+
useEventListener('orientationchange', () => {
|
|
22
|
+
callback(width);
|
|
23
|
+
}, false);
|
|
24
|
+
useEventListener('resize', () => {
|
|
25
|
+
callback(width);
|
|
26
|
+
}, false);
|
|
23
27
|
onMounted(() => {
|
|
24
28
|
callback(width);
|
|
25
29
|
});
|
package/lib/client/config.d.ts
CHANGED
package/lib/client/config.js
CHANGED
|
@@ -7,6 +7,7 @@ import { defineClientConfig } from 'vuepress/client';
|
|
|
7
7
|
import { Badge, CodeGroup, CodeGroupItem } from './components/global/index.js';
|
|
8
8
|
import Layout from './layouts/Layout.vue';
|
|
9
9
|
import NotFound from './layouts/NotFound.vue';
|
|
10
|
+
import '@vuepress/helper/colors.css';
|
|
10
11
|
import '@vuepress/helper/normalize.css';
|
|
11
12
|
import './styles/index.scss';
|
|
12
13
|
export default defineClientConfig({
|
|
@@ -19,7 +20,7 @@ export default defineClientConfig({
|
|
|
19
20
|
app.component('CodeGroupItem', CodeGroupItem);
|
|
20
21
|
// compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
|
|
21
22
|
app.component('VPSearch', () => {
|
|
22
|
-
const SearchComponent = app.component('Docsearch')
|
|
23
|
+
const SearchComponent = app.component('Docsearch') ?? app.component('SearchBox');
|
|
23
24
|
if (SearchComponent) {
|
|
24
25
|
return h(SearchComponent);
|
|
25
26
|
}
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { useScrollPromise } from '@theme/useScrollPromise'
|
|
3
|
-
import { useSidebarItems } from '@theme/useSidebarItems'
|
|
4
|
-
import { useThemeLocaleData } from '@theme/useThemeData'
|
|
5
2
|
import VPHome from '@theme/VPHome.vue'
|
|
6
3
|
import VPNavbar from '@theme/VPNavbar.vue'
|
|
7
4
|
import VPPage from '@theme/VPPage.vue'
|
|
8
5
|
import VPSidebar from '@theme/VPSidebar.vue'
|
|
6
|
+
import { useScrollPromise } from '@theme/useScrollPromise'
|
|
7
|
+
import { useSidebarItems } from '@theme/useSidebarItems'
|
|
8
|
+
import { useThemeLocaleData } from '@theme/useThemeData'
|
|
9
|
+
import type { VNode } from 'vue'
|
|
9
10
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
10
11
|
import { usePageData, usePageFrontmatter, useRouter } from 'vuepress/client'
|
|
11
12
|
import type { DefaultThemePageFrontmatter } from '../../shared/index.js'
|
|
12
13
|
|
|
13
14
|
defineSlots<{
|
|
14
|
-
'navbar'?: (props: Record<never, never>) =>
|
|
15
|
-
'navbar-before'?: (props: Record<never, never>) =>
|
|
16
|
-
'navbar-after'?: (props: Record<never, never>) =>
|
|
17
|
-
'sidebar'?: (props: Record<never, never>) =>
|
|
18
|
-
'sidebar-top'?: (props: Record<never, never>) =>
|
|
19
|
-
'sidebar-bottom'?: (props: Record<never, never>) =>
|
|
20
|
-
'page'?: (props: Record<never, never>) =>
|
|
21
|
-
'page-top'?: (props: Record<never, never>) =>
|
|
22
|
-
'page-bottom'?: (props: Record<never, never>) =>
|
|
23
|
-
'page-content-top'?: (props: Record<never, never>) =>
|
|
24
|
-
'page-content-bottom'?: (
|
|
15
|
+
'navbar'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
16
|
+
'navbar-before'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
17
|
+
'navbar-after'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
18
|
+
'sidebar'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
19
|
+
'sidebar-top'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
20
|
+
'sidebar-bottom'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
21
|
+
'page'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
22
|
+
'page-top'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
23
|
+
'page-bottom'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
24
|
+
'page-content-top'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
25
|
+
'page-content-bottom'?: (
|
|
26
|
+
props: Record<never, never>,
|
|
27
|
+
) => VNode | VNode[] | null
|
|
25
28
|
}>()
|
|
26
29
|
|
|
27
30
|
const page = usePageData()
|
|
@@ -41,11 +44,11 @@ const toggleSidebar = (to?: boolean): void => {
|
|
|
41
44
|
isSidebarOpen.value = typeof to === 'boolean' ? to : !isSidebarOpen.value
|
|
42
45
|
}
|
|
43
46
|
const touchStart = { x: 0, y: 0 }
|
|
44
|
-
const onTouchStart = (e): void => {
|
|
47
|
+
const onTouchStart = (e: TouchEvent): void => {
|
|
45
48
|
touchStart.x = e.changedTouches[0].clientX
|
|
46
49
|
touchStart.y = e.changedTouches[0].clientY
|
|
47
50
|
}
|
|
48
|
-
const onTouchEnd = (e): void => {
|
|
51
|
+
const onTouchEnd = (e: TouchEvent): void => {
|
|
49
52
|
const dx = e.changedTouches[0].clientX - touchStart.x
|
|
50
53
|
const dy = e.changedTouches[0].clientY - touchStart.y
|
|
51
54
|
if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 40) {
|
|
@@ -77,7 +80,7 @@ const containerClass = computed(() => [
|
|
|
77
80
|
])
|
|
78
81
|
|
|
79
82
|
// close sidebar after navigation
|
|
80
|
-
let unregisterRouterHook
|
|
83
|
+
let unregisterRouterHook: () => void
|
|
81
84
|
onMounted(() => {
|
|
82
85
|
const router = useRouter()
|
|
83
86
|
unregisterRouterHook = router.afterEach(() => {
|
|
@@ -98,6 +101,7 @@ const onBeforeLeave = scrollPromise.pending
|
|
|
98
101
|
<div
|
|
99
102
|
class="vp-theme-container"
|
|
100
103
|
:class="containerClass"
|
|
104
|
+
vp-container
|
|
101
105
|
@touchstart="onTouchStart"
|
|
102
106
|
@touchend="onTouchEnd"
|
|
103
107
|
>
|