@verifiedinc-public/shared-ui-elements 12.27.1-rc.117 → 12.28.0
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.
|
@@ -39,7 +39,7 @@ interface UseBidirectionalScrollOptions {
|
|
|
39
39
|
/**
|
|
40
40
|
* Manages bidirectional infinite scroll for a virtualised, reverse-chronological list.
|
|
41
41
|
*
|
|
42
|
-
* - Triggers `onLoadNewer` when the user scrolls to the top.
|
|
42
|
+
* - Triggers `onLoadNewer` when the user scrolls to the top, or pulls past it while already there.
|
|
43
43
|
* - Triggers `onLoadOlder` when the user scrolls to the bottom.
|
|
44
44
|
* - Preserves the scroll position when newer rows are prepended so the
|
|
45
45
|
* viewport doesn't jump.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useRef as
|
|
1
|
+
"use strict";import{useRef as t,useEffect as T,useLayoutEffect as M}from"react";import F from"lodash/debounce";function P({enabled:u=!0,scrollContainerRef:n,virtualizer:w,rowCount:J,hasNewer:H,hasOlder:O,isLoadingNewer:s,isLoadingOlder:y,onLoadNewer:N,onLoadOlder:b,debounceMs:L=300,rearmDistance:g=100,resetKey:K}){const a=t(null),p=t(!1),d=t(!1);T(()=>{if(!u)return;const e=n.current;e&&(e.scrollTop=0),a.current=null,p.current=!1,d.current=!1},[u,K,n]),T(()=>{if(u){if(s&&!p.current){const e=n.current;e&&(a.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop})}p.current=!!s}},[u,s,n]),M(()=>{const e=n.current,o=a.current;if(e&&o){const l=e.scrollHeight-o.scrollHeight;l>0&&(e.scrollTop=o.scrollTop+l),a.current=null,w.measure()}},[J,w,n]);const E=t(O),v=t(H),m=t(y),h=t(s),x=t(b),B=t(N);E.current=O,v.current=H,m.current=y,h.current=s,x.current=b,B.current=N,T(()=>{if(!u)return;const e=n.current;if(!e)return;let o=!1;const l=F(()=>{v.current&&!h.current&&B.current()},L,{leading:!0,trailing:!1}),C=F(()=>{E.current&&!m.current&&x.current()},L,{leading:!0,trailing:!1}),Y=()=>{const{scrollTop:r,scrollHeight:c,clientHeight:i}=e,D=c-r-i;c<=i||(r>g&&(o=!0),D>g&&(d.current=!0),o&&v.current&&!h.current&&r<=1&&(o=!1,l()),d.current&&E.current&&!m.current&&D<=1&&(d.current=!1,C()))},j=()=>e.scrollTop<=1&&v.current&&!h.current,k=r=>{r.deltaY<0&&j()&&l()};let f=null;const q=r=>{var c;f=((c=r.touches[0])==null?void 0:c.clientY)??null},z=r=>{var c;const i=(c=r.touches[0])==null?void 0:c.clientY;f!==null&&i!==void 0&&i>f&&j()&&(f=null,l())};return e.addEventListener("scroll",Y,{passive:!0}),e.addEventListener("wheel",k,{passive:!0}),e.addEventListener("touchstart",q,{passive:!0}),e.addEventListener("touchmove",z,{passive:!0}),()=>{e.removeEventListener("scroll",Y),e.removeEventListener("wheel",k),e.removeEventListener("touchstart",q),e.removeEventListener("touchmove",z),l.cancel(),C.cancel()}},[u,n,L,g])}export{P as useBidirectionalScroll};
|
package/package.json
CHANGED