@taocompany/magic-grid 0.4.7 → 0.4.8
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/dist/index.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./validation-CD6lt5wS.cjs");let t=require("vue");var n=`default`,r={mini:{spacing:4,fontSize:12,borderRadius:4,rowHeight:20,headerHeight:20,statusBarHeight:20,checkboxSize:12},small:{spacing:8,fontSize:12,borderRadius:8,rowHeight:24,headerHeight:24,statusBarHeight:24,checkboxSize:12},default:{spacing:8,fontSize:12,borderRadius:8,rowHeight:32,headerHeight:32,statusBarHeight:32,checkboxSize:14},large:{spacing:12,fontSize:14,borderRadius:8,rowHeight:40,headerHeight:40,statusBarHeight:40,checkboxSize:14}};function i(e){let{rounded:t=!1,sizeBorderRadius:n}=e;return t===!0?n:typeof t==`number`?Math.max(0,t):0}function a(e={}){let t=e.size??`default`,n=r[t],i=e.rowHeight!=null,a=e.headerHeight!=null;return{size:t,spacing:n.spacing,fontSize:n.fontSize,borderRadius:n.borderRadius,rowHeight:i?e.rowHeight:n.rowHeight,headerHeight:a?e.headerHeight:n.headerHeight,statusBarHeight:n.statusBarHeight,checkboxSize:n.checkboxSize,rowHeightOverridden:i,headerHeightOverridden:a}}function o(e,t){return e==null||e===`auto`||!Number.isFinite(e)?t:Math.max(12,Math.trunc(e))}function s(e){return Math.max(12,e-6)}function c(e){return Math.max(12,e-8)}function l(e){return r[e].statusBarHeight}var u={mini:12,small:14,default:16,large:18};function d(e){return u[e]}function f(e=n){return{"--mg-column-settings-button-size":`${l(e)}px`,"--mg-column-settings-button-icon-size":`${d(e)}px`}}function p(e,t,n){let r=n??e.rowHeight,i=s(e.statusBarHeight),a=l(e.size);return{"--mg-row-height":`${e.rowHeight}px`,"--mg-header-height":`${e.headerHeight}px`,"--mg-summary-row-height":`${r}px`,"--mg-status-bar-height":`${e.statusBarHeight}px`,"--mg-status-bar-control-height":`${i}px`,"--mg-column-settings-button-size":`${a}px`,"--mg-column-settings-button-icon-size":`${d(e.size)}px`,"--mg-status-bar-font-size":`${e.fontSize}px`,"--mg-font-size":`${e.fontSize}px`,"--mg-spacing":`${e.spacing}px`,"--mg-cell-padding-x":`${e.spacing}px`,"--mg-border-radius":`${t}px`,"--mg-checkbox-size":`${e.checkboxSize}px`,"--mg-cell-control-size":`${c(e.rowHeight)}px`}}var m=r.default.rowHeight,h=r.default.headerHeight,g=class{requestFrame;cancelFrame;now;frameBudgetMs;rendererFrameBudgetMs;scrollActive=!1;p1=[];p2=[];f1=[];destroyTasks=[];scrollGridIfNeeded=null;scrollGoingDown=!0;ticking=!1;rafId=null;createOrderSeed=0;constructor(e={}){this.requestFrame=e.requestFrame??(e=>requestAnimationFrame(e)),this.cancelFrame=e.cancelFrame??(e=>cancelAnimationFrame(e)),this.now=e.now??(()=>performance.now()),this.frameBudgetMs=Math.max(1,e.frameBudgetMs??60),this.rendererFrameBudgetMs=Math.max(0,e.rendererFrameBudgetMs??20)}setRendererFrameBudgetMs(e){this.rendererFrameBudgetMs=Math.max(0,e)}getRendererFrameBudgetMs(){return this.rendererFrameBudgetMs}setScrollActive(e){this.scrollActive=e}isScrollActive(){return this.scrollActive}setFrameBudgetMs(e){this.frameBudgetMs=Math.max(1,e)}getFrameBudgetMs(){return this.frameBudgetMs}setScrollGridIfNeeded(e){this.scrollGridIfNeeded=e}setScrollDirection(e){this.scrollGoingDown=e}schedule(){this.ticking||(this.ticking=!0,this.rafId=this.requestFrame(()=>{this.ticking=!1,this.rafId=null,this.executeFrame(this.frameBudgetMs)}))}createTask(e,t,n){this.getTaskList(n).push({task:e,index:t,createOrder:this.createOrderSeed++,deferred:!1}),this.schedule()}addDestroyTask(e){this.destroyTasks.push(e),this.schedule()}flushAllFrames(e){this.rafId!=null&&(this.cancelFrame(this.rafId),this.rafId=null,this.ticking=!1);let t=e??-1,n=!0;for(;n||this.hasPendingWork();)n=!1,this.executeFrame(t)}destroy(){this.rafId!=null&&(this.cancelFrame(this.rafId),this.rafId=null),this.ticking=!1,this.p1=[],this.p2=[],this.f1=[],this.destroyTasks=[]}getPendingTaskCount(){return this.p1.length+this.p2.length+this.f1.length+this.destroyTasks.length}getPendingRendererTaskCount(){return this.f1.length}executeFrame(e){let t=this.now(),n=e<0,r=!n&&this.scrollActive&&this.rendererFrameBudgetMs>0&&this.f1.length>0,i=r?Math.max(0,e-this.rendererFrameBudgetMs):e,a=r?this.rendererFrameBudgetMs:e;for(this.runTaskPhase({start:t,budgetMs:i,unlimited:n,queues:r?[`p1`,`p2`]:[`p1`,`p2`,`f1`]}),r&&this.runTaskPhase({start:this.now(),budgetMs:a,unlimited:!1,queues:[`f1`]});n||this.now()-t<e;){let e=this.destroyTasks.shift();if(!e)break;e()}this.hasPendingWork()&&this.schedule()}runTaskPhase(e){for(;e.unlimited||this.now()-e.start<e.budgetMs;){if(this.scrollGridIfNeeded?.())continue;let t=this.popNextTask(e.queues);if(!t)break;t.task()}}hasPendingWork(){return this.p1.length>0||this.p2.length>0||this.f1.length>0||this.destroyTasks.length>0}popNextTask(e=[`p1`,`p2`,`f1`]){for(let t of e){let e=this.getTaskList(t);if(e.length!==0)return this.sortTaskList(e),e.shift()}}sortTaskList(e){e.sort((e,t)=>e.index===t.index?e.createOrder-t.createOrder:this.scrollGoingDown?e.index-t.index:t.index-e.index)}getTaskList(e){switch(e){case`p1`:return this.p1;case`p2`:return this.p2;case`f1`:return this.f1}}},_=class{depth=0;beginDeferred(){this.depth++}endDeferred(e){this.depth<=0||(this.depth--,this.depth===0&&e())}isDeferred(){return this.depth>0}reset(){this.depth=0}};function v(e){return{setData:t=>e.setData(t),applyTransaction:t=>e.applyTransaction(t),addRows:t=>e.addRows(t),removeRows:t=>e.removeRows(t),getData:t=>e.getData(t),promoteRowId:t=>e.promoteRowId(t),moveRow:(t,n,r)=>e.moveRow(t,n,r),setSortModel:t=>e.setSortModel(t),getSortModel:()=>e.getSortModel(),setFilterModel:t=>e.setFilterModel(t),getFilterModel:()=>e.getFilterModel(),getColumnFilter:t=>e.getColumnFilter(t),isColumnFilterActive:t=>e.isColumnFilterActive(t),isAnyFilterActive:()=>e.isAnyFilterActive(),setQuickFilterText:t=>e.setQuickFilterText(t),getQuickFilterText:()=>e.getQuickFilterText(),clearAllFilters:()=>e.clearAllFilters(),setColumnFilter:(t,n)=>e.setColumnFilter(t,n),refreshCells:t=>e.refreshCells(t),refreshCellSpans:()=>e.refreshCellSpans(),getCellSpan:(t,n)=>e.getCellSpan(t,n),ensureIndexVisible:(t,n)=>e.ensureIndexVisible(t,n),getRowNode:t=>e.getRowNode(t),getMetrics:()=>e.getMetrics(),getPendingFrameTaskCount:()=>e.getPendingFrameTaskCount(),getPendingRendererTaskCount:()=>e.getPendingRendererTaskCount(),beginUpdate:()=>e.beginUpdate(),endUpdate:()=>e.endUpdate(),scrollTo:(t,n)=>e.scrollTo(t,n),moveColumn:(t,n)=>e.moveColumn(t,n),resetColumnOrder:()=>e.resetColumnOrder(),resetColumnWidths:()=>e.resetColumnWidths(),setColumnFixed:(t,n)=>e.setColumnFixed(t,n),setColumnsHidden:(t,n)=>e.setColumnsHidden(t,n),isColumnHidden:t=>e.isColumnHidden(t),getDisplayedColumnIds:()=>e.getDisplayedColumnIds(),getColumns:()=>e.getColumns(),getDisplayedColumns:()=>e.getDisplayedColumns(),getColumnDistinctFilterValues:t=>e.getColumnDistinctFilterValues(t),setColumnWidths:(t,n,r)=>e.setColumnWidths(t,n,r),setColumnWidth:(t,n,r,i)=>e.setColumnWidth(t,n,r,i),getColumnWidth:t=>e.getColumnWidth(t),autoSizeColumn:(t,n)=>e.autoSizeColumn(t,n),autoSizeColumns:(t,n)=>e.autoSizeColumns(t,n),sizeColumnsToFit:t=>e.sizeColumnsToFit(t),setRowHeight:(t,n,r)=>e.setRowHeight(t,n,r),setRowHeights:(t,n)=>e.setRowHeights(t,n),getRowHeight:t=>e.getRowHeight(t),resetRowHeights:t=>e.resetRowHeights(t),updateDimensions:t=>e.updateDimensions(t),expandRow:t=>e.expandRow(t),collapseRow:t=>e.collapseRow(t),isRowExpanded:t=>e.isRowExpanded(t),expandAll:()=>e.expandAll(),collapseAll:()=>e.collapseAll(),setRowGroupColumns:t=>e.setRowGroupColumns(t),getRowGroupColumns:()=>e.getRowGroupColumns(),expandGroup:t=>e.expandGroup(t),collapseGroup:t=>e.collapseGroup(t),isGroupExpanded:t=>e.isGroupExpanded(t),expandNode:t=>e.expandNode(t),collapseNode:t=>e.collapseNode(t),isNodeExpanded:t=>e.isNodeExpanded(t),getDataPath:t=>e.getDataPath(t),getCellComment:(t,n)=>e.getCellComment(t,n),setCellComment:(t,n,r)=>e.setCellComment(t,n,r),refreshCellComments:t=>e.refreshCellComments(t),getCellRanges:()=>e.getCellRanges(),getCellSelectionAggregation:()=>e.getCellSelectionAggregation(),clearCellSelection:()=>e.clearCellSelection(),addCellRange:t=>e.addCellRange(t),copySelectedRangeToClipboard:()=>e.copySelectedRangeToClipboard(),pasteFromClipboard:()=>e.pasteFromClipboard(),showLoadingOverlay:()=>e.showLoadingOverlay(),showNoRowsOverlay:()=>e.showNoRowsOverlay(),hideOverlay:()=>e.hideOverlay(),isOverlayShowing:()=>e.isOverlayShowing(),getOverlayType:()=>e.getOverlayType(),refreshDisabledState:t=>e.refreshDisabledState(t),refreshCellStyles:t=>e.refreshCellStyles(t),startEditingCell:t=>e.startEditingCell(t),stopEditing:t=>e.stopEditing(t),isEditing:()=>e.isEditing(),isCommitting:()=>e.isCommitting(),cancelCommit:()=>e.cancelCommit(),getEditSessionPhase:()=>e.getEditSessionPhase(),getEditingCell:()=>e.getEditingCell(),getEditingCells:()=>e.getEditingCells(),registerCellEditor:(t,n)=>e.registerCellEditor(t,n),unregisterCellEditor:t=>e.unregisterCellEditor(t),validate:t=>e.validate(t),validateRows:t=>e.validateRows(t),validateCells:t=>e.validateCells(t),clearValidation:t=>e.clearValidation(t),clearRowValidation:t=>e.clearRowValidation(t),clearCellValidation:t=>e.clearCellValidation(t),toggleRowSelection:(t,n,r)=>e.toggleRowSelection(t,n,r),toggleAllSelection:t=>e.toggleAllSelection(t),setIndexFocus:t=>e.setIndexFocus(t),destroy:()=>e.destroy(),on:(t,n)=>e.on(t,n)}}var y=[`.mg-cell-editor-host`],b=[];function x(e){b.push(...e)}function S(){b.length=0}function C(e){return e instanceof Element?e:e instanceof Text?e.parentElement:null}function w(){return[...y,...b]}function T(e){let t=C(e);return t?w().some(e=>t.closest(e)!=null):!1}function E(e=document.activeElement){return T(e)}var D=[`text`,`number`,`checkbox`];function O(e){return D.includes(e)}var k=`mg-inline-checkbox`;function A(e,t){let n=document.createElement(`input`);return n.className=`mg-cell-editor`,n.type=e,n.value=t,n.style.width=`100%`,n.style.height=`100%`,n.style.boxSizing=`border-box`,n}function j(e){return e==null||e===``||e===!1||e===`false`||e===0||e===`0`?!1:e===!0||e===`true`||e===1||e===`1`||!!e}function M(e){return e?`true`:`false`}function N(e){return M(e.checked)}var P=(e,t)=>{let n=A(`text`,e.formattedValue);return t.mountEl.appendChild(n),n},ee=(e,t)=>{let n=A(`number`,e.value==null||e.value===``?``:String(e.value));return t.mountEl.appendChild(n),n},te=(e,t)=>{let n=document.createElement(`input`);return n.type=`checkbox`,n.className=`mg-cell-editor ${k}`,n.checked=j(e.value),e.inline&&(n.addEventListener(`click`,e=>{e.stopPropagation()}),n.addEventListener(`change`,()=>{e.commit?.()})),t.mountEl.appendChild(n),n};function F(e){return e instanceof HTMLInputElement&&e.type===`checkbox`?N(e):e.value}var ne=new Map;function re(e,t){if(!e||O(e))throw Error(`Invalid cell editor name "${e}"`);ne.set(e,t)}function ie(e){return ne.delete(e)}function ae(e){return ne.get(e)}function oe(e){return ne.has(e)}function se(){return[...ne.keys()]}function ce(e,t={}){return t[e]??ne.get(e)}function le(e,t={}){return e===void 0?P:typeof e==`function`?e:O(e)?e===`number`?ee:e===`checkbox`?te:P:ce(e,t.byName)||(console.warn(`[magic-grid] Cell editor "${e}" is not registered; falling back to text editor.`),P)}var ue=class{onUnmountEditor;instanceEditors;constructor(e={}){this.onUnmountEditor=e.onUnmountEditor,this.instanceEditors={...e.byName??{}}}register(e,t){if(!e||O(e))throw Error(`Invalid cell editor name "${e}"`);this.instanceEditors[e]=t}unregister(e){return delete this.instanceEditors[e]}has(e){return e in this.instanceEditors||ce(e,this.instanceEditors)!==void 0}mount(e,t,n,r){let i=e.querySelector(`.mg-cell[data-col-id="${t.colId}"]`),a=i??e,o=document.createElement(`div`);o.className=`mg-cell-editor-host`,o.style.position=`absolute`,o.style.top=`0`,o.style.boxSizing=`border-box`,i?(o.style.left=`0`,o.style.width=`100%`,o.style.height=`100%`,i.classList.add(`mg-cell--editing`)):(o.style.left=`${t.left}px`,o.style.width=`${t.width}px`,o.style.height=`100%`),a.appendChild(o);let s=null,c={mountEl:o,clear:()=>{this.onUnmountEditor?.(o),o.replaceChildren()}},l={...n,setGetValue:e=>{s=e}},u=le(r,{byName:this.instanceEditors})(l,c);return u instanceof HTMLElement&&!o.contains(u)&&o.appendChild(u),{mountEl:o,getValue:()=>{if(s)return s();let e=o.querySelector(`input:not([type="hidden"]).mg-cell-editor, select.mg-cell-editor, textarea.mg-cell-editor`);if(e)return F(e);let t=o.querySelector(`input:not([type="hidden"]), select, textarea`);return t?F(t):n.formattedValue},getFocusTarget:()=>u instanceof HTMLElement?u:o.querySelector(`input:not([type="hidden"]), select, textarea, [tabindex]`)??o.firstElementChild,destroy:()=>{o.parentElement?.classList.remove(`mg-cell--editing`),c.clear(),o.remove()}}}},de=class{editing=null;mountedEditor=null;listenerTarget=null;onCommit=null;onCancel=null;onEditingStopped=null;onTab=null;onEditingInput=null;onCommitLifecycle=null;oldValue=void 0;blurCommitAfterClickListener=null;blurCommitFallbackTimer=null;pinnedRowIds=new Set;editorHost;keyboardPolicy={};phase=`idle`;commitController=null;inflightCommit=null;nextCommitId=0;handleEditorKeyDown=e=>{if(this.phase===`committing`){e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),this.cancelCommit());return}if(e.key===`Enter`){if(this.shouldDeferEnterCommit())return;e.preventDefault(),e.stopPropagation(),this.stopEditing(!0)}else if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),this.stopEditing(!1);else if(e.key===`Tab`){e.preventDefault(),e.stopPropagation();let t=this.onTab,n=e.shiftKey;this.stopEditing(!0).then(e=>{e?.committed&&t?.(n)})}else e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&this.onEditingInput?.()};handleEditorFocusOut=e=>{let t=e;requestAnimationFrame(()=>{this.isEditing()&&this.phase!==`committing`&&(this.isFocusWithinEditorSurface(t)||(this.clearPendingBlurCommit(),this.scheduleBlurCommitAfterClick()))})};constructor(e){this.editorHost=e??new ue}getEditingCell(){return this.editing}isEditing(){return this.editing!==null}isCommitting(){return this.phase===`committing`}getEditSessionPhase(){return this.phase}getEditorValue(){return this.mountedEditor?.getValue()??null}getEditorMountEl(){return this.mountedEditor?.mountEl??null}awaitCommitIdle(){return(this.inflightCommit??Promise.resolve()).then(()=>void 0)}isPinnedRow(e){return this.pinnedRowIds.has(e)}getPinnedRowIds(){return this.pinnedRowIds}cancelCommit(){this.phase===`committing`&&(this.commitController?.abort(),this.finishCommittingVisual(),this.phase=`editing`,this.commitController=null,this.onCommitLifecycle?.onAborted?.())}startEditing(e,t,n,r,i,a){this.stopEditing(!1),this.editing={rowId:t.id,colId:n.colId,rowIndex:t.rowIndex},this.oldValue=i,this.phase=`editing`,this.pinnedRowIds.add(t.id),this.onCommit=a.onCommit,this.onCancel=a.onCancel,this.onEditingStopped=a.onEditingStopped??null,this.onTab=a.onTab??null,this.onEditingInput=a.onEditingInput??null,this.onCommitLifecycle=a.onCommitLifecycle??null;let o={};this.keyboardPolicy=o;let s={rowId:t.id,rowIndex:t.rowIndex,colId:n.colId,value:i,data:t.data,formattedValue:r,...a.editorParams,stopEditing:(e=!0)=>this.stopEditing(e).then(()=>void 0),cancelCommit:()=>this.cancelCommit(),getEditPhase:()=>this.phase,validate:a.editorParams?.validate??(async()=>({valid:!0})),setKeyboardPolicy:e=>{Object.assign(o,e),this.keyboardPolicy=o}};this.mountedEditor=this.editorHost.mount(e,n,s,n.cellEditor),this.attachEditorListeners(this.mountedEditor),requestAnimationFrame(()=>{this.mountedEditor&&this.isEditing()&&this.focusEditor(this.mountedEditor)})}async stopEditing(e){if(!this.editing||!this.mountedEditor)return null;if(this.phase===`committing`)return e||this.cancelCommit(),this.inflightCommit;if(this.clearPendingBlurCommit(),!e)return this.cancelEditingSession();let t=this.commitEditingSession();this.inflightCommit=t;try{return await t}finally{this.inflightCommit===t&&(this.inflightCommit=null)}}destroy(){this.clearPendingBlurCommit(),this.cancelCommit(),this.mountedEditor&&(this.detachEditorListeners(),this.mountedEditor.destroy()),this.mountedEditor=null,this.editing=null,this.onCommit=null,this.onCancel=null,this.onEditingStopped=null,this.onTab=null,this.onEditingInput=null,this.onCommitLifecycle=null,this.oldValue=void 0,this.keyboardPolicy={},this.phase=`idle`,this.commitController=null,this.inflightCommit=null,this.pinnedRowIds.clear()}async commitEditingSession(){if(!this.editing||!this.mountedEditor)return null;let t=this.editing,n=this.mountedEditor,r=n.getValue(),i=this.onCommit,a=this.oldValue,o=++this.nextCommitId;this.phase=`committing`,this.setCommittingVisual(!0),this.onCommitLifecycle?.onStarted?.();let s=e.s(o,this.commitController);this.commitController=s;let c={ok:!1};try{let e=await i?.(r,s.context);if(s.context.commitId!==o)return null;c=e??{ok:!0}}catch(t){if(e.c(t))c={ok:`aborted`};else throw t}finally{this.commitController===s&&(this.commitController=null),this.finishCommittingVisual()}if(s.context.commitId!==o||this.editing!==t)return null;if(this.onCommitLifecycle?.onFinished?.(c),c.ok===`aborted`)return this.phase=`editing`,this.onCommitLifecycle?.onAborted?.(),null;if(c.ok===!1){if(c.revert){let e=this.onEditingStopped;this.teardownEditorSession(n);let r={committed:!1,oldValue:a,newValue:void 0,rowId:t.rowId,colId:t.colId,rowIndex:t.rowIndex};return e?.(r),r}return this.phase=`editing`,this.focusEditor(n),null}let l=c.newValue===void 0?r:c.newValue;return this.finalizeSuccessfulCommit(t,n,a,l)}cancelEditingSession(){if(!this.editing||!this.mountedEditor)return null;let e=this.editing,t=this.mountedEditor,n=this.onCancel,r=this.onEditingStopped,i=this.oldValue;this.teardownEditorSession(t),n?.();let a={committed:!1,oldValue:i,newValue:void 0,rowId:e.rowId,colId:e.colId,rowIndex:e.rowIndex};return r?.(a),a}finalizeSuccessfulCommit(e,t,n,r){let i=this.onEditingStopped;this.teardownEditorSession(t);let a={committed:!0,oldValue:n,newValue:r,rowId:e.rowId,colId:e.colId,rowIndex:e.rowIndex};return i?.(a),a}teardownEditorSession(e){let t=this.editing;this.detachEditorListeners(),this.mountedEditor=null,this.editing=null,this.onCommit=null,this.onCancel=null,this.onEditingStopped=null,this.onTab=null,this.onEditingInput=null,this.onCommitLifecycle=null,this.oldValue=void 0,this.keyboardPolicy={},this.phase=`idle`,this.commitController=null,t&&this.pinnedRowIds.delete(t.rowId),e.destroy()}setCommittingVisual(e){if(!this.editing||!this.mountedEditor)return;let t=this.mountedEditor.mountEl.parentElement;((t?.classList.contains(`mg-cell`)?t.parentElement:t)?.querySelector(`.mg-cell[data-col-id="${this.editing.colId}"]`))?.classList.toggle(`mg-cell--committing`,e),this.mountedEditor.mountEl.classList.toggle(`mg-cell-editor-host--committing`,e)}finishCommittingVisual(){this.setCommittingVisual(!1)}attachEditorListeners(e){this.listenerTarget=e.mountEl,this.listenerTarget.addEventListener(`keydown`,this.handleEditorKeyDown,!0),this.listenerTarget.addEventListener(`focusout`,this.handleEditorFocusOut)}detachEditorListeners(){this.listenerTarget&&=(this.listenerTarget.removeEventListener(`keydown`,this.handleEditorKeyDown,!0),this.listenerTarget.removeEventListener(`focusout`,this.handleEditorFocusOut),null)}resolveFocusTarget(e){let t=e.getFocusTarget();return t?t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement?t:t.querySelector(`input:not([type="hidden"]), select, textarea`)??t:null}shouldDeferEnterCommit(){return this.keyboardPolicy.deferEnterCommit===!0}isFocusWithinEditorSurface(e){return!!(E()||e?.relatedTarget instanceof Node&&T(e.relatedTarget))}focusEditor(e){let t=this.resolveFocusTarget(e);t&&t.focus()}scheduleBlurCommitAfterClick(){let e=()=>{this.clearPendingBlurCommit(),!(!this.isEditing()||this.phase===`committing`)&&this.stopEditing(!0).then(e=>{e===null&&this.isEditing()&&this.mountedEditor&&this.focusEditor(this.mountedEditor)})};this.blurCommitAfterClickListener=t=>{T(t.target)||e()},window.addEventListener(`click`,this.blurCommitAfterClickListener,!1),this.blurCommitFallbackTimer=window.setTimeout(()=>{e()},300)}clearPendingBlurCommit(){this.blurCommitAfterClickListener&&=(window.removeEventListener(`click`,this.blurCommitAfterClickListener,!1),null),this.blurCommitFallbackTimer!==null&&(clearTimeout(this.blurCommitFallbackTimer),this.blurCommitFallbackTimer=null)}};function fe(e){return[...e.getLeftFixedColumnIndices(),...e.getCenterColumnIndices(),...e.getRightFixedColumnIndices()]}function pe(e,t){let n=t.indexOf(e);return n>=0?n:0}function me(e,t){return t[e]}function he(e){return e[0]??0}function ge(e){return e[e.length-1]??0}var _e=`__header__`,ve=`__footer__`;function ye(e){return e.rowIndex===-1}function be(e){return e.rowIndex===-2}function I(e){return ye(e)||be(e)}function xe(e={}){return{headerEnabled:e.headerEnabled??!1,footerEnabled:e.footerEnabled??!1}}function Se(e,t){return e===-1?_e:e===-2?ve:t(e)}var Ce=class{focus=null;getFocusedCell(){return this.focus}setFocusedCell(e){this.focus=e}clear(){this.focus=null}move(e,t,n,r,i,a={}){let o=this.focus??ke(t,n,r,i);if(!o)return null;let s=we(o,e,t,n,r,i,a);return this.focus=s,s}moveTab(e,t,n,r,i,a={}){let o=this.focus??ke(t,n,r,i);if(!o)return null;let s=Te(o,e,t,n,r,i,a);return this.focus=s,s}moveToEdge(e,t,n,r,i,a={}){let o=this.focus??ke(t,n,r,i);if(!o)return null;let s=Ee(o,e,t,n,r,i,a);return this.focus=s,s}};function we(e,t,n,r,i,a,o={}){let{headerEnabled:s,footerEnabled:c}=xe(o),l=r.length;if(n<=0||l<=0)return null;let u=e.rowIndex,d=pe(e.colIndex,r);t===`up`?u===-2?u=n-1:u===-1||(u===0?s&&(u=-1):--u):t===`down`?u=s&&u===-1?0:c&&u===n-1?-2:Math.min(n-1,u+1):t===`left`?d=Math.max(0,d-1):t===`right`&&(d=Math.min(l-1,d+1));let f=me(d,r),p=Se(u,i),m=f===void 0?void 0:a(f);return f===void 0||!p||!m||u===e.rowIndex&&f===e.colIndex?e:{rowId:p,colId:m,rowIndex:u,colIndex:f}}function Te(e,t,n,r,i,a,o={}){let{headerEnabled:s,footerEnabled:c}=xe(o),l=r.length;if(n<=0||l<=0)return null;let u=e.rowIndex,d=pe(e.colIndex,r);t?c&&u===-2&&d===0?(u=n-1,d=l-1):u===-2&&d>0?--d:s&&u===0&&d===0?(u=-1,d=l-1):s&&u===-1?d>0&&--d:d>0?--d:u>0&&(--u,d=l-1):s&&u===-1?d<l-1?d+=1:(u=0,d=0):u===-2?d<l-1&&(d+=1):d<l-1?d+=1:u<n-1?(u+=1,d=0):c&&u===n-1&&(u=-2,d=0);let f=me(d,r),p=Se(u,i),m=f===void 0?void 0:a(f);return f===void 0||!p||!m||u===e.rowIndex&&f===e.colIndex?e:{rowId:p,colId:m,rowIndex:u,colIndex:f}}function Ee(e,t,n,r,i,a,o={}){let{headerEnabled:s,footerEnabled:c}=xe(o),l=r.length;if(n<=0||l<=0)return null;let u=e.rowIndex,d=e.colIndex;t===`up`?u=s?-1:0:t===`down`?u=c?-2:n-1:t===`left`?d=he(r):t===`right`&&(d=ge(r));let f=Se(u,i),p=a(d);return!f||!p||u===e.rowIndex&&d===e.colIndex?e:{rowId:f,colId:p,rowIndex:u,colIndex:d}}function De(e,t,n,r,i,a,o,s={}){let c=r.length;if(n<=0||c<=0)return null;let l=e,u=n*c;for(let e=0;e<u;e++){let e=Te(l,t,n,r,i,a,s);if(!e||e.rowIndex===l.rowIndex&&e.colIndex===l.colIndex)return null;if(l=e,e.rowIndex!==-1&&e.rowIndex!==-2&&o(e.rowIndex,e.colId))return e}return null}function Oe(e,t,n){if(t.length===0)return null;if(t.length===1)return t[0]??null;let r=t.indexOf(e),i=r>=0?r:0;return t[n?(i-1+t.length)%t.length:(i+1)%t.length]??null}function ke(e,t,n,r){let i=he(t),a=n(0),o=r(i);return!a||!o||e<=0||t.length===0?null:{rowId:a,colId:o,rowIndex:0,colIndex:i}}var Ae=class{editing=null;onCommitRow=null;onFocusColChange=null;activeColId=null;onCancel=null;onRowEditingStopped=null;onCommitLifecycle=null;blurCommitAfterClickListener=null;blurCommitFallbackTimer=null;attachedListeners=[];pinnedRowIds=new Set;editorHost;phase=`idle`;commitController=null;inflightCommit=null;nextCommitId=0;handleEditorKeyDown=e=>{if(this.phase===`committing`){e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),this.cancelCommit());return}if(e.key===`Tab`){e.preventDefault(),e.stopPropagation(),this.navigateRowTab(e.shiftKey,this.resolveColIdFromEvent(e));return}if(e.key===`Enter`){let t=this.resolveColIdFromEvent(e);if((t?this.editing?.cells.get(t):void 0)?.keyboardPolicy.deferEnterCommit)return;e.preventDefault(),e.stopPropagation(),this.stopRowEditing(!0);return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),this.stopRowEditing(!1))};handleEditorBlur=e=>{let t=e;requestAnimationFrame(()=>{this.isEditing()&&this.phase!==`committing`&&(this.isFocusWithinRowEditors(t.relatedTarget)||(this.clearPendingBlurCommit(),this.scheduleBlurCommitAfterClick()))})};constructor(e){this.editorHost=e??new ue}getEditingRow(){return this.editing?{rowId:this.editing.rowId,rowIndex:this.editing.rowIndex}:null}getActiveColId(){return this.editing?this.activeColId&&this.editing.cells.has(this.activeColId)?this.activeColId:this.editing.focusColId&&this.editing.cells.has(this.editing.focusColId)?this.editing.focusColId:this.editing.cells.keys().next().value??null:null}focusEditingColumn(e){return this.editing?.cells.has(e)?(this.focusRowEditor(e),!0):!1}getEditingCells(){return this.editing?[...this.editing.cells.values()].map(e=>({rowId:this.editing.rowId,rowIndex:this.editing.rowIndex,colId:e.colId})):[]}getEditorValue(e){return this.editing?.cells.get(e)?.mountedEditor.getValue()??null}getEditorMountEl(e){return this.editing?.cells.get(e)?.mountedEditor.mountEl??null}isEditing(){return this.editing!==null}isCommitting(){return this.phase===`committing`}getEditSessionPhase(){return this.phase}awaitCommitIdle(){return(this.inflightCommit??Promise.resolve()).then(()=>void 0)}cancelCommit(){this.phase===`committing`&&(this.commitController?.abort(),this.finishCommittingVisual(),this.phase=`editing`,this.commitController=null,this.onCommitLifecycle?.onAborted?.())}isPinnedRow(e){return this.pinnedRowIds.has(e)}getPinnedRowIds(){return this.pinnedRowIds}startRowEditing(e){if(e.columns.length===0)return!1;this.stopRowEditing(!1);let{rowElement:t,rowNode:n,columns:r,focusColId:i}=e,a=new Map;for(let e of r){let n={},r={...e.params,autoFocus:i==null||e.column.colId===i,stopEditing:(e=!0)=>this.stopRowEditing(e).then(()=>void 0),cancelCommit:()=>this.cancelCommit(),getEditPhase:()=>this.phase,setKeyboardPolicy:t=>{Object.assign(n,t);let r=a.get(e.column.colId);r&&(r.keyboardPolicy=n)}},o=this.editorHost.mount(t,e.column,r,e.column.cellEditor);a.set(e.column.colId,{colId:e.column.colId,column:e.column,oldValue:e.oldValue,mountedEditor:o,keyboardPolicy:n}),this.attachEditorListeners(o)}return this.editing={rowId:n.id,rowIndex:n.rowIndex,rowElement:t,focusColId:i,cells:a},this.phase=`editing`,this.onCommitRow=e.onCommitRow,this.onFocusColChange=e.onFocusColChange??null,this.onCancel=e.onCancel??null,this.onRowEditingStopped=e.onRowEditingStopped??null,this.onCommitLifecycle=e.onCommitLifecycle??null,this.pinnedRowIds.add(n.id),queueMicrotask(()=>{this.focusRowEditor(i)}),!0}async stopRowEditing(e){if(!this.editing)return null;if(this.phase===`committing`)return e||this.cancelCommit(),this.inflightCommit;if(this.clearPendingBlurCommit(),!e)return this.cancelRowEditingSession();let t=this.commitRowEditingSession();this.inflightCommit=t;try{return await t}finally{this.inflightCommit===t&&(this.inflightCommit=null)}}destroy(){this.clearPendingBlurCommit(),this.cancelCommit(),this.teardownEditingState(),this.onCommitRow=null,this.onFocusColChange=null,this.activeColId=null,this.onCancel=null,this.onRowEditingStopped=null,this.onCommitLifecycle=null,this.phase=`idle`,this.commitController=null,this.inflightCommit=null,this.pinnedRowIds.clear()}async commitRowEditingSession(){if(!this.editing)return null;let t=this.editing,n=new Map;for(let e of t.cells.values())n.set(e.colId,e.mountedEditor.getValue());let r=this.onCommitRow;if(!r)return null;let i=++this.nextCommitId;this.phase=`committing`,this.setCommittingVisual(!0),this.onCommitLifecycle?.onStarted?.();let a=e.s(i,this.commitController);this.commitController=a;let o={ok:!1,failedColId:``};try{let e=await r(n,a.context);if(a.context.commitId!==i)return null;o=e}catch(t){if(e.c(t))o={ok:`aborted`};else throw t}finally{this.commitController===a&&(this.commitController=null),this.finishCommittingVisual()}return a.context.commitId!==i||this.editing!==t?null:(this.onCommitLifecycle?.onFinished?.(o),o.ok===`aborted`?(this.phase=`editing`,this.onCommitLifecycle?.onAborted?.(),null):o.ok===!1?o.revert?this.revertRowEditingSession(t):(this.phase=`editing`,this.focusRowEditor(o.failedColId),null):this.finalizeSuccessfulCommit(t,o.cells))}revertRowEditingSession(e){let t=this.onRowEditingStopped,n=[];for(let t of e.cells.values())n.push({colId:t.colId,committed:!1,oldValue:t.oldValue,newValue:void 0});this.teardownEditingState(),this.onCommitRow=null,this.onFocusColChange=null,this.activeColId=null,this.onCancel=null,this.onRowEditingStopped=null,this.onCommitLifecycle=null;let r={rowId:e.rowId,rowIndex:e.rowIndex,committed:!1,cells:n};return t?.(r),r}cancelRowEditingSession(){if(!this.editing)return null;let e=this.editing,t=this.onCancel,n=this.onRowEditingStopped,r=[];for(let t of e.cells.values())r.push({colId:t.colId,committed:!1,oldValue:t.oldValue,newValue:void 0});this.teardownEditingState(),t?.(),this.onCommitRow=null,this.onFocusColChange=null,this.activeColId=null,this.onCancel=null,this.onRowEditingStopped=null,this.onCommitLifecycle=null;let i={rowId:e.rowId,rowIndex:e.rowIndex,committed:!1,cells:r};return n?.(i),i}finalizeSuccessfulCommit(e,t){let n=this.onRowEditingStopped;this.teardownEditingState(),this.onCommitRow=null,this.onFocusColChange=null,this.activeColId=null,this.onCancel=null,this.onRowEditingStopped=null,this.onCommitLifecycle=null;let r={rowId:e.rowId,rowIndex:e.rowIndex,committed:!0,cells:t};return n?.(r),r}teardownEditingState(){if(this.editing){for(let e of this.editing.cells.values())e.mountedEditor.destroy();this.detachEditorListeners(),this.editing=null,this.phase=`idle`,this.commitController=null,this.pinnedRowIds.clear()}}setCommittingVisual(e){if(this.editing){this.editing.rowElement.classList.toggle(`mg-row--committing`,e);for(let t of this.editing.cells.values())t.mountedEditor.mountEl.classList.toggle(`mg-cell-editor-host--committing`,e)}}finishCommittingVisual(){this.setCommittingVisual(!1)}attachEditorListeners(e){let t=e.getFocusTarget();if(e.mountEl.addEventListener(`keydown`,this.handleEditorKeyDown,!0),t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement){t.addEventListener(`blur`,this.handleEditorBlur),this.attachedListeners.push({mountEl:e.mountEl,blurTarget:t});return}this.attachedListeners.push({mountEl:e.mountEl,blurTarget:null})}detachEditorListeners(){for(let e of this.attachedListeners)e.mountEl.removeEventListener(`keydown`,this.handleEditorKeyDown,!0),e.blurTarget&&e.blurTarget.removeEventListener(`blur`,this.handleEditorBlur);this.attachedListeners.length=0}focusRowEditor(e){if(!this.editing)return;let t=e&&this.editing.cells.has(e)?e:this.editing.focusColId&&this.editing.cells.has(this.editing.focusColId)?this.editing.focusColId:this.editing.cells.keys().next().value;t&&((this.editing.cells.get(t)?.mountedEditor.getFocusTarget())?.focus(),this.activeColId=t,this.editing.focusColId=t,this.onFocusColChange?.(t))}getOrderedEditableColIds(){return this.editing?[...this.editing.cells.values()].sort((e,t)=>e.column.left-t.column.left).map(e=>e.colId):[]}navigateRowTab(e,t){if(!this.editing)return;let n=this.getOrderedEditableColIds(),r=t??this.activeColId??n[0];if(!r)return;let i=Oe(r,n,e);i&&this.focusRowEditor(i)}resolveColIdFromEvent(e){if(!this.editing)return;let t=e.target;if(t instanceof Node){for(let e of this.editing.cells.values())if(e.mountedEditor.mountEl.contains(t))return e.colId}}isFocusWithinRowEditors(e){if(!this.editing)return!1;if(e instanceof Node){for(let t of this.editing.cells.values())if(t.mountedEditor.mountEl.contains(e))return!0;if(T(e))return!0}return E()}scheduleBlurCommitAfterClick(){let e=()=>{this.clearPendingBlurCommit(),!(!this.isEditing()||this.phase===`committing`)&&this.stopRowEditing(!0).then(e=>{e===null&&this.isEditing()&&this.focusRowEditor()})};this.blurCommitAfterClickListener=t=>{T(t.target)||e()},window.addEventListener(`click`,this.blurCommitAfterClickListener,!1),this.blurCommitFallbackTimer=window.setTimeout(()=>{e()},300)}clearPendingBlurCommit(){this.blurCommitAfterClickListener&&=(window.removeEventListener(`click`,this.blurCommitAfterClickListener,!1),null),this.blurCommitFallbackTimer!==null&&(clearTimeout(this.blurCommitFallbackTimer),this.blurCommitFallbackTimer=null)}},je=`__index__`,Me=40,Ne=1;function Pe(e){return Math.max(40,e??40)}function Fe(e={}){return{label:e.label??``,width:Pe(e.width),start:e.start??1,focusMode:e.focusMode===`single`?`single`:`multiple`,syncToSelectionColumn:e.syncToSelectionColumn??!1,showRowDragHandle:e.showRowDragHandle??!1,enableRowResizer:e.enableRowResizer??!1,headerAlign:e.headerAlign??`center`,headerValign:e.headerValign??`center`,align:e.align??`center`,valign:e.valign??`center`,footerAlign:e.footerAlign??`center`,footerValign:e.footerValign??`center`,index:e.index}}function Ie(e={}){return{showIndexColumn:e.showIndexColumn??!1,indexColumn:Fe(e.indexColumn)}}function L(e){return e===je}function Le(e,t){return e.key??e.prop??`col_${t}`}function Re(e){return e===!1?{mode:!1,groupSelectsChildren:!0}:e==null?{mode:`single`,groupSelectsChildren:!0}:typeof e==`string`?{mode:e===`multiple`?`multiple`:`single`,groupSelectsChildren:!0}:{mode:e.mode===`multiple`?`multiple`:`single`,groupSelectsChildren:e.groupSelectsChildren??!0}}var ze=`__select__`,Be=40,Ve=40,He=`全选`;function Ue(e){return Math.max(40,e??40)}function We(e={}){return{width:Ue(e.width),selectAllLabel:e.selectAllLabel??`全选`,rowLabel:e.rowLabel,headerAlign:e.headerAlign??`center`,headerValign:e.headerValign??`center`,align:e.align??`center`,valign:e.valign??`center`,footerAlign:e.footerAlign??`center`,footerValign:e.footerValign??`center`}}function Ge(e={}){if(e.rowSelection==null)return{enabled:!1,mode:`single`,selectionColumn:We(e.selectionColumn)};let t=Re(e.rowSelection),n=t.mode!==!1;return{enabled:n,mode:n&&t.mode!==!1?t.mode:`single`,selectionColumn:We(e.selectionColumn)}}function R(e){return e===ze}var Ke=`__expand__`,qe=`__detail`,Je=`mg-cell__row-expand`,Ye=`mg-cell__row-expand--expanded`,Xe=`mg-full-width-rows-container`,Ze=`mg-full-width-row`,Qe=`mg-full-width-row__content`,$e=`mg-full-width-row--last`;function et(e){return!0}function tt(e={}){return{masterDetail:e.masterDetail??!1,isRowMaster:e.isRowMaster??et,masterDefaultExpanded:e.masterDefaultExpanded??0,detailRowHeight:e.detailRowHeight??200,detailRowAutoHeight:e.detailRowAutoHeight??!1,embedFullWidthRows:e.embedFullWidthRows??!1,showExpandColumn:e.showExpandColumn??!1,getDetailRowData:e.getDetailRowData,detailCellRenderer:e.detailCellRenderer}}function z(e){return e===Ke}function nt(e){return z(e.colId)||e.rowExpand}function rt(e,t){return L(t)||R(t)||z(t)?!1:e??!1}function it(e,t){return rt(e.rowExpand,t)}function at(e){return e??`data`}function ot(e){return`${e}${qe}`}function st(e){return e.endsWith(qe)}function B(e){return at(e.rowKind)===`detail`||st(e.id)}function ct(e){return at(e.rowKind)===`data`&&!st(e.id)}function lt(e,t){let n=typeof e==`function`?e(t):e;return!Number.isFinite(n)||n<1?200:Math.floor(n)}function ut(e,t){return{rowId:e,expanded:!0,source:t}}function dt(e,t){return{rowId:e,expanded:!1,source:t}}function ft(e){return e.available!==!1}function pt(e){return e.filter(ft)}var mt=`__group__`,ht=`group::`,gt=`__header`,_t=`__footer`,vt=`(Blanks)`,yt=`mg-cell__group-expand`,bt=`mg-cell__group-expand--expanded`,xt=`mg-cell__group-indent-`,St=`mg-row--group-header`,Ct=`mg-row--group-footer`,wt=`mg-cell--group-auto`;function Tt(e={}){return{rowGrouping:e.rowGrouping??!1,groupDefaultExpanded:e.groupDefaultExpanded??-1,showGroupHeader:e.showGroupHeader??!1,showGroupFooter:e.showGroupFooter??!1,groupDisplayType:e.groupDisplayType??`singleColumn`,showGroupColumn:e.showGroupColumn??!1,autoGroupColumnDef:e.autoGroupColumnDef,groupKeyCreator:e.groupKeyCreator,groupComparator:e.groupComparator,groupFooterLabel:e.groupFooterLabel??`小计`,groupCellRenderer:e.groupCellRenderer}}function V(e){return e===mt}function Et(e){return V(e.colId)}function Dt(e,t){return L(t)||R(t)||z(t)||V(t)?!1:e??!1}function Ot(e,t){return Dt(e.rowGroup,t)}function kt(e,t){if(Ot(e,t))return e.rowGroupIndex}function At(e,t){if(!(L(t)||R(t)||z(t)||V(t)))return e.groupAgg}function jt(e,t){return L(t)||R(t)||z(t)||V(t)?!1:e.showGroupHeaderCell??!1}function Mt(e,t){return L(t)||R(t)||z(t)||V(t)?!1:e.showGroupFooterCell??!1}function Nt(e,t){if(!(L(t)||R(t)||z(t)||V(t)))return e.groupFooterLabel}function Pt(e){return Et(e)||e.showGroupHeaderCell}function Ft(e){return Et(e)||e.showGroupFooterCell}function It(e,t){return Xt(t)?Jt(t)?Pt(e):Yt(t)?Ft(e):!1:!1}function Lt(e){let t=pt(e).map((e,t)=>{let n=Le(e,t);return{colId:n,rowGroup:Ot(e,n),rowGroupIndex:e.rowGroupIndex,index:t}}).filter(e=>e.rowGroup);return t.sort((e,t)=>{let n=e.rowGroupIndex??e.index,r=t.rowGroupIndex??t.index;return n===r?e.index-t.index:n-r}),t.map(e=>e.colId)}function Rt(e,t){return e&&t}function zt(e,t){return e&&t.length>0}function Bt(e){if(e==null||e===``)return vt;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);if(e instanceof Date)return Number.isNaN(e.getTime())?vt:e.toISOString();try{return JSON.stringify(e)}catch{return vt}}function Vt(e,t,n,r){let i=`${ht}L${e}::${encodeURIComponent(t)}::${encodeURIComponent(n)}`;return r?`${r}::${i}`:i}function Ht(e){return e.join(`/`)}function Ut(e){return`${e}${gt}`}function Wt(e){return`${e}${_t}`}function Gt(e){return e.endsWith(gt)}function Kt(e){return e.endsWith(_t)}function qt(e){return Gt(e)||Kt(e)?e.slice(0,-8):null}function Jt(e){return e.rowKind===`groupHeader`||Gt(e.id)}function Yt(e){return e.rowKind===`groupFooter`||Kt(e.id)}function Xt(e){return e.group===!0||Jt(e)||Yt(e)}function Zt(e){return Xt(e)?!1:e.rowKind===void 0||e.rowKind===`data`}function Qt(e){return{groupId:e.groupId,expanded:e.expanded,field:e.field,key:e.key,level:e.level,source:e.source}}function $t(e,t){return{columns:[...e],source:t}}var en=`__tree__`,tn=`mg-cell__tree-expand`,nn=`mg-cell__tree-expand--expanded`,rn=`mg-cell__tree-expand--loading`,an=`mg-cell__tree-indent-`,on=`mg-cell--tree-auto`;function sn(e){return e||(({data:e,dataPath:t})=>{Array.isArray(e.pathSegments)&&(e.pathSegments=[...t])})}function cn(e={}){let t=e.treeLazyLoad??!1,n=e.loadTreeChildren;return t&&typeof n!=`function`&&console.warn(`[magic-grid] treeLazyLoad: true requires loadTreeChildren callback.`),{tree:e.tree??!1,getDataPath:e.getDataPath,treeDragScope:e.treeDragScope??`siblings`,setDataPath:sn(e.setDataPath),showTreeColumn:e.showTreeColumn??!0,autoTreeColumnDef:e.autoTreeColumnDef,treeValueGetter:e.treeValueGetter,treeDisplayType:e.treeDisplayType??`singleColumn`,treeLazyLoad:t,hasTreeChildren:e.hasTreeChildren,loadTreeChildren:n}}function ln(e){return e===en}function un(e,t){return e===!0&&typeof t==`function`}function dn(e,t,n){return un(e,n)&&t!==!1}function H(e){return e.dataPath!=null&&e.dataPath.length>0}function fn(e){e.forEach((e,t)=>{let n=Le(e,t);(n===`__tree__`||L(n)||R(n)||z(n)||V(n))&&console.warn(`[magic-grid] Column colId "${n}" is reserved for system columns and will be ignored.`)})}function pn(e,t,n,r,i){return{rowId:e,expanded:t,level:n,dataPath:r,source:i}}function mn(e,t){if(e&&typeof t!=`function`)throw Error(`[magic-grid] tree: true requires getDataPath callback.`)}var hn=`__mg_summary__`;function gn(e={}){return{showSummary:e.showSummary??!1,summaryScope:e.summaryScope??`displayed`,summaryRowHeight:e.summaryRowHeight,summaryMethod:e.summaryMethod}}function _n(e,t){return e??t}var vn=`mg-cell--disabled`,yn=`data-disabled`;function bn(e={}){return{isRowDisabled:e.isRowDisabled}}function xn(e){return L(e)||R(e)||z(e)||ln(e)||V(e)}function Sn(e,t,n,r){return!((t??`data`)!==`data`||r===`__mg_summary__`||!n||xn(e))}function Cn(e,t){return t==null||t===!1?!1:t===!0||t(e)}function wn(e){let{column:t,rowNode:n,isRowDisabled:r}=e;if(!Sn(t.colId,n.rowKind,t.prop,n.id))return!1;if(Cn({data:n.data,rowId:n.id,rowIndex:n.rowIndex},r)||t.disabled===!0)return!0;let{cellDisabled:i}=t;return i===!0||typeof i==`function`&&i({data:n.data,rowId:n.id,colId:t.colId})}function Tn(e={}){return bn(e)}function En(e,t,n){return wn({column:e,rowNode:t,isRowDisabled:n?.isRowDisabled})}function Dn(e,t){return{...e,isRowDisabled:t}}var On=Symbol(`CELL_EDIT_REJECTED`);function kn(e){return e===On}function An(e){return L(e.colId)||R(e.colId)||nt({colId:e.colId,rowExpand:!1})}function jn(e,t){let{editable:n}=e;return n===void 0||n===!1?!1:n===!0||n(t)}function U(e,t,n){return An(e)||!e.prop||En(e,t,n)?!1:jn(e,t.data)}function Mn(e,t=`singleClick`){return e.editType??t}function Nn(e){return{editBehavior:e.editBehavior??`cell`,editType:e.editType??`singleClick`}}function W(e){return e===`row`}function Pn(e){let t=e.trim();if(t===``)return On;let n=Number(t);return Number.isFinite(n)?n:On}function Fn(e){return e===`true`}function In(e,t,n){try{return t.valueParser?t.valueParser(e,n):t.cellEditor===`number`?Pn(e):t.cellEditor===`checkbox`?Fn(e):e}catch{return On}}function Ln(e,t,n){if(e.valueSetter){let r=e.valueSetter({...t,newValue:n,signal:new AbortController().signal});if(r instanceof Promise)throw Error(`Async valueSetter requires applyCellEditValue / commitRowEditCells`);return r}let r=e.prop;return r?(t.data[r]=n,!0):!1}async function Rn(t,n,r,i){let a=i??new AbortController().signal;if(e.l(a),t.valueSetter)try{let i=await t.valueSetter({...n,newValue:r,signal:a});return e.l(a),i}catch(t){if(e.c(t))throw t;return!1}let o=t.prop;return o?(n.data[o]=r,!0):!1}var zn=`data-custom-bg`;function Bn(e){return L(e)||z(e)||ln(e)||V(e)}function Vn(e,t,n,r){return(t??`data`)!==`data`||r===`__mg_summary__`?!1:R(e)?!0:!(!n||Bn(e))}function Hn(e,t){return Vn(e.colId,t.rowKind,e.prop,t.id)}function Un(e={}){return{rowStyle:e.rowStyle}}function Wn(e){return typeof e==`function`}function Gn(e={}){return Un(e)}function Kn(e){let t={};for(let n of[e.row,e.column,e.cell])n&&(n.backgroundColor!==void 0&&(t.backgroundColor=n.backgroundColor),n.color!==void 0&&(t.color=n.color));return t}function qn(e,t){return{data:t.data,rowId:t.id,colId:e.colId,rowIndex:t.rowIndex,column:{colId:e.colId,prop:e.prop}}}function Jn(e,t){let n=t?.rowStyle;return n==null?null:typeof n==`function`?n({data:e.data,rowId:e.id,rowIndex:e.rowIndex,rowKind:e.rowKind})??null:n}function Yn(e){let{cellStyle:t}=e;return t==null||Wn(t)?null:t}function Xn(e,t){let{cellStyle:n}=e;return n==null||!Wn(n)?null:n(qn(e,t))??null}function Zn(e,t,n){return Hn(e,t)?Kn({row:Jn(t,n),column:Yn(e),cell:Xn(e,t)}):{}}function Qn(e,t,n){return Zn(e,t,n)}function $n(e,t){return{...e,rowStyle:t}}function er(e){if(e==null||!Array.isArray(e))return null;let t=e.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean);return t.length>0?t:null}function tr(e){if(e==null)return null;if(Array.isArray(e)){let t=er(e);return t?{errors:t}:null}if(typeof e==`object`&&Array.isArray(e.errors)){let t=er(e.errors);if(!t)return null;let n=e.colIds?.filter(e=>typeof e==`string`&&e.length>0);return n?.length?{errors:t,colIds:n}:{errors:t}}return null}function nr(e,t){if(t?.length)return[...t];let n=new Set(e);return n.has(`min`)&&n.has(`max`)?[`min`,`max`]:e.length>0?[e[0]]:[]}async function rr(t,n,r,i){e.l(i);let a=t.cellValidator;if(!a)return null;try{let t=await a({...n,parsedValue:r,signal:i});return e.l(i),er(t)}catch(t){throw e.c(t),t}}async function ir(t,n){if(!t)return null;e.l(n.signal);try{let r=await t(n);return e.l(n.signal),tr(r)}catch(t){throw e.c(t),t}}async function ar(e,t,n,r){let i=await rr(e,t,n,r??new AbortController().signal);return i?{valid:!1,errors:i}:{valid:!0}}function or(e,t){return t.index?String(t.index(e)):String(e+t.start)}function sr(e,t,n){if(L(t.colId))return n?or(e.rowIndex,n):String(e.rowIndex+1);if(R(t.colId)||z(t.colId)||t.rowExpand||V(t.colId))return``;if(Yt(e)&&t.groupAgg)return e.__groupAggValues?.[t.colId]?.formattedValue??``;let r=t.prop??t.colId,i=r?e.data[r]:void 0;return t.valueGetter&&(i=t.valueGetter(e.data,i)),t.formatter?t.formatter(e.data,i):i==null?``:String(i)}function G(e,t){let n=t.prop??t.colId,r=n?e.data[n]:void 0;return t.valueGetter&&(r=t.valueGetter(e.data,r)),r}async function cr(t,n,r,i,a,o,s){if(!r.prop)return{ok:!0,newValue:o};try{let e=In(i,r,a);if(kn(e))return{ok:!1,revert:!0};let c=await rr(r,a,e,s),l=t.invalidEditValueMode;return c&&l!==`keep`?{ok:!1,revert:!0}:o===e?{ok:!0,newValue:e}:await Rn(r,a,e,s)?(t.applyTransaction({update:[n.data]}),t.eventBus.emit(`cellValueChanged`,{rowId:n.id,colId:r.colId,oldValue:o,newValue:e,rowNode:n}),t.syncPinnedRows(),{ok:!0,newValue:e}):{ok:!1,revert:!0}}catch(t){if(e.c(t))return{ok:`aborted`};throw t}}var lr=class{onUnmountEditor;instanceEditors;constructor(e={}){this.onUnmountEditor=e.onUnmountEditor,this.instanceEditors={...e.byName??{}}}mount(e,t,n){this.onUnmountEditor?.(e),e.replaceChildren();let r=null,i=null,a={mountEl:e,clear:()=>{this.onUnmountEditor?.(e),e.replaceChildren()}},o={...n,inline:!0,setGetValue:e=>{r=e}},s=le(t.cellEditor,{byName:this.instanceEditors})(o,a);return s instanceof HTMLElement&&(i=s,e.contains(s)||e.appendChild(s)),{mountEl:e,getValue:()=>{if(r)return r();let t=e.querySelector(`input:not([type="hidden"]).mg-cell-editor, select.mg-cell-editor, textarea.mg-cell-editor`);if(t)return F(t);let i=e.querySelector(`input:not([type="hidden"]), select, textarea`);return i?F(i):n.formattedValue},getFocusTarget:()=>i||(e.querySelector(`input:not([type="hidden"]), select, textarea, [tabindex]`)??e.firstElementChild),destroy(){a.clear()}}}};function ur(e,t,n,r,i,a,o){return`${e}:${t}:${n}:${String(r)}:${i}:${a}:${o===void 0?`default`:typeof o==`function`?`fn`:o}`}var dr=class{host;commits=new Map;inFlight=new Map;deps;constructor(e){this.deps=e,this.host=new lr({onUnmountEditor:e.onUnmountEditor,byName:e.byName})}getRefreshContext(){return{host:this.host,createParams:(e,t)=>this.createParams(e,t),commit:(e,t,n,r)=>this.commit(e,t,n,r)}}isCommitting(){return this.commits.size>0}async awaitCommitIdle(){this.inFlight.size!==0&&await Promise.all([...this.inFlight.values()])}cancelCommit(e,t){if(e&&t){this.abortCommit(`${e}:${t}`,!0);return}for(let e of[...this.commits.keys()])this.abortCommit(e,!0)}createParams(e,t){let n={rowId:e.id,rowIndex:e.rowIndex,colId:t.colId,value:G(e,t),data:e.data,formattedValue:sr(e,t),stopEditing:async()=>void 0,cancelCommit:()=>this.cancelCommit(e.id,t.colId),getEditPhase:()=>this.isCellCommitting(e.id,t.colId)?`committing`:`idle`,inline:!0};return{...n,validate:async r=>{let i={...n,validate:async()=>({valid:!0})},a;try{if(a=In(fr(G(e,t),t),t,i),kn(a))return{valid:!1,errors:[`Invalid value`]}}catch(e){return{valid:!1,errors:[e instanceof Error?e.message:`Invalid value`]}}return ar(t,i,a,r?.signal)}}}isCellCommitting(e,t){return this.commits.has(`${e}:${t}`)}abortCommit(t,n){let r=this.commits.get(t);r&&(r.userCancelled=n,r.controller.abort(new e.o))}async commit(e,t,n,r){let i=`${e.id}:${t.colId}`,a=this.runCommit(e,t,n,r,i);this.inFlight.set(i,a);try{return await a}finally{this.inFlight.get(i)===a&&this.inFlight.delete(i)}}async runCommit(e,t,n,r,i){this.abortCommit(i,!1);let a=new AbortController,o={controller:a,rowId:e.id,colId:t.colId,rowIndex:e.rowIndex,userCancelled:!1};this.commits.set(i,o),this.deps.eventBus.emit(`cellCommitStarted`,{rowId:e.id,colId:t.colId,rowIndex:e.rowIndex});let s=this.createParams(e,t),c=await cr({eventBus:this.deps.eventBus,applyTransaction:this.deps.applyTransaction,syncPinnedRows:this.deps.syncPinnedRows,invalidEditValueMode:this.deps.invalidEditValueMode},e,t,n,s,r,a.signal);return this.commits.get(i)===o&&this.commits.delete(i),c.ok===`aborted`?(o.userCancelled&&this.deps.eventBus.emit(`editCommitAborted`,{rowId:e.id,colId:t.colId,rowIndex:e.rowIndex}),this.deps.eventBus.emit(`cellCommitFinished`,{rowId:e.id,colId:t.colId,rowIndex:e.rowIndex,committed:!1,aborted:o.userCancelled}),!1):(this.deps.eventBus.emit(`cellCommitFinished`,{rowId:e.id,colId:t.colId,rowIndex:e.rowIndex,committed:c.ok===!0,aborted:!1}),c.ok===!0)}};function fr(e,t){return t.cellEditor===`checkbox`?e===!0||e===`true`||e===1||e===`1`?`true`:`false`:e==null?``:String(e)}var pr=class{registry=new Map;invalidColIds=new Set;domStates=[];showCellInvalid(e){this.setRowCellInvalid(e.rowId,e.rowElement,{colId:e.colId,errors:e.errors,editorMountEl:e.editorMountEl})}showCellsInvalid(e){this.setRowInvalid(e.rowId,e.rowElement,e.cells)}setRowInvalid(e,t,n){this.clearRowDom(e,t);let r=new Map;for(let i of n)i.errors.length&&(r.set(i.colId,i.errors),t&&this.applyCellDom(e,t,i));r.size===0?this.registry.delete(e):this.registry.set(e,r),this.rebuildInvalidColIds()}applyGridValidationFeedback(e,t){let n=new Set(t.map(e=>e.rowId));for(let t of[...this.registry.keys()])if(!n.has(t)){let n=this.findRowElement(e,t);this.clearRow(t,n)}for(let n of t){let t=this.findRowElement(e,n.rowId);this.setRowInvalid(n.rowId,t,n.cells)}}applyRowsValidationFeedback(e,t){for(let n of t){let t=this.findRowElement(e,n.rowId);this.setRowInvalid(n.rowId,t,n.cells)}}clearRow(e,t){this.clearRowDom(e,t??null),this.registry.delete(e),this.rebuildInvalidColIds()}clearRowCell(e,t,n){let r=this.registry.get(e);if(r?.delete(n),r?.size===0&&this.registry.delete(e),t){let e=t.querySelector(`.mg-cell[data-col-id="${n}"]`);e?.classList.remove(`mg-cell--invalid`),e?.removeAttribute(`title`)}let i=[];for(let t of this.domStates)(t.rowId!==e||t.colId!==n)&&i.push(t);this.domStates=i,this.rebuildInvalidColIds()}setRowCellInvalid(e,t,n){if(!n.errors.length){this.clearRowCell(e,t,n.colId);return}if(t){for(let r of this.domStates)r.rowId===e&&r.colId===n.colId&&this.removeCellDom(r,t);this.domStates=this.domStates.filter(t=>t.rowId!==e||t.colId!==n.colId)}let r=this.registry.get(e);r||(r=new Map,this.registry.set(e,r)),r.set(n.colId,n.errors),t&&this.applyCellDom(e,t,n),this.rebuildInvalidColIds()}clear(e){e&&this.removeRegistryDom(e),this.domStates=[],this.registry.clear(),this.rebuildInvalidColIds()}syncDom(e){this.domStates=[];for(let[t,n]of this.registry){let r=this.findRowElement(e,t);if(r)for(let[e,i]of n)i.length&&this.applyCellDom(t,r,{colId:e,errors:i})}}hasInvalidCells(){return this.registry.size>0}hasColErrors(e){return this.invalidColIds.has(e)}getInvalidColIds(){return this.invalidColIds}syncHeaderDom(e,t){for(let n of t){let t=e.querySelector(`.mg-header-cell[data-col-id="${n.colId}"]`);t&&(t.classList.toggle(`mg-header-cell--required`,n.validationRequired===!0),t.classList.toggle(`mg-header-cell--invalid`,this.invalidColIds.has(n.colId)))}}getRegistry(){return this.registry}migrateRowId(e,t,n){let r=this.registry.get(e);r&&(this.registry.delete(e),this.registry.set(t,r));for(let n of this.domStates)n.rowId===e&&(n.rowId=t);let i=this.findRowElement(n,e);i&&(i.dataset.rowId=t)}rebuildInvalidColIds(){let e=new Set;for(let t of this.registry.values())for(let n of t.keys())e.add(n);this.invalidColIds=e}findRowElement(e,t){return e.querySelector(`.mg-row[data-row-id="${t}"]`)}clearRowDom(e,t){let n=[];for(let r of this.domStates){if(r.rowId!==e){n.push(r);continue}t&&this.removeCellDom(r,t)}this.domStates=n}applyCellDom(e,t,n){let r=n.errors.join(`
|
|
2
|
-
`),i=t.querySelector(`.mg-cell[data-col-id="${n.colId}"]`);i?.classList.add(`mg-cell--invalid`),i?.setAttribute(`title`,r),this.domStates.push({rowId:e,colId:n.colId,editorMountEl:n.editorMountEl??null})}removeCellDom(e,t){let n=t.querySelector(`.mg-cell[data-col-id="${e.colId}"]`);n?.classList.remove(`mg-cell--invalid`),n?.removeAttribute(`title`)}removeRegistryDom(e){for(let[t,n]of this.registry){let r=this.findRowElement(e,t);if(r)for(let e of n.keys()){let t=r.querySelector(`.mg-cell[data-col-id="${e}"]`);t?.classList.remove(`mg-cell--invalid`),t?.removeAttribute(`title`)}}}},mr=`__mg_tmp_`,hr=0;function gr(){return hr+=1,`${Date.now().toString(36)}_${hr.toString(36)}`}function _r(){return`${mr}${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():gr()}`}function vr(e){return e.startsWith(mr)}function yr(e){return e==null||e===``}function br(e){if(e.group)return!0;let t=e.rowKind;return t===`detail`||t===`groupHeader`||t===`groupFooter`}function xr(e,t){if(e.isTransient)return null;let n=e.data[t];return!br(e)&&(typeof n==`number`||typeof n==`string`)?n:e.id}function Sr(e,t,n,r){if(r?.isTransient||vr(n))return null;let i=e[t];return typeof i==`number`||typeof i==`string`?i:n}function Cr(e,t){if(vr(e))return null;let n=t.getRowById(e);return n?xr(n,t.rowKey):e}function wr(e,t){return e.map(e=>Cr(e,t))}function Tr(e){return{fromNode:t=>xr(t,e.rowKey),fromInternal:t=>Cr(t,e),fromInternalList:t=>wr(t,e)}}function Er(e,t){let n=Tr(t);return{...e,cellErrors:e.cellErrors.map(e=>({...e,rowId:n.fromInternal(String(e.rowId))}))}}function K(e,t){return t.fromInternal(e)}function Dr(e,t){return t.fromInternalList(e)}function Or(e,t,n){let r=Tr(n);switch(e){case`cellClicked`:case`rowClicked`:case`rowDoubleClicked`:case`cellFocused`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`selectionChanged`:return{selectedRowIds:Dr(t.selectedRowIds,r)};case`indexFocusChanged`:return{focusedRowIds:Dr(t.focusedRowIds,r)};case`cellValueChanged`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`cellEditingStarted`:case`cellEditingStopped`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`rowEditingStarted`:case`rowEditingStopped`:case`rowValueChanged`:case`rowCommitStarted`:case`rowCommitFinished`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`cellCommitStarted`:case`cellCommitFinished`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`editCommitAborted`:{let e=t;return{...e,rowId:e.rowId==null?e.rowId:K(e.rowId,r)}}case`cellValidationFailed`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`rowValidationFailed`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`rowsAdded`:return{rows:t.rows.map(e=>({...e,rowId:Sr(e.data,n.rowKey,String(e.rowId),{isTransient:e.isTransient})}))};case`rowsRemoved`:return{rows:t.rows.map(e=>({...e,rowId:Sr(e.data,n.rowKey,String(e.rowId))}))};case`rowIdPromoted`:{let e=t,n=vr(e.oldRowId)?null:K(e.oldRowId,r);return{...e,oldRowId:n,newRowId:K(e.newRowId,r)}}case`rowMoved`:{let e=t;return{...e,rowId:K(e.rowId,r),parentRowId:e.parentRowId===void 0?void 0:e.parentRowId===null?null:K(e.parentRowId,r)}}case`rowDragEnd`:{let e=t;return{...e,rowId:K(e.rowId,r),rowIds:e.rowIds?Dr(e.rowIds,r):void 0,parentRowId:e.parentRowId===void 0?void 0:e.parentRowId===null?null:K(e.parentRowId,r)}}case`rowDragCommitStarted`:{let e=t;return{...e,rowId:K(e.rowId,r),rowIds:Dr(e.rowIds,r),leaderRowId:K(e.leaderRowId,r),parentRowId:e.parentRowId===void 0?void 0:e.parentRowId===null?null:K(e.parentRowId,r)}}case`rowDragCommitFinished`:{let e=t;return{...e,rowId:K(e.rowId,r),leaderRowId:K(e.leaderRowId,r)}}case`rowHeightChanged`:{let e=t;return{...e,rows:e.rows.map(e=>({...e,rowId:K(e.rowId,r)}))}}case`rowExpanded`:case`rowCollapsed`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`treeNodeOpened`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`treeChildrenLoading`:case`treeChildrenLoaded`:case`treeChildrenLoadFailed`:{let e=t;return{...e,parentRowId:K(e.parentRowId,r)}}case`cellCommentChanged`:{let e=t;return{...e,rowId:K(e.rowId,r)}}default:return t}}var kr=class{listeners=new Map;destroyed=!1;projector=null;setProjector(e){this.projector=e}on(e,t){if(this.destroyed)return()=>void 0;let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n));let r=t;return n.add(r),()=>{n?.delete(r)}}emit(e,t){if(this.destroyed)return;let n=this.listeners.get(e);if(!n)return;let r=this.projector?this.projector(e,t):t;for(let e of n)e(r)}destroy(){this.destroyed=!0,this.listeners.clear(),this.projector=null}};function Ar(e){return(t,n)=>Or(t,n,e)}var jr=class{mode;selectedIds=new Set;anchorIndex=-1;constructor(e=`single`){this.mode=e===`multiple`?`multiple`:`single`}getSelectedRowIds(){return[...this.selectedIds]}isSelected(e){return this.selectedIds.has(e)}clear(){this.selectedIds.clear(),this.anchorIndex=-1}removeRowIds(e){let t=!1;for(let n of e)this.selectedIds.delete(n)&&(t=!0);return t}migrateRowId(e,t){return this.selectedIds.has(e)?(this.selectedIds.delete(e),this.selectedIds.add(t),!0):!1}getAnchorIndex(){return this.anchorIndex}isMultiple(){return this.mode===`multiple`}setAnchorIndex(e){this.anchorIndex=e}selectRow(e,t,n,r={}){let{ctrlKey:i=!1,shiftKey:a=!1,toggleOnReselect:o=!1}=r;if(this.mode===`multiple`&&a&&this.anchorIndex>=0&&t>=0)return this.selectRangeBetween(this.anchorIndex,t,n,r.rangeSelection);if(this.mode===`multiple`&&i)return this.selectedIds.has(e)?this.selectedIds.delete(e):this.selectedIds.add(e),this.anchorIndex=t,!0;if(o&&this.selectedIds.has(e))return this.selectedIds.delete(e),this.anchorIndex===t&&(this.anchorIndex=-1),!0;if(this.mode===`multiple`&&o){let n=!this.selectedIds.has(e);return this.selectedIds.add(e),this.anchorIndex=t,n}let s=this.selectedIds.size!==1||!this.selectedIds.has(e);return this.selectedIds.clear(),this.selectedIds.add(e),this.anchorIndex=t,s}selectRangeBetween(e,t,n,r){let i=Math.min(e,t),a=Math.max(e,t),o=new Set;if(r){let{rowCount:e,getAllRowIdAt:t}=r;for(let r=0;r<e;r++){let e=t(r);if(!e)continue;let s=n(r),c=r>=i&&r<=a;if(s){c&&o.add(s);continue}this.selectedIds.has(e)&&o.add(e)}}else for(let e=i;e<=a;e++){let t=n(e);t&&o.add(t)}let s=o.size!==this.selectedIds.size||[...o].some(e=>!this.selectedIds.has(e));return this.selectedIds=o,s}isAllVisibleRowsSelected(e,t){if(e===0)return!1;for(let n=0;n<e;n++){let e=t(n);if(e&&!this.selectedIds.has(e))return!1}return!0}selectAllVisibleRows(e,t){let n=!1;for(let r=0;r<e;r++){let e=t(r);e&&!this.selectedIds.has(e)&&(this.selectedIds.add(e),n=!0)}return n&&e>0&&(this.anchorIndex=0),n}deselectAllVisibleRows(e,t){let n=!1;for(let r=0;r<e;r++){let e=t(r);e&&this.selectedIds.delete(e)&&(n=!0)}return n}replaceSelectionWithVisibleRows(e,t){return this.selectAllVisibleRows(e,t)}toggleSelectAllVisibleRows(e,t){return this.isAllVisibleRowsSelected(e,t)?this.deselectAllVisibleRows(e,t):this.selectAllVisibleRows(e,t)}replaceWithRowIds(e,t=-1){let n=new Set(e),r=n.size!==this.selectedIds.size||[...n].some(e=>!this.selectedIds.has(e));return this.selectedIds=n,this.anchorIndex=t,r}addRowId(e,t=-1){if(this.mode===`single`){let n=this.selectedIds.size!==1||!this.selectedIds.has(e);return this.selectedIds.clear(),this.selectedIds.add(e),this.anchorIndex=t,n}return!this.selectedIds.has(e)&&(this.selectedIds.add(e),t>=0&&(this.anchorIndex=t),!0)}toggleRowId(e,t){return this.selectedIds.has(e)?this.removeRowIds([e]):this.addRowId(e,t)}},Mr=()=>!0;function Nr(e){return e??Mr}function Pr(e,t,n){return e({data:t.data,rowId:xr(t,n),rowIndex:t.rowIndex})}var Fr=class extends jr{getFocusedRowIds(){return this.getSelectedRowIds()}};function Ir(e,t){return e===t}function Lr(e,t,n){return e.length===0||!Ir(t,n)?[]:[...e]}function Rr(e){let t=[],n=[],r=[];return e.forEach((e,i)=>{let a=e.fixed??null;a===`left`?t.push(i):a===`right`?r.push(i):n.push(i)}),{left:t,center:n,right:r}}function zr(e){let t=[],n=[],r=[];return e.forEach((e,i)=>{if(e.hidden)return;let a=e.fixed??null;a===`left`?t.push(i):a===`right`?r.push(i):n.push(i)}),{left:t,center:n,right:r}}function Br(e){return L(e)||R(e)}function q(e){return e.fixed??null}function Vr(e){for(let t=0;t<e.length;t++){let n=e[t];if(!(!n||q(n)!==`left`)&&!Br(n.colId))return t}return e.length}function Hr(e){for(let t=0;t<e.length;t++){let n=e[t];if(!n||q(n)!==`left`||!Br(n.colId))return t}let t=0;for(let n of e){if(q(n)!==`left`)break;t+=1}return t}function Ur(e,t,n){let r=e[t];return r?q(r)===n:!1}function Wr(e,t,n){if(n!==void 0)return n;if(t>=e.length)return`right`;let r=e[t];return r?q(r):null}function Gr(e,t,n){return n===`left`?Hr(e):n===`right`?e.length:t.center.length>0?t.center[0]:t.left.length>0?t.left[t.left.length-1]+1:Vr(e)}function Kr(e,t,n){if(n===`left`)return t.center.length>0?t.center[0]:t.right.length>0?t.right[0]:e.length;if(n===`right`)return e.length;if(t.center.length>0){let n=t.center[t.center.length-1];if(t.right.length>0){let r=t.right[0];return r>n?r:Math.min(n+1,e.length-1)}return e.length}return t.right.length>0?t.right[0]:e.length}function qr(e){let{columns:t,colId:n,toGlobalIndex:r,toFixed:i}=e;if(r<0||r>t.length)return!1;let a=t.findIndex(e=>e.colId===n);if(a<0||a===r||Br(n))return!1;let o=t[a];if(!o?.movable)return!1;let s=q(o),c=Wr(t,r,i);if(r<t.length){let e=t[r];if(!e||Br(e.colId))return!1}else if(i===void 0)return!1;if(s===c)return r===t.length||s===`left`&&r<Vr(t)?!1:Ur(t,r,s);if(e.allowCrossLaneColumnMove!==!0)return!1;if(c===`left`){let e=s===c?Vr(t):Hr(t);if(r<t.length&&r<e)return!1}return!0}function Jr(e,t,n,r){return e.findIndex(e=>e.colId===t)<0?null:Wr(e,n,r)}function Yr(e){if(!qr(e))return null;let t=e.columns.map(e=>e.colId),n=t.indexOf(e.colId);return n<0?null:e.toGlobalIndex===e.columns.length?(t.splice(n,1),t.push(e.colId),t):(t.splice(n,1),t.splice(e.toGlobalIndex,0,e.colId),t)}function Xr(e){let t=e.columns.findIndex(t=>t.colId===e.colId);if(t<0)return null;let n=e.direction===`right`?t+1:t-1;if(!qr({...e,toGlobalIndex:n}))return null;let r=e.columns[t],i=e.columns[n];return!r||!i||q(r)!==q(i)?null:n}function Zr(e){let t=e.leftFixedWidth+e.centerTotalWidth;return e.laneIndices.map(n=>{let r=e.columns[n];if(!r||Br(r.colId)||r.colId===e.sourceColId)return null;let i=e.targetFixed===`right`?r.left-t:r.left;return{colId:r.colId,globalIndex:n,left:i,width:r.width}}).filter(e=>e!=null)}function Qr(e){let t=e.laneHeaderCells.filter(t=>{let n=e.columns[t.globalIndex];return n&&t.colId!==e.sourceColId&&!Br(t.colId)&&q(n)===e.targetFixed});if(t.length===0)return e.clientX<e.laneRectLeft||e.clientX>e.laneRectRight?null:{globalIndex:Gr(e.columns,e.fixedGroups,e.targetFixed),toFixed:e.targetFixed};for(let n of t)if(e.clientX<n.rectLeft+n.rectWidth/2)return{globalIndex:n.globalIndex};let n=Kr(e.columns,e.fixedGroups,e.targetFixed);return e.targetFixed===`right`&&n===e.columns.length&&e.fixedGroups.right.length===0?{globalIndex:n,toFixed:`right`}:{globalIndex:n}}function $r(e){let t=e.targetFixed===`left`?e.fixedGroups.left:e.targetFixed===`right`?e.fixedGroups.right:e.fixedGroups.center,n=Zr({columns:e.columns,laneIndices:t,targetFixed:e.targetFixed,leftFixedWidth:e.leftFixedWidth,centerTotalWidth:e.centerTotalWidth,sourceColId:e.sourceColId});if(n.length===0)return e.clientX<e.laneRectLeft||e.clientX>e.laneRectRight?null:{globalIndex:Gr(e.columns,e.fixedGroups,e.targetFixed),toFixed:e.targetFixed};for(let t of n)if(e.sectionX<t.left+t.width/2)return{globalIndex:t.globalIndex};let r=Kr(e.columns,e.fixedGroups,e.targetFixed);return e.targetFixed===`right`&&r===e.columns.length&&e.fixedGroups.right.length===0?{globalIndex:r,toFixed:`right`}:{globalIndex:r}}function ei(e){return!L(e)&&!R(e)}function ti(e,t){return e.center.length>0?e.center[0]:e.right.length>0?e.right[0]:e.left.length>0?e.left[e.left.length-1]+1:t}function ni(e){if(!ei(e.colId))return null;let t=e.columns.find(t=>t.colId===e.colId);if(!t)return null;let n=q(t);return n===e.fixed?null:e.fixed===`left`?{toGlobalIndex:Kr(e.columns,e.fixedGroups,`left`),toFixed:`left`}:e.fixed===`right`?{toGlobalIndex:e.columns.length,toFixed:`right`}:n===`right`?{toGlobalIndex:e.fixedGroups.right[0]??e.columns.length,toFixed:null}:{toGlobalIndex:ti(e.fixedGroups,e.columns.length),toFixed:null}}var ri={left:`--align-h-left`,center:`--align-h-center`,right:`--align-h-right`},ii={top:`--align-v-top`,center:`--align-v-center`,bottom:`--align-v-bottom`},ai=[...Object.values(ri),...Object.values(ii)];function oi(e={}){return{headerAlign:e.headerAlign,headerValign:e.headerValign,align:e.align,valign:e.valign,footerAlign:e.footerAlign,footerValign:e.footerValign}}function si(e,t={}){return{headerAlign:e.headerAlign??t.headerAlign??`center`,headerValign:e.headerValign??t.headerValign??`center`,align:e.align??t.align??`center`,valign:e.valign??t.valign??`center`,footerAlign:e.footerAlign??t.footerAlign??`center`,footerValign:e.footerValign??t.footerValign??`center`}}function ci(e,t,n,r){for(let t of ai)e.classList.remove(`${r}${t}`);e.classList.add(`${r}${ri[t]}`),e.classList.add(`${r}${ii[n]}`)}var li=5,ui=50;function di(e={}){return{columnMovable:e.columnMovable??!0,suppressMoveWhenColumnDragging:e.suppressMoveWhenColumnDragging??!1,suppressColumnMoveAnimation:e.suppressColumnMoveAnimation??!1,allowCrossLaneColumnMove:e.allowCrossLaneColumnMove??!1}}function fi(e,t){return e!==!1&&t}function pi(e={}){return{resizable:e.resizable??!0,colResizeDefault:e.colResizeDefault??null}}function mi(e,t,n){return L(n)||R(n)?!1:e??t}function hi(e,t){return t===`shift`?!e:e}function gi(e,t,n,r,i){let a=e.map(e=>({colId:e.colId,width:t.getColumnWidth(e.colId)})),o=i&&i.length>0?i.map(e=>({colId:e,width:t.getColumnWidth(e)})):null;return{columns:a,column:a.length===1?a[0]??null:null,finished:n,flexColumns:o,source:r}}var _i=[`group`,`filter`,`sort`,`aggregate`,`map`],vi=[`tree`,`filter`,`sort`,`map`],yi=[`sort`,`filter`,`map`];function bi(e){switch(e){case`tree`:return vi;case`group`:return _i;default:return yi}}function xi(e){return`predicate`in e}function Si(e){return e!=null&&e.trim()!==``}function Ci(e){return Mi(e.type)?!0:e.type===`inRange`?Si(e.filter)&&Si(e.filterTo):Si(e.filter)}function wi(e){return e?e.conditions&&e.conditions.length>0?e.conditions:[{type:e.type,filter:e.filter,filterTo:e.filterTo}]:[]}function Ti(e){return e.operator??`AND`}function Ei(e){return e?.setValues}function Di(e){return wi(e).some(Ci)}function Oi(e){return e.setValues!==void 0}function ki(e){return e??`text`}function Ai(e){return{caseSensitive:e?.caseSensitive??!0,locale:e?.locale}}function ji(e){return e!=null&&e.trim()!==``}function Mi(e){return e===`blank`||e===`notBlank`}function Ni(e){return e?xi(e)?!0:Di(e)||Oi(e):!1}function Pi(e,t){return Ni(t[e])}function Fi(e,t){if(ji(t))return!0;for(let t of Object.values(e))if(Ni(t))return!0;return!1}var Ii=`mg-row--span-top`;function Li(e={}){return{enableCellSpan:e.enableCellSpan??!1}}function Ri(e){return e}function zi(e){return!Number.isFinite(e)||e<1?1:Math.floor(e)}function Bi(e,t){if(!(L(t)||R(t)))return e}function Vi(e,t){if(!(L(t)||R(t)))return e}function Hi(e,t){if(!(L(t)||R(t)))return e}function Ui(e,t){return Bi(e.colSpan,t)}function Wi(e,t){return Vi(e.rowSpan,t)}function Gi(e,t){return Hi(e.spanRows,t)}function Ki(e,t){return e?`rowSpan`:t===!0||typeof t==`function`?`spanRows`:`none`}function qi(e){return e===!0||typeof e==`function`}var Ji=`mg-cell__row-resize-handle`,Yi=`mg-cell--row-resizing`,Xi=`mg-cell--auto-height`;function Zi(e={},t){let n=e.rowHeightMin??t,r=e.rowHeightMax??null;return{getRowHeight:e.getRowHeight,rowHeightMin:Math.max(1,n),rowHeightMax:r==null?null:Math.max(n,r)}}function Qi(e,t){return L(t)||R(t)?!1:e??!1}function $i(e,t){return Qi(e.autoHeight,t)}function ea(e,t,n){let r=Math.max(t,e);return n==null?r:Math.min(n,r)}function ta(e,t,n){return{rows:e.map(e=>({...e})),finished:t,source:n}}var na=`mg-cell__row-drag-handle`,ra=`mg-cell--row-dragging`,ia=`mg-row-drop-indicator`,aa=`mg-row-drag-ghost`,oa=`mg-row-dragging--drop-forbidden`,sa=`mg-row--row-drag-committing`,ca=`magic-grid--row-drag-committing`;function la(e={}){return{rowDragManaged:e.rowDragManaged??!0,rowDragCommitMode:e.rowDragCommitMode??`sync`}}function ua(e,t){return L(t)||R(t)?!1:e??!1}function da(e,t){return ua(e.rowDrag,t)}function fa(e,t,n=!1){return!n&&t&&e}function pa(e,t,n,r=!1){return e?!fa(t,n,r):!1}function J(e,t,n,r,i=!0,a){let o={rowId:e,fromIndex:t,toIndex:n,source:r,finished:i};return a?.displayIndex!==void 0&&(o.displayIndex=a.displayIndex),a?.parentRowId!==void 0&&(o.parentRowId=a.parentRowId),a?.siblingIndex!==void 0&&(o.siblingIndex=a.siblingIndex),a?.treeLevel!==void 0&&(o.treeLevel=a.treeLevel),o}function ma(e,t,n,r,i){return{rowId:e,rowIds:r&&r.length>1?[...r]:void 0,displayIndex:t,finished:n,...i?{parentRowId:i.parentRowId,siblingIndex:i.siblingIndex,treeLevel:i.treeLevel}:{}}}function ha(e){return{rowId:e.leaderRowId,rowIds:[...e.rowIds],leaderRowId:e.leaderRowId,displayIndex:e.displayIndex,parentRowId:e.treeDrop?.parentRowId,siblingIndex:e.treeDrop?.siblingIndex,treeLevel:e.treeDrop?.treeLevel}}function ga(e){return{commitId:e.commitId,rowId:e.leaderRowId,leaderRowId:e.leaderRowId,committed:e.committed,aborted:e.aborted,reason:e.reason}}function _a(e,t,n){return{signal:n.signal,commitId:n.commitId,rowIds:[...e.rowIds],leaderRowId:e.leaderRowId,moves:[...e.moves],displayIndex:e.displayIndex,parentRowId:e.treeDrop?.parentRowId===void 0?void 0:e.treeDrop.parentRowId===null?null:String(e.treeDrop.parentRowId),siblingIndex:e.treeDrop?.siblingIndex,treeLevel:e.treeDrop?.treeLevel,nestUnderRowId:t??void 0}}function va(e){return e.length===0?[]:[e[0]]}function ya(e={}){return va(e.defaultSort??[])}function ba(e={}){return{defaultSort:ya(e),sortable:e.sortable??!1,showUnsortedSortHintOnHover:e.showUnsortedSortHintOnHover??!1}}function xa(e,t,n){return L(n)||R(n)?!1:e??t}var Sa=`current`,Ca=`tree`;function wa(e={}){return{filterable:e.filterable??!1,filterSetValueMode:e.filterSetValueMode??`current`,filterSetDateLayoutMode:e.filterSetDateLayoutMode??`tree`}}function Ta(e,t,n){return L(n)||R(n)||z(n)||V(n)?!1:e??t}var Ea=`overlay`;function Da(e){return e===`inline`?`inline`:Ea}function Oa(e,t){return L(e)||R(e)?Ea:Da(t)}function ka(e){return L(e.colId)||R(e.colId)||Da(e.cellEditorMode)!==`inline`?!1:e.cellEditor!=null}function Aa(e){return L(e)||R(e)||z(e)||ln(e)||V(e)}function ja(e,t){return!Aa(e)&&t.hidden===!0}function Ma(e){return!e.hidden}function Na(e){return e.filter(e=>Ma(e))}function Pa(e){return Na(e).length}function Fa(e){let t=[];for(let n of e)!n.hidden||Aa(n.colId)||t.push({colId:n.colId,label:n.label??n.prop??n.colId});return t}var Ia=`.mg-cell__text:not([hidden])`,La=`.mg-header-cell__text`,Ra=`.mg-footer-cell__text:not([hidden])`,za=[`.mg-status-bar__panel`,`[data-mg-tooltip-anchor]`].join(`, `),Ba=[Ia,La,Ra].join(`, `),Va=`mg-tooltip`;function Ha(e){return L(e)||R(e)||z(e)||ln(e)||V(e)}function Ua(e,t){return Ha(e)?!0:t.suppressTooltip===!0}function Wa(e={}){let t=e.enableTooltips??!0;return{enableTooltips:t,tooltipShowMode:e.tooltipShowMode??(t?`whenTruncated`:`never`),tooltipShowDelay:e.tooltipShowDelay??500,tooltipSwitchShowDelay:e.tooltipSwitchShowDelay??200,tooltipHideDelay:e.tooltipHideDelay??3e3,tooltipInteraction:e.tooltipInteraction??!1,tooltipMouseTrack:e.tooltipMouseTrack??!1,tooltipComponent:e.tooltipComponent,tooltipComponentParams:e.tooltipComponentParams}}function Ga(e){return e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight}function Ka(e){return!e.enableTooltips||e.mode===`never`||!e.text?!1:e.mode===`always`||!e.isAutoHeight&&Ga(e.anchorEl)}var qa={left:[],center:[],right:[]},Ja=class{columns=[];totalWidth=0;fixedGroups=qa;leftFixedWidth=0;rightFixedWidth=0;centerTotalWidth=0;gridAlignDefaults={};columnMovableDefault=!0;allowCrossLaneColumnMove=!1;gridResizableDefault=!0;gridSortableDefault=!1;gridFilterableDefault=!1;constructor(e=[],t={},n={},r={},i,a,o,s){this.gridAlignDefaults=r;let c=di(i);this.columnMovableDefault=c.columnMovable,this.allowCrossLaneColumnMove=c.allowCrossLaneColumnMove;let l=pi(a);this.gridResizableDefault=l.resizable,this.gridSortableDefault=ba(o).sortable,this.gridFilterableDefault=wa(s).filterable,this.setColumns(e,t,n)}setColumns(e,t={},n={},r,i,a,o,s){if(r!==void 0&&(this.gridAlignDefaults=r),i!==void 0){let e=di(i);this.columnMovableDefault=e.columnMovable,this.allowCrossLaneColumnMove=e.allowCrossLaneColumnMove}a!==void 0&&(this.gridResizableDefault=pi(a).resizable),o!==void 0&&(this.gridSortableDefault=ba(o).sortable),s!==void 0&&(this.gridFilterableDefault=wa(s).filterable);let c=pt(e),l=this.columns.map(e=>e.colId),u=new Map(this.columns.map(e=>[e.colId,e])),d=c.map((e,r)=>{let i=this.parseColumn(e,r,t,n),a=u.get(i.colId);return a&&(a.defHidden===i.defHidden&&(i.hidden=a.hidden),a.defWidth===i.defWidth&&a.defFlex===i.defFlex&&(i.width=a.width,i.flex=a.flex),a.defFixed===i.defFixed&&(i.fixed=a.fixed)),i});if(l.length===0)this.columns=d;else{let e=new Map(d.map(e=>[e.colId,e])),t=[],n=new Set;for(let r of l){let i=e.get(r);i&&(t.push(i),n.add(r))}for(let e of d)n.has(e.colId)||t.push(e);this.columns=t}this.rebuildDisplayedLayout()}setColumnsHidden(e,t){let n=[];for(let r of e){if(Aa(r))continue;let e=this.columns.find(e=>e.colId===r);!e||e.hidden===t||(e.hidden=t,n.push(r))}return n.length>0&&this.rebuildDisplayedLayout(),n}isColumnHidden(e){return this.getColumnById(e)?.hidden}getDisplayedColumnIds(){return Na(this.columns).map(e=>e.colId)}getDisplayedColumnIdsInLaneOrder(){let e=[],t=new Set,{left:n,center:r,right:i}=this.fixedGroups;for(let a of[...n,...r,...i]){let n=this.columns[a];!n||n.hidden||t.has(n.colId)||(t.add(n.colId),e.push(n.colId))}return e}rebuildDisplayedLayout(){this.fixedGroups=zr(this.columns),this.positionColumns()}setColumnMoveGridOptions(e){this.columnMovableDefault=e.columnMovable,this.allowCrossLaneColumnMove=e.allowCrossLaneColumnMove;for(let e of this.columns){if(L(e.colId)||R(e.colId)||z(e.colId)){e.movable=!1;continue}e.movable=fi(e.defMovable,this.columnMovableDefault)}}setColumnResizeGridOptions(e){this.gridResizableDefault=e.resizable;for(let e of this.columns){if(L(e.colId)||R(e.colId)||z(e.colId)){e.resizable=!1;continue}e.resizable=mi(e.defResizable,this.gridResizableDefault,e.colId)}}setColumnSortGridOptions(e){this.gridSortableDefault=e.sortable;for(let e of this.columns){if(L(e.colId)||R(e.colId)||z(e.colId)||V(e.colId)){e.sortable=!1;continue}e.sortable=xa(e.defSortable,this.gridSortableDefault,e.colId)}}setColumnFilterGridOptions(e){this.gridFilterableDefault=e.filterable;for(let e of this.columns){if(L(e.colId)||R(e.colId)||z(e.colId)||V(e.colId)){e.filterable=!1;continue}e.filterable=Ta(e.defFilterable,this.gridFilterableDefault,e.colId)}}getColumnCount(){return this.columns.length}getColumn(e){return this.columns[e]}getColumnById(e){return this.columns.find(t=>t.colId===e)}getColAfter(e){let t=Na(this.columns),n=t.findIndex(t=>t.colId===e);if(!(n<0||n>=t.length-1))return t[n+1]}getColumnWidth(e){return this.getColumnById(e)?.width??100}getColumnInitialWidth(e){return this.getColumnById(e)?.initialWidth??100}getTotalWidth(){return this.totalWidth}getColumns(){return this.columns}getDisplayedColumns(){return Na(this.columns)}getDisplayedColumnCount(){return Pa(this.columns)}getFixedColumnGroups(){return this.fixedGroups}getLeftFixedColumnIndices(){return this.fixedGroups.left}getRightFixedColumnIndices(){return this.fixedGroups.right}getCenterColumnIndices(){return this.fixedGroups.center}getLeftFixedWidth(){return this.leftFixedWidth}getRightFixedWidth(){return this.rightFixedWidth}getCenterTotalWidth(){return this.centerTotalWidth}isFixedColumn(e){let t=this.columns[e];return t?.fixed===`left`||t?.fixed===`right`}setColumnWidth(e,t){this.applyColumnWidthChanges([{colId:e,width:t}])}applyColumnWidthChanges(e,t){let n=!1,r=t?.widthSource!==`flex`;for(let t of e){let e=this.columns.find(e=>e.colId===t.colId);if(!e)continue;r&&e.flex!=null&&(e.flex=null);let i=Ya(t.width,e.minWidth,e.maxWidth);e.width!==i&&(e.width=i,n=!0)}return n&&this.positionColumns(),n}hasFlexColumns(){return this.columns.some(e=>!e.hidden&&e.flex!=null&&e.flex>0&&e.fixed!==`left`&&e.fixed!==`right`)}reorderColumns(e){if(e.length!==this.columns.length)return!1;let t=new Map(this.columns.map(e=>[e.colId,e])),n=[];for(let r of e){let e=t.get(r);if(!e)return!1;n.push(e)}return this.columns=n,this.rebuildDisplayedLayout(),!0}resetColumnsOrder(e){return this.reorderColumns(e)}resetColumnsWidth(){let e=[];for(let t of this.columns){if(Aa(t.colId))continue;let n=!1,r=Ya(t.defWidth,t.minWidth,t.maxWidth);t.width!==r&&(t.width=r,n=!0),t.flex!==t.defFlex&&(t.flex=t.defFlex,n=!0),n&&e.push(t.colId)}return e.length>0&&this.positionColumns(),e}moveColumn(e,t,n){let r=Jr(this.columns,e,t,n),i=Yr({columns:this.columns,colId:e,toGlobalIndex:t,fixedGroups:this.fixedGroups,toFixed:n,allowCrossLaneColumnMove:this.allowCrossLaneColumnMove});if(!i)return!1;let a=this.columns.find(t=>t.colId===e);return a&&q(a)!==r&&(a.fixed=r),this.reorderColumns(i)}setColumnFixed(e,t){let n=ni({columns:this.columns,fixedGroups:this.fixedGroups,colId:e,fixed:t});if(!n)return!1;let r=this.columns.findIndex(t=>t.colId===e);if(r<0)return!1;let i=this.columns[r];if(r===n.toGlobalIndex)return i.fixed=n.toFixed,this.rebuildDisplayedLayout(),!0;let a=Yr({columns:this.columns,colId:e,toGlobalIndex:n.toGlobalIndex,fixedGroups:this.fixedGroups,toFixed:n.toFixed,allowCrossLaneColumnMove:!0});return a?(i.fixed=Jr(this.columns,e,n.toGlobalIndex,n.toFixed),this.reorderColumns(a)):!1}parseColumn(e,t,n,r){let i=e.key??e.prop??`col_${t}`,a=e.minWidth??50,o=Ya(e.width??100,a,e.maxWidth),s=si(e,this.gridAlignDefaults),c=L(i)||R(i)||z(i)||V(i),l=e.fixed===`left`||e.fixed===`right`,u=!c&&!l&&e.flex!=null&&e.flex>0?e.flex:null;return e.cellEditorMode,e.cellEditor??r[i],e.cellEditorMode,e.cellEditor??r[i],{colId:i,prop:e.prop,label:e.label,width:o,initialWidth:o,minWidth:a,maxWidth:e.maxWidth,flex:u,suppressSizeToFit:c?!0:e.suppressSizeToFit??!1,left:0,fixed:e.fixed??null,sortable:!c&&xa(e.sortable,this.gridSortableDefault,i),filterable:!c&&Ta(e.filterable,this.gridFilterableDefault,i),filterType:ki(c?void 0:e.filterType),filterParams:Ai(c?void 0:e.filterParams),filterFormatter:c?void 0:e.filterFormatter,comparator:e.comparator,defMovable:c?void 0:e.movable,movable:!c&&fi(e.movable,this.columnMovableDefault),defResizable:c?void 0:e.resizable,defSortable:c?void 0:e.sortable,defFilterable:c?void 0:e.filterable,resizable:mi(!c&&e.resizable,this.gridResizableDefault,i),suppressAutoSize:c?!0:e.suppressAutoSize??!1,valueGetter:e.valueGetter,formatter:e.formatter,editable:e.editable,cellRenderer:e.cellRenderer??n[i],cellRendererMount:c?void 0:e.cellRendererMount,cellEditor:e.cellEditor??r[i],cellEditorMode:Oa(i,e.cellEditorMode),valueParser:e.valueParser,valueSetter:e.valueSetter,editType:e.editType,cellValidator:e.cellValidator,suppressPaste:c?!0:e.suppressPaste,useParserForClipboard:e.useParserForClipboard,useFormatterForClipboard:e.useFormatterForClipboard,validationRequired:e.validationRequired,summary:e.summary,summaryAgg:e.summaryAgg,summaryFormatter:e.summaryFormatter,autoHeight:$i(e,i),rowDrag:da(e,i),rowExpand:it(e,i),rowGroup:Ot(e,i),rowGroupIndex:kt(e,i),groupAgg:At(e,i),showGroupHeaderCell:jt(e,i),showGroupFooterCell:Mt(e,i),groupFooterLabel:Nt(e,i),suppressCellComments:c?!0:e.suppressCellComments,disabled:!c&&e.disabled,cellDisabled:c?void 0:e.cellDisabled,cellStyle:c?void 0:e.cellStyle,defWidth:o,defFlex:u,defFixed:c?null:e.fixed??null,defHidden:!c&&e.hidden===!0,defOrder:t,hidden:ja(i,e),tooltipField:c?void 0:e.tooltipField,tooltipValueGetter:c?void 0:e.tooltipValueGetter,headerTooltip:c?void 0:e.headerTooltip,headerTooltipValueGetter:c?void 0:e.headerTooltipValueGetter,suppressTooltip:Ua(i,e),tooltipComponent:c?void 0:e.tooltipComponent,tooltipComponentParams:c?void 0:e.tooltipComponentParams,colSpan:Ui(e,i),rowSpan:Wi(e,i),spanRows:Gi(e,i),...s}}hasAutoHeightColumns(){return this.columns.some(e=>e.autoHeight)}isColumnAutoHeight(e){return this.getColumnById(e)?.autoHeight??!1}getAutoHeightColumnIds(){return this.columns.filter(e=>e.autoHeight).map(e=>e.colId)}positionColumns(){this.leftFixedWidth=0,this.centerTotalWidth=0,this.rightFixedWidth=0;for(let e of this.fixedGroups.left){let t=this.columns[e];!t||t.hidden||(t.left=this.leftFixedWidth,t.rightOffset=void 0,this.leftFixedWidth+=t.width)}let e=0;for(let t of this.fixedGroups.center){let n=this.columns[t];!n||n.hidden||(n.left=e,n.rightOffset=void 0,e+=n.width)}this.centerTotalWidth=e;let t=this.leftFixedWidth+this.centerTotalWidth;for(let e of this.fixedGroups.right){let n=this.columns[e];!n||n.hidden||(n.left=t,t+=n.width,this.rightFixedWidth+=n.width)}let n=0;for(let e=this.fixedGroups.right.length-1;e>=0;e--){let t=this.fixedGroups.right[e],r=t===void 0?void 0:this.columns[t];!r||r.hidden||(r.rightOffset=n,n+=r.width)}this.totalWidth=this.leftFixedWidth+this.centerTotalWidth+this.rightFixedWidth}};function Ya(e,t,n){let r=Math.max(e,t);return n!==void 0&&(r=Math.min(r,n)),r}function Xa(e,t,n){if(e.length===0)return-1;let r=document.createElement(`form`);r.style.position=`fixed`,r.style.visibility=`hidden`,r.style.pointerEvents=`none`,r.style.top=`0`,r.style.left=`0`;for(let t of e)eo(t,r);t.appendChild(r);let i=r.offsetWidth+n;return r.remove(),i}function Za(e,t,n){let r=[];if(!n){let n=e.querySelector(`.mg-header-cell[data-col-id="${Qa(t)}"]`);n&&r.push(n)}return e.querySelectorAll(`.mg-cell[data-col-id="${Qa(t)}"]`).forEach(e=>{e instanceof HTMLElement&&r.push(e)}),r}function Qa(e){return typeof CSS<`u`&&typeof CSS.escape==`function`?CSS.escape(e):e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function $a(e,t,n,r){let i=e.querySelector(`.mg-viewport`);if(!i)return-1;let a=Za(e,t,n);return a.length===0?-1:Xa(a,i,r)}function eo(e,t){let n=e.cloneNode(!0);n.style.width=``,n.style.minWidth=``,n.style.maxWidth=``,n.style.left=``,n.style.right=``,n.style.position=`static`;let r=document.createElement(`div`);to(e,r),r.append(n),t.append(r)}function to(e,t){(e.classList.contains(`mg-header-cell`)||e.classList.contains(`mg-cell`)||e.classList.contains(`mg-footer-cell`))&&t.classList.add(`mg-row`);let n=e.parentElement;for(;n;){if(n.classList.contains(`mg-row`)||n.classList.contains(`mg-header-row`)||n.classList.contains(`mg-header-lane`)||n.classList.contains(`mg-body-lane`)){for(let e of n.classList)e!==`mg-row-position-absolute`&&t.classList.add(e);break}n=n.parentElement}}function no(e){return e.reduce((e,t)=>e+t.width,0)}function ro(e,t,n={}){if(t<=0)return[];let r=Object.fromEntries((n.columnLimits??[]).map(({colId:e,minWidth:t,maxWidth:n})=>[e,{minWidth:t,maxWidth:n}])),i=n.colIds?new Set(n.colIds):null,a=[],o=[];for(let t of e.getColumns()){if(t.hidden){o.push({colId:t.colId,width:t.width,minWidth:t.minWidth,maxWidth:t.maxWidth??2**53-1});continue}if(L(t.colId)||R(t.colId)){o.push({colId:t.colId,width:t.width,minWidth:t.minWidth,maxWidth:t.maxWidth??2**53-1});continue}let s=r[t.colId]??{},c=Math.max(t.minWidth,s.minWidth??n.defaultMinWidth??t.minWidth),l=Math.min(t.maxWidth??2**53-1,s.maxWidth??n.defaultMaxWidth??t.maxWidth??2**53-1),u={colId:t.colId,width:e.getColumnInitialWidth(t.colId),minWidth:c,maxWidth:l};if(t.suppressSizeToFit){u.width=t.width,o.push(u);continue}if(i&&!i.has(t.colId)){u.width=t.width,o.push(u);continue}a.push(u)}if(a.length===0||n.onlyScaleUp&&no(a)+no(o)>=t)return[];let s=new Map(a.map(t=>[t.colId,e.getColumnWidth(t.colId)])),c=a.map(e=>e.colId),l=!1;for(;!l;){l=!0;let e=t-no(o);if(e<=0){for(let e of a)e.width=e.minWidth;break}let n=no(a);if(n<=0)break;let r=e/n,i=e;for(let e=a.length-1;e>=0;e--){let t=a[e],n=e===0?i:Math.round(t.width*r);n<t.minWidth?(n=t.minWidth,o.push(t),a.splice(e,1),l=!1):n>t.maxWidth&&(n=t.maxWidth,o.push(t),a.splice(e,1),l=!1),t.width=n,i-=n}}let u=e=>a.find(t=>t.colId===e)?.width??o.find(t=>t.colId===e)?.width,d=[];for(let t of c){let n=u(t);n!=null&&(s.get(t)??e.getColumnWidth(t))!==n&&d.push({colId:t,newWidth:n})}return d}var io=class{mountEl;columnModel;autosizeOptions;constructor(e,t,n){this.mountEl=e,this.columnModel=t,this.autosizeOptions=n}setAutosizeOptions(e){this.autosizeOptions=e}getAutoSizeStrategy(){return this.autosizeOptions.autoSizeStrategy}autoSizeColumn(e,t){let n=this.columnModel.getColumnById(e);if(!n?.resizable||n.suppressAutoSize||L(e)||R(e))return null;let r=t??this.autosizeOptions.skipHeaderOnAutoSize,i=$a(this.mountEl,e,r,this.autosizeOptions.autoSizePadding);return i<=0?null:{colId:e,newWidth:ao(n.minWidth,n.maxWidth,i)}}autoSizeColumns(e,t){let n=[];for(let r of e){let e=this.autoSizeColumn(r,t);e&&n.push(e)}return n}autoSizeAllColumns(e){let t=this.columnModel.getColumns().filter(e=>e.resizable&&!e.suppressAutoSize&&!L(e.colId)&&!R(e.colId)).map(e=>e.colId);return this.autoSizeColumns(t,e)}sizeColumnsToFit(e,t={}){return ro(this.columnModel,e,t)}buildFitWidthStrategyParams(e,t){return{gridWidth:e.type===`fitProvidedWidth`?e.width:t,defaultMinWidth:e.defaultMinWidth,defaultMaxWidth:e.defaultMaxWidth,columnLimits:e.columnLimits}}buildFitCellContentsChanges(e){let t=e.skipHeader??this.autosizeOptions.skipHeaderOnAutoSize,n=e.colIds??this.columnModel.getColumns().filter(e=>e.resizable&&!e.suppressAutoSize&&!L(e.colId)&&!R(e.colId)).map(e=>e.colId),r=Object.fromEntries((e.columnLimits??[]).map(({colId:e,minWidth:t,maxWidth:n})=>[e,{minWidth:t,maxWidth:n}])),i=[];for(let a of n){let n=this.columnModel.getColumnById(a);if(!n)continue;let o=r[a]??{},s=this.autoSizeColumn(a,t);if(!s)continue;let c=Math.max(n.minWidth,o.minWidth??e.defaultMinWidth??n.minWidth),l=Math.min(n.maxWidth??2**53-1,o.maxWidth??e.defaultMaxWidth??n.maxWidth??2**53-1);i.push({colId:a,newWidth:ao(c,l===2**53-1?void 0:l,s.newWidth)})}return!e.scaleUpToFitGridWidth||i.length===0?{contentChanges:i}:{contentChanges:i,scaleUpParams:{colIds:i.map(e=>e.colId),defaultMinWidth:e.defaultMinWidth,defaultMaxWidth:e.defaultMaxWidth,columnLimits:e.columnLimits,onlyScaleUp:!0}}}};function ao(e,t,n){let r=Math.max(n,e);return t!==void 0&&(r=Math.min(r,t)),r}function oo(e,t){if(e.length===0||t<=0)return 0;let n=e[e.length-1];if(t>=n.left+n.width)return e.length-1;let r=0,i=e.length-1;for(;r<i;){let n=Math.ceil((r+i)/2);e[n].left<=t?r=n:i=n-1}return r}function so(e,t){if(e.length===0)return 0;let n=0,r=e.length-1;for(;n<r;){let i=Math.floor((n+r)/2),a=e[i];a.left+a.width<=t?n=i+1:r=i}return n}function co(e,t){return Math.max(0,e-t)}function lo(e,t,n){let r=Math.max(0,t-n);return Math.max(0,Math.min(e,r))}function uo(e,t,n){return Math.max(0,e-t-n)}function fo(e){let t=e.getCenterColumnIndices(),n=e.getColumns();return{centerIndices:t,centerColumns:t.map(e=>n[e]).filter(e=>e!==void 0)}}function po(e){let{scrollLeft:t,viewportWidth:n,columnModel:r,margin:i=200}=e,{centerIndices:a,centerColumns:o}=fo(r),s=r.getLeftFixedWidth(),c=r.getRightFixedWidth();if(o.length===0)return{window:{firstCol:0,lastCol:-1},centerScrollLeft:co(t,s)};let l=r.getCenterTotalWidth(),u=uo(n,s,c),d=lo(t,l,u),f=Math.max(0,d-i),p=Math.min(d+u+i,l+i),m=so(o,f),h=oo(o,p);return h=Math.min(h,o.length-1),h<m?{window:{firstCol:0,lastCol:-1},centerScrollLeft:d}:{window:{firstCol:a[m],lastCol:a[h]},centerScrollLeft:d}}var mo=class{columnModel;flexViewportWidth=0;constructor(e){this.columnModel=e}resolveCenterViewportWidth(e){return uo(e,this.columnModel.getLeftFixedWidth(),this.columnModel.getRightFixedWidth())}refreshFlexedColumns(e){let t=e.viewportWidth;this.flexViewportWidth=t;let n=this.getCenterColumns();if(n.length===0||t<=0)return{changed:!1,changedColIds:[],flexColIds:[]};let r=-1;if(e.resizingColIds&&e.resizingColIds.length>0){let t=new Set(e.resizingColIds);for(let e=n.length-1;e>=0;e--){let i=n[e];if(i&&t.has(i.colId)){r=e;break}}}let i=!1,a=n.map((e,t)=>{let n=e.flex??0,a=n>0&&t>r;return i||=a,{colId:e.colId,column:e,isFlex:a,flex:Math.max(0,n),initialSize:e.width,min:e.minWidth,max:e.maxWidth??2**53-1,targetSize:0}});if(!i)return{changed:!1,changedColIds:[],flexColIds:[]};let o=a.length,s=a.reduce((e,t)=>e+t.flex,0),c=t,l=(e,t)=>{e.frozenSize=t,c-=t,s-=e.flex,--o},u=e=>e.frozenSize!=null;for(let e of a)e.isFlex||l(e,e.initialSize);for(;o>0;){let e=Math.round(s<1?c*s:c),t,n=0,r=0;for(let i of a){if(u(i))continue;t=i,r+=e*(i.flex/s);let a=r-n,o=Math.round(a);i.targetSize=o,n+=o}t&&(t.targetSize+=e-n);let i=0;for(let e of a){if(u(e))continue;let t=e.targetSize,n=Math.min(Math.max(t,e.min),e.max);i+=n-t,e.violationType=n===t?void 0:n<t?`max`:`min`,e.targetSize=n}let o=i===0?`all`:i>0?`min`:`max`;for(let e of a)u(e)||(o===`all`||e.violationType===o)&&l(e,e.targetSize)}let d=[],f=[],p=[];for(let e of a){let t=e.frozenSize;t!=null&&t!==e.initialSize&&(d.push({colId:e.colId,width:t}),f.push(e.colId),e.isFlex&&p.push(e.colId))}return d.length===0?{changed:!1,changedColIds:[],flexColIds:[]}:(this.columnModel.applyColumnWidthChanges(d,{widthSource:`flex`}),{changed:!0,changedColIds:f,flexColIds:p})}getStoredViewportWidth(){return this.flexViewportWidth}getCenterColumns(){let e=this.columnModel.getCenterColumnIndices(),t=this.columnModel.getColumns();return e.map(e=>t[e]).filter(e=>e!==void 0)}};function ho(e,t,n,r){let i=hi(n,r.colResizeDefault),a=[],o=[];for(let n of t){let t=e.getColumnById(n.colId);if(!t?.resizable)continue;let r=yo(t,n.newWidth);if(a.push({width:r,ratios:[1],colIds:[n.colId]}),o.push(n.colId),i){let i=e.getColAfter(n.colId);if(!i?.resizable)continue;let s=t.width-r,c=i.width+s;a.push({width:c,ratios:[1],colIds:[i.colId]}),o.includes(i.colId)||o.push(i.colId)}}return{sets:a,affectedColIds:o}}var go=class{columnModel;syncLayout;columnFlexService;getCenterViewportWidth;constructor(e,t,n,r){this.columnModel=e,this.syncLayout=t,this.columnFlexService=n,this.getCenterViewportWidth=r}setColumnWidths(e,t,n,r,i){let{sets:a,affectedColIds:o}=ho(this.columnModel,e,t,i);return a.length===0?{changed:!1,affectedColIds:[],flexColIds:[]}:this.resizeColumnSets({resizeSets:a,finished:n,source:r,affectedColIds:o})}resizeColumnSets(e){let{resizeSets:t,affectedColIds:n}=e;if(!t.every(e=>_o(this.columnModel,e)))return{changed:!1,affectedColIds:n,flexColIds:[]};let r=[];for(let e of t){let t=vo(this.columnModel,e);for(let[e,n]of Object.entries(t)){let t=r.find(t=>t.colId===e);t?t.width=n:r.push({colId:e,width:n})}}let i=r.filter(e=>this.columnModel.getColumnById(e.colId)?.resizable),a=this.columnModel.applyColumnWidthChanges(i,{widthSource:`manual`});a&&this.syncLayout();let o=[];if(this.columnFlexService&&this.getCenterViewportWidth&&this.columnModel.hasFlexColumns()){let e=this.columnFlexService.refreshFlexedColumns({viewportWidth:this.getCenterViewportWidth(),resizingColIds:n});o=e.flexColIds,e.changed&&this.syncLayout()}return{changed:a||o.length>0,affectedColIds:n,flexColIds:o}}};function _o(e,t){let n=0,r=0,i=!0;for(let a of t.colIds){let t=e.getColumnById(a);if(!t)return!1;n+=t.minWidth,t.maxWidth===void 0?i=!1:r+=t.maxWidth}return t.width>=n&&(!i||t.width<=r)}function vo(e,t){let{colIds:n,width:r,ratios:i}=t,a=Object.create(null),o=Object.create(null),s=!0,c=0;for(;s&&(c++,!(c>1e3));){s=!1;let t=[],c=0,l=r;n.forEach((e,n)=>{o[e]?l-=a[e]??0:(t.push(e),c+=i[n]??1)});let u=c>0?1/c:1;t.forEach((c,d)=>{let f=e.getColumnById(c);if(!f)return;let p=d===t.length-1,m;if(p)m=l;else{let e=n.indexOf(c),t=i[e]??1;m=Math.round(t*r*u),l-=m}let h=f.minWidth,g=f.maxWidth;m<h?(m=h,o[c]=!0,s=!0):g!==void 0&&m>g&&(m=g,o[c]=!0,s=!0),a[c]=m})}return a}function yo(e,t){let n=Math.max(t,e.minWidth);return e.maxWidth!==void 0&&(n=Math.min(n,e.maxWidth)),n}function bo(){return{key:Ke,label:``,width:40,minWidth:40,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!1,headerAlign:`center`,align:`center`,valign:`center`}}function xo(e={}){return{key:mt,label:`分组`,width:200,minWidth:120,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!0,headerAlign:`left`,align:`left`,valign:`center`,...e}}function So(e={}){return{key:en,label:`树`,width:200,minWidth:120,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!0,headerAlign:`left`,align:`left`,valign:`center`,...e}}function Co(e){return{key:je,label:e.label,width:e.width,minWidth:40,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!1,headerAlign:e.headerAlign,headerValign:e.headerValign,align:e.align,valign:e.valign,footerAlign:e.footerAlign,footerValign:e.footerValign}}function wo(e){return{key:ze,label:``,width:e.width,minWidth:40,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!1,headerAlign:e.headerAlign,headerValign:e.headerValign,align:e.align,valign:e.valign,footerAlign:e.footerAlign,footerValign:e.footerValign}}function To(e,t,n=Ge(),r={}){let i=[];t.showIndexColumn&&i.push(Co(t.indexColumn)),n.enabled&&i.push(wo(n.selectionColumn));let a=r.rowExpansion;a?.masterDetail&&a.showExpandColumn&&i.push(bo());let o=r.treeTable;if(o&&dn(o.tree,o.showTreeColumn,o.getDataPath))i.push(So(o.autoTreeColumnDef??{}));else{let e=r.rowGrouping;e&&Rt(e.rowGrouping,e.showGroupColumn)&&i.push(xo(e.autoGroupColumnDef??{}))}return[...i,...e]}var Eo=class{columnModel;currentWindow={firstCol:0,lastCol:-1};centerScrollLeft=0;windowHash=``;constructor(e){this.columnModel=e}update(e,t){let{window:n,centerScrollLeft:r}=po({scrollLeft:e,viewportWidth:t,columnModel:this.columnModel}),i=this.computeHash(n),a=i!==this.windowHash;return this.currentWindow=n,this.centerScrollLeft=r,this.windowHash=i,a}getWindow(){return this.currentWindow}getCenterScrollLeft(){return this.centerScrollLeft}getState(){return{centerWindow:this.currentWindow,fixed:this.columnModel.getFixedColumnGroups(),centerScrollLeft:this.centerScrollLeft}}invalidate(){this.windowHash=``,this.currentWindow={firstCol:0,lastCol:-1},this.centerScrollLeft=0}computeHash(e){let t=this.columnModel.getColumns(),n=this.columnModel.getFixedColumnGroups(),r=`fixed:`;for(let e of n.left){let n=t[e];n&&(r+=`L${n.colId}:${n.width};`)}for(let e of n.right){let n=t[e];n&&(r+=`R${n.colId}:${n.width};`)}if(e.lastCol<e.firstCol)return`${r}|empty`;r+=`|${e.firstCol}:${e.lastCol}`;for(let n=e.firstCol;n<=e.lastCol;n++){let e=t[n];e&&(r+=`|${e.colId}:${e.width}:${e.left}`)}return r}},Do=new class{apply(e,t){if(e.replaceChildren(),typeof t==`string`){e.textContent=t;return}e.appendChild(t)}clear(e){e.replaceChildren()}},Oo=class{cachedValue=``;cachedRenderKey=``;cacheVersion=-1;refreshSummaryCell(e,t,n,r,i=!1){let a=typeof i==`boolean`?{force:i}:i,o=a.force??!1;if(e.cellRenderer)return this.refreshRendererCell(e,t,n,r,o,a.scheduleRenderer);let s=t.formattedValue;return!o&&this.cacheVersion===r&&this.cachedValue===s?!1:(n.clearRenderer(),this.cachedValue=s,this.cachedRenderKey=``,this.cacheVersion=r,n.setValue(s),!0)}invalidate(){this.cacheVersion=-1,this.cachedRenderKey=``}refreshRendererCell(e,t,n,r,i,a){let o=t.formattedValue,s=`${r}:summary:${e.colId}:${o}`;if(!i&&this.cacheVersion===r&&this.cachedRenderKey===s)return!1;this.cachedValue=o,this.cachedRenderKey=s,this.cacheVersion=r;let c={rowId:hn,rowIndex:-1,colId:e.colId,value:t.value,data:{},formattedValue:o,isSummaryRow:!0},l=()=>{this.applyRenderer(e,n,c)};return a?(a(l),!0):(l(),!0)}applyRenderer(e,t,n){let r=e.cellRenderer;if(!r)return;t.prepareForRenderer();let i=t.getRendererMountEl(),a=r(n,{mountEl:i,clear:()=>{t.clearRenderer()}});a!=null&&(typeof a==`string`||a instanceof HTMLElement)&&Do.apply(i,a)}};function ko(e,t){let n=t.getLeftFixedWidth(),r=t.getLeftFixedColumnIndices(),i=t.getRightFixedColumnIndices(),a=n+t.getCenterTotalWidth(),o=Mo(t,e.colId),s=o>=0&&o===t.getColumnCount()-1;if(e.fixed===`left`){let t=r[r.length-1];return{left:e.left,width:e.width,fixed:`left`,isLastLeftFixed:t!==void 0&&t===o,isLastColumn:s}}if(e.fixed===`right`){let t=i[0];return{left:e.left-a,width:e.width,fixed:`right`,isFirstRightFixed:t!==void 0&&t===o,isLastColumn:s}}let c=t.getCenterColumnIndices(),l=c[c.length-1];return{left:e.left,width:e.width,fixed:null,isLastCenter:i.length>0&&l!==void 0&&l===o,isLastColumn:s}}function Ao(e,t,n){e.style.width=`${t.width}px`,e.style.left=`${t.left}px`,e.style.removeProperty(`right`),e.style.removeProperty(`transform`),e.classList.remove(`${n}--fixed-left`,`${n}--fixed-right`,`${n}--fixed-left-last`,`${n}--center-last`,`${n}--column-last`,`${n}--fixed-right-first`),t.fixed===`left`?(e.classList.add(`${n}--fixed-left`),t.isLastLeftFixed&&e.classList.add(`${n}--fixed-left-last`)):t.fixed===`right`?(e.classList.add(`${n}--fixed-right`),t.isFirstRightFixed&&e.classList.add(`${n}--fixed-right-first`)):t.isLastCenter&&e.classList.add(`${n}--center-last`),t.isLastColumn&&e.classList.add(`${n}--column-last`)}function jo(e,t,n){e.querySelectorAll(`[data-col-id]`).forEach(e=>{if(!(e instanceof HTMLElement))return;let r=e.dataset.colId;if(!r)return;let i=t.getColumnById(r);i&&Ao(e,ko(i,t),n)})}function Mo(e,t){for(let n=0;n<e.getColumnCount();n++)if(e.getColumn(n)?.colId===t)return n;return-1}var No=class{element;textEl;rendererMount;onUnmountRenderer;usingRenderer=!1;constructor(e,t={}){this.onUnmountRenderer=t.onUnmountRenderer,this.element=document.createElement(`div`),this.element.className=`mg-footer-cell`,this.textEl=document.createElement(`span`),this.textEl.className=`mg-footer-cell__text`,this.rendererMount=document.createElement(`div`),this.rendererMount.className=`mg-footer-cell__renderer`,this.rendererMount.hidden=!0,this.element.append(this.textEl,this.rendererMount),e.appendChild(this.element)}setLayout(e,t){Ao(this.element,{left:e,width:t,fixed:null},`mg-footer-cell`)}setColumnLayout(e){Ao(this.element,e,`mg-footer-cell`)}setValue(e){this.clearRenderer(),this.textEl.hidden=!1,this.textEl.textContent!==e&&(this.textEl.textContent=e)}setRendererResult(e){this.prepareForRenderer(),Do.apply(this.rendererMount,e)}prepareForRenderer(){this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,this.rendererMount.hidden=!1,this.usingRenderer=!0}clearRenderer(){(this.usingRenderer||this.rendererMount.childNodes.length>0)&&this.onUnmountRenderer?.(this.rendererMount),Do.clear(this.rendererMount),this.rendererMount.hidden=!0,this.usingRenderer=!1}hasRenderer(){return this.usingRenderer}getRendererMountEl(){return this.rendererMount}setColId(e){this.element.dataset.colId=e}getColId(){return this.element.dataset.colId}getElement(){return this.element}destroy(){this.clearRenderer(),this.element.remove()}};function Po(e,t){return{rowId:e.id,rowIndex:e.rowIndex,data:e.data,colId:t.colId,isSummaryRow:!1,value:G(e,t)}}function Fo(e,t=null){return{rowId:hn,rowIndex:-1,data:null,colId:e.colId,isSummaryRow:!0,value:t}}function Io(e,t){let n=e[0];if(!n)return{left:0,width:0,fixed:null};let r=ko(n,t);if(r.width=Vo(e),e.length>1){let n=e[e.length-1],i=ko(n,t);r.isLastLeftFixed=i.isLastLeftFixed,r.isLastCenter=i.isLastCenter,r.isLastColumn=i.isLastColumn}return r}function Lo(e,t,n=`mg-cell`){let r=t>1;e.classList.toggle(`${n}--spanning`,r),e.classList.toggle(`${n}--col-span`,r),r?e.dataset.colSpan=String(t):delete e.dataset.colSpan}function Ro(e){if(!e.enableCellSpan)return 1;let{column:t,params:n}=e;if(L(t.colId)||R(t.colId))return 1;let r=t.colSpan;return r?zi(r(n)):1}function zo(e,t){let n=t.getColAfter(e.colId);if(n&&n.fixed===e.fixed&&!(L(n.colId)||R(n.colId)))return n}function Bo(e,t,n){let r=Ro({enableCellSpan:n.enableCellSpan,column:e,params:n.params}),i=[e],a=e;for(let e=1;e<r;e++){let e=zo(a,t);if(!e)break;i.push(e),a=e}return i}function Vo(e){let t=0;for(let n of e)t+=n.width;return t}function Ho(e){let{enableCellSpan:t,columnModel:n,columnIndices:r,paramsForColumn:i,filterCallback:a}=e,o=[],s=r.length;for(let e=0;e<s;){let s=r[e];if(s===void 0){e++;continue}let c=n.getColumn(s);if(!c){e++;continue}let l=Bo(c,n,{enableCellSpan:t,params:i(c)}),u=Uo(n,r,e,l),d=!0;if(a){d=!1;for(let t=0;t<u;t++){let i=r[e+t];if(i===void 0)continue;let o=n.getColumn(i);if(o&&a(o,i)){d=!0;break}}}d&&o.push(s),e+=Math.max(1,u)}return o}function Uo(e,t,n,r){let i=1;for(let a=1;a<r.length&&n+a<t.length;a++){let o=t[n+a];if(o===void 0)break;let s=e.getColumn(o),c=r[a];if(!s||!c||s.colId!==c.colId)break;i++}return i}function Wo(e,t){let n=[...e.getLeftFixedColumnIndices()],r=[...e.getRightFixedColumnIndices()],i=[];if(t.lastCol>=t.firstCol)for(let n of e.getCenterColumnIndices())n>=t.firstCol&&n<=t.lastCol&&i.push(n);return{left:n,center:i,right:r}}function Go(e){let{columnModel:t,centerWindow:n,enableCellSpan:r,paramsForColumn:i}=e;return r?{left:Ho({enableCellSpan:!0,columnModel:t,columnIndices:t.getLeftFixedColumnIndices(),paramsForColumn:i}),center:Ho({enableCellSpan:!0,columnModel:t,columnIndices:t.getCenterColumnIndices(),paramsForColumn:i,filterCallback:(e,t)=>n.lastCol>=n.firstCol&&t>=n.firstCol&&t<=n.lastCol}),right:Ho({enableCellSpan:!0,columnModel:t,columnIndices:t.getRightFixedColumnIndices(),paramsForColumn:i})}:Wo(t,n)}function Ko(e){if(!e.enableCellSpan||e.params.isSummaryRow)return 1;let{column:t,params:n}=e;if(L(t.colId)||R(t.colId))return 1;let r=t.rowSpan;return r?zi(r(n)):1}function qo(e){let{enableCellSpan:t,column:n,rowNode:r,getRowByIndex:i,rowCount:a}=e;if(!t||!n.rowSpan)return{head:r,rowSpan:1,covered:!1};let o=Math.max(0,r.rowIndex-100);for(let e=r.rowIndex-1;e>=o;e--){let o=i(e);if(!o)continue;let s=$o(Ko({enableCellSpan:t,column:n,params:Po(o,n)}),o.rowIndex,a);if(s>1&&o.rowIndex+s-1>=r.rowIndex)return{head:o,rowSpan:s,covered:!0}}return{head:r,rowSpan:$o(Ko({enableCellSpan:t,column:n,params:Po(r,n)}),r.rowIndex,a),covered:!1}}function Jo(e,t,n){if(t<=1)return e.rowHeight;let r=n(e.rowIndex+t-1)??e,i=r.rowTop+r.rowHeight-e.rowTop;return Math.max(e.rowHeight,i)}function Yo(e,t,n){let r=t>1;if(e.classList.toggle(`mg-cell--row-span`,r),r){e.classList.add(`mg-cell--spanning`),e.dataset.rowSpan=String(t),n!=null&&(e.style.height=`${n}px`);return}delete e.dataset.rowSpan,e.style.removeProperty(`height`),e.classList.remove(`mg-cell--row-span-highlighted`),e.classList.contains(`mg-cell--col-span`)||e.classList.remove(`mg-cell--spanning`)}function Xo(e){let{head:t,rowSpan:n,getRowByIndex:r,isRowHighlighted:i}=e;if(n<=1)return i(t.id);for(let e=0;e<n;e++){let n=r(t.rowIndex+e);if(n&&i(n.id))return!0}return!1}function Zo(e){let{head:t,rowSpan:n,colId:r,getRowByIndex:i,isCellSelected:a}=e;if(n<=1)return a(t.rowIndex,r);for(let e=0;e<n;e++){let n=i(t.rowIndex+e);if(n&&a(n.rowIndex,r))return!0}return!1}function Qo(e){let{enableCellSpan:t,rowModel:n,columns:r,firstRow:i,lastRow:a}=e,o=new Set;if(!t||a<i)return o;let s=r.filter(e=>e.rowSpan!=null);if(s.length===0)return o;let c=n.getRowCount(),l=e=>n.getRow(e),u=Math.max(0,i-50);for(let e=u;e<=a;e++){let n=l(e);if(n)for(let e of s){let r=qo({enableCellSpan:t,column:e,rowNode:n,getRowByIndex:l,rowCount:c});r.covered||r.rowSpan<=1||r.head.id!==n.id||r.head.rowIndex+r.rowSpan-1>=i&&r.head.rowIndex<=a&&o.add(r.head.id)}}return o}function $o(e,t,n){if(n<=0)return 1;let r=n-t;return Math.min(e,r,50)}function es(e,t){let n=new Map;if(!qi(e.spanRows)||t.length===0)return n;let r=e.spanRows,i=0,a=G(t[0],e),o=r=>{let a=i;for(;a<=r;){let i=Math.min(r,a+50-1),o=[];for(let e=a;e<=i;e++)o.push(t[e].id);let s={colId:e.colId,firstRowId:o[0],lastRowId:o[o.length-1],rowIds:o,rowSpan:o.length};for(let e of o)n.set(e,s);a=i+1}};for(let n=1;n<t.length;n++){let s=t[n],c=G(s,e),l=t[i];ts(r,l,s,a,c,e.colId)||(o(n-1),i=n,a=c)}return o(t.length-1),n}function ts(e,t,n,r,i,a){return e===!0?Object.is(r,i):typeof e==`function`&&e({nodeA:{rowId:t.id,data:t.data,rowIndex:t.rowIndex},nodeB:{rowId:n.id,data:n.data,rowIndex:n.rowIndex},valueA:r,valueB:i,colId:a})}var ns=class{deps;spanRowsCaches=new Map;warnedBothModes=new Set;constructor(e){this.deps=e}get active(){return this.deps.getEnableCellSpan()}refresh(){if(this.spanRowsCaches.clear(),!this.active)return;let e=this.deps.getDisplayRows(),t=this.deps.getColumnModel().getColumns();for(let n of t)n.rowSpan&&qi(n.spanRows)&&this.warnBothModes(n.colId),Ki(n.rowSpan,n.spanRows)===`spanRows`&&this.spanRowsCaches.set(n.colId,es(n,e))}getColSpan(e,t){let n=this.deps.getColumnModel().getColumnById(t);if(!n||!this.active)return 1;if(e===`__mg_summary__`)return Ro({enableCellSpan:!0,column:n,params:Fo(n,this.deps.getSummaryValue?.(t)??null)});let r=this.deps.getRowById(e);return r?Ro({enableCellSpan:!0,column:n,params:Po(r,n)}):1}getCellSpan(e,t){let n=this.deps.getColumnModel(),r=n.getColumnById(t),i=this.deps.getRowById(e);if(!r||!i||!this.active)return null;let a=this.resolveVerticalSpan(i,r),o=Bo(r,n,{enableCellSpan:!0,params:Po(i,r)});if(a.rowSpan<=1&&o.length<=1)return null;let s=this.collectVerticalRowIds(a.head,a.rowSpan);return{colId:r.colId,firstRowId:a.head.id,lastRowId:s[s.length-1]??a.head.id,rowSpan:a.rowSpan,colSpan:o.length,rowIds:s,colIds:o.map(e=>e.colId)}}isCovered(e,t){let n=this.deps.getColumnModel().getColumnById(t),r=this.deps.getRowById(e);return!n||!r||!this.active?!1:this.resolveVerticalSpan(r,n).covered}normalizePosition(e,t){let n=this.deps.getColumnModel().getColumnById(t),r=this.deps.getRowById(e);return!n||!r||!this.active?{rowId:e,colId:t}:{rowId:this.resolveVerticalSpan(r,n).head.id,colId:t}}resolveVerticalSpan(e,t){if(!this.active)return{head:e,rowSpan:1,covered:!1};let n=Ki(t.rowSpan,t.spanRows);return n===`rowSpan`?qo({enableCellSpan:!0,column:t,rowNode:e,getRowByIndex:this.deps.getRowByIndex,rowCount:this.deps.getRowCount()}):n===`spanRows`?this.resolveFromSpanRowsCache(e,t):{head:e,rowSpan:1,covered:!1}}getVerticalSpanHeight(e,t){let n=this.resolveVerticalSpan(e,t);return n.covered||n.rowSpan<=1?e.rowHeight:Jo(n.head,n.rowSpan,this.deps.getRowByIndex)}collectSpannedHeadRowIds(e,t){let n=new Set;if(!this.active||t<e)return n;let r=this.deps.getColumnModel().getColumns().filter(e=>Ki(e.rowSpan,e.spanRows)!==`none`);if(r.length===0)return n;let i=Math.max(0,e-50);for(let a=i;a<=t;a++){let i=this.deps.getRowByIndex(a);if(i)for(let a of r){let r=this.resolveVerticalSpan(i,a);r.covered||r.rowSpan<=1||r.head.id!==i.id||r.head.rowIndex+r.rowSpan-1>=e&&r.head.rowIndex<=t&&n.add(r.head.id)}}return n}resolveFromSpanRowsCache(e,t){let n=this.spanRowsCaches.get(t.colId)?.get(e.id);return!n||n.rowSpan<=1?{head:e,rowSpan:1,covered:!1}:{head:this.deps.getRowById(n.firstRowId)??e,rowSpan:n.rowSpan,covered:n.firstRowId!==e.id}}collectVerticalRowIds(e,t){let n=[];for(let r=0;r<t;r++){let t=this.deps.getRowByIndex(e.rowIndex+r);t&&n.push(t.id)}return n}warnBothModes(e){this.warnedBothModes.has(e)||(this.warnedBothModes.add(e),console.warn(`[magic-grid] Column "${e}" has both rowSpan and spanRows; rowSpan takes precedence.`))}},rs=`copy`,is=`mg-cell--range-selected`,as=`mg-cell--range-anchor`,os=`mg-cell-range-border`,ss=`mg-cell-range-border--edge-top`,cs=`mg-cell-range-border--edge-right`,ls=`mg-cell-range-border--edge-bottom`,us=`mg-cell-range-border--edge-left`,ds=`mg-cell-range-border--fill-h`,fs=`mg-cell-range-border--fill-v`,ps=`mg-cell-range-overlay`,ms=`mg-cell--range-copy-flash`,hs=`mg-cell-range-overlay--copy-flash`,gs=`mg-cell--range-paste-flash`,_s=`mg-cell--range-paste-blocked-flash`,vs=`mg-cell-range-paste-overlay`,ys=`mg-cell-range-paste-overlay--applied`,bs=`mg-cell-range-paste-overlay--blocked`,xs=`mg-cell-range-paste-flash-layer`,Ss=`mg-fill-handle`,Cs=`mg-range-handle`,ws=`mg-header-cell--range-highlight`,Ts=`mg-cell--index-range-highlight`;function Es(e){return L(e)||R(e)||z(e)||ln(e)||V(e)}function Ds(e){return Es(e)}function Os(e){let t=at(e);return t===`data`||t===`groupHeader`||t===`groupFooter`}function ks(e){return at(e)===`data`}function As(e,t){return L(e)||R(e)||z(e)?!1:Os(t)}function js(e,t){return!Ds(e)&&ks(t)}function Ms(e={}){let t=e.handleMode??`off`;return t===`off`?null:t===`range`?{mode:`range`}:{mode:`fill`,direction:e.direction??`xy`,fillStrategy:e.fillStrategy??`copy`,fillReverseStrategy:e.fillReverseStrategy??`default`,setFillValue:e.setFillValue}}function Ns(e){return!e.enabled||!e.handle?null:e.handle.mode}function Ps(e){return Ns(e)===`fill`}function Fs(e){return Ns(e)===`range`}function Is(e={}){return{enableHeaderHighlight:e.enableHeaderHighlight??!0,enableIndexColumnHighlight:e.enableIndexColumnHighlight??!0}}function Ls(e={}){let t=e.cellSelection;if(t===!1||t==null)return{enabled:!1,suppressMultiRanges:!0,enableColumnSelection:!1,enableCellCopy:!1,enableCellPaste:!1,handle:null};let n=t===!0?{}:t,r=e.enableCellCopy??!0,i=e.enableCellPaste??!1;return{enabled:!0,suppressMultiRanges:n.suppressMultiRanges??!0,enableColumnSelection:n.enableColumnSelection??!1,enableCellCopy:r,enableCellPaste:i,handle:Ms(n)}}function Rs(e,t){return{startRowIndex:Math.min(e.rowIndex,t.rowIndex),endRowIndex:Math.max(e.rowIndex,t.rowIndex),startColId:e.colId,endColId:t.colId}}function zs(e){return e.serviceRanges.length>0?[...e.serviceRanges]:!e.enableHeaderHighlight&&!e.enableIndexColumnHighlight?[]:e.editingRanges&&e.editingRanges.length>0?[...e.editingRanges]:!e.focus||!e.focusEligible?[]:[Rs(e.focus,e.focus)]}function Y(e,t){let n=Math.min(e.startRowIndex,e.endRowIndex),r=Math.max(e.startRowIndex,e.endRowIndex),i=t.indexOf(e.startColId),a=t.indexOf(e.endColId);if(i<0||a<0)return null;let o=Math.min(i,a),s=Math.max(i,a);return{top:n,bottom:r,leftColId:t[o],rightColId:t[s]}}function Bs(e){return{startRowIndex:e.top,endRowIndex:e.bottom,startColId:e.leftColId,endColId:e.rightColId}}function Vs(e,t,n,r){if(e<n.top||e>n.bottom)return!1;let i=r.indexOf(t);if(i<0)return!1;let a=r.indexOf(n.leftColId),o=r.indexOf(n.rightColId);return a<0||o<0?!1:i>=a&&i<=o}function Hs(e,t){return e.startRowIndex===t.startRowIndex&&e.endRowIndex===t.endRowIndex&&e.startColId===t.startColId&&e.endColId===t.endColId}function Us(e,t){let n=Math.min(e.startRowIndex,e.endRowIndex),r=Math.max(e.startRowIndex,e.endRowIndex);return[{rowIndex:n,colId:e.startColId},{rowIndex:n,colId:e.endColId},{rowIndex:r,colId:e.startColId},{rowIndex:r,colId:e.endColId}].every(e=>As(e.colId,t(e.rowIndex)))}function Ws(e,t,n){if(Es(e)||t<=0)return null;let r=-1,i=-1;for(let a=0;a<t;a++)As(e,n(a))&&(r<0&&(r=a),i=a);return r<0||i<0?null:{startRowIndex:r,endRowIndex:i,startColId:e,endColId:e}}function Gs(e,t,n){let r=null,i=null;for(let a of e)As(a,t(n))&&(r??=a,i=a);return r==null||i==null?null:{startColId:r,endColId:i}}function Ks(e){if(e.length===0)return[];let t=[...e].sort((e,t)=>e-t),n=[],r=t[0],i=t[0];for(let e=1;e<t.length;e++){let a=t[e];if(a===i+1){i=a;continue}n.push({top:r,bottom:i}),r=a,i=a}return n.push({top:r,bottom:i}),n}function qs(e){let{focusedRowIndices:t,displayedColIds:n,rowKindAt:r,suppressMultiRanges:i,currentRowIndex:a}=e,o=[...t].filter(e=>Os(r(e))).sort((e,t)=>e-t);if(o.length===0)return[];let s=Gs(n,r,o[0]);if(!s)return[];if(i){if(o.length===1||o.every((e,t)=>t===0||e===o[t-1]+1))return[{startRowIndex:o[0],endRowIndex:o[o.length-1],startColId:s.startColId,endColId:s.endColId}];let e=a??o[o.length-1];return Os(r(e))?[{startRowIndex:e,endRowIndex:e,startColId:s.startColId,endColId:s.endColId}]:[]}return Ks(o).map(({top:e,bottom:t})=>({startRowIndex:e,endRowIndex:t,startColId:s.startColId,endColId:s.endColId}))}function Js(e){let t=new Set(e.rangeRowIndices);for(let n of e.indexFocusedRowIds){let r=e.rowIndexById(n);r>=0&&t.add(r)}for(let n of e.selectedRowIds){let r=e.rowIndexById(n);r>=0&&t.add(r)}return t}function Ys(e,t){console.warn(`[magic-grid] addCellRange: ignored invalid range (${t}).`,e)}function Xs(e,t,n,r){if(!r?.active)return!1;if(r.resolveVerticalSpan(e,t).covered)return!0;let i=n.getDisplayedColumns().map(e=>e.colId),a=i.indexOf(t.colId);if(a<=0)return!1;for(let r=0;r<a;r++){let a=n.getColumnById(i[r]);if(!a)continue;let o=Bo(a,n,{enableCellSpan:!0,params:Po(e,a)});if(!(o.length<=1)&&o.findIndex(e=>e.colId===t.colId)>0)return!0}return!1}function Zs(e,t,n,r){let i=r.indexOf(t);if(i<0)return{leftColId:t,rightColId:t};for(let a=i;a>=0;--a){let i=r[a];if(!i)continue;let o=n.getColumnById(i);if(!o)continue;let s=Bo(o,n,{enableCellSpan:!0,params:Po(e,o)});if(!(s.length<=1)&&s.findIndex(e=>e.colId===t)>=0)return{leftColId:s[0].colId,rightColId:s[s.length-1].colId}}return{leftColId:t,rightColId:t}}function Qs(e,t,n){let r={top:e,bottom:e,leftColId:t,rightColId:t},i=n.rowModel.getRow(e);if(!i||!n.cellSpanService?.active)return r;let a=n.columnModel.getColumnById(t);if(!a)return r;let o=n.cellSpanService.resolveVerticalSpan(i,a),s=o.head,c=s.rowIndex,l=s.rowIndex;o.rowSpan>1&&(l=o.head.rowIndex+o.rowSpan-1);let u=Zs(s,t,n.columnModel,n.displayedColIds);return{top:c,bottom:l,leftColId:u.leftColId,rightColId:u.rightColId}}function $s(e,t,n){if(!n.cellSpanService?.active)return e;let r=e.top,i=e.bottom,a=e.leftColId,o=e.rightColId,s=t.indexOf(a),c=t.indexOf(o);if(s<0||c<0)return e;let l=Math.min(s,c),u=Math.max(s,c),d=!0;for(;d;){d=!1;for(let e=r;e<=i;e+=1)for(let s=l;s<=u;s+=1){let c=t[s];if(!c)continue;let f=Qs(e,c,n);f.top<r&&(r=f.top,d=!0),f.bottom>i&&(i=f.bottom,d=!0);let p=t.indexOf(f.leftColId),m=t.indexOf(f.rightColId);p>=0&&p<l&&(l=p,a=t[l],d=!0),m>=0&&m>u&&(u=m,o=t[u],d=!0)}}return{top:r,bottom:i,leftColId:a,rightColId:o}}function ec(e,t){if(!t.cellSpanService?.active)return e;let n=Y(e,t.displayedColIds);return n?Bs($s(n,t.displayedColIds,t)):e}function tc(e,t,n){let r=$s(e,t,{...n,displayedColIds:t,cellSpanService:n.cellSpanService});return{topRowIndex:r.top,bottomRowIndex:r.bottom}}var nc=class{lanes;footerRowEl;frameService;onUnmountRenderer;enableCellSpan;columnModel=null;summaryCells=new Map;constructor(e){this.footerRowEl=e.footerRowEl,this.frameService=e.frameService??null,this.onUnmountRenderer=e.onUnmountRenderer,this.enableCellSpan=e.enableCellSpan??!1,this.lanes={left:this.createLane(e.footerLeftLaneEl),center:this.createLane(e.footerCenterLaneEl),right:this.createLane(e.footerRightLaneEl)}}setEnableCellSpan(e){this.enableCellSpan=e}render(e){this.columnModel=e.columnModel,this.summaryCells=e.summaryCells;let t=Go({columnModel:e.columnModel,centerWindow:e.centerWindow,enableCellSpan:this.enableCellSpan,paramsForColumn:t=>Fo(t,e.summaryCells.get(t.colId)?.value??null)});this.syncLaneWidths(e.columnModel),this.syncLaneCells(`left`,t.left),this.syncLaneCells(`center`,t.center),this.syncLaneCells(`right`,t.right),this.syncCellValues(e.summaryCells,e.valueCacheVersion,e.force??!1)}syncRowLayout(e){this.footerRowEl.style.width=`${e.getTotalWidth()}px`,this.syncLaneWidths(e)}syncColumnLayouts(){if(this.columnModel){this.syncRowLayout(this.columnModel);for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];!r||!i||this.applyCellColumnLayout(i,r)}}}}refreshVisibleColumnStructure(e){if(!this.columnModel)return;let t=Go({columnModel:this.columnModel,centerWindow:e,enableCellSpan:this.enableCellSpan,paramsForColumn:e=>Fo(e,this.summaryCells.get(e.colId)?.value??null)});this.syncLaneWidths(this.columnModel),this.syncLaneCells(`left`,t.left),this.syncLaneCells(`center`,t.center),this.syncLaneCells(`right`,t.right),this.syncCellValues(this.summaryCells,0,!0)}destroy(){for(let e of Object.values(this.lanes)){for(let t of e.cells)t.destroy();e.cells.length=0,e.cellCtrls.length=0,e.indices.length=0}}createLane(e){return{element:e,cells:[],cellCtrls:[],indices:[]}}syncLaneWidths(e){this.lanes.left.element.style.width=`${e.getLeftFixedWidth()}px`,this.lanes.center.element.style.width=`${e.getCenterTotalWidth()}px`,this.lanes.right.element.style.width=`${e.getRightFixedWidth()}px`}syncLaneCells(e,t){let n=this.lanes[e];for(n.indices=t;n.cells.length<t.length;)n.cells.push(new No(n.element,{onUnmountRenderer:this.onUnmountRenderer})),n.cellCtrls.push(new Oo);for(;n.cells.length>t.length;)n.cells.pop()?.destroy(),n.cellCtrls.pop();for(let e=0;e<t.length;e++){let r=t[e],i=r===void 0?void 0:this.columnModel.getColumn(r),a=n.cells[e];!i||!a||(this.applyCellColumnLayout(a,i),a.setColId(i.colId),ci(a.getElement(),i.footerAlign,i.footerValign,`mg-footer-cell`),a.getElement().classList.toggle(`mg-footer-cell--index`,L(i.colId)),a.getElement().classList.toggle(`mg-footer-cell--selection`,R(i.colId)))}}applyCellColumnLayout(e,t){if(!this.columnModel)return;if(!this.enableCellSpan||!t.colSpan){e.setColumnLayout(ko(t,this.columnModel)),Lo(e.getElement(),1,`mg-footer-cell`);return}let n=Bo(t,this.columnModel,{enableCellSpan:!0,params:Fo(t,this.summaryCells.get(t.colId)?.value??null)});e.setColumnLayout(Io(n,this.columnModel)),Lo(e.getElement(),n.length,`mg-footer-cell`)}syncCellValues(e,t,n){if(this.columnModel)for(let r of[`left`,`center`,`right`]){let i=this.lanes[r];for(let r=0;r<i.indices.length;r++){let a=i.indices[r],o=a===void 0?void 0:this.columnModel.getColumn(a),s=i.cells[r],c=i.cellCtrls[r];if(!o||!s||!c)continue;let l=e.get(o.colId)??{value:null,formattedValue:``};c.refreshSummaryCell(o,l,s,t,{force:n,scheduleRenderer:e=>this.scheduleRendererTask(e)})}}}scheduleRendererTask(e){if(this.frameService){this.frameService.createTask(e,-1,`f1`);return}e()}};function rc(e,t,n,r){e.style.width=`${r.getLeftFixedWidth()}px`,t.style.width=`${r.getCenterTotalWidth()}px`,n.style.width=`${r.getRightFixedWidth()}px`}function ic(e,t,n,r){jo(e,r,`mg-footer-cell`),jo(t,r,`mg-footer-cell`),jo(n,r,`mg-footer-cell`)}function ac(e){return e==null||e===``||typeof e==`string`&&e.trim()===``}function oc(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=e.trim();if(t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null}return null}var sc={count:0,numericCount:0,sum:null,average:null};function cc(e){let{ranges:t,displayedColIds:n,rowKindAt:r,getCellValue:i,normalizePosition:a=(e,t)=>({rowIndex:e,colId:t})}=e;if(t.length===0)return{...sc};let o=new Set,s=0,c=0,l=0;for(let e of t){let t=Y(e,n);t&&lc(t,n,(e,t)=>{if(!js(t,r(e)))return;let n=a(e,t),u=`${n.rowIndex}:${n.colId}`;if(o.has(u))return;o.add(u);let d=i(n.rowIndex,n.colId);if(ac(d))return;s+=1;let f=oc(d);f!=null&&(c+=1,l+=f)})}return{count:s,numericCount:c,sum:c>0?l:null,average:c>0?l/c:null}}function lc(e,t,n){let r=t.indexOf(e.leftColId),i=t.indexOf(e.rightColId);if(!(r<0||i<0))for(let a=e.top;a<=e.bottom;a++)for(let e=r;e<=i;e++)n(a,t[e])}function uc(e,t){if(t.filterFormatter)return t.filterFormatter(e.data);let n=t.prop??t.colId,r=n?e.data[n]:void 0;return t.formatter?(t.valueGetter&&(r=t.valueGetter(e.data,r)),t.formatter(e.data,r)):t.valueGetter?t.valueGetter(e.data,r):r}function dc(e,t){return{getFilterType:t=>e(t)?.filterType??`text`,getFilterParams:t=>e(t)?.filterParams??{caseSensitive:!0},getFilterValue:(n,r)=>{let i=e(r);return i?uc(n,i):t(n,r)}}}function fc(e,t){let n=e.__autoHeights;if(!n)return null;let r=Object.values(n);return r.length===0?null:Math.max(t,...r)}function pc(e,t,n){if(e.rowHeightPinned&&e.rowHeight>0)return{height:e.rowHeight,estimated:!1};if(n){let t=n(e);if(t!=null&&t>0)return{height:t,estimated:!1}}let r=fc(e,t);return r==null?e.rowHeight>0?{height:e.rowHeight,estimated:e.estimated??!1}:{height:t,estimated:!1}:{height:r,estimated:e.estimated??!1}}function mc(e,t){let n=0;for(let r=0;r<e.length;r++){let i=e[r];i.rowIndex=r,i.rowTop=n,i.rowHeight=t,i.estimated=!1,n+=t}}function hc(e,t){let n=0;for(let r=0;r<e.length;r++){let i=e[r],{height:a,estimated:o}=pc(i,t.defaultRowHeight,t.getRowHeight);i.rowIndex=r,i.rowTop=n,i.rowHeight=a,i.estimated=o,n+=a}}function gc(e,t){if(typeof t==`number`){mc(e,t);return}hc(e,t)}function _c(e){if(e.length===0)return 0;let t=e[e.length-1];return t.rowTop+t.rowHeight}function vc(e,t){return e===t?0:e===`(Blanks)`?1:t===`(Blanks)`?-1:e.localeCompare(t)}function yc(e){return e?(t,n,r)=>e({valueA:t,valueB:n,colId:r.colId,field:r.field,level:r.level}):(e,t)=>vc(e,t)}function bc(e){let{sourceRows:t,rowGroupColumns:n}=e;return n.length===0||t.length===0?[...t]:xc({rows:t,level:0,parentGroupId:void 0,parentPathIds:[],rowGroupColumns:n,getCellValue:e.getCellValue,groupKeyCreator:e.groupKeyCreator,groupComparator:e.groupComparator,getColumnField:e.getColumnField})}function xc(e){let{rows:t,level:n,parentGroupId:r,parentPathIds:i,rowGroupColumns:a,getCellValue:o,groupKeyCreator:s,groupComparator:c,getColumnField:l}=e;if(t.length===0)return[];if(n>=a.length)return wc(t,Ht(i)),[...t];let u=a[n],d=l?.(u)??u,f=Sc(t,u,d,o,s),p=yc(c),m={colId:u,field:d,level:n};return[...f.keys()].sort((e,t)=>p(e,t,m)).map(e=>{let t=f.get(e),p=Vt(n,d,e,r),m=[...i,p],h=xc({rows:t,level:n+1,parentGroupId:p,parentPathIds:m,rowGroupColumns:a,getCellValue:o,groupKeyCreator:s,groupComparator:c,getColumnField:l});return Tc({colId:u,field:d,key:e,level:n,groupId:p,groupPathKey:Ht(m),children:h})})}function Sc(e,t,n,r,i){let a=new Map;for(let o of e){let e=Cc(o,t,n,r,i),s=a.get(e);if(s){s.push(o);continue}a.set(e,[o])}return a}function Cc(e,t,n,r,i){let a=r(e,t);return Bt(i?i({field:n,colId:t,value:a,data:e.data}):a)}function wc(e,t){for(let n of e)n.leafGroupPathKey=t}function Tc(e){let t=Ec(e.children);return{id:e.groupId,data:{},rowTop:0,rowHeight:0,estimated:!1,rowIndex:-1,group:!0,groupField:e.colId,groupKey:e.key,groupLevel:e.level,groupId:e.groupId,groupPathKey:e.groupPathKey,groupLeafCount:t,childrenAfterGroup:e.children}}function Ec(e){let t=0;for(let n of e){if(n.group){let e=n.childrenAfterSort??n.childrenAfterFilter??n.childrenAfterGroup??[];t+=Ec(e);continue}t+=1}return t}function Dc(e){return e.some(e=>e.group===!0)}function Oc(e){return e.childrenAfterGroup??[]}function kc(e){return e.childrenAfterFilter??e.childrenAfterGroup??[]}function Ac(e){return e.childrenAfterSort??kc(e)}function jc(e){return Ac(e)}function Mc(e){let t=[];for(let n of e){if(n.group){t.push(...Mc(Ac(n)));continue}t.push(n)}return t}function Nc(e){for(let t of e){if(!t.group)continue;let e=Nc(Oc(t));t.childrenAfterFilter=e,t.groupLeafCount=Ec(e)}return[...e]}function Pc(e){for(let t of e){if(!t.group)continue;let e=t.childrenAfterSort??kc(t);Pc(e),t.groupLeafCount=Ec(e)}}function Fc(e){return e.some(e=>e.dataPath!=null&&e.dataPath.length>0&&e.group!==!0)}function Ic(e){return e.childrenAfterFilter??e.childrenAfterTree??[]}function Lc(e){return e.childrenAfterSort??Ic(e)}function Rc(e){for(let t of e){let e=t.childrenAfterTree??[];t.childrenAfterFilter=e.length>0?Rc(e):[]}return[...e]}function zc(e){return Bc(e??``)!==``}function Bc(e){return e.trim()}function Vc(e){let t=Bc(e.quickFilterText).toLowerCase();if(t===``)return!0;for(let n of e.filterableColIds){let r=e.getFilterValue(e.row,n,e.getCellValue);if(String(r??``).toLowerCase().includes(t))return!0}return!1}var Hc=`__mg_blank__`,Uc=/^\d{4}-\d{2}-\d{2}$/;function Wc(e){return!!(e==null||typeof e==`number`&&Number.isNaN(e)||typeof e==`string`&&e.trim()===``)}function Gc(e){return e.toISOString().slice(0,10)}function Kc(e){if(Wc(e))return null;if(e instanceof Date)return Number.isNaN(e.getTime())?null:Gc(e);if(typeof e==`number`){let t=new Date(e);return Number.isNaN(t.getTime())?null:Gc(t)}let t=String(e).trim();if(t===``)return null;if(Uc.test(t))return t;let n=Date.parse(t);return Number.isNaN(n)?null:Gc(new Date(n))}function qc(e){if(Wc(e))return null;let t=Number(e);return Number.isNaN(t)?null:t}function Jc(e,t){if(Wc(e))return Hc;switch(t){case`number`:{let t=qc(e);return t===null?Hc:String(t)}case`date`:return Kc(e)??`__mg_blank__`;default:return String(e)}}function Yc(e,t){return e===`__mg_blank__`?`(空白)`:e}function Xc(e,t){return e===`__mg_blank__`?-1:t===`__mg_blank__`?1:e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`})}function Zc(e){let t=new Map;for(let n of e.rows){let r=Jc(e.getFilterValue(n),e.filterType);t.set(r,(t.get(r)??0)+1)}return[...t.keys()].sort(Xc).map(t=>({key:t,label:Yc(t,e.filterType),blank:t===Hc}))}var Qc=/^\d{4}-\d{2}-\d{2}$/;function $c(e){return!!(e==null||typeof e==`number`&&Number.isNaN(e)||typeof e==`string`&&e.trim()===``)}function el(e,t){let n=String(e??``);return t?n:n.toLowerCase()}function tl(e,t){return t?e:e.toLowerCase()}function nl(e){return e.toISOString().slice(0,10)}function rl(e){if($c(e))return null;if(e instanceof Date)return Number.isNaN(e.getTime())?null:nl(e);if(typeof e==`number`){let t=new Date(e);return Number.isNaN(t.getTime())?null:nl(t)}let t=String(e).trim();if(t===``)return null;if(Qc.test(t))return t;let n=Date.parse(t);return Number.isNaN(n)?null:nl(new Date(n))}function il(e){if($c(e))return null;let t=Number(e);return Number.isNaN(t)?null:t}function al(e,t,n){let r=n(e);return t===`blank`?r:!r}function ol(e,t,n){if(Mi(t.type))return al(e,t.type,$c);let r=t.filter??``,i=el(e,n.caseSensitive),a=tl(r,n.caseSensitive);switch(t.type){case`contains`:return i.includes(a);case`notContains`:return!i.includes(a);case`equals`:return i===a;case`notEqual`:return i!==a;case`startsWith`:return i.startsWith(a);case`endsWith`:return i.endsWith(a);default:return!1}}function sl(e,t){if(Mi(t.type))return al(e,t.type,e=>il(e)===null);let n=il(e),r=il(t.filter);if(n===null||r===null)return!1;switch(t.type){case`equals`:return n===r;case`notEqual`:return n!==r;case`lessThan`:return n<r;case`lessThanOrEqual`:return n<=r;case`greaterThan`:return n>r;case`greaterThanOrEqual`:return n>=r;default:return ol(e,t,{caseSensitive:!0})}}function cl(e,t){if(Mi(t.type))return al(e,t.type,$c);let n=rl(e),r=t.filter?.trim()??``;if(r===``)return!1;switch(t.type){case`equals`:return n!==null&&n===r;case`notEqual`:return n===null||n!==r;case`lessThan`:return n!==null&&n<r;case`greaterThan`:return n!==null&&n>r;case`inRange`:{let e=t.filterTo?.trim()??``;return e===``||n===null?!1:n>=r&&n<=e}default:return!1}}function ll(e,t,n){if(t.length===0)return!1;let r=Jc(e,n);return t.includes(r)}function ul(e,t,n,r){switch(n){case`number`:return sl(e,t);case`date`:return cl(e,t);default:return ol(e,t,r)}}function dl(e,t,n,r){let i=Ti(t),a=wi(t).filter(Ci);if(a.length===0)return!0;let o=a.map(t=>ul(e,t,n,r));return i===`OR`?o.some(Boolean):o.every(Boolean)}function fl(e,t,n,r){let i=Di(t),a=Oi(t);return!(i&&!dl(e,t,n,r)||a&&!ll(e,Ei(t)??[],n))}function X(e){return String(e)}function pl(e){return typeof e==`string`||typeof e==`number`?[String(e)]:e.map(X)}function ml(e){if(e!=null)return e.map(X)}var hl=class extends Error{cause;constructor(e,t){super(e),this.cause=t,this.name=`RowMutationPersistError`}},gl=`mg-column-handle-menu`,_l=`mg-column-handle-menu-portal`,vl=`mg-column-handle-menu__section`,yl=`mg-column-handle-menu__item`,bl=`mg-column-handle-menu__item-content`,xl=`mg-column-handle-menu__item-label`,Sl=`mg-column-handle-menu__item--submenu-trigger`,Cl=`mg-column-handle-menu__submenu`,wl=`mg-column-handle-menu__submenu-panel`,Tl=`mg-column-handle-menu__divider`,El=`mg-column-handle-menu__filter-panel`,Dl=`mg-column-handle-menu__section--sort`,Ol=`mg-column-handle-menu__section--pin`,kl=`mg-column-handle-menu__section--filter`,Al=`mg-column-handle-menu__section--visibility`;function jl(e){return!L(e)&&!R(e)}function Ml(e,t=`full`){return jl(e.colId)?t===`filter-only`?{sort:!1,pin:!1,filter:e.filterable,visibility:!1}:{sort:e.sortable,pin:!0,filter:e.filterable,visibility:!0}:{sort:!1,pin:!1,filter:!1,visibility:!1}}function Nl(e){return e.sort||e.pin||e.filter||e.visibility}var Pl=Symbol.for(`magic-grid.vueCellRenderer`);function Fl(e){return Object.defineProperty(e,Pl,{value:!0,configurable:!0}),e}function Il(e){return e?Reflect.get(e,Pl)===!0:!1}function Ll(e,t,n){return!t||e===`never`?!1:e===`always`||n===`vue`||n!==`sync`&&Il(t)}function Rl(e,t,n,r){return e!==`immediate`&&Ll(t,n,r)}var zl=[`immediate`,`deferred`,`placeholder-then-vue`];function Bl(e){return e&&zl.includes(e)?e:`deferred`}function Vl(e={}){return{scrollEndFlushMs:Math.max(0,e.scrollEndFlushMs??0),frameBudgetMs:Math.max(1,e.frameBudgetMs??60),scrollEndFrameBudgetMs:e.scrollEndFrameBudgetMs??-1,cellRendererDefer:e.cellRendererDefer??`always`,deferRowDestroyOnScroll:e.deferRowDestroyOnScroll??!1,rendererFrameBudgetMs:Math.max(0,e.rendererFrameBudgetMs??20),cellRendererPresentation:Bl(e.cellRendererPresentation)}}var Hl=`mg-cell--has-comment`,Ul=`mg-cell--comment-empty`,Wl=`mg-cell-comment-popup`,Gl=`mg-cell-comment-popup--readonly`,Kl=`mg-cell-comment-popup--committing`,ql=`mg-cell-comment-context-menu`,Jl=`mg-cell-comment-context-menu--committing`;function Yl(e={}){return{cellCommentsDataSource:e.cellCommentsDataSource,suppressCellComments:e.suppressCellComments??!1,cellCommentTrigger:e.cellCommentTrigger??`click`,cellCommentShowDelay:e.cellCommentShowDelay??180,cellCommentHideDelay:e.cellCommentHideDelay??220}}function Xl(e){return e!=null&&typeof e.getComment==`function`&&typeof e.setComment==`function`}function Zl(e){return L(e)||R(e)||z(e)||ln(e)||V(e)}function Ql(e,t,n){return!(t!==`data`||n!=null&&String(n)===`__mg_summary__`||Zl(e))}function $l(e,t){return e==null?!1:typeof e==`function`?e(t):e}function eu(e){let t={canView:!1,canCreate:!1,canEdit:!1,canDelete:!1};if(!Ql(e.colId,e.rowKind,e.rowId))return t;let n=$l(e.columnSuppress,{data:e.data,rowId:e.rowId,colId:e.colId});return e.gridSuppress===!0||n?{canView:e.hasExistingComment,canCreate:!1,canEdit:!1,canDelete:!1}:{canView:!0,canCreate:!e.hasExistingComment,canEdit:e.hasExistingComment,canDelete:e.hasExistingComment}}function tu(e,t){return t?.readOnly?{canView:e.canView,canCreate:!1,canEdit:!1,canDelete:!1}:e}function nu(e){return typeof e?.text==`string`&&e.text.length>0}function ru(e,t,n,r){return{rowId:e,colId:t,comment:n,source:r}}function iu(e,t){return`${e}::${t}`}function au(e,t){e&&(t||console.warn(`[magic-grid] cellCommentsDataSource requires rowKey for stable (rowId, colId) keys; cell comment interactions are disabled.`))}var ou=`mg-column-settings`,su=`mg-column-settings__header`,cu=`mg-column-settings__body`,lu=`mg-column-settings-button`,uu=`mg-column-settings-portal`,du=`mg-column-settings-popover`,fu=`mg-column-settings-menu`,pu=`mg-column-settings-menu__item`,mu=`mg-column-settings-menu__divider`,hu=`mg-column-settings-menu__submenu`,gu=`mg-column-settings-menu__submenu-panel`,_u=`mg-column-settings-menu__item--submenu-trigger`,vu=`mg-column-settings__clear-filters`,yu=`mg-column-settings__group`,bu=`mg-column-settings__group-heading`,xu=`mg-column-settings__row`,Su=`mg-column-settings__row--filtered`,Cu=`mg-column-settings__hidden-section`;function wu(e){return!Aa(e)}function Tu(e){return e===`left`?`left`:e===`right`?`right`:`center`}function Eu(e){return e.label??e.prop??e.colId}function Du(e){let t=new Map,n={left:0,center:0,right:0};for(let r of e){if(r.hidden||!wu(r.colId))continue;let e=Tu(r.fixed);t.set(r.colId,n[e]),n[e]++}return t}function Ou(e){let t=e.sortModel[0],n=t?.colId,r=t?.sort??null,i=e.includeHidden??!0,a=e.columns.filter(e=>!(!wu(e.colId)||!i&&e.hidden)),o=Du(a);return a.map(t=>{let i=Tu(t.fixed),a=t.hidden?-1:o.get(t.colId)??-1;return{colId:t.colId,label:Eu(t),movable:t.movable,sortable:t.sortable,filterable:t.filterable,fixed:t.fixed??null,hidden:t.hidden,sortDirection:t.colId===n?r:null,filterActive:e.isColumnFilterActive(t.colId),displayIndex:a,lane:i}})}function ku(e){let t=e.filter(e=>!e.hidden),n=e.filter(e=>e.hidden);return{left:t.filter(e=>e.lane===`left`),center:t.filter(e=>e.lane===`center`),right:t.filter(e=>e.lane===`right`),hidden:n}}var Au=`加载中…`,ju=`暂无数据`,Mu=`没有匹配的行`,Nu=`mg-overlay`,Pu=`mg-overlay__wrapper`,Fu=`mg-overlay--masked`,Iu=`mg-overlay__content`,Lu=`mg-overlay__panel--loading`,Ru=`mg-overlay__panel--no-rows`,zu=`mg-overlay__panel--no-matching-rows`,Bu=`mg-overlay__spinner`;function Vu(e){switch(e){case`loading`:return Au;case`noRows`:return ju;case`noMatchingRows`:return Mu;default:return e}}function Hu(e={}){let t=new Set(e.suppressOverlays??[]);return e.suppressLoadingOverlay&&t.add(`loading`),e.suppressNoRowsOverlay&&t.add(`noRows`),e.suppressNoMatchingRowsOverlay&&t.add(`noMatchingRows`),t}function Uu(e={}){return{loading:e.loading,suppressOverlays:Hu(e),overlayLoadingTemplate:e.overlayLoadingTemplate,overlayNoRowsTemplate:e.overlayNoRowsTemplate,overlayNoMatchingRowsTemplate:e.overlayNoMatchingRowsTemplate,loadingOverlayComponent:e.loadingOverlayComponent,loadingOverlayComponentParams:e.loadingOverlayComponentParams,noRowsOverlayComponent:e.noRowsOverlayComponent,noRowsOverlayComponentParams:e.noRowsOverlayComponentParams,noMatchingRowsOverlayComponent:e.noMatchingRowsOverlayComponent,noMatchingRowsOverlayComponentParams:e.noMatchingRowsOverlayComponentParams,overlayComponent:e.overlayComponent,overlayComponentParams:e.overlayComponentParams,overlayInteraction:e.overlayInteraction??!1}}function Wu(e,t){return t.has(e)}function Gu(e){let{rows:t,filterModel:n,getCellValue:r,columnContext:i,quickFilterText:a,quickFilterColIds:o=[]}=e,s=Object.entries(n).filter(([,e])=>Ni(e)),c=zc(a),l=Dc(t),u=!l&&Fc(t);if(l)return s.length===0&&!c?Nc(t):Ku(t,s,c,{getCellValue:r,context:i??Yu,quickFilterText:a??``,quickFilterColIds:o});if(u)return s.length===0&&!c?Rc(t):qu(t,s,c,{getCellValue:r,context:i??Yu,quickFilterText:a??``,quickFilterColIds:o});if(s.length===0&&!c)return[...t];let d=i??Yu;return t.filter(e=>Ju(e,s,r,d,c,{quickFilterText:a??``,quickFilterColIds:o}))}function Ku(e,t,n,r){let i=[];for(let a of e){if(a.group){let e=Ku(a.childrenAfterGroup??[],t,n,r);if(e.length===0)continue;a.childrenAfterFilter=e,a.groupLeafCount=Ec(e),i.push(a);continue}Ju(a,t,r.getCellValue,r.context,n,{quickFilterText:r.quickFilterText,quickFilterColIds:r.quickFilterColIds})&&i.push(a)}return i}function qu(e,t,n,r){let i=[];for(let a of e){let e=qu(a.childrenAfterTree??[],t,n,r);!Ju(a,t,r.getCellValue,r.context,n,{quickFilterText:r.quickFilterText,quickFilterColIds:r.quickFilterColIds})&&e.length===0||(a.childrenAfterFilter=e,i.push(a))}return i}function Ju(e,t,n,r,i,a){return Xu(e,t,n,r)&&(!i||Vc({row:e,quickFilterText:a.quickFilterText,filterableColIds:a.quickFilterColIds,getCellValue:n,getFilterValue:(e,t,n)=>r.getFilterValue(e,t,n)}))}var Yu={getFilterType:()=>`text`,getFilterParams:()=>({caseSensitive:!0}),getFilterValue:(e,t,n)=>n(e,t)};function Xu(e,t,n,r){for(let[i,a]of t){let t=r.getFilterValue(e,i,n);if(xi(a)){if(!a.predicate(t,e.data))return!1;continue}if(!fl(t,a,r.getFilterType(i),r.getFilterParams(i)))return!1}return!0}var Zu=`合计`;function Qu(e){return typeof e==`number`&&Number.isFinite(e)}function $u(e,t){let n=[];for(let r of e){let e=G(r,t);Qu(e)&&n.push(e)}return n}function ed(e,t,n){if(e===`count`)return t.length;let r=$u(t,n);if(r.length===0)return null;switch(e){case`sum`:return r.reduce((e,t)=>e+t,0);case`avg`:return r.reduce((e,t)=>e+t,0)/r.length;case`min`:return Math.min(...r);case`max`:return Math.max(...r);default:return null}}function td(e,t,n){return typeof e==`function`?e(t,n):ed(e,t,n)}function nd(e){return e.summary===!1?!1:e.summaryAgg!=null||e.summary===!0}function rd(e,t){return t==null?``:e.summaryFormatter?e.summaryFormatter(t):e.formatter?e.formatter({},t):String(t)}function id(e,t){return{value:t,formattedValue:rd(e,t)}}function ad(e,t,n){if(!n)return null;try{let r=n({columns:e,data:t.map(e=>e.data),rows:t}),i=new Map;for(let[e,t]of Object.entries(r))t!==void 0&&i.set(e,t);return i}catch(e){return console.warn(`[magic-grid] summaryMethod failed:`,e),new Map}}function od(e){return e.find(e=>!L(e.colId)&&!R(e.colId))}function sd(e){let{columns:t,rows:n,summaryMethod:r}=e,i=new Map,a=ad(t,n,r);for(let e of t){if(L(e.colId)||R(e.colId)){i.set(e.colId,id(e,null));continue}let t=a?.get(e.colId);if(a?.has(e.colId)){i.set(e.colId,id(e,t??null));continue}if(nd(e)&&e.summaryAgg!=null){let t=td(e.summaryAgg,n,e);i.set(e.colId,id(e,t))}}let o=od(t);return o&&!i.has(o.colId)&&i.set(o.colId,id(o,Zu)),i}function cd(e){return Dc(e.rows)&&ld(e.rows,e.columns),[...e.rows]}function ld(e,t){for(let n of e){if(!n.group)continue;let e=Ac(n);ld(e,t),n.__groupAggValues=ud(t,Mc(e))}}function ud(e,t){let n={};for(let r of e){if(!r.groupAgg||L(r.colId)||R(r.colId)||z(r.colId)||V(r.colId))continue;let e=td(r.groupAgg,t,r);n[r.colId]={value:e,formattedValue:rd(r,e)}}return n}function dd(e,t={}){let n=e.groupId??e.id,r=t.rowHeight??m;return{id:Ut(n),data:{},rowTop:0,rowHeight:r,estimated:!1,rowIndex:-1,rowKind:`groupHeader`,sourceGroupId:n,groupField:e.groupField,groupKey:e.groupKey,groupLevel:e.groupLevel,groupLeafCount:e.groupLeafCount,groupId:n,groupPathKey:e.groupPathKey}}function fd(e,t={}){let n=e.groupId??e.id,r=t.rowHeight??m;return{id:Wt(n),data:{},rowTop:0,rowHeight:r,estimated:!1,rowIndex:-1,rowKind:`groupFooter`,sourceGroupId:n,groupField:e.groupField,groupKey:e.groupKey,groupLevel:e.groupLevel,groupLeafCount:e.groupLeafCount,groupId:n,groupPathKey:e.groupPathKey,__groupAggValues:pd(e.__groupAggValues)}}function pd(e){if(e)return{...e}}function md(e,t){return Dc(e)?gd(e,{expandedGroupIds:t?.expandedGroupIds??new Set,showGroupHeader:t?.showGroupHeader??!1,showGroupFooter:t?.showGroupFooter??!1,defaultRowHeight:t?.defaultRowHeight}):Fc(e)?hd(e,{expandedRowIds:t?.expandedRowIds??new Set}):[...e]}function hd(e,t){let n=[];function r(e){for(let i of e)n.push(i),t.expandedRowIds.has(i.id)&&r(Lc(i))}return r(e),n}function gd(e,t){let n=[];for(let r of e){if(!r.group){n.push(r);continue}let e=r.groupId??r.id,i=!t.showGroupHeader||t.expandedGroupIds.has(e);t.showGroupHeader&&n.push(dd(r,{rowHeight:t.defaultRowHeight})),i&&(n.push(...gd(Ac(r),t)),t.showGroupFooter&&n.push(fd(r,{rowHeight:t.defaultRowHeight})))}return n}function _d(e,t,n){let{colId:r,sort:i}=e;return n?(e,a)=>{let o=n(t(e,r),t(a,r),i,e.data,a.data);return o===0?e.id.localeCompare(a.id):i===`desc`?-o:o}:(e,n)=>{let a=vd(t(e,r),t(n,r),i);return a===0?e.id.localeCompare(n.id):a}}function vd(e,t,n){let r=0;return r=e==null&&t==null?0:e==null?-1:t==null?1:typeof e==`number`&&typeof t==`number`?e-t:String(e).localeCompare(String(t)),n===`desc`?-r:r}function yd(e,t,n,r){if(t.length<4)return[...r??e].sort(n);let i=new Set(t.map(e=>e.id));return bd(e.filter(e=>!i.has(e.id)),[...t].sort(n),n)}function bd(e,t,n){let r=[],i=0,a=0;for(;i<e.length&&a<t.length;)n(e[i],t[a])<=0?(r.push(e[i]),i++):(r.push(t[a]),a++);for(;i<e.length;)r.push(e[i]),i++;for(;a<t.length;)r.push(t[a]),a++;return r}function xd(e){let t=e.rows??e.sourceRows;if(Dc(t))return Sd({rows:t,sortModel:e.sortModel,getCellValue:e.getCellValue,getColumnComparator:e.getColumnComparator,groupComparator:e.groupComparator});if(Fc(t))return Ed({rows:t,sortModel:e.sortModel,getCellValue:e.getCellValue,getColumnComparator:e.getColumnComparator});let{sourceRows:n,currentDisplayRows:r,sortModel:i,touchedRowIds:a,getCellValue:o,getColumnComparator:s}=e;if(i.length===0)return[...t];let c=i[0],l=_d(c,o,s?.(c.colId));if(a&&a.size>0){let e=n.filter(e=>a.has(e.id));if(e.length>0&&r.length>0)return yd(r,e,l,n)}return[...t].sort(l)}function Sd(e){let t=Cd(e.rows,e);return Pc(t),t}function Cd(e,t){if(e.length===0)return[];if(e[0]?.group){let n=yc(t.groupComparator);return e.map(e=>wd(e,t)).sort((e,t)=>{let r=e.groupLevel??t.groupLevel??0,i=e.groupField??t.groupField??``;return n(e.groupKey??``,t.groupKey??``,{colId:i,field:i,level:r})})}return Td(e,t)}function wd(e,t){return e.childrenAfterSort=Cd(e.childrenAfterFilter??e.childrenAfterGroup??[],t),e}function Td(e,t){if(t.sortModel.length===0)return[...e];let n=t.sortModel[0],r=_d(n,t.getCellValue,t.getColumnComparator?.(n.colId));return[...e].sort(r)}function Ed(e){return Dd(e.rows,e)}function Dd(e,t){let n=Td(e,t);for(let e of n){let n=Ic(e);e.childrenAfterSort=n.length>0?Dd(n,t):[]}return n}var Od=`\0`;function kd(e){return e.join(Od)}var Ad=class extends Error{constructor(e){super(e),this.name=`TreeBuildError`}};function jd(e){let{sourceRows:t,getDataPath:n}=e,r=new Map,i=t.map((e,t)=>({node:e,path:n({data:e.data}),sourceIndex:t})).sort((e,t)=>e.path.length===t.path.length?e.sourceIndex-t.sourceIndex:e.path.length-t.path.length);for(let{path:e}of i)if(!Array.isArray(e)||e.length===0)throw new Ad(`[TreeBuildStage] getDataPath must return a non-empty string[]`);for(let{node:e,path:t}of i){let n=kd(t);if(r.has(n))throw new Ad(`[TreeBuildStage] duplicate dataPath: ${t.join(`/`)}`);e.dataPath=[...t],e.treeLevel=t.length-1,e.treeLeaf=!0,e.childrenAfterTree=[],r.set(n,e)}let a=[];for(let{node:e,path:t}of i){if(t.length===1){e.parentRowId=void 0,a.push(e);continue}let n=t.slice(0,-1),i=r.get(kd(n));if(!i)throw new Ad(`[TreeBuildStage] missing parent path: ${n.join(`/`)}`);e.parentRowId=i.id,i.treeLeaf=!1,i.childrenAfterTree.push(e)}return{roots:a,nodeByPath:r}}function Md(e){function t(e){for(let n of e){let e=n.childrenAfterTree??[];e.length===0?n.treeLeaf=!0:(n.treeLeaf=!1,t(e))}}t(e)}function Nd(e){let{sourceRows:t,getDataPath:n}=e;if(t.length===0)return[];let{roots:r}=jd({sourceRows:t,getDataPath:n});return Md(r),r}var Pd=[...yi];function Fd(e,t){return e.length===1&&e[0]===`map`&&t!=null&&t.groupedTreeRoots!=null&&t.groupedTreeRoots.length>0&&Dc(t.groupedTreeRoots)}function Id(e,t){return e.length===1&&e[0]===`map`&&t!=null&&t.treeTreeRoots!=null&&t.treeTreeRoots.length>0&&Fc(t.treeTreeRoots)}function Ld(e,t){if(t)return t.getMapStageOptions?.()??t.mapStageOptions;if(e)return e.getMapStageOptions?.()??e.mapStageOptions}function Rd(e){let t=e.stages??Pd,n=e.grouping,r=e.tree,i=[...e.sourceRows];if(Fd(t,n)&&n?.groupedTreeRoots)i=md(n.groupedTreeRoots,Ld(n,void 0));else if(Id(t,r)&&r?.treeTreeRoots)i=md(r.treeTreeRoots,Ld(void 0,r));else for(let a of t)switch(a){case`tree`:i=r?.getDataPath?Nd({sourceRows:e.sourceRows,getDataPath:r.getDataPath}):[...e.sourceRows];break;case`group`:i=n&&n.rowGroupColumns.length>0?bc({sourceRows:e.sourceRows,rowGroupColumns:n.rowGroupColumns,getCellValue:e.getCellValue,groupKeyCreator:n.groupKeyCreator,groupComparator:n.groupComparator,getColumnField:n.getColumnField}):[...e.sourceRows];break;case`filter`:i=Gu({rows:i,filterModel:e.filterModel,getCellValue:e.getCellValue,columnContext:e.filterColumnContext,quickFilterText:e.quickFilterText,quickFilterColIds:e.getQuickFilterColIds?.()??[]});break;case`sort`:i=xd({sourceRows:e.sourceRows,rows:i,currentDisplayRows:e.currentDisplayRows,sortModel:e.sortModel,touchedRowIds:e.touchedRowIds,getCellValue:e.getCellValue,getColumnComparator:e.getColumnComparator,groupComparator:n?.groupComparator});break;case`aggregate`:n&&Dc(i)&&(i=cd({rows:i,columns:n.columns}));break;case`map`:n?.prepareGroupedTree&&Dc(i)&&n.prepareGroupedTree(i),r?.prepareTreeTree&&Fc(i)&&r.prepareTreeTree(i),i=md(i,Ld(n,r))}return e.afterMap&&(i=e.afterMap(i)),e.positionRowsOptions?gc(i,e.positionRowsOptions):gc(i,e.rowHeight),i}function zd(e){return[...bi(e)]}var Bd=class{refreshing=!1;pendingRun=null;refresh(e){if(this.refreshing){this.pendingRun=e;return}this.refreshing=!0;try{let t=e;for(;t;){let e=t;t=null,e(),t=this.pendingRun,this.pendingRun=null}}finally{this.refreshing=!1}}reset(){this.refreshing=!1,this.pendingRun=null}};function Vd(e,t){for(let n of e)n.group&&(t(n),Vd(jc(n),t))}function Hd(e){let t=[];return Vd(e,e=>{e.groupId&&t.push(e.groupId)}),t}function Ud(e,t){let n;return Vd(e,e=>{e.groupId===t&&(n=e)}),n}function Wd(e,t){return t===0?!1:t===-1||e<t}var Gd=class extends Error{constructor(e){super(e),this.name=`RowModelError`}};function Kd(e,t){let{rowKey:n,rowHeight:r=m,allowTransient:i=!1}=t;if(!n)throw new Gd(`rowKey is required`);let a=new Set,o=Array(e.length);for(let t=0;t<e.length;t++){let s=e[t],c=s[n];if(yr(c)){if(!i)throw new Gd(`Missing rowKey "${n}" at index ${t}`);let e=_r();if(a.has(e))throw new Gd(`Duplicate transient row id "${e}" at index ${t}`);a.add(e),o[t]={id:e,data:s,isTransient:!0,rowTop:0,rowHeight:r,estimated:!1,rowIndex:t};continue}let l=String(c);if(a.has(l))throw new Gd(`Duplicate rowKey "${n}" value "${l}" at index ${t}`);a.add(l),o[t]={id:l,data:s,isTransient:!1,rowTop:0,rowHeight:r,estimated:!1,rowIndex:t}}return o}function qd(e,t,n){if(t.length===0)return[...e];let r=n??e.length,i=Math.max(0,Math.min(r,e.length));return[...e.slice(0,i),...t,...e.slice(i)]}function Jd(e,t){return Math.max(0,Math.min(e,t))}function Yd(e,t){if(typeof e==`string`)return e;let n=e[t];if(n==null)throw new Gd(`Missing rowKey "${t}" in remove item`);return String(n)}function Xd(e,t){if(typeof e!=`object`||!e||!(`data`in e))return!1;let n=e;return n[t]!==void 0&&n[t]!==null&&n[t]!==``?!1:typeof e.data==`object`&&e.data!==null}function Zd(e,t){return Xd(e,t)?e.data:e}function Qd(e,t){if(Xd(e,t))return e.index}function $d(e,t,n){let r=n.rowKey,i=n.rowHeight??m,a=new Map(e.map(e=>[e.id,e])),o={add:[],remove:[],update:[]},s=new Set;if(t.remove?.length)for(let e of t.remove){let t=Yd(e,r),n=a.get(t);n&&(o.remove.push(n),a.delete(t),s.add(t))}if(t.update?.length)for(let e of t.update){let t=e[r],n;if(t==null){if(n=[...a.values()].find(t=>t.data===e&&t.isTransient),!n)throw new Gd(`Missing rowKey "${r}" in update item`)}else n=a.get(String(t));n&&(n.data!==e&&Object.assign(n.data,e),o.update.push(n),s.add(n.id))}let c=new Set(o.remove.map(e=>e.id)),l=e.filter(e=>!c.has(e.id));if(t.add?.length)for(let e of t.add){let t=Zd(e,r),n=Qd(e,r),[c]=Kd([t],{rowKey:r,rowHeight:i,allowTransient:!0});if(c){if(a.has(c.id))throw new Gd(`Duplicate rowKey on add: "${c.id}"`);a.set(c.id,c),o.add.push(c),s.add(c.id),l=qd(l,[c],n)}}return{sourceRows:l,transaction:o,touchedRowIds:[...s]}}function ef(e,t){if(t<0||t>=e.length)return null;let n=e[t];return{rowTop:n.rowTop,rowHeight:n.rowHeight}}function tf(e,t){let n=e.length;if(n===0||t<=0)return 0;let r=0,i=n-1;for(;r<=i;){let n=r+i>>1,a=e[n],o=a.rowTop+a.rowHeight;if(t<a.rowTop)i=n-1;else if(t>=o)r=n+1;else return n}return n-1}var nf=class{sourceRows=[];displayRows=[];baseDisplayRows=[];sortModel=[];filterModel={};quickFilterText=``;touchedRowIds=null;rowKey;defaultRowHeight;getCellValue;getColumnComparator;filterColumnContext;getQuickFilterColIds;refreshScheduler=new Bd;positionGetRowHeight;rowExpansionService=null;rowGroupingDeps=null;treeTableDeps=null;groupedTreeRoots=[];treeTreeRoots=[];constructor(e){this.rowKey=e.rowKey,this.defaultRowHeight=e.rowHeight??m,this.getCellValue=e.getCellValue??rf,this.getColumnComparator=e.getColumnComparator,this.filterColumnContext=e.filterColumnContext,this.getQuickFilterColIds=e.getQuickFilterColIds,this.quickFilterText=e.quickFilterText??``}get rowsToDisplay(){return this.displayRows}getBaseDisplayRows(){return this.baseDisplayRows}setRowExpansionService(e){this.rowExpansionService=e}getRowExpansionService(){return this.rowExpansionService}setRowGroupingDeps(e){this.rowGroupingDeps=e,e?.active()||(this.groupedTreeRoots=[])}setTreeTableDeps(e){this.treeTableDeps=e,e?.active()||(this.treeTreeRoots=[])}getTreeTreeRoots(){return this.treeTreeRoots}getGroupedTreeRoots(){return this.groupedTreeRoots}setPositionGetRowHeight(e){this.positionGetRowHeight=e}resolvePositionRowsOptions(){return{defaultRowHeight:this.defaultRowHeight,getRowHeight:this.positionGetRowHeight}}setData(e){this.sourceRows=Kd(e,{rowKey:this.rowKey,rowHeight:this.defaultRowHeight}),this.touchedRowIds=null,this.rowExpansionService?.clearExpanded(),this.rowGroupingDeps?.clearExpanded(),this.treeTableDeps?.clearExpanded(),this.groupedTreeRoots=[],this.treeTreeRoots=[],this.refreshModel({applyDefaultExpanded:!0})}setSortModel(e){this.sortModel=[...e],this.touchedRowIds=null,this.refreshModel()}setFilterModel(e){this.filterModel={...e},this.refreshModel()}getSortModel(){return[...this.sortModel]}getFilterModel(){return{...this.filterModel}}getQuickFilterText(){return this.quickFilterText}setQuickFilterText(e){this.quickFilterText!==e&&(this.quickFilterText=e,this.refreshModel())}markTouchedRowIds(e){this.touchedRowIds=new Set(e)}applyTransaction(e){let{sourceRows:t,transaction:n,touchedRowIds:r}=$d(this.sourceRows,e,{rowKey:this.rowKey,rowHeight:this.defaultRowHeight});return this.sourceRows=t,this.markTouchedRowIds(r),this.refreshModel(),n}rebuildDisplayProjection(){if(this.treeTableDeps?.active()){this.rebuildTreeMapProjection();return}if(this.rowGroupingDeps?.active()){this.rebuildGroupedMapProjection();return}this.displayRows=this.buildProjectedDisplayRows(!1),gc(this.displayRows,this.resolvePositionRowsOptions())}rebuildTreeMapProjection(){if(this.treeTableDeps?.active()){if(this.treeTreeRoots.length===0||!Fc(this.treeTreeRoots)){this.refreshModel();return}this.refreshModel({stages:[`map`]})}}rebuildGroupedMapProjection(){if(this.rowGroupingDeps?.active()){if(this.groupedTreeRoots.length===0||!this.groupedTreeRoots.some(e=>e.group)){this.refreshModel();return}this.refreshModel({stages:[`map`]})}}getRowById(e){return this.sourceRows.find(t=>t.id===e)}resolveRowById(e){return this.getRowById(e)??this.getDisplayRowById(e)}getDisplayRowById(e){return this.displayRows.find(t=>t.id===e)}setDefaultRowHeight(e){this.defaultRowHeight=Math.max(1,e)}repositionDisplayRows(e){gc(this.displayRows,{defaultRowHeight:this.defaultRowHeight,getRowHeight:e?.getRowHeight??this.positionGetRowHeight})}getRowIndexById(e){return this.displayRows.findIndex(t=>t.id===e)}refreshModel(e={}){let t=typeof e==`boolean`?{applyDefaultExpanded:e}:e,n=t.applyDefaultExpanded??!1,r=this.rowGroupingDeps?.active()??!1,i=this.treeTableDeps?.active()??!1,a=i?`tree`:r?`group`:`flat`,o=t.stages??zd(a);this.refreshScheduler.refresh(()=>{let e=this.rowGroupingDeps,t=this.treeTableDeps,s=n;this.displayRows=Rd({sourceRows:this.sourceRows,currentDisplayRows:this.displayRows,sortModel:this.sortModel,filterModel:this.filterModel,touchedRowIds:this.touchedRowIds??void 0,getCellValue:this.getCellValue,getColumnComparator:this.getColumnComparator,filterColumnContext:this.filterColumnContext,quickFilterText:this.quickFilterText,getQuickFilterColIds:this.getQuickFilterColIds,rowHeight:this.defaultRowHeight,positionRowsOptions:this.resolvePositionRowsOptions(),stages:o,hierarchyMode:a,grouping:r&&e?{rowGroupColumns:e.getRowGroupColumns(),groupKeyCreator:e.getGroupKeyCreator(),groupComparator:e.getGroupComparator(),getColumnField:e.getColumnField,columns:e.getColumns(),getMapStageOptions:()=>({...e.getMapStageOptions(),defaultRowHeight:this.defaultRowHeight}),groupedTreeRoots:this.groupedTreeRoots,prepareGroupedTree:t=>{this.groupedTreeRoots=[...t],e.pruneExpanded(new Set(Hd(t))),s&&=(e.applyDefaultExpanded(t),!1)}}:void 0,tree:i&&t?{getDataPath:t.getDataPath(),getMapStageOptions:()=>({...t.getMapStageOptions(),defaultRowHeight:this.defaultRowHeight}),treeTreeRoots:this.treeTreeRoots,prepareTreeTree:e=>{this.treeTreeRoots=[...e],t.prepareTreeTree(e),s&&=(t.applyDefaultExpanded(e),!1)}}:void 0,afterMap:e=>this.buildProjectedDisplayRows(n,e)}),this.touchedRowIds=null})}buildProjectedDisplayRows(e,t=this.baseDisplayRows){return this.baseDisplayRows=t,this.rowExpansionService?.active?(e&&this.rowExpansionService.applyDefaultExpanded(t),this.rowExpansionService.pruneExpanded(new Set(this.sourceRows.map(e=>e.id))),this.rowExpansionService.injectDetailRows(t)):t.slice()}getRow(e){return this.displayRows[e]}getRowCount(){return this.displayRows.length}getSourceRowCount(){return this.sourceRows.length}getSourceRows(){return this.sourceRows}getSourceRowIndexById(e){return this.sourceRows.findIndex(t=>t.id===e)}setSourceRows(e){this.sourceRows=e,this.touchedRowIds=null,this.refreshModel()}getRowKey(){return this.rowKey}promoteRowId(e,t){let n=this.getRowById(e);if(!n)return{ok:!1,reason:`Row "${e}" not found`};if(!n.isTransient)return{ok:!1,reason:`Row "${e}" is not transient`};if(yr(t))return{ok:!1,reason:`businessId is required`};let r=String(t);return this.sourceRows.some(e=>e!==n&&e.id===r)?{ok:!1,reason:`Duplicate row id "${r}"`}:(n.data[this.rowKey]=t,n.id=r,n.isTransient=!1,this.markTouchedRowIds([r]),this.refreshModel(),{ok:!0,rowId:r})}getRowIndexAtPixel(e){return tf(this.displayRows,e)}getRowBounds(e){return ef(this.displayRows,e)}getTotalHeight(){return _c(this.displayRows)}ensureRowHeightsValid(e,t){return!1}};function rf(e,t){return e.data[t]}function af(e,t){if(t.length===0)return!1;let n=e.__autoHeights??{};return t.some(e=>n[e]==null)}function of(e){if(!e.getRowHeight)return;let t=e.getRowHeight;return e=>t({rowId:e.id,data:e.data,rowIndex:e.rowIndex})}function sf(e,t,n){if(e.rowHeightPinned&&e.rowHeight>0)return{height:ea(e.rowHeight,n.rowHeightMin,n.rowHeightMax),estimated:!1};let r=pc(e,t,of(n));return{height:ea(r.height,n.rowHeightMin,n.rowHeightMax),estimated:r.estimated}}function cf(e,t,n){if(e.rowHeightPinned)return!1;let r=of(n)?.(e);return r!=null&&r>0||e.__autoHeights&&Object.keys(e.__autoHeights).length>0?!1:e.rowHeight===t||e.rowHeight===0}function lf(e,t){return t??(e===`api`||e===`uiRowResized`)}var uf=class{deps;defaultRowHeight;options;gridOptions;constructor(e,t,n={}){this.deps=e,this.defaultRowHeight=t,this.gridOptions=n,this.options=Zi(n,t)}getDefaultRowHeight(){return this.defaultRowHeight}setGridOptions(e={}){this.gridOptions=e,this.options=Zi(e,this.defaultRowHeight)}getOptions(){return this.options}updateDefaultRowHeight(e,t={}){let n=this.defaultRowHeight,r=Math.max(1,e);if(this.gridOptions={...this.gridOptions,...t},this.defaultRowHeight=r,this.options=Zi(this.gridOptions,r),n===r)return this.recalculateDisplayRowHeights(void 0,`dimensions`);for(let e of this.deps.getDisplayRows())cf(e,n,this.options)&&(e.rowHeight=0,e.estimated=!1);let i=this.recalculateDisplayRowHeights(void 0,`dimensions`);return i.changed||this.deps.repositionDisplayRows(),i}getRowHeight(e){let t=this.deps.getRowById(e);return t?sf(t,this.defaultRowHeight,this.options).height:null}setRowHeights(e,t){let n=[],r=lf(t.source,t.pin);for(let t of e){let e=this.deps.getRowById(t.rowId);if(!e)continue;let i=ea(t.height,this.options.rowHeightMin,this.options.rowHeightMax),a=r;(e.rowHeight!==i||e.rowHeightPinned!==a)&&(e.rowHeight=i,e.rowHeightPinned=a,e.estimated=!1,n.push({rowId:e.id,rowHeight:i}))}if(n.length===0)return{changed:!1,rows:[],finished:t.finished,source:t.source};this.deps.repositionDisplayRows();let i=ta(n,t.finished,t.source);return this.deps.emitRowHeightChanged(i),{changed:!0,rows:n,finished:t.finished,source:t.source}}setRowHeight(e,t,n=!0,r=`api`){return this.setRowHeights([{rowId:e,height:t}],{finished:n,source:r})}resetRowHeights(e){let t=this.resolveResetTargets(e),n=[];for(let e of t){e.rowHeightPinned=!1,delete e.__autoHeights,e.rowHeight=0,e.estimated=!1;let t=sf(e,this.defaultRowHeight,this.options);e.rowHeight=t.height,e.estimated=t.estimated,n.push({rowId:e.id,height:t.height})}if(n.length===0)return{changed:!1,rows:[],finished:!0,source:`api`};this.deps.repositionDisplayRows();let r=n.map(e=>({rowId:e.rowId,rowHeight:e.height})),i=ta(r,!0,`api`);return this.deps.emitRowHeightChanged(i),{changed:!0,rows:r,finished:!0,source:`api`}}recalculateDisplayRowHeights(e,t=`autoHeight`){let n=e?new Set(e):null,r=[];for(let e of this.deps.getDisplayRows()){if(n&&!n.has(e.id)||e.rowHeightPinned)continue;let t=sf(e,this.defaultRowHeight,this.options),i=this.deps.getAutoHeightColumnIds?.()??[],a=t.estimated;!e.rowHeightPinned&&i.length>0&&af(e,i)&&(a=!0),(e.rowHeight!==t.height||e.estimated!==a)&&(e.rowHeight=t.height,e.estimated=a,r.push({rowId:e.id,rowHeight:t.height}))}if(r.length===0)return{changed:!1,rows:[],finished:!0,source:t};this.deps.repositionDisplayRows();let i=ta(r,!0,t);return this.deps.emitRowHeightChanged(i),{changed:!0,rows:r,finished:!0,source:t}}getPositionRowHeightFn(){return of(this.options)}resolveResetTargets(e){return e&&e.length>0?e.map(e=>this.deps.getRowById(e)).filter(e=>e!=null):[...this.deps.getDisplayRows()]}};function df(e){return e.classList.contains(`mg-cell--editing`)||e.classList.contains(`mg-cell--inline-editor`)}function ff(e){if(df(e))return 0;let t=pf(e);if(!t)return e.offsetHeight;let n=getComputedStyle(e),r=Number.parseFloat(n.paddingTop)||0,i=Number.parseFloat(n.paddingBottom)||0,a=Number.parseFloat(n.borderTopWidth)||0,o=Number.parseFloat(n.borderBottomWidth)||0,s=t.scrollHeight;return Math.ceil(s+r+i+a+o)}function pf(e){return[e.querySelector(`.mg-cell__text:not([hidden])`),e.querySelector(`.mg-cell__renderer:not([hidden])`),e.querySelector(`.mg-cell__inline-editor:not([hidden])`)].find(e=>e!=null)??null}var mf=5,hf=1,gf=class{deps;active=!1;wasEverActive=!1;debounceTimer=null;pendingRowIds=new Set;constructor(e){this.deps=e}isActive(){return this.active}setCellHeight(e,t,n){if(!this.deps.isColumnAutoHeight(t))return;let r=this.deps.getRowById(e);if(!r)return;if(r.__autoHeights??={},n==null){r.__autoHeights[t]!=null&&(delete r.__autoHeights[t],Object.keys(r.__autoHeights).length===0&&delete r.__autoHeights,r.rowHeightPinned||this.requestCheckAutoHeight(e));return}if(r.rowHeightPinned)return;let i=r.__autoHeights[t];r.__autoHeights[t]=n,this.active=!0,this.wasEverActive=!0,i!==n&&this.requestCheckAutoHeight(e)}setupCellAutoHeight(e){if(!this.deps.isColumnAutoHeight(e.colId))return null;this.active=!0,this.wasEverActive=!0;let{rowId:t,colId:n,cellEl:r}=e;r.classList.add(Xi);let i=(e=0)=>{if(r.classList.contains(`mg-cell--editing`))return;let a=ff(r);if(a<=0&&e<mf){window.setTimeout(()=>i(e+1),0);return}a>0&&this.setCellHeight(t,n,a)};i();let a=pf(r),o=a&&typeof ResizeObserver<`u`?new ResizeObserver(()=>{r.classList.contains(`mg-cell--editing`)||i()}):null;o?.observe(a??r);let s=typeof MutationObserver<`u`?new MutationObserver(()=>{r.classList.contains(`mg-cell--editing`)||i()}):null;return s?.observe(r,{attributes:!0,attributeFilter:[`class`]}),()=>{o?.disconnect(),s?.disconnect(),r.classList.remove(Xi),this.setCellHeight(t,n,void 0)}}requestCheckAutoHeight(e){this.wasEverActive&&(this.pendingRowIds.add(e),this.scheduleRecalculate())}flushPendingRecalculate(){if(this.pendingRowIds.size===0)return;let e=[...this.pendingRowIds];this.pendingRowIds.clear(),this.deps.rowHeightService.recalculateDisplayRowHeights(e)}destroy(){this.debounceTimer!=null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingRowIds.clear(),this.active=!1}scheduleRecalculate(){this.debounceTimer??=window.setTimeout(()=>{this.debounceTimer=null,this.flushPendingRecalculate()},hf)}};function _f(e){let t=new Set;if(e.lastRow<e.firstRow)return t;for(let n=e.firstRow;n<=e.lastRow;n++)t.add(n);return t}function vf(e,t){let n=_f(t),r=[],i=[],a=[];for(let t of n)e.has(t)?i.push(t):r.push(t);for(let t of e)n.has(t)||a.push(t);return{toCreate:r,toUpdate:i,toDestroy:a}}var yf=3;function bf(e,t,n){let r=e.getRowCount();if(r===0)return t;let i=e.getTotalHeight()/r,a=e.getRowIndexAtPixel(n),o=e.getRowBounds(a)?.rowHeight??t;return Math.max(t,i,o)}function xf(e,t,n,r,i){let a=e.getRowCount(),o=t,s=n;for(;o>0;){let t=e.getRowBounds(o);if(!t||t.rowTop<=r)break;o--}for(;s<a-1;){let t=e.getRowBounds(s);if(!t||t.rowTop+t.rowHeight>=i)break;s++}return{firstRow:o,lastRow:s}}function Sf(e,t,n){for(let r=t;r<=n;r++)if(e.getRow(r)?.estimated)return!0;return!1}function Cf(e,t,n,r){let i=Math.max(n,500);return t-e+1<=i?t:Math.min(e+i-1,r-1)}function wf(e){let{scrollTop:t,viewportHeight:n,rowBuffer:r,rowHeight:i,rowModel:a}=e,o=a.getRowCount();if(o===0)return{firstRow:0,lastRow:-1};let s=0,c=o-1,l=!1;for(let e=0;e<yf&&!l;e++){let e=r*bf(a,i,t),u=Math.max(0,t-e),d=t+n+e;s=a.getRowIndexAtPixel(u),c=Math.min(a.getRowIndexAtPixel(d),o-1);let f=xf(a,s,c,u,d);s=f.firstRow,c=f.lastRow,l=!Sf(a,s,c)}return c=Cf(s,c,r,o),{firstRow:s,lastRow:c}}var Tf=class{pool=new Map;acquire(e,t){let n=this.pool.get(e);if(n)return n;let r=t();return this.pool.set(e,r),r}get(e){return this.pool.get(e)}release(e){let t=this.pool.get(e);t&&(t.destroy(),this.pool.delete(e))}migrateId(e,t){if(e===t)return;let n=this.pool.get(e);n&&(this.pool.delete(e),this.pool.set(t,n))}clear(){for(let e of this.pool.values())e.destroy();this.pool.clear()}getActiveCount(){return this.pool.size}getActiveIds(){return[...this.pool.keys()]}},Ef=`mg-selection-checkbox`,Df=`mg-selection-checkbox--header`;function Of(e){let t=document.createElement(`input`);return t.type=`checkbox`,t.className=Ef,t.setAttribute(`aria-label`,e.ariaLabel),kf(t,e),t}function kf(e,t){e.checked=t.checked,e.indeterminate=!!t.indeterminate,e.disabled=!!t.disabled,e.classList.toggle(`mg-selection-checkbox--disabled`,!!t.disabled),e.setAttribute(`aria-checked`,t.indeterminate?`mixed`:String(t.checked))}function Af(e){return e.querySelector(`input.${Ef}`)}function jf(e,t){return t.rowLabel?.(e)??`选择第 ${e+1} 行`}function Mf(e,t,n=new Set){let r=e.getRowCount();if(r===0)return{checked:!1,indeterminate:!1};let i=0,a=0;for(let o=0;o<r;o+=1){let r=e.getRow(o);r&&(Xt(r)||B(r)||(i++,t.has(r.id)&&!n.has(r.id)&&a++))}return a===0?{checked:!1,indeterminate:!1}:a===i?{checked:!0,indeterminate:!1}:{checked:!1,indeterminate:!0}}function Nf(e,t){let{selectionColumnOptions:n,selectedIds:r,indeterminateIds:i,rowModel:a}=t;if(!n.enabled||n.mode!==`multiple`)return;let o=e.querySelector(`.mg-header-cell[data-col-id="${ze}"]`);if(!o)return;let s=Af(o);s&&kf(s,Mf(a,r,i??new Set))}var Pf=[[`circle`,{cx:`12`,cy:`12`,r:`1`}],[`circle`,{cx:`12`,cy:`5`,r:`1`}],[`circle`,{cx:`12`,cy:`19`,r:`1`}]],Ff=[[`path`,{d:`m5 12 7-7 7 7`}],[`path`,{d:`M12 19V5`}]],If=[[`path`,{d:`M12 5v14`}],[`path`,{d:`m19 12-7 7-7-7`}]],Lf=[[`path`,{d:`M12 2v20`}],[`path`,{d:`m15 19-3 3-3-3`}],[`path`,{d:`m19 9 3 3-3 3`}],[`path`,{d:`M2 12h20`}],[`path`,{d:`m5 9-3 3 3 3`}],[`path`,{d:`m9 5 3-3 3 3`}]],Rf=[[`path`,{d:`M3 6h18`}],[`path`,{d:`M7 12h10`}],[`path`,{d:`M10 18h4`}]],zf=[[`path`,{d:`M12 17v5`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v3.76`}]],Bf=[[`path`,{d:`M12 17v5`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v3.76`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`}]],Vf=[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}],[`path`,{d:`M9 3v18`}]],Hf=[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}],[`path`,{d:`M15 3v18`}]],Uf=[[`path`,{d:`m9 18 6-6-6-6`}]],Wf=[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}],[`path`,{d:`M9 3v18`}],[`path`,{d:`M15 3v18`}]],Gf=[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`}]],Kf=[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`}],[`path`,{d:`m2 2 20 20`}]],qf=[[`path`,{d:`M12 2v4`}],[`path`,{d:`m16.2 7.8 2.9-2.9`}],[`path`,{d:`M18 12h4`}],[`path`,{d:`m16.2 16.2 2.9 2.9`}],[`path`,{d:`M12 18v4`}],[`path`,{d:`m7.8 16.2-2.9 2.9`}],[`path`,{d:`M2 12h4`}],[`path`,{d:`m7.8 7.8-2.9-2.9`}]];function Z(e,t,n=14){let r=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);r.setAttribute(`class`,e),r.setAttribute(`width`,String(n)),r.setAttribute(`height`,String(n)),r.setAttribute(`viewBox`,`0 0 24 24`),r.setAttribute(`fill`,`none`),r.setAttribute(`stroke`,`currentColor`),r.setAttribute(`stroke-width`,`2`),r.setAttribute(`stroke-linecap`,`round`),r.setAttribute(`stroke-linejoin`,`round`),r.setAttribute(`aria-hidden`,`true`);for(let[e,n]of t){let t=document.createElementNS(`http://www.w3.org/2000/svg`,e);for(let[e,r]of Object.entries(n))t.setAttribute(e,String(r));r.appendChild(t)}return r}function Jf(){return Z(`mg-header-icon mg-header-icon--column-handle`,Pf,14)}function Yf(e){let t=e===`asc`?Ff:If;return Z(`mg-sort-icon mg-sort-icon--${e}`,t,14)}function Xf(){let e=document.createDocumentFragment();return e.append(Yf(`asc`),Yf(`desc`)),e}function Zf(){return Z(`mg-column-drag-ghost__move-icon`,Lf,16)}function Qf(){return Z(`mg-header-icon mg-header-icon--floating-filter`,Rf,14)}function $f(){return Yf(`asc`)}function ep(){return Yf(`desc`)}function tp(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--pin`,zf,14)}function np(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--pin-off`,Bf,14)}function rp(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--pin-left`,Vf,14)}function ip(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--pin-right`,Hf,14)}function ap(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--chevron`,Uf,14)}function op(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--visibility`,Wf,14)}function sp(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--hide-column`,Kf,14)}function cp(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--show-column`,Gf,14)}function lp(){return Z(`mg-cell__row-expand__icon`,Uf,16)}function up(){return Z(`mg-cell__tree-expand__loading-icon`,qf,16)}function dp(e,t){return t?`折叠第 ${e+1} 行详情`:`展开第 ${e+1} 行详情`}function fp(){let e=document.createElement(`button`);return e.type=`button`,e.className=Je,e.setAttribute(`aria-expanded`,`false`),e.appendChild(lp()),e}function pp(e,t){if(!t.visible){e.hidden=!0,e.classList.remove(Ye),e.setAttribute(`aria-expanded`,`false`);return}e.hidden=!1,e.setAttribute(`aria-label`,t.ariaLabel),e.setAttribute(`aria-expanded`,String(t.expanded)),e.classList.toggle(Ye,t.expanded)}var mp=`mg-cell__group-content`,hp=`mg-cell__group-label`,gp=`mg-cell__group-count`;function _p(e,t,n){let r=n>0?`,${n} 条`:``;return t?`折叠分组 ${e}${r}`:`展开分组 ${e}${r}`}function vp(e,t){return e.groupFooterLabel??t.getGroupFooterLabel?.()??`小计`}function yp(e,t){return Yt(t)&&e.showGroupFooterCell&&!Et(e)}function bp(e,t,n){let r={visible:!1,showChevron:!1,expanded:!1,indentLevel:0,label:``,showCount:!1,count:0,ariaLabel:``};if(!t.active())return r;if(Jt(e)){if(n&&!Pt(n))return r;let i=e.sourceGroupId??qt(e.id)??e.groupId??``,a=e.groupKey??``,o=e.groupLeafCount??0,s=i?t.isExpanded(i):!1;return{visible:!0,showChevron:!!i,expanded:s,indentLevel:e.groupLevel??0,label:a,showCount:o>0,count:o,ariaLabel:_p(a,s,o)}}if(Yt(e)){if(n&&!Ft(n))return r;let i=n?vp(n,t):t.getGroupFooterLabel?.()??`小计`;return{visible:!0,showChevron:!1,expanded:!1,indentLevel:e.groupLevel??0,label:i,showCount:!1,count:0,ariaLabel:i}}return Zt(e),r}function xp(e){return`(${e})`}function Sp(){let e=document.createElement(`button`);return e.type=`button`,e.className=yt,e.setAttribute(`aria-expanded`,`false`),e.appendChild(lp()),e}function Cp(e,t){if(!t.showChevron){e.hidden=!0,e.classList.remove(bt),e.setAttribute(`aria-expanded`,`false`);return}e.hidden=!1,e.setAttribute(`aria-label`,t.ariaLabel),e.setAttribute(`aria-expanded`,String(t.expanded)),e.classList.toggle(bt,t.expanded)}function wp(e,t){for(let t=e.classList.length-1;t>=0;--t){let n=e.classList.item(t);n?.startsWith(`mg-cell__group-indent-`)&&e.classList.remove(n)}e.classList.add(`${xt}${Math.max(0,t)}`),e.style.paddingLeft=`${Math.max(0,t)*16}px`}function Tp(e,t,n,r,i){e.classList.toggle(wt,i.visible),wp(e,i.indentLevel),t&&Cp(t,i),n.textContent=i.label,n.hidden=i.label.length===0,i.showCount&&i.count>0?(r.textContent=xp(i.count),r.hidden=!1):(r.textContent=``,r.hidden=!0)}function Ep(e,t){return ln(e.colId)&&H(t)}function Dp(e,t){return t?`折叠 ${e}`:`展开 ${e}`}function Op(e,t){let n={visible:!1,showChevron:!1,expanded:!1,indentLevel:0,label:``,showCount:!1,count:0,ariaLabel:``};if(!t.active()||!H(e))return n;let r=t.getTreeValue?.(e)??e.dataPath?.[e.dataPath.length-1]??``,i=t.isExpanded(e.id),a=t.isTreeNodeLoading?.(e.id)??!1;return{visible:!0,showChevron:t.isTreeNodeExpandable?.(e)??e.treeLeaf!==!0,expanded:i,loading:a,indentLevel:e.treeLevel??0,label:r,showCount:!1,count:0,ariaLabel:Dp(r,i)}}function kp(){let e=Sp();return e.className=tn,e}function Ap(e,t){if(jp(e,!!t.loading),!t.showChevron){e.hidden=!0,e.classList.remove(nn,rn),e.disabled=!1,e.setAttribute(`aria-expanded`,`false`),e.setAttribute(`aria-busy`,`false`);return}e.hidden=!1,e.setAttribute(`aria-label`,t.ariaLabel),e.setAttribute(`aria-expanded`,String(t.expanded&&!t.loading)),e.classList.toggle(nn,t.expanded&&!t.loading),e.classList.toggle(rn,!!t.loading),e.disabled=!!t.loading,e.setAttribute(`aria-busy`,t.loading?`true`:`false`)}function jp(e,t){let n=e.querySelector(`.mg-cell__row-expand__icon`),r=e.querySelector(`.mg-cell__tree-expand__loading-icon`);if(t){if(n instanceof SVGElement&&n.setAttribute(`hidden`,`hidden`),!(r instanceof SVGElement)){e.appendChild(up());return}r.removeAttribute(`hidden`);return}if(r instanceof SVGElement&&r.remove(),n instanceof SVGElement){n.removeAttribute(`hidden`);return}e.appendChild(lp())}function Mp(e,t){for(let t=e.classList.length-1;t>=0;--t){let n=e.classList.item(t);(n?.startsWith(`mg-cell__tree-indent-`)||n?.startsWith(`mg-cell__group-indent-`))&&e.classList.remove(n)}e.classList.add(`${an}${Math.max(0,t)}`),e.style.paddingLeft=`${Math.max(0,t)*16}px`}function Np(e,t,n,r){e.classList.toggle(on,r.visible),e.classList.toggle(wt,r.visible),Mp(e,r.indentLevel),t&&Ap(t,r),n.textContent=r.label,n.hidden=r.label.length===0}function Pp(e,t,n,r){if(r){if(t)return t;let r=kp();return e.insertBefore(r,n),r}return t&&t.remove(),null}function Fp(e,t,n,r){if(r){if(t)return t;let r=Sp();return e.insertBefore(r,n),r}return t&&t.remove(),null}function Ip(e,t){return e===t}var Lp=class{cachedValue=``;cachedRenderKey=``;cacheVersion=-1;inlineSession=null;activeResolveBusinessRowId;pendingVueRendererContext=null;refreshCell(e,t,n,r,i=!1){let a=typeof i==`boolean`?{force:i}:i,o=a.force??!1;this.activeResolveBusinessRowId=a.resolveBusinessRowId;let s=a.cellDisableContext??a.getCellDisableContext?.(),c=a.cellStyleContext??a.getCellStyleContext?.(),l=a.indexColumnOptions,u=a.selectionColumnOptions;if(Sn(t.colId,e.rowKind,t.prop,e.id)&&this.syncCellDisabledVisual(e,t,n,s),this.syncCellStyleVisual(e,t,n,c),R(t.colId))return this.clearInlineSession(n),this.refreshSelectionCell(e,t,n,r,o,u,a.selectionChecked??!1,a.selectionDisabled??!1,a.selectionIndeterminate??!1);if(nt(t)&&a.rowExpansionHost?.active())return this.clearInlineSession(n),this.refreshExpandCell(e,t,n,r,o,a.rowExpansionHost);if(It(t,e)&&a.rowGroupingHost?.active())return this.clearInlineSession(n),this.refreshGroupCell(e,t,n,r,o,a.rowGroupingHost);if(Ep(t,e)&&a.treeTableHost?.active())return this.clearInlineSession(n),this.refreshTreeCell(e,n,r,o,a.treeTableHost);if(!L(t.colId)&&ka(t)&&a.inlineEditor)return this.refreshInlineEditorCell(e,t,n,r,o,a.inlineEditor,a,a.scheduleInlineEditor);if(this.clearInlineSession(n),!L(t.colId)&&t.cellRenderer)return this.refreshRendererCell(e,t,n,r,o,a.scheduleRenderer,a.cellRendererDefer,a.cellRendererPresentation,a.scrollActive,l);let d=sr(e,t,l);return!o&&this.cacheVersion===r&&Ip(this.cachedValue,d)?!1:(n.clearRenderer(),this.cachedValue=d,this.cachedRenderKey=``,this.cacheVersion=r,n.setValue(d),!0)}syncCellDisabledVisual(e,t,n,r){let i=En(t,e,r);n.setCellDisabled(i)}syncCellStyleVisual(e,t,n,r){let i=Qn(t,e,r);n.setCellStyle(i)}invalidate(){this.cacheVersion=-1,this.cachedRenderKey=``,this.inlineSession=null,this.pendingVueRendererContext=null}hasPendingVueRenderer(){return this.pendingVueRendererContext!==null}promoteVueRenderer(e,t,n={}){let r=this.pendingVueRendererContext;if(!r)return!1;this.pendingVueRendererContext=null,this.cachedRenderKey.endsWith(`:placeholder`)&&(this.cachedRenderKey=this.cachedRenderKey.slice(0,-12));let i=()=>{this.applyRenderer(r.column,t,r.params)};return n.scheduleRenderer&&Rl(r.cellRendererPresentation,r.cellRendererDefer,r.column.cellRenderer,r.column.cellRendererMount)&&n.scheduleRenderer?(n.scheduleRenderer(i),!0):(i(),!0)}clearInlineSession(e){this.inlineSession&&(this.inlineSession.mounted.destroy(),this.inlineSession=null,e.clearInlineEditor())}refreshInlineEditorCell(e,t,n,r,i,a,o,s){let c=G(e,t),l=o.cellDisableContext??o.getCellDisableContext?.(),u=U(t,e,l),d=En(t,e,l),f=!u,p=ur(r,e.id,t.colId,c,u,d,t.cellEditor);if(!i&&this.cacheVersion===r&&this.cachedRenderKey===p&&this.inlineSession)return Rp(this.inlineSession.mounted,c,f),n.setInlineEditorDisabledVisual(d),!1;this.cachedRenderKey=p,this.cachedValue=String(c),this.cacheVersion=r;let m=()=>{this.mountInlineEditor(e,t,n,a,f,d)};return s?(s(m),!0):(m(),!0)}mountInlineEditor(e,t,n,r,i,a){this.clearInlineSession(n);let o=n;o.prepareForInlineEditor(a);let s=o.getInlineEditorMountEl(),c=null,l={...r.createParams(e,t),commit:async()=>{if(!c)return;let a=n;a.setInlineEditorCommitting(!0);let o=c.getFocusTarget();o instanceof HTMLInputElement&&(o.disabled=!0);try{let n=G(e,t);await r.commit(e,t,c.getValue(),n)||Rp(c,G(e,t),i)}finally{a.setInlineEditorCommitting(!1),o instanceof HTMLInputElement&&(o.disabled=i)}}};c=r.host.mount(s,t,l),this.inlineSession={renderKey:this.cachedRenderKey,mounted:c},Rp(c,l.value,i);let u=c.getFocusTarget();u instanceof HTMLInputElement&&(u.disabled=i)}refreshSelectionCell(e,t,n,r,i,a,o,s,c){let l=n;if(Xt(e)){let e=`group-row:no-selection`;return!i&&this.cacheVersion===r&&this.cachedValue===e?!1:(this.cachedValue=e,this.cachedRenderKey=``,this.cacheVersion=r,l.clearSelectionCheckbox(),l.setValue(``),!0)}let u=a?jf(e.rowIndex,a.selectionColumn):`选择第 ${e.rowIndex+1} 行`,d=`${o}:${s}:${c}:${u}`;return!i&&this.cacheVersion===r&&this.cachedValue===d?!1:(this.cachedValue=d,this.cachedRenderKey=``,this.cacheVersion=r,l.setSelectionCheckbox({checked:o,disabled:s,indeterminate:c,ariaLabel:u}),!0)}refreshExpandCell(e,t,n,r,i,a){let o=!B(e)&&a.isRowMaster(e),s=o&&a.isExpanded(e.id),c=dp(e.rowIndex,s),l=`${o}:${s}:${c}`;if(!i&&this.cacheVersion===r&&this.cachedValue===l)return!1;this.cachedValue=l,this.cachedRenderKey=``,this.cacheVersion=r;let u=n;return o?(u.setRowExpandButton({visible:!0,expanded:s,ariaLabel:c}),!0):(u.clearRowExpandButton(),u.setValue(``),!0)}refreshGroupCell(e,t,n,r,i,a){if(yp(t,e)){let e=vp(t,a);return!i&&this.cacheVersion===r&&this.cachedValue===e?!1:(this.cachedValue=e,this.cachedRenderKey=``,this.cacheVersion=r,n.setValue(e),!0)}let o=bp(e,a,t),s=[o.visible,o.showChevron,o.expanded,o.indentLevel,o.label,o.showCount,o.count,o.ariaLabel].join(`:`);if(!i&&this.cacheVersion===r&&this.cachedValue===s)return!1;this.cachedValue=s,this.cachedRenderKey=``,this.cacheVersion=r;let c=n;return o.visible?(c.setGroupCell(o),!0):(c.clearGroupCell(),c.setValue(``),!0)}refreshTreeCell(e,t,n,r,i){let a=Op(e,i),o=[`tree`,a.visible,a.showChevron,a.expanded,a.loading,a.indentLevel,a.label,a.ariaLabel].join(`:`);if(!r&&this.cacheVersion===n&&this.cachedValue===o)return!1;this.cachedValue=o,this.cachedRenderKey=``,this.cacheVersion=n;let s=t;return a.visible?(s.setTreeCell(a),!0):(s.clearGroupCell(),s.setValue(``),!0)}refreshRendererCell(e,t,n,r,i,a,o=`always`,s=`deferred`,c=!1,l){let u=sr(e,t,l),d=`${r}:${e.id}:${t.colId}:${u}`,f=Il(t.cellRenderer);if(!i&&this.cacheVersion===r&&this.cachedRenderKey===d&&!this.pendingVueRendererContext||!i&&this.cacheVersion===r&&this.cachedRenderKey===`${d}:placeholder`&&this.pendingVueRendererContext&&c)return!1;this.cachedValue=u,this.cacheVersion=r;let p={rowId:this.activeResolveBusinessRowId?.(e)??e.id,rowIndex:e.rowIndex,colId:t.colId,value:G(e,t),data:e.data,formattedValue:u};if(s===`placeholder-then-vue`&&f&&c)return this.cachedRenderKey=`${d}:placeholder`,this.pendingVueRendererContext={column:t,params:p,cellRendererDefer:o,cellRendererPresentation:s,indexColumnOptions:l},n.setRendererPlaceholder(u),!0;this.pendingVueRendererContext=null,this.cachedRenderKey=d;let m=()=>{this.applyRenderer(t,n,p)};return a&&Rl(s,o,t.cellRenderer,t.cellRendererMount)&&a?(a(m),!0):(m(),!0)}applyRenderer(e,t,n){let r=e.cellRenderer;if(!r)return;let i=t,a=Il(r);a&&i.canPatchVueRenderer(e.colId)?i.prepareForRendererPatch():i.prepareForRenderer();let o=t.getRendererMountEl(),s=r(n,{mountEl:o,clear:()=>{t.clearRenderer()}});a&&s==null&&i.markVueRendererMounted(e.colId),s!=null&&(typeof s==`string`||s instanceof HTMLElement)&&Do.apply(o,s)}};function Rp(e,t,n){let r=e.getFocusTarget();!(r instanceof HTMLInputElement)||r.type!==`checkbox`||(r.checked=j(t),r.disabled=n)}function zp(e,t){let n=e.masterRowId;if(!n)return null;let r=t?.(n);return{rowId:e.id,masterRowId:n,data:e.data,detailRowData:r?.__detailRowData,loading:r?.__detailLoading??!1,loadFailed:r?.__detailLoadError!==void 0,loadError:r?.__detailLoadError}}function Bp(e,t,n,r={}){let i=()=>{if(r.onUnmountRenderer?.(e),e.replaceChildren(),!n){t.loading?e.textContent=`Loading…`:t.loadFailed&&(e.textContent=`Failed to load detail`),r.onAfterRender?.();return}let i={mountEl:e,clear:()=>{r.onUnmountRenderer?.(e),e.replaceChildren()}},a=n(t,i);if(typeof a==`string`){i.clear(),e.textContent=a;return}a instanceof HTMLElement&&(i.clear(),e.appendChild(a)),r.onAfterRender?.()},a=r.rowIndex??0;if(r.frameService){r.frameService.createTask(i,a,`f1`);return}i()}function Vp(e,t){e.classList.toggle(Hl,t===`filled`),e.classList.toggle(Ul,t===`empty`),e.removeAttribute(`data-has-comment`),e.removeAttribute(`data-comment-empty`),t===`filled`?e.dataset.hasComment=`true`:t===`empty`&&(e.dataset.commentEmpty=`true`)}var Hp=class{element;textEl;rendererMount;inlineEditorMount;onUnmountRenderer;onUnmountEditor;selectionCheckbox=null;rowExpandButton=null;groupContentEl=null;groupExpandButton=null;groupLabelEl=null;groupCountEl=null;rowResizeHandle=null;rowDragHandle=null;usingRenderer=!1;usingInlineEditor=!1;vueRendererActive=!1;vueRendererColId;rendererPlaceholderActive=!1;lastCellStyle={};constructor(e,t={}){this.onUnmountRenderer=t.onUnmountRenderer,this.onUnmountEditor=t.onUnmountEditor,this.element=document.createElement(`div`),this.element.className=`mg-cell`,this.textEl=document.createElement(`span`),this.textEl.className=`mg-cell__text`,this.rendererMount=document.createElement(`div`),this.rendererMount.className=`mg-cell__renderer`,this.rendererMount.hidden=!0,this.inlineEditorMount=document.createElement(`div`),this.inlineEditorMount.className=`mg-cell__inline-editor`,this.inlineEditorMount.hidden=!0,this.element.append(this.textEl,this.rendererMount,this.inlineEditorMount),e.appendChild(this.element)}setLayout(e,t){Ao(this.element,{left:e,width:t,fixed:null},`mg-cell`)}setColumnLayout(e){Ao(this.element,e,`mg-cell`)}setValue(e){this.clearSelectionCheckbox(),this.clearRowExpandButton(),this.clearGroupCell(),this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!1,this.textEl.textContent!==e&&(this.textEl.textContent=e)}setSelectionCheckbox(e){if(this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,this.element.classList.toggle(`mg-cell--selection-disabled`,!!e.disabled),!this.selectionCheckbox){this.selectionCheckbox=Of(e),this.element.append(this.selectionCheckbox);return}kf(this.selectionCheckbox,e),this.selectionCheckbox.getAttribute(`aria-label`)!==e.ariaLabel&&this.selectionCheckbox.setAttribute(`aria-label`,e.ariaLabel)}clearSelectionCheckbox(){this.selectionCheckbox&&=(this.selectionCheckbox.remove(),null)}getSelectionCheckbox(){return this.selectionCheckbox}setRowExpandButton(e){if(this.clearInlineEditor(),this.clearRenderer(),this.clearGroupCell(),this.textEl.hidden=!0,this.textEl.textContent=``,!e.visible){this.clearRowExpandButton();return}this.rowExpandButton||(this.rowExpandButton=fp(),this.element.append(this.rowExpandButton)),pp(this.rowExpandButton,e)}clearRowExpandButton(){this.rowExpandButton&&=(this.rowExpandButton.remove(),null)}getRowExpandButton(){return this.rowExpandButton}setGroupCell(e){if(this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,!e.visible){this.clearGroupCell();return}this.groupContentEl||(this.groupContentEl=document.createElement(`div`),this.groupContentEl.className=mp,this.groupLabelEl=document.createElement(`span`),this.groupLabelEl.className=hp,this.groupCountEl=document.createElement(`span`),this.groupCountEl.className=gp,this.groupContentEl.append(this.groupLabelEl,this.groupCountEl),this.element.append(this.groupContentEl)),this.groupExpandButton=Fp(this.groupContentEl,this.groupExpandButton,this.groupLabelEl,e.showChevron),Tp(this.groupContentEl,this.groupExpandButton,this.groupLabelEl,this.groupCountEl,e)}setTreeCell(e){if(this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,!e.visible){this.clearGroupCell();return}this.groupContentEl||(this.groupContentEl=document.createElement(`div`),this.groupContentEl.className=mp,this.groupLabelEl=document.createElement(`span`),this.groupLabelEl.className=hp,this.groupCountEl=document.createElement(`span`),this.groupCountEl.className=gp,this.groupCountEl.hidden=!0,this.groupContentEl.append(this.groupLabelEl,this.groupCountEl),this.element.append(this.groupContentEl)),this.groupExpandButton=Pp(this.groupContentEl,this.groupExpandButton,this.groupLabelEl,e.showChevron),Np(this.groupContentEl,this.groupExpandButton,this.groupLabelEl,e)}clearGroupCell(){this.groupContentEl&&(this.groupContentEl.remove(),this.groupContentEl=null,this.groupExpandButton=null,this.groupLabelEl=null,this.groupCountEl=null)}getGroupExpandButton(){return this.groupExpandButton}setRendererResult(e){this.prepareForRenderer(),Do.apply(this.rendererMount,e)}prepareForRenderer(){this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,this.rendererMount.hidden=!1,this.usingRenderer=!0}prepareForRendererPatch(){this.clearInlineEditor(),this.textEl.hidden=!0,this.textEl.textContent=``,this.rendererMount.hidden=!1,this.usingRenderer=!0}canPatchVueRenderer(e){return this.usingRenderer&&this.vueRendererActive&&this.vueRendererColId===e}markVueRendererMounted(e){this.vueRendererActive=!0,this.vueRendererColId=e,this.rendererPlaceholderActive=!1}setRendererPlaceholder(e){this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!1,this.textEl.textContent!==e&&(this.textEl.textContent=e),this.rendererMount.hidden=!0,this.usingRenderer=!1,this.rendererPlaceholderActive=!0}isRendererPlaceholderActive(){return this.rendererPlaceholderActive}prepareForInlineEditor(e){this.clearSelectionCheckbox(),this.clearRowExpandButton(),this.clearGroupCell(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,this.inlineEditorMount.hidden=!1,this.usingInlineEditor=!0,this.element.classList.add(`mg-cell--inline-editor`),this.setInlineEditorDisabledVisual(e)}clearInlineEditor(){(this.usingInlineEditor||this.inlineEditorMount.childNodes.length>0)&&this.onUnmountEditor?.(this.inlineEditorMount),this.inlineEditorMount.replaceChildren(),this.inlineEditorMount.hidden=!0,this.usingInlineEditor=!1,this.element.classList.remove(`mg-cell--inline-editor`,`mg-cell--inline-disabled`,`mg-cell--committing`)}getInlineEditorMountEl(){return this.inlineEditorMount}setInlineEditorDisabledVisual(e){this.element.classList.toggle(`mg-cell--inline-disabled`,e),this.setCellDisabled(e)}setInlineEditorCommitting(e){this.setCommittingVisual(e)}setCommittingVisual(e){this.element.classList.toggle(`mg-cell--committing`,e)}clearRenderer(){(this.usingRenderer||this.rendererMount.childNodes.length>0)&&this.onUnmountRenderer?.(this.rendererMount),Do.clear(this.rendererMount),this.rendererMount.hidden=!0,this.usingRenderer=!1,this.vueRendererActive=!1,this.vueRendererColId=void 0,this.rendererPlaceholderActive=!1}hasRenderer(){return this.usingRenderer}getRendererMountEl(){return this.rendererMount}setColId(e){this.element.dataset.colId=e}setFocused(e){this.element.classList.toggle(`mg-cell--focused`,e)}setRangeSelected(e){this.element.classList.toggle(is,e)}setRangeAnchor(e){this.element.classList.toggle(as,e)}setIndexRangeHighlight(e){this.element.classList.toggle(Ts,e)}playRangeCopyFlash(){this.element.classList.remove(ms),this.element.offsetWidth,this.element.classList.add(ms);let e=()=>{this.element.classList.remove(ms),this.element.removeEventListener(`animationend`,e)};this.element.addEventListener(`animationend`,e)}playRangePasteFlash(e){this.element.classList.remove(gs,_s),this.element.offsetWidth,this.element.classList.add(e?_s:gs);let t=()=>{this.element.classList.remove(gs,_s),this.element.removeEventListener(`animationend`,t)};this.element.addEventListener(`animationend`,t)}setCellDisabled(e){if(this.element.classList.toggle(vn,e),e){this.element.setAttribute(`aria-disabled`,`true`),this.element.setAttribute(yn,`true`);return}this.element.removeAttribute(`aria-disabled`),this.element.removeAttribute(yn)}setCellStyle(e){let t=this.lastCellStyle,n=e.backgroundColor,r=e.color;t.backgroundColor!==n&&(n===void 0||n===``?this.element.style.removeProperty(`background-color`):this.element.style.backgroundColor=n),t.color!==r&&(r===void 0||r===``?this.element.style.removeProperty(`color`):this.element.style.color=r),this.lastCellStyle={backgroundColor:n,color:r},n!==void 0&&n!==``?this.element.setAttribute(zn,`true`):this.element.removeAttribute(zn)}setCommentIndicator(e){Vp(this.element,e)}setRowDragHandle(e){if(e){this.rowDragHandle||(this.rowDragHandle=document.createElement(`div`),this.rowDragHandle.className=na,this.rowDragHandle.setAttribute(`role`,`button`),this.rowDragHandle.setAttribute(`aria-label`,`拖拽行`),this.rowDragHandle.append(Jf()),this.element.prepend(this.rowDragHandle)),this.element.classList.add(`mg-cell--row-draggable`);return}this.clearRowDragHandle()}clearRowDragHandle(){this.rowDragHandle?.remove(),this.rowDragHandle=null,this.element.classList.remove(`mg-cell--row-draggable`)}setRowResizeHandle(e){if(e){this.rowResizeHandle||(this.rowResizeHandle=document.createElement(`div`),this.rowResizeHandle.className=Ji,this.rowResizeHandle.setAttribute(`role`,`separator`),this.rowResizeHandle.setAttribute(`aria-orientation`,`horizontal`),this.element.append(this.rowResizeHandle)),this.element.classList.add(`mg-cell--row-resizable`);return}this.clearRowResizeHandle()}clearRowResizeHandle(){this.rowResizeHandle?.remove(),this.rowResizeHandle=null,this.element.classList.remove(`mg-cell--row-resizable`)}getColId(){return this.element.dataset.colId}getElement(){return this.element}destroy(){this.clearSelectionCheckbox(),this.clearRowExpandButton(),this.clearRowDragHandle(),this.clearRowResizeHandle(),this.clearInlineEditor(),this.clearRenderer(),this.element.remove()}},Up=class{element;lanes;frameService;onUnmountRenderer;onUnmountEditor;inlineEditor;indexColumnOptions;selectionColumnOptions;rowAutoHeightService;isRowDragHandleEnabled;isRowDragCommittingRow;enableCellSpan;cellSpanService;getRowByIndex;getRowCount;isRowCoverHighlighted;spannedRowOnly;embedFullWidthRows;getDetailCellRenderer;getMasterRowById;rowExpansionHost;rowGroupingHost;treeTableHost;getCellCommentHost;detailRowAutoHeightService;resolveBusinessRowId;getCellDisableContext;getCellStyleContext;cellRendererDefer;isScrollActive;cellRendererPresentation;fullWidthEmbedContentEl=null;isFullWidthEmbedActive=!1;autoHeightCleanups=new Map;columnModel=null;columnWindow={firstCol:0,lastCol:-1};rowNode=null;stripe=!1;valueCacheVersion=0;selected=!1;selectionIndeterminate=!1;indexFocused=!1;indexColumnRangeHighlighted=!1;selectionDisabled=!1;lastRowTop=null;pendingRendererTasks=[];rendererBatchDepth=0;constructor(e,t={}){this.stripe=t.stripe??!1,this.frameService=t.frameService??null,this.onUnmountRenderer=t.onUnmountRenderer,this.onUnmountEditor=t.onUnmountEditor,this.inlineEditor=t.inlineEditor,this.indexColumnOptions=t.indexColumnOptions,this.selectionColumnOptions=t.selectionColumnOptions,this.rowAutoHeightService=t.rowAutoHeightService??null,this.isRowDragHandleEnabled=t.isRowDragHandleEnabled,this.isRowDragCommittingRow=t.isRowDragCommittingRow,this.enableCellSpan=t.enableCellSpan??!1,this.cellSpanService=t.cellSpanService??null,this.getRowByIndex=t.getRowByIndex,this.getRowCount=t.getRowCount,this.isRowCoverHighlighted=t.isRowCoverHighlighted,this.spannedRowOnly=t.spannedRowOnly??!1,this.embedFullWidthRows=t.embedFullWidthRows??!1,this.getDetailCellRenderer=t.getDetailCellRenderer,this.getMasterRowById=t.getMasterRowById,this.rowExpansionHost=t.rowExpansionHost,this.rowGroupingHost=t.rowGroupingHost,this.treeTableHost=t.treeTableHost,this.getCellCommentHost=t.getCellCommentHost,this.detailRowAutoHeightService=t.detailRowAutoHeightService??null,this.resolveBusinessRowId=t.resolveBusinessRowId,this.getCellDisableContext=t.getCellDisableContext,this.getCellStyleContext=t.getCellStyleContext,this.cellRendererDefer=t.cellRendererDefer??`always`,this.isScrollActive=t.isScrollActive,this.cellRendererPresentation=t.cellRendererPresentation??`deferred`,this.element=document.createElement(`div`),this.element.className=`mg-row`,this.spannedRowOnly&&this.element.classList.add(`mg-row--spanned`),this.syncTopPositioningClass(),this.lanes={left:this.createLane(`left`),center:this.createLane(`center`),right:this.createLane(`right`)},this.element.append(this.lanes.left.element,this.lanes.center.element,this.lanes.right.element),e.appendChild(this.element)}setSelected(e,t=!1){this.selected=e,this.selectionIndeterminate=t,this.element.classList.toggle(`mg-row--selected`,e),this.syncSelectionColumnCheckbox(),this.syncRowSpanHighlights()}setSelectionDisabled(e){this.selectionDisabled=e,this.syncSelectionColumnCheckbox()}setIndexFocused(e){this.indexFocused=e,this.element.classList.toggle(`mg-row--index-focused`,e),this.syncIndexFocusedVisual(),this.syncRowSpanHighlights()}setIndexColumnRangeHighlight(e){this.indexColumnRangeHighlighted!==e&&(this.indexColumnRangeHighlighted=e,this.syncIndexColumnRangeHighlightVisual())}setFocusedColId(e){for(let t of Object.values(this.lanes))for(let n of t.cells){let t=n.getColId();n.setFocused(e!==null&&t===e)}}setCellRangeSelection(e,t,n){for(let r of Object.values(this.lanes))for(let i of r.cells){let r=i.getColId()??``,a=i.getElement(),o=Number(a.dataset.rowSpan??1),s=o>1&&this.rowNode&&this.getRowByIndex&&n?Zo({head:this.rowNode,rowSpan:o,colId:r,getRowByIndex:this.getRowByIndex,isCellSelected:n}):e(r);i.setRangeSelected(s),i.setRangeAnchor(t!==null&&r===t)}}flashCellRangeSelection(e,t){for(let n of Object.values(this.lanes))for(let r of n.cells){let n=r.getColId()??``,i=r.getElement(),a=Number(i.dataset.rowSpan??1);(a>1&&this.rowNode&&this.getRowByIndex&&t?Zo({head:this.rowNode,rowSpan:a,colId:n,getRowByIndex:this.getRowByIndex,isCellSelected:t}):e(n))&&r.playRangeCopyFlash()}}flashCellRangePaste(e){for(let t of Object.values(this.lanes))for(let n of t.cells){let t=n.getColId(),r=e.find(e=>e.colId===t);r&&n.playRangePasteFlash(!r.applied)}}setRowTop(e){this.lastRowTop=e,this.applyRowTop(e)}syncRowLayout(e){if(this.rowNode=e,this.spannedRowOnly){this.syncSpannedRowHeight();return}this.syncRowHeight(e.rowHeight)}setRowDragCommittingVisual(e){this.element.classList.toggle(sa,e)}syncRowDragCommittingVisual(){this.rowNode&&this.setRowDragCommittingVisual(this.isRowDragCommittingRow?.(this.rowNode.id)??!1)}syncRowHeight(e){let t=`${e}px`;this.element.style.height=t,this.element.style.setProperty(`--mg-row-height`,t)}syncSpannedRowHeight(){this.element.style.height=`0px`,this.element.style.setProperty(`--mg-row-height`,`0px`)}setData(e,t,n,r=0,i=!1,a){if(this.rowNode=e,this.columnModel=t,this.columnWindow=n,this.valueCacheVersion=r,this.element.dataset.rowId=e.id,this.spannedRowOnly?this.syncSpannedRowHeight():this.syncRowHeight(e.rowHeight),this.element.style.width=`${t.getTotalWidth()}px`,this.syncLaneWidths(),this.embedFullWidthRows&&B(e)){this.syncFullWidthEmbedRow(e,i);return}this.isFullWidthEmbedActive&&this.clearFullWidthEmbedState(),this.syncCells(),this.syncRowDragCommittingVisual(),this.syncStripeClass(),this.syncLastRowClass(i),this.syncExpandedMasterClass(),this.syncGroupRowClasses(),a?.columnStructureChanged?this.syncCellValues(`structure-changed`):this.syncCellValues(`all`),this.syncAutoHeightCells(),this.syncCellCommentIndicators()}setEnableCellSpan(e){this.enableCellSpan!==e&&(this.enableCellSpan=e,this.syncTopPositioningClass(),this.lastRowTop!==null&&this.applyRowTop(this.lastRowTop))}setCellSpanService(e){this.cellSpanService=e}setRowSpanAccessors(e){this.getRowByIndex=e.getRowByIndex,this.getRowCount=e.getRowCount}refreshCells(e){if(!this.rowNode)return 0;if(this.columnModel=e.columnModel,this.columnWindow=e.columnWindow,this.valueCacheVersion=e.valueCacheVersion,e.inlineEditor&&(this.inlineEditor=e.inlineEditor),this.syncLaneWidths(),this.isFullWidthEmbedActive)return this.syncFullWidthEmbedPinnedLanes(),this.syncFullWidthEmbedContent(),1;this.enableCellSpan&&this.syncCells();let t=e.indexColumnOptions??this.indexColumnOptions,n=e.selectionColumnOptions??this.selectionColumnOptions,r=e.colIds?new Set(e.colIds):null;if(!this.hasVisibleCells()||!this.columnModel)return 0;let i=e.force??!1,a=this.withRendererBatch(()=>{let e=0;for(let a of[`left`,`center`,`right`]){let o=this.lanes[a];for(let s=0;s<o.indices.length;s++)this.refreshCellAtLaneIndex(a,s,r,i,t,n)&&e++}return e});return this.syncAutoHeightCells(r,i),this.syncCellCommentIndicators(r),a}promoteRendererPlaceholders(){return!this.rowNode||!this.columnModel||this.isFullWidthEmbedActive?0:this.withRendererBatch(()=>{let e=0;for(let t of[`left`,`center`,`right`]){let n=this.lanes[t];for(let r=0;r<n.indices.length;r++)this.promoteRendererPlaceholderAtLaneIndex(t,r)&&e++}return e})}syncCellCommentIndicators(e=null){let t=this.getCellCommentHost?.();if(!t?.active()||!this.rowNode||!this.columnModel||this.isFullWidthEmbedActive)return;let n=this.rowNode,r=at(n.rowKind);for(let i of[`left`,`center`,`right`]){let a=this.lanes[i];for(let i=0;i<a.indices.length;i++){let o=a.indices[i],s=o===void 0?void 0:this.columnModel.getColumn(o),c=a.cells[i];if(!s||!c)continue;let{colId:l}=s;if(e&&!e.has(l))continue;if(!Ql(l,r,n.id)){c.setCommentIndicator(`none`);continue}let u=t.hasComment(n.id,l),d=t.canCreateComment(n.id,l);c.setCommentIndicator(u?`filled`:d?`empty`:`none`)}}}getElement(){return this.element}destroy(){this.clearFullWidthEmbedState(),this.clearAutoHeightCleanups();for(let e of Object.values(this.lanes)){for(let t of e.cells)t.destroy();e.cells.length=0,e.cellCtrls.length=0}this.element.remove()}createLane(e){let t=document.createElement(`div`);return t.className=`mg-row__lane mg-row__lane--${e}`,{element:t,cells:[],cellCtrls:[],indices:[],mountedColIds:[],changedSlotIndices:new Set}}applyRowTop(e){if(Ri(this.enableCellSpan)){this.element.style.top=`${e}px`,this.element.style.transform=``;return}this.element.style.top=`0px`,this.element.style.transform=`translateY(${e}px)`}syncTopPositioningClass(){this.element.classList.toggle(Ii,Ri(this.enableCellSpan))}hasVisibleCells(e){return e?e.left.length+e.center.length+e.right.length>0:this.lanes.left.indices.length>0||this.lanes.center.indices.length>0||this.lanes.right.indices.length>0}syncLaneWidths(){this.columnModel&&(this.lanes.left.element.style.width=`${this.columnModel.getLeftFixedWidth()}px`,this.lanes.center.element.style.width=`${this.columnModel.getCenterTotalWidth()}px`,this.lanes.right.element.style.width=`${this.columnModel.getRightFixedWidth()}px`)}syncColumnLayouts(){if(this.columnModel){if(this.element.style.width=`${this.columnModel.getTotalWidth()}px`,this.syncLaneWidths(),this.isFullWidthEmbedActive){this.syncFullWidthEmbedPinnedLanes();return}for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];!r||!i||this.applyCellColumnLayout(i,r)}}}}syncCells(){if(!this.columnModel||!this.rowNode)return;let e=this.rowNode,t=this.columnModel,n=Go({columnModel:t,centerWindow:this.columnWindow,enableCellSpan:this.enableCellSpan,paramsForColumn:t=>Po(e,t)});for(let e of[`left`,`center`,`right`]){let t=this.filterRowSpanIndices(n[e]);this.syncLaneCells(e,t)}}filterRowSpanIndices(e){if(!this.enableCellSpan||!this.rowNode||!this.columnModel)return e;let t=this.rowNode,n=this.columnModel,r=this.cellSpanService,i=e=>{if(r)return r.resolveVerticalSpan(t,e);if(!e.rowSpan||!this.getRowByIndex)return{head:t,rowSpan:1,covered:!1};let n=this.getRowCount?.()??t.rowIndex+1;return qo({enableCellSpan:!0,column:e,rowNode:t,getRowByIndex:this.getRowByIndex,rowCount:n})};return e.filter(e=>{let r=n.getColumn(e);if(!r)return!0;let a=i(r);if(a.covered)return!1;let o=a.rowSpan>1&&a.head.id===t.id;return this.spannedRowOnly?o:!o})}syncLaneCells(e,t){let n=this.lanes[e];for(n.indices=t,n.changedSlotIndices.clear();n.cells.length<t.length;)n.cells.push(new Hp(n.element,{onUnmountRenderer:this.onUnmountRenderer,onUnmountEditor:this.onUnmountEditor})),n.cellCtrls.push(new Lp),n.mountedColIds.push(``);for(;n.cells.length>t.length;){let e=n.cells.pop();e&&(this.cleanupAutoHeightCell(e.getElement()),e.destroy()),n.cellCtrls.pop(),n.mountedColIds.pop()}for(let e=0;e<t.length;e++){let r=t[e],i=r===void 0?void 0:this.columnModel.getColumn(r),a=n.cells[e];if(!i||!a)continue;let o=n.mountedColIds[e],s=i.colId;o!==s&&(n.changedSlotIndices.add(e),o&&n.cellCtrls[e]?.invalidate()),n.mountedColIds[e]=s,this.applyCellColumnLayout(a,i),a.setColId(s),a.getElement().toggleAttribute(`data-auto-height`,i.autoHeight),ci(a.getElement(),i.align,i.valign,`mg-cell`),a.getElement().classList.toggle(`mg-cell--index`,L(i.colId)),a.getElement().classList.toggle(`mg-cell--selection`,R(i.colId)),a.getElement().classList.toggle(`mg-cell--expand`,z(i.colId)||i.rowExpand),a.getElement().classList.toggle(`mg-cell--group`,V(i.colId));let c=this.rowNode!=null&&Zt(this.rowNode)&&(this.isRowDragHandleEnabled?.(i.colId)??!1);L(i.colId)?(a.getElement().classList.toggle(`mg-cell--index-focused`,this.indexFocused),a.setIndexRangeHighlight(this.indexColumnRangeHighlighted),a.setRowResizeHandle(this.indexColumnOptions?.enableRowResizer??!1),a.setRowDragHandle(c)):(a.clearRowResizeHandle(),a.setRowDragHandle(i.rowDrag?c:!1))}}applyCellColumnLayout(e,t){if(!this.columnModel||!this.rowNode)return;let n=e.getElement();if(!this.enableCellSpan||!t.colSpan)e.setColumnLayout(ko(t,this.columnModel)),Lo(n,1);else{let r=Bo(t,this.columnModel,{enableCellSpan:!0,params:Po(this.rowNode,t)});e.setColumnLayout(Io(r,this.columnModel)),Lo(n,r.length)}this.applyCellRowSpanState(n,t)}applyCellRowSpanState(e,t){if(!this.enableCellSpan||!this.rowNode){Yo(e,1,null);return}if(this.cellSpanService){let n=this.cellSpanService.resolveVerticalSpan(this.rowNode,t);if(n.covered||n.rowSpan<=1){Yo(e,1,null);return}let r=this.cellSpanService.getVerticalSpanHeight(this.rowNode,t);Yo(e,n.rowSpan,r),this.applyRowSpanCoverHighlight(e,n.head,n.rowSpan);return}if(!t.rowSpan||!this.getRowByIndex){Yo(e,1,null);return}let n=this.getRowCount?.()??this.rowNode.rowIndex+1,r=qo({enableCellSpan:!0,column:t,rowNode:this.rowNode,getRowByIndex:this.getRowByIndex,rowCount:n});if(r.covered||r.rowSpan<=1){Yo(e,1,null);return}let i=Jo(r.head,r.rowSpan,this.getRowByIndex);Yo(e,r.rowSpan,i),this.applyRowSpanCoverHighlight(e,r.head,r.rowSpan)}syncRowSpanHighlights(){if(!(!this.enableCellSpan||!this.rowNode||!this.getRowByIndex))for(let e of Object.values(this.lanes))for(let t of e.cells){let e=t.getElement();if(!e.classList.contains(`mg-cell--row-span`))continue;let n=Number(e.dataset.rowSpan??1);n<=1||this.applyRowSpanCoverHighlight(e,this.rowNode,n)}}applyRowSpanCoverHighlight(e,t,n){if(!this.getRowByIndex||n<=1){e.classList.remove(`mg-cell--row-span-highlighted`);return}let r=Xo({head:t,rowSpan:n,getRowByIndex:this.getRowByIndex,isRowHighlighted:e=>this.isRowCoverHighlighted?this.isRowCoverHighlighted(e):e===t.id&&(this.selected||this.indexFocused)});e.classList.toggle(`mg-cell--row-span-highlighted`,r)}syncIndexFocusedVisual(){if(this.columnModel)for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];!r||!i||!L(r.colId)||i.getElement().classList.toggle(`mg-cell--index-focused`,this.indexFocused)}}}syncIndexColumnRangeHighlightVisual(){if(this.columnModel)for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];!r||!i||!L(r.colId)||i.setIndexRangeHighlight(this.indexColumnRangeHighlighted)}}}withRendererBatch(e){this.rendererBatchDepth++;try{return e()}finally{this.rendererBatchDepth--,this.flushRowRendererBatch()}}scheduleRendererTask(e){if(this.rendererBatchDepth>0){this.pendingRendererTasks.push(e);return}this.enqueueRendererTask(e)}flushRowRendererBatch(){if(this.rendererBatchDepth>0||this.pendingRendererTasks.length===0)return;let e=this.pendingRendererTasks.splice(0);this.enqueueRendererTask(()=>{for(let t of e)t()})}enqueueRendererTask(e){let t=this.rowNode?.rowIndex??0;if(this.frameService){this.frameService.createTask(e,t,`f1`);return}e()}scheduleInlineEditorTask(e){let t=this.rowNode?.rowIndex??0;if(this.frameService){this.frameService.createTask(e,t,`p2`);return}e()}refreshCellAtLaneIndex(e,t,n,r,i,a){let o=this.lanes[e],s=o.indices[t],c=s===void 0?void 0:this.columnModel.getColumn(s),l=o.cells[t],u=o.cellCtrls[t];return!c||!l||!u||!this.rowNode||n&&!n.has(c.colId)?!1:u.refreshCell(this.rowNode,c,l,this.valueCacheVersion,{force:r,scheduleRenderer:e=>this.scheduleRendererTask(e),scheduleInlineEditor:e=>this.scheduleInlineEditorTask(e),inlineEditor:this.inlineEditor,indexColumnOptions:i??this.indexColumnOptions,selectionColumnOptions:a??this.selectionColumnOptions,selectionChecked:this.selected,selectionDisabled:this.selectionDisabled,selectionIndeterminate:this.selectionIndeterminate,rowExpansionHost:this.rowExpansionHost,rowGroupingHost:this.rowGroupingHost,treeTableHost:this.treeTableHost,resolveBusinessRowId:this.resolveBusinessRowId,getCellDisableContext:this.getCellDisableContext,getCellStyleContext:this.getCellStyleContext,cellRendererDefer:this.cellRendererDefer,cellRendererPresentation:this.cellRendererPresentation,scrollActive:this.isScrollActive?.()??!1})}promoteRendererPlaceholderAtLaneIndex(e,t){let n=this.lanes[e],r=n.indices[t],i=r===void 0?void 0:this.columnModel.getColumn(r),a=n.cells[t],o=n.cellCtrls[t];return!i||!a||!o||!this.rowNode||!o.hasPendingVueRenderer()?!1:o.promoteVueRenderer(this.rowNode,a,{scheduleRenderer:e=>this.scheduleRendererTask(e),cellRendererDefer:this.cellRendererDefer,cellRendererPresentation:this.cellRendererPresentation})}syncGroupRowClasses(){this.rowNode&&(this.element.classList.toggle(St,this.rowNode.rowKind===`groupHeader`),this.element.classList.toggle(Ct,this.rowNode.rowKind===`groupFooter`))}syncStripeClass(){this.rowNode&&this.element.classList.toggle(`mg-row--stripe`,this.stripe&&this.rowNode.rowIndex%2==1)}syncLastRowClass(e){this.element.classList.toggle(`mg-row--last`,e)}syncExpandedMasterClass(){if(!this.rowNode||B(this.rowNode)){this.element.classList.remove(`mg-row--expanded-master`);return}let e=this.rowExpansionHost?.active()===!0&&this.rowExpansionHost.isExpanded(this.rowNode.id);this.element.classList.toggle(`mg-row--expanded-master`,e)}syncSelectionColumnCheckbox(){if(!(!this.columnModel||!this.rowNode||this.isFullWidthEmbedActive))for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];if(!r||!i||!R(r.colId))continue;if(Xt(this.rowNode)){i.clearSelectionCheckbox();continue}let a=this.selectionColumnOptions?jf(this.rowNode.rowIndex,this.selectionColumnOptions.selectionColumn):`选择第 ${this.rowNode.rowIndex+1} 行`;i.setSelectionCheckbox({checked:this.selected,disabled:this.selectionDisabled,indeterminate:this.selectionIndeterminate,ariaLabel:a})}}}syncCellValues(e=`all`){return!this.rowNode||!this.columnModel||!this.hasVisibleCells()?0:this.withRendererBatch(()=>{let t=0;for(let n of[`left`,`center`,`right`]){let r=this.lanes[n];for(let i=0;i<r.indices.length;i++){let a=e===`all`||r.changedSlotIndices.has(i);this.refreshCellAtLaneIndex(n,i,null,a,this.indexColumnOptions,this.selectionColumnOptions)&&t++}}return t})}syncAutoHeightCells(e=null,t=!1){if(!(!this.rowAutoHeightService||!this.rowNode||!this.columnModel))for(let n of[`left`,`center`,`right`]){let r=this.lanes[n];for(let n=0;n<r.indices.length;n++){let i=r.indices[n],a=i===void 0?void 0:this.columnModel.getColumn(i),o=r.cells[n];if(!a||!o)continue;let s=o.getElement(),{colId:c}=a;if(e&&!e.has(c))continue;if(!a.autoHeight){o.getElement().removeAttribute(`data-auto-height`),this.cleanupAutoHeightCell(s);continue}if(this.autoHeightCleanups.has(s)&&!t)continue;t&&this.cleanupAutoHeightCell(s);let l=this.rowNode.id;this.scheduleRendererTask(()=>{if(!this.rowNode||this.rowNode.id!==l)return;let e=this.rowAutoHeightService.setupCellAutoHeight({rowId:l,colId:c,cellEl:s});e&&this.autoHeightCleanups.set(s,e)})}}}cleanupAutoHeightCell(e){let t=this.autoHeightCleanups.get(e);t&&(t(),this.autoHeightCleanups.delete(e))}clearAutoHeightCleanups(){for(let e of this.autoHeightCleanups.values())e();this.autoHeightCleanups.clear()}syncFullWidthEmbedRow(e,t){this.isFullWidthEmbedActive=!0,this.element.classList.add(`mg-row--full-width-embed`,`mg-row--detail`),this.element.dataset.rowKind=`detail`,e.masterRowId&&(this.element.dataset.masterRowId=e.masterRowId),this.syncFullWidthEmbedPinnedLanes(),this.syncLaneCells(`center`,[]),this.fullWidthEmbedContentEl||(this.fullWidthEmbedContentEl=document.createElement(`div`),this.fullWidthEmbedContentEl.className=Qe,this.lanes.center.element.appendChild(this.fullWidthEmbedContentEl)),this.syncFullWidthEmbedContent(),this.syncStripeClass(),this.syncLastRowClass(t)}syncFullWidthEmbedPinnedLanes(){if(!this.columnModel||!this.rowNode)return;let e=Go({columnModel:this.columnModel,centerWindow:this.columnWindow,enableCellSpan:!1,paramsForColumn:e=>Po(this.rowNode,e)});this.syncLaneCells(`left`,this.filterRowSpanIndices(e.left)),this.syncLaneCells(`right`,this.filterRowSpanIndices(e.right)),this.syncFullWidthEmbedSpacerCells()}syncFullWidthEmbedSpacerCells(){for(let e of[`left`,`right`]){let t=this.lanes[e];for(let e of t.cells){let t=e.getElement();t.classList.add(`mg-cell--embed-spacer`),t.setAttribute(`aria-hidden`,`true`),e.clearSelectionCheckbox(),e.clearRowExpandButton(),e.setValue(``)}}}syncFullWidthEmbedContent(){if(!this.rowNode||!this.fullWidthEmbedContentEl)return;let e=zp(this.rowNode,this.getMasterRowById);e&&Bp(this.fullWidthEmbedContentEl,e,this.getDetailCellRenderer?.(),{frameService:this.frameService,onUnmountRenderer:this.onUnmountRenderer,rowIndex:this.rowNode.rowIndex,onAfterRender:()=>{this.detailRowAutoHeightService?.setupContentObserver(this.rowNode.id,this.fullWidthEmbedContentEl)}})}clearFullWidthEmbedState(){this.rowNode&&this.detailRowAutoHeightService?.teardownContentObserver(this.rowNode.id),this.isFullWidthEmbedActive=!1,this.element.classList.remove(`mg-row--full-width-embed`,`mg-row--detail`),delete this.element.dataset.rowKind,delete this.element.dataset.masterRowId,this.fullWidthEmbedContentEl&&=(this.onUnmountRenderer?.(this.fullWidthEmbedContentEl),this.fullWidthEmbedContentEl.replaceChildren(),this.fullWidthEmbedContentEl.remove(),null);for(let e of[`left`,`right`])for(let t of this.lanes[e].cells)t.getElement().classList.remove(`mg-cell--embed-spacer`),t.getElement().removeAttribute(`aria-hidden`)}},Wp=class{container;rowModel;columnModel;stripe;rowPool=new Tf;frameService;onUnmountRenderer;onUnmountEditor;inlineCellEditor;indexColumnOptions;selectionColumnOptions;rowAutoHeightService;isRowDragHandleEnabled;enableCellSpan;cellSpanService;valueCacheVersion=0;selectedRowIds=new Set;indexFocusedRowIds=new Set;focusedCell=null;cellRangeIsSelected=null;cellRangeAnchor=null;columnWindow={firstCol:0,lastCol:-1};activeHeadIds=new Set;compressedScroll=!1;scrollTop=0;constructor(e){this.container=e.container,this.rowModel=e.rowModel,this.columnModel=e.columnModel,this.stripe=e.stripe??!1,this.frameService=e.frameService??null,this.onUnmountRenderer=e.onUnmountRenderer,this.onUnmountEditor=e.onUnmountEditor,this.indexColumnOptions=e.indexColumnOptions,this.selectionColumnOptions=e.selectionColumnOptions,this.rowAutoHeightService=e.rowAutoHeightService??null,this.isRowDragHandleEnabled=e.isRowDragHandleEnabled,this.enableCellSpan=e.enableCellSpan??!1,this.cellSpanService=e.cellSpanService??null}setEnableCellSpan(e){this.enableCellSpan=e,e||this.clear()}setCellSpanService(e){this.cellSpanService=e}setRowAutoHeightService(e){this.rowAutoHeightService=e}setInlineCellEditorContext(e){this.inlineCellEditor=e}setCompressedScroll(e){this.compressedScroll=e}setValueCacheVersion(e){this.valueCacheVersion=e}refreshSelection(e){this.selectedRowIds=new Set(e);for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setSelected?.(e.has(t))}refreshIndexFocus(e){this.indexFocusedRowIds=new Set(e);for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setIndexFocused?.(e.has(t))}setFocusedCell(e){this.focusedCell=e,this.refreshFocus()}refreshFocus(){let e=this.focusedCell;for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setFocusedColId?.(e?.rowId===t?e.colId:null)}setCellRangeVisualState(e,t){this.cellRangeIsSelected=e,this.cellRangeAnchor=t,this.refreshCellRangeSelection()}refreshCellRangeSelection(){let e=this.cellRangeIsSelected,t=this.cellRangeAnchor;for(let n of this.rowPool.getActiveIds()){let r=this.findRowIndexById(n),i=this.rowPool.get(n);!i?.setCellRangeSelection||r<0||i.setCellRangeSelection(e?t=>e(r,t):()=>!1,t?.rowIndex===r?t.colId:null,e??void 0)}}playCellRangeCopyFlash(){let e=this.cellRangeIsSelected;if(e)for(let t of this.rowPool.getActiveIds()){let n=this.findRowIndexById(t),r=this.rowPool.get(t);!r?.flashCellRangeSelection||n<0||r.flashCellRangeSelection(t=>e(n,t),e)}}playCellRangePasteFlash(e){if(e.length===0)return;let t=new Map;for(let n of e){let e=t.get(n.rowIndex);e?e.push(n):t.set(n.rowIndex,[n])}for(let e of this.rowPool.getActiveIds()){let n=this.findRowIndexById(e),r=this.rowPool.get(e),i=t.get(n);!r?.flashCellRangePaste||!i?.length||n<0||r.flashCellRangePaste(i)}}syncColumnLayouts(){for(let e of this.rowPool.getActiveIds())this.rowPool.get(e)?.syncColumnLayouts?.()}refreshVisibleColumnStructure(e){if(!this.enableCellSpan)return;this.columnWindow=e;let t={columnStructureChanged:!0};for(let e of this.activeHeadIds)this.updateHeadRow(e,t)}migrateRowId(e,t){if(e===t)return;this.rowPool.migrateId(e,t);let n=this.rowPool.get(t);n&&(n.getElement().dataset.rowId=t),this.selectedRowIds.has(e)&&(this.selectedRowIds.delete(e),this.selectedRowIds.add(t)),this.indexFocusedRowIds.has(e)&&(this.indexFocusedRowIds.delete(e),this.indexFocusedRowIds.add(t)),this.focusedCell?.rowId===e&&(this.focusedCell={rowId:t,colId:this.focusedCell.colId}),this.activeHeadIds.has(e)&&(this.activeHeadIds.delete(e),this.activeHeadIds.add(t))}refreshRows(e){let t=e.rowIds?new Set(e.rowIds):null,n=0;for(let r of this.rowPool.getActiveIds()){if(t&&!this.includesRefreshTarget(r,t))continue;let i=this.rowPool.get(r);i?.refreshCells&&(n+=i.refreshCells({columnModel:this.columnModel,columnWindow:this.columnWindow,valueCacheVersion:this.valueCacheVersion,colIds:e.colIds,force:e.force,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,inlineEditor:this.inlineCellEditor}))}return n}syncVisibleRowLayouts(e){let t=e?new Set(e):null;for(let e of this.rowPool.getActiveIds()){if(t&&!this.includesRefreshTarget(e,t))continue;let n=this.findRowNodeById(e);if(!n)continue;let r=this.rowPool.get(e);r?.syncRowLayout?.(n),r?.setRowTop(this.compressedScroll?n.rowTop-this.scrollTop:n.rowTop)}}redraw(e,t,n,r=!1){if(!this.enableCellSpan){this.clear();return}this.scrollTop=e,this.columnWindow=n;let i=this.collectHeadRowIds(t.firstRow,t.lastRow),a=[...this.activeHeadIds].filter(e=>!i.has(e)),o=[...i];for(let e of a)this.frameService&&!this.compressedScroll?this.frameService.addDestroyTask(()=>{this.rowPool.release(e)}):this.rowPool.release(e);for(let e of o)(!this.activeHeadIds.has(e)||r)&&this.updateHeadRow(e,r?{columnStructureChanged:!0}:void 0);this.activeHeadIds=i,this.container.style.display=i.size>0?``:`none`}invalidate(){this.frameService&&this.frameService.flushAllFrames(),this.clear()}destroy(){this.clear()}getActiveHeadCount(){return this.rowPool.getActiveCount()}clear(){this.rowPool.clear(),this.activeHeadIds.clear(),this.container.style.display=`none`}collectHeadRowIds(e,t){return this.cellSpanService?this.cellSpanService.collectSpannedHeadRowIds(e,t):Qo({enableCellSpan:this.enableCellSpan,rowModel:this.rowModel,columns:this.columnModel.getColumns(),firstRow:e,lastRow:t})}updateHeadRow(e,t){let n=this.findRowNodeById(e);if(!n)return;let r=this.rowPool.acquire(e,()=>this.createSpannedRowComp()),i=this.rowModel.getRowCount();r.setData(n,this.columnModel,this.columnWindow,this.valueCacheVersion,i>0&&n.rowIndex===i-1,t),r.setRowTop(this.compressedScroll?n.rowTop-this.scrollTop:n.rowTop),r.setSelected?.(this.selectedRowIds.has(e)),r.setIndexFocused?.(this.indexFocusedRowIds.has(e)),r.setFocusedColId?.(this.focusedCell?.rowId===e?this.focusedCell.colId:null),this.applyCellRangeSelectionToHead(e,n.rowIndex)}applyCellRangeSelectionToHead(e,t){let n=this.rowPool.get(e),r=this.cellRangeIsSelected,i=this.cellRangeAnchor;!n?.setCellRangeSelection||t<0||n.setCellRangeSelection(r?e=>r(t,e):()=>!1,i?.rowIndex===t?i.colId:null,r??void 0)}createSpannedRowComp(){return new Up(this.container,{stripe:this.stripe,frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,onUnmountEditor:this.onUnmountEditor,inlineEditor:this.inlineCellEditor,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,rowAutoHeightService:this.rowAutoHeightService,isRowDragHandleEnabled:this.isRowDragHandleEnabled,enableCellSpan:!0,cellSpanService:this.cellSpanService,getRowByIndex:e=>this.rowModel.getRow(e),getRowCount:()=>this.rowModel.getRowCount(),spannedRowOnly:!0,isRowCoverHighlighted:e=>this.selectedRowIds.has(e)||this.indexFocusedRowIds.has(e)})}includesRefreshTarget(e,t){if(t.has(e))return!0;if(!this.cellSpanService)return!1;for(let n of this.columnModel.getColumns().map(e=>e.colId)){let r=this.cellSpanService.getCellSpan(e,n);if(r&&r.rowIds.some(e=>t.has(e)))return!0}return!1}findRowIndexById(e){for(let t=0;t<this.rowModel.getRowCount();t++)if(this.rowModel.getRow(t)?.id===e)return t;return-1}findRowNodeById(e){for(let t=0;t<this.rowModel.getRowCount();t++){let n=this.rowModel.getRow(t);if(n?.id===e)return n}}},Gp=class{element;contentEl;frameService;onUnmountRenderer;detailRowAutoHeightService;detailCellRenderer;rowNode=null;renderParams=null;constructor(e,t={}){this.frameService=t.frameService??null,this.onUnmountRenderer=t.onUnmountRenderer,this.detailRowAutoHeightService=t.detailRowAutoHeightService??null,this.element=document.createElement(`div`),this.element.className=Ze,this.element.dataset.rowKind=`detail`,this.contentEl=document.createElement(`div`),this.contentEl.className=Qe,this.element.appendChild(this.contentEl),e.appendChild(this.element)}getElement(){return this.element}setDetailCellRenderer(e){this.detailCellRenderer=e,this.renderParams&&this.renderContent(this.renderParams)}setData(e,t,n,r=!1){this.rowNode=e,this.renderParams=t,this.detailCellRenderer=n??this.detailCellRenderer,this.element.dataset.rowId=e.id,this.element.dataset.masterRowId=t.masterRowId==null?``:String(t.masterRowId),this.element.style.height=`${e.rowHeight}px`,this.element.classList.toggle($e,r),this.renderContent(t)}syncRowLayout(e){this.rowNode=e,this.element.style.height=`${e.rowHeight}px`}syncBodyWidth(e){this.element.style.width=`${e}px`}setRowTop(e){this.element.style.transform=`translateY(${e}px)`}destroy(){this.rowNode&&this.detailRowAutoHeightService?.teardownContentObserver(this.rowNode.id),this.onUnmountRenderer?.(this.contentEl),this.contentEl.replaceChildren(),this.element.remove(),this.rowNode=null,this.renderParams=null}renderContent(e){let t=this.rowNode?.id;Bp(this.contentEl,e,this.detailCellRenderer,{frameService:this.frameService,onUnmountRenderer:this.onUnmountRenderer,rowIndex:this.rowNode?.rowIndex??0,onAfterRender:()=>{t&&this.detailRowAutoHeightService?.setupContentObserver(t,this.contentEl)}})}},Kp=class{pool=new Map;acquire(e,t){let n=this.pool.get(e);if(n)return n;let r=t();return this.pool.set(e,r),r}get(e){return this.pool.get(e)}release(e){let t=this.pool.get(e);t&&(t.destroy(),this.pool.delete(e))}clear(){for(let e of this.pool.values())e.destroy();this.pool.clear()}getActiveCount(){return this.pool.size}getActiveIds(){return[...this.pool.keys()]}},qp=class{container;rowModel;columnModel;rowPool=new Kp;frameService;onUnmountRenderer;getDetailCellRenderer;getMasterRowById;masterDetail;embedFullWidthRows;detailRowAutoHeightService;pinnedRowIds=new Set;activeDetailIds=new Set;compressedScroll=!1;scrollTop=0;constructor(e){this.container=e.container,this.container.classList.add(Xe),this.rowModel=e.rowModel,this.columnModel=e.columnModel,this.frameService=e.frameService??null,this.onUnmountRenderer=e.onUnmountRenderer,this.getDetailCellRenderer=e.getDetailCellRenderer,this.getMasterRowById=e.getMasterRowById,this.masterDetail=e.masterDetail??!1,this.embedFullWidthRows=e.embedFullWidthRows??!1,this.detailRowAutoHeightService=e.detailRowAutoHeightService??null,this.container.style.display=`none`}setDetailRowAutoHeightService(e){this.detailRowAutoHeightService=e}setEmbedFullWidthRows(e){this.embedFullWidthRows=e,e&&this.clear()}setMasterDetail(e){this.masterDetail=e,e||this.clear()}setCompressedScroll(e){this.compressedScroll=e}setPinnedRowIds(e){this.pinnedRowIds=new Set(e)}redraw(e,t){if(!this.masterDetail||this.embedFullWidthRows){this.clear();return}this.scrollTop=e;let n=this.collectDetailRowIds(t.firstRow,t.lastRow),r=[...this.activeDetailIds].filter(e=>!n.has(e)),i=[...n];for(let e of r)this.frameService&&!this.compressedScroll?this.frameService.addDestroyTask(()=>{this.rowPool.release(e)}):this.rowPool.release(e);for(let e of i)this.activeDetailIds.has(e)?this.syncDetailRowLayout(e):this.updateDetailRow(e);this.activeDetailIds=n,this.container.style.display=n.size>0?``:`none`}syncVisibleRowLayouts(e){let t=e?new Set(e):null;for(let e of this.rowPool.getActiveIds())t&&!t.has(e)||this.syncDetailRowLayout(e)}syncColumnLayouts(){let e=this.columnModel.getTotalWidth();for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.syncBodyWidth(e)}invalidate(){this.frameService&&this.frameService.flushAllFrames(),this.clear()}destroy(){this.clear()}getActiveDetailCount(){return this.rowPool.getActiveCount()}refreshDetailRowContent(e){let t=this.findRowNodeById(e),n=this.rowPool.get(e);if(!t||!n||!B(t))return;let r=this.buildRendererParams(t);r&&(n.syncBodyWidth(this.columnModel.getTotalWidth()),n.setData(t,r,this.getDetailCellRenderer?.(),this.isLastDisplayRow(e)))}clear(){this.rowPool.clear(),this.activeDetailIds.clear(),this.container.style.display=`none`}collectDetailRowIds(e,t){let n=new Set;if(t>=e)for(let r=e;r<=t;r++){let e=this.rowModel.getRow(r);e&&B(e)&&n.add(e.id)}for(let e of this.pinnedRowIds)st(e)&&n.add(e);return n}updateDetailRow(e){let t=this.findRowNodeById(e);if(!t||!B(t)||!t.masterRowId)return;let n=this.buildRendererParams(t);if(!n)return;let r=this.rowPool.acquire(e,()=>new Gp(this.container,{frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,detailRowAutoHeightService:this.detailRowAutoHeightService}));r.syncBodyWidth(this.columnModel.getTotalWidth()),r.setData(t,n,this.getDetailCellRenderer?.(),this.isLastDisplayRow(e)),r.setRowTop(this.compressedScroll?t.rowTop-this.scrollTop:t.rowTop)}syncDetailRowLayout(e){let t=this.findRowNodeById(e),n=this.rowPool.get(e);!t||!n||(n.syncRowLayout(t),n.syncBodyWidth(this.columnModel.getTotalWidth()),n.setRowTop(this.compressedScroll?t.rowTop-this.scrollTop:t.rowTop))}buildRendererParams(e){return zp(e,e=>this.getMasterRowById?.(e)??this.findRowNodeById(e))}findRowNodeById(e){for(let t=0;t<this.rowModel.getRowCount();t++){let n=this.rowModel.getRow(t);if(n?.id===e)return n}}isLastDisplayRow(e){let t=this.rowModel.getRowCount();return t!==0&&this.rowModel.getRow(t-1)?.id===e}},Jp=class{rowModel;columnModel;rowHeight;rowBuffer;stripe;rowPool=new Tf;rowCompFactory;rowsContainer;frameService;onUnmountRenderer;onUnmountEditor;inlineCellEditor;indexColumnOptions;selectionColumnOptions;rowAutoHeightService;isRowDragHandleEnabled;rowDragCommittingRowIds=null;enableCellSpan;cellSpanService;spannedRowRenderer;fullWidthRowRenderer;embedFullWidthRows;rowExpansionHost;rowGroupingHost;treeTableHost;cellCommentHost;getCellDisableContext=()=>({});getCellStyleContext=()=>({});detailRowAutoHeightService=null;resolveBusinessRowId;valueCacheVersion=0;pinnedRowIds=new Set;selectedRowIds=new Set;indeterminateRowIds=new Set;indexFocusedRowIds=new Set;isRowNodeSelectable=()=>!0;focusedCell=null;cellRangeIsSelected=null;cellRangeAnchor=null;indexColumnHighlightChecker=null;activeIndices=new Set;columnWindow={firstCol:0,lastCol:-1};currentWindow={firstRow:0,lastRow:-1,firstCol:0,lastCol:-1};compressedScroll=!1;scrollTop=0;cellRendererDefer=`always`;deferRowDestroyOnScroll=!1;cellRendererPresentation=`deferred`;scrollActive=!1;pendingDestroyTasks=[];constructor(e,t){this.rowsContainer=e,this.rowModel=t.rowModel,this.columnModel=t.columnModel,this.rowHeight=t.rowHeight??m,this.rowBuffer=t.rowBuffer??10,this.stripe=t.stripe??!1,this.frameService=t.frameService??null,this.onUnmountRenderer=t.onUnmountRenderer,this.onUnmountEditor=t.onUnmountEditor,this.indexColumnOptions=t.indexColumnOptions,this.selectionColumnOptions=t.selectionColumnOptions,this.rowAutoHeightService=t.rowAutoHeightService??null,this.isRowDragHandleEnabled=t.isRowDragHandleEnabled,this.enableCellSpan=t.enableCellSpan??!1,this.cellSpanService=t.cellSpanService??null,this.embedFullWidthRows=t.embedFullWidthRows??!1,this.rowExpansionHost=t.rowExpansionHost,this.rowGroupingHost=t.rowGroupingHost,this.treeTableHost=t.treeTableHost,this.cellCommentHost=t.cellCommentHost,this.resolveBusinessRowId=t.resolveBusinessRowId,this.getCellDisableContext=t.getCellDisableContext??this.getCellDisableContext,this.getCellStyleContext=t.getCellStyleContext??this.getCellStyleContext,this.cellRendererDefer=t.cellRendererDefer??`always`,this.deferRowDestroyOnScroll=t.deferRowDestroyOnScroll??!1,this.cellRendererPresentation=t.cellRendererPresentation??`deferred`,this.rowCompFactory=t.rowCompFactory??{create:()=>new Up(this.rowsContainer,{stripe:this.stripe,frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,onUnmountEditor:this.onUnmountEditor,inlineEditor:this.inlineCellEditor,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,rowAutoHeightService:this.rowAutoHeightService,isRowDragHandleEnabled:this.isRowDragHandleEnabled,isRowDragCommittingRow:e=>this.isRowDragCommittingRowAt(e),enableCellSpan:this.enableCellSpan,cellSpanService:this.cellSpanService,getRowByIndex:e=>this.rowModel.getRow(e),getRowCount:()=>this.rowModel.getRowCount(),embedFullWidthRows:this.embedFullWidthRows,getDetailCellRenderer:t.getDetailCellRenderer,getMasterRowById:t.getMasterRowById,rowExpansionHost:this.rowExpansionHost,rowGroupingHost:this.rowGroupingHost,treeTableHost:this.treeTableHost,getCellCommentHost:()=>this.cellCommentHost,detailRowAutoHeightService:this.detailRowAutoHeightService,resolveBusinessRowId:this.resolveBusinessRowId,getCellDisableContext:()=>this.getCellDisableContext(),getCellStyleContext:()=>this.getCellStyleContext(),cellRendererDefer:this.cellRendererDefer,isScrollActive:()=>this.scrollActive,cellRendererPresentation:this.cellRendererPresentation})},this.spannedRowRenderer=t.spannedRowsContainerEl?new Wp({container:t.spannedRowsContainerEl,rowModel:this.rowModel,columnModel:this.columnModel,stripe:this.stripe,frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,onUnmountEditor:this.onUnmountEditor,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,rowAutoHeightService:this.rowAutoHeightService,isRowDragHandleEnabled:this.isRowDragHandleEnabled,enableCellSpan:this.enableCellSpan,cellSpanService:this.cellSpanService}):null,this.fullWidthRowRenderer=t.fullWidthRowsContainerEl?new qp({container:t.fullWidthRowsContainerEl,rowModel:this.rowModel,columnModel:this.columnModel,frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,masterDetail:t.masterDetail??!1,embedFullWidthRows:t.embedFullWidthRows??!1,getDetailCellRenderer:t.getDetailCellRenderer,getMasterRowById:t.getMasterRowById}):null}setEmbedFullWidthRows(e){this.embedFullWidthRows!==e&&(this.embedFullWidthRows=e,this.fullWidthRowRenderer?.setEmbedFullWidthRows(e),this.invalidate())}setMasterDetail(e){this.fullWidthRowRenderer?.setMasterDetail(e)}setRowDragHandleEnabled(e){this.isRowDragHandleEnabled=e}setRowDragCommittingRows(e){let t=this.rowDragCommittingRowIds,n=e&&e.length>0?new Set(e):null;if(!(t===n||t&&n&&t.size===n.size&&[...t].every(e=>n.has(e)))){if(t)for(let e of t)n?.has(e)||this.applyRowCommittingVisual(e,!1);if(this.rowDragCommittingRowIds=n,n)for(let e of n)this.applyRowCommittingVisual(e,!0)}}setEnableCellSpan(e){this.enableCellSpan=e;for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setEnableCellSpan?.(e);this.spannedRowRenderer?.setEnableCellSpan(e)}setCellSpanService(e){this.cellSpanService=e,this.spannedRowRenderer?.setCellSpanService(e)}setRowAutoHeightService(e){this.rowAutoHeightService=e,this.spannedRowRenderer?.setRowAutoHeightService(e)}setDetailRowAutoHeightService(e){this.detailRowAutoHeightService=e,this.fullWidthRowRenderer?.setDetailRowAutoHeightService(e)}setInlineCellEditorContext(e){this.inlineCellEditor=e,this.spannedRowRenderer?.setInlineCellEditorContext(e)}setCellCommentHost(e){this.cellCommentHost=e}setGetCellDisableContext(e){this.getCellDisableContext=e}setGetCellStyleContext(e){this.getCellStyleContext=e}setDefaultRowHeight(e){this.rowHeight=Math.max(1,e)}setCompressedScroll(e){this.compressedScroll=e,this.spannedRowRenderer?.setCompressedScroll(e),this.fullWidthRowRenderer?.setCompressedScroll(e)}getScrollTop(){return this.scrollTop}isCompressedScroll(){return this.compressedScroll}setScrollActive(e){this.scrollActive=e}setScrollRenderBehavior(e){e.cellRendererDefer!==void 0&&(this.cellRendererDefer=e.cellRendererDefer),e.deferRowDestroyOnScroll!==void 0&&(this.deferRowDestroyOnScroll=e.deferRowDestroyOnScroll),e.cellRendererPresentation!==void 0&&(this.cellRendererPresentation=e.cellRendererPresentation)}promoteRendererPlaceholders(){let e=0;for(let t of this.rowPool.getActiveIds()){let n=this.rowPool.get(t);e+=n?.promoteRendererPlaceholders()??0}return e}flushDeferredDestroys(){if(this.pendingDestroyTasks.length===0)return;let e=this.pendingDestroyTasks.splice(0);if(this.frameService&&!this.compressedScroll){for(let t of e)this.frameService.addDestroyTask(t);return}for(let t of e)t()}redraw(e,t,n,r=!1){this.scrollTop=e,this.columnWindow=n;let i={...wf({scrollTop:e,viewportHeight:t,rowBuffer:this.rowBuffer,rowHeight:this.rowHeight,rowModel:this.rowModel}),firstCol:n.firstCol,lastCol:n.lastCol};return this.recycleRows(i,r),this.syncVisibleCellCommentIndicators(),this.refreshIndexColumnHighlight(),this.spannedRowRenderer?.redraw(e,i,n,r),this.fullWidthRowRenderer?.redraw(e,i),this.refreshCellRangeSelection(),this.currentWindow=i,i}getActiveRowCount(){return this.rowPool.getActiveCount()}getCurrentWindow(){return this.currentWindow}destroy(){this.rowPool.clear(),this.spannedRowRenderer?.destroy(),this.fullWidthRowRenderer?.destroy(),this.activeIndices.clear()}invalidate(){this.frameService&&this.frameService.flushAllFrames(),this.rowPool.clear(),this.spannedRowRenderer?.invalidate(),this.fullWidthRowRenderer?.invalidate(),this.activeIndices.clear(),this.currentWindow={firstRow:0,lastRow:-1,firstCol:0,lastCol:-1}}setValueCacheVersion(e){this.valueCacheVersion=e,this.spannedRowRenderer?.setValueCacheVersion(e)}setPinnedRowIds(e){this.pinnedRowIds=new Set(e),this.fullWidthRowRenderer?.setPinnedRowIds(e)}setIsRowNodeSelectable(e){this.isRowNodeSelectable=e}refreshSelection(e,t=new Set){this.selectedRowIds=new Set(e),this.indeterminateRowIds=new Set(t);for(let n of this.rowPool.getActiveIds()){let r=this.rowPool.get(n);r?.setSelected?.(e.has(n),t.has(n)),this.syncRowSelectionDisabled(n,r)}this.spannedRowRenderer?.refreshSelection(e)}refreshDetailRows(e){for(let t of e){let e=ot(t);this.fullWidthRowRenderer?.refreshDetailRowContent(e);let n=this.rowPool.get(e);n?.refreshCells&&n.refreshCells({columnModel:this.columnModel,columnWindow:this.columnWindow,valueCacheVersion:this.valueCacheVersion,force:!0})}}syncRowSelectionDisabled(e,t=this.rowPool.get(e)){let n=this.findRowIndexById(e),r=n>=0?this.rowModel.getRow(n):null,i=r?!this.isRowNodeSelectable(r):!1;t?.setSelectionDisabled?.(i)}refreshIndexFocus(e){this.indexFocusedRowIds=new Set(e);for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setIndexFocused?.(e.has(t));this.spannedRowRenderer?.refreshIndexFocus(e)}setFocusedCell(e){this.focusedCell=e,this.refreshFocus()}refreshFocus(){let e=this.focusedCell;for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setFocusedColId?.(e?.rowId===t?e.colId:null);this.spannedRowRenderer?.setFocusedCell(e)}setCellRangeVisualState(e,t){this.cellRangeIsSelected=e,this.cellRangeAnchor=t,this.refreshCellRangeSelection()}setIndexColumnHighlight(e){this.indexColumnHighlightChecker=e,this.refreshIndexColumnHighlight()}refreshCellRangeSelection(){let e=this.cellRangeIsSelected,t=this.cellRangeAnchor;for(let n of this.rowPool.getActiveIds()){let r=this.findRowIndexById(n),i=this.rowPool.get(n);!i?.setCellRangeSelection||r<0||i.setCellRangeSelection(e?t=>e(r,t):()=>!1,t?.rowIndex===r?t.colId:null,e??void 0)}this.spannedRowRenderer?.setCellRangeVisualState(e,t)}refreshIndexColumnHighlight(){let e=this.indexColumnHighlightChecker;for(let t of this.rowPool.getActiveIds()){let n=this.findRowIndexById(t),r=this.rowPool.get(t);!r?.setIndexColumnRangeHighlight||n<0||r.setIndexColumnRangeHighlight(e?e(n):!1)}}playCellRangeCopyFlash(){let e=this.cellRangeIsSelected;if(e){for(let t of this.rowPool.getActiveIds()){let n=this.findRowIndexById(t),r=this.rowPool.get(t);!r?.flashCellRangeSelection||n<0||r.flashCellRangeSelection(t=>e(n,t),e)}this.spannedRowRenderer?.playCellRangeCopyFlash()}}playCellRangePasteFlash(e){if(e.length===0)return;let t=new Map;for(let n of e){let e=t.get(n.rowIndex);e?e.push(n):t.set(n.rowIndex,[n])}for(let e of this.rowPool.getActiveIds()){let n=this.findRowIndexById(e),r=this.rowPool.get(e),i=t.get(n);!r?.flashCellRangePaste||!i?.length||n<0||r.flashCellRangePaste(i)}this.spannedRowRenderer?.playCellRangePasteFlash(e)}syncColumnLayouts(){for(let e of this.rowPool.getActiveIds())this.rowPool.get(e)?.syncColumnLayouts?.();this.spannedRowRenderer?.syncColumnLayouts(),this.fullWidthRowRenderer?.syncColumnLayouts()}refreshVisibleColumnStructure(e){this.columnWindow=e;let t={columnStructureChanged:!0};for(let e of this.activeIndices)this.updateRowAtIndex(e,t);for(let e of this.pinnedRowIds){let n=this.findRowIndexById(e);n>=0&&!this.activeIndices.has(n)&&this.updateRowAtIndex(n,t)}this.spannedRowRenderer?.refreshVisibleColumnStructure(e),this.refreshCellRangeSelection(),this.syncVisibleCellCommentIndicators(),this.refreshIndexColumnHighlight()}migrateRowId(e,t){if(e===t)return;this.rowPool.migrateId(e,t);let n=this.rowPool.get(t);n&&(n.getElement().dataset.rowId=t),this.selectedRowIds.has(e)&&(this.selectedRowIds.delete(e),this.selectedRowIds.add(t)),this.indexFocusedRowIds.has(e)&&(this.indexFocusedRowIds.delete(e),this.indexFocusedRowIds.add(t)),this.focusedCell?.rowId===e&&(this.focusedCell={rowId:t,colId:this.focusedCell.colId}),this.pinnedRowIds.has(e)&&(this.pinnedRowIds.delete(e),this.pinnedRowIds.add(t)),this.spannedRowRenderer?.migrateRowId(e,t)}refreshRows(e){let t=e.rowIds?new Set(e.rowIds):null,{firstRow:n,lastRow:r}=this.currentWindow;if(r<n)return 0;let i=0;for(let a=n;a<=r;a++){let n=this.rowModel.getRow(a);if(!n||t&&!t.has(n.id))continue;let r=this.rowPool.get(n.id);r?.refreshCells&&(i+=r.refreshCells({columnModel:this.columnModel,columnWindow:this.columnWindow,valueCacheVersion:this.valueCacheVersion,colIds:e.colIds,force:e.force,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,inlineEditor:this.inlineCellEditor}))}return i+=this.spannedRowRenderer?.refreshRows(e)??0,this.syncVisibleCellCommentIndicators({rowIds:e.rowIds,colIds:e.colIds}),i}syncVisibleCellCommentIndicators(e){if(!this.cellCommentHost?.active())return;let t=e?.rowIds?new Set(e.rowIds):null,n=e?.colIds?new Set(e.colIds):null,{firstRow:r,lastRow:i}=this.currentWindow;if(!(i<r)){for(let e=r;e<=i;e++){let r=this.rowModel.getRow(e);r&&(t&&!t.has(r.id)||this.rowPool.get(r.id)?.syncCellCommentIndicators?.(n))}for(let e of this.pinnedRowIds)t&&!t.has(e)||this.rowPool.get(e)?.syncCellCommentIndicators?.(n)}}syncVisibleRowLayouts(e){let t=e?new Set(e):null,n=e=>{let n=this.rowModel.getRow(e);if(!n||t&&!t.has(n.id))return;let r=this.rowPool.get(n.id);if(!r){this.updateRowAtIndex(e);return}r.syncRowLayout?.(n),r.setRowTop(this.compressedScroll?n.rowTop-this.scrollTop:n.rowTop)};for(let e of this.activeIndices)n(e);for(let e of this.pinnedRowIds){if(t&&!t.has(e))continue;let r=this.findRowIndexById(e);r>=0&&n(r)}this.spannedRowRenderer?.syncVisibleRowLayouts(e),this.fullWidthRowRenderer?.syncVisibleRowLayouts(e)}recycleRows(e,t){let n=vf(this.activeIndices,e);if(t)for(let e of this.activeIndices)n.toUpdate.includes(e)||n.toUpdate.push(e);for(let e of n.toDestroy){let t=this.rowModel.getRow(e);if(!t||!this.rowPool.get(t.id)||this.pinnedRowIds.has(t.id))continue;let n=t.id,r=()=>{this.rowPool.release(n)};this.frameService&&!this.compressedScroll?this.deferRowDestroyOnScroll&&this.scrollActive?this.pendingDestroyTasks.push(r):this.frameService.addDestroyTask(r):r()}for(let e of n.toUpdate)this.updateRowAtIndex(e,t?{columnStructureChanged:!0}:void 0);for(let e of n.toCreate){let n=t?{columnStructureChanged:!0}:void 0;this.frameService&&!this.compressedScroll?this.frameService.createTask(()=>{this.updateRowAtIndex(e,n)},e,`p1`):this.updateRowAtIndex(e,n)}this.activeIndices=Yp(e);for(let e of this.pinnedRowIds){let r=this.findRowIndexById(e);r>=0&&(this.activeIndices.add(r),!n.toUpdate.includes(r)&&!n.toCreate.includes(r)&&this.updateRowAtIndex(r,t?{columnStructureChanged:!0}:void 0))}}updateRowAtIndex(e,t){let n=this.rowModel.getRow(e);if(!n||B(n)&&!this.embedFullWidthRows)return;let r=this.rowPool.acquire(n.id,()=>this.rowCompFactory.create()),i=this.rowModel.getRowCount();r.setData(n,this.columnModel,this.columnWindow,this.valueCacheVersion,i>0&&e===i-1,t),r.setRowTop(this.compressedScroll?n.rowTop-this.scrollTop:n.rowTop),r.setSelected?.(this.selectedRowIds.has(n.id)),r.setSelectionDisabled?.(!this.isRowNodeSelectable(n)),r.setIndexFocused?.(this.indexFocusedRowIds.has(n.id)),r.setIndexColumnRangeHighlight?.(this.indexColumnHighlightChecker?.(e)??!1),r.setFocusedColId?.(this.focusedCell?.rowId===n.id?this.focusedCell.colId:null)}findRowIndexById(e){let{firstRow:t,lastRow:n}=this.currentWindow;if(n<t)return-1;for(let r=t;r<=n;r++)if(this.rowModel.getRow(r)?.id===e)return r;for(let t=0;t<this.rowModel.getRowCount();t++)if(this.rowModel.getRow(t)?.id===e)return t;return-1}isRowDragCommittingRowAt(e){return this.rowDragCommittingRowIds?.has(e)??!1}applyRowCommittingVisual(e,t){this.rowPool.get(e)?.setRowDragCommittingVisual?.(t),this.rowsContainer.querySelector(`.mg-row[data-row-id="${CSS.escape(e)}"]`)?.classList.toggle(sa,t)}};function Yp(e){let t=new Set;if(e.lastRow<e.firstRow)return t;for(let n=e.firstRow;n<=e.lastRow;n++)t.add(n);return t}var Xp=[`left`,`center`,`right`];function Zp(e,t){let n=Xp.filter(t=>e.includes(t)),r=n.indexOf(t);return r<0?{top:!0,right:!0,bottom:!0,left:!0}:{top:!0,bottom:!0,left:r===0,right:r===n.length-1}}function Qp(e){return{top:e.top,height:e.height}}function $p(e){return e.fixed??`center`}function em(e,t,n,r,i=0){let a=t.indexOf(e.leftColId),o=t.indexOf(e.rightColId);if(a<0||o<0)return null;let s=Math.min(a,o),c=Math.max(a,o),l=null,u=null;for(let e=s;e<=c;e++){let i=t[e];if(!i)continue;let a=n.find(e=>e.colId===i);!a||a.hidden||$p(a)===r&&(l||=a,u=a)}return!l||!u?null:{left:l.left-i,width:u.left+u.width-l.left}}function tm(e,t){return e===`right`?t.getLeftFixedWidth()+t.getCenterTotalWidth():0}function nm(e,t){if(t<=0)return null;let n=e.top+e.height,r=Math.max(0,e.top),i=Math.min(t,n)-r;return i<=0?null:{top:r,height:i,lanes:e.lanes}}function rm(e,t,n,r,i,a){let{topRowIndex:o,bottomRowIndex:s}=tc(e,t,a??{rowModel:r,columnModel:n,cellSpanService:null}),c=r.getRow(o),l=r.getRow(s);if(!c||!l)return null;let u=n.getColumns(),d={};for(let r of[`left`,`center`,`right`]){let i=em(e,t,u,r,tm(r,n));i&&(d[r]=i)}if(Object.keys(d).length===0)return null;let f=c.rowTop,p=l.rowTop+l.rowHeight-c.rowTop,m={top:i.compressedScroll?f-i.scrollTop:f,height:p,lanes:d};return!i.compressedScroll||i.viewportHeight==null?m:nm(m,i.viewportHeight)}function im(e,t){let n=new Set;for(let r of e){let e=t.indexOf(r.leftColId),i=t.indexOf(r.rightColId);if(e<0||i<0)continue;let a=Math.min(e,i),o=Math.max(e,i);for(let e=a;e<=o;e++){let r=t[e];r&&n.add(r)}}return n}function am(e){let t=new Set;for(let n of e)for(let e=n.top;e<=n.bottom;e+=1)t.add(e);return t}function om(e,t){if(t<=0)return{rect:{...e,left:0,width:0},clippedLeft:!0,clippedRight:!0};let n=e.left,r=e.width,i=!1,a=!1;n<0&&(r+=n,n=0,i=!0);let o=n+r-t;return o>0&&(r-=o,a=!0),r<=0?{rect:{...e,left:n,width:0},clippedLeft:i,clippedRight:a}:{rect:{...e,left:n,width:r},clippedLeft:i,clippedRight:a}}function sm(e,t,n){if(n<=0)return{rect:{...e,left:0,width:0},clippedLeft:!0,clippedRight:!0};let r=t,i=t+n;e.left+e.width;let a=e.left,o=e.width,s=!1,c=!1;return a<r&&(o-=r-a,a=r,s=!0),a+o>i&&(o-=a+o-i,c=!0),o<=0?{rect:{...e,left:a,width:0},clippedLeft:s,clippedRight:c}:{rect:{...e,left:a,width:o},clippedLeft:s,clippedRight:c}}function cm(e,t){return{top:e.top,bottom:e.bottom,left:e.left&&!t.clippedLeft,right:e.right&&!t.clippedRight}}function lm(e,t,n){return uo(e,t,n)}function um(e){return e===`right`}function dm(e,t,n,r,i,a){let o=a??rm(e,t,n,r,i);if(!o)return null;let s=e.rightColId,c=n.getColumnById(s);if(!c||c.hidden)return null;let l=$p(c),u=o.lanes[l];if(!u)return null;let d=u.left+u.width-6/2,{top:f,height:p}=Qp(o);return{lane:l,left:d,top:f+p-6/2}}var fm=class{deps;overlayEl=null;overlayLanes=null;pasteFlashOverlayEl=null;pasteFlashLanes=null;pasteFlashCleanupTimer=null;fillHandleEl=null;rangeHandleEl=null;normalizedRanges=[];anchor=null;displayedColIds=[];constructor(e){this.deps=e}refresh(e){this.displayedColIds=e.displayedColIds,this.anchor=e.anchor,this.normalizedRanges=e.ranges.map(t=>Y(t,e.displayedColIds)).filter(e=>e!=null),this.syncRangeSelectionVisuals(),this.syncHeaderHighlight(),this.syncIndexColumnHighlight()}clear(){this.normalizedRanges=[],this.anchor=null,this.displayedColIds=[],this.syncRangeSelectionVisuals(),this.syncHeaderHighlight(),this.syncIndexColumnHighlight()}syncRangeSelectionVisuals(){if(!this.deps.isCellSelectionVisualEnabled?.()){this.deps.rowRenderer.setCellRangeVisualState(null,null),this.clearBorderOverlays(),this.clearSelectionHandles();return}this.syncCellClasses(),this.syncBorderOverlays(),this.syncSelectionHandle()}syncCellClasses(){let e=this.displayedColIds,t=this.normalizedRanges,n=this.anchor;if(t.length===0){this.deps.rowRenderer.setCellRangeVisualState(null,null);return}this.deps.rowRenderer.setCellRangeVisualState((n,r)=>t.some(t=>Vs(n,r,t,e)),n)}ensureOverlay(){if(this.overlayEl&&this.overlayLanes)return this.overlayLanes;this.deps.mountEl.querySelectorAll(`.${ps}`).forEach(e=>{e.remove()});let e=document.createElement(`div`);e.className=ps;let t=t=>{let n=document.createElement(`div`);return n.className=`mg-cell-range-overlay__lane mg-cell-range-overlay__lane--${t}`,e.appendChild(n),n},n={left:t(`left`),center:t(`center`),right:t(`right`)};return this.deps.rowsLayerEl.appendChild(e),this.overlayEl=e,this.overlayLanes=n,n}resolveBandOptions(){let e=this.deps.isCompressedScroll();return{scrollTop:this.deps.getScrollTop(),scrollLeft:this.deps.getScrollLeft(),compressedScroll:e,viewportHeight:e?this.deps.getViewportHeight():void 0}}findCellElement(e,t){let n=this.deps.rowModel.getRow(e);if(!n)return null;let r=pm(n.id),i=pm(t),a=this.deps.mountEl.querySelector(`.mg-row[data-row-id="${r}"] .mg-cell[data-col-id="${i}"]`);return a instanceof HTMLElement?a:null}syncOverlayLaneLayoutFor(e,t){let{leftFixedWidth:n,centerTotalWidth:r,rightFixedWidth:i}=t;e.left.style.width=`${n}px`,e.center.style.width=`${r}px`,e.right.style.width=`${i}px`,e.center.style.position=`relative`,e.center.style.left=``,e.center.style.transform=``}resolveOverlayLaneLayoutParams(){return{leftFixedWidth:this.deps.columnModel.getLeftFixedWidth(),centerTotalWidth:this.deps.columnModel.getCenterTotalWidth(),rightFixedWidth:this.deps.columnModel.getRightFixedWidth()}}syncOverlayRootWidth(e){let t=this.deps.columnModel.getTotalWidth();e.style.left=`0`,e.style.right=`auto`,e.style.width=`${t}px`,e.style.minWidth=`${t}px`}syncOverlayLaneLayout(e){let t=this.overlayLanes;t&&(this.overlayEl&&this.syncOverlayRootWidth(this.overlayEl),this.syncOverlayLaneLayoutFor(t,e))}findRowLaneElement(e,t){let n=this.deps.rowModel.getRow(e);if(!n)return null;let r=this.deps.mountEl.querySelector(`.mg-row[data-row-id="${pm(n.id)}"]`);if(!(r instanceof HTMLElement))return null;let i=r.querySelector(`.mg-row__lane--${t}`);return i instanceof HTMLElement?i:null}resolveLaneContentRectForRange(e,t){return em(e,this.displayedColIds,this.deps.columnModel.getColumns(),t,tm(t,this.deps.columnModel))}resolveRangeBand(e,t){let n={rowModel:this.deps.rowModel,columnModel:this.deps.columnModel,cellSpanService:this.deps.getCellSpanService?.()??null};return{band:rm(e,this.displayedColIds,this.deps.columnModel,this.deps.rowModel,t,n),domMeasuredLanes:new Set}}syncBorderOverlays(){if(this.normalizedRanges.length===0){this.clearBorderOverlays();return}let e=this.ensureOverlay(),t=this.resolveBandOptions(),{scrollLeft:n}=t,r=this.deps.columnModel.getLeftFixedWidth(),i=this.deps.columnModel.getCenterTotalWidth(),a=this.deps.columnModel.getRightFixedWidth(),o=this.deps.getViewportWidth(),s=lm(o,r,a),c=o>0&&s>0&&s<i;e.left.replaceChildren(),e.center.replaceChildren(),e.right.replaceChildren(),this.syncOverlayLaneLayout({leftFixedWidth:r,centerTotalWidth:i,rightFixedWidth:a}),e.center.offsetWidth,e.right.offsetWidth;for(let r of this.normalizedRanges){let{band:o}=this.resolveRangeBand(r,t);if(!o)continue;let l=[`left`,`center`,`right`].filter(e=>this.resolveLaneContentRectForRange(r,e)!=null);for(let t of l){let u=this.resolveLaneContentRectForRange(r,t),d=u,f;if(f=t===`center`&&c?sm(u,lo(n,i,s),s):t===`center`||t===`right`?om(d,t===`center`?i:a):{rect:d,clippedLeft:!1,clippedRight:!1},f.rect.width<=0)continue;let p=cm(Zp(l,t),f);t===`center`&&!l.includes(`left`)&&f.clippedLeft&&(p={...p,left:!1});let{top:m,height:h}=Qp(o);if(t===`center`){this.appendSegmentedBorder(e[t],p,m,h,f.rect.left,f.rect.width);continue}um(t)?this.appendSegmentedBorder(e[t],p,m,h,f.rect.left,f.rect.width):this.appendEnvelopeBorder(e[t],p,m,h,f.rect.left,f.rect.width)}}this.ensureOverlayOnTop()}ensureOverlayOnTop(){this.overlayEl?.parentElement===this.deps.rowsLayerEl&&this.deps.rowsLayerEl.appendChild(this.overlayEl)}appendEnvelopeBorder(e,t,n,r,i,a){let o=document.createElement(`div`);o.className=os,t.top&&o.classList.add(ss),t.right&&o.classList.add(cs),t.bottom&&o.classList.add(ls),t.left&&o.classList.add(us),o.style.top=`${n}px`,o.style.height=`${r}px`,o.style.left=`${i}px`,o.style.width=`${a}px`,e.appendChild(o)}appendSegmentedBorder(e,t,n,r,i,a){let o=(t,n)=>{let r=document.createElement(`div`);r.className=`${os} ${t}`;for(let[e,t]of Object.entries(n))r.style.setProperty(e,t);e.appendChild(r)};t.top&&o(ds,{top:`${n}px`,left:`${i}px`,width:`${a}px`,height:`2px`}),t.bottom&&o(ds,{top:`${n+r-2}px`,left:`${i}px`,width:`${a}px`,height:`2px`}),t.left&&o(fs,{top:`${n}px`,left:`${i}px`,width:`2px`,height:`${r}px`}),t.right&&o(fs,{top:`${n}px`,left:`${i+a-2}px`,width:`2px`,height:`${r}px`})}playCopyFlash(){if(this.normalizedRanges.length===0)return;this.deps.rowRenderer.playCellRangeCopyFlash(),this.ensureOverlay();let e=this.overlayEl;if(!e)return;e.classList.remove(hs),e.offsetWidth,e.classList.add(hs);let t=()=>{e.classList.remove(hs),e.removeEventListener(`animationend`,t)};e.addEventListener(`animationend`,t)}playPasteFlash(e){e.length!==0&&(this.deps.rowRenderer.playCellRangePasteFlash(e),this.playPasteTargetOverlayFlash(e))}measurePasteTargetCellOverlayRect(e,t,n){let r=this.findCellElement(e,t);if(!r)return null;let i=this.deps.columnModel.getColumnById(t);if(!i)return null;let a=i.fixed??`center`,o=n[a],s=r.getBoundingClientRect(),c=o.getBoundingClientRect(),l=s.top-c.top,u=s.left-c.left,d=s.width,f=s.height;return d<=0||f<=0?null:{lane:a,top:l,left:u,width:d,height:f}}playPasteTargetOverlayFlash(e){this.clearPasteFlashOverlay();let t=this.ensurePasteFlashOverlay();this.syncPasteFlashOverlayLayout();let n=[];for(let r of e){let e=this.measurePasteTargetCellOverlayRect(r.rowIndex,r.colId,t);if(!e)continue;let i=document.createElement(`div`);i.className=`${vs} ${r.applied?ys:bs}`,i.style.top=`${e.top}px`,i.style.left=`${e.left}px`,i.style.width=`${e.width}px`,i.style.height=`${e.height}px`,t[e.lane].appendChild(i),n.push(i)}n.length!==0&&(this.pasteFlashCleanupTimer=window.setTimeout(()=>{this.pasteFlashCleanupTimer=null;for(let e of n)e.remove()},520))}syncOverlayPosition(){if(this.normalizedRanges.length===0){this.syncPasteFlashOverlayLayout();return}this.syncBorderOverlays(),this.syncSelectionHandle(),this.syncPasteFlashOverlayLayout()}clearPasteFlashOverlay(){this.pasteFlashCleanupTimer!=null&&(window.clearTimeout(this.pasteFlashCleanupTimer),this.pasteFlashCleanupTimer=null),this.pasteFlashLanes?.left.replaceChildren(),this.pasteFlashLanes?.center.replaceChildren(),this.pasteFlashLanes?.right.replaceChildren()}ensurePasteFlashOverlay(){if(this.pasteFlashOverlayEl&&this.pasteFlashLanes)return this.pasteFlashLanes;let e=document.createElement(`div`);e.className=xs;let t=t=>{let n=document.createElement(`div`);return n.className=`mg-cell-range-overlay__lane mg-cell-range-overlay__lane--${t}`,e.appendChild(n),n},n={left:t(`left`),center:t(`center`),right:t(`right`)};return this.deps.rowsLayerEl.appendChild(e),this.pasteFlashOverlayEl=e,this.pasteFlashLanes=n,n}syncPasteFlashOverlayLayout(){let e=this.pasteFlashLanes;e&&(e.left.childElementCount>0||e.center.childElementCount>0||e.right.childElementCount>0)&&(this.syncOverlayLaneLayoutFor(e,this.resolveOverlayLaneLayoutParams()),this.pasteFlashOverlayEl&&this.syncOverlayRootWidth(this.pasteFlashOverlayEl),this.pasteFlashOverlayEl?.parentElement===this.deps.rowsLayerEl&&this.deps.rowsLayerEl.appendChild(this.pasteFlashOverlayEl))}clearBorderOverlays(){this.overlayLanes?.left.replaceChildren(),this.overlayLanes?.center.replaceChildren(),this.overlayLanes?.right.replaceChildren()}ensureFillHandle(){if(this.fillHandleEl)return this.fillHandleEl;let e=document.createElement(`div`);return e.className=Ss,e.style.width=`6px`,e.style.height=`6px`,this.fillHandleEl=e,e}clearSelectionHandles(){this.fillHandleEl?.remove(),this.fillHandleEl=null,this.rangeHandleEl?.remove(),this.rangeHandleEl=null}syncSelectionHandle(){let e=this.deps.getCellSelectionOptions?.();if(!e||this.normalizedRanges.length!==1){this.clearSelectionHandles();return}let t=this.normalizedRanges[0],n=this.resolveBandOptions(),{band:r}=this.resolveRangeBand(t,n),i=dm(t,this.displayedColIds,this.deps.columnModel,this.deps.rowModel,{...n,viewportWidth:this.deps.getViewportWidth()},null);if(!i){this.clearSelectionHandles();return}if(Ps(e)){this.rangeHandleEl?.remove(),this.rangeHandleEl=null,this.mountHandle(this.ensureFillHandle(),i);return}if(Fs(e)){this.fillHandleEl?.remove(),this.fillHandleEl=null,this.mountHandle(this.ensureRangeHandle(),i);return}this.clearSelectionHandles()}mountHandle(e,t){let n=this.ensureOverlay()[t.lane],r=t.lane===`left`?this.deps.columnModel.getLeftFixedWidth():t.lane===`center`?this.deps.columnModel.getCenterTotalWidth():this.deps.columnModel.getRightFixedWidth(),i=Math.max(0,r-6),a=Math.min(Math.max(t.left,0),i);if(r<=0){e.remove();return}e.parentElement!==n&&(e.remove(),n.appendChild(e)),e.style.left=`${a}px`,e.style.top=`${t.top}px`}ensureRangeHandle(){if(this.rangeHandleEl)return this.rangeHandleEl;let e=document.createElement(`div`);return e.className=Cs,e.style.width=`6px`,e.style.height=`6px`,this.rangeHandleEl=e,e}syncHeaderHighlight(){let e=this.deps.isHeaderHighlightEnabled()?im(this.normalizedRanges,this.displayedColIds):new Set;this.deps.mountEl.querySelectorAll(`.mg-header-cell[data-col-id]`).forEach(t=>{if(!(t instanceof HTMLElement))return;let n=t.dataset.colId;t.classList.toggle(ws,n!=null&&e.has(n))})}syncIndexColumnHighlight(){if(!this.deps.isIndexColumnHighlightEnabled()){this.deps.rowRenderer.setIndexColumnHighlight(null);return}let e=Js({rangeRowIndices:am(this.normalizedRanges),indexFocusedRowIds:this.deps.getIndexFocusedRowIds?.()??[],selectedRowIds:this.deps.getSelectedRowIds?.()??[],rowIndexById:e=>this.deps.rowModel.getRowIndexById(e)});this.deps.rowRenderer.setIndexColumnHighlight(t=>e.has(t))}destroy(){this.clear(),this.clearPasteFlashOverlay(),this.overlayEl?.remove(),this.overlayEl=null,this.overlayLanes=null,this.pasteFlashOverlayEl?.remove(),this.pasteFlashOverlayEl=null,this.pasteFlashLanes=null,this.fillHandleEl=null,this.rangeHandleEl=null}};function pm(e){return typeof CSS<`u`&&typeof CSS.escape==`function`?CSS.escape(e):e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}var mm=class{scrollTop=0;nextScrollTop=0;notifyScroll(e){this.nextScrollTop=e}isScrollGoingDown(){return this.nextScrollTop>=this.scrollTop}scrollGridIfNeeded(e){return this.scrollTop!==this.nextScrollTop&&(this.scrollTop=this.nextScrollTop,e(this.scrollTop),!0)}syncScrollTop(e){this.scrollTop=e,this.nextScrollTop=e}getScrollTop(){return this.scrollTop}getNextScrollTop(){return this.nextScrollTop}},hm=class{version=0;getVersion(){return this.version}bump(){this.version++}reset(){this.version=0}};function gm(e={}){return{navigateHeader:e.navigateHeader??!1,navigateFooter:e.navigateFooter??!1}}function _m(e,t,n){if(t.size===0)return e.slice();let r=[];for(let i of e)ct(i)&&(r.push(i),t.has(i.id)&&r.push(n(i)));return r}function vm(e,t,n){if(e.__detailLoading||e.__detailRowData!==void 0)return;e.__detailLoading=!0,delete e.__detailLoadError,n.onLoading();let r=!1,i=e=>{r||(r=!0,e(),n.onSettled())},a={rowId:e.id,data:e.data,successCallback:t=>{i(()=>{e.__detailRowData=t,e.__detailLoading=!1})},failCallback:t=>{i(()=>{e.__detailLoading=!1,e.__detailLoadError=t??!0})}};try{let e=t(a);ym(e)&&e.catch(e=>{a.failCallback?.(e)})}catch(e){a.failCallback?.(e)}}function ym(e){return typeof e==`object`&&!!e&&`then`in e&&typeof e.then==`function`}function bm(e){let t=e.style.height,n=e.style.minHeight,r=e.style.overflow;e.style.height=`auto`,e.style.minHeight=`0`,e.style.overflow=`visible`;let i=e.scrollHeight;return e.style.height=t,e.style.minHeight=n,e.style.overflow=r,Math.ceil(i)}var xm=1,Sm=5,Cm=class{deps;debounceTimer=null;pendingHeights=new Map;contentCleanups=new Map;constructor(e){this.deps=e}setupContentObserver(e,t){if(!this.deps.isEnabled())return;this.teardownContentObserver(e);let n=(r=0)=>{let i=this.deps.getRowById(e);if(!i||!B(i))return;let a=bm(t);if(a<=0&&r<Sm){window.setTimeout(()=>n(r+1),0);return}a>0&&this.queueMeasuredHeight(e,a,i)};n();let r=typeof ResizeObserver<`u`?new ResizeObserver(()=>{n()}):null;r?.observe(t),this.contentCleanups.set(e,()=>{r?.disconnect()})}teardownContentObserver(e){this.contentCleanups.get(e)?.(),this.contentCleanups.delete(e)}destroy(){this.debounceTimer!=null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null);for(let e of this.contentCleanups.values())e();this.contentCleanups.clear(),this.pendingHeights.clear()}queueMeasuredHeight(e,t,n){let r=this.deps.getMinDetailRowHeight(n),i=Math.max(r,t);n.rowHeight===i&&!n.estimated||(this.pendingHeights.set(e,i),this.scheduleApply())}scheduleApply(){this.debounceTimer??=window.setTimeout(()=>{this.debounceTimer=null,this.flushPendingHeights()},xm)}flushPendingHeights(){if(this.pendingHeights.size!==0){for(let[e,t]of this.pendingHeights.entries()){let n=this.deps.getRowById(e);!n||n.rowHeight===t&&!n.estimated||this.deps.rowHeightService.setRowHeight(e,t,!0,`autoHeight`)}this.pendingHeights.clear()}}};function wm(e,t){let n=lt(t.detailRowHeight,{rowId:e.id,data:e.data,masterRowId:e.id});return{id:ot(e.id),data:e.data,rowKind:`detail`,masterRowId:e.id,rowTop:0,rowHeight:n,estimated:t.detailRowAutoHeight,rowIndex:0}}var Tm=class{deps;expandedMasterIds=new Set;constructor(e){this.deps=e}get active(){return this.deps.getOptions().masterDetail}isExpanded(e){return this.expandedMasterIds.has(e)}getExpandedMasterIds(){return this.expandedMasterIds}getPinnedRowIds(){let e=[];for(let t of this.expandedMasterIds)e.push(t,ot(t));return e}isRowMaster(e){return!this.active||B(e)?!1:this.deps.getOptions().isRowMaster({rowId:e.id,data:e.data,rowIndex:e.rowIndex})}expandRow(e,t){if(!this.active||this.expandedMasterIds.has(e))return!1;let n=this.findBaseMasterRow(e);return!n||!this.isRowMaster(n)?!1:(this.expandedMasterIds.add(e),this.ensureDetailRowData(e),this.emit(ut(e,t)),!0)}collapseRow(e,t){return!this.active||!this.expandedMasterIds.has(e)?!1:(this.expandedMasterIds.delete(e),this.clearMasterDetailCache(e),this.emit(dt(e,t)),!0)}toggleRow(e,t){return this.isExpanded(e)?this.collapseRow(e,t):this.expandRow(e,t)}expandAll(e){if(this.active)for(let t of this.deps.getBaseDisplayRows())this.isRowMaster(t)&&this.expandRow(t.id,e)}collapseAll(e){if(this.active)for(let t of[...this.expandedMasterIds])this.collapseRow(t,e)}pruneExpanded(e){for(let t of[...this.expandedMasterIds])e.has(t)||(this.expandedMasterIds.delete(t),this.clearMasterDetailCache(t))}clearExpanded(){this.expandedMasterIds.clear()}applyDefaultExpanded(e){if(this.active&&this.deps.getOptions().masterDefaultExpanded!==0)for(let t of e)this.isRowMaster(t)&&(this.expandedMasterIds.add(t.id),this.ensureDetailRowData(t.id))}injectDetailRows(e){return!this.active||this.expandedMasterIds.size===0?e.slice():_m(e,this.expandedMasterIds,e=>this.createDetailRowNode(e))}createDetailRowNode(e){let t=this.deps.getOptions();return wm(e,{detailRowHeight:t.detailRowHeight,detailRowAutoHeight:t.detailRowAutoHeight})}findBaseMasterRow(e){return this.deps.getBaseDisplayRows().find(t=>t.id===e)}clearMasterDetailCache(e){let t=this.findBaseMasterRow(e);t&&(delete t.__detailRowData,delete t.__detailLoading,delete t.__detailLoadError)}ensureDetailRowData(e){let t=this.deps.getOptions().getDetailRowData;if(!t)return;let n=this.findBaseMasterRow(e);n&&vm(n,t,{onLoading:()=>this.deps.onDetailDataChanged?.(e),onSettled:()=>this.deps.onDetailDataChanged?.(e)})}emit(e){this.deps.onExpansionChanged?.(e)}},Em=class{deps;expandedGroupIds=new Set;rowGroupColumns;constructor(e){this.deps=e,this.rowGroupColumns=[...e.getRowGroupColumnsFromDefs()]}get active(){return zt(this.deps.getOptions().rowGrouping,this.rowGroupColumns)}getExpandedGroupIds(){return this.expandedGroupIds}getRowGroupColumns(){return this.rowGroupColumns}syncRowGroupColumnsFromDefs(){this.rowGroupColumns=[...this.deps.getRowGroupColumnsFromDefs()]}setRowGroupColumns(e,t){this.deps.getOptions().rowGrouping&&(this.rowGroupColumns=[...e],this.clearExpanded(),this.emitGroupChanged($t(this.rowGroupColumns,t)))}isExpanded(e){return this.expandedGroupIds.has(e)}expandGroup(e,t){if(!this.active||this.expandedGroupIds.has(e))return;let n=Ud(this.deps.getGroupedTreeRoots(),e);n?.groupId&&(this.expandedGroupIds.add(e),this.emitGroupOpened(n,!0,t),this.deps.onGroupingStateChanged?.())}collapseGroup(e,t){if(!this.active||!this.expandedGroupIds.has(e))return;let n=Ud(this.deps.getGroupedTreeRoots(),e);this.expandedGroupIds.delete(e),n?.groupId&&this.emitGroupOpened(n,!1,t),this.deps.onGroupingStateChanged?.()}toggleGroup(e,t){if(this.isExpanded(e)){this.collapseGroup(e,t);return}this.expandGroup(e,t)}expandAll(e){if(this.active)for(let t of Hd(this.deps.getGroupedTreeRoots()))this.expandedGroupIds.has(t)||this.expandGroup(t,e)}collapseAll(e){if(this.active)for(let t of[...this.expandedGroupIds])this.collapseGroup(t,e)}clearExpanded(){this.expandedGroupIds.clear()}pruneExpanded(e){for(let t of[...this.expandedGroupIds])e.has(t)||this.expandedGroupIds.delete(t)}applyDefaultExpanded(e){if(!this.active)return;let t=this.deps.getOptions().groupDefaultExpanded;t!==0&&Vd(e,e=>{!Wd(e.groupLevel??0,t)||!e.groupId||this.expandedGroupIds.add(e.groupId)})}getLeafGroupPathKey(e){return!Zt(e)||Jt(e)||Yt(e)?null:e.leafGroupPathKey??null}getMapStageOptions(){return{expandedGroupIds:this.expandedGroupIds,showGroupHeader:this.deps.getOptions().showGroupHeader,showGroupFooter:this.deps.getOptions().showGroupFooter}}emitGroupOpened(e,t,n){this.deps.onGroupOpened?.(Qt({groupId:e.groupId,expanded:t,field:e.groupField??``,key:e.groupKey??``,level:e.groupLevel??0,source:n}))}emitGroupChanged(e){this.deps.onGroupChanged?.(e)}};function Dm(e,t){for(let n of e)t(n),Dm(Lc(n),t)}function Om(e,t=e=>e.treeLeaf!==!0){let n=[];return Dm(e,e=>{t(e)&&n.push(e.id)}),n}function km(e,t){let n;return Dm(e,e=>{e.id===t&&(n=e)}),n}function Am(e,t){return t===0?!1:t===-1||e<t}function jm(e){let t=new Set;return Dm(e,e=>t.add(e.id)),t}var Mm=class{deps;expandedRowIds=new Set;constructor(e){this.deps=e}get active(){let e=this.deps.getOptions();return un(e.tree,e.getDataPath)}getExpandedRowIds(){return this.expandedRowIds}isExpanded(e){return this.expandedRowIds.has(e)}expandNode(e,t){if(!this.active||this.expandedRowIds.has(e))return;let n=km(this.deps.getTreeTreeRoots(),e);!n||!this.isNodeExpandable(n)||(this.expandedRowIds.add(e),this.emitNodeOpened(n,!0,t),this.deps.onTreeStateChanged?.())}collapseNode(e,t){if(!this.active||!this.expandedRowIds.has(e))return;this.deps.getLazyLoadHost?.()?.abortLoad(e);let n=km(this.deps.getTreeTreeRoots(),e);this.expandedRowIds.delete(e),n&&this.emitNodeOpened(n,!1,t),this.deps.onTreeStateChanged?.()}toggleNode(e,t){if(this.isExpanded(e)){this.collapseNode(e,t);return}this.expandNode(e,t)}async requestToggleNode(e,t){if(!this.active)return;if(this.isExpanded(e)){this.collapseNode(e,t);return}let n=km(this.deps.getTreeTreeRoots(),e);if(!n||!this.isNodeExpandable(n))return;let r=this.deps.getLazyLoadHost?.();if(r?.ensureChildrenLoaded){if(!await r.ensureChildrenLoaded(n,t))return;let i=km(this.deps.getTreeTreeRoots(),e)??n;if(!this.isNodeExpandable(i))return}this.expandNode(e,t)}isNodeExpandable(e){let t=this.deps.getLazyLoadHost?.();return t?t.isExpandable(e):e.treeLeaf!==!0}isNodeLoading(e){return this.deps.getLazyLoadHost?.()?.isLoading(e)??!1}expandAll(e){if(this.active)for(let t of Om(this.deps.getTreeTreeRoots(),e=>this.isNodeExpandable(e)))this.expandedRowIds.has(t)||this.expandNode(t,e)}collapseAll(){if(this.active)for(let e of[...this.expandedRowIds])this.collapseNode(e,`api`)}clearExpanded(){this.expandedRowIds.clear()}pruneExpanded(e){for(let t of[...this.expandedRowIds])e.has(t)||this.expandedRowIds.delete(t)}applyDefaultExpanded(e){if(!this.active)return;let t=this.deps.getGroupDefaultExpanded();t!==0&&Dm(e,e=>{let n=e.treeLevel??0;e.treeLeaf!==!0&&Am(n,t)&&this.expandedRowIds.add(e.id)})}getDataPathForRow(e){let t=km(this.deps.getTreeTreeRoots(),e);return t?.dataPath?[...t.dataPath]:void 0}getMapStageOptions(){let e=this.deps.getOptions();return{expandedRowIds:this.expandedRowIds,treeValueGetter:e.treeValueGetter}}getTreeDisplayValue(e){let t=this.deps.getOptions(),n=e.dataPath??[];return t.treeValueGetter?t.treeValueGetter({data:e.data,dataPath:n,treeLevel:e.treeLevel??0}):n[n.length-1]??``}prepareTreeTree(e){let t=jm(e);this.pruneExpanded(t),this.deps.getLazyLoadHost?.()?.pruneLoaded(t)}applyDefaultExpandedToTree(e){this.applyDefaultExpanded(e)}emitNodeOpened(e,t,n){this.deps.onNodeOpened?.(pn(e.id,t,e.treeLevel??0,e.dataPath??[],n))}},Nm=class{deps;loadedParentIds=new Set;emptyLeafParentIds=new Set;loadingParentIds=new Set;inflight=new Map;constructor(e){this.deps=e}get active(){let e=this.deps.getOptions();return e.treeLazyLoad===!0&&typeof e.loadTreeChildren==`function`}isLoading(e){return this.loadingParentIds.has(e)}isLoadedEmptyLeaf(e){return this.emptyLeafParentIds.has(e)}isLoadedParent(e){return this.loadedParentIds.has(e)}resolveExpandable(e){let t=e.childrenAfterTree;if(t&&t.length>0)return!0;if(this.emptyLeafParentIds.has(e.id))return!1;let n=this.deps.getOptions().hasTreeChildren;return n?n({data:e.data,dataPath:e.dataPath??[],treeLevel:e.treeLevel??0}):e.treeLeaf!==!0}isExpandable(e){return this.resolveExpandable(e)}needsLazyLoad(e){return!this.active||this.loadedParentIds.has(e.id)||this.emptyLeafParentIds.has(e.id)||e.childrenAfterTree&&e.childrenAfterTree.length>0?!1:this.resolveExpandable(e)}abortLoad(e){let t=this.inflight.get(e);t&&(t.controller.abort(),this.inflight.delete(e)),this.loadingParentIds.delete(e)}reset(){for(let e of this.inflight.values())e.controller.abort();this.inflight.clear(),this.loadedParentIds.clear(),this.emptyLeafParentIds.clear(),this.loadingParentIds.clear()}prune(e){for(let t of[...this.loadedParentIds])e.has(t)||this.loadedParentIds.delete(t);for(let t of[...this.emptyLeafParentIds])e.has(t)||this.emptyLeafParentIds.delete(t);for(let t of[...this.inflight.keys()])e.has(t)||this.abortLoad(t)}pruneLoaded(e){this.prune(e)}ensureChildrenLoaded(e,t=`ui`){if(!this.needsLazyLoad(e))return Promise.resolve(!0);let n=this.inflight.get(e.id);if(n)return n.promise;let r=new AbortController,i=this.runLoad(e,t,r);return this.inflight.set(e.id,{controller:r,promise:i}),i.finally(()=>{this.inflight.delete(e.id)})}async runLoad(e,t,n){let r=this.deps.getOptions().loadTreeChildren;if(!r)return!1;let i=e.id,a=e.dataPath??[],o=e.treeLevel??0;this.loadingParentIds.add(i),this.deps.onStateChanged?.(),this.deps.onLoading?.({parentRowId:i,dataPath:[...a],treeLevel:o,source:t});try{let s=await r({parentRowId:i,parentData:e.data,dataPath:[...a],treeLevel:o,signal:n.signal});if(n.signal.aborted)return!1;let c=Pm(s);return c.length===0?(this.emptyLeafParentIds.add(i),this.deps.onLoaded?.({parentRowId:i,children:[],childCount:0,source:t}),!0):(Fm({parentPath:a,children:c,rowKey:this.deps.rowKey,getDataPath:this.deps.getDataPath(),existingRowKeys:this.deps.getExistingRowKeys()}),this.deps.applyTransaction({add:c}),this.loadedParentIds.add(i),this.deps.onLoaded?.({parentRowId:i,children:c,childCount:c.length,source:t}),!0)}catch(e){if(n.signal.aborted)return!1;let t=e instanceof Error?e.message:String(e);return this.deps.onLoadFailed?.({parentRowId:i,reason:t,aborted:!1}),!1}finally{this.loadingParentIds.delete(i),this.deps.onStateChanged?.()}}};function Pm(e){return e?[...e]:[]}function Fm(e){let t=new Set(e.existingRowKeys);for(let n of e.children){let r=e.getDataPath({data:n});if(!Im(e.parentPath,r))throw Error(`[magic-grid] loadTreeChildren: child path [${r.join(`/`)}] must extend parent [${e.parentPath.join(`/`)}]`);let i=n[e.rowKey];if(i==null||i===``)throw Error(`[magic-grid] loadTreeChildren: child row is missing rowKey value.`);let a=String(i);if(t.has(a))throw Error(`[magic-grid] loadTreeChildren: duplicate rowKey "${a}".`);t.add(a)}}function Im(e,t){if(t.length!==e.length+1)return!1;for(let n=0;n<e.length;n++)if(t[n]!==e[n])return!1;return!0}var Lm=!1;function Rm(e){let t=e.tree===!0,n=e.rowGrouping===!0;return t?(n&&!Lm&&(Lm=!0,console.warn(`[magic-grid] tree and rowGrouping are mutually exclusive; rowGrouping ignored.`)),{mode:`tree`,rowGroupingIgnored:n}):n?{mode:`group`,rowGroupingIgnored:!1}:{mode:`flat`,rowGroupingIgnored:!1}}function zm(e){return{sourceRows:e.sourceRows,displayRows:e.displayRows,hasSortOrFilter:e.sortModelLength>0||e.filterModelKeyCount>0}}function Bm(e,t,n){if(e===void 0)return;if(t===`source`||!n.hasSortOrFilter)return Jd(e,n.sourceRows.length);if(n.displayRows.length===0)return 0;let r=Jd(e,n.displayRows.length),i=n.displayRows[r];if(!i)return n.sourceRows.length;let a=n.sourceRows.findIndex(e=>e.id===i.id);return a<0?n.sourceRows.length:a}function Vm(e,t,n){let r=t===`display`||n.hasSortOrFilter?n.displayRows:n.sourceRows,i=[];for(let t of e){if(r.length===0)continue;let e=r[Jd(t,r.length)];e&&i.push(e.id)}return i}function Hm(e,t){return t<=0?0:Math.max(0,Math.min(e,t-1))}function Um(e,t,n,r){if(t===`display`&&r)return null;if(t===`source`||!n.hasSortOrFilter)return Hm(e,n.sourceRows.length);let i=Hm(e,n.displayRows.length),a=n.displayRows[i];if(!a)return Hm(n.sourceRows.length-1,n.sourceRows.length);let o=n.sourceRows.findIndex(e=>e.id===a.id);return o<0?Hm(n.sourceRows.length-1,n.sourceRows.length):o}function Wm(e,t){let n=null;for(let r of t){let t=e.find(e=>e.id===r);if(!t||!H(t))return`missing`;let i=t.parentRowId??null;if(n==null){n=i;continue}if(n!==i)return`mixed`}return n}function Gm(e,t,n,r){let i=0,a=Math.max(0,Math.min(t,e.length));for(let t=0;t<a;t+=1){let a=e[t];H(a)&&(a.parentRowId??null)===n&&!r.has(a.id)&&(i+=1)}return i}function Km(e,t){let n=e.findIndex(e=>e.id===t);if(n<0)return null;let r=e[n];if(!H(r))return null;let i=r.parentRowId??null,a=0;for(let t=0;t<n;t+=1)(e[t].parentRowId??null)===i&&(a+=1);return{parentRowId:i,siblingIndex:a,treeLevel:r.treeLevel??Math.max(0,(r.dataPath?.length??1)-1)}}function qm(e,t,n,r){let i=new Set(t),a=0,o=Hm(n,e.length);for(let t=0;t<o;t+=1){let n=e[t];H(n)&&(n.parentRowId??null)===r&&!i.has(n.id)&&(a+=1)}return a}function Jm(e){if(!e.active)return{allowed:!0};let t=Wm(e.sourceRows,e.rowIds);return t===`mixed`?{allowed:!1,reason:`selected rows must belong to the same tree parent`}:t===`missing`?{allowed:!1,reason:`cannot move non-tree rows while tree mode is active`}:t!=null&&!Ym(e.sourceRows,e.rowIds,e.targetSourceIndex,t)?{allowed:!1,reason:`tree drag target must stay within the same parent siblings`}:{allowed:!0,parentRowId:t}}function Ym(e,t,n,r){let i=new Set(t),a=e.filter(e=>H(e)&&(e.parentRowId??null)===r).length,o=qm(e,t,n,r),s=a-i.size;return o>=0&&o<=s}function Xm(e,t,n,r,i){for(let e of n){let n=t(e);if(!n||!H(n)||(n.parentRowId??null)!==i)return!1}let a=[];for(let t=0;t<e.length;t+=1){let n=e[t];H(n)&&(n.parentRowId??null)===i&&a.push(t)}if(a.length===0)return!1;let o=Math.min(...a),s=Math.max(...a)+1,c=Math.max(0,Math.min(r,e.length));return c>=o&&c<=s}function Zm(e){let t=new Set(e.rowIds),n=[],r=[];for(let t=0;t<e.sourceRows.length;t+=1){let i=e.sourceRows[t];!H(i)||(i.parentRowId??null)!==e.parentRowId||(n.push(t),r.push(i))}let i=e.rowIds.map(e=>r.find(t=>t.id===e)).filter(e=>e!=null);if(i.length!==e.rowIds.length)return null;let a=r.filter(e=>!t.has(e.id)),o=Math.max(0,Math.min(e.withinSiblingInsertIndex,a.length)),s=[...a.slice(0,o),...i,...a.slice(o)];if(s.every((e,t)=>e.id===r[t].id))return null;let c=[...e.sourceRows];for(let e=0;e<n.length;e+=1)c[n[e]]=s[e];let l=[];for(let t of i){let n=e.sourceRows.findIndex(e=>e.id===t.id),r=c.findIndex(e=>e.id===t.id);n>=0&&r>=0&&n!==r&&l.push({rowId:t.id,fromIndex:n,toIndex:r})}return l.length===0?null:{rows:c,moves:l}}function Qm(e){let t=new Set(e.rowIds);if(!Xm(e.displayRows,t=>e.sourceRows.find(e=>e.id===t),e.rowIds,e.displayInsertIndex,e.parentRowId))return null;let n=Gm(e.displayRows,e.displayInsertIndex,e.parentRowId,t);return Zm({sourceRows:e.sourceRows,rowIds:e.rowIds,withinSiblingInsertIndex:n,parentRowId:e.parentRowId})}var $m=1.5;function eh(e,t,n,r){return e<t+40?-Math.min(1,(t+40-e)/40)*r*$m:e>n-40?Math.min(1,(e-(n-40))/40)*r*$m:0}function th(e,t,n,r,i){let a=nh(e,n,r);if(a)return a;let o=t.getBoundingClientRect(),s=i()+(r-o.top),c=e.getRowIndexAtPixel(s),l=e.getRow(c);return l?{rowId:l.id,rowIndex:c}:null}function nh(e,t,n){let r=document.elementFromPoint(t,n)?.closest(`.mg-row`);if(!r)return null;let i=r.dataset.rowId;if(!i)return null;let a=e.getRowIndexById(i);return a<0?null:{rowId:i,rowIndex:a}}function rh(e,t,n){return eh(e,t,n,1)!==0}function ih(e,t){return e.dataPath??t({data:e.data})}function ah(e,t){if(t.length<e.length)return!1;for(let n=0;n<e.length;n+=1)if(t[n]!==e[n])return!1;return!0}function oh(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function sh(e,t,n){let r=e;for(;r;){if(r.id===t)return!0;let e=r.parentRowId;if(e==null)return!1;r=n(e)}return!1}function ch(e,t,n){let r=[];for(let i of n){let n=e.find(e=>e.id===i);n&&r.push(ih(n,t))}if(r.length===0)return[];let i=[],a=new Set;for(let n of e){let e=ih(n,t);r.some(t=>oh(e,t)||ah(t,e))&&!a.has(n.id)&&(a.add(n.id),i.push(n.id))}return i}function lh(e){let t=th(e.rowModel,e.viewportEl,e.clientX,e.clientY,e.getLogicalScrollTop);if(!t||new Set(e.movingRowIds??[]).has(t.rowId))return null;let n=e.rowModel.getRowById(t.rowId);if(!n||!H(n))return null;if(e.altKey)return t.rowId;let r=e.viewportEl.querySelector(`.mg-row[data-row-id="${CSS.escape(t.rowId)}"]`)?.querySelector(`.mg-cell[data-col-id="${en}"], .mg-cell--tree-auto`);if(!r)return null;let i=n.treeLevel??0,a=r.getBoundingClientRect().left+(i+1)*16;return e.clientX>=a?t.rowId:null}function uh(e,t,n,r={}){let i=r.nestUnderRowId??null;if(i){if(n.has(i))return null;let r=e.find(e=>e.id===i);return!r||!H(r)?null:{newParentRowId:i,withinSiblingInsertIndex:Gm(e,Math.max(0,Math.min(t,e.length)),i,n)}}let a=Math.max(0,Math.min(t,e.length)),o=a<e.length?e[a]:void 0,s=a>0?e[a-1]:void 0;if(!o&&!s)return{newParentRowId:null,withinSiblingInsertIndex:0};let c=o??s;if(!c||!H(c))return null;let l=o?o.parentRowId??null:s.parentRowId??null;return{newParentRowId:l,withinSiblingInsertIndex:Gm(e,a,l,n)}}function dh(e,t,n,r,i,a,o={}){for(let e of r){let t=n(e);if(!t||!H(t))return!1}let s=uh(t,i,new Set(ch(e,a,r)),o);if(!s)return!1;if(s.newParentRowId){let e=n(s.newParentRowId);if(!e||!H(e))return!1;for(let t of r)if(s.newParentRowId===t||sh(e,t,n))return!1}return!0}function fh(e){let t=new Set(ch(e.sourceRows,e.getDataPath,e.rowIds));if(e.treeDragScope===`hierarchy`){let n=uh(e.displayRows,e.insertIndex,t,{nestUnderRowId:e.nestUnderRowId});if(!n)return null;let r=n.newParentRowId==null?void 0:e.sourceRows.find(e=>e.id===n.newParentRowId);return{parentRowId:n.newParentRowId,siblingIndex:n.withinSiblingInsertIndex,treeLevel:n.newParentRowId==null?0:(r?.treeLevel??0)+1}}let n=Wm(e.sourceRows,e.rowIds);if(n===`mixed`||n===`missing`)return null;let r=n==null?void 0:e.sourceRows.find(e=>e.id===n);return{parentRowId:n,siblingIndex:Gm(e.displayRows,e.insertIndex,n,t),treeLevel:n==null?0:(r?.treeLevel??0)+1}}function ph(e,t,n){let r=ih(e[t],n),i=t;for(let a=t+1;a<e.length;a+=1){let t=ih(e[a],n);if(ah(r,t)&&!oh(r,t)){i=a;continue}break}return i}function mh(e,t,n,r){let i=[];for(let n=0;n<e.length;n+=1)(e[n].parentRowId??null)===t&&i.push(n);if(i.length===0){if(t==null)return 0;let n=e.findIndex(e=>e.id===t);return n<0?e.length:ph(e,n,r)+1}if(n>=i.length){let t=i[i.length-1];return ph(e,t,r)+1}return i[n]}function hh(e,t,n){for(let r of e)if(oh(ih(r,n),t))return r.id}function gh(e){return e.map(e=>({...e,data:{...e.data},dataPath:e.dataPath?[...e.dataPath]:void 0,childrenAfterTree:e.childrenAfterTree?[...e.childrenAfterTree]:void 0}))}function _h(e){if(!dh(e.sourceRows,e.displayRows,t=>e.sourceRows.find(e=>e.id===t),e.rowIds,e.displayInsertIndex,e.getDataPath,{nestUnderRowId:e.nestUnderRowId}))return null;let t=ch(e.sourceRows,e.getDataPath,e.rowIds),n=new Set(t),r=Wm(e.sourceRows,e.rowIds),i=uh(e.displayRows,e.displayInsertIndex,n,{nestUnderRowId:e.nestUnderRowId});if(!i||r===`mixed`||r===`missing`)return null;if((i.newParentRowId??null)===r&&t.length===e.rowIds.length)return Qm({sourceRows:e.sourceRows,displayRows:e.displayRows,rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,parentRowId:r});let a=gh(e.sourceRows),o=e=>a.find(t=>t.id===e),s=t=>ih(t,e.getDataPath),c=new Map;for(let t of e.rowIds){let e=o(t);if(!e)return null;let n=s(e),r=e.parentRowId==null?[]:s(o(e.parentRowId)),a=n.slice(r.length),l=i.newParentRowId==null?[]:s(o(i.newParentRowId));c.set(t,[...l,...a])}let l=[...t].sort((e,t)=>{let n=o(e),r=o(t);return s(n).length-s(r).length});for(let t of l){let n=o(t);if(!n)return null;let r=s(n),i=e.rowIds.find(e=>{let t=o(e);if(!t)return!1;let n=s(t);return oh(r,n)||ah(n,r)});if(!i)return null;let l=s(o(i)),u=c.get(i);if(!u)return null;let d=[...u,...r.slice(l.length)];e.setDataPath({data:n.data,dataPath:d,treeLevel:d.length-1,previousPath:[...r]}),n.dataPath=d,n.treeLevel=d.length-1,n.parentRowId=d.length>1?hh(a,d.slice(0,-1),e.getDataPath):void 0}let u=a.filter(e=>n.has(e.id)),d=a.filter(e=>!n.has(e.id)),f=mh(d,i.newParentRowId,i.withinSiblingInsertIndex,e.getDataPath),p=[...d.slice(0,f),...u,...d.slice(f)],m=[];for(let t of u){let n=e.sourceRows.findIndex(e=>e.id===t.id),r=p.findIndex(e=>e.id===t.id);n>=0&&r>=0&&n!==r&&m.push({rowId:t.id,fromIndex:n,toIndex:r})}let h=u.some(t=>{let n=e.sourceRows.find(e=>e.id===t.id);if(!n)return!1;let r=ih(n,e.getDataPath),i=s(t);return n.parentRowId!==t.parentRowId||!oh(r,i)});return m.length===0&&!h?null:{rows:p,moves:m}}function vh(e,t){let n=null;for(let r of t){let t=e.find(e=>e.id===r);if(!t||Xt(t))return`missing`;let i=t.leafGroupPathKey??null;if(!i)return null;if(n==null){n=i;continue}if(n!==i)return`mixed`}return n}function yh(e,t,n,r){let i=0,a=Math.max(0,Math.min(t,e.length));for(let t=0;t<a;t+=1){let a=e[t];Zt(a)&&a.leafGroupPathKey===n&&!r.has(a.id)&&(i+=1)}return i}function bh(e,t,n,r){let i=new Set(t),a=0,o=Hm(n,e.length);for(let t=0;t<o;t+=1){let n=e[t];n.leafGroupPathKey===r&&!i.has(n.id)&&(a+=1)}if(t.length===1){let n=e.findIndex(e=>e.id===t[0]);n>=0&&n<o&&--a}return Math.max(0,a)}function xh(e){let{sourceRows:t,rowIds:n,groupPath:r,withinGroupInsertIndex:i}=e,a=new Set(n);if(vh(t,n)!==r)return null;let o=[],s=[];for(let e=0;e<t.length;e+=1){let n=t[e];n.leafGroupPathKey===r&&(o.push(e),s.push(n))}let c=s.filter(e=>a.has(e.id));if(c.length!==n.length)return null;let l=s.filter(e=>!a.has(e.id)),u=Math.max(0,Math.min(i,l.length)),d=[...l.slice(0,u),...c,...l.slice(u)];if(d.every((e,t)=>e.id===s[t].id))return null;let f=[...t];for(let e=0;e<o.length;e+=1)f[o[e]]=d[e];let p=[];for(let e of c){let n=t.findIndex(t=>t.id===e.id),r=f.findIndex(t=>t.id===e.id);n>=0&&r>=0&&n!==r&&p.push({rowId:e.id,fromIndex:n,toIndex:r})}return p.length===0?null:{rows:f,moves:p}}function Sh(e){let{sourceRows:t,displayRows:n,rowIds:r,displayInsertIndex:i,groupPath:a}=e,o=new Set(r);return wh(n,e=>t.find(t=>t.id===e),r,i,a)?xh({sourceRows:t,rowIds:r,groupPath:a,withinGroupInsertIndex:yh(n,i,a,o)}):null}function Ch(e,t,n,r){let i=new Set(t),a=e.filter(e=>e.leafGroupPathKey===r).length,o=bh(e,t,n,r),s=a-i.size;return o>=0&&o<=s}function wh(e,t,n,r,i){let a=[];for(let n=0;n<e.length;n+=1){let r=e[n];Zt(r)&&(t(r.id)??r).leafGroupPathKey===i&&a.push(n)}if(a.length===0)return!1;let o=Math.min(...a),s=Math.max(...a)+1;return r>=o&&r<=s}function Th(e){if(!e.active)return{allowed:!0};let t=vh(e.sourceRows,e.rowIds);return t===null?{allowed:!0}:t===`missing`?{allowed:!1,reason:`cannot move non-leaf rows while row grouping is active`}:t===`mixed`?{allowed:!1,reason:`selected rows must belong to the same group`}:Ch(e.sourceRows,e.rowIds,e.targetSourceIndex,t)?{allowed:!0}:{allowed:!1,reason:`cannot move rows across groups`}}function Eh(e,t,n){let r=new Set(n);return r.size<=1||!r.has(t)?[t]:e.filter(e=>r.has(e.id)).map(e=>e.id)}function Dh(e,t,n,r){let i=t.indexOf(n);if(i<0)return Math.max(0,Math.min(r,e-1));let a=r-i,o=Math.max(0,e-t.length);return Math.max(0,Math.min(a,o))}function Oh(e,t,n){return{displayIndex:n,...Km(e,t)??{}}}function kh(e,t,n,r,i){for(let a of t.moves)e(J(a.rowId,a.fromIndex,a.toIndex,r,i,Oh(t.rows,a.rowId,n)))}function Ah(e,t,n){let r=e.findIndex(e=>e.id===t);if(r<0)return null;let i=Hm(n,e.length);if(r===i)return null;let a=[...e],[o]=a.splice(r,1);return a.splice(i,0,o),{rows:a,fromIndex:r,toIndex:i}}function jh(e,t,n){let r=new Set(t),i=e.filter(e=>r.has(e.id));if(i.length===0||i.length!==t.length)return null;let a=new Map;for(let t=0;t<e.length;t++){let n=e[t];r.has(n.id)&&a.set(n.id,t)}let o=e.filter(e=>!r.has(e.id)),s=Math.max(0,Math.min(n,o.length)),c=[...o.slice(0,s),...i,...o.slice(s)],l=[];for(let e of i){let t=a.get(e.id),n=c.findIndex(t=>t.id===e.id);t==null||n<0||t===n||l.push({rowId:e.id,fromIndex:t,toIndex:n})}return l.length===0?null:{rows:c,moves:l}}var Mh=class{deps;constructor(e){this.deps=e}moveRow(e,t=`api`){let n=e.indexMode??`source`,r=zm({sourceRows:this.deps.getSourceRows(),displayRows:this.deps.getDisplayRows(),sortModelLength:this.deps.getSortModelLength(),filterModelKeyCount:this.deps.getFilterModelKeyCount()}),i=this.deps.getSortModelLength()>0,a=Um(e.toIndex,n,r,i);if(a==null)return{moved:!1,reason:`display index mode is not allowed while sort is active`};let o=this.deps.getSourceRows(),s=o.findIndex(t=>t.id===e.rowId);if(s<0)return{moved:!1,reason:`row "${e.rowId}" not found`};let c=Th({active:this.deps.isRowGroupingActive?.()??!1,sourceRows:o,rowIds:[e.rowId],targetSourceIndex:a});if(!c.allowed)return{moved:!1,fromIndex:s,reason:c.reason};let l=Jm({active:this.deps.isTreeActive?.()??!1,sourceRows:o,rowIds:[e.rowId],targetSourceIndex:a});if(!l.allowed)return{moved:!1,fromIndex:s,reason:l.reason};let u=vh(o,[e.rowId]);if(typeof u==`string`&&(this.deps.isRowGroupingActive?.()??!1)){if(n===`display`)return this.finishGroupedDisplayMove(o,[e.rowId],e.rowId,e.toIndex,u,t,e.finished??!0,s);let r=bh(o,[e.rowId],a,u),i=xh({sourceRows:o,rowIds:[e.rowId],groupPath:u,withinGroupInsertIndex:r});if(!i)return{moved:!1,fromIndex:s,toIndex:s};this.deps.setSourceRows(i.rows);let c=i.moves[0];return this.deps.emitRowMoved(J(e.rowId,c?.fromIndex??s,c?.toIndex??s,t,e.finished??!0)),{moved:!0,fromIndex:c?.fromIndex??s,toIndex:c?.toIndex??s}}let d=Wm(o,[e.rowId]);if((typeof d==`string`||d===null)&&this.deps.isTreeActive?.()){if(n===`display`)return this.finishTreeDisplayMove(o,[e.rowId],e.rowId,e.toIndex,d,t,e.finished??!0,s);let r=qm(o,[e.rowId],a,d),i=Zm({sourceRows:o,rowIds:[e.rowId],withinSiblingInsertIndex:r,parentRowId:d});if(!i)return{moved:!1,fromIndex:s,toIndex:s};this.deps.setSourceRows(i.rows);let c=i.moves[0];return this.deps.emitRowMoved(J(e.rowId,c?.fromIndex??s,c?.toIndex??s,t,e.finished??!0)),{moved:!0,fromIndex:c?.fromIndex??s,toIndex:c?.toIndex??s}}let f=Ah(o,e.rowId,a);return f?(this.deps.setSourceRows(f.rows),this.deps.emitRowMoved(J(e.rowId,f.fromIndex,f.toIndex,t,e.finished??!0)),{moved:!0,fromIndex:f.fromIndex,toIndex:f.toIndex}):{moved:!1,fromIndex:s,toIndex:s}}moveRows(e,t=`api`){if(e.rowIds.length===0)return{moved:!1,reason:`no rows to move`};if((this.deps.isRowGroupingActive?.()??!1)&&e.displayInsertIndex!=null)return this.moveRowsByGroupedDisplayInsert(e,t);if((this.deps.isTreeActive?.()??!1)&&e.displayInsertIndex!=null)return this.moveRowsByTreeDisplayInsert(e,t);if(e.rowIds.length===1)return this.moveRow({rowId:e.rowIds[0],toIndex:e.toIndex,indexMode:e.indexMode,finished:e.finished},t);let n=e.indexMode??`source`,r=zm({sourceRows:this.deps.getSourceRows(),displayRows:this.deps.getDisplayRows(),sortModelLength:this.deps.getSortModelLength(),filterModelKeyCount:this.deps.getFilterModelKeyCount()}),i=this.deps.getSortModelLength()>0,a=Um(e.toIndex,n,r,i);if(a==null)return{moved:!1,reason:`display index mode is not allowed while sort is active`};let o=this.deps.getSourceRows(),s=Dh(o.length,e.rowIds,e.leaderRowId,a),c=Th({active:this.deps.isRowGroupingActive?.()??!1,sourceRows:o,rowIds:e.rowIds,targetSourceIndex:s});if(!c.allowed)return{moved:!1,reason:c.reason};let l=Jm({active:this.deps.isTreeActive?.()??!1,sourceRows:o,rowIds:e.rowIds,targetSourceIndex:s});if(!l.allowed)return{moved:!1,reason:l.reason};let u=Wm(o,e.rowIds);if((typeof u==`string`||u===null)&&(this.deps.isTreeActive?.()??!1)){let n=qm(o,e.rowIds,s,u),r=Zm({sourceRows:o,rowIds:e.rowIds,withinSiblingInsertIndex:n,parentRowId:u});if(!r)return{moved:!1,moves:[]};this.deps.setSourceRows(r.rows);let i=e.finished??!0;for(let e of r.moves)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,t,i));let a=r.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:a?.fromIndex,toIndex:a?.toIndex,moves:r.moves}}let d=jh(o,e.rowIds,s);if(!d)return{moved:!1,moves:[]};this.deps.setSourceRows(d.rows);let f=e.finished??!0;for(let e of d.moves)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,t,f));let p=d.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:p?.fromIndex,toIndex:p?.toIndex,moves:d.moves}}moveRowsByGroupedDisplayInsert(e,t){let n=this.deps.getSourceRows(),r=vh(n,e.rowIds);if(r===`mixed`)return{moved:!1,reason:`selected rows must belong to the same group`};if(r===`missing`)return{moved:!1,reason:`cannot move non-leaf rows while row grouping is active`};if(r===null)return{moved:!1,reason:`group path missing on source rows`};let i=Sh({sourceRows:n,displayRows:this.deps.getDisplayRows(),rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,groupPath:r});if(!i)return{moved:!1,moves:[]};this.deps.setSourceRows(i.rows);let a=e.finished??!0;for(let e of i.moves)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,t,a));let o=i.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:o?.fromIndex,toIndex:o?.toIndex,moves:i.moves}}finishGroupedDisplayMove(e,t,n,r,i,a,o,s){let c=this.deps.getDisplayRows(),l=c.findIndex(e=>e.id===n),u=Hm(r,c.length),d=Sh({sourceRows:e,displayRows:c,rowIds:t,displayInsertIndex:l>=0&&l<u?u+1:u,groupPath:i});if(!d)return{moved:!1,fromIndex:s,toIndex:s};this.deps.setSourceRows(d.rows);let f=d.moves;for(let e of f)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,a,o));let p=f.find(e=>e.rowId===n);return{moved:!0,fromIndex:p?.fromIndex??s,toIndex:p?.toIndex??s,moves:f}}moveRowsByTreeDisplayInsert(e,t){let n=this.deps.getSourceRows(),r=Wm(n,e.rowIds);if(r===`mixed`)return{moved:!1,reason:`selected rows must belong to the same tree parent`};if(r===`missing`)return{moved:!1,reason:`cannot move non-tree rows while tree mode is active`};if(this.deps.getTreeDragScope?.()===`hierarchy`){let r=this.deps.getDataPath?.(),i=this.deps.setDataPath?.();if(!r||!i)return{moved:!1,reason:`hierarchy tree drag requires getDataPath and setDataPath`};let a=_h({sourceRows:n,displayRows:this.deps.getDisplayRows(),rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,getDataPath:r,setDataPath:i,nestUnderRowId:e.treeNestUnderRowId});if(!a)return{moved:!1,moves:[]};this.deps.setSourceRows(a.rows);let o=e.finished??!0;kh(this.deps.emitRowMoved,a,e.displayInsertIndex,t,o);let s=a.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:s?.fromIndex,toIndex:s?.toIndex,moves:a.moves}}let i=Qm({sourceRows:n,displayRows:this.deps.getDisplayRows(),rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,parentRowId:r});if(!i)return{moved:!1,moves:[]};this.deps.setSourceRows(i.rows);let a=e.finished??!0;kh(this.deps.emitRowMoved,i,e.displayInsertIndex,t,a);let o=i.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:o?.fromIndex,toIndex:o?.toIndex,moves:i.moves}}finishTreeDisplayMove(e,t,n,r,i,a,o,s){let c=this.deps.getDisplayRows(),l=c.findIndex(e=>e.id===n),u=Hm(r,c.length),d=Qm({sourceRows:e,displayRows:c,rowIds:t,displayInsertIndex:l>=0&&l<u?u+1:u,parentRowId:i});if(!d)return{moved:!1,fromIndex:s,toIndex:s};this.deps.setSourceRows(d.rows);let f=d.moves;for(let e of f)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,a,o));let p=f.find(e=>e.rowId===n);return{moved:!0,fromIndex:p?.fromIndex??s,toIndex:p?.toIndex??s,moves:f}}};function Nh(e,t,n,r,i){let a=th(e,t,n,r,i);return a?Ph(a,r,t,e,i):-1}function Ph(e,t,n,r,i){let a=r.getRowCount(),o=Ih(e,n,r,i),s=e.rowIndex;return o!=null&&t>o&&(s+=1),Math.max(0,Math.min(s,a))}function Fh(e,t){return t<=0?0:Math.max(0,Math.min(e,t-1))}function Ih(e,t,n,r){let i=t.querySelector(`.mg-row[data-row-id="${CSS.escape(e.rowId)}"]`);if(i){let e=i.getBoundingClientRect();return e.top+e.height/2}let a=n.getRowBounds(e.rowIndex);return a?t.getBoundingClientRect().top+a.rowTop+a.rowHeight/2-r():null}function Lh(e,t,n){return{displayIndex:n,...Km(e,t)??{}}}function Rh(e,t,n){if(t.moves.length===0)return{ok:!1,reason:`no row order change`};let r=n??e.leaderRowId;return{ok:!0,plan:{rowIds:[...e.rowIds],leaderRowId:e.leaderRowId,rows:t.rows,moves:t.moves,displayIndex:e.displayInsertIndex,treeDrop:e.isTreeActive?Lh(t.rows,r,e.displayInsertIndex):{displayIndex:e.displayInsertIndex}}}}function zh(e){let t=vh(e.sourceRows,e.rowIds);if(t===`mixed`)return{ok:!1,reason:`selected rows must belong to the same group`};if(t===`missing`)return{ok:!1,reason:`cannot move non-leaf rows while row grouping is active`};if(t===null)return{ok:!1,reason:`group path missing on source rows`};let n=Sh({sourceRows:e.sourceRows,displayRows:e.displayRows,rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,groupPath:t});return n?Rh(e,n):{ok:!1,reason:`invalid grouped display drop`}}function Bh(e){let t=Wm(e.sourceRows,e.rowIds);if(t===`mixed`)return{ok:!1,reason:`selected rows must belong to the same tree parent`};if(t===`missing`)return{ok:!1,reason:`cannot move non-tree rows while tree mode is active`};if(e.treeDragScope===`hierarchy`){let t=e.getDataPath,n=e.setDataPath;if(!t||!n)return{ok:!1,reason:`hierarchy tree drag requires getDataPath and setDataPath`};let r=_h({sourceRows:e.sourceRows,displayRows:e.displayRows,rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,getDataPath:t,setDataPath:n,nestUnderRowId:e.treeNestUnderRowId});return r?Rh(e,r):{ok:!1,reason:`invalid tree hierarchy display drop`}}let n=Qm({sourceRows:e.sourceRows,displayRows:e.displayRows,rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,parentRowId:t});return n?Rh(e,n):{ok:!1,reason:`invalid tree sibling display drop`}}function Vh(e){let t=e.displayRows.length,n=Fh(e.displayInsertIndex,t),r=e.displayRows.findIndex(t=>t.id===e.leaderRowId);if(r>=0&&n===r)return{ok:!1,reason:`no row order change`};let i=e.sortModelLength>0,a=zm({sourceRows:e.sourceRows,displayRows:e.displayRows,sortModelLength:e.sortModelLength,filterModelKeyCount:e.filterModelKeyCount}),o=Um(n,a.hasSortOrFilter&&!i?`display`:`source`,a,i);if(o==null)return{ok:!1,reason:`display index mode is not allowed while sort is active`};if(e.rowIds.length===1){let t=Ah(e.sourceRows,e.rowIds[0],o);return t?Rh(e,{rows:t.rows,moves:[{rowId:e.rowIds[0],fromIndex:t.fromIndex,toIndex:t.toIndex}]}):{ok:!1,reason:`no row order change`}}let s=Dh(e.sourceRows.length,e.rowIds,e.leaderRowId,o),c=jh(e.sourceRows,e.rowIds,s);return c?Rh(e,c):{ok:!1,reason:`no row order change`}}function Hh(e){return e.rowIds.length===0?{ok:!1,reason:`no rows to move`}:e.displayInsertIndex<0?{ok:!1,reason:`invalid display insert index`}:e.isRowGroupingActive?zh(e):e.isTreeActive?Bh(e):Vh(e)}function Uh(e){return e===void 0||e===!0?{ok:!0}:e===!1?{ok:!1}:typeof e==`object`&&e.ok===!1?{ok:!1,reason:e.reason}:{ok:!0}}var Wh=class{deps;phase=`idle`;nextCommitId=0;commitController=null;committingTarget=null;constructor(e){this.deps=e}isCommitting(){return this.phase===`committing`}getCommittingTarget(){return this.committingTarget}abort(){this.commitController?.abort(),this.commitController=null,this.phase=`idle`,this.setCommitVisual(null)}destroy(){this.abort()}async commit(t){let n=this.deps.getOnRowDragCommit();if(!n){this.deps.emitFinished(ga({commitId:-1,leaderRowId:t.plan.leaderRowId,committed:!1,reason:`onRowDragCommit is required when rowDragCommitMode is deferred`}));return}let r=++this.nextCommitId,i=e.s(r,this.commitController);this.commitController=i,this.phase=`committing`,this.setCommitVisual({rowIds:t.rowIds}),this.deps.emitStarted(ha({rowIds:t.rowIds,leaderRowId:t.plan.leaderRowId,displayIndex:t.plan.displayIndex,treeDrop:t.plan.treeDrop}));let a={ok:!1};try{let e=await n(_a(t.plan,t.nestUnderRowId,i.context));if(i.context.commitId!==r)return;a=Uh(e)}catch(t){if(e.c(t))a={ok:!1,aborted:!0};else throw t}finally{this.commitController===i&&(this.commitController=null),this.phase=`idle`,this.setCommitVisual(null)}i.context.commitId===r&&(this.deps.emitFinished(ga({commitId:r,leaderRowId:t.plan.leaderRowId,committed:a.ok,aborted:a.aborted,reason:a.reason})),a.ok&&(this.deps.applyPlan(t.plan),this.deps.emitRowDragEnd(ma(t.plan.leaderRowId,t.plan.displayIndex,!0,t.rowIds,t.treeContext))))}setCommitVisual(e){this.committingTarget=e,this.deps.setCommittingVisual(e)}};function Gh(e,t=6){let n=e;for(;n;){let e=getComputedStyle(n).getPropertyValue(`--mg-cell-comment-indicator-size`).trim();if(e){let t=parseFloat(e);if(Number.isFinite(t))return t}n=n.parentElement}return t}function Kh(e,t,n=2){let r=t,i=t,a=e.right-n,o=e.top+n,s=a-r;return{x:s,y:o,left:s,top:o,right:a,bottom:o+i,width:r,height:i,toJSON:()=>({})}}function qh(e,t,n){if(!e.classList.contains(`mg-cell--has-comment`)&&!e.classList.contains(`mg-cell--comment-empty`))return!1;let r=Kh(e.getBoundingClientRect(),Gh(e));return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom}var Jh=`mg-cell-comment-popup__textarea`,Yh=`mg-cell-comment-popup__actions`,Xh=`mg-cell-comment-popup__btn--save`,Zh=`mg-cell-comment-popup__btn--delete`,Qh=`mg-cell-comment-popup__btn--cancel`;function $h(e,t=8){let n=e;for(;n;){let e=getComputedStyle(n).getPropertyValue(`--mg-spacing`).trim();if(e){let t=parseFloat(e);if(Number.isFinite(t))return t}n=n.parentElement}return t}function eg(e){let t=$h(e);return{viewportPadding:t,anchorGap:t}}function tg(e,t,n,r=eg(null),i=6){let{viewportPadding:a,anchorGap:o}=r,s=Kh(e,i),c=s.right+o,l=s.top;return c+t>window.innerWidth-a&&(c=s.left-t-o),c=Math.max(a,Math.min(c,window.innerWidth-t-a)),l=Math.max(a,Math.min(l,window.innerHeight-n-a)),{left:c,top:l}}function ng(e,t){if(!t)return 4;let n=e?e.split(`
|
|
2
|
+
`),i=t.querySelector(`.mg-cell[data-col-id="${n.colId}"]`);i?.classList.add(`mg-cell--invalid`),i?.setAttribute(`title`,r),this.domStates.push({rowId:e,colId:n.colId,editorMountEl:n.editorMountEl??null})}removeCellDom(e,t){let n=t.querySelector(`.mg-cell[data-col-id="${e.colId}"]`);n?.classList.remove(`mg-cell--invalid`),n?.removeAttribute(`title`)}removeRegistryDom(e){for(let[t,n]of this.registry){let r=this.findRowElement(e,t);if(r)for(let e of n.keys()){let t=r.querySelector(`.mg-cell[data-col-id="${e}"]`);t?.classList.remove(`mg-cell--invalid`),t?.removeAttribute(`title`)}}}},mr=`__mg_tmp_`,hr=0;function gr(){return hr+=1,`${Date.now().toString(36)}_${hr.toString(36)}`}function _r(){return`${mr}${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():gr()}`}function vr(e){return e.startsWith(mr)}function yr(e){return e==null||e===``}function br(e){if(e.group)return!0;let t=e.rowKind;return t===`detail`||t===`groupHeader`||t===`groupFooter`}function xr(e,t){if(e.isTransient)return null;let n=e.data[t];return!br(e)&&(typeof n==`number`||typeof n==`string`)?n:e.id}function Sr(e,t,n,r){if(r?.isTransient||vr(n))return null;let i=e[t];return typeof i==`number`||typeof i==`string`?i:n}function Cr(e,t){if(vr(e))return null;let n=t.getRowById(e);return n?xr(n,t.rowKey):e}function wr(e,t){return e.map(e=>Cr(e,t))}function Tr(e){return{fromNode:t=>xr(t,e.rowKey),fromInternal:t=>Cr(t,e),fromInternalList:t=>wr(t,e)}}function Er(e,t){let n=Tr(t);return{...e,cellErrors:e.cellErrors.map(e=>({...e,rowId:n.fromInternal(String(e.rowId))}))}}function K(e,t){return t.fromInternal(e)}function Dr(e,t){return t.fromInternalList(e)}function Or(e,t,n){let r=Tr(n);switch(e){case`cellClicked`:case`rowClicked`:case`rowDoubleClicked`:case`cellFocused`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`selectionChanged`:return{selectedRowIds:Dr(t.selectedRowIds,r)};case`indexFocusChanged`:return{focusedRowIds:Dr(t.focusedRowIds,r)};case`cellValueChanged`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`cellEditingStarted`:case`cellEditingStopped`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`rowEditingStarted`:case`rowEditingStopped`:case`rowValueChanged`:case`rowCommitStarted`:case`rowCommitFinished`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`cellCommitStarted`:case`cellCommitFinished`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`editCommitAborted`:{let e=t;return{...e,rowId:e.rowId==null?e.rowId:K(e.rowId,r)}}case`cellValidationFailed`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`rowValidationFailed`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`rowsAdded`:return{rows:t.rows.map(e=>({...e,rowId:Sr(e.data,n.rowKey,String(e.rowId),{isTransient:e.isTransient})}))};case`rowsRemoved`:return{rows:t.rows.map(e=>({...e,rowId:Sr(e.data,n.rowKey,String(e.rowId))}))};case`rowIdPromoted`:{let e=t,n=vr(e.oldRowId)?null:K(e.oldRowId,r);return{...e,oldRowId:n,newRowId:K(e.newRowId,r)}}case`rowMoved`:{let e=t;return{...e,rowId:K(e.rowId,r),parentRowId:e.parentRowId===void 0?void 0:e.parentRowId===null?null:K(e.parentRowId,r)}}case`rowDragEnd`:{let e=t;return{...e,rowId:K(e.rowId,r),rowIds:e.rowIds?Dr(e.rowIds,r):void 0,parentRowId:e.parentRowId===void 0?void 0:e.parentRowId===null?null:K(e.parentRowId,r)}}case`rowDragCommitStarted`:{let e=t;return{...e,rowId:K(e.rowId,r),rowIds:Dr(e.rowIds,r),leaderRowId:K(e.leaderRowId,r),parentRowId:e.parentRowId===void 0?void 0:e.parentRowId===null?null:K(e.parentRowId,r)}}case`rowDragCommitFinished`:{let e=t;return{...e,rowId:K(e.rowId,r),leaderRowId:K(e.leaderRowId,r)}}case`rowHeightChanged`:{let e=t;return{...e,rows:e.rows.map(e=>({...e,rowId:K(e.rowId,r)}))}}case`rowExpanded`:case`rowCollapsed`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`treeNodeOpened`:{let e=t;return{...e,rowId:K(e.rowId,r)}}case`treeChildrenLoading`:case`treeChildrenLoaded`:case`treeChildrenLoadFailed`:{let e=t;return{...e,parentRowId:K(e.parentRowId,r)}}case`cellCommentChanged`:{let e=t;return{...e,rowId:K(e.rowId,r)}}default:return t}}var kr=class{listeners=new Map;destroyed=!1;projector=null;setProjector(e){this.projector=e}on(e,t){if(this.destroyed)return()=>void 0;let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n));let r=t;return n.add(r),()=>{n?.delete(r)}}emit(e,t){if(this.destroyed)return;let n=this.listeners.get(e);if(!n)return;let r=this.projector?this.projector(e,t):t;for(let e of n)e(r)}destroy(){this.destroyed=!0,this.listeners.clear(),this.projector=null}};function Ar(e){return(t,n)=>Or(t,n,e)}var jr=class{mode;selectedIds=new Set;anchorIndex=-1;constructor(e=`single`){this.mode=e===`multiple`?`multiple`:`single`}getSelectedRowIds(){return[...this.selectedIds]}isSelected(e){return this.selectedIds.has(e)}clear(){this.selectedIds.clear(),this.anchorIndex=-1}removeRowIds(e){let t=!1;for(let n of e)this.selectedIds.delete(n)&&(t=!0);return t}migrateRowId(e,t){return this.selectedIds.has(e)?(this.selectedIds.delete(e),this.selectedIds.add(t),!0):!1}getAnchorIndex(){return this.anchorIndex}isMultiple(){return this.mode===`multiple`}setAnchorIndex(e){this.anchorIndex=e}selectRow(e,t,n,r={}){let{ctrlKey:i=!1,shiftKey:a=!1,toggleOnReselect:o=!1}=r;if(this.mode===`multiple`&&a&&this.anchorIndex>=0&&t>=0)return this.selectRangeBetween(this.anchorIndex,t,n,r.rangeSelection);if(this.mode===`multiple`&&i)return this.selectedIds.has(e)?this.selectedIds.delete(e):this.selectedIds.add(e),this.anchorIndex=t,!0;if(o&&this.selectedIds.has(e))return this.selectedIds.delete(e),this.anchorIndex===t&&(this.anchorIndex=-1),!0;if(this.mode===`multiple`&&o){let n=!this.selectedIds.has(e);return this.selectedIds.add(e),this.anchorIndex=t,n}let s=this.selectedIds.size!==1||!this.selectedIds.has(e);return this.selectedIds.clear(),this.selectedIds.add(e),this.anchorIndex=t,s}selectRangeBetween(e,t,n,r){let i=Math.min(e,t),a=Math.max(e,t),o=new Set;if(r){let{rowCount:e,getAllRowIdAt:t}=r;for(let r=0;r<e;r++){let e=t(r);if(!e)continue;let s=n(r),c=r>=i&&r<=a;if(s){c&&o.add(s);continue}this.selectedIds.has(e)&&o.add(e)}}else for(let e=i;e<=a;e++){let t=n(e);t&&o.add(t)}let s=o.size!==this.selectedIds.size||[...o].some(e=>!this.selectedIds.has(e));return this.selectedIds=o,s}isAllVisibleRowsSelected(e,t){if(e===0)return!1;for(let n=0;n<e;n++){let e=t(n);if(e&&!this.selectedIds.has(e))return!1}return!0}selectAllVisibleRows(e,t){let n=!1;for(let r=0;r<e;r++){let e=t(r);e&&!this.selectedIds.has(e)&&(this.selectedIds.add(e),n=!0)}return n&&e>0&&(this.anchorIndex=0),n}deselectAllVisibleRows(e,t){let n=!1;for(let r=0;r<e;r++){let e=t(r);e&&this.selectedIds.delete(e)&&(n=!0)}return n}replaceSelectionWithVisibleRows(e,t){return this.selectAllVisibleRows(e,t)}toggleSelectAllVisibleRows(e,t){return this.isAllVisibleRowsSelected(e,t)?this.deselectAllVisibleRows(e,t):this.selectAllVisibleRows(e,t)}replaceWithRowIds(e,t=-1){let n=new Set(e),r=n.size!==this.selectedIds.size||[...n].some(e=>!this.selectedIds.has(e));return this.selectedIds=n,this.anchorIndex=t,r}addRowId(e,t=-1){if(this.mode===`single`){let n=this.selectedIds.size!==1||!this.selectedIds.has(e);return this.selectedIds.clear(),this.selectedIds.add(e),this.anchorIndex=t,n}return!this.selectedIds.has(e)&&(this.selectedIds.add(e),t>=0&&(this.anchorIndex=t),!0)}toggleRowId(e,t){return this.selectedIds.has(e)?this.removeRowIds([e]):this.addRowId(e,t)}},Mr=()=>!0;function Nr(e){return e??Mr}function Pr(e,t,n){return e({data:t.data,rowId:xr(t,n),rowIndex:t.rowIndex})}var Fr=class extends jr{getFocusedRowIds(){return this.getSelectedRowIds()}};function Ir(e,t){return e===t}function Lr(e,t,n){return e.length===0||!Ir(t,n)?[]:[...e]}function Rr(e){let t=[],n=[],r=[];return e.forEach((e,i)=>{let a=e.fixed??null;a===`left`?t.push(i):a===`right`?r.push(i):n.push(i)}),{left:t,center:n,right:r}}function zr(e){let t=[],n=[],r=[];return e.forEach((e,i)=>{if(e.hidden)return;let a=e.fixed??null;a===`left`?t.push(i):a===`right`?r.push(i):n.push(i)}),{left:t,center:n,right:r}}function Br(e){return L(e)||R(e)}function q(e){return e.fixed??null}function Vr(e){for(let t=0;t<e.length;t++){let n=e[t];if(!(!n||q(n)!==`left`)&&!Br(n.colId))return t}return e.length}function Hr(e){for(let t=0;t<e.length;t++){let n=e[t];if(!n||q(n)!==`left`||!Br(n.colId))return t}let t=0;for(let n of e){if(q(n)!==`left`)break;t+=1}return t}function Ur(e,t,n){let r=e[t];return r?q(r)===n:!1}function Wr(e,t,n){if(n!==void 0)return n;if(t>=e.length)return`right`;let r=e[t];return r?q(r):null}function Gr(e,t,n){return n===`left`?Hr(e):n===`right`?e.length:t.center.length>0?t.center[0]:t.left.length>0?t.left[t.left.length-1]+1:Vr(e)}function Kr(e,t,n){if(n===`left`)return t.center.length>0?t.center[0]:t.right.length>0?t.right[0]:e.length;if(n===`right`)return e.length;if(t.center.length>0){let n=t.center[t.center.length-1];if(t.right.length>0){let r=t.right[0];return r>n?r:Math.min(n+1,e.length-1)}return e.length}return t.right.length>0?t.right[0]:e.length}function qr(e){let{columns:t,colId:n,toGlobalIndex:r,toFixed:i}=e;if(r<0||r>t.length)return!1;let a=t.findIndex(e=>e.colId===n);if(a<0||a===r||Br(n))return!1;let o=t[a];if(!o?.movable)return!1;let s=q(o),c=Wr(t,r,i);if(r<t.length){let e=t[r];if(!e||Br(e.colId))return!1}else if(i===void 0)return!1;if(s===c)return r===t.length||s===`left`&&r<Vr(t)?!1:Ur(t,r,s);if(e.allowCrossLaneColumnMove!==!0)return!1;if(c===`left`){let e=s===c?Vr(t):Hr(t);if(r<t.length&&r<e)return!1}return!0}function Jr(e,t,n,r){return e.findIndex(e=>e.colId===t)<0?null:Wr(e,n,r)}function Yr(e){if(!qr(e))return null;let t=e.columns.map(e=>e.colId),n=t.indexOf(e.colId);return n<0?null:e.toGlobalIndex===e.columns.length?(t.splice(n,1),t.push(e.colId),t):(t.splice(n,1),t.splice(e.toGlobalIndex,0,e.colId),t)}function Xr(e){let t=e.columns.findIndex(t=>t.colId===e.colId);if(t<0)return null;let n=e.direction===`right`?t+1:t-1;if(!qr({...e,toGlobalIndex:n}))return null;let r=e.columns[t],i=e.columns[n];return!r||!i||q(r)!==q(i)?null:n}function Zr(e){let t=e.leftFixedWidth+e.centerTotalWidth;return e.laneIndices.map(n=>{let r=e.columns[n];if(!r||Br(r.colId)||r.colId===e.sourceColId)return null;let i=e.targetFixed===`right`?r.left-t:r.left;return{colId:r.colId,globalIndex:n,left:i,width:r.width}}).filter(e=>e!=null)}function Qr(e){let t=e.laneHeaderCells.filter(t=>{let n=e.columns[t.globalIndex];return n&&t.colId!==e.sourceColId&&!Br(t.colId)&&q(n)===e.targetFixed});if(t.length===0)return e.clientX<e.laneRectLeft||e.clientX>e.laneRectRight?null:{globalIndex:Gr(e.columns,e.fixedGroups,e.targetFixed),toFixed:e.targetFixed};for(let n of t)if(e.clientX<n.rectLeft+n.rectWidth/2)return{globalIndex:n.globalIndex};let n=Kr(e.columns,e.fixedGroups,e.targetFixed);return e.targetFixed===`right`&&n===e.columns.length&&e.fixedGroups.right.length===0?{globalIndex:n,toFixed:`right`}:{globalIndex:n}}function $r(e){let t=e.targetFixed===`left`?e.fixedGroups.left:e.targetFixed===`right`?e.fixedGroups.right:e.fixedGroups.center,n=Zr({columns:e.columns,laneIndices:t,targetFixed:e.targetFixed,leftFixedWidth:e.leftFixedWidth,centerTotalWidth:e.centerTotalWidth,sourceColId:e.sourceColId});if(n.length===0)return e.clientX<e.laneRectLeft||e.clientX>e.laneRectRight?null:{globalIndex:Gr(e.columns,e.fixedGroups,e.targetFixed),toFixed:e.targetFixed};for(let t of n)if(e.sectionX<t.left+t.width/2)return{globalIndex:t.globalIndex};let r=Kr(e.columns,e.fixedGroups,e.targetFixed);return e.targetFixed===`right`&&r===e.columns.length&&e.fixedGroups.right.length===0?{globalIndex:r,toFixed:`right`}:{globalIndex:r}}function ei(e){return!L(e)&&!R(e)}function ti(e,t){return e.center.length>0?e.center[0]:e.right.length>0?e.right[0]:e.left.length>0?e.left[e.left.length-1]+1:t}function ni(e){if(!ei(e.colId))return null;let t=e.columns.find(t=>t.colId===e.colId);if(!t)return null;let n=q(t);return n===e.fixed?null:e.fixed===`left`?{toGlobalIndex:Kr(e.columns,e.fixedGroups,`left`),toFixed:`left`}:e.fixed===`right`?{toGlobalIndex:e.columns.length,toFixed:`right`}:n===`right`?{toGlobalIndex:e.fixedGroups.right[0]??e.columns.length,toFixed:null}:{toGlobalIndex:ti(e.fixedGroups,e.columns.length),toFixed:null}}var ri={left:`--align-h-left`,center:`--align-h-center`,right:`--align-h-right`},ii={top:`--align-v-top`,center:`--align-v-center`,bottom:`--align-v-bottom`},ai=[...Object.values(ri),...Object.values(ii)];function oi(e={}){return{headerAlign:e.headerAlign,headerValign:e.headerValign,align:e.align,valign:e.valign,footerAlign:e.footerAlign,footerValign:e.footerValign}}function si(e,t={}){return{headerAlign:e.headerAlign??t.headerAlign??`center`,headerValign:e.headerValign??t.headerValign??`center`,align:e.align??t.align??`center`,valign:e.valign??t.valign??`center`,footerAlign:e.footerAlign??t.footerAlign??`center`,footerValign:e.footerValign??t.footerValign??`center`}}function ci(e,t,n,r){for(let t of ai)e.classList.remove(`${r}${t}`);e.classList.add(`${r}${ri[t]}`),e.classList.add(`${r}${ii[n]}`)}var li=5,ui=50;function di(e={}){return{columnMovable:e.columnMovable??!0,suppressMoveWhenColumnDragging:e.suppressMoveWhenColumnDragging??!1,suppressColumnMoveAnimation:e.suppressColumnMoveAnimation??!1,allowCrossLaneColumnMove:e.allowCrossLaneColumnMove??!1}}function fi(e,t){return e!==!1&&t}function pi(e={}){return{resizable:e.resizable??!0,colResizeDefault:e.colResizeDefault??null}}function mi(e,t,n){return L(n)||R(n)?!1:e??t}function hi(e,t){return t===`shift`?!e:e}function gi(e,t,n,r,i){let a=e.map(e=>({colId:e.colId,width:t.getColumnWidth(e.colId)})),o=i&&i.length>0?i.map(e=>({colId:e,width:t.getColumnWidth(e)})):null;return{columns:a,column:a.length===1?a[0]??null:null,finished:n,flexColumns:o,source:r}}var _i=[`group`,`filter`,`sort`,`aggregate`,`map`],vi=[`tree`,`filter`,`sort`,`map`],yi=[`sort`,`filter`,`map`];function bi(e){switch(e){case`tree`:return vi;case`group`:return _i;default:return yi}}function xi(e){return`predicate`in e}function Si(e){return e!=null&&e.trim()!==``}function Ci(e){return Mi(e.type)?!0:e.type===`inRange`?Si(e.filter)&&Si(e.filterTo):Si(e.filter)}function wi(e){return e?e.conditions&&e.conditions.length>0?e.conditions:[{type:e.type,filter:e.filter,filterTo:e.filterTo}]:[]}function Ti(e){return e.operator??`AND`}function Ei(e){return e?.setValues}function Di(e){return wi(e).some(Ci)}function Oi(e){return e.setValues!==void 0}function ki(e){return e??`text`}function Ai(e){return{caseSensitive:e?.caseSensitive??!0,locale:e?.locale}}function ji(e){return e!=null&&e.trim()!==``}function Mi(e){return e===`blank`||e===`notBlank`}function Ni(e){return e?xi(e)?!0:Di(e)||Oi(e):!1}function Pi(e,t){return Ni(t[e])}function Fi(e,t){if(ji(t))return!0;for(let t of Object.values(e))if(Ni(t))return!0;return!1}var Ii=`mg-row--span-top`;function Li(e={}){return{enableCellSpan:e.enableCellSpan??!1}}function Ri(e){return e}function zi(e){return!Number.isFinite(e)||e<1?1:Math.floor(e)}function Bi(e,t){if(!(L(t)||R(t)))return e}function Vi(e,t){if(!(L(t)||R(t)))return e}function Hi(e,t){if(!(L(t)||R(t)))return e}function Ui(e,t){return Bi(e.colSpan,t)}function Wi(e,t){return Vi(e.rowSpan,t)}function Gi(e,t){return Hi(e.spanRows,t)}function Ki(e,t){return e?`rowSpan`:t===!0||typeof t==`function`?`spanRows`:`none`}function qi(e){return e===!0||typeof e==`function`}var Ji=`mg-cell__row-resize-handle`,Yi=`mg-cell--row-resizing`,Xi=`mg-cell--auto-height`;function Zi(e={},t){let n=e.rowHeightMin??t,r=e.rowHeightMax??null;return{getRowHeight:e.getRowHeight,rowHeightMin:Math.max(1,n),rowHeightMax:r==null?null:Math.max(n,r)}}function Qi(e,t){return L(t)||R(t)?!1:e??!1}function $i(e,t){return Qi(e.autoHeight,t)}function ea(e,t,n){let r=Math.max(t,e);return n==null?r:Math.min(n,r)}function ta(e,t,n){return{rows:e.map(e=>({...e})),finished:t,source:n}}var na=`mg-cell__row-drag-handle`,ra=`mg-cell--row-dragging`,ia=`mg-row-drop-indicator`,aa=`mg-row-drag-ghost`,oa=`mg-row-dragging--drop-forbidden`,sa=`mg-row--row-drag-committing`,ca=`magic-grid--row-drag-committing`;function la(e={}){return{rowDragManaged:e.rowDragManaged??!0,rowDragCommitMode:e.rowDragCommitMode??`sync`}}function ua(e,t){return L(t)||R(t)?!1:e??!1}function da(e,t){return ua(e.rowDrag,t)}function fa(e,t,n=!1){return!n&&t&&e}function pa(e,t,n,r=!1){return e?!fa(t,n,r):!1}function J(e,t,n,r,i=!0,a){let o={rowId:e,fromIndex:t,toIndex:n,source:r,finished:i};return a?.displayIndex!==void 0&&(o.displayIndex=a.displayIndex),a?.parentRowId!==void 0&&(o.parentRowId=a.parentRowId),a?.siblingIndex!==void 0&&(o.siblingIndex=a.siblingIndex),a?.treeLevel!==void 0&&(o.treeLevel=a.treeLevel),o}function ma(e,t,n,r,i){return{rowId:e,rowIds:r&&r.length>1?[...r]:void 0,displayIndex:t,finished:n,...i?{parentRowId:i.parentRowId,siblingIndex:i.siblingIndex,treeLevel:i.treeLevel}:{}}}function ha(e){return{rowId:e.leaderRowId,rowIds:[...e.rowIds],leaderRowId:e.leaderRowId,displayIndex:e.displayIndex,parentRowId:e.treeDrop?.parentRowId,siblingIndex:e.treeDrop?.siblingIndex,treeLevel:e.treeDrop?.treeLevel}}function ga(e){return{commitId:e.commitId,rowId:e.leaderRowId,leaderRowId:e.leaderRowId,committed:e.committed,aborted:e.aborted,reason:e.reason}}function _a(e,t,n){return{signal:n.signal,commitId:n.commitId,rowIds:[...e.rowIds],leaderRowId:e.leaderRowId,moves:[...e.moves],displayIndex:e.displayIndex,parentRowId:e.treeDrop?.parentRowId===void 0?void 0:e.treeDrop.parentRowId===null?null:String(e.treeDrop.parentRowId),siblingIndex:e.treeDrop?.siblingIndex,treeLevel:e.treeDrop?.treeLevel,nestUnderRowId:t??void 0}}function va(e){return e.length===0?[]:[e[0]]}function ya(e={}){return va(e.defaultSort??[])}function ba(e={}){return{defaultSort:ya(e),sortable:e.sortable??!1,showUnsortedSortHintOnHover:e.showUnsortedSortHintOnHover??!1}}function xa(e,t,n){return L(n)||R(n)?!1:e??t}var Sa=`current`,Ca=`tree`;function wa(e={}){return{filterable:e.filterable??!1,filterSetValueMode:e.filterSetValueMode??`current`,filterSetDateLayoutMode:e.filterSetDateLayoutMode??`tree`}}function Ta(e,t,n){return L(n)||R(n)||z(n)||V(n)?!1:e??t}var Ea=`overlay`;function Da(e){return e===`inline`?`inline`:Ea}function Oa(e,t){return L(e)||R(e)?Ea:Da(t)}function ka(e){return L(e.colId)||R(e.colId)||Da(e.cellEditorMode)!==`inline`?!1:e.cellEditor!=null}function Aa(e){return L(e)||R(e)||z(e)||ln(e)||V(e)}function ja(e,t){return!Aa(e)&&t.hidden===!0}function Ma(e){return!e.hidden}function Na(e){return e.filter(e=>Ma(e))}function Pa(e){return Na(e).length}function Fa(e){let t=[];for(let n of e)!n.hidden||Aa(n.colId)||t.push({colId:n.colId,label:n.label??n.prop??n.colId});return t}var Ia=`.mg-cell__text:not([hidden])`,La=`.mg-header-cell__text`,Ra=`.mg-footer-cell__text:not([hidden])`,za=[`.mg-status-bar__panel`,`[data-mg-tooltip-anchor]`].join(`, `),Ba=[Ia,La,Ra].join(`, `),Va=`mg-tooltip`;function Ha(e){return L(e)||R(e)||z(e)||ln(e)||V(e)}function Ua(e,t){return Ha(e)?!0:t.suppressTooltip===!0}function Wa(e={}){let t=e.enableTooltips??!0;return{enableTooltips:t,tooltipShowMode:e.tooltipShowMode??(t?`whenTruncated`:`never`),tooltipShowDelay:e.tooltipShowDelay??500,tooltipSwitchShowDelay:e.tooltipSwitchShowDelay??200,tooltipHideDelay:e.tooltipHideDelay??3e3,tooltipInteraction:e.tooltipInteraction??!1,tooltipMouseTrack:e.tooltipMouseTrack??!1,tooltipComponent:e.tooltipComponent,tooltipComponentParams:e.tooltipComponentParams}}function Ga(e){return e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight}function Ka(e){return!e.enableTooltips||e.mode===`never`||!e.text?!1:e.mode===`always`||!e.isAutoHeight&&Ga(e.anchorEl)}var qa={left:[],center:[],right:[]},Ja=class{columns=[];totalWidth=0;fixedGroups=qa;leftFixedWidth=0;rightFixedWidth=0;centerTotalWidth=0;gridAlignDefaults={};columnMovableDefault=!0;allowCrossLaneColumnMove=!1;gridResizableDefault=!0;gridSortableDefault=!1;gridFilterableDefault=!1;constructor(e=[],t={},n={},r={},i,a,o,s){this.gridAlignDefaults=r;let c=di(i);this.columnMovableDefault=c.columnMovable,this.allowCrossLaneColumnMove=c.allowCrossLaneColumnMove;let l=pi(a);this.gridResizableDefault=l.resizable,this.gridSortableDefault=ba(o).sortable,this.gridFilterableDefault=wa(s).filterable,this.setColumns(e,t,n)}setColumns(e,t={},n={},r,i,a,o,s){if(r!==void 0&&(this.gridAlignDefaults=r),i!==void 0){let e=di(i);this.columnMovableDefault=e.columnMovable,this.allowCrossLaneColumnMove=e.allowCrossLaneColumnMove}a!==void 0&&(this.gridResizableDefault=pi(a).resizable),o!==void 0&&(this.gridSortableDefault=ba(o).sortable),s!==void 0&&(this.gridFilterableDefault=wa(s).filterable);let c=pt(e),l=this.columns.map(e=>e.colId),u=new Map(this.columns.map(e=>[e.colId,e])),d=c.map((e,r)=>{let i=this.parseColumn(e,r,t,n),a=u.get(i.colId);return a&&(a.defHidden===i.defHidden&&(i.hidden=a.hidden),a.defWidth===i.defWidth&&a.defFlex===i.defFlex&&(i.width=a.width,i.flex=a.flex),a.defFixed===i.defFixed&&(i.fixed=a.fixed)),i});if(l.length===0)this.columns=d;else{let e=new Map(d.map(e=>[e.colId,e])),t=[],n=new Set;for(let r of l){let i=e.get(r);i&&(t.push(i),n.add(r))}for(let e of d)n.has(e.colId)||t.push(e);this.columns=t}this.rebuildDisplayedLayout()}setColumnsHidden(e,t){let n=[];for(let r of e){if(Aa(r))continue;let e=this.columns.find(e=>e.colId===r);!e||e.hidden===t||(e.hidden=t,n.push(r))}return n.length>0&&this.rebuildDisplayedLayout(),n}isColumnHidden(e){return this.getColumnById(e)?.hidden}getDisplayedColumnIds(){return Na(this.columns).map(e=>e.colId)}getDisplayedColumnIdsInLaneOrder(){let e=[],t=new Set,{left:n,center:r,right:i}=this.fixedGroups;for(let a of[...n,...r,...i]){let n=this.columns[a];!n||n.hidden||t.has(n.colId)||(t.add(n.colId),e.push(n.colId))}return e}rebuildDisplayedLayout(){this.fixedGroups=zr(this.columns),this.positionColumns()}setColumnMoveGridOptions(e){this.columnMovableDefault=e.columnMovable,this.allowCrossLaneColumnMove=e.allowCrossLaneColumnMove;for(let e of this.columns){if(L(e.colId)||R(e.colId)||z(e.colId)){e.movable=!1;continue}e.movable=fi(e.defMovable,this.columnMovableDefault)}}setColumnResizeGridOptions(e){this.gridResizableDefault=e.resizable;for(let e of this.columns){if(L(e.colId)||R(e.colId)||z(e.colId)){e.resizable=!1;continue}e.resizable=mi(e.defResizable,this.gridResizableDefault,e.colId)}}setColumnSortGridOptions(e){this.gridSortableDefault=e.sortable;for(let e of this.columns){if(L(e.colId)||R(e.colId)||z(e.colId)||V(e.colId)){e.sortable=!1;continue}e.sortable=xa(e.defSortable,this.gridSortableDefault,e.colId)}}setColumnFilterGridOptions(e){this.gridFilterableDefault=e.filterable;for(let e of this.columns){if(L(e.colId)||R(e.colId)||z(e.colId)||V(e.colId)){e.filterable=!1;continue}e.filterable=Ta(e.defFilterable,this.gridFilterableDefault,e.colId)}}getColumnCount(){return this.columns.length}getColumn(e){return this.columns[e]}getColumnById(e){return this.columns.find(t=>t.colId===e)}getColAfter(e){let t=Na(this.columns),n=t.findIndex(t=>t.colId===e);if(!(n<0||n>=t.length-1))return t[n+1]}getColumnWidth(e){return this.getColumnById(e)?.width??100}getColumnInitialWidth(e){return this.getColumnById(e)?.initialWidth??100}getTotalWidth(){return this.totalWidth}getColumns(){return this.columns}getDisplayedColumns(){return Na(this.columns)}getDisplayedColumnCount(){return Pa(this.columns)}getFixedColumnGroups(){return this.fixedGroups}getLeftFixedColumnIndices(){return this.fixedGroups.left}getRightFixedColumnIndices(){return this.fixedGroups.right}getCenterColumnIndices(){return this.fixedGroups.center}getLeftFixedWidth(){return this.leftFixedWidth}getRightFixedWidth(){return this.rightFixedWidth}getCenterTotalWidth(){return this.centerTotalWidth}isFixedColumn(e){let t=this.columns[e];return t?.fixed===`left`||t?.fixed===`right`}setColumnWidth(e,t){this.applyColumnWidthChanges([{colId:e,width:t}])}applyColumnWidthChanges(e,t){let n=!1,r=t?.widthSource!==`flex`;for(let t of e){let e=this.columns.find(e=>e.colId===t.colId);if(!e)continue;r&&e.flex!=null&&(e.flex=null);let i=Ya(t.width,e.minWidth,e.maxWidth);e.width!==i&&(e.width=i,n=!0)}return n&&this.positionColumns(),n}hasFlexColumns(){return this.columns.some(e=>!e.hidden&&e.flex!=null&&e.flex>0&&e.fixed!==`left`&&e.fixed!==`right`)}reorderColumns(e){if(e.length!==this.columns.length)return!1;let t=new Map(this.columns.map(e=>[e.colId,e])),n=[];for(let r of e){let e=t.get(r);if(!e)return!1;n.push(e)}return this.columns=n,this.rebuildDisplayedLayout(),!0}resetColumnsOrder(e){return this.reorderColumns(e)}resetColumnsWidth(){let e=[];for(let t of this.columns){if(Aa(t.colId))continue;let n=!1,r=Ya(t.defWidth,t.minWidth,t.maxWidth);t.width!==r&&(t.width=r,n=!0),t.flex!==t.defFlex&&(t.flex=t.defFlex,n=!0),n&&e.push(t.colId)}return e.length>0&&this.positionColumns(),e}moveColumn(e,t,n){let r=Jr(this.columns,e,t,n),i=Yr({columns:this.columns,colId:e,toGlobalIndex:t,fixedGroups:this.fixedGroups,toFixed:n,allowCrossLaneColumnMove:this.allowCrossLaneColumnMove});if(!i)return!1;let a=this.columns.find(t=>t.colId===e);return a&&q(a)!==r&&(a.fixed=r),this.reorderColumns(i)}setColumnFixed(e,t){let n=ni({columns:this.columns,fixedGroups:this.fixedGroups,colId:e,fixed:t});if(!n)return!1;let r=this.columns.findIndex(t=>t.colId===e);if(r<0)return!1;let i=this.columns[r];if(r===n.toGlobalIndex)return i.fixed=n.toFixed,this.rebuildDisplayedLayout(),!0;let a=Yr({columns:this.columns,colId:e,toGlobalIndex:n.toGlobalIndex,fixedGroups:this.fixedGroups,toFixed:n.toFixed,allowCrossLaneColumnMove:!0});return a?(i.fixed=Jr(this.columns,e,n.toGlobalIndex,n.toFixed),this.reorderColumns(a)):!1}parseColumn(e,t,n,r){let i=e.key??e.prop??`col_${t}`,a=e.minWidth??50,o=Ya(e.width??100,a,e.maxWidth),s=si(e,this.gridAlignDefaults),c=L(i)||R(i)||z(i)||V(i),l=e.fixed===`left`||e.fixed===`right`,u=!c&&!l&&e.flex!=null&&e.flex>0?e.flex:null;return e.cellEditorMode,e.cellEditor??r[i],e.cellEditorMode,e.cellEditor??r[i],{colId:i,prop:e.prop,label:e.label,width:o,initialWidth:o,minWidth:a,maxWidth:e.maxWidth,flex:u,suppressSizeToFit:c?!0:e.suppressSizeToFit??!1,left:0,fixed:e.fixed??null,sortable:!c&&xa(e.sortable,this.gridSortableDefault,i),filterable:!c&&Ta(e.filterable,this.gridFilterableDefault,i),filterType:ki(c?void 0:e.filterType),filterParams:Ai(c?void 0:e.filterParams),filterFormatter:c?void 0:e.filterFormatter,comparator:e.comparator,defMovable:c?void 0:e.movable,movable:!c&&fi(e.movable,this.columnMovableDefault),defResizable:c?void 0:e.resizable,defSortable:c?void 0:e.sortable,defFilterable:c?void 0:e.filterable,resizable:mi(!c&&e.resizable,this.gridResizableDefault,i),suppressAutoSize:c?!0:e.suppressAutoSize??!1,valueGetter:e.valueGetter,formatter:e.formatter,editable:e.editable,cellRenderer:e.cellRenderer??n[i],cellRendererMount:c?void 0:e.cellRendererMount,cellEditor:e.cellEditor??r[i],cellEditorMode:Oa(i,e.cellEditorMode),valueParser:e.valueParser,valueSetter:e.valueSetter,editType:e.editType,cellValidator:e.cellValidator,suppressPaste:c?!0:e.suppressPaste,useParserForClipboard:e.useParserForClipboard,useFormatterForClipboard:e.useFormatterForClipboard,validationRequired:e.validationRequired,summary:e.summary,summaryAgg:e.summaryAgg,summaryFormatter:e.summaryFormatter,autoHeight:$i(e,i),rowDrag:da(e,i),rowExpand:it(e,i),rowGroup:Ot(e,i),rowGroupIndex:kt(e,i),groupAgg:At(e,i),showGroupHeaderCell:jt(e,i),showGroupFooterCell:Mt(e,i),groupFooterLabel:Nt(e,i),suppressCellComments:c?!0:e.suppressCellComments,disabled:!c&&e.disabled,cellDisabled:c?void 0:e.cellDisabled,cellStyle:c?void 0:e.cellStyle,defWidth:o,defFlex:u,defFixed:c?null:e.fixed??null,defHidden:!c&&e.hidden===!0,defOrder:t,hidden:ja(i,e),tooltipField:c?void 0:e.tooltipField,tooltipValueGetter:c?void 0:e.tooltipValueGetter,headerTooltip:c?void 0:e.headerTooltip,headerTooltipValueGetter:c?void 0:e.headerTooltipValueGetter,suppressTooltip:Ua(i,e),tooltipComponent:c?void 0:e.tooltipComponent,tooltipComponentParams:c?void 0:e.tooltipComponentParams,colSpan:Ui(e,i),rowSpan:Wi(e,i),spanRows:Gi(e,i),...s}}hasAutoHeightColumns(){return this.columns.some(e=>e.autoHeight)}isColumnAutoHeight(e){return this.getColumnById(e)?.autoHeight??!1}getAutoHeightColumnIds(){return this.columns.filter(e=>e.autoHeight).map(e=>e.colId)}positionColumns(){this.leftFixedWidth=0,this.centerTotalWidth=0,this.rightFixedWidth=0;for(let e of this.fixedGroups.left){let t=this.columns[e];!t||t.hidden||(t.left=this.leftFixedWidth,t.rightOffset=void 0,this.leftFixedWidth+=t.width)}let e=0;for(let t of this.fixedGroups.center){let n=this.columns[t];!n||n.hidden||(n.left=e,n.rightOffset=void 0,e+=n.width)}this.centerTotalWidth=e;let t=this.leftFixedWidth+this.centerTotalWidth;for(let e of this.fixedGroups.right){let n=this.columns[e];!n||n.hidden||(n.left=t,t+=n.width,this.rightFixedWidth+=n.width)}let n=0;for(let e=this.fixedGroups.right.length-1;e>=0;e--){let t=this.fixedGroups.right[e],r=t===void 0?void 0:this.columns[t];!r||r.hidden||(r.rightOffset=n,n+=r.width)}this.totalWidth=this.leftFixedWidth+this.centerTotalWidth+this.rightFixedWidth}};function Ya(e,t,n){let r=Math.max(e,t);return n!==void 0&&(r=Math.min(r,n)),r}function Xa(e,t,n){if(e.length===0)return-1;let r=document.createElement(`form`);r.style.position=`fixed`,r.style.visibility=`hidden`,r.style.pointerEvents=`none`,r.style.top=`0`,r.style.left=`0`;for(let t of e)eo(t,r);t.appendChild(r);let i=r.offsetWidth+n;return r.remove(),i}function Za(e,t,n){let r=[];if(!n){let n=e.querySelector(`.mg-header-cell[data-col-id="${Qa(t)}"]`);n&&r.push(n)}return e.querySelectorAll(`.mg-cell[data-col-id="${Qa(t)}"]`).forEach(e=>{e instanceof HTMLElement&&r.push(e)}),r}function Qa(e){return typeof CSS<`u`&&typeof CSS.escape==`function`?CSS.escape(e):e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function $a(e,t,n,r){let i=e.querySelector(`.mg-viewport`);if(!i)return-1;let a=Za(e,t,n);return a.length===0?-1:Xa(a,i,r)}function eo(e,t){let n=e.cloneNode(!0);n.style.width=``,n.style.minWidth=``,n.style.maxWidth=``,n.style.left=``,n.style.right=``,n.style.position=`static`;let r=document.createElement(`div`);to(e,r),r.append(n),t.append(r)}function to(e,t){(e.classList.contains(`mg-header-cell`)||e.classList.contains(`mg-cell`)||e.classList.contains(`mg-footer-cell`))&&t.classList.add(`mg-row`);let n=e.parentElement;for(;n;){if(n.classList.contains(`mg-row`)||n.classList.contains(`mg-header-row`)||n.classList.contains(`mg-header-lane`)||n.classList.contains(`mg-body-lane`)){for(let e of n.classList)e!==`mg-row-position-absolute`&&t.classList.add(e);break}n=n.parentElement}}function no(e){return e.reduce((e,t)=>e+t.width,0)}function ro(e,t,n={}){if(t<=0)return[];let r=Object.fromEntries((n.columnLimits??[]).map(({colId:e,minWidth:t,maxWidth:n})=>[e,{minWidth:t,maxWidth:n}])),i=n.colIds?new Set(n.colIds):null,a=[],o=[];for(let t of e.getColumns()){if(t.hidden){o.push({colId:t.colId,width:t.width,minWidth:t.minWidth,maxWidth:t.maxWidth??2**53-1});continue}if(L(t.colId)||R(t.colId)){o.push({colId:t.colId,width:t.width,minWidth:t.minWidth,maxWidth:t.maxWidth??2**53-1});continue}let s=r[t.colId]??{},c=Math.max(t.minWidth,s.minWidth??n.defaultMinWidth??t.minWidth),l=Math.min(t.maxWidth??2**53-1,s.maxWidth??n.defaultMaxWidth??t.maxWidth??2**53-1),u={colId:t.colId,width:e.getColumnInitialWidth(t.colId),minWidth:c,maxWidth:l};if(t.suppressSizeToFit){u.width=t.width,o.push(u);continue}if(i&&!i.has(t.colId)){u.width=t.width,o.push(u);continue}a.push(u)}if(a.length===0||n.onlyScaleUp&&no(a)+no(o)>=t)return[];let s=new Map(a.map(t=>[t.colId,e.getColumnWidth(t.colId)])),c=a.map(e=>e.colId),l=!1;for(;!l;){l=!0;let e=t-no(o);if(e<=0){for(let e of a)e.width=e.minWidth;break}let n=no(a);if(n<=0)break;let r=e/n,i=e;for(let e=a.length-1;e>=0;e--){let t=a[e],n=e===0?i:Math.round(t.width*r);n<t.minWidth?(n=t.minWidth,o.push(t),a.splice(e,1),l=!1):n>t.maxWidth&&(n=t.maxWidth,o.push(t),a.splice(e,1),l=!1),t.width=n,i-=n}}let u=e=>a.find(t=>t.colId===e)?.width??o.find(t=>t.colId===e)?.width,d=[];for(let t of c){let n=u(t);n!=null&&(s.get(t)??e.getColumnWidth(t))!==n&&d.push({colId:t,newWidth:n})}return d}var io=class{mountEl;columnModel;autosizeOptions;constructor(e,t,n){this.mountEl=e,this.columnModel=t,this.autosizeOptions=n}setAutosizeOptions(e){this.autosizeOptions=e}getAutoSizeStrategy(){return this.autosizeOptions.autoSizeStrategy}autoSizeColumn(e,t){let n=this.columnModel.getColumnById(e);if(!n?.resizable||n.suppressAutoSize||L(e)||R(e))return null;let r=t??this.autosizeOptions.skipHeaderOnAutoSize,i=$a(this.mountEl,e,r,this.autosizeOptions.autoSizePadding);return i<=0?null:{colId:e,newWidth:ao(n.minWidth,n.maxWidth,i)}}autoSizeColumns(e,t){let n=[];for(let r of e){let e=this.autoSizeColumn(r,t);e&&n.push(e)}return n}autoSizeAllColumns(e){let t=this.columnModel.getColumns().filter(e=>e.resizable&&!e.suppressAutoSize&&!L(e.colId)&&!R(e.colId)).map(e=>e.colId);return this.autoSizeColumns(t,e)}sizeColumnsToFit(e,t={}){return ro(this.columnModel,e,t)}buildFitWidthStrategyParams(e,t){return{gridWidth:e.type===`fitProvidedWidth`?e.width:t,defaultMinWidth:e.defaultMinWidth,defaultMaxWidth:e.defaultMaxWidth,columnLimits:e.columnLimits}}buildFitCellContentsChanges(e){let t=e.skipHeader??this.autosizeOptions.skipHeaderOnAutoSize,n=e.colIds??this.columnModel.getColumns().filter(e=>e.resizable&&!e.suppressAutoSize&&!L(e.colId)&&!R(e.colId)).map(e=>e.colId),r=Object.fromEntries((e.columnLimits??[]).map(({colId:e,minWidth:t,maxWidth:n})=>[e,{minWidth:t,maxWidth:n}])),i=[];for(let a of n){let n=this.columnModel.getColumnById(a);if(!n)continue;let o=r[a]??{},s=this.autoSizeColumn(a,t);if(!s)continue;let c=Math.max(n.minWidth,o.minWidth??e.defaultMinWidth??n.minWidth),l=Math.min(n.maxWidth??2**53-1,o.maxWidth??e.defaultMaxWidth??n.maxWidth??2**53-1);i.push({colId:a,newWidth:ao(c,l===2**53-1?void 0:l,s.newWidth)})}return!e.scaleUpToFitGridWidth||i.length===0?{contentChanges:i}:{contentChanges:i,scaleUpParams:{colIds:i.map(e=>e.colId),defaultMinWidth:e.defaultMinWidth,defaultMaxWidth:e.defaultMaxWidth,columnLimits:e.columnLimits,onlyScaleUp:!0}}}};function ao(e,t,n){let r=Math.max(n,e);return t!==void 0&&(r=Math.min(r,t)),r}function oo(e,t){if(e.length===0||t<=0)return 0;let n=e[e.length-1];if(t>=n.left+n.width)return e.length-1;let r=0,i=e.length-1;for(;r<i;){let n=Math.ceil((r+i)/2);e[n].left<=t?r=n:i=n-1}return r}function so(e,t){if(e.length===0)return 0;let n=0,r=e.length-1;for(;n<r;){let i=Math.floor((n+r)/2),a=e[i];a.left+a.width<=t?n=i+1:r=i}return n}function co(e,t){return Math.max(0,e-t)}function lo(e,t,n){let r=Math.max(0,t-n);return Math.max(0,Math.min(e,r))}function uo(e,t,n){return Math.max(0,e-t-n)}function fo(e){let t=e.getCenterColumnIndices(),n=e.getColumns();return{centerIndices:t,centerColumns:t.map(e=>n[e]).filter(e=>e!==void 0)}}function po(e){let{scrollLeft:t,viewportWidth:n,columnModel:r,margin:i=200}=e,{centerIndices:a,centerColumns:o}=fo(r),s=r.getLeftFixedWidth(),c=r.getRightFixedWidth();if(o.length===0)return{window:{firstCol:0,lastCol:-1},centerScrollLeft:co(t,s)};let l=r.getCenterTotalWidth(),u=uo(n,s,c),d=lo(t,l,u),f=Math.max(0,d-i),p=Math.min(d+u+i,l+i),m=so(o,f),h=oo(o,p);return h=Math.min(h,o.length-1),h<m?{window:{firstCol:0,lastCol:-1},centerScrollLeft:d}:{window:{firstCol:a[m],lastCol:a[h]},centerScrollLeft:d}}var mo=class{columnModel;flexViewportWidth=0;constructor(e){this.columnModel=e}resolveCenterViewportWidth(e){return uo(e,this.columnModel.getLeftFixedWidth(),this.columnModel.getRightFixedWidth())}refreshFlexedColumns(e){let t=e.viewportWidth;this.flexViewportWidth=t;let n=this.getCenterColumns();if(n.length===0||t<=0)return{changed:!1,changedColIds:[],flexColIds:[]};let r=-1;if(e.resizingColIds&&e.resizingColIds.length>0){let t=new Set(e.resizingColIds);for(let e=n.length-1;e>=0;e--){let i=n[e];if(i&&t.has(i.colId)){r=e;break}}}let i=!1,a=n.map((e,t)=>{let n=e.flex??0,a=n>0&&t>r;return i||=a,{colId:e.colId,column:e,isFlex:a,flex:Math.max(0,n),initialSize:e.width,min:e.minWidth,max:e.maxWidth??2**53-1,targetSize:0}});if(!i)return{changed:!1,changedColIds:[],flexColIds:[]};let o=a.length,s=a.reduce((e,t)=>e+t.flex,0),c=t,l=(e,t)=>{e.frozenSize=t,c-=t,s-=e.flex,--o},u=e=>e.frozenSize!=null;for(let e of a)e.isFlex||l(e,e.initialSize);for(;o>0;){let e=Math.round(s<1?c*s:c),t,n=0,r=0;for(let i of a){if(u(i))continue;t=i,r+=e*(i.flex/s);let a=r-n,o=Math.round(a);i.targetSize=o,n+=o}t&&(t.targetSize+=e-n);let i=0;for(let e of a){if(u(e))continue;let t=e.targetSize,n=Math.min(Math.max(t,e.min),e.max);i+=n-t,e.violationType=n===t?void 0:n<t?`max`:`min`,e.targetSize=n}let o=i===0?`all`:i>0?`min`:`max`;for(let e of a)u(e)||(o===`all`||e.violationType===o)&&l(e,e.targetSize)}let d=[],f=[],p=[];for(let e of a){let t=e.frozenSize;t!=null&&t!==e.initialSize&&(d.push({colId:e.colId,width:t}),f.push(e.colId),e.isFlex&&p.push(e.colId))}return d.length===0?{changed:!1,changedColIds:[],flexColIds:[]}:(this.columnModel.applyColumnWidthChanges(d,{widthSource:`flex`}),{changed:!0,changedColIds:f,flexColIds:p})}getStoredViewportWidth(){return this.flexViewportWidth}getCenterColumns(){let e=this.columnModel.getCenterColumnIndices(),t=this.columnModel.getColumns();return e.map(e=>t[e]).filter(e=>e!==void 0)}};function ho(e,t,n,r){let i=hi(n,r.colResizeDefault),a=[],o=[];for(let n of t){let t=e.getColumnById(n.colId);if(!t?.resizable)continue;let r=yo(t,n.newWidth);if(a.push({width:r,ratios:[1],colIds:[n.colId]}),o.push(n.colId),i){let i=e.getColAfter(n.colId);if(!i?.resizable)continue;let s=t.width-r,c=i.width+s;a.push({width:c,ratios:[1],colIds:[i.colId]}),o.includes(i.colId)||o.push(i.colId)}}return{sets:a,affectedColIds:o}}var go=class{columnModel;syncLayout;columnFlexService;getCenterViewportWidth;constructor(e,t,n,r){this.columnModel=e,this.syncLayout=t,this.columnFlexService=n,this.getCenterViewportWidth=r}setColumnWidths(e,t,n,r,i){let{sets:a,affectedColIds:o}=ho(this.columnModel,e,t,i);return a.length===0?{changed:!1,affectedColIds:[],flexColIds:[]}:this.resizeColumnSets({resizeSets:a,finished:n,source:r,affectedColIds:o})}resizeColumnSets(e){let{resizeSets:t,affectedColIds:n}=e;if(!t.every(e=>_o(this.columnModel,e)))return{changed:!1,affectedColIds:n,flexColIds:[]};let r=[];for(let e of t){let t=vo(this.columnModel,e);for(let[e,n]of Object.entries(t)){let t=r.find(t=>t.colId===e);t?t.width=n:r.push({colId:e,width:n})}}let i=r.filter(e=>this.columnModel.getColumnById(e.colId)?.resizable),a=this.columnModel.applyColumnWidthChanges(i,{widthSource:`manual`});a&&this.syncLayout();let o=[];if(this.columnFlexService&&this.getCenterViewportWidth&&this.columnModel.hasFlexColumns()){let e=this.columnFlexService.refreshFlexedColumns({viewportWidth:this.getCenterViewportWidth(),resizingColIds:n});o=e.flexColIds,e.changed&&this.syncLayout()}return{changed:a||o.length>0,affectedColIds:n,flexColIds:o}}};function _o(e,t){let n=0,r=0,i=!0;for(let a of t.colIds){let t=e.getColumnById(a);if(!t)return!1;n+=t.minWidth,t.maxWidth===void 0?i=!1:r+=t.maxWidth}return t.width>=n&&(!i||t.width<=r)}function vo(e,t){let{colIds:n,width:r,ratios:i}=t,a=Object.create(null),o=Object.create(null),s=!0,c=0;for(;s&&(c++,!(c>1e3));){s=!1;let t=[],c=0,l=r;n.forEach((e,n)=>{o[e]?l-=a[e]??0:(t.push(e),c+=i[n]??1)});let u=c>0?1/c:1;t.forEach((c,d)=>{let f=e.getColumnById(c);if(!f)return;let p=d===t.length-1,m;if(p)m=l;else{let e=n.indexOf(c),t=i[e]??1;m=Math.round(t*r*u),l-=m}let h=f.minWidth,g=f.maxWidth;m<h?(m=h,o[c]=!0,s=!0):g!==void 0&&m>g&&(m=g,o[c]=!0,s=!0),a[c]=m})}return a}function yo(e,t){let n=Math.max(t,e.minWidth);return e.maxWidth!==void 0&&(n=Math.min(n,e.maxWidth)),n}function bo(){return{key:Ke,label:``,width:40,minWidth:40,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!1,headerAlign:`center`,align:`center`,valign:`center`}}function xo(e={}){return{key:mt,label:`分组`,width:200,minWidth:120,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!0,headerAlign:`left`,align:`left`,valign:`center`,...e}}function So(e={}){return{key:en,label:`树`,width:200,minWidth:120,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!0,headerAlign:`left`,align:`left`,valign:`center`,...e}}function Co(e){return{key:je,label:e.label,width:e.width,minWidth:40,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!1,headerAlign:e.headerAlign,headerValign:e.headerValign,align:e.align,valign:e.valign,footerAlign:e.footerAlign,footerValign:e.footerValign}}function wo(e){return{key:ze,label:``,width:e.width,minWidth:40,fixed:`left`,sortable:!1,filterable:!1,editable:!1,resizable:!1,headerAlign:e.headerAlign,headerValign:e.headerValign,align:e.align,valign:e.valign,footerAlign:e.footerAlign,footerValign:e.footerValign}}function To(e,t,n=Ge(),r={}){let i=[];t.showIndexColumn&&i.push(Co(t.indexColumn)),n.enabled&&i.push(wo(n.selectionColumn));let a=r.rowExpansion;a?.masterDetail&&a.showExpandColumn&&i.push(bo());let o=r.treeTable;if(o&&dn(o.tree,o.showTreeColumn,o.getDataPath))i.push(So(o.autoTreeColumnDef??{}));else{let e=r.rowGrouping;e&&Rt(e.rowGrouping,e.showGroupColumn)&&i.push(xo(e.autoGroupColumnDef??{}))}return[...i,...e]}var Eo=class{columnModel;currentWindow={firstCol:0,lastCol:-1};centerScrollLeft=0;windowHash=``;constructor(e){this.columnModel=e}update(e,t){let{window:n,centerScrollLeft:r}=po({scrollLeft:e,viewportWidth:t,columnModel:this.columnModel}),i=this.computeHash(n),a=i!==this.windowHash;return this.currentWindow=n,this.centerScrollLeft=r,this.windowHash=i,a}getWindow(){return this.currentWindow}getCenterScrollLeft(){return this.centerScrollLeft}getState(){return{centerWindow:this.currentWindow,fixed:this.columnModel.getFixedColumnGroups(),centerScrollLeft:this.centerScrollLeft}}invalidate(){this.windowHash=``,this.currentWindow={firstCol:0,lastCol:-1},this.centerScrollLeft=0}computeHash(e){let t=this.columnModel.getColumns(),n=this.columnModel.getFixedColumnGroups(),r=`fixed:`;for(let e of n.left){let n=t[e];n&&(r+=`L${n.colId}:${n.width};`)}for(let e of n.right){let n=t[e];n&&(r+=`R${n.colId}:${n.width};`)}if(e.lastCol<e.firstCol)return`${r}|empty`;r+=`|${e.firstCol}:${e.lastCol}`;for(let n=e.firstCol;n<=e.lastCol;n++){let e=t[n];e&&(r+=`|${e.colId}:${e.width}:${e.left}`)}return r}},Do=new class{apply(e,t){if(e.replaceChildren(),typeof t==`string`){e.textContent=t;return}e.appendChild(t)}clear(e){e.replaceChildren()}},Oo=class{cachedValue=``;cachedRenderKey=``;cacheVersion=-1;refreshSummaryCell(e,t,n,r,i=!1){let a=typeof i==`boolean`?{force:i}:i,o=a.force??!1;if(e.cellRenderer)return this.refreshRendererCell(e,t,n,r,o,a.scheduleRenderer);let s=t.formattedValue;return!o&&this.cacheVersion===r&&this.cachedValue===s?!1:(n.clearRenderer(),this.cachedValue=s,this.cachedRenderKey=``,this.cacheVersion=r,n.setValue(s),!0)}invalidate(){this.cacheVersion=-1,this.cachedRenderKey=``}refreshRendererCell(e,t,n,r,i,a){let o=t.formattedValue,s=`${r}:summary:${e.colId}:${o}`;if(!i&&this.cacheVersion===r&&this.cachedRenderKey===s)return!1;this.cachedValue=o,this.cachedRenderKey=s,this.cacheVersion=r;let c={rowId:hn,rowIndex:-1,colId:e.colId,value:t.value,data:{},formattedValue:o,isSummaryRow:!0},l=()=>{this.applyRenderer(e,n,c)};return a?(a(l),!0):(l(),!0)}applyRenderer(e,t,n){let r=e.cellRenderer;if(!r)return;t.prepareForRenderer();let i=t.getRendererMountEl(),a=r(n,{mountEl:i,clear:()=>{t.clearRenderer()}});a!=null&&(typeof a==`string`||a instanceof HTMLElement)&&Do.apply(i,a)}};function ko(e,t){let n=t.getLeftFixedWidth(),r=t.getLeftFixedColumnIndices(),i=t.getRightFixedColumnIndices(),a=n+t.getCenterTotalWidth(),o=Mo(t,e.colId),s=o>=0&&o===t.getColumnCount()-1;if(e.fixed===`left`){let t=r[r.length-1];return{left:e.left,width:e.width,fixed:`left`,isLastLeftFixed:t!==void 0&&t===o,isLastColumn:s}}if(e.fixed===`right`){let t=i[0];return{left:e.left-a,width:e.width,fixed:`right`,isFirstRightFixed:t!==void 0&&t===o,isLastColumn:s}}let c=t.getCenterColumnIndices(),l=c[c.length-1];return{left:e.left,width:e.width,fixed:null,isLastCenter:i.length>0&&l!==void 0&&l===o,isLastColumn:s}}function Ao(e,t,n){e.style.width=`${t.width}px`,e.style.left=`${t.left}px`,e.style.removeProperty(`right`),e.style.removeProperty(`transform`),e.classList.remove(`${n}--fixed-left`,`${n}--fixed-right`,`${n}--fixed-left-last`,`${n}--center-last`,`${n}--column-last`,`${n}--fixed-right-first`),t.fixed===`left`?(e.classList.add(`${n}--fixed-left`),t.isLastLeftFixed&&e.classList.add(`${n}--fixed-left-last`)):t.fixed===`right`?(e.classList.add(`${n}--fixed-right`),t.isFirstRightFixed&&e.classList.add(`${n}--fixed-right-first`)):t.isLastCenter&&e.classList.add(`${n}--center-last`),t.isLastColumn&&e.classList.add(`${n}--column-last`)}function jo(e,t,n){e.querySelectorAll(`[data-col-id]`).forEach(e=>{if(!(e instanceof HTMLElement))return;let r=e.dataset.colId;if(!r)return;let i=t.getColumnById(r);i&&Ao(e,ko(i,t),n)})}function Mo(e,t){for(let n=0;n<e.getColumnCount();n++)if(e.getColumn(n)?.colId===t)return n;return-1}var No=class{element;textEl;rendererMount;onUnmountRenderer;usingRenderer=!1;constructor(e,t={}){this.onUnmountRenderer=t.onUnmountRenderer,this.element=document.createElement(`div`),this.element.className=`mg-footer-cell`,this.textEl=document.createElement(`span`),this.textEl.className=`mg-footer-cell__text`,this.rendererMount=document.createElement(`div`),this.rendererMount.className=`mg-footer-cell__renderer`,this.rendererMount.hidden=!0,this.element.append(this.textEl,this.rendererMount),e.appendChild(this.element)}setLayout(e,t){Ao(this.element,{left:e,width:t,fixed:null},`mg-footer-cell`)}setColumnLayout(e){Ao(this.element,e,`mg-footer-cell`)}setValue(e){this.clearRenderer(),this.textEl.hidden=!1,this.textEl.textContent!==e&&(this.textEl.textContent=e)}setRendererResult(e){this.prepareForRenderer(),Do.apply(this.rendererMount,e)}prepareForRenderer(){this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,this.rendererMount.hidden=!1,this.usingRenderer=!0}clearRenderer(){(this.usingRenderer||this.rendererMount.childNodes.length>0)&&this.onUnmountRenderer?.(this.rendererMount),Do.clear(this.rendererMount),this.rendererMount.hidden=!0,this.usingRenderer=!1}hasRenderer(){return this.usingRenderer}getRendererMountEl(){return this.rendererMount}setColId(e){this.element.dataset.colId=e}getColId(){return this.element.dataset.colId}getElement(){return this.element}destroy(){this.clearRenderer(),this.element.remove()}};function Po(e,t){return{rowId:e.id,rowIndex:e.rowIndex,data:e.data,colId:t.colId,isSummaryRow:!1,value:G(e,t)}}function Fo(e,t=null){return{rowId:hn,rowIndex:-1,data:null,colId:e.colId,isSummaryRow:!0,value:t}}function Io(e,t){let n=e[0];if(!n)return{left:0,width:0,fixed:null};let r=ko(n,t);if(r.width=Vo(e),e.length>1){let n=e[e.length-1],i=ko(n,t);r.isLastLeftFixed=i.isLastLeftFixed,r.isLastCenter=i.isLastCenter,r.isLastColumn=i.isLastColumn}return r}function Lo(e,t,n=`mg-cell`){let r=t>1;e.classList.toggle(`${n}--spanning`,r),e.classList.toggle(`${n}--col-span`,r),r?e.dataset.colSpan=String(t):delete e.dataset.colSpan}function Ro(e){if(!e.enableCellSpan)return 1;let{column:t,params:n}=e;if(L(t.colId)||R(t.colId))return 1;let r=t.colSpan;return r?zi(r(n)):1}function zo(e,t){let n=t.getColAfter(e.colId);if(n&&n.fixed===e.fixed&&!(L(n.colId)||R(n.colId)))return n}function Bo(e,t,n){let r=Ro({enableCellSpan:n.enableCellSpan,column:e,params:n.params}),i=[e],a=e;for(let e=1;e<r;e++){let e=zo(a,t);if(!e)break;i.push(e),a=e}return i}function Vo(e){let t=0;for(let n of e)t+=n.width;return t}function Ho(e){let{enableCellSpan:t,columnModel:n,columnIndices:r,paramsForColumn:i,filterCallback:a}=e,o=[],s=r.length;for(let e=0;e<s;){let s=r[e];if(s===void 0){e++;continue}let c=n.getColumn(s);if(!c){e++;continue}let l=Bo(c,n,{enableCellSpan:t,params:i(c)}),u=Uo(n,r,e,l),d=!0;if(a){d=!1;for(let t=0;t<u;t++){let i=r[e+t];if(i===void 0)continue;let o=n.getColumn(i);if(o&&a(o,i)){d=!0;break}}}d&&o.push(s),e+=Math.max(1,u)}return o}function Uo(e,t,n,r){let i=1;for(let a=1;a<r.length&&n+a<t.length;a++){let o=t[n+a];if(o===void 0)break;let s=e.getColumn(o),c=r[a];if(!s||!c||s.colId!==c.colId)break;i++}return i}function Wo(e,t){let n=[...e.getLeftFixedColumnIndices()],r=[...e.getRightFixedColumnIndices()],i=[];if(t.lastCol>=t.firstCol)for(let n of e.getCenterColumnIndices())n>=t.firstCol&&n<=t.lastCol&&i.push(n);return{left:n,center:i,right:r}}function Go(e){let{columnModel:t,centerWindow:n,enableCellSpan:r,paramsForColumn:i}=e;return r?{left:Ho({enableCellSpan:!0,columnModel:t,columnIndices:t.getLeftFixedColumnIndices(),paramsForColumn:i}),center:Ho({enableCellSpan:!0,columnModel:t,columnIndices:t.getCenterColumnIndices(),paramsForColumn:i,filterCallback:(e,t)=>n.lastCol>=n.firstCol&&t>=n.firstCol&&t<=n.lastCol}),right:Ho({enableCellSpan:!0,columnModel:t,columnIndices:t.getRightFixedColumnIndices(),paramsForColumn:i})}:Wo(t,n)}function Ko(e){if(!e.enableCellSpan||e.params.isSummaryRow)return 1;let{column:t,params:n}=e;if(L(t.colId)||R(t.colId))return 1;let r=t.rowSpan;return r?zi(r(n)):1}function qo(e){let{enableCellSpan:t,column:n,rowNode:r,getRowByIndex:i,rowCount:a}=e;if(!t||!n.rowSpan)return{head:r,rowSpan:1,covered:!1};let o=Math.max(0,r.rowIndex-100);for(let e=r.rowIndex-1;e>=o;e--){let o=i(e);if(!o)continue;let s=$o(Ko({enableCellSpan:t,column:n,params:Po(o,n)}),o.rowIndex,a);if(s>1&&o.rowIndex+s-1>=r.rowIndex)return{head:o,rowSpan:s,covered:!0}}return{head:r,rowSpan:$o(Ko({enableCellSpan:t,column:n,params:Po(r,n)}),r.rowIndex,a),covered:!1}}function Jo(e,t,n){if(t<=1)return e.rowHeight;let r=n(e.rowIndex+t-1)??e,i=r.rowTop+r.rowHeight-e.rowTop;return Math.max(e.rowHeight,i)}function Yo(e,t,n){let r=t>1;if(e.classList.toggle(`mg-cell--row-span`,r),r){e.classList.add(`mg-cell--spanning`),e.dataset.rowSpan=String(t),n!=null&&(e.style.height=`${n}px`);return}delete e.dataset.rowSpan,e.style.removeProperty(`height`),e.classList.remove(`mg-cell--row-span-highlighted`),e.classList.contains(`mg-cell--col-span`)||e.classList.remove(`mg-cell--spanning`)}function Xo(e){let{head:t,rowSpan:n,getRowByIndex:r,isRowHighlighted:i}=e;if(n<=1)return i(t.id);for(let e=0;e<n;e++){let n=r(t.rowIndex+e);if(n&&i(n.id))return!0}return!1}function Zo(e){let{head:t,rowSpan:n,colId:r,getRowByIndex:i,isCellSelected:a}=e;if(n<=1)return a(t.rowIndex,r);for(let e=0;e<n;e++){let n=i(t.rowIndex+e);if(n&&a(n.rowIndex,r))return!0}return!1}function Qo(e){let{enableCellSpan:t,rowModel:n,columns:r,firstRow:i,lastRow:a}=e,o=new Set;if(!t||a<i)return o;let s=r.filter(e=>e.rowSpan!=null);if(s.length===0)return o;let c=n.getRowCount(),l=e=>n.getRow(e),u=Math.max(0,i-50);for(let e=u;e<=a;e++){let n=l(e);if(n)for(let e of s){let r=qo({enableCellSpan:t,column:e,rowNode:n,getRowByIndex:l,rowCount:c});r.covered||r.rowSpan<=1||r.head.id!==n.id||r.head.rowIndex+r.rowSpan-1>=i&&r.head.rowIndex<=a&&o.add(r.head.id)}}return o}function $o(e,t,n){if(n<=0)return 1;let r=n-t;return Math.min(e,r,50)}function es(e,t){let n=new Map;if(!qi(e.spanRows)||t.length===0)return n;let r=e.spanRows,i=0,a=G(t[0],e),o=r=>{let a=i;for(;a<=r;){let i=Math.min(r,a+50-1),o=[];for(let e=a;e<=i;e++)o.push(t[e].id);let s={colId:e.colId,firstRowId:o[0],lastRowId:o[o.length-1],rowIds:o,rowSpan:o.length};for(let e of o)n.set(e,s);a=i+1}};for(let n=1;n<t.length;n++){let s=t[n],c=G(s,e),l=t[i];ts(r,l,s,a,c,e.colId)||(o(n-1),i=n,a=c)}return o(t.length-1),n}function ts(e,t,n,r,i,a){return e===!0?Object.is(r,i):typeof e==`function`&&e({nodeA:{rowId:t.id,data:t.data,rowIndex:t.rowIndex},nodeB:{rowId:n.id,data:n.data,rowIndex:n.rowIndex},valueA:r,valueB:i,colId:a})}var ns=class{deps;spanRowsCaches=new Map;warnedBothModes=new Set;constructor(e){this.deps=e}get active(){return this.deps.getEnableCellSpan()}refresh(){if(this.spanRowsCaches.clear(),!this.active)return;let e=this.deps.getDisplayRows(),t=this.deps.getColumnModel().getColumns();for(let n of t)n.rowSpan&&qi(n.spanRows)&&this.warnBothModes(n.colId),Ki(n.rowSpan,n.spanRows)===`spanRows`&&this.spanRowsCaches.set(n.colId,es(n,e))}getColSpan(e,t){let n=this.deps.getColumnModel().getColumnById(t);if(!n||!this.active)return 1;if(e===`__mg_summary__`)return Ro({enableCellSpan:!0,column:n,params:Fo(n,this.deps.getSummaryValue?.(t)??null)});let r=this.deps.getRowById(e);return r?Ro({enableCellSpan:!0,column:n,params:Po(r,n)}):1}getCellSpan(e,t){let n=this.deps.getColumnModel(),r=n.getColumnById(t),i=this.deps.getRowById(e);if(!r||!i||!this.active)return null;let a=this.resolveVerticalSpan(i,r),o=Bo(r,n,{enableCellSpan:!0,params:Po(i,r)});if(a.rowSpan<=1&&o.length<=1)return null;let s=this.collectVerticalRowIds(a.head,a.rowSpan);return{colId:r.colId,firstRowId:a.head.id,lastRowId:s[s.length-1]??a.head.id,rowSpan:a.rowSpan,colSpan:o.length,rowIds:s,colIds:o.map(e=>e.colId)}}isCovered(e,t){let n=this.deps.getColumnModel().getColumnById(t),r=this.deps.getRowById(e);return!n||!r||!this.active?!1:this.resolveVerticalSpan(r,n).covered}normalizePosition(e,t){let n=this.deps.getColumnModel().getColumnById(t),r=this.deps.getRowById(e);return!n||!r||!this.active?{rowId:e,colId:t}:{rowId:this.resolveVerticalSpan(r,n).head.id,colId:t}}resolveVerticalSpan(e,t){if(!this.active)return{head:e,rowSpan:1,covered:!1};let n=Ki(t.rowSpan,t.spanRows);return n===`rowSpan`?qo({enableCellSpan:!0,column:t,rowNode:e,getRowByIndex:this.deps.getRowByIndex,rowCount:this.deps.getRowCount()}):n===`spanRows`?this.resolveFromSpanRowsCache(e,t):{head:e,rowSpan:1,covered:!1}}getVerticalSpanHeight(e,t){let n=this.resolveVerticalSpan(e,t);return n.covered||n.rowSpan<=1?e.rowHeight:Jo(n.head,n.rowSpan,this.deps.getRowByIndex)}collectSpannedHeadRowIds(e,t){let n=new Set;if(!this.active||t<e)return n;let r=this.deps.getColumnModel().getColumns().filter(e=>Ki(e.rowSpan,e.spanRows)!==`none`);if(r.length===0)return n;let i=Math.max(0,e-50);for(let a=i;a<=t;a++){let i=this.deps.getRowByIndex(a);if(i)for(let a of r){let r=this.resolveVerticalSpan(i,a);r.covered||r.rowSpan<=1||r.head.id!==i.id||r.head.rowIndex+r.rowSpan-1>=e&&r.head.rowIndex<=t&&n.add(r.head.id)}}return n}resolveFromSpanRowsCache(e,t){let n=this.spanRowsCaches.get(t.colId)?.get(e.id);return!n||n.rowSpan<=1?{head:e,rowSpan:1,covered:!1}:{head:this.deps.getRowById(n.firstRowId)??e,rowSpan:n.rowSpan,covered:n.firstRowId!==e.id}}collectVerticalRowIds(e,t){let n=[];for(let r=0;r<t;r++){let t=this.deps.getRowByIndex(e.rowIndex+r);t&&n.push(t.id)}return n}warnBothModes(e){this.warnedBothModes.has(e)||(this.warnedBothModes.add(e),console.warn(`[magic-grid] Column "${e}" has both rowSpan and spanRows; rowSpan takes precedence.`))}},rs=`copy`,is=`mg-cell--range-selected`,as=`mg-cell--range-anchor`,os=`mg-cell-range-border`,ss=`mg-cell-range-border--edge-top`,cs=`mg-cell-range-border--edge-right`,ls=`mg-cell-range-border--edge-bottom`,us=`mg-cell-range-border--edge-left`,ds=`mg-cell-range-border--fill-h`,fs=`mg-cell-range-border--fill-v`,ps=`mg-cell-range-overlay`,ms=`mg-cell--range-copy-flash`,hs=`mg-cell-range-overlay--copy-flash`,gs=`mg-cell--range-paste-flash`,_s=`mg-cell--range-paste-blocked-flash`,vs=`mg-cell-range-paste-overlay`,ys=`mg-cell-range-paste-overlay--applied`,bs=`mg-cell-range-paste-overlay--blocked`,xs=`mg-cell-range-paste-flash-layer`,Ss=`mg-fill-handle`,Cs=`mg-range-handle`,ws=`mg-header-cell--range-highlight`,Ts=`mg-cell--index-range-highlight`;function Es(e){return L(e)||R(e)||z(e)||ln(e)||V(e)}function Ds(e){return Es(e)}function Os(e){let t=at(e);return t===`data`||t===`groupHeader`||t===`groupFooter`}function ks(e){return at(e)===`data`}function As(e,t){return L(e)||R(e)||z(e)?!1:Os(t)}function js(e,t){return!Ds(e)&&ks(t)}function Ms(e={}){let t=e.handleMode??`off`;return t===`off`?null:t===`range`?{mode:`range`}:{mode:`fill`,direction:e.direction??`xy`,fillStrategy:e.fillStrategy??`copy`,fillReverseStrategy:e.fillReverseStrategy??`default`,setFillValue:e.setFillValue}}function Ns(e){return!e.enabled||!e.handle?null:e.handle.mode}function Ps(e){return Ns(e)===`fill`}function Fs(e){return Ns(e)===`range`}function Is(e={}){return{enableHeaderHighlight:e.enableHeaderHighlight??!0,enableIndexColumnHighlight:e.enableIndexColumnHighlight??!0}}function Ls(e={}){let t=e.cellSelection;if(t===!1||t==null)return{enabled:!1,suppressMultiRanges:!0,enableColumnSelection:!1,enableCellCopy:!1,enableCellPaste:!1,handle:null};let n=t===!0?{}:t,r=e.enableCellCopy??!0,i=e.enableCellPaste??!1;return{enabled:!0,suppressMultiRanges:n.suppressMultiRanges??!0,enableColumnSelection:n.enableColumnSelection??!1,enableCellCopy:r,enableCellPaste:i,handle:Ms(n)}}function Rs(e,t){return{startRowIndex:Math.min(e.rowIndex,t.rowIndex),endRowIndex:Math.max(e.rowIndex,t.rowIndex),startColId:e.colId,endColId:t.colId}}function zs(e){return e.serviceRanges.length>0?[...e.serviceRanges]:!e.enableHeaderHighlight&&!e.enableIndexColumnHighlight?[]:e.editingRanges&&e.editingRanges.length>0?[...e.editingRanges]:!e.focus||!e.focusEligible?[]:[Rs(e.focus,e.focus)]}function Y(e,t){let n=Math.min(e.startRowIndex,e.endRowIndex),r=Math.max(e.startRowIndex,e.endRowIndex),i=t.indexOf(e.startColId),a=t.indexOf(e.endColId);if(i<0||a<0)return null;let o=Math.min(i,a),s=Math.max(i,a);return{top:n,bottom:r,leftColId:t[o],rightColId:t[s]}}function Bs(e){return{startRowIndex:e.top,endRowIndex:e.bottom,startColId:e.leftColId,endColId:e.rightColId}}function Vs(e,t,n,r){if(e<n.top||e>n.bottom)return!1;let i=r.indexOf(t);if(i<0)return!1;let a=r.indexOf(n.leftColId),o=r.indexOf(n.rightColId);return a<0||o<0?!1:i>=a&&i<=o}function Hs(e,t){return e.startRowIndex===t.startRowIndex&&e.endRowIndex===t.endRowIndex&&e.startColId===t.startColId&&e.endColId===t.endColId}function Us(e,t){let n=Math.min(e.startRowIndex,e.endRowIndex),r=Math.max(e.startRowIndex,e.endRowIndex);return[{rowIndex:n,colId:e.startColId},{rowIndex:n,colId:e.endColId},{rowIndex:r,colId:e.startColId},{rowIndex:r,colId:e.endColId}].every(e=>As(e.colId,t(e.rowIndex)))}function Ws(e,t,n){if(Es(e)||t<=0)return null;let r=-1,i=-1;for(let a=0;a<t;a++)As(e,n(a))&&(r<0&&(r=a),i=a);return r<0||i<0?null:{startRowIndex:r,endRowIndex:i,startColId:e,endColId:e}}function Gs(e,t,n){let r=null,i=null;for(let a of e)As(a,t(n))&&(r??=a,i=a);return r==null||i==null?null:{startColId:r,endColId:i}}function Ks(e){if(e.length===0)return[];let t=[...e].sort((e,t)=>e-t),n=[],r=t[0],i=t[0];for(let e=1;e<t.length;e++){let a=t[e];if(a===i+1){i=a;continue}n.push({top:r,bottom:i}),r=a,i=a}return n.push({top:r,bottom:i}),n}function qs(e){let{focusedRowIndices:t,displayedColIds:n,rowKindAt:r,suppressMultiRanges:i,currentRowIndex:a}=e,o=[...t].filter(e=>Os(r(e))).sort((e,t)=>e-t);if(o.length===0)return[];let s=Gs(n,r,o[0]);if(!s)return[];if(i){if(o.length===1||o.every((e,t)=>t===0||e===o[t-1]+1))return[{startRowIndex:o[0],endRowIndex:o[o.length-1],startColId:s.startColId,endColId:s.endColId}];let e=a??o[o.length-1];return Os(r(e))?[{startRowIndex:e,endRowIndex:e,startColId:s.startColId,endColId:s.endColId}]:[]}return Ks(o).map(({top:e,bottom:t})=>({startRowIndex:e,endRowIndex:t,startColId:s.startColId,endColId:s.endColId}))}function Js(e){let t=new Set(e.rangeRowIndices);for(let n of e.indexFocusedRowIds){let r=e.rowIndexById(n);r>=0&&t.add(r)}for(let n of e.selectedRowIds){let r=e.rowIndexById(n);r>=0&&t.add(r)}return t}function Ys(e,t){console.warn(`[magic-grid] addCellRange: ignored invalid range (${t}).`,e)}function Xs(e,t,n,r){if(!r?.active)return!1;if(r.resolveVerticalSpan(e,t).covered)return!0;let i=n.getDisplayedColumns().map(e=>e.colId),a=i.indexOf(t.colId);if(a<=0)return!1;for(let r=0;r<a;r++){let a=n.getColumnById(i[r]);if(!a)continue;let o=Bo(a,n,{enableCellSpan:!0,params:Po(e,a)});if(!(o.length<=1)&&o.findIndex(e=>e.colId===t.colId)>0)return!0}return!1}function Zs(e,t,n,r){let i=r.indexOf(t);if(i<0)return{leftColId:t,rightColId:t};for(let a=i;a>=0;--a){let i=r[a];if(!i)continue;let o=n.getColumnById(i);if(!o)continue;let s=Bo(o,n,{enableCellSpan:!0,params:Po(e,o)});if(!(s.length<=1)&&s.findIndex(e=>e.colId===t)>=0)return{leftColId:s[0].colId,rightColId:s[s.length-1].colId}}return{leftColId:t,rightColId:t}}function Qs(e,t,n){let r={top:e,bottom:e,leftColId:t,rightColId:t},i=n.rowModel.getRow(e);if(!i||!n.cellSpanService?.active)return r;let a=n.columnModel.getColumnById(t);if(!a)return r;let o=n.cellSpanService.resolveVerticalSpan(i,a),s=o.head,c=s.rowIndex,l=s.rowIndex;o.rowSpan>1&&(l=o.head.rowIndex+o.rowSpan-1);let u=Zs(s,t,n.columnModel,n.displayedColIds);return{top:c,bottom:l,leftColId:u.leftColId,rightColId:u.rightColId}}function $s(e,t,n){if(!n.cellSpanService?.active)return e;let r=e.top,i=e.bottom,a=e.leftColId,o=e.rightColId,s=t.indexOf(a),c=t.indexOf(o);if(s<0||c<0)return e;let l=Math.min(s,c),u=Math.max(s,c),d=!0;for(;d;){d=!1;for(let e=r;e<=i;e+=1)for(let s=l;s<=u;s+=1){let c=t[s];if(!c)continue;let f=Qs(e,c,n);f.top<r&&(r=f.top,d=!0),f.bottom>i&&(i=f.bottom,d=!0);let p=t.indexOf(f.leftColId),m=t.indexOf(f.rightColId);p>=0&&p<l&&(l=p,a=t[l],d=!0),m>=0&&m>u&&(u=m,o=t[u],d=!0)}}return{top:r,bottom:i,leftColId:a,rightColId:o}}function ec(e,t){if(!t.cellSpanService?.active)return e;let n=Y(e,t.displayedColIds);return n?Bs($s(n,t.displayedColIds,t)):e}function tc(e,t,n){let r=$s(e,t,{...n,displayedColIds:t,cellSpanService:n.cellSpanService});return{topRowIndex:r.top,bottomRowIndex:r.bottom}}var nc=class{lanes;footerRowEl;frameService;onUnmountRenderer;enableCellSpan;columnModel=null;summaryCells=new Map;constructor(e){this.footerRowEl=e.footerRowEl,this.frameService=e.frameService??null,this.onUnmountRenderer=e.onUnmountRenderer,this.enableCellSpan=e.enableCellSpan??!1,this.lanes={left:this.createLane(e.footerLeftLaneEl),center:this.createLane(e.footerCenterLaneEl),right:this.createLane(e.footerRightLaneEl)}}setEnableCellSpan(e){this.enableCellSpan=e}render(e){this.columnModel=e.columnModel,this.summaryCells=e.summaryCells;let t=Go({columnModel:e.columnModel,centerWindow:e.centerWindow,enableCellSpan:this.enableCellSpan,paramsForColumn:t=>Fo(t,e.summaryCells.get(t.colId)?.value??null)});this.syncLaneWidths(e.columnModel),this.syncLaneCells(`left`,t.left),this.syncLaneCells(`center`,t.center),this.syncLaneCells(`right`,t.right),this.syncCellValues(e.summaryCells,e.valueCacheVersion,e.force??!1)}syncRowLayout(e){this.footerRowEl.style.width=`${e.getTotalWidth()}px`,this.syncLaneWidths(e)}syncColumnLayouts(){if(this.columnModel){this.syncRowLayout(this.columnModel);for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];!r||!i||this.applyCellColumnLayout(i,r)}}}}refreshVisibleColumnStructure(e){if(!this.columnModel)return;let t=Go({columnModel:this.columnModel,centerWindow:e,enableCellSpan:this.enableCellSpan,paramsForColumn:e=>Fo(e,this.summaryCells.get(e.colId)?.value??null)});this.syncLaneWidths(this.columnModel),this.syncLaneCells(`left`,t.left),this.syncLaneCells(`center`,t.center),this.syncLaneCells(`right`,t.right),this.syncCellValues(this.summaryCells,0,!0)}destroy(){for(let e of Object.values(this.lanes)){for(let t of e.cells)t.destroy();e.cells.length=0,e.cellCtrls.length=0,e.indices.length=0}}createLane(e){return{element:e,cells:[],cellCtrls:[],indices:[]}}syncLaneWidths(e){this.lanes.left.element.style.width=`${e.getLeftFixedWidth()}px`,this.lanes.center.element.style.width=`${e.getCenterTotalWidth()}px`,this.lanes.right.element.style.width=`${e.getRightFixedWidth()}px`}syncLaneCells(e,t){let n=this.lanes[e];for(n.indices=t;n.cells.length<t.length;)n.cells.push(new No(n.element,{onUnmountRenderer:this.onUnmountRenderer})),n.cellCtrls.push(new Oo);for(;n.cells.length>t.length;)n.cells.pop()?.destroy(),n.cellCtrls.pop();for(let e=0;e<t.length;e++){let r=t[e],i=r===void 0?void 0:this.columnModel.getColumn(r),a=n.cells[e];!i||!a||(this.applyCellColumnLayout(a,i),a.setColId(i.colId),ci(a.getElement(),i.footerAlign,i.footerValign,`mg-footer-cell`),a.getElement().classList.toggle(`mg-footer-cell--index`,L(i.colId)),a.getElement().classList.toggle(`mg-footer-cell--selection`,R(i.colId)))}}applyCellColumnLayout(e,t){if(!this.columnModel)return;if(!this.enableCellSpan||!t.colSpan){e.setColumnLayout(ko(t,this.columnModel)),Lo(e.getElement(),1,`mg-footer-cell`);return}let n=Bo(t,this.columnModel,{enableCellSpan:!0,params:Fo(t,this.summaryCells.get(t.colId)?.value??null)});e.setColumnLayout(Io(n,this.columnModel)),Lo(e.getElement(),n.length,`mg-footer-cell`)}syncCellValues(e,t,n){if(this.columnModel)for(let r of[`left`,`center`,`right`]){let i=this.lanes[r];for(let r=0;r<i.indices.length;r++){let a=i.indices[r],o=a===void 0?void 0:this.columnModel.getColumn(a),s=i.cells[r],c=i.cellCtrls[r];if(!o||!s||!c)continue;let l=e.get(o.colId)??{value:null,formattedValue:``};c.refreshSummaryCell(o,l,s,t,{force:n,scheduleRenderer:e=>this.scheduleRendererTask(e)})}}}scheduleRendererTask(e){if(this.frameService){this.frameService.createTask(e,-1,`f1`);return}e()}};function rc(e,t,n,r){e.style.width=`${r.getLeftFixedWidth()}px`,t.style.width=`${r.getCenterTotalWidth()}px`,n.style.width=`${r.getRightFixedWidth()}px`}function ic(e,t,n,r){jo(e,r,`mg-footer-cell`),jo(t,r,`mg-footer-cell`),jo(n,r,`mg-footer-cell`)}function ac(e){return e==null||e===``||typeof e==`string`&&e.trim()===``}function oc(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=e.trim();if(t===``)return null;let n=Number(t);return Number.isFinite(n)?n:null}return null}var sc={count:0,numericCount:0,sum:null,average:null};function cc(e){let{ranges:t,displayedColIds:n,rowKindAt:r,getCellValue:i,normalizePosition:a=(e,t)=>({rowIndex:e,colId:t})}=e;if(t.length===0)return{...sc};let o=new Set,s=0,c=0,l=0;for(let e of t){let t=Y(e,n);t&&lc(t,n,(e,t)=>{if(!js(t,r(e)))return;let n=a(e,t),u=`${n.rowIndex}:${n.colId}`;if(o.has(u))return;o.add(u);let d=i(n.rowIndex,n.colId);if(ac(d))return;s+=1;let f=oc(d);f!=null&&(c+=1,l+=f)})}return{count:s,numericCount:c,sum:c>0?l:null,average:c>0?l/c:null}}function lc(e,t,n){let r=t.indexOf(e.leftColId),i=t.indexOf(e.rightColId);if(!(r<0||i<0))for(let a=e.top;a<=e.bottom;a++)for(let e=r;e<=i;e++)n(a,t[e])}function uc(e,t){if(t.filterFormatter)return t.filterFormatter(e.data);let n=t.prop??t.colId,r=n?e.data[n]:void 0;return t.formatter?(t.valueGetter&&(r=t.valueGetter(e.data,r)),t.formatter(e.data,r)):t.valueGetter?t.valueGetter(e.data,r):r}function dc(e,t){return{getFilterType:t=>e(t)?.filterType??`text`,getFilterParams:t=>e(t)?.filterParams??{caseSensitive:!0},getFilterValue:(n,r)=>{let i=e(r);return i?uc(n,i):t(n,r)}}}function fc(e,t){let n=e.__autoHeights;if(!n)return null;let r=Object.values(n);return r.length===0?null:Math.max(t,...r)}function pc(e,t,n){if(e.rowHeightPinned&&e.rowHeight>0)return{height:e.rowHeight,estimated:!1};if(n){let t=n(e);if(t!=null&&t>0)return{height:t,estimated:!1}}let r=fc(e,t);return r==null?e.rowHeight>0?{height:e.rowHeight,estimated:e.estimated??!1}:{height:t,estimated:!1}:{height:r,estimated:e.estimated??!1}}function mc(e,t){let n=0;for(let r=0;r<e.length;r++){let i=e[r];i.rowIndex=r,i.rowTop=n,i.rowHeight=t,i.estimated=!1,n+=t}}function hc(e,t){let n=0;for(let r=0;r<e.length;r++){let i=e[r],{height:a,estimated:o}=pc(i,t.defaultRowHeight,t.getRowHeight);i.rowIndex=r,i.rowTop=n,i.rowHeight=a,i.estimated=o,n+=a}}function gc(e,t){if(typeof t==`number`){mc(e,t);return}hc(e,t)}function _c(e){if(e.length===0)return 0;let t=e[e.length-1];return t.rowTop+t.rowHeight}function vc(e,t){return e===t?0:e===`(Blanks)`?1:t===`(Blanks)`?-1:e.localeCompare(t)}function yc(e){return e?(t,n,r)=>e({valueA:t,valueB:n,colId:r.colId,field:r.field,level:r.level}):(e,t)=>vc(e,t)}function bc(e){let{sourceRows:t,rowGroupColumns:n}=e;return n.length===0||t.length===0?[...t]:xc({rows:t,level:0,parentGroupId:void 0,parentPathIds:[],rowGroupColumns:n,getCellValue:e.getCellValue,groupKeyCreator:e.groupKeyCreator,groupComparator:e.groupComparator,getColumnField:e.getColumnField})}function xc(e){let{rows:t,level:n,parentGroupId:r,parentPathIds:i,rowGroupColumns:a,getCellValue:o,groupKeyCreator:s,groupComparator:c,getColumnField:l}=e;if(t.length===0)return[];if(n>=a.length)return wc(t,Ht(i)),[...t];let u=a[n],d=l?.(u)??u,f=Sc(t,u,d,o,s),p=yc(c),m={colId:u,field:d,level:n};return[...f.keys()].sort((e,t)=>p(e,t,m)).map(e=>{let t=f.get(e),p=Vt(n,d,e,r),m=[...i,p],h=xc({rows:t,level:n+1,parentGroupId:p,parentPathIds:m,rowGroupColumns:a,getCellValue:o,groupKeyCreator:s,groupComparator:c,getColumnField:l});return Tc({colId:u,field:d,key:e,level:n,groupId:p,groupPathKey:Ht(m),children:h})})}function Sc(e,t,n,r,i){let a=new Map;for(let o of e){let e=Cc(o,t,n,r,i),s=a.get(e);if(s){s.push(o);continue}a.set(e,[o])}return a}function Cc(e,t,n,r,i){let a=r(e,t);return Bt(i?i({field:n,colId:t,value:a,data:e.data}):a)}function wc(e,t){for(let n of e)n.leafGroupPathKey=t}function Tc(e){let t=Ec(e.children);return{id:e.groupId,data:{},rowTop:0,rowHeight:0,estimated:!1,rowIndex:-1,group:!0,groupField:e.colId,groupKey:e.key,groupLevel:e.level,groupId:e.groupId,groupPathKey:e.groupPathKey,groupLeafCount:t,childrenAfterGroup:e.children}}function Ec(e){let t=0;for(let n of e){if(n.group){let e=n.childrenAfterSort??n.childrenAfterFilter??n.childrenAfterGroup??[];t+=Ec(e);continue}t+=1}return t}function Dc(e){return e.some(e=>e.group===!0)}function Oc(e){return e.childrenAfterGroup??[]}function kc(e){return e.childrenAfterFilter??e.childrenAfterGroup??[]}function Ac(e){return e.childrenAfterSort??kc(e)}function jc(e){return Ac(e)}function Mc(e){let t=[];for(let n of e){if(n.group){t.push(...Mc(Ac(n)));continue}t.push(n)}return t}function Nc(e){for(let t of e){if(!t.group)continue;let e=Nc(Oc(t));t.childrenAfterFilter=e,t.groupLeafCount=Ec(e)}return[...e]}function Pc(e){for(let t of e){if(!t.group)continue;let e=t.childrenAfterSort??kc(t);Pc(e),t.groupLeafCount=Ec(e)}}function Fc(e){return e.some(e=>e.dataPath!=null&&e.dataPath.length>0&&e.group!==!0)}function Ic(e){return e.childrenAfterFilter??e.childrenAfterTree??[]}function Lc(e){return e.childrenAfterSort??Ic(e)}function Rc(e){for(let t of e){let e=t.childrenAfterTree??[];t.childrenAfterFilter=e.length>0?Rc(e):[]}return[...e]}function zc(e){return Bc(e??``)!==``}function Bc(e){return e.trim()}function Vc(e){let t=Bc(e.quickFilterText).toLowerCase();if(t===``)return!0;for(let n of e.filterableColIds){let r=e.getFilterValue(e.row,n,e.getCellValue);if(String(r??``).toLowerCase().includes(t))return!0}return!1}var Hc=`__mg_blank__`,Uc=/^\d{4}-\d{2}-\d{2}$/;function Wc(e){return!!(e==null||typeof e==`number`&&Number.isNaN(e)||typeof e==`string`&&e.trim()===``)}function Gc(e){return e.toISOString().slice(0,10)}function Kc(e){if(Wc(e))return null;if(e instanceof Date)return Number.isNaN(e.getTime())?null:Gc(e);if(typeof e==`number`){let t=new Date(e);return Number.isNaN(t.getTime())?null:Gc(t)}let t=String(e).trim();if(t===``)return null;if(Uc.test(t))return t;let n=Date.parse(t);return Number.isNaN(n)?null:Gc(new Date(n))}function qc(e){if(Wc(e))return null;let t=Number(e);return Number.isNaN(t)?null:t}function Jc(e,t){if(Wc(e))return Hc;switch(t){case`number`:{let t=qc(e);return t===null?Hc:String(t)}case`date`:return Kc(e)??`__mg_blank__`;default:return String(e)}}function Yc(e,t){return e===`__mg_blank__`?`(空白)`:e}function Xc(e,t){return e===`__mg_blank__`?-1:t===`__mg_blank__`?1:e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`})}function Zc(e){let t=new Map;for(let n of e.rows){let r=Jc(e.getFilterValue(n),e.filterType);t.set(r,(t.get(r)??0)+1)}return[...t.keys()].sort(Xc).map(t=>({key:t,label:Yc(t,e.filterType),blank:t===Hc}))}var Qc=/^\d{4}-\d{2}-\d{2}$/;function $c(e){return!!(e==null||typeof e==`number`&&Number.isNaN(e)||typeof e==`string`&&e.trim()===``)}function el(e,t){let n=String(e??``);return t?n:n.toLowerCase()}function tl(e,t){return t?e:e.toLowerCase()}function nl(e){return e.toISOString().slice(0,10)}function rl(e){if($c(e))return null;if(e instanceof Date)return Number.isNaN(e.getTime())?null:nl(e);if(typeof e==`number`){let t=new Date(e);return Number.isNaN(t.getTime())?null:nl(t)}let t=String(e).trim();if(t===``)return null;if(Qc.test(t))return t;let n=Date.parse(t);return Number.isNaN(n)?null:nl(new Date(n))}function il(e){if($c(e))return null;let t=Number(e);return Number.isNaN(t)?null:t}function al(e,t,n){let r=n(e);return t===`blank`?r:!r}function ol(e,t,n){if(Mi(t.type))return al(e,t.type,$c);let r=t.filter??``,i=el(e,n.caseSensitive),a=tl(r,n.caseSensitive);switch(t.type){case`contains`:return i.includes(a);case`notContains`:return!i.includes(a);case`equals`:return i===a;case`notEqual`:return i!==a;case`startsWith`:return i.startsWith(a);case`endsWith`:return i.endsWith(a);default:return!1}}function sl(e,t){if(Mi(t.type))return al(e,t.type,e=>il(e)===null);let n=il(e),r=il(t.filter);if(n===null||r===null)return!1;switch(t.type){case`equals`:return n===r;case`notEqual`:return n!==r;case`lessThan`:return n<r;case`lessThanOrEqual`:return n<=r;case`greaterThan`:return n>r;case`greaterThanOrEqual`:return n>=r;default:return ol(e,t,{caseSensitive:!0})}}function cl(e,t){if(Mi(t.type))return al(e,t.type,$c);let n=rl(e),r=t.filter?.trim()??``;if(r===``)return!1;switch(t.type){case`equals`:return n!==null&&n===r;case`notEqual`:return n===null||n!==r;case`lessThan`:return n!==null&&n<r;case`greaterThan`:return n!==null&&n>r;case`inRange`:{let e=t.filterTo?.trim()??``;return e===``||n===null?!1:n>=r&&n<=e}default:return!1}}function ll(e,t,n){if(t.length===0)return!1;let r=Jc(e,n);return t.includes(r)}function ul(e,t,n,r){switch(n){case`number`:return sl(e,t);case`date`:return cl(e,t);default:return ol(e,t,r)}}function dl(e,t,n,r){let i=Ti(t),a=wi(t).filter(Ci);if(a.length===0)return!0;let o=a.map(t=>ul(e,t,n,r));return i===`OR`?o.some(Boolean):o.every(Boolean)}function fl(e,t,n,r){let i=Di(t),a=Oi(t);return!(i&&!dl(e,t,n,r)||a&&!ll(e,Ei(t)??[],n))}function X(e){return String(e)}function pl(e){return typeof e==`string`||typeof e==`number`?[String(e)]:e.map(X)}function ml(e){if(e!=null)return e.map(X)}var hl=class extends Error{cause;constructor(e,t){super(e),this.cause=t,this.name=`RowMutationPersistError`}},gl=`mg-column-handle-menu`,_l=`mg-column-handle-menu-portal`,vl=`mg-column-handle-menu__section`,yl=`mg-column-handle-menu__item`,bl=`mg-column-handle-menu__item-content`,xl=`mg-column-handle-menu__item-label`,Sl=`mg-column-handle-menu__item--submenu-trigger`,Cl=`mg-column-handle-menu__submenu`,wl=`mg-column-handle-menu__submenu-panel`,Tl=`mg-column-handle-menu__divider`,El=`mg-column-handle-menu__filter-panel`,Dl=`mg-column-handle-menu__section--sort`,Ol=`mg-column-handle-menu__section--pin`,kl=`mg-column-handle-menu__section--filter`,Al=`mg-column-handle-menu__section--visibility`;function jl(e){return!L(e)&&!R(e)}function Ml(e,t=`full`){return jl(e.colId)?t===`filter-only`?{sort:!1,pin:!1,filter:e.filterable,visibility:!1}:{sort:e.sortable,pin:!0,filter:e.filterable,visibility:!0}:{sort:!1,pin:!1,filter:!1,visibility:!1}}function Nl(e){return e.sort||e.pin||e.filter||e.visibility}var Pl=Symbol.for(`magic-grid.vueCellRenderer`);function Fl(e){return Object.defineProperty(e,Pl,{value:!0,configurable:!0}),e}function Il(e){return e?Reflect.get(e,Pl)===!0:!1}function Ll(e,t,n){return!t||e===`never`?!1:e===`always`||n===`vue`||n!==`sync`&&Il(t)}function Rl(e,t,n,r){return e!==`immediate`&&Ll(t,n,r)}var zl=[`immediate`,`deferred`,`placeholder-then-vue`];function Bl(e){return e&&zl.includes(e)?e:`deferred`}function Vl(e={}){return{scrollEndFlushMs:Math.max(0,e.scrollEndFlushMs??0),frameBudgetMs:Math.max(1,e.frameBudgetMs??60),scrollEndFrameBudgetMs:e.scrollEndFrameBudgetMs??-1,cellRendererDefer:e.cellRendererDefer??`always`,deferRowDestroyOnScroll:e.deferRowDestroyOnScroll??!1,rendererFrameBudgetMs:Math.max(0,e.rendererFrameBudgetMs??20),cellRendererPresentation:Bl(e.cellRendererPresentation)}}var Hl=`mg-cell--has-comment`,Ul=`mg-cell--comment-empty`,Wl=`mg-cell-comment-popup`,Gl=`mg-cell-comment-popup--readonly`,Kl=`mg-cell-comment-popup--committing`,ql=`mg-cell-comment-context-menu`,Jl=`mg-cell-comment-context-menu--committing`;function Yl(e={}){return{cellCommentsDataSource:e.cellCommentsDataSource,suppressCellComments:e.suppressCellComments??!1,cellCommentTrigger:e.cellCommentTrigger??`click`,cellCommentShowDelay:e.cellCommentShowDelay??180,cellCommentHideDelay:e.cellCommentHideDelay??220}}function Xl(e){return e!=null&&typeof e.getComment==`function`&&typeof e.setComment==`function`}function Zl(e){return L(e)||R(e)||z(e)||ln(e)||V(e)}function Ql(e,t,n){return!(t!==`data`||n!=null&&String(n)===`__mg_summary__`||Zl(e))}function $l(e,t){return e==null?!1:typeof e==`function`?e(t):e}function eu(e){let t={canView:!1,canCreate:!1,canEdit:!1,canDelete:!1};if(!Ql(e.colId,e.rowKind,e.rowId))return t;let n=$l(e.columnSuppress,{data:e.data,rowId:e.rowId,colId:e.colId});return e.gridSuppress===!0||n?{canView:e.hasExistingComment,canCreate:!1,canEdit:!1,canDelete:!1}:{canView:!0,canCreate:!e.hasExistingComment,canEdit:e.hasExistingComment,canDelete:e.hasExistingComment}}function tu(e,t){return t?.readOnly?{canView:e.canView,canCreate:!1,canEdit:!1,canDelete:!1}:e}function nu(e){return typeof e?.text==`string`&&e.text.length>0}function ru(e,t,n,r){return{rowId:e,colId:t,comment:n,source:r}}function iu(e,t){return`${e}::${t}`}function au(e,t){e&&(t||console.warn(`[magic-grid] cellCommentsDataSource requires rowKey for stable (rowId, colId) keys; cell comment interactions are disabled.`))}var ou=`mg-column-settings`,su=`mg-column-settings__header`,cu=`mg-column-settings__body`,lu=`mg-column-settings-button`,uu=`mg-column-settings-portal`,du=`mg-column-settings-popover`,fu=`mg-column-settings-menu`,pu=`mg-column-settings-menu__item`,mu=`mg-column-settings-menu__divider`,hu=`mg-column-settings-menu__submenu`,gu=`mg-column-settings-menu__submenu-panel`,_u=`mg-column-settings-menu__item--submenu-trigger`,vu=`mg-column-settings__clear-filters`,yu=`mg-column-settings__group`,bu=`mg-column-settings__group-heading`,xu=`mg-column-settings__row`,Su=`mg-column-settings__row--filtered`,Cu=`mg-column-settings__hidden-section`;function wu(e){return!Aa(e)}function Tu(e){return e===`left`?`left`:e===`right`?`right`:`center`}function Eu(e){return e.label??e.prop??e.colId}function Du(e){let t=new Map,n={left:0,center:0,right:0};for(let r of e){if(r.hidden||!wu(r.colId))continue;let e=Tu(r.fixed);t.set(r.colId,n[e]),n[e]++}return t}function Ou(e){let t=e.sortModel[0],n=t?.colId,r=t?.sort??null,i=e.includeHidden??!0,a=e.columns.filter(e=>!(!wu(e.colId)||!i&&e.hidden)),o=Du(a);return a.map(t=>{let i=Tu(t.fixed),a=t.hidden?-1:o.get(t.colId)??-1;return{colId:t.colId,label:Eu(t),movable:t.movable,sortable:t.sortable,filterable:t.filterable,fixed:t.fixed??null,hidden:t.hidden,sortDirection:t.colId===n?r:null,filterActive:e.isColumnFilterActive(t.colId),displayIndex:a,lane:i}})}function ku(e){let t=e.filter(e=>!e.hidden),n=e.filter(e=>e.hidden);return{left:t.filter(e=>e.lane===`left`),center:t.filter(e=>e.lane===`center`),right:t.filter(e=>e.lane===`right`),hidden:n}}var Au=`加载中…`,ju=`暂无数据`,Mu=`没有匹配的行`,Nu=`mg-overlay`,Pu=`mg-overlay__wrapper`,Fu=`mg-overlay--masked`,Iu=`mg-overlay__content`,Lu=`mg-overlay__panel--loading`,Ru=`mg-overlay__panel--no-rows`,zu=`mg-overlay__panel--no-matching-rows`,Bu=`mg-overlay__spinner`;function Vu(e){switch(e){case`loading`:return Au;case`noRows`:return ju;case`noMatchingRows`:return Mu;default:return e}}function Hu(e={}){let t=new Set(e.suppressOverlays??[]);return e.suppressLoadingOverlay&&t.add(`loading`),e.suppressNoRowsOverlay&&t.add(`noRows`),e.suppressNoMatchingRowsOverlay&&t.add(`noMatchingRows`),t}function Uu(e={}){return{loading:e.loading,suppressOverlays:Hu(e),overlayLoadingTemplate:e.overlayLoadingTemplate,overlayNoRowsTemplate:e.overlayNoRowsTemplate,overlayNoMatchingRowsTemplate:e.overlayNoMatchingRowsTemplate,loadingOverlayComponent:e.loadingOverlayComponent,loadingOverlayComponentParams:e.loadingOverlayComponentParams,noRowsOverlayComponent:e.noRowsOverlayComponent,noRowsOverlayComponentParams:e.noRowsOverlayComponentParams,noMatchingRowsOverlayComponent:e.noMatchingRowsOverlayComponent,noMatchingRowsOverlayComponentParams:e.noMatchingRowsOverlayComponentParams,overlayComponent:e.overlayComponent,overlayComponentParams:e.overlayComponentParams,overlayInteraction:e.overlayInteraction??!1}}function Wu(e,t){return t.has(e)}function Gu(e){let{rows:t,filterModel:n,getCellValue:r,columnContext:i,quickFilterText:a,quickFilterColIds:o=[]}=e,s=Object.entries(n).filter(([,e])=>Ni(e)),c=zc(a),l=Dc(t),u=!l&&Fc(t);if(l)return s.length===0&&!c?Nc(t):Ku(t,s,c,{getCellValue:r,context:i??Yu,quickFilterText:a??``,quickFilterColIds:o});if(u)return s.length===0&&!c?Rc(t):qu(t,s,c,{getCellValue:r,context:i??Yu,quickFilterText:a??``,quickFilterColIds:o});if(s.length===0&&!c)return[...t];let d=i??Yu;return t.filter(e=>Ju(e,s,r,d,c,{quickFilterText:a??``,quickFilterColIds:o}))}function Ku(e,t,n,r){let i=[];for(let a of e){if(a.group){let e=Ku(a.childrenAfterGroup??[],t,n,r);if(e.length===0)continue;a.childrenAfterFilter=e,a.groupLeafCount=Ec(e),i.push(a);continue}Ju(a,t,r.getCellValue,r.context,n,{quickFilterText:r.quickFilterText,quickFilterColIds:r.quickFilterColIds})&&i.push(a)}return i}function qu(e,t,n,r){let i=[];for(let a of e){let e=qu(a.childrenAfterTree??[],t,n,r);!Ju(a,t,r.getCellValue,r.context,n,{quickFilterText:r.quickFilterText,quickFilterColIds:r.quickFilterColIds})&&e.length===0||(a.childrenAfterFilter=e,i.push(a))}return i}function Ju(e,t,n,r,i,a){return Xu(e,t,n,r)&&(!i||Vc({row:e,quickFilterText:a.quickFilterText,filterableColIds:a.quickFilterColIds,getCellValue:n,getFilterValue:(e,t,n)=>r.getFilterValue(e,t,n)}))}var Yu={getFilterType:()=>`text`,getFilterParams:()=>({caseSensitive:!0}),getFilterValue:(e,t,n)=>n(e,t)};function Xu(e,t,n,r){for(let[i,a]of t){let t=r.getFilterValue(e,i,n);if(xi(a)){if(!a.predicate(t,e.data))return!1;continue}if(!fl(t,a,r.getFilterType(i),r.getFilterParams(i)))return!1}return!0}var Zu=`合计`;function Qu(e){return typeof e==`number`&&Number.isFinite(e)}function $u(e,t){let n=[];for(let r of e){let e=G(r,t);Qu(e)&&n.push(e)}return n}function ed(e,t,n){if(e===`count`)return t.length;let r=$u(t,n);if(r.length===0)return null;switch(e){case`sum`:return r.reduce((e,t)=>e+t,0);case`avg`:return r.reduce((e,t)=>e+t,0)/r.length;case`min`:return Math.min(...r);case`max`:return Math.max(...r);default:return null}}function td(e,t,n){return typeof e==`function`?e(t,n):ed(e,t,n)}function nd(e){return e.summary===!1?!1:e.summaryAgg!=null||e.summary===!0}function rd(e,t){return t==null?``:e.summaryFormatter?e.summaryFormatter(t):e.formatter?e.formatter({},t):String(t)}function id(e,t){return{value:t,formattedValue:rd(e,t)}}function ad(e,t,n){if(!n)return null;try{let r=n({columns:e,data:t.map(e=>e.data),rows:t}),i=new Map;for(let[e,t]of Object.entries(r))t!==void 0&&i.set(e,t);return i}catch(e){return console.warn(`[magic-grid] summaryMethod failed:`,e),new Map}}function od(e){return e.find(e=>!L(e.colId)&&!R(e.colId))}function sd(e){let{columns:t,rows:n,summaryMethod:r}=e,i=new Map,a=ad(t,n,r);for(let e of t){if(L(e.colId)||R(e.colId)){i.set(e.colId,id(e,null));continue}let t=a?.get(e.colId);if(a?.has(e.colId)){i.set(e.colId,id(e,t??null));continue}if(nd(e)&&e.summaryAgg!=null){let t=td(e.summaryAgg,n,e);i.set(e.colId,id(e,t))}}let o=od(t);return o&&!i.has(o.colId)&&i.set(o.colId,id(o,Zu)),i}function cd(e){return Dc(e.rows)&&ld(e.rows,e.columns),[...e.rows]}function ld(e,t){for(let n of e){if(!n.group)continue;let e=Ac(n);ld(e,t),n.__groupAggValues=ud(t,Mc(e))}}function ud(e,t){let n={};for(let r of e){if(!r.groupAgg||L(r.colId)||R(r.colId)||z(r.colId)||V(r.colId))continue;let e=td(r.groupAgg,t,r);n[r.colId]={value:e,formattedValue:rd(r,e)}}return n}function dd(e,t={}){let n=e.groupId??e.id,r=t.rowHeight??m;return{id:Ut(n),data:{},rowTop:0,rowHeight:r,estimated:!1,rowIndex:-1,rowKind:`groupHeader`,sourceGroupId:n,groupField:e.groupField,groupKey:e.groupKey,groupLevel:e.groupLevel,groupLeafCount:e.groupLeafCount,groupId:n,groupPathKey:e.groupPathKey}}function fd(e,t={}){let n=e.groupId??e.id,r=t.rowHeight??m;return{id:Wt(n),data:{},rowTop:0,rowHeight:r,estimated:!1,rowIndex:-1,rowKind:`groupFooter`,sourceGroupId:n,groupField:e.groupField,groupKey:e.groupKey,groupLevel:e.groupLevel,groupLeafCount:e.groupLeafCount,groupId:n,groupPathKey:e.groupPathKey,__groupAggValues:pd(e.__groupAggValues)}}function pd(e){if(e)return{...e}}function md(e,t){return Dc(e)?gd(e,{expandedGroupIds:t?.expandedGroupIds??new Set,showGroupHeader:t?.showGroupHeader??!1,showGroupFooter:t?.showGroupFooter??!1,defaultRowHeight:t?.defaultRowHeight}):Fc(e)?hd(e,{expandedRowIds:t?.expandedRowIds??new Set}):[...e]}function hd(e,t){let n=[];function r(e){for(let i of e)n.push(i),t.expandedRowIds.has(i.id)&&r(Lc(i))}return r(e),n}function gd(e,t){let n=[];for(let r of e){if(!r.group){n.push(r);continue}let e=r.groupId??r.id,i=!t.showGroupHeader||t.expandedGroupIds.has(e);t.showGroupHeader&&n.push(dd(r,{rowHeight:t.defaultRowHeight})),i&&(n.push(...gd(Ac(r),t)),t.showGroupFooter&&n.push(fd(r,{rowHeight:t.defaultRowHeight})))}return n}function _d(e,t,n){let{colId:r,sort:i}=e;return n?(e,a)=>{let o=n(t(e,r),t(a,r),i,e.data,a.data);return o===0?e.id.localeCompare(a.id):i===`desc`?-o:o}:(e,n)=>{let a=vd(t(e,r),t(n,r),i);return a===0?e.id.localeCompare(n.id):a}}function vd(e,t,n){let r=0;return r=e==null&&t==null?0:e==null?-1:t==null?1:typeof e==`number`&&typeof t==`number`?e-t:String(e).localeCompare(String(t)),n===`desc`?-r:r}function yd(e,t,n,r){if(t.length<4)return[...r??e].sort(n);let i=new Set(t.map(e=>e.id));return bd(e.filter(e=>!i.has(e.id)),[...t].sort(n),n)}function bd(e,t,n){let r=[],i=0,a=0;for(;i<e.length&&a<t.length;)n(e[i],t[a])<=0?(r.push(e[i]),i++):(r.push(t[a]),a++);for(;i<e.length;)r.push(e[i]),i++;for(;a<t.length;)r.push(t[a]),a++;return r}function xd(e){let t=e.rows??e.sourceRows;if(Dc(t))return Sd({rows:t,sortModel:e.sortModel,getCellValue:e.getCellValue,getColumnComparator:e.getColumnComparator,groupComparator:e.groupComparator});if(Fc(t))return Ed({rows:t,sortModel:e.sortModel,getCellValue:e.getCellValue,getColumnComparator:e.getColumnComparator});let{sourceRows:n,currentDisplayRows:r,sortModel:i,touchedRowIds:a,getCellValue:o,getColumnComparator:s}=e;if(i.length===0)return[...t];let c=i[0],l=_d(c,o,s?.(c.colId));if(a&&a.size>0){let e=n.filter(e=>a.has(e.id));if(e.length>0&&r.length>0)return yd(r,e,l,n)}return[...t].sort(l)}function Sd(e){let t=Cd(e.rows,e);return Pc(t),t}function Cd(e,t){if(e.length===0)return[];if(e[0]?.group){let n=yc(t.groupComparator);return e.map(e=>wd(e,t)).sort((e,t)=>{let r=e.groupLevel??t.groupLevel??0,i=e.groupField??t.groupField??``;return n(e.groupKey??``,t.groupKey??``,{colId:i,field:i,level:r})})}return Td(e,t)}function wd(e,t){return e.childrenAfterSort=Cd(e.childrenAfterFilter??e.childrenAfterGroup??[],t),e}function Td(e,t){if(t.sortModel.length===0)return[...e];let n=t.sortModel[0],r=_d(n,t.getCellValue,t.getColumnComparator?.(n.colId));return[...e].sort(r)}function Ed(e){return Dd(e.rows,e)}function Dd(e,t){let n=Td(e,t);for(let e of n){let n=Ic(e);e.childrenAfterSort=n.length>0?Dd(n,t):[]}return n}var Od=`\0`;function kd(e){return e.join(Od)}var Ad=class extends Error{constructor(e){super(e),this.name=`TreeBuildError`}};function jd(e){let{sourceRows:t,getDataPath:n}=e,r=new Map,i=t.map((e,t)=>({node:e,path:n({data:e.data}),sourceIndex:t})).sort((e,t)=>e.path.length===t.path.length?e.sourceIndex-t.sourceIndex:e.path.length-t.path.length);for(let{path:e}of i)if(!Array.isArray(e)||e.length===0)throw new Ad(`[TreeBuildStage] getDataPath must return a non-empty string[]`);for(let{node:e,path:t}of i){let n=kd(t);if(r.has(n))throw new Ad(`[TreeBuildStage] duplicate dataPath: ${t.join(`/`)}`);e.dataPath=[...t],e.treeLevel=t.length-1,e.treeLeaf=!0,e.childrenAfterTree=[],r.set(n,e)}let a=[];for(let{node:e,path:t}of i){if(t.length===1){e.parentRowId=void 0,a.push(e);continue}let n=t.slice(0,-1),i=r.get(kd(n));if(!i)throw new Ad(`[TreeBuildStage] missing parent path: ${n.join(`/`)}`);e.parentRowId=i.id,i.treeLeaf=!1,i.childrenAfterTree.push(e)}return{roots:a,nodeByPath:r}}function Md(e){function t(e){for(let n of e){let e=n.childrenAfterTree??[];e.length===0?n.treeLeaf=!0:(n.treeLeaf=!1,t(e))}}t(e)}function Nd(e){let{sourceRows:t,getDataPath:n}=e;if(t.length===0)return[];let{roots:r}=jd({sourceRows:t,getDataPath:n});return Md(r),r}var Pd=[...yi];function Fd(e,t){return e.length===1&&e[0]===`map`&&t!=null&&t.groupedTreeRoots!=null&&t.groupedTreeRoots.length>0&&Dc(t.groupedTreeRoots)}function Id(e,t){return e.length===1&&e[0]===`map`&&t!=null&&t.treeTreeRoots!=null&&t.treeTreeRoots.length>0&&Fc(t.treeTreeRoots)}function Ld(e,t){if(t)return t.getMapStageOptions?.()??t.mapStageOptions;if(e)return e.getMapStageOptions?.()??e.mapStageOptions}function Rd(e){let t=e.stages??Pd,n=e.grouping,r=e.tree,i=[...e.sourceRows];if(Fd(t,n)&&n?.groupedTreeRoots)i=md(n.groupedTreeRoots,Ld(n,void 0));else if(Id(t,r)&&r?.treeTreeRoots)i=md(r.treeTreeRoots,Ld(void 0,r));else for(let a of t)switch(a){case`tree`:i=r?.getDataPath?Nd({sourceRows:e.sourceRows,getDataPath:r.getDataPath}):[...e.sourceRows];break;case`group`:i=n&&n.rowGroupColumns.length>0?bc({sourceRows:e.sourceRows,rowGroupColumns:n.rowGroupColumns,getCellValue:e.getCellValue,groupKeyCreator:n.groupKeyCreator,groupComparator:n.groupComparator,getColumnField:n.getColumnField}):[...e.sourceRows];break;case`filter`:i=Gu({rows:i,filterModel:e.filterModel,getCellValue:e.getCellValue,columnContext:e.filterColumnContext,quickFilterText:e.quickFilterText,quickFilterColIds:e.getQuickFilterColIds?.()??[]});break;case`sort`:i=xd({sourceRows:e.sourceRows,rows:i,currentDisplayRows:e.currentDisplayRows,sortModel:e.sortModel,touchedRowIds:e.touchedRowIds,getCellValue:e.getCellValue,getColumnComparator:e.getColumnComparator,groupComparator:n?.groupComparator});break;case`aggregate`:n&&Dc(i)&&(i=cd({rows:i,columns:n.columns}));break;case`map`:n?.prepareGroupedTree&&Dc(i)&&n.prepareGroupedTree(i),r?.prepareTreeTree&&Fc(i)&&r.prepareTreeTree(i),i=md(i,Ld(n,r))}return e.afterMap&&(i=e.afterMap(i)),e.positionRowsOptions?gc(i,e.positionRowsOptions):gc(i,e.rowHeight),i}function zd(e){return[...bi(e)]}var Bd=class{refreshing=!1;pendingRun=null;refresh(e){if(this.refreshing){this.pendingRun=e;return}this.refreshing=!0;try{let t=e;for(;t;){let e=t;t=null,e(),t=this.pendingRun,this.pendingRun=null}}finally{this.refreshing=!1}}reset(){this.refreshing=!1,this.pendingRun=null}};function Vd(e,t){for(let n of e)n.group&&(t(n),Vd(jc(n),t))}function Hd(e){let t=[];return Vd(e,e=>{e.groupId&&t.push(e.groupId)}),t}function Ud(e,t){let n;return Vd(e,e=>{e.groupId===t&&(n=e)}),n}function Wd(e,t){return t===0?!1:t===-1||e<t}var Gd=class extends Error{constructor(e){super(e),this.name=`RowModelError`}};function Kd(e,t){let{rowKey:n,rowHeight:r=m,allowTransient:i=!1}=t;if(!n)throw new Gd(`rowKey is required`);let a=new Set,o=Array(e.length);for(let t=0;t<e.length;t++){let s=e[t],c=s[n];if(yr(c)){if(!i)throw new Gd(`Missing rowKey "${n}" at index ${t}`);let e=_r();if(a.has(e))throw new Gd(`Duplicate transient row id "${e}" at index ${t}`);a.add(e),o[t]={id:e,data:s,isTransient:!0,rowTop:0,rowHeight:r,estimated:!1,rowIndex:t};continue}let l=String(c);if(a.has(l))throw new Gd(`Duplicate rowKey "${n}" value "${l}" at index ${t}`);a.add(l),o[t]={id:l,data:s,isTransient:!1,rowTop:0,rowHeight:r,estimated:!1,rowIndex:t}}return o}function qd(e,t,n){if(t.length===0)return[...e];let r=n??e.length,i=Math.max(0,Math.min(r,e.length));return[...e.slice(0,i),...t,...e.slice(i)]}function Jd(e,t){return Math.max(0,Math.min(e,t))}function Yd(e,t){if(typeof e==`string`)return e;let n=e[t];if(n==null)throw new Gd(`Missing rowKey "${t}" in remove item`);return String(n)}function Xd(e,t){if(typeof e!=`object`||!e||!(`data`in e))return!1;let n=e;return n[t]!==void 0&&n[t]!==null&&n[t]!==``?!1:typeof e.data==`object`&&e.data!==null}function Zd(e,t){return Xd(e,t)?e.data:e}function Qd(e,t){if(Xd(e,t))return e.index}function $d(e,t,n){let r=n.rowKey,i=n.rowHeight??m,a=new Map(e.map(e=>[e.id,e])),o={add:[],remove:[],update:[]},s=new Set;if(t.remove?.length)for(let e of t.remove){let t=Yd(e,r),n=a.get(t);n&&(o.remove.push(n),a.delete(t),s.add(t))}if(t.update?.length)for(let e of t.update){let t=e[r],n;if(t==null){if(n=[...a.values()].find(t=>t.data===e&&t.isTransient),!n)throw new Gd(`Missing rowKey "${r}" in update item`)}else n=a.get(String(t));n&&(n.data!==e&&Object.assign(n.data,e),o.update.push(n),s.add(n.id))}let c=new Set(o.remove.map(e=>e.id)),l=e.filter(e=>!c.has(e.id));if(t.add?.length)for(let e of t.add){let t=Zd(e,r),n=Qd(e,r),[c]=Kd([t],{rowKey:r,rowHeight:i,allowTransient:!0});if(c){if(a.has(c.id))throw new Gd(`Duplicate rowKey on add: "${c.id}"`);a.set(c.id,c),o.add.push(c),s.add(c.id),l=qd(l,[c],n)}}return{sourceRows:l,transaction:o,touchedRowIds:[...s]}}function ef(e,t){if(t<0||t>=e.length)return null;let n=e[t];return{rowTop:n.rowTop,rowHeight:n.rowHeight}}function tf(e,t){let n=e.length;if(n===0||t<=0)return 0;let r=0,i=n-1;for(;r<=i;){let n=r+i>>1,a=e[n],o=a.rowTop+a.rowHeight;if(t<a.rowTop)i=n-1;else if(t>=o)r=n+1;else return n}return n-1}var nf=class{sourceRows=[];displayRows=[];baseDisplayRows=[];sortModel=[];filterModel={};quickFilterText=``;touchedRowIds=null;rowKey;defaultRowHeight;getCellValue;getColumnComparator;filterColumnContext;getQuickFilterColIds;refreshScheduler=new Bd;positionGetRowHeight;rowExpansionService=null;rowGroupingDeps=null;treeTableDeps=null;groupedTreeRoots=[];treeTreeRoots=[];constructor(e){this.rowKey=e.rowKey,this.defaultRowHeight=e.rowHeight??m,this.getCellValue=e.getCellValue??rf,this.getColumnComparator=e.getColumnComparator,this.filterColumnContext=e.filterColumnContext,this.getQuickFilterColIds=e.getQuickFilterColIds,this.quickFilterText=e.quickFilterText??``}get rowsToDisplay(){return this.displayRows}getBaseDisplayRows(){return this.baseDisplayRows}setRowExpansionService(e){this.rowExpansionService=e}getRowExpansionService(){return this.rowExpansionService}setRowGroupingDeps(e){this.rowGroupingDeps=e,e?.active()||(this.groupedTreeRoots=[])}setTreeTableDeps(e){this.treeTableDeps=e,e?.active()||(this.treeTreeRoots=[])}getTreeTreeRoots(){return this.treeTreeRoots}getGroupedTreeRoots(){return this.groupedTreeRoots}setPositionGetRowHeight(e){this.positionGetRowHeight=e}resolvePositionRowsOptions(){return{defaultRowHeight:this.defaultRowHeight,getRowHeight:this.positionGetRowHeight}}setData(e){this.sourceRows=Kd(e,{rowKey:this.rowKey,rowHeight:this.defaultRowHeight}),this.touchedRowIds=null,this.rowExpansionService?.clearExpanded(),this.rowGroupingDeps?.clearExpanded(),this.treeTableDeps?.clearExpanded(),this.groupedTreeRoots=[],this.treeTreeRoots=[],this.refreshModel({applyDefaultExpanded:!0})}setSortModel(e){this.sortModel=[...e],this.touchedRowIds=null,this.refreshModel()}setFilterModel(e){this.filterModel={...e},this.refreshModel()}getSortModel(){return[...this.sortModel]}getFilterModel(){return{...this.filterModel}}getQuickFilterText(){return this.quickFilterText}setQuickFilterText(e){this.quickFilterText!==e&&(this.quickFilterText=e,this.refreshModel())}markTouchedRowIds(e){this.touchedRowIds=new Set(e)}applyTransaction(e){let{sourceRows:t,transaction:n,touchedRowIds:r}=$d(this.sourceRows,e,{rowKey:this.rowKey,rowHeight:this.defaultRowHeight});return this.sourceRows=t,this.markTouchedRowIds(r),this.refreshModel(),n}rebuildDisplayProjection(){if(this.treeTableDeps?.active()){this.rebuildTreeMapProjection();return}if(this.rowGroupingDeps?.active()){this.rebuildGroupedMapProjection();return}this.displayRows=this.buildProjectedDisplayRows(!1),gc(this.displayRows,this.resolvePositionRowsOptions())}rebuildTreeMapProjection(){if(this.treeTableDeps?.active()){if(this.treeTreeRoots.length===0||!Fc(this.treeTreeRoots)){this.refreshModel();return}this.refreshModel({stages:[`map`]})}}rebuildGroupedMapProjection(){if(this.rowGroupingDeps?.active()){if(this.groupedTreeRoots.length===0||!this.groupedTreeRoots.some(e=>e.group)){this.refreshModel();return}this.refreshModel({stages:[`map`]})}}getRowById(e){return this.sourceRows.find(t=>t.id===e)}resolveRowById(e){return this.getRowById(e)??this.getDisplayRowById(e)}getDisplayRowById(e){return this.displayRows.find(t=>t.id===e)}setDefaultRowHeight(e){this.defaultRowHeight=Math.max(1,e)}repositionDisplayRows(e){gc(this.displayRows,{defaultRowHeight:this.defaultRowHeight,getRowHeight:e?.getRowHeight??this.positionGetRowHeight})}getRowIndexById(e){return this.displayRows.findIndex(t=>t.id===e)}refreshModel(e={}){let t=typeof e==`boolean`?{applyDefaultExpanded:e}:e,n=t.applyDefaultExpanded??!1,r=this.rowGroupingDeps?.active()??!1,i=this.treeTableDeps?.active()??!1,a=i?`tree`:r?`group`:`flat`,o=t.stages??zd(a);this.refreshScheduler.refresh(()=>{let e=this.rowGroupingDeps,t=this.treeTableDeps,s=n;this.displayRows=Rd({sourceRows:this.sourceRows,currentDisplayRows:this.displayRows,sortModel:this.sortModel,filterModel:this.filterModel,touchedRowIds:this.touchedRowIds??void 0,getCellValue:this.getCellValue,getColumnComparator:this.getColumnComparator,filterColumnContext:this.filterColumnContext,quickFilterText:this.quickFilterText,getQuickFilterColIds:this.getQuickFilterColIds,rowHeight:this.defaultRowHeight,positionRowsOptions:this.resolvePositionRowsOptions(),stages:o,hierarchyMode:a,grouping:r&&e?{rowGroupColumns:e.getRowGroupColumns(),groupKeyCreator:e.getGroupKeyCreator(),groupComparator:e.getGroupComparator(),getColumnField:e.getColumnField,columns:e.getColumns(),getMapStageOptions:()=>({...e.getMapStageOptions(),defaultRowHeight:this.defaultRowHeight}),groupedTreeRoots:this.groupedTreeRoots,prepareGroupedTree:t=>{this.groupedTreeRoots=[...t],e.pruneExpanded(new Set(Hd(t))),s&&=(e.applyDefaultExpanded(t),!1)}}:void 0,tree:i&&t?{getDataPath:t.getDataPath(),getMapStageOptions:()=>({...t.getMapStageOptions(),defaultRowHeight:this.defaultRowHeight}),treeTreeRoots:this.treeTreeRoots,prepareTreeTree:e=>{this.treeTreeRoots=[...e],t.prepareTreeTree(e),s&&=(t.applyDefaultExpanded(e),!1)}}:void 0,afterMap:e=>this.buildProjectedDisplayRows(n,e)}),this.touchedRowIds=null})}buildProjectedDisplayRows(e,t=this.baseDisplayRows){return this.baseDisplayRows=t,this.rowExpansionService?.active?(e&&this.rowExpansionService.applyDefaultExpanded(t),this.rowExpansionService.pruneExpanded(new Set(this.sourceRows.map(e=>e.id))),this.rowExpansionService.injectDetailRows(t)):t.slice()}getRow(e){return this.displayRows[e]}getRowCount(){return this.displayRows.length}getSourceRowCount(){return this.sourceRows.length}getSourceRows(){return this.sourceRows}getSourceRowIndexById(e){return this.sourceRows.findIndex(t=>t.id===e)}setSourceRows(e){this.sourceRows=e,this.touchedRowIds=null,this.refreshModel()}getRowKey(){return this.rowKey}promoteRowId(e,t){let n=this.getRowById(e);if(!n)return{ok:!1,reason:`Row "${e}" not found`};if(!n.isTransient)return{ok:!1,reason:`Row "${e}" is not transient`};if(yr(t))return{ok:!1,reason:`businessId is required`};let r=String(t);return this.sourceRows.some(e=>e!==n&&e.id===r)?{ok:!1,reason:`Duplicate row id "${r}"`}:(n.data[this.rowKey]=t,n.id=r,n.isTransient=!1,this.markTouchedRowIds([r]),this.refreshModel(),{ok:!0,rowId:r})}getRowIndexAtPixel(e){return tf(this.displayRows,e)}getRowBounds(e){return ef(this.displayRows,e)}getTotalHeight(){return _c(this.displayRows)}ensureRowHeightsValid(e,t){return!1}};function rf(e,t){return e.data[t]}function af(e,t){if(t.length===0)return!1;let n=e.__autoHeights??{};return t.some(e=>n[e]==null)}function of(e){if(!e.getRowHeight)return;let t=e.getRowHeight;return e=>t({rowId:e.id,data:e.data,rowIndex:e.rowIndex})}function sf(e,t,n){if(e.rowHeightPinned&&e.rowHeight>0)return{height:ea(e.rowHeight,n.rowHeightMin,n.rowHeightMax),estimated:!1};let r=pc(e,t,of(n));return{height:ea(r.height,n.rowHeightMin,n.rowHeightMax),estimated:r.estimated}}function cf(e,t,n){if(e.rowHeightPinned)return!1;let r=of(n)?.(e);return r!=null&&r>0||e.__autoHeights&&Object.keys(e.__autoHeights).length>0?!1:e.rowHeight===t||e.rowHeight===0}function lf(e,t){return t??(e===`api`||e===`uiRowResized`)}var uf=class{deps;defaultRowHeight;options;gridOptions;constructor(e,t,n={}){this.deps=e,this.defaultRowHeight=t,this.gridOptions=n,this.options=Zi(n,t)}getDefaultRowHeight(){return this.defaultRowHeight}setGridOptions(e={}){this.gridOptions=e,this.options=Zi(e,this.defaultRowHeight)}getOptions(){return this.options}updateDefaultRowHeight(e,t={}){let n=this.defaultRowHeight,r=Math.max(1,e);if(this.gridOptions={...this.gridOptions,...t},this.defaultRowHeight=r,this.options=Zi(this.gridOptions,r),n===r)return this.recalculateDisplayRowHeights(void 0,`dimensions`);for(let e of this.deps.getDisplayRows())cf(e,n,this.options)&&(e.rowHeight=0,e.estimated=!1);let i=this.recalculateDisplayRowHeights(void 0,`dimensions`);return i.changed||this.deps.repositionDisplayRows(),i}getRowHeight(e){let t=this.deps.getRowById(e);return t?sf(t,this.defaultRowHeight,this.options).height:null}setRowHeights(e,t){let n=[],r=lf(t.source,t.pin);for(let t of e){let e=this.deps.getRowById(t.rowId);if(!e)continue;let i=ea(t.height,this.options.rowHeightMin,this.options.rowHeightMax),a=r;(e.rowHeight!==i||e.rowHeightPinned!==a)&&(e.rowHeight=i,e.rowHeightPinned=a,e.estimated=!1,n.push({rowId:e.id,rowHeight:i}))}if(n.length===0)return{changed:!1,rows:[],finished:t.finished,source:t.source};this.deps.repositionDisplayRows();let i=ta(n,t.finished,t.source);return this.deps.emitRowHeightChanged(i),{changed:!0,rows:n,finished:t.finished,source:t.source}}setRowHeight(e,t,n=!0,r=`api`){return this.setRowHeights([{rowId:e,height:t}],{finished:n,source:r})}resetRowHeights(e){let t=this.resolveResetTargets(e),n=[];for(let e of t){e.rowHeightPinned=!1,delete e.__autoHeights,e.rowHeight=0,e.estimated=!1;let t=sf(e,this.defaultRowHeight,this.options);e.rowHeight=t.height,e.estimated=t.estimated,n.push({rowId:e.id,height:t.height})}if(n.length===0)return{changed:!1,rows:[],finished:!0,source:`api`};this.deps.repositionDisplayRows();let r=n.map(e=>({rowId:e.rowId,rowHeight:e.height})),i=ta(r,!0,`api`);return this.deps.emitRowHeightChanged(i),{changed:!0,rows:r,finished:!0,source:`api`}}recalculateDisplayRowHeights(e,t=`autoHeight`){let n=e?new Set(e):null,r=[];for(let e of this.deps.getDisplayRows()){if(n&&!n.has(e.id)||e.rowHeightPinned)continue;let t=sf(e,this.defaultRowHeight,this.options),i=this.deps.getAutoHeightColumnIds?.()??[],a=t.estimated;!e.rowHeightPinned&&i.length>0&&af(e,i)&&(a=!0),(e.rowHeight!==t.height||e.estimated!==a)&&(e.rowHeight=t.height,e.estimated=a,r.push({rowId:e.id,rowHeight:t.height}))}if(r.length===0)return{changed:!1,rows:[],finished:!0,source:t};this.deps.repositionDisplayRows();let i=ta(r,!0,t);return this.deps.emitRowHeightChanged(i),{changed:!0,rows:r,finished:!0,source:t}}getPositionRowHeightFn(){return of(this.options)}resolveResetTargets(e){return e&&e.length>0?e.map(e=>this.deps.getRowById(e)).filter(e=>e!=null):[...this.deps.getDisplayRows()]}};function df(e){return e.classList.contains(`mg-cell--editing`)||e.classList.contains(`mg-cell--inline-editor`)}function ff(e){if(df(e))return 0;let t=pf(e);if(!t)return e.offsetHeight;let n=getComputedStyle(e),r=Number.parseFloat(n.paddingTop)||0,i=Number.parseFloat(n.paddingBottom)||0,a=Number.parseFloat(n.borderTopWidth)||0,o=Number.parseFloat(n.borderBottomWidth)||0,s=t.scrollHeight;return Math.ceil(s+r+i+a+o)}function pf(e){return[e.querySelector(`.mg-cell__text:not([hidden])`),e.querySelector(`.mg-cell__renderer:not([hidden])`),e.querySelector(`.mg-cell__inline-editor:not([hidden])`)].find(e=>e!=null)??null}var mf=5,hf=1,gf=class{deps;active=!1;wasEverActive=!1;debounceTimer=null;pendingRowIds=new Set;constructor(e){this.deps=e}isActive(){return this.active}setCellHeight(e,t,n){if(!this.deps.isColumnAutoHeight(t))return;let r=this.deps.getRowById(e);if(!r)return;if(r.__autoHeights??={},n==null){r.__autoHeights[t]!=null&&(delete r.__autoHeights[t],Object.keys(r.__autoHeights).length===0&&delete r.__autoHeights,r.rowHeightPinned||this.requestCheckAutoHeight(e));return}if(r.rowHeightPinned)return;let i=r.__autoHeights[t];r.__autoHeights[t]=n,this.active=!0,this.wasEverActive=!0,i!==n&&this.requestCheckAutoHeight(e)}setupCellAutoHeight(e){if(!this.deps.isColumnAutoHeight(e.colId))return null;this.active=!0,this.wasEverActive=!0;let{rowId:t,colId:n,cellEl:r}=e;r.classList.add(Xi);let i=(e=0)=>{if(r.classList.contains(`mg-cell--editing`))return;let a=ff(r);if(a<=0&&e<mf){window.setTimeout(()=>i(e+1),0);return}a>0&&this.setCellHeight(t,n,a)};i();let a=pf(r),o=a&&typeof ResizeObserver<`u`?new ResizeObserver(()=>{r.classList.contains(`mg-cell--editing`)||i()}):null;o?.observe(a??r);let s=typeof MutationObserver<`u`?new MutationObserver(()=>{r.classList.contains(`mg-cell--editing`)||i()}):null;return s?.observe(r,{attributes:!0,attributeFilter:[`class`]}),()=>{o?.disconnect(),s?.disconnect(),r.classList.remove(Xi),this.setCellHeight(t,n,void 0)}}requestCheckAutoHeight(e){this.wasEverActive&&(this.pendingRowIds.add(e),this.scheduleRecalculate())}flushPendingRecalculate(){if(this.pendingRowIds.size===0)return;let e=[...this.pendingRowIds];this.pendingRowIds.clear(),this.deps.rowHeightService.recalculateDisplayRowHeights(e)}destroy(){this.debounceTimer!=null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingRowIds.clear(),this.active=!1}scheduleRecalculate(){this.debounceTimer??=window.setTimeout(()=>{this.debounceTimer=null,this.flushPendingRecalculate()},hf)}};function _f(e){let t=new Set;if(e.lastRow<e.firstRow)return t;for(let n=e.firstRow;n<=e.lastRow;n++)t.add(n);return t}function vf(e,t){let n=_f(t),r=[],i=[],a=[];for(let t of n)e.has(t)?i.push(t):r.push(t);for(let t of e)n.has(t)||a.push(t);return{toCreate:r,toUpdate:i,toDestroy:a}}var yf=3;function bf(e,t,n){let r=e.getRowCount();if(r===0)return t;let i=e.getTotalHeight()/r,a=e.getRowIndexAtPixel(n),o=e.getRowBounds(a)?.rowHeight??t;return Math.max(t,i,o)}function xf(e,t,n,r,i){let a=e.getRowCount(),o=t,s=n;for(;o>0;){let t=e.getRowBounds(o);if(!t||t.rowTop<=r)break;o--}for(;s<a-1;){let t=e.getRowBounds(s);if(!t||t.rowTop+t.rowHeight>=i)break;s++}return{firstRow:o,lastRow:s}}function Sf(e,t,n){for(let r=t;r<=n;r++)if(e.getRow(r)?.estimated)return!0;return!1}function Cf(e,t,n,r){let i=Math.max(n,500);return t-e+1<=i?t:Math.min(e+i-1,r-1)}function wf(e){let{scrollTop:t,viewportHeight:n,rowBuffer:r,rowHeight:i,rowModel:a}=e,o=a.getRowCount();if(o===0)return{firstRow:0,lastRow:-1};let s=0,c=o-1,l=!1;for(let e=0;e<yf&&!l;e++){let e=r*bf(a,i,t),u=Math.max(0,t-e),d=t+n+e;s=a.getRowIndexAtPixel(u),c=Math.min(a.getRowIndexAtPixel(d),o-1);let f=xf(a,s,c,u,d);s=f.firstRow,c=f.lastRow,l=!Sf(a,s,c)}return c=Cf(s,c,r,o),{firstRow:s,lastRow:c}}var Tf=class{pool=new Map;acquire(e,t){let n=this.pool.get(e);if(n)return n;let r=t();return this.pool.set(e,r),r}get(e){return this.pool.get(e)}release(e){let t=this.pool.get(e);t&&(t.destroy(),this.pool.delete(e))}migrateId(e,t){if(e===t)return;let n=this.pool.get(e);n&&(this.pool.delete(e),this.pool.set(t,n))}clear(){for(let e of this.pool.values())e.destroy();this.pool.clear()}getActiveCount(){return this.pool.size}getActiveIds(){return[...this.pool.keys()]}},Ef=`mg-selection-checkbox`,Df=`mg-selection-checkbox--header`;function Of(e){let t=document.createElement(`input`);return t.type=`checkbox`,t.className=Ef,t.setAttribute(`aria-label`,e.ariaLabel),kf(t,e),t}function kf(e,t){e.checked=t.checked,e.indeterminate=!!t.indeterminate,e.disabled=!!t.disabled,e.classList.toggle(`mg-selection-checkbox--disabled`,!!t.disabled),e.setAttribute(`aria-checked`,t.indeterminate?`mixed`:String(t.checked))}function Af(e){return e.querySelector(`input.${Ef}`)}function jf(e,t){return t.rowLabel?.(e)??`选择第 ${e+1} 行`}function Mf(e,t,n=new Set){let r=e.getRowCount();if(r===0)return{checked:!1,indeterminate:!1};let i=0,a=0;for(let o=0;o<r;o+=1){let r=e.getRow(o);r&&(Xt(r)||B(r)||(i++,t.has(r.id)&&!n.has(r.id)&&a++))}return a===0?{checked:!1,indeterminate:!1}:a===i?{checked:!0,indeterminate:!1}:{checked:!1,indeterminate:!0}}function Nf(e,t){let{selectionColumnOptions:n,selectedIds:r,indeterminateIds:i,rowModel:a}=t;if(!n.enabled||n.mode!==`multiple`)return;let o=e.querySelector(`.mg-header-cell[data-col-id="${ze}"]`);if(!o)return;let s=Af(o);s&&kf(s,Mf(a,r,i??new Set))}var Pf=[[`circle`,{cx:`12`,cy:`12`,r:`1`}],[`circle`,{cx:`12`,cy:`5`,r:`1`}],[`circle`,{cx:`12`,cy:`19`,r:`1`}]],Ff=[[`path`,{d:`m5 12 7-7 7 7`}],[`path`,{d:`M12 19V5`}]],If=[[`path`,{d:`M12 5v14`}],[`path`,{d:`m19 12-7 7-7-7`}]],Lf=[[`path`,{d:`M12 2v20`}],[`path`,{d:`m15 19-3 3-3-3`}],[`path`,{d:`m19 9 3 3-3 3`}],[`path`,{d:`M2 12h20`}],[`path`,{d:`m5 9-3 3 3 3`}],[`path`,{d:`m9 5 3-3 3 3`}]],Rf=[[`path`,{d:`M3 6h18`}],[`path`,{d:`M7 12h10`}],[`path`,{d:`M10 18h4`}]],zf=[[`path`,{d:`M12 17v5`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v3.76`}]],Bf=[[`path`,{d:`M12 17v5`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v3.76`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`}]],Vf=[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}],[`path`,{d:`M9 3v18`}]],Hf=[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}],[`path`,{d:`M15 3v18`}]],Uf=[[`path`,{d:`m9 18 6-6-6-6`}]],Wf=[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}],[`path`,{d:`M9 3v18`}],[`path`,{d:`M15 3v18`}]],Gf=[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`}]],Kf=[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`}],[`path`,{d:`m2 2 20 20`}]],qf=[[`path`,{d:`M12 2v4`}],[`path`,{d:`m16.2 7.8 2.9-2.9`}],[`path`,{d:`M18 12h4`}],[`path`,{d:`m16.2 16.2 2.9 2.9`}],[`path`,{d:`M12 18v4`}],[`path`,{d:`m7.8 16.2-2.9 2.9`}],[`path`,{d:`M2 12h4`}],[`path`,{d:`m7.8 7.8-2.9-2.9`}]];function Z(e,t,n=14){let r=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);r.setAttribute(`class`,e),r.setAttribute(`width`,String(n)),r.setAttribute(`height`,String(n)),r.setAttribute(`viewBox`,`0 0 24 24`),r.setAttribute(`fill`,`none`),r.setAttribute(`stroke`,`currentColor`),r.setAttribute(`stroke-width`,`2`),r.setAttribute(`stroke-linecap`,`round`),r.setAttribute(`stroke-linejoin`,`round`),r.setAttribute(`aria-hidden`,`true`);for(let[e,n]of t){let t=document.createElementNS(`http://www.w3.org/2000/svg`,e);for(let[e,r]of Object.entries(n))t.setAttribute(e,String(r));r.appendChild(t)}return r}function Jf(){return Z(`mg-header-icon mg-header-icon--column-handle`,Pf,14)}function Yf(e){let t=e===`asc`?Ff:If;return Z(`mg-sort-icon mg-sort-icon--${e}`,t,14)}function Xf(){let e=document.createDocumentFragment();return e.append(Yf(`asc`),Yf(`desc`)),e}function Zf(){return Z(`mg-column-drag-ghost__move-icon`,Lf,16)}function Qf(){return Z(`mg-header-icon mg-header-icon--floating-filter`,Rf,14)}function $f(){return Yf(`asc`)}function ep(){return Yf(`desc`)}function tp(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--pin`,zf,14)}function np(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--pin-off`,Bf,14)}function rp(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--pin-left`,Vf,14)}function ip(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--pin-right`,Hf,14)}function ap(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--chevron`,Uf,14)}function op(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--visibility`,Wf,14)}function sp(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--hide-column`,Kf,14)}function cp(){return Z(`mg-column-handle-menu__icon mg-column-handle-menu__icon--show-column`,Gf,14)}function lp(){return Z(`mg-cell__row-expand__icon`,Uf,16)}function up(){return Z(`mg-cell__tree-expand__loading-icon`,qf,16)}function dp(e,t){return t?`折叠第 ${e+1} 行详情`:`展开第 ${e+1} 行详情`}function fp(){let e=document.createElement(`button`);return e.type=`button`,e.className=Je,e.setAttribute(`aria-expanded`,`false`),e.appendChild(lp()),e}function pp(e,t){if(!t.visible){e.hidden=!0,e.classList.remove(Ye),e.setAttribute(`aria-expanded`,`false`);return}e.hidden=!1,e.setAttribute(`aria-label`,t.ariaLabel),e.setAttribute(`aria-expanded`,String(t.expanded)),e.classList.toggle(Ye,t.expanded)}var mp=`mg-cell__group-content`,hp=`mg-cell__group-label`,gp=`mg-cell__group-count`;function _p(e,t,n){let r=n>0?`,${n} 条`:``;return t?`折叠分组 ${e}${r}`:`展开分组 ${e}${r}`}function vp(e,t){return e.groupFooterLabel??t.getGroupFooterLabel?.()??`小计`}function yp(e,t){return Yt(t)&&e.showGroupFooterCell&&!Et(e)}function bp(e,t,n){let r={visible:!1,showChevron:!1,expanded:!1,indentLevel:0,label:``,showCount:!1,count:0,ariaLabel:``};if(!t.active())return r;if(Jt(e)){if(n&&!Pt(n))return r;let i=e.sourceGroupId??qt(e.id)??e.groupId??``,a=e.groupKey??``,o=e.groupLeafCount??0,s=i?t.isExpanded(i):!1;return{visible:!0,showChevron:!!i,expanded:s,indentLevel:e.groupLevel??0,label:a,showCount:o>0,count:o,ariaLabel:_p(a,s,o)}}if(Yt(e)){if(n&&!Ft(n))return r;let i=n?vp(n,t):t.getGroupFooterLabel?.()??`小计`;return{visible:!0,showChevron:!1,expanded:!1,indentLevel:e.groupLevel??0,label:i,showCount:!1,count:0,ariaLabel:i}}return Zt(e),r}function xp(e){return`(${e})`}function Sp(){let e=document.createElement(`button`);return e.type=`button`,e.className=yt,e.setAttribute(`aria-expanded`,`false`),e.appendChild(lp()),e}function Cp(e,t){if(!t.showChevron){e.hidden=!0,e.classList.remove(bt),e.setAttribute(`aria-expanded`,`false`);return}e.hidden=!1,e.setAttribute(`aria-label`,t.ariaLabel),e.setAttribute(`aria-expanded`,String(t.expanded)),e.classList.toggle(bt,t.expanded)}function wp(e,t){for(let t=e.classList.length-1;t>=0;--t){let n=e.classList.item(t);n?.startsWith(`mg-cell__group-indent-`)&&e.classList.remove(n)}e.classList.add(`${xt}${Math.max(0,t)}`),e.style.paddingLeft=`${Math.max(0,t)*16}px`}function Tp(e,t,n,r,i){e.classList.toggle(wt,i.visible),wp(e,i.indentLevel),t&&Cp(t,i),n.textContent=i.label,n.hidden=i.label.length===0,i.showCount&&i.count>0?(r.textContent=xp(i.count),r.hidden=!1):(r.textContent=``,r.hidden=!0)}function Ep(e,t){return ln(e.colId)&&H(t)}function Dp(e,t){return t?`折叠 ${e}`:`展开 ${e}`}function Op(e,t){let n={visible:!1,showChevron:!1,expanded:!1,indentLevel:0,label:``,showCount:!1,count:0,ariaLabel:``};if(!t.active()||!H(e))return n;let r=t.getTreeValue?.(e)??e.dataPath?.[e.dataPath.length-1]??``,i=t.isExpanded(e.id),a=t.isTreeNodeLoading?.(e.id)??!1;return{visible:!0,showChevron:t.isTreeNodeExpandable?.(e)??e.treeLeaf!==!0,expanded:i,loading:a,indentLevel:e.treeLevel??0,label:r,showCount:!1,count:0,ariaLabel:Dp(r,i)}}function kp(){let e=Sp();return e.className=tn,e}function Ap(e,t){if(jp(e,!!t.loading),!t.showChevron){e.hidden=!0,e.classList.remove(nn,rn),e.disabled=!1,e.setAttribute(`aria-expanded`,`false`),e.setAttribute(`aria-busy`,`false`);return}e.hidden=!1,e.setAttribute(`aria-label`,t.ariaLabel),e.setAttribute(`aria-expanded`,String(t.expanded&&!t.loading)),e.classList.toggle(nn,t.expanded&&!t.loading),e.classList.toggle(rn,!!t.loading),e.disabled=!!t.loading,e.setAttribute(`aria-busy`,t.loading?`true`:`false`)}function jp(e,t){let n=e.querySelector(`.mg-cell__row-expand__icon`),r=e.querySelector(`.mg-cell__tree-expand__loading-icon`);if(t){if(n instanceof SVGElement&&n.setAttribute(`hidden`,`hidden`),!(r instanceof SVGElement)){e.appendChild(up());return}r.removeAttribute(`hidden`);return}if(r instanceof SVGElement&&r.remove(),n instanceof SVGElement){n.removeAttribute(`hidden`);return}e.appendChild(lp())}function Mp(e,t){for(let t=e.classList.length-1;t>=0;--t){let n=e.classList.item(t);(n?.startsWith(`mg-cell__tree-indent-`)||n?.startsWith(`mg-cell__group-indent-`))&&e.classList.remove(n)}e.classList.add(`${an}${Math.max(0,t)}`),e.style.paddingLeft=`${Math.max(0,t)*16}px`}function Np(e,t,n,r){e.classList.toggle(on,r.visible),e.classList.toggle(wt,r.visible),Mp(e,r.indentLevel),t&&Ap(t,r),n.textContent=r.label,n.hidden=r.label.length===0}function Pp(e,t,n,r){if(r){if(t)return t;let r=kp();return e.insertBefore(r,n),r}return t&&t.remove(),null}function Fp(e,t,n,r){if(r){if(t)return t;let r=Sp();return e.insertBefore(r,n),r}return t&&t.remove(),null}function Ip(e,t){return e===t}var Lp=class{cachedValue=``;cachedRenderKey=``;cacheVersion=-1;inlineSession=null;activeResolveBusinessRowId;pendingVueRendererContext=null;refreshCell(e,t,n,r,i=!1){let a=typeof i==`boolean`?{force:i}:i,o=a.force??!1;this.activeResolveBusinessRowId=a.resolveBusinessRowId;let s=a.cellDisableContext??a.getCellDisableContext?.(),c=a.cellStyleContext??a.getCellStyleContext?.(),l=a.indexColumnOptions,u=a.selectionColumnOptions;if(Sn(t.colId,e.rowKind,t.prop,e.id)&&this.syncCellDisabledVisual(e,t,n,s),this.syncCellStyleVisual(e,t,n,c),R(t.colId))return this.clearInlineSession(n),this.refreshSelectionCell(e,t,n,r,o,u,a.selectionChecked??!1,a.selectionDisabled??!1,a.selectionIndeterminate??!1);if(nt(t)&&a.rowExpansionHost?.active())return this.clearInlineSession(n),this.refreshExpandCell(e,t,n,r,o,a.rowExpansionHost);if(It(t,e)&&a.rowGroupingHost?.active())return this.clearInlineSession(n),this.refreshGroupCell(e,t,n,r,o,a.rowGroupingHost);if(Ep(t,e)&&a.treeTableHost?.active())return this.clearInlineSession(n),this.refreshTreeCell(e,n,r,o,a.treeTableHost);if(!L(t.colId)&&ka(t)&&a.inlineEditor)return this.refreshInlineEditorCell(e,t,n,r,o,a.inlineEditor,a,a.scheduleInlineEditor);if(this.clearInlineSession(n),!L(t.colId)&&t.cellRenderer)return this.refreshRendererCell(e,t,n,r,o,a.scheduleRenderer,a.cellRendererDefer,a.cellRendererPresentation,a.scrollActive,l);let d=sr(e,t,l);return!o&&this.cacheVersion===r&&Ip(this.cachedValue,d)?!1:(n.clearRenderer(),this.cachedValue=d,this.cachedRenderKey=``,this.cacheVersion=r,n.setValue(d),!0)}syncCellDisabledVisual(e,t,n,r){let i=En(t,e,r);n.setCellDisabled(i)}syncCellStyleVisual(e,t,n,r){let i=Qn(t,e,r);n.setCellStyle(i)}invalidate(){this.cacheVersion=-1,this.cachedRenderKey=``,this.inlineSession=null,this.pendingVueRendererContext=null}hasPendingVueRenderer(){return this.pendingVueRendererContext!==null}promoteVueRenderer(e,t,n={}){let r=this.pendingVueRendererContext;if(!r)return!1;this.pendingVueRendererContext=null,this.cachedRenderKey.endsWith(`:placeholder`)&&(this.cachedRenderKey=this.cachedRenderKey.slice(0,-12));let i=()=>{this.applyRenderer(r.column,t,r.params)};return n.scheduleRenderer&&Rl(r.cellRendererPresentation,r.cellRendererDefer,r.column.cellRenderer,r.column.cellRendererMount)&&n.scheduleRenderer?(n.scheduleRenderer(i),!0):(i(),!0)}clearInlineSession(e){this.inlineSession&&(this.inlineSession.mounted.destroy(),this.inlineSession=null,e.clearInlineEditor())}refreshInlineEditorCell(e,t,n,r,i,a,o,s){let c=G(e,t),l=o.cellDisableContext??o.getCellDisableContext?.(),u=U(t,e,l),d=En(t,e,l),f=!u,p=ur(r,e.id,t.colId,c,u,d,t.cellEditor);if(!i&&this.cacheVersion===r&&this.cachedRenderKey===p&&this.inlineSession)return Rp(this.inlineSession.mounted,c,f),n.setInlineEditorDisabledVisual(d),!1;this.cachedRenderKey=p,this.cachedValue=String(c),this.cacheVersion=r;let m=()=>{this.mountInlineEditor(e,t,n,a,f,d)};return s?(s(m),!0):(m(),!0)}mountInlineEditor(e,t,n,r,i,a){this.clearInlineSession(n);let o=n;o.prepareForInlineEditor(a);let s=o.getInlineEditorMountEl(),c=null,l={...r.createParams(e,t),commit:async()=>{if(!c)return;let a=n;a.setInlineEditorCommitting(!0);let o=c.getFocusTarget();o instanceof HTMLInputElement&&(o.disabled=!0);try{let n=G(e,t);await r.commit(e,t,c.getValue(),n)||Rp(c,G(e,t),i)}finally{a.setInlineEditorCommitting(!1),o instanceof HTMLInputElement&&(o.disabled=i)}}};c=r.host.mount(s,t,l),this.inlineSession={renderKey:this.cachedRenderKey,mounted:c},Rp(c,l.value,i);let u=c.getFocusTarget();u instanceof HTMLInputElement&&(u.disabled=i)}refreshSelectionCell(e,t,n,r,i,a,o,s,c){let l=n;if(Xt(e)){let e=`group-row:no-selection`;return!i&&this.cacheVersion===r&&this.cachedValue===e?!1:(this.cachedValue=e,this.cachedRenderKey=``,this.cacheVersion=r,l.clearSelectionCheckbox(),l.setValue(``),!0)}let u=a?jf(e.rowIndex,a.selectionColumn):`选择第 ${e.rowIndex+1} 行`,d=`${o}:${s}:${c}:${u}`;return!i&&this.cacheVersion===r&&this.cachedValue===d?!1:(this.cachedValue=d,this.cachedRenderKey=``,this.cacheVersion=r,l.setSelectionCheckbox({checked:o,disabled:s,indeterminate:c,ariaLabel:u}),!0)}refreshExpandCell(e,t,n,r,i,a){let o=!B(e)&&a.isRowMaster(e),s=o&&a.isExpanded(e.id),c=dp(e.rowIndex,s),l=`${o}:${s}:${c}`;if(!i&&this.cacheVersion===r&&this.cachedValue===l)return!1;this.cachedValue=l,this.cachedRenderKey=``,this.cacheVersion=r;let u=n;return o?(u.setRowExpandButton({visible:!0,expanded:s,ariaLabel:c}),!0):(u.clearRowExpandButton(),u.setValue(``),!0)}refreshGroupCell(e,t,n,r,i,a){if(yp(t,e)){let e=vp(t,a);return!i&&this.cacheVersion===r&&this.cachedValue===e?!1:(this.cachedValue=e,this.cachedRenderKey=``,this.cacheVersion=r,n.setValue(e),!0)}let o=bp(e,a,t),s=[o.visible,o.showChevron,o.expanded,o.indentLevel,o.label,o.showCount,o.count,o.ariaLabel].join(`:`);if(!i&&this.cacheVersion===r&&this.cachedValue===s)return!1;this.cachedValue=s,this.cachedRenderKey=``,this.cacheVersion=r;let c=n;return o.visible?(c.setGroupCell(o),!0):(c.clearGroupCell(),c.setValue(``),!0)}refreshTreeCell(e,t,n,r,i){let a=Op(e,i),o=[`tree`,a.visible,a.showChevron,a.expanded,a.loading,a.indentLevel,a.label,a.ariaLabel].join(`:`);if(!r&&this.cacheVersion===n&&this.cachedValue===o)return!1;this.cachedValue=o,this.cachedRenderKey=``,this.cacheVersion=n;let s=t;return a.visible?(s.setTreeCell(a),!0):(s.clearGroupCell(),s.setValue(``),!0)}refreshRendererCell(e,t,n,r,i,a,o=`always`,s=`deferred`,c=!1,l){let u=sr(e,t,l),d=`${r}:${e.id}:${t.colId}:${u}`,f=Il(t.cellRenderer);if(!i&&this.cacheVersion===r&&this.cachedRenderKey===d&&!this.pendingVueRendererContext||!i&&this.cacheVersion===r&&this.cachedRenderKey===`${d}:placeholder`&&this.pendingVueRendererContext&&c)return!1;this.cachedValue=u,this.cacheVersion=r;let p={rowId:this.activeResolveBusinessRowId?.(e)??e.id,rowIndex:e.rowIndex,colId:t.colId,value:G(e,t),data:e.data,formattedValue:u};if(s===`placeholder-then-vue`&&f&&c)return this.cachedRenderKey=`${d}:placeholder`,this.pendingVueRendererContext={column:t,params:p,cellRendererDefer:o,cellRendererPresentation:s,indexColumnOptions:l},n.setRendererPlaceholder(u),!0;this.pendingVueRendererContext=null,this.cachedRenderKey=d;let m=()=>{this.applyRenderer(t,n,p)};return a&&Rl(s,o,t.cellRenderer,t.cellRendererMount)&&a?(a(m),!0):(m(),!0)}applyRenderer(e,t,n){let r=e.cellRenderer;if(!r)return;let i=t,a=Il(r);a&&i.canPatchVueRenderer(e.colId)?i.prepareForRendererPatch():i.prepareForRenderer();let o=t.getRendererMountEl(),s=r(n,{mountEl:o,clear:()=>{t.clearRenderer()}});a&&s==null&&i.markVueRendererMounted(e.colId),s!=null&&(typeof s==`string`||s instanceof HTMLElement)&&Do.apply(o,s)}};function Rp(e,t,n){let r=e.getFocusTarget();!(r instanceof HTMLInputElement)||r.type!==`checkbox`||(r.checked=j(t),r.disabled=n)}function zp(e,t){let n=e.masterRowId;if(!n)return null;let r=t?.(n);return{rowId:e.id,masterRowId:n,data:e.data,detailRowData:r?.__detailRowData,loading:r?.__detailLoading??!1,loadFailed:r?.__detailLoadError!==void 0,loadError:r?.__detailLoadError}}function Bp(e,t,n,r={}){let i=()=>{if(r.onUnmountRenderer?.(e),e.replaceChildren(),!n){t.loading?e.textContent=`Loading…`:t.loadFailed&&(e.textContent=`Failed to load detail`),r.onAfterRender?.();return}let i={mountEl:e,clear:()=>{r.onUnmountRenderer?.(e),e.replaceChildren()}},a=n(t,i);if(typeof a==`string`){i.clear(),e.textContent=a;return}a instanceof HTMLElement&&(i.clear(),e.appendChild(a)),r.onAfterRender?.()},a=r.rowIndex??0;if(r.frameService){r.frameService.createTask(i,a,`f1`);return}i()}function Vp(e,t){e.classList.toggle(Hl,t===`filled`),e.classList.toggle(Ul,t===`empty`),e.removeAttribute(`data-has-comment`),e.removeAttribute(`data-comment-empty`),t===`filled`?e.dataset.hasComment=`true`:t===`empty`&&(e.dataset.commentEmpty=`true`)}var Hp=class{element;textEl;rendererMount;inlineEditorMount;onUnmountRenderer;onUnmountEditor;selectionCheckbox=null;rowExpandButton=null;groupContentEl=null;groupExpandButton=null;groupLabelEl=null;groupCountEl=null;rowResizeHandle=null;rowDragHandle=null;usingRenderer=!1;usingInlineEditor=!1;vueRendererActive=!1;vueRendererColId;rendererPlaceholderActive=!1;lastCellStyle={};constructor(e,t={}){this.onUnmountRenderer=t.onUnmountRenderer,this.onUnmountEditor=t.onUnmountEditor,this.element=document.createElement(`div`),this.element.className=`mg-cell`,this.textEl=document.createElement(`span`),this.textEl.className=`mg-cell__text`,this.rendererMount=document.createElement(`div`),this.rendererMount.className=`mg-cell__renderer`,this.rendererMount.hidden=!0,this.inlineEditorMount=document.createElement(`div`),this.inlineEditorMount.className=`mg-cell__inline-editor`,this.inlineEditorMount.hidden=!0,this.element.append(this.textEl,this.rendererMount,this.inlineEditorMount),e.appendChild(this.element)}setLayout(e,t){Ao(this.element,{left:e,width:t,fixed:null},`mg-cell`)}setColumnLayout(e){Ao(this.element,e,`mg-cell`)}setValue(e){this.clearSelectionCheckbox(),this.clearRowExpandButton(),this.clearGroupCell(),this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!1,this.textEl.textContent!==e&&(this.textEl.textContent=e)}setSelectionCheckbox(e){if(this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,this.element.classList.toggle(`mg-cell--selection-disabled`,!!e.disabled),!this.selectionCheckbox){this.selectionCheckbox=Of(e),this.element.append(this.selectionCheckbox);return}kf(this.selectionCheckbox,e),this.selectionCheckbox.getAttribute(`aria-label`)!==e.ariaLabel&&this.selectionCheckbox.setAttribute(`aria-label`,e.ariaLabel)}clearSelectionCheckbox(){this.selectionCheckbox&&=(this.selectionCheckbox.remove(),null)}getSelectionCheckbox(){return this.selectionCheckbox}setRowExpandButton(e){if(this.clearInlineEditor(),this.clearRenderer(),this.clearGroupCell(),this.textEl.hidden=!0,this.textEl.textContent=``,!e.visible){this.clearRowExpandButton();return}this.rowExpandButton||(this.rowExpandButton=fp(),this.element.append(this.rowExpandButton)),pp(this.rowExpandButton,e)}clearRowExpandButton(){this.rowExpandButton&&=(this.rowExpandButton.remove(),null)}getRowExpandButton(){return this.rowExpandButton}setGroupCell(e){if(this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,!e.visible){this.clearGroupCell();return}this.groupContentEl||(this.groupContentEl=document.createElement(`div`),this.groupContentEl.className=mp,this.groupLabelEl=document.createElement(`span`),this.groupLabelEl.className=hp,this.groupCountEl=document.createElement(`span`),this.groupCountEl.className=gp,this.groupContentEl.append(this.groupLabelEl,this.groupCountEl),this.element.append(this.groupContentEl)),this.groupExpandButton=Fp(this.groupContentEl,this.groupExpandButton,this.groupLabelEl,e.showChevron),Tp(this.groupContentEl,this.groupExpandButton,this.groupLabelEl,this.groupCountEl,e)}setTreeCell(e){if(this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,!e.visible){this.clearGroupCell();return}this.groupContentEl||(this.groupContentEl=document.createElement(`div`),this.groupContentEl.className=mp,this.groupLabelEl=document.createElement(`span`),this.groupLabelEl.className=hp,this.groupCountEl=document.createElement(`span`),this.groupCountEl.className=gp,this.groupCountEl.hidden=!0,this.groupContentEl.append(this.groupLabelEl,this.groupCountEl),this.element.append(this.groupContentEl)),this.groupExpandButton=Pp(this.groupContentEl,this.groupExpandButton,this.groupLabelEl,e.showChevron),Np(this.groupContentEl,this.groupExpandButton,this.groupLabelEl,e)}clearGroupCell(){this.groupContentEl&&(this.groupContentEl.remove(),this.groupContentEl=null,this.groupExpandButton=null,this.groupLabelEl=null,this.groupCountEl=null)}getGroupExpandButton(){return this.groupExpandButton}setRendererResult(e){this.prepareForRenderer(),Do.apply(this.rendererMount,e)}prepareForRenderer(){this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,this.rendererMount.hidden=!1,this.usingRenderer=!0}prepareForRendererPatch(){this.clearInlineEditor(),this.textEl.hidden=!0,this.textEl.textContent=``,this.rendererMount.hidden=!1,this.usingRenderer=!0}canPatchVueRenderer(e){return this.usingRenderer&&this.vueRendererActive&&this.vueRendererColId===e}markVueRendererMounted(e){this.vueRendererActive=!0,this.vueRendererColId=e,this.rendererPlaceholderActive=!1}setRendererPlaceholder(e){this.clearInlineEditor(),this.clearRenderer(),this.textEl.hidden=!1,this.textEl.textContent!==e&&(this.textEl.textContent=e),this.rendererMount.hidden=!0,this.usingRenderer=!1,this.rendererPlaceholderActive=!0}isRendererPlaceholderActive(){return this.rendererPlaceholderActive}prepareForInlineEditor(e){this.clearSelectionCheckbox(),this.clearRowExpandButton(),this.clearGroupCell(),this.clearRenderer(),this.textEl.hidden=!0,this.textEl.textContent=``,this.inlineEditorMount.hidden=!1,this.usingInlineEditor=!0,this.element.classList.add(`mg-cell--inline-editor`),this.setInlineEditorDisabledVisual(e)}clearInlineEditor(){(this.usingInlineEditor||this.inlineEditorMount.childNodes.length>0)&&this.onUnmountEditor?.(this.inlineEditorMount),this.inlineEditorMount.replaceChildren(),this.inlineEditorMount.hidden=!0,this.usingInlineEditor=!1,this.element.classList.remove(`mg-cell--inline-editor`,`mg-cell--inline-disabled`,`mg-cell--committing`)}getInlineEditorMountEl(){return this.inlineEditorMount}setInlineEditorDisabledVisual(e){this.element.classList.toggle(`mg-cell--inline-disabled`,e),this.setCellDisabled(e)}setInlineEditorCommitting(e){this.setCommittingVisual(e)}setCommittingVisual(e){this.element.classList.toggle(`mg-cell--committing`,e)}clearRenderer(){(this.usingRenderer||this.rendererMount.childNodes.length>0)&&this.onUnmountRenderer?.(this.rendererMount),Do.clear(this.rendererMount),this.rendererMount.hidden=!0,this.usingRenderer=!1,this.vueRendererActive=!1,this.vueRendererColId=void 0,this.rendererPlaceholderActive=!1}hasRenderer(){return this.usingRenderer}getRendererMountEl(){return this.rendererMount}setColId(e){this.element.dataset.colId=e}setFocused(e){this.element.classList.toggle(`mg-cell--focused`,e)}setRangeSelected(e){this.element.classList.toggle(is,e)}setRangeAnchor(e){this.element.classList.toggle(as,e)}setIndexRangeHighlight(e){this.element.classList.toggle(Ts,e)}playRangeCopyFlash(){this.element.classList.remove(ms),this.element.offsetWidth,this.element.classList.add(ms);let e=()=>{this.element.classList.remove(ms),this.element.removeEventListener(`animationend`,e)};this.element.addEventListener(`animationend`,e)}playRangePasteFlash(e){this.element.classList.remove(gs,_s),this.element.offsetWidth,this.element.classList.add(e?_s:gs);let t=()=>{this.element.classList.remove(gs,_s),this.element.removeEventListener(`animationend`,t)};this.element.addEventListener(`animationend`,t)}setCellDisabled(e){if(this.element.classList.toggle(vn,e),e){this.element.setAttribute(`aria-disabled`,`true`),this.element.setAttribute(yn,`true`);return}this.element.removeAttribute(`aria-disabled`),this.element.removeAttribute(yn)}setCellStyle(e){let t=this.lastCellStyle,n=e.backgroundColor,r=e.color;t.backgroundColor!==n&&(n===void 0||n===``?this.element.style.removeProperty(`background-color`):this.element.style.backgroundColor=n),t.color!==r&&(r===void 0||r===``?this.element.style.removeProperty(`color`):this.element.style.color=r),this.lastCellStyle={backgroundColor:n,color:r},n!==void 0&&n!==``?this.element.setAttribute(zn,`true`):this.element.removeAttribute(zn)}setCommentIndicator(e){Vp(this.element,e)}setRowDragHandle(e){if(e){this.rowDragHandle||(this.rowDragHandle=document.createElement(`div`),this.rowDragHandle.className=na,this.rowDragHandle.setAttribute(`role`,`button`),this.rowDragHandle.setAttribute(`aria-label`,`拖拽行`),this.rowDragHandle.append(Jf()),this.element.prepend(this.rowDragHandle)),this.element.classList.add(`mg-cell--row-draggable`);return}this.clearRowDragHandle()}clearRowDragHandle(){this.rowDragHandle?.remove(),this.rowDragHandle=null,this.element.classList.remove(`mg-cell--row-draggable`)}setRowResizeHandle(e){if(e){this.rowResizeHandle||(this.rowResizeHandle=document.createElement(`div`),this.rowResizeHandle.className=Ji,this.rowResizeHandle.setAttribute(`role`,`separator`),this.rowResizeHandle.setAttribute(`aria-orientation`,`horizontal`),this.element.append(this.rowResizeHandle)),this.element.classList.add(`mg-cell--row-resizable`);return}this.clearRowResizeHandle()}clearRowResizeHandle(){this.rowResizeHandle?.remove(),this.rowResizeHandle=null,this.element.classList.remove(`mg-cell--row-resizable`)}getColId(){return this.element.dataset.colId}getElement(){return this.element}destroy(){this.clearSelectionCheckbox(),this.clearRowExpandButton(),this.clearRowDragHandle(),this.clearRowResizeHandle(),this.clearInlineEditor(),this.clearRenderer(),this.element.remove()}},Up=class{element;lanes;frameService;onUnmountRenderer;onUnmountEditor;inlineEditor;indexColumnOptions;selectionColumnOptions;rowAutoHeightService;isRowDragHandleEnabled;isRowDragCommittingRow;enableCellSpan;cellSpanService;getRowByIndex;getRowCount;isRowCoverHighlighted;spannedRowOnly;embedFullWidthRows;getDetailCellRenderer;getMasterRowById;rowExpansionHost;rowGroupingHost;treeTableHost;getCellCommentHost;detailRowAutoHeightService;resolveBusinessRowId;getCellDisableContext;getCellStyleContext;cellRendererDefer;isScrollActive;cellRendererPresentation;fullWidthEmbedContentEl=null;isFullWidthEmbedActive=!1;autoHeightCleanups=new Map;columnModel=null;columnWindow={firstCol:0,lastCol:-1};rowNode=null;stripe=!1;valueCacheVersion=0;selected=!1;selectionIndeterminate=!1;indexFocused=!1;indexColumnRangeHighlighted=!1;selectionDisabled=!1;lastRowTop=null;pendingRendererTasks=[];rendererBatchDepth=0;constructor(e,t={}){this.stripe=t.stripe??!1,this.frameService=t.frameService??null,this.onUnmountRenderer=t.onUnmountRenderer,this.onUnmountEditor=t.onUnmountEditor,this.inlineEditor=t.inlineEditor,this.indexColumnOptions=t.indexColumnOptions,this.selectionColumnOptions=t.selectionColumnOptions,this.rowAutoHeightService=t.rowAutoHeightService??null,this.isRowDragHandleEnabled=t.isRowDragHandleEnabled,this.isRowDragCommittingRow=t.isRowDragCommittingRow,this.enableCellSpan=t.enableCellSpan??!1,this.cellSpanService=t.cellSpanService??null,this.getRowByIndex=t.getRowByIndex,this.getRowCount=t.getRowCount,this.isRowCoverHighlighted=t.isRowCoverHighlighted,this.spannedRowOnly=t.spannedRowOnly??!1,this.embedFullWidthRows=t.embedFullWidthRows??!1,this.getDetailCellRenderer=t.getDetailCellRenderer,this.getMasterRowById=t.getMasterRowById,this.rowExpansionHost=t.rowExpansionHost,this.rowGroupingHost=t.rowGroupingHost,this.treeTableHost=t.treeTableHost,this.getCellCommentHost=t.getCellCommentHost,this.detailRowAutoHeightService=t.detailRowAutoHeightService??null,this.resolveBusinessRowId=t.resolveBusinessRowId,this.getCellDisableContext=t.getCellDisableContext,this.getCellStyleContext=t.getCellStyleContext,this.cellRendererDefer=t.cellRendererDefer??`always`,this.isScrollActive=t.isScrollActive,this.cellRendererPresentation=t.cellRendererPresentation??`deferred`,this.element=document.createElement(`div`),this.element.className=`mg-row`,this.spannedRowOnly&&this.element.classList.add(`mg-row--spanned`),this.syncTopPositioningClass(),this.lanes={left:this.createLane(`left`),center:this.createLane(`center`),right:this.createLane(`right`)},this.element.append(this.lanes.left.element,this.lanes.center.element,this.lanes.right.element),e.appendChild(this.element)}setSelected(e,t=!1){this.selected=e,this.selectionIndeterminate=t,this.element.classList.toggle(`mg-row--selected`,e),this.syncSelectionColumnCheckbox(),this.syncRowSpanHighlights()}setSelectionDisabled(e){this.selectionDisabled=e,this.syncSelectionColumnCheckbox()}setIndexFocused(e){this.indexFocused=e,this.element.classList.toggle(`mg-row--index-focused`,e),this.syncIndexFocusedVisual(),this.syncRowSpanHighlights()}setIndexColumnRangeHighlight(e){this.indexColumnRangeHighlighted!==e&&(this.indexColumnRangeHighlighted=e,this.syncIndexColumnRangeHighlightVisual())}setFocusedColId(e){for(let t of Object.values(this.lanes))for(let n of t.cells){let t=n.getColId();n.setFocused(e!==null&&t===e)}}setCellRangeSelection(e,t,n){for(let r of Object.values(this.lanes))for(let i of r.cells){let r=i.getColId()??``,a=i.getElement(),o=Number(a.dataset.rowSpan??1),s=o>1&&this.rowNode&&this.getRowByIndex&&n?Zo({head:this.rowNode,rowSpan:o,colId:r,getRowByIndex:this.getRowByIndex,isCellSelected:n}):e(r);i.setRangeSelected(s),i.setRangeAnchor(t!==null&&r===t)}}flashCellRangeSelection(e,t){for(let n of Object.values(this.lanes))for(let r of n.cells){let n=r.getColId()??``,i=r.getElement(),a=Number(i.dataset.rowSpan??1);(a>1&&this.rowNode&&this.getRowByIndex&&t?Zo({head:this.rowNode,rowSpan:a,colId:n,getRowByIndex:this.getRowByIndex,isCellSelected:t}):e(n))&&r.playRangeCopyFlash()}}flashCellRangePaste(e){for(let t of Object.values(this.lanes))for(let n of t.cells){let t=n.getColId(),r=e.find(e=>e.colId===t);r&&n.playRangePasteFlash(!r.applied)}}setRowTop(e){this.lastRowTop=e,this.applyRowTop(e)}syncRowLayout(e){if(this.rowNode=e,this.spannedRowOnly){this.syncSpannedRowHeight();return}this.syncRowHeight(e.rowHeight)}setRowDragCommittingVisual(e){this.element.classList.toggle(sa,e)}syncRowDragCommittingVisual(){this.rowNode&&this.setRowDragCommittingVisual(this.isRowDragCommittingRow?.(this.rowNode.id)??!1)}syncRowHeight(e){let t=`${e}px`;this.element.style.height=t,this.element.style.setProperty(`--mg-row-height`,t)}syncSpannedRowHeight(){this.element.style.height=`0px`,this.element.style.setProperty(`--mg-row-height`,`0px`)}setData(e,t,n,r=0,i=!1,a){if(this.rowNode=e,this.columnModel=t,this.columnWindow=n,this.valueCacheVersion=r,this.element.dataset.rowId=e.id,this.spannedRowOnly?this.syncSpannedRowHeight():this.syncRowHeight(e.rowHeight),this.element.style.width=`${t.getTotalWidth()}px`,this.syncLaneWidths(),this.embedFullWidthRows&&B(e)){this.syncFullWidthEmbedRow(e,i);return}this.isFullWidthEmbedActive&&this.clearFullWidthEmbedState(),this.syncCells(),this.syncRowDragCommittingVisual(),this.syncStripeClass(),this.syncLastRowClass(i),this.syncExpandedMasterClass(),this.syncGroupRowClasses(),a?.columnStructureChanged?this.syncCellValues(`structure-changed`):this.syncCellValues(`all`),this.syncAutoHeightCells(),this.syncCellCommentIndicators()}setEnableCellSpan(e){this.enableCellSpan!==e&&(this.enableCellSpan=e,this.syncTopPositioningClass(),this.lastRowTop!==null&&this.applyRowTop(this.lastRowTop))}setCellSpanService(e){this.cellSpanService=e}setRowSpanAccessors(e){this.getRowByIndex=e.getRowByIndex,this.getRowCount=e.getRowCount}refreshCells(e){if(!this.rowNode)return 0;if(this.columnModel=e.columnModel,this.columnWindow=e.columnWindow,this.valueCacheVersion=e.valueCacheVersion,e.inlineEditor&&(this.inlineEditor=e.inlineEditor),this.syncLaneWidths(),this.isFullWidthEmbedActive)return this.syncFullWidthEmbedPinnedLanes(),this.syncFullWidthEmbedContent(),1;this.enableCellSpan&&this.syncCells();let t=e.indexColumnOptions??this.indexColumnOptions,n=e.selectionColumnOptions??this.selectionColumnOptions,r=e.colIds?new Set(e.colIds):null;if(!this.hasVisibleCells()||!this.columnModel)return 0;let i=e.force??!1,a=this.withRendererBatch(()=>{let e=0;for(let a of[`left`,`center`,`right`]){let o=this.lanes[a];for(let s=0;s<o.indices.length;s++)this.refreshCellAtLaneIndex(a,s,r,i,t,n)&&e++}return e});return this.syncAutoHeightCells(r,i),this.syncCellCommentIndicators(r),a}promoteRendererPlaceholders(){return!this.rowNode||!this.columnModel||this.isFullWidthEmbedActive?0:this.withRendererBatch(()=>{let e=0;for(let t of[`left`,`center`,`right`]){let n=this.lanes[t];for(let r=0;r<n.indices.length;r++)this.promoteRendererPlaceholderAtLaneIndex(t,r)&&e++}return e})}syncCellCommentIndicators(e=null){let t=this.getCellCommentHost?.();if(!t?.active()||!this.rowNode||!this.columnModel||this.isFullWidthEmbedActive)return;let n=this.rowNode,r=at(n.rowKind);for(let i of[`left`,`center`,`right`]){let a=this.lanes[i];for(let i=0;i<a.indices.length;i++){let o=a.indices[i],s=o===void 0?void 0:this.columnModel.getColumn(o),c=a.cells[i];if(!s||!c)continue;let{colId:l}=s;if(e&&!e.has(l))continue;if(!Ql(l,r,n.id)){c.setCommentIndicator(`none`);continue}let u=t.hasComment(n.id,l),d=t.canCreateComment(n.id,l);c.setCommentIndicator(u?`filled`:d?`empty`:`none`)}}}getElement(){return this.element}destroy(){this.clearFullWidthEmbedState(),this.clearAutoHeightCleanups();for(let e of Object.values(this.lanes)){for(let t of e.cells)t.destroy();e.cells.length=0,e.cellCtrls.length=0}this.element.remove()}createLane(e){let t=document.createElement(`div`);return t.className=`mg-row__lane mg-row__lane--${e}`,{element:t,cells:[],cellCtrls:[],indices:[],mountedColIds:[],changedSlotIndices:new Set}}applyRowTop(e){if(Ri(this.enableCellSpan)){this.element.style.top=`${e}px`,this.element.style.transform=``;return}this.element.style.top=`0px`,this.element.style.transform=`translateY(${e}px)`}syncTopPositioningClass(){this.element.classList.toggle(Ii,Ri(this.enableCellSpan))}hasVisibleCells(e){return e?e.left.length+e.center.length+e.right.length>0:this.lanes.left.indices.length>0||this.lanes.center.indices.length>0||this.lanes.right.indices.length>0}syncLaneWidths(){this.columnModel&&(this.lanes.left.element.style.width=`${this.columnModel.getLeftFixedWidth()}px`,this.lanes.center.element.style.width=`${this.columnModel.getCenterTotalWidth()}px`,this.lanes.right.element.style.width=`${this.columnModel.getRightFixedWidth()}px`)}syncColumnLayouts(){if(this.columnModel){if(this.element.style.width=`${this.columnModel.getTotalWidth()}px`,this.syncLaneWidths(),this.isFullWidthEmbedActive){this.syncFullWidthEmbedPinnedLanes();return}for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];!r||!i||this.applyCellColumnLayout(i,r)}}}}syncCells(){if(!this.columnModel||!this.rowNode)return;let e=this.rowNode,t=this.columnModel,n=Go({columnModel:t,centerWindow:this.columnWindow,enableCellSpan:this.enableCellSpan,paramsForColumn:t=>Po(e,t)});for(let e of[`left`,`center`,`right`]){let t=this.filterRowSpanIndices(n[e]);this.syncLaneCells(e,t)}}filterRowSpanIndices(e){if(!this.enableCellSpan||!this.rowNode||!this.columnModel)return e;let t=this.rowNode,n=this.columnModel,r=this.cellSpanService,i=e=>{if(r)return r.resolveVerticalSpan(t,e);if(!e.rowSpan||!this.getRowByIndex)return{head:t,rowSpan:1,covered:!1};let n=this.getRowCount?.()??t.rowIndex+1;return qo({enableCellSpan:!0,column:e,rowNode:t,getRowByIndex:this.getRowByIndex,rowCount:n})};return e.filter(e=>{let r=n.getColumn(e);if(!r)return!0;let a=i(r);if(a.covered)return!1;let o=a.rowSpan>1&&a.head.id===t.id;return this.spannedRowOnly?o:!o})}syncLaneCells(e,t){let n=this.lanes[e];for(n.indices=t,n.changedSlotIndices.clear();n.cells.length<t.length;)n.cells.push(new Hp(n.element,{onUnmountRenderer:this.onUnmountRenderer,onUnmountEditor:this.onUnmountEditor})),n.cellCtrls.push(new Lp),n.mountedColIds.push(``);for(;n.cells.length>t.length;){let e=n.cells.pop();e&&(this.cleanupAutoHeightCell(e.getElement()),e.destroy()),n.cellCtrls.pop(),n.mountedColIds.pop()}for(let e=0;e<t.length;e++){let r=t[e],i=r===void 0?void 0:this.columnModel.getColumn(r),a=n.cells[e];if(!i||!a)continue;let o=n.mountedColIds[e],s=i.colId;o!==s&&(n.changedSlotIndices.add(e),o&&n.cellCtrls[e]?.invalidate()),n.mountedColIds[e]=s,this.applyCellColumnLayout(a,i),a.setColId(s),a.getElement().toggleAttribute(`data-auto-height`,i.autoHeight),ci(a.getElement(),i.align,i.valign,`mg-cell`),a.getElement().classList.toggle(`mg-cell--index`,L(i.colId)),a.getElement().classList.toggle(`mg-cell--selection`,R(i.colId)),a.getElement().classList.toggle(`mg-cell--expand`,z(i.colId)||i.rowExpand),a.getElement().classList.toggle(`mg-cell--group`,V(i.colId));let c=this.rowNode!=null&&Zt(this.rowNode)&&(this.isRowDragHandleEnabled?.(i.colId)??!1);L(i.colId)?(a.getElement().classList.toggle(`mg-cell--index-focused`,this.indexFocused),a.setIndexRangeHighlight(this.indexColumnRangeHighlighted),a.setRowResizeHandle(this.indexColumnOptions?.enableRowResizer??!1),a.setRowDragHandle(c)):(a.clearRowResizeHandle(),a.setRowDragHandle(i.rowDrag?c:!1))}}applyCellColumnLayout(e,t){if(!this.columnModel||!this.rowNode)return;let n=e.getElement();if(!this.enableCellSpan||!t.colSpan)e.setColumnLayout(ko(t,this.columnModel)),Lo(n,1);else{let r=Bo(t,this.columnModel,{enableCellSpan:!0,params:Po(this.rowNode,t)});e.setColumnLayout(Io(r,this.columnModel)),Lo(n,r.length)}this.applyCellRowSpanState(n,t)}applyCellRowSpanState(e,t){if(!this.enableCellSpan||!this.rowNode){Yo(e,1,null);return}if(this.cellSpanService){let n=this.cellSpanService.resolveVerticalSpan(this.rowNode,t);if(n.covered||n.rowSpan<=1){Yo(e,1,null);return}let r=this.cellSpanService.getVerticalSpanHeight(this.rowNode,t);Yo(e,n.rowSpan,r),this.applyRowSpanCoverHighlight(e,n.head,n.rowSpan);return}if(!t.rowSpan||!this.getRowByIndex){Yo(e,1,null);return}let n=this.getRowCount?.()??this.rowNode.rowIndex+1,r=qo({enableCellSpan:!0,column:t,rowNode:this.rowNode,getRowByIndex:this.getRowByIndex,rowCount:n});if(r.covered||r.rowSpan<=1){Yo(e,1,null);return}let i=Jo(r.head,r.rowSpan,this.getRowByIndex);Yo(e,r.rowSpan,i),this.applyRowSpanCoverHighlight(e,r.head,r.rowSpan)}syncRowSpanHighlights(){if(!(!this.enableCellSpan||!this.rowNode||!this.getRowByIndex))for(let e of Object.values(this.lanes))for(let t of e.cells){let e=t.getElement();if(!e.classList.contains(`mg-cell--row-span`))continue;let n=Number(e.dataset.rowSpan??1);n<=1||this.applyRowSpanCoverHighlight(e,this.rowNode,n)}}applyRowSpanCoverHighlight(e,t,n){if(!this.getRowByIndex||n<=1){e.classList.remove(`mg-cell--row-span-highlighted`);return}let r=Xo({head:t,rowSpan:n,getRowByIndex:this.getRowByIndex,isRowHighlighted:e=>this.isRowCoverHighlighted?this.isRowCoverHighlighted(e):e===t.id&&(this.selected||this.indexFocused)});e.classList.toggle(`mg-cell--row-span-highlighted`,r)}syncIndexFocusedVisual(){if(this.columnModel)for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];!r||!i||!L(r.colId)||i.getElement().classList.toggle(`mg-cell--index-focused`,this.indexFocused)}}}syncIndexColumnRangeHighlightVisual(){if(this.columnModel)for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];!r||!i||!L(r.colId)||i.setIndexRangeHighlight(this.indexColumnRangeHighlighted)}}}withRendererBatch(e){this.rendererBatchDepth++;try{return e()}finally{this.rendererBatchDepth--,this.flushRowRendererBatch()}}scheduleRendererTask(e){if(this.rendererBatchDepth>0){this.pendingRendererTasks.push(e);return}this.enqueueRendererTask(e)}flushRowRendererBatch(){if(this.rendererBatchDepth>0||this.pendingRendererTasks.length===0)return;let e=this.pendingRendererTasks.splice(0);this.enqueueRendererTask(()=>{for(let t of e)t()})}enqueueRendererTask(e){let t=this.rowNode?.rowIndex??0;if(this.frameService){this.frameService.createTask(e,t,`f1`);return}e()}scheduleInlineEditorTask(e){let t=this.rowNode?.rowIndex??0;if(this.frameService){this.frameService.createTask(e,t,`p2`);return}e()}refreshCellAtLaneIndex(e,t,n,r,i,a){let o=this.lanes[e],s=o.indices[t],c=s===void 0?void 0:this.columnModel.getColumn(s),l=o.cells[t],u=o.cellCtrls[t];return!c||!l||!u||!this.rowNode||n&&!n.has(c.colId)?!1:u.refreshCell(this.rowNode,c,l,this.valueCacheVersion,{force:r,scheduleRenderer:e=>this.scheduleRendererTask(e),scheduleInlineEditor:e=>this.scheduleInlineEditorTask(e),inlineEditor:this.inlineEditor,indexColumnOptions:i??this.indexColumnOptions,selectionColumnOptions:a??this.selectionColumnOptions,selectionChecked:this.selected,selectionDisabled:this.selectionDisabled,selectionIndeterminate:this.selectionIndeterminate,rowExpansionHost:this.rowExpansionHost,rowGroupingHost:this.rowGroupingHost,treeTableHost:this.treeTableHost,resolveBusinessRowId:this.resolveBusinessRowId,getCellDisableContext:this.getCellDisableContext,getCellStyleContext:this.getCellStyleContext,cellRendererDefer:this.cellRendererDefer,cellRendererPresentation:this.cellRendererPresentation,scrollActive:this.isScrollActive?.()??!1})}promoteRendererPlaceholderAtLaneIndex(e,t){let n=this.lanes[e],r=n.indices[t],i=r===void 0?void 0:this.columnModel.getColumn(r),a=n.cells[t],o=n.cellCtrls[t];return!i||!a||!o||!this.rowNode||!o.hasPendingVueRenderer()?!1:o.promoteVueRenderer(this.rowNode,a,{scheduleRenderer:e=>this.scheduleRendererTask(e),cellRendererDefer:this.cellRendererDefer,cellRendererPresentation:this.cellRendererPresentation})}syncGroupRowClasses(){this.rowNode&&(this.element.classList.toggle(St,this.rowNode.rowKind===`groupHeader`),this.element.classList.toggle(Ct,this.rowNode.rowKind===`groupFooter`))}syncStripeClass(){this.rowNode&&this.element.classList.toggle(`mg-row--stripe`,this.stripe&&this.rowNode.rowIndex%2==1)}syncLastRowClass(e){this.element.classList.toggle(`mg-row--last`,e)}syncExpandedMasterClass(){if(!this.rowNode||B(this.rowNode)){this.element.classList.remove(`mg-row--expanded-master`);return}let e=this.rowExpansionHost?.active()===!0&&this.rowExpansionHost.isExpanded(this.rowNode.id);this.element.classList.toggle(`mg-row--expanded-master`,e)}syncSelectionColumnCheckbox(){if(!(!this.columnModel||!this.rowNode||this.isFullWidthEmbedActive))for(let e of[`left`,`center`,`right`]){let t=this.lanes[e];for(let e=0;e<t.indices.length;e++){let n=t.indices[e],r=n===void 0?void 0:this.columnModel.getColumn(n),i=t.cells[e];if(!r||!i||!R(r.colId))continue;if(Xt(this.rowNode)){i.clearSelectionCheckbox();continue}let a=this.selectionColumnOptions?jf(this.rowNode.rowIndex,this.selectionColumnOptions.selectionColumn):`选择第 ${this.rowNode.rowIndex+1} 行`;i.setSelectionCheckbox({checked:this.selected,disabled:this.selectionDisabled,indeterminate:this.selectionIndeterminate,ariaLabel:a})}}}syncCellValues(e=`all`){return!this.rowNode||!this.columnModel||!this.hasVisibleCells()?0:this.withRendererBatch(()=>{let t=0;for(let n of[`left`,`center`,`right`]){let r=this.lanes[n];for(let i=0;i<r.indices.length;i++){let a=e===`all`||r.changedSlotIndices.has(i);this.refreshCellAtLaneIndex(n,i,null,a,this.indexColumnOptions,this.selectionColumnOptions)&&t++}}return t})}syncAutoHeightCells(e=null,t=!1){if(!(!this.rowAutoHeightService||!this.rowNode||!this.columnModel))for(let n of[`left`,`center`,`right`]){let r=this.lanes[n];for(let n=0;n<r.indices.length;n++){let i=r.indices[n],a=i===void 0?void 0:this.columnModel.getColumn(i),o=r.cells[n];if(!a||!o)continue;let s=o.getElement(),{colId:c}=a;if(e&&!e.has(c))continue;if(!a.autoHeight){o.getElement().removeAttribute(`data-auto-height`),this.cleanupAutoHeightCell(s);continue}if(this.autoHeightCleanups.has(s)&&!t)continue;t&&this.cleanupAutoHeightCell(s);let l=this.rowNode.id;this.scheduleRendererTask(()=>{if(!this.rowNode||this.rowNode.id!==l)return;let e=this.rowAutoHeightService.setupCellAutoHeight({rowId:l,colId:c,cellEl:s});e&&this.autoHeightCleanups.set(s,e)})}}}cleanupAutoHeightCell(e){let t=this.autoHeightCleanups.get(e);t&&(t(),this.autoHeightCleanups.delete(e))}clearAutoHeightCleanups(){for(let e of this.autoHeightCleanups.values())e();this.autoHeightCleanups.clear()}syncFullWidthEmbedRow(e,t){this.isFullWidthEmbedActive=!0,this.element.classList.add(`mg-row--full-width-embed`,`mg-row--detail`),this.element.dataset.rowKind=`detail`,e.masterRowId&&(this.element.dataset.masterRowId=e.masterRowId),this.syncFullWidthEmbedPinnedLanes(),this.syncLaneCells(`center`,[]),this.fullWidthEmbedContentEl||(this.fullWidthEmbedContentEl=document.createElement(`div`),this.fullWidthEmbedContentEl.className=Qe,this.lanes.center.element.appendChild(this.fullWidthEmbedContentEl)),this.syncFullWidthEmbedContent(),this.syncStripeClass(),this.syncLastRowClass(t)}syncFullWidthEmbedPinnedLanes(){if(!this.columnModel||!this.rowNode)return;let e=Go({columnModel:this.columnModel,centerWindow:this.columnWindow,enableCellSpan:!1,paramsForColumn:e=>Po(this.rowNode,e)});this.syncLaneCells(`left`,this.filterRowSpanIndices(e.left)),this.syncLaneCells(`right`,this.filterRowSpanIndices(e.right)),this.syncFullWidthEmbedSpacerCells()}syncFullWidthEmbedSpacerCells(){for(let e of[`left`,`right`]){let t=this.lanes[e];for(let e of t.cells){let t=e.getElement();t.classList.add(`mg-cell--embed-spacer`),t.setAttribute(`aria-hidden`,`true`),e.clearSelectionCheckbox(),e.clearRowExpandButton(),e.setValue(``)}}}syncFullWidthEmbedContent(){if(!this.rowNode||!this.fullWidthEmbedContentEl)return;let e=zp(this.rowNode,this.getMasterRowById);e&&Bp(this.fullWidthEmbedContentEl,e,this.getDetailCellRenderer?.(),{frameService:this.frameService,onUnmountRenderer:this.onUnmountRenderer,rowIndex:this.rowNode.rowIndex,onAfterRender:()=>{this.detailRowAutoHeightService?.setupContentObserver(this.rowNode.id,this.fullWidthEmbedContentEl)}})}clearFullWidthEmbedState(){this.rowNode&&this.detailRowAutoHeightService?.teardownContentObserver(this.rowNode.id),this.isFullWidthEmbedActive=!1,this.element.classList.remove(`mg-row--full-width-embed`,`mg-row--detail`),delete this.element.dataset.rowKind,delete this.element.dataset.masterRowId,this.fullWidthEmbedContentEl&&=(this.onUnmountRenderer?.(this.fullWidthEmbedContentEl),this.fullWidthEmbedContentEl.replaceChildren(),this.fullWidthEmbedContentEl.remove(),null);for(let e of[`left`,`right`])for(let t of this.lanes[e].cells)t.getElement().classList.remove(`mg-cell--embed-spacer`),t.getElement().removeAttribute(`aria-hidden`)}},Wp=class{container;rowModel;columnModel;stripe;rowPool=new Tf;frameService;onUnmountRenderer;onUnmountEditor;inlineCellEditor;indexColumnOptions;selectionColumnOptions;rowAutoHeightService;isRowDragHandleEnabled;enableCellSpan;cellSpanService;valueCacheVersion=0;selectedRowIds=new Set;indexFocusedRowIds=new Set;focusedCell=null;cellRangeIsSelected=null;cellRangeAnchor=null;columnWindow={firstCol:0,lastCol:-1};activeHeadIds=new Set;compressedScroll=!1;scrollTop=0;constructor(e){this.container=e.container,this.rowModel=e.rowModel,this.columnModel=e.columnModel,this.stripe=e.stripe??!1,this.frameService=e.frameService??null,this.onUnmountRenderer=e.onUnmountRenderer,this.onUnmountEditor=e.onUnmountEditor,this.indexColumnOptions=e.indexColumnOptions,this.selectionColumnOptions=e.selectionColumnOptions,this.rowAutoHeightService=e.rowAutoHeightService??null,this.isRowDragHandleEnabled=e.isRowDragHandleEnabled,this.enableCellSpan=e.enableCellSpan??!1,this.cellSpanService=e.cellSpanService??null}setEnableCellSpan(e){this.enableCellSpan=e,e||this.clear()}setCellSpanService(e){this.cellSpanService=e}setRowAutoHeightService(e){this.rowAutoHeightService=e}setInlineCellEditorContext(e){this.inlineCellEditor=e}setCompressedScroll(e){this.compressedScroll=e}setValueCacheVersion(e){this.valueCacheVersion=e}refreshSelection(e){this.selectedRowIds=new Set(e);for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setSelected?.(e.has(t))}refreshIndexFocus(e){this.indexFocusedRowIds=new Set(e);for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setIndexFocused?.(e.has(t))}setFocusedCell(e){this.focusedCell=e,this.refreshFocus()}refreshFocus(){let e=this.focusedCell;for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setFocusedColId?.(e?.rowId===t?e.colId:null)}setCellRangeVisualState(e,t){this.cellRangeIsSelected=e,this.cellRangeAnchor=t,this.refreshCellRangeSelection()}refreshCellRangeSelection(){let e=this.cellRangeIsSelected,t=this.cellRangeAnchor;for(let n of this.rowPool.getActiveIds()){let r=this.findRowIndexById(n),i=this.rowPool.get(n);!i?.setCellRangeSelection||r<0||i.setCellRangeSelection(e?t=>e(r,t):()=>!1,t?.rowIndex===r?t.colId:null,e??void 0)}}playCellRangeCopyFlash(){let e=this.cellRangeIsSelected;if(e)for(let t of this.rowPool.getActiveIds()){let n=this.findRowIndexById(t),r=this.rowPool.get(t);!r?.flashCellRangeSelection||n<0||r.flashCellRangeSelection(t=>e(n,t),e)}}playCellRangePasteFlash(e){if(e.length===0)return;let t=new Map;for(let n of e){let e=t.get(n.rowIndex);e?e.push(n):t.set(n.rowIndex,[n])}for(let e of this.rowPool.getActiveIds()){let n=this.findRowIndexById(e),r=this.rowPool.get(e),i=t.get(n);!r?.flashCellRangePaste||!i?.length||n<0||r.flashCellRangePaste(i)}}syncColumnLayouts(){for(let e of this.rowPool.getActiveIds())this.rowPool.get(e)?.syncColumnLayouts?.()}refreshVisibleColumnStructure(e){if(!this.enableCellSpan)return;this.columnWindow=e;let t={columnStructureChanged:!0};for(let e of this.activeHeadIds)this.updateHeadRow(e,t)}migrateRowId(e,t){if(e===t)return;this.rowPool.migrateId(e,t);let n=this.rowPool.get(t);n&&(n.getElement().dataset.rowId=t),this.selectedRowIds.has(e)&&(this.selectedRowIds.delete(e),this.selectedRowIds.add(t)),this.indexFocusedRowIds.has(e)&&(this.indexFocusedRowIds.delete(e),this.indexFocusedRowIds.add(t)),this.focusedCell?.rowId===e&&(this.focusedCell={rowId:t,colId:this.focusedCell.colId}),this.activeHeadIds.has(e)&&(this.activeHeadIds.delete(e),this.activeHeadIds.add(t))}refreshRows(e){let t=e.rowIds?new Set(e.rowIds):null,n=0;for(let r of this.rowPool.getActiveIds()){if(t&&!this.includesRefreshTarget(r,t))continue;let i=this.rowPool.get(r);i?.refreshCells&&(n+=i.refreshCells({columnModel:this.columnModel,columnWindow:this.columnWindow,valueCacheVersion:this.valueCacheVersion,colIds:e.colIds,force:e.force,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,inlineEditor:this.inlineCellEditor}))}return n}syncVisibleRowLayouts(e){let t=e?new Set(e):null;for(let e of this.rowPool.getActiveIds()){if(t&&!this.includesRefreshTarget(e,t))continue;let n=this.findRowNodeById(e);if(!n)continue;let r=this.rowPool.get(e);r?.syncRowLayout?.(n),r?.setRowTop(this.compressedScroll?n.rowTop-this.scrollTop:n.rowTop)}}redraw(e,t,n,r=!1){if(!this.enableCellSpan){this.clear();return}this.scrollTop=e,this.columnWindow=n;let i=this.collectHeadRowIds(t.firstRow,t.lastRow),a=[...this.activeHeadIds].filter(e=>!i.has(e)),o=[...i];for(let e of a)this.frameService&&!this.compressedScroll?this.frameService.addDestroyTask(()=>{this.rowPool.release(e)}):this.rowPool.release(e);for(let e of o)(!this.activeHeadIds.has(e)||r)&&this.updateHeadRow(e,r?{columnStructureChanged:!0}:void 0);this.activeHeadIds=i,this.container.style.display=i.size>0?``:`none`}invalidate(){this.frameService&&this.frameService.flushAllFrames(),this.clear()}destroy(){this.clear()}getActiveHeadCount(){return this.rowPool.getActiveCount()}clear(){this.rowPool.clear(),this.activeHeadIds.clear(),this.container.style.display=`none`}collectHeadRowIds(e,t){return this.cellSpanService?this.cellSpanService.collectSpannedHeadRowIds(e,t):Qo({enableCellSpan:this.enableCellSpan,rowModel:this.rowModel,columns:this.columnModel.getColumns(),firstRow:e,lastRow:t})}updateHeadRow(e,t){let n=this.findRowNodeById(e);if(!n)return;let r=this.rowPool.acquire(e,()=>this.createSpannedRowComp()),i=this.rowModel.getRowCount();r.setData(n,this.columnModel,this.columnWindow,this.valueCacheVersion,i>0&&n.rowIndex===i-1,t),r.setRowTop(this.compressedScroll?n.rowTop-this.scrollTop:n.rowTop),r.setSelected?.(this.selectedRowIds.has(e)),r.setIndexFocused?.(this.indexFocusedRowIds.has(e)),r.setFocusedColId?.(this.focusedCell?.rowId===e?this.focusedCell.colId:null),this.applyCellRangeSelectionToHead(e,n.rowIndex)}applyCellRangeSelectionToHead(e,t){let n=this.rowPool.get(e),r=this.cellRangeIsSelected,i=this.cellRangeAnchor;!n?.setCellRangeSelection||t<0||n.setCellRangeSelection(r?e=>r(t,e):()=>!1,i?.rowIndex===t?i.colId:null,r??void 0)}createSpannedRowComp(){return new Up(this.container,{stripe:this.stripe,frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,onUnmountEditor:this.onUnmountEditor,inlineEditor:this.inlineCellEditor,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,rowAutoHeightService:this.rowAutoHeightService,isRowDragHandleEnabled:this.isRowDragHandleEnabled,enableCellSpan:!0,cellSpanService:this.cellSpanService,getRowByIndex:e=>this.rowModel.getRow(e),getRowCount:()=>this.rowModel.getRowCount(),spannedRowOnly:!0,isRowCoverHighlighted:e=>this.selectedRowIds.has(e)||this.indexFocusedRowIds.has(e)})}includesRefreshTarget(e,t){if(t.has(e))return!0;if(!this.cellSpanService)return!1;for(let n of this.columnModel.getColumns().map(e=>e.colId)){let r=this.cellSpanService.getCellSpan(e,n);if(r&&r.rowIds.some(e=>t.has(e)))return!0}return!1}findRowIndexById(e){for(let t=0;t<this.rowModel.getRowCount();t++)if(this.rowModel.getRow(t)?.id===e)return t;return-1}findRowNodeById(e){for(let t=0;t<this.rowModel.getRowCount();t++){let n=this.rowModel.getRow(t);if(n?.id===e)return n}}},Gp=class{element;contentEl;frameService;onUnmountRenderer;detailRowAutoHeightService;detailCellRenderer;rowNode=null;renderParams=null;constructor(e,t={}){this.frameService=t.frameService??null,this.onUnmountRenderer=t.onUnmountRenderer,this.detailRowAutoHeightService=t.detailRowAutoHeightService??null,this.element=document.createElement(`div`),this.element.className=Ze,this.element.dataset.rowKind=`detail`,this.contentEl=document.createElement(`div`),this.contentEl.className=Qe,this.element.appendChild(this.contentEl),e.appendChild(this.element)}getElement(){return this.element}setDetailCellRenderer(e){this.detailCellRenderer=e,this.renderParams&&this.renderContent(this.renderParams)}setData(e,t,n,r=!1){this.rowNode=e,this.renderParams=t,this.detailCellRenderer=n??this.detailCellRenderer,this.element.dataset.rowId=e.id,this.element.dataset.masterRowId=t.masterRowId==null?``:String(t.masterRowId),this.element.style.height=`${e.rowHeight}px`,this.element.classList.toggle($e,r),this.renderContent(t)}syncRowLayout(e){this.rowNode=e,this.element.style.height=`${e.rowHeight}px`}syncBodyWidth(e){this.element.style.width=`${e}px`}setRowTop(e){this.element.style.transform=`translateY(${e}px)`}destroy(){this.rowNode&&this.detailRowAutoHeightService?.teardownContentObserver(this.rowNode.id),this.onUnmountRenderer?.(this.contentEl),this.contentEl.replaceChildren(),this.element.remove(),this.rowNode=null,this.renderParams=null}renderContent(e){let t=this.rowNode?.id;Bp(this.contentEl,e,this.detailCellRenderer,{frameService:this.frameService,onUnmountRenderer:this.onUnmountRenderer,rowIndex:this.rowNode?.rowIndex??0,onAfterRender:()=>{t&&this.detailRowAutoHeightService?.setupContentObserver(t,this.contentEl)}})}},Kp=class{pool=new Map;acquire(e,t){let n=this.pool.get(e);if(n)return n;let r=t();return this.pool.set(e,r),r}get(e){return this.pool.get(e)}release(e){let t=this.pool.get(e);t&&(t.destroy(),this.pool.delete(e))}clear(){for(let e of this.pool.values())e.destroy();this.pool.clear()}getActiveCount(){return this.pool.size}getActiveIds(){return[...this.pool.keys()]}},qp=class{container;rowModel;columnModel;rowPool=new Kp;frameService;onUnmountRenderer;getDetailCellRenderer;getMasterRowById;masterDetail;embedFullWidthRows;detailRowAutoHeightService;pinnedRowIds=new Set;activeDetailIds=new Set;compressedScroll=!1;scrollTop=0;constructor(e){this.container=e.container,this.container.classList.add(Xe),this.rowModel=e.rowModel,this.columnModel=e.columnModel,this.frameService=e.frameService??null,this.onUnmountRenderer=e.onUnmountRenderer,this.getDetailCellRenderer=e.getDetailCellRenderer,this.getMasterRowById=e.getMasterRowById,this.masterDetail=e.masterDetail??!1,this.embedFullWidthRows=e.embedFullWidthRows??!1,this.detailRowAutoHeightService=e.detailRowAutoHeightService??null,this.container.style.display=`none`}setDetailRowAutoHeightService(e){this.detailRowAutoHeightService=e}setEmbedFullWidthRows(e){this.embedFullWidthRows=e,e&&this.clear()}setMasterDetail(e){this.masterDetail=e,e||this.clear()}setCompressedScroll(e){this.compressedScroll=e}setPinnedRowIds(e){this.pinnedRowIds=new Set(e)}redraw(e,t){if(!this.masterDetail||this.embedFullWidthRows){this.clear();return}this.scrollTop=e;let n=this.collectDetailRowIds(t.firstRow,t.lastRow),r=[...this.activeDetailIds].filter(e=>!n.has(e)),i=[...n];for(let e of r)this.frameService&&!this.compressedScroll?this.frameService.addDestroyTask(()=>{this.rowPool.release(e)}):this.rowPool.release(e);for(let e of i)this.activeDetailIds.has(e)?this.syncDetailRowLayout(e):this.updateDetailRow(e);this.activeDetailIds=n,this.container.style.display=n.size>0?``:`none`}syncVisibleRowLayouts(e){let t=e?new Set(e):null;for(let e of this.rowPool.getActiveIds())t&&!t.has(e)||this.syncDetailRowLayout(e)}syncColumnLayouts(){let e=this.columnModel.getTotalWidth();for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.syncBodyWidth(e)}invalidate(){this.frameService&&this.frameService.flushAllFrames(),this.clear()}destroy(){this.clear()}getActiveDetailCount(){return this.rowPool.getActiveCount()}refreshDetailRowContent(e){let t=this.findRowNodeById(e),n=this.rowPool.get(e);if(!t||!n||!B(t))return;let r=this.buildRendererParams(t);r&&(n.syncBodyWidth(this.columnModel.getTotalWidth()),n.setData(t,r,this.getDetailCellRenderer?.(),this.isLastDisplayRow(e)))}clear(){this.rowPool.clear(),this.activeDetailIds.clear(),this.container.style.display=`none`}collectDetailRowIds(e,t){let n=new Set;if(t>=e)for(let r=e;r<=t;r++){let e=this.rowModel.getRow(r);e&&B(e)&&n.add(e.id)}for(let e of this.pinnedRowIds)st(e)&&n.add(e);return n}updateDetailRow(e){let t=this.findRowNodeById(e);if(!t||!B(t)||!t.masterRowId)return;let n=this.buildRendererParams(t);if(!n)return;let r=this.rowPool.acquire(e,()=>new Gp(this.container,{frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,detailRowAutoHeightService:this.detailRowAutoHeightService}));r.syncBodyWidth(this.columnModel.getTotalWidth()),r.setData(t,n,this.getDetailCellRenderer?.(),this.isLastDisplayRow(e)),r.setRowTop(this.compressedScroll?t.rowTop-this.scrollTop:t.rowTop)}syncDetailRowLayout(e){let t=this.findRowNodeById(e),n=this.rowPool.get(e);!t||!n||(n.syncRowLayout(t),n.syncBodyWidth(this.columnModel.getTotalWidth()),n.setRowTop(this.compressedScroll?t.rowTop-this.scrollTop:t.rowTop))}buildRendererParams(e){return zp(e,e=>this.getMasterRowById?.(e)??this.findRowNodeById(e))}findRowNodeById(e){for(let t=0;t<this.rowModel.getRowCount();t++){let n=this.rowModel.getRow(t);if(n?.id===e)return n}}isLastDisplayRow(e){let t=this.rowModel.getRowCount();return t!==0&&this.rowModel.getRow(t-1)?.id===e}},Jp=class{rowModel;columnModel;rowHeight;rowBuffer;stripe;rowPool=new Tf;rowCompFactory;rowsContainer;frameService;onUnmountRenderer;onUnmountEditor;inlineCellEditor;indexColumnOptions;selectionColumnOptions;rowAutoHeightService;isRowDragHandleEnabled;rowDragCommittingRowIds=null;enableCellSpan;cellSpanService;spannedRowRenderer;fullWidthRowRenderer;embedFullWidthRows;rowExpansionHost;rowGroupingHost;treeTableHost;cellCommentHost;getCellDisableContext=()=>({});getCellStyleContext=()=>({});detailRowAutoHeightService=null;resolveBusinessRowId;valueCacheVersion=0;pinnedRowIds=new Set;selectedRowIds=new Set;indeterminateRowIds=new Set;indexFocusedRowIds=new Set;isRowNodeSelectable=()=>!0;focusedCell=null;cellRangeIsSelected=null;cellRangeAnchor=null;indexColumnHighlightChecker=null;activeIndices=new Set;columnWindow={firstCol:0,lastCol:-1};currentWindow={firstRow:0,lastRow:-1,firstCol:0,lastCol:-1};compressedScroll=!1;scrollTop=0;cellRendererDefer=`always`;deferRowDestroyOnScroll=!1;cellRendererPresentation=`deferred`;scrollActive=!1;pendingDestroyTasks=new Map;constructor(e,t){this.rowsContainer=e,this.rowModel=t.rowModel,this.columnModel=t.columnModel,this.rowHeight=t.rowHeight??m,this.rowBuffer=t.rowBuffer??10,this.stripe=t.stripe??!1,this.frameService=t.frameService??null,this.onUnmountRenderer=t.onUnmountRenderer,this.onUnmountEditor=t.onUnmountEditor,this.indexColumnOptions=t.indexColumnOptions,this.selectionColumnOptions=t.selectionColumnOptions,this.rowAutoHeightService=t.rowAutoHeightService??null,this.isRowDragHandleEnabled=t.isRowDragHandleEnabled,this.enableCellSpan=t.enableCellSpan??!1,this.cellSpanService=t.cellSpanService??null,this.embedFullWidthRows=t.embedFullWidthRows??!1,this.rowExpansionHost=t.rowExpansionHost,this.rowGroupingHost=t.rowGroupingHost,this.treeTableHost=t.treeTableHost,this.cellCommentHost=t.cellCommentHost,this.resolveBusinessRowId=t.resolveBusinessRowId,this.getCellDisableContext=t.getCellDisableContext??this.getCellDisableContext,this.getCellStyleContext=t.getCellStyleContext??this.getCellStyleContext,this.cellRendererDefer=t.cellRendererDefer??`always`,this.deferRowDestroyOnScroll=t.deferRowDestroyOnScroll??!1,this.cellRendererPresentation=t.cellRendererPresentation??`deferred`,this.rowCompFactory=t.rowCompFactory??{create:()=>new Up(this.rowsContainer,{stripe:this.stripe,frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,onUnmountEditor:this.onUnmountEditor,inlineEditor:this.inlineCellEditor,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,rowAutoHeightService:this.rowAutoHeightService,isRowDragHandleEnabled:this.isRowDragHandleEnabled,isRowDragCommittingRow:e=>this.isRowDragCommittingRowAt(e),enableCellSpan:this.enableCellSpan,cellSpanService:this.cellSpanService,getRowByIndex:e=>this.rowModel.getRow(e),getRowCount:()=>this.rowModel.getRowCount(),embedFullWidthRows:this.embedFullWidthRows,getDetailCellRenderer:t.getDetailCellRenderer,getMasterRowById:t.getMasterRowById,rowExpansionHost:this.rowExpansionHost,rowGroupingHost:this.rowGroupingHost,treeTableHost:this.treeTableHost,getCellCommentHost:()=>this.cellCommentHost,detailRowAutoHeightService:this.detailRowAutoHeightService,resolveBusinessRowId:this.resolveBusinessRowId,getCellDisableContext:()=>this.getCellDisableContext(),getCellStyleContext:()=>this.getCellStyleContext(),cellRendererDefer:this.cellRendererDefer,isScrollActive:()=>this.scrollActive,cellRendererPresentation:this.cellRendererPresentation})},this.spannedRowRenderer=t.spannedRowsContainerEl?new Wp({container:t.spannedRowsContainerEl,rowModel:this.rowModel,columnModel:this.columnModel,stripe:this.stripe,frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,onUnmountEditor:this.onUnmountEditor,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,rowAutoHeightService:this.rowAutoHeightService,isRowDragHandleEnabled:this.isRowDragHandleEnabled,enableCellSpan:this.enableCellSpan,cellSpanService:this.cellSpanService}):null,this.fullWidthRowRenderer=t.fullWidthRowsContainerEl?new qp({container:t.fullWidthRowsContainerEl,rowModel:this.rowModel,columnModel:this.columnModel,frameService:this.frameService??void 0,onUnmountRenderer:this.onUnmountRenderer,masterDetail:t.masterDetail??!1,embedFullWidthRows:t.embedFullWidthRows??!1,getDetailCellRenderer:t.getDetailCellRenderer,getMasterRowById:t.getMasterRowById}):null}setEmbedFullWidthRows(e){this.embedFullWidthRows!==e&&(this.embedFullWidthRows=e,this.fullWidthRowRenderer?.setEmbedFullWidthRows(e),this.invalidate())}setMasterDetail(e){this.fullWidthRowRenderer?.setMasterDetail(e)}setRowDragHandleEnabled(e){this.isRowDragHandleEnabled=e}setRowDragCommittingRows(e){let t=this.rowDragCommittingRowIds,n=e&&e.length>0?new Set(e):null;if(!(t===n||t&&n&&t.size===n.size&&[...t].every(e=>n.has(e)))){if(t)for(let e of t)n?.has(e)||this.applyRowCommittingVisual(e,!1);if(this.rowDragCommittingRowIds=n,n)for(let e of n)this.applyRowCommittingVisual(e,!0)}}setEnableCellSpan(e){this.enableCellSpan=e;for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setEnableCellSpan?.(e);this.spannedRowRenderer?.setEnableCellSpan(e)}setCellSpanService(e){this.cellSpanService=e,this.spannedRowRenderer?.setCellSpanService(e)}setRowAutoHeightService(e){this.rowAutoHeightService=e,this.spannedRowRenderer?.setRowAutoHeightService(e)}setDetailRowAutoHeightService(e){this.detailRowAutoHeightService=e,this.fullWidthRowRenderer?.setDetailRowAutoHeightService(e)}setInlineCellEditorContext(e){this.inlineCellEditor=e,this.spannedRowRenderer?.setInlineCellEditorContext(e)}setCellCommentHost(e){this.cellCommentHost=e}setGetCellDisableContext(e){this.getCellDisableContext=e}setGetCellStyleContext(e){this.getCellStyleContext=e}setDefaultRowHeight(e){this.rowHeight=Math.max(1,e)}setCompressedScroll(e){this.compressedScroll=e,this.spannedRowRenderer?.setCompressedScroll(e),this.fullWidthRowRenderer?.setCompressedScroll(e)}getScrollTop(){return this.scrollTop}isCompressedScroll(){return this.compressedScroll}setScrollActive(e){this.scrollActive=e}setScrollRenderBehavior(e){e.cellRendererDefer!==void 0&&(this.cellRendererDefer=e.cellRendererDefer),e.deferRowDestroyOnScroll!==void 0&&(this.deferRowDestroyOnScroll=e.deferRowDestroyOnScroll),e.cellRendererPresentation!==void 0&&(this.cellRendererPresentation=e.cellRendererPresentation)}promoteRendererPlaceholders(){let e=0;for(let t of this.rowPool.getActiveIds()){let n=this.rowPool.get(t);e+=n?.promoteRendererPlaceholders()??0}return e}flushDeferredDestroys(){if(this.pendingDestroyTasks.size===0)return;let e=[...this.pendingDestroyTasks.values()];if(this.pendingDestroyTasks.clear(),this.frameService&&!this.compressedScroll){for(let t of e)this.frameService.addDestroyTask(t);return}for(let t of e)t()}cancelPendingDestroy(e){this.pendingDestroyTasks.delete(e)}redraw(e,t,n,r=!1){this.scrollTop=e,this.columnWindow=n;let i={...wf({scrollTop:e,viewportHeight:t,rowBuffer:this.rowBuffer,rowHeight:this.rowHeight,rowModel:this.rowModel}),firstCol:n.firstCol,lastCol:n.lastCol};return this.recycleRows(i,r),this.syncVisibleCellCommentIndicators(),this.refreshIndexColumnHighlight(),this.spannedRowRenderer?.redraw(e,i,n,r),this.fullWidthRowRenderer?.redraw(e,i),this.refreshCellRangeSelection(),this.currentWindow=i,i}getActiveRowCount(){return this.rowPool.getActiveCount()}getCurrentWindow(){return this.currentWindow}destroy(){this.rowPool.clear(),this.spannedRowRenderer?.destroy(),this.fullWidthRowRenderer?.destroy(),this.activeIndices.clear()}invalidate(){this.frameService&&this.frameService.flushAllFrames(),this.pendingDestroyTasks.clear(),this.rowPool.clear(),this.spannedRowRenderer?.invalidate(),this.fullWidthRowRenderer?.invalidate(),this.activeIndices.clear(),this.currentWindow={firstRow:0,lastRow:-1,firstCol:0,lastCol:-1}}setValueCacheVersion(e){this.valueCacheVersion=e,this.spannedRowRenderer?.setValueCacheVersion(e)}setPinnedRowIds(e){this.pinnedRowIds=new Set(e),this.fullWidthRowRenderer?.setPinnedRowIds(e)}setIsRowNodeSelectable(e){this.isRowNodeSelectable=e}refreshSelection(e,t=new Set){this.selectedRowIds=new Set(e),this.indeterminateRowIds=new Set(t);for(let n of this.rowPool.getActiveIds()){let r=this.rowPool.get(n);r?.setSelected?.(e.has(n),t.has(n)),this.syncRowSelectionDisabled(n,r)}this.spannedRowRenderer?.refreshSelection(e)}refreshDetailRows(e){for(let t of e){let e=ot(t);this.fullWidthRowRenderer?.refreshDetailRowContent(e);let n=this.rowPool.get(e);n?.refreshCells&&n.refreshCells({columnModel:this.columnModel,columnWindow:this.columnWindow,valueCacheVersion:this.valueCacheVersion,force:!0})}}syncRowSelectionDisabled(e,t=this.rowPool.get(e)){let n=this.findRowIndexById(e),r=n>=0?this.rowModel.getRow(n):null,i=r?!this.isRowNodeSelectable(r):!1;t?.setSelectionDisabled?.(i)}refreshIndexFocus(e){this.indexFocusedRowIds=new Set(e);for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setIndexFocused?.(e.has(t));this.spannedRowRenderer?.refreshIndexFocus(e)}setFocusedCell(e){this.focusedCell=e,this.refreshFocus()}refreshFocus(){let e=this.focusedCell;for(let t of this.rowPool.getActiveIds())this.rowPool.get(t)?.setFocusedColId?.(e?.rowId===t?e.colId:null);this.spannedRowRenderer?.setFocusedCell(e)}setCellRangeVisualState(e,t){this.cellRangeIsSelected=e,this.cellRangeAnchor=t,this.refreshCellRangeSelection()}setIndexColumnHighlight(e){this.indexColumnHighlightChecker=e,this.refreshIndexColumnHighlight()}refreshCellRangeSelection(){let e=this.cellRangeIsSelected,t=this.cellRangeAnchor;for(let n of this.rowPool.getActiveIds()){let r=this.findRowIndexById(n),i=this.rowPool.get(n);!i?.setCellRangeSelection||r<0||i.setCellRangeSelection(e?t=>e(r,t):()=>!1,t?.rowIndex===r?t.colId:null,e??void 0)}this.spannedRowRenderer?.setCellRangeVisualState(e,t)}refreshIndexColumnHighlight(){let e=this.indexColumnHighlightChecker;for(let t of this.rowPool.getActiveIds()){let n=this.findRowIndexById(t),r=this.rowPool.get(t);!r?.setIndexColumnRangeHighlight||n<0||r.setIndexColumnRangeHighlight(e?e(n):!1)}}playCellRangeCopyFlash(){let e=this.cellRangeIsSelected;if(e){for(let t of this.rowPool.getActiveIds()){let n=this.findRowIndexById(t),r=this.rowPool.get(t);!r?.flashCellRangeSelection||n<0||r.flashCellRangeSelection(t=>e(n,t),e)}this.spannedRowRenderer?.playCellRangeCopyFlash()}}playCellRangePasteFlash(e){if(e.length===0)return;let t=new Map;for(let n of e){let e=t.get(n.rowIndex);e?e.push(n):t.set(n.rowIndex,[n])}for(let e of this.rowPool.getActiveIds()){let n=this.findRowIndexById(e),r=this.rowPool.get(e),i=t.get(n);!r?.flashCellRangePaste||!i?.length||n<0||r.flashCellRangePaste(i)}this.spannedRowRenderer?.playCellRangePasteFlash(e)}syncColumnLayouts(){for(let e of this.rowPool.getActiveIds())this.rowPool.get(e)?.syncColumnLayouts?.();this.spannedRowRenderer?.syncColumnLayouts(),this.fullWidthRowRenderer?.syncColumnLayouts()}refreshVisibleColumnStructure(e){this.columnWindow=e;let t={columnStructureChanged:!0};for(let e of this.activeIndices)this.updateRowAtIndex(e,t);for(let e of this.pinnedRowIds){let n=this.findRowIndexById(e);n>=0&&!this.activeIndices.has(n)&&this.updateRowAtIndex(n,t)}this.spannedRowRenderer?.refreshVisibleColumnStructure(e),this.refreshCellRangeSelection(),this.syncVisibleCellCommentIndicators(),this.refreshIndexColumnHighlight()}migrateRowId(e,t){if(e===t)return;this.rowPool.migrateId(e,t);let n=this.rowPool.get(t);n&&(n.getElement().dataset.rowId=t),this.selectedRowIds.has(e)&&(this.selectedRowIds.delete(e),this.selectedRowIds.add(t)),this.indexFocusedRowIds.has(e)&&(this.indexFocusedRowIds.delete(e),this.indexFocusedRowIds.add(t)),this.focusedCell?.rowId===e&&(this.focusedCell={rowId:t,colId:this.focusedCell.colId}),this.pinnedRowIds.has(e)&&(this.pinnedRowIds.delete(e),this.pinnedRowIds.add(t)),this.spannedRowRenderer?.migrateRowId(e,t)}refreshRows(e){let t=e.rowIds?new Set(e.rowIds):null,{firstRow:n,lastRow:r}=this.currentWindow;if(r<n)return 0;let i=0;for(let a=n;a<=r;a++){let n=this.rowModel.getRow(a);if(!n||t&&!t.has(n.id))continue;let r=this.rowPool.get(n.id);r?.refreshCells&&(i+=r.refreshCells({columnModel:this.columnModel,columnWindow:this.columnWindow,valueCacheVersion:this.valueCacheVersion,colIds:e.colIds,force:e.force,indexColumnOptions:this.indexColumnOptions,selectionColumnOptions:this.selectionColumnOptions,inlineEditor:this.inlineCellEditor}))}return i+=this.spannedRowRenderer?.refreshRows(e)??0,this.syncVisibleCellCommentIndicators({rowIds:e.rowIds,colIds:e.colIds}),i}syncVisibleCellCommentIndicators(e){if(!this.cellCommentHost?.active())return;let t=e?.rowIds?new Set(e.rowIds):null,n=e?.colIds?new Set(e.colIds):null,{firstRow:r,lastRow:i}=this.currentWindow;if(!(i<r)){for(let e=r;e<=i;e++){let r=this.rowModel.getRow(e);r&&(t&&!t.has(r.id)||this.rowPool.get(r.id)?.syncCellCommentIndicators?.(n))}for(let e of this.pinnedRowIds)t&&!t.has(e)||this.rowPool.get(e)?.syncCellCommentIndicators?.(n)}}syncVisibleRowLayouts(e){let t=e?new Set(e):null,n=e=>{let n=this.rowModel.getRow(e);if(!n||t&&!t.has(n.id))return;let r=this.rowPool.get(n.id);if(!r){this.updateRowAtIndex(e);return}r.syncRowLayout?.(n),r.setRowTop(this.compressedScroll?n.rowTop-this.scrollTop:n.rowTop)};for(let e of this.activeIndices)n(e);for(let e of this.pinnedRowIds){if(t&&!t.has(e))continue;let r=this.findRowIndexById(e);r>=0&&n(r)}this.spannedRowRenderer?.syncVisibleRowLayouts(e),this.fullWidthRowRenderer?.syncVisibleRowLayouts(e)}recycleRows(e,t){let n=vf(this.activeIndices,e);if(t)for(let e of this.activeIndices)n.toUpdate.includes(e)||n.toUpdate.push(e);for(let e of n.toDestroy){let t=this.rowModel.getRow(e);if(!t||!this.rowPool.get(t.id)||this.pinnedRowIds.has(t.id))continue;let n=t.id,r=()=>{this.rowPool.release(n)};this.frameService&&!this.compressedScroll?this.deferRowDestroyOnScroll&&this.scrollActive?this.pendingDestroyTasks.set(n,r):this.frameService.addDestroyTask(r):r()}for(let e of n.toUpdate)this.updateRowAtIndex(e,t?{columnStructureChanged:!0}:void 0);for(let e of n.toCreate){let n=t?{columnStructureChanged:!0}:void 0;this.frameService&&!this.compressedScroll?this.frameService.createTask(()=>{this.updateRowAtIndex(e,n)},e,`p1`):this.updateRowAtIndex(e,n)}this.activeIndices=Yp(e);for(let e of this.pinnedRowIds){let r=this.findRowIndexById(e);r>=0&&(this.activeIndices.add(r),!n.toUpdate.includes(r)&&!n.toCreate.includes(r)&&this.updateRowAtIndex(r,t?{columnStructureChanged:!0}:void 0))}}updateRowAtIndex(e,t){let n=this.rowModel.getRow(e);if(!n||B(n)&&!this.embedFullWidthRows)return;this.cancelPendingDestroy(n.id);let r=this.rowPool.acquire(n.id,()=>this.rowCompFactory.create()),i=this.rowModel.getRowCount();r.setData(n,this.columnModel,this.columnWindow,this.valueCacheVersion,i>0&&e===i-1,t),r.setRowTop(this.compressedScroll?n.rowTop-this.scrollTop:n.rowTop),r.setSelected?.(this.selectedRowIds.has(n.id)),r.setSelectionDisabled?.(!this.isRowNodeSelectable(n)),r.setIndexFocused?.(this.indexFocusedRowIds.has(n.id)),r.setIndexColumnRangeHighlight?.(this.indexColumnHighlightChecker?.(e)??!1),r.setFocusedColId?.(this.focusedCell?.rowId===n.id?this.focusedCell.colId:null)}findRowIndexById(e){let{firstRow:t,lastRow:n}=this.currentWindow;if(n<t)return-1;for(let r=t;r<=n;r++)if(this.rowModel.getRow(r)?.id===e)return r;for(let t=0;t<this.rowModel.getRowCount();t++)if(this.rowModel.getRow(t)?.id===e)return t;return-1}isRowDragCommittingRowAt(e){return this.rowDragCommittingRowIds?.has(e)??!1}applyRowCommittingVisual(e,t){this.rowPool.get(e)?.setRowDragCommittingVisual?.(t),this.rowsContainer.querySelector(`.mg-row[data-row-id="${CSS.escape(e)}"]`)?.classList.toggle(sa,t)}};function Yp(e){let t=new Set;if(e.lastRow<e.firstRow)return t;for(let n=e.firstRow;n<=e.lastRow;n++)t.add(n);return t}var Xp=[`left`,`center`,`right`];function Zp(e,t){let n=Xp.filter(t=>e.includes(t)),r=n.indexOf(t);return r<0?{top:!0,right:!0,bottom:!0,left:!0}:{top:!0,bottom:!0,left:r===0,right:r===n.length-1}}function Qp(e){return{top:e.top,height:e.height}}function $p(e){return e.fixed??`center`}function em(e,t,n,r,i=0){let a=t.indexOf(e.leftColId),o=t.indexOf(e.rightColId);if(a<0||o<0)return null;let s=Math.min(a,o),c=Math.max(a,o),l=null,u=null;for(let e=s;e<=c;e++){let i=t[e];if(!i)continue;let a=n.find(e=>e.colId===i);!a||a.hidden||$p(a)===r&&(l||=a,u=a)}return!l||!u?null:{left:l.left-i,width:u.left+u.width-l.left}}function tm(e,t){return e===`right`?t.getLeftFixedWidth()+t.getCenterTotalWidth():0}function nm(e,t){if(t<=0)return null;let n=e.top+e.height,r=Math.max(0,e.top),i=Math.min(t,n)-r;return i<=0?null:{top:r,height:i,lanes:e.lanes}}function rm(e,t,n,r,i,a){let{topRowIndex:o,bottomRowIndex:s}=tc(e,t,a??{rowModel:r,columnModel:n,cellSpanService:null}),c=r.getRow(o),l=r.getRow(s);if(!c||!l)return null;let u=n.getColumns(),d={};for(let r of[`left`,`center`,`right`]){let i=em(e,t,u,r,tm(r,n));i&&(d[r]=i)}if(Object.keys(d).length===0)return null;let f=c.rowTop,p=l.rowTop+l.rowHeight-c.rowTop,m={top:i.compressedScroll?f-i.scrollTop:f,height:p,lanes:d};return!i.compressedScroll||i.viewportHeight==null?m:nm(m,i.viewportHeight)}function im(e,t){let n=new Set;for(let r of e){let e=t.indexOf(r.leftColId),i=t.indexOf(r.rightColId);if(e<0||i<0)continue;let a=Math.min(e,i),o=Math.max(e,i);for(let e=a;e<=o;e++){let r=t[e];r&&n.add(r)}}return n}function am(e){let t=new Set;for(let n of e)for(let e=n.top;e<=n.bottom;e+=1)t.add(e);return t}function om(e,t){if(t<=0)return{rect:{...e,left:0,width:0},clippedLeft:!0,clippedRight:!0};let n=e.left,r=e.width,i=!1,a=!1;n<0&&(r+=n,n=0,i=!0);let o=n+r-t;return o>0&&(r-=o,a=!0),r<=0?{rect:{...e,left:n,width:0},clippedLeft:i,clippedRight:a}:{rect:{...e,left:n,width:r},clippedLeft:i,clippedRight:a}}function sm(e,t,n){if(n<=0)return{rect:{...e,left:0,width:0},clippedLeft:!0,clippedRight:!0};let r=t,i=t+n;e.left+e.width;let a=e.left,o=e.width,s=!1,c=!1;return a<r&&(o-=r-a,a=r,s=!0),a+o>i&&(o-=a+o-i,c=!0),o<=0?{rect:{...e,left:a,width:0},clippedLeft:s,clippedRight:c}:{rect:{...e,left:a,width:o},clippedLeft:s,clippedRight:c}}function cm(e,t){return{top:e.top,bottom:e.bottom,left:e.left&&!t.clippedLeft,right:e.right&&!t.clippedRight}}function lm(e,t,n){return uo(e,t,n)}function um(e){return e===`right`}function dm(e,t,n,r,i,a){let o=a??rm(e,t,n,r,i);if(!o)return null;let s=e.rightColId,c=n.getColumnById(s);if(!c||c.hidden)return null;let l=$p(c),u=o.lanes[l];if(!u)return null;let d=u.left+u.width-6/2,{top:f,height:p}=Qp(o);return{lane:l,left:d,top:f+p-6/2}}var fm=class{deps;overlayEl=null;overlayLanes=null;pasteFlashOverlayEl=null;pasteFlashLanes=null;pasteFlashCleanupTimer=null;fillHandleEl=null;rangeHandleEl=null;normalizedRanges=[];anchor=null;displayedColIds=[];constructor(e){this.deps=e}refresh(e){this.displayedColIds=e.displayedColIds,this.anchor=e.anchor,this.normalizedRanges=e.ranges.map(t=>Y(t,e.displayedColIds)).filter(e=>e!=null),this.syncRangeSelectionVisuals(),this.syncHeaderHighlight(),this.syncIndexColumnHighlight()}clear(){this.normalizedRanges=[],this.anchor=null,this.displayedColIds=[],this.syncRangeSelectionVisuals(),this.syncHeaderHighlight(),this.syncIndexColumnHighlight()}syncRangeSelectionVisuals(){if(!this.deps.isCellSelectionVisualEnabled?.()){this.deps.rowRenderer.setCellRangeVisualState(null,null),this.clearBorderOverlays(),this.clearSelectionHandles();return}this.syncCellClasses(),this.syncBorderOverlays(),this.syncSelectionHandle()}syncCellClasses(){let e=this.displayedColIds,t=this.normalizedRanges,n=this.anchor;if(t.length===0){this.deps.rowRenderer.setCellRangeVisualState(null,null);return}this.deps.rowRenderer.setCellRangeVisualState((n,r)=>t.some(t=>Vs(n,r,t,e)),n)}ensureOverlay(){if(this.overlayEl&&this.overlayLanes)return this.overlayLanes;this.deps.mountEl.querySelectorAll(`.${ps}`).forEach(e=>{e.remove()});let e=document.createElement(`div`);e.className=ps;let t=t=>{let n=document.createElement(`div`);return n.className=`mg-cell-range-overlay__lane mg-cell-range-overlay__lane--${t}`,e.appendChild(n),n},n={left:t(`left`),center:t(`center`),right:t(`right`)};return this.deps.rowsLayerEl.appendChild(e),this.overlayEl=e,this.overlayLanes=n,n}resolveBandOptions(){let e=this.deps.isCompressedScroll();return{scrollTop:this.deps.getScrollTop(),scrollLeft:this.deps.getScrollLeft(),compressedScroll:e,viewportHeight:e?this.deps.getViewportHeight():void 0}}findCellElement(e,t){let n=this.deps.rowModel.getRow(e);if(!n)return null;let r=pm(n.id),i=pm(t),a=this.deps.mountEl.querySelector(`.mg-row[data-row-id="${r}"] .mg-cell[data-col-id="${i}"]`);return a instanceof HTMLElement?a:null}syncOverlayLaneLayoutFor(e,t){let{leftFixedWidth:n,centerTotalWidth:r,rightFixedWidth:i}=t;e.left.style.width=`${n}px`,e.center.style.width=`${r}px`,e.right.style.width=`${i}px`,e.center.style.position=`relative`,e.center.style.left=``,e.center.style.transform=``}resolveOverlayLaneLayoutParams(){return{leftFixedWidth:this.deps.columnModel.getLeftFixedWidth(),centerTotalWidth:this.deps.columnModel.getCenterTotalWidth(),rightFixedWidth:this.deps.columnModel.getRightFixedWidth()}}syncOverlayRootWidth(e){let t=this.deps.columnModel.getTotalWidth();e.style.left=`0`,e.style.right=`auto`,e.style.width=`${t}px`,e.style.minWidth=`${t}px`}syncOverlayLaneLayout(e){let t=this.overlayLanes;t&&(this.overlayEl&&this.syncOverlayRootWidth(this.overlayEl),this.syncOverlayLaneLayoutFor(t,e))}findRowLaneElement(e,t){let n=this.deps.rowModel.getRow(e);if(!n)return null;let r=this.deps.mountEl.querySelector(`.mg-row[data-row-id="${pm(n.id)}"]`);if(!(r instanceof HTMLElement))return null;let i=r.querySelector(`.mg-row__lane--${t}`);return i instanceof HTMLElement?i:null}resolveLaneContentRectForRange(e,t){return em(e,this.displayedColIds,this.deps.columnModel.getColumns(),t,tm(t,this.deps.columnModel))}resolveRangeBand(e,t){let n={rowModel:this.deps.rowModel,columnModel:this.deps.columnModel,cellSpanService:this.deps.getCellSpanService?.()??null};return{band:rm(e,this.displayedColIds,this.deps.columnModel,this.deps.rowModel,t,n),domMeasuredLanes:new Set}}syncBorderOverlays(){if(this.normalizedRanges.length===0){this.clearBorderOverlays();return}let e=this.ensureOverlay(),t=this.resolveBandOptions(),{scrollLeft:n}=t,r=this.deps.columnModel.getLeftFixedWidth(),i=this.deps.columnModel.getCenterTotalWidth(),a=this.deps.columnModel.getRightFixedWidth(),o=this.deps.getViewportWidth(),s=lm(o,r,a),c=o>0&&s>0&&s<i;e.left.replaceChildren(),e.center.replaceChildren(),e.right.replaceChildren(),this.syncOverlayLaneLayout({leftFixedWidth:r,centerTotalWidth:i,rightFixedWidth:a}),e.center.offsetWidth,e.right.offsetWidth;for(let r of this.normalizedRanges){let{band:o}=this.resolveRangeBand(r,t);if(!o)continue;let l=[`left`,`center`,`right`].filter(e=>this.resolveLaneContentRectForRange(r,e)!=null);for(let t of l){let u=this.resolveLaneContentRectForRange(r,t),d=u,f;if(f=t===`center`&&c?sm(u,lo(n,i,s),s):t===`center`||t===`right`?om(d,t===`center`?i:a):{rect:d,clippedLeft:!1,clippedRight:!1},f.rect.width<=0)continue;let p=cm(Zp(l,t),f);t===`center`&&!l.includes(`left`)&&f.clippedLeft&&(p={...p,left:!1});let{top:m,height:h}=Qp(o);if(t===`center`){this.appendSegmentedBorder(e[t],p,m,h,f.rect.left,f.rect.width);continue}um(t)?this.appendSegmentedBorder(e[t],p,m,h,f.rect.left,f.rect.width):this.appendEnvelopeBorder(e[t],p,m,h,f.rect.left,f.rect.width)}}this.ensureOverlayOnTop()}ensureOverlayOnTop(){this.overlayEl?.parentElement===this.deps.rowsLayerEl&&this.deps.rowsLayerEl.appendChild(this.overlayEl)}appendEnvelopeBorder(e,t,n,r,i,a){let o=document.createElement(`div`);o.className=os,t.top&&o.classList.add(ss),t.right&&o.classList.add(cs),t.bottom&&o.classList.add(ls),t.left&&o.classList.add(us),o.style.top=`${n}px`,o.style.height=`${r}px`,o.style.left=`${i}px`,o.style.width=`${a}px`,e.appendChild(o)}appendSegmentedBorder(e,t,n,r,i,a){let o=(t,n)=>{let r=document.createElement(`div`);r.className=`${os} ${t}`;for(let[e,t]of Object.entries(n))r.style.setProperty(e,t);e.appendChild(r)};t.top&&o(ds,{top:`${n}px`,left:`${i}px`,width:`${a}px`,height:`2px`}),t.bottom&&o(ds,{top:`${n+r-2}px`,left:`${i}px`,width:`${a}px`,height:`2px`}),t.left&&o(fs,{top:`${n}px`,left:`${i}px`,width:`2px`,height:`${r}px`}),t.right&&o(fs,{top:`${n}px`,left:`${i+a-2}px`,width:`2px`,height:`${r}px`})}playCopyFlash(){if(this.normalizedRanges.length===0)return;this.deps.rowRenderer.playCellRangeCopyFlash(),this.ensureOverlay();let e=this.overlayEl;if(!e)return;e.classList.remove(hs),e.offsetWidth,e.classList.add(hs);let t=()=>{e.classList.remove(hs),e.removeEventListener(`animationend`,t)};e.addEventListener(`animationend`,t)}playPasteFlash(e){e.length!==0&&(this.deps.rowRenderer.playCellRangePasteFlash(e),this.playPasteTargetOverlayFlash(e))}measurePasteTargetCellOverlayRect(e,t,n){let r=this.findCellElement(e,t);if(!r)return null;let i=this.deps.columnModel.getColumnById(t);if(!i)return null;let a=i.fixed??`center`,o=n[a],s=r.getBoundingClientRect(),c=o.getBoundingClientRect(),l=s.top-c.top,u=s.left-c.left,d=s.width,f=s.height;return d<=0||f<=0?null:{lane:a,top:l,left:u,width:d,height:f}}playPasteTargetOverlayFlash(e){this.clearPasteFlashOverlay();let t=this.ensurePasteFlashOverlay();this.syncPasteFlashOverlayLayout();let n=[];for(let r of e){let e=this.measurePasteTargetCellOverlayRect(r.rowIndex,r.colId,t);if(!e)continue;let i=document.createElement(`div`);i.className=`${vs} ${r.applied?ys:bs}`,i.style.top=`${e.top}px`,i.style.left=`${e.left}px`,i.style.width=`${e.width}px`,i.style.height=`${e.height}px`,t[e.lane].appendChild(i),n.push(i)}n.length!==0&&(this.pasteFlashCleanupTimer=window.setTimeout(()=>{this.pasteFlashCleanupTimer=null;for(let e of n)e.remove()},520))}syncOverlayPosition(){if(this.normalizedRanges.length===0){this.syncPasteFlashOverlayLayout();return}this.syncBorderOverlays(),this.syncSelectionHandle(),this.syncPasteFlashOverlayLayout()}clearPasteFlashOverlay(){this.pasteFlashCleanupTimer!=null&&(window.clearTimeout(this.pasteFlashCleanupTimer),this.pasteFlashCleanupTimer=null),this.pasteFlashLanes?.left.replaceChildren(),this.pasteFlashLanes?.center.replaceChildren(),this.pasteFlashLanes?.right.replaceChildren()}ensurePasteFlashOverlay(){if(this.pasteFlashOverlayEl&&this.pasteFlashLanes)return this.pasteFlashLanes;let e=document.createElement(`div`);e.className=xs;let t=t=>{let n=document.createElement(`div`);return n.className=`mg-cell-range-overlay__lane mg-cell-range-overlay__lane--${t}`,e.appendChild(n),n},n={left:t(`left`),center:t(`center`),right:t(`right`)};return this.deps.rowsLayerEl.appendChild(e),this.pasteFlashOverlayEl=e,this.pasteFlashLanes=n,n}syncPasteFlashOverlayLayout(){let e=this.pasteFlashLanes;e&&(e.left.childElementCount>0||e.center.childElementCount>0||e.right.childElementCount>0)&&(this.syncOverlayLaneLayoutFor(e,this.resolveOverlayLaneLayoutParams()),this.pasteFlashOverlayEl&&this.syncOverlayRootWidth(this.pasteFlashOverlayEl),this.pasteFlashOverlayEl?.parentElement===this.deps.rowsLayerEl&&this.deps.rowsLayerEl.appendChild(this.pasteFlashOverlayEl))}clearBorderOverlays(){this.overlayLanes?.left.replaceChildren(),this.overlayLanes?.center.replaceChildren(),this.overlayLanes?.right.replaceChildren()}ensureFillHandle(){if(this.fillHandleEl)return this.fillHandleEl;let e=document.createElement(`div`);return e.className=Ss,e.style.width=`6px`,e.style.height=`6px`,this.fillHandleEl=e,e}clearSelectionHandles(){this.fillHandleEl?.remove(),this.fillHandleEl=null,this.rangeHandleEl?.remove(),this.rangeHandleEl=null}syncSelectionHandle(){let e=this.deps.getCellSelectionOptions?.();if(!e||this.normalizedRanges.length!==1){this.clearSelectionHandles();return}let t=this.normalizedRanges[0],n=this.resolveBandOptions(),{band:r}=this.resolveRangeBand(t,n),i=dm(t,this.displayedColIds,this.deps.columnModel,this.deps.rowModel,{...n,viewportWidth:this.deps.getViewportWidth()},null);if(!i){this.clearSelectionHandles();return}if(Ps(e)){this.rangeHandleEl?.remove(),this.rangeHandleEl=null,this.mountHandle(this.ensureFillHandle(),i);return}if(Fs(e)){this.fillHandleEl?.remove(),this.fillHandleEl=null,this.mountHandle(this.ensureRangeHandle(),i);return}this.clearSelectionHandles()}mountHandle(e,t){let n=this.ensureOverlay()[t.lane],r=t.lane===`left`?this.deps.columnModel.getLeftFixedWidth():t.lane===`center`?this.deps.columnModel.getCenterTotalWidth():this.deps.columnModel.getRightFixedWidth(),i=Math.max(0,r-6),a=Math.min(Math.max(t.left,0),i);if(r<=0){e.remove();return}e.parentElement!==n&&(e.remove(),n.appendChild(e)),e.style.left=`${a}px`,e.style.top=`${t.top}px`}ensureRangeHandle(){if(this.rangeHandleEl)return this.rangeHandleEl;let e=document.createElement(`div`);return e.className=Cs,e.style.width=`6px`,e.style.height=`6px`,this.rangeHandleEl=e,e}syncHeaderHighlight(){let e=this.deps.isHeaderHighlightEnabled()?im(this.normalizedRanges,this.displayedColIds):new Set;this.deps.mountEl.querySelectorAll(`.mg-header-cell[data-col-id]`).forEach(t=>{if(!(t instanceof HTMLElement))return;let n=t.dataset.colId;t.classList.toggle(ws,n!=null&&e.has(n))})}syncIndexColumnHighlight(){if(!this.deps.isIndexColumnHighlightEnabled()){this.deps.rowRenderer.setIndexColumnHighlight(null);return}let e=Js({rangeRowIndices:am(this.normalizedRanges),indexFocusedRowIds:this.deps.getIndexFocusedRowIds?.()??[],selectedRowIds:this.deps.getSelectedRowIds?.()??[],rowIndexById:e=>this.deps.rowModel.getRowIndexById(e)});this.deps.rowRenderer.setIndexColumnHighlight(t=>e.has(t))}destroy(){this.clear(),this.clearPasteFlashOverlay(),this.overlayEl?.remove(),this.overlayEl=null,this.overlayLanes=null,this.pasteFlashOverlayEl?.remove(),this.pasteFlashOverlayEl=null,this.pasteFlashLanes=null,this.fillHandleEl=null,this.rangeHandleEl=null}};function pm(e){return typeof CSS<`u`&&typeof CSS.escape==`function`?CSS.escape(e):e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}var mm=class{scrollTop=0;nextScrollTop=0;notifyScroll(e){this.nextScrollTop=e}isScrollGoingDown(){return this.nextScrollTop>=this.scrollTop}scrollGridIfNeeded(e){return this.scrollTop!==this.nextScrollTop&&(this.scrollTop=this.nextScrollTop,e(this.scrollTop),!0)}syncScrollTop(e){this.scrollTop=e,this.nextScrollTop=e}getScrollTop(){return this.scrollTop}getNextScrollTop(){return this.nextScrollTop}},hm=class{version=0;getVersion(){return this.version}bump(){this.version++}reset(){this.version=0}};function gm(e={}){return{navigateHeader:e.navigateHeader??!1,navigateFooter:e.navigateFooter??!1}}function _m(e,t,n){if(t.size===0)return e.slice();let r=[];for(let i of e)ct(i)&&(r.push(i),t.has(i.id)&&r.push(n(i)));return r}function vm(e,t,n){if(e.__detailLoading||e.__detailRowData!==void 0)return;e.__detailLoading=!0,delete e.__detailLoadError,n.onLoading();let r=!1,i=e=>{r||(r=!0,e(),n.onSettled())},a={rowId:e.id,data:e.data,successCallback:t=>{i(()=>{e.__detailRowData=t,e.__detailLoading=!1})},failCallback:t=>{i(()=>{e.__detailLoading=!1,e.__detailLoadError=t??!0})}};try{let e=t(a);ym(e)&&e.catch(e=>{a.failCallback?.(e)})}catch(e){a.failCallback?.(e)}}function ym(e){return typeof e==`object`&&!!e&&`then`in e&&typeof e.then==`function`}function bm(e){let t=e.style.height,n=e.style.minHeight,r=e.style.overflow;e.style.height=`auto`,e.style.minHeight=`0`,e.style.overflow=`visible`;let i=e.scrollHeight;return e.style.height=t,e.style.minHeight=n,e.style.overflow=r,Math.ceil(i)}var xm=1,Sm=5,Cm=class{deps;debounceTimer=null;pendingHeights=new Map;contentCleanups=new Map;constructor(e){this.deps=e}setupContentObserver(e,t){if(!this.deps.isEnabled())return;this.teardownContentObserver(e);let n=(r=0)=>{let i=this.deps.getRowById(e);if(!i||!B(i))return;let a=bm(t);if(a<=0&&r<Sm){window.setTimeout(()=>n(r+1),0);return}a>0&&this.queueMeasuredHeight(e,a,i)};n();let r=typeof ResizeObserver<`u`?new ResizeObserver(()=>{n()}):null;r?.observe(t),this.contentCleanups.set(e,()=>{r?.disconnect()})}teardownContentObserver(e){this.contentCleanups.get(e)?.(),this.contentCleanups.delete(e)}destroy(){this.debounceTimer!=null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null);for(let e of this.contentCleanups.values())e();this.contentCleanups.clear(),this.pendingHeights.clear()}queueMeasuredHeight(e,t,n){let r=this.deps.getMinDetailRowHeight(n),i=Math.max(r,t);n.rowHeight===i&&!n.estimated||(this.pendingHeights.set(e,i),this.scheduleApply())}scheduleApply(){this.debounceTimer??=window.setTimeout(()=>{this.debounceTimer=null,this.flushPendingHeights()},xm)}flushPendingHeights(){if(this.pendingHeights.size!==0){for(let[e,t]of this.pendingHeights.entries()){let n=this.deps.getRowById(e);!n||n.rowHeight===t&&!n.estimated||this.deps.rowHeightService.setRowHeight(e,t,!0,`autoHeight`)}this.pendingHeights.clear()}}};function wm(e,t){let n=lt(t.detailRowHeight,{rowId:e.id,data:e.data,masterRowId:e.id});return{id:ot(e.id),data:e.data,rowKind:`detail`,masterRowId:e.id,rowTop:0,rowHeight:n,estimated:t.detailRowAutoHeight,rowIndex:0}}var Tm=class{deps;expandedMasterIds=new Set;constructor(e){this.deps=e}get active(){return this.deps.getOptions().masterDetail}isExpanded(e){return this.expandedMasterIds.has(e)}getExpandedMasterIds(){return this.expandedMasterIds}getPinnedRowIds(){let e=[];for(let t of this.expandedMasterIds)e.push(t,ot(t));return e}isRowMaster(e){return!this.active||B(e)?!1:this.deps.getOptions().isRowMaster({rowId:e.id,data:e.data,rowIndex:e.rowIndex})}expandRow(e,t){if(!this.active||this.expandedMasterIds.has(e))return!1;let n=this.findBaseMasterRow(e);return!n||!this.isRowMaster(n)?!1:(this.expandedMasterIds.add(e),this.ensureDetailRowData(e),this.emit(ut(e,t)),!0)}collapseRow(e,t){return!this.active||!this.expandedMasterIds.has(e)?!1:(this.expandedMasterIds.delete(e),this.clearMasterDetailCache(e),this.emit(dt(e,t)),!0)}toggleRow(e,t){return this.isExpanded(e)?this.collapseRow(e,t):this.expandRow(e,t)}expandAll(e){if(this.active)for(let t of this.deps.getBaseDisplayRows())this.isRowMaster(t)&&this.expandRow(t.id,e)}collapseAll(e){if(this.active)for(let t of[...this.expandedMasterIds])this.collapseRow(t,e)}pruneExpanded(e){for(let t of[...this.expandedMasterIds])e.has(t)||(this.expandedMasterIds.delete(t),this.clearMasterDetailCache(t))}clearExpanded(){this.expandedMasterIds.clear()}applyDefaultExpanded(e){if(this.active&&this.deps.getOptions().masterDefaultExpanded!==0)for(let t of e)this.isRowMaster(t)&&(this.expandedMasterIds.add(t.id),this.ensureDetailRowData(t.id))}injectDetailRows(e){return!this.active||this.expandedMasterIds.size===0?e.slice():_m(e,this.expandedMasterIds,e=>this.createDetailRowNode(e))}createDetailRowNode(e){let t=this.deps.getOptions();return wm(e,{detailRowHeight:t.detailRowHeight,detailRowAutoHeight:t.detailRowAutoHeight})}findBaseMasterRow(e){return this.deps.getBaseDisplayRows().find(t=>t.id===e)}clearMasterDetailCache(e){let t=this.findBaseMasterRow(e);t&&(delete t.__detailRowData,delete t.__detailLoading,delete t.__detailLoadError)}ensureDetailRowData(e){let t=this.deps.getOptions().getDetailRowData;if(!t)return;let n=this.findBaseMasterRow(e);n&&vm(n,t,{onLoading:()=>this.deps.onDetailDataChanged?.(e),onSettled:()=>this.deps.onDetailDataChanged?.(e)})}emit(e){this.deps.onExpansionChanged?.(e)}},Em=class{deps;expandedGroupIds=new Set;rowGroupColumns;constructor(e){this.deps=e,this.rowGroupColumns=[...e.getRowGroupColumnsFromDefs()]}get active(){return zt(this.deps.getOptions().rowGrouping,this.rowGroupColumns)}getExpandedGroupIds(){return this.expandedGroupIds}getRowGroupColumns(){return this.rowGroupColumns}syncRowGroupColumnsFromDefs(){this.rowGroupColumns=[...this.deps.getRowGroupColumnsFromDefs()]}setRowGroupColumns(e,t){this.deps.getOptions().rowGrouping&&(this.rowGroupColumns=[...e],this.clearExpanded(),this.emitGroupChanged($t(this.rowGroupColumns,t)))}isExpanded(e){return this.expandedGroupIds.has(e)}expandGroup(e,t){if(!this.active||this.expandedGroupIds.has(e))return;let n=Ud(this.deps.getGroupedTreeRoots(),e);n?.groupId&&(this.expandedGroupIds.add(e),this.emitGroupOpened(n,!0,t),this.deps.onGroupingStateChanged?.())}collapseGroup(e,t){if(!this.active||!this.expandedGroupIds.has(e))return;let n=Ud(this.deps.getGroupedTreeRoots(),e);this.expandedGroupIds.delete(e),n?.groupId&&this.emitGroupOpened(n,!1,t),this.deps.onGroupingStateChanged?.()}toggleGroup(e,t){if(this.isExpanded(e)){this.collapseGroup(e,t);return}this.expandGroup(e,t)}expandAll(e){if(this.active)for(let t of Hd(this.deps.getGroupedTreeRoots()))this.expandedGroupIds.has(t)||this.expandGroup(t,e)}collapseAll(e){if(this.active)for(let t of[...this.expandedGroupIds])this.collapseGroup(t,e)}clearExpanded(){this.expandedGroupIds.clear()}pruneExpanded(e){for(let t of[...this.expandedGroupIds])e.has(t)||this.expandedGroupIds.delete(t)}applyDefaultExpanded(e){if(!this.active)return;let t=this.deps.getOptions().groupDefaultExpanded;t!==0&&Vd(e,e=>{!Wd(e.groupLevel??0,t)||!e.groupId||this.expandedGroupIds.add(e.groupId)})}getLeafGroupPathKey(e){return!Zt(e)||Jt(e)||Yt(e)?null:e.leafGroupPathKey??null}getMapStageOptions(){return{expandedGroupIds:this.expandedGroupIds,showGroupHeader:this.deps.getOptions().showGroupHeader,showGroupFooter:this.deps.getOptions().showGroupFooter}}emitGroupOpened(e,t,n){this.deps.onGroupOpened?.(Qt({groupId:e.groupId,expanded:t,field:e.groupField??``,key:e.groupKey??``,level:e.groupLevel??0,source:n}))}emitGroupChanged(e){this.deps.onGroupChanged?.(e)}};function Dm(e,t){for(let n of e)t(n),Dm(Lc(n),t)}function Om(e,t=e=>e.treeLeaf!==!0){let n=[];return Dm(e,e=>{t(e)&&n.push(e.id)}),n}function km(e,t){let n;return Dm(e,e=>{e.id===t&&(n=e)}),n}function Am(e,t){return t===0?!1:t===-1||e<t}function jm(e){let t=new Set;return Dm(e,e=>t.add(e.id)),t}var Mm=class{deps;expandedRowIds=new Set;constructor(e){this.deps=e}get active(){let e=this.deps.getOptions();return un(e.tree,e.getDataPath)}getExpandedRowIds(){return this.expandedRowIds}isExpanded(e){return this.expandedRowIds.has(e)}expandNode(e,t){if(!this.active||this.expandedRowIds.has(e))return;let n=km(this.deps.getTreeTreeRoots(),e);!n||!this.isNodeExpandable(n)||(this.expandedRowIds.add(e),this.emitNodeOpened(n,!0,t),this.deps.onTreeStateChanged?.())}collapseNode(e,t){if(!this.active||!this.expandedRowIds.has(e))return;this.deps.getLazyLoadHost?.()?.abortLoad(e);let n=km(this.deps.getTreeTreeRoots(),e);this.expandedRowIds.delete(e),n&&this.emitNodeOpened(n,!1,t),this.deps.onTreeStateChanged?.()}toggleNode(e,t){if(this.isExpanded(e)){this.collapseNode(e,t);return}this.expandNode(e,t)}async requestToggleNode(e,t){if(!this.active)return;if(this.isExpanded(e)){this.collapseNode(e,t);return}let n=km(this.deps.getTreeTreeRoots(),e);if(!n||!this.isNodeExpandable(n))return;let r=this.deps.getLazyLoadHost?.();if(r?.ensureChildrenLoaded){if(!await r.ensureChildrenLoaded(n,t))return;let i=km(this.deps.getTreeTreeRoots(),e)??n;if(!this.isNodeExpandable(i))return}this.expandNode(e,t)}isNodeExpandable(e){let t=this.deps.getLazyLoadHost?.();return t?t.isExpandable(e):e.treeLeaf!==!0}isNodeLoading(e){return this.deps.getLazyLoadHost?.()?.isLoading(e)??!1}expandAll(e){if(this.active)for(let t of Om(this.deps.getTreeTreeRoots(),e=>this.isNodeExpandable(e)))this.expandedRowIds.has(t)||this.expandNode(t,e)}collapseAll(){if(this.active)for(let e of[...this.expandedRowIds])this.collapseNode(e,`api`)}clearExpanded(){this.expandedRowIds.clear()}pruneExpanded(e){for(let t of[...this.expandedRowIds])e.has(t)||this.expandedRowIds.delete(t)}applyDefaultExpanded(e){if(!this.active)return;let t=this.deps.getGroupDefaultExpanded();t!==0&&Dm(e,e=>{let n=e.treeLevel??0;e.treeLeaf!==!0&&Am(n,t)&&this.expandedRowIds.add(e.id)})}getDataPathForRow(e){let t=km(this.deps.getTreeTreeRoots(),e);return t?.dataPath?[...t.dataPath]:void 0}getMapStageOptions(){let e=this.deps.getOptions();return{expandedRowIds:this.expandedRowIds,treeValueGetter:e.treeValueGetter}}getTreeDisplayValue(e){let t=this.deps.getOptions(),n=e.dataPath??[];return t.treeValueGetter?t.treeValueGetter({data:e.data,dataPath:n,treeLevel:e.treeLevel??0}):n[n.length-1]??``}prepareTreeTree(e){let t=jm(e);this.pruneExpanded(t),this.deps.getLazyLoadHost?.()?.pruneLoaded(t)}applyDefaultExpandedToTree(e){this.applyDefaultExpanded(e)}emitNodeOpened(e,t,n){this.deps.onNodeOpened?.(pn(e.id,t,e.treeLevel??0,e.dataPath??[],n))}},Nm=class{deps;loadedParentIds=new Set;emptyLeafParentIds=new Set;loadingParentIds=new Set;inflight=new Map;constructor(e){this.deps=e}get active(){let e=this.deps.getOptions();return e.treeLazyLoad===!0&&typeof e.loadTreeChildren==`function`}isLoading(e){return this.loadingParentIds.has(e)}isLoadedEmptyLeaf(e){return this.emptyLeafParentIds.has(e)}isLoadedParent(e){return this.loadedParentIds.has(e)}resolveExpandable(e){let t=e.childrenAfterTree;if(t&&t.length>0)return!0;if(this.emptyLeafParentIds.has(e.id))return!1;let n=this.deps.getOptions().hasTreeChildren;return n?n({data:e.data,dataPath:e.dataPath??[],treeLevel:e.treeLevel??0}):e.treeLeaf!==!0}isExpandable(e){return this.resolveExpandable(e)}needsLazyLoad(e){return!this.active||this.loadedParentIds.has(e.id)||this.emptyLeafParentIds.has(e.id)||e.childrenAfterTree&&e.childrenAfterTree.length>0?!1:this.resolveExpandable(e)}abortLoad(e){let t=this.inflight.get(e);t&&(t.controller.abort(),this.inflight.delete(e)),this.loadingParentIds.delete(e)}reset(){for(let e of this.inflight.values())e.controller.abort();this.inflight.clear(),this.loadedParentIds.clear(),this.emptyLeafParentIds.clear(),this.loadingParentIds.clear()}prune(e){for(let t of[...this.loadedParentIds])e.has(t)||this.loadedParentIds.delete(t);for(let t of[...this.emptyLeafParentIds])e.has(t)||this.emptyLeafParentIds.delete(t);for(let t of[...this.inflight.keys()])e.has(t)||this.abortLoad(t)}pruneLoaded(e){this.prune(e)}ensureChildrenLoaded(e,t=`ui`){if(!this.needsLazyLoad(e))return Promise.resolve(!0);let n=this.inflight.get(e.id);if(n)return n.promise;let r=new AbortController,i=this.runLoad(e,t,r);return this.inflight.set(e.id,{controller:r,promise:i}),i.finally(()=>{this.inflight.delete(e.id)})}async runLoad(e,t,n){let r=this.deps.getOptions().loadTreeChildren;if(!r)return!1;let i=e.id,a=e.dataPath??[],o=e.treeLevel??0;this.loadingParentIds.add(i),this.deps.onStateChanged?.(),this.deps.onLoading?.({parentRowId:i,dataPath:[...a],treeLevel:o,source:t});try{let s=await r({parentRowId:i,parentData:e.data,dataPath:[...a],treeLevel:o,signal:n.signal});if(n.signal.aborted)return!1;let c=Pm(s);return c.length===0?(this.emptyLeafParentIds.add(i),this.deps.onLoaded?.({parentRowId:i,children:[],childCount:0,source:t}),!0):(Fm({parentPath:a,children:c,rowKey:this.deps.rowKey,getDataPath:this.deps.getDataPath(),existingRowKeys:this.deps.getExistingRowKeys()}),this.deps.applyTransaction({add:c}),this.loadedParentIds.add(i),this.deps.onLoaded?.({parentRowId:i,children:c,childCount:c.length,source:t}),!0)}catch(e){if(n.signal.aborted)return!1;let t=e instanceof Error?e.message:String(e);return this.deps.onLoadFailed?.({parentRowId:i,reason:t,aborted:!1}),!1}finally{this.loadingParentIds.delete(i),this.deps.onStateChanged?.()}}};function Pm(e){return e?[...e]:[]}function Fm(e){let t=new Set(e.existingRowKeys);for(let n of e.children){let r=e.getDataPath({data:n});if(!Im(e.parentPath,r))throw Error(`[magic-grid] loadTreeChildren: child path [${r.join(`/`)}] must extend parent [${e.parentPath.join(`/`)}]`);let i=n[e.rowKey];if(i==null||i===``)throw Error(`[magic-grid] loadTreeChildren: child row is missing rowKey value.`);let a=String(i);if(t.has(a))throw Error(`[magic-grid] loadTreeChildren: duplicate rowKey "${a}".`);t.add(a)}}function Im(e,t){if(t.length!==e.length+1)return!1;for(let n=0;n<e.length;n++)if(t[n]!==e[n])return!1;return!0}var Lm=!1;function Rm(e){let t=e.tree===!0,n=e.rowGrouping===!0;return t?(n&&!Lm&&(Lm=!0,console.warn(`[magic-grid] tree and rowGrouping are mutually exclusive; rowGrouping ignored.`)),{mode:`tree`,rowGroupingIgnored:n}):n?{mode:`group`,rowGroupingIgnored:!1}:{mode:`flat`,rowGroupingIgnored:!1}}function zm(e){return{sourceRows:e.sourceRows,displayRows:e.displayRows,hasSortOrFilter:e.sortModelLength>0||e.filterModelKeyCount>0}}function Bm(e,t,n){if(e===void 0)return;if(t===`source`||!n.hasSortOrFilter)return Jd(e,n.sourceRows.length);if(n.displayRows.length===0)return 0;let r=Jd(e,n.displayRows.length),i=n.displayRows[r];if(!i)return n.sourceRows.length;let a=n.sourceRows.findIndex(e=>e.id===i.id);return a<0?n.sourceRows.length:a}function Vm(e,t,n){let r=t===`display`||n.hasSortOrFilter?n.displayRows:n.sourceRows,i=[];for(let t of e){if(r.length===0)continue;let e=r[Jd(t,r.length)];e&&i.push(e.id)}return i}function Hm(e,t){return t<=0?0:Math.max(0,Math.min(e,t-1))}function Um(e,t,n,r){if(t===`display`&&r)return null;if(t===`source`||!n.hasSortOrFilter)return Hm(e,n.sourceRows.length);let i=Hm(e,n.displayRows.length),a=n.displayRows[i];if(!a)return Hm(n.sourceRows.length-1,n.sourceRows.length);let o=n.sourceRows.findIndex(e=>e.id===a.id);return o<0?Hm(n.sourceRows.length-1,n.sourceRows.length):o}function Wm(e,t){let n=null;for(let r of t){let t=e.find(e=>e.id===r);if(!t||!H(t))return`missing`;let i=t.parentRowId??null;if(n==null){n=i;continue}if(n!==i)return`mixed`}return n}function Gm(e,t,n,r){let i=0,a=Math.max(0,Math.min(t,e.length));for(let t=0;t<a;t+=1){let a=e[t];H(a)&&(a.parentRowId??null)===n&&!r.has(a.id)&&(i+=1)}return i}function Km(e,t){let n=e.findIndex(e=>e.id===t);if(n<0)return null;let r=e[n];if(!H(r))return null;let i=r.parentRowId??null,a=0;for(let t=0;t<n;t+=1)(e[t].parentRowId??null)===i&&(a+=1);return{parentRowId:i,siblingIndex:a,treeLevel:r.treeLevel??Math.max(0,(r.dataPath?.length??1)-1)}}function qm(e,t,n,r){let i=new Set(t),a=0,o=Hm(n,e.length);for(let t=0;t<o;t+=1){let n=e[t];H(n)&&(n.parentRowId??null)===r&&!i.has(n.id)&&(a+=1)}return a}function Jm(e){if(!e.active)return{allowed:!0};let t=Wm(e.sourceRows,e.rowIds);return t===`mixed`?{allowed:!1,reason:`selected rows must belong to the same tree parent`}:t===`missing`?{allowed:!1,reason:`cannot move non-tree rows while tree mode is active`}:t!=null&&!Ym(e.sourceRows,e.rowIds,e.targetSourceIndex,t)?{allowed:!1,reason:`tree drag target must stay within the same parent siblings`}:{allowed:!0,parentRowId:t}}function Ym(e,t,n,r){let i=new Set(t),a=e.filter(e=>H(e)&&(e.parentRowId??null)===r).length,o=qm(e,t,n,r),s=a-i.size;return o>=0&&o<=s}function Xm(e,t,n,r,i){for(let e of n){let n=t(e);if(!n||!H(n)||(n.parentRowId??null)!==i)return!1}let a=[];for(let t=0;t<e.length;t+=1){let n=e[t];H(n)&&(n.parentRowId??null)===i&&a.push(t)}if(a.length===0)return!1;let o=Math.min(...a),s=Math.max(...a)+1,c=Math.max(0,Math.min(r,e.length));return c>=o&&c<=s}function Zm(e){let t=new Set(e.rowIds),n=[],r=[];for(let t=0;t<e.sourceRows.length;t+=1){let i=e.sourceRows[t];!H(i)||(i.parentRowId??null)!==e.parentRowId||(n.push(t),r.push(i))}let i=e.rowIds.map(e=>r.find(t=>t.id===e)).filter(e=>e!=null);if(i.length!==e.rowIds.length)return null;let a=r.filter(e=>!t.has(e.id)),o=Math.max(0,Math.min(e.withinSiblingInsertIndex,a.length)),s=[...a.slice(0,o),...i,...a.slice(o)];if(s.every((e,t)=>e.id===r[t].id))return null;let c=[...e.sourceRows];for(let e=0;e<n.length;e+=1)c[n[e]]=s[e];let l=[];for(let t of i){let n=e.sourceRows.findIndex(e=>e.id===t.id),r=c.findIndex(e=>e.id===t.id);n>=0&&r>=0&&n!==r&&l.push({rowId:t.id,fromIndex:n,toIndex:r})}return l.length===0?null:{rows:c,moves:l}}function Qm(e){let t=new Set(e.rowIds);if(!Xm(e.displayRows,t=>e.sourceRows.find(e=>e.id===t),e.rowIds,e.displayInsertIndex,e.parentRowId))return null;let n=Gm(e.displayRows,e.displayInsertIndex,e.parentRowId,t);return Zm({sourceRows:e.sourceRows,rowIds:e.rowIds,withinSiblingInsertIndex:n,parentRowId:e.parentRowId})}var $m=1.5;function eh(e,t,n,r){return e<t+40?-Math.min(1,(t+40-e)/40)*r*$m:e>n-40?Math.min(1,(e-(n-40))/40)*r*$m:0}function th(e,t,n,r,i){let a=nh(e,n,r);if(a)return a;let o=t.getBoundingClientRect(),s=i()+(r-o.top),c=e.getRowIndexAtPixel(s),l=e.getRow(c);return l?{rowId:l.id,rowIndex:c}:null}function nh(e,t,n){let r=document.elementFromPoint(t,n)?.closest(`.mg-row`);if(!r)return null;let i=r.dataset.rowId;if(!i)return null;let a=e.getRowIndexById(i);return a<0?null:{rowId:i,rowIndex:a}}function rh(e,t,n){return eh(e,t,n,1)!==0}function ih(e,t){return e.dataPath??t({data:e.data})}function ah(e,t){if(t.length<e.length)return!1;for(let n=0;n<e.length;n+=1)if(t[n]!==e[n])return!1;return!0}function oh(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function sh(e,t,n){let r=e;for(;r;){if(r.id===t)return!0;let e=r.parentRowId;if(e==null)return!1;r=n(e)}return!1}function ch(e,t,n){let r=[];for(let i of n){let n=e.find(e=>e.id===i);n&&r.push(ih(n,t))}if(r.length===0)return[];let i=[],a=new Set;for(let n of e){let e=ih(n,t);r.some(t=>oh(e,t)||ah(t,e))&&!a.has(n.id)&&(a.add(n.id),i.push(n.id))}return i}function lh(e){let t=th(e.rowModel,e.viewportEl,e.clientX,e.clientY,e.getLogicalScrollTop);if(!t||new Set(e.movingRowIds??[]).has(t.rowId))return null;let n=e.rowModel.getRowById(t.rowId);if(!n||!H(n))return null;if(e.altKey)return t.rowId;let r=e.viewportEl.querySelector(`.mg-row[data-row-id="${CSS.escape(t.rowId)}"]`)?.querySelector(`.mg-cell[data-col-id="${en}"], .mg-cell--tree-auto`);if(!r)return null;let i=n.treeLevel??0,a=r.getBoundingClientRect().left+(i+1)*16;return e.clientX>=a?t.rowId:null}function uh(e,t,n,r={}){let i=r.nestUnderRowId??null;if(i){if(n.has(i))return null;let r=e.find(e=>e.id===i);return!r||!H(r)?null:{newParentRowId:i,withinSiblingInsertIndex:Gm(e,Math.max(0,Math.min(t,e.length)),i,n)}}let a=Math.max(0,Math.min(t,e.length)),o=a<e.length?e[a]:void 0,s=a>0?e[a-1]:void 0;if(!o&&!s)return{newParentRowId:null,withinSiblingInsertIndex:0};let c=o??s;if(!c||!H(c))return null;let l=o?o.parentRowId??null:s.parentRowId??null;return{newParentRowId:l,withinSiblingInsertIndex:Gm(e,a,l,n)}}function dh(e,t,n,r,i,a,o={}){for(let e of r){let t=n(e);if(!t||!H(t))return!1}let s=uh(t,i,new Set(ch(e,a,r)),o);if(!s)return!1;if(s.newParentRowId){let e=n(s.newParentRowId);if(!e||!H(e))return!1;for(let t of r)if(s.newParentRowId===t||sh(e,t,n))return!1}return!0}function fh(e){let t=new Set(ch(e.sourceRows,e.getDataPath,e.rowIds));if(e.treeDragScope===`hierarchy`){let n=uh(e.displayRows,e.insertIndex,t,{nestUnderRowId:e.nestUnderRowId});if(!n)return null;let r=n.newParentRowId==null?void 0:e.sourceRows.find(e=>e.id===n.newParentRowId);return{parentRowId:n.newParentRowId,siblingIndex:n.withinSiblingInsertIndex,treeLevel:n.newParentRowId==null?0:(r?.treeLevel??0)+1}}let n=Wm(e.sourceRows,e.rowIds);if(n===`mixed`||n===`missing`)return null;let r=n==null?void 0:e.sourceRows.find(e=>e.id===n);return{parentRowId:n,siblingIndex:Gm(e.displayRows,e.insertIndex,n,t),treeLevel:n==null?0:(r?.treeLevel??0)+1}}function ph(e,t,n){let r=ih(e[t],n),i=t;for(let a=t+1;a<e.length;a+=1){let t=ih(e[a],n);if(ah(r,t)&&!oh(r,t)){i=a;continue}break}return i}function mh(e,t,n,r){let i=[];for(let n=0;n<e.length;n+=1)(e[n].parentRowId??null)===t&&i.push(n);if(i.length===0){if(t==null)return 0;let n=e.findIndex(e=>e.id===t);return n<0?e.length:ph(e,n,r)+1}if(n>=i.length){let t=i[i.length-1];return ph(e,t,r)+1}return i[n]}function hh(e,t,n){for(let r of e)if(oh(ih(r,n),t))return r.id}function gh(e){return e.map(e=>({...e,data:{...e.data},dataPath:e.dataPath?[...e.dataPath]:void 0,childrenAfterTree:e.childrenAfterTree?[...e.childrenAfterTree]:void 0}))}function _h(e){if(!dh(e.sourceRows,e.displayRows,t=>e.sourceRows.find(e=>e.id===t),e.rowIds,e.displayInsertIndex,e.getDataPath,{nestUnderRowId:e.nestUnderRowId}))return null;let t=ch(e.sourceRows,e.getDataPath,e.rowIds),n=new Set(t),r=Wm(e.sourceRows,e.rowIds),i=uh(e.displayRows,e.displayInsertIndex,n,{nestUnderRowId:e.nestUnderRowId});if(!i||r===`mixed`||r===`missing`)return null;if((i.newParentRowId??null)===r&&t.length===e.rowIds.length)return Qm({sourceRows:e.sourceRows,displayRows:e.displayRows,rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,parentRowId:r});let a=gh(e.sourceRows),o=e=>a.find(t=>t.id===e),s=t=>ih(t,e.getDataPath),c=new Map;for(let t of e.rowIds){let e=o(t);if(!e)return null;let n=s(e),r=e.parentRowId==null?[]:s(o(e.parentRowId)),a=n.slice(r.length),l=i.newParentRowId==null?[]:s(o(i.newParentRowId));c.set(t,[...l,...a])}let l=[...t].sort((e,t)=>{let n=o(e),r=o(t);return s(n).length-s(r).length});for(let t of l){let n=o(t);if(!n)return null;let r=s(n),i=e.rowIds.find(e=>{let t=o(e);if(!t)return!1;let n=s(t);return oh(r,n)||ah(n,r)});if(!i)return null;let l=s(o(i)),u=c.get(i);if(!u)return null;let d=[...u,...r.slice(l.length)];e.setDataPath({data:n.data,dataPath:d,treeLevel:d.length-1,previousPath:[...r]}),n.dataPath=d,n.treeLevel=d.length-1,n.parentRowId=d.length>1?hh(a,d.slice(0,-1),e.getDataPath):void 0}let u=a.filter(e=>n.has(e.id)),d=a.filter(e=>!n.has(e.id)),f=mh(d,i.newParentRowId,i.withinSiblingInsertIndex,e.getDataPath),p=[...d.slice(0,f),...u,...d.slice(f)],m=[];for(let t of u){let n=e.sourceRows.findIndex(e=>e.id===t.id),r=p.findIndex(e=>e.id===t.id);n>=0&&r>=0&&n!==r&&m.push({rowId:t.id,fromIndex:n,toIndex:r})}let h=u.some(t=>{let n=e.sourceRows.find(e=>e.id===t.id);if(!n)return!1;let r=ih(n,e.getDataPath),i=s(t);return n.parentRowId!==t.parentRowId||!oh(r,i)});return m.length===0&&!h?null:{rows:p,moves:m}}function vh(e,t){let n=null;for(let r of t){let t=e.find(e=>e.id===r);if(!t||Xt(t))return`missing`;let i=t.leafGroupPathKey??null;if(!i)return null;if(n==null){n=i;continue}if(n!==i)return`mixed`}return n}function yh(e,t,n,r){let i=0,a=Math.max(0,Math.min(t,e.length));for(let t=0;t<a;t+=1){let a=e[t];Zt(a)&&a.leafGroupPathKey===n&&!r.has(a.id)&&(i+=1)}return i}function bh(e,t,n,r){let i=new Set(t),a=0,o=Hm(n,e.length);for(let t=0;t<o;t+=1){let n=e[t];n.leafGroupPathKey===r&&!i.has(n.id)&&(a+=1)}if(t.length===1){let n=e.findIndex(e=>e.id===t[0]);n>=0&&n<o&&--a}return Math.max(0,a)}function xh(e){let{sourceRows:t,rowIds:n,groupPath:r,withinGroupInsertIndex:i}=e,a=new Set(n);if(vh(t,n)!==r)return null;let o=[],s=[];for(let e=0;e<t.length;e+=1){let n=t[e];n.leafGroupPathKey===r&&(o.push(e),s.push(n))}let c=s.filter(e=>a.has(e.id));if(c.length!==n.length)return null;let l=s.filter(e=>!a.has(e.id)),u=Math.max(0,Math.min(i,l.length)),d=[...l.slice(0,u),...c,...l.slice(u)];if(d.every((e,t)=>e.id===s[t].id))return null;let f=[...t];for(let e=0;e<o.length;e+=1)f[o[e]]=d[e];let p=[];for(let e of c){let n=t.findIndex(t=>t.id===e.id),r=f.findIndex(t=>t.id===e.id);n>=0&&r>=0&&n!==r&&p.push({rowId:e.id,fromIndex:n,toIndex:r})}return p.length===0?null:{rows:f,moves:p}}function Sh(e){let{sourceRows:t,displayRows:n,rowIds:r,displayInsertIndex:i,groupPath:a}=e,o=new Set(r);return wh(n,e=>t.find(t=>t.id===e),r,i,a)?xh({sourceRows:t,rowIds:r,groupPath:a,withinGroupInsertIndex:yh(n,i,a,o)}):null}function Ch(e,t,n,r){let i=new Set(t),a=e.filter(e=>e.leafGroupPathKey===r).length,o=bh(e,t,n,r),s=a-i.size;return o>=0&&o<=s}function wh(e,t,n,r,i){let a=[];for(let n=0;n<e.length;n+=1){let r=e[n];Zt(r)&&(t(r.id)??r).leafGroupPathKey===i&&a.push(n)}if(a.length===0)return!1;let o=Math.min(...a),s=Math.max(...a)+1;return r>=o&&r<=s}function Th(e){if(!e.active)return{allowed:!0};let t=vh(e.sourceRows,e.rowIds);return t===null?{allowed:!0}:t===`missing`?{allowed:!1,reason:`cannot move non-leaf rows while row grouping is active`}:t===`mixed`?{allowed:!1,reason:`selected rows must belong to the same group`}:Ch(e.sourceRows,e.rowIds,e.targetSourceIndex,t)?{allowed:!0}:{allowed:!1,reason:`cannot move rows across groups`}}function Eh(e,t,n){let r=new Set(n);return r.size<=1||!r.has(t)?[t]:e.filter(e=>r.has(e.id)).map(e=>e.id)}function Dh(e,t,n,r){let i=t.indexOf(n);if(i<0)return Math.max(0,Math.min(r,e-1));let a=r-i,o=Math.max(0,e-t.length);return Math.max(0,Math.min(a,o))}function Oh(e,t,n){return{displayIndex:n,...Km(e,t)??{}}}function kh(e,t,n,r,i){for(let a of t.moves)e(J(a.rowId,a.fromIndex,a.toIndex,r,i,Oh(t.rows,a.rowId,n)))}function Ah(e,t,n){let r=e.findIndex(e=>e.id===t);if(r<0)return null;let i=Hm(n,e.length);if(r===i)return null;let a=[...e],[o]=a.splice(r,1);return a.splice(i,0,o),{rows:a,fromIndex:r,toIndex:i}}function jh(e,t,n){let r=new Set(t),i=e.filter(e=>r.has(e.id));if(i.length===0||i.length!==t.length)return null;let a=new Map;for(let t=0;t<e.length;t++){let n=e[t];r.has(n.id)&&a.set(n.id,t)}let o=e.filter(e=>!r.has(e.id)),s=Math.max(0,Math.min(n,o.length)),c=[...o.slice(0,s),...i,...o.slice(s)],l=[];for(let e of i){let t=a.get(e.id),n=c.findIndex(t=>t.id===e.id);t==null||n<0||t===n||l.push({rowId:e.id,fromIndex:t,toIndex:n})}return l.length===0?null:{rows:c,moves:l}}var Mh=class{deps;constructor(e){this.deps=e}moveRow(e,t=`api`){let n=e.indexMode??`source`,r=zm({sourceRows:this.deps.getSourceRows(),displayRows:this.deps.getDisplayRows(),sortModelLength:this.deps.getSortModelLength(),filterModelKeyCount:this.deps.getFilterModelKeyCount()}),i=this.deps.getSortModelLength()>0,a=Um(e.toIndex,n,r,i);if(a==null)return{moved:!1,reason:`display index mode is not allowed while sort is active`};let o=this.deps.getSourceRows(),s=o.findIndex(t=>t.id===e.rowId);if(s<0)return{moved:!1,reason:`row "${e.rowId}" not found`};let c=Th({active:this.deps.isRowGroupingActive?.()??!1,sourceRows:o,rowIds:[e.rowId],targetSourceIndex:a});if(!c.allowed)return{moved:!1,fromIndex:s,reason:c.reason};let l=Jm({active:this.deps.isTreeActive?.()??!1,sourceRows:o,rowIds:[e.rowId],targetSourceIndex:a});if(!l.allowed)return{moved:!1,fromIndex:s,reason:l.reason};let u=vh(o,[e.rowId]);if(typeof u==`string`&&(this.deps.isRowGroupingActive?.()??!1)){if(n===`display`)return this.finishGroupedDisplayMove(o,[e.rowId],e.rowId,e.toIndex,u,t,e.finished??!0,s);let r=bh(o,[e.rowId],a,u),i=xh({sourceRows:o,rowIds:[e.rowId],groupPath:u,withinGroupInsertIndex:r});if(!i)return{moved:!1,fromIndex:s,toIndex:s};this.deps.setSourceRows(i.rows);let c=i.moves[0];return this.deps.emitRowMoved(J(e.rowId,c?.fromIndex??s,c?.toIndex??s,t,e.finished??!0)),{moved:!0,fromIndex:c?.fromIndex??s,toIndex:c?.toIndex??s}}let d=Wm(o,[e.rowId]);if((typeof d==`string`||d===null)&&this.deps.isTreeActive?.()){if(n===`display`)return this.finishTreeDisplayMove(o,[e.rowId],e.rowId,e.toIndex,d,t,e.finished??!0,s);let r=qm(o,[e.rowId],a,d),i=Zm({sourceRows:o,rowIds:[e.rowId],withinSiblingInsertIndex:r,parentRowId:d});if(!i)return{moved:!1,fromIndex:s,toIndex:s};this.deps.setSourceRows(i.rows);let c=i.moves[0];return this.deps.emitRowMoved(J(e.rowId,c?.fromIndex??s,c?.toIndex??s,t,e.finished??!0)),{moved:!0,fromIndex:c?.fromIndex??s,toIndex:c?.toIndex??s}}let f=Ah(o,e.rowId,a);return f?(this.deps.setSourceRows(f.rows),this.deps.emitRowMoved(J(e.rowId,f.fromIndex,f.toIndex,t,e.finished??!0)),{moved:!0,fromIndex:f.fromIndex,toIndex:f.toIndex}):{moved:!1,fromIndex:s,toIndex:s}}moveRows(e,t=`api`){if(e.rowIds.length===0)return{moved:!1,reason:`no rows to move`};if((this.deps.isRowGroupingActive?.()??!1)&&e.displayInsertIndex!=null)return this.moveRowsByGroupedDisplayInsert(e,t);if((this.deps.isTreeActive?.()??!1)&&e.displayInsertIndex!=null)return this.moveRowsByTreeDisplayInsert(e,t);if(e.rowIds.length===1)return this.moveRow({rowId:e.rowIds[0],toIndex:e.toIndex,indexMode:e.indexMode,finished:e.finished},t);let n=e.indexMode??`source`,r=zm({sourceRows:this.deps.getSourceRows(),displayRows:this.deps.getDisplayRows(),sortModelLength:this.deps.getSortModelLength(),filterModelKeyCount:this.deps.getFilterModelKeyCount()}),i=this.deps.getSortModelLength()>0,a=Um(e.toIndex,n,r,i);if(a==null)return{moved:!1,reason:`display index mode is not allowed while sort is active`};let o=this.deps.getSourceRows(),s=Dh(o.length,e.rowIds,e.leaderRowId,a),c=Th({active:this.deps.isRowGroupingActive?.()??!1,sourceRows:o,rowIds:e.rowIds,targetSourceIndex:s});if(!c.allowed)return{moved:!1,reason:c.reason};let l=Jm({active:this.deps.isTreeActive?.()??!1,sourceRows:o,rowIds:e.rowIds,targetSourceIndex:s});if(!l.allowed)return{moved:!1,reason:l.reason};let u=Wm(o,e.rowIds);if((typeof u==`string`||u===null)&&(this.deps.isTreeActive?.()??!1)){let n=qm(o,e.rowIds,s,u),r=Zm({sourceRows:o,rowIds:e.rowIds,withinSiblingInsertIndex:n,parentRowId:u});if(!r)return{moved:!1,moves:[]};this.deps.setSourceRows(r.rows);let i=e.finished??!0;for(let e of r.moves)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,t,i));let a=r.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:a?.fromIndex,toIndex:a?.toIndex,moves:r.moves}}let d=jh(o,e.rowIds,s);if(!d)return{moved:!1,moves:[]};this.deps.setSourceRows(d.rows);let f=e.finished??!0;for(let e of d.moves)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,t,f));let p=d.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:p?.fromIndex,toIndex:p?.toIndex,moves:d.moves}}moveRowsByGroupedDisplayInsert(e,t){let n=this.deps.getSourceRows(),r=vh(n,e.rowIds);if(r===`mixed`)return{moved:!1,reason:`selected rows must belong to the same group`};if(r===`missing`)return{moved:!1,reason:`cannot move non-leaf rows while row grouping is active`};if(r===null)return{moved:!1,reason:`group path missing on source rows`};let i=Sh({sourceRows:n,displayRows:this.deps.getDisplayRows(),rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,groupPath:r});if(!i)return{moved:!1,moves:[]};this.deps.setSourceRows(i.rows);let a=e.finished??!0;for(let e of i.moves)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,t,a));let o=i.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:o?.fromIndex,toIndex:o?.toIndex,moves:i.moves}}finishGroupedDisplayMove(e,t,n,r,i,a,o,s){let c=this.deps.getDisplayRows(),l=c.findIndex(e=>e.id===n),u=Hm(r,c.length),d=Sh({sourceRows:e,displayRows:c,rowIds:t,displayInsertIndex:l>=0&&l<u?u+1:u,groupPath:i});if(!d)return{moved:!1,fromIndex:s,toIndex:s};this.deps.setSourceRows(d.rows);let f=d.moves;for(let e of f)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,a,o));let p=f.find(e=>e.rowId===n);return{moved:!0,fromIndex:p?.fromIndex??s,toIndex:p?.toIndex??s,moves:f}}moveRowsByTreeDisplayInsert(e,t){let n=this.deps.getSourceRows(),r=Wm(n,e.rowIds);if(r===`mixed`)return{moved:!1,reason:`selected rows must belong to the same tree parent`};if(r===`missing`)return{moved:!1,reason:`cannot move non-tree rows while tree mode is active`};if(this.deps.getTreeDragScope?.()===`hierarchy`){let r=this.deps.getDataPath?.(),i=this.deps.setDataPath?.();if(!r||!i)return{moved:!1,reason:`hierarchy tree drag requires getDataPath and setDataPath`};let a=_h({sourceRows:n,displayRows:this.deps.getDisplayRows(),rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,getDataPath:r,setDataPath:i,nestUnderRowId:e.treeNestUnderRowId});if(!a)return{moved:!1,moves:[]};this.deps.setSourceRows(a.rows);let o=e.finished??!0;kh(this.deps.emitRowMoved,a,e.displayInsertIndex,t,o);let s=a.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:s?.fromIndex,toIndex:s?.toIndex,moves:a.moves}}let i=Qm({sourceRows:n,displayRows:this.deps.getDisplayRows(),rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,parentRowId:r});if(!i)return{moved:!1,moves:[]};this.deps.setSourceRows(i.rows);let a=e.finished??!0;kh(this.deps.emitRowMoved,i,e.displayInsertIndex,t,a);let o=i.moves.find(t=>t.rowId===e.leaderRowId);return{moved:!0,fromIndex:o?.fromIndex,toIndex:o?.toIndex,moves:i.moves}}finishTreeDisplayMove(e,t,n,r,i,a,o,s){let c=this.deps.getDisplayRows(),l=c.findIndex(e=>e.id===n),u=Hm(r,c.length),d=Qm({sourceRows:e,displayRows:c,rowIds:t,displayInsertIndex:l>=0&&l<u?u+1:u,parentRowId:i});if(!d)return{moved:!1,fromIndex:s,toIndex:s};this.deps.setSourceRows(d.rows);let f=d.moves;for(let e of f)this.deps.emitRowMoved(J(e.rowId,e.fromIndex,e.toIndex,a,o));let p=f.find(e=>e.rowId===n);return{moved:!0,fromIndex:p?.fromIndex??s,toIndex:p?.toIndex??s,moves:f}}};function Nh(e,t,n,r,i){let a=th(e,t,n,r,i);return a?Ph(a,r,t,e,i):-1}function Ph(e,t,n,r,i){let a=r.getRowCount(),o=Ih(e,n,r,i),s=e.rowIndex;return o!=null&&t>o&&(s+=1),Math.max(0,Math.min(s,a))}function Fh(e,t){return t<=0?0:Math.max(0,Math.min(e,t-1))}function Ih(e,t,n,r){let i=t.querySelector(`.mg-row[data-row-id="${CSS.escape(e.rowId)}"]`);if(i){let e=i.getBoundingClientRect();return e.top+e.height/2}let a=n.getRowBounds(e.rowIndex);return a?t.getBoundingClientRect().top+a.rowTop+a.rowHeight/2-r():null}function Lh(e,t,n){return{displayIndex:n,...Km(e,t)??{}}}function Rh(e,t,n){if(t.moves.length===0)return{ok:!1,reason:`no row order change`};let r=n??e.leaderRowId;return{ok:!0,plan:{rowIds:[...e.rowIds],leaderRowId:e.leaderRowId,rows:t.rows,moves:t.moves,displayIndex:e.displayInsertIndex,treeDrop:e.isTreeActive?Lh(t.rows,r,e.displayInsertIndex):{displayIndex:e.displayInsertIndex}}}}function zh(e){let t=vh(e.sourceRows,e.rowIds);if(t===`mixed`)return{ok:!1,reason:`selected rows must belong to the same group`};if(t===`missing`)return{ok:!1,reason:`cannot move non-leaf rows while row grouping is active`};if(t===null)return{ok:!1,reason:`group path missing on source rows`};let n=Sh({sourceRows:e.sourceRows,displayRows:e.displayRows,rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,groupPath:t});return n?Rh(e,n):{ok:!1,reason:`invalid grouped display drop`}}function Bh(e){let t=Wm(e.sourceRows,e.rowIds);if(t===`mixed`)return{ok:!1,reason:`selected rows must belong to the same tree parent`};if(t===`missing`)return{ok:!1,reason:`cannot move non-tree rows while tree mode is active`};if(e.treeDragScope===`hierarchy`){let t=e.getDataPath,n=e.setDataPath;if(!t||!n)return{ok:!1,reason:`hierarchy tree drag requires getDataPath and setDataPath`};let r=_h({sourceRows:e.sourceRows,displayRows:e.displayRows,rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,getDataPath:t,setDataPath:n,nestUnderRowId:e.treeNestUnderRowId});return r?Rh(e,r):{ok:!1,reason:`invalid tree hierarchy display drop`}}let n=Qm({sourceRows:e.sourceRows,displayRows:e.displayRows,rowIds:e.rowIds,displayInsertIndex:e.displayInsertIndex,parentRowId:t});return n?Rh(e,n):{ok:!1,reason:`invalid tree sibling display drop`}}function Vh(e){let t=e.displayRows.length,n=Fh(e.displayInsertIndex,t),r=e.displayRows.findIndex(t=>t.id===e.leaderRowId);if(r>=0&&n===r)return{ok:!1,reason:`no row order change`};let i=e.sortModelLength>0,a=zm({sourceRows:e.sourceRows,displayRows:e.displayRows,sortModelLength:e.sortModelLength,filterModelKeyCount:e.filterModelKeyCount}),o=Um(n,a.hasSortOrFilter&&!i?`display`:`source`,a,i);if(o==null)return{ok:!1,reason:`display index mode is not allowed while sort is active`};if(e.rowIds.length===1){let t=Ah(e.sourceRows,e.rowIds[0],o);return t?Rh(e,{rows:t.rows,moves:[{rowId:e.rowIds[0],fromIndex:t.fromIndex,toIndex:t.toIndex}]}):{ok:!1,reason:`no row order change`}}let s=Dh(e.sourceRows.length,e.rowIds,e.leaderRowId,o),c=jh(e.sourceRows,e.rowIds,s);return c?Rh(e,c):{ok:!1,reason:`no row order change`}}function Hh(e){return e.rowIds.length===0?{ok:!1,reason:`no rows to move`}:e.displayInsertIndex<0?{ok:!1,reason:`invalid display insert index`}:e.isRowGroupingActive?zh(e):e.isTreeActive?Bh(e):Vh(e)}function Uh(e){return e===void 0||e===!0?{ok:!0}:e===!1?{ok:!1}:typeof e==`object`&&e.ok===!1?{ok:!1,reason:e.reason}:{ok:!0}}var Wh=class{deps;phase=`idle`;nextCommitId=0;commitController=null;committingTarget=null;constructor(e){this.deps=e}isCommitting(){return this.phase===`committing`}getCommittingTarget(){return this.committingTarget}abort(){this.commitController?.abort(),this.commitController=null,this.phase=`idle`,this.setCommitVisual(null)}destroy(){this.abort()}async commit(t){let n=this.deps.getOnRowDragCommit();if(!n){this.deps.emitFinished(ga({commitId:-1,leaderRowId:t.plan.leaderRowId,committed:!1,reason:`onRowDragCommit is required when rowDragCommitMode is deferred`}));return}let r=++this.nextCommitId,i=e.s(r,this.commitController);this.commitController=i,this.phase=`committing`,this.setCommitVisual({rowIds:t.rowIds}),this.deps.emitStarted(ha({rowIds:t.rowIds,leaderRowId:t.plan.leaderRowId,displayIndex:t.plan.displayIndex,treeDrop:t.plan.treeDrop}));let a={ok:!1};try{let e=await n(_a(t.plan,t.nestUnderRowId,i.context));if(i.context.commitId!==r)return;a=Uh(e)}catch(t){if(e.c(t))a={ok:!1,aborted:!0};else throw t}finally{this.commitController===i&&(this.commitController=null),this.phase=`idle`,this.setCommitVisual(null)}i.context.commitId===r&&(this.deps.emitFinished(ga({commitId:r,leaderRowId:t.plan.leaderRowId,committed:a.ok,aborted:a.aborted,reason:a.reason})),a.ok&&(this.deps.applyPlan(t.plan),this.deps.emitRowDragEnd(ma(t.plan.leaderRowId,t.plan.displayIndex,!0,t.rowIds,t.treeContext))))}setCommitVisual(e){this.committingTarget=e,this.deps.setCommittingVisual(e)}};function Gh(e,t=6){let n=e;for(;n;){let e=getComputedStyle(n).getPropertyValue(`--mg-cell-comment-indicator-size`).trim();if(e){let t=parseFloat(e);if(Number.isFinite(t))return t}n=n.parentElement}return t}function Kh(e,t,n=2){let r=t,i=t,a=e.right-n,o=e.top+n,s=a-r;return{x:s,y:o,left:s,top:o,right:a,bottom:o+i,width:r,height:i,toJSON:()=>({})}}function qh(e,t,n){if(!e.classList.contains(`mg-cell--has-comment`)&&!e.classList.contains(`mg-cell--comment-empty`))return!1;let r=Kh(e.getBoundingClientRect(),Gh(e));return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom}var Jh=`mg-cell-comment-popup__textarea`,Yh=`mg-cell-comment-popup__actions`,Xh=`mg-cell-comment-popup__btn--save`,Zh=`mg-cell-comment-popup__btn--delete`,Qh=`mg-cell-comment-popup__btn--cancel`;function $h(e,t=8){let n=e;for(;n;){let e=getComputedStyle(n).getPropertyValue(`--mg-spacing`).trim();if(e){let t=parseFloat(e);if(Number.isFinite(t))return t}n=n.parentElement}return t}function eg(e){let t=$h(e);return{viewportPadding:t,anchorGap:t}}function tg(e,t,n,r=eg(null),i=6){let{viewportPadding:a,anchorGap:o}=r,s=Kh(e,i),c=s.right+o,l=s.top;return c+t>window.innerWidth-a&&(c=s.left-t-o),c=Math.max(a,Math.min(c,window.innerWidth-t-a)),l=Math.max(a,Math.min(l,window.innerHeight-n-a)),{left:c,top:l}}function ng(e,t){if(!t)return 4;let n=e?e.split(`
|
|
3
3
|
`).length:1;return Math.max(1,Math.min(n,12))}var rg=class{getMountEl;rootEl=null;textareaEl=null;anchorEl=null;options=null;committing=!1;textareaReadOnly=!1;saveButton=null;deleteButton=null;cancelButton=null;constructor(e=()=>document.body){this.getMountEl=e}onWindowKeyDown=e=>{if(e.key===`Escape`){if(this.committing){e.preventDefault(),e.stopPropagation();return}e.preventDefault(),e.stopPropagation(),this.close()}};get isOpen(){return this.rootEl!=null}isCommitting(){return this.committing}getAnchorEl(){return this.anchorEl}getRootEl(){return this.rootEl}open(e){this.close(),this.options=e,this.anchorEl=e.anchorEl,this.anchorEl.dataset.commentOpen=`true`;let t=e.readOnly===!0||e.mode===`view`,n=e.mode??(e.comment?.text?`edit`:`create`);this.rootEl=document.createElement(`div`),this.rootEl.className=Wl,this.rootEl.classList.toggle(Gl,t),this.rootEl.dataset.mode=n,this.textareaEl=document.createElement(`textarea`),this.textareaEl.className=Jh,this.textareaEl.value=e.comment?.text??``,this.textareaReadOnly=t,this.textareaEl.readOnly=t,this.textareaEl.rows=ng(e.comment?.text,t),this.textareaEl.setAttribute(`aria-label`,t?`单元格批注`:`编辑单元格批注`),this.rootEl.append(this.textareaEl),t?this.rootEl.append(this.createActions(`view`,!!e.comment?.text)):this.rootEl.append(this.createActions(n,!!e.comment?.text)),this.getMountEl().append(this.rootEl),this.reposition(),window.addEventListener(`keydown`,this.onWindowKeyDown,!0),t||(this.textareaEl.focus(),this.textareaEl.setSelectionRange(this.textareaEl.value.length,this.textareaEl.value.length))}updatePosition(){this.reposition()}close(e=!1){if(this.committing&&!e)return;window.removeEventListener(`keydown`,this.onWindowKeyDown,!0),this.anchorEl&&=(delete this.anchorEl.dataset.commentOpen,null),this.rootEl?.remove(),this.rootEl=null,this.textareaEl=null,this.saveButton=null,this.deleteButton=null,this.cancelButton=null,this.committing=!1,this.textareaReadOnly=!1;let t=this.options?.onClose;this.options=null,t?.()}reposition(){if(!this.rootEl||!this.anchorEl)return;let e=Math.max(this.rootEl.offsetWidth,280),t=this.rootEl.offsetHeight,n=eg(this.anchorEl),r=Gh(this.anchorEl),i=tg(this.anchorEl.getBoundingClientRect(),e,t,n,r);this.rootEl.style.position=`fixed`,this.rootEl.style.left=`${i.left}px`,this.rootEl.style.top=`${i.top}px`,this.rootEl.style.minWidth=`280px`,this.rootEl.style.removeProperty(`min-height`)}createActions(e,t){let n=document.createElement(`div`);if(n.className=Yh,e!==`view`){let e=document.createElement(`button`);e.type=`button`,e.className=Xh,e.textContent=`保存`,e.addEventListener(`click`,()=>{this.handleSave()}),n.append(e),this.saveButton=e}if(t&&e===`edit`){let e=document.createElement(`button`);e.type=`button`,e.className=Zh,e.textContent=`删除`,e.addEventListener(`click`,()=>{this.handleDelete()}),n.append(e),this.deleteButton=e}let r=document.createElement(`button`);return r.type=`button`,r.className=Qh,r.textContent=e===`view`?`关闭`:`取消`,r.addEventListener(`click`,()=>{this.close()}),n.append(r),this.cancelButton=r,n}async handleSave(){let e=this.textareaEl?.value.trim()??``;if(!e){this.close();return}await this.runAction(`save`,()=>this.options?.onSave?.(e))}async handleDelete(){await this.runAction(`delete`,()=>this.options?.onDelete?.())}async runAction(e,t){if(this.committing||!this.isOpen)return;this.committing=!0,this.setCommittingVisual(!0,e);let n=!1;try{if(await t()===!1)return;n=!0,this.committing=!1,this.close()}catch{}finally{!n&&this.isOpen&&(this.committing=!1,this.setCommittingVisual(!1))}}setCommittingVisual(e,t){if(this.rootEl?.classList.toggle(Kl,e),this.textareaEl&&(this.textareaEl.readOnly=e||this.textareaReadOnly),this.saveButton?.toggleAttribute(`disabled`,e),this.deleteButton?.toggleAttribute(`disabled`,e),this.cancelButton?.toggleAttribute(`disabled`,e),e&&t===`save`){this.saveButton.textContent=`保存中...`;return}if(e&&t===`delete`){this.deleteButton.textContent=`删除中...`;return}this.saveButton&&(this.saveButton.textContent=`保存`),this.deleteButton&&(this.deleteButton.textContent=`删除`)}},ig=class{deps;datasourceInitialized=!1;presenceCache=new Map;popup;constructor(e){this.deps=e,this.popup=new rg(()=>e.getMountEl())}getPopup(){return this.popup}get active(){return Xl(this.deps.getOptions().cellCommentsDataSource)&&!!this.deps.getRowKey()}init(e){let t=this.deps.getOptions().cellCommentsDataSource;au(Xl(t),this.deps.getRowKey()),Xl(t)&&(this.datasourceInitialized||=(t?.init?.({api:e}),!0))}destroy(){this.popup.close(!0);let e=this.deps.getOptions().cellCommentsDataSource;this.datasourceInitialized&&=(e?.destroy?.(),!1),this.presenceCache.clear()}resetDatasourceLifecycle(){let e=this.deps.getOptions().cellCommentsDataSource;this.datasourceInitialized&&=(e?.destroy?.(),!1),this.presenceCache.clear()}getComment(e,t){let n=this.resolveCellParams(e,t);if(!n)return;let r=this.deps.getOptions().cellCommentsDataSource?.getComment(n);return ag(r)}hasComment(e,t){let n=iu(e,t),r=this.presenceCache.get(n);if(r!=null)return r;let i=nu(this.getComment(e,t));return this.presenceCache.set(n,i),i}getCachedHasComment(e,t){return this.presenceCache.get(iu(e,t))}resolveInteraction(e,t){let n=this.resolveCellParams(e,t);if(!n)return{canView:!1,canCreate:!1,canEdit:!1,canDelete:!1};let r=this.getComment(e,t);return tu(eu({gridSuppress:this.deps.getOptions().suppressCellComments,columnSuppress:n.column.suppressCellComments,colId:t,rowId:n.rowId,rowKind:at(n.rowNode.rowKind),data:n.data,hasExistingComment:nu(r)}),r)}async setComment(e,t,n,r,i){if(!this.active)return!1;let a=this.resolveCellParams(e,t);if(!a)return!1;let o=X(e),s=n??void 0,c=s==null;if(r===`ui`&&!i?.bypassSuppress){let e=this.resolveInteraction(o,t);if(c&&!e.canDelete)return!1;if(!c){if(this.getComment(o,t)){if(!e.canEdit)return!1}else if(!e.canCreate)return!1}}r===`api`&&this.deps.getOptions().suppressCellComments&&i?.bypassSuppress;let l=this.deps.getOptions().cellCommentsDataSource;if(!l)return!1;await l.setComment({...a,comment:s}),this.invalidateCache(o,t);let u=ru(o,t,s??null,r);return this.deps.onCommentChanged?.(u),this.deps.onCommentsRefresh?.({rowIds:[o],colIds:[t]}),!0}refreshPresenceCache(e){for(let t of e){let e=iu(t.rowId,t.colId);this.presenceCache.set(e,nu(this.getComment(t.rowId,t.colId)))}}invalidateCache(e,t){if(e==null&&t==null){this.presenceCache.clear();return}if(e!=null&&t!=null){this.presenceCache.delete(iu(e,t));return}let n=e==null?t==null?null:`::${t}`:`${X(e)}::`;if(n)for(let r of[...this.presenceCache.keys()])(e!=null&&r.startsWith(n)||t!=null&&r.endsWith(n))&&this.presenceCache.delete(r)}requestRefresh(e){if(e?.rowIds?.length||e?.colIds?.length){if(e.rowIds?.length&&e.colIds?.length){for(let t of e.rowIds)if(t!=null)for(let n of e.colIds)this.invalidateCache(X(t),n)}else if(e.rowIds?.length)for(let t of e.rowIds)t!=null&&this.invalidateCache(X(t));else if(e.colIds?.length)for(let t of e.colIds)this.invalidateCache(void 0,t)}else this.invalidateCache();this.deps.onCommentsRefresh?.(e)}createHost(){return{active:()=>this.active,hasComment:(e,t)=>this.hasComment(e,t),canCreateComment:(e,t)=>this.resolveInteraction(e,t).canCreate}}openEditor(e){if(!this.active)return!1;let t=this.resolveCellParams(e.rowId,e.colId);if(!t)return!1;let{rowId:n,colId:r}=t,i=this.getComment(n,r),a=nu(i),o=this.resolveInteraction(n,r),s=og(e.preferredMode,a,o,i?.readOnly===!0);if(!s)return!1;let c=s===`view`||i?.readOnly===!0;return this.popup.open({anchorEl:e.anchorEl,comment:i,readOnly:c,mode:s,onSave:async e=>{let t=this.getComment(n,r);return this.setComment(n,r,{...t,text:e},`ui`)},onDelete:async()=>this.setComment(n,r,null,`ui`),onClose:e.onPopupClose}),!0}closeEditor(){this.popup.close()}getOpenEditorCell(){let e=this.popup.getAnchorEl();if(!e)return null;let t=e.closest(`.mg-row`)?.dataset.rowId,n=e.dataset.colId;return!t||!n?null:{rowId:t,colId:n}}resolveCellParams(e,t){if(!this.active)return;let n=X(e),r=this.deps.getRowNode(n),i=this.deps.getColumn(t);if(!(!r||!i))return{rowId:n,colId:t,data:r.data,rowNode:r,column:i}}};function ag(e){if(e!=null)return e}function og(e,t,n,r){if(e===`create`){if(n.canCreate)return`create`;if(t){if(n.canEdit&&!r)return`edit`;if(n.canView)return`view`}return null}return e===`edit`?n.canEdit?`edit`:n.canView?`view`:null:e===`view`?n.canView?`view`:null:t?n.canEdit&&!r?`edit`:n.canView?`view`:null:n.canCreate?`create`:null}function sg(e){return{startRowIndex:e.startRowIndex,endRowIndex:e.endRowIndex,startColId:e.startColId,endColId:e.endColId}}function cg(e){return{rowIndex:e.rowIndex,colId:e.colId}}function lg(e,t){return e.length===t.length&&e.every((e,n)=>Hs(e,t[n]))}function ug(e,t){let n=t.expandRangeForCellSpans?.(e)??e,r=Y(n,t.displayedColIds);return!r||t.rowKindAt&&!Us(n,t.rowKindAt)?null:Bs(r)}function dg(e,t){let n=[];for(let r of e){let e=ug(r,t);e&&n.push(e)}return n}function fg(e,t,n){for(let r=0;r<t.length;r++){let i=Y(t[r],n);if(i&&Vs(e.rowIndex,e.colId,i,n))return r}return-1}var pg=class{suppressMultiRanges;ranges=[];anchor=null;constructor(e=!0){this.suppressMultiRanges=e}getRanges(){return this.ranges.map(sg)}getAnchor(){return this.anchor?cg(this.anchor):null}hasRanges(){return this.ranges.length>0}isSuppressMultiRanges(){return this.suppressMultiRanges}setSuppressMultiRanges(e){this.suppressMultiRanges=e,e&&this.ranges.length>1&&(this.ranges=this.ranges.slice(0,1))}setAnchor(e){this.anchor=e?cg(e):null}clear(){return this.ranges.length===0&&this.anchor===null?!1:(this.ranges=[],this.anchor=null,!0)}setRanges(e,t,n){let r=dg(e,t);this.suppressMultiRanges&&r.length>1&&(r=r.slice(0,1));let i=!lg(this.ranges,r);return!i&&n==null?!1:(this.ranges=r,n===null?this.anchor=null:n===void 0?r.length===0&&(this.anchor=null):this.anchor=cg(n),i||n!==void 0)}addRange(e,t,n){let r=ug(e,t);return r?this.suppressMultiRanges?this.setRanges([r],t,n??this.anchor):!this.ranges.some(e=>Hs(e,r))&&(this.ranges=[...this.ranges,r],n&&(this.anchor=cg(n)),!0):!1}extendFromAnchor(e,t){if(!this.anchor)return!1;let n=ug(Rs(this.anchor,e),t);if(!n)return!1;let r=fg(this.anchor,this.ranges,t.displayedColIds);if(r>=0){let e=[...this.ranges];return e[r]=n,this.setRanges(e,t,this.anchor)}return this.setRanges([n],t,this.anchor)}extendFocusedRange(e,t,n){if(this.anchor)return this.extendFromAnchor(t,n);let r=ug(Rs(e,t),n);if(!r)return!1;let i=fg(e,this.ranges,n.displayedColIds);if(i>=0){let t=[...this.ranges];return t[i]=r,this.setRanges(t,n,e)}return this.ranges.length===0||this.suppressMultiRanges?this.setRanges([r],n,e):this.addRange(r,n,e)}isCellInAnyRange(e,t,n){return fg({rowIndex:e,colId:t},this.ranges,n)>=0}};function mg(e,t){let n=e.suppressPaste;return n==null||n===!1?!1:n===!0||n(t)}function hg(e){return e==null?``:Array.isArray(e)?e.join(`, `):String(e)}function gg(e,t,n){let r=n?.getRowGroupingHost?.();if(r?.active()&&It(t,e)){let n=bp(e,r,t);return!n.visible||n.label.length===0?``:n.showCount&&n.count>0?`${n.label}${xp(n.count)}`:n.label}let i=n?.getTreeTableHost?.();if(i?.active()&&Ep(t,e)){let t=Op(e,i);return t.visible?t.label:``}return null}function _g(e,t,n,r){return gg(e,t,r)??(t.useFormatterForClipboard===!1?hg(G(e,t)):sr(e,t,n))}function vg(e,t,n,r,i,a){return{rowIndex:e,colId:n.colId,rowNode:t,column:n,value:r,formatValue:e=>bg(t,n,e),parseValue:e=>xg(e,n,i)}}function yg(e,t,n,r,i,a,o){return{...vg(e,t,n,r,a,o),oldValue:i}}function bg(e,t,n){return t.formatter?t.formatter(e.data,n):hg(n)}function xg(e,t,n){return wg(e,t,n)}function Sg(e,t,n,r,i,a,o){let s=_g(t,n,r,o);return a?hg(a(vg(e,t,n,s,i,r))):s}function Cg(e,t,n,r,i,a,o){if(!o)return wg(e,t,i);let s=o(yg(n,r,t,e,i.value,i,a));return kn(s)||t.useParserForClipboard===!1?s:In(hg(s),t,i)}function wg(e,t,n){return t.useParserForClipboard===!1?e:In(e,t,n)}async function Tg(e,t,n,r,i){let a=Cg(n,e,i.rowIndex,i.rowNode,t,i.indexColumnOptions,i.processCellFromClipboard);return kn(a)||await rr(e,t,a,i.signal??new AbortController().signal)?{status:`blocked`,showBlockedVisual:!0}:Object.is(r,a)?{status:`blocked`,showBlockedVisual:!1}:Ln(e,t,a)?{status:`applied`,parsed:a}:{status:`blocked`,showBlockedVisual:!0}}function Eg(e){return/[\t\n\r"]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function Dg(e){return e.map(Eg).join(` `)}function Og(e){return e.map(e=>e.join(`
|
|
4
4
|
`)).filter(e=>e.length>0).join(`
|
|
5
5
|
|