Skip to content

Commit b1bb0df

Browse files
committed
fix: overview clicks preview slider
1 parent 80c8d42 commit b1bb0df

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

packages/client/composables/useClicks.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ClicksContext, NormalizedRangeClickValue, NormalizedSingleClickValue, RawAtValue, RawSingleAtValue, SlideRoute } from '@slidev/types'
22
import type { MaybeRefOrGetter, Ref } from 'vue'
33
import { clamp, sum } from '@antfu/utils'
4-
import { computed, isReadonly, onMounted, onUnmounted, ref, shallowReactive, toValue } from 'vue'
4+
import { computed, isReadonly, onMounted, onUnmounted, ref, shallowReactive, toValue, watch } from 'vue'
55

66
export function normalizeSingleAtValue(at: RawSingleAtValue): NormalizedSingleClickValue {
77
if (at === false || at === 'false')
@@ -164,8 +164,12 @@ export function createFixedClicks(
164164
currentInit: MaybeRefOrGetter<number> = 0,
165165
): ClicksContext {
166166
const clicksStart = route?.meta.slide?.frontmatter.clicksStart ?? 0
167+
const clicks = ref(Math.max(toValue(currentInit), clicksStart))
168+
watch(() => toValue(currentInit), (v) => {
169+
clicks.value = Math.max(v, clicksStart)
170+
})
167171
return createClicksContextBase(
168-
computed(() => Math.max(toValue(currentInit), clicksStart)),
172+
clicks,
169173
clicksStart,
170174
route?.meta?.clicks,
171175
)

packages/client/internals/NoteDisplay.vue

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ const emit = defineEmits<{
2323
(type: 'markerClick', e: MouseEvent, clicks: number): void
2424
}>()
2525
26-
const withClicks = computed(() => props.clicksContext != null && props.noteHtml?.includes('slidev-note-click-mark'))
27-
const noteDisplay = ref<HTMLElement | null>(null)
28-
2926
const CLASS_FADE = 'slidev-note-fade'
3027
const CLASS_MARKER = 'slidev-note-click-mark'
3128
29+
const withClicks = computed(() => props.clicksContext != null && props.noteHtml?.includes(CLASS_MARKER))
30+
const noteDisplay = ref<HTMLElement | null>(null)
31+
3232
function processNote() {
3333
if (!noteDisplay.value || !withClicks.value)
3434
return
@@ -100,21 +100,21 @@ function processNote() {
100100
marker.classList.toggle(`${CLASS_MARKER}-active`, enabled && clicks === current)
101101
marker.classList.toggle(`${CLASS_MARKER}-next`, enabled && clicks === current + 1)
102102
marker.classList.toggle(`${CLASS_MARKER}-future`, enabled && clicks > current + 1)
103-
marker.ondblclick = enabled
104-
? (e) => {
105-
emit('markerDblclick', e, clicks)
106-
if (e.defaultPrevented)
107-
return
108-
props.clicksContext!.current = clicks
109-
e.stopPropagation()
110-
e.stopImmediatePropagation()
111-
}
112-
: null
113-
marker.onclick = enabled
114-
? (e) => {
115-
emit('markerClick', e, clicks)
116-
}
117-
: null
103+
marker.ondblclick = (e) => {
104+
if (!enabled)
105+
return
106+
emit('markerDblclick', e, clicks)
107+
if (e.defaultPrevented)
108+
return
109+
props.clicksContext!.current = clicks
110+
e.stopPropagation()
111+
e.stopImmediatePropagation()
112+
}
113+
marker.onclick = (e) => {
114+
if (enabled) {
115+
emit('markerClick', e, clicks)
116+
}
117+
}
118118
119119
if (enabled && props.autoScroll && clicks === current)
120120
marker.scrollIntoView({ block: 'center', behavior: 'smooth' })

0 commit comments

Comments
 (0)