@vuepress/theme-default 2.0.0-beta.30 → 2.0.0-beta.31
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/Sidebar.vue +2 -14
- package/lib/client/components/SidebarItem.vue +69 -0
- package/lib/client/components/SidebarItems.vue +16 -0
- package/lib/client/styles/{_wrapper.scss → _mixins.scss} +6 -1
- package/lib/client/styles/code.scss +2 -1
- package/lib/client/styles/dropdown.scss +2 -2
- package/lib/client/styles/layout.scss +2 -2
- package/lib/client/styles/normalize.scss +4 -0
- package/lib/client/styles/page.scss +3 -3
- package/lib/client/styles/sidebar.scss +61 -64
- package/lib/client/utils/index.d.ts +1 -0
- package/lib/client/utils/index.js +1 -0
- package/lib/client/utils/isActiveSidebarItem.d.ts +3 -0
- package/lib/client/utils/isActiveSidebarItem.js +20 -0
- package/lib/shared/nav.d.ts +9 -3
- package/package.json +2 -2
- package/lib/client/components/SidebarChild.d.ts +0 -6
- package/lib/client/components/SidebarChild.js +0 -76
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { useSidebarItems } from '../composables'
|
|
3
2
|
import NavbarLinks from './NavbarLinks.vue'
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
const sidebarItems = useSidebarItems()
|
|
3
|
+
import SidebarItems from './SidebarItems.vue'
|
|
7
4
|
</script>
|
|
8
5
|
|
|
9
6
|
<template>
|
|
10
7
|
<aside class="sidebar">
|
|
11
8
|
<NavbarLinks />
|
|
12
|
-
|
|
13
9
|
<slot name="top" />
|
|
14
|
-
|
|
15
|
-
<ul class="sidebar-links">
|
|
16
|
-
<SidebarChild
|
|
17
|
-
v-for="item in sidebarItems"
|
|
18
|
-
:key="item.link || item.text"
|
|
19
|
-
:item="item"
|
|
20
|
-
/>
|
|
21
|
-
</ul>
|
|
22
|
-
|
|
10
|
+
<SidebarItems />
|
|
23
11
|
<slot name="bottom" />
|
|
24
12
|
</aside>
|
|
25
13
|
</template>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, toRefs } from 'vue'
|
|
3
|
+
import type { PropType } from 'vue'
|
|
4
|
+
import { useRoute, useRouter } from 'vue-router'
|
|
5
|
+
import type { ResolvedSidebarItem } from '../../shared'
|
|
6
|
+
import { isActiveSidebarItem } from '../utils'
|
|
7
|
+
import DropdownTransition from './DropdownTransition.vue'
|
|
8
|
+
import NavLink from './NavLink.vue'
|
|
9
|
+
|
|
10
|
+
const props = defineProps({
|
|
11
|
+
item: {
|
|
12
|
+
type: Object as PropType<ResolvedSidebarItem>,
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
depth: {
|
|
16
|
+
type: Number,
|
|
17
|
+
required: false,
|
|
18
|
+
default: 0,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const { item, depth } = toRefs(props)
|
|
23
|
+
const route = useRoute()
|
|
24
|
+
const router = useRouter()
|
|
25
|
+
|
|
26
|
+
const isActive = computed(() => isActiveSidebarItem(item.value, route))
|
|
27
|
+
const itemClass = computed(() => ({
|
|
28
|
+
'sidebar-item': true,
|
|
29
|
+
'sidebar-heading': depth.value === 0,
|
|
30
|
+
'active': isActive.value,
|
|
31
|
+
'collapsible': item.value.collapsible,
|
|
32
|
+
}))
|
|
33
|
+
|
|
34
|
+
const isOpen = ref(true)
|
|
35
|
+
const onClick = ref<(() => void) | undefined>(undefined)
|
|
36
|
+
|
|
37
|
+
if (item.value.collapsible) {
|
|
38
|
+
// active item is open by default
|
|
39
|
+
isOpen.value = isActive.value
|
|
40
|
+
// toggle open status on click
|
|
41
|
+
onClick.value = () => {
|
|
42
|
+
isOpen.value = !isOpen.value
|
|
43
|
+
}
|
|
44
|
+
// reset open status after navigation
|
|
45
|
+
router.afterEach(() => {
|
|
46
|
+
isOpen.value = isActive.value
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<NavLink v-if="item.link" :class="itemClass" :item="item" />
|
|
53
|
+
<p v-else :class="itemClass" @click="onClick">
|
|
54
|
+
{{ item.text }}
|
|
55
|
+
<span
|
|
56
|
+
v-if="item.collapsible"
|
|
57
|
+
class="arrow"
|
|
58
|
+
:class="isOpen ? 'down' : 'right'"
|
|
59
|
+
/>
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
<DropdownTransition v-if="item.children?.length">
|
|
63
|
+
<ul v-show="isOpen" class="sidebar-item-children">
|
|
64
|
+
<li v-for="child in item.children" :key="child.text">
|
|
65
|
+
<SidebarItem :item="child" :depth="depth + 1" />
|
|
66
|
+
</li>
|
|
67
|
+
</ul>
|
|
68
|
+
</DropdownTransition>
|
|
69
|
+
</template>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useSidebarItems } from '../composables'
|
|
3
|
+
import SidebarItem from './SidebarItem.vue'
|
|
4
|
+
|
|
5
|
+
const sidebarItems = useSidebarItems()
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<template>
|
|
9
|
+
<ul v-if="sidebarItems.length" class="sidebar-items">
|
|
10
|
+
<SidebarItem
|
|
11
|
+
v-for="item in sidebarItems"
|
|
12
|
+
:key="item.link || item.text"
|
|
13
|
+
:item="item"
|
|
14
|
+
/>
|
|
15
|
+
</ul>
|
|
16
|
+
</template>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@import '_variables';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
@mixin content_wrapper {
|
|
4
4
|
max-width: var(--content-width);
|
|
5
5
|
margin: 0 auto;
|
|
6
6
|
padding: 2rem 2.5rem;
|
|
@@ -13,3 +13,8 @@
|
|
|
13
13
|
padding: 1.5rem;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
@mixin dropdown_wrapper {
|
|
18
|
+
transition: height 0.1s ease-out;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
}
|
|
@@ -125,7 +125,7 @@ pre[class*='language-'] {
|
|
|
125
125
|
pre,
|
|
126
126
|
pre[class*='language-'] {
|
|
127
127
|
line-height: 1.4;
|
|
128
|
-
padding: 1.
|
|
128
|
+
padding: 1.3rem 1.5rem;
|
|
129
129
|
margin: 0.85rem 0;
|
|
130
130
|
border-radius: 6px;
|
|
131
131
|
overflow: auto;
|
|
@@ -228,6 +228,7 @@ div[class*='language-'] {
|
|
|
228
228
|
z-index: 3;
|
|
229
229
|
user-select: none;
|
|
230
230
|
font-size: 0.85em;
|
|
231
|
+
line-height: 0;
|
|
231
232
|
}
|
|
232
233
|
}
|
|
233
234
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@import '_mixins';
|
|
1
2
|
@import '_variables';
|
|
2
3
|
|
|
3
4
|
.dropdown-wrapper {
|
|
@@ -124,8 +125,7 @@
|
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
.nav-dropdown {
|
|
127
|
-
|
|
128
|
-
overflow: hidden;
|
|
128
|
+
@include dropdown_wrapper;
|
|
129
129
|
|
|
130
130
|
.dropdown-item {
|
|
131
131
|
.dropdown-subtitle {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
@import '_mixins';
|
|
1
2
|
@import '_variables';
|
|
2
|
-
@import '_wrapper';
|
|
3
3
|
|
|
4
4
|
.page {
|
|
5
5
|
padding-top: var(--navbar-height);
|
|
@@ -142,7 +142,7 @@ h6 {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
.theme-default-content:not(.custom) {
|
|
145
|
-
@
|
|
145
|
+
@include content_wrapper;
|
|
146
146
|
|
|
147
147
|
padding-top: 0;
|
|
148
148
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
@import '_mixins';
|
|
1
2
|
@import '_variables';
|
|
2
|
-
@import '_wrapper';
|
|
3
3
|
|
|
4
4
|
.page {
|
|
5
5
|
padding-bottom: 2rem;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
.page-meta {
|
|
10
|
-
@
|
|
10
|
+
@include content_wrapper;
|
|
11
11
|
padding-top: 1rem;
|
|
12
12
|
padding-bottom: 1rem;
|
|
13
13
|
overflow: auto;
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
.page-nav {
|
|
54
|
-
@
|
|
54
|
+
@include content_wrapper;
|
|
55
55
|
padding-top: 1rem;
|
|
56
56
|
padding-bottom: 0;
|
|
57
57
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@import '_mixins';
|
|
1
2
|
@import '_variables';
|
|
2
3
|
|
|
3
4
|
.sidebar {
|
|
@@ -29,17 +30,8 @@
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
.sidebar-
|
|
33
|
+
.sidebar-items {
|
|
33
34
|
padding: 1.5rem 0;
|
|
34
|
-
|
|
35
|
-
> li:not(:first-child) {
|
|
36
|
-
margin-top: 0.75rem;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.sidebar-sub-items {
|
|
40
|
-
padding-left: 1rem;
|
|
41
|
-
font-size: 0.95em;
|
|
42
|
-
}
|
|
43
35
|
}
|
|
44
36
|
}
|
|
45
37
|
|
|
@@ -56,53 +48,74 @@
|
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
50
|
|
|
59
|
-
.sidebar-
|
|
51
|
+
.sidebar-items {
|
|
60
52
|
padding: 1rem 0;
|
|
61
53
|
}
|
|
62
54
|
}
|
|
63
55
|
}
|
|
64
56
|
|
|
65
|
-
.sidebar-
|
|
66
|
-
|
|
67
|
-
transition: color 0.15s ease;
|
|
68
|
-
font-size: 1.1em;
|
|
69
|
-
font-weight: bold;
|
|
70
|
-
padding: 0.35rem 1.5rem 0.35rem 1.25rem;
|
|
71
|
-
width: 100%;
|
|
72
|
-
box-sizing: border-box;
|
|
73
|
-
margin: 0;
|
|
74
|
-
border-left: 0.25rem solid transparent;
|
|
75
|
-
|
|
76
|
-
.arrow {
|
|
77
|
-
position: relative;
|
|
78
|
-
top: -0.12em;
|
|
79
|
-
left: 0.5em;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
57
|
+
.sidebar-item {
|
|
58
|
+
cursor: default;
|
|
82
59
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
60
|
+
&.sidebar-heading {
|
|
61
|
+
color: var(--c-text);
|
|
62
|
+
transition: color 0.15s ease;
|
|
63
|
+
font-size: 1.1em;
|
|
64
|
+
font-weight: bold;
|
|
65
|
+
padding: 0.35rem 1.5rem 0.35rem 1.25rem;
|
|
66
|
+
width: 100%;
|
|
67
|
+
box-sizing: border-box;
|
|
68
|
+
margin: 0;
|
|
69
|
+
border-left: 0.25rem solid transparent;
|
|
70
|
+
|
|
71
|
+
&.collapsible {
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
|
|
74
|
+
& + .sidebar-item-children {
|
|
75
|
+
@include dropdown_wrapper;
|
|
76
|
+
margin-bottom: 0.75rem;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
98
79
|
|
|
99
|
-
|
|
100
|
-
|
|
80
|
+
.arrow {
|
|
81
|
+
position: relative;
|
|
82
|
+
top: -0.12em;
|
|
83
|
+
left: 0.5em;
|
|
84
|
+
}
|
|
101
85
|
}
|
|
102
|
-
}
|
|
103
86
|
|
|
104
|
-
.sidebar-
|
|
105
|
-
|
|
87
|
+
&:not(.sidebar-heading) {
|
|
88
|
+
font-size: 1em;
|
|
89
|
+
font-weight: 400;
|
|
90
|
+
display: inline-block;
|
|
91
|
+
color: var(--c-text);
|
|
92
|
+
border-left: 0.25rem solid transparent;
|
|
93
|
+
margin: 0;
|
|
94
|
+
padding: 0.35rem 1rem 0.35rem 2rem;
|
|
95
|
+
line-height: 1.4;
|
|
96
|
+
width: 100%;
|
|
97
|
+
box-sizing: border-box;
|
|
98
|
+
|
|
99
|
+
&.active {
|
|
100
|
+
font-weight: 600;
|
|
101
|
+
color: var(--c-text-accent);
|
|
102
|
+
border-left-color: var(--c-text-accent);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
& + .sidebar-item-children {
|
|
106
|
+
padding-left: 1rem;
|
|
107
|
+
font-size: 0.95em;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.sidebar-item-children .sidebar-item-children & {
|
|
111
|
+
padding: 0.25rem 1rem 0.25rem 1.75rem;
|
|
112
|
+
|
|
113
|
+
&.active {
|
|
114
|
+
font-weight: 500;
|
|
115
|
+
border-left-color: transparent;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
a.sidebar-item {
|
|
@@ -111,20 +124,4 @@ a.sidebar-item {
|
|
|
111
124
|
&:hover {
|
|
112
125
|
color: var(--c-text-accent);
|
|
113
126
|
}
|
|
114
|
-
|
|
115
|
-
&.active {
|
|
116
|
-
font-weight: 600;
|
|
117
|
-
color: var(--c-text-accent);
|
|
118
|
-
border-left-color: var(--c-text-accent);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
&.sidebar-heading.active {
|
|
122
|
-
font-weight: bold;
|
|
123
|
-
border-left-color: transparent;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.sidebar-sub-items &.active {
|
|
127
|
-
font-weight: 500;
|
|
128
|
-
border-left-color: transparent;
|
|
129
|
-
}
|
|
130
127
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const normalizePath = (path) => decodeURI(path)
|
|
2
|
+
.replace(/#.*$/, '')
|
|
3
|
+
.replace(/(index)?\.(md|html)$/, '');
|
|
4
|
+
const isActiveLink = (link, route) => {
|
|
5
|
+
if (route.hash === link) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
const currentPath = normalizePath(route.path);
|
|
9
|
+
const targetPath = normalizePath(link);
|
|
10
|
+
return currentPath === targetPath;
|
|
11
|
+
};
|
|
12
|
+
export const isActiveSidebarItem = (item, route) => {
|
|
13
|
+
if (item.link && isActiveLink(item.link, route)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (item.children) {
|
|
17
|
+
return item.children.some((child) => isActiveSidebarItem(child, route));
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
package/lib/shared/nav.d.ts
CHANGED
|
@@ -30,8 +30,14 @@ export declare type ResolvedNavbarItem = NavbarItem | NavGroup<ResolvedNavbarIte
|
|
|
30
30
|
/**
|
|
31
31
|
* Sidebar types
|
|
32
32
|
*/
|
|
33
|
-
export declare type SidebarItem = NavItem & Partial<NavLink
|
|
34
|
-
export declare type
|
|
33
|
+
export declare type SidebarItem = NavItem & Partial<NavLink>;
|
|
34
|
+
export declare type SidebarGroup = SidebarItem & NavGroup<SidebarItem | SidebarGroup | string>;
|
|
35
|
+
export declare type SidebarGroupCollapsible = SidebarGroup & {
|
|
36
|
+
collapsible?: boolean;
|
|
37
|
+
};
|
|
38
|
+
export declare type SidebarConfigArray = (SidebarItem | SidebarGroupCollapsible | string)[];
|
|
35
39
|
export declare type SidebarConfigObject = Record<string, SidebarConfigArray>;
|
|
36
40
|
export declare type SidebarConfig = SidebarConfigArray | SidebarConfigObject;
|
|
37
|
-
export declare type ResolvedSidebarItem =
|
|
41
|
+
export declare type ResolvedSidebarItem = SidebarItem & Partial<NavGroup<ResolvedSidebarItem>> & {
|
|
42
|
+
collapsible?: boolean;
|
|
43
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/theme-default",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.31",
|
|
4
4
|
"description": "Default theme of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-theme",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "e7c89264b0f0acb20e477ad1eda89e0f70057014"
|
|
56
56
|
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { h } from 'vue';
|
|
2
|
-
import { useRoute } from 'vue-router';
|
|
3
|
-
import NavLink from './NavLink.vue';
|
|
4
|
-
const normalizePath = (path) => decodeURI(path)
|
|
5
|
-
.replace(/#.*$/, '')
|
|
6
|
-
.replace(/(index)?\.(md|html)$/, '');
|
|
7
|
-
const isActiveLink = (route, link) => {
|
|
8
|
-
if (link === undefined) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
if (route.hash === link) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
const currentPath = normalizePath(route.path);
|
|
15
|
-
const targetPath = normalizePath(link);
|
|
16
|
-
return currentPath === targetPath;
|
|
17
|
-
};
|
|
18
|
-
const isActiveItem = (route, item) => {
|
|
19
|
-
if (isActiveLink(route, item.link)) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
if (item.children) {
|
|
23
|
-
return item.children.some((child) => isActiveItem(route, child));
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
};
|
|
27
|
-
const renderItem = (item, props) => {
|
|
28
|
-
// if the item has link, render it as `<NavLink>`
|
|
29
|
-
if (item.link) {
|
|
30
|
-
return h(NavLink, {
|
|
31
|
-
...props,
|
|
32
|
-
item,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
// if the item only has text, render it as `<p>`
|
|
36
|
-
return h('p', props, item.text);
|
|
37
|
-
};
|
|
38
|
-
const renderChildren = (item, depth) => {
|
|
39
|
-
var _a;
|
|
40
|
-
if (!((_a = item.children) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
return h('ul', {
|
|
44
|
-
class: {
|
|
45
|
-
'sidebar-sub-items': depth > 0,
|
|
46
|
-
},
|
|
47
|
-
}, item.children.map((child) => h('li', h(SidebarChild, {
|
|
48
|
-
item: child,
|
|
49
|
-
depth: depth + 1,
|
|
50
|
-
}))));
|
|
51
|
-
};
|
|
52
|
-
export const SidebarChild = ({ item, depth = 0 }) => {
|
|
53
|
-
const route = useRoute();
|
|
54
|
-
const active = isActiveItem(route, item);
|
|
55
|
-
return [
|
|
56
|
-
renderItem(item, {
|
|
57
|
-
class: {
|
|
58
|
-
'sidebar-heading': depth === 0,
|
|
59
|
-
'sidebar-item': true,
|
|
60
|
-
active,
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
renderChildren(item, depth),
|
|
64
|
-
];
|
|
65
|
-
};
|
|
66
|
-
SidebarChild.displayName = 'SidebarChild';
|
|
67
|
-
SidebarChild.props = {
|
|
68
|
-
item: {
|
|
69
|
-
type: Object,
|
|
70
|
-
required: true,
|
|
71
|
-
},
|
|
72
|
-
depth: {
|
|
73
|
-
type: Number,
|
|
74
|
-
required: false,
|
|
75
|
-
},
|
|
76
|
-
};
|