vuepress-theme-uniapp-official 1.4.19 → 1.4.21
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/components/Toc-top.vue +79 -85
- package/components/Toc.vue +157 -151
- package/package.json +1 -1
package/components/Toc-top.vue
CHANGED
|
@@ -1,95 +1,89 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{{ !expand ? collapseText : expandText }}
|
|
23
|
-
<uni-icon :type="!expand ? 'bottom' : 'top'"></uni-icon>
|
|
24
|
-
</span>
|
|
25
|
-
</div>
|
|
2
|
+
<div class="table-of-contents">
|
|
3
|
+
<div
|
|
4
|
+
v-for="item in showHeaders"
|
|
5
|
+
ref="chairTocItem"
|
|
6
|
+
class="vuepress-toc-item-top"
|
|
7
|
+
:class="[`vuepress-toc-h${item.level}`]"
|
|
8
|
+
>
|
|
9
|
+
<RouterLink
|
|
10
|
+
:style="{ paddingLeft: createPaddingLeft(item.level) }"
|
|
11
|
+
:to="`#${item.slug}`"
|
|
12
|
+
:title="item.title.replace(/\\/g, '')"
|
|
13
|
+
>
|
|
14
|
+
{{ item.title.replace(/\\/g, '') }}
|
|
15
|
+
</RouterLink>
|
|
16
|
+
</div>
|
|
17
|
+
<span v-if="pageHeaders && pageHeaders.length > expandHeaderLength" class="expand-button" @click="expandClick">
|
|
18
|
+
{{ !expand ? collapseText : expandText }}
|
|
19
|
+
<uni-icon :type="!expand ? 'bottom' : 'top'"></uni-icon>
|
|
20
|
+
</span>
|
|
21
|
+
</div>
|
|
26
22
|
</template>
|
|
27
23
|
|
|
28
24
|
<script>
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
import toc from '../mixin/toc'
|
|
26
|
+
import tocConfig from '@theme-config/toc'
|
|
31
27
|
|
|
32
|
-
|
|
28
|
+
const { expandText, collapseText } = tocConfig
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
};
|
|
30
|
+
export default {
|
|
31
|
+
mixins: [toc],
|
|
32
|
+
data: () => ({
|
|
33
|
+
expand: false,
|
|
34
|
+
expandText,
|
|
35
|
+
collapseText,
|
|
36
|
+
expandHeaderLength: 10,
|
|
37
|
+
}),
|
|
38
|
+
computed: {
|
|
39
|
+
showHeaders() {
|
|
40
|
+
return this.expand ? this.pageHeaders : this.pageHeaders.slice(0, this.expandHeaderLength)
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
methods: {
|
|
44
|
+
expandClick() {
|
|
45
|
+
this.expand = !this.expand
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}
|
|
55
49
|
</script>
|
|
56
50
|
|
|
57
51
|
<style lang="stylus" scoped>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
52
|
+
$paddingLeft = 1.5rem
|
|
53
|
+
.table-of-contents
|
|
54
|
+
margin 0 auto
|
|
55
|
+
padding 2rem 2.5rem 0 2.5rem
|
|
56
|
+
@media (max-width: $MQNarrow)
|
|
57
|
+
padding 2rem 2rem 0 2rem
|
|
58
|
+
@media (max-width: $MQMobileNarrow)
|
|
59
|
+
padding 1.5rem 1.5rem 0 1.5rem
|
|
60
|
+
// border-left: 2px solid #e6e6e6
|
|
61
|
+
.expand-button
|
|
62
|
+
padding-left $paddingLeft
|
|
63
|
+
border-left 2px solid rgba(0, 0, 0, 0.08)
|
|
64
|
+
color #666
|
|
65
|
+
&:hover
|
|
66
|
+
cursor pointer
|
|
67
|
+
color $accentColor
|
|
68
|
+
.vuepress-toc-item-top
|
|
69
|
+
position relative
|
|
70
|
+
padding 0.1rem 0.6rem 0.1rem $paddingLeft
|
|
71
|
+
line-height 1.5rem
|
|
72
|
+
border-left 2px solid rgba(0, 0, 0, 0.08)
|
|
73
|
+
overflow hidden
|
|
74
|
+
a
|
|
75
|
+
// display block
|
|
76
|
+
// color $textColor
|
|
77
|
+
// width 100%
|
|
78
|
+
box-sizing border-box
|
|
79
|
+
font-size 15px
|
|
80
|
+
font-weight 400
|
|
81
|
+
text-decoration none
|
|
82
|
+
transition color 0.3s
|
|
83
|
+
overflow hidden
|
|
84
|
+
text-overflow ellipsis
|
|
85
|
+
white-space nowrap
|
|
86
|
+
/* for i in range(2, 6)
|
|
87
|
+
.vuepress-toc-h{i} a
|
|
88
|
+
padding-left 1rem * (i - 1) */
|
|
95
89
|
</style>
|
package/components/Toc.vue
CHANGED
|
@@ -1,165 +1,171 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
<Sticker ref="sticker" :class="['vuepress-toc', visible ? '' : 'table-of-contents-sticker']" v-bind="$attrs">
|
|
3
|
+
<h5>{{ onThisPage }}</h5>
|
|
4
|
+
<!-- :key="item.slug" -->
|
|
5
|
+
<div
|
|
6
|
+
v-for="(item, index) in pageHeaders"
|
|
7
|
+
ref="chairTocItem"
|
|
8
|
+
class="vuepress-toc-item"
|
|
9
|
+
:class="[`vuepress-toc-h${item.level}`, { active: activeIndex === index }]"
|
|
10
|
+
>
|
|
11
|
+
<RouterLink
|
|
12
|
+
:style="{ paddingLeft: createPaddingLeft(item.level) }"
|
|
13
|
+
:to="`#${item.slug}`"
|
|
14
|
+
:title="item.title.replace(/\\/g, '')"
|
|
15
|
+
>
|
|
16
|
+
{{ item.title.replace(/\\/g, '') }}
|
|
17
|
+
</RouterLink>
|
|
18
|
+
</div>
|
|
19
|
+
</Sticker>
|
|
12
20
|
</template>
|
|
13
21
|
|
|
14
22
|
<script>
|
|
15
|
-
import Sticker from './Sticker.vue'
|
|
16
|
-
import toc from '../mixin/toc'
|
|
17
|
-
import tocConfig from '@theme-config/toc'
|
|
23
|
+
import Sticker from './Sticker.vue'
|
|
24
|
+
import toc from '../mixin/toc'
|
|
25
|
+
import tocConfig from '@theme-config/toc'
|
|
18
26
|
|
|
19
|
-
const { onThisPage } = tocConfig
|
|
27
|
+
const { onThisPage } = tocConfig
|
|
20
28
|
|
|
21
|
-
let initTop
|
|
29
|
+
let initTop
|
|
22
30
|
// get offset top
|
|
23
31
|
function getAbsoluteTop(dom) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
document.documentElement.scrollTop
|
|
28
|
-
: 0;
|
|
32
|
+
return dom && dom.getBoundingClientRect
|
|
33
|
+
? dom.getBoundingClientRect().top + document.body.scrollTop + document.documentElement.scrollTop
|
|
34
|
+
: 0
|
|
29
35
|
}
|
|
30
36
|
export default {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
37
|
+
mixins: [toc],
|
|
38
|
+
components: {
|
|
39
|
+
Sticker,
|
|
40
|
+
},
|
|
41
|
+
data() {
|
|
42
|
+
return {
|
|
43
|
+
activeIndex: 0,
|
|
44
|
+
tocConfig,
|
|
45
|
+
onThisPage,
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
watch: {
|
|
49
|
+
activeIndex() {
|
|
50
|
+
const items = this.$refs.chairTocItem || []
|
|
51
|
+
const dom = items[this.activeIndex]
|
|
52
|
+
if (!dom) return
|
|
53
|
+
const rect = dom.getBoundingClientRect()
|
|
54
|
+
const wrapperRect = this.$el.getBoundingClientRect()
|
|
55
|
+
const top = rect.top - wrapperRect.top
|
|
56
|
+
if (top < 20) {
|
|
57
|
+
this.$el.scrollTop = this.$el.scrollTop + top - 20
|
|
58
|
+
} else if (top + rect.height > wrapperRect.height) {
|
|
59
|
+
this.$el.scrollTop += rect.top - (wrapperRect.height - rect.height)
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
$route() {},
|
|
63
|
+
},
|
|
64
|
+
mounted() {
|
|
65
|
+
// sync visible to parent component
|
|
66
|
+
const syncVisible = () => {
|
|
67
|
+
this.$emit('visible-change', this.visible)
|
|
68
|
+
}
|
|
69
|
+
syncVisible()
|
|
70
|
+
this.$watch('visible', syncVisible)
|
|
71
|
+
// binding event
|
|
72
|
+
setTimeout(() => this._onScroll(), 1000)
|
|
73
|
+
this._onScroll = () => this.onScroll()
|
|
74
|
+
this._onHashChange = () => {
|
|
75
|
+
const hash = decodeURIComponent(location.hash.substring(1))
|
|
76
|
+
const index = (this.pageHeaders || []).findIndex(h => h.slug === hash)
|
|
77
|
+
if (index >= 0) this.activeIndex = index
|
|
78
|
+
const dom = hash && document.getElementById(hash)
|
|
79
|
+
if (dom) window.scrollTo(0, getAbsoluteTop(dom) - 20)
|
|
80
|
+
}
|
|
81
|
+
window.addEventListener('scroll', this._onScroll)
|
|
82
|
+
// window.addEventListener('hashchange', this._onHashChange);
|
|
83
|
+
const sideBar = document.querySelector('.sidebar')
|
|
84
|
+
this.$refs.sticker.$el.style.top = sideBar && sideBar.style && sideBar.style.top
|
|
85
|
+
},
|
|
86
|
+
beforeDestroy() {
|
|
87
|
+
window.removeEventListener('scroll', this._onScroll)
|
|
88
|
+
window.removeEventListener('hashchange', this._onHashChange)
|
|
89
|
+
},
|
|
90
|
+
methods: {
|
|
91
|
+
onScroll() {
|
|
92
|
+
if (initTop === undefined) {
|
|
93
|
+
initTop = getAbsoluteTop(this.$el)
|
|
94
|
+
}
|
|
95
|
+
// update position
|
|
96
|
+
const scrollTop = document.body.scrollTop + document.documentElement.scrollTop
|
|
97
|
+
const headings = this.pageHeaders || []
|
|
98
|
+
// change active toc with scrolling
|
|
99
|
+
let i = 0
|
|
100
|
+
const addLink = index => {
|
|
101
|
+
this.activeIndex = index
|
|
102
|
+
}
|
|
103
|
+
for (; i < headings.length; i++) {
|
|
104
|
+
const dom = document.getElementById(headings[i].slug)
|
|
105
|
+
const top = getAbsoluteTop(dom)
|
|
106
|
+
if (top - 50 < scrollTop) {
|
|
107
|
+
addLink(i)
|
|
108
|
+
} else {
|
|
109
|
+
if (!i) addLink(i)
|
|
110
|
+
break
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
triggerEvt() {
|
|
115
|
+
this._onScroll()
|
|
116
|
+
this._onHashChange()
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
}
|
|
114
120
|
</script>
|
|
115
121
|
|
|
116
122
|
<style lang="stylus">
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
123
|
+
.table-of-contents-sticker
|
|
124
|
+
display none !important
|
|
125
|
+
.vuepress-toc
|
|
126
|
+
position fixed
|
|
127
|
+
display none
|
|
128
|
+
max-height 89vh
|
|
129
|
+
width $vuepress-toc-width
|
|
130
|
+
overflow-y hidden
|
|
131
|
+
// margin-top $navbarHeight
|
|
132
|
+
top $navbarHeight
|
|
133
|
+
right 0
|
|
134
|
+
box-sizing border-box
|
|
135
|
+
background-color #fff
|
|
136
|
+
/* background: #fff; */
|
|
137
|
+
z-index 0
|
|
138
|
+
.vuepress-toc-item
|
|
139
|
+
position relative
|
|
140
|
+
padding 0.1rem 0.6rem 0.1rem 1.5rem
|
|
141
|
+
line-height 1.5rem
|
|
142
|
+
border-left 2px solid rgba(0, 0, 0, 0.08)
|
|
143
|
+
overflow hidden
|
|
144
|
+
a
|
|
145
|
+
display block
|
|
146
|
+
color $textColor
|
|
147
|
+
width 100%
|
|
148
|
+
box-sizing border-box
|
|
149
|
+
font-size 14px
|
|
150
|
+
font-weight 400
|
|
151
|
+
text-decoration none
|
|
152
|
+
transition color 0.3s
|
|
153
|
+
overflow hidden
|
|
154
|
+
text-overflow ellipsis
|
|
155
|
+
white-space nowrap
|
|
156
|
+
&.active
|
|
157
|
+
border-left-color $accentColor
|
|
158
|
+
a
|
|
159
|
+
color $accentColor
|
|
160
|
+
&:hover
|
|
161
|
+
a
|
|
162
|
+
color $accentColor
|
|
163
|
+
.vuepress-toc-h1 a
|
|
164
|
+
.vuepress-toc-h2 a
|
|
165
|
+
font-weight bold
|
|
166
|
+
/* for i in range(2, 6)
|
|
167
|
+
.vuepress-toc-h{i} a
|
|
168
|
+
padding-left 1rem * (i - 1) */
|
|
169
|
+
.vuepress-toc:hover
|
|
170
|
+
overflow-y auto
|
|
165
171
|
</style>
|