cogsbox-state 0.5.352 → 0.5.354

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.352",
3
+ "version": "0.5.354",
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
@@ -1946,8 +1946,29 @@ function createProxyHandler<T>(
1946
1946
  if (!container) return;
1947
1947
 
1948
1948
  const updateVirtualRange = () => {
1949
- /* ... same as before ... */
1949
+ const { scrollTop, clientHeight } = container;
1950
+ let low = 0,
1951
+ high = totalCount - 1;
1952
+ while (low <= high) {
1953
+ const mid = Math.floor((low + high) / 2);
1954
+ if (positions[mid]! < scrollTop) low = mid + 1;
1955
+ else high = mid - 1;
1956
+ }
1957
+ const startIndex = Math.max(0, high - overscan);
1958
+ let endIndex = startIndex;
1959
+ const visibleEnd = scrollTop + clientHeight;
1960
+ while (
1961
+ endIndex < totalCount &&
1962
+ positions[endIndex]! < visibleEnd
1963
+ ) {
1964
+ endIndex++;
1965
+ }
1966
+ setRange({
1967
+ startIndex,
1968
+ endIndex: Math.min(totalCount, endIndex + overscan),
1969
+ });
1950
1970
  };
1971
+
1951
1972
  const handleUserScroll = () => {
1952
1973
  const isAtBottom =
1953
1974
  container.scrollHeight -
@@ -1960,12 +1981,16 @@ function createProxyHandler<T>(
1960
1981
  }
1961
1982
  updateVirtualRange();
1962
1983
  };
1984
+
1963
1985
  container.addEventListener("scroll", handleUserScroll, {
1964
1986
  passive: true,
1965
1987
  });
1988
+ // Always run on mount and when data changes to show correct initial view
1989
+ updateVirtualRange();
1990
+
1966
1991
  return () =>
1967
1992
  container.removeEventListener("scroll", handleUserScroll);
1968
- }, []);
1993
+ }, [totalCount, positions]);
1969
1994
 
1970
1995
  const scrollToBottom = useCallback(
1971
1996
  (behavior: ScrollBehavior = "smooth") => {