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/cjs/index.js
CHANGED
|
@@ -40837,7 +40837,7 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40837
40837
|
/*------------------------------------------------------------------------*/
|
|
40838
40838
|
/* -------------- Props ------------- */
|
|
40839
40839
|
// Destructure all props
|
|
40840
|
-
const { itemsName, items, jumpToBottomButtonVariant = Variant$1.Danger, } = props;
|
|
40840
|
+
const { itemsName, items, jumpToBottomButtonVariant = Variant$1.Danger, messageBeforeItems, messageAfterItems, } = props;
|
|
40841
40841
|
/* -------------- State ------------- */
|
|
40842
40842
|
// Initial state
|
|
40843
40843
|
const initialState = {
|
|
@@ -40851,7 +40851,7 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40851
40851
|
// Initialize refs
|
|
40852
40852
|
const lastItemIds = React.useRef([]);
|
|
40853
40853
|
const container = React.useRef(null);
|
|
40854
|
-
const
|
|
40854
|
+
const wasLastScrolledToBottom = React.useRef(true);
|
|
40855
40855
|
/*------------------------------------------------------------------------*/
|
|
40856
40856
|
/* ------------------------- Component Functions ------------------------ */
|
|
40857
40857
|
/*------------------------------------------------------------------------*/
|
|
@@ -40874,7 +40874,10 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40874
40874
|
const rootFontSizePx = Number.parseInt(getComputedStyle(document.documentElement).fontSize, 10);
|
|
40875
40875
|
const distanceToBottomRems = Math.abs((scrollTop + clientHeight - scrollHeight) / rootFontSizePx);
|
|
40876
40876
|
// Figure out if we're scrolled to the bottom
|
|
40877
|
-
|
|
40877
|
+
const atBottom = (distanceToBottomRems < SCROLLED_TO_BOTTOM_THRESHOLD_REMS);
|
|
40878
|
+
// Remember if we scrolled to the bottom
|
|
40879
|
+
wasLastScrolledToBottom.current = atBottom;
|
|
40880
|
+
return atBottom;
|
|
40878
40881
|
};
|
|
40879
40882
|
/**
|
|
40880
40883
|
* Scroll the user to the bottom of the container
|
|
@@ -40890,7 +40893,10 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40890
40893
|
type: ActionType.HideJumpToBottomButton,
|
|
40891
40894
|
});
|
|
40892
40895
|
// Scroll to bottom
|
|
40893
|
-
container.current.scrollTop = container.current.scrollHeight
|
|
40896
|
+
container.current.scrollTop = (container.current.scrollHeight
|
|
40897
|
+
- container.current.clientHeight);
|
|
40898
|
+
// Remember that we scrolled to the bottom
|
|
40899
|
+
wasLastScrolledToBottom.current = true;
|
|
40894
40900
|
};
|
|
40895
40901
|
/*----------------------------------------*/
|
|
40896
40902
|
/* -------------- Handlers -------------- */
|
|
@@ -40904,8 +40910,9 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40904
40910
|
if (!container.current) {
|
|
40905
40911
|
return;
|
|
40906
40912
|
}
|
|
40907
|
-
// If scrolled to bottom, hide the button
|
|
40913
|
+
// If scrolled to bottom, hide the button and remember position
|
|
40908
40914
|
if (isScrolledToBottom()) {
|
|
40915
|
+
// Hide button
|
|
40909
40916
|
dispatch({
|
|
40910
40917
|
type: ActionType.HideJumpToBottomButton,
|
|
40911
40918
|
});
|
|
@@ -40930,15 +40937,19 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40930
40937
|
// Check if new content appeared
|
|
40931
40938
|
const currentItemIds = getItemIds(items);
|
|
40932
40939
|
// Check if new content appeared at bottom
|
|
40933
|
-
const newContentAppeared = (
|
|
40934
|
-
|
|
40935
|
-
|
|
40940
|
+
const newContentAppeared = (
|
|
40941
|
+
// There are items
|
|
40942
|
+
currentItemIds.length > 0
|
|
40943
|
+
// The last item is new
|
|
40944
|
+
&& !lastItemIds.current.includes(currentItemIds[currentItemIds.length - 1]));
|
|
40945
|
+
// Update last item ids
|
|
40946
|
+
lastItemIds.current = currentItemIds;
|
|
40936
40947
|
// Do nothing if no new content
|
|
40937
40948
|
if (!newContentAppeared) {
|
|
40938
40949
|
return;
|
|
40939
40950
|
}
|
|
40940
40951
|
// Check if used to be scrolled to the bottom
|
|
40941
|
-
if (
|
|
40952
|
+
if (wasLastScrolledToBottom.current) {
|
|
40942
40953
|
// Was scrolled to the bottom! Autoscroll.
|
|
40943
40954
|
scrollToBottom();
|
|
40944
40955
|
}
|
|
@@ -40948,12 +40959,6 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40948
40959
|
type: ActionType.ShowJumpToBottomButton,
|
|
40949
40960
|
});
|
|
40950
40961
|
}
|
|
40951
|
-
// Update last item ids
|
|
40952
|
-
lastItemIds.current = currentItemIds;
|
|
40953
|
-
// Remember if we were scrolled to the bottom before the update
|
|
40954
|
-
return () => {
|
|
40955
|
-
wasScrolledToBottomBeforeItemsUpdate.current = isScrolledToBottom();
|
|
40956
|
-
};
|
|
40957
40962
|
}, [items]);
|
|
40958
40963
|
/*------------------------------------------------------------------------*/
|
|
40959
40964
|
/* ------------------------------- Render ------------------------------- */
|
|
@@ -40974,11 +40979,14 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40974
40979
|
return (React__default["default"].createElement("div", { className: "AutoscrollToBottomContainer-outer-container" },
|
|
40975
40980
|
React__default["default"].createElement("style", null, style),
|
|
40976
40981
|
jumpToBottomButton,
|
|
40977
|
-
React__default["default"].createElement("div", { className: "AutoscrollToBottomContainer-scrollable-container", onScroll: handleScroll, ref: container },
|
|
40978
|
-
|
|
40979
|
-
|
|
40980
|
-
|
|
40981
|
-
|
|
40982
|
+
React__default["default"].createElement("div", { className: "AutoscrollToBottomContainer-scrollable-container", onScroll: handleScroll, ref: container },
|
|
40983
|
+
messageBeforeItems,
|
|
40984
|
+
items
|
|
40985
|
+
// Render each item with a key
|
|
40986
|
+
.map((item) => {
|
|
40987
|
+
return (React__default["default"].createElement("div", { className: "AutoscrollToBottomContainer-item-container", key: item.id }, item.item));
|
|
40988
|
+
}),
|
|
40989
|
+
messageAfterItems)));
|
|
40982
40990
|
};
|
|
40983
40991
|
|
|
40984
40992
|
/**
|