react-anchorlist 0.2.4 → 0.2.5
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/hooks/useVirtualEngine.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +235 -229
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVirtualEngine.d.ts","sourceRoot":"","sources":["../../src/hooks/useVirtualEngine.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAe,MAAM,UAAU,CAAA;AAEnE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE;IAC3C,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACnD,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,KAAK,GAAG,QAAQ,CAAA;CACnC,GAAG,sBAAsB,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"useVirtualEngine.d.ts","sourceRoot":"","sources":["../../src/hooks/useVirtualEngine.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAe,MAAM,UAAU,CAAA;AAEnE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE;IAC3C,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACnD,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,KAAK,GAAG,QAAQ,CAAA;CACnC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAsQ5B"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),r=require("react");function $(o){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>o[t]})}}return e.default=o,Object.freeze(e)}const D=$(r);class G{constructor(e,t){this.defaultSize=t,this.sizes=e>0?Array(e).fill(t):[],this.offsets=e>0?Array(e).fill(0):[],e>0&&this._recalcFrom(0)}_recalcFrom(e){for(let t=e;t<this.sizes.length;t++)this.offsets[t]=t===0?0:(this.offsets[t-1]??0)+(this.sizes[t-1]??this.defaultSize)}getOffset(e){return this.offsets[e]??0}getSize(e){return this.sizes[e]??this.defaultSize}setSize(e,t){return this.sizes[e]===t?!1:(this.sizes[e]=t,this._recalcFrom(e+1),!0)}prepend(e){const t=Array(e).fill(this.defaultSize);this.sizes=[...t,...this.sizes],this.offsets=Array(this.sizes.length).fill(0),this._recalcFrom(0)}append(e){const t=this.sizes.length;for(let n=0;n<e;n++)this.sizes.push(this.defaultSize),this.offsets.push(0);this._recalcFrom(t)}resize(e){const t=this.sizes.length;e>t?this.append(e-t):e<t&&(this.sizes=this.sizes.slice(0,e),this.offsets=this.offsets.slice(0,e))}totalSize(){if(this.sizes.length===0)return 0;const e=this.sizes.length-1;return(this.offsets[e]??0)+(this.sizes[e]??this.defaultSize)}get count(){return this.sizes.length}getOffsets(){return this.offsets}getSizes(){return this.sizes}}class J{constructor(){this.cache=new Map}get(e){return this.cache.get(e)}set(e,t){this.cache.set(e,t)}has(e){return this.cache.has(e)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}applyToOffsetMap(e,t){for(const[n,l]of this.cache){const i=t.get(n);i!==void 0&&e.setSize(i,l)}}}function Q(o,e){if(o.length===0)return 0;let t=0,n=o.length-1;for(;t<n;){const l=t+n>>1;(o[l]??0)<e?t=l+1:n=l}return Math.max(0,t>0&&(o[t]??0)>e?t-1:t)}function W(o,e,t){if(o.length===0)return 0;for(let n=o.length-1;n>=0;n--)if((o[n]??0)<t)return n;return 0}function Z(o){const{firstVisible:e,lastVisible:t,itemCount:n,overscan:l}=o;return n===0?{start:0,end:-1}:{start:Math.max(0,e-l),end:Math.min(n-1,t+l)}}function ee(o,e,t){return r.useCallback((n,l)=>{var H;const i=o.current,c=e.current;if(!i||!c)return;let m,f;if(typeof n=="object"&&n!==null?(m=n.index,f={align:n.align,behavior:n.behavior,offset:n.offset}):(m=n,f=l),!Number.isFinite(m))return;const d=Math.max(0,Math.min(Math.floor(m),c.count-1)),g=((H=t==null?void 0:t.current)==null?void 0:H.offsetTop)??0,z=c.getOffset(d),S=c.getSize(d),T=(f==null?void 0:f.align)??"start",h=(f==null?void 0:f.behavior)??"auto",F=(f==null?void 0:f.offset)??0;let y;T==="start"?y=g+z+F:T==="center"?y=g+z-i.clientHeight/2+S/2+F:y=g+z-i.clientHeight+S+F,i.scrollTo({top:Math.max(0,y),behavior:h})},[o,e,t])}function Y(o){var N;const{items:e,getKey:t,estimatedItemSize:n,overscan:l,initialAlignment:i}=o,c=r.useRef(null),m=r.useRef(null),f=r.useRef(null),d=r.useRef(new J),g=r.useRef([]),z=r.useRef(!1),S=r.useRef(0),T=r.useRef(0),h=r.useRef(null),F=r.useRef(!1),y=r.useRef(null),[,H]=r.useState(0),v=r.useCallback(()=>H(s=>s+1),[]);f.current||(f.current=new G(e.length,n));const P=r.useRef(e.length);if(e.length!==P.current||e.some((s,R)=>{const C=t(s,R);return g.current[R]!==C})){const s=f.current,R=e.map((O,q)=>t(O,q)),C=g.current,b=C.length,E=R.length;E===0?s.resize(0):b===0?s.resize(E):E>b?C.length>0&&R[E-b]===C[0]?s.prepend(E-b):s.resize(E):E<b&&s.resize(E);const k=new Map;R.forEach((O,q)=>k.set(O,q)),d.current.applyToOffsetMap(s,k),g.current=R,P.current=e.length}r.useEffect(()=>{const s=c.current;if(!s)return;const R=()=>{h.current===null&&(h.current=requestAnimationFrame(()=>{h.current=null,S.current=s.scrollTop,T.current=s.clientHeight,v()}))};return s.addEventListener("scroll",R,{passive:!0}),()=>{s.removeEventListener("scroll",R),h.current!==null&&(cancelAnimationFrame(h.current),h.current=null)}},[v]),r.useEffect(()=>{const s=c.current;if(!s)return;T.current=s.clientHeight,S.current=s.scrollTop;const R=new ResizeObserver(([C])=>{C&&(T.current=C.contentRect.height,v())});return R.observe(s),()=>R.disconnect()},[v]),r.useLayoutEffect(()=>{if(z.current||e.length===0)return;const s=c.current;if(s){if(i==="bottom"){s.scrollTop=s.scrollHeight,S.current=s.scrollTop,T.current=s.clientHeight,F.current=!0,y.current!==null&&cancelAnimationFrame(y.current);let R=0;const C=30,b=()=>{if(!F.current||R>=C){F.current=!1,y.current=null;return}R++,s.scrollTop=s.scrollHeight,S.current=s.scrollTop,y.current=requestAnimationFrame(b)};y.current=requestAnimationFrame(b)}z.current=!0}},[i,e.length]),r.useEffect(()=>{e.length===0&&(z.current=!1,F.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null))},[e.length]);const w=r.useCallback((s,R)=>{const C=f.current;if(!C||d.current.get(s)===R)return;d.current.set(s,R);const E=g.current.indexOf(s);if(E===-1)return;C.setSize(E,R)&&v()},[v]),L=r.useCallback((s,R="auto")=>{var C;(C=c.current)==null||C.scrollTo({top:s,behavior:R})},[]),B=ee(c,f,m),I=f.current,V=I?I.totalSize():0,a=c.current,u=(a==null?void 0:a.scrollTop)??S.current,p=(a==null?void 0:a.clientHeight)??T.current,x=((N=m.current)==null?void 0:N.offsetTop)??0,K=Math.max(0,u-x);let j=[];if(I&&I.count>0&&p>0){const s=I.getOffsets(),R=I.getSizes(),C=Q(s,K),b=W(s,R,K+p),E=Z({firstVisible:C,lastVisible:b,itemCount:I.count,overscan:l});for(let k=E.start;k<=E.end&&k<e.length;k++)j.push({key:g.current[k]??t(e[k],k),index:k,start:I.getOffset(k),size:I.getSize(k),data:e[k]})}else if(I&&I.count>0){const s=Math.min(e.length,l*2+1),R=i==="bottom"?Math.max(0,e.length-s):0,C=R+s-1;for(let b=R;b<=C;b++)j.push({key:g.current[b]??t(e[b],b),index:b,start:I.getOffset(b),size:I.getSize(b),data:e[b]})}const _=a?a.scrollHeight-a.scrollTop-a.clientHeight:1/0;return{scrollerRef:c,innerRef:m,virtualItems:j,totalSize:V,measureItem:w,scrollToIndex:B,scrollToOffset:L,isAtTop:u<=1,isAtBottom:_<=1,scrollTop:u}}function te(o,e,t){const n=r.useRef(0),l=r.useRef(0),i=r.useRef(!1),c=r.useRef({first:null,second:null,timeout:null}),m=r.useCallback(()=>{const{first:d,second:g,timeout:z}=c.current;d&&cancelAnimationFrame(d),g&&cancelAnimationFrame(g),z&&clearTimeout(z),c.current={first:null,second:null,timeout:null}},[]),f=r.useCallback(()=>{const d=o.current;d&&(n.current=d.scrollTop,l.current=d.scrollHeight,i.current=!0)},[o]);return r.useLayoutEffect(()=>{if(!i.current)return;const d=o.current;if(!d)return;i.current=!1;const g=()=>{const z=n.current+(d.scrollHeight-l.current);Number.isFinite(z)&&Math.abs(d.scrollTop-z)>1&&(d.scrollTop=z)};return m(),g(),t==null||t(),c.current.first=requestAnimationFrame(()=>{c.current.first=null,g(),c.current.second=requestAnimationFrame(()=>{c.current.second=null,g()})}),c.current.timeout=setTimeout(()=>{c.current.timeout=null,g()},90),()=>m()},[e,o,m,t]),{prepareAnchor:f}}function re(o,e){const[t,n]=r.useState(!0),l=r.useRef(null);return r.useEffect(()=>{const i=o.current;if(!i)return;const c=()=>{const f=i.scrollHeight-i.scrollTop-i.clientHeight;n(f<=e)},m=()=>{l.current!==null&&cancelAnimationFrame(l.current),l.current=requestAnimationFrame(c)};return i.addEventListener("scroll",m,{passive:!0}),c(),()=>{i.removeEventListener("scroll",m),l.current!==null&&cancelAnimationFrame(l.current)}},[o,e]),t}function ne(o){const{itemCount:e,firstKey:t,lastKey:n,isAtBottom:l,scrollToIndex:i,mode:c}=o,m=r.useRef(e),f=r.useRef(t),d=r.useRef(n);r.useLayoutEffect(()=>{if(!c){m.current=e,f.current=t,d.current=n;return}const g=m.current,z=f.current,S=d.current;e>g&&t===z&&n!==S&&l&&e>0&&i(e-1,{align:"end",behavior:c==="smooth"?"smooth":"auto"}),m.current=e,f.current=t,d.current=n},[e,t,n,l,i,c])}function U(o){const{items:e,getKey:t,estimatedItemSize:n=80,overscan:l=20,atBottomThreshold:i=200,followOutput:c="auto",initialAlignment:m="bottom",onStartReached:f,onEndReached:d,startReachedThreshold:g=300,endReachedThreshold:z=300,scrollToMessageKey:S,onScrollToMessageComplete:T}=o,h=Y({items:e,getKey:t,estimatedItemSize:n,overscan:l,initialAlignment:m}),F=re(h.scrollerRef,i),[,y]=r.useState(0),H=r.useCallback(()=>y(u=>u+1),[]),{prepareAnchor:v}=te(h.scrollerRef,e.length,H),P=e.length>0?t(e[0],0):null,A=e.length>0?t(e[e.length-1],e.length-1):null;ne({itemCount:e.length,firstKey:P,lastKey:A,isAtBottom:F,scrollToIndex:h.scrollToIndex,mode:c??!1});const w=r.useRef(!1),L=r.useRef(m==="top");r.useEffect(()=>{const u=h.scrollerRef.current;if(!u||!f)return;const p=()=>{const x=u.scrollTop;!L.current&&x>g&&(L.current=!0),L.current&&x<=g&&!w.current&&(w.current=!0,Promise.resolve(f()).finally(()=>{w.current=!1}))};return u.addEventListener("scroll",p,{passive:!0}),()=>u.removeEventListener("scroll",p)},[h.scrollerRef,f,g,m]);const B=r.useRef(!1);r.useEffect(()=>{const u=h.scrollerRef.current;if(!u||!d)return;const p=()=>{u.scrollHeight-u.scrollTop-u.clientHeight<=z&&!B.current&&(B.current=!0,Promise.resolve(d()).finally(()=>{B.current=!1}))};return u.addEventListener("scroll",p,{passive:!0}),()=>u.removeEventListener("scroll",p)},[h.scrollerRef,d,z]);const I=r.useRef(null);r.useEffect(()=>{if(!S||I.current===S)return;const u=e.findIndex((p,x)=>t(p,x)===S);u!==-1&&(I.current=S,h.scrollToIndex(u,{align:"center",behavior:"smooth"}),T==null||T())},[S,e,t,h,T]);const V=r.useCallback((u="auto")=>{e.length!==0&&h.scrollToIndex(e.length-1,{align:"end",behavior:u})},[e.length,h]),a=r.useCallback((u,p)=>{const x=e.findIndex((K,j)=>t(K,j)===u);x!==-1&&h.scrollToIndex(x,p)},[e,t,h]);return{scrollerRef:h.scrollerRef,innerRef:h.innerRef,virtualItems:h.virtualItems,totalSize:h.totalSize,measureItem:h.measureItem,scrollToIndex:h.scrollToIndex,scrollToBottom:V,scrollToKey:a,isAtBottom:F,prepareAnchor:v}}function X({virtualItem:o,measureItem:e,children:t}){const n=r.useRef(null),l=r.useRef(!1);return r.useEffect(()=>{const i=n.current;if(!i)return;l.current=!1;const c=new ResizeObserver(([m])=>{m&&(l.current=!0,e(o.key,m.contentRect.height))});return c.observe(i),()=>c.disconnect()},[o.key,e]),M.jsx("div",{ref:n,style:{position:"absolute",top:0,transform:`translateY(${o.start}px)`,width:"100%",minHeight:l.current?void 0:o.size},children:t})}function se(o,e){const{data:t,itemContent:n,computeItemKey:l,estimatedItemSize:i=80,overscan:c=20,followOutput:m="auto",atBottomThreshold:f=200,initialAlignment:d="bottom",onStartReached:g,onEndReached:z,startReachedThreshold:S=300,endReachedThreshold:T=300,scrollToMessageKey:h,onScrollToMessageComplete:F,onAtBottomChange:y,components:H={},className:v,style:P}=o,{scrollerRef:A,innerRef:w,virtualItems:L,totalSize:B,measureItem:I,scrollToIndex:V,scrollToBottom:a,scrollToKey:u,isAtBottom:p,prepareAnchor:x}=U({items:t,getKey:(s,R)=>l(R,s),estimatedItemSize:i,overscan:c,atBottomThreshold:f,followOutput:m,initialAlignment:d,onStartReached:g,onEndReached:z,startReachedThreshold:S,endReachedThreshold:T,scrollToMessageKey:h,onScrollToMessageComplete:F}),K=D.useRef(p);D.useEffect(()=>{K.current!==p&&(K.current=p,y==null||y(p))},[p,y]),r.useImperativeHandle(e,()=>({scrollToBottom:a,scrollToIndex:V,scrollToKey:u,getScrollTop:()=>{var s;return((s=A.current)==null?void 0:s.scrollTop)??0},isAtBottom:()=>p,prepareAnchor:x}),[a,V,u,A,p,x]);const{Header:j,Footer:_,EmptyPlaceholder:N}=H;return t.length===0&&N?M.jsx(N,{}):M.jsxs("div",{ref:A,className:v,style:{overflow:"auto",height:"100%",position:"relative",overscrollBehaviorY:"contain",...P},children:[j&&M.jsx(j,{}),M.jsx("div",{ref:w,style:{height:B,position:"relative",width:"100%"},children:L.map(s=>M.jsx(X,{virtualItem:s,measureItem:I,children:n(s.index,s.data)},s.key))}),_&&M.jsx(_,{})]})}const ce=r.forwardRef(se);function ie({data:o,itemContent:e,computeItemKey:t,estimatedItemSize:n=60,overscan:l=20,onEndReached:i,endReachedThreshold:c=300,components:m={},className:f,style:d}){const{scrollerRef:g,innerRef:z,virtualItems:S,totalSize:T,measureItem:h}=Y({items:o,getKey:(v,P)=>t(P,v),estimatedItemSize:n,overscan:l,initialAlignment:"top"});D.useEffect(()=>{const v=g.current;if(!v||!i)return;let P=!1;const A=()=>{v.scrollHeight-v.scrollTop-v.clientHeight<=c&&!P&&(P=!0,Promise.resolve(i()).finally(()=>{P=!1}))};return v.addEventListener("scroll",A,{passive:!0}),()=>v.removeEventListener("scroll",A)},[g,i,c]);const{Header:F,Footer:y,EmptyPlaceholder:H}=m;return o.length===0&&H?M.jsx(H,{}):M.jsxs("div",{ref:g,className:f,style:{overflow:"auto",height:"100%",position:"relative",overscrollBehaviorY:"contain",...d},children:[F&&M.jsx(F,{}),M.jsx("div",{ref:z,style:{height:T,position:"relative",width:"100%"},children:S.map(v=>M.jsx(X,{virtualItem:v,measureItem:h,children:e(v.index,v.data)},v.key))}),y&&M.jsx(y,{})]})}function oe(o){const{fetcher:e,initialPage:t=1,direction:n="append",getKey:l,onPageLoaded:i,onError:c}=o,[m,f]=r.useState([]),[d,g]=r.useState(t),[z,S]=r.useState(!0),[T,h]=r.useState(!1),[F,y]=r.useState(!1),[H,v]=r.useState(!1),P=r.useRef(new Set),A=r.useRef(!1),w=r.useCallback(a=>l?a.filter(u=>{const p=l(u);return P.current.has(p)?!1:(P.current.add(p),!0)}):a,[l]),L=r.useCallback(async()=>{if(!(A.current||!z)){A.current=!0,v(!0);try{const a=d+1,u=await e(a),p=w(u.data);f(x=>n==="prepend"?[...p,...x]:[...x,...p]),g(a),S(u.hasNextPage),h(u.hasPrevPage),i==null||i(a,p)}catch(a){c==null||c(a instanceof Error?a:new Error(String(a)))}finally{v(!1),A.current=!1}}},[d,z,e,w,n,i,c]),B=r.useCallback(async()=>{if(!(A.current||!T)){A.current=!0,v(!0);try{const a=d-1,u=await e(a),p=w(u.data);f(x=>[...p,...x]),g(a),h(u.hasPrevPage),S(u.hasNextPage),i==null||i(a,p)}catch(a){c==null||c(a instanceof Error?a:new Error(String(a)))}finally{v(!1),A.current=!1}}},[d,T,e,w,i,c]),I=r.useCallback(async()=>{if(!A.current){A.current=!0,y(!0);try{const a=await e(t),u=a.data;if(l){const p=new Set(u.map(l));u.forEach(x=>P.current.add(l(x))),f(x=>{const K=x.filter(j=>!p.has(l(j)));return n==="prepend"?[...u,...K]:[...K,...u]})}else f(u);g(t),S(a.hasNextPage),h(a.hasPrevPage),i==null||i(t,u)}catch(a){c==null||c(a instanceof Error?a:new Error(String(a)))}finally{y(!1),A.current=!1}}},[e,t,l,n,i,c]),V=r.useCallback(()=>{f([]),g(t),S(!0),h(!1),y(!1),v(!1),P.current.clear(),A.current=!1},[t]);return{items:m,loadNextPage:L,loadPrevPage:B,hasNextPage:z,hasPrevPage:T,loading:F,loadingMore:H,refresh:I,reset:V,currentPage:d}}exports.ChatVirtualList=ce;exports.VirtualList=ie;exports.useChatVirtualizer=U;exports.usePagination=oe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),r=require("react");function Q(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const D=Q(r);class W{constructor(e,t){this.defaultSize=t,this.sizes=e>0?Array(e).fill(t):[],this.offsets=e>0?Array(e).fill(0):[],e>0&&this._recalcFrom(0)}_recalcFrom(e){for(let t=e;t<this.sizes.length;t++)this.offsets[t]=t===0?0:(this.offsets[t-1]??0)+(this.sizes[t-1]??this.defaultSize)}getOffset(e){return this.offsets[e]??0}getSize(e){return this.sizes[e]??this.defaultSize}setSize(e,t){return this.sizes[e]===t?!1:(this.sizes[e]=t,this._recalcFrom(e+1),!0)}prepend(e){const t=Array(e).fill(this.defaultSize);this.sizes=[...t,...this.sizes],this.offsets=Array(this.sizes.length).fill(0),this._recalcFrom(0)}append(e){const t=this.sizes.length;for(let n=0;n<e;n++)this.sizes.push(this.defaultSize),this.offsets.push(0);this._recalcFrom(t)}resize(e){const t=this.sizes.length;e>t?this.append(e-t):e<t&&(this.sizes=this.sizes.slice(0,e),this.offsets=this.offsets.slice(0,e))}totalSize(){if(this.sizes.length===0)return 0;const e=this.sizes.length-1;return(this.offsets[e]??0)+(this.sizes[e]??this.defaultSize)}get count(){return this.sizes.length}getOffsets(){return this.offsets}getSizes(){return this.sizes}}class Z{constructor(){this.cache=new Map}get(e){return this.cache.get(e)}set(e,t){this.cache.set(e,t)}has(e){return this.cache.has(e)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}applyToOffsetMap(e,t){for(const[n,l]of this.cache){const o=t.get(n);o!==void 0&&e.setSize(o,l)}}}function ee(i,e){if(i.length===0)return 0;let t=0,n=i.length-1;for(;t<n;){const l=t+n>>1;(i[l]??0)<e?t=l+1:n=l}return Math.max(0,t>0&&(i[t]??0)>e?t-1:t)}function te(i,e,t){if(i.length===0)return 0;for(let n=i.length-1;n>=0;n--)if((i[n]??0)<t)return n;return 0}function re(i){const{firstVisible:e,lastVisible:t,itemCount:n,overscan:l}=i;return n===0?{start:0,end:-1}:{start:Math.max(0,e-l),end:Math.min(n-1,t+l)}}function ne(i,e,t){return r.useCallback((n,l)=>{var H;const o=i.current,s=e.current;if(!o||!s)return;let m,f;if(typeof n=="object"&&n!==null?(m=n.index,f={align:n.align,behavior:n.behavior,offset:n.offset}):(m=n,f=l),!Number.isFinite(m))return;const d=Math.max(0,Math.min(Math.floor(m),s.count-1)),g=((H=t==null?void 0:t.current)==null?void 0:H.offsetTop)??0,z=s.getOffset(d),S=s.getSize(d),T=(f==null?void 0:f.align)??"start",h=(f==null?void 0:f.behavior)??"auto",I=(f==null?void 0:f.offset)??0;let y;T==="start"?y=g+z+I:T==="center"?y=g+z-o.clientHeight/2+S/2+I:y=g+z-o.clientHeight+S+I,o.scrollTo({top:Math.max(0,y),behavior:h})},[i,e,t])}function X(i){var O;const{items:e,getKey:t,estimatedItemSize:n,overscan:l,initialAlignment:o}=i,s=r.useRef(null),m=r.useRef(null),f=r.useRef(null),d=r.useRef(new Z),g=r.useRef([]),z=r.useRef(!1),S=r.useRef(0),T=r.useRef(0),h=r.useRef(null),I=r.useRef(!1),y=r.useRef(null),[,H]=r.useState(0),v=r.useCallback(()=>H(c=>c+1),[]);f.current||(f.current=new W(e.length,n));const E=r.useRef(e.length);if(e.length!==E.current||e.some((c,R)=>{const b=t(c,R);return g.current[R]!==b})){const c=f.current,R=e.map((_,N)=>t(_,N)),b=g.current,A=b.length,k=R.length;k===0?c.resize(0):A===0?c.resize(k):k>A?b.length>0&&R[k-A]===b[0]?c.prepend(k-A):c.resize(k):k<A&&c.resize(k);const P=new Map;R.forEach((_,N)=>P.set(_,N)),d.current.applyToOffsetMap(c,P),g.current=R,E.current=e.length}r.useEffect(()=>{const c=s.current;if(!c)return;const R=()=>{h.current===null&&(h.current=requestAnimationFrame(()=>{h.current=null,S.current=c.scrollTop,T.current=c.clientHeight,v()}))};return c.addEventListener("scroll",R,{passive:!0}),()=>{c.removeEventListener("scroll",R),h.current!==null&&(cancelAnimationFrame(h.current),h.current=null)}},[v]),r.useEffect(()=>{const c=s.current;if(!c)return;T.current=c.clientHeight,S.current=c.scrollTop;const R=new ResizeObserver(([b])=>{b&&(T.current=b.contentRect.height,v())});return R.observe(c),()=>R.disconnect()},[v]),r.useLayoutEffect(()=>{if(z.current||e.length===0)return;const c=s.current;if(c){if(o==="bottom"){c.scrollTop=c.scrollHeight,S.current=c.scrollTop,T.current=c.clientHeight,I.current=!0,y.current!==null&&cancelAnimationFrame(y.current);let R=0;const b=30,A=()=>{if(!I.current||R>=b){I.current=!1,y.current=null;return}R++,c.scrollTop=c.scrollHeight,S.current=c.scrollTop,y.current=requestAnimationFrame(A)};y.current=requestAnimationFrame(A)}z.current=!0}},[o,e.length]),r.useEffect(()=>{e.length===0&&(z.current=!1,I.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null))},[e.length]);const w=r.useCallback((c,R)=>{var N;const b=f.current;if(!b||d.current.get(c)===R)return;d.current.set(c,R);const k=g.current.indexOf(c);if(k===-1)return;const P=s.current;if(P&&!I.current){const Y=b.getSize(k),U=R-Y,J=b.getOffset(k)+Y+(((N=m.current)==null?void 0:N.offsetTop)??0);U!==0&&J<P.scrollTop&&(P.scrollTop+=U,S.current=P.scrollTop)}b.setSize(k,R)&&v()},[v]),L=r.useCallback((c,R="auto")=>{var b;(b=s.current)==null||b.scrollTo({top:c,behavior:R})},[]),B=ne(s,f,m),F=f.current,V=F?F.totalSize():0,a=s.current,u=(a==null?void 0:a.scrollTop)??S.current,p=(a==null?void 0:a.clientHeight)??T.current,x=((O=m.current)==null?void 0:O.offsetTop)??0,K=Math.max(0,u-x);let j=[];if(F&&F.count>0&&p>0){const c=F.getOffsets(),R=F.getSizes(),b=ee(c,K),A=te(c,R,K+p),k=re({firstVisible:b,lastVisible:A,itemCount:F.count,overscan:l});for(let P=k.start;P<=k.end&&P<e.length;P++)j.push({key:g.current[P]??t(e[P],P),index:P,start:F.getOffset(P),size:F.getSize(P),data:e[P]})}else if(F&&F.count>0){const c=Math.min(e.length,l*2+1),R=o==="bottom"?Math.max(0,e.length-c):0,b=R+c-1;for(let A=R;A<=b;A++)j.push({key:g.current[A]??t(e[A],A),index:A,start:F.getOffset(A),size:F.getSize(A),data:e[A]})}const q=a?a.scrollHeight-a.scrollTop-a.clientHeight:1/0;return{scrollerRef:s,innerRef:m,virtualItems:j,totalSize:V,measureItem:w,scrollToIndex:B,scrollToOffset:L,isAtTop:u<=1,isAtBottom:q<=1,scrollTop:u}}function se(i,e,t){const n=r.useRef(0),l=r.useRef(0),o=r.useRef(!1),s=r.useRef({first:null,second:null,timeout:null}),m=r.useCallback(()=>{const{first:d,second:g,timeout:z}=s.current;d&&cancelAnimationFrame(d),g&&cancelAnimationFrame(g),z&&clearTimeout(z),s.current={first:null,second:null,timeout:null}},[]),f=r.useCallback(()=>{const d=i.current;d&&(n.current=d.scrollTop,l.current=d.scrollHeight,o.current=!0)},[i]);return r.useLayoutEffect(()=>{if(!o.current)return;const d=i.current;if(!d)return;o.current=!1;const g=()=>{const z=n.current+(d.scrollHeight-l.current);Number.isFinite(z)&&Math.abs(d.scrollTop-z)>1&&(d.scrollTop=z)};return m(),g(),t==null||t(),s.current.first=requestAnimationFrame(()=>{s.current.first=null,g(),s.current.second=requestAnimationFrame(()=>{s.current.second=null,g()})}),s.current.timeout=setTimeout(()=>{s.current.timeout=null,g()},90),()=>m()},[e,i,m,t]),{prepareAnchor:f}}function ce(i,e){const[t,n]=r.useState(!0),l=r.useRef(null);return r.useEffect(()=>{const o=i.current;if(!o)return;const s=()=>{const f=o.scrollHeight-o.scrollTop-o.clientHeight;n(f<=e)},m=()=>{l.current!==null&&cancelAnimationFrame(l.current),l.current=requestAnimationFrame(s)};return o.addEventListener("scroll",m,{passive:!0}),s(),()=>{o.removeEventListener("scroll",m),l.current!==null&&cancelAnimationFrame(l.current)}},[i,e]),t}function oe(i){const{itemCount:e,firstKey:t,lastKey:n,isAtBottom:l,scrollToIndex:o,mode:s}=i,m=r.useRef(e),f=r.useRef(t),d=r.useRef(n);r.useLayoutEffect(()=>{if(!s){m.current=e,f.current=t,d.current=n;return}const g=m.current,z=f.current,S=d.current;e>g&&t===z&&n!==S&&l&&e>0&&o(e-1,{align:"end",behavior:s==="smooth"?"smooth":"auto"}),m.current=e,f.current=t,d.current=n},[e,t,n,l,o,s])}function $(i){const{items:e,getKey:t,estimatedItemSize:n=80,overscan:l=20,atBottomThreshold:o=200,followOutput:s="auto",initialAlignment:m="bottom",onStartReached:f,onEndReached:d,startReachedThreshold:g=300,endReachedThreshold:z=300,scrollToMessageKey:S,onScrollToMessageComplete:T}=i,h=X({items:e,getKey:t,estimatedItemSize:n,overscan:l,initialAlignment:m}),I=ce(h.scrollerRef,o),[,y]=r.useState(0),H=r.useCallback(()=>y(u=>u+1),[]),{prepareAnchor:v}=se(h.scrollerRef,e.length,H),E=e.length>0?t(e[0],0):null,C=e.length>0?t(e[e.length-1],e.length-1):null;oe({itemCount:e.length,firstKey:E,lastKey:C,isAtBottom:I,scrollToIndex:h.scrollToIndex,mode:s??!1});const w=r.useRef(!1),L=r.useRef(m==="top");r.useEffect(()=>{const u=h.scrollerRef.current;if(!u||!f)return;const p=()=>{const x=u.scrollTop;!L.current&&x>g&&(L.current=!0),L.current&&x<=g&&!w.current&&(w.current=!0,Promise.resolve(f()).finally(()=>{w.current=!1}))};return u.addEventListener("scroll",p,{passive:!0}),()=>u.removeEventListener("scroll",p)},[h.scrollerRef,f,g,m]);const B=r.useRef(!1);r.useEffect(()=>{const u=h.scrollerRef.current;if(!u||!d)return;const p=()=>{u.scrollHeight-u.scrollTop-u.clientHeight<=z&&!B.current&&(B.current=!0,Promise.resolve(d()).finally(()=>{B.current=!1}))};return u.addEventListener("scroll",p,{passive:!0}),()=>u.removeEventListener("scroll",p)},[h.scrollerRef,d,z]);const F=r.useRef(null);r.useEffect(()=>{if(!S||F.current===S)return;const u=e.findIndex((p,x)=>t(p,x)===S);u!==-1&&(F.current=S,h.scrollToIndex(u,{align:"center",behavior:"smooth"}),T==null||T())},[S,e,t,h,T]);const V=r.useCallback((u="auto")=>{e.length!==0&&h.scrollToIndex(e.length-1,{align:"end",behavior:u})},[e.length,h]),a=r.useCallback((u,p)=>{const x=e.findIndex((K,j)=>t(K,j)===u);x!==-1&&h.scrollToIndex(x,p)},[e,t,h]);return{scrollerRef:h.scrollerRef,innerRef:h.innerRef,virtualItems:h.virtualItems,totalSize:h.totalSize,measureItem:h.measureItem,scrollToIndex:h.scrollToIndex,scrollToBottom:V,scrollToKey:a,isAtBottom:I,prepareAnchor:v}}function G({virtualItem:i,measureItem:e,children:t}){const n=r.useRef(null),l=r.useRef(!1);return r.useEffect(()=>{const o=n.current;if(!o)return;l.current=!1;const s=new ResizeObserver(([m])=>{m&&(l.current=!0,e(i.key,m.contentRect.height))});return s.observe(o),()=>s.disconnect()},[i.key,e]),M.jsx("div",{ref:n,style:{position:"absolute",top:0,transform:`translateY(${i.start}px)`,width:"100%",minHeight:l.current?void 0:i.size},children:t})}function ie(i,e){const{data:t,itemContent:n,computeItemKey:l,estimatedItemSize:o=80,overscan:s=20,followOutput:m="auto",atBottomThreshold:f=200,initialAlignment:d="bottom",onStartReached:g,onEndReached:z,startReachedThreshold:S=300,endReachedThreshold:T=300,scrollToMessageKey:h,onScrollToMessageComplete:I,onAtBottomChange:y,components:H={},className:v,style:E}=i,{scrollerRef:C,innerRef:w,virtualItems:L,totalSize:B,measureItem:F,scrollToIndex:V,scrollToBottom:a,scrollToKey:u,isAtBottom:p,prepareAnchor:x}=$({items:t,getKey:(c,R)=>l(R,c),estimatedItemSize:o,overscan:s,atBottomThreshold:f,followOutput:m,initialAlignment:d,onStartReached:g,onEndReached:z,startReachedThreshold:S,endReachedThreshold:T,scrollToMessageKey:h,onScrollToMessageComplete:I}),K=D.useRef(p);D.useEffect(()=>{K.current!==p&&(K.current=p,y==null||y(p))},[p,y]),r.useImperativeHandle(e,()=>({scrollToBottom:a,scrollToIndex:V,scrollToKey:u,getScrollTop:()=>{var c;return((c=C.current)==null?void 0:c.scrollTop)??0},isAtBottom:()=>p,prepareAnchor:x}),[a,V,u,C,p,x]);const{Header:j,Footer:q,EmptyPlaceholder:O}=H;return t.length===0&&O?M.jsx(O,{}):M.jsxs("div",{ref:C,className:v,style:{overflow:"auto",height:"100%",position:"relative",overscrollBehaviorY:"contain",...E},children:[j&&M.jsx(j,{}),M.jsx("div",{ref:w,style:{height:B,position:"relative",width:"100%"},children:L.map(c=>M.jsx(G,{virtualItem:c,measureItem:F,children:n(c.index,c.data)},c.key))}),q&&M.jsx(q,{})]})}const le=r.forwardRef(ie);function ue({data:i,itemContent:e,computeItemKey:t,estimatedItemSize:n=60,overscan:l=20,onEndReached:o,endReachedThreshold:s=300,components:m={},className:f,style:d}){const{scrollerRef:g,innerRef:z,virtualItems:S,totalSize:T,measureItem:h}=X({items:i,getKey:(v,E)=>t(E,v),estimatedItemSize:n,overscan:l,initialAlignment:"top"});D.useEffect(()=>{const v=g.current;if(!v||!o)return;let E=!1;const C=()=>{v.scrollHeight-v.scrollTop-v.clientHeight<=s&&!E&&(E=!0,Promise.resolve(o()).finally(()=>{E=!1}))};return v.addEventListener("scroll",C,{passive:!0}),()=>v.removeEventListener("scroll",C)},[g,o,s]);const{Header:I,Footer:y,EmptyPlaceholder:H}=m;return i.length===0&&H?M.jsx(H,{}):M.jsxs("div",{ref:g,className:f,style:{overflow:"auto",height:"100%",position:"relative",overscrollBehaviorY:"contain",...d},children:[I&&M.jsx(I,{}),M.jsx("div",{ref:z,style:{height:T,position:"relative",width:"100%"},children:S.map(v=>M.jsx(G,{virtualItem:v,measureItem:h,children:e(v.index,v.data)},v.key))}),y&&M.jsx(y,{})]})}function ae(i){const{fetcher:e,initialPage:t=1,direction:n="append",getKey:l,onPageLoaded:o,onError:s}=i,[m,f]=r.useState([]),[d,g]=r.useState(t),[z,S]=r.useState(!0),[T,h]=r.useState(!1),[I,y]=r.useState(!1),[H,v]=r.useState(!1),E=r.useRef(new Set),C=r.useRef(!1),w=r.useCallback(a=>l?a.filter(u=>{const p=l(u);return E.current.has(p)?!1:(E.current.add(p),!0)}):a,[l]),L=r.useCallback(async()=>{if(!(C.current||!z)){C.current=!0,v(!0);try{const a=d+1,u=await e(a),p=w(u.data);f(x=>n==="prepend"?[...p,...x]:[...x,...p]),g(a),S(u.hasNextPage),h(u.hasPrevPage),o==null||o(a,p)}catch(a){s==null||s(a instanceof Error?a:new Error(String(a)))}finally{v(!1),C.current=!1}}},[d,z,e,w,n,o,s]),B=r.useCallback(async()=>{if(!(C.current||!T)){C.current=!0,v(!0);try{const a=d-1,u=await e(a),p=w(u.data);f(x=>[...p,...x]),g(a),h(u.hasPrevPage),S(u.hasNextPage),o==null||o(a,p)}catch(a){s==null||s(a instanceof Error?a:new Error(String(a)))}finally{v(!1),C.current=!1}}},[d,T,e,w,o,s]),F=r.useCallback(async()=>{if(!C.current){C.current=!0,y(!0);try{const a=await e(t),u=a.data;if(l){const p=new Set(u.map(l));u.forEach(x=>E.current.add(l(x))),f(x=>{const K=x.filter(j=>!p.has(l(j)));return n==="prepend"?[...u,...K]:[...K,...u]})}else f(u);g(t),S(a.hasNextPage),h(a.hasPrevPage),o==null||o(t,u)}catch(a){s==null||s(a instanceof Error?a:new Error(String(a)))}finally{y(!1),C.current=!1}}},[e,t,l,n,o,s]),V=r.useCallback(()=>{f([]),g(t),S(!0),h(!1),y(!1),v(!1),E.current.clear(),C.current=!1},[t]);return{items:m,loadNextPage:L,loadPrevPage:B,hasNextPage:z,hasPrevPage:T,loading:I,loadingMore:H,refresh:F,reset:V,currentPage:d}}exports.ChatVirtualList=le;exports.VirtualList=ue;exports.useChatVirtualizer=$;exports.usePagination=ae;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as B, jsxs as
|
|
1
|
+
import { jsx as B, jsxs as Q } from "react/jsx-runtime";
|
|
2
2
|
import * as X from "react";
|
|
3
|
-
import { useCallback as M, useRef as
|
|
4
|
-
class
|
|
3
|
+
import { useCallback as M, useRef as T, useState as _, useEffect as j, useLayoutEffect as $, forwardRef as te, useImperativeHandle as re } from "react";
|
|
4
|
+
class ne {
|
|
5
5
|
constructor(e, t) {
|
|
6
6
|
this.defaultSize = t, this.sizes = e > 0 ? Array(e).fill(t) : [], this.offsets = e > 0 ? Array(e).fill(0) : [], e > 0 && this._recalcFrom(0);
|
|
7
7
|
}
|
|
@@ -25,7 +25,7 @@ class ee {
|
|
|
25
25
|
}
|
|
26
26
|
append(e) {
|
|
27
27
|
const t = this.sizes.length;
|
|
28
|
-
for (let
|
|
28
|
+
for (let s = 0; s < e; s++)
|
|
29
29
|
this.sizes.push(this.defaultSize), this.offsets.push(0);
|
|
30
30
|
this._recalcFrom(t);
|
|
31
31
|
}
|
|
@@ -48,7 +48,7 @@ class ee {
|
|
|
48
48
|
return this.sizes;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
class
|
|
51
|
+
class se {
|
|
52
52
|
constructor() {
|
|
53
53
|
this.cache = /* @__PURE__ */ new Map();
|
|
54
54
|
}
|
|
@@ -69,155 +69,161 @@ class te {
|
|
|
69
69
|
}
|
|
70
70
|
/** Re-applies all cached sizes to the OffsetMap using a key→index map */
|
|
71
71
|
applyToOffsetMap(e, t) {
|
|
72
|
-
for (const [
|
|
73
|
-
const c = t.get(
|
|
72
|
+
for (const [s, o] of this.cache) {
|
|
73
|
+
const c = t.get(s);
|
|
74
74
|
c !== void 0 && e.setSize(c, o);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function ce(a, e) {
|
|
79
79
|
if (a.length === 0) return 0;
|
|
80
|
-
let t = 0,
|
|
81
|
-
for (; t <
|
|
82
|
-
const o = t +
|
|
83
|
-
(a[o] ?? 0) < e ? t = o + 1 :
|
|
80
|
+
let t = 0, s = a.length - 1;
|
|
81
|
+
for (; t < s; ) {
|
|
82
|
+
const o = t + s >> 1;
|
|
83
|
+
(a[o] ?? 0) < e ? t = o + 1 : s = o;
|
|
84
84
|
}
|
|
85
85
|
return Math.max(0, t > 0 && (a[t] ?? 0) > e ? t - 1 : t);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function oe(a, e, t) {
|
|
88
88
|
if (a.length === 0) return 0;
|
|
89
|
-
for (let
|
|
90
|
-
if ((a[
|
|
89
|
+
for (let s = a.length - 1; s >= 0; s--)
|
|
90
|
+
if ((a[s] ?? 0) < t) return s;
|
|
91
91
|
return 0;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
const { firstVisible: e, lastVisible: t, itemCount:
|
|
95
|
-
return
|
|
93
|
+
function ie(a) {
|
|
94
|
+
const { firstVisible: e, lastVisible: t, itemCount: s, overscan: o } = a;
|
|
95
|
+
return s === 0 ? { start: 0, end: -1 } : {
|
|
96
96
|
start: Math.max(0, e - o),
|
|
97
|
-
end: Math.min(
|
|
97
|
+
end: Math.min(s - 1, t + o)
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
function
|
|
100
|
+
function le(a, e, t) {
|
|
101
101
|
return M(
|
|
102
|
-
(
|
|
102
|
+
(s, o) => {
|
|
103
103
|
var E;
|
|
104
|
-
const c = a.current,
|
|
105
|
-
if (!c || !
|
|
104
|
+
const c = a.current, r = e.current;
|
|
105
|
+
if (!c || !r) return;
|
|
106
106
|
let m, u;
|
|
107
|
-
if (typeof
|
|
108
|
-
align:
|
|
109
|
-
behavior:
|
|
110
|
-
offset:
|
|
111
|
-
}) : (m =
|
|
112
|
-
const h = Math.max(0, Math.min(Math.floor(m),
|
|
107
|
+
if (typeof s == "object" && s !== null ? (m = s.index, u = {
|
|
108
|
+
align: s.align,
|
|
109
|
+
behavior: s.behavior,
|
|
110
|
+
offset: s.offset
|
|
111
|
+
}) : (m = s, u = o), !Number.isFinite(m)) return;
|
|
112
|
+
const h = Math.max(0, Math.min(Math.floor(m), r.count - 1)), d = ((E = t == null ? void 0 : t.current) == null ? void 0 : E.offsetTop) ?? 0, y = r.getOffset(h), S = r.getSize(h), x = (u == null ? void 0 : u.align) ?? "start", f = (u == null ? void 0 : u.behavior) ?? "auto", F = (u == null ? void 0 : u.offset) ?? 0;
|
|
113
113
|
let z;
|
|
114
|
-
x === "start" ? z = d +
|
|
114
|
+
x === "start" ? z = d + y + F : x === "center" ? z = d + y - c.clientHeight / 2 + S / 2 + F : z = d + y - c.clientHeight + S + F, c.scrollTo({ top: Math.max(0, z), behavior: f });
|
|
115
115
|
},
|
|
116
116
|
[a, e, t]
|
|
117
117
|
);
|
|
118
118
|
}
|
|
119
|
-
function
|
|
120
|
-
var
|
|
121
|
-
const { items: e, getKey: t, estimatedItemSize:
|
|
122
|
-
u.current || (u.current = new
|
|
123
|
-
const
|
|
124
|
-
if (e.length !==
|
|
125
|
-
const
|
|
126
|
-
return d.current[v] !==
|
|
119
|
+
function W(a) {
|
|
120
|
+
var Y;
|
|
121
|
+
const { items: e, getKey: t, estimatedItemSize: s, overscan: o, initialAlignment: c } = a, r = T(null), m = T(null), u = T(null), h = T(new se()), d = T([]), y = T(!1), S = T(0), x = T(0), f = T(null), F = T(!1), z = T(null), [, E] = _(0), p = M(() => E((n) => n + 1), []);
|
|
122
|
+
u.current || (u.current = new ne(e.length, s));
|
|
123
|
+
const w = T(e.length);
|
|
124
|
+
if (e.length !== w.current || e.some((n, v) => {
|
|
125
|
+
const I = t(n, v);
|
|
126
|
+
return d.current[v] !== I;
|
|
127
127
|
})) {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
v.forEach((U,
|
|
128
|
+
const n = u.current, v = e.map((U, O) => t(U, O)), I = d.current, R = I.length, K = v.length;
|
|
129
|
+
K === 0 ? n.resize(0) : R === 0 ? n.resize(K) : K > R ? I.length > 0 && v[K - R] === I[0] ? n.prepend(K - R) : n.resize(K) : K < R && n.resize(K);
|
|
130
|
+
const P = /* @__PURE__ */ new Map();
|
|
131
|
+
v.forEach((U, O) => P.set(U, O)), h.current.applyToOffsetMap(n, P), d.current = v, w.current = e.length;
|
|
132
132
|
}
|
|
133
133
|
j(() => {
|
|
134
|
-
const
|
|
135
|
-
if (!
|
|
134
|
+
const n = r.current;
|
|
135
|
+
if (!n) return;
|
|
136
136
|
const v = () => {
|
|
137
137
|
f.current === null && (f.current = requestAnimationFrame(() => {
|
|
138
|
-
f.current = null, S.current =
|
|
138
|
+
f.current = null, S.current = n.scrollTop, x.current = n.clientHeight, p();
|
|
139
139
|
}));
|
|
140
140
|
};
|
|
141
|
-
return
|
|
142
|
-
|
|
141
|
+
return n.addEventListener("scroll", v, { passive: !0 }), () => {
|
|
142
|
+
n.removeEventListener("scroll", v), f.current !== null && (cancelAnimationFrame(f.current), f.current = null);
|
|
143
143
|
};
|
|
144
144
|
}, [p]), j(() => {
|
|
145
|
-
const
|
|
146
|
-
if (!
|
|
147
|
-
x.current =
|
|
148
|
-
const v = new ResizeObserver(([
|
|
149
|
-
|
|
145
|
+
const n = r.current;
|
|
146
|
+
if (!n) return;
|
|
147
|
+
x.current = n.clientHeight, S.current = n.scrollTop;
|
|
148
|
+
const v = new ResizeObserver(([I]) => {
|
|
149
|
+
I && (x.current = I.contentRect.height, p());
|
|
150
150
|
});
|
|
151
|
-
return v.observe(
|
|
151
|
+
return v.observe(n), () => v.disconnect();
|
|
152
152
|
}, [p]), $(() => {
|
|
153
|
-
if (
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
153
|
+
if (y.current || e.length === 0) return;
|
|
154
|
+
const n = r.current;
|
|
155
|
+
if (n) {
|
|
156
156
|
if (c === "bottom") {
|
|
157
|
-
|
|
157
|
+
n.scrollTop = n.scrollHeight, S.current = n.scrollTop, x.current = n.clientHeight, F.current = !0, z.current !== null && cancelAnimationFrame(z.current);
|
|
158
158
|
let v = 0;
|
|
159
|
-
const
|
|
160
|
-
if (!
|
|
161
|
-
|
|
159
|
+
const I = 30, R = () => {
|
|
160
|
+
if (!F.current || v >= I) {
|
|
161
|
+
F.current = !1, z.current = null;
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
|
-
v++,
|
|
164
|
+
v++, n.scrollTop = n.scrollHeight, S.current = n.scrollTop, z.current = requestAnimationFrame(R);
|
|
165
165
|
};
|
|
166
|
-
z.current = requestAnimationFrame(
|
|
166
|
+
z.current = requestAnimationFrame(R);
|
|
167
167
|
}
|
|
168
|
-
|
|
168
|
+
y.current = !0;
|
|
169
169
|
}
|
|
170
170
|
}, [c, e.length]), j(() => {
|
|
171
|
-
e.length === 0 && (
|
|
171
|
+
e.length === 0 && (y.current = !1, F.current = !1, z.current !== null && (cancelAnimationFrame(z.current), z.current = null));
|
|
172
172
|
}, [e.length]);
|
|
173
|
-
const C = M((
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
h.current.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
173
|
+
const C = M((n, v) => {
|
|
174
|
+
var O;
|
|
175
|
+
const I = u.current;
|
|
176
|
+
if (!I || h.current.get(n) === v) return;
|
|
177
|
+
h.current.set(n, v);
|
|
178
|
+
const K = d.current.indexOf(n);
|
|
179
|
+
if (K === -1) return;
|
|
180
|
+
const P = r.current;
|
|
181
|
+
if (P && !F.current) {
|
|
182
|
+
const G = I.getSize(K), J = v - G, ee = I.getOffset(K) + G + (((O = m.current) == null ? void 0 : O.offsetTop) ?? 0);
|
|
183
|
+
J !== 0 && ee < P.scrollTop && (P.scrollTop += J, S.current = P.scrollTop);
|
|
184
|
+
}
|
|
185
|
+
I.setSize(K, v) && p();
|
|
180
186
|
}, [p]), V = M(
|
|
181
|
-
(
|
|
182
|
-
var
|
|
183
|
-
(
|
|
187
|
+
(n, v = "auto") => {
|
|
188
|
+
var I;
|
|
189
|
+
(I = r.current) == null || I.scrollTo({ top: n, behavior: v });
|
|
184
190
|
},
|
|
185
191
|
[]
|
|
186
|
-
), N =
|
|
192
|
+
), N = le(r, u, m), H = u.current, q = H ? H.totalSize() : 0, l = r.current, i = (l == null ? void 0 : l.scrollTop) ?? S.current, g = (l == null ? void 0 : l.clientHeight) ?? x.current, A = ((Y = m.current) == null ? void 0 : Y.offsetTop) ?? 0, L = Math.max(0, i - A);
|
|
187
193
|
let k = [];
|
|
188
|
-
if (
|
|
189
|
-
const
|
|
190
|
-
|
|
194
|
+
if (H && H.count > 0 && g > 0) {
|
|
195
|
+
const n = H.getOffsets(), v = H.getSizes(), I = ce(n, L), R = oe(
|
|
196
|
+
n,
|
|
191
197
|
v,
|
|
192
198
|
L + g
|
|
193
|
-
),
|
|
194
|
-
firstVisible:
|
|
195
|
-
lastVisible:
|
|
196
|
-
itemCount:
|
|
199
|
+
), K = ie({
|
|
200
|
+
firstVisible: I,
|
|
201
|
+
lastVisible: R,
|
|
202
|
+
itemCount: H.count,
|
|
197
203
|
overscan: o
|
|
198
204
|
});
|
|
199
|
-
for (let
|
|
205
|
+
for (let P = K.start; P <= K.end && P < e.length; P++)
|
|
200
206
|
k.push({
|
|
201
|
-
key: d.current[
|
|
202
|
-
index:
|
|
203
|
-
start:
|
|
204
|
-
size:
|
|
205
|
-
data: e[
|
|
207
|
+
key: d.current[P] ?? t(e[P], P),
|
|
208
|
+
index: P,
|
|
209
|
+
start: H.getOffset(P),
|
|
210
|
+
size: H.getSize(P),
|
|
211
|
+
data: e[P]
|
|
206
212
|
});
|
|
207
|
-
} else if (
|
|
208
|
-
const
|
|
209
|
-
for (let
|
|
213
|
+
} else if (H && H.count > 0) {
|
|
214
|
+
const n = Math.min(e.length, o * 2 + 1), v = c === "bottom" ? Math.max(0, e.length - n) : 0, I = v + n - 1;
|
|
215
|
+
for (let R = v; R <= I; R++)
|
|
210
216
|
k.push({
|
|
211
|
-
key: d.current[
|
|
212
|
-
index:
|
|
213
|
-
start:
|
|
214
|
-
size:
|
|
215
|
-
data: e[
|
|
217
|
+
key: d.current[R] ?? t(e[R], R),
|
|
218
|
+
index: R,
|
|
219
|
+
start: H.getOffset(R),
|
|
220
|
+
size: H.getSize(R),
|
|
221
|
+
data: e[R]
|
|
216
222
|
});
|
|
217
223
|
}
|
|
218
|
-
const
|
|
224
|
+
const D = l ? l.scrollHeight - l.scrollTop - l.clientHeight : 1 / 0;
|
|
219
225
|
return {
|
|
220
|
-
scrollerRef:
|
|
226
|
+
scrollerRef: r,
|
|
221
227
|
innerRef: m,
|
|
222
228
|
virtualItems: k,
|
|
223
229
|
totalSize: q,
|
|
@@ -225,21 +231,21 @@ function J(a) {
|
|
|
225
231
|
scrollToIndex: N,
|
|
226
232
|
scrollToOffset: V,
|
|
227
233
|
isAtTop: i <= 1,
|
|
228
|
-
isAtBottom:
|
|
234
|
+
isAtBottom: D <= 1,
|
|
229
235
|
scrollTop: i
|
|
230
236
|
};
|
|
231
237
|
}
|
|
232
|
-
function
|
|
233
|
-
const
|
|
238
|
+
function ae(a, e, t) {
|
|
239
|
+
const s = T(0), o = T(0), c = T(!1), r = T({
|
|
234
240
|
first: null,
|
|
235
241
|
second: null,
|
|
236
242
|
timeout: null
|
|
237
243
|
}), m = M(() => {
|
|
238
|
-
const { first: h, second: d, timeout:
|
|
239
|
-
h && cancelAnimationFrame(h), d && cancelAnimationFrame(d),
|
|
244
|
+
const { first: h, second: d, timeout: y } = r.current;
|
|
245
|
+
h && cancelAnimationFrame(h), d && cancelAnimationFrame(d), y && clearTimeout(y), r.current = { first: null, second: null, timeout: null };
|
|
240
246
|
}, []), u = M(() => {
|
|
241
247
|
const h = a.current;
|
|
242
|
-
h && (
|
|
248
|
+
h && (s.current = h.scrollTop, o.current = h.scrollHeight, c.current = !0);
|
|
243
249
|
}, [a]);
|
|
244
250
|
return $(() => {
|
|
245
251
|
if (!c.current) return;
|
|
@@ -247,79 +253,79 @@ function oe(a, e, t) {
|
|
|
247
253
|
if (!h) return;
|
|
248
254
|
c.current = !1;
|
|
249
255
|
const d = () => {
|
|
250
|
-
const
|
|
251
|
-
Number.isFinite(
|
|
256
|
+
const y = s.current + (h.scrollHeight - o.current);
|
|
257
|
+
Number.isFinite(y) && Math.abs(h.scrollTop - y) > 1 && (h.scrollTop = y);
|
|
252
258
|
};
|
|
253
|
-
return m(), d(), t == null || t(),
|
|
254
|
-
|
|
255
|
-
|
|
259
|
+
return m(), d(), t == null || t(), r.current.first = requestAnimationFrame(() => {
|
|
260
|
+
r.current.first = null, d(), r.current.second = requestAnimationFrame(() => {
|
|
261
|
+
r.current.second = null, d();
|
|
256
262
|
});
|
|
257
|
-
}),
|
|
258
|
-
|
|
263
|
+
}), r.current.timeout = setTimeout(() => {
|
|
264
|
+
r.current.timeout = null, d();
|
|
259
265
|
}, 90), () => m();
|
|
260
266
|
}, [e, a, m, t]), { prepareAnchor: u };
|
|
261
267
|
}
|
|
262
|
-
function
|
|
263
|
-
const [t,
|
|
268
|
+
function ue(a, e) {
|
|
269
|
+
const [t, s] = _(!0), o = T(null);
|
|
264
270
|
return j(() => {
|
|
265
271
|
const c = a.current;
|
|
266
272
|
if (!c) return;
|
|
267
|
-
const
|
|
273
|
+
const r = () => {
|
|
268
274
|
const u = c.scrollHeight - c.scrollTop - c.clientHeight;
|
|
269
|
-
|
|
275
|
+
s(u <= e);
|
|
270
276
|
}, m = () => {
|
|
271
|
-
o.current !== null && cancelAnimationFrame(o.current), o.current = requestAnimationFrame(
|
|
277
|
+
o.current !== null && cancelAnimationFrame(o.current), o.current = requestAnimationFrame(r);
|
|
272
278
|
};
|
|
273
|
-
return c.addEventListener("scroll", m, { passive: !0 }),
|
|
279
|
+
return c.addEventListener("scroll", m, { passive: !0 }), r(), () => {
|
|
274
280
|
c.removeEventListener("scroll", m), o.current !== null && cancelAnimationFrame(o.current);
|
|
275
281
|
};
|
|
276
282
|
}, [a, e]), t;
|
|
277
283
|
}
|
|
278
|
-
function
|
|
279
|
-
const { itemCount: e, firstKey: t, lastKey:
|
|
284
|
+
function fe(a) {
|
|
285
|
+
const { itemCount: e, firstKey: t, lastKey: s, isAtBottom: o, scrollToIndex: c, mode: r } = a, m = T(e), u = T(t), h = T(s);
|
|
280
286
|
$(() => {
|
|
281
|
-
if (!
|
|
282
|
-
m.current = e, u.current = t, h.current =
|
|
287
|
+
if (!r) {
|
|
288
|
+
m.current = e, u.current = t, h.current = s;
|
|
283
289
|
return;
|
|
284
290
|
}
|
|
285
|
-
const d = m.current,
|
|
286
|
-
e > d && t ===
|
|
291
|
+
const d = m.current, y = u.current, S = h.current;
|
|
292
|
+
e > d && t === y && s !== S && o && e > 0 && c(e - 1, {
|
|
287
293
|
align: "end",
|
|
288
|
-
behavior:
|
|
289
|
-
}), m.current = e, u.current = t, h.current =
|
|
290
|
-
}, [e, t,
|
|
294
|
+
behavior: r === "smooth" ? "smooth" : "auto"
|
|
295
|
+
}), m.current = e, u.current = t, h.current = s;
|
|
296
|
+
}, [e, t, s, o, c, r]);
|
|
291
297
|
}
|
|
292
|
-
function
|
|
298
|
+
function he(a) {
|
|
293
299
|
const {
|
|
294
300
|
items: e,
|
|
295
301
|
getKey: t,
|
|
296
|
-
estimatedItemSize:
|
|
302
|
+
estimatedItemSize: s = 80,
|
|
297
303
|
overscan: o = 20,
|
|
298
304
|
atBottomThreshold: c = 200,
|
|
299
|
-
followOutput:
|
|
305
|
+
followOutput: r = "auto",
|
|
300
306
|
initialAlignment: m = "bottom",
|
|
301
307
|
onStartReached: u,
|
|
302
308
|
onEndReached: h,
|
|
303
309
|
startReachedThreshold: d = 300,
|
|
304
|
-
endReachedThreshold:
|
|
310
|
+
endReachedThreshold: y = 300,
|
|
305
311
|
scrollToMessageKey: S,
|
|
306
312
|
onScrollToMessageComplete: x
|
|
307
|
-
} = a, f =
|
|
313
|
+
} = a, f = W({
|
|
308
314
|
items: e,
|
|
309
315
|
getKey: t,
|
|
310
|
-
estimatedItemSize:
|
|
316
|
+
estimatedItemSize: s,
|
|
311
317
|
overscan: o,
|
|
312
318
|
initialAlignment: m
|
|
313
|
-
}),
|
|
314
|
-
|
|
319
|
+
}), F = ue(f.scrollerRef, c), [, z] = _(0), E = M(() => z((i) => i + 1), []), { prepareAnchor: p } = ae(f.scrollerRef, e.length, E), w = e.length > 0 ? t(e[0], 0) : null, b = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
|
|
320
|
+
fe({
|
|
315
321
|
itemCount: e.length,
|
|
316
|
-
firstKey:
|
|
317
|
-
lastKey:
|
|
318
|
-
isAtBottom:
|
|
322
|
+
firstKey: w,
|
|
323
|
+
lastKey: b,
|
|
324
|
+
isAtBottom: F,
|
|
319
325
|
scrollToIndex: f.scrollToIndex,
|
|
320
|
-
mode:
|
|
326
|
+
mode: r ?? !1
|
|
321
327
|
});
|
|
322
|
-
const C =
|
|
328
|
+
const C = T(!1), V = T(m === "top");
|
|
323
329
|
j(() => {
|
|
324
330
|
const i = f.scrollerRef.current;
|
|
325
331
|
if (!i || !u) return;
|
|
@@ -331,22 +337,22 @@ function ae(a) {
|
|
|
331
337
|
};
|
|
332
338
|
return i.addEventListener("scroll", g, { passive: !0 }), () => i.removeEventListener("scroll", g);
|
|
333
339
|
}, [f.scrollerRef, u, d, m]);
|
|
334
|
-
const N =
|
|
340
|
+
const N = T(!1);
|
|
335
341
|
j(() => {
|
|
336
342
|
const i = f.scrollerRef.current;
|
|
337
343
|
if (!i || !h) return;
|
|
338
344
|
const g = () => {
|
|
339
|
-
i.scrollHeight - i.scrollTop - i.clientHeight <=
|
|
345
|
+
i.scrollHeight - i.scrollTop - i.clientHeight <= y && !N.current && (N.current = !0, Promise.resolve(h()).finally(() => {
|
|
340
346
|
N.current = !1;
|
|
341
347
|
}));
|
|
342
348
|
};
|
|
343
349
|
return i.addEventListener("scroll", g, { passive: !0 }), () => i.removeEventListener("scroll", g);
|
|
344
|
-
}, [f.scrollerRef, h,
|
|
345
|
-
const
|
|
350
|
+
}, [f.scrollerRef, h, y]);
|
|
351
|
+
const H = T(null);
|
|
346
352
|
j(() => {
|
|
347
|
-
if (!S ||
|
|
353
|
+
if (!S || H.current === S) return;
|
|
348
354
|
const i = e.findIndex((g, A) => t(g, A) === S);
|
|
349
|
-
i !== -1 && (
|
|
355
|
+
i !== -1 && (H.current = S, f.scrollToIndex(i, { align: "center", behavior: "smooth" }), x == null || x());
|
|
350
356
|
}, [S, e, t, f, x]);
|
|
351
357
|
const q = M(
|
|
352
358
|
(i = "auto") => {
|
|
@@ -369,28 +375,28 @@ function ae(a) {
|
|
|
369
375
|
scrollToIndex: f.scrollToIndex,
|
|
370
376
|
scrollToBottom: q,
|
|
371
377
|
scrollToKey: l,
|
|
372
|
-
isAtBottom:
|
|
378
|
+
isAtBottom: F,
|
|
373
379
|
prepareAnchor: p
|
|
374
380
|
};
|
|
375
381
|
}
|
|
376
|
-
function
|
|
382
|
+
function Z({
|
|
377
383
|
virtualItem: a,
|
|
378
384
|
measureItem: e,
|
|
379
385
|
children: t
|
|
380
386
|
}) {
|
|
381
|
-
const
|
|
387
|
+
const s = T(null), o = T(!1);
|
|
382
388
|
return j(() => {
|
|
383
|
-
const c =
|
|
389
|
+
const c = s.current;
|
|
384
390
|
if (!c) return;
|
|
385
391
|
o.current = !1;
|
|
386
|
-
const
|
|
392
|
+
const r = new ResizeObserver(([m]) => {
|
|
387
393
|
m && (o.current = !0, e(a.key, m.contentRect.height));
|
|
388
394
|
});
|
|
389
|
-
return
|
|
395
|
+
return r.observe(c), () => r.disconnect();
|
|
390
396
|
}, [a.key, e]), /* @__PURE__ */ B(
|
|
391
397
|
"div",
|
|
392
398
|
{
|
|
393
|
-
ref:
|
|
399
|
+
ref: s,
|
|
394
400
|
style: {
|
|
395
401
|
position: "absolute",
|
|
396
402
|
top: 0,
|
|
@@ -408,131 +414,131 @@ function Q({
|
|
|
408
414
|
}
|
|
409
415
|
);
|
|
410
416
|
}
|
|
411
|
-
function
|
|
417
|
+
function de(a, e) {
|
|
412
418
|
const {
|
|
413
419
|
data: t,
|
|
414
|
-
itemContent:
|
|
420
|
+
itemContent: s,
|
|
415
421
|
computeItemKey: o,
|
|
416
422
|
estimatedItemSize: c = 80,
|
|
417
|
-
overscan:
|
|
423
|
+
overscan: r = 20,
|
|
418
424
|
followOutput: m = "auto",
|
|
419
425
|
atBottomThreshold: u = 200,
|
|
420
426
|
initialAlignment: h = "bottom",
|
|
421
427
|
onStartReached: d,
|
|
422
|
-
onEndReached:
|
|
428
|
+
onEndReached: y,
|
|
423
429
|
startReachedThreshold: S = 300,
|
|
424
430
|
endReachedThreshold: x = 300,
|
|
425
431
|
scrollToMessageKey: f,
|
|
426
|
-
onScrollToMessageComplete:
|
|
432
|
+
onScrollToMessageComplete: F,
|
|
427
433
|
onAtBottomChange: z,
|
|
428
434
|
components: E = {},
|
|
429
435
|
className: p,
|
|
430
|
-
style:
|
|
436
|
+
style: w
|
|
431
437
|
} = a, {
|
|
432
|
-
scrollerRef:
|
|
438
|
+
scrollerRef: b,
|
|
433
439
|
innerRef: C,
|
|
434
440
|
virtualItems: V,
|
|
435
441
|
totalSize: N,
|
|
436
|
-
measureItem:
|
|
442
|
+
measureItem: H,
|
|
437
443
|
scrollToIndex: q,
|
|
438
444
|
scrollToBottom: l,
|
|
439
445
|
scrollToKey: i,
|
|
440
446
|
isAtBottom: g,
|
|
441
447
|
prepareAnchor: A
|
|
442
|
-
} =
|
|
448
|
+
} = he({
|
|
443
449
|
items: t,
|
|
444
|
-
getKey: (
|
|
450
|
+
getKey: (n, v) => o(v, n),
|
|
445
451
|
estimatedItemSize: c,
|
|
446
|
-
overscan:
|
|
452
|
+
overscan: r,
|
|
447
453
|
atBottomThreshold: u,
|
|
448
454
|
followOutput: m,
|
|
449
455
|
initialAlignment: h,
|
|
450
456
|
onStartReached: d,
|
|
451
|
-
onEndReached:
|
|
457
|
+
onEndReached: y,
|
|
452
458
|
startReachedThreshold: S,
|
|
453
459
|
endReachedThreshold: x,
|
|
454
460
|
scrollToMessageKey: f,
|
|
455
|
-
onScrollToMessageComplete:
|
|
461
|
+
onScrollToMessageComplete: F
|
|
456
462
|
}), L = X.useRef(g);
|
|
457
463
|
X.useEffect(() => {
|
|
458
464
|
L.current !== g && (L.current = g, z == null || z(g));
|
|
459
|
-
}, [g, z]),
|
|
465
|
+
}, [g, z]), re(
|
|
460
466
|
e,
|
|
461
467
|
() => ({
|
|
462
468
|
scrollToBottom: l,
|
|
463
469
|
scrollToIndex: q,
|
|
464
470
|
scrollToKey: i,
|
|
465
471
|
getScrollTop: () => {
|
|
466
|
-
var
|
|
467
|
-
return ((
|
|
472
|
+
var n;
|
|
473
|
+
return ((n = b.current) == null ? void 0 : n.scrollTop) ?? 0;
|
|
468
474
|
},
|
|
469
475
|
isAtBottom: () => g,
|
|
470
476
|
prepareAnchor: A
|
|
471
477
|
}),
|
|
472
|
-
[l, q, i,
|
|
478
|
+
[l, q, i, b, g, A]
|
|
473
479
|
);
|
|
474
|
-
const { Header: k, Footer:
|
|
475
|
-
return t.length === 0 &&
|
|
480
|
+
const { Header: k, Footer: D, EmptyPlaceholder: Y } = E;
|
|
481
|
+
return t.length === 0 && Y ? /* @__PURE__ */ B(Y, {}) : /* @__PURE__ */ Q(
|
|
476
482
|
"div",
|
|
477
483
|
{
|
|
478
|
-
ref:
|
|
484
|
+
ref: b,
|
|
479
485
|
className: p,
|
|
480
486
|
style: {
|
|
481
487
|
overflow: "auto",
|
|
482
488
|
height: "100%",
|
|
483
489
|
position: "relative",
|
|
484
490
|
overscrollBehaviorY: "contain",
|
|
485
|
-
...
|
|
491
|
+
...w
|
|
486
492
|
},
|
|
487
493
|
children: [
|
|
488
494
|
k && /* @__PURE__ */ B(k, {}),
|
|
489
|
-
/* @__PURE__ */ B("div", { ref: C, style: { height: N, position: "relative", width: "100%" }, children: V.map((
|
|
490
|
-
|
|
495
|
+
/* @__PURE__ */ B("div", { ref: C, style: { height: N, position: "relative", width: "100%" }, children: V.map((n) => /* @__PURE__ */ B(
|
|
496
|
+
Z,
|
|
491
497
|
{
|
|
492
|
-
virtualItem:
|
|
493
|
-
measureItem:
|
|
494
|
-
children: n
|
|
498
|
+
virtualItem: n,
|
|
499
|
+
measureItem: H,
|
|
500
|
+
children: s(n.index, n.data)
|
|
495
501
|
},
|
|
496
|
-
|
|
502
|
+
n.key
|
|
497
503
|
)) }),
|
|
498
|
-
|
|
504
|
+
D && /* @__PURE__ */ B(D, {})
|
|
499
505
|
]
|
|
500
506
|
}
|
|
501
507
|
);
|
|
502
508
|
}
|
|
503
|
-
const
|
|
504
|
-
function
|
|
509
|
+
const pe = te(de);
|
|
510
|
+
function ve({
|
|
505
511
|
data: a,
|
|
506
512
|
itemContent: e,
|
|
507
513
|
computeItemKey: t,
|
|
508
|
-
estimatedItemSize:
|
|
514
|
+
estimatedItemSize: s = 60,
|
|
509
515
|
overscan: o = 20,
|
|
510
516
|
onEndReached: c,
|
|
511
|
-
endReachedThreshold:
|
|
517
|
+
endReachedThreshold: r = 300,
|
|
512
518
|
components: m = {},
|
|
513
519
|
className: u,
|
|
514
520
|
style: h
|
|
515
521
|
}) {
|
|
516
|
-
const { scrollerRef: d, innerRef:
|
|
522
|
+
const { scrollerRef: d, innerRef: y, virtualItems: S, totalSize: x, measureItem: f } = W({
|
|
517
523
|
items: a,
|
|
518
|
-
getKey: (p,
|
|
519
|
-
estimatedItemSize:
|
|
524
|
+
getKey: (p, w) => t(w, p),
|
|
525
|
+
estimatedItemSize: s,
|
|
520
526
|
overscan: o,
|
|
521
527
|
initialAlignment: "top"
|
|
522
528
|
});
|
|
523
529
|
X.useEffect(() => {
|
|
524
530
|
const p = d.current;
|
|
525
531
|
if (!p || !c) return;
|
|
526
|
-
let
|
|
527
|
-
const
|
|
528
|
-
p.scrollHeight - p.scrollTop - p.clientHeight <=
|
|
529
|
-
|
|
532
|
+
let w = !1;
|
|
533
|
+
const b = () => {
|
|
534
|
+
p.scrollHeight - p.scrollTop - p.clientHeight <= r && !w && (w = !0, Promise.resolve(c()).finally(() => {
|
|
535
|
+
w = !1;
|
|
530
536
|
}));
|
|
531
537
|
};
|
|
532
|
-
return p.addEventListener("scroll",
|
|
533
|
-
}, [d, c,
|
|
534
|
-
const { Header:
|
|
535
|
-
return a.length === 0 && E ? /* @__PURE__ */ B(E, {}) : /* @__PURE__ */
|
|
538
|
+
return p.addEventListener("scroll", b, { passive: !0 }), () => p.removeEventListener("scroll", b);
|
|
539
|
+
}, [d, c, r]);
|
|
540
|
+
const { Header: F, Footer: z, EmptyPlaceholder: E } = m;
|
|
541
|
+
return a.length === 0 && E ? /* @__PURE__ */ B(E, {}) : /* @__PURE__ */ Q(
|
|
536
542
|
"div",
|
|
537
543
|
{
|
|
538
544
|
ref: d,
|
|
@@ -545,9 +551,9 @@ function me({
|
|
|
545
551
|
...h
|
|
546
552
|
},
|
|
547
553
|
children: [
|
|
548
|
-
|
|
549
|
-
/* @__PURE__ */ B("div", { ref:
|
|
550
|
-
|
|
554
|
+
F && /* @__PURE__ */ B(F, {}),
|
|
555
|
+
/* @__PURE__ */ B("div", { ref: y, style: { height: x, position: "relative", width: "100%" }, children: S.map((p) => /* @__PURE__ */ B(
|
|
556
|
+
Z,
|
|
551
557
|
{
|
|
552
558
|
virtualItem: p,
|
|
553
559
|
measureItem: f,
|
|
@@ -560,85 +566,85 @@ function me({
|
|
|
560
566
|
}
|
|
561
567
|
);
|
|
562
568
|
}
|
|
563
|
-
function
|
|
569
|
+
function ze(a) {
|
|
564
570
|
const {
|
|
565
571
|
fetcher: e,
|
|
566
572
|
initialPage: t = 1,
|
|
567
|
-
direction:
|
|
573
|
+
direction: s = "append",
|
|
568
574
|
getKey: o,
|
|
569
575
|
onPageLoaded: c,
|
|
570
|
-
onError:
|
|
571
|
-
} = a, [m, u] = _([]), [h, d] = _(t), [
|
|
576
|
+
onError: r
|
|
577
|
+
} = a, [m, u] = _([]), [h, d] = _(t), [y, S] = _(!0), [x, f] = _(!1), [F, z] = _(!1), [E, p] = _(!1), w = T(/* @__PURE__ */ new Set()), b = T(!1), C = M(
|
|
572
578
|
(l) => o ? l.filter((i) => {
|
|
573
579
|
const g = o(i);
|
|
574
|
-
return
|
|
580
|
+
return w.current.has(g) ? !1 : (w.current.add(g), !0);
|
|
575
581
|
}) : l,
|
|
576
582
|
[o]
|
|
577
583
|
), V = M(async () => {
|
|
578
|
-
if (!(
|
|
579
|
-
|
|
584
|
+
if (!(b.current || !y)) {
|
|
585
|
+
b.current = !0, p(!0);
|
|
580
586
|
try {
|
|
581
587
|
const l = h + 1, i = await e(l), g = C(i.data);
|
|
582
588
|
u(
|
|
583
|
-
(A) =>
|
|
589
|
+
(A) => s === "prepend" ? [...g, ...A] : [...A, ...g]
|
|
584
590
|
), d(l), S(i.hasNextPage), f(i.hasPrevPage), c == null || c(l, g);
|
|
585
591
|
} catch (l) {
|
|
586
|
-
|
|
592
|
+
r == null || r(l instanceof Error ? l : new Error(String(l)));
|
|
587
593
|
} finally {
|
|
588
|
-
p(!1),
|
|
594
|
+
p(!1), b.current = !1;
|
|
589
595
|
}
|
|
590
596
|
}
|
|
591
|
-
}, [h,
|
|
592
|
-
if (!(
|
|
593
|
-
|
|
597
|
+
}, [h, y, e, C, s, c, r]), N = M(async () => {
|
|
598
|
+
if (!(b.current || !x)) {
|
|
599
|
+
b.current = !0, p(!0);
|
|
594
600
|
try {
|
|
595
601
|
const l = h - 1, i = await e(l), g = C(i.data);
|
|
596
602
|
u((A) => [...g, ...A]), d(l), f(i.hasPrevPage), S(i.hasNextPage), c == null || c(l, g);
|
|
597
603
|
} catch (l) {
|
|
598
|
-
|
|
604
|
+
r == null || r(l instanceof Error ? l : new Error(String(l)));
|
|
599
605
|
} finally {
|
|
600
|
-
p(!1),
|
|
606
|
+
p(!1), b.current = !1;
|
|
601
607
|
}
|
|
602
608
|
}
|
|
603
|
-
}, [h, x, e, C, c,
|
|
604
|
-
if (!
|
|
605
|
-
|
|
609
|
+
}, [h, x, e, C, c, r]), H = M(async () => {
|
|
610
|
+
if (!b.current) {
|
|
611
|
+
b.current = !0, z(!0);
|
|
606
612
|
try {
|
|
607
613
|
const l = await e(t), i = l.data;
|
|
608
614
|
if (o) {
|
|
609
615
|
const g = new Set(i.map(o));
|
|
610
|
-
i.forEach((A) =>
|
|
616
|
+
i.forEach((A) => w.current.add(o(A))), u((A) => {
|
|
611
617
|
const L = A.filter((k) => !g.has(o(k)));
|
|
612
|
-
return
|
|
618
|
+
return s === "prepend" ? [...i, ...L] : [...L, ...i];
|
|
613
619
|
});
|
|
614
620
|
} else
|
|
615
621
|
u(i);
|
|
616
622
|
d(t), S(l.hasNextPage), f(l.hasPrevPage), c == null || c(t, i);
|
|
617
623
|
} catch (l) {
|
|
618
|
-
|
|
624
|
+
r == null || r(l instanceof Error ? l : new Error(String(l)));
|
|
619
625
|
} finally {
|
|
620
|
-
z(!1),
|
|
626
|
+
z(!1), b.current = !1;
|
|
621
627
|
}
|
|
622
628
|
}
|
|
623
|
-
}, [e, t, o,
|
|
624
|
-
u([]), d(t), S(!0), f(!1), z(!1), p(!1),
|
|
629
|
+
}, [e, t, o, s, c, r]), q = M(() => {
|
|
630
|
+
u([]), d(t), S(!0), f(!1), z(!1), p(!1), w.current.clear(), b.current = !1;
|
|
625
631
|
}, [t]);
|
|
626
632
|
return {
|
|
627
633
|
items: m,
|
|
628
634
|
loadNextPage: V,
|
|
629
635
|
loadPrevPage: N,
|
|
630
|
-
hasNextPage:
|
|
636
|
+
hasNextPage: y,
|
|
631
637
|
hasPrevPage: x,
|
|
632
|
-
loading:
|
|
638
|
+
loading: F,
|
|
633
639
|
loadingMore: E,
|
|
634
|
-
refresh:
|
|
640
|
+
refresh: H,
|
|
635
641
|
reset: q,
|
|
636
642
|
currentPage: h
|
|
637
643
|
};
|
|
638
644
|
}
|
|
639
645
|
export {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
646
|
+
pe as ChatVirtualList,
|
|
647
|
+
ve as VirtualList,
|
|
648
|
+
he as useChatVirtualizer,
|
|
649
|
+
ze as usePagination
|
|
644
650
|
};
|