UNPKG

@progress/kendo-react-grid

Version:

React Data Grid (Table) provides 100+ ready-to-use data grid features. KendoReact Grid package

10 lines (9 loc) 8.42 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 client"; "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ce=require("react");function Fe(f){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(f){for(const r in f)if(r!=="default"){const h=Object.getOwnPropertyDescriptor(f,r);Object.defineProperty(a,r,h.get?h:{enumerable:!0,get:()=>f[r]})}}return a.default=f,Object.freeze(a)}const x=Fe(Ce);function ve(f){const a=[],r=[];for(let e=0;e<f.length;e++){const u=f[e];if(u.rowType==="groupHeader"){for(let n=r.length-1;n>=0;n--)if(r[n].level>=u.level){const s=r[n];a.push({headerIndex:s.headerIndex,footerIndex:null,firstChildIndex:s.headerIndex+1,lastChildIndex:e-1,level:s.level}),r.splice(n,1)}r.push({headerIndex:e,level:u.level})}else if(u.rowType==="groupFooter"){for(let n=r.length-1;n>=0;n--)if(r[n].level===u.level){const s=r[n];a.push({headerIndex:s.headerIndex,footerIndex:e,firstChildIndex:s.headerIndex+1,lastChildIndex:e-1,level:u.level}),r.splice(n,1);break}}}for(const e of r)a.push({headerIndex:e.headerIndex,footerIndex:null,firstChildIndex:e.headerIndex+1,lastChildIndex:f.length-1,level:e.level});const h=new Map;for(const e of a)h.set(e.headerIndex,e);return h}function Re(f,a,r,h,e){var y;const u=[],n=e!=null?e:r,s=[];for(const d of a.values())if(d.headerIndex<r){const p=(y=d.footerIndex)!=null?y:d.lastChildIndex;p>d.headerIndex&&p>=n&&s.push(d)}const t=new Map;for(const d of s){const p=t.get(d.level);(!p||d.headerIndex>p.headerIndex)&&t.set(d.level,d)}const c=Array.from(t.keys()).sort((d,p)=>d-p);for(const d of c){const p=t.get(d);u.push({item:f[p.headerIndex],flatIndex:p.headerIndex})}return u}function ke(f,a,r,h){const e=[],u=[];for(const t of a.values())t.footerIndex!==null&&t.footerIndex>h&&t.headerIndex<=h&&u.push(t);const n=new Map;for(const t of u){const c=n.get(t.level);(!c||t.footerIndex<c.footerIndex)&&n.set(t.level,t)}const s=Array.from(n.keys()).sort((t,c)=>c-t);for(const t of s){const c=n.get(t);e.push({item:f[c.footerIndex],flatIndex:c.footerIndex})}return e}function W(f,a){if(f.length!==a.length)return!0;for(let r=0;r<f.length;r++)if(f[r].flatIndex!==a[r].flatIndex)return!0;return!1}function be(f,a){const r=f.querySelectorAll("tbody > tr");let h=0,e=!1;for(let u=0;u<r.length&&u<a.length;u++){const n=r[u],s=n.offsetHeight||n.getBoundingClientRect().height,t=a[u];if(t<0){e=!0;const c=-t,y=Math.max(s-c,0);h+=y,y<=0?(n.style.display="none",n.style.transform="",n.style.clipPath=""):(n.style.display="",n.style.transform=`translateY(${t}px)`,n.style.clipPath=`inset(${c}px 0 0 0)`)}else h+=s,n.style.display="",n.style.transform="",n.style.clipPath=""}f.style.height=e?h+"px":""}function He(f,a){const r=f.querySelectorAll("tbody > tr");let h=0,e=!1,u=0;const n=[];for(let s=0;s<r.length&&s<a.length;s++){const t=r[s],c=t.offsetHeight||t.getBoundingClientRect().height;n.push(c);const y=a[s];if(y>0){e=!0;const d=Math.max(c-y,0);h+=d,u+=c-d}else h+=c}for(let s=0;s<r.length&&s<a.length;s++){const t=r[s],c=a[s],y=n[s];c>0?Math.max(y-c,0)<=0?(t.style.display="",t.style.transform="",t.style.clipPath="inset(0 0 100% 0)"):(t.style.display="",t.style.transform="",t.style.clipPath=`inset(0 0 ${c}px 0)`):(t.style.display="",t.style.transform=e?`translateY(${-u}px)`:"",t.style.clipPath="")}f.style.height=e?h+"px":""}function Me(f){const{enabled:a,enabledFooters:r,flatData:h,containerRef:e,tableBodyRef:u,isGrouped:n,virtualSkipRef:s,rowHeight:t,rowHeightServiceRef:c}=f,y=a&&n,d=!!r&&n,p=x.useRef([]),X=x.useRef([]),v=x.useRef(null),[re,le]=x.useState([]),J=x.useRef([]),Z=x.useRef([]),R=x.useRef(null),[ce,ie]=x.useState([]),ee=x.useRef(!1),te=x.useRef(!1);x.useLayoutEffect(()=>{ee.current&&v.current&&X.current.length>0&&(be(v.current,X.current),ee.current=!1),v.current&&e.current&&(v.current.scrollLeft=e.current.scrollLeft)},[re]),x.useLayoutEffect(()=>{te.current&&R.current&&Z.current.length>0&&(He(R.current,Z.current),te.current=!1),R.current&&e.current&&(R.current.scrollLeft=e.current.scrollLeft)},[ce]);const fe=x.useRef(()=>{});fe.current=()=>{var me,xe;if(!y&&!d)return;const H=h,P=ve(H);if(P.size===0)return;const A=new Map;if(d)for(const o of P.values())o.footerIndex!==null&&A.set(o.footerIndex,o);const C=e.current,j=u.current;if(!C||!j)return;const k=C.scrollTop,q=C.clientHeight,$=j.children;if($.length===0)return;const F=c==null?void 0:c.current,K=t||36,g=(s==null?void 0:s.current)||0,O=C.getBoundingClientRect(),B=j.getBoundingClientRect().top-O.top+k,w=$.length,E=new Array(w),Q=new Array(w);for(let o=0;o<w;o++){const l=$[o];E[o]=B+l.offsetTop,Q[o]=l.offsetHeight}const ne=o=>{const l=o-g;return l>=0&&l<w?Q[l]:F&&o>=0&&o<H.length?F.height(o):K},ae=o=>{const l=o-g;if(l>=0&&l<w)return E[l];if(F&&o>=0&&o<H.length)return F.offset(o)},Te=o=>{let l=0,i=w;for(;l<i;){const m=l+i>>1;E[m]<o?l=m+1:i=m}return l},ue=o=>{const l=Te(o);return l<w?g+l:g},de=o=>{let l=0,i=w-1;for(;l<=i;){const m=l+i>>1;E[m]+Q[m]<=o?l=m+1:i=m-1}return i>=0?g+i:H.length-1},he=Math.min(ue(k),H.length-1);let _=he;const ge=o=>{const l=o.querySelectorAll("tbody > tr");for(let i=0;i<l.length;i++){const m=l[i];m.style.transform="",m.style.clipPath="",m.style.display=""}o.style.height=""};if(y&&v.current){let o=0,l=[],i=[];const m=T=>{var b;const M=[];let I=0;for(const S of T){const L=ne(S);let G=0;const V=P.get(S);if(V){const U=(b=V.footerIndex)!=null?b:V.lastChildIndex+1,Y=ae(U);if(Y!==void 0){const N=I+L,Ie=Y-k;Ie<N&&(G=Ie-N)}}M.push(G),I+=Math.max(L+G,0)}return{totalHeight:I,offsets:M}},z=new Set;for(;;){_=Math.min(ue(k+Math.max(o,0)),H.length-1);const T=z.has(_);z.add(_);const M=Math.min(de(k+q),H.length-1),I=Re(H,P,_,M,he),b=m(I.map(L=>L.flatIndex)),S=!W(I,i)&&Math.abs(b.totalHeight-o)<1;if(i=I,o=b.totalHeight,l=b.offsets,S||T)break}const oe=i.length>0,se=p.current,D=W(i,se);oe?D?(p.current=i,X.current=l,ee.current=!0):(v.current.style.display="",be(v.current,l)):(v.current.style.display="none",ge(v.current)),D&&(le(i),p.current=i)}if(d&&R.current){let o=0,l=[],i=[];const m=T=>{const M=[];let I=0;for(let b=T.length-1;b>=0;b--){const S=T[b],L=ne(S);let G=0;const V=A.get(S);if(V){const U=ae(V.headerIndex);if(U!==void 0){const Y=U+ne(V.headerIndex),N=k+q-I-L;Y>N&&(G=Y-N)}}M[b]=G,I+=Math.max(L-G,0)}return{totalHeight:I,offsets:M}},z=new Set;for(;;){const T=Math.min(de(k+q-o),H.length-1),M=z.has(T);z.add(T);const I=ke(H,P,_,T),b=m(I.map(L=>L.flatIndex)),S=!W(I,i)&&Math.abs(b.totalHeight-o)<1;if(i=I,o=b.totalHeight,l=b.offsets,S||M)break}const oe=i.length>0,se=J.current,D=W(i,se);oe?D?(J.current=i,Z.current=l,te.current=!0):(R.current.style.display="",He(R.current,l)):(R.current.style.display="none",ge(R.current)),D&&(ie(i),J.current=i)}const ye=((me=v.current)==null?void 0:me.offsetHeight)||0,pe=((xe=R.current)==null?void 0:xe.offsetHeight)||0;C.style.scrollPaddingTop=ye>0?ye+"px":"",C.style.scrollPaddingBottom=pe>0?pe+"px":""};const Pe=x.useCallback(()=>fe.current(),[]),we=x.useCallback(H=>{var K;if(!y)return;const P=p.current.find(g=>{var O,B;return((O=g.item.group)==null?void 0:O.field)===H.field&&((B=g.item.group)==null?void 0:B.value)===H.value});if(!P)return;const A=e.current;if(!A)return;let C=0;const j=t||36,k=(K=v.current)==null?void 0:K.querySelectorAll("tbody > tr"),q=p.current;for(let g=0;g<q.length;g++)if(q[g].item.level<P.item.level){const O=k&&g<k.length&&k[g].offsetHeight||j;C+=O}const $=c==null?void 0:c.current;let F;if($)F=$.offset(P.flatIndex);else{const g=u.current,O=(s==null?void 0:s.current)||0,B=P.flatIndex-O;if(g&&B>=0&&B<g.children.length){const w=g.children[B],E=A.getBoundingClientRect();F=g.getBoundingClientRect().top-E.top+A.scrollTop+w.offsetTop}}F!==void 0&&(A.scrollTop=F-C)},[y,e,t,c,u,s]);return x.useEffect(()=>{y||(p.current=[],le([])),d||(J.current=[],ie([])),!y&&!d&&e.current&&(e.current.style.scrollPaddingTop="",e.current.style.scrollPaddingBottom="")},[y,d,e]),{stickyHeaderItems:re,stickyHeaderRef:v,stickyFooterItems:ce,stickyFooterRef:R,scrollToStickyGroup:we,update:Pe}}exports.buildGroupRangeMap=ve;exports.computeStickyFooterItems=ke;exports.computeStickyItems=Re;exports.useStickyGroups=Me;