gp-grid-core 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1062 -103
- package/dist/index.js +765 -9
- package/package.json +3 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var e=class{state={activeCell:null,range:null,anchor:null,selectionMode:!1};options;listeners=[];constructor(e){this.options=e}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e)}getState(){return{...this.state}}getActiveCell(){return this.state.activeCell}getSelectionRange(){return this.state.range}isSelected(e,t){let{range:n}=this.state;if(!n)return!1;let r=Math.min(n.startRow,n.endRow),i=Math.max(n.startRow,n.endRow),a=Math.min(n.startCol,n.endCol),o=Math.max(n.startCol,n.endCol);return e>=r&&e<=i&&t>=a&&t<=o}isActiveCell(e,t){let{activeCell:n}=this.state;return n?.row===e&&n?.col===t}startSelection(e,t={}){let{shift:n=!1,ctrl:r=!1}=t,{row:i,col:a}=this.clampPosition(e);n&&this.state.anchor?(this.state.range={startRow:this.state.anchor.row,startCol:this.state.anchor.col,endRow:i,endCol:a},this.state.activeCell={row:i,col:a}):(this.state.activeCell={row:i,col:a},this.state.anchor={row:i,col:a},this.state.range=null),this.state.selectionMode=r,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})}moveFocus(e,t=!1){if(!this.state.activeCell){this.startSelection({row:0,col:0});return}let{row:n,col:r}=this.state.activeCell,i=n,a=r;switch(e){case`up`:i=Math.max(0,n-1);break;case`down`:i=Math.min(this.options.getRowCount()-1,n+1);break;case`left`:a=Math.max(0,r-1);break;case`right`:a=Math.min(this.options.getColumnCount()-1,r+1);break}t?(this.state.anchor||(this.state.anchor={row:n,col:r}),this.state.range={startRow:this.state.anchor.row,startCol:this.state.anchor.col,endRow:i,endCol:a},this.state.activeCell={row:i,col:a},this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})):(this.state.activeCell={row:i,col:a},this.state.anchor={row:i,col:a},this.state.range=null,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:null}))}selectAll(){let e=this.options.getRowCount(),t=this.options.getColumnCount();e===0||t===0||(this.state.range={startRow:0,startCol:0,endRow:e-1,endCol:t-1},this.state.activeCell||(this.state.activeCell={row:0,col:0},this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell})),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range}))}clearSelection(){this.state.activeCell=null,this.state.range=null,this.state.anchor=null,this.state.selectionMode=!1,this.emit({type:`SET_ACTIVE_CELL`,position:null}),this.emit({type:`SET_SELECTION_RANGE`,range:null})}setActiveCell(e,t){let n=this.clampPosition({row:e,col:t});this.state.activeCell=n,this.state.anchor=n,this.state.range=null,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:null})}setSelectionRange(e){this.state.range=e,this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})}getSelectedData(){let{range:e,activeCell:t}=this.state;if(!e&&!t)return[];let n=e||{startRow:t.row,startCol:t.col,endRow:t.row,endCol:t.col},r=Math.min(n.startRow,n.endRow),i=Math.max(n.startRow,n.endRow),a=Math.min(n.startCol,n.endCol),o=Math.max(n.startCol,n.endCol),s=[];for(let e=r;e<=i;e++){let t=[];for(let n=a;n<=o;n++)t.push(this.options.getCellValue(e,n));s.push(t)}return s}async copySelectionToClipboard(){let e=this.getSelectedData();if(e.length===0)return;let t=e.map(e=>e.map(e=>e==null?``:String(e)).join(` `)).join(`
|
|
2
|
-
`);try{await navigator.clipboard.writeText(t)}catch{let e=document.createElement(`textarea`);e.value=t,e.style.position=`fixed`,e.style.left=`-9999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}}clampPosition(e){let t=this.options.getRowCount(),n=this.options.getColumnCount();return{row:Math.max(0,Math.min(e.row,t-1)),col:Math.max(0,Math.min(e.col,n-1))}}},t=class{state=null;options;listeners=[];constructor(e){this.options=e}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e)}getState(){return this.state?{...this.state}:null}isActive(){return this.state!==null}startFillDrag(e){this.state={sourceRange:e,targetRow:e.endRow,targetCol:e.endCol},this.emit({type:`START_FILL`,sourceRange:e})}updateFillDrag(e,t){if(!this.state)return;let n=this.options.getRowCount(),r=this.options.getColumnCount();e=Math.max(0,Math.min(e,n-1)),t=Math.max(0,Math.min(t,r-1)),this.state.targetRow=e,this.state.targetCol=t,this.emit({type:`UPDATE_FILL`,targetRow:e,targetCol:t})}commitFillDrag(){if(!this.state)return;let{sourceRange:e,targetRow:t,targetCol:n}=this.state,r=this.calculateFilledCells(e,t,n);for(let{row:e,col:t,value:n}of r)this.options.setCellValue(e,t,n);this.emit({type:`COMMIT_FILL`,filledCells:r}),this.state=null}cancelFillDrag(){this.state&&(this.state=null,this.emit({type:`CANCEL_FILL`}))}calculateFilledCells(e,t,n){let r=[],i=Math.min(e.startRow,e.endRow),a=Math.max(e.startRow,e.endRow),o=Math.min(e.startCol,e.endCol),s=Math.max(e.startCol,e.endCol),c=t>a,l=t<i;if(c||l)for(let e=o;e<=s;e++){let n=this.getSourceColumnValues(i,a,e),o=this.detectPattern(n);if(c)for(let i=a+1;i<=t;i++){let t=i-a-1,s=this.applyPattern(o,n,t);r.push({row:i,col:e,value:s})}else if(l)for(let a=i-1;a>=t;a--){let t=i-a-1,s=this.applyPattern(o,n,t,!0);r.push({row:a,col:e,value:s})}}return r}getSourceColumnValues(e,t,n){let r=[];for(let i=e;i<=t;i++)r.push(this.options.getCellValue(i,n));return r}detectPattern(e){if(e.length===0)return{type:`constant`,value:null};if(e.length===1)return{type:`constant`,value:e[0]??null};let t=e.map(e=>typeof e==`number`?e:Number(e));if(t.every(e=>!isNaN(e))){let e=[];for(let n=1;n<t.length;n++)e.push(t[n]-t[n-1]);if(e.every(t=>t===e[0])&&e[0]!==void 0)return{type:`arithmetic`,start:t[0],step:e[0]}}return{type:`repeat`,values:e}}applyPattern(e,t,n,r=!1){switch(e.type){case`constant`:return e.value;case`arithmetic`:{let i=r?-(n+1):n+1;return(r?e.start:e.start+e.step*(t.length-1))+e.step*i}case`repeat`:{let t=e.values.length;if(t===0)return null;if(r){let r=(t-1-n%t+t)%t;return e.values[r]??null}return e.values[n%t]??null}}}},n=class n{static MAX_SAFE_HEIGHT=1e6;columns;dataSource;rowHeight;headerHeight;overscan;scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;cachedRows=new Map;totalRows=0;currentPageIndex=0;pageSize=1e6;sortModel=[];filterModel={};slotPool={slots:new Map,rowToSlot:new Map,nextSlotId:0};selection;fill;editState=null;columnPositions=[];listeners=[];batchListeners=[];constructor(n){this.columns=n.columns,this.dataSource=n.dataSource,this.rowHeight=n.rowHeight,this.headerHeight=n.headerHeight??n.rowHeight,this.overscan=n.overscan??3,this.computeColumnPositions(),this.selection=new e({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getRowData:e=>this.cachedRows.get(e),getColumn:e=>this.columns[e]}),this.selection.onInstruction(e=>this.emit(e)),this.fill=new t({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getColumn:e=>this.columns[e],setCellValue:(e,t,n)=>this.setCellValue(e,t,n)}),this.fill.onInstruction(e=>this.emit(e))}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}onBatchInstruction(e){return this.batchListeners.push(e),()=>{this.batchListeners=this.batchListeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e);for(let t of this.batchListeners)t([e])}emitBatch(e){if(e.length!==0){for(let t of this.batchListeners)t(e);for(let t of e)for(let e of this.listeners)e(t)}}async initialize(){await this.fetchData(),this.syncSlots(),this.emitContentSize(),this.emitHeaders()}setViewport(e,t,n,r){(this.scrollTop!==e||this.scrollLeft!==t||this.viewportWidth!==n||this.viewportHeight!==r)&&(this.scrollTop=e,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r,this.syncSlots())}syncSlots(){let e=this.getVirtualScrollTop(),t=Math.max(0,Math.floor(e/this.rowHeight)-this.overscan),n=Math.min(this.totalRows-1,Math.ceil((e+this.viewportHeight)/this.rowHeight)+this.overscan);if(this.totalRows===0||n<t){this.destroyAllSlots();return}let r=new Set;for(let e=t;e<=n;e++)r.add(e);let i=[],a=[];for(let[e,t]of this.slotPool.slots)r.has(t.rowIndex)?r.delete(t.rowIndex):(a.push(e),this.slotPool.rowToSlot.delete(t.rowIndex));let o=Array.from(r);for(let e=0;e<o.length;e++){let t=o[e],n=this.cachedRows.get(t);if(e<a.length){let r=a[e],o=this.slotPool.slots.get(r),s=this.getRowTranslateY(t);o.rowIndex=t,o.rowData=n??{},o.translateY=s,this.slotPool.rowToSlot.set(t,r),i.push({type:`ASSIGN_SLOT`,slotId:r,rowIndex:t,rowData:n??{}}),i.push({type:`MOVE_SLOT`,slotId:r,translateY:s})}else{let e=`slot-${this.slotPool.nextSlotId++}`,r=this.getRowTranslateY(t),a={slotId:e,rowIndex:t,rowData:n??{},translateY:r};this.slotPool.slots.set(e,a),this.slotPool.rowToSlot.set(t,e),i.push({type:`CREATE_SLOT`,slotId:e}),i.push({type:`ASSIGN_SLOT`,slotId:e,rowIndex:t,rowData:n??{}}),i.push({type:`MOVE_SLOT`,slotId:e,translateY:r})}}for(let e=o.length;e<a.length;e++){let t=a[e];this.slotPool.slots.delete(t),i.push({type:`DESTROY_SLOT`,slotId:t})}for(let[e,t]of this.slotPool.slots){let n=this.getRowTranslateY(t.rowIndex);t.translateY!==n&&(t.translateY=n,i.push({type:`MOVE_SLOT`,slotId:e,translateY:n}))}this.emitBatch(i)}destroyAllSlots(){let e=[];for(let t of this.slotPool.slots.keys())e.push({type:`DESTROY_SLOT`,slotId:t});this.slotPool.slots.clear(),this.slotPool.rowToSlot.clear(),this.emitBatch(e)}getVirtualHeight(){return this.totalRows*this.rowHeight+this.headerHeight}getDisplayHeight(){return Math.min(this.getVirtualHeight(),n.MAX_SAFE_HEIGHT)}needsScaling(){return this.getVirtualHeight()>n.MAX_SAFE_HEIGHT}getScrollProgress(){let e=this.getDisplayHeight()-this.viewportHeight;return e<=0?0:Math.min(1,Math.max(0,this.scrollTop/e))}getVirtualScrollTop(){if(!this.needsScaling())return this.scrollTop;let e=this.getVirtualHeight()-this.viewportHeight;return this.getScrollProgress()*e}getRowTranslateY(e){let t=e*this.rowHeight+this.headerHeight;if(!this.needsScaling())return t;let n=this.getDisplayHeight(),r=this.getVirtualHeight(),i=t+this.getScrollProgress()*(n-r);return Math.min(i,n)}async fetchData(){this.emit({type:`DATA_LOADING`});try{let e={pagination:{pageIndex:this.currentPageIndex,pageSize:this.pageSize},sort:this.sortModel.length>0?this.sortModel:void 0,filter:Object.keys(this.filterModel).length>0?this.filterModel:void 0},t=await this.dataSource.fetch(e);this.cachedRows.clear(),t.rows.forEach((e,t)=>{this.cachedRows.set(this.currentPageIndex*this.pageSize+t,e)}),this.totalRows=t.totalRows,t.totalRows>t.rows.length&&this.currentPageIndex===0&&await this.fetchAllData(),this.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}}async fetchAllData(){let e=Math.ceil(this.totalRows/this.pageSize);for(let t=1;t<e;t++){let e={pagination:{pageIndex:t,pageSize:this.pageSize},sort:this.sortModel.length>0?this.sortModel:void 0,filter:Object.keys(this.filterModel).length>0?this.filterModel:void 0};(await this.dataSource.fetch(e)).rows.forEach((e,n)=>{this.cachedRows.set(t*this.pageSize+n,e)})}}async setSort(e,t,n=!1){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.fetchData(),this.refreshAllSlots(),this.emitHeaders()}async setFilter(e,t){t===``?delete this.filterModel[e]:this.filterModel[e]=t,await this.fetchData(),this.refreshAllSlots(),this.emitContentSize()}refreshAllSlots(){let e=[];for(let[t,n]of this.slotPool.slots)if(n.rowIndex>=0&&n.rowIndex<this.totalRows){let r=this.cachedRows.get(n.rowIndex),i=this.getRowTranslateY(n.rowIndex);n.rowData=r??{},n.translateY=i,e.push({type:`ASSIGN_SLOT`,slotId:t,rowIndex:n.rowIndex,rowData:r??{}}),e.push({type:`MOVE_SLOT`,slotId:t,translateY:i})}this.emitBatch(e),this.syncSlots()}getSortModel(){return[...this.sortModel]}getFilterModel(){return{...this.filterModel}}startEdit(e,t){let n=this.columns[t];if(!n||n.editable!==!0)return;let r=this.getCellValue(e,t);this.editState={row:e,col:t,initialValue:r,currentValue:r},this.emit({type:`START_EDIT`,row:e,col:t,initialValue:r})}updateEditValue(e){this.editState&&(this.editState.currentValue=e)}commitEdit(){if(!this.editState)return;let{row:e,col:t,currentValue:n}=this.editState;this.setCellValue(e,t,n),this.emit({type:`COMMIT_EDIT`,row:e,col:t,value:n}),this.editState=null,this.emit({type:`STOP_EDIT`});let r=this.slotPool.rowToSlot.get(e);if(r){let t=this.cachedRows.get(e);t&&this.emit({type:`ASSIGN_SLOT`,slotId:r,rowIndex:e,rowData:t})}}cancelEdit(){this.editState=null,this.emit({type:`STOP_EDIT`})}getEditState(){return this.editState?{...this.editState}:null}getCellValue(e,t){let n=this.cachedRows.get(e);if(!n)return null;let r=this.columns[t];return r?this.getFieldValue(n,r.field):null}setCellValue(e,t,n){let r=this.cachedRows.get(e);if(!r||typeof r!=`object`)return;let i=this.columns[t];i&&this.setFieldValue(r,i.field,n)}getFieldValue(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}setFieldValue(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];t in i||(i[t]={}),i=i[t]}let a=r[r.length-1];i[a]=n}computeColumnPositions(){this.columnPositions=[0];let e=0;for(let t of this.columns)e+=t.width,this.columnPositions.push(e)}emitContentSize(){let e=this.columnPositions[this.columnPositions.length-1]??0,t=this.getDisplayHeight();this.emit({type:`SET_CONTENT_SIZE`,width:e,height:t})}emitHeaders(){let e=new Map;this.sortModel.forEach((t,n)=>{e.set(t.colId,{direction:t.direction,index:n+1})});for(let t=0;t<this.columns.length;t++){let n=this.columns[t],r=n.colId??n.field,i=e.get(r);this.emit({type:`UPDATE_HEADER`,colIndex:t,column:n,sortDirection:i?.direction,sortIndex:i?.index})}}getColumns(){return this.columns}getColumnPositions(){return[...this.columnPositions]}getRowCount(){return this.totalRows}getRowHeight(){return this.rowHeight}getHeaderHeight(){return this.headerHeight}getTotalWidth(){return this.columnPositions[this.columnPositions.length-1]??0}getTotalHeight(){return this.totalRows*this.rowHeight+this.headerHeight}getRowData(e){return this.cachedRows.get(e)}getDisplayYForRow(e){return this.getRowTranslateY(e)}isScalingActive(){return this.needsScaling()}getRowIndexAtDisplayY(e,t){if(!this.needsScaling())return Math.floor(e/this.rowHeight);let n=this.getDisplayHeight(),r=this.getVirtualHeight(),i=n-this.viewportHeight,a=e-(i>0?Math.min(1,Math.max(0,t/i)):0)*(n-r);return Math.floor(a/this.rowHeight)}getScrollTopForRow(e){if(!this.needsScaling())return Math.max(0,e*this.rowHeight);let t=this.getDisplayHeight(),n=Math.max(0,t-this.viewportHeight),r=this.totalRows>0?e/this.totalRows:0;return Math.min(n,Math.max(0,r*n))}getVisibleRowRange(){let e=this.getVirtualScrollTop(),t=Math.max(0,this.viewportHeight-this.headerHeight),n=Math.max(0,Math.ceil(e/this.rowHeight)),r=Math.min(this.totalRows-1,Math.floor((e+t)/this.rowHeight)-1);return{start:Math.min(n,r),end:r}}async refresh(){await this.fetchData(),this.syncSlots(),this.emitContentSize()}refreshSlotData(){this.refreshAllSlots()}async setDataSource(e){this.dataSource=e,await this.refresh()}setColumns(e){this.columns=e,this.computeColumnPositions(),this.emitContentSize(),this.emitHeaders(),this.syncSlots()}};function r(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 i(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;let n=Number(e),r=Number(t);return!isNaN(n)&&!isNaN(r)?n-r:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function a(e,t){return[...e].sort((e,n)=>{for(let{colId:a,direction:o}of t){let t=i(r(e,a),r(n,a));if(t!==0)return o===`asc`?t:-t}return 0})}typeof self<`u`&&self.onmessage!==void 0&&(self.onmessage=e=>{let{type:t,id:n,data:r,sortModel:i}=e.data;if(t===`sort`)try{let e=a(r,i);self.postMessage({type:`sorted`,id:n,data:e})}catch(e){self.postMessage({type:`error`,id:n,error:String(e)})}});var o=class{worker=null;workerUrl=null;pendingRequests=new Map;nextRequestId=0;isTerminated=!1;async sortInWorker(e,t){if(this.isTerminated)throw Error(`SortWorkerManager has been terminated`);this.worker||this.initializeWorker();let n=this.nextRequestId++;return new Promise((r,i)=>{this.pendingRequests.set(n,{resolve:r,reject:i});let a={type:`sort`,id:n,data:e,sortModel:t};this.worker.postMessage(a)})}async sortIndices(e,t){if(this.isTerminated)throw Error(`SortWorkerManager has been terminated`);this.worker||this.initializeWorker();let n=this.nextRequestId++,r=new Float64Array(e);return new Promise((e,i)=>{this.pendingRequests.set(n,{resolve:e,reject:i});let a={type:`sortIndices`,id:n,values:r,direction:t};this.worker.postMessage(a,[r.buffer])})}async sortMultiColumn(e,t){if(this.isTerminated)throw Error(`SortWorkerManager has been terminated`);this.worker||this.initializeWorker();let n=this.nextRequestId++,r=e.map(e=>new Float64Array(e)),i=new Int8Array(t.map(e=>e===`asc`?1:-1));return new Promise((e,t)=>{this.pendingRequests.set(n,{resolve:e,reject:t});let a={type:`sortMultiColumn`,id:n,columns:r,directions:i},o=r.map(e=>e.buffer);o.push(i.buffer),this.worker.postMessage(a,o)})}async sortStringHashes(e,t,n){if(this.isTerminated)throw Error(`SortWorkerManager has been terminated`);this.worker||this.initializeWorker();let r=this.nextRequestId++;return new Promise((i,a)=>{this.pendingRequests.set(r,{resolve:e=>{let{indices:r,collisionPairs:a}=e;a.length>0&&this.resolveCollisions(r,a,n,t),i(r)},reject:a});let o={type:`sortStringHashes`,id:r,hashChunks:e,direction:t},s=e.map(e=>e.buffer);this.worker.postMessage(o,s)})}resolveCollisions(e,t,n,r){let i=new Set;for(let e=0;e<t.length;e++)i.add(t[e]);if(i.size===0)return;let a=[],o=-1;for(let t=0;t<e.length;t++){let n=e[t];i.has(n)?o===-1&&(o=t):o!==-1&&(a.push({start:o,end:t}),o=-1)}o!==-1&&a.push({start:o,end:e.length});let s=r===`asc`?1:-1;for(let t of a){let r=Array.from(e.slice(t.start,t.end));r.sort((e,t)=>s*n[e].localeCompare(n[t]));for(let n=0;n<r.length;n++)e[t.start+n]=r[n]}}initializeWorker(){if(typeof Worker>`u`)throw Error(`Web Workers are not available in this environment`);let e=new Blob([`
|
|
2
|
+
`);try{await navigator.clipboard.writeText(t)}catch{let e=document.createElement(`textarea`);e.value=t,e.style.position=`fixed`,e.style.left=`-9999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}}clampPosition(e){let t=this.options.getRowCount(),n=this.options.getColumnCount();return{row:Math.max(0,Math.min(e.row,t-1)),col:Math.max(0,Math.min(e.col,n-1))}}},t=class{state=null;options;listeners=[];constructor(e){this.options=e}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e)}getState(){return this.state?{...this.state}:null}isActive(){return this.state!==null}startFillDrag(e){this.state={sourceRange:e,targetRow:e.endRow,targetCol:e.endCol},this.emit({type:`START_FILL`,sourceRange:e})}updateFillDrag(e,t){if(!this.state)return;let n=this.options.getRowCount(),r=this.options.getColumnCount();e=Math.max(0,Math.min(e,n-1)),t=Math.max(0,Math.min(t,r-1)),this.state.targetRow=e,this.state.targetCol=t,this.emit({type:`UPDATE_FILL`,targetRow:e,targetCol:t})}commitFillDrag(){if(!this.state)return;let{sourceRange:e,targetRow:t,targetCol:n}=this.state,r=this.calculateFilledCells(e,t,n);for(let{row:e,col:t,value:n}of r)this.options.setCellValue(e,t,n);this.emit({type:`COMMIT_FILL`,filledCells:r}),this.state=null}cancelFillDrag(){this.state&&(this.state=null,this.emit({type:`CANCEL_FILL`}))}calculateFilledCells(e,t,n){let r=[],i=Math.min(e.startRow,e.endRow),a=Math.max(e.startRow,e.endRow),o=Math.min(e.startCol,e.endCol),s=Math.max(e.startCol,e.endCol),c=t>a,l=t<i;if(c||l)for(let e=o;e<=s;e++){let n=this.getSourceColumnValues(i,a,e),o=this.detectPattern(n);if(c)for(let i=a+1;i<=t;i++){let t=i-a-1,s=this.applyPattern(o,n,t);r.push({row:i,col:e,value:s})}else if(l)for(let a=i-1;a>=t;a--){let t=i-a-1,s=this.applyPattern(o,n,t,!0);r.push({row:a,col:e,value:s})}}return r}getSourceColumnValues(e,t,n){let r=[];for(let i=e;i<=t;i++)r.push(this.options.getCellValue(i,n));return r}detectPattern(e){if(e.length===0)return{type:`constant`,value:null};if(e.length===1)return{type:`constant`,value:e[0]??null};let t=e.map(e=>typeof e==`number`?e:Number(e));if(t.every(e=>!isNaN(e))){let e=[];for(let n=1;n<t.length;n++)e.push(t[n]-t[n-1]);if(e.every(t=>t===e[0])&&e[0]!==void 0)return{type:`arithmetic`,start:t[0],step:e[0]}}return{type:`repeat`,values:e}}applyPattern(e,t,n,r=!1){switch(e.type){case`constant`:return e.value;case`arithmetic`:{let i=r?-(n+1):n+1;return(r?e.start:e.start+e.step*(t.length-1))+e.step*i}case`repeat`:{let t=e.values.length;if(t===0)return null;if(r){let r=(t-1-n%t+t)%t;return e.values[r]??null}return e.values[n%t]??null}}}},n=class{state={slots:new Map,rowToSlot:new Map,nextSlotId:0};options;listeners=[];batchListeners=[];constructor(e){this.options=e}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}onBatchInstruction(e){return this.batchListeners.push(e),()=>{this.batchListeners=this.batchListeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e);for(let t of this.batchListeners)t([e])}emitBatch(e){if(e.length!==0){for(let t of this.batchListeners)t(e);for(let t of e)for(let e of this.listeners)e(t)}}getSlotForRow(e){return this.state.rowToSlot.get(e)}getSlots(){return this.state.slots}syncSlots(){let e=this.options.getScrollTop(),t=this.options.getRowHeight(),n=this.options.getViewportHeight(),r=this.options.getTotalRows(),i=this.options.getOverscan(),a=Math.max(0,Math.floor(e/t)-i),o=Math.min(r-1,Math.ceil((e+n)/t)+i);if(r===0||o<a){this.destroyAllSlots();return}let s=new Set;for(let e=a;e<=o;e++)s.add(e);let c=[],l=[];for(let[e,t]of this.state.slots)s.has(t.rowIndex)?s.delete(t.rowIndex):(l.push(e),this.state.rowToSlot.delete(t.rowIndex));let u=Array.from(s);for(let e=0;e<u.length;e++){let t=u[e],n=this.options.getRowData(t);if(e<l.length){let r=l[e],i=this.state.slots.get(r),a=this.getRowTranslateY(t);i.rowIndex=t,i.rowData=n??{},i.translateY=a,this.state.rowToSlot.set(t,r),c.push({type:`ASSIGN_SLOT`,slotId:r,rowIndex:t,rowData:n??{}}),c.push({type:`MOVE_SLOT`,slotId:r,translateY:a})}else{let e=`slot-${this.state.nextSlotId++}`,r=this.getRowTranslateY(t),i={slotId:e,rowIndex:t,rowData:n??{},translateY:r};this.state.slots.set(e,i),this.state.rowToSlot.set(t,e),c.push({type:`CREATE_SLOT`,slotId:e}),c.push({type:`ASSIGN_SLOT`,slotId:e,rowIndex:t,rowData:n??{}}),c.push({type:`MOVE_SLOT`,slotId:e,translateY:r})}}for(let e=u.length;e<l.length;e++){let t=l[e];this.state.slots.delete(t),c.push({type:`DESTROY_SLOT`,slotId:t})}for(let[e,t]of this.state.slots){let n=this.getRowTranslateY(t.rowIndex);t.translateY!==n&&(t.translateY=n,c.push({type:`MOVE_SLOT`,slotId:e,translateY:n}))}this.emitBatch(c)}destroyAllSlots(){let e=[];for(let t of this.state.slots.keys())e.push({type:`DESTROY_SLOT`,slotId:t});this.state.slots.clear(),this.state.rowToSlot.clear(),this.emitBatch(e)}refreshAllSlots(){let e=[],t=this.options.getTotalRows();for(let[n,r]of this.state.slots)if(r.rowIndex>=0&&r.rowIndex<t){let t=this.options.getRowData(r.rowIndex),i=this.getRowTranslateY(r.rowIndex);r.rowData=t??{},r.translateY=i,e.push({type:`ASSIGN_SLOT`,slotId:n,rowIndex:r.rowIndex,rowData:t??{}}),e.push({type:`MOVE_SLOT`,slotId:n,translateY:i})}this.emitBatch(e),this.syncSlots()}updateSlot(e){let t=this.state.rowToSlot.get(e);if(t){let n=this.options.getRowData(e);n&&this.emit({type:`ASSIGN_SLOT`,slotId:t,rowIndex:e,rowData:n})}}getRowTranslateY(e){let t=this.options.getRowHeight(),n=this.options.getHeaderHeight(),r=this.options.getScrollRatio(),i=this.options.getVirtualContentHeight(),a=this.options.getScrollTop(),o=e*t+n;if(r>=1)return o;let s=a,c=o-(s-s*r);return Math.max(0,Math.min(c,i))}},r=class{editState=null;options;listeners=[];constructor(e){this.options=e}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e)}getState(){return this.editState?{...this.editState}:null}isEditing(){return this.editState!==null}isEditingCell(e,t){return this.editState!==null&&this.editState.row===e&&this.editState.col===t}startEdit(e,t){let n=this.options.getColumn(t);if(!n||n.editable!==!0)return!1;let r=this.options.getCellValue(e,t);return this.editState={row:e,col:t,initialValue:r,currentValue:r},this.emit({type:`START_EDIT`,row:e,col:t,initialValue:r}),!0}updateValue(e){this.editState&&(this.editState.currentValue=e)}commit(){if(!this.editState)return;let{row:e,col:t,currentValue:n}=this.editState;this.options.setCellValue(e,t,n),this.emit({type:`COMMIT_EDIT`,row:e,col:t,value:n}),this.editState=null,this.emit({type:`STOP_EDIT`}),this.options.onCommit?.(e,t,n)}cancel(){this.editState=null,this.emit({type:`STOP_EDIT`})}},i=class{core;deps;isDraggingSelection=!1;isDraggingFill=!1;fillSourceRange=null;fillTarget=null;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps={...this.deps,...e}}getDragState(){return{isDragging:this.isDraggingSelection||this.isDraggingFill,dragType:this.isDraggingFill?`fill`:this.isDraggingSelection?`selection`:null,fillSourceRange:this.fillSourceRange,fillTarget:this.fillTarget}}handleCellMouseDown(e,t,n){return n.button!==0||this.core.getEditState()!==null?{preventDefault:!1,stopPropagation:!1}:(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)}handleFillHandleMouseDown(e,t,n){if(!e&&!t)return{preventDefault:!1,stopPropagation:!1};let r=t??{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};return this.core.fill.startFillDrag(r),this.fillSourceRange=r,this.fillTarget={row:Math.max(r.startRow,r.endRow),col:Math.max(r.startCol,r.endCol)},this.isDraggingFill=!0,{preventDefault:!0,stopPropagation:!0,startDrag:`fill`}}handleHeaderClick(e,t){let n=this.core.getSortModel().find(t=>t.colId===e)?.direction,r=n==null?`asc`:n===`asc`?`desc`:null;this.core.setSort(e,r,t)}startSelectionDrag(){this.isDraggingSelection=!0}handleDragMove(e,t){if(!this.isDraggingSelection&&!this.isDraggingFill)return null;let{top:n,left:r,width:i,height:a,scrollTop:o,scrollLeft:s}=t,c=this.deps.getHeaderHeight(),l=this.deps.getColumnPositions(),u=this.deps.getColumnCount(),d=e.clientX-r+s,f=e.clientY-n-c,p=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(f,o),this.core.getRowCount()-1)),m=Math.max(0,Math.min(this.findColumnAtX(d,l),u-1));this.isDraggingSelection&&this.core.selection.startSelection({row:p,col:m},{shift:!0}),this.isDraggingFill&&(this.core.fill.updateFillDrag(p,m),this.fillTarget={row:p,col:m});let h=e.clientY-n,g=e.clientX-r;return{targetRow:p,targetCol:m,autoScroll:this.calculateAutoScroll(h,g,a,i,c)}}handleDragEnd(){this.isDraggingFill&&(this.core.fill.commitFillDrag(),this.core.refreshSlotData()),this.isDraggingSelection=!1,this.isDraggingFill=!1,this.fillSourceRange=null,this.fillTarget=null}handleWheel(e,t,n){return this.core.isScalingActive()?{dy:e*n,dx:t*n}:null}handleKeyDown(e,t,n,r){if(r||n&&e.key!==`Enter`&&e.key!==`Escape`&&e.key!==`Tab`)return{preventDefault:!1};let{selection:i}=this.core,a=e.shiftKey,o=e.ctrlKey||e.metaKey,s=(e=>{switch(e){case`ArrowUp`:return`up`;case`ArrowDown`:return`down`;case`ArrowLeft`:return`left`;case`ArrowRight`:return`right`;default:return null}})(e.key);if(s)return i.moveFocus(s,a),{preventDefault:!0,scrollToCell:i.getActiveCell()??void 0};switch(e.key){case`Enter`:return n?this.core.commitEdit():t&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Escape`:return n?this.core.cancelEdit():i.clearSelection(),{preventDefault:!0};case`Tab`:return n&&this.core.commitEdit(),i.moveFocus(a?`left`:`right`,!1),{preventDefault:!0};case`a`:if(o)return i.selectAll(),{preventDefault:!0};break;case`c`:if(o)return i.copySelectionToClipboard(),{preventDefault:!0};break;case`F2`:return t&&!n&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Delete`:case`Backspace`:if(t&&!n)return this.core.startEdit(t.row,t.col),{preventDefault:!0};break;default:t&&!n&&!o&&e.key.length===1&&this.core.startEdit(t.row,t.col);break}return{preventDefault:!1}}findColumnAtX(e,t){for(let n=0;n<t.length-1;n++)if(e>=t[n]&&e<t[n+1])return n;return e>=t[t.length-1]?t.length-2:0}calculateAutoScroll(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}};const a=1e7;var o=class{columns;dataSource;rowHeight;headerHeight;overscan;sortingEnabled;scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;cachedRows=new Map;totalRows=0;currentPageIndex=0;pageSize=1e6;sortModel=[];filterModel={};openFilterColIndex=null;selection;fill;input;slotPool;editManager;columnPositions=[];listeners=[];batchListeners=[];naturalContentHeight=0;virtualContentHeight=0;scrollRatio=1;constructor(a){this.columns=a.columns,this.dataSource=a.dataSource,this.rowHeight=a.rowHeight,this.headerHeight=a.headerHeight??a.rowHeight,this.overscan=a.overscan??3,this.sortingEnabled=a.sortingEnabled??!0,this.computeColumnPositions(),this.selection=new e({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getRowData:e=>this.cachedRows.get(e),getColumn:e=>this.columns[e]}),this.selection.onInstruction(e=>this.emit(e)),this.fill=new t({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getColumn:e=>this.columns[e],setCellValue:(e,t,n)=>this.setCellValue(e,t,n)}),this.fill.onInstruction(e=>this.emit(e)),this.slotPool=new n({getRowHeight:()=>this.rowHeight,getHeaderHeight:()=>this.headerHeight,getOverscan:()=>this.overscan,getScrollTop:()=>this.scrollTop,getViewportHeight:()=>this.viewportHeight,getTotalRows:()=>this.totalRows,getScrollRatio:()=>this.scrollRatio,getVirtualContentHeight:()=>this.virtualContentHeight,getRowData:e=>this.cachedRows.get(e)}),this.slotPool.onBatchInstruction(e=>this.emitBatch(e)),this.editManager=new r({getColumn:e=>this.columns[e],getCellValue:(e,t)=>this.getCellValue(e,t),setCellValue:(e,t,n)=>this.setCellValue(e,t,n),onCommit:e=>{this.slotPool.updateSlot(e)}}),this.editManager.onInstruction(e=>this.emit(e)),this.input=new i(this,{getHeaderHeight:()=>this.headerHeight,getRowHeight:()=>this.rowHeight,getColumnPositions:()=>this.columnPositions,getColumnCount:()=>this.columns.length})}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}onBatchInstruction(e){return this.batchListeners.push(e),()=>{this.batchListeners=this.batchListeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e);for(let t of this.batchListeners)t([e])}emitBatch(e){if(e.length!==0){for(let t of this.batchListeners)t(e);for(let t of e)for(let e of this.listeners)e(t)}}async initialize(){await this.fetchData(),this.slotPool.syncSlots(),this.emitContentSize(),this.emitHeaders()}setViewport(e,t,n,r){let i=this.scrollRatio<1?e/this.scrollRatio:e;if(!(this.scrollTop!==i||this.scrollLeft!==t||this.viewportWidth!==n||this.viewportHeight!==r))return;this.scrollTop=i,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r,this.slotPool.syncSlots();let a=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:a.start,end:a.end})}async fetchData(){this.emit({type:`DATA_LOADING`});try{let e={pagination:{pageIndex:this.currentPageIndex,pageSize:this.pageSize},sort:this.sortModel.length>0?this.sortModel:void 0,filter:Object.keys(this.filterModel).length>0?this.filterModel:void 0},t=await this.dataSource.fetch(e);this.cachedRows.clear(),t.rows.forEach((e,t)=>{this.cachedRows.set(this.currentPageIndex*this.pageSize+t,e)}),this.totalRows=t.totalRows,t.totalRows>t.rows.length&&this.currentPageIndex===0&&await this.fetchAllData(),this.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}}async fetchAllData(){let e=Math.ceil(this.totalRows/this.pageSize);for(let t=1;t<e;t++){let e={pagination:{pageIndex:t,pageSize:this.pageSize},sort:this.sortModel.length>0?this.sortModel:void 0,filter:Object.keys(this.filterModel).length>0?this.filterModel:void 0};(await this.dataSource.fetch(e)).rows.forEach((e,n)=>{this.cachedRows.set(t*this.pageSize+n,e)})}}async setSort(e,t,n=!1){if(!this.sortingEnabled||this.columns.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.fetchData(),this.slotPool.refreshAllSlots(),this.emitHeaders()}async setFilter(e,t){this.columns.find(t=>(t.colId??t.field)===e)?.filterable!==!1&&(t===null||typeof t==`string`&&t.trim()===``||typeof t==`object`&&t.conditions&&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.fetchData(),this.slotPool.refreshAllSlots(),this.emitContentSize(),this.emitHeaders())}hasActiveFilter(e){let t=this.filterModel[e];return t?t.conditions.length>0:!1}isColumnSortable(e){return this.sortingEnabled?this.columns[e]?.sortable!==!1:!1}isColumnFilterable(e){return this.columns[e]?.filterable!==!1}getDistinctValuesForColumn(e,t=500){let n=this.columns.find(t=>(t.colId??t.field)===e);if(!n)return[];let r=new Map;for(let e of this.cachedRows.values()){let i=this.getFieldValue(e,n.field);if(Array.isArray(i)){let e=[...i].sort((e,t)=>String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:`base`})),n=JSON.stringify(e);if(!r.has(n)&&(r.set(n,e),r.size>=t))break}else{let e=JSON.stringify(i);if(!r.has(e)&&(r.set(e,i),r.size>=t))break}}let i=Array.from(r.values());return i.sort((e,t)=>{let n=Array.isArray(e)?e.join(`, `):String(e??``),r=Array.isArray(t)?t.join(`, `):String(t??``);return n.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})}),i}openFilterPopup(e,t){if(this.openFilterColIndex===e){this.closeFilterPopup();return}let n=this.columns[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`})}getSortModel(){return[...this.sortModel]}getFilterModel(){return{...this.filterModel}}startEdit(e,t){this.editManager.startEdit(e,t)}updateEditValue(e){this.editManager.updateValue(e)}commitEdit(){this.editManager.commit()}cancelEdit(){this.editManager.cancel()}getEditState(){return this.editManager.getState()}getCellValue(e,t){let n=this.cachedRows.get(e);if(!n)return null;let r=this.columns[t];return r?this.getFieldValue(n,r.field):null}setCellValue(e,t,n){let r=this.cachedRows.get(e);if(!r||typeof r!=`object`)return;let i=this.columns[t];i&&this.setFieldValue(r,i.field,n)}getFieldValue(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}setFieldValue(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];t in i||(i[t]={}),i=i[t]}let a=r[r.length-1];i[a]=n}computeColumnPositions(){this.columnPositions=[0];let e=0;for(let t of this.columns)e+=t.width,this.columnPositions.push(e)}emitContentSize(){let e=this.columnPositions[this.columnPositions.length-1]??0;this.naturalContentHeight=this.totalRows*this.rowHeight+this.headerHeight,this.naturalContentHeight>a?(this.virtualContentHeight=a,this.scrollRatio=a/this.naturalContentHeight):(this.virtualContentHeight=this.naturalContentHeight,this.scrollRatio=1),this.emit({type:`SET_CONTENT_SIZE`,width:e,height:this.virtualContentHeight})}emitHeaders(){let e=new Map;this.sortModel.forEach((t,n)=>{e.set(t.colId,{direction:t.direction,index:n+1})});for(let t=0;t<this.columns.length;t++){let n=this.columns[t],r=n.colId??n.field,i=e.get(r);this.emit({type:`UPDATE_HEADER`,colIndex:t,column:n,sortDirection:i?.direction,sortIndex:i?.index,sortable:this.isColumnSortable(t),filterable:this.isColumnFilterable(t),hasFilter:this.hasActiveFilter(r)})}}getColumns(){return this.columns}getColumnPositions(){return[...this.columnPositions]}getRowCount(){return this.totalRows}getRowHeight(){return this.rowHeight}getHeaderHeight(){return this.headerHeight}getTotalWidth(){return this.columnPositions[this.columnPositions.length-1]??0}getTotalHeight(){return this.virtualContentHeight||this.totalRows*this.rowHeight+this.headerHeight}isScalingActive(){return this.scrollRatio<1}getNaturalHeight(){return this.naturalContentHeight||this.totalRows*this.rowHeight+this.headerHeight}getScrollRatio(){return this.scrollRatio}getVisibleRowRange(){let e=this.viewportHeight-this.headerHeight,t=Math.max(0,Math.floor(this.scrollTop/this.rowHeight)),n=Math.min(this.totalRows-1,Math.ceil((this.scrollTop+e)/this.rowHeight)-1);return{start:t,end:Math.max(t,n)}}getScrollTopForRow(e){return e*this.rowHeight*this.scrollRatio}getRowIndexAtDisplayY(e,t){let n=e+(this.scrollRatio<1?t/this.scrollRatio:t);return Math.floor(n/this.rowHeight)}getRowData(e){return this.cachedRows.get(e)}async refresh(){await this.fetchData(),this.slotPool.refreshAllSlots(),this.emitContentSize();let e=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:e.start,end:e.end})}refreshSlotData(){this.slotPool.refreshAllSlots()}async setDataSource(e){this.dataSource=e,await this.refresh()}setColumns(e){this.columns=e,this.computeColumnPositions(),this.emitContentSize(),this.emitHeaders(),this.slotPool.syncSlots()}};function s(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 c(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;let n=Number(e),r=Number(t);return!isNaN(n)&&!isNaN(r)?n-r:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function l(e,t){return[...e].sort((e,n)=>{for(let{colId:r,direction:i}of t){let t=c(s(e,r),s(n,r));if(t!==0)return i===`asc`?t:-t}return 0})}typeof self<`u`&&self.onmessage!==void 0&&(self.onmessage=e=>{let{type:t,id:n,data:r,sortModel:i}=e.data;if(t===`sort`)try{let e=l(r,i);self.postMessage({type:`sorted`,id:n,data:e})}catch(e){self.postMessage({type:`error`,id:n,error:String(e)})}});var u=class{worker=null;workerUrl=null;pendingRequests=new Map;nextRequestId=0;isTerminated=!1;async sortInWorker(e,t){if(this.isTerminated)throw Error(`SortWorkerManager has been terminated`);this.worker||this.initializeWorker();let n=this.nextRequestId++;return new Promise((r,i)=>{this.pendingRequests.set(n,{resolve:r,reject:i});let a={type:`sort`,id:n,data:e,sortModel:t};this.worker.postMessage(a)})}async sortIndices(e,t){if(this.isTerminated)throw Error(`SortWorkerManager has been terminated`);this.worker||this.initializeWorker();let n=this.nextRequestId++,r=new Float64Array(e);return new Promise((e,i)=>{this.pendingRequests.set(n,{resolve:e,reject:i});let a={type:`sortIndices`,id:n,values:r,direction:t};this.worker.postMessage(a,[r.buffer])})}async sortMultiColumn(e,t){if(this.isTerminated)throw Error(`SortWorkerManager has been terminated`);this.worker||this.initializeWorker();let n=this.nextRequestId++,r=e.map(e=>new Float64Array(e)),i=new Int8Array(t.map(e=>e===`asc`?1:-1));return new Promise((e,t)=>{this.pendingRequests.set(n,{resolve:e,reject:t});let a={type:`sortMultiColumn`,id:n,columns:r,directions:i},o=r.map(e=>e.buffer);o.push(i.buffer),this.worker.postMessage(a,o)})}async sortStringHashes(e,t,n){if(this.isTerminated)throw Error(`SortWorkerManager has been terminated`);this.worker||this.initializeWorker();let r=this.nextRequestId++;return new Promise((i,a)=>{this.pendingRequests.set(r,{resolve:e=>{let{indices:r,collisionRuns:a}=e;a.length>0&&this.resolveCollisions(r,a,n,t),i(r)},reject:a});let o={type:`sortStringHashes`,id:r,hashChunks:e,direction:t},s=e.map(e=>e.buffer);this.worker.postMessage(o,s)})}resolveCollisions(e,t,n,r){let i=r===`asc`?1:-1;for(let r=0;r<t.length;r+=2){let a=t[r],o=t[r+1],s=Array.from(e.slice(a,o)),c=n[s[0]],l=!0;for(let e=1;e<s.length;e++)if(n[s[e]]!==c){l=!1;break}if(!l){s.sort((e,t)=>i*n[e].localeCompare(n[t]));for(let t=0;t<s.length;t++)e[a+t]=s[t]}}}initializeWorker(){if(typeof Worker>`u`)throw Error(`Web Workers are not available in this environment`);let e=new Blob([`
|
|
3
3
|
// Inline sort worker code
|
|
4
4
|
function getFieldValue(row, field) {
|
|
5
5
|
const parts = field.split(".");
|
|
@@ -97,8 +97,8 @@ function sortStringHashes(hashChunks, direction) {
|
|
|
97
97
|
for (let i = 0; i < len; i++) indices[i] = i;
|
|
98
98
|
|
|
99
99
|
const mult = direction === "asc" ? 1 : -1;
|
|
100
|
-
const collisions = []; // Track collision pairs
|
|
101
100
|
|
|
101
|
+
// Sort by hash only (no collision tracking during sort)
|
|
102
102
|
indices.sort((a, b) => {
|
|
103
103
|
for (let c = 0; c < numChunks; c++) {
|
|
104
104
|
const va = hashChunks[c][a];
|
|
@@ -106,12 +106,38 @@ function sortStringHashes(hashChunks, direction) {
|
|
|
106
106
|
if (va < vb) return -1 * mult;
|
|
107
107
|
if (va > vb) return 1 * mult;
|
|
108
108
|
}
|
|
109
|
-
// All chunks equal = collision, record for fallback
|
|
110
|
-
collisions.push(a, b);
|
|
111
109
|
return 0; // Stable sort preserves original order
|
|
112
110
|
});
|
|
113
111
|
|
|
114
|
-
|
|
112
|
+
// Detect collision runs AFTER sorting (much more efficient)
|
|
113
|
+
// Find runs of consecutive indices with identical hashes
|
|
114
|
+
const collisionRuns = []; // [start1, end1, start2, end2, ...]
|
|
115
|
+
let runStart = 0;
|
|
116
|
+
|
|
117
|
+
for (let i = 1; i <= len; i++) {
|
|
118
|
+
// Check if current element has different hash than previous
|
|
119
|
+
let isDifferent = i === len; // End of array is always "different"
|
|
120
|
+
if (!isDifferent) {
|
|
121
|
+
const prevIdx = indices[i - 1];
|
|
122
|
+
const currIdx = indices[i];
|
|
123
|
+
for (let c = 0; c < numChunks; c++) {
|
|
124
|
+
if (hashChunks[c][prevIdx] !== hashChunks[c][currIdx]) {
|
|
125
|
+
isDifferent = true;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (isDifferent) {
|
|
132
|
+
// End of a run - only record if run has more than 1 element
|
|
133
|
+
if (i - runStart > 1) {
|
|
134
|
+
collisionRuns.push(runStart, i);
|
|
135
|
+
}
|
|
136
|
+
runStart = i;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return { indices, collisionRuns: new Uint32Array(collisionRuns) };
|
|
115
141
|
}
|
|
116
142
|
|
|
117
143
|
self.onmessage = function(e) {
|
|
@@ -147,13 +173,743 @@ self.onmessage = function(e) {
|
|
|
147
173
|
const { hashChunks, direction } = e.data;
|
|
148
174
|
const result = sortStringHashes(hashChunks, direction);
|
|
149
175
|
self.postMessage(
|
|
150
|
-
{ type: "sortedStringHashes", id, indices: result.indices,
|
|
151
|
-
[result.indices.buffer, result.
|
|
176
|
+
{ type: "sortedStringHashes", id, indices: result.indices, collisionRuns: result.collisionRuns },
|
|
177
|
+
[result.indices.buffer, result.collisionRuns.buffer]
|
|
152
178
|
);
|
|
153
179
|
} catch (error) {
|
|
154
180
|
self.postMessage({ type: "error", id, error: String(error) });
|
|
155
181
|
}
|
|
156
182
|
}
|
|
157
183
|
};
|
|
158
|
-
`],{type:`application/javascript`});this.workerUrl=URL.createObjectURL(e),this.worker=new Worker(this.workerUrl),this.worker.onmessage=e=>{let{id:t}=e.data,n=this.pendingRequests.get(t);n&&(this.pendingRequests.delete(t),e.data.type===`sorted`?n.resolve(e.data.data):e.data.type===`sortedIndices`||e.data.type===`sortedMultiColumn`?n.resolve(e.data.indices):e.data.type===`sortedStringHashes`?n.resolve({indices:e.data.indices,collisionPairs:e.data.collisionPairs}):e.data.type===`error`&&n.reject(Error(e.data.error)))},this.worker.onerror=e=>{for(let[t,n]of this.pendingRequests)n.reject(Error(`Worker error: ${e.message}`)),this.pendingRequests.delete(t)}}terminate(){this.worker&&=(this.worker.terminate(),null),this.workerUrl&&=(URL.revokeObjectURL(this.workerUrl),null);for(let[,e]of this.pendingRequests)e.reject(Error(`Worker terminated`));this.pendingRequests.clear(),this.isTerminated=!0}isAvailable(){return!this.isTerminated&&typeof Worker<`u`}};let s=null;function c(){return s||=new o,s}function l(){s&&=(s.terminate(),null)}function u(e,t={}){let{getFieldValue:n=h,useWorker:r=!0}=t,i=r?new o:null;return{async fetch(t){let r=[...e];if(t.filter&&Object.keys(t.filter).length>0&&(r=g(r,t.filter,n)),t.sort&&t.sort.length>0)if(i&&i.isAvailable()&&r.length>=2e5){let e;if(t.sort.length===1){let{colId:a,direction:o}=t.sort[0],s=!1;for(let e of r){let t=n(e,a);if(t!=null){s=typeof t==`string`;break}}if(s){let t=[],s=Array.from({length:3},()=>[]);for(let e of r){let r=n(e,a),i=r==null?``:String(r);t.push(i);let o=m(i);for(let e=0;e<3;e++)s[e].push(o[e])}let c=s.map(e=>new Float64Array(e));e=await i.sortStringHashes(c,o,t)}else{let t=r.map(e=>f(n(e,a)));e=await i.sortIndices(t,o)}}else{let a=[],o=[];for(let{colId:e,direction:i}of t.sort){let t=r.map(t=>f(n(t,e)));a.push(t),o.push(i)}e=await i.sortMultiColumn(a,o)}let a=Array(r.length);for(let t=0;t<e.length;t++)a[t]=r[e[t]];r=a}else r=_(r,t.sort,n);let a=r.length,{pageIndex:o,pageSize:s}=t.pagination,c=o*s;return{rows:r.slice(c,c+s),totalRows:a}}}}function d(e){return{async fetch(t){return e(t)}}}function f(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 p(e);let t=Number(e);return isNaN(t)?0:t}function p(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.charCodeAt(e),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 m(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.charCodeAt(n):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 h(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 g(e,t,n){let r=Object.entries(t).filter(([,e])=>e!==``);return r.length===0?e:e.filter(e=>{for(let[t,i]of r){let r=n(e,t),a=String(r??``).toLowerCase(),o=i.toLowerCase();if(!a.includes(o))return!1}return!0})}function _(e,t,n){return[...e].sort((e,r)=>{for(let{colId:i,direction:a}of t){let t=v(n(e,i),n(r,i));if(t!==0)return a===`asc`?t:-t}return 0})}function v(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;let n=Number(e),r=Number(t);return!isNaN(n)&&!isNaN(r)?n-r:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function y(e){return u(e)}export{t as FillManager,n as GridCore,e as SelectionManager,o as SortWorkerManager,u as createClientDataSource,y as createDataSourceFromArray,d as createServerDataSource,c as getSharedSortWorker,l as terminateSharedSortWorker};
|
|
159
|
-
|
|
184
|
+
`],{type:`application/javascript`});this.workerUrl=URL.createObjectURL(e),this.worker=new Worker(this.workerUrl),this.worker.onmessage=e=>{let{id:t}=e.data,n=this.pendingRequests.get(t);n&&(this.pendingRequests.delete(t),e.data.type===`sorted`?n.resolve(e.data.data):e.data.type===`sortedIndices`||e.data.type===`sortedMultiColumn`?n.resolve(e.data.indices):e.data.type===`sortedStringHashes`?n.resolve({indices:e.data.indices,collisionRuns:e.data.collisionRuns}):e.data.type===`error`&&n.reject(Error(e.data.error)))},this.worker.onerror=e=>{for(let[t,n]of this.pendingRequests)n.reject(Error(`Worker error: ${e.message}`)),this.pendingRequests.delete(t)}}terminate(){this.worker&&=(this.worker.terminate(),null),this.workerUrl&&=(URL.revokeObjectURL(this.workerUrl),null);for(let[,e]of this.pendingRequests)e.reject(Error(`Worker terminated`));this.pendingRequests.clear(),this.isTerminated=!0}isAvailable(){return!this.isTerminated&&typeof Worker<`u`}};let d=null;function f(){return d||=new u,d}function p(){d&&=(d.terminate(),null)}function m(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.charCodeAt(e),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 h(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.charCodeAt(n):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 g(e){if(e==null)return Number.MAX_VALUE;if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:m(e.join(`, `));if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return m(e);let t=Number(e);return isNaN(t)?0:t}function ee(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(`, `):String(e??``),r=Array.isArray(t)?t.join(`, `):String(t??``);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!isNaN(i)&&!isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function te(e,t,n){return[...e].sort((e,r)=>{for(let{colId:i,direction:a}of t){let t=ee(n(e,i),n(r,i));if(t!==0)return a===`asc`?t:-t}return 0})}function _(e,t,n){let r=Object.entries(t).filter(([,e])=>typeof e==`string`?e.trim()!==``:e.conditions&&e.conditions.length>0);return r.length===0?e:e.filter(e=>{for(let[t,i]of r){let r=n(e,t);if(typeof i==`string`){if(!String(r??``).toLowerCase().includes(i.toLowerCase()))return!1;continue}if(!v(r,i))return!1}return!0})}function v(e,t){if(t.conditions.length===0)return!0;let n=t.conditions[0];if(!n)return!0;let r=y(e,n);for(let n=1;n<t.conditions.length;n++){let i=t.conditions[n-1],a=t.conditions[n],o=i.nextOperator??t.combination,s=y(e,a);o===`and`?r&&=s:r||=s}return r}function y(e,t){switch(t.type){case`text`:return ne(e,t);case`number`:return b(e,t);case`date`:return S(e,t);default:return!0}}function ne(e,t){let n=e==null||e===``||Array.isArray(e)&&e.length===0;if(t.selectedValues&&t.selectedValues.size>0){let r=t.includeBlank===!0&&n;if(Array.isArray(e)){let n=[...e].sort((e,t)=>String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:`base`})).join(`, `);return t.selectedValues.has(n)||r}let i=String(e??``);return t.selectedValues.has(i)||r}let r=String(e??``).toLowerCase(),i=String(t.value??``).toLowerCase();switch(t.operator){case`contains`:return r.includes(i);case`notContains`:return!r.includes(i);case`equals`:return r===i;case`notEquals`:return r!==i;case`startsWith`:return r.startsWith(i);case`endsWith`:return r.endsWith(i);case`blank`:return n;case`notBlank`:return!n;default:return!0}}function b(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=Number(e);if(isNaN(r))return!1;let i=t.value??0,a=t.valueTo??0;switch(t.operator){case`=`:return r===i;case`!=`:return r!==i;case`>`:return r>i;case`<`:return r<i;case`>=`:return r>=i;case`<=`:return r<=i;case`between`:return r>=i&&r<=a;default:return!0}}function x(e,t){return e.toDateString()===t.toDateString()}function S(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(String(e));if(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??``)),o=r.getTime(),s=i.getTime(),c=a.getTime();switch(t.operator){case`=`:return x(r,i);case`!=`:return!x(r,i);case`>`:return o>s;case`<`:return o<s;case`between`:return o>=s&&o<=c;default:return!0}}function re(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 C(e,t={}){let{getFieldValue:n=re,useWorker:r=!0}=t,i=r?new u:null;return{async fetch(t){let r=[...e];if(t.filter&&Object.keys(t.filter).length>0&&(r=_(r,t.filter,n)),t.sort&&t.sort.length>0)if(i&&i.isAvailable()&&r.length>=2e5){let e;if(t.sort.length===1){let{colId:a,direction:o}=t.sort[0],s=!1;for(let e of r){let t=n(e,a);if(t!=null){s=typeof t==`string`||Array.isArray(t);break}}if(s){let t=[],s=Array.from({length:3},()=>[]);for(let e of r){let r=n(e,a),i=r==null?``:Array.isArray(r)?r.join(`, `):String(r);t.push(i);let o=h(i);for(let e=0;e<3;e++)s[e].push(o[e])}let c=s.map(e=>new Float64Array(e));e=await i.sortStringHashes(c,o,t)}else{let t=r.map(e=>g(n(e,a)));e=await i.sortIndices(t,o)}}else{let a=[],o=[];for(let{colId:e,direction:i}of t.sort){let t=r.map(t=>g(n(t,e)));a.push(t),o.push(i)}e=await i.sortMultiColumn(a,o)}let a=Array(r.length);for(let t=0;t<e.length;t++)a[t]=r[e[t]];r=a}else r=te(r,t.sort,n);let a=r.length,{pageIndex:o,pageSize:s}=t.pagination,c=o*s;return{rows:r.slice(c,c+s),totalRows:a}}}}function w(e){return C(e)}function T(e){return{async fetch(t){return e(t)}}}function E(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 D(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[r.length-1]]=n)}function O(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.charCodeAt(e),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(`, `):String(e??``),r=Array.isArray(t)?t.join(`, `):String(t??``);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!isNaN(i)&&!isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function A(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 O(e);let t=Number(e);return isNaN(t)?0:t}function ie(e,t){let n=[];for(let r of t.sortModel){let i=A(t.getFieldValue(e,r.colId));n.push(i)}return n}function j(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 M(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 N(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function P(e,t){let n=e==null||e===``||Array.isArray(e)&&e.length===0;if(t.selectedValues&&t.selectedValues.size>0){let r=t.includeBlank===!0&&n;if(Array.isArray(e)){let n=[...e].sort((e,t)=>String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:`base`})).join(`, `);return t.selectedValues.has(n)||r}let i=String(e??``);return t.selectedValues.has(i)||r}let r=String(e??``).toLowerCase(),i=String(t.value??``).toLowerCase();switch(t.operator){case`contains`:return r.includes(i);case`notContains`:return!r.includes(i);case`equals`:return r===i;case`notEquals`:return r!==i;case`startsWith`:return r.startsWith(i);case`endsWith`:return r.endsWith(i);case`blank`:return n;case`notBlank`:return!n;default:return!0}}function F(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:parseFloat(String(e));if(isNaN(r))return!1;let i=t.value??0,a=t.valueTo??0;switch(t.operator){case`=`:return r===i;case`!=`:return r!==i;case`>`:return r>i;case`<`:return r<i;case`>=`:return r>=i;case`<=`:return r<=i;case`between`:return r>=i&&r<=a;default:return!0}}function I(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(String(e));if(isNaN(r.getTime()))return!1;let i=t.value?t.value instanceof Date?t.value:new Date(t.value):new Date,a=t.valueTo?t.valueTo instanceof Date?t.valueTo:new Date(t.valueTo):new Date;switch(t.operator){case`=`:return N(r,i);case`!=`:return!N(r,i);case`>`:return r>i;case`<`:return r<i;case`between`:return r>=i&&r<=a;default:return!0}}function L(e,t){switch(t.type){case`text`:return P(e,t);case`number`:return F(e,t);case`date`:return I(e,t);default:return!0}}function R(e,t){if(!t.conditions||!t.conditions.length)return!0;let n=t.conditions[0];if(!n)return!0;let r=L(e,n);for(let n=1;n<t.conditions.length;n++){let i=t.conditions[n-1],a=t.conditions[n],o=i.nextOperator??t.combination,s=L(e,a);o===`and`?r&&=s:r||=s}return r}function z(e,t,n){let r=Object.entries(t).filter(([,e])=>e!=null);if(r.length===0)return!0;for(let[t,i]of r){let r=n(e,t);if(typeof i==`string`){if(!String(r??``).toLowerCase().includes(i.toLowerCase()))return!1;continue}if(!R(r,i))return!1}return!0}var B=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:t.getRowId,getFieldValue:t.getFieldValue??E},this.setData(e)}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){e.sort&&this.setSortModel(e.sort),e.filter&&this.setFilterModel(e.filter);let t=this.getVisibleIndices(),n=t.length,{pageIndex:r,pageSize:i}=e.pagination,a=r*i,o=Math.min(a+i,n),s=[];for(let e=a;e<o;e++){let n=t[e];n!==void 0&&s.push(this.rows[n])}return{rows:s,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}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):[]}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){t.sort((e,t)=>t-e);for(let e of t)this.removeRowByIndex(e)}}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(D(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=ie(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=j(i,a,this.sortModel);return o===null?M(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).filter(([,e])=>e!=null).length!==0)for(let e=0;e<this.rows.length;e++)this.rowPassesFilter(this.rows[e])&&this.filteredIndices.add(e)}rowPassesFilter(e){return z(e,this.filterModel,this.options.getFieldValue)}getVisibleIndices(){return Object.entries(this.filterModel).filter(([,e])=>e!=null).length>0?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))if(r!=null&&t===`add`){let e=this.distinctValues.get(n);if(e||(e=new Set,this.distinctValues.set(n,e)),Array.isArray(r))for(let t of r)t!=null&&e.add(t);else e.add(r)}}}updateDistinctValueForField(e,t,n){if(n!=null){let t=this.distinctValues.get(e);if(t||(t=new Set,this.distinctValues.set(e,t)),Array.isArray(n))for(let e of n)e!=null&&t.add(e);else t.add(n)}}},V=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`:this.options.store.removeRows(n.rowIds),t.removed+=n.rowIds.length;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)}}};function H(e,t){let{getRowId:n,getFieldValue:r,debounceMs:i=50,onTransactionProcessed:a}=t,o=new B(e,{getRowId:n,getFieldValue:r}),s=new Set,c=new V({debounceMs:i,store:o,onProcessed:e=>{a?.(e);for(let t of s)t(e)}});return{async fetch(e){return c.hasPending()&&await c.flush(),o.query(e)},addRows(e){c.add(e)},removeRows(e){c.remove(e)},updateCell(e,t,n){c.updateCell(e,t,n)},updateRow(e,t){c.updateRow(e,t)},async flushTransactions(){await c.flush()},hasPendingTransactions(){return c.hasPending()},getDistinctValues(e){return o.getDistinctValues(e)},getRowById(e){return o.getRowById(e)},getTotalRowCount(){return o.getTotalRowCount()},subscribe(e){return s.add(e),()=>{s.delete(e)}}}}const U=`
|
|
185
|
+
/* =============================================================================
|
|
186
|
+
GP Grid - CSS Variables for Theming
|
|
187
|
+
============================================================================= */
|
|
188
|
+
|
|
189
|
+
.gp-grid-container {
|
|
190
|
+
/* Colors - Light Mode (default) */
|
|
191
|
+
--gp-grid-bg: #ffffff;
|
|
192
|
+
--gp-grid-bg-alt: #f8f9fa;
|
|
193
|
+
--gp-grid-text: #212529;
|
|
194
|
+
--gp-grid-text-secondary: #6c757d;
|
|
195
|
+
--gp-grid-text-muted: #adb5bd;
|
|
196
|
+
--gp-grid-border: #dee2e6;
|
|
197
|
+
--gp-grid-border-light: #e9ecef;
|
|
198
|
+
|
|
199
|
+
/* Header */
|
|
200
|
+
--gp-grid-header-bg: #f1f3f5;
|
|
201
|
+
--gp-grid-header-text: #212529;
|
|
202
|
+
|
|
203
|
+
/* Selection */
|
|
204
|
+
--gp-grid-primary: #228be6;
|
|
205
|
+
--gp-grid-primary-light: #e7f5ff;
|
|
206
|
+
--gp-grid-primary-border: #74c0fc;
|
|
207
|
+
--gp-grid-hover: #f1f3f5;
|
|
208
|
+
|
|
209
|
+
/* Filter */
|
|
210
|
+
--gp-grid-filter-bg: #f8f9fa;
|
|
211
|
+
--gp-grid-input-bg: #ffffff;
|
|
212
|
+
--gp-grid-input-border: #ced4da;
|
|
213
|
+
|
|
214
|
+
/* Error */
|
|
215
|
+
--gp-grid-error-bg: #fff5f5;
|
|
216
|
+
--gp-grid-error-text: #c92a2a;
|
|
217
|
+
|
|
218
|
+
/* Loading */
|
|
219
|
+
--gp-grid-loading-bg: rgba(255, 255, 255, 0.95);
|
|
220
|
+
--gp-grid-loading-text: #495057;
|
|
221
|
+
|
|
222
|
+
/* Scrollbar */
|
|
223
|
+
--gp-grid-scrollbar-track: #f1f3f5;
|
|
224
|
+
--gp-grid-scrollbar-thumb: #ced4da;
|
|
225
|
+
--gp-grid-scrollbar-thumb-hover: #adb5bd;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/* Dark Mode */
|
|
229
|
+
.gp-grid-container--dark {
|
|
230
|
+
--gp-grid-bg: #1a1b1e;
|
|
231
|
+
--gp-grid-bg-alt: #25262b;
|
|
232
|
+
--gp-grid-text: #c1c2c5;
|
|
233
|
+
--gp-grid-text-secondary: #909296;
|
|
234
|
+
--gp-grid-text-muted: #5c5f66;
|
|
235
|
+
--gp-grid-border: #373a40;
|
|
236
|
+
--gp-grid-border-light: #2c2e33;
|
|
237
|
+
|
|
238
|
+
/* Header */
|
|
239
|
+
--gp-grid-header-bg: #25262b;
|
|
240
|
+
--gp-grid-header-text: #c1c2c5;
|
|
241
|
+
|
|
242
|
+
/* Selection */
|
|
243
|
+
--gp-grid-primary: #339af0;
|
|
244
|
+
--gp-grid-primary-light: #1c3d5a;
|
|
245
|
+
--gp-grid-primary-border: #1c7ed6;
|
|
246
|
+
--gp-grid-hover: #2c2e33;
|
|
247
|
+
|
|
248
|
+
/* Filter */
|
|
249
|
+
--gp-grid-filter-bg: #25262b;
|
|
250
|
+
--gp-grid-input-bg: #1a1b1e;
|
|
251
|
+
--gp-grid-input-border: #373a40;
|
|
252
|
+
|
|
253
|
+
/* Error */
|
|
254
|
+
--gp-grid-error-bg: #2c1a1a;
|
|
255
|
+
--gp-grid-error-text: #ff6b6b;
|
|
256
|
+
|
|
257
|
+
/* Loading */
|
|
258
|
+
--gp-grid-loading-bg: rgba(26, 27, 30, 0.95);
|
|
259
|
+
--gp-grid-loading-text: #c1c2c5;
|
|
260
|
+
|
|
261
|
+
/* Scrollbar */
|
|
262
|
+
--gp-grid-scrollbar-track: #25262b;
|
|
263
|
+
--gp-grid-scrollbar-thumb: #373a40;
|
|
264
|
+
--gp-grid-scrollbar-thumb-hover: #4a4d52;
|
|
265
|
+
}
|
|
266
|
+
`,W=`
|
|
267
|
+
/* =============================================================================
|
|
268
|
+
GP Grid - Clean Flat Design
|
|
269
|
+
============================================================================= */
|
|
270
|
+
|
|
271
|
+
/* Grid Container */
|
|
272
|
+
.gp-grid-container {
|
|
273
|
+
outline: none;
|
|
274
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
275
|
+
font-size: 13px;
|
|
276
|
+
line-height: 1.5;
|
|
277
|
+
color: var(--gp-grid-text);
|
|
278
|
+
background-color: var(--gp-grid-bg);
|
|
279
|
+
border: 1px solid var(--gp-grid-border);
|
|
280
|
+
border-radius: 6px;
|
|
281
|
+
user-select: none;
|
|
282
|
+
-webkit-user-select: none;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.gp-grid-container:focus {
|
|
286
|
+
outline: none;
|
|
287
|
+
border-color: var(--gp-grid-primary);
|
|
288
|
+
}
|
|
289
|
+
`,G=`
|
|
290
|
+
/* =============================================================================
|
|
291
|
+
Header
|
|
292
|
+
============================================================================= */
|
|
293
|
+
|
|
294
|
+
.gp-grid-header {
|
|
295
|
+
position: sticky;
|
|
296
|
+
top: 0;
|
|
297
|
+
left: 0;
|
|
298
|
+
z-index: 100;
|
|
299
|
+
background-color: var(--gp-grid-header-bg);
|
|
300
|
+
border-bottom: 1px solid var(--gp-grid-border);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.gp-grid-container .gp-grid-header-cell {
|
|
304
|
+
position: absolute;
|
|
305
|
+
box-sizing: border-box;
|
|
306
|
+
border-right: 1px solid var(--gp-grid-border);
|
|
307
|
+
font-weight: 600;
|
|
308
|
+
font-size: 12px;
|
|
309
|
+
text-transform: uppercase;
|
|
310
|
+
letter-spacing: 0.5px;
|
|
311
|
+
color: var(--gp-grid-header-text);
|
|
312
|
+
cursor: pointer;
|
|
313
|
+
user-select: none;
|
|
314
|
+
display: flex;
|
|
315
|
+
align-items: center;
|
|
316
|
+
padding: 0 12px;
|
|
317
|
+
background-color: transparent;
|
|
318
|
+
transition: background-color 0.1s ease;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.gp-grid-container .gp-grid-header-cell:hover {
|
|
322
|
+
background-color: var(--gp-grid-hover);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.gp-grid-container .gp-grid-header-cell:active {
|
|
326
|
+
background-color: var(--gp-grid-border-light);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.gp-grid-container .gp-grid-header-text {
|
|
330
|
+
flex: 1;
|
|
331
|
+
overflow: hidden;
|
|
332
|
+
text-overflow: ellipsis;
|
|
333
|
+
white-space: nowrap;
|
|
334
|
+
color: var(--gp-grid-header-text);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/* Header icons container */
|
|
338
|
+
.gp-grid-header-icons {
|
|
339
|
+
display: flex;
|
|
340
|
+
align-items: center;
|
|
341
|
+
gap: 4px;
|
|
342
|
+
margin-left: auto;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/* Stacked sort arrows */
|
|
346
|
+
.gp-grid-sort-arrows {
|
|
347
|
+
display: flex;
|
|
348
|
+
flex-direction: row;
|
|
349
|
+
align-items: center;
|
|
350
|
+
gap: 2px;
|
|
351
|
+
margin-left: 6px;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.gp-grid-sort-arrows-stack {
|
|
355
|
+
display: flex;
|
|
356
|
+
flex-direction: column;
|
|
357
|
+
align-items: center;
|
|
358
|
+
gap: 2px;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.gp-grid-sort-arrow-up,
|
|
362
|
+
.gp-grid-sort-arrow-down {
|
|
363
|
+
opacity: 0.35;
|
|
364
|
+
transition: opacity 0.15s ease, color 0.15s ease;
|
|
365
|
+
color: var(--gp-grid-text);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.gp-grid-sort-arrow-up.active,
|
|
369
|
+
.gp-grid-sort-arrow-down.active {
|
|
370
|
+
opacity: 1;
|
|
371
|
+
color: var(--gp-grid-primary);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.gp-grid-sort-index {
|
|
375
|
+
font-size: 9px;
|
|
376
|
+
color: var(--gp-grid-primary);
|
|
377
|
+
font-weight: 600;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/* Filter icon */
|
|
381
|
+
.gp-grid-filter-icon {
|
|
382
|
+
display: flex;
|
|
383
|
+
align-items: center;
|
|
384
|
+
justify-content: center;
|
|
385
|
+
width: 20px;
|
|
386
|
+
height: 20px;
|
|
387
|
+
border-radius: 4px;
|
|
388
|
+
cursor: pointer;
|
|
389
|
+
color: var(--gp-grid-text-secondary);
|
|
390
|
+
transition: background-color 0.15s ease, color 0.15s ease;
|
|
391
|
+
margin-left: 2px;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
.gp-grid-filter-icon:hover {
|
|
395
|
+
background-color: var(--gp-grid-hover);
|
|
396
|
+
color: var(--gp-grid-primary);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
.gp-grid-filter-icon.active {
|
|
400
|
+
color: var(--gp-grid-primary);
|
|
401
|
+
background-color: var(--gp-grid-primary-light);
|
|
402
|
+
}
|
|
403
|
+
`,K=`
|
|
404
|
+
/* =============================================================================
|
|
405
|
+
Data Cells
|
|
406
|
+
============================================================================= */
|
|
407
|
+
|
|
408
|
+
.gp-grid-row {
|
|
409
|
+
position: absolute;
|
|
410
|
+
top: 0;
|
|
411
|
+
left: 0;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
.gp-grid-cell {
|
|
415
|
+
position: absolute;
|
|
416
|
+
top: 0;
|
|
417
|
+
box-sizing: border-box;
|
|
418
|
+
padding: 0 12px;
|
|
419
|
+
display: flex;
|
|
420
|
+
align-items: center;
|
|
421
|
+
cursor: cell;
|
|
422
|
+
color: var(--gp-grid-text);
|
|
423
|
+
border-right: 1px solid var(--gp-grid-border-light);
|
|
424
|
+
border-bottom: 1px solid var(--gp-grid-border-light);
|
|
425
|
+
background-color: var(--gp-grid-bg);
|
|
426
|
+
overflow: hidden;
|
|
427
|
+
text-overflow: ellipsis;
|
|
428
|
+
white-space: nowrap;
|
|
429
|
+
user-select: none;
|
|
430
|
+
-webkit-user-select: none;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/* Alternating row colors */
|
|
434
|
+
.gp-grid-row--even .gp-grid-cell {
|
|
435
|
+
background-color: var(--gp-grid-bg-alt);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.gp-grid-cell:hover {
|
|
439
|
+
background-color: var(--gp-grid-hover) !important;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/* Active cell (focused) */
|
|
443
|
+
.gp-grid-cell--active {
|
|
444
|
+
background-color: var(--gp-grid-primary-light) !important;
|
|
445
|
+
border: 2px solid var(--gp-grid-primary) !important;
|
|
446
|
+
outline: none;
|
|
447
|
+
z-index: 5;
|
|
448
|
+
padding: 0 11px;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/* Selected cells (range selection) */
|
|
452
|
+
.gp-grid-cell--selected {
|
|
453
|
+
background-color: var(--gp-grid-primary-light) !important;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/* Editing cell */
|
|
457
|
+
.gp-grid-cell--editing {
|
|
458
|
+
background-color: var(--gp-grid-bg) !important;
|
|
459
|
+
border: 2px solid var(--gp-grid-primary) !important;
|
|
460
|
+
padding: 0 !important;
|
|
461
|
+
z-index: 10;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/* =============================================================================
|
|
465
|
+
Fill Handle (drag to fill)
|
|
466
|
+
============================================================================= */
|
|
467
|
+
|
|
468
|
+
.gp-grid-fill-handle {
|
|
469
|
+
position: absolute;
|
|
470
|
+
width: 8px;
|
|
471
|
+
height: 8px;
|
|
472
|
+
background-color: var(--gp-grid-primary);
|
|
473
|
+
border: 2px solid var(--gp-grid-bg);
|
|
474
|
+
cursor: crosshair;
|
|
475
|
+
z-index: 100;
|
|
476
|
+
pointer-events: auto;
|
|
477
|
+
box-sizing: border-box;
|
|
478
|
+
border-radius: 1px;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
.gp-grid-fill-handle:hover {
|
|
482
|
+
transform: scale(1.2);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/* Fill preview (cells being filled) */
|
|
486
|
+
.gp-grid-cell--fill-preview {
|
|
487
|
+
background-color: var(--gp-grid-primary-light) !important;
|
|
488
|
+
border: 1px dashed var(--gp-grid-primary) !important;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/* =============================================================================
|
|
492
|
+
Edit Input
|
|
493
|
+
============================================================================= */
|
|
494
|
+
|
|
495
|
+
.gp-grid-edit-input {
|
|
496
|
+
width: 100%;
|
|
497
|
+
height: 100%;
|
|
498
|
+
padding: 0 11px;
|
|
499
|
+
font-family: inherit;
|
|
500
|
+
font-size: inherit;
|
|
501
|
+
color: var(--gp-grid-text);
|
|
502
|
+
border: none;
|
|
503
|
+
background-color: transparent;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
.gp-grid-edit-input:focus {
|
|
507
|
+
outline: none;
|
|
508
|
+
}
|
|
509
|
+
`,q=`
|
|
510
|
+
/* =============================================================================
|
|
511
|
+
Loading & Error States
|
|
512
|
+
============================================================================= */
|
|
513
|
+
|
|
514
|
+
.gp-grid-loading {
|
|
515
|
+
position: absolute;
|
|
516
|
+
top: 50%;
|
|
517
|
+
left: 50%;
|
|
518
|
+
transform: translate(-50%, -50%);
|
|
519
|
+
padding: 12px 20px;
|
|
520
|
+
background-color: var(--gp-grid-loading-bg);
|
|
521
|
+
color: var(--gp-grid-loading-text);
|
|
522
|
+
border-radius: 6px;
|
|
523
|
+
border: 1px solid var(--gp-grid-border);
|
|
524
|
+
font-weight: 500;
|
|
525
|
+
font-size: 13px;
|
|
526
|
+
z-index: 1000;
|
|
527
|
+
display: flex;
|
|
528
|
+
align-items: center;
|
|
529
|
+
gap: 10px;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
.gp-grid-loading-spinner {
|
|
533
|
+
width: 16px;
|
|
534
|
+
height: 16px;
|
|
535
|
+
border: 2px solid var(--gp-grid-border);
|
|
536
|
+
border-top-color: var(--gp-grid-primary);
|
|
537
|
+
border-radius: 50%;
|
|
538
|
+
animation: gp-grid-spin 0.7s linear infinite;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
@keyframes gp-grid-spin {
|
|
542
|
+
to {
|
|
543
|
+
transform: rotate(360deg);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
.gp-grid-error {
|
|
548
|
+
position: absolute;
|
|
549
|
+
top: 50%;
|
|
550
|
+
left: 50%;
|
|
551
|
+
transform: translate(-50%, -50%);
|
|
552
|
+
padding: 12px 20px;
|
|
553
|
+
background-color: var(--gp-grid-error-bg);
|
|
554
|
+
color: var(--gp-grid-error-text);
|
|
555
|
+
border-radius: 6px;
|
|
556
|
+
border: 1px solid var(--gp-grid-error-text);
|
|
557
|
+
font-weight: 500;
|
|
558
|
+
font-size: 13px;
|
|
559
|
+
z-index: 1000;
|
|
560
|
+
max-width: 80%;
|
|
561
|
+
text-align: center;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/* =============================================================================
|
|
565
|
+
Empty State
|
|
566
|
+
============================================================================= */
|
|
567
|
+
|
|
568
|
+
.gp-grid-empty {
|
|
569
|
+
position: absolute;
|
|
570
|
+
top: 50%;
|
|
571
|
+
left: 50%;
|
|
572
|
+
transform: translate(-50%, -50%);
|
|
573
|
+
color: var(--gp-grid-text-muted);
|
|
574
|
+
font-size: 14px;
|
|
575
|
+
text-align: center;
|
|
576
|
+
}
|
|
577
|
+
`,J=`
|
|
578
|
+
/* =============================================================================
|
|
579
|
+
Scrollbar Styling
|
|
580
|
+
============================================================================= */
|
|
581
|
+
|
|
582
|
+
.gp-grid-container::-webkit-scrollbar {
|
|
583
|
+
width: 8px;
|
|
584
|
+
height: 8px;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
.gp-grid-container::-webkit-scrollbar-track {
|
|
588
|
+
background-color: var(--gp-grid-scrollbar-track);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
.gp-grid-container::-webkit-scrollbar-thumb {
|
|
592
|
+
background-color: var(--gp-grid-scrollbar-thumb);
|
|
593
|
+
border-radius: 4px;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
.gp-grid-container::-webkit-scrollbar-thumb:hover {
|
|
597
|
+
background-color: var(--gp-grid-scrollbar-thumb-hover);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
.gp-grid-container::-webkit-scrollbar-corner {
|
|
601
|
+
background-color: var(--gp-grid-scrollbar-track);
|
|
602
|
+
}
|
|
603
|
+
`,Y=`
|
|
604
|
+
/* =============================================================================
|
|
605
|
+
Filter Popup
|
|
606
|
+
============================================================================= */
|
|
607
|
+
|
|
608
|
+
.gp-grid-filter-popup {
|
|
609
|
+
background-color: var(--gp-grid-bg);
|
|
610
|
+
border: 1px solid var(--gp-grid-border);
|
|
611
|
+
border-radius: 6px;
|
|
612
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
613
|
+
max-height: 400px;
|
|
614
|
+
display: flex;
|
|
615
|
+
flex-direction: column;
|
|
616
|
+
font-size: 13px;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
.gp-grid-filter-header {
|
|
620
|
+
padding: 10px 12px;
|
|
621
|
+
font-weight: 600;
|
|
622
|
+
border-bottom: 1px solid var(--gp-grid-border-light);
|
|
623
|
+
color: var(--gp-grid-header-text);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
.gp-grid-filter-content {
|
|
627
|
+
padding: 10px 12px;
|
|
628
|
+
display: flex;
|
|
629
|
+
flex-direction: column;
|
|
630
|
+
gap: 10px;
|
|
631
|
+
overflow: hidden;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/* Mode toggle (Values / Condition) */
|
|
635
|
+
.gp-grid-filter-mode-toggle {
|
|
636
|
+
display: flex;
|
|
637
|
+
gap: 4px;
|
|
638
|
+
background-color: var(--gp-grid-bg-alt);
|
|
639
|
+
border-radius: 4px;
|
|
640
|
+
padding: 2px;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
.gp-grid-filter-mode-toggle button {
|
|
644
|
+
flex: 1;
|
|
645
|
+
padding: 6px 10px;
|
|
646
|
+
font-size: 11px;
|
|
647
|
+
font-family: inherit;
|
|
648
|
+
border: none;
|
|
649
|
+
border-radius: 3px;
|
|
650
|
+
background-color: transparent;
|
|
651
|
+
color: var(--gp-grid-text-secondary);
|
|
652
|
+
cursor: pointer;
|
|
653
|
+
transition: background-color 0.15s ease, color 0.15s ease;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
.gp-grid-filter-mode-toggle button:hover {
|
|
657
|
+
color: var(--gp-grid-text);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
.gp-grid-filter-mode-toggle button.active {
|
|
661
|
+
background-color: var(--gp-grid-bg);
|
|
662
|
+
color: var(--gp-grid-text);
|
|
663
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/* Info message for too many values */
|
|
667
|
+
.gp-grid-filter-info {
|
|
668
|
+
font-size: 11px;
|
|
669
|
+
color: var(--gp-grid-text-secondary);
|
|
670
|
+
padding: 6px 8px;
|
|
671
|
+
background-color: var(--gp-grid-bg-alt);
|
|
672
|
+
border-radius: 4px;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/* Search input in filter */
|
|
676
|
+
.gp-grid-filter-search {
|
|
677
|
+
width: 100%;
|
|
678
|
+
height: 30px;
|
|
679
|
+
padding: 0 10px;
|
|
680
|
+
font-family: inherit;
|
|
681
|
+
font-size: 12px;
|
|
682
|
+
border: 1px solid var(--gp-grid-input-border);
|
|
683
|
+
border-radius: 4px;
|
|
684
|
+
background-color: var(--gp-grid-input-bg);
|
|
685
|
+
color: var(--gp-grid-text);
|
|
686
|
+
box-sizing: border-box;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
.gp-grid-filter-search:focus {
|
|
690
|
+
outline: none;
|
|
691
|
+
border-color: var(--gp-grid-primary);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/* Select All / Deselect All actions */
|
|
695
|
+
.gp-grid-filter-actions {
|
|
696
|
+
display: flex;
|
|
697
|
+
gap: 8px;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
.gp-grid-filter-actions button {
|
|
701
|
+
flex: 1;
|
|
702
|
+
padding: 4px 8px;
|
|
703
|
+
font-size: 11px;
|
|
704
|
+
font-family: inherit;
|
|
705
|
+
border: 1px solid var(--gp-grid-input-border);
|
|
706
|
+
border-radius: 3px;
|
|
707
|
+
background-color: var(--gp-grid-bg);
|
|
708
|
+
color: var(--gp-grid-text);
|
|
709
|
+
cursor: pointer;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
.gp-grid-filter-actions button:hover:not(:disabled) {
|
|
713
|
+
background-color: var(--gp-grid-hover);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
.gp-grid-filter-actions button:disabled {
|
|
717
|
+
opacity: 0.5;
|
|
718
|
+
cursor: not-allowed;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/* Checkbox list */
|
|
722
|
+
.gp-grid-filter-list {
|
|
723
|
+
max-height: 200px;
|
|
724
|
+
overflow-y: auto;
|
|
725
|
+
display: flex;
|
|
726
|
+
flex-direction: column;
|
|
727
|
+
gap: 4px;
|
|
728
|
+
border: 1px solid var(--gp-grid-border-light);
|
|
729
|
+
border-radius: 4px;
|
|
730
|
+
padding: 6px;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
.gp-grid-filter-option {
|
|
734
|
+
display: flex;
|
|
735
|
+
align-items: center;
|
|
736
|
+
gap: 8px;
|
|
737
|
+
padding: 4px 6px;
|
|
738
|
+
border-radius: 3px;
|
|
739
|
+
cursor: pointer;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
.gp-grid-filter-option:hover {
|
|
743
|
+
background-color: var(--gp-grid-hover);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
.gp-grid-filter-option input[type="checkbox"] {
|
|
747
|
+
margin: 0;
|
|
748
|
+
cursor: pointer;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
.gp-grid-filter-option span {
|
|
752
|
+
flex: 1;
|
|
753
|
+
overflow: hidden;
|
|
754
|
+
text-overflow: ellipsis;
|
|
755
|
+
white-space: nowrap;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
.gp-grid-filter-blank {
|
|
759
|
+
font-style: italic;
|
|
760
|
+
color: var(--gp-grid-text-muted);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/* Filter condition row (for number/date filters) */
|
|
764
|
+
.gp-grid-filter-condition {
|
|
765
|
+
display: flex;
|
|
766
|
+
flex-direction: column;
|
|
767
|
+
gap: 6px;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
.gp-grid-filter-row {
|
|
771
|
+
display: flex;
|
|
772
|
+
align-items: center;
|
|
773
|
+
gap: 6px;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
.gp-grid-filter-row select {
|
|
777
|
+
height: 30px;
|
|
778
|
+
padding: 0 6px;
|
|
779
|
+
font-family: inherit;
|
|
780
|
+
font-size: 12px;
|
|
781
|
+
border: 1px solid var(--gp-grid-input-border);
|
|
782
|
+
border-radius: 4px;
|
|
783
|
+
background-color: var(--gp-grid-input-bg);
|
|
784
|
+
color: var(--gp-grid-text);
|
|
785
|
+
cursor: pointer;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
.gp-grid-filter-row input[type="number"],
|
|
789
|
+
.gp-grid-filter-row input[type="date"],
|
|
790
|
+
.gp-grid-filter-row input[type="text"],
|
|
791
|
+
.gp-grid-filter-text-input {
|
|
792
|
+
flex: 1;
|
|
793
|
+
height: 30px;
|
|
794
|
+
padding: 0 8px;
|
|
795
|
+
font-family: inherit;
|
|
796
|
+
font-size: 12px;
|
|
797
|
+
border: 1px solid var(--gp-grid-input-border);
|
|
798
|
+
border-radius: 4px;
|
|
799
|
+
background-color: var(--gp-grid-input-bg);
|
|
800
|
+
color: var(--gp-grid-text);
|
|
801
|
+
min-width: 0;
|
|
802
|
+
box-sizing: border-box;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
.gp-grid-filter-row input:focus {
|
|
806
|
+
outline: none;
|
|
807
|
+
border-color: var(--gp-grid-primary);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
.gp-grid-filter-to {
|
|
811
|
+
font-size: 11px;
|
|
812
|
+
color: var(--gp-grid-text-secondary);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
.gp-grid-filter-remove {
|
|
816
|
+
width: 24px;
|
|
817
|
+
height: 24px;
|
|
818
|
+
padding: 0;
|
|
819
|
+
font-size: 16px;
|
|
820
|
+
line-height: 1;
|
|
821
|
+
border: none;
|
|
822
|
+
border-radius: 3px;
|
|
823
|
+
background-color: transparent;
|
|
824
|
+
color: var(--gp-grid-text-muted);
|
|
825
|
+
cursor: pointer;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
.gp-grid-filter-remove:hover {
|
|
829
|
+
background-color: var(--gp-grid-error-bg);
|
|
830
|
+
color: var(--gp-grid-error-text);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/* AND/OR combination toggle */
|
|
834
|
+
.gp-grid-filter-combination {
|
|
835
|
+
display: flex;
|
|
836
|
+
gap: 4px;
|
|
837
|
+
margin-bottom: 4px;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
.gp-grid-filter-combination button {
|
|
841
|
+
flex: 1;
|
|
842
|
+
padding: 4px 8px;
|
|
843
|
+
font-size: 10px;
|
|
844
|
+
font-family: inherit;
|
|
845
|
+
border: 1px solid var(--gp-grid-input-border);
|
|
846
|
+
border-radius: 3px;
|
|
847
|
+
background-color: var(--gp-grid-bg);
|
|
848
|
+
color: var(--gp-grid-text-secondary);
|
|
849
|
+
cursor: pointer;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
.gp-grid-filter-combination button.active {
|
|
853
|
+
background-color: var(--gp-grid-primary);
|
|
854
|
+
border-color: var(--gp-grid-primary);
|
|
855
|
+
color: #fff;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
/* Add condition button */
|
|
859
|
+
.gp-grid-filter-add {
|
|
860
|
+
width: 100%;
|
|
861
|
+
padding: 6px;
|
|
862
|
+
font-size: 11px;
|
|
863
|
+
font-family: inherit;
|
|
864
|
+
border: 1px dashed var(--gp-grid-border);
|
|
865
|
+
border-radius: 4px;
|
|
866
|
+
background-color: transparent;
|
|
867
|
+
color: var(--gp-grid-text-secondary);
|
|
868
|
+
cursor: pointer;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
.gp-grid-filter-add:hover {
|
|
872
|
+
background-color: var(--gp-grid-hover);
|
|
873
|
+
border-color: var(--gp-grid-primary);
|
|
874
|
+
color: var(--gp-grid-primary);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/* Apply / Clear buttons */
|
|
878
|
+
.gp-grid-filter-buttons {
|
|
879
|
+
display: flex;
|
|
880
|
+
gap: 8px;
|
|
881
|
+
padding-top: 8px;
|
|
882
|
+
border-top: 1px solid var(--gp-grid-border-light);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
.gp-grid-filter-btn-clear,
|
|
886
|
+
.gp-grid-filter-btn-apply {
|
|
887
|
+
flex: 1;
|
|
888
|
+
padding: 8px 12px;
|
|
889
|
+
font-size: 12px;
|
|
890
|
+
font-family: inherit;
|
|
891
|
+
border-radius: 4px;
|
|
892
|
+
cursor: pointer;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
.gp-grid-filter-btn-clear {
|
|
896
|
+
border: 1px solid var(--gp-grid-input-border);
|
|
897
|
+
background-color: var(--gp-grid-bg);
|
|
898
|
+
color: var(--gp-grid-text);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
.gp-grid-filter-btn-clear:hover {
|
|
902
|
+
background-color: var(--gp-grid-hover);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
.gp-grid-filter-btn-apply {
|
|
906
|
+
border: 1px solid var(--gp-grid-primary);
|
|
907
|
+
background-color: var(--gp-grid-primary);
|
|
908
|
+
color: #fff;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
.gp-grid-filter-btn-apply:hover {
|
|
912
|
+
opacity: 0.9;
|
|
913
|
+
}
|
|
914
|
+
`,X=`gp-grid-styles`,Z=[U,W,G,K,q,J,Y].join(`
|
|
915
|
+
`);let Q=!1;function ae(){if(Q||typeof document>`u`)return;if(document.getElementById(X)){Q=!0;return}let e=document.createElement(`style`);e.id=X,e.textContent=Z,document.head.appendChild(e),Q=!0}function oe(e){let t=[0],n=0;for(let r of e)n+=r.width,t.push(n);return t}function $(e){return e[e.length-1]??0}function se(e,t){for(let n=0;n<t.length-1;n++)if(e>=t[n]&&e<t[n+1])return n;return e>=t[t.length-1]?t.length-2:0}function ce(e,t,n){if(!n)return!1;let r=Math.min(n.startRow,n.endRow),i=Math.max(n.startRow,n.endRow),a=Math.min(n.startCol,n.endCol),o=Math.max(n.startCol,n.endCol);return e>=r&&e<=i&&t>=a&&t<=o}function le(e,t,n){return n?.row===e&&n?.col===t}function ue(e,t){return!t||t.end<0||t.start>t.end?!0:e>=t.start&&e<=t.end}function de(e,t,n){return n?.row===e&&n?.col===t}function fe(e,t,n,r,i){if(!n||!r||!i)return!1;let a=Math.min(r.startRow,r.endRow),o=Math.max(r.startRow,r.endRow),s=Math.min(r.startCol,r.endCol),c=Math.max(r.startCol,r.endCol),l=i.row>o,u=i.row<a;return l?e>o&&e<=i.row&&t>=s&&t<=c:u?e<a&&e>=i.row&&t>=s&&t<=c:!1}function pe(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(` `)}export{r as EditManager,t as FillManager,o as GridCore,B as IndexedDataStore,i as InputHandler,e as SelectionManager,n as SlotPoolManager,u as SortWorkerManager,V as TransactionManager,pe as buildCellClasses,oe as calculateColumnPositions,K as cellStyles,k as compareValues,A as computeValueHash,W as containerStyles,C as createClientDataSource,w as createDataSourceFromArray,H as createMutableClientDataSource,T as createServerDataSource,R as evaluateColumnFilter,I as evaluateDateCondition,F as evaluateNumberCondition,P as evaluateTextCondition,Y as filtersStyles,se as findColumnAtX,E as getFieldValue,f as getSharedSortWorker,$ as getTotalWidth,Z as gridStyles,G as headerStyles,ae as injectStyles,le as isCellActive,de as isCellEditing,fe as isCellInFillPreview,ce as isCellSelected,ue as isRowVisible,N as isSameDay,z as rowPassesFilter,J as scrollbarStyles,D as setFieldValue,q as statesStyles,O as stringToSortableNumber,p as terminateSharedSortWorker,U as variablesStyles};
|