@agile-team/mach-table 0.32.0 → 0.32.1

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # @agile-team/mach-table
6
6
 
7
- MachTable 0.32.0 的框架无关 TypeScript Core:零运行时依赖,提供行列双虚拟化、领域化 API、单元格/整行编辑、树与分组、随机访问远程数据、区段隔离状态持久化和可诊断扩展系统。本版增加六个按需高级子入口,完善内部资源所有权、框架生命周期与缓存操作边界。
7
+ MachTable 0.32.1 的框架无关 TypeScript Core:零运行时依赖,提供行列双虚拟化、领域化 API、单元格/整行编辑、树与分组、随机访问远程数据、区段隔离状态持久化和可诊断扩展系统。本版增加六个按需高级子入口,完善内部资源所有权、框架生命周期与缓存操作边界。
8
8
 
9
9
  ```bash
10
10
  pnpm add @agile-team/mach-table
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var $t=Object.defineProperty;var Mi=Object.getOwnPropertyDescriptor;var Si=Object.getOwnPropertyNames;var ki=Object.prototype.hasOwnProperty;var Ii=(i,e)=>{for(var t in e)$t(i,t,{get:e[t],enumerable:!0})},Ai=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Si(e))!ki.call(i,o)&&o!==t&&$t(i,o,{get:()=>e[o],enumerable:!(r=Mi(e,o))||r.enumerable});return i};var Li=i=>Ai($t({},"__esModule",{value:!0}),i);var na={};Ii(na,{BUILTIN_AGG_FUNCS:()=>Jt,DEFAULT_LOCALE:()=>E,EVENT_TYPES:()=>Y,LOCALE_EN:()=>co,actionsColumn:()=>ci,advancedFilterCondition:()=>Gr,advancedFilterGroup:()=>Nr,applyGridViewState:()=>Ir,buildColDefsFromSchema:()=>ni,captureGridViewState:()=>kr,clearGridState:()=>Wo,createActionButtonsRenderer:()=>ye,createAggResolver:()=>Ve,createBusinessColumnTypes:()=>wi,createCachedDictionary:()=>bi,createColumnHelper:()=>hi,createDictionaryRenderer:()=>Ci,createEnterprisePreset:()=>fi,createGrid:()=>ri,createGridViewManager:()=>Ei,createLocalGridStateStore:()=>mr,createLocalGridViewStore:()=>Ar,createMachTableCommands:()=>si,createMachTablePreset:()=>Sr,createProgressBarRenderer:()=>br,createRemoteExportRequest:()=>oi,createRowActionsRenderer:()=>Ft,createStatusTagRenderer:()=>wr,defineColumns:()=>pi,defineGridOptions:()=>gi,defineMachTableConfig:()=>yi,defineMachTablePreset:()=>mi,describeFilter:()=>Ct,downloadFile:()=>vt,dragColumn:()=>di,escapeHtml:()=>ie,formatText:()=>B,formatTwo:()=>he,getByPath:()=>q,indexColumn:()=>li,isColDefGroup:()=>de,isSafePath:()=>se,linkRenderer:()=>Cr,loadGridState:()=>Pt,matchLocaleKey:()=>st,normalizeAdvancedFilterModel:()=>H,normalizeColumnFilter:()=>Pe,normalizeFilterModel:()=>U,normalizeGridState:()=>_,normalizeGridViewState:()=>Wt,normalizeSavedGridView:()=>ve,parseCsv:()=>Ue,parseDelimited:()=>je,parseTsv:()=>qe,resolveGridFeatures:()=>Vt,resolveSaveConflict:()=>To,resolveTagVariant:()=>vr,rowActionsColumn:()=>ui,sanitizeFormulaCell:()=>Ce,saveGridState:()=>Lt,selectionColumn:()=>ai,setByPath:()=>ae,toTsv:()=>ue,validateGridOptions:()=>Ot,version:()=>ia});module.exports=Li(na);var Ae="0.32.0";var Le=class{constructor(e){this.onListenerError=e;this.Ke=new Map}on(e,t){let r=this.Ke.get(e);return r||(r=new Set,this.Ke.set(e,r)),r.add(t),()=>{r.delete(t)}}once(e,t){let r=this.on(e,o=>{r(),t(o)});return r}off(e,t){let r=this.Ke.get(e);r&&(r.delete(t),r.size===0&&this.Ke.delete(e))}emit(e,t){let r=this.Ke.get(e);if(r)for(let o of[...r])try{o(t)}catch(n){console.error(`[mach-table] error in "${e}" listener`,n),this.onListenerError?.(n,e)}}clear(){this.Ke.clear()}};var Gi=new Set(["__proto__","prototype","constructor"]);function se(i){return typeof i!="string"||i.length===0?!1:i.split(".").every(t=>t.length>0&&!Gi.has(t))}function q(i,e){if(i==null||!se(e))return;if(e.indexOf(".")<0)return i[e];let r=i,o=0;for(;o<e.length;){if(r==null)return;let n=e.indexOf(".",o);if(n<0){r=r[e.slice(o)];break}r=r[e.slice(o,n)],o=n+1}return r}function ae(i,e,t){if(i==null||!se(e))return!1;let r=e.split("."),o=i;for(let n=0;n<r.length-1;n++){if(typeof o!="object"&&typeof o!="function"||o===null)return!1;o[r[n]]==null&&(o[r[n]]={}),o=o[r[n]]}return typeof o!="object"&&typeof o!="function"||o===null?!1:(o[r[r.length-1]]=t,!0)}var Ni=new Set(["contains","notContains","equals","notEquals","startsWith","endsWith","blank","notBlank"]),Fi=new Set(["equals","notEquals","lessThan","lessThanOrEqual","greaterThan","greaterThanOrEqual","inRange","blank","notBlank"]),Oi=new Set(["equals","notEquals","lessThan","greaterThan","inRange","blank","notBlank"]);function Hi(i){return i==null||typeof i=="string"||typeof i=="number"&&Number.isFinite(i)}function Vi(i){return i==="text"?Ni:i==="number"?Fi:Oi}function Bi(i,e,t){if(i==null||typeof i!="object")return null;let r=i;return typeof r.match!="string"||!t.has(r.match)?null:{match:r.match,...zi(r,e)}}function zi(i,e){let t=e==="number"?Lr(i.value):typeof i.value=="string"?i.value:void 0,r=e==="number"?Lr(i.value2):typeof i.value2=="string"?i.value2:void 0;return{...t!==void 0?{value:t}:{},...r!==void 0?{value2:r}:{}}}function Lr(i){return typeof i=="number"&&Number.isFinite(i)?i:void 0}function _i(i,e){let t=[],r=Vi(e);for(let o of i.slice(0,20)){let n=Bi(o,e,r);n&&t.push(n)}return t}function Pe(i){if(i==null||typeof i!="object")return null;let e=i;return e.type==="set"?Array.isArray(e.values)?{type:"set",values:e.values.filter(Hi).slice(0,2e3)}:null:e.type!=="text"&&e.type!=="number"&&e.type!=="date"||!Array.isArray(e.conditions)?null:{type:e.type,...e.operator==="or"||e.operator==="and"?{operator:e.operator}:{},conditions:_i(e.conditions,e.type)}}function Wi(i,e){if(typeof i.colId!="string"||!i.colId.trim())return null;let t=i.colId.trim();if(e.validColumnIds?.has(t)===!1)return null;let r=Pe(i.filter);return r?{kind:"condition",colId:t,filter:r}:null}function $i(i,e,t){if(!Array.isArray(i.children))return null;let r=[];for(let o of i.children){let n=Pr(o,e+1,t);n&&r.push(n)}return r.length===0?null:{kind:"group",operator:i.operator==="or"?"or":"and",children:r,...i.not===!0?{not:!0}:{}}}function Ki(i,e,t){return e<=16&&t.nodes<512&&i!=null&&typeof i=="object"}function Pr(i,e,t){if(!Ki(i,e,t)||t.ancestors.has(i))return null;t.ancestors.add(i),t.nodes++;let r=i,o=r.kind==="condition"?Wi(r,t):r.kind==="group"?$i(r,e,t):null;return t.ancestors.delete(i),o}function H(i,e){if(i==null||typeof i!="object")return null;let t=i;if(t.version!==1||t.root==null)return null;let r=Pr(t.root,0,{ancestors:new WeakSet,nodes:0,validColumnIds:e});return r?{version:1,root:r}:null}function Gr(i,e){return{kind:"condition",colId:i,filter:e}}function U(i,e){if(i==null||typeof i!="object"||Array.isArray(i))return{};let t={};for(let[r,o]of Object.entries(i).slice(0,2e3)){let n=r.trim();if(!n||e?.has(n)===!1)continue;let s=Pe(o);s&&(t[n]=s)}return t}function Nr(i,e,t={}){return{kind:"group",operator:i,children:e,...t.not?{not:!0}:{}}}var Kt={align:"center",sortable:!0,resizable:!0,movable:!0,filter:!1,minWidth:80},we={compact:{rowHeight:30,headerHeight:34,fontSize:12,cellPadding:6},normal:{rowHeight:36,headerHeight:40,fontSize:13,cellPadding:9},large:{rowHeight:44,headerHeight:48,fontSize:14,cellPadding:12}};function M(i,e,t,r=!1){return typeof i!="number"||!Number.isFinite(i)||i<t?e:r?Math.floor(i):i}function qi(i){return i&&Object.prototype.hasOwnProperty.call(we,i)?i:"normal"}function Ui(i){return i.theme==="light"||i.theme==="dark"||i.theme==="auto"?i.theme:"light"}function ji(i,e){let t=typeof i.pagination=="object"&&Array.isArray(i.pagination.pageSizeOptions)?i.pagination.pageSizeOptions:void 0,r=t?[...new Set(t.map(o=>M(o,0,1,!0)).filter(Boolean))]:[10,20,50,100];return r.includes(e)||r.push(e),r.sort((o,n)=>o-n)}function qt(i,e){let t=typeof i=="function"?i(e):q(e,i);return t==null?"":String(t)}function Yi(i){let e=i.rowKey,t=e?({data:r})=>qt(e,r):void 0;return{...t?{resolveRowId:t}:{},...e?{rowKey:e}:{}}}function Xi(i,e){let t=we[e];return{columnDefs:Array.isArray(i.columnDefs)?i.columnDefs:[],rowData:Array.isArray(i.rowData)?i.rowData:[],defaultColDef:{...Kt,...i.defaultColDef??{}},columnTypes:i.columnTypes??{},...Yi(i),rowHeight:M(i.rowHeight,t.rowHeight,1),headerHeight:M(i.headerHeight,t.headerHeight,1),rowBuffer:M(i.rowBuffer,8,0,!0),columnLayout:i.columnLayout==="fit"?"fit":"normal",enableColumnResize:i.enableColumnResize===!0,domLayout:i.domLayout==="autoHeight"?"autoHeight":"normal",rowSelection:i.rowSelection==="single"||i.rowSelection==="multiple"?i.rowSelection:"none",multiSort:i.multiSort??!0,size:e,pinnedTopRowData:Array.isArray(i.pinnedTopRowData)?i.pinnedTopRowData:[],pinnedBottomRowData:Array.isArray(i.pinnedBottomRowData)?i.pinnedBottomRowData:[]}}function Ji(i){return{stripedRows:i.stripedRows??!1,rowStyleRules:Array.isArray(i.rowStyleRules)?i.rowStyleRules:[],showCellBorders:i.showCellBorders??!1,theme:Ui(i),quickFilterText:i.quickFilterText??null,suppressCellFocus:i.suppressCellFocus??!1,suppressRowHoverHighlight:i.suppressRowHoverHighlight??!1,suppressNoRowsOverlay:i.suppressNoRowsOverlay??!1,suppressHeaderFocus:i.suppressHeaderFocus??!1,loading:i.loading??!1,error:i.error??null,className:i.className??""}}function Zi(i){return{editType:i.editType==="fullRow"?"fullRow":"cell",editableIndicator:i.editableIndicator==="always"||i.editableIndicator==="none"?i.editableIndicator:"hover",singleClickEdit:i.singleClickEdit??!1,manualSorting:i.manualSorting??!1,manualFiltering:i.manualFiltering??!1,showSummary:i.showSummary??!1,indexOffset:i.indexOffset??0,applyRowDrag:i.applyRowDrag??!0,rowDragPolicy:i.rowDragPolicy,undoStackSize:M(i.undoStackSize,100,0,!0),asyncTransactionWaitMillis:M(i.asyncTransactionWaitMillis,16,0,!0)}}function Qi(i){return{masterDetail:i.masterDetail??!1,detailRowHeight:M(i.detailRowHeight,240,1),detailToggleColumn:i.detailToggleColumn??!0,treeData:i.treeData??!1,childrenKey:i.childrenKey??"children",autoCheckedChildren:i.autoCheckedChildren??!0,defaultExpandAll:i.defaultExpandAll??!1}}function en(i){let e=typeof i.pagination=="object"?i.pagination:void 0,t=M(e?.pageSize,20,1,!0);return{paginationEnabled:i.pagination!==!1&&i.datasource==null,paginationMode:e?.mode==="server"?"server":"client",paginationPage:M(e?.page,1,1,!0),paginationTotal:M(e?.total,0,0,!0),paginationPageSize:t,paginationPageSizeOptions:ji(i,t),paginationShowTotal:e?e.showTotal!==!1:!0,paginationShowSizeSelector:e?e.showPageSizeSelector!==!1:!0}}function tn(i){return{watermarkEnabled:i.watermark!=null&&i.watermark!==!1,watermarkConfig:i.watermark==null||i.watermark===!1?null:i.watermark===!0?{text:"MachTable"}:i.watermark}}function rn(i){return{columnMenu:i.columnMenu??!1,advancedFilterModel:H(i.advancedFilterModel),...on(i),locale:i.locale??{},suppressWarnings:i.suppressWarnings??!1,enableRangeSelection:i.enableRangeSelection??!1,suppressClipboard:i.suppressClipboard??!1,contextMenu:i.contextMenu??!1,tooltipShowDelay:M(i.tooltipShowDelay,600,0),flashCells:i.flashCells??!0,fillHandle:i.fillHandle??!0,statusBarEnabled:i.statusBar===!0||typeof i.statusBar=="object"&&i.statusBar!=null,statusBarPanels:typeof i.statusBar=="object"&&i.statusBar?.panels?i.statusBar.panels:["rowCount","selectedRowCount","rangeAggregate"]}}function on(i){let e=i.persistence;return!e||typeof e.key!="string"||!e.key.trim()?{persistence:null}:{persistence:{key:e.key.trim(),debounceMs:M(e.debounceMs,160,0,!0),...e.sections?{sections:[...new Set(e.sections)]}:{},...e.store?{store:e.store}:{}}}}function nn(i){return{datasourceMode:i.datasourceMode==="block"?"block":"sequential",blockSize:M(i.blockSize,100,1,!0),infiniteBufferRows:M(i.infiniteBufferRows,40,0,!0),maxBlocksInCache:M(i.maxBlocksInCache,12,1,!0),datasourceMaxConcurrentRequests:M(i.datasourceMaxConcurrentRequests,4,1,!0),blockPrefetch:M(i.blockPrefetch,1,0,!0),datasourceRowCount:i.datasourceRowCount==null?null:M(i.datasourceRowCount,0,0,!0),dataProcessorMinRows:M(i.dataProcessorMinRows,5e3,1,!0),datasourceRetryCount:M(i.datasourceRetryCount,2,0,!0),datasourceRetryDelay:M(i.datasourceRetryDelay,300,0,!0),datasourceRetryJitter:Math.min(1,M(i.datasourceRetryJitter,.15,0))}}function sn(i){return{ariaLabel:i.ariaLabel??"MachTable data grid",ariaLabelledBy:i.ariaLabelledBy??"",ariaDescribedBy:i.ariaDescribedBy??"",overlayNoRowsTemplate:i.overlayNoRowsTemplate??"",overlayLoadingTemplate:i.overlayLoadingTemplate??"",overlayErrorTemplate:i.overlayErrorTemplate??"",allowUnsafeOverlayHtml:i.allowUnsafeOverlayHtml??!1}}var an=["detailRowRenderer","isRowExpandable","aggFuncs","components","actionPolicy","summaryMethod","datasource","getRowHeight","tooltipComponent","getContextMenuItems","initialState","rowEditValidator","isTreeRowExpandable","loadTreeChildren","dataProcessor"];function ln(i,e){for(let t of an)i[t]&&Object.assign(e,{[t]:i[t]})}function dn(i,e){for(let t of Object.keys(i))t.startsWith("on")&&typeof i[t]=="function"&&Object.assign(e,{[t]:i[t]})}function Fr(i){let e=qi(i.size),t={...Xi(i,e),...Ji(i),...Zi(i),...Qi(i),...en(i),...tn(i),...rn(i),...nn(i),...sn(i),features:Array.isArray(i.features)?i.features:[]};return ln(i,t),dn(i,t),t}function Or(i){return Array.isArray(i)?i.filter(e=>typeof e=="string"&&e.length>0):typeof i=="string"&&i.length>0?[i]:[]}function le(i,e){return Or(i.type).includes(e)}function Hr(i,e,t={}){let r={};for(let o of Or(i.type)){let n=t[o];n&&Object.assign(r,n)}return{...e,...r,...i}}var W=class{constructor(e,t){this.manualWidth=null;this.contentWidth=null;this.flex=null;this.currentWidth=0;this.parentGroup=null;this.level=0;this.isDetailToggle=!1;this.id=e,this.colDef=t,this.hide=t.hide??!1;let r=t.pinned;this.pinned=r===!0?"left":r===!1||r==null?null:r,this.resetWidth()}get sortable(){return this.colDef.sortable!==!1}get resizable(){return this.colDef.resizable!==!1}get movable(){return this.colDef.movable!==!1}get filterable(){return this.colDef.filter!=null&&this.colDef.filter!==!1}get filterType(){let e=this.colDef.filter;return e===!0?"text":e??"text"}get hasCheckbox(){return this.colDef.checkboxSelection===!0}resetWidth(){this.manualWidth=null,this.contentWidth=null,this.flex=typeof this.colDef.flex=="number"&&Number.isFinite(this.colDef.flex)&&this.colDef.flex>0?this.colDef.flex:null}};var Q=class i{constructor(e,t){this.parent=null;this.children=[];this.groupId=e,this.def=t}get headerName(){return this.def.headerName??this.def.groupId??""}getLeafColumns(e=[]){for(let t of this.children)t instanceof i?t.getLeafColumns(e):e.push(t);return e}};function de(i){return Array.isArray(i.children)}function Ge(i,e){return typeof i=="number"&&Number.isFinite(i)&&i>0?i:e}function Vr(i){let e=Ge(i.minWidth,80);return{min:e,max:Math.max(e,Ge(i.maxWidth,Number.MAX_SAFE_INTEGER))}}function O(i,e){let{min:t,max:r}=Vr(e),o=Ge(i,Ge(e.width,150));return Math.max(t,Math.min(r,o))}function Br(i,e){let t=i.map(s=>O(s.width??150,s)),r=[],o=0;i.forEach((s,a)=>{let l=s.flex??0;l>0&&(r.push(a),o+=l)});let n=0;for(let s of t)n+=s;if(o>0&&e>n){let s=e-n;for(let a=0;a<4&&s>.5&&r.length>0;a++){let l=[],d=0;for(let p of r){let m=i[p].flex??0;l.push(p),d+=m}let c=[];for(let p=0;p<l.length;p++){let m=l[p],g=i[m].flex??0,v=s*g/d,y=t[m];t[m]=O(y+v,i[m]),c.push(t[m]-y)}let u=0;for(let p of c)u+=p;s-=u;let h=l.filter((p,m)=>c[m]>.001);if(h.length===l.length)break;r.length=0;for(let p of h)r.push(p)}}return t}function cn(i,e,t){let r=new Set(i.map((n,s)=>s)),o=t;for(let n=0;n<i.length+1&&r.size>0;n++){let s=0;for(let l of r)s+=Math.max(1,e[l]);if(s<=0)break;let a=!1;for(let l of[...r]){let d=o*(Math.max(1,e[l])/s),c=O(d,i[l]),{min:u,max:h}=Vr(i[l]);(d<u||d>h)&&(e[l]=c,o-=c,r.delete(l),a=!0)}if(!a){for(let l of r)e[l]=O(o*(Math.max(1,e[l])/s),i[l]);break}o=Math.max(0,o)}}function un(i,e,t){let r=t-e.reduce((o,n)=>o+n,0);if(!(Math.abs(r)<=.01))for(let o=e.length-1;o>=0;o--){let n=O(e[o]+r,i[o]);if(Math.abs(n-e[o])>.01){e[o]=n;return}}}function Ne(i,e){let t=i.map(r=>O(r.width??150,r));return!Number.isFinite(e)||e<=0||i.length===0||(cn(i,t,e),un(i,t,e)),t}var Ut="__rg_detail_toggle__";function ce(i){return typeof i=="number"&&Number.isFinite(i)&&i>0}var Fe=class{constructor(e){this.core=e;this.columns=[];this.rn=new Map;this.q=[];this.left=[];this.center=[];this.right=[];this.sortModel=[];this.defs=[];this.qe=1;this.vo=new Map;this.fa=0}wt(e){this.defs=e?[...e]:[];let t=new Map(this.columns.map(s=>[s.id,s])),r=this.core.options.defaultColDef,o=new Set(this.core.options.masterDetail&&this.core.options.detailToggleColumn?[Ut]:[]),n=(s,a,l)=>s.map((d,c)=>{if(de(d)){let y=d.groupId??d.headerName??`group_${c}_${l}`,b=new Q(y,d);return b.parent=a,b.children=n(d.children,b,l+1),b}let u=d,h=u.colId??u.field??`col_${c}`,p=h,m=2;for(;o.has(p);)p=`${h}_${m++}`;o.add(p);let g=new W(p,Hr(u,r,this.core.options.columnTypes));g.parentGroup=a,g.level=l;let v=t.get(p);return v&&(g.manualWidth=v.manualWidth,g.contentWidth=v.contentWidth,g.flex=v.flex,g.hide=v.hide,g.pinned=v.pinned),g});if(this.q=n(this.defs,null,0),this.core.options.masterDetail&&this.core.options.detailToggleColumn){let s=new W(Ut,{colId:Ut,headerName:"",width:38,pinned:"left",sortable:!1,resizable:!1,movable:!1,filter:!1});s.isDetailToggle=!0,this.q.unshift(s)}if(this.columns=this.ir(this.q),this.rn=new Map(this.columns.map(s=>[s.id,s])),this.qe=this.columns.reduce((s,a)=>Math.max(s,a.level+1),1),this.sortModel=this.sortModel.filter(s=>this.columns.some(a=>a.id===s.colId)),this.sortModel.length===0){let s=[];for(let a of this.columns)a.colDef.initialSort&&s.push({colId:a.id,direction:a.colDef.initialSort});this.sortModel=s}this.Ue()}ir(e,t=[]){for(let r of e)r instanceof Q?this.ir(r.children,t):t.push(r);return t}Ue(){let e=this.columns.filter(t=>!t.hide);this.left=e.filter(t=>t.pinned==="left"),this.right=e.filter(t=>t.pinned==="right"),this.center=e.filter(t=>t.pinned===null),this.vo.clear(),this.e().forEach((t,r)=>this.vo.set(t.id,r))}te(e){return this.vo.get(e)??-1}G(){return this.columns}nr(){return this.defs}ma(){return this.q}ga(){return this.qe}m(e){return this.rn.get(e)}d(e){return e==="left"?this.left:e==="right"?this.right:this.center}e(){return[...this.left,...this.center,...this.right]}re(){return this.e().filter(e=>e.colDef.rowGroup===!0)}ya(){return this.e().filter(e=>e.colDef.aggFunc!=null&&e.colDef.rowGroup!==!0)}wo(){return this.center.some(e=>e.colDef.colSpan!=null)}nn(){let e=this.e();return this.center.find(t=>!t.hasCheckbox&&!t.isDetailToggle)??e.find(t=>!t.hasCheckbox&&!t.isDetailToggle)??e[0]}bt(e){return e.pinned==="left"?"left":e.pinned==="right"?"right":"center"}sn(e){this.fa=e;let t=0;for(let c of[...this.left,...this.right])c.currentWidth=O(c.manualWidth??c.contentWidth??c.colDef.width??150,this.Se(c)),t+=c.currentWidth;let r=Math.max(0,e-t),o=[],n=[];for(let c of this.center)(c.colDef.suppressSizeToFit||c.manualWidth!=null?n:o).push(c);let s=0;for(let c of n)c.currentWidth=O(c.manualWidth??c.contentWidth??c.colDef.width??150,this.Se(c)),s+=c.currentWidth;let a=o.map(c=>this.Se(c)),l=Math.max(0,r-s),d=this.core.options.columnLayout==="fit"?Ne(a,l):Br(a,l);o.forEach((c,u)=>{c.currentWidth=d[u]})}Se(e){let t=e.colDef;return{width:e.manualWidth??e.contentWidth??t.width,minWidth:t.minWidth,maxWidth:t.maxWidth,flex:e.manualWidth==null?e.flex??void 0:void 0}}oe(e,t){return ce(t)?(e.manualWidth=O(t,this.Se(e)),e.flex=null,!0):!1}an(e,t){return ce(t)?(e.resetWidth(),e.contentWidth=O(t,this.Se(e)),!0):!1}bo(e,t){let r=this.m(e);!r||r.hide===!t||(r.hide=!t,this.Ue())}moveColumn(e,t){let r=this.m(e);if(!r)return!1;let o=this.bt(r),n=u=>r.parentGroup?!0:this.bt(u)===o,s=r.parentGroup?r.parentGroup.children:this.q,a=s.filter(u=>u instanceof W&&!u.hide&&n(u)),l=a.indexOf(r);if(l<0)return!1;a.splice(l,1);let d=Math.max(0,Math.min(t,a.length));a.splice(d,0,r);let c=[];return s.forEach((u,h)=>{u instanceof W&&!u.hide&&n(u)&&c.push(h)}),c.length!==a.length?!1:(c.forEach((u,h)=>{s[u]=a[h]}),this.columns=this.ir(this.q),this.Ue(),!0)}Co(e,t){let r=this.m(e);!r||!r.movable||(r.pinned=t,this.Ue())}sr(){return this.columns.map(e=>({colId:e.id,hide:e.hide,width:e.manualWidth??e.currentWidth,flex:e.flex,widthMode:e.manualWidth==null?"auto":"manual",contentWidth:e.contentWidth??void 0,pinned:e.pinned}))}ln(e){let t=new Map(e.map(r=>[r.colId,r]));for(let r of this.columns){let o=t.get(r.id);o&&this.va(r,o)}this.wa(e),this.Ue()}va(e,t){typeof t.hide=="boolean"&&(e.hide=t.hide),t.widthMode==="auto"?(e.resetWidth(),ce(t.flex)&&(e.flex=t.flex)):ce(t.flex)?(e.flex=t.flex,e.manualWidth=null):ce(t.width)&&(e.manualWidth=O(t.width,this.Se(e)),e.flex=null),ce(t.contentWidth)&&(e.contentWidth=O(t.contentWidth,this.Se(e))),e.movable&&(t.pinned==="left"||t.pinned==="right"||t.pinned===null)&&(e.pinned=t.pinned)}wa(e){let t=new Map;e.forEach((o,n)=>t.set(o.colId,n));let r=o=>o.pinned==="left"?"left":o.pinned==="right"?"right":"center";for(let o of["left","center","right"]){let n=this.q.filter(d=>d instanceof W&&!d.hide&&d.parentGroup===null&&r(d)===o);if(n.length<2)continue;let s=n.filter(d=>d.movable),a=s.slice().sort((d,c)=>(t.get(d.id)??Number.MAX_SAFE_INTEGER)-(t.get(c.id)??Number.MAX_SAFE_INTEGER));if(a.every((d,c)=>d===s[c]))continue;let l=[];this.q.forEach((d,c)=>{d instanceof W&&!d.hide&&d.parentGroup===null&&r(d)===o&&d.movable&&l.push(c)}),l.forEach((d,c)=>{this.q[d]=a[c]})}this.columns=this.ir(this.q)}To(){for(let e of this.columns){e.resetWidth(),e.hide=e.colDef.hide??!1;let t=e.colDef.pinned;e.pinned=t===!0?"left":t===!1||t==null?null:t}this.Ue()}D(){return this.sortModel.map(e=>({...e}))}Ct(e){if(!e||e.length===0){this.sortModel=[];return}this.sortModel=e.filter(t=>this.columns.some(r=>r.id===t.colId)&&(t.direction==="asc"||t.direction==="desc")).map(t=>({colId:t.colId,direction:t.direction}))}cycleSort(e,t){let r=[...this.sortModel],o=r.findIndex(l=>l.colId===e.id),n=o>=0?r[o].direction:null,s=n===null?"asc":n==="asc"?"desc":null;t&&this.core.options.multiSort?s===null?o>=0&&r.splice(o,1):o>=0?r[o]={colId:e.id,direction:s}:r.push({colId:e.id,direction:s}):(r.length=0,s&&r.push({colId:e.id,direction:s})),this.sortModel=r}};function _r(i){return i==null?"":String(i).toLowerCase()}function hn(i,e,t){let r=_r(i),o=n=>{let s=(n.value??"").toLowerCase();switch(n.match){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"blank":return r==="";case"notBlank":return r!=="";default:return!0}};return e.length===0||(t==="or"?e.some(o):e.every(o))}function pn(i,e,t){switch(t.match){case"equals":return i===e;case"notEquals":return i!==e;case"lessThan":return i<e;case"lessThanOrEqual":return i<=e;case"greaterThan":return i>e;case"greaterThanOrEqual":return i>=e;case"inRange":return i>=e&&i<=(t.value2??e);default:return!0}}function fn(i,e){let t=i==null||i==="";if(e.match==="blank")return t;if(e.match==="notBlank")return!t;if(t)return!1;let r=typeof i=="number"?i:Number(i);if(Number.isNaN(r))return!1;let o=e.value;return o==null||Number.isNaN(o)?!1:pn(r,o,e)}function mn(i,e,t){let r=o=>fn(i,o);return e.length===0||(t==="or"?e.some(r):e.every(r))}function jt(i){if(i==null||i==="")return null;if(i instanceof Date)return isNaN(i.getTime())?null:i.getTime();if(typeof i=="number")return i;let e=Date.parse(String(i));return isNaN(e)?null:e}function gn(i,e,t){let r=jt(i),o=n=>{let s=r==null;if(n.match==="blank")return s;if(n.match==="notBlank")return!s;if(s)return!1;let a=r,l=n.value!=null?jt(n.value):null;if(l==null)return!1;switch(n.match){case"equals":return a===l;case"notEquals":return a!==l;case"lessThan":return a<l;case"greaterThan":return a>l;case"inRange":{let d=n.value2!=null?jt(n.value2):null;return d!=null?a>=l&&a<=d:a>=l}default:return!0}};return e.length===0||(t==="or"?e.some(o):e.every(o))}function yn(i,e){return e.length===0?!0:e.some(t=>t==null&&i==null||t===i)}function Wr(i,e){let t=e.type!=="set"&&e.operator==="or"?"or":"and";switch(e.type){case"text":return hn(i,e.conditions,t);case"number":return mn(i,e.conditions,t);case"date":return gn(i,e.conditions,t);case"set":return yn(i,e.values);default:return!0}}function $r(i,e,t){if(i.kind==="condition"){let o=e.get(i.colId);return o?n=>Wr(t(n,o),i.filter):()=>!0}let r=i.children.map(o=>$r(o,e,t));return o=>{let n=i.operator==="or"?r.some(s=>s(o)):r.every(s=>s(o));return i.not?!n:n}}function Yt(i,e,t,r,o){let n=new Map(i.map(d=>[d.id,d])),s=Object.entries(e).flatMap(([d,c])=>{let u=n.get(d);return u?[{column:u,filter:c}]:[]}),a=t?$r(t.root,n,o):()=>!0,l=r?.trim().toLowerCase().split(/\s+/).filter(Boolean)??[];return d=>!s.every(({column:c,filter:u})=>Wr(o(d,c),u))||!a(d)?!1:l.every(c=>i.some(u=>_r(o(d,u)).includes(c)))}var Kr=typeof Intl<"u"?new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"}):null;function vn(i,e){let t=i==null||i==="",r=e==null||e==="";return!t&&!r?null:t&&r?0:t?1:-1}function wn(i,e){let t=Number.isNaN(i),r=Number.isNaN(e);return t||r?t===r?0:t?1:-1:i-e}function bn(i,e){return i===e?0:i?1:-1}function Oe(i,e){let t=vn(i,e);if(t!==null)return t;if(typeof i=="number"&&typeof e=="number")return wn(i,e);if(i instanceof Date&&e instanceof Date)return i.getTime()-e.getTime();if(typeof i=="boolean"&&typeof e=="boolean")return bn(i,e);let r=String(i),o=String(e);return Kr?Kr.compare(r,o):r.localeCompare(o)}function Xt(i,e,t,r){let o=new Map(t.map(a=>[a.id,a])),n=e.flatMap(a=>{let l=o.get(a.colId);return l?[{column:l,compare:l.colDef.comparator??Oe,direction:a.direction}]:[]}),s=i.map(a=>({node:a,values:n.map(({column:l})=>r(a,l))}));return s.sort((a,l)=>{for(let d=0;d<n.length;d++){let c=n[d],u=c.compare(a.values[d],l.values[d],a.node,l.node);if(u!==0)return c.direction==="asc"?u:-u}return 0}),s.map(({node:a})=>a)}function He(i){return i.filter(e=>typeof e=="number"&&!isNaN(e))}var Jt={sum:i=>He(i).reduce((e,t)=>e+t,0),avg:i=>{let e=He(i);return e.length===0?null:e.reduce((t,r)=>t+r,0)/e.length},count:i=>i.length,min:i=>{let e=He(i);return e.length===0?null:Math.min(...e)},max:i=>{let e=He(i);return e.length===0?null:Math.max(...e)},first:i=>i.length>0?i[0]:null,last:i=>i.length>0?i[i.length-1]:null};function Ve(i){let e={...Jt,...i??{}};return t=>e[t]}function ee(i){if(i.reason instanceof Error)return i.reason;let e=new Error(typeof i.reason=="string"?i.reason:"Block request aborted");return e.name="AbortError",e}function Be(i){return Number.isFinite(i)?Math.max(1,Math.trunc(i)):1}var ze=class{constructor(e,t,r=4){this.maxBlocks=e;this.onEvict=t;this.maxConcurrentRequests=r;this.S=new Map;this.x=new Map;this.dn=0;this.generation=0;this.hitCount=0;this.missCount=0;this.evictionCount=0;this.ar=0;this.lr=new Set;this.maxBlocks=Be(e),this.maxConcurrentRequests=Be(r)}configure(e,t=this.maxConcurrentRequests){this.maxBlocks=Be(e),this.maxConcurrentRequests=Be(t),this.Do(),this.dr()}retain(e){this.lr=e,this.Do()}peek(e){let t=this.S.get(e);if(t)return t.touchedAt=++this.dn,t}has(e){return this.S.has(e)}invalidate(e){let t=this.x.get(e);t&&(this.x.delete(e),t.controller.abort(),t.state==="queued"&&t.reject(ee(t.controller.signal)));let r=this.S.get(e);r&&(this.S.delete(e),this.onEvict?.(e,r))}load(e,t,r,o=0){if(r?.aborted)return Promise.reject(ee(r));let n=this.peek(e);if(n)return this.hitCount++,Promise.resolve(n);let s=this.x.get(e);if(s)return this.hitCount++,s.priority=Math.max(s.priority,o),this.dr(),this.cn(e,s,r);this.missCount++;let a=new AbortController,l,d,c=new Promise((p,m)=>{l=p,d=m}),u={controller:a,promise:c,consumers:0,loader:t,priority:o,state:"queued",resolve:l,reject:d};this.x.set(e,u);let h=this.cn(e,u,r);return this.dr(),h}purge(){this.generation++,this.lr.clear();for(let e of this.x.values())e.controller.abort(),e.state==="queued"&&e.reject(ee(e.controller.signal));this.x.clear();for(let[e,t]of this.S)this.onEvict?.(e,t);this.S.clear()}snapshot(){let e=0,t=0;for(let r of this.S.values())e+=r.rows.length;for(let r of this.x.values())r.state==="active"&&t++;return{cachedBlockCount:this.S.size,loadingBlockCount:this.x.size,activeRequestCount:t,queuedRequestCount:Math.max(0,this.x.size-t),cachedRowCount:e,hitCount:this.hitCount,missCount:this.missCount,evictionCount:this.evictionCount}}dr(){for(;this.ar<this.maxConcurrentRequests;){let e,t;for(let[r,o]of this.x)o.state!=="queued"||o.controller.signal.aborted||(!t||o.priority>t.priority)&&(e=r,t=o);if(e==null||!t)return;this.ba(e,t)}}ba(e,t){t.state="active",this.ar++;let r=this.generation;this.Ca(t).then(o=>{r===this.generation&&!t.controller.signal.aborted&&(this.S.set(e,{rows:o.rows,...o.lastRow==null?{}:{lastRow:o.lastRow},touchedAt:++this.dn}),this.Do()),t.resolve(o)},t.reject).finally(()=>{this.ar=Math.max(0,this.ar-1),this.x.get(e)===t&&this.x.delete(e),this.dr()})}Ca(e){let{signal:t}=e.controller;return t.aborted?Promise.reject(ee(t)):new Promise((r,o)=>{let n=()=>o(ee(t));t.addEventListener("abort",n,{once:!0}),Promise.resolve().then(()=>e.loader(t)).then(r,o).finally(()=>{t.removeEventListener("abort",n)})})}cn(e,t,r){return t.consumers++,new Promise((o,n)=>{let s=!1,a=d=>{s||(s=!0,r?.removeEventListener("abort",l),t.consumers=Math.max(0,t.consumers-1),d())},l=()=>a(()=>{t.consumers===0&&this.x.get(e)===t&&(this.x.delete(e),t.controller.abort(r?.reason),t.state==="queued"&&t.reject(ee(t.controller.signal))),n(ee(r))});r?.addEventListener("abort",l,{once:!0}),t.promise.then(d=>a(()=>o(d)),d=>a(()=>n(d instanceof Error?d:new Error(String(d??"Block request failed")))))})}Do(){let e=Math.max(this.maxBlocks,this.lr.size+1);for(;this.S.size>e;){let t=-1,r=Number.POSITIVE_INFINITY;for(let[n,s]of this.S)this.lr.has(n)||s.touchedAt<r&&(t=n,r=s.touchedAt);if(t<0)return;let o=this.S.get(t);this.S.delete(t),this.evictionCount++,o&&this.onEvict?.(t,o)}}};function be(i,e){if(i==null||typeof i!="object")return;let t=i[e];return Array.isArray(t)?t:void 0}var _e=class{constructor(e){this.core=e;this.all=[];this.M=[];this.k=new Map;this.displayed=[];this.r=new Map;this.filterModel={};this.advancedFilterModel=null;this.quickFilter=null;this.g=new Set;this.I=new Set;this.je=[];this.Tt=new Map;this.un=[];this.y=null;this.Ye=!1;this.hn=!1;this.U=0;this.cr=null;this.Dt=null;this.ur=null;this.hr=new WeakMap;this.Rt=new WeakMap;this.he=new Map;this.Et=new Map;this.xt=0;this.pr=0;this.pe=new Map;this.ke=new Map;this.fr=new Set;this.Ie=new Map;this.fe=new ze(12,e=>this.pn(e));this.Mt=0;this.mr=null;this.Ro=!1;this.fn=0;this.N=[];this.page=1;this.pageSize=20;this.advancedFilterModel=H(e.options.advancedFilterModel)}resolveRowId(e,t,r){let o=this.core.options.resolveRowId;if(!o)return r;try{let n=o({data:e,index:t,api:this.core.getApi()});if(typeof n=="string"&&n.length>0)return n;this.core.reportError(new Error("rowKey must resolve to a non-empty identifier"),"rowKey",{index:t})}catch(n){this.core.reportError(n,"rowKey",{index:t})}return r}get w(){return this.core.options.treeData}get o(){return this.core.options.datasource!=null}get B(){return this.o&&this.core.options.datasourceMode==="block"}Xe(){if(this.o){if(this.B)return this.Je();let e=Math.max(0,this.displayed.length-this.all.length);return(this.y??this.all.length)+e}return this.displayed.length}Eo(){return this.xt}gr(){return this.pr}Ta(){return this.hn}xo(e){return!this.o||e?.aborted?Promise.resolve():(this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.core.changeTracker.clear(),this.yr(),this.y=null,this.Ye=!1,this.all=[],this.M=[],this.r.clear(),this.g.clear(),this.core.undoService.clear(),this.a(),this.core.requestUpdate({data:!0}),this.B?(this.fe.configure(this.core.options.maxBlocksInCache,this.core.options.datasourceMaxConcurrentRequests),this.vr(0,e)):this.mn(0,void 0,e))}gn(e){return this.o?this.xo(e):Promise.resolve()}Ae(e){this.hn=e,this.core.skeleton.Ae(e,this.core.getLocaleText("loading"))}mn(e,t,r){if(!this.o||this.Ye||this.y!=null&&e>=this.y)return Promise.resolve();let o=this.core.options.datasource,n=this.core.options.blockSize,s=t??e+n;if(s<=e)return Promise.resolve();let a=++this.U,l=new AbortController,d=()=>l.abort(r?.reason);return r?.addEventListener("abort",d,{once:!0}),this.cr=l,this.Ye=!0,this.Ae(!0),new Promise(c=>{let u=!1,h=0;this.ur=c;let p=g=>{u||(u=!0,r?.removeEventListener("abort",d),a===this.U&&(this.Ye=!1,this.cr=null,this.ur=null,this.Ae(!1),g!=null&&g?.name!=="AbortError"&&this.core.reportError(g,"datasource.getRows",{startRow:e,endRow:s})),c())},m=()=>{if(u||a!==this.U||l.signal.aborted||this.core.isDestroyed()){p();return}h++;let g=!1,v=y=>{if(!(g||u)){if(g=!0,a!==this.U||l.signal.aborted||this.core.isDestroyed()){p();return}if(h<=this.core.options.datasourceRetryCount){let b=this.retryDelay(h);this.Dt=setTimeout(()=>{this.Dt=null,m()},b);return}p(y??new Error("Datasource request failed"))}};try{let y=o.getRows({startRow:e,endRow:s,sortModel:this.core.columnModel.D(),filterModel:this.R(),advancedFilterModel:this.z(),quickFilterText:this.quickFilter,signal:l.signal,onSuccess:(b,C)=>{if(g||u)return;if(g=!0,a!==this.U||this.core.isDestroyed()||l.signal.aborted){p();return}let x=b??[];typeof C=="number"&&C>=0?this.y=C:x.length<s-e&&(this.y=e+x.length);let w=this.all.length===0;this.Da(x),p(),this.a(),this.core.requestUpdate({data:!0}),w&&this.core.relayout(),this.core.headerRenderer.wr()},fail:v});y&&typeof y.catch=="function"&&y.catch(v)}catch(y){v(y)}};m()})}yr(){this.U++,this.Dt!=null&&clearTimeout(this.Dt),this.Dt=null,this.cr?.abort(),this.cr=null,this.Ye=!1,this.Ae(!1),this.ur?.(),this.ur=null,this.fe.purge(),this.pe.clear(),this.ke.clear(),this.fr.clear();for(let[e,t]of this.Ie)this.r.get(e)===t&&this.r.delete(e);this.Ie.clear()}Da(e){for(let t of e){if(t==null)continue;let r=this.all.length,o=this.resolveRowId(t,r,`inf-${this.core.nextId()}`);if(this.r.has(o)){this.core.reportError(new Error(`Duplicate row id: ${o}`),"datasource.getRows",{rowId:o});continue}let n={id:o,data:t,rowIndex:-1,selected:this.core.selectionService.isSelected(o)};this.all.push(n),this.r.set(o,n),this.M.push(n)}}vr(e,t,r=0){if(!this.B||e<0)return Promise.resolve();if(t?.aborted)return Promise.reject(this.yn(t.reason));let o=this.core.options.blockSize,n=this.U,s=e*o;if(s>=this.Je())return Promise.resolve();let a=this.y==null?s+o:Math.min(this.y,s+o),l=this.fe.load(e,d=>this.Ra(s,a,d),t,r);return this.Ae(this.all.length===0&&this.fe.snapshot().loadingBlockCount>0),l.then(d=>{n!==this.U||t?.aborted||this.core.isDestroyed()||!this.B||!this.fe.has(e)||this.fr.has(e)||(this.Ea(e,d),this.a(),this.core.requestUpdate({data:!0}),this.core.headerRenderer.wr(),n===this.U&&!this.core.isDestroyed()&&this.vn(this.core.bodyRenderer.Mo().lastExcl-1))}).catch(d=>{throw d?.name!=="AbortError"&&this.core.reportError(d,"datasource.getRows",{startRow:s,endRow:a}),d}).finally(()=>{n===this.U&&this.Ae(this.all.length===0&&this.fe.snapshot().loadingBlockCount>0)})}Ra(e,t,r){let o=this.core.options.datasource;return new Promise((n,s)=>{let a=0,l=null,d=!1,c=p=>{d||(d=!0,l!=null&&clearTimeout(l),r.removeEventListener("abort",u),s(p instanceof Error?p:new Error(typeof p=="string"?p:"Datasource request failed")))},u=()=>c(this.yn(r.reason));r.addEventListener("abort",u,{once:!0});let h=()=>{if(d)return;if(r.aborted||this.core.isDestroyed()){u();return}a++;let p=!1,m=g=>{if(!(p||d)){if(p=!0,r.aborted||this.core.isDestroyed()){u();return}if(a<=this.core.options.datasourceRetryCount){let v=this.retryDelay(a);l=setTimeout(()=>{l=null,h()},v)}else c(g)}};try{let g=o.getRows({startRow:e,endRow:t,sortModel:this.core.columnModel.D(),filterModel:this.R(),advancedFilterModel:this.z(),quickFilterText:this.quickFilter,signal:r,onSuccess:(v,y)=>{p||d||(p=!0,d=!0,r.removeEventListener("abort",u),n({rows:v??[],...typeof y=="number"&&y>=0?{lastRow:y}:{}}))},fail:m});g&&typeof g.catch=="function"&&g.catch(m)}catch(g){m(g)}};h()})}Ea(e,t){let r=this.core.options.blockSize,o=e*r;this.pn(e),typeof t.lastRow=="number"&&t.lastRow>=0?this.y=t.lastRow:t.rows.length<r&&(this.y=o+t.rows.length),t.rows.forEach((n,s)=>{if(n==null)return;let a=o+s;if(this.y!=null&&a>=this.y)return;let l=this.resolveRowId(n,a,`block-${a}`),d=this.Ie.get(l),c=this.r.get(l);if(c&&c!==d&&c.rowIndex!==a){this.core.reportError(new Error(`Duplicate row id: ${l}`),"datasource.getRows",{rowId:l});return}let u=d??{id:l,data:n,rowIndex:a,selected:this.core.selectionService.isSelected(l)};u.rowIndex=a,u.selected=this.core.selectionService.isSelected(l),this.Ie.delete(l),this.pe.set(a,u),this.ke.delete(a),this.r.set(l,u),this.Rt.set(u,a+1)}),this.wn(),this.fr.add(e)}pn(e){this.fr.delete(e);let t=this.core.options.blockSize,r=e*t,o;for(let n=r;n<r+t;n++){let s=this.pe.get(n);s&&(o??(o=new Set(this.core.changeTracker.getDirtyRowIds())),this.pe.delete(n),o.has(s.id)?this.Ie.set(s.id,s):this.r.get(s.id)===s&&this.r.delete(s.id))}this.wn()}wn(){this.all=[...this.pe.entries()].sort(([e],[t])=>e-t).map(([,e])=>e),this.M=this.all}Je(){if(this.y!=null)return this.y;if(this.core.options.datasourceRowCount!=null)return this.core.options.datasourceRowCount;if(this.pe.size===0)return this.core.options.blockSize;let e=0;for(let t of this.pe.keys())e=Math.max(e,t+1);return e+this.core.options.blockSize}xa(e){let t=this.ke.get(e);if(!t&&(t={id:`__mach_loading_${e}`,data:null,rowIndex:e,selected:!1,loading:!0},this.ke.set(e,t),this.ke.size>2e3)){let r=this.ke.keys().next().value;r!=null&&this.ke.delete(r)}return t}yn(e){if(e instanceof Error)return e;let t=new Error(typeof e=="string"?e:"Operation aborted");return t.name="AbortError",t}retryDelay(e){let t=Math.min(this.core.options.datasourceRetryDelay*2**Math.max(0,e-1),3e4),r=this.core.options.datasourceRetryJitter;return Math.max(0,Math.round(t*(1+(Math.random()*2-1)*r)))}Ma(e){if(this.B){this.vn(e);return}if(!this.o||this.Ye)return;let t=this.all.length;if(this.y!=null&&t>=this.y)return;let r=this.core.options.infiniteBufferRows;if(e+r<t&&e<t)return;let o=this.core.options.blockSize,n=this.y==null?t+o:Math.min(this.y,t+o);this.mn(t,n)}vn(e){if(e<0)return;this.bn();let t=this.core.options.blockSize,r=Math.floor(e/t),o=Math.floor(this.core.bodyRenderer.Mo().first/t),n=this.core.options.blockPrefetch,s=r<this.fn?-1:1;this.fn=r;for(let a=o;a<r;a++)this.vr(a,void 0,n+2).catch(()=>{});for(let a=0;a<=n;a++){let l=a===0?[r]:[r+s*a,r-s*a];for(let d of l)d<0||d*t>=this.Je()||this.vr(d,void 0,n-a+1).catch(()=>{})}}ie(){return this.gn().catch(()=>{})}Sa(){return this.yr(),this.o?this.xo().catch(()=>{}):(this.y=null,this.me(this.core.options.rowData),this.core.requestUpdate({data:!0}),Promise.resolve())}destroy(){this.yr(),this.Cn(),this.So(),this.all=this.M=this.displayed=this.N=[],this.r.clear(),this.k.clear(),this.Tt.clear(),this.un=[],this.g.clear(),this.I.clear(),this.je=[],this.core.options.dataProcessor?.destroy?.()}ko(e,t,r){if(!this.B)return Promise.resolve();this.bn();let o=this.core.options.blockSize,n=Math.max(0,Math.trunc(e)),s=Math.min(this.Je(),Math.max(n,Math.trunc(t))),a=Math.floor(n/o),l=Math.max(a,Math.floor(Math.max(n,s-1)/o)),d=[];for(let c=a;c<=l;c++)d.push(this.vr(c,r,100));return Promise.all(d).then(()=>{})}Io(){this.B&&(this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.core.changeTracker.clear(),this.yr(),this.core.undoService.clear(),this.all=[],this.M=[],this.r.clear(),this.a(),this.core.requestUpdate({data:!0}))}Ao(){return this.fe.snapshot()}bn(){let e=new Set(this.core.changeTracker.getDirtyRowIds());for(let[l,d]of this.Ie)e.has(l)||(this.Ie.delete(l),this.r.get(l)===d&&this.r.delete(l));let t=this.core.options.blockSize,r=new Set,{first:o,lastExcl:n}=this.core.bodyRenderer.Mo();for(let l=o;l<n;l+=t)r.add(Math.floor(l/t));n>o&&r.add(Math.floor((n-1)/t));let s=this.core.bodyRenderer.c;s&&r.add(Math.floor(s.rowIndex/t));let a=this.core.editingService.ka();a!=null&&r.add(Math.floor(a/t)),this.fe.retain(r)}me(e){this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.Cn(),this.core.changeTracker.clear();let t=this.core.options.resolveRowId,r=this.core.options.childrenKey,o=[],n=[],s=new Map,a=new Map,l=0,d=(c,u,h)=>{let p=l++,m=this.resolveRowId(c,p,`auto-${p}`);if(s.has(m))return this.core.reportError(new Error(`Duplicate row id: ${m}`),"rowData",{rowId:m,index:p}),null;let g=this.w?be(c,r):void 0,v={id:m,data:c,rowIndex:-1,selected:!1,treeChildrenLoaded:Array.isArray(g)};if(this.hr.set(v,u),o.push(v),s.set(m,v),h!=null){let y=a.get(h)??[];y.push(m),a.set(h,y)}else n.push(v);if(this.w&&Array.isArray(g))for(let y of g)y!=null&&d(y,u+1,m);return v};(e??[]).forEach(c=>{c!=null&&d(c,0,null)}),this.all=o,this.M=n,this.k=a,this.r=s,this.core.undoService.clear();for(let c of[...this.g])s.has(c)||this.g.delete(c);if(this.core.options.defaultExpandAll)for(let c of o)this.Tn(c.id)>0&&this.g.add(c.id);this.core.selectionService.onRowsRebuilt(t!=null),this.a()}St(e){return this.k.get(e)??[]}Tn(e){return this.k.get(e)?.length??0}Lo(e){return this.Tn(e)>0}isTreeRowLoading(e){return this.r.get(e)?.treeLoading===!0}Cn(){for(let e of this.he.values())e.abort();this.he.clear(),this.Et.clear()}loadTreeChildren(e,t=!1){let r=this.r.get(e),o=this.core.options.loadTreeChildren;if(!this.w||!r?.data||!o)return Promise.resolve([]);if(!t&&r.treeChildrenLoaded)return Promise.resolve(this.St(e).flatMap(l=>{let d=this.r.get(l)?.data;return d==null?[]:[d]}));let n=this.Et.get(e);if(n&&!t)return n;this.he.get(e)?.abort();let s=new AbortController;this.he.set(e,s),r.treeLoading=!0,r.treeLoadError=void 0,this.core.requestUpdate({data:!0});let a=Promise.resolve().then(()=>o({data:r.data,node:r,api:this.core.getApi(),signal:s.signal})).then(l=>{if(s.signal.aborted||this.core.isDestroyed())return[];if(!Array.isArray(l))throw new TypeError("[MachTable] loadTreeChildren must resolve to an array.");return this.Ia(r,l),r.treeChildrenLoaded=!0,r.treeLoadError=void 0,this.core.emit("treeChildrenLoaded",{rowId:e,rowNode:r,children:l}),l}).catch(l=>{if(s.signal.aborted||l?.name==="AbortError")return[];throw r.treeLoadError=l,r.treeChildrenLoaded=!1,this.core.reportError(l,"treeData.loadChildren",{rowId:e}),this.core.emit("treeChildrenLoadFailed",{rowId:e,rowNode:r,error:l}),l}).finally(()=>{this.he.get(e)===s&&(this.he.delete(e),this.Et.delete(e),r.treeLoading=!1,this.core.requestUpdate({data:!0}))});return this.Et.set(e,a),a}Ia(e,t){let r=new Set,o=[...this.St(e.id)];for(;o.length>0;){let s=o.pop();r.has(s)||(r.add(s),o.push(...this.St(s)))}this.Aa(t,r);for(let s of r)this.he.get(s)?.abort(),this.he.delete(s),this.Et.delete(s),this.k.delete(s),this.r.delete(s),this.g.delete(s);this.k.delete(e.id);let n=this.Po(e)+1;for(let s of t)s!=null&&this.Go(e,s,n);this.Dn(),this.core.selectionService.onRowsRebuilt(this.core.options.resolveRowId!=null),this.a(),this.core.requestUpdate({data:!0})}Aa(e,t){let r=this.core.options.resolveRowId,o=r?new Set([...this.r.keys()].filter(l=>!t.has(l))):null,n=new WeakSet,s=[...e],a=0;for(;s.length>0;){let l=s.pop();if(l==null)continue;if(typeof l=="object"){if(n.has(l))throw new TypeError("[MachTable] Lazy tree children contain a cyclic object graph.");n.add(l)}if(r&&o){let c=r({data:l,index:a++,api:this.core.getApi()});if(typeof c!="string"||c.length===0)throw new TypeError("[MachTable] rowKey must resolve to a non-empty identifier for lazy tree children.");if(o.has(c))throw new Error(`Duplicate row id: ${c}`);o.add(c)}let d=be(l,this.core.options.childrenKey);d&&s.push(...d)}}kt(e,t=!0){let r=this.core.options.resolveRowId,o=[],n=[];if(e.remove?.length){let a=new Set,l=new Set,d=u=>{if(r){let p=[this.resolveRowId(u,-1,`__missing_remove_${this.core.nextId()}`)];for(;p.length>0;){let m=p.pop();if(!a.has(m)){a.add(m);for(let g of this.k.get(m)??[])p.push(g)}}}else{let h=[u];for(;h.length>0;){let p=h.pop();l.add(p);let m=this.w?be(p,this.core.options.childrenKey):void 0;if(m)for(let g of m)h.push(g)}}};e.remove.forEach(d),this.all=this.all.filter(u=>{let h=a.has(u.id)||u.data!=null&&l.has(u.data);return h&&(n.push(u.id),this.r.delete(u.id),this.k.delete(u.id)),!h});let c=new Set(this.all);this.M=this.M.filter(u=>c.has(u))}if(e.update?.length)for(let a of e.update){let l;r?l=this.r.get(this.resolveRowId(a,-1,`__missing_update_${this.core.nextId()}`)):l=this.all.find(d=>d.data===a),l&&(l.data=a,n.push(l.id),this.core.bodyRenderer.br(l),o.push(l))}if(e.add?.length){let a=e.addIndex!=null?Math.max(0,Math.min(e.addIndex,this.M.length)):this.M.length,l=[];e.add.forEach((d,c)=>{let u=this.resolveRowId(d,a+c,`add-${this.core.nextId()}`);if(this.r.has(u)){this.core.reportError(new Error(`Duplicate row id: ${u}`),"transaction.add",{rowId:u});return}let h={id:u,data:d,rowIndex:-1,selected:!1};this.r.set(u,h),this.hr.set(h,0);let p=this.w?be(d,this.core.options.childrenKey):void 0;if(p)for(let m of p)m!=null&&this.Go(h,m,1);l.push(h)}),this.M.splice(a,0,...l),this.Dn()}let s=this.La(e);return t&&(s?this.a():o.length>0&&this.Rn()),this.core.changeTracker.clearRows(n),{pipelineChanged:s,updatedRowIds:o.map(a=>a.id)}}Pa(e){if(e.length===0)return{pipelineChanged:!1,updatedRowIds:[]};let t=!1,r=new Set;for(let o of e){let n=this.kt(o,!1);t||(t=n.pipelineChanged);for(let s of n.updatedRowIds)r.add(s)}return t?this.a():r.size>0&&this.Rn(),{pipelineChanged:t,updatedRowIds:[...r]}}La(e){return e.add?.length||e.remove?.length?!0:e.update?.length?this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0||!this.core.options.manualFiltering&&this.Cr()||!this.core.options.manualSorting&&this.core.columnModel.D().length>0||this.core.options.getRowHeight?!0:this.core.columnModel.e().some(t=>t.colDef.autoHeight===!0||t.colDef.autoRowSpan===!0||t.colDef.rowSpan!=null):!1}Rn(){this.core.emit("modelUpdated",{rowCount:this.N.length})}Go(e,t,r){let o=this.resolveRowId(t,-1,`add-${this.core.nextId()}`);if(this.r.has(o)){this.core.reportError(new Error(`Duplicate row id: ${o}`),"transaction.add",{rowId:o});return}let n=be(t,this.core.options.childrenKey),s={id:o,data:t,rowIndex:-1,selected:!1,treeChildrenLoaded:Array.isArray(n)};this.r.set(o,s),this.hr.set(s,r);let a=this.k.get(e.id)??[];if(a.push(s.id),this.k.set(e.id,a),!!n)for(let l of n)l!=null&&this.Go(s,l,r+1)}Dn(){this.all=[];let e=t=>{this.all.push(t),this.r.has(t.id)||this.r.set(t.id,t);for(let r of this.k.get(t.id)??[]){let o=this.r.get(r);o&&e(o)}};for(let t of this.M)e(t)}It(e){let t=JSON.stringify(this.filterModel),r=new Set(this.core.columnModel.G().map(o=>o.id));return this.filterModel=U(e,r),JSON.stringify(this.filterModel)!==t}R(){return{...this.filterModel}}Ze(e){let t=new Set(this.core.columnModel.G().map(n=>n.id)),r=H(e,t),o=JSON.stringify(this.advancedFilterModel);return this.advancedFilterModel=r,this.core.options.advancedFilterModel=r,JSON.stringify(r)!==o}z(){return H(this.advancedFilterModel)}Qe(e){let t=e!=null&&e.trim()!==""?e:null;return t===this.quickFilter?!1:(this.quickFilter=t,!0)}At(){return this.quickFilter}Cr(){return Object.keys(this.filterModel).length>0||this.advancedFilterModel!=null||this.quickFilter!=null}a(){let e=this.core.performanceMonitor.start(),t=this.core.columnModel.e(),r=(s,a)=>this.core.getCellValue(s,a);if(this.o){this.Ga(e);return}if(this.Na(e))return;let o;if(this.w)o=this.Fa(t,r);else{o=this.all,this.Cr()&&!this.core.options.manualFiltering&&(o=o.filter(Yt(t,this.filterModel,this.advancedFilterModel,this.quickFilter,r)));let a=this.core.columnModel.D();if(a.length>0&&!this.core.options.manualSorting)try{o=Xt(o,a,t,r)}catch(d){this.core.reportError(d,"comparator",{sortModel:a})}let l=this.core.columnModel.re();if(l.length>0)o=this.Oa(o,l);else if(this.core.options.masterDetail){let d=[];for(let c of o)d.push(c),this.g.has(c.id)&&this.isRowExpandable(c)&&d.push({id:`__detail__${c.id}`,data:c.data,rowIndex:-1,selected:!1,isDetail:!0,masterId:c.id});o=d}}for(let s of this.all)s.rowIndex=-1;let n=0;o.forEach((s,a)=>{s.rowIndex=a,!s.isDetail&&!s.isGroup&&(n++,this.Rt.set(s,n))}),this.N=o,this.et(),this.En(r),this.core.emit("modelUpdated",{rowCount:o.length}),this.core.performanceMonitor.recordModel(e)}Ga(e){this.all.forEach((t,r)=>{this.B||(t.rowIndex=r),this.Rt.set(t,this.B?t.rowIndex+1:r+1)}),this.displayed=this.all,this.N=this.all,this.Tt.clear(),this.xt++,this.core.emit("modelUpdated",{rowCount:this.all.length}),this.core.performanceMonitor.recordModel(e)}Na(e){let t=this.Ro;return this.Ro=!1,!t&&this.Ha()?(this.Va(e),!0):(this.So(),!1)}Ha(){if(!this.core.options.dataProcessor||this.all.length<this.core.options.dataProcessorMinRows||this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0)return!1;let e=!this.core.options.manualFiltering&&this.Cr(),t=!this.core.options.manualSorting&&this.core.columnModel.D().length>0;return e||t}Va(e){this.So();let t=this.core.options.dataProcessor;if(!t)return;let r=++this.Mt,o=new AbortController;this.mr=o;let n=this.core.columnModel.e(),s=this.all.flatMap(d=>d.data==null?[]:[{id:d.id,data:d.data}]),a=!this.core.options.manualFiltering,l=!this.core.options.manualSorting;Promise.resolve().then(()=>t.process({rows:s,columns:n.map(d=>({colId:d.id,...d.colDef.field?{field:d.colDef.field}:{}})),sortModel:l?this.core.columnModel.D():[],filterModel:a?this.R():{},advancedFilterModel:a?this.z():null,quickFilterText:a?this.quickFilter:null,signal:o.signal})).then(d=>{if(r!==this.Mt||o.signal.aborted||this.core.isDestroyed())return;let c=new Set,u=[];for(let p of d.rowIds){if(c.has(p))continue;c.add(p);let m=this.r.get(p);m&&!m.isDetail&&!m.isGroup&&u.push(m)}for(let p of this.all)p.rowIndex=-1;u.forEach((p,m)=>{p.rowIndex=m,this.Rt.set(p,m+1)}),this.N=u,this.et();let h=(p,m)=>this.core.getCellValue(p,m);this.En(h),this.core.emit("modelUpdated",{rowCount:u.length}),this.core.performanceMonitor.recordModel(e),this.core.requestUpdate({data:!0})}).catch(d=>{r!==this.Mt||o.signal.aborted||this.core.isDestroyed()||(this.core.reportError(d,"dataProcessor.process"),this.Ro=!0,this.a(),this.core.requestUpdate({data:!0}))}).finally(()=>{r===this.Mt&&(this.mr=null)})}So(){this.Mt++,this.mr?.abort(),this.mr=null}get j(){return this.core.options.paginationEnabled&&!this.o}et(){if(!this.j){this.displayed=this.N,this.xt++;return}let e=this.Lt(),t=this.getPageCount();if(this.page>t&&(this.page=t),this.page<1&&(this.page=1),this.core.options.paginationPage=this.page,this.core.options.paginationMode==="server"){this.N.forEach((n,s)=>{n.rowIndex=s}),this.displayed=this.N,this.xt++;return}let r=(this.page-1)*e,o=this.N.slice(r,r+e);o.forEach((n,s)=>{n.rowIndex=s}),this.displayed=o,this.xt++}Lt(){return this.pageSize=this.core.options.paginationPageSize,Math.max(1,this.pageSize)}Pt(){return this.j?this.page:1}getTotalRowCount(){return this.o?this.Xe():this.j&&this.core.options.paginationMode==="server"?this.core.options.paginationTotal:this.N.length}getPageCount(){return this.j?Math.max(1,Math.ceil(this.getTotalRowCount()/this.Lt())):1}xn(){return this.N}setPage(e,t=!1){if(!this.j)return;let r=this.getPageCount(),o=Math.max(1,Math.min(Math.round(e)||1,r));o!==this.page&&(this.page=o,this.core.options.paginationPage=o,this.et(),this.core.requestUpdate({data:!0}),this.core.bodyRenderer.tt(0,"top"),t||this.Tr())}setPageSize(e){if(!this.j)return;let t=Math.max(1,Math.round(e)||this.Lt()),r=(this.page-1)*this.Lt();this.core.options.paginationPageSize=t,this.pageSize=t,this.page=Math.floor(r/t)+1,this.core.options.paginationPage=this.page,this.et(),this.core.requestUpdate({data:!0}),this.Tr()}Mn(e,t){this.pageSize=Math.max(1,Math.round(t)||1),this.core.options.paginationPageSize=this.pageSize,this.page=Math.max(1,Math.round(e)||1),this.core.options.paginationPage=this.page}Dr(e){this.core.options.paginationEnabled!==e&&(this.core.options.paginationEnabled=e&&!this.o,this.core.options.paginationEnabled&&(this.page=1),this.et(),this.core.requestUpdate({data:!0}),this.Tr())}Ba(){this.j&&(this.page=this.core.options.paginationMode==="server"?this.core.options.paginationPage:1,this.et(),this.core.requestUpdate({data:!0}),this.Tr())}Tr(){this.core.emit("paginationChanged",{page:this.Pt(),pageSize:this.Lt(),pageCount:this.getPageCount(),total:this.getTotalRowCount()})}Fa(e,t){let r=this.core.options.manualSorting?[]:this.core.columnModel.D(),o=new Map,n=this.Cr()&&!this.core.options.manualFiltering,s=Yt(e,this.filterModel,this.advancedFilterModel,this.quickFilter,t),a=c=>{let u=o.get(c.id);if(u!==void 0)return u;let h=!0;if(n){h=s(c);for(let p of this.k.get(c.id)??[]){let m=this.r.get(p);m&&a(m)&&(h=!0)}}return o.set(c.id,h),h},l=[],d=c=>{let u=c;r.length>0&&(u=Xt(c,r,e,t));for(let h of u)if(a(h)&&(l.push(h),this.g.has(h.id))){let p=(this.k.get(h.id)??[]).map(m=>this.r.get(m)).filter(m=>m!=null);d(p)}};return d(this.M),l}za(){let e=this.un,t=0;for(let r of this.displayed)!r.isDetail&&!r.isGroup&&(e[t++]=r);return e.length=t,e}_a(e,t,r,o){let n=t.colDef.rowSpan;if(!n)return 1;try{let s=n({api:this.core.getApi(),colDef:t.colDef,column:t,node:e,data:e.data,value:r,rowIndex:e.rowIndex});return Math.max(1,Math.min(Math.round(s)||1,o))}catch(s){return this.core.reportError(s,"rowSpan",{colId:t.id,rowId:e.id}),1}}Wa(e,t,r,o,n){if(!r.colDef.autoRowSpan||o==null||o==="")return 1;let s=1;for(;t+s<e.length&&Oe(o,n(e[t+s],r))===0;)s++;return s}$a(e,t,r){let o=new Int32Array(e.length),n=0;for(;n<e.length;){let s=e[n],a=r(s,t),l=t.colDef.rowSpan?this._a(s,t,a,e.length-n):this.Wa(e,n,t,a,r);o[n]=l;for(let d=1;d<l;d++)o[n+d]=-1;n+=l}return o}En(e){if(this.Tt.clear(),this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0)return;let t=this.core.columnModel.e().filter(o=>o.colDef.rowSpan!=null||o.colDef.autoRowSpan===!0);if(t.length===0)return;let r=this.za();if(r.length!==0)for(let o of t)this.Tt.set(o.id,this.$a(r,o,e))}Ka(e){return this.Tt.get(e)}Sn(e){return this.Rt.get(e)??0}Po(e){return this.hr.get(e)??0}Oa(e,t){let r=Ve(this.core.options.aggFuncs),o=this.core.columnModel.ya();this.je=[];let n=a=>{let l={};for(let d of o){let c=r(d.colDef.aggFunc);if(c)try{l[d.id]=c(a.map(u=>this.core.getCellValue(u,d)))}catch(u){this.core.reportError(u,"aggFunc",{colId:d.id,aggFunc:d.colDef.aggFunc}),l[d.id]=null}}return l},s=(a,l,d)=>{if(l>=t.length)return{display:a,leaves:a};let c=t[l],u=new Map,h=[];for(let g of a){let v=this.core.getCellValue(g,c),y=v==null?"(\u7A7A)":String(v),b=u.get(y);b||(b=[],u.set(y,b),h.push(y)),b.push(g)}h.sort((g,v)=>g.localeCompare(v,void 0,{numeric:!0,sensitivity:"base"}));let p=[],m=[];for(let g of h){let v=u.get(g),y=`${d}/g${l}:${g}`;this.je.push(y);let b=s(v,l+1,y),C={id:y,data:null,rowIndex:-1,selected:!1,isGroup:!0,groupLevel:l,groupKey:g,leafNodes:b.leaves,aggValues:n(b.leaves)};p.push(C),this.I.has(y)&&p.push(...b.display),m.push(...b.leaves)}return{display:p,leaves:m}};return s(e,0,"").display}isRowExpandable(e){if(this.w){if(this.Lo(e.id)||e.treeLoading)return!0;if(e.treeChildrenLoaded||!e.data||!this.core.options.loadTreeChildren)return!1;let r=this.core.options.isTreeRowExpandable;if(!r)return!1;try{return r({data:e.data,node:e,api:this.core.getApi()})}catch(o){return this.core.reportError(o,"isTreeRowExpandable",{rowId:e.id}),!1}}if(!this.core.options.masterDetail)return!1;let t=this.core.options.isRowExpandable;if(t)try{return t({data:e.data,node:e,api:this.core.getApi()})}catch(r){return this.core.reportError(r,"isRowExpandable",{rowId:e.id}),!1}return!0}isRowExpanded(e){return this.g.has(e)}qa(){return[...this.g]}Ua(){return[...this.I]}ja(e,t){this.g=new Set(e.filter(r=>this.r.has(r))),this.I=new Set(t)}No(e){return this.Fo(e,!0)}Oo(e){return this.Fo(e,!1)}toggleDetail(e){return this.Fo(e,!this.g.has(e))}Fo(e,t){let r=this.r.get(e);return!r||t&&!this.isRowExpandable(r)?!1:(t===this.g.has(e)||(t?this.g.add(e):this.g.delete(e),this.a(),this.core.requestUpdate({data:!0}),this.core.emit("detailToggled",{rowId:e,rowNode:r,expanded:t}),t&&this.w&&!this.Lo(e)&&!r.treeLoading&&this.loadTreeChildren(e).catch(()=>{})),t)}Ho(){let e=!1;for(let t of this.all)!this.g.has(t.id)&&this.isRowExpandable(t)&&(this.g.add(t.id),e=!0);e&&(this.a(),this.core.requestUpdate({data:!0}))}Vo(){this.g.size!==0&&(this.g.clear(),this.a(),this.core.requestUpdate({data:!0}))}Bo(e){return this.setGroupExpanded(e,!this.I.has(e))}isGroupExpanded(e){return this.I.has(e)}uh(e){return this.displayed.find(t=>t.isGroup&&t.id===e)}zo(){if(this.je.length===0)return;let e=!1;for(let t of this.je)this.I.has(t)||(this.I.add(t),e=!0);e&&(this.a(),this.core.requestUpdate({data:!0}))}_o(){this.I.size!==0&&(this.I.clear(),this.a(),this.core.requestUpdate({data:!0}))}setGroupExpanded(e,t){return!this.je.includes(e)||t===this.I.has(e)||(t?this.I.add(e):this.I.delete(e),this.a(),this.core.requestUpdate({data:!0})),t}kn(){return!this.w&&!this.o&&!this.core.options.dataProcessor&&this.core.options.paginationMode!=="server"&&this.core.columnModel.D().length===0&&this.core.columnModel.re().length===0}In(e,t){if(!this.kn()||!Number.isInteger(e)||!Number.isInteger(t))return!1;let r=this.i(e),o=this.i(t);if(!r||!o||r.isDetail||o.isDetail||r.isGroup||o.isGroup)return!1;let n=this.all.indexOf(r),s=this.all.indexOf(o);return n<0||s<0||n===s?!1:(this.all.splice(n,1),this.all.splice(s,0,r),this.a(),this.core.requestUpdate({data:!0}),!0)}_(){return this.all}Ya(){return this.M}ge(){return this.displayed}f(){return this.B?this.Je():this.displayed.length}i(e){return this.B?e<0||e>=this.Je()?void 0:this.pe.get(e)??this.xa(e):this.displayed[e]}T(e){return this.r.get(e)}Wo(e){this.all.forEach(e)}$o(e){let t=0;for(let r of this.N)r.isDetail||r.isGroup||e(r,t++)}};var We=class{constructor(e){this.core=e;this.h=new Set;this.ne=null;this.Gt=new Set}isSelected(e){return this.h.has(e)}isIndeterminate(e){return this.Gt.has(e)}isSelectable(e){if(e.loading)return!1;let t=this.Xa(e),r=t?.colDef.selectable;if(!t||!r)return!0;try{return r({api:this.core.getApi(),colDef:t.colDef,column:t,node:e,data:e.data,value:this.core.getCellValue(e,t),rowIndex:e.rowIndex})}catch(o){return this.core.reportError(o,"selectable",{rowId:e.id,colId:t?.id}),!1}}Xa(e){if(!(e.isGroup||e.isDetail))return this.core.columnModel.e().find(t=>t.hasCheckbox&&t.colDef.selectable!=null)}getSelectedNodes(){return this.core.rowModel._().filter(e=>this.h.has(e.id))}getSelectedRows(){return this.getSelectedNodes().filter(e=>e.data!=null).map(e=>e.data)}getSelectedIds(){return[...this.h]}restoreSelection(e){let t=new Set(e),r=this.core.rowModel._().filter(o=>t.has(o.id)&&!o.isDetail&&!o.isGroup).map(o=>({node:o,selected:!0}));this.W(r,!0)}onRowsRebuilt(e){if(!e)this.h.clear(),this.ne=null;else{let t=new Set(this.core.rowModel._().map(r=>r.id));for(let r of[...this.h])t.has(r)||this.h.delete(r);this.ne!=null&&!t.has(this.ne)&&(this.ne=null)}for(let t of this.core.rowModel._())t.selected=this.h.has(t.id);this.An()}getGroupSelectionState(e){let t=e.leafNodes??[];if(t.length===0)return{all:!1,some:!1};let r=0,o=0;for(let n of t)this.isSelectable(n)&&(r++,this.h.has(n.id)&&o++);return r===0?{all:!1,some:!1}:{all:o===r,some:o>0}}setGroupSelected(e,t){let r=(e.leafNodes??[]).filter(o=>this.isSelectable(o));r.length!==0&&this.W(r.map(o=>({node:o,selected:t})))}setNodeSelected(e,t,r=!1){this.W([{node:e,selected:t,clearOthers:r}])}selectNodeById(e,t=!0,r=!0){let o=this.core.rowModel.T(e);o&&this.setNodeSelected(o,t,r)}Ja(e,t){let r=t==="single";this.W([{node:e,selected:r?!0:!e.selected,clearOthers:r}]),this.ne=e.id}Za(e,t,r){return!r||!t.ctrlKey&&!t.metaKey?!1:(this.W([{node:e,selected:!e.selected}]),this.ne=e.id,!0)}Qa(e,t,r){if(!r||!t.shiftKey||this.ne==null)return!1;let o=this.core.rowModel.T(this.ne);if(!o||o.rowIndex<0||e.rowIndex<0)return!1;let n=Math.min(o.rowIndex,e.rowIndex),s=Math.max(o.rowIndex,e.rowIndex),a=[];for(let l=n;l<=s;l++){let d=this.core.rowModel.i(l);d&&!d.isDetail&&!d.isGroup&&this.isSelectable(d)&&a.push({node:d,selected:!0})}return this.W(a),!0}onRowClick(e,t,r){let o=this.core.options.rowSelection;if(o==="none"||!this.isSelectable(e))return;if(r){this.Ja(e,o);return}let n=o==="multiple";this.Za(e,t,n)||this.Qa(e,t,n)||(this.W([{node:e,selected:!0,clearOthers:!0}]),this.ne=e.id)}selectAll(e=!0){let t=this.core.options.rowSelection;if(t==="none")return;let o=(e?this.core.rowModel.ge():this.core.rowModel._()).filter(n=>!n.isDetail&&!n.isGroup&&this.isSelectable(n));if(o.length!==0){if(t==="single"){this.W([{node:o[0],selected:!0,clearOthers:!0}]);return}this.W(o.map(n=>({node:n,selected:!0})))}}deselectAll(){this.W([],!0)}isSelectAllActive(){let t=this.core.rowModel.ge().filter(r=>!r.isDetail&&!r.isGroup).filter(r=>this.isSelectable(r));if(t.length===0)return!1;if(this.core.rowModel.o){let r=this.core.rowModel.Xe();if(t.length<r)return!1}return t.every(r=>this.h.has(r.id))}isSelectAllIndeterminate(){let t=this.core.rowModel.ge().filter(o=>!o.isDetail&&!o.isGroup).filter(o=>this.isSelectable(o)),r=t.reduce((o,n)=>o+(this.h.has(n.id)?1:0),0);if(r===0)return!1;if(this.core.rowModel.o){let o=this.core.rowModel.Xe();if(t.length<o)return!0}return r>0&&r<t.length}applySelectionPublic(e,t=!1){this.W(e,t)}tl(e,t,r){!t&&!e.some(o=>o.clearOthers)||(this.h=t?new Set:new Set(e.filter(o=>o.selected).flatMap(o=>r?this.Ln(o.node):[o.node.id])))}rl(e,t){for(let r of e){if(!this.isSelectable(r.node))continue;let o=t?this.Ln(r.node):[r.node.id];for(let n of o)r.selected?this.h.add(n):this.h.delete(n)}}ol(e){let t=new Set;for(let r of new Set([...e,...this.h]))e.has(r)!==this.h.has(r)&&t.add(r);return t}il(e,t,r){let o=[],n=new Set([...e,...r,...this.Gt]);for(let s of this.core.rowModel._()){let a=this.h.has(s.id);s.selected=a,(n.has(s.id)||t.get(s.id)!==a)&&s.rowIndex>=0&&o.push(s.rowIndex)}return o}W(e,t=!1){let r=new Set(this.h),o=this.core.rowModel.w&&this.core.options.autoCheckedChildren;this.tl(e,t,o),this.rl(e,o);let n=this.ol(r),s=new Map;for(let d of this.core.rowModel._())s.set(d.id,d.selected);let a=new Set(this.Gt);this.An();let l=this.il(n,s,a);n.size>0&&(this.core.bodyRenderer.ye(l),this.core.headerRenderer.wr(),this.core.emit("selectionChanged",{selectedNodes:this.getSelectedNodes(),selectedRows:this.getSelectedRows()}))}Ln(e){let t=[e.id],r=o=>{for(let n of this.core.rowModel.St(o))t.push(n),r(n)};return r(e.id),t}An(){if(this.Gt.clear(),!this.core.rowModel.w)return;let e=t=>{let r=this.core.rowModel.St(t);if(r.length===0)return{all:this.h.has(t),some:this.h.has(t)};let o=!0,n=!1;for(let s of r){let a=e(s);a.all?n=!0:(a.some&&(n=!0),o=!1)}return n&&!o&&this.Gt.add(t),o?this.h.add(t):this.h.delete(t),{all:o,some:n}};for(let t of this.core.rowModel.Ya())e(t.id);for(let t of this.core.rowModel._())t.selected=this.h.has(t.id)}};var $e=class{constructor(e){this.core=e;this.active=null;this.A=0;this.ve=0;this.Y=null;this.Le=null;this.we=e=>{let t=this.qo(e);t&&(this.ve=this.Fn(t,e.clientX),t.didResize||(t.didResize=Math.abs(this.ve-t.startWidth)>=.5),!this.A&&(this.A=requestAnimationFrame(()=>{this.A=0,this.sl()})))};this.X=e=>{let t=this.qo(e);t&&(this.ve=this.Fn(t,e.clientX),t.didResize||(t.didResize=Math.abs(this.ve-t.startWidth)>=.5),this.al(t))};this.Pe=e=>{this.qo(e)&&this.cancelResize()};this.Pn=()=>{this.cancelResize()}}startResize(e,t){if(!this.core.options.enableColumnResize||!t.resizable||e.isPrimary===!1)return;this.cancelResize();let r=e.currentTarget,o=t.currentWidth;this.ve=o,this.active={column:t,didResize:!1,handle:r,pointerId:e.pointerId,startFlex:t.flex,startManualWidth:t.manualWidth,startWidth:o,startX:e.clientX},window.addEventListener("pointermove",this.we),window.addEventListener("pointerup",this.X,!0),window.addEventListener("pointercancel",this.Pe,!0),r.addEventListener("lostpointercapture",this.Pn);try{r.setPointerCapture?.(e.pointerId)}catch{}this.core.skeleton.root.classList.add("mach-root--resizing"),r.classList.add("mach-header-resize--active"),this.nl(this.active)}cancelResize(e=!0){let t=this.active;t&&(this.active=null,this.Ko(),this.Gn(t),e&&(t.column.manualWidth=t.startManualWidth,t.column.flex=t.startFlex,this.core.relayoutColumns()),this.core.skeleton.root.classList.remove("mach-root--resizing"),this.Nn(t))}al(e){this.active=null,this.Ko(),e.didResize&&(Math.abs(this.ve-e.startWidth)<.5?(e.column.manualWidth=e.startManualWidth,e.column.flex=e.startFlex):this.core.columnModel.oe(e.column,this.ve),this.core.relayoutColumns()),this.Gn(e);try{e.handle.releasePointerCapture?.(e.pointerId)}catch{}this.core.skeleton.root.classList.remove("mach-root--resizing"),this.Nn(e),e.didResize&&this.core.commitColumnWidths([e.column])}sl(){let e=this.active;!e||!this.core.columnModel.oe(e.column,this.ve)||(this.core.relayoutColumns(),this.Nt(e),this.core.emitColumnResize(e.column,!1))}nl(e){this.Y=document.createElement("div"),this.Y.className="mach-column-resize-guide",this.Y.setAttribute("aria-hidden","true"),this.Le=document.createElement("span"),this.Le.className="mach-column-resize-label",this.Y.appendChild(this.Le),this.core.skeleton.root.appendChild(this.Y),this.Nt(e)}Nt(e){if(!this.Y||!this.Le)return;let t=this.core.skeleton.root,r=t.getBoundingClientRect(),o=e.handle.parentElement.getBoundingClientRect(),n=Math.max(0,Math.min(t.clientWidth,o.right-r.left-t.clientLeft)),s=Math.max(32,Math.min(t.clientWidth-32,n));this.Y.style.left=`${n}px`,this.Y.style.top=`${Math.max(0,o.top-r.top-t.clientTop)}px`,this.Le.style.left=`${s-n}px`,this.Le.textContent=`${Math.round(e.column.currentWidth)} px`}Nn(e){e.handle.classList.remove("mach-header-resize--active"),this.Y?.remove(),this.Y=null,this.Le=null}Fn(e,t){let r=Number.isFinite(t)?t:e.startX;return e.startWidth+r-e.startX}qo(e){let t=this.active;return t&&e.pointerId===t.pointerId?t:null}Ko(){this.A&&cancelAnimationFrame(this.A),this.A=0}Gn(e){window.removeEventListener("pointermove",this.we),window.removeEventListener("pointerup",this.X,!0),window.removeEventListener("pointercancel",this.Pe,!0),e.handle.removeEventListener("lostpointercapture",this.Pn)}destroy(){this.cancelResize(!1),this.Ko(),this.core.skeleton.root?.classList.remove("mach-root--resizing")}};function f(i,e,t){let r=document.createElement(i);if(e&&(r.className=e),t)for(let o of Object.keys(t))r.setAttribute(o,t[o]);return r}var Cn=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function L(i,e){if(i.classList.add("mach-portal"),!e)return;let t=window.getComputedStyle(e);for(let r of Cn){let o=t.getPropertyValue(r).trim();o&&i.style.setProperty(r,o)}i.style.colorScheme=t.colorScheme}function R(i,e,t){return i<e?e:i>t?t:i}var qr=0;function Ur(i="rg"){return qr++,`${i}-${qr}`}var jr='<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3.5h12L9.5 8v4.5L6.5 14V8L2 3.5z"/></svg>',Yr='<svg viewBox="0 0 16 16" width="10" height="10" fill="currentColor"><path d="M8 3l4 5H4l4-5z"/></svg>',Xr='<svg viewBox="0 0 16 16" width="10" height="10" fill="currentColor"><path d="M8 13l4-5H4l4 5z"/></svg>',Jr='<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.35" stroke-linecap="round"><path d="M2 4h3m3 0h6M2 8h7m3 0h2M2 12h1m3 0h8"/><circle cx="6.5" cy="4" r="1.35"/><circle cx="10.5" cy="8" r="1.35"/><circle cx="4.5" cy="12" r="1.35"/></svg>';var Zr=6,Ke=class{constructor(e){this.core=e;this.pending=null;this.rt=null;this.Uo=!1;this.F=0;this.Rr=null;this.we=e=>{if(this.rt){this.ll(e);return}let t=this.pending;t&&(Math.abs(e.clientX-t.startX)<Zr&&Math.abs(e.clientY-t.startY)<Zr||this.dl(e))};this.X=e=>{this.pending=null,e.type!=="pointercancel"&&this.rt&&this.Xo(e.clientX,e.clientY),this.jo();let t=this.On();t&&e.type!=="pointercancel"&&t.targetIndex>=0&&this.core.moveColumn(t.column.id,t.targetIndex)}}onPointerDown(e,t){e.button===0&&t.movable&&(this.pending={column:t,startX:e.clientX,startY:e.clientY},window.addEventListener("pointermove",this.we),window.addEventListener("pointerup",this.X),window.addEventListener("pointercancel",this.X))}didDrag(){let e=this.Uo;return this.Uo=!1,e}dl(e){let t=this.pending;if(!t)return;let r=this.cl(t.column);if(!r||!r.parentElement){this.jo();return}this.Uo=!0;let o=f("div","mach-drop-indicator"),n=f("div","mach-column-drag-ghost");n.textContent=t.column.colDef.headerName??t.column.colDef.field??t.column.id,n.ariaHidden="true",L(n,this.core.skeleton.root),document.body.appendChild(n),r.parentElement.appendChild(o),r.classList.add("mach-header-cell--dragging"),this.core.skeleton.root.classList.add("mach-root--dragging");let s=this.core.bodyRenderer.Yo(t.column),a=this.core.skeleton.ot[s],l=this.core.columnModel.d(s),d=new Float64Array(l.length+1),c=new Float64Array(l.length);for(let h=0;h<l.length;h++){let p=l[h].currentWidth;c[h]=d[h]+p/2,d[h+1]=d[h]+p}let u=n.getBoundingClientRect();this.rt={column:t.column,cellEl:r,ghost:n,indicator:o,targetIndex:-1,pane:s,containerLeft:a.getBoundingClientRect().left,startScrollLeft:this.core.skeleton.b.center.scrollLeft,fromIndex:l.indexOf(t.column),midpoints:c,offsets:d,ghostWidth:u.width,ghostHeight:u.height},this.Xo(e.clientX,e.clientY)}cl(e){let t=this.core.bodyRenderer.Yo(e);return this.core.skeleton.ot[t].querySelector(`.mach-header-cell[data-col-id="${Tn(e.id)}"]`)}ll(e){this.Rr={clientX:e.clientX,clientY:e.clientY},!this.F&&(this.F=requestAnimationFrame(()=>{this.F=0;let t=this.Rr;this.Rr=null,t&&this.Xo(t.clientX,t.clientY)}))}Xo(e,t){let r=this.rt;if(!r)return;let o=R(e+12,8,window.innerWidth-r.ghostWidth-8),n=R(t+12,8,window.innerHeight-r.ghostHeight-8);r.ghost.style.transform=`translate3d(${o}px, ${n}px, 0)`;let s=r.pane==="center"?this.core.skeleton.b.center.scrollLeft-r.startScrollLeft:0,a=e-(r.containerLeft-s),l=r.midpoints.length;for(let d=0;d<r.midpoints.length;d++)if(a<r.midpoints[d]){l=d;break}r.targetIndex=l>r.fromIndex?l-1:l,r.indicator.style.transform=`translate3d(${r.offsets[l]}px, 0, 0)`}On(){let e=this.rt;return e?(this.rt=null,e.cellEl.classList.remove("mach-header-cell--dragging"),e.ghost.remove(),e.indicator.remove(),this.core.skeleton.root.classList.remove("mach-root--dragging"),e):null}jo(){window.removeEventListener("pointermove",this.we),window.removeEventListener("pointerup",this.X),window.removeEventListener("pointercancel",this.X),this.F&&cancelAnimationFrame(this.F),this.F=0,this.Rr=null}destroy(){this.jo(),this.On(),this.pending=null}};function Tn(i){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(i):i.replace(/[^a-zA-Z0-9_-]/g,"\\$&")}function Qr(i,e){let t=i==null?"":String(i);return t.includes(e)||t.includes('"')||t.includes(`
1
+ "use strict";var $t=Object.defineProperty;var Mi=Object.getOwnPropertyDescriptor;var Si=Object.getOwnPropertyNames;var ki=Object.prototype.hasOwnProperty;var Ii=(i,e)=>{for(var t in e)$t(i,t,{get:e[t],enumerable:!0})},Ai=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Si(e))!ki.call(i,o)&&o!==t&&$t(i,o,{get:()=>e[o],enumerable:!(r=Mi(e,o))||r.enumerable});return i};var Li=i=>Ai($t({},"__esModule",{value:!0}),i);var na={};Ii(na,{BUILTIN_AGG_FUNCS:()=>Jt,DEFAULT_LOCALE:()=>E,EVENT_TYPES:()=>Y,LOCALE_EN:()=>co,actionsColumn:()=>ci,advancedFilterCondition:()=>Gr,advancedFilterGroup:()=>Nr,applyGridViewState:()=>Ir,buildColDefsFromSchema:()=>ni,captureGridViewState:()=>kr,clearGridState:()=>Wo,createActionButtonsRenderer:()=>ye,createAggResolver:()=>Ve,createBusinessColumnTypes:()=>wi,createCachedDictionary:()=>bi,createColumnHelper:()=>hi,createDictionaryRenderer:()=>Ci,createEnterprisePreset:()=>fi,createGrid:()=>ri,createGridViewManager:()=>Ei,createLocalGridStateStore:()=>mr,createLocalGridViewStore:()=>Ar,createMachTableCommands:()=>si,createMachTablePreset:()=>Sr,createProgressBarRenderer:()=>br,createRemoteExportRequest:()=>oi,createRowActionsRenderer:()=>Ft,createStatusTagRenderer:()=>wr,defineColumns:()=>pi,defineGridOptions:()=>gi,defineMachTableConfig:()=>yi,defineMachTablePreset:()=>mi,describeFilter:()=>Ct,downloadFile:()=>vt,dragColumn:()=>di,escapeHtml:()=>ie,formatText:()=>B,formatTwo:()=>he,getByPath:()=>q,indexColumn:()=>li,isColDefGroup:()=>de,isSafePath:()=>se,linkRenderer:()=>Cr,loadGridState:()=>Pt,matchLocaleKey:()=>st,normalizeAdvancedFilterModel:()=>H,normalizeColumnFilter:()=>Pe,normalizeFilterModel:()=>U,normalizeGridState:()=>_,normalizeGridViewState:()=>Wt,normalizeSavedGridView:()=>ve,parseCsv:()=>Ue,parseDelimited:()=>je,parseTsv:()=>qe,resolveGridFeatures:()=>Vt,resolveSaveConflict:()=>To,resolveTagVariant:()=>vr,rowActionsColumn:()=>ui,sanitizeFormulaCell:()=>Ce,saveGridState:()=>Lt,selectionColumn:()=>ai,setByPath:()=>ae,toTsv:()=>ue,validateGridOptions:()=>Ot,version:()=>ia});module.exports=Li(na);var Ae="0.32.1";var Le=class{constructor(e){this.onListenerError=e;this.Ke=new Map}on(e,t){let r=this.Ke.get(e);return r||(r=new Set,this.Ke.set(e,r)),r.add(t),()=>{r.delete(t)}}once(e,t){let r=this.on(e,o=>{r(),t(o)});return r}off(e,t){let r=this.Ke.get(e);r&&(r.delete(t),r.size===0&&this.Ke.delete(e))}emit(e,t){let r=this.Ke.get(e);if(r)for(let o of[...r])try{o(t)}catch(n){console.error(`[mach-table] error in "${e}" listener`,n),this.onListenerError?.(n,e)}}clear(){this.Ke.clear()}};var Gi=new Set(["__proto__","prototype","constructor"]);function se(i){return typeof i!="string"||i.length===0?!1:i.split(".").every(t=>t.length>0&&!Gi.has(t))}function q(i,e){if(i==null||!se(e))return;if(e.indexOf(".")<0)return i[e];let r=i,o=0;for(;o<e.length;){if(r==null)return;let n=e.indexOf(".",o);if(n<0){r=r[e.slice(o)];break}r=r[e.slice(o,n)],o=n+1}return r}function ae(i,e,t){if(i==null||!se(e))return!1;let r=e.split("."),o=i;for(let n=0;n<r.length-1;n++){if(typeof o!="object"&&typeof o!="function"||o===null)return!1;o[r[n]]==null&&(o[r[n]]={}),o=o[r[n]]}return typeof o!="object"&&typeof o!="function"||o===null?!1:(o[r[r.length-1]]=t,!0)}var Ni=new Set(["contains","notContains","equals","notEquals","startsWith","endsWith","blank","notBlank"]),Fi=new Set(["equals","notEquals","lessThan","lessThanOrEqual","greaterThan","greaterThanOrEqual","inRange","blank","notBlank"]),Oi=new Set(["equals","notEquals","lessThan","greaterThan","inRange","blank","notBlank"]);function Hi(i){return i==null||typeof i=="string"||typeof i=="number"&&Number.isFinite(i)}function Vi(i){return i==="text"?Ni:i==="number"?Fi:Oi}function Bi(i,e,t){if(i==null||typeof i!="object")return null;let r=i;return typeof r.match!="string"||!t.has(r.match)?null:{match:r.match,...zi(r,e)}}function zi(i,e){let t=e==="number"?Lr(i.value):typeof i.value=="string"?i.value:void 0,r=e==="number"?Lr(i.value2):typeof i.value2=="string"?i.value2:void 0;return{...t!==void 0?{value:t}:{},...r!==void 0?{value2:r}:{}}}function Lr(i){return typeof i=="number"&&Number.isFinite(i)?i:void 0}function _i(i,e){let t=[],r=Vi(e);for(let o of i.slice(0,20)){let n=Bi(o,e,r);n&&t.push(n)}return t}function Pe(i){if(i==null||typeof i!="object")return null;let e=i;return e.type==="set"?Array.isArray(e.values)?{type:"set",values:e.values.filter(Hi).slice(0,2e3)}:null:e.type!=="text"&&e.type!=="number"&&e.type!=="date"||!Array.isArray(e.conditions)?null:{type:e.type,...e.operator==="or"||e.operator==="and"?{operator:e.operator}:{},conditions:_i(e.conditions,e.type)}}function Wi(i,e){if(typeof i.colId!="string"||!i.colId.trim())return null;let t=i.colId.trim();if(e.validColumnIds?.has(t)===!1)return null;let r=Pe(i.filter);return r?{kind:"condition",colId:t,filter:r}:null}function $i(i,e,t){if(!Array.isArray(i.children))return null;let r=[];for(let o of i.children){let n=Pr(o,e+1,t);n&&r.push(n)}return r.length===0?null:{kind:"group",operator:i.operator==="or"?"or":"and",children:r,...i.not===!0?{not:!0}:{}}}function Ki(i,e,t){return e<=16&&t.nodes<512&&i!=null&&typeof i=="object"}function Pr(i,e,t){if(!Ki(i,e,t)||t.ancestors.has(i))return null;t.ancestors.add(i),t.nodes++;let r=i,o=r.kind==="condition"?Wi(r,t):r.kind==="group"?$i(r,e,t):null;return t.ancestors.delete(i),o}function H(i,e){if(i==null||typeof i!="object")return null;let t=i;if(t.version!==1||t.root==null)return null;let r=Pr(t.root,0,{ancestors:new WeakSet,nodes:0,validColumnIds:e});return r?{version:1,root:r}:null}function Gr(i,e){return{kind:"condition",colId:i,filter:e}}function U(i,e){if(i==null||typeof i!="object"||Array.isArray(i))return{};let t={};for(let[r,o]of Object.entries(i).slice(0,2e3)){let n=r.trim();if(!n||e?.has(n)===!1)continue;let s=Pe(o);s&&(t[n]=s)}return t}function Nr(i,e,t={}){return{kind:"group",operator:i,children:e,...t.not?{not:!0}:{}}}var Kt={align:"center",sortable:!0,resizable:!0,movable:!0,filter:!1,minWidth:80},we={compact:{rowHeight:30,headerHeight:34,fontSize:12,cellPadding:6},normal:{rowHeight:36,headerHeight:40,fontSize:13,cellPadding:9},large:{rowHeight:44,headerHeight:48,fontSize:14,cellPadding:12}};function M(i,e,t,r=!1){return typeof i!="number"||!Number.isFinite(i)||i<t?e:r?Math.floor(i):i}function qi(i){return i&&Object.prototype.hasOwnProperty.call(we,i)?i:"normal"}function Ui(i){return i.theme==="light"||i.theme==="dark"||i.theme==="auto"?i.theme:"light"}function ji(i,e){let t=typeof i.pagination=="object"&&Array.isArray(i.pagination.pageSizeOptions)?i.pagination.pageSizeOptions:void 0,r=t?[...new Set(t.map(o=>M(o,0,1,!0)).filter(Boolean))]:[10,20,50,100];return r.includes(e)||r.push(e),r.sort((o,n)=>o-n)}function qt(i,e){let t=typeof i=="function"?i(e):q(e,i);return t==null?"":String(t)}function Yi(i){let e=i.rowKey,t=e?({data:r})=>qt(e,r):void 0;return{...t?{resolveRowId:t}:{},...e?{rowKey:e}:{}}}function Xi(i,e){let t=we[e];return{columnDefs:Array.isArray(i.columnDefs)?i.columnDefs:[],rowData:Array.isArray(i.rowData)?i.rowData:[],defaultColDef:{...Kt,...i.defaultColDef??{}},columnTypes:i.columnTypes??{},...Yi(i),rowHeight:M(i.rowHeight,t.rowHeight,1),headerHeight:M(i.headerHeight,t.headerHeight,1),rowBuffer:M(i.rowBuffer,8,0,!0),columnLayout:i.columnLayout==="fit"?"fit":"normal",enableColumnResize:i.enableColumnResize===!0,domLayout:i.domLayout==="autoHeight"?"autoHeight":"normal",rowSelection:i.rowSelection==="single"||i.rowSelection==="multiple"?i.rowSelection:"none",multiSort:i.multiSort??!0,size:e,pinnedTopRowData:Array.isArray(i.pinnedTopRowData)?i.pinnedTopRowData:[],pinnedBottomRowData:Array.isArray(i.pinnedBottomRowData)?i.pinnedBottomRowData:[]}}function Ji(i){return{stripedRows:i.stripedRows??!1,rowStyleRules:Array.isArray(i.rowStyleRules)?i.rowStyleRules:[],showCellBorders:i.showCellBorders??!1,theme:Ui(i),quickFilterText:i.quickFilterText??null,suppressCellFocus:i.suppressCellFocus??!1,suppressRowHoverHighlight:i.suppressRowHoverHighlight??!1,suppressNoRowsOverlay:i.suppressNoRowsOverlay??!1,suppressHeaderFocus:i.suppressHeaderFocus??!1,loading:i.loading??!1,error:i.error??null,className:i.className??""}}function Zi(i){return{editType:i.editType==="fullRow"?"fullRow":"cell",editableIndicator:i.editableIndicator==="always"||i.editableIndicator==="none"?i.editableIndicator:"hover",singleClickEdit:i.singleClickEdit??!1,manualSorting:i.manualSorting??!1,manualFiltering:i.manualFiltering??!1,showSummary:i.showSummary??!1,indexOffset:i.indexOffset??0,applyRowDrag:i.applyRowDrag??!0,rowDragPolicy:i.rowDragPolicy,undoStackSize:M(i.undoStackSize,100,0,!0),asyncTransactionWaitMillis:M(i.asyncTransactionWaitMillis,16,0,!0)}}function Qi(i){return{masterDetail:i.masterDetail??!1,detailRowHeight:M(i.detailRowHeight,240,1),detailToggleColumn:i.detailToggleColumn??!0,treeData:i.treeData??!1,childrenKey:i.childrenKey??"children",autoCheckedChildren:i.autoCheckedChildren??!0,defaultExpandAll:i.defaultExpandAll??!1}}function en(i){let e=typeof i.pagination=="object"?i.pagination:void 0,t=M(e?.pageSize,20,1,!0);return{paginationEnabled:i.pagination!==!1&&i.datasource==null,paginationMode:e?.mode==="server"?"server":"client",paginationPage:M(e?.page,1,1,!0),paginationTotal:M(e?.total,0,0,!0),paginationPageSize:t,paginationPageSizeOptions:ji(i,t),paginationShowTotal:e?e.showTotal!==!1:!0,paginationShowSizeSelector:e?e.showPageSizeSelector!==!1:!0}}function tn(i){return{watermarkEnabled:i.watermark!=null&&i.watermark!==!1,watermarkConfig:i.watermark==null||i.watermark===!1?null:i.watermark===!0?{text:"MachTable"}:i.watermark}}function rn(i){return{columnMenu:i.columnMenu??!1,advancedFilterModel:H(i.advancedFilterModel),...on(i),locale:i.locale??{},suppressWarnings:i.suppressWarnings??!1,enableRangeSelection:i.enableRangeSelection??!1,suppressClipboard:i.suppressClipboard??!1,contextMenu:i.contextMenu??!1,tooltipShowDelay:M(i.tooltipShowDelay,600,0),flashCells:i.flashCells??!0,fillHandle:i.fillHandle??!0,statusBarEnabled:i.statusBar===!0||typeof i.statusBar=="object"&&i.statusBar!=null,statusBarPanels:typeof i.statusBar=="object"&&i.statusBar?.panels?i.statusBar.panels:["rowCount","selectedRowCount","rangeAggregate"]}}function on(i){let e=i.persistence;return!e||typeof e.key!="string"||!e.key.trim()?{persistence:null}:{persistence:{key:e.key.trim(),debounceMs:M(e.debounceMs,160,0,!0),...e.sections?{sections:[...new Set(e.sections)]}:{},...e.store?{store:e.store}:{}}}}function nn(i){return{datasourceMode:i.datasourceMode==="block"?"block":"sequential",blockSize:M(i.blockSize,100,1,!0),infiniteBufferRows:M(i.infiniteBufferRows,40,0,!0),maxBlocksInCache:M(i.maxBlocksInCache,12,1,!0),datasourceMaxConcurrentRequests:M(i.datasourceMaxConcurrentRequests,4,1,!0),blockPrefetch:M(i.blockPrefetch,1,0,!0),datasourceRowCount:i.datasourceRowCount==null?null:M(i.datasourceRowCount,0,0,!0),dataProcessorMinRows:M(i.dataProcessorMinRows,5e3,1,!0),datasourceRetryCount:M(i.datasourceRetryCount,2,0,!0),datasourceRetryDelay:M(i.datasourceRetryDelay,300,0,!0),datasourceRetryJitter:Math.min(1,M(i.datasourceRetryJitter,.15,0))}}function sn(i){return{ariaLabel:i.ariaLabel??"MachTable data grid",ariaLabelledBy:i.ariaLabelledBy??"",ariaDescribedBy:i.ariaDescribedBy??"",overlayNoRowsTemplate:i.overlayNoRowsTemplate??"",overlayLoadingTemplate:i.overlayLoadingTemplate??"",overlayErrorTemplate:i.overlayErrorTemplate??"",allowUnsafeOverlayHtml:i.allowUnsafeOverlayHtml??!1}}var an=["detailRowRenderer","isRowExpandable","aggFuncs","components","actionPolicy","summaryMethod","datasource","getRowHeight","tooltipComponent","getContextMenuItems","initialState","rowEditValidator","isTreeRowExpandable","loadTreeChildren","dataProcessor"];function ln(i,e){for(let t of an)i[t]&&Object.assign(e,{[t]:i[t]})}function dn(i,e){for(let t of Object.keys(i))t.startsWith("on")&&typeof i[t]=="function"&&Object.assign(e,{[t]:i[t]})}function Fr(i){let e=qi(i.size),t={...Xi(i,e),...Ji(i),...Zi(i),...Qi(i),...en(i),...tn(i),...rn(i),...nn(i),...sn(i),features:Array.isArray(i.features)?i.features:[]};return ln(i,t),dn(i,t),t}function Or(i){return Array.isArray(i)?i.filter(e=>typeof e=="string"&&e.length>0):typeof i=="string"&&i.length>0?[i]:[]}function le(i,e){return Or(i.type).includes(e)}function Hr(i,e,t={}){let r={};for(let o of Or(i.type)){let n=t[o];n&&Object.assign(r,n)}return{...e,...r,...i}}var W=class{constructor(e,t){this.manualWidth=null;this.contentWidth=null;this.flex=null;this.currentWidth=0;this.parentGroup=null;this.level=0;this.isDetailToggle=!1;this.id=e,this.colDef=t,this.hide=t.hide??!1;let r=t.pinned;this.pinned=r===!0?"left":r===!1||r==null?null:r,this.resetWidth()}get sortable(){return this.colDef.sortable!==!1}get resizable(){return this.colDef.resizable!==!1}get movable(){return this.colDef.movable!==!1}get filterable(){return this.colDef.filter!=null&&this.colDef.filter!==!1}get filterType(){let e=this.colDef.filter;return e===!0?"text":e??"text"}get hasCheckbox(){return this.colDef.checkboxSelection===!0}resetWidth(){this.manualWidth=null,this.contentWidth=null,this.flex=typeof this.colDef.flex=="number"&&Number.isFinite(this.colDef.flex)&&this.colDef.flex>0?this.colDef.flex:null}};var Q=class i{constructor(e,t){this.parent=null;this.children=[];this.groupId=e,this.def=t}get headerName(){return this.def.headerName??this.def.groupId??""}getLeafColumns(e=[]){for(let t of this.children)t instanceof i?t.getLeafColumns(e):e.push(t);return e}};function de(i){return Array.isArray(i.children)}function Ge(i,e){return typeof i=="number"&&Number.isFinite(i)&&i>0?i:e}function Vr(i){let e=Ge(i.minWidth,80);return{min:e,max:Math.max(e,Ge(i.maxWidth,Number.MAX_SAFE_INTEGER))}}function O(i,e){let{min:t,max:r}=Vr(e),o=Ge(i,Ge(e.width,150));return Math.max(t,Math.min(r,o))}function Br(i,e){let t=i.map(s=>O(s.width??150,s)),r=[],o=0;i.forEach((s,a)=>{let l=s.flex??0;l>0&&(r.push(a),o+=l)});let n=0;for(let s of t)n+=s;if(o>0&&e>n){let s=e-n;for(let a=0;a<4&&s>.5&&r.length>0;a++){let l=[],d=0;for(let p of r){let m=i[p].flex??0;l.push(p),d+=m}let c=[];for(let p=0;p<l.length;p++){let m=l[p],g=i[m].flex??0,v=s*g/d,y=t[m];t[m]=O(y+v,i[m]),c.push(t[m]-y)}let u=0;for(let p of c)u+=p;s-=u;let h=l.filter((p,m)=>c[m]>.001);if(h.length===l.length)break;r.length=0;for(let p of h)r.push(p)}}return t}function cn(i,e,t){let r=new Set(i.map((n,s)=>s)),o=t;for(let n=0;n<i.length+1&&r.size>0;n++){let s=0;for(let l of r)s+=Math.max(1,e[l]);if(s<=0)break;let a=!1;for(let l of[...r]){let d=o*(Math.max(1,e[l])/s),c=O(d,i[l]),{min:u,max:h}=Vr(i[l]);(d<u||d>h)&&(e[l]=c,o-=c,r.delete(l),a=!0)}if(!a){for(let l of r)e[l]=O(o*(Math.max(1,e[l])/s),i[l]);break}o=Math.max(0,o)}}function un(i,e,t){let r=t-e.reduce((o,n)=>o+n,0);if(!(Math.abs(r)<=.01))for(let o=e.length-1;o>=0;o--){let n=O(e[o]+r,i[o]);if(Math.abs(n-e[o])>.01){e[o]=n;return}}}function Ne(i,e){let t=i.map(r=>O(r.width??150,r));return!Number.isFinite(e)||e<=0||i.length===0||(cn(i,t,e),un(i,t,e)),t}var Ut="__rg_detail_toggle__";function ce(i){return typeof i=="number"&&Number.isFinite(i)&&i>0}var Fe=class{constructor(e){this.core=e;this.columns=[];this.rn=new Map;this.q=[];this.left=[];this.center=[];this.right=[];this.sortModel=[];this.defs=[];this.qe=1;this.vo=new Map;this.fa=0}wt(e){this.defs=e?[...e]:[];let t=new Map(this.columns.map(s=>[s.id,s])),r=this.core.options.defaultColDef,o=new Set(this.core.options.masterDetail&&this.core.options.detailToggleColumn?[Ut]:[]),n=(s,a,l)=>s.map((d,c)=>{if(de(d)){let y=d.groupId??d.headerName??`group_${c}_${l}`,b=new Q(y,d);return b.parent=a,b.children=n(d.children,b,l+1),b}let u=d,h=u.colId??u.field??`col_${c}`,p=h,m=2;for(;o.has(p);)p=`${h}_${m++}`;o.add(p);let g=new W(p,Hr(u,r,this.core.options.columnTypes));g.parentGroup=a,g.level=l;let v=t.get(p);return v&&(g.manualWidth=v.manualWidth,g.contentWidth=v.contentWidth,g.flex=v.flex,g.hide=v.hide,g.pinned=v.pinned),g});if(this.q=n(this.defs,null,0),this.core.options.masterDetail&&this.core.options.detailToggleColumn){let s=new W(Ut,{colId:Ut,headerName:"",width:38,pinned:"left",sortable:!1,resizable:!1,movable:!1,filter:!1});s.isDetailToggle=!0,this.q.unshift(s)}if(this.columns=this.ir(this.q),this.rn=new Map(this.columns.map(s=>[s.id,s])),this.qe=this.columns.reduce((s,a)=>Math.max(s,a.level+1),1),this.sortModel=this.sortModel.filter(s=>this.columns.some(a=>a.id===s.colId)),this.sortModel.length===0){let s=[];for(let a of this.columns)a.colDef.initialSort&&s.push({colId:a.id,direction:a.colDef.initialSort});this.sortModel=s}this.Ue()}ir(e,t=[]){for(let r of e)r instanceof Q?this.ir(r.children,t):t.push(r);return t}Ue(){let e=this.columns.filter(t=>!t.hide);this.left=e.filter(t=>t.pinned==="left"),this.right=e.filter(t=>t.pinned==="right"),this.center=e.filter(t=>t.pinned===null),this.vo.clear(),this.e().forEach((t,r)=>this.vo.set(t.id,r))}te(e){return this.vo.get(e)??-1}G(){return this.columns}nr(){return this.defs}ma(){return this.q}ga(){return this.qe}m(e){return this.rn.get(e)}d(e){return e==="left"?this.left:e==="right"?this.right:this.center}e(){return[...this.left,...this.center,...this.right]}re(){return this.e().filter(e=>e.colDef.rowGroup===!0)}ya(){return this.e().filter(e=>e.colDef.aggFunc!=null&&e.colDef.rowGroup!==!0)}wo(){return this.center.some(e=>e.colDef.colSpan!=null)}nn(){let e=this.e();return this.center.find(t=>!t.hasCheckbox&&!t.isDetailToggle)??e.find(t=>!t.hasCheckbox&&!t.isDetailToggle)??e[0]}bt(e){return e.pinned==="left"?"left":e.pinned==="right"?"right":"center"}sn(e){this.fa=e;let t=0;for(let c of[...this.left,...this.right])c.currentWidth=O(c.manualWidth??c.contentWidth??c.colDef.width??150,this.Se(c)),t+=c.currentWidth;let r=Math.max(0,e-t),o=[],n=[];for(let c of this.center)(c.colDef.suppressSizeToFit||c.manualWidth!=null?n:o).push(c);let s=0;for(let c of n)c.currentWidth=O(c.manualWidth??c.contentWidth??c.colDef.width??150,this.Se(c)),s+=c.currentWidth;let a=o.map(c=>this.Se(c)),l=Math.max(0,r-s),d=this.core.options.columnLayout==="fit"?Ne(a,l):Br(a,l);o.forEach((c,u)=>{c.currentWidth=d[u]})}Se(e){let t=e.colDef;return{width:e.manualWidth??e.contentWidth??t.width,minWidth:t.minWidth,maxWidth:t.maxWidth,flex:e.manualWidth==null?e.flex??void 0:void 0}}oe(e,t){return ce(t)?(e.manualWidth=O(t,this.Se(e)),e.flex=null,!0):!1}an(e,t){return ce(t)?(e.resetWidth(),e.contentWidth=O(t,this.Se(e)),!0):!1}bo(e,t){let r=this.m(e);!r||r.hide===!t||(r.hide=!t,this.Ue())}moveColumn(e,t){let r=this.m(e);if(!r)return!1;let o=this.bt(r),n=u=>r.parentGroup?!0:this.bt(u)===o,s=r.parentGroup?r.parentGroup.children:this.q,a=s.filter(u=>u instanceof W&&!u.hide&&n(u)),l=a.indexOf(r);if(l<0)return!1;a.splice(l,1);let d=Math.max(0,Math.min(t,a.length));a.splice(d,0,r);let c=[];return s.forEach((u,h)=>{u instanceof W&&!u.hide&&n(u)&&c.push(h)}),c.length!==a.length?!1:(c.forEach((u,h)=>{s[u]=a[h]}),this.columns=this.ir(this.q),this.Ue(),!0)}Co(e,t){let r=this.m(e);!r||!r.movable||(r.pinned=t,this.Ue())}sr(){return this.columns.map(e=>({colId:e.id,hide:e.hide,width:e.manualWidth??e.currentWidth,flex:e.flex,widthMode:e.manualWidth==null?"auto":"manual",contentWidth:e.contentWidth??void 0,pinned:e.pinned}))}ln(e){let t=new Map(e.map(r=>[r.colId,r]));for(let r of this.columns){let o=t.get(r.id);o&&this.va(r,o)}this.wa(e),this.Ue()}va(e,t){typeof t.hide=="boolean"&&(e.hide=t.hide),t.widthMode==="auto"?(e.resetWidth(),ce(t.flex)&&(e.flex=t.flex)):ce(t.flex)?(e.flex=t.flex,e.manualWidth=null):ce(t.width)&&(e.manualWidth=O(t.width,this.Se(e)),e.flex=null),ce(t.contentWidth)&&(e.contentWidth=O(t.contentWidth,this.Se(e))),e.movable&&(t.pinned==="left"||t.pinned==="right"||t.pinned===null)&&(e.pinned=t.pinned)}wa(e){let t=new Map;e.forEach((o,n)=>t.set(o.colId,n));let r=o=>o.pinned==="left"?"left":o.pinned==="right"?"right":"center";for(let o of["left","center","right"]){let n=this.q.filter(d=>d instanceof W&&!d.hide&&d.parentGroup===null&&r(d)===o);if(n.length<2)continue;let s=n.filter(d=>d.movable),a=s.slice().sort((d,c)=>(t.get(d.id)??Number.MAX_SAFE_INTEGER)-(t.get(c.id)??Number.MAX_SAFE_INTEGER));if(a.every((d,c)=>d===s[c]))continue;let l=[];this.q.forEach((d,c)=>{d instanceof W&&!d.hide&&d.parentGroup===null&&r(d)===o&&d.movable&&l.push(c)}),l.forEach((d,c)=>{this.q[d]=a[c]})}this.columns=this.ir(this.q)}To(){for(let e of this.columns){e.resetWidth(),e.hide=e.colDef.hide??!1;let t=e.colDef.pinned;e.pinned=t===!0?"left":t===!1||t==null?null:t}this.Ue()}D(){return this.sortModel.map(e=>({...e}))}Ct(e){if(!e||e.length===0){this.sortModel=[];return}this.sortModel=e.filter(t=>this.columns.some(r=>r.id===t.colId)&&(t.direction==="asc"||t.direction==="desc")).map(t=>({colId:t.colId,direction:t.direction}))}cycleSort(e,t){let r=[...this.sortModel],o=r.findIndex(l=>l.colId===e.id),n=o>=0?r[o].direction:null,s=n===null?"asc":n==="asc"?"desc":null;t&&this.core.options.multiSort?s===null?o>=0&&r.splice(o,1):o>=0?r[o]={colId:e.id,direction:s}:r.push({colId:e.id,direction:s}):(r.length=0,s&&r.push({colId:e.id,direction:s})),this.sortModel=r}};function _r(i){return i==null?"":String(i).toLowerCase()}function hn(i,e,t){let r=_r(i),o=n=>{let s=(n.value??"").toLowerCase();switch(n.match){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"blank":return r==="";case"notBlank":return r!=="";default:return!0}};return e.length===0||(t==="or"?e.some(o):e.every(o))}function pn(i,e,t){switch(t.match){case"equals":return i===e;case"notEquals":return i!==e;case"lessThan":return i<e;case"lessThanOrEqual":return i<=e;case"greaterThan":return i>e;case"greaterThanOrEqual":return i>=e;case"inRange":return i>=e&&i<=(t.value2??e);default:return!0}}function fn(i,e){let t=i==null||i==="";if(e.match==="blank")return t;if(e.match==="notBlank")return!t;if(t)return!1;let r=typeof i=="number"?i:Number(i);if(Number.isNaN(r))return!1;let o=e.value;return o==null||Number.isNaN(o)?!1:pn(r,o,e)}function mn(i,e,t){let r=o=>fn(i,o);return e.length===0||(t==="or"?e.some(r):e.every(r))}function jt(i){if(i==null||i==="")return null;if(i instanceof Date)return isNaN(i.getTime())?null:i.getTime();if(typeof i=="number")return i;let e=Date.parse(String(i));return isNaN(e)?null:e}function gn(i,e,t){let r=jt(i),o=n=>{let s=r==null;if(n.match==="blank")return s;if(n.match==="notBlank")return!s;if(s)return!1;let a=r,l=n.value!=null?jt(n.value):null;if(l==null)return!1;switch(n.match){case"equals":return a===l;case"notEquals":return a!==l;case"lessThan":return a<l;case"greaterThan":return a>l;case"inRange":{let d=n.value2!=null?jt(n.value2):null;return d!=null?a>=l&&a<=d:a>=l}default:return!0}};return e.length===0||(t==="or"?e.some(o):e.every(o))}function yn(i,e){return e.length===0?!0:e.some(t=>t==null&&i==null||t===i)}function Wr(i,e){let t=e.type!=="set"&&e.operator==="or"?"or":"and";switch(e.type){case"text":return hn(i,e.conditions,t);case"number":return mn(i,e.conditions,t);case"date":return gn(i,e.conditions,t);case"set":return yn(i,e.values);default:return!0}}function $r(i,e,t){if(i.kind==="condition"){let o=e.get(i.colId);return o?n=>Wr(t(n,o),i.filter):()=>!0}let r=i.children.map(o=>$r(o,e,t));return o=>{let n=i.operator==="or"?r.some(s=>s(o)):r.every(s=>s(o));return i.not?!n:n}}function Yt(i,e,t,r,o){let n=new Map(i.map(d=>[d.id,d])),s=Object.entries(e).flatMap(([d,c])=>{let u=n.get(d);return u?[{column:u,filter:c}]:[]}),a=t?$r(t.root,n,o):()=>!0,l=r?.trim().toLowerCase().split(/\s+/).filter(Boolean)??[];return d=>!s.every(({column:c,filter:u})=>Wr(o(d,c),u))||!a(d)?!1:l.every(c=>i.some(u=>_r(o(d,u)).includes(c)))}var Kr=typeof Intl<"u"?new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"}):null;function vn(i,e){let t=i==null||i==="",r=e==null||e==="";return!t&&!r?null:t&&r?0:t?1:-1}function wn(i,e){let t=Number.isNaN(i),r=Number.isNaN(e);return t||r?t===r?0:t?1:-1:i-e}function bn(i,e){return i===e?0:i?1:-1}function Oe(i,e){let t=vn(i,e);if(t!==null)return t;if(typeof i=="number"&&typeof e=="number")return wn(i,e);if(i instanceof Date&&e instanceof Date)return i.getTime()-e.getTime();if(typeof i=="boolean"&&typeof e=="boolean")return bn(i,e);let r=String(i),o=String(e);return Kr?Kr.compare(r,o):r.localeCompare(o)}function Xt(i,e,t,r){let o=new Map(t.map(a=>[a.id,a])),n=e.flatMap(a=>{let l=o.get(a.colId);return l?[{column:l,compare:l.colDef.comparator??Oe,direction:a.direction}]:[]}),s=i.map(a=>({node:a,values:n.map(({column:l})=>r(a,l))}));return s.sort((a,l)=>{for(let d=0;d<n.length;d++){let c=n[d],u=c.compare(a.values[d],l.values[d],a.node,l.node);if(u!==0)return c.direction==="asc"?u:-u}return 0}),s.map(({node:a})=>a)}function He(i){return i.filter(e=>typeof e=="number"&&!isNaN(e))}var Jt={sum:i=>He(i).reduce((e,t)=>e+t,0),avg:i=>{let e=He(i);return e.length===0?null:e.reduce((t,r)=>t+r,0)/e.length},count:i=>i.length,min:i=>{let e=He(i);return e.length===0?null:Math.min(...e)},max:i=>{let e=He(i);return e.length===0?null:Math.max(...e)},first:i=>i.length>0?i[0]:null,last:i=>i.length>0?i[i.length-1]:null};function Ve(i){let e={...Jt,...i??{}};return t=>e[t]}function ee(i){if(i.reason instanceof Error)return i.reason;let e=new Error(typeof i.reason=="string"?i.reason:"Block request aborted");return e.name="AbortError",e}function Be(i){return Number.isFinite(i)?Math.max(1,Math.trunc(i)):1}var ze=class{constructor(e,t,r=4){this.maxBlocks=e;this.onEvict=t;this.maxConcurrentRequests=r;this.S=new Map;this.x=new Map;this.dn=0;this.generation=0;this.hitCount=0;this.missCount=0;this.evictionCount=0;this.ar=0;this.lr=new Set;this.maxBlocks=Be(e),this.maxConcurrentRequests=Be(r)}configure(e,t=this.maxConcurrentRequests){this.maxBlocks=Be(e),this.maxConcurrentRequests=Be(t),this.Do(),this.dr()}retain(e){this.lr=e,this.Do()}peek(e){let t=this.S.get(e);if(t)return t.touchedAt=++this.dn,t}has(e){return this.S.has(e)}invalidate(e){let t=this.x.get(e);t&&(this.x.delete(e),t.controller.abort(),t.state==="queued"&&t.reject(ee(t.controller.signal)));let r=this.S.get(e);r&&(this.S.delete(e),this.onEvict?.(e,r))}load(e,t,r,o=0){if(r?.aborted)return Promise.reject(ee(r));let n=this.peek(e);if(n)return this.hitCount++,Promise.resolve(n);let s=this.x.get(e);if(s)return this.hitCount++,s.priority=Math.max(s.priority,o),this.dr(),this.cn(e,s,r);this.missCount++;let a=new AbortController,l,d,c=new Promise((p,m)=>{l=p,d=m}),u={controller:a,promise:c,consumers:0,loader:t,priority:o,state:"queued",resolve:l,reject:d};this.x.set(e,u);let h=this.cn(e,u,r);return this.dr(),h}purge(){this.generation++,this.lr.clear();for(let e of this.x.values())e.controller.abort(),e.state==="queued"&&e.reject(ee(e.controller.signal));this.x.clear();for(let[e,t]of this.S)this.onEvict?.(e,t);this.S.clear()}snapshot(){let e=0,t=0;for(let r of this.S.values())e+=r.rows.length;for(let r of this.x.values())r.state==="active"&&t++;return{cachedBlockCount:this.S.size,loadingBlockCount:this.x.size,activeRequestCount:t,queuedRequestCount:Math.max(0,this.x.size-t),cachedRowCount:e,hitCount:this.hitCount,missCount:this.missCount,evictionCount:this.evictionCount}}dr(){for(;this.ar<this.maxConcurrentRequests;){let e,t;for(let[r,o]of this.x)o.state!=="queued"||o.controller.signal.aborted||(!t||o.priority>t.priority)&&(e=r,t=o);if(e==null||!t)return;this.ba(e,t)}}ba(e,t){t.state="active",this.ar++;let r=this.generation;this.Ca(t).then(o=>{r===this.generation&&!t.controller.signal.aborted&&(this.S.set(e,{rows:o.rows,...o.lastRow==null?{}:{lastRow:o.lastRow},touchedAt:++this.dn}),this.Do()),t.resolve(o)},t.reject).finally(()=>{this.ar=Math.max(0,this.ar-1),this.x.get(e)===t&&this.x.delete(e),this.dr()})}Ca(e){let{signal:t}=e.controller;return t.aborted?Promise.reject(ee(t)):new Promise((r,o)=>{let n=()=>o(ee(t));t.addEventListener("abort",n,{once:!0}),Promise.resolve().then(()=>e.loader(t)).then(r,o).finally(()=>{t.removeEventListener("abort",n)})})}cn(e,t,r){return t.consumers++,new Promise((o,n)=>{let s=!1,a=d=>{s||(s=!0,r?.removeEventListener("abort",l),t.consumers=Math.max(0,t.consumers-1),d())},l=()=>a(()=>{t.consumers===0&&this.x.get(e)===t&&(this.x.delete(e),t.controller.abort(r?.reason),t.state==="queued"&&t.reject(ee(t.controller.signal))),n(ee(r))});r?.addEventListener("abort",l,{once:!0}),t.promise.then(d=>a(()=>o(d)),d=>a(()=>n(d instanceof Error?d:new Error(String(d??"Block request failed")))))})}Do(){let e=Math.max(this.maxBlocks,this.lr.size+1);for(;this.S.size>e;){let t=-1,r=Number.POSITIVE_INFINITY;for(let[n,s]of this.S)this.lr.has(n)||s.touchedAt<r&&(t=n,r=s.touchedAt);if(t<0)return;let o=this.S.get(t);this.S.delete(t),this.evictionCount++,o&&this.onEvict?.(t,o)}}};function be(i,e){if(i==null||typeof i!="object")return;let t=i[e];return Array.isArray(t)?t:void 0}var _e=class{constructor(e){this.core=e;this.all=[];this.M=[];this.k=new Map;this.displayed=[];this.r=new Map;this.filterModel={};this.advancedFilterModel=null;this.quickFilter=null;this.g=new Set;this.I=new Set;this.je=[];this.Tt=new Map;this.un=[];this.y=null;this.Ye=!1;this.hn=!1;this.U=0;this.cr=null;this.Dt=null;this.ur=null;this.hr=new WeakMap;this.Rt=new WeakMap;this.he=new Map;this.Et=new Map;this.xt=0;this.pr=0;this.pe=new Map;this.ke=new Map;this.fr=new Set;this.Ie=new Map;this.fe=new ze(12,e=>this.pn(e));this.Mt=0;this.mr=null;this.Ro=!1;this.fn=0;this.N=[];this.page=1;this.pageSize=20;this.advancedFilterModel=H(e.options.advancedFilterModel)}resolveRowId(e,t,r){let o=this.core.options.resolveRowId;if(!o)return r;try{let n=o({data:e,index:t,api:this.core.getApi()});if(typeof n=="string"&&n.length>0)return n;this.core.reportError(new Error("rowKey must resolve to a non-empty identifier"),"rowKey",{index:t})}catch(n){this.core.reportError(n,"rowKey",{index:t})}return r}get w(){return this.core.options.treeData}get o(){return this.core.options.datasource!=null}get B(){return this.o&&this.core.options.datasourceMode==="block"}Xe(){if(this.o){if(this.B)return this.Je();let e=Math.max(0,this.displayed.length-this.all.length);return(this.y??this.all.length)+e}return this.displayed.length}Eo(){return this.xt}gr(){return this.pr}Ta(){return this.hn}xo(e){return!this.o||e?.aborted?Promise.resolve():(this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.core.changeTracker.clear(),this.yr(),this.y=null,this.Ye=!1,this.all=[],this.M=[],this.r.clear(),this.g.clear(),this.core.undoService.clear(),this.a(),this.core.requestUpdate({data:!0}),this.B?(this.fe.configure(this.core.options.maxBlocksInCache,this.core.options.datasourceMaxConcurrentRequests),this.vr(0,e)):this.mn(0,void 0,e))}gn(e){return this.o?this.xo(e):Promise.resolve()}Ae(e){this.hn=e,this.core.skeleton.Ae(e,this.core.getLocaleText("loading"))}mn(e,t,r){if(!this.o||this.Ye||this.y!=null&&e>=this.y)return Promise.resolve();let o=this.core.options.datasource,n=this.core.options.blockSize,s=t??e+n;if(s<=e)return Promise.resolve();let a=++this.U,l=new AbortController,d=()=>l.abort(r?.reason);return r?.addEventListener("abort",d,{once:!0}),this.cr=l,this.Ye=!0,this.Ae(!0),new Promise(c=>{let u=!1,h=0;this.ur=c;let p=g=>{u||(u=!0,r?.removeEventListener("abort",d),a===this.U&&(this.Ye=!1,this.cr=null,this.ur=null,this.Ae(!1),g!=null&&g?.name!=="AbortError"&&this.core.reportError(g,"datasource.getRows",{startRow:e,endRow:s})),c())},m=()=>{if(u||a!==this.U||l.signal.aborted||this.core.isDestroyed()){p();return}h++;let g=!1,v=y=>{if(!(g||u)){if(g=!0,a!==this.U||l.signal.aborted||this.core.isDestroyed()){p();return}if(h<=this.core.options.datasourceRetryCount){let b=this.retryDelay(h);this.Dt=setTimeout(()=>{this.Dt=null,m()},b);return}p(y??new Error("Datasource request failed"))}};try{let y=o.getRows({startRow:e,endRow:s,sortModel:this.core.columnModel.D(),filterModel:this.R(),advancedFilterModel:this.z(),quickFilterText:this.quickFilter,signal:l.signal,onSuccess:(b,C)=>{if(g||u)return;if(g=!0,a!==this.U||this.core.isDestroyed()||l.signal.aborted){p();return}let x=b??[];typeof C=="number"&&C>=0?this.y=C:x.length<s-e&&(this.y=e+x.length);let w=this.all.length===0;this.Da(x),p(),this.a(),this.core.requestUpdate({data:!0}),w&&this.core.relayout(),this.core.headerRenderer.wr()},fail:v});y&&typeof y.catch=="function"&&y.catch(v)}catch(y){v(y)}};m()})}yr(){this.U++,this.Dt!=null&&clearTimeout(this.Dt),this.Dt=null,this.cr?.abort(),this.cr=null,this.Ye=!1,this.Ae(!1),this.ur?.(),this.ur=null,this.fe.purge(),this.pe.clear(),this.ke.clear(),this.fr.clear();for(let[e,t]of this.Ie)this.r.get(e)===t&&this.r.delete(e);this.Ie.clear()}Da(e){for(let t of e){if(t==null)continue;let r=this.all.length,o=this.resolveRowId(t,r,`inf-${this.core.nextId()}`);if(this.r.has(o)){this.core.reportError(new Error(`Duplicate row id: ${o}`),"datasource.getRows",{rowId:o});continue}let n={id:o,data:t,rowIndex:-1,selected:this.core.selectionService.isSelected(o)};this.all.push(n),this.r.set(o,n),this.M.push(n)}}vr(e,t,r=0){if(!this.B||e<0)return Promise.resolve();if(t?.aborted)return Promise.reject(this.yn(t.reason));let o=this.core.options.blockSize,n=this.U,s=e*o;if(s>=this.Je())return Promise.resolve();let a=this.y==null?s+o:Math.min(this.y,s+o),l=this.fe.load(e,d=>this.Ra(s,a,d),t,r);return this.Ae(this.all.length===0&&this.fe.snapshot().loadingBlockCount>0),l.then(d=>{n!==this.U||t?.aborted||this.core.isDestroyed()||!this.B||!this.fe.has(e)||this.fr.has(e)||(this.Ea(e,d),this.a(),this.core.requestUpdate({data:!0}),this.core.headerRenderer.wr(),n===this.U&&!this.core.isDestroyed()&&this.vn(this.core.bodyRenderer.Mo().lastExcl-1))}).catch(d=>{throw d?.name!=="AbortError"&&this.core.reportError(d,"datasource.getRows",{startRow:s,endRow:a}),d}).finally(()=>{n===this.U&&this.Ae(this.all.length===0&&this.fe.snapshot().loadingBlockCount>0)})}Ra(e,t,r){let o=this.core.options.datasource;return new Promise((n,s)=>{let a=0,l=null,d=!1,c=p=>{d||(d=!0,l!=null&&clearTimeout(l),r.removeEventListener("abort",u),s(p instanceof Error?p:new Error(typeof p=="string"?p:"Datasource request failed")))},u=()=>c(this.yn(r.reason));r.addEventListener("abort",u,{once:!0});let h=()=>{if(d)return;if(r.aborted||this.core.isDestroyed()){u();return}a++;let p=!1,m=g=>{if(!(p||d)){if(p=!0,r.aborted||this.core.isDestroyed()){u();return}if(a<=this.core.options.datasourceRetryCount){let v=this.retryDelay(a);l=setTimeout(()=>{l=null,h()},v)}else c(g)}};try{let g=o.getRows({startRow:e,endRow:t,sortModel:this.core.columnModel.D(),filterModel:this.R(),advancedFilterModel:this.z(),quickFilterText:this.quickFilter,signal:r,onSuccess:(v,y)=>{p||d||(p=!0,d=!0,r.removeEventListener("abort",u),n({rows:v??[],...typeof y=="number"&&y>=0?{lastRow:y}:{}}))},fail:m});g&&typeof g.catch=="function"&&g.catch(m)}catch(g){m(g)}};h()})}Ea(e,t){let r=this.core.options.blockSize,o=e*r;this.pn(e),typeof t.lastRow=="number"&&t.lastRow>=0?this.y=t.lastRow:t.rows.length<r&&(this.y=o+t.rows.length),t.rows.forEach((n,s)=>{if(n==null)return;let a=o+s;if(this.y!=null&&a>=this.y)return;let l=this.resolveRowId(n,a,`block-${a}`),d=this.Ie.get(l),c=this.r.get(l);if(c&&c!==d&&c.rowIndex!==a){this.core.reportError(new Error(`Duplicate row id: ${l}`),"datasource.getRows",{rowId:l});return}let u=d??{id:l,data:n,rowIndex:a,selected:this.core.selectionService.isSelected(l)};u.rowIndex=a,u.selected=this.core.selectionService.isSelected(l),this.Ie.delete(l),this.pe.set(a,u),this.ke.delete(a),this.r.set(l,u),this.Rt.set(u,a+1)}),this.wn(),this.fr.add(e)}pn(e){this.fr.delete(e);let t=this.core.options.blockSize,r=e*t,o;for(let n=r;n<r+t;n++){let s=this.pe.get(n);s&&(o??(o=new Set(this.core.changeTracker.getDirtyRowIds())),this.pe.delete(n),o.has(s.id)?this.Ie.set(s.id,s):this.r.get(s.id)===s&&this.r.delete(s.id))}this.wn()}wn(){this.all=[...this.pe.entries()].sort(([e],[t])=>e-t).map(([,e])=>e),this.M=this.all}Je(){if(this.y!=null)return this.y;if(this.core.options.datasourceRowCount!=null)return this.core.options.datasourceRowCount;if(this.pe.size===0)return this.core.options.blockSize;let e=0;for(let t of this.pe.keys())e=Math.max(e,t+1);return e+this.core.options.blockSize}xa(e){let t=this.ke.get(e);if(!t&&(t={id:`__mach_loading_${e}`,data:null,rowIndex:e,selected:!1,loading:!0},this.ke.set(e,t),this.ke.size>2e3)){let r=this.ke.keys().next().value;r!=null&&this.ke.delete(r)}return t}yn(e){if(e instanceof Error)return e;let t=new Error(typeof e=="string"?e:"Operation aborted");return t.name="AbortError",t}retryDelay(e){let t=Math.min(this.core.options.datasourceRetryDelay*2**Math.max(0,e-1),3e4),r=this.core.options.datasourceRetryJitter;return Math.max(0,Math.round(t*(1+(Math.random()*2-1)*r)))}Ma(e){if(this.B){this.vn(e);return}if(!this.o||this.Ye)return;let t=this.all.length;if(this.y!=null&&t>=this.y)return;let r=this.core.options.infiniteBufferRows;if(e+r<t&&e<t)return;let o=this.core.options.blockSize,n=this.y==null?t+o:Math.min(this.y,t+o);this.mn(t,n)}vn(e){if(e<0)return;this.bn();let t=this.core.options.blockSize,r=Math.floor(e/t),o=Math.floor(this.core.bodyRenderer.Mo().first/t),n=this.core.options.blockPrefetch,s=r<this.fn?-1:1;this.fn=r;for(let a=o;a<r;a++)this.vr(a,void 0,n+2).catch(()=>{});for(let a=0;a<=n;a++){let l=a===0?[r]:[r+s*a,r-s*a];for(let d of l)d<0||d*t>=this.Je()||this.vr(d,void 0,n-a+1).catch(()=>{})}}ie(){return this.gn().catch(()=>{})}Sa(){return this.yr(),this.o?this.xo().catch(()=>{}):(this.y=null,this.me(this.core.options.rowData),this.core.requestUpdate({data:!0}),Promise.resolve())}destroy(){this.yr(),this.Cn(),this.So(),this.all=this.M=this.displayed=this.N=[],this.r.clear(),this.k.clear(),this.Tt.clear(),this.un=[],this.g.clear(),this.I.clear(),this.je=[],this.core.options.dataProcessor?.destroy?.()}ko(e,t,r){if(!this.B)return Promise.resolve();this.bn();let o=this.core.options.blockSize,n=Math.max(0,Math.trunc(e)),s=Math.min(this.Je(),Math.max(n,Math.trunc(t))),a=Math.floor(n/o),l=Math.max(a,Math.floor(Math.max(n,s-1)/o)),d=[];for(let c=a;c<=l;c++)d.push(this.vr(c,r,100));return Promise.all(d).then(()=>{})}Io(){this.B&&(this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.core.changeTracker.clear(),this.yr(),this.core.undoService.clear(),this.all=[],this.M=[],this.r.clear(),this.a(),this.core.requestUpdate({data:!0}))}Ao(){return this.fe.snapshot()}bn(){let e=new Set(this.core.changeTracker.getDirtyRowIds());for(let[l,d]of this.Ie)e.has(l)||(this.Ie.delete(l),this.r.get(l)===d&&this.r.delete(l));let t=this.core.options.blockSize,r=new Set,{first:o,lastExcl:n}=this.core.bodyRenderer.Mo();for(let l=o;l<n;l+=t)r.add(Math.floor(l/t));n>o&&r.add(Math.floor((n-1)/t));let s=this.core.bodyRenderer.c;s&&r.add(Math.floor(s.rowIndex/t));let a=this.core.editingService.ka();a!=null&&r.add(Math.floor(a/t)),this.fe.retain(r)}me(e){this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.Cn(),this.core.changeTracker.clear();let t=this.core.options.resolveRowId,r=this.core.options.childrenKey,o=[],n=[],s=new Map,a=new Map,l=0,d=(c,u,h)=>{let p=l++,m=this.resolveRowId(c,p,`auto-${p}`);if(s.has(m))return this.core.reportError(new Error(`Duplicate row id: ${m}`),"rowData",{rowId:m,index:p}),null;let g=this.w?be(c,r):void 0,v={id:m,data:c,rowIndex:-1,selected:!1,treeChildrenLoaded:Array.isArray(g)};if(this.hr.set(v,u),o.push(v),s.set(m,v),h!=null){let y=a.get(h)??[];y.push(m),a.set(h,y)}else n.push(v);if(this.w&&Array.isArray(g))for(let y of g)y!=null&&d(y,u+1,m);return v};(e??[]).forEach(c=>{c!=null&&d(c,0,null)}),this.all=o,this.M=n,this.k=a,this.r=s,this.core.undoService.clear();for(let c of[...this.g])s.has(c)||this.g.delete(c);if(this.core.options.defaultExpandAll)for(let c of o)this.Tn(c.id)>0&&this.g.add(c.id);this.core.selectionService.onRowsRebuilt(t!=null),this.a()}St(e){return this.k.get(e)??[]}Tn(e){return this.k.get(e)?.length??0}Lo(e){return this.Tn(e)>0}isTreeRowLoading(e){return this.r.get(e)?.treeLoading===!0}Cn(){for(let e of this.he.values())e.abort();this.he.clear(),this.Et.clear()}loadTreeChildren(e,t=!1){let r=this.r.get(e),o=this.core.options.loadTreeChildren;if(!this.w||!r?.data||!o)return Promise.resolve([]);if(!t&&r.treeChildrenLoaded)return Promise.resolve(this.St(e).flatMap(l=>{let d=this.r.get(l)?.data;return d==null?[]:[d]}));let n=this.Et.get(e);if(n&&!t)return n;this.he.get(e)?.abort();let s=new AbortController;this.he.set(e,s),r.treeLoading=!0,r.treeLoadError=void 0,this.core.requestUpdate({data:!0});let a=Promise.resolve().then(()=>o({data:r.data,node:r,api:this.core.getApi(),signal:s.signal})).then(l=>{if(s.signal.aborted||this.core.isDestroyed())return[];if(!Array.isArray(l))throw new TypeError("[MachTable] loadTreeChildren must resolve to an array.");return this.Ia(r,l),r.treeChildrenLoaded=!0,r.treeLoadError=void 0,this.core.emit("treeChildrenLoaded",{rowId:e,rowNode:r,children:l}),l}).catch(l=>{if(s.signal.aborted||l?.name==="AbortError")return[];throw r.treeLoadError=l,r.treeChildrenLoaded=!1,this.core.reportError(l,"treeData.loadChildren",{rowId:e}),this.core.emit("treeChildrenLoadFailed",{rowId:e,rowNode:r,error:l}),l}).finally(()=>{this.he.get(e)===s&&(this.he.delete(e),this.Et.delete(e),r.treeLoading=!1,this.core.requestUpdate({data:!0}))});return this.Et.set(e,a),a}Ia(e,t){let r=new Set,o=[...this.St(e.id)];for(;o.length>0;){let s=o.pop();r.has(s)||(r.add(s),o.push(...this.St(s)))}this.Aa(t,r);for(let s of r)this.he.get(s)?.abort(),this.he.delete(s),this.Et.delete(s),this.k.delete(s),this.r.delete(s),this.g.delete(s);this.k.delete(e.id);let n=this.Po(e)+1;for(let s of t)s!=null&&this.Go(e,s,n);this.Dn(),this.core.selectionService.onRowsRebuilt(this.core.options.resolveRowId!=null),this.a(),this.core.requestUpdate({data:!0})}Aa(e,t){let r=this.core.options.resolveRowId,o=r?new Set([...this.r.keys()].filter(l=>!t.has(l))):null,n=new WeakSet,s=[...e],a=0;for(;s.length>0;){let l=s.pop();if(l==null)continue;if(typeof l=="object"){if(n.has(l))throw new TypeError("[MachTable] Lazy tree children contain a cyclic object graph.");n.add(l)}if(r&&o){let c=r({data:l,index:a++,api:this.core.getApi()});if(typeof c!="string"||c.length===0)throw new TypeError("[MachTable] rowKey must resolve to a non-empty identifier for lazy tree children.");if(o.has(c))throw new Error(`Duplicate row id: ${c}`);o.add(c)}let d=be(l,this.core.options.childrenKey);d&&s.push(...d)}}kt(e,t=!0){let r=this.core.options.resolveRowId,o=[],n=[];if(e.remove?.length){let a=new Set,l=new Set,d=u=>{if(r){let p=[this.resolveRowId(u,-1,`__missing_remove_${this.core.nextId()}`)];for(;p.length>0;){let m=p.pop();if(!a.has(m)){a.add(m);for(let g of this.k.get(m)??[])p.push(g)}}}else{let h=[u];for(;h.length>0;){let p=h.pop();l.add(p);let m=this.w?be(p,this.core.options.childrenKey):void 0;if(m)for(let g of m)h.push(g)}}};e.remove.forEach(d),this.all=this.all.filter(u=>{let h=a.has(u.id)||u.data!=null&&l.has(u.data);return h&&(n.push(u.id),this.r.delete(u.id),this.k.delete(u.id)),!h});let c=new Set(this.all);this.M=this.M.filter(u=>c.has(u))}if(e.update?.length)for(let a of e.update){let l;r?l=this.r.get(this.resolveRowId(a,-1,`__missing_update_${this.core.nextId()}`)):l=this.all.find(d=>d.data===a),l&&(l.data=a,n.push(l.id),this.core.bodyRenderer.br(l),o.push(l))}if(e.add?.length){let a=e.addIndex!=null?Math.max(0,Math.min(e.addIndex,this.M.length)):this.M.length,l=[];e.add.forEach((d,c)=>{let u=this.resolveRowId(d,a+c,`add-${this.core.nextId()}`);if(this.r.has(u)){this.core.reportError(new Error(`Duplicate row id: ${u}`),"transaction.add",{rowId:u});return}let h={id:u,data:d,rowIndex:-1,selected:!1};this.r.set(u,h),this.hr.set(h,0);let p=this.w?be(d,this.core.options.childrenKey):void 0;if(p)for(let m of p)m!=null&&this.Go(h,m,1);l.push(h)}),this.M.splice(a,0,...l),this.Dn()}let s=this.La(e);return t&&(s?this.a():o.length>0&&this.Rn()),this.core.changeTracker.clearRows(n),{pipelineChanged:s,updatedRowIds:o.map(a=>a.id)}}Pa(e){if(e.length===0)return{pipelineChanged:!1,updatedRowIds:[]};let t=!1,r=new Set;for(let o of e){let n=this.kt(o,!1);t||(t=n.pipelineChanged);for(let s of n.updatedRowIds)r.add(s)}return t?this.a():r.size>0&&this.Rn(),{pipelineChanged:t,updatedRowIds:[...r]}}La(e){return e.add?.length||e.remove?.length?!0:e.update?.length?this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0||!this.core.options.manualFiltering&&this.Cr()||!this.core.options.manualSorting&&this.core.columnModel.D().length>0||this.core.options.getRowHeight?!0:this.core.columnModel.e().some(t=>t.colDef.autoHeight===!0||t.colDef.autoRowSpan===!0||t.colDef.rowSpan!=null):!1}Rn(){this.core.emit("modelUpdated",{rowCount:this.N.length})}Go(e,t,r){let o=this.resolveRowId(t,-1,`add-${this.core.nextId()}`);if(this.r.has(o)){this.core.reportError(new Error(`Duplicate row id: ${o}`),"transaction.add",{rowId:o});return}let n=be(t,this.core.options.childrenKey),s={id:o,data:t,rowIndex:-1,selected:!1,treeChildrenLoaded:Array.isArray(n)};this.r.set(o,s),this.hr.set(s,r);let a=this.k.get(e.id)??[];if(a.push(s.id),this.k.set(e.id,a),!!n)for(let l of n)l!=null&&this.Go(s,l,r+1)}Dn(){this.all=[];let e=t=>{this.all.push(t),this.r.has(t.id)||this.r.set(t.id,t);for(let r of this.k.get(t.id)??[]){let o=this.r.get(r);o&&e(o)}};for(let t of this.M)e(t)}It(e){let t=JSON.stringify(this.filterModel),r=new Set(this.core.columnModel.G().map(o=>o.id));return this.filterModel=U(e,r),JSON.stringify(this.filterModel)!==t}R(){return{...this.filterModel}}Ze(e){let t=new Set(this.core.columnModel.G().map(n=>n.id)),r=H(e,t),o=JSON.stringify(this.advancedFilterModel);return this.advancedFilterModel=r,this.core.options.advancedFilterModel=r,JSON.stringify(r)!==o}z(){return H(this.advancedFilterModel)}Qe(e){let t=e!=null&&e.trim()!==""?e:null;return t===this.quickFilter?!1:(this.quickFilter=t,!0)}At(){return this.quickFilter}Cr(){return Object.keys(this.filterModel).length>0||this.advancedFilterModel!=null||this.quickFilter!=null}a(){let e=this.core.performanceMonitor.start(),t=this.core.columnModel.e(),r=(s,a)=>this.core.getCellValue(s,a);if(this.o){this.Ga(e);return}if(this.Na(e))return;let o;if(this.w)o=this.Fa(t,r);else{o=this.all,this.Cr()&&!this.core.options.manualFiltering&&(o=o.filter(Yt(t,this.filterModel,this.advancedFilterModel,this.quickFilter,r)));let a=this.core.columnModel.D();if(a.length>0&&!this.core.options.manualSorting)try{o=Xt(o,a,t,r)}catch(d){this.core.reportError(d,"comparator",{sortModel:a})}let l=this.core.columnModel.re();if(l.length>0)o=this.Oa(o,l);else if(this.core.options.masterDetail){let d=[];for(let c of o)d.push(c),this.g.has(c.id)&&this.isRowExpandable(c)&&d.push({id:`__detail__${c.id}`,data:c.data,rowIndex:-1,selected:!1,isDetail:!0,masterId:c.id});o=d}}for(let s of this.all)s.rowIndex=-1;let n=0;o.forEach((s,a)=>{s.rowIndex=a,!s.isDetail&&!s.isGroup&&(n++,this.Rt.set(s,n))}),this.N=o,this.et(),this.En(r),this.core.emit("modelUpdated",{rowCount:o.length}),this.core.performanceMonitor.recordModel(e)}Ga(e){this.all.forEach((t,r)=>{this.B||(t.rowIndex=r),this.Rt.set(t,this.B?t.rowIndex+1:r+1)}),this.displayed=this.all,this.N=this.all,this.Tt.clear(),this.xt++,this.core.emit("modelUpdated",{rowCount:this.all.length}),this.core.performanceMonitor.recordModel(e)}Na(e){let t=this.Ro;return this.Ro=!1,!t&&this.Ha()?(this.Va(e),!0):(this.So(),!1)}Ha(){if(!this.core.options.dataProcessor||this.all.length<this.core.options.dataProcessorMinRows||this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0)return!1;let e=!this.core.options.manualFiltering&&this.Cr(),t=!this.core.options.manualSorting&&this.core.columnModel.D().length>0;return e||t}Va(e){this.So();let t=this.core.options.dataProcessor;if(!t)return;let r=++this.Mt,o=new AbortController;this.mr=o;let n=this.core.columnModel.e(),s=this.all.flatMap(d=>d.data==null?[]:[{id:d.id,data:d.data}]),a=!this.core.options.manualFiltering,l=!this.core.options.manualSorting;Promise.resolve().then(()=>t.process({rows:s,columns:n.map(d=>({colId:d.id,...d.colDef.field?{field:d.colDef.field}:{}})),sortModel:l?this.core.columnModel.D():[],filterModel:a?this.R():{},advancedFilterModel:a?this.z():null,quickFilterText:a?this.quickFilter:null,signal:o.signal})).then(d=>{if(r!==this.Mt||o.signal.aborted||this.core.isDestroyed())return;let c=new Set,u=[];for(let p of d.rowIds){if(c.has(p))continue;c.add(p);let m=this.r.get(p);m&&!m.isDetail&&!m.isGroup&&u.push(m)}for(let p of this.all)p.rowIndex=-1;u.forEach((p,m)=>{p.rowIndex=m,this.Rt.set(p,m+1)}),this.N=u,this.et();let h=(p,m)=>this.core.getCellValue(p,m);this.En(h),this.core.emit("modelUpdated",{rowCount:u.length}),this.core.performanceMonitor.recordModel(e),this.core.requestUpdate({data:!0})}).catch(d=>{r!==this.Mt||o.signal.aborted||this.core.isDestroyed()||(this.core.reportError(d,"dataProcessor.process"),this.Ro=!0,this.a(),this.core.requestUpdate({data:!0}))}).finally(()=>{r===this.Mt&&(this.mr=null)})}So(){this.Mt++,this.mr?.abort(),this.mr=null}get j(){return this.core.options.paginationEnabled&&!this.o}et(){if(!this.j){this.displayed=this.N,this.xt++;return}let e=this.Lt(),t=this.getPageCount();if(this.page>t&&(this.page=t),this.page<1&&(this.page=1),this.core.options.paginationPage=this.page,this.core.options.paginationMode==="server"){this.N.forEach((n,s)=>{n.rowIndex=s}),this.displayed=this.N,this.xt++;return}let r=(this.page-1)*e,o=this.N.slice(r,r+e);o.forEach((n,s)=>{n.rowIndex=s}),this.displayed=o,this.xt++}Lt(){return this.pageSize=this.core.options.paginationPageSize,Math.max(1,this.pageSize)}Pt(){return this.j?this.page:1}getTotalRowCount(){return this.o?this.Xe():this.j&&this.core.options.paginationMode==="server"?this.core.options.paginationTotal:this.N.length}getPageCount(){return this.j?Math.max(1,Math.ceil(this.getTotalRowCount()/this.Lt())):1}xn(){return this.N}setPage(e,t=!1){if(!this.j)return;let r=this.getPageCount(),o=Math.max(1,Math.min(Math.round(e)||1,r));o!==this.page&&(this.page=o,this.core.options.paginationPage=o,this.et(),this.core.requestUpdate({data:!0}),this.core.bodyRenderer.tt(0,"top"),t||this.Tr())}setPageSize(e){if(!this.j)return;let t=Math.max(1,Math.round(e)||this.Lt()),r=(this.page-1)*this.Lt();this.core.options.paginationPageSize=t,this.pageSize=t,this.page=Math.floor(r/t)+1,this.core.options.paginationPage=this.page,this.et(),this.core.requestUpdate({data:!0}),this.Tr()}Mn(e,t){this.pageSize=Math.max(1,Math.round(t)||1),this.core.options.paginationPageSize=this.pageSize,this.page=Math.max(1,Math.round(e)||1),this.core.options.paginationPage=this.page}Dr(e){this.core.options.paginationEnabled!==e&&(this.core.options.paginationEnabled=e&&!this.o,this.core.options.paginationEnabled&&(this.page=1),this.et(),this.core.requestUpdate({data:!0}),this.Tr())}Ba(){this.j&&(this.page=this.core.options.paginationMode==="server"?this.core.options.paginationPage:1,this.et(),this.core.requestUpdate({data:!0}),this.Tr())}Tr(){this.core.emit("paginationChanged",{page:this.Pt(),pageSize:this.Lt(),pageCount:this.getPageCount(),total:this.getTotalRowCount()})}Fa(e,t){let r=this.core.options.manualSorting?[]:this.core.columnModel.D(),o=new Map,n=this.Cr()&&!this.core.options.manualFiltering,s=Yt(e,this.filterModel,this.advancedFilterModel,this.quickFilter,t),a=c=>{let u=o.get(c.id);if(u!==void 0)return u;let h=!0;if(n){h=s(c);for(let p of this.k.get(c.id)??[]){let m=this.r.get(p);m&&a(m)&&(h=!0)}}return o.set(c.id,h),h},l=[],d=c=>{let u=c;r.length>0&&(u=Xt(c,r,e,t));for(let h of u)if(a(h)&&(l.push(h),this.g.has(h.id))){let p=(this.k.get(h.id)??[]).map(m=>this.r.get(m)).filter(m=>m!=null);d(p)}};return d(this.M),l}za(){let e=this.un,t=0;for(let r of this.displayed)!r.isDetail&&!r.isGroup&&(e[t++]=r);return e.length=t,e}_a(e,t,r,o){let n=t.colDef.rowSpan;if(!n)return 1;try{let s=n({api:this.core.getApi(),colDef:t.colDef,column:t,node:e,data:e.data,value:r,rowIndex:e.rowIndex});return Math.max(1,Math.min(Math.round(s)||1,o))}catch(s){return this.core.reportError(s,"rowSpan",{colId:t.id,rowId:e.id}),1}}Wa(e,t,r,o,n){if(!r.colDef.autoRowSpan||o==null||o==="")return 1;let s=1;for(;t+s<e.length&&Oe(o,n(e[t+s],r))===0;)s++;return s}$a(e,t,r){let o=new Int32Array(e.length),n=0;for(;n<e.length;){let s=e[n],a=r(s,t),l=t.colDef.rowSpan?this._a(s,t,a,e.length-n):this.Wa(e,n,t,a,r);o[n]=l;for(let d=1;d<l;d++)o[n+d]=-1;n+=l}return o}En(e){if(this.Tt.clear(),this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0)return;let t=this.core.columnModel.e().filter(o=>o.colDef.rowSpan!=null||o.colDef.autoRowSpan===!0);if(t.length===0)return;let r=this.za();if(r.length!==0)for(let o of t)this.Tt.set(o.id,this.$a(r,o,e))}Ka(e){return this.Tt.get(e)}Sn(e){return this.Rt.get(e)??0}Po(e){return this.hr.get(e)??0}Oa(e,t){let r=Ve(this.core.options.aggFuncs),o=this.core.columnModel.ya();this.je=[];let n=a=>{let l={};for(let d of o){let c=r(d.colDef.aggFunc);if(c)try{l[d.id]=c(a.map(u=>this.core.getCellValue(u,d)))}catch(u){this.core.reportError(u,"aggFunc",{colId:d.id,aggFunc:d.colDef.aggFunc}),l[d.id]=null}}return l},s=(a,l,d)=>{if(l>=t.length)return{display:a,leaves:a};let c=t[l],u=new Map,h=[];for(let g of a){let v=this.core.getCellValue(g,c),y=v==null?"(\u7A7A)":String(v),b=u.get(y);b||(b=[],u.set(y,b),h.push(y)),b.push(g)}h.sort((g,v)=>g.localeCompare(v,void 0,{numeric:!0,sensitivity:"base"}));let p=[],m=[];for(let g of h){let v=u.get(g),y=`${d}/g${l}:${g}`;this.je.push(y);let b=s(v,l+1,y),C={id:y,data:null,rowIndex:-1,selected:!1,isGroup:!0,groupLevel:l,groupKey:g,leafNodes:b.leaves,aggValues:n(b.leaves)};p.push(C),this.I.has(y)&&p.push(...b.display),m.push(...b.leaves)}return{display:p,leaves:m}};return s(e,0,"").display}isRowExpandable(e){if(this.w){if(this.Lo(e.id)||e.treeLoading)return!0;if(e.treeChildrenLoaded||!e.data||!this.core.options.loadTreeChildren)return!1;let r=this.core.options.isTreeRowExpandable;if(!r)return!1;try{return r({data:e.data,node:e,api:this.core.getApi()})}catch(o){return this.core.reportError(o,"isTreeRowExpandable",{rowId:e.id}),!1}}if(!this.core.options.masterDetail)return!1;let t=this.core.options.isRowExpandable;if(t)try{return t({data:e.data,node:e,api:this.core.getApi()})}catch(r){return this.core.reportError(r,"isRowExpandable",{rowId:e.id}),!1}return!0}isRowExpanded(e){return this.g.has(e)}qa(){return[...this.g]}Ua(){return[...this.I]}ja(e,t){this.g=new Set(e.filter(r=>this.r.has(r))),this.I=new Set(t)}No(e){return this.Fo(e,!0)}Oo(e){return this.Fo(e,!1)}toggleDetail(e){return this.Fo(e,!this.g.has(e))}Fo(e,t){let r=this.r.get(e);return!r||t&&!this.isRowExpandable(r)?!1:(t===this.g.has(e)||(t?this.g.add(e):this.g.delete(e),this.a(),this.core.requestUpdate({data:!0}),this.core.emit("detailToggled",{rowId:e,rowNode:r,expanded:t}),t&&this.w&&!this.Lo(e)&&!r.treeLoading&&this.loadTreeChildren(e).catch(()=>{})),t)}Ho(){let e=!1;for(let t of this.all)!this.g.has(t.id)&&this.isRowExpandable(t)&&(this.g.add(t.id),e=!0);e&&(this.a(),this.core.requestUpdate({data:!0}))}Vo(){this.g.size!==0&&(this.g.clear(),this.a(),this.core.requestUpdate({data:!0}))}Bo(e){return this.setGroupExpanded(e,!this.I.has(e))}isGroupExpanded(e){return this.I.has(e)}uh(e){return this.displayed.find(t=>t.isGroup&&t.id===e)}zo(){if(this.je.length===0)return;let e=!1;for(let t of this.je)this.I.has(t)||(this.I.add(t),e=!0);e&&(this.a(),this.core.requestUpdate({data:!0}))}_o(){this.I.size!==0&&(this.I.clear(),this.a(),this.core.requestUpdate({data:!0}))}setGroupExpanded(e,t){return!this.je.includes(e)||t===this.I.has(e)||(t?this.I.add(e):this.I.delete(e),this.a(),this.core.requestUpdate({data:!0})),t}kn(){return!this.w&&!this.o&&!this.core.options.dataProcessor&&this.core.options.paginationMode!=="server"&&this.core.columnModel.D().length===0&&this.core.columnModel.re().length===0}In(e,t){if(!this.kn()||!Number.isInteger(e)||!Number.isInteger(t))return!1;let r=this.i(e),o=this.i(t);if(!r||!o||r.isDetail||o.isDetail||r.isGroup||o.isGroup)return!1;let n=this.all.indexOf(r),s=this.all.indexOf(o);return n<0||s<0||n===s?!1:(this.all.splice(n,1),this.all.splice(s,0,r),this.a(),this.core.requestUpdate({data:!0}),!0)}_(){return this.all}Ya(){return this.M}ge(){return this.displayed}f(){return this.B?this.Je():this.displayed.length}i(e){return this.B?e<0||e>=this.Je()?void 0:this.pe.get(e)??this.xa(e):this.displayed[e]}T(e){return this.r.get(e)}Wo(e){this.all.forEach(e)}$o(e){let t=0;for(let r of this.N)r.isDetail||r.isGroup||e(r,t++)}};var We=class{constructor(e){this.core=e;this.h=new Set;this.ne=null;this.Gt=new Set}isSelected(e){return this.h.has(e)}isIndeterminate(e){return this.Gt.has(e)}isSelectable(e){if(e.loading)return!1;let t=this.Xa(e),r=t?.colDef.selectable;if(!t||!r)return!0;try{return r({api:this.core.getApi(),colDef:t.colDef,column:t,node:e,data:e.data,value:this.core.getCellValue(e,t),rowIndex:e.rowIndex})}catch(o){return this.core.reportError(o,"selectable",{rowId:e.id,colId:t?.id}),!1}}Xa(e){if(!(e.isGroup||e.isDetail))return this.core.columnModel.e().find(t=>t.hasCheckbox&&t.colDef.selectable!=null)}getSelectedNodes(){return this.core.rowModel._().filter(e=>this.h.has(e.id))}getSelectedRows(){return this.getSelectedNodes().filter(e=>e.data!=null).map(e=>e.data)}getSelectedIds(){return[...this.h]}restoreSelection(e){let t=new Set(e),r=this.core.rowModel._().filter(o=>t.has(o.id)&&!o.isDetail&&!o.isGroup).map(o=>({node:o,selected:!0}));this.W(r,!0)}onRowsRebuilt(e){if(!e)this.h.clear(),this.ne=null;else{let t=new Set(this.core.rowModel._().map(r=>r.id));for(let r of[...this.h])t.has(r)||this.h.delete(r);this.ne!=null&&!t.has(this.ne)&&(this.ne=null)}for(let t of this.core.rowModel._())t.selected=this.h.has(t.id);this.An()}getGroupSelectionState(e){let t=e.leafNodes??[];if(t.length===0)return{all:!1,some:!1};let r=0,o=0;for(let n of t)this.isSelectable(n)&&(r++,this.h.has(n.id)&&o++);return r===0?{all:!1,some:!1}:{all:o===r,some:o>0}}setGroupSelected(e,t){let r=(e.leafNodes??[]).filter(o=>this.isSelectable(o));r.length!==0&&this.W(r.map(o=>({node:o,selected:t})))}setNodeSelected(e,t,r=!1){this.W([{node:e,selected:t,clearOthers:r}])}selectNodeById(e,t=!0,r=!0){let o=this.core.rowModel.T(e);o&&this.setNodeSelected(o,t,r)}Ja(e,t){let r=t==="single";this.W([{node:e,selected:r?!0:!e.selected,clearOthers:r}]),this.ne=e.id}Za(e,t,r){return!r||!t.ctrlKey&&!t.metaKey?!1:(this.W([{node:e,selected:!e.selected}]),this.ne=e.id,!0)}Qa(e,t,r){if(!r||!t.shiftKey||this.ne==null)return!1;let o=this.core.rowModel.T(this.ne);if(!o||o.rowIndex<0||e.rowIndex<0)return!1;let n=Math.min(o.rowIndex,e.rowIndex),s=Math.max(o.rowIndex,e.rowIndex),a=[];for(let l=n;l<=s;l++){let d=this.core.rowModel.i(l);d&&!d.isDetail&&!d.isGroup&&this.isSelectable(d)&&a.push({node:d,selected:!0})}return this.W(a),!0}onRowClick(e,t,r){let o=this.core.options.rowSelection;if(o==="none"||!this.isSelectable(e))return;if(r){this.Ja(e,o);return}let n=o==="multiple";this.Za(e,t,n)||this.Qa(e,t,n)||(this.W([{node:e,selected:!0,clearOthers:!0}]),this.ne=e.id)}selectAll(e=!0){let t=this.core.options.rowSelection;if(t==="none")return;let o=(e?this.core.rowModel.ge():this.core.rowModel._()).filter(n=>!n.isDetail&&!n.isGroup&&this.isSelectable(n));if(o.length!==0){if(t==="single"){this.W([{node:o[0],selected:!0,clearOthers:!0}]);return}this.W(o.map(n=>({node:n,selected:!0})))}}deselectAll(){this.W([],!0)}isSelectAllActive(){let t=this.core.rowModel.ge().filter(r=>!r.isDetail&&!r.isGroup).filter(r=>this.isSelectable(r));if(t.length===0)return!1;if(this.core.rowModel.o){let r=this.core.rowModel.Xe();if(t.length<r)return!1}return t.every(r=>this.h.has(r.id))}isSelectAllIndeterminate(){let t=this.core.rowModel.ge().filter(o=>!o.isDetail&&!o.isGroup).filter(o=>this.isSelectable(o)),r=t.reduce((o,n)=>o+(this.h.has(n.id)?1:0),0);if(r===0)return!1;if(this.core.rowModel.o){let o=this.core.rowModel.Xe();if(t.length<o)return!0}return r>0&&r<t.length}applySelectionPublic(e,t=!1){this.W(e,t)}tl(e,t,r){!t&&!e.some(o=>o.clearOthers)||(this.h=t?new Set:new Set(e.filter(o=>o.selected).flatMap(o=>r?this.Ln(o.node):[o.node.id])))}rl(e,t){for(let r of e){if(!this.isSelectable(r.node))continue;let o=t?this.Ln(r.node):[r.node.id];for(let n of o)r.selected?this.h.add(n):this.h.delete(n)}}ol(e){let t=new Set;for(let r of new Set([...e,...this.h]))e.has(r)!==this.h.has(r)&&t.add(r);return t}il(e,t,r){let o=[],n=new Set([...e,...r,...this.Gt]);for(let s of this.core.rowModel._()){let a=this.h.has(s.id);s.selected=a,(n.has(s.id)||t.get(s.id)!==a)&&s.rowIndex>=0&&o.push(s.rowIndex)}return o}W(e,t=!1){let r=new Set(this.h),o=this.core.rowModel.w&&this.core.options.autoCheckedChildren;this.tl(e,t,o),this.rl(e,o);let n=this.ol(r),s=new Map;for(let d of this.core.rowModel._())s.set(d.id,d.selected);let a=new Set(this.Gt);this.An();let l=this.il(n,s,a);n.size>0&&(this.core.bodyRenderer.ye(l),this.core.headerRenderer.wr(),this.core.emit("selectionChanged",{selectedNodes:this.getSelectedNodes(),selectedRows:this.getSelectedRows()}))}Ln(e){let t=[e.id],r=o=>{for(let n of this.core.rowModel.St(o))t.push(n),r(n)};return r(e.id),t}An(){if(this.Gt.clear(),!this.core.rowModel.w)return;let e=t=>{let r=this.core.rowModel.St(t);if(r.length===0)return{all:this.h.has(t),some:this.h.has(t)};let o=!0,n=!1;for(let s of r){let a=e(s);a.all?n=!0:(a.some&&(n=!0),o=!1)}return n&&!o&&this.Gt.add(t),o?this.h.add(t):this.h.delete(t),{all:o,some:n}};for(let t of this.core.rowModel.Ya())e(t.id);for(let t of this.core.rowModel._())t.selected=this.h.has(t.id)}};var $e=class{constructor(e){this.core=e;this.active=null;this.A=0;this.ve=0;this.Y=null;this.Le=null;this.we=e=>{let t=this.qo(e);t&&(this.ve=this.Fn(t,e.clientX),t.didResize||(t.didResize=Math.abs(this.ve-t.startWidth)>=.5),!this.A&&(this.A=requestAnimationFrame(()=>{this.A=0,this.sl()})))};this.X=e=>{let t=this.qo(e);t&&(this.ve=this.Fn(t,e.clientX),t.didResize||(t.didResize=Math.abs(this.ve-t.startWidth)>=.5),this.al(t))};this.Pe=e=>{this.qo(e)&&this.cancelResize()};this.Pn=()=>{this.cancelResize()}}startResize(e,t){if(!this.core.options.enableColumnResize||!t.resizable||e.isPrimary===!1)return;this.cancelResize();let r=e.currentTarget,o=t.currentWidth;this.ve=o,this.active={column:t,didResize:!1,handle:r,pointerId:e.pointerId,startFlex:t.flex,startManualWidth:t.manualWidth,startWidth:o,startX:e.clientX},window.addEventListener("pointermove",this.we),window.addEventListener("pointerup",this.X,!0),window.addEventListener("pointercancel",this.Pe,!0),r.addEventListener("lostpointercapture",this.Pn);try{r.setPointerCapture?.(e.pointerId)}catch{}this.core.skeleton.root.classList.add("mach-root--resizing"),r.classList.add("mach-header-resize--active"),this.nl(this.active)}cancelResize(e=!0){let t=this.active;t&&(this.active=null,this.Ko(),this.Gn(t),e&&(t.column.manualWidth=t.startManualWidth,t.column.flex=t.startFlex,this.core.relayoutColumns()),this.core.skeleton.root.classList.remove("mach-root--resizing"),this.Nn(t))}al(e){this.active=null,this.Ko(),e.didResize&&(Math.abs(this.ve-e.startWidth)<.5?(e.column.manualWidth=e.startManualWidth,e.column.flex=e.startFlex):this.core.columnModel.oe(e.column,this.ve),this.core.relayoutColumns()),this.Gn(e);try{e.handle.releasePointerCapture?.(e.pointerId)}catch{}this.core.skeleton.root.classList.remove("mach-root--resizing"),this.Nn(e),e.didResize&&this.core.commitColumnWidths([e.column])}sl(){let e=this.active;!e||!this.core.columnModel.oe(e.column,this.ve)||(this.core.relayoutColumns(),this.Nt(e),this.core.emitColumnResize(e.column,!1))}nl(e){this.Y=document.createElement("div"),this.Y.className="mach-column-resize-guide",this.Y.setAttribute("aria-hidden","true"),this.Le=document.createElement("span"),this.Le.className="mach-column-resize-label",this.Y.appendChild(this.Le),this.core.skeleton.root.appendChild(this.Y),this.Nt(e)}Nt(e){if(!this.Y||!this.Le)return;let t=this.core.skeleton.root,r=t.getBoundingClientRect(),o=e.handle.parentElement.getBoundingClientRect(),n=Math.max(0,Math.min(t.clientWidth,o.right-r.left-t.clientLeft)),s=Math.max(32,Math.min(t.clientWidth-32,n));this.Y.style.left=`${n}px`,this.Y.style.top=`${Math.max(0,o.top-r.top-t.clientTop)}px`,this.Le.style.left=`${s-n}px`,this.Le.textContent=`${Math.round(e.column.currentWidth)} px`}Nn(e){e.handle.classList.remove("mach-header-resize--active"),this.Y?.remove(),this.Y=null,this.Le=null}Fn(e,t){let r=Number.isFinite(t)?t:e.startX;return e.startWidth+r-e.startX}qo(e){let t=this.active;return t&&e.pointerId===t.pointerId?t:null}Ko(){this.A&&cancelAnimationFrame(this.A),this.A=0}Gn(e){window.removeEventListener("pointermove",this.we),window.removeEventListener("pointerup",this.X,!0),window.removeEventListener("pointercancel",this.Pe,!0),e.handle.removeEventListener("lostpointercapture",this.Pn)}destroy(){this.cancelResize(!1),this.Ko(),this.core.skeleton.root?.classList.remove("mach-root--resizing")}};function f(i,e,t){let r=document.createElement(i);if(e&&(r.className=e),t)for(let o of Object.keys(t))r.setAttribute(o,t[o]);return r}var Cn=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function L(i,e){if(i.classList.add("mach-portal"),!e)return;let t=window.getComputedStyle(e);for(let r of Cn){let o=t.getPropertyValue(r).trim();o&&i.style.setProperty(r,o)}i.style.colorScheme=t.colorScheme}function R(i,e,t){return i<e?e:i>t?t:i}var qr=0;function Ur(i="rg"){return qr++,`${i}-${qr}`}var jr='<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3.5h12L9.5 8v4.5L6.5 14V8L2 3.5z"/></svg>',Yr='<svg viewBox="0 0 16 16" width="10" height="10" fill="currentColor"><path d="M8 3l4 5H4l4-5z"/></svg>',Xr='<svg viewBox="0 0 16 16" width="10" height="10" fill="currentColor"><path d="M8 13l4-5H4l4 5z"/></svg>',Jr='<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.35" stroke-linecap="round"><path d="M2 4h3m3 0h6M2 8h7m3 0h2M2 12h1m3 0h8"/><circle cx="6.5" cy="4" r="1.35"/><circle cx="10.5" cy="8" r="1.35"/><circle cx="4.5" cy="12" r="1.35"/></svg>';var Zr=6,Ke=class{constructor(e){this.core=e;this.pending=null;this.rt=null;this.Uo=!1;this.F=0;this.Rr=null;this.we=e=>{if(this.rt){this.ll(e);return}let t=this.pending;t&&(Math.abs(e.clientX-t.startX)<Zr&&Math.abs(e.clientY-t.startY)<Zr||this.dl(e))};this.X=e=>{this.pending=null,e.type!=="pointercancel"&&this.rt&&this.Xo(e.clientX,e.clientY),this.jo();let t=this.On();t&&e.type!=="pointercancel"&&t.targetIndex>=0&&this.core.moveColumn(t.column.id,t.targetIndex)}}onPointerDown(e,t){e.button===0&&t.movable&&(this.pending={column:t,startX:e.clientX,startY:e.clientY},window.addEventListener("pointermove",this.we),window.addEventListener("pointerup",this.X),window.addEventListener("pointercancel",this.X))}didDrag(){let e=this.Uo;return this.Uo=!1,e}dl(e){let t=this.pending;if(!t)return;let r=this.cl(t.column);if(!r||!r.parentElement){this.jo();return}this.Uo=!0;let o=f("div","mach-drop-indicator"),n=f("div","mach-column-drag-ghost");n.textContent=t.column.colDef.headerName??t.column.colDef.field??t.column.id,n.ariaHidden="true",L(n,this.core.skeleton.root),document.body.appendChild(n),r.parentElement.appendChild(o),r.classList.add("mach-header-cell--dragging"),this.core.skeleton.root.classList.add("mach-root--dragging");let s=this.core.bodyRenderer.Yo(t.column),a=this.core.skeleton.ot[s],l=this.core.columnModel.d(s),d=new Float64Array(l.length+1),c=new Float64Array(l.length);for(let h=0;h<l.length;h++){let p=l[h].currentWidth;c[h]=d[h]+p/2,d[h+1]=d[h]+p}let u=n.getBoundingClientRect();this.rt={column:t.column,cellEl:r,ghost:n,indicator:o,targetIndex:-1,pane:s,containerLeft:a.getBoundingClientRect().left,startScrollLeft:this.core.skeleton.b.center.scrollLeft,fromIndex:l.indexOf(t.column),midpoints:c,offsets:d,ghostWidth:u.width,ghostHeight:u.height},this.Xo(e.clientX,e.clientY)}cl(e){let t=this.core.bodyRenderer.Yo(e);return this.core.skeleton.ot[t].querySelector(`.mach-header-cell[data-col-id="${Tn(e.id)}"]`)}ll(e){this.Rr={clientX:e.clientX,clientY:e.clientY},!this.F&&(this.F=requestAnimationFrame(()=>{this.F=0;let t=this.Rr;this.Rr=null,t&&this.Xo(t.clientX,t.clientY)}))}Xo(e,t){let r=this.rt;if(!r)return;let o=R(e+12,8,window.innerWidth-r.ghostWidth-8),n=R(t+12,8,window.innerHeight-r.ghostHeight-8);r.ghost.style.transform=`translate3d(${o}px, ${n}px, 0)`;let s=r.pane==="center"?this.core.skeleton.b.center.scrollLeft-r.startScrollLeft:0,a=e-(r.containerLeft-s),l=r.midpoints.length;for(let d=0;d<r.midpoints.length;d++)if(a<r.midpoints[d]){l=d;break}r.targetIndex=l>r.fromIndex?l-1:l,r.indicator.style.transform=`translate3d(${r.offsets[l]}px, 0, 0)`}On(){let e=this.rt;return e?(this.rt=null,e.cellEl.classList.remove("mach-header-cell--dragging"),e.ghost.remove(),e.indicator.remove(),this.core.skeleton.root.classList.remove("mach-root--dragging"),e):null}jo(){window.removeEventListener("pointermove",this.we),window.removeEventListener("pointerup",this.X),window.removeEventListener("pointercancel",this.X),this.F&&cancelAnimationFrame(this.F),this.F=0,this.Rr=null}destroy(){this.jo(),this.On(),this.pending=null}};function Tn(i){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(i):i.replace(/[^a-zA-Z0-9_-]/g,"\\$&")}function Qr(i,e){let t=i==null?"":String(i);return t.includes(e)||t.includes('"')||t.includes(`
2
2
  `)||t.includes("\r")?'"'+t.replace(/"/g,'""')+'"':t}function Ce(i){return typeof i!="string"||i===""||/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(i)?i:/^[\s\u0000-\u001f]*[=+\-@]/.test(i)?"'"+i:i}function Zt(i,e={}){let t=e.columnSeparator??",",r=e.includeHeader??!0,o=e.protectFormulas??!0,n=[];r&&n.push(i.getHeaderLabels().map(a=>Qr(a,t)).join(t));for(let a of i.getRowValues())n.push(a.map(l=>Qr(o?Ce(l):l,t)).join(t));let s=n.join(`\r
3
3
  `);return e.prependBOM?"\uFEFF"+s:s}function Dn(i,e){let t=e?Ce(i):i,r=t==null?"":String(t);return/["\t\n\r]/.test(r)?'"'+r.replace(/"/g,'""')+'"':r}function ue(i,e=!0){return i.map(t=>t.map(r=>Dn(r,e)).join(" ")).join(`
4
4
  `)}function qe(i){return je(i," ")}function Ue(i,e=","){return je(i,e)}function je(i,e){let t=[],r=[],o="",n=!1,s=0;for(;s<i.length;){let a=i[s];if(n){if(a==='"'){if(i[s+1]==='"'){o+='"',s+=2;continue}n=!1,s++;continue}o+=a,s++;continue}if(a==='"'&&o===""){n=!0,s++;continue}if(a===e){r.push(o),o="",s++;continue}if(a===`
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var Ie="0.32.0";var Ae=class{constructor(e){this.onListenerError=e;this.Ke=new Map}on(e,t){let r=this.Ke.get(e);return r||(r=new Set,this.Ke.set(e,r)),r.add(t),()=>{r.delete(t)}}once(e,t){let r=this.on(e,o=>{r(),t(o)});return r}off(e,t){let r=this.Ke.get(e);r&&(r.delete(t),r.size===0&&this.Ke.delete(e))}emit(e,t){let r=this.Ke.get(e);if(r)for(let o of[...r])try{o(t)}catch(n){console.error(`[mach-table] error in "${e}" listener`,n),this.onListenerError?.(n,e)}}clear(){this.Ke.clear()}};var oi=new Set(["__proto__","prototype","constructor"]);function he(i){return typeof i!="string"||i.length===0?!1:i.split(".").every(t=>t.length>0&&!oi.has(t))}function X(i,e){if(i==null||!he(e))return;if(e.indexOf(".")<0)return i[e];let r=i,o=0;for(;o<e.length;){if(r==null)return;let n=e.indexOf(".",o);if(n<0){r=r[e.slice(o)];break}r=r[e.slice(o,n)],o=n+1}return r}function pe(i,e,t){if(i==null||!he(e))return!1;let r=e.split("."),o=i;for(let n=0;n<r.length-1;n++){if(typeof o!="object"&&typeof o!="function"||o===null)return!1;o[r[n]]==null&&(o[r[n]]={}),o=o[r[n]]}return typeof o!="object"&&typeof o!="function"||o===null?!1:(o[r[r.length-1]]=t,!0)}var ii=new Set(["contains","notContains","equals","notEquals","startsWith","endsWith","blank","notBlank"]),ni=new Set(["equals","notEquals","lessThan","lessThanOrEqual","greaterThan","greaterThanOrEqual","inRange","blank","notBlank"]),si=new Set(["equals","notEquals","lessThan","greaterThan","inRange","blank","notBlank"]);function ai(i){return i==null||typeof i=="string"||typeof i=="number"&&Number.isFinite(i)}function li(i){return i==="text"?ii:i==="number"?ni:si}function di(i,e,t){if(i==null||typeof i!="object")return null;let r=i;return typeof r.match!="string"||!t.has(r.match)?null:{match:r.match,...ci(r,e)}}function ci(i,e){let t=e==="number"?Cr(i.value):typeof i.value=="string"?i.value:void 0,r=e==="number"?Cr(i.value2):typeof i.value2=="string"?i.value2:void 0;return{...t!==void 0?{value:t}:{},...r!==void 0?{value2:r}:{}}}function Cr(i){return typeof i=="number"&&Number.isFinite(i)?i:void 0}function ui(i,e){let t=[],r=li(e);for(let o of i.slice(0,20)){let n=di(o,e,r);n&&t.push(n)}return t}function It(i){if(i==null||typeof i!="object")return null;let e=i;return e.type==="set"?Array.isArray(e.values)?{type:"set",values:e.values.filter(ai).slice(0,2e3)}:null:e.type!=="text"&&e.type!=="number"&&e.type!=="date"||!Array.isArray(e.conditions)?null:{type:e.type,...e.operator==="or"||e.operator==="and"?{operator:e.operator}:{},conditions:ui(e.conditions,e.type)}}function hi(i,e){if(typeof i.colId!="string"||!i.colId.trim())return null;let t=i.colId.trim();if(e.validColumnIds?.has(t)===!1)return null;let r=It(i.filter);return r?{kind:"condition",colId:t,filter:r}:null}function pi(i,e,t){if(!Array.isArray(i.children))return null;let r=[];for(let o of i.children){let n=Tr(o,e+1,t);n&&r.push(n)}return r.length===0?null:{kind:"group",operator:i.operator==="or"?"or":"and",children:r,...i.not===!0?{not:!0}:{}}}function fi(i,e,t){return e<=16&&t.nodes<512&&i!=null&&typeof i=="object"}function Tr(i,e,t){if(!fi(i,e,t)||t.ancestors.has(i))return null;t.ancestors.add(i),t.nodes++;let r=i,o=r.kind==="condition"?hi(r,t):r.kind==="group"?pi(r,e,t):null;return t.ancestors.delete(i),o}function V(i,e){if(i==null||typeof i!="object")return null;let t=i;if(t.version!==1||t.root==null)return null;let r=Tr(t.root,0,{ancestors:new WeakSet,nodes:0,validColumnIds:e});return r?{version:1,root:r}:null}function mi(i,e){return{kind:"condition",colId:i,filter:e}}function J(i,e){if(i==null||typeof i!="object"||Array.isArray(i))return{};let t={};for(let[r,o]of Object.entries(i).slice(0,2e3)){let n=r.trim();if(!n||e?.has(n)===!1)continue;let s=It(o);s&&(t[n]=s)}return t}function gi(i,e,t={}){return{kind:"group",operator:i,children:e,...t.not?{not:!0}:{}}}var At={align:"center",sortable:!0,resizable:!0,movable:!0,filter:!1,minWidth:80},fe={compact:{rowHeight:30,headerHeight:34,fontSize:12,cellPadding:6},normal:{rowHeight:36,headerHeight:40,fontSize:13,cellPadding:9},large:{rowHeight:44,headerHeight:48,fontSize:14,cellPadding:12}};function M(i,e,t,r=!1){return typeof i!="number"||!Number.isFinite(i)||i<t?e:r?Math.floor(i):i}function yi(i){return i&&Object.prototype.hasOwnProperty.call(fe,i)?i:"normal"}function vi(i){return i.theme==="light"||i.theme==="dark"||i.theme==="auto"?i.theme:"light"}function wi(i,e){let t=typeof i.pagination=="object"&&Array.isArray(i.pagination.pageSizeOptions)?i.pagination.pageSizeOptions:void 0,r=t?[...new Set(t.map(o=>M(o,0,1,!0)).filter(Boolean))]:[10,20,50,100];return r.includes(e)||r.push(e),r.sort((o,n)=>o-n)}function Lt(i,e){let t=typeof i=="function"?i(e):X(e,i);return t==null?"":String(t)}function bi(i){let e=i.rowKey,t=e?({data:r})=>Lt(e,r):void 0;return{...t?{resolveRowId:t}:{},...e?{rowKey:e}:{}}}function Ci(i,e){let t=fe[e];return{columnDefs:Array.isArray(i.columnDefs)?i.columnDefs:[],rowData:Array.isArray(i.rowData)?i.rowData:[],defaultColDef:{...At,...i.defaultColDef??{}},columnTypes:i.columnTypes??{},...bi(i),rowHeight:M(i.rowHeight,t.rowHeight,1),headerHeight:M(i.headerHeight,t.headerHeight,1),rowBuffer:M(i.rowBuffer,8,0,!0),columnLayout:i.columnLayout==="fit"?"fit":"normal",enableColumnResize:i.enableColumnResize===!0,domLayout:i.domLayout==="autoHeight"?"autoHeight":"normal",rowSelection:i.rowSelection==="single"||i.rowSelection==="multiple"?i.rowSelection:"none",multiSort:i.multiSort??!0,size:e,pinnedTopRowData:Array.isArray(i.pinnedTopRowData)?i.pinnedTopRowData:[],pinnedBottomRowData:Array.isArray(i.pinnedBottomRowData)?i.pinnedBottomRowData:[]}}function Ti(i){return{stripedRows:i.stripedRows??!1,rowStyleRules:Array.isArray(i.rowStyleRules)?i.rowStyleRules:[],showCellBorders:i.showCellBorders??!1,theme:vi(i),quickFilterText:i.quickFilterText??null,suppressCellFocus:i.suppressCellFocus??!1,suppressRowHoverHighlight:i.suppressRowHoverHighlight??!1,suppressNoRowsOverlay:i.suppressNoRowsOverlay??!1,suppressHeaderFocus:i.suppressHeaderFocus??!1,loading:i.loading??!1,error:i.error??null,className:i.className??""}}function Di(i){return{editType:i.editType==="fullRow"?"fullRow":"cell",editableIndicator:i.editableIndicator==="always"||i.editableIndicator==="none"?i.editableIndicator:"hover",singleClickEdit:i.singleClickEdit??!1,manualSorting:i.manualSorting??!1,manualFiltering:i.manualFiltering??!1,showSummary:i.showSummary??!1,indexOffset:i.indexOffset??0,applyRowDrag:i.applyRowDrag??!0,rowDragPolicy:i.rowDragPolicy,undoStackSize:M(i.undoStackSize,100,0,!0),asyncTransactionWaitMillis:M(i.asyncTransactionWaitMillis,16,0,!0)}}function Ri(i){return{masterDetail:i.masterDetail??!1,detailRowHeight:M(i.detailRowHeight,240,1),detailToggleColumn:i.detailToggleColumn??!0,treeData:i.treeData??!1,childrenKey:i.childrenKey??"children",autoCheckedChildren:i.autoCheckedChildren??!0,defaultExpandAll:i.defaultExpandAll??!1}}function Ei(i){let e=typeof i.pagination=="object"?i.pagination:void 0,t=M(e?.pageSize,20,1,!0);return{paginationEnabled:i.pagination!==!1&&i.datasource==null,paginationMode:e?.mode==="server"?"server":"client",paginationPage:M(e?.page,1,1,!0),paginationTotal:M(e?.total,0,0,!0),paginationPageSize:t,paginationPageSizeOptions:wi(i,t),paginationShowTotal:e?e.showTotal!==!1:!0,paginationShowSizeSelector:e?e.showPageSizeSelector!==!1:!0}}function xi(i){return{watermarkEnabled:i.watermark!=null&&i.watermark!==!1,watermarkConfig:i.watermark==null||i.watermark===!1?null:i.watermark===!0?{text:"MachTable"}:i.watermark}}function Mi(i){return{columnMenu:i.columnMenu??!1,advancedFilterModel:V(i.advancedFilterModel),...Si(i),locale:i.locale??{},suppressWarnings:i.suppressWarnings??!1,enableRangeSelection:i.enableRangeSelection??!1,suppressClipboard:i.suppressClipboard??!1,contextMenu:i.contextMenu??!1,tooltipShowDelay:M(i.tooltipShowDelay,600,0),flashCells:i.flashCells??!0,fillHandle:i.fillHandle??!0,statusBarEnabled:i.statusBar===!0||typeof i.statusBar=="object"&&i.statusBar!=null,statusBarPanels:typeof i.statusBar=="object"&&i.statusBar?.panels?i.statusBar.panels:["rowCount","selectedRowCount","rangeAggregate"]}}function Si(i){let e=i.persistence;return!e||typeof e.key!="string"||!e.key.trim()?{persistence:null}:{persistence:{key:e.key.trim(),debounceMs:M(e.debounceMs,160,0,!0),...e.sections?{sections:[...new Set(e.sections)]}:{},...e.store?{store:e.store}:{}}}}function ki(i){return{datasourceMode:i.datasourceMode==="block"?"block":"sequential",blockSize:M(i.blockSize,100,1,!0),infiniteBufferRows:M(i.infiniteBufferRows,40,0,!0),maxBlocksInCache:M(i.maxBlocksInCache,12,1,!0),datasourceMaxConcurrentRequests:M(i.datasourceMaxConcurrentRequests,4,1,!0),blockPrefetch:M(i.blockPrefetch,1,0,!0),datasourceRowCount:i.datasourceRowCount==null?null:M(i.datasourceRowCount,0,0,!0),dataProcessorMinRows:M(i.dataProcessorMinRows,5e3,1,!0),datasourceRetryCount:M(i.datasourceRetryCount,2,0,!0),datasourceRetryDelay:M(i.datasourceRetryDelay,300,0,!0),datasourceRetryJitter:Math.min(1,M(i.datasourceRetryJitter,.15,0))}}function Ii(i){return{ariaLabel:i.ariaLabel??"MachTable data grid",ariaLabelledBy:i.ariaLabelledBy??"",ariaDescribedBy:i.ariaDescribedBy??"",overlayNoRowsTemplate:i.overlayNoRowsTemplate??"",overlayLoadingTemplate:i.overlayLoadingTemplate??"",overlayErrorTemplate:i.overlayErrorTemplate??"",allowUnsafeOverlayHtml:i.allowUnsafeOverlayHtml??!1}}var Ai=["detailRowRenderer","isRowExpandable","aggFuncs","components","actionPolicy","summaryMethod","datasource","getRowHeight","tooltipComponent","getContextMenuItems","initialState","rowEditValidator","isTreeRowExpandable","loadTreeChildren","dataProcessor"];function Li(i,e){for(let t of Ai)i[t]&&Object.assign(e,{[t]:i[t]})}function Pi(i,e){for(let t of Object.keys(i))t.startsWith("on")&&typeof i[t]=="function"&&Object.assign(e,{[t]:i[t]})}function Dr(i){let e=yi(i.size),t={...Ci(i,e),...Ti(i),...Di(i),...Ri(i),...Ei(i),...xi(i),...Mi(i),...ki(i),...Ii(i),features:Array.isArray(i.features)?i.features:[]};return Li(i,t),Pi(i,t),t}function Rr(i){return Array.isArray(i)?i.filter(e=>typeof e=="string"&&e.length>0):typeof i=="string"&&i.length>0?[i]:[]}function ne(i,e){return Rr(i.type).includes(e)}function Er(i,e,t={}){let r={};for(let o of Rr(i.type)){let n=t[o];n&&Object.assign(r,n)}return{...e,...r,...i}}var _=class{constructor(e,t){this.manualWidth=null;this.contentWidth=null;this.flex=null;this.currentWidth=0;this.parentGroup=null;this.level=0;this.isDetailToggle=!1;this.id=e,this.colDef=t,this.hide=t.hide??!1;let r=t.pinned;this.pinned=r===!0?"left":r===!1||r==null?null:r,this.resetWidth()}get sortable(){return this.colDef.sortable!==!1}get resizable(){return this.colDef.resizable!==!1}get movable(){return this.colDef.movable!==!1}get filterable(){return this.colDef.filter!=null&&this.colDef.filter!==!1}get filterType(){let e=this.colDef.filter;return e===!0?"text":e??"text"}get hasCheckbox(){return this.colDef.checkboxSelection===!0}resetWidth(){this.manualWidth=null,this.contentWidth=null,this.flex=typeof this.colDef.flex=="number"&&Number.isFinite(this.colDef.flex)&&this.colDef.flex>0?this.colDef.flex:null}};var Z=class i{constructor(e,t){this.parent=null;this.children=[];this.groupId=e,this.def=t}get headerName(){return this.def.headerName??this.def.groupId??""}getLeafColumns(e=[]){for(let t of this.children)t instanceof i?t.getLeafColumns(e):e.push(t);return e}};function me(i){return Array.isArray(i.children)}function Le(i,e){return typeof i=="number"&&Number.isFinite(i)&&i>0?i:e}function xr(i){let e=Le(i.minWidth,80);return{min:e,max:Math.max(e,Le(i.maxWidth,Number.MAX_SAFE_INTEGER))}}function O(i,e){let{min:t,max:r}=xr(e),o=Le(i,Le(e.width,150));return Math.max(t,Math.min(r,o))}function Mr(i,e){let t=i.map(s=>O(s.width??150,s)),r=[],o=0;i.forEach((s,a)=>{let l=s.flex??0;l>0&&(r.push(a),o+=l)});let n=0;for(let s of t)n+=s;if(o>0&&e>n){let s=e-n;for(let a=0;a<4&&s>.5&&r.length>0;a++){let l=[],d=0;for(let p of r){let m=i[p].flex??0;l.push(p),d+=m}let c=[];for(let p=0;p<l.length;p++){let m=l[p],g=i[m].flex??0,v=s*g/d,y=t[m];t[m]=O(y+v,i[m]),c.push(t[m]-y)}let u=0;for(let p of c)u+=p;s-=u;let h=l.filter((p,m)=>c[m]>.001);if(h.length===l.length)break;r.length=0;for(let p of h)r.push(p)}}return t}function Gi(i,e,t){let r=new Set(i.map((n,s)=>s)),o=t;for(let n=0;n<i.length+1&&r.size>0;n++){let s=0;for(let l of r)s+=Math.max(1,e[l]);if(s<=0)break;let a=!1;for(let l of[...r]){let d=o*(Math.max(1,e[l])/s),c=O(d,i[l]),{min:u,max:h}=xr(i[l]);(d<u||d>h)&&(e[l]=c,o-=c,r.delete(l),a=!0)}if(!a){for(let l of r)e[l]=O(o*(Math.max(1,e[l])/s),i[l]);break}o=Math.max(0,o)}}function Ni(i,e,t){let r=t-e.reduce((o,n)=>o+n,0);if(!(Math.abs(r)<=.01))for(let o=e.length-1;o>=0;o--){let n=O(e[o]+r,i[o]);if(Math.abs(n-e[o])>.01){e[o]=n;return}}}function Pe(i,e){let t=i.map(r=>O(r.width??150,r));return!Number.isFinite(e)||e<=0||i.length===0||(Gi(i,t,e),Ni(i,t,e)),t}var Pt="__rg_detail_toggle__";function se(i){return typeof i=="number"&&Number.isFinite(i)&&i>0}var Ge=class{constructor(e){this.core=e;this.columns=[];this.rn=new Map;this.q=[];this.left=[];this.center=[];this.right=[];this.sortModel=[];this.defs=[];this.qe=1;this.vo=new Map;this.fa=0}wt(e){this.defs=e?[...e]:[];let t=new Map(this.columns.map(s=>[s.id,s])),r=this.core.options.defaultColDef,o=new Set(this.core.options.masterDetail&&this.core.options.detailToggleColumn?[Pt]:[]),n=(s,a,l)=>s.map((d,c)=>{if(me(d)){let y=d.groupId??d.headerName??`group_${c}_${l}`,b=new Z(y,d);return b.parent=a,b.children=n(d.children,b,l+1),b}let u=d,h=u.colId??u.field??`col_${c}`,p=h,m=2;for(;o.has(p);)p=`${h}_${m++}`;o.add(p);let g=new _(p,Er(u,r,this.core.options.columnTypes));g.parentGroup=a,g.level=l;let v=t.get(p);return v&&(g.manualWidth=v.manualWidth,g.contentWidth=v.contentWidth,g.flex=v.flex,g.hide=v.hide,g.pinned=v.pinned),g});if(this.q=n(this.defs,null,0),this.core.options.masterDetail&&this.core.options.detailToggleColumn){let s=new _(Pt,{colId:Pt,headerName:"",width:38,pinned:"left",sortable:!1,resizable:!1,movable:!1,filter:!1});s.isDetailToggle=!0,this.q.unshift(s)}if(this.columns=this.ir(this.q),this.rn=new Map(this.columns.map(s=>[s.id,s])),this.qe=this.columns.reduce((s,a)=>Math.max(s,a.level+1),1),this.sortModel=this.sortModel.filter(s=>this.columns.some(a=>a.id===s.colId)),this.sortModel.length===0){let s=[];for(let a of this.columns)a.colDef.initialSort&&s.push({colId:a.id,direction:a.colDef.initialSort});this.sortModel=s}this.Ue()}ir(e,t=[]){for(let r of e)r instanceof Z?this.ir(r.children,t):t.push(r);return t}Ue(){let e=this.columns.filter(t=>!t.hide);this.left=e.filter(t=>t.pinned==="left"),this.right=e.filter(t=>t.pinned==="right"),this.center=e.filter(t=>t.pinned===null),this.vo.clear(),this.e().forEach((t,r)=>this.vo.set(t.id,r))}te(e){return this.vo.get(e)??-1}G(){return this.columns}nr(){return this.defs}ma(){return this.q}ga(){return this.qe}m(e){return this.rn.get(e)}d(e){return e==="left"?this.left:e==="right"?this.right:this.center}e(){return[...this.left,...this.center,...this.right]}re(){return this.e().filter(e=>e.colDef.rowGroup===!0)}ya(){return this.e().filter(e=>e.colDef.aggFunc!=null&&e.colDef.rowGroup!==!0)}wo(){return this.center.some(e=>e.colDef.colSpan!=null)}nn(){let e=this.e();return this.center.find(t=>!t.hasCheckbox&&!t.isDetailToggle)??e.find(t=>!t.hasCheckbox&&!t.isDetailToggle)??e[0]}bt(e){return e.pinned==="left"?"left":e.pinned==="right"?"right":"center"}sn(e){this.fa=e;let t=0;for(let c of[...this.left,...this.right])c.currentWidth=O(c.manualWidth??c.contentWidth??c.colDef.width??150,this.Se(c)),t+=c.currentWidth;let r=Math.max(0,e-t),o=[],n=[];for(let c of this.center)(c.colDef.suppressSizeToFit||c.manualWidth!=null?n:o).push(c);let s=0;for(let c of n)c.currentWidth=O(c.manualWidth??c.contentWidth??c.colDef.width??150,this.Se(c)),s+=c.currentWidth;let a=o.map(c=>this.Se(c)),l=Math.max(0,r-s),d=this.core.options.columnLayout==="fit"?Pe(a,l):Mr(a,l);o.forEach((c,u)=>{c.currentWidth=d[u]})}Se(e){let t=e.colDef;return{width:e.manualWidth??e.contentWidth??t.width,minWidth:t.minWidth,maxWidth:t.maxWidth,flex:e.manualWidth==null?e.flex??void 0:void 0}}oe(e,t){return se(t)?(e.manualWidth=O(t,this.Se(e)),e.flex=null,!0):!1}an(e,t){return se(t)?(e.resetWidth(),e.contentWidth=O(t,this.Se(e)),!0):!1}bo(e,t){let r=this.m(e);!r||r.hide===!t||(r.hide=!t,this.Ue())}moveColumn(e,t){let r=this.m(e);if(!r)return!1;let o=this.bt(r),n=u=>r.parentGroup?!0:this.bt(u)===o,s=r.parentGroup?r.parentGroup.children:this.q,a=s.filter(u=>u instanceof _&&!u.hide&&n(u)),l=a.indexOf(r);if(l<0)return!1;a.splice(l,1);let d=Math.max(0,Math.min(t,a.length));a.splice(d,0,r);let c=[];return s.forEach((u,h)=>{u instanceof _&&!u.hide&&n(u)&&c.push(h)}),c.length!==a.length?!1:(c.forEach((u,h)=>{s[u]=a[h]}),this.columns=this.ir(this.q),this.Ue(),!0)}Co(e,t){let r=this.m(e);!r||!r.movable||(r.pinned=t,this.Ue())}sr(){return this.columns.map(e=>({colId:e.id,hide:e.hide,width:e.manualWidth??e.currentWidth,flex:e.flex,widthMode:e.manualWidth==null?"auto":"manual",contentWidth:e.contentWidth??void 0,pinned:e.pinned}))}ln(e){let t=new Map(e.map(r=>[r.colId,r]));for(let r of this.columns){let o=t.get(r.id);o&&this.va(r,o)}this.wa(e),this.Ue()}va(e,t){typeof t.hide=="boolean"&&(e.hide=t.hide),t.widthMode==="auto"?(e.resetWidth(),se(t.flex)&&(e.flex=t.flex)):se(t.flex)?(e.flex=t.flex,e.manualWidth=null):se(t.width)&&(e.manualWidth=O(t.width,this.Se(e)),e.flex=null),se(t.contentWidth)&&(e.contentWidth=O(t.contentWidth,this.Se(e))),e.movable&&(t.pinned==="left"||t.pinned==="right"||t.pinned===null)&&(e.pinned=t.pinned)}wa(e){let t=new Map;e.forEach((o,n)=>t.set(o.colId,n));let r=o=>o.pinned==="left"?"left":o.pinned==="right"?"right":"center";for(let o of["left","center","right"]){let n=this.q.filter(d=>d instanceof _&&!d.hide&&d.parentGroup===null&&r(d)===o);if(n.length<2)continue;let s=n.filter(d=>d.movable),a=s.slice().sort((d,c)=>(t.get(d.id)??Number.MAX_SAFE_INTEGER)-(t.get(c.id)??Number.MAX_SAFE_INTEGER));if(a.every((d,c)=>d===s[c]))continue;let l=[];this.q.forEach((d,c)=>{d instanceof _&&!d.hide&&d.parentGroup===null&&r(d)===o&&d.movable&&l.push(c)}),l.forEach((d,c)=>{this.q[d]=a[c]})}this.columns=this.ir(this.q)}To(){for(let e of this.columns){e.resetWidth(),e.hide=e.colDef.hide??!1;let t=e.colDef.pinned;e.pinned=t===!0?"left":t===!1||t==null?null:t}this.Ue()}D(){return this.sortModel.map(e=>({...e}))}Ct(e){if(!e||e.length===0){this.sortModel=[];return}this.sortModel=e.filter(t=>this.columns.some(r=>r.id===t.colId)&&(t.direction==="asc"||t.direction==="desc")).map(t=>({colId:t.colId,direction:t.direction}))}cycleSort(e,t){let r=[...this.sortModel],o=r.findIndex(l=>l.colId===e.id),n=o>=0?r[o].direction:null,s=n===null?"asc":n==="asc"?"desc":null;t&&this.core.options.multiSort?s===null?o>=0&&r.splice(o,1):o>=0?r[o]={colId:e.id,direction:s}:r.push({colId:e.id,direction:s}):(r.length=0,s&&r.push({colId:e.id,direction:s})),this.sortModel=r}};function kr(i){return i==null?"":String(i).toLowerCase()}function Fi(i,e,t){let r=kr(i),o=n=>{let s=(n.value??"").toLowerCase();switch(n.match){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"blank":return r==="";case"notBlank":return r!=="";default:return!0}};return e.length===0||(t==="or"?e.some(o):e.every(o))}function Oi(i,e,t){switch(t.match){case"equals":return i===e;case"notEquals":return i!==e;case"lessThan":return i<e;case"lessThanOrEqual":return i<=e;case"greaterThan":return i>e;case"greaterThanOrEqual":return i>=e;case"inRange":return i>=e&&i<=(t.value2??e);default:return!0}}function Hi(i,e){let t=i==null||i==="";if(e.match==="blank")return t;if(e.match==="notBlank")return!t;if(t)return!1;let r=typeof i=="number"?i:Number(i);if(Number.isNaN(r))return!1;let o=e.value;return o==null||Number.isNaN(o)?!1:Oi(r,o,e)}function Vi(i,e,t){let r=o=>Hi(i,o);return e.length===0||(t==="or"?e.some(r):e.every(r))}function Gt(i){if(i==null||i==="")return null;if(i instanceof Date)return isNaN(i.getTime())?null:i.getTime();if(typeof i=="number")return i;let e=Date.parse(String(i));return isNaN(e)?null:e}function Bi(i,e,t){let r=Gt(i),o=n=>{let s=r==null;if(n.match==="blank")return s;if(n.match==="notBlank")return!s;if(s)return!1;let a=r,l=n.value!=null?Gt(n.value):null;if(l==null)return!1;switch(n.match){case"equals":return a===l;case"notEquals":return a!==l;case"lessThan":return a<l;case"greaterThan":return a>l;case"inRange":{let d=n.value2!=null?Gt(n.value2):null;return d!=null?a>=l&&a<=d:a>=l}default:return!0}};return e.length===0||(t==="or"?e.some(o):e.every(o))}function zi(i,e){return e.length===0?!0:e.some(t=>t==null&&i==null||t===i)}function Ir(i,e){let t=e.type!=="set"&&e.operator==="or"?"or":"and";switch(e.type){case"text":return Fi(i,e.conditions,t);case"number":return Vi(i,e.conditions,t);case"date":return Bi(i,e.conditions,t);case"set":return zi(i,e.values);default:return!0}}function Ar(i,e,t){if(i.kind==="condition"){let o=e.get(i.colId);return o?n=>Ir(t(n,o),i.filter):()=>!0}let r=i.children.map(o=>Ar(o,e,t));return o=>{let n=i.operator==="or"?r.some(s=>s(o)):r.every(s=>s(o));return i.not?!n:n}}function Nt(i,e,t,r,o){let n=new Map(i.map(d=>[d.id,d])),s=Object.entries(e).flatMap(([d,c])=>{let u=n.get(d);return u?[{column:u,filter:c}]:[]}),a=t?Ar(t.root,n,o):()=>!0,l=r?.trim().toLowerCase().split(/\s+/).filter(Boolean)??[];return d=>!s.every(({column:c,filter:u})=>Ir(o(d,c),u))||!a(d)?!1:l.every(c=>i.some(u=>kr(o(d,u)).includes(c)))}var Lr=typeof Intl<"u"?new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"}):null;function _i(i,e){let t=i==null||i==="",r=e==null||e==="";return!t&&!r?null:t&&r?0:t?1:-1}function Wi(i,e){let t=Number.isNaN(i),r=Number.isNaN(e);return t||r?t===r?0:t?1:-1:i-e}function $i(i,e){return i===e?0:i?1:-1}function Ne(i,e){let t=_i(i,e);if(t!==null)return t;if(typeof i=="number"&&typeof e=="number")return Wi(i,e);if(i instanceof Date&&e instanceof Date)return i.getTime()-e.getTime();if(typeof i=="boolean"&&typeof e=="boolean")return $i(i,e);let r=String(i),o=String(e);return Lr?Lr.compare(r,o):r.localeCompare(o)}function Ft(i,e,t,r){let o=new Map(t.map(a=>[a.id,a])),n=e.flatMap(a=>{let l=o.get(a.colId);return l?[{column:l,compare:l.colDef.comparator??Ne,direction:a.direction}]:[]}),s=i.map(a=>({node:a,values:n.map(({column:l})=>r(a,l))}));return s.sort((a,l)=>{for(let d=0;d<n.length;d++){let c=n[d],u=c.compare(a.values[d],l.values[d],a.node,l.node);if(u!==0)return c.direction==="asc"?u:-u}return 0}),s.map(({node:a})=>a)}function Fe(i){return i.filter(e=>typeof e=="number"&&!isNaN(e))}var Pr={sum:i=>Fe(i).reduce((e,t)=>e+t,0),avg:i=>{let e=Fe(i);return e.length===0?null:e.reduce((t,r)=>t+r,0)/e.length},count:i=>i.length,min:i=>{let e=Fe(i);return e.length===0?null:Math.min(...e)},max:i=>{let e=Fe(i);return e.length===0?null:Math.max(...e)},first:i=>i.length>0?i[0]:null,last:i=>i.length>0?i[i.length-1]:null};function Ot(i){let e={...Pr,...i??{}};return t=>e[t]}function Q(i){if(i.reason instanceof Error)return i.reason;let e=new Error(typeof i.reason=="string"?i.reason:"Block request aborted");return e.name="AbortError",e}function Oe(i){return Number.isFinite(i)?Math.max(1,Math.trunc(i)):1}var He=class{constructor(e,t,r=4){this.maxBlocks=e;this.onEvict=t;this.maxConcurrentRequests=r;this.S=new Map;this.x=new Map;this.dn=0;this.generation=0;this.hitCount=0;this.missCount=0;this.evictionCount=0;this.ar=0;this.lr=new Set;this.maxBlocks=Oe(e),this.maxConcurrentRequests=Oe(r)}configure(e,t=this.maxConcurrentRequests){this.maxBlocks=Oe(e),this.maxConcurrentRequests=Oe(t),this.Do(),this.dr()}retain(e){this.lr=e,this.Do()}peek(e){let t=this.S.get(e);if(t)return t.touchedAt=++this.dn,t}has(e){return this.S.has(e)}invalidate(e){let t=this.x.get(e);t&&(this.x.delete(e),t.controller.abort(),t.state==="queued"&&t.reject(Q(t.controller.signal)));let r=this.S.get(e);r&&(this.S.delete(e),this.onEvict?.(e,r))}load(e,t,r,o=0){if(r?.aborted)return Promise.reject(Q(r));let n=this.peek(e);if(n)return this.hitCount++,Promise.resolve(n);let s=this.x.get(e);if(s)return this.hitCount++,s.priority=Math.max(s.priority,o),this.dr(),this.cn(e,s,r);this.missCount++;let a=new AbortController,l,d,c=new Promise((p,m)=>{l=p,d=m}),u={controller:a,promise:c,consumers:0,loader:t,priority:o,state:"queued",resolve:l,reject:d};this.x.set(e,u);let h=this.cn(e,u,r);return this.dr(),h}purge(){this.generation++,this.lr.clear();for(let e of this.x.values())e.controller.abort(),e.state==="queued"&&e.reject(Q(e.controller.signal));this.x.clear();for(let[e,t]of this.S)this.onEvict?.(e,t);this.S.clear()}snapshot(){let e=0,t=0;for(let r of this.S.values())e+=r.rows.length;for(let r of this.x.values())r.state==="active"&&t++;return{cachedBlockCount:this.S.size,loadingBlockCount:this.x.size,activeRequestCount:t,queuedRequestCount:Math.max(0,this.x.size-t),cachedRowCount:e,hitCount:this.hitCount,missCount:this.missCount,evictionCount:this.evictionCount}}dr(){for(;this.ar<this.maxConcurrentRequests;){let e,t;for(let[r,o]of this.x)o.state!=="queued"||o.controller.signal.aborted||(!t||o.priority>t.priority)&&(e=r,t=o);if(e==null||!t)return;this.ba(e,t)}}ba(e,t){t.state="active",this.ar++;let r=this.generation;this.Ca(t).then(o=>{r===this.generation&&!t.controller.signal.aborted&&(this.S.set(e,{rows:o.rows,...o.lastRow==null?{}:{lastRow:o.lastRow},touchedAt:++this.dn}),this.Do()),t.resolve(o)},t.reject).finally(()=>{this.ar=Math.max(0,this.ar-1),this.x.get(e)===t&&this.x.delete(e),this.dr()})}Ca(e){let{signal:t}=e.controller;return t.aborted?Promise.reject(Q(t)):new Promise((r,o)=>{let n=()=>o(Q(t));t.addEventListener("abort",n,{once:!0}),Promise.resolve().then(()=>e.loader(t)).then(r,o).finally(()=>{t.removeEventListener("abort",n)})})}cn(e,t,r){return t.consumers++,new Promise((o,n)=>{let s=!1,a=d=>{s||(s=!0,r?.removeEventListener("abort",l),t.consumers=Math.max(0,t.consumers-1),d())},l=()=>a(()=>{t.consumers===0&&this.x.get(e)===t&&(this.x.delete(e),t.controller.abort(r?.reason),t.state==="queued"&&t.reject(Q(t.controller.signal))),n(Q(r))});r?.addEventListener("abort",l,{once:!0}),t.promise.then(d=>a(()=>o(d)),d=>a(()=>n(d instanceof Error?d:new Error(String(d??"Block request failed")))))})}Do(){let e=Math.max(this.maxBlocks,this.lr.size+1);for(;this.S.size>e;){let t=-1,r=Number.POSITIVE_INFINITY;for(let[n,s]of this.S)this.lr.has(n)||s.touchedAt<r&&(t=n,r=s.touchedAt);if(t<0)return;let o=this.S.get(t);this.S.delete(t),this.evictionCount++,o&&this.onEvict?.(t,o)}}};function ge(i,e){if(i==null||typeof i!="object")return;let t=i[e];return Array.isArray(t)?t:void 0}var Ve=class{constructor(e){this.core=e;this.all=[];this.M=[];this.k=new Map;this.displayed=[];this.r=new Map;this.filterModel={};this.advancedFilterModel=null;this.quickFilter=null;this.g=new Set;this.I=new Set;this.je=[];this.Tt=new Map;this.un=[];this.y=null;this.Ye=!1;this.hn=!1;this.U=0;this.cr=null;this.Dt=null;this.ur=null;this.hr=new WeakMap;this.Rt=new WeakMap;this.he=new Map;this.Et=new Map;this.xt=0;this.pr=0;this.pe=new Map;this.ke=new Map;this.fr=new Set;this.Ie=new Map;this.fe=new He(12,e=>this.pn(e));this.Mt=0;this.mr=null;this.Ro=!1;this.fn=0;this.N=[];this.page=1;this.pageSize=20;this.advancedFilterModel=V(e.options.advancedFilterModel)}resolveRowId(e,t,r){let o=this.core.options.resolveRowId;if(!o)return r;try{let n=o({data:e,index:t,api:this.core.getApi()});if(typeof n=="string"&&n.length>0)return n;this.core.reportError(new Error("rowKey must resolve to a non-empty identifier"),"rowKey",{index:t})}catch(n){this.core.reportError(n,"rowKey",{index:t})}return r}get w(){return this.core.options.treeData}get o(){return this.core.options.datasource!=null}get B(){return this.o&&this.core.options.datasourceMode==="block"}Xe(){if(this.o){if(this.B)return this.Je();let e=Math.max(0,this.displayed.length-this.all.length);return(this.y??this.all.length)+e}return this.displayed.length}Eo(){return this.xt}gr(){return this.pr}Ta(){return this.hn}xo(e){return!this.o||e?.aborted?Promise.resolve():(this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.core.changeTracker.clear(),this.yr(),this.y=null,this.Ye=!1,this.all=[],this.M=[],this.r.clear(),this.g.clear(),this.core.undoService.clear(),this.a(),this.core.requestUpdate({data:!0}),this.B?(this.fe.configure(this.core.options.maxBlocksInCache,this.core.options.datasourceMaxConcurrentRequests),this.vr(0,e)):this.mn(0,void 0,e))}gn(e){return this.o?this.xo(e):Promise.resolve()}Ae(e){this.hn=e,this.core.skeleton.Ae(e,this.core.getLocaleText("loading"))}mn(e,t,r){if(!this.o||this.Ye||this.y!=null&&e>=this.y)return Promise.resolve();let o=this.core.options.datasource,n=this.core.options.blockSize,s=t??e+n;if(s<=e)return Promise.resolve();let a=++this.U,l=new AbortController,d=()=>l.abort(r?.reason);return r?.addEventListener("abort",d,{once:!0}),this.cr=l,this.Ye=!0,this.Ae(!0),new Promise(c=>{let u=!1,h=0;this.ur=c;let p=g=>{u||(u=!0,r?.removeEventListener("abort",d),a===this.U&&(this.Ye=!1,this.cr=null,this.ur=null,this.Ae(!1),g!=null&&g?.name!=="AbortError"&&this.core.reportError(g,"datasource.getRows",{startRow:e,endRow:s})),c())},m=()=>{if(u||a!==this.U||l.signal.aborted||this.core.isDestroyed()){p();return}h++;let g=!1,v=y=>{if(!(g||u)){if(g=!0,a!==this.U||l.signal.aborted||this.core.isDestroyed()){p();return}if(h<=this.core.options.datasourceRetryCount){let b=this.retryDelay(h);this.Dt=setTimeout(()=>{this.Dt=null,m()},b);return}p(y??new Error("Datasource request failed"))}};try{let y=o.getRows({startRow:e,endRow:s,sortModel:this.core.columnModel.D(),filterModel:this.R(),advancedFilterModel:this.z(),quickFilterText:this.quickFilter,signal:l.signal,onSuccess:(b,C)=>{if(g||u)return;if(g=!0,a!==this.U||this.core.isDestroyed()||l.signal.aborted){p();return}let x=b??[];typeof C=="number"&&C>=0?this.y=C:x.length<s-e&&(this.y=e+x.length);let w=this.all.length===0;this.Da(x),p(),this.a(),this.core.requestUpdate({data:!0}),w&&this.core.relayout(),this.core.headerRenderer.wr()},fail:v});y&&typeof y.catch=="function"&&y.catch(v)}catch(y){v(y)}};m()})}yr(){this.U++,this.Dt!=null&&clearTimeout(this.Dt),this.Dt=null,this.cr?.abort(),this.cr=null,this.Ye=!1,this.Ae(!1),this.ur?.(),this.ur=null,this.fe.purge(),this.pe.clear(),this.ke.clear(),this.fr.clear();for(let[e,t]of this.Ie)this.r.get(e)===t&&this.r.delete(e);this.Ie.clear()}Da(e){for(let t of e){if(t==null)continue;let r=this.all.length,o=this.resolveRowId(t,r,`inf-${this.core.nextId()}`);if(this.r.has(o)){this.core.reportError(new Error(`Duplicate row id: ${o}`),"datasource.getRows",{rowId:o});continue}let n={id:o,data:t,rowIndex:-1,selected:this.core.selectionService.isSelected(o)};this.all.push(n),this.r.set(o,n),this.M.push(n)}}vr(e,t,r=0){if(!this.B||e<0)return Promise.resolve();if(t?.aborted)return Promise.reject(this.yn(t.reason));let o=this.core.options.blockSize,n=this.U,s=e*o;if(s>=this.Je())return Promise.resolve();let a=this.y==null?s+o:Math.min(this.y,s+o),l=this.fe.load(e,d=>this.Ra(s,a,d),t,r);return this.Ae(this.all.length===0&&this.fe.snapshot().loadingBlockCount>0),l.then(d=>{n!==this.U||t?.aborted||this.core.isDestroyed()||!this.B||!this.fe.has(e)||this.fr.has(e)||(this.Ea(e,d),this.a(),this.core.requestUpdate({data:!0}),this.core.headerRenderer.wr(),n===this.U&&!this.core.isDestroyed()&&this.vn(this.core.bodyRenderer.Mo().lastExcl-1))}).catch(d=>{throw d?.name!=="AbortError"&&this.core.reportError(d,"datasource.getRows",{startRow:s,endRow:a}),d}).finally(()=>{n===this.U&&this.Ae(this.all.length===0&&this.fe.snapshot().loadingBlockCount>0)})}Ra(e,t,r){let o=this.core.options.datasource;return new Promise((n,s)=>{let a=0,l=null,d=!1,c=p=>{d||(d=!0,l!=null&&clearTimeout(l),r.removeEventListener("abort",u),s(p instanceof Error?p:new Error(typeof p=="string"?p:"Datasource request failed")))},u=()=>c(this.yn(r.reason));r.addEventListener("abort",u,{once:!0});let h=()=>{if(d)return;if(r.aborted||this.core.isDestroyed()){u();return}a++;let p=!1,m=g=>{if(!(p||d)){if(p=!0,r.aborted||this.core.isDestroyed()){u();return}if(a<=this.core.options.datasourceRetryCount){let v=this.retryDelay(a);l=setTimeout(()=>{l=null,h()},v)}else c(g)}};try{let g=o.getRows({startRow:e,endRow:t,sortModel:this.core.columnModel.D(),filterModel:this.R(),advancedFilterModel:this.z(),quickFilterText:this.quickFilter,signal:r,onSuccess:(v,y)=>{p||d||(p=!0,d=!0,r.removeEventListener("abort",u),n({rows:v??[],...typeof y=="number"&&y>=0?{lastRow:y}:{}}))},fail:m});g&&typeof g.catch=="function"&&g.catch(m)}catch(g){m(g)}};h()})}Ea(e,t){let r=this.core.options.blockSize,o=e*r;this.pn(e),typeof t.lastRow=="number"&&t.lastRow>=0?this.y=t.lastRow:t.rows.length<r&&(this.y=o+t.rows.length),t.rows.forEach((n,s)=>{if(n==null)return;let a=o+s;if(this.y!=null&&a>=this.y)return;let l=this.resolveRowId(n,a,`block-${a}`),d=this.Ie.get(l),c=this.r.get(l);if(c&&c!==d&&c.rowIndex!==a){this.core.reportError(new Error(`Duplicate row id: ${l}`),"datasource.getRows",{rowId:l});return}let u=d??{id:l,data:n,rowIndex:a,selected:this.core.selectionService.isSelected(l)};u.rowIndex=a,u.selected=this.core.selectionService.isSelected(l),this.Ie.delete(l),this.pe.set(a,u),this.ke.delete(a),this.r.set(l,u),this.Rt.set(u,a+1)}),this.wn(),this.fr.add(e)}pn(e){this.fr.delete(e);let t=this.core.options.blockSize,r=e*t,o;for(let n=r;n<r+t;n++){let s=this.pe.get(n);s&&(o??(o=new Set(this.core.changeTracker.getDirtyRowIds())),this.pe.delete(n),o.has(s.id)?this.Ie.set(s.id,s):this.r.get(s.id)===s&&this.r.delete(s.id))}this.wn()}wn(){this.all=[...this.pe.entries()].sort(([e],[t])=>e-t).map(([,e])=>e),this.M=this.all}Je(){if(this.y!=null)return this.y;if(this.core.options.datasourceRowCount!=null)return this.core.options.datasourceRowCount;if(this.pe.size===0)return this.core.options.blockSize;let e=0;for(let t of this.pe.keys())e=Math.max(e,t+1);return e+this.core.options.blockSize}xa(e){let t=this.ke.get(e);if(!t&&(t={id:`__mach_loading_${e}`,data:null,rowIndex:e,selected:!1,loading:!0},this.ke.set(e,t),this.ke.size>2e3)){let r=this.ke.keys().next().value;r!=null&&this.ke.delete(r)}return t}yn(e){if(e instanceof Error)return e;let t=new Error(typeof e=="string"?e:"Operation aborted");return t.name="AbortError",t}retryDelay(e){let t=Math.min(this.core.options.datasourceRetryDelay*2**Math.max(0,e-1),3e4),r=this.core.options.datasourceRetryJitter;return Math.max(0,Math.round(t*(1+(Math.random()*2-1)*r)))}Ma(e){if(this.B){this.vn(e);return}if(!this.o||this.Ye)return;let t=this.all.length;if(this.y!=null&&t>=this.y)return;let r=this.core.options.infiniteBufferRows;if(e+r<t&&e<t)return;let o=this.core.options.blockSize,n=this.y==null?t+o:Math.min(this.y,t+o);this.mn(t,n)}vn(e){if(e<0)return;this.bn();let t=this.core.options.blockSize,r=Math.floor(e/t),o=Math.floor(this.core.bodyRenderer.Mo().first/t),n=this.core.options.blockPrefetch,s=r<this.fn?-1:1;this.fn=r;for(let a=o;a<r;a++)this.vr(a,void 0,n+2).catch(()=>{});for(let a=0;a<=n;a++){let l=a===0?[r]:[r+s*a,r-s*a];for(let d of l)d<0||d*t>=this.Je()||this.vr(d,void 0,n-a+1).catch(()=>{})}}ie(){return this.gn().catch(()=>{})}Sa(){return this.yr(),this.o?this.xo().catch(()=>{}):(this.y=null,this.me(this.core.options.rowData),this.core.requestUpdate({data:!0}),Promise.resolve())}destroy(){this.yr(),this.Cn(),this.So(),this.all=this.M=this.displayed=this.N=[],this.r.clear(),this.k.clear(),this.Tt.clear(),this.un=[],this.g.clear(),this.I.clear(),this.je=[],this.core.options.dataProcessor?.destroy?.()}ko(e,t,r){if(!this.B)return Promise.resolve();this.bn();let o=this.core.options.blockSize,n=Math.max(0,Math.trunc(e)),s=Math.min(this.Je(),Math.max(n,Math.trunc(t))),a=Math.floor(n/o),l=Math.max(a,Math.floor(Math.max(n,s-1)/o)),d=[];for(let c=a;c<=l;c++)d.push(this.vr(c,r,100));return Promise.all(d).then(()=>{})}Io(){this.B&&(this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.core.changeTracker.clear(),this.yr(),this.core.undoService.clear(),this.all=[],this.M=[],this.r.clear(),this.a(),this.core.requestUpdate({data:!0}))}Ao(){return this.fe.snapshot()}bn(){let e=new Set(this.core.changeTracker.getDirtyRowIds());for(let[l,d]of this.Ie)e.has(l)||(this.Ie.delete(l),this.r.get(l)===d&&this.r.delete(l));let t=this.core.options.blockSize,r=new Set,{first:o,lastExcl:n}=this.core.bodyRenderer.Mo();for(let l=o;l<n;l+=t)r.add(Math.floor(l/t));n>o&&r.add(Math.floor((n-1)/t));let s=this.core.bodyRenderer.c;s&&r.add(Math.floor(s.rowIndex/t));let a=this.core.editingService.ka();a!=null&&r.add(Math.floor(a/t)),this.fe.retain(r)}me(e){this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.Cn(),this.core.changeTracker.clear();let t=this.core.options.resolveRowId,r=this.core.options.childrenKey,o=[],n=[],s=new Map,a=new Map,l=0,d=(c,u,h)=>{let p=l++,m=this.resolveRowId(c,p,`auto-${p}`);if(s.has(m))return this.core.reportError(new Error(`Duplicate row id: ${m}`),"rowData",{rowId:m,index:p}),null;let g=this.w?ge(c,r):void 0,v={id:m,data:c,rowIndex:-1,selected:!1,treeChildrenLoaded:Array.isArray(g)};if(this.hr.set(v,u),o.push(v),s.set(m,v),h!=null){let y=a.get(h)??[];y.push(m),a.set(h,y)}else n.push(v);if(this.w&&Array.isArray(g))for(let y of g)y!=null&&d(y,u+1,m);return v};(e??[]).forEach(c=>{c!=null&&d(c,0,null)}),this.all=o,this.M=n,this.k=a,this.r=s,this.core.undoService.clear();for(let c of[...this.g])s.has(c)||this.g.delete(c);if(this.core.options.defaultExpandAll)for(let c of o)this.Tn(c.id)>0&&this.g.add(c.id);this.core.selectionService.onRowsRebuilt(t!=null),this.a()}St(e){return this.k.get(e)??[]}Tn(e){return this.k.get(e)?.length??0}Lo(e){return this.Tn(e)>0}isTreeRowLoading(e){return this.r.get(e)?.treeLoading===!0}Cn(){for(let e of this.he.values())e.abort();this.he.clear(),this.Et.clear()}loadTreeChildren(e,t=!1){let r=this.r.get(e),o=this.core.options.loadTreeChildren;if(!this.w||!r?.data||!o)return Promise.resolve([]);if(!t&&r.treeChildrenLoaded)return Promise.resolve(this.St(e).flatMap(l=>{let d=this.r.get(l)?.data;return d==null?[]:[d]}));let n=this.Et.get(e);if(n&&!t)return n;this.he.get(e)?.abort();let s=new AbortController;this.he.set(e,s),r.treeLoading=!0,r.treeLoadError=void 0,this.core.requestUpdate({data:!0});let a=Promise.resolve().then(()=>o({data:r.data,node:r,api:this.core.getApi(),signal:s.signal})).then(l=>{if(s.signal.aborted||this.core.isDestroyed())return[];if(!Array.isArray(l))throw new TypeError("[MachTable] loadTreeChildren must resolve to an array.");return this.Ia(r,l),r.treeChildrenLoaded=!0,r.treeLoadError=void 0,this.core.emit("treeChildrenLoaded",{rowId:e,rowNode:r,children:l}),l}).catch(l=>{if(s.signal.aborted||l?.name==="AbortError")return[];throw r.treeLoadError=l,r.treeChildrenLoaded=!1,this.core.reportError(l,"treeData.loadChildren",{rowId:e}),this.core.emit("treeChildrenLoadFailed",{rowId:e,rowNode:r,error:l}),l}).finally(()=>{this.he.get(e)===s&&(this.he.delete(e),this.Et.delete(e),r.treeLoading=!1,this.core.requestUpdate({data:!0}))});return this.Et.set(e,a),a}Ia(e,t){let r=new Set,o=[...this.St(e.id)];for(;o.length>0;){let s=o.pop();r.has(s)||(r.add(s),o.push(...this.St(s)))}this.Aa(t,r);for(let s of r)this.he.get(s)?.abort(),this.he.delete(s),this.Et.delete(s),this.k.delete(s),this.r.delete(s),this.g.delete(s);this.k.delete(e.id);let n=this.Po(e)+1;for(let s of t)s!=null&&this.Go(e,s,n);this.Dn(),this.core.selectionService.onRowsRebuilt(this.core.options.resolveRowId!=null),this.a(),this.core.requestUpdate({data:!0})}Aa(e,t){let r=this.core.options.resolveRowId,o=r?new Set([...this.r.keys()].filter(l=>!t.has(l))):null,n=new WeakSet,s=[...e],a=0;for(;s.length>0;){let l=s.pop();if(l==null)continue;if(typeof l=="object"){if(n.has(l))throw new TypeError("[MachTable] Lazy tree children contain a cyclic object graph.");n.add(l)}if(r&&o){let c=r({data:l,index:a++,api:this.core.getApi()});if(typeof c!="string"||c.length===0)throw new TypeError("[MachTable] rowKey must resolve to a non-empty identifier for lazy tree children.");if(o.has(c))throw new Error(`Duplicate row id: ${c}`);o.add(c)}let d=ge(l,this.core.options.childrenKey);d&&s.push(...d)}}kt(e,t=!0){let r=this.core.options.resolveRowId,o=[],n=[];if(e.remove?.length){let a=new Set,l=new Set,d=u=>{if(r){let p=[this.resolveRowId(u,-1,`__missing_remove_${this.core.nextId()}`)];for(;p.length>0;){let m=p.pop();if(!a.has(m)){a.add(m);for(let g of this.k.get(m)??[])p.push(g)}}}else{let h=[u];for(;h.length>0;){let p=h.pop();l.add(p);let m=this.w?ge(p,this.core.options.childrenKey):void 0;if(m)for(let g of m)h.push(g)}}};e.remove.forEach(d),this.all=this.all.filter(u=>{let h=a.has(u.id)||u.data!=null&&l.has(u.data);return h&&(n.push(u.id),this.r.delete(u.id),this.k.delete(u.id)),!h});let c=new Set(this.all);this.M=this.M.filter(u=>c.has(u))}if(e.update?.length)for(let a of e.update){let l;r?l=this.r.get(this.resolveRowId(a,-1,`__missing_update_${this.core.nextId()}`)):l=this.all.find(d=>d.data===a),l&&(l.data=a,n.push(l.id),this.core.bodyRenderer.br(l),o.push(l))}if(e.add?.length){let a=e.addIndex!=null?Math.max(0,Math.min(e.addIndex,this.M.length)):this.M.length,l=[];e.add.forEach((d,c)=>{let u=this.resolveRowId(d,a+c,`add-${this.core.nextId()}`);if(this.r.has(u)){this.core.reportError(new Error(`Duplicate row id: ${u}`),"transaction.add",{rowId:u});return}let h={id:u,data:d,rowIndex:-1,selected:!1};this.r.set(u,h),this.hr.set(h,0);let p=this.w?ge(d,this.core.options.childrenKey):void 0;if(p)for(let m of p)m!=null&&this.Go(h,m,1);l.push(h)}),this.M.splice(a,0,...l),this.Dn()}let s=this.La(e);return t&&(s?this.a():o.length>0&&this.Rn()),this.core.changeTracker.clearRows(n),{pipelineChanged:s,updatedRowIds:o.map(a=>a.id)}}Pa(e){if(e.length===0)return{pipelineChanged:!1,updatedRowIds:[]};let t=!1,r=new Set;for(let o of e){let n=this.kt(o,!1);t||(t=n.pipelineChanged);for(let s of n.updatedRowIds)r.add(s)}return t?this.a():r.size>0&&this.Rn(),{pipelineChanged:t,updatedRowIds:[...r]}}La(e){return e.add?.length||e.remove?.length?!0:e.update?.length?this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0||!this.core.options.manualFiltering&&this.Cr()||!this.core.options.manualSorting&&this.core.columnModel.D().length>0||this.core.options.getRowHeight?!0:this.core.columnModel.e().some(t=>t.colDef.autoHeight===!0||t.colDef.autoRowSpan===!0||t.colDef.rowSpan!=null):!1}Rn(){this.core.emit("modelUpdated",{rowCount:this.N.length})}Go(e,t,r){let o=this.resolveRowId(t,-1,`add-${this.core.nextId()}`);if(this.r.has(o)){this.core.reportError(new Error(`Duplicate row id: ${o}`),"transaction.add",{rowId:o});return}let n=ge(t,this.core.options.childrenKey),s={id:o,data:t,rowIndex:-1,selected:!1,treeChildrenLoaded:Array.isArray(n)};this.r.set(o,s),this.hr.set(s,r);let a=this.k.get(e.id)??[];if(a.push(s.id),this.k.set(e.id,a),!!n)for(let l of n)l!=null&&this.Go(s,l,r+1)}Dn(){this.all=[];let e=t=>{this.all.push(t),this.r.has(t.id)||this.r.set(t.id,t);for(let r of this.k.get(t.id)??[]){let o=this.r.get(r);o&&e(o)}};for(let t of this.M)e(t)}It(e){let t=JSON.stringify(this.filterModel),r=new Set(this.core.columnModel.G().map(o=>o.id));return this.filterModel=J(e,r),JSON.stringify(this.filterModel)!==t}R(){return{...this.filterModel}}Ze(e){let t=new Set(this.core.columnModel.G().map(n=>n.id)),r=V(e,t),o=JSON.stringify(this.advancedFilterModel);return this.advancedFilterModel=r,this.core.options.advancedFilterModel=r,JSON.stringify(r)!==o}z(){return V(this.advancedFilterModel)}Qe(e){let t=e!=null&&e.trim()!==""?e:null;return t===this.quickFilter?!1:(this.quickFilter=t,!0)}At(){return this.quickFilter}Cr(){return Object.keys(this.filterModel).length>0||this.advancedFilterModel!=null||this.quickFilter!=null}a(){let e=this.core.performanceMonitor.start(),t=this.core.columnModel.e(),r=(s,a)=>this.core.getCellValue(s,a);if(this.o){this.Ga(e);return}if(this.Na(e))return;let o;if(this.w)o=this.Fa(t,r);else{o=this.all,this.Cr()&&!this.core.options.manualFiltering&&(o=o.filter(Nt(t,this.filterModel,this.advancedFilterModel,this.quickFilter,r)));let a=this.core.columnModel.D();if(a.length>0&&!this.core.options.manualSorting)try{o=Ft(o,a,t,r)}catch(d){this.core.reportError(d,"comparator",{sortModel:a})}let l=this.core.columnModel.re();if(l.length>0)o=this.Oa(o,l);else if(this.core.options.masterDetail){let d=[];for(let c of o)d.push(c),this.g.has(c.id)&&this.isRowExpandable(c)&&d.push({id:`__detail__${c.id}`,data:c.data,rowIndex:-1,selected:!1,isDetail:!0,masterId:c.id});o=d}}for(let s of this.all)s.rowIndex=-1;let n=0;o.forEach((s,a)=>{s.rowIndex=a,!s.isDetail&&!s.isGroup&&(n++,this.Rt.set(s,n))}),this.N=o,this.et(),this.En(r),this.core.emit("modelUpdated",{rowCount:o.length}),this.core.performanceMonitor.recordModel(e)}Ga(e){this.all.forEach((t,r)=>{this.B||(t.rowIndex=r),this.Rt.set(t,this.B?t.rowIndex+1:r+1)}),this.displayed=this.all,this.N=this.all,this.Tt.clear(),this.xt++,this.core.emit("modelUpdated",{rowCount:this.all.length}),this.core.performanceMonitor.recordModel(e)}Na(e){let t=this.Ro;return this.Ro=!1,!t&&this.Ha()?(this.Va(e),!0):(this.So(),!1)}Ha(){if(!this.core.options.dataProcessor||this.all.length<this.core.options.dataProcessorMinRows||this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0)return!1;let e=!this.core.options.manualFiltering&&this.Cr(),t=!this.core.options.manualSorting&&this.core.columnModel.D().length>0;return e||t}Va(e){this.So();let t=this.core.options.dataProcessor;if(!t)return;let r=++this.Mt,o=new AbortController;this.mr=o;let n=this.core.columnModel.e(),s=this.all.flatMap(d=>d.data==null?[]:[{id:d.id,data:d.data}]),a=!this.core.options.manualFiltering,l=!this.core.options.manualSorting;Promise.resolve().then(()=>t.process({rows:s,columns:n.map(d=>({colId:d.id,...d.colDef.field?{field:d.colDef.field}:{}})),sortModel:l?this.core.columnModel.D():[],filterModel:a?this.R():{},advancedFilterModel:a?this.z():null,quickFilterText:a?this.quickFilter:null,signal:o.signal})).then(d=>{if(r!==this.Mt||o.signal.aborted||this.core.isDestroyed())return;let c=new Set,u=[];for(let p of d.rowIds){if(c.has(p))continue;c.add(p);let m=this.r.get(p);m&&!m.isDetail&&!m.isGroup&&u.push(m)}for(let p of this.all)p.rowIndex=-1;u.forEach((p,m)=>{p.rowIndex=m,this.Rt.set(p,m+1)}),this.N=u,this.et();let h=(p,m)=>this.core.getCellValue(p,m);this.En(h),this.core.emit("modelUpdated",{rowCount:u.length}),this.core.performanceMonitor.recordModel(e),this.core.requestUpdate({data:!0})}).catch(d=>{r!==this.Mt||o.signal.aborted||this.core.isDestroyed()||(this.core.reportError(d,"dataProcessor.process"),this.Ro=!0,this.a(),this.core.requestUpdate({data:!0}))}).finally(()=>{r===this.Mt&&(this.mr=null)})}So(){this.Mt++,this.mr?.abort(),this.mr=null}get j(){return this.core.options.paginationEnabled&&!this.o}et(){if(!this.j){this.displayed=this.N,this.xt++;return}let e=this.Lt(),t=this.getPageCount();if(this.page>t&&(this.page=t),this.page<1&&(this.page=1),this.core.options.paginationPage=this.page,this.core.options.paginationMode==="server"){this.N.forEach((n,s)=>{n.rowIndex=s}),this.displayed=this.N,this.xt++;return}let r=(this.page-1)*e,o=this.N.slice(r,r+e);o.forEach((n,s)=>{n.rowIndex=s}),this.displayed=o,this.xt++}Lt(){return this.pageSize=this.core.options.paginationPageSize,Math.max(1,this.pageSize)}Pt(){return this.j?this.page:1}getTotalRowCount(){return this.o?this.Xe():this.j&&this.core.options.paginationMode==="server"?this.core.options.paginationTotal:this.N.length}getPageCount(){return this.j?Math.max(1,Math.ceil(this.getTotalRowCount()/this.Lt())):1}xn(){return this.N}setPage(e,t=!1){if(!this.j)return;let r=this.getPageCount(),o=Math.max(1,Math.min(Math.round(e)||1,r));o!==this.page&&(this.page=o,this.core.options.paginationPage=o,this.et(),this.core.requestUpdate({data:!0}),this.core.bodyRenderer.tt(0,"top"),t||this.Tr())}setPageSize(e){if(!this.j)return;let t=Math.max(1,Math.round(e)||this.Lt()),r=(this.page-1)*this.Lt();this.core.options.paginationPageSize=t,this.pageSize=t,this.page=Math.floor(r/t)+1,this.core.options.paginationPage=this.page,this.et(),this.core.requestUpdate({data:!0}),this.Tr()}Mn(e,t){this.pageSize=Math.max(1,Math.round(t)||1),this.core.options.paginationPageSize=this.pageSize,this.page=Math.max(1,Math.round(e)||1),this.core.options.paginationPage=this.page}Dr(e){this.core.options.paginationEnabled!==e&&(this.core.options.paginationEnabled=e&&!this.o,this.core.options.paginationEnabled&&(this.page=1),this.et(),this.core.requestUpdate({data:!0}),this.Tr())}Ba(){this.j&&(this.page=this.core.options.paginationMode==="server"?this.core.options.paginationPage:1,this.et(),this.core.requestUpdate({data:!0}),this.Tr())}Tr(){this.core.emit("paginationChanged",{page:this.Pt(),pageSize:this.Lt(),pageCount:this.getPageCount(),total:this.getTotalRowCount()})}Fa(e,t){let r=this.core.options.manualSorting?[]:this.core.columnModel.D(),o=new Map,n=this.Cr()&&!this.core.options.manualFiltering,s=Nt(e,this.filterModel,this.advancedFilterModel,this.quickFilter,t),a=c=>{let u=o.get(c.id);if(u!==void 0)return u;let h=!0;if(n){h=s(c);for(let p of this.k.get(c.id)??[]){let m=this.r.get(p);m&&a(m)&&(h=!0)}}return o.set(c.id,h),h},l=[],d=c=>{let u=c;r.length>0&&(u=Ft(c,r,e,t));for(let h of u)if(a(h)&&(l.push(h),this.g.has(h.id))){let p=(this.k.get(h.id)??[]).map(m=>this.r.get(m)).filter(m=>m!=null);d(p)}};return d(this.M),l}za(){let e=this.un,t=0;for(let r of this.displayed)!r.isDetail&&!r.isGroup&&(e[t++]=r);return e.length=t,e}_a(e,t,r,o){let n=t.colDef.rowSpan;if(!n)return 1;try{let s=n({api:this.core.getApi(),colDef:t.colDef,column:t,node:e,data:e.data,value:r,rowIndex:e.rowIndex});return Math.max(1,Math.min(Math.round(s)||1,o))}catch(s){return this.core.reportError(s,"rowSpan",{colId:t.id,rowId:e.id}),1}}Wa(e,t,r,o,n){if(!r.colDef.autoRowSpan||o==null||o==="")return 1;let s=1;for(;t+s<e.length&&Ne(o,n(e[t+s],r))===0;)s++;return s}$a(e,t,r){let o=new Int32Array(e.length),n=0;for(;n<e.length;){let s=e[n],a=r(s,t),l=t.colDef.rowSpan?this._a(s,t,a,e.length-n):this.Wa(e,n,t,a,r);o[n]=l;for(let d=1;d<l;d++)o[n+d]=-1;n+=l}return o}En(e){if(this.Tt.clear(),this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0)return;let t=this.core.columnModel.e().filter(o=>o.colDef.rowSpan!=null||o.colDef.autoRowSpan===!0);if(t.length===0)return;let r=this.za();if(r.length!==0)for(let o of t)this.Tt.set(o.id,this.$a(r,o,e))}Ka(e){return this.Tt.get(e)}Sn(e){return this.Rt.get(e)??0}Po(e){return this.hr.get(e)??0}Oa(e,t){let r=Ot(this.core.options.aggFuncs),o=this.core.columnModel.ya();this.je=[];let n=a=>{let l={};for(let d of o){let c=r(d.colDef.aggFunc);if(c)try{l[d.id]=c(a.map(u=>this.core.getCellValue(u,d)))}catch(u){this.core.reportError(u,"aggFunc",{colId:d.id,aggFunc:d.colDef.aggFunc}),l[d.id]=null}}return l},s=(a,l,d)=>{if(l>=t.length)return{display:a,leaves:a};let c=t[l],u=new Map,h=[];for(let g of a){let v=this.core.getCellValue(g,c),y=v==null?"(\u7A7A)":String(v),b=u.get(y);b||(b=[],u.set(y,b),h.push(y)),b.push(g)}h.sort((g,v)=>g.localeCompare(v,void 0,{numeric:!0,sensitivity:"base"}));let p=[],m=[];for(let g of h){let v=u.get(g),y=`${d}/g${l}:${g}`;this.je.push(y);let b=s(v,l+1,y),C={id:y,data:null,rowIndex:-1,selected:!1,isGroup:!0,groupLevel:l,groupKey:g,leafNodes:b.leaves,aggValues:n(b.leaves)};p.push(C),this.I.has(y)&&p.push(...b.display),m.push(...b.leaves)}return{display:p,leaves:m}};return s(e,0,"").display}isRowExpandable(e){if(this.w){if(this.Lo(e.id)||e.treeLoading)return!0;if(e.treeChildrenLoaded||!e.data||!this.core.options.loadTreeChildren)return!1;let r=this.core.options.isTreeRowExpandable;if(!r)return!1;try{return r({data:e.data,node:e,api:this.core.getApi()})}catch(o){return this.core.reportError(o,"isTreeRowExpandable",{rowId:e.id}),!1}}if(!this.core.options.masterDetail)return!1;let t=this.core.options.isRowExpandable;if(t)try{return t({data:e.data,node:e,api:this.core.getApi()})}catch(r){return this.core.reportError(r,"isRowExpandable",{rowId:e.id}),!1}return!0}isRowExpanded(e){return this.g.has(e)}qa(){return[...this.g]}Ua(){return[...this.I]}ja(e,t){this.g=new Set(e.filter(r=>this.r.has(r))),this.I=new Set(t)}No(e){return this.Fo(e,!0)}Oo(e){return this.Fo(e,!1)}toggleDetail(e){return this.Fo(e,!this.g.has(e))}Fo(e,t){let r=this.r.get(e);return!r||t&&!this.isRowExpandable(r)?!1:(t===this.g.has(e)||(t?this.g.add(e):this.g.delete(e),this.a(),this.core.requestUpdate({data:!0}),this.core.emit("detailToggled",{rowId:e,rowNode:r,expanded:t}),t&&this.w&&!this.Lo(e)&&!r.treeLoading&&this.loadTreeChildren(e).catch(()=>{})),t)}Ho(){let e=!1;for(let t of this.all)!this.g.has(t.id)&&this.isRowExpandable(t)&&(this.g.add(t.id),e=!0);e&&(this.a(),this.core.requestUpdate({data:!0}))}Vo(){this.g.size!==0&&(this.g.clear(),this.a(),this.core.requestUpdate({data:!0}))}Bo(e){return this.setGroupExpanded(e,!this.I.has(e))}isGroupExpanded(e){return this.I.has(e)}uh(e){return this.displayed.find(t=>t.isGroup&&t.id===e)}zo(){if(this.je.length===0)return;let e=!1;for(let t of this.je)this.I.has(t)||(this.I.add(t),e=!0);e&&(this.a(),this.core.requestUpdate({data:!0}))}_o(){this.I.size!==0&&(this.I.clear(),this.a(),this.core.requestUpdate({data:!0}))}setGroupExpanded(e,t){return!this.je.includes(e)||t===this.I.has(e)||(t?this.I.add(e):this.I.delete(e),this.a(),this.core.requestUpdate({data:!0})),t}kn(){return!this.w&&!this.o&&!this.core.options.dataProcessor&&this.core.options.paginationMode!=="server"&&this.core.columnModel.D().length===0&&this.core.columnModel.re().length===0}In(e,t){if(!this.kn()||!Number.isInteger(e)||!Number.isInteger(t))return!1;let r=this.i(e),o=this.i(t);if(!r||!o||r.isDetail||o.isDetail||r.isGroup||o.isGroup)return!1;let n=this.all.indexOf(r),s=this.all.indexOf(o);return n<0||s<0||n===s?!1:(this.all.splice(n,1),this.all.splice(s,0,r),this.a(),this.core.requestUpdate({data:!0}),!0)}_(){return this.all}Ya(){return this.M}ge(){return this.displayed}f(){return this.B?this.Je():this.displayed.length}i(e){return this.B?e<0||e>=this.Je()?void 0:this.pe.get(e)??this.xa(e):this.displayed[e]}T(e){return this.r.get(e)}Wo(e){this.all.forEach(e)}$o(e){let t=0;for(let r of this.N)r.isDetail||r.isGroup||e(r,t++)}};var Be=class{constructor(e){this.core=e;this.h=new Set;this.ne=null;this.Gt=new Set}isSelected(e){return this.h.has(e)}isIndeterminate(e){return this.Gt.has(e)}isSelectable(e){if(e.loading)return!1;let t=this.Xa(e),r=t?.colDef.selectable;if(!t||!r)return!0;try{return r({api:this.core.getApi(),colDef:t.colDef,column:t,node:e,data:e.data,value:this.core.getCellValue(e,t),rowIndex:e.rowIndex})}catch(o){return this.core.reportError(o,"selectable",{rowId:e.id,colId:t?.id}),!1}}Xa(e){if(!(e.isGroup||e.isDetail))return this.core.columnModel.e().find(t=>t.hasCheckbox&&t.colDef.selectable!=null)}getSelectedNodes(){return this.core.rowModel._().filter(e=>this.h.has(e.id))}getSelectedRows(){return this.getSelectedNodes().filter(e=>e.data!=null).map(e=>e.data)}getSelectedIds(){return[...this.h]}restoreSelection(e){let t=new Set(e),r=this.core.rowModel._().filter(o=>t.has(o.id)&&!o.isDetail&&!o.isGroup).map(o=>({node:o,selected:!0}));this.W(r,!0)}onRowsRebuilt(e){if(!e)this.h.clear(),this.ne=null;else{let t=new Set(this.core.rowModel._().map(r=>r.id));for(let r of[...this.h])t.has(r)||this.h.delete(r);this.ne!=null&&!t.has(this.ne)&&(this.ne=null)}for(let t of this.core.rowModel._())t.selected=this.h.has(t.id);this.An()}getGroupSelectionState(e){let t=e.leafNodes??[];if(t.length===0)return{all:!1,some:!1};let r=0,o=0;for(let n of t)this.isSelectable(n)&&(r++,this.h.has(n.id)&&o++);return r===0?{all:!1,some:!1}:{all:o===r,some:o>0}}setGroupSelected(e,t){let r=(e.leafNodes??[]).filter(o=>this.isSelectable(o));r.length!==0&&this.W(r.map(o=>({node:o,selected:t})))}setNodeSelected(e,t,r=!1){this.W([{node:e,selected:t,clearOthers:r}])}selectNodeById(e,t=!0,r=!0){let o=this.core.rowModel.T(e);o&&this.setNodeSelected(o,t,r)}Ja(e,t){let r=t==="single";this.W([{node:e,selected:r?!0:!e.selected,clearOthers:r}]),this.ne=e.id}Za(e,t,r){return!r||!t.ctrlKey&&!t.metaKey?!1:(this.W([{node:e,selected:!e.selected}]),this.ne=e.id,!0)}Qa(e,t,r){if(!r||!t.shiftKey||this.ne==null)return!1;let o=this.core.rowModel.T(this.ne);if(!o||o.rowIndex<0||e.rowIndex<0)return!1;let n=Math.min(o.rowIndex,e.rowIndex),s=Math.max(o.rowIndex,e.rowIndex),a=[];for(let l=n;l<=s;l++){let d=this.core.rowModel.i(l);d&&!d.isDetail&&!d.isGroup&&this.isSelectable(d)&&a.push({node:d,selected:!0})}return this.W(a),!0}onRowClick(e,t,r){let o=this.core.options.rowSelection;if(o==="none"||!this.isSelectable(e))return;if(r){this.Ja(e,o);return}let n=o==="multiple";this.Za(e,t,n)||this.Qa(e,t,n)||(this.W([{node:e,selected:!0,clearOthers:!0}]),this.ne=e.id)}selectAll(e=!0){let t=this.core.options.rowSelection;if(t==="none")return;let o=(e?this.core.rowModel.ge():this.core.rowModel._()).filter(n=>!n.isDetail&&!n.isGroup&&this.isSelectable(n));if(o.length!==0){if(t==="single"){this.W([{node:o[0],selected:!0,clearOthers:!0}]);return}this.W(o.map(n=>({node:n,selected:!0})))}}deselectAll(){this.W([],!0)}isSelectAllActive(){let t=this.core.rowModel.ge().filter(r=>!r.isDetail&&!r.isGroup).filter(r=>this.isSelectable(r));if(t.length===0)return!1;if(this.core.rowModel.o){let r=this.core.rowModel.Xe();if(t.length<r)return!1}return t.every(r=>this.h.has(r.id))}isSelectAllIndeterminate(){let t=this.core.rowModel.ge().filter(o=>!o.isDetail&&!o.isGroup).filter(o=>this.isSelectable(o)),r=t.reduce((o,n)=>o+(this.h.has(n.id)?1:0),0);if(r===0)return!1;if(this.core.rowModel.o){let o=this.core.rowModel.Xe();if(t.length<o)return!0}return r>0&&r<t.length}applySelectionPublic(e,t=!1){this.W(e,t)}tl(e,t,r){!t&&!e.some(o=>o.clearOthers)||(this.h=t?new Set:new Set(e.filter(o=>o.selected).flatMap(o=>r?this.Ln(o.node):[o.node.id])))}rl(e,t){for(let r of e){if(!this.isSelectable(r.node))continue;let o=t?this.Ln(r.node):[r.node.id];for(let n of o)r.selected?this.h.add(n):this.h.delete(n)}}ol(e){let t=new Set;for(let r of new Set([...e,...this.h]))e.has(r)!==this.h.has(r)&&t.add(r);return t}il(e,t,r){let o=[],n=new Set([...e,...r,...this.Gt]);for(let s of this.core.rowModel._()){let a=this.h.has(s.id);s.selected=a,(n.has(s.id)||t.get(s.id)!==a)&&s.rowIndex>=0&&o.push(s.rowIndex)}return o}W(e,t=!1){let r=new Set(this.h),o=this.core.rowModel.w&&this.core.options.autoCheckedChildren;this.tl(e,t,o),this.rl(e,o);let n=this.ol(r),s=new Map;for(let d of this.core.rowModel._())s.set(d.id,d.selected);let a=new Set(this.Gt);this.An();let l=this.il(n,s,a);n.size>0&&(this.core.bodyRenderer.ye(l),this.core.headerRenderer.wr(),this.core.emit("selectionChanged",{selectedNodes:this.getSelectedNodes(),selectedRows:this.getSelectedRows()}))}Ln(e){let t=[e.id],r=o=>{for(let n of this.core.rowModel.St(o))t.push(n),r(n)};return r(e.id),t}An(){if(this.Gt.clear(),!this.core.rowModel.w)return;let e=t=>{let r=this.core.rowModel.St(t);if(r.length===0)return{all:this.h.has(t),some:this.h.has(t)};let o=!0,n=!1;for(let s of r){let a=e(s);a.all?n=!0:(a.some&&(n=!0),o=!1)}return n&&!o&&this.Gt.add(t),o?this.h.add(t):this.h.delete(t),{all:o,some:n}};for(let t of this.core.rowModel.Ya())e(t.id);for(let t of this.core.rowModel._())t.selected=this.h.has(t.id)}};var ze=class{constructor(e){this.core=e;this.active=null;this.A=0;this.ve=0;this.Y=null;this.Le=null;this.we=e=>{let t=this.qo(e);t&&(this.ve=this.Fn(t,e.clientX),t.didResize||(t.didResize=Math.abs(this.ve-t.startWidth)>=.5),!this.A&&(this.A=requestAnimationFrame(()=>{this.A=0,this.sl()})))};this.X=e=>{let t=this.qo(e);t&&(this.ve=this.Fn(t,e.clientX),t.didResize||(t.didResize=Math.abs(this.ve-t.startWidth)>=.5),this.al(t))};this.Pe=e=>{this.qo(e)&&this.cancelResize()};this.Pn=()=>{this.cancelResize()}}startResize(e,t){if(!this.core.options.enableColumnResize||!t.resizable||e.isPrimary===!1)return;this.cancelResize();let r=e.currentTarget,o=t.currentWidth;this.ve=o,this.active={column:t,didResize:!1,handle:r,pointerId:e.pointerId,startFlex:t.flex,startManualWidth:t.manualWidth,startWidth:o,startX:e.clientX},window.addEventListener("pointermove",this.we),window.addEventListener("pointerup",this.X,!0),window.addEventListener("pointercancel",this.Pe,!0),r.addEventListener("lostpointercapture",this.Pn);try{r.setPointerCapture?.(e.pointerId)}catch{}this.core.skeleton.root.classList.add("mach-root--resizing"),r.classList.add("mach-header-resize--active"),this.nl(this.active)}cancelResize(e=!0){let t=this.active;t&&(this.active=null,this.Ko(),this.Gn(t),e&&(t.column.manualWidth=t.startManualWidth,t.column.flex=t.startFlex,this.core.relayoutColumns()),this.core.skeleton.root.classList.remove("mach-root--resizing"),this.Nn(t))}al(e){this.active=null,this.Ko(),e.didResize&&(Math.abs(this.ve-e.startWidth)<.5?(e.column.manualWidth=e.startManualWidth,e.column.flex=e.startFlex):this.core.columnModel.oe(e.column,this.ve),this.core.relayoutColumns()),this.Gn(e);try{e.handle.releasePointerCapture?.(e.pointerId)}catch{}this.core.skeleton.root.classList.remove("mach-root--resizing"),this.Nn(e),e.didResize&&this.core.commitColumnWidths([e.column])}sl(){let e=this.active;!e||!this.core.columnModel.oe(e.column,this.ve)||(this.core.relayoutColumns(),this.Nt(e),this.core.emitColumnResize(e.column,!1))}nl(e){this.Y=document.createElement("div"),this.Y.className="mach-column-resize-guide",this.Y.setAttribute("aria-hidden","true"),this.Le=document.createElement("span"),this.Le.className="mach-column-resize-label",this.Y.appendChild(this.Le),this.core.skeleton.root.appendChild(this.Y),this.Nt(e)}Nt(e){if(!this.Y||!this.Le)return;let t=this.core.skeleton.root,r=t.getBoundingClientRect(),o=e.handle.parentElement.getBoundingClientRect(),n=Math.max(0,Math.min(t.clientWidth,o.right-r.left-t.clientLeft)),s=Math.max(32,Math.min(t.clientWidth-32,n));this.Y.style.left=`${n}px`,this.Y.style.top=`${Math.max(0,o.top-r.top-t.clientTop)}px`,this.Le.style.left=`${s-n}px`,this.Le.textContent=`${Math.round(e.column.currentWidth)} px`}Nn(e){e.handle.classList.remove("mach-header-resize--active"),this.Y?.remove(),this.Y=null,this.Le=null}Fn(e,t){let r=Number.isFinite(t)?t:e.startX;return e.startWidth+r-e.startX}qo(e){let t=this.active;return t&&e.pointerId===t.pointerId?t:null}Ko(){this.A&&cancelAnimationFrame(this.A),this.A=0}Gn(e){window.removeEventListener("pointermove",this.we),window.removeEventListener("pointerup",this.X,!0),window.removeEventListener("pointercancel",this.Pe,!0),e.handle.removeEventListener("lostpointercapture",this.Pn)}destroy(){this.cancelResize(!1),this.Ko(),this.core.skeleton.root?.classList.remove("mach-root--resizing")}};function f(i,e,t){let r=document.createElement(i);if(e&&(r.className=e),t)for(let o of Object.keys(t))r.setAttribute(o,t[o]);return r}var Ki=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function L(i,e){if(i.classList.add("mach-portal"),!e)return;let t=window.getComputedStyle(e);for(let r of Ki){let o=t.getPropertyValue(r).trim();o&&i.style.setProperty(r,o)}i.style.colorScheme=t.colorScheme}function R(i,e,t){return i<e?e:i>t?t:i}var Gr=0;function Nr(i="rg"){return Gr++,`${i}-${Gr}`}var Fr='<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3.5h12L9.5 8v4.5L6.5 14V8L2 3.5z"/></svg>',Or='<svg viewBox="0 0 16 16" width="10" height="10" fill="currentColor"><path d="M8 3l4 5H4l4-5z"/></svg>',Hr='<svg viewBox="0 0 16 16" width="10" height="10" fill="currentColor"><path d="M8 13l4-5H4l4 5z"/></svg>',Vr='<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.35" stroke-linecap="round"><path d="M2 4h3m3 0h6M2 8h7m3 0h2M2 12h1m3 0h8"/><circle cx="6.5" cy="4" r="1.35"/><circle cx="10.5" cy="8" r="1.35"/><circle cx="4.5" cy="12" r="1.35"/></svg>';var Br=6,_e=class{constructor(e){this.core=e;this.pending=null;this.rt=null;this.Uo=!1;this.F=0;this.Rr=null;this.we=e=>{if(this.rt){this.ll(e);return}let t=this.pending;t&&(Math.abs(e.clientX-t.startX)<Br&&Math.abs(e.clientY-t.startY)<Br||this.dl(e))};this.X=e=>{this.pending=null,e.type!=="pointercancel"&&this.rt&&this.Xo(e.clientX,e.clientY),this.jo();let t=this.On();t&&e.type!=="pointercancel"&&t.targetIndex>=0&&this.core.moveColumn(t.column.id,t.targetIndex)}}onPointerDown(e,t){e.button===0&&t.movable&&(this.pending={column:t,startX:e.clientX,startY:e.clientY},window.addEventListener("pointermove",this.we),window.addEventListener("pointerup",this.X),window.addEventListener("pointercancel",this.X))}didDrag(){let e=this.Uo;return this.Uo=!1,e}dl(e){let t=this.pending;if(!t)return;let r=this.cl(t.column);if(!r||!r.parentElement){this.jo();return}this.Uo=!0;let o=f("div","mach-drop-indicator"),n=f("div","mach-column-drag-ghost");n.textContent=t.column.colDef.headerName??t.column.colDef.field??t.column.id,n.ariaHidden="true",L(n,this.core.skeleton.root),document.body.appendChild(n),r.parentElement.appendChild(o),r.classList.add("mach-header-cell--dragging"),this.core.skeleton.root.classList.add("mach-root--dragging");let s=this.core.bodyRenderer.Yo(t.column),a=this.core.skeleton.ot[s],l=this.core.columnModel.d(s),d=new Float64Array(l.length+1),c=new Float64Array(l.length);for(let h=0;h<l.length;h++){let p=l[h].currentWidth;c[h]=d[h]+p/2,d[h+1]=d[h]+p}let u=n.getBoundingClientRect();this.rt={column:t.column,cellEl:r,ghost:n,indicator:o,targetIndex:-1,pane:s,containerLeft:a.getBoundingClientRect().left,startScrollLeft:this.core.skeleton.b.center.scrollLeft,fromIndex:l.indexOf(t.column),midpoints:c,offsets:d,ghostWidth:u.width,ghostHeight:u.height},this.Xo(e.clientX,e.clientY)}cl(e){let t=this.core.bodyRenderer.Yo(e);return this.core.skeleton.ot[t].querySelector(`.mach-header-cell[data-col-id="${qi(e.id)}"]`)}ll(e){this.Rr={clientX:e.clientX,clientY:e.clientY},!this.F&&(this.F=requestAnimationFrame(()=>{this.F=0;let t=this.Rr;this.Rr=null,t&&this.Xo(t.clientX,t.clientY)}))}Xo(e,t){let r=this.rt;if(!r)return;let o=R(e+12,8,window.innerWidth-r.ghostWidth-8),n=R(t+12,8,window.innerHeight-r.ghostHeight-8);r.ghost.style.transform=`translate3d(${o}px, ${n}px, 0)`;let s=r.pane==="center"?this.core.skeleton.b.center.scrollLeft-r.startScrollLeft:0,a=e-(r.containerLeft-s),l=r.midpoints.length;for(let d=0;d<r.midpoints.length;d++)if(a<r.midpoints[d]){l=d;break}r.targetIndex=l>r.fromIndex?l-1:l,r.indicator.style.transform=`translate3d(${r.offsets[l]}px, 0, 0)`}On(){let e=this.rt;return e?(this.rt=null,e.cellEl.classList.remove("mach-header-cell--dragging"),e.ghost.remove(),e.indicator.remove(),this.core.skeleton.root.classList.remove("mach-root--dragging"),e):null}jo(){window.removeEventListener("pointermove",this.we),window.removeEventListener("pointerup",this.X),window.removeEventListener("pointercancel",this.X),this.F&&cancelAnimationFrame(this.F),this.F=0,this.Rr=null}destroy(){this.jo(),this.On(),this.pending=null}};function qi(i){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(i):i.replace(/[^a-zA-Z0-9_-]/g,"\\$&")}function zr(i,e){let t=i==null?"":String(i);return t.includes(e)||t.includes('"')||t.includes(`
1
+ var Ie="0.32.1";var Ae=class{constructor(e){this.onListenerError=e;this.Ke=new Map}on(e,t){let r=this.Ke.get(e);return r||(r=new Set,this.Ke.set(e,r)),r.add(t),()=>{r.delete(t)}}once(e,t){let r=this.on(e,o=>{r(),t(o)});return r}off(e,t){let r=this.Ke.get(e);r&&(r.delete(t),r.size===0&&this.Ke.delete(e))}emit(e,t){let r=this.Ke.get(e);if(r)for(let o of[...r])try{o(t)}catch(n){console.error(`[mach-table] error in "${e}" listener`,n),this.onListenerError?.(n,e)}}clear(){this.Ke.clear()}};var oi=new Set(["__proto__","prototype","constructor"]);function he(i){return typeof i!="string"||i.length===0?!1:i.split(".").every(t=>t.length>0&&!oi.has(t))}function X(i,e){if(i==null||!he(e))return;if(e.indexOf(".")<0)return i[e];let r=i,o=0;for(;o<e.length;){if(r==null)return;let n=e.indexOf(".",o);if(n<0){r=r[e.slice(o)];break}r=r[e.slice(o,n)],o=n+1}return r}function pe(i,e,t){if(i==null||!he(e))return!1;let r=e.split("."),o=i;for(let n=0;n<r.length-1;n++){if(typeof o!="object"&&typeof o!="function"||o===null)return!1;o[r[n]]==null&&(o[r[n]]={}),o=o[r[n]]}return typeof o!="object"&&typeof o!="function"||o===null?!1:(o[r[r.length-1]]=t,!0)}var ii=new Set(["contains","notContains","equals","notEquals","startsWith","endsWith","blank","notBlank"]),ni=new Set(["equals","notEquals","lessThan","lessThanOrEqual","greaterThan","greaterThanOrEqual","inRange","blank","notBlank"]),si=new Set(["equals","notEquals","lessThan","greaterThan","inRange","blank","notBlank"]);function ai(i){return i==null||typeof i=="string"||typeof i=="number"&&Number.isFinite(i)}function li(i){return i==="text"?ii:i==="number"?ni:si}function di(i,e,t){if(i==null||typeof i!="object")return null;let r=i;return typeof r.match!="string"||!t.has(r.match)?null:{match:r.match,...ci(r,e)}}function ci(i,e){let t=e==="number"?Cr(i.value):typeof i.value=="string"?i.value:void 0,r=e==="number"?Cr(i.value2):typeof i.value2=="string"?i.value2:void 0;return{...t!==void 0?{value:t}:{},...r!==void 0?{value2:r}:{}}}function Cr(i){return typeof i=="number"&&Number.isFinite(i)?i:void 0}function ui(i,e){let t=[],r=li(e);for(let o of i.slice(0,20)){let n=di(o,e,r);n&&t.push(n)}return t}function It(i){if(i==null||typeof i!="object")return null;let e=i;return e.type==="set"?Array.isArray(e.values)?{type:"set",values:e.values.filter(ai).slice(0,2e3)}:null:e.type!=="text"&&e.type!=="number"&&e.type!=="date"||!Array.isArray(e.conditions)?null:{type:e.type,...e.operator==="or"||e.operator==="and"?{operator:e.operator}:{},conditions:ui(e.conditions,e.type)}}function hi(i,e){if(typeof i.colId!="string"||!i.colId.trim())return null;let t=i.colId.trim();if(e.validColumnIds?.has(t)===!1)return null;let r=It(i.filter);return r?{kind:"condition",colId:t,filter:r}:null}function pi(i,e,t){if(!Array.isArray(i.children))return null;let r=[];for(let o of i.children){let n=Tr(o,e+1,t);n&&r.push(n)}return r.length===0?null:{kind:"group",operator:i.operator==="or"?"or":"and",children:r,...i.not===!0?{not:!0}:{}}}function fi(i,e,t){return e<=16&&t.nodes<512&&i!=null&&typeof i=="object"}function Tr(i,e,t){if(!fi(i,e,t)||t.ancestors.has(i))return null;t.ancestors.add(i),t.nodes++;let r=i,o=r.kind==="condition"?hi(r,t):r.kind==="group"?pi(r,e,t):null;return t.ancestors.delete(i),o}function V(i,e){if(i==null||typeof i!="object")return null;let t=i;if(t.version!==1||t.root==null)return null;let r=Tr(t.root,0,{ancestors:new WeakSet,nodes:0,validColumnIds:e});return r?{version:1,root:r}:null}function mi(i,e){return{kind:"condition",colId:i,filter:e}}function J(i,e){if(i==null||typeof i!="object"||Array.isArray(i))return{};let t={};for(let[r,o]of Object.entries(i).slice(0,2e3)){let n=r.trim();if(!n||e?.has(n)===!1)continue;let s=It(o);s&&(t[n]=s)}return t}function gi(i,e,t={}){return{kind:"group",operator:i,children:e,...t.not?{not:!0}:{}}}var At={align:"center",sortable:!0,resizable:!0,movable:!0,filter:!1,minWidth:80},fe={compact:{rowHeight:30,headerHeight:34,fontSize:12,cellPadding:6},normal:{rowHeight:36,headerHeight:40,fontSize:13,cellPadding:9},large:{rowHeight:44,headerHeight:48,fontSize:14,cellPadding:12}};function M(i,e,t,r=!1){return typeof i!="number"||!Number.isFinite(i)||i<t?e:r?Math.floor(i):i}function yi(i){return i&&Object.prototype.hasOwnProperty.call(fe,i)?i:"normal"}function vi(i){return i.theme==="light"||i.theme==="dark"||i.theme==="auto"?i.theme:"light"}function wi(i,e){let t=typeof i.pagination=="object"&&Array.isArray(i.pagination.pageSizeOptions)?i.pagination.pageSizeOptions:void 0,r=t?[...new Set(t.map(o=>M(o,0,1,!0)).filter(Boolean))]:[10,20,50,100];return r.includes(e)||r.push(e),r.sort((o,n)=>o-n)}function Lt(i,e){let t=typeof i=="function"?i(e):X(e,i);return t==null?"":String(t)}function bi(i){let e=i.rowKey,t=e?({data:r})=>Lt(e,r):void 0;return{...t?{resolveRowId:t}:{},...e?{rowKey:e}:{}}}function Ci(i,e){let t=fe[e];return{columnDefs:Array.isArray(i.columnDefs)?i.columnDefs:[],rowData:Array.isArray(i.rowData)?i.rowData:[],defaultColDef:{...At,...i.defaultColDef??{}},columnTypes:i.columnTypes??{},...bi(i),rowHeight:M(i.rowHeight,t.rowHeight,1),headerHeight:M(i.headerHeight,t.headerHeight,1),rowBuffer:M(i.rowBuffer,8,0,!0),columnLayout:i.columnLayout==="fit"?"fit":"normal",enableColumnResize:i.enableColumnResize===!0,domLayout:i.domLayout==="autoHeight"?"autoHeight":"normal",rowSelection:i.rowSelection==="single"||i.rowSelection==="multiple"?i.rowSelection:"none",multiSort:i.multiSort??!0,size:e,pinnedTopRowData:Array.isArray(i.pinnedTopRowData)?i.pinnedTopRowData:[],pinnedBottomRowData:Array.isArray(i.pinnedBottomRowData)?i.pinnedBottomRowData:[]}}function Ti(i){return{stripedRows:i.stripedRows??!1,rowStyleRules:Array.isArray(i.rowStyleRules)?i.rowStyleRules:[],showCellBorders:i.showCellBorders??!1,theme:vi(i),quickFilterText:i.quickFilterText??null,suppressCellFocus:i.suppressCellFocus??!1,suppressRowHoverHighlight:i.suppressRowHoverHighlight??!1,suppressNoRowsOverlay:i.suppressNoRowsOverlay??!1,suppressHeaderFocus:i.suppressHeaderFocus??!1,loading:i.loading??!1,error:i.error??null,className:i.className??""}}function Di(i){return{editType:i.editType==="fullRow"?"fullRow":"cell",editableIndicator:i.editableIndicator==="always"||i.editableIndicator==="none"?i.editableIndicator:"hover",singleClickEdit:i.singleClickEdit??!1,manualSorting:i.manualSorting??!1,manualFiltering:i.manualFiltering??!1,showSummary:i.showSummary??!1,indexOffset:i.indexOffset??0,applyRowDrag:i.applyRowDrag??!0,rowDragPolicy:i.rowDragPolicy,undoStackSize:M(i.undoStackSize,100,0,!0),asyncTransactionWaitMillis:M(i.asyncTransactionWaitMillis,16,0,!0)}}function Ri(i){return{masterDetail:i.masterDetail??!1,detailRowHeight:M(i.detailRowHeight,240,1),detailToggleColumn:i.detailToggleColumn??!0,treeData:i.treeData??!1,childrenKey:i.childrenKey??"children",autoCheckedChildren:i.autoCheckedChildren??!0,defaultExpandAll:i.defaultExpandAll??!1}}function Ei(i){let e=typeof i.pagination=="object"?i.pagination:void 0,t=M(e?.pageSize,20,1,!0);return{paginationEnabled:i.pagination!==!1&&i.datasource==null,paginationMode:e?.mode==="server"?"server":"client",paginationPage:M(e?.page,1,1,!0),paginationTotal:M(e?.total,0,0,!0),paginationPageSize:t,paginationPageSizeOptions:wi(i,t),paginationShowTotal:e?e.showTotal!==!1:!0,paginationShowSizeSelector:e?e.showPageSizeSelector!==!1:!0}}function xi(i){return{watermarkEnabled:i.watermark!=null&&i.watermark!==!1,watermarkConfig:i.watermark==null||i.watermark===!1?null:i.watermark===!0?{text:"MachTable"}:i.watermark}}function Mi(i){return{columnMenu:i.columnMenu??!1,advancedFilterModel:V(i.advancedFilterModel),...Si(i),locale:i.locale??{},suppressWarnings:i.suppressWarnings??!1,enableRangeSelection:i.enableRangeSelection??!1,suppressClipboard:i.suppressClipboard??!1,contextMenu:i.contextMenu??!1,tooltipShowDelay:M(i.tooltipShowDelay,600,0),flashCells:i.flashCells??!0,fillHandle:i.fillHandle??!0,statusBarEnabled:i.statusBar===!0||typeof i.statusBar=="object"&&i.statusBar!=null,statusBarPanels:typeof i.statusBar=="object"&&i.statusBar?.panels?i.statusBar.panels:["rowCount","selectedRowCount","rangeAggregate"]}}function Si(i){let e=i.persistence;return!e||typeof e.key!="string"||!e.key.trim()?{persistence:null}:{persistence:{key:e.key.trim(),debounceMs:M(e.debounceMs,160,0,!0),...e.sections?{sections:[...new Set(e.sections)]}:{},...e.store?{store:e.store}:{}}}}function ki(i){return{datasourceMode:i.datasourceMode==="block"?"block":"sequential",blockSize:M(i.blockSize,100,1,!0),infiniteBufferRows:M(i.infiniteBufferRows,40,0,!0),maxBlocksInCache:M(i.maxBlocksInCache,12,1,!0),datasourceMaxConcurrentRequests:M(i.datasourceMaxConcurrentRequests,4,1,!0),blockPrefetch:M(i.blockPrefetch,1,0,!0),datasourceRowCount:i.datasourceRowCount==null?null:M(i.datasourceRowCount,0,0,!0),dataProcessorMinRows:M(i.dataProcessorMinRows,5e3,1,!0),datasourceRetryCount:M(i.datasourceRetryCount,2,0,!0),datasourceRetryDelay:M(i.datasourceRetryDelay,300,0,!0),datasourceRetryJitter:Math.min(1,M(i.datasourceRetryJitter,.15,0))}}function Ii(i){return{ariaLabel:i.ariaLabel??"MachTable data grid",ariaLabelledBy:i.ariaLabelledBy??"",ariaDescribedBy:i.ariaDescribedBy??"",overlayNoRowsTemplate:i.overlayNoRowsTemplate??"",overlayLoadingTemplate:i.overlayLoadingTemplate??"",overlayErrorTemplate:i.overlayErrorTemplate??"",allowUnsafeOverlayHtml:i.allowUnsafeOverlayHtml??!1}}var Ai=["detailRowRenderer","isRowExpandable","aggFuncs","components","actionPolicy","summaryMethod","datasource","getRowHeight","tooltipComponent","getContextMenuItems","initialState","rowEditValidator","isTreeRowExpandable","loadTreeChildren","dataProcessor"];function Li(i,e){for(let t of Ai)i[t]&&Object.assign(e,{[t]:i[t]})}function Pi(i,e){for(let t of Object.keys(i))t.startsWith("on")&&typeof i[t]=="function"&&Object.assign(e,{[t]:i[t]})}function Dr(i){let e=yi(i.size),t={...Ci(i,e),...Ti(i),...Di(i),...Ri(i),...Ei(i),...xi(i),...Mi(i),...ki(i),...Ii(i),features:Array.isArray(i.features)?i.features:[]};return Li(i,t),Pi(i,t),t}function Rr(i){return Array.isArray(i)?i.filter(e=>typeof e=="string"&&e.length>0):typeof i=="string"&&i.length>0?[i]:[]}function ne(i,e){return Rr(i.type).includes(e)}function Er(i,e,t={}){let r={};for(let o of Rr(i.type)){let n=t[o];n&&Object.assign(r,n)}return{...e,...r,...i}}var _=class{constructor(e,t){this.manualWidth=null;this.contentWidth=null;this.flex=null;this.currentWidth=0;this.parentGroup=null;this.level=0;this.isDetailToggle=!1;this.id=e,this.colDef=t,this.hide=t.hide??!1;let r=t.pinned;this.pinned=r===!0?"left":r===!1||r==null?null:r,this.resetWidth()}get sortable(){return this.colDef.sortable!==!1}get resizable(){return this.colDef.resizable!==!1}get movable(){return this.colDef.movable!==!1}get filterable(){return this.colDef.filter!=null&&this.colDef.filter!==!1}get filterType(){let e=this.colDef.filter;return e===!0?"text":e??"text"}get hasCheckbox(){return this.colDef.checkboxSelection===!0}resetWidth(){this.manualWidth=null,this.contentWidth=null,this.flex=typeof this.colDef.flex=="number"&&Number.isFinite(this.colDef.flex)&&this.colDef.flex>0?this.colDef.flex:null}};var Z=class i{constructor(e,t){this.parent=null;this.children=[];this.groupId=e,this.def=t}get headerName(){return this.def.headerName??this.def.groupId??""}getLeafColumns(e=[]){for(let t of this.children)t instanceof i?t.getLeafColumns(e):e.push(t);return e}};function me(i){return Array.isArray(i.children)}function Le(i,e){return typeof i=="number"&&Number.isFinite(i)&&i>0?i:e}function xr(i){let e=Le(i.minWidth,80);return{min:e,max:Math.max(e,Le(i.maxWidth,Number.MAX_SAFE_INTEGER))}}function O(i,e){let{min:t,max:r}=xr(e),o=Le(i,Le(e.width,150));return Math.max(t,Math.min(r,o))}function Mr(i,e){let t=i.map(s=>O(s.width??150,s)),r=[],o=0;i.forEach((s,a)=>{let l=s.flex??0;l>0&&(r.push(a),o+=l)});let n=0;for(let s of t)n+=s;if(o>0&&e>n){let s=e-n;for(let a=0;a<4&&s>.5&&r.length>0;a++){let l=[],d=0;for(let p of r){let m=i[p].flex??0;l.push(p),d+=m}let c=[];for(let p=0;p<l.length;p++){let m=l[p],g=i[m].flex??0,v=s*g/d,y=t[m];t[m]=O(y+v,i[m]),c.push(t[m]-y)}let u=0;for(let p of c)u+=p;s-=u;let h=l.filter((p,m)=>c[m]>.001);if(h.length===l.length)break;r.length=0;for(let p of h)r.push(p)}}return t}function Gi(i,e,t){let r=new Set(i.map((n,s)=>s)),o=t;for(let n=0;n<i.length+1&&r.size>0;n++){let s=0;for(let l of r)s+=Math.max(1,e[l]);if(s<=0)break;let a=!1;for(let l of[...r]){let d=o*(Math.max(1,e[l])/s),c=O(d,i[l]),{min:u,max:h}=xr(i[l]);(d<u||d>h)&&(e[l]=c,o-=c,r.delete(l),a=!0)}if(!a){for(let l of r)e[l]=O(o*(Math.max(1,e[l])/s),i[l]);break}o=Math.max(0,o)}}function Ni(i,e,t){let r=t-e.reduce((o,n)=>o+n,0);if(!(Math.abs(r)<=.01))for(let o=e.length-1;o>=0;o--){let n=O(e[o]+r,i[o]);if(Math.abs(n-e[o])>.01){e[o]=n;return}}}function Pe(i,e){let t=i.map(r=>O(r.width??150,r));return!Number.isFinite(e)||e<=0||i.length===0||(Gi(i,t,e),Ni(i,t,e)),t}var Pt="__rg_detail_toggle__";function se(i){return typeof i=="number"&&Number.isFinite(i)&&i>0}var Ge=class{constructor(e){this.core=e;this.columns=[];this.rn=new Map;this.q=[];this.left=[];this.center=[];this.right=[];this.sortModel=[];this.defs=[];this.qe=1;this.vo=new Map;this.fa=0}wt(e){this.defs=e?[...e]:[];let t=new Map(this.columns.map(s=>[s.id,s])),r=this.core.options.defaultColDef,o=new Set(this.core.options.masterDetail&&this.core.options.detailToggleColumn?[Pt]:[]),n=(s,a,l)=>s.map((d,c)=>{if(me(d)){let y=d.groupId??d.headerName??`group_${c}_${l}`,b=new Z(y,d);return b.parent=a,b.children=n(d.children,b,l+1),b}let u=d,h=u.colId??u.field??`col_${c}`,p=h,m=2;for(;o.has(p);)p=`${h}_${m++}`;o.add(p);let g=new _(p,Er(u,r,this.core.options.columnTypes));g.parentGroup=a,g.level=l;let v=t.get(p);return v&&(g.manualWidth=v.manualWidth,g.contentWidth=v.contentWidth,g.flex=v.flex,g.hide=v.hide,g.pinned=v.pinned),g});if(this.q=n(this.defs,null,0),this.core.options.masterDetail&&this.core.options.detailToggleColumn){let s=new _(Pt,{colId:Pt,headerName:"",width:38,pinned:"left",sortable:!1,resizable:!1,movable:!1,filter:!1});s.isDetailToggle=!0,this.q.unshift(s)}if(this.columns=this.ir(this.q),this.rn=new Map(this.columns.map(s=>[s.id,s])),this.qe=this.columns.reduce((s,a)=>Math.max(s,a.level+1),1),this.sortModel=this.sortModel.filter(s=>this.columns.some(a=>a.id===s.colId)),this.sortModel.length===0){let s=[];for(let a of this.columns)a.colDef.initialSort&&s.push({colId:a.id,direction:a.colDef.initialSort});this.sortModel=s}this.Ue()}ir(e,t=[]){for(let r of e)r instanceof Z?this.ir(r.children,t):t.push(r);return t}Ue(){let e=this.columns.filter(t=>!t.hide);this.left=e.filter(t=>t.pinned==="left"),this.right=e.filter(t=>t.pinned==="right"),this.center=e.filter(t=>t.pinned===null),this.vo.clear(),this.e().forEach((t,r)=>this.vo.set(t.id,r))}te(e){return this.vo.get(e)??-1}G(){return this.columns}nr(){return this.defs}ma(){return this.q}ga(){return this.qe}m(e){return this.rn.get(e)}d(e){return e==="left"?this.left:e==="right"?this.right:this.center}e(){return[...this.left,...this.center,...this.right]}re(){return this.e().filter(e=>e.colDef.rowGroup===!0)}ya(){return this.e().filter(e=>e.colDef.aggFunc!=null&&e.colDef.rowGroup!==!0)}wo(){return this.center.some(e=>e.colDef.colSpan!=null)}nn(){let e=this.e();return this.center.find(t=>!t.hasCheckbox&&!t.isDetailToggle)??e.find(t=>!t.hasCheckbox&&!t.isDetailToggle)??e[0]}bt(e){return e.pinned==="left"?"left":e.pinned==="right"?"right":"center"}sn(e){this.fa=e;let t=0;for(let c of[...this.left,...this.right])c.currentWidth=O(c.manualWidth??c.contentWidth??c.colDef.width??150,this.Se(c)),t+=c.currentWidth;let r=Math.max(0,e-t),o=[],n=[];for(let c of this.center)(c.colDef.suppressSizeToFit||c.manualWidth!=null?n:o).push(c);let s=0;for(let c of n)c.currentWidth=O(c.manualWidth??c.contentWidth??c.colDef.width??150,this.Se(c)),s+=c.currentWidth;let a=o.map(c=>this.Se(c)),l=Math.max(0,r-s),d=this.core.options.columnLayout==="fit"?Pe(a,l):Mr(a,l);o.forEach((c,u)=>{c.currentWidth=d[u]})}Se(e){let t=e.colDef;return{width:e.manualWidth??e.contentWidth??t.width,minWidth:t.minWidth,maxWidth:t.maxWidth,flex:e.manualWidth==null?e.flex??void 0:void 0}}oe(e,t){return se(t)?(e.manualWidth=O(t,this.Se(e)),e.flex=null,!0):!1}an(e,t){return se(t)?(e.resetWidth(),e.contentWidth=O(t,this.Se(e)),!0):!1}bo(e,t){let r=this.m(e);!r||r.hide===!t||(r.hide=!t,this.Ue())}moveColumn(e,t){let r=this.m(e);if(!r)return!1;let o=this.bt(r),n=u=>r.parentGroup?!0:this.bt(u)===o,s=r.parentGroup?r.parentGroup.children:this.q,a=s.filter(u=>u instanceof _&&!u.hide&&n(u)),l=a.indexOf(r);if(l<0)return!1;a.splice(l,1);let d=Math.max(0,Math.min(t,a.length));a.splice(d,0,r);let c=[];return s.forEach((u,h)=>{u instanceof _&&!u.hide&&n(u)&&c.push(h)}),c.length!==a.length?!1:(c.forEach((u,h)=>{s[u]=a[h]}),this.columns=this.ir(this.q),this.Ue(),!0)}Co(e,t){let r=this.m(e);!r||!r.movable||(r.pinned=t,this.Ue())}sr(){return this.columns.map(e=>({colId:e.id,hide:e.hide,width:e.manualWidth??e.currentWidth,flex:e.flex,widthMode:e.manualWidth==null?"auto":"manual",contentWidth:e.contentWidth??void 0,pinned:e.pinned}))}ln(e){let t=new Map(e.map(r=>[r.colId,r]));for(let r of this.columns){let o=t.get(r.id);o&&this.va(r,o)}this.wa(e),this.Ue()}va(e,t){typeof t.hide=="boolean"&&(e.hide=t.hide),t.widthMode==="auto"?(e.resetWidth(),se(t.flex)&&(e.flex=t.flex)):se(t.flex)?(e.flex=t.flex,e.manualWidth=null):se(t.width)&&(e.manualWidth=O(t.width,this.Se(e)),e.flex=null),se(t.contentWidth)&&(e.contentWidth=O(t.contentWidth,this.Se(e))),e.movable&&(t.pinned==="left"||t.pinned==="right"||t.pinned===null)&&(e.pinned=t.pinned)}wa(e){let t=new Map;e.forEach((o,n)=>t.set(o.colId,n));let r=o=>o.pinned==="left"?"left":o.pinned==="right"?"right":"center";for(let o of["left","center","right"]){let n=this.q.filter(d=>d instanceof _&&!d.hide&&d.parentGroup===null&&r(d)===o);if(n.length<2)continue;let s=n.filter(d=>d.movable),a=s.slice().sort((d,c)=>(t.get(d.id)??Number.MAX_SAFE_INTEGER)-(t.get(c.id)??Number.MAX_SAFE_INTEGER));if(a.every((d,c)=>d===s[c]))continue;let l=[];this.q.forEach((d,c)=>{d instanceof _&&!d.hide&&d.parentGroup===null&&r(d)===o&&d.movable&&l.push(c)}),l.forEach((d,c)=>{this.q[d]=a[c]})}this.columns=this.ir(this.q)}To(){for(let e of this.columns){e.resetWidth(),e.hide=e.colDef.hide??!1;let t=e.colDef.pinned;e.pinned=t===!0?"left":t===!1||t==null?null:t}this.Ue()}D(){return this.sortModel.map(e=>({...e}))}Ct(e){if(!e||e.length===0){this.sortModel=[];return}this.sortModel=e.filter(t=>this.columns.some(r=>r.id===t.colId)&&(t.direction==="asc"||t.direction==="desc")).map(t=>({colId:t.colId,direction:t.direction}))}cycleSort(e,t){let r=[...this.sortModel],o=r.findIndex(l=>l.colId===e.id),n=o>=0?r[o].direction:null,s=n===null?"asc":n==="asc"?"desc":null;t&&this.core.options.multiSort?s===null?o>=0&&r.splice(o,1):o>=0?r[o]={colId:e.id,direction:s}:r.push({colId:e.id,direction:s}):(r.length=0,s&&r.push({colId:e.id,direction:s})),this.sortModel=r}};function kr(i){return i==null?"":String(i).toLowerCase()}function Fi(i,e,t){let r=kr(i),o=n=>{let s=(n.value??"").toLowerCase();switch(n.match){case"contains":return r.includes(s);case"notContains":return!r.includes(s);case"equals":return r===s;case"notEquals":return r!==s;case"startsWith":return r.startsWith(s);case"endsWith":return r.endsWith(s);case"blank":return r==="";case"notBlank":return r!=="";default:return!0}};return e.length===0||(t==="or"?e.some(o):e.every(o))}function Oi(i,e,t){switch(t.match){case"equals":return i===e;case"notEquals":return i!==e;case"lessThan":return i<e;case"lessThanOrEqual":return i<=e;case"greaterThan":return i>e;case"greaterThanOrEqual":return i>=e;case"inRange":return i>=e&&i<=(t.value2??e);default:return!0}}function Hi(i,e){let t=i==null||i==="";if(e.match==="blank")return t;if(e.match==="notBlank")return!t;if(t)return!1;let r=typeof i=="number"?i:Number(i);if(Number.isNaN(r))return!1;let o=e.value;return o==null||Number.isNaN(o)?!1:Oi(r,o,e)}function Vi(i,e,t){let r=o=>Hi(i,o);return e.length===0||(t==="or"?e.some(r):e.every(r))}function Gt(i){if(i==null||i==="")return null;if(i instanceof Date)return isNaN(i.getTime())?null:i.getTime();if(typeof i=="number")return i;let e=Date.parse(String(i));return isNaN(e)?null:e}function Bi(i,e,t){let r=Gt(i),o=n=>{let s=r==null;if(n.match==="blank")return s;if(n.match==="notBlank")return!s;if(s)return!1;let a=r,l=n.value!=null?Gt(n.value):null;if(l==null)return!1;switch(n.match){case"equals":return a===l;case"notEquals":return a!==l;case"lessThan":return a<l;case"greaterThan":return a>l;case"inRange":{let d=n.value2!=null?Gt(n.value2):null;return d!=null?a>=l&&a<=d:a>=l}default:return!0}};return e.length===0||(t==="or"?e.some(o):e.every(o))}function zi(i,e){return e.length===0?!0:e.some(t=>t==null&&i==null||t===i)}function Ir(i,e){let t=e.type!=="set"&&e.operator==="or"?"or":"and";switch(e.type){case"text":return Fi(i,e.conditions,t);case"number":return Vi(i,e.conditions,t);case"date":return Bi(i,e.conditions,t);case"set":return zi(i,e.values);default:return!0}}function Ar(i,e,t){if(i.kind==="condition"){let o=e.get(i.colId);return o?n=>Ir(t(n,o),i.filter):()=>!0}let r=i.children.map(o=>Ar(o,e,t));return o=>{let n=i.operator==="or"?r.some(s=>s(o)):r.every(s=>s(o));return i.not?!n:n}}function Nt(i,e,t,r,o){let n=new Map(i.map(d=>[d.id,d])),s=Object.entries(e).flatMap(([d,c])=>{let u=n.get(d);return u?[{column:u,filter:c}]:[]}),a=t?Ar(t.root,n,o):()=>!0,l=r?.trim().toLowerCase().split(/\s+/).filter(Boolean)??[];return d=>!s.every(({column:c,filter:u})=>Ir(o(d,c),u))||!a(d)?!1:l.every(c=>i.some(u=>kr(o(d,u)).includes(c)))}var Lr=typeof Intl<"u"?new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"}):null;function _i(i,e){let t=i==null||i==="",r=e==null||e==="";return!t&&!r?null:t&&r?0:t?1:-1}function Wi(i,e){let t=Number.isNaN(i),r=Number.isNaN(e);return t||r?t===r?0:t?1:-1:i-e}function $i(i,e){return i===e?0:i?1:-1}function Ne(i,e){let t=_i(i,e);if(t!==null)return t;if(typeof i=="number"&&typeof e=="number")return Wi(i,e);if(i instanceof Date&&e instanceof Date)return i.getTime()-e.getTime();if(typeof i=="boolean"&&typeof e=="boolean")return $i(i,e);let r=String(i),o=String(e);return Lr?Lr.compare(r,o):r.localeCompare(o)}function Ft(i,e,t,r){let o=new Map(t.map(a=>[a.id,a])),n=e.flatMap(a=>{let l=o.get(a.colId);return l?[{column:l,compare:l.colDef.comparator??Ne,direction:a.direction}]:[]}),s=i.map(a=>({node:a,values:n.map(({column:l})=>r(a,l))}));return s.sort((a,l)=>{for(let d=0;d<n.length;d++){let c=n[d],u=c.compare(a.values[d],l.values[d],a.node,l.node);if(u!==0)return c.direction==="asc"?u:-u}return 0}),s.map(({node:a})=>a)}function Fe(i){return i.filter(e=>typeof e=="number"&&!isNaN(e))}var Pr={sum:i=>Fe(i).reduce((e,t)=>e+t,0),avg:i=>{let e=Fe(i);return e.length===0?null:e.reduce((t,r)=>t+r,0)/e.length},count:i=>i.length,min:i=>{let e=Fe(i);return e.length===0?null:Math.min(...e)},max:i=>{let e=Fe(i);return e.length===0?null:Math.max(...e)},first:i=>i.length>0?i[0]:null,last:i=>i.length>0?i[i.length-1]:null};function Ot(i){let e={...Pr,...i??{}};return t=>e[t]}function Q(i){if(i.reason instanceof Error)return i.reason;let e=new Error(typeof i.reason=="string"?i.reason:"Block request aborted");return e.name="AbortError",e}function Oe(i){return Number.isFinite(i)?Math.max(1,Math.trunc(i)):1}var He=class{constructor(e,t,r=4){this.maxBlocks=e;this.onEvict=t;this.maxConcurrentRequests=r;this.S=new Map;this.x=new Map;this.dn=0;this.generation=0;this.hitCount=0;this.missCount=0;this.evictionCount=0;this.ar=0;this.lr=new Set;this.maxBlocks=Oe(e),this.maxConcurrentRequests=Oe(r)}configure(e,t=this.maxConcurrentRequests){this.maxBlocks=Oe(e),this.maxConcurrentRequests=Oe(t),this.Do(),this.dr()}retain(e){this.lr=e,this.Do()}peek(e){let t=this.S.get(e);if(t)return t.touchedAt=++this.dn,t}has(e){return this.S.has(e)}invalidate(e){let t=this.x.get(e);t&&(this.x.delete(e),t.controller.abort(),t.state==="queued"&&t.reject(Q(t.controller.signal)));let r=this.S.get(e);r&&(this.S.delete(e),this.onEvict?.(e,r))}load(e,t,r,o=0){if(r?.aborted)return Promise.reject(Q(r));let n=this.peek(e);if(n)return this.hitCount++,Promise.resolve(n);let s=this.x.get(e);if(s)return this.hitCount++,s.priority=Math.max(s.priority,o),this.dr(),this.cn(e,s,r);this.missCount++;let a=new AbortController,l,d,c=new Promise((p,m)=>{l=p,d=m}),u={controller:a,promise:c,consumers:0,loader:t,priority:o,state:"queued",resolve:l,reject:d};this.x.set(e,u);let h=this.cn(e,u,r);return this.dr(),h}purge(){this.generation++,this.lr.clear();for(let e of this.x.values())e.controller.abort(),e.state==="queued"&&e.reject(Q(e.controller.signal));this.x.clear();for(let[e,t]of this.S)this.onEvict?.(e,t);this.S.clear()}snapshot(){let e=0,t=0;for(let r of this.S.values())e+=r.rows.length;for(let r of this.x.values())r.state==="active"&&t++;return{cachedBlockCount:this.S.size,loadingBlockCount:this.x.size,activeRequestCount:t,queuedRequestCount:Math.max(0,this.x.size-t),cachedRowCount:e,hitCount:this.hitCount,missCount:this.missCount,evictionCount:this.evictionCount}}dr(){for(;this.ar<this.maxConcurrentRequests;){let e,t;for(let[r,o]of this.x)o.state!=="queued"||o.controller.signal.aborted||(!t||o.priority>t.priority)&&(e=r,t=o);if(e==null||!t)return;this.ba(e,t)}}ba(e,t){t.state="active",this.ar++;let r=this.generation;this.Ca(t).then(o=>{r===this.generation&&!t.controller.signal.aborted&&(this.S.set(e,{rows:o.rows,...o.lastRow==null?{}:{lastRow:o.lastRow},touchedAt:++this.dn}),this.Do()),t.resolve(o)},t.reject).finally(()=>{this.ar=Math.max(0,this.ar-1),this.x.get(e)===t&&this.x.delete(e),this.dr()})}Ca(e){let{signal:t}=e.controller;return t.aborted?Promise.reject(Q(t)):new Promise((r,o)=>{let n=()=>o(Q(t));t.addEventListener("abort",n,{once:!0}),Promise.resolve().then(()=>e.loader(t)).then(r,o).finally(()=>{t.removeEventListener("abort",n)})})}cn(e,t,r){return t.consumers++,new Promise((o,n)=>{let s=!1,a=d=>{s||(s=!0,r?.removeEventListener("abort",l),t.consumers=Math.max(0,t.consumers-1),d())},l=()=>a(()=>{t.consumers===0&&this.x.get(e)===t&&(this.x.delete(e),t.controller.abort(r?.reason),t.state==="queued"&&t.reject(Q(t.controller.signal))),n(Q(r))});r?.addEventListener("abort",l,{once:!0}),t.promise.then(d=>a(()=>o(d)),d=>a(()=>n(d instanceof Error?d:new Error(String(d??"Block request failed")))))})}Do(){let e=Math.max(this.maxBlocks,this.lr.size+1);for(;this.S.size>e;){let t=-1,r=Number.POSITIVE_INFINITY;for(let[n,s]of this.S)this.lr.has(n)||s.touchedAt<r&&(t=n,r=s.touchedAt);if(t<0)return;let o=this.S.get(t);this.S.delete(t),this.evictionCount++,o&&this.onEvict?.(t,o)}}};function ge(i,e){if(i==null||typeof i!="object")return;let t=i[e];return Array.isArray(t)?t:void 0}var Ve=class{constructor(e){this.core=e;this.all=[];this.M=[];this.k=new Map;this.displayed=[];this.r=new Map;this.filterModel={};this.advancedFilterModel=null;this.quickFilter=null;this.g=new Set;this.I=new Set;this.je=[];this.Tt=new Map;this.un=[];this.y=null;this.Ye=!1;this.hn=!1;this.U=0;this.cr=null;this.Dt=null;this.ur=null;this.hr=new WeakMap;this.Rt=new WeakMap;this.he=new Map;this.Et=new Map;this.xt=0;this.pr=0;this.pe=new Map;this.ke=new Map;this.fr=new Set;this.Ie=new Map;this.fe=new He(12,e=>this.pn(e));this.Mt=0;this.mr=null;this.Ro=!1;this.fn=0;this.N=[];this.page=1;this.pageSize=20;this.advancedFilterModel=V(e.options.advancedFilterModel)}resolveRowId(e,t,r){let o=this.core.options.resolveRowId;if(!o)return r;try{let n=o({data:e,index:t,api:this.core.getApi()});if(typeof n=="string"&&n.length>0)return n;this.core.reportError(new Error("rowKey must resolve to a non-empty identifier"),"rowKey",{index:t})}catch(n){this.core.reportError(n,"rowKey",{index:t})}return r}get w(){return this.core.options.treeData}get o(){return this.core.options.datasource!=null}get B(){return this.o&&this.core.options.datasourceMode==="block"}Xe(){if(this.o){if(this.B)return this.Je();let e=Math.max(0,this.displayed.length-this.all.length);return(this.y??this.all.length)+e}return this.displayed.length}Eo(){return this.xt}gr(){return this.pr}Ta(){return this.hn}xo(e){return!this.o||e?.aborted?Promise.resolve():(this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.core.changeTracker.clear(),this.yr(),this.y=null,this.Ye=!1,this.all=[],this.M=[],this.r.clear(),this.g.clear(),this.core.undoService.clear(),this.a(),this.core.requestUpdate({data:!0}),this.B?(this.fe.configure(this.core.options.maxBlocksInCache,this.core.options.datasourceMaxConcurrentRequests),this.vr(0,e)):this.mn(0,void 0,e))}gn(e){return this.o?this.xo(e):Promise.resolve()}Ae(e){this.hn=e,this.core.skeleton.Ae(e,this.core.getLocaleText("loading"))}mn(e,t,r){if(!this.o||this.Ye||this.y!=null&&e>=this.y)return Promise.resolve();let o=this.core.options.datasource,n=this.core.options.blockSize,s=t??e+n;if(s<=e)return Promise.resolve();let a=++this.U,l=new AbortController,d=()=>l.abort(r?.reason);return r?.addEventListener("abort",d,{once:!0}),this.cr=l,this.Ye=!0,this.Ae(!0),new Promise(c=>{let u=!1,h=0;this.ur=c;let p=g=>{u||(u=!0,r?.removeEventListener("abort",d),a===this.U&&(this.Ye=!1,this.cr=null,this.ur=null,this.Ae(!1),g!=null&&g?.name!=="AbortError"&&this.core.reportError(g,"datasource.getRows",{startRow:e,endRow:s})),c())},m=()=>{if(u||a!==this.U||l.signal.aborted||this.core.isDestroyed()){p();return}h++;let g=!1,v=y=>{if(!(g||u)){if(g=!0,a!==this.U||l.signal.aborted||this.core.isDestroyed()){p();return}if(h<=this.core.options.datasourceRetryCount){let b=this.retryDelay(h);this.Dt=setTimeout(()=>{this.Dt=null,m()},b);return}p(y??new Error("Datasource request failed"))}};try{let y=o.getRows({startRow:e,endRow:s,sortModel:this.core.columnModel.D(),filterModel:this.R(),advancedFilterModel:this.z(),quickFilterText:this.quickFilter,signal:l.signal,onSuccess:(b,C)=>{if(g||u)return;if(g=!0,a!==this.U||this.core.isDestroyed()||l.signal.aborted){p();return}let x=b??[];typeof C=="number"&&C>=0?this.y=C:x.length<s-e&&(this.y=e+x.length);let w=this.all.length===0;this.Da(x),p(),this.a(),this.core.requestUpdate({data:!0}),w&&this.core.relayout(),this.core.headerRenderer.wr()},fail:v});y&&typeof y.catch=="function"&&y.catch(v)}catch(y){v(y)}};m()})}yr(){this.U++,this.Dt!=null&&clearTimeout(this.Dt),this.Dt=null,this.cr?.abort(),this.cr=null,this.Ye=!1,this.Ae(!1),this.ur?.(),this.ur=null,this.fe.purge(),this.pe.clear(),this.ke.clear(),this.fr.clear();for(let[e,t]of this.Ie)this.r.get(e)===t&&this.r.delete(e);this.Ie.clear()}Da(e){for(let t of e){if(t==null)continue;let r=this.all.length,o=this.resolveRowId(t,r,`inf-${this.core.nextId()}`);if(this.r.has(o)){this.core.reportError(new Error(`Duplicate row id: ${o}`),"datasource.getRows",{rowId:o});continue}let n={id:o,data:t,rowIndex:-1,selected:this.core.selectionService.isSelected(o)};this.all.push(n),this.r.set(o,n),this.M.push(n)}}vr(e,t,r=0){if(!this.B||e<0)return Promise.resolve();if(t?.aborted)return Promise.reject(this.yn(t.reason));let o=this.core.options.blockSize,n=this.U,s=e*o;if(s>=this.Je())return Promise.resolve();let a=this.y==null?s+o:Math.min(this.y,s+o),l=this.fe.load(e,d=>this.Ra(s,a,d),t,r);return this.Ae(this.all.length===0&&this.fe.snapshot().loadingBlockCount>0),l.then(d=>{n!==this.U||t?.aborted||this.core.isDestroyed()||!this.B||!this.fe.has(e)||this.fr.has(e)||(this.Ea(e,d),this.a(),this.core.requestUpdate({data:!0}),this.core.headerRenderer.wr(),n===this.U&&!this.core.isDestroyed()&&this.vn(this.core.bodyRenderer.Mo().lastExcl-1))}).catch(d=>{throw d?.name!=="AbortError"&&this.core.reportError(d,"datasource.getRows",{startRow:s,endRow:a}),d}).finally(()=>{n===this.U&&this.Ae(this.all.length===0&&this.fe.snapshot().loadingBlockCount>0)})}Ra(e,t,r){let o=this.core.options.datasource;return new Promise((n,s)=>{let a=0,l=null,d=!1,c=p=>{d||(d=!0,l!=null&&clearTimeout(l),r.removeEventListener("abort",u),s(p instanceof Error?p:new Error(typeof p=="string"?p:"Datasource request failed")))},u=()=>c(this.yn(r.reason));r.addEventListener("abort",u,{once:!0});let h=()=>{if(d)return;if(r.aborted||this.core.isDestroyed()){u();return}a++;let p=!1,m=g=>{if(!(p||d)){if(p=!0,r.aborted||this.core.isDestroyed()){u();return}if(a<=this.core.options.datasourceRetryCount){let v=this.retryDelay(a);l=setTimeout(()=>{l=null,h()},v)}else c(g)}};try{let g=o.getRows({startRow:e,endRow:t,sortModel:this.core.columnModel.D(),filterModel:this.R(),advancedFilterModel:this.z(),quickFilterText:this.quickFilter,signal:r,onSuccess:(v,y)=>{p||d||(p=!0,d=!0,r.removeEventListener("abort",u),n({rows:v??[],...typeof y=="number"&&y>=0?{lastRow:y}:{}}))},fail:m});g&&typeof g.catch=="function"&&g.catch(m)}catch(g){m(g)}};h()})}Ea(e,t){let r=this.core.options.blockSize,o=e*r;this.pn(e),typeof t.lastRow=="number"&&t.lastRow>=0?this.y=t.lastRow:t.rows.length<r&&(this.y=o+t.rows.length),t.rows.forEach((n,s)=>{if(n==null)return;let a=o+s;if(this.y!=null&&a>=this.y)return;let l=this.resolveRowId(n,a,`block-${a}`),d=this.Ie.get(l),c=this.r.get(l);if(c&&c!==d&&c.rowIndex!==a){this.core.reportError(new Error(`Duplicate row id: ${l}`),"datasource.getRows",{rowId:l});return}let u=d??{id:l,data:n,rowIndex:a,selected:this.core.selectionService.isSelected(l)};u.rowIndex=a,u.selected=this.core.selectionService.isSelected(l),this.Ie.delete(l),this.pe.set(a,u),this.ke.delete(a),this.r.set(l,u),this.Rt.set(u,a+1)}),this.wn(),this.fr.add(e)}pn(e){this.fr.delete(e);let t=this.core.options.blockSize,r=e*t,o;for(let n=r;n<r+t;n++){let s=this.pe.get(n);s&&(o??(o=new Set(this.core.changeTracker.getDirtyRowIds())),this.pe.delete(n),o.has(s.id)?this.Ie.set(s.id,s):this.r.get(s.id)===s&&this.r.delete(s.id))}this.wn()}wn(){this.all=[...this.pe.entries()].sort(([e],[t])=>e-t).map(([,e])=>e),this.M=this.all}Je(){if(this.y!=null)return this.y;if(this.core.options.datasourceRowCount!=null)return this.core.options.datasourceRowCount;if(this.pe.size===0)return this.core.options.blockSize;let e=0;for(let t of this.pe.keys())e=Math.max(e,t+1);return e+this.core.options.blockSize}xa(e){let t=this.ke.get(e);if(!t&&(t={id:`__mach_loading_${e}`,data:null,rowIndex:e,selected:!1,loading:!0},this.ke.set(e,t),this.ke.size>2e3)){let r=this.ke.keys().next().value;r!=null&&this.ke.delete(r)}return t}yn(e){if(e instanceof Error)return e;let t=new Error(typeof e=="string"?e:"Operation aborted");return t.name="AbortError",t}retryDelay(e){let t=Math.min(this.core.options.datasourceRetryDelay*2**Math.max(0,e-1),3e4),r=this.core.options.datasourceRetryJitter;return Math.max(0,Math.round(t*(1+(Math.random()*2-1)*r)))}Ma(e){if(this.B){this.vn(e);return}if(!this.o||this.Ye)return;let t=this.all.length;if(this.y!=null&&t>=this.y)return;let r=this.core.options.infiniteBufferRows;if(e+r<t&&e<t)return;let o=this.core.options.blockSize,n=this.y==null?t+o:Math.min(this.y,t+o);this.mn(t,n)}vn(e){if(e<0)return;this.bn();let t=this.core.options.blockSize,r=Math.floor(e/t),o=Math.floor(this.core.bodyRenderer.Mo().first/t),n=this.core.options.blockPrefetch,s=r<this.fn?-1:1;this.fn=r;for(let a=o;a<r;a++)this.vr(a,void 0,n+2).catch(()=>{});for(let a=0;a<=n;a++){let l=a===0?[r]:[r+s*a,r-s*a];for(let d of l)d<0||d*t>=this.Je()||this.vr(d,void 0,n-a+1).catch(()=>{})}}ie(){return this.gn().catch(()=>{})}Sa(){return this.yr(),this.o?this.xo().catch(()=>{}):(this.y=null,this.me(this.core.options.rowData),this.core.requestUpdate({data:!0}),Promise.resolve())}destroy(){this.yr(),this.Cn(),this.So(),this.all=this.M=this.displayed=this.N=[],this.r.clear(),this.k.clear(),this.Tt.clear(),this.un=[],this.g.clear(),this.I.clear(),this.je=[],this.core.options.dataProcessor?.destroy?.()}ko(e,t,r){if(!this.B)return Promise.resolve();this.bn();let o=this.core.options.blockSize,n=Math.max(0,Math.trunc(e)),s=Math.min(this.Je(),Math.max(n,Math.trunc(t))),a=Math.floor(n/o),l=Math.max(a,Math.floor(Math.max(n,s-1)/o)),d=[];for(let c=a;c<=l;c++)d.push(this.vr(c,r,100));return Promise.all(d).then(()=>{})}Io(){this.B&&(this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.core.changeTracker.clear(),this.yr(),this.core.undoService.clear(),this.all=[],this.M=[],this.r.clear(),this.a(),this.core.requestUpdate({data:!0}))}Ao(){return this.fe.snapshot()}bn(){let e=new Set(this.core.changeTracker.getDirtyRowIds());for(let[l,d]of this.Ie)e.has(l)||(this.Ie.delete(l),this.r.get(l)===d&&this.r.delete(l));let t=this.core.options.blockSize,r=new Set,{first:o,lastExcl:n}=this.core.bodyRenderer.Mo();for(let l=o;l<n;l+=t)r.add(Math.floor(l/t));n>o&&r.add(Math.floor((n-1)/t));let s=this.core.bodyRenderer.c;s&&r.add(Math.floor(s.rowIndex/t));let a=this.core.editingService.ka();a!=null&&r.add(Math.floor(a/t)),this.fe.retain(r)}me(e){this.pr++,this.core.cancelPendingInput(),this.core.getApi().editing.stop({cancel:!0}),this.Cn(),this.core.changeTracker.clear();let t=this.core.options.resolveRowId,r=this.core.options.childrenKey,o=[],n=[],s=new Map,a=new Map,l=0,d=(c,u,h)=>{let p=l++,m=this.resolveRowId(c,p,`auto-${p}`);if(s.has(m))return this.core.reportError(new Error(`Duplicate row id: ${m}`),"rowData",{rowId:m,index:p}),null;let g=this.w?ge(c,r):void 0,v={id:m,data:c,rowIndex:-1,selected:!1,treeChildrenLoaded:Array.isArray(g)};if(this.hr.set(v,u),o.push(v),s.set(m,v),h!=null){let y=a.get(h)??[];y.push(m),a.set(h,y)}else n.push(v);if(this.w&&Array.isArray(g))for(let y of g)y!=null&&d(y,u+1,m);return v};(e??[]).forEach(c=>{c!=null&&d(c,0,null)}),this.all=o,this.M=n,this.k=a,this.r=s,this.core.undoService.clear();for(let c of[...this.g])s.has(c)||this.g.delete(c);if(this.core.options.defaultExpandAll)for(let c of o)this.Tn(c.id)>0&&this.g.add(c.id);this.core.selectionService.onRowsRebuilt(t!=null),this.a()}St(e){return this.k.get(e)??[]}Tn(e){return this.k.get(e)?.length??0}Lo(e){return this.Tn(e)>0}isTreeRowLoading(e){return this.r.get(e)?.treeLoading===!0}Cn(){for(let e of this.he.values())e.abort();this.he.clear(),this.Et.clear()}loadTreeChildren(e,t=!1){let r=this.r.get(e),o=this.core.options.loadTreeChildren;if(!this.w||!r?.data||!o)return Promise.resolve([]);if(!t&&r.treeChildrenLoaded)return Promise.resolve(this.St(e).flatMap(l=>{let d=this.r.get(l)?.data;return d==null?[]:[d]}));let n=this.Et.get(e);if(n&&!t)return n;this.he.get(e)?.abort();let s=new AbortController;this.he.set(e,s),r.treeLoading=!0,r.treeLoadError=void 0,this.core.requestUpdate({data:!0});let a=Promise.resolve().then(()=>o({data:r.data,node:r,api:this.core.getApi(),signal:s.signal})).then(l=>{if(s.signal.aborted||this.core.isDestroyed())return[];if(!Array.isArray(l))throw new TypeError("[MachTable] loadTreeChildren must resolve to an array.");return this.Ia(r,l),r.treeChildrenLoaded=!0,r.treeLoadError=void 0,this.core.emit("treeChildrenLoaded",{rowId:e,rowNode:r,children:l}),l}).catch(l=>{if(s.signal.aborted||l?.name==="AbortError")return[];throw r.treeLoadError=l,r.treeChildrenLoaded=!1,this.core.reportError(l,"treeData.loadChildren",{rowId:e}),this.core.emit("treeChildrenLoadFailed",{rowId:e,rowNode:r,error:l}),l}).finally(()=>{this.he.get(e)===s&&(this.he.delete(e),this.Et.delete(e),r.treeLoading=!1,this.core.requestUpdate({data:!0}))});return this.Et.set(e,a),a}Ia(e,t){let r=new Set,o=[...this.St(e.id)];for(;o.length>0;){let s=o.pop();r.has(s)||(r.add(s),o.push(...this.St(s)))}this.Aa(t,r);for(let s of r)this.he.get(s)?.abort(),this.he.delete(s),this.Et.delete(s),this.k.delete(s),this.r.delete(s),this.g.delete(s);this.k.delete(e.id);let n=this.Po(e)+1;for(let s of t)s!=null&&this.Go(e,s,n);this.Dn(),this.core.selectionService.onRowsRebuilt(this.core.options.resolveRowId!=null),this.a(),this.core.requestUpdate({data:!0})}Aa(e,t){let r=this.core.options.resolveRowId,o=r?new Set([...this.r.keys()].filter(l=>!t.has(l))):null,n=new WeakSet,s=[...e],a=0;for(;s.length>0;){let l=s.pop();if(l==null)continue;if(typeof l=="object"){if(n.has(l))throw new TypeError("[MachTable] Lazy tree children contain a cyclic object graph.");n.add(l)}if(r&&o){let c=r({data:l,index:a++,api:this.core.getApi()});if(typeof c!="string"||c.length===0)throw new TypeError("[MachTable] rowKey must resolve to a non-empty identifier for lazy tree children.");if(o.has(c))throw new Error(`Duplicate row id: ${c}`);o.add(c)}let d=ge(l,this.core.options.childrenKey);d&&s.push(...d)}}kt(e,t=!0){let r=this.core.options.resolveRowId,o=[],n=[];if(e.remove?.length){let a=new Set,l=new Set,d=u=>{if(r){let p=[this.resolveRowId(u,-1,`__missing_remove_${this.core.nextId()}`)];for(;p.length>0;){let m=p.pop();if(!a.has(m)){a.add(m);for(let g of this.k.get(m)??[])p.push(g)}}}else{let h=[u];for(;h.length>0;){let p=h.pop();l.add(p);let m=this.w?ge(p,this.core.options.childrenKey):void 0;if(m)for(let g of m)h.push(g)}}};e.remove.forEach(d),this.all=this.all.filter(u=>{let h=a.has(u.id)||u.data!=null&&l.has(u.data);return h&&(n.push(u.id),this.r.delete(u.id),this.k.delete(u.id)),!h});let c=new Set(this.all);this.M=this.M.filter(u=>c.has(u))}if(e.update?.length)for(let a of e.update){let l;r?l=this.r.get(this.resolveRowId(a,-1,`__missing_update_${this.core.nextId()}`)):l=this.all.find(d=>d.data===a),l&&(l.data=a,n.push(l.id),this.core.bodyRenderer.br(l),o.push(l))}if(e.add?.length){let a=e.addIndex!=null?Math.max(0,Math.min(e.addIndex,this.M.length)):this.M.length,l=[];e.add.forEach((d,c)=>{let u=this.resolveRowId(d,a+c,`add-${this.core.nextId()}`);if(this.r.has(u)){this.core.reportError(new Error(`Duplicate row id: ${u}`),"transaction.add",{rowId:u});return}let h={id:u,data:d,rowIndex:-1,selected:!1};this.r.set(u,h),this.hr.set(h,0);let p=this.w?ge(d,this.core.options.childrenKey):void 0;if(p)for(let m of p)m!=null&&this.Go(h,m,1);l.push(h)}),this.M.splice(a,0,...l),this.Dn()}let s=this.La(e);return t&&(s?this.a():o.length>0&&this.Rn()),this.core.changeTracker.clearRows(n),{pipelineChanged:s,updatedRowIds:o.map(a=>a.id)}}Pa(e){if(e.length===0)return{pipelineChanged:!1,updatedRowIds:[]};let t=!1,r=new Set;for(let o of e){let n=this.kt(o,!1);t||(t=n.pipelineChanged);for(let s of n.updatedRowIds)r.add(s)}return t?this.a():r.size>0&&this.Rn(),{pipelineChanged:t,updatedRowIds:[...r]}}La(e){return e.add?.length||e.remove?.length?!0:e.update?.length?this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0||!this.core.options.manualFiltering&&this.Cr()||!this.core.options.manualSorting&&this.core.columnModel.D().length>0||this.core.options.getRowHeight?!0:this.core.columnModel.e().some(t=>t.colDef.autoHeight===!0||t.colDef.autoRowSpan===!0||t.colDef.rowSpan!=null):!1}Rn(){this.core.emit("modelUpdated",{rowCount:this.N.length})}Go(e,t,r){let o=this.resolveRowId(t,-1,`add-${this.core.nextId()}`);if(this.r.has(o)){this.core.reportError(new Error(`Duplicate row id: ${o}`),"transaction.add",{rowId:o});return}let n=ge(t,this.core.options.childrenKey),s={id:o,data:t,rowIndex:-1,selected:!1,treeChildrenLoaded:Array.isArray(n)};this.r.set(o,s),this.hr.set(s,r);let a=this.k.get(e.id)??[];if(a.push(s.id),this.k.set(e.id,a),!!n)for(let l of n)l!=null&&this.Go(s,l,r+1)}Dn(){this.all=[];let e=t=>{this.all.push(t),this.r.has(t.id)||this.r.set(t.id,t);for(let r of this.k.get(t.id)??[]){let o=this.r.get(r);o&&e(o)}};for(let t of this.M)e(t)}It(e){let t=JSON.stringify(this.filterModel),r=new Set(this.core.columnModel.G().map(o=>o.id));return this.filterModel=J(e,r),JSON.stringify(this.filterModel)!==t}R(){return{...this.filterModel}}Ze(e){let t=new Set(this.core.columnModel.G().map(n=>n.id)),r=V(e,t),o=JSON.stringify(this.advancedFilterModel);return this.advancedFilterModel=r,this.core.options.advancedFilterModel=r,JSON.stringify(r)!==o}z(){return V(this.advancedFilterModel)}Qe(e){let t=e!=null&&e.trim()!==""?e:null;return t===this.quickFilter?!1:(this.quickFilter=t,!0)}At(){return this.quickFilter}Cr(){return Object.keys(this.filterModel).length>0||this.advancedFilterModel!=null||this.quickFilter!=null}a(){let e=this.core.performanceMonitor.start(),t=this.core.columnModel.e(),r=(s,a)=>this.core.getCellValue(s,a);if(this.o){this.Ga(e);return}if(this.Na(e))return;let o;if(this.w)o=this.Fa(t,r);else{o=this.all,this.Cr()&&!this.core.options.manualFiltering&&(o=o.filter(Nt(t,this.filterModel,this.advancedFilterModel,this.quickFilter,r)));let a=this.core.columnModel.D();if(a.length>0&&!this.core.options.manualSorting)try{o=Ft(o,a,t,r)}catch(d){this.core.reportError(d,"comparator",{sortModel:a})}let l=this.core.columnModel.re();if(l.length>0)o=this.Oa(o,l);else if(this.core.options.masterDetail){let d=[];for(let c of o)d.push(c),this.g.has(c.id)&&this.isRowExpandable(c)&&d.push({id:`__detail__${c.id}`,data:c.data,rowIndex:-1,selected:!1,isDetail:!0,masterId:c.id});o=d}}for(let s of this.all)s.rowIndex=-1;let n=0;o.forEach((s,a)=>{s.rowIndex=a,!s.isDetail&&!s.isGroup&&(n++,this.Rt.set(s,n))}),this.N=o,this.et(),this.En(r),this.core.emit("modelUpdated",{rowCount:o.length}),this.core.performanceMonitor.recordModel(e)}Ga(e){this.all.forEach((t,r)=>{this.B||(t.rowIndex=r),this.Rt.set(t,this.B?t.rowIndex+1:r+1)}),this.displayed=this.all,this.N=this.all,this.Tt.clear(),this.xt++,this.core.emit("modelUpdated",{rowCount:this.all.length}),this.core.performanceMonitor.recordModel(e)}Na(e){let t=this.Ro;return this.Ro=!1,!t&&this.Ha()?(this.Va(e),!0):(this.So(),!1)}Ha(){if(!this.core.options.dataProcessor||this.all.length<this.core.options.dataProcessorMinRows||this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0)return!1;let e=!this.core.options.manualFiltering&&this.Cr(),t=!this.core.options.manualSorting&&this.core.columnModel.D().length>0;return e||t}Va(e){this.So();let t=this.core.options.dataProcessor;if(!t)return;let r=++this.Mt,o=new AbortController;this.mr=o;let n=this.core.columnModel.e(),s=this.all.flatMap(d=>d.data==null?[]:[{id:d.id,data:d.data}]),a=!this.core.options.manualFiltering,l=!this.core.options.manualSorting;Promise.resolve().then(()=>t.process({rows:s,columns:n.map(d=>({colId:d.id,...d.colDef.field?{field:d.colDef.field}:{}})),sortModel:l?this.core.columnModel.D():[],filterModel:a?this.R():{},advancedFilterModel:a?this.z():null,quickFilterText:a?this.quickFilter:null,signal:o.signal})).then(d=>{if(r!==this.Mt||o.signal.aborted||this.core.isDestroyed())return;let c=new Set,u=[];for(let p of d.rowIds){if(c.has(p))continue;c.add(p);let m=this.r.get(p);m&&!m.isDetail&&!m.isGroup&&u.push(m)}for(let p of this.all)p.rowIndex=-1;u.forEach((p,m)=>{p.rowIndex=m,this.Rt.set(p,m+1)}),this.N=u,this.et();let h=(p,m)=>this.core.getCellValue(p,m);this.En(h),this.core.emit("modelUpdated",{rowCount:u.length}),this.core.performanceMonitor.recordModel(e),this.core.requestUpdate({data:!0})}).catch(d=>{r!==this.Mt||o.signal.aborted||this.core.isDestroyed()||(this.core.reportError(d,"dataProcessor.process"),this.Ro=!0,this.a(),this.core.requestUpdate({data:!0}))}).finally(()=>{r===this.Mt&&(this.mr=null)})}So(){this.Mt++,this.mr?.abort(),this.mr=null}get j(){return this.core.options.paginationEnabled&&!this.o}et(){if(!this.j){this.displayed=this.N,this.xt++;return}let e=this.Lt(),t=this.getPageCount();if(this.page>t&&(this.page=t),this.page<1&&(this.page=1),this.core.options.paginationPage=this.page,this.core.options.paginationMode==="server"){this.N.forEach((n,s)=>{n.rowIndex=s}),this.displayed=this.N,this.xt++;return}let r=(this.page-1)*e,o=this.N.slice(r,r+e);o.forEach((n,s)=>{n.rowIndex=s}),this.displayed=o,this.xt++}Lt(){return this.pageSize=this.core.options.paginationPageSize,Math.max(1,this.pageSize)}Pt(){return this.j?this.page:1}getTotalRowCount(){return this.o?this.Xe():this.j&&this.core.options.paginationMode==="server"?this.core.options.paginationTotal:this.N.length}getPageCount(){return this.j?Math.max(1,Math.ceil(this.getTotalRowCount()/this.Lt())):1}xn(){return this.N}setPage(e,t=!1){if(!this.j)return;let r=this.getPageCount(),o=Math.max(1,Math.min(Math.round(e)||1,r));o!==this.page&&(this.page=o,this.core.options.paginationPage=o,this.et(),this.core.requestUpdate({data:!0}),this.core.bodyRenderer.tt(0,"top"),t||this.Tr())}setPageSize(e){if(!this.j)return;let t=Math.max(1,Math.round(e)||this.Lt()),r=(this.page-1)*this.Lt();this.core.options.paginationPageSize=t,this.pageSize=t,this.page=Math.floor(r/t)+1,this.core.options.paginationPage=this.page,this.et(),this.core.requestUpdate({data:!0}),this.Tr()}Mn(e,t){this.pageSize=Math.max(1,Math.round(t)||1),this.core.options.paginationPageSize=this.pageSize,this.page=Math.max(1,Math.round(e)||1),this.core.options.paginationPage=this.page}Dr(e){this.core.options.paginationEnabled!==e&&(this.core.options.paginationEnabled=e&&!this.o,this.core.options.paginationEnabled&&(this.page=1),this.et(),this.core.requestUpdate({data:!0}),this.Tr())}Ba(){this.j&&(this.page=this.core.options.paginationMode==="server"?this.core.options.paginationPage:1,this.et(),this.core.requestUpdate({data:!0}),this.Tr())}Tr(){this.core.emit("paginationChanged",{page:this.Pt(),pageSize:this.Lt(),pageCount:this.getPageCount(),total:this.getTotalRowCount()})}Fa(e,t){let r=this.core.options.manualSorting?[]:this.core.columnModel.D(),o=new Map,n=this.Cr()&&!this.core.options.manualFiltering,s=Nt(e,this.filterModel,this.advancedFilterModel,this.quickFilter,t),a=c=>{let u=o.get(c.id);if(u!==void 0)return u;let h=!0;if(n){h=s(c);for(let p of this.k.get(c.id)??[]){let m=this.r.get(p);m&&a(m)&&(h=!0)}}return o.set(c.id,h),h},l=[],d=c=>{let u=c;r.length>0&&(u=Ft(c,r,e,t));for(let h of u)if(a(h)&&(l.push(h),this.g.has(h.id))){let p=(this.k.get(h.id)??[]).map(m=>this.r.get(m)).filter(m=>m!=null);d(p)}};return d(this.M),l}za(){let e=this.un,t=0;for(let r of this.displayed)!r.isDetail&&!r.isGroup&&(e[t++]=r);return e.length=t,e}_a(e,t,r,o){let n=t.colDef.rowSpan;if(!n)return 1;try{let s=n({api:this.core.getApi(),colDef:t.colDef,column:t,node:e,data:e.data,value:r,rowIndex:e.rowIndex});return Math.max(1,Math.min(Math.round(s)||1,o))}catch(s){return this.core.reportError(s,"rowSpan",{colId:t.id,rowId:e.id}),1}}Wa(e,t,r,o,n){if(!r.colDef.autoRowSpan||o==null||o==="")return 1;let s=1;for(;t+s<e.length&&Ne(o,n(e[t+s],r))===0;)s++;return s}$a(e,t,r){let o=new Int32Array(e.length),n=0;for(;n<e.length;){let s=e[n],a=r(s,t),l=t.colDef.rowSpan?this._a(s,t,a,e.length-n):this.Wa(e,n,t,a,r);o[n]=l;for(let d=1;d<l;d++)o[n+d]=-1;n+=l}return o}En(e){if(this.Tt.clear(),this.w||this.core.options.masterDetail||this.core.columnModel.re().length>0)return;let t=this.core.columnModel.e().filter(o=>o.colDef.rowSpan!=null||o.colDef.autoRowSpan===!0);if(t.length===0)return;let r=this.za();if(r.length!==0)for(let o of t)this.Tt.set(o.id,this.$a(r,o,e))}Ka(e){return this.Tt.get(e)}Sn(e){return this.Rt.get(e)??0}Po(e){return this.hr.get(e)??0}Oa(e,t){let r=Ot(this.core.options.aggFuncs),o=this.core.columnModel.ya();this.je=[];let n=a=>{let l={};for(let d of o){let c=r(d.colDef.aggFunc);if(c)try{l[d.id]=c(a.map(u=>this.core.getCellValue(u,d)))}catch(u){this.core.reportError(u,"aggFunc",{colId:d.id,aggFunc:d.colDef.aggFunc}),l[d.id]=null}}return l},s=(a,l,d)=>{if(l>=t.length)return{display:a,leaves:a};let c=t[l],u=new Map,h=[];for(let g of a){let v=this.core.getCellValue(g,c),y=v==null?"(\u7A7A)":String(v),b=u.get(y);b||(b=[],u.set(y,b),h.push(y)),b.push(g)}h.sort((g,v)=>g.localeCompare(v,void 0,{numeric:!0,sensitivity:"base"}));let p=[],m=[];for(let g of h){let v=u.get(g),y=`${d}/g${l}:${g}`;this.je.push(y);let b=s(v,l+1,y),C={id:y,data:null,rowIndex:-1,selected:!1,isGroup:!0,groupLevel:l,groupKey:g,leafNodes:b.leaves,aggValues:n(b.leaves)};p.push(C),this.I.has(y)&&p.push(...b.display),m.push(...b.leaves)}return{display:p,leaves:m}};return s(e,0,"").display}isRowExpandable(e){if(this.w){if(this.Lo(e.id)||e.treeLoading)return!0;if(e.treeChildrenLoaded||!e.data||!this.core.options.loadTreeChildren)return!1;let r=this.core.options.isTreeRowExpandable;if(!r)return!1;try{return r({data:e.data,node:e,api:this.core.getApi()})}catch(o){return this.core.reportError(o,"isTreeRowExpandable",{rowId:e.id}),!1}}if(!this.core.options.masterDetail)return!1;let t=this.core.options.isRowExpandable;if(t)try{return t({data:e.data,node:e,api:this.core.getApi()})}catch(r){return this.core.reportError(r,"isRowExpandable",{rowId:e.id}),!1}return!0}isRowExpanded(e){return this.g.has(e)}qa(){return[...this.g]}Ua(){return[...this.I]}ja(e,t){this.g=new Set(e.filter(r=>this.r.has(r))),this.I=new Set(t)}No(e){return this.Fo(e,!0)}Oo(e){return this.Fo(e,!1)}toggleDetail(e){return this.Fo(e,!this.g.has(e))}Fo(e,t){let r=this.r.get(e);return!r||t&&!this.isRowExpandable(r)?!1:(t===this.g.has(e)||(t?this.g.add(e):this.g.delete(e),this.a(),this.core.requestUpdate({data:!0}),this.core.emit("detailToggled",{rowId:e,rowNode:r,expanded:t}),t&&this.w&&!this.Lo(e)&&!r.treeLoading&&this.loadTreeChildren(e).catch(()=>{})),t)}Ho(){let e=!1;for(let t of this.all)!this.g.has(t.id)&&this.isRowExpandable(t)&&(this.g.add(t.id),e=!0);e&&(this.a(),this.core.requestUpdate({data:!0}))}Vo(){this.g.size!==0&&(this.g.clear(),this.a(),this.core.requestUpdate({data:!0}))}Bo(e){return this.setGroupExpanded(e,!this.I.has(e))}isGroupExpanded(e){return this.I.has(e)}uh(e){return this.displayed.find(t=>t.isGroup&&t.id===e)}zo(){if(this.je.length===0)return;let e=!1;for(let t of this.je)this.I.has(t)||(this.I.add(t),e=!0);e&&(this.a(),this.core.requestUpdate({data:!0}))}_o(){this.I.size!==0&&(this.I.clear(),this.a(),this.core.requestUpdate({data:!0}))}setGroupExpanded(e,t){return!this.je.includes(e)||t===this.I.has(e)||(t?this.I.add(e):this.I.delete(e),this.a(),this.core.requestUpdate({data:!0})),t}kn(){return!this.w&&!this.o&&!this.core.options.dataProcessor&&this.core.options.paginationMode!=="server"&&this.core.columnModel.D().length===0&&this.core.columnModel.re().length===0}In(e,t){if(!this.kn()||!Number.isInteger(e)||!Number.isInteger(t))return!1;let r=this.i(e),o=this.i(t);if(!r||!o||r.isDetail||o.isDetail||r.isGroup||o.isGroup)return!1;let n=this.all.indexOf(r),s=this.all.indexOf(o);return n<0||s<0||n===s?!1:(this.all.splice(n,1),this.all.splice(s,0,r),this.a(),this.core.requestUpdate({data:!0}),!0)}_(){return this.all}Ya(){return this.M}ge(){return this.displayed}f(){return this.B?this.Je():this.displayed.length}i(e){return this.B?e<0||e>=this.Je()?void 0:this.pe.get(e)??this.xa(e):this.displayed[e]}T(e){return this.r.get(e)}Wo(e){this.all.forEach(e)}$o(e){let t=0;for(let r of this.N)r.isDetail||r.isGroup||e(r,t++)}};var Be=class{constructor(e){this.core=e;this.h=new Set;this.ne=null;this.Gt=new Set}isSelected(e){return this.h.has(e)}isIndeterminate(e){return this.Gt.has(e)}isSelectable(e){if(e.loading)return!1;let t=this.Xa(e),r=t?.colDef.selectable;if(!t||!r)return!0;try{return r({api:this.core.getApi(),colDef:t.colDef,column:t,node:e,data:e.data,value:this.core.getCellValue(e,t),rowIndex:e.rowIndex})}catch(o){return this.core.reportError(o,"selectable",{rowId:e.id,colId:t?.id}),!1}}Xa(e){if(!(e.isGroup||e.isDetail))return this.core.columnModel.e().find(t=>t.hasCheckbox&&t.colDef.selectable!=null)}getSelectedNodes(){return this.core.rowModel._().filter(e=>this.h.has(e.id))}getSelectedRows(){return this.getSelectedNodes().filter(e=>e.data!=null).map(e=>e.data)}getSelectedIds(){return[...this.h]}restoreSelection(e){let t=new Set(e),r=this.core.rowModel._().filter(o=>t.has(o.id)&&!o.isDetail&&!o.isGroup).map(o=>({node:o,selected:!0}));this.W(r,!0)}onRowsRebuilt(e){if(!e)this.h.clear(),this.ne=null;else{let t=new Set(this.core.rowModel._().map(r=>r.id));for(let r of[...this.h])t.has(r)||this.h.delete(r);this.ne!=null&&!t.has(this.ne)&&(this.ne=null)}for(let t of this.core.rowModel._())t.selected=this.h.has(t.id);this.An()}getGroupSelectionState(e){let t=e.leafNodes??[];if(t.length===0)return{all:!1,some:!1};let r=0,o=0;for(let n of t)this.isSelectable(n)&&(r++,this.h.has(n.id)&&o++);return r===0?{all:!1,some:!1}:{all:o===r,some:o>0}}setGroupSelected(e,t){let r=(e.leafNodes??[]).filter(o=>this.isSelectable(o));r.length!==0&&this.W(r.map(o=>({node:o,selected:t})))}setNodeSelected(e,t,r=!1){this.W([{node:e,selected:t,clearOthers:r}])}selectNodeById(e,t=!0,r=!0){let o=this.core.rowModel.T(e);o&&this.setNodeSelected(o,t,r)}Ja(e,t){let r=t==="single";this.W([{node:e,selected:r?!0:!e.selected,clearOthers:r}]),this.ne=e.id}Za(e,t,r){return!r||!t.ctrlKey&&!t.metaKey?!1:(this.W([{node:e,selected:!e.selected}]),this.ne=e.id,!0)}Qa(e,t,r){if(!r||!t.shiftKey||this.ne==null)return!1;let o=this.core.rowModel.T(this.ne);if(!o||o.rowIndex<0||e.rowIndex<0)return!1;let n=Math.min(o.rowIndex,e.rowIndex),s=Math.max(o.rowIndex,e.rowIndex),a=[];for(let l=n;l<=s;l++){let d=this.core.rowModel.i(l);d&&!d.isDetail&&!d.isGroup&&this.isSelectable(d)&&a.push({node:d,selected:!0})}return this.W(a),!0}onRowClick(e,t,r){let o=this.core.options.rowSelection;if(o==="none"||!this.isSelectable(e))return;if(r){this.Ja(e,o);return}let n=o==="multiple";this.Za(e,t,n)||this.Qa(e,t,n)||(this.W([{node:e,selected:!0,clearOthers:!0}]),this.ne=e.id)}selectAll(e=!0){let t=this.core.options.rowSelection;if(t==="none")return;let o=(e?this.core.rowModel.ge():this.core.rowModel._()).filter(n=>!n.isDetail&&!n.isGroup&&this.isSelectable(n));if(o.length!==0){if(t==="single"){this.W([{node:o[0],selected:!0,clearOthers:!0}]);return}this.W(o.map(n=>({node:n,selected:!0})))}}deselectAll(){this.W([],!0)}isSelectAllActive(){let t=this.core.rowModel.ge().filter(r=>!r.isDetail&&!r.isGroup).filter(r=>this.isSelectable(r));if(t.length===0)return!1;if(this.core.rowModel.o){let r=this.core.rowModel.Xe();if(t.length<r)return!1}return t.every(r=>this.h.has(r.id))}isSelectAllIndeterminate(){let t=this.core.rowModel.ge().filter(o=>!o.isDetail&&!o.isGroup).filter(o=>this.isSelectable(o)),r=t.reduce((o,n)=>o+(this.h.has(n.id)?1:0),0);if(r===0)return!1;if(this.core.rowModel.o){let o=this.core.rowModel.Xe();if(t.length<o)return!0}return r>0&&r<t.length}applySelectionPublic(e,t=!1){this.W(e,t)}tl(e,t,r){!t&&!e.some(o=>o.clearOthers)||(this.h=t?new Set:new Set(e.filter(o=>o.selected).flatMap(o=>r?this.Ln(o.node):[o.node.id])))}rl(e,t){for(let r of e){if(!this.isSelectable(r.node))continue;let o=t?this.Ln(r.node):[r.node.id];for(let n of o)r.selected?this.h.add(n):this.h.delete(n)}}ol(e){let t=new Set;for(let r of new Set([...e,...this.h]))e.has(r)!==this.h.has(r)&&t.add(r);return t}il(e,t,r){let o=[],n=new Set([...e,...r,...this.Gt]);for(let s of this.core.rowModel._()){let a=this.h.has(s.id);s.selected=a,(n.has(s.id)||t.get(s.id)!==a)&&s.rowIndex>=0&&o.push(s.rowIndex)}return o}W(e,t=!1){let r=new Set(this.h),o=this.core.rowModel.w&&this.core.options.autoCheckedChildren;this.tl(e,t,o),this.rl(e,o);let n=this.ol(r),s=new Map;for(let d of this.core.rowModel._())s.set(d.id,d.selected);let a=new Set(this.Gt);this.An();let l=this.il(n,s,a);n.size>0&&(this.core.bodyRenderer.ye(l),this.core.headerRenderer.wr(),this.core.emit("selectionChanged",{selectedNodes:this.getSelectedNodes(),selectedRows:this.getSelectedRows()}))}Ln(e){let t=[e.id],r=o=>{for(let n of this.core.rowModel.St(o))t.push(n),r(n)};return r(e.id),t}An(){if(this.Gt.clear(),!this.core.rowModel.w)return;let e=t=>{let r=this.core.rowModel.St(t);if(r.length===0)return{all:this.h.has(t),some:this.h.has(t)};let o=!0,n=!1;for(let s of r){let a=e(s);a.all?n=!0:(a.some&&(n=!0),o=!1)}return n&&!o&&this.Gt.add(t),o?this.h.add(t):this.h.delete(t),{all:o,some:n}};for(let t of this.core.rowModel.Ya())e(t.id);for(let t of this.core.rowModel._())t.selected=this.h.has(t.id)}};var ze=class{constructor(e){this.core=e;this.active=null;this.A=0;this.ve=0;this.Y=null;this.Le=null;this.we=e=>{let t=this.qo(e);t&&(this.ve=this.Fn(t,e.clientX),t.didResize||(t.didResize=Math.abs(this.ve-t.startWidth)>=.5),!this.A&&(this.A=requestAnimationFrame(()=>{this.A=0,this.sl()})))};this.X=e=>{let t=this.qo(e);t&&(this.ve=this.Fn(t,e.clientX),t.didResize||(t.didResize=Math.abs(this.ve-t.startWidth)>=.5),this.al(t))};this.Pe=e=>{this.qo(e)&&this.cancelResize()};this.Pn=()=>{this.cancelResize()}}startResize(e,t){if(!this.core.options.enableColumnResize||!t.resizable||e.isPrimary===!1)return;this.cancelResize();let r=e.currentTarget,o=t.currentWidth;this.ve=o,this.active={column:t,didResize:!1,handle:r,pointerId:e.pointerId,startFlex:t.flex,startManualWidth:t.manualWidth,startWidth:o,startX:e.clientX},window.addEventListener("pointermove",this.we),window.addEventListener("pointerup",this.X,!0),window.addEventListener("pointercancel",this.Pe,!0),r.addEventListener("lostpointercapture",this.Pn);try{r.setPointerCapture?.(e.pointerId)}catch{}this.core.skeleton.root.classList.add("mach-root--resizing"),r.classList.add("mach-header-resize--active"),this.nl(this.active)}cancelResize(e=!0){let t=this.active;t&&(this.active=null,this.Ko(),this.Gn(t),e&&(t.column.manualWidth=t.startManualWidth,t.column.flex=t.startFlex,this.core.relayoutColumns()),this.core.skeleton.root.classList.remove("mach-root--resizing"),this.Nn(t))}al(e){this.active=null,this.Ko(),e.didResize&&(Math.abs(this.ve-e.startWidth)<.5?(e.column.manualWidth=e.startManualWidth,e.column.flex=e.startFlex):this.core.columnModel.oe(e.column,this.ve),this.core.relayoutColumns()),this.Gn(e);try{e.handle.releasePointerCapture?.(e.pointerId)}catch{}this.core.skeleton.root.classList.remove("mach-root--resizing"),this.Nn(e),e.didResize&&this.core.commitColumnWidths([e.column])}sl(){let e=this.active;!e||!this.core.columnModel.oe(e.column,this.ve)||(this.core.relayoutColumns(),this.Nt(e),this.core.emitColumnResize(e.column,!1))}nl(e){this.Y=document.createElement("div"),this.Y.className="mach-column-resize-guide",this.Y.setAttribute("aria-hidden","true"),this.Le=document.createElement("span"),this.Le.className="mach-column-resize-label",this.Y.appendChild(this.Le),this.core.skeleton.root.appendChild(this.Y),this.Nt(e)}Nt(e){if(!this.Y||!this.Le)return;let t=this.core.skeleton.root,r=t.getBoundingClientRect(),o=e.handle.parentElement.getBoundingClientRect(),n=Math.max(0,Math.min(t.clientWidth,o.right-r.left-t.clientLeft)),s=Math.max(32,Math.min(t.clientWidth-32,n));this.Y.style.left=`${n}px`,this.Y.style.top=`${Math.max(0,o.top-r.top-t.clientTop)}px`,this.Le.style.left=`${s-n}px`,this.Le.textContent=`${Math.round(e.column.currentWidth)} px`}Nn(e){e.handle.classList.remove("mach-header-resize--active"),this.Y?.remove(),this.Y=null,this.Le=null}Fn(e,t){let r=Number.isFinite(t)?t:e.startX;return e.startWidth+r-e.startX}qo(e){let t=this.active;return t&&e.pointerId===t.pointerId?t:null}Ko(){this.A&&cancelAnimationFrame(this.A),this.A=0}Gn(e){window.removeEventListener("pointermove",this.we),window.removeEventListener("pointerup",this.X,!0),window.removeEventListener("pointercancel",this.Pe,!0),e.handle.removeEventListener("lostpointercapture",this.Pn)}destroy(){this.cancelResize(!1),this.Ko(),this.core.skeleton.root?.classList.remove("mach-root--resizing")}};function f(i,e,t){let r=document.createElement(i);if(e&&(r.className=e),t)for(let o of Object.keys(t))r.setAttribute(o,t[o]);return r}var Ki=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function L(i,e){if(i.classList.add("mach-portal"),!e)return;let t=window.getComputedStyle(e);for(let r of Ki){let o=t.getPropertyValue(r).trim();o&&i.style.setProperty(r,o)}i.style.colorScheme=t.colorScheme}function R(i,e,t){return i<e?e:i>t?t:i}var Gr=0;function Nr(i="rg"){return Gr++,`${i}-${Gr}`}var Fr='<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3.5h12L9.5 8v4.5L6.5 14V8L2 3.5z"/></svg>',Or='<svg viewBox="0 0 16 16" width="10" height="10" fill="currentColor"><path d="M8 3l4 5H4l4-5z"/></svg>',Hr='<svg viewBox="0 0 16 16" width="10" height="10" fill="currentColor"><path d="M8 13l4-5H4l4 5z"/></svg>',Vr='<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.35" stroke-linecap="round"><path d="M2 4h3m3 0h6M2 8h7m3 0h2M2 12h1m3 0h8"/><circle cx="6.5" cy="4" r="1.35"/><circle cx="10.5" cy="8" r="1.35"/><circle cx="4.5" cy="12" r="1.35"/></svg>';var Br=6,_e=class{constructor(e){this.core=e;this.pending=null;this.rt=null;this.Uo=!1;this.F=0;this.Rr=null;this.we=e=>{if(this.rt){this.ll(e);return}let t=this.pending;t&&(Math.abs(e.clientX-t.startX)<Br&&Math.abs(e.clientY-t.startY)<Br||this.dl(e))};this.X=e=>{this.pending=null,e.type!=="pointercancel"&&this.rt&&this.Xo(e.clientX,e.clientY),this.jo();let t=this.On();t&&e.type!=="pointercancel"&&t.targetIndex>=0&&this.core.moveColumn(t.column.id,t.targetIndex)}}onPointerDown(e,t){e.button===0&&t.movable&&(this.pending={column:t,startX:e.clientX,startY:e.clientY},window.addEventListener("pointermove",this.we),window.addEventListener("pointerup",this.X),window.addEventListener("pointercancel",this.X))}didDrag(){let e=this.Uo;return this.Uo=!1,e}dl(e){let t=this.pending;if(!t)return;let r=this.cl(t.column);if(!r||!r.parentElement){this.jo();return}this.Uo=!0;let o=f("div","mach-drop-indicator"),n=f("div","mach-column-drag-ghost");n.textContent=t.column.colDef.headerName??t.column.colDef.field??t.column.id,n.ariaHidden="true",L(n,this.core.skeleton.root),document.body.appendChild(n),r.parentElement.appendChild(o),r.classList.add("mach-header-cell--dragging"),this.core.skeleton.root.classList.add("mach-root--dragging");let s=this.core.bodyRenderer.Yo(t.column),a=this.core.skeleton.ot[s],l=this.core.columnModel.d(s),d=new Float64Array(l.length+1),c=new Float64Array(l.length);for(let h=0;h<l.length;h++){let p=l[h].currentWidth;c[h]=d[h]+p/2,d[h+1]=d[h]+p}let u=n.getBoundingClientRect();this.rt={column:t.column,cellEl:r,ghost:n,indicator:o,targetIndex:-1,pane:s,containerLeft:a.getBoundingClientRect().left,startScrollLeft:this.core.skeleton.b.center.scrollLeft,fromIndex:l.indexOf(t.column),midpoints:c,offsets:d,ghostWidth:u.width,ghostHeight:u.height},this.Xo(e.clientX,e.clientY)}cl(e){let t=this.core.bodyRenderer.Yo(e);return this.core.skeleton.ot[t].querySelector(`.mach-header-cell[data-col-id="${qi(e.id)}"]`)}ll(e){this.Rr={clientX:e.clientX,clientY:e.clientY},!this.F&&(this.F=requestAnimationFrame(()=>{this.F=0;let t=this.Rr;this.Rr=null,t&&this.Xo(t.clientX,t.clientY)}))}Xo(e,t){let r=this.rt;if(!r)return;let o=R(e+12,8,window.innerWidth-r.ghostWidth-8),n=R(t+12,8,window.innerHeight-r.ghostHeight-8);r.ghost.style.transform=`translate3d(${o}px, ${n}px, 0)`;let s=r.pane==="center"?this.core.skeleton.b.center.scrollLeft-r.startScrollLeft:0,a=e-(r.containerLeft-s),l=r.midpoints.length;for(let d=0;d<r.midpoints.length;d++)if(a<r.midpoints[d]){l=d;break}r.targetIndex=l>r.fromIndex?l-1:l,r.indicator.style.transform=`translate3d(${r.offsets[l]}px, 0, 0)`}On(){let e=this.rt;return e?(this.rt=null,e.cellEl.classList.remove("mach-header-cell--dragging"),e.ghost.remove(),e.indicator.remove(),this.core.skeleton.root.classList.remove("mach-root--dragging"),e):null}jo(){window.removeEventListener("pointermove",this.we),window.removeEventListener("pointerup",this.X),window.removeEventListener("pointercancel",this.X),this.F&&cancelAnimationFrame(this.F),this.F=0,this.Rr=null}destroy(){this.jo(),this.On(),this.pending=null}};function qi(i){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(i):i.replace(/[^a-zA-Z0-9_-]/g,"\\$&")}function zr(i,e){let t=i==null?"":String(i);return t.includes(e)||t.includes('"')||t.includes(`
2
2
  `)||t.includes("\r")?'"'+t.replace(/"/g,'""')+'"':t}function We(i){return typeof i!="string"||i===""||/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(i)?i:/^[\s\u0000-\u001f]*[=+\-@]/.test(i)?"'"+i:i}function Ht(i,e={}){let t=e.columnSeparator??",",r=e.includeHeader??!0,o=e.protectFormulas??!0,n=[];r&&n.push(i.getHeaderLabels().map(a=>zr(a,t)).join(t));for(let a of i.getRowValues())n.push(a.map(l=>zr(o?We(l):l,t)).join(t));let s=n.join(`\r
3
3
  `);return e.prependBOM?"\uFEFF"+s:s}function Ui(i,e){let t=e?We(i):i,r=t==null?"":String(t);return/["\t\n\r]/.test(r)?'"'+r.replace(/"/g,'""')+'"':r}function ye(i,e=!0){return i.map(t=>t.map(r=>Ui(r,e)).join(" ")).join(`
4
4
  `)}function Vt(i){return zt(i," ")}function Bt(i,e=","){return zt(i,e)}function zt(i,e){let t=[],r=[],o="",n=!1,s=0;for(;s<i.length;){let a=i[s];if(n){if(a==='"'){if(i[s+1]==='"'){o+='"',s+=2;continue}n=!1,s++;continue}o+=a,s++;continue}if(a==='"'&&o===""){n=!0,s++;continue}if(a===e){r.push(o),o="",s++;continue}if(a===`
package/dist/ordering.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var ie=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var qe=(r,e)=>{for(var t in e)ie(r,t,{get:e[t],enumerable:!0})},Be=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fe(e))!He.call(r,o)&&o!==t&&ie(r,o,{get:()=>e[o],enumerable:!(n=Ne(e,o))||n.enumerable});return r};var Ke=r=>Be(ie({},"__esModule",{value:!0}),r);var et={};qe(et,{RowOrderConflictError:()=>P,createRowOrderController:()=>Ae,moveTreeNodes:()=>V,reorderRows:()=>X});module.exports=Ke(et);var Ue=new Set(["__proto__","prototype","constructor"]);function Ye(r){return typeof r!="string"||r.length===0?!1:r.split(".").every(t=>t.length>0&&!Ue.has(t))}function j(r,e){if(r==null||!Ye(e))return;if(e.indexOf(".")<0)return r[e];let n=r,o=0;for(;o<e.length;){if(n==null)return;let i=e.indexOf(".",o);if(i<0){n=n[e.slice(o)];break}n=n[e.slice(o,i)],o=i+1}return n}function _e(r,e){let t=typeof e.rowKey=="function"?e.rowKey(r):j(r,e.rowKey);if(t==null||String(t).length===0)throw new Error("[MachTable] Row ordering requires a non-empty stable row key.");return String(t)}function ze(r,e){let t=r[e];if(t==null)return[];if(!Array.isArray(t))throw new Error(`[MachTable] Tree ordering expects an array at "${e}".`);return t}function K(r,e,t,n){let o={entries:[],byId:new Map,byRow:new Map,children:new Map([[null,r]])},i=[...r].reverse().map(d=>({row:d,parentId:null,selectedAncestor:!1})),a=t.childrenKey??"children";for(;i.length;){let d=i.pop(),c=_e(d.row,t);if(o.byId.has(c))throw new Error(`[MachTable] Row ordering found duplicate or cyclic row key "${c}".`);let l=n?ze(d.row,a):[],h={...d,id:c,children:l};o.entries.push(h),o.byId.set(c,h),o.byRow.set(h.row,h),o.children.set(c,l);for(let f=l.length-1;f>=0;f--)i.push({row:l[f],parentId:c,selectedAncestor:d.selectedAncestor||e.has(c)})}return o}function $e(r){if(!["before","after","inside"].includes(r.position))throw new Error("[MachTable] Unknown row ordering position.");let e=[...new Set(r.rowIds.map(String))];if(!e.length)throw new Error("[MachTable] Row ordering requires at least one source row.");return{...r,rowIds:e,targetId:String(r.targetId)}}function ae(r,e){for(let n of e)if(!r.byId.has(n))throw new Error(`[MachTable] Ordering source "${n}" is unavailable.`);let t=new Set(e);return{selected:t,moved:r.entries.filter(n=>t.has(n.id)&&!n.selectedAncestor)}}function be(r,e,t,n){let o=r.byId.get(t.targetId);if(!o)throw new Error(`[MachTable] Ordering target "${t.targetId}" is unavailable.`);if(e.selected.has(o.id)||o.selectedAncestor)throw new Error("[MachTable] A row cannot be moved into or relative to its own subtree.");let i=t.position==="inside"?o.id:o.parentId,a=i===null?null:r.byId.get(i).row;if(n.canMove)for(let d of e.moved){let c=d.parentId===null?null:r.byId.get(d.parentId).row,l=n.canMove({row:d.row,previousParent:c,parent:a,target:o.row,intent:t});if(l===!1||typeof l=="string")throw new Error(typeof l=="string"?l:"[MachTable] This row cannot be moved to the selected parent.")}return i}function Re(r,e,t,n){let o=[...new Set(e.map(String))];if(!o.length)throw new Error("[MachTable] Row ordering requires at least one source row.");let i=K(r,new Set(o),t,n),a=ae(i,o);return d=>{if(!n&&d.position==="inside")throw new Error("[MachTable] Flat rows cannot have child destinations.");be(i,a,d,t)}}function We(r,e,t,n){let o=new Set(e.map(l=>l.id)),i=new Map;for(let l of e)i.has(l.parentId)||i.set(l.parentId,r.children.get(l.parentId).filter(h=>!o.has(r.byRow.get(h).id)));let a=i.get(t)??r.children.get(t),d=a.findIndex(l=>l===r.byId.get(n.targetId).row),c=n.position==="inside"?a.length:d+ +(n.position==="after");return i.set(t,[...a.slice(0,c),...e.map(l=>l.row),...a.slice(c)]),i}function ve(r,e){return r.length===e.length&&r.every((t,n)=>t===e[n])}function je(r,e,t,n){let o=new Map,i=n.childrenKey??"children";for(let d=e.entries.length-1;d>=0;d--){let c=e.entries[d],h=(t.get(c.id)??c.children).map(f=>o.get(f)??f);ve(c.children,h)||o.set(c.row,{...c.row,[i]:h})}let a=(t.get(null)??r).map(d=>o.get(d)??d);return ve(r,a)?r:a}function Xe(r,e,t,n){let o=t.indexOf(e[0].row),i=o+e.length;return{...r,rowIds:e.map(a=>a.id),beforeId:o>0?n.byRow.get(t[o-1]).id:null,afterId:i<t.length?n.byRow.get(t[i]).id:null}}function Te(r,e,t){let n=K(r.before,new Set(r.rowIds),e,t),o=new Map;for(let i of n.children.values())i.forEach((a,d)=>o.set(n.byRow.get(a).id,d));return ae(n,r.rowIds).moved.reverse().map(i=>{let a=n.children.get(i.parentId),d=o.get(i.id),c=a[d+1];if(c)return{rowIds:[i.id],targetId:n.byRow.get(c).id,position:"before"};if(i.parentId!==null)return{rowIds:[i.id],targetId:i.parentId,position:"inside"};let l=a[d-1];if(!l)throw new Error("[MachTable] Row ordering cannot restore an isolated root.");return{rowIds:[i.id],targetId:n.byRow.get(l).id,position:"after"}})}function Ie(r,e,t,n,o){if(!n.canMove)return;let i=K(r,new Set,n,o),a=K(e,new Set,n,o);for(let d of t)for(let c of d.rowIds){let l=i.byId.get(c),h=a.byId.get(c),f=h.parentId===null?null:i.byId.get(h.parentId).row,x=l.parentId===null?null:i.byId.get(l.parentId).row,E=n.canMove({row:l.row,previousParent:x,parent:f,target:i.byId.get(d.targetId).row,intent:d});if(E===!1||typeof E=="string")throw new Error(typeof E=="string"?E:"[MachTable] This row cannot be restored to its previous parent.")}}function De(r,e,t,n){let o=$e(e);if(!n&&o.position==="inside")throw new Error("[MachTable] Flat rows cannot have child destinations.");let i=K(r,new Set(o.rowIds),t,n),{moved:a,selected:d}=ae(i,o.rowIds),c=be(i,{moved:a,selected:d},o,t),l=We(i,a,c,o),h=je(r,i,l,t),f=Xe(o,a,l.get(c),i);return{before:r,after:h,intent:f,rowIds:f.rowIds,changed:r!==h}}function X(r,e,t){return De(r,e,t,!1)}function V(r,e,t){return De(r,e,t,!0)}function se(r,e,t){let n=document.createElement(r);if(e&&(n.className=e),t)for(let o of Object.keys(t))n.setAttribute(o,t[o]);return n}function M(r,e,t){return r<e?e:r>t?t:r}var de=Symbol.for("mach-table.adapter.lifecycle.v1");function J(r){return!r.isDestroyed()&&(r[de]?.canReplaceData()??!1)}function le(r,e){let t=r[de]?.rowDrag;return t?.original===e&&t.policy===r.getOption("rowDragPolicy")}function ce(r,e){let t=r[de];if(!t)return()=>{};t.rowDrag?.activeInteraction?.destroy();let n={original:e,policy:r.getOption("rowDragPolicy"),factory:o=>(n.activeInteraction=e(o),n.activeInteraction)};return t.rowDrag=n,()=>{n.activeInteraction?.destroy(),t.rowDrag===n&&(t.rowDrag=void 0)}}function Oe(r,e){return new Promise((t,n)=>{let o=()=>n(Object.assign(new Error("[MachTable] Operation cancelled."),{name:"AbortError"}));if(r.then(t,n).finally(()=>e.removeEventListener("abort",o)),e.aborted){o();return}e.addEventListener("abort",o,{once:!0})})}function ue(r,e,t){return r.replace("{a}",String(e)).replace("{b}",String(t))}function Ve(r,e,t){return r&&e>.25&&e<.75?"inside":t}function xe(r,e){let t=0,n=r.length;for(;t<n;){let o=t+n>>>1;r[o]<e?t=o+1:n=o}return t}function Je(r,e,t,n,o,i){let a=r.getOption("locale")??{},d=e>1?ue(a.rowDragSelection??"\u5DF2\u9009 {a} \u884C \u2192 \u7B2C {b} \u884C",e,n+1):ue(a.rowDragPosition??"\u7B2C {a} \u884C \u2192 \u7B2C {b} \u884C",t+1,n+1),c=o==="inside"?a.rowDragInside??"\u79FB\u5165":o==="before"?a.rowDragBefore??"\u4E4B\u524D":a.rowDragAfter??"\u4E4B\u540E";return{text:`${d} \xB7 ${c}`,indicatorStyle:o==="inside"?`height:${i}px;background:color-mix(in srgb,var(--mach-primary) 12%,transparent);box-shadow:inset 0 0 0 1px var(--mach-primary)`:void 0}}function Qe(r,e,t){let n={parents:new Map,siblings:new Map([[null,[]]]),depths:new Map},o=[...r].reverse().map(a=>({row:a,parent:null,depth:0})),i=e.childrenKey??"children";for(;o.length;){let{row:a,parent:d,depth:c}=o.pop(),l=String(typeof e.rowKey=="function"?e.rowKey(a):j(a,e.rowKey));if(n.depths.has(l))throw new Error("[MachTable] Row ordering requires unique, acyclic row keys.");n.depths.set(l,c),n.siblings.get(d).push(l),n.siblings.set(l,[]),d!==null&&n.parents.set(l,d);let h=t?a[i]:void 0;if(h!=null&&!Array.isArray(h))throw new Error("[MachTable] Row ordering children must be an array.");for(let f=(h?.length??0)-1;f>=0;f--)o.push({row:h[f],parent:l,depth:c+1})}return n}function Ee(r,e,t,n,o,i){let a=new Map;r.rows.forEach(u=>{!u.loading&&!u.isDetail&&!u.isGroup&&u.data!=null&&a.set(u.id,u)});let d=Qe(t,n,o),c=new Set(e.selected?[...d.depths.keys()].filter(u=>a.get(u)?.selected):[e.id]),l=[...c],h=u=>{let y=u;for(;y!==void 0;){if(c.has(y))return!0;y=d.parents.get(y)}return!1},f=new Map,x=new Map;for(let[u,y]of d.siblings){let m=y.filter(v=>!c.has(v));f.set(u,m),m.forEach((v,g)=>x.set(v,g))}let E=new Map,S=[],I=[],A=0;r.rows.forEachDisplayed(u=>{h(u.id)&&S.push(u.rowIndex),A=u.rowIndex+1;let y=d.depths.get(u.id)??0;for(;I.length&&(d.depths.get(I[I.length-1].id)??0)>=y;)E.set(I.pop().id,u.rowIndex);d.siblings.get(u.id)?.length&&I.push(u)});for(let u of I)E.set(u.id,A);return{rowIds:l,isSource:h,validate:()=>{for(let u of l){let y=a.get(u);if(y.treeLoading)return!1;let m=r.getOption("rowDragPolicy")?.canDrag?.({node:y,api:r});if(m===!1||typeof m=="string")return m}return!0},resolve:({targetNode:u,position:y,fraction:m,height:v})=>{let g=Ve(o,m,y);if(h(u.id))return"Cannot target own subtree.";if(!o&&g==="inside")return!1;let _=g==="inside"?u.id:d.parents.get(u.id)??null,C=f.get(_)??[],L=g==="inside"?C.length:(x.get(u.id)??0)+ +(g==="after"),G=g==="before"?u.rowIndex:E.get(u.id)??u.rowIndex+1,z=G-xe(S,G)+xe(S,e.rowIndex);return{intent:{rowIds:l,targetId:u.id,position:g,beforeId:C[L-1]??null,afterId:C[L]??null,expectedRevision:i},indicatorIndex:g==="inside"?u.rowIndex:g==="after"?E.get(u.id):void 0,toIndex:G,targetIndex:z,...Je(r,l.length,e.rowIndex,u.rowIndex,g,v)}},keyboardTarget:u=>{let y=e.id;for(;c.has(d.parents.get(y)??"");)y=d.parents.get(y);let m=d.siblings.get(d.parents.get(y)??null)??[],v=m.indexOf(y)+u;for(;v>=0&&v<m.length;){let g=m[v];if(!h(g)&&a.has(g))return a.get(g);v+=u}}}}var Q=class{constructor(e){this.host=e;this.drag=null;this.t=0;this.r=0;this.s=e=>{let t=this.drag;if(!(!t||e.pointerId!==t.pointerId)){if(t.clientX=e.clientX,t.clientY=e.clientY,!t.active){if(Math.abs(e.clientY-t.startY)<5)return;t.active=!0,this.host.root.classList.add("mach-root--row-dragging"),this.host.root.querySelectorAll(".mach-row").forEach(n=>n.classList.toggle("mach-row--drag-source",this.sourceContains(n.dataset.id??"")))}this.d()}};this.h=()=>{if(this.t=0,!!this.drag?.active){if(!this.current()){this.destroy();return}this.c(),this.g()&&this.d()}};this.a=e=>{let t=this.drag;if(!(!t||e.pointerId!==t.pointerId)){t.clientX=e.clientX,t.clientY=e.clientY,t.active&&this.current()&&this.c(),this.u();try{t.active&&t.drop?.valid&&this.o(e.clientX,e.clientY)&&this.current()&&this.commitDrop(t.drop)}finally{this.release()}}};this.l=e=>{e.key==="Escape"&&(e.preventDefault(),this.destroy())};this.n=e=>{e.type==="pointercancel"&&e.pointerId!==this.drag?.pointerId||this.destroy()}}begin(e){let t=this.host.containers.map(o=>{let i=se("div","mach-row-drop-indicator");return i.hidden=!0,o.append(i),i}),n=se("div","mach-row-drag-preview");n.setAttribute("role","status"),n.hidden=!0,this.host.root.append(n),this.drag={startY:e.clientY,clientX:e.clientX,clientY:e.clientY,pointerId:e.pointerId,indicators:t,preview:n,drop:null,active:!1},window.addEventListener("pointermove",this.s),window.addEventListener("pointerup",this.a),window.addEventListener("pointercancel",this.n),window.addEventListener("keydown",this.l),window.addEventListener("blur",this.n)}draggingSource(e){return this.drag?.active===!0&&this.sourceContains(e)}focusHandle(e,t=()=>!0){this.r=requestAnimationFrame(()=>{this.r=0,t()&&[...this.host.root.querySelectorAll(".mach-row-drag-handle")].find(n=>n.closest(".mach-row")?.dataset.id===e)?.focus()})}d(){this.t||(this.t=requestAnimationFrame(this.h))}o(e,t,n=0){let o=this.host.body.getBoundingClientRect();return e>=o.left&&e<=o.right&&t>=o.top-n&&t<=o.bottom+n}g(){let e=this.drag;if(!e||!this.o(e.clientX,e.clientY,28))return!1;let t=this.host.viewport,n=t.getBoundingClientRect(),o=Math.min(36,n.height/3);if(o<=0)return!1;let i=e.clientY<n.top+o?-Math.ceil(14*M((n.top+o-e.clientY)/o,0,1)):Math.ceil(14*M((e.clientY-n.bottom+o)/o,0,1)),a=t.scrollTop;return t.scrollTop=M(a+i,0,Math.max(0,t.scrollHeight-t.clientHeight)),t.scrollTop!==a}c(){let e=this.drag;if(!e?.active)return;let t=e.clientY-this.host.viewport.getBoundingClientRect().top+this.host.viewport.scrollTop,n=this.describe(t);e.drop=n;let o=this.o(e.clientX,e.clientY);for(let a of e.indicators)a.hidden=!o||!n?.valid,n&&(a.dataset.dropPosition=n.position??"",a.style.cssText=n.style??"",a.style.transform=`translate3d(0, ${this.host.getRowTop(n.boundary)}px, 0)`);let i=this.host.root.getBoundingClientRect();e.preview.hidden=!1,e.preview.textContent=o?n?.text??this.outsideText():this.outsideText(),e.preview.style.transform=`translate3d(${M(e.clientX-i.left+16,8,Math.max(8,i.width-224))}px, ${M(e.clientY-i.top+16,8,Math.max(8,i.height-48))}px, 0)`}u(){let e=this.drag;this.drag=null,window.removeEventListener("pointermove",this.s),window.removeEventListener("pointerup",this.a),window.removeEventListener("pointercancel",this.n),window.removeEventListener("keydown",this.l),window.removeEventListener("blur",this.n),cancelAnimationFrame(this.t),this.t=0,this.host.root?.classList.remove("mach-root--row-dragging"),this.host.root?.querySelectorAll(".mach-row--drag-source").forEach(t=>t.classList.remove("mach-row--drag-source")),e?.indicators.forEach(t=>t.remove()),e?.preview.remove()}destroy(){this.u(),this.release(),cancelAnimationFrame(this.r),this.r=0}};var Z=class extends Q{constructor(t,n,o){super(t);this.bridge=t;this.prepare=n;this.requestFocus=o;this.scope=null;this.i=!1}e(t,n,o){try{return n()}catch(i){return this.scope&&(this.scope.failed=!0),this.bridge.report(i,t),o}}p(t){return this.e("prepare",()=>{let n=this.bridge.capture(t),o=this.prepare(t);return this.scope={node:t,from:t.rowIndex,guard:n,session:o,sourceDecision:!0,failed:!1},this.scope.sourceDecision=o.validate(),this.scope},null)}start(t,n){this.destroy(),this.p(n)&&this.current()&&this.begin(t)}moveWithKeyboard(t,n){this.destroy();let o=this.p(n);if(!(!o||!this.current())){this.i=!0;try{let i=t.key==="ArrowUp"?-1:1,a=this.e("keyboardTarget",()=>o.session.keyboardTarget(i),void 0);a&&this.commitDrop(this.destination(a,i<0?0:1))}finally{this.i=!1,this.release()}}}isSource(t){return this.draggingSource(t.id)}current(){return!!(this.scope&&!this.scope.failed&&this.scope.guard.current()&&this.bridge.api.rows.getById(this.scope.node.id)===this.scope.node)}sourceContains(t){return this.e("isSource",()=>this.scope?.session.isSource(t)??!1,!1)}release(){this.scope=null}outsideText(){return this.bridge.api.getOption("locale")?.rowDragOutside??"\u79FB\u56DE\u8868\u683C\u5185\u653E\u7F6E \xB7 Esc \u53D6\u6D88"}describe(t){let n=this.bridge.api,o=M(this.host.findRowAt(t),0,n.rows.getCount()-1),i=n.rows.getAt(o);if(i?.isDetail&&(i=n.rows.getById(i.masterId)),!i)return null;let a=this.host.getRowTop(i.rowIndex),d=this.host.getRowTop(i.rowIndex+1)-a;return this.destination(i,(t-a)/Math.max(1,d))}destination(t,n){let o=this.scope,i=n<.5?"before":"after",a=this.host.getRowTop(t.rowIndex+1)-this.host.getRowTop(t.rowIndex),d=this.e("resolve",()=>o.session.resolve({targetNode:t,position:i,fraction:n,height:a}),!1),c=typeof o.sourceDecision=="string"?o.sourceDecision:typeof d=="string"?d:"\u6B64\u4F4D\u7F6E\u4E0D\u53EF\u653E\u7F6E",l={node:t,fraction:n,boundary:t.rowIndex,valid:!1,text:c};if(!d||typeof d=="string"||o.sourceDecision!==!0||t.loading||t.treeLoading||t.isGroup)return l;l.intent=d.intent,l.position=d.intent.position,l.toIndex=d.toIndex,l.targetIndex=d.targetIndex,l.boundary=d.indicatorIndex??t.rowIndex+ +(d.intent.position==="after"),l.style=d.indicatorStyle,l.text=d.text??c;let h=this.e("canDrop",()=>this.bridge.api.getOption("rowDragPolicy")?.canDrop?.({node:o.node,api:this.bridge.api,targetNode:t,intent:d.intent})??!0,!1);return l.valid=h===!0,typeof h=="string"&&(l.text=h),l}commitDrop(t){let n=this.scope;if(!n||!this.current()||this.e("validate",()=>n.session.validate(),!1)!==!0||!this.current())return!1;let o=this.destination(t.node,t.fraction);return!o.valid||!o.intent||!this.current()?!1:(this.i&&this.requestFocus(o.intent,i=>this.focusHandle(n.node.id,i)),this.bridge.emit(n.node,n.from,o.toIndex,o.targetIndex,o.intent),!0)}};function U(r,e,t){let n=[],o=[...r].reverse().map(a=>({row:a,parent:null})),i=new Set;for(;o.length;){let a=o.pop();if(i.has(a.row))throw new Error("[MachTable] Installed order contains duplicate or cyclic rows.");i.add(a.row),n.push(a);let d=t?a.row[e]??[]:[];for(let c=d.length-1;c>=0;c--)o.push({row:d[c],parent:a.row})}return n}function H(r,e,t,n){try{let o=U(r,t,n);return o.length===e.length&&o.every((i,a)=>i.row===e[a].row&&i.parent===e[a].parent)}catch{return!1}}function pe(r){let e=[];return r?.rows.forEach(t=>e.push({node:t,data:t.data})),e}function Y(r,e){if(!r)return!0;if(r.isDestroyed())return!1;let t=0,n=!0;return r.rows.forEach(o=>{let i=e[t++];(i?.node!==o||i.data!==o.data)&&(n=!1)}),n&&t===e.length}var ee=class{constructor(){this.entries=[];this.cursor=0}get canUndo(){return this.cursor>0}get canRedo(){return this.cursor<this.entries.length}peek(e){return this.entries[e==="undo"?this.cursor-1:this.cursor]}commit(e,t){e==="undo"?this.cursor--:e==="redo"?this.cursor++:(this.entries.splice(this.cursor),this.entries.push(t),this.entries.length>50&&this.entries.shift(),this.cursor=this.entries.length)}clear(){this.entries=[],this.cursor=0}};var P=class extends Error{constructor(t="The row order changed on the server. Reload before trying again.",n){super(t);this.serverRevision=n;this.name="RowOrderConflictError"}};function Ze(r){if(r?.status==="conflict")throw new P(r.message,r.revision);return r?.revision}function Se(r){if(r.targetId===null)throw new Error("[MachTable] Row ordering requires an existing destination.");return{...r,targetId:r.targetId}}function Ae(r){let e={status:"idle",error:null,revision:r.getRevision?.(),plan:null,canUndo:!1,canRedo:!1},t=0,n=!1,o=null,i=null,a=null,d=()=>{},c=()=>{},l=0,h=null,f=new ee,x=null,E=new Set,S=r.childrenKey??"children",I=null,A=()=>{f.clear(),x=null},u=()=>{if(!o)return!1;let s=o;return t++,o=null,i=null,s.abort(),!0},y=(s=e.status)=>({canUndo:!n&&s!=="saving"&&f.canUndo,canRedo:!n&&s!=="saving"&&f.canRedo}),m=s=>{e=Object.freeze({...s,...y(s.status)}),a&&!a.isDestroyed()&&a.view.refreshCells();let p=[w=>r.onStateChange?.(w),...E];for(let w of p)try{w?.(e)}catch(b){console.error("[MachTable] Row order state observer failed",b)}},v=()=>r.getRevision?.()??e.revision,g=(s=h)=>{s?.release(),h===s&&(h=null)},_=()=>{!i||i()||(u(),A(),g(),m({...e,status:"idle",plan:null,error:null}))},C=s=>new Z(s,p=>Ee(s.api,p,r.getRows(),r,r.treeData===!0,v()),(p,w)=>{g();let b=document.activeElement,T=N=>{N.target!==b&&N.target!==document.body&&g(R)},R={api:s.api,intent:p,restore:w,generation:t+1,release:()=>document.removeEventListener("focusin",T,!0)};h=R,document.addEventListener("focusin",T,!0)}),L=()=>{_(),!o&&x&&(x.api!==a||x.revision!==v()||!Y(a,x.nodes)||!H(r.getRows(),x.rows,S,r.treeData===!0))&&A();let s=y();(e.canUndo!==s.canUndo||e.canRedo!==s.canRedo)&&(e=Object.freeze({...e,...s}))},G=s=>{if(s===a){_(),le(s,C)||(c(),c=ce(s,C));return}let p=u();d(),c(),g(),A(),a=s,c=ce(s,C),d=s.on("cellValueChanged",()=>{l++;let w=f.canUndo||f.canRedo;A(),w&&m({...e,status:o?"saving":"idle",plan:o?e.plan:null,error:null})}),p&&m({...e,status:"idle",plan:null,error:null})},z=s=>{if(L(),n)throw new Error("[MachTable] The row order controller is disposed.");if(o)throw new Error("[MachTable] A row order save is already in progress.");let p=v();if(p!==void 0&&s.expectedRevision!==void 0&&s.expectedRevision!==p)throw new P;let w={...s,expectedRevision:s.expectedRevision??p};return(r.treeData?V:X)(r.getRows(),w,r)},he=async(s,p,w,b,T)=>{if(!s.changed)return s;let R=a;if(R&&!J(R))throw new Error("[MachTable] Save or discard edited rows before changing their order.");let N=++t;I=null;let $=new AbortController;o=$,i=null;let W=v(),Le=l,F=null,q=[],ye=!1,te=!1,re=W,me=D=>{if(!T)return;if(!D||T!==h||T.api!==a){g(T);return}let O=x;T.restore(()=>{let oe=O!==null&&O===x&&O.revision===v()&&Y(T.api,O.nodes)&&H(r.getRows(),O.rows,S,r.treeData===!0)&&h===T&&!n&&t===T.generation&&a===T.api&&le(T.api,C);return g(T),oe})},k=()=>!n&&t===N,ne=()=>k()&&(!R||a===R&&!R.isDestroyed())&&F!==null&&v()===W&&Y(R,q)&&H(r.getRows(),F,S,r.treeData===!0),ke=D=>{if(!ne()){k()&&!F&&m({...e,status:"error",error:D,plan:s});return}let O=!R||J(R),B=O?D:Object.assign(new Error("[MachTable] Row order could not be saved. Automatic rollback was skipped to preserve new edits. Save or discard those edits, then reload the row order."),{cause:D});if(O){i=null;try{r.applyRows(s.before),te=!0}catch(oe){B=Object.assign(new Error("[MachTable] Row order could not be saved or restored. Reload the row order before trying again."),{cause:D,rollbackError:oe})}}k()&&(te||A(),m({...e,status:D instanceof P?"conflict":"error",error:B}))},Ge=()=>{if(!k()){me(!1);return}let D=v(),O=!1;ye&&k()&&(D===W||D===re)&&Y(R,q)&&H(r.getRows(),F,S,r.treeData===!0)?(x={rows:F,nodes:q,api:R,revision:D},O=!0):te&&k()?(x={rows:U(r.getRows(),S,r.treeData===!0),nodes:pe(R),api:R,revision:D},O=H(r.getRows(),U(s.before,S,r.treeData===!0),S,r.treeData===!0)):A(),o===$&&(o=null,i=null,a&&!a.isDestroyed()&&a.view.refreshCells()),k()&&e.status==="saving"&&m({...e,status:"idle",plan:null}),L(),me(O)};try{r.applyRows(s.after),F=U(r.getRows(),S,r.treeData===!0),q=pe(R);let D=r.getRows(),O=q[0]?.node;if(i=R&&O?()=>!R.isDestroyed()&&R.rows.getById(O.id)===O:()=>r.getRows()===D,m({...e,status:"saving",error:null,plan:s}),!ne())return s;let B=Ze(await Oe(Promise.resolve(r.save?.(s.intent,{signal:$.signal,plan:s,operation:p,operations:w})),$.signal));return ne()&&(ye=!0,re=B??W,l===Le?f.commit(p,b):A(),m({...e,status:"saved",revision:re})),s}catch(D){throw ke(D),D}finally{Ge()}},we=async(s,p)=>{p!==h&&(p=void 0),h!==p&&g();let w=z(s);w.changed||g(p);let b=w.changed?Te(w,r,r.treeData===!0):[];return he(w,"move",[w.intent],{plan:w,inverse:b},p)},Ce=s=>we(s),ge=async s=>{if(g(),L(),n||o)throw new Error("[MachTable] Row ordering is unavailable while disposed or saving.");let p=f.peek(s);if(!p)throw new Error(`[MachTable] Nothing to ${s}.`);let w=(s==="undo"?p.inverse:[p.plan.intent]).map(N=>({...N,expectedRevision:v()})),b=r.getRows(),T=s==="undo"?p.plan.before:p.plan.after;Ie(b,T,w,r,r.treeData===!0);let R={before:b,after:T,intent:w[0],rowIds:p.plan.rowIds,changed:!0};return he(R,s,w,p)},Me=s=>{try{if(n||o)return!1;let p=r.getRows(),w=v();if(w!==void 0&&s.expectedRevision!==void 0&&s.expectedRevision!==w)return!1;let b=I?.rowIds===s.rowIds?I.sources:JSON.stringify(s.rowIds.map(String));return(!I||I.rows!==p||I.revision!==w||I.sources!==b)&&(I={rows:p,revision:w,sources:b,rowIds:s.rowIds,validate:Re(p,s.rowIds,r,r.treeData===!0)}),I.rowIds=s.rowIds,I.validate(s),!0}catch(p){return p instanceof Error?p.message:!1}},Pe=s=>{let p=s.intent;if(s.applied||!p)return;G(s.api);let w=t,b=h?.intent===p?h:void 0;Promise.resolve().then(()=>we(Se(p),b)).catch(T=>{b&&b.generation!==t&&g(b),!n&&t===w&&e.status!=="saving"&&m({...e,status:T instanceof P?"conflict":"error",error:T})})},fe=s=>n?!1:(G(s),o?"Wait for the current row order to finish saving.":J(s)||"Save or discard edited rows before changing their order.");return{get state(){return L(),e},bindings:{applyRowDrag:!1,rowDragPolicy:{canDrag:({api:s})=>fe(s),canDrop:({intent:s,api:p})=>{let w=fe(p);if(w!==!0)return w;try{return Me(Se(s))}catch(b){return b instanceof Error?b.message:!1}},getRevision:v},onRowDragEnd:Pe},preview:z,move:Ce,undo:()=>ge("undo"),redo:()=>ge("redo"),subscribe(s){return n?()=>{}:(E.add(s),()=>{E.delete(s)})},dispose(){n=!0,t++,o?.abort(),o=null,i=null,d(),c(),g(),A(),a&&!a.isDestroyed()&&a.view.refreshCells(),a=null,I=null,E.clear(),e=Object.freeze({...e,status:"idle",error:null,plan:null,canUndo:!1,canRedo:!1})}}}0&&(module.exports={RowOrderConflictError,createRowOrderController,moveTreeNodes,reorderRows});
1
+ "use strict";var ae=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var qe=(r,e)=>{for(var t in e)ae(r,t,{get:e[t],enumerable:!0})},Be=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fe(e))!He.call(r,o)&&o!==t&&ae(r,o,{get:()=>e[o],enumerable:!(n=Ne(e,o))||n.enumerable});return r};var Ke=r=>Be(ae({},"__esModule",{value:!0}),r);var et={};qe(et,{RowOrderConflictError:()=>P,createRowOrderController:()=>Ae,moveTreeNodes:()=>J,reorderRows:()=>V});module.exports=Ke(et);var Ue=new Set(["__proto__","prototype","constructor"]);function Ye(r){return typeof r!="string"||r.length===0?!1:r.split(".").every(t=>t.length>0&&!Ue.has(t))}function X(r,e){if(r==null||!Ye(e))return;if(e.indexOf(".")<0)return r[e];let n=r,o=0;for(;o<e.length;){if(n==null)return;let i=e.indexOf(".",o);if(i<0){n=n[e.slice(o)];break}n=n[e.slice(o,i)],o=i+1}return n}function _e(r,e){let t=typeof e.rowKey=="function"?e.rowKey(r):X(r,e.rowKey);if(t==null||String(t).length===0)throw new Error("[MachTable] Row ordering requires a non-empty stable row key.");return String(t)}function ze(r,e){let t=r[e];if(t==null)return[];if(!Array.isArray(t))throw new Error(`[MachTable] Tree ordering expects an array at "${e}".`);return t}function Y(r,e,t,n){let o={entries:[],byId:new Map,byRow:new Map,children:new Map([[null,r]])},i=[...r].reverse().map(d=>({row:d,parentId:null,selectedAncestor:!1})),a=t.childrenKey??"children";for(;i.length;){let d=i.pop(),c=_e(d.row,t);if(o.byId.has(c))throw new Error(`[MachTable] Row ordering found duplicate or cyclic row key "${c}".`);let l=n?ze(d.row,a):[],h={...d,id:c,children:l};o.entries.push(h),o.byId.set(c,h),o.byRow.set(h.row,h),o.children.set(c,l);for(let f=l.length-1;f>=0;f--)i.push({row:l[f],parentId:c,selectedAncestor:d.selectedAncestor||e.has(c)})}return o}function $e(r){if(!["before","after","inside"].includes(r.position))throw new Error("[MachTable] Unknown row ordering position.");let e=[...new Set(r.rowIds.map(String))];if(!e.length)throw new Error("[MachTable] Row ordering requires at least one source row.");return{...r,rowIds:e,targetId:String(r.targetId)}}function se(r,e){for(let n of e)if(!r.byId.has(n))throw new Error(`[MachTable] Ordering source "${n}" is unavailable.`);let t=new Set(e);return{selected:t,moved:r.entries.filter(n=>t.has(n.id)&&!n.selectedAncestor)}}function be(r,e,t,n){let o=r.byId.get(t.targetId);if(!o)throw new Error(`[MachTable] Ordering target "${t.targetId}" is unavailable.`);if(e.selected.has(o.id)||o.selectedAncestor)throw new Error("[MachTable] A row cannot be moved into or relative to its own subtree.");let i=t.position==="inside"?o.id:o.parentId,a=i===null?null:r.byId.get(i).row;if(n.canMove)for(let d of e.moved){let c=d.parentId===null?null:r.byId.get(d.parentId).row,l=n.canMove({row:d.row,previousParent:c,parent:a,target:o.row,intent:t});if(l===!1||typeof l=="string")throw new Error(typeof l=="string"?l:"[MachTable] This row cannot be moved to the selected parent.")}return i}function Re(r,e,t,n){let o=[...new Set(e.map(String))];if(!o.length)throw new Error("[MachTable] Row ordering requires at least one source row.");let i=Y(r,new Set(o),t,n),a=se(i,o);return d=>{if(!n&&d.position==="inside")throw new Error("[MachTable] Flat rows cannot have child destinations.");be(i,a,d,t)}}function We(r,e,t,n){let o=new Set(e.map(l=>l.id)),i=new Map;for(let l of e)i.has(l.parentId)||i.set(l.parentId,r.children.get(l.parentId).filter(h=>!o.has(r.byRow.get(h).id)));let a=i.get(t)??r.children.get(t),d=a.findIndex(l=>l===r.byId.get(n.targetId).row),c=n.position==="inside"?a.length:d+ +(n.position==="after");return i.set(t,[...a.slice(0,c),...e.map(l=>l.row),...a.slice(c)]),i}function ve(r,e){return r.length===e.length&&r.every((t,n)=>t===e[n])}function je(r,e,t,n){let o=new Map,i=n.childrenKey??"children";for(let d=e.entries.length-1;d>=0;d--){let c=e.entries[d],h=(t.get(c.id)??c.children).map(f=>o.get(f)??f);ve(c.children,h)||o.set(c.row,{...c.row,[i]:h})}let a=(t.get(null)??r).map(d=>o.get(d)??d);return ve(r,a)?r:a}function Xe(r,e,t,n){let o=t.indexOf(e[0].row),i=o+e.length;return{...r,rowIds:e.map(a=>a.id),beforeId:o>0?n.byRow.get(t[o-1]).id:null,afterId:i<t.length?n.byRow.get(t[i]).id:null}}function Te(r,e,t){let n=Y(r.before,new Set(r.rowIds),e,t),o=new Map;for(let i of n.children.values())i.forEach((a,d)=>o.set(n.byRow.get(a).id,d));return se(n,r.rowIds).moved.reverse().map(i=>{let a=n.children.get(i.parentId),d=o.get(i.id),c=a[d+1];if(c)return{rowIds:[i.id],targetId:n.byRow.get(c).id,position:"before"};if(i.parentId!==null)return{rowIds:[i.id],targetId:i.parentId,position:"inside"};let l=a[d-1];if(!l)throw new Error("[MachTable] Row ordering cannot restore an isolated root.");return{rowIds:[i.id],targetId:n.byRow.get(l).id,position:"after"}})}function Ie(r,e,t,n,o){if(!n.canMove)return;let i=Y(r,new Set,n,o),a=Y(e,new Set,n,o);for(let d of t)for(let c of d.rowIds){let l=i.byId.get(c),h=a.byId.get(c),f=h.parentId===null?null:i.byId.get(h.parentId).row,O=l.parentId===null?null:i.byId.get(l.parentId).row,S=n.canMove({row:l.row,previousParent:O,parent:f,target:i.byId.get(d.targetId).row,intent:d});if(S===!1||typeof S=="string")throw new Error(typeof S=="string"?S:"[MachTable] This row cannot be restored to its previous parent.")}}function De(r,e,t,n){let o=$e(e);if(!n&&o.position==="inside")throw new Error("[MachTable] Flat rows cannot have child destinations.");let i=Y(r,new Set(o.rowIds),t,n),{moved:a,selected:d}=se(i,o.rowIds),c=be(i,{moved:a,selected:d},o,t),l=We(i,a,c,o),h=je(r,i,l,t),f=Xe(o,a,l.get(c),i);return{before:r,after:h,intent:f,rowIds:f.rowIds,changed:r!==h}}function V(r,e,t){return De(r,e,t,!1)}function J(r,e,t){return De(r,e,t,!0)}function de(r,e,t){let n=document.createElement(r);if(e&&(n.className=e),t)for(let o of Object.keys(t))n.setAttribute(o,t[o]);return n}function M(r,e,t){return r<e?e:r>t?t:r}var le=Symbol.for("mach-table.adapter.lifecycle.v1");function Q(r){return!r.isDestroyed()&&(r[le]?.canReplaceData()??!1)}function ce(r,e){let t=r[le]?.rowDrag;return t?.original===e&&t.policy===r.getOption("rowDragPolicy")}function ue(r,e){let t=r[le];if(!t)return()=>{};t.rowDrag?.activeInteraction?.destroy();let n={original:e,policy:r.getOption("rowDragPolicy"),factory:o=>(n.activeInteraction=e(o),n.activeInteraction)};return t.rowDrag=n,()=>{n.activeInteraction?.destroy(),t.rowDrag===n&&(t.rowDrag=void 0)}}function Oe(r,e){return new Promise((t,n)=>{let o=()=>n(Object.assign(new Error("[MachTable] Operation cancelled."),{name:"AbortError"}));if(r.then(t,n).finally(()=>e.removeEventListener("abort",o)),e.aborted){o();return}e.addEventListener("abort",o,{once:!0})})}function pe(r,e,t){return r.replace("{a}",String(e)).replace("{b}",String(t))}function Ve(r,e,t){return r&&e>.25&&e<.75?"inside":t}function xe(r,e){let t=0,n=r.length;for(;t<n;){let o=t+n>>>1;r[o]<e?t=o+1:n=o}return t}function Je(r,e,t,n,o,i){let a=r.getOption("locale")??{},d=e>1?pe(a.rowDragSelection??"\u5DF2\u9009 {a} \u884C \u2192 \u7B2C {b} \u884C",e,n+1):pe(a.rowDragPosition??"\u7B2C {a} \u884C \u2192 \u7B2C {b} \u884C",t+1,n+1),c=o==="inside"?a.rowDragInside??"\u79FB\u5165":o==="before"?a.rowDragBefore??"\u4E4B\u524D":a.rowDragAfter??"\u4E4B\u540E";return{text:`${d} \xB7 ${c}`,indicatorStyle:o==="inside"?`height:${i}px;background:color-mix(in srgb,var(--mach-primary) 12%,transparent);box-shadow:inset 0 0 0 1px var(--mach-primary)`:void 0}}function Qe(r,e,t){let n={parents:new Map,siblings:new Map([[null,[]]]),depths:new Map},o=[...r].reverse().map(a=>({row:a,parent:null,depth:0})),i=e.childrenKey??"children";for(;o.length;){let{row:a,parent:d,depth:c}=o.pop(),l=String(typeof e.rowKey=="function"?e.rowKey(a):X(a,e.rowKey));if(n.depths.has(l))throw new Error("[MachTable] Row ordering requires unique, acyclic row keys.");n.depths.set(l,c),n.siblings.get(d).push(l),n.siblings.set(l,[]),d!==null&&n.parents.set(l,d);let h=t?a[i]:void 0;if(h!=null&&!Array.isArray(h))throw new Error("[MachTable] Row ordering children must be an array.");for(let f=(h?.length??0)-1;f>=0;f--)o.push({row:h[f],parent:l,depth:c+1})}return n}function Ee(r,e,t,n,o,i){let a=new Map;r.rows.forEach(u=>{!u.loading&&!u.isDetail&&!u.isGroup&&u.data!=null&&a.set(u.id,u)});let d=Qe(t,n,o),c=new Set(e.selected?[...d.depths.keys()].filter(u=>a.get(u)?.selected):[e.id]),l=[...c],h=u=>{let g=u;for(;g!==void 0;){if(c.has(g))return!0;g=d.parents.get(g)}return!1},f=new Map,O=new Map;for(let[u,g]of d.siblings){let y=g.filter(m=>!c.has(m));f.set(u,y),y.forEach((m,T)=>O.set(m,T))}let S=new Map,A=new Set,x=[],E=[],q=0;r.rows.forEachDisplayed(u=>{A.add(u.id),h(u.id)&&x.push(u.rowIndex),q=u.rowIndex+1;let g=d.depths.get(u.id)??0;for(;E.length&&(d.depths.get(E[E.length-1].id)??0)>=g;)S.set(E.pop().id,u.rowIndex);d.siblings.get(u.id)?.length&&E.push(u)});for(let u of E)S.set(u.id,q);return{rowIds:l,isSource:h,validate:()=>{for(let u of l){let g=a.get(u);if(g.treeLoading)return!1;let y=r.getOption("rowDragPolicy")?.canDrag?.({node:g,api:r});if(y===!1||typeof y=="string")return y}return!0},resolve:({targetNode:u,position:g,fraction:y,height:m})=>{let T=Ve(o,y,g);if(h(u.id))return"Cannot target own subtree.";if(!o&&T==="inside")return!1;let k=T==="inside"?u.id:d.parents.get(u.id)??null,C=f.get(k)??[],B=T==="inside"?C.length:(O.get(u.id)??0)+ +(T==="after"),G=T==="before"?u.rowIndex:S.get(u.id)??u.rowIndex+1,$=G-xe(x,G)+xe(x,e.rowIndex);return{intent:{rowIds:l,targetId:u.id,position:T,beforeId:C[B-1]??null,afterId:C[B]??null,expectedRevision:i},indicatorIndex:T==="inside"?u.rowIndex:T==="after"?S.get(u.id):void 0,toIndex:G,targetIndex:$,...Je(r,l.length,e.rowIndex,u.rowIndex,T,m)}},keyboardTarget:u=>{let g=e.id;for(;c.has(d.parents.get(g)??"");)g=d.parents.get(g);let y=d.siblings.get(d.parents.get(g)??null)??[],m=y.indexOf(g)+u;for(;m>=0&&m<y.length;){let T=y[m];if(!h(T)&&A.has(T)&&a.has(T))return a.get(T);m+=u}}}}var Z=class{constructor(e){this.host=e;this.drag=null;this.t=0;this.r=0;this.s=e=>{let t=this.drag;if(!(!t||e.pointerId!==t.pointerId)){if(t.clientX=e.clientX,t.clientY=e.clientY,!t.active){if(Math.abs(e.clientY-t.startY)<5)return;t.active=!0,this.host.root.classList.add("mach-root--row-dragging"),this.host.root.querySelectorAll(".mach-row").forEach(n=>n.classList.toggle("mach-row--drag-source",this.sourceContains(n.dataset.id??"")))}this.d()}};this.h=()=>{if(this.t=0,!!this.drag?.active){if(!this.current()){this.destroy();return}this.c(),this.g()&&this.d()}};this.a=e=>{let t=this.drag;if(!(!t||e.pointerId!==t.pointerId)){t.clientX=e.clientX,t.clientY=e.clientY,t.active&&this.current()&&this.c(),this.u();try{t.active&&t.drop?.valid&&this.o(e.clientX,e.clientY)&&this.current()&&this.commitDrop(t.drop)}finally{this.release()}}};this.l=e=>{e.key==="Escape"&&(e.preventDefault(),this.destroy())};this.n=e=>{e.type==="pointercancel"&&e.pointerId!==this.drag?.pointerId||this.destroy()}}begin(e){let t=this.host.containers.map(o=>{let i=de("div","mach-row-drop-indicator");return i.hidden=!0,o.append(i),i}),n=de("div","mach-row-drag-preview");n.setAttribute("role","status"),n.hidden=!0,this.host.root.append(n),this.drag={startY:e.clientY,clientX:e.clientX,clientY:e.clientY,pointerId:e.pointerId,indicators:t,preview:n,drop:null,active:!1},window.addEventListener("pointermove",this.s),window.addEventListener("pointerup",this.a),window.addEventListener("pointercancel",this.n),window.addEventListener("keydown",this.l),window.addEventListener("blur",this.n)}draggingSource(e){return this.drag?.active===!0&&this.sourceContains(e)}focusHandle(e,t=()=>!0){this.r=requestAnimationFrame(()=>{this.r=0,t()&&[...this.host.root.querySelectorAll(".mach-row-drag-handle")].find(n=>n.closest(".mach-row")?.dataset.id===e)?.focus()})}d(){this.t||(this.t=requestAnimationFrame(this.h))}o(e,t,n=0){let o=this.host.body.getBoundingClientRect();return e>=o.left&&e<=o.right&&t>=o.top-n&&t<=o.bottom+n}g(){let e=this.drag;if(!e||!this.o(e.clientX,e.clientY,28))return!1;let t=this.host.viewport,n=t.getBoundingClientRect(),o=Math.min(36,n.height/3);if(o<=0)return!1;let i=e.clientY<n.top+o?-Math.ceil(14*M((n.top+o-e.clientY)/o,0,1)):Math.ceil(14*M((e.clientY-n.bottom+o)/o,0,1)),a=t.scrollTop;return t.scrollTop=M(a+i,0,Math.max(0,t.scrollHeight-t.clientHeight)),t.scrollTop!==a}c(){let e=this.drag;if(!e?.active)return;let t=e.clientY-this.host.viewport.getBoundingClientRect().top+this.host.viewport.scrollTop,n=this.describe(t);e.drop=n;let o=this.o(e.clientX,e.clientY);for(let a of e.indicators)a.hidden=!o||!n?.valid,n&&(a.dataset.dropPosition=n.position??"",a.style.cssText=n.style??"",a.style.transform=`translate3d(0, ${this.host.getRowTop(n.boundary)}px, 0)`);let i=this.host.root.getBoundingClientRect();e.preview.hidden=!1,e.preview.textContent=o?n?.text??this.outsideText():this.outsideText(),e.preview.style.transform=`translate3d(${M(e.clientX-i.left+16,8,Math.max(8,i.width-224))}px, ${M(e.clientY-i.top+16,8,Math.max(8,i.height-48))}px, 0)`}u(){let e=this.drag;this.drag=null,window.removeEventListener("pointermove",this.s),window.removeEventListener("pointerup",this.a),window.removeEventListener("pointercancel",this.n),window.removeEventListener("keydown",this.l),window.removeEventListener("blur",this.n),cancelAnimationFrame(this.t),this.t=0,this.host.root?.classList.remove("mach-root--row-dragging"),this.host.root?.querySelectorAll(".mach-row--drag-source").forEach(t=>t.classList.remove("mach-row--drag-source")),e?.indicators.forEach(t=>t.remove()),e?.preview.remove()}destroy(){this.u(),this.release(),cancelAnimationFrame(this.r),this.r=0}};var ee=class extends Z{constructor(t,n,o){super(t);this.bridge=t;this.prepare=n;this.requestFocus=o;this.scope=null;this.i=!1}e(t,n,o){try{return n()}catch(i){return this.scope&&(this.scope.failed=!0),this.bridge.report(i,t),o}}p(t){return this.e("prepare",()=>{let n=this.bridge.capture(t),o=this.prepare(t);return this.scope={node:t,from:t.rowIndex,guard:n,session:o,sourceDecision:!0,failed:!1},this.scope.sourceDecision=o.validate(),this.scope},null)}start(t,n){this.destroy(),this.p(n)&&this.current()&&this.begin(t)}moveWithKeyboard(t,n){this.destroy();let o=this.p(n);if(!(!o||!this.current())){this.i=!0;try{let i=t.key==="ArrowUp"?-1:1,a=this.e("keyboardTarget",()=>o.session.keyboardTarget(i),void 0);a&&this.commitDrop(this.destination(a,i<0?0:1))}finally{this.i=!1,this.release()}}}isSource(t){return this.draggingSource(t.id)}current(){return!!(this.scope&&!this.scope.failed&&this.scope.guard.current()&&this.bridge.api.rows.getById(this.scope.node.id)===this.scope.node)}sourceContains(t){return this.e("isSource",()=>this.scope?.session.isSource(t)??!1,!1)}release(){this.scope=null}outsideText(){return this.bridge.api.getOption("locale")?.rowDragOutside??"\u79FB\u56DE\u8868\u683C\u5185\u653E\u7F6E \xB7 Esc \u53D6\u6D88"}describe(t){let n=this.bridge.api,o=M(this.host.findRowAt(t),0,n.rows.getCount()-1),i=n.rows.getAt(o);if(i?.isDetail&&(i=n.rows.getById(i.masterId)),!i)return null;let a=this.host.getRowTop(i.rowIndex),d=this.host.getRowTop(i.rowIndex+1)-a;return this.destination(i,(t-a)/Math.max(1,d))}destination(t,n){let o=this.scope,i=n<.5?"before":"after",a=this.host.getRowTop(t.rowIndex+1)-this.host.getRowTop(t.rowIndex),d=this.e("resolve",()=>o.session.resolve({targetNode:t,position:i,fraction:n,height:a}),!1),c=typeof o.sourceDecision=="string"?o.sourceDecision:typeof d=="string"?d:"\u6B64\u4F4D\u7F6E\u4E0D\u53EF\u653E\u7F6E",l={node:t,fraction:n,boundary:t.rowIndex,valid:!1,text:c};if(!d||typeof d=="string"||o.sourceDecision!==!0||t.loading||t.treeLoading||t.isGroup)return l;l.intent=d.intent,l.position=d.intent.position,l.toIndex=d.toIndex,l.targetIndex=d.targetIndex,l.boundary=d.indicatorIndex??t.rowIndex+ +(d.intent.position==="after"),l.style=d.indicatorStyle,l.text=d.text??c;let h=this.e("canDrop",()=>this.bridge.api.getOption("rowDragPolicy")?.canDrop?.({node:o.node,api:this.bridge.api,targetNode:t,intent:d.intent})??!0,!1);return l.valid=h===!0,typeof h=="string"&&(l.text=h),l}commitDrop(t){let n=this.scope;if(!n||!this.current()||this.e("validate",()=>n.session.validate(),!1)!==!0||!this.current())return!1;let o=this.destination(t.node,t.fraction);return!o.valid||!o.intent||!this.current()?!1:(this.i&&this.requestFocus(o.intent,i=>this.focusHandle(n.node.id,i)),this.bridge.emit(n.node,n.from,o.toIndex,o.targetIndex,o.intent),!0)}};function _(r,e,t){let n=[],o=[...r].reverse().map(a=>({row:a,parent:null})),i=new Set;for(;o.length;){let a=o.pop();if(i.has(a.row))throw new Error("[MachTable] Installed order contains duplicate or cyclic rows.");i.add(a.row),n.push(a);let d=t?a.row[e]??[]:[];for(let c=d.length-1;c>=0;c--)o.push({row:d[c],parent:a.row})}return n}function H(r,e,t,n){try{let o=_(r,t,n);return o.length===e.length&&o.every((i,a)=>i.row===e[a].row&&i.parent===e[a].parent)}catch{return!1}}function he(r){let e=[];return r?.rows.forEach(t=>e.push({node:t,data:t.data})),e}function z(r,e){if(!r)return!0;if(r.isDestroyed())return!1;let t=0,n=!0;return r.rows.forEach(o=>{let i=e[t++];(i?.node!==o||i.data!==o.data)&&(n=!1)}),n&&t===e.length}var te=class{constructor(){this.entries=[];this.cursor=0}get canUndo(){return this.cursor>0}get canRedo(){return this.cursor<this.entries.length}peek(e){return this.entries[e==="undo"?this.cursor-1:this.cursor]}commit(e,t){e==="undo"?this.cursor--:e==="redo"?this.cursor++:(this.entries.splice(this.cursor),this.entries.push(t),this.entries.length>50&&this.entries.shift(),this.cursor=this.entries.length)}clear(){this.entries=[],this.cursor=0}};var P=class extends Error{constructor(t="The row order changed on the server. Reload before trying again.",n){super(t);this.serverRevision=n;this.name="RowOrderConflictError"}};function Ze(r){if(r?.status==="conflict")throw new P(r.message,r.revision);return r?.revision}function Se(r){if(r.targetId===null)throw new Error("[MachTable] Row ordering requires an existing destination.");return{...r,targetId:r.targetId}}function Ae(r){let e={status:"idle",error:null,revision:r.getRevision?.(),plan:null,canUndo:!1,canRedo:!1},t=0,n=!1,o=null,i=null,a=null,d=()=>{},c=()=>{},l=0,h=null,f=new te,O=null,S=new Set,A=r.childrenKey??"children",x=null,E=()=>{f.clear(),O=null},q=()=>{if(!o)return!1;let s=o;return t++,o=null,i=null,s.abort(),!0},u=(s=e.status)=>({canUndo:!n&&s!=="saving"&&f.canUndo,canRedo:!n&&s!=="saving"&&f.canRedo}),g=s=>{e=Object.freeze({...s,...u(s.status)}),a&&!a.isDestroyed()&&a.view.refreshCells();let p=[w=>r.onStateChange?.(w),...S];for(let w of p)try{w?.(e)}catch(v){console.error("[MachTable] Row order state observer failed",v)}},y=()=>r.getRevision?.()??e.revision,m=(s=h)=>{s?.release(),h===s&&(h=null)},T=()=>{!i||i()||(q(),E(),m(),g({...e,status:"idle",plan:null,error:null}))},k=s=>new ee(s,p=>Ee(s.api,p,r.getRows(),r,r.treeData===!0,y()),(p,w)=>{m();let v=document.activeElement,R=N=>{N.target!==v&&N.target!==document.body&&m(b)},b={api:s.api,intent:p,restore:w,generation:t+1,release:()=>document.removeEventListener("focusin",R,!0)};h=b,document.addEventListener("focusin",R,!0)}),C=()=>{T(),!o&&O&&(O.api!==a||O.revision!==y()||!z(a,O.nodes)||!H(r.getRows(),O.rows,A,r.treeData===!0))&&E();let s=u();(e.canUndo!==s.canUndo||e.canRedo!==s.canRedo)&&(e=Object.freeze({...e,...s}))},B=s=>{if(s===a){T(),ce(s,k)||(c(),c=ue(s,k));return}let p=q();d(),c(),m(),E(),a=s,c=ue(s,k),d=s.on("cellValueChanged",()=>{l++;let w=f.canUndo||f.canRedo;E(),w&&g({...e,status:o?"saving":"idle",plan:o?e.plan:null,error:null})}),p&&g({...e,status:"idle",plan:null,error:null})},G=s=>{if(C(),n)throw new Error("[MachTable] The row order controller is disposed.");if(o)throw new Error("[MachTable] A row order save is already in progress.");let p=y();if(p!==void 0&&s.expectedRevision!==void 0&&s.expectedRevision!==p)throw new P;let w={...s,expectedRevision:s.expectedRevision??p};return(r.treeData?J:V)(r.getRows(),w,r)},$=async(s,p,w,v,R)=>{if(!s.changed)return s;let b=a;if(b&&!Q(b))throw new Error("[MachTable] Save or discard edited rows before changing their order.");let N=++t;x=null;let W=new AbortController;o=W,i=null;let j=y(),Le=l,F=null,K=[],ye=!1,re=!1,ne=j,me=I=>{if(!R)return;if(!I||R!==h||R.api!==a){m(R);return}let D=O;R.restore(()=>{let ie=D!==null&&D===O&&D.revision===y()&&z(R.api,D.nodes)&&H(r.getRows(),D.rows,A,r.treeData===!0)&&h===R&&!n&&t===R.generation&&a===R.api&&ce(R.api,k);return m(R),ie})},L=()=>!n&&t===N,oe=()=>L()&&(!b||a===b&&!b.isDestroyed())&&F!==null&&y()===j&&z(b,K)&&H(r.getRows(),F,A,r.treeData===!0),ke=I=>{if(!oe()){L()&&!F&&g({...e,status:"error",error:I,plan:s});return}let D=!b||Q(b),U=D?I:Object.assign(new Error("[MachTable] Row order could not be saved. Automatic rollback was skipped to preserve new edits. Save or discard those edits, then reload the row order."),{cause:I});if(D){i=null;try{r.applyRows(s.before),re=!0}catch(ie){U=Object.assign(new Error("[MachTable] Row order could not be saved or restored. Reload the row order before trying again."),{cause:I,rollbackError:ie})}}L()&&(re||E(),g({...e,status:I instanceof P?"conflict":"error",error:U}))},Ge=()=>{if(!L()){me(!1);return}let I=y(),D=!1;ye&&L()&&(I===j||I===ne)&&z(b,K)&&H(r.getRows(),F,A,r.treeData===!0)?(O={rows:F,nodes:K,api:b,revision:I},D=!0):re&&L()?(O={rows:_(r.getRows(),A,r.treeData===!0),nodes:he(b),api:b,revision:I},D=H(r.getRows(),_(s.before,A,r.treeData===!0),A,r.treeData===!0)):E(),o===W&&(o=null,i=null,a&&!a.isDestroyed()&&a.view.refreshCells()),L()&&e.status==="saving"&&g({...e,status:"idle",plan:null}),C(),me(D)};try{r.applyRows(s.after),F=_(r.getRows(),A,r.treeData===!0),K=he(b);let I=r.getRows(),D=K[0]?.node;if(i=b&&D?()=>!b.isDestroyed()&&b.rows.getById(D.id)===D:()=>r.getRows()===I,g({...e,status:"saving",error:null,plan:s}),!oe())return s;let U=Ze(await Oe(Promise.resolve(r.save?.(s.intent,{signal:W.signal,plan:s,operation:p,operations:w})),W.signal));return oe()&&(ye=!0,ne=U??j,l===Le?f.commit(p,v):E(),g({...e,status:"saved",revision:ne})),s}catch(I){throw ke(I),I}finally{Ge()}},we=async(s,p)=>{p!==h&&(p=void 0),h!==p&&m();let w=G(s);w.changed||m(p);let v=w.changed?Te(w,r,r.treeData===!0):[];return $(w,"move",[w.intent],{plan:w,inverse:v},p)},Ce=s=>we(s),ge=async s=>{if(m(),C(),n||o)throw new Error("[MachTable] Row ordering is unavailable while disposed or saving.");let p=f.peek(s);if(!p)throw new Error(`[MachTable] Nothing to ${s}.`);let w=(s==="undo"?p.inverse:[p.plan.intent]).map(N=>({...N,expectedRevision:y()})),v=r.getRows(),R=s==="undo"?p.plan.before:p.plan.after;Ie(v,R,w,r,r.treeData===!0);let b={before:v,after:R,intent:w[0],rowIds:p.plan.rowIds,changed:!0};return $(b,s,w,p)},Me=s=>{try{if(n||o)return!1;let p=r.getRows(),w=y();if(w!==void 0&&s.expectedRevision!==void 0&&s.expectedRevision!==w)return!1;let v=x?.rowIds===s.rowIds?x.sources:JSON.stringify(s.rowIds.map(String));return(!x||x.rows!==p||x.revision!==w||x.sources!==v)&&(x={rows:p,revision:w,sources:v,rowIds:s.rowIds,validate:Re(p,s.rowIds,r,r.treeData===!0)}),x.rowIds=s.rowIds,x.validate(s),!0}catch(p){return p instanceof Error?p.message:!1}},Pe=s=>{let p=s.intent;if(s.applied||!p)return;B(s.api);let w=t,v=h?.intent===p?h:void 0;Promise.resolve().then(()=>we(Se(p),v)).catch(R=>{v&&v.generation!==t&&m(v),!n&&t===w&&e.status!=="saving"&&g({...e,status:R instanceof P?"conflict":"error",error:R})})},fe=s=>n?!1:(B(s),o?"Wait for the current row order to finish saving.":Q(s)||"Save or discard edited rows before changing their order.");return{get state(){return C(),e},bindings:{applyRowDrag:!1,rowDragPolicy:{canDrag:({api:s})=>fe(s),canDrop:({intent:s,api:p})=>{let w=fe(p);if(w!==!0)return w;try{return Me(Se(s))}catch(v){return v instanceof Error?v.message:!1}},getRevision:y},onRowDragEnd:Pe},preview:G,move:Ce,undo:()=>ge("undo"),redo:()=>ge("redo"),subscribe(s){return n?()=>{}:(S.add(s),()=>{S.delete(s)})},dispose(){n=!0,t++,o?.abort(),o=null,i=null,d(),c(),m(),E(),a&&!a.isDestroyed()&&a.view.refreshCells(),a=null,x=null,S.clear(),e=Object.freeze({...e,status:"idle",error:null,plan:null,canUndo:!1,canRedo:!1})}}}0&&(module.exports={RowOrderConflictError,createRowOrderController,moveTreeNodes,reorderRows});
package/dist/ordering.js CHANGED
@@ -1 +1 @@
1
- var ke=new Set(["__proto__","prototype","constructor"]);function Ge(r){return typeof r!="string"||r.length===0?!1:r.split(".").every(t=>t.length>0&&!ke.has(t))}function j(r,e){if(r==null||!Ge(e))return;if(e.indexOf(".")<0)return r[e];let n=r,o=0;for(;o<e.length;){if(n==null)return;let i=e.indexOf(".",o);if(i<0){n=n[e.slice(o)];break}n=n[e.slice(o,i)],o=i+1}return n}function Ne(r,e){let t=typeof e.rowKey=="function"?e.rowKey(r):j(r,e.rowKey);if(t==null||String(t).length===0)throw new Error("[MachTable] Row ordering requires a non-empty stable row key.");return String(t)}function Fe(r,e){let t=r[e];if(t==null)return[];if(!Array.isArray(t))throw new Error(`[MachTable] Tree ordering expects an array at "${e}".`);return t}function K(r,e,t,n){let o={entries:[],byId:new Map,byRow:new Map,children:new Map([[null,r]])},i=[...r].reverse().map(d=>({row:d,parentId:null,selectedAncestor:!1})),a=t.childrenKey??"children";for(;i.length;){let d=i.pop(),c=Ne(d.row,t);if(o.byId.has(c))throw new Error(`[MachTable] Row ordering found duplicate or cyclic row key "${c}".`);let l=n?Fe(d.row,a):[],h={...d,id:c,children:l};o.entries.push(h),o.byId.set(c,h),o.byRow.set(h.row,h),o.children.set(c,l);for(let f=l.length-1;f>=0;f--)i.push({row:l[f],parentId:c,selectedAncestor:d.selectedAncestor||e.has(c)})}return o}function He(r){if(!["before","after","inside"].includes(r.position))throw new Error("[MachTable] Unknown row ordering position.");let e=[...new Set(r.rowIds.map(String))];if(!e.length)throw new Error("[MachTable] Row ordering requires at least one source row.");return{...r,rowIds:e,targetId:String(r.targetId)}}function ne(r,e){for(let n of e)if(!r.byId.has(n))throw new Error(`[MachTable] Ordering source "${n}" is unavailable.`);let t=new Set(e);return{selected:t,moved:r.entries.filter(n=>t.has(n.id)&&!n.selectedAncestor)}}function ve(r,e,t,n){let o=r.byId.get(t.targetId);if(!o)throw new Error(`[MachTable] Ordering target "${t.targetId}" is unavailable.`);if(e.selected.has(o.id)||o.selectedAncestor)throw new Error("[MachTable] A row cannot be moved into or relative to its own subtree.");let i=t.position==="inside"?o.id:o.parentId,a=i===null?null:r.byId.get(i).row;if(n.canMove)for(let d of e.moved){let c=d.parentId===null?null:r.byId.get(d.parentId).row,l=n.canMove({row:d.row,previousParent:c,parent:a,target:o.row,intent:t});if(l===!1||typeof l=="string")throw new Error(typeof l=="string"?l:"[MachTable] This row cannot be moved to the selected parent.")}return i}function be(r,e,t,n){let o=[...new Set(e.map(String))];if(!o.length)throw new Error("[MachTable] Row ordering requires at least one source row.");let i=K(r,new Set(o),t,n),a=ne(i,o);return d=>{if(!n&&d.position==="inside")throw new Error("[MachTable] Flat rows cannot have child destinations.");ve(i,a,d,t)}}function qe(r,e,t,n){let o=new Set(e.map(l=>l.id)),i=new Map;for(let l of e)i.has(l.parentId)||i.set(l.parentId,r.children.get(l.parentId).filter(h=>!o.has(r.byRow.get(h).id)));let a=i.get(t)??r.children.get(t),d=a.findIndex(l=>l===r.byId.get(n.targetId).row),c=n.position==="inside"?a.length:d+ +(n.position==="after");return i.set(t,[...a.slice(0,c),...e.map(l=>l.row),...a.slice(c)]),i}function me(r,e){return r.length===e.length&&r.every((t,n)=>t===e[n])}function Be(r,e,t,n){let o=new Map,i=n.childrenKey??"children";for(let d=e.entries.length-1;d>=0;d--){let c=e.entries[d],h=(t.get(c.id)??c.children).map(f=>o.get(f)??f);me(c.children,h)||o.set(c.row,{...c.row,[i]:h})}let a=(t.get(null)??r).map(d=>o.get(d)??d);return me(r,a)?r:a}function Ke(r,e,t,n){let o=t.indexOf(e[0].row),i=o+e.length;return{...r,rowIds:e.map(a=>a.id),beforeId:o>0?n.byRow.get(t[o-1]).id:null,afterId:i<t.length?n.byRow.get(t[i]).id:null}}function Re(r,e,t){let n=K(r.before,new Set(r.rowIds),e,t),o=new Map;for(let i of n.children.values())i.forEach((a,d)=>o.set(n.byRow.get(a).id,d));return ne(n,r.rowIds).moved.reverse().map(i=>{let a=n.children.get(i.parentId),d=o.get(i.id),c=a[d+1];if(c)return{rowIds:[i.id],targetId:n.byRow.get(c).id,position:"before"};if(i.parentId!==null)return{rowIds:[i.id],targetId:i.parentId,position:"inside"};let l=a[d-1];if(!l)throw new Error("[MachTable] Row ordering cannot restore an isolated root.");return{rowIds:[i.id],targetId:n.byRow.get(l).id,position:"after"}})}function Te(r,e,t,n,o){if(!n.canMove)return;let i=K(r,new Set,n,o),a=K(e,new Set,n,o);for(let d of t)for(let c of d.rowIds){let l=i.byId.get(c),h=a.byId.get(c),f=h.parentId===null?null:i.byId.get(h.parentId).row,x=l.parentId===null?null:i.byId.get(l.parentId).row,E=n.canMove({row:l.row,previousParent:x,parent:f,target:i.byId.get(d.targetId).row,intent:d});if(E===!1||typeof E=="string")throw new Error(typeof E=="string"?E:"[MachTable] This row cannot be restored to its previous parent.")}}function Ie(r,e,t,n){let o=He(e);if(!n&&o.position==="inside")throw new Error("[MachTable] Flat rows cannot have child destinations.");let i=K(r,new Set(o.rowIds),t,n),{moved:a,selected:d}=ne(i,o.rowIds),c=ve(i,{moved:a,selected:d},o,t),l=qe(i,a,c,o),h=Be(r,i,l,t),f=Ke(o,a,l.get(c),i);return{before:r,after:h,intent:f,rowIds:f.rowIds,changed:r!==h}}function oe(r,e,t){return Ie(r,e,t,!1)}function ie(r,e,t){return Ie(r,e,t,!0)}function ae(r,e,t){let n=document.createElement(r);if(e&&(n.className=e),t)for(let o of Object.keys(t))n.setAttribute(o,t[o]);return n}function M(r,e,t){return r<e?e:r>t?t:r}var se=Symbol.for("mach-table.adapter.lifecycle.v1");function X(r){return!r.isDestroyed()&&(r[se]?.canReplaceData()??!1)}function de(r,e){let t=r[se]?.rowDrag;return t?.original===e&&t.policy===r.getOption("rowDragPolicy")}function le(r,e){let t=r[se];if(!t)return()=>{};t.rowDrag?.activeInteraction?.destroy();let n={original:e,policy:r.getOption("rowDragPolicy"),factory:o=>(n.activeInteraction=e(o),n.activeInteraction)};return t.rowDrag=n,()=>{n.activeInteraction?.destroy(),t.rowDrag===n&&(t.rowDrag=void 0)}}function De(r,e){return new Promise((t,n)=>{let o=()=>n(Object.assign(new Error("[MachTable] Operation cancelled."),{name:"AbortError"}));if(r.then(t,n).finally(()=>e.removeEventListener("abort",o)),e.aborted){o();return}e.addEventListener("abort",o,{once:!0})})}function ce(r,e,t){return r.replace("{a}",String(e)).replace("{b}",String(t))}function Ue(r,e,t){return r&&e>.25&&e<.75?"inside":t}function Oe(r,e){let t=0,n=r.length;for(;t<n;){let o=t+n>>>1;r[o]<e?t=o+1:n=o}return t}function Ye(r,e,t,n,o,i){let a=r.getOption("locale")??{},d=e>1?ce(a.rowDragSelection??"\u5DF2\u9009 {a} \u884C \u2192 \u7B2C {b} \u884C",e,n+1):ce(a.rowDragPosition??"\u7B2C {a} \u884C \u2192 \u7B2C {b} \u884C",t+1,n+1),c=o==="inside"?a.rowDragInside??"\u79FB\u5165":o==="before"?a.rowDragBefore??"\u4E4B\u524D":a.rowDragAfter??"\u4E4B\u540E";return{text:`${d} \xB7 ${c}`,indicatorStyle:o==="inside"?`height:${i}px;background:color-mix(in srgb,var(--mach-primary) 12%,transparent);box-shadow:inset 0 0 0 1px var(--mach-primary)`:void 0}}function _e(r,e,t){let n={parents:new Map,siblings:new Map([[null,[]]]),depths:new Map},o=[...r].reverse().map(a=>({row:a,parent:null,depth:0})),i=e.childrenKey??"children";for(;o.length;){let{row:a,parent:d,depth:c}=o.pop(),l=String(typeof e.rowKey=="function"?e.rowKey(a):j(a,e.rowKey));if(n.depths.has(l))throw new Error("[MachTable] Row ordering requires unique, acyclic row keys.");n.depths.set(l,c),n.siblings.get(d).push(l),n.siblings.set(l,[]),d!==null&&n.parents.set(l,d);let h=t?a[i]:void 0;if(h!=null&&!Array.isArray(h))throw new Error("[MachTable] Row ordering children must be an array.");for(let f=(h?.length??0)-1;f>=0;f--)o.push({row:h[f],parent:l,depth:c+1})}return n}function xe(r,e,t,n,o,i){let a=new Map;r.rows.forEach(u=>{!u.loading&&!u.isDetail&&!u.isGroup&&u.data!=null&&a.set(u.id,u)});let d=_e(t,n,o),c=new Set(e.selected?[...d.depths.keys()].filter(u=>a.get(u)?.selected):[e.id]),l=[...c],h=u=>{let y=u;for(;y!==void 0;){if(c.has(y))return!0;y=d.parents.get(y)}return!1},f=new Map,x=new Map;for(let[u,y]of d.siblings){let m=y.filter(v=>!c.has(v));f.set(u,m),m.forEach((v,g)=>x.set(v,g))}let E=new Map,S=[],I=[],A=0;r.rows.forEachDisplayed(u=>{h(u.id)&&S.push(u.rowIndex),A=u.rowIndex+1;let y=d.depths.get(u.id)??0;for(;I.length&&(d.depths.get(I[I.length-1].id)??0)>=y;)E.set(I.pop().id,u.rowIndex);d.siblings.get(u.id)?.length&&I.push(u)});for(let u of I)E.set(u.id,A);return{rowIds:l,isSource:h,validate:()=>{for(let u of l){let y=a.get(u);if(y.treeLoading)return!1;let m=r.getOption("rowDragPolicy")?.canDrag?.({node:y,api:r});if(m===!1||typeof m=="string")return m}return!0},resolve:({targetNode:u,position:y,fraction:m,height:v})=>{let g=Ue(o,m,y);if(h(u.id))return"Cannot target own subtree.";if(!o&&g==="inside")return!1;let _=g==="inside"?u.id:d.parents.get(u.id)??null,C=f.get(_)??[],P=g==="inside"?C.length:(x.get(u.id)??0)+ +(g==="after"),G=g==="before"?u.rowIndex:E.get(u.id)??u.rowIndex+1,z=G-Oe(S,G)+Oe(S,e.rowIndex);return{intent:{rowIds:l,targetId:u.id,position:g,beforeId:C[P-1]??null,afterId:C[P]??null,expectedRevision:i},indicatorIndex:g==="inside"?u.rowIndex:g==="after"?E.get(u.id):void 0,toIndex:G,targetIndex:z,...Ye(r,l.length,e.rowIndex,u.rowIndex,g,v)}},keyboardTarget:u=>{let y=e.id;for(;c.has(d.parents.get(y)??"");)y=d.parents.get(y);let m=d.siblings.get(d.parents.get(y)??null)??[],v=m.indexOf(y)+u;for(;v>=0&&v<m.length;){let g=m[v];if(!h(g)&&a.has(g))return a.get(g);v+=u}}}}var V=class{constructor(e){this.host=e;this.drag=null;this.t=0;this.r=0;this.s=e=>{let t=this.drag;if(!(!t||e.pointerId!==t.pointerId)){if(t.clientX=e.clientX,t.clientY=e.clientY,!t.active){if(Math.abs(e.clientY-t.startY)<5)return;t.active=!0,this.host.root.classList.add("mach-root--row-dragging"),this.host.root.querySelectorAll(".mach-row").forEach(n=>n.classList.toggle("mach-row--drag-source",this.sourceContains(n.dataset.id??"")))}this.d()}};this.h=()=>{if(this.t=0,!!this.drag?.active){if(!this.current()){this.destroy();return}this.c(),this.g()&&this.d()}};this.a=e=>{let t=this.drag;if(!(!t||e.pointerId!==t.pointerId)){t.clientX=e.clientX,t.clientY=e.clientY,t.active&&this.current()&&this.c(),this.u();try{t.active&&t.drop?.valid&&this.o(e.clientX,e.clientY)&&this.current()&&this.commitDrop(t.drop)}finally{this.release()}}};this.l=e=>{e.key==="Escape"&&(e.preventDefault(),this.destroy())};this.n=e=>{e.type==="pointercancel"&&e.pointerId!==this.drag?.pointerId||this.destroy()}}begin(e){let t=this.host.containers.map(o=>{let i=ae("div","mach-row-drop-indicator");return i.hidden=!0,o.append(i),i}),n=ae("div","mach-row-drag-preview");n.setAttribute("role","status"),n.hidden=!0,this.host.root.append(n),this.drag={startY:e.clientY,clientX:e.clientX,clientY:e.clientY,pointerId:e.pointerId,indicators:t,preview:n,drop:null,active:!1},window.addEventListener("pointermove",this.s),window.addEventListener("pointerup",this.a),window.addEventListener("pointercancel",this.n),window.addEventListener("keydown",this.l),window.addEventListener("blur",this.n)}draggingSource(e){return this.drag?.active===!0&&this.sourceContains(e)}focusHandle(e,t=()=>!0){this.r=requestAnimationFrame(()=>{this.r=0,t()&&[...this.host.root.querySelectorAll(".mach-row-drag-handle")].find(n=>n.closest(".mach-row")?.dataset.id===e)?.focus()})}d(){this.t||(this.t=requestAnimationFrame(this.h))}o(e,t,n=0){let o=this.host.body.getBoundingClientRect();return e>=o.left&&e<=o.right&&t>=o.top-n&&t<=o.bottom+n}g(){let e=this.drag;if(!e||!this.o(e.clientX,e.clientY,28))return!1;let t=this.host.viewport,n=t.getBoundingClientRect(),o=Math.min(36,n.height/3);if(o<=0)return!1;let i=e.clientY<n.top+o?-Math.ceil(14*M((n.top+o-e.clientY)/o,0,1)):Math.ceil(14*M((e.clientY-n.bottom+o)/o,0,1)),a=t.scrollTop;return t.scrollTop=M(a+i,0,Math.max(0,t.scrollHeight-t.clientHeight)),t.scrollTop!==a}c(){let e=this.drag;if(!e?.active)return;let t=e.clientY-this.host.viewport.getBoundingClientRect().top+this.host.viewport.scrollTop,n=this.describe(t);e.drop=n;let o=this.o(e.clientX,e.clientY);for(let a of e.indicators)a.hidden=!o||!n?.valid,n&&(a.dataset.dropPosition=n.position??"",a.style.cssText=n.style??"",a.style.transform=`translate3d(0, ${this.host.getRowTop(n.boundary)}px, 0)`);let i=this.host.root.getBoundingClientRect();e.preview.hidden=!1,e.preview.textContent=o?n?.text??this.outsideText():this.outsideText(),e.preview.style.transform=`translate3d(${M(e.clientX-i.left+16,8,Math.max(8,i.width-224))}px, ${M(e.clientY-i.top+16,8,Math.max(8,i.height-48))}px, 0)`}u(){let e=this.drag;this.drag=null,window.removeEventListener("pointermove",this.s),window.removeEventListener("pointerup",this.a),window.removeEventListener("pointercancel",this.n),window.removeEventListener("keydown",this.l),window.removeEventListener("blur",this.n),cancelAnimationFrame(this.t),this.t=0,this.host.root?.classList.remove("mach-root--row-dragging"),this.host.root?.querySelectorAll(".mach-row--drag-source").forEach(t=>t.classList.remove("mach-row--drag-source")),e?.indicators.forEach(t=>t.remove()),e?.preview.remove()}destroy(){this.u(),this.release(),cancelAnimationFrame(this.r),this.r=0}};var J=class extends V{constructor(t,n,o){super(t);this.bridge=t;this.prepare=n;this.requestFocus=o;this.scope=null;this.i=!1}e(t,n,o){try{return n()}catch(i){return this.scope&&(this.scope.failed=!0),this.bridge.report(i,t),o}}p(t){return this.e("prepare",()=>{let n=this.bridge.capture(t),o=this.prepare(t);return this.scope={node:t,from:t.rowIndex,guard:n,session:o,sourceDecision:!0,failed:!1},this.scope.sourceDecision=o.validate(),this.scope},null)}start(t,n){this.destroy(),this.p(n)&&this.current()&&this.begin(t)}moveWithKeyboard(t,n){this.destroy();let o=this.p(n);if(!(!o||!this.current())){this.i=!0;try{let i=t.key==="ArrowUp"?-1:1,a=this.e("keyboardTarget",()=>o.session.keyboardTarget(i),void 0);a&&this.commitDrop(this.destination(a,i<0?0:1))}finally{this.i=!1,this.release()}}}isSource(t){return this.draggingSource(t.id)}current(){return!!(this.scope&&!this.scope.failed&&this.scope.guard.current()&&this.bridge.api.rows.getById(this.scope.node.id)===this.scope.node)}sourceContains(t){return this.e("isSource",()=>this.scope?.session.isSource(t)??!1,!1)}release(){this.scope=null}outsideText(){return this.bridge.api.getOption("locale")?.rowDragOutside??"\u79FB\u56DE\u8868\u683C\u5185\u653E\u7F6E \xB7 Esc \u53D6\u6D88"}describe(t){let n=this.bridge.api,o=M(this.host.findRowAt(t),0,n.rows.getCount()-1),i=n.rows.getAt(o);if(i?.isDetail&&(i=n.rows.getById(i.masterId)),!i)return null;let a=this.host.getRowTop(i.rowIndex),d=this.host.getRowTop(i.rowIndex+1)-a;return this.destination(i,(t-a)/Math.max(1,d))}destination(t,n){let o=this.scope,i=n<.5?"before":"after",a=this.host.getRowTop(t.rowIndex+1)-this.host.getRowTop(t.rowIndex),d=this.e("resolve",()=>o.session.resolve({targetNode:t,position:i,fraction:n,height:a}),!1),c=typeof o.sourceDecision=="string"?o.sourceDecision:typeof d=="string"?d:"\u6B64\u4F4D\u7F6E\u4E0D\u53EF\u653E\u7F6E",l={node:t,fraction:n,boundary:t.rowIndex,valid:!1,text:c};if(!d||typeof d=="string"||o.sourceDecision!==!0||t.loading||t.treeLoading||t.isGroup)return l;l.intent=d.intent,l.position=d.intent.position,l.toIndex=d.toIndex,l.targetIndex=d.targetIndex,l.boundary=d.indicatorIndex??t.rowIndex+ +(d.intent.position==="after"),l.style=d.indicatorStyle,l.text=d.text??c;let h=this.e("canDrop",()=>this.bridge.api.getOption("rowDragPolicy")?.canDrop?.({node:o.node,api:this.bridge.api,targetNode:t,intent:d.intent})??!0,!1);return l.valid=h===!0,typeof h=="string"&&(l.text=h),l}commitDrop(t){let n=this.scope;if(!n||!this.current()||this.e("validate",()=>n.session.validate(),!1)!==!0||!this.current())return!1;let o=this.destination(t.node,t.fraction);return!o.valid||!o.intent||!this.current()?!1:(this.i&&this.requestFocus(o.intent,i=>this.focusHandle(n.node.id,i)),this.bridge.emit(n.node,n.from,o.toIndex,o.targetIndex,o.intent),!0)}};function U(r,e,t){let n=[],o=[...r].reverse().map(a=>({row:a,parent:null})),i=new Set;for(;o.length;){let a=o.pop();if(i.has(a.row))throw new Error("[MachTable] Installed order contains duplicate or cyclic rows.");i.add(a.row),n.push(a);let d=t?a.row[e]??[]:[];for(let c=d.length-1;c>=0;c--)o.push({row:d[c],parent:a.row})}return n}function H(r,e,t,n){try{let o=U(r,t,n);return o.length===e.length&&o.every((i,a)=>i.row===e[a].row&&i.parent===e[a].parent)}catch{return!1}}function ue(r){let e=[];return r?.rows.forEach(t=>e.push({node:t,data:t.data})),e}function Y(r,e){if(!r)return!0;if(r.isDestroyed())return!1;let t=0,n=!0;return r.rows.forEach(o=>{let i=e[t++];(i?.node!==o||i.data!==o.data)&&(n=!1)}),n&&t===e.length}var Q=class{constructor(){this.entries=[];this.cursor=0}get canUndo(){return this.cursor>0}get canRedo(){return this.cursor<this.entries.length}peek(e){return this.entries[e==="undo"?this.cursor-1:this.cursor]}commit(e,t){e==="undo"?this.cursor--:e==="redo"?this.cursor++:(this.entries.splice(this.cursor),this.entries.push(t),this.entries.length>50&&this.entries.shift(),this.cursor=this.entries.length)}clear(){this.entries=[],this.cursor=0}};var k=class extends Error{constructor(t="The row order changed on the server. Reload before trying again.",n){super(t);this.serverRevision=n;this.name="RowOrderConflictError"}};function ze(r){if(r?.status==="conflict")throw new k(r.message,r.revision);return r?.revision}function Ee(r){if(r.targetId===null)throw new Error("[MachTable] Row ordering requires an existing destination.");return{...r,targetId:r.targetId}}function $e(r){let e={status:"idle",error:null,revision:r.getRevision?.(),plan:null,canUndo:!1,canRedo:!1},t=0,n=!1,o=null,i=null,a=null,d=()=>{},c=()=>{},l=0,h=null,f=new Q,x=null,E=new Set,S=r.childrenKey??"children",I=null,A=()=>{f.clear(),x=null},u=()=>{if(!o)return!1;let s=o;return t++,o=null,i=null,s.abort(),!0},y=(s=e.status)=>({canUndo:!n&&s!=="saving"&&f.canUndo,canRedo:!n&&s!=="saving"&&f.canRedo}),m=s=>{e=Object.freeze({...s,...y(s.status)}),a&&!a.isDestroyed()&&a.view.refreshCells();let p=[w=>r.onStateChange?.(w),...E];for(let w of p)try{w?.(e)}catch(b){console.error("[MachTable] Row order state observer failed",b)}},v=()=>r.getRevision?.()??e.revision,g=(s=h)=>{s?.release(),h===s&&(h=null)},_=()=>{!i||i()||(u(),A(),g(),m({...e,status:"idle",plan:null,error:null}))},C=s=>new J(s,p=>xe(s.api,p,r.getRows(),r,r.treeData===!0,v()),(p,w)=>{g();let b=document.activeElement,T=N=>{N.target!==b&&N.target!==document.body&&g(R)},R={api:s.api,intent:p,restore:w,generation:t+1,release:()=>document.removeEventListener("focusin",T,!0)};h=R,document.addEventListener("focusin",T,!0)}),P=()=>{_(),!o&&x&&(x.api!==a||x.revision!==v()||!Y(a,x.nodes)||!H(r.getRows(),x.rows,S,r.treeData===!0))&&A();let s=y();(e.canUndo!==s.canUndo||e.canRedo!==s.canRedo)&&(e=Object.freeze({...e,...s}))},G=s=>{if(s===a){_(),de(s,C)||(c(),c=le(s,C));return}let p=u();d(),c(),g(),A(),a=s,c=le(s,C),d=s.on("cellValueChanged",()=>{l++;let w=f.canUndo||f.canRedo;A(),w&&m({...e,status:o?"saving":"idle",plan:o?e.plan:null,error:null})}),p&&m({...e,status:"idle",plan:null,error:null})},z=s=>{if(P(),n)throw new Error("[MachTable] The row order controller is disposed.");if(o)throw new Error("[MachTable] A row order save is already in progress.");let p=v();if(p!==void 0&&s.expectedRevision!==void 0&&s.expectedRevision!==p)throw new k;let w={...s,expectedRevision:s.expectedRevision??p};return(r.treeData?ie:oe)(r.getRows(),w,r)},pe=async(s,p,w,b,T)=>{if(!s.changed)return s;let R=a;if(R&&!X(R))throw new Error("[MachTable] Save or discard edited rows before changing their order.");let N=++t;I=null;let $=new AbortController;o=$,i=null;let W=v(),Me=l,F=null,q=[],fe=!1,Z=!1,ee=W,ye=D=>{if(!T)return;if(!D||T!==h||T.api!==a){g(T);return}let O=x;T.restore(()=>{let re=O!==null&&O===x&&O.revision===v()&&Y(T.api,O.nodes)&&H(r.getRows(),O.rows,S,r.treeData===!0)&&h===T&&!n&&t===T.generation&&a===T.api&&de(T.api,C);return g(T),re})},L=()=>!n&&t===N,te=()=>L()&&(!R||a===R&&!R.isDestroyed())&&F!==null&&v()===W&&Y(R,q)&&H(r.getRows(),F,S,r.treeData===!0),Pe=D=>{if(!te()){L()&&!F&&m({...e,status:"error",error:D,plan:s});return}let O=!R||X(R),B=O?D:Object.assign(new Error("[MachTable] Row order could not be saved. Automatic rollback was skipped to preserve new edits. Save or discard those edits, then reload the row order."),{cause:D});if(O){i=null;try{r.applyRows(s.before),Z=!0}catch(re){B=Object.assign(new Error("[MachTable] Row order could not be saved or restored. Reload the row order before trying again."),{cause:D,rollbackError:re})}}L()&&(Z||A(),m({...e,status:D instanceof k?"conflict":"error",error:B}))},Le=()=>{if(!L()){ye(!1);return}let D=v(),O=!1;fe&&L()&&(D===W||D===ee)&&Y(R,q)&&H(r.getRows(),F,S,r.treeData===!0)?(x={rows:F,nodes:q,api:R,revision:D},O=!0):Z&&L()?(x={rows:U(r.getRows(),S,r.treeData===!0),nodes:ue(R),api:R,revision:D},O=H(r.getRows(),U(s.before,S,r.treeData===!0),S,r.treeData===!0)):A(),o===$&&(o=null,i=null,a&&!a.isDestroyed()&&a.view.refreshCells()),L()&&e.status==="saving"&&m({...e,status:"idle",plan:null}),P(),ye(O)};try{r.applyRows(s.after),F=U(r.getRows(),S,r.treeData===!0),q=ue(R);let D=r.getRows(),O=q[0]?.node;if(i=R&&O?()=>!R.isDestroyed()&&R.rows.getById(O.id)===O:()=>r.getRows()===D,m({...e,status:"saving",error:null,plan:s}),!te())return s;let B=ze(await De(Promise.resolve(r.save?.(s.intent,{signal:$.signal,plan:s,operation:p,operations:w})),$.signal));return te()&&(fe=!0,ee=B??W,l===Me?f.commit(p,b):A(),m({...e,status:"saved",revision:ee})),s}catch(D){throw Pe(D),D}finally{Le()}},he=async(s,p)=>{p!==h&&(p=void 0),h!==p&&g();let w=z(s);w.changed||g(p);let b=w.changed?Re(w,r,r.treeData===!0):[];return pe(w,"move",[w.intent],{plan:w,inverse:b},p)},Se=s=>he(s),we=async s=>{if(g(),P(),n||o)throw new Error("[MachTable] Row ordering is unavailable while disposed or saving.");let p=f.peek(s);if(!p)throw new Error(`[MachTable] Nothing to ${s}.`);let w=(s==="undo"?p.inverse:[p.plan.intent]).map(N=>({...N,expectedRevision:v()})),b=r.getRows(),T=s==="undo"?p.plan.before:p.plan.after;Te(b,T,w,r,r.treeData===!0);let R={before:b,after:T,intent:w[0],rowIds:p.plan.rowIds,changed:!0};return pe(R,s,w,p)},Ae=s=>{try{if(n||o)return!1;let p=r.getRows(),w=v();if(w!==void 0&&s.expectedRevision!==void 0&&s.expectedRevision!==w)return!1;let b=I?.rowIds===s.rowIds?I.sources:JSON.stringify(s.rowIds.map(String));return(!I||I.rows!==p||I.revision!==w||I.sources!==b)&&(I={rows:p,revision:w,sources:b,rowIds:s.rowIds,validate:be(p,s.rowIds,r,r.treeData===!0)}),I.rowIds=s.rowIds,I.validate(s),!0}catch(p){return p instanceof Error?p.message:!1}},Ce=s=>{let p=s.intent;if(s.applied||!p)return;G(s.api);let w=t,b=h?.intent===p?h:void 0;Promise.resolve().then(()=>he(Ee(p),b)).catch(T=>{b&&b.generation!==t&&g(b),!n&&t===w&&e.status!=="saving"&&m({...e,status:T instanceof k?"conflict":"error",error:T})})},ge=s=>n?!1:(G(s),o?"Wait for the current row order to finish saving.":X(s)||"Save or discard edited rows before changing their order.");return{get state(){return P(),e},bindings:{applyRowDrag:!1,rowDragPolicy:{canDrag:({api:s})=>ge(s),canDrop:({intent:s,api:p})=>{let w=ge(p);if(w!==!0)return w;try{return Ae(Ee(s))}catch(b){return b instanceof Error?b.message:!1}},getRevision:v},onRowDragEnd:Ce},preview:z,move:Se,undo:()=>we("undo"),redo:()=>we("redo"),subscribe(s){return n?()=>{}:(E.add(s),()=>{E.delete(s)})},dispose(){n=!0,t++,o?.abort(),o=null,i=null,d(),c(),g(),A(),a&&!a.isDestroyed()&&a.view.refreshCells(),a=null,I=null,E.clear(),e=Object.freeze({...e,status:"idle",error:null,plan:null,canUndo:!1,canRedo:!1})}}}export{k as RowOrderConflictError,$e as createRowOrderController,ie as moveTreeNodes,oe as reorderRows};
1
+ var ke=new Set(["__proto__","prototype","constructor"]);function Ge(r){return typeof r!="string"||r.length===0?!1:r.split(".").every(t=>t.length>0&&!ke.has(t))}function X(r,e){if(r==null||!Ge(e))return;if(e.indexOf(".")<0)return r[e];let n=r,o=0;for(;o<e.length;){if(n==null)return;let i=e.indexOf(".",o);if(i<0){n=n[e.slice(o)];break}n=n[e.slice(o,i)],o=i+1}return n}function Ne(r,e){let t=typeof e.rowKey=="function"?e.rowKey(r):X(r,e.rowKey);if(t==null||String(t).length===0)throw new Error("[MachTable] Row ordering requires a non-empty stable row key.");return String(t)}function Fe(r,e){let t=r[e];if(t==null)return[];if(!Array.isArray(t))throw new Error(`[MachTable] Tree ordering expects an array at "${e}".`);return t}function Y(r,e,t,n){let o={entries:[],byId:new Map,byRow:new Map,children:new Map([[null,r]])},i=[...r].reverse().map(d=>({row:d,parentId:null,selectedAncestor:!1})),a=t.childrenKey??"children";for(;i.length;){let d=i.pop(),c=Ne(d.row,t);if(o.byId.has(c))throw new Error(`[MachTable] Row ordering found duplicate or cyclic row key "${c}".`);let l=n?Fe(d.row,a):[],h={...d,id:c,children:l};o.entries.push(h),o.byId.set(c,h),o.byRow.set(h.row,h),o.children.set(c,l);for(let f=l.length-1;f>=0;f--)i.push({row:l[f],parentId:c,selectedAncestor:d.selectedAncestor||e.has(c)})}return o}function He(r){if(!["before","after","inside"].includes(r.position))throw new Error("[MachTable] Unknown row ordering position.");let e=[...new Set(r.rowIds.map(String))];if(!e.length)throw new Error("[MachTable] Row ordering requires at least one source row.");return{...r,rowIds:e,targetId:String(r.targetId)}}function oe(r,e){for(let n of e)if(!r.byId.has(n))throw new Error(`[MachTable] Ordering source "${n}" is unavailable.`);let t=new Set(e);return{selected:t,moved:r.entries.filter(n=>t.has(n.id)&&!n.selectedAncestor)}}function ve(r,e,t,n){let o=r.byId.get(t.targetId);if(!o)throw new Error(`[MachTable] Ordering target "${t.targetId}" is unavailable.`);if(e.selected.has(o.id)||o.selectedAncestor)throw new Error("[MachTable] A row cannot be moved into or relative to its own subtree.");let i=t.position==="inside"?o.id:o.parentId,a=i===null?null:r.byId.get(i).row;if(n.canMove)for(let d of e.moved){let c=d.parentId===null?null:r.byId.get(d.parentId).row,l=n.canMove({row:d.row,previousParent:c,parent:a,target:o.row,intent:t});if(l===!1||typeof l=="string")throw new Error(typeof l=="string"?l:"[MachTable] This row cannot be moved to the selected parent.")}return i}function be(r,e,t,n){let o=[...new Set(e.map(String))];if(!o.length)throw new Error("[MachTable] Row ordering requires at least one source row.");let i=Y(r,new Set(o),t,n),a=oe(i,o);return d=>{if(!n&&d.position==="inside")throw new Error("[MachTable] Flat rows cannot have child destinations.");ve(i,a,d,t)}}function qe(r,e,t,n){let o=new Set(e.map(l=>l.id)),i=new Map;for(let l of e)i.has(l.parentId)||i.set(l.parentId,r.children.get(l.parentId).filter(h=>!o.has(r.byRow.get(h).id)));let a=i.get(t)??r.children.get(t),d=a.findIndex(l=>l===r.byId.get(n.targetId).row),c=n.position==="inside"?a.length:d+ +(n.position==="after");return i.set(t,[...a.slice(0,c),...e.map(l=>l.row),...a.slice(c)]),i}function me(r,e){return r.length===e.length&&r.every((t,n)=>t===e[n])}function Be(r,e,t,n){let o=new Map,i=n.childrenKey??"children";for(let d=e.entries.length-1;d>=0;d--){let c=e.entries[d],h=(t.get(c.id)??c.children).map(f=>o.get(f)??f);me(c.children,h)||o.set(c.row,{...c.row,[i]:h})}let a=(t.get(null)??r).map(d=>o.get(d)??d);return me(r,a)?r:a}function Ke(r,e,t,n){let o=t.indexOf(e[0].row),i=o+e.length;return{...r,rowIds:e.map(a=>a.id),beforeId:o>0?n.byRow.get(t[o-1]).id:null,afterId:i<t.length?n.byRow.get(t[i]).id:null}}function Re(r,e,t){let n=Y(r.before,new Set(r.rowIds),e,t),o=new Map;for(let i of n.children.values())i.forEach((a,d)=>o.set(n.byRow.get(a).id,d));return oe(n,r.rowIds).moved.reverse().map(i=>{let a=n.children.get(i.parentId),d=o.get(i.id),c=a[d+1];if(c)return{rowIds:[i.id],targetId:n.byRow.get(c).id,position:"before"};if(i.parentId!==null)return{rowIds:[i.id],targetId:i.parentId,position:"inside"};let l=a[d-1];if(!l)throw new Error("[MachTable] Row ordering cannot restore an isolated root.");return{rowIds:[i.id],targetId:n.byRow.get(l).id,position:"after"}})}function Te(r,e,t,n,o){if(!n.canMove)return;let i=Y(r,new Set,n,o),a=Y(e,new Set,n,o);for(let d of t)for(let c of d.rowIds){let l=i.byId.get(c),h=a.byId.get(c),f=h.parentId===null?null:i.byId.get(h.parentId).row,O=l.parentId===null?null:i.byId.get(l.parentId).row,S=n.canMove({row:l.row,previousParent:O,parent:f,target:i.byId.get(d.targetId).row,intent:d});if(S===!1||typeof S=="string")throw new Error(typeof S=="string"?S:"[MachTable] This row cannot be restored to its previous parent.")}}function Ie(r,e,t,n){let o=He(e);if(!n&&o.position==="inside")throw new Error("[MachTable] Flat rows cannot have child destinations.");let i=Y(r,new Set(o.rowIds),t,n),{moved:a,selected:d}=oe(i,o.rowIds),c=ve(i,{moved:a,selected:d},o,t),l=qe(i,a,c,o),h=Be(r,i,l,t),f=Ke(o,a,l.get(c),i);return{before:r,after:h,intent:f,rowIds:f.rowIds,changed:r!==h}}function ie(r,e,t){return Ie(r,e,t,!1)}function ae(r,e,t){return Ie(r,e,t,!0)}function se(r,e,t){let n=document.createElement(r);if(e&&(n.className=e),t)for(let o of Object.keys(t))n.setAttribute(o,t[o]);return n}function M(r,e,t){return r<e?e:r>t?t:r}var de=Symbol.for("mach-table.adapter.lifecycle.v1");function V(r){return!r.isDestroyed()&&(r[de]?.canReplaceData()??!1)}function le(r,e){let t=r[de]?.rowDrag;return t?.original===e&&t.policy===r.getOption("rowDragPolicy")}function ce(r,e){let t=r[de];if(!t)return()=>{};t.rowDrag?.activeInteraction?.destroy();let n={original:e,policy:r.getOption("rowDragPolicy"),factory:o=>(n.activeInteraction=e(o),n.activeInteraction)};return t.rowDrag=n,()=>{n.activeInteraction?.destroy(),t.rowDrag===n&&(t.rowDrag=void 0)}}function De(r,e){return new Promise((t,n)=>{let o=()=>n(Object.assign(new Error("[MachTable] Operation cancelled."),{name:"AbortError"}));if(r.then(t,n).finally(()=>e.removeEventListener("abort",o)),e.aborted){o();return}e.addEventListener("abort",o,{once:!0})})}function ue(r,e,t){return r.replace("{a}",String(e)).replace("{b}",String(t))}function Ue(r,e,t){return r&&e>.25&&e<.75?"inside":t}function Oe(r,e){let t=0,n=r.length;for(;t<n;){let o=t+n>>>1;r[o]<e?t=o+1:n=o}return t}function Ye(r,e,t,n,o,i){let a=r.getOption("locale")??{},d=e>1?ue(a.rowDragSelection??"\u5DF2\u9009 {a} \u884C \u2192 \u7B2C {b} \u884C",e,n+1):ue(a.rowDragPosition??"\u7B2C {a} \u884C \u2192 \u7B2C {b} \u884C",t+1,n+1),c=o==="inside"?a.rowDragInside??"\u79FB\u5165":o==="before"?a.rowDragBefore??"\u4E4B\u524D":a.rowDragAfter??"\u4E4B\u540E";return{text:`${d} \xB7 ${c}`,indicatorStyle:o==="inside"?`height:${i}px;background:color-mix(in srgb,var(--mach-primary) 12%,transparent);box-shadow:inset 0 0 0 1px var(--mach-primary)`:void 0}}function _e(r,e,t){let n={parents:new Map,siblings:new Map([[null,[]]]),depths:new Map},o=[...r].reverse().map(a=>({row:a,parent:null,depth:0})),i=e.childrenKey??"children";for(;o.length;){let{row:a,parent:d,depth:c}=o.pop(),l=String(typeof e.rowKey=="function"?e.rowKey(a):X(a,e.rowKey));if(n.depths.has(l))throw new Error("[MachTable] Row ordering requires unique, acyclic row keys.");n.depths.set(l,c),n.siblings.get(d).push(l),n.siblings.set(l,[]),d!==null&&n.parents.set(l,d);let h=t?a[i]:void 0;if(h!=null&&!Array.isArray(h))throw new Error("[MachTable] Row ordering children must be an array.");for(let f=(h?.length??0)-1;f>=0;f--)o.push({row:h[f],parent:l,depth:c+1})}return n}function xe(r,e,t,n,o,i){let a=new Map;r.rows.forEach(u=>{!u.loading&&!u.isDetail&&!u.isGroup&&u.data!=null&&a.set(u.id,u)});let d=_e(t,n,o),c=new Set(e.selected?[...d.depths.keys()].filter(u=>a.get(u)?.selected):[e.id]),l=[...c],h=u=>{let g=u;for(;g!==void 0;){if(c.has(g))return!0;g=d.parents.get(g)}return!1},f=new Map,O=new Map;for(let[u,g]of d.siblings){let y=g.filter(m=>!c.has(m));f.set(u,y),y.forEach((m,T)=>O.set(m,T))}let S=new Map,A=new Set,x=[],E=[],q=0;r.rows.forEachDisplayed(u=>{A.add(u.id),h(u.id)&&x.push(u.rowIndex),q=u.rowIndex+1;let g=d.depths.get(u.id)??0;for(;E.length&&(d.depths.get(E[E.length-1].id)??0)>=g;)S.set(E.pop().id,u.rowIndex);d.siblings.get(u.id)?.length&&E.push(u)});for(let u of E)S.set(u.id,q);return{rowIds:l,isSource:h,validate:()=>{for(let u of l){let g=a.get(u);if(g.treeLoading)return!1;let y=r.getOption("rowDragPolicy")?.canDrag?.({node:g,api:r});if(y===!1||typeof y=="string")return y}return!0},resolve:({targetNode:u,position:g,fraction:y,height:m})=>{let T=Ue(o,y,g);if(h(u.id))return"Cannot target own subtree.";if(!o&&T==="inside")return!1;let k=T==="inside"?u.id:d.parents.get(u.id)??null,C=f.get(k)??[],B=T==="inside"?C.length:(O.get(u.id)??0)+ +(T==="after"),G=T==="before"?u.rowIndex:S.get(u.id)??u.rowIndex+1,$=G-Oe(x,G)+Oe(x,e.rowIndex);return{intent:{rowIds:l,targetId:u.id,position:T,beforeId:C[B-1]??null,afterId:C[B]??null,expectedRevision:i},indicatorIndex:T==="inside"?u.rowIndex:T==="after"?S.get(u.id):void 0,toIndex:G,targetIndex:$,...Ye(r,l.length,e.rowIndex,u.rowIndex,T,m)}},keyboardTarget:u=>{let g=e.id;for(;c.has(d.parents.get(g)??"");)g=d.parents.get(g);let y=d.siblings.get(d.parents.get(g)??null)??[],m=y.indexOf(g)+u;for(;m>=0&&m<y.length;){let T=y[m];if(!h(T)&&A.has(T)&&a.has(T))return a.get(T);m+=u}}}}var J=class{constructor(e){this.host=e;this.drag=null;this.t=0;this.r=0;this.s=e=>{let t=this.drag;if(!(!t||e.pointerId!==t.pointerId)){if(t.clientX=e.clientX,t.clientY=e.clientY,!t.active){if(Math.abs(e.clientY-t.startY)<5)return;t.active=!0,this.host.root.classList.add("mach-root--row-dragging"),this.host.root.querySelectorAll(".mach-row").forEach(n=>n.classList.toggle("mach-row--drag-source",this.sourceContains(n.dataset.id??"")))}this.d()}};this.h=()=>{if(this.t=0,!!this.drag?.active){if(!this.current()){this.destroy();return}this.c(),this.g()&&this.d()}};this.a=e=>{let t=this.drag;if(!(!t||e.pointerId!==t.pointerId)){t.clientX=e.clientX,t.clientY=e.clientY,t.active&&this.current()&&this.c(),this.u();try{t.active&&t.drop?.valid&&this.o(e.clientX,e.clientY)&&this.current()&&this.commitDrop(t.drop)}finally{this.release()}}};this.l=e=>{e.key==="Escape"&&(e.preventDefault(),this.destroy())};this.n=e=>{e.type==="pointercancel"&&e.pointerId!==this.drag?.pointerId||this.destroy()}}begin(e){let t=this.host.containers.map(o=>{let i=se("div","mach-row-drop-indicator");return i.hidden=!0,o.append(i),i}),n=se("div","mach-row-drag-preview");n.setAttribute("role","status"),n.hidden=!0,this.host.root.append(n),this.drag={startY:e.clientY,clientX:e.clientX,clientY:e.clientY,pointerId:e.pointerId,indicators:t,preview:n,drop:null,active:!1},window.addEventListener("pointermove",this.s),window.addEventListener("pointerup",this.a),window.addEventListener("pointercancel",this.n),window.addEventListener("keydown",this.l),window.addEventListener("blur",this.n)}draggingSource(e){return this.drag?.active===!0&&this.sourceContains(e)}focusHandle(e,t=()=>!0){this.r=requestAnimationFrame(()=>{this.r=0,t()&&[...this.host.root.querySelectorAll(".mach-row-drag-handle")].find(n=>n.closest(".mach-row")?.dataset.id===e)?.focus()})}d(){this.t||(this.t=requestAnimationFrame(this.h))}o(e,t,n=0){let o=this.host.body.getBoundingClientRect();return e>=o.left&&e<=o.right&&t>=o.top-n&&t<=o.bottom+n}g(){let e=this.drag;if(!e||!this.o(e.clientX,e.clientY,28))return!1;let t=this.host.viewport,n=t.getBoundingClientRect(),o=Math.min(36,n.height/3);if(o<=0)return!1;let i=e.clientY<n.top+o?-Math.ceil(14*M((n.top+o-e.clientY)/o,0,1)):Math.ceil(14*M((e.clientY-n.bottom+o)/o,0,1)),a=t.scrollTop;return t.scrollTop=M(a+i,0,Math.max(0,t.scrollHeight-t.clientHeight)),t.scrollTop!==a}c(){let e=this.drag;if(!e?.active)return;let t=e.clientY-this.host.viewport.getBoundingClientRect().top+this.host.viewport.scrollTop,n=this.describe(t);e.drop=n;let o=this.o(e.clientX,e.clientY);for(let a of e.indicators)a.hidden=!o||!n?.valid,n&&(a.dataset.dropPosition=n.position??"",a.style.cssText=n.style??"",a.style.transform=`translate3d(0, ${this.host.getRowTop(n.boundary)}px, 0)`);let i=this.host.root.getBoundingClientRect();e.preview.hidden=!1,e.preview.textContent=o?n?.text??this.outsideText():this.outsideText(),e.preview.style.transform=`translate3d(${M(e.clientX-i.left+16,8,Math.max(8,i.width-224))}px, ${M(e.clientY-i.top+16,8,Math.max(8,i.height-48))}px, 0)`}u(){let e=this.drag;this.drag=null,window.removeEventListener("pointermove",this.s),window.removeEventListener("pointerup",this.a),window.removeEventListener("pointercancel",this.n),window.removeEventListener("keydown",this.l),window.removeEventListener("blur",this.n),cancelAnimationFrame(this.t),this.t=0,this.host.root?.classList.remove("mach-root--row-dragging"),this.host.root?.querySelectorAll(".mach-row--drag-source").forEach(t=>t.classList.remove("mach-row--drag-source")),e?.indicators.forEach(t=>t.remove()),e?.preview.remove()}destroy(){this.u(),this.release(),cancelAnimationFrame(this.r),this.r=0}};var Q=class extends J{constructor(t,n,o){super(t);this.bridge=t;this.prepare=n;this.requestFocus=o;this.scope=null;this.i=!1}e(t,n,o){try{return n()}catch(i){return this.scope&&(this.scope.failed=!0),this.bridge.report(i,t),o}}p(t){return this.e("prepare",()=>{let n=this.bridge.capture(t),o=this.prepare(t);return this.scope={node:t,from:t.rowIndex,guard:n,session:o,sourceDecision:!0,failed:!1},this.scope.sourceDecision=o.validate(),this.scope},null)}start(t,n){this.destroy(),this.p(n)&&this.current()&&this.begin(t)}moveWithKeyboard(t,n){this.destroy();let o=this.p(n);if(!(!o||!this.current())){this.i=!0;try{let i=t.key==="ArrowUp"?-1:1,a=this.e("keyboardTarget",()=>o.session.keyboardTarget(i),void 0);a&&this.commitDrop(this.destination(a,i<0?0:1))}finally{this.i=!1,this.release()}}}isSource(t){return this.draggingSource(t.id)}current(){return!!(this.scope&&!this.scope.failed&&this.scope.guard.current()&&this.bridge.api.rows.getById(this.scope.node.id)===this.scope.node)}sourceContains(t){return this.e("isSource",()=>this.scope?.session.isSource(t)??!1,!1)}release(){this.scope=null}outsideText(){return this.bridge.api.getOption("locale")?.rowDragOutside??"\u79FB\u56DE\u8868\u683C\u5185\u653E\u7F6E \xB7 Esc \u53D6\u6D88"}describe(t){let n=this.bridge.api,o=M(this.host.findRowAt(t),0,n.rows.getCount()-1),i=n.rows.getAt(o);if(i?.isDetail&&(i=n.rows.getById(i.masterId)),!i)return null;let a=this.host.getRowTop(i.rowIndex),d=this.host.getRowTop(i.rowIndex+1)-a;return this.destination(i,(t-a)/Math.max(1,d))}destination(t,n){let o=this.scope,i=n<.5?"before":"after",a=this.host.getRowTop(t.rowIndex+1)-this.host.getRowTop(t.rowIndex),d=this.e("resolve",()=>o.session.resolve({targetNode:t,position:i,fraction:n,height:a}),!1),c=typeof o.sourceDecision=="string"?o.sourceDecision:typeof d=="string"?d:"\u6B64\u4F4D\u7F6E\u4E0D\u53EF\u653E\u7F6E",l={node:t,fraction:n,boundary:t.rowIndex,valid:!1,text:c};if(!d||typeof d=="string"||o.sourceDecision!==!0||t.loading||t.treeLoading||t.isGroup)return l;l.intent=d.intent,l.position=d.intent.position,l.toIndex=d.toIndex,l.targetIndex=d.targetIndex,l.boundary=d.indicatorIndex??t.rowIndex+ +(d.intent.position==="after"),l.style=d.indicatorStyle,l.text=d.text??c;let h=this.e("canDrop",()=>this.bridge.api.getOption("rowDragPolicy")?.canDrop?.({node:o.node,api:this.bridge.api,targetNode:t,intent:d.intent})??!0,!1);return l.valid=h===!0,typeof h=="string"&&(l.text=h),l}commitDrop(t){let n=this.scope;if(!n||!this.current()||this.e("validate",()=>n.session.validate(),!1)!==!0||!this.current())return!1;let o=this.destination(t.node,t.fraction);return!o.valid||!o.intent||!this.current()?!1:(this.i&&this.requestFocus(o.intent,i=>this.focusHandle(n.node.id,i)),this.bridge.emit(n.node,n.from,o.toIndex,o.targetIndex,o.intent),!0)}};function _(r,e,t){let n=[],o=[...r].reverse().map(a=>({row:a,parent:null})),i=new Set;for(;o.length;){let a=o.pop();if(i.has(a.row))throw new Error("[MachTable] Installed order contains duplicate or cyclic rows.");i.add(a.row),n.push(a);let d=t?a.row[e]??[]:[];for(let c=d.length-1;c>=0;c--)o.push({row:d[c],parent:a.row})}return n}function H(r,e,t,n){try{let o=_(r,t,n);return o.length===e.length&&o.every((i,a)=>i.row===e[a].row&&i.parent===e[a].parent)}catch{return!1}}function pe(r){let e=[];return r?.rows.forEach(t=>e.push({node:t,data:t.data})),e}function z(r,e){if(!r)return!0;if(r.isDestroyed())return!1;let t=0,n=!0;return r.rows.forEach(o=>{let i=e[t++];(i?.node!==o||i.data!==o.data)&&(n=!1)}),n&&t===e.length}var Z=class{constructor(){this.entries=[];this.cursor=0}get canUndo(){return this.cursor>0}get canRedo(){return this.cursor<this.entries.length}peek(e){return this.entries[e==="undo"?this.cursor-1:this.cursor]}commit(e,t){e==="undo"?this.cursor--:e==="redo"?this.cursor++:(this.entries.splice(this.cursor),this.entries.push(t),this.entries.length>50&&this.entries.shift(),this.cursor=this.entries.length)}clear(){this.entries=[],this.cursor=0}};var L=class extends Error{constructor(t="The row order changed on the server. Reload before trying again.",n){super(t);this.serverRevision=n;this.name="RowOrderConflictError"}};function ze(r){if(r?.status==="conflict")throw new L(r.message,r.revision);return r?.revision}function Ee(r){if(r.targetId===null)throw new Error("[MachTable] Row ordering requires an existing destination.");return{...r,targetId:r.targetId}}function $e(r){let e={status:"idle",error:null,revision:r.getRevision?.(),plan:null,canUndo:!1,canRedo:!1},t=0,n=!1,o=null,i=null,a=null,d=()=>{},c=()=>{},l=0,h=null,f=new Z,O=null,S=new Set,A=r.childrenKey??"children",x=null,E=()=>{f.clear(),O=null},q=()=>{if(!o)return!1;let s=o;return t++,o=null,i=null,s.abort(),!0},u=(s=e.status)=>({canUndo:!n&&s!=="saving"&&f.canUndo,canRedo:!n&&s!=="saving"&&f.canRedo}),g=s=>{e=Object.freeze({...s,...u(s.status)}),a&&!a.isDestroyed()&&a.view.refreshCells();let p=[w=>r.onStateChange?.(w),...S];for(let w of p)try{w?.(e)}catch(v){console.error("[MachTable] Row order state observer failed",v)}},y=()=>r.getRevision?.()??e.revision,m=(s=h)=>{s?.release(),h===s&&(h=null)},T=()=>{!i||i()||(q(),E(),m(),g({...e,status:"idle",plan:null,error:null}))},k=s=>new Q(s,p=>xe(s.api,p,r.getRows(),r,r.treeData===!0,y()),(p,w)=>{m();let v=document.activeElement,R=N=>{N.target!==v&&N.target!==document.body&&m(b)},b={api:s.api,intent:p,restore:w,generation:t+1,release:()=>document.removeEventListener("focusin",R,!0)};h=b,document.addEventListener("focusin",R,!0)}),C=()=>{T(),!o&&O&&(O.api!==a||O.revision!==y()||!z(a,O.nodes)||!H(r.getRows(),O.rows,A,r.treeData===!0))&&E();let s=u();(e.canUndo!==s.canUndo||e.canRedo!==s.canRedo)&&(e=Object.freeze({...e,...s}))},B=s=>{if(s===a){T(),le(s,k)||(c(),c=ce(s,k));return}let p=q();d(),c(),m(),E(),a=s,c=ce(s,k),d=s.on("cellValueChanged",()=>{l++;let w=f.canUndo||f.canRedo;E(),w&&g({...e,status:o?"saving":"idle",plan:o?e.plan:null,error:null})}),p&&g({...e,status:"idle",plan:null,error:null})},G=s=>{if(C(),n)throw new Error("[MachTable] The row order controller is disposed.");if(o)throw new Error("[MachTable] A row order save is already in progress.");let p=y();if(p!==void 0&&s.expectedRevision!==void 0&&s.expectedRevision!==p)throw new L;let w={...s,expectedRevision:s.expectedRevision??p};return(r.treeData?ae:ie)(r.getRows(),w,r)},$=async(s,p,w,v,R)=>{if(!s.changed)return s;let b=a;if(b&&!V(b))throw new Error("[MachTable] Save or discard edited rows before changing their order.");let N=++t;x=null;let W=new AbortController;o=W,i=null;let j=y(),Me=l,F=null,K=[],fe=!1,ee=!1,te=j,ye=I=>{if(!R)return;if(!I||R!==h||R.api!==a){m(R);return}let D=O;R.restore(()=>{let ne=D!==null&&D===O&&D.revision===y()&&z(R.api,D.nodes)&&H(r.getRows(),D.rows,A,r.treeData===!0)&&h===R&&!n&&t===R.generation&&a===R.api&&le(R.api,k);return m(R),ne})},P=()=>!n&&t===N,re=()=>P()&&(!b||a===b&&!b.isDestroyed())&&F!==null&&y()===j&&z(b,K)&&H(r.getRows(),F,A,r.treeData===!0),Pe=I=>{if(!re()){P()&&!F&&g({...e,status:"error",error:I,plan:s});return}let D=!b||V(b),U=D?I:Object.assign(new Error("[MachTable] Row order could not be saved. Automatic rollback was skipped to preserve new edits. Save or discard those edits, then reload the row order."),{cause:I});if(D){i=null;try{r.applyRows(s.before),ee=!0}catch(ne){U=Object.assign(new Error("[MachTable] Row order could not be saved or restored. Reload the row order before trying again."),{cause:I,rollbackError:ne})}}P()&&(ee||E(),g({...e,status:I instanceof L?"conflict":"error",error:U}))},Le=()=>{if(!P()){ye(!1);return}let I=y(),D=!1;fe&&P()&&(I===j||I===te)&&z(b,K)&&H(r.getRows(),F,A,r.treeData===!0)?(O={rows:F,nodes:K,api:b,revision:I},D=!0):ee&&P()?(O={rows:_(r.getRows(),A,r.treeData===!0),nodes:pe(b),api:b,revision:I},D=H(r.getRows(),_(s.before,A,r.treeData===!0),A,r.treeData===!0)):E(),o===W&&(o=null,i=null,a&&!a.isDestroyed()&&a.view.refreshCells()),P()&&e.status==="saving"&&g({...e,status:"idle",plan:null}),C(),ye(D)};try{r.applyRows(s.after),F=_(r.getRows(),A,r.treeData===!0),K=pe(b);let I=r.getRows(),D=K[0]?.node;if(i=b&&D?()=>!b.isDestroyed()&&b.rows.getById(D.id)===D:()=>r.getRows()===I,g({...e,status:"saving",error:null,plan:s}),!re())return s;let U=ze(await De(Promise.resolve(r.save?.(s.intent,{signal:W.signal,plan:s,operation:p,operations:w})),W.signal));return re()&&(fe=!0,te=U??j,l===Me?f.commit(p,v):E(),g({...e,status:"saved",revision:te})),s}catch(I){throw Pe(I),I}finally{Le()}},he=async(s,p)=>{p!==h&&(p=void 0),h!==p&&m();let w=G(s);w.changed||m(p);let v=w.changed?Re(w,r,r.treeData===!0):[];return $(w,"move",[w.intent],{plan:w,inverse:v},p)},Se=s=>he(s),we=async s=>{if(m(),C(),n||o)throw new Error("[MachTable] Row ordering is unavailable while disposed or saving.");let p=f.peek(s);if(!p)throw new Error(`[MachTable] Nothing to ${s}.`);let w=(s==="undo"?p.inverse:[p.plan.intent]).map(N=>({...N,expectedRevision:y()})),v=r.getRows(),R=s==="undo"?p.plan.before:p.plan.after;Te(v,R,w,r,r.treeData===!0);let b={before:v,after:R,intent:w[0],rowIds:p.plan.rowIds,changed:!0};return $(b,s,w,p)},Ae=s=>{try{if(n||o)return!1;let p=r.getRows(),w=y();if(w!==void 0&&s.expectedRevision!==void 0&&s.expectedRevision!==w)return!1;let v=x?.rowIds===s.rowIds?x.sources:JSON.stringify(s.rowIds.map(String));return(!x||x.rows!==p||x.revision!==w||x.sources!==v)&&(x={rows:p,revision:w,sources:v,rowIds:s.rowIds,validate:be(p,s.rowIds,r,r.treeData===!0)}),x.rowIds=s.rowIds,x.validate(s),!0}catch(p){return p instanceof Error?p.message:!1}},Ce=s=>{let p=s.intent;if(s.applied||!p)return;B(s.api);let w=t,v=h?.intent===p?h:void 0;Promise.resolve().then(()=>he(Ee(p),v)).catch(R=>{v&&v.generation!==t&&m(v),!n&&t===w&&e.status!=="saving"&&g({...e,status:R instanceof L?"conflict":"error",error:R})})},ge=s=>n?!1:(B(s),o?"Wait for the current row order to finish saving.":V(s)||"Save or discard edited rows before changing their order.");return{get state(){return C(),e},bindings:{applyRowDrag:!1,rowDragPolicy:{canDrag:({api:s})=>ge(s),canDrop:({intent:s,api:p})=>{let w=ge(p);if(w!==!0)return w;try{return Ae(Ee(s))}catch(v){return v instanceof Error?v.message:!1}},getRevision:y},onRowDragEnd:Ce},preview:G,move:Se,undo:()=>we("undo"),redo:()=>we("redo"),subscribe(s){return n?()=>{}:(S.add(s),()=>{S.delete(s)})},dispose(){n=!0,t++,o?.abort(),o=null,i=null,d(),c(),m(),E(),a&&!a.isDestroyed()&&a.view.refreshCells(),a=null,x=null,S.clear(),e=Object.freeze({...e,status:"idle",error:null,plan:null,canUndo:!1,canRedo:!1})}}}export{L as RowOrderConflictError,$e as createRowOrderController,ae as moveTreeNodes,ie as reorderRows};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agile-team/mach-table",
3
- "version": "0.32.0",
3
+ "version": "0.32.1",
4
4
  "description": "Enterprise-grade, framework-agnostic TypeScript data grid with virtualization, editing, grouping and extensibility",
5
5
  "keywords": [
6
6
  "data-grid",
@@ -148,5 +148,5 @@
148
148
  "test": "vitest run",
149
149
  "test:coverage": "vitest run --coverage"
150
150
  },
151
- "readme": "<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/ChenyCHENYU/MachTable/main/assets/mach-table-logo.svg\" alt=\"MachTable\" width=\"760\" />\n</p>\n\n# @agile-team/mach-table\n\nMachTable 0.32.0 的框架无关 TypeScript Core:零运行时依赖,提供行列双虚拟化、领域化 API、单元格/整行编辑、树与分组、随机访问远程数据、区段隔离状态持久化和可诊断扩展系统。本版增加六个按需高级子入口,完善内部资源所有权、框架生命周期与缓存操作边界。\n\n```bash\npnpm add @agile-team/mach-table\n```\n\n```ts\nimport { createGrid, indexColumn } from \"@agile-team/mach-table\";\nimport \"@agile-team/mach-table/styles/mach-table.css\";\n\nconst api = createGrid(document.querySelector(\"#grid\")!, {\n columnDefs: [\n indexColumn({ headerName: \"序号\" }),\n { field: \"id\", headerName: \"ID\", width: 120 },\n { field: \"name\", headerName: \"名称\", flex: 1, editable: true }\n ],\n rowData: [{ id: \"1\", name: \"MachTable\" }],\n rowKey: \"id\",\n enableColumnResize: true,\n persistence: { key: \"tenant:user:customers\", sections: [\"columns\"] }\n});\n\napi.batch((grid) => {\n grid.rows.transact({ update: [{ id: \"1\", name: \"Updated\" }] });\n grid.columns.setVisible(\"internalNote\", false);\n grid.view.refreshCells({ rowIds: [\"1\"] });\n});\n\nconst saved = await api.editing.save(orderApi.saveChanges);\nconsole.table(saved.conflicts);\nconsole.info(api.diagnostics.get());\n\n// 原生宿主卸载时必须销毁;Vue/React 适配器会自动处理。\napi.destroy();\n```\n\n`persistence.sections` 同时约束进入 store 的数据与恢复范围;异步 store 写入有序,晚到加载不会覆盖加载期间的用户操作。\n\n单元格编辑通过内置对勾/取消控件显式结束,普通鼠标和焦点变化不会误提交;Enter、Escape、Tab 仍提供完整键盘路径。筛选、列设置、上下文菜单和操作菜单会继承所属表格实例的主题变量,不受宿主页面全局样式影响。\n\n编辑、粘贴、清空和填充共用已有列校验与整行校验,批量输入按行提交并合并撤销记录,异步校验不会写回已替换的数据。随机块缓存淘汰后,未保存行仍可通过编辑 API 保存或回滚;完整替换数据与重新查询会清理旧作用域的状态。\n\n`loading: true` 默认展示轻量表格骨架与本地化状态文案,空数据默认展示内置插画;需要品牌化时再通过 `overlayLoadingTemplate`、`overlayNoRowsTemplate` 覆盖,基础页面无需重复实现 loading/empty DOM。\n\n公共命令按 `rows`、`columns`、`selection`、`editing`、`filtering`、`sorting`、`pagination`、`hierarchy`、`view`、`state`、`io`、`diagnostics` 划分。完整签名见 [GridApi](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/api/grid-api.md)。\n\n大型本地数据 Worker 使用独立入口:\n\n```ts\nimport { createWorkerDataProcessor } from \"@agile-team/mach-table/worker\";\n```\n\nVue/React 项目请只安装对应适配包,它会自动安装并重导出 Core:\n\n- [@agile-team/mach-table-vue](https://www.npmjs.com/package/@agile-team/mach-table-vue)\n- [@agile-team/mach-table-react](https://www.npmjs.com/package/@agile-team/mach-table-react)\n\n## 行拖拽与条件整行颜色\n\n```ts\nimport { dragColumn, type GridOptions } from \"@agile-team/mach-table\";\n\ninterface Plan { id: string; name: string; status: string }\nconst options: GridOptions<Plan> = {\n rowKey: \"id\",\n columnDefs: [dragColumn(), { field: \"name\" }, { field: \"status\" }],\n rowStyleRules: [\n { when: ({ data }) => data.status === \"pending\", tone: \"warning\" },\n { when: ({ data }) => data.status === \"failed\", tone: \"danger\" },\n { when: ({ data }) => data.status === \"done\", tone: \"success\" }\n ]\n};\n```\n\n状态码由应用定义,包内不识别业务状态。颜色规则取第一条命中结果,未命中时沿用默认样式;支持自定义背景/文字颜色、固定列、明暗主题、选择和虚拟行复用。拖拽提供主题手柄、落点线、位置浮层、边缘滚动、Esc 取消和 Alt + ↑/↓ 移动。扁平外部数据设置 `applyRowDrag: false`,由 `onRowDragEnd` 处理持久化;自动模式先完成移动再发出事件,使用 `targetIndex` 读取最终下标。树、分组及排序等自动模式限制见[完整配方](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/row-presentation.md)。\n\n文档:[快速开始](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/getting-started.md) · [企业接入](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/enterprise-integration.md) · [API](https://github.com/ChenyCHENYU/MachTable/tree/main/docs/api)\n\n## 按需高级入口(0.32)\n\n仍从本包导入,无需另装高级功能包。普通根入口不加载这些实现或附加 CSS。\n\n| 子路径 | 功能 |\n| --- | --- |\n| `/workbench` | 高级过滤草稿与应用、修改差异/部分保存/冲突审阅、手动诊断 |\n| `/preferences` | 复合身份隔离、CAS、有序写入、历史版本及列 ID/类型迁移报告 |\n| `/ordering` | 多行/树移动、防环与业务约束、失败回滚、持久化撤销/重做 |\n| `/server-side` | 服务端分组/聚合、route 分页、缓存/刷新/事务及层级选择 |\n| `/multi-range` | Ctrl/Cmd 追加范围、格式化复制、校验清空及撤销 |\n| `/analysis` | Pivot、安全公式、柱/折线图和数据表回退 |\n\n```ts\nimport { mountAdvancedFilterBuilder } from \"@agile-team/mach-table/workbench\";\nimport \"@agile-team/mach-table/styles/workbench.css\";\n\nconst filters = mountAdvancedFilterBuilder(host, { api });\n// 宿主卸载时调用;表格销毁也会释放工作台。\nfilters.destroy();\n```\n\n服务端分组控件使用 `/styles/server-side.css`,分析与多范围使用 `/styles/workbench.css`。排序、偏好和纯分析计算无需附加 CSS。服务端 Store 按 route 分页,不提供全树任意显示 offset;分析只处理当前已加载数据并显示范围。排序 undo/redo 的 transport 必须一次 CAS 保存 `context.operations` 的完整批次或 `context.plan.after`,只保存首参数无法完整恢复非连续/跨父级位置。\n\n完整示例与限制:[工作台](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/workbench.md) · [排序](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/row-presentation.md) · [企业偏好](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/enterprise-preferences.md) · [服务端 Store](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/server-side-store.md) · [多范围](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/multi-range.md) · [分析](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/analysis.md)。\n\nSource-available © ChenyCHENYU (Agile Team). 任何使用均须事先取得书面授权。详见 [LICENSE](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSE) 与[授权流程](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSING.md)。\n"
151
+ "readme": "<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/ChenyCHENYU/MachTable/main/assets/mach-table-logo.svg\" alt=\"MachTable\" width=\"760\" />\n</p>\n\n# @agile-team/mach-table\n\nMachTable 0.32.1 的框架无关 TypeScript Core:零运行时依赖,提供行列双虚拟化、领域化 API、单元格/整行编辑、树与分组、随机访问远程数据、区段隔离状态持久化和可诊断扩展系统。本版增加六个按需高级子入口,完善内部资源所有权、框架生命周期与缓存操作边界。\n\n```bash\npnpm add @agile-team/mach-table\n```\n\n```ts\nimport { createGrid, indexColumn } from \"@agile-team/mach-table\";\nimport \"@agile-team/mach-table/styles/mach-table.css\";\n\nconst api = createGrid(document.querySelector(\"#grid\")!, {\n columnDefs: [\n indexColumn({ headerName: \"序号\" }),\n { field: \"id\", headerName: \"ID\", width: 120 },\n { field: \"name\", headerName: \"名称\", flex: 1, editable: true }\n ],\n rowData: [{ id: \"1\", name: \"MachTable\" }],\n rowKey: \"id\",\n enableColumnResize: true,\n persistence: { key: \"tenant:user:customers\", sections: [\"columns\"] }\n});\n\napi.batch((grid) => {\n grid.rows.transact({ update: [{ id: \"1\", name: \"Updated\" }] });\n grid.columns.setVisible(\"internalNote\", false);\n grid.view.refreshCells({ rowIds: [\"1\"] });\n});\n\nconst saved = await api.editing.save(orderApi.saveChanges);\nconsole.table(saved.conflicts);\nconsole.info(api.diagnostics.get());\n\n// 原生宿主卸载时必须销毁;Vue/React 适配器会自动处理。\napi.destroy();\n```\n\n`persistence.sections` 同时约束进入 store 的数据与恢复范围;异步 store 写入有序,晚到加载不会覆盖加载期间的用户操作。\n\n单元格编辑通过内置对勾/取消控件显式结束,普通鼠标和焦点变化不会误提交;Enter、Escape、Tab 仍提供完整键盘路径。筛选、列设置、上下文菜单和操作菜单会继承所属表格实例的主题变量,不受宿主页面全局样式影响。\n\n编辑、粘贴、清空和填充共用已有列校验与整行校验,批量输入按行提交并合并撤销记录,异步校验不会写回已替换的数据。随机块缓存淘汰后,未保存行仍可通过编辑 API 保存或回滚;完整替换数据与重新查询会清理旧作用域的状态。\n\n`loading: true` 默认展示轻量表格骨架与本地化状态文案,空数据默认展示内置插画;需要品牌化时再通过 `overlayLoadingTemplate`、`overlayNoRowsTemplate` 覆盖,基础页面无需重复实现 loading/empty DOM。\n\n公共命令按 `rows`、`columns`、`selection`、`editing`、`filtering`、`sorting`、`pagination`、`hierarchy`、`view`、`state`、`io`、`diagnostics` 划分。完整签名见 [GridApi](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/api/grid-api.md)。\n\n大型本地数据 Worker 使用独立入口:\n\n```ts\nimport { createWorkerDataProcessor } from \"@agile-team/mach-table/worker\";\n```\n\nVue/React 项目请只安装对应适配包,它会自动安装并重导出 Core:\n\n- [@agile-team/mach-table-vue](https://www.npmjs.com/package/@agile-team/mach-table-vue)\n- [@agile-team/mach-table-react](https://www.npmjs.com/package/@agile-team/mach-table-react)\n\n## 行拖拽与条件整行颜色\n\n```ts\nimport { dragColumn, type GridOptions } from \"@agile-team/mach-table\";\n\ninterface Plan { id: string; name: string; status: string }\nconst options: GridOptions<Plan> = {\n rowKey: \"id\",\n columnDefs: [dragColumn(), { field: \"name\" }, { field: \"status\" }],\n rowStyleRules: [\n { when: ({ data }) => data.status === \"pending\", tone: \"warning\" },\n { when: ({ data }) => data.status === \"failed\", tone: \"danger\" },\n { when: ({ data }) => data.status === \"done\", tone: \"success\" }\n ]\n};\n```\n\n状态码由应用定义,包内不识别业务状态。颜色规则取第一条命中结果,未命中时沿用默认样式;支持自定义背景/文字颜色、固定列、明暗主题、选择和虚拟行复用。拖拽提供主题手柄、落点线、位置浮层、边缘滚动、Esc 取消和 Alt + ↑/↓ 移动。扁平外部数据设置 `applyRowDrag: false`,由 `onRowDragEnd` 处理持久化;自动模式先完成移动再发出事件,使用 `targetIndex` 读取最终下标。树、分组及排序等自动模式限制见[完整配方](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/row-presentation.md)。\n\n文档:[快速开始](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/getting-started.md) · [企业接入](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/enterprise-integration.md) · [API](https://github.com/ChenyCHENYU/MachTable/tree/main/docs/api)\n\n## 按需高级入口(0.32)\n\n仍从本包导入,无需另装高级功能包。普通根入口不加载这些实现或附加 CSS。\n\n| 子路径 | 功能 |\n| --- | --- |\n| `/workbench` | 高级过滤草稿与应用、修改差异/部分保存/冲突审阅、手动诊断 |\n| `/preferences` | 复合身份隔离、CAS、有序写入、历史版本及列 ID/类型迁移报告 |\n| `/ordering` | 多行/树移动、防环与业务约束、失败回滚、持久化撤销/重做 |\n| `/server-side` | 服务端分组/聚合、route 分页、缓存/刷新/事务及层级选择 |\n| `/multi-range` | Ctrl/Cmd 追加范围、格式化复制、校验清空及撤销 |\n| `/analysis` | Pivot、安全公式、柱/折线图和数据表回退 |\n\n```ts\nimport { mountAdvancedFilterBuilder } from \"@agile-team/mach-table/workbench\";\nimport \"@agile-team/mach-table/styles/workbench.css\";\n\nconst filters = mountAdvancedFilterBuilder(host, { api });\n// 宿主卸载时调用;表格销毁也会释放工作台。\nfilters.destroy();\n```\n\n服务端分组控件使用 `/styles/server-side.css`,分析与多范围使用 `/styles/workbench.css`。排序、偏好和纯分析计算无需附加 CSS。服务端 Store 按 route 分页,不提供全树任意显示 offset;分析只处理当前已加载数据并显示范围。排序 undo/redo 的 transport 必须一次 CAS 保存 `context.operations` 的完整批次或 `context.plan.after`,只保存首参数无法完整恢复非连续/跨父级位置。\n\n完整示例与限制:[工作台](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/workbench.md) · [排序](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/row-presentation.md) · [企业偏好](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/enterprise-preferences.md) · [服务端 Store](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/server-side-store.md) · [多范围](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/multi-range.md) · [分析](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/analysis.md)。\n\nSource-available © ChenyCHENYU (Agile Team). 任何使用均须事先取得书面授权。详见 [LICENSE](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSE) 与[授权流程](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSING.md)。\n"
152
152
  }