@pravinrd/awesome-grid 0.2.0

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.
@@ -0,0 +1,25 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");var Ie={exports:{}},ve={};/**
2
+ * @license React
3
+ * react-jsx-runtime.production.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var at;function Tt(){if(at)return ve;at=1;var d=Symbol.for("react.transitional.element"),x=Symbol.for("react.fragment");function v(O,S,j){var W=null;if(j!==void 0&&(W=""+j),S.key!==void 0&&(W=""+S.key),"key"in S){j={};for(var U in S)U!=="key"&&(j[U]=S[U])}else j=S;return S=j.ref,{$$typeof:d,type:O,key:W,ref:S!==void 0?S:null,props:j}}return ve.Fragment=x,ve.jsx=v,ve.jsxs=v,ve}var ke={};/**
10
+ * @license React
11
+ * react-jsx-runtime.development.js
12
+ *
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ */var lt;function Et(){return lt||(lt=1,process.env.NODE_ENV!=="production"&&(function(){function d(o){if(o==null)return null;if(typeof o=="function")return o.$$typeof===N?null:o.displayName||o.name||null;if(typeof o=="string")return o;switch(o){case fe:return"Fragment";case Be:return"Profiler";case g:return"StrictMode";case we:return"Suspense";case Y:return"SuspenseList";case Fe:return"Activity"}if(typeof o=="object")switch(typeof o.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),o.$$typeof){case se:return"Portal";case Q:return o.displayName||"Context";case $:return(o._context.displayName||"Context")+".Consumer";case ge:var u=o.render;return o=o.displayName,o||(o=u.displayName||u.name||"",o=o!==""?"ForwardRef("+o+")":"ForwardRef"),o;case z:return u=o.displayName||null,u!==null?u:d(o.type)||"Memo";case ee:u=o._payload,o=o._init;try{return d(o(u))}catch{}}return null}function x(o){return""+o}function v(o){try{x(o);var u=!1}catch{u=!0}if(u){u=console;var w=u.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&o[Symbol.toStringTag]||o.constructor.name||"Object";return w.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),x(o)}}function O(o){if(o===fe)return"<>";if(typeof o=="object"&&o!==null&&o.$$typeof===ee)return"<...>";try{var u=d(o);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function S(){var o=_e.A;return o===null?null:o.getOwner()}function j(){return Error("react-stack-top-frame")}function W(o){if(Ce.call(o,"key")){var u=Object.getOwnPropertyDescriptor(o,"key").get;if(u&&u.isReactWarning)return!1}return o.key!==void 0}function U(o,u){function w(){te||(te=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",u))}w.isReactWarning=!0,Object.defineProperty(o,"key",{get:w,configurable:!0})}function pe(){var o=d(this.type);return ae[o]||(ae[o]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),o=this.props.ref,o!==void 0?o:null}function ne(o,u,w,b,L,ce){var y=w.ref;return o={$$typeof:Ne,type:o,key:u,props:w,_owner:b},(y!==void 0?y:null)!==null?Object.defineProperty(o,"ref",{enumerable:!1,get:pe}):Object.defineProperty(o,"ref",{enumerable:!1,value:null}),o._store={},Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(o,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(o,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:L}),Object.defineProperty(o,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:ce}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o}function Z(o,u,w,b,L,ce){var y=u.children;if(y!==void 0)if(b)if(Re(y)){for(b=0;b<y.length;b++)oe(y[b]);Object.freeze&&Object.freeze(y)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else oe(y);if(Ce.call(u,"key")){y=d(o);var C=Object.keys(u).filter(function(V){return V!=="key"});b=0<C.length?"{key: someKey, "+C.join(": ..., ")+": ...}":"{key: someKey}",re[y+b]||(C=0<C.length?"{"+C.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
+ let props = %s;
19
+ <%s {...props} />
20
+ React keys must be passed directly to JSX without using spread:
21
+ let props = %s;
22
+ <%s key={someKey} {...props} />`,b,y,C,y),re[y+b]=!0)}if(y=null,w!==void 0&&(v(w),y=""+w),W(u)&&(v(u.key),y=""+u.key),"key"in u){w={};for(var be in u)be!=="key"&&(w[be]=u[be])}else w=u;return y&&U(w,typeof o=="function"?o.displayName||o.name||"Unknown":o),ne(o,y,w,S(),L,ce)}function oe(o){je(o)?o._store&&(o._store.validated=1):typeof o=="object"&&o!==null&&o.$$typeof===ee&&(o._payload.status==="fulfilled"?je(o._payload.value)&&o._payload.value._store&&(o._payload.value._store.validated=1):o._store&&(o._store.validated=1))}function je(o){return typeof o=="object"&&o!==null&&o.$$typeof===Ne}var H=l,Ne=Symbol.for("react.transitional.element"),se=Symbol.for("react.portal"),fe=Symbol.for("react.fragment"),g=Symbol.for("react.strict_mode"),Be=Symbol.for("react.profiler"),$=Symbol.for("react.consumer"),Q=Symbol.for("react.context"),ge=Symbol.for("react.forward_ref"),we=Symbol.for("react.suspense"),Y=Symbol.for("react.suspense_list"),z=Symbol.for("react.memo"),ee=Symbol.for("react.lazy"),Fe=Symbol.for("react.activity"),N=Symbol.for("react.client.reference"),_e=H.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Ce=Object.prototype.hasOwnProperty,Re=Array.isArray,T=console.createTask?console.createTask:function(){return null};H={react_stack_bottom_frame:function(o){return o()}};var te,ae={},le=H.react_stack_bottom_frame.bind(H,j)(),G=T(O(j)),re={};ke.Fragment=fe,ke.jsx=function(o,u,w){var b=1e4>_e.recentlyCreatedOwnerStacks++;return Z(o,u,w,!1,b?Error("react-stack-top-frame"):le,b?T(O(o)):G)},ke.jsxs=function(o,u,w){var b=1e4>_e.recentlyCreatedOwnerStacks++;return Z(o,u,w,!0,b?Error("react-stack-top-frame"):le,b?T(O(o)):G)}})()),ke}var ct;function Ot(){return ct||(ct=1,process.env.NODE_ENV==="production"?Ie.exports=Tt():Ie.exports=Et()),Ie.exports}var r=Ot();const At="_container_dihwe_1",Mt="_themeLight_dihwe_10",Dt="_themeDark_dihwe_29",Pt="_themePurple_dihwe_48",It="_headerRow_dihwe_67",$t="_flexRow_dihwe_76",Lt="_toolbarGroup_dihwe_82",Bt="_dropdown_dihwe_86",Ft="_buttonBase_dihwe_90",Wt="_buttonPrimary_dihwe_101",zt="_buttonDanger_dihwe_111",Gt="_buttonMuted_dihwe_121",Vt="_dropdownToggle_dihwe_142",Ut="_dropdownMenu_dihwe_147",Ht="_dropdownMenuOpen_dihwe_163",Yt="_menuItemButton_dihwe_167",Jt="_labelMuted_dihwe_185",qt="_selectSmall_dihwe_190",Xt="_selectAuto_dihwe_199",Kt="_switchRow_dihwe_203",Zt="_groupingSummary_dihwe_210",Qt="_relative_dihwe_217",er="_overlay_dihwe_221",tr="_overlayInner_dihwe_229",rr="_spinner_dihwe_236",nr="_tableWrap_dihwe_252",or="_tableWrapAll_dihwe_256",sr="_table_dihwe_252",ar="_tableHead_dihwe_278",lr="_thCellTop_dihwe_282",cr="_thCellFilter_dihwe_290",ir="_thInner_dihwe_297",ur="_resizeHandle_dihwe_303",dr="_sortButton_dihwe_328",hr="_iconMuted_dihwe_338",mr="_inlineGroup_dihwe_342",pr="_input_dihwe_350",fr="_rowInteractive_dihwe_362",gr="_groupRow_dihwe_375",wr="_groupRowAnimated_dihwe_382",_r="_groupChildRow_dihwe_386",br="_groupToggle_dihwe_390",yr="_groupMeta_dihwe_430",xr="_checkbox_dihwe_438",vr="_dangerText_dihwe_443",kr="_tfoot_dihwe_447",Sr="_textCenter_dihwe_455",jr="_paginationWrap_dihwe_459",Nr="_pagination_dihwe_459",Cr="_pageButton_dihwe_473",Rr="_pageButtonActive_dihwe_488",Tr="_backdrop_dihwe_494",Er="_drawer_dihwe_500",Or="_drawerTitle_dihwe_515",Ar="_drawerSection_dihwe_521",Mr="_drawerSubtitle_dihwe_527",Dr="_sectionToggle_dihwe_534",Pr="_sectionBody_dihwe_547",Ir="_drawerRow_dihwe_551",$r="_spacerAuto_dihwe_558",Lr="_successText_dihwe_562",Br="_srOnly_dihwe_570",s={container:At,themeLight:Mt,themeDark:Dt,themePurple:Pt,headerRow:It,flexRow:$t,toolbarGroup:Lt,dropdown:Bt,buttonBase:Ft,buttonPrimary:Wt,buttonDanger:zt,buttonMuted:Gt,dropdownToggle:Vt,dropdownMenu:Ut,dropdownMenuOpen:Ht,menuItemButton:Yt,labelMuted:Jt,selectSmall:qt,selectAuto:Xt,switchRow:Kt,groupingSummary:Zt,relative:Qt,overlay:er,overlayInner:tr,spinner:rr,tableWrap:nr,tableWrapAll:or,table:sr,tableHead:ar,thCellTop:lr,thCellFilter:cr,thInner:ir,resizeHandle:ur,sortButton:dr,iconMuted:hr,inlineGroup:mr,input:pr,rowInteractive:fr,groupRow:gr,groupRowAnimated:wr,groupChildRow:_r,groupToggle:br,groupMeta:yr,checkbox:xr,dangerText:vr,tfoot:kr,textCenter:Sr,paginationWrap:jr,pagination:Nr,pageButton:Cr,pageButtonActive:Rr,backdrop:Tr,drawer:Er,drawerTitle:Or,drawerSection:Ar,drawerSubtitle:Mr,sectionToggle:Dr,sectionBody:Pr,drawerRow:Ir,spacerAuto:$r,successText:Lr,srOnly:Br},E=(...d)=>d.filter(Boolean).join(" ");function it({label:d,children:x}){const[v,O]=l.useState(!1),S=l.useRef(null);return l.useEffect(()=>{const j=W=>{S.current&&!S.current.contains(W.target)&&O(!1)};return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[]),r.jsxs("div",{className:s.dropdown,ref:S,children:[r.jsx("button",{className:E(s.buttonBase,s.buttonPrimary,s.dropdownToggle),type:"button","aria-haspopup":"menu","aria-expanded":v,onClick:()=>O(!v),children:d}),r.jsx("ul",{className:E(s.dropdownMenu,v&&s.dropdownMenuOpen),role:"menu",onClick:()=>O(!1),children:x})]})}const Ue=(d,x="14px system-ui")=>{const O=(Ue.canvas||(Ue.canvas=document.createElement("canvas"))).getContext("2d");return O.font=x,O.measureText(d).width},Se=d=>d.toLowerCase().replace(/[_\s]+(.)?/g,(x,v)=>v?v.toUpperCase():"").replace(/^(.)/,x=>x.toLowerCase()),Fr=d=>{if(!d||typeof d!="object")return d;const x={};return Object.keys(d).forEach(v=>{x[Se(v)]=d[v]}),x},X=0,$e=38,ut=10,Wr=[],Le=80;function zr({apiEndpoint:d,rowKey:x,theme:v="light",computedColumns:O=Wr,currency:S="INR",dateFormat:j={locale:"en-US",options:{year:"numeric",month:"2-digit",day:"2-digit"}},dateSeparator:W="/",pageSizeOptions:U=[50,100,500,1e3,0],defaultPageSize:pe}){const ne=l.useRef(!1),Z=l.useRef(!1),oe=l.useRef(!1),je=50,[H,Ne]=l.useState(!0),[se,fe]=l.useState([]),[g,Be]=l.useState([]),[$,Q]=l.useState([]),[ge,we]=l.useState(!1),[Y,z]=l.useState(1),ee=Array.isArray(U)&&U.length>0?U:[50,100,500,1e3,0],Fe=pe!==void 0&&ee.includes(pe)?pe:ee[0]||50,[N,_e]=l.useState(Fe),[Ce,Re]=l.useState(!1),[T,te]=l.useState([]),[ae,le]=l.useState({}),[G,re]=l.useState([]),[o,u]=l.useState(()=>{const e=String(v||"light").toLowerCase();return e==="dark"||e==="purple"?e:"light"}),[w,b]=l.useState({groupBy:!1,aggregates:!1}),[L,ce]=l.useState({}),y=l.useDeferredValue(L),[C,be]=l.useState({key:null,direction:"asc"}),[V,ye]=l.useState([]),[Te,Ee]=l.useState({}),[dt,I]=l.useTransition(),He=l.useRef(null),[ht,mt]=l.useState(0),Oe=l.useRef(null),[Ye,Je]=l.useState(0),[qe,pt]=l.useState(0),ie=l.useRef(null),[ft,Xe]=l.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(max-width: 767.98px)").matches),We=String(S||"INR").toUpperCase()==="USD"?"USD":"INR",Ke=We==="USD"?"en-US":"en-IN",Ze=j?.locale||"en-US",Qe=l.useMemo(()=>j?.options||{year:"numeric",month:"2-digit",day:"2-digit"},[j]);l.useEffect(()=>{N>100&&we(!0)},[N]),l.useEffect(()=>{let e=!0;const t=new AbortController;return(async()=>{try{we(!0);const n=new URLSearchParams({page:String(Y),pageSize:String(N)}),a=await fetch(`${d}?${n.toString()}`,{signal:t.signal});if(!a.ok)throw new Error(`Request failed: ${a.status} ${a.statusText}`);const c=await a.json();if(!e)return;const i=(Array.isArray(c?.data)?c.data:[]).map(p=>Fr(p)),f=c?.columns||[],_=O.filter(p=>p&&p.key&&typeof p.formula=="function").map(p=>({key:Se(p.key),label:p.label||p.key,formula:p.formula})),m=f.map(p=>{const R=typeof p=="string"?p:p.key;return{key:Se(R),label:p.label||R.replace(/_/g," ").replace(/\b\w/g,F=>F.toUpperCase())}}),k=[...m,..._.filter(p=>!m.some(R=>R.key===p.key)).map(({key:p,label:R})=>({key:p,label:R}))],A=i.map(p=>{const R={...p};return _.forEach(F=>{try{R[F.key]=F.formula(p)}catch(me){R[F.key]="",console.error(`Failed computed column formula for '${F.key}'`,me)}}),R});if(fe(A),Be(k),!ne.current){const p=k.map(R=>R.key);Q(p),ye(p),ne.current=!0}}catch(n){if(n?.name==="AbortError")return;console.error("Failed to load grid data",n)}finally{e&&we(!1)}})(),()=>{e=!1,t.abort()}},[d,Y,N,O]),l.useEffect(()=>{if(g.length>0&&$.length===0){const e=g.map(t=>t.key);Q(e),ye(e),ne.current=!0}},[g,$]),l.useEffect(()=>{if(!g.length)return;const e=g.map(t=>t.key);ye(t=>{const n=t.filter(c=>e.includes(c)),a=e.filter(c=>!n.includes(c));return[...n,...a]}),Q(t=>{if(!t.length)return e;const n=t.filter(c=>e.includes(c)),a=e.filter(c=>!n.includes(c));return[...n,...a]})},[g]),l.useEffect(()=>{if(!g.length)return;const e=new Set(g.map(t=>t.key));te(t=>t.filter(n=>e.has(n)))},[g]),l.useEffect(()=>{const e=()=>z(1);return window.addEventListener("refreshTable",e),()=>window.removeEventListener("refreshTable",e)},[]),l.useEffect(()=>{if(!d)return;Z.current=!1,oe.current=!1;const e=localStorage.getItem(`columnOrder_${d}`),t=localStorage.getItem(`visibleColumns_${d}`),n=localStorage.getItem(`groupByColumns_${d}`),a=localStorage.getItem(`totalColumns_${d}`),c=localStorage.getItem(`theme_${d}`),h=localStorage.getItem(`columnWidths_${d}`);if(e&&(ye(JSON.parse(e)),ne.current=!0),t&&Q(JSON.parse(t)),n&&te(JSON.parse(n)),a&&(re(JSON.parse(a)),Z.current=!0),h&&Ee(JSON.parse(h)),c==="light"||c==="dark"||c==="purple")u(c);else{const i=String(v||"light").toLowerCase();u(i==="dark"||i==="purple"?i:"light")}oe.current=!0},[d,v]),l.useEffect(()=>{d&&oe.current&&(V.length>0&&localStorage.setItem(`columnOrder_${d}`,JSON.stringify(V)),$.length>0&&localStorage.setItem(`visibleColumns_${d}`,JSON.stringify($)),localStorage.setItem(`groupByColumns_${d}`,JSON.stringify(T)),localStorage.setItem(`totalColumns_${d}`,JSON.stringify(G)),localStorage.setItem(`theme_${d}`,o),localStorage.setItem(`columnWidths_${d}`,JSON.stringify(Te)))},[d,V,$,T,G,o,Te]);const J=(e,t)=>e[t]??"",ue=l.useCallback(e=>{const t=Number(e);return Number.isNaN(t)?"":new Intl.NumberFormat(Ke,{style:"currency",currency:We,maximumFractionDigits:2}).format(t)},[Ke,We]),gt=l.useCallback(e=>{const t=new Date(e);return Number.isNaN(t.getTime())?e??"":new Intl.DateTimeFormat(Ze,Qe).formatToParts(t).filter(a=>a.type==="year"||a.type==="month"||a.type==="day").map(a=>a.value).join(W)},[Ze,Qe,W]),q=l.useCallback(e=>{const t=se[0]?.[e];return t==null?"text":isNaN(Number(t))?isNaN(Date.parse(t))?"text":"date":"number"},[se]),et=e=>{const t=new Date(e);return Number.isNaN(t.getTime())?null:`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`},Ae=l.useMemo(()=>g.filter(e=>q(e.key)==="number"),[g,q]);l.useEffect(()=>{if(!g.length)return;const e=Ae.map(t=>t.key);if(!e.length){re([]);return}re(t=>{const n=new Set(e);return Z.current?t.filter(a=>n.has(a)):(Z.current=!0,e)})},[g.length,Ae]);const xe=(e,t)=>{I(()=>{ce(n=>({...n,[e]:{...n[e],...t}})),z(1)})},wt=()=>{I(()=>{ce({}),z(1)})},ze=l.useMemo(()=>se.filter(e=>Object.entries(y).every(([t,n])=>{if(!(n?.value!==void 0&&n?.value!==null&&String(n.value).trim()!==""))return!0;const c=J(e,t);if(n.type==="number"){const h=Number(c),i=Number(n.value),f=n.op||"=";return Number.isNaN(h)||Number.isNaN(i)?!0:f==="="?h===i:f===">"?h>i:f==="<"?h<i:f==="!="?h!==i:!0}if(n.type==="date"){const h=et(c),i=et(n.value),f=n.op||"=";return!h||!i?!0:f==="="?h===i:f===">"?h>i:f==="<"?h<i:f==="!="?h!==i:!0}return String(c).toLowerCase().includes(String(n.value).toLowerCase())})),[se,y]),_t=e=>{I(()=>{be(t=>({key:e,direction:t.key===e&&t.direction==="asc"?"desc":"asc"}))})},M=l.useMemo(()=>{if(!C.key)return ze;const e=q(C.key);return[...ze].sort((t,n)=>{const a=J(t,C.key),c=J(n,C.key),h=e==="date"?new Date(a).getTime():isNaN(Number(a))?a:Number(a),i=e==="date"?new Date(c).getTime():isNaN(Number(c))?c:Number(c);return h<i?C.direction==="asc"?-1:1:h>i?C.direction==="asc"?1:-1:0})},[ze,C,q]),Me=l.useMemo(()=>{if(!H)return null;const e={};return g.forEach(t=>{q(t.key)==="number"&&G.includes(t.key)&&(e[t.key]=M.reduce((n,a)=>n+Number(a[t.key]||0),0))}),e},[H,M,g,q,G]),De=N===X?M.length:Math.min(N,je),Ge=N===X?1:Math.ceil(M.length/De),K=l.useMemo(()=>{if(N===X)return M;const e=(Y-1)*De;return M.slice(e,e+De)},[M,Y,N,De]),D=T.length>0,B=!D&&N===X&&!ft,bt=e=>{I(()=>{te(t=>t.includes(e)?t.filter(n=>n!==e):[...t,e]),le({}),z(1)})},yt=e=>{le(t=>({...t,[e]:!t[e]}))},xt=e=>{I(()=>{re(t=>t.includes(e)?t.filter(n=>n!==e):[...t,e])})},tt=l.useCallback(e=>{const t={};return G.forEach(n=>{const a=e.map(_=>Number(_[n])).filter(_=>!Number.isNaN(_));if(!a.length)return;const c=a.reduce((_,m)=>_+m,0),h=Math.min(...a),i=Math.max(...a),f=c/a.length;t[n]={count:a.length,sum:c,avg:f,min:h,max:i}}),t},[G]),Pe=l.useMemo(()=>{if(!D)return[];const e=[],t=M,n=(a,c,h)=>{const i=T[c],f=new Map;a.forEach(_=>{const m=J(_,i),k=m==null||m===""?"(Blank)":String(m);f.has(k)||f.set(k,[]),f.get(k).push(_)}),Array.from(f.entries()).forEach(([_,m],k)=>{const A=`${h}${i}:${_}:${k}`;if(e.push({type:"group",id:A,groupKey:i,groupValue:_,level:c,count:m.length,aggregates:tt(m)}),!ae[A]){if(c<T.length-1){n(m,c+1,`${A}|`);return}m.forEach((p,R)=>{const F=p[Se(x)]??p[x]??R;e.push({type:"row",id:`${A}|row:${F}:${R}`,row:p})})}})};return n(t,0,""),e},[D,M,T,ae,tt,x]),vt=l.useCallback(e=>{B&&Je(e.currentTarget.scrollTop)},[B]);l.useLayoutEffect(()=>{if(!B)return;const e=Oe.current;if(!e)return;const t=()=>pt(e.clientHeight||0);return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[B]),l.useEffect(()=>{Je(0),Oe.current&&(Oe.current.scrollTop=0)},[B,M.length]);const de=l.useMemo(()=>{if(!B)return{start:0,end:K.length,rows:K,topSpacer:0,bottomSpacer:0};const e=K.length,t=Math.ceil((qe||1)/$e),n=Math.max(0,Math.floor(Ye/$e)-ut),a=Math.min(e,n+t+ut*2);return{start:n,end:a,rows:K.slice(n,a),topSpacer:n*$e,bottomSpacer:Math.max(0,(e-a)*$e)}},[B,K,Ye,qe]),Ve=l.useCallback(e=>Object.entries(e||{}).map(([t,n])=>`${g.find(c=>c.key===t)?.label||t}: Σ ${ue(n.sum)} | Avg ${ue(n.avg)} | Min ${ue(n.min)} | Max ${ue(n.max)}`),[g,ue]),kt=()=>{try{const e=P.filter(m=>$.includes(m.key)),t=m=>{const A=String(m??"").replace(/"/g,'""');return/[",\n\r]/.test(A)?`"${A}"`:A},n=D?Pe.map(m=>{if(m.type==="group"){const p=g.find(me=>me.key===m.groupKey)?.label||m.groupKey,R=Ve(m.aggregates).join(" || "),F={};return e.forEach((me,st)=>{if(st===0){F[me.key]=`GROUP ${p}: ${m.groupValue} (${m.count})`;return}F[me.key]=st===1?R:""}),F}const k={},A=m.row;return e.forEach(p=>{k[p.key]=J(A,p.key)}),k}):M.map(m=>{const k={};return e.forEach(A=>{k[A.key]=J(m,A.key)}),k}),a=e.map(m=>t(m.label)).join(","),c=n.map(m=>e.map(k=>t(m[k.key])).join(",")).join(`\r
23
+ `),h=`\uFEFF${a}\r
24
+ ${c}`,i=new Blob([h],{type:"text/csv;charset=utf-8;"}),f=URL.createObjectURL(i),_=document.createElement("a");_.href=f,_.download="TableData.csv",document.body.appendChild(_),_.click(),document.body.removeChild(_),URL.revokeObjectURL(f)}catch(e){console.error("Failed to export CSV",e)}},St=()=>{(async()=>{const[{default:e},{default:t}]=await Promise.all([Promise.resolve().then(()=>require("./jspdf.es.min-C0D3oDUy.cjs")).then(i=>i.jspdf_es_min),Promise.resolve().then(()=>require("./jspdf.plugin.autotable-A1eGW8GI.cjs"))]),n=new e({orientation:"landscape",unit:"pt",format:"A4"}),a=P.filter(i=>$.includes(i.key)),c=[a.map(i=>i.label)],h=D?Pe.map(i=>{if(i.type==="group"){const f=g.find(k=>k.key===i.groupKey)?.label||i.groupKey,_=Ve(i.aggregates);return[{content:[`GROUP ${f}: ${i.groupValue} (${i.count})`,..._].join(`
25
+ `),colSpan:Math.max(1,a.length),styles:{fontStyle:"bold",fillColor:[235,240,250],textColor:[20,40,80],overflow:"linebreak",cellWidth:"wrap"}}]}return a.map(f=>String(J(i.row,f.key)??""))}):M.map(i=>a.map(f=>String(J(i,f.key)??"")));t(n,{head:c,body:h,styles:{fontSize:9,cellPadding:4,halign:"left",valign:"middle"},headStyles:{fillColor:[22,160,133],textColor:[255,255,255],fontStyle:"bold"},margin:{top:40},didDrawPage:i=>{n.setFontSize(12),n.text("Table Data Export",i.settings.margin.left,30)}}),n.save("TableData.pdf")})().catch(e=>{console.error("Failed to export PDF",e)})},rt=(e,t)=>{e.dataTransfer.setData("colKey",t)},nt=(e,t)=>{const n=e.dataTransfer.getData("colKey");!n||n===t||I(()=>{ye(a=>{const c=[...a],h=c.indexOf(n),i=c.indexOf(t);return c.splice(h,1),c.splice(i,0,n),c})})},ot=e=>e.preventDefault(),P=l.useMemo(()=>V.map(e=>g.find(t=>t.key===e)).filter(e=>e&&$.includes(e.key)),[g,V,$]),he=l.useMemo(()=>{const a="14px system-ui",c={};return P.forEach(h=>{const i=Ue(h.label,a),f=Math.min(320,Math.max(Le,i+32+48));c[h.key]=Math.max(Le,Te[h.key]??f)}),c},[P,Te]);l.useEffect(()=>{if(!g.length)return;const e=new Set(g.map(t=>t.key));Ee(t=>{const n={};return Object.entries(t).forEach(([a,c])=>{e.has(a)&&(n[a]=c)}),n})},[g]);const jt=(e,t)=>{if(e.preventDefault(),e.stopPropagation(),e.button!==void 0&&e.button!==0)return;const n=e.clientX,a=he[t]||Le;ie.current={key:t,startX:n,startWidth:a},document.body.style.cursor="col-resize";const c=i=>{if(!ie.current)return;const f=i.clientX-ie.current.startX,_=Math.max(Le,ie.current.startWidth+f);Ee(m=>({...m,[ie.current.key]:_}))},h=()=>{ie.current=null,document.body.style.cursor="",window.removeEventListener("pointermove",c),window.removeEventListener("pointerup",h)};window.addEventListener("pointermove",c),window.addEventListener("pointerup",h)},Nt=(e,t)=>{e.preventDefault(),e.stopPropagation(),Ee(n=>{const a={...n};return delete a[t],a})},Ct=ge||dt,Rt=o==="dark"?s.themeDark:o==="purple"?s.themePurple:s.themeLight;return l.useLayoutEffect(()=>{const e=()=>{mt(He.current?.offsetHeight||0)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[P.length]),l.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const e=window.matchMedia("(max-width: 767.98px)"),t=n=>Xe(n.matches);return Xe(e.matches),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]),r.jsxs("div",{className:E(s.container,Rt),children:[r.jsxs("div",{className:s.headerRow,children:[r.jsxs("div",{className:E(s.flexRow,s.toolbarGroup),children:[r.jsx("label",{className:s.labelMuted,children:"Rows:"}),r.jsx("select",{className:E(s.selectSmall,s.selectAuto),value:N,onChange:e=>I(()=>{_e(Number(e.target.value)),z(1)}),children:ee.map(e=>r.jsx("option",{value:e,children:e===X?"All":e},e))}),r.jsxs("div",{className:s.switchRow,children:[r.jsx("input",{className:s.checkbox,type:"checkbox",checked:H,onChange:e=>I(()=>Ne(e.target.checked))}),r.jsx("label",{className:s.labelMuted,children:"Show Totals"})]}),r.jsxs("div",{className:s.groupingSummary,children:[r.jsxs("span",{className:s.labelMuted,children:["Group By:"," ",T.length?T.map(e=>g.find(t=>t.key===e)?.label||e).join(" > "):"None"]}),T.length>0&&r.jsx("button",{className:E(s.buttonBase,s.buttonMuted),onClick:()=>{I(()=>{te([]),le({})})},children:"Clear Groups"})]})]}),r.jsxs("div",{className:E(s.flexRow,s.toolbarGroup),children:[r.jsxs("button",{className:E(s.buttonBase,s.buttonDanger),disabled:!Object.values(L).some(e=>e?.value),onClick:wt,children:["✕"," ","Clear Filters"]}),r.jsxs(it,{label:r.jsxs(r.Fragment,{children:["⬇"," Export"]}),children:[r.jsx("li",{children:r.jsxs("button",{className:s.menuItemButton,onClick:kt,children:[r.jsx("span",{className:s.successText,children:"CSV"})," Export to CSV"]})}),r.jsx("li",{children:r.jsxs("button",{className:s.menuItemButton,onClick:St,children:[r.jsx("span",{className:s.dangerText,children:"PDF"})," ","Export to PDF"]})})]}),r.jsxs("button",{className:E(s.buttonBase,s.buttonMuted),onClick:()=>Re(!0),children:["☰"," ","Columns"]}),r.jsxs(it,{label:r.jsxs(r.Fragment,{children:["▣"," Theme"]}),children:[r.jsx("li",{children:r.jsx("button",{className:s.menuItemButton,onClick:()=>u("light"),children:"Light"})}),r.jsx("li",{children:r.jsx("button",{className:s.menuItemButton,onClick:()=>u("dark"),children:"Dark"})}),r.jsx("li",{children:r.jsx("button",{className:s.menuItemButton,onClick:()=>u("purple"),children:"Purple"})})]})]})]}),r.jsxs("div",{className:s.relative,children:[r.jsx("div",{className:s.srOnly,"aria-live":"polite",children:ge?"Loading table data":"Table updated"}),Ct&&r.jsx("div",{className:s.overlay,children:r.jsxs("div",{className:s.overlayInner,style:{top:"15%"},children:[r.jsx("div",{className:s.spinner,role:"status"}),r.jsx("div",{className:s.labelMuted,children:ge?"Loading data...":"Updating..."})]})}),r.jsx("div",{className:E(s.tableWrap,N===X&&s.tableWrapAll),ref:Oe,style:N===X?{maxHeight:"70vh",overflowY:"auto"}:{},onScroll:vt,children:r.jsxs("table",{className:s.table,style:{tableLayout:"fixed"},role:"grid","aria-rowcount":D?Pe.length:K.length,"aria-colcount":P.length,children:[r.jsxs("thead",{className:s.tableHead,children:[r.jsx("tr",{ref:He,children:P.map(e=>{const t=C.key===e.key,n=t?C.direction==="asc"?"↑":"↓":"⇅";return r.jsxs("th",{scope:"col","aria-sort":t?C.direction==="asc"?"ascending":"descending":"none",draggable:!0,onDragStart:a=>rt(a,e.key),onDragOver:ot,onDrop:a=>nt(a,e.key),style:{width:he[e.key]},className:s.thCellTop,children:[r.jsx("div",{className:s.thInner,children:r.jsxs("button",{type:"button",className:s.sortButton,"aria-label":`Sort by ${e.label}`,onClick:()=>_t(e.key),children:[e.label,r.jsxs("span",{className:s.iconMuted,children:[" ",n]})]})}),r.jsx("span",{className:s.resizeHandle,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${e.label} column`,tabIndex:0,onPointerDown:a=>jt(a,e.key),onDoubleClick:a=>Nt(a,e.key)})]},e.key)})}),r.jsx("tr",{children:P.map(e=>r.jsx("th",{style:{top:ht},className:s.thCellFilter,children:q(e.key)==="number"?r.jsxs("div",{className:s.inlineGroup,children:[r.jsxs("select",{className:E(s.selectSmall,s.selectAuto),value:L[e.key]?.op||"=",onChange:t=>xe(e.key,{type:"number",op:t.target.value}),children:[r.jsx("option",{value:"=",children:"="}),r.jsx("option",{value:">",children:">"}),r.jsx("option",{value:"<",children:"<"}),r.jsx("option",{value:"!=",children:"!="})]}),r.jsx("input",{type:"number",className:s.input,value:L[e.key]?.value||"",onChange:t=>xe(e.key,{type:"number",value:t.target.value})})]}):q(e.key)==="date"?r.jsxs("div",{className:s.inlineGroup,children:[r.jsxs("select",{className:E(s.selectSmall,s.selectAuto),value:L[e.key]?.op||"=",onChange:t=>xe(e.key,{type:"date",op:t.target.value}),children:[r.jsx("option",{value:"=",children:"="}),r.jsx("option",{value:">",children:">"}),r.jsx("option",{value:"<",children:"<"}),r.jsx("option",{value:"!=",children:"!="})]}),r.jsx("input",{type:"date",className:s.input,value:L[e.key]?.value||"",onChange:t=>xe(e.key,{type:"date",value:t.target.value})})]}):r.jsx("input",{type:"text",className:s.input,placeholder:"Filter...",value:L[e.key]?.value||"",onChange:t=>xe(e.key,{type:"text",value:t.target.value})})},e.key))})]}),r.jsxs("tbody",{children:[B&&de.topSpacer>0&&r.jsx("tr",{"aria-hidden":"true",children:r.jsx("td",{colSpan:P.length,style:{height:`${de.topSpacer}px`,padding:0}})}),(D?Pe:B?de.rows:K).map(e=>{if(D&&e.type==="group"){const n=g.find(h=>h.key===e.groupKey)?.label||e.groupKey,a=!!ae[e.id],c=Ve(e.aggregates).join(" || ");return r.jsx("tr",{className:E(s.groupRow,s.groupRowAnimated),children:r.jsx("td",{colSpan:P.length,children:r.jsxs("button",{type:"button",className:s.groupToggle,onClick:()=>yt(e.id),children:[r.jsxs("span",{style:{paddingLeft:`${e.level*18}px`},children:[a?"▶":"▼"," ",n,": ",e.groupValue," (",e.count,")"]}),c&&r.jsxs("span",{className:s.groupMeta,children:[" ",c]})]})})},e.id)}const t=D?e.row:e;return r.jsx("tr",{className:E(s.rowInteractive,D&&s.groupChildRow),tabIndex:0,children:P.map(n=>{const a=J(t,n.key);return typeof a=="boolean"?r.jsx("td",{"data-label":n.label,style:{width:he[n.key]},children:r.jsx("input",{type:"checkbox",checked:a,disabled:!0,className:s.checkbox})},n.key):q(n.key)==="date"?r.jsx("td",{"data-label":n.label,style:{width:he[n.key]},children:gt(a)},n.key):r.jsx("td",{"data-label":n.label,style:{width:he[n.key]},children:a},n.key)})},D?e.id:t[Se(x)]??t[x])}),B&&de.bottomSpacer>0&&r.jsx("tr",{"aria-hidden":"true",children:r.jsx("td",{colSpan:P.length,style:{height:`${de.bottomSpacer}px`,padding:0}})})]}),H&&Me&&Object.keys(Me).length>0&&r.jsxs("tfoot",{className:s.tfoot,children:[r.jsx("tr",{children:r.jsx("td",{colSpan:P.length,className:s.textCenter,children:"Totals"})}),r.jsx("tr",{children:P.map(e=>r.jsx("td",{"data-label":e.label,style:{width:he[e.key]},children:Me[e.key]!==void 0?ue(Me[e.key]):""},e.key))})]})]})})]}),!D&&N!==X&&Ge>1&&r.jsx("div",{className:s.paginationWrap,children:r.jsxs("ul",{className:s.pagination,children:[r.jsx("li",{children:r.jsx("button",{className:s.pageButton,disabled:Y===1,onClick:()=>I(()=>z(e=>e-1)),children:"Prev"})}),Array.from({length:Ge},(e,t)=>r.jsx("li",{children:r.jsx("button",{className:E(s.pageButton,Y===t+1&&s.pageButtonActive),onClick:()=>I(()=>z(t+1)),children:t+1})},t)),r.jsx("li",{children:r.jsx("button",{className:s.pageButton,disabled:Y===Ge,onClick:()=>I(()=>z(e=>e+1)),children:"Next"})})]})}),!D&&N===X&&r.jsxs("div",{className:s.labelMuted,children:["Showing"," ",(B?de.end:K.length).toLocaleString()," of"," ",M.length.toLocaleString()," rows",B?" (virtualized)":""]}),D&&r.jsxs("div",{className:s.labelMuted,children:["Grouped view: ",M.length.toLocaleString()," rows across"," ",T.length," level",T.length>1?"s":""]}),Ce&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:s.backdrop,onClick:()=>Re(!1)}),r.jsxs("div",{className:s.drawer,children:[r.jsx("h6",{className:s.drawerTitle,children:"Column Settings"}),r.jsx("h6",{className:s.drawerSubtitle,children:"Visible Columns"}),V.map(e=>{const t=g.find(n=>n.key===e);return t?r.jsxs("div",{className:s.drawerRow,draggable:!0,onDragStart:n=>rt(n,t.key),onDragOver:ot,onDrop:n=>nt(n,t.key),children:[r.jsx("input",{type:"checkbox",className:s.checkbox,checked:$.includes(t.key),onChange:()=>I(()=>Q(n=>n.includes(t.key)?n.filter(a=>a!==t.key):[...n,t.key]))}),r.jsx("label",{children:t.label}),r.jsx("span",{className:E(s.spacerAuto,s.iconMuted),children:"⋮"})]},t.key):null}),r.jsxs("div",{className:s.drawerSection,children:[r.jsxs("button",{type:"button",className:s.sectionToggle,"aria-expanded":w.groupBy,onClick:()=>b(e=>({...e,groupBy:!e.groupBy})),children:[r.jsx("span",{children:"Group By Columns"}),r.jsx("span",{className:s.iconMuted,children:w.groupBy?"▲":"▼"})]}),w.groupBy&&r.jsx("div",{className:s.sectionBody,children:V.map(e=>{const t=g.find(n=>n.key===e);return t?r.jsxs("div",{className:s.drawerRow,children:[r.jsx("input",{type:"checkbox",className:s.checkbox,checked:T.includes(t.key),onChange:()=>bt(t.key)}),r.jsx("label",{children:t.label})]},`group-${t.key}`):null})})]}),r.jsxs("div",{className:s.drawerSection,children:[r.jsxs("button",{type:"button",className:s.sectionToggle,"aria-expanded":w.aggregates,onClick:()=>b(e=>({...e,aggregates:!e.aggregates})),children:[r.jsx("span",{children:"Show Total/Aggregate For"}),r.jsx("span",{className:s.iconMuted,children:w.aggregates?"▲":"▼"})]}),w.aggregates&&r.jsxs("div",{className:s.sectionBody,children:[Ae.length===0&&r.jsx("div",{className:s.labelMuted,children:"No numeric columns available."}),V.map(e=>{const t=Ae.find(n=>n.key===e);return t?r.jsxs("div",{className:s.drawerRow,children:[r.jsx("input",{type:"checkbox",className:s.checkbox,checked:G.includes(t.key),onChange:()=>xt(t.key)}),r.jsx("label",{children:t.label})]},`total-${t.key}`):null})]})]})]})]})]})}exports.AwesomeGrid=zr;