Preserve scroll across required library refreshes
This commit is contained in:
@@ -49,3 +49,21 @@ export function cardIntentInsertionIndex(items, draggedId, targetId) {
|
||||
export function materializationNeedsLibraryRefresh(payload) {
|
||||
return Array.isArray(payload?.moved) && payload.moved.length > 0
|
||||
}
|
||||
|
||||
export function libraryRefreshScrollRestore(
|
||||
view,
|
||||
savedScrollTop,
|
||||
liveScrollTop,
|
||||
clientWidth,
|
||||
clientHeight
|
||||
) {
|
||||
const normalizedView = String(view ?? '')
|
||||
if (!normalizedView) return null
|
||||
const visible = Number(clientWidth) > 0 && Number(clientHeight) > 0
|
||||
const live = Number(liveScrollTop)
|
||||
const saved = Number(savedScrollTop)
|
||||
const scrollTop = visible && Number.isFinite(live)
|
||||
? live
|
||||
: (Number.isFinite(saved) ? saved : 0)
|
||||
return { view: normalizedView, scrollTop: Math.max(0, scrollTop) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user