File tree Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<component
3
3
:is =" component"
4
+ v-intersect =" href ? onIntersect : undefined"
4
5
:class =" classes"
5
6
>
6
7
<router-link
22
23
<script setup>
23
24
// Utilities
24
25
import { computed } from ' vue'
26
+ import { storeToRefs } from ' pinia'
27
+
28
+ // Composables
29
+ import { useAppStore } from ' @/store/app'
25
30
26
31
const HEADING_CLASSES = {
27
32
1 : ' text-h3 text-sm-h3' ,
31
36
5 : ' text-subtitle-1 font-weight-medium' ,
32
37
}
33
38
39
+ const { activeHeaders } = storeToRefs (useAppStore ())
40
+
34
41
const props = defineProps ({
35
42
content: String ,
36
43
href: String ,
39
46
40
47
const component = computed (() => ` h${ props .level } ` )
41
48
const classes = computed (() => [' v-heading' , ' mb-2' , HEADING_CLASSES [props .level ]])
49
+
50
+ function onIntersect (isIntersecting ) {
51
+ if (isIntersecting) {
52
+ if (! activeHeaders .value .hrefs .includes (props .href )) {
53
+ activeHeaders .value .hrefs .push (props .href )
54
+ }
55
+ } else if (! isIntersecting && activeHeaders .value .hrefs .includes (props .href )) {
56
+ activeHeaders .value .hrefs .splice (activeHeaders .value .hrefs .indexOf (props .href ), 1 )
57
+ }
58
+ activeHeaders .value .temp = ! isIntersecting && ! activeHeaders .value .hrefs .length ? props .href : ' '
59
+ }
42
60
</script >
43
61
44
62
<style lang="sass">
Original file line number Diff line number Diff line change 2
2
<v-navigation-drawer
3
3
v-if =" !route.meta.fluid"
4
4
id =" app-toc"
5
- v-model =" app.toc "
5
+ v-model =" tocDrawer "
6
6
color =" background"
7
7
floating
8
8
location =" right"
29
29
>
30
30
<li
31
31
:class =" [
32
- 'ps-3 text-body-2 py-1 font-weight-regular',
32
+ 'ps-3 text-medium-emphasis text- body-2 py-1 font-weight-regular',
33
33
{
34
- 'text-primary router-link-active': route.hash === to,
35
- 'text-medium-emphasis': route.hash !== to,
34
+ 'text-primary router-link-active': activeHeaders.temp == to || activeHeaders.hrefs.includes(to),
36
35
'ps-6': level === 3,
37
36
'ps-9': level === 4,
38
37
'ps-12': level === 5,
126
125
127
126
// Composables
128
127
import { RouteLocation , Router , useRoute , useRouter } from ' vue-router'
128
+ import { storeToRefs } from ' pinia'
129
129
import { useAppStore } from ' @/store/app'
130
130
// import { useGtag } from 'vue-gtag-next'
131
131
import { useSponsorsStore } from ' @/store/sponsors'
141
141
level: number ;
142
142
}
143
143
144
- const app = useAppStore ()
144
+ const { toc : tocDrawer, activeHeaders } = storeToRefs ( useAppStore () )
145
145
146
146
function useUpdateHashOnScroll (route : RouteLocation , router : Router ) {
147
147
const scrolling = ref (false )
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ export type Category = {
12
12
13
13
export type RootState = {
14
14
apiSearch : string
15
+ activeHeaders : {
16
+ hrefs : string [ ]
17
+ temp : string
18
+ }
15
19
drawer : boolean | null
16
20
toc : boolean | null
17
21
items : NavItem [ ]
@@ -33,6 +37,10 @@ export const useAppStore = defineStore({
33
37
id : 'app' ,
34
38
state : ( ) => ( {
35
39
apiSearch : '' ,
40
+ activeHeaders : {
41
+ hrefs : [ ] ,
42
+ temp : '' ,
43
+ } ,
36
44
drawer : null ,
37
45
toc : null ,
38
46
items : Array . from ( data ) ,
You can’t perform that action at this time.
0 commit comments