dce-reactkit 3.5.7 → 3.5.9
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 +29 -57
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +29 -57
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AutoscrollToBottomContainer.tsx +31 -58
package/dist/esm/index.js
CHANGED
|
@@ -40724,17 +40724,11 @@ const style = `
|
|
|
40724
40724
|
|
|
40725
40725
|
.AutoscrollToBottomContainer-scrollable-container {
|
|
40726
40726
|
/* Take up max 100% height, don't take it up if not needed */
|
|
40727
|
-
/* (so column-reverse layout doesn't start at the bottom) */
|
|
40728
40727
|
max-height: 100%;
|
|
40729
40728
|
overflow-y: auto;
|
|
40730
40729
|
|
|
40731
40730
|
/* Allow children to position */
|
|
40732
40731
|
position: relative;
|
|
40733
|
-
|
|
40734
|
-
/* Reverse order of children so scroll starts at bottom */
|
|
40735
|
-
/* (but children will have to be rendered in reverse order) */
|
|
40736
|
-
display: flex;
|
|
40737
|
-
flex-direction: column-reverse;
|
|
40738
40732
|
}
|
|
40739
40733
|
|
|
40740
40734
|
.AutoscrollToBottomContainer-jump-to-bottom-container {
|
|
@@ -40765,7 +40759,7 @@ const style = `
|
|
|
40765
40759
|
/*------------------------------------------------------------------------*/
|
|
40766
40760
|
// Scrolled to bottom threshold
|
|
40767
40761
|
// (how close you have to be to the bottom for it to count as the bottom)
|
|
40768
|
-
const SCROLLED_TO_BOTTOM_THRESHOLD_REMS =
|
|
40762
|
+
const SCROLLED_TO_BOTTOM_THRESHOLD_REMS = 1.5;
|
|
40769
40763
|
/*------------------------------------------------------------------------*/
|
|
40770
40764
|
/* -------------------------- Static Functions -------------------------- */
|
|
40771
40765
|
/*------------------------------------------------------------------------*/
|
|
@@ -40784,12 +40778,10 @@ const getItemIds = (items) => {
|
|
|
40784
40778
|
// Types of actions
|
|
40785
40779
|
var ActionType;
|
|
40786
40780
|
(function (ActionType) {
|
|
40787
|
-
//
|
|
40788
|
-
ActionType["
|
|
40789
|
-
//
|
|
40790
|
-
ActionType["
|
|
40791
|
-
// Identify that new content appeared at the bottom but is not visible
|
|
40792
|
-
ActionType["NewContentAtBottom"] = "NewContentAtBottom";
|
|
40781
|
+
// Hide the "jump to bottom" button
|
|
40782
|
+
ActionType["HideJumpToBottomButton"] = "HideJumpToBottomButton";
|
|
40783
|
+
// Show the "jump to bottom" button
|
|
40784
|
+
ActionType["ShowJumpToBottomButton"] = "ShowJumpToBottomButton";
|
|
40793
40785
|
})(ActionType || (ActionType = {}));
|
|
40794
40786
|
/**
|
|
40795
40787
|
* Reducer that executes actions
|
|
@@ -40799,24 +40791,11 @@ var ActionType;
|
|
|
40799
40791
|
*/
|
|
40800
40792
|
const reducer = (state, action) => {
|
|
40801
40793
|
switch (action.type) {
|
|
40802
|
-
case ActionType.
|
|
40803
|
-
return Object.assign(Object.assign({}, state), {
|
|
40804
|
-
// Store the event
|
|
40805
|
-
wasScrolledToBottom: true,
|
|
40806
|
-
// Hide the "jump to bottom" button
|
|
40807
|
-
jumpToBottomButtonVisible: false });
|
|
40808
|
-
}
|
|
40809
|
-
case ActionType.NowScrolledAwayFromBottom: {
|
|
40810
|
-
return Object.assign(Object.assign({}, state), {
|
|
40811
|
-
// Store the event
|
|
40812
|
-
wasScrolledToBottom: false });
|
|
40794
|
+
case ActionType.HideJumpToBottomButton: {
|
|
40795
|
+
return Object.assign(Object.assign({}, state), { jumpToBottomButtonVisible: false });
|
|
40813
40796
|
}
|
|
40814
|
-
case ActionType.
|
|
40815
|
-
return Object.assign(Object.assign({}, state), {
|
|
40816
|
-
// Store the event
|
|
40817
|
-
wasScrolledToBottom: false,
|
|
40818
|
-
// Show the "jump to bottom" button
|
|
40819
|
-
jumpToBottomButtonVisible: true });
|
|
40797
|
+
case ActionType.ShowJumpToBottomButton: {
|
|
40798
|
+
return Object.assign(Object.assign({}, state), { jumpToBottomButtonVisible: true });
|
|
40820
40799
|
}
|
|
40821
40800
|
default: {
|
|
40822
40801
|
return state;
|
|
@@ -40836,17 +40815,17 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40836
40815
|
/* -------------- State ------------- */
|
|
40837
40816
|
// Initial state
|
|
40838
40817
|
const initialState = {
|
|
40839
|
-
wasScrolledToBottom: true,
|
|
40840
40818
|
jumpToBottomButtonVisible: false,
|
|
40841
40819
|
};
|
|
40842
40820
|
// Initialize state
|
|
40843
40821
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
40844
40822
|
// Destructure common state
|
|
40845
|
-
const {
|
|
40823
|
+
const { jumpToBottomButtonVisible, } = state;
|
|
40846
40824
|
/* -------------- Refs -------------- */
|
|
40847
40825
|
// Initialize refs
|
|
40848
40826
|
const lastItemIds = useRef([]);
|
|
40849
40827
|
const container = useRef(null);
|
|
40828
|
+
const wasScrolledToBottomBeforeItemsUpdate = useRef(true);
|
|
40850
40829
|
/*------------------------------------------------------------------------*/
|
|
40851
40830
|
/* ------------------------- Component Functions ------------------------ */
|
|
40852
40831
|
/*------------------------------------------------------------------------*/
|
|
@@ -40864,10 +40843,10 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40864
40843
|
return true;
|
|
40865
40844
|
}
|
|
40866
40845
|
// Get info about container
|
|
40867
|
-
const { scrollTop, } = container.current;
|
|
40846
|
+
const { scrollTop, scrollHeight, clientHeight, } = container.current;
|
|
40868
40847
|
// Distance to bottom
|
|
40869
40848
|
const rootFontSizePx = Number.parseInt(getComputedStyle(document.documentElement).fontSize, 10);
|
|
40870
|
-
const distanceToBottomRems = Math.abs(scrollTop / rootFontSizePx);
|
|
40849
|
+
const distanceToBottomRems = Math.abs((scrollTop + clientHeight - scrollHeight) / rootFontSizePx);
|
|
40871
40850
|
// Figure out if we're scrolled to the bottom
|
|
40872
40851
|
return (distanceToBottomRems < SCROLLED_TO_BOTTOM_THRESHOLD_REMS);
|
|
40873
40852
|
};
|
|
@@ -40882,10 +40861,10 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40882
40861
|
}
|
|
40883
40862
|
// Update state
|
|
40884
40863
|
dispatch({
|
|
40885
|
-
type: ActionType.
|
|
40864
|
+
type: ActionType.HideJumpToBottomButton,
|
|
40886
40865
|
});
|
|
40887
40866
|
// Scroll to bottom
|
|
40888
|
-
container.current.scrollTop =
|
|
40867
|
+
container.current.scrollTop = container.current.scrollHeight;
|
|
40889
40868
|
};
|
|
40890
40869
|
/*----------------------------------------*/
|
|
40891
40870
|
/* -------------- Handlers -------------- */
|
|
@@ -40899,17 +40878,10 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40899
40878
|
if (!container.current) {
|
|
40900
40879
|
return;
|
|
40901
40880
|
}
|
|
40902
|
-
//
|
|
40903
|
-
|
|
40904
|
-
// Remember if now no longer scrolled to bottom
|
|
40905
|
-
if (nowScrolledToBottom) {
|
|
40881
|
+
// If scrolled to bottom, hide the button
|
|
40882
|
+
if (isScrolledToBottom()) {
|
|
40906
40883
|
dispatch({
|
|
40907
|
-
type: ActionType.
|
|
40908
|
-
});
|
|
40909
|
-
}
|
|
40910
|
-
else {
|
|
40911
|
-
dispatch({
|
|
40912
|
-
type: ActionType.NowScrolledAwayFromBottom,
|
|
40884
|
+
type: ActionType.HideJumpToBottomButton,
|
|
40913
40885
|
});
|
|
40914
40886
|
}
|
|
40915
40887
|
};
|
|
@@ -40925,33 +40897,37 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40925
40897
|
scrollToBottom();
|
|
40926
40898
|
}, []);
|
|
40927
40899
|
/**
|
|
40928
|
-
* Update (also called on mount)
|
|
40900
|
+
* Update (also called on mount): autoscroll
|
|
40929
40901
|
* @author Gabe Abrams
|
|
40930
40902
|
*/
|
|
40931
40903
|
useEffect(() => {
|
|
40932
40904
|
// Check if new content appeared
|
|
40933
40905
|
const currentItemIds = getItemIds(items);
|
|
40934
40906
|
// Check if new content appeared at bottom
|
|
40935
|
-
const
|
|
40907
|
+
const newContentAppeared = (currentItemIds.length > 0
|
|
40936
40908
|
&& (currentItemIds[currentItemIds.length - 1]
|
|
40937
40909
|
!== lastItemIds.current[lastItemIds.current.length - 1]));
|
|
40938
40910
|
// Do nothing if no new content
|
|
40939
|
-
if (!
|
|
40911
|
+
if (!newContentAppeared) {
|
|
40940
40912
|
return;
|
|
40941
40913
|
}
|
|
40942
40914
|
// Check if used to be scrolled to the bottom
|
|
40943
|
-
if (
|
|
40915
|
+
if (wasScrolledToBottomBeforeItemsUpdate.current) {
|
|
40944
40916
|
// Was scrolled to the bottom! Autoscroll.
|
|
40945
40917
|
scrollToBottom();
|
|
40946
40918
|
}
|
|
40947
40919
|
else {
|
|
40948
40920
|
// Not scrolled to bottom. Show "jump to bottom" button.
|
|
40949
40921
|
dispatch({
|
|
40950
|
-
type: ActionType.
|
|
40922
|
+
type: ActionType.ShowJumpToBottomButton,
|
|
40951
40923
|
});
|
|
40952
40924
|
}
|
|
40953
40925
|
// Update last item ids
|
|
40954
40926
|
lastItemIds.current = currentItemIds;
|
|
40927
|
+
// Remember if we were scrolled to the bottom before the update
|
|
40928
|
+
return () => {
|
|
40929
|
+
wasScrolledToBottomBeforeItemsUpdate.current = isScrolledToBottom();
|
|
40930
|
+
};
|
|
40955
40931
|
}, [items]);
|
|
40956
40932
|
/*------------------------------------------------------------------------*/
|
|
40957
40933
|
/* ------------------------------- Render ------------------------------- */
|
|
@@ -40972,15 +40948,11 @@ const AutoscrollToBottomContainer = (props) => {
|
|
|
40972
40948
|
return (React__default.createElement("div", { className: "AutoscrollToBottomContainer-outer-container" },
|
|
40973
40949
|
React__default.createElement("style", null, style),
|
|
40974
40950
|
jumpToBottomButton,
|
|
40975
|
-
React__default.createElement("div", { className: "AutoscrollToBottomContainer-scrollable-container", onScroll:
|
|
40976
|
-
handleScroll();
|
|
40977
|
-
}, ref: container }, items
|
|
40951
|
+
React__default.createElement("div", { className: "AutoscrollToBottomContainer-scrollable-container", onScroll: handleScroll, ref: container }, items
|
|
40978
40952
|
// Render each item with a key
|
|
40979
40953
|
.map((item) => {
|
|
40980
40954
|
return (React__default.createElement("div", { className: "AutoscrollToBottomContainer-item-container", key: item.id }, item.item));
|
|
40981
|
-
})
|
|
40982
|
-
// Reverse order because flex column is reverse
|
|
40983
|
-
.reverse())));
|
|
40955
|
+
}))));
|
|
40984
40956
|
};
|
|
40985
40957
|
|
|
40986
40958
|
/**
|