Files
remanso/src/hooks/useOverlay.hook.ts
Julien Calixte 84803c45dd refactor(scroll): clean up debug overlay and pass anchor by param
Removes the temporary on-screen scroll diagnosis panel and the global
window.__scrollAtClick stash. The anchor scrollTop is now captured
synchronously at addStackedNote entry and threaded through
scrollToFocusedNote and scrollToNoteElement to scrollToElement, so no
state survives across calls — nothing to reset on repo or page change.
2026-05-04 23:02:12 +02:00

62 lines
1.4 KiB
TypeScript

import { useEventListener, useWindowSize } from "@vueuse/core"
import { computed, ref } from "vue"
import { MOBILE_BREAKPOINT } from "@/constants/mobile"
export const useOverlay = (listen = true) => {
const x = ref(0)
const y = ref(0)
const { width } = useWindowSize()
const isMobile = computed(() => width.value <= MOBILE_BREAKPOINT)
if (listen) {
const updateScroll = () => {
const mainApp = document.getElementById("main-app")
x.value = mainApp?.scrollLeft ?? 0
y.value = mainApp?.scrollTop ?? 0
}
useEventListener(
() => document.getElementById("main-app"),
"scroll",
updateScroll,
{ passive: true }
)
}
const scrollToNote = (to: number) => {
const go = () => {
const mainApp = document.getElementById("main-app")
if (!mainApp) return
if (isMobile.value) {
mainApp.scrollTo({ top: to, behavior: "smooth" })
} else {
mainApp.scrollTo({ left: to, behavior: "smooth" })
}
}
setTimeout(() => {
go()
}, 80)
}
const scrollToElement = (element: HTMLElement, anchorTop?: number) => {
const mainApp = document.getElementById("main-app")
if (mainApp && anchorTop !== undefined) {
mainApp.scrollTop = anchorTop
}
requestAnimationFrame(() => {
element.scrollIntoView({ behavior: "smooth", block: "start" })
})
}
return {
x,
y,
isMobile,
scrollToNote,
scrollToElement
}
}