forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoc.vue
More file actions
111 lines (108 loc) · 2.36 KB
/
toc.vue
File metadata and controls
111 lines (108 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
<template>
<div
class="side-bar-toc"
:class="[{ 'side-bar-toc-overflow': !wordWrapInToc, 'side-bar-toc-wordwrap': wordWrapInToc }]"
>
<div class="title">Table Of Contents</div>
<el-tree
v-if="toc.length"
:data="toc"
:default-expand-all="true"
:props="defaultProps"
@node-click="handleClick"
:expand-on-click-node="false"
:indent="10"
></el-tree>
<div class="no-data" v-else>
<svg aria-hidden="true" :viewBox="EmptyIcon.viewBox">
<use :xlink:href="EmptyIcon.url"></use>
</svg>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
import bus from '../../bus'
import EmptyIcon from '@/assets/icons/undraw_toc_empty.svg'
export default {
data () {
this.EmptyIcon = EmptyIcon
return {
defaultProps: {
children: 'children',
label: 'label'
}
}
},
computed: {
...mapState({
toc: state => state.editor.toc,
wordWrapInToc: state => state.preferences.wordWrapInToc
})
},
methods: {
handleClick ({ slug }) {
bus.$emit('scroll-to-header', slug)
}
}
}
</script>
<style>
.side-bar-toc {
height: calc(100% - 35px);
margin: 0;
padding: 0;
list-style: none;
display: flex;
flex-direction: column;
& .title {
color: var(--sideBarTitleColor);
font-weight: 600;
font-size: 16px;
margin: 37px 0 10px 0;
padding-left: 25px;
}
& .el-tree-node {
margin-top: 8px;
}
& .el-tree {
background: transparent;
color: var(--sideBarColor);
}
& .el-tree-node:focus > .el-tree-node__content {
background-color: var(--sideBarItemHoverBgColor);
}
& .el-tree-node__content:hover {
background: var(--sideBarItemHoverBgColor);
}
& > li {
font-size: 14px;
margin-bottom: 15px;
cursor: pointer;
}
& .no-data {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
padding-bottom: 50px;
& svg {
width: 120px;
fill: var(--themeColor);
}
}
}
.side-bar-toc-overflow {
overflow: auto;
}
.side-bar-toc-wordwrap {
overflow-x: hidden;
overflow-y: auto;
& .el-tree-node__content {
white-space: normal;
height: auto;
min-height: 26px;
}
}
</style>