1
1
<script setup lang="ts">
2
- import { computed , nextTick , onMounted , reactive , ref } from ' vue'
2
+ import { computed , nextTick , onMounted , reactive , ref , shallowRef } from ' vue'
3
3
import { useHead } from ' @unhead/vue'
4
4
import type { ClicksContext , SlideRoute } from ' @slidev/types'
5
5
import { pathPrefix , slidesTitle } from ' ../env'
@@ -28,6 +28,7 @@ const wordCounts = computed(() => slides.value.map(route => wordCount(route.meta
28
28
const totalWords = computed (() => wordCounts .value .reduce ((a , b ) => a + b , 0 ))
29
29
const totalClicks = computed (() => slides .value .map (route => getSlideClicks (route )).reduce ((a , b ) => a + b , 0 ))
30
30
31
+ const activeSlide = shallowRef <SlideRoute >()
31
32
const clicksContextMap = new WeakMap <SlideRoute , ClicksContext >()
32
33
function getClicksContext(route : SlideRoute ) {
33
34
// We create a local clicks context to calculate the total clicks of the slide
@@ -40,8 +41,15 @@ function getSlideClicks(route: SlideRoute) {
40
41
return route .meta ?.clicks || getClicksContext (route )?.total
41
42
}
42
43
44
+ function toggleRoute(route : SlideRoute ) {
45
+ if (activeSlide .value === route )
46
+ activeSlide .value = undefined
47
+ else
48
+ activeSlide .value = route
49
+ }
50
+
43
51
function wordCount(str : string ) {
44
- return str .match (/ [\w ’' -] + / g )?.length || 0
52
+ return str .match (/ [\w `' \ - ] + / g )?.length || 0
45
53
}
46
54
47
55
function isElementInViewport(el : HTMLElement ) {
@@ -185,9 +193,11 @@ onMounted(() => {
185
193
</div >
186
194
<ClicksSlider
187
195
v-if =" getSlideClicks(route)"
196
+ :active =" activeSlide === route"
188
197
:clicks-context =" getClicksContext(route)"
189
198
class =" w-full mt-2"
190
- @dblclick =" getClicksContext(route).current = CLICKS_MAX"
199
+ @dblclick =" toggleRoute(route)"
200
+ @click =" activeSlide = route"
191
201
/>
192
202
</div >
193
203
<div class =" py3 mt-0.5 mr--8 ml--4 op0 transition group-hover:op100" >
@@ -204,6 +214,7 @@ onMounted(() => {
204
214
:no =" route.no"
205
215
class =" max-w-250 w-250 text-lg rounded p3"
206
216
:auto-height =" true"
217
+ :highlight =" activeSlide === route"
207
218
:editing =" edittingNote === route.no"
208
219
:clicks-context =" getClicksContext(route)"
209
220
@dblclick =" edittingNote !== route.no ? edittingNote = route.no : null"
0 commit comments