dce-reactkit 3.5.10 → 3.5.11
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/cjs/index.js +19 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +19 -16
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AutoscrollToBottomContainer.tsx +24 -18
package/dist/esm/index.js
CHANGED
|
@@ -40825,7 +40825,7 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40825
40825
|
// Initialize refs
|
|
40826
40826
|
const lastItemIds = useRef([]);
|
|
40827
40827
|
const container = useRef(null);
|
|
40828
|
-
const
|
|
40828
|
+
const wasLastScrolledToBottom = useRef(true);
|
|
40829
40829
|
/*------------------------------------------------------------------------*/
|
|
40830
40830
|
/* ------------------------- Component Functions ------------------------ */
|
|
40831
40831
|
/*------------------------------------------------------------------------*/
|
|
@@ -40848,7 +40848,10 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40848
40848
|
const rootFontSizePx = Number.parseInt(getComputedStyle(document.documentElement).fontSize, 10);
|
|
40849
40849
|
const distanceToBottomRems = Math.abs((scrollTop + clientHeight - scrollHeight) / rootFontSizePx);
|
|
40850
40850
|
// Figure out if we're scrolled to the bottom
|
|
40851
|
-
|
|
40851
|
+
const atBottom = (distanceToBottomRems < SCROLLED_TO_BOTTOM_THRESHOLD_REMS);
|
|
40852
|
+
// Remember if we scrolled to the bottom
|
|
40853
|
+
wasLastScrolledToBottom.current = atBottom;
|
|
40854
|
+
return atBottom;
|
|
40852
40855
|
};
|
|
40853
40856
|
/**
|
|
40854
40857
|
* Scroll the user to the bottom of the container
|
|
@@ -40864,7 +40867,10 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40864
40867
|
type: ActionType.HideJumpToBottomButton,
|
|
40865
40868
|
});
|
|
40866
40869
|
// Scroll to bottom
|
|
40867
|
-
container.current.scrollTop = container.current.scrollHeight
|
|
40870
|
+
container.current.scrollTop = (container.current.scrollHeight
|
|
40871
|
+
- container.current.clientHeight);
|
|
40872
|
+
// Remember that we scrolled to the bottom
|
|
40873
|
+
wasLastScrolledToBottom.current = true;
|
|
40868
40874
|
};
|
|
40869
40875
|
/*----------------------------------------*/
|
|
40870
40876
|
/* -------------- Handlers -------------- */
|
|
@@ -40878,8 +40884,9 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40878
40884
|
if (!container.current) {
|
|
40879
40885
|
return;
|
|
40880
40886
|
}
|
|
40881
|
-
// If scrolled to bottom, hide the button
|
|
40887
|
+
// If scrolled to bottom, hide the button and remember position
|
|
40882
40888
|
if (isScrolledToBottom()) {
|
|
40889
|
+
// Hide button
|
|
40883
40890
|
dispatch({
|
|
40884
40891
|
type: ActionType.HideJumpToBottomButton,
|
|
40885
40892
|
});
|
|
@@ -40904,17 +40911,19 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40904
40911
|
// Check if new content appeared
|
|
40905
40912
|
const currentItemIds = getItemIds(items);
|
|
40906
40913
|
// Check if new content appeared at bottom
|
|
40907
|
-
const newContentAppeared = (
|
|
40908
|
-
|
|
40909
|
-
|
|
40910
|
-
|
|
40911
|
-
|
|
40914
|
+
const newContentAppeared = (
|
|
40915
|
+
// There are items
|
|
40916
|
+
currentItemIds.length > 0
|
|
40917
|
+
// The last item is new
|
|
40918
|
+
&& !lastItemIds.current.includes(currentItemIds[currentItemIds.length - 1]));
|
|
40919
|
+
// Update last item ids
|
|
40920
|
+
lastItemIds.current = currentItemIds;
|
|
40912
40921
|
// Do nothing if no new content
|
|
40913
40922
|
if (!newContentAppeared) {
|
|
40914
40923
|
return;
|
|
40915
40924
|
}
|
|
40916
40925
|
// Check if used to be scrolled to the bottom
|
|
40917
|
-
if (
|
|
40926
|
+
if (wasLastScrolledToBottom.current) {
|
|
40918
40927
|
// Was scrolled to the bottom! Autoscroll.
|
|
40919
40928
|
scrollToBottom();
|
|
40920
40929
|
}
|
|
@@ -40924,12 +40933,6 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40924
40933
|
type: ActionType.ShowJumpToBottomButton,
|
|
40925
40934
|
});
|
|
40926
40935
|
}
|
|
40927
|
-
// Update last item ids
|
|
40928
|
-
lastItemIds.current = currentItemIds;
|
|
40929
|
-
// Remember if we were scrolled to the bottom before the update
|
|
40930
|
-
return () => {
|
|
40931
|
-
wasScrolledToBottomBeforeItemsUpdate.current = isScrolledToBottom();
|
|
40932
|
-
};
|
|
40933
40936
|
}, [items]);
|
|
40934
40937
|
/*------------------------------------------------------------------------*/
|
|
40935
40938
|
/* ------------------------------- Render ------------------------------- */
|