fixed-size-list-ec5399cb.js 6.1 KB

123456
  1. import{bu as ht,bM as dt,bv as mt,d as St,ai as gt,b5 as vt,r as D,bN as H,Y as w,a as r,q as pt,bO as wt,bP as yt,aV as st,bg as j,bQ as G,aj as B,bR as Ot,bS as xt,__tla as Mt}from"./index-893d5d13.js";import{H as ot,V as bt,v as zt,I as at,S as rt,u as Tt,i as J,R as K,g as it,a as Rt,b as nt,c as It,B as Et,F as _t,d as Y,A as ct,e as Wt,C as ft,E as $t,f as Lt,h as kt,__tla as Dt}from"./el-virtual-list-ac8e07f6.js";let ut,Z,Ft=Promise.all([(()=>{try{return Mt}catch{}})(),(()=>{try{return Dt}catch{}})()]).then(async()=>{let tt;tt={[ot]:"deltaX",[bt]:"deltaY"},Z=({name:u,getOffset:m,getItemSize:S,getItemOffset:E,getEstimatedTotalSize:_,getStartIndexForOffset:z,getStopIndexForStartIndex:T,initCache:g,clearCache:h,validateProps:R})=>St({name:u??"ElVirtualList",props:zt,emits:[at,rt],setup(e,{emit:d,expose:y}){R(e);const N=gt(),W=vt("vl"),O=D(g(e,N)),$=Tt(),I=D(),F=D(),q=D(),i=D({isScrolling:!1,scrollDir:"forward",scrollOffset:H(e.initScrollOffset)?e.initScrollOffset:0,updateRequested:!1,isScrollbarDragging:!1,scrollbarAlwaysOn:e.scrollbarAlwaysOn}),C=w(()=>{const{total:t,cache:l}=e,{isScrolling:o,scrollDir:n,scrollOffset:s}=r(i);if(t===0)return[0,0,0,0];const a=z(e,s,r(O)),f=T(e,a,s,r(O)),c=o&&n!==Et?1:Math.max(1,l),p=o&&n!==_t?1:Math.max(1,l);return[Math.max(0,a-c),Math.max(0,Math.min(t-1,f+p)),a,f]}),v=w(()=>_(e,r(O))),x=w(()=>J(e.layout)),Q=w(()=>[{position:"relative",["overflow-"+(x.value?"x":"y")]:"scroll",WebkitOverflowScrolling:"touch",willChange:"transform"},{direction:e.direction,height:H(e.height)?`${e.height}px`:e.height,width:H(e.width)?`${e.width}px`:e.width},e.style]),U=w(()=>{const t=r(v),l=r(x);return{height:l?"100%":`${t}px`,pointerEvents:r(i).isScrolling?"none":void 0,width:l?`${t}px`:"100%"}}),M=w(()=>x.value?e.width:e.height),{onWheel:X}=(({atEndEdge:t,atStartEdge:l,layout:o},n)=>{let s,a=0;const f=c=>c<0&&l.value||c>0&&t.value;return{hasReachedEdge:f,onWheel:c=>{ht(s);const p=c[tt[o.value]];f(a)&&f(a+p)||(a+=p,dt()||c.preventDefault(),s=mt(()=>{n(a),a=0}))}}})({atStartEdge:w(()=>i.value.scrollOffset<=0),atEndEdge:w(()=>i.value.scrollOffset>=v.value),layout:w(()=>e.layout)},t=>{var l,o;(o=(l=q.value).onMouseUp)==null||o.call(l),b(Math.min(i.value.scrollOffset+t,v.value-M.value))}),A=()=>{const{total:t}=e;if(t>0){const[s,a,f,c]=r(C);d(at,s,a,f,c)}const{scrollDir:l,scrollOffset:o,updateRequested:n}=r(i);d(rt,l,o,n)},b=t=>{(t=Math.max(t,0))!==r(i).scrollOffset&&(i.value={...r(i),scrollOffset:t,scrollDir:Y(r(i).scrollOffset,t),updateRequested:!0},B(L))},P=(t,l=ct)=>{const{scrollOffset:o}=r(i);t=Math.max(0,Math.min(t,e.total-1)),b(m(e,t,l,o,r(O)))},L=()=>{i.value.isScrolling=!1,B(()=>{$.value(-1,null,null)})},k=()=>{const t=I.value;t&&(t.scrollTop=0)};pt(()=>{if(!wt)return;const{initScrollOffset:t}=e,l=r(I);H(t)&&l&&(r(x)?l.scrollLeft=t:l.scrollTop=t),A()}),yt(()=>{const{direction:t,layout:l}=e,{scrollOffset:o,updateRequested:n}=r(i),s=r(I);if(n&&s)if(l===ot)if(t===K)switch(it()){case nt:s.scrollLeft=-o;break;case Rt:s.scrollLeft=o;break;default:{const{clientWidth:a,scrollWidth:f}=s;s.scrollLeft=f-a-o;break}}else s.scrollLeft=o;else s.scrollTop=o});const V={ns:W,clientSize:M,estimatedTotalSize:v,windowStyle:Q,windowRef:I,innerRef:F,innerStyle:U,itemsToRender:C,scrollbarRef:q,states:i,getItemStyle:t=>{const{direction:l,itemSize:o,layout:n}=e,s=$.value(h&&o,h&&n,h&&l);let a;if(Ot(s,String(t)))a=s[t];else{const f=E(e,t,r(O)),c=S(e,t,r(O)),p=r(x),et=l===K,lt=p?f:0;s[t]=a={position:"absolute",left:et?void 0:`${lt}px`,right:et?`${lt}px`:void 0,top:p?0:`${f}px`,height:p?"100%":`${c}px`,width:p?`${c}px`:"100%"}}return a},onScroll:t=>{r(x)?(l=>{const{clientWidth:o,scrollLeft:n,scrollWidth:s}=l.currentTarget,a=r(i);if(a.scrollOffset===n)return;const{direction:f}=e;let c=n;if(f===K)switch(it()){case nt:c=-n;break;case Wt:c=s-o-n}c=Math.max(0,Math.min(c,s-o)),i.value={...a,isScrolling:!0,scrollDir:Y(a.scrollOffset,c),scrollOffset:c,updateRequested:!1},B(L)})(t):(l=>{const{clientHeight:o,scrollHeight:n,scrollTop:s}=l.currentTarget,a=r(i);if(a.scrollOffset===s)return;const f=Math.max(0,Math.min(s,n-o));i.value={...a,isScrolling:!0,scrollDir:Y(a.scrollOffset,f),scrollOffset:f,updateRequested:!1},B(L)})(t),A()},onScrollbarScroll:(t,l)=>{const o=(v.value-M.value)/l*t;b(Math.min(v.value-M.value,o))},onWheel:X,scrollTo:b,scrollToItem:P,resetScrollTop:k};return y({windowRef:I,innerRef:F,getItemStyleCache:$,scrollTo:b,scrollToItem:P,resetScrollTop:k,states:i}),V},render(e){var d;const{$slots:y,className:N,clientSize:W,containerElement:O,data:$,getItemStyle:I,innerElement:F,itemsToRender:q,innerStyle:i,layout:C,total:v,onScroll:x,onScrollbarScroll:Q,onWheel:U,states:M,useIsScrolling:X,windowStyle:A,ns:b}=e,[P,L]=q,k=st(O),V=st(F),t=[];if(v>0)for(let s=P;s<=L;s++)t.push((d=y.default)==null?void 0:d.call(y,{data:$,key:s,index:s,isScrolling:X?M.isScrolling:void 0,style:I(s)}));const l=[j(V,{style:i,ref:"innerRef"},G(V)?t:{default:()=>t})],o=j(It,{ref:"scrollbarRef",clientSize:W,layout:C,onScroll:Q,ratio:100*W/this.estimatedTotalSize,scrollFrom:M.scrollOffset/(this.estimatedTotalSize-W),total:v}),n=j(k,{class:[b.e("window"),N],style:A,onScroll:x,onWheel:U,ref:"windowRef",key:0},G(k)?[l]:{default:()=>[l]});return j("div",{key:0,class:[b.e("wrapper"),M.scrollbarAlwaysOn?"always-on":""]},[n,o])}}),ut=Z({name:"ElFixedSizeList",getItemOffset:({itemSize:u},m)=>m*u,getItemSize:({itemSize:u})=>u,getEstimatedTotalSize:({total:u,itemSize:m})=>m*u,getOffset:({height:u,total:m,itemSize:S,layout:E,width:_},z,T,g)=>{const h=J(E)?_:u;G(h)&&xt("[ElVirtualList]",`
  2. You should set
  3. width/height
  4. to number when your layout is
  5. horizontal/vertical
  6. `);const R=Math.max(0,m*S-h),e=Math.min(R,z*S),d=Math.max(0,(z+1)*S-h);switch(T===kt&&(T=g>=d-h&&g<=e+h?ct:ft),T){case Lt:return e;case $t:return d;case ft:{const y=Math.round(d+(e-d)/2);return y<Math.ceil(h/2)?0:y>R+Math.floor(h/2)?R:y}default:return g>=d&&g<=e?g:g<d?d:e}},getStartIndexForOffset:({total:u,itemSize:m},S)=>Math.max(0,Math.min(u-1,Math.floor(S/m))),getStopIndexForStartIndex:({height:u,total:m,itemSize:S,layout:E,width:_},z,T)=>{const g=z*S,h=J(E)?_:u,R=Math.ceil((h+T-g)/S);return Math.max(0,Math.min(m-1,z+R-1))},initCache(){},clearCache:!0,validateProps(){}})});export{ut as F,Ft as __tla,Z as c};