cogsbox-state 0.5.417 → 0.5.419
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 +414 -416
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +17 -15
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1823,7 +1823,7 @@ function createProxyHandler<T>(
|
|
|
1823
1823
|
const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
|
|
1824
1824
|
const wasAtBottomRef = useRef(true);
|
|
1825
1825
|
const previousCountRef = useRef(0);
|
|
1826
|
-
|
|
1826
|
+
const userHasScrolledAwayRef = useRef(false);
|
|
1827
1827
|
// Subscribe to shadow state updates
|
|
1828
1828
|
useEffect(() => {
|
|
1829
1829
|
const unsubscribe = getGlobalStore
|
|
@@ -1910,9 +1910,9 @@ function createProxyHandler<T>(
|
|
|
1910
1910
|
previousCountRef.current === 0 && totalCount > 0;
|
|
1911
1911
|
|
|
1912
1912
|
if ((hasNewItems || isInitialLoad) && wasAtBottomRef.current) {
|
|
1913
|
-
//
|
|
1913
|
+
// Only update range and scroll if we're at bottom
|
|
1914
1914
|
const visibleCount = Math.ceil(
|
|
1915
|
-
containerRef.current?.clientHeight || 0 / itemHeight
|
|
1915
|
+
(containerRef.current?.clientHeight || 0) / itemHeight
|
|
1916
1916
|
);
|
|
1917
1917
|
const newRange = {
|
|
1918
1918
|
startIndex: Math.max(
|
|
@@ -1924,19 +1924,12 @@ function createProxyHandler<T>(
|
|
|
1924
1924
|
|
|
1925
1925
|
setRange(newRange);
|
|
1926
1926
|
|
|
1927
|
-
// Then scroll to the last item after it renders
|
|
1928
1927
|
const timeoutId = setTimeout(() => {
|
|
1929
|
-
|
|
1930
|
-
if (!scrolled && containerRef.current) {
|
|
1931
|
-
// Fallback if ref not available yet
|
|
1928
|
+
if (containerRef.current) {
|
|
1932
1929
|
containerRef.current.scrollTop =
|
|
1933
1930
|
containerRef.current.scrollHeight;
|
|
1934
1931
|
}
|
|
1935
1932
|
}, 50);
|
|
1936
|
-
|
|
1937
|
-
previousCountRef.current = totalCount;
|
|
1938
|
-
|
|
1939
|
-
return () => clearTimeout(timeoutId);
|
|
1940
1933
|
}
|
|
1941
1934
|
|
|
1942
1935
|
previousCountRef.current = totalCount;
|
|
@@ -1952,9 +1945,19 @@ function createProxyHandler<T>(
|
|
|
1952
1945
|
const distanceFromBottom =
|
|
1953
1946
|
scrollHeight - scrollTop - clientHeight;
|
|
1954
1947
|
|
|
1955
|
-
//
|
|
1956
|
-
|
|
1957
|
-
wasAtBottomRef.current =
|
|
1948
|
+
// Track if user is at bottom with tight tolerance
|
|
1949
|
+
const isAtBottom = distanceFromBottom < 5;
|
|
1950
|
+
wasAtBottomRef.current = isAtBottom;
|
|
1951
|
+
|
|
1952
|
+
// If user scrolls away from bottom, set the flag
|
|
1953
|
+
if (!isAtBottom && distanceFromBottom > 50) {
|
|
1954
|
+
userHasScrolledAwayRef.current = true;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
// If user scrolls back to bottom, clear the flag
|
|
1958
|
+
if (isAtBottom) {
|
|
1959
|
+
userHasScrolledAwayRef.current = false;
|
|
1960
|
+
}
|
|
1958
1961
|
|
|
1959
1962
|
// Update visible range based on scroll position
|
|
1960
1963
|
let startIndex = 0;
|
|
@@ -1979,7 +1982,6 @@ function createProxyHandler<T>(
|
|
|
1979
1982
|
endIndex: Math.min(totalCount, endIndex + 1 + overscan),
|
|
1980
1983
|
});
|
|
1981
1984
|
};
|
|
1982
|
-
|
|
1983
1985
|
container.addEventListener("scroll", handleScroll, {
|
|
1984
1986
|
passive: true,
|
|
1985
1987
|
});
|