@cronocode/react-box 3.1.10 → 3.1.12
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/BOX_AI_CONTEXT.md +85 -215
- package/components/dataGrid/components/dataGridCellRowDetail.d.ts +6 -0
- package/components/dataGrid/components/dataGridDetailRow.d.ts +6 -0
- package/components/dataGrid/components/dataGridEmptyColumns.d.ts +6 -1
- package/components/dataGrid/components/dataGridPagination.d.ts +1 -1
- package/components/dataGrid/contracts/dataGridContract.d.ts +49 -3
- package/components/dataGrid/models/detailRowModel.d.ts +16 -0
- package/components/dataGrid/models/gridModel.d.ts +20 -2
- package/components/dataGrid/models/groupRowModel.d.ts +2 -1
- package/components/dataGrid/models/rowModel.d.ts +3 -1
- package/components/dataGrid.cjs +1 -1
- package/components/dataGrid.mjs +921 -585
- package/components/semantics.d.ts +25 -25
- package/core/boxStyles.d.ts +4 -2
- package/core/extends/boxComponents.d.ts +21 -0
- package/core.cjs +3 -3
- package/core.mjs +444 -412
- package/package.json +1 -1
package/components/dataGrid.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("react/jsx-runtime"),h=require("react"),m=require("../box.cjs"),p=require("./flex.cjs"),ne=require("./grid.cjs"),w=require("../core.cjs"),ee=require("./checkbox.cjs"),_=require("./button.cjs"),le=require("./baseSvg.cjs"),R=require("./dropdown.cjs"),z=require("./textbox.cjs"),B=require("./semantics.cjs"),Se=require("./tooltip.cjs");function Fe(o){const{grid:e}=o,{filtered:t,total:i}=e.filterStats,r=e.hasActiveFilters;return s.jsxs(p.default,{component:"datagrid.bottomBar",children:[s.jsxs(m.default,{children:["Rows: ",t!==i?`${t} / ${i}`:i]}),e.props.def.rowSelection&&s.jsxs(m.default,{children:["Selected: ",e.selectedRows.size]}),r&&s.jsx(m.default,{color:"blue-600",cursor:"pointer",hover:{textDecoration:"underline"},props:{onClick:e.clearAllFilters},children:"Clear filters"})]})}function oe(o){const{cell:e}=o,t=h.useCallback(()=>{e.grid.toggleRowSelection(e.row.key)},[e.grid,e.row.key]);return s.jsx(ee.default,{variant:"datagrid",checked:e.row.selected,onChange:t})}oe.displayName="DataGridCellRowSelection";const Ge="NO_PIN";class M{constructor(e,t,i){if(this.def=e,this.grid=t,this.parent=i,this.columns=e.columns?.map(r=>new M(e.pin?{...r,pin:e.pin}:r,t,this))??[],this.isLeaf){const r=this.grid.columnWidths.get(this.key);this._inlineWidth=this.key==D?void 0:r??this.def.width??this.grid.DEFAULT_COLUMN_WIDTH_PX,this._pin=e.pin}}columns=[];get visibleColumns(){return this.columns.filter(e=>e.isVisible)}get isFirstLeaf(){const{leafs:e}=this;return e.length>0&&e.at(0)===this}get isLastLeaf(){const{leafs:e}=this;return e.length>0&&e.at(-1)===this}get key(){return this.def.key}get header(){return this.def.header}get align(){return this.def.align}get isLeaf(){return this.columns.length===0}get Cell(){return this.def.Cell}get filterable(){return this.def.filterable}get sortable(){return this.def.sortable!==void 0?this.def.sortable:this.grid.props.def.sortable!==!1}get resizable(){return this.def.resizable!==void 0?this.def.resizable:this.grid.props.def.resizable!==!1}get isFlexible(){return this.def.flexible!==!1}get baseWidth(){return this._inlineWidth??this.grid.DEFAULT_COLUMN_WIDTH_PX}_pin;get pin(){if(this.isLeaf)return this._pin;const e=[...new Set(this.columns.flatMap(t=>t.pin))];if(e.length===1)return e[0]}get uniqueKey(){return`${this.key}${this.pin??""}`}getPinnedColumn(e){if(this.hasPin(e)){if(this.isLeaf)return this;const t=new M({...this.def,pin:e},this.grid,this.parent);return t.columns=this.columns.filter(i=>i.hasPin(e)).map(i=>{const r=i.getPinnedColumn(e);return r.parent=t,r}).filter(i=>!!i),t}}hasPin(e){return this.isLeaf?this._pin===e:this.columns.some(t=>t.hasPin(e))}get death(){return this.parent?this.parent.death+1:0}get flatColumns(){const e=[this];return e.push(...this.columns.flatMap(t=>t.flatColumns)),e}_inlineWidth;get inlineWidth(){if(this.isLeaf)return this.grid.getFlexWidth(this.key)??this._inlineWidth;const e=this.visibleColumns.map(t=>t.inlineWidth).filter(t=>typeof t=="number");if(e.length!==0)return e.sumBy(t=>t)}get left(){let e=0;if(this.parent){const{visibleColumns:t,left:i}=this.parent,r=t.findIndex(n=>n===this);e+=t.sumBy((n,a)=>a<r?n.inlineWidth??0:0),e+=i}else{const t=this.grid.columns.value.left.filter(r=>r.isVisible),i=t.findIndex(r=>r===this);e+=t.sumBy((r,n)=>n<i?r.inlineWidth??0:0)}return e}get right(){let e=0;if(this.parent){const{visibleColumns:t}=this.parent,i=t.reverse(),r=i.findIndex(n=>n===this);e+=i.sumBy((n,a)=>a<r?n.inlineWidth??0:0),e+=this.parent.right}else{const i=this.grid.columns.value.right.filter(n=>n.isVisible).reverse(),r=i.findIndex(n=>n===this);e+=i.sumBy((n,a)=>a<r?n.inlineWidth??0:0)}return e}get isEdge(){if(!this.pin)return!1;if(this.parent){const{visibleColumns:t}=this.parent;return(this.pin==="LEFT"?t.at(-1):t.at(0))===this&&this.parent.isEdge}return(this.pin==="LEFT"?this.grid.columns.value.left.filter(t=>t.isVisible).at(-1):this.grid.columns.value.right.filter(t=>t.isVisible).at(0))===this}get isVisible(){return this.isLeaf?!this.grid.hiddenColumns.has(this.key):this.leafs.some(e=>e.isVisible)}get leafs(){return this.isLeaf?[this]:this.visibleColumns.flatMap(e=>e.leafs)}get groupColumnWidthVarName(){return`--${this.uniqueKey}-group-width`}get widthVarName(){return`--${this.uniqueKey}-width`}get leftVarName(){return`--${this.uniqueKey}-left`}get rightVarName(){return`--${this.uniqueKey}-right`}get gridRows(){return this.isLeaf?this.grid.columns.value.maxDeath-this.death:1}resizeColumn=e=>{const t=e.pageX,{MIN_COLUMN_WIDTH_PX:i,update:r}=this.grid,n=this.leafs.toRecord(u=>[u.key,u.inlineWidth??u.baseWidth]),a=this.leafs.sumBy(u=>n[u.key])-this.leafs.length*i,c=w.FnUtils.throttle(u=>{const f=(u.pageX-t)*(this.pin==="RIGHT"?-1:1);this.leafs.forEach(g=>{const y=n[g.key],b=a>0?(y-i)/a*f:f/this.leafs.length,j=Math.round(y+b);g.setWidth(j<i?i:j)}),this.grid.flexWidths.clear(),this.grid.sizes.clear(),r()},40),d=new AbortController,l=u=>{d.abort(),r()};window.addEventListener("mousemove",c,d),window.addEventListener("mouseup",l,d)};pinColumn=e=>{this.isLeaf?this._pin=e:this.columns.forEach(t=>t.pinColumn(e)),this.grid.pinColumn(this.uniqueKey,e)};toggleGrouping=()=>{this.grid.toggleGrouping(this.key)};sortColumn=(...e)=>{this.grid.setSortColumn(this.key,...e)};setWidth=e=>{if(!this.isLeaf)throw new Error("Cannot set width for a parent column.");this._inlineWidth!==e&&(this._inlineWidth=e,this.grid.setWidth(this.key,e))};toggleVisibility=()=>{this.grid.toggleColumnVisibility(this.key)}}class Te{constructor(e,t,i){this.grid=e,this.row=t,this.column=i}get value(){return this.column.key===G?this.row.rowIndex+1:this.row.data[this.column.key]}}class te{constructor(e,t,i){this.grid=e,this.data=t,this.rowIndex=i,this.grid=e,this.data=t,this.key=this.grid.getRowKey(t)}key;parentRow;count=1;get cells(){return this.grid.columns.value.visibleLeafs.map(e=>new Te(this.grid,this,e))}get selected(){return this.grid.selectedRows.has(this.key)}get flatRows(){return this}get allRows(){return this}}const D="empty-cell",G="row-number-cell",ie=70,W="row-selection-cell",L="grouping-cell";class Le{constructor(e,t){this.props=e,this.update=t,console.debug("\x1B[32m%s\x1B[0m","[react-box]: DataGrid GridModel ctor")}sourceColumns=w.memo(()=>{const{def:e}=this.props,t=[];if(this.groupColumns.size>0&&t.push(new M({key:L},this)),t.push(...e.columns.map(i=>new M(i,this))),e.rowSelection){const i=typeof e.rowSelection=="object"&&e.rowSelection.pinned?"LEFT":void 0;t.unshift(new M({key:W,pin:i,width:50,align:"center",Cell:oe},this))}if(e.showRowNumber){let i,r=ie;typeof e.showRowNumber=="object"&&(e.showRowNumber.pinned&&(i="LEFT"),r=e.showRowNumber.width??ie),t.unshift(new M({key:G,pin:i,width:r,align:"right"},this))}return t});columns=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid columns memo");const e=this.sourceColumns.value.map(l=>l.getPinnedColumn("LEFT")).filter(l=>!!l),t=this.sourceColumns.value.map(l=>l.getPinnedColumn()).filter(l=>!!l),i=this.sourceColumns.value.map(l=>l.getPinnedColumn("RIGHT")).filter(l=>!!l),r=[...e,...t,...i].flatMap(l=>l.flatColumns),n=r.filter(l=>l.isLeaf),a=r.filter(l=>l.isLeaf&&l.isVisible),c=a.filter(l=>![D,G,W,L].includes(l.key)),d=r.maxBy(l=>l.death)+1;return{left:e,middle:t,right:i,flat:r,leafs:n,visibleLeafs:a,userVisibleLeafs:c,maxDeath:d}});headerRows=w.memo(()=>(console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid headerRows memo"),this.columns.value.flat.groupBy(t=>t.death).sortBy(t=>t.key).map(t=>{const i=t.values.groupBy(r=>r.pin??Ge).toRecord(r=>[r.key,r.values]);return[...i.LEFT?.filter(r=>r.isVisible)??[],...i.NO_PIN?.filter(r=>r.isVisible)??[],...i.RIGHT?.filter(r=>r.isVisible)??[]]})));gridTemplateColumns=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid gridTemplateColumns memo");const{visibleLeafs:e}=this.columns.value,t=e.sumBy(a=>a.pin==="RIGHT"?1:0),i=e.length-t,r=i>0?`repeat(${i}, max-content)`:"",n=t>0?`repeat(${t}, max-content)`:"";return`${r} ${n}`.trim()});_globalFilterValue="";get globalFilterValue(){return this.props.globalFilterValue??this._globalFilterValue}_columnFilters={};get columnFilters(){return this.props.columnFilters??this._columnFilters}applyGlobalFilter(e){const t=this.globalFilterValue.trim();if(!t)return e;const{globalFilterKeys:i}=this.props.def,r=i??this.columns.value.leafs.filter(n=>n.key!==D&&n.key!==G&&n.key!==W&&n.key!==L).map(n=>n.key);return e.filter(n=>r.some(a=>{const c=n[a];return c==null?!1:w.fuzzySearch(t,String(c))}))}applyColumnFilters(e){const t=this.columnFilters,i=Object.keys(t);return i.length===0?e:e.filter(r=>i.every(n=>{const a=t[n];if(!a)return!0;const c=r[n];return this.matchesFilter(c,a)}))}matchesFilter(e,t){switch(t.type){case"text":return t.value.trim()?e==null?!1:w.fuzzySearch(t.value,String(e)):!0;case"number":{if(e==null)return!1;const i=typeof e=="number"?e:parseFloat(String(e));if(isNaN(i))return!1;switch(t.operator){case"eq":return i===t.value;case"ne":return i!==t.value;case"gt":return i>t.value;case"gte":return i>=t.value;case"lt":return i<t.value;case"lte":return i<=t.value;case"between":return t.valueTo!==void 0?i>=t.value&&i<=t.valueTo:i>=t.value;default:return!0}}case"multiselect":return t.values.length===0?!0:t.values.includes(e);default:return!0}}applyExternalFilters(e){const t=this.props.filters;return!t||t.length===0?e:e.filter(i=>t.every(r=>r(i)))}get filteredData(){let e=this.props.data;return e=this.applyExternalFilters(e),this.props.def.globalFilter&&(e=this.applyGlobalFilter(e)),e=this.applyColumnFilters(e),e}setGlobalFilter=e=>{this.props.onGlobalFilterChange?this.props.onGlobalFilterChange(e):this._globalFilterValue=e,this.rows.clear(),this.flatRows.clear(),this.update()};setColumnFilter=(e,t)=>{const i={...this.columnFilters};t===void 0?delete i[e]:i[e]=t,this.props.onColumnFiltersChange?this.props.onColumnFiltersChange(i):this._columnFilters=i,this.rows.clear(),this.flatRows.clear(),this.update()};clearColumnFilters=()=>{this.props.onColumnFiltersChange?this.props.onColumnFiltersChange({}):this._columnFilters={},this.rows.clear(),this.flatRows.clear(),this.update()};clearAllFilters=()=>{this.setGlobalFilter(""),this.clearColumnFilters()};getColumnUniqueValues=e=>{const t=new Set;return this.props.data.forEach(i=>{const r=i[e];r!==void 0&&t.add(r)}),Array.from(t).sort((i,r)=>i===null?1:r===null?-1:typeof i=="string"&&typeof r=="string"?i.localeCompare(r):typeof i=="number"&&typeof r=="number"?i-r:String(i).localeCompare(String(r)))};get hasActiveFilters(){return this.globalFilterValue.trim()!==""||Object.keys(this.columnFilters).length>0}get filterStats(){return{filtered:this.filteredData.length,total:this.props.data.length}}rows=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid rows memo");let e=this.filteredData;if(this._sortColumn&&(e=e.sortBy(t=>t[this._sortColumn],this._sortDirection)),this.groupColumns.size>0){const t=(i,r,n)=>{const a=r.values().next().value;r.delete(a);const c=this.columns.value.leafs.findOrThrow(d=>d.key===a);return this._sortColumn===L&&(i=i.sortBy(d=>d[a],this._sortDirection)),i.groupBy(d=>d[a]).map(d=>{let l;r.size>0?l=t(d.values,new Set(r),n+1):l=d.values.map((f,g)=>new te(this,f,n+1+g));const u=new ae(this,c,l,n,d.key);return n+=1,u.expanded&&(n+=l.length),u})};return t(e,new Set(this.groupColumns),0)}return e.map((t,i)=>new te(this,t,i))});flatRows=w.memo(()=>(console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid flatRows memo"),this.rows.value.flatMap(e=>e.flatRows)));get rowHeight(){return this.props.def.rowHeight??this.DEFAULT_ROW_HEIGHT_PX}sizes=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid sizes memo");const e=this.columns.value.flat.reduce((r,n)=>{const{inlineWidth:a}=n;return typeof a=="number"&&(r[n.widthVarName]=`${n.inlineWidth}px`),n.pin==="LEFT"&&(r[n.leftVarName]=`${n.left}px`),n.pin==="RIGHT"&&(r[n.rightVarName]=`${n.right}px`),r},{});e[this.rowHeightVarName]=`${this.rowHeight}px`,e[this.leftEdgeVarName]=`${this.leftEdge}px`;const{visibleLeafs:t}=this.columns.value,i=t.find(r=>r.key===L);if(i){const r=t.sumBy(n=>n.pin===i.pin&&n.key!==G&&n.key!==W?n.inlineWidth??0:0);e[i.groupColumnWidthVarName]=`${r}px`}return this.groupColumns.forEach(r=>{const n=this.columns.value.leafs.findOrThrow(a=>a.key===r);e[n.groupColumnWidthVarName]=`${t.sumBy(a=>a.pin===n.pin?a.inlineWidth??0:0)}px`}),e});_containerWidth=0;get containerWidth(){return this._containerWidth}setContainerWidth=e=>{this._containerWidth!==e&&(this._containerWidth=e,this.flexWidths.clear(),this.sizes.clear(),this.update())};flexWidths=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid flexWidths memo");const e=this._containerWidth;if(e<=0)return{};const t=this.columns.value.visibleLeafs.filter(u=>u.key!==D),i=u=>!u.isFlexible||this.columnWidths.has(u.key),r=t.filter(i).sumBy(u=>u.baseWidth),n=t.filter(u=>!i(u)),a=n.sumBy(u=>u.baseWidth),c=e-r;if(c<=a)return n.toRecord(u=>[u.key,u.baseWidth]);const d={};let l=0;return n.forEach((u,f)=>{if(f===n.length-1)d[u.key]=c-l;else{const g=Math.floor(u.baseWidth/a*c);d[u.key]=g,l+=g}}),d});getFlexWidth(e){return this.flexWidths.value[e]}DEFAULT_ROW_HEIGHT_PX=48;MIN_COLUMN_WIDTH_PX=48;DEFAULT_COLUMN_WIDTH_PX=200;expandedGroupRow=new Set;selectedRows=new Set;get leftEdge(){return this.columns.value.left.sumBy(e=>e.inlineWidth??0)}get rightEdge(){return this.columns.value.right.sumBy(e=>e.inlineWidth??0)}leftEdgeVarName="--left-edge";rowHeightVarName="--row-height";_idMap=new WeakMap;getRowKey(e){const{rowKey:t}=this.props.def;return t?typeof t=="function"?t(e):e[t]:(this._idMap.has(e)||this._idMap.set(e,crypto.randomUUID()),this._idMap.get(e))}setSortColumn=(e,...t)=>{if(t.length>0)[this._sortDirection]=t,this._sortColumn=this._sortDirection?e:void 0;else{const{_sortColumn:i,_sortDirection:r}=this;this._sortColumn=i===e&&r==="DESC"?void 0:e,this._sortDirection=i===e&&r==="ASC"?"DESC":"ASC"}this.headerRows.clear(),this.rows.clear(),this.flatRows.clear(),this.update()};pinColumn=(e,t)=>{const i=this.columns.value.flat.findOrThrow(r=>r.uniqueKey===e);i.pin!==t&&i.pinColumn(t),this.columns.clear(),this.headerRows.clear(),this.gridTemplateColumns.clear(),this.rows.clear(),this.flatRows.clear(),this.flexWidths.clear(),this.sizes.clear(),this.update()};toggleGrouping=e=>{this.groupColumns=new Set(this.groupColumns),this.hiddenColumns=new Set(this.hiddenColumns),this.groupColumns.has(e)?(this.groupColumns.delete(e),this.hiddenColumns.delete(e)):(this.groupColumns.add(e),this.hiddenColumns.add(e)),this.sourceColumns.clear(),this.columns.clear(),this.headerRows.clear(),this.gridTemplateColumns.clear(),this.rows.clear(),this.flatRows.clear(),this.flexWidths.clear(),this.sizes.clear(),this.update()};unGroupAll=()=>{const e=new Set(this.groupColumns);this.groupColumns=new Set,this.hiddenColumns=new Set(Array.from(this.hiddenColumns).filter(t=>!e.has(t))),this.sourceColumns.clear(),this.columns.clear(),this.headerRows.clear(),this.gridTemplateColumns.clear(),this.rows.clear(),this.flatRows.clear(),this.flexWidths.clear(),this.sizes.clear(),this.update()};toggleGroupRow=e=>{this.expandedGroupRow=new Set(this.expandedGroupRow),this.expandedGroupRow.has(e)?this.expandedGroupRow.delete(e):this.expandedGroupRow.add(e),this.rows.clear(),this.flatRows.clear(),this.update()};toggleRowSelection=e=>{this.toggleRowsSelection([e])};toggleRowsSelection=e=>{this.selectedRows=new Set(this.selectedRows);const t=e.every(i=>this.selectedRows.has(i));t?e.forEach(i=>this.selectedRows.delete(i)):e.forEach(i=>this.selectedRows.add(i)),this.flatRows.clear(),this.update(),this.props.onSelectionChange?.({action:t?"deselect":"select",affectedRowKeys:e,selectedRowKeys:Array.from(this.selectedRows),isAllSelected:this.selectedRows.size===this.props.data.length})};toggleSelectAllRows=()=>{this.toggleRowsSelection(this.props.data.map(e=>this.getRowKey(e)))};toggleColumnVisibility=e=>{this.hiddenColumns=new Set(this.hiddenColumns),this.hiddenColumns.has(e)?this.hiddenColumns.delete(e):this.hiddenColumns.add(e),this.columns.clear(),this.headerRows.clear(),this.gridTemplateColumns.clear(),this.rows.clear(),this.flatRows.clear(),this.flexWidths.clear(),this.sizes.clear(),this.update()};setWidth=(e,t)=>{this.columnWidths.set(e,t)};groupColumns=new Set;hiddenColumns=new Set;columnWidths=new Map;_sortColumn;get sortColumn(){return this._sortColumn}_sortDirection="ASC";get sortDirection(){return this._sortDirection}}class _e{constructor(e,t,i){this.grid=e,this.row=t,this.column=i}get value(){return this.column.key===G?this.row.rowIndex+1:this.column.key===L?`${this.row.groupValue} (${this.row.count})`:null}}class ae{constructor(e,t,i,r,n){this.grid=e,this.groupColumn=t,this.rows=i,this.rowIndex=r,this.groupValue=n,i.forEach(a=>a.parentRow=this)}get key(){return`${this.parentRow?.key??""}${this.groupColumn.key}${this.groupValue}`}parentRow;get cells(){return this.grid.columns.value.visibleLeafs.map(e=>new _e(this.grid,this,e))}get selected(){return this.allRows.every(e=>e.selected)}get indeterminate(){return!this.selected&&this.allRows.some(e=>e.selected)}get expanded(){return this.grid.expandedGroupRow.has(this.key)}get depth(){return this.parentRow?this.parentRow.depth+1:0}get count(){return this.rows.sumBy(e=>e.count,0)}get flatRows(){return this.expanded?[this,...this.rows.flatMap(e=>e.flatRows)]:[this]}get allRows(){return this.rows.flatMap(e=>e.allRows)}get groupingColumn(){return this.grid.columns.value.leafs.findOrThrow(e=>e.key===L)}get groupingColumnGridColumn(){const{visibleLeafs:e}=this.grid.columns.value,{groupingColumn:t}=this;return e.sumBy(r=>r.pin===t.pin&&r.key!==D&&r.key!==W&&r.key!==G?1:0)}toggleRow(){this.grid.toggleGroupRow(this.key)}}function A(o){const{children:e,column:t,style:i,...r}=o,{key:n,pin:a,left:c,right:d,isEdge:l,align:u,widthVarName:f,leftVarName:g,rightVarName:y,isFirstLeaf:b,isLastLeaf:j}=t;"align"in t.def&&(r.jc=u);const E=n===G,T=n===W,k=n===D,S=a==="LEFT",x=a==="RIGHT",C=S||x,v=S&&c===0,F=S&&l,V=x&&l,N=x&&d===0;return s.jsx(p.default,{component:"datagrid.body.cell",props:{role:"cell"},variant:{isPinned:C,isFirstLeftPinned:v,isLastLeftPinned:F,isFirstRightPinned:V,isLastRightPinned:N,isRowSelection:T,isRowNumber:E,isFirstLeaf:b,isLastLeaf:j,isEmptyCell:k},style:{width:`var(${f})`,height:`var(${t.grid.rowHeightVarName})`,left:S?`var(${g})`:void 0,right:x?`var(${y})`:void 0,...i},...r,children:e})}A.displayName="DataGridCell";function ue(o){const{row:e}=o,{selected:t,indeterminate:i,cells:r,groupingColumn:n,groupingColumnGridColumn:a,depth:c,expanded:d}=e,l=h.useCallback(()=>{e.grid.toggleRowsSelection(e.allRows.map(u=>u.key))},[]);return s.jsx(p.default,{className:"grid-row",selected:t,display:"contents",props:{role:"rowgroup"},children:r.map(u=>{const{key:f,pin:g,groupColumnWidthVarName:y}=u.column,b=g==="RIGHT";if(f===L)return s.jsx(A,{column:u.column,style:{width:`var(${y})`,right:b?"0":void 0},br:n.pin==="LEFT"?1:void 0,gridColumn:a,pl:4*c,overflow:"auto",children:s.jsx(m.default,{textWrap:"nowrap",px:3,children:s.jsxs(_.default,{clean:!0,onClick:()=>e.toggleRow(),cursor:"pointer",display:"flex",gap:1,ai:"center",children:[s.jsx(w.ExpandIcon,{fill:"currentColor",width:"14px",height:"14px",rotate:d?0:-90}),u.value]})})},f);if(f===W)return s.jsx(A,{column:u.column,children:s.jsx(ee.default,{variant:"datagrid",m:1,checked:t,indeterminate:i,onChange:l})},f);if(g!==n.pin||f===G||f===D)return s.jsx(A,{column:u.column,px:f===G?3:void 0,children:u.value},f)})})}ue.displayName="DataGridGroupRow";function ce(o){const{cell:e}=o;return s.jsx(p.default,{height:"fit",width:"fit",overflow:"auto",ai:"center",jc:e.column.align,children:s.jsx(m.default,{px:3,textOverflow:"ellipsis",overflow:"hidden",textWrap:"nowrap",children:e.value})})}ce.displayName="DataGridCellText";function de(o){const{row:e}=o,{selected:t}=e;return s.jsx(p.default,{className:"grid-row",selected:t,display:"contents",props:{role:"row"},children:e.cells.map(i=>s.jsx(A,{column:i.column,children:i.column.Cell?s.jsx(i.column.Cell,{cell:i}):s.jsx(ce,{cell:i})},i.column.key))})}de.displayName="DataGridRow";const We=10,se=20;function he(o){const{grid:e,scrollTop:t}=o,i=e.flatRows.value.length,r=Math.max(0,Math.floor(t/e.rowHeight)-se),n=e.props.def.visibleRowsCount??We,a=e.rowHeight*n+e.rowHeight/5,c=e.props.data.length===0,d=h.useMemo(()=>{if(console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid render rows"),c)return null;const l=n+se*2;return e.flatRows.value.take(l,r).map(f=>f instanceof ae?s.jsx(ue,{row:f},f.key):s.jsx(de,{row:f},f.key))},[e.flatRows.value,c,r,n]);if(console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid render DataGridBody"),c){const{noDataComponent:l}=e.props.def,u=e.props.loading?"loading...":"empty";return s.jsx(p.default,{jc:"center",ai:"center",width:"fit",position:"sticky",left:0,style:{height:a},children:l??u})}return s.jsx(m.default,{style:{height:a},children:s.jsx(m.default,{style:{height:`${i*e.rowHeight}px`},children:s.jsx(ne.default,{component:"datagrid.body",width:"max-content",minWidth:"fit",transition:"none",style:{transform:`translate3d(0, ${r*e.rowHeight}px, 0)`,willChange:"transform",gridTemplateColumns:e.gridTemplateColumns.value},children:d})})})}he.displayName="DataGridBody";function De(){return s.jsx(p.default,{d:"column",ai:"center",jc:"center",gap:4,py:16,px:6,bgColor:"gray-50",borderRadius:4,theme:{dark:{bgColor:"gray-900"}},children:s.jsxs(p.default,{d:"column",ai:"center",gap:3,children:[s.jsx(m.default,{width:16,height:16,borderRadius:999,bgColor:"gray-200",theme:{dark:{bgColor:"gray-700"}},display:"flex",ai:"center",jc:"center",children:s.jsx(le.default,{viewBox:"0 0 24 24",width:"40",fill:"currentColor",color:"gray-400",theme:{dark:{color:"gray-500"}},children:s.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M3 6a3 3 0 013-3h12a3 3 0 013 3v12a3 3 0 01-3 3H6a3 3 0 01-3-3V6zm3-1a1 1 0 00-1 1v12a1 1 0 001 1h12a1 1 0 001-1V6a1 1 0 00-1-1H6zm2 3a1 1 0 011-1h6a1 1 0 110 2H9a1 1 0 01-1-1zm0 4a1 1 0 011-1h6a1 1 0 110 2H9a1 1 0 01-1-1zm0 4a1 1 0 011-1h4a1 1 0 110 2H9a1 1 0 01-1-1z"})})}),s.jsxs(p.default,{d:"column",ai:"center",gap:1,children:[s.jsx(m.default,{fontSize:18,fontWeight:600,color:"gray-900",theme:{dark:{color:"gray-50"}},children:"No Columns Selected"}),s.jsx(m.default,{fontSize:14,color:"gray-500",textAlign:"center",theme:{dark:{color:"gray-400"}},children:"Select at least one column from the columns menu to display data"})]})]})})}function re({column:o,grid:e}){const t=e.columnFilters[o.key],i=t?.type==="text"?t.value:"",[r,n]=h.useState(i),a=h.useRef(null);h.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]);const c=h.useCallback(u=>{const f=u.target.value;n(f),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{f.trim()?e.setColumnFilter(o.key,{type:"text",value:f}):e.setColumnFilter(o.key,void 0),a.current=null},300)},[e,o.key]),d=h.useCallback(()=>{n(""),e.setColumnFilter(o.key,void 0)},[e,o.key]),l=typeof o.def.filterable=="object"?o.def.filterable:{};return s.jsxs(p.default,{ai:"center",position:"relative",width:"fit",children:[s.jsx(z.default,{width:"fit",variant:"compact",placeholder:l.placeholder??"Filter...",value:r,onChange:c}),r&&s.jsx(p.default,{position:"absolute",right:2,top:"1/2",translateY:"-1/2",cursor:"pointer",props:{onClick:d},children:s.jsx(m.default,{fontSize:10,color:"gray-400",hover:{color:"gray-600"},children:"✕"})})]})}function Ee({column:o,grid:e}){const t=e.columnFilters[o.key],i=t?.type==="number"?t.value:"",r=t?.type==="number"?t.operator:"eq",n=t?.type==="number"?t.valueTo:"",[a,c]=h.useState(i),[d,l]=h.useState(r),[u,f]=h.useState(n??""),g=h.useRef(null),y=h.useRef(null);h.useEffect(()=>()=>{g.current&&clearTimeout(g.current),y.current&&clearTimeout(y.current)},[]);const b=typeof o.def.filterable=="object"?o.def.filterable:{},j=h.useCallback((x,C,v)=>{const F=typeof C=="number"?C:parseFloat(C);if(isNaN(F)||C===""){e.setColumnFilter(o.key,void 0);return}const V={type:"number",operator:x,value:F};if(x==="between"&&v!==void 0&&v!==""){const N=typeof v=="number"?v:parseFloat(String(v));isNaN(N)||(V.valueTo=N)}e.setColumnFilter(o.key,V)},[e,o.key]),E=h.useCallback(x=>{const C=x.target.value;c(C),g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{j(d,C,u),g.current=null},300)},[d,u,j]),T=h.useCallback(x=>{l(x),j(x,a,u)},[a,u,j]),k=h.useCallback(x=>{const C=x.target.value;f(C),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{j(d,a,C),y.current=null},300)},[d,a,j]),S=h.useCallback(()=>{c(""),f(""),l("eq"),e.setColumnFilter(o.key,void 0)},[e,o.key]);return s.jsxs(p.default,{ai:d==="between"?"start":"center",gap:1,width:"fit",children:[s.jsxs(R.default,{value:d,variant:"compact",onChange:x=>x&&T(x),minWidth:6,hideIcon:!0,children:[s.jsx(R.default.Item,{value:"eq",children:"="}),s.jsx(R.default.Item,{value:"ne",children:"≠"}),s.jsx(R.default.Item,{value:"gt",children:">"}),s.jsx(R.default.Item,{value:"gte",children:"≥"}),s.jsx(R.default.Item,{value:"lt",children:"<"}),s.jsx(R.default.Item,{value:"lte",children:"≤"}),s.jsx(R.default.Item,{value:"between",children:"↔"})]}),d==="between"?s.jsxs(p.default,{d:"column",gap:1,flex1:!0,children:[s.jsxs(p.default,{ai:"center",position:"relative",flex1:!0,children:[s.jsx(z.default,{type:"number",variant:"compact",placeholder:b.placeholder??"From",value:a,onChange:E,width:"fit",step:b.step}),(a!==""||u!=="")&&s.jsx(p.default,{position:"absolute",right:2,top:"1/2",translateY:"-1/2",cursor:"pointer",props:{onClick:S},children:s.jsx(m.default,{fontSize:10,color:"gray-400",hover:{color:"gray-600"},children:"✕"})})]}),s.jsx(p.default,{ai:"center",flex1:!0,children:s.jsx(z.default,{type:"number",variant:"compact",placeholder:"To",value:u,onChange:k,width:"fit",step:b.step})})]}):s.jsxs(p.default,{ai:"center",position:"relative",flex1:!0,children:[s.jsx(z.default,{type:"number",variant:"compact",placeholder:b.placeholder??"Value",value:a,onChange:E,width:"fit",step:b.step}),a!==""&&s.jsx(p.default,{position:"absolute",right:2,top:"1/2",translateY:"-1/2",cursor:"pointer",props:{onClick:S},children:s.jsx(m.default,{fontSize:10,color:"gray-400",hover:{color:"gray-600"},children:"✕"})})]})]})}function Ve({column:o,grid:e}){const t=e.columnFilters[o.key],i=t?.type==="multiselect"?t.values:[],r=typeof o.def.filterable=="object"?o.def.filterable:{},n=h.useMemo(()=>r.options?r.options:e.getColumnUniqueValues(o.key).map(d=>({label:d===null?"(empty)":String(d),value:d})),[r.options,e,o.key]),a=h.useCallback((c,d)=>{d.length===0?e.setColumnFilter(o.key,void 0):e.setColumnFilter(o.key,{type:"multiselect",values:d})},[e,o.key]);return s.jsxs(R.default,{multiple:!0,showCheckbox:!0,isSearchable:!0,searchPlaceholder:"Search...",value:i,width:"fit",minWidth:0,onChange:a,variant:"compact",children:[s.jsx(R.default.Unselect,{children:"Clear"}),s.jsx(R.default.SelectAll,{children:"Select All"}),n.map(c=>s.jsx(R.default.Item,{value:c.value,ai:"center",gap:2,children:c.label},String(c.value)))]})}function fe(o){const{column:e,grid:t}=o,{filterable:i}=e.def;if(!i)return null;switch((typeof i=="object"?i:{type:"text"}).type){case"text":return s.jsx(re,{column:e,grid:t});case"number":return s.jsx(Ee,{column:e,grid:t});case"multiselect":return s.jsx(Ve,{column:e,grid:t});default:return s.jsx(re,{column:e,grid:t})}}fe.displayName="DataGridColumnFilter";function pe(o){const{column:e,grid:t}=o,{key:i,pin:r,left:n,right:a,isEdge:c,widthVarName:d,leftVarName:l,rightVarName:u,filterable:f}=e,g=i===D,E=g||i===L||i===G||i===W,T=r==="LEFT",k=r==="RIGHT",S=T||k,x=T&&n===0,C=T&&c,v=k&&c,F=k&&a===0;return s.jsx(p.default,{component:"datagrid.filter.cell",variant:{isPinned:S,isFirstLeftPinned:x,isLastLeftPinned:C,isFirstRightPinned:v,isLastRightPinned:F},px:g?0:2,style:{width:`var(${d})`,left:T?`var(${l})`:void 0,right:k?`var(${u})`:void 0},children:!E&&f&&s.jsx(fe,{column:e,grid:t})})}pe.displayName="DataGridFilterCell";function me(o){const{grid:e}=o,{visibleLeafs:t}=e.columns.value;return t.some(r=>r.filterable)?t.map(r=>s.jsx(pe,{column:r,grid:e},r.uniqueKey)):null}me.displayName="DataGridFilterRow";function ge(o){const{column:e}=o,{key:t,pin:i,left:r,right:n,isEdge:a,isLeaf:c,align:d,header:l,grid:u}=e,[f,g,y]=w.useVisibility({hideOnScroll:!0,event:"mousedown"}),[b,j]=h.useState({top:0,left:0}),E=h.useMemo(()=>b.left>window.innerWidth/2,[b.left]),T=c&&e.sortable&&(u.sortColumn!==t||u.sortDirection==="DESC"),k=c&&e.sortable&&(u.sortColumn!==t||u.sortDirection==="ASC"),S=c&&e.sortable&&u.sortColumn===t,x=i!=="LEFT",C=i!=="RIGHT",v=!!i,F=c&&t!==L,V=c&&t===L,N=T||k||S,O=x||C||v,Y=d==="right"?2:void 0,K=d==="right"?void 0:i==="RIGHT"?2.5:4,$=t===D,q=t===G,J=t===W,P=i==="LEFT",U=i==="RIGHT",Q=P||i==="RIGHT",X=P&&r===0,Z=P&&a,I=U&&a,H=U&&n===0,ke=c&&!$&&!q&&!J&&e.sortable;return s.jsx(p.default,{position:"absolute",left:Y,right:K,top:"1/2",translateY:-3,ai:"center",children:s.jsxs(_.default,{component:"datagrid.header.cell.contextMenu",onClick:()=>g(!f),variant:{isPinned:Q,isFirstLeftPinned:X,isLastLeftPinned:Z,isFirstRightPinned:I,isLastRightPinned:H,isSortable:ke,isRowNumber:q},children:[s.jsx(B.Span,{component:"datagrid.header.cell.contextMenu.icon",children:s.jsx(w.DotsIcon,{fill:"currentColor"})}),f&&s.jsxs(Se.default,{component:"datagrid.header.cell.contextMenu.tooltip",onPositionChange:j,ref:y,adjustTranslateX:E?"-100%":"-21px",adjustTranslateY:"16px",children:[T&&s.jsxs(_.default,{component:"datagrid.header.cell.contextMenu.tooltip.item",onClick:()=>e.sortColumn("ASC"),children:[s.jsx(B.Span,{component:"datagrid.header.cell.contextMenu.tooltip.item.icon",children:s.jsx(w.SortIcon,{width:"100%",fill:"currentColor"})}),"Sort Ascending"]}),k&&s.jsxs(_.default,{component:"datagrid.header.cell.contextMenu.tooltip.item",onClick:()=>e.sortColumn("DESC"),children:[s.jsx(B.Span,{component:"datagrid.header.cell.contextMenu.tooltip.item.icon",children:s.jsx(w.SortIcon,{width:"100%",fill:"currentColor",rotate:180})}),"Sort Descending"]}),S&&s.jsxs(_.default,{component:"datagrid.header.cell.contextMenu.tooltip.item",onClick:()=>e.sortColumn(void 0),children:[s.jsx(m.default,{width:4}),"Clear Sort"]}),N&&(O||F||V)&&s.jsx(m.default,{bb:1,my:2,borderColor:"gray-300",component:"datagrid.header.cell.contextMenu.tooltip.item.separator"}),x&&s.jsxs(_.default,{component:"datagrid.header.cell.contextMenu.tooltip.item",onClick:()=>e.pinColumn("LEFT"),children:[s.jsx(B.Span,{component:"datagrid.header.cell.contextMenu.tooltip.item.icon",children:s.jsx(w.PinIcon,{width:"100%",fill:"currentColor"})}),"Pin Left"]}),C&&s.jsxs(_.default,{component:"datagrid.header.cell.contextMenu.tooltip.item",onClick:()=>e.pinColumn("RIGHT"),children:[s.jsx(B.Span,{component:"datagrid.header.cell.contextMenu.tooltip.item.icon",children:s.jsx(w.PinIcon,{width:"100%",fill:"currentColor",rotate:-90})}),"Pin Right"]}),v&&s.jsxs(_.default,{component:"datagrid.header.cell.contextMenu.tooltip.item",onClick:()=>e.pinColumn(),children:[s.jsx(m.default,{width:4}),"Unpin"]}),N&&O&&(F||V)&&s.jsx(m.default,{component:"datagrid.header.cell.contextMenu.tooltip.item.separator"}),F&&s.jsxs(_.default,{component:"datagrid.header.cell.contextMenu.tooltip.item",onClick:e.toggleGrouping,children:[s.jsx(B.Span,{component:"datagrid.header.cell.contextMenu.tooltip.item.icon",children:s.jsx(w.GroupingIcon,{width:"100%",fill:"currentColor"})}),s.jsxs(m.default,{textWrap:"nowrap",children:["Group by ",l??t]})]}),V&&s.jsxs(_.default,{component:"datagrid.header.cell.contextMenu.tooltip.item",onClick:u.unGroupAll,children:[s.jsx(B.Span,{component:"datagrid.header.cell.contextMenu.tooltip.item.icon",children:s.jsx(w.GroupingIcon,{width:"100%",fill:"currentColor"})}),s.jsx(m.default,{textWrap:"nowrap",children:"Un-Group All"})]})]})]})})}ge.displayName="DataGridHeaderCellContextMenu";function xe(o){const{column:e}=o;return s.jsx(p.default,{height:"fit",ai:"center",position:"absolute",right:e.pin==="RIGHT"?void 0:0,left:e.pin!=="RIGHT"?void 0:0,py:3,children:s.jsx(m.default,{cursor:"col-resize",px:.75,mt:-6,className:"resizer",height:"fit",props:{onMouseDown:e.resizeColumn,onTouchStart:e.resizeColumn},children:s.jsx(m.default,{component:"datagrid.header.cell.resizer"})})})}xe.displayName="DataGridHeaderCellResizer";function Ce(o){const{column:e}=o,{key:t,pin:i,left:r,right:n,isEdge:a,isLeaf:c,leafs:d,grid:l,header:u,gridRows:f,widthVarName:g,leftVarName:y,rightVarName:b,inlineWidth:j,isFirstLeaf:E,isLastLeaf:T}=e,k=t===D,S=t===L,x=t===G,C=t===W,v=i==="LEFT",F=i==="RIGHT",V=v||i==="RIGHT",N=v&&r===0,O=v&&a,Y=F&&a,K=F&&n===0,$=c&&!k&&!x&&!C&&e.sortable,q=c?1:d.length,J=!x&&!C&&e.resizable,P=!x&&!C,U=C?void 0:e.align==="right"?10:3,Q=C?void 0:e.align==="center"?3:void 0,X=h.useCallback(()=>{l.toggleSelectAllRows()},[]),Z=h.useMemo(()=>{if(x)return null;if(C){const I=l.selectedRows.size===l.props.data.length,H=!I&&l.selectedRows.size>0;return s.jsx(ee.default,{variant:"datagrid",m:1,indeterminate:H,checked:I,onChange:X})}if(S){if(l.groupColumns.size===1){const I=l.columns.value.leafs.findOrThrow(H=>H.key===l.groupColumns.values().next().value);return I.header??I.key}return"Group"}return u??t},[l.groupColumns,l.selectedRows,X]);return s.jsx(p.default,{props:{role:"columnheader"},component:"datagrid.header.cell",variant:{isPinned:V,isFirstLeftPinned:N,isLastLeftPinned:O,isFirstRightPinned:Y,isLastRightPinned:K,isSortable:$,isRowNumber:x,isFirstLeaf:E,isLastLeaf:T,isEmptyCell:k},gridRow:f,gridColumn:q,style:{width:`var(${g})`,left:v?`var(${y})`:void 0,right:F?`var(${b})`:void 0},children:!k&&s.jsxs(s.Fragment,{children:[s.jsx(p.default,{width:"fit",height:"fit",jc:e.align,props:{onClick:$?()=>e.sortColumn():void 0},children:s.jsxs(p.default,{overflow:"hidden",position:c?void 0:"sticky",ai:"center",transition:"none",pl:U,pr:Q,style:{left:i?void 0:`var(${l.leftEdgeVarName})`},children:[s.jsx(m.default,{overflow:"hidden",textOverflow:"ellipsis",textWrap:"nowrap",children:Z}),t===l.sortColumn&&s.jsx(m.default,{pl:(j??0)<58?0:2,children:s.jsx(w.SortIcon,{width:"16px",rotate:l.sortDirection==="ASC"?0:180,fill:"currentColor"})}),P&&s.jsx(m.default,{minWidth:e.align==="right"?4:10})]})}),J&&s.jsx(xe,{column:e}),P&&s.jsx(ge,{column:e})]})})}Ce.displayName="DataGridHeaderCell";function we(o){const{grid:e}=o;return s.jsxs(ne.default,{component:"datagrid.header",style:{gridTemplateColumns:e.gridTemplateColumns.value},children:[e.headerRows.value.map(t=>t.map(i=>s.jsx(Ce,{column:i},i.uniqueKey))),s.jsx(me,{grid:e})]})}we.displayName="DataGridHeader";function ye(o){const{grid:e}=o,[t,i]=h.useState(0),r=h.useRef(null),n=h.useCallback(c=>{r.current!==null&&cancelAnimationFrame(r.current),r.current=requestAnimationFrame(()=>{i(c.target.scrollTop),r.current=null})},[]);return e.columns.value.userVisibleLeafs.length>0?s.jsxs(m.default,{overflowX:"scroll",style:{willChange:"scroll-position"},props:{onScroll:n},children:[s.jsx(we,{grid:e}),s.jsx(he,{grid:e,scrollTop:t})]}):s.jsx(De,{})}ye.displayName="DataGridContent";function be(o){const{grid:e}=o;return e.groupColumns.size===0?null:s.jsxs(p.default,{component:"datagrid.topBar.columnGroups",children:[s.jsx(B.Span,{component:"datagrid.topBar.columnGroups.icon",children:s.jsx(w.GroupingIcon,{width:"100%",fill:"currentColor"})}),Array.from(e.groupColumns,t=>{const i=e.columns.value.leafs.findOrThrow(r=>r.key===t);return s.jsxs(h.Fragment,{children:[s.jsx(w.ExpandIcon,{fill:"currentColor",width:"14px",height:"14px",rotate:-90}),s.jsxs(p.default,{component:"datagrid.topBar.columnGroups.item",children:[i.header??i.key,s.jsx(_.default,{component:"datagrid.topBar.columnGroups.item.icon",onClick:()=>e.toggleGrouping(i.key),children:s.jsx(m.default,{fontSize:10,color:"gray-400",hover:{color:"gray-600"},children:"✕"})})]})]},t)})]})}be.displayName="DataGridColumnGroups";function Ne(o){const{grid:e}=o,[t,i]=h.useState(e.globalFilterValue),r=h.useRef(null);h.useEffect(()=>()=>{r.current&&clearTimeout(r.current)},[]);const n=h.useCallback(u=>{const f=u.target.value;i(f),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{e.setGlobalFilter(f),r.current=null},300)},[e]),a=h.useCallback(()=>{i(""),e.setGlobalFilter("")},[e]),{filtered:c,total:d}=e.filterStats,l=e.hasActiveFilters&&c!==d;return s.jsxs(p.default,{component:"datagrid.topBar.globalFilter",children:[l&&s.jsxs(m.default,{component:"datagrid.topBar.globalFilter.stats",children:[c,"/",d]}),s.jsxs(p.default,{position:"relative",ai:"center",children:[s.jsx(p.default,{position:"absolute",left:3,pointerEvents:"none",color:"gray-400",theme:{dark:{color:"gray-500"}},children:s.jsx(w.SearchIcon,{fill:"currentColor",width:"14px"})}),s.jsx(z.default,{placeholder:"Search...",variant:"compact",value:t,onChange:n,pl:8,pr:t?8:3}),t&&s.jsx(m.default,{position:"absolute",right:2,cursor:"pointer",p:1,color:"gray-400",hover:{color:"gray-600"},theme:{dark:{color:"gray-500",hover:{color:"gray-300"}}},props:{onClick:a},children:s.jsx(m.default,{fontSize:12,fontWeight:600,children:"✕"})})]})]})}function ve(o){const{grid:e}=o,i=h.useMemo(()=>e.columns.value.leafs.filter(l=>![D,G,W,L].includes(l.key)),[e.columns.value.leafs]).map(l=>({id:String(l.key),label:l.header??l.key,leaf:l})),r=i.filter(l=>l.leaf.isVisible).map(l=>l.id),n=i.length,c=n-r.length>0,d=(l,u)=>{const f=new Set(u);i.forEach(g=>{const y=f.has(g.id);g.leaf.isVisible!==y&&g.leaf.toggleVisibility()})};return s.jsxs(R.default,{multiple:!0,showCheckbox:!0,hideIcon:!0,variant:"compact",value:r,onChange:d,isSearchable:i.length>6,searchPlaceholder:"Search columns...",display:"inline-flex",children:[s.jsx(R.default.Display,{children:l=>{const u=l.length===0;return s.jsxs(p.default,{ai:"center",gap:2,children:[s.jsxs(le.default,{viewBox:"0 0 20 20",width:"18",height:"18",children:[s.jsx("rect",{x:"2",y:"3",width:"4",height:"14",rx:"1",fill:"currentColor",opacity:.9}),s.jsx("rect",{x:"8",y:"3",width:"4",height:"14",rx:"1",fill:"currentColor",opacity:.6}),s.jsx("rect",{x:"14",y:"3",width:"4",height:"14",rx:"1",fill:"currentColor",opacity:.3})]}),c&&s.jsxs(m.default,{tag:"span",fontSize:11,lineHeight:16,fontWeight:500,px:2,py:.5,borderRadius:1,bgColor:u?"red-100":"amber-100",color:u?"red-700":"amber-700",theme:{dark:{bgColor:u?"red-900":"amber-900",color:u?"red-300":"amber-300"}},children:[l.length,"/",n]})]})}}),s.jsx(R.default.SelectAll,{children:"Show All"}),s.jsx(R.default.Unselect,{children:"Hide All"}),i.map(l=>s.jsx(R.default.Item,{value:l.id,textWrap:"nowrap",children:l.label},l.id))]})}ve.displayName="DataGridTopBarContextMenu";function Re(o){const{grid:e}=o,{title:t,topBarContent:i,globalFilter:r}=e.props.def;return s.jsxs(p.default,{component:"datagrid.topBar",position:"relative",ai:"center",jc:"space-between",gap:4,flexWrap:"wrap",children:[s.jsxs(p.default,{ai:"center",gap:3,flexWrap:"wrap",minWidth:0,children:[s.jsx(ve,{grid:e}),t&&s.jsx(m.default,{fontWeight:600,fontSize:16,color:"gray-800",theme:{dark:{color:"gray-100"}},children:t}),s.jsx(be,{grid:e})]}),s.jsxs(p.default,{ai:"center",gap:3,flexWrap:"wrap",jc:"flex-end",minWidth:0,children:[i&&s.jsx(m.default,{children:i}),r&&s.jsx(Ne,{grid:e})]})]})}Re.displayName="DataGridTopBar";function Be(o){const[e,t]=h.useState(0),i=h.useRef();return i.current||(i.current=new Le(o,()=>t(r=>r+1))),h.useEffect(()=>{i.current.props=o,i.current.rows.clear(),i.current.flatRows.clear(),i.current.update()},[o.data]),h.useEffect(()=>{i.current.props=o,i.current.sourceColumns.clear(),i.current.columns.clear(),i.current.headerRows.clear(),i.current.gridTemplateColumns.clear(),i.current.rows.clear(),i.current.flatRows.clear(),i.current.sizes.clear(),i.current.update()},[o.def]),h.useEffect(()=>{i.current.props=o,i.current.update()},[o.loading]),h.useEffect(()=>{i.current.props=o,i.current.rows.clear(),i.current.flatRows.clear(),i.current.update()},[o.globalFilterValue,o.columnFilters,o.filters]),i.current}function je(o){const e=Be(o),t=h.useRef(null);return h.useLayoutEffect(()=>{const i=t.current;if(!i)return;const r=new ResizeObserver(n=>{const a=n[0]?.contentRect.width??0;e.setContainerWidth(a)});return r.observe(i),()=>r.disconnect()},[e]),console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid render"),s.jsxs(m.default,{ref:t,component:"datagrid",style:e.sizes.value,props:{role:"presentation"},children:[e.props.def.topBar&&s.jsx(Re,{grid:e}),s.jsx(ye,{grid:e}),e.props.def.bottomBar&&s.jsx(Fe,{grid:e})]})}je.displayName="DataGrid";exports.default=je;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react/jsx-runtime"),d=require("react"),f=require("../box.cjs"),m=require("./flex.cjs"),z=require("./baseSvg.cjs"),N=require("./button.cjs"),oe=require("./grid.cjs"),w=require("../core.cjs"),re=require("./checkbox.cjs"),R=require("./dropdown.cjs"),A=require("./textbox.cjs"),V=require("./semantics.cjs"),We=require("./tooltip.cjs");function de(r){const{grid:e}=r,t=e.paginationState,i=t?.page??1,s=t?.totalPages??1,o=i<=1,c=i>=s,u=d.useCallback(()=>!o&&e.changePage(1),[e,o]),h=d.useCallback(()=>!o&&e.changePage(i-1),[e,i,o]),a=d.useCallback(()=>!c&&e.changePage(i+1),[e,i,c]),l=d.useCallback(()=>!c&&e.changePage(s),[e,s,c]);return t?n.jsxs(m.default,{component:`${e.componentName}.bottomBar.pagination`,gap:.5,ai:"center",children:[n.jsx(Q,{onClick:u,disabled:o,children:n.jsx(Ve,{})}),n.jsx(Q,{onClick:h,disabled:o,children:n.jsx(Pe,{})}),n.jsxs(f.default,{fontSize:12,px:3,userSelect:"none",children:[i," of ",s]}),n.jsx(Q,{onClick:a,disabled:c,children:n.jsx(Ee,{})}),n.jsx(Q,{onClick:l,disabled:c,children:n.jsx($e,{})})]}):null}de.displayName="DataGridPagination";function Q(r){const{onClick:e,disabled:t,children:i}=r;return n.jsx(N.default,{clean:!0,onClick:e,cursor:t?"default":"pointer",p:1,borderRadius:4,opacity:t?.3:.7,hover:t?void 0:{opacity:1,bgColor:"gray-100"},theme:{dark:{hover:t?void 0:{bgColor:"gray-700"}}},transition:"all",transitionDuration:150,children:i})}function Pe(){return n.jsx(z.default,{viewBox:"0 0 24 24",width:"14",height:"14",children:n.jsx(f.default,{tag:"path",props:{d:"M15 18l-6-6 6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}})})}function Ee(){return n.jsx(z.default,{viewBox:"0 0 24 24",width:"14",height:"14",children:n.jsx(f.default,{tag:"path",props:{d:"M9 18l6-6-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}})})}function Ve(){return n.jsx(z.default,{viewBox:"0 0 24 24",width:"14",height:"14",children:n.jsx(f.default,{tag:"path",props:{d:"M18 18l-6-6 6-6M11 18l-6-6 6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}})})}function $e(){return n.jsx(z.default,{viewBox:"0 0 24 24",width:"14",height:"14",children:n.jsx(f.default,{tag:"path",props:{d:"M6 18l6-6-6-6M13 18l6-6-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}})})}function Me(r){const{grid:e}=r,t=e.paginationState;if(t){const{page:c,pageSize:u,totalItems:h}=t,a=(c-1)*u+1,l=Math.min(a+u-1,h);return n.jsxs(m.default,{component:`${e.componentName}.bottomBar`,children:[n.jsxs(f.default,{children:["Rows: ",h>0?`${a}–${l} of ${h}`:"0"]}),e.props.def.rowSelection&&n.jsxs(f.default,{children:["Selected: ",e.selectedRows.size]}),n.jsx(de,{grid:e})]})}const{filtered:i,total:s}=e.filterStats,o=e.hasActiveFilters;return n.jsxs(m.default,{component:`${e.componentName}.bottomBar`,children:[n.jsxs(f.default,{children:["Rows: ",i!==s?`${i} / ${s}`:s]}),e.props.def.rowSelection&&n.jsxs(f.default,{children:["Selected: ",e.selectedRows.size]}),o&&n.jsx(f.default,{color:"blue-600",cursor:"pointer",hover:{textDecoration:"underline"},props:{onClick:e.clearAllFilters},children:"Clear filters"})]})}class U{constructor(e,t){this.grid=e,this.parentRow=t}get key(){return`detail-${this.parentRow.key}`}static AUTO_HEIGHT_ESTIMATE=200;get height(){const e=this.grid.props.def.rowDetail;return!e||e.height===void 0||e.height==="auto"?"auto":typeof e.height=="function"?e.height(this.parentRow.data):e.height}get heightForOffset(){const e=this.height;return e==="auto"?U.AUTO_HEIGHT_ESTIMATE:e}count=0;get flatRows(){return[this]}get allRows(){return[]}}function pe(r){const{cell:e}=r,t=e.grid.expandedDetailRows.has(e.row.key),i=d.useCallback(()=>{e.grid.toggleDetailRow(e.row.key)},[e.grid,e.row.key]);return n.jsx(N.default,{clean:!0,onClick:i,cursor:"pointer",display:"flex",ai:"center",jc:"center",children:n.jsx(w.ExpandIcon,{fill:"currentColor",width:"14px",height:"14px",rotate:t?0:-90})})}pe.displayName="DataGridCellRowDetail";function fe(r){const{cell:e}=r,t=d.useCallback(()=>{e.grid.toggleRowSelection(e.row.key)},[e.grid,e.row.key]);return n.jsx(re.default,{variant:"datagrid",checked:e.row.selected,onChange:t})}fe.displayName="DataGridCellRowSelection";const Be="NO_PIN";class ${constructor(e,t,i){if(this.def=e,this.grid=t,this.parent=i,this.columns=e.columns?.map(s=>new $(e.pin?{...s,pin:e.pin}:s,t,this))??[],this.isLeaf){const s=this.grid.columnWidths.get(this.key);this._inlineWidth=this.key==T?void 0:s??this.def.width??this.grid.DEFAULT_COLUMN_WIDTH_PX,this._pin=e.pin}}columns=[];get visibleColumns(){return this.columns.filter(e=>e.isVisible)}get isFirstLeaf(){const{leafs:e}=this;return e.length>0&&e.at(0)===this}get isLastLeaf(){const{leafs:e}=this;return e.length>0&&e.at(-1)===this}get key(){return this.def.key}get header(){return this.def.header}get align(){return this.def.align}get isLeaf(){return this.columns.length===0}get Cell(){return this.def.Cell}get filterable(){return this.def.filterable}get sortable(){return this.def.sortable!==void 0?this.def.sortable:this.grid.props.def.sortable!==!1}get resizable(){return this.def.resizable!==void 0?this.def.resizable:this.grid.props.def.resizable!==!1}get isFlexible(){return this.def.flexible!==!1}get baseWidth(){return this._inlineWidth??this.grid.DEFAULT_COLUMN_WIDTH_PX}_pin;get pin(){if(this.isLeaf)return this._pin;const e=[...new Set(this.columns.flatMap(t=>t.pin))];if(e.length===1)return e[0]}get uniqueKey(){return`${this.key}${this.pin??""}`}getPinnedColumn(e){if(this.hasPin(e)){if(this.isLeaf)return this;const t=new $({...this.def,pin:e},this.grid,this.parent);return t.columns=this.columns.filter(i=>i.hasPin(e)).map(i=>{const s=i.getPinnedColumn(e);return s.parent=t,s}).filter(i=>!!i),t}}hasPin(e){return this.isLeaf?this._pin===e:this.columns.some(t=>t.hasPin(e))}get death(){return this.parent?this.parent.death+1:0}get flatColumns(){const e=[this];return e.push(...this.columns.flatMap(t=>t.flatColumns)),e}_inlineWidth;get inlineWidth(){if(this.isLeaf)return this.grid.getFlexWidth(this.key)??this._inlineWidth;const e=this.visibleColumns.map(t=>t.inlineWidth).filter(t=>typeof t=="number");if(e.length!==0)return e.sumBy(t=>t)}get left(){let e=0;if(this.parent){const{visibleColumns:t,left:i}=this.parent,s=t.findIndex(o=>o===this);e+=t.sumBy((o,c)=>c<s?o.inlineWidth??0:0),e+=i}else{const t=this.grid.columns.value.left.filter(s=>s.isVisible),i=t.findIndex(s=>s===this);e+=t.sumBy((s,o)=>o<i?s.inlineWidth??0:0)}return e}get right(){let e=0;if(this.parent){const{visibleColumns:t}=this.parent,i=t.reverse(),s=i.findIndex(o=>o===this);e+=i.sumBy((o,c)=>c<s?o.inlineWidth??0:0),e+=this.parent.right}else{const i=this.grid.columns.value.right.filter(o=>o.isVisible).reverse(),s=i.findIndex(o=>o===this);e+=i.sumBy((o,c)=>c<s?o.inlineWidth??0:0)}return e}get isEdge(){if(!this.pin)return!1;if(this.parent){const{visibleColumns:t}=this.parent;return(this.pin==="LEFT"?t.at(-1):t.at(0))===this&&this.parent.isEdge}return(this.pin==="LEFT"?this.grid.columns.value.left.filter(t=>t.isVisible).at(-1):this.grid.columns.value.right.filter(t=>t.isVisible).at(0))===this}get isVisible(){return this.isLeaf?!this.grid.hiddenColumns.has(this.key):this.leafs.some(e=>e.isVisible)}get leafs(){return this.isLeaf?[this]:this.visibleColumns.flatMap(e=>e.leafs)}get groupColumnWidthVarName(){return`--${this.uniqueKey}-group-width`}get widthVarName(){return`--${this.uniqueKey}-width`}get leftVarName(){return`--${this.uniqueKey}-left`}get rightVarName(){return`--${this.uniqueKey}-right`}get gridRows(){return this.isLeaf?this.grid.columns.value.maxDeath-this.death:1}resizeColumn=e=>{const t=e.pageX,{MIN_COLUMN_WIDTH_PX:i,update:s}=this.grid,o=this.leafs.toRecord(l=>[l.key,l.inlineWidth??l.baseWidth]),c=this.leafs.sumBy(l=>o[l.key])-this.leafs.length*i,u=w.FnUtils.throttle(l=>{const p=(l.pageX-t)*(this.pin==="RIGHT"?-1:1);this.leafs.forEach(g=>{const C=o[g.key],b=c>0?(C-i)/c*p:p/this.leafs.length,j=Math.round(C+b);g.setWidth(j<i?i:j)}),this.grid.flexWidths.clear(),this.grid.sizes.clear(),s()},40),h=new AbortController,a=l=>{h.abort(),s()};window.addEventListener("mousemove",u,h),window.addEventListener("mouseup",a,h)};pinColumn=e=>{this.isLeaf?this._pin=e:this.columns.forEach(t=>t.pinColumn(e)),this.grid.pinColumn(this.uniqueKey,e)};toggleGrouping=()=>{this.grid.toggleGrouping(this.key)};sortColumn=(...e)=>{this.grid.setSortColumn(this.key,...e)};setWidth=e=>{if(!this.isLeaf)throw new Error("Cannot set width for a parent column.");this._inlineWidth!==e&&(this._inlineWidth=e,this.grid.setWidth(this.key,e))};toggleVisibility=()=>{this.grid.toggleColumnVisibility(this.key)}}class Ie{constructor(e,t,i){this.grid=e,this.row=t,this.column=i}get value(){return this.column.key===D?this.row.rowIndex+1:this.row.data[this.column.key]}}class le{constructor(e,t,i){this.grid=e,this.data=t,this.rowIndex=i,this.grid=e,this.data=t,this.key=this.grid.getRowKey(t)}key;parentRow;count=1;get cells(){return this.grid.columns.value.visibleLeafs.map(e=>new Ie(this.grid,this,e))}get selected(){return this.grid.selectedRows.has(this.key)}get expanded(){return this.grid.expandedDetailRows.has(this.key)}get flatRows(){return this.grid.props.def.rowDetail&&this.expanded?[this,new U(this.grid,this)]:[this]}get allRows(){return this}}const T="empty-cell",D="row-number-cell",ae=70,_="row-selection-cell",L="grouping-cell",I="row-detail-cell";class ze{constructor(e,t){this.props=e,this.update=t,console.debug("\x1B[32m%s\x1B[0m","[react-box]: DataGrid GridModel ctor")}get componentName(){return this.props.component||"datagrid"}sourceColumns=w.memo(()=>{const{def:e}=this.props,t=[];if(this.groupColumns.size>0&&t.push(new $({key:L},this)),t.push(...e.columns.map(i=>new $(i,this))),e.rowSelection){const i=typeof e.rowSelection=="object"&&e.rowSelection.pinned?"LEFT":void 0;t.unshift(new $({key:_,pin:i,width:50,align:"center",Cell:fe},this))}if(e.showRowNumber){let i,s=ae;typeof e.showRowNumber=="object"&&(e.showRowNumber.pinned&&(i="LEFT"),s=e.showRowNumber.width??ae),t.unshift(new $({key:D,pin:i,width:s,align:"right"},this))}if(e.rowDetail){const i=e.rowDetail.pinned?"LEFT":void 0,s=e.rowDetail.expandColumnWidth??50;t.unshift(new $({key:I,pin:i,width:s,align:"center",Cell:pe},this))}return t});columns=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid columns memo");const e=this.sourceColumns.value.map(a=>a.getPinnedColumn("LEFT")).filter(a=>!!a),t=this.sourceColumns.value.map(a=>a.getPinnedColumn()).filter(a=>!!a),i=this.sourceColumns.value.map(a=>a.getPinnedColumn("RIGHT")).filter(a=>!!a),s=[...e,...t,...i].flatMap(a=>a.flatColumns),o=s.filter(a=>a.isLeaf),c=s.filter(a=>a.isLeaf&&a.isVisible),u=c.filter(a=>![T,D,_,L,I].includes(a.key)),h=s.maxBy(a=>a.death)+1;return{left:e,middle:t,right:i,flat:s,leafs:o,visibleLeafs:c,userVisibleLeafs:u,maxDeath:h}});headerRows=w.memo(()=>(console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid headerRows memo"),this.columns.value.flat.groupBy(t=>t.death).sortBy(t=>t.key).map(t=>{const i=t.values.groupBy(s=>s.pin??Be).toRecord(s=>[s.key,s.values]);return[...i.LEFT?.filter(s=>s.isVisible)??[],...i.NO_PIN?.filter(s=>s.isVisible)??[],...i.RIGHT?.filter(s=>s.isVisible)??[]]})));gridTemplateColumns=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid gridTemplateColumns memo");const{visibleLeafs:e}=this.columns.value,t=e.sumBy(c=>c.pin==="RIGHT"?1:0),i=e.length-t,s=i>0?`repeat(${i}, max-content)`:"",o=t>0?`repeat(${t}, max-content)`:"";return`${s} ${o}`.trim()});_globalFilterValue="";get globalFilterValue(){return this.props.globalFilterValue??this._globalFilterValue}_columnFilters={};get columnFilters(){return this.props.columnFilters??this._columnFilters}applyGlobalFilter(e){const t=this.globalFilterValue.trim();if(!t)return e;const{globalFilterKeys:i}=this.props.def,s=i??this.columns.value.leafs.filter(o=>o.key!==T&&o.key!==D&&o.key!==_&&o.key!==L&&o.key!==I).map(o=>o.key);return e.filter(o=>s.some(c=>{const u=o[c];return u==null?!1:w.fuzzySearch(t,String(u))}))}applyColumnFilters(e){const t=this.columnFilters,i=Object.keys(t);return i.length===0?e:e.filter(s=>i.every(o=>{const c=t[o];if(!c)return!0;const u=s[o];return this.matchesFilter(u,c)}))}matchesFilter(e,t){switch(t.type){case"text":return t.value.trim()?e==null?!1:w.fuzzySearch(t.value,String(e)):!0;case"number":{if(e==null)return!1;const i=typeof e=="number"?e:parseFloat(String(e));if(isNaN(i))return!1;switch(t.operator){case"eq":return i===t.value;case"ne":return i!==t.value;case"gt":return i>t.value;case"gte":return i>=t.value;case"lt":return i<t.value;case"lte":return i<=t.value;case"between":return t.valueTo!==void 0?i>=t.value&&i<=t.valueTo:i>=t.value;default:return!0}}case"multiselect":return t.values.length===0?!0:t.values.includes(e);default:return!0}}applyExternalFilters(e){const t=this.props.filters;return!t||t.length===0?e:e.filter(i=>t.every(s=>s(i)))}get filteredData(){if(this.isPaginated)return this.props.data;let e=this.props.data;return e=this.applyExternalFilters(e),this.props.def.globalFilter&&(e=this.applyGlobalFilter(e)),e=this.applyColumnFilters(e),e}fireServerStateChange(e){this.props.onServerStateChange?.({page:e?.page??this.page,pageSize:this.pageSize,sortColumn:"sortColumn"in(e??{})?e.sortColumn:this._sortColumn,sortDirection:"sortDirection"in(e??{})?e.sortDirection:this._sortDirection,columnFilters:e?.columnFilters??this.columnFilters,globalFilterValue:e?.globalFilterValue??this.globalFilterValue})}setGlobalFilter=e=>{this.props.onGlobalFilterChange?this.props.onGlobalFilterChange(e):this._globalFilterValue=e;const t=this.isPaginated&&this.page!==1?1:this.page;t!==this.page&&(this.props.onPageChange?this.props.onPageChange(1,this.pageSize):this._page=1),this.fireServerStateChange({globalFilterValue:e,page:t}),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.update()};setColumnFilter=(e,t)=>{const i={...this.columnFilters};t===void 0?delete i[e]:i[e]=t,this.props.onColumnFiltersChange?this.props.onColumnFiltersChange(i):this._columnFilters=i;const s=this.isPaginated&&this.page!==1?1:this.page;s!==this.page&&(this.props.onPageChange?this.props.onPageChange(1,this.pageSize):this._page=1),this.fireServerStateChange({columnFilters:i,page:s}),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.update()};clearColumnFilters=()=>{this.props.onColumnFiltersChange?this.props.onColumnFiltersChange({}):this._columnFilters={},this.fireServerStateChange({columnFilters:{}}),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.update()};clearAllFilters=()=>{this.setGlobalFilter(""),this.clearColumnFilters()};getColumnUniqueValues=e=>{const t=new Set;return this.props.data.forEach(i=>{const s=i[e];s!==void 0&&t.add(s)}),Array.from(t).sort((i,s)=>i===null?1:s===null?-1:typeof i=="string"&&typeof s=="string"?i.localeCompare(s):typeof i=="number"&&typeof s=="number"?i-s:String(i).localeCompare(String(s)))};get hasActiveFilters(){return this.globalFilterValue.trim()!==""||Object.keys(this.columnFilters).length>0}get filterStats(){if(this.isPaginated){const e=this.props.def.pagination.totalCount;return{filtered:e,total:e}}return{filtered:this.filteredData.length,total:this.props.data.length}}rows=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid rows memo");let e=this.filteredData;if(this._sortColumn&&!this.isPaginated&&(e=e.sortBy(t=>t[this._sortColumn],this._sortDirection)),this.groupColumns.size>0){const t=(i,s,o)=>{const c=s.values().next().value;s.delete(c);const u=this.columns.value.leafs.findOrThrow(h=>h.key===c);return this._sortColumn===L&&(i=i.sortBy(h=>h[c],this._sortDirection)),i.groupBy(h=>h[c]).map(h=>{let a;s.size>0?a=t(h.values,new Set(s),o+1):a=h.values.map((p,g)=>new le(this,p,o+1+g));const l=new me(this,u,a,o,h.key);return o+=1,l.expanded&&(o+=a.length),l})};return t(e,new Set(this.groupColumns),0)}return e.map((t,i)=>new le(this,t,i))});flatRows=w.memo(()=>(console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid flatRows memo"),this.rows.value.flatMap(e=>e.flatRows)));get rowHeight(){return this.props.def.rowHeight??this.DEFAULT_ROW_HEIGHT_PX}sizes=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid sizes memo");const e=this.columns.value.flat.reduce((s,o)=>{const{inlineWidth:c}=o;return typeof c=="number"&&(s[o.widthVarName]=`${o.inlineWidth}px`),o.pin==="LEFT"&&(s[o.leftVarName]=`${o.left}px`),o.pin==="RIGHT"&&(s[o.rightVarName]=`${o.right}px`),s},{});e[this.rowHeightVarName]=`${this.rowHeight}px`,e[this.leftEdgeVarName]=`${this.leftEdge}px`;const{visibleLeafs:t}=this.columns.value,i=t.find(s=>s.key===L);if(i){const s=t.sumBy(o=>o.pin===i.pin&&o.key!==D&&o.key!==_&&o.key!==I?o.inlineWidth??0:0);e[i.groupColumnWidthVarName]=`${s}px`}return this.groupColumns.forEach(s=>{const o=this.columns.value.leafs.findOrThrow(c=>c.key===s);e[o.groupColumnWidthVarName]=`${t.sumBy(c=>c.pin===o.pin?c.inlineWidth??0:0)}px`}),e});_containerWidth=0;get containerWidth(){return this._containerWidth}setContainerWidth=e=>{this._containerWidth!==e&&(this._containerWidth=e,this.flexWidths.clear(),this.sizes.clear(),this.update())};flexWidths=w.memo(()=>{console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid flexWidths memo");const e=this._containerWidth;if(e<=0)return{};const t=this.columns.value.visibleLeafs.filter(l=>l.key!==T),i=l=>!l.isFlexible||this.columnWidths.has(l.key),s=t.filter(i).sumBy(l=>l.baseWidth),o=t.filter(l=>!i(l)),c=o.sumBy(l=>l.baseWidth),u=e-s;if(u<=c)return o.toRecord(l=>[l.key,l.baseWidth]);const h={};let a=0;return o.forEach((l,p)=>{if(p===o.length-1)h[l.key]=u-a;else{const g=Math.floor(l.baseWidth/c*u);h[l.key]=g,a+=g}}),h});getFlexWidth(e){return this.flexWidths.value[e]}DEFAULT_ROW_HEIGHT_PX=48;MIN_COLUMN_WIDTH_PX=48;DEFAULT_COLUMN_WIDTH_PX=200;expandedGroupRow=new Set;_expandedDetailRows=new Set;get expandedDetailRows(){return this.props.expandedRowKeys?new Set(this.props.expandedRowKeys):this._expandedDetailRows}toggleDetailRow=e=>{const t=new Set(this.expandedDetailRows);t.has(e)?t.delete(e):t.add(e),this.props.onExpandedRowKeysChange?this.props.onExpandedRowKeysChange(Array.from(t)):this._expandedDetailRows=t,this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.update()};_page=1;get page(){return this.props.page??this._page}get pageSize(){const e=this.props.def.pagination;if(e?.pageSize)return e.pageSize;const t=this.props.def.visibleRowsCount;return typeof t=="number"?t:10}get isPaginated(){return!!this.props.def.pagination}get paginationState(){const e=this.props.def.pagination;if(!e)return;const t=e.totalCount,i=this.pageSize;return{page:this.page,pageSize:i,totalItems:t,totalPages:Math.max(1,Math.ceil(t/i))}}changePage=e=>{const t=this.paginationState;if(!t)return;const i=Math.max(1,Math.min(e,t.totalPages));i!==this.page&&(this.props.onPageChange?this.props.onPageChange(i,t.pageSize):this._page=i,this.fireServerStateChange({page:i}),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.update())};rowOffsets=w.memo(()=>{const e=[];let t=0;for(const i of this.flatRows.value)e.push(t),t+=i instanceof U?i.heightForOffset:this.rowHeight;return{offsets:e,totalHeight:t}});selectedRows=new Set;get leftEdge(){return this.columns.value.left.sumBy(e=>e.inlineWidth??0)}get rightEdge(){return this.columns.value.right.sumBy(e=>e.inlineWidth??0)}leftEdgeVarName="--left-edge";rowHeightVarName="--row-height";_idMap=new WeakMap;getRowKey(e){const{rowKey:t}=this.props.def;return t?typeof t=="function"?t(e):e[t]:(this._idMap.has(e)||this._idMap.set(e,crypto.randomUUID()),this._idMap.get(e))}setSortColumn=(e,...t)=>{if(t.length>0)[this._sortDirection]=t,this._sortColumn=this._sortDirection?e:void 0;else{const{_sortColumn:s,_sortDirection:o}=this;this._sortColumn=s===e&&o==="DESC"?void 0:e,this._sortDirection=s===e&&o==="ASC"?"DESC":"ASC"}this.props.onSortChange?.(this._sortColumn,this._sortDirection);const i=this.isPaginated&&this.page!==1?1:this.page;i!==this.page&&(this.props.onPageChange?this.props.onPageChange(1,this.pageSize):this._page=1),this.fireServerStateChange({sortColumn:this._sortColumn,sortDirection:this._sortDirection,page:i}),this.headerRows.clear(),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.update()};pinColumn=(e,t)=>{const i=this.columns.value.flat.findOrThrow(s=>s.uniqueKey===e);i.pin!==t&&i.pinColumn(t),this.columns.clear(),this.headerRows.clear(),this.gridTemplateColumns.clear(),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.flexWidths.clear(),this.sizes.clear(),this.update()};toggleGrouping=e=>{this.groupColumns=new Set(this.groupColumns),this.hiddenColumns=new Set(this.hiddenColumns),this.groupColumns.has(e)?(this.groupColumns.delete(e),this.hiddenColumns.delete(e)):(this.groupColumns.add(e),this.hiddenColumns.add(e)),this.sourceColumns.clear(),this.columns.clear(),this.headerRows.clear(),this.gridTemplateColumns.clear(),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.flexWidths.clear(),this.sizes.clear(),this.update()};unGroupAll=()=>{const e=new Set(this.groupColumns);this.groupColumns=new Set,this.hiddenColumns=new Set(Array.from(this.hiddenColumns).filter(t=>!e.has(t))),this.sourceColumns.clear(),this.columns.clear(),this.headerRows.clear(),this.gridTemplateColumns.clear(),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.flexWidths.clear(),this.sizes.clear(),this.update()};toggleGroupRow=e=>{this.expandedGroupRow=new Set(this.expandedGroupRow),this.expandedGroupRow.has(e)?this.expandedGroupRow.delete(e):this.expandedGroupRow.add(e),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.update()};toggleRowSelection=e=>{this.toggleRowsSelection([e])};toggleRowsSelection=e=>{this.selectedRows=new Set(this.selectedRows);const t=e.every(i=>this.selectedRows.has(i));t?e.forEach(i=>this.selectedRows.delete(i)):e.forEach(i=>this.selectedRows.add(i)),this.flatRows.clear(),this.rowOffsets.clear(),this.update(),this.props.onSelectionChange?.({action:t?"deselect":"select",affectedRowKeys:e,selectedRowKeys:Array.from(this.selectedRows),isAllSelected:this.selectedRows.size===this.props.data.length})};toggleSelectAllRows=()=>{this.toggleRowsSelection(this.props.data.map(e=>this.getRowKey(e)))};toggleColumnVisibility=e=>{this.hiddenColumns=new Set(this.hiddenColumns),this.hiddenColumns.has(e)?this.hiddenColumns.delete(e):this.hiddenColumns.add(e),this.columns.clear(),this.headerRows.clear(),this.gridTemplateColumns.clear(),this.rows.clear(),this.flatRows.clear(),this.rowOffsets.clear(),this.flexWidths.clear(),this.sizes.clear(),this.update()};setWidth=(e,t)=>{this.columnWidths.set(e,t)};groupColumns=new Set;hiddenColumns=new Set;columnWidths=new Map;_sortColumn;get sortColumn(){return this._sortColumn}_sortDirection="ASC";get sortDirection(){return this._sortDirection}}class He{constructor(e,t,i){this.grid=e,this.row=t,this.column=i}get value(){return this.column.key===D?this.row.rowIndex+1:this.column.key===L?`${this.row.groupValue} (${this.row.count})`:null}}class me{constructor(e,t,i,s,o){this.grid=e,this.groupColumn=t,this.rows=i,this.rowIndex=s,this.groupValue=o,i.forEach(c=>c.parentRow=this)}get key(){return`${this.parentRow?.key??""}${this.groupColumn.key}${this.groupValue}`}parentRow;get cells(){return this.grid.columns.value.visibleLeafs.map(e=>new He(this.grid,this,e))}get selected(){return this.allRows.every(e=>e.selected)}get indeterminate(){return!this.selected&&this.allRows.some(e=>e.selected)}get expanded(){return this.grid.expandedGroupRow.has(this.key)}get depth(){return this.parentRow?this.parentRow.depth+1:0}get count(){return this.rows.sumBy(e=>e.count,0)}get flatRows(){return this.expanded?[this,...this.rows.flatMap(e=>e.flatRows)]:[this]}get allRows(){return this.rows.flatMap(e=>e.allRows)}get groupingColumn(){return this.grid.columns.value.leafs.findOrThrow(e=>e.key===L)}get groupingColumnGridColumn(){const{visibleLeafs:e}=this.grid.columns.value,{groupingColumn:t}=this;return e.sumBy(s=>s.pin===t.pin&&s.key!==T&&s.key!==_&&s.key!==D&&s.key!==I?1:0)}toggleRow(){this.grid.toggleGroupRow(this.key)}}function ge(r){const{row:e}=r,{grid:t,parentRow:i}=e,s=t.props.def.rowDetail,o=e.height==="auto";return n.jsx(m.default,{component:`${t.componentName}.body.detailRow`,props:{role:"row"},style:{gridColumn:"1 / -1",height:o?"auto":`${e.height}px`},children:n.jsx(f.default,{position:"sticky",left:0,width:"fit",overflow:"hidden",style:{minWidth:"100%"},children:s.content(i.data)})})}ge.displayName="DataGridDetailRow";function O(r){const{children:e,column:t,style:i,...s}=r,{key:o,pin:c,left:u,right:h,isEdge:a,align:l,widthVarName:p,leftVarName:g,rightVarName:C,isFirstLeaf:b,isLastLeaf:j}=t;"align"in t.def&&(s.jc=l);const W=o===D,G=o===_,k=o===T,S=c==="LEFT",x=c==="RIGHT",y=S||x,v=S&&u===0,F=S&&a,P=x&&a,E=x&&h===0;return n.jsx(m.default,{component:`${t.grid.componentName}.body.cell`,props:{role:"cell"},variant:{isPinned:y,isFirstLeftPinned:v,isLastLeftPinned:F,isFirstRightPinned:P,isLastRightPinned:E,isRowSelection:G,isRowNumber:W,isFirstLeaf:b,isLastLeaf:j,isEmptyCell:k},style:{width:`var(${p})`,height:`var(${t.grid.rowHeightVarName})`,left:S?`var(${g})`:void 0,right:x?`var(${C})`:void 0,...i},...s,children:e})}O.displayName="DataGridCell";function xe(r){const{row:e}=r,{selected:t,indeterminate:i,cells:s,groupingColumn:o,groupingColumnGridColumn:c,depth:u,expanded:h}=e,a=d.useCallback(()=>{e.grid.toggleRowsSelection(e.allRows.map(l=>l.key))},[]);return n.jsx(m.default,{component:`${e.grid.componentName}.body.groupRow`,className:"grid-row",selected:t,display:"contents",props:{role:"rowgroup"},children:s.map(l=>{const{key:p,pin:g,groupColumnWidthVarName:C}=l.column,b=g==="RIGHT";if(p===L)return n.jsx(O,{column:l.column,style:{width:`var(${C})`,right:b?"0":void 0},br:o.pin==="LEFT"?1:void 0,gridColumn:c,pl:4*u,overflow:"auto",children:n.jsx(f.default,{textWrap:"nowrap",px:3,children:n.jsxs(N.default,{clean:!0,onClick:()=>e.toggleRow(),cursor:"pointer",display:"flex",gap:1,ai:"center",children:[n.jsx(w.ExpandIcon,{fill:"currentColor",width:"14px",height:"14px",rotate:h?0:-90}),l.value]})})},p);if(p===_)return n.jsx(O,{column:l.column,children:n.jsx(re.default,{variant:"datagrid",m:1,checked:t,indeterminate:i,onChange:a})},p);if(g!==o.pin||p===D||p===T||p===I)return n.jsx(O,{column:l.column,px:p===D?3:void 0,children:l.value},p)})})}xe.displayName="DataGridGroupRow";function we(r){const{cell:e}=r;return n.jsx(m.default,{height:"fit",width:"fit",overflow:"auto",ai:"center",jc:e.column.align,children:n.jsx(f.default,{px:3,textOverflow:"ellipsis",overflow:"hidden",textWrap:"nowrap",children:e.value})})}we.displayName="DataGridCellText";function Ce(r){const{row:e}=r,{selected:t}=e,i=e.grid.props.def.rowDetail?.expandOnRowClick,s=d.useCallback(()=>{e.grid.toggleDetailRow(e.key)},[e.grid,e.key]);return n.jsx(m.default,{component:`${e.grid.componentName}.body.row`,className:"grid-row",selected:t,display:"contents",props:{role:"row",onClick:i?s:void 0},cursor:i?"pointer":void 0,children:e.cells.map(o=>n.jsx(O,{column:o.column,children:o.column.Cell?n.jsx(o.column.Cell,{cell:o}):n.jsx(we,{cell:o})},o.column.key))})}Ce.displayName="DataGridRow";const ce=10,se=20;function Ae(r,e){let t=0,i=r.length-1;for(;t<i;){const s=t+i+1>>>1;r[s]<=e?t=s:i=s-1}return t}function ue(r){return r instanceof U?n.jsx(ge,{row:r},r.key):r instanceof me?n.jsx(xe,{row:r},r.key):n.jsx(Ce,{row:r},r.key)}function ye(r){const{grid:e,scrollTop:t}=r,i=e.props.def.visibleRowsCount==="all",{offsets:s,totalHeight:o}=e.rowOffsets.value,c=!!e.props.def.rowDetail,u=i?0:c?Math.max(0,Ae(s,t)-se):Math.max(0,Math.floor(t/e.rowHeight)-se),h=i?0:c?s[u]??0:u*e.rowHeight,a=i?e.flatRows.value.length:e.props.def.visibleRowsCount??ce,l=i?void 0:e.rowHeight*a+e.rowHeight/5,p=e.props.data.length===0,g=d.useMemo(()=>{if(console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid render rows"),p)return null;if(i)return e.flatRows.value.map(ue);const C=a+se*2;return e.flatRows.value.take(C,u).map(ue)},[e.flatRows.value,p,i,u,a]);if(console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid render DataGridBody"),p){const{noDataComponent:C}=e.props.def,b=e.props.loading?"loading...":"empty";return n.jsx(m.default,{jc:"center",ai:"center",width:"fit",position:"sticky",left:0,style:{height:l??e.rowHeight*ce},children:C??b})}return i?n.jsx(oe.default,{component:`${e.componentName}.body`,width:"max-content",minWidth:"fit",transition:"none",style:{gridTemplateColumns:e.gridTemplateColumns.value},children:g}):n.jsx(f.default,{style:{height:l},children:n.jsx(f.default,{style:{height:c?`${o}px`:`${e.flatRows.value.length*e.rowHeight}px`},children:n.jsx(oe.default,{component:`${e.componentName}.body`,width:"max-content",minWidth:"fit",transition:"none",style:{transform:`translate3d(0, ${h}px, 0)`,willChange:"transform",gridTemplateColumns:e.gridTemplateColumns.value},children:g})})})}ye.displayName="DataGridBody";function Oe(r){const{grid:e}=r;return n.jsx(m.default,{component:`${e.componentName}.emptyColumns`,d:"column",ai:"center",jc:"center",gap:4,py:16,px:6,bgColor:"gray-50",borderRadius:4,theme:{dark:{bgColor:"gray-900"}},children:n.jsxs(m.default,{d:"column",ai:"center",gap:3,children:[n.jsx(f.default,{width:16,height:16,borderRadius:999,bgColor:"gray-200",theme:{dark:{bgColor:"gray-700"}},display:"flex",ai:"center",jc:"center",children:n.jsx(z.default,{viewBox:"0 0 24 24",width:"40",fill:"currentColor",color:"gray-400",theme:{dark:{color:"gray-500"}},children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M3 6a3 3 0 013-3h12a3 3 0 013 3v12a3 3 0 01-3 3H6a3 3 0 01-3-3V6zm3-1a1 1 0 00-1 1v12a1 1 0 001 1h12a1 1 0 001-1V6a1 1 0 00-1-1H6zm2 3a1 1 0 011-1h6a1 1 0 110 2H9a1 1 0 01-1-1zm0 4a1 1 0 011-1h6a1 1 0 110 2H9a1 1 0 01-1-1zm0 4a1 1 0 011-1h4a1 1 0 110 2H9a1 1 0 01-1-1z"})})}),n.jsxs(m.default,{d:"column",ai:"center",gap:1,children:[n.jsx(f.default,{fontSize:18,fontWeight:600,color:"gray-900",theme:{dark:{color:"gray-50"}},children:"No Columns Selected"}),n.jsx(f.default,{fontSize:14,color:"gray-500",textAlign:"center",theme:{dark:{color:"gray-400"}},children:"Select at least one column from the columns menu to display data"})]})]})})}function he({column:r,grid:e}){const t=e.columnFilters[r.key],i=t?.type==="text"?t.value:"",[s,o]=d.useState(i),c=d.useRef(null);d.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const u=d.useCallback(l=>{const p=l.target.value;o(p),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{p.trim()?e.setColumnFilter(r.key,{type:"text",value:p}):e.setColumnFilter(r.key,void 0),c.current=null},300)},[e,r.key]),h=d.useCallback(()=>{o(""),e.setColumnFilter(r.key,void 0)},[e,r.key]),a=typeof r.def.filterable=="object"?r.def.filterable:{};return n.jsxs(m.default,{ai:"center",position:"relative",width:"fit",children:[n.jsx(A.default,{width:"fit",variant:"compact",placeholder:a.placeholder??"Filter...",value:s,onChange:u}),s&&n.jsx(m.default,{position:"absolute",right:2,top:"1/2",translateY:"-1/2",cursor:"pointer",props:{onClick:h},children:n.jsx(f.default,{fontSize:10,color:"gray-400",hover:{color:"gray-600"},children:"✕"})})]})}function Ue({column:r,grid:e}){const t=e.columnFilters[r.key],i=t?.type==="number"?t.value:"",s=t?.type==="number"?t.operator:"eq",o=t?.type==="number"?t.valueTo:"",[c,u]=d.useState(i),[h,a]=d.useState(s),[l,p]=d.useState(o??""),g=d.useRef(null),C=d.useRef(null);d.useEffect(()=>()=>{g.current&&clearTimeout(g.current),C.current&&clearTimeout(C.current)},[]);const b=typeof r.def.filterable=="object"?r.def.filterable:{},j=d.useCallback((x,y,v)=>{const F=typeof y=="number"?y:parseFloat(y);if(isNaN(F)||y===""){e.setColumnFilter(r.key,void 0);return}const P={type:"number",operator:x,value:F};if(x==="between"&&v!==void 0&&v!==""){const E=typeof v=="number"?v:parseFloat(String(v));isNaN(E)||(P.valueTo=E)}e.setColumnFilter(r.key,P)},[e,r.key]),W=d.useCallback(x=>{const y=x.target.value;u(y),g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{j(h,y,l),g.current=null},300)},[h,l,j]),G=d.useCallback(x=>{a(x),j(x,c,l)},[c,l,j]),k=d.useCallback(x=>{const y=x.target.value;p(y),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{j(h,c,y),C.current=null},300)},[h,c,j]),S=d.useCallback(()=>{u(""),p(""),a("eq"),e.setColumnFilter(r.key,void 0)},[e,r.key]);return n.jsxs(m.default,{ai:h==="between"?"start":"center",gap:1,width:"fit",children:[n.jsxs(R.default,{value:h,variant:"compact",onChange:x=>x&&G(x),minWidth:6,hideIcon:!0,children:[n.jsx(R.default.Item,{value:"eq",children:"="}),n.jsx(R.default.Item,{value:"ne",children:"≠"}),n.jsx(R.default.Item,{value:"gt",children:">"}),n.jsx(R.default.Item,{value:"gte",children:"≥"}),n.jsx(R.default.Item,{value:"lt",children:"<"}),n.jsx(R.default.Item,{value:"lte",children:"≤"}),n.jsx(R.default.Item,{value:"between",children:"↔"})]}),h==="between"?n.jsxs(m.default,{d:"column",gap:1,flex1:!0,children:[n.jsxs(m.default,{ai:"center",position:"relative",flex1:!0,children:[n.jsx(A.default,{type:"number",variant:"compact",placeholder:b.placeholder??"From",value:c,onChange:W,width:"fit",step:b.step}),(c!==""||l!=="")&&n.jsx(m.default,{position:"absolute",right:2,top:"1/2",translateY:"-1/2",cursor:"pointer",props:{onClick:S},children:n.jsx(f.default,{fontSize:10,color:"gray-400",hover:{color:"gray-600"},children:"✕"})})]}),n.jsx(m.default,{ai:"center",flex1:!0,children:n.jsx(A.default,{type:"number",variant:"compact",placeholder:"To",value:l,onChange:k,width:"fit",step:b.step})})]}):n.jsxs(m.default,{ai:"center",position:"relative",flex1:!0,children:[n.jsx(A.default,{type:"number",variant:"compact",placeholder:b.placeholder??"Value",value:c,onChange:W,width:"fit",step:b.step}),c!==""&&n.jsx(m.default,{position:"absolute",right:2,top:"1/2",translateY:"-1/2",cursor:"pointer",props:{onClick:S},children:n.jsx(f.default,{fontSize:10,color:"gray-400",hover:{color:"gray-600"},children:"✕"})})]})]})}function qe({column:r,grid:e}){const t=e.columnFilters[r.key],i=t?.type==="multiselect"?t.values:[],s=typeof r.def.filterable=="object"?r.def.filterable:{},o=d.useMemo(()=>s.options?s.options:e.getColumnUniqueValues(r.key).map(h=>({label:h===null?"(empty)":String(h),value:h})),[s.options,e,r.key]),c=d.useCallback((u,h)=>{h.length===0?e.setColumnFilter(r.key,void 0):e.setColumnFilter(r.key,{type:"multiselect",values:h})},[e,r.key]);return n.jsxs(R.default,{multiple:!0,showCheckbox:!0,isSearchable:!0,searchPlaceholder:"Search...",value:i,width:"fit",minWidth:0,onChange:c,variant:"compact",children:[n.jsx(R.default.Unselect,{children:"Clear"}),n.jsx(R.default.SelectAll,{children:"Select All"}),o.map(u=>n.jsx(R.default.Item,{value:u.value,ai:"center",gap:2,children:u.label},String(u.value)))]})}function be(r){const{column:e,grid:t}=r,{filterable:i}=e.def;if(!i)return null;switch((typeof i=="object"?i:{type:"text"}).type){case"text":return n.jsx(he,{column:e,grid:t});case"number":return n.jsx(Ue,{column:e,grid:t});case"multiselect":return n.jsx(qe,{column:e,grid:t});default:return n.jsx(he,{column:e,grid:t})}}be.displayName="DataGridColumnFilter";function ve(r){const{column:e,grid:t}=r,{key:i,pin:s,left:o,right:c,isEdge:u,widthVarName:h,leftVarName:a,rightVarName:l,filterable:p}=e,g=i===T,W=g||i===L||i===D||i===_,G=s==="LEFT",k=s==="RIGHT",S=G||k,x=G&&o===0,y=G&&u,v=k&&u,F=k&&c===0;return n.jsx(m.default,{component:`${t.componentName}.filter.cell`,variant:{isPinned:S,isFirstLeftPinned:x,isLastLeftPinned:y,isFirstRightPinned:v,isLastRightPinned:F},px:g?0:2,style:{width:`var(${h})`,left:G?`var(${a})`:void 0,right:k?`var(${l})`:void 0},children:!W&&p&&n.jsx(be,{column:e,grid:t})})}ve.displayName="DataGridFilterCell";function Re(r){const{grid:e}=r,{visibleLeafs:t}=e.columns.value;return t.some(s=>s.filterable)?t.map(s=>n.jsx(ve,{column:s,grid:e},s.uniqueKey)):null}Re.displayName="DataGridFilterRow";function je(r){const{column:e}=r,{key:t,pin:i,left:s,right:o,isEdge:c,isLeaf:u,align:h,header:a,grid:l}=e,[p,g,C]=w.useVisibility({hideOnScroll:!0,event:"mousedown"}),[b,j]=d.useState({top:0,left:0}),W=d.useMemo(()=>b.left>window.innerWidth/2,[b.left]),G=u&&e.sortable&&(l.sortColumn!==t||l.sortDirection==="DESC"),k=u&&e.sortable&&(l.sortColumn!==t||l.sortDirection==="ASC"),S=u&&e.sortable&&l.sortColumn===t,x=i!=="LEFT",y=i!=="RIGHT",v=!!i,F=u&&t!==L,P=u&&t===L,E=G||k||S,q=x||y||v,Z=h==="right"?2:void 0,ee=h==="right"?void 0:i==="RIGHT"?2.5:4,K=t===T,X=t===D,te=t===_,B=i==="LEFT",Y=i==="RIGHT",ie=B||i==="RIGHT",J=B&&s===0,ne=B&&c,M=Y&&c,H=Y&&o===0,Te=u&&!K&&!X&&!te&&e.sortable;return n.jsx(m.default,{position:"absolute",left:Z,right:ee,top:"1/2",translateY:-3,ai:"center",children:n.jsxs(N.default,{component:`${l.componentName}.header.cell.contextMenu`,onClick:()=>g(!p),variant:{isPinned:ie,isFirstLeftPinned:J,isLastLeftPinned:ne,isFirstRightPinned:M,isLastRightPinned:H,isSortable:Te,isRowNumber:X},children:[n.jsx(V.Span,{component:`${l.componentName}.header.cell.contextMenu.icon`,children:n.jsx(w.DotsIcon,{fill:"currentColor"})}),p&&n.jsxs(We.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip`,onPositionChange:j,ref:C,adjustTranslateX:W?"-100%":"-21px",adjustTranslateY:"16px",children:[G&&n.jsxs(N.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item`,onClick:()=>e.sortColumn("ASC"),children:[n.jsx(V.Span,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item.icon`,children:n.jsx(w.SortIcon,{width:"100%",fill:"currentColor"})}),"Sort Ascending"]}),k&&n.jsxs(N.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item`,onClick:()=>e.sortColumn("DESC"),children:[n.jsx(V.Span,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item.icon`,children:n.jsx(w.SortIcon,{width:"100%",fill:"currentColor",rotate:180})}),"Sort Descending"]}),S&&n.jsxs(N.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item`,onClick:()=>e.sortColumn(void 0),children:[n.jsx(f.default,{width:4}),"Clear Sort"]}),E&&(q||F||P)&&n.jsx(f.default,{bb:1,my:2,borderColor:"gray-300",component:`${l.componentName}.header.cell.contextMenu.tooltip.item.separator`}),x&&n.jsxs(N.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item`,onClick:()=>e.pinColumn("LEFT"),children:[n.jsx(V.Span,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item.icon`,children:n.jsx(w.PinIcon,{width:"100%",fill:"currentColor"})}),"Pin Left"]}),y&&n.jsxs(N.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item`,onClick:()=>e.pinColumn("RIGHT"),children:[n.jsx(V.Span,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item.icon`,children:n.jsx(w.PinIcon,{width:"100%",fill:"currentColor",rotate:-90})}),"Pin Right"]}),v&&n.jsxs(N.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item`,onClick:()=>e.pinColumn(),children:[n.jsx(f.default,{width:4}),"Unpin"]}),E&&q&&(F||P)&&n.jsx(f.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item.separator`}),F&&n.jsxs(N.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item`,onClick:e.toggleGrouping,children:[n.jsx(V.Span,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item.icon`,children:n.jsx(w.GroupingIcon,{width:"100%",fill:"currentColor"})}),n.jsxs(f.default,{textWrap:"nowrap",children:["Group by ",a??t]})]}),P&&n.jsxs(N.default,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item`,onClick:l.unGroupAll,children:[n.jsx(V.Span,{component:`${l.componentName}.header.cell.contextMenu.tooltip.item.icon`,children:n.jsx(w.GroupingIcon,{width:"100%",fill:"currentColor"})}),n.jsx(f.default,{textWrap:"nowrap",children:"Un-Group All"})]})]})]})})}je.displayName="DataGridHeaderCellContextMenu";function ke(r){const{column:e}=r;return n.jsx(m.default,{height:"fit",ai:"center",position:"absolute",right:e.pin==="RIGHT"?void 0:0,left:e.pin!=="RIGHT"?void 0:0,py:3,children:n.jsx(f.default,{cursor:"col-resize",px:.75,mt:-6,className:"resizer",height:"fit",props:{onMouseDown:e.resizeColumn,onTouchStart:e.resizeColumn},children:n.jsx(f.default,{component:`${e.grid.componentName}.header.cell.resizer`})})})}ke.displayName="DataGridHeaderCellResizer";function Se(r){const{column:e}=r,{key:t,pin:i,left:s,right:o,isEdge:c,isLeaf:u,leafs:h,grid:a,header:l,gridRows:p,widthVarName:g,leftVarName:C,rightVarName:b,inlineWidth:j,isFirstLeaf:W,isLastLeaf:G}=e,k=t===T,S=t===L,x=t===D,y=t===_,v=i==="LEFT",F=i==="RIGHT",P=v||i==="RIGHT",E=v&&s===0,q=v&&c,Z=F&&c,ee=F&&o===0,K=u&&!k&&!x&&!y&&e.sortable,X=u?1:h.length,te=!x&&!y&&e.resizable,B=!x&&!y,Y=y?void 0:e.align==="right"?10:3,ie=y?void 0:e.align==="center"?3:void 0,J=d.useCallback(()=>{a.toggleSelectAllRows()},[]),ne=d.useMemo(()=>{if(x)return null;if(y){const M=a.selectedRows.size===a.props.data.length,H=!M&&a.selectedRows.size>0;return n.jsx(re.default,{variant:"datagrid",m:1,indeterminate:H,checked:M,onChange:J})}if(S){if(a.groupColumns.size===1){const M=a.columns.value.leafs.findOrThrow(H=>H.key===a.groupColumns.values().next().value);return M.header??M.key}return"Group"}return l??t},[a.groupColumns,a.selectedRows,J]);return n.jsx(m.default,{props:{role:"columnheader"},component:`${a.componentName}.header.cell`,variant:{isPinned:P,isFirstLeftPinned:E,isLastLeftPinned:q,isFirstRightPinned:Z,isLastRightPinned:ee,isSortable:K,isRowNumber:x,isFirstLeaf:W,isLastLeaf:G,isEmptyCell:k},gridRow:p,gridColumn:X,style:{width:`var(${g})`,left:v?`var(${C})`:void 0,right:F?`var(${b})`:void 0},children:!k&&n.jsxs(n.Fragment,{children:[n.jsx(m.default,{width:"fit",height:"fit",jc:e.align,props:{onClick:K?()=>e.sortColumn():void 0},children:n.jsxs(m.default,{overflow:"hidden",position:u?void 0:"sticky",ai:"center",transition:"none",pl:Y,pr:ie,style:{left:i?void 0:`var(${a.leftEdgeVarName})`},children:[n.jsx(f.default,{overflow:"hidden",textOverflow:"ellipsis",textWrap:"nowrap",children:ne}),t===a.sortColumn&&n.jsx(f.default,{pl:(j??0)<58?0:2,children:n.jsx(w.SortIcon,{width:"16px",rotate:a.sortDirection==="ASC"?0:180,fill:"currentColor"})}),B&&n.jsx(f.default,{minWidth:e.align==="right"?4:10})]})}),te&&n.jsx(ke,{column:e}),B&&n.jsx(je,{column:e})]})})}Se.displayName="DataGridHeaderCell";function Fe(r){const{grid:e}=r;return n.jsxs(oe.default,{component:`${e.componentName}.header`,style:{gridTemplateColumns:e.gridTemplateColumns.value},children:[e.headerRows.value.map(t=>t.map(i=>n.jsx(Se,{column:i},i.uniqueKey))),n.jsx(Re,{grid:e})]})}Fe.displayName="DataGridHeader";function De(r){const{grid:e}=r,[t,i]=d.useState(0),s=d.useRef(null),o=d.useCallback(u=>{s.current!==null&&cancelAnimationFrame(s.current),s.current=requestAnimationFrame(()=>{i(u.target.scrollTop),s.current=null})},[]);return e.columns.value.userVisibleLeafs.length>0?n.jsxs(f.default,{component:`${e.componentName}.content`,overflowX:"scroll",style:{willChange:"scroll-position"},props:{onScroll:o},children:[n.jsx(Fe,{grid:e}),n.jsx(ye,{grid:e,scrollTop:t})]}):n.jsx(Oe,{grid:e})}De.displayName="DataGridContent";function Ge(r){const{grid:e}=r;return e.groupColumns.size===0?null:n.jsxs(m.default,{component:`${e.componentName}.topBar.columnGroups`,children:[n.jsx(V.Span,{component:`${e.componentName}.topBar.columnGroups.icon`,children:n.jsx(w.GroupingIcon,{width:"100%",fill:"currentColor"})}),Array.from(e.groupColumns,t=>{const i=e.columns.value.leafs.findOrThrow(s=>s.key===t);return n.jsxs(d.Fragment,{children:[n.jsx(w.ExpandIcon,{fill:"currentColor",width:"14px",height:"14px",rotate:-90}),n.jsxs(m.default,{component:`${e.componentName}.topBar.columnGroups.item`,children:[i.header??i.key,n.jsx(N.default,{component:`${e.componentName}.topBar.columnGroups.item.icon`,onClick:()=>e.toggleGrouping(i.key),children:n.jsx(f.default,{fontSize:10,color:"gray-400",hover:{color:"gray-600"},children:"✕"})})]})]},t)})]})}Ge.displayName="DataGridColumnGroups";function Ke(r){const{grid:e}=r,[t,i]=d.useState(e.globalFilterValue),s=d.useRef(null);d.useEffect(()=>()=>{s.current&&clearTimeout(s.current)},[]);const o=d.useCallback(l=>{const p=l.target.value;i(p),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{e.setGlobalFilter(p),s.current=null},300)},[e]),c=d.useCallback(()=>{i(""),e.setGlobalFilter("")},[e]),{filtered:u,total:h}=e.filterStats,a=e.hasActiveFilters&&u!==h;return n.jsxs(m.default,{component:`${e.componentName}.topBar.globalFilter`,children:[a&&n.jsxs(f.default,{component:`${e.componentName}.topBar.globalFilter.stats`,children:[u,"/",h]}),n.jsxs(m.default,{position:"relative",ai:"center",children:[n.jsx(m.default,{position:"absolute",left:3,pointerEvents:"none",color:"gray-400",theme:{dark:{color:"gray-500"}},children:n.jsx(w.SearchIcon,{fill:"currentColor",width:"14px"})}),n.jsx(A.default,{placeholder:"Search...",variant:"compact",value:t,onChange:o,pl:8,pr:t?8:3}),t&&n.jsx(f.default,{position:"absolute",right:2,cursor:"pointer",p:1,color:"gray-400",hover:{color:"gray-600"},theme:{dark:{color:"gray-500",hover:{color:"gray-300"}}},props:{onClick:c},children:n.jsx(f.default,{fontSize:12,fontWeight:600,children:"✕"})})]})]})}function Ne(r){const{grid:e}=r,i=d.useMemo(()=>e.columns.value.leafs.filter(a=>![T,D,_,L].includes(a.key)),[e.columns.value.leafs]).map(a=>({id:String(a.key),label:a.header??a.key,leaf:a})),s=i.filter(a=>a.leaf.isVisible).map(a=>a.id),o=i.length,u=o-s.length>0,h=(a,l)=>{const p=new Set(l);i.forEach(g=>{const C=p.has(g.id);g.leaf.isVisible!==C&&g.leaf.toggleVisibility()})};return n.jsxs(R.default,{multiple:!0,showCheckbox:!0,hideIcon:!0,variant:"compact",value:s,onChange:h,isSearchable:i.length>6,searchPlaceholder:"Search columns...",display:"inline-flex",children:[n.jsx(R.default.Display,{children:a=>{const l=a.length===0;return n.jsxs(m.default,{ai:"center",gap:2,children:[n.jsxs(z.default,{viewBox:"0 0 20 20",width:"18",height:"18",children:[n.jsx("rect",{x:"2",y:"3",width:"4",height:"14",rx:"1",fill:"currentColor",opacity:.9}),n.jsx("rect",{x:"8",y:"3",width:"4",height:"14",rx:"1",fill:"currentColor",opacity:.6}),n.jsx("rect",{x:"14",y:"3",width:"4",height:"14",rx:"1",fill:"currentColor",opacity:.3})]}),u&&n.jsxs(f.default,{tag:"span",fontSize:11,lineHeight:16,fontWeight:500,px:2,py:.5,borderRadius:1,bgColor:l?"red-100":"amber-100",color:l?"red-700":"amber-700",theme:{dark:{bgColor:l?"red-900":"amber-900",color:l?"red-300":"amber-300"}},children:[a.length,"/",o]})]})}}),n.jsx(R.default.SelectAll,{children:"Show All"}),n.jsx(R.default.Unselect,{children:"Hide All"}),i.map(a=>n.jsx(R.default.Item,{value:a.id,textWrap:"nowrap",children:a.label},a.id))]})}Ne.displayName="DataGridTopBarContextMenu";function Le(r){const{grid:e}=r,{title:t,topBarContent:i,globalFilter:s}=e.props.def;return n.jsxs(m.default,{component:`${e.componentName}.topBar`,position:"relative",ai:"center",jc:"space-between",gap:4,flexWrap:"wrap",children:[n.jsxs(m.default,{ai:"center",gap:3,flexWrap:"wrap",minWidth:0,children:[n.jsx(Ne,{grid:e}),t&&n.jsx(f.default,{fontWeight:600,fontSize:16,color:"gray-800",theme:{dark:{color:"gray-100"}},children:t}),n.jsx(Ge,{grid:e})]}),n.jsxs(m.default,{ai:"center",gap:3,flexWrap:"wrap",jc:"flex-end",minWidth:0,children:[i&&n.jsx(f.default,{children:i}),s&&n.jsx(Ke,{grid:e})]})]})}Le.displayName="DataGridTopBar";function Xe(r){const[e,t]=d.useState(0),i=d.useRef();i.current||(i.current=new ze(r,()=>t(c=>c+1)));const s=i.current,o=s.props;return o!==r&&(s.props=r,o.def!==r.def&&(s.sourceColumns.clear(),s.columns.clear(),s.headerRows.clear(),s.gridTemplateColumns.clear(),s.sizes.clear()),(o.data!==r.data||o.def!==r.def||o.globalFilterValue!==r.globalFilterValue||o.columnFilters!==r.columnFilters||o.filters!==r.filters||o.expandedRowKeys!==r.expandedRowKeys||o.page!==r.page)&&(s.rows.clear(),s.flatRows.clear(),s.rowOffsets.clear())),s}function _e(r){const e=Xe(r),t=d.useRef(null);return d.useLayoutEffect(()=>{const i=t.current;if(!i)return;const s=new ResizeObserver(o=>{const c=o[0]?.contentRect.width??0;e.setContainerWidth(c)});return s.observe(i),()=>s.disconnect()},[e]),console.debug("\x1B[36m%s\x1B[0m","[react-box]: DataGrid render"),n.jsxs(f.default,{ref:t,component:e.componentName,style:e.sizes.value,props:{role:"presentation"},children:[e.props.def.topBar&&n.jsx(Le,{grid:e}),n.jsx(De,{grid:e}),e.props.def.bottomBar&&n.jsx(Me,{grid:e})]})}_e.displayName="DataGrid";exports.default=_e;
|