cogsbox-state 0.5.308 → 0.5.310
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 +542 -532
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +26 -3
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1817,6 +1817,20 @@ function createProxyHandler<T>(
|
|
|
1817
1817
|
const isAtBottomRef = useRef(stickToBottom);
|
|
1818
1818
|
const previousTotalCountRef = useRef(0);
|
|
1819
1819
|
const isInitialMountRef = useRef(true);
|
|
1820
|
+
const previousTotalHeightRef = useRef(0);
|
|
1821
|
+
const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
|
|
1822
|
+
|
|
1823
|
+
useEffect(() => {
|
|
1824
|
+
// Subscribe to shadow state updates for this stateKey
|
|
1825
|
+
const unsubscribe = getGlobalStore
|
|
1826
|
+
.getState()
|
|
1827
|
+
.subscribeToShadowState(stateKey, () => {
|
|
1828
|
+
// Force recalculation when shadow state updates
|
|
1829
|
+
setShadowUpdateTrigger((prev) => prev + 1);
|
|
1830
|
+
});
|
|
1831
|
+
|
|
1832
|
+
return unsubscribe;
|
|
1833
|
+
}, [stateKey]);
|
|
1820
1834
|
|
|
1821
1835
|
const sourceArray = getGlobalStore().getNestedState(
|
|
1822
1836
|
stateKey,
|
|
@@ -1840,7 +1854,14 @@ function createProxyHandler<T>(
|
|
|
1840
1854
|
}
|
|
1841
1855
|
|
|
1842
1856
|
return { totalHeight: height, positions: pos };
|
|
1843
|
-
}, [
|
|
1857
|
+
}, [
|
|
1858
|
+
totalCount,
|
|
1859
|
+
stateKey,
|
|
1860
|
+
path.join("."),
|
|
1861
|
+
itemHeight,
|
|
1862
|
+
shadowUpdateTrigger,
|
|
1863
|
+
]);
|
|
1864
|
+
|
|
1844
1865
|
console.log("height", totalHeight);
|
|
1845
1866
|
const virtualState = useMemo(() => {
|
|
1846
1867
|
const start = Math.max(0, range.startIndex);
|
|
@@ -1862,12 +1883,14 @@ function createProxyHandler<T>(
|
|
|
1862
1883
|
|
|
1863
1884
|
const wasAtBottom = isAtBottomRef.current;
|
|
1864
1885
|
const listGrew = totalCount > previousTotalCountRef.current;
|
|
1886
|
+
const heightGrew = totalHeight > previousTotalHeightRef.current;
|
|
1865
1887
|
previousTotalCountRef.current = totalCount;
|
|
1888
|
+
previousTotalHeightRef.current = totalHeight;
|
|
1866
1889
|
|
|
1867
1890
|
const handleScroll = () => {
|
|
1868
1891
|
const { scrollTop, clientHeight, scrollHeight } = container;
|
|
1869
1892
|
isAtBottomRef.current =
|
|
1870
|
-
scrollHeight - scrollTop - clientHeight <
|
|
1893
|
+
scrollHeight - scrollTop - clientHeight < 30;
|
|
1871
1894
|
|
|
1872
1895
|
// Binary search for start index
|
|
1873
1896
|
let low = 0,
|
|
@@ -1920,7 +1943,7 @@ function createProxyHandler<T>(
|
|
|
1920
1943
|
behavior: "auto",
|
|
1921
1944
|
});
|
|
1922
1945
|
isInitialMountRef.current = false;
|
|
1923
|
-
} else if (wasAtBottom && listGrew) {
|
|
1946
|
+
} else if (wasAtBottom && (listGrew || heightGrew)) {
|
|
1924
1947
|
console.log(
|
|
1925
1948
|
"stickToBottom wasAtBottom && listGrew",
|
|
1926
1949
|
container.scrollHeight
|