UNPKG

@progress/kendo-vue-grid

Version:
9 lines (8 loc) 8.23 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2026 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("vue");require("@progress/kendo-vue-common");require("@progress/kendo-vue-data-tools");function Pe(d){const u=[],a=[];for(let t=0;t<d.length;t++){const n=d[t];if(n.rowType==="groupHeader"){for(let e=a.length-1;e>=0;e--)if(a[e].level>=n.level){const r=a[e];u.push({headerIndex:r.headerIndex,footerIndex:null,firstChildIndex:r.headerIndex+1,lastChildIndex:t-1,level:r.level}),a.splice(e,1)}a.push({headerIndex:t,level:n.level})}else if(n.rowType==="groupFooter"){for(let e=a.length-1;e>=0;e--)if(a[e].level===n.level){const r=a[e];u.push({headerIndex:r.headerIndex,footerIndex:t,firstChildIndex:r.headerIndex+1,lastChildIndex:t-1,level:n.level}),a.splice(e,1);break}}}for(const t of a)u.push({headerIndex:t.headerIndex,footerIndex:null,firstChildIndex:t.headerIndex+1,lastChildIndex:d.length-1,level:t.level});const p=new Map;for(const t of u)p.set(t.headerIndex,t);return p}function ke(d,u,a,p,t){var I;const n=[],e=t!=null?t:a,r=[];for(const f of u.values())if(f.headerIndex<a){const v=(I=f.footerIndex)!=null?I:f.lastChildIndex;v>f.headerIndex&&v>=e&&r.push(f)}const o=new Map;for(const f of r){const v=o.get(f.level);(!v||f.headerIndex>v.headerIndex)&&o.set(f.level,f)}const c=Array.from(o.keys()).sort((f,v)=>f-v);for(const f of c){const v=o.get(f);n.push({item:d[v.headerIndex],flatIndex:v.headerIndex})}return n}function Re(d,u,a,p){const t=[],n=[];for(const o of u.values())o.footerIndex!==null&&o.footerIndex>p&&o.headerIndex<=p&&n.push(o);const e=new Map;for(const o of n){const c=e.get(o.level);(!c||o.footerIndex<c.footerIndex)&&e.set(o.level,o)}const r=Array.from(e.keys()).sort((o,c)=>c-o);for(const o of r){const c=e.get(o);t.push({item:d[c.footerIndex],flatIndex:c.footerIndex})}return t}function _(d,u){if(d.length!==u.length)return!0;for(let a=0;a<d.length;a++)if(d[a].flatIndex!==u[a].flatIndex)return!0;return!1}function be(d,u){const a=d.querySelectorAll("tbody > tr");let p=0,t=!1;for(let n=0;n<a.length&&n<u.length;n++){const e=a[n],r=e.offsetHeight||e.getBoundingClientRect().height,o=u[n];if(o<0){t=!0;const c=-o,I=Math.max(r-c,0);p+=I,I<=0?(e.style.display="none",e.style.transform="",e.style.clipPath=""):(e.style.display="",e.style.transform=`translateY(${o}px)`,e.style.clipPath=`inset(${c}px 0 0 0)`)}else p+=r,e.style.display="",e.style.transform="",e.style.clipPath=""}d.style.height=t?p+"px":""}function we(d,u){const a=d.querySelectorAll("tbody > tr");let p=0,t=!1,n=0;const e=[];for(let r=0;r<a.length&&r<u.length;r++){const o=a[r],c=o.offsetHeight||o.getBoundingClientRect().height;e.push(c);const I=u[r];if(I>0){t=!0;const f=Math.max(c-I,0);p+=f,n+=c-f}else p+=c}for(let r=0;r<a.length&&r<u.length;r++){const o=a[r],c=u[r],I=e[r];c>0?Math.max(I-c,0)<=0?(o.style.display="",o.style.transform="",o.style.clipPath="inset(0 0 100% 0)"):(o.style.display="",o.style.transform="",o.style.clipPath=`inset(0 0 ${c}px 0)`):(o.style.display="",o.style.transform=t?`translateY(${-n}px)`:"",o.style.clipPath="")}d.style.height=t?p+"px":""}function $e(d){const{enabled:u,enabledFooters:a,flatData:p,stickyHeaderRef:t,stickyFooterRef:n,containerRef:e,tableBodyRef:r,isGrouped:o,virtualSkipRef:c,rowHeight:I,rowHeightServiceRef:f}=d,v=u&&o.value,A=!!a&&o.value,G=w.ref([]),ee=w.ref([]),K=w.ref([]),N=w.ref([]),te=w.ref([]),Q=w.ref([]),oe=w.ref(!1),se=w.ref(!1);w.onUpdated(()=>{var h;oe.value&&((h=t.value)!=null&&h.$el)&&ee.value.length>0&&(be(t.value.$el,ee.value),oe.value=!1),t.value&&e.value&&(t.value.$el.scrollLeft=e.value.scrollLeft)}),w.onUpdated(()=>{var h,H;se.value&&((h=n.value)!=null&&h.$el)&&te.value.length>0&&(we((H=n.value)==null?void 0:H.$el,te.value),se.value=!1),n.value&&e.value&&(n.value.$el.scrollLeft=e.value.scrollLeft)});const Te=()=>{var ge,ve,pe,ye,me,xe,Ie;if(!v&&!A)return;const h=p.value,H=Pe(h);if(H.size===0)return;const B=new Map;if(A)for(const s of H.values())s.footerIndex!==null&&B.set(s.footerIndex,s);const R=e.value,O=r.value;if(!R||!O)return;const b=R.scrollTop,V=R.clientHeight,U=O.children;if(U.length===0)return;const T=f==null?void 0:f.value,W=I||36,g=(c==null?void 0:c.value)||0,M=R.getBoundingClientRect(),S=O.getBoundingClientRect().top-M.top+b,P=U.length,Y=new Array(P),X=new Array(P);for(let s=0;s<P;s++){const l=U[s];Y[s]=S+l.offsetTop,X[s]=l.offsetHeight}const le=s=>{const l=s-g;return l>=0&&l<P?X[l]:T&&s>=0&&s<h.length?T.height(s):W},ae=s=>{const l=s-g;if(l>=0&&l<P)return Y[l];if(T&&s>=0&&s<h.length)return T.offset(s)},Ce=s=>{let l=0,i=P;for(;l<i;){const y=l+i>>1;Y[y]<s?l=y+1:i=y}return l},ie=s=>{const l=Ce(s);return l<P?g+l:g},ce=s=>{let l=0,i=P-1;for(;l<=i;){const y=l+i>>1;Y[y]+X[y]<=s?l=y+1:i=y-1}return i>=0?g+i:h.length-1},fe=Math.min(ie(b),h.length-1);let j=fe;const ue=s=>{const l=s.querySelectorAll("tbody > tr");for(let i=0;i<l.length;i++){const y=l[i];y.style.transform="",y.style.clipPath="",y.style.display=""}s.style.height=""};if(v&&t.value){let s=0,l=[],i=[];const y=k=>{var x;const F=[];let m=0;for(const C of k){const $=le(C);let L=0;const q=H.get(C);if(q){const Z=(x=q.footerIndex)!=null?x:q.lastChildIndex+1,E=ae(Z);if(E!==void 0){const J=m+$,He=E-b;He<J&&(L=He-J)}}F.push(L),m+=Math.max($+L,0)}return{totalHeight:m,offsets:F}},z=new Set;for(;;){j=Math.min(ie(b+Math.max(s,0)),h.length-1);const k=z.has(j);z.add(j);const F=Math.min(ce(b+V),h.length-1),m=ke(h,H,j,F,fe),x=y(m.map($=>$.flatIndex)),C=!_(m,i)&&Math.abs(x.totalHeight-s)<1;if(i=m,s=x.totalHeight,l=x.offsets,C||k)break}const ne=i.length>0,re=G.value,D=_(i,re);ne?D?(G.value=i,ee.value=l,oe.value=!0):(t.value.$el.style.display="",be((ve=t.value)==null?void 0:ve.$el,l)):(t.value.$el.style.display="none",ue((ge=t.value)==null?void 0:ge.$el)),D&&(K.value=i,G.value=i)}if(A&&n.value){let s=0,l=[],i=[];const y=k=>{const F=[];let m=0;for(let x=k.length-1;x>=0;x--){const C=k[x],$=le(C);let L=0;const q=B.get(C);if(q){const Z=ae(q.headerIndex);if(Z!==void 0){const E=Z+le(q.headerIndex),J=b+V-m-$;E>J&&(L=E-J)}}F[x]=L,m+=Math.max($-L,0)}return{totalHeight:m,offsets:F}},z=new Set;for(;;){const k=Math.min(ce(b+V-s),h.length-1),F=z.has(k);z.add(k);const m=Re(h,H,j,k),x=y(m.map($=>$.flatIndex)),C=!_(m,i)&&Math.abs(x.totalHeight-s)<1;if(i=m,s=x.totalHeight,l=x.offsets,C||F)break}const ne=i.length>0,re=N.value,D=_(i,re);ne?D?(N.value=i,te.value=l,se.value=!0):(n.value.$el.style.display="",we(n.value.$el,l)):(n.value.$el.style.display="none",ue((pe=n.value)==null?void 0:pe.$el)),D&&(Q.value=i,N.value=i)}const de=((me=(ye=t.value)==null?void 0:ye.$el)==null?void 0:me.offsetHeight)||0,he=((Ie=(xe=n.value)==null?void 0:xe.$el)==null?void 0:Ie.offsetHeight)||0;return R.style.scrollPaddingTop=de>0?de+"px":"",R.style.scrollPaddingBottom=he>0?he+"px":"",{stickyHeaderItems:K,stickyFooterItems:Q}},Fe=h=>{var W;if(!v)return;const H=G.value.find(g=>{var M,S;return((M=g.item.group)==null?void 0:M.field)===h.field&&((S=g.item.group)==null?void 0:S.value)===h.value});if(!H)return;const B=e.value;if(!B)return;let R=0;const O=I||36,b=(W=t.value.$el)==null?void 0:W.querySelectorAll("tbody > tr"),V=G.value;for(let g=0;g<V.length;g++)if(V[g].item.level<H.item.level){const M=b&&g<b.length&&b[g].offsetHeight||O;R+=M}const U=f==null?void 0:f.value;let T;if(U)T=U.offset(H.flatIndex);else{const g=r.value,M=(c==null?void 0:c.value)||0,S=H.flatIndex-M;if(g&&S>=0&&S<g.children.length){const P=g.children[S],Y=B.getBoundingClientRect();T=g.getBoundingClientRect().top-Y.top+B.scrollTop+P.offsetTop}}T!==void 0&&(B.scrollTop=T-R)};return w.watch([()=>v,()=>A,e],()=>{v||(G.value=[],K.value=[]),A||(N.value=[],Q.value=[]),!v&&!A&&e.value&&(e.value.style.scrollPaddingTop="",e.value.style.scrollPaddingBottom="")}),{stickyHeaderItems:K,stickyFooterItems:Q,scrollToStickyGroup:Fe,update:Te}}exports.buildGroupRangeMap=Pe;exports.computeStickyFooterItems=Re;exports.computeStickyItems=ke;exports.useStickyGroups=$e;