mirror of
https://github.com/logseq/logseq.git
synced 2026-05-27 06:04:23 +00:00
fix offset issue
This commit is contained in:
@@ -38,5 +38,5 @@
|
||||
[:div.absolute.w-full.h-full
|
||||
;; makes sure the whiteboard will not cover the borders
|
||||
{:key name
|
||||
:style {:padding "0.5px"}}
|
||||
:style {:padding "0.5px" :z-index 0}}
|
||||
(tldraw-app {:file tldr-name})]))
|
||||
|
||||
@@ -35,6 +35,15 @@ export function throttle<T extends (...args: any) => any>(
|
||||
}
|
||||
}
|
||||
|
||||
export function debounce<T extends (...args: any[]) => void>(fn: T, ms = 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let timeoutId: number | any
|
||||
return function (...args: Parameters<T>) {
|
||||
clearTimeout(timeoutId)
|
||||
timeoutId = setTimeout(() => fn.apply(args), ms)
|
||||
}
|
||||
}
|
||||
|
||||
/** Linear interpolate between two values. */
|
||||
export function lerp(a: number, b: number, t: number) {
|
||||
return a + (b - a) * t
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as React from 'react'
|
||||
import type { TLViewport, TLBounds } from '@tldraw/core'
|
||||
import { TLViewport, TLBounds, debounce } from '@tldraw/core'
|
||||
|
||||
const getNearestScrollableContainer = (element: HTMLElement): HTMLElement | Document => {
|
||||
let parent = element.parentElement
|
||||
@@ -54,11 +54,12 @@ export function useResizeObserver<T extends HTMLElement>(
|
||||
|
||||
React.useEffect(() => {
|
||||
const scrollingAnchor = ref.current ? getNearestScrollableContainer(ref.current) : document
|
||||
scrollingAnchor.addEventListener('scroll', updateBounds)
|
||||
scrollingAnchor.addEventListener('resize', updateBounds)
|
||||
const debouncedupdateBounds = debounce(updateBounds, 100)
|
||||
scrollingAnchor.addEventListener('scroll', debouncedupdateBounds)
|
||||
scrollingAnchor.addEventListener('resize', debouncedupdateBounds)
|
||||
return () => {
|
||||
scrollingAnchor.removeEventListener('scroll', updateBounds)
|
||||
scrollingAnchor.removeEventListener('resize', updateBounds)
|
||||
scrollingAnchor.removeEventListener('scroll', debouncedupdateBounds)
|
||||
scrollingAnchor.removeEventListener('resize', debouncedupdateBounds)
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user