Fix scrollToIndex
This commit is contained in:
parent
fa68ff76d8
commit
bf67676010
|
@ -83,19 +83,16 @@ const scrollToCurrent = (behavior: ScrollBehavior = 'smooth') => {
|
||||||
}
|
}
|
||||||
|
|
||||||
watchDebounced(currentTrack, () => scrollToCurrent(), { debounce: 100 })
|
watchDebounced(currentTrack, () => scrollToCurrent(), { debounce: 100 })
|
||||||
whenever(
|
|
||||||
() => store.state.ui.queueFocused,
|
|
||||||
async () => {
|
|
||||||
list.value?.scrollToIndex(currentIndex.value)
|
|
||||||
await nextTick()
|
|
||||||
requestAnimationFrame(() => scrollToCurrent('auto'))
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
onMounted(async () => {
|
const scrollLoop = () => {
|
||||||
await nextTick()
|
const visible = [...(list.value?.scroller.$_views.values() ?? [])].map(item => item.nr.index)
|
||||||
|
if (!visible.includes(currentIndex.value)) {
|
||||||
list.value?.scrollToIndex(currentIndex.value)
|
list.value?.scrollToIndex(currentIndex.value)
|
||||||
})
|
requestAnimationFrame(scrollLoop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(scrollLoop)
|
||||||
|
|
||||||
whenever(
|
whenever(
|
||||||
() => tracks.value.length === 0,
|
() => tracks.value.length === 0,
|
||||||
|
@ -389,6 +386,8 @@ const reorderTracks = async (from: number, to: number) => {
|
||||||
:component="QueueItem"
|
:component="QueueItem"
|
||||||
:size="50"
|
:size="50"
|
||||||
@reorder="reorderTracks"
|
@reorder="reorderTracks"
|
||||||
|
@visible="scrollToCurrent('auto')"
|
||||||
|
@hidden="scrollLoop"
|
||||||
>
|
>
|
||||||
<template #default="{ index, item, classList }">
|
<template #default="{ index, item, classList }">
|
||||||
<queue-item
|
<queue-item
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { MaybeElementRef, MaybeElement } from '@vueuse/core'
|
import { useMouse, useCurrentElement, useRafFn, useElementByPoint } from '@vueuse/core'
|
||||||
|
|
||||||
import { useMouse, useCurrentElement, useResizeObserver, useRafFn, useElementByPoint } from '@vueuse/core'
|
|
||||||
import { ref, watchEffect, reactive } from 'vue'
|
import { ref, watchEffect, reactive } from 'vue'
|
||||||
|
|
||||||
// @ts-expect-error no typings
|
// @ts-expect-error no typings
|
||||||
|
@ -11,6 +9,8 @@ import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
|
||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
(e: 'reorder', from: number, to: number): void
|
(e: 'reorder', from: number, to: number): void
|
||||||
|
(e: 'visible'): void
|
||||||
|
(e: 'hidden'): void
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
@ -133,14 +133,11 @@ watchEffect(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const el = useCurrentElement()
|
const el = useCurrentElement()
|
||||||
useResizeObserver(el as unknown as MaybeElementRef<MaybeElement>, ([entry]) => {
|
const resize = () => {
|
||||||
const height = entry.borderBoxSize?.[0]?.blockSize ?? 0
|
const element = el.value as HTMLElement
|
||||||
|
containerSize.top = element.offsetTop
|
||||||
if (height !== 0) {
|
containerSize.bottom = element.offsetHeight + containerSize.top
|
||||||
containerSize.top = (entry.target as HTMLElement).offsetTop
|
}
|
||||||
containerSize.bottom = height + containerSize.top
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
let lastDate = +new Date()
|
let lastDate = +new Date()
|
||||||
const { resume, pause } = useRafFn(() => {
|
const { resume, pause } = useRafFn(() => {
|
||||||
|
@ -156,9 +153,9 @@ const { resume, pause } = useRafFn(() => {
|
||||||
}, { immediate: false })
|
}, { immediate: false })
|
||||||
|
|
||||||
const virtualList = ref()
|
const virtualList = ref()
|
||||||
window.vl = virtualList
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
scrollToIndex: (index: number) => virtualList.value?.scrollToItem(index),
|
scrollToIndex: (index: number) => virtualList.value?.scrollToItem(index),
|
||||||
|
scroller: virtualList,
|
||||||
cleanup
|
cleanup
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -174,6 +171,9 @@ defineExpose({
|
||||||
@mousedown="onMousedown"
|
@mousedown="onMousedown"
|
||||||
@touchstart="onMousedown"
|
@touchstart="onMousedown"
|
||||||
@touchmove="onTouchmove"
|
@touchmove="onTouchmove"
|
||||||
|
@resize="resize"
|
||||||
|
@visible="emit('visible')"
|
||||||
|
@hidden="emit('hidden')"
|
||||||
>
|
>
|
||||||
<slot
|
<slot
|
||||||
:class-list="[draggedItem && hoveredIndex === index && `drop-${position}`, 'drag-item']"
|
:class-list="[draggedItem && hoveredIndex === index && `drop-${position}`, 'drag-item']"
|
||||||
|
|
|
@ -307,7 +307,7 @@
|
||||||
|
|
||||||
.virtual-list {
|
.virtual-list {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow-y: auto;
|
overflow-y: scroll;
|
||||||
padding-bottom: 2rem;
|
padding-bottom: 2rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue