cogsbox-state 0.5.320 → 0.5.322
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 +536 -547
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +15 -38
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1809,14 +1809,6 @@ function createProxyHandler<T>(
|
|
|
1809
1809
|
} = options;
|
|
1810
1810
|
|
|
1811
1811
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
1812
|
-
|
|
1813
|
-
const sourceArray = getGlobalStore().getNestedState(
|
|
1814
|
-
stateKey,
|
|
1815
|
-
path
|
|
1816
|
-
) as any[];
|
|
1817
|
-
const totalCount = sourceArray.length;
|
|
1818
|
-
|
|
1819
|
-
// Start at top, will adjust once container is measured
|
|
1820
1812
|
const [range, setRange] = useState({
|
|
1821
1813
|
startIndex: 0,
|
|
1822
1814
|
endIndex: 10,
|
|
@@ -1824,7 +1816,6 @@ function createProxyHandler<T>(
|
|
|
1824
1816
|
|
|
1825
1817
|
const isLockedToBottomRef = useRef(stickToBottom);
|
|
1826
1818
|
const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
|
|
1827
|
-
const hasInitializedRef = useRef(false);
|
|
1828
1819
|
|
|
1829
1820
|
useEffect(() => {
|
|
1830
1821
|
const unsubscribe = getGlobalStore
|
|
@@ -1835,6 +1826,12 @@ function createProxyHandler<T>(
|
|
|
1835
1826
|
return unsubscribe;
|
|
1836
1827
|
}, [stateKey]);
|
|
1837
1828
|
|
|
1829
|
+
const sourceArray = getGlobalStore().getNestedState(
|
|
1830
|
+
stateKey,
|
|
1831
|
+
path
|
|
1832
|
+
) as any[];
|
|
1833
|
+
const totalCount = sourceArray.length;
|
|
1834
|
+
|
|
1838
1835
|
const { totalHeight, positions } = useMemo(() => {
|
|
1839
1836
|
const shadowArray =
|
|
1840
1837
|
getGlobalStore.getState().getShadowMetadata(stateKey, path) ||
|
|
@@ -1910,40 +1907,20 @@ function createProxyHandler<T>(
|
|
|
1910
1907
|
passive: true,
|
|
1911
1908
|
});
|
|
1912
1909
|
|
|
1913
|
-
// Initialize at bottom if needed
|
|
1914
|
-
if (
|
|
1915
|
-
stickToBottom &&
|
|
1916
|
-
!hasInitializedRef.current &&
|
|
1917
|
-
totalCount > 0 &&
|
|
1918
|
-
container.clientHeight > 0
|
|
1919
|
-
) {
|
|
1920
|
-
hasInitializedRef.current = true;
|
|
1921
|
-
|
|
1922
|
-
// Now we have the actual container height, calculate visible items
|
|
1923
|
-
const visibleCount = Math.ceil(
|
|
1924
|
-
container.clientHeight / itemHeight
|
|
1925
|
-
);
|
|
1926
|
-
const startIdx = Math.max(
|
|
1927
|
-
0,
|
|
1928
|
-
totalCount - visibleCount - overscan
|
|
1929
|
-
);
|
|
1930
|
-
|
|
1931
|
-
// Set range to show bottom items
|
|
1932
|
-
setRange({
|
|
1933
|
-
startIndex: startIdx,
|
|
1934
|
-
endIndex: totalCount,
|
|
1935
|
-
});
|
|
1936
|
-
|
|
1937
|
-
// Scroll to bottom
|
|
1938
|
-
container.scrollTop = container.scrollHeight;
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
1910
|
updateVirtualRange();
|
|
1942
1911
|
|
|
1943
1912
|
return () => {
|
|
1944
1913
|
container.removeEventListener("scroll", handleUserScroll);
|
|
1945
1914
|
};
|
|
1946
|
-
}, [totalCount, positions
|
|
1915
|
+
}, [totalCount, positions]);
|
|
1916
|
+
|
|
1917
|
+
// SEPARATE EFFECT JUST FOR SCROLLING TO BOTTOM
|
|
1918
|
+
useEffect(() => {
|
|
1919
|
+
if (stickToBottom && containerRef.current && totalCount > 0) {
|
|
1920
|
+
// Just scroll to a massive number every time count changes
|
|
1921
|
+
containerRef.current.scrollTop = 999999999;
|
|
1922
|
+
}
|
|
1923
|
+
}, [totalCount, stickToBottom]);
|
|
1947
1924
|
|
|
1948
1925
|
const scrollToBottom = useCallback(
|
|
1949
1926
|
(behavior: ScrollBehavior = "smooth") => {
|