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