@alaarab/ogrid-js 2.5.4 → 2.5.5
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/esm/index.js +1 -1
- package/package.json +2 -2
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {flattenColumns,resolveResponsiveConfig,deriveFilterOptionsFromData,validateColumns,validateRowIds,applyResponsiveHiding,processClientSideData,processClientSideDataAsync,mergeFilter,exportToCsv,getCellValue,ROW_NUMBER_COLUMN_WIDTH,ROW_NUMBER_COLUMN_ID,CHECKBOX_COLUMN_WIDTH,indexToColumnLetter,buildHeaderRows,partitionColumnsForVirtualization,isInSelectionRange,getPaginationViewModel,getStatusBarParts,DEFAULT_MIN_COLUMN_WIDTH,CELL_PADDING,applyRangeRowSelection,computeRowSelectionState,validateVirtualScrollConfig,computeTotalHeight,computeVisibleColumnRange,getScrollTopForRow,computeVisibleRange,rangesEqual,applyCellDeletion,computeTabNavigation,computeArrowNavigation,normalizeSelectionRange,formatSelectionAsTsv,parseTsvClipboard,applyPastedValues,applyCutClear,UndoRedoStack,ROW_NUMBER_COLUMN_MIN_WIDTH,applyFillValues,getPinStateForColumn,calculateDropTarget,reorderColumnArray,injectGlobalStyles,GRID_CONTEXT_MENU_ITEMS,formatShortcut,measureColumnContentWidth,formatCellReference,measureRange}from'@alaarab/ogrid-core';export{AUTOSIZE_EXTRA_PX,AUTOSIZE_MAX_PX,CELL_PADDING,CHECKBOX_COLUMN_WIDTH,COLUMN_HEADER_MENU_ITEMS,CellDescriptorCache,DEFAULT_DEBOUNCE_MS,DEFAULT_MIN_COLUMN_WIDTH,GRID_BORDER_RADIUS,GRID_CONTEXT_MENU_ITEMS,MAX_PAGE_BUTTONS,PAGE_SIZE_OPTIONS,PEOPLE_SEARCH_DEBOUNCE_MS,RESPONSIVE_BREAKPOINTS,ROW_NUMBER_COLUMN_ID,ROW_NUMBER_COLUMN_MIN_WIDTH,ROW_NUMBER_COLUMN_WIDTH,SIDEBAR_TRANSITION_MS,UndoRedoStack,Z_INDEX,applyCellDeletion,applyCutClear,applyFillValues,applyPastedValues,applyRangeRowSelection,applyResponsiveHiding,areGridRowPropsEqual,booleanParser,buildCellIndex,buildCsvHeader,buildCsvRows,buildHeaderRows,buildInlineEditorProps,buildPopoverEditorProps,calculateDropTarget,clampSelectionToBounds,columnLetterToIndex,computeAggregations,computeArrowNavigation,computeAutoScrollSpeed,computeNextSortState,computeRowSelectionState,computeTabNavigation,computeTotalHeight,computeVisibleColumnRange,computeVisibleRange,createGridDataAccessor,createSortFilterWorker,currencyParser,dateParser,debounce,deriveFilterOptionsFromData,emailParser,escapeCsvValue,exportToCsv,extractValueMatrix,findCtrlArrowTarget,flattenColumns,formatCellReference,formatCellValueForTsv,formatSelectionAsTsv,formatShortcut,getCellRenderDescriptor,getCellValue,getColumnHeaderMenuItems,getContextMenuHandlers,getDataGridStatusBarConfig,getFilterField,getHeaderFilterConfig,getMultiSelectFilterFields,getPaginationViewModel,getPinStateForColumn,getResponsiveHiddenColumns,getScrollTopForRow,getStatusBarParts,indexToColumnLetter,injectGlobalStyles,isColumnEditable,isFilterConfig,isInSelectionRange,isRowInRange,measureColumnContentWidth,measureRange,mergeFilter,normalizeSelectionRange,numberParser,parseTsvClipboard,parseValue,partitionColumnsForVirtualization,processClientSideData,processClientSideDataAsync,rangesEqual,reorderColumnArray,resolveCellDisplayContent,resolveCellStyle,resolveResponsiveConfig,terminateSortFilterWorker,toUserLike,triggerCsvDownload,validateColumns,validateRowIds,validateVirtualScrollConfig}from'@alaarab/ogrid-core';import {FormulaEngine,handleFormulaBarKeyDown,FORMULA_BAR_CSS}from'@alaarab/ogrid-core/formula';export{CIRC_ERROR,DIV_ZERO_ERROR,DependencyGraph,FORMULA_BAR_CSS,FORMULA_BAR_STYLES,FORMULA_REF_COLORS,FormulaEngine,FormulaError,FormulaEvaluator,GENERAL_ERROR,NAME_ERROR,NA_ERROR,REF_ERROR,VALUE_ERROR,adjustFormulaReferences,canInsertReference,createBuiltInFunctions,deriveFormulaBarText,extractFormulaReferences,flattenArgs,formatAddress,formulaToString,fromCellKey,handleFormulaBarKeyDown,insertReferenceAtCursor,isFormulaError,parse,parseCellRef,parseRange,processFormulaBarCommit,toBoolean,toCellKey,toNumber,tokenize}from'@alaarab/ogrid-core/formula';function L(R){let e=R.getAttribute("data-row-index"),t=R.getAttribute("data-col-index");if(e==null||t==null)return null;let i=parseInt(e,10),n=parseInt(t,10);return Number.isNaN(i)||Number.isNaN(n)?null:{rowIndex:i,colIndex:n}}var x=class{constructor(){this.handlers=new Map;}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e)?.add(t);}off(e,t){this.handlers.get(e)?.delete(t);}emit(e,...t){let i=t[0];this.handlers.get(e)?.forEach(n=>{n(i);});}removeAllListeners(e){e?this.handlers.delete(e):this.handlers.clear();}};var N=class{constructor(e){this.emitter=new x;this._data=[];this._filters={};this._isLoading=false;this._serverItems=[];this._serverTotalCount=0;this._fetchId=0;this._abortController=null;this._firstDataRendered=false;this._formulaEngine=null;this._filterOptions={};this._columnOrder=[];this._responsiveColumns=null;this._containerWidth=0;this._visibleColsCache=null;this._visibleColsDirty=true;this._allColumns=e.columns,this._columns=flattenColumns(e.columns),this._getRowId=e.getRowId,this._data=e.data??[],this._dataSource=e.dataSource,this._page=e.page??1,this._pageSize=e.pageSize??20,this._sort=e.sort,this._filters=e.filters??{},this._visibleColumns=e.visibleColumns??new Set(this._columns.map(t=>t.columnId)),this._columnOrder=this._columns.map(t=>t.columnId),this._onError=e.onError,this._onFirstDataRendered=e.onFirstDataRendered,this._rowHeight=e.rowHeight,this._ariaLabel=e.ariaLabel,this._stickyHeader=e.stickyHeader??true,this._fullScreen=e.fullScreen??false,this._workerSort=e.workerSort??false,this._responsiveColumns=resolveResponsiveConfig(e.responsiveColumns)??null,this._dataSource||(this._filterOptions=deriveFilterOptionsFromData(this._data,this._columns)),validateColumns(this._columns),!this._dataSource&&this._data.length>0&&(validateRowIds(this._data,this._getRowId),this._firstDataRendered=true),this._dataSource&&(this._isLoading=true,this.fetchServerData());}get data(){return this._data}get page(){return this._page}get pageSize(){return this._pageSize}get sort(){return this._sort}get filters(){return this._filters}get visibleColumns(){return this._visibleColumns}get isLoading(){return this._isLoading}get columns(){return this._columns}get allColumns(){return this._allColumns}get getRowId(){return this._getRowId}get isServerSide(){return this._dataSource!=null}get stickyHeader(){return this._stickyHeader}get fullScreen(){return this._fullScreen}get filterOptions(){return this._filterOptions}get columnOrder(){return this._columnOrder}get rowHeight(){return this._rowHeight}get ariaLabel(){return this._ariaLabel}get responsiveColumns(){return this._responsiveColumns}get visibleColumnDefs(){if(!this._visibleColsDirty&&this._visibleColsCache)return this._visibleColsCache;let e=this._columns.filter(i=>this._visibleColumns.has(i.columnId)),t=applyResponsiveHiding(e,this._containerWidth,this._responsiveColumns??void 0);if(this._columnOrder.length===0)this._visibleColsCache=t;else {let i=new Map(this._columnOrder.map((n,r)=>[n,r]));this._visibleColsCache=[...t].sort((n,r)=>{let o=i.get(n.columnId)??1/0,l=i.get(r.columnId)??1/0;return o-l});}return this._visibleColsDirty=false,this._visibleColsCache}getProcessedItems(){if(this.isServerSide)return {items:this._serverItems,totalCount:this._serverTotalCount};let e=processClientSideData(this._data,this._columns,this._filters,this._sort?.field,this._sort?.direction),t=e.length,i=(this._page-1)*this._pageSize,n=i+this._pageSize;return {items:e.slice(i,n),totalCount:t}}get useWorkerSort(){return this._workerSort===true||this._workerSort==="auto"&&this._data.length>5e3}async getProcessedItemsAsync(){if(this.isServerSide||!this.useWorkerSort)return this.getProcessedItems();let e=await processClientSideDataAsync(this._data,this._columns,this._filters,this._sort?.field,this._sort?.direction),t=e.length,i=(this._page-1)*this._pageSize,n=i+this._pageSize;return {items:e.slice(i,n),totalCount:t}}fetchServerData(){if(!this._dataSource)return;this._abortController&&this._abortController.abort();let e=++this._fetchId;this._abortController=new AbortController;let t=this._abortController;this._isLoading=true,this.emitter.emit("stateChange",{type:"loading"}),this._dataSource.fetchPage({page:this._page,pageSize:this._pageSize,sort:this._sort?{field:this._sort.field,direction:this._sort.direction}:void 0,filters:this._filters}).then(i=>{e!==this._fetchId||t.signal.aborted||(this._serverItems=i.items,this._serverTotalCount=i.totalCount,this._isLoading=false,!this._firstDataRendered&&i.items.length>0&&(this._firstDataRendered=true,validateRowIds(i.items,this._getRowId),this._onFirstDataRendered?.()),this.emitter.emit("stateChange",{type:"data"}));}).catch(i=>{e!==this._fetchId||t.signal.aborted||(this._onError?.(i),this._serverItems=[],this._serverTotalCount=0,this._isLoading=false,this.emitter.emit("stateChange",{type:"data"}));});}setData(e){this._data=e,this.isServerSide||(this._filterOptions=deriveFilterOptionsFromData(e,this._columns)),this.emitter.emit("stateChange",{type:"data"});}setPage(e){this._page=e,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"page"});}setPageSize(e){this._pageSize=e,this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"page"});}setSort(e){this._sort=e,this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"sort"});}toggleSort(e){this._sort?.field===e?this._sort=this._sort.direction==="asc"?{field:e,direction:"desc"}:void 0:this._sort={field:e,direction:"asc"},this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"sort"});}setFilter(e,t){this._filters=mergeFilter(this._filters,e,t),this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});}clearFilters(){this._filters={},this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});}setVisibleColumns(e){this._visibleColumns=e,this._visibleColsDirty=true,this.emitter.emit("stateChange",{type:"columns"});}setColumnOrder(e){this._columnOrder=e,this._visibleColsDirty=true,this.emitter.emit("stateChange",{type:"columns"});}setContainerWidth(e){this._containerWidth!==e&&(this._containerWidth=e,this._responsiveColumns&&(this._visibleColsDirty=true,this.emitter.emit("stateChange",{type:"columns"})));}setLoading(e){this._isLoading=e,this.emitter.emit("stateChange",{type:"loading"});}refreshData(){this.isServerSide&&this.fetchServerData();}onStateChange(e){return this.emitter.on("stateChange",e),()=>this.emitter.off("stateChange",e)}getApi(){return {setRowData:e=>{this.isServerSide||this.setData(e);},setLoading:e=>this.setLoading(e),getColumnState:()=>({visibleColumns:Array.from(this._visibleColumns),sort:this._sort,filters:Object.keys(this._filters).length>0?this._filters:void 0}),applyColumnState:e=>{e.visibleColumns&&(this._visibleColumns=new Set(e.visibleColumns)),e.sort!==void 0&&(this._sort=e.sort),e.filters!==void 0&&(this._filters=e.filters??{}),this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"columns"});},setFilterModel:e=>{this._filters=e,this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});},getSelectedRows:()=>[],setSelectedRows:()=>{},selectAll:()=>{},deselectAll:()=>{},clearFilters:()=>this.clearFilters(),clearSort:()=>this.setSort(void 0),resetGridState:()=>{this.clearFilters(),this.setSort(void 0);},getDisplayedRows:()=>this.getProcessedItems().items,refreshData:()=>this.refreshData(),scrollToRow:()=>{},getColumnOrder:()=>[...this._columnOrder],setColumnOrder:e=>this.setColumnOrder(e),exportToCsv:(e,t)=>{let{items:i}=this.getProcessedItems(),n=this.visibleColumnDefs.map(o=>({columnId:o.columnId,name:o.name})),r=this._formulaEngine?.isEnabled()?{getFormula:this._formulaEngine.getFormula.bind(this._formulaEngine),hasFormula:this._formulaEngine.hasFormula.bind(this._formulaEngine),columnIdToIndex:new Map(this.visibleColumnDefs.map((o,l)=>[o.columnId,l])),exportMode:t?.exportMode??"values"}:void 0;exportToCsv(i,n,(o,l)=>{let a=this._columns.find(d=>d.columnId===l);if(!a)return "";let s=getCellValue(o,a);return a.valueFormatter?a.valueFormatter(s,o):s!=null?String(s):""},e,r);}}}setFormulaEngine(e){this._formulaEngine=e;}destroy(){this._abortController&&(this._abortController.abort(),this._abortController=null),this.emitter.removeAllListeners();}};function P(R){return {minR:Math.min(R.startRow,R.endRow),maxR:Math.max(R.startRow,R.endRow),minC:Math.min(R.startCol,R.endCol),maxC:Math.max(R.startCol,R.endCol)}}function M(R,e,t){return e>=R.minR&&e<=R.maxR&&t>=R.minC&&t<=R.maxC}var V=class{constructor(e,t){this.table=null;this.thead=null;this.tbody=null;this.interactionState=null;this.wrapperEl=null;this.headerFilterState=null;this.filterConfigs=new Map;this.onFilterIconClick=null;this.dropIndicator=null;this.virtualScrollState=null;this._tbodyClickHandler=null;this._tbodyPointerdownHandler=null;this._tbodyDblclickHandler=null;this._tbodyContextmenuHandler=null;this._theadClickHandler=null;this._theadPointerdownHandler=null;this._theadDblclickHandler=null;this.lastActiveCell=null;this.lastSelectionRange=null;this.lastCopyRange=null;this.lastCutRange=null;this.lastEditingCell=null;this.lastColumnWidths={};this.lastHeaderSignature="";this.lastRenderedItems=null;this.formulaEngine=null;this.container=e,this.state=t;}setFormulaEngine(e){this.formulaEngine=e;}setVirtualScrollState(e){this.virtualScrollState=e;}setHeaderFilterState(e,t){this.headerFilterState=e,this.filterConfigs=t;}setOnFilterIconClick(e){this.onFilterIconClick=e;}setInteractionState(e){this.interactionState=e;}getCellFromEvent(e){let i=e.target.closest("td[data-row-index]");if(!i)return null;let n=L(i);return n?{el:i,rowIndex:n.rowIndex,colIndex:n.colIndex}:null}attachBodyDelegation(){this.tbody&&(this._tbodyClickHandler=e=>{let t=this.getCellFromEvent(e);t&&this.interactionState?.onCellClick?.({rowIndex:t.rowIndex,colIndex:t.colIndex,event:e});},this._tbodyPointerdownHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-fill-handle")||t.getAttribute("data-fill-handle")==="true"){this.interactionState?.onFillHandleMouseDown?.(e);return}let i=this.getCellFromEvent(e);i&&this.interactionState?.onCellMouseDown?.({rowIndex:i.rowIndex,colIndex:i.colIndex,event:e});},this._tbodyDblclickHandler=e=>{let t=this.getCellFromEvent(e);if(!t)return;let i=t.el.getAttribute("data-column-id")??"",{items:n}=this.state.getProcessedItems(),r=n[t.rowIndex];if(!r)return;let o=this.state.getRowId(r);this.interactionState?.onCellDoubleClick?.({rowIndex:t.rowIndex,colIndex:t.colIndex,rowId:o,columnId:i});},this._tbodyContextmenuHandler=e=>{let t=this.getCellFromEvent(e);t&&this.interactionState?.onCellContextMenu?.({rowIndex:t.rowIndex,colIndex:t.colIndex,event:e});},this.tbody.addEventListener("click",this._tbodyClickHandler,{passive:true}),this.tbody.addEventListener("pointerdown",this._tbodyPointerdownHandler),this.tbody.addEventListener("dblclick",this._tbodyDblclickHandler,{passive:true}),this.tbody.addEventListener("contextmenu",this._tbodyContextmenuHandler));}detachBodyDelegation(){this.tbody&&(this._tbodyClickHandler&&this.tbody.removeEventListener("click",this._tbodyClickHandler),this._tbodyPointerdownHandler&&this.tbody.removeEventListener("pointerdown",this._tbodyPointerdownHandler),this._tbodyDblclickHandler&&this.tbody.removeEventListener("dblclick",this._tbodyDblclickHandler),this._tbodyContextmenuHandler&&this.tbody.removeEventListener("contextmenu",this._tbodyContextmenuHandler),this._tbodyClickHandler=null,this._tbodyPointerdownHandler=null,this._tbodyDblclickHandler=null,this._tbodyContextmenuHandler=null);}attachHeaderDelegation(){this.thead&&(this._theadClickHandler=null,this._theadPointerdownHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-resize-handle")){e.stopPropagation();let i=t.getAttribute("data-column-id"),n=t.closest("th[data-column-id]"),r=i??n?.getAttribute("data-column-id");if(r){let l=t.closest("th")?.getBoundingClientRect();this.interactionState?.onResizeStart?.(r,e.clientX,l?.width??ROW_NUMBER_COLUMN_WIDTH);}return}if(!t.classList.contains("ogrid-filter-icon")&&this.interactionState?.onColumnReorderStart){let i=t.closest("th[data-column-id]");if(!i)return;let n=i.getAttribute("data-column-id");n&&this.interactionState.onColumnReorderStart(n,e);}},this._theadDblclickHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-resize-handle")){e.stopPropagation();let i=t.getAttribute("data-column-id"),n=t.closest("th[data-column-id]"),r=i??n?.getAttribute("data-column-id");r&&this.interactionState?.onResizeDoubleClick?.(r);}},this._theadClickHandler&&this.thead.addEventListener("click",this._theadClickHandler),this.thead.addEventListener("pointerdown",this._theadPointerdownHandler),this.thead.addEventListener("dblclick",this._theadDblclickHandler));}detachHeaderDelegation(){this.thead&&(this._theadClickHandler&&this.thead.removeEventListener("click",this._theadClickHandler),this._theadPointerdownHandler&&this.thead.removeEventListener("pointerdown",this._theadPointerdownHandler),this._theadDblclickHandler&&this.thead.removeEventListener("dblclick",this._theadDblclickHandler),this._theadClickHandler=null,this._theadPointerdownHandler=null,this._theadDblclickHandler=null);}getWrapperElement(){return this.wrapperEl}render(){this.container.innerHTML="";let e=document.createElement("div");e.className="ogrid-wrapper",e.setAttribute("role","region"),e.setAttribute("data-ogrid-scroll-container",""),e.setAttribute("tabindex","0"),e.style.position="relative",this.state.rowHeight&&e.style.setProperty("--ogrid-row-height",`${this.state.rowHeight}px`);let t=this.state.ariaLabel??"Data grid";e.setAttribute("aria-label",t),this.wrapperEl=e,this.table=document.createElement("table"),this.table.className="ogrid-table",this.table.setAttribute("role","grid"),this.virtualScrollState&&this.table.setAttribute("data-virtual-scroll",""),this.thead=document.createElement("thead"),this.state.stickyHeader&&this.thead.classList.add("ogrid-sticky-header"),this.renderHeader(),this.attachHeaderDelegation(),this.table.appendChild(this.thead),this.tbody=document.createElement("tbody"),this.renderBody(),this.attachBodyDelegation(),this.table.appendChild(this.tbody),e.appendChild(this.table),this.dropIndicator=document.createElement("div"),this.dropIndicator.className="ogrid-drop-indicator",this.dropIndicator.style.display="none",e.appendChild(this.dropIndicator),this.container.appendChild(e),this.snapshotState();}computeHeaderSignature(){let e=this.state.visibleColumnDefs,t=this.interactionState,i=[];for(let r of e)i.push(r.columnId),i.push(r.name),i.push(t?.columnWidths[r.columnId]?.toString()??"");let n=this.state.sort;n&&i.push(`sort:${n.field}:${n.direction}`),i.push(`sel:${t?.rowSelectionMode??""}`),i.push(`allSel:${t?.allSelected??""}`),i.push(`someSel:${t?.someSelected??""}`),i.push(`rn:${t?.showRowNumbers??""}`),t?.showRowNumbers&&i.push(`rnw:${t?.columnWidths[ROW_NUMBER_COLUMN_ID]??""}`),i.push(`cl:${t?.showColumnLetters??""}`);for(let[r,o]of this.filterConfigs)this.headerFilterState?.hasActiveFilter(o)&&i.push(`flt:${r}`);return i.join("|")}snapshotState(){let e=this.interactionState;this.lastActiveCell=e?.activeCell?{...e.activeCell}:null,this.lastSelectionRange=e?.selectionRange?{...e.selectionRange}:null,this.lastCopyRange=e?.copyRange?{...e.copyRange}:null,this.lastCutRange=e?.cutRange?{...e.cutRange}:null,this.lastEditingCell=e?.editingCell?{...e.editingCell}:null,this.lastColumnWidths=e?.columnWidths?{...e.columnWidths}:{},this.lastRowSelectionMode=e?.rowSelectionMode,this.lastSelectedRowIds=e?.selectedRowIds?new Set(e.selectedRowIds):void 0,this.lastShowRowNumbers=e?.showRowNumbers,this.lastPinnedColumns=e?.pinnedColumns,this.lastAllSelected=e?.allSelected,this.lastSomeSelected=e?.someSelected,this.lastHeaderSignature=this.computeHeaderSignature();let{items:t}=this.state.getProcessedItems();this.lastRenderedItems=t;}isSelectionOnlyChange(){if(!this.lastRenderedItems)return false;let e=this.interactionState,{items:t}=this.state.getProcessedItems();if(t!==this.lastRenderedItems||this.computeHeaderSignature()!==this.lastHeaderSignature)return false;let n=e?.editingCell,r=this.lastEditingCell;if(n?.rowId!==r?.rowId||n?.columnId!==r?.columnId||e?.rowSelectionMode!==this.lastRowSelectionMode)return false;if(e?.selectedRowIds!==this.lastSelectedRowIds){let o=e?.selectedRowIds,l=this.lastSelectedRowIds;if(!(!o&&!l)){if(!o||!l||o.size!==l.size)return false;for(let a of o)if(!l.has(a))return false}}return !(e?.showRowNumbers!==this.lastShowRowNumbers||e?.pinnedColumns!==this.lastPinnedColumns)}patchSelectionClasses(){if(!this.tbody||!this.interactionState)return;let e=this.interactionState,{activeCell:t,selectionRange:i,copyRange:n,cutRange:r}=e,o=this.lastActiveCell,l=this.lastSelectionRange,a=this.lastCopyRange,s=this.lastCutRange,d=i?P(i):null,c=l?P(l):null,u=n?P(n):null,m=a?P(a):null,v=r?P(r):null,g=s?P(s):null,S=this.getColOffset(),p=this.tbody.querySelectorAll("td[data-row-index][data-col-index]");for(let f=0;f<p.length;f++){let h=p[f],I=L(h);if(!I)continue;let w=I.rowIndex,b=I.colIndex,y=b-S,A=o&&o.rowIndex===w&&o.columnIndex===b,E=t&&t.rowIndex===w&&t.columnIndex===b;A&&!E?(h.removeAttribute("data-active-cell"),h.style.outline="",h.style.zIndex=""):E&&!A&&(h.setAttribute("data-active-cell","true"),h.style.outline="2px solid var(--ogrid-accent, #0078d4)",h.style.position="relative",h.style.zIndex="var(--ogrid-z-active-cell, 2)");let T=c&&M(c,w,y),C=d&&M(d,w,y),_=C&&!E,F=T&&!(o&&o.rowIndex===w&&o.columnIndex===b);F&&!_?(h.removeAttribute("data-in-range"),h.style.backgroundColor=""):_&&!F&&(h.setAttribute("data-in-range","true"),h.style.backgroundColor="var(--ogrid-range-bg, rgba(33, 115, 70, 0.12))");let H=m&&M(m,w,y),D=u&&M(u,w,y);H&&!D?!E&&!(v&&M(v,w,y))&&(h.style.outline=""):D&&!H&&(h.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))");let be=g&&M(g,w,y),O=v&&M(v,w,y);be&&!O?!E&&!(u&&M(u,w,y))&&(h.style.outline=""):O&&!be&&(h.style.outline="1px dashed var(--ogrid-accent, #0078d4)");let we=h.querySelector(".ogrid-fill-handle"),xe=i&&e.onFillHandleMouseDown&&w===Math.max(i.startRow,i.endRow)&&y===Math.max(i.startCol,i.endCol),_e=!!we;if(_e&&!xe)we?.remove();else if(!_e&&xe){let k=document.createElement("div");k.className="ogrid-fill-handle",k.setAttribute("data-fill-handle","true"),k.style.position="absolute",k.style.right="-3px",k.style.bottom="-3px",k.style.width="6px",k.style.height="6px",k.style.backgroundColor="var(--ogrid-selection, #217346)",k.style.cursor="crosshair",k.style.zIndex="5",h.style.position=h.style.position||"relative",k.addEventListener("pointerdown",Ge=>{this.interactionState?.onFillHandleMouseDown?.(Ge);}),h.appendChild(k);}if(!C&&e.pinnedColumns){let k=h.getAttribute("data-column-id");k&&e.pinnedColumns[k]&&(h.style.backgroundColor=h.style.backgroundColor||"var(--ogrid-bg, #fff)");}}this.snapshotState();}update(){if(!this.tbody||!this.thead){this.render(),this.snapshotState();return}if(this.isSelectionOnlyChange()){this.patchSelectionClasses();return}this.computeHeaderSignature()!==this.lastHeaderSignature&&(this.thead.innerHTML="",this.renderHeader()),this.tbody.innerHTML="",this.renderBody(),this.snapshotState();}hasCheckboxColumn(){let e=this.interactionState?.rowSelectionMode;return e==="single"||e==="multiple"}hasRowNumbersColumn(){return !!this.interactionState?.showRowNumbers}getColOffset(){let e=0;return this.hasCheckboxColumn()&&e++,this.hasRowNumbersColumn()&&e++,e}applyPinningStyles(e,t,i){let n=this.interactionState;if(!n?.pinnedColumns)return;let r=n.pinnedColumns[t];r&&(e.style.position="sticky",e.style.zIndex=i?"3":"1",e.setAttribute("data-pinned",r),r==="left"&&n.leftOffsets?e.style.left=`${n.leftOffsets[t]??0}px`:r==="right"&&n.rightOffsets&&(e.style.right=`${n.rightOffsets[t]??0}px`),i||(e.style.backgroundColor=e.style.backgroundColor||"var(--ogrid-bg, #fff)"));}renderHeader(){if(!this.thead)return;this.thead.innerHTML="";let e=this.state.visibleColumnDefs,t=this.hasCheckboxColumn(),i=this.hasRowNumbersColumn();if(this.interactionState?.showColumnLetters){let r=document.createElement("tr");if(r.className="ogrid-column-letter-row",t){let o=document.createElement("th");o.className="ogrid-column-letter-cell",o.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,r.appendChild(o);}if(i){let o=document.createElement("th");o.className="ogrid-column-letter-cell";let l=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH;o.style.width=`${l}px`,r.appendChild(o);}for(let o=0;o<e.length;o++){let l=document.createElement("th");l.className="ogrid-column-letter-cell",l.textContent=indexToColumnLetter(o),r.appendChild(l);}this.thead.appendChild(r);}let n=buildHeaderRows(this.state.allColumns,this.state.visibleColumns);if(n.length>1)for(let r=0;r<n.length;r++){let o=n[r],l=r===n.length-1,a=document.createElement("tr");if(t){let s=document.createElement("th");s.className="ogrid-header-cell ogrid-checkbox-header",s.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,l&&this.appendSelectAllCheckbox(s),a.appendChild(s);}if(i){if(l){let s=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,d=document.createElement("th");d.className="ogrid-header-cell ogrid-row-number-header",d.style.width=`${s}px`,d.style.minWidth=`${s}px`,d.style.maxWidth=`${s}px`,d.style.textAlign="center",d.style.position=d.style.position||"relative",d.textContent="#";let c=document.createElement("div");c.className="ogrid-resize-handle",c.style.position="absolute",c.style.right="0",c.style.top="0",c.style.bottom="0",c.style.width="4px",c.style.cursor="col-resize",c.style.userSelect="none",c.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),d.appendChild(c),a.appendChild(d);}else if(r===0){let s=document.createElement("th");s.rowSpan=n.length-1,s.style.padding="0",a.appendChild(s);}}for(let s of o){let d=document.createElement("th");if(d.textContent=s.label,d.className=s.isGroup?"ogrid-group-header":"ogrid-header-cell",s.colSpan>1&&(d.colSpan=s.colSpan),!s.isGroup&&s.columnDef?.sortable&&(d.classList.add("ogrid-sortable"),d.addEventListener("click",()=>{s.columnDef&&this.state.toggleSort(s.columnDef.columnId);})),!s.isGroup&&s.columnDef){d.setAttribute("data-column-id",s.columnDef.columnId),d.setAttribute("scope","col");let c=this.state.sort;c?.field===s.columnDef.columnId&&d.setAttribute("aria-sort",c.direction==="asc"?"ascending":"descending"),this.applyPinningStyles(d,s.columnDef.columnId,true);}a.appendChild(d);}this.thead?.appendChild(a);}else {let r=document.createElement("tr");if(t){let o=document.createElement("th");o.className="ogrid-header-cell ogrid-checkbox-header",o.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,this.appendSelectAllCheckbox(o),r.appendChild(o);}if(this.hasRowNumbersColumn()){let o=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,l=document.createElement("th");l.className="ogrid-header-cell ogrid-row-number-header",l.style.width=`${o}px`,l.style.minWidth=`${o}px`,l.style.maxWidth=`${o}px`,l.style.textAlign="center",l.style.position=l.style.position||"relative",l.textContent="#";let a=document.createElement("div");a.className="ogrid-resize-handle",a.style.position="absolute",a.style.right="0",a.style.top="0",a.style.bottom="0",a.style.width="4px",a.style.cursor="col-resize",a.style.userSelect="none",a.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),l.appendChild(a),r.appendChild(l);}for(let o=0;o<e.length;o++){let l=e[o],a=document.createElement("th");a.className="ogrid-header-cell",a.setAttribute("data-column-id",l.columnId),a.setAttribute("scope","col");let s=this.state.sort;s?.field===l.columnId&&a.setAttribute("aria-sort",s.direction==="asc"?"ascending":"descending");let d=document.createElement("span");d.textContent=l.name,a.appendChild(d),l.sortable&&(a.classList.add("ogrid-sortable"),a.addEventListener("click",()=>this.state.toggleSort(l.columnId))),l.type==="numeric"&&(a.style.textAlign="right"),this.interactionState?.columnWidths[l.columnId]&&(a.style.width=`${this.interactionState.columnWidths[l.columnId]}px`),this.applyPinningStyles(a,l.columnId,true);let c=document.createElement("div");c.className="ogrid-resize-handle",c.style.position="absolute",c.style.right="0",c.style.top="0",c.style.bottom="0",c.style.width="4px",c.style.cursor="col-resize",c.style.userSelect="none",a.style.position=a.style.position||"relative",a.appendChild(c);let u=this.filterConfigs.get(l.columnId);if(u&&this.onFilterIconClick){let m=document.createElement("button");m.className="ogrid-filter-icon",m.setAttribute("aria-label",`Filter ${l.name}`),m.setAttribute("aria-expanded","false"),m.setAttribute("aria-haspopup","dialog"),m.style.border="none",m.style.background="transparent",m.style.cursor="pointer",m.style.fontSize="10px",m.style.padding="0 2px",m.style.marginLeft="4px",m.style.color="var(--ogrid-fg, #242424)",m.style.opacity="0.6";let v=this.headerFilterState?.hasActiveFilter(u);m.textContent=v?"\u25BC":"\u25BD",v&&(m.style.opacity="1",m.style.color="var(--ogrid-selection, #217346)"),m.addEventListener("click",g=>{g.stopPropagation(),g.preventDefault(),this.onFilterIconClick?.(l.columnId,a);}),a.appendChild(m);}r.appendChild(a);}this.thead?.appendChild(r);}}appendSelectAllCheckbox(e){let t=this.interactionState;if(t?.rowSelectionMode!=="multiple")return;let i=document.createElement("input");i.type="checkbox",i.className="ogrid-select-all-checkbox",i.checked=t?.allSelected===true,i.indeterminate=t?.someSelected===true,i.setAttribute("aria-label","Select all rows"),i.addEventListener("change",()=>{t?.onSelectAll?.(i.checked);}),e.appendChild(i);}renderBody(){if(!this.tbody)return;let e=this.state.visibleColumnDefs,{items:t}=this.state.getProcessedItems(),i=this.hasCheckboxColumn(),n=this.hasRowNumbersColumn(),r=this.getColOffset(),o=e.length+r,l=n?(this.state.page-1)*this.state.pageSize:0;if(t.length===0&&!this.state.isLoading){let p=document.createElement("tr"),f=document.createElement("td");f.colSpan=o,f.className="ogrid-empty-state",f.textContent="No data",p.appendChild(f),this.tbody.appendChild(p);return}let a=this.virtualScrollState,s=a?.enabled===true,d=0,c=t.length-1;if(s){let p=a?.visibleRange;if(!p)return;if(d=Math.max(0,p.startIndex),c=Math.min(t.length-1,p.endIndex),p.offsetTop>0){let f=document.createElement("tr");f.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${p.offsetTop}px`,h.style.padding="0",h.style.border="none",f.appendChild(h),this.tbody.appendChild(f);}}let u=a?.columnVirtualizationEnabled===true&&a.columnRange!=null,m=e,v=null,g=0,S=0;if(u&&a){let p=partitionColumnsForVirtualization(e,a.columnRange,this.interactionState?.pinnedColumns),f=[...p.pinnedLeft,...p.virtualizedUnpinned,...p.pinnedRight];v=f.map(h=>e.indexOf(h)),m=f,g=p.leftSpacerWidth,S=p.rightSpacerWidth;}for(let p=d;p<=c;p++){let f=t[p];if(!f)continue;let h=this.state.getRowId(f),I=document.createElement("tr");I.className="ogrid-row",I.setAttribute("data-row-id",String(h));let w=this.interactionState?.selectedRowIds?.has(h)===true;if(w&&(I.setAttribute("data-row-selected","true"),I.setAttribute("aria-selected","true")),i){let b=document.createElement("td");b.className="ogrid-cell ogrid-checkbox-cell",b.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,b.style.textAlign="center";let y=document.createElement("input");y.type="checkbox",y.className="ogrid-row-checkbox",y.checked=w,y.setAttribute("aria-label",`Select row ${h}`),y.addEventListener("click",A=>{A.stopPropagation(),this.interactionState?.onRowCheckboxChange?.(h,y.checked,p,A.shiftKey);}),b.appendChild(y),I.appendChild(b);}if(n){let b=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,y=document.createElement("td");y.className="ogrid-cell ogrid-row-number-cell",y.style.width=`${b}px`,y.style.minWidth=`${b}px`,y.style.maxWidth=`${b}px`,y.style.textAlign="center",y.style.color="var(--ogrid-fg-muted, #666)",y.style.fontSize="0.9em",y.textContent=String(l+p+1),I.appendChild(y);}if(g>0){let b=document.createElement("td");b.style.width=`${g}px`,b.style.minWidth=`${g}px`,b.style.padding="0",b.style.border="none",b.setAttribute("aria-hidden","true"),I.appendChild(b);}for(let b=0;b<m.length;b++){let y=m[b],A=(v?v[b]:b)+r,E=document.createElement("td");if(E.className="ogrid-cell",E.setAttribute("data-column-id",y.columnId),E.setAttribute("data-row-index",String(p)),E.setAttribute("data-col-index",String(A)),E.setAttribute("tabindex","-1"),y.type==="numeric"&&(E.style.textAlign="right"),this.applyPinningStyles(E,y.columnId,false),this.interactionState){let{activeCell:T,selectionRange:C,copyRange:_,cutRange:F,editingCell:H}=this.interactionState;T&&T.rowIndex===p&&T.columnIndex===A&&(E.setAttribute("data-active-cell","true"),E.style.outline="2px solid var(--ogrid-accent, #0078d4)",E.style.position="relative",E.style.zIndex="var(--ogrid-z-active-cell, 2)"),C&&isInSelectionRange(C,p,b)&&(E.setAttribute("data-in-range","true"),E.style.backgroundColor="var(--ogrid-range-bg, rgba(33, 115, 70, 0.12))"),_&&isInSelectionRange(_,p,b)&&(E.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))"),F&&isInSelectionRange(F,p,b)&&(E.style.outline="1px dashed var(--ogrid-accent, #0078d4)"),H&&H.rowId===h&&H.columnId===y.columnId&&(E.style.visibility="hidden");}if(y.renderCell){let T=getCellValue(f,y),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(b,p)?this.formulaEngine.getValue(b,p)??T:T;y.renderCell(E,f,C);}else {let T=getCellValue(f,y),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(b,p)?this.formulaEngine.getValue(b,p)??T:T;if(y.type==="boolean"){let _=!!C,F=!!y.editable,H=document.createElement("input");H.type="checkbox",H.checked=_,H.disabled=!F,H.style.margin="0",H.style.cursor=F?"pointer":"default",H.setAttribute("aria-label",_?"Checked":"Unchecked"),F&&(H.addEventListener("change",()=>{this.interactionState?.onBooleanToggle?.(h,y.columnId,_);}),H.addEventListener("click",D=>D.stopPropagation())),E.appendChild(H);}else y.valueFormatter?E.textContent=y.valueFormatter(C,f):C!=null&&(E.textContent=String(C));}if(y.cellStyle){let T=typeof y.cellStyle=="function"?y.cellStyle(f):y.cellStyle;T&&Object.assign(E.style,T);}if(this.interactionState){let{selectionRange:T}=this.interactionState;if(T&&this.interactionState.onFillHandleMouseDown&&p===Math.max(T.startRow,T.endRow)&&b===Math.max(T.startCol,T.endCol)){let C=document.createElement("div");C.className="ogrid-fill-handle",C.setAttribute("data-fill-handle","true"),C.style.position="absolute",C.style.right="-3px",C.style.bottom="-3px",C.style.width="6px",C.style.height="6px",C.style.backgroundColor="var(--ogrid-selection, #217346)",C.style.cursor="crosshair",C.style.zIndex="5",E.style.position=E.style.position||"relative",E.appendChild(C);}}I.appendChild(E);}if(S>0){let b=document.createElement("td");b.style.width=`${S}px`,b.style.minWidth=`${S}px`,b.style.padding="0",b.style.border="none",b.setAttribute("aria-hidden","true"),I.appendChild(b);}this.tbody.appendChild(I);}if(s&&a){let p=a.visibleRange;if(p.offsetBottom>0){let f=document.createElement("tr");f.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${p.offsetBottom}px`,h.style.padding="0",h.style.border="none",f.appendChild(h),this.tbody.appendChild(f);}}}getTableElement(){return this.table}getOnResizeStart(){return this.interactionState?.onResizeStart}updateDropIndicator(e,t){if(!this.dropIndicator||!this.wrapperEl)return;if(!t||e===null){this.dropIndicator.style.display="none";return}let i=this.wrapperEl.getBoundingClientRect(),n=e-i.left+this.wrapperEl.scrollLeft;this.dropIndicator.style.display="block",this.dropIndicator.style.left=`${n}px`;}destroy(){this.detachHeaderDelegation(),this.detachBodyDelegation(),this.container.innerHTML="",this.table=null,this.thead=null,this.tbody=null,this.dropIndicator=null;}};var W=class{constructor(e,t){this.el=null;this.container=e,this.state=t;}render(e,t){this.el&&this.el.remove();let i=getPaginationViewModel(this.state.page,this.state.pageSize,e,t?{pageSizeOptions:t}:void 0);if(!i)return;this.el=document.createElement("div"),this.el.className="ogrid-pagination";let n=document.createElement("div");n.className="ogrid-pagination-size";let r=document.createElement("span");r.textContent="Rows per page: ",n.appendChild(r);let o=document.createElement("select");o.className="ogrid-page-size-select";for(let c of i.pageSizeOptions){let u=document.createElement("option");u.value=String(c),u.textContent=String(c),u.selected=c===this.state.pageSize,o.appendChild(u);}o.addEventListener("change",()=>{this.state.setPageSize(Number(o.value));}),n.appendChild(o),this.el.appendChild(n);let l=document.createElement("span");l.className="ogrid-pagination-info",l.textContent=`${i.startItem}-${i.endItem} of ${e}`,this.el.appendChild(l);let a=document.createElement("div");a.className="ogrid-pagination-nav";let s=document.createElement("button");if(s.textContent="\u25C0",s.className="ogrid-pagination-btn",s.disabled=this.state.page===1,s.addEventListener("click",()=>this.state.setPage(this.state.page-1)),a.appendChild(s),i.showStartEllipsis){let c=document.createElement("span");c.textContent="...",c.className="ogrid-pagination-ellipsis",a.appendChild(c);}for(let c of i.pageNumbers){let u=document.createElement("button");u.textContent=String(c),u.className="ogrid-pagination-btn"+(c===this.state.page?" ogrid-pagination-active":""),u.addEventListener("click",()=>this.state.setPage(c)),a.appendChild(u);}if(i.showEndEllipsis){let c=document.createElement("span");c.textContent="...",c.className="ogrid-pagination-ellipsis",a.appendChild(c);}let d=document.createElement("button");d.textContent="\u25B6",d.className="ogrid-pagination-btn",d.disabled=this.state.page===i.totalPages,d.addEventListener("click",()=>this.state.setPage(this.state.page+1)),a.appendChild(d),this.el.appendChild(a),this.container.appendChild(this.el);}destroy(){this.el?.remove(),this.el=null;}};var G=class{constructor(e){this.el=null;this.container=e;}render(e){this.el&&this.el.remove();let t=getStatusBarParts(e);if(!(t.length===0&&!e.aggregation)){this.el=document.createElement("div"),this.el.className="ogrid-status-bar";for(let i of t){let n=document.createElement("span");n.className="ogrid-status-part",n.textContent=`${i.label}: ${i.value}`,this.el.appendChild(n);}if(e.aggregation){let i=e.aggregation,n=document.createElement("span");n.className="ogrid-status-aggregation",n.textContent=`Sum: ${i.sum.toLocaleString()} | Avg: ${i.avg.toFixed(2)} | Min: ${i.min} | Max: ${i.max} | Count: ${i.count}`,this.el.appendChild(n);}this.container.appendChild(this.el);}}destroy(){this.el?.remove(),this.el=null;}};var U=class{constructor(e,t){this.el=null;this.dropdown=null;this.isOpen=false;this.initialized=false;this.container=e,this.state=t;}render(){this.initialized||(this.createDOM(),this.initialized=true),this.isOpen&&this.dropdown&&this.updateDropdownState();}createDOM(){this.el=document.createElement("div"),this.el.className="ogrid-column-chooser";let e=document.createElement("button");e.className="ogrid-column-chooser-btn",e.textContent="Columns",e.addEventListener("click",()=>this.toggle()),this.el.appendChild(e),this.container.appendChild(this.el);}updateDropdownState(){if(!this.dropdown)return;let e=this.dropdown.querySelectorAll('input[type="checkbox"]'),t=this.state.columns;e.forEach((i,n)=>{n<t.length&&(i.checked=this.state.visibleColumns.has(t[n].columnId));});}toggle(){this.isOpen?this.close():this.open();}open(){if(!this.dropdown){this.isOpen=true,this.dropdown=document.createElement("div"),this.dropdown.className="ogrid-column-chooser-dropdown";for(let e of this.state.columns){let t=document.createElement("label");t.className="ogrid-column-chooser-item";let i=document.createElement("input");i.type="checkbox",i.checked=this.state.visibleColumns.has(e.columnId),i.disabled=!!e.required,i.addEventListener("change",()=>{let n=new Set(this.state.visibleColumns);i.checked?n.add(e.columnId):n.delete(e.columnId),this.state.setVisibleColumns(n);}),t.appendChild(i),t.appendChild(document.createTextNode(" "+e.name)),this.dropdown.appendChild(t);}this.el?.appendChild(this.dropdown);}}close(){this.isOpen=false,this.dropdown?.remove(),this.dropdown=null;}destroy(){this.close(),this.el?.remove(),this.el=null,this.initialized=false;}};var ke=["columns","filters"],K=class{constructor(e){this.emitter=new x;if(this._isEnabled=e!=null&&e!==false,!this._isEnabled||e===true)this._panels=ke,this._position="right",this._activePanel=null;else {let t=e;this._panels=t.panels??ke,this._position=t.position??"right",this._activePanel=t.defaultPanel??null;}}get isEnabled(){return this._isEnabled}get panels(){return this._panels}get position(){return this._position}get activePanel(){return this._activePanel}get isOpen(){return this._activePanel!==null}setActivePanel(e){this._activePanel=e,this.emitter.emit("change");}toggle(e){this.setActivePanel(this._activePanel===e?null:e);}close(){this.setActivePanel(null);}onChange(e){return this.emitter.on("change",e),()=>this.emitter.off("change",e)}destroy(){this.emitter.removeAllListeners();}};var pe={columns:"Columns",filters:"Filters"},ot={columns:"\u2261",filters:"\u2A65"},$=class{constructor(e,t){this.el=null;this.config=null;this.container=e,this.state=t;}setConfig(e){this.config=e;}render(){if(this.el&&this.el.remove(),!this.state.isEnabled||!this.config)return;this.el=document.createElement("div"),this.el.className="ogrid-sidebar",this.el.setAttribute("role","complementary"),this.el.setAttribute("aria-label","Side bar"),this.el.style.display="flex",this.el.style.flexDirection="row",this.el.style.flexShrink="0";let e=this.state.position,t=this.createTabStrip(e),i=this.createPanel(e);e==="left"?(this.el.appendChild(t),i&&this.el.appendChild(i)):(i&&this.el.appendChild(i),this.el.appendChild(t)),this.container.appendChild(this.el);}createTabStrip(e){let t=document.createElement("div");t.style.display="flex",t.style.flexDirection="column",t.style.width="36px",t.style.background="var(--ogrid-header-bg, #f5f5f5)",t.setAttribute("role","tablist"),t.setAttribute("aria-label","Side bar tabs"),e==="right"?t.style.borderLeft="1px solid var(--ogrid-border, #e0e0e0)":t.style.borderRight="1px solid var(--ogrid-border, #e0e0e0)";for(let i of this.state.panels){let n=document.createElement("button");n.setAttribute("role","tab"),n.setAttribute("aria-selected",String(this.state.activePanel===i)),n.setAttribute("aria-label",pe[i]),n.title=pe[i],n.textContent=ot[i],n.className="ogrid-sidebar-tab",n.style.width="36px",n.style.height="36px",n.style.border="none",n.style.cursor="pointer",n.style.color="var(--ogrid-fg, #242424)",n.style.fontSize="14px",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",this.state.activePanel===i?(n.style.background="var(--ogrid-bg, #fff)",n.style.fontWeight="bold"):(n.style.background="transparent",n.style.fontWeight="normal"),n.addEventListener("click",()=>{this.state.toggle(i);}),t.appendChild(n);}return t}createPanel(e){if(!this.state.isOpen||!this.state.activePanel)return null;let t=document.createElement("div");t.setAttribute("role","tabpanel"),t.setAttribute("aria-label",pe[this.state.activePanel]),t.className="ogrid-sidebar-panel",t.style.width="240px",t.style.display="flex",t.style.flexDirection="column",t.style.overflow="hidden",t.style.background="var(--ogrid-bg, #fff)",t.style.color="var(--ogrid-fg, #242424)",e==="right"?t.style.borderLeft="1px solid var(--ogrid-border, #e0e0e0)":t.style.borderRight="1px solid var(--ogrid-border, #e0e0e0)";let i=document.createElement("div");i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.padding="8px 12px",i.style.borderBottom="1px solid var(--ogrid-border, #e0e0e0)",i.style.fontWeight="600";let n=document.createElement("span");n.textContent=pe[this.state.activePanel],i.appendChild(n);let r=document.createElement("button");r.innerHTML="×",r.setAttribute("aria-label","Close panel"),r.style.border="none",r.style.background="transparent",r.style.cursor="pointer",r.style.fontSize="16px",r.style.color="var(--ogrid-fg, #242424)",r.addEventListener("click",()=>this.state.close()),i.appendChild(r),t.appendChild(i);let o=document.createElement("div");return o.style.flex="1",o.style.overflowY="auto",o.style.padding="8px 12px",this.state.activePanel==="columns"?this.renderColumnsPanel(o):this.state.activePanel==="filters"&&this.renderFiltersPanel(o),t.appendChild(o),t}renderColumnsPanel(e){if(!this.config)return;let{columns:t,visibleColumns:i,onVisibilityChange:n,onSetVisibleColumns:r}=this.config,o=t.every(d=>i.has(d.columnId)),l=document.createElement("div");l.style.display="flex",l.style.gap="8px",l.style.marginBottom="8px";let a=document.createElement("button");a.textContent="Select All",a.disabled=o,a.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(a),a.addEventListener("click",()=>{let d=new Set(i);t.forEach(c=>d.add(c.columnId)),r(d);}),l.appendChild(a);let s=document.createElement("button");s.textContent="Clear All",s.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(s),s.addEventListener("click",()=>{let d=new Set;t.forEach(c=>{c.required&&i.has(c.columnId)&&d.add(c.columnId);}),r(d);}),l.appendChild(s),e.appendChild(l);for(let d of t){let c=document.createElement("label");c.style.display="flex",c.style.alignItems="center",c.style.gap="6px",c.style.padding="2px 0",c.style.cursor="pointer";let u=document.createElement("input");u.type="checkbox",u.checked=i.has(d.columnId),u.disabled=!!d.required,u.addEventListener("change",()=>{n(d.columnId,u.checked);});let m=document.createElement("span");m.textContent=d.name,c.appendChild(u),c.appendChild(m),e.appendChild(c);}}renderFiltersPanel(e){if(!this.config)return;let{filterableColumns:t,filters:i,onFilterChange:n,filterOptions:r}=this.config;if(t.length===0){let o=document.createElement("div");o.style.color="var(--ogrid-muted, #999)",o.style.fontStyle="italic",o.textContent="No filterable columns",e.appendChild(o);return}for(let o of t){let l=document.createElement("div");l.style.marginBottom="12px";let a=document.createElement("div");if(a.style.fontWeight="500",a.style.marginBottom="4px",a.style.fontSize="13px",a.textContent=o.name,l.appendChild(a),o.filterType==="text"){let s=document.createElement("input");s.type="text";let d=i[o.filterField];s.value=d?.type==="text"?d.value:"",s.placeholder=`Filter ${o.name}...`,s.setAttribute("aria-label",`Filter ${o.name}`),this.applyTextInputStyle(s),s.addEventListener("input",()=>{n(o.filterField,s.value?{type:"text",value:s.value}:void 0);}),l.appendChild(s);}else if(o.filterType==="date"){let s=document.createElement("div");s.style.display="flex",s.style.flexDirection="column",s.style.gap="4px";let d=i[o.filterField],c=d?.type==="date"?d.value:{},u=document.createElement("label");u.style.display="flex",u.style.alignItems="center",u.style.gap="4px",u.style.fontSize="12px",u.textContent="From: ";let m=document.createElement("input");m.type="date",m.value=c.from??"",m.setAttribute("aria-label",`${o.name} from date`),this.applyDateInputStyle(m),u.appendChild(m),s.appendChild(u);let v=document.createElement("label");v.style.display="flex",v.style.alignItems="center",v.style.gap="4px",v.style.fontSize="12px",v.textContent="To: ";let g=document.createElement("input");g.type="date",g.value=c.to??"",g.setAttribute("aria-label",`${o.name} to date`),this.applyDateInputStyle(g),v.appendChild(g),s.appendChild(v);let S=()=>{let p=m.value||void 0,f=g.value||void 0;n(o.filterField,p||f?{type:"date",value:{from:p,to:f}}:void 0);};m.addEventListener("change",S),g.addEventListener("change",S),l.appendChild(s);}else if(o.filterType==="multiSelect"){let s=r[o.filterField]??[],d=document.createElement("div");d.style.maxHeight="120px",d.style.overflowY="auto",d.setAttribute("role","group"),d.setAttribute("aria-label",`${o.name} options`);let c=i[o.filterField],u=c?.type==="multiSelect"?c.value:[];for(let m of s){let v=document.createElement("label");v.style.display="flex",v.style.alignItems="center",v.style.gap="4px",v.style.padding="1px 0",v.style.cursor="pointer",v.style.fontSize="13px";let g=document.createElement("input");g.type="checkbox",g.checked=u.includes(m),g.addEventListener("change",()=>{let p=i[o.filterField],f=p?.type==="multiSelect"?[...p.value]:[],h=g.checked?[...f,m]:f.filter(I=>I!==m);n(o.filterField,h.length>0?{type:"multiSelect",value:h}:void 0);});let S=document.createElement("span");S.textContent=m,v.appendChild(g),v.appendChild(S),d.appendChild(v);}l.appendChild(d);}e.appendChild(l);}}applyActionButtonStyle(e){e.style.flex="1",e.style.cursor="pointer",e.style.background="var(--ogrid-bg-subtle, #f3f2f1)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px",e.style.padding="4px 8px";}applyTextInputStyle(e){e.style.width="100%",e.style.boxSizing="border-box",e.style.padding="4px 6px",e.style.background="var(--ogrid-bg, #fff)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}applyDateInputStyle(e){e.style.flex="1",e.style.padding="2px 4px",e.style.background="var(--ogrid-bg, #fff)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}destroy(){this.el?.remove(),this.el=null;}};var X=class{constructor(e){this.emitter=new x;this._openColumnId=null;this._tempTextValue="";this._tempSelected=new Set;this._tempDateFrom="";this._tempDateTo="";this._searchText="";this._popoverPosition=null;this._filters={};this._filterOptions={};this._clickOutsideHandler=null;this._escapeHandler=null;this._popoverEl=null;this._headerEl=null;this._onFilterChange=e;}get openColumnId(){return this._openColumnId}get tempTextValue(){return this._tempTextValue}get tempSelected(){return this._tempSelected}get tempDateFrom(){return this._tempDateFrom}get tempDateTo(){return this._tempDateTo}get searchText(){return this._searchText}get popoverPosition(){return this._popoverPosition}setFilters(e){this._filters=e;}setFilterOptions(e){this._filterOptions=e;}setPopoverEl(e){this._popoverEl=e;}getFilterOptions(e){return this._filterOptions[e]??[]}getFilteredOptions(e){let t=this.getFilterOptions(e);if(!this._searchText)return t;let i=this._searchText.toLowerCase();return t.filter(n=>n.toLowerCase().includes(i))}hasActiveFilter(e){let t=this._filters[e.filterField];return t?t.type==="text"?t.value.trim().length>0:t.type==="multiSelect"?t.value.length>0:t.type==="date"?!!(t.value.from||t.value.to):t.type==="people"?!!t.value:false:false}open(e,t,i,n){this._openColumnId&&this.close(),this._openColumnId=e,this._headerEl=i,this._popoverEl=n;let r=this._filters[t.filterField];if(t.filterType==="text")this._tempTextValue=r?.type==="text"?r.value:"";else if(t.filterType==="multiSelect")this._tempSelected=new Set(r?.type==="multiSelect"?r.value:[]);else if(t.filterType==="date"){let l=r?.type==="date"?r.value:{};this._tempDateFrom=l.from??"",this._tempDateTo=l.to??"";}this._searchText="";let o=i.getBoundingClientRect();this._popoverPosition={top:o.bottom+4,left:o.left},this._clickOutsideHandler=l=>{let a=l.target;this._popoverEl&&!this._popoverEl.contains(a)&&this._headerEl&&!this._headerEl.contains(a)&&this.close();},this._escapeHandler=l=>{l.key==="Escape"&&(l.preventDefault(),l.stopPropagation(),this.close());},setTimeout(()=>{this._clickOutsideHandler&&document.addEventListener("mousedown",this._clickOutsideHandler,{passive:true});},0),this._escapeHandler&&document.addEventListener("keydown",this._escapeHandler,true),this.emitter.emit("change");}close(){this._openColumnId=null,this._popoverPosition=null,this._popoverEl=null,this._headerEl=null,this._clickOutsideHandler&&(document.removeEventListener("mousedown",this._clickOutsideHandler),this._clickOutsideHandler=null),this._escapeHandler&&(document.removeEventListener("keydown",this._escapeHandler,true),this._escapeHandler=null),this.emitter.emit("change");}setTempTextValue(e){this._tempTextValue=e,this.emitter.emit("change");}setSearchText(e){this._searchText=e,this.emitter.emit("change");}setTempDateFrom(e){this._tempDateFrom=e,this.emitter.emit("change");}setTempDateTo(e){this._tempDateTo=e,this.emitter.emit("change");}handleCheckboxChange(e,t){let i=new Set(this._tempSelected);t?i.add(e):i.delete(e),this._tempSelected=i,this.emitter.emit("change");}handleSelectAll(e){this._tempSelected=new Set(this.getFilterOptions(e)),this.emitter.emit("change");}handleClearSelection(){this._tempSelected=new Set,this.emitter.emit("change");}applyTextFilter(e){let t=this._tempTextValue.trim();this._onFilterChange(e,t?{type:"text",value:t}:void 0),this.close();}clearTextFilter(e){this._tempTextValue="",this._onFilterChange(e,void 0),this.close();}applyMultiSelectFilter(e){let t=Array.from(this._tempSelected);this._onFilterChange(e,t.length>0?{type:"multiSelect",value:t}:void 0),this.close();}applyDateFilter(e){let t=this._tempDateFrom||void 0,i=this._tempDateTo||void 0;this._onFilterChange(e,t||i?{type:"date",value:{from:t,to:i}}:void 0),this.close();}clearDateFilter(e){this._tempDateFrom="",this._tempDateTo="",this._onFilterChange(e,void 0),this.close();}clearFilter(e){this._onFilterChange(e,void 0),this.close();}onChange(e){return this.emitter.on("change",e),()=>this.emitter.off("change",e)}destroy(){this.close(),this.emitter.removeAllListeners();}};var q=class{constructor(e){this.popoverEl=null;this.state=e;}render(e){if(this.cleanup(),!e||!this.state.openColumnId||!this.state.popoverPosition)return;let t=this.state.popoverPosition;this.popoverEl=document.createElement("div"),this.popoverEl.className="ogrid-header-filter-popover",this.popoverEl.style.position="fixed",this.popoverEl.style.top=`${t.top}px`,this.popoverEl.style.left=`${t.left}px`,this.popoverEl.style.zIndex="9999",this.popoverEl.style.background="var(--ogrid-bg, #fff)",this.popoverEl.style.color="var(--ogrid-fg, #242424)",this.popoverEl.style.border="1px solid var(--ogrid-border, #e0e0e0)",this.popoverEl.style.borderRadius="4px",this.popoverEl.style.boxShadow="var(--ogrid-shadow, 0 2px 8px rgba(0,0,0,0.15))",this.popoverEl.style.padding="8px",this.popoverEl.style.minWidth="200px",this.popoverEl.style.maxHeight="320px",this.popoverEl.style.overflowY="auto",this.popoverEl.addEventListener("click",i=>i.stopPropagation()),this.popoverEl.addEventListener("mousedown",i=>i.stopPropagation()),e.filterType==="text"?this.renderTextFilter(e):e.filterType==="multiSelect"?this.renderMultiSelectFilter(e):e.filterType==="date"&&this.renderDateFilter(e),document.body.appendChild(this.popoverEl);}renderTextFilter(e){if(!this.popoverEl)return;let t=document.createElement("input");t.type="text",t.value=this.state.tempTextValue,t.placeholder="Filter...",t.setAttribute("aria-label","Text filter"),t.className="ogrid-filter-text-input",this.applyInputStyle(t),t.style.marginBottom="8px",t.addEventListener("input",()=>{this.state.setTempTextValue(t.value);}),t.addEventListener("keydown",o=>{o.key==="Enter"&&this.state.applyTextFilter(e.filterField),o.stopPropagation();}),this.popoverEl.appendChild(t);let i=document.createElement("div");i.style.display="flex",i.style.gap="8px";let n=document.createElement("button");n.textContent="Apply",n.className="ogrid-filter-apply-btn",this.applyButtonStyle(n),n.addEventListener("click",()=>this.state.applyTextFilter(e.filterField)),i.appendChild(n);let r=document.createElement("button");r.textContent="Clear",r.className="ogrid-filter-clear-btn",this.applyButtonStyle(r),r.addEventListener("click",()=>this.state.clearTextFilter(e.filterField)),i.appendChild(r),this.popoverEl.appendChild(i),setTimeout(()=>t.focus(),0);}renderMultiSelectFilter(e){if(!this.popoverEl)return;let t=document.createElement("input");t.type="text",t.value=this.state.searchText,t.placeholder="Search...",t.setAttribute("aria-label","Search filter options"),t.className="ogrid-filter-search-input",this.applyInputStyle(t),t.style.marginBottom="8px",t.addEventListener("input",()=>{this.state.setSearchText(t.value),this.updateCheckboxList(e,o);}),t.addEventListener("keydown",a=>a.stopPropagation()),this.popoverEl.appendChild(t);let i=document.createElement("div");i.style.display="flex",i.style.gap="8px",i.style.marginBottom="8px";let n=document.createElement("button");n.textContent="Select All",n.className="ogrid-filter-select-all-btn",this.applySmallButtonStyle(n),n.addEventListener("click",()=>{this.state.handleSelectAll(e.filterField),this.updateCheckboxList(e,o);}),i.appendChild(n);let r=document.createElement("button");r.textContent="Clear",r.className="ogrid-filter-clear-sel-btn",this.applySmallButtonStyle(r),r.addEventListener("click",()=>{this.state.handleClearSelection(),this.updateCheckboxList(e,o);}),i.appendChild(r),this.popoverEl.appendChild(i);let o=document.createElement("div");o.className="ogrid-filter-checkbox-list",o.style.maxHeight="160px",o.style.overflowY="auto",o.style.marginBottom="8px",o.setAttribute("role","group"),o.setAttribute("aria-label","Filter options"),this.updateCheckboxList(e,o),this.popoverEl.appendChild(o);let l=document.createElement("button");l.textContent="Apply",l.className="ogrid-filter-apply-btn",this.applyButtonStyle(l),l.addEventListener("click",()=>this.state.applyMultiSelectFilter(e.filterField)),this.popoverEl.appendChild(l);}updateCheckboxList(e,t){t.innerHTML="";let i=this.state.getFilteredOptions(e.filterField),n=this.state.tempSelected;for(let r of i){let o=document.createElement("label");o.style.display="flex",o.style.alignItems="center",o.style.gap="4px",o.style.padding="2px 0",o.style.cursor="pointer",o.style.fontSize="13px";let l=document.createElement("input");l.type="checkbox",l.checked=n.has(r),l.addEventListener("change",()=>{this.state.handleCheckboxChange(r,l.checked);});let a=document.createElement("span");a.textContent=r,o.appendChild(l),o.appendChild(a),t.appendChild(o);}if(i.length===0){let r=document.createElement("div");r.style.color="var(--ogrid-muted, #999)",r.style.fontStyle="italic",r.style.padding="4px 0",r.textContent="No options",t.appendChild(r);}}renderDateFilter(e){if(!this.popoverEl)return;let t=document.createElement("div");t.style.display="flex",t.style.flexDirection="column",t.style.gap="8px";let i=document.createElement("label");i.style.display="flex",i.style.alignItems="center",i.style.gap="4px",i.style.fontSize="13px",i.textContent="From: ";let n=document.createElement("input");n.type="date",n.value=this.state.tempDateFrom,n.setAttribute("aria-label","From date"),this.applyInputStyle(n),n.addEventListener("change",()=>{this.state.setTempDateFrom(n.value);}),n.addEventListener("keydown",d=>d.stopPropagation()),i.appendChild(n),t.appendChild(i);let r=document.createElement("label");r.style.display="flex",r.style.alignItems="center",r.style.gap="4px",r.style.fontSize="13px",r.textContent="To: ";let o=document.createElement("input");o.type="date",o.value=this.state.tempDateTo,o.setAttribute("aria-label","To date"),this.applyInputStyle(o),o.addEventListener("change",()=>{this.state.setTempDateTo(o.value);}),o.addEventListener("keydown",d=>d.stopPropagation()),r.appendChild(o),t.appendChild(r),this.popoverEl.appendChild(t);let l=document.createElement("div");l.style.display="flex",l.style.gap="8px",l.style.marginTop="8px";let a=document.createElement("button");a.textContent="Apply",a.className="ogrid-filter-apply-btn",this.applyButtonStyle(a),a.addEventListener("click",()=>this.state.applyDateFilter(e.filterField)),l.appendChild(a);let s=document.createElement("button");s.textContent="Clear",s.className="ogrid-filter-clear-btn",this.applyButtonStyle(s),s.addEventListener("click",()=>this.state.clearDateFilter(e.filterField)),l.appendChild(s),this.popoverEl.appendChild(l);}applyInputStyle(e){e.style.width="100%",e.style.boxSizing="border-box",e.style.padding="4px 6px",e.style.background="var(--ogrid-bg, #fff)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}applyButtonStyle(e){e.style.flex="1",e.style.cursor="pointer",e.style.padding="6px 12px",e.style.background="var(--ogrid-bg-subtle, #f3f2f1)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}applySmallButtonStyle(e){e.style.cursor="pointer",e.style.padding="2px 8px",e.style.fontSize="12px",e.style.background="transparent",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}cleanup(){this.popoverEl&&(this.popoverEl.remove(),this.popoverEl=null);}destroy(){this.cleanup();}};var j=class{constructor(){this.emitter=new x;this._containerWidth=0;this._columnSizingOverrides={};this._ro=null;}observeContainer(e){this.disconnectObserver(),typeof ResizeObserver<"u"&&(this._ro=new ResizeObserver(t=>{for(let i of t){let n=i.contentRect;this._containerWidth=n.width,this.emitter.emit("layoutChange",{type:"containerResize"});}}),this._ro.observe(e)),this._containerWidth=e.clientWidth;}disconnectObserver(){this._ro&&(this._ro.disconnect(),this._ro=null);}get containerWidth(){return this._containerWidth}get columnSizingOverrides(){return this._columnSizingOverrides}setColumnOverride(e,t){this._columnSizingOverrides[e]=t,this.emitter.emit("layoutChange",{type:"columnOverride"});}computeMinTableWidth(e,t){return (t?CHECKBOX_COLUMN_WIDTH:0)+e*(DEFAULT_MIN_COLUMN_WIDTH+CELL_PADDING)}computeDesiredTableWidth(e,t){let n=t?CHECKBOX_COLUMN_WIDTH:0;for(let r of e){let o=this._columnSizingOverrides[r.columnId];o?n+=o+CELL_PADDING:n+=(r.width??r.minWidth??DEFAULT_MIN_COLUMN_WIDTH)+CELL_PADDING;}return n}getAllColumnWidths(){return {...this._columnSizingOverrides}}cleanupOverrides(e){let t={},i=false;for(let[n,r]of Object.entries(this._columnSizingOverrides))e.has(n)?t[n]=r:i=true;i&&(this._columnSizingOverrides=t,this.emitter.emit("layoutChange",{type:"columnOverride"}));}applyInitialWidths(e){this._columnSizingOverrides={...e};}onLayoutChange(e){return this.emitter.on("layoutChange",e),()=>this.emitter.off("layoutChange",e)}destroy(){this.disconnectObserver(),this.emitter.removeAllListeners();}};var Y=class{constructor(e,t){this.emitter=new x;this._selectedRowIds=new Set;this._lastClickedRow=-1;this._rowSelection=e,this._getRowId=t;}get selectedRowIds(){return this._selectedRowIds}get rowSelection(){return this._rowSelection}updateSelection(e,t){this._selectedRowIds=e,this.emitter.emit("rowSelectionChange",{selectedRowIds:Array.from(e),selectedItems:t.filter(i=>e.has(this._getRowId(i)))});}handleRowCheckboxChange(e,t,i,n,r){if(this._rowSelection==="single"){this.updateSelection(t?new Set([e]):new Set,r),this._lastClickedRow=i;return}let o;n&&this._lastClickedRow>=0&&this._lastClickedRow!==i?o=applyRangeRowSelection(this._lastClickedRow,i,t,r,this._getRowId,this._selectedRowIds):(o=new Set(this._selectedRowIds),t?o.add(e):o.delete(e)),this._lastClickedRow=i,this.updateSelection(o,r);}handleSelectAll(e,t){e?this.updateSelection(new Set(t.map(i=>this._getRowId(i))),t):this.updateSelection(new Set,t);}isAllSelected(e){return computeRowSelectionState(this._selectedRowIds,e,this._getRowId).allSelected}isSomeSelected(e){return computeRowSelectionState(this._selectedRowIds,e,this._getRowId).someSelected}getSelectedRows(e){return e.filter(t=>this._selectedRowIds.has(this._getRowId(t)))}onRowSelectionChange(e){return this.emitter.on("rowSelectionChange",e),()=>this.emitter.off("rowSelectionChange",e)}destroy(){this.emitter.removeAllListeners();}};var Z=class{constructor(e,t){this.emitter=new x;this._pinnedColumns={};if(e&&(this._pinnedColumns={...e}),t)for(let i of t)i.pinned&&!(i.columnId in this._pinnedColumns)&&(this._pinnedColumns[i.columnId]=i.pinned);}get pinnedColumns(){return this._pinnedColumns}pinColumn(e,t){this._pinnedColumns={...this._pinnedColumns,[e]:t},this.emitter.emit("pinningChange",{pinnedColumns:this._pinnedColumns});}unpinColumn(e){let{[e]:t,...i}=this._pinnedColumns;this._pinnedColumns=i,this.emitter.emit("pinningChange",{pinnedColumns:this._pinnedColumns});}isPinned(e){return this._pinnedColumns[e]}computeLeftOffsets(e,t,i,n,r,o){let l={},a=0;n&&(a+=r),o&&(a+=ROW_NUMBER_COLUMN_WIDTH);for(let s of e)this._pinnedColumns[s.columnId]==="left"&&(l[s.columnId]=a,a+=t[s.columnId]??i);return l}computeRightOffsets(e,t,i){let n={},r=0;for(let o=e.length-1;o>=0;o--){let l=e[o];this._pinnedColumns[l.columnId]==="right"&&(n[l.columnId]=r,r+=t[l.columnId]??i);}return n}onPinningChange(e){return this.emitter.on("pinningChange",e),()=>this.emitter.off("pinningChange",e)}destroy(){this.emitter.removeAllListeners();}};var Re=36,ut=5,ht=100,J=class{constructor(e){this.emitter=new x;this._scrollTop=0;this._containerHeight=0;this._totalRows=0;this.rafId=0;this._ro=null;this._resizeRafId=0;this._cachedRange={startIndex:0,endIndex:-1,offsetTop:0,offsetBottom:0};this._scrollLeft=0;this._scrollLeftRafId=0;this._containerWidth=0;this._columnWidths=[];this._cachedColumnRange=null;this._roWidth=null;this._resizeWidthRafId=0;this._config=e??{enabled:false},validateVirtualScrollConfig(this._config);}get enabled(){let e=this._config.threshold??ht;return this._config.enabled===true&&this._totalRows>=e}get config(){return this._config}get containerHeight(){return this._containerHeight}get totalRows(){return this._totalRows}get scrollTop(){return this._scrollTop}get visibleRange(){return this._cachedRange}get totalHeight(){return computeTotalHeight(this._totalRows,this._config.rowHeight??Re)}get columnVirtualizationEnabled(){return this._config.columns===true}get columnRange(){return this._cachedColumnRange}setColumnWidths(e){this._columnWidths=e,this.recomputeColumnRange();}handleHorizontalScroll(e){this.columnVirtualizationEnabled&&(this._scrollLeftRafId&&cancelAnimationFrame(this._scrollLeftRafId),this._scrollLeftRafId=requestAnimationFrame(()=>{this._scrollLeftRafId=0,this._scrollLeft=e,this.recomputeColumnRange();}));}observeContainerWidth(e){this.disconnectWidthObserver(),typeof ResizeObserver<"u"&&(this._roWidth=new ResizeObserver(t=>{t.length!==0&&(this._containerWidth=t[0].contentRect.width,this._resizeWidthRafId&&cancelAnimationFrame(this._resizeWidthRafId),this._resizeWidthRafId=requestAnimationFrame(()=>{this._resizeWidthRafId=0,this.recomputeColumnRange();}));}),this._roWidth.observe(e)),this._containerWidth=e.clientWidth;}disconnectWidthObserver(){this._roWidth&&(this._roWidth.disconnect(),this._roWidth=null);}recomputeColumnRange(){if(!this.columnVirtualizationEnabled||this._columnWidths.length===0||this._containerWidth<=0){this._cachedColumnRange!==null&&(this._cachedColumnRange=null,this.emitter.emit("columnRangeChanged",{columnRange:null}));return}let e=this._config.columnOverscan??2,t=computeVisibleColumnRange(this._scrollLeft,this._columnWidths,this._containerWidth,e),i=this._cachedColumnRange;!i||i.startIndex!==t.startIndex||i.endIndex!==t.endIndex?(this._cachedColumnRange=t,this.emitter.emit("columnRangeChanged",{columnRange:t})):this._cachedColumnRange=t;}handleScroll(e){this.rafId&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.rafId=0,this._scrollTop=e,this.recompute();});}scrollToRow(e,t,i){let n=this._config.rowHeight??Re,r=getScrollTopForRow(e,n,this._containerHeight,i);t.scrollTop=r,this._scrollTop=r,this.recompute();}updateConfig(e){validateVirtualScrollConfig(e),this._config=e,this.recompute(),this.emitter.emit("configChanged",{config:e});}setTotalRows(e){this._totalRows=e,this.recompute();}observeContainer(e){this.disconnectObserver(),typeof ResizeObserver<"u"&&(this._ro=new ResizeObserver(t=>{t.length!==0&&(this._containerHeight=t[0].contentRect.height,this._resizeRafId&&cancelAnimationFrame(this._resizeRafId),this._resizeRafId=requestAnimationFrame(()=>{this._resizeRafId=0,this.recompute();}));}),this._ro.observe(e)),this._containerHeight=e.clientHeight;}disconnectObserver(){this._ro&&(this._ro.disconnect(),this._ro=null);}recompute(){if(!this.enabled)return;let e=this._config.rowHeight??Re,t=this._config.overscan??ut,i=computeVisibleRange(this._scrollTop,e,this._containerHeight,this._totalRows,t),n=this._cachedRange;n.startIndex!==i.startIndex||n.endIndex!==i.endIndex?(this._cachedRange=i,this.emitter.emit("rangeChanged",{visibleRange:i})):this._cachedRange=i;}onRangeChanged(e){return this.emitter.on("rangeChanged",e),()=>this.emitter.off("rangeChanged",e)}onColumnRangeChanged(e){return this.emitter.on("columnRangeChanged",e),()=>this.emitter.off("columnRangeChanged",e)}onConfigChanged(e){return this.emitter.on("configChanged",e),()=>this.emitter.off("configChanged",e)}destroy(){this.rafId&&cancelAnimationFrame(this.rafId),this._resizeRafId&&cancelAnimationFrame(this._resizeRafId),this._scrollLeftRafId&&cancelAnimationFrame(this._scrollLeftRafId),this._resizeWidthRafId&&cancelAnimationFrame(this._resizeWidthRafId),this.disconnectObserver(),this.disconnectWidthObserver(),this.emitter.removeAllListeners();}};var Q=class{constructor(){this.emitter=new x;this._activeCell=null;this._selectionRange=null;this._selectedRowIds=new Set;this._isDragging=false;this.dragStartCell=null;this.rafHandle=null;this.pendingRange=null;}get activeCell(){return this._activeCell}get dragAnchor(){return this.dragStartCell}get selectionRange(){return this._selectionRange}get selectedRowIds(){return this._selectedRowIds}get isDragging(){return this._isDragging}getDragRange(){return this.pendingRange}setActiveCell(e){this._activeCell=e,this._selectionRange=e!=null?{startRow:e.rowIndex,startCol:e.columnIndex,endRow:e.rowIndex,endCol:e.columnIndex}:null,this.emitter.emit("selectionChange",{activeCell:e,selectionRange:this._selectionRange});}setSelectionRange(e){this._selectionRange=e,this.emitter.emit("selectionChange",{activeCell:this._activeCell,selectionRange:e});}clearSelection(){this._activeCell=null,this._selectionRange=null,this.emitter.emit("selectionChange",{activeCell:null,selectionRange:null});}startDrag(e,t){this._isDragging=true,this.dragStartCell={rowIndex:e,columnIndex:t},this._activeCell={rowIndex:e,columnIndex:t},this._selectionRange={startRow:e,startCol:t,endRow:e,endCol:t};}updateDrag(e,t,i){if(!this._isDragging||!this.dragStartCell)return;let n={startRow:this.dragStartCell.rowIndex,startCol:this.dragStartCell.columnIndex,endRow:e,endCol:t};rangesEqual(this.pendingRange,n)||(this.pendingRange=n,this.rafHandle===null&&(this.rafHandle=requestAnimationFrame(()=>{this.pendingRange&&i(this.pendingRange),this.rafHandle=null;})));}endDrag(){this.rafHandle!==null&&(cancelAnimationFrame(this.rafHandle),this.rafHandle=null),this.pendingRange&&(this._selectionRange=this.pendingRange,this.pendingRange=null,this.emitter.emit("selectionChange",{activeCell:this._activeCell,selectionRange:this._selectionRange})),this._isDragging=false,this.dragStartCell=null;}setSelectedRowIds(e){this._selectedRowIds=e,this.emitter.emit("rowSelectionChange",{selectedRowIds:e});}onSelectionChange(e){return this.emitter.on("selectionChange",e),()=>this.emitter.off("selectionChange",e)}onRowSelectionChange(e){return this.emitter.on("rowSelectionChange",e),()=>this.emitter.off("rowSelectionChange",e)}destroy(){this.rafHandle!==null&&cancelAnimationFrame(this.rafHandle),this.emitter.removeAllListeners();}};var ee=class{constructor(e,t,i,n,r){this.wrapperRef=null;this.handleKeyDown=e=>{let{items:t,visibleCols:i,colOffset:n,editable:r,onCellValueChanged:o,onCopy:l,onCut:a,onPaste:s,onUndo:d,onRedo:c,onContextMenu:u,onStartEdit:m,getRowId:v,clearClipboardRanges:g,onKeyDown:S,onFillDown:p}=this.params;if(S&&(S(e),e.defaultPrevented))return;let f=this.getActiveCell(),h=this.getSelectionRange(),I=t.length-1,w=i.length-1+n;if(t.length===0)return;if(f===null){["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Tab","Enter","Home","End","PageDown","PageUp"].includes(e.key)&&(this.setActiveCell({rowIndex:0,columnIndex:n}),e.preventDefault());return}let{rowIndex:b,columnIndex:y}=f,A=y-n,E=e.shiftKey,T=(C,_)=>{if(C<0||C>=t.length||_<0||_>=i.length)return true;let F=getCellValue(t[C],i[_]);return F==null||F===""};switch(e.key){case "c":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),l?.());break;case "x":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),a?.());break;case "v":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),s?.());break;case "d":(e.ctrlKey||e.metaKey)&&r!==false&&p&&(e.preventDefault(),p());break;case "ArrowDown":case "ArrowUp":case "ArrowRight":case "ArrowLeft":{e.preventDefault();let{newRowIndex:C,newColumnIndex:_,newRange:F}=computeArrowNavigation({direction:e.key,rowIndex:b,columnIndex:y,dataColIndex:A,colOffset:n,maxRowIndex:I,maxColIndex:w,visibleColCount:i.length,isCtrl:e.ctrlKey||e.metaKey,isShift:E,selectionRange:h,isEmptyAt:T});this.setActiveCell({rowIndex:C,columnIndex:_}),this.setSelectionRange(F);break}case "Tab":{e.preventDefault();let C=computeTabNavigation(b,y,I,w,n,e.shiftKey),_=C.columnIndex-n;this.setActiveCell({rowIndex:C.rowIndex,columnIndex:C.columnIndex}),this.setSelectionRange({startRow:C.rowIndex,startCol:_,endRow:C.rowIndex,endCol:_});break}case "Home":{e.preventDefault();let C=e.ctrlKey?0:b;this.setActiveCell({rowIndex:C,columnIndex:n}),this.setSelectionRange({startRow:C,startCol:0,endRow:C,endCol:0});break}case "End":{e.preventDefault();let C=e.ctrlKey?I:b;this.setActiveCell({rowIndex:C,columnIndex:w}),this.setSelectionRange({startRow:C,startCol:i.length-1,endRow:C,endCol:i.length-1});break}case "PageDown":case "PageUp":{e.preventDefault();let C=this.wrapperRef,_=10,F=36;if(C){let O=C.querySelector("tbody tr");O&&O.offsetHeight>0&&(F=O.offsetHeight,_=Math.max(1,Math.floor(C.clientHeight/F)));}let H=e.key==="PageDown"?1:-1,D=Math.max(0,Math.min(b+H*_,I));e.shiftKey?this.setSelectionRange({startRow:h?.startRow??b,startCol:h?.startCol??A,endRow:D,endCol:h?.endCol??A}):this.setSelectionRange({startRow:D,startCol:A,endRow:D,endCol:A}),this.setActiveCell({rowIndex:D,columnIndex:y}),C&&(C.scrollTop=getScrollTopForRow(D,F,C.clientHeight,"center"));break}case "Enter":case "F2":{if(e.preventDefault(),A>=0&&A<i.length){let C=i[A],_=t[b];if(_&&C){let F=C.editable===true||typeof C.editable=="function"&&C.editable(_);r!==false&&F&&m?.(v(_),C.columnId);}}break}case "Escape":e.preventDefault(),g?.(),this.setActiveCell(null),this.setSelectionRange(null);break;case "z":(e.ctrlKey||e.metaKey)&&(e.shiftKey&&c?(e.preventDefault(),c()):!e.shiftKey&&d&&(e.preventDefault(),d()));break;case "y":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),c?.());break;case "a":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),t.length>0&&i.length>0&&(this.setActiveCell({rowIndex:0,columnIndex:n}),this.setSelectionRange({startRow:0,startCol:0,endRow:t.length-1,endCol:i.length-1})));break;case "Delete":case "Backspace":{if(r===false||o==null)break;let C=h??(f!=null?{startRow:f.rowIndex,startCol:f.columnIndex-n,endRow:f.rowIndex,endCol:f.columnIndex-n}:null);if(C==null)break;e.preventDefault();let _=applyCellDeletion(C,t,i);for(let F of _)o(F);break}case "F10":if(e.shiftKey)if(e.preventDefault(),f!=null&&this.wrapperRef){let C=`[data-row-index="${f.rowIndex}"][data-col-index="${f.columnIndex}"]`,_=this.wrapperRef.querySelector(C);if(_){let F=_.getBoundingClientRect();u?.(F.left+F.width/2,F.top+F.height/2);}else u?.(100,100);}else u?.(100,100);break;}};this.params=e,this.getActiveCell=t,this.getSelectionRange=i,this.setActiveCell=n,this.setSelectionRange=r;}setWrapperRef(e){this.wrapperRef=e;}updateParams(e){this.params=e;}};var te=class{constructor(e,t,i){this.emitter=new x;this._cutRange=null;this._copyRange=null;this.internalClipboard=null;this.params=e,this.getActiveCell=t,this.getSelectionRange=i;}updateParams(e){this.params=e;}get cutRange(){return this._cutRange}get copyRange(){return this._copyRange}getEffectiveRange(){let e=this.getSelectionRange(),t=this.getActiveCell();return e??(t!=null?{startRow:t.rowIndex,startCol:t.columnIndex-this.params.colOffset,endRow:t.rowIndex,endCol:t.columnIndex-this.params.colOffset}:null)}handleCopy(){let e=this.getEffectiveRange();if(e==null)return;let t=normalizeSelectionRange(e),{items:i,visibleCols:n,formulas:r,flatColumns:o,getFormula:l,hasFormula:a,colOffset:s}=this.params,c=formatSelectionAsTsv(i,n,t,r&&o?{colOffset:s,flatColumns:o,getFormula:l,hasFormula:a}:void 0);this.internalClipboard=c,this._copyRange=t,this._cutRange=null,this.emitter.emit("rangesChange",{copyRange:this._copyRange,cutRange:null}),typeof navigator<"u"&&navigator.clipboard&&navigator.clipboard.writeText(c).catch(()=>{});}handleCut(){if(this.params.editable===false)return;let e=this.getEffectiveRange();if(e==null)return;let t=normalizeSelectionRange(e);this._cutRange=t,this._copyRange=null,this.handleCopy(),this._copyRange=null,this._cutRange=t,this.emitter.emit("rangesChange",{copyRange:null,cutRange:this._cutRange});}async handlePaste(){if(this.params.editable===false)return;let{onCellValueChanged:e}=this.params,t;try{typeof navigator<"u"&&navigator.clipboard?t=await navigator.clipboard.readText():t="";}catch{t="";}if(!t.trim()&&this.internalClipboard!=null&&(t=this.internalClipboard),!t.trim()||e==null)return;let i=this.getEffectiveRange(),n=i?i.startRow:0,r=i?i.startCol:0,{items:o,visibleCols:l,formulas:a,flatColumns:s,setFormula:d,colOffset:c}=this.params,u=a&&s?{colOffset:c,flatColumns:s,setFormula:d}:void 0,m=parseTsvClipboard(t),v=applyPastedValues(m,n,r,o,l,u);for(let g of v)e(g);if(this._cutRange){let g=applyCutClear(this._cutRange,o,l);for(let S of g)e(S);this._cutRange=null;}this._copyRange=null,this.emitter.emit("rangesChange",{copyRange:null,cutRange:null});}clearClipboardRanges(){this._copyRange=null,this._cutRange=null,this.emitter.emit("rangesChange",{copyRange:null,cutRange:null});}onRangesChange(e){return this.emitter.on("rangesChange",e),()=>this.emitter.off("rangesChange",e)}destroy(){this.emitter.removeAllListeners();}};var ie=class{constructor(e,t=100){this.onCellValueChanged=e;this.emitter=new x;this.stack=new UndoRedoStack(t),e&&(this.wrappedCallback=i=>{this.stack.record(i),this.stack.isBatching||this.emitStackChange(),e(i);});}get canUndo(){return this.stack.canUndo}get canRedo(){return this.stack.canRedo}getWrappedCallback(){return this.wrappedCallback}beginBatch(){this.stack.beginBatch();}endBatch(){this.stack.endBatch(),this.emitStackChange();}undo(){if(!this.onCellValueChanged)return;let e=this.stack.undo();if(e){this.emitStackChange();for(let t=e.length-1;t>=0;t--){let i=e[t];this.onCellValueChanged({...i,oldValue:i.newValue,newValue:i.oldValue});}}}redo(){if(!this.onCellValueChanged)return;let e=this.stack.redo();if(e){this.emitStackChange();for(let t of e)this.onCellValueChanged(t);}}emitStackChange(){this.emitter.emit("stackChange",{canUndo:this.canUndo,canRedo:this.canRedo});}onStackChange(e){return this.emitter.on("stackChange",e),()=>this.emitter.off("stackChange",e)}destroy(){this.emitter.removeAllListeners();}};var ne=class{constructor(){this.emitter=new x;this.columnWidths=new Map;this.isResizing=false;this.resizeColumnId=null;this.resizeStartX=0;this.resizeStartWidth=0;}get resizingColumnId(){return this.resizeColumnId}getColumnWidth(e){return this.columnWidths.get(e)}getAllColumnWidths(){let e={};return this.columnWidths.forEach((t,i)=>{e[i]=t;}),e}startResize(e,t,i){this.isResizing=true,this.resizeColumnId=e,this.resizeStartX=t,this.resizeStartWidth=i;}updateResize(e){if(!this.isResizing||!this.resizeColumnId)return null;let t=e-this.resizeStartX,i=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH;return Math.max(i,this.resizeStartWidth+t)}endResize(e){if(!this.isResizing||!this.resizeColumnId)return;let t=e-this.resizeStartX,i=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH,n=Math.max(i,this.resizeStartWidth+t);this.columnWidths.set(this.resizeColumnId,n),this.emitter.emit("columnWidthChange",{columnId:this.resizeColumnId,widthPx:n}),this.isResizing=false,this.resizeColumnId=null;}setColumnWidth(e,t){this.columnWidths.set(e,t),this.emitter.emit("columnWidthChange",{columnId:e,widthPx:t});}onColumnWidthChange(e){return this.emitter.on("columnWidthChange",e),()=>this.emitter.off("columnWidthChange",e)}destroy(){this.emitter.removeAllListeners();}};var oe=class{constructor(e,t,i,n){this.emitter=new x;this.wrapperRef=null;this._isFillDragging=false;this.fillDragStart=null;this.fillDragEnd={endRow:0,endCol:0};this.rafHandle=0;this.liveFillRange=null;this.lastMousePos=null;this.cachedCells=null;this.params=e,this.getSelectionRange=t,this.setSelectionRange=i,this.setActiveCell=n,this.onMoveBound=this.onMouseMove.bind(this),this.onUpBound=this.onMouseUp.bind(this);}get isFillDragging(){return this._isFillDragging}get fillRange(){return this.liveFillRange}setWrapperRef(e){this.wrapperRef=e;}updateParams(e){this.params=e;}fillDown(){let e=this.getSelectionRange();if(!e||this.params.editable===false||!this.params.onCellValueChanged)return;let t=normalizeSelectionRange(e);this.applyFillValuesFromCore(t,{startRow:t.startRow,startCol:t.startCol});}startFillDrag(e){e.preventDefault(),e.stopPropagation();let t=this.getSelectionRange();t&&(this.params.editable===false||!this.params.onCellValueChanged||(this._isFillDragging=true,this.fillDragStart={startRow:t.startRow,startCol:t.startCol},this.fillDragEnd={endRow:t.startRow,endCol:t.startCol},this.liveFillRange=null,this.cachedCells=this.wrapperRef?this.wrapperRef.querySelectorAll("[data-row-index][data-col-index]"):null,window.addEventListener("pointermove",this.onMoveBound,{capture:true,passive:true}),window.addEventListener("pointerup",this.onUpBound,{capture:true,passive:true})));}onMouseMove(e){!this._isFillDragging||!this.fillDragStart||(this.lastMousePos={cx:e.clientX,cy:e.clientY},this.rafHandle&&cancelAnimationFrame(this.rafHandle),this.rafHandle=requestAnimationFrame(()=>{if(this.rafHandle=0,!this.lastMousePos)return;let t=this.resolveRange(this.lastMousePos.cx,this.lastMousePos.cy);if(!t)return;let i=this.liveFillRange;i&&i.startRow===t.startRow&&i.startCol===t.startCol&&i.endRow===t.endRow&&i.endCol===t.endCol||(this.liveFillRange=t,this.fillDragEnd={endRow:t.endRow,endCol:t.endCol},this.applyDragAttrs(t));}));}onMouseUp(){if(!this._isFillDragging||!this.fillDragStart)return;if(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true),this.rafHandle&&(cancelAnimationFrame(this.rafHandle),this.rafHandle=0),this.lastMousePos){let n=this.resolveRange(this.lastMousePos.cx,this.lastMousePos.cy);n&&(this.liveFillRange=n,this.fillDragEnd={endRow:n.endRow,endCol:n.endCol});}this.clearDragAttrs();let e=this.fillDragStart,t=this.fillDragEnd,i=normalizeSelectionRange({startRow:e.startRow,startCol:e.startCol,endRow:t.endRow,endCol:t.endCol});this.setSelectionRange(i),this.setActiveCell({rowIndex:e.startRow,columnIndex:e.startCol+this.params.colOffset}),this.applyFillValuesFromCore(i,e),this._isFillDragging=false,this.fillDragStart=null,this.liveFillRange=null,this.lastMousePos=null,this.emitter.emit("fillRangeChange",{fillRange:null});}applyFillValuesFromCore(e,t){let{items:i,visibleCols:n,onCellValueChanged:r,beginBatch:o,endBatch:l,formulaOptions:a}=this.params;if(!r)return;let s=applyFillValues(e,t.startRow,t.startCol,i,n,a);if(s.length>0){o?.();for(let d of s)r(d);l?.();}}resolveRange(e,t){if(!this.fillDragStart||!this.wrapperRef)return null;let n=document.elementFromPoint(e,t)?.closest?.("[data-row-index][data-col-index]");if(!n||!this.wrapperRef.contains(n))return null;let r=L(n);if(!r||r.colIndex<this.params.colOffset)return null;let o=r.rowIndex,l=r.colIndex-this.params.colOffset;return normalizeSelectionRange({startRow:this.fillDragStart.startRow,startCol:this.fillDragStart.startCol,endRow:o,endCol:l})}applyDragAttrs(e){let t=this.cachedCells;if(!t)return;let i=this.params.colOffset,n=Math.min(e.startRow,e.endRow),r=Math.max(e.startRow,e.endRow),o=Math.min(e.startCol,e.endCol),l=Math.max(e.startCol,e.endCol);for(let a=0;a<t.length;a++){let s=t[a],d=L(s);if(!d)continue;let c=d.rowIndex,u=d.colIndex-i;c>=n&&c<=r&&u>=o&&u<=l?s.hasAttribute("data-drag-range")||s.setAttribute("data-drag-range",""):s.hasAttribute("data-drag-range")&&s.removeAttribute("data-drag-range");}}clearDragAttrs(){let e=this.cachedCells;if(e)for(let t=0;t<e.length;t++)e[t].removeAttribute("data-drag-range");this.cachedCells=null;}onFillRangeChange(e){return this.emitter.on("fillRangeChange",e),()=>this.emitter.off("fillRangeChange",e)}destroy(){this._isFillDragging&&(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true),this.clearDragAttrs(),this._isFillDragging=false,this.fillDragStart=null,this.liveFillRange=null,this.lastMousePos=null),this.rafHandle&&(cancelAnimationFrame(this.rafHandle),this.rafHandle=0),this.emitter.removeAllListeners();}};var re=class{constructor(){this.emitter=new x;this._isDragging=false;this._draggedColumnId=null;this._dropIndicatorX=null;this._dropTargetIndex=null;this.rafId=0;this.columnOrder=[];this.draggedPinState="unpinned";this.tableElement=null;this.onMoveBound=this.handleMouseMove.bind(this),this.onUpBound=this.handleMouseUp.bind(this);}get isDragging(){return this._isDragging}get dropIndicatorX(){return this._dropIndicatorX}startDrag(e,t,i,n,r,o){if(t.preventDefault(),this._isDragging=true,this._draggedColumnId=e,this._dropIndicatorX=null,this._dropTargetIndex=null,this.tableElement=o,this.columnOrder=n.length>0?[...n]:i.map(l=>l.columnId),r){let l=[],a=[];for(let[s,d]of Object.entries(r))d==="left"?l.push(s):d==="right"&&a.push(s);this.pinnedColumns={left:l,right:a};}else this.pinnedColumns=void 0;this.draggedPinState=getPinStateForColumn(e,this.pinnedColumns),window.addEventListener("pointermove",this.onMoveBound,{capture:true,passive:true}),window.addEventListener("pointerup",this.onUpBound,{capture:true,passive:true}),this.emitter.emit("stateChange",{isDragging:true,dropIndicatorX:null});}handleMouseMove(e){if(!this._isDragging||!this._draggedColumnId||!this.tableElement)return;this.rafId&&cancelAnimationFrame(this.rafId);let t=e.clientX;this.rafId=requestAnimationFrame(()=>{if(this.rafId=0,!this._draggedColumnId||!this.tableElement)return;let i=calculateDropTarget({mouseX:t,columnOrder:this.columnOrder,draggedColumnId:this._draggedColumnId,draggedPinState:this.draggedPinState,tableElement:this.tableElement,pinnedColumns:this.pinnedColumns});if(!i)return;let n=this._dropIndicatorX,r=this._dropTargetIndex;this._dropTargetIndex=i.targetIndex,this._dropIndicatorX=i.indicatorX,(n!==i.indicatorX||r!==i.targetIndex)&&this.emitter.emit("stateChange",{isDragging:true,dropIndicatorX:i.indicatorX});});}handleMouseUp(){if(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true),this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=0),this._isDragging&&this._draggedColumnId&&this._dropTargetIndex!==null&&this._dropIndicatorX!==null){let e=reorderColumnArray(this.columnOrder,this._draggedColumnId,this._dropTargetIndex);this.emitter.emit("reorder",{columnOrder:e});}this._isDragging=false,this._draggedColumnId=null,this._dropIndicatorX=null,this._dropTargetIndex=null,this.tableElement=null,this.emitter.emit("stateChange",{isDragging:false,dropIndicatorX:null});}onStateChange(e){return this.emitter.on("stateChange",e),()=>this.emitter.off("stateChange",e)}onReorder(e){return this.emitter.on("reorder",e),()=>this.emitter.off("reorder",e)}destroy(){this._isDragging&&(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true)),this.rafId&&cancelAnimationFrame(this.rafId),this.emitter.removeAllListeners();}};function Ve(R,e,t){let i=measureRange(R,e,t);return i?{top:i.top+R.scrollTop,left:i.left+R.scrollLeft,width:i.width,height:i.height}:null}var le=class{constructor(e,t=0){this.selSvg=null;this.clipSvg=null;this.selectionRange=null;this.copyRange=null;this.cutRange=null;this.rafHandle=0;this.layoutVersion=0;this.container=e,this.colOffset=t,injectGlobalStyles("ogrid-marching-ants-keyframes","@keyframes ogrid-marching-ants{to{stroke-dashoffset:-8}}");let i=getComputedStyle(e).position;(i==="static"||i==="")&&(e.style.position="relative");}update(e,t,i,n){let r=n!==void 0&&n!==this.layoutVersion;r&&n!==void 0&&(this.layoutVersion=n),!(!r&&rangesEqual(this.selectionRange,e)&&rangesEqual(this.copyRange,t)&&rangesEqual(this.cutRange,i))&&(this.selectionRange=e,this.copyRange=t,this.cutRange=i,this.rafHandle&&cancelAnimationFrame(this.rafHandle),this.rafHandle=requestAnimationFrame(()=>{this.rafHandle=0,this.render();}));}render(){let e=this.copyRange??this.cutRange,t=this.selectionRange?Ve(this.container,this.selectionRange,this.colOffset):null,i=this.selectionRange!=null&&e!=null&&rangesEqual(this.selectionRange,e),n=this.selectionRange!=null&&this.selectionRange.startRow===this.selectionRange.endRow&&this.selectionRange.startCol===this.selectionRange.endCol;if(t&&!i&&!n){this.selSvg||(this.selSvg=this.createSvg(4),this.container.appendChild(this.selSvg)),this.positionSvg(this.selSvg,t);let o=this.selSvg.querySelector("rect");o&&(o.setAttribute("width",String(Math.max(0,t.width-2))),o.setAttribute("height",String(Math.max(0,t.height-2))),o.setAttribute("stroke","var(--ogrid-selection, #217346)"),o.setAttribute("stroke-width","2"),o.removeAttribute("stroke-dasharray"),o.style.animation="");}else this.removeSvg("sel");let r=e?Ve(this.container,e,this.colOffset):null;if(r){this.clipSvg||(this.clipSvg=this.createSvg(5),this.container.appendChild(this.clipSvg)),this.positionSvg(this.clipSvg,r);let o=this.clipSvg.querySelector("rect");o&&(o.setAttribute("width",String(Math.max(0,r.width-2))),o.setAttribute("height",String(Math.max(0,r.height-2))),o.setAttribute("stroke","var(--ogrid-selection, #217346)"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-dasharray","4 4"),o.style.animation="ogrid-marching-ants 0.5s linear infinite");}else this.removeSvg("clip");}createSvg(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("aria-hidden","true"),t.style.position="absolute",t.style.pointerEvents="none",t.style.zIndex=String(e),t.style.overflow="visible";let i=document.createElementNS("http://www.w3.org/2000/svg","rect");return i.setAttribute("x","1"),i.setAttribute("y","1"),i.setAttribute("fill","none"),t.appendChild(i),t}positionSvg(e,t){e.style.top=`${t.top}px`,e.style.left=`${t.left}px`,e.style.width=`${t.width}px`,e.style.height=`${t.height}px`;}removeSvg(e){e==="sel"&&this.selSvg?(this.selSvg.remove(),this.selSvg=null):e==="clip"&&this.clipSvg&&(this.clipSvg.remove(),this.clipSvg=null);}destroy(){this.rafHandle&&cancelAnimationFrame(this.rafHandle),this.removeSvg("sel"),this.removeSvg("clip");}};var fe={position:"absolute",zIndex:"1000",boxSizing:"border-box",border:"2px solid var(--ogrid-selection, #217346)",background:"var(--ogrid-bg, #fff)",color:"var(--ogrid-fg, #242424)",outline:"none",fontFamily:"inherit",fontSize:"inherit"},se=class{constructor(e){this.editor=null;this.editingCell=null;this.editingCellElement=null;this.onCommit=null;this.onCancel=null;this.onAfterCommit=null;this.scrollCleanup=null;this.container=e;}startEdit(e,t,i,n,r,o,l,a,s){this.closeEditor(),this.editingCell={rowId:e,columnId:t},this.editingCellElement=r,this.onCommit=o,this.onCancel=l,this.onAfterCommit=a??null;let d=s!==void 0?s:getCellValue(i,n),c=r.getBoundingClientRect(),u=this.container.getBoundingClientRect(),m=this.createEditor(n,i,d,r);m.style.position="absolute",m.style.left=`${c.left-u.left+this.container.scrollLeft}px`,m.style.top=`${c.top-u.top+this.container.scrollTop}px`,m.style.width=`${c.width}px`,m.style.height=`${c.height}px`,this.editor=m,this.container.appendChild(m),m.focus();let v=m.querySelector('[role="listbox"]');if(v){let S=window.innerHeight-c.bottom,p=S<200&&c.top>S;v.style.position="fixed",v.style.left=`${c.left}px`,v.style.width=`${c.width}px`,v.style.maxHeight="200px",v.style.zIndex="9999",v.style.right="auto",p?(v.style.top="auto",v.style.bottom=`${window.innerHeight-c.top}px`):v.style.top=`${c.bottom}px`;let f=m.closest("[data-ogrid-scroll-container]")??m.closest('[style*="overflow"]'),h=()=>this.closeEditor(),I=requestAnimationFrame(()=>{f&&f.addEventListener("scroll",h,{passive:true}),window.addEventListener("scroll",h,{passive:true});});this.scrollCleanup=()=>{cancelAnimationFrame(I),f&&f.removeEventListener("scroll",h),window.removeEventListener("scroll",h);};}}getEditingCell(){return this.editingCell}closeEditor(){if(this.scrollCleanup?.(),this.scrollCleanup=null,this.editingCell&&this.container.isConnected){let{rowId:e,columnId:t}=this.editingCell,i=this.container.querySelector(`tr[data-row-id="${e}"]`);if(i){let n=i.querySelector(`td[data-column-id="${t}"]`);n&&(n.style.visibility="");}}this.editingCellElement&&(this.editingCellElement.isConnected&&(this.editingCellElement.style.visibility=""),this.editingCellElement=null),this.editor&&(this.editor.remove(),this.editor=null),this.editingCell=null,this.onCommit=null,this.onCancel=null,this.onAfterCommit=null;}createEditor(e,t,i,n){let r=e.cellEditor;if(typeof r=="function"){let o={value:i,onValueChange:l=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,l);},onCommit:()=>this.closeEditor(),onCancel:()=>{this.onCancel?.(),this.closeEditor();},item:t,column:e,cell:n,cellEditorParams:e.cellEditorParams};return r(o)}return r==="checkbox"||e.type==="boolean"?this.createCheckboxEditor(i):r==="select"?this.createSelectEditor(i,e):r==="richSelect"?this.createRichSelectEditor(i,e):r==="date"||e.type==="date"?this.createDateEditor(i):this.createTextEditor(i)}createInputEditor(e){let t=document.createElement("input");return t.type="text",t.value=e,Object.assign(t.style,fe),t.addEventListener("keydown",i=>{if(i.key==="Enter"){i.preventDefault(),i.stopPropagation(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,t.value);let n=this.onAfterCommit;this.closeEditor(),n?.();}else i.key==="Escape"?(i.preventDefault(),i.stopPropagation(),this.onCancel?.(),this.closeEditor()):(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(i.key)||(i.ctrlKey||i.metaKey)&&["c","x","v","a","z","y"].includes(i.key))&&i.stopPropagation();}),t.addEventListener("blur",()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,t.value),this.closeEditor();}),setTimeout(()=>t.select(),0),t}createTextEditor(e){return this.createInputEditor(e!=null?String(e):"")}createCheckboxEditor(e){let t=document.createElement("input");return t.type="checkbox",t.checked=!!e,Object.assign(t.style,fe),t.style.width="20px",t.style.height="20px",t.addEventListener("change",()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,t.checked),this.closeEditor();}),t.addEventListener("keydown",i=>{i.key==="Escape"?(i.preventDefault(),i.stopPropagation(),this.onCancel?.(),this.closeEditor()):["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(i.key)&&i.stopPropagation();}),t}createDateEditor(e){let t="";if(e!=null){let i=String(e);i.match(/^\d{4}-\d{2}-\d{2}/)&&(t=i.substring(0,10));}return this.createInputEditor(t)}createSelectEditor(e,t){let i=t.cellEditorParams?.values??[],n=t.cellEditorParams?.formatValue,r=g=>n?n(g):g!=null?String(g):"",o=document.createElement("div");Object.assign(o.style,fe),o.style.padding="6px 10px",o.style.display="flex",o.style.alignItems="center",o.tabIndex=0;let l=document.createElement("div");l.style.display="flex",l.style.alignItems="center",l.style.justifyContent="space-between",l.style.width="100%",l.style.cursor="pointer",l.style.fontSize="13px";let a=document.createElement("span");a.textContent=r(e),l.appendChild(a);let s=document.createElement("span");s.textContent="\u25BE",s.style.marginLeft="4px",s.style.fontSize="10px",s.style.opacity="0.5",l.appendChild(s),o.appendChild(l);let d=document.createElement("div");d.setAttribute("role","listbox"),d.style.position="absolute",d.style.top="100%",d.style.left="0",d.style.right="0",d.style.maxHeight="200px",d.style.overflowY="auto",d.style.backgroundColor="var(--ogrid-bg, #fff)",d.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",d.style.zIndex="1001",d.style.boxShadow="0 4px 16px rgba(0,0,0,0.2)",d.style.textAlign="left",o.appendChild(d);let c=Math.max(i.findIndex(g=>String(g)===String(e)),0),u=()=>{d.innerHTML="";for(let g=0;g<i.length;g++){let S=i[g],p=document.createElement("div");p.setAttribute("role","option"),p.setAttribute("aria-selected",String(g===c)),p.textContent=r(S),p.style.padding="6px 8px",p.style.cursor="pointer",p.style.color="var(--ogrid-fg, #242424)",g===c&&(p.style.background="var(--ogrid-bg-hover, #e8f0fe)"),p.addEventListener("mousedown",f=>{f.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,S),this.closeEditor();}),d.appendChild(p);}},m=(g,S)=>{let p=d.children[g],f=d.children[S];p&&(p.style.background="",p.setAttribute("aria-selected","false")),f&&(f.style.background="var(--ogrid-bg-hover, #e8f0fe)",f.setAttribute("aria-selected","true"));},v=()=>{d.children[c]?.scrollIntoView({block:"nearest"});};return u(),o.addEventListener("keydown",g=>{switch(g.stopPropagation(),g.key){case "ArrowDown":{g.preventDefault();let S=c;c=Math.min(c+1,i.length-1),m(S,c),v();break}case "ArrowUp":{g.preventDefault();let S=c;c=Math.max(c-1,0),m(S,c),v();break}case "Enter":if(g.preventDefault(),g.stopPropagation(),i.length>0&&c<i.length){this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i[c]);let S=this.onAfterCommit;this.closeEditor(),S?.();}break;case "Tab":g.preventDefault(),i.length>0&&c<i.length&&(this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i[c]),this.closeEditor());break;case "Escape":g.preventDefault(),g.stopPropagation(),this.onCancel?.(),this.closeEditor();break}}),o}createRichSelectEditor(e,t){let i=document.createElement("div");Object.assign(i.style,fe),i.style.padding="0";let n=document.createElement("input");n.type="text",n.value=e!=null?String(e):"",n.style.width="100%",n.style.border="none",n.style.outline="none",n.style.padding="4px",n.style.boxSizing="border-box",n.style.background="var(--ogrid-bg, #fff)",n.style.color="var(--ogrid-fg, rgba(0, 0, 0, 0.87))",i.appendChild(n);let r=document.createElement("div");r.style.position="absolute",r.style.top="100%",r.style.left="0",r.style.width="100%",r.style.maxHeight="200px",r.style.overflowY="auto",r.style.backgroundColor="var(--ogrid-bg, #fff)",r.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",r.style.zIndex="1001",r.style.textAlign="left",i.appendChild(r);let o=t.cellEditorParams?.values??[],l=t.cellEditorParams?.formatValue??(s=>String(s)),a=s=>{r.innerHTML="";let d=o.filter(c=>String(l(c)).toLowerCase().includes(s.toLowerCase()));for(let c of d){let u=document.createElement("div");u.textContent=String(l(c)),u.style.padding="4px 8px",u.style.cursor="pointer",u.addEventListener("mousedown",m=>{m.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,c),this.closeEditor();}),u.addEventListener("mouseenter",()=>{u.style.backgroundColor="var(--ogrid-hover-bg, rgba(0, 0, 0, 0.04))";},{passive:true}),u.addEventListener("mouseleave",()=>{u.style.backgroundColor="var(--ogrid-bg, #fff)";},{passive:true}),r.appendChild(u);}};return n.addEventListener("input",()=>{a(n.value);}),n.addEventListener("keydown",s=>{if(s.key==="Enter"){s.preventDefault(),s.stopPropagation(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value);let d=this.onAfterCommit;this.closeEditor(),d?.();}else s.key==="Escape"?(s.preventDefault(),s.stopPropagation(),this.onCancel?.(),this.closeEditor()):(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(s.key)||(s.ctrlKey||s.metaKey)&&["c","x","v","a","z","y"].includes(s.key))&&s.stopPropagation();}),n.addEventListener("blur",s=>{let d=s.relatedTarget;d&&this.editor?.contains(d)||(this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value),this.closeEditor());}),a(""),setTimeout(()=>n.select(),0),i}destroy(){this.closeEditor();}};var Dt={position:"fixed",backgroundColor:"var(--ogrid-bg, #fff)",border:"1px solid var(--ogrid-border, #e0e0e0)",boxShadow:"var(--ogrid-shadow, 0 4px 16px rgba(0, 0, 0, 0.12))",borderRadius:"6px",zIndex:"10000",minWidth:"180px",padding:"4px 0",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"14px",color:"var(--ogrid-fg, #242424)"},Lt={padding:"6px 12px",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},Mt={height:"1px",backgroundColor:"var(--ogrid-border, #e0e0e0)",margin:"4px 0"},ae=class{constructor(){this.menu=null;this.handlers=null;}show(e,t,i,n,r,o){this.close(),this.handlers=i,this.menu=document.createElement("div"),Object.assign(this.menu.style,Dt),this.menu.style.left=`${e}px`,this.menu.style.top=`${t}px`;for(let a of GRID_CONTEXT_MENU_ITEMS){if(a.dividerBefore){let u=document.createElement("div");Object.assign(u.style,Mt),this.menu.appendChild(u);}let s=document.createElement("div");Object.assign(s.style,Lt);let d=document.createElement("span");if(d.textContent=a.label,s.appendChild(d),a.shortcut){let u=document.createElement("span");u.textContent=formatShortcut(a.shortcut),u.style.marginLeft="20px",u.style.color="var(--ogrid-muted, #666)",u.style.fontSize="12px",s.appendChild(u);}a.id==="undo"&&!n||a.id==="redo"&&!r||a.disabledWhenNoSelection&&o==null?(s.style.color="var(--ogrid-fg-muted, rgba(0, 0, 0, 0.4))",s.style.opacity="0.5",s.style.cursor="not-allowed"):(s.addEventListener("mouseenter",()=>{s.style.backgroundColor="var(--ogrid-bg-hover, #f5f5f5)";},{passive:true}),s.addEventListener("mouseleave",()=>{s.style.backgroundColor="";},{passive:true}),s.addEventListener("click",()=>{this.handleItemClick(a.id);},{passive:true})),this.menu.appendChild(s);}document.body.appendChild(this.menu);let l=a=>{this.menu&&!this.menu.contains(a.target)&&(this.close(),document.removeEventListener("mousedown",l));};setTimeout(()=>{document.addEventListener("mousedown",l,{passive:true});},0);}close(){this.menu&&(this.menu.remove(),this.menu=null),this.handlers=null;}handleItemClick(e){if(this.handlers){switch(e){case "undo":this.handlers.onUndo();break;case "redo":this.handlers.onRedo();break;case "copy":this.handlers.onCopy();break;case "cut":this.handlers.onCut();break;case "paste":this.handlers.onPaste();break;case "selectAll":this.handlers.onSelectAll();break}this.close();}}destroy(){this.close();}};var de=class{initializeInteraction(e,t,i,n,r,o,l,a){let{editable:s}=e,d=o?1:0,c=[],u=new Q,m=new ne,v=new ae,g=new se(n),S=e.onCellValueChanged,p=new ie(S),f=new te({items:[],visibleCols:[],colOffset:d,editable:s,onCellValueChanged:p.getWrappedCallback()},()=>u.activeCell??null,()=>u.selectionRange??null),h=new oe({items:[],visibleCols:[],editable:s,onCellValueChanged:p.getWrappedCallback(),colOffset:d,beginBatch:()=>p.beginBatch(),endBatch:()=>p.endBatch()},()=>u.selectionRange??null,E=>{u.setSelectionRange(E),a.updateRendererInteractionState();},E=>{u.setActiveCell(E);}),I=new ee({items:[],visibleCols:[],colOffset:d,getRowId:t.getRowId,editable:s,onCellValueChanged:p.getWrappedCallback(),onCopy:()=>f.handleCopy(),onCut:()=>f.handleCut(),onPaste:async()=>{await f.handlePaste();},onUndo:()=>p.undo(),onRedo:()=>p.redo(),onContextMenu:(E,T)=>a.showContextMenu(E,T),onStartEdit:(E,T)=>a.startCellEdit(E,T),clearClipboardRanges:()=>f.clearClipboardRanges()},()=>u.activeCell??null,()=>u.selectionRange??null,E=>u.setActiveCell(E),E=>u.setSelectionRange(E));c.push(u.onSelectionChange(()=>{a.updateRendererInteractionState();})),c.push(f.onRangesChange(()=>{a.updateRendererInteractionState();})),c.push(m.onColumnWidthChange(()=>{a.updateRendererInteractionState();}));let w=new re;c.push(w.onStateChange(({isDragging:E,dropIndicatorX:T})=>{i.updateDropIndicator(T,E);})),c.push(w.onReorder(({columnOrder:E})=>{t.setColumnOrder(E);}));let b=i.getWrapperElement(),y=null;b&&(b.addEventListener("keydown",I.handleKeyDown),I.setWrapperRef(b),h.setWrapperRef(b),y=new le(b,d));let A=this.attachGlobalHandlers(u,m,r,i,a);return c.push(...A),{selectionState:u,keyboardNavState:I,clipboardState:f,undoRedoState:p,resizeState:m,fillHandleState:h,reorderState:w,marchingAnts:y,cellEditor:g,contextMenu:v,unsubscribes:c}}attachGlobalHandlers(e,t,i,n,r){let o=[],l=false,a=c=>{if(l&&t){let u=t.updateResize(c.clientX);u!==null&&t.resizingColumnId&&(i.setColumnOverride(t.resizingColumnId,u),r.updateRendererInteractionState());}if(e?.isDragging){let u=c.target;if(u.tagName==="TD"){let m=L(u);m&&m.rowIndex>=0&&m.colIndex>=0&&e.updateDrag(m.rowIndex,m.colIndex,()=>r.updateDragAttributes());}}},s=c=>{if(l&&t){let u=t.resizingColumnId;if(t.endResize(c.clientX),u){let m=t.getColumnWidth(u);m&&i.setColumnOverride(u,m);}l=false,document.body.style.cursor="",r.updateRendererInteractionState();}e?.isDragging&&(e.endDrag(),r.clearCachedDragCells());},d=(c,u,m)=>{l=true,document.body.style.cursor="col-resize",t.startResize(c,u,m);};return document.addEventListener("pointermove",a,{passive:true}),document.addEventListener("pointerup",s,{passive:true}),o.push(()=>{document.removeEventListener("pointermove",a),document.removeEventListener("pointerup",s);}),n.setInteractionState({activeCell:null,selectionRange:null,copyRange:null,cutRange:null,editingCell:null,columnWidths:{},onResizeStart:d}),o}};var ce=class{constructor(e){this.layoutVersion=0;this.cachedDragCells=null;this.ctx=e;}incrementLayoutVersion(){this.layoutVersion++;}clearCachedDragCells(){this.cachedDragCells=null;}getLayoutVersion(){return this.layoutVersion}updateRendererInteractionState(){let{selectionState:e,clipboardState:t,resizeState:i,state:n,layoutState:r,pinningState:o,rowSelectionState:l,cellEditor:a,renderer:s,reorderState:d,marchingAnts:c,fillHandleState:u,options:m}=this.ctx;if(!e||!t||!i)return;let{items:v}=n.getProcessedItems(),g=n.visibleColumnDefs,S=r.getAllColumnWidths(),p=o?.computeLeftOffsets(g,S,120,!!l,CHECKBOX_COLUMN_WIDTH,!!m.showRowNumbers)??{},f=o?.computeRightOffsets(g,S,120)??{};s.setInteractionState({activeCell:e.activeCell,selectionRange:e.selectionRange,copyRange:t.copyRange,cutRange:t.cutRange,editingCell:a?.getEditingCell()??null,columnWidths:S,onCellClick:h=>this.ctx.handleCellClick(h.rowIndex,h.colIndex),onCellMouseDown:h=>{h.event&&this.ctx.handleCellMouseDown(h.rowIndex,h.colIndex,h.event);},onCellDoubleClick:h=>{h.rowId!=null&&h.columnId&&this.ctx.startCellEdit(h.rowId,h.columnId);},onCellContextMenu:h=>{h.event&&this.ctx.handleCellContextMenu(h.rowIndex,h.colIndex,h.event);},onResizeStart:s.getOnResizeStart(),onResizeDoubleClick:h=>{let w=g.find(A=>A.columnId===h)?.minWidth??DEFAULT_MIN_COLUMN_WIDTH,b=s.getTableElement()?.parentElement??void 0,y=measureColumnContentWidth(h,w,b);i.setColumnWidth(h,y);},onBooleanToggle:m.editable!==false?(h,I,w)=>this.ctx.toggleBooleanCell(h,I,w):void 0,onFillHandleMouseDown:m.editable!==false?h=>u?.startFillDrag(h):void 0,rowSelectionMode:l?.rowSelection??"none",selectedRowIds:l?.selectedRowIds,onRowCheckboxChange:(h,I,w,b)=>{l?.handleRowCheckboxChange(h,I,w,b,v);},onSelectAll:h=>{l?.handleSelectAll(h,v);},allSelected:l?.isAllSelected(v),someSelected:l?.isSomeSelected(v),showRowNumbers:m.showRowNumbers||m.cellReferences,showColumnLetters:!!m.cellReferences,showNameBox:!!m.cellReferences,pinnedColumns:o?.pinnedColumns,leftOffsets:p,rightOffsets:f,onColumnReorderStart:d?(h,I)=>{let w=s.getTableElement();w&&d?.startDrag(h,I,g,n.columnOrder,o?.pinnedColumns,w);}:void 0}),s.update(),c?.update(e.selectionRange,t.copyRange,t.cutRange,this.layoutVersion);}updateDragAttributes(){let e=this.ctx.renderer.getWrapperElement(),t=this.ctx.selectionState;if(!e||!t)return;let i=t.getDragRange();if(!i)return;let n=normalizeSelectionRange(i),r=t.dragAnchor;this.cachedDragCells||(this.cachedDragCells=e.querySelectorAll("td[data-row-index][data-col-index]"));let o=this.cachedDragCells;for(let l=0;l<o.length;l++){let s=o[l],d=L(s);if(!d)continue;let c=d.rowIndex,u=d.colIndex;isInSelectionRange(n,c,u)?(s.setAttribute("data-drag-range","true"),r&&c===r.rowIndex&&u===r.columnIndex?s.setAttribute("data-drag-anchor",""):s.removeAttribute("data-drag-anchor"),s.classList.add("ogrid-drag-target")):(s.removeAttribute("data-drag-range"),s.removeAttribute("data-drag-anchor"),s.classList.remove("ogrid-drag-target"));}}renderAll(){this.layoutVersion++;let{state:e,options:t,headerFilterState:i,rowSelectionState:n,keyboardNavState:r,clipboardState:o,undoRedoState:l,fillHandleState:a,virtualScrollState:s,pagination:d,statusBar:c,columnChooser:u,renderer:m}=this.ctx,v=n?1:0;i.setFilters(e.filters),i.setFilterOptions(e.filterOptions);let{items:g,totalCount:S}=e.getProcessedItems();if(r&&o){let p=e.visibleColumnDefs;r.updateParams({items:g,visibleCols:p,colOffset:v,getRowId:e.getRowId,editable:t.editable,onCellValueChanged:l?.getWrappedCallback(),onCopy:()=>o?.handleCopy(),onCut:()=>o?.handleCut(),onPaste:async()=>{await o?.handlePaste();},onUndo:()=>l?.undo(),onRedo:()=>l?.redo(),onContextMenu:(f,h)=>this.ctx.showContextMenu(f,h),onStartEdit:(f,h)=>this.ctx.startCellEdit(f,h),clearClipboardRanges:()=>o?.clearClipboardRanges(),onKeyDown:t.onKeyDown,onFillDown:a?()=>a.fillDown():void 0}),o.updateParams({items:g,visibleCols:p,colOffset:v,editable:t.editable,onCellValueChanged:l?.getWrappedCallback()}),a?.updateParams({items:g,visibleCols:p,editable:t.editable,onCellValueChanged:l?.getWrappedCallback(),colOffset:v,beginBatch:()=>l?.beginBatch(),endBatch:()=>l?.endBatch()}),this.updateRendererInteractionState();}else m.update();s?.setTotalRows(S),d.render(S,t.pageSizeOptions),c.render({totalCount:S}),u.render(),this.renderSideBar(),this.renderLoadingOverlay();}renderHeaderFilterPopover(){let{headerFilterState:e,headerFilterComponent:t,filterConfigs:i}=this.ctx,n=e.openColumnId,r=this.ctx.tableContainer.querySelectorAll(".ogrid-filter-icon[aria-haspopup]");for(let a of r){let s=a.closest("th[data-column-id]")?.getAttribute("data-column-id");a.setAttribute("aria-expanded",s===n?"true":"false");}if(!n){t.cleanup();return}let o=i.get(n);if(!o)return;t.render(o);let l=document.querySelector(".ogrid-header-filter-popover");e.setPopoverEl(l);}renderSideBar(){let{sideBarComponent:e,sideBarState:t,state:i}=this.ctx;if(!e||!t)return;let n=i.columns.map(o=>({columnId:o.columnId,name:o.name,required:o.required===true})),r=i.columns.filter(o=>o.filterable&&typeof o.filterable=="object"&&o.filterable.type).map(o=>({columnId:o.columnId,name:o.name,filterField:o.filterable.filterField??o.columnId,filterType:o.filterable.type}));e.setConfig({columns:n,visibleColumns:i.visibleColumns,onVisibilityChange:(o,l)=>{let a=new Set(i.visibleColumns);l?a.add(o):a.delete(o),i.setVisibleColumns(a);},onSetVisibleColumns:o=>i.setVisibleColumns(o),filterableColumns:r,filters:i.filters,onFilterChange:(o,l)=>i.setFilter(o,l),filterOptions:i.filterOptions}),e.render();}renderLoadingOverlay(){let{state:e,tableContainer:t}=this.ctx;if(e.isLoading){let{items:i}=e.getProcessedItems();t.style.minHeight=!i||i.length===0?"200px":"";let n=this.ctx.loadingOverlay;if(!n){n=document.createElement("div"),n.className="ogrid-loading-overlay",n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.right="0",n.style.bottom="0",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",n.style.background="var(--ogrid-loading-overlay, rgba(255, 255, 255, 0.7))",n.style.zIndex="100";let r=document.createElement("div");r.className="ogrid-loading-spinner",r.textContent="Loading...",n.appendChild(r),this.ctx.setLoadingOverlay(n);}t.contains(n)||t.appendChild(n);}else {t.style.minHeight="";let i=this.ctx.loadingOverlay;i&&t.contains(i)&&i.remove();}}};var ue=class{constructor(e){this.emitter=new x;this.engine=null;if(this.options=e,e.formulas&&(this.engine=new FormulaEngine({customFunctions:e.formulaFunctions,namedRanges:e.namedRanges}),e.sheets))for(let[t,i]of Object.entries(e.sheets))this.engine.registerSheet(t,i);}initialize(e){if(!this.engine||!this.options.initialFormulas?.length)return;let t=this.engine.loadFormulas(this.options.initialFormulas,e);t.updatedCells.length>0&&this.emitRecalc(t);}setFormula(e,t,i,n){if(!this.engine)return;let r=this.engine.setFormula(e,t,i,n);return r.updatedCells.length>0&&this.emitRecalc(r),r}onCellChanged(e,t,i){if(!this.engine)return;let n=this.engine.onCellChanged(e,t,i);return n.updatedCells.length>0&&this.emitRecalc(n),n}getValue(e,t){return this.engine?.getValue(e,t)}hasFormula(e,t){return this.engine?.hasFormula(e,t)??false}getFormula(e,t){return this.engine?.getFormula(e,t)}isEnabled(){return this.engine!==null}defineNamedRange(e,t){this.engine?.defineNamedRange(e,t);}removeNamedRange(e){this.engine?.removeNamedRange(e);}registerSheet(e,t){this.engine?.registerSheet(e,t);}unregisterSheet(e){this.engine?.unregisterSheet(e);}getPrecedents(e,t){return this.engine?.getPrecedents(e,t)??[]}getDependents(e,t){return this.engine?.getDependents(e,t)??[]}getAuditTrail(e,t){return this.engine?.getAuditTrail(e,t)??null}onFormulaRecalc(e){return this.emitter.on("formulaRecalc",e),()=>this.emitter.off("formulaRecalc",e)}destroy(){this.engine=null,this.emitter.removeAllListeners();}emitRecalc(e){this.options.onFormulaRecalc?.(e),this.emitter.emit("formulaRecalc",e);}};var he=class{constructor(e){this.el=null;this.nameBoxEl=null;this.inputEl=null;this.isEditing=false;this.handleKeyDown=e=>{handleFormulaBarKeyDown(e.key,()=>e.preventDefault(),this.callbacks.onCommit,this.callbacks.onCancel);};this.handleInput=()=>{this.inputEl&&this.callbacks.onInputChange(this.inputEl.value);};this.handleClick=()=>{this.isEditing||this.callbacks.onStartEditing();};this.callbacks=e;}mount(e){if(this.el)return;this.el=document.createElement("div"),this.el.className="ogrid-formula-bar",this.el.setAttribute("role","toolbar"),this.el.setAttribute("aria-label","Formula bar"),this.el.style.cssText=FORMULA_BAR_CSS.bar,this.nameBoxEl=document.createElement("div"),this.nameBoxEl.className="ogrid-formula-bar-name",this.nameBoxEl.setAttribute("aria-label","Active cell reference"),this.nameBoxEl.style.cssText=FORMULA_BAR_CSS.nameBox,this.nameBoxEl.textContent="\u2014",this.el.appendChild(this.nameBoxEl);let t=document.createElement("div");t.className="ogrid-formula-bar-fx",t.setAttribute("aria-hidden","true"),t.style.cssText=FORMULA_BAR_CSS.fxLabel,t.textContent="fx",this.el.appendChild(t),this.inputEl=document.createElement("input"),this.inputEl.type="text",this.inputEl.className="ogrid-formula-bar-input",this.inputEl.setAttribute("aria-label","Formula input"),this.inputEl.spellcheck=false,this.inputEl.autocomplete="off",this.inputEl.readOnly=true,this.inputEl.style.cssText=FORMULA_BAR_CSS.input,this.inputEl.addEventListener("keydown",this.handleKeyDown),this.inputEl.addEventListener("input",this.handleInput),this.inputEl.addEventListener("click",this.handleClick),this.inputEl.addEventListener("dblclick",this.handleClick),this.el.appendChild(this.inputEl),e.appendChild(this.el);}update(e,t){this.nameBoxEl&&(this.nameBoxEl.textContent=e??"\u2014"),this.inputEl&&(this.inputEl.value=t);}setEditing(e){this.isEditing=e,this.inputEl&&(this.inputEl.readOnly=!e,e&&this.inputEl.focus());}destroy(){this.inputEl&&(this.inputEl.removeEventListener("keydown",this.handleKeyDown),this.inputEl.removeEventListener("input",this.handleInput),this.inputEl.removeEventListener("click",this.handleClick),this.inputEl.removeEventListener("dblclick",this.handleClick)),this.el?.remove(),this.el=null,this.nameBoxEl=null,this.inputEl=null;}};var Ut=`
|
|
1
|
+
import {flattenColumns,resolveResponsiveConfig,deriveFilterOptionsFromData,validateColumns,validateRowIds,applyResponsiveHiding,processClientSideData,processClientSideDataAsync,mergeFilter,exportToCsv,getCellValue,ROW_NUMBER_COLUMN_WIDTH,ROW_NUMBER_COLUMN_ID,CHECKBOX_COLUMN_WIDTH,indexToColumnLetter,buildHeaderRows,partitionColumnsForVirtualization,isInSelectionRange,getPaginationViewModel,getStatusBarParts,DEFAULT_MIN_COLUMN_WIDTH,CELL_PADDING,applyRangeRowSelection,computeRowSelectionState,validateVirtualScrollConfig,computeTotalHeight,computeVisibleColumnRange,getScrollTopForRow,computeVisibleRange,rangesEqual,applyCellDeletion,computeTabNavigation,computeArrowNavigation,normalizeSelectionRange,formatSelectionAsTsv,parseTsvClipboard,applyPastedValues,applyCutClear,UndoRedoStack,ROW_NUMBER_COLUMN_MIN_WIDTH,applyFillValues,getPinStateForColumn,calculateDropTarget,reorderColumnArray,injectGlobalStyles,GRID_CONTEXT_MENU_ITEMS,formatShortcut,measureColumnContentWidth,formatCellReference,measureRange}from'@alaarab/ogrid-core';export{AUTOSIZE_EXTRA_PX,AUTOSIZE_MAX_PX,CELL_PADDING,CHECKBOX_COLUMN_WIDTH,COLUMN_HEADER_MENU_ITEMS,CellDescriptorCache,DEFAULT_DEBOUNCE_MS,DEFAULT_MIN_COLUMN_WIDTH,GRID_BORDER_RADIUS,GRID_CONTEXT_MENU_ITEMS,MAX_PAGE_BUTTONS,PAGE_SIZE_OPTIONS,PEOPLE_SEARCH_DEBOUNCE_MS,RESPONSIVE_BREAKPOINTS,ROW_NUMBER_COLUMN_ID,ROW_NUMBER_COLUMN_MIN_WIDTH,ROW_NUMBER_COLUMN_WIDTH,SIDEBAR_TRANSITION_MS,UndoRedoStack,Z_INDEX,applyCellDeletion,applyCutClear,applyFillValues,applyPastedValues,applyRangeRowSelection,applyResponsiveHiding,areGridRowPropsEqual,booleanParser,buildCellIndex,buildCsvHeader,buildCsvRows,buildHeaderRows,buildInlineEditorProps,buildPopoverEditorProps,calculateDropTarget,clampSelectionToBounds,columnLetterToIndex,computeAggregations,computeArrowNavigation,computeAutoScrollSpeed,computeNextSortState,computeRowSelectionState,computeTabNavigation,computeTotalHeight,computeVisibleColumnRange,computeVisibleRange,createGridDataAccessor,createSortFilterWorker,currencyParser,dateParser,debounce,deriveFilterOptionsFromData,emailParser,escapeCsvValue,exportToCsv,extractValueMatrix,findCtrlArrowTarget,flattenColumns,formatCellReference,formatCellValueForTsv,formatSelectionAsTsv,formatShortcut,getCellRenderDescriptor,getCellValue,getColumnHeaderMenuItems,getContextMenuHandlers,getDataGridStatusBarConfig,getFilterField,getHeaderFilterConfig,getMultiSelectFilterFields,getPaginationViewModel,getPinStateForColumn,getResponsiveHiddenColumns,getScrollTopForRow,getStatusBarParts,indexToColumnLetter,injectGlobalStyles,isColumnEditable,isFilterConfig,isInSelectionRange,isRowInRange,measureColumnContentWidth,measureRange,mergeFilter,normalizeSelectionRange,numberParser,parseTsvClipboard,parseValue,partitionColumnsForVirtualization,processClientSideData,processClientSideDataAsync,rangesEqual,reorderColumnArray,resolveCellDisplayContent,resolveCellStyle,resolveResponsiveConfig,terminateSortFilterWorker,toUserLike,triggerCsvDownload,validateColumns,validateRowIds,validateVirtualScrollConfig}from'@alaarab/ogrid-core';import {FormulaEngine,handleFormulaBarKeyDown,FORMULA_BAR_CSS}from'@alaarab/ogrid-core/formula';export{CIRC_ERROR,DIV_ZERO_ERROR,DependencyGraph,FORMULA_BAR_CSS,FORMULA_BAR_STYLES,FORMULA_REF_COLORS,FormulaEngine,FormulaError,FormulaEvaluator,GENERAL_ERROR,NAME_ERROR,NA_ERROR,REF_ERROR,VALUE_ERROR,adjustFormulaReferences,canInsertReference,createBuiltInFunctions,deriveFormulaBarText,extractFormulaReferences,flattenArgs,formatAddress,formulaToString,fromCellKey,handleFormulaBarKeyDown,insertReferenceAtCursor,isFormulaError,parse,parseCellRef,parseRange,processFormulaBarCommit,toBoolean,toCellKey,toNumber,tokenize}from'@alaarab/ogrid-core/formula';function L(R){let e=R.getAttribute("data-row-index"),t=R.getAttribute("data-col-index");if(e==null||t==null)return null;let i=parseInt(e,10),n=parseInt(t,10);return Number.isNaN(i)||Number.isNaN(n)?null:{rowIndex:i,colIndex:n}}var x=class{constructor(){this.handlers=new Map;}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e)?.add(t);}off(e,t){this.handlers.get(e)?.delete(t);}emit(e,...t){let i=t[0];this.handlers.get(e)?.forEach(n=>{n(i);});}removeAllListeners(e){e?this.handlers.delete(e):this.handlers.clear();}};var N=class{constructor(e){this.emitter=new x;this._data=[];this._filters={};this._isLoading=false;this._serverItems=[];this._serverTotalCount=0;this._fetchId=0;this._abortController=null;this._firstDataRendered=false;this._formulaEngine=null;this._filterOptions={};this._columnOrder=[];this._responsiveColumns=null;this._containerWidth=0;this._visibleColsCache=null;this._visibleColsDirty=true;this._allColumns=e.columns,this._columns=flattenColumns(e.columns),this._getRowId=e.getRowId,this._data=e.data??[],this._dataSource=e.dataSource,this._page=e.page??1,this._pageSize=e.pageSize??20,this._sort=e.sort,this._filters=e.filters??{},this._visibleColumns=e.visibleColumns??new Set(this._columns.map(t=>t.columnId)),this._columnOrder=this._columns.map(t=>t.columnId),this._onError=e.onError,this._onFirstDataRendered=e.onFirstDataRendered,this._rowHeight=e.rowHeight,this._ariaLabel=e.ariaLabel,this._stickyHeader=e.stickyHeader??true,this._fullScreen=e.fullScreen??false,this._workerSort=e.workerSort??false,this._responsiveColumns=resolveResponsiveConfig(e.responsiveColumns)??null,this._dataSource||(this._filterOptions=deriveFilterOptionsFromData(this._data,this._columns)),validateColumns(this._columns),!this._dataSource&&this._data.length>0&&(validateRowIds(this._data,this._getRowId),this._firstDataRendered=true),this._dataSource&&(this._isLoading=true,this.fetchServerData());}get data(){return this._data}get page(){return this._page}get pageSize(){return this._pageSize}get sort(){return this._sort}get filters(){return this._filters}get visibleColumns(){return this._visibleColumns}get isLoading(){return this._isLoading}get columns(){return this._columns}get allColumns(){return this._allColumns}get getRowId(){return this._getRowId}get isServerSide(){return this._dataSource!=null}get stickyHeader(){return this._stickyHeader}get fullScreen(){return this._fullScreen}get filterOptions(){return this._filterOptions}get columnOrder(){return this._columnOrder}get rowHeight(){return this._rowHeight}get ariaLabel(){return this._ariaLabel}get responsiveColumns(){return this._responsiveColumns}get visibleColumnDefs(){if(!this._visibleColsDirty&&this._visibleColsCache)return this._visibleColsCache;let e=this._columns.filter(i=>this._visibleColumns.has(i.columnId)),t=applyResponsiveHiding(e,this._containerWidth,this._responsiveColumns??void 0);if(this._columnOrder.length===0)this._visibleColsCache=t;else {let i=new Map(this._columnOrder.map((n,r)=>[n,r]));this._visibleColsCache=[...t].sort((n,r)=>{let o=i.get(n.columnId)??1/0,l=i.get(r.columnId)??1/0;return o-l});}return this._visibleColsDirty=false,this._visibleColsCache}getProcessedItems(){if(this.isServerSide)return {items:this._serverItems,totalCount:this._serverTotalCount};let e=processClientSideData(this._data,this._columns,this._filters,this._sort?.field,this._sort?.direction),t=e.length,i=(this._page-1)*this._pageSize,n=i+this._pageSize;return {items:e.slice(i,n),totalCount:t}}get useWorkerSort(){return this._workerSort===true||this._workerSort==="auto"&&this._data.length>5e3}async getProcessedItemsAsync(){if(this.isServerSide||!this.useWorkerSort)return this.getProcessedItems();let e=await processClientSideDataAsync(this._data,this._columns,this._filters,this._sort?.field,this._sort?.direction),t=e.length,i=(this._page-1)*this._pageSize,n=i+this._pageSize;return {items:e.slice(i,n),totalCount:t}}fetchServerData(){if(!this._dataSource)return;this._abortController&&this._abortController.abort();let e=++this._fetchId;this._abortController=new AbortController;let t=this._abortController;this._isLoading=true,this.emitter.emit("stateChange",{type:"loading"}),this._dataSource.fetchPage({page:this._page,pageSize:this._pageSize,sort:this._sort?{field:this._sort.field,direction:this._sort.direction}:void 0,filters:this._filters}).then(i=>{e!==this._fetchId||t.signal.aborted||(this._serverItems=i.items,this._serverTotalCount=i.totalCount,this._isLoading=false,!this._firstDataRendered&&i.items.length>0&&(this._firstDataRendered=true,validateRowIds(i.items,this._getRowId),this._onFirstDataRendered?.()),this.emitter.emit("stateChange",{type:"data"}));}).catch(i=>{e!==this._fetchId||t.signal.aborted||(this._onError?.(i),this._serverItems=[],this._serverTotalCount=0,this._isLoading=false,this.emitter.emit("stateChange",{type:"data"}));});}setData(e){this._data=e,this.isServerSide||(this._filterOptions=deriveFilterOptionsFromData(e,this._columns)),this.emitter.emit("stateChange",{type:"data"});}setPage(e){this._page=e,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"page"});}setPageSize(e){this._pageSize=e,this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"page"});}setSort(e){this._sort=e,this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"sort"});}toggleSort(e){this._sort?.field===e?this._sort=this._sort.direction==="asc"?{field:e,direction:"desc"}:void 0:this._sort={field:e,direction:"asc"},this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"sort"});}setFilter(e,t){this._filters=mergeFilter(this._filters,e,t),this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});}clearFilters(){this._filters={},this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});}setVisibleColumns(e){this._visibleColumns=e,this._visibleColsDirty=true,this.emitter.emit("stateChange",{type:"columns"});}setColumnOrder(e){this._columnOrder=e,this._visibleColsDirty=true,this.emitter.emit("stateChange",{type:"columns"});}setContainerWidth(e){this._containerWidth!==e&&(this._containerWidth=e,this._responsiveColumns&&(this._visibleColsDirty=true,this.emitter.emit("stateChange",{type:"columns"})));}setLoading(e){this._isLoading=e,this.emitter.emit("stateChange",{type:"loading"});}refreshData(){this.isServerSide&&this.fetchServerData();}onStateChange(e){return this.emitter.on("stateChange",e),()=>this.emitter.off("stateChange",e)}getApi(){return {setRowData:e=>{this.isServerSide||this.setData(e);},setLoading:e=>this.setLoading(e),getColumnState:()=>({visibleColumns:Array.from(this._visibleColumns),sort:this._sort,filters:Object.keys(this._filters).length>0?this._filters:void 0}),applyColumnState:e=>{e.visibleColumns&&(this._visibleColumns=new Set(e.visibleColumns)),e.sort!==void 0&&(this._sort=e.sort),e.filters!==void 0&&(this._filters=e.filters??{}),this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"columns"});},setFilterModel:e=>{this._filters=e,this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});},getSelectedRows:()=>[],setSelectedRows:()=>{},selectAll:()=>{},deselectAll:()=>{},clearFilters:()=>this.clearFilters(),clearSort:()=>this.setSort(void 0),resetGridState:()=>{this.clearFilters(),this.setSort(void 0);},getDisplayedRows:()=>this.getProcessedItems().items,refreshData:()=>this.refreshData(),scrollToRow:()=>{},getColumnOrder:()=>[...this._columnOrder],setColumnOrder:e=>this.setColumnOrder(e),exportToCsv:(e,t)=>{let{items:i}=this.getProcessedItems(),n=this.visibleColumnDefs.map(o=>({columnId:o.columnId,name:o.name})),r=this._formulaEngine?.isEnabled()?{getFormula:this._formulaEngine.getFormula.bind(this._formulaEngine),hasFormula:this._formulaEngine.hasFormula.bind(this._formulaEngine),columnIdToIndex:new Map(this.visibleColumnDefs.map((o,l)=>[o.columnId,l])),exportMode:t?.exportMode??"values"}:void 0;exportToCsv(i,n,(o,l)=>{let a=this._columns.find(d=>d.columnId===l);if(!a)return "";let s=getCellValue(o,a);return a.valueFormatter?a.valueFormatter(s,o):s!=null?String(s):""},e,r);}}}setFormulaEngine(e){this._formulaEngine=e;}destroy(){this._abortController&&(this._abortController.abort(),this._abortController=null),this.emitter.removeAllListeners();}};function P(R){return {minR:Math.min(R.startRow,R.endRow),maxR:Math.max(R.startRow,R.endRow),minC:Math.min(R.startCol,R.endCol),maxC:Math.max(R.startCol,R.endCol)}}function M(R,e,t){return e>=R.minR&&e<=R.maxR&&t>=R.minC&&t<=R.maxC}var V=class{constructor(e,t){this.table=null;this.thead=null;this.tbody=null;this.interactionState=null;this.wrapperEl=null;this.headerFilterState=null;this.filterConfigs=new Map;this.onFilterIconClick=null;this.dropIndicator=null;this.virtualScrollState=null;this._tbodyClickHandler=null;this._tbodyPointerdownHandler=null;this._tbodyDblclickHandler=null;this._tbodyContextmenuHandler=null;this._theadClickHandler=null;this._theadPointerdownHandler=null;this._theadDblclickHandler=null;this.lastActiveCell=null;this.lastSelectionRange=null;this.lastCopyRange=null;this.lastCutRange=null;this.lastEditingCell=null;this.lastColumnWidths={};this.lastHeaderSignature="";this.lastRenderedItems=null;this.formulaEngine=null;this.container=e,this.state=t;}setFormulaEngine(e){this.formulaEngine=e;}setVirtualScrollState(e){this.virtualScrollState=e;}setHeaderFilterState(e,t){this.headerFilterState=e,this.filterConfigs=t;}setOnFilterIconClick(e){this.onFilterIconClick=e;}setInteractionState(e){this.interactionState=e;}getCellFromEvent(e){let i=e.target.closest("td[data-row-index]");if(!i)return null;let n=L(i);return n?{el:i,rowIndex:n.rowIndex,colIndex:n.colIndex}:null}attachBodyDelegation(){this.tbody&&(this._tbodyClickHandler=e=>{let t=this.getCellFromEvent(e);t&&this.interactionState?.onCellClick?.({rowIndex:t.rowIndex,colIndex:t.colIndex,event:e});},this._tbodyPointerdownHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-fill-handle")||t.getAttribute("data-fill-handle")==="true"){this.interactionState?.onFillHandleMouseDown?.(e);return}let i=this.getCellFromEvent(e);i&&this.interactionState?.onCellMouseDown?.({rowIndex:i.rowIndex,colIndex:i.colIndex,event:e});},this._tbodyDblclickHandler=e=>{let t=this.getCellFromEvent(e);if(!t)return;let i=t.el.getAttribute("data-column-id")??"",{items:n}=this.state.getProcessedItems(),r=n[t.rowIndex];if(!r)return;let o=this.state.getRowId(r);this.interactionState?.onCellDoubleClick?.({rowIndex:t.rowIndex,colIndex:t.colIndex,rowId:o,columnId:i});},this._tbodyContextmenuHandler=e=>{let t=this.getCellFromEvent(e);t&&this.interactionState?.onCellContextMenu?.({rowIndex:t.rowIndex,colIndex:t.colIndex,event:e});},this.tbody.addEventListener("click",this._tbodyClickHandler,{passive:true}),this.tbody.addEventListener("pointerdown",this._tbodyPointerdownHandler),this.tbody.addEventListener("dblclick",this._tbodyDblclickHandler,{passive:true}),this.tbody.addEventListener("contextmenu",this._tbodyContextmenuHandler));}detachBodyDelegation(){this.tbody&&(this._tbodyClickHandler&&this.tbody.removeEventListener("click",this._tbodyClickHandler),this._tbodyPointerdownHandler&&this.tbody.removeEventListener("pointerdown",this._tbodyPointerdownHandler),this._tbodyDblclickHandler&&this.tbody.removeEventListener("dblclick",this._tbodyDblclickHandler),this._tbodyContextmenuHandler&&this.tbody.removeEventListener("contextmenu",this._tbodyContextmenuHandler),this._tbodyClickHandler=null,this._tbodyPointerdownHandler=null,this._tbodyDblclickHandler=null,this._tbodyContextmenuHandler=null);}attachHeaderDelegation(){this.thead&&(this._theadClickHandler=null,this._theadPointerdownHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-resize-handle")){e.stopPropagation();let i=t.getAttribute("data-column-id"),n=t.closest("th[data-column-id]"),r=i??n?.getAttribute("data-column-id");if(r){let l=t.closest("th")?.getBoundingClientRect();this.interactionState?.onResizeStart?.(r,e.clientX,l?.width??ROW_NUMBER_COLUMN_WIDTH);}return}if(!t.classList.contains("ogrid-filter-icon")&&this.interactionState?.onColumnReorderStart){let i=t.closest("th[data-column-id]");if(!i)return;let n=i.getAttribute("data-column-id");n&&this.interactionState.onColumnReorderStart(n,e);}},this._theadDblclickHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-resize-handle")){e.stopPropagation();let i=t.getAttribute("data-column-id"),n=t.closest("th[data-column-id]"),r=i??n?.getAttribute("data-column-id");r&&this.interactionState?.onResizeDoubleClick?.(r);}},this._theadClickHandler&&this.thead.addEventListener("click",this._theadClickHandler),this.thead.addEventListener("pointerdown",this._theadPointerdownHandler),this.thead.addEventListener("dblclick",this._theadDblclickHandler));}detachHeaderDelegation(){this.thead&&(this._theadClickHandler&&this.thead.removeEventListener("click",this._theadClickHandler),this._theadPointerdownHandler&&this.thead.removeEventListener("pointerdown",this._theadPointerdownHandler),this._theadDblclickHandler&&this.thead.removeEventListener("dblclick",this._theadDblclickHandler),this._theadClickHandler=null,this._theadPointerdownHandler=null,this._theadDblclickHandler=null);}getWrapperElement(){return this.wrapperEl}render(){this.container.innerHTML="";let e=document.createElement("div");e.className="ogrid-wrapper",e.setAttribute("role","region"),e.setAttribute("data-ogrid-scroll-container",""),e.setAttribute("tabindex","0"),e.style.position="relative",this.state.rowHeight&&e.style.setProperty("--ogrid-row-height",`${this.state.rowHeight}px`);let t=this.state.ariaLabel??"Data grid";e.setAttribute("aria-label",t),this.wrapperEl=e,this.table=document.createElement("table"),this.table.className="ogrid-table",this.table.setAttribute("role","grid"),this.virtualScrollState&&this.table.setAttribute("data-virtual-scroll",""),this.thead=document.createElement("thead"),this.state.stickyHeader&&this.thead.classList.add("ogrid-sticky-header"),this.renderHeader(),this.attachHeaderDelegation(),this.table.appendChild(this.thead),this.tbody=document.createElement("tbody"),this.renderBody(),this.attachBodyDelegation(),this.table.appendChild(this.tbody),e.appendChild(this.table),this.dropIndicator=document.createElement("div"),this.dropIndicator.className="ogrid-drop-indicator",this.dropIndicator.style.display="none",e.appendChild(this.dropIndicator),this.container.appendChild(e),this.snapshotState();}computeHeaderSignature(){let e=this.state.visibleColumnDefs,t=this.interactionState,i=[];for(let r of e)i.push(r.columnId),i.push(r.name),i.push(t?.columnWidths[r.columnId]?.toString()??"");let n=this.state.sort;n&&i.push(`sort:${n.field}:${n.direction}`),i.push(`sel:${t?.rowSelectionMode??""}`),i.push(`allSel:${t?.allSelected??""}`),i.push(`someSel:${t?.someSelected??""}`),i.push(`rn:${t?.showRowNumbers??""}`),t?.showRowNumbers&&i.push(`rnw:${t?.columnWidths[ROW_NUMBER_COLUMN_ID]??""}`),i.push(`cl:${t?.showColumnLetters??""}`);for(let[r,o]of this.filterConfigs)this.headerFilterState?.hasActiveFilter(o)&&i.push(`flt:${r}`);return i.join("|")}snapshotState(){let e=this.interactionState;this.lastActiveCell=e?.activeCell?{...e.activeCell}:null,this.lastSelectionRange=e?.selectionRange?{...e.selectionRange}:null,this.lastCopyRange=e?.copyRange?{...e.copyRange}:null,this.lastCutRange=e?.cutRange?{...e.cutRange}:null,this.lastEditingCell=e?.editingCell?{...e.editingCell}:null,this.lastColumnWidths=e?.columnWidths?{...e.columnWidths}:{},this.lastRowSelectionMode=e?.rowSelectionMode,this.lastSelectedRowIds=e?.selectedRowIds?new Set(e.selectedRowIds):void 0,this.lastShowRowNumbers=e?.showRowNumbers,this.lastPinnedColumns=e?.pinnedColumns,this.lastAllSelected=e?.allSelected,this.lastSomeSelected=e?.someSelected,this.lastHeaderSignature=this.computeHeaderSignature();let{items:t}=this.state.getProcessedItems();this.lastRenderedItems=t;}isSelectionOnlyChange(){if(!this.lastRenderedItems)return false;let e=this.interactionState,{items:t}=this.state.getProcessedItems();if(t!==this.lastRenderedItems||this.computeHeaderSignature()!==this.lastHeaderSignature)return false;let n=e?.editingCell,r=this.lastEditingCell;if(n?.rowId!==r?.rowId||n?.columnId!==r?.columnId||e?.rowSelectionMode!==this.lastRowSelectionMode)return false;if(e?.selectedRowIds!==this.lastSelectedRowIds){let o=e?.selectedRowIds,l=this.lastSelectedRowIds;if(!(!o&&!l)){if(!o||!l||o.size!==l.size)return false;for(let a of o)if(!l.has(a))return false}}return !(e?.showRowNumbers!==this.lastShowRowNumbers||e?.pinnedColumns!==this.lastPinnedColumns)}patchSelectionClasses(){if(!this.tbody||!this.interactionState)return;let e=this.interactionState,{activeCell:t,selectionRange:i,copyRange:n,cutRange:r}=e,o=this.lastActiveCell,l=this.lastSelectionRange,a=this.lastCopyRange,s=this.lastCutRange,d=i?P(i):null,c=l?P(l):null,u=n?P(n):null,m=a?P(a):null,v=r?P(r):null,g=s?P(s):null,S=this.getColOffset(),p=this.tbody.querySelectorAll("td[data-row-index][data-col-index]");for(let f=0;f<p.length;f++){let h=p[f],I=L(h);if(!I)continue;let w=I.rowIndex,b=I.colIndex,y=b-S,A=o&&o.rowIndex===w&&o.columnIndex===b,E=t&&t.rowIndex===w&&t.columnIndex===b;A&&!E?(h.removeAttribute("data-active-cell"),h.style.outline="",h.style.zIndex=""):E&&!A&&(h.setAttribute("data-active-cell","true"),h.style.outline="2px solid var(--ogrid-accent, #0078d4)",h.style.position="relative",h.style.zIndex="var(--ogrid-z-active-cell, 2)");let T=c&&M(c,w,y),C=d&&M(d,w,y),_=C&&!E,F=T&&!(o&&o.rowIndex===w&&o.columnIndex===b);F&&!_?(h.removeAttribute("data-in-range"),h.style.backgroundColor=""):_&&!F&&(h.setAttribute("data-in-range","true"),h.style.backgroundColor="var(--ogrid-range-bg, rgba(33, 115, 70, 0.12))");let H=m&&M(m,w,y),D=u&&M(u,w,y);H&&!D?!E&&!(v&&M(v,w,y))&&(h.style.outline=""):D&&!H&&(h.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))");let be=g&&M(g,w,y),O=v&&M(v,w,y);be&&!O?!E&&!(u&&M(u,w,y))&&(h.style.outline=""):O&&!be&&(h.style.outline="1px dashed var(--ogrid-accent, #0078d4)");let we=h.querySelector(".ogrid-fill-handle"),xe=i&&e.onFillHandleMouseDown&&w===Math.max(i.startRow,i.endRow)&&y===Math.max(i.startCol,i.endCol),_e=!!we;if(_e&&!xe)we?.remove();else if(!_e&&xe){let k=document.createElement("div");k.className="ogrid-fill-handle",k.setAttribute("data-fill-handle","true"),k.style.position="absolute",k.style.right="-3px",k.style.bottom="-3px",k.style.width="6px",k.style.height="6px",k.style.backgroundColor="var(--ogrid-selection, #217346)",k.style.cursor="crosshair",k.style.zIndex="5",h.style.position=h.style.position||"relative",k.addEventListener("pointerdown",Ge=>{this.interactionState?.onFillHandleMouseDown?.(Ge);}),h.appendChild(k);}if(!C&&e.pinnedColumns){let k=h.getAttribute("data-column-id");k&&e.pinnedColumns[k]&&(h.style.backgroundColor=h.style.backgroundColor||"var(--ogrid-bg, #fff)");}}this.snapshotState();}update(){if(!this.tbody||!this.thead){this.render(),this.snapshotState();return}if(this.isSelectionOnlyChange()){this.patchSelectionClasses();return}this.computeHeaderSignature()!==this.lastHeaderSignature&&(this.thead.innerHTML="",this.renderHeader()),this.tbody.innerHTML="",this.renderBody(),this.snapshotState();}hasCheckboxColumn(){let e=this.interactionState?.rowSelectionMode;return e==="single"||e==="multiple"}hasRowNumbersColumn(){return !!this.interactionState?.showRowNumbers}getColOffset(){let e=0;return this.hasCheckboxColumn()&&e++,this.hasRowNumbersColumn()&&e++,e}applyPinningStyles(e,t,i){let n=this.interactionState;if(!n?.pinnedColumns)return;let r=n.pinnedColumns[t];r&&(e.style.position="sticky",e.style.zIndex=i?"3":"1",e.setAttribute("data-pinned",r),r==="left"&&n.leftOffsets?e.style.left=`${n.leftOffsets[t]??0}px`:r==="right"&&n.rightOffsets&&(e.style.right=`${n.rightOffsets[t]??0}px`),i||(e.style.backgroundColor=e.style.backgroundColor||"var(--ogrid-bg, #fff)"));}renderHeader(){if(!this.thead)return;this.thead.innerHTML="";let e=this.state.visibleColumnDefs,t=this.hasCheckboxColumn(),i=this.hasRowNumbersColumn();if(this.interactionState?.showColumnLetters){let r=document.createElement("tr");if(r.className="ogrid-column-letter-row",t){let o=document.createElement("th");o.className="ogrid-column-letter-cell",o.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,r.appendChild(o);}if(i){let o=document.createElement("th");o.className="ogrid-column-letter-cell";let l=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH;o.style.width=`${l}px`,r.appendChild(o);}for(let o=0;o<e.length;o++){let l=document.createElement("th");l.className="ogrid-column-letter-cell",l.textContent=indexToColumnLetter(o),r.appendChild(l);}this.thead.appendChild(r);}let n=buildHeaderRows(this.state.allColumns,this.state.visibleColumns);if(n.length>1)for(let r=0;r<n.length;r++){let o=n[r],l=r===n.length-1,a=document.createElement("tr");if(t){let s=document.createElement("th");s.className="ogrid-header-cell ogrid-checkbox-header",s.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,l&&this.appendSelectAllCheckbox(s),a.appendChild(s);}if(i){if(l){let s=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,d=document.createElement("th");d.className="ogrid-header-cell ogrid-row-number-header",d.style.width=`${s}px`,d.style.minWidth=`${s}px`,d.style.maxWidth=`${s}px`,d.style.textAlign="center",d.style.position=d.style.position||"relative",d.textContent="#";let c=document.createElement("div");c.className="ogrid-resize-handle",c.style.position="absolute",c.style.right="0",c.style.top="0",c.style.bottom="0",c.style.width="4px",c.style.cursor="col-resize",c.style.userSelect="none",c.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),d.appendChild(c),a.appendChild(d);}else if(r===0){let s=document.createElement("th");s.rowSpan=n.length-1,s.style.padding="0",a.appendChild(s);}}for(let s of o){let d=document.createElement("th");if(d.textContent=s.label,d.className=s.isGroup?"ogrid-group-header":"ogrid-header-cell",s.colSpan>1&&(d.colSpan=s.colSpan),!s.isGroup&&s.columnDef?.sortable&&(d.classList.add("ogrid-sortable"),d.addEventListener("click",()=>{s.columnDef&&this.state.toggleSort(s.columnDef.columnId);})),!s.isGroup&&s.columnDef){d.setAttribute("data-column-id",s.columnDef.columnId),d.setAttribute("scope","col");let c=this.state.sort;c?.field===s.columnDef.columnId&&d.setAttribute("aria-sort",c.direction==="asc"?"ascending":"descending"),this.applyPinningStyles(d,s.columnDef.columnId,true);}a.appendChild(d);}this.thead?.appendChild(a);}else {let r=document.createElement("tr");if(t){let o=document.createElement("th");o.className="ogrid-header-cell ogrid-checkbox-header",o.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,this.appendSelectAllCheckbox(o),r.appendChild(o);}if(this.hasRowNumbersColumn()){let o=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,l=document.createElement("th");l.className="ogrid-header-cell ogrid-row-number-header",l.style.width=`${o}px`,l.style.minWidth=`${o}px`,l.style.maxWidth=`${o}px`,l.style.textAlign="center",l.style.position=l.style.position||"relative",l.textContent="#";let a=document.createElement("div");a.className="ogrid-resize-handle",a.style.position="absolute",a.style.right="0",a.style.top="0",a.style.bottom="0",a.style.width="4px",a.style.cursor="col-resize",a.style.userSelect="none",a.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),l.appendChild(a),r.appendChild(l);}for(let o=0;o<e.length;o++){let l=e[o],a=document.createElement("th");a.className="ogrid-header-cell",a.setAttribute("data-column-id",l.columnId),a.setAttribute("scope","col");let s=this.state.sort;s?.field===l.columnId&&a.setAttribute("aria-sort",s.direction==="asc"?"ascending":"descending");let d=document.createElement("span");d.textContent=l.name,a.appendChild(d),l.sortable&&(a.classList.add("ogrid-sortable"),a.addEventListener("click",()=>this.state.toggleSort(l.columnId))),l.type==="numeric"&&(a.style.textAlign="right"),this.interactionState?.columnWidths[l.columnId]&&(a.style.width=`${this.interactionState.columnWidths[l.columnId]}px`),this.applyPinningStyles(a,l.columnId,true);let c=document.createElement("div");c.className="ogrid-resize-handle",c.style.position="absolute",c.style.right="0",c.style.top="0",c.style.bottom="0",c.style.width="4px",c.style.cursor="col-resize",c.style.userSelect="none",a.style.position=a.style.position||"relative",a.appendChild(c);let u=this.filterConfigs.get(l.columnId);if(u&&this.onFilterIconClick){let m=document.createElement("button");m.className="ogrid-filter-icon",m.setAttribute("aria-label",`Filter ${l.name}`),m.setAttribute("aria-expanded","false"),m.setAttribute("aria-haspopup","dialog"),m.style.border="none",m.style.background="transparent",m.style.cursor="pointer",m.style.fontSize="10px",m.style.padding="0 2px",m.style.marginLeft="4px",m.style.color="var(--ogrid-fg, #242424)",m.style.opacity="0.6";let v=this.headerFilterState?.hasActiveFilter(u);m.textContent=v?"\u25BC":"\u25BD",v&&(m.style.opacity="1",m.style.color="var(--ogrid-selection, #217346)"),m.addEventListener("click",g=>{g.stopPropagation(),g.preventDefault(),this.onFilterIconClick?.(l.columnId,a);}),a.appendChild(m);}r.appendChild(a);}this.thead?.appendChild(r);}}appendSelectAllCheckbox(e){let t=this.interactionState;if(t?.rowSelectionMode!=="multiple")return;let i=document.createElement("input");i.type="checkbox",i.className="ogrid-select-all-checkbox",i.checked=t?.allSelected===true,i.indeterminate=t?.someSelected===true,i.setAttribute("aria-label","Select all rows"),i.addEventListener("change",()=>{t?.onSelectAll?.(i.checked);}),e.appendChild(i);}renderBody(){if(!this.tbody)return;let e=this.state.visibleColumnDefs,{items:t}=this.state.getProcessedItems(),i=this.hasCheckboxColumn(),n=this.hasRowNumbersColumn(),r=this.getColOffset(),o=e.length+r,l=n?(this.state.page-1)*this.state.pageSize:0;if(t.length===0&&!this.state.isLoading){let p=document.createElement("tr"),f=document.createElement("td");f.colSpan=o,f.className="ogrid-empty-state",f.textContent="No data",p.appendChild(f),this.tbody.appendChild(p);return}let a=this.virtualScrollState,s=a?.enabled===true,d=0,c=t.length-1;if(s){let p=a?.visibleRange;if(!p)return;if(d=Math.max(0,p.startIndex),c=Math.min(t.length-1,p.endIndex),p.offsetTop>0){let f=document.createElement("tr");f.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${p.offsetTop}px`,h.style.padding="0",h.style.border="none",f.appendChild(h),this.tbody.appendChild(f);}}let u=a?.columnVirtualizationEnabled===true&&a.columnRange!=null,m=e,v=null,g=0,S=0;if(u&&a){let p=partitionColumnsForVirtualization(e,a.columnRange,this.interactionState?.pinnedColumns),f=[...p.pinnedLeft,...p.virtualizedUnpinned,...p.pinnedRight];v=f.map(h=>e.indexOf(h)),m=f,g=p.leftSpacerWidth,S=p.rightSpacerWidth;}for(let p=d;p<=c;p++){let f=t[p];if(!f)continue;let h=this.state.getRowId(f),I=document.createElement("tr");I.className="ogrid-row",I.setAttribute("data-row-id",String(h));let w=this.interactionState?.selectedRowIds?.has(h)===true;if(w&&(I.setAttribute("data-row-selected","true"),I.setAttribute("aria-selected","true")),i){let b=document.createElement("td");b.className="ogrid-cell ogrid-checkbox-cell",b.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,b.style.textAlign="center";let y=document.createElement("input");y.type="checkbox",y.className="ogrid-row-checkbox",y.checked=w,y.setAttribute("aria-label",`Select row ${h}`),y.addEventListener("click",A=>{A.stopPropagation(),this.interactionState?.onRowCheckboxChange?.(h,y.checked,p,A.shiftKey);}),b.appendChild(y),I.appendChild(b);}if(n){let b=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,y=document.createElement("td");y.className="ogrid-cell ogrid-row-number-cell",y.style.width=`${b}px`,y.style.minWidth=`${b}px`,y.style.maxWidth=`${b}px`,y.style.textAlign="center",y.style.color="var(--ogrid-fg-muted, #666)",y.style.fontSize="0.9em",y.textContent=String(l+p+1),I.appendChild(y);}if(g>0){let b=document.createElement("td");b.style.width=`${g}px`,b.style.minWidth=`${g}px`,b.style.padding="0",b.style.border="none",b.setAttribute("aria-hidden","true"),I.appendChild(b);}for(let b=0;b<m.length;b++){let y=m[b],A=(v?v[b]:b)+r,E=document.createElement("td");if(E.className="ogrid-cell",E.setAttribute("data-column-id",y.columnId),E.setAttribute("data-row-index",String(p)),E.setAttribute("data-col-index",String(A)),E.setAttribute("tabindex","-1"),y.type==="numeric"&&(E.style.textAlign="right"),this.applyPinningStyles(E,y.columnId,false),this.interactionState){let{activeCell:T,selectionRange:C,copyRange:_,cutRange:F,editingCell:H}=this.interactionState;T&&T.rowIndex===p&&T.columnIndex===A&&(E.setAttribute("data-active-cell","true"),E.style.outline="2px solid var(--ogrid-accent, #0078d4)",E.style.position="relative",E.style.zIndex="var(--ogrid-z-active-cell, 2)"),C&&isInSelectionRange(C,p,b)&&(E.setAttribute("data-in-range","true"),E.style.backgroundColor="var(--ogrid-range-bg, rgba(33, 115, 70, 0.12))"),_&&isInSelectionRange(_,p,b)&&(E.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))"),F&&isInSelectionRange(F,p,b)&&(E.style.outline="1px dashed var(--ogrid-accent, #0078d4)"),H&&H.rowId===h&&H.columnId===y.columnId&&(E.style.visibility="hidden");}if(y.renderCell){let T=getCellValue(f,y),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(b,p)?this.formulaEngine.getValue(b,p)??T:T;y.renderCell(E,f,C);}else {let T=getCellValue(f,y),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(b,p)?this.formulaEngine.getValue(b,p)??T:T;if(y.type==="boolean"){let _=!!C,F=!!y.editable,H=document.createElement("input");H.type="checkbox",H.checked=_,H.disabled=!F,H.style.margin="0",H.style.cursor=F?"pointer":"default",H.style.outline="none",H.setAttribute("aria-label",_?"Checked":"Unchecked"),F&&(H.addEventListener("change",()=>{this.interactionState?.onBooleanToggle?.(h,y.columnId,_);}),H.addEventListener("click",D=>D.stopPropagation())),E.appendChild(H);}else y.valueFormatter?E.textContent=y.valueFormatter(C,f):C!=null&&(E.textContent=String(C));}if(y.cellStyle){let T=typeof y.cellStyle=="function"?y.cellStyle(f):y.cellStyle;T&&Object.assign(E.style,T);}if(this.interactionState){let{selectionRange:T}=this.interactionState;if(T&&this.interactionState.onFillHandleMouseDown&&p===Math.max(T.startRow,T.endRow)&&b===Math.max(T.startCol,T.endCol)){let C=document.createElement("div");C.className="ogrid-fill-handle",C.setAttribute("data-fill-handle","true"),C.style.position="absolute",C.style.right="-3px",C.style.bottom="-3px",C.style.width="6px",C.style.height="6px",C.style.backgroundColor="var(--ogrid-selection, #217346)",C.style.cursor="crosshair",C.style.zIndex="5",E.style.position=E.style.position||"relative",E.appendChild(C);}}I.appendChild(E);}if(S>0){let b=document.createElement("td");b.style.width=`${S}px`,b.style.minWidth=`${S}px`,b.style.padding="0",b.style.border="none",b.setAttribute("aria-hidden","true"),I.appendChild(b);}this.tbody.appendChild(I);}if(s&&a){let p=a.visibleRange;if(p.offsetBottom>0){let f=document.createElement("tr");f.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${p.offsetBottom}px`,h.style.padding="0",h.style.border="none",f.appendChild(h),this.tbody.appendChild(f);}}}getTableElement(){return this.table}getOnResizeStart(){return this.interactionState?.onResizeStart}updateDropIndicator(e,t){if(!this.dropIndicator||!this.wrapperEl)return;if(!t||e===null){this.dropIndicator.style.display="none";return}let i=this.wrapperEl.getBoundingClientRect(),n=e-i.left+this.wrapperEl.scrollLeft;this.dropIndicator.style.display="block",this.dropIndicator.style.left=`${n}px`;}destroy(){this.detachHeaderDelegation(),this.detachBodyDelegation(),this.container.innerHTML="",this.table=null,this.thead=null,this.tbody=null,this.dropIndicator=null;}};var W=class{constructor(e,t){this.el=null;this.container=e,this.state=t;}render(e,t){this.el&&this.el.remove();let i=getPaginationViewModel(this.state.page,this.state.pageSize,e,t?{pageSizeOptions:t}:void 0);if(!i)return;this.el=document.createElement("div"),this.el.className="ogrid-pagination";let n=document.createElement("div");n.className="ogrid-pagination-size";let r=document.createElement("span");r.textContent="Rows per page: ",n.appendChild(r);let o=document.createElement("select");o.className="ogrid-page-size-select";for(let c of i.pageSizeOptions){let u=document.createElement("option");u.value=String(c),u.textContent=String(c),u.selected=c===this.state.pageSize,o.appendChild(u);}o.addEventListener("change",()=>{this.state.setPageSize(Number(o.value));}),n.appendChild(o),this.el.appendChild(n);let l=document.createElement("span");l.className="ogrid-pagination-info",l.textContent=`${i.startItem}-${i.endItem} of ${e}`,this.el.appendChild(l);let a=document.createElement("div");a.className="ogrid-pagination-nav";let s=document.createElement("button");if(s.textContent="\u25C0",s.className="ogrid-pagination-btn",s.disabled=this.state.page===1,s.addEventListener("click",()=>this.state.setPage(this.state.page-1)),a.appendChild(s),i.showStartEllipsis){let c=document.createElement("span");c.textContent="...",c.className="ogrid-pagination-ellipsis",a.appendChild(c);}for(let c of i.pageNumbers){let u=document.createElement("button");u.textContent=String(c),u.className="ogrid-pagination-btn"+(c===this.state.page?" ogrid-pagination-active":""),u.addEventListener("click",()=>this.state.setPage(c)),a.appendChild(u);}if(i.showEndEllipsis){let c=document.createElement("span");c.textContent="...",c.className="ogrid-pagination-ellipsis",a.appendChild(c);}let d=document.createElement("button");d.textContent="\u25B6",d.className="ogrid-pagination-btn",d.disabled=this.state.page===i.totalPages,d.addEventListener("click",()=>this.state.setPage(this.state.page+1)),a.appendChild(d),this.el.appendChild(a),this.container.appendChild(this.el);}destroy(){this.el?.remove(),this.el=null;}};var G=class{constructor(e){this.el=null;this.container=e;}render(e){this.el&&this.el.remove();let t=getStatusBarParts(e);if(!(t.length===0&&!e.aggregation)){this.el=document.createElement("div"),this.el.className="ogrid-status-bar";for(let i of t){let n=document.createElement("span");n.className="ogrid-status-part",n.textContent=`${i.label}: ${i.value}`,this.el.appendChild(n);}if(e.aggregation){let i=e.aggregation,n=document.createElement("span");n.className="ogrid-status-aggregation",n.textContent=`Sum: ${i.sum.toLocaleString()} | Avg: ${i.avg.toFixed(2)} | Min: ${i.min} | Max: ${i.max} | Count: ${i.count}`,this.el.appendChild(n);}this.container.appendChild(this.el);}}destroy(){this.el?.remove(),this.el=null;}};var U=class{constructor(e,t){this.el=null;this.dropdown=null;this.isOpen=false;this.initialized=false;this.container=e,this.state=t;}render(){this.initialized||(this.createDOM(),this.initialized=true),this.isOpen&&this.dropdown&&this.updateDropdownState();}createDOM(){this.el=document.createElement("div"),this.el.className="ogrid-column-chooser";let e=document.createElement("button");e.className="ogrid-column-chooser-btn",e.textContent="Columns",e.addEventListener("click",()=>this.toggle()),this.el.appendChild(e),this.container.appendChild(this.el);}updateDropdownState(){if(!this.dropdown)return;let e=this.dropdown.querySelectorAll('input[type="checkbox"]'),t=this.state.columns;e.forEach((i,n)=>{n<t.length&&(i.checked=this.state.visibleColumns.has(t[n].columnId));});}toggle(){this.isOpen?this.close():this.open();}open(){if(!this.dropdown){this.isOpen=true,this.dropdown=document.createElement("div"),this.dropdown.className="ogrid-column-chooser-dropdown";for(let e of this.state.columns){let t=document.createElement("label");t.className="ogrid-column-chooser-item";let i=document.createElement("input");i.type="checkbox",i.checked=this.state.visibleColumns.has(e.columnId),i.disabled=!!e.required,i.addEventListener("change",()=>{let n=new Set(this.state.visibleColumns);i.checked?n.add(e.columnId):n.delete(e.columnId),this.state.setVisibleColumns(n);}),t.appendChild(i),t.appendChild(document.createTextNode(" "+e.name)),this.dropdown.appendChild(t);}this.el?.appendChild(this.dropdown);}}close(){this.isOpen=false,this.dropdown?.remove(),this.dropdown=null;}destroy(){this.close(),this.el?.remove(),this.el=null,this.initialized=false;}};var ke=["columns","filters"],K=class{constructor(e){this.emitter=new x;if(this._isEnabled=e!=null&&e!==false,!this._isEnabled||e===true)this._panels=ke,this._position="right",this._activePanel=null;else {let t=e;this._panels=t.panels??ke,this._position=t.position??"right",this._activePanel=t.defaultPanel??null;}}get isEnabled(){return this._isEnabled}get panels(){return this._panels}get position(){return this._position}get activePanel(){return this._activePanel}get isOpen(){return this._activePanel!==null}setActivePanel(e){this._activePanel=e,this.emitter.emit("change");}toggle(e){this.setActivePanel(this._activePanel===e?null:e);}close(){this.setActivePanel(null);}onChange(e){return this.emitter.on("change",e),()=>this.emitter.off("change",e)}destroy(){this.emitter.removeAllListeners();}};var pe={columns:"Columns",filters:"Filters"},ot={columns:"\u2261",filters:"\u2A65"},$=class{constructor(e,t){this.el=null;this.config=null;this.container=e,this.state=t;}setConfig(e){this.config=e;}render(){if(this.el&&this.el.remove(),!this.state.isEnabled||!this.config)return;this.el=document.createElement("div"),this.el.className="ogrid-sidebar",this.el.setAttribute("role","complementary"),this.el.setAttribute("aria-label","Side bar"),this.el.style.display="flex",this.el.style.flexDirection="row",this.el.style.flexShrink="0";let e=this.state.position,t=this.createTabStrip(e),i=this.createPanel(e);e==="left"?(this.el.appendChild(t),i&&this.el.appendChild(i)):(i&&this.el.appendChild(i),this.el.appendChild(t)),this.container.appendChild(this.el);}createTabStrip(e){let t=document.createElement("div");t.style.display="flex",t.style.flexDirection="column",t.style.width="36px",t.style.background="var(--ogrid-header-bg, #f5f5f5)",t.setAttribute("role","tablist"),t.setAttribute("aria-label","Side bar tabs"),e==="right"?t.style.borderLeft="1px solid var(--ogrid-border, #e0e0e0)":t.style.borderRight="1px solid var(--ogrid-border, #e0e0e0)";for(let i of this.state.panels){let n=document.createElement("button");n.setAttribute("role","tab"),n.setAttribute("aria-selected",String(this.state.activePanel===i)),n.setAttribute("aria-label",pe[i]),n.title=pe[i],n.textContent=ot[i],n.className="ogrid-sidebar-tab",n.style.width="36px",n.style.height="36px",n.style.border="none",n.style.cursor="pointer",n.style.color="var(--ogrid-fg, #242424)",n.style.fontSize="14px",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",this.state.activePanel===i?(n.style.background="var(--ogrid-bg, #fff)",n.style.fontWeight="bold"):(n.style.background="transparent",n.style.fontWeight="normal"),n.addEventListener("click",()=>{this.state.toggle(i);}),t.appendChild(n);}return t}createPanel(e){if(!this.state.isOpen||!this.state.activePanel)return null;let t=document.createElement("div");t.setAttribute("role","tabpanel"),t.setAttribute("aria-label",pe[this.state.activePanel]),t.className="ogrid-sidebar-panel",t.style.width="240px",t.style.display="flex",t.style.flexDirection="column",t.style.overflow="hidden",t.style.background="var(--ogrid-bg, #fff)",t.style.color="var(--ogrid-fg, #242424)",e==="right"?t.style.borderLeft="1px solid var(--ogrid-border, #e0e0e0)":t.style.borderRight="1px solid var(--ogrid-border, #e0e0e0)";let i=document.createElement("div");i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.padding="8px 12px",i.style.borderBottom="1px solid var(--ogrid-border, #e0e0e0)",i.style.fontWeight="600";let n=document.createElement("span");n.textContent=pe[this.state.activePanel],i.appendChild(n);let r=document.createElement("button");r.innerHTML="×",r.setAttribute("aria-label","Close panel"),r.style.border="none",r.style.background="transparent",r.style.cursor="pointer",r.style.fontSize="16px",r.style.color="var(--ogrid-fg, #242424)",r.addEventListener("click",()=>this.state.close()),i.appendChild(r),t.appendChild(i);let o=document.createElement("div");return o.style.flex="1",o.style.overflowY="auto",o.style.padding="8px 12px",this.state.activePanel==="columns"?this.renderColumnsPanel(o):this.state.activePanel==="filters"&&this.renderFiltersPanel(o),t.appendChild(o),t}renderColumnsPanel(e){if(!this.config)return;let{columns:t,visibleColumns:i,onVisibilityChange:n,onSetVisibleColumns:r}=this.config,o=t.every(d=>i.has(d.columnId)),l=document.createElement("div");l.style.display="flex",l.style.gap="8px",l.style.marginBottom="8px";let a=document.createElement("button");a.textContent="Select All",a.disabled=o,a.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(a),a.addEventListener("click",()=>{let d=new Set(i);t.forEach(c=>d.add(c.columnId)),r(d);}),l.appendChild(a);let s=document.createElement("button");s.textContent="Clear All",s.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(s),s.addEventListener("click",()=>{let d=new Set;t.forEach(c=>{c.required&&i.has(c.columnId)&&d.add(c.columnId);}),r(d);}),l.appendChild(s),e.appendChild(l);for(let d of t){let c=document.createElement("label");c.style.display="flex",c.style.alignItems="center",c.style.gap="6px",c.style.padding="2px 0",c.style.cursor="pointer";let u=document.createElement("input");u.type="checkbox",u.checked=i.has(d.columnId),u.disabled=!!d.required,u.addEventListener("change",()=>{n(d.columnId,u.checked);});let m=document.createElement("span");m.textContent=d.name,c.appendChild(u),c.appendChild(m),e.appendChild(c);}}renderFiltersPanel(e){if(!this.config)return;let{filterableColumns:t,filters:i,onFilterChange:n,filterOptions:r}=this.config;if(t.length===0){let o=document.createElement("div");o.style.color="var(--ogrid-muted, #999)",o.style.fontStyle="italic",o.textContent="No filterable columns",e.appendChild(o);return}for(let o of t){let l=document.createElement("div");l.style.marginBottom="12px";let a=document.createElement("div");if(a.style.fontWeight="500",a.style.marginBottom="4px",a.style.fontSize="13px",a.textContent=o.name,l.appendChild(a),o.filterType==="text"){let s=document.createElement("input");s.type="text";let d=i[o.filterField];s.value=d?.type==="text"?d.value:"",s.placeholder=`Filter ${o.name}...`,s.setAttribute("aria-label",`Filter ${o.name}`),this.applyTextInputStyle(s),s.addEventListener("input",()=>{n(o.filterField,s.value?{type:"text",value:s.value}:void 0);}),l.appendChild(s);}else if(o.filterType==="date"){let s=document.createElement("div");s.style.display="flex",s.style.flexDirection="column",s.style.gap="4px";let d=i[o.filterField],c=d?.type==="date"?d.value:{},u=document.createElement("label");u.style.display="flex",u.style.alignItems="center",u.style.gap="4px",u.style.fontSize="12px",u.textContent="From: ";let m=document.createElement("input");m.type="date",m.value=c.from??"",m.setAttribute("aria-label",`${o.name} from date`),this.applyDateInputStyle(m),u.appendChild(m),s.appendChild(u);let v=document.createElement("label");v.style.display="flex",v.style.alignItems="center",v.style.gap="4px",v.style.fontSize="12px",v.textContent="To: ";let g=document.createElement("input");g.type="date",g.value=c.to??"",g.setAttribute("aria-label",`${o.name} to date`),this.applyDateInputStyle(g),v.appendChild(g),s.appendChild(v);let S=()=>{let p=m.value||void 0,f=g.value||void 0;n(o.filterField,p||f?{type:"date",value:{from:p,to:f}}:void 0);};m.addEventListener("change",S),g.addEventListener("change",S),l.appendChild(s);}else if(o.filterType==="multiSelect"){let s=r[o.filterField]??[],d=document.createElement("div");d.style.maxHeight="120px",d.style.overflowY="auto",d.setAttribute("role","group"),d.setAttribute("aria-label",`${o.name} options`);let c=i[o.filterField],u=c?.type==="multiSelect"?c.value:[];for(let m of s){let v=document.createElement("label");v.style.display="flex",v.style.alignItems="center",v.style.gap="4px",v.style.padding="1px 0",v.style.cursor="pointer",v.style.fontSize="13px";let g=document.createElement("input");g.type="checkbox",g.checked=u.includes(m),g.addEventListener("change",()=>{let p=i[o.filterField],f=p?.type==="multiSelect"?[...p.value]:[],h=g.checked?[...f,m]:f.filter(I=>I!==m);n(o.filterField,h.length>0?{type:"multiSelect",value:h}:void 0);});let S=document.createElement("span");S.textContent=m,v.appendChild(g),v.appendChild(S),d.appendChild(v);}l.appendChild(d);}e.appendChild(l);}}applyActionButtonStyle(e){e.style.flex="1",e.style.cursor="pointer",e.style.background="var(--ogrid-bg-subtle, #f3f2f1)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px",e.style.padding="4px 8px";}applyTextInputStyle(e){e.style.width="100%",e.style.boxSizing="border-box",e.style.padding="4px 6px",e.style.background="var(--ogrid-bg, #fff)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}applyDateInputStyle(e){e.style.flex="1",e.style.padding="2px 4px",e.style.background="var(--ogrid-bg, #fff)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}destroy(){this.el?.remove(),this.el=null;}};var X=class{constructor(e){this.emitter=new x;this._openColumnId=null;this._tempTextValue="";this._tempSelected=new Set;this._tempDateFrom="";this._tempDateTo="";this._searchText="";this._popoverPosition=null;this._filters={};this._filterOptions={};this._clickOutsideHandler=null;this._escapeHandler=null;this._popoverEl=null;this._headerEl=null;this._onFilterChange=e;}get openColumnId(){return this._openColumnId}get tempTextValue(){return this._tempTextValue}get tempSelected(){return this._tempSelected}get tempDateFrom(){return this._tempDateFrom}get tempDateTo(){return this._tempDateTo}get searchText(){return this._searchText}get popoverPosition(){return this._popoverPosition}setFilters(e){this._filters=e;}setFilterOptions(e){this._filterOptions=e;}setPopoverEl(e){this._popoverEl=e;}getFilterOptions(e){return this._filterOptions[e]??[]}getFilteredOptions(e){let t=this.getFilterOptions(e);if(!this._searchText)return t;let i=this._searchText.toLowerCase();return t.filter(n=>n.toLowerCase().includes(i))}hasActiveFilter(e){let t=this._filters[e.filterField];return t?t.type==="text"?t.value.trim().length>0:t.type==="multiSelect"?t.value.length>0:t.type==="date"?!!(t.value.from||t.value.to):t.type==="people"?!!t.value:false:false}open(e,t,i,n){this._openColumnId&&this.close(),this._openColumnId=e,this._headerEl=i,this._popoverEl=n;let r=this._filters[t.filterField];if(t.filterType==="text")this._tempTextValue=r?.type==="text"?r.value:"";else if(t.filterType==="multiSelect")this._tempSelected=new Set(r?.type==="multiSelect"?r.value:[]);else if(t.filterType==="date"){let l=r?.type==="date"?r.value:{};this._tempDateFrom=l.from??"",this._tempDateTo=l.to??"";}this._searchText="";let o=i.getBoundingClientRect();this._popoverPosition={top:o.bottom+4,left:o.left},this._clickOutsideHandler=l=>{let a=l.target;this._popoverEl&&!this._popoverEl.contains(a)&&this._headerEl&&!this._headerEl.contains(a)&&this.close();},this._escapeHandler=l=>{l.key==="Escape"&&(l.preventDefault(),l.stopPropagation(),this.close());},setTimeout(()=>{this._clickOutsideHandler&&document.addEventListener("mousedown",this._clickOutsideHandler,{passive:true});},0),this._escapeHandler&&document.addEventListener("keydown",this._escapeHandler,true),this.emitter.emit("change");}close(){this._openColumnId=null,this._popoverPosition=null,this._popoverEl=null,this._headerEl=null,this._clickOutsideHandler&&(document.removeEventListener("mousedown",this._clickOutsideHandler),this._clickOutsideHandler=null),this._escapeHandler&&(document.removeEventListener("keydown",this._escapeHandler,true),this._escapeHandler=null),this.emitter.emit("change");}setTempTextValue(e){this._tempTextValue=e,this.emitter.emit("change");}setSearchText(e){this._searchText=e,this.emitter.emit("change");}setTempDateFrom(e){this._tempDateFrom=e,this.emitter.emit("change");}setTempDateTo(e){this._tempDateTo=e,this.emitter.emit("change");}handleCheckboxChange(e,t){let i=new Set(this._tempSelected);t?i.add(e):i.delete(e),this._tempSelected=i,this.emitter.emit("change");}handleSelectAll(e){this._tempSelected=new Set(this.getFilterOptions(e)),this.emitter.emit("change");}handleClearSelection(){this._tempSelected=new Set,this.emitter.emit("change");}applyTextFilter(e){let t=this._tempTextValue.trim();this._onFilterChange(e,t?{type:"text",value:t}:void 0),this.close();}clearTextFilter(e){this._tempTextValue="",this._onFilterChange(e,void 0),this.close();}applyMultiSelectFilter(e){let t=Array.from(this._tempSelected);this._onFilterChange(e,t.length>0?{type:"multiSelect",value:t}:void 0),this.close();}applyDateFilter(e){let t=this._tempDateFrom||void 0,i=this._tempDateTo||void 0;this._onFilterChange(e,t||i?{type:"date",value:{from:t,to:i}}:void 0),this.close();}clearDateFilter(e){this._tempDateFrom="",this._tempDateTo="",this._onFilterChange(e,void 0),this.close();}clearFilter(e){this._onFilterChange(e,void 0),this.close();}onChange(e){return this.emitter.on("change",e),()=>this.emitter.off("change",e)}destroy(){this.close(),this.emitter.removeAllListeners();}};var q=class{constructor(e){this.popoverEl=null;this.state=e;}render(e){if(this.cleanup(),!e||!this.state.openColumnId||!this.state.popoverPosition)return;let t=this.state.popoverPosition;this.popoverEl=document.createElement("div"),this.popoverEl.className="ogrid-header-filter-popover",this.popoverEl.style.position="fixed",this.popoverEl.style.top=`${t.top}px`,this.popoverEl.style.left=`${t.left}px`,this.popoverEl.style.zIndex="9999",this.popoverEl.style.background="var(--ogrid-bg, #fff)",this.popoverEl.style.color="var(--ogrid-fg, #242424)",this.popoverEl.style.border="1px solid var(--ogrid-border, #e0e0e0)",this.popoverEl.style.borderRadius="4px",this.popoverEl.style.boxShadow="var(--ogrid-shadow, 0 2px 8px rgba(0,0,0,0.15))",this.popoverEl.style.padding="8px",this.popoverEl.style.minWidth="200px",this.popoverEl.style.maxHeight="320px",this.popoverEl.style.overflowY="auto",this.popoverEl.addEventListener("click",i=>i.stopPropagation()),this.popoverEl.addEventListener("mousedown",i=>i.stopPropagation()),e.filterType==="text"?this.renderTextFilter(e):e.filterType==="multiSelect"?this.renderMultiSelectFilter(e):e.filterType==="date"&&this.renderDateFilter(e),document.body.appendChild(this.popoverEl);}renderTextFilter(e){if(!this.popoverEl)return;let t=document.createElement("input");t.type="text",t.value=this.state.tempTextValue,t.placeholder="Filter...",t.setAttribute("aria-label","Text filter"),t.className="ogrid-filter-text-input",this.applyInputStyle(t),t.style.marginBottom="8px",t.addEventListener("input",()=>{this.state.setTempTextValue(t.value);}),t.addEventListener("keydown",o=>{o.key==="Enter"&&this.state.applyTextFilter(e.filterField),o.stopPropagation();}),this.popoverEl.appendChild(t);let i=document.createElement("div");i.style.display="flex",i.style.gap="8px";let n=document.createElement("button");n.textContent="Apply",n.className="ogrid-filter-apply-btn",this.applyButtonStyle(n),n.addEventListener("click",()=>this.state.applyTextFilter(e.filterField)),i.appendChild(n);let r=document.createElement("button");r.textContent="Clear",r.className="ogrid-filter-clear-btn",this.applyButtonStyle(r),r.addEventListener("click",()=>this.state.clearTextFilter(e.filterField)),i.appendChild(r),this.popoverEl.appendChild(i),setTimeout(()=>t.focus(),0);}renderMultiSelectFilter(e){if(!this.popoverEl)return;let t=document.createElement("input");t.type="text",t.value=this.state.searchText,t.placeholder="Search...",t.setAttribute("aria-label","Search filter options"),t.className="ogrid-filter-search-input",this.applyInputStyle(t),t.style.marginBottom="8px",t.addEventListener("input",()=>{this.state.setSearchText(t.value),this.updateCheckboxList(e,o);}),t.addEventListener("keydown",a=>a.stopPropagation()),this.popoverEl.appendChild(t);let i=document.createElement("div");i.style.display="flex",i.style.gap="8px",i.style.marginBottom="8px";let n=document.createElement("button");n.textContent="Select All",n.className="ogrid-filter-select-all-btn",this.applySmallButtonStyle(n),n.addEventListener("click",()=>{this.state.handleSelectAll(e.filterField),this.updateCheckboxList(e,o);}),i.appendChild(n);let r=document.createElement("button");r.textContent="Clear",r.className="ogrid-filter-clear-sel-btn",this.applySmallButtonStyle(r),r.addEventListener("click",()=>{this.state.handleClearSelection(),this.updateCheckboxList(e,o);}),i.appendChild(r),this.popoverEl.appendChild(i);let o=document.createElement("div");o.className="ogrid-filter-checkbox-list",o.style.maxHeight="160px",o.style.overflowY="auto",o.style.marginBottom="8px",o.setAttribute("role","group"),o.setAttribute("aria-label","Filter options"),this.updateCheckboxList(e,o),this.popoverEl.appendChild(o);let l=document.createElement("button");l.textContent="Apply",l.className="ogrid-filter-apply-btn",this.applyButtonStyle(l),l.addEventListener("click",()=>this.state.applyMultiSelectFilter(e.filterField)),this.popoverEl.appendChild(l);}updateCheckboxList(e,t){t.innerHTML="";let i=this.state.getFilteredOptions(e.filterField),n=this.state.tempSelected;for(let r of i){let o=document.createElement("label");o.style.display="flex",o.style.alignItems="center",o.style.gap="4px",o.style.padding="2px 0",o.style.cursor="pointer",o.style.fontSize="13px";let l=document.createElement("input");l.type="checkbox",l.checked=n.has(r),l.addEventListener("change",()=>{this.state.handleCheckboxChange(r,l.checked);});let a=document.createElement("span");a.textContent=r,o.appendChild(l),o.appendChild(a),t.appendChild(o);}if(i.length===0){let r=document.createElement("div");r.style.color="var(--ogrid-muted, #999)",r.style.fontStyle="italic",r.style.padding="4px 0",r.textContent="No options",t.appendChild(r);}}renderDateFilter(e){if(!this.popoverEl)return;let t=document.createElement("div");t.style.display="flex",t.style.flexDirection="column",t.style.gap="8px";let i=document.createElement("label");i.style.display="flex",i.style.alignItems="center",i.style.gap="4px",i.style.fontSize="13px",i.textContent="From: ";let n=document.createElement("input");n.type="date",n.value=this.state.tempDateFrom,n.setAttribute("aria-label","From date"),this.applyInputStyle(n),n.addEventListener("change",()=>{this.state.setTempDateFrom(n.value);}),n.addEventListener("keydown",d=>d.stopPropagation()),i.appendChild(n),t.appendChild(i);let r=document.createElement("label");r.style.display="flex",r.style.alignItems="center",r.style.gap="4px",r.style.fontSize="13px",r.textContent="To: ";let o=document.createElement("input");o.type="date",o.value=this.state.tempDateTo,o.setAttribute("aria-label","To date"),this.applyInputStyle(o),o.addEventListener("change",()=>{this.state.setTempDateTo(o.value);}),o.addEventListener("keydown",d=>d.stopPropagation()),r.appendChild(o),t.appendChild(r),this.popoverEl.appendChild(t);let l=document.createElement("div");l.style.display="flex",l.style.gap="8px",l.style.marginTop="8px";let a=document.createElement("button");a.textContent="Apply",a.className="ogrid-filter-apply-btn",this.applyButtonStyle(a),a.addEventListener("click",()=>this.state.applyDateFilter(e.filterField)),l.appendChild(a);let s=document.createElement("button");s.textContent="Clear",s.className="ogrid-filter-clear-btn",this.applyButtonStyle(s),s.addEventListener("click",()=>this.state.clearDateFilter(e.filterField)),l.appendChild(s),this.popoverEl.appendChild(l);}applyInputStyle(e){e.style.width="100%",e.style.boxSizing="border-box",e.style.padding="4px 6px",e.style.background="var(--ogrid-bg, #fff)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}applyButtonStyle(e){e.style.flex="1",e.style.cursor="pointer",e.style.padding="6px 12px",e.style.background="var(--ogrid-bg-subtle, #f3f2f1)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}applySmallButtonStyle(e){e.style.cursor="pointer",e.style.padding="2px 8px",e.style.fontSize="12px",e.style.background="transparent",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}cleanup(){this.popoverEl&&(this.popoverEl.remove(),this.popoverEl=null);}destroy(){this.cleanup();}};var j=class{constructor(){this.emitter=new x;this._containerWidth=0;this._columnSizingOverrides={};this._ro=null;}observeContainer(e){this.disconnectObserver(),typeof ResizeObserver<"u"&&(this._ro=new ResizeObserver(t=>{for(let i of t){let n=i.contentRect;this._containerWidth=n.width,this.emitter.emit("layoutChange",{type:"containerResize"});}}),this._ro.observe(e)),this._containerWidth=e.clientWidth;}disconnectObserver(){this._ro&&(this._ro.disconnect(),this._ro=null);}get containerWidth(){return this._containerWidth}get columnSizingOverrides(){return this._columnSizingOverrides}setColumnOverride(e,t){this._columnSizingOverrides[e]=t,this.emitter.emit("layoutChange",{type:"columnOverride"});}computeMinTableWidth(e,t){return (t?CHECKBOX_COLUMN_WIDTH:0)+e*(DEFAULT_MIN_COLUMN_WIDTH+CELL_PADDING)}computeDesiredTableWidth(e,t){let n=t?CHECKBOX_COLUMN_WIDTH:0;for(let r of e){let o=this._columnSizingOverrides[r.columnId];o?n+=o+CELL_PADDING:n+=(r.width??r.minWidth??DEFAULT_MIN_COLUMN_WIDTH)+CELL_PADDING;}return n}getAllColumnWidths(){return {...this._columnSizingOverrides}}cleanupOverrides(e){let t={},i=false;for(let[n,r]of Object.entries(this._columnSizingOverrides))e.has(n)?t[n]=r:i=true;i&&(this._columnSizingOverrides=t,this.emitter.emit("layoutChange",{type:"columnOverride"}));}applyInitialWidths(e){this._columnSizingOverrides={...e};}onLayoutChange(e){return this.emitter.on("layoutChange",e),()=>this.emitter.off("layoutChange",e)}destroy(){this.disconnectObserver(),this.emitter.removeAllListeners();}};var Y=class{constructor(e,t){this.emitter=new x;this._selectedRowIds=new Set;this._lastClickedRow=-1;this._rowSelection=e,this._getRowId=t;}get selectedRowIds(){return this._selectedRowIds}get rowSelection(){return this._rowSelection}updateSelection(e,t){this._selectedRowIds=e,this.emitter.emit("rowSelectionChange",{selectedRowIds:Array.from(e),selectedItems:t.filter(i=>e.has(this._getRowId(i)))});}handleRowCheckboxChange(e,t,i,n,r){if(this._rowSelection==="single"){this.updateSelection(t?new Set([e]):new Set,r),this._lastClickedRow=i;return}let o;n&&this._lastClickedRow>=0&&this._lastClickedRow!==i?o=applyRangeRowSelection(this._lastClickedRow,i,t,r,this._getRowId,this._selectedRowIds):(o=new Set(this._selectedRowIds),t?o.add(e):o.delete(e)),this._lastClickedRow=i,this.updateSelection(o,r);}handleSelectAll(e,t){e?this.updateSelection(new Set(t.map(i=>this._getRowId(i))),t):this.updateSelection(new Set,t);}isAllSelected(e){return computeRowSelectionState(this._selectedRowIds,e,this._getRowId).allSelected}isSomeSelected(e){return computeRowSelectionState(this._selectedRowIds,e,this._getRowId).someSelected}getSelectedRows(e){return e.filter(t=>this._selectedRowIds.has(this._getRowId(t)))}onRowSelectionChange(e){return this.emitter.on("rowSelectionChange",e),()=>this.emitter.off("rowSelectionChange",e)}destroy(){this.emitter.removeAllListeners();}};var Z=class{constructor(e,t){this.emitter=new x;this._pinnedColumns={};if(e&&(this._pinnedColumns={...e}),t)for(let i of t)i.pinned&&!(i.columnId in this._pinnedColumns)&&(this._pinnedColumns[i.columnId]=i.pinned);}get pinnedColumns(){return this._pinnedColumns}pinColumn(e,t){this._pinnedColumns={...this._pinnedColumns,[e]:t},this.emitter.emit("pinningChange",{pinnedColumns:this._pinnedColumns});}unpinColumn(e){let{[e]:t,...i}=this._pinnedColumns;this._pinnedColumns=i,this.emitter.emit("pinningChange",{pinnedColumns:this._pinnedColumns});}isPinned(e){return this._pinnedColumns[e]}computeLeftOffsets(e,t,i,n,r,o){let l={},a=0;n&&(a+=r),o&&(a+=ROW_NUMBER_COLUMN_WIDTH);for(let s of e)this._pinnedColumns[s.columnId]==="left"&&(l[s.columnId]=a,a+=t[s.columnId]??i);return l}computeRightOffsets(e,t,i){let n={},r=0;for(let o=e.length-1;o>=0;o--){let l=e[o];this._pinnedColumns[l.columnId]==="right"&&(n[l.columnId]=r,r+=t[l.columnId]??i);}return n}onPinningChange(e){return this.emitter.on("pinningChange",e),()=>this.emitter.off("pinningChange",e)}destroy(){this.emitter.removeAllListeners();}};var Re=36,ut=5,ht=100,J=class{constructor(e){this.emitter=new x;this._scrollTop=0;this._containerHeight=0;this._totalRows=0;this.rafId=0;this._ro=null;this._resizeRafId=0;this._cachedRange={startIndex:0,endIndex:-1,offsetTop:0,offsetBottom:0};this._scrollLeft=0;this._scrollLeftRafId=0;this._containerWidth=0;this._columnWidths=[];this._cachedColumnRange=null;this._roWidth=null;this._resizeWidthRafId=0;this._config=e??{enabled:false},validateVirtualScrollConfig(this._config);}get enabled(){let e=this._config.threshold??ht;return this._config.enabled===true&&this._totalRows>=e}get config(){return this._config}get containerHeight(){return this._containerHeight}get totalRows(){return this._totalRows}get scrollTop(){return this._scrollTop}get visibleRange(){return this._cachedRange}get totalHeight(){return computeTotalHeight(this._totalRows,this._config.rowHeight??Re)}get columnVirtualizationEnabled(){return this._config.columns===true}get columnRange(){return this._cachedColumnRange}setColumnWidths(e){this._columnWidths=e,this.recomputeColumnRange();}handleHorizontalScroll(e){this.columnVirtualizationEnabled&&(this._scrollLeftRafId&&cancelAnimationFrame(this._scrollLeftRafId),this._scrollLeftRafId=requestAnimationFrame(()=>{this._scrollLeftRafId=0,this._scrollLeft=e,this.recomputeColumnRange();}));}observeContainerWidth(e){this.disconnectWidthObserver(),typeof ResizeObserver<"u"&&(this._roWidth=new ResizeObserver(t=>{t.length!==0&&(this._containerWidth=t[0].contentRect.width,this._resizeWidthRafId&&cancelAnimationFrame(this._resizeWidthRafId),this._resizeWidthRafId=requestAnimationFrame(()=>{this._resizeWidthRafId=0,this.recomputeColumnRange();}));}),this._roWidth.observe(e)),this._containerWidth=e.clientWidth;}disconnectWidthObserver(){this._roWidth&&(this._roWidth.disconnect(),this._roWidth=null);}recomputeColumnRange(){if(!this.columnVirtualizationEnabled||this._columnWidths.length===0||this._containerWidth<=0){this._cachedColumnRange!==null&&(this._cachedColumnRange=null,this.emitter.emit("columnRangeChanged",{columnRange:null}));return}let e=this._config.columnOverscan??2,t=computeVisibleColumnRange(this._scrollLeft,this._columnWidths,this._containerWidth,e),i=this._cachedColumnRange;!i||i.startIndex!==t.startIndex||i.endIndex!==t.endIndex?(this._cachedColumnRange=t,this.emitter.emit("columnRangeChanged",{columnRange:t})):this._cachedColumnRange=t;}handleScroll(e){this.rafId&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.rafId=0,this._scrollTop=e,this.recompute();});}scrollToRow(e,t,i){let n=this._config.rowHeight??Re,r=getScrollTopForRow(e,n,this._containerHeight,i);t.scrollTop=r,this._scrollTop=r,this.recompute();}updateConfig(e){validateVirtualScrollConfig(e),this._config=e,this.recompute(),this.emitter.emit("configChanged",{config:e});}setTotalRows(e){this._totalRows=e,this.recompute();}observeContainer(e){this.disconnectObserver(),typeof ResizeObserver<"u"&&(this._ro=new ResizeObserver(t=>{t.length!==0&&(this._containerHeight=t[0].contentRect.height,this._resizeRafId&&cancelAnimationFrame(this._resizeRafId),this._resizeRafId=requestAnimationFrame(()=>{this._resizeRafId=0,this.recompute();}));}),this._ro.observe(e)),this._containerHeight=e.clientHeight;}disconnectObserver(){this._ro&&(this._ro.disconnect(),this._ro=null);}recompute(){if(!this.enabled)return;let e=this._config.rowHeight??Re,t=this._config.overscan??ut,i=computeVisibleRange(this._scrollTop,e,this._containerHeight,this._totalRows,t),n=this._cachedRange;n.startIndex!==i.startIndex||n.endIndex!==i.endIndex?(this._cachedRange=i,this.emitter.emit("rangeChanged",{visibleRange:i})):this._cachedRange=i;}onRangeChanged(e){return this.emitter.on("rangeChanged",e),()=>this.emitter.off("rangeChanged",e)}onColumnRangeChanged(e){return this.emitter.on("columnRangeChanged",e),()=>this.emitter.off("columnRangeChanged",e)}onConfigChanged(e){return this.emitter.on("configChanged",e),()=>this.emitter.off("configChanged",e)}destroy(){this.rafId&&cancelAnimationFrame(this.rafId),this._resizeRafId&&cancelAnimationFrame(this._resizeRafId),this._scrollLeftRafId&&cancelAnimationFrame(this._scrollLeftRafId),this._resizeWidthRafId&&cancelAnimationFrame(this._resizeWidthRafId),this.disconnectObserver(),this.disconnectWidthObserver(),this.emitter.removeAllListeners();}};var Q=class{constructor(){this.emitter=new x;this._activeCell=null;this._selectionRange=null;this._selectedRowIds=new Set;this._isDragging=false;this.dragStartCell=null;this.rafHandle=null;this.pendingRange=null;}get activeCell(){return this._activeCell}get dragAnchor(){return this.dragStartCell}get selectionRange(){return this._selectionRange}get selectedRowIds(){return this._selectedRowIds}get isDragging(){return this._isDragging}getDragRange(){return this.pendingRange}setActiveCell(e){this._activeCell=e,this._selectionRange=e!=null?{startRow:e.rowIndex,startCol:e.columnIndex,endRow:e.rowIndex,endCol:e.columnIndex}:null,this.emitter.emit("selectionChange",{activeCell:e,selectionRange:this._selectionRange});}setSelectionRange(e){this._selectionRange=e,this.emitter.emit("selectionChange",{activeCell:this._activeCell,selectionRange:e});}clearSelection(){this._activeCell=null,this._selectionRange=null,this.emitter.emit("selectionChange",{activeCell:null,selectionRange:null});}startDrag(e,t){this._isDragging=true,this.dragStartCell={rowIndex:e,columnIndex:t},this._activeCell={rowIndex:e,columnIndex:t},this._selectionRange={startRow:e,startCol:t,endRow:e,endCol:t};}updateDrag(e,t,i){if(!this._isDragging||!this.dragStartCell)return;let n={startRow:this.dragStartCell.rowIndex,startCol:this.dragStartCell.columnIndex,endRow:e,endCol:t};rangesEqual(this.pendingRange,n)||(this.pendingRange=n,this.rafHandle===null&&(this.rafHandle=requestAnimationFrame(()=>{this.pendingRange&&i(this.pendingRange),this.rafHandle=null;})));}endDrag(){this.rafHandle!==null&&(cancelAnimationFrame(this.rafHandle),this.rafHandle=null),this.pendingRange&&(this._selectionRange=this.pendingRange,this.pendingRange=null,this.emitter.emit("selectionChange",{activeCell:this._activeCell,selectionRange:this._selectionRange})),this._isDragging=false,this.dragStartCell=null;}setSelectedRowIds(e){this._selectedRowIds=e,this.emitter.emit("rowSelectionChange",{selectedRowIds:e});}onSelectionChange(e){return this.emitter.on("selectionChange",e),()=>this.emitter.off("selectionChange",e)}onRowSelectionChange(e){return this.emitter.on("rowSelectionChange",e),()=>this.emitter.off("rowSelectionChange",e)}destroy(){this.rafHandle!==null&&cancelAnimationFrame(this.rafHandle),this.emitter.removeAllListeners();}};var ee=class{constructor(e,t,i,n,r){this.wrapperRef=null;this.handleKeyDown=e=>{let{items:t,visibleCols:i,colOffset:n,editable:r,onCellValueChanged:o,onCopy:l,onCut:a,onPaste:s,onUndo:d,onRedo:c,onContextMenu:u,onStartEdit:m,getRowId:v,clearClipboardRanges:g,onKeyDown:S,onFillDown:p}=this.params;if(S&&(S(e),e.defaultPrevented))return;let f=this.getActiveCell(),h=this.getSelectionRange(),I=t.length-1,w=i.length-1+n;if(t.length===0)return;if(f===null){["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Tab","Enter","Home","End","PageDown","PageUp"].includes(e.key)&&(this.setActiveCell({rowIndex:0,columnIndex:n}),e.preventDefault());return}let{rowIndex:b,columnIndex:y}=f,A=y-n,E=e.shiftKey,T=(C,_)=>{if(C<0||C>=t.length||_<0||_>=i.length)return true;let F=getCellValue(t[C],i[_]);return F==null||F===""};switch(e.key){case "c":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),l?.());break;case "x":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),a?.());break;case "v":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),s?.());break;case "d":(e.ctrlKey||e.metaKey)&&r!==false&&p&&(e.preventDefault(),p());break;case "ArrowDown":case "ArrowUp":case "ArrowRight":case "ArrowLeft":{e.preventDefault();let{newRowIndex:C,newColumnIndex:_,newRange:F}=computeArrowNavigation({direction:e.key,rowIndex:b,columnIndex:y,dataColIndex:A,colOffset:n,maxRowIndex:I,maxColIndex:w,visibleColCount:i.length,isCtrl:e.ctrlKey||e.metaKey,isShift:E,selectionRange:h,isEmptyAt:T});this.setActiveCell({rowIndex:C,columnIndex:_}),this.setSelectionRange(F);break}case "Tab":{e.preventDefault();let C=computeTabNavigation(b,y,I,w,n,e.shiftKey),_=C.columnIndex-n;this.setActiveCell({rowIndex:C.rowIndex,columnIndex:C.columnIndex}),this.setSelectionRange({startRow:C.rowIndex,startCol:_,endRow:C.rowIndex,endCol:_});break}case "Home":{e.preventDefault();let C=e.ctrlKey?0:b;this.setActiveCell({rowIndex:C,columnIndex:n}),this.setSelectionRange({startRow:C,startCol:0,endRow:C,endCol:0});break}case "End":{e.preventDefault();let C=e.ctrlKey?I:b;this.setActiveCell({rowIndex:C,columnIndex:w}),this.setSelectionRange({startRow:C,startCol:i.length-1,endRow:C,endCol:i.length-1});break}case "PageDown":case "PageUp":{e.preventDefault();let C=this.wrapperRef,_=10,F=36;if(C){let O=C.querySelector("tbody tr");O&&O.offsetHeight>0&&(F=O.offsetHeight,_=Math.max(1,Math.floor(C.clientHeight/F)));}let H=e.key==="PageDown"?1:-1,D=Math.max(0,Math.min(b+H*_,I));e.shiftKey?this.setSelectionRange({startRow:h?.startRow??b,startCol:h?.startCol??A,endRow:D,endCol:h?.endCol??A}):this.setSelectionRange({startRow:D,startCol:A,endRow:D,endCol:A}),this.setActiveCell({rowIndex:D,columnIndex:y}),C&&(C.scrollTop=getScrollTopForRow(D,F,C.clientHeight,"center"));break}case "Enter":case "F2":{if(e.preventDefault(),A>=0&&A<i.length){let C=i[A],_=t[b];if(_&&C){let F=C.editable===true||typeof C.editable=="function"&&C.editable(_);r!==false&&F&&m?.(v(_),C.columnId);}}break}case "Escape":e.preventDefault(),g?.(),this.setActiveCell(null),this.setSelectionRange(null);break;case "z":(e.ctrlKey||e.metaKey)&&(e.shiftKey&&c?(e.preventDefault(),c()):!e.shiftKey&&d&&(e.preventDefault(),d()));break;case "y":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),c?.());break;case "a":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),t.length>0&&i.length>0&&(this.setActiveCell({rowIndex:0,columnIndex:n}),this.setSelectionRange({startRow:0,startCol:0,endRow:t.length-1,endCol:i.length-1})));break;case "Delete":case "Backspace":{if(r===false||o==null)break;let C=h??(f!=null?{startRow:f.rowIndex,startCol:f.columnIndex-n,endRow:f.rowIndex,endCol:f.columnIndex-n}:null);if(C==null)break;e.preventDefault();let _=applyCellDeletion(C,t,i);for(let F of _)o(F);break}case "F10":if(e.shiftKey)if(e.preventDefault(),f!=null&&this.wrapperRef){let C=`[data-row-index="${f.rowIndex}"][data-col-index="${f.columnIndex}"]`,_=this.wrapperRef.querySelector(C);if(_){let F=_.getBoundingClientRect();u?.(F.left+F.width/2,F.top+F.height/2);}else u?.(100,100);}else u?.(100,100);break;}};this.params=e,this.getActiveCell=t,this.getSelectionRange=i,this.setActiveCell=n,this.setSelectionRange=r;}setWrapperRef(e){this.wrapperRef=e;}updateParams(e){this.params=e;}};var te=class{constructor(e,t,i){this.emitter=new x;this._cutRange=null;this._copyRange=null;this.internalClipboard=null;this.params=e,this.getActiveCell=t,this.getSelectionRange=i;}updateParams(e){this.params=e;}get cutRange(){return this._cutRange}get copyRange(){return this._copyRange}getEffectiveRange(){let e=this.getSelectionRange(),t=this.getActiveCell();return e??(t!=null?{startRow:t.rowIndex,startCol:t.columnIndex-this.params.colOffset,endRow:t.rowIndex,endCol:t.columnIndex-this.params.colOffset}:null)}handleCopy(){let e=this.getEffectiveRange();if(e==null)return;let t=normalizeSelectionRange(e),{items:i,visibleCols:n,formulas:r,flatColumns:o,getFormula:l,hasFormula:a,colOffset:s}=this.params,c=formatSelectionAsTsv(i,n,t,r&&o?{colOffset:s,flatColumns:o,getFormula:l,hasFormula:a}:void 0);this.internalClipboard=c,this._copyRange=t,this._cutRange=null,this.emitter.emit("rangesChange",{copyRange:this._copyRange,cutRange:null}),typeof navigator<"u"&&navigator.clipboard&&navigator.clipboard.writeText(c).catch(()=>{});}handleCut(){if(this.params.editable===false)return;let e=this.getEffectiveRange();if(e==null)return;let t=normalizeSelectionRange(e);this._cutRange=t,this._copyRange=null,this.handleCopy(),this._copyRange=null,this._cutRange=t,this.emitter.emit("rangesChange",{copyRange:null,cutRange:this._cutRange});}async handlePaste(){if(this.params.editable===false)return;let{onCellValueChanged:e}=this.params,t;try{typeof navigator<"u"&&navigator.clipboard?t=await navigator.clipboard.readText():t="";}catch{t="";}if(!t.trim()&&this.internalClipboard!=null&&(t=this.internalClipboard),!t.trim()||e==null)return;let i=this.getEffectiveRange(),n=i?i.startRow:0,r=i?i.startCol:0,{items:o,visibleCols:l,formulas:a,flatColumns:s,setFormula:d,colOffset:c}=this.params,u=a&&s?{colOffset:c,flatColumns:s,setFormula:d}:void 0,m=parseTsvClipboard(t),v=applyPastedValues(m,n,r,o,l,u);for(let g of v)e(g);if(this._cutRange){let g=applyCutClear(this._cutRange,o,l);for(let S of g)e(S);this._cutRange=null;}this._copyRange=null,this.emitter.emit("rangesChange",{copyRange:null,cutRange:null});}clearClipboardRanges(){this._copyRange=null,this._cutRange=null,this.emitter.emit("rangesChange",{copyRange:null,cutRange:null});}onRangesChange(e){return this.emitter.on("rangesChange",e),()=>this.emitter.off("rangesChange",e)}destroy(){this.emitter.removeAllListeners();}};var ie=class{constructor(e,t=100){this.onCellValueChanged=e;this.emitter=new x;this.stack=new UndoRedoStack(t),e&&(this.wrappedCallback=i=>{this.stack.record(i),this.stack.isBatching||this.emitStackChange(),e(i);});}get canUndo(){return this.stack.canUndo}get canRedo(){return this.stack.canRedo}getWrappedCallback(){return this.wrappedCallback}beginBatch(){this.stack.beginBatch();}endBatch(){this.stack.endBatch(),this.emitStackChange();}undo(){if(!this.onCellValueChanged)return;let e=this.stack.undo();if(e){this.emitStackChange();for(let t=e.length-1;t>=0;t--){let i=e[t];this.onCellValueChanged({...i,oldValue:i.newValue,newValue:i.oldValue});}}}redo(){if(!this.onCellValueChanged)return;let e=this.stack.redo();if(e){this.emitStackChange();for(let t of e)this.onCellValueChanged(t);}}emitStackChange(){this.emitter.emit("stackChange",{canUndo:this.canUndo,canRedo:this.canRedo});}onStackChange(e){return this.emitter.on("stackChange",e),()=>this.emitter.off("stackChange",e)}destroy(){this.emitter.removeAllListeners();}};var ne=class{constructor(){this.emitter=new x;this.columnWidths=new Map;this.isResizing=false;this.resizeColumnId=null;this.resizeStartX=0;this.resizeStartWidth=0;}get resizingColumnId(){return this.resizeColumnId}getColumnWidth(e){return this.columnWidths.get(e)}getAllColumnWidths(){let e={};return this.columnWidths.forEach((t,i)=>{e[i]=t;}),e}startResize(e,t,i){this.isResizing=true,this.resizeColumnId=e,this.resizeStartX=t,this.resizeStartWidth=i;}updateResize(e){if(!this.isResizing||!this.resizeColumnId)return null;let t=e-this.resizeStartX,i=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH;return Math.max(i,this.resizeStartWidth+t)}endResize(e){if(!this.isResizing||!this.resizeColumnId)return;let t=e-this.resizeStartX,i=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH,n=Math.max(i,this.resizeStartWidth+t);this.columnWidths.set(this.resizeColumnId,n),this.emitter.emit("columnWidthChange",{columnId:this.resizeColumnId,widthPx:n}),this.isResizing=false,this.resizeColumnId=null;}setColumnWidth(e,t){this.columnWidths.set(e,t),this.emitter.emit("columnWidthChange",{columnId:e,widthPx:t});}onColumnWidthChange(e){return this.emitter.on("columnWidthChange",e),()=>this.emitter.off("columnWidthChange",e)}destroy(){this.emitter.removeAllListeners();}};var oe=class{constructor(e,t,i,n){this.emitter=new x;this.wrapperRef=null;this._isFillDragging=false;this.fillDragStart=null;this.fillDragEnd={endRow:0,endCol:0};this.rafHandle=0;this.liveFillRange=null;this.lastMousePos=null;this.cachedCells=null;this.params=e,this.getSelectionRange=t,this.setSelectionRange=i,this.setActiveCell=n,this.onMoveBound=this.onMouseMove.bind(this),this.onUpBound=this.onMouseUp.bind(this);}get isFillDragging(){return this._isFillDragging}get fillRange(){return this.liveFillRange}setWrapperRef(e){this.wrapperRef=e;}updateParams(e){this.params=e;}fillDown(){let e=this.getSelectionRange();if(!e||this.params.editable===false||!this.params.onCellValueChanged)return;let t=normalizeSelectionRange(e);this.applyFillValuesFromCore(t,{startRow:t.startRow,startCol:t.startCol});}startFillDrag(e){e.preventDefault(),e.stopPropagation();let t=this.getSelectionRange();t&&(this.params.editable===false||!this.params.onCellValueChanged||(this._isFillDragging=true,this.fillDragStart={startRow:t.startRow,startCol:t.startCol},this.fillDragEnd={endRow:t.startRow,endCol:t.startCol},this.liveFillRange=null,this.cachedCells=this.wrapperRef?this.wrapperRef.querySelectorAll("[data-row-index][data-col-index]"):null,window.addEventListener("pointermove",this.onMoveBound,{capture:true,passive:true}),window.addEventListener("pointerup",this.onUpBound,{capture:true,passive:true})));}onMouseMove(e){!this._isFillDragging||!this.fillDragStart||(this.lastMousePos={cx:e.clientX,cy:e.clientY},this.rafHandle&&cancelAnimationFrame(this.rafHandle),this.rafHandle=requestAnimationFrame(()=>{if(this.rafHandle=0,!this.lastMousePos)return;let t=this.resolveRange(this.lastMousePos.cx,this.lastMousePos.cy);if(!t)return;let i=this.liveFillRange;i&&i.startRow===t.startRow&&i.startCol===t.startCol&&i.endRow===t.endRow&&i.endCol===t.endCol||(this.liveFillRange=t,this.fillDragEnd={endRow:t.endRow,endCol:t.endCol},this.applyDragAttrs(t));}));}onMouseUp(){if(!this._isFillDragging||!this.fillDragStart)return;if(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true),this.rafHandle&&(cancelAnimationFrame(this.rafHandle),this.rafHandle=0),this.lastMousePos){let n=this.resolveRange(this.lastMousePos.cx,this.lastMousePos.cy);n&&(this.liveFillRange=n,this.fillDragEnd={endRow:n.endRow,endCol:n.endCol});}this.clearDragAttrs();let e=this.fillDragStart,t=this.fillDragEnd,i=normalizeSelectionRange({startRow:e.startRow,startCol:e.startCol,endRow:t.endRow,endCol:t.endCol});this.setSelectionRange(i),this.setActiveCell({rowIndex:e.startRow,columnIndex:e.startCol+this.params.colOffset}),this.applyFillValuesFromCore(i,e),this._isFillDragging=false,this.fillDragStart=null,this.liveFillRange=null,this.lastMousePos=null,this.emitter.emit("fillRangeChange",{fillRange:null});}applyFillValuesFromCore(e,t){let{items:i,visibleCols:n,onCellValueChanged:r,beginBatch:o,endBatch:l,formulaOptions:a}=this.params;if(!r)return;let s=applyFillValues(e,t.startRow,t.startCol,i,n,a);if(s.length>0){o?.();for(let d of s)r(d);l?.();}}resolveRange(e,t){if(!this.fillDragStart||!this.wrapperRef)return null;let n=document.elementFromPoint(e,t)?.closest?.("[data-row-index][data-col-index]");if(!n||!this.wrapperRef.contains(n))return null;let r=L(n);if(!r||r.colIndex<this.params.colOffset)return null;let o=r.rowIndex,l=r.colIndex-this.params.colOffset;return normalizeSelectionRange({startRow:this.fillDragStart.startRow,startCol:this.fillDragStart.startCol,endRow:o,endCol:l})}applyDragAttrs(e){let t=this.cachedCells;if(!t)return;let i=this.params.colOffset,n=Math.min(e.startRow,e.endRow),r=Math.max(e.startRow,e.endRow),o=Math.min(e.startCol,e.endCol),l=Math.max(e.startCol,e.endCol);for(let a=0;a<t.length;a++){let s=t[a],d=L(s);if(!d)continue;let c=d.rowIndex,u=d.colIndex-i;c>=n&&c<=r&&u>=o&&u<=l?s.hasAttribute("data-drag-range")||s.setAttribute("data-drag-range",""):s.hasAttribute("data-drag-range")&&s.removeAttribute("data-drag-range");}}clearDragAttrs(){let e=this.cachedCells;if(e)for(let t=0;t<e.length;t++)e[t].removeAttribute("data-drag-range");this.cachedCells=null;}onFillRangeChange(e){return this.emitter.on("fillRangeChange",e),()=>this.emitter.off("fillRangeChange",e)}destroy(){this._isFillDragging&&(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true),this.clearDragAttrs(),this._isFillDragging=false,this.fillDragStart=null,this.liveFillRange=null,this.lastMousePos=null),this.rafHandle&&(cancelAnimationFrame(this.rafHandle),this.rafHandle=0),this.emitter.removeAllListeners();}};var re=class{constructor(){this.emitter=new x;this._isDragging=false;this._draggedColumnId=null;this._dropIndicatorX=null;this._dropTargetIndex=null;this.rafId=0;this.columnOrder=[];this.draggedPinState="unpinned";this.tableElement=null;this.onMoveBound=this.handleMouseMove.bind(this),this.onUpBound=this.handleMouseUp.bind(this);}get isDragging(){return this._isDragging}get dropIndicatorX(){return this._dropIndicatorX}startDrag(e,t,i,n,r,o){if(t.preventDefault(),this._isDragging=true,this._draggedColumnId=e,this._dropIndicatorX=null,this._dropTargetIndex=null,this.tableElement=o,this.columnOrder=n.length>0?[...n]:i.map(l=>l.columnId),r){let l=[],a=[];for(let[s,d]of Object.entries(r))d==="left"?l.push(s):d==="right"&&a.push(s);this.pinnedColumns={left:l,right:a};}else this.pinnedColumns=void 0;this.draggedPinState=getPinStateForColumn(e,this.pinnedColumns),window.addEventListener("pointermove",this.onMoveBound,{capture:true,passive:true}),window.addEventListener("pointerup",this.onUpBound,{capture:true,passive:true}),this.emitter.emit("stateChange",{isDragging:true,dropIndicatorX:null});}handleMouseMove(e){if(!this._isDragging||!this._draggedColumnId||!this.tableElement)return;this.rafId&&cancelAnimationFrame(this.rafId);let t=e.clientX;this.rafId=requestAnimationFrame(()=>{if(this.rafId=0,!this._draggedColumnId||!this.tableElement)return;let i=calculateDropTarget({mouseX:t,columnOrder:this.columnOrder,draggedColumnId:this._draggedColumnId,draggedPinState:this.draggedPinState,tableElement:this.tableElement,pinnedColumns:this.pinnedColumns});if(!i)return;let n=this._dropIndicatorX,r=this._dropTargetIndex;this._dropTargetIndex=i.targetIndex,this._dropIndicatorX=i.indicatorX,(n!==i.indicatorX||r!==i.targetIndex)&&this.emitter.emit("stateChange",{isDragging:true,dropIndicatorX:i.indicatorX});});}handleMouseUp(){if(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true),this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=0),this._isDragging&&this._draggedColumnId&&this._dropTargetIndex!==null&&this._dropIndicatorX!==null){let e=reorderColumnArray(this.columnOrder,this._draggedColumnId,this._dropTargetIndex);this.emitter.emit("reorder",{columnOrder:e});}this._isDragging=false,this._draggedColumnId=null,this._dropIndicatorX=null,this._dropTargetIndex=null,this.tableElement=null,this.emitter.emit("stateChange",{isDragging:false,dropIndicatorX:null});}onStateChange(e){return this.emitter.on("stateChange",e),()=>this.emitter.off("stateChange",e)}onReorder(e){return this.emitter.on("reorder",e),()=>this.emitter.off("reorder",e)}destroy(){this._isDragging&&(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true)),this.rafId&&cancelAnimationFrame(this.rafId),this.emitter.removeAllListeners();}};function Ve(R,e,t){let i=measureRange(R,e,t);return i?{top:i.top+R.scrollTop,left:i.left+R.scrollLeft,width:i.width,height:i.height}:null}var le=class{constructor(e,t=0){this.selSvg=null;this.clipSvg=null;this.selectionRange=null;this.copyRange=null;this.cutRange=null;this.rafHandle=0;this.layoutVersion=0;this.container=e,this.colOffset=t,injectGlobalStyles("ogrid-marching-ants-keyframes","@keyframes ogrid-marching-ants{to{stroke-dashoffset:-8}}");let i=getComputedStyle(e).position;(i==="static"||i==="")&&(e.style.position="relative");}update(e,t,i,n){let r=n!==void 0&&n!==this.layoutVersion;r&&n!==void 0&&(this.layoutVersion=n),!(!r&&rangesEqual(this.selectionRange,e)&&rangesEqual(this.copyRange,t)&&rangesEqual(this.cutRange,i))&&(this.selectionRange=e,this.copyRange=t,this.cutRange=i,this.rafHandle&&cancelAnimationFrame(this.rafHandle),this.rafHandle=requestAnimationFrame(()=>{this.rafHandle=0,this.render();}));}render(){let e=this.copyRange??this.cutRange,t=this.selectionRange?Ve(this.container,this.selectionRange,this.colOffset):null,i=this.selectionRange!=null&&e!=null&&rangesEqual(this.selectionRange,e),n=this.selectionRange!=null&&this.selectionRange.startRow===this.selectionRange.endRow&&this.selectionRange.startCol===this.selectionRange.endCol;if(t&&!i&&!n){this.selSvg||(this.selSvg=this.createSvg(4),this.container.appendChild(this.selSvg)),this.positionSvg(this.selSvg,t);let o=this.selSvg.querySelector("rect");o&&(o.setAttribute("width",String(Math.max(0,t.width-2))),o.setAttribute("height",String(Math.max(0,t.height-2))),o.setAttribute("stroke","var(--ogrid-selection, #217346)"),o.setAttribute("stroke-width","2"),o.removeAttribute("stroke-dasharray"),o.style.animation="");}else this.removeSvg("sel");let r=e?Ve(this.container,e,this.colOffset):null;if(r){this.clipSvg||(this.clipSvg=this.createSvg(5),this.container.appendChild(this.clipSvg)),this.positionSvg(this.clipSvg,r);let o=this.clipSvg.querySelector("rect");o&&(o.setAttribute("width",String(Math.max(0,r.width-2))),o.setAttribute("height",String(Math.max(0,r.height-2))),o.setAttribute("stroke","var(--ogrid-selection, #217346)"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-dasharray","4 4"),o.style.animation="ogrid-marching-ants 0.5s linear infinite");}else this.removeSvg("clip");}createSvg(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("aria-hidden","true"),t.style.position="absolute",t.style.pointerEvents="none",t.style.zIndex=String(e),t.style.overflow="visible";let i=document.createElementNS("http://www.w3.org/2000/svg","rect");return i.setAttribute("x","1"),i.setAttribute("y","1"),i.setAttribute("fill","none"),t.appendChild(i),t}positionSvg(e,t){e.style.top=`${t.top}px`,e.style.left=`${t.left}px`,e.style.width=`${t.width}px`,e.style.height=`${t.height}px`;}removeSvg(e){e==="sel"&&this.selSvg?(this.selSvg.remove(),this.selSvg=null):e==="clip"&&this.clipSvg&&(this.clipSvg.remove(),this.clipSvg=null);}destroy(){this.rafHandle&&cancelAnimationFrame(this.rafHandle),this.removeSvg("sel"),this.removeSvg("clip");}};var fe={position:"absolute",zIndex:"1000",boxSizing:"border-box",border:"2px solid var(--ogrid-selection, #217346)",background:"var(--ogrid-bg, #fff)",color:"var(--ogrid-fg, #242424)",outline:"none",fontFamily:"inherit",fontSize:"inherit"},se=class{constructor(e){this.editor=null;this.editingCell=null;this.editingCellElement=null;this.onCommit=null;this.onCancel=null;this.onAfterCommit=null;this.scrollCleanup=null;this.container=e;}startEdit(e,t,i,n,r,o,l,a,s){this.closeEditor(),this.editingCell={rowId:e,columnId:t},this.editingCellElement=r,this.onCommit=o,this.onCancel=l,this.onAfterCommit=a??null;let d=s!==void 0?s:getCellValue(i,n),c=r.getBoundingClientRect(),u=this.container.getBoundingClientRect(),m=this.createEditor(n,i,d,r);m.style.position="absolute",m.style.left=`${c.left-u.left+this.container.scrollLeft}px`,m.style.top=`${c.top-u.top+this.container.scrollTop}px`,m.style.width=`${c.width}px`,m.style.height=`${c.height}px`,this.editor=m,this.container.appendChild(m),m.focus();let v=m.querySelector('[role="listbox"]');if(v){let S=window.innerHeight-c.bottom,p=S<200&&c.top>S;v.style.position="fixed",v.style.left=`${c.left}px`,v.style.width=`${c.width}px`,v.style.maxHeight="200px",v.style.zIndex="9999",v.style.right="auto",p?(v.style.top="auto",v.style.bottom=`${window.innerHeight-c.top}px`):v.style.top=`${c.bottom}px`;let f=m.closest("[data-ogrid-scroll-container]")??m.closest('[style*="overflow"]'),h=()=>this.closeEditor(),I=requestAnimationFrame(()=>{f&&f.addEventListener("scroll",h,{passive:true}),window.addEventListener("scroll",h,{passive:true});});this.scrollCleanup=()=>{cancelAnimationFrame(I),f&&f.removeEventListener("scroll",h),window.removeEventListener("scroll",h);};}}getEditingCell(){return this.editingCell}closeEditor(){if(this.scrollCleanup?.(),this.scrollCleanup=null,this.editingCell&&this.container.isConnected){let{rowId:e,columnId:t}=this.editingCell,i=this.container.querySelector(`tr[data-row-id="${e}"]`);if(i){let n=i.querySelector(`td[data-column-id="${t}"]`);n&&(n.style.visibility="");}}this.editingCellElement&&(this.editingCellElement.isConnected&&(this.editingCellElement.style.visibility=""),this.editingCellElement=null),this.editor&&(this.editor.remove(),this.editor=null),this.editingCell=null,this.onCommit=null,this.onCancel=null,this.onAfterCommit=null;}createEditor(e,t,i,n){let r=e.cellEditor;if(typeof r=="function"){let o={value:i,onValueChange:l=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,l);},onCommit:()=>this.closeEditor(),onCancel:()=>{this.onCancel?.(),this.closeEditor();},item:t,column:e,cell:n,cellEditorParams:e.cellEditorParams};return r(o)}return r==="checkbox"||e.type==="boolean"?this.createCheckboxEditor(i):r==="select"?this.createSelectEditor(i,e):r==="richSelect"?this.createRichSelectEditor(i,e):r==="date"||e.type==="date"?this.createDateEditor(i):this.createTextEditor(i)}createInputEditor(e,t){let i=document.createElement("input");return i.type=e,i.value=t,Object.assign(i.style,fe),i.addEventListener("keydown",n=>{if(n.key==="Enter"){n.preventDefault(),n.stopPropagation(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i.value);let r=this.onAfterCommit;this.closeEditor(),r?.();}else n.key==="Escape"?(n.preventDefault(),n.stopPropagation(),this.onCancel?.(),this.closeEditor()):(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(n.key)||(n.ctrlKey||n.metaKey)&&["c","x","v","a","z","y"].includes(n.key))&&n.stopPropagation();}),i.addEventListener("blur",()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i.value),this.closeEditor();}),setTimeout(()=>i.select(),0),i}createTextEditor(e){return this.createInputEditor("text",e!=null?String(e):"")}createCheckboxEditor(e){let t=document.createElement("input");return t.type="checkbox",t.checked=!!e,Object.assign(t.style,fe),t.style.width="20px",t.style.height="20px",t.addEventListener("change",()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,t.checked),this.closeEditor();}),t.addEventListener("keydown",i=>{i.key==="Escape"?(i.preventDefault(),i.stopPropagation(),this.onCancel?.(),this.closeEditor()):["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(i.key)&&i.stopPropagation();}),t}createDateEditor(e){let t="";if(e!=null){let i=String(e);i.match(/^\d{4}-\d{2}-\d{2}/)&&(t=i.substring(0,10));}return this.createInputEditor("date",t)}createSelectEditor(e,t){let i=t.cellEditorParams?.values??[],n=t.cellEditorParams?.formatValue,r=g=>n?n(g):g!=null?String(g):"",o=document.createElement("div");Object.assign(o.style,fe),o.style.padding="6px 10px",o.style.display="flex",o.style.alignItems="center",o.tabIndex=0;let l=document.createElement("div");l.style.display="flex",l.style.alignItems="center",l.style.justifyContent="space-between",l.style.width="100%",l.style.cursor="pointer",l.style.fontSize="13px";let a=document.createElement("span");a.textContent=r(e),l.appendChild(a);let s=document.createElement("span");s.textContent="\u25BE",s.style.marginLeft="4px",s.style.fontSize="10px",s.style.opacity="0.5",l.appendChild(s),o.appendChild(l);let d=document.createElement("div");d.setAttribute("role","listbox"),d.style.position="absolute",d.style.top="100%",d.style.left="0",d.style.right="0",d.style.maxHeight="200px",d.style.overflowY="auto",d.style.backgroundColor="var(--ogrid-bg, #fff)",d.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",d.style.zIndex="1001",d.style.boxShadow="0 4px 16px rgba(0,0,0,0.2)",d.style.textAlign="left",o.appendChild(d);let c=Math.max(i.findIndex(g=>String(g)===String(e)),0),u=()=>{d.innerHTML="";for(let g=0;g<i.length;g++){let S=i[g],p=document.createElement("div");p.setAttribute("role","option"),p.setAttribute("aria-selected",String(g===c)),p.textContent=r(S),p.style.padding="6px 8px",p.style.cursor="pointer",p.style.color="var(--ogrid-fg, #242424)",g===c&&(p.style.background="var(--ogrid-bg-hover, #e8f0fe)"),p.addEventListener("mousedown",f=>{f.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,S),this.closeEditor();}),d.appendChild(p);}},m=(g,S)=>{let p=d.children[g],f=d.children[S];p&&(p.style.background="",p.setAttribute("aria-selected","false")),f&&(f.style.background="var(--ogrid-bg-hover, #e8f0fe)",f.setAttribute("aria-selected","true"));},v=()=>{d.children[c]?.scrollIntoView({block:"nearest"});};return u(),o.addEventListener("keydown",g=>{switch(g.stopPropagation(),g.key){case "ArrowDown":{g.preventDefault();let S=c;c=Math.min(c+1,i.length-1),m(S,c),v();break}case "ArrowUp":{g.preventDefault();let S=c;c=Math.max(c-1,0),m(S,c),v();break}case "Enter":if(g.preventDefault(),g.stopPropagation(),i.length>0&&c<i.length){this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i[c]);let S=this.onAfterCommit;this.closeEditor(),S?.();}break;case "Tab":g.preventDefault(),i.length>0&&c<i.length&&(this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i[c]),this.closeEditor());break;case "Escape":g.preventDefault(),g.stopPropagation(),this.onCancel?.(),this.closeEditor();break}}),o}createRichSelectEditor(e,t){let i=document.createElement("div");Object.assign(i.style,fe),i.style.padding="0";let n=document.createElement("input");n.type="text",n.value=e!=null?String(e):"",n.style.width="100%",n.style.border="none",n.style.outline="none",n.style.padding="4px",n.style.boxSizing="border-box",n.style.background="var(--ogrid-bg, #fff)",n.style.color="var(--ogrid-fg, rgba(0, 0, 0, 0.87))",i.appendChild(n);let r=document.createElement("div");r.style.position="absolute",r.style.top="100%",r.style.left="0",r.style.width="100%",r.style.maxHeight="200px",r.style.overflowY="auto",r.style.backgroundColor="var(--ogrid-bg, #fff)",r.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",r.style.zIndex="1001",r.style.textAlign="left",i.appendChild(r);let o=t.cellEditorParams?.values??[],l=t.cellEditorParams?.formatValue??(s=>String(s)),a=s=>{r.innerHTML="";let d=o.filter(c=>String(l(c)).toLowerCase().includes(s.toLowerCase()));for(let c of d){let u=document.createElement("div");u.textContent=String(l(c)),u.style.padding="4px 8px",u.style.cursor="pointer",u.addEventListener("mousedown",m=>{m.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,c),this.closeEditor();}),u.addEventListener("mouseenter",()=>{u.style.backgroundColor="var(--ogrid-hover-bg, rgba(0, 0, 0, 0.04))";},{passive:true}),u.addEventListener("mouseleave",()=>{u.style.backgroundColor="var(--ogrid-bg, #fff)";},{passive:true}),r.appendChild(u);}};return n.addEventListener("input",()=>{a(n.value);}),n.addEventListener("keydown",s=>{if(s.key==="Enter"){s.preventDefault(),s.stopPropagation(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value);let d=this.onAfterCommit;this.closeEditor(),d?.();}else s.key==="Escape"?(s.preventDefault(),s.stopPropagation(),this.onCancel?.(),this.closeEditor()):(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(s.key)||(s.ctrlKey||s.metaKey)&&["c","x","v","a","z","y"].includes(s.key))&&s.stopPropagation();}),n.addEventListener("blur",s=>{let d=s.relatedTarget;d&&this.editor?.contains(d)||(this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value),this.closeEditor());}),a(""),setTimeout(()=>n.select(),0),i}destroy(){this.closeEditor();}};var Dt={position:"fixed",backgroundColor:"var(--ogrid-bg, #fff)",border:"1px solid var(--ogrid-border, #e0e0e0)",boxShadow:"var(--ogrid-shadow, 0 4px 16px rgba(0, 0, 0, 0.12))",borderRadius:"6px",zIndex:"10000",minWidth:"180px",padding:"4px 0",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"14px",color:"var(--ogrid-fg, #242424)"},Lt={padding:"6px 12px",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},Mt={height:"1px",backgroundColor:"var(--ogrid-border, #e0e0e0)",margin:"4px 0"},ae=class{constructor(){this.menu=null;this.handlers=null;}show(e,t,i,n,r,o){this.close(),this.handlers=i,this.menu=document.createElement("div"),Object.assign(this.menu.style,Dt),this.menu.style.left=`${e}px`,this.menu.style.top=`${t}px`;for(let a of GRID_CONTEXT_MENU_ITEMS){if(a.dividerBefore){let u=document.createElement("div");Object.assign(u.style,Mt),this.menu.appendChild(u);}let s=document.createElement("div");Object.assign(s.style,Lt);let d=document.createElement("span");if(d.textContent=a.label,s.appendChild(d),a.shortcut){let u=document.createElement("span");u.textContent=formatShortcut(a.shortcut),u.style.marginLeft="20px",u.style.color="var(--ogrid-muted, #666)",u.style.fontSize="12px",s.appendChild(u);}a.id==="undo"&&!n||a.id==="redo"&&!r||a.disabledWhenNoSelection&&o==null?(s.style.color="var(--ogrid-fg-muted, rgba(0, 0, 0, 0.4))",s.style.opacity="0.5",s.style.cursor="not-allowed"):(s.addEventListener("mouseenter",()=>{s.style.backgroundColor="var(--ogrid-bg-hover, #f5f5f5)";},{passive:true}),s.addEventListener("mouseleave",()=>{s.style.backgroundColor="";},{passive:true}),s.addEventListener("click",()=>{this.handleItemClick(a.id);},{passive:true})),this.menu.appendChild(s);}document.body.appendChild(this.menu);let l=a=>{this.menu&&!this.menu.contains(a.target)&&(this.close(),document.removeEventListener("mousedown",l));};setTimeout(()=>{document.addEventListener("mousedown",l,{passive:true});},0);}close(){this.menu&&(this.menu.remove(),this.menu=null),this.handlers=null;}handleItemClick(e){if(this.handlers){switch(e){case "undo":this.handlers.onUndo();break;case "redo":this.handlers.onRedo();break;case "copy":this.handlers.onCopy();break;case "cut":this.handlers.onCut();break;case "paste":this.handlers.onPaste();break;case "selectAll":this.handlers.onSelectAll();break}this.close();}}destroy(){this.close();}};var de=class{initializeInteraction(e,t,i,n,r,o,l,a){let{editable:s}=e,d=o?1:0,c=[],u=new Q,m=new ne,v=new ae,g=new se(n),S=e.onCellValueChanged,p=new ie(S),f=new te({items:[],visibleCols:[],colOffset:d,editable:s,onCellValueChanged:p.getWrappedCallback()},()=>u.activeCell??null,()=>u.selectionRange??null),h=new oe({items:[],visibleCols:[],editable:s,onCellValueChanged:p.getWrappedCallback(),colOffset:d,beginBatch:()=>p.beginBatch(),endBatch:()=>p.endBatch()},()=>u.selectionRange??null,E=>{u.setSelectionRange(E),a.updateRendererInteractionState();},E=>{u.setActiveCell(E);}),I=new ee({items:[],visibleCols:[],colOffset:d,getRowId:t.getRowId,editable:s,onCellValueChanged:p.getWrappedCallback(),onCopy:()=>f.handleCopy(),onCut:()=>f.handleCut(),onPaste:async()=>{await f.handlePaste();},onUndo:()=>p.undo(),onRedo:()=>p.redo(),onContextMenu:(E,T)=>a.showContextMenu(E,T),onStartEdit:(E,T)=>a.startCellEdit(E,T),clearClipboardRanges:()=>f.clearClipboardRanges()},()=>u.activeCell??null,()=>u.selectionRange??null,E=>u.setActiveCell(E),E=>u.setSelectionRange(E));c.push(u.onSelectionChange(()=>{a.updateRendererInteractionState();})),c.push(f.onRangesChange(()=>{a.updateRendererInteractionState();})),c.push(m.onColumnWidthChange(()=>{a.updateRendererInteractionState();}));let w=new re;c.push(w.onStateChange(({isDragging:E,dropIndicatorX:T})=>{i.updateDropIndicator(T,E);})),c.push(w.onReorder(({columnOrder:E})=>{t.setColumnOrder(E);}));let b=i.getWrapperElement(),y=null;b&&(b.addEventListener("keydown",I.handleKeyDown),I.setWrapperRef(b),h.setWrapperRef(b),y=new le(b,d));let A=this.attachGlobalHandlers(u,m,r,i,a);return c.push(...A),{selectionState:u,keyboardNavState:I,clipboardState:f,undoRedoState:p,resizeState:m,fillHandleState:h,reorderState:w,marchingAnts:y,cellEditor:g,contextMenu:v,unsubscribes:c}}attachGlobalHandlers(e,t,i,n,r){let o=[],l=false,a=c=>{if(l&&t){let u=t.updateResize(c.clientX);u!==null&&t.resizingColumnId&&(i.setColumnOverride(t.resizingColumnId,u),r.updateRendererInteractionState());}if(e?.isDragging){let u=c.target;if(u.tagName==="TD"){let m=L(u);m&&m.rowIndex>=0&&m.colIndex>=0&&e.updateDrag(m.rowIndex,m.colIndex,()=>r.updateDragAttributes());}}},s=c=>{if(l&&t){let u=t.resizingColumnId;if(t.endResize(c.clientX),u){let m=t.getColumnWidth(u);m&&i.setColumnOverride(u,m);}l=false,document.body.style.cursor="",r.updateRendererInteractionState();}e?.isDragging&&(e.endDrag(),r.clearCachedDragCells());},d=(c,u,m)=>{l=true,document.body.style.cursor="col-resize",t.startResize(c,u,m);};return document.addEventListener("pointermove",a,{passive:true}),document.addEventListener("pointerup",s,{passive:true}),o.push(()=>{document.removeEventListener("pointermove",a),document.removeEventListener("pointerup",s);}),n.setInteractionState({activeCell:null,selectionRange:null,copyRange:null,cutRange:null,editingCell:null,columnWidths:{},onResizeStart:d}),o}};var ce=class{constructor(e){this.layoutVersion=0;this.cachedDragCells=null;this.ctx=e;}incrementLayoutVersion(){this.layoutVersion++;}clearCachedDragCells(){this.cachedDragCells=null;}getLayoutVersion(){return this.layoutVersion}updateRendererInteractionState(){let{selectionState:e,clipboardState:t,resizeState:i,state:n,layoutState:r,pinningState:o,rowSelectionState:l,cellEditor:a,renderer:s,reorderState:d,marchingAnts:c,fillHandleState:u,options:m}=this.ctx;if(!e||!t||!i)return;let{items:v}=n.getProcessedItems(),g=n.visibleColumnDefs,S=r.getAllColumnWidths(),p=o?.computeLeftOffsets(g,S,120,!!l,CHECKBOX_COLUMN_WIDTH,!!m.showRowNumbers)??{},f=o?.computeRightOffsets(g,S,120)??{};s.setInteractionState({activeCell:e.activeCell,selectionRange:e.selectionRange,copyRange:t.copyRange,cutRange:t.cutRange,editingCell:a?.getEditingCell()??null,columnWidths:S,onCellClick:h=>this.ctx.handleCellClick(h.rowIndex,h.colIndex),onCellMouseDown:h=>{h.event&&this.ctx.handleCellMouseDown(h.rowIndex,h.colIndex,h.event);},onCellDoubleClick:h=>{h.rowId!=null&&h.columnId&&this.ctx.startCellEdit(h.rowId,h.columnId);},onCellContextMenu:h=>{h.event&&this.ctx.handleCellContextMenu(h.rowIndex,h.colIndex,h.event);},onResizeStart:s.getOnResizeStart(),onResizeDoubleClick:h=>{let w=g.find(A=>A.columnId===h)?.minWidth??DEFAULT_MIN_COLUMN_WIDTH,b=s.getTableElement()?.parentElement??void 0,y=measureColumnContentWidth(h,w,b);i.setColumnWidth(h,y);},onBooleanToggle:m.editable!==false?(h,I,w)=>this.ctx.toggleBooleanCell(h,I,w):void 0,onFillHandleMouseDown:m.editable!==false?h=>u?.startFillDrag(h):void 0,rowSelectionMode:l?.rowSelection??"none",selectedRowIds:l?.selectedRowIds,onRowCheckboxChange:(h,I,w,b)=>{l?.handleRowCheckboxChange(h,I,w,b,v);},onSelectAll:h=>{l?.handleSelectAll(h,v);},allSelected:l?.isAllSelected(v),someSelected:l?.isSomeSelected(v),showRowNumbers:m.showRowNumbers||m.cellReferences,showColumnLetters:!!m.cellReferences,showNameBox:!!m.cellReferences,pinnedColumns:o?.pinnedColumns,leftOffsets:p,rightOffsets:f,onColumnReorderStart:d?(h,I)=>{let w=s.getTableElement();w&&d?.startDrag(h,I,g,n.columnOrder,o?.pinnedColumns,w);}:void 0}),s.update(),c?.update(e.selectionRange,t.copyRange,t.cutRange,this.layoutVersion);}updateDragAttributes(){let e=this.ctx.renderer.getWrapperElement(),t=this.ctx.selectionState;if(!e||!t)return;let i=t.getDragRange();if(!i)return;let n=normalizeSelectionRange(i),r=t.dragAnchor;this.cachedDragCells||(this.cachedDragCells=e.querySelectorAll("td[data-row-index][data-col-index]"));let o=this.cachedDragCells;for(let l=0;l<o.length;l++){let s=o[l],d=L(s);if(!d)continue;let c=d.rowIndex,u=d.colIndex;isInSelectionRange(n,c,u)?(s.setAttribute("data-drag-range","true"),r&&c===r.rowIndex&&u===r.columnIndex?s.setAttribute("data-drag-anchor",""):s.removeAttribute("data-drag-anchor"),s.classList.add("ogrid-drag-target")):(s.removeAttribute("data-drag-range"),s.removeAttribute("data-drag-anchor"),s.classList.remove("ogrid-drag-target"));}}renderAll(){this.layoutVersion++;let{state:e,options:t,headerFilterState:i,rowSelectionState:n,keyboardNavState:r,clipboardState:o,undoRedoState:l,fillHandleState:a,virtualScrollState:s,pagination:d,statusBar:c,columnChooser:u,renderer:m}=this.ctx,v=n?1:0;i.setFilters(e.filters),i.setFilterOptions(e.filterOptions);let{items:g,totalCount:S}=e.getProcessedItems();if(r&&o){let p=e.visibleColumnDefs;r.updateParams({items:g,visibleCols:p,colOffset:v,getRowId:e.getRowId,editable:t.editable,onCellValueChanged:l?.getWrappedCallback(),onCopy:()=>o?.handleCopy(),onCut:()=>o?.handleCut(),onPaste:async()=>{await o?.handlePaste();},onUndo:()=>l?.undo(),onRedo:()=>l?.redo(),onContextMenu:(f,h)=>this.ctx.showContextMenu(f,h),onStartEdit:(f,h)=>this.ctx.startCellEdit(f,h),clearClipboardRanges:()=>o?.clearClipboardRanges(),onKeyDown:t.onKeyDown,onFillDown:a?()=>a.fillDown():void 0}),o.updateParams({items:g,visibleCols:p,colOffset:v,editable:t.editable,onCellValueChanged:l?.getWrappedCallback()}),a?.updateParams({items:g,visibleCols:p,editable:t.editable,onCellValueChanged:l?.getWrappedCallback(),colOffset:v,beginBatch:()=>l?.beginBatch(),endBatch:()=>l?.endBatch()}),this.updateRendererInteractionState();}else m.update();s?.setTotalRows(S),d.render(S,t.pageSizeOptions),c.render({totalCount:S}),u.render(),this.renderSideBar(),this.renderLoadingOverlay();}renderHeaderFilterPopover(){let{headerFilterState:e,headerFilterComponent:t,filterConfigs:i}=this.ctx,n=e.openColumnId,r=this.ctx.tableContainer.querySelectorAll(".ogrid-filter-icon[aria-haspopup]");for(let a of r){let s=a.closest("th[data-column-id]")?.getAttribute("data-column-id");a.setAttribute("aria-expanded",s===n?"true":"false");}if(!n){t.cleanup();return}let o=i.get(n);if(!o)return;t.render(o);let l=document.querySelector(".ogrid-header-filter-popover");e.setPopoverEl(l);}renderSideBar(){let{sideBarComponent:e,sideBarState:t,state:i}=this.ctx;if(!e||!t)return;let n=i.columns.map(o=>({columnId:o.columnId,name:o.name,required:o.required===true})),r=i.columns.filter(o=>o.filterable&&typeof o.filterable=="object"&&o.filterable.type).map(o=>({columnId:o.columnId,name:o.name,filterField:o.filterable.filterField??o.columnId,filterType:o.filterable.type}));e.setConfig({columns:n,visibleColumns:i.visibleColumns,onVisibilityChange:(o,l)=>{let a=new Set(i.visibleColumns);l?a.add(o):a.delete(o),i.setVisibleColumns(a);},onSetVisibleColumns:o=>i.setVisibleColumns(o),filterableColumns:r,filters:i.filters,onFilterChange:(o,l)=>i.setFilter(o,l),filterOptions:i.filterOptions}),e.render();}renderLoadingOverlay(){let{state:e,tableContainer:t}=this.ctx;if(e.isLoading){let{items:i}=e.getProcessedItems();t.style.minHeight=!i||i.length===0?"200px":"";let n=this.ctx.loadingOverlay;if(!n){n=document.createElement("div"),n.className="ogrid-loading-overlay",n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.right="0",n.style.bottom="0",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",n.style.background="var(--ogrid-loading-overlay, rgba(255, 255, 255, 0.7))",n.style.zIndex="100";let r=document.createElement("div");r.className="ogrid-loading-spinner",r.textContent="Loading...",n.appendChild(r),this.ctx.setLoadingOverlay(n);}t.contains(n)||t.appendChild(n);}else {t.style.minHeight="";let i=this.ctx.loadingOverlay;i&&t.contains(i)&&i.remove();}}};var ue=class{constructor(e){this.emitter=new x;this.engine=null;if(this.options=e,e.formulas&&(this.engine=new FormulaEngine({customFunctions:e.formulaFunctions,namedRanges:e.namedRanges}),e.sheets))for(let[t,i]of Object.entries(e.sheets))this.engine.registerSheet(t,i);}initialize(e){if(!this.engine||!this.options.initialFormulas?.length)return;let t=this.engine.loadFormulas(this.options.initialFormulas,e);t.updatedCells.length>0&&this.emitRecalc(t);}setFormula(e,t,i,n){if(!this.engine)return;let r=this.engine.setFormula(e,t,i,n);return r.updatedCells.length>0&&this.emitRecalc(r),r}onCellChanged(e,t,i){if(!this.engine)return;let n=this.engine.onCellChanged(e,t,i);return n.updatedCells.length>0&&this.emitRecalc(n),n}getValue(e,t){return this.engine?.getValue(e,t)}hasFormula(e,t){return this.engine?.hasFormula(e,t)??false}getFormula(e,t){return this.engine?.getFormula(e,t)}isEnabled(){return this.engine!==null}defineNamedRange(e,t){this.engine?.defineNamedRange(e,t);}removeNamedRange(e){this.engine?.removeNamedRange(e);}registerSheet(e,t){this.engine?.registerSheet(e,t);}unregisterSheet(e){this.engine?.unregisterSheet(e);}getPrecedents(e,t){return this.engine?.getPrecedents(e,t)??[]}getDependents(e,t){return this.engine?.getDependents(e,t)??[]}getAuditTrail(e,t){return this.engine?.getAuditTrail(e,t)??null}onFormulaRecalc(e){return this.emitter.on("formulaRecalc",e),()=>this.emitter.off("formulaRecalc",e)}destroy(){this.engine=null,this.emitter.removeAllListeners();}emitRecalc(e){this.options.onFormulaRecalc?.(e),this.emitter.emit("formulaRecalc",e);}};var he=class{constructor(e){this.el=null;this.nameBoxEl=null;this.inputEl=null;this.isEditing=false;this.handleKeyDown=e=>{handleFormulaBarKeyDown(e.key,()=>e.preventDefault(),this.callbacks.onCommit,this.callbacks.onCancel);};this.handleInput=()=>{this.inputEl&&this.callbacks.onInputChange(this.inputEl.value);};this.handleClick=()=>{this.isEditing||this.callbacks.onStartEditing();};this.callbacks=e;}mount(e){if(this.el)return;this.el=document.createElement("div"),this.el.className="ogrid-formula-bar",this.el.setAttribute("role","toolbar"),this.el.setAttribute("aria-label","Formula bar"),this.el.style.cssText=FORMULA_BAR_CSS.bar,this.nameBoxEl=document.createElement("div"),this.nameBoxEl.className="ogrid-formula-bar-name",this.nameBoxEl.setAttribute("aria-label","Active cell reference"),this.nameBoxEl.style.cssText=FORMULA_BAR_CSS.nameBox,this.nameBoxEl.textContent="\u2014",this.el.appendChild(this.nameBoxEl);let t=document.createElement("div");t.className="ogrid-formula-bar-fx",t.setAttribute("aria-hidden","true"),t.style.cssText=FORMULA_BAR_CSS.fxLabel,t.textContent="fx",this.el.appendChild(t),this.inputEl=document.createElement("input"),this.inputEl.type="text",this.inputEl.className="ogrid-formula-bar-input",this.inputEl.setAttribute("aria-label","Formula input"),this.inputEl.spellcheck=false,this.inputEl.autocomplete="off",this.inputEl.readOnly=true,this.inputEl.style.cssText=FORMULA_BAR_CSS.input,this.inputEl.addEventListener("keydown",this.handleKeyDown),this.inputEl.addEventListener("input",this.handleInput),this.inputEl.addEventListener("click",this.handleClick),this.inputEl.addEventListener("dblclick",this.handleClick),this.el.appendChild(this.inputEl),e.appendChild(this.el);}update(e,t){this.nameBoxEl&&(this.nameBoxEl.textContent=e??"\u2014"),this.inputEl&&(this.inputEl.value=t);}setEditing(e){this.isEditing=e,this.inputEl&&(this.inputEl.readOnly=!e,e&&this.inputEl.focus());}destroy(){this.inputEl&&(this.inputEl.removeEventListener("keydown",this.handleKeyDown),this.inputEl.removeEventListener("input",this.handleInput),this.inputEl.removeEventListener("click",this.handleClick),this.inputEl.removeEventListener("dblclick",this.handleClick)),this.el?.remove(),this.el=null,this.nameBoxEl=null,this.inputEl=null;}};var Ut=`
|
|
2
2
|
.ogrid-drag-target { box-shadow: inset 0 0 0 1px var(--ogrid-accent, #0078d4); }
|
|
3
3
|
:where(:root) {
|
|
4
4
|
--ogrid-bg: #ffffff;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alaarab/ogrid-js",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "OGrid vanilla JS – framework-free data grid with sorting, filtering, pagination, and spreadsheet-style editing.",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"node": ">=18"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@alaarab/ogrid-core": "2.5.
|
|
39
|
+
"@alaarab/ogrid-core": "2.5.5"
|
|
40
40
|
},
|
|
41
41
|
"sideEffects": [
|
|
42
42
|
"**/*.css"
|