@gp-grid/core 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -244,7 +244,7 @@ Both data source types implement this interface:
244
244
 
245
245
  ```typescript
246
246
  interface DataSource<TData = Row> {
247
- fetch(request: DataSourceRequest): Promise<DataSourceResponse<TData>>;
247
+ query(request: DataSourceRequest): Promise<DataSourceResponse<TData>>;
248
248
  }
249
249
 
250
250
  interface DataSourceRequest {
@@ -265,8 +265,8 @@ interface DataSourceResponse<TData> {
265
265
  `createServerDataSource` uses paginated loading by default. The grid sends
266
266
  one absolute `range`, so APIs can use `startRow` as an offset and
267
267
  `endRow - startRow` as a limit. Use
268
- `createServerDataSource(fetchFn, { loadMode: "all" })` or
269
- `rowLoading: { mode: "all" }` when you intentionally want fetch-all behavior.
268
+ `createServerDataSource(queryFn, { loadMode: "all" })` or
269
+ `rowLoading: { mode: "all" }` when you intentionally want load-all behavior.
270
270
 
271
271
  Paginated cache aggressiveness is controlled through `rowLoading.cache`:
272
272
 
package/dist/index.d.ts CHANGED
@@ -358,8 +358,8 @@ interface DataSource<TData = unknown> {
358
358
  * Undefined is treated as "all".
359
359
  */
360
360
  readonly loadMode?: DataSourceLoadMode;
361
- /** Fetch data based on the request */
362
- fetch(request: DataSourceRequest): Promise<DataSourceResponse<TData>>;
361
+ /** Query data based on the request (range, sort, filter). */
362
+ query(request: DataSourceRequest): Promise<DataSourceResponse<TData>>;
363
363
  /** Optional cleanup method to release resources */
364
364
  destroy?: () => void;
365
365
  /** Move a row */
@@ -1519,7 +1519,7 @@ declare class IndexedDataStore<TData = unknown> {
1519
1519
  setData(data: TData[]): void;
1520
1520
  /**
1521
1521
  * Query data with sorting, filtering, and row-range slicing.
1522
- * Compatible with DataSource.fetch() interface.
1522
+ * Compatible with DataSource.query() interface.
1523
1523
  */
1524
1524
  query(request: DataSourceRequest): DataSourceResponse<TData>;
1525
1525
  /**
@@ -2559,16 +2559,16 @@ declare function createClientDataSource<TData = unknown>(data: TData[], options?
2559
2559
  declare function createDataSourceFromArray<TData = unknown>(data: TData[]): DataSource<TData>;
2560
2560
  //#endregion
2561
2561
  //#region src/data-source/server-data-source.d.ts
2562
- type ServerFetchFunction<TData> = (request: DataSourceRequest) => Promise<DataSourceResponse<TData>>;
2562
+ type ServerQueryFunction<TData> = (request: DataSourceRequest) => Promise<DataSourceResponse<TData>>;
2563
2563
  interface ServerDataSourceOptions {
2564
2564
  /** Server data sources use paginated loading by default. */
2565
2565
  loadMode?: DataSourceLoadMode;
2566
2566
  }
2567
2567
  /**
2568
2568
  * Creates a server-side data source that delegates all operations to the server.
2569
- * The fetch function receives sort/filter/range params to pass to the API.
2569
+ * The query function receives sort/filter/range params to pass to the API.
2570
2570
  */
2571
- declare function createServerDataSource<TData = unknown>(fetchFn: ServerFetchFunction<TData>, options?: ServerDataSourceOptions): DataSource<TData>;
2571
+ declare function createServerDataSource<TData = unknown>(queryFn: ServerQueryFunction<TData>, options?: ServerDataSourceOptions): DataSource<TData>;
2572
2572
  //#endregion
2573
2573
  //#region src/data-source/mutable-data-source.d.ts
2574
2574
  /** Callback for data change notifications */
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const e=(e,t,n,r,i)=>{let a=0,o=0;return e<40+i?o=-10:e>n-40&&(o=10),t<40?a=-10:t>r-40&&(a=10),a!==0||o!==0?{dx:a,dy:o}:null};var t=class{active=!1;colIndex=-1;startX=0;initialWidth=0;currentWidth=0;core;constructor(e){this.core=e}get isActive(){return this.active}start(e,t,n){return n.button!==0||this.core.getColumns()[e]?.resizable===!1?{preventDefault:!1,stopPropagation:!1}:(this.active=!0,this.colIndex=e,this.startX=n.clientX,this.initialWidth=t,this.currentWidth=t,{preventDefault:!0,stopPropagation:!0,startDrag:`column-resize`})}move(e,t){let n=this.core.getColumns()[this.colIndex],r=n?.minWidth??50,i=n?.maxWidth,a=this.initialWidth+(e.clientX-this.startX);a=Math.max(r,a),i!==void 0&&(a=Math.min(i,a)),this.currentWidth=a;let o=e.clientX-t.left>t.width-40?10:0,s=o===0?null:{dx:o,dy:0};return{targetRow:0,targetCol:this.colIndex,autoScroll:s}}end(){this.active&&this.core.setColumnWidth(this.colIndex,this.currentWidth),this.active=!1,this.colIndex=-1}getState(){return this.active===!1?null:{colIndex:this.colIndex,initialWidth:this.initialWidth,currentWidth:this.currentWidth}}};const n=e=>{let t=[0],n=0;for(let r of e)n+=r.width,t.push(n);return t},r=e=>e.at(-1)??0,i=(e,t)=>{let i=n(e),a=r(i);if(t<=a||a===0)return{positions:i,widths:e.map(e=>e.width)};let o=t/a,s=e.map(e=>e.width*o),c=[0],l=0;for(let e of s)l+=e,c.push(l);return{positions:c,widths:s}},a=(e,t)=>{for(let n=0;n<t.length-1;n++)if(e>=t[n]&&e<t[n+1])return n;return e>=t.at(-1)?t.length-2:0},o=e=>({minRow:Math.min(e.startRow,e.endRow),maxRow:Math.max(e.startRow,e.endRow),minCol:Math.min(e.startCol,e.endCol),maxCol:Math.max(e.startCol,e.endCol)}),s=(e,t,n)=>e>=n.minRow&&e<=n.maxRow&&t>=n.minCol&&t<=n.maxCol,c=(e,t,n)=>n?s(e,t,o(n)):!1,l=(e,t,n)=>n?.row===e&&n?.col===t,u=(e,t)=>!t||t.end<0||t.start>t.end?!0:e>=t.start&&e<=t.end,d=(e,t,n)=>n?.row===e&&n?.col===t,f=(e,t,n,r,i)=>{if(!n||!r||!i)return!1;let{minRow:a,maxRow:s,minCol:c,maxCol:l}=o(r),u=i.row>s,d=i.row<a;return u?e>s&&e<=i.row&&t>=c&&t<=l:d?e<a&&e>=i.row&&t>=c&&t<=l:!1},p=(e,t,n,r)=>{let i=[`gp-grid-cell`];return e&&i.push(`gp-grid-cell--active`),t&&!e&&i.push(`gp-grid-cell--selected`),n&&i.push(`gp-grid-cell--editing`),r&&i.push(`gp-grid-cell--fill-preview`),i.join(` `)},m=(e,t)=>{if(!t)return!1;let{minRow:n,maxRow:r}=o(t);return e>=n&&e<=r},h=(e,t)=>{if(!t)return!1;let{minCol:n,maxCol:r}=o(t);return e>=n&&e<=r};function g(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}function _(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];if(typeof i!=`object`||!i)return;i=i[t]}typeof i==`object`&&i&&(i[r.at(-1)]=n)}const v=()=>{let e=[];return{onInstruction:t=>(e.push(t),()=>{e=e.filter(e=>e!==t)}),emit:t=>{for(let n of e)n(t)},clearListeners:()=>{e=[]}}},ee=()=>{let e=v(),t=[];return{onInstruction:e.onInstruction,onBatchInstruction:e=>(t.push(e),()=>{t=t.filter(t=>t!==e)}),emit:n=>{e.emit(n);for(let e of t)e([n])},emitBatch:n=>{if(n.length!==0){for(let e of t)e(n);for(let t of n)e.emit(t)}},clearListeners:()=>{e.clearListeners(),t=[]}}},te=(e,t)=>{for(let n of e.values())if(n.rowIndex===t)return n;return null},ne=(e,t,n,r,i,a=0)=>{let o=te(i,n);if(!o){t.scrollTop=e.getScrollTopForRow(n);return}let s=a+o.translateY-t.scrollTop,c=s+r;if(s<0)t.scrollTop=e.getScrollTopForRow(n);else if(c>t.clientHeight){let i=Math.floor(t.clientHeight/r),a=Math.max(0,n-i+1);t.scrollTop=e.getScrollTopForRow(a)}},y=(e,t)=>e==null?``:t?t(e):Array.isArray(e)?e.join(`, `):typeof e==`object`?e instanceof Date?String(e):JSON.stringify(e):String(e),re=e=>{let{activeCell:t,selectionRange:n,slots:r,columns:i,visibleColumnsWithIndices:a,columnPositions:o,columnWidths:s,rowHeight:c}=e;if(!t&&!n)return null;let l,u,d,f;if(n)l=Math.max(n.startRow,n.endRow),u=Math.max(n.startCol,n.endCol),d=Math.min(n.startCol,n.endCol),f=Math.max(n.startCol,n.endCol);else if(t)l=t.row,u=t.col,d=u,f=u;else return null;for(let e=d;e<=f;e++){let t=i[e];if(!(!t||t.hidden)&&t.editable!==!0)return null}let p=a.findIndex(e=>e.originalIndex===u);if(p===-1)return null;let m=null;for(let e of r.values())if(e.rowIndex===l){m=e.translateY;break}if(m===null)return null;let h=o[p]??0,g=s[p]??0;return{top:m+c-5,left:h+g-20}},ie=(e,t,n=8)=>{let r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=r.bottom+4,o=r.left,s=Math.max(200,r.width);return o+i.width>window.innerWidth-n&&(o=window.innerWidth-i.width-n),o=Math.max(n,o),a+i.height>window.innerHeight-n&&(a=r.top-i.height-4),a=Math.max(n,a),{top:a,left:o,minWidth:s}},ae=e=>{if(!e||e.length===0)return;let t={};for(let n of e)n.valueFormatter&&(t[n.colId??n.field]=n.valueFormatter);return Object.keys(t).length>0?t:void 0},b=e=>({range:e.range,sort:e.sortModel.length>0?e.sortModel:void 0,filter:Object.keys(e.filterModel).length>0?e.filterModel:void 0,valueFormatters:ae(e.columns)}),oe=(e,t,n)=>{let r=e.get(t);if(r!==void 0){if(t<n){let i=n-1;for(let n=t;n<i;n++){let t=e.get(n+1);t===void 0?e.delete(n):e.set(n,t)}e.set(i,r);return}for(let r=t;r>n;r--){let t=e.get(r-1);t===void 0?e.delete(r):e.set(r,t)}e.set(n,r)}},se=e=>{let t=[0],n=0;for(let r of e)r.hidden||(n+=r.width,t.push(n));return t},ce=(e,t,n,r)=>{let i=e.get(n);if(!i)return null;let a=t[r];return a?g(i,a.field):null},le=(e,t,n,r,i,a)=>{let o=e.get(n);if(!o||typeof o!=`object`)return;let s=t[r];if(!s)return;let c=a.onCellValueChanged!==void 0,l=c?g(o,s.field):void 0;_(o,s.field,i),c&&a.onCellValueChanged({rowId:a.getRowId(o),colIndex:r,field:s.field,oldValue:l,newValue:i,rowData:o})};var ue=class{active=!1;sourceColIndex=-1;startX=0;startY=0;thresholdMet=!1;shiftKey=!1;ghostWidth=0;ghostHeight=0;currentX=0;currentY=0;dropTargetIndex=null;core;deps;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps=e}get isActive(){return this.active}get isDraggingForDisplay(){return this.active&&this.thresholdMet}start(e,t,n,r){return r.button!==0||this.core.getColumns()[e]?.movable===!1?{preventDefault:!1,stopPropagation:!1}:(this.active=!0,this.sourceColIndex=e,this.startX=r.clientX,this.startY=r.clientY,this.thresholdMet=!1,this.shiftKey=r.shiftKey,this.ghostWidth=t,this.ghostHeight=n,this.currentX=r.clientX,this.currentY=r.clientY,this.dropTargetIndex=null,{preventDefault:!0,stopPropagation:!0,startDrag:`column-move`})}move(e,t){let n=e.clientX-this.startX,r=e.clientY-this.startY;if(this.thresholdMet===!1){if(!(Math.abs(n)>5||Math.abs(r)>5))return null;this.thresholdMet=!0}this.currentX=e.clientX,this.currentY=e.clientY;let{left:i,width:o,scrollLeft:s}=t,c=e.clientX-i+s,l=this.deps.getColumnPositions(),u=this.deps.getColumnCount();this.dropTargetIndex=Math.max(0,Math.min(a(c,l),u));let d=e.clientX-i,f=0;d<40?f=-10:d>o-40&&(f=10);let p=f===0?null:{dx:f,dy:0};return{targetRow:0,targetCol:this.dropTargetIndex??0,autoScroll:p}}end(e){this.thresholdMet?this.commitMove():this.treatAsHeaderClick(e),this.reset()}commitMove(){if(this.dropTargetIndex===null)return;let e=this.sourceColIndex,t=this.deps.getOriginalColumnIndex?this.deps.getOriginalColumnIndex(Math.min(this.dropTargetIndex,this.deps.getColumnCount()-1)):this.dropTargetIndex;e!==t&&this.core.moveColumn(e,t)}treatAsHeaderClick(e){let t=this.core.getColumns()[this.sourceColIndex];if(!t)return;let n=t.colId??t.field,r=this.core.getSortModel().find(e=>e.colId===n)?.direction;this.core.setSort(n,e(r),this.shiftKey)}reset(){this.active=!1,this.sourceColIndex=-1,this.thresholdMet=!1,this.shiftKey=!1,this.dropTargetIndex=null}getState(){return this.active===!1?null:{sourceColIndex:this.sourceColIndex,currentX:this.currentX,currentY:this.currentY,dropTargetIndex:this.dropTargetIndex,ghostWidth:this.ghostWidth,ghostHeight:this.ghostHeight}}},de=class{active=!1;sourceRowIndex=-1;startX=0;startY=0;thresholdMet=!1;currentX=0;currentY=0;dropTargetIndex=null;core;deps;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps=e}get isActive(){return this.active}get isDraggingForDisplay(){return this.active&&this.thresholdMet}start(e,t,n){this.active=!0,this.sourceRowIndex=e,this.startX=t,this.startY=n,this.thresholdMet=!1,this.currentX=t,this.currentY=n,this.dropTargetIndex=null}move(t,n){let r=t.clientX-this.startX,i=t.clientY-this.startY;if(this.thresholdMet===!1){if(!(Math.abs(r)>5||Math.abs(i)>5))return null;this.thresholdMet=!0}this.currentX=t.clientX,this.currentY=t.clientY;let{top:a,left:o,height:s,width:c,scrollTop:l}=n,u=this.deps.getHeaderHeight(),d=t.clientY-a,f=this.core.getRowCount(),p=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(d,l),f));return this.dropTargetIndex=p,{targetRow:p,targetCol:0,autoScroll:e(t.clientY-a,t.clientX-o,s,c,u)}}end(){this.thresholdMet&&this.dropTargetIndex!==null&&this.dropTargetIndex!==this.sourceRowIndex&&this.core.commitRowDrag(this.sourceRowIndex,this.dropTargetIndex),this.active=!1,this.sourceRowIndex=-1,this.thresholdMet=!1,this.dropTargetIndex=null}getState(){return this.active===!1?null:{sourceRowIndex:this.sourceRowIndex,currentX:this.currentX,currentY:this.currentY,dropTargetIndex:this.dropTargetIndex,dropIndicatorY:this.dropTargetIndex===null?0:this.core.getRowTranslateY(this.dropTargetIndex)}}},fe=class{active=!1;core;constructor(e){this.core=e}get isActive(){return this.active}start(){this.active=!0}moveToTarget(e,t){this.active!==!1&&this.core.selection.startSelection({row:e,col:t},{shift:!0})}end(){this.active=!1}},pe=class{active=!1;sourceRange=null;target=null;core;constructor(e){this.core=e}get isActive(){return this.active}get stateSnapshot(){return{sourceRange:this.sourceRange,target:this.target}}start(e,t){if(!e&&!t)return{preventDefault:!1,stopPropagation:!1};let n=t??{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};return this.core.fill.startFillDrag(n),this.sourceRange=n,this.target={row:Math.max(n.startRow,n.endRow),col:Math.max(n.startCol,n.endCol)},this.active=!0,{preventDefault:!0,stopPropagation:!0,startDrag:`fill`}}moveToTarget(e,t){this.active!==!1&&(this.core.fill.updateFillDrag(e,t),this.target={row:e,col:t})}end(){this.active&&(this.core.fill.commitFillDrag(),this.core.refreshSlotData()),this.active=!1,this.sourceRange=null,this.target=null}},me=class{record=null;set(e){this.record=e}clear(){this.record=null}consume(){let e=this.record;return this.record=null,e}};const he=e=>{switch(e){case`ArrowUp`:return`up`;case`ArrowDown`:return`down`;case`ArrowLeft`:return`left`;case`ArrowRight`:return`right`;default:return null}};var ge=class{core;constructor(e){this.core=e}handle(e,t,n,r){if(r||n!==null&&e.key!==`Enter`&&e.key!==`Escape`&&e.key!==`Tab`)return{preventDefault:!1};let i=he(e.key);if(i!==null)return this.moveFocus(i,e.shiftKey);let a=e.ctrlKey||e.metaKey;return this.handleAction(e.key,t,n,e.shiftKey,a)}moveFocus(e,t){let{selection:n}=this.core;return n.moveFocus(e,t),{preventDefault:!0,scrollToCell:n.getActiveCell()??void 0}}handleAction(e,t,n,r,i){switch(e){case`Enter`:return this.handleEnter(t,n);case`Escape`:return this.handleEscape(n);case`Tab`:return this.handleTab(n,r);default:return this.handleNonSpecialKey(e,t,n,i)}}handleEnter(e,t){return t?this.core.commitEdit():e&&this.core.startEdit(e.row,e.col),{preventDefault:!0}}handleEscape(e){return e?this.core.cancelEdit():this.core.selection.clearSelection(),{preventDefault:!0}}handleTab(e,t){return e&&this.core.commitEdit(),this.core.selection.moveFocus(t?`left`:`right`,!1),{preventDefault:!0}}handleNonSpecialKey(e,t,n,r){let{selection:i}=this.core;return e===`a`&&r?(i.selectAll(),{preventDefault:!0}):e===`c`&&r?(i.copySelectionToClipboard(),{preventDefault:!0}):e===`F2`?(t&&!n&&this.core.startEdit(t.row,t.col),{preventDefault:!0}):e===`Delete`||e===`Backspace`?t&&!n?(this.core.startEdit(t.row,t.col),{preventDefault:!0}):{preventDefault:!1}:(t&&!n&&!r&&e.length===1&&this.core.startEdit(t.row,t.col),{preventDefault:!1})}};const _e=(t,n,r,i)=>{let{top:o,left:s,width:c,height:l,scrollTop:u,scrollLeft:d}=i,f=n.getColumnPositions(),p=n.getColumnCount(),m=r.clientY-o,h=r.clientX-s+d,g=Math.max(0,Math.min(t.getRowIndexAtDisplayY(m,u),t.getRowCount()-1)),_=Math.max(0,Math.min(a(h,f),p-1));return{row:g,col:n.getOriginalColumnIndex?n.getOriginalColumnIndex(_):_,autoScroll:e(r.clientY-o,r.clientX-s,l,c,n.getHeaderHeight())}},x=e=>e==null?`asc`:e===`asc`?`desc`:null;var S=class{core;deps;columnResize;columnMove;rowDrag;selectionDrag;fillDrag;pendingRowDrag=new me;keyboard;constructor(e,n){this.core=e,this.deps=n,this.columnResize=new t(e),this.columnMove=new ue(e,n),this.rowDrag=new de(e,n),this.selectionDrag=new fe(e),this.fillDrag=new pe(e),this.keyboard=new ge(e)}updateDeps(e){this.deps={...this.deps,...e},this.columnMove.updateDeps(this.deps),this.rowDrag.updateDeps(this.deps)}getDragState(){let e=this.getDragType(),t=this.fillDrag.stateSnapshot;return{isDragging:e!==null,dragType:e,fillSourceRange:t.sourceRange,fillTarget:t.target,columnResize:this.columnResize.getState(),columnMove:this.columnMove.getState(),rowDrag:this.rowDrag.getState()}}getDragType(){return this.fillDrag.isActive?`fill`:this.columnResize.isActive?`column-resize`:this.columnMove.isDraggingForDisplay?`column-move`:this.rowDrag.isDraggingForDisplay?`row-drag`:this.selectionDrag.isActive?`selection`:null}handleHeaderMouseDown(e,t,n,r){return this.columnMove.start(e,t,n,r)}handleHeaderResizeMouseDown(e,t,n){return this.columnResize.start(e,t,n)}handleCellMouseDown(e,t,n){if(n.button!==0||this.core.getEditState()!==null)return ve;let r=(this.core.getColumns()[t]?.rowDrag===!0||this.core.isRowDragEntireRow())&&!n.shiftKey;return r&&n.pointerType===`touch`?this.startPendingRowDrag(e,t,n):r?this.startRowDrag(e,t,n):this.startSelectionClick(e,t,n)}startPendingRowDrag(e,t,n){return this.pendingRowDrag.set({rowIndex:e,colIndex:t,clientX:n.clientX,clientY:n.clientY}),this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:`row-drag-pending`}}startRowDrag(e,t,n){return this.rowDrag.start(e,n.clientX,n.clientY),this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!0,stopPropagation:!0,focusContainer:!0,startDrag:`row-drag`}}startSelectionClick(e,t,n){return this.core.selection.startSelection({row:e,col:t},{shift:n.shiftKey,ctrl:n.ctrlKey||n.metaKey}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:n.shiftKey?void 0:`selection`}}handleCellDoubleClick(e,t){this.core.startEdit(e,t)}handleCellMouseEnter(e,t){this.core.highlight?.setHoverPosition({row:e,col:t})}handleCellMouseLeave(){this.core.highlight?.setHoverPosition(null)}handleFillHandleMouseDown(e,t,n){return this.fillDrag.start(e,t)}handleHeaderClick(e,t){let n=this.core.getSortModel().find(t=>t.colId===e)?.direction;this.core.setSort(e,x(n),t)}startSelectionDrag(){this.selectionDrag.start()}confirmPendingRowDrag(){let e=this.pendingRowDrag.consume();return e===null?!1:(this.rowDrag.start(e.rowIndex,e.clientX,e.clientY),!0)}cancelPendingRowDrag(){this.pendingRowDrag.clear()}handleDragMove(e,t){return this.columnResize.isActive?this.columnResize.move(e,t):this.columnMove.isActive?this.columnMove.move(e,t):this.rowDrag.isActive?this.rowDrag.move(e,t):this.selectionFillMove(e,t)}selectionFillMove(e,t){if((this.selectionDrag.isActive||this.fillDrag.isActive)===!1)return null;let n=_e(this.core,this.deps,e,t);return this.selectionDrag.moveToTarget(n.row,n.col),this.fillDrag.moveToTarget(n.row,n.col),{targetRow:n.row,targetCol:n.col,autoScroll:n.autoScroll}}handleDragEnd(){if(this.columnResize.isActive)return this.columnResize.end();if(this.columnMove.isActive)return this.columnMove.end(x);if(this.rowDrag.isActive)return this.rowDrag.end();this.selectionDrag.end(),this.fillDrag.end()}handleWheel(e,t,n){return this.core.isScalingActive()?{dy:e*n,dx:t*n}:null}handleKeyDown(e,t,n,r){return this.keyboard.handle(e,t,n,r)}};const ve={preventDefault:!1,stopPropagation:!1};var C=class{options;highlightingOptions;hoverPosition=null;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;rowClassCache=new Map;columnClassCache=new Map;cellClassCache=new Map;constructor(e,t={}){this.options=e,this.highlightingOptions=t}isEnabled(){return!!(this.highlightingOptions.computeRowClasses||this.highlightingOptions.computeColumnClasses||this.highlightingOptions.computeCellClasses)}updateOptions(e){this.highlightingOptions=e,this.clearAllCaches()}setHoverPosition(e){this.isEnabled()&&(this.hoverPosition?.row===e?.row&&this.hoverPosition?.col===e?.col||(this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear(),this.hoverPosition=e,this.emit({type:`SET_HOVER_POSITION`,position:e})))}getHoverPosition(){return this.hoverPosition}onSelectionChange(){this.clearAllCaches()}buildRowContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:e,colIndex:null,column:void 0,rowData:t,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.row===e,isActive:n?.row===e,isSelected:m(e,r)}}buildColumnContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:null,colIndex:e,column:t,rowData:void 0,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.col===e,isActive:n?.col===e,isSelected:h(e,r)}}buildCellContext(e,t,n,r){let i=this.options.getActiveCell(),a=this.options.getSelectionRange(),s=this.hoverPosition?.row===e&&this.hoverPosition?.col===t,c=!1;if(a){let{minRow:n,maxRow:r,minCol:i,maxCol:s}=o(a);c=e>=n&&e<=r&&t>=i&&t<=s}return{rowIndex:e,colIndex:t,column:n,rowData:r,hoverPosition:this.hoverPosition,activeCell:i,selectionRange:a,isHovered:s,isActive:i?.row===e&&i?.col===t,isSelected:c}}computeRowClasses(e,t){let n=this.highlightingOptions.computeRowClasses;if(!n)return[];let r=this.rowClassCache.get(e);if(r!==void 0)return r;let i=n(this.buildRowContext(e,t));return this.rowClassCache.set(e,i),i}computeColumnClasses(e,t){let n=this.columnClassCache.get(e);if(n!==void 0)return n;let r=this.buildColumnContext(e,t),i;if(t.computeColumnClasses)i=t.computeColumnClasses(r);else if(this.highlightingOptions.computeColumnClasses)i=this.highlightingOptions.computeColumnClasses(r);else return[];return this.columnClassCache.set(e,i),i}computeCellClasses(e,t,n,r){let i=`${e},${t}`,a=this.cellClassCache.get(i);if(a!==void 0)return a;let o=this.buildCellContext(e,t,n,r),s;if(n.computeCellClasses)s=n.computeCellClasses(o);else if(this.highlightingOptions.computeCellClasses)s=this.highlightingOptions.computeCellClasses(o);else return[];return this.cellClassCache.set(i,s),s}computeCombinedCellClasses(e,t,n,r){let i=this.computeColumnClasses(t,n),a=this.computeCellClasses(e,t,n,r);return[...i,...a]}clearAllCaches(){this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear()}destroy(){this.emitter.clearListeners(),this.clearAllCaches(),this.hoverPosition=null}},w=class{options;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getRow(e){return this.options.getCachedRows().get(e)}addRows(e,t){if(e.length===0)return;let n=this.options.getCachedRows(),r=this.options.getTotalRows(),i=t??r,a=r+e.length;if(i<r){let t=new Map;for(let[r,a]of n)r>=i?t.set(r+e.length,a):t.set(r,a);this.options.setCachedRows(t)}let o=this.options.getCachedRows();e.forEach((e,t)=>{o.set(i+t,e)}),this.options.setTotalRows(a);let s=e.map((e,t)=>i+t);this.emit({type:`ROWS_ADDED`,indices:s,count:s.length,totalRows:a}),this.options.emitContentSize(),this.options.refreshAllSlots()}updateRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=[];for(let r of e){let e=t.get(r.index);e&&(t.set(r.index,{...e,...r.data}),n.push(r.index))}if(n.length!==0){this.emit({type:`ROWS_UPDATED`,indices:n});for(let e of n)this.options.updateSlot(e)}}deleteRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=this.options.getTotalRows(),r=[...e].sort((e,t)=>t-e);for(let e of r){if(e<0||e>=n)continue;t.delete(e);let r=new Map;for(let[n,i]of t)n>e?r.set(n-1,i):r.set(n,i);this.options.setCachedRows(r),n--}this.options.setTotalRows(n),this.options.clearSelectionIfInvalid(n),this.emit({type:`ROWS_REMOVED`,indices:r,totalRows:n}),this.options.emitContentSize(),this.options.refreshAllSlots()}setRow(e,t){let n=this.options.getTotalRows();e<0||e>=n||(this.options.getCachedRows().set(e,t),this.emit({type:`ROWS_UPDATED`,indices:[e]}),this.options.updateSlot(e))}destroy(){this.emitter.clearListeners()}};const ye={aggressive:{prefetchPages:0,maxPages:1},balanced:{prefetchPages:1,maxPages:5},conservative:{prefetchPages:2,maxPages:10}},T=(e,t)=>e===void 0?t:Number.isFinite(e)&&e>0?Math.floor(e):t,be=(e,t)=>e===void 0?t:Number.isFinite(e)&&e>=0?Math.floor(e):t,E=e=>{let t=ye[e?.eviction??`balanced`];return{pageSize:T(e?.pageSize,100),prefetchPages:be(e?.prefetchPages,t.prefetchPages),maxPages:T(e?.maxPages,t.maxPages)}};var xe=class{options;cacheOptions;generation=0;hasKnownTotal=!1;loadedBlocks=new Set;pendingBlocks=new Map;constructor(e,t){this.options=e,this.cacheOptions=E(t)}configure(e){this.cacheOptions=E(e)}getPageSize(){return this.cacheOptions.pageSize}reset(){this.generation+=1,this.hasKnownTotal=!1,this.loadedBlocks.clear(),this.pendingBlocks.clear(),this.options.getCachedRows().clear()}hasMissingRows(e){if(e.endRow<=e.startRow)return!1;let t=this.options.getTotalRows();if(this.hasKnownTotal&&t===0||this.hasKnownTotal&&e.startRow>=t)return!1;let n=this.hasKnownTotal?Math.min(e.endRow,t):e.endRow,r=this.options.getCachedRows();for(let t=e.startRow;t<n;t+=1)if(!r.has(t))return!0;return!1}async loadRange(e,t=!1){t&&this.reset();let n=this.generation,r=this.options.getTotalRows(),i=this.getBlocksForRange(e).map(e=>this.getOrCreateBlockRequest(e,n)).filter(e=>e!==null);return i.length>0&&await Promise.all(i),n===this.generation?(this.evictAround(e),{applied:!0,loadedBlockCount:i.length,totalRowsChanged:r!==this.options.getTotalRows()}):{applied:!1,loadedBlockCount:0,totalRowsChanged:!1}}getOrCreateBlockRequest(e,t){if(this.loadedBlocks.has(e))return null;let n=this.pendingBlocks.get(e);if(n)return n;let r=this.fetchBlock(e,t);return this.pendingBlocks.set(e,r),r.then(()=>this.deletePendingBlock(e,r),()=>this.deletePendingBlock(e,r)),r}deletePendingBlock(e,t){this.pendingBlocks.get(e)===t&&this.pendingBlocks.delete(e)}async fetchBlock(e,t){let n=e*this.cacheOptions.pageSize,r=this.getBlockEndRow(e),i;try{i=await this.options.getDataSource().fetch(b({range:{startRow:n,endRow:r},sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),columns:this.options.getColumns()}))}catch(e){if(t===this.generation)throw e;return}t===this.generation&&this.applyBlockResponse(e,i.rows,i.totalRows)}applyBlockResponse(e,t,n){let r=this.options.getCachedRows(),i=this.options.getTotalRows();this.deleteRowsForBlock(e);let a=e*this.cacheOptions.pageSize;t.forEach((e,t)=>{e!==void 0&&r.set(a+t,e)}),this.options.setTotalRows(n),this.hasKnownTotal=!0,this.loadedBlocks.add(e),n<i&&this.deleteRowsAfterTotal(n)}getBlocksForRange(e){if(e.endRow<=e.startRow)return[];let t=this.options.getTotalRows();if(this.hasKnownTotal&&t===0||this.hasKnownTotal&&e.startRow>=t)return[];let n=this.hasKnownTotal?Math.min(e.endRow,t):e.endRow,r=this.cacheOptions.pageSize,i=Math.floor(e.startRow/r),a=Math.floor((n-1)/r),o=Math.max(0,i-this.cacheOptions.prefetchPages),s=this.getLastPrefetchBlock(a),c=[];for(let e=o;e<=s;e+=1)c.push(e);return c}getLastPrefetchBlock(e){let t=this.options.getTotalRows(),n=e+this.cacheOptions.prefetchPages;if(this.hasKnownTotal&&t>0){let e=Math.floor((t-1)/this.cacheOptions.pageSize);return Math.min(n,e)}return n}getBlockEndRow(e){let t=e*this.cacheOptions.pageSize+this.cacheOptions.pageSize,n=this.options.getTotalRows();return this.hasKnownTotal&&n>0?Math.min(t,n):t}evictAround(e){if(this.loadedBlocks.size<=this.cacheOptions.maxPages)return;let t=new Set(this.getBlocksForRange(e)),n=Math.floor(e.startRow/this.cacheOptions.pageSize),r=[...this.loadedBlocks].filter(e=>t.has(e)===!1).sort((e,t)=>Math.abs(t-n)-Math.abs(e-n));for(let e of r){if(this.loadedBlocks.size<=this.cacheOptions.maxPages)return;this.loadedBlocks.delete(e),this.deleteRowsForBlock(e)}}deleteRowsForBlock(e){let t=this.options.getCachedRows(),n=e*this.cacheOptions.pageSize,r=n+this.cacheOptions.pageSize;for(let e=n;e<r;e+=1)t.delete(e)}deleteRowsAfterTotal(e){let t=this.options.getCachedRows();for(let n of t.keys())n>=e&&t.delete(n)}};const D=e=>{e.computeColumnPositions(),e.batcher.start();try{e.emitContentSize(),e.emitHeaders(),e.batcher.emit({type:`COLUMNS_CHANGED`,columns:[...e.columns]}),e.refreshSlots===`sync`?e.slotPool.syncSlots():e.slotPool.refreshAllSlots()}finally{e.batcher.flush()}e.onComplete()},Se=(e,t,n)=>{let r=n.columns[e];r&&(r.width=t,D({...n,refreshSlots:`sync`}))},Ce=(e,t,n)=>{if(e===t||e<0||e>=n.columns.length)return null;let r=t>e?t-1:t;if(r<0||r>=n.columns.length||e===r)return null;let[i]=n.columns.splice(e,1);return n.columns.splice(r,0,i),D({...n,refreshSlots:`all`}),r},we=(e,t,n)=>{let r=n.dataSource;if(!r.moveRow)return;r.moveRow(e,t),oe(n.cachedRows,e,t),n.highlight?.clearAllCaches();let i=Math.min(e,t),a=Math.max(e,t);for(let e=i;e<=a;e++)n.slotPool.updateSlot(e)},Te=async e=>{let t=await e.dataSource.fetch(b({range:{startRow:0,endRow:2**53-1},sortModel:e.sortModel,filterModel:e.filterModel,columns:e.getColumns()}));e.cachedRows.clear();for(let n=0;n<t.rows.length;n++){let r=t.rows[n];r!==void 0&&e.cachedRows.set(n,r)}return e.setTotalRows(t.totalRows),{totalRows:t.totalRows}};var O=class{dataSource;options;rowLoading;rowWindowLoader;cachedRows=new Map;totalRows=0;isDataLoading=!1;constructor(e){this.options=e,this.dataSource=e.dataSource,this.rowLoading=e.rowLoading??{},this.rowWindowLoader=new xe({getDataSource:()=>this.dataSource,getCachedRows:()=>this.cachedRows,getTotalRows:()=>this.totalRows,setTotalRows:e=>{this.totalRows=e},getSortModel:e.getSortModel,getFilterModel:e.getFilterModel,getColumns:e.getColumns},this.rowLoading.cache)}getCachedRows(){return this.cachedRows}setCachedRows(e){this.cachedRows=e}getTotalRows(){return this.totalRows}setTotalRows(e){this.totalRows=e}getDataSource(){return this.dataSource}getRowData(e){return this.cachedRows.get(e)}isLoading(){return this.isDataLoading}getCellValue(e,t){return ce(this.cachedRows,this.options.getColumns(),e,t)}setCellValue(e,t,n){le(this.cachedRows,this.options.getColumns(),e,t,n,{onCellValueChanged:this.options.onCellValueChanged,getRowId:this.options.getRowId})}async loadInitial(){if(this.isPaginatedLoading()){await this.fetchPaginatedData({range:this.getInitialPaginatedRange(),resetCache:!0,showLoading:!0,refreshSlots:!1});return}await this.fetchAllData()}requestVisibleRows(){if(this.isPaginatedLoading()===!1)return;let e=this.getPaginatedLoadRange(!0);if(e.endRow<=e.startRow)return;let t=this.getPaginatedLoadRange(!1),n=this.rowWindowLoader.hasMissingRows(t);this.fetchPaginatedData({range:e,resetCache:!1,showLoading:n,refreshSlots:!0})}async refreshFromTransaction(){if(this.isPaginatedLoading()){await this.fetchPaginatedData({range:this.getPaginatedLoadRange(!0),resetCache:!0,showLoading:!1,refreshSlots:!1});return}await Te({dataSource:this.dataSource,sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),cachedRows:this.cachedRows,setTotalRows:e=>{this.totalRows=e},getColumns:this.options.getColumns})}setDataSource(e){this.dataSource=e,this.rowWindowLoader.reset(),this.totalRows=0}destroy(){this.rowWindowLoader.reset(),this.cachedRows.clear(),this.totalRows=0,this.isDataLoading=!1}async fetchAllData(){this.isDataLoading=!0,this.options.batcher.emit({type:`DATA_LOADING`});try{let e=b({range:{startRow:0,endRow:2**53-1},sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),columns:this.options.getColumns()}),t=await this.dataSource.fetch(e);this.cachedRows.clear(),t.rows.forEach((e,t)=>{this.cachedRows.set(t,e)}),this.totalRows=t.totalRows,this.options.batcher.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emitDataError(e)}finally{this.isDataLoading=!1}}async fetchPaginatedData(e){e.showLoading&&(this.isDataLoading=!0,this.options.batcher.emit({type:`DATA_LOADING`}));try{let t=await this.rowWindowLoader.loadRange(e.range,e.resetCache);if(t.applied===!1)return;(e.showLoading||t.totalRowsChanged)&&this.options.batcher.emit({type:`DATA_LOADED`,totalRows:this.totalRows}),e.refreshSlots&&(this.options.syncSlots(),this.options.emitVisibleRange(),t.totalRowsChanged&&this.options.emitContentSize())}catch(e){this.emitDataError(e)}finally{e.showLoading&&(this.isDataLoading=!1)}}emitDataError(e){this.options.batcher.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}isPaginatedLoading(){let e=this.rowLoading.mode??`auto`;return e===`paginated`?!0:e===`all`?!1:this.dataSource.loadMode===`paginated`}getInitialPaginatedRange(){let e=this.getPaginatedLoadRange(!0);return{startRow:0,endRow:Math.max(this.rowWindowLoader.getPageSize(),e.endRow)}}getPaginatedLoadRange(e){let t=this.options.getRowHeight(),n=this.options.getViewportHeight(),r=this.options.getScrollTop(),i=e?this.options.getOverscan():0,a=Math.max(0,Math.floor(r/t)-i),o=Math.ceil((r+n)/t)+i+1,s=this.totalRows>0?Math.min(this.totalRows,o):o;return{startRow:a,endRow:Math.max(a,s)}}};const k=1e7;var A=class{naturalContentHeight=0;virtualContentHeight=0;scrollRatio=1;options;constructor(e){this.options=e}updateContentSize(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight(),r=this.options.getViewportHeight(),i=e*t;if(this.naturalContentHeight=i+n,this.naturalContentHeight>k){this.virtualContentHeight=k;let e=this.virtualContentHeight-n-r,a=Math.ceil((i-r)/t)*t;this.scrollRatio=a>0?e/a:1}else this.virtualContentHeight=this.naturalContentHeight,this.scrollRatio=1;return{naturalHeight:this.naturalContentHeight,virtualHeight:this.virtualContentHeight,scrollRatio:this.scrollRatio}}isScalingActive(){return this.scrollRatio<1}getNaturalHeight(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight();return this.naturalContentHeight||e*t+n}getVirtualHeight(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight();return this.virtualContentHeight||e*t+n}getScrollRatio(){return this.scrollRatio}getVisibleRowRange(){let e=this.options.getViewportHeight(),t=this.options.getScrollTop(),n=this.options.getRowHeight(),r=this.options.getTotalRows(),i=e,a=Math.max(0,Math.floor(t/n)),o=Math.min(r-1,Math.ceil((t+i)/n)-1);return{start:a,end:Math.max(a,o)}}getScrollTopForRow(e){return e*this.options.getRowHeight()*this.scrollRatio}getRowIndexAtDisplayY(e,t){let n=this.options.getRowHeight(),r=e+(this.scrollRatio<1?t/this.scrollRatio:t);return Math.floor(r/n)}getVirtualContentHeight(){return this.virtualContentHeight}},j=class{options;emitter=v();sortModel=[];filterModel={};openFilterColIndex=null;onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}async setSort(e,t,n=!1){if(!this.options.isSortingEnabled()||this.options.getColumns().find(t=>(t.colId??t.field)===e)?.sortable===!1)return;let r=this.sortModel.findIndex(t=>t.colId===e);n?t===null&&r>=0?this.sortModel.splice(r,1):r>=0?this.sortModel[r].direction=t:this.sortModel.push({colId:e,direction:t}):this.sortModel=t===null?[]:[{colId:e,direction:t}],await this.options.onSortFilterChange(),this.options.onDataRefreshed()}getSortModel(){return[...this.sortModel]}async setFilter(e,t){this.options.getColumns().find(t=>(t.colId??t.field)===e)?.filterable!==!1&&(t===null||typeof t==`string`&&t.trim()===``||typeof t==`object`&&t.conditions?.length===0?delete this.filterModel[e]:typeof t==`string`?this.filterModel[e]={conditions:[{type:`text`,operator:`contains`,value:t}],combination:`and`}:this.filterModel[e]=t,await this.options.onSortFilterChange(),this.options.onDataRefreshed())}getFilterModel(){return{...this.filterModel}}hasActiveFilter(e){let t=this.filterModel[e];return t?t.conditions.length>0:!1}isColumnSortable(e){return this.options.isSortingEnabled()?this.options.getColumns()[e]?.sortable!==!1:!1}isColumnFilterable(e){return this.options.getColumns()[e]?.filterable!==!1}getDistinctValuesForColumn(e,t=500,n=1e5){let r=this.options.getColumns().find(t=>(t.colId??t.field)===e);if(!r)return[];let i=this.options.getCachedRows(),a=i.size,o=a>n?Math.ceil(a/n):1,s=r.valueFormatter,c=new Map;for(let e=0;e<a;e+=o){let n=i.get(e);if(n===void 0)continue;let a=g(n,r.field),[o,l]=this.normalizeDistinctValue(a,s);if(!c.has(o)&&(c.set(o,l),c.size>=t))break}let l=Array.from(c.values());return l.sort((e,t)=>{let n=y(e,s),r=y(t,s);return n.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})}),l}normalizeDistinctValue(e,t){if(Array.isArray(e)){let n=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1});return[t?t(n):JSON.stringify(n),n]}return[t?t(e):JSON.stringify(e),e]}openFilterPopup(e,t){if(this.openFilterColIndex===e){this.closeFilterPopup();return}let n=this.options.getColumns()[e];if(!n||!this.isColumnFilterable(e))return;let r=n.colId??n.field,i=this.getDistinctValuesForColumn(r);this.openFilterColIndex=e,this.emit({type:`OPEN_FILTER_POPUP`,colIndex:e,column:n,anchorRect:t,distinctValues:i,currentFilter:this.filterModel[r]})}closeFilterPopup(){this.openFilterColIndex=null,this.emit({type:`CLOSE_FILTER_POPUP`})}getSortInfoMap(){let e=new Map;return this.sortModel.forEach((t,n)=>{e.set(t.colId,{direction:t.direction,index:n+1})}),e}destroy(){this.emitter.clearListeners(),this.sortModel=[],this.filterModel={},this.openFilterColIndex=null}},M=class{queue=[];debounceTimer=null;pendingPromise=null;options;constructor(e){this.options=e}add(e){e.length!==0&&(this.queue.push({type:`ADD`,rows:e}),this.scheduleProcessing())}remove(e){e.length!==0&&(this.queue.push({type:`REMOVE`,rowIds:e}),this.scheduleProcessing())}updateCell(e,t,n){this.queue.push({type:`UPDATE_CELL`,rowId:e,field:t,value:n}),this.scheduleProcessing()}updateRow(e,t){Object.keys(t).length!==0&&(this.queue.push({type:`UPDATE_ROW`,rowId:e,data:t}),this.scheduleProcessing())}flush(){return this.queue.length===0?Promise.resolve():(this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise?new Promise((e,t)=>{let n=this.pendingPromise,r=n.resolve,i=n.reject;n.resolve=()=>{r(),e()},n.reject=e=>{i(e),t(e)}}):new Promise((e,t)=>{this.pendingPromise={resolve:e,reject:t},this.processQueue()}))}hasPending(){return this.queue.length>0}getPendingCount(){return this.queue.length}clear(){this.queue=[],this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}scheduleProcessing(){if(this.options.debounceMs===0){this.processQueue();return}this.debounceTimer===null&&(this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.processQueue()},this.options.debounceMs))}processQueue(){if(this.queue.length===0){this.pendingPromise&&=(this.pendingPromise.resolve(),null);return}let e=this.queue;this.queue=[];let t={added:0,removed:0,updated:0};try{for(let n of e)switch(n.type){case`ADD`:this.options.store.addRows(n.rows),t.added+=n.rows.length;break;case`REMOVE`:t.removed+=this.options.store.removeRows(n.rowIds);break;case`UPDATE_CELL`:this.options.store.updateCell(n.rowId,n.field,n.value),t.updated++;break;case`UPDATE_ROW`:this.options.store.updateRow(n.rowId,n.data),t.updated++;break}this.options.onProcessed&&this.options.onProcessed(t),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}catch(e){this.pendingPromise&&=(this.pendingPromise.reject(e instanceof Error?e:Error(String(e))),null)}}},Ee=class{listeners=[];buffer=null;subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}start(){this.buffer=[]}flush(){let e=this.buffer;if(this.buffer=null,e!==null&&e.length>0)for(let t of this.listeners)t(e)}emit(e){if(this.buffer!==null){this.buffer.push(e);return}this.notify([e])}emitBatch(e){if(e.length!==0){if(this.buffer!==null){this.buffer.push(...e);return}this.notify(e)}}clearListeners(){this.listeners=[]}notify(e){for(let t of this.listeners)t(e)}},De=class{scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;getScrollRatio;constructor(e){this.getScrollRatio=e}getScrollTop(){return this.scrollTop}getScrollLeft(){return this.scrollLeft}getViewportWidth(){return this.viewportWidth}getViewportHeight(){return this.viewportHeight}resetScrollTop(){this.scrollTop=0}update(e,t,n,r){let i=this.getScrollRatio(),a=i<1?e/i:e,o=this.viewportWidth!==n||this.viewportHeight!==r,s=this.scrollTop!==a||this.scrollLeft!==t||o;return s&&(this.scrollTop=a,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r),{changed:s,viewportSizeChanged:o}}};const N=e=>e.replaceAll(`\r
1
+ const e=(e,t,n,r,i)=>{let a=0,o=0;return e<40+i?o=-10:e>n-40&&(o=10),t<40?a=-10:t>r-40&&(a=10),a!==0||o!==0?{dx:a,dy:o}:null};var t=class{active=!1;colIndex=-1;startX=0;initialWidth=0;currentWidth=0;core;constructor(e){this.core=e}get isActive(){return this.active}start(e,t,n){return n.button!==0||this.core.getColumns()[e]?.resizable===!1?{preventDefault:!1,stopPropagation:!1}:(this.active=!0,this.colIndex=e,this.startX=n.clientX,this.initialWidth=t,this.currentWidth=t,{preventDefault:!0,stopPropagation:!0,startDrag:`column-resize`})}move(e,t){let n=this.core.getColumns()[this.colIndex],r=n?.minWidth??50,i=n?.maxWidth,a=this.initialWidth+(e.clientX-this.startX);a=Math.max(r,a),i!==void 0&&(a=Math.min(i,a)),this.currentWidth=a;let o=e.clientX-t.left>t.width-40?10:0,s=o===0?null:{dx:o,dy:0};return{targetRow:0,targetCol:this.colIndex,autoScroll:s}}end(){this.active&&this.core.setColumnWidth(this.colIndex,this.currentWidth),this.active=!1,this.colIndex=-1}getState(){return this.active===!1?null:{colIndex:this.colIndex,initialWidth:this.initialWidth,currentWidth:this.currentWidth}}};const n=e=>{let t=[0],n=0;for(let r of e)n+=r.width,t.push(n);return t},r=e=>e.at(-1)??0,i=(e,t)=>{let i=n(e),a=r(i);if(t<=a||a===0)return{positions:i,widths:e.map(e=>e.width)};let o=t/a,s=e.map(e=>e.width*o),c=[0],l=0;for(let e of s)l+=e,c.push(l);return{positions:c,widths:s}},a=(e,t)=>{for(let n=0;n<t.length-1;n++)if(e>=t[n]&&e<t[n+1])return n;return e>=t.at(-1)?t.length-2:0},o=e=>({minRow:Math.min(e.startRow,e.endRow),maxRow:Math.max(e.startRow,e.endRow),minCol:Math.min(e.startCol,e.endCol),maxCol:Math.max(e.startCol,e.endCol)}),s=(e,t,n)=>e>=n.minRow&&e<=n.maxRow&&t>=n.minCol&&t<=n.maxCol,c=(e,t,n)=>n?s(e,t,o(n)):!1,l=(e,t,n)=>n?.row===e&&n?.col===t,u=(e,t)=>!t||t.end<0||t.start>t.end?!0:e>=t.start&&e<=t.end,d=(e,t,n)=>n?.row===e&&n?.col===t,f=(e,t,n,r,i)=>{if(!n||!r||!i)return!1;let{minRow:a,maxRow:s,minCol:c,maxCol:l}=o(r),u=i.row>s,d=i.row<a;return u?e>s&&e<=i.row&&t>=c&&t<=l:d?e<a&&e>=i.row&&t>=c&&t<=l:!1},p=(e,t,n,r)=>{let i=[`gp-grid-cell`];return e&&i.push(`gp-grid-cell--active`),t&&!e&&i.push(`gp-grid-cell--selected`),n&&i.push(`gp-grid-cell--editing`),r&&i.push(`gp-grid-cell--fill-preview`),i.join(` `)},m=(e,t)=>{if(!t)return!1;let{minRow:n,maxRow:r}=o(t);return e>=n&&e<=r},h=(e,t)=>{if(!t)return!1;let{minCol:n,maxCol:r}=o(t);return e>=n&&e<=r};function g(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}function _(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];if(typeof i!=`object`||!i)return;i=i[t]}typeof i==`object`&&i&&(i[r.at(-1)]=n)}const v=()=>{let e=[];return{onInstruction:t=>(e.push(t),()=>{e=e.filter(e=>e!==t)}),emit:t=>{for(let n of e)n(t)},clearListeners:()=>{e=[]}}},ee=()=>{let e=v(),t=[];return{onInstruction:e.onInstruction,onBatchInstruction:e=>(t.push(e),()=>{t=t.filter(t=>t!==e)}),emit:n=>{e.emit(n);for(let e of t)e([n])},emitBatch:n=>{if(n.length!==0){for(let e of t)e(n);for(let t of n)e.emit(t)}},clearListeners:()=>{e.clearListeners(),t=[]}}},te=(e,t)=>{for(let n of e.values())if(n.rowIndex===t)return n;return null},ne=(e,t,n,r,i,a=0)=>{let o=te(i,n);if(!o){t.scrollTop=e.getScrollTopForRow(n);return}let s=a+o.translateY-t.scrollTop,c=s+r;if(s<0)t.scrollTop=e.getScrollTopForRow(n);else if(c>t.clientHeight){let i=Math.floor(t.clientHeight/r),a=Math.max(0,n-i+1);t.scrollTop=e.getScrollTopForRow(a)}},y=(e,t)=>e==null?``:t?t(e):Array.isArray(e)?e.join(`, `):typeof e==`object`?e instanceof Date?String(e):JSON.stringify(e):String(e),re=e=>{let{activeCell:t,selectionRange:n,slots:r,columns:i,visibleColumnsWithIndices:a,columnPositions:o,columnWidths:s,rowHeight:c}=e;if(!t&&!n)return null;let l,u,d,f;if(n)l=Math.max(n.startRow,n.endRow),u=Math.max(n.startCol,n.endCol),d=Math.min(n.startCol,n.endCol),f=Math.max(n.startCol,n.endCol);else if(t)l=t.row,u=t.col,d=u,f=u;else return null;for(let e=d;e<=f;e++){let t=i[e];if(!(!t||t.hidden)&&t.editable!==!0)return null}let p=a.findIndex(e=>e.originalIndex===u);if(p===-1)return null;let m=null;for(let e of r.values())if(e.rowIndex===l){m=e.translateY;break}if(m===null)return null;let h=o[p]??0,g=s[p]??0;return{top:m+c-5,left:h+g-20}},ie=(e,t,n=8)=>{let r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=r.bottom+4,o=r.left,s=Math.max(200,r.width);return o+i.width>window.innerWidth-n&&(o=window.innerWidth-i.width-n),o=Math.max(n,o),a+i.height>window.innerHeight-n&&(a=r.top-i.height-4),a=Math.max(n,a),{top:a,left:o,minWidth:s}},ae=e=>{if(!e||e.length===0)return;let t={};for(let n of e)n.valueFormatter&&(t[n.colId??n.field]=n.valueFormatter);return Object.keys(t).length>0?t:void 0},b=e=>({range:e.range,sort:e.sortModel.length>0?e.sortModel:void 0,filter:Object.keys(e.filterModel).length>0?e.filterModel:void 0,valueFormatters:ae(e.columns)}),oe=(e,t,n)=>{let r=e.get(t);if(r!==void 0){if(t<n){let i=n-1;for(let n=t;n<i;n++){let t=e.get(n+1);t===void 0?e.delete(n):e.set(n,t)}e.set(i,r);return}for(let r=t;r>n;r--){let t=e.get(r-1);t===void 0?e.delete(r):e.set(r,t)}e.set(n,r)}},se=e=>{let t=[0],n=0;for(let r of e)r.hidden||(n+=r.width,t.push(n));return t},ce=(e,t,n,r)=>{let i=e.get(n);if(!i)return null;let a=t[r];return a?g(i,a.field):null},le=(e,t,n,r,i,a)=>{let o=e.get(n);if(!o||typeof o!=`object`)return;let s=t[r];if(!s)return;let c=a.onCellValueChanged!==void 0,l=c?g(o,s.field):void 0;_(o,s.field,i),c&&a.onCellValueChanged({rowId:a.getRowId(o),colIndex:r,field:s.field,oldValue:l,newValue:i,rowData:o})};var ue=class{active=!1;sourceColIndex=-1;startX=0;startY=0;thresholdMet=!1;shiftKey=!1;ghostWidth=0;ghostHeight=0;currentX=0;currentY=0;dropTargetIndex=null;core;deps;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps=e}get isActive(){return this.active}get isDraggingForDisplay(){return this.active&&this.thresholdMet}start(e,t,n,r){return r.button!==0||this.core.getColumns()[e]?.movable===!1?{preventDefault:!1,stopPropagation:!1}:(this.active=!0,this.sourceColIndex=e,this.startX=r.clientX,this.startY=r.clientY,this.thresholdMet=!1,this.shiftKey=r.shiftKey,this.ghostWidth=t,this.ghostHeight=n,this.currentX=r.clientX,this.currentY=r.clientY,this.dropTargetIndex=null,{preventDefault:!0,stopPropagation:!0,startDrag:`column-move`})}move(e,t){let n=e.clientX-this.startX,r=e.clientY-this.startY;if(this.thresholdMet===!1){if(!(Math.abs(n)>5||Math.abs(r)>5))return null;this.thresholdMet=!0}this.currentX=e.clientX,this.currentY=e.clientY;let{left:i,width:o,scrollLeft:s}=t,c=e.clientX-i+s,l=this.deps.getColumnPositions(),u=this.deps.getColumnCount();this.dropTargetIndex=Math.max(0,Math.min(a(c,l),u));let d=e.clientX-i,f=0;d<40?f=-10:d>o-40&&(f=10);let p=f===0?null:{dx:f,dy:0};return{targetRow:0,targetCol:this.dropTargetIndex??0,autoScroll:p}}end(e){this.thresholdMet?this.commitMove():this.treatAsHeaderClick(e),this.reset()}commitMove(){if(this.dropTargetIndex===null)return;let e=this.sourceColIndex,t=this.deps.getOriginalColumnIndex?this.deps.getOriginalColumnIndex(Math.min(this.dropTargetIndex,this.deps.getColumnCount()-1)):this.dropTargetIndex;e!==t&&this.core.moveColumn(e,t)}treatAsHeaderClick(e){let t=this.core.getColumns()[this.sourceColIndex];if(!t)return;let n=t.colId??t.field,r=this.core.getSortModel().find(e=>e.colId===n)?.direction;this.core.setSort(n,e(r),this.shiftKey)}reset(){this.active=!1,this.sourceColIndex=-1,this.thresholdMet=!1,this.shiftKey=!1,this.dropTargetIndex=null}getState(){return this.active===!1?null:{sourceColIndex:this.sourceColIndex,currentX:this.currentX,currentY:this.currentY,dropTargetIndex:this.dropTargetIndex,ghostWidth:this.ghostWidth,ghostHeight:this.ghostHeight}}},de=class{active=!1;sourceRowIndex=-1;startX=0;startY=0;thresholdMet=!1;currentX=0;currentY=0;dropTargetIndex=null;core;deps;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps=e}get isActive(){return this.active}get isDraggingForDisplay(){return this.active&&this.thresholdMet}start(e,t,n){this.active=!0,this.sourceRowIndex=e,this.startX=t,this.startY=n,this.thresholdMet=!1,this.currentX=t,this.currentY=n,this.dropTargetIndex=null}move(t,n){let r=t.clientX-this.startX,i=t.clientY-this.startY;if(this.thresholdMet===!1){if(!(Math.abs(r)>5||Math.abs(i)>5))return null;this.thresholdMet=!0}this.currentX=t.clientX,this.currentY=t.clientY;let{top:a,left:o,height:s,width:c,scrollTop:l}=n,u=this.deps.getHeaderHeight(),d=t.clientY-a,f=this.core.getRowCount(),p=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(d,l),f));return this.dropTargetIndex=p,{targetRow:p,targetCol:0,autoScroll:e(t.clientY-a,t.clientX-o,s,c,u)}}end(){this.thresholdMet&&this.dropTargetIndex!==null&&this.dropTargetIndex!==this.sourceRowIndex&&this.core.commitRowDrag(this.sourceRowIndex,this.dropTargetIndex),this.active=!1,this.sourceRowIndex=-1,this.thresholdMet=!1,this.dropTargetIndex=null}getState(){return this.active===!1?null:{sourceRowIndex:this.sourceRowIndex,currentX:this.currentX,currentY:this.currentY,dropTargetIndex:this.dropTargetIndex,dropIndicatorY:this.dropTargetIndex===null?0:this.core.getRowTranslateY(this.dropTargetIndex)}}},fe=class{active=!1;core;constructor(e){this.core=e}get isActive(){return this.active}start(){this.active=!0}moveToTarget(e,t){this.active!==!1&&this.core.selection.startSelection({row:e,col:t},{shift:!0})}end(){this.active=!1}},pe=class{active=!1;sourceRange=null;target=null;core;constructor(e){this.core=e}get isActive(){return this.active}get stateSnapshot(){return{sourceRange:this.sourceRange,target:this.target}}start(e,t){if(!e&&!t)return{preventDefault:!1,stopPropagation:!1};let n=t??{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};return this.core.fill.startFillDrag(n),this.sourceRange=n,this.target={row:Math.max(n.startRow,n.endRow),col:Math.max(n.startCol,n.endCol)},this.active=!0,{preventDefault:!0,stopPropagation:!0,startDrag:`fill`}}moveToTarget(e,t){this.active!==!1&&(this.core.fill.updateFillDrag(e,t),this.target={row:e,col:t})}end(){this.active&&(this.core.fill.commitFillDrag(),this.core.refreshSlotData()),this.active=!1,this.sourceRange=null,this.target=null}},me=class{record=null;set(e){this.record=e}clear(){this.record=null}consume(){let e=this.record;return this.record=null,e}};const he=e=>{switch(e){case`ArrowUp`:return`up`;case`ArrowDown`:return`down`;case`ArrowLeft`:return`left`;case`ArrowRight`:return`right`;default:return null}};var ge=class{core;constructor(e){this.core=e}handle(e,t,n,r){if(r||n!==null&&e.key!==`Enter`&&e.key!==`Escape`&&e.key!==`Tab`)return{preventDefault:!1};let i=he(e.key);if(i!==null)return this.moveFocus(i,e.shiftKey);let a=e.ctrlKey||e.metaKey;return this.handleAction(e.key,t,n,e.shiftKey,a)}moveFocus(e,t){let{selection:n}=this.core;return n.moveFocus(e,t),{preventDefault:!0,scrollToCell:n.getActiveCell()??void 0}}handleAction(e,t,n,r,i){switch(e){case`Enter`:return this.handleEnter(t,n);case`Escape`:return this.handleEscape(n);case`Tab`:return this.handleTab(n,r);default:return this.handleNonSpecialKey(e,t,n,i)}}handleEnter(e,t){return t?this.core.commitEdit():e&&this.core.startEdit(e.row,e.col),{preventDefault:!0}}handleEscape(e){return e?this.core.cancelEdit():this.core.selection.clearSelection(),{preventDefault:!0}}handleTab(e,t){return e&&this.core.commitEdit(),this.core.selection.moveFocus(t?`left`:`right`,!1),{preventDefault:!0}}handleNonSpecialKey(e,t,n,r){let{selection:i}=this.core;return e===`a`&&r?(i.selectAll(),{preventDefault:!0}):e===`c`&&r?(i.copySelectionToClipboard(),{preventDefault:!0}):e===`F2`?(t&&!n&&this.core.startEdit(t.row,t.col),{preventDefault:!0}):e===`Delete`||e===`Backspace`?t&&!n?(this.core.startEdit(t.row,t.col),{preventDefault:!0}):{preventDefault:!1}:(t&&!n&&!r&&e.length===1&&this.core.startEdit(t.row,t.col),{preventDefault:!1})}};const _e=(t,n,r,i)=>{let{top:o,left:s,width:c,height:l,scrollTop:u,scrollLeft:d}=i,f=n.getColumnPositions(),p=n.getColumnCount(),m=r.clientY-o,h=r.clientX-s+d,g=Math.max(0,Math.min(t.getRowIndexAtDisplayY(m,u),t.getRowCount()-1)),_=Math.max(0,Math.min(a(h,f),p-1));return{row:g,col:n.getOriginalColumnIndex?n.getOriginalColumnIndex(_):_,autoScroll:e(r.clientY-o,r.clientX-s,l,c,n.getHeaderHeight())}},x=e=>e==null?`asc`:e===`asc`?`desc`:null;var S=class{core;deps;columnResize;columnMove;rowDrag;selectionDrag;fillDrag;pendingRowDrag=new me;keyboard;constructor(e,n){this.core=e,this.deps=n,this.columnResize=new t(e),this.columnMove=new ue(e,n),this.rowDrag=new de(e,n),this.selectionDrag=new fe(e),this.fillDrag=new pe(e),this.keyboard=new ge(e)}updateDeps(e){this.deps={...this.deps,...e},this.columnMove.updateDeps(this.deps),this.rowDrag.updateDeps(this.deps)}getDragState(){let e=this.getDragType(),t=this.fillDrag.stateSnapshot;return{isDragging:e!==null,dragType:e,fillSourceRange:t.sourceRange,fillTarget:t.target,columnResize:this.columnResize.getState(),columnMove:this.columnMove.getState(),rowDrag:this.rowDrag.getState()}}getDragType(){return this.fillDrag.isActive?`fill`:this.columnResize.isActive?`column-resize`:this.columnMove.isDraggingForDisplay?`column-move`:this.rowDrag.isDraggingForDisplay?`row-drag`:this.selectionDrag.isActive?`selection`:null}handleHeaderMouseDown(e,t,n,r){return this.columnMove.start(e,t,n,r)}handleHeaderResizeMouseDown(e,t,n){return this.columnResize.start(e,t,n)}handleCellMouseDown(e,t,n){if(n.button!==0||this.core.getEditState()!==null)return ve;let r=(this.core.getColumns()[t]?.rowDrag===!0||this.core.isRowDragEntireRow())&&!n.shiftKey;return r&&n.pointerType===`touch`?this.startPendingRowDrag(e,t,n):r?this.startRowDrag(e,t,n):this.startSelectionClick(e,t,n)}startPendingRowDrag(e,t,n){return this.pendingRowDrag.set({rowIndex:e,colIndex:t,clientX:n.clientX,clientY:n.clientY}),this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:`row-drag-pending`}}startRowDrag(e,t,n){return this.rowDrag.start(e,n.clientX,n.clientY),this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!0,stopPropagation:!0,focusContainer:!0,startDrag:`row-drag`}}startSelectionClick(e,t,n){return this.core.selection.startSelection({row:e,col:t},{shift:n.shiftKey,ctrl:n.ctrlKey||n.metaKey}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:n.shiftKey?void 0:`selection`}}handleCellDoubleClick(e,t){this.core.startEdit(e,t)}handleCellMouseEnter(e,t){this.core.highlight?.setHoverPosition({row:e,col:t})}handleCellMouseLeave(){this.core.highlight?.setHoverPosition(null)}handleFillHandleMouseDown(e,t,n){return this.fillDrag.start(e,t)}handleHeaderClick(e,t){let n=this.core.getSortModel().find(t=>t.colId===e)?.direction;this.core.setSort(e,x(n),t)}startSelectionDrag(){this.selectionDrag.start()}confirmPendingRowDrag(){let e=this.pendingRowDrag.consume();return e===null?!1:(this.rowDrag.start(e.rowIndex,e.clientX,e.clientY),!0)}cancelPendingRowDrag(){this.pendingRowDrag.clear()}handleDragMove(e,t){return this.columnResize.isActive?this.columnResize.move(e,t):this.columnMove.isActive?this.columnMove.move(e,t):this.rowDrag.isActive?this.rowDrag.move(e,t):this.selectionFillMove(e,t)}selectionFillMove(e,t){if((this.selectionDrag.isActive||this.fillDrag.isActive)===!1)return null;let n=_e(this.core,this.deps,e,t);return this.selectionDrag.moveToTarget(n.row,n.col),this.fillDrag.moveToTarget(n.row,n.col),{targetRow:n.row,targetCol:n.col,autoScroll:n.autoScroll}}handleDragEnd(){if(this.columnResize.isActive)return this.columnResize.end();if(this.columnMove.isActive)return this.columnMove.end(x);if(this.rowDrag.isActive)return this.rowDrag.end();this.selectionDrag.end(),this.fillDrag.end()}handleWheel(e,t,n){return this.core.isScalingActive()?{dy:e*n,dx:t*n}:null}handleKeyDown(e,t,n,r){return this.keyboard.handle(e,t,n,r)}};const ve={preventDefault:!1,stopPropagation:!1};var C=class{options;highlightingOptions;hoverPosition=null;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;rowClassCache=new Map;columnClassCache=new Map;cellClassCache=new Map;constructor(e,t={}){this.options=e,this.highlightingOptions=t}isEnabled(){return!!(this.highlightingOptions.computeRowClasses||this.highlightingOptions.computeColumnClasses||this.highlightingOptions.computeCellClasses)}updateOptions(e){this.highlightingOptions=e,this.clearAllCaches()}setHoverPosition(e){this.isEnabled()&&(this.hoverPosition?.row===e?.row&&this.hoverPosition?.col===e?.col||(this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear(),this.hoverPosition=e,this.emit({type:`SET_HOVER_POSITION`,position:e})))}getHoverPosition(){return this.hoverPosition}onSelectionChange(){this.clearAllCaches()}buildRowContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:e,colIndex:null,column:void 0,rowData:t,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.row===e,isActive:n?.row===e,isSelected:m(e,r)}}buildColumnContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:null,colIndex:e,column:t,rowData:void 0,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.col===e,isActive:n?.col===e,isSelected:h(e,r)}}buildCellContext(e,t,n,r){let i=this.options.getActiveCell(),a=this.options.getSelectionRange(),s=this.hoverPosition?.row===e&&this.hoverPosition?.col===t,c=!1;if(a){let{minRow:n,maxRow:r,minCol:i,maxCol:s}=o(a);c=e>=n&&e<=r&&t>=i&&t<=s}return{rowIndex:e,colIndex:t,column:n,rowData:r,hoverPosition:this.hoverPosition,activeCell:i,selectionRange:a,isHovered:s,isActive:i?.row===e&&i?.col===t,isSelected:c}}computeRowClasses(e,t){let n=this.highlightingOptions.computeRowClasses;if(!n)return[];let r=this.rowClassCache.get(e);if(r!==void 0)return r;let i=n(this.buildRowContext(e,t));return this.rowClassCache.set(e,i),i}computeColumnClasses(e,t){let n=this.columnClassCache.get(e);if(n!==void 0)return n;let r=this.buildColumnContext(e,t),i;if(t.computeColumnClasses)i=t.computeColumnClasses(r);else if(this.highlightingOptions.computeColumnClasses)i=this.highlightingOptions.computeColumnClasses(r);else return[];return this.columnClassCache.set(e,i),i}computeCellClasses(e,t,n,r){let i=`${e},${t}`,a=this.cellClassCache.get(i);if(a!==void 0)return a;let o=this.buildCellContext(e,t,n,r),s;if(n.computeCellClasses)s=n.computeCellClasses(o);else if(this.highlightingOptions.computeCellClasses)s=this.highlightingOptions.computeCellClasses(o);else return[];return this.cellClassCache.set(i,s),s}computeCombinedCellClasses(e,t,n,r){let i=this.computeColumnClasses(t,n),a=this.computeCellClasses(e,t,n,r);return[...i,...a]}clearAllCaches(){this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear()}destroy(){this.emitter.clearListeners(),this.clearAllCaches(),this.hoverPosition=null}},w=class{options;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getRow(e){return this.options.getCachedRows().get(e)}addRows(e,t){if(e.length===0)return;let n=this.options.getCachedRows(),r=this.options.getTotalRows(),i=t??r,a=r+e.length;if(i<r){let t=new Map;for(let[r,a]of n)r>=i?t.set(r+e.length,a):t.set(r,a);this.options.setCachedRows(t)}let o=this.options.getCachedRows();e.forEach((e,t)=>{o.set(i+t,e)}),this.options.setTotalRows(a);let s=e.map((e,t)=>i+t);this.emit({type:`ROWS_ADDED`,indices:s,count:s.length,totalRows:a}),this.options.emitContentSize(),this.options.refreshAllSlots()}updateRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=[];for(let r of e){let e=t.get(r.index);e&&(t.set(r.index,{...e,...r.data}),n.push(r.index))}if(n.length!==0){this.emit({type:`ROWS_UPDATED`,indices:n});for(let e of n)this.options.updateSlot(e)}}deleteRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=this.options.getTotalRows(),r=[...e].sort((e,t)=>t-e);for(let e of r){if(e<0||e>=n)continue;t.delete(e);let r=new Map;for(let[n,i]of t)n>e?r.set(n-1,i):r.set(n,i);this.options.setCachedRows(r),n--}this.options.setTotalRows(n),this.options.clearSelectionIfInvalid(n),this.emit({type:`ROWS_REMOVED`,indices:r,totalRows:n}),this.options.emitContentSize(),this.options.refreshAllSlots()}setRow(e,t){let n=this.options.getTotalRows();e<0||e>=n||(this.options.getCachedRows().set(e,t),this.emit({type:`ROWS_UPDATED`,indices:[e]}),this.options.updateSlot(e))}destroy(){this.emitter.clearListeners()}};const ye={aggressive:{prefetchPages:0,maxPages:1},balanced:{prefetchPages:1,maxPages:5},conservative:{prefetchPages:2,maxPages:10}},T=(e,t)=>e===void 0?t:Number.isFinite(e)&&e>0?Math.floor(e):t,be=(e,t)=>e===void 0?t:Number.isFinite(e)&&e>=0?Math.floor(e):t,E=e=>{let t=ye[e?.eviction??`balanced`];return{pageSize:T(e?.pageSize,100),prefetchPages:be(e?.prefetchPages,t.prefetchPages),maxPages:T(e?.maxPages,t.maxPages)}};var xe=class{options;cacheOptions;generation=0;hasKnownTotal=!1;loadedBlocks=new Set;pendingBlocks=new Map;constructor(e,t){this.options=e,this.cacheOptions=E(t)}configure(e){this.cacheOptions=E(e)}getPageSize(){return this.cacheOptions.pageSize}reset(){this.generation+=1,this.hasKnownTotal=!1,this.loadedBlocks.clear(),this.pendingBlocks.clear(),this.options.getCachedRows().clear()}hasMissingRows(e){if(e.endRow<=e.startRow)return!1;let t=this.options.getTotalRows();if(this.hasKnownTotal&&t===0||this.hasKnownTotal&&e.startRow>=t)return!1;let n=this.hasKnownTotal?Math.min(e.endRow,t):e.endRow,r=this.options.getCachedRows();for(let t=e.startRow;t<n;t+=1)if(!r.has(t))return!0;return!1}async loadRange(e,t=!1){t&&this.reset();let n=this.generation,r=this.options.getTotalRows(),i=this.getBlocksForRange(e).map(e=>this.getOrCreateBlockRequest(e,n)).filter(e=>e!==null);return i.length>0&&await Promise.all(i),n===this.generation?(this.evictAround(e),{applied:!0,loadedBlockCount:i.length,totalRowsChanged:r!==this.options.getTotalRows()}):{applied:!1,loadedBlockCount:0,totalRowsChanged:!1}}getOrCreateBlockRequest(e,t){if(this.loadedBlocks.has(e))return null;let n=this.pendingBlocks.get(e);if(n)return n;let r=this.fetchBlock(e,t);return this.pendingBlocks.set(e,r),r.then(()=>this.deletePendingBlock(e,r),()=>this.deletePendingBlock(e,r)),r}deletePendingBlock(e,t){this.pendingBlocks.get(e)===t&&this.pendingBlocks.delete(e)}async fetchBlock(e,t){let n=e*this.cacheOptions.pageSize,r=this.getBlockEndRow(e),i;try{i=await this.options.getDataSource().query(b({range:{startRow:n,endRow:r},sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),columns:this.options.getColumns()}))}catch(e){if(t===this.generation)throw e;return}t===this.generation&&this.applyBlockResponse(e,i.rows,i.totalRows)}applyBlockResponse(e,t,n){let r=this.options.getCachedRows(),i=this.options.getTotalRows();this.deleteRowsForBlock(e);let a=e*this.cacheOptions.pageSize;t.forEach((e,t)=>{e!==void 0&&r.set(a+t,e)}),this.options.setTotalRows(n),this.hasKnownTotal=!0,this.loadedBlocks.add(e),n<i&&this.deleteRowsAfterTotal(n)}getBlocksForRange(e){if(e.endRow<=e.startRow)return[];let t=this.options.getTotalRows();if(this.hasKnownTotal&&t===0||this.hasKnownTotal&&e.startRow>=t)return[];let n=this.hasKnownTotal?Math.min(e.endRow,t):e.endRow,r=this.cacheOptions.pageSize,i=Math.floor(e.startRow/r),a=Math.floor((n-1)/r),o=Math.max(0,i-this.cacheOptions.prefetchPages),s=this.getLastPrefetchBlock(a),c=[];for(let e=o;e<=s;e+=1)c.push(e);return c}getLastPrefetchBlock(e){let t=this.options.getTotalRows(),n=e+this.cacheOptions.prefetchPages;if(this.hasKnownTotal&&t>0){let e=Math.floor((t-1)/this.cacheOptions.pageSize);return Math.min(n,e)}return n}getBlockEndRow(e){let t=e*this.cacheOptions.pageSize+this.cacheOptions.pageSize,n=this.options.getTotalRows();return this.hasKnownTotal&&n>0?Math.min(t,n):t}evictAround(e){if(this.loadedBlocks.size<=this.cacheOptions.maxPages)return;let t=new Set(this.getBlocksForRange(e)),n=Math.floor(e.startRow/this.cacheOptions.pageSize),r=[...this.loadedBlocks].filter(e=>t.has(e)===!1).sort((e,t)=>Math.abs(t-n)-Math.abs(e-n));for(let e of r){if(this.loadedBlocks.size<=this.cacheOptions.maxPages)return;this.loadedBlocks.delete(e),this.deleteRowsForBlock(e)}}deleteRowsForBlock(e){let t=this.options.getCachedRows(),n=e*this.cacheOptions.pageSize,r=n+this.cacheOptions.pageSize;for(let e=n;e<r;e+=1)t.delete(e)}deleteRowsAfterTotal(e){let t=this.options.getCachedRows();for(let n of t.keys())n>=e&&t.delete(n)}};const D=e=>{e.computeColumnPositions(),e.batcher.start();try{e.emitContentSize(),e.emitHeaders(),e.batcher.emit({type:`COLUMNS_CHANGED`,columns:[...e.columns]}),e.refreshSlots===`sync`?e.slotPool.syncSlots():e.slotPool.refreshAllSlots()}finally{e.batcher.flush()}e.onComplete()},Se=(e,t,n)=>{let r=n.columns[e];r&&(r.width=t,D({...n,refreshSlots:`sync`}))},Ce=(e,t,n)=>{if(e===t||e<0||e>=n.columns.length)return null;let r=t>e?t-1:t;if(r<0||r>=n.columns.length||e===r)return null;let[i]=n.columns.splice(e,1);return n.columns.splice(r,0,i),D({...n,refreshSlots:`all`}),r},we=(e,t,n)=>{let r=n.dataSource;if(!r.moveRow)return;r.moveRow(e,t),oe(n.cachedRows,e,t),n.highlight?.clearAllCaches();let i=Math.min(e,t),a=Math.max(e,t);for(let e=i;e<=a;e++)n.slotPool.updateSlot(e)},Te=async e=>{let t=await e.dataSource.query(b({range:{startRow:0,endRow:2**53-1},sortModel:e.sortModel,filterModel:e.filterModel,columns:e.getColumns()}));e.cachedRows.clear();for(let n=0;n<t.rows.length;n++){let r=t.rows[n];r!==void 0&&e.cachedRows.set(n,r)}return e.setTotalRows(t.totalRows),{totalRows:t.totalRows}};var O=class{dataSource;options;rowLoading;rowWindowLoader;cachedRows=new Map;totalRows=0;isDataLoading=!1;constructor(e){this.options=e,this.dataSource=e.dataSource,this.rowLoading=e.rowLoading??{},this.rowWindowLoader=new xe({getDataSource:()=>this.dataSource,getCachedRows:()=>this.cachedRows,getTotalRows:()=>this.totalRows,setTotalRows:e=>{this.totalRows=e},getSortModel:e.getSortModel,getFilterModel:e.getFilterModel,getColumns:e.getColumns},this.rowLoading.cache)}getCachedRows(){return this.cachedRows}setCachedRows(e){this.cachedRows=e}getTotalRows(){return this.totalRows}setTotalRows(e){this.totalRows=e}getDataSource(){return this.dataSource}getRowData(e){return this.cachedRows.get(e)}isLoading(){return this.isDataLoading}getCellValue(e,t){return ce(this.cachedRows,this.options.getColumns(),e,t)}setCellValue(e,t,n){le(this.cachedRows,this.options.getColumns(),e,t,n,{onCellValueChanged:this.options.onCellValueChanged,getRowId:this.options.getRowId})}async loadInitial(){if(this.isPaginatedLoading()){await this.fetchPaginatedData({range:this.getInitialPaginatedRange(),resetCache:!0,showLoading:!0,refreshSlots:!1});return}await this.fetchAllData()}requestVisibleRows(){if(this.isPaginatedLoading()===!1)return;let e=this.getPaginatedLoadRange(!0);if(e.endRow<=e.startRow)return;let t=this.getPaginatedLoadRange(!1),n=this.rowWindowLoader.hasMissingRows(t);this.fetchPaginatedData({range:e,resetCache:!1,showLoading:n,refreshSlots:!0})}async refreshFromTransaction(){if(this.isPaginatedLoading()){await this.fetchPaginatedData({range:this.getPaginatedLoadRange(!0),resetCache:!0,showLoading:!1,refreshSlots:!1});return}await Te({dataSource:this.dataSource,sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),cachedRows:this.cachedRows,setTotalRows:e=>{this.totalRows=e},getColumns:this.options.getColumns})}setDataSource(e){this.dataSource=e,this.rowWindowLoader.reset(),this.totalRows=0}destroy(){this.rowWindowLoader.reset(),this.cachedRows.clear(),this.totalRows=0,this.isDataLoading=!1}async fetchAllData(){this.isDataLoading=!0,this.options.batcher.emit({type:`DATA_LOADING`});try{let e=b({range:{startRow:0,endRow:2**53-1},sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),columns:this.options.getColumns()}),t=await this.dataSource.query(e);this.cachedRows.clear(),t.rows.forEach((e,t)=>{this.cachedRows.set(t,e)}),this.totalRows=t.totalRows,this.options.batcher.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emitDataError(e)}finally{this.isDataLoading=!1}}async fetchPaginatedData(e){e.showLoading&&(this.isDataLoading=!0,this.options.batcher.emit({type:`DATA_LOADING`}));try{let t=await this.rowWindowLoader.loadRange(e.range,e.resetCache);if(t.applied===!1)return;(e.showLoading||t.totalRowsChanged)&&this.options.batcher.emit({type:`DATA_LOADED`,totalRows:this.totalRows}),e.refreshSlots&&(this.options.syncSlots(),this.options.emitVisibleRange(),t.totalRowsChanged&&this.options.emitContentSize())}catch(e){this.emitDataError(e)}finally{e.showLoading&&(this.isDataLoading=!1)}}emitDataError(e){this.options.batcher.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}isPaginatedLoading(){let e=this.rowLoading.mode??`auto`;return e===`paginated`?!0:e===`all`?!1:this.dataSource.loadMode===`paginated`}getInitialPaginatedRange(){let e=this.getPaginatedLoadRange(!0);return{startRow:0,endRow:Math.max(this.rowWindowLoader.getPageSize(),e.endRow)}}getPaginatedLoadRange(e){let t=this.options.getRowHeight(),n=this.options.getViewportHeight(),r=this.options.getScrollTop(),i=e?this.options.getOverscan():0,a=Math.max(0,Math.floor(r/t)-i),o=Math.ceil((r+n)/t)+i+1,s=this.totalRows>0?Math.min(this.totalRows,o):o;return{startRow:a,endRow:Math.max(a,s)}}};const k=1e7;var A=class{naturalContentHeight=0;virtualContentHeight=0;scrollRatio=1;options;constructor(e){this.options=e}updateContentSize(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight(),r=this.options.getViewportHeight(),i=e*t;if(this.naturalContentHeight=i+n,this.naturalContentHeight>k){this.virtualContentHeight=k;let e=this.virtualContentHeight-n-r,a=Math.ceil((i-r)/t)*t;this.scrollRatio=a>0?e/a:1}else this.virtualContentHeight=this.naturalContentHeight,this.scrollRatio=1;return{naturalHeight:this.naturalContentHeight,virtualHeight:this.virtualContentHeight,scrollRatio:this.scrollRatio}}isScalingActive(){return this.scrollRatio<1}getNaturalHeight(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight();return this.naturalContentHeight||e*t+n}getVirtualHeight(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight();return this.virtualContentHeight||e*t+n}getScrollRatio(){return this.scrollRatio}getVisibleRowRange(){let e=this.options.getViewportHeight(),t=this.options.getScrollTop(),n=this.options.getRowHeight(),r=this.options.getTotalRows(),i=e,a=Math.max(0,Math.floor(t/n)),o=Math.min(r-1,Math.ceil((t+i)/n)-1);return{start:a,end:Math.max(a,o)}}getScrollTopForRow(e){return e*this.options.getRowHeight()*this.scrollRatio}getRowIndexAtDisplayY(e,t){let n=this.options.getRowHeight(),r=e+(this.scrollRatio<1?t/this.scrollRatio:t);return Math.floor(r/n)}getVirtualContentHeight(){return this.virtualContentHeight}},j=class{options;emitter=v();sortModel=[];filterModel={};openFilterColIndex=null;onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}async setSort(e,t,n=!1){if(!this.options.isSortingEnabled()||this.options.getColumns().find(t=>(t.colId??t.field)===e)?.sortable===!1)return;let r=this.sortModel.findIndex(t=>t.colId===e);n?t===null&&r>=0?this.sortModel.splice(r,1):r>=0?this.sortModel[r].direction=t:this.sortModel.push({colId:e,direction:t}):this.sortModel=t===null?[]:[{colId:e,direction:t}],await this.options.onSortFilterChange(),this.options.onDataRefreshed()}getSortModel(){return[...this.sortModel]}async setFilter(e,t){this.options.getColumns().find(t=>(t.colId??t.field)===e)?.filterable!==!1&&(t===null||typeof t==`string`&&t.trim()===``||typeof t==`object`&&t.conditions?.length===0?delete this.filterModel[e]:typeof t==`string`?this.filterModel[e]={conditions:[{type:`text`,operator:`contains`,value:t}],combination:`and`}:this.filterModel[e]=t,await this.options.onSortFilterChange(),this.options.onDataRefreshed())}getFilterModel(){return{...this.filterModel}}hasActiveFilter(e){let t=this.filterModel[e];return t?t.conditions.length>0:!1}isColumnSortable(e){return this.options.isSortingEnabled()?this.options.getColumns()[e]?.sortable!==!1:!1}isColumnFilterable(e){return this.options.getColumns()[e]?.filterable!==!1}getDistinctValuesForColumn(e,t=500,n=1e5){let r=this.options.getColumns().find(t=>(t.colId??t.field)===e);if(!r)return[];let i=this.options.getCachedRows(),a=i.size,o=a>n?Math.ceil(a/n):1,s=r.valueFormatter,c=new Map;for(let e=0;e<a;e+=o){let n=i.get(e);if(n===void 0)continue;let a=g(n,r.field),[o,l]=this.normalizeDistinctValue(a,s);if(!c.has(o)&&(c.set(o,l),c.size>=t))break}let l=Array.from(c.values());return l.sort((e,t)=>{let n=y(e,s),r=y(t,s);return n.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})}),l}normalizeDistinctValue(e,t){if(Array.isArray(e)){let n=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1});return[t?t(n):JSON.stringify(n),n]}return[t?t(e):JSON.stringify(e),e]}openFilterPopup(e,t){if(this.openFilterColIndex===e){this.closeFilterPopup();return}let n=this.options.getColumns()[e];if(!n||!this.isColumnFilterable(e))return;let r=n.colId??n.field,i=this.getDistinctValuesForColumn(r);this.openFilterColIndex=e,this.emit({type:`OPEN_FILTER_POPUP`,colIndex:e,column:n,anchorRect:t,distinctValues:i,currentFilter:this.filterModel[r]})}closeFilterPopup(){this.openFilterColIndex=null,this.emit({type:`CLOSE_FILTER_POPUP`})}getSortInfoMap(){let e=new Map;return this.sortModel.forEach((t,n)=>{e.set(t.colId,{direction:t.direction,index:n+1})}),e}destroy(){this.emitter.clearListeners(),this.sortModel=[],this.filterModel={},this.openFilterColIndex=null}},M=class{queue=[];debounceTimer=null;pendingPromise=null;options;constructor(e){this.options=e}add(e){e.length!==0&&(this.queue.push({type:`ADD`,rows:e}),this.scheduleProcessing())}remove(e){e.length!==0&&(this.queue.push({type:`REMOVE`,rowIds:e}),this.scheduleProcessing())}updateCell(e,t,n){this.queue.push({type:`UPDATE_CELL`,rowId:e,field:t,value:n}),this.scheduleProcessing()}updateRow(e,t){Object.keys(t).length!==0&&(this.queue.push({type:`UPDATE_ROW`,rowId:e,data:t}),this.scheduleProcessing())}flush(){return this.queue.length===0?Promise.resolve():(this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise?new Promise((e,t)=>{let n=this.pendingPromise,r=n.resolve,i=n.reject;n.resolve=()=>{r(),e()},n.reject=e=>{i(e),t(e)}}):new Promise((e,t)=>{this.pendingPromise={resolve:e,reject:t},this.processQueue()}))}hasPending(){return this.queue.length>0}getPendingCount(){return this.queue.length}clear(){this.queue=[],this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}scheduleProcessing(){if(this.options.debounceMs===0){this.processQueue();return}this.debounceTimer===null&&(this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.processQueue()},this.options.debounceMs))}processQueue(){if(this.queue.length===0){this.pendingPromise&&=(this.pendingPromise.resolve(),null);return}let e=this.queue;this.queue=[];let t={added:0,removed:0,updated:0};try{for(let n of e)switch(n.type){case`ADD`:this.options.store.addRows(n.rows),t.added+=n.rows.length;break;case`REMOVE`:t.removed+=this.options.store.removeRows(n.rowIds);break;case`UPDATE_CELL`:this.options.store.updateCell(n.rowId,n.field,n.value),t.updated++;break;case`UPDATE_ROW`:this.options.store.updateRow(n.rowId,n.data),t.updated++;break}this.options.onProcessed&&this.options.onProcessed(t),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}catch(e){this.pendingPromise&&=(this.pendingPromise.reject(e instanceof Error?e:Error(String(e))),null)}}},Ee=class{listeners=[];buffer=null;subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}start(){this.buffer=[]}flush(){let e=this.buffer;if(this.buffer=null,e!==null&&e.length>0)for(let t of this.listeners)t(e)}emit(e){if(this.buffer!==null){this.buffer.push(e);return}this.notify([e])}emitBatch(e){if(e.length!==0){if(this.buffer!==null){this.buffer.push(...e);return}this.notify(e)}}clearListeners(){this.listeners=[]}notify(e){for(let t of this.listeners)t(e)}},De=class{scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;getScrollRatio;constructor(e){this.getScrollRatio=e}getScrollTop(){return this.scrollTop}getScrollLeft(){return this.scrollLeft}getViewportWidth(){return this.viewportWidth}getViewportHeight(){return this.viewportHeight}resetScrollTop(){this.scrollTop=0}update(e,t,n,r){let i=this.getScrollRatio(),a=i<1?e/i:e,o=this.viewportWidth!==n||this.viewportHeight!==r,s=this.scrollTop!==a||this.scrollLeft!==t||o;return s&&(this.scrollTop=a,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r),{changed:s,viewportSizeChanged:o}}};const N=e=>e.replaceAll(`\r
2
2
  `,`
3
3
  `).replaceAll(`\r`,`
4
4
  `),Oe=e=>{let t=N(e).split(`
@@ -205,7 +205,7 @@ self.onmessage = function(e) {
205
205
  self.postMessage({ type: "error", id, error: String(error) });
206
206
  }
207
207
  };
208
- `,{maxWorkers:e.maxWorkers??(navigator===void 0?4:navigator.hardwareConcurrency)??4}),this.parallelThreshold=e.parallelThreshold??4e5,this.minChunkSize=e.minChunkSize??5e4}isAvailable(){return this.isTerminated?!1:this.pool.isAvailable()}terminate(){this.pool.terminate(),this.isTerminated=!0}async sortIndices(e,t){return this.assertNotTerminated(),e.length<this.parallelThreshold?this.sortIndicesSingle(e,t):this.sortIndicesParallel(e,t)}async sortStringHashes(e,t,n){return this.assertNotTerminated(),(e[0]?.length??0)<this.parallelThreshold?this.sortStringHashesSingle(e,t,n):this.sortStringHashesParallel(e,t,n)}async sortMultiColumn(e,t){return this.assertNotTerminated(),(e[0]?.length??0)<this.parallelThreshold?this.sortMultiColumnSingle(e,t):this.sortMultiColumnParallel(e,t)}assertNotTerminated(){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`)}async sortIndicesSingle(e,t){let n=new Float64Array(e),r={type:`sortIndices`,id:0,values:n,direction:t};return(await this.pool.execute(r,[n.buffer])).indices}async sortStringHashesSingle(e,t,n){let r={type:`sortStringHashes`,id:0,hashChunks:e,direction:t},i=e.map(e=>e.buffer),a=await this.pool.execute(r,i);return a.collisionRuns.length>0&&Ye(a.indices,a.collisionRuns,n,t),a.indices}async sortMultiColumnSingle(e,t){let n=e.map(e=>new Float64Array(e)),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i={type:`sortMultiColumn`,id:0,columns:n,directions:r},a=[...n.map(e=>e.buffer),r.buffer];return(await this.pool.execute(i,a)).indices}boundariesFor(e){return qe(e,this.pool.getMaxWorkers(),this.minChunkSize)}async runChunks(e){let t=await this.pool.executeParallel(e);return t.sort((e,t)=>e.chunkOffset-t.chunkOffset),t}async sortIndicesParallel(e,t){let n=this.boundariesFor(e.length).map(n=>{let r=new Float64Array(e.slice(n.offset,n.offset+n.length));return{request:{type:`sortChunk`,id:0,values:r,direction:t,chunkOffset:n.offset},transferables:[r.buffer]}});return U((await this.runChunks(n)).map(e=>({indices:e.indices,values:e.sortedValues,offset:e.chunkOffset})),t)}async sortStringHashesParallel(e,t,n){let r=this.boundariesFor(e[0].length).map(n=>{let r=e.map(e=>{let t=new Float64Array(n.length);return t.set(new Float64Array(e.buffer,n.offset*8,n.length)),t});return{request:{type:`sortStringChunk`,id:0,hashChunks:r,direction:t,chunkOffset:n.offset},transferables:r.map(e=>e.buffer)}}),i=await this.runChunks(r),a=i.map(e=>({indices:e.indices,values:e.sortedHashes,offset:e.chunkOffset})),o=Qe(i),s=U(a,t),c=Je(a),l=new Uint32Array([...o,...c]);return l.length>0&&Ye(s,l,n,t),s}async sortMultiColumnParallel(e,t){let n=this.boundariesFor(e[0].length),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i=n.map(t=>{let n=e.map(e=>{let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t.offset+r];return n}),i=new Int8Array(r);return{request:{type:`sortMultiColumnChunk`,id:0,columns:n,directions:i,chunkOffset:t.offset},transferables:[...n.map(e=>e.buffer),i.buffer]}});return Ge((await this.runChunks(i)).map(e=>({indices:e.indices,columns:e.sortedColumns,directions:r,offset:e.chunkOffset})))}};const Qe=e=>{let t=[];for(let n of e)for(let e=0;e<n.collisionRuns.length;e+=2)t.push(n.collisionRuns[e]+n.chunkOffset,n.collisionRuns[e+1]+n.chunkOffset);return t};function G(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.codePointAt(e)??200,i;i=n>=97&&n<=122?n-97:n>=48&&n<=57?n-48+26:0,r=r*36+i}for(let e=n;e<10;e++)r*=36;return r}function K(e,t){let n=e==null||Array.isArray(e)&&e.length===0,r=t==null||Array.isArray(t)&&t.length===0;if(n&&r)return 0;if(n)return 1;if(r)return-1;if(Array.isArray(e)||Array.isArray(t)){let n=Array.isArray(e)?e.join(`, `):y(e),r=Array.isArray(t)?t.join(`, `):y(t);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!Number.isNaN(i)&&!Number.isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():y(e).localeCompare(y(t))}function $e(e){if(e==null)return Number.MAX_VALUE;if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return G(e);if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:G(e.join(`, `));if(typeof e==`object`)return G(JSON.stringify(e));let t=Number(e);return Number.isNaN(t)?0:t}function et(e,t){let n=[];for(let r of t.sortModel){let i=$e(t.getFieldValue(e,r.colId));n.push(i)}return n}function tt(e,t,n){if(!e||!t)return null;for(let r=0;r<n.length;r++){let i=e[r]-t[r];if(i!==0)return n[r].direction===`asc`?i:-i}return 0}function nt(e,t,n,r){for(let{colId:i,direction:a}of n){let n=K(r(e,i),r(t,i));if(n!==0)return a===`asc`?n:-n}return 0}function rt(e){let t=e.toLowerCase(),n=[];for(let e=0;e<3;e++){let r=e*10,i=0;for(let e=0;e<10;e++){let n=r+e,a=n<t.length?t.codePointAt(n)??200:0,o;o=a>=97&&a<=122?a-97:a>=48&&a<=57?a-48+26:0,i=i*36+o}n.push(i)}return n}function it(e){if(e==null)return Number.MAX_VALUE;if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:G(e.join(`, `));if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return G(e);if(typeof e==`object`)return G(JSON.stringify(e));let t=Number(e);return Number.isNaN(t)?0:t}function at(e,t,n){return[...e].sort((e,r)=>{for(let{colId:i,direction:a}of t){let t=K(n(e,i),n(r,i));if(t!==0)return a===`asc`?t:-t}return 0})}const ot=(e,t,n)=>{for(let r of e){let e=n(r,t);if(e!=null)return typeof e==`string`||Array.isArray(e)||typeof e==`object`&&!(e instanceof Date)?`string`:`numeric`}return`numeric`},st=(e,t,n)=>{let r=[],i=Array.from({length:3},()=>[]);for(let a of e){let e=y(n(a,t));r.push(e);let o=rt(e);for(let e=0;e<3;e++)i[e].push(o[e])}return{originalStrings:r,hashChunkArrays:i.map(e=>new Float64Array(e))}},ct=(e,t,n)=>e.map(e=>it(n(e,t))),lt=(e,t,n)=>{let r=[],i=[];for(let{colId:a,direction:o}of t)r.push(e.map(e=>it(n(e,a)))),i.push(o??`asc`);return{columnValues:r,directions:i}},ut=(e,t)=>{let n=Array(e.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n},dt=async(e,t,n,r)=>{let{colId:i,direction:a}=t,o=a??`asc`;if(ot(e,i,r)===`string`){let{originalStrings:t,hashChunkArrays:a}=st(e,i,r);return n.sortStringHashes(a,o,t)}let s=ct(e,i,r);return n.sortIndices(s,o)},ft=async(e,t,n,r)=>{let{columnValues:i,directions:a}=lt(e,t,r);return n.sortMultiColumn(i,a)},pt=async(e,t,n,r)=>ut(e,t.length===1?await dt(e,t[0],n,r):await ft(e,t,n,r));function q(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function mt(e){return e==null||e===``||Array.isArray(e)&&e.length===0}const ht={contains:(e,t)=>e.includes(t),notContains:(e,t)=>!e.includes(t),equals:(e,t)=>e===t,notEquals:(e,t)=>e!==t,startsWith:(e,t)=>e.startsWith(t),endsWith:(e,t)=>e.endsWith(t),blank:(e,t,n)=>n,notBlank:(e,t,n)=>!n};function gt(e,t,n){let r=mt(e);if(t.selectedValues&&t.selectedValues.size>0){let i=t.includeBlank===!0&&r;if(Array.isArray(e)){let r=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1}),a=n?n(r):r.join(`, `);return t.selectedValues.has(a)||i}let a=y(e,n);return t.selectedValues.has(a)||i}let i=y(e,n).toLowerCase(),a=String(t.value??``).toLowerCase();return ht[t.operator](i,a,r)}const _t={"=":(e,t)=>e===t,"!=":(e,t)=>e!==t,">":(e,t)=>e>t,"<":(e,t)=>e<t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t,between:(e,t,n)=>e>=t&&e<=n};function vt(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=typeof e==`number`?e:Number(e);if(Number.isNaN(r))return!1;let i=t.value??0,a=t.valueTo??0;return _t[t.operator](r,i,a)}const yt={"=":(e,t)=>q(e,t),"!=":(e,t)=>!q(e,t),">":(e,t)=>e.getTime()>t.getTime(),"<":(e,t)=>e.getTime()<t.getTime(),between:(e,t,n)=>{let r=e.getTime();return r>=t.getTime()&&r<=n.getTime()}};function bt(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=e instanceof Date?e:new Date(y(e));if(Number.isNaN(r.getTime()))return!1;let i=t.value instanceof Date?t.value:new Date(String(t.value??``)),a=t.valueTo instanceof Date?t.valueTo:new Date(String(t.valueTo??``));return yt[t.operator](r,i,a)}function xt(e,t,n){switch(t.type){case`text`:return gt(e,t,n);case`number`:return vt(e,t);case`date`:return bt(e,t);default:return!0}}function J(e,t,n){if(!t.conditions||t.conditions.length===0)return!0;let r=t.conditions[0];if(!r)return!0;let i=xt(e,r,n);for(let r=1;r<t.conditions.length;r++){let a=t.conditions[r-1],o=t.conditions[r],s=a.nextOperator??t.combination,c=xt(e,o,n);s===`and`?i&&=c:i||=c}return i}function St(e,t,n,r){let i=Object.entries(t).filter(([,e])=>e!=null);if(i.length===0)return!0;for(let[t,a]of i){let i=n(e,t),o=r?.(t);if(!J(i,a,o))return!1}return!0}function Ct(e,t,n,r){let i=Object.entries(t).filter(([,e])=>typeof e==`string`?e.trim()!==``:e.conditions&&e.conditions.length>0);return i.length===0?e:e.filter(e=>{for(let[t,a]of i){let i=n(e,t),o=r?.(t);if(typeof a==`string`){if(!y(i,o).toLowerCase().includes(a.toLowerCase()))return!1;continue}if(!J(i,a,o))return!1}return!0})}function Y(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r}function wt(e,t={}){let{getFieldValue:n=Y,getValueFormatter:r,useWorker:i=!0,parallelSort:a}=t,o=e,s=!1,c=i?new W(a===!1?{maxWorkers:1}:a):null;return{loadMode:`all`,async fetch(e){let t=o?[...o]:[];if(e.filter&&Object.keys(e.filter).length>0){let i=e.valueFormatters===null?r:t=>e.valueFormatters?.[t];t=Ct(t,e.filter,n,i)}e.sort&&e.sort.length>0&&(t=c&&c.isAvailable()&&t.length>=2e5?await pt(t,e.sort,c,n):at(t,e.sort,n));let i=t.length;return{rows:t.slice(e.range.startRow,e.range.endRow),totalRows:i}},destroy(){s||(s=!0,o=null,c&&c.terminate())},moveRow(e,t){if(!o||e===t||e<0||e>=o.length||t<0||t>=o.length)return;let[n]=o.splice(e,1),r=t>e?t-1:t;o.splice(r,0,n)}}}function X(e){return wt(e)}function Tt(e,t={}){return{loadMode:t.loadMode??`paginated`,async fetch(t){return e(t)}}}var Et=class{rows=[];rowById=new Map;sortedIndices=[];sortModel=[];sortModelHash=``;filterModel={};filteredIndices=new Set;distinctValues=new Map;rowSortCache=new Map;options;constructor(e,t=[]){this.options={getRowId:e.getRowId,getFieldValue:e.getFieldValue??g,getValueFormatter:e.getValueFormatter??(()=>void 0)},this.setData(t)}clear(){this.rows=[],this.rowById.clear(),this.sortedIndices=[],this.filterModel={},this.filteredIndices.clear(),this.rowSortCache.clear(),this.distinctValues.clear(),this.sortModel=[],this.sortModelHash=``}setData(e){this.rows=[...e],this.rowById.clear(),this.rowSortCache.clear(),this.distinctValues.clear();for(let e=0;e<this.rows.length;e++){let t=this.rows[e],n=this.options.getRowId(t);this.rowById.set(n,e)}this.rebuildSortedIndices(),this.rebuildFilteredIndices(),this.rebuildDistinctValues()}query(e){this.setSortModel(e.sort??[]),this.setFilterModel(e.filter??{});let t=this.getVisibleIndices(),n=t.length,r=e.range.startRow,i=Math.min(e.range.endRow,n),a=[];for(let e=r;e<i;e++){let n=t[e];n!==void 0&&a.push(this.rows[n])}return{rows:a,totalRows:n}}getRowById(e){let t=this.rowById.get(e);return t===void 0?void 0:this.rows[t]}getRowByIndex(e){return this.rows[e]}getTotalRowCount(){return this.rows.length}getAllRows(){return[...this.rows]}moveRow(e,t){if(e===t||e<0||e>=this.rows.length||t<0||t>=this.rows.length)return;let[n]=this.rows.splice(e,1),r=t>e?t-1:t;this.rows.splice(r,0,n),this.rowById.clear();for(let e=0;e<this.rows.length;e++)this.rowById.set(this.options.getRowId(this.rows[e]),e);this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.rowSortCache.clear()}getVisibleRowCount(){return Object.keys(this.filterModel).length===0?this.rows.length:this.filteredIndices.size}getDistinctValues(e){let t=this.distinctValues.get(e);return t?Array.from(t.keys()):[]}addRows(e){for(let t of e)this.addRow(t)}addRow(e){let t=this.options.getRowId(e);if(this.rowById.has(t)){console.warn(`Row with ID ${t} already exists. Skipping.`);return}let n=this.rows.length;if(this.rows.push(e),this.rowById.set(t,n),this.updateDistinctValuesForRow(e,`add`),this.sortModel.length>0&&this.computeRowHashes(n,e),this.sortModel.length>0){let e=this.binarySearchInsertPosition(n);this.sortedIndices.splice(e,0,n)}else this.sortedIndices.push(n);this.rowPassesFilter(e)&&this.filteredIndices.add(n)}removeRows(e){let t=[];for(let n of e){let e=this.rowById.get(n);e!==void 0&&t.push(e)}if(t.length===0)return 0;t.sort((e,t)=>t-e);for(let e of t)this.removeRowByIndex(e);return t.length}removeRowByIndex(e){let t=this.rows[e];if(!t)return;let n=this.options.getRowId(t);this.updateDistinctValuesForRow(t,`remove`);let r=this.sortedIndices.indexOf(e);r!==-1&&this.sortedIndices.splice(r,1),this.filteredIndices.delete(e),this.rowSortCache.delete(e),this.rowById.delete(n),this.rows.splice(e,1),this.reindexAfterRemoval(e)}reindexAfterRemoval(e){for(let[t,n]of this.rowById.entries())n>e&&this.rowById.set(t,n-1);for(let t=0;t<this.sortedIndices.length;t++)this.sortedIndices[t]>e&&this.sortedIndices[t]--;let t=new Set;for(let n of this.filteredIndices)n>e?t.add(n-1):t.add(n);this.filteredIndices=t;let n=new Map;for(let[t,r]of this.rowSortCache)t>e?n.set(t-1,r):n.set(t,r);this.rowSortCache=n}updateCell(e,t,n){let r=this.rowById.get(e);if(r===void 0){console.warn(`Row with ID ${e} not found.`);return}let i=this.rows[r],a=this.options.getFieldValue(i,t);if(_(i,t,n),this.updateDistinctValueForField(t,a,n),this.sortModel.some(e=>e.colId===t)&&this.sortModel.length>0){this.computeRowHashes(r,i);let e=this.sortedIndices.indexOf(r);e!==-1&&this.sortedIndices.splice(e,1);let t=this.binarySearchInsertPosition(r);this.sortedIndices.splice(t,0,r)}t in this.filterModel&&(this.rowPassesFilter(i)?this.filteredIndices.add(r):this.filteredIndices.delete(r))}updateRow(e,t){for(let[n,r]of Object.entries(t))this.updateCell(e,n,r)}setSortModel(e){let t=JSON.stringify(e);t!==this.sortModelHash&&(this.sortModelHash=t,this.sortModel=[...e],this.rebuildHashCache(),this.rebuildSortedIndices())}getSortModel(){return[...this.sortModel]}setFilterModel(e){JSON.stringify(e)!==JSON.stringify(this.filterModel)&&(this.filterModel={...e},this.rebuildFilteredIndices())}getFilterModel(){return{...this.filterModel}}rebuildSortedIndices(){this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.sortModel.length!==0&&this.sortedIndices.sort((e,t)=>this.compareRows(e,t))}rebuildHashCache(){if(this.rowSortCache.clear(),this.sortModel.length!==0)for(let e=0;e<this.rows.length;e++)this.computeRowHashes(e,this.rows[e])}computeRowHashes(e,t){if(this.sortModel.length===0)return;let n=et(t,{sortModel:this.sortModel,sortModelHash:this.sortModelHash,getFieldValue:this.options.getFieldValue}),r=this.rowSortCache.get(e);r||(r={hashes:new Map},this.rowSortCache.set(e,r)),r.hashes.set(this.sortModelHash,n)}compareRows(e,t){let n=this.rowSortCache.get(e),r=this.rowSortCache.get(t),i=n?.hashes.get(this.sortModelHash),a=r?.hashes.get(this.sortModelHash),o=tt(i,a,this.sortModel);return o===null?nt(this.rows[e],this.rows[t],this.sortModel,this.options.getFieldValue):o}binarySearchInsertPosition(e){let t=0,n=this.sortedIndices.length;for(;t<n;){let r=t+n>>>1,i=this.sortedIndices[r];this.compareRows(e,i)>0?t=r+1:n=r}return t}rebuildFilteredIndices(){if(this.filteredIndices.clear(),Object.entries(this.filterModel).some(([,e])=>e!=null))for(let e=0;e<this.rows.length;e++)this.rowPassesFilter(this.rows[e])&&this.filteredIndices.add(e)}rowPassesFilter(e){return St(e,this.filterModel,this.options.getFieldValue,this.options.getValueFormatter)}getVisibleIndices(){return Object.entries(this.filterModel).some(([,e])=>e!=null)?this.sortedIndices.filter(e=>this.filteredIndices.has(e)):this.sortedIndices}rebuildDistinctValues(){this.distinctValues.clear();for(let e of this.rows)this.updateDistinctValuesForRow(e,`add`)}updateDistinctValuesForRow(e,t){if(!(typeof e!=`object`||!e))for(let[n,r]of Object.entries(e))r!=null&&(t===`add`?this.addToDistinctValues(n,r):this.decrementDistinctValues(n,r))}updateDistinctValueForField(e,t,n){t!=null&&this.decrementDistinctValues(e,t),n!=null&&this.addToDistinctValues(e,n)}addToDistinctValues(e,t){let n=this.distinctValues.get(e);if(n||(n=new Map,this.distinctValues.set(e,n)),Array.isArray(t)){for(let e of t)e!=null&&Dt(n,e);return}Dt(n,t)}decrementDistinctValues(e,t){let n=this.distinctValues.get(e);if(n!==void 0){if(Array.isArray(t)){for(let e of t)e!=null&&Z(n,e);return}Z(n,t)}}};const Dt=(e,t)=>{e.set(t,(e.get(t)??0)+1)},Z=(e,t)=>{let n=e.get(t);if(n!==void 0){if(n<=1){e.delete(t);return}e.set(t,n-1)}};function Ot(e,t){let{getRowId:n,getFieldValue:r,getValueFormatter:i,debounceMs:a=50,onTransactionProcessed:o,useWorker:s=!0,parallelSort:c}=t,l=new Et({getRowId:n,getFieldValue:r??Y,getValueFormatter:i},e),u=new Set,d=v().emit,f=s&&c!==!1?new W(c):null,p=new M({debounceMs:a,store:l,onProcessed:e=>{o?.(e);for(let t of u)t(e)}});return{loadMode:`all`,async fetch(e){if(p.hasPending()){d({type:`DATA_LOADING`});try{await p.flush()}finally{d({type:`DATA_LOADED`,totalRows:l.getTotalRowCount()})}}let t=l.getAllRows(),n=r??Y;if(e.filter&&Object.keys(e.filter).length>0){let r=e.valueFormatters===null?i:t=>e.valueFormatters?.[t];t=Ct(t,e.filter,n,r)}if(e.sort&&e.sort.length>0)if(f&&f.isAvailable()&&t.length>=2e5){d({type:`DATA_LOADING`});try{t=await pt(t,e.sort,f,n)}finally{d({type:`DATA_LOADED`,totalRows:t.length})}}else t=at(t,e.sort,n);let a=t.length;return{rows:t.slice(e.range.startRow,e.range.endRow),totalRows:a}},addRows(e){p.add(e)},removeRows(e){p.remove(e)},updateCell(e,t,n){p.updateCell(e,t,n)},updateRow(e,t){p.updateRow(e,t)},async flushTransactions(){await p.flush()},hasPendingTransactions(){return p.hasPending()},getDistinctValues(e){return l.getDistinctValues(e)},getRowById(e){return l.getRowById(e)},getTotalRowCount(){return l.getTotalRowCount()},subscribe(e){return u.add(e),()=>{u.delete(e)}},clear(){let e=l.getTotalRowCount();l.clear();let t={added:0,removed:e,updated:0};o?.(t);for(let e of u)e(t)},moveRow(e,t){l.moveRow(e,t)}}}const kt=`
208
+ `,{maxWorkers:e.maxWorkers??(navigator===void 0?4:navigator.hardwareConcurrency)??4}),this.parallelThreshold=e.parallelThreshold??4e5,this.minChunkSize=e.minChunkSize??5e4}isAvailable(){return this.isTerminated?!1:this.pool.isAvailable()}terminate(){this.pool.terminate(),this.isTerminated=!0}async sortIndices(e,t){return this.assertNotTerminated(),e.length<this.parallelThreshold?this.sortIndicesSingle(e,t):this.sortIndicesParallel(e,t)}async sortStringHashes(e,t,n){return this.assertNotTerminated(),(e[0]?.length??0)<this.parallelThreshold?this.sortStringHashesSingle(e,t,n):this.sortStringHashesParallel(e,t,n)}async sortMultiColumn(e,t){return this.assertNotTerminated(),(e[0]?.length??0)<this.parallelThreshold?this.sortMultiColumnSingle(e,t):this.sortMultiColumnParallel(e,t)}assertNotTerminated(){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`)}async sortIndicesSingle(e,t){let n=new Float64Array(e),r={type:`sortIndices`,id:0,values:n,direction:t};return(await this.pool.execute(r,[n.buffer])).indices}async sortStringHashesSingle(e,t,n){let r={type:`sortStringHashes`,id:0,hashChunks:e,direction:t},i=e.map(e=>e.buffer),a=await this.pool.execute(r,i);return a.collisionRuns.length>0&&Ye(a.indices,a.collisionRuns,n,t),a.indices}async sortMultiColumnSingle(e,t){let n=e.map(e=>new Float64Array(e)),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i={type:`sortMultiColumn`,id:0,columns:n,directions:r},a=[...n.map(e=>e.buffer),r.buffer];return(await this.pool.execute(i,a)).indices}boundariesFor(e){return qe(e,this.pool.getMaxWorkers(),this.minChunkSize)}async runChunks(e){let t=await this.pool.executeParallel(e);return t.sort((e,t)=>e.chunkOffset-t.chunkOffset),t}async sortIndicesParallel(e,t){let n=this.boundariesFor(e.length).map(n=>{let r=new Float64Array(e.slice(n.offset,n.offset+n.length));return{request:{type:`sortChunk`,id:0,values:r,direction:t,chunkOffset:n.offset},transferables:[r.buffer]}});return U((await this.runChunks(n)).map(e=>({indices:e.indices,values:e.sortedValues,offset:e.chunkOffset})),t)}async sortStringHashesParallel(e,t,n){let r=this.boundariesFor(e[0].length).map(n=>{let r=e.map(e=>{let t=new Float64Array(n.length);return t.set(new Float64Array(e.buffer,n.offset*8,n.length)),t});return{request:{type:`sortStringChunk`,id:0,hashChunks:r,direction:t,chunkOffset:n.offset},transferables:r.map(e=>e.buffer)}}),i=await this.runChunks(r),a=i.map(e=>({indices:e.indices,values:e.sortedHashes,offset:e.chunkOffset})),o=Qe(i),s=U(a,t),c=Je(a),l=new Uint32Array([...o,...c]);return l.length>0&&Ye(s,l,n,t),s}async sortMultiColumnParallel(e,t){let n=this.boundariesFor(e[0].length),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i=n.map(t=>{let n=e.map(e=>{let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t.offset+r];return n}),i=new Int8Array(r);return{request:{type:`sortMultiColumnChunk`,id:0,columns:n,directions:i,chunkOffset:t.offset},transferables:[...n.map(e=>e.buffer),i.buffer]}});return Ge((await this.runChunks(i)).map(e=>({indices:e.indices,columns:e.sortedColumns,directions:r,offset:e.chunkOffset})))}};const Qe=e=>{let t=[];for(let n of e)for(let e=0;e<n.collisionRuns.length;e+=2)t.push(n.collisionRuns[e]+n.chunkOffset,n.collisionRuns[e+1]+n.chunkOffset);return t};function G(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.codePointAt(e)??200,i;i=n>=97&&n<=122?n-97:n>=48&&n<=57?n-48+26:0,r=r*36+i}for(let e=n;e<10;e++)r*=36;return r}function K(e,t){let n=e==null||Array.isArray(e)&&e.length===0,r=t==null||Array.isArray(t)&&t.length===0;if(n&&r)return 0;if(n)return 1;if(r)return-1;if(Array.isArray(e)||Array.isArray(t)){let n=Array.isArray(e)?e.join(`, `):y(e),r=Array.isArray(t)?t.join(`, `):y(t);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!Number.isNaN(i)&&!Number.isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():y(e).localeCompare(y(t))}function $e(e){if(e==null)return Number.MAX_VALUE;if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return G(e);if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:G(e.join(`, `));if(typeof e==`object`)return G(JSON.stringify(e));let t=Number(e);return Number.isNaN(t)?0:t}function et(e,t){let n=[];for(let r of t.sortModel){let i=$e(t.getFieldValue(e,r.colId));n.push(i)}return n}function tt(e,t,n){if(!e||!t)return null;for(let r=0;r<n.length;r++){let i=e[r]-t[r];if(i!==0)return n[r].direction===`asc`?i:-i}return 0}function nt(e,t,n,r){for(let{colId:i,direction:a}of n){let n=K(r(e,i),r(t,i));if(n!==0)return a===`asc`?n:-n}return 0}function rt(e){let t=e.toLowerCase(),n=[];for(let e=0;e<3;e++){let r=e*10,i=0;for(let e=0;e<10;e++){let n=r+e,a=n<t.length?t.codePointAt(n)??200:0,o;o=a>=97&&a<=122?a-97:a>=48&&a<=57?a-48+26:0,i=i*36+o}n.push(i)}return n}function it(e){if(e==null)return Number.MAX_VALUE;if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:G(e.join(`, `));if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return G(e);if(typeof e==`object`)return G(JSON.stringify(e));let t=Number(e);return Number.isNaN(t)?0:t}function at(e,t,n){return[...e].sort((e,r)=>{for(let{colId:i,direction:a}of t){let t=K(n(e,i),n(r,i));if(t!==0)return a===`asc`?t:-t}return 0})}const ot=(e,t,n)=>{for(let r of e){let e=n(r,t);if(e!=null)return typeof e==`string`||Array.isArray(e)||typeof e==`object`&&!(e instanceof Date)?`string`:`numeric`}return`numeric`},st=(e,t,n)=>{let r=[],i=Array.from({length:3},()=>[]);for(let a of e){let e=y(n(a,t));r.push(e);let o=rt(e);for(let e=0;e<3;e++)i[e].push(o[e])}return{originalStrings:r,hashChunkArrays:i.map(e=>new Float64Array(e))}},ct=(e,t,n)=>e.map(e=>it(n(e,t))),lt=(e,t,n)=>{let r=[],i=[];for(let{colId:a,direction:o}of t)r.push(e.map(e=>it(n(e,a)))),i.push(o??`asc`);return{columnValues:r,directions:i}},ut=(e,t)=>{let n=Array(e.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n},dt=async(e,t,n,r)=>{let{colId:i,direction:a}=t,o=a??`asc`;if(ot(e,i,r)===`string`){let{originalStrings:t,hashChunkArrays:a}=st(e,i,r);return n.sortStringHashes(a,o,t)}let s=ct(e,i,r);return n.sortIndices(s,o)},ft=async(e,t,n,r)=>{let{columnValues:i,directions:a}=lt(e,t,r);return n.sortMultiColumn(i,a)},pt=async(e,t,n,r)=>ut(e,t.length===1?await dt(e,t[0],n,r):await ft(e,t,n,r));function q(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function mt(e){return e==null||e===``||Array.isArray(e)&&e.length===0}const ht={contains:(e,t)=>e.includes(t),notContains:(e,t)=>!e.includes(t),equals:(e,t)=>e===t,notEquals:(e,t)=>e!==t,startsWith:(e,t)=>e.startsWith(t),endsWith:(e,t)=>e.endsWith(t),blank:(e,t,n)=>n,notBlank:(e,t,n)=>!n};function gt(e,t,n){let r=mt(e);if(t.selectedValues&&t.selectedValues.size>0){let i=t.includeBlank===!0&&r;if(Array.isArray(e)){let r=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1}),a=n?n(r):r.join(`, `);return t.selectedValues.has(a)||i}let a=y(e,n);return t.selectedValues.has(a)||i}let i=y(e,n).toLowerCase(),a=String(t.value??``).toLowerCase();return ht[t.operator](i,a,r)}const _t={"=":(e,t)=>e===t,"!=":(e,t)=>e!==t,">":(e,t)=>e>t,"<":(e,t)=>e<t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t,between:(e,t,n)=>e>=t&&e<=n};function vt(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=typeof e==`number`?e:Number(e);if(Number.isNaN(r))return!1;let i=t.value??0,a=t.valueTo??0;return _t[t.operator](r,i,a)}const yt={"=":(e,t)=>q(e,t),"!=":(e,t)=>!q(e,t),">":(e,t)=>e.getTime()>t.getTime(),"<":(e,t)=>e.getTime()<t.getTime(),between:(e,t,n)=>{let r=e.getTime();return r>=t.getTime()&&r<=n.getTime()}};function bt(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=e instanceof Date?e:new Date(y(e));if(Number.isNaN(r.getTime()))return!1;let i=t.value instanceof Date?t.value:new Date(String(t.value??``)),a=t.valueTo instanceof Date?t.valueTo:new Date(String(t.valueTo??``));return yt[t.operator](r,i,a)}function xt(e,t,n){switch(t.type){case`text`:return gt(e,t,n);case`number`:return vt(e,t);case`date`:return bt(e,t);default:return!0}}function J(e,t,n){if(!t.conditions||t.conditions.length===0)return!0;let r=t.conditions[0];if(!r)return!0;let i=xt(e,r,n);for(let r=1;r<t.conditions.length;r++){let a=t.conditions[r-1],o=t.conditions[r],s=a.nextOperator??t.combination,c=xt(e,o,n);s===`and`?i&&=c:i||=c}return i}function St(e,t,n,r){let i=Object.entries(t).filter(([,e])=>e!=null);if(i.length===0)return!0;for(let[t,a]of i){let i=n(e,t),o=r?.(t);if(!J(i,a,o))return!1}return!0}function Ct(e,t,n,r){let i=Object.entries(t).filter(([,e])=>typeof e==`string`?e.trim()!==``:e.conditions&&e.conditions.length>0);return i.length===0?e:e.filter(e=>{for(let[t,a]of i){let i=n(e,t),o=r?.(t);if(typeof a==`string`){if(!y(i,o).toLowerCase().includes(a.toLowerCase()))return!1;continue}if(!J(i,a,o))return!1}return!0})}function Y(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r}function wt(e,t={}){let{getFieldValue:n=Y,getValueFormatter:r,useWorker:i=!0,parallelSort:a}=t,o=e,s=!1,c=i?new W(a===!1?{maxWorkers:1}:a):null;return{loadMode:`all`,async query(e){let t=o?[...o]:[];if(e.filter&&Object.keys(e.filter).length>0){let i=e.valueFormatters===null?r:t=>e.valueFormatters?.[t];t=Ct(t,e.filter,n,i)}e.sort&&e.sort.length>0&&(t=c&&c.isAvailable()&&t.length>=2e5?await pt(t,e.sort,c,n):at(t,e.sort,n));let i=t.length;return{rows:t.slice(e.range.startRow,e.range.endRow),totalRows:i}},destroy(){s||(s=!0,o=null,c&&c.terminate())},moveRow(e,t){if(!o||e===t||e<0||e>=o.length||t<0||t>=o.length)return;let[n]=o.splice(e,1),r=t>e?t-1:t;o.splice(r,0,n)}}}function X(e){return wt(e)}function Tt(e,t={}){return{loadMode:t.loadMode??`paginated`,async query(t){return e(t)}}}var Et=class{rows=[];rowById=new Map;sortedIndices=[];sortModel=[];sortModelHash=``;filterModel={};filteredIndices=new Set;distinctValues=new Map;rowSortCache=new Map;options;constructor(e,t=[]){this.options={getRowId:e.getRowId,getFieldValue:e.getFieldValue??g,getValueFormatter:e.getValueFormatter??(()=>void 0)},this.setData(t)}clear(){this.rows=[],this.rowById.clear(),this.sortedIndices=[],this.filterModel={},this.filteredIndices.clear(),this.rowSortCache.clear(),this.distinctValues.clear(),this.sortModel=[],this.sortModelHash=``}setData(e){this.rows=[...e],this.rowById.clear(),this.rowSortCache.clear(),this.distinctValues.clear();for(let e=0;e<this.rows.length;e++){let t=this.rows[e],n=this.options.getRowId(t);this.rowById.set(n,e)}this.rebuildSortedIndices(),this.rebuildFilteredIndices(),this.rebuildDistinctValues()}query(e){this.setSortModel(e.sort??[]),this.setFilterModel(e.filter??{});let t=this.getVisibleIndices(),n=t.length,r=e.range.startRow,i=Math.min(e.range.endRow,n),a=[];for(let e=r;e<i;e++){let n=t[e];n!==void 0&&a.push(this.rows[n])}return{rows:a,totalRows:n}}getRowById(e){let t=this.rowById.get(e);return t===void 0?void 0:this.rows[t]}getRowByIndex(e){return this.rows[e]}getTotalRowCount(){return this.rows.length}getAllRows(){return[...this.rows]}moveRow(e,t){if(e===t||e<0||e>=this.rows.length||t<0||t>=this.rows.length)return;let[n]=this.rows.splice(e,1),r=t>e?t-1:t;this.rows.splice(r,0,n),this.rowById.clear();for(let e=0;e<this.rows.length;e++)this.rowById.set(this.options.getRowId(this.rows[e]),e);this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.rowSortCache.clear()}getVisibleRowCount(){return Object.keys(this.filterModel).length===0?this.rows.length:this.filteredIndices.size}getDistinctValues(e){let t=this.distinctValues.get(e);return t?Array.from(t.keys()):[]}addRows(e){for(let t of e)this.addRow(t)}addRow(e){let t=this.options.getRowId(e);if(this.rowById.has(t)){console.warn(`Row with ID ${t} already exists. Skipping.`);return}let n=this.rows.length;if(this.rows.push(e),this.rowById.set(t,n),this.updateDistinctValuesForRow(e,`add`),this.sortModel.length>0&&this.computeRowHashes(n,e),this.sortModel.length>0){let e=this.binarySearchInsertPosition(n);this.sortedIndices.splice(e,0,n)}else this.sortedIndices.push(n);this.rowPassesFilter(e)&&this.filteredIndices.add(n)}removeRows(e){let t=[];for(let n of e){let e=this.rowById.get(n);e!==void 0&&t.push(e)}if(t.length===0)return 0;t.sort((e,t)=>t-e);for(let e of t)this.removeRowByIndex(e);return t.length}removeRowByIndex(e){let t=this.rows[e];if(!t)return;let n=this.options.getRowId(t);this.updateDistinctValuesForRow(t,`remove`);let r=this.sortedIndices.indexOf(e);r!==-1&&this.sortedIndices.splice(r,1),this.filteredIndices.delete(e),this.rowSortCache.delete(e),this.rowById.delete(n),this.rows.splice(e,1),this.reindexAfterRemoval(e)}reindexAfterRemoval(e){for(let[t,n]of this.rowById.entries())n>e&&this.rowById.set(t,n-1);for(let t=0;t<this.sortedIndices.length;t++)this.sortedIndices[t]>e&&this.sortedIndices[t]--;let t=new Set;for(let n of this.filteredIndices)n>e?t.add(n-1):t.add(n);this.filteredIndices=t;let n=new Map;for(let[t,r]of this.rowSortCache)t>e?n.set(t-1,r):n.set(t,r);this.rowSortCache=n}updateCell(e,t,n){let r=this.rowById.get(e);if(r===void 0){console.warn(`Row with ID ${e} not found.`);return}let i=this.rows[r],a=this.options.getFieldValue(i,t);if(_(i,t,n),this.updateDistinctValueForField(t,a,n),this.sortModel.some(e=>e.colId===t)&&this.sortModel.length>0){this.computeRowHashes(r,i);let e=this.sortedIndices.indexOf(r);e!==-1&&this.sortedIndices.splice(e,1);let t=this.binarySearchInsertPosition(r);this.sortedIndices.splice(t,0,r)}t in this.filterModel&&(this.rowPassesFilter(i)?this.filteredIndices.add(r):this.filteredIndices.delete(r))}updateRow(e,t){for(let[n,r]of Object.entries(t))this.updateCell(e,n,r)}setSortModel(e){let t=JSON.stringify(e);t!==this.sortModelHash&&(this.sortModelHash=t,this.sortModel=[...e],this.rebuildHashCache(),this.rebuildSortedIndices())}getSortModel(){return[...this.sortModel]}setFilterModel(e){JSON.stringify(e)!==JSON.stringify(this.filterModel)&&(this.filterModel={...e},this.rebuildFilteredIndices())}getFilterModel(){return{...this.filterModel}}rebuildSortedIndices(){this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.sortModel.length!==0&&this.sortedIndices.sort((e,t)=>this.compareRows(e,t))}rebuildHashCache(){if(this.rowSortCache.clear(),this.sortModel.length!==0)for(let e=0;e<this.rows.length;e++)this.computeRowHashes(e,this.rows[e])}computeRowHashes(e,t){if(this.sortModel.length===0)return;let n=et(t,{sortModel:this.sortModel,sortModelHash:this.sortModelHash,getFieldValue:this.options.getFieldValue}),r=this.rowSortCache.get(e);r||(r={hashes:new Map},this.rowSortCache.set(e,r)),r.hashes.set(this.sortModelHash,n)}compareRows(e,t){let n=this.rowSortCache.get(e),r=this.rowSortCache.get(t),i=n?.hashes.get(this.sortModelHash),a=r?.hashes.get(this.sortModelHash),o=tt(i,a,this.sortModel);return o===null?nt(this.rows[e],this.rows[t],this.sortModel,this.options.getFieldValue):o}binarySearchInsertPosition(e){let t=0,n=this.sortedIndices.length;for(;t<n;){let r=t+n>>>1,i=this.sortedIndices[r];this.compareRows(e,i)>0?t=r+1:n=r}return t}rebuildFilteredIndices(){if(this.filteredIndices.clear(),Object.entries(this.filterModel).some(([,e])=>e!=null))for(let e=0;e<this.rows.length;e++)this.rowPassesFilter(this.rows[e])&&this.filteredIndices.add(e)}rowPassesFilter(e){return St(e,this.filterModel,this.options.getFieldValue,this.options.getValueFormatter)}getVisibleIndices(){return Object.entries(this.filterModel).some(([,e])=>e!=null)?this.sortedIndices.filter(e=>this.filteredIndices.has(e)):this.sortedIndices}rebuildDistinctValues(){this.distinctValues.clear();for(let e of this.rows)this.updateDistinctValuesForRow(e,`add`)}updateDistinctValuesForRow(e,t){if(!(typeof e!=`object`||!e))for(let[n,r]of Object.entries(e))r!=null&&(t===`add`?this.addToDistinctValues(n,r):this.decrementDistinctValues(n,r))}updateDistinctValueForField(e,t,n){t!=null&&this.decrementDistinctValues(e,t),n!=null&&this.addToDistinctValues(e,n)}addToDistinctValues(e,t){let n=this.distinctValues.get(e);if(n||(n=new Map,this.distinctValues.set(e,n)),Array.isArray(t)){for(let e of t)e!=null&&Dt(n,e);return}Dt(n,t)}decrementDistinctValues(e,t){let n=this.distinctValues.get(e);if(n!==void 0){if(Array.isArray(t)){for(let e of t)e!=null&&Z(n,e);return}Z(n,t)}}};const Dt=(e,t)=>{e.set(t,(e.get(t)??0)+1)},Z=(e,t)=>{let n=e.get(t);if(n!==void 0){if(n<=1){e.delete(t);return}e.set(t,n-1)}};function Ot(e,t){let{getRowId:n,getFieldValue:r,getValueFormatter:i,debounceMs:a=50,onTransactionProcessed:o,useWorker:s=!0,parallelSort:c}=t,l=new Et({getRowId:n,getFieldValue:r??Y,getValueFormatter:i},e),u=new Set,d=v().emit,f=s&&c!==!1?new W(c):null,p=new M({debounceMs:a,store:l,onProcessed:e=>{o?.(e);for(let t of u)t(e)}});return{loadMode:`all`,async query(e){if(p.hasPending()){d({type:`DATA_LOADING`});try{await p.flush()}finally{d({type:`DATA_LOADED`,totalRows:l.getTotalRowCount()})}}let t=l.getAllRows(),n=r??Y;if(e.filter&&Object.keys(e.filter).length>0){let r=e.valueFormatters===null?i:t=>e.valueFormatters?.[t];t=Ct(t,e.filter,n,r)}if(e.sort&&e.sort.length>0)if(f&&f.isAvailable()&&t.length>=2e5){d({type:`DATA_LOADING`});try{t=await pt(t,e.sort,f,n)}finally{d({type:`DATA_LOADED`,totalRows:t.length})}}else t=at(t,e.sort,n);let a=t.length;return{rows:t.slice(e.range.startRow,e.range.endRow),totalRows:a}},addRows(e){p.add(e)},removeRows(e){p.remove(e)},updateCell(e,t,n){p.updateCell(e,t,n)},updateRow(e,t){p.updateRow(e,t)},async flushTransactions(){await p.flush()},hasPendingTransactions(){return p.hasPending()},getDistinctValues(e){return l.getDistinctValues(e)},getRowById(e){return l.getRowById(e)},getTotalRowCount(){return l.getTotalRowCount()},subscribe(e){return u.add(e),()=>{u.delete(e)}},clear(){let e=l.getTotalRowCount();l.clear();let t={added:0,removed:e,updated:0};o?.(t);for(let e of u)e(t)},moveRow(e,t){l.moveRow(e,t)}}}const kt=`
209
209
  /* =============================================================================
210
210
  GP Grid - CSS Variables for Theming
211
211
  ============================================================================= */
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@gp-grid/core",
3
3
  "description": "A high-performance, framework-agnostic TypeScript data grid core with virtual scrolling",
4
4
  "private": false,
5
- "version": "0.15.0",
5
+ "version": "0.16.0",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",