react-anchorlist 0.3.5 → 0.3.7
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/useScrollAnchor.d.ts.map +1 -1
- package/dist/hooks/useVirtualEngine.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +293 -289
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScrollAnchor.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollAnchor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C,UAAU,sBAAsB;IAC9B,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,qBAAqB,EAAE,MAAM,cAAc,GAAG,IAAI,CAAA;IAClD,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IACnF,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;CACxB;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE;IACtD,QAAQ,EAAE,cAAc,CAAA;IACxB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;CACpF,GAAG,MAAM,CAgBT;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG;IAAE,aAAa,EAAE,MAAM,IAAI,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"useScrollAnchor.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollAnchor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C,UAAU,sBAAsB;IAC9B,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,qBAAqB,EAAE,MAAM,cAAc,GAAG,IAAI,CAAA;IAClD,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IACnF,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;CACxB;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE;IACtD,QAAQ,EAAE,cAAc,CAAA;IACxB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;CACpF,GAAG,MAAM,CAgBT;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG;IAAE,aAAa,EAAE,MAAM,IAAI,CAAA;CAAE,CAyF9F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVirtualEngine.d.ts","sourceRoot":"","sources":["../../src/hooks/useVirtualEngine.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAkB,sBAAsB,EAAe,MAAM,UAAU,CAAA;AAEnF;;;;;;;GAOG;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,EAAkB,sBAAsB,EAAe,MAAM,UAAU,CAAA;AAEnF;;;;;;;GAOG;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,CAqX5B"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),r=require("react");function he(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const te=he(r);class de{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 s=0;s<e;s++)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 me{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[s,l]of this.cache){const o=t.get(s);o!==void 0&&e.setSize(o,l)}}}function oe(i,e){if(i.length===0)return 0;let t=0,s=i.length-1;for(;t<s;){const l=t+s>>1;(i[l]??0)<e?t=l+1:s=l}return Math.max(0,t>0&&(i[t]??0)>e?t-1:t)}function pe(i,e,t){if(i.length===0)return 0;let s=0,l=i.length-1,o=0;for(;s<=l;){const n=s+l>>1;(i[n]??0)<t?(o=n,s=n+1):l=n-1}return o}function ge(i){const{firstVisible:e,lastVisible:t,itemCount:s,overscan:l}=i;return s===0?{start:0,end:-1}:{start:Math.max(0,e-l),end:Math.min(s-1,t+l)}}function Re(i,e,t,s){const l=s==null?void 0:s.reconcile,o=r.useRef(null);return r.useCallback((n,y)=>{const u=i.current,d=e.current;if(!u||!d)return;o.current!==null&&(cancelAnimationFrame(o.current),o.current=null);let R,h;if(typeof n=="object"&&n!==null?(R=n.index,h={align:n.align,behavior:n.behavior,offset:n.offset}):(R=n,h=y),!Number.isFinite(R))return;const p=Math.max(0,Math.min(Math.floor(R),d.count-1));d.getOffset(p),d.getSize(p);const I=(h==null?void 0:h.align)??"start",k=(h==null?void 0:h.behavior)??"auto",E=(h==null?void 0:h.offset)??0,a=()=>{var P;const H=e.current,f=i.current;if(!H||!f)return 0;const S=((P=t==null?void 0:t.current)==null?void 0:P.offsetTop)??0,v=H.getOffset(p),C=H.getSize(p);return I==="start"?S+v+E:I==="center"?S+v-f.clientHeight/2+C/2+E:S+v-f.clientHeight+C+E},w=a();((H,f)=>{typeof u.scrollTo=="function"?u.scrollTo({top:H,behavior:f}):u.scrollTop=H})(Math.max(0,w),k);const F=performance.now();let T=0;const j=12,L=300,D=1,K=()=>{o.current=null;const H=i.current;if(!H)return;const f=Math.max(0,a()),S=Math.abs(H.scrollTop-f),v=performance.now()-F>=L,C=T>=j;S<=D||v||C||(typeof H.scrollTo=="function"?H.scrollTo({top:f,behavior:"auto"}):H.scrollTop=f,T+=1,o.current=requestAnimationFrame(K))};o.current=requestAnimationFrame(K)},[i,e,t,l])}function ce(i){var se;const{items:e,getKey:t,estimatedItemSize:s,overscan:l,initialAlignment:o}=i,n=r.useRef(null),y=r.useRef(null),u=r.useRef(null),d=r.useRef(new me),R=r.useRef([]),h=r.useRef(new Map),p=r.useRef(e.length),I=r.useRef(null),k=r.useRef(null),E=r.useRef(!1),a=r.useRef(0),w=r.useRef(0),g=r.useRef(null),F=r.useRef(!1),T=r.useRef(null),j=r.useRef(0),L=r.useRef(0),D=r.useRef(0),K=r.useRef(null),H=r.useRef(!1),f=r.useRef(!1),[,S]=r.useState(0),v=r.useCallback(()=>S(c=>c+1),[]);u.current||(u.current=new de(e.length,s));const C=e.length>0?t(e[0],0):null,P=e.length>0?t(e[e.length-1],e.length-1):null;if(e.length!==p.current||C!==I.current||P!==k.current){const c=u.current,m=e.map((O,W)=>t(O,W)),z=R.current,x=z.length,M=m.length;if(M===0)c.resize(0);else if(x===0)c.resize(M);else if(M>x){const O=M-x;z.length>0&&O>=0&&m[O]===z[0]?c.prepend(O):c.resize(M)}else M<x,c.resize(M);const A=new Map;m.forEach((O,W)=>A.set(O,W)),h.current=A,d.current.applyToOffsetMap(c,A),R.current=m,p.current=e.length,I.current=C,k.current=P}const b=r.useCallback(()=>{K.current===null&&(K.current=requestAnimationFrame(()=>{K.current=null;const c=n.current;if(!c)return;const m=j.current;Math.abs(m)<.01||(j.current=0,L.current+=m,D.current+=m,c.scrollTop+=m,a.current=c.scrollTop,H.current=!0,v())}))},[v]);r.useEffect(()=>{const c=n.current;if(!c)return;const m=()=>{g.current===null&&(g.current=requestAnimationFrame(()=>{g.current=null,a.current=c.scrollTop,w.current=c.clientHeight,H.current&&(H.current=!1,L.current=0,D.current=0),v()}))};return c.addEventListener("scroll",m,{passive:!0}),()=>{c.removeEventListener("scroll",m),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),K.current!==null&&(cancelAnimationFrame(K.current),K.current=null)}},[v]),r.useEffect(()=>{const c=n.current;if(!c)return;w.current=c.clientHeight,a.current=c.scrollTop;const m=new ResizeObserver(([z])=>{z&&(w.current=z.contentRect.height,v())});return m.observe(c),()=>m.disconnect()},[v]),r.useLayoutEffect(()=>{if(E.current||e.length===0)return;const c=n.current;if(c){if(o==="bottom"){c.scrollTop=c.scrollHeight,a.current=c.scrollTop,w.current=c.clientHeight,F.current=!0,T.current!==null&&cancelAnimationFrame(T.current);const m=performance.now();let z=0,x=c.scrollHeight;const M=()=>{if(!F.current){T.current=null;return}const A=c.scrollHeight,O=Math.abs(A-x);x=A,O<1?z+=1:z=0,c.scrollTop=c.scrollHeight,a.current=c.scrollTop;const W=performance.now()-m;if(z>=3||W>=500){F.current=!1,T.current=null;return}T.current=requestAnimationFrame(M)};T.current=requestAnimationFrame(M)}E.current=!0}},[o,e.length]),r.useEffect(()=>{e.length===0&&(E.current=!1,F.current=!1,T.current!==null&&(cancelAnimationFrame(T.current),T.current=null))},[e.length]);const B=r.useCallback((c,m)=>{var X;const z=u.current;if(!z||d.current.get(c)===m)return;d.current.set(c,m);const M=h.current.get(c);if(M===void 0)return;const A=z.getSize(M),O=m-A,W=n.current;W&&!F.current&&!f.current&&O!==0&&z.getOffset(M)+A+(((X=y.current)==null?void 0:X.offsetTop)??0)<W.scrollTop&&(j.current+=O,b()),z.setSize(M,m)&&v()},[b,v]),V=r.useCallback((c,m="auto")=>{var z;(z=n.current)==null||z.scrollTo({top:c,behavior:m})},[]),Y=Re(n,u,y,{reconcile:!0}),N=r.useCallback(()=>{var Z;const c=n.current,m=u.current;if(!c||!m||m.count===0)return null;const z=((Z=y.current)==null?void 0:Z.offsetTop)??0,x=Math.max(0,c.scrollTop-z),M=m.getOffsets(),A=oe(M,x),O=R.current[A]??null,W=[];for(let X=A;X<Math.min(m.count,A+6);X++){const ee=R.current[X]??null;ee!==null&&W.push({key:ee,offsetWithinItem:x-m.getOffset(X)})}return{key:O,offsetWithinItem:x-m.getOffset(A),candidates:W,scrollTop:c.scrollTop,scrollHeight:c.scrollHeight}},[]),$=r.useCallback((c,m)=>{var A;const z=u.current;if(!z)return null;const x=h.current.get(c);return x===void 0?null:(((A=y.current)==null?void 0:A.offsetTop)??0)+z.getOffset(x)+m},[]),_=u.current,ue=_?_.totalSize():0,J=n.current,G=(J==null?void 0:J.scrollTop)??a.current,re=(J==null?void 0:J.clientHeight)??w.current,ae=((se=y.current)==null?void 0:se.offsetTop)??0,ne=Math.max(0,G-ae),Q=[];if(_&&_.count>0&&re>0){const c=_.getOffsets(),m=_.getSizes(),z=oe(c,ne),x=pe(c,m,ne+re),M=ge({firstVisible:z,lastVisible:x,itemCount:_.count,overscan:l});for(let A=M.start;A<=M.end&&A<e.length;A++)Q.push({key:R.current[A]??t(e[A],A),index:A,start:_.getOffset(A),size:_.getSize(A),data:e[A]})}else if(_&&_.count>0){const c=Math.min(e.length,l*2+1),m=o==="bottom"?Math.max(0,e.length-c):0,z=m+c-1;for(let x=m;x<=z;x++)Q.push({key:R.current[x]??t(e[x],x),index:x,start:_.getOffset(x),size:_.getSize(x),data:e[x]})}const fe=J?J.scrollHeight-J.scrollTop-J.clientHeight:1/0;return{scrollerRef:n,innerRef:y,virtualItems:Q,totalSize:ue,measureItem:B,scrollToIndex:Y,scrollToOffset:V,captureAnchorSnapshot:N,resolveAnchorTop:$,isAtTop:G<=1,isAtBottom:fe<=1,scrollTop:G,jumpSuppressedRef:f}}function ve(i){var l;const{snapshot:e,currentScrollHeight:t,resolveAnchorTop:s}=i;if(e.key!==null){const o=s(e.key,e.offsetWithinItem);if(o!==null)return o}if((l=e.candidates)!=null&&l.length)for(const o of e.candidates){const n=s(o.key,o.offsetWithinItem);if(n!==null)return n}return e.scrollTop+(t-e.scrollHeight)}function ye(i){const{scrollerRef:e,itemCount:t,captureAnchorSnapshot:s,resolveAnchorTop:l,onRestored:o}=i,n=r.useRef(null),y=r.useRef(!1),u=r.useRef({first:null,second:null,timeout:null}),d=r.useCallback(()=>{const{first:h,second:p,timeout:I}=u.current;h&&cancelAnimationFrame(h),p&&cancelAnimationFrame(p),I&&clearTimeout(I),u.current={first:null,second:null,timeout:null}},[]),R=r.useCallback(()=>{const h=e.current;if(!h)return;const p=s();n.current=p??{key:null,offsetWithinItem:0,scrollTop:h.scrollTop,scrollHeight:h.scrollHeight},y.current=!0},[e,s]);return r.useLayoutEffect(()=>{if(!y.current)return;const h=e.current,p=n.current;if(!h||!p)return;y.current=!1;const I=()=>{const k=ve({snapshot:p,currentScrollHeight:h.scrollHeight,resolveAnchorTop:l});Number.isFinite(k)&&Math.abs(h.scrollTop-k)>1&&(h.scrollTop=k)};return d(),I(),o==null||o(),u.current.first=requestAnimationFrame(()=>{u.current.first=null,I(),u.current.second=requestAnimationFrame(()=>{u.current.second=null,I()})}),u.current.timeout=setTimeout(()=>{u.current.timeout=null,I()},90),()=>d()},[t,e,l,d,o]),{prepareAnchor:R}}function Te(i){const{previous:e,distanceFromBottom:t,threshold:s,hysteresis:l}=i;if(!l)return t<=s;const o=Math.max(0,l.enter),n=Math.max(o,l.leave);return e?t<=n:t<=o}function Se(i,e){const t=typeof e=="number"?e:e.threshold??200,s=typeof e=="number"?void 0:e.hysteresis,[l,o]=r.useState(!0),n=r.useRef(null),y=r.useRef(!0);return r.useEffect(()=>{const u=i.current;if(!u)return;const d=()=>{const h=u.scrollHeight-u.scrollTop-u.clientHeight,p=Te({previous:y.current,distanceFromBottom:h,threshold:t,hysteresis:s});y.current=p,o(p)},R=()=>{n.current!==null&&cancelAnimationFrame(n.current),n.current=requestAnimationFrame(d)};return u.addEventListener("scroll",R,{passive:!0}),d(),()=>{u.removeEventListener("scroll",R),n.current!==null&&cancelAnimationFrame(n.current)}},[i,t,s==null?void 0:s.enter,s==null?void 0:s.leave]),l}function be(i){const{itemCount:e,firstKey:t,lastKey:s,isAtBottom:l,scrollToIndex:o,mode:n}=i,y=r.useRef(e),u=r.useRef(t),d=r.useRef(s);r.useLayoutEffect(()=>{if(!n){y.current=e,u.current=t,d.current=s;return}const R=y.current,h=u.current,p=d.current;e>R&&t===h&&s!==p&&l&&e>0&&o(e-1,{align:"end",behavior:n==="smooth"?"smooth":"auto"}),y.current=e,u.current=t,d.current=s},[e,t,s,l,o,n])}function le(i){const{items:e,getKey:t,estimatedItemSize:s=80,overscan:l=20,atBottomThreshold:o=200,atBottomHysteresis:n,followOutput:y="auto",initialAlignment:u="bottom",scrollModifier:d=null,onStartReached:R,onEndReached:h,startReachedThreshold:p=300,endReachedThreshold:I=300,scrollToMessageKey:k,onScrollToMessageComplete:E}=i,a=ce({items:e,getKey:t,estimatedItemSize:s,overscan:l,initialAlignment:u}),w=Se(a.scrollerRef,{threshold:o,hysteresis:n??{enter:80,leave:160}}),[,g]=r.useState(0),F=r.useRef(null),T=r.useCallback(()=>{g(b=>b+1),F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{a.jumpSuppressedRef.current=!1,F.current=null},200)},[a.jumpSuppressedRef]),{prepareAnchor:j}=ye({scrollerRef:a.scrollerRef,itemCount:e.length,captureAnchorSnapshot:a.captureAnchorSnapshot,resolveAnchorTop:a.resolveAnchorTop,onRestored:T}),L=r.useCallback(()=>{a.jumpSuppressedRef.current=!0,j()},[j,a.jumpSuppressedRef]),D=e.length>0?t(e[0],0):null,K=e.length>0?t(e[e.length-1],e.length-1):null;be({itemCount:e.length,firstKey:D,lastKey:K,isAtBottom:w,scrollToIndex:a.scrollToIndex,mode:y??!1});const H=r.useCallback((b="auto")=>{e.length!==0&&a.scrollToIndex(e.length-1,{align:"end",behavior:b})},[e.length,a]),f=r.useCallback((b,B)=>{const V=e.findIndex((Y,N)=>t(Y,N)===b);V!==-1&&a.scrollToIndex(V,B)},[e,t,a]),S=r.useRef(null);r.useLayoutEffect(()=>{if(d&&S.current!==d.id){if(S.current=d.id,d.type==="prepend"){L();return}if(d.type==="append"){if(d.ifAtBottomOnly&&!w)return;H(d.behavior??"auto");return}if(d.type==="items-change"){w&&H("auto");return}f(d.key,{align:d.align??"center",behavior:d.behavior??"auto"})}},[d,w,L,H,f]);const v=r.useRef(!1),C=r.useRef(u==="top");r.useEffect(()=>{const b=a.scrollerRef.current;if(!b||!R)return;const B=()=>{const V=b.scrollTop;C.current||(b.scrollHeight<=b.clientHeight+p||V>p)&&(C.current=!0),C.current&&V<=p&&!v.current&&(v.current=!0,Promise.resolve(R()).finally(()=>{v.current=!1}))};return b.addEventListener("scroll",B,{passive:!0}),B(),()=>b.removeEventListener("scroll",B)},[a.scrollerRef,R,p,u]);const P=r.useRef(!1);r.useEffect(()=>{const b=a.scrollerRef.current;if(!b||!h)return;const B=()=>{b.scrollHeight-b.scrollTop-b.clientHeight<=I&&!P.current&&(P.current=!0,Promise.resolve(h()).finally(()=>{P.current=!1}))};return b.addEventListener("scroll",B,{passive:!0}),()=>b.removeEventListener("scroll",B)},[a.scrollerRef,h,I]);const U=r.useRef(null);return r.useEffect(()=>{if(!k||U.current===k)return;const b=e.findIndex((B,V)=>t(B,V)===k);b!==-1&&(U.current=k,a.scrollToIndex(b,{align:"center",behavior:"auto"}),E==null||E())},[k,e,t,a,E]),{scrollerRef:a.scrollerRef,innerRef:a.innerRef,virtualItems:a.virtualItems,totalSize:a.totalSize,measureItem:a.measureItem,scrollToIndex:a.scrollToIndex,scrollToBottom:H,scrollToKey:f,isAtBottom:w,prepareAnchor:L}}function ie({virtualItem:i,measureItem:e,children:t}){const s=r.useRef(null),l=r.useRef(!1);return r.useEffect(()=>{const o=s.current;if(!o)return;l.current=!1;const n=new ResizeObserver(([y])=>{y&&(l.current=!0,e(i.key,y.contentRect.height))});return n.observe(o),()=>n.disconnect()},[i.key,e]),q.jsx("div",{ref:s,style:{position:"absolute",top:0,transform:`translateY(${i.start}px)`,width:"100%",minHeight:l.current?void 0:i.size},children:t})}function Ae(i,e){const{data:t,itemContent:s,computeItemKey:l,estimatedItemSize:o=80,overscan:n=20,followOutput:y="auto",atBottomThreshold:u=200,atBottomHysteresis:d,initialAlignment:R="bottom",scrollModifier:h,onStartReached:p,onEndReached:I,startReachedThreshold:k=300,endReachedThreshold:E=300,scrollToMessageKey:a,onScrollToMessageComplete:w,onAtBottomChange:g,components:F={},className:T,style:j}=i,{scrollerRef:L,innerRef:D,virtualItems:K,totalSize:H,measureItem:f,scrollToIndex:S,scrollToBottom:v,scrollToKey:C,isAtBottom:P,prepareAnchor:U}=le({items:t,getKey:(N,$)=>l($,N),estimatedItemSize:o,overscan:n,atBottomThreshold:u,atBottomHysteresis:d,followOutput:y,initialAlignment:R,scrollModifier:h,onStartReached:p,onEndReached:I,startReachedThreshold:k,endReachedThreshold:E,scrollToMessageKey:a,onScrollToMessageComplete:w}),b=te.useRef(P);te.useEffect(()=>{b.current!==P&&(b.current=P,g==null||g(P))},[P,g]),r.useImperativeHandle(e,()=>({scrollToBottom:v,scrollToIndex:S,scrollToKey:C,getScrollTop:()=>{var N;return((N=L.current)==null?void 0:N.scrollTop)??0},isAtBottom:()=>P,prepareAnchor:U}),[v,S,C,L,P,U]);const{Header:B,Footer:V,EmptyPlaceholder:Y}=F;return t.length===0&&Y?q.jsx(Y,{}):q.jsxs("div",{ref:L,className:T,style:{overflow:"auto",height:"100%",position:"relative",overflowAnchor:"none",overscrollBehaviorY:"contain",...j},children:[B&&q.jsx(B,{}),q.jsx("div",{ref:D,style:{height:H,position:"relative",width:"100%"},children:K.map(N=>q.jsx(ie,{virtualItem:N,measureItem:f,children:s(N.index,N.data)},N.key))}),V&&q.jsx(V,{})]})}const ze=r.forwardRef(Ae);function xe({data:i,itemContent:e,computeItemKey:t,estimatedItemSize:s=60,overscan:l=20,onEndReached:o,endReachedThreshold:n=300,components:y={},className:u,style:d}){const{scrollerRef:R,innerRef:h,virtualItems:p,totalSize:I,measureItem:k}=ce({items:i,getKey:(g,F)=>t(F,g),estimatedItemSize:s,overscan:l,initialAlignment:"top"});te.useEffect(()=>{const g=R.current;if(!g||!o)return;let F=!1;const T=()=>{g.scrollHeight-g.scrollTop-g.clientHeight<=n&&!F&&(F=!0,Promise.resolve(o()).finally(()=>{F=!1}))};return g.addEventListener("scroll",T,{passive:!0}),()=>g.removeEventListener("scroll",T)},[R,o,n]);const{Header:E,Footer:a,EmptyPlaceholder:w}=y;return i.length===0&&w?q.jsx(w,{}):q.jsxs("div",{ref:R,className:u,style:{overflow:"auto",height:"100%",position:"relative",overflowAnchor:"none",overscrollBehaviorY:"contain",...d},children:[E&&q.jsx(E,{}),q.jsx("div",{ref:h,style:{height:I,position:"relative",width:"100%"},children:p.map(g=>q.jsx(ie,{virtualItem:g,measureItem:k,children:e(g.index,g.data)},g.key))}),a&&q.jsx(a,{})]})}function Ie(i){const{fetcher:e,initialPage:t=1,direction:s="append",getKey:l,onPageLoaded:o,onError:n}=i,[y,u]=r.useState([]),[d,R]=r.useState(t),[h,p]=r.useState(!0),[I,k]=r.useState(!1),[E,a]=r.useState(!1),[w,g]=r.useState(!1),F=r.useRef(new Set),T=r.useRef(!1),j=r.useCallback(f=>l?f.filter(S=>{const v=l(S);return F.current.has(v)?!1:(F.current.add(v),!0)}):f,[l]),L=r.useCallback(async()=>{if(!(T.current||!h)){T.current=!0,g(!0);try{const f=d+1,S=await e(f),v=j(S.data);u(C=>s==="prepend"?[...v,...C]:[...C,...v]),R(f),p(S.hasNextPage),k(S.hasPrevPage),o==null||o(f,v)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{g(!1),T.current=!1}}},[d,h,e,j,s,o,n]),D=r.useCallback(async()=>{if(!(T.current||!I)){T.current=!0,g(!0);try{const f=d-1,S=await e(f),v=j(S.data);u(C=>[...v,...C]),R(f),k(S.hasPrevPage),p(S.hasNextPage),o==null||o(f,v)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{g(!1),T.current=!1}}},[d,I,e,j,o,n]),K=r.useCallback(async()=>{if(!T.current){T.current=!0,a(!0);try{const f=await e(t),S=f.data;if(l){const v=new Set(S.map(l));S.forEach(C=>F.current.add(l(C))),u(C=>{const P=C.filter(U=>!v.has(l(U)));return s==="prepend"?[...S,...P]:[...P,...S]})}else u(S);R(t),p(f.hasNextPage),k(f.hasPrevPage),o==null||o(t,S)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{a(!1),T.current=!1}}},[e,t,l,s,o,n]),H=r.useCallback(()=>{u([]),R(t),p(!0),k(!1),a(!1),g(!1),F.current.clear(),T.current=!1},[t]);return{items:y,loadNextPage:L,loadPrevPage:D,hasNextPage:h,hasPrevPage:I,loading:E,loadingMore:w,refresh:K,reset:H,currentPage:d}}exports.ChatVirtualList=ze;exports.VirtualList=xe;exports.useChatVirtualizer=le;exports.usePagination=Ie;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),r=require("react");function he(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const te=he(r);class de{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 s=0;s<e;s++)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 me{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[s,l]of this.cache){const o=t.get(s);o!==void 0&&e.setSize(o,l)}}}function oe(i,e){if(i.length===0)return 0;let t=0,s=i.length-1;for(;t<s;){const l=t+s>>1;(i[l]??0)<e?t=l+1:s=l}return Math.max(0,t>0&&(i[t]??0)>e?t-1:t)}function pe(i,e,t){if(i.length===0)return 0;let s=0,l=i.length-1,o=0;for(;s<=l;){const n=s+l>>1;(i[n]??0)<t?(o=n,s=n+1):l=n-1}return o}function ge(i){const{firstVisible:e,lastVisible:t,itemCount:s,overscan:l}=i;return s===0?{start:0,end:-1}:{start:Math.max(0,e-l),end:Math.min(s-1,t+l)}}function Re(i,e,t,s){const l=s==null?void 0:s.reconcile,o=r.useRef(null);return r.useCallback((n,y)=>{const u=i.current,d=e.current;if(!u||!d)return;o.current!==null&&(cancelAnimationFrame(o.current),o.current=null);let R,a;if(typeof n=="object"&&n!==null?(R=n.index,a={align:n.align,behavior:n.behavior,offset:n.offset}):(R=n,a=y),!Number.isFinite(R))return;const p=Math.max(0,Math.min(Math.floor(R),d.count-1));d.getOffset(p),d.getSize(p);const F=(a==null?void 0:a.align)??"start",E=(a==null?void 0:a.behavior)??"auto",I=(a==null?void 0:a.offset)??0,h=()=>{var P;const M=e.current,f=i.current;if(!M||!f)return 0;const S=((P=t==null?void 0:t.current)==null?void 0:P.offsetTop)??0,v=M.getOffset(p),k=M.getSize(p);return F==="start"?S+v+I:F==="center"?S+v-f.clientHeight/2+k/2+I:S+v-f.clientHeight+k+I},w=h();((M,f)=>{typeof u.scrollTo=="function"?u.scrollTo({top:M,behavior:f}):u.scrollTop=M})(Math.max(0,w),E);const H=performance.now();let T=0;const j=12,L=300,J=1,K=()=>{o.current=null;const M=i.current;if(!M)return;const f=Math.max(0,h()),S=Math.abs(M.scrollTop-f),v=performance.now()-H>=L,k=T>=j;S<=J||v||k||(typeof M.scrollTo=="function"?M.scrollTo({top:f,behavior:"auto"}):M.scrollTop=f,T+=1,o.current=requestAnimationFrame(K))};o.current=requestAnimationFrame(K)},[i,e,t,l])}function ce(i){var se;const{items:e,getKey:t,estimatedItemSize:s,overscan:l,initialAlignment:o}=i,n=r.useRef(null),y=r.useRef(null),u=r.useRef(null),d=r.useRef(new me),R=r.useRef([]),a=r.useRef(new Map),p=r.useRef(e.length),F=r.useRef(null),E=r.useRef(null),I=r.useRef(!1),h=r.useRef(0),w=r.useRef(0),g=r.useRef(null),H=r.useRef(!1),T=r.useRef(null),j=r.useRef(0),L=r.useRef(0),J=r.useRef(0),K=r.useRef(null),M=r.useRef(!1),f=r.useRef(!1),[,S]=r.useState(0),v=r.useCallback(()=>S(c=>c+1),[]);u.current||(u.current=new de(e.length,s));const k=e.length>0?t(e[0],0):null,P=e.length>0?t(e[e.length-1],e.length-1):null;if(e.length!==p.current||k!==F.current||P!==E.current){const c=u.current,m=e.map((O,_)=>t(O,_)),z=R.current,x=z.length,C=m.length;if(C===0)c.resize(0);else if(x===0)c.resize(C);else if(C>x){const O=C-x;z.length>0&&O>=0&&m[O]===z[0]?c.prepend(O):c.resize(C)}else C<x,c.resize(C);const b=new Map;m.forEach((O,_)=>b.set(O,_)),a.current=b,d.current.applyToOffsetMap(c,b),R.current=m,p.current=e.length,F.current=k,E.current=P}const A=r.useCallback(()=>{K.current===null&&(K.current=requestAnimationFrame(()=>{K.current=null;const c=n.current;if(!c)return;const m=j.current;Math.abs(m)<.01||(j.current=0,L.current+=m,J.current+=m,c.scrollTop+=m,h.current=c.scrollTop,M.current=!0,v())}))},[v]);r.useEffect(()=>{const c=n.current;if(!c)return;const m=()=>{g.current===null&&(g.current=requestAnimationFrame(()=>{g.current=null,h.current=c.scrollTop,w.current=c.clientHeight,M.current&&(M.current=!1,L.current=0,J.current=0),v()}))};return c.addEventListener("scroll",m,{passive:!0}),()=>{c.removeEventListener("scroll",m),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),K.current!==null&&(cancelAnimationFrame(K.current),K.current=null)}},[v]),r.useEffect(()=>{const c=n.current;if(!c)return;w.current=c.clientHeight,h.current=c.scrollTop;const m=new ResizeObserver(([z])=>{z&&(w.current=z.contentRect.height,v())});return m.observe(c),()=>m.disconnect()},[v]),r.useLayoutEffect(()=>{if(I.current||e.length===0)return;const c=n.current;if(c){if(o==="bottom"){c.scrollTop=c.scrollHeight,h.current=c.scrollTop,w.current=c.clientHeight,H.current=!0,T.current!==null&&cancelAnimationFrame(T.current);const m=performance.now();let z=0,x=c.scrollHeight;const C=()=>{if(!H.current){T.current=null;return}const b=c.scrollHeight,O=Math.abs(b-x);x=b,O<1?z+=1:z=0,c.scrollTop=c.scrollHeight,h.current=c.scrollTop;const _=performance.now()-m;if(z>=3||_>=500){H.current=!1,T.current=null;return}T.current=requestAnimationFrame(C)};T.current=requestAnimationFrame(C)}I.current=!0}},[o,e.length]),r.useEffect(()=>{e.length===0&&(I.current=!1,H.current=!1,T.current!==null&&(cancelAnimationFrame(T.current),T.current=null))},[e.length]);const B=r.useCallback((c,m)=>{var Y;const z=u.current;if(!z||d.current.get(c)===m)return;d.current.set(c,m);const C=a.current.get(c);if(C===void 0)return;const b=z.getSize(C),O=m-b,_=n.current;if(_&&!H.current&&!f.current&&O!==0){const X=z.getOffset(C)+b+(((Y=y.current)==null?void 0:Y.offsetTop)??0);X<_.scrollTop&&(console.log(`[JUMP] key=${c} idx=${C} delta=${O} itemBottom=${Math.round(X)} scrollTop=${Math.round(_.scrollTop)} suppressed=${f.current}`),j.current+=O,A())}z.setSize(C,m)&&v()},[A,v]),N=r.useCallback((c,m="auto")=>{var z;(z=n.current)==null||z.scrollTo({top:c,behavior:m})},[]),D=Re(n,u,y,{reconcile:!0}),V=r.useCallback(()=>{var ee;const c=n.current,m=u.current;if(!c||!m||m.count===0)return null;const z=((ee=y.current)==null?void 0:ee.offsetTop)??0,x=Math.max(0,c.scrollTop-z),C=m.getOffsets(),b=oe(C,x),O=R.current[b]??null,_=[];for(let Y=b;Y<Math.min(m.count,b+6);Y++){const X=R.current[Y]??null;X!==null&&_.push({key:X,offsetWithinItem:x-m.getOffset(Y)})}return{key:O,offsetWithinItem:x-m.getOffset(b),candidates:_,scrollTop:c.scrollTop,scrollHeight:c.scrollHeight}},[]),G=r.useCallback((c,m)=>{var b;const z=u.current;if(!z)return null;const x=a.current.get(c);return x===void 0?null:(((b=y.current)==null?void 0:b.offsetTop)??0)+z.getOffset(x)+m},[]),$=u.current,ue=$?$.totalSize():0,W=n.current,Q=(W==null?void 0:W.scrollTop)??h.current,re=(W==null?void 0:W.clientHeight)??w.current,ae=((se=y.current)==null?void 0:se.offsetTop)??0,ne=Math.max(0,Q-ae),Z=[];if($&&$.count>0&&re>0){const c=$.getOffsets(),m=$.getSizes(),z=oe(c,ne),x=pe(c,m,ne+re),C=ge({firstVisible:z,lastVisible:x,itemCount:$.count,overscan:l});for(let b=C.start;b<=C.end&&b<e.length;b++)Z.push({key:R.current[b]??t(e[b],b),index:b,start:$.getOffset(b),size:$.getSize(b),data:e[b]})}else if($&&$.count>0){const c=Math.min(e.length,l*2+1),m=o==="bottom"?Math.max(0,e.length-c):0,z=m+c-1;for(let x=m;x<=z;x++)Z.push({key:R.current[x]??t(e[x],x),index:x,start:$.getOffset(x),size:$.getSize(x),data:e[x]})}const fe=W?W.scrollHeight-W.scrollTop-W.clientHeight:1/0;return{scrollerRef:n,innerRef:y,virtualItems:Z,totalSize:ue,measureItem:B,scrollToIndex:D,scrollToOffset:N,captureAnchorSnapshot:V,resolveAnchorTop:G,isAtTop:Q<=1,isAtBottom:fe<=1,scrollTop:Q,jumpSuppressedRef:f}}function ve(i){var l;const{snapshot:e,currentScrollHeight:t,resolveAnchorTop:s}=i;if(e.key!==null){const o=s(e.key,e.offsetWithinItem);if(o!==null)return o}if((l=e.candidates)!=null&&l.length)for(const o of e.candidates){const n=s(o.key,o.offsetWithinItem);if(n!==null)return n}return e.scrollTop+(t-e.scrollHeight)}function ye(i){const{scrollerRef:e,itemCount:t,captureAnchorSnapshot:s,resolveAnchorTop:l,onRestored:o}=i,n=r.useRef(null),y=r.useRef(!1),u=r.useRef({first:null,second:null,timeout:null}),d=r.useCallback(()=>{const{first:a,second:p,timeout:F}=u.current;a&&cancelAnimationFrame(a),p&&cancelAnimationFrame(p),F&&clearTimeout(F),u.current={first:null,second:null,timeout:null}},[]),R=r.useCallback(()=>{const a=e.current;if(!a)return;const p=s();n.current=p??{key:null,offsetWithinItem:0,scrollTop:a.scrollTop,scrollHeight:a.scrollHeight},y.current=!0,console.log("[ANCHOR] prepareAnchor snapshot:",JSON.stringify(n.current,null,2))},[e,s]);return r.useLayoutEffect(()=>{if(!y.current)return;const a=e.current,p=n.current;if(!a||!p)return;y.current=!1;const F=E=>{const I=ve({snapshot:p,currentScrollHeight:a.scrollHeight,resolveAnchorTop:l});console.log(`[ANCHOR] restore(${E}): target=${Math.round(I)}, currentScrollTop=${Math.round(a.scrollTop)}, scrollHeight=${a.scrollHeight}, snapshotKey=${p.key}, delta=${Math.round(I-a.scrollTop)}`),Number.isFinite(I)&&Math.abs(a.scrollTop-I)>1&&(a.scrollTop=I)};return d(),F("layout"),o==null||o(),u.current.first=requestAnimationFrame(()=>{u.current.first=null,F("raf1"),u.current.second=requestAnimationFrame(()=>{u.current.second=null,F("raf2")})}),u.current.timeout=setTimeout(()=>{u.current.timeout=null,F("timeout")},90),()=>d()},[t,e,l,d,o]),{prepareAnchor:R}}function Te(i){const{previous:e,distanceFromBottom:t,threshold:s,hysteresis:l}=i;if(!l)return t<=s;const o=Math.max(0,l.enter),n=Math.max(o,l.leave);return e?t<=n:t<=o}function Se(i,e){const t=typeof e=="number"?e:e.threshold??200,s=typeof e=="number"?void 0:e.hysteresis,[l,o]=r.useState(!0),n=r.useRef(null),y=r.useRef(!0);return r.useEffect(()=>{const u=i.current;if(!u)return;const d=()=>{const a=u.scrollHeight-u.scrollTop-u.clientHeight,p=Te({previous:y.current,distanceFromBottom:a,threshold:t,hysteresis:s});y.current=p,o(p)},R=()=>{n.current!==null&&cancelAnimationFrame(n.current),n.current=requestAnimationFrame(d)};return u.addEventListener("scroll",R,{passive:!0}),d(),()=>{u.removeEventListener("scroll",R),n.current!==null&&cancelAnimationFrame(n.current)}},[i,t,s==null?void 0:s.enter,s==null?void 0:s.leave]),l}function Ae(i){const{itemCount:e,firstKey:t,lastKey:s,isAtBottom:l,scrollToIndex:o,mode:n}=i,y=r.useRef(e),u=r.useRef(t),d=r.useRef(s);r.useLayoutEffect(()=>{if(!n){y.current=e,u.current=t,d.current=s;return}const R=y.current,a=u.current,p=d.current;e>R&&t===a&&s!==p&&l&&e>0&&o(e-1,{align:"end",behavior:n==="smooth"?"smooth":"auto"}),y.current=e,u.current=t,d.current=s},[e,t,s,l,o,n])}function le(i){const{items:e,getKey:t,estimatedItemSize:s=80,overscan:l=20,atBottomThreshold:o=200,atBottomHysteresis:n,followOutput:y="auto",initialAlignment:u="bottom",scrollModifier:d=null,onStartReached:R,onEndReached:a,startReachedThreshold:p=300,endReachedThreshold:F=300,scrollToMessageKey:E,onScrollToMessageComplete:I}=i,h=ce({items:e,getKey:t,estimatedItemSize:s,overscan:l,initialAlignment:u}),w=Se(h.scrollerRef,{threshold:o,hysteresis:n??{enter:80,leave:160}}),[,g]=r.useState(0),H=r.useRef(null),T=r.useCallback(()=>{g(A=>A+1),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{h.jumpSuppressedRef.current=!1,H.current=null},200)},[h.jumpSuppressedRef]),{prepareAnchor:j}=ye({scrollerRef:h.scrollerRef,itemCount:e.length,captureAnchorSnapshot:h.captureAnchorSnapshot,resolveAnchorTop:h.resolveAnchorTop,onRestored:T}),L=r.useCallback(()=>{h.jumpSuppressedRef.current=!0,j()},[j,h.jumpSuppressedRef]),J=e.length>0?t(e[0],0):null,K=e.length>0?t(e[e.length-1],e.length-1):null;Ae({itemCount:e.length,firstKey:J,lastKey:K,isAtBottom:w,scrollToIndex:h.scrollToIndex,mode:y??!1});const M=r.useCallback((A="auto")=>{e.length!==0&&h.scrollToIndex(e.length-1,{align:"end",behavior:A})},[e.length,h]),f=r.useCallback((A,B)=>{const N=e.findIndex((D,V)=>t(D,V)===A);N!==-1&&h.scrollToIndex(N,B)},[e,t,h]),S=r.useRef(null);r.useLayoutEffect(()=>{if(d&&S.current!==d.id){if(S.current=d.id,d.type==="prepend"){L();return}if(d.type==="append"){if(d.ifAtBottomOnly&&!w)return;M(d.behavior??"auto");return}if(d.type==="items-change"){w&&M("auto");return}f(d.key,{align:d.align??"center",behavior:d.behavior??"auto"})}},[d,w,L,M,f]);const v=r.useRef(!1),k=r.useRef(u==="top");r.useEffect(()=>{const A=h.scrollerRef.current;if(!A||!R)return;const B=()=>{const N=A.scrollTop;k.current||(A.scrollHeight<=A.clientHeight+p||N>p)&&(k.current=!0),k.current&&N<=p&&!v.current&&(v.current=!0,Promise.resolve(R()).finally(()=>{v.current=!1}))};return A.addEventListener("scroll",B,{passive:!0}),B(),()=>A.removeEventListener("scroll",B)},[h.scrollerRef,R,p,u]);const P=r.useRef(!1);r.useEffect(()=>{const A=h.scrollerRef.current;if(!A||!a)return;const B=()=>{A.scrollHeight-A.scrollTop-A.clientHeight<=F&&!P.current&&(P.current=!0,Promise.resolve(a()).finally(()=>{P.current=!1}))};return A.addEventListener("scroll",B,{passive:!0}),()=>A.removeEventListener("scroll",B)},[h.scrollerRef,a,F]);const U=r.useRef(null);return r.useEffect(()=>{if(!E||U.current===E)return;const A=e.findIndex((B,N)=>t(B,N)===E);A!==-1&&(U.current=E,h.scrollToIndex(A,{align:"center",behavior:"auto"}),I==null||I())},[E,e,t,h,I]),{scrollerRef:h.scrollerRef,innerRef:h.innerRef,virtualItems:h.virtualItems,totalSize:h.totalSize,measureItem:h.measureItem,scrollToIndex:h.scrollToIndex,scrollToBottom:M,scrollToKey:f,isAtBottom:w,prepareAnchor:L}}function ie({virtualItem:i,measureItem:e,children:t}){const s=r.useRef(null),l=r.useRef(!1);return r.useEffect(()=>{const o=s.current;if(!o)return;l.current=!1;const n=new ResizeObserver(([y])=>{y&&(l.current=!0,e(i.key,y.contentRect.height))});return n.observe(o),()=>n.disconnect()},[i.key,e]),q.jsx("div",{ref:s,style:{position:"absolute",top:0,transform:`translateY(${i.start}px)`,width:"100%",minHeight:l.current?void 0:i.size},children:t})}function be(i,e){const{data:t,itemContent:s,computeItemKey:l,estimatedItemSize:o=80,overscan:n=20,followOutput:y="auto",atBottomThreshold:u=200,atBottomHysteresis:d,initialAlignment:R="bottom",scrollModifier:a,onStartReached:p,onEndReached:F,startReachedThreshold:E=300,endReachedThreshold:I=300,scrollToMessageKey:h,onScrollToMessageComplete:w,onAtBottomChange:g,components:H={},className:T,style:j}=i,{scrollerRef:L,innerRef:J,virtualItems:K,totalSize:M,measureItem:f,scrollToIndex:S,scrollToBottom:v,scrollToKey:k,isAtBottom:P,prepareAnchor:U}=le({items:t,getKey:(V,G)=>l(G,V),estimatedItemSize:o,overscan:n,atBottomThreshold:u,atBottomHysteresis:d,followOutput:y,initialAlignment:R,scrollModifier:a,onStartReached:p,onEndReached:F,startReachedThreshold:E,endReachedThreshold:I,scrollToMessageKey:h,onScrollToMessageComplete:w}),A=te.useRef(P);te.useEffect(()=>{A.current!==P&&(A.current=P,g==null||g(P))},[P,g]),r.useImperativeHandle(e,()=>({scrollToBottom:v,scrollToIndex:S,scrollToKey:k,getScrollTop:()=>{var V;return((V=L.current)==null?void 0:V.scrollTop)??0},isAtBottom:()=>P,prepareAnchor:U}),[v,S,k,L,P,U]);const{Header:B,Footer:N,EmptyPlaceholder:D}=H;return t.length===0&&D?q.jsx(D,{}):q.jsxs("div",{ref:L,className:T,style:{overflow:"auto",height:"100%",position:"relative",overflowAnchor:"none",overscrollBehaviorY:"contain",...j},children:[B&&q.jsx(B,{}),q.jsx("div",{ref:J,style:{height:M,position:"relative",width:"100%"},children:K.map(V=>q.jsx(ie,{virtualItem:V,measureItem:f,children:s(V.index,V.data)},V.key))}),N&&q.jsx(N,{})]})}const ze=r.forwardRef(be);function xe({data:i,itemContent:e,computeItemKey:t,estimatedItemSize:s=60,overscan:l=20,onEndReached:o,endReachedThreshold:n=300,components:y={},className:u,style:d}){const{scrollerRef:R,innerRef:a,virtualItems:p,totalSize:F,measureItem:E}=ce({items:i,getKey:(g,H)=>t(H,g),estimatedItemSize:s,overscan:l,initialAlignment:"top"});te.useEffect(()=>{const g=R.current;if(!g||!o)return;let H=!1;const T=()=>{g.scrollHeight-g.scrollTop-g.clientHeight<=n&&!H&&(H=!0,Promise.resolve(o()).finally(()=>{H=!1}))};return g.addEventListener("scroll",T,{passive:!0}),()=>g.removeEventListener("scroll",T)},[R,o,n]);const{Header:I,Footer:h,EmptyPlaceholder:w}=y;return i.length===0&&w?q.jsx(w,{}):q.jsxs("div",{ref:R,className:u,style:{overflow:"auto",height:"100%",position:"relative",overflowAnchor:"none",overscrollBehaviorY:"contain",...d},children:[I&&q.jsx(I,{}),q.jsx("div",{ref:a,style:{height:F,position:"relative",width:"100%"},children:p.map(g=>q.jsx(ie,{virtualItem:g,measureItem:E,children:e(g.index,g.data)},g.key))}),h&&q.jsx(h,{})]})}function Ie(i){const{fetcher:e,initialPage:t=1,direction:s="append",getKey:l,onPageLoaded:o,onError:n}=i,[y,u]=r.useState([]),[d,R]=r.useState(t),[a,p]=r.useState(!0),[F,E]=r.useState(!1),[I,h]=r.useState(!1),[w,g]=r.useState(!1),H=r.useRef(new Set),T=r.useRef(!1),j=r.useCallback(f=>l?f.filter(S=>{const v=l(S);return H.current.has(v)?!1:(H.current.add(v),!0)}):f,[l]),L=r.useCallback(async()=>{if(!(T.current||!a)){T.current=!0,g(!0);try{const f=d+1,S=await e(f),v=j(S.data);u(k=>s==="prepend"?[...v,...k]:[...k,...v]),R(f),p(S.hasNextPage),E(S.hasPrevPage),o==null||o(f,v)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{g(!1),T.current=!1}}},[d,a,e,j,s,o,n]),J=r.useCallback(async()=>{if(!(T.current||!F)){T.current=!0,g(!0);try{const f=d-1,S=await e(f),v=j(S.data);u(k=>[...v,...k]),R(f),E(S.hasPrevPage),p(S.hasNextPage),o==null||o(f,v)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{g(!1),T.current=!1}}},[d,F,e,j,o,n]),K=r.useCallback(async()=>{if(!T.current){T.current=!0,h(!0);try{const f=await e(t),S=f.data;if(l){const v=new Set(S.map(l));S.forEach(k=>H.current.add(l(k))),u(k=>{const P=k.filter(U=>!v.has(l(U)));return s==="prepend"?[...S,...P]:[...P,...S]})}else u(S);R(t),p(f.hasNextPage),E(f.hasPrevPage),o==null||o(t,S)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{h(!1),T.current=!1}}},[e,t,l,s,o,n]),M=r.useCallback(()=>{u([]),R(t),p(!0),E(!1),h(!1),g(!1),H.current.clear(),T.current=!1},[t]);return{items:y,loadNextPage:L,loadPrevPage:J,hasNextPage:a,hasPrevPage:F,loading:I,loadingMore:w,refresh:K,reset:M,currentPage:d}}exports.ChatVirtualList=ze;exports.VirtualList=xe;exports.useChatVirtualizer=le;exports.usePagination=Ie;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as J, jsxs as ae } from "react/jsx-runtime";
|
|
2
2
|
import * as oe from "react";
|
|
3
|
-
import { useRef as
|
|
3
|
+
import { useRef as d, useCallback as k, useState as Y, useEffect as D, useLayoutEffect as ee, forwardRef as ge, useImperativeHandle as ve } from "react";
|
|
4
4
|
class Te {
|
|
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);
|
|
@@ -75,133 +75,133 @@ class ye {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
function ue(
|
|
79
|
-
if (
|
|
80
|
-
let t = 0, s =
|
|
78
|
+
function ue(f, e) {
|
|
79
|
+
if (f.length === 0) return 0;
|
|
80
|
+
let t = 0, s = f.length - 1;
|
|
81
81
|
for (; t < s; ) {
|
|
82
82
|
const c = t + s >> 1;
|
|
83
|
-
(
|
|
83
|
+
(f[c] ?? 0) < e ? t = c + 1 : s = c;
|
|
84
84
|
}
|
|
85
|
-
return Math.max(0, t > 0 && (
|
|
85
|
+
return Math.max(0, t > 0 && (f[t] ?? 0) > e ? t - 1 : t);
|
|
86
86
|
}
|
|
87
|
-
function Se(
|
|
88
|
-
if (
|
|
89
|
-
let s = 0, c =
|
|
87
|
+
function Se(f, e, t) {
|
|
88
|
+
if (f.length === 0) return 0;
|
|
89
|
+
let s = 0, c = f.length - 1, n = 0;
|
|
90
90
|
for (; s <= c; ) {
|
|
91
91
|
const r = s + c >> 1;
|
|
92
|
-
(
|
|
92
|
+
(f[r] ?? 0) < t ? (n = r, s = r + 1) : c = r - 1;
|
|
93
93
|
}
|
|
94
94
|
return n;
|
|
95
95
|
}
|
|
96
|
-
function Ae(
|
|
97
|
-
const { firstVisible: e, lastVisible: t, itemCount: s, overscan: c } =
|
|
96
|
+
function Ae(f) {
|
|
97
|
+
const { firstVisible: e, lastVisible: t, itemCount: s, overscan: c } = f;
|
|
98
98
|
return s === 0 ? { start: 0, end: -1 } : {
|
|
99
99
|
start: Math.max(0, e - c),
|
|
100
100
|
end: Math.min(s - 1, t + c)
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
const c = s == null ? void 0 : s.reconcile, n =
|
|
103
|
+
function Re(f, e, t, s) {
|
|
104
|
+
const c = s == null ? void 0 : s.reconcile, n = d(null);
|
|
105
105
|
return k(
|
|
106
106
|
(r, y) => {
|
|
107
|
-
const l =
|
|
107
|
+
const l = f.current, h = e.current;
|
|
108
108
|
if (!l || !h) return;
|
|
109
109
|
n.current !== null && (cancelAnimationFrame(n.current), n.current = null);
|
|
110
|
-
let v,
|
|
111
|
-
if (typeof r == "object" && r !== null ? (v = r.index,
|
|
110
|
+
let v, i;
|
|
111
|
+
if (typeof r == "object" && r !== null ? (v = r.index, i = {
|
|
112
112
|
align: r.align,
|
|
113
113
|
behavior: r.behavior,
|
|
114
114
|
offset: r.offset
|
|
115
|
-
}) : (v = r,
|
|
115
|
+
}) : (v = r, i = y), !Number.isFinite(v)) return;
|
|
116
116
|
const p = Math.max(0, Math.min(Math.floor(v), h.count - 1));
|
|
117
117
|
h.getOffset(p), h.getSize(p);
|
|
118
|
-
const
|
|
118
|
+
const H = (i == null ? void 0 : i.align) ?? "start", K = (i == null ? void 0 : i.behavior) ?? "auto", F = (i == null ? void 0 : i.offset) ?? 0, a = () => {
|
|
119
119
|
var B;
|
|
120
|
-
const
|
|
121
|
-
if (!
|
|
122
|
-
const A = ((B = t == null ? void 0 : t.current) == null ? void 0 : B.offsetTop) ?? 0, T =
|
|
123
|
-
return
|
|
124
|
-
}, E =
|
|
125
|
-
((
|
|
126
|
-
typeof l.scrollTo == "function" ? l.scrollTo({ top:
|
|
127
|
-
})(Math.max(0, E),
|
|
120
|
+
const M = e.current, u = f.current;
|
|
121
|
+
if (!M || !u) return 0;
|
|
122
|
+
const A = ((B = t == null ? void 0 : t.current) == null ? void 0 : B.offsetTop) ?? 0, T = M.getOffset(p), w = M.getSize(p);
|
|
123
|
+
return H === "start" ? A + T + F : H === "center" ? A + T - u.clientHeight / 2 + w / 2 + F : A + T - u.clientHeight + w + F;
|
|
124
|
+
}, E = a();
|
|
125
|
+
((M, u) => {
|
|
126
|
+
typeof l.scrollTo == "function" ? l.scrollTo({ top: M, behavior: u }) : l.scrollTop = M;
|
|
127
|
+
})(Math.max(0, E), K);
|
|
128
128
|
const b = performance.now();
|
|
129
129
|
let S = 0;
|
|
130
|
-
const C = 12, j = 300,
|
|
130
|
+
const C = 12, j = 300, W = 1, O = () => {
|
|
131
131
|
n.current = null;
|
|
132
|
-
const
|
|
133
|
-
if (!
|
|
134
|
-
const u = Math.max(0,
|
|
135
|
-
A <=
|
|
132
|
+
const M = f.current;
|
|
133
|
+
if (!M) return;
|
|
134
|
+
const u = Math.max(0, a()), A = Math.abs(M.scrollTop - u), T = performance.now() - b >= j, w = S >= C;
|
|
135
|
+
A <= W || T || w || (typeof M.scrollTo == "function" ? M.scrollTo({ top: u, behavior: "auto" }) : M.scrollTop = u, S += 1, n.current = requestAnimationFrame(O));
|
|
136
136
|
};
|
|
137
|
-
n.current = requestAnimationFrame(
|
|
137
|
+
n.current = requestAnimationFrame(O);
|
|
138
138
|
},
|
|
139
|
-
[
|
|
139
|
+
[f, e, t, c]
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
|
-
function fe(
|
|
142
|
+
function fe(f) {
|
|
143
143
|
var ie;
|
|
144
|
-
const { items: e, getKey: t, estimatedItemSize: s, overscan: c, initialAlignment: n } =
|
|
144
|
+
const { items: e, getKey: t, estimatedItemSize: s, overscan: c, initialAlignment: n } = f, r = d(null), y = d(null), l = d(null), h = d(new ye()), v = d([]), i = d(/* @__PURE__ */ new Map()), p = d(e.length), H = d(null), K = d(null), F = d(!1), a = d(0), E = d(0), g = d(null), b = d(!1), S = d(null), C = d(0), j = d(0), W = d(0), O = d(null), M = d(!1), u = d(!1), [, A] = Y(0), T = k(() => A((o) => o + 1), []);
|
|
145
145
|
l.current || (l.current = new Te(e.length, s));
|
|
146
146
|
const w = e.length > 0 ? t(e[0], 0) : null, B = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
|
|
147
|
-
if (e.length !== p.current || w !==
|
|
148
|
-
const o = l.current,
|
|
147
|
+
if (e.length !== p.current || w !== H.current || B !== K.current) {
|
|
148
|
+
const o = l.current, m = e.map((N, _) => t(N, _)), x = v.current, I = x.length, P = m.length;
|
|
149
149
|
if (P === 0)
|
|
150
150
|
o.resize(0);
|
|
151
151
|
else if (I === 0)
|
|
152
152
|
o.resize(P);
|
|
153
153
|
else if (P > I) {
|
|
154
|
-
const
|
|
155
|
-
x.length > 0 &&
|
|
154
|
+
const N = P - I;
|
|
155
|
+
x.length > 0 && N >= 0 && m[N] === x[0] ? o.prepend(N) : o.resize(P);
|
|
156
156
|
} else P < I, o.resize(P);
|
|
157
|
-
const
|
|
158
|
-
|
|
157
|
+
const z = /* @__PURE__ */ new Map();
|
|
158
|
+
m.forEach((N, _) => z.set(N, _)), i.current = z, h.current.applyToOffsetMap(o, z), v.current = m, p.current = e.length, H.current = w, K.current = B;
|
|
159
159
|
}
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
const R = k(() => {
|
|
161
|
+
O.current === null && (O.current = requestAnimationFrame(() => {
|
|
162
|
+
O.current = null;
|
|
163
163
|
const o = r.current;
|
|
164
164
|
if (!o) return;
|
|
165
|
-
const
|
|
166
|
-
Math.abs(
|
|
165
|
+
const m = C.current;
|
|
166
|
+
Math.abs(m) < 0.01 || (C.current = 0, j.current += m, W.current += m, o.scrollTop += m, a.current = o.scrollTop, M.current = !0, T());
|
|
167
167
|
}));
|
|
168
168
|
}, [T]);
|
|
169
|
-
|
|
169
|
+
D(() => {
|
|
170
170
|
const o = r.current;
|
|
171
171
|
if (!o) return;
|
|
172
|
-
const
|
|
172
|
+
const m = () => {
|
|
173
173
|
g.current === null && (g.current = requestAnimationFrame(() => {
|
|
174
|
-
g.current = null,
|
|
174
|
+
g.current = null, a.current = o.scrollTop, E.current = o.clientHeight, M.current && (M.current = !1, j.current = 0, W.current = 0), T();
|
|
175
175
|
}));
|
|
176
176
|
};
|
|
177
|
-
return o.addEventListener("scroll",
|
|
178
|
-
o.removeEventListener("scroll",
|
|
177
|
+
return o.addEventListener("scroll", m, { passive: !0 }), () => {
|
|
178
|
+
o.removeEventListener("scroll", m), g.current !== null && (cancelAnimationFrame(g.current), g.current = null), O.current !== null && (cancelAnimationFrame(O.current), O.current = null);
|
|
179
179
|
};
|
|
180
|
-
}, [T]),
|
|
180
|
+
}, [T]), D(() => {
|
|
181
181
|
const o = r.current;
|
|
182
182
|
if (!o) return;
|
|
183
|
-
E.current = o.clientHeight,
|
|
184
|
-
const
|
|
183
|
+
E.current = o.clientHeight, a.current = o.scrollTop;
|
|
184
|
+
const m = new ResizeObserver(([x]) => {
|
|
185
185
|
x && (E.current = x.contentRect.height, T());
|
|
186
186
|
});
|
|
187
|
-
return
|
|
188
|
-
}, [T]),
|
|
189
|
-
if (
|
|
187
|
+
return m.observe(o), () => m.disconnect();
|
|
188
|
+
}, [T]), ee(() => {
|
|
189
|
+
if (F.current || e.length === 0) return;
|
|
190
190
|
const o = r.current;
|
|
191
191
|
if (o) {
|
|
192
192
|
if (n === "bottom") {
|
|
193
|
-
o.scrollTop = o.scrollHeight,
|
|
194
|
-
const
|
|
193
|
+
o.scrollTop = o.scrollHeight, a.current = o.scrollTop, E.current = o.clientHeight, b.current = !0, S.current !== null && cancelAnimationFrame(S.current);
|
|
194
|
+
const m = performance.now();
|
|
195
195
|
let x = 0, I = o.scrollHeight;
|
|
196
196
|
const P = () => {
|
|
197
197
|
if (!b.current) {
|
|
198
198
|
S.current = null;
|
|
199
199
|
return;
|
|
200
200
|
}
|
|
201
|
-
const
|
|
202
|
-
I =
|
|
203
|
-
const
|
|
204
|
-
if (x >= 3 ||
|
|
201
|
+
const z = o.scrollHeight, N = Math.abs(z - I);
|
|
202
|
+
I = z, N < 1 ? x += 1 : x = 0, o.scrollTop = o.scrollHeight, a.current = o.scrollTop;
|
|
203
|
+
const _ = performance.now() - m;
|
|
204
|
+
if (x >= 3 || _ >= 500) {
|
|
205
205
|
b.current = !1, S.current = null;
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
@@ -209,107 +209,111 @@ function fe(a) {
|
|
|
209
209
|
};
|
|
210
210
|
S.current = requestAnimationFrame(P);
|
|
211
211
|
}
|
|
212
|
-
|
|
212
|
+
F.current = !0;
|
|
213
213
|
}
|
|
214
|
-
}, [n, e.length]),
|
|
215
|
-
e.length === 0 && (
|
|
214
|
+
}, [n, e.length]), D(() => {
|
|
215
|
+
e.length === 0 && (F.current = !1, b.current = !1, S.current !== null && (cancelAnimationFrame(S.current), S.current = null));
|
|
216
216
|
}, [e.length]);
|
|
217
|
-
const
|
|
217
|
+
const L = k((o, m) => {
|
|
218
218
|
var Q;
|
|
219
219
|
const x = l.current;
|
|
220
|
-
if (!x || h.current.get(o) ===
|
|
221
|
-
h.current.set(o,
|
|
222
|
-
const P =
|
|
220
|
+
if (!x || h.current.get(o) === m) return;
|
|
221
|
+
h.current.set(o, m);
|
|
222
|
+
const P = i.current.get(o);
|
|
223
223
|
if (P === void 0) return;
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
const z = x.getSize(P), N = m - z, _ = r.current;
|
|
225
|
+
if (_ && !b.current && !u.current && N !== 0) {
|
|
226
|
+
const Z = x.getOffset(P) + z + (((Q = y.current) == null ? void 0 : Q.offsetTop) ?? 0);
|
|
227
|
+
Z < _.scrollTop && (console.log(`[JUMP] key=${o} idx=${P} delta=${N} itemBottom=${Math.round(Z)} scrollTop=${Math.round(_.scrollTop)} suppressed=${u.current}`), C.current += N, R());
|
|
228
|
+
}
|
|
229
|
+
x.setSize(P, m) && T();
|
|
230
|
+
}, [R, T]), V = k(
|
|
231
|
+
(o, m = "auto") => {
|
|
228
232
|
var x;
|
|
229
|
-
(x = r.current) == null || x.scrollTo({ top: o, behavior:
|
|
233
|
+
(x = r.current) == null || x.scrollTo({ top: o, behavior: m });
|
|
230
234
|
},
|
|
231
235
|
[]
|
|
232
|
-
), G =
|
|
236
|
+
), G = Re(r, l, y, {
|
|
233
237
|
reconcile: !0
|
|
234
|
-
}),
|
|
235
|
-
var
|
|
236
|
-
const o = r.current,
|
|
237
|
-
if (!o || !
|
|
238
|
-
const x = ((
|
|
239
|
-
for (let Q =
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
key:
|
|
243
|
-
offsetWithinItem: I -
|
|
238
|
+
}), $ = k(() => {
|
|
239
|
+
var se;
|
|
240
|
+
const o = r.current, m = l.current;
|
|
241
|
+
if (!o || !m || m.count === 0) return null;
|
|
242
|
+
const x = ((se = y.current) == null ? void 0 : se.offsetTop) ?? 0, I = Math.max(0, o.scrollTop - x), P = m.getOffsets(), z = ue(P, I), N = v.current[z] ?? null, _ = [];
|
|
243
|
+
for (let Q = z; Q < Math.min(m.count, z + 6); Q++) {
|
|
244
|
+
const Z = v.current[Q] ?? null;
|
|
245
|
+
Z !== null && _.push({
|
|
246
|
+
key: Z,
|
|
247
|
+
offsetWithinItem: I - m.getOffset(Q)
|
|
244
248
|
});
|
|
245
249
|
}
|
|
246
250
|
return {
|
|
247
|
-
key:
|
|
248
|
-
offsetWithinItem: I -
|
|
249
|
-
candidates:
|
|
251
|
+
key: N,
|
|
252
|
+
offsetWithinItem: I - m.getOffset(z),
|
|
253
|
+
candidates: _,
|
|
250
254
|
scrollTop: o.scrollTop,
|
|
251
255
|
scrollHeight: o.scrollHeight
|
|
252
256
|
};
|
|
253
|
-
}, []),
|
|
254
|
-
(o,
|
|
255
|
-
var
|
|
257
|
+
}, []), te = k(
|
|
258
|
+
(o, m) => {
|
|
259
|
+
var z;
|
|
256
260
|
const x = l.current;
|
|
257
261
|
if (!x) return null;
|
|
258
|
-
const I =
|
|
259
|
-
return I === void 0 ? null : (((
|
|
262
|
+
const I = i.current.get(o);
|
|
263
|
+
return I === void 0 ? null : (((z = y.current) == null ? void 0 : z.offsetTop) ?? 0) + x.getOffset(I) + m;
|
|
260
264
|
},
|
|
261
265
|
[]
|
|
262
|
-
),
|
|
263
|
-
if (
|
|
264
|
-
const o =
|
|
266
|
+
), q = l.current, de = q ? q.totalSize() : 0, U = r.current, re = (U == null ? void 0 : U.scrollTop) ?? a.current, ce = (U == null ? void 0 : U.clientHeight) ?? E.current, me = ((ie = y.current) == null ? void 0 : ie.offsetTop) ?? 0, le = Math.max(0, re - me), ne = [];
|
|
267
|
+
if (q && q.count > 0 && ce > 0) {
|
|
268
|
+
const o = q.getOffsets(), m = q.getSizes(), x = ue(o, le), I = Se(
|
|
265
269
|
o,
|
|
266
|
-
|
|
270
|
+
m,
|
|
267
271
|
le + ce
|
|
268
272
|
), P = Ae({
|
|
269
273
|
firstVisible: x,
|
|
270
274
|
lastVisible: I,
|
|
271
|
-
itemCount:
|
|
275
|
+
itemCount: q.count,
|
|
272
276
|
overscan: c
|
|
273
277
|
});
|
|
274
|
-
for (let
|
|
275
|
-
|
|
276
|
-
key: v.current[
|
|
277
|
-
index:
|
|
278
|
-
start:
|
|
279
|
-
size:
|
|
280
|
-
data: e[
|
|
278
|
+
for (let z = P.start; z <= P.end && z < e.length; z++)
|
|
279
|
+
ne.push({
|
|
280
|
+
key: v.current[z] ?? t(e[z], z),
|
|
281
|
+
index: z,
|
|
282
|
+
start: q.getOffset(z),
|
|
283
|
+
size: q.getSize(z),
|
|
284
|
+
data: e[z]
|
|
281
285
|
});
|
|
282
|
-
} else if (
|
|
283
|
-
const o = Math.min(e.length, c * 2 + 1),
|
|
284
|
-
for (let I =
|
|
285
|
-
|
|
286
|
+
} else if (q && q.count > 0) {
|
|
287
|
+
const o = Math.min(e.length, c * 2 + 1), m = n === "bottom" ? Math.max(0, e.length - o) : 0, x = m + o - 1;
|
|
288
|
+
for (let I = m; I <= x; I++)
|
|
289
|
+
ne.push({
|
|
286
290
|
key: v.current[I] ?? t(e[I], I),
|
|
287
291
|
index: I,
|
|
288
|
-
start:
|
|
289
|
-
size:
|
|
292
|
+
start: q.getOffset(I),
|
|
293
|
+
size: q.getSize(I),
|
|
290
294
|
data: e[I]
|
|
291
295
|
});
|
|
292
296
|
}
|
|
293
|
-
const pe =
|
|
297
|
+
const pe = U ? U.scrollHeight - U.scrollTop - U.clientHeight : 1 / 0;
|
|
294
298
|
return {
|
|
295
299
|
scrollerRef: r,
|
|
296
300
|
innerRef: y,
|
|
297
|
-
virtualItems:
|
|
298
|
-
totalSize:
|
|
299
|
-
measureItem:
|
|
301
|
+
virtualItems: ne,
|
|
302
|
+
totalSize: de,
|
|
303
|
+
measureItem: L,
|
|
300
304
|
scrollToIndex: G,
|
|
301
|
-
scrollToOffset:
|
|
302
|
-
captureAnchorSnapshot:
|
|
303
|
-
resolveAnchorTop:
|
|
304
|
-
isAtTop:
|
|
305
|
+
scrollToOffset: V,
|
|
306
|
+
captureAnchorSnapshot: $,
|
|
307
|
+
resolveAnchorTop: te,
|
|
308
|
+
isAtTop: re <= 1,
|
|
305
309
|
isAtBottom: pe <= 1,
|
|
306
|
-
scrollTop:
|
|
310
|
+
scrollTop: re,
|
|
307
311
|
jumpSuppressedRef: u
|
|
308
312
|
};
|
|
309
313
|
}
|
|
310
|
-
function
|
|
314
|
+
function ze(f) {
|
|
311
315
|
var c;
|
|
312
|
-
const { snapshot: e, currentScrollHeight: t, resolveAnchorTop: s } =
|
|
316
|
+
const { snapshot: e, currentScrollHeight: t, resolveAnchorTop: s } = f;
|
|
313
317
|
if (e.key !== null) {
|
|
314
318
|
const n = s(e.key, e.offsetWithinItem);
|
|
315
319
|
if (n !== null) return n;
|
|
@@ -321,68 +325,68 @@ function Re(a) {
|
|
|
321
325
|
}
|
|
322
326
|
return e.scrollTop + (t - e.scrollHeight);
|
|
323
327
|
}
|
|
324
|
-
function xe(
|
|
328
|
+
function xe(f) {
|
|
325
329
|
const {
|
|
326
330
|
scrollerRef: e,
|
|
327
331
|
itemCount: t,
|
|
328
332
|
captureAnchorSnapshot: s,
|
|
329
333
|
resolveAnchorTop: c,
|
|
330
334
|
onRestored: n
|
|
331
|
-
} =
|
|
335
|
+
} = f, r = d(null), y = d(!1), l = d({
|
|
332
336
|
first: null,
|
|
333
337
|
second: null,
|
|
334
338
|
timeout: null
|
|
335
339
|
}), h = k(() => {
|
|
336
|
-
const { first:
|
|
337
|
-
|
|
340
|
+
const { first: i, second: p, timeout: H } = l.current;
|
|
341
|
+
i && cancelAnimationFrame(i), p && cancelAnimationFrame(p), H && clearTimeout(H), l.current = { first: null, second: null, timeout: null };
|
|
338
342
|
}, []), v = k(() => {
|
|
339
|
-
const
|
|
340
|
-
if (!
|
|
343
|
+
const i = e.current;
|
|
344
|
+
if (!i) return;
|
|
341
345
|
const p = s();
|
|
342
346
|
r.current = p ?? {
|
|
343
347
|
key: null,
|
|
344
348
|
offsetWithinItem: 0,
|
|
345
|
-
scrollTop:
|
|
346
|
-
scrollHeight:
|
|
347
|
-
}, y.current = !0;
|
|
349
|
+
scrollTop: i.scrollTop,
|
|
350
|
+
scrollHeight: i.scrollHeight
|
|
351
|
+
}, y.current = !0, console.log("[ANCHOR] prepareAnchor snapshot:", JSON.stringify(r.current, null, 2));
|
|
348
352
|
}, [e, s]);
|
|
349
|
-
return
|
|
353
|
+
return ee(() => {
|
|
350
354
|
if (!y.current) return;
|
|
351
|
-
const
|
|
352
|
-
if (!
|
|
355
|
+
const i = e.current, p = r.current;
|
|
356
|
+
if (!i || !p) return;
|
|
353
357
|
y.current = !1;
|
|
354
|
-
const
|
|
355
|
-
const
|
|
358
|
+
const H = (K) => {
|
|
359
|
+
const F = ze({
|
|
356
360
|
snapshot: p,
|
|
357
|
-
currentScrollHeight:
|
|
361
|
+
currentScrollHeight: i.scrollHeight,
|
|
358
362
|
resolveAnchorTop: c
|
|
359
363
|
});
|
|
360
|
-
Number.isFinite(
|
|
364
|
+
console.log(`[ANCHOR] restore(${K}): target=${Math.round(F)}, currentScrollTop=${Math.round(i.scrollTop)}, scrollHeight=${i.scrollHeight}, snapshotKey=${p.key}, delta=${Math.round(F - i.scrollTop)}`), Number.isFinite(F) && Math.abs(i.scrollTop - F) > 1 && (i.scrollTop = F);
|
|
361
365
|
};
|
|
362
|
-
return h(),
|
|
363
|
-
l.current.first = null,
|
|
364
|
-
l.current.second = null,
|
|
366
|
+
return h(), H("layout"), n == null || n(), l.current.first = requestAnimationFrame(() => {
|
|
367
|
+
l.current.first = null, H("raf1"), l.current.second = requestAnimationFrame(() => {
|
|
368
|
+
l.current.second = null, H("raf2");
|
|
365
369
|
});
|
|
366
370
|
}), l.current.timeout = setTimeout(() => {
|
|
367
|
-
l.current.timeout = null,
|
|
371
|
+
l.current.timeout = null, H("timeout");
|
|
368
372
|
}, 90), () => h();
|
|
369
373
|
}, [t, e, c, h, n]), { prepareAnchor: v };
|
|
370
374
|
}
|
|
371
|
-
function Ie(
|
|
372
|
-
const { previous: e, distanceFromBottom: t, threshold: s, hysteresis: c } =
|
|
375
|
+
function Ie(f) {
|
|
376
|
+
const { previous: e, distanceFromBottom: t, threshold: s, hysteresis: c } = f;
|
|
373
377
|
if (!c) return t <= s;
|
|
374
378
|
const n = Math.max(0, c.enter), r = Math.max(n, c.leave);
|
|
375
379
|
return e ? t <= r : t <= n;
|
|
376
380
|
}
|
|
377
|
-
function Fe(
|
|
378
|
-
const t = typeof e == "number" ? e : e.threshold ?? 200, s = typeof e == "number" ? void 0 : e.hysteresis, [c, n] =
|
|
379
|
-
return
|
|
380
|
-
const l =
|
|
381
|
+
function Fe(f, e) {
|
|
382
|
+
const t = typeof e == "number" ? e : e.threshold ?? 200, s = typeof e == "number" ? void 0 : e.hysteresis, [c, n] = Y(!0), r = d(null), y = d(!0);
|
|
383
|
+
return D(() => {
|
|
384
|
+
const l = f.current;
|
|
381
385
|
if (!l) return;
|
|
382
386
|
const h = () => {
|
|
383
|
-
const
|
|
387
|
+
const i = l.scrollHeight - l.scrollTop - l.clientHeight, p = Ie({
|
|
384
388
|
previous: y.current,
|
|
385
|
-
distanceFromBottom:
|
|
389
|
+
distanceFromBottom: i,
|
|
386
390
|
threshold: t,
|
|
387
391
|
hysteresis: s
|
|
388
392
|
});
|
|
@@ -393,23 +397,23 @@ function Fe(a, e) {
|
|
|
393
397
|
return l.addEventListener("scroll", v, { passive: !0 }), h(), () => {
|
|
394
398
|
l.removeEventListener("scroll", v), r.current !== null && cancelAnimationFrame(r.current);
|
|
395
399
|
};
|
|
396
|
-
}, [
|
|
400
|
+
}, [f, t, s == null ? void 0 : s.enter, s == null ? void 0 : s.leave]), c;
|
|
397
401
|
}
|
|
398
|
-
function
|
|
399
|
-
const { itemCount: e, firstKey: t, lastKey: s, isAtBottom: c, scrollToIndex: n, mode: r } =
|
|
400
|
-
|
|
402
|
+
function He(f) {
|
|
403
|
+
const { itemCount: e, firstKey: t, lastKey: s, isAtBottom: c, scrollToIndex: n, mode: r } = f, y = d(e), l = d(t), h = d(s);
|
|
404
|
+
ee(() => {
|
|
401
405
|
if (!r) {
|
|
402
406
|
y.current = e, l.current = t, h.current = s;
|
|
403
407
|
return;
|
|
404
408
|
}
|
|
405
|
-
const v = y.current,
|
|
406
|
-
e > v && t ===
|
|
409
|
+
const v = y.current, i = l.current, p = h.current;
|
|
410
|
+
e > v && t === i && s !== p && c && e > 0 && n(e - 1, {
|
|
407
411
|
align: "end",
|
|
408
412
|
behavior: r === "smooth" ? "smooth" : "auto"
|
|
409
413
|
}), y.current = e, l.current = t, h.current = s;
|
|
410
414
|
}, [e, t, s, c, n, r]);
|
|
411
415
|
}
|
|
412
|
-
function
|
|
416
|
+
function be(f) {
|
|
413
417
|
const {
|
|
414
418
|
items: e,
|
|
415
419
|
getKey: t,
|
|
@@ -421,54 +425,54 @@ function He(a) {
|
|
|
421
425
|
initialAlignment: l = "bottom",
|
|
422
426
|
scrollModifier: h = null,
|
|
423
427
|
onStartReached: v,
|
|
424
|
-
onEndReached:
|
|
428
|
+
onEndReached: i,
|
|
425
429
|
startReachedThreshold: p = 300,
|
|
426
|
-
endReachedThreshold:
|
|
427
|
-
scrollToMessageKey:
|
|
428
|
-
onScrollToMessageComplete:
|
|
429
|
-
} =
|
|
430
|
+
endReachedThreshold: H = 300,
|
|
431
|
+
scrollToMessageKey: K,
|
|
432
|
+
onScrollToMessageComplete: F
|
|
433
|
+
} = f, a = fe({
|
|
430
434
|
items: e,
|
|
431
435
|
getKey: t,
|
|
432
436
|
estimatedItemSize: s,
|
|
433
437
|
overscan: c,
|
|
434
438
|
initialAlignment: l
|
|
435
|
-
}), E = Fe(
|
|
439
|
+
}), E = Fe(a.scrollerRef, {
|
|
436
440
|
threshold: n,
|
|
437
441
|
hysteresis: r ?? { enter: 80, leave: 160 }
|
|
438
|
-
}), [, g] =
|
|
439
|
-
g((
|
|
440
|
-
|
|
442
|
+
}), [, g] = Y(0), b = d(null), S = k(() => {
|
|
443
|
+
g((R) => R + 1), b.current && clearTimeout(b.current), b.current = setTimeout(() => {
|
|
444
|
+
a.jumpSuppressedRef.current = !1, b.current = null;
|
|
441
445
|
}, 200);
|
|
442
|
-
}, [
|
|
443
|
-
scrollerRef:
|
|
446
|
+
}, [a.jumpSuppressedRef]), { prepareAnchor: C } = xe({
|
|
447
|
+
scrollerRef: a.scrollerRef,
|
|
444
448
|
itemCount: e.length,
|
|
445
|
-
captureAnchorSnapshot:
|
|
446
|
-
resolveAnchorTop:
|
|
449
|
+
captureAnchorSnapshot: a.captureAnchorSnapshot,
|
|
450
|
+
resolveAnchorTop: a.resolveAnchorTop,
|
|
447
451
|
onRestored: S
|
|
448
452
|
}), j = k(() => {
|
|
449
|
-
|
|
450
|
-
}, [C,
|
|
451
|
-
|
|
453
|
+
a.jumpSuppressedRef.current = !0, C();
|
|
454
|
+
}, [C, a.jumpSuppressedRef]), W = e.length > 0 ? t(e[0], 0) : null, O = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
|
|
455
|
+
He({
|
|
452
456
|
itemCount: e.length,
|
|
453
|
-
firstKey:
|
|
454
|
-
lastKey:
|
|
457
|
+
firstKey: W,
|
|
458
|
+
lastKey: O,
|
|
455
459
|
isAtBottom: E,
|
|
456
|
-
scrollToIndex:
|
|
460
|
+
scrollToIndex: a.scrollToIndex,
|
|
457
461
|
mode: y ?? !1
|
|
458
462
|
});
|
|
459
|
-
const
|
|
460
|
-
(
|
|
461
|
-
e.length !== 0 &&
|
|
463
|
+
const M = k(
|
|
464
|
+
(R = "auto") => {
|
|
465
|
+
e.length !== 0 && a.scrollToIndex(e.length - 1, { align: "end", behavior: R });
|
|
462
466
|
},
|
|
463
|
-
[e.length,
|
|
467
|
+
[e.length, a]
|
|
464
468
|
), u = k(
|
|
465
|
-
(
|
|
466
|
-
const
|
|
467
|
-
|
|
469
|
+
(R, L) => {
|
|
470
|
+
const V = e.findIndex((G, $) => t(G, $) === R);
|
|
471
|
+
V !== -1 && a.scrollToIndex(V, L);
|
|
468
472
|
},
|
|
469
|
-
[e, t,
|
|
470
|
-
), A =
|
|
471
|
-
|
|
473
|
+
[e, t, a]
|
|
474
|
+
), A = d(null);
|
|
475
|
+
ee(() => {
|
|
472
476
|
if (h && A.current !== h.id) {
|
|
473
477
|
if (A.current = h.id, h.type === "prepend") {
|
|
474
478
|
j();
|
|
@@ -476,11 +480,11 @@ function He(a) {
|
|
|
476
480
|
}
|
|
477
481
|
if (h.type === "append") {
|
|
478
482
|
if (h.ifAtBottomOnly && !E) return;
|
|
479
|
-
|
|
483
|
+
M(h.behavior ?? "auto");
|
|
480
484
|
return;
|
|
481
485
|
}
|
|
482
486
|
if (h.type === "items-change") {
|
|
483
|
-
E &&
|
|
487
|
+
E && M("auto");
|
|
484
488
|
return;
|
|
485
489
|
}
|
|
486
490
|
u(h.key, {
|
|
@@ -488,63 +492,63 @@ function He(a) {
|
|
|
488
492
|
behavior: h.behavior ?? "auto"
|
|
489
493
|
});
|
|
490
494
|
}
|
|
491
|
-
}, [h, E, j,
|
|
492
|
-
const T =
|
|
493
|
-
|
|
494
|
-
const
|
|
495
|
-
if (!
|
|
496
|
-
const
|
|
497
|
-
const
|
|
498
|
-
w.current || (
|
|
495
|
+
}, [h, E, j, M, u]);
|
|
496
|
+
const T = d(!1), w = d(l === "top");
|
|
497
|
+
D(() => {
|
|
498
|
+
const R = a.scrollerRef.current;
|
|
499
|
+
if (!R || !v) return;
|
|
500
|
+
const L = () => {
|
|
501
|
+
const V = R.scrollTop;
|
|
502
|
+
w.current || (R.scrollHeight <= R.clientHeight + p || V > p) && (w.current = !0), w.current && V <= p && !T.current && (T.current = !0, Promise.resolve(v()).finally(() => {
|
|
499
503
|
T.current = !1;
|
|
500
504
|
}));
|
|
501
505
|
};
|
|
502
|
-
return
|
|
503
|
-
}, [
|
|
504
|
-
const B =
|
|
505
|
-
|
|
506
|
-
const
|
|
507
|
-
if (!
|
|
508
|
-
const
|
|
509
|
-
|
|
506
|
+
return R.addEventListener("scroll", L, { passive: !0 }), L(), () => R.removeEventListener("scroll", L);
|
|
507
|
+
}, [a.scrollerRef, v, p, l]);
|
|
508
|
+
const B = d(!1);
|
|
509
|
+
D(() => {
|
|
510
|
+
const R = a.scrollerRef.current;
|
|
511
|
+
if (!R || !i) return;
|
|
512
|
+
const L = () => {
|
|
513
|
+
R.scrollHeight - R.scrollTop - R.clientHeight <= H && !B.current && (B.current = !0, Promise.resolve(i()).finally(() => {
|
|
510
514
|
B.current = !1;
|
|
511
515
|
}));
|
|
512
516
|
};
|
|
513
|
-
return
|
|
514
|
-
}, [
|
|
515
|
-
const
|
|
516
|
-
return
|
|
517
|
-
if (!
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
}, [
|
|
521
|
-
scrollerRef:
|
|
522
|
-
innerRef:
|
|
523
|
-
virtualItems:
|
|
524
|
-
totalSize:
|
|
525
|
-
measureItem:
|
|
526
|
-
scrollToIndex:
|
|
527
|
-
scrollToBottom:
|
|
517
|
+
return R.addEventListener("scroll", L, { passive: !0 }), () => R.removeEventListener("scroll", L);
|
|
518
|
+
}, [a.scrollerRef, i, H]);
|
|
519
|
+
const X = d(null);
|
|
520
|
+
return D(() => {
|
|
521
|
+
if (!K || X.current === K) return;
|
|
522
|
+
const R = e.findIndex((L, V) => t(L, V) === K);
|
|
523
|
+
R !== -1 && (X.current = K, a.scrollToIndex(R, { align: "center", behavior: "auto" }), F == null || F());
|
|
524
|
+
}, [K, e, t, a, F]), {
|
|
525
|
+
scrollerRef: a.scrollerRef,
|
|
526
|
+
innerRef: a.innerRef,
|
|
527
|
+
virtualItems: a.virtualItems,
|
|
528
|
+
totalSize: a.totalSize,
|
|
529
|
+
measureItem: a.measureItem,
|
|
530
|
+
scrollToIndex: a.scrollToIndex,
|
|
531
|
+
scrollToBottom: M,
|
|
528
532
|
scrollToKey: u,
|
|
529
533
|
isAtBottom: E,
|
|
530
534
|
prepareAnchor: j
|
|
531
535
|
};
|
|
532
536
|
}
|
|
533
537
|
function he({
|
|
534
|
-
virtualItem:
|
|
538
|
+
virtualItem: f,
|
|
535
539
|
measureItem: e,
|
|
536
540
|
children: t
|
|
537
541
|
}) {
|
|
538
|
-
const s =
|
|
539
|
-
return
|
|
542
|
+
const s = d(null), c = d(!1);
|
|
543
|
+
return D(() => {
|
|
540
544
|
const n = s.current;
|
|
541
545
|
if (!n) return;
|
|
542
546
|
c.current = !1;
|
|
543
547
|
const r = new ResizeObserver(([y]) => {
|
|
544
|
-
y && (c.current = !0, e(
|
|
548
|
+
y && (c.current = !0, e(f.key, y.contentRect.height));
|
|
545
549
|
});
|
|
546
550
|
return r.observe(n), () => r.disconnect();
|
|
547
|
-
}, [
|
|
551
|
+
}, [f.key, e]), /* @__PURE__ */ J(
|
|
548
552
|
"div",
|
|
549
553
|
{
|
|
550
554
|
ref: s,
|
|
@@ -552,20 +556,20 @@ function he({
|
|
|
552
556
|
position: "absolute",
|
|
553
557
|
top: 0,
|
|
554
558
|
// transform instead of top: avoids reflow, uses GPU compositor layer
|
|
555
|
-
transform: `translateY(${
|
|
559
|
+
transform: `translateY(${f.start}px)`,
|
|
556
560
|
width: "100%",
|
|
557
561
|
// Only reserve estimated height before first measurement.
|
|
558
562
|
// After measurement, let the item take its natural height so
|
|
559
563
|
// ResizeObserver can accurately report the real size.
|
|
560
564
|
// Without this, items can never be smaller than estimatedItemSize,
|
|
561
565
|
// which distorts offsets and total height.
|
|
562
|
-
minHeight: c.current ? void 0 :
|
|
566
|
+
minHeight: c.current ? void 0 : f.size
|
|
563
567
|
},
|
|
564
568
|
children: t
|
|
565
569
|
}
|
|
566
570
|
);
|
|
567
571
|
}
|
|
568
|
-
function Me(
|
|
572
|
+
function Me(f, e) {
|
|
569
573
|
const {
|
|
570
574
|
data: t,
|
|
571
575
|
itemContent: s,
|
|
@@ -576,47 +580,47 @@ function Me(a, e) {
|
|
|
576
580
|
atBottomThreshold: l = 200,
|
|
577
581
|
atBottomHysteresis: h,
|
|
578
582
|
initialAlignment: v = "bottom",
|
|
579
|
-
scrollModifier:
|
|
583
|
+
scrollModifier: i,
|
|
580
584
|
onStartReached: p,
|
|
581
|
-
onEndReached:
|
|
582
|
-
startReachedThreshold:
|
|
583
|
-
endReachedThreshold:
|
|
584
|
-
scrollToMessageKey:
|
|
585
|
+
onEndReached: H,
|
|
586
|
+
startReachedThreshold: K = 300,
|
|
587
|
+
endReachedThreshold: F = 300,
|
|
588
|
+
scrollToMessageKey: a,
|
|
585
589
|
onScrollToMessageComplete: E,
|
|
586
590
|
onAtBottomChange: g,
|
|
587
591
|
components: b = {},
|
|
588
592
|
className: S,
|
|
589
593
|
style: C
|
|
590
|
-
} =
|
|
594
|
+
} = f, {
|
|
591
595
|
scrollerRef: j,
|
|
592
|
-
innerRef:
|
|
593
|
-
virtualItems:
|
|
594
|
-
totalSize:
|
|
596
|
+
innerRef: W,
|
|
597
|
+
virtualItems: O,
|
|
598
|
+
totalSize: M,
|
|
595
599
|
measureItem: u,
|
|
596
600
|
scrollToIndex: A,
|
|
597
601
|
scrollToBottom: T,
|
|
598
602
|
scrollToKey: w,
|
|
599
603
|
isAtBottom: B,
|
|
600
|
-
prepareAnchor:
|
|
601
|
-
} =
|
|
604
|
+
prepareAnchor: X
|
|
605
|
+
} = be({
|
|
602
606
|
items: t,
|
|
603
|
-
getKey: (
|
|
607
|
+
getKey: ($, te) => c(te, $),
|
|
604
608
|
estimatedItemSize: n,
|
|
605
609
|
overscan: r,
|
|
606
610
|
atBottomThreshold: l,
|
|
607
611
|
atBottomHysteresis: h,
|
|
608
612
|
followOutput: y,
|
|
609
613
|
initialAlignment: v,
|
|
610
|
-
scrollModifier:
|
|
614
|
+
scrollModifier: i,
|
|
611
615
|
onStartReached: p,
|
|
612
|
-
onEndReached:
|
|
613
|
-
startReachedThreshold:
|
|
614
|
-
endReachedThreshold:
|
|
615
|
-
scrollToMessageKey:
|
|
616
|
+
onEndReached: H,
|
|
617
|
+
startReachedThreshold: K,
|
|
618
|
+
endReachedThreshold: F,
|
|
619
|
+
scrollToMessageKey: a,
|
|
616
620
|
onScrollToMessageComplete: E
|
|
617
|
-
}),
|
|
621
|
+
}), R = oe.useRef(B);
|
|
618
622
|
oe.useEffect(() => {
|
|
619
|
-
|
|
623
|
+
R.current !== B && (R.current = B, g == null || g(B));
|
|
620
624
|
}, [B, g]), ve(
|
|
621
625
|
e,
|
|
622
626
|
() => ({
|
|
@@ -624,15 +628,15 @@ function Me(a, e) {
|
|
|
624
628
|
scrollToIndex: A,
|
|
625
629
|
scrollToKey: w,
|
|
626
630
|
getScrollTop: () => {
|
|
627
|
-
var
|
|
628
|
-
return ((
|
|
631
|
+
var $;
|
|
632
|
+
return (($ = j.current) == null ? void 0 : $.scrollTop) ?? 0;
|
|
629
633
|
},
|
|
630
634
|
isAtBottom: () => B,
|
|
631
|
-
prepareAnchor:
|
|
635
|
+
prepareAnchor: X
|
|
632
636
|
}),
|
|
633
|
-
[T, A, w, j, B,
|
|
637
|
+
[T, A, w, j, B, X]
|
|
634
638
|
);
|
|
635
|
-
const { Header:
|
|
639
|
+
const { Header: L, Footer: V, EmptyPlaceholder: G } = b;
|
|
636
640
|
return t.length === 0 && G ? /* @__PURE__ */ J(G, {}) : /* @__PURE__ */ ae(
|
|
637
641
|
"div",
|
|
638
642
|
{
|
|
@@ -649,24 +653,24 @@ function Me(a, e) {
|
|
|
649
653
|
...C
|
|
650
654
|
},
|
|
651
655
|
children: [
|
|
652
|
-
|
|
653
|
-
/* @__PURE__ */ J("div", { ref:
|
|
656
|
+
L && /* @__PURE__ */ J(L, {}),
|
|
657
|
+
/* @__PURE__ */ J("div", { ref: W, style: { height: M, position: "relative", width: "100%" }, children: O.map(($) => /* @__PURE__ */ J(
|
|
654
658
|
he,
|
|
655
659
|
{
|
|
656
|
-
virtualItem:
|
|
660
|
+
virtualItem: $,
|
|
657
661
|
measureItem: u,
|
|
658
|
-
children: s(
|
|
662
|
+
children: s($.index, $.data)
|
|
659
663
|
},
|
|
660
|
-
|
|
664
|
+
$.key
|
|
661
665
|
)) }),
|
|
662
|
-
|
|
666
|
+
V && /* @__PURE__ */ J(V, {})
|
|
663
667
|
]
|
|
664
668
|
}
|
|
665
669
|
);
|
|
666
670
|
}
|
|
667
671
|
const Ke = ge(Me);
|
|
668
672
|
function Ee({
|
|
669
|
-
data:
|
|
673
|
+
data: f,
|
|
670
674
|
itemContent: e,
|
|
671
675
|
computeItemKey: t,
|
|
672
676
|
estimatedItemSize: s = 60,
|
|
@@ -677,8 +681,8 @@ function Ee({
|
|
|
677
681
|
className: l,
|
|
678
682
|
style: h
|
|
679
683
|
}) {
|
|
680
|
-
const { scrollerRef: v, innerRef:
|
|
681
|
-
items:
|
|
684
|
+
const { scrollerRef: v, innerRef: i, virtualItems: p, totalSize: H, measureItem: K } = fe({
|
|
685
|
+
items: f,
|
|
682
686
|
getKey: (g, b) => t(b, g),
|
|
683
687
|
estimatedItemSize: s,
|
|
684
688
|
overscan: c,
|
|
@@ -695,8 +699,8 @@ function Ee({
|
|
|
695
699
|
};
|
|
696
700
|
return g.addEventListener("scroll", S, { passive: !0 }), () => g.removeEventListener("scroll", S);
|
|
697
701
|
}, [v, n, r]);
|
|
698
|
-
const { Header:
|
|
699
|
-
return
|
|
702
|
+
const { Header: F, Footer: a, EmptyPlaceholder: E } = y;
|
|
703
|
+
return f.length === 0 && E ? /* @__PURE__ */ J(E, {}) : /* @__PURE__ */ ae(
|
|
700
704
|
"div",
|
|
701
705
|
{
|
|
702
706
|
ref: v,
|
|
@@ -711,22 +715,22 @@ function Ee({
|
|
|
711
715
|
...h
|
|
712
716
|
},
|
|
713
717
|
children: [
|
|
714
|
-
|
|
715
|
-
/* @__PURE__ */ J("div", { ref:
|
|
718
|
+
F && /* @__PURE__ */ J(F, {}),
|
|
719
|
+
/* @__PURE__ */ J("div", { ref: i, style: { height: H, position: "relative", width: "100%" }, children: p.map((g) => /* @__PURE__ */ J(
|
|
716
720
|
he,
|
|
717
721
|
{
|
|
718
722
|
virtualItem: g,
|
|
719
|
-
measureItem:
|
|
723
|
+
measureItem: K,
|
|
720
724
|
children: e(g.index, g.data)
|
|
721
725
|
},
|
|
722
726
|
g.key
|
|
723
727
|
)) }),
|
|
724
|
-
|
|
728
|
+
a && /* @__PURE__ */ J(a, {})
|
|
725
729
|
]
|
|
726
730
|
}
|
|
727
731
|
);
|
|
728
732
|
}
|
|
729
|
-
function Be(
|
|
733
|
+
function Be(f) {
|
|
730
734
|
const {
|
|
731
735
|
fetcher: e,
|
|
732
736
|
initialPage: t = 1,
|
|
@@ -734,77 +738,77 @@ function Be(a) {
|
|
|
734
738
|
getKey: c,
|
|
735
739
|
onPageLoaded: n,
|
|
736
740
|
onError: r
|
|
737
|
-
} =
|
|
741
|
+
} = f, [y, l] = Y([]), [h, v] = Y(t), [i, p] = Y(!0), [H, K] = Y(!1), [F, a] = Y(!1), [E, g] = Y(!1), b = d(/* @__PURE__ */ new Set()), S = d(!1), C = k(
|
|
738
742
|
(u) => c ? u.filter((A) => {
|
|
739
743
|
const T = c(A);
|
|
740
744
|
return b.current.has(T) ? !1 : (b.current.add(T), !0);
|
|
741
745
|
}) : u,
|
|
742
746
|
[c]
|
|
743
747
|
), j = k(async () => {
|
|
744
|
-
if (!(S.current || !
|
|
748
|
+
if (!(S.current || !i)) {
|
|
745
749
|
S.current = !0, g(!0);
|
|
746
750
|
try {
|
|
747
751
|
const u = h + 1, A = await e(u), T = C(A.data);
|
|
748
752
|
l(
|
|
749
753
|
(w) => s === "prepend" ? [...T, ...w] : [...w, ...T]
|
|
750
|
-
), v(u), p(A.hasNextPage),
|
|
754
|
+
), v(u), p(A.hasNextPage), K(A.hasPrevPage), n == null || n(u, T);
|
|
751
755
|
} catch (u) {
|
|
752
756
|
r == null || r(u instanceof Error ? u : new Error(String(u)));
|
|
753
757
|
} finally {
|
|
754
758
|
g(!1), S.current = !1;
|
|
755
759
|
}
|
|
756
760
|
}
|
|
757
|
-
}, [h,
|
|
758
|
-
if (!(S.current || !
|
|
761
|
+
}, [h, i, e, C, s, n, r]), W = k(async () => {
|
|
762
|
+
if (!(S.current || !H)) {
|
|
759
763
|
S.current = !0, g(!0);
|
|
760
764
|
try {
|
|
761
765
|
const u = h - 1, A = await e(u), T = C(A.data);
|
|
762
|
-
l((w) => [...T, ...w]), v(u),
|
|
766
|
+
l((w) => [...T, ...w]), v(u), K(A.hasPrevPage), p(A.hasNextPage), n == null || n(u, T);
|
|
763
767
|
} catch (u) {
|
|
764
768
|
r == null || r(u instanceof Error ? u : new Error(String(u)));
|
|
765
769
|
} finally {
|
|
766
770
|
g(!1), S.current = !1;
|
|
767
771
|
}
|
|
768
772
|
}
|
|
769
|
-
}, [h,
|
|
773
|
+
}, [h, H, e, C, n, r]), O = k(async () => {
|
|
770
774
|
if (!S.current) {
|
|
771
|
-
S.current = !0,
|
|
775
|
+
S.current = !0, a(!0);
|
|
772
776
|
try {
|
|
773
777
|
const u = await e(t), A = u.data;
|
|
774
778
|
if (c) {
|
|
775
779
|
const T = new Set(A.map(c));
|
|
776
780
|
A.forEach((w) => b.current.add(c(w))), l((w) => {
|
|
777
|
-
const B = w.filter((
|
|
781
|
+
const B = w.filter((X) => !T.has(c(X)));
|
|
778
782
|
return s === "prepend" ? [...A, ...B] : [...B, ...A];
|
|
779
783
|
});
|
|
780
784
|
} else
|
|
781
785
|
l(A);
|
|
782
|
-
v(t), p(u.hasNextPage),
|
|
786
|
+
v(t), p(u.hasNextPage), K(u.hasPrevPage), n == null || n(t, A);
|
|
783
787
|
} catch (u) {
|
|
784
788
|
r == null || r(u instanceof Error ? u : new Error(String(u)));
|
|
785
789
|
} finally {
|
|
786
|
-
|
|
790
|
+
a(!1), S.current = !1;
|
|
787
791
|
}
|
|
788
792
|
}
|
|
789
|
-
}, [e, t, c, s, n, r]),
|
|
790
|
-
l([]), v(t), p(!0),
|
|
793
|
+
}, [e, t, c, s, n, r]), M = k(() => {
|
|
794
|
+
l([]), v(t), p(!0), K(!1), a(!1), g(!1), b.current.clear(), S.current = !1;
|
|
791
795
|
}, [t]);
|
|
792
796
|
return {
|
|
793
797
|
items: y,
|
|
794
798
|
loadNextPage: j,
|
|
795
|
-
loadPrevPage:
|
|
796
|
-
hasNextPage:
|
|
797
|
-
hasPrevPage:
|
|
798
|
-
loading:
|
|
799
|
+
loadPrevPage: W,
|
|
800
|
+
hasNextPage: i,
|
|
801
|
+
hasPrevPage: H,
|
|
802
|
+
loading: F,
|
|
799
803
|
loadingMore: E,
|
|
800
|
-
refresh:
|
|
801
|
-
reset:
|
|
804
|
+
refresh: O,
|
|
805
|
+
reset: M,
|
|
802
806
|
currentPage: h
|
|
803
807
|
};
|
|
804
808
|
}
|
|
805
809
|
export {
|
|
806
810
|
Ke as ChatVirtualList,
|
|
807
811
|
Ee as VirtualList,
|
|
808
|
-
|
|
812
|
+
be as useChatVirtualizer,
|
|
809
813
|
Be as usePagination
|
|
810
814
|
};
|