cogsbox-state 0.5.353 → 0.5.355
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 +516 -496
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +37 -5
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1816,7 +1816,7 @@ function createProxyHandler<T>(
|
|
|
1816
1816
|
});
|
|
1817
1817
|
|
|
1818
1818
|
const isLockedToBottomRef = useRef(stickToBottom);
|
|
1819
|
-
|
|
1819
|
+
const isAutoScrolling = useRef(false);
|
|
1820
1820
|
const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
|
|
1821
1821
|
|
|
1822
1822
|
useEffect(() => {
|
|
@@ -1915,12 +1915,15 @@ function createProxyHandler<T>(
|
|
|
1915
1915
|
"color: green; font-weight: bold;"
|
|
1916
1916
|
);
|
|
1917
1917
|
clearInterval(intervalId); // Stop the loop.
|
|
1918
|
-
|
|
1918
|
+
isAutoScrolling.current = true;
|
|
1919
1919
|
// STEP 3: Scroll.
|
|
1920
1920
|
container.scrollTo({
|
|
1921
1921
|
top: container.scrollHeight,
|
|
1922
1922
|
behavior: "smooth",
|
|
1923
1923
|
});
|
|
1924
|
+
setTimeout(() => {
|
|
1925
|
+
isAutoScrolling.current = false;
|
|
1926
|
+
}, 1000);
|
|
1924
1927
|
} else {
|
|
1925
1928
|
console.log("...WAITING. Height is not ready.");
|
|
1926
1929
|
if (loopCount > 20) {
|
|
@@ -1938,7 +1941,7 @@ function createProxyHandler<T>(
|
|
|
1938
1941
|
console.log("ALGORITHM: Cleaning up loop.");
|
|
1939
1942
|
clearInterval(intervalId);
|
|
1940
1943
|
};
|
|
1941
|
-
}, [totalCount, ...(options.dependencies ?? [])]); // This whole process triggers ONLY when totalCount changes.
|
|
1944
|
+
}, [totalCount, totalHeight, ...(options.dependencies ?? [])]); // This whole process triggers ONLY when totalCount changes.
|
|
1942
1945
|
|
|
1943
1946
|
// Effect to handle user scrolling.
|
|
1944
1947
|
useEffect(() => {
|
|
@@ -1946,9 +1949,34 @@ function createProxyHandler<T>(
|
|
|
1946
1949
|
if (!container) return;
|
|
1947
1950
|
|
|
1948
1951
|
const updateVirtualRange = () => {
|
|
1949
|
-
|
|
1952
|
+
const { scrollTop, clientHeight } = container;
|
|
1953
|
+
let low = 0,
|
|
1954
|
+
high = totalCount - 1;
|
|
1955
|
+
while (low <= high) {
|
|
1956
|
+
const mid = Math.floor((low + high) / 2);
|
|
1957
|
+
if (positions[mid]! < scrollTop) low = mid + 1;
|
|
1958
|
+
else high = mid - 1;
|
|
1959
|
+
}
|
|
1960
|
+
const startIndex = Math.max(0, high - overscan);
|
|
1961
|
+
let endIndex = startIndex;
|
|
1962
|
+
const visibleEnd = scrollTop + clientHeight;
|
|
1963
|
+
while (
|
|
1964
|
+
endIndex < totalCount &&
|
|
1965
|
+
positions[endIndex]! < visibleEnd
|
|
1966
|
+
) {
|
|
1967
|
+
endIndex++;
|
|
1968
|
+
}
|
|
1969
|
+
setRange({
|
|
1970
|
+
startIndex,
|
|
1971
|
+
endIndex: Math.min(totalCount, endIndex + overscan),
|
|
1972
|
+
});
|
|
1950
1973
|
};
|
|
1974
|
+
|
|
1951
1975
|
const handleUserScroll = () => {
|
|
1976
|
+
if (isAutoScrolling.current) {
|
|
1977
|
+
// <--- ADD THIS CHECK
|
|
1978
|
+
return;
|
|
1979
|
+
}
|
|
1952
1980
|
const isAtBottom =
|
|
1953
1981
|
container.scrollHeight -
|
|
1954
1982
|
container.scrollTop -
|
|
@@ -1960,12 +1988,16 @@ function createProxyHandler<T>(
|
|
|
1960
1988
|
}
|
|
1961
1989
|
updateVirtualRange();
|
|
1962
1990
|
};
|
|
1991
|
+
|
|
1963
1992
|
container.addEventListener("scroll", handleUserScroll, {
|
|
1964
1993
|
passive: true,
|
|
1965
1994
|
});
|
|
1995
|
+
// Always run on mount and when data changes to show correct initial view
|
|
1996
|
+
updateVirtualRange();
|
|
1997
|
+
|
|
1966
1998
|
return () =>
|
|
1967
1999
|
container.removeEventListener("scroll", handleUserScroll);
|
|
1968
|
-
}, []);
|
|
2000
|
+
}, [totalCount, positions]);
|
|
1969
2001
|
|
|
1970
2002
|
const scrollToBottom = useCallback(
|
|
1971
2003
|
(behavior: ScrollBehavior = "smooth") => {
|