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 CHANGED
@@ -40750,17 +40750,11 @@ const style = `
40750
40750
 
40751
40751
  .AutoscrollToBottomContainer-scrollable-container {
40752
40752
  /* Take up max 100% height, don't take it up if not needed */
40753
- /* (so column-reverse layout doesn't start at the bottom) */
40754
40753
  max-height: 100%;
40755
40754
  overflow-y: auto;
40756
40755
 
40757
40756
  /* Allow children to position */
40758
40757
  position: relative;
40759
-
40760
- /* Reverse order of children so scroll starts at bottom */
40761
- /* (but children will have to be rendered in reverse order) */
40762
- display: flex;
40763
- flex-direction: column-reverse;
40764
40758
  }
40765
40759
 
40766
40760
  .AutoscrollToBottomContainer-jump-to-bottom-container {
@@ -40791,7 +40785,7 @@ const style = `
40791
40785
  /*------------------------------------------------------------------------*/
40792
40786
  // Scrolled to bottom threshold
40793
40787
  // (how close you have to be to the bottom for it to count as the bottom)
40794
- const SCROLLED_TO_BOTTOM_THRESHOLD_REMS = 2;
40788
+ const SCROLLED_TO_BOTTOM_THRESHOLD_REMS = 1.5;
40795
40789
  /*------------------------------------------------------------------------*/
40796
40790
  /* -------------------------- Static Functions -------------------------- */
40797
40791
  /*------------------------------------------------------------------------*/
@@ -40810,12 +40804,10 @@ const getItemIds = (items) => {
40810
40804
  // Types of actions
40811
40805
  var ActionType;
40812
40806
  (function (ActionType) {
40813
- // Identify that the user is now scrolled to the bottom
40814
- ActionType["NowScrolledToBottom"] = "NowScrolledToBottom";
40815
- // Identify that the user scrolled away from the bottom
40816
- ActionType["NowScrolledAwayFromBottom"] = "NowScrolledAwayFromBottom";
40817
- // Identify that new content appeared at the bottom but is not visible
40818
- ActionType["NewContentAtBottom"] = "NewContentAtBottom";
40807
+ // Hide the "jump to bottom" button
40808
+ ActionType["HideJumpToBottomButton"] = "HideJumpToBottomButton";
40809
+ // Show the "jump to bottom" button
40810
+ ActionType["ShowJumpToBottomButton"] = "ShowJumpToBottomButton";
40819
40811
  })(ActionType || (ActionType = {}));
40820
40812
  /**
40821
40813
  * Reducer that executes actions
@@ -40825,24 +40817,11 @@ var ActionType;
40825
40817
  */
40826
40818
  const reducer = (state, action) => {
40827
40819
  switch (action.type) {
40828
- case ActionType.NowScrolledToBottom: {
40829
- return Object.assign(Object.assign({}, state), {
40830
- // Store the event
40831
- wasScrolledToBottom: true,
40832
- // Hide the "jump to bottom" button
40833
- jumpToBottomButtonVisible: false });
40834
- }
40835
- case ActionType.NowScrolledAwayFromBottom: {
40836
- return Object.assign(Object.assign({}, state), {
40837
- // Store the event
40838
- wasScrolledToBottom: false });
40820
+ case ActionType.HideJumpToBottomButton: {
40821
+ return Object.assign(Object.assign({}, state), { jumpToBottomButtonVisible: false });
40839
40822
  }
40840
- case ActionType.NewContentAtBottom: {
40841
- return Object.assign(Object.assign({}, state), {
40842
- // Store the event
40843
- wasScrolledToBottom: false,
40844
- // Show the "jump to bottom" button
40845
- jumpToBottomButtonVisible: true });
40823
+ case ActionType.ShowJumpToBottomButton: {
40824
+ return Object.assign(Object.assign({}, state), { jumpToBottomButtonVisible: true });
40846
40825
  }
40847
40826
  default: {
40848
40827
  return state;
@@ -40862,17 +40841,17 @@ const AutoscrollToBottomContainer = (props) => {
40862
40841
  /* -------------- State ------------- */
40863
40842
  // Initial state
40864
40843
  const initialState = {
40865
- wasScrolledToBottom: true,
40866
40844
  jumpToBottomButtonVisible: false,
40867
40845
  };
40868
40846
  // Initialize state
40869
40847
  const [state, dispatch] = React.useReducer(reducer, initialState);
40870
40848
  // Destructure common state
40871
- const { wasScrolledToBottom, jumpToBottomButtonVisible, } = state;
40849
+ const { jumpToBottomButtonVisible, } = state;
40872
40850
  /* -------------- Refs -------------- */
40873
40851
  // Initialize refs
40874
40852
  const lastItemIds = React.useRef([]);
40875
40853
  const container = React.useRef(null);
40854
+ const wasScrolledToBottomBeforeItemsUpdate = React.useRef(true);
40876
40855
  /*------------------------------------------------------------------------*/
40877
40856
  /* ------------------------- Component Functions ------------------------ */
40878
40857
  /*------------------------------------------------------------------------*/
@@ -40890,10 +40869,10 @@ const AutoscrollToBottomContainer = (props) => {
40890
40869
  return true;
40891
40870
  }
40892
40871
  // Get info about container
40893
- const { scrollTop, } = container.current;
40872
+ const { scrollTop, scrollHeight, clientHeight, } = container.current;
40894
40873
  // Distance to bottom
40895
40874
  const rootFontSizePx = Number.parseInt(getComputedStyle(document.documentElement).fontSize, 10);
40896
- const distanceToBottomRems = Math.abs(scrollTop / rootFontSizePx);
40875
+ const distanceToBottomRems = Math.abs((scrollTop + clientHeight - scrollHeight) / rootFontSizePx);
40897
40876
  // Figure out if we're scrolled to the bottom
40898
40877
  return (distanceToBottomRems < SCROLLED_TO_BOTTOM_THRESHOLD_REMS);
40899
40878
  };
@@ -40908,10 +40887,10 @@ const AutoscrollToBottomContainer = (props) => {
40908
40887
  }
40909
40888
  // Update state
40910
40889
  dispatch({
40911
- type: ActionType.NowScrolledToBottom,
40890
+ type: ActionType.HideJumpToBottomButton,
40912
40891
  });
40913
40892
  // Scroll to bottom
40914
- container.current.scrollTop = 0;
40893
+ container.current.scrollTop = container.current.scrollHeight;
40915
40894
  };
40916
40895
  /*----------------------------------------*/
40917
40896
  /* -------------- Handlers -------------- */
@@ -40925,17 +40904,10 @@ const AutoscrollToBottomContainer = (props) => {
40925
40904
  if (!container.current) {
40926
40905
  return;
40927
40906
  }
40928
- // Check if now scrolled to bottom
40929
- const nowScrolledToBottom = isScrolledToBottom();
40930
- // Remember if now no longer scrolled to bottom
40931
- if (nowScrolledToBottom) {
40907
+ // If scrolled to bottom, hide the button
40908
+ if (isScrolledToBottom()) {
40932
40909
  dispatch({
40933
- type: ActionType.NowScrolledToBottom,
40934
- });
40935
- }
40936
- else {
40937
- dispatch({
40938
- type: ActionType.NowScrolledAwayFromBottom,
40910
+ type: ActionType.HideJumpToBottomButton,
40939
40911
  });
40940
40912
  }
40941
40913
  };
@@ -40951,33 +40923,37 @@ const AutoscrollToBottomContainer = (props) => {
40951
40923
  scrollToBottom();
40952
40924
  }, []);
40953
40925
  /**
40954
- * Update (also called on mount)
40926
+ * Update (also called on mount): autoscroll
40955
40927
  * @author Gabe Abrams
40956
40928
  */
40957
40929
  React.useEffect(() => {
40958
40930
  // Check if new content appeared
40959
40931
  const currentItemIds = getItemIds(items);
40960
40932
  // Check if new content appeared at bottom
40961
- const newContentAtBottom = (currentItemIds.length > 0
40933
+ const newContentAppeared = (currentItemIds.length > 0
40962
40934
  && (currentItemIds[currentItemIds.length - 1]
40963
40935
  !== lastItemIds.current[lastItemIds.current.length - 1]));
40964
40936
  // Do nothing if no new content
40965
- if (!newContentAtBottom) {
40937
+ if (!newContentAppeared) {
40966
40938
  return;
40967
40939
  }
40968
40940
  // Check if used to be scrolled to the bottom
40969
- if (wasScrolledToBottom) {
40941
+ if (wasScrolledToBottomBeforeItemsUpdate.current) {
40970
40942
  // Was scrolled to the bottom! Autoscroll.
40971
40943
  scrollToBottom();
40972
40944
  }
40973
40945
  else {
40974
40946
  // Not scrolled to bottom. Show "jump to bottom" button.
40975
40947
  dispatch({
40976
- type: ActionType.NewContentAtBottom,
40948
+ type: ActionType.ShowJumpToBottomButton,
40977
40949
  });
40978
40950
  }
40979
40951
  // Update last item ids
40980
40952
  lastItemIds.current = currentItemIds;
40953
+ // Remember if we were scrolled to the bottom before the update
40954
+ return () => {
40955
+ wasScrolledToBottomBeforeItemsUpdate.current = isScrolledToBottom();
40956
+ };
40981
40957
  }, [items]);
40982
40958
  /*------------------------------------------------------------------------*/
40983
40959
  /* ------------------------------- Render ------------------------------- */
@@ -40998,15 +40974,11 @@ const AutoscrollToBottomContainer = (props) => {
40998
40974
  return (React__default["default"].createElement("div", { className: "AutoscrollToBottomContainer-outer-container" },
40999
40975
  React__default["default"].createElement("style", null, style),
41000
40976
  jumpToBottomButton,
41001
- React__default["default"].createElement("div", { className: "AutoscrollToBottomContainer-scrollable-container", onScroll: () => {
41002
- handleScroll();
41003
- }, ref: container }, items
40977
+ React__default["default"].createElement("div", { className: "AutoscrollToBottomContainer-scrollable-container", onScroll: handleScroll, ref: container }, items
41004
40978
  // Render each item with a key
41005
40979
  .map((item) => {
41006
40980
  return (React__default["default"].createElement("div", { className: "AutoscrollToBottomContainer-item-container", key: item.id }, item.item));
41007
- })
41008
- // Reverse order because flex column is reverse
41009
- .reverse())));
40981
+ }))));
41010
40982
  };
41011
40983
 
41012
40984
  /**