cogsbox-state 0.5.404 → 0.5.406
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 +364 -302
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +104 -18
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1805,6 +1805,7 @@ function createProxyHandler<T>(
|
|
|
1805
1805
|
}
|
|
1806
1806
|
// Simplified useVirtualView approach
|
|
1807
1807
|
// Optimal approach - replace the useVirtualView implementation
|
|
1808
|
+
// Complete useVirtualView implementation with comprehensive logging
|
|
1808
1809
|
if (prop === "useVirtualView") {
|
|
1809
1810
|
return (
|
|
1810
1811
|
options: VirtualViewOptions
|
|
@@ -1816,6 +1817,12 @@ function createProxyHandler<T>(
|
|
|
1816
1817
|
dependencies = [],
|
|
1817
1818
|
} = options;
|
|
1818
1819
|
|
|
1820
|
+
console.log("useVirtualView initialized with:", {
|
|
1821
|
+
itemHeight,
|
|
1822
|
+
overscan,
|
|
1823
|
+
stickToBottom,
|
|
1824
|
+
});
|
|
1825
|
+
|
|
1819
1826
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
1820
1827
|
const [range, setRange] = useState({
|
|
1821
1828
|
startIndex: 0,
|
|
@@ -1830,9 +1837,11 @@ function createProxyHandler<T>(
|
|
|
1830
1837
|
|
|
1831
1838
|
// Subscribe to shadow state updates
|
|
1832
1839
|
useEffect(() => {
|
|
1840
|
+
console.log("Setting up shadow state subscription");
|
|
1833
1841
|
const unsubscribe = getGlobalStore
|
|
1834
1842
|
.getState()
|
|
1835
1843
|
.subscribeToShadowState(stateKey, () => {
|
|
1844
|
+
console.log("Shadow state updated");
|
|
1836
1845
|
setShadowUpdateTrigger((prev) => prev + 1);
|
|
1837
1846
|
});
|
|
1838
1847
|
return unsubscribe;
|
|
@@ -1843,9 +1852,11 @@ function createProxyHandler<T>(
|
|
|
1843
1852
|
path
|
|
1844
1853
|
) as any[];
|
|
1845
1854
|
const totalCount = sourceArray.length;
|
|
1855
|
+
console.log("Source array length:", totalCount);
|
|
1846
1856
|
|
|
1847
1857
|
// Calculate heights and positions
|
|
1848
1858
|
const { totalHeight, positions } = useMemo(() => {
|
|
1859
|
+
console.log("Recalculating heights and positions");
|
|
1849
1860
|
const shadowArray =
|
|
1850
1861
|
getGlobalStore.getState().getShadowMetadata(stateKey, path) ||
|
|
1851
1862
|
[];
|
|
@@ -1857,6 +1868,7 @@ function createProxyHandler<T>(
|
|
|
1857
1868
|
shadowArray[i]?.virtualizer?.itemHeight;
|
|
1858
1869
|
height += measuredHeight || itemHeight;
|
|
1859
1870
|
}
|
|
1871
|
+
console.log("Total height calculated:", height);
|
|
1860
1872
|
return { totalHeight: height, positions: pos };
|
|
1861
1873
|
}, [
|
|
1862
1874
|
totalCount,
|
|
@@ -1870,6 +1882,10 @@ function createProxyHandler<T>(
|
|
|
1870
1882
|
const virtualState = useMemo(() => {
|
|
1871
1883
|
const start = Math.max(0, range.startIndex);
|
|
1872
1884
|
const end = Math.min(totalCount, range.endIndex);
|
|
1885
|
+
console.log("Creating virtual state for range:", {
|
|
1886
|
+
start,
|
|
1887
|
+
end,
|
|
1888
|
+
});
|
|
1873
1889
|
const validIndices = Array.from(
|
|
1874
1890
|
{ length: end - start },
|
|
1875
1891
|
(_, i) => start + i
|
|
@@ -1883,12 +1899,41 @@ function createProxyHandler<T>(
|
|
|
1883
1899
|
|
|
1884
1900
|
// Handle auto-scroll to bottom
|
|
1885
1901
|
useEffect(() => {
|
|
1886
|
-
|
|
1902
|
+
console.log("Auto-scroll effect triggered:", {
|
|
1903
|
+
stickToBottom,
|
|
1904
|
+
hasContainer: !!containerRef.current,
|
|
1905
|
+
totalCount,
|
|
1906
|
+
shouldStickToBottom: shouldStickToBottomRef.current,
|
|
1907
|
+
range,
|
|
1908
|
+
});
|
|
1909
|
+
|
|
1910
|
+
if (!stickToBottom) {
|
|
1911
|
+
console.log("Stick to bottom is false, skipping");
|
|
1887
1912
|
return;
|
|
1888
|
-
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
if (!containerRef.current) {
|
|
1916
|
+
console.log("No container ref, skipping");
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
if (totalCount === 0) {
|
|
1921
|
+
console.log("No items, skipping");
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
if (!shouldStickToBottomRef.current) {
|
|
1926
|
+
console.log(
|
|
1927
|
+
"Should not stick to bottom (user scrolled), skipping"
|
|
1928
|
+
);
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
console.log("Proceeding with auto-scroll logic");
|
|
1889
1933
|
|
|
1890
1934
|
// Clear any existing interval
|
|
1891
1935
|
if (scrollToBottomIntervalRef.current) {
|
|
1936
|
+
console.log("Clearing existing scroll interval");
|
|
1892
1937
|
clearInterval(scrollToBottomIntervalRef.current);
|
|
1893
1938
|
}
|
|
1894
1939
|
|
|
@@ -1897,21 +1942,34 @@ function createProxyHandler<T>(
|
|
|
1897
1942
|
const isInitialLoad = range.endIndex < jumpThreshold;
|
|
1898
1943
|
const isBigJump = totalCount > range.endIndex + jumpThreshold;
|
|
1899
1944
|
|
|
1945
|
+
console.log("Jump check:", {
|
|
1946
|
+
isInitialLoad,
|
|
1947
|
+
isBigJump,
|
|
1948
|
+
totalCount,
|
|
1949
|
+
currentEndIndex: range.endIndex,
|
|
1950
|
+
});
|
|
1951
|
+
|
|
1900
1952
|
if (isInitialLoad || isBigJump) {
|
|
1901
|
-
|
|
1902
|
-
setRange({
|
|
1953
|
+
const newRange = {
|
|
1903
1954
|
startIndex: Math.max(0, totalCount - 20),
|
|
1904
1955
|
endIndex: totalCount,
|
|
1905
|
-
}
|
|
1956
|
+
};
|
|
1957
|
+
console.log("Jumping to end range:", newRange);
|
|
1958
|
+
setRange(newRange);
|
|
1906
1959
|
}
|
|
1907
1960
|
|
|
1908
1961
|
// Keep scrolling to bottom until we're actually there
|
|
1909
1962
|
let attempts = 0;
|
|
1910
1963
|
const maxAttempts = 50; // 5 seconds max
|
|
1911
1964
|
|
|
1965
|
+
console.log("Starting scroll-to-bottom interval");
|
|
1966
|
+
|
|
1912
1967
|
scrollToBottomIntervalRef.current = setInterval(() => {
|
|
1913
1968
|
const container = containerRef.current;
|
|
1914
|
-
if (!container)
|
|
1969
|
+
if (!container) {
|
|
1970
|
+
console.log("Container lost during interval");
|
|
1971
|
+
return;
|
|
1972
|
+
}
|
|
1915
1973
|
|
|
1916
1974
|
attempts++;
|
|
1917
1975
|
|
|
@@ -1920,41 +1978,54 @@ function createProxyHandler<T>(
|
|
|
1920
1978
|
const actualBottom = scrollHeight;
|
|
1921
1979
|
const isAtBottom = actualBottom - currentBottom < 5;
|
|
1922
1980
|
|
|
1923
|
-
console.log(
|
|
1924
|
-
|
|
1925
|
-
|
|
1981
|
+
console.log(`Scroll attempt ${attempts}:`, {
|
|
1982
|
+
currentBottom,
|
|
1983
|
+
actualBottom,
|
|
1984
|
+
isAtBottom,
|
|
1985
|
+
scrollTop,
|
|
1986
|
+
scrollHeight,
|
|
1987
|
+
clientHeight,
|
|
1988
|
+
});
|
|
1926
1989
|
|
|
1927
1990
|
if (isAtBottom || attempts >= maxAttempts) {
|
|
1928
|
-
clearInterval(scrollToBottomIntervalRef.current!);
|
|
1929
|
-
scrollToBottomIntervalRef.current = null;
|
|
1930
1991
|
console.log(
|
|
1931
|
-
isAtBottom
|
|
1992
|
+
isAtBottom
|
|
1993
|
+
? "Successfully reached bottom!"
|
|
1994
|
+
: "Timeout - giving up"
|
|
1932
1995
|
);
|
|
1996
|
+
clearInterval(scrollToBottomIntervalRef.current!);
|
|
1997
|
+
scrollToBottomIntervalRef.current = null;
|
|
1933
1998
|
} else {
|
|
1934
|
-
|
|
1999
|
+
console.log("Scrolling to", container.scrollHeight);
|
|
1935
2000
|
container.scrollTop = container.scrollHeight;
|
|
1936
2001
|
}
|
|
1937
2002
|
}, 100);
|
|
1938
2003
|
|
|
1939
2004
|
// Cleanup
|
|
1940
2005
|
return () => {
|
|
2006
|
+
console.log("Cleaning up scroll interval");
|
|
1941
2007
|
if (scrollToBottomIntervalRef.current) {
|
|
1942
2008
|
clearInterval(scrollToBottomIntervalRef.current);
|
|
1943
2009
|
scrollToBottomIntervalRef.current = null;
|
|
1944
2010
|
}
|
|
1945
2011
|
};
|
|
1946
|
-
}, [totalCount, stickToBottom]);
|
|
2012
|
+
}, [totalCount, stickToBottom, range.startIndex, range.endIndex]);
|
|
1947
2013
|
|
|
1948
2014
|
// Handle user scroll
|
|
1949
2015
|
useEffect(() => {
|
|
1950
2016
|
const container = containerRef.current;
|
|
1951
|
-
if (!container)
|
|
2017
|
+
if (!container) {
|
|
2018
|
+
console.log("No container for scroll handler");
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
console.log("Setting up scroll handler");
|
|
1952
2023
|
|
|
1953
2024
|
let scrollTimeout: NodeJS.Timeout;
|
|
1954
2025
|
|
|
1955
2026
|
const handleScroll = () => {
|
|
1956
2027
|
if (scrollToBottomIntervalRef.current) {
|
|
1957
|
-
|
|
2028
|
+
console.log("User scrolled - stopping auto-scroll");
|
|
1958
2029
|
clearInterval(scrollToBottomIntervalRef.current);
|
|
1959
2030
|
scrollToBottomIntervalRef.current = null;
|
|
1960
2031
|
}
|
|
@@ -1965,12 +2036,14 @@ function createProxyHandler<T>(
|
|
|
1965
2036
|
|
|
1966
2037
|
// Update whether we should stick to bottom
|
|
1967
2038
|
shouldStickToBottomRef.current = isAtBottom;
|
|
2039
|
+
console.log("User scroll - at bottom:", isAtBottom);
|
|
1968
2040
|
|
|
1969
2041
|
// Mark as user scrolling
|
|
1970
2042
|
clearTimeout(scrollTimeout);
|
|
1971
2043
|
isUserScrollingRef.current = true;
|
|
1972
2044
|
scrollTimeout = setTimeout(() => {
|
|
1973
2045
|
isUserScrollingRef.current = false;
|
|
2046
|
+
console.log("User stopped scrolling");
|
|
1974
2047
|
}, 150);
|
|
1975
2048
|
|
|
1976
2049
|
// Update visible range
|
|
@@ -1991,18 +2064,23 @@ function createProxyHandler<T>(
|
|
|
1991
2064
|
endIndex = i;
|
|
1992
2065
|
}
|
|
1993
2066
|
|
|
1994
|
-
|
|
2067
|
+
const newRange = {
|
|
1995
2068
|
startIndex: Math.max(0, startIndex),
|
|
1996
2069
|
endIndex: Math.min(totalCount, endIndex + 1 + overscan),
|
|
1997
|
-
}
|
|
2070
|
+
};
|
|
2071
|
+
|
|
2072
|
+
console.log("Updating visible range:", newRange);
|
|
2073
|
+
setRange(newRange);
|
|
1998
2074
|
};
|
|
1999
2075
|
|
|
2000
2076
|
container.addEventListener("scroll", handleScroll, {
|
|
2001
2077
|
passive: true,
|
|
2002
2078
|
});
|
|
2079
|
+
console.log("Initial scroll calculation");
|
|
2003
2080
|
handleScroll(); // Initial calculation
|
|
2004
2081
|
|
|
2005
2082
|
return () => {
|
|
2083
|
+
console.log("Removing scroll handler");
|
|
2006
2084
|
container.removeEventListener("scroll", handleScroll);
|
|
2007
2085
|
clearTimeout(scrollTimeout);
|
|
2008
2086
|
};
|
|
@@ -2010,6 +2088,7 @@ function createProxyHandler<T>(
|
|
|
2010
2088
|
|
|
2011
2089
|
const scrollToBottom = useCallback(
|
|
2012
2090
|
(behavior: ScrollBehavior = "auto") => {
|
|
2091
|
+
console.log("Manual scrollToBottom called");
|
|
2013
2092
|
shouldStickToBottomRef.current = true;
|
|
2014
2093
|
if (containerRef.current) {
|
|
2015
2094
|
containerRef.current.scrollTop =
|
|
@@ -2021,6 +2100,7 @@ function createProxyHandler<T>(
|
|
|
2021
2100
|
|
|
2022
2101
|
const scrollToIndex = useCallback(
|
|
2023
2102
|
(index: number, behavior: ScrollBehavior = "smooth") => {
|
|
2103
|
+
console.log("scrollToIndex called:", index);
|
|
2024
2104
|
if (containerRef.current && positions[index] !== undefined) {
|
|
2025
2105
|
containerRef.current.scrollTo({
|
|
2026
2106
|
top: positions[index],
|
|
@@ -2049,6 +2129,12 @@ function createProxyHandler<T>(
|
|
|
2049
2129
|
},
|
|
2050
2130
|
};
|
|
2051
2131
|
|
|
2132
|
+
console.log("Returning virtualizer with props:", {
|
|
2133
|
+
range,
|
|
2134
|
+
totalHeight,
|
|
2135
|
+
startPosition: positions[range.startIndex] || 0,
|
|
2136
|
+
});
|
|
2137
|
+
|
|
2052
2138
|
return {
|
|
2053
2139
|
virtualState,
|
|
2054
2140
|
virtualizerProps,
|