@alaarab/ogrid-js 2.5.6 → 2.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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,formatDateForDisplay,getDateInputPlaceholder,GRID_CONTEXT_MENU_ITEMS,formatShortcut,measureColumnContentWidth,formatCellReference,measureRange,parseUserInputDate}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(E){let e=E.getAttribute("data-row-index"),t=E.getAttribute("data-col-index");if(e==null||t==null)return null;let n=parseInt(e,10),i=parseInt(t,10);return Number.isNaN(n)||Number.isNaN(i)?null:{rowIndex:n,colIndex:i}}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 n=t[0];this.handlers.get(e)?.forEach(i=>{i(n);});}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(n=>this._visibleColumns.has(n.columnId)),t=applyResponsiveHiding(e,this._containerWidth,this._responsiveColumns??void 0);if(this._columnOrder.length===0)this._visibleColsCache=t;else {let n=new Map(this._columnOrder.map((i,r)=>[i,r]));this._visibleColsCache=[...t].sort((i,r)=>{let o=n.get(i.columnId)??1/0,l=n.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,n=(this._page-1)*this._pageSize,i=n+this._pageSize;return {items:e.slice(n,i),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,n=(this._page-1)*this._pageSize,i=n+this._pageSize;return {items:e.slice(n,i),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(n=>{e!==this._fetchId||t.signal.aborted||(this._serverItems=n.items,this._serverTotalCount=n.totalCount,this._isLoading=false,!this._firstDataRendered&&n.items.length>0&&(this._firstDataRendered=true,validateRowIds(n.items,this._getRowId),this._onFirstDataRendered?.()),this.emitter.emit("stateChange",{type:"data"}));}).catch(n=>{e!==this._fetchId||t.signal.aborted||(this._onError?.(n),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:n}=this.getProcessedItems(),i=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(n,i,(o,l)=>{let s=this._columns.find(c=>c.columnId===l);if(!s)return "";let a=getCellValue(o,s);return s.valueFormatter?s.valueFormatter(a,o):a!=null?String(a):""},e,r);}}}setFormulaEngine(e){this._formulaEngine=e;}destroy(){this._abortController&&(this._abortController.abort(),this._abortController=null),this.emitter.removeAllListeners();}};function P(E){return {minR:Math.min(E.startRow,E.endRow),maxR:Math.max(E.startRow,E.endRow),minC:Math.min(E.startCol,E.endCol),maxC:Math.max(E.startCol,E.endCol)}}function M(E,e,t){return e>=E.minR&&e<=E.maxR&&t>=E.minC&&t<=E.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 n=e.target.closest("td[data-row-index]");if(!n)return null;let i=L(n);return i?{el:n,rowIndex:i.rowIndex,colIndex:i.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 n=this.getCellFromEvent(e);n&&this.interactionState?.onCellMouseDown?.({rowIndex:n.rowIndex,colIndex:n.colIndex,event:e});},this._tbodyDblclickHandler=e=>{let t=this.getCellFromEvent(e);if(!t)return;let n=t.el.getAttribute("data-column-id")??"",{items:i}=this.state.getProcessedItems(),r=i[t.rowIndex];if(!r)return;let o=this.state.getRowId(r);this.interactionState?.onCellDoubleClick?.({rowIndex:t.rowIndex,colIndex:t.colIndex,rowId:o,columnId:n});},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 n=t.getAttribute("data-column-id"),i=t.closest("th[data-column-id]"),r=n??i?.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 n=t.closest("th[data-column-id]");if(!n)return;let i=n.getAttribute("data-column-id");i&&this.interactionState.onColumnReorderStart(i,e);}},this._theadDblclickHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-resize-handle")){e.stopPropagation();let n=t.getAttribute("data-column-id"),i=t.closest("th[data-column-id]"),r=n??i?.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,n=[];for(let r of e)n.push(r.columnId),n.push(r.name),n.push(t?.columnWidths[r.columnId]?.toString()??"");let i=this.state.sort;i&&n.push(`sort:${i.field}:${i.direction}`),n.push(`sel:${t?.rowSelectionMode??""}`),n.push(`allSel:${t?.allSelected??""}`),n.push(`someSel:${t?.someSelected??""}`),n.push(`rn:${t?.showRowNumbers??""}`),t?.showRowNumbers&&n.push(`rnw:${t?.columnWidths[ROW_NUMBER_COLUMN_ID]??""}`),n.push(`cl:${t?.showColumnLetters??""}`);for(let[r,o]of this.filterConfigs)this.headerFilterState?.hasActiveFilter(o)&&n.push(`flt:${r}`);return n.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 i=e?.editingCell,r=this.lastEditingCell;if(i?.rowId!==r?.rowId||i?.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 s of o)if(!l.has(s))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:n,copyRange:i,cutRange:r}=e,o=this.lastActiveCell,l=this.lastSelectionRange,s=this.lastCopyRange,a=this.lastCutRange,c=n?P(n):null,d=l?P(l):null,p=i?P(i):null,m=s?P(s):null,v=r?P(r):null,f=a?P(a):null,b=this.getColOffset(),u=this.tbody.querySelectorAll("td[data-row-index][data-col-index]");for(let g=0;g<u.length;g++){let h=u[g],S=L(h);if(!S)continue;let I=S.rowIndex,y=S.colIndex,R=y-b,k=o&&o.rowIndex===I&&o.columnIndex===y,w=t&&t.rowIndex===I&&t.columnIndex===y;k&&!w?(h.removeAttribute("data-active-cell"),h.style.outline="",h.style.zIndex=""):w&&!k&&(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=d&&M(d,I,R),C=c&&M(c,I,R),_=C&&!w,F=T&&!(o&&o.rowIndex===I&&o.columnIndex===y);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 A=m&&M(m,I,R),D=p&&M(p,I,R);A&&!D?!w&&!(v&&M(v,I,R))&&(h.style.outline=""):D&&!A&&(h.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))");let be=f&&M(f,I,R),O=v&&M(v,I,R);be&&!O?!w&&!(p&&M(p,I,R))&&(h.style.outline=""):O&&!be&&(h.style.outline="1px dashed var(--ogrid-accent, #0078d4)");let Ie=h.querySelector(".ogrid-fill-handle"),xe=n&&e.onFillHandleMouseDown&&I===Math.max(n.startRow,n.endRow)&&R===Math.max(n.startCol,n.endCol),_e=!!Ie;if(_e&&!xe)Ie?.remove();else if(!_e&&xe){let H=document.createElement("div");H.className="ogrid-fill-handle",H.setAttribute("data-fill-handle","true"),H.style.position="absolute",H.style.right="-3px",H.style.bottom="-3px",H.style.width="6px",H.style.height="6px",H.style.backgroundColor="var(--ogrid-selection, #217346)",H.style.cursor="crosshair",H.style.zIndex="5",h.style.position=h.style.position||"relative",H.addEventListener("pointerdown",Ue=>{this.interactionState?.onFillHandleMouseDown?.(Ue);}),h.appendChild(H);}if(!C&&e.pinnedColumns){let H=h.getAttribute("data-column-id");H&&e.pinnedColumns[H]&&(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,n){let i=this.interactionState;if(!i?.pinnedColumns)return;let r=i.pinnedColumns[t];r&&(e.style.position="sticky",e.style.zIndex=n?"3":"1",e.setAttribute("data-pinned",r),r==="left"&&i.leftOffsets?e.style.left=`${i.leftOffsets[t]??0}px`:r==="right"&&i.rightOffsets&&(e.style.right=`${i.rightOffsets[t]??0}px`),n||(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(),n=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(n){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 i=buildHeaderRows(this.state.allColumns,this.state.visibleColumns);if(i.length>1)for(let r=0;r<i.length;r++){let o=i[r],l=r===i.length-1,s=document.createElement("tr");if(t){let a=document.createElement("th");a.className="ogrid-header-cell ogrid-checkbox-header",a.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,l&&this.appendSelectAllCheckbox(a),s.appendChild(a);}if(n){if(l){let a=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,c=document.createElement("th");c.className="ogrid-header-cell ogrid-row-number-header",c.style.width=`${a}px`,c.style.minWidth=`${a}px`,c.style.maxWidth=`${a}px`,c.style.textAlign="center",c.style.position=c.style.position||"relative",c.textContent="#";let d=document.createElement("div");d.className="ogrid-resize-handle",d.style.position="absolute",d.style.right="0",d.style.top="0",d.style.bottom="0",d.style.width="4px",d.style.cursor="col-resize",d.style.userSelect="none",d.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),c.appendChild(d),s.appendChild(c);}else if(r===0){let a=document.createElement("th");a.rowSpan=i.length-1,a.style.padding="0",s.appendChild(a);}}for(let a of o){let c=document.createElement("th");if(c.textContent=a.label,c.className=a.isGroup?"ogrid-group-header":"ogrid-header-cell",a.colSpan>1&&(c.colSpan=a.colSpan),!a.isGroup&&a.columnDef?.sortable&&(c.classList.add("ogrid-sortable"),c.addEventListener("click",()=>{a.columnDef&&this.state.toggleSort(a.columnDef.columnId);})),!a.isGroup&&a.columnDef){c.setAttribute("data-column-id",a.columnDef.columnId),c.setAttribute("scope","col");let d=this.state.sort;d?.field===a.columnDef.columnId&&c.setAttribute("aria-sort",d.direction==="asc"?"ascending":"descending"),this.applyPinningStyles(c,a.columnDef.columnId,true);}s.appendChild(c);}this.thead?.appendChild(s);}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 s=document.createElement("div");s.className="ogrid-resize-handle",s.style.position="absolute",s.style.right="0",s.style.top="0",s.style.bottom="0",s.style.width="4px",s.style.cursor="col-resize",s.style.userSelect="none",s.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),l.appendChild(s),r.appendChild(l);}for(let o=0;o<e.length;o++){let l=e[o],s=document.createElement("th");s.className="ogrid-header-cell",s.setAttribute("data-column-id",l.columnId),s.setAttribute("scope","col");let a=this.state.sort;a?.field===l.columnId&&s.setAttribute("aria-sort",a.direction==="asc"?"ascending":"descending");let c=document.createElement("span");c.textContent=l.name,s.appendChild(c),l.sortable&&(s.classList.add("ogrid-sortable"),s.addEventListener("click",()=>this.state.toggleSort(l.columnId))),l.type==="numeric"&&(s.style.textAlign="right"),this.interactionState?.columnWidths[l.columnId]&&(s.style.width=`${this.interactionState.columnWidths[l.columnId]}px`),this.applyPinningStyles(s,l.columnId,true);let d=document.createElement("div");d.className="ogrid-resize-handle",d.style.position="absolute",d.style.right="0",d.style.top="0",d.style.bottom="0",d.style.width="4px",d.style.cursor="col-resize",d.style.userSelect="none",s.style.position=s.style.position||"relative",s.appendChild(d);let p=this.filterConfigs.get(l.columnId);if(p&&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(p);m.textContent=v?"\u25BC":"\u25BD",v&&(m.style.opacity="1",m.style.color="var(--ogrid-selection, #217346)"),m.addEventListener("click",f=>{f.stopPropagation(),f.preventDefault(),this.onFilterIconClick?.(l.columnId,s);}),s.appendChild(m);}r.appendChild(s);}this.thead?.appendChild(r);}}appendSelectAllCheckbox(e){let t=this.interactionState;if(t?.rowSelectionMode!=="multiple")return;let n=document.createElement("input");n.type="checkbox",n.className="ogrid-select-all-checkbox",n.checked=t?.allSelected===true,n.indeterminate=t?.someSelected===true,n.setAttribute("aria-label","Select all rows"),n.addEventListener("change",()=>{t?.onSelectAll?.(n.checked);}),e.appendChild(n);}renderBody(){if(!this.tbody)return;let e=this.state.visibleColumnDefs,{items:t}=this.state.getProcessedItems(),n=this.hasCheckboxColumn(),i=this.hasRowNumbersColumn(),r=this.getColOffset(),o=e.length+r,l=i?(this.state.page-1)*this.state.pageSize:0;if(t.length===0&&!this.state.isLoading){let u=document.createElement("tr"),g=document.createElement("td");g.colSpan=o,g.className="ogrid-empty-state",g.textContent="No data",u.appendChild(g),this.tbody.appendChild(u);return}let s=this.virtualScrollState,a=s?.enabled===true,c=0,d=t.length-1;if(a){let u=s?.visibleRange;if(!u)return;if(c=Math.max(0,u.startIndex),d=Math.min(t.length-1,u.endIndex),u.offsetTop>0){let g=document.createElement("tr");g.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${u.offsetTop}px`,h.style.padding="0",h.style.border="none",g.appendChild(h),this.tbody.appendChild(g);}}let p=s?.columnVirtualizationEnabled===true&&s.columnRange!=null,m=e,v=null,f=0,b=0;if(p&&s){let u=partitionColumnsForVirtualization(e,s.columnRange,this.interactionState?.pinnedColumns),g=[...u.pinnedLeft,...u.virtualizedUnpinned,...u.pinnedRight];v=g.map(h=>e.indexOf(h)),m=g,f=u.leftSpacerWidth,b=u.rightSpacerWidth;}for(let u=c;u<=d;u++){let g=t[u];if(!g)continue;let h=this.state.getRowId(g),S=document.createElement("tr");S.className="ogrid-row",S.setAttribute("data-row-id",String(h));let I=this.interactionState?.selectedRowIds?.has(h)===true;if(I&&(S.setAttribute("data-row-selected","true"),S.setAttribute("aria-selected","true")),n){let y=document.createElement("td");y.className="ogrid-cell ogrid-checkbox-cell",y.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,y.style.textAlign="center";let R=document.createElement("input");R.type="checkbox",R.className="ogrid-row-checkbox",R.checked=I,R.setAttribute("aria-label",`Select row ${h}`),R.addEventListener("click",k=>{k.stopPropagation(),this.interactionState?.onRowCheckboxChange?.(h,R.checked,u,k.shiftKey);}),y.appendChild(R),S.appendChild(y);}if(i){let y=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,R=document.createElement("td");R.className="ogrid-cell ogrid-row-number-cell",R.style.width=`${y}px`,R.style.minWidth=`${y}px`,R.style.maxWidth=`${y}px`,R.style.textAlign="center",R.style.color="var(--ogrid-fg-muted, #666)",R.style.fontSize="0.9em",R.textContent=String(l+u+1),S.appendChild(R);}if(f>0){let y=document.createElement("td");y.style.width=`${f}px`,y.style.minWidth=`${f}px`,y.style.padding="0",y.style.border="none",y.setAttribute("aria-hidden","true"),S.appendChild(y);}for(let y=0;y<m.length;y++){let R=m[y],k=(v?v[y]:y)+r,w=document.createElement("td");if(w.className="ogrid-cell",w.setAttribute("data-column-id",R.columnId),w.setAttribute("data-row-index",String(u)),w.setAttribute("data-col-index",String(k)),w.setAttribute("tabindex","-1"),R.type==="numeric"&&(w.style.textAlign="right"),this.applyPinningStyles(w,R.columnId,false),this.interactionState){let{activeCell:T,selectionRange:C,copyRange:_,cutRange:F,editingCell:A}=this.interactionState;T&&T.rowIndex===u&&T.columnIndex===k&&(w.setAttribute("data-active-cell","true"),w.style.outline="2px solid var(--ogrid-accent, #0078d4)",w.style.position="relative",w.style.zIndex="var(--ogrid-z-active-cell, 2)"),C&&isInSelectionRange(C,u,y)&&(w.setAttribute("data-in-range","true"),w.style.backgroundColor="var(--ogrid-range-bg, rgba(33, 115, 70, 0.12))"),_&&isInSelectionRange(_,u,y)&&(w.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))"),F&&isInSelectionRange(F,u,y)&&(w.style.outline="1px dashed var(--ogrid-accent, #0078d4)"),A&&A.rowId===h&&A.columnId===R.columnId&&(w.style.visibility="hidden");}if(R.renderCell){let T=getCellValue(g,R),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(y,u)?this.formulaEngine.getValue(y,u)??T:T;R.renderCell(w,g,C);}else {let T=getCellValue(g,R),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(y,u)?this.formulaEngine.getValue(y,u)??T:T;if(R.type==="boolean"){let _=!!C,F=!!R.editable,A=document.createElement("input");A.type="checkbox",A.checked=_,A.disabled=!F,A.style.margin="0",A.style.cursor=F?"pointer":"default",A.style.outline="none",A.setAttribute("aria-label",_?"Checked":"Unchecked"),F&&(A.addEventListener("change",()=>{this.interactionState?.onBooleanToggle?.(h,R.columnId,_);}),A.addEventListener("click",D=>D.stopPropagation())),w.appendChild(A);}else R.valueFormatter?w.textContent=R.valueFormatter(C,g):C!=null&&(w.textContent=String(C));}if(R.cellStyle){let T=typeof R.cellStyle=="function"?R.cellStyle(g):R.cellStyle;T&&Object.assign(w.style,T);}if(this.interactionState){let{selectionRange:T}=this.interactionState;if(T&&this.interactionState.onFillHandleMouseDown&&u===Math.max(T.startRow,T.endRow)&&y===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",w.style.position=w.style.position||"relative",w.appendChild(C);}}S.appendChild(w);}if(b>0){let y=document.createElement("td");y.style.width=`${b}px`,y.style.minWidth=`${b}px`,y.style.padding="0",y.style.border="none",y.setAttribute("aria-hidden","true"),S.appendChild(y);}this.tbody.appendChild(S);}if(a&&s){let u=s.visibleRange;if(u.offsetBottom>0){let g=document.createElement("tr");g.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${u.offsetBottom}px`,h.style.padding="0",h.style.border="none",g.appendChild(h),this.tbody.appendChild(g);}}}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 n=this.wrapperEl.getBoundingClientRect(),i=e-n.left+this.wrapperEl.scrollLeft;this.dropIndicator.style.display="block",this.dropIndicator.style.left=`${i}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 n=getPaginationViewModel(this.state.page,this.state.pageSize,e,t?{pageSizeOptions:t}:void 0);if(!n)return;this.el=document.createElement("div"),this.el.className="ogrid-pagination";let i=document.createElement("div");i.className="ogrid-pagination-size";let r=document.createElement("span");r.textContent="Rows per page: ",i.appendChild(r);let o=document.createElement("select");o.className="ogrid-page-size-select";for(let d of n.pageSizeOptions){let p=document.createElement("option");p.value=String(d),p.textContent=String(d),p.selected=d===this.state.pageSize,o.appendChild(p);}o.addEventListener("change",()=>{this.state.setPageSize(Number(o.value));}),i.appendChild(o),this.el.appendChild(i);let l=document.createElement("span");l.className="ogrid-pagination-info",l.textContent=`${n.startItem}-${n.endItem} of ${e}`,this.el.appendChild(l);let s=document.createElement("div");s.className="ogrid-pagination-nav";let a=document.createElement("button");if(a.textContent="\u25C0",a.className="ogrid-pagination-btn",a.disabled=this.state.page===1,a.addEventListener("click",()=>this.state.setPage(this.state.page-1)),s.appendChild(a),n.showStartEllipsis){let d=document.createElement("span");d.textContent="...",d.className="ogrid-pagination-ellipsis",s.appendChild(d);}for(let d of n.pageNumbers){let p=document.createElement("button");p.textContent=String(d),p.className="ogrid-pagination-btn"+(d===this.state.page?" ogrid-pagination-active":""),p.addEventListener("click",()=>this.state.setPage(d)),s.appendChild(p);}if(n.showEndEllipsis){let d=document.createElement("span");d.textContent="...",d.className="ogrid-pagination-ellipsis",s.appendChild(d);}let c=document.createElement("button");c.textContent="\u25B6",c.className="ogrid-pagination-btn",c.disabled=this.state.page===n.totalPages,c.addEventListener("click",()=>this.state.setPage(this.state.page+1)),s.appendChild(c),this.el.appendChild(s),this.container.appendChild(this.el);}destroy(){this.el?.remove(),this.el=null;}};var U=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 n of t){let i=document.createElement("span");i.className="ogrid-status-part",i.textContent=`${n.label}: ${n.value}`,this.el.appendChild(i);}if(e.aggregation){let n=e.aggregation,i=document.createElement("span");i.className="ogrid-status-aggregation",i.textContent=`Sum: ${n.sum.toLocaleString()} | Avg: ${n.avg.toFixed(2)} | Min: ${n.min} | Max: ${n.max} | Count: ${n.count}`,this.el.appendChild(i);}this.container.appendChild(this.el);}}destroy(){this.el?.remove(),this.el=null;}};var G=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((n,i)=>{i<t.length&&(n.checked=this.state.visibleColumns.has(t[i].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 n=document.createElement("input");n.type="checkbox",n.checked=this.state.visibleColumns.has(e.columnId),n.disabled=!!e.required,n.addEventListener("change",()=>{let i=new Set(this.state.visibleColumns);n.checked?i.add(e.columnId):i.delete(e.columnId),this.state.setVisibleColumns(i);}),t.appendChild(n),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 He=["columns","filters"],K=class{constructor(e){this.emitter=new x;if(this._isEnabled=e!=null&&e!==false,!this._isEnabled||e===true)this._panels=He,this._position="right",this._activePanel=null;else {let t=e;this._panels=t.panels??He,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 ge={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),n=this.createPanel(e);e==="left"?(this.el.appendChild(t),n&&this.el.appendChild(n)):(n&&this.el.appendChild(n),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 n of this.state.panels){let i=document.createElement("button");i.setAttribute("role","tab"),i.setAttribute("aria-selected",String(this.state.activePanel===n)),i.setAttribute("aria-label",ge[n]),i.title=ge[n],i.textContent=ot[n],i.className="ogrid-sidebar-tab",i.style.width="36px",i.style.height="36px",i.style.border="none",i.style.cursor="pointer",i.style.color="var(--ogrid-fg, #242424)",i.style.fontSize="14px",i.style.display="flex",i.style.alignItems="center",i.style.justifyContent="center",this.state.activePanel===n?(i.style.background="var(--ogrid-bg, #fff)",i.style.fontWeight="bold"):(i.style.background="transparent",i.style.fontWeight="normal"),i.addEventListener("click",()=>{this.state.toggle(n);}),t.appendChild(i);}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",ge[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 n=document.createElement("div");n.style.display="flex",n.style.justifyContent="space-between",n.style.alignItems="center",n.style.padding="8px 12px",n.style.borderBottom="1px solid var(--ogrid-border, #e0e0e0)",n.style.fontWeight="600";let i=document.createElement("span");i.textContent=ge[this.state.activePanel],n.appendChild(i);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()),n.appendChild(r),t.appendChild(n);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:n,onVisibilityChange:i,onSetVisibleColumns:r}=this.config,o=t.every(c=>n.has(c.columnId)),l=document.createElement("div");l.style.display="flex",l.style.gap="8px",l.style.marginBottom="8px";let s=document.createElement("button");s.textContent="Select All",s.disabled=o,s.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(s),s.addEventListener("click",()=>{let c=new Set(n);t.forEach(d=>c.add(d.columnId)),r(c);}),l.appendChild(s);let a=document.createElement("button");a.textContent="Clear All",a.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(a),a.addEventListener("click",()=>{let c=new Set;t.forEach(d=>{d.required&&n.has(d.columnId)&&c.add(d.columnId);}),r(c);}),l.appendChild(a),e.appendChild(l);for(let c of t){let d=document.createElement("label");d.style.display="flex",d.style.alignItems="center",d.style.gap="6px",d.style.padding="2px 0",d.style.cursor="pointer";let p=document.createElement("input");p.type="checkbox",p.checked=n.has(c.columnId),p.disabled=!!c.required,p.addEventListener("change",()=>{i(c.columnId,p.checked);});let m=document.createElement("span");m.textContent=c.name,d.appendChild(p),d.appendChild(m),e.appendChild(d);}}renderFiltersPanel(e){if(!this.config)return;let{filterableColumns:t,filters:n,onFilterChange:i,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 s=document.createElement("div");if(s.style.fontWeight="500",s.style.marginBottom="4px",s.style.fontSize="13px",s.textContent=o.name,l.appendChild(s),o.filterType==="text"){let a=document.createElement("input");a.type="text";let c=n[o.filterField];a.value=c?.type==="text"?c.value:"",a.placeholder=`Filter ${o.name}...`,a.setAttribute("aria-label",`Filter ${o.name}`),this.applyTextInputStyle(a),a.addEventListener("input",()=>{i(o.filterField,a.value?{type:"text",value:a.value}:void 0);}),l.appendChild(a);}else if(o.filterType==="date"){let a=document.createElement("div");a.style.display="flex",a.style.flexDirection="column",a.style.gap="4px";let c=n[o.filterField],d=c?.type==="date"?c.value:{},p=document.createElement("label");p.style.display="flex",p.style.alignItems="center",p.style.gap="4px",p.style.fontSize="12px",p.textContent="From: ";let m=document.createElement("input");m.type="date",m.value=d.from??"",m.setAttribute("aria-label",`${o.name} from date`),this.applyDateInputStyle(m),p.appendChild(m),a.appendChild(p);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 f=document.createElement("input");f.type="date",f.value=d.to??"",f.setAttribute("aria-label",`${o.name} to date`),this.applyDateInputStyle(f),v.appendChild(f),a.appendChild(v);let b=()=>{let u=m.value||void 0,g=f.value||void 0;i(o.filterField,u||g?{type:"date",value:{from:u,to:g}}:void 0);};m.addEventListener("change",b),f.addEventListener("change",b),l.appendChild(a);}else if(o.filterType==="multiSelect"){let a=r[o.filterField]??[],c=document.createElement("div");c.style.maxHeight="120px",c.style.overflowY="auto",c.setAttribute("role","group"),c.setAttribute("aria-label",`${o.name} options`);let d=n[o.filterField],p=d?.type==="multiSelect"?d.value:[];for(let m of a){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 f=document.createElement("input");f.type="checkbox",f.checked=p.includes(m),f.addEventListener("change",()=>{let u=n[o.filterField],g=u?.type==="multiSelect"?[...u.value]:[],h=f.checked?[...g,m]:g.filter(S=>S!==m);i(o.filterField,h.length>0?{type:"multiSelect",value:h}:void 0);});let b=document.createElement("span");b.textContent=m,v.appendChild(f),v.appendChild(b),c.appendChild(v);}l.appendChild(c);}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 n=this._searchText.toLowerCase();return t.filter(i=>i.toLowerCase().includes(n))}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,n,i){this._openColumnId&&this.close(),this._openColumnId=e,this._headerEl=n,this._popoverEl=i;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=n.getBoundingClientRect();this._popoverPosition={top:o.bottom+4,left:o.left},this._clickOutsideHandler=l=>{let s=l.target;this._popoverEl&&!this._popoverEl.contains(s)&&this._headerEl&&!this._headerEl.contains(s)&&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 n=new Set(this._tempSelected);t?n.add(e):n.delete(e),this._tempSelected=n,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,n=this._tempDateTo||void 0;this._onFilterChange(e,t||n?{type:"date",value:{from:t,to:n}}: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",n=>n.stopPropagation()),this.popoverEl.addEventListener("mousedown",n=>n.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 n=document.createElement("div");n.style.display="flex",n.style.gap="8px";let i=document.createElement("button");i.textContent="Apply",i.className="ogrid-filter-apply-btn",this.applyButtonStyle(i),i.addEventListener("click",()=>this.state.applyTextFilter(e.filterField)),n.appendChild(i);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)),n.appendChild(r),this.popoverEl.appendChild(n),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",s=>s.stopPropagation()),this.popoverEl.appendChild(t);let n=document.createElement("div");n.style.display="flex",n.style.gap="8px",n.style.marginBottom="8px";let i=document.createElement("button");i.textContent="Select All",i.className="ogrid-filter-select-all-btn",this.applySmallButtonStyle(i),i.addEventListener("click",()=>{this.state.handleSelectAll(e.filterField),this.updateCheckboxList(e,o);}),n.appendChild(i);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);}),n.appendChild(r),this.popoverEl.appendChild(n);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 n=this.state.getFilteredOptions(e.filterField),i=this.state.tempSelected;for(let r of n){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=i.has(r),l.addEventListener("change",()=>{this.state.handleCheckboxChange(r,l.checked);});let s=document.createElement("span");s.textContent=r,o.appendChild(l),o.appendChild(s),t.appendChild(o);}if(n.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 n=document.createElement("label");n.style.display="flex",n.style.alignItems="center",n.style.gap="4px",n.style.fontSize="13px",n.textContent="From: ";let i=document.createElement("input");i.type="date",i.value=this.state.tempDateFrom,i.setAttribute("aria-label","From date"),this.applyInputStyle(i),i.addEventListener("change",()=>{this.state.setTempDateFrom(i.value);}),i.addEventListener("keydown",c=>c.stopPropagation()),n.appendChild(i),t.appendChild(n);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",c=>c.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 s=document.createElement("button");s.textContent="Apply",s.className="ogrid-filter-apply-btn",this.applyButtonStyle(s),s.addEventListener("click",()=>this.state.applyDateFilter(e.filterField)),l.appendChild(s);let a=document.createElement("button");a.textContent="Clear",a.className="ogrid-filter-clear-btn",this.applyButtonStyle(a),a.addEventListener("click",()=>this.state.clearDateFilter(e.filterField)),l.appendChild(a),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 n of t){let i=n.contentRect;this._containerWidth=i.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 i=t?CHECKBOX_COLUMN_WIDTH:0;for(let r of e){let o=this._columnSizingOverrides[r.columnId];o?i+=o+CELL_PADDING:i+=(r.width??r.minWidth??DEFAULT_MIN_COLUMN_WIDTH)+CELL_PADDING;}return i}getAllColumnWidths(){return {...this._columnSizingOverrides}}cleanupOverrides(e){let t={},n=false;for(let[i,r]of Object.entries(this._columnSizingOverrides))e.has(i)?t[i]=r:n=true;n&&(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(n=>e.has(this._getRowId(n)))});}handleRowCheckboxChange(e,t,n,i,r){if(this._rowSelection==="single"){this.updateSelection(t?new Set([e]):new Set,r),this._lastClickedRow=n;return}let o;i&&this._lastClickedRow>=0&&this._lastClickedRow!==n?o=applyRangeRowSelection(this._lastClickedRow,n,t,r,this._getRowId,this._selectedRowIds):(o=new Set(this._selectedRowIds),t?o.add(e):o.delete(e)),this._lastClickedRow=n,this.updateSelection(o,r);}handleSelectAll(e,t){e?this.updateSelection(new Set(t.map(n=>this._getRowId(n))),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 n of t)n.pinned&&!(n.columnId in this._pinnedColumns)&&(this._pinnedColumns[n.columnId]=n.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,...n}=this._pinnedColumns;this._pinnedColumns=n,this.emitter.emit("pinningChange",{pinnedColumns:this._pinnedColumns});}isPinned(e){return this._pinnedColumns[e]}computeLeftOffsets(e,t,n,i,r,o){let l={},s=0;i&&(s+=r),o&&(s+=ROW_NUMBER_COLUMN_WIDTH);for(let a of e)this._pinnedColumns[a.columnId]==="left"&&(l[a.columnId]=s,s+=t[a.columnId]??n);return l}computeRightOffsets(e,t,n){let i={},r=0;for(let o=e.length-1;o>=0;o--){let l=e[o];this._pinnedColumns[l.columnId]==="right"&&(i[l.columnId]=r,r+=t[l.columnId]??n);}return i}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),n=this._cachedColumnRange;!n||n.startIndex!==t.startIndex||n.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,n){let i=this._config.rowHeight??Re,r=getScrollTopForRow(e,i,this._containerHeight,n);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,n=computeVisibleRange(this._scrollTop,e,this._containerHeight,this._totalRows,t),i=this._cachedRange;i.startIndex!==n.startIndex||i.endIndex!==n.endIndex?(this._cachedRange=n,this.emitter.emit("rangeChanged",{visibleRange:n})):this._cachedRange=n;}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,n){if(!this._isDragging||!this.dragStartCell)return;let i={startRow:this.dragStartCell.rowIndex,startCol:this.dragStartCell.columnIndex,endRow:e,endCol:t};rangesEqual(this.pendingRange,i)||(this.pendingRange=i,this.rafHandle===null&&(this.rafHandle=requestAnimationFrame(()=>{this.pendingRange&&n(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,n,i,r){this.wrapperRef=null;this.handleKeyDown=e=>{let{items:t,visibleCols:n,colOffset:i,editable:r,onCellValueChanged:o,onCopy:l,onCut:s,onPaste:a,onUndo:c,onRedo:d,onContextMenu:p,onStartEdit:m,getRowId:v,clearClipboardRanges:f,onKeyDown:b,onFillDown:u}=this.params;if(b&&(b(e),e.defaultPrevented))return;let g=this.getActiveCell(),h=this.getSelectionRange(),S=t.length-1,I=n.length-1+i;if(t.length===0)return;if(g===null){["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Tab","Enter","Home","End","PageDown","PageUp"].includes(e.key)&&(this.setActiveCell({rowIndex:0,columnIndex:i}),e.preventDefault());return}let{rowIndex:y,columnIndex:R}=g,k=R-i,w=e.shiftKey,T=(C,_)=>{if(C<0||C>=t.length||_<0||_>=n.length)return true;let F=getCellValue(t[C],n[_]);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(),s?.());break;case "v":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),a?.());break;case "d":(e.ctrlKey||e.metaKey)&&r!==false&&u&&(e.preventDefault(),u());break;case "ArrowDown":case "ArrowUp":case "ArrowRight":case "ArrowLeft":{e.preventDefault();let{newRowIndex:C,newColumnIndex:_,newRange:F}=computeArrowNavigation({direction:e.key,rowIndex:y,columnIndex:R,dataColIndex:k,colOffset:i,maxRowIndex:S,maxColIndex:I,visibleColCount:n.length,isCtrl:e.ctrlKey||e.metaKey,isShift:w,selectionRange:h,isEmptyAt:T});this.setActiveCell({rowIndex:C,columnIndex:_}),this.setSelectionRange(F);break}case "Tab":{e.preventDefault();let C=computeTabNavigation(y,R,S,I,i,e.shiftKey),_=C.columnIndex-i;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:y;this.setActiveCell({rowIndex:C,columnIndex:i}),this.setSelectionRange({startRow:C,startCol:0,endRow:C,endCol:0});break}case "End":{e.preventDefault();let C=e.ctrlKey?S:y;this.setActiveCell({rowIndex:C,columnIndex:I}),this.setSelectionRange({startRow:C,startCol:n.length-1,endRow:C,endCol:n.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 A=e.key==="PageDown"?1:-1,D=Math.max(0,Math.min(y+A*_,S));e.shiftKey?this.setSelectionRange({startRow:h?.startRow??y,startCol:h?.startCol??k,endRow:D,endCol:h?.endCol??k}):this.setSelectionRange({startRow:D,startCol:k,endRow:D,endCol:k}),this.setActiveCell({rowIndex:D,columnIndex:R}),C&&(C.scrollTop=getScrollTopForRow(D,F,C.clientHeight,"center"));break}case "Enter":case "F2":{if(e.preventDefault(),k>=0&&k<n.length){let C=n[k],_=t[y];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(),f?.(),this.setActiveCell(null),this.setSelectionRange(null);break;case "z":(e.ctrlKey||e.metaKey)&&(e.shiftKey&&d?(e.preventDefault(),d()):!e.shiftKey&&c&&(e.preventDefault(),c()));break;case "y":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),d?.());break;case "a":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),t.length>0&&n.length>0&&(this.setActiveCell({rowIndex:0,columnIndex:i}),this.setSelectionRange({startRow:0,startCol:0,endRow:t.length-1,endCol:n.length-1})));break;case "Delete":case "Backspace":{if(r===false||o==null)break;let C=h??(g!=null?{startRow:g.rowIndex,startCol:g.columnIndex-i,endRow:g.rowIndex,endCol:g.columnIndex-i}:null);if(C==null)break;e.preventDefault();let _=applyCellDeletion(C,t,n);for(let F of _)o(F);break}case "F10":if(e.shiftKey)if(e.preventDefault(),g!=null&&this.wrapperRef){let C=`[data-row-index="${g.rowIndex}"][data-col-index="${g.columnIndex}"]`,_=this.wrapperRef.querySelector(C);if(_){let F=_.getBoundingClientRect();p?.(F.left+F.width/2,F.top+F.height/2);}else p?.(100,100);}else p?.(100,100);break;}};this.params=e,this.getActiveCell=t,this.getSelectionRange=n,this.setActiveCell=i,this.setSelectionRange=r;}setWrapperRef(e){this.wrapperRef=e;}updateParams(e){this.params=e;}};var te=class{constructor(e,t,n){this.emitter=new x;this._cutRange=null;this._copyRange=null;this.internalClipboard=null;this.params=e,this.getActiveCell=t,this.getSelectionRange=n;}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:n,visibleCols:i,formulas:r,flatColumns:o,getFormula:l,hasFormula:s,colOffset:a}=this.params,d=formatSelectionAsTsv(n,i,t,r&&o?{colOffset:a,flatColumns:o,getFormula:l,hasFormula:s}:void 0);this.internalClipboard=d,this._copyRange=t,this._cutRange=null,this.emitter.emit("rangesChange",{copyRange:this._copyRange,cutRange:null}),typeof navigator<"u"&&navigator.clipboard&&navigator.clipboard.writeText(d).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 n=this.getEffectiveRange(),i=n?n.startRow:0,r=n?n.startCol:0,{items:o,visibleCols:l,formulas:s,flatColumns:a,setFormula:c,colOffset:d}=this.params,p=s&&a?{colOffset:d,flatColumns:a,setFormula:c}:void 0,m=parseTsvClipboard(t),v=applyPastedValues(m,i,r,o,l,p);for(let f of v)e(f);if(this._cutRange){let f=applyCutClear(this._cutRange,o,l);for(let b of f)e(b);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 ne=class{constructor(e,t=100){this.onCellValueChanged=e;this.emitter=new x;this.stack=new UndoRedoStack(t),e&&(this.wrappedCallback=n=>{this.stack.record(n),this.stack.isBatching||this.emitStackChange(),e(n);});}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 n=e[t];this.onCellValueChanged({...n,oldValue:n.newValue,newValue:n.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 ie=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,n)=>{e[n]=t;}),e}startResize(e,t,n){this.isResizing=true,this.resizeColumnId=e,this.resizeStartX=t,this.resizeStartWidth=n;}updateResize(e){if(!this.isResizing||!this.resizeColumnId)return null;let t=e-this.resizeStartX,n=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH;return Math.max(n,this.resizeStartWidth+t)}endResize(e){if(!this.isResizing||!this.resizeColumnId)return;let t=e-this.resizeStartX,n=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH,i=Math.max(n,this.resizeStartWidth+t);this.columnWidths.set(this.resizeColumnId,i),this.emitter.emit("columnWidthChange",{columnId:this.resizeColumnId,widthPx:i}),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,n,i){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=n,this.setActiveCell=i,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 n=this.liveFillRange;n&&n.startRow===t.startRow&&n.startCol===t.startCol&&n.endRow===t.endRow&&n.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 i=this.resolveRange(this.lastMousePos.cx,this.lastMousePos.cy);i&&(this.liveFillRange=i,this.fillDragEnd={endRow:i.endRow,endCol:i.endCol});}this.clearDragAttrs();let e=this.fillDragStart,t=this.fillDragEnd,n=normalizeSelectionRange({startRow:e.startRow,startCol:e.startCol,endRow:t.endRow,endCol:t.endCol});this.setSelectionRange(n),this.setActiveCell({rowIndex:e.startRow,columnIndex:e.startCol+this.params.colOffset}),this.applyFillValuesFromCore(n,e),this._isFillDragging=false,this.fillDragStart=null,this.liveFillRange=null,this.lastMousePos=null,this.emitter.emit("fillRangeChange",{fillRange:null});}applyFillValuesFromCore(e,t){let{items:n,visibleCols:i,onCellValueChanged:r,beginBatch:o,endBatch:l,formulaOptions:s}=this.params;if(!r)return;let a=applyFillValues(e,t.startRow,t.startCol,n,i,s);if(a.length>0){o?.();for(let c of a)r(c);l?.();}}resolveRange(e,t){if(!this.fillDragStart||!this.wrapperRef)return null;let i=document.elementFromPoint(e,t)?.closest?.("[data-row-index][data-col-index]");if(!i||!this.wrapperRef.contains(i))return null;let r=L(i);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 n=this.params.colOffset,i=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 s=0;s<t.length;s++){let a=t[s],c=L(a);if(!c)continue;let d=c.rowIndex,p=c.colIndex-n;d>=i&&d<=r&&p>=o&&p<=l?a.hasAttribute("data-drag-range")||a.setAttribute("data-drag-range",""):a.hasAttribute("data-drag-range")&&a.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,n,i,r,o){if(t.preventDefault(),this._isDragging=true,this._draggedColumnId=e,this._dropIndicatorX=null,this._dropTargetIndex=null,this.tableElement=o,this.columnOrder=i.length>0?[...i]:n.map(l=>l.columnId),r){let l=[],s=[];for(let[a,c]of Object.entries(r))c==="left"?l.push(a):c==="right"&&s.push(a);this.pinnedColumns={left:l,right:s};}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 n=calculateDropTarget({mouseX:t,columnOrder:this.columnOrder,draggedColumnId:this._draggedColumnId,draggedPinState:this.draggedPinState,tableElement:this.tableElement,pinnedColumns:this.pinnedColumns});if(!n)return;let i=this._dropIndicatorX,r=this._dropTargetIndex;this._dropTargetIndex=n.targetIndex,this._dropIndicatorX=n.indicatorX,(i!==n.indicatorX||r!==n.targetIndex)&&this.emitter.emit("stateChange",{isDragging:true,dropIndicatorX:n.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(E,e,t){let n=measureRange(E,e,t);return n?{top:n.top+E.scrollTop,left:n.left+E.scrollLeft,width:n.width,height:n.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 n=getComputedStyle(e).position;(n==="static"||n==="")&&(e.style.position="relative");}update(e,t,n,i){let r=i!==void 0&&i!==this.layoutVersion;r&&i!==void 0&&(this.layoutVersion=i),!(!r&&rangesEqual(this.selectionRange,e)&&rangesEqual(this.copyRange,t)&&rangesEqual(this.cutRange,n))&&(this.selectionRange=e,this.copyRange=t,this.cutRange=n,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,n=this.selectionRange!=null&&e!=null&&rangesEqual(this.selectionRange,e),i=this.selectionRange!=null&&this.selectionRange.startRow===this.selectionRange.endRow&&this.selectionRange.startCol===this.selectionRange.endCol;if(t&&!n&&!i){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 n=document.createElementNS("http://www.w3.org/2000/svg","rect");return n.setAttribute("x","1"),n.setAttribute("y","1"),n.setAttribute("fill","none"),t.appendChild(n),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 se={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"},ae=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,n,i,r,o,l,s,a){this.closeEditor(),this.editingCell={rowId:e,columnId:t},this.editingCellElement=r,this.onCommit=o,this.onCancel=l,this.onAfterCommit=s??null;let c=a!==void 0?a:getCellValue(n,i),d=r.getBoundingClientRect(),p=this.container.getBoundingClientRect(),m=this.createEditor(i,n,c,r);m.style.position="absolute",m.style.left=`${d.left-p.left+this.container.scrollLeft}px`,m.style.top=`${d.top-p.top+this.container.scrollTop}px`,m.style.width=`${d.width}px`,m.style.height=`${d.height}px`,this.editor=m,this.container.appendChild(m),m.focus();let v=m.querySelector('[role="listbox"]');if(v){let b=window.innerHeight-d.bottom,u=b<200&&d.top>b;v.style.position="fixed",v.style.left=`${d.left}px`,v.style.width=`${d.width}px`,v.style.maxHeight="200px",v.style.zIndex="9999",v.style.right="auto",u?(v.style.top="auto",v.style.bottom=`${window.innerHeight-d.top}px`):v.style.top=`${d.bottom}px`;let g=m.closest("[data-ogrid-scroll-container]")??m.closest('[style*="overflow"]'),h=()=>this.closeEditor(),S=requestAnimationFrame(()=>{g&&g.addEventListener("scroll",h,{passive:true}),window.addEventListener("scroll",h,{passive:true});});this.scrollCleanup=()=>{cancelAnimationFrame(S),g&&g.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,n=this.container.querySelector(`tr[data-row-id="${e}"]`);if(n){let i=n.querySelector(`td[data-column-id="${t}"]`);i&&(i.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,n,i){let r=e.cellEditor;if(typeof r=="function"){let o={value:n,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:i,cellEditorParams:e.cellEditorParams};return r(o)}return r==="checkbox"||e.type==="boolean"?this.createCheckboxEditor(n):r==="select"?this.createSelectEditor(n,e):r==="richSelect"?this.createRichSelectEditor(n,e):r==="date"||e.type==="date"?this.createDateEditor(n,e):this.createTextEditor(n)}createInputEditor(e,t){let n=document.createElement("input");return n.type=e,n.value=t,Object.assign(n.style,se),n.addEventListener("keydown",i=>{if(i.key==="Enter"){i.preventDefault(),i.stopPropagation(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value);let r=this.onAfterCommit;this.closeEditor(),r?.();}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();}),n.addEventListener("blur",()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value),this.closeEditor();}),setTimeout(()=>n.select(),0),n}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,se),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",n=>{n.key==="Escape"?(n.preventDefault(),n.stopPropagation(),this.onCancel?.(),this.closeEditor()):["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(n.key)&&n.stopPropagation();}),t}createDateEditor(e,t){let n=t?.cellEditorParams?.dateFormat??t?.dateFormat??"YYYY-MM-DD";if(t?.cellEditorParams?.editorType==="native"){let s="";if(e!=null){let d=String(e).match(/^(\d{4})-(\d{2})-(\d{2})/);d&&(s=`${d[1]}-${d[2]}-${d[3]}`);}return this.createInputEditor("date",s)}let r=e!=null?formatDateForDisplay(e,n)??"":"",o=getDateInputPlaceholder(n);return this.createDateTextEditor(r,o,n)}createDateTextEditor(e,t,n){let i=document.createElement("input");i.type="text",i.value=e,i.placeholder=t,Object.assign(i.style,se);let r=()=>{let l=i.value;if(!l.trim())return "";let s=parseUserInputDate(l,n);if(s instanceof Date){let a=s.getUTCFullYear().toString().padStart(4,"0"),c=(s.getUTCMonth()+1).toString().padStart(2,"0"),d=s.getUTCDate().toString().padStart(2,"0");return `${a}-${c}-${d}`}return l},o=()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,r());};return i.addEventListener("keydown",l=>{if(l.key==="Enter"){l.preventDefault(),l.stopPropagation(),o();let s=this.onAfterCommit;this.closeEditor(),s?.();}else l.key==="Escape"?(l.preventDefault(),l.stopPropagation(),this.onCancel?.(),this.closeEditor()):(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(l.key)||(l.ctrlKey||l.metaKey)&&["c","x","v","a","z","y"].includes(l.key))&&l.stopPropagation();}),i.addEventListener("blur",()=>{o(),this.closeEditor();}),setTimeout(()=>i.select(),0),i}createSelectEditor(e,t){let n=t.cellEditorParams?.values??[],i=t.cellEditorParams?.formatValue,r=f=>i?i(f):f!=null?String(f):"",o=document.createElement("div");Object.assign(o.style,se),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 s=document.createElement("span");s.textContent=r(e),l.appendChild(s);let a=document.createElement("span");a.textContent="\u25BE",a.style.marginLeft="4px",a.style.fontSize="10px",a.style.opacity="0.5",l.appendChild(a),o.appendChild(l);let c=document.createElement("div");c.setAttribute("role","listbox"),c.style.position="absolute",c.style.top="100%",c.style.left="0",c.style.right="0",c.style.maxHeight="200px",c.style.overflowY="auto",c.style.backgroundColor="var(--ogrid-bg, #fff)",c.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",c.style.zIndex="1001",c.style.boxShadow="0 4px 16px rgba(0,0,0,0.2)",c.style.textAlign="left",c.style.fontSize="13px",c.style.fontFamily="inherit",o.appendChild(c);let d=Math.max(n.findIndex(f=>String(f)===String(e)),0),p=()=>{c.innerHTML="";for(let f=0;f<n.length;f++){let b=n[f],u=document.createElement("div");u.setAttribute("role","option"),u.setAttribute("aria-selected",String(f===d)),u.textContent=r(b),u.style.padding="6px 8px",u.style.cursor="pointer",u.style.color="var(--ogrid-fg, #242424)",u.style.fontSize="13px",f===d&&(u.style.background="var(--ogrid-bg-hover, #e8f0fe)"),u.addEventListener("mousedown",g=>{g.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,b),this.closeEditor();}),c.appendChild(u);}},m=(f,b)=>{let u=c.children[f],g=c.children[b];u&&(u.style.background="",u.setAttribute("aria-selected","false")),g&&(g.style.background="var(--ogrid-bg-hover, #e8f0fe)",g.setAttribute("aria-selected","true"));},v=()=>{c.children[d]?.scrollIntoView({block:"nearest"});};return p(),o.addEventListener("keydown",f=>{switch(f.stopPropagation(),f.key){case "ArrowDown":{f.preventDefault();let b=d;d=Math.min(d+1,n.length-1),m(b,d),v();break}case "ArrowUp":{f.preventDefault();let b=d;d=Math.max(d-1,0),m(b,d),v();break}case "Enter":if(f.preventDefault(),f.stopPropagation(),n.length>0&&d<n.length){this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n[d]);let b=this.onAfterCommit;this.closeEditor(),b?.();}break;case "Tab":f.preventDefault(),n.length>0&&d<n.length&&(this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n[d]),this.closeEditor());break;case "Escape":f.preventDefault(),f.stopPropagation(),this.onCancel?.(),this.closeEditor();break}}),o}createRichSelectEditor(e,t){let n=t.cellEditorParams?.values??[],i=t.cellEditorParams?.formatValue??(u=>String(u)),r=u=>u!=null?String(i(u)):"",o=document.createElement("div");Object.assign(o.style,se),o.style.padding="6px 10px",o.style.display="flex",o.style.alignItems="center";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 s=document.createElement("span");s.textContent=r(e),l.appendChild(s);let a=document.createElement("span");a.textContent="\u25BE",a.style.marginLeft="4px",a.style.fontSize="10px",a.style.opacity="0.5",l.appendChild(a),o.appendChild(l);let c=document.createElement("div");c.setAttribute("role","listbox"),c.style.position="absolute",c.style.top="100%",c.style.left="0",c.style.width="100%",c.style.maxHeight="200px",c.style.overflowY="auto",c.style.backgroundColor="var(--ogrid-bg, #fff)",c.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",c.style.zIndex="1001",c.style.textAlign="left",c.style.boxShadow="0 4px 16px rgba(0,0,0,0.2)",c.style.fontSize="13px",c.style.fontFamily="inherit";let d=document.createElement("input");d.type="text",d.placeholder="Search...",d.style.width="100%",d.style.padding="6px 8px",d.style.border="none",d.style.borderBottom="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",d.style.outline="none",d.style.boxSizing="border-box",d.style.background="var(--ogrid-bg, #fff)",d.style.color="var(--ogrid-fg, rgba(0, 0, 0, 0.87))",d.style.font="inherit",d.style.fontSize="13px",d.style.position="sticky",d.style.top="0",d.style.zIndex="1",c.appendChild(d);let p=document.createElement("div");c.appendChild(p),o.appendChild(c);let m=Math.max(n.findIndex(u=>String(u)===String(e)),0),v=[...n],f=u=>{p.innerHTML="",v=n.filter(g=>String(i(g)).toLowerCase().includes(u.toLowerCase())),m=Math.min(m,Math.max(v.length-1,0));for(let g=0;g<v.length;g++){let h=v[g],S=document.createElement("div");S.textContent=String(i(h)),S.style.padding="6px 8px",S.style.cursor="pointer",S.style.color="var(--ogrid-fg, #242424)",S.style.fontSize="13px",g===m&&(S.style.background="var(--ogrid-bg-hover, #e8f0fe)"),S.addEventListener("mousedown",I=>{I.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,h),this.closeEditor();}),S.addEventListener("mouseenter",()=>{S.style.backgroundColor="var(--ogrid-bg-hover, #e8f0fe)";},{passive:true}),S.addEventListener("mouseleave",()=>{S.style.backgroundColor="";},{passive:true}),p.appendChild(S);}},b=(u,g)=>{let h=p.children[u],S=p.children[g];h&&(h.style.background=""),S&&(S.style.background="var(--ogrid-bg-hover, #e8f0fe)",S.scrollIntoView({block:"nearest"}));};return d.addEventListener("input",()=>{f(d.value);}),d.addEventListener("keydown",u=>{switch(u.key){case "ArrowDown":{u.preventDefault(),u.stopPropagation();let g=m;m=Math.min(m+1,v.length-1),b(g,m);break}case "ArrowUp":{u.preventDefault(),u.stopPropagation();let g=m;m=Math.max(m-1,0),b(g,m);break}case "Enter":if(u.preventDefault(),u.stopPropagation(),v.length>0&&m<v.length){this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,v[m]);let g=this.onAfterCommit;this.closeEditor(),g?.();}break;case "Escape":u.preventDefault(),u.stopPropagation(),this.onCancel?.(),this.closeEditor();break;case "ArrowLeft":case "ArrowRight":u.stopPropagation();break;default:(u.ctrlKey||u.metaKey)&&["c","x","v","a","z","y"].includes(u.key)&&u.stopPropagation();break}}),d.addEventListener("blur",u=>{let g=u.relatedTarget;g&&this.editor?.contains(g)||(this.onCancel?.(),this.closeEditor());}),f(""),setTimeout(()=>d.focus(),0),o}destroy(){this.closeEditor();}};var Bt={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)"},Ot={padding:"6px 12px",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},Pt={height:"1px",backgroundColor:"var(--ogrid-border, #e0e0e0)",margin:"4px 0"},de=class{constructor(){this.menu=null;this.handlers=null;}show(e,t,n,i,r,o){this.close(),this.handlers=n,this.menu=document.createElement("div"),Object.assign(this.menu.style,Bt),this.menu.style.left=`${e}px`,this.menu.style.top=`${t}px`;for(let s of GRID_CONTEXT_MENU_ITEMS){if(s.dividerBefore){let p=document.createElement("div");Object.assign(p.style,Pt),this.menu.appendChild(p);}let a=document.createElement("div");Object.assign(a.style,Ot);let c=document.createElement("span");if(c.textContent=s.label,a.appendChild(c),s.shortcut){let p=document.createElement("span");p.textContent=formatShortcut(s.shortcut),p.style.marginLeft="20px",p.style.color="var(--ogrid-muted, #666)",p.style.fontSize="12px",a.appendChild(p);}s.id==="undo"&&!i||s.id==="redo"&&!r||s.disabledWhenNoSelection&&o==null?(a.style.color="var(--ogrid-fg-muted, rgba(0, 0, 0, 0.4))",a.style.opacity="0.5",a.style.cursor="not-allowed"):(a.addEventListener("mouseenter",()=>{a.style.backgroundColor="var(--ogrid-bg-hover, #f5f5f5)";},{passive:true}),a.addEventListener("mouseleave",()=>{a.style.backgroundColor="";},{passive:true}),a.addEventListener("click",()=>{this.handleItemClick(s.id);},{passive:true})),this.menu.appendChild(a);}document.body.appendChild(this.menu);let l=s=>{this.menu&&!this.menu.contains(s.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 ce=class{initializeInteraction(e,t,n,i,r,o,l,s){let{editable:a}=e,c=o?1:0,d=[],p=new Q,m=new ie,v=new de,f=new ae(i),b=e.onCellValueChanged,u=new ne(b),g=new te({items:[],visibleCols:[],colOffset:c,editable:a,onCellValueChanged:u.getWrappedCallback()},()=>p.activeCell??null,()=>p.selectionRange??null),h=new oe({items:[],visibleCols:[],editable:a,onCellValueChanged:u.getWrappedCallback(),colOffset:c,beginBatch:()=>u.beginBatch(),endBatch:()=>u.endBatch()},()=>p.selectionRange??null,w=>{p.setSelectionRange(w),s.updateRendererInteractionState();},w=>{p.setActiveCell(w);}),S=new ee({items:[],visibleCols:[],colOffset:c,getRowId:t.getRowId,editable:a,onCellValueChanged:u.getWrappedCallback(),onCopy:()=>g.handleCopy(),onCut:()=>g.handleCut(),onPaste:async()=>{await g.handlePaste();},onUndo:()=>u.undo(),onRedo:()=>u.redo(),onContextMenu:(w,T)=>s.showContextMenu(w,T),onStartEdit:(w,T)=>s.startCellEdit(w,T),clearClipboardRanges:()=>g.clearClipboardRanges()},()=>p.activeCell??null,()=>p.selectionRange??null,w=>p.setActiveCell(w),w=>p.setSelectionRange(w));d.push(p.onSelectionChange(()=>{s.updateRendererInteractionState();})),d.push(g.onRangesChange(()=>{s.updateRendererInteractionState();})),d.push(m.onColumnWidthChange(()=>{s.updateRendererInteractionState();}));let I=new re;d.push(I.onStateChange(({isDragging:w,dropIndicatorX:T})=>{n.updateDropIndicator(T,w);})),d.push(I.onReorder(({columnOrder:w})=>{t.setColumnOrder(w);}));let y=n.getWrapperElement(),R=null;y&&(y.addEventListener("keydown",S.handleKeyDown),S.setWrapperRef(y),h.setWrapperRef(y),R=new le(y,c));let k=this.attachGlobalHandlers(p,m,r,n,s);return d.push(...k),{selectionState:p,keyboardNavState:S,clipboardState:g,undoRedoState:u,resizeState:m,fillHandleState:h,reorderState:I,marchingAnts:R,cellEditor:f,contextMenu:v,unsubscribes:d}}attachGlobalHandlers(e,t,n,i,r){let o=[],l=false,s=d=>{if(l&&t){let p=t.updateResize(d.clientX);p!==null&&t.resizingColumnId&&(n.setColumnOverride(t.resizingColumnId,p),r.updateRendererInteractionState());}if(e?.isDragging){let p=d.target;if(p.tagName==="TD"){let m=L(p);m&&m.rowIndex>=0&&m.colIndex>=0&&e.updateDrag(m.rowIndex,m.colIndex,()=>r.updateDragAttributes());}}},a=d=>{if(l&&t){let p=t.resizingColumnId;if(t.endResize(d.clientX),p){let m=t.getColumnWidth(p);m&&n.setColumnOverride(p,m);}l=false,document.body.style.cursor="",r.updateRendererInteractionState();}e?.isDragging&&(e.endDrag(),r.clearCachedDragCells());},c=(d,p,m)=>{l=true,document.body.style.cursor="col-resize",t.startResize(d,p,m);};return document.addEventListener("pointermove",s,{passive:true}),document.addEventListener("pointerup",a,{passive:true}),o.push(()=>{document.removeEventListener("pointermove",s),document.removeEventListener("pointerup",a);}),i.setInteractionState({activeCell:null,selectionRange:null,copyRange:null,cutRange:null,editingCell:null,columnWidths:{},onResizeStart:c}),o}};var ue=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:n,state:i,layoutState:r,pinningState:o,rowSelectionState:l,cellEditor:s,renderer:a,reorderState:c,marchingAnts:d,fillHandleState:p,options:m}=this.ctx;if(!e||!t||!n)return;let{items:v}=i.getProcessedItems(),f=i.visibleColumnDefs,b=r.getAllColumnWidths(),u=o?.computeLeftOffsets(f,b,120,!!l,CHECKBOX_COLUMN_WIDTH,!!m.showRowNumbers)??{},g=o?.computeRightOffsets(f,b,120)??{};a.setInteractionState({activeCell:e.activeCell,selectionRange:e.selectionRange,copyRange:t.copyRange,cutRange:t.cutRange,editingCell:s?.getEditingCell()??null,columnWidths:b,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:a.getOnResizeStart(),onResizeDoubleClick:h=>{let I=f.find(k=>k.columnId===h)?.minWidth??DEFAULT_MIN_COLUMN_WIDTH,y=a.getTableElement()?.parentElement??void 0,R=measureColumnContentWidth(h,I,y);n.setColumnWidth(h,R);},onBooleanToggle:m.editable!==false?(h,S,I)=>this.ctx.toggleBooleanCell(h,S,I):void 0,onFillHandleMouseDown:m.editable!==false?h=>p?.startFillDrag(h):void 0,rowSelectionMode:l?.rowSelection??"none",selectedRowIds:l?.selectedRowIds,onRowCheckboxChange:(h,S,I,y)=>{l?.handleRowCheckboxChange(h,S,I,y,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:u,rightOffsets:g,onColumnReorderStart:c?(h,S)=>{let I=a.getTableElement();I&&c?.startDrag(h,S,f,i.columnOrder,o?.pinnedColumns,I);}:void 0}),a.update(),d?.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 n=t.getDragRange();if(!n)return;let i=normalizeSelectionRange(n),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 a=o[l],c=L(a);if(!c)continue;let d=c.rowIndex,p=c.colIndex;isInSelectionRange(i,d,p)?(a.setAttribute("data-drag-range","true"),r&&d===r.rowIndex&&p===r.columnIndex?a.setAttribute("data-drag-anchor",""):a.removeAttribute("data-drag-anchor"),a.classList.add("ogrid-drag-target")):(a.removeAttribute("data-drag-range"),a.removeAttribute("data-drag-anchor"),a.classList.remove("ogrid-drag-target"));}}renderAll(){this.layoutVersion++;let{state:e,options:t,headerFilterState:n,rowSelectionState:i,keyboardNavState:r,clipboardState:o,undoRedoState:l,fillHandleState:s,virtualScrollState:a,pagination:c,statusBar:d,columnChooser:p,renderer:m}=this.ctx,v=i?1:0;n.setFilters(e.filters),n.setFilterOptions(e.filterOptions);let{items:f,totalCount:b}=e.getProcessedItems();if(r&&o){let u=e.visibleColumnDefs;r.updateParams({items:f,visibleCols:u,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:(g,h)=>this.ctx.showContextMenu(g,h),onStartEdit:(g,h)=>this.ctx.startCellEdit(g,h),clearClipboardRanges:()=>o?.clearClipboardRanges(),onKeyDown:t.onKeyDown,onFillDown:s?()=>s.fillDown():void 0}),o.updateParams({items:f,visibleCols:u,colOffset:v,editable:t.editable,onCellValueChanged:l?.getWrappedCallback()}),s?.updateParams({items:f,visibleCols:u,editable:t.editable,onCellValueChanged:l?.getWrappedCallback(),colOffset:v,beginBatch:()=>l?.beginBatch(),endBatch:()=>l?.endBatch()}),this.updateRendererInteractionState();}else m.update();a?.setTotalRows(b),c.render(b,t.pageSizeOptions),d.render({totalCount:b}),p.render(),this.renderSideBar(),this.renderLoadingOverlay();}renderHeaderFilterPopover(){let{headerFilterState:e,headerFilterComponent:t,filterConfigs:n}=this.ctx,i=e.openColumnId,r=this.ctx.tableContainer.querySelectorAll(".ogrid-filter-icon[aria-haspopup]");for(let s of r){let a=s.closest("th[data-column-id]")?.getAttribute("data-column-id");s.setAttribute("aria-expanded",a===i?"true":"false");}if(!i){t.cleanup();return}let o=n.get(i);if(!o)return;t.render(o);let l=document.querySelector(".ogrid-header-filter-popover");e.setPopoverEl(l);}renderSideBar(){let{sideBarComponent:e,sideBarState:t,state:n}=this.ctx;if(!e||!t)return;let i=n.columns.map(o=>({columnId:o.columnId,name:o.name,required:o.required===true})),r=n.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:i,visibleColumns:n.visibleColumns,onVisibilityChange:(o,l)=>{let s=new Set(n.visibleColumns);l?s.add(o):s.delete(o),n.setVisibleColumns(s);},onSetVisibleColumns:o=>n.setVisibleColumns(o),filterableColumns:r,filters:n.filters,onFilterChange:(o,l)=>n.setFilter(o,l),filterOptions:n.filterOptions}),e.render();}renderLoadingOverlay(){let{state:e,tableContainer:t}=this.ctx;if(e.isLoading){let{items:n}=e.getProcessedItems();t.style.minHeight=!n||n.length===0?"200px":"";let i=this.ctx.loadingOverlay;if(!i){i=document.createElement("div"),i.className="ogrid-loading-overlay",i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.right="0",i.style.bottom="0",i.style.display="flex",i.style.alignItems="center",i.style.justifyContent="center",i.style.background="var(--ogrid-loading-overlay, rgba(255, 255, 255, 0.7))",i.style.zIndex="100";let r=document.createElement("div");r.className="ogrid-loading-spinner",r.textContent="Loading...",i.appendChild(r),this.ctx.setLoadingOverlay(i);}t.contains(i)||t.appendChild(i);}else {t.style.minHeight="";let n=this.ctx.loadingOverlay;n&&t.contains(n)&&n.remove();}}};var he=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,n]of Object.entries(e.sheets))this.engine.registerSheet(t,n);}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,n,i){if(!this.engine)return;let r=this.engine.setFormula(e,t,n,i);return r.updatedCells.length>0&&this.emitRecalc(r),r}onCellChanged(e,t,n){if(!this.engine)return;let i=this.engine.onCellChanged(e,t,n);return i.updatedCells.length>0&&this.emitRecalc(i),i}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 pe=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 Xt=`
|
|
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,estimateHeaderMinWidth,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,formatDateForDisplay,getDateInputPlaceholder,GRID_CONTEXT_MENU_ITEMS,formatShortcut,measureColumnContentWidth,formatCellReference,measureRange,parseUserInputDate}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(E){let e=E.getAttribute("data-row-index"),t=E.getAttribute("data-col-index");if(e==null||t==null)return null;let n=parseInt(e,10),i=parseInt(t,10);return Number.isNaN(n)||Number.isNaN(i)?null:{rowIndex:n,colIndex:i}}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 n=t[0];this.handlers.get(e)?.forEach(i=>{i(n);});}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._sortedIndices=null;this._sortDirty=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(n=>this._visibleColumns.has(n.columnId)),t=applyResponsiveHiding(e,this._containerWidth,this._responsiveColumns??void 0);if(this._columnOrder.length===0)this._visibleColsCache=t;else {let n=new Map(this._columnOrder.map((i,r)=>[i,r]));this._visibleColsCache=[...t].sort((i,r)=>{let o=n.get(i.columnId)??1/0,l=n.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;if(this._sortDirty||this._sortedIndices===null){let o=processClientSideData(this._data,this._columns,this._filters,this._sort?.field,this._sort?.direction),l=new Map;for(let s=0;s<this._data.length;s++)l.set(this._data[s],s);this._sortedIndices=o.map(s=>{let a=l.get(s);return a!==void 0?a:-1}).filter(s=>s!==-1),this._sortDirty=false,e=o;}else e=this._sortedIndices.map(o=>this._data[o]).filter(o=>o!==void 0);let t=e.length,n=(this._page-1)*this._pageSize,i=n+this._pageSize;return {items:e.slice(n,i),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();if(!this._sortDirty&&this._sortedIndices!==null){let l=this._sortedIndices.map(d=>this._data[d]).filter(d=>d!==void 0),s=l.length,a=(this._page-1)*this._pageSize,c=a+this._pageSize;return {items:l.slice(a,c),totalCount:s}}let e=await processClientSideDataAsync(this._data,this._columns,this._filters,this._sort?.field,this._sort?.direction),t=new Map;for(let l=0;l<this._data.length;l++)t.set(this._data[l],l);this._sortedIndices=e.map(l=>{let s=t.get(l);return s!==void 0?s:-1}).filter(l=>l!==-1),this._sortDirty=false;let n=e.length,i=(this._page-1)*this._pageSize,r=i+this._pageSize;return {items:e.slice(i,r),totalCount:n}}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(n=>{e!==this._fetchId||t.signal.aborted||(this._serverItems=n.items,this._serverTotalCount=n.totalCount,this._isLoading=false,!this._firstDataRendered&&n.items.length>0&&(this._firstDataRendered=true,validateRowIds(n.items,this._getRowId),this._onFirstDataRendered?.()),this.emitter.emit("stateChange",{type:"data"}));}).catch(n=>{e!==this._fetchId||t.signal.aborted||(this._onError?.(n),this._serverItems=[],this._serverTotalCount=0,this._isLoading=false,this.emitter.emit("stateChange",{type:"data"}));});}setData(e){let t=this._data.length;this._data=e,this.isServerSide||(this._filterOptions=deriveFilterOptionsFromData(e,this._columns)),e.length!==t&&(this._sortDirty=true),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._sortDirty=true,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._sortDirty=true,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"sort"});}setFilter(e,t){this._filters=mergeFilter(this._filters,e,t),this._page=1,this._sortDirty=true,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});}clearFilters(){this._filters={},this._page=1,this._sortDirty=true,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:n}=this.getProcessedItems(),i=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(n,i,(o,l)=>{let s=this._columns.find(c=>c.columnId===l);if(!s)return "";let a=getCellValue(o,s);return s.valueFormatter?s.valueFormatter(a,o):a!=null?String(a):""},e,r);}}}setFormulaEngine(e){this._formulaEngine=e;}destroy(){this._abortController&&(this._abortController.abort(),this._abortController=null),this.emitter.removeAllListeners();}};function P(E){return {minR:Math.min(E.startRow,E.endRow),maxR:Math.max(E.startRow,E.endRow),minC:Math.min(E.startCol,E.endCol),maxC:Math.max(E.startCol,E.endCol)}}function M(E,e,t){return e>=E.minR&&e<=E.maxR&&t>=E.minC&&t<=E.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 n=e.target.closest("td[data-row-index]");if(!n)return null;let i=L(n);return i?{el:n,rowIndex:i.rowIndex,colIndex:i.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 n=this.getCellFromEvent(e);n&&this.interactionState?.onCellMouseDown?.({rowIndex:n.rowIndex,colIndex:n.colIndex,event:e});},this._tbodyDblclickHandler=e=>{let t=this.getCellFromEvent(e);if(!t)return;let n=t.el.getAttribute("data-column-id")??"",{items:i}=this.state.getProcessedItems(),r=i[t.rowIndex];if(!r)return;let o=this.state.getRowId(r);this.interactionState?.onCellDoubleClick?.({rowIndex:t.rowIndex,colIndex:t.colIndex,rowId:o,columnId:n});},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 n=t.getAttribute("data-column-id"),i=t.closest("th[data-column-id]"),r=n??i?.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 n=t.closest("th[data-column-id]");if(!n)return;let i=n.getAttribute("data-column-id");i&&this.interactionState.onColumnReorderStart(i,e);}},this._theadDblclickHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-resize-handle")){e.stopPropagation();let n=t.getAttribute("data-column-id"),i=t.closest("th[data-column-id]"),r=n??i?.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,n=[];for(let r of e)n.push(r.columnId),n.push(r.name),n.push(t?.columnWidths[r.columnId]?.toString()??"");let i=this.state.sort;i&&n.push(`sort:${i.field}:${i.direction}`),n.push(`sel:${t?.rowSelectionMode??""}`),n.push(`allSel:${t?.allSelected??""}`),n.push(`someSel:${t?.someSelected??""}`),n.push(`rn:${t?.showRowNumbers??""}`),t?.showRowNumbers&&n.push(`rnw:${t?.columnWidths[ROW_NUMBER_COLUMN_ID]??""}`),n.push(`cl:${t?.showColumnLetters??""}`);for(let[r,o]of this.filterConfigs)this.headerFilterState?.hasActiveFilter(o)&&n.push(`flt:${r}`);return n.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 i=e?.editingCell,r=this.lastEditingCell;if(i?.rowId!==r?.rowId||i?.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 s of o)if(!l.has(s))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:n,copyRange:i,cutRange:r}=e,o=this.lastActiveCell,l=this.lastSelectionRange,s=this.lastCopyRange,a=this.lastCutRange,c=n?P(n):null,d=l?P(l):null,p=i?P(i):null,m=s?P(s):null,v=r?P(r):null,f=a?P(a):null,S=this.getColOffset(),u=this.tbody.querySelectorAll("td[data-row-index][data-col-index]");for(let g=0;g<u.length;g++){let h=u[g],y=L(h);if(!y)continue;let I=y.rowIndex,b=y.colIndex,R=b-S,k=o&&o.rowIndex===I&&o.columnIndex===b,w=t&&t.rowIndex===I&&t.columnIndex===b;k&&!w?(h.removeAttribute("data-active-cell"),h.style.outline="",h.style.zIndex=""):w&&!k&&(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=d&&M(d,I,R),C=c&&M(c,I,R),_=C&&!w,F=T&&!(o&&o.rowIndex===I&&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 D=m&&M(m,I,R),H=p&&M(p,I,R);D&&!H?!w&&!(v&&M(v,I,R))&&(h.style.outline=""):H&&!D&&(h.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))");let be=f&&M(f,I,R),O=v&&M(v,I,R);be&&!O?!w&&!(p&&M(p,I,R))&&(h.style.outline=""):O&&!be&&(h.style.outline="1px dashed var(--ogrid-accent, #0078d4)");let Ie=h.querySelector(".ogrid-fill-handle"),xe=n&&e.onFillHandleMouseDown&&I===Math.max(n.startRow,n.endRow)&&R===Math.max(n.startCol,n.endCol),_e=!!Ie;if(_e&&!xe)Ie?.remove();else if(!_e&&xe){let A=document.createElement("div");A.className="ogrid-fill-handle",A.setAttribute("data-fill-handle","true"),A.style.position="absolute",A.style.right="-3px",A.style.bottom="-3px",A.style.width="6px",A.style.height="6px",A.style.backgroundColor="var(--ogrid-selection, #217346)",A.style.cursor="crosshair",A.style.zIndex="5",h.style.position=h.style.position||"relative",A.addEventListener("pointerdown",Ue=>{this.interactionState?.onFillHandleMouseDown?.(Ue);}),h.appendChild(A);}if(!C&&e.pinnedColumns){let A=h.getAttribute("data-column-id");A&&e.pinnedColumns[A]&&(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,n){let i=this.interactionState;if(!i?.pinnedColumns)return;let r=i.pinnedColumns[t];r&&(e.style.position="sticky",e.style.zIndex=n?"3":"1",e.setAttribute("data-pinned",r),r==="left"&&i.leftOffsets?e.style.left=`${i.leftOffsets[t]??0}px`:r==="right"&&i.rightOffsets&&(e.style.right=`${i.rightOffsets[t]??0}px`),n||(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(),n=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(n){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 i=buildHeaderRows(this.state.allColumns,this.state.visibleColumns);if(i.length>1)for(let r=0;r<i.length;r++){let o=i[r],l=r===i.length-1,s=document.createElement("tr");if(t){let a=document.createElement("th");a.className="ogrid-header-cell ogrid-checkbox-header",a.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,l&&this.appendSelectAllCheckbox(a),s.appendChild(a);}if(n){if(l){let a=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,c=document.createElement("th");c.className="ogrid-header-cell ogrid-row-number-header",c.style.width=`${a}px`,c.style.minWidth=`${a}px`,c.style.maxWidth=`${a}px`,c.style.textAlign="center",c.style.position=c.style.position||"relative",c.textContent="#";let d=document.createElement("div");d.className="ogrid-resize-handle",d.style.position="absolute",d.style.right="0",d.style.top="0",d.style.bottom="0",d.style.width="4px",d.style.cursor="col-resize",d.style.userSelect="none",d.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),c.appendChild(d),s.appendChild(c);}else if(r===0){let a=document.createElement("th");a.rowSpan=i.length-1,a.style.padding="0",s.appendChild(a);}}for(let a of o){let c=document.createElement("th");if(c.textContent=a.label,c.className=a.isGroup?"ogrid-group-header":"ogrid-header-cell",a.colSpan>1&&(c.colSpan=a.colSpan),!a.isGroup&&a.columnDef?.sortable&&(c.classList.add("ogrid-sortable"),c.addEventListener("click",()=>{a.columnDef&&this.state.toggleSort(a.columnDef.columnId);})),!a.isGroup&&a.columnDef){c.setAttribute("data-column-id",a.columnDef.columnId),c.setAttribute("scope","col");let d=this.state.sort;d?.field===a.columnDef.columnId&&c.setAttribute("aria-sort",d.direction==="asc"?"ascending":"descending"),this.applyPinningStyles(c,a.columnDef.columnId,true);}s.appendChild(c);}this.thead?.appendChild(s);}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 s=document.createElement("div");s.className="ogrid-resize-handle",s.style.position="absolute",s.style.right="0",s.style.top="0",s.style.bottom="0",s.style.width="4px",s.style.cursor="col-resize",s.style.userSelect="none",s.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),l.appendChild(s),r.appendChild(l);}for(let o=0;o<e.length;o++){let l=e[o],s=document.createElement("th");s.className="ogrid-header-cell",s.setAttribute("data-column-id",l.columnId),s.setAttribute("scope","col");let a=this.state.sort;a?.field===l.columnId&&s.setAttribute("aria-sort",a.direction==="asc"?"ascending":"descending");let c=document.createElement("span");c.textContent=l.name,s.appendChild(c),l.sortable&&(s.classList.add("ogrid-sortable"),s.addEventListener("click",()=>this.state.toggleSort(l.columnId))),l.type==="numeric"&&(s.style.textAlign="right"),this.interactionState?.columnWidths[l.columnId]?s.style.width=`${this.interactionState.columnWidths[l.columnId]}px`:l.minWidth==null&&(s.style.minWidth=`${estimateHeaderMinWidth(l.name)}px`),this.applyPinningStyles(s,l.columnId,true);let d=document.createElement("div");d.className="ogrid-resize-handle",d.style.position="absolute",d.style.right="0",d.style.top="0",d.style.bottom="0",d.style.width="4px",d.style.cursor="col-resize",d.style.userSelect="none",s.style.position=s.style.position||"relative",s.appendChild(d);let p=this.filterConfigs.get(l.columnId);if(p&&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(p);m.textContent=v?"\u25BC":"\u25BD",v&&(m.style.opacity="1",m.style.color="var(--ogrid-selection, #217346)"),m.addEventListener("click",f=>{f.stopPropagation(),f.preventDefault(),this.onFilterIconClick?.(l.columnId,s);}),s.appendChild(m);}r.appendChild(s);}this.thead?.appendChild(r);}}appendSelectAllCheckbox(e){let t=this.interactionState;if(t?.rowSelectionMode!=="multiple")return;let n=document.createElement("input");n.type="checkbox",n.className="ogrid-select-all-checkbox",n.checked=t?.allSelected===true,n.indeterminate=t?.someSelected===true,n.setAttribute("aria-label","Select all rows"),n.addEventListener("change",()=>{t?.onSelectAll?.(n.checked);}),e.appendChild(n);}renderBody(){if(!this.tbody)return;let e=this.state.visibleColumnDefs,{items:t}=this.state.getProcessedItems(),n=this.hasCheckboxColumn(),i=this.hasRowNumbersColumn(),r=this.getColOffset(),o=e.length+r,l=i?(this.state.page-1)*this.state.pageSize:0;if(t.length===0&&!this.state.isLoading){let u=document.createElement("tr"),g=document.createElement("td");g.colSpan=o,g.className="ogrid-empty-state",g.textContent="No data",u.appendChild(g),this.tbody.appendChild(u);return}let s=this.virtualScrollState,a=s?.enabled===true,c=0,d=t.length-1;if(a){let u=s?.visibleRange;if(!u)return;if(c=Math.max(0,u.startIndex),d=Math.min(t.length-1,u.endIndex),u.offsetTop>0){let g=document.createElement("tr");g.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${u.offsetTop}px`,h.style.padding="0",h.style.border="none",g.appendChild(h),this.tbody.appendChild(g);}}let p=s?.columnVirtualizationEnabled===true&&s.columnRange!=null,m=e,v=null,f=0,S=0;if(p&&s){let u=partitionColumnsForVirtualization(e,s.columnRange,this.interactionState?.pinnedColumns),g=[...u.pinnedLeft,...u.virtualizedUnpinned,...u.pinnedRight];v=g.map(h=>e.indexOf(h)),m=g,f=u.leftSpacerWidth,S=u.rightSpacerWidth;}for(let u=c;u<=d;u++){let g=t[u];if(!g)continue;let h=this.state.getRowId(g),y=document.createElement("tr");y.className="ogrid-row",y.setAttribute("data-row-id",String(h));let I=this.interactionState?.selectedRowIds?.has(h)===true;if(I&&(y.setAttribute("data-row-selected","true"),y.setAttribute("aria-selected","true")),n){let b=document.createElement("td");b.className="ogrid-cell ogrid-checkbox-cell",b.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,b.style.textAlign="center";let R=document.createElement("input");R.type="checkbox",R.className="ogrid-row-checkbox",R.checked=I,R.setAttribute("aria-label",`Select row ${h}`),R.addEventListener("click",k=>{k.stopPropagation(),this.interactionState?.onRowCheckboxChange?.(h,R.checked,u,k.shiftKey);}),b.appendChild(R),y.appendChild(b);}if(i){let b=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,R=document.createElement("td");R.className="ogrid-cell ogrid-row-number-cell",R.style.width=`${b}px`,R.style.minWidth=`${b}px`,R.style.maxWidth=`${b}px`,R.style.textAlign="center",R.style.color="var(--ogrid-fg-muted, #666)",R.style.fontSize="0.9em",R.textContent=String(l+u+1),y.appendChild(R);}if(f>0){let b=document.createElement("td");b.style.width=`${f}px`,b.style.minWidth=`${f}px`,b.style.padding="0",b.style.border="none",b.setAttribute("aria-hidden","true"),y.appendChild(b);}for(let b=0;b<m.length;b++){let R=m[b],k=(v?v[b]:b)+r,w=document.createElement("td");if(w.className="ogrid-cell",w.setAttribute("data-column-id",R.columnId),w.setAttribute("data-row-index",String(u)),w.setAttribute("data-col-index",String(k)),w.setAttribute("tabindex","-1"),R.type==="numeric"&&(w.style.textAlign="right"),this.applyPinningStyles(w,R.columnId,false),this.interactionState){let{activeCell:T,selectionRange:C,copyRange:_,cutRange:F,editingCell:D}=this.interactionState;T&&T.rowIndex===u&&T.columnIndex===k&&(w.setAttribute("data-active-cell","true"),w.style.outline="2px solid var(--ogrid-accent, #0078d4)",w.style.position="relative",w.style.zIndex="var(--ogrid-z-active-cell, 2)"),C&&isInSelectionRange(C,u,b)&&(w.setAttribute("data-in-range","true"),w.style.backgroundColor="var(--ogrid-range-bg, rgba(33, 115, 70, 0.12))"),_&&isInSelectionRange(_,u,b)&&(w.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))"),F&&isInSelectionRange(F,u,b)&&(w.style.outline="1px dashed var(--ogrid-accent, #0078d4)"),D&&D.rowId===h&&D.columnId===R.columnId&&(w.style.visibility="hidden");}if(R.renderCell){let T=getCellValue(g,R),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(b,u)?this.formulaEngine.getValue(b,u)??T:T;R.renderCell(w,g,C);}else {let T=getCellValue(g,R),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(b,u)?this.formulaEngine.getValue(b,u)??T:T;if(R.type==="boolean"){let _=!!C,F=!!R.editable,D=document.createElement("input");D.type="checkbox",D.checked=_,D.disabled=!F,D.style.margin="0",D.style.cursor=F?"pointer":"default",D.style.outline="none",D.setAttribute("aria-label",_?"Checked":"Unchecked"),D.addEventListener("pointerdown",H=>{H.stopPropagation(),this.interactionState?.onCellMouseDown?.({rowIndex:u,colIndex:b,event:H});}),F&&(D.addEventListener("change",()=>{this.interactionState?.onBooleanToggle?.(h,R.columnId,_);}),D.addEventListener("click",H=>H.stopPropagation())),w.appendChild(D);}else R.valueFormatter?w.textContent=R.valueFormatter(C,g):C!=null&&(w.textContent=String(C));}if(R.cellStyle){let T=typeof R.cellStyle=="function"?R.cellStyle(g):R.cellStyle;T&&Object.assign(w.style,T);}if(this.interactionState){let{selectionRange:T}=this.interactionState;if(T&&this.interactionState.onFillHandleMouseDown&&u===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",w.style.position=w.style.position||"relative",w.appendChild(C);}}y.appendChild(w);}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"),y.appendChild(b);}this.tbody.appendChild(y);}if(a&&s){let u=s.visibleRange;if(u.offsetBottom>0){let g=document.createElement("tr");g.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${u.offsetBottom}px`,h.style.padding="0",h.style.border="none",g.appendChild(h),this.tbody.appendChild(g);}}}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 n=this.wrapperEl.getBoundingClientRect(),i=e-n.left+this.wrapperEl.scrollLeft;this.dropIndicator.style.display="block",this.dropIndicator.style.left=`${i}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 n=getPaginationViewModel(this.state.page,this.state.pageSize,e,t?{pageSizeOptions:t}:void 0);if(!n)return;this.el=document.createElement("div"),this.el.className="ogrid-pagination";let i=document.createElement("div");i.className="ogrid-pagination-size";let r=document.createElement("span");r.textContent="Rows per page: ",i.appendChild(r);let o=document.createElement("select");o.className="ogrid-page-size-select";for(let d of n.pageSizeOptions){let p=document.createElement("option");p.value=String(d),p.textContent=String(d),p.selected=d===this.state.pageSize,o.appendChild(p);}o.addEventListener("change",()=>{this.state.setPageSize(Number(o.value));}),i.appendChild(o),this.el.appendChild(i);let l=document.createElement("span");l.className="ogrid-pagination-info",l.textContent=`${n.startItem}-${n.endItem} of ${e}`,this.el.appendChild(l);let s=document.createElement("div");s.className="ogrid-pagination-nav";let a=document.createElement("button");if(a.textContent="\u25C0",a.className="ogrid-pagination-btn",a.disabled=this.state.page===1,a.addEventListener("click",()=>this.state.setPage(this.state.page-1)),s.appendChild(a),n.showStartEllipsis){let d=document.createElement("span");d.textContent="...",d.className="ogrid-pagination-ellipsis",s.appendChild(d);}for(let d of n.pageNumbers){let p=document.createElement("button");p.textContent=String(d),p.className="ogrid-pagination-btn"+(d===this.state.page?" ogrid-pagination-active":""),p.addEventListener("click",()=>this.state.setPage(d)),s.appendChild(p);}if(n.showEndEllipsis){let d=document.createElement("span");d.textContent="...",d.className="ogrid-pagination-ellipsis",s.appendChild(d);}let c=document.createElement("button");c.textContent="\u25B6",c.className="ogrid-pagination-btn",c.disabled=this.state.page===n.totalPages,c.addEventListener("click",()=>this.state.setPage(this.state.page+1)),s.appendChild(c),this.el.appendChild(s),this.container.appendChild(this.el);}destroy(){this.el?.remove(),this.el=null;}};var U=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 n of t){let i=document.createElement("span");i.className="ogrid-status-part",i.textContent=`${n.label}: ${n.value}`,this.el.appendChild(i);}if(e.aggregation){let n=e.aggregation,i=document.createElement("span");i.className="ogrid-status-aggregation",i.textContent=`Sum: ${n.sum.toLocaleString()} | Avg: ${n.avg.toFixed(2)} | Min: ${n.min} | Max: ${n.max} | Count: ${n.count}`,this.el.appendChild(i);}this.container.appendChild(this.el);}}destroy(){this.el?.remove(),this.el=null;}};var G=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((n,i)=>{i<t.length&&(n.checked=this.state.visibleColumns.has(t[i].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 n=document.createElement("input");n.type="checkbox",n.checked=this.state.visibleColumns.has(e.columnId),n.disabled=!!e.required,n.addEventListener("change",()=>{let i=new Set(this.state.visibleColumns);n.checked?i.add(e.columnId):i.delete(e.columnId),this.state.setVisibleColumns(i);}),t.appendChild(n),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 Ae=["columns","filters"],K=class{constructor(e){this.emitter=new x;if(this._isEnabled=e!=null&&e!==false,!this._isEnabled||e===true)this._panels=Ae,this._position="right",this._activePanel=null;else {let t=e;this._panels=t.panels??Ae,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 ge={columns:"Columns",filters:"Filters"},rt={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),n=this.createPanel(e);e==="left"?(this.el.appendChild(t),n&&this.el.appendChild(n)):(n&&this.el.appendChild(n),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 n of this.state.panels){let i=document.createElement("button");i.setAttribute("role","tab"),i.setAttribute("aria-selected",String(this.state.activePanel===n)),i.setAttribute("aria-label",ge[n]),i.title=ge[n],i.textContent=rt[n],i.className="ogrid-sidebar-tab",i.style.width="36px",i.style.height="36px",i.style.border="none",i.style.cursor="pointer",i.style.color="var(--ogrid-fg, #242424)",i.style.fontSize="14px",i.style.display="flex",i.style.alignItems="center",i.style.justifyContent="center",this.state.activePanel===n?(i.style.background="var(--ogrid-bg, #fff)",i.style.fontWeight="bold"):(i.style.background="transparent",i.style.fontWeight="normal"),i.addEventListener("click",()=>{this.state.toggle(n);}),t.appendChild(i);}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",ge[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 n=document.createElement("div");n.style.display="flex",n.style.justifyContent="space-between",n.style.alignItems="center",n.style.padding="8px 12px",n.style.borderBottom="1px solid var(--ogrid-border, #e0e0e0)",n.style.fontWeight="600";let i=document.createElement("span");i.textContent=ge[this.state.activePanel],n.appendChild(i);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()),n.appendChild(r),t.appendChild(n);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:n,onVisibilityChange:i,onSetVisibleColumns:r}=this.config,o=t.every(c=>n.has(c.columnId)),l=document.createElement("div");l.style.display="flex",l.style.gap="8px",l.style.marginBottom="8px";let s=document.createElement("button");s.textContent="Select All",s.disabled=o,s.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(s),s.addEventListener("click",()=>{let c=new Set(n);t.forEach(d=>c.add(d.columnId)),r(c);}),l.appendChild(s);let a=document.createElement("button");a.textContent="Clear All",a.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(a),a.addEventListener("click",()=>{let c=new Set;t.forEach(d=>{d.required&&n.has(d.columnId)&&c.add(d.columnId);}),r(c);}),l.appendChild(a),e.appendChild(l);for(let c of t){let d=document.createElement("label");d.style.display="flex",d.style.alignItems="center",d.style.gap="6px",d.style.padding="2px 0",d.style.cursor="pointer";let p=document.createElement("input");p.type="checkbox",p.checked=n.has(c.columnId),p.disabled=!!c.required,p.addEventListener("change",()=>{i(c.columnId,p.checked);});let m=document.createElement("span");m.textContent=c.name,d.appendChild(p),d.appendChild(m),e.appendChild(d);}}renderFiltersPanel(e){if(!this.config)return;let{filterableColumns:t,filters:n,onFilterChange:i,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 s=document.createElement("div");if(s.style.fontWeight="500",s.style.marginBottom="4px",s.style.fontSize="13px",s.textContent=o.name,l.appendChild(s),o.filterType==="text"){let a=document.createElement("input");a.type="text";let c=n[o.filterField];a.value=c?.type==="text"?c.value:"",a.placeholder=`Filter ${o.name}...`,a.setAttribute("aria-label",`Filter ${o.name}`),this.applyTextInputStyle(a),a.addEventListener("input",()=>{i(o.filterField,a.value?{type:"text",value:a.value}:void 0);}),l.appendChild(a);}else if(o.filterType==="date"){let a=document.createElement("div");a.style.display="flex",a.style.flexDirection="column",a.style.gap="4px";let c=n[o.filterField],d=c?.type==="date"?c.value:{},p=document.createElement("label");p.style.display="flex",p.style.alignItems="center",p.style.gap="4px",p.style.fontSize="12px",p.textContent="From: ";let m=document.createElement("input");m.type="date",m.value=d.from??"",m.setAttribute("aria-label",`${o.name} from date`),this.applyDateInputStyle(m),p.appendChild(m),a.appendChild(p);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 f=document.createElement("input");f.type="date",f.value=d.to??"",f.setAttribute("aria-label",`${o.name} to date`),this.applyDateInputStyle(f),v.appendChild(f),a.appendChild(v);let S=()=>{let u=m.value||void 0,g=f.value||void 0;i(o.filterField,u||g?{type:"date",value:{from:u,to:g}}:void 0);};m.addEventListener("change",S),f.addEventListener("change",S),l.appendChild(a);}else if(o.filterType==="multiSelect"){let a=r[o.filterField]??[],c=document.createElement("div");c.style.maxHeight="120px",c.style.overflowY="auto",c.setAttribute("role","group"),c.setAttribute("aria-label",`${o.name} options`);let d=n[o.filterField],p=d?.type==="multiSelect"?d.value:[];for(let m of a){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 f=document.createElement("input");f.type="checkbox",f.checked=p.includes(m),f.addEventListener("change",()=>{let u=n[o.filterField],g=u?.type==="multiSelect"?[...u.value]:[],h=f.checked?[...g,m]:g.filter(y=>y!==m);i(o.filterField,h.length>0?{type:"multiSelect",value:h}:void 0);});let S=document.createElement("span");S.textContent=m,v.appendChild(f),v.appendChild(S),c.appendChild(v);}l.appendChild(c);}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 n=this._searchText.toLowerCase();return t.filter(i=>i.toLowerCase().includes(n))}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,n,i){this._openColumnId&&this.close(),this._openColumnId=e,this._headerEl=n,this._popoverEl=i;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=n.getBoundingClientRect();this._popoverPosition={top:o.bottom+4,left:o.left},this._clickOutsideHandler=l=>{let s=l.target;this._popoverEl&&!this._popoverEl.contains(s)&&this._headerEl&&!this._headerEl.contains(s)&&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 n=new Set(this._tempSelected);t?n.add(e):n.delete(e),this._tempSelected=n,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,n=this._tempDateTo||void 0;this._onFilterChange(e,t||n?{type:"date",value:{from:t,to:n}}: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",n=>n.stopPropagation()),this.popoverEl.addEventListener("mousedown",n=>n.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 n=document.createElement("div");n.style.display="flex",n.style.gap="8px";let i=document.createElement("button");i.textContent="Apply",i.className="ogrid-filter-apply-btn",this.applyButtonStyle(i),i.addEventListener("click",()=>this.state.applyTextFilter(e.filterField)),n.appendChild(i);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)),n.appendChild(r),this.popoverEl.appendChild(n),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",s=>s.stopPropagation()),this.popoverEl.appendChild(t);let n=document.createElement("div");n.style.display="flex",n.style.gap="8px",n.style.marginBottom="8px";let i=document.createElement("button");i.textContent="Select All",i.className="ogrid-filter-select-all-btn",this.applySmallButtonStyle(i),i.addEventListener("click",()=>{this.state.handleSelectAll(e.filterField),this.updateCheckboxList(e,o);}),n.appendChild(i);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);}),n.appendChild(r),this.popoverEl.appendChild(n);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 n=this.state.getFilteredOptions(e.filterField),i=this.state.tempSelected;for(let r of n){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=i.has(r),l.addEventListener("change",()=>{this.state.handleCheckboxChange(r,l.checked);});let s=document.createElement("span");s.textContent=r,o.appendChild(l),o.appendChild(s),t.appendChild(o);}if(n.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 n=document.createElement("label");n.style.display="flex",n.style.alignItems="center",n.style.gap="4px",n.style.fontSize="13px",n.textContent="From: ";let i=document.createElement("input");i.type="date",i.value=this.state.tempDateFrom,i.setAttribute("aria-label","From date"),this.applyInputStyle(i),i.addEventListener("change",()=>{this.state.setTempDateFrom(i.value);}),i.addEventListener("keydown",c=>c.stopPropagation()),n.appendChild(i),t.appendChild(n);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",c=>c.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 s=document.createElement("button");s.textContent="Apply",s.className="ogrid-filter-apply-btn",this.applyButtonStyle(s),s.addEventListener("click",()=>this.state.applyDateFilter(e.filterField)),l.appendChild(s);let a=document.createElement("button");a.textContent="Clear",a.className="ogrid-filter-clear-btn",this.applyButtonStyle(a),a.addEventListener("click",()=>this.state.clearDateFilter(e.filterField)),l.appendChild(a),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 n of t){let i=n.contentRect;this._containerWidth=i.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 i=t?CHECKBOX_COLUMN_WIDTH:0;for(let r of e){let o=this._columnSizingOverrides[r.columnId];o?i+=o+CELL_PADDING:i+=(r.width??r.minWidth??DEFAULT_MIN_COLUMN_WIDTH)+CELL_PADDING;}return i}getAllColumnWidths(){return {...this._columnSizingOverrides}}cleanupOverrides(e){let t={},n=false;for(let[i,r]of Object.entries(this._columnSizingOverrides))e.has(i)?t[i]=r:n=true;n&&(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(n=>e.has(this._getRowId(n)))});}handleRowCheckboxChange(e,t,n,i,r){if(this._rowSelection==="single"){this.updateSelection(t?new Set([e]):new Set,r),this._lastClickedRow=n;return}let o;i&&this._lastClickedRow>=0&&this._lastClickedRow!==n?o=applyRangeRowSelection(this._lastClickedRow,n,t,r,this._getRowId,this._selectedRowIds):(o=new Set(this._selectedRowIds),t?o.add(e):o.delete(e)),this._lastClickedRow=n,this.updateSelection(o,r);}handleSelectAll(e,t){e?this.updateSelection(new Set(t.map(n=>this._getRowId(n))),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 n of t)n.pinned&&!(n.columnId in this._pinnedColumns)&&(this._pinnedColumns[n.columnId]=n.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,...n}=this._pinnedColumns;this._pinnedColumns=n,this.emitter.emit("pinningChange",{pinnedColumns:this._pinnedColumns});}isPinned(e){return this._pinnedColumns[e]}computeLeftOffsets(e,t,n,i,r,o){let l={},s=0;i&&(s+=r),o&&(s+=ROW_NUMBER_COLUMN_WIDTH);for(let a of e)this._pinnedColumns[a.columnId]==="left"&&(l[a.columnId]=s,s+=t[a.columnId]??n);return l}computeRightOffsets(e,t,n){let i={},r=0;for(let o=e.length-1;o>=0;o--){let l=e[o];this._pinnedColumns[l.columnId]==="right"&&(i[l.columnId]=r,r+=t[l.columnId]??n);}return i}onPinningChange(e){return this.emitter.on("pinningChange",e),()=>this.emitter.off("pinningChange",e)}destroy(){this.emitter.removeAllListeners();}};var Re=36,ht=5,pt=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??pt;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),n=this._cachedColumnRange;!n||n.startIndex!==t.startIndex||n.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,n){let i=this._config.rowHeight??Re,r=getScrollTopForRow(e,i,this._containerHeight,n);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??ht,n=computeVisibleRange(this._scrollTop,e,this._containerHeight,this._totalRows,t),i=this._cachedRange;i.startIndex!==n.startIndex||i.endIndex!==n.endIndex?(this._cachedRange=n,this.emitter.emit("rangeChanged",{visibleRange:n})):this._cachedRange=n;}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},this.pendingRange=this._selectionRange;}updateDrag(e,t,n){if(!this._isDragging||!this.dragStartCell)return;let i={startRow:this.dragStartCell.rowIndex,startCol:this.dragStartCell.columnIndex,endRow:e,endCol:t};rangesEqual(this.pendingRange,i)||(this.pendingRange=i,this.rafHandle===null&&(this.rafHandle=requestAnimationFrame(()=>{this.pendingRange&&n(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,n,i,r){this.wrapperRef=null;this.handleKeyDown=e=>{let{items:t,visibleCols:n,colOffset:i,editable:r,onCellValueChanged:o,onCopy:l,onCut:s,onPaste:a,onUndo:c,onRedo:d,onContextMenu:p,onStartEdit:m,getRowId:v,clearClipboardRanges:f,onKeyDown:S,onFillDown:u}=this.params;if(S&&(S(e),e.defaultPrevented))return;let g=this.getActiveCell(),h=this.getSelectionRange(),y=t.length-1,I=n.length-1+i;if(t.length===0)return;if(g===null){["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Tab","Enter","Home","End","PageDown","PageUp"].includes(e.key)&&(this.setActiveCell({rowIndex:0,columnIndex:i}),e.preventDefault());return}let{rowIndex:b,columnIndex:R}=g,k=R-i,w=e.shiftKey,T=(C,_)=>{if(C<0||C>=t.length||_<0||_>=n.length)return true;let F=getCellValue(t[C],n[_]);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(),s?.());break;case "v":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),a?.());break;case "d":(e.ctrlKey||e.metaKey)&&r!==false&&u&&(e.preventDefault(),u());break;case "ArrowDown":case "ArrowUp":case "ArrowRight":case "ArrowLeft":{e.preventDefault();let{newRowIndex:C,newColumnIndex:_,newRange:F}=computeArrowNavigation({direction:e.key,rowIndex:b,columnIndex:R,dataColIndex:k,colOffset:i,maxRowIndex:y,maxColIndex:I,visibleColCount:n.length,isCtrl:e.ctrlKey||e.metaKey,isShift:w,selectionRange:h,isEmptyAt:T});this.setActiveCell({rowIndex:C,columnIndex:_}),this.setSelectionRange(F);break}case "Tab":{e.preventDefault();let C=computeTabNavigation(b,R,y,I,i,e.shiftKey),_=C.columnIndex-i;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:i}),this.setSelectionRange({startRow:C,startCol:0,endRow:C,endCol:0});break}case "End":{e.preventDefault();let C=e.ctrlKey?y:b;this.setActiveCell({rowIndex:C,columnIndex:I}),this.setSelectionRange({startRow:C,startCol:n.length-1,endRow:C,endCol:n.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 D=e.key==="PageDown"?1:-1,H=Math.max(0,Math.min(b+D*_,y));e.shiftKey?this.setSelectionRange({startRow:h?.startRow??b,startCol:h?.startCol??k,endRow:H,endCol:h?.endCol??k}):this.setSelectionRange({startRow:H,startCol:k,endRow:H,endCol:k}),this.setActiveCell({rowIndex:H,columnIndex:R}),C&&(C.scrollTop=getScrollTopForRow(H,F,C.clientHeight,"center"));break}case "Enter":case "F2":{if(e.preventDefault(),k>=0&&k<n.length){let C=n[k],_=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(),f?.(),this.setActiveCell(null),this.setSelectionRange(null);break;case "z":(e.ctrlKey||e.metaKey)&&(e.shiftKey&&d?(e.preventDefault(),d()):!e.shiftKey&&c&&(e.preventDefault(),c()));break;case "y":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),d?.());break;case "a":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),t.length>0&&n.length>0&&(this.setActiveCell({rowIndex:0,columnIndex:i}),this.setSelectionRange({startRow:0,startCol:0,endRow:t.length-1,endCol:n.length-1})));break;case "Delete":case "Backspace":{if(r===false||o==null)break;let C=h??(g!=null?{startRow:g.rowIndex,startCol:g.columnIndex-i,endRow:g.rowIndex,endCol:g.columnIndex-i}:null);if(C==null)break;e.preventDefault();let _=applyCellDeletion(C,t,n);for(let F of _)o(F);break}case "F10":if(e.shiftKey)if(e.preventDefault(),g!=null&&this.wrapperRef){let C=`[data-row-index="${g.rowIndex}"][data-col-index="${g.columnIndex}"]`,_=this.wrapperRef.querySelector(C);if(_){let F=_.getBoundingClientRect();p?.(F.left+F.width/2,F.top+F.height/2);}else p?.(100,100);}else p?.(100,100);break;}};this.params=e,this.getActiveCell=t,this.getSelectionRange=n,this.setActiveCell=i,this.setSelectionRange=r;}setWrapperRef(e){this.wrapperRef=e;}updateParams(e){this.params=e;}};var te=class{constructor(e,t,n){this.emitter=new x;this._cutRange=null;this._copyRange=null;this.internalClipboard=null;this.params=e,this.getActiveCell=t,this.getSelectionRange=n;}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:n,visibleCols:i,formulas:r,flatColumns:o,getFormula:l,hasFormula:s,colOffset:a}=this.params,d=formatSelectionAsTsv(n,i,t,r&&o?{colOffset:a,flatColumns:o,getFormula:l,hasFormula:s}:void 0);this.internalClipboard=d,this._copyRange=t,this._cutRange=null,this.emitter.emit("rangesChange",{copyRange:this._copyRange,cutRange:null}),typeof navigator<"u"&&navigator.clipboard&&navigator.clipboard.writeText(d).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 n=this.getEffectiveRange(),i=n?n.startRow:0,r=n?n.startCol:0,{items:o,visibleCols:l,formulas:s,flatColumns:a,setFormula:c,colOffset:d}=this.params,p=s&&a?{colOffset:d,flatColumns:a,setFormula:c}:void 0,m=parseTsvClipboard(t),v=applyPastedValues(m,i,r,o,l,p);for(let f of v)e(f);if(this._cutRange){let f=applyCutClear(this._cutRange,o,l);for(let S of f)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 ne=class{constructor(e,t=100){this.onCellValueChanged=e;this.emitter=new x;this.stack=new UndoRedoStack(t),e&&(this.wrappedCallback=n=>{this.stack.record(n),this.stack.isBatching||this.emitStackChange(),e(n);});}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 n=e[t];this.onCellValueChanged({...n,oldValue:n.newValue,newValue:n.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 ie=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,n)=>{e[n]=t;}),e}startResize(e,t,n){this.isResizing=true,this.resizeColumnId=e,this.resizeStartX=t,this.resizeStartWidth=n;}updateResize(e){if(!this.isResizing||!this.resizeColumnId)return null;let t=e-this.resizeStartX,n=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH;return Math.max(n,this.resizeStartWidth+t)}endResize(e){if(!this.isResizing||!this.resizeColumnId)return;let t=e-this.resizeStartX,n=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH,i=Math.max(n,this.resizeStartWidth+t);this.columnWidths.set(this.resizeColumnId,i),this.emitter.emit("columnWidthChange",{columnId:this.resizeColumnId,widthPx:i}),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,n,i){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=n,this.setActiveCell=i,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 n=this.liveFillRange;n&&n.startRow===t.startRow&&n.startCol===t.startCol&&n.endRow===t.endRow&&n.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 i=this.resolveRange(this.lastMousePos.cx,this.lastMousePos.cy);i&&(this.liveFillRange=i,this.fillDragEnd={endRow:i.endRow,endCol:i.endCol});}this.clearDragAttrs();let e=this.fillDragStart,t=this.fillDragEnd,n=normalizeSelectionRange({startRow:e.startRow,startCol:e.startCol,endRow:t.endRow,endCol:t.endCol});this.setSelectionRange(n),this.setActiveCell({rowIndex:e.startRow,columnIndex:e.startCol+this.params.colOffset}),this.applyFillValuesFromCore(n,e),this._isFillDragging=false,this.fillDragStart=null,this.liveFillRange=null,this.lastMousePos=null,this.emitter.emit("fillRangeChange",{fillRange:null});}applyFillValuesFromCore(e,t){let{items:n,visibleCols:i,onCellValueChanged:r,beginBatch:o,endBatch:l,formulaOptions:s}=this.params;if(!r)return;let a=applyFillValues(e,t.startRow,t.startCol,n,i,s);if(a.length>0){o?.();for(let c of a)r(c);l?.();}}resolveRange(e,t){if(!this.fillDragStart||!this.wrapperRef)return null;let i=document.elementFromPoint(e,t)?.closest?.("[data-row-index][data-col-index]");if(!i||!this.wrapperRef.contains(i))return null;let r=L(i);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 n=this.params.colOffset,i=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 s=0;s<t.length;s++){let a=t[s],c=L(a);if(!c)continue;let d=c.rowIndex,p=c.colIndex-n;d>=i&&d<=r&&p>=o&&p<=l?a.hasAttribute("data-drag-range")||a.setAttribute("data-drag-range",""):a.hasAttribute("data-drag-range")&&a.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,n,i,r,o){if(t.preventDefault(),this._isDragging=true,this._draggedColumnId=e,this._dropIndicatorX=null,this._dropTargetIndex=null,this.tableElement=o,this.columnOrder=i.length>0?[...i]:n.map(l=>l.columnId),r){let l=[],s=[];for(let[a,c]of Object.entries(r))c==="left"?l.push(a):c==="right"&&s.push(a);this.pinnedColumns={left:l,right:s};}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 n=calculateDropTarget({mouseX:t,columnOrder:this.columnOrder,draggedColumnId:this._draggedColumnId,draggedPinState:this.draggedPinState,tableElement:this.tableElement,pinnedColumns:this.pinnedColumns});if(!n)return;let i=this._dropIndicatorX,r=this._dropTargetIndex;this._dropTargetIndex=n.targetIndex,this._dropIndicatorX=n.indicatorX,(i!==n.indicatorX||r!==n.targetIndex)&&this.emitter.emit("stateChange",{isDragging:true,dropIndicatorX:n.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(E,e,t){let n=measureRange(E,e,t);return n?{top:n.top+E.scrollTop,left:n.left+E.scrollLeft,width:n.width,height:n.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 n=getComputedStyle(e).position;(n==="static"||n==="")&&(e.style.position="relative");}update(e,t,n,i){let r=i!==void 0&&i!==this.layoutVersion;r&&i!==void 0&&(this.layoutVersion=i),!(!r&&rangesEqual(this.selectionRange,e)&&rangesEqual(this.copyRange,t)&&rangesEqual(this.cutRange,n))&&(this.selectionRange=e,this.copyRange=t,this.cutRange=n,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,n=this.selectionRange!=null&&e!=null&&rangesEqual(this.selectionRange,e),i=this.selectionRange!=null&&this.selectionRange.startRow===this.selectionRange.endRow&&this.selectionRange.startCol===this.selectionRange.endCol;if(t&&!n&&!i){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 n=document.createElementNS("http://www.w3.org/2000/svg","rect");return n.setAttribute("x","1"),n.setAttribute("y","1"),n.setAttribute("fill","none"),t.appendChild(n),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 se={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"},ae=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,n,i,r,o,l,s,a){this.closeEditor(),this.editingCell={rowId:e,columnId:t},this.editingCellElement=r,this.onCommit=o,this.onCancel=l,this.onAfterCommit=s??null;let c=a!==void 0?a:getCellValue(n,i),d=r.getBoundingClientRect(),p=this.container.getBoundingClientRect(),m=this.createEditor(i,n,c,r);m.style.position="absolute",m.style.left=`${d.left-p.left+this.container.scrollLeft}px`,m.style.top=`${d.top-p.top+this.container.scrollTop}px`,m.style.width=`${d.width}px`,m.style.height=`${d.height}px`,this.editor=m,this.container.appendChild(m),m.focus();let v=m.querySelector('[role="listbox"]');if(v){let S=window.innerHeight-d.bottom,u=S<200&&d.top>S;v.style.position="fixed",v.style.left=`${d.left}px`,v.style.width=`${d.width}px`,v.style.maxHeight="200px",v.style.zIndex="9999",v.style.right="auto",u?(v.style.top="auto",v.style.bottom=`${window.innerHeight-d.top}px`):v.style.top=`${d.bottom}px`;let g=m.closest("[data-ogrid-scroll-container]")??m.closest('[style*="overflow"]'),h=()=>this.closeEditor(),y=requestAnimationFrame(()=>{g&&g.addEventListener("scroll",h,{passive:true}),window.addEventListener("scroll",h,{passive:true});});this.scrollCleanup=()=>{cancelAnimationFrame(y),g&&g.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,n=this.container.querySelector(`tr[data-row-id="${e}"]`);if(n){let i=n.querySelector(`td[data-column-id="${t}"]`);i&&(i.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,n,i){let r=e.cellEditor;if(typeof r=="function"){let o={value:n,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:i,cellEditorParams:e.cellEditorParams};return r(o)}return r==="checkbox"||e.type==="boolean"?this.createCheckboxEditor(n):r==="select"?this.createSelectEditor(n,e):r==="richSelect"?this.createRichSelectEditor(n,e):r==="date"||e.type==="date"?this.createDateEditor(n,e):this.createTextEditor(n)}createInputEditor(e,t){let n=document.createElement("input");return n.type=e,n.value=t,Object.assign(n.style,se),n.addEventListener("keydown",i=>{if(i.key==="Enter"){i.preventDefault(),i.stopPropagation(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value);let r=this.onAfterCommit;this.closeEditor(),r?.();}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();}),n.addEventListener("blur",()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value),this.closeEditor();}),setTimeout(()=>n.select(),0),n}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,se),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",n=>{n.key==="Escape"?(n.preventDefault(),n.stopPropagation(),this.onCancel?.(),this.closeEditor()):["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(n.key)&&n.stopPropagation();}),t}createDateEditor(e,t){let n=t?.cellEditorParams?.dateFormat??t?.dateFormat??"YYYY-MM-DD";if(t?.cellEditorParams?.editorType==="native"){let s="";if(e!=null){let d=String(e).match(/^(\d{4})-(\d{2})-(\d{2})/);d&&(s=`${d[1]}-${d[2]}-${d[3]}`);}return this.createInputEditor("date",s)}let r=e!=null?formatDateForDisplay(e,n)??"":"",o=getDateInputPlaceholder(n);return this.createDateTextEditor(r,o,n)}createDateTextEditor(e,t,n){let i=document.createElement("input");i.type="text",i.value=e,i.placeholder=t,Object.assign(i.style,se);let r=()=>{let l=i.value;if(!l.trim())return "";let s=parseUserInputDate(l,n);if(s instanceof Date){let a=s.getUTCFullYear().toString().padStart(4,"0"),c=(s.getUTCMonth()+1).toString().padStart(2,"0"),d=s.getUTCDate().toString().padStart(2,"0");return `${a}-${c}-${d}`}return l},o=()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,r());};return i.addEventListener("keydown",l=>{if(l.key==="Enter"){l.preventDefault(),l.stopPropagation(),o();let s=this.onAfterCommit;this.closeEditor(),s?.();}else l.key==="Escape"?(l.preventDefault(),l.stopPropagation(),this.onCancel?.(),this.closeEditor()):(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(l.key)||(l.ctrlKey||l.metaKey)&&["c","x","v","a","z","y"].includes(l.key))&&l.stopPropagation();}),i.addEventListener("blur",()=>{o(),this.closeEditor();}),setTimeout(()=>i.select(),0),i}createSelectEditor(e,t){let n=t.cellEditorParams?.values??[],i=t.cellEditorParams?.formatValue,r=f=>i?i(f):f!=null?String(f):"",o=document.createElement("div");Object.assign(o.style,se),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 s=document.createElement("span");s.textContent=r(e),l.appendChild(s);let a=document.createElement("span");a.textContent="\u25BE",a.style.marginLeft="4px",a.style.fontSize="10px",a.style.opacity="0.5",l.appendChild(a),o.appendChild(l);let c=document.createElement("div");c.setAttribute("role","listbox"),c.style.position="absolute",c.style.top="100%",c.style.left="0",c.style.right="0",c.style.maxHeight="200px",c.style.overflowY="auto",c.style.backgroundColor="var(--ogrid-bg, #fff)",c.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",c.style.zIndex="1001",c.style.boxShadow="0 4px 16px rgba(0,0,0,0.2)",c.style.textAlign="left",c.style.fontSize="13px",c.style.fontFamily="inherit",o.appendChild(c);let d=Math.max(n.findIndex(f=>String(f)===String(e)),0),p=()=>{c.innerHTML="";for(let f=0;f<n.length;f++){let S=n[f],u=document.createElement("div");u.setAttribute("role","option"),u.setAttribute("aria-selected",String(f===d)),u.textContent=r(S),u.style.padding="6px 8px",u.style.cursor="pointer",u.style.color="var(--ogrid-fg, #242424)",u.style.fontSize="13px",f===d&&(u.style.background="var(--ogrid-bg-hover, #e8f0fe)"),u.addEventListener("mousedown",g=>{g.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,S),this.closeEditor();}),c.appendChild(u);}},m=(f,S)=>{let u=c.children[f],g=c.children[S];u&&(u.style.background="",u.setAttribute("aria-selected","false")),g&&(g.style.background="var(--ogrid-bg-hover, #e8f0fe)",g.setAttribute("aria-selected","true"));},v=()=>{c.children[d]?.scrollIntoView({block:"nearest"});};return p(),o.addEventListener("keydown",f=>{switch(f.stopPropagation(),f.key){case "ArrowDown":{f.preventDefault();let S=d;d=Math.min(d+1,n.length-1),m(S,d),v();break}case "ArrowUp":{f.preventDefault();let S=d;d=Math.max(d-1,0),m(S,d),v();break}case "Enter":if(f.preventDefault(),f.stopPropagation(),n.length>0&&d<n.length){this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n[d]);let S=this.onAfterCommit;this.closeEditor(),S?.();}break;case "Tab":f.preventDefault(),n.length>0&&d<n.length&&(this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n[d]),this.closeEditor());break;case "Escape":f.preventDefault(),f.stopPropagation(),this.onCancel?.(),this.closeEditor();break}}),o}createRichSelectEditor(e,t){let n=t.cellEditorParams?.values??[],i=t.cellEditorParams?.formatValue??(u=>String(u)),r=u=>u!=null?String(i(u)):"",o=document.createElement("div");Object.assign(o.style,se),o.style.padding="6px 10px",o.style.display="flex",o.style.alignItems="center";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 s=document.createElement("span");s.textContent=r(e),l.appendChild(s);let a=document.createElement("span");a.textContent="\u25BE",a.style.marginLeft="4px",a.style.fontSize="10px",a.style.opacity="0.5",l.appendChild(a),o.appendChild(l);let c=document.createElement("div");c.setAttribute("role","listbox"),c.style.position="absolute",c.style.top="100%",c.style.left="0",c.style.width="100%",c.style.maxHeight="200px",c.style.overflowY="auto",c.style.backgroundColor="var(--ogrid-bg, #fff)",c.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",c.style.zIndex="1001",c.style.textAlign="left",c.style.boxShadow="0 4px 16px rgba(0,0,0,0.2)",c.style.fontSize="13px",c.style.fontFamily="inherit";let d=document.createElement("input");d.type="text",d.placeholder="Search...",d.style.width="100%",d.style.padding="6px 8px",d.style.border="none",d.style.borderBottom="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",d.style.outline="none",d.style.boxSizing="border-box",d.style.background="var(--ogrid-bg, #fff)",d.style.color="var(--ogrid-fg, rgba(0, 0, 0, 0.87))",d.style.font="inherit",d.style.fontSize="13px",d.style.position="sticky",d.style.top="0",d.style.zIndex="1",c.appendChild(d);let p=document.createElement("div");c.appendChild(p),o.appendChild(c);let m=Math.max(n.findIndex(u=>String(u)===String(e)),0),v=[...n],f=u=>{p.innerHTML="",v=n.filter(g=>String(i(g)).toLowerCase().includes(u.toLowerCase())),m=Math.min(m,Math.max(v.length-1,0));for(let g=0;g<v.length;g++){let h=v[g],y=document.createElement("div");y.textContent=String(i(h)),y.style.padding="6px 8px",y.style.cursor="pointer",y.style.color="var(--ogrid-fg, #242424)",y.style.fontSize="13px",g===m&&(y.style.background="var(--ogrid-bg-hover, #e8f0fe)"),y.addEventListener("mousedown",I=>{I.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,h),this.closeEditor();}),y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--ogrid-bg-hover, #e8f0fe)";},{passive:true}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="";},{passive:true}),p.appendChild(y);}},S=(u,g)=>{let h=p.children[u],y=p.children[g];h&&(h.style.background=""),y&&(y.style.background="var(--ogrid-bg-hover, #e8f0fe)",y.scrollIntoView({block:"nearest"}));};return d.addEventListener("input",()=>{f(d.value);}),d.addEventListener("keydown",u=>{switch(u.key){case "ArrowDown":{u.preventDefault(),u.stopPropagation();let g=m;m=Math.min(m+1,v.length-1),S(g,m);break}case "ArrowUp":{u.preventDefault(),u.stopPropagation();let g=m;m=Math.max(m-1,0),S(g,m);break}case "Enter":if(u.preventDefault(),u.stopPropagation(),v.length>0&&m<v.length){this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,v[m]);let g=this.onAfterCommit;this.closeEditor(),g?.();}break;case "Escape":u.preventDefault(),u.stopPropagation(),this.onCancel?.(),this.closeEditor();break;case "ArrowLeft":case "ArrowRight":u.stopPropagation();break;default:(u.ctrlKey||u.metaKey)&&["c","x","v","a","z","y"].includes(u.key)&&u.stopPropagation();break}}),d.addEventListener("blur",u=>{let g=u.relatedTarget;g&&this.editor?.contains(g)||(this.onCancel?.(),this.closeEditor());}),f(""),setTimeout(()=>d.focus(),0),o}destroy(){this.closeEditor();}};var Ot={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)"},Pt={padding:"6px 12px",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},Nt={height:"1px",backgroundColor:"var(--ogrid-border, #e0e0e0)",margin:"4px 0"},de=class{constructor(){this.menu=null;this.handlers=null;}show(e,t,n,i,r,o){this.close(),this.handlers=n,this.menu=document.createElement("div"),Object.assign(this.menu.style,Ot),this.menu.style.left=`${e}px`,this.menu.style.top=`${t}px`;for(let s of GRID_CONTEXT_MENU_ITEMS){if(s.dividerBefore){let p=document.createElement("div");Object.assign(p.style,Nt),this.menu.appendChild(p);}let a=document.createElement("div");Object.assign(a.style,Pt);let c=document.createElement("span");if(c.textContent=s.label,a.appendChild(c),s.shortcut){let p=document.createElement("span");p.textContent=formatShortcut(s.shortcut),p.style.marginLeft="20px",p.style.color="var(--ogrid-muted, #666)",p.style.fontSize="12px",a.appendChild(p);}s.id==="undo"&&!i||s.id==="redo"&&!r||s.disabledWhenNoSelection&&o==null?(a.style.color="var(--ogrid-fg-muted, rgba(0, 0, 0, 0.4))",a.style.opacity="0.5",a.style.cursor="not-allowed"):(a.addEventListener("mouseenter",()=>{a.style.backgroundColor="var(--ogrid-bg-hover, #f5f5f5)";},{passive:true}),a.addEventListener("mouseleave",()=>{a.style.backgroundColor="";},{passive:true}),a.addEventListener("click",()=>{this.handleItemClick(s.id);},{passive:true})),this.menu.appendChild(a);}document.body.appendChild(this.menu);let l=s=>{this.menu&&!this.menu.contains(s.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 ce=class{initializeInteraction(e,t,n,i,r,o,l,s){let{editable:a}=e,c=o?1:0,d=[],p=new Q,m=new ie,v=new de,f=new ae(i),S=e.onCellValueChanged,u=new ne(S),g=new te({items:[],visibleCols:[],colOffset:c,editable:a,onCellValueChanged:u.getWrappedCallback()},()=>p.activeCell??null,()=>p.selectionRange??null),h=new oe({items:[],visibleCols:[],editable:a,onCellValueChanged:u.getWrappedCallback(),colOffset:c,beginBatch:()=>u.beginBatch(),endBatch:()=>u.endBatch()},()=>p.selectionRange??null,w=>{p.setSelectionRange(w),s.updateRendererInteractionState();},w=>{p.setActiveCell(w);}),y=new ee({items:[],visibleCols:[],colOffset:c,getRowId:t.getRowId,editable:a,onCellValueChanged:u.getWrappedCallback(),onCopy:()=>g.handleCopy(),onCut:()=>g.handleCut(),onPaste:async()=>{await g.handlePaste();},onUndo:()=>u.undo(),onRedo:()=>u.redo(),onContextMenu:(w,T)=>s.showContextMenu(w,T),onStartEdit:(w,T)=>s.startCellEdit(w,T),clearClipboardRanges:()=>g.clearClipboardRanges()},()=>p.activeCell??null,()=>p.selectionRange??null,w=>p.setActiveCell(w),w=>p.setSelectionRange(w));d.push(p.onSelectionChange(()=>{s.updateRendererInteractionState();})),d.push(g.onRangesChange(()=>{s.updateRendererInteractionState();})),d.push(m.onColumnWidthChange(()=>{s.updateRendererInteractionState();}));let I=new re;d.push(I.onStateChange(({isDragging:w,dropIndicatorX:T})=>{n.updateDropIndicator(T,w);})),d.push(I.onReorder(({columnOrder:w})=>{t.setColumnOrder(w);}));let b=n.getWrapperElement(),R=null;b&&(b.addEventListener("keydown",y.handleKeyDown),y.setWrapperRef(b),h.setWrapperRef(b),R=new le(b,c));let k=this.attachGlobalHandlers(p,m,r,n,s);return d.push(...k),{selectionState:p,keyboardNavState:y,clipboardState:g,undoRedoState:u,resizeState:m,fillHandleState:h,reorderState:I,marchingAnts:R,cellEditor:f,contextMenu:v,unsubscribes:d}}attachGlobalHandlers(e,t,n,i,r){let o=[],l=false,s=d=>{if(l&&t){let p=t.updateResize(d.clientX);p!==null&&t.resizingColumnId&&(n.setColumnOverride(t.resizingColumnId,p),r.updateRendererInteractionState());}if(e?.isDragging){let p=d.target;if(p.tagName==="TD"){let m=L(p);m&&m.rowIndex>=0&&m.colIndex>=0&&e.updateDrag(m.rowIndex,m.colIndex,()=>r.updateDragAttributes());}}},a=d=>{if(l&&t){let p=t.resizingColumnId;if(t.endResize(d.clientX),p){let m=t.getColumnWidth(p);m&&n.setColumnOverride(p,m);}l=false,document.body.style.cursor="",r.updateRendererInteractionState();}e?.isDragging&&(e.endDrag(),r.clearCachedDragCells());},c=(d,p,m)=>{l=true,document.body.style.cursor="col-resize",t.startResize(d,p,m);};return document.addEventListener("pointermove",s,{passive:true}),document.addEventListener("pointerup",a,{passive:true}),o.push(()=>{document.removeEventListener("pointermove",s),document.removeEventListener("pointerup",a);}),i.setInteractionState({activeCell:null,selectionRange:null,copyRange:null,cutRange:null,editingCell:null,columnWidths:{},onResizeStart:c}),o}};var ue=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:n,state:i,layoutState:r,pinningState:o,rowSelectionState:l,cellEditor:s,renderer:a,reorderState:c,marchingAnts:d,fillHandleState:p,options:m}=this.ctx;if(!e||!t||!n)return;let{items:v}=i.getProcessedItems(),f=i.visibleColumnDefs,S=r.getAllColumnWidths(),u=o?.computeLeftOffsets(f,S,120,!!l,CHECKBOX_COLUMN_WIDTH,!!m.showRowNumbers)??{},g=o?.computeRightOffsets(f,S,120)??{};a.setInteractionState({activeCell:e.activeCell,selectionRange:e.selectionRange,copyRange:t.copyRange,cutRange:t.cutRange,editingCell:s?.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:a.getOnResizeStart(),onResizeDoubleClick:h=>{let I=f.find(k=>k.columnId===h)?.minWidth??DEFAULT_MIN_COLUMN_WIDTH,b=a.getTableElement()?.parentElement??void 0,R=measureColumnContentWidth(h,I,b);n.setColumnWidth(h,R);},onBooleanToggle:m.editable!==false?(h,y,I)=>this.ctx.toggleBooleanCell(h,y,I):void 0,onFillHandleMouseDown:m.editable!==false?h=>p?.startFillDrag(h):void 0,rowSelectionMode:l?.rowSelection??"none",selectedRowIds:l?.selectedRowIds,onRowCheckboxChange:(h,y,I,b)=>{l?.handleRowCheckboxChange(h,y,I,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:u,rightOffsets:g,onColumnReorderStart:c?(h,y)=>{let I=a.getTableElement();I&&c?.startDrag(h,y,f,i.columnOrder,o?.pinnedColumns,I);}:void 0}),a.update(),d?.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 n=t.getDragRange();if(!n)return;let i=normalizeSelectionRange(n),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 a=o[l],c=L(a);if(!c)continue;let d=c.rowIndex,p=c.colIndex;isInSelectionRange(i,d,p)?(a.setAttribute("data-drag-range","true"),r&&d===r.rowIndex&&p===r.columnIndex?a.setAttribute("data-drag-anchor",""):a.removeAttribute("data-drag-anchor"),a.classList.add("ogrid-drag-target")):(a.removeAttribute("data-drag-range"),a.removeAttribute("data-drag-anchor"),a.classList.remove("ogrid-drag-target"));}}renderAll(){this.layoutVersion++;let{state:e,options:t,headerFilterState:n,rowSelectionState:i,keyboardNavState:r,clipboardState:o,undoRedoState:l,fillHandleState:s,virtualScrollState:a,pagination:c,statusBar:d,columnChooser:p,renderer:m}=this.ctx,v=i?1:0;n.setFilters(e.filters),n.setFilterOptions(e.filterOptions);let{items:f,totalCount:S}=e.getProcessedItems();if(r&&o){let u=e.visibleColumnDefs;r.updateParams({items:f,visibleCols:u,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:(g,h)=>this.ctx.showContextMenu(g,h),onStartEdit:(g,h)=>this.ctx.startCellEdit(g,h),clearClipboardRanges:()=>o?.clearClipboardRanges(),onKeyDown:t.onKeyDown,onFillDown:s?()=>s.fillDown():void 0}),o.updateParams({items:f,visibleCols:u,colOffset:v,editable:t.editable,onCellValueChanged:l?.getWrappedCallback()}),s?.updateParams({items:f,visibleCols:u,editable:t.editable,onCellValueChanged:l?.getWrappedCallback(),colOffset:v,beginBatch:()=>l?.beginBatch(),endBatch:()=>l?.endBatch()}),this.updateRendererInteractionState();}else m.update();a?.setTotalRows(S),c.render(S,t.pageSizeOptions),d.render({totalCount:S}),p.render(),this.renderSideBar(),this.renderLoadingOverlay();}renderHeaderFilterPopover(){let{headerFilterState:e,headerFilterComponent:t,filterConfigs:n}=this.ctx,i=e.openColumnId,r=this.ctx.tableContainer.querySelectorAll(".ogrid-filter-icon[aria-haspopup]");for(let s of r){let a=s.closest("th[data-column-id]")?.getAttribute("data-column-id");s.setAttribute("aria-expanded",a===i?"true":"false");}if(!i){t.cleanup();return}let o=n.get(i);if(!o)return;t.render(o);let l=document.querySelector(".ogrid-header-filter-popover");e.setPopoverEl(l);}renderSideBar(){let{sideBarComponent:e,sideBarState:t,state:n}=this.ctx;if(!e||!t)return;let i=n.columns.map(o=>({columnId:o.columnId,name:o.name,required:o.required===true})),r=n.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:i,visibleColumns:n.visibleColumns,onVisibilityChange:(o,l)=>{let s=new Set(n.visibleColumns);l?s.add(o):s.delete(o),n.setVisibleColumns(s);},onSetVisibleColumns:o=>n.setVisibleColumns(o),filterableColumns:r,filters:n.filters,onFilterChange:(o,l)=>n.setFilter(o,l),filterOptions:n.filterOptions}),e.render();}renderLoadingOverlay(){let{state:e,tableContainer:t}=this.ctx;if(e.isLoading){let{items:n}=e.getProcessedItems();t.style.minHeight=!n||n.length===0?"200px":"";let i=this.ctx.loadingOverlay;if(!i){i=document.createElement("div"),i.className="ogrid-loading-overlay",i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.right="0",i.style.bottom="0",i.style.display="flex",i.style.alignItems="center",i.style.justifyContent="center",i.style.background="var(--ogrid-loading-overlay, rgba(255, 255, 255, 0.7))",i.style.zIndex="100";let r=document.createElement("div");r.className="ogrid-loading-spinner",r.textContent="Loading...",i.appendChild(r),this.ctx.setLoadingOverlay(i);}t.contains(i)||t.appendChild(i);}else {t.style.minHeight="";let n=this.ctx.loadingOverlay;n&&t.contains(n)&&n.remove();}}};var he=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,n]of Object.entries(e.sheets))this.engine.registerSheet(t,n);}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,n,i){if(!this.engine)return;let r=this.engine.setFormula(e,t,n,i);return r.updatedCells.length>0&&this.emitRecalc(r),r}onCellChanged(e,t,n){if(!this.engine)return;let i=this.engine.onCellChanged(e,t,n);return i.updatedCells.length>0&&this.emitRecalc(i),i}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 pe=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 qt=`
|
|
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;
|
|
@@ -101,4 +101,4 @@ import {flattenColumns,resolveResponsiveConfig,deriveFilterOptionsFromData,valid
|
|
|
101
101
|
--ogrid-bg-selected: #1a3a5c;
|
|
102
102
|
--ogrid-loading-bg: rgba(0, 0, 0, 0.7);
|
|
103
103
|
}
|
|
104
|
-
`,we=class{constructor(e,t){this.sideBarState=null;this.sideBarComponent=null;this.sideBarContainer=null;this.filterConfigs=new Map;this.loadingOverlay=null;this.bodyArea=null;this.selectionState=null;this.keyboardNavState=null;this.clipboardState=null;this.undoRedoState=null;this.resizeState=null;this.fillHandleState=null;this.rowSelectionState=null;this.pinningState=null;this.reorderState=null;this.virtualScrollState=null;this.marchingAnts=null;this.cellEditor=null;this.contextMenu=null;this.formulaEngine=null;this.formulaBar=null;this.formulaBarContainer=null;this.formulaBarText="";this.formulaBarEditing=false;this.events=new x;this.unsubscribes=[];this.isFullScreen=false;this.fullscreenBtn=null;this.nameBoxEl=null;this.options=t,this.state=new N(t),this.api=this.state.getApi(),this.eventWiringHelper=new ce,t.formulas&&(this.formulaEngine=new he({formulas:true,initialFormulas:t.initialFormulas,onFormulaRecalc:t.onFormulaRecalc,formulaFunctions:t.formulaFunctions,namedRanges:t.namedRanges,sheets:t.sheets}),this.state.setFormulaEngine(this.formulaEngine)),injectGlobalStyles("ogrid-theme-vars",Xt),this.containerEl=document.createElement("div"),this.containerEl.className="ogrid-container",this.toolbarEl=document.createElement("div"),this.toolbarEl.className="ogrid-toolbar";let n=document.createElement("div");if(this.toolbarEl.appendChild(n),t.cellReferences&&(this.nameBoxEl=document.createElement("div"),this.nameBoxEl.className="ogrid-name-box",this.nameBoxEl.style.cssText="display:inline-flex;align-items:center;padding:0 8px;font-family:'Consolas','Courier New',monospace;font-size:12px;border:1px solid var(--ogrid-border, rgba(0,0,0,0.12));border-radius:3px;height:24px;margin-right:8px;background:var(--ogrid-bg, #fff);min-width:40px;color:var(--ogrid-fg-secondary, rgba(0,0,0,0.6));",this.nameBoxEl.textContent="\u2014",n.appendChild(this.nameBoxEl)),t.fullScreen){let i=document.createElement("div");i.style.display="flex",i.style.alignItems="center",i.style.gap="8px",this.fullscreenBtn=document.createElement("button"),this.fullscreenBtn.type="button",this.fullscreenBtn.className="ogrid-fullscreen-btn",this.fullscreenBtn.title="Fullscreen",this.fullscreenBtn.setAttribute("aria-label","Fullscreen"),this.fullscreenBtn.innerHTML='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="10 2 14 2 14 6"/><polyline points="6 14 2 14 2 10"/><line x1="14" y1="2" x2="10" y2="6"/><line x1="2" y1="14" x2="6" y2="10"/></svg>',this.fullscreenBtn.addEventListener("click",()=>this.toggleFullScreen()),i.appendChild(this.fullscreenBtn),this.toolbarEl.appendChild(i);let r=o=>{o.key==="Escape"&&this.isFullScreen&&this.toggleFullScreen();};document.addEventListener("keydown",r),this.unsubscribes.push(()=>document.removeEventListener("keydown",r));}this.containerEl.appendChild(this.toolbarEl),t.formulas&&(this.formulaBarContainer=document.createElement("div"),this.formulaBarContainer.className="ogrid-formula-bar-container",this.formulaBar=new pe({onCommit:()=>this.handleFormulaBarCommit(),onCancel:()=>this.handleFormulaBarCancel(),onInputChange:i=>{this.formulaBarText=i;},onStartEditing:()=>this.handleFormulaBarStartEditing()}),this.formulaBar.mount(this.formulaBarContainer),this.containerEl.appendChild(this.formulaBarContainer)),this.bodyArea=document.createElement("div"),this.bodyArea.className="ogrid-body-area",this.bodyArea.style.display="flex",this.bodyArea.style.flex="1",this.bodyArea.style.overflow="hidden",this.containerEl.appendChild(this.bodyArea),this.tableContainer=document.createElement("div"),this.tableContainer.className="ogrid-table-container",this.tableContainer.style.flex="1",this.tableContainer.style.overflow="auto",this.tableContainer.style.position="relative",this.bodyArea.appendChild(this.tableContainer),this.statusBarContainer=document.createElement("div"),this.statusBarContainer.className="ogrid-status-bar-container",this.containerEl.appendChild(this.statusBarContainer),this.paginationContainer=document.createElement("div"),this.paginationContainer.className="ogrid-pagination-container",this.containerEl.appendChild(this.paginationContainer),e.appendChild(this.containerEl),this.layoutState=new j,this.layoutState.observeContainer(this.tableContainer),t.responsiveColumns&&this.state.setContainerWidth(this.layoutState.containerWidth),this.renderer=new V(this.tableContainer,this.state),this.formulaEngine&&this.renderer.setFormulaEngine(this.formulaEngine),this.pagination=new W(this.paginationContainer,this.state),this.statusBar=new U(this.statusBarContainer),this.columnChooser=new G(this.toolbarEl,this.state),this.headerFilterState=new X((i,r)=>{this.state.setFilter(i,r);}),this.headerFilterComponent=new q(this.headerFilterState),this.buildFilterConfigs();try{this.renderer.setHeaderFilterState(this.headerFilterState,this.filterConfigs),this.renderer.setOnFilterIconClick((o,l)=>{this.handleFilterIconClick(o,l);}),t.sideBar&&(this.sideBarState=new K(t.sideBar),this.sideBarContainer=document.createElement("div"),this.sideBarContainer.className="ogrid-sidebar-container",this.sideBarComponent=new $(this.sideBarContainer,this.sideBarState),this.bodyArea&&(this.sideBarState.position==="left"?this.bodyArea.insertBefore(this.sideBarContainer,this.tableContainer):this.bodyArea.appendChild(this.sideBarContainer)),this.unsubscribes.push(this.sideBarState.onChange(()=>{this.renderingHelper.renderSideBar();})));let i=flattenColumns(t.columns);if(this.pinningState=new Z(t.pinnedColumns,i),t.rowSelection&&t.rowSelection!=="none"&&(this.rowSelectionState=new Y(t.rowSelection,t.getRowId),this.api.getSelectedRows=()=>Array.from(this.rowSelectionState?.selectedRowIds??[]),this.api.selectAll=()=>{let{items:o}=this.state.getProcessedItems();this.rowSelectionState?.handleSelectAll(!0,o);},this.api.deselectAll=()=>{let{items:o}=this.state.getProcessedItems();this.rowSelectionState?.handleSelectAll(!1,o);},this.api.setSelectedRows=o=>{let{items:l}=this.state.getProcessedItems();this.rowSelectionState?.updateSelection(new Set(o),l);},this.unsubscribes.push(this.rowSelectionState.onRowSelectionChange(()=>{this.renderingHelper.updateRendererInteractionState();}))),this.renderingHelper=this.createRenderingHelper(),this.renderer.render(),t.cellSelection!==!1||t.editable===!0){let o=this.eventWiringHelper.initializeInteraction(t,this.state,this.renderer,this.tableContainer,this.layoutState,this.rowSelectionState,this.pinningState,{updateRendererInteractionState:()=>this.renderingHelper.updateRendererInteractionState(),updateDragAttributes:()=>this.renderingHelper.updateDragAttributes(),clearCachedDragCells:()=>this.renderingHelper.clearCachedDragCells(),showContextMenu:(l,s)=>this.showContextMenu(l,s),startCellEdit:(l,s)=>this.startCellEdit(l,s)});if(this.selectionState=o.selectionState,this.keyboardNavState=o.keyboardNavState,this.clipboardState=o.clipboardState,this.undoRedoState=o.undoRedoState,this.resizeState=o.resizeState,this.fillHandleState=o.fillHandleState,this.reorderState=o.reorderState,this.marchingAnts=o.marchingAnts,this.cellEditor=o.cellEditor,this.contextMenu=o.contextMenu,this.unsubscribes.push(...o.unsubscribes),this.nameBoxEl&&this.selectionState){let l=this.nameBoxEl,s=this.selectionState,a=0;this.rowSelectionState&&a++,(t.showRowNumbers||t.cellReferences)&&a++,this.unsubscribes.push(s.onSelectionChange(({activeCell:c})=>{if(c){let d=c.columnIndex-a,p=(this.state.page-1)*this.state.pageSize+c.rowIndex+1;l.textContent=formatCellReference(d,p);}else l.textContent="\u2014";}));}if(this.formulaBar&&this.selectionState&&this.formulaEngine){let l=this.formulaBar,s=this.selectionState,a=this.formulaEngine,c=0;this.rowSelectionState&&c++,(t.showRowNumbers||t.cellReferences||t.formulas)&&c++,this.unsubscribes.push(s.onSelectionChange(({activeCell:d})=>{if(this.formulaBarEditing=!1,l.setEditing(!1),d){let p=d.columnIndex-c,m=(this.state.page-1)*this.state.pageSize+d.rowIndex,v=formatCellReference(p,m+1),f=a.getFormula(p,m);if(f)this.formulaBarText=f,l.update(v,f);else {let{items:b}=this.state.getProcessedItems(),u=this.state.visibleColumnDefs,g=b[d.rowIndex],h=u[p],S=g&&h?String(g[h.columnId]??""):"";this.formulaBarText=S,l.update(v,S);}}else this.formulaBarText="",l.update(null,"");}));}}if(this.unsubscribes.push(this.state.onStateChange(()=>{this.renderingHelper.renderAll();})),this.unsubscribes.push(this.pinningState.onPinningChange(()=>{this.renderingHelper.updateRendererInteractionState();})),this.unsubscribes.push(this.headerFilterState.onChange(()=>{this.renderingHelper.renderHeaderFilterPopover();})),t.responsiveColumns&&this.unsubscribes.push(this.layoutState.onLayoutChange(o=>{o.type==="containerResize"&&this.state.setContainerWidth(this.layoutState.containerWidth);})),t.virtualScroll?.enabled){this.virtualScrollState=new J(t.virtualScroll),this.virtualScrollState.observeContainer(this.tableContainer),this.renderer.setVirtualScrollState(this.virtualScrollState);let o=()=>{this.virtualScrollState?.handleScroll(this.tableContainer.scrollTop),this.virtualScrollState?.handleHorizontalScroll(this.tableContainer.scrollLeft);};this.tableContainer.addEventListener("scroll",o,{passive:!0}),this.unsubscribes.push(()=>{this.tableContainer.removeEventListener("scroll",o);}),t.virtualScroll?.columns&&this.virtualScrollState.observeContainerWidth(this.tableContainer),this.unsubscribes.push(this.virtualScrollState.onRangeChanged(()=>{this.renderingHelper.updateRendererInteractionState();})),this.unsubscribes.push(this.virtualScrollState.onColumnRangeChanged(()=>{this.renderingHelper.updateRendererInteractionState();})),this.api.scrollToRow=(l,s)=>{this.virtualScrollState?.scrollToRow(l,this.tableContainer,s?.align);};}this.renderingHelper.renderAll();}catch(i){throw this.destroy(),i}}createRenderingHelper(){let e=n=>({get:n,enumerable:true,configurable:true}),t={options:this.options,state:this.state,renderer:this.renderer,pagination:this.pagination,statusBar:this.statusBar,columnChooser:this.columnChooser,layoutState:this.layoutState,tableContainer:this.tableContainer,headerFilterState:this.headerFilterState,headerFilterComponent:this.headerFilterComponent,filterConfigs:this.filterConfigs,setLoadingOverlay:n=>{this.loadingOverlay=n;},handleCellClick:(n,i)=>this.handleCellClick(n,i),handleCellMouseDown:(n,i,r)=>this.handleCellMouseDown(n,i,r),handleCellContextMenu:(n,i,r)=>this.handleCellContextMenu(n,i,r),startCellEdit:(n,i)=>this.startCellEdit(n,i),toggleBooleanCell:(n,i,r)=>this.toggleBooleanCell(n,i,r),showContextMenu:(n,i)=>this.showContextMenu(n,i)};return Object.defineProperties(t,{selectionState:e(()=>this.selectionState),keyboardNavState:e(()=>this.keyboardNavState),clipboardState:e(()=>this.clipboardState),undoRedoState:e(()=>this.undoRedoState),resizeState:e(()=>this.resizeState),fillHandleState:e(()=>this.fillHandleState),rowSelectionState:e(()=>this.rowSelectionState),pinningState:e(()=>this.pinningState),reorderState:e(()=>this.reorderState),virtualScrollState:e(()=>this.virtualScrollState),marchingAnts:e(()=>this.marchingAnts),cellEditor:e(()=>this.cellEditor),sideBarState:e(()=>this.sideBarState),sideBarComponent:e(()=>this.sideBarComponent),loadingOverlay:e(()=>this.loadingOverlay)}),new ue(t)}handleCellClick(e,t){this.selectionState&&this.selectionState.setActiveCell({rowIndex:e,columnIndex:t});}handleCellMouseDown(e,t,n){this.selectionState&&(this.cellEditor?.closeEditor(),n.preventDefault(),this.selectionState.startDrag(e,t),setTimeout(()=>this.renderingHelper.updateDragAttributes(),0));}handleCellContextMenu(e,t,n){n.preventDefault(),!(!this.contextMenu||!this.selectionState||!this.clipboardState||!this.undoRedoState)&&((!this.selectionState.activeCell||this.selectionState.activeCell.rowIndex!==e||this.selectionState.activeCell.columnIndex!==t)&&(this.selectionState.setActiveCell({rowIndex:e,columnIndex:t}),this.renderingHelper.updateRendererInteractionState()),this.showContextMenu(n.clientX,n.clientY));}showContextMenu(e,t){!this.contextMenu||!this.clipboardState||!this.undoRedoState||!this.keyboardNavState||!this.selectionState||this.contextMenu.show(e,t,{onCopy:()=>this.clipboardState?.handleCopy(),onCut:()=>this.clipboardState?.handleCut(),onPaste:()=>{this.clipboardState?.handlePaste();},onSelectAll:()=>{let{items:n}=this.state.getProcessedItems(),i=this.state.visibleColumnDefs;n.length>0&&i.length>0&&(this.selectionState?.setSelectionRange({startRow:0,startCol:0,endRow:n.length-1,endCol:i.length-1}),this.renderingHelper.updateRendererInteractionState());},onUndo:()=>this.undoRedoState?.undo(),onRedo:()=>this.undoRedoState?.redo()},this.undoRedoState.canUndo,this.undoRedoState.canRedo,this.selectionState.selectionRange);}toggleBooleanCell(e,t,n){let{items:i}=this.state.getProcessedItems(),r=i.findIndex(a=>this.state.getRowId(a)===e);if(r<0)return;let o=i[r],l=!n;o[t]=l;let s=this.undoRedoState?.getWrappedCallback();s&&s({item:o,columnId:t,oldValue:n,newValue:l,rowIndex:r}),this.renderingHelper.updateRendererInteractionState();}startCellEdit(e,t){if(!this.cellEditor||!this.undoRedoState)return;let{items:n}=this.state.getProcessedItems(),i=this.state.visibleColumnDefs,r=n.find(f=>this.state.getRowId(f)===e),o=i.find(f=>f.columnId===t);if(!r||!o)return;let l=this.renderer.getWrapperElement();if(!l)return;let s=l.querySelector(`tr[data-row-id="${e}"]`);if(!s)return;let a=s.querySelector(`td[data-column-id="${t}"]`);if(!a)return;let c=n.indexOf(r),d=(f,b,u)=>{if(!i.find(I=>I.columnId===b))return;let h=r[b];r[b]=u;let S=this.undoRedoState?.getWrappedCallback();S&&S({item:r,columnId:b,oldValue:h,newValue:u,rowIndex:c}),this.renderingHelper.updateRendererInteractionState();},p=()=>{this.renderingHelper.updateRendererInteractionState();},m=()=>{if(this.selectionState){let b=this.selectionState.activeCell;if(b){let{items:u}=this.state.getProcessedItems(),g=Math.min(b.rowIndex+1,u.length-1);this.selectionState.setActiveCell({rowIndex:g,columnIndex:b.columnIndex});let h=this.renderer.getColOffset(),S=b.columnIndex-h;this.selectionState.setSelectionRange({startRow:g,startCol:S,endRow:g,endCol:S});}}this.renderer.getWrapperElement()?.focus();},v;if(this.formulaEngine){let b=this.state.columns.findIndex(u=>u.columnId===t);b>=0&&this.formulaEngine.hasFormula(b,c)&&(v=this.formulaEngine.getFormula(b,c));}this.cellEditor.startEdit(e,t,r,o,a,d,p,m,v);}buildFilterConfigs(){let e=flattenColumns(this.options.columns);for(let t of e){let n=t.filterable&&typeof t.filterable=="object"?t.filterable:null;n&&n.type&&this.filterConfigs.set(t.columnId,{columnId:t.columnId,filterField:n.filterField??t.columnId,filterType:n.type});}}handleFilterIconClick(e,t){let n=this.filterConfigs.get(e);if(!n)return;if(this.headerFilterState.openColumnId===e){this.headerFilterState.close();return}let i=document.createElement("div");this.headerFilterState.setFilters(this.state.filters),this.headerFilterState.setFilterOptions(this.state.filterOptions),this.headerFilterState.open(e,n,t,i);}buildFormulaAccessor(){let{items:e}=this.state.getProcessedItems(),t=this.state.visibleColumnDefs;return {getCellValue:(n,i)=>{let r=e[i],o=t[n];if(!(!r||!o))return r[o.columnId]},getRowCount:()=>e.length,getColumnCount:()=>t.length}}handleFormulaBarCommit(){if(!this.formulaEngine||!this.selectionState)return;let e=this.selectionState.activeCell;if(!e)return;let t=0;this.rowSelectionState&&t++,(this.options.showRowNumbers||this.options.cellReferences||this.options.formulas)&&t++;let n=e.columnIndex-t,i=(this.state.page-1)*this.state.pageSize+e.rowIndex,r=this.formulaBarText,o=this.buildFormulaAccessor();if(r.startsWith("="))this.formulaEngine.setFormula(n,i,r,o);else {this.formulaEngine.hasFormula(n,i)&&this.formulaEngine.setFormula(n,i,null,o);let{items:l}=this.state.getProcessedItems(),s=this.state.visibleColumnDefs,a=l[e.rowIndex],c=s[n];a&&c&&(a[c.columnId]=r);}this.formulaBarEditing=false,this.formulaBar?.setEditing(false),this.renderingHelper.updateRendererInteractionState(),this.renderer.getWrapperElement()?.focus();}handleFormulaBarCancel(){if(this.selectionState?.activeCell&&this.formulaEngine){let e=this.selectionState.activeCell,t=0;this.rowSelectionState&&t++,(this.options.showRowNumbers||this.options.cellReferences||this.options.formulas)&&t++;let n=e.columnIndex-t,i=(this.state.page-1)*this.state.pageSize+e.rowIndex,r=this.formulaEngine.getFormula(n,i);if(r)this.formulaBarText=r,this.formulaBar?.update(formatCellReference(n,i+1),r);else {let{items:o}=this.state.getProcessedItems(),l=this.state.visibleColumnDefs,s=o[e.rowIndex],a=l[n],c=s&&a?String(s[a.columnId]??""):"";this.formulaBarText=c,this.formulaBar?.update(formatCellReference(n,i+1),c);}}this.formulaBarEditing=false,this.formulaBar?.setEditing(false),this.renderer.getWrapperElement()?.focus();}handleFormulaBarStartEditing(){this.selectionState?.activeCell&&(this.formulaBarEditing=true,this.formulaBar?.setEditing(true));}on(e,t){this.events.on(e,t);}off(e,t){this.events.off(e,t);}toggleFullScreen(){this.isFullScreen=!this.isFullScreen,this.isFullScreen?this.containerEl.classList.add("ogrid-fullscreen"):this.containerEl.classList.remove("ogrid-fullscreen"),this.fullscreenBtn&&(this.fullscreenBtn.title=this.isFullScreen?"Exit fullscreen":"Fullscreen",this.fullscreenBtn.setAttribute("aria-label",this.isFullScreen?"Exit fullscreen":"Fullscreen"),this.fullscreenBtn.innerHTML=this.isFullScreen?'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 10 0 10 0 14"/><polyline points="12 6 16 6 16 2"/><line x1="0" y1="10" x2="4" y2="6"/><line x1="16" y1="6" x2="12" y2="10"/></svg>':'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="10 2 14 2 14 6"/><polyline points="6 14 2 14 2 10"/><line x1="14" y1="2" x2="10" y2="6"/><line x1="2" y1="14" x2="6" y2="10"/></svg>');}destroy(){this.unsubscribes.forEach(e=>e()),this.renderer.destroy(),this.pagination.destroy(),this.statusBar.destroy(),this.columnChooser.destroy(),this.sideBarState?.destroy(),this.sideBarComponent?.destroy(),this.headerFilterState.destroy(),this.headerFilterComponent.destroy(),this.state.destroy(),this.selectionState?.destroy(),this.clipboardState?.destroy(),this.undoRedoState?.destroy(),this.resizeState?.destroy(),this.fillHandleState?.destroy(),this.rowSelectionState?.destroy(),this.pinningState?.destroy(),this.reorderState?.destroy(),this.virtualScrollState?.destroy(),this.marchingAnts?.destroy(),this.layoutState.destroy(),this.cellEditor?.closeEditor(),this.contextMenu?.close(),this.formulaBar?.destroy(),this.formulaEngine?.destroy(),this.events.removeAllListeners(),this.containerEl.remove();}};export{te as ClipboardState,G as ColumnChooser,Z as ColumnPinningState,re as ColumnReorderState,ie as ColumnResizeState,de as ContextMenu,x as EventEmitter,oe as FillHandleState,pe as FormulaBar,he as FormulaEngineState,N as GridState,q as HeaderFilter,X as HeaderFilterState,ae as InlineCellEditor,ee as KeyboardNavState,le as MarchingAntsOverlay,we as OGrid,ce as OGridEventWiring,ue as OGridRendering,W as PaginationControls,Y as RowSelectionState,Q as SelectionState,$ as SideBar,K as SideBarState,U as StatusBar,j as TableLayoutState,V as TableRenderer,ne as UndoRedoState,J as VirtualScrollState};
|
|
104
|
+
`,we=class{constructor(e,t){this.sideBarState=null;this.sideBarComponent=null;this.sideBarContainer=null;this.filterConfigs=new Map;this.loadingOverlay=null;this.bodyArea=null;this.selectionState=null;this.keyboardNavState=null;this.clipboardState=null;this.undoRedoState=null;this.resizeState=null;this.fillHandleState=null;this.rowSelectionState=null;this.pinningState=null;this.reorderState=null;this.virtualScrollState=null;this.marchingAnts=null;this.cellEditor=null;this.contextMenu=null;this.formulaEngine=null;this.formulaBar=null;this.formulaBarContainer=null;this.formulaBarText="";this.formulaBarEditing=false;this.events=new x;this.unsubscribes=[];this.isFullScreen=false;this.fullscreenBtn=null;this.nameBoxEl=null;this.options=t,this.state=new N(t),this.api=this.state.getApi(),this.eventWiringHelper=new ce,t.formulas&&(this.formulaEngine=new he({formulas:true,initialFormulas:t.initialFormulas,onFormulaRecalc:t.onFormulaRecalc,formulaFunctions:t.formulaFunctions,namedRanges:t.namedRanges,sheets:t.sheets}),this.state.setFormulaEngine(this.formulaEngine)),injectGlobalStyles("ogrid-theme-vars",qt),this.containerEl=document.createElement("div"),this.containerEl.className="ogrid-container",this.toolbarEl=document.createElement("div"),this.toolbarEl.className="ogrid-toolbar";let n=document.createElement("div");if(this.toolbarEl.appendChild(n),t.cellReferences&&(this.nameBoxEl=document.createElement("div"),this.nameBoxEl.className="ogrid-name-box",this.nameBoxEl.style.cssText="display:inline-flex;align-items:center;padding:0 8px;font-family:'Consolas','Courier New',monospace;font-size:12px;border:1px solid var(--ogrid-border, rgba(0,0,0,0.12));border-radius:3px;height:24px;margin-right:8px;background:var(--ogrid-bg, #fff);min-width:40px;color:var(--ogrid-fg-secondary, rgba(0,0,0,0.6));",this.nameBoxEl.textContent="\u2014",n.appendChild(this.nameBoxEl)),t.fullScreen){let i=document.createElement("div");i.style.display="flex",i.style.alignItems="center",i.style.gap="8px",this.fullscreenBtn=document.createElement("button"),this.fullscreenBtn.type="button",this.fullscreenBtn.className="ogrid-fullscreen-btn",this.fullscreenBtn.title="Fullscreen",this.fullscreenBtn.setAttribute("aria-label","Fullscreen"),this.fullscreenBtn.innerHTML='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="10 2 14 2 14 6"/><polyline points="6 14 2 14 2 10"/><line x1="14" y1="2" x2="10" y2="6"/><line x1="2" y1="14" x2="6" y2="10"/></svg>',this.fullscreenBtn.addEventListener("click",()=>this.toggleFullScreen()),i.appendChild(this.fullscreenBtn),this.toolbarEl.appendChild(i);let r=o=>{o.key==="Escape"&&this.isFullScreen&&this.toggleFullScreen();};document.addEventListener("keydown",r),this.unsubscribes.push(()=>document.removeEventListener("keydown",r));}this.containerEl.appendChild(this.toolbarEl),t.formulas&&(this.formulaBarContainer=document.createElement("div"),this.formulaBarContainer.className="ogrid-formula-bar-container",this.formulaBar=new pe({onCommit:()=>this.handleFormulaBarCommit(),onCancel:()=>this.handleFormulaBarCancel(),onInputChange:i=>{this.formulaBarText=i;},onStartEditing:()=>this.handleFormulaBarStartEditing()}),this.formulaBar.mount(this.formulaBarContainer),this.containerEl.appendChild(this.formulaBarContainer)),this.bodyArea=document.createElement("div"),this.bodyArea.className="ogrid-body-area",this.bodyArea.style.display="flex",this.bodyArea.style.flex="1",this.bodyArea.style.overflow="hidden",this.containerEl.appendChild(this.bodyArea),this.tableContainer=document.createElement("div"),this.tableContainer.className="ogrid-table-container",this.tableContainer.style.flex="1",this.tableContainer.style.overflow="auto",this.tableContainer.style.position="relative",this.bodyArea.appendChild(this.tableContainer),this.statusBarContainer=document.createElement("div"),this.statusBarContainer.className="ogrid-status-bar-container",this.containerEl.appendChild(this.statusBarContainer),this.paginationContainer=document.createElement("div"),this.paginationContainer.className="ogrid-pagination-container",this.containerEl.appendChild(this.paginationContainer),e.appendChild(this.containerEl),this.layoutState=new j,this.layoutState.observeContainer(this.tableContainer),t.responsiveColumns&&this.state.setContainerWidth(this.layoutState.containerWidth),this.renderer=new V(this.tableContainer,this.state),this.formulaEngine&&this.renderer.setFormulaEngine(this.formulaEngine),this.pagination=new W(this.paginationContainer,this.state),this.statusBar=new U(this.statusBarContainer),this.columnChooser=new G(this.toolbarEl,this.state),this.headerFilterState=new X((i,r)=>{this.state.setFilter(i,r);}),this.headerFilterComponent=new q(this.headerFilterState),this.buildFilterConfigs();try{this.renderer.setHeaderFilterState(this.headerFilterState,this.filterConfigs),this.renderer.setOnFilterIconClick((o,l)=>{this.handleFilterIconClick(o,l);}),t.sideBar&&(this.sideBarState=new K(t.sideBar),this.sideBarContainer=document.createElement("div"),this.sideBarContainer.className="ogrid-sidebar-container",this.sideBarComponent=new $(this.sideBarContainer,this.sideBarState),this.bodyArea&&(this.sideBarState.position==="left"?this.bodyArea.insertBefore(this.sideBarContainer,this.tableContainer):this.bodyArea.appendChild(this.sideBarContainer)),this.unsubscribes.push(this.sideBarState.onChange(()=>{this.renderingHelper.renderSideBar();})));let i=flattenColumns(t.columns);if(this.pinningState=new Z(t.pinnedColumns,i),t.rowSelection&&t.rowSelection!=="none"&&(this.rowSelectionState=new Y(t.rowSelection,t.getRowId),this.api.getSelectedRows=()=>Array.from(this.rowSelectionState?.selectedRowIds??[]),this.api.selectAll=()=>{let{items:o}=this.state.getProcessedItems();this.rowSelectionState?.handleSelectAll(!0,o);},this.api.deselectAll=()=>{let{items:o}=this.state.getProcessedItems();this.rowSelectionState?.handleSelectAll(!1,o);},this.api.setSelectedRows=o=>{let{items:l}=this.state.getProcessedItems();this.rowSelectionState?.updateSelection(new Set(o),l);},this.unsubscribes.push(this.rowSelectionState.onRowSelectionChange(()=>{this.renderingHelper.updateRendererInteractionState();}))),this.renderingHelper=this.createRenderingHelper(),this.renderer.render(),t.cellSelection!==!1||t.editable===!0){let o=this.eventWiringHelper.initializeInteraction(t,this.state,this.renderer,this.tableContainer,this.layoutState,this.rowSelectionState,this.pinningState,{updateRendererInteractionState:()=>this.renderingHelper.updateRendererInteractionState(),updateDragAttributes:()=>this.renderingHelper.updateDragAttributes(),clearCachedDragCells:()=>this.renderingHelper.clearCachedDragCells(),showContextMenu:(l,s)=>this.showContextMenu(l,s),startCellEdit:(l,s)=>this.startCellEdit(l,s)});if(this.selectionState=o.selectionState,this.keyboardNavState=o.keyboardNavState,this.clipboardState=o.clipboardState,this.undoRedoState=o.undoRedoState,this.resizeState=o.resizeState,this.fillHandleState=o.fillHandleState,this.reorderState=o.reorderState,this.marchingAnts=o.marchingAnts,this.cellEditor=o.cellEditor,this.contextMenu=o.contextMenu,this.unsubscribes.push(...o.unsubscribes),this.nameBoxEl&&this.selectionState){let l=this.nameBoxEl,s=this.selectionState,a=0;this.rowSelectionState&&a++,(t.showRowNumbers||t.cellReferences)&&a++,this.unsubscribes.push(s.onSelectionChange(({activeCell:c})=>{if(c){let d=c.columnIndex-a,p=(this.state.page-1)*this.state.pageSize+c.rowIndex+1;l.textContent=formatCellReference(d,p);}else l.textContent="\u2014";}));}if(this.formulaBar&&this.selectionState&&this.formulaEngine){let l=this.formulaBar,s=this.selectionState,a=this.formulaEngine,c=0;this.rowSelectionState&&c++,(t.showRowNumbers||t.cellReferences||t.formulas)&&c++,this.unsubscribes.push(s.onSelectionChange(({activeCell:d})=>{if(this.formulaBarEditing=!1,l.setEditing(!1),d){let p=d.columnIndex-c,m=(this.state.page-1)*this.state.pageSize+d.rowIndex,v=formatCellReference(p,m+1),f=a.getFormula(p,m);if(f)this.formulaBarText=f,l.update(v,f);else {let{items:S}=this.state.getProcessedItems(),u=this.state.visibleColumnDefs,g=S[d.rowIndex],h=u[p],y=g&&h?String(g[h.columnId]??""):"";this.formulaBarText=y,l.update(v,y);}}else this.formulaBarText="",l.update(null,"");}));}}if(this.unsubscribes.push(this.state.onStateChange(()=>{this.renderingHelper.renderAll();})),this.unsubscribes.push(this.pinningState.onPinningChange(()=>{this.renderingHelper.updateRendererInteractionState();})),this.unsubscribes.push(this.headerFilterState.onChange(()=>{this.renderingHelper.renderHeaderFilterPopover();})),t.responsiveColumns&&this.unsubscribes.push(this.layoutState.onLayoutChange(o=>{o.type==="containerResize"&&this.state.setContainerWidth(this.layoutState.containerWidth);})),t.virtualScroll?.enabled){this.virtualScrollState=new J(t.virtualScroll),this.virtualScrollState.observeContainer(this.tableContainer),this.renderer.setVirtualScrollState(this.virtualScrollState);let o=()=>{this.virtualScrollState?.handleScroll(this.tableContainer.scrollTop),this.virtualScrollState?.handleHorizontalScroll(this.tableContainer.scrollLeft);};this.tableContainer.addEventListener("scroll",o,{passive:!0}),this.unsubscribes.push(()=>{this.tableContainer.removeEventListener("scroll",o);}),t.virtualScroll?.columns&&this.virtualScrollState.observeContainerWidth(this.tableContainer),this.unsubscribes.push(this.virtualScrollState.onRangeChanged(()=>{this.renderingHelper.updateRendererInteractionState();})),this.unsubscribes.push(this.virtualScrollState.onColumnRangeChanged(()=>{this.renderingHelper.updateRendererInteractionState();})),this.api.scrollToRow=(l,s)=>{this.virtualScrollState?.scrollToRow(l,this.tableContainer,s?.align);};}this.renderingHelper.renderAll();}catch(i){throw this.destroy(),i}}createRenderingHelper(){let e=n=>({get:n,enumerable:true,configurable:true}),t={options:this.options,state:this.state,renderer:this.renderer,pagination:this.pagination,statusBar:this.statusBar,columnChooser:this.columnChooser,layoutState:this.layoutState,tableContainer:this.tableContainer,headerFilterState:this.headerFilterState,headerFilterComponent:this.headerFilterComponent,filterConfigs:this.filterConfigs,setLoadingOverlay:n=>{this.loadingOverlay=n;},handleCellClick:(n,i)=>this.handleCellClick(n,i),handleCellMouseDown:(n,i,r)=>this.handleCellMouseDown(n,i,r),handleCellContextMenu:(n,i,r)=>this.handleCellContextMenu(n,i,r),startCellEdit:(n,i)=>this.startCellEdit(n,i),toggleBooleanCell:(n,i,r)=>this.toggleBooleanCell(n,i,r),showContextMenu:(n,i)=>this.showContextMenu(n,i)};return Object.defineProperties(t,{selectionState:e(()=>this.selectionState),keyboardNavState:e(()=>this.keyboardNavState),clipboardState:e(()=>this.clipboardState),undoRedoState:e(()=>this.undoRedoState),resizeState:e(()=>this.resizeState),fillHandleState:e(()=>this.fillHandleState),rowSelectionState:e(()=>this.rowSelectionState),pinningState:e(()=>this.pinningState),reorderState:e(()=>this.reorderState),virtualScrollState:e(()=>this.virtualScrollState),marchingAnts:e(()=>this.marchingAnts),cellEditor:e(()=>this.cellEditor),sideBarState:e(()=>this.sideBarState),sideBarComponent:e(()=>this.sideBarComponent),loadingOverlay:e(()=>this.loadingOverlay)}),new ue(t)}handleCellClick(e,t){this.selectionState&&this.selectionState.setActiveCell({rowIndex:e,columnIndex:t});}handleCellMouseDown(e,t,n){this.selectionState&&(this.cellEditor?.closeEditor(),n.preventDefault(),this.selectionState.startDrag(e,t),this.renderingHelper.updateDragAttributes());}handleCellContextMenu(e,t,n){n.preventDefault(),!(!this.contextMenu||!this.selectionState||!this.clipboardState||!this.undoRedoState)&&((!this.selectionState.activeCell||this.selectionState.activeCell.rowIndex!==e||this.selectionState.activeCell.columnIndex!==t)&&(this.selectionState.setActiveCell({rowIndex:e,columnIndex:t}),this.renderingHelper.updateRendererInteractionState()),this.showContextMenu(n.clientX,n.clientY));}showContextMenu(e,t){!this.contextMenu||!this.clipboardState||!this.undoRedoState||!this.keyboardNavState||!this.selectionState||this.contextMenu.show(e,t,{onCopy:()=>this.clipboardState?.handleCopy(),onCut:()=>this.clipboardState?.handleCut(),onPaste:()=>{this.clipboardState?.handlePaste();},onSelectAll:()=>{let{items:n}=this.state.getProcessedItems(),i=this.state.visibleColumnDefs;n.length>0&&i.length>0&&(this.selectionState?.setSelectionRange({startRow:0,startCol:0,endRow:n.length-1,endCol:i.length-1}),this.renderingHelper.updateRendererInteractionState());},onUndo:()=>this.undoRedoState?.undo(),onRedo:()=>this.undoRedoState?.redo()},this.undoRedoState.canUndo,this.undoRedoState.canRedo,this.selectionState.selectionRange);}toggleBooleanCell(e,t,n){let{items:i}=this.state.getProcessedItems(),r=i.findIndex(a=>this.state.getRowId(a)===e);if(r<0)return;let o=i[r],l=!n;o[t]=l;let s=this.undoRedoState?.getWrappedCallback();s&&s({item:o,columnId:t,oldValue:n,newValue:l,rowIndex:r}),this.renderingHelper.updateRendererInteractionState();}startCellEdit(e,t){if(!this.cellEditor||!this.undoRedoState)return;let{items:n}=this.state.getProcessedItems(),i=this.state.visibleColumnDefs,r=n.find(f=>this.state.getRowId(f)===e),o=i.find(f=>f.columnId===t);if(!r||!o)return;let l=this.renderer.getWrapperElement();if(!l)return;let s=l.querySelector(`tr[data-row-id="${e}"]`);if(!s)return;let a=s.querySelector(`td[data-column-id="${t}"]`);if(!a)return;let c=n.indexOf(r),d=(f,S,u)=>{if(!i.find(I=>I.columnId===S))return;let h=r[S];r[S]=u;let y=this.undoRedoState?.getWrappedCallback();y&&y({item:r,columnId:S,oldValue:h,newValue:u,rowIndex:c}),this.renderingHelper.updateRendererInteractionState();},p=()=>{this.renderingHelper.updateRendererInteractionState();},m=()=>{if(this.selectionState){let S=this.selectionState.activeCell;if(S){let{items:u}=this.state.getProcessedItems(),g=Math.min(S.rowIndex+1,u.length-1);this.selectionState.setActiveCell({rowIndex:g,columnIndex:S.columnIndex});let h=this.renderer.getColOffset(),y=S.columnIndex-h;this.selectionState.setSelectionRange({startRow:g,startCol:y,endRow:g,endCol:y});}}this.renderer.getWrapperElement()?.focus();},v;if(this.formulaEngine){let S=this.state.columns.findIndex(u=>u.columnId===t);S>=0&&this.formulaEngine.hasFormula(S,c)&&(v=this.formulaEngine.getFormula(S,c));}this.cellEditor.startEdit(e,t,r,o,a,d,p,m,v);}buildFilterConfigs(){let e=flattenColumns(this.options.columns);for(let t of e){let n=t.filterable&&typeof t.filterable=="object"?t.filterable:null;n&&n.type&&this.filterConfigs.set(t.columnId,{columnId:t.columnId,filterField:n.filterField??t.columnId,filterType:n.type});}}handleFilterIconClick(e,t){let n=this.filterConfigs.get(e);if(!n)return;if(this.headerFilterState.openColumnId===e){this.headerFilterState.close();return}let i=document.createElement("div");this.headerFilterState.setFilters(this.state.filters),this.headerFilterState.setFilterOptions(this.state.filterOptions),this.headerFilterState.open(e,n,t,i);}buildFormulaAccessor(){let{items:e}=this.state.getProcessedItems(),t=this.state.visibleColumnDefs;return {getCellValue:(n,i)=>{let r=e[i],o=t[n];if(!(!r||!o))return r[o.columnId]},getRowCount:()=>e.length,getColumnCount:()=>t.length}}handleFormulaBarCommit(){if(!this.formulaEngine||!this.selectionState)return;let e=this.selectionState.activeCell;if(!e)return;let t=0;this.rowSelectionState&&t++,(this.options.showRowNumbers||this.options.cellReferences||this.options.formulas)&&t++;let n=e.columnIndex-t,i=(this.state.page-1)*this.state.pageSize+e.rowIndex,r=this.formulaBarText,o=this.buildFormulaAccessor();if(r.startsWith("="))this.formulaEngine.setFormula(n,i,r,o);else {this.formulaEngine.hasFormula(n,i)&&this.formulaEngine.setFormula(n,i,null,o);let{items:l}=this.state.getProcessedItems(),s=this.state.visibleColumnDefs,a=l[e.rowIndex],c=s[n];a&&c&&(a[c.columnId]=r);}this.formulaBarEditing=false,this.formulaBar?.setEditing(false),this.renderingHelper.updateRendererInteractionState(),this.renderer.getWrapperElement()?.focus();}handleFormulaBarCancel(){if(this.selectionState?.activeCell&&this.formulaEngine){let e=this.selectionState.activeCell,t=0;this.rowSelectionState&&t++,(this.options.showRowNumbers||this.options.cellReferences||this.options.formulas)&&t++;let n=e.columnIndex-t,i=(this.state.page-1)*this.state.pageSize+e.rowIndex,r=this.formulaEngine.getFormula(n,i);if(r)this.formulaBarText=r,this.formulaBar?.update(formatCellReference(n,i+1),r);else {let{items:o}=this.state.getProcessedItems(),l=this.state.visibleColumnDefs,s=o[e.rowIndex],a=l[n],c=s&&a?String(s[a.columnId]??""):"";this.formulaBarText=c,this.formulaBar?.update(formatCellReference(n,i+1),c);}}this.formulaBarEditing=false,this.formulaBar?.setEditing(false),this.renderer.getWrapperElement()?.focus();}handleFormulaBarStartEditing(){this.selectionState?.activeCell&&(this.formulaBarEditing=true,this.formulaBar?.setEditing(true));}on(e,t){this.events.on(e,t);}off(e,t){this.events.off(e,t);}toggleFullScreen(){this.isFullScreen=!this.isFullScreen,this.isFullScreen?this.containerEl.classList.add("ogrid-fullscreen"):this.containerEl.classList.remove("ogrid-fullscreen"),this.fullscreenBtn&&(this.fullscreenBtn.title=this.isFullScreen?"Exit fullscreen":"Fullscreen",this.fullscreenBtn.setAttribute("aria-label",this.isFullScreen?"Exit fullscreen":"Fullscreen"),this.fullscreenBtn.innerHTML=this.isFullScreen?'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 10 0 10 0 14"/><polyline points="12 6 16 6 16 2"/><line x1="0" y1="10" x2="4" y2="6"/><line x1="16" y1="6" x2="12" y2="10"/></svg>':'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="10 2 14 2 14 6"/><polyline points="6 14 2 14 2 10"/><line x1="14" y1="2" x2="10" y2="6"/><line x1="2" y1="14" x2="6" y2="10"/></svg>');}destroy(){this.unsubscribes.forEach(e=>e()),this.renderer.destroy(),this.pagination.destroy(),this.statusBar.destroy(),this.columnChooser.destroy(),this.sideBarState?.destroy(),this.sideBarComponent?.destroy(),this.headerFilterState.destroy(),this.headerFilterComponent.destroy(),this.state.destroy(),this.selectionState?.destroy(),this.clipboardState?.destroy(),this.undoRedoState?.destroy(),this.resizeState?.destroy(),this.fillHandleState?.destroy(),this.rowSelectionState?.destroy(),this.pinningState?.destroy(),this.reorderState?.destroy(),this.virtualScrollState?.destroy(),this.marchingAnts?.destroy(),this.layoutState.destroy(),this.cellEditor?.closeEditor(),this.contextMenu?.close(),this.formulaBar?.destroy(),this.formulaEngine?.destroy(),this.events.removeAllListeners(),this.containerEl.remove();}};export{te as ClipboardState,G as ColumnChooser,Z as ColumnPinningState,re as ColumnReorderState,ie as ColumnResizeState,de as ContextMenu,x as EventEmitter,oe as FillHandleState,pe as FormulaBar,he as FormulaEngineState,N as GridState,q as HeaderFilter,X as HeaderFilterState,ae as InlineCellEditor,ee as KeyboardNavState,le as MarchingAntsOverlay,we as OGrid,ce as OGridEventWiring,ue as OGridRendering,W as PaginationControls,Y as RowSelectionState,Q as SelectionState,$ as SideBar,K as SideBarState,U as StatusBar,j as TableLayoutState,V as TableRenderer,ne as UndoRedoState,J as VirtualScrollState};
|
|
@@ -37,6 +37,8 @@ export declare class GridState<T> {
|
|
|
37
37
|
private _containerWidth;
|
|
38
38
|
private _visibleColsCache;
|
|
39
39
|
private _visibleColsDirty;
|
|
40
|
+
private _sortedIndices;
|
|
41
|
+
private _sortDirty;
|
|
40
42
|
constructor(options: OGridOptions<T>);
|
|
41
43
|
get data(): T[];
|
|
42
44
|
get page(): number;
|
|
@@ -71,6 +73,7 @@ export declare class GridState<T> {
|
|
|
71
73
|
/**
|
|
72
74
|
* Async version of getProcessedItems that offloads sort/filter to a Web Worker.
|
|
73
75
|
* Falls back to sync when worker sort is not active.
|
|
76
|
+
* Uses the same index-based snapshot approach as getProcessedItems.
|
|
74
77
|
*/
|
|
75
78
|
getProcessedItemsAsync(): Promise<{
|
|
76
79
|
items: T[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alaarab/ogrid-js",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.8",
|
|
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.7"
|
|
40
40
|
},
|
|
41
41
|
"sideEffects": [
|
|
42
42
|
"**/*.css"
|