vuepress-theme-uniapp-official 1.4.23 → 1.4.25
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 +7 -14
- package/components/Toc.vue +6 -15
- package/global-components/CodeSimulator.vue +49 -46
- package/mixin/toc.js +17 -1
- package/package.json +1 -1
package/components/Toc-top.vue
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="table-of-contents">
|
|
3
|
-
<div
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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, '') }}
|
|
3
|
+
<div v-for="item in showHeaders" ref="chairTocItem" class="vuepress-toc-item-top"
|
|
4
|
+
:class="[`vuepress-toc-h${item.level}`]">
|
|
5
|
+
<RouterLink :style="{ paddingLeft: createPaddingLeft(item.level) }" :to="`#${item.slug}`"
|
|
6
|
+
:title="item.title">
|
|
7
|
+
<span v-html="item.title"></span>
|
|
15
8
|
</RouterLink>
|
|
16
9
|
</div>
|
|
17
|
-
<span v-if="
|
|
10
|
+
<span v-if="formatTitlePageHeaders && formatTitlePageHeaders.length > expandHeaderLength" class="expand-button" @click="expandClick">
|
|
18
11
|
{{ !expand ? collapseText : expandText }}
|
|
19
12
|
<uni-icon :type="!expand ? 'bottom' : 'top'"></uni-icon>
|
|
20
13
|
</span>
|
|
@@ -37,7 +30,7 @@ export default {
|
|
|
37
30
|
}),
|
|
38
31
|
computed: {
|
|
39
32
|
showHeaders() {
|
|
40
|
-
return this.expand ? this.
|
|
33
|
+
return this.expand ? this.formatTitlePageHeaders : this.formatTitlePageHeaders.slice(0, this.expandHeaderLength)
|
|
41
34
|
},
|
|
42
35
|
},
|
|
43
36
|
methods: {
|
package/components/Toc.vue
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<Sticker ref="sticker" :class="['vuepress-toc', visible ? '' : 'table-of-contents-sticker']" v-bind="$attrs">
|
|
3
3
|
<h5>{{ onThisPage }}</h5>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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, '') }}
|
|
4
|
+
<div v-for="(item, index) in formatTitlePageHeaders" ref="chairTocItem" class="vuepress-toc-item"
|
|
5
|
+
:class="[`vuepress-toc-h${item.level}`, { active: activeIndex === index }]">
|
|
6
|
+
<RouterLink :style="{ paddingLeft: createPaddingLeft(item.level) }" :to="`#${item.slug}`"
|
|
7
|
+
:title="item.title">
|
|
8
|
+
<span v-html="item.title"></span>
|
|
17
9
|
</RouterLink>
|
|
18
10
|
</div>
|
|
19
11
|
</Sticker>
|
|
@@ -58,8 +50,7 @@ export default {
|
|
|
58
50
|
} else if (top + rect.height > wrapperRect.height) {
|
|
59
51
|
this.$el.scrollTop += rect.top - (wrapperRect.height - rect.height)
|
|
60
52
|
}
|
|
61
|
-
}
|
|
62
|
-
$route() {},
|
|
53
|
+
}
|
|
63
54
|
},
|
|
64
55
|
mounted() {
|
|
65
56
|
// sync visible to parent component
|
|
@@ -34,66 +34,71 @@ export default {
|
|
|
34
34
|
},
|
|
35
35
|
createdDom(h,node){
|
|
36
36
|
let headerDom = []
|
|
37
|
-
node.forEach((v,index)=>{
|
|
38
|
-
headerDom.push(h('p',
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
node.forEach((v, index) => {
|
|
38
|
+
headerDom.push(h('p', {
|
|
39
|
+
class: `pages-tabs-header-text ${this.activeIndex === index ? 'pages-tabs--active' : ''}`, on: {
|
|
40
|
+
click: (e) => {
|
|
41
|
+
this.onClick(index)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}, v.title),)
|
|
41
45
|
})
|
|
42
|
-
return this.renderDom(h,h('div',{class:'page-tabs'},[
|
|
43
|
-
h('div',{class:'pages-tabs-header'},headerDom),
|
|
44
|
-
h('div',{class:'page-snippet-code',key:this.activeIndex},[node[this.activeIndex].node]),
|
|
46
|
+
return this.renderDom(h, h('div', { class: 'page-tabs' }, [
|
|
47
|
+
h('div', { class: 'pages-tabs-header' }, headerDom),
|
|
48
|
+
h('div', { class: 'page-snippet-code', key: this.activeIndex }, [node[this.activeIndex].node]),
|
|
45
49
|
]))
|
|
46
50
|
},
|
|
47
51
|
renderDom(h,node){
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
return h('div', { class: 'page-runtime' }, [
|
|
53
|
+
h('div', { class: 'page-snippet' , style: { height: this.src ? '667px' : 'auto' }}, [node]),
|
|
54
|
+
h('div', { class: 'code-content', style: { display: this.src ? 'block' : 'none' } }, [
|
|
55
|
+
h('iframe', {
|
|
56
|
+
class: 'code-iframe',
|
|
57
|
+
attrs: {
|
|
58
|
+
src: this.src,
|
|
59
|
+
frameborder: '0',
|
|
60
|
+
allow: 'geolocation https://hellouniappx.dcloud.net.cn',
|
|
61
|
+
},
|
|
62
|
+
ref: 'codeIframe',
|
|
63
|
+
}),
|
|
64
|
+
]),
|
|
65
|
+
])
|
|
61
66
|
}
|
|
62
67
|
},
|
|
63
68
|
render(h){
|
|
64
69
|
const columns = this.$slots.default || []
|
|
65
70
|
let boxObj = []
|
|
66
71
|
let realDom = []
|
|
67
|
-
columns.forEach((v,i)=>{
|
|
68
|
-
if(v.tag && v.children){
|
|
72
|
+
columns.forEach((v, i) => {
|
|
73
|
+
if (v.tag && v.children) {
|
|
69
74
|
realDom.push(v)
|
|
70
75
|
}
|
|
71
76
|
})
|
|
72
|
-
realDom.forEach((vnode,index)=>{
|
|
77
|
+
realDom.forEach((vnode, index) => {
|
|
73
78
|
let code = vnode.children[0]
|
|
74
|
-
if(vnode.tag === 'div' && code.tag === 'pre'){
|
|
79
|
+
if (vnode.tag === 'div' && code.tag === 'pre') {
|
|
75
80
|
let i = index - 1
|
|
76
|
-
if(i >= 0){
|
|
81
|
+
if (i >= 0) {
|
|
77
82
|
let textDom = realDom[i]
|
|
78
|
-
if(textDom.tag === 'blockquote'){
|
|
83
|
+
if (textDom.tag === 'blockquote') {
|
|
79
84
|
let text = textDom.children[0]
|
|
80
85
|
let p = text.children[0]
|
|
81
86
|
boxObj.push({
|
|
82
|
-
title:p.text,
|
|
83
|
-
node:vnode
|
|
87
|
+
title: p.text ? p.text : 'title',
|
|
88
|
+
node: vnode
|
|
84
89
|
})
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
94
|
})
|
|
90
|
-
if(boxObj.length > 0){
|
|
91
|
-
return h('div',null,[this.createdDom(h,boxObj)])
|
|
92
|
-
}else{
|
|
93
|
-
if(this.src){
|
|
94
|
-
return this.renderDom(h,this.$slots.default)
|
|
95
|
-
}else{
|
|
96
|
-
return h('div',null,this.$slots.default)
|
|
95
|
+
if (boxObj.length > 0) {
|
|
96
|
+
return h('div', null, [this.createdDom(h, boxObj)])
|
|
97
|
+
} else {
|
|
98
|
+
if (this.src) {
|
|
99
|
+
return this.renderDom(h, this.$slots.default)
|
|
100
|
+
} else {
|
|
101
|
+
return h('div', null, this.$slots.default)
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
104
|
}
|
|
@@ -123,17 +128,12 @@ export default {
|
|
|
123
128
|
display: flex;
|
|
124
129
|
height: 44px;
|
|
125
130
|
background-color: #222;
|
|
131
|
+
align-items: center;
|
|
126
132
|
}
|
|
127
133
|
.pages-tabs-header-text {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
margin: 5px;
|
|
132
|
-
margin-bottom: 0px;
|
|
133
|
-
border-top-left-radius: 5px;
|
|
134
|
-
border-top-right-radius: 5px;
|
|
135
|
-
padding: 0 45px;
|
|
136
|
-
text-align: center;
|
|
134
|
+
margin: 0 0 0 8px;
|
|
135
|
+
padding: 4px 8px;
|
|
136
|
+
border-radius: 5px;
|
|
137
137
|
font-size: 16px;
|
|
138
138
|
color: #eee;
|
|
139
139
|
background:transparent;
|
|
@@ -144,11 +144,14 @@ export default {
|
|
|
144
144
|
-khtml-user-select:none; /*早期浏览器*/
|
|
145
145
|
user-select:none;
|
|
146
146
|
}
|
|
147
|
+
.pages-tabs-header-text:hover {
|
|
148
|
+
background: #454545;
|
|
149
|
+
}
|
|
147
150
|
.pages-tabs--active {
|
|
148
151
|
// background:#282c34;
|
|
149
|
-
background-color: #
|
|
152
|
+
background-color: #3b3b3b;
|
|
150
153
|
color: #fff;
|
|
151
|
-
font-weight: bold;
|
|
154
|
+
// font-weight: bold;
|
|
152
155
|
}
|
|
153
156
|
|
|
154
157
|
.page-snippet div[class*="language-"]{
|
package/mixin/toc.js
CHANGED
|
@@ -13,8 +13,24 @@ export default {
|
|
|
13
13
|
!!(this.$page && this.$page.headers && this.$page.headers.length)
|
|
14
14
|
);
|
|
15
15
|
},
|
|
16
|
+
formatTitlePageHeaders() {
|
|
17
|
+
return (this.pageHeaders || []).map(item => {
|
|
18
|
+
return {
|
|
19
|
+
...item,
|
|
20
|
+
title: this.simpleMd2html(item.title)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
16
24
|
},
|
|
17
25
|
methods: {
|
|
26
|
+
simpleMd2html(md) {
|
|
27
|
+
md = md
|
|
28
|
+
.replace(/\\/g, '')
|
|
29
|
+
.replace(/</g, '<')
|
|
30
|
+
.replace(/>/g, '>')
|
|
31
|
+
.replace(/([\s\S]*)~~([\S\s]+)~~([\s\S]*)/g, '$1<del>$2</del>$3')
|
|
32
|
+
return md
|
|
33
|
+
},
|
|
18
34
|
createPaddingLeft(level) {
|
|
19
35
|
return level - this.paddingLeftOffset + 'rem';
|
|
20
36
|
},
|
|
@@ -33,4 +49,4 @@ export default {
|
|
|
33
49
|
}
|
|
34
50
|
}
|
|
35
51
|
}
|
|
36
|
-
}
|
|
52
|
+
}
|