dce-reactkit 3.5.9 → 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 +28 -20
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AutoscrollToBottomContainer.d.ts +2 -0
- package/dist/esm/index.js +28 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AutoscrollToBottomContainer.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/AutoscrollToBottomContainer.tsx +36 -16
package/dist/esm/index.js
CHANGED
|
@@ -40811,7 +40811,7 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40811
40811
|
/*------------------------------------------------------------------------*/
|
|
40812
40812
|
/* -------------- Props ------------- */
|
|
40813
40813
|
// Destructure all props
|
|
40814
|
-
const { itemsName, items, jumpToBottomButtonVariant = Variant$1.Danger, } = props;
|
|
40814
|
+
const { itemsName, items, jumpToBottomButtonVariant = Variant$1.Danger, messageBeforeItems, messageAfterItems, } = props;
|
|
40815
40815
|
/* -------------- State ------------- */
|
|
40816
40816
|
// Initial state
|
|
40817
40817
|
const initialState = {
|
|
@@ -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,15 +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
|
-
|
|
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;
|
|
40910
40921
|
// Do nothing if no new content
|
|
40911
40922
|
if (!newContentAppeared) {
|
|
40912
40923
|
return;
|
|
40913
40924
|
}
|
|
40914
40925
|
// Check if used to be scrolled to the bottom
|
|
40915
|
-
if (
|
|
40926
|
+
if (wasLastScrolledToBottom.current) {
|
|
40916
40927
|
// Was scrolled to the bottom! Autoscroll.
|
|
40917
40928
|
scrollToBottom();
|
|
40918
40929
|
}
|
|
@@ -40922,12 +40933,6 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40922
40933
|
type: ActionType.ShowJumpToBottomButton,
|
|
40923
40934
|
});
|
|
40924
40935
|
}
|
|
40925
|
-
// Update last item ids
|
|
40926
|
-
lastItemIds.current = currentItemIds;
|
|
40927
|
-
// Remember if we were scrolled to the bottom before the update
|
|
40928
|
-
return () => {
|
|
40929
|
-
wasScrolledToBottomBeforeItemsUpdate.current = isScrolledToBottom();
|
|
40930
|
-
};
|
|
40931
40936
|
}, [items]);
|
|
40932
40937
|
/*------------------------------------------------------------------------*/
|
|
40933
40938
|
/* ------------------------------- Render ------------------------------- */
|
|
@@ -40948,11 +40953,14 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40948
40953
|
return (React__default.createElement("div", { className: "AutoscrollToBottomContainer-outer-container" },
|
|
40949
40954
|
React__default.createElement("style", null, style),
|
|
40950
40955
|
jumpToBottomButton,
|
|
40951
|
-
React__default.createElement("div", { className: "AutoscrollToBottomContainer-scrollable-container", onScroll: handleScroll, ref: container },
|
|
40952
|
-
|
|
40953
|
-
|
|
40954
|
-
|
|
40955
|
-
|
|
40956
|
+
React__default.createElement("div", { className: "AutoscrollToBottomContainer-scrollable-container", onScroll: handleScroll, ref: container },
|
|
40957
|
+
messageBeforeItems,
|
|
40958
|
+
items
|
|
40959
|
+
// Render each item with a key
|
|
40960
|
+
.map((item) => {
|
|
40961
|
+
return (React__default.createElement("div", { className: "AutoscrollToBottomContainer-item-container", key: item.id }, item.item));
|
|
40962
|
+
}),
|
|
40963
|
+
messageAfterItems)));
|
|
40956
40964
|
};
|
|
40957
40965
|
|
|
40958
40966
|
/**
|