cogsbox-state 0.5.377 → 0.5.378

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-state",
3
- "version": "0.5.377",
3
+ "version": "0.5.378",
4
4
  "description": "React state management library with form controls and server sync",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/CogsState.tsx CHANGED
@@ -1933,11 +1933,13 @@ function createProxyHandler<T>(
1933
1933
  console.log(
1934
1934
  "ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
1935
1935
  );
1936
+
1936
1937
  setRange({
1937
1938
  startIndex: Math.max(0, totalCount - 10 - overscan),
1938
1939
  endIndex: totalCount,
1939
1940
  });
1940
1941
 
1942
+ let intervalId: NodeJS.Timeout;
1941
1943
  intervalId = setInterval(() => {
1942
1944
  const lastItemIndex = totalCount - 1;
1943
1945
  const shadowArray =
@@ -1949,15 +1951,36 @@ function createProxyHandler<T>(
1949
1951
 
1950
1952
  if (lastItemHeight > 0) {
1951
1953
  clearInterval(intervalId);
1952
- if (!shouldNotScroll.current) {
1953
- console.log(
1954
- "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
1955
- );
1956
1954
 
1957
- setStatus("SCROLLING_TO_BOTTOM");
1955
+ if (!shouldNotScroll.current) {
1956
+ const prevCount = prevTotalCountRef.current;
1957
+ const addedItems = totalCount - prevCount;
1958
+ const smallAddition = addedItems > 0 && addedItems <= 3;
1959
+
1960
+ if (smallAddition) {
1961
+ const addedHeight =
1962
+ positions[totalCount - 1]! -
1963
+ (positions[prevCount] ?? 0);
1964
+ container.scrollBy({
1965
+ top: addedHeight,
1966
+ behavior: "smooth",
1967
+ });
1968
+
1969
+ console.log(
1970
+ "ACTION (GETTING_HEIGHTS): Small addition -> LOCKED_AT_BOTTOM"
1971
+ );
1972
+ setStatus("LOCKED_AT_BOTTOM");
1973
+ } else {
1974
+ console.log(
1975
+ "ACTION (GETTING_HEIGHTS): Large change -> SCROLLING_TO_BOTTOM"
1976
+ );
1977
+ setStatus("SCROLLING_TO_BOTTOM");
1978
+ }
1958
1979
  }
1959
1980
  }
1960
1981
  }, 100);
1982
+
1983
+ return () => clearInterval(intervalId);
1961
1984
  } else if (status === "SCROLLING_TO_BOTTOM") {
1962
1985
  console.log(
1963
1986
  "ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
@@ -1987,33 +2010,23 @@ function createProxyHandler<T>(
1987
2010
  return () => clearTimeout(timeoutId);
1988
2011
  }
1989
2012
 
1990
- // If status is IDLE_NOT_AT_BOTTOM or LOCKED_AT_BOTTOM, we do nothing here.
1991
- // The scroll has either finished or been disabled by the user.
1992
-
1993
2013
  return () => {
1994
2014
  if (intervalId) clearInterval(intervalId);
1995
2015
  };
1996
2016
  }, [status, totalCount, positions]);
1997
2017
 
1998
- // --- 3. USER INTERACTION & RANGE UPDATER ---
1999
2018
  useEffect(() => {
2000
2019
  const container = containerRef.current;
2001
2020
  if (!container) return;
2002
2021
 
2003
- // The scroll distance threshold. One item's height is a great default.
2004
2022
  const scrollThreshold = itemHeight;
2005
2023
 
2006
2024
  const handleUserScroll = () => {
2007
- // Essential guard for our own programmatic scrolls.
2008
2025
  if (isProgrammaticScroll.current) {
2009
2026
  return;
2010
2027
  }
2011
2028
 
2012
2029
  const scrollTop = container.scrollTop;
2013
-
2014
- // --- THE CORE LOGIC YOU REQUESTED ---
2015
- // Is the user just wiggling the scrollbar? If so, exit.
2016
- // This is a very cheap check that runs on every scroll event.
2017
2030
  if (
2018
2031
  Math.abs(scrollTop - lastUpdateAtScrollTop.current) <
2019
2032
  scrollThreshold
@@ -2021,8 +2034,6 @@ function createProxyHandler<T>(
2021
2034
  return;
2022
2035
  }
2023
2036
 
2024
- // --- IF WE ARE HERE, WE HAVE SCROLLED A "DECENT AMOUNT" ---
2025
-
2026
2037
  console.log(
2027
2038
  `Threshold passed at ${scrollTop}px. Recalculating range...`
2028
2039
  );