cogsbox-state 0.5.419 → 0.5.421
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CogsState.jsx +265 -259
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +33 -16
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1822,8 +1822,9 @@ function createProxyHandler<T>(
|
|
|
1822
1822
|
});
|
|
1823
1823
|
const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
|
|
1824
1824
|
const wasAtBottomRef = useRef(true);
|
|
1825
|
-
const previousCountRef = useRef(0);
|
|
1826
1825
|
const userHasScrolledAwayRef = useRef(false);
|
|
1826
|
+
const previousCountRef = useRef(0);
|
|
1827
|
+
|
|
1827
1828
|
// Subscribe to shadow state updates
|
|
1828
1829
|
useEffect(() => {
|
|
1829
1830
|
const unsubscribe = getGlobalStore
|
|
@@ -1909,8 +1910,12 @@ function createProxyHandler<T>(
|
|
|
1909
1910
|
const isInitialLoad =
|
|
1910
1911
|
previousCountRef.current === 0 && totalCount > 0;
|
|
1911
1912
|
|
|
1912
|
-
|
|
1913
|
-
|
|
1913
|
+
// Only auto-scroll if user hasn't scrolled away
|
|
1914
|
+
if (
|
|
1915
|
+
(hasNewItems || isInitialLoad) &&
|
|
1916
|
+
wasAtBottomRef.current &&
|
|
1917
|
+
!userHasScrolledAwayRef.current
|
|
1918
|
+
) {
|
|
1914
1919
|
const visibleCount = Math.ceil(
|
|
1915
1920
|
(containerRef.current?.clientHeight || 0) / itemHeight
|
|
1916
1921
|
);
|
|
@@ -1930,10 +1935,12 @@ function createProxyHandler<T>(
|
|
|
1930
1935
|
containerRef.current.scrollHeight;
|
|
1931
1936
|
}
|
|
1932
1937
|
}, 50);
|
|
1938
|
+
|
|
1939
|
+
return () => clearTimeout(timeoutId);
|
|
1933
1940
|
}
|
|
1934
1941
|
|
|
1935
1942
|
previousCountRef.current = totalCount;
|
|
1936
|
-
}, [totalCount]);
|
|
1943
|
+
}, [totalCount, itemHeight, overscan]);
|
|
1937
1944
|
|
|
1938
1945
|
// Handle scroll events
|
|
1939
1946
|
useEffect(() => {
|
|
@@ -1945,17 +1952,16 @@ function createProxyHandler<T>(
|
|
|
1945
1952
|
const distanceFromBottom =
|
|
1946
1953
|
scrollHeight - scrollTop - clientHeight;
|
|
1947
1954
|
|
|
1948
|
-
// Track if
|
|
1949
|
-
|
|
1950
|
-
wasAtBottomRef.current = isAtBottom;
|
|
1955
|
+
// Track if we're at bottom
|
|
1956
|
+
wasAtBottomRef.current = distanceFromBottom < 5;
|
|
1951
1957
|
|
|
1952
|
-
// If user scrolls away from bottom, set
|
|
1953
|
-
if (
|
|
1958
|
+
// If user scrolls away from bottom past threshold, set flag
|
|
1959
|
+
if (distanceFromBottom > 100) {
|
|
1954
1960
|
userHasScrolledAwayRef.current = true;
|
|
1955
1961
|
}
|
|
1956
1962
|
|
|
1957
|
-
// If user scrolls back to bottom, clear
|
|
1958
|
-
if (
|
|
1963
|
+
// If user scrolls back to bottom, clear flag
|
|
1964
|
+
if (distanceFromBottom < 5) {
|
|
1959
1965
|
userHasScrolledAwayRef.current = false;
|
|
1960
1966
|
}
|
|
1961
1967
|
|
|
@@ -1982,15 +1988,25 @@ function createProxyHandler<T>(
|
|
|
1982
1988
|
endIndex: Math.min(totalCount, endIndex + 1 + overscan),
|
|
1983
1989
|
});
|
|
1984
1990
|
};
|
|
1991
|
+
|
|
1985
1992
|
container.addEventListener("scroll", handleScroll, {
|
|
1986
1993
|
passive: true,
|
|
1987
1994
|
});
|
|
1988
1995
|
|
|
1989
|
-
//
|
|
1990
|
-
if (
|
|
1991
|
-
|
|
1992
|
-
|
|
1996
|
+
// Only auto-scroll on initial load when user hasn't scrolled away
|
|
1997
|
+
if (
|
|
1998
|
+
stickToBottom &&
|
|
1999
|
+
totalCount > 0 &&
|
|
2000
|
+
!userHasScrolledAwayRef.current
|
|
2001
|
+
) {
|
|
2002
|
+
const { scrollTop } = container;
|
|
2003
|
+
// Only if we're at the very top (initial load)
|
|
2004
|
+
if (scrollTop === 0) {
|
|
2005
|
+
container.scrollTop = container.scrollHeight;
|
|
2006
|
+
wasAtBottomRef.current = true;
|
|
2007
|
+
}
|
|
1993
2008
|
}
|
|
2009
|
+
|
|
1994
2010
|
handleScroll();
|
|
1995
2011
|
|
|
1996
2012
|
return () => {
|
|
@@ -2000,6 +2016,7 @@ function createProxyHandler<T>(
|
|
|
2000
2016
|
|
|
2001
2017
|
const scrollToBottom = useCallback(() => {
|
|
2002
2018
|
wasAtBottomRef.current = true;
|
|
2019
|
+
userHasScrolledAwayRef.current = false;
|
|
2003
2020
|
const scrolled = scrollToLastItem();
|
|
2004
2021
|
if (!scrolled && containerRef.current) {
|
|
2005
2022
|
containerRef.current.scrollTop =
|
|
@@ -2018,7 +2035,7 @@ function createProxyHandler<T>(
|
|
|
2018
2035
|
if (itemData?.virtualizer?.domRef) {
|
|
2019
2036
|
const element = itemData.virtualizer.domRef;
|
|
2020
2037
|
if (element && element.scrollIntoView) {
|
|
2021
|
-
element.scrollIntoView({ behavior, block: "
|
|
2038
|
+
element.scrollIntoView({ behavior, block: "end" });
|
|
2022
2039
|
return;
|
|
2023
2040
|
}
|
|
2024
2041
|
}
|