@alaarab/ogrid-js 2.5.5 → 2.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -59
- package/dist/esm/index.js +2 -2
- package/dist/types/OGridEventWiring.d.ts +4 -4
- package/dist/types/OGridRendering.d.ts +1 -1
- package/dist/types/components/ColumnChooser.d.ts +1 -1
- package/dist/types/components/FormulaBar.d.ts +1 -1
- package/dist/types/components/InlineCellEditor.d.ts +8 -1
- package/dist/types/components/MarchingAntsOverlay.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/renderer/TableRenderer.d.ts +1 -1
- package/dist/types/state/ColumnPinningState.d.ts +1 -1
- package/dist/types/state/FormulaEngineState.d.ts +4 -4
- package/dist/types/state/GridState.d.ts +3 -0
- package/dist/types/state/TableLayoutState.d.ts +1 -1
- package/dist/types/types/columnTypes.d.ts +1 -1
- package/dist/types/types/gridTypes.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,73 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
<strong>OGrid JS</strong> — Vanilla JavaScript data grid with zero framework dependencies.
|
|
3
|
-
</p>
|
|
1
|
+
# @alaarab/ogrid-js
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
<a href="https://www.npmjs.com/package/@alaarab/ogrid-js"><img src="https://img.shields.io/npm/v/@alaarab/ogrid-js?color=%23217346&label=npm" alt="npm version" /></a>
|
|
7
|
-
<a href="https://github.com/alaarab/ogrid/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License" /></a>
|
|
8
|
-
<img src="https://img.shields.io/badge/TypeScript-strict-blue" alt="TypeScript strict" />
|
|
9
|
-
</p>
|
|
3
|
+
OGrid data grid for vanilla JavaScript - no framework required.
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
<a href="https://alaarab.github.io/ogrid/">Documentation</a> · <a href="https://alaarab.github.io/ogrid/docs/getting-started/overview">Getting Started</a> · <a href="https://alaarab.github.io/ogrid/docs/api/ogrid-props">API Reference</a>
|
|
13
|
-
</p>
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
Vanilla JS data grid for [OGrid](https://github.com/alaarab/ogrid) — full feature parity with the React packages, no framework required. Class-based state with EventEmitter replaces React hooks. Depends only on [`@alaarab/ogrid-core`](https://www.npmjs.com/package/@alaarab/ogrid-core).
|
|
18
|
-
|
|
19
|
-
## Features
|
|
5
|
+
## Install
|
|
20
6
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- Fill handle (drag-to-fill)
|
|
25
|
-
- Row selection (single/multiple, shift-click range, select all)
|
|
26
|
-
- Column resizing and pinning (left/right)
|
|
27
|
-
- Column chooser, sidebar (columns & filters panels)
|
|
28
|
-
- Header filters (text, multiSelect, date)
|
|
29
|
-
- Context menu
|
|
30
|
-
- Status bar with aggregations
|
|
31
|
-
- Marching ants copy/cut overlay
|
|
32
|
-
- Server-side data source with `fetchPage`
|
|
7
|
+
```bash
|
|
8
|
+
npm install @alaarab/ogrid-js
|
|
9
|
+
```
|
|
33
10
|
|
|
34
|
-
##
|
|
11
|
+
## Usage
|
|
35
12
|
|
|
36
13
|
```typescript
|
|
37
14
|
import { OGrid } from '@alaarab/ogrid-js';
|
|
38
15
|
|
|
39
16
|
const grid = new OGrid(document.getElementById('grid')!, {
|
|
40
17
|
columns: [
|
|
41
|
-
{ columnId: 'name',
|
|
42
|
-
{ columnId: 'age',
|
|
43
|
-
],
|
|
44
|
-
data: [
|
|
45
|
-
{ name: 'Alice', age: 30 },
|
|
46
|
-
{ name: 'Bob', age: 25 },
|
|
18
|
+
{ columnId: 'name', name: 'Name', sortable: true },
|
|
19
|
+
{ columnId: 'age', name: 'Age', type: 'numeric' },
|
|
47
20
|
],
|
|
48
|
-
|
|
49
|
-
pageSize: 10,
|
|
21
|
+
data: [{ name: 'Alice', age: 30 }],
|
|
50
22
|
});
|
|
51
|
-
|
|
52
|
-
// Access the API
|
|
53
|
-
const api = grid.getApi();
|
|
54
|
-
|
|
55
|
-
// Clean up
|
|
56
|
-
grid.destroy();
|
|
57
23
|
```
|
|
58
24
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
npm install @alaarab/ogrid-js
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
Peer dep: `@alaarab/ogrid-core`.
|
|
66
|
-
|
|
67
|
-
## Documentation
|
|
68
|
-
|
|
69
|
-
Full docs at **[alaarab.github.io/ogrid](https://alaarab.github.io/ogrid/)**.
|
|
70
|
-
|
|
71
|
-
## License
|
|
72
|
-
|
|
73
|
-
MIT — Free forever.
|
|
25
|
+
See the [OGrid docs](https://alaarab.github.io/ogrid/) for full documentation.
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {flattenColumns,resolveResponsiveConfig,deriveFilterOptionsFromData,validateColumns,validateRowIds,applyResponsiveHiding,processClientSideData,processClientSideDataAsync,mergeFilter,exportToCsv,getCellValue,ROW_NUMBER_COLUMN_WIDTH,ROW_NUMBER_COLUMN_ID,CHECKBOX_COLUMN_WIDTH,indexToColumnLetter,buildHeaderRows,partitionColumnsForVirtualization,isInSelectionRange,getPaginationViewModel,getStatusBarParts,DEFAULT_MIN_COLUMN_WIDTH,CELL_PADDING,applyRangeRowSelection,computeRowSelectionState,validateVirtualScrollConfig,computeTotalHeight,computeVisibleColumnRange,getScrollTopForRow,computeVisibleRange,rangesEqual,applyCellDeletion,computeTabNavigation,computeArrowNavigation,normalizeSelectionRange,formatSelectionAsTsv,parseTsvClipboard,applyPastedValues,applyCutClear,UndoRedoStack,ROW_NUMBER_COLUMN_MIN_WIDTH,applyFillValues,getPinStateForColumn,calculateDropTarget,reorderColumnArray,injectGlobalStyles,GRID_CONTEXT_MENU_ITEMS,formatShortcut,measureColumnContentWidth,formatCellReference,measureRange}from'@alaarab/ogrid-core';export{AUTOSIZE_EXTRA_PX,AUTOSIZE_MAX_PX,CELL_PADDING,CHECKBOX_COLUMN_WIDTH,COLUMN_HEADER_MENU_ITEMS,CellDescriptorCache,DEFAULT_DEBOUNCE_MS,DEFAULT_MIN_COLUMN_WIDTH,GRID_BORDER_RADIUS,GRID_CONTEXT_MENU_ITEMS,MAX_PAGE_BUTTONS,PAGE_SIZE_OPTIONS,PEOPLE_SEARCH_DEBOUNCE_MS,RESPONSIVE_BREAKPOINTS,ROW_NUMBER_COLUMN_ID,ROW_NUMBER_COLUMN_MIN_WIDTH,ROW_NUMBER_COLUMN_WIDTH,SIDEBAR_TRANSITION_MS,UndoRedoStack,Z_INDEX,applyCellDeletion,applyCutClear,applyFillValues,applyPastedValues,applyRangeRowSelection,applyResponsiveHiding,areGridRowPropsEqual,booleanParser,buildCellIndex,buildCsvHeader,buildCsvRows,buildHeaderRows,buildInlineEditorProps,buildPopoverEditorProps,calculateDropTarget,clampSelectionToBounds,columnLetterToIndex,computeAggregations,computeArrowNavigation,computeAutoScrollSpeed,computeNextSortState,computeRowSelectionState,computeTabNavigation,computeTotalHeight,computeVisibleColumnRange,computeVisibleRange,createGridDataAccessor,createSortFilterWorker,currencyParser,dateParser,debounce,deriveFilterOptionsFromData,emailParser,escapeCsvValue,exportToCsv,extractValueMatrix,findCtrlArrowTarget,flattenColumns,formatCellReference,formatCellValueForTsv,formatSelectionAsTsv,formatShortcut,getCellRenderDescriptor,getCellValue,getColumnHeaderMenuItems,getContextMenuHandlers,getDataGridStatusBarConfig,getFilterField,getHeaderFilterConfig,getMultiSelectFilterFields,getPaginationViewModel,getPinStateForColumn,getResponsiveHiddenColumns,getScrollTopForRow,getStatusBarParts,indexToColumnLetter,injectGlobalStyles,isColumnEditable,isFilterConfig,isInSelectionRange,isRowInRange,measureColumnContentWidth,measureRange,mergeFilter,normalizeSelectionRange,numberParser,parseTsvClipboard,parseValue,partitionColumnsForVirtualization,processClientSideData,processClientSideDataAsync,rangesEqual,reorderColumnArray,resolveCellDisplayContent,resolveCellStyle,resolveResponsiveConfig,terminateSortFilterWorker,toUserLike,triggerCsvDownload,validateColumns,validateRowIds,validateVirtualScrollConfig}from'@alaarab/ogrid-core';import {FormulaEngine,handleFormulaBarKeyDown,FORMULA_BAR_CSS}from'@alaarab/ogrid-core/formula';export{CIRC_ERROR,DIV_ZERO_ERROR,DependencyGraph,FORMULA_BAR_CSS,FORMULA_BAR_STYLES,FORMULA_REF_COLORS,FormulaEngine,FormulaError,FormulaEvaluator,GENERAL_ERROR,NAME_ERROR,NA_ERROR,REF_ERROR,VALUE_ERROR,adjustFormulaReferences,canInsertReference,createBuiltInFunctions,deriveFormulaBarText,extractFormulaReferences,flattenArgs,formatAddress,formulaToString,fromCellKey,handleFormulaBarKeyDown,insertReferenceAtCursor,isFormulaError,parse,parseCellRef,parseRange,processFormulaBarCommit,toBoolean,toCellKey,toNumber,tokenize}from'@alaarab/ogrid-core/formula';function L(R){let e=R.getAttribute("data-row-index"),t=R.getAttribute("data-col-index");if(e==null||t==null)return null;let i=parseInt(e,10),n=parseInt(t,10);return Number.isNaN(i)||Number.isNaN(n)?null:{rowIndex:i,colIndex:n}}var x=class{constructor(){this.handlers=new Map;}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e)?.add(t);}off(e,t){this.handlers.get(e)?.delete(t);}emit(e,...t){let i=t[0];this.handlers.get(e)?.forEach(n=>{n(i);});}removeAllListeners(e){e?this.handlers.delete(e):this.handlers.clear();}};var N=class{constructor(e){this.emitter=new x;this._data=[];this._filters={};this._isLoading=false;this._serverItems=[];this._serverTotalCount=0;this._fetchId=0;this._abortController=null;this._firstDataRendered=false;this._formulaEngine=null;this._filterOptions={};this._columnOrder=[];this._responsiveColumns=null;this._containerWidth=0;this._visibleColsCache=null;this._visibleColsDirty=true;this._allColumns=e.columns,this._columns=flattenColumns(e.columns),this._getRowId=e.getRowId,this._data=e.data??[],this._dataSource=e.dataSource,this._page=e.page??1,this._pageSize=e.pageSize??20,this._sort=e.sort,this._filters=e.filters??{},this._visibleColumns=e.visibleColumns??new Set(this._columns.map(t=>t.columnId)),this._columnOrder=this._columns.map(t=>t.columnId),this._onError=e.onError,this._onFirstDataRendered=e.onFirstDataRendered,this._rowHeight=e.rowHeight,this._ariaLabel=e.ariaLabel,this._stickyHeader=e.stickyHeader??true,this._fullScreen=e.fullScreen??false,this._workerSort=e.workerSort??false,this._responsiveColumns=resolveResponsiveConfig(e.responsiveColumns)??null,this._dataSource||(this._filterOptions=deriveFilterOptionsFromData(this._data,this._columns)),validateColumns(this._columns),!this._dataSource&&this._data.length>0&&(validateRowIds(this._data,this._getRowId),this._firstDataRendered=true),this._dataSource&&(this._isLoading=true,this.fetchServerData());}get data(){return this._data}get page(){return this._page}get pageSize(){return this._pageSize}get sort(){return this._sort}get filters(){return this._filters}get visibleColumns(){return this._visibleColumns}get isLoading(){return this._isLoading}get columns(){return this._columns}get allColumns(){return this._allColumns}get getRowId(){return this._getRowId}get isServerSide(){return this._dataSource!=null}get stickyHeader(){return this._stickyHeader}get fullScreen(){return this._fullScreen}get filterOptions(){return this._filterOptions}get columnOrder(){return this._columnOrder}get rowHeight(){return this._rowHeight}get ariaLabel(){return this._ariaLabel}get responsiveColumns(){return this._responsiveColumns}get visibleColumnDefs(){if(!this._visibleColsDirty&&this._visibleColsCache)return this._visibleColsCache;let e=this._columns.filter(i=>this._visibleColumns.has(i.columnId)),t=applyResponsiveHiding(e,this._containerWidth,this._responsiveColumns??void 0);if(this._columnOrder.length===0)this._visibleColsCache=t;else {let i=new Map(this._columnOrder.map((n,r)=>[n,r]));this._visibleColsCache=[...t].sort((n,r)=>{let o=i.get(n.columnId)??1/0,l=i.get(r.columnId)??1/0;return o-l});}return this._visibleColsDirty=false,this._visibleColsCache}getProcessedItems(){if(this.isServerSide)return {items:this._serverItems,totalCount:this._serverTotalCount};let e=processClientSideData(this._data,this._columns,this._filters,this._sort?.field,this._sort?.direction),t=e.length,i=(this._page-1)*this._pageSize,n=i+this._pageSize;return {items:e.slice(i,n),totalCount:t}}get useWorkerSort(){return this._workerSort===true||this._workerSort==="auto"&&this._data.length>5e3}async getProcessedItemsAsync(){if(this.isServerSide||!this.useWorkerSort)return this.getProcessedItems();let e=await processClientSideDataAsync(this._data,this._columns,this._filters,this._sort?.field,this._sort?.direction),t=e.length,i=(this._page-1)*this._pageSize,n=i+this._pageSize;return {items:e.slice(i,n),totalCount:t}}fetchServerData(){if(!this._dataSource)return;this._abortController&&this._abortController.abort();let e=++this._fetchId;this._abortController=new AbortController;let t=this._abortController;this._isLoading=true,this.emitter.emit("stateChange",{type:"loading"}),this._dataSource.fetchPage({page:this._page,pageSize:this._pageSize,sort:this._sort?{field:this._sort.field,direction:this._sort.direction}:void 0,filters:this._filters}).then(i=>{e!==this._fetchId||t.signal.aborted||(this._serverItems=i.items,this._serverTotalCount=i.totalCount,this._isLoading=false,!this._firstDataRendered&&i.items.length>0&&(this._firstDataRendered=true,validateRowIds(i.items,this._getRowId),this._onFirstDataRendered?.()),this.emitter.emit("stateChange",{type:"data"}));}).catch(i=>{e!==this._fetchId||t.signal.aborted||(this._onError?.(i),this._serverItems=[],this._serverTotalCount=0,this._isLoading=false,this.emitter.emit("stateChange",{type:"data"}));});}setData(e){this._data=e,this.isServerSide||(this._filterOptions=deriveFilterOptionsFromData(e,this._columns)),this.emitter.emit("stateChange",{type:"data"});}setPage(e){this._page=e,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"page"});}setPageSize(e){this._pageSize=e,this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"page"});}setSort(e){this._sort=e,this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"sort"});}toggleSort(e){this._sort?.field===e?this._sort=this._sort.direction==="asc"?{field:e,direction:"desc"}:void 0:this._sort={field:e,direction:"asc"},this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"sort"});}setFilter(e,t){this._filters=mergeFilter(this._filters,e,t),this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});}clearFilters(){this._filters={},this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});}setVisibleColumns(e){this._visibleColumns=e,this._visibleColsDirty=true,this.emitter.emit("stateChange",{type:"columns"});}setColumnOrder(e){this._columnOrder=e,this._visibleColsDirty=true,this.emitter.emit("stateChange",{type:"columns"});}setContainerWidth(e){this._containerWidth!==e&&(this._containerWidth=e,this._responsiveColumns&&(this._visibleColsDirty=true,this.emitter.emit("stateChange",{type:"columns"})));}setLoading(e){this._isLoading=e,this.emitter.emit("stateChange",{type:"loading"});}refreshData(){this.isServerSide&&this.fetchServerData();}onStateChange(e){return this.emitter.on("stateChange",e),()=>this.emitter.off("stateChange",e)}getApi(){return {setRowData:e=>{this.isServerSide||this.setData(e);},setLoading:e=>this.setLoading(e),getColumnState:()=>({visibleColumns:Array.from(this._visibleColumns),sort:this._sort,filters:Object.keys(this._filters).length>0?this._filters:void 0}),applyColumnState:e=>{e.visibleColumns&&(this._visibleColumns=new Set(e.visibleColumns)),e.sort!==void 0&&(this._sort=e.sort),e.filters!==void 0&&(this._filters=e.filters??{}),this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"columns"});},setFilterModel:e=>{this._filters=e,this._page=1,this.isServerSide?this.fetchServerData():this.emitter.emit("stateChange",{type:"filter"});},getSelectedRows:()=>[],setSelectedRows:()=>{},selectAll:()=>{},deselectAll:()=>{},clearFilters:()=>this.clearFilters(),clearSort:()=>this.setSort(void 0),resetGridState:()=>{this.clearFilters(),this.setSort(void 0);},getDisplayedRows:()=>this.getProcessedItems().items,refreshData:()=>this.refreshData(),scrollToRow:()=>{},getColumnOrder:()=>[...this._columnOrder],setColumnOrder:e=>this.setColumnOrder(e),exportToCsv:(e,t)=>{let{items:i}=this.getProcessedItems(),n=this.visibleColumnDefs.map(o=>({columnId:o.columnId,name:o.name})),r=this._formulaEngine?.isEnabled()?{getFormula:this._formulaEngine.getFormula.bind(this._formulaEngine),hasFormula:this._formulaEngine.hasFormula.bind(this._formulaEngine),columnIdToIndex:new Map(this.visibleColumnDefs.map((o,l)=>[o.columnId,l])),exportMode:t?.exportMode??"values"}:void 0;exportToCsv(i,n,(o,l)=>{let a=this._columns.find(d=>d.columnId===l);if(!a)return "";let s=getCellValue(o,a);return a.valueFormatter?a.valueFormatter(s,o):s!=null?String(s):""},e,r);}}}setFormulaEngine(e){this._formulaEngine=e;}destroy(){this._abortController&&(this._abortController.abort(),this._abortController=null),this.emitter.removeAllListeners();}};function P(R){return {minR:Math.min(R.startRow,R.endRow),maxR:Math.max(R.startRow,R.endRow),minC:Math.min(R.startCol,R.endCol),maxC:Math.max(R.startCol,R.endCol)}}function M(R,e,t){return e>=R.minR&&e<=R.maxR&&t>=R.minC&&t<=R.maxC}var V=class{constructor(e,t){this.table=null;this.thead=null;this.tbody=null;this.interactionState=null;this.wrapperEl=null;this.headerFilterState=null;this.filterConfigs=new Map;this.onFilterIconClick=null;this.dropIndicator=null;this.virtualScrollState=null;this._tbodyClickHandler=null;this._tbodyPointerdownHandler=null;this._tbodyDblclickHandler=null;this._tbodyContextmenuHandler=null;this._theadClickHandler=null;this._theadPointerdownHandler=null;this._theadDblclickHandler=null;this.lastActiveCell=null;this.lastSelectionRange=null;this.lastCopyRange=null;this.lastCutRange=null;this.lastEditingCell=null;this.lastColumnWidths={};this.lastHeaderSignature="";this.lastRenderedItems=null;this.formulaEngine=null;this.container=e,this.state=t;}setFormulaEngine(e){this.formulaEngine=e;}setVirtualScrollState(e){this.virtualScrollState=e;}setHeaderFilterState(e,t){this.headerFilterState=e,this.filterConfigs=t;}setOnFilterIconClick(e){this.onFilterIconClick=e;}setInteractionState(e){this.interactionState=e;}getCellFromEvent(e){let i=e.target.closest("td[data-row-index]");if(!i)return null;let n=L(i);return n?{el:i,rowIndex:n.rowIndex,colIndex:n.colIndex}:null}attachBodyDelegation(){this.tbody&&(this._tbodyClickHandler=e=>{let t=this.getCellFromEvent(e);t&&this.interactionState?.onCellClick?.({rowIndex:t.rowIndex,colIndex:t.colIndex,event:e});},this._tbodyPointerdownHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-fill-handle")||t.getAttribute("data-fill-handle")==="true"){this.interactionState?.onFillHandleMouseDown?.(e);return}let i=this.getCellFromEvent(e);i&&this.interactionState?.onCellMouseDown?.({rowIndex:i.rowIndex,colIndex:i.colIndex,event:e});},this._tbodyDblclickHandler=e=>{let t=this.getCellFromEvent(e);if(!t)return;let i=t.el.getAttribute("data-column-id")??"",{items:n}=this.state.getProcessedItems(),r=n[t.rowIndex];if(!r)return;let o=this.state.getRowId(r);this.interactionState?.onCellDoubleClick?.({rowIndex:t.rowIndex,colIndex:t.colIndex,rowId:o,columnId:i});},this._tbodyContextmenuHandler=e=>{let t=this.getCellFromEvent(e);t&&this.interactionState?.onCellContextMenu?.({rowIndex:t.rowIndex,colIndex:t.colIndex,event:e});},this.tbody.addEventListener("click",this._tbodyClickHandler,{passive:true}),this.tbody.addEventListener("pointerdown",this._tbodyPointerdownHandler),this.tbody.addEventListener("dblclick",this._tbodyDblclickHandler,{passive:true}),this.tbody.addEventListener("contextmenu",this._tbodyContextmenuHandler));}detachBodyDelegation(){this.tbody&&(this._tbodyClickHandler&&this.tbody.removeEventListener("click",this._tbodyClickHandler),this._tbodyPointerdownHandler&&this.tbody.removeEventListener("pointerdown",this._tbodyPointerdownHandler),this._tbodyDblclickHandler&&this.tbody.removeEventListener("dblclick",this._tbodyDblclickHandler),this._tbodyContextmenuHandler&&this.tbody.removeEventListener("contextmenu",this._tbodyContextmenuHandler),this._tbodyClickHandler=null,this._tbodyPointerdownHandler=null,this._tbodyDblclickHandler=null,this._tbodyContextmenuHandler=null);}attachHeaderDelegation(){this.thead&&(this._theadClickHandler=null,this._theadPointerdownHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-resize-handle")){e.stopPropagation();let i=t.getAttribute("data-column-id"),n=t.closest("th[data-column-id]"),r=i??n?.getAttribute("data-column-id");if(r){let l=t.closest("th")?.getBoundingClientRect();this.interactionState?.onResizeStart?.(r,e.clientX,l?.width??ROW_NUMBER_COLUMN_WIDTH);}return}if(!t.classList.contains("ogrid-filter-icon")&&this.interactionState?.onColumnReorderStart){let i=t.closest("th[data-column-id]");if(!i)return;let n=i.getAttribute("data-column-id");n&&this.interactionState.onColumnReorderStart(n,e);}},this._theadDblclickHandler=e=>{let t=e.target;if(t.classList.contains("ogrid-resize-handle")){e.stopPropagation();let i=t.getAttribute("data-column-id"),n=t.closest("th[data-column-id]"),r=i??n?.getAttribute("data-column-id");r&&this.interactionState?.onResizeDoubleClick?.(r);}},this._theadClickHandler&&this.thead.addEventListener("click",this._theadClickHandler),this.thead.addEventListener("pointerdown",this._theadPointerdownHandler),this.thead.addEventListener("dblclick",this._theadDblclickHandler));}detachHeaderDelegation(){this.thead&&(this._theadClickHandler&&this.thead.removeEventListener("click",this._theadClickHandler),this._theadPointerdownHandler&&this.thead.removeEventListener("pointerdown",this._theadPointerdownHandler),this._theadDblclickHandler&&this.thead.removeEventListener("dblclick",this._theadDblclickHandler),this._theadClickHandler=null,this._theadPointerdownHandler=null,this._theadDblclickHandler=null);}getWrapperElement(){return this.wrapperEl}render(){this.container.innerHTML="";let e=document.createElement("div");e.className="ogrid-wrapper",e.setAttribute("role","region"),e.setAttribute("data-ogrid-scroll-container",""),e.setAttribute("tabindex","0"),e.style.position="relative",this.state.rowHeight&&e.style.setProperty("--ogrid-row-height",`${this.state.rowHeight}px`);let t=this.state.ariaLabel??"Data grid";e.setAttribute("aria-label",t),this.wrapperEl=e,this.table=document.createElement("table"),this.table.className="ogrid-table",this.table.setAttribute("role","grid"),this.virtualScrollState&&this.table.setAttribute("data-virtual-scroll",""),this.thead=document.createElement("thead"),this.state.stickyHeader&&this.thead.classList.add("ogrid-sticky-header"),this.renderHeader(),this.attachHeaderDelegation(),this.table.appendChild(this.thead),this.tbody=document.createElement("tbody"),this.renderBody(),this.attachBodyDelegation(),this.table.appendChild(this.tbody),e.appendChild(this.table),this.dropIndicator=document.createElement("div"),this.dropIndicator.className="ogrid-drop-indicator",this.dropIndicator.style.display="none",e.appendChild(this.dropIndicator),this.container.appendChild(e),this.snapshotState();}computeHeaderSignature(){let e=this.state.visibleColumnDefs,t=this.interactionState,i=[];for(let r of e)i.push(r.columnId),i.push(r.name),i.push(t?.columnWidths[r.columnId]?.toString()??"");let n=this.state.sort;n&&i.push(`sort:${n.field}:${n.direction}`),i.push(`sel:${t?.rowSelectionMode??""}`),i.push(`allSel:${t?.allSelected??""}`),i.push(`someSel:${t?.someSelected??""}`),i.push(`rn:${t?.showRowNumbers??""}`),t?.showRowNumbers&&i.push(`rnw:${t?.columnWidths[ROW_NUMBER_COLUMN_ID]??""}`),i.push(`cl:${t?.showColumnLetters??""}`);for(let[r,o]of this.filterConfigs)this.headerFilterState?.hasActiveFilter(o)&&i.push(`flt:${r}`);return i.join("|")}snapshotState(){let e=this.interactionState;this.lastActiveCell=e?.activeCell?{...e.activeCell}:null,this.lastSelectionRange=e?.selectionRange?{...e.selectionRange}:null,this.lastCopyRange=e?.copyRange?{...e.copyRange}:null,this.lastCutRange=e?.cutRange?{...e.cutRange}:null,this.lastEditingCell=e?.editingCell?{...e.editingCell}:null,this.lastColumnWidths=e?.columnWidths?{...e.columnWidths}:{},this.lastRowSelectionMode=e?.rowSelectionMode,this.lastSelectedRowIds=e?.selectedRowIds?new Set(e.selectedRowIds):void 0,this.lastShowRowNumbers=e?.showRowNumbers,this.lastPinnedColumns=e?.pinnedColumns,this.lastAllSelected=e?.allSelected,this.lastSomeSelected=e?.someSelected,this.lastHeaderSignature=this.computeHeaderSignature();let{items:t}=this.state.getProcessedItems();this.lastRenderedItems=t;}isSelectionOnlyChange(){if(!this.lastRenderedItems)return false;let e=this.interactionState,{items:t}=this.state.getProcessedItems();if(t!==this.lastRenderedItems||this.computeHeaderSignature()!==this.lastHeaderSignature)return false;let n=e?.editingCell,r=this.lastEditingCell;if(n?.rowId!==r?.rowId||n?.columnId!==r?.columnId||e?.rowSelectionMode!==this.lastRowSelectionMode)return false;if(e?.selectedRowIds!==this.lastSelectedRowIds){let o=e?.selectedRowIds,l=this.lastSelectedRowIds;if(!(!o&&!l)){if(!o||!l||o.size!==l.size)return false;for(let a of o)if(!l.has(a))return false}}return !(e?.showRowNumbers!==this.lastShowRowNumbers||e?.pinnedColumns!==this.lastPinnedColumns)}patchSelectionClasses(){if(!this.tbody||!this.interactionState)return;let e=this.interactionState,{activeCell:t,selectionRange:i,copyRange:n,cutRange:r}=e,o=this.lastActiveCell,l=this.lastSelectionRange,a=this.lastCopyRange,s=this.lastCutRange,d=i?P(i):null,c=l?P(l):null,u=n?P(n):null,m=a?P(a):null,v=r?P(r):null,g=s?P(s):null,S=this.getColOffset(),p=this.tbody.querySelectorAll("td[data-row-index][data-col-index]");for(let f=0;f<p.length;f++){let h=p[f],I=L(h);if(!I)continue;let w=I.rowIndex,b=I.colIndex,y=b-S,A=o&&o.rowIndex===w&&o.columnIndex===b,E=t&&t.rowIndex===w&&t.columnIndex===b;A&&!E?(h.removeAttribute("data-active-cell"),h.style.outline="",h.style.zIndex=""):E&&!A&&(h.setAttribute("data-active-cell","true"),h.style.outline="2px solid var(--ogrid-accent, #0078d4)",h.style.position="relative",h.style.zIndex="var(--ogrid-z-active-cell, 2)");let T=c&&M(c,w,y),C=d&&M(d,w,y),_=C&&!E,F=T&&!(o&&o.rowIndex===w&&o.columnIndex===b);F&&!_?(h.removeAttribute("data-in-range"),h.style.backgroundColor=""):_&&!F&&(h.setAttribute("data-in-range","true"),h.style.backgroundColor="var(--ogrid-range-bg, rgba(33, 115, 70, 0.12))");let H=m&&M(m,w,y),D=u&&M(u,w,y);H&&!D?!E&&!(v&&M(v,w,y))&&(h.style.outline=""):D&&!H&&(h.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))");let be=g&&M(g,w,y),O=v&&M(v,w,y);be&&!O?!E&&!(u&&M(u,w,y))&&(h.style.outline=""):O&&!be&&(h.style.outline="1px dashed var(--ogrid-accent, #0078d4)");let we=h.querySelector(".ogrid-fill-handle"),xe=i&&e.onFillHandleMouseDown&&w===Math.max(i.startRow,i.endRow)&&y===Math.max(i.startCol,i.endCol),_e=!!we;if(_e&&!xe)we?.remove();else if(!_e&&xe){let k=document.createElement("div");k.className="ogrid-fill-handle",k.setAttribute("data-fill-handle","true"),k.style.position="absolute",k.style.right="-3px",k.style.bottom="-3px",k.style.width="6px",k.style.height="6px",k.style.backgroundColor="var(--ogrid-selection, #217346)",k.style.cursor="crosshair",k.style.zIndex="5",h.style.position=h.style.position||"relative",k.addEventListener("pointerdown",Ge=>{this.interactionState?.onFillHandleMouseDown?.(Ge);}),h.appendChild(k);}if(!C&&e.pinnedColumns){let k=h.getAttribute("data-column-id");k&&e.pinnedColumns[k]&&(h.style.backgroundColor=h.style.backgroundColor||"var(--ogrid-bg, #fff)");}}this.snapshotState();}update(){if(!this.tbody||!this.thead){this.render(),this.snapshotState();return}if(this.isSelectionOnlyChange()){this.patchSelectionClasses();return}this.computeHeaderSignature()!==this.lastHeaderSignature&&(this.thead.innerHTML="",this.renderHeader()),this.tbody.innerHTML="",this.renderBody(),this.snapshotState();}hasCheckboxColumn(){let e=this.interactionState?.rowSelectionMode;return e==="single"||e==="multiple"}hasRowNumbersColumn(){return !!this.interactionState?.showRowNumbers}getColOffset(){let e=0;return this.hasCheckboxColumn()&&e++,this.hasRowNumbersColumn()&&e++,e}applyPinningStyles(e,t,i){let n=this.interactionState;if(!n?.pinnedColumns)return;let r=n.pinnedColumns[t];r&&(e.style.position="sticky",e.style.zIndex=i?"3":"1",e.setAttribute("data-pinned",r),r==="left"&&n.leftOffsets?e.style.left=`${n.leftOffsets[t]??0}px`:r==="right"&&n.rightOffsets&&(e.style.right=`${n.rightOffsets[t]??0}px`),i||(e.style.backgroundColor=e.style.backgroundColor||"var(--ogrid-bg, #fff)"));}renderHeader(){if(!this.thead)return;this.thead.innerHTML="";let e=this.state.visibleColumnDefs,t=this.hasCheckboxColumn(),i=this.hasRowNumbersColumn();if(this.interactionState?.showColumnLetters){let r=document.createElement("tr");if(r.className="ogrid-column-letter-row",t){let o=document.createElement("th");o.className="ogrid-column-letter-cell",o.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,r.appendChild(o);}if(i){let o=document.createElement("th");o.className="ogrid-column-letter-cell";let l=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH;o.style.width=`${l}px`,r.appendChild(o);}for(let o=0;o<e.length;o++){let l=document.createElement("th");l.className="ogrid-column-letter-cell",l.textContent=indexToColumnLetter(o),r.appendChild(l);}this.thead.appendChild(r);}let n=buildHeaderRows(this.state.allColumns,this.state.visibleColumns);if(n.length>1)for(let r=0;r<n.length;r++){let o=n[r],l=r===n.length-1,a=document.createElement("tr");if(t){let s=document.createElement("th");s.className="ogrid-header-cell ogrid-checkbox-header",s.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,l&&this.appendSelectAllCheckbox(s),a.appendChild(s);}if(i){if(l){let s=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,d=document.createElement("th");d.className="ogrid-header-cell ogrid-row-number-header",d.style.width=`${s}px`,d.style.minWidth=`${s}px`,d.style.maxWidth=`${s}px`,d.style.textAlign="center",d.style.position=d.style.position||"relative",d.textContent="#";let c=document.createElement("div");c.className="ogrid-resize-handle",c.style.position="absolute",c.style.right="0",c.style.top="0",c.style.bottom="0",c.style.width="4px",c.style.cursor="col-resize",c.style.userSelect="none",c.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),d.appendChild(c),a.appendChild(d);}else if(r===0){let s=document.createElement("th");s.rowSpan=n.length-1,s.style.padding="0",a.appendChild(s);}}for(let s of o){let d=document.createElement("th");if(d.textContent=s.label,d.className=s.isGroup?"ogrid-group-header":"ogrid-header-cell",s.colSpan>1&&(d.colSpan=s.colSpan),!s.isGroup&&s.columnDef?.sortable&&(d.classList.add("ogrid-sortable"),d.addEventListener("click",()=>{s.columnDef&&this.state.toggleSort(s.columnDef.columnId);})),!s.isGroup&&s.columnDef){d.setAttribute("data-column-id",s.columnDef.columnId),d.setAttribute("scope","col");let c=this.state.sort;c?.field===s.columnDef.columnId&&d.setAttribute("aria-sort",c.direction==="asc"?"ascending":"descending"),this.applyPinningStyles(d,s.columnDef.columnId,true);}a.appendChild(d);}this.thead?.appendChild(a);}else {let r=document.createElement("tr");if(t){let o=document.createElement("th");o.className="ogrid-header-cell ogrid-checkbox-header",o.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,this.appendSelectAllCheckbox(o),r.appendChild(o);}if(this.hasRowNumbersColumn()){let o=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,l=document.createElement("th");l.className="ogrid-header-cell ogrid-row-number-header",l.style.width=`${o}px`,l.style.minWidth=`${o}px`,l.style.maxWidth=`${o}px`,l.style.textAlign="center",l.style.position=l.style.position||"relative",l.textContent="#";let a=document.createElement("div");a.className="ogrid-resize-handle",a.style.position="absolute",a.style.right="0",a.style.top="0",a.style.bottom="0",a.style.width="4px",a.style.cursor="col-resize",a.style.userSelect="none",a.setAttribute("data-column-id",ROW_NUMBER_COLUMN_ID),l.appendChild(a),r.appendChild(l);}for(let o=0;o<e.length;o++){let l=e[o],a=document.createElement("th");a.className="ogrid-header-cell",a.setAttribute("data-column-id",l.columnId),a.setAttribute("scope","col");let s=this.state.sort;s?.field===l.columnId&&a.setAttribute("aria-sort",s.direction==="asc"?"ascending":"descending");let d=document.createElement("span");d.textContent=l.name,a.appendChild(d),l.sortable&&(a.classList.add("ogrid-sortable"),a.addEventListener("click",()=>this.state.toggleSort(l.columnId))),l.type==="numeric"&&(a.style.textAlign="right"),this.interactionState?.columnWidths[l.columnId]&&(a.style.width=`${this.interactionState.columnWidths[l.columnId]}px`),this.applyPinningStyles(a,l.columnId,true);let c=document.createElement("div");c.className="ogrid-resize-handle",c.style.position="absolute",c.style.right="0",c.style.top="0",c.style.bottom="0",c.style.width="4px",c.style.cursor="col-resize",c.style.userSelect="none",a.style.position=a.style.position||"relative",a.appendChild(c);let u=this.filterConfigs.get(l.columnId);if(u&&this.onFilterIconClick){let m=document.createElement("button");m.className="ogrid-filter-icon",m.setAttribute("aria-label",`Filter ${l.name}`),m.setAttribute("aria-expanded","false"),m.setAttribute("aria-haspopup","dialog"),m.style.border="none",m.style.background="transparent",m.style.cursor="pointer",m.style.fontSize="10px",m.style.padding="0 2px",m.style.marginLeft="4px",m.style.color="var(--ogrid-fg, #242424)",m.style.opacity="0.6";let v=this.headerFilterState?.hasActiveFilter(u);m.textContent=v?"\u25BC":"\u25BD",v&&(m.style.opacity="1",m.style.color="var(--ogrid-selection, #217346)"),m.addEventListener("click",g=>{g.stopPropagation(),g.preventDefault(),this.onFilterIconClick?.(l.columnId,a);}),a.appendChild(m);}r.appendChild(a);}this.thead?.appendChild(r);}}appendSelectAllCheckbox(e){let t=this.interactionState;if(t?.rowSelectionMode!=="multiple")return;let i=document.createElement("input");i.type="checkbox",i.className="ogrid-select-all-checkbox",i.checked=t?.allSelected===true,i.indeterminate=t?.someSelected===true,i.setAttribute("aria-label","Select all rows"),i.addEventListener("change",()=>{t?.onSelectAll?.(i.checked);}),e.appendChild(i);}renderBody(){if(!this.tbody)return;let e=this.state.visibleColumnDefs,{items:t}=this.state.getProcessedItems(),i=this.hasCheckboxColumn(),n=this.hasRowNumbersColumn(),r=this.getColOffset(),o=e.length+r,l=n?(this.state.page-1)*this.state.pageSize:0;if(t.length===0&&!this.state.isLoading){let p=document.createElement("tr"),f=document.createElement("td");f.colSpan=o,f.className="ogrid-empty-state",f.textContent="No data",p.appendChild(f),this.tbody.appendChild(p);return}let a=this.virtualScrollState,s=a?.enabled===true,d=0,c=t.length-1;if(s){let p=a?.visibleRange;if(!p)return;if(d=Math.max(0,p.startIndex),c=Math.min(t.length-1,p.endIndex),p.offsetTop>0){let f=document.createElement("tr");f.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${p.offsetTop}px`,h.style.padding="0",h.style.border="none",f.appendChild(h),this.tbody.appendChild(f);}}let u=a?.columnVirtualizationEnabled===true&&a.columnRange!=null,m=e,v=null,g=0,S=0;if(u&&a){let p=partitionColumnsForVirtualization(e,a.columnRange,this.interactionState?.pinnedColumns),f=[...p.pinnedLeft,...p.virtualizedUnpinned,...p.pinnedRight];v=f.map(h=>e.indexOf(h)),m=f,g=p.leftSpacerWidth,S=p.rightSpacerWidth;}for(let p=d;p<=c;p++){let f=t[p];if(!f)continue;let h=this.state.getRowId(f),I=document.createElement("tr");I.className="ogrid-row",I.setAttribute("data-row-id",String(h));let w=this.interactionState?.selectedRowIds?.has(h)===true;if(w&&(I.setAttribute("data-row-selected","true"),I.setAttribute("aria-selected","true")),i){let b=document.createElement("td");b.className="ogrid-cell ogrid-checkbox-cell",b.style.width=`${CHECKBOX_COLUMN_WIDTH}px`,b.style.textAlign="center";let y=document.createElement("input");y.type="checkbox",y.className="ogrid-row-checkbox",y.checked=w,y.setAttribute("aria-label",`Select row ${h}`),y.addEventListener("click",A=>{A.stopPropagation(),this.interactionState?.onRowCheckboxChange?.(h,y.checked,p,A.shiftKey);}),b.appendChild(y),I.appendChild(b);}if(n){let b=this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID]??ROW_NUMBER_COLUMN_WIDTH,y=document.createElement("td");y.className="ogrid-cell ogrid-row-number-cell",y.style.width=`${b}px`,y.style.minWidth=`${b}px`,y.style.maxWidth=`${b}px`,y.style.textAlign="center",y.style.color="var(--ogrid-fg-muted, #666)",y.style.fontSize="0.9em",y.textContent=String(l+p+1),I.appendChild(y);}if(g>0){let b=document.createElement("td");b.style.width=`${g}px`,b.style.minWidth=`${g}px`,b.style.padding="0",b.style.border="none",b.setAttribute("aria-hidden","true"),I.appendChild(b);}for(let b=0;b<m.length;b++){let y=m[b],A=(v?v[b]:b)+r,E=document.createElement("td");if(E.className="ogrid-cell",E.setAttribute("data-column-id",y.columnId),E.setAttribute("data-row-index",String(p)),E.setAttribute("data-col-index",String(A)),E.setAttribute("tabindex","-1"),y.type==="numeric"&&(E.style.textAlign="right"),this.applyPinningStyles(E,y.columnId,false),this.interactionState){let{activeCell:T,selectionRange:C,copyRange:_,cutRange:F,editingCell:H}=this.interactionState;T&&T.rowIndex===p&&T.columnIndex===A&&(E.setAttribute("data-active-cell","true"),E.style.outline="2px solid var(--ogrid-accent, #0078d4)",E.style.position="relative",E.style.zIndex="var(--ogrid-z-active-cell, 2)"),C&&isInSelectionRange(C,p,b)&&(E.setAttribute("data-in-range","true"),E.style.backgroundColor="var(--ogrid-range-bg, rgba(33, 115, 70, 0.12))"),_&&isInSelectionRange(_,p,b)&&(E.style.outline="1px dashed var(--ogrid-fg-muted, rgba(0, 0, 0, 0.5))"),F&&isInSelectionRange(F,p,b)&&(E.style.outline="1px dashed var(--ogrid-accent, #0078d4)"),H&&H.rowId===h&&H.columnId===y.columnId&&(E.style.visibility="hidden");}if(y.renderCell){let T=getCellValue(f,y),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(b,p)?this.formulaEngine.getValue(b,p)??T:T;y.renderCell(E,f,C);}else {let T=getCellValue(f,y),C=this.formulaEngine?.isEnabled()&&this.formulaEngine.hasFormula(b,p)?this.formulaEngine.getValue(b,p)??T:T;if(y.type==="boolean"){let _=!!C,F=!!y.editable,H=document.createElement("input");H.type="checkbox",H.checked=_,H.disabled=!F,H.style.margin="0",H.style.cursor=F?"pointer":"default",H.style.outline="none",H.setAttribute("aria-label",_?"Checked":"Unchecked"),F&&(H.addEventListener("change",()=>{this.interactionState?.onBooleanToggle?.(h,y.columnId,_);}),H.addEventListener("click",D=>D.stopPropagation())),E.appendChild(H);}else y.valueFormatter?E.textContent=y.valueFormatter(C,f):C!=null&&(E.textContent=String(C));}if(y.cellStyle){let T=typeof y.cellStyle=="function"?y.cellStyle(f):y.cellStyle;T&&Object.assign(E.style,T);}if(this.interactionState){let{selectionRange:T}=this.interactionState;if(T&&this.interactionState.onFillHandleMouseDown&&p===Math.max(T.startRow,T.endRow)&&b===Math.max(T.startCol,T.endCol)){let C=document.createElement("div");C.className="ogrid-fill-handle",C.setAttribute("data-fill-handle","true"),C.style.position="absolute",C.style.right="-3px",C.style.bottom="-3px",C.style.width="6px",C.style.height="6px",C.style.backgroundColor="var(--ogrid-selection, #217346)",C.style.cursor="crosshair",C.style.zIndex="5",E.style.position=E.style.position||"relative",E.appendChild(C);}}I.appendChild(E);}if(S>0){let b=document.createElement("td");b.style.width=`${S}px`,b.style.minWidth=`${S}px`,b.style.padding="0",b.style.border="none",b.setAttribute("aria-hidden","true"),I.appendChild(b);}this.tbody.appendChild(I);}if(s&&a){let p=a.visibleRange;if(p.offsetBottom>0){let f=document.createElement("tr");f.className="ogrid-virtual-spacer";let h=document.createElement("td");h.colSpan=o,h.style.height=`${p.offsetBottom}px`,h.style.padding="0",h.style.border="none",f.appendChild(h),this.tbody.appendChild(f);}}}getTableElement(){return this.table}getOnResizeStart(){return this.interactionState?.onResizeStart}updateDropIndicator(e,t){if(!this.dropIndicator||!this.wrapperEl)return;if(!t||e===null){this.dropIndicator.style.display="none";return}let i=this.wrapperEl.getBoundingClientRect(),n=e-i.left+this.wrapperEl.scrollLeft;this.dropIndicator.style.display="block",this.dropIndicator.style.left=`${n}px`;}destroy(){this.detachHeaderDelegation(),this.detachBodyDelegation(),this.container.innerHTML="",this.table=null,this.thead=null,this.tbody=null,this.dropIndicator=null;}};var W=class{constructor(e,t){this.el=null;this.container=e,this.state=t;}render(e,t){this.el&&this.el.remove();let i=getPaginationViewModel(this.state.page,this.state.pageSize,e,t?{pageSizeOptions:t}:void 0);if(!i)return;this.el=document.createElement("div"),this.el.className="ogrid-pagination";let n=document.createElement("div");n.className="ogrid-pagination-size";let r=document.createElement("span");r.textContent="Rows per page: ",n.appendChild(r);let o=document.createElement("select");o.className="ogrid-page-size-select";for(let c of i.pageSizeOptions){let u=document.createElement("option");u.value=String(c),u.textContent=String(c),u.selected=c===this.state.pageSize,o.appendChild(u);}o.addEventListener("change",()=>{this.state.setPageSize(Number(o.value));}),n.appendChild(o),this.el.appendChild(n);let l=document.createElement("span");l.className="ogrid-pagination-info",l.textContent=`${i.startItem}-${i.endItem} of ${e}`,this.el.appendChild(l);let a=document.createElement("div");a.className="ogrid-pagination-nav";let s=document.createElement("button");if(s.textContent="\u25C0",s.className="ogrid-pagination-btn",s.disabled=this.state.page===1,s.addEventListener("click",()=>this.state.setPage(this.state.page-1)),a.appendChild(s),i.showStartEllipsis){let c=document.createElement("span");c.textContent="...",c.className="ogrid-pagination-ellipsis",a.appendChild(c);}for(let c of i.pageNumbers){let u=document.createElement("button");u.textContent=String(c),u.className="ogrid-pagination-btn"+(c===this.state.page?" ogrid-pagination-active":""),u.addEventListener("click",()=>this.state.setPage(c)),a.appendChild(u);}if(i.showEndEllipsis){let c=document.createElement("span");c.textContent="...",c.className="ogrid-pagination-ellipsis",a.appendChild(c);}let d=document.createElement("button");d.textContent="\u25B6",d.className="ogrid-pagination-btn",d.disabled=this.state.page===i.totalPages,d.addEventListener("click",()=>this.state.setPage(this.state.page+1)),a.appendChild(d),this.el.appendChild(a),this.container.appendChild(this.el);}destroy(){this.el?.remove(),this.el=null;}};var G=class{constructor(e){this.el=null;this.container=e;}render(e){this.el&&this.el.remove();let t=getStatusBarParts(e);if(!(t.length===0&&!e.aggregation)){this.el=document.createElement("div"),this.el.className="ogrid-status-bar";for(let i of t){let n=document.createElement("span");n.className="ogrid-status-part",n.textContent=`${i.label}: ${i.value}`,this.el.appendChild(n);}if(e.aggregation){let i=e.aggregation,n=document.createElement("span");n.className="ogrid-status-aggregation",n.textContent=`Sum: ${i.sum.toLocaleString()} | Avg: ${i.avg.toFixed(2)} | Min: ${i.min} | Max: ${i.max} | Count: ${i.count}`,this.el.appendChild(n);}this.container.appendChild(this.el);}}destroy(){this.el?.remove(),this.el=null;}};var U=class{constructor(e,t){this.el=null;this.dropdown=null;this.isOpen=false;this.initialized=false;this.container=e,this.state=t;}render(){this.initialized||(this.createDOM(),this.initialized=true),this.isOpen&&this.dropdown&&this.updateDropdownState();}createDOM(){this.el=document.createElement("div"),this.el.className="ogrid-column-chooser";let e=document.createElement("button");e.className="ogrid-column-chooser-btn",e.textContent="Columns",e.addEventListener("click",()=>this.toggle()),this.el.appendChild(e),this.container.appendChild(this.el);}updateDropdownState(){if(!this.dropdown)return;let e=this.dropdown.querySelectorAll('input[type="checkbox"]'),t=this.state.columns;e.forEach((i,n)=>{n<t.length&&(i.checked=this.state.visibleColumns.has(t[n].columnId));});}toggle(){this.isOpen?this.close():this.open();}open(){if(!this.dropdown){this.isOpen=true,this.dropdown=document.createElement("div"),this.dropdown.className="ogrid-column-chooser-dropdown";for(let e of this.state.columns){let t=document.createElement("label");t.className="ogrid-column-chooser-item";let i=document.createElement("input");i.type="checkbox",i.checked=this.state.visibleColumns.has(e.columnId),i.disabled=!!e.required,i.addEventListener("change",()=>{let n=new Set(this.state.visibleColumns);i.checked?n.add(e.columnId):n.delete(e.columnId),this.state.setVisibleColumns(n);}),t.appendChild(i),t.appendChild(document.createTextNode(" "+e.name)),this.dropdown.appendChild(t);}this.el?.appendChild(this.dropdown);}}close(){this.isOpen=false,this.dropdown?.remove(),this.dropdown=null;}destroy(){this.close(),this.el?.remove(),this.el=null,this.initialized=false;}};var ke=["columns","filters"],K=class{constructor(e){this.emitter=new x;if(this._isEnabled=e!=null&&e!==false,!this._isEnabled||e===true)this._panels=ke,this._position="right",this._activePanel=null;else {let t=e;this._panels=t.panels??ke,this._position=t.position??"right",this._activePanel=t.defaultPanel??null;}}get isEnabled(){return this._isEnabled}get panels(){return this._panels}get position(){return this._position}get activePanel(){return this._activePanel}get isOpen(){return this._activePanel!==null}setActivePanel(e){this._activePanel=e,this.emitter.emit("change");}toggle(e){this.setActivePanel(this._activePanel===e?null:e);}close(){this.setActivePanel(null);}onChange(e){return this.emitter.on("change",e),()=>this.emitter.off("change",e)}destroy(){this.emitter.removeAllListeners();}};var pe={columns:"Columns",filters:"Filters"},ot={columns:"\u2261",filters:"\u2A65"},$=class{constructor(e,t){this.el=null;this.config=null;this.container=e,this.state=t;}setConfig(e){this.config=e;}render(){if(this.el&&this.el.remove(),!this.state.isEnabled||!this.config)return;this.el=document.createElement("div"),this.el.className="ogrid-sidebar",this.el.setAttribute("role","complementary"),this.el.setAttribute("aria-label","Side bar"),this.el.style.display="flex",this.el.style.flexDirection="row",this.el.style.flexShrink="0";let e=this.state.position,t=this.createTabStrip(e),i=this.createPanel(e);e==="left"?(this.el.appendChild(t),i&&this.el.appendChild(i)):(i&&this.el.appendChild(i),this.el.appendChild(t)),this.container.appendChild(this.el);}createTabStrip(e){let t=document.createElement("div");t.style.display="flex",t.style.flexDirection="column",t.style.width="36px",t.style.background="var(--ogrid-header-bg, #f5f5f5)",t.setAttribute("role","tablist"),t.setAttribute("aria-label","Side bar tabs"),e==="right"?t.style.borderLeft="1px solid var(--ogrid-border, #e0e0e0)":t.style.borderRight="1px solid var(--ogrid-border, #e0e0e0)";for(let i of this.state.panels){let n=document.createElement("button");n.setAttribute("role","tab"),n.setAttribute("aria-selected",String(this.state.activePanel===i)),n.setAttribute("aria-label",pe[i]),n.title=pe[i],n.textContent=ot[i],n.className="ogrid-sidebar-tab",n.style.width="36px",n.style.height="36px",n.style.border="none",n.style.cursor="pointer",n.style.color="var(--ogrid-fg, #242424)",n.style.fontSize="14px",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",this.state.activePanel===i?(n.style.background="var(--ogrid-bg, #fff)",n.style.fontWeight="bold"):(n.style.background="transparent",n.style.fontWeight="normal"),n.addEventListener("click",()=>{this.state.toggle(i);}),t.appendChild(n);}return t}createPanel(e){if(!this.state.isOpen||!this.state.activePanel)return null;let t=document.createElement("div");t.setAttribute("role","tabpanel"),t.setAttribute("aria-label",pe[this.state.activePanel]),t.className="ogrid-sidebar-panel",t.style.width="240px",t.style.display="flex",t.style.flexDirection="column",t.style.overflow="hidden",t.style.background="var(--ogrid-bg, #fff)",t.style.color="var(--ogrid-fg, #242424)",e==="right"?t.style.borderLeft="1px solid var(--ogrid-border, #e0e0e0)":t.style.borderRight="1px solid var(--ogrid-border, #e0e0e0)";let i=document.createElement("div");i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.padding="8px 12px",i.style.borderBottom="1px solid var(--ogrid-border, #e0e0e0)",i.style.fontWeight="600";let n=document.createElement("span");n.textContent=pe[this.state.activePanel],i.appendChild(n);let r=document.createElement("button");r.innerHTML="×",r.setAttribute("aria-label","Close panel"),r.style.border="none",r.style.background="transparent",r.style.cursor="pointer",r.style.fontSize="16px",r.style.color="var(--ogrid-fg, #242424)",r.addEventListener("click",()=>this.state.close()),i.appendChild(r),t.appendChild(i);let o=document.createElement("div");return o.style.flex="1",o.style.overflowY="auto",o.style.padding="8px 12px",this.state.activePanel==="columns"?this.renderColumnsPanel(o):this.state.activePanel==="filters"&&this.renderFiltersPanel(o),t.appendChild(o),t}renderColumnsPanel(e){if(!this.config)return;let{columns:t,visibleColumns:i,onVisibilityChange:n,onSetVisibleColumns:r}=this.config,o=t.every(d=>i.has(d.columnId)),l=document.createElement("div");l.style.display="flex",l.style.gap="8px",l.style.marginBottom="8px";let a=document.createElement("button");a.textContent="Select All",a.disabled=o,a.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(a),a.addEventListener("click",()=>{let d=new Set(i);t.forEach(c=>d.add(c.columnId)),r(d);}),l.appendChild(a);let s=document.createElement("button");s.textContent="Clear All",s.className="ogrid-sidebar-action-btn",this.applyActionButtonStyle(s),s.addEventListener("click",()=>{let d=new Set;t.forEach(c=>{c.required&&i.has(c.columnId)&&d.add(c.columnId);}),r(d);}),l.appendChild(s),e.appendChild(l);for(let d of t){let c=document.createElement("label");c.style.display="flex",c.style.alignItems="center",c.style.gap="6px",c.style.padding="2px 0",c.style.cursor="pointer";let u=document.createElement("input");u.type="checkbox",u.checked=i.has(d.columnId),u.disabled=!!d.required,u.addEventListener("change",()=>{n(d.columnId,u.checked);});let m=document.createElement("span");m.textContent=d.name,c.appendChild(u),c.appendChild(m),e.appendChild(c);}}renderFiltersPanel(e){if(!this.config)return;let{filterableColumns:t,filters:i,onFilterChange:n,filterOptions:r}=this.config;if(t.length===0){let o=document.createElement("div");o.style.color="var(--ogrid-muted, #999)",o.style.fontStyle="italic",o.textContent="No filterable columns",e.appendChild(o);return}for(let o of t){let l=document.createElement("div");l.style.marginBottom="12px";let a=document.createElement("div");if(a.style.fontWeight="500",a.style.marginBottom="4px",a.style.fontSize="13px",a.textContent=o.name,l.appendChild(a),o.filterType==="text"){let s=document.createElement("input");s.type="text";let d=i[o.filterField];s.value=d?.type==="text"?d.value:"",s.placeholder=`Filter ${o.name}...`,s.setAttribute("aria-label",`Filter ${o.name}`),this.applyTextInputStyle(s),s.addEventListener("input",()=>{n(o.filterField,s.value?{type:"text",value:s.value}:void 0);}),l.appendChild(s);}else if(o.filterType==="date"){let s=document.createElement("div");s.style.display="flex",s.style.flexDirection="column",s.style.gap="4px";let d=i[o.filterField],c=d?.type==="date"?d.value:{},u=document.createElement("label");u.style.display="flex",u.style.alignItems="center",u.style.gap="4px",u.style.fontSize="12px",u.textContent="From: ";let m=document.createElement("input");m.type="date",m.value=c.from??"",m.setAttribute("aria-label",`${o.name} from date`),this.applyDateInputStyle(m),u.appendChild(m),s.appendChild(u);let v=document.createElement("label");v.style.display="flex",v.style.alignItems="center",v.style.gap="4px",v.style.fontSize="12px",v.textContent="To: ";let g=document.createElement("input");g.type="date",g.value=c.to??"",g.setAttribute("aria-label",`${o.name} to date`),this.applyDateInputStyle(g),v.appendChild(g),s.appendChild(v);let S=()=>{let p=m.value||void 0,f=g.value||void 0;n(o.filterField,p||f?{type:"date",value:{from:p,to:f}}:void 0);};m.addEventListener("change",S),g.addEventListener("change",S),l.appendChild(s);}else if(o.filterType==="multiSelect"){let s=r[o.filterField]??[],d=document.createElement("div");d.style.maxHeight="120px",d.style.overflowY="auto",d.setAttribute("role","group"),d.setAttribute("aria-label",`${o.name} options`);let c=i[o.filterField],u=c?.type==="multiSelect"?c.value:[];for(let m of s){let v=document.createElement("label");v.style.display="flex",v.style.alignItems="center",v.style.gap="4px",v.style.padding="1px 0",v.style.cursor="pointer",v.style.fontSize="13px";let g=document.createElement("input");g.type="checkbox",g.checked=u.includes(m),g.addEventListener("change",()=>{let p=i[o.filterField],f=p?.type==="multiSelect"?[...p.value]:[],h=g.checked?[...f,m]:f.filter(I=>I!==m);n(o.filterField,h.length>0?{type:"multiSelect",value:h}:void 0);});let S=document.createElement("span");S.textContent=m,v.appendChild(g),v.appendChild(S),d.appendChild(v);}l.appendChild(d);}e.appendChild(l);}}applyActionButtonStyle(e){e.style.flex="1",e.style.cursor="pointer",e.style.background="var(--ogrid-bg-subtle, #f3f2f1)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px",e.style.padding="4px 8px";}applyTextInputStyle(e){e.style.width="100%",e.style.boxSizing="border-box",e.style.padding="4px 6px",e.style.background="var(--ogrid-bg, #fff)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}applyDateInputStyle(e){e.style.flex="1",e.style.padding="2px 4px",e.style.background="var(--ogrid-bg, #fff)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}destroy(){this.el?.remove(),this.el=null;}};var X=class{constructor(e){this.emitter=new x;this._openColumnId=null;this._tempTextValue="";this._tempSelected=new Set;this._tempDateFrom="";this._tempDateTo="";this._searchText="";this._popoverPosition=null;this._filters={};this._filterOptions={};this._clickOutsideHandler=null;this._escapeHandler=null;this._popoverEl=null;this._headerEl=null;this._onFilterChange=e;}get openColumnId(){return this._openColumnId}get tempTextValue(){return this._tempTextValue}get tempSelected(){return this._tempSelected}get tempDateFrom(){return this._tempDateFrom}get tempDateTo(){return this._tempDateTo}get searchText(){return this._searchText}get popoverPosition(){return this._popoverPosition}setFilters(e){this._filters=e;}setFilterOptions(e){this._filterOptions=e;}setPopoverEl(e){this._popoverEl=e;}getFilterOptions(e){return this._filterOptions[e]??[]}getFilteredOptions(e){let t=this.getFilterOptions(e);if(!this._searchText)return t;let i=this._searchText.toLowerCase();return t.filter(n=>n.toLowerCase().includes(i))}hasActiveFilter(e){let t=this._filters[e.filterField];return t?t.type==="text"?t.value.trim().length>0:t.type==="multiSelect"?t.value.length>0:t.type==="date"?!!(t.value.from||t.value.to):t.type==="people"?!!t.value:false:false}open(e,t,i,n){this._openColumnId&&this.close(),this._openColumnId=e,this._headerEl=i,this._popoverEl=n;let r=this._filters[t.filterField];if(t.filterType==="text")this._tempTextValue=r?.type==="text"?r.value:"";else if(t.filterType==="multiSelect")this._tempSelected=new Set(r?.type==="multiSelect"?r.value:[]);else if(t.filterType==="date"){let l=r?.type==="date"?r.value:{};this._tempDateFrom=l.from??"",this._tempDateTo=l.to??"";}this._searchText="";let o=i.getBoundingClientRect();this._popoverPosition={top:o.bottom+4,left:o.left},this._clickOutsideHandler=l=>{let a=l.target;this._popoverEl&&!this._popoverEl.contains(a)&&this._headerEl&&!this._headerEl.contains(a)&&this.close();},this._escapeHandler=l=>{l.key==="Escape"&&(l.preventDefault(),l.stopPropagation(),this.close());},setTimeout(()=>{this._clickOutsideHandler&&document.addEventListener("mousedown",this._clickOutsideHandler,{passive:true});},0),this._escapeHandler&&document.addEventListener("keydown",this._escapeHandler,true),this.emitter.emit("change");}close(){this._openColumnId=null,this._popoverPosition=null,this._popoverEl=null,this._headerEl=null,this._clickOutsideHandler&&(document.removeEventListener("mousedown",this._clickOutsideHandler),this._clickOutsideHandler=null),this._escapeHandler&&(document.removeEventListener("keydown",this._escapeHandler,true),this._escapeHandler=null),this.emitter.emit("change");}setTempTextValue(e){this._tempTextValue=e,this.emitter.emit("change");}setSearchText(e){this._searchText=e,this.emitter.emit("change");}setTempDateFrom(e){this._tempDateFrom=e,this.emitter.emit("change");}setTempDateTo(e){this._tempDateTo=e,this.emitter.emit("change");}handleCheckboxChange(e,t){let i=new Set(this._tempSelected);t?i.add(e):i.delete(e),this._tempSelected=i,this.emitter.emit("change");}handleSelectAll(e){this._tempSelected=new Set(this.getFilterOptions(e)),this.emitter.emit("change");}handleClearSelection(){this._tempSelected=new Set,this.emitter.emit("change");}applyTextFilter(e){let t=this._tempTextValue.trim();this._onFilterChange(e,t?{type:"text",value:t}:void 0),this.close();}clearTextFilter(e){this._tempTextValue="",this._onFilterChange(e,void 0),this.close();}applyMultiSelectFilter(e){let t=Array.from(this._tempSelected);this._onFilterChange(e,t.length>0?{type:"multiSelect",value:t}:void 0),this.close();}applyDateFilter(e){let t=this._tempDateFrom||void 0,i=this._tempDateTo||void 0;this._onFilterChange(e,t||i?{type:"date",value:{from:t,to:i}}:void 0),this.close();}clearDateFilter(e){this._tempDateFrom="",this._tempDateTo="",this._onFilterChange(e,void 0),this.close();}clearFilter(e){this._onFilterChange(e,void 0),this.close();}onChange(e){return this.emitter.on("change",e),()=>this.emitter.off("change",e)}destroy(){this.close(),this.emitter.removeAllListeners();}};var q=class{constructor(e){this.popoverEl=null;this.state=e;}render(e){if(this.cleanup(),!e||!this.state.openColumnId||!this.state.popoverPosition)return;let t=this.state.popoverPosition;this.popoverEl=document.createElement("div"),this.popoverEl.className="ogrid-header-filter-popover",this.popoverEl.style.position="fixed",this.popoverEl.style.top=`${t.top}px`,this.popoverEl.style.left=`${t.left}px`,this.popoverEl.style.zIndex="9999",this.popoverEl.style.background="var(--ogrid-bg, #fff)",this.popoverEl.style.color="var(--ogrid-fg, #242424)",this.popoverEl.style.border="1px solid var(--ogrid-border, #e0e0e0)",this.popoverEl.style.borderRadius="4px",this.popoverEl.style.boxShadow="var(--ogrid-shadow, 0 2px 8px rgba(0,0,0,0.15))",this.popoverEl.style.padding="8px",this.popoverEl.style.minWidth="200px",this.popoverEl.style.maxHeight="320px",this.popoverEl.style.overflowY="auto",this.popoverEl.addEventListener("click",i=>i.stopPropagation()),this.popoverEl.addEventListener("mousedown",i=>i.stopPropagation()),e.filterType==="text"?this.renderTextFilter(e):e.filterType==="multiSelect"?this.renderMultiSelectFilter(e):e.filterType==="date"&&this.renderDateFilter(e),document.body.appendChild(this.popoverEl);}renderTextFilter(e){if(!this.popoverEl)return;let t=document.createElement("input");t.type="text",t.value=this.state.tempTextValue,t.placeholder="Filter...",t.setAttribute("aria-label","Text filter"),t.className="ogrid-filter-text-input",this.applyInputStyle(t),t.style.marginBottom="8px",t.addEventListener("input",()=>{this.state.setTempTextValue(t.value);}),t.addEventListener("keydown",o=>{o.key==="Enter"&&this.state.applyTextFilter(e.filterField),o.stopPropagation();}),this.popoverEl.appendChild(t);let i=document.createElement("div");i.style.display="flex",i.style.gap="8px";let n=document.createElement("button");n.textContent="Apply",n.className="ogrid-filter-apply-btn",this.applyButtonStyle(n),n.addEventListener("click",()=>this.state.applyTextFilter(e.filterField)),i.appendChild(n);let r=document.createElement("button");r.textContent="Clear",r.className="ogrid-filter-clear-btn",this.applyButtonStyle(r),r.addEventListener("click",()=>this.state.clearTextFilter(e.filterField)),i.appendChild(r),this.popoverEl.appendChild(i),setTimeout(()=>t.focus(),0);}renderMultiSelectFilter(e){if(!this.popoverEl)return;let t=document.createElement("input");t.type="text",t.value=this.state.searchText,t.placeholder="Search...",t.setAttribute("aria-label","Search filter options"),t.className="ogrid-filter-search-input",this.applyInputStyle(t),t.style.marginBottom="8px",t.addEventListener("input",()=>{this.state.setSearchText(t.value),this.updateCheckboxList(e,o);}),t.addEventListener("keydown",a=>a.stopPropagation()),this.popoverEl.appendChild(t);let i=document.createElement("div");i.style.display="flex",i.style.gap="8px",i.style.marginBottom="8px";let n=document.createElement("button");n.textContent="Select All",n.className="ogrid-filter-select-all-btn",this.applySmallButtonStyle(n),n.addEventListener("click",()=>{this.state.handleSelectAll(e.filterField),this.updateCheckboxList(e,o);}),i.appendChild(n);let r=document.createElement("button");r.textContent="Clear",r.className="ogrid-filter-clear-sel-btn",this.applySmallButtonStyle(r),r.addEventListener("click",()=>{this.state.handleClearSelection(),this.updateCheckboxList(e,o);}),i.appendChild(r),this.popoverEl.appendChild(i);let o=document.createElement("div");o.className="ogrid-filter-checkbox-list",o.style.maxHeight="160px",o.style.overflowY="auto",o.style.marginBottom="8px",o.setAttribute("role","group"),o.setAttribute("aria-label","Filter options"),this.updateCheckboxList(e,o),this.popoverEl.appendChild(o);let l=document.createElement("button");l.textContent="Apply",l.className="ogrid-filter-apply-btn",this.applyButtonStyle(l),l.addEventListener("click",()=>this.state.applyMultiSelectFilter(e.filterField)),this.popoverEl.appendChild(l);}updateCheckboxList(e,t){t.innerHTML="";let i=this.state.getFilteredOptions(e.filterField),n=this.state.tempSelected;for(let r of i){let o=document.createElement("label");o.style.display="flex",o.style.alignItems="center",o.style.gap="4px",o.style.padding="2px 0",o.style.cursor="pointer",o.style.fontSize="13px";let l=document.createElement("input");l.type="checkbox",l.checked=n.has(r),l.addEventListener("change",()=>{this.state.handleCheckboxChange(r,l.checked);});let a=document.createElement("span");a.textContent=r,o.appendChild(l),o.appendChild(a),t.appendChild(o);}if(i.length===0){let r=document.createElement("div");r.style.color="var(--ogrid-muted, #999)",r.style.fontStyle="italic",r.style.padding="4px 0",r.textContent="No options",t.appendChild(r);}}renderDateFilter(e){if(!this.popoverEl)return;let t=document.createElement("div");t.style.display="flex",t.style.flexDirection="column",t.style.gap="8px";let i=document.createElement("label");i.style.display="flex",i.style.alignItems="center",i.style.gap="4px",i.style.fontSize="13px",i.textContent="From: ";let n=document.createElement("input");n.type="date",n.value=this.state.tempDateFrom,n.setAttribute("aria-label","From date"),this.applyInputStyle(n),n.addEventListener("change",()=>{this.state.setTempDateFrom(n.value);}),n.addEventListener("keydown",d=>d.stopPropagation()),i.appendChild(n),t.appendChild(i);let r=document.createElement("label");r.style.display="flex",r.style.alignItems="center",r.style.gap="4px",r.style.fontSize="13px",r.textContent="To: ";let o=document.createElement("input");o.type="date",o.value=this.state.tempDateTo,o.setAttribute("aria-label","To date"),this.applyInputStyle(o),o.addEventListener("change",()=>{this.state.setTempDateTo(o.value);}),o.addEventListener("keydown",d=>d.stopPropagation()),r.appendChild(o),t.appendChild(r),this.popoverEl.appendChild(t);let l=document.createElement("div");l.style.display="flex",l.style.gap="8px",l.style.marginTop="8px";let a=document.createElement("button");a.textContent="Apply",a.className="ogrid-filter-apply-btn",this.applyButtonStyle(a),a.addEventListener("click",()=>this.state.applyDateFilter(e.filterField)),l.appendChild(a);let s=document.createElement("button");s.textContent="Clear",s.className="ogrid-filter-clear-btn",this.applyButtonStyle(s),s.addEventListener("click",()=>this.state.clearDateFilter(e.filterField)),l.appendChild(s),this.popoverEl.appendChild(l);}applyInputStyle(e){e.style.width="100%",e.style.boxSizing="border-box",e.style.padding="4px 6px",e.style.background="var(--ogrid-bg, #fff)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}applyButtonStyle(e){e.style.flex="1",e.style.cursor="pointer",e.style.padding="6px 12px",e.style.background="var(--ogrid-bg-subtle, #f3f2f1)",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}applySmallButtonStyle(e){e.style.cursor="pointer",e.style.padding="2px 8px",e.style.fontSize="12px",e.style.background="transparent",e.style.color="var(--ogrid-fg, #242424)",e.style.border="1px solid var(--ogrid-border, #e0e0e0)",e.style.borderRadius="4px";}cleanup(){this.popoverEl&&(this.popoverEl.remove(),this.popoverEl=null);}destroy(){this.cleanup();}};var j=class{constructor(){this.emitter=new x;this._containerWidth=0;this._columnSizingOverrides={};this._ro=null;}observeContainer(e){this.disconnectObserver(),typeof ResizeObserver<"u"&&(this._ro=new ResizeObserver(t=>{for(let i of t){let n=i.contentRect;this._containerWidth=n.width,this.emitter.emit("layoutChange",{type:"containerResize"});}}),this._ro.observe(e)),this._containerWidth=e.clientWidth;}disconnectObserver(){this._ro&&(this._ro.disconnect(),this._ro=null);}get containerWidth(){return this._containerWidth}get columnSizingOverrides(){return this._columnSizingOverrides}setColumnOverride(e,t){this._columnSizingOverrides[e]=t,this.emitter.emit("layoutChange",{type:"columnOverride"});}computeMinTableWidth(e,t){return (t?CHECKBOX_COLUMN_WIDTH:0)+e*(DEFAULT_MIN_COLUMN_WIDTH+CELL_PADDING)}computeDesiredTableWidth(e,t){let n=t?CHECKBOX_COLUMN_WIDTH:0;for(let r of e){let o=this._columnSizingOverrides[r.columnId];o?n+=o+CELL_PADDING:n+=(r.width??r.minWidth??DEFAULT_MIN_COLUMN_WIDTH)+CELL_PADDING;}return n}getAllColumnWidths(){return {...this._columnSizingOverrides}}cleanupOverrides(e){let t={},i=false;for(let[n,r]of Object.entries(this._columnSizingOverrides))e.has(n)?t[n]=r:i=true;i&&(this._columnSizingOverrides=t,this.emitter.emit("layoutChange",{type:"columnOverride"}));}applyInitialWidths(e){this._columnSizingOverrides={...e};}onLayoutChange(e){return this.emitter.on("layoutChange",e),()=>this.emitter.off("layoutChange",e)}destroy(){this.disconnectObserver(),this.emitter.removeAllListeners();}};var Y=class{constructor(e,t){this.emitter=new x;this._selectedRowIds=new Set;this._lastClickedRow=-1;this._rowSelection=e,this._getRowId=t;}get selectedRowIds(){return this._selectedRowIds}get rowSelection(){return this._rowSelection}updateSelection(e,t){this._selectedRowIds=e,this.emitter.emit("rowSelectionChange",{selectedRowIds:Array.from(e),selectedItems:t.filter(i=>e.has(this._getRowId(i)))});}handleRowCheckboxChange(e,t,i,n,r){if(this._rowSelection==="single"){this.updateSelection(t?new Set([e]):new Set,r),this._lastClickedRow=i;return}let o;n&&this._lastClickedRow>=0&&this._lastClickedRow!==i?o=applyRangeRowSelection(this._lastClickedRow,i,t,r,this._getRowId,this._selectedRowIds):(o=new Set(this._selectedRowIds),t?o.add(e):o.delete(e)),this._lastClickedRow=i,this.updateSelection(o,r);}handleSelectAll(e,t){e?this.updateSelection(new Set(t.map(i=>this._getRowId(i))),t):this.updateSelection(new Set,t);}isAllSelected(e){return computeRowSelectionState(this._selectedRowIds,e,this._getRowId).allSelected}isSomeSelected(e){return computeRowSelectionState(this._selectedRowIds,e,this._getRowId).someSelected}getSelectedRows(e){return e.filter(t=>this._selectedRowIds.has(this._getRowId(t)))}onRowSelectionChange(e){return this.emitter.on("rowSelectionChange",e),()=>this.emitter.off("rowSelectionChange",e)}destroy(){this.emitter.removeAllListeners();}};var Z=class{constructor(e,t){this.emitter=new x;this._pinnedColumns={};if(e&&(this._pinnedColumns={...e}),t)for(let i of t)i.pinned&&!(i.columnId in this._pinnedColumns)&&(this._pinnedColumns[i.columnId]=i.pinned);}get pinnedColumns(){return this._pinnedColumns}pinColumn(e,t){this._pinnedColumns={...this._pinnedColumns,[e]:t},this.emitter.emit("pinningChange",{pinnedColumns:this._pinnedColumns});}unpinColumn(e){let{[e]:t,...i}=this._pinnedColumns;this._pinnedColumns=i,this.emitter.emit("pinningChange",{pinnedColumns:this._pinnedColumns});}isPinned(e){return this._pinnedColumns[e]}computeLeftOffsets(e,t,i,n,r,o){let l={},a=0;n&&(a+=r),o&&(a+=ROW_NUMBER_COLUMN_WIDTH);for(let s of e)this._pinnedColumns[s.columnId]==="left"&&(l[s.columnId]=a,a+=t[s.columnId]??i);return l}computeRightOffsets(e,t,i){let n={},r=0;for(let o=e.length-1;o>=0;o--){let l=e[o];this._pinnedColumns[l.columnId]==="right"&&(n[l.columnId]=r,r+=t[l.columnId]??i);}return n}onPinningChange(e){return this.emitter.on("pinningChange",e),()=>this.emitter.off("pinningChange",e)}destroy(){this.emitter.removeAllListeners();}};var Re=36,ut=5,ht=100,J=class{constructor(e){this.emitter=new x;this._scrollTop=0;this._containerHeight=0;this._totalRows=0;this.rafId=0;this._ro=null;this._resizeRafId=0;this._cachedRange={startIndex:0,endIndex:-1,offsetTop:0,offsetBottom:0};this._scrollLeft=0;this._scrollLeftRafId=0;this._containerWidth=0;this._columnWidths=[];this._cachedColumnRange=null;this._roWidth=null;this._resizeWidthRafId=0;this._config=e??{enabled:false},validateVirtualScrollConfig(this._config);}get enabled(){let e=this._config.threshold??ht;return this._config.enabled===true&&this._totalRows>=e}get config(){return this._config}get containerHeight(){return this._containerHeight}get totalRows(){return this._totalRows}get scrollTop(){return this._scrollTop}get visibleRange(){return this._cachedRange}get totalHeight(){return computeTotalHeight(this._totalRows,this._config.rowHeight??Re)}get columnVirtualizationEnabled(){return this._config.columns===true}get columnRange(){return this._cachedColumnRange}setColumnWidths(e){this._columnWidths=e,this.recomputeColumnRange();}handleHorizontalScroll(e){this.columnVirtualizationEnabled&&(this._scrollLeftRafId&&cancelAnimationFrame(this._scrollLeftRafId),this._scrollLeftRafId=requestAnimationFrame(()=>{this._scrollLeftRafId=0,this._scrollLeft=e,this.recomputeColumnRange();}));}observeContainerWidth(e){this.disconnectWidthObserver(),typeof ResizeObserver<"u"&&(this._roWidth=new ResizeObserver(t=>{t.length!==0&&(this._containerWidth=t[0].contentRect.width,this._resizeWidthRafId&&cancelAnimationFrame(this._resizeWidthRafId),this._resizeWidthRafId=requestAnimationFrame(()=>{this._resizeWidthRafId=0,this.recomputeColumnRange();}));}),this._roWidth.observe(e)),this._containerWidth=e.clientWidth;}disconnectWidthObserver(){this._roWidth&&(this._roWidth.disconnect(),this._roWidth=null);}recomputeColumnRange(){if(!this.columnVirtualizationEnabled||this._columnWidths.length===0||this._containerWidth<=0){this._cachedColumnRange!==null&&(this._cachedColumnRange=null,this.emitter.emit("columnRangeChanged",{columnRange:null}));return}let e=this._config.columnOverscan??2,t=computeVisibleColumnRange(this._scrollLeft,this._columnWidths,this._containerWidth,e),i=this._cachedColumnRange;!i||i.startIndex!==t.startIndex||i.endIndex!==t.endIndex?(this._cachedColumnRange=t,this.emitter.emit("columnRangeChanged",{columnRange:t})):this._cachedColumnRange=t;}handleScroll(e){this.rafId&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.rafId=0,this._scrollTop=e,this.recompute();});}scrollToRow(e,t,i){let n=this._config.rowHeight??Re,r=getScrollTopForRow(e,n,this._containerHeight,i);t.scrollTop=r,this._scrollTop=r,this.recompute();}updateConfig(e){validateVirtualScrollConfig(e),this._config=e,this.recompute(),this.emitter.emit("configChanged",{config:e});}setTotalRows(e){this._totalRows=e,this.recompute();}observeContainer(e){this.disconnectObserver(),typeof ResizeObserver<"u"&&(this._ro=new ResizeObserver(t=>{t.length!==0&&(this._containerHeight=t[0].contentRect.height,this._resizeRafId&&cancelAnimationFrame(this._resizeRafId),this._resizeRafId=requestAnimationFrame(()=>{this._resizeRafId=0,this.recompute();}));}),this._ro.observe(e)),this._containerHeight=e.clientHeight;}disconnectObserver(){this._ro&&(this._ro.disconnect(),this._ro=null);}recompute(){if(!this.enabled)return;let e=this._config.rowHeight??Re,t=this._config.overscan??ut,i=computeVisibleRange(this._scrollTop,e,this._containerHeight,this._totalRows,t),n=this._cachedRange;n.startIndex!==i.startIndex||n.endIndex!==i.endIndex?(this._cachedRange=i,this.emitter.emit("rangeChanged",{visibleRange:i})):this._cachedRange=i;}onRangeChanged(e){return this.emitter.on("rangeChanged",e),()=>this.emitter.off("rangeChanged",e)}onColumnRangeChanged(e){return this.emitter.on("columnRangeChanged",e),()=>this.emitter.off("columnRangeChanged",e)}onConfigChanged(e){return this.emitter.on("configChanged",e),()=>this.emitter.off("configChanged",e)}destroy(){this.rafId&&cancelAnimationFrame(this.rafId),this._resizeRafId&&cancelAnimationFrame(this._resizeRafId),this._scrollLeftRafId&&cancelAnimationFrame(this._scrollLeftRafId),this._resizeWidthRafId&&cancelAnimationFrame(this._resizeWidthRafId),this.disconnectObserver(),this.disconnectWidthObserver(),this.emitter.removeAllListeners();}};var Q=class{constructor(){this.emitter=new x;this._activeCell=null;this._selectionRange=null;this._selectedRowIds=new Set;this._isDragging=false;this.dragStartCell=null;this.rafHandle=null;this.pendingRange=null;}get activeCell(){return this._activeCell}get dragAnchor(){return this.dragStartCell}get selectionRange(){return this._selectionRange}get selectedRowIds(){return this._selectedRowIds}get isDragging(){return this._isDragging}getDragRange(){return this.pendingRange}setActiveCell(e){this._activeCell=e,this._selectionRange=e!=null?{startRow:e.rowIndex,startCol:e.columnIndex,endRow:e.rowIndex,endCol:e.columnIndex}:null,this.emitter.emit("selectionChange",{activeCell:e,selectionRange:this._selectionRange});}setSelectionRange(e){this._selectionRange=e,this.emitter.emit("selectionChange",{activeCell:this._activeCell,selectionRange:e});}clearSelection(){this._activeCell=null,this._selectionRange=null,this.emitter.emit("selectionChange",{activeCell:null,selectionRange:null});}startDrag(e,t){this._isDragging=true,this.dragStartCell={rowIndex:e,columnIndex:t},this._activeCell={rowIndex:e,columnIndex:t},this._selectionRange={startRow:e,startCol:t,endRow:e,endCol:t};}updateDrag(e,t,i){if(!this._isDragging||!this.dragStartCell)return;let n={startRow:this.dragStartCell.rowIndex,startCol:this.dragStartCell.columnIndex,endRow:e,endCol:t};rangesEqual(this.pendingRange,n)||(this.pendingRange=n,this.rafHandle===null&&(this.rafHandle=requestAnimationFrame(()=>{this.pendingRange&&i(this.pendingRange),this.rafHandle=null;})));}endDrag(){this.rafHandle!==null&&(cancelAnimationFrame(this.rafHandle),this.rafHandle=null),this.pendingRange&&(this._selectionRange=this.pendingRange,this.pendingRange=null,this.emitter.emit("selectionChange",{activeCell:this._activeCell,selectionRange:this._selectionRange})),this._isDragging=false,this.dragStartCell=null;}setSelectedRowIds(e){this._selectedRowIds=e,this.emitter.emit("rowSelectionChange",{selectedRowIds:e});}onSelectionChange(e){return this.emitter.on("selectionChange",e),()=>this.emitter.off("selectionChange",e)}onRowSelectionChange(e){return this.emitter.on("rowSelectionChange",e),()=>this.emitter.off("rowSelectionChange",e)}destroy(){this.rafHandle!==null&&cancelAnimationFrame(this.rafHandle),this.emitter.removeAllListeners();}};var ee=class{constructor(e,t,i,n,r){this.wrapperRef=null;this.handleKeyDown=e=>{let{items:t,visibleCols:i,colOffset:n,editable:r,onCellValueChanged:o,onCopy:l,onCut:a,onPaste:s,onUndo:d,onRedo:c,onContextMenu:u,onStartEdit:m,getRowId:v,clearClipboardRanges:g,onKeyDown:S,onFillDown:p}=this.params;if(S&&(S(e),e.defaultPrevented))return;let f=this.getActiveCell(),h=this.getSelectionRange(),I=t.length-1,w=i.length-1+n;if(t.length===0)return;if(f===null){["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Tab","Enter","Home","End","PageDown","PageUp"].includes(e.key)&&(this.setActiveCell({rowIndex:0,columnIndex:n}),e.preventDefault());return}let{rowIndex:b,columnIndex:y}=f,A=y-n,E=e.shiftKey,T=(C,_)=>{if(C<0||C>=t.length||_<0||_>=i.length)return true;let F=getCellValue(t[C],i[_]);return F==null||F===""};switch(e.key){case "c":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),l?.());break;case "x":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),a?.());break;case "v":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),s?.());break;case "d":(e.ctrlKey||e.metaKey)&&r!==false&&p&&(e.preventDefault(),p());break;case "ArrowDown":case "ArrowUp":case "ArrowRight":case "ArrowLeft":{e.preventDefault();let{newRowIndex:C,newColumnIndex:_,newRange:F}=computeArrowNavigation({direction:e.key,rowIndex:b,columnIndex:y,dataColIndex:A,colOffset:n,maxRowIndex:I,maxColIndex:w,visibleColCount:i.length,isCtrl:e.ctrlKey||e.metaKey,isShift:E,selectionRange:h,isEmptyAt:T});this.setActiveCell({rowIndex:C,columnIndex:_}),this.setSelectionRange(F);break}case "Tab":{e.preventDefault();let C=computeTabNavigation(b,y,I,w,n,e.shiftKey),_=C.columnIndex-n;this.setActiveCell({rowIndex:C.rowIndex,columnIndex:C.columnIndex}),this.setSelectionRange({startRow:C.rowIndex,startCol:_,endRow:C.rowIndex,endCol:_});break}case "Home":{e.preventDefault();let C=e.ctrlKey?0:b;this.setActiveCell({rowIndex:C,columnIndex:n}),this.setSelectionRange({startRow:C,startCol:0,endRow:C,endCol:0});break}case "End":{e.preventDefault();let C=e.ctrlKey?I:b;this.setActiveCell({rowIndex:C,columnIndex:w}),this.setSelectionRange({startRow:C,startCol:i.length-1,endRow:C,endCol:i.length-1});break}case "PageDown":case "PageUp":{e.preventDefault();let C=this.wrapperRef,_=10,F=36;if(C){let O=C.querySelector("tbody tr");O&&O.offsetHeight>0&&(F=O.offsetHeight,_=Math.max(1,Math.floor(C.clientHeight/F)));}let H=e.key==="PageDown"?1:-1,D=Math.max(0,Math.min(b+H*_,I));e.shiftKey?this.setSelectionRange({startRow:h?.startRow??b,startCol:h?.startCol??A,endRow:D,endCol:h?.endCol??A}):this.setSelectionRange({startRow:D,startCol:A,endRow:D,endCol:A}),this.setActiveCell({rowIndex:D,columnIndex:y}),C&&(C.scrollTop=getScrollTopForRow(D,F,C.clientHeight,"center"));break}case "Enter":case "F2":{if(e.preventDefault(),A>=0&&A<i.length){let C=i[A],_=t[b];if(_&&C){let F=C.editable===true||typeof C.editable=="function"&&C.editable(_);r!==false&&F&&m?.(v(_),C.columnId);}}break}case "Escape":e.preventDefault(),g?.(),this.setActiveCell(null),this.setSelectionRange(null);break;case "z":(e.ctrlKey||e.metaKey)&&(e.shiftKey&&c?(e.preventDefault(),c()):!e.shiftKey&&d&&(e.preventDefault(),d()));break;case "y":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),c?.());break;case "a":(e.ctrlKey||e.metaKey)&&(e.preventDefault(),t.length>0&&i.length>0&&(this.setActiveCell({rowIndex:0,columnIndex:n}),this.setSelectionRange({startRow:0,startCol:0,endRow:t.length-1,endCol:i.length-1})));break;case "Delete":case "Backspace":{if(r===false||o==null)break;let C=h??(f!=null?{startRow:f.rowIndex,startCol:f.columnIndex-n,endRow:f.rowIndex,endCol:f.columnIndex-n}:null);if(C==null)break;e.preventDefault();let _=applyCellDeletion(C,t,i);for(let F of _)o(F);break}case "F10":if(e.shiftKey)if(e.preventDefault(),f!=null&&this.wrapperRef){let C=`[data-row-index="${f.rowIndex}"][data-col-index="${f.columnIndex}"]`,_=this.wrapperRef.querySelector(C);if(_){let F=_.getBoundingClientRect();u?.(F.left+F.width/2,F.top+F.height/2);}else u?.(100,100);}else u?.(100,100);break;}};this.params=e,this.getActiveCell=t,this.getSelectionRange=i,this.setActiveCell=n,this.setSelectionRange=r;}setWrapperRef(e){this.wrapperRef=e;}updateParams(e){this.params=e;}};var te=class{constructor(e,t,i){this.emitter=new x;this._cutRange=null;this._copyRange=null;this.internalClipboard=null;this.params=e,this.getActiveCell=t,this.getSelectionRange=i;}updateParams(e){this.params=e;}get cutRange(){return this._cutRange}get copyRange(){return this._copyRange}getEffectiveRange(){let e=this.getSelectionRange(),t=this.getActiveCell();return e??(t!=null?{startRow:t.rowIndex,startCol:t.columnIndex-this.params.colOffset,endRow:t.rowIndex,endCol:t.columnIndex-this.params.colOffset}:null)}handleCopy(){let e=this.getEffectiveRange();if(e==null)return;let t=normalizeSelectionRange(e),{items:i,visibleCols:n,formulas:r,flatColumns:o,getFormula:l,hasFormula:a,colOffset:s}=this.params,c=formatSelectionAsTsv(i,n,t,r&&o?{colOffset:s,flatColumns:o,getFormula:l,hasFormula:a}:void 0);this.internalClipboard=c,this._copyRange=t,this._cutRange=null,this.emitter.emit("rangesChange",{copyRange:this._copyRange,cutRange:null}),typeof navigator<"u"&&navigator.clipboard&&navigator.clipboard.writeText(c).catch(()=>{});}handleCut(){if(this.params.editable===false)return;let e=this.getEffectiveRange();if(e==null)return;let t=normalizeSelectionRange(e);this._cutRange=t,this._copyRange=null,this.handleCopy(),this._copyRange=null,this._cutRange=t,this.emitter.emit("rangesChange",{copyRange:null,cutRange:this._cutRange});}async handlePaste(){if(this.params.editable===false)return;let{onCellValueChanged:e}=this.params,t;try{typeof navigator<"u"&&navigator.clipboard?t=await navigator.clipboard.readText():t="";}catch{t="";}if(!t.trim()&&this.internalClipboard!=null&&(t=this.internalClipboard),!t.trim()||e==null)return;let i=this.getEffectiveRange(),n=i?i.startRow:0,r=i?i.startCol:0,{items:o,visibleCols:l,formulas:a,flatColumns:s,setFormula:d,colOffset:c}=this.params,u=a&&s?{colOffset:c,flatColumns:s,setFormula:d}:void 0,m=parseTsvClipboard(t),v=applyPastedValues(m,n,r,o,l,u);for(let g of v)e(g);if(this._cutRange){let g=applyCutClear(this._cutRange,o,l);for(let S of g)e(S);this._cutRange=null;}this._copyRange=null,this.emitter.emit("rangesChange",{copyRange:null,cutRange:null});}clearClipboardRanges(){this._copyRange=null,this._cutRange=null,this.emitter.emit("rangesChange",{copyRange:null,cutRange:null});}onRangesChange(e){return this.emitter.on("rangesChange",e),()=>this.emitter.off("rangesChange",e)}destroy(){this.emitter.removeAllListeners();}};var ie=class{constructor(e,t=100){this.onCellValueChanged=e;this.emitter=new x;this.stack=new UndoRedoStack(t),e&&(this.wrappedCallback=i=>{this.stack.record(i),this.stack.isBatching||this.emitStackChange(),e(i);});}get canUndo(){return this.stack.canUndo}get canRedo(){return this.stack.canRedo}getWrappedCallback(){return this.wrappedCallback}beginBatch(){this.stack.beginBatch();}endBatch(){this.stack.endBatch(),this.emitStackChange();}undo(){if(!this.onCellValueChanged)return;let e=this.stack.undo();if(e){this.emitStackChange();for(let t=e.length-1;t>=0;t--){let i=e[t];this.onCellValueChanged({...i,oldValue:i.newValue,newValue:i.oldValue});}}}redo(){if(!this.onCellValueChanged)return;let e=this.stack.redo();if(e){this.emitStackChange();for(let t of e)this.onCellValueChanged(t);}}emitStackChange(){this.emitter.emit("stackChange",{canUndo:this.canUndo,canRedo:this.canRedo});}onStackChange(e){return this.emitter.on("stackChange",e),()=>this.emitter.off("stackChange",e)}destroy(){this.emitter.removeAllListeners();}};var ne=class{constructor(){this.emitter=new x;this.columnWidths=new Map;this.isResizing=false;this.resizeColumnId=null;this.resizeStartX=0;this.resizeStartWidth=0;}get resizingColumnId(){return this.resizeColumnId}getColumnWidth(e){return this.columnWidths.get(e)}getAllColumnWidths(){let e={};return this.columnWidths.forEach((t,i)=>{e[i]=t;}),e}startResize(e,t,i){this.isResizing=true,this.resizeColumnId=e,this.resizeStartX=t,this.resizeStartWidth=i;}updateResize(e){if(!this.isResizing||!this.resizeColumnId)return null;let t=e-this.resizeStartX,i=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH;return Math.max(i,this.resizeStartWidth+t)}endResize(e){if(!this.isResizing||!this.resizeColumnId)return;let t=e-this.resizeStartX,i=this.resizeColumnId===ROW_NUMBER_COLUMN_ID?ROW_NUMBER_COLUMN_MIN_WIDTH:DEFAULT_MIN_COLUMN_WIDTH,n=Math.max(i,this.resizeStartWidth+t);this.columnWidths.set(this.resizeColumnId,n),this.emitter.emit("columnWidthChange",{columnId:this.resizeColumnId,widthPx:n}),this.isResizing=false,this.resizeColumnId=null;}setColumnWidth(e,t){this.columnWidths.set(e,t),this.emitter.emit("columnWidthChange",{columnId:e,widthPx:t});}onColumnWidthChange(e){return this.emitter.on("columnWidthChange",e),()=>this.emitter.off("columnWidthChange",e)}destroy(){this.emitter.removeAllListeners();}};var oe=class{constructor(e,t,i,n){this.emitter=new x;this.wrapperRef=null;this._isFillDragging=false;this.fillDragStart=null;this.fillDragEnd={endRow:0,endCol:0};this.rafHandle=0;this.liveFillRange=null;this.lastMousePos=null;this.cachedCells=null;this.params=e,this.getSelectionRange=t,this.setSelectionRange=i,this.setActiveCell=n,this.onMoveBound=this.onMouseMove.bind(this),this.onUpBound=this.onMouseUp.bind(this);}get isFillDragging(){return this._isFillDragging}get fillRange(){return this.liveFillRange}setWrapperRef(e){this.wrapperRef=e;}updateParams(e){this.params=e;}fillDown(){let e=this.getSelectionRange();if(!e||this.params.editable===false||!this.params.onCellValueChanged)return;let t=normalizeSelectionRange(e);this.applyFillValuesFromCore(t,{startRow:t.startRow,startCol:t.startCol});}startFillDrag(e){e.preventDefault(),e.stopPropagation();let t=this.getSelectionRange();t&&(this.params.editable===false||!this.params.onCellValueChanged||(this._isFillDragging=true,this.fillDragStart={startRow:t.startRow,startCol:t.startCol},this.fillDragEnd={endRow:t.startRow,endCol:t.startCol},this.liveFillRange=null,this.cachedCells=this.wrapperRef?this.wrapperRef.querySelectorAll("[data-row-index][data-col-index]"):null,window.addEventListener("pointermove",this.onMoveBound,{capture:true,passive:true}),window.addEventListener("pointerup",this.onUpBound,{capture:true,passive:true})));}onMouseMove(e){!this._isFillDragging||!this.fillDragStart||(this.lastMousePos={cx:e.clientX,cy:e.clientY},this.rafHandle&&cancelAnimationFrame(this.rafHandle),this.rafHandle=requestAnimationFrame(()=>{if(this.rafHandle=0,!this.lastMousePos)return;let t=this.resolveRange(this.lastMousePos.cx,this.lastMousePos.cy);if(!t)return;let i=this.liveFillRange;i&&i.startRow===t.startRow&&i.startCol===t.startCol&&i.endRow===t.endRow&&i.endCol===t.endCol||(this.liveFillRange=t,this.fillDragEnd={endRow:t.endRow,endCol:t.endCol},this.applyDragAttrs(t));}));}onMouseUp(){if(!this._isFillDragging||!this.fillDragStart)return;if(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true),this.rafHandle&&(cancelAnimationFrame(this.rafHandle),this.rafHandle=0),this.lastMousePos){let n=this.resolveRange(this.lastMousePos.cx,this.lastMousePos.cy);n&&(this.liveFillRange=n,this.fillDragEnd={endRow:n.endRow,endCol:n.endCol});}this.clearDragAttrs();let e=this.fillDragStart,t=this.fillDragEnd,i=normalizeSelectionRange({startRow:e.startRow,startCol:e.startCol,endRow:t.endRow,endCol:t.endCol});this.setSelectionRange(i),this.setActiveCell({rowIndex:e.startRow,columnIndex:e.startCol+this.params.colOffset}),this.applyFillValuesFromCore(i,e),this._isFillDragging=false,this.fillDragStart=null,this.liveFillRange=null,this.lastMousePos=null,this.emitter.emit("fillRangeChange",{fillRange:null});}applyFillValuesFromCore(e,t){let{items:i,visibleCols:n,onCellValueChanged:r,beginBatch:o,endBatch:l,formulaOptions:a}=this.params;if(!r)return;let s=applyFillValues(e,t.startRow,t.startCol,i,n,a);if(s.length>0){o?.();for(let d of s)r(d);l?.();}}resolveRange(e,t){if(!this.fillDragStart||!this.wrapperRef)return null;let n=document.elementFromPoint(e,t)?.closest?.("[data-row-index][data-col-index]");if(!n||!this.wrapperRef.contains(n))return null;let r=L(n);if(!r||r.colIndex<this.params.colOffset)return null;let o=r.rowIndex,l=r.colIndex-this.params.colOffset;return normalizeSelectionRange({startRow:this.fillDragStart.startRow,startCol:this.fillDragStart.startCol,endRow:o,endCol:l})}applyDragAttrs(e){let t=this.cachedCells;if(!t)return;let i=this.params.colOffset,n=Math.min(e.startRow,e.endRow),r=Math.max(e.startRow,e.endRow),o=Math.min(e.startCol,e.endCol),l=Math.max(e.startCol,e.endCol);for(let a=0;a<t.length;a++){let s=t[a],d=L(s);if(!d)continue;let c=d.rowIndex,u=d.colIndex-i;c>=n&&c<=r&&u>=o&&u<=l?s.hasAttribute("data-drag-range")||s.setAttribute("data-drag-range",""):s.hasAttribute("data-drag-range")&&s.removeAttribute("data-drag-range");}}clearDragAttrs(){let e=this.cachedCells;if(e)for(let t=0;t<e.length;t++)e[t].removeAttribute("data-drag-range");this.cachedCells=null;}onFillRangeChange(e){return this.emitter.on("fillRangeChange",e),()=>this.emitter.off("fillRangeChange",e)}destroy(){this._isFillDragging&&(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true),this.clearDragAttrs(),this._isFillDragging=false,this.fillDragStart=null,this.liveFillRange=null,this.lastMousePos=null),this.rafHandle&&(cancelAnimationFrame(this.rafHandle),this.rafHandle=0),this.emitter.removeAllListeners();}};var re=class{constructor(){this.emitter=new x;this._isDragging=false;this._draggedColumnId=null;this._dropIndicatorX=null;this._dropTargetIndex=null;this.rafId=0;this.columnOrder=[];this.draggedPinState="unpinned";this.tableElement=null;this.onMoveBound=this.handleMouseMove.bind(this),this.onUpBound=this.handleMouseUp.bind(this);}get isDragging(){return this._isDragging}get dropIndicatorX(){return this._dropIndicatorX}startDrag(e,t,i,n,r,o){if(t.preventDefault(),this._isDragging=true,this._draggedColumnId=e,this._dropIndicatorX=null,this._dropTargetIndex=null,this.tableElement=o,this.columnOrder=n.length>0?[...n]:i.map(l=>l.columnId),r){let l=[],a=[];for(let[s,d]of Object.entries(r))d==="left"?l.push(s):d==="right"&&a.push(s);this.pinnedColumns={left:l,right:a};}else this.pinnedColumns=void 0;this.draggedPinState=getPinStateForColumn(e,this.pinnedColumns),window.addEventListener("pointermove",this.onMoveBound,{capture:true,passive:true}),window.addEventListener("pointerup",this.onUpBound,{capture:true,passive:true}),this.emitter.emit("stateChange",{isDragging:true,dropIndicatorX:null});}handleMouseMove(e){if(!this._isDragging||!this._draggedColumnId||!this.tableElement)return;this.rafId&&cancelAnimationFrame(this.rafId);let t=e.clientX;this.rafId=requestAnimationFrame(()=>{if(this.rafId=0,!this._draggedColumnId||!this.tableElement)return;let i=calculateDropTarget({mouseX:t,columnOrder:this.columnOrder,draggedColumnId:this._draggedColumnId,draggedPinState:this.draggedPinState,tableElement:this.tableElement,pinnedColumns:this.pinnedColumns});if(!i)return;let n=this._dropIndicatorX,r=this._dropTargetIndex;this._dropTargetIndex=i.targetIndex,this._dropIndicatorX=i.indicatorX,(n!==i.indicatorX||r!==i.targetIndex)&&this.emitter.emit("stateChange",{isDragging:true,dropIndicatorX:i.indicatorX});});}handleMouseUp(){if(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true),this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=0),this._isDragging&&this._draggedColumnId&&this._dropTargetIndex!==null&&this._dropIndicatorX!==null){let e=reorderColumnArray(this.columnOrder,this._draggedColumnId,this._dropTargetIndex);this.emitter.emit("reorder",{columnOrder:e});}this._isDragging=false,this._draggedColumnId=null,this._dropIndicatorX=null,this._dropTargetIndex=null,this.tableElement=null,this.emitter.emit("stateChange",{isDragging:false,dropIndicatorX:null});}onStateChange(e){return this.emitter.on("stateChange",e),()=>this.emitter.off("stateChange",e)}onReorder(e){return this.emitter.on("reorder",e),()=>this.emitter.off("reorder",e)}destroy(){this._isDragging&&(window.removeEventListener("pointermove",this.onMoveBound,true),window.removeEventListener("pointerup",this.onUpBound,true)),this.rafId&&cancelAnimationFrame(this.rafId),this.emitter.removeAllListeners();}};function Ve(R,e,t){let i=measureRange(R,e,t);return i?{top:i.top+R.scrollTop,left:i.left+R.scrollLeft,width:i.width,height:i.height}:null}var le=class{constructor(e,t=0){this.selSvg=null;this.clipSvg=null;this.selectionRange=null;this.copyRange=null;this.cutRange=null;this.rafHandle=0;this.layoutVersion=0;this.container=e,this.colOffset=t,injectGlobalStyles("ogrid-marching-ants-keyframes","@keyframes ogrid-marching-ants{to{stroke-dashoffset:-8}}");let i=getComputedStyle(e).position;(i==="static"||i==="")&&(e.style.position="relative");}update(e,t,i,n){let r=n!==void 0&&n!==this.layoutVersion;r&&n!==void 0&&(this.layoutVersion=n),!(!r&&rangesEqual(this.selectionRange,e)&&rangesEqual(this.copyRange,t)&&rangesEqual(this.cutRange,i))&&(this.selectionRange=e,this.copyRange=t,this.cutRange=i,this.rafHandle&&cancelAnimationFrame(this.rafHandle),this.rafHandle=requestAnimationFrame(()=>{this.rafHandle=0,this.render();}));}render(){let e=this.copyRange??this.cutRange,t=this.selectionRange?Ve(this.container,this.selectionRange,this.colOffset):null,i=this.selectionRange!=null&&e!=null&&rangesEqual(this.selectionRange,e),n=this.selectionRange!=null&&this.selectionRange.startRow===this.selectionRange.endRow&&this.selectionRange.startCol===this.selectionRange.endCol;if(t&&!i&&!n){this.selSvg||(this.selSvg=this.createSvg(4),this.container.appendChild(this.selSvg)),this.positionSvg(this.selSvg,t);let o=this.selSvg.querySelector("rect");o&&(o.setAttribute("width",String(Math.max(0,t.width-2))),o.setAttribute("height",String(Math.max(0,t.height-2))),o.setAttribute("stroke","var(--ogrid-selection, #217346)"),o.setAttribute("stroke-width","2"),o.removeAttribute("stroke-dasharray"),o.style.animation="");}else this.removeSvg("sel");let r=e?Ve(this.container,e,this.colOffset):null;if(r){this.clipSvg||(this.clipSvg=this.createSvg(5),this.container.appendChild(this.clipSvg)),this.positionSvg(this.clipSvg,r);let o=this.clipSvg.querySelector("rect");o&&(o.setAttribute("width",String(Math.max(0,r.width-2))),o.setAttribute("height",String(Math.max(0,r.height-2))),o.setAttribute("stroke","var(--ogrid-selection, #217346)"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-dasharray","4 4"),o.style.animation="ogrid-marching-ants 0.5s linear infinite");}else this.removeSvg("clip");}createSvg(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("aria-hidden","true"),t.style.position="absolute",t.style.pointerEvents="none",t.style.zIndex=String(e),t.style.overflow="visible";let i=document.createElementNS("http://www.w3.org/2000/svg","rect");return i.setAttribute("x","1"),i.setAttribute("y","1"),i.setAttribute("fill","none"),t.appendChild(i),t}positionSvg(e,t){e.style.top=`${t.top}px`,e.style.left=`${t.left}px`,e.style.width=`${t.width}px`,e.style.height=`${t.height}px`;}removeSvg(e){e==="sel"&&this.selSvg?(this.selSvg.remove(),this.selSvg=null):e==="clip"&&this.clipSvg&&(this.clipSvg.remove(),this.clipSvg=null);}destroy(){this.rafHandle&&cancelAnimationFrame(this.rafHandle),this.removeSvg("sel"),this.removeSvg("clip");}};var fe={position:"absolute",zIndex:"1000",boxSizing:"border-box",border:"2px solid var(--ogrid-selection, #217346)",background:"var(--ogrid-bg, #fff)",color:"var(--ogrid-fg, #242424)",outline:"none",fontFamily:"inherit",fontSize:"inherit"},se=class{constructor(e){this.editor=null;this.editingCell=null;this.editingCellElement=null;this.onCommit=null;this.onCancel=null;this.onAfterCommit=null;this.scrollCleanup=null;this.container=e;}startEdit(e,t,i,n,r,o,l,a,s){this.closeEditor(),this.editingCell={rowId:e,columnId:t},this.editingCellElement=r,this.onCommit=o,this.onCancel=l,this.onAfterCommit=a??null;let d=s!==void 0?s:getCellValue(i,n),c=r.getBoundingClientRect(),u=this.container.getBoundingClientRect(),m=this.createEditor(n,i,d,r);m.style.position="absolute",m.style.left=`${c.left-u.left+this.container.scrollLeft}px`,m.style.top=`${c.top-u.top+this.container.scrollTop}px`,m.style.width=`${c.width}px`,m.style.height=`${c.height}px`,this.editor=m,this.container.appendChild(m),m.focus();let v=m.querySelector('[role="listbox"]');if(v){let S=window.innerHeight-c.bottom,p=S<200&&c.top>S;v.style.position="fixed",v.style.left=`${c.left}px`,v.style.width=`${c.width}px`,v.style.maxHeight="200px",v.style.zIndex="9999",v.style.right="auto",p?(v.style.top="auto",v.style.bottom=`${window.innerHeight-c.top}px`):v.style.top=`${c.bottom}px`;let f=m.closest("[data-ogrid-scroll-container]")??m.closest('[style*="overflow"]'),h=()=>this.closeEditor(),I=requestAnimationFrame(()=>{f&&f.addEventListener("scroll",h,{passive:true}),window.addEventListener("scroll",h,{passive:true});});this.scrollCleanup=()=>{cancelAnimationFrame(I),f&&f.removeEventListener("scroll",h),window.removeEventListener("scroll",h);};}}getEditingCell(){return this.editingCell}closeEditor(){if(this.scrollCleanup?.(),this.scrollCleanup=null,this.editingCell&&this.container.isConnected){let{rowId:e,columnId:t}=this.editingCell,i=this.container.querySelector(`tr[data-row-id="${e}"]`);if(i){let n=i.querySelector(`td[data-column-id="${t}"]`);n&&(n.style.visibility="");}}this.editingCellElement&&(this.editingCellElement.isConnected&&(this.editingCellElement.style.visibility=""),this.editingCellElement=null),this.editor&&(this.editor.remove(),this.editor=null),this.editingCell=null,this.onCommit=null,this.onCancel=null,this.onAfterCommit=null;}createEditor(e,t,i,n){let r=e.cellEditor;if(typeof r=="function"){let o={value:i,onValueChange:l=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,l);},onCommit:()=>this.closeEditor(),onCancel:()=>{this.onCancel?.(),this.closeEditor();},item:t,column:e,cell:n,cellEditorParams:e.cellEditorParams};return r(o)}return r==="checkbox"||e.type==="boolean"?this.createCheckboxEditor(i):r==="select"?this.createSelectEditor(i,e):r==="richSelect"?this.createRichSelectEditor(i,e):r==="date"||e.type==="date"?this.createDateEditor(i):this.createTextEditor(i)}createInputEditor(e,t){let i=document.createElement("input");return i.type=e,i.value=t,Object.assign(i.style,fe),i.addEventListener("keydown",n=>{if(n.key==="Enter"){n.preventDefault(),n.stopPropagation(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i.value);let r=this.onAfterCommit;this.closeEditor(),r?.();}else n.key==="Escape"?(n.preventDefault(),n.stopPropagation(),this.onCancel?.(),this.closeEditor()):(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(n.key)||(n.ctrlKey||n.metaKey)&&["c","x","v","a","z","y"].includes(n.key))&&n.stopPropagation();}),i.addEventListener("blur",()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i.value),this.closeEditor();}),setTimeout(()=>i.select(),0),i}createTextEditor(e){return this.createInputEditor("text",e!=null?String(e):"")}createCheckboxEditor(e){let t=document.createElement("input");return t.type="checkbox",t.checked=!!e,Object.assign(t.style,fe),t.style.width="20px",t.style.height="20px",t.addEventListener("change",()=>{this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,t.checked),this.closeEditor();}),t.addEventListener("keydown",i=>{i.key==="Escape"?(i.preventDefault(),i.stopPropagation(),this.onCancel?.(),this.closeEditor()):["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(i.key)&&i.stopPropagation();}),t}createDateEditor(e){let t="";if(e!=null){let i=String(e);i.match(/^\d{4}-\d{2}-\d{2}/)&&(t=i.substring(0,10));}return this.createInputEditor("date",t)}createSelectEditor(e,t){let i=t.cellEditorParams?.values??[],n=t.cellEditorParams?.formatValue,r=g=>n?n(g):g!=null?String(g):"",o=document.createElement("div");Object.assign(o.style,fe),o.style.padding="6px 10px",o.style.display="flex",o.style.alignItems="center",o.tabIndex=0;let l=document.createElement("div");l.style.display="flex",l.style.alignItems="center",l.style.justifyContent="space-between",l.style.width="100%",l.style.cursor="pointer",l.style.fontSize="13px";let a=document.createElement("span");a.textContent=r(e),l.appendChild(a);let s=document.createElement("span");s.textContent="\u25BE",s.style.marginLeft="4px",s.style.fontSize="10px",s.style.opacity="0.5",l.appendChild(s),o.appendChild(l);let d=document.createElement("div");d.setAttribute("role","listbox"),d.style.position="absolute",d.style.top="100%",d.style.left="0",d.style.right="0",d.style.maxHeight="200px",d.style.overflowY="auto",d.style.backgroundColor="var(--ogrid-bg, #fff)",d.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",d.style.zIndex="1001",d.style.boxShadow="0 4px 16px rgba(0,0,0,0.2)",d.style.textAlign="left",o.appendChild(d);let c=Math.max(i.findIndex(g=>String(g)===String(e)),0),u=()=>{d.innerHTML="";for(let g=0;g<i.length;g++){let S=i[g],p=document.createElement("div");p.setAttribute("role","option"),p.setAttribute("aria-selected",String(g===c)),p.textContent=r(S),p.style.padding="6px 8px",p.style.cursor="pointer",p.style.color="var(--ogrid-fg, #242424)",g===c&&(p.style.background="var(--ogrid-bg-hover, #e8f0fe)"),p.addEventListener("mousedown",f=>{f.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,S),this.closeEditor();}),d.appendChild(p);}},m=(g,S)=>{let p=d.children[g],f=d.children[S];p&&(p.style.background="",p.setAttribute("aria-selected","false")),f&&(f.style.background="var(--ogrid-bg-hover, #e8f0fe)",f.setAttribute("aria-selected","true"));},v=()=>{d.children[c]?.scrollIntoView({block:"nearest"});};return u(),o.addEventListener("keydown",g=>{switch(g.stopPropagation(),g.key){case "ArrowDown":{g.preventDefault();let S=c;c=Math.min(c+1,i.length-1),m(S,c),v();break}case "ArrowUp":{g.preventDefault();let S=c;c=Math.max(c-1,0),m(S,c),v();break}case "Enter":if(g.preventDefault(),g.stopPropagation(),i.length>0&&c<i.length){this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i[c]);let S=this.onAfterCommit;this.closeEditor(),S?.();}break;case "Tab":g.preventDefault(),i.length>0&&c<i.length&&(this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,i[c]),this.closeEditor());break;case "Escape":g.preventDefault(),g.stopPropagation(),this.onCancel?.(),this.closeEditor();break}}),o}createRichSelectEditor(e,t){let i=document.createElement("div");Object.assign(i.style,fe),i.style.padding="0";let n=document.createElement("input");n.type="text",n.value=e!=null?String(e):"",n.style.width="100%",n.style.border="none",n.style.outline="none",n.style.padding="4px",n.style.boxSizing="border-box",n.style.background="var(--ogrid-bg, #fff)",n.style.color="var(--ogrid-fg, rgba(0, 0, 0, 0.87))",i.appendChild(n);let r=document.createElement("div");r.style.position="absolute",r.style.top="100%",r.style.left="0",r.style.width="100%",r.style.maxHeight="200px",r.style.overflowY="auto",r.style.backgroundColor="var(--ogrid-bg, #fff)",r.style.border="1px solid var(--ogrid-border, rgba(0, 0, 0, 0.12))",r.style.zIndex="1001",r.style.textAlign="left",i.appendChild(r);let o=t.cellEditorParams?.values??[],l=t.cellEditorParams?.formatValue??(s=>String(s)),a=s=>{r.innerHTML="";let d=o.filter(c=>String(l(c)).toLowerCase().includes(s.toLowerCase()));for(let c of d){let u=document.createElement("div");u.textContent=String(l(c)),u.style.padding="4px 8px",u.style.cursor="pointer",u.addEventListener("mousedown",m=>{m.preventDefault(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,c),this.closeEditor();}),u.addEventListener("mouseenter",()=>{u.style.backgroundColor="var(--ogrid-hover-bg, rgba(0, 0, 0, 0.04))";},{passive:true}),u.addEventListener("mouseleave",()=>{u.style.backgroundColor="var(--ogrid-bg, #fff)";},{passive:true}),r.appendChild(u);}};return n.addEventListener("input",()=>{a(n.value);}),n.addEventListener("keydown",s=>{if(s.key==="Enter"){s.preventDefault(),s.stopPropagation(),this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value);let d=this.onAfterCommit;this.closeEditor(),d?.();}else s.key==="Escape"?(s.preventDefault(),s.stopPropagation(),this.onCancel?.(),this.closeEditor()):(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(s.key)||(s.ctrlKey||s.metaKey)&&["c","x","v","a","z","y"].includes(s.key))&&s.stopPropagation();}),n.addEventListener("blur",s=>{let d=s.relatedTarget;d&&this.editor?.contains(d)||(this.editingCell&&this.onCommit?.(this.editingCell.rowId,this.editingCell.columnId,n.value),this.closeEditor());}),a(""),setTimeout(()=>n.select(),0),i}destroy(){this.closeEditor();}};var Dt={position:"fixed",backgroundColor:"var(--ogrid-bg, #fff)",border:"1px solid var(--ogrid-border, #e0e0e0)",boxShadow:"var(--ogrid-shadow, 0 4px 16px rgba(0, 0, 0, 0.12))",borderRadius:"6px",zIndex:"10000",minWidth:"180px",padding:"4px 0",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"14px",color:"var(--ogrid-fg, #242424)"},Lt={padding:"6px 12px",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},Mt={height:"1px",backgroundColor:"var(--ogrid-border, #e0e0e0)",margin:"4px 0"},ae=class{constructor(){this.menu=null;this.handlers=null;}show(e,t,i,n,r,o){this.close(),this.handlers=i,this.menu=document.createElement("div"),Object.assign(this.menu.style,Dt),this.menu.style.left=`${e}px`,this.menu.style.top=`${t}px`;for(let a of GRID_CONTEXT_MENU_ITEMS){if(a.dividerBefore){let u=document.createElement("div");Object.assign(u.style,Mt),this.menu.appendChild(u);}let s=document.createElement("div");Object.assign(s.style,Lt);let d=document.createElement("span");if(d.textContent=a.label,s.appendChild(d),a.shortcut){let u=document.createElement("span");u.textContent=formatShortcut(a.shortcut),u.style.marginLeft="20px",u.style.color="var(--ogrid-muted, #666)",u.style.fontSize="12px",s.appendChild(u);}a.id==="undo"&&!n||a.id==="redo"&&!r||a.disabledWhenNoSelection&&o==null?(s.style.color="var(--ogrid-fg-muted, rgba(0, 0, 0, 0.4))",s.style.opacity="0.5",s.style.cursor="not-allowed"):(s.addEventListener("mouseenter",()=>{s.style.backgroundColor="var(--ogrid-bg-hover, #f5f5f5)";},{passive:true}),s.addEventListener("mouseleave",()=>{s.style.backgroundColor="";},{passive:true}),s.addEventListener("click",()=>{this.handleItemClick(a.id);},{passive:true})),this.menu.appendChild(s);}document.body.appendChild(this.menu);let l=a=>{this.menu&&!this.menu.contains(a.target)&&(this.close(),document.removeEventListener("mousedown",l));};setTimeout(()=>{document.addEventListener("mousedown",l,{passive:true});},0);}close(){this.menu&&(this.menu.remove(),this.menu=null),this.handlers=null;}handleItemClick(e){if(this.handlers){switch(e){case "undo":this.handlers.onUndo();break;case "redo":this.handlers.onRedo();break;case "copy":this.handlers.onCopy();break;case "cut":this.handlers.onCut();break;case "paste":this.handlers.onPaste();break;case "selectAll":this.handlers.onSelectAll();break}this.close();}}destroy(){this.close();}};var de=class{initializeInteraction(e,t,i,n,r,o,l,a){let{editable:s}=e,d=o?1:0,c=[],u=new Q,m=new ne,v=new ae,g=new se(n),S=e.onCellValueChanged,p=new ie(S),f=new te({items:[],visibleCols:[],colOffset:d,editable:s,onCellValueChanged:p.getWrappedCallback()},()=>u.activeCell??null,()=>u.selectionRange??null),h=new oe({items:[],visibleCols:[],editable:s,onCellValueChanged:p.getWrappedCallback(),colOffset:d,beginBatch:()=>p.beginBatch(),endBatch:()=>p.endBatch()},()=>u.selectionRange??null,E=>{u.setSelectionRange(E),a.updateRendererInteractionState();},E=>{u.setActiveCell(E);}),I=new ee({items:[],visibleCols:[],colOffset:d,getRowId:t.getRowId,editable:s,onCellValueChanged:p.getWrappedCallback(),onCopy:()=>f.handleCopy(),onCut:()=>f.handleCut(),onPaste:async()=>{await f.handlePaste();},onUndo:()=>p.undo(),onRedo:()=>p.redo(),onContextMenu:(E,T)=>a.showContextMenu(E,T),onStartEdit:(E,T)=>a.startCellEdit(E,T),clearClipboardRanges:()=>f.clearClipboardRanges()},()=>u.activeCell??null,()=>u.selectionRange??null,E=>u.setActiveCell(E),E=>u.setSelectionRange(E));c.push(u.onSelectionChange(()=>{a.updateRendererInteractionState();})),c.push(f.onRangesChange(()=>{a.updateRendererInteractionState();})),c.push(m.onColumnWidthChange(()=>{a.updateRendererInteractionState();}));let w=new re;c.push(w.onStateChange(({isDragging:E,dropIndicatorX:T})=>{i.updateDropIndicator(T,E);})),c.push(w.onReorder(({columnOrder:E})=>{t.setColumnOrder(E);}));let b=i.getWrapperElement(),y=null;b&&(b.addEventListener("keydown",I.handleKeyDown),I.setWrapperRef(b),h.setWrapperRef(b),y=new le(b,d));let A=this.attachGlobalHandlers(u,m,r,i,a);return c.push(...A),{selectionState:u,keyboardNavState:I,clipboardState:f,undoRedoState:p,resizeState:m,fillHandleState:h,reorderState:w,marchingAnts:y,cellEditor:g,contextMenu:v,unsubscribes:c}}attachGlobalHandlers(e,t,i,n,r){let o=[],l=false,a=c=>{if(l&&t){let u=t.updateResize(c.clientX);u!==null&&t.resizingColumnId&&(i.setColumnOverride(t.resizingColumnId,u),r.updateRendererInteractionState());}if(e?.isDragging){let u=c.target;if(u.tagName==="TD"){let m=L(u);m&&m.rowIndex>=0&&m.colIndex>=0&&e.updateDrag(m.rowIndex,m.colIndex,()=>r.updateDragAttributes());}}},s=c=>{if(l&&t){let u=t.resizingColumnId;if(t.endResize(c.clientX),u){let m=t.getColumnWidth(u);m&&i.setColumnOverride(u,m);}l=false,document.body.style.cursor="",r.updateRendererInteractionState();}e?.isDragging&&(e.endDrag(),r.clearCachedDragCells());},d=(c,u,m)=>{l=true,document.body.style.cursor="col-resize",t.startResize(c,u,m);};return document.addEventListener("pointermove",a,{passive:true}),document.addEventListener("pointerup",s,{passive:true}),o.push(()=>{document.removeEventListener("pointermove",a),document.removeEventListener("pointerup",s);}),n.setInteractionState({activeCell:null,selectionRange:null,copyRange:null,cutRange:null,editingCell:null,columnWidths:{},onResizeStart:d}),o}};var ce=class{constructor(e){this.layoutVersion=0;this.cachedDragCells=null;this.ctx=e;}incrementLayoutVersion(){this.layoutVersion++;}clearCachedDragCells(){this.cachedDragCells=null;}getLayoutVersion(){return this.layoutVersion}updateRendererInteractionState(){let{selectionState:e,clipboardState:t,resizeState:i,state:n,layoutState:r,pinningState:o,rowSelectionState:l,cellEditor:a,renderer:s,reorderState:d,marchingAnts:c,fillHandleState:u,options:m}=this.ctx;if(!e||!t||!i)return;let{items:v}=n.getProcessedItems(),g=n.visibleColumnDefs,S=r.getAllColumnWidths(),p=o?.computeLeftOffsets(g,S,120,!!l,CHECKBOX_COLUMN_WIDTH,!!m.showRowNumbers)??{},f=o?.computeRightOffsets(g,S,120)??{};s.setInteractionState({activeCell:e.activeCell,selectionRange:e.selectionRange,copyRange:t.copyRange,cutRange:t.cutRange,editingCell:a?.getEditingCell()??null,columnWidths:S,onCellClick:h=>this.ctx.handleCellClick(h.rowIndex,h.colIndex),onCellMouseDown:h=>{h.event&&this.ctx.handleCellMouseDown(h.rowIndex,h.colIndex,h.event);},onCellDoubleClick:h=>{h.rowId!=null&&h.columnId&&this.ctx.startCellEdit(h.rowId,h.columnId);},onCellContextMenu:h=>{h.event&&this.ctx.handleCellContextMenu(h.rowIndex,h.colIndex,h.event);},onResizeStart:s.getOnResizeStart(),onResizeDoubleClick:h=>{let w=g.find(A=>A.columnId===h)?.minWidth??DEFAULT_MIN_COLUMN_WIDTH,b=s.getTableElement()?.parentElement??void 0,y=measureColumnContentWidth(h,w,b);i.setColumnWidth(h,y);},onBooleanToggle:m.editable!==false?(h,I,w)=>this.ctx.toggleBooleanCell(h,I,w):void 0,onFillHandleMouseDown:m.editable!==false?h=>u?.startFillDrag(h):void 0,rowSelectionMode:l?.rowSelection??"none",selectedRowIds:l?.selectedRowIds,onRowCheckboxChange:(h,I,w,b)=>{l?.handleRowCheckboxChange(h,I,w,b,v);},onSelectAll:h=>{l?.handleSelectAll(h,v);},allSelected:l?.isAllSelected(v),someSelected:l?.isSomeSelected(v),showRowNumbers:m.showRowNumbers||m.cellReferences,showColumnLetters:!!m.cellReferences,showNameBox:!!m.cellReferences,pinnedColumns:o?.pinnedColumns,leftOffsets:p,rightOffsets:f,onColumnReorderStart:d?(h,I)=>{let w=s.getTableElement();w&&d?.startDrag(h,I,g,n.columnOrder,o?.pinnedColumns,w);}:void 0}),s.update(),c?.update(e.selectionRange,t.copyRange,t.cutRange,this.layoutVersion);}updateDragAttributes(){let e=this.ctx.renderer.getWrapperElement(),t=this.ctx.selectionState;if(!e||!t)return;let i=t.getDragRange();if(!i)return;let n=normalizeSelectionRange(i),r=t.dragAnchor;this.cachedDragCells||(this.cachedDragCells=e.querySelectorAll("td[data-row-index][data-col-index]"));let o=this.cachedDragCells;for(let l=0;l<o.length;l++){let s=o[l],d=L(s);if(!d)continue;let c=d.rowIndex,u=d.colIndex;isInSelectionRange(n,c,u)?(s.setAttribute("data-drag-range","true"),r&&c===r.rowIndex&&u===r.columnIndex?s.setAttribute("data-drag-anchor",""):s.removeAttribute("data-drag-anchor"),s.classList.add("ogrid-drag-target")):(s.removeAttribute("data-drag-range"),s.removeAttribute("data-drag-anchor"),s.classList.remove("ogrid-drag-target"));}}renderAll(){this.layoutVersion++;let{state:e,options:t,headerFilterState:i,rowSelectionState:n,keyboardNavState:r,clipboardState:o,undoRedoState:l,fillHandleState:a,virtualScrollState:s,pagination:d,statusBar:c,columnChooser:u,renderer:m}=this.ctx,v=n?1:0;i.setFilters(e.filters),i.setFilterOptions(e.filterOptions);let{items:g,totalCount:S}=e.getProcessedItems();if(r&&o){let p=e.visibleColumnDefs;r.updateParams({items:g,visibleCols:p,colOffset:v,getRowId:e.getRowId,editable:t.editable,onCellValueChanged:l?.getWrappedCallback(),onCopy:()=>o?.handleCopy(),onCut:()=>o?.handleCut(),onPaste:async()=>{await o?.handlePaste();},onUndo:()=>l?.undo(),onRedo:()=>l?.redo(),onContextMenu:(f,h)=>this.ctx.showContextMenu(f,h),onStartEdit:(f,h)=>this.ctx.startCellEdit(f,h),clearClipboardRanges:()=>o?.clearClipboardRanges(),onKeyDown:t.onKeyDown,onFillDown:a?()=>a.fillDown():void 0}),o.updateParams({items:g,visibleCols:p,colOffset:v,editable:t.editable,onCellValueChanged:l?.getWrappedCallback()}),a?.updateParams({items:g,visibleCols:p,editable:t.editable,onCellValueChanged:l?.getWrappedCallback(),colOffset:v,beginBatch:()=>l?.beginBatch(),endBatch:()=>l?.endBatch()}),this.updateRendererInteractionState();}else m.update();s?.setTotalRows(S),d.render(S,t.pageSizeOptions),c.render({totalCount:S}),u.render(),this.renderSideBar(),this.renderLoadingOverlay();}renderHeaderFilterPopover(){let{headerFilterState:e,headerFilterComponent:t,filterConfigs:i}=this.ctx,n=e.openColumnId,r=this.ctx.tableContainer.querySelectorAll(".ogrid-filter-icon[aria-haspopup]");for(let a of r){let s=a.closest("th[data-column-id]")?.getAttribute("data-column-id");a.setAttribute("aria-expanded",s===n?"true":"false");}if(!n){t.cleanup();return}let o=i.get(n);if(!o)return;t.render(o);let l=document.querySelector(".ogrid-header-filter-popover");e.setPopoverEl(l);}renderSideBar(){let{sideBarComponent:e,sideBarState:t,state:i}=this.ctx;if(!e||!t)return;let n=i.columns.map(o=>({columnId:o.columnId,name:o.name,required:o.required===true})),r=i.columns.filter(o=>o.filterable&&typeof o.filterable=="object"&&o.filterable.type).map(o=>({columnId:o.columnId,name:o.name,filterField:o.filterable.filterField??o.columnId,filterType:o.filterable.type}));e.setConfig({columns:n,visibleColumns:i.visibleColumns,onVisibilityChange:(o,l)=>{let a=new Set(i.visibleColumns);l?a.add(o):a.delete(o),i.setVisibleColumns(a);},onSetVisibleColumns:o=>i.setVisibleColumns(o),filterableColumns:r,filters:i.filters,onFilterChange:(o,l)=>i.setFilter(o,l),filterOptions:i.filterOptions}),e.render();}renderLoadingOverlay(){let{state:e,tableContainer:t}=this.ctx;if(e.isLoading){let{items:i}=e.getProcessedItems();t.style.minHeight=!i||i.length===0?"200px":"";let n=this.ctx.loadingOverlay;if(!n){n=document.createElement("div"),n.className="ogrid-loading-overlay",n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.right="0",n.style.bottom="0",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",n.style.background="var(--ogrid-loading-overlay, rgba(255, 255, 255, 0.7))",n.style.zIndex="100";let r=document.createElement("div");r.className="ogrid-loading-spinner",r.textContent="Loading...",n.appendChild(r),this.ctx.setLoadingOverlay(n);}t.contains(n)||t.appendChild(n);}else {t.style.minHeight="";let i=this.ctx.loadingOverlay;i&&t.contains(i)&&i.remove();}}};var ue=class{constructor(e){this.emitter=new x;this.engine=null;if(this.options=e,e.formulas&&(this.engine=new FormulaEngine({customFunctions:e.formulaFunctions,namedRanges:e.namedRanges}),e.sheets))for(let[t,i]of Object.entries(e.sheets))this.engine.registerSheet(t,i);}initialize(e){if(!this.engine||!this.options.initialFormulas?.length)return;let t=this.engine.loadFormulas(this.options.initialFormulas,e);t.updatedCells.length>0&&this.emitRecalc(t);}setFormula(e,t,i,n){if(!this.engine)return;let r=this.engine.setFormula(e,t,i,n);return r.updatedCells.length>0&&this.emitRecalc(r),r}onCellChanged(e,t,i){if(!this.engine)return;let n=this.engine.onCellChanged(e,t,i);return n.updatedCells.length>0&&this.emitRecalc(n),n}getValue(e,t){return this.engine?.getValue(e,t)}hasFormula(e,t){return this.engine?.hasFormula(e,t)??false}getFormula(e,t){return this.engine?.getFormula(e,t)}isEnabled(){return this.engine!==null}defineNamedRange(e,t){this.engine?.defineNamedRange(e,t);}removeNamedRange(e){this.engine?.removeNamedRange(e);}registerSheet(e,t){this.engine?.registerSheet(e,t);}unregisterSheet(e){this.engine?.unregisterSheet(e);}getPrecedents(e,t){return this.engine?.getPrecedents(e,t)??[]}getDependents(e,t){return this.engine?.getDependents(e,t)??[]}getAuditTrail(e,t){return this.engine?.getAuditTrail(e,t)??null}onFormulaRecalc(e){return this.emitter.on("formulaRecalc",e),()=>this.emitter.off("formulaRecalc",e)}destroy(){this.engine=null,this.emitter.removeAllListeners();}emitRecalc(e){this.options.onFormulaRecalc?.(e),this.emitter.emit("formulaRecalc",e);}};var he=class{constructor(e){this.el=null;this.nameBoxEl=null;this.inputEl=null;this.isEditing=false;this.handleKeyDown=e=>{handleFormulaBarKeyDown(e.key,()=>e.preventDefault(),this.callbacks.onCommit,this.callbacks.onCancel);};this.handleInput=()=>{this.inputEl&&this.callbacks.onInputChange(this.inputEl.value);};this.handleClick=()=>{this.isEditing||this.callbacks.onStartEditing();};this.callbacks=e;}mount(e){if(this.el)return;this.el=document.createElement("div"),this.el.className="ogrid-formula-bar",this.el.setAttribute("role","toolbar"),this.el.setAttribute("aria-label","Formula bar"),this.el.style.cssText=FORMULA_BAR_CSS.bar,this.nameBoxEl=document.createElement("div"),this.nameBoxEl.className="ogrid-formula-bar-name",this.nameBoxEl.setAttribute("aria-label","Active cell reference"),this.nameBoxEl.style.cssText=FORMULA_BAR_CSS.nameBox,this.nameBoxEl.textContent="\u2014",this.el.appendChild(this.nameBoxEl);let t=document.createElement("div");t.className="ogrid-formula-bar-fx",t.setAttribute("aria-hidden","true"),t.style.cssText=FORMULA_BAR_CSS.fxLabel,t.textContent="fx",this.el.appendChild(t),this.inputEl=document.createElement("input"),this.inputEl.type="text",this.inputEl.className="ogrid-formula-bar-input",this.inputEl.setAttribute("aria-label","Formula input"),this.inputEl.spellcheck=false,this.inputEl.autocomplete="off",this.inputEl.readOnly=true,this.inputEl.style.cssText=FORMULA_BAR_CSS.input,this.inputEl.addEventListener("keydown",this.handleKeyDown),this.inputEl.addEventListener("input",this.handleInput),this.inputEl.addEventListener("click",this.handleClick),this.inputEl.addEventListener("dblclick",this.handleClick),this.el.appendChild(this.inputEl),e.appendChild(this.el);}update(e,t){this.nameBoxEl&&(this.nameBoxEl.textContent=e??"\u2014"),this.inputEl&&(this.inputEl.value=t);}setEditing(e){this.isEditing=e,this.inputEl&&(this.inputEl.readOnly=!e,e&&this.inputEl.focus());}destroy(){this.inputEl&&(this.inputEl.removeEventListener("keydown",this.handleKeyDown),this.inputEl.removeEventListener("input",this.handleInput),this.inputEl.removeEventListener("click",this.handleClick),this.inputEl.removeEventListener("dblclick",this.handleClick)),this.el?.remove(),this.el=null,this.nameBoxEl=null,this.inputEl=null;}};var Ut=`
|
|
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,areFillCompatible,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`),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"},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 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,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: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 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),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 Xt=`
|
|
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
|
-
`,Ie=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 de,t.formulas&&(this.formulaEngine=new ue({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",Ut),this.containerEl=document.createElement("div"),this.containerEl.className="ogrid-container",this.toolbarEl=document.createElement("div"),this.toolbarEl.className="ogrid-toolbar";let i=document.createElement("div");if(this.toolbarEl.appendChild(i),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",i.appendChild(this.nameBoxEl)),t.fullScreen){let n=document.createElement("div");n.style.display="flex",n.style.alignItems="center",n.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()),n.appendChild(this.fullscreenBtn),this.toolbarEl.appendChild(n);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 he({onCommit:()=>this.handleFormulaBarCommit(),onCancel:()=>this.handleFormulaBarCancel(),onInputChange:n=>{this.formulaBarText=n;},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 G(this.statusBarContainer),this.columnChooser=new U(this.toolbarEl,this.state),this.headerFilterState=new X((n,r)=>{this.state.setFilter(n,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 n=flattenColumns(t.columns);if(this.pinningState=new Z(t.pinnedColumns,n),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,a)=>this.showContextMenu(l,a),startCellEdit:(l,a)=>this.startCellEdit(l,a)});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,a=this.selectionState,s=0;this.rowSelectionState&&s++,(t.showRowNumbers||t.cellReferences)&&s++,this.unsubscribes.push(a.onSelectionChange(({activeCell:d})=>{if(d){let c=d.columnIndex-s,u=(this.state.page-1)*this.state.pageSize+d.rowIndex+1;l.textContent=formatCellReference(c,u);}else l.textContent="\u2014";}));}if(this.formulaBar&&this.selectionState&&this.formulaEngine){let l=this.formulaBar,a=this.selectionState,s=this.formulaEngine,d=0;this.rowSelectionState&&d++,(t.showRowNumbers||t.cellReferences||t.formulas)&&d++,this.unsubscribes.push(a.onSelectionChange(({activeCell:c})=>{if(this.formulaBarEditing=!1,l.setEditing(!1),c){let u=c.columnIndex-d,m=(this.state.page-1)*this.state.pageSize+c.rowIndex,v=formatCellReference(u,m+1),g=s.getFormula(u,m);if(g)this.formulaBarText=g,l.update(v,g);else {let{items:S}=this.state.getProcessedItems(),p=this.state.visibleColumnDefs,f=S[c.rowIndex],h=p[u],I=f&&h?String(f[h.columnId]??""):"";this.formulaBarText=I,l.update(v,I);}}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,a)=>{this.virtualScrollState?.scrollToRow(l,this.tableContainer,a?.align);};}this.renderingHelper.renderAll();}catch(n){throw this.destroy(),n}}createRenderingHelper(){let e=i=>({get:i,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:i=>{this.loadingOverlay=i;},handleCellClick:(i,n)=>this.handleCellClick(i,n),handleCellMouseDown:(i,n,r)=>this.handleCellMouseDown(i,n,r),handleCellContextMenu:(i,n,r)=>this.handleCellContextMenu(i,n,r),startCellEdit:(i,n)=>this.startCellEdit(i,n),toggleBooleanCell:(i,n,r)=>this.toggleBooleanCell(i,n,r),showContextMenu:(i,n)=>this.showContextMenu(i,n)};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 ce(t)}handleCellClick(e,t){this.selectionState&&this.selectionState.setActiveCell({rowIndex:e,columnIndex:t});}handleCellMouseDown(e,t,i){this.selectionState&&(this.cellEditor?.closeEditor(),i.preventDefault(),this.selectionState.startDrag(e,t),setTimeout(()=>this.renderingHelper.updateDragAttributes(),0));}handleCellContextMenu(e,t,i){i.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(i.clientX,i.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:i}=this.state.getProcessedItems(),n=this.state.visibleColumnDefs;i.length>0&&n.length>0&&(this.selectionState?.setSelectionRange({startRow:0,startCol:0,endRow:i.length-1,endCol:n.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,i){let{items:n}=this.state.getProcessedItems(),r=n.findIndex(s=>this.state.getRowId(s)===e);if(r<0)return;let o=n[r],l=!i;o[t]=l;let a=this.undoRedoState?.getWrappedCallback();a&&a({item:o,columnId:t,oldValue:i,newValue:l,rowIndex:r}),this.renderingHelper.updateRendererInteractionState();}startCellEdit(e,t){if(!this.cellEditor||!this.undoRedoState)return;let{items:i}=this.state.getProcessedItems(),n=this.state.visibleColumnDefs,r=i.find(g=>this.state.getRowId(g)===e),o=n.find(g=>g.columnId===t);if(!r||!o)return;let l=this.renderer.getWrapperElement();if(!l)return;let a=l.querySelector(`tr[data-row-id="${e}"]`);if(!a)return;let s=a.querySelector(`td[data-column-id="${t}"]`);if(!s)return;let d=i.indexOf(r),c=(g,S,p)=>{if(!n.find(w=>w.columnId===S))return;let h=r[S];r[S]=p;let I=this.undoRedoState?.getWrappedCallback();I&&I({item:r,columnId:S,oldValue:h,newValue:p,rowIndex:d}),this.renderingHelper.updateRendererInteractionState();},u=()=>{this.renderingHelper.updateRendererInteractionState();},m=()=>{if(this.selectionState){let S=this.selectionState.activeCell;if(S){let{items:p}=this.state.getProcessedItems(),f=Math.min(S.rowIndex+1,p.length-1);this.selectionState.setActiveCell({rowIndex:f,columnIndex:S.columnIndex});let h=this.renderer.getColOffset(),I=S.columnIndex-h;this.selectionState.setSelectionRange({startRow:f,startCol:I,endRow:f,endCol:I});}}this.renderer.getWrapperElement()?.focus();},v;if(this.formulaEngine){let S=this.state.columns.findIndex(p=>p.columnId===t);S>=0&&this.formulaEngine.hasFormula(S,d)&&(v=this.formulaEngine.getFormula(S,d));}this.cellEditor.startEdit(e,t,r,o,s,c,u,m,v);}buildFilterConfigs(){let e=flattenColumns(this.options.columns);for(let t of e){let i=t.filterable&&typeof t.filterable=="object"?t.filterable:null;i&&i.type&&this.filterConfigs.set(t.columnId,{columnId:t.columnId,filterField:i.filterField??t.columnId,filterType:i.type});}}handleFilterIconClick(e,t){let i=this.filterConfigs.get(e);if(!i)return;if(this.headerFilterState.openColumnId===e){this.headerFilterState.close();return}let n=document.createElement("div");this.headerFilterState.setFilters(this.state.filters),this.headerFilterState.setFilterOptions(this.state.filterOptions),this.headerFilterState.open(e,i,t,n);}buildFormulaAccessor(){let{items:e}=this.state.getProcessedItems(),t=this.state.visibleColumnDefs;return {getCellValue:(i,n)=>{let r=e[n],o=t[i];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 i=e.columnIndex-t,n=(this.state.page-1)*this.state.pageSize+e.rowIndex,r=this.formulaBarText,o=this.buildFormulaAccessor();if(r.startsWith("="))this.formulaEngine.setFormula(i,n,r,o);else {this.formulaEngine.hasFormula(i,n)&&this.formulaEngine.setFormula(i,n,null,o);let{items:l}=this.state.getProcessedItems(),a=this.state.visibleColumnDefs,s=l[e.rowIndex],d=a[i];s&&d&&(s[d.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 i=e.columnIndex-t,n=(this.state.page-1)*this.state.pageSize+e.rowIndex,r=this.formulaEngine.getFormula(i,n);if(r)this.formulaBarText=r,this.formulaBar?.update(formatCellReference(i,n+1),r);else {let{items:o}=this.state.getProcessedItems(),l=this.state.visibleColumnDefs,a=o[e.rowIndex],s=l[i],d=a&&s?String(a[s.columnId]??""):"";this.formulaBarText=d,this.formulaBar?.update(formatCellReference(i,n+1),d);}}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,U as ColumnChooser,Z as ColumnPinningState,re as ColumnReorderState,ne as ColumnResizeState,ae as ContextMenu,x as EventEmitter,oe as FillHandleState,he as FormulaBar,ue as FormulaEngineState,N as GridState,q as HeaderFilter,X as HeaderFilterState,se as InlineCellEditor,ee as KeyboardNavState,le as MarchingAntsOverlay,Ie as OGrid,de as OGridEventWiring,ce as OGridRendering,W as PaginationControls,Y as RowSelectionState,Q as SelectionState,$ as SideBar,K as SideBarState,G as StatusBar,j as TableLayoutState,V as TableRenderer,ie 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",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: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),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,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};
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Event wiring helper for OGrid (Vanilla JS).
|
|
3
3
|
*
|
|
4
4
|
* Extracts event subscription setup from OGrid for modularity:
|
|
5
|
-
* - initializeInteraction()
|
|
6
|
-
* - attachGlobalHandlers()
|
|
5
|
+
* - initializeInteraction() - creates interaction states and subscribes events
|
|
6
|
+
* - attachGlobalHandlers() - global pointer handlers for resize and drag
|
|
7
7
|
*
|
|
8
|
-
* Not exported publicly
|
|
8
|
+
* Not exported publicly - instantiated and owned by OGrid.
|
|
9
9
|
*/
|
|
10
10
|
import type { OGridOptions } from './types/gridTypes';
|
|
11
11
|
import type { GridState } from './state/GridState';
|
|
@@ -25,7 +25,7 @@ import type { TableLayoutState } from './state/TableLayoutState';
|
|
|
25
25
|
import type { ColumnPinningState } from './state/ColumnPinningState';
|
|
26
26
|
import type { RowId } from '@alaarab/ogrid-core';
|
|
27
27
|
/**
|
|
28
|
-
* Result of initializeInteraction
|
|
28
|
+
* Result of initializeInteraction - the created state objects and subscriptions.
|
|
29
29
|
*/
|
|
30
30
|
export interface InteractionResult<T> {
|
|
31
31
|
selectionState: SelectionState;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* - renderSideBar()
|
|
10
10
|
* - renderLoadingOverlay()
|
|
11
11
|
*
|
|
12
|
-
* Not exported publicly
|
|
12
|
+
* Not exported publicly - instantiated and owned by OGrid.
|
|
13
13
|
*/
|
|
14
14
|
import type { OGridOptions } from './types/gridTypes';
|
|
15
15
|
import type { GridState } from './state/GridState';
|
|
@@ -8,7 +8,7 @@ export declare class ColumnChooser<T> {
|
|
|
8
8
|
private initialized;
|
|
9
9
|
constructor(container: HTMLElement, state: GridState<T>);
|
|
10
10
|
render(): void;
|
|
11
|
-
/** Initial DOM creation
|
|
11
|
+
/** Initial DOM creation - called once. */
|
|
12
12
|
private createDOM;
|
|
13
13
|
/** Update checkbox checked states without destroying the dropdown. */
|
|
14
14
|
private updateDropdownState;
|
|
@@ -19,13 +19,20 @@ export declare class InlineCellEditor<T> {
|
|
|
19
19
|
closeEditor(): void;
|
|
20
20
|
private createEditor;
|
|
21
21
|
/**
|
|
22
|
-
* Shared factory for text/date input editors
|
|
22
|
+
* Shared factory for text/date input editors - both types have identical event handling,
|
|
23
23
|
* differing only in input.type and initial value formatting.
|
|
24
24
|
*/
|
|
25
25
|
private createInputEditor;
|
|
26
26
|
private createTextEditor;
|
|
27
27
|
private createCheckboxEditor;
|
|
28
28
|
private createDateEditor;
|
|
29
|
+
/**
|
|
30
|
+
* Create a text-based date editor with format-aware commit/blur handling.
|
|
31
|
+
* Parses user input with parseUserInputDate before committing.
|
|
32
|
+
* The committed value is either a YYYY-MM-DD ISO string (when parseable)
|
|
33
|
+
* or the raw user input (to allow downstream valueParser to handle it).
|
|
34
|
+
*/
|
|
35
|
+
private createDateTextEditor;
|
|
29
36
|
private createSelectEditor;
|
|
30
37
|
private createRichSelectEditor;
|
|
31
38
|
destroy(): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ISelectionRange } from '@alaarab/ogrid-core';
|
|
2
2
|
/**
|
|
3
|
-
* MarchingAntsOverlay
|
|
3
|
+
* MarchingAntsOverlay - renders SVG overlays on top of the grid:
|
|
4
4
|
* 1. Selection range: solid green border
|
|
5
5
|
* 2. Copy/Cut range: animated dashed border (marching ants)
|
|
6
6
|
*
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { ColumnFilterType, IDateFilterValue, IColumnFilterDef, IColumnMeta, IValueParserParams, IColumnDef as ICoreColumnDef, ICellValueChangedEvent, ICellEditorProps, CellEditorParams, IColumnGroupDef as ICoreColumnGroupDef, HeaderCell, HeaderRow, IColumnDefinition, RowId, UserLike, UserLikeInput, FilterValue, IFilters, IFetchParams, IPageResult, IDataSource, IGridColumnState, RowSelectionMode, IRowSelectionChangeEvent, StatusBarPanel, IStatusBarProps, IActiveCell, ISelectionRange, SideBarPanelId, ISideBarDef, ISheetDef, IVirtualScrollConfig, IColumnReorderConfig, IOGridApi, CsvColumn, FormulaExportOptions, StatusBarPart, StatusBarPartsInput, PaginationViewModel, GridContextMenuItem, IColumnHeaderMenuItem, GridContextMenuHandlerProps, ColumnHeaderMenuInput, ColumnHeaderMenuHandlers, ParseValueResult, AggregationResult, GridRowComparatorProps, ColumnPinState, IDropTarget, ICalculateDropTargetParams, IVisibleRange, IVisibleColumnRange, SortFilterRequest, SortFilterResponse, HeaderFilterConfigInput, HeaderFilterConfig, CellRenderDescriptorInput, CellRenderDescriptor, CellRenderMode, OverlayRect, ISortState, ArrowNavigationContext, ArrowNavigationResult, IFillFormulaOptions, FormulaReference, IResponsiveColumnsConfig, ZIndexKey, ICellAddress, ICellRange, CellKey, FormulaErrorType, TokenType, Token, ASTNode, BinaryOp, IFormulaContext, IFormulaFunction, IEvaluator, IRecalcResult, IFormulaEngineConfig, IGridDataAccessor, INamedRange, IAuditEntry, IAuditTrail, } from '@alaarab/ogrid-core';
|
|
2
|
-
export { toUserLike, isInSelectionRange, normalizeSelectionRange, escapeCsvValue, buildCsvHeader, buildCsvRows, exportToCsv, triggerCsvDownload, getCellValue, isColumnEditable, createGridDataAccessor, flattenColumns, buildHeaderRows, isFilterConfig, getFilterField, mergeFilter, deriveFilterOptionsFromData, getMultiSelectFilterFields, getStatusBarParts, getDataGridStatusBarConfig, getPaginationViewModel, PAGE_SIZE_OPTIONS, MAX_PAGE_BUTTONS, GRID_CONTEXT_MENU_ITEMS, COLUMN_HEADER_MENU_ITEMS, getContextMenuHandlers, getColumnHeaderMenuItems, formatShortcut, parseValue, numberParser, currencyParser, dateParser, emailParser, booleanParser, computeAggregations, processClientSideData, areGridRowPropsEqual, isRowInRange, getPinStateForColumn, reorderColumnArray, calculateDropTarget, computeVisibleRange, computeTotalHeight, getScrollTopForRow, computeVisibleColumnRange, partitionColumnsForVirtualization, createSortFilterWorker, terminateSortFilterWorker, extractValueMatrix, processClientSideDataAsync, getHeaderFilterConfig, getCellRenderDescriptor, CellDescriptorCache, resolveCellDisplayContent, resolveCellStyle, buildInlineEditorProps, buildPopoverEditorProps, measureRange, buildCellIndex, injectGlobalStyles, computeNextSortState, measureColumnContentWidth, AUTOSIZE_EXTRA_PX, AUTOSIZE_MAX_PX, findCtrlArrowTarget, computeTabNavigation, computeArrowNavigation, applyCellDeletion, rangesEqual, clampSelectionToBounds, computeAutoScrollSpeed, applyRangeRowSelection, computeRowSelectionState, formatCellValueForTsv, formatSelectionAsTsv, parseTsvClipboard, applyPastedValues, applyCutClear, applyFillValues, UndoRedoStack, validateColumns, validateRowIds, validateVirtualScrollConfig, indexToColumnLetter, columnLetterToIndex, formatCellReference, getResponsiveHiddenColumns, RESPONSIVE_BREAKPOINTS, resolveResponsiveConfig, applyResponsiveHiding, } from '@alaarab/ogrid-core';
|
|
2
|
+
export { toUserLike, isInSelectionRange, normalizeSelectionRange, escapeCsvValue, buildCsvHeader, buildCsvRows, exportToCsv, triggerCsvDownload, getCellValue, isColumnEditable, createGridDataAccessor, flattenColumns, buildHeaderRows, isFilterConfig, getFilterField, mergeFilter, deriveFilterOptionsFromData, getMultiSelectFilterFields, getStatusBarParts, getDataGridStatusBarConfig, getPaginationViewModel, PAGE_SIZE_OPTIONS, MAX_PAGE_BUTTONS, GRID_CONTEXT_MENU_ITEMS, COLUMN_HEADER_MENU_ITEMS, getContextMenuHandlers, getColumnHeaderMenuItems, formatShortcut, parseValue, numberParser, currencyParser, dateParser, emailParser, booleanParser, computeAggregations, processClientSideData, areGridRowPropsEqual, isRowInRange, getPinStateForColumn, reorderColumnArray, calculateDropTarget, computeVisibleRange, computeTotalHeight, getScrollTopForRow, computeVisibleColumnRange, partitionColumnsForVirtualization, createSortFilterWorker, terminateSortFilterWorker, extractValueMatrix, processClientSideDataAsync, getHeaderFilterConfig, getCellRenderDescriptor, CellDescriptorCache, resolveCellDisplayContent, resolveCellStyle, buildInlineEditorProps, buildPopoverEditorProps, measureRange, buildCellIndex, injectGlobalStyles, computeNextSortState, measureColumnContentWidth, AUTOSIZE_EXTRA_PX, AUTOSIZE_MAX_PX, findCtrlArrowTarget, computeTabNavigation, computeArrowNavigation, applyCellDeletion, rangesEqual, clampSelectionToBounds, computeAutoScrollSpeed, applyRangeRowSelection, computeRowSelectionState, formatCellValueForTsv, formatSelectionAsTsv, parseTsvClipboard, applyPastedValues, applyCutClear, applyFillValues, areFillCompatible, UndoRedoStack, validateColumns, validateRowIds, validateVirtualScrollConfig, indexToColumnLetter, columnLetterToIndex, formatCellReference, getResponsiveHiddenColumns, RESPONSIVE_BREAKPOINTS, resolveResponsiveConfig, applyResponsiveHiding, } from '@alaarab/ogrid-core';
|
|
3
3
|
export { CHECKBOX_COLUMN_WIDTH, ROW_NUMBER_COLUMN_WIDTH, ROW_NUMBER_COLUMN_ID, ROW_NUMBER_COLUMN_MIN_WIDTH, DEFAULT_MIN_COLUMN_WIDTH, CELL_PADDING, GRID_BORDER_RADIUS, DEFAULT_DEBOUNCE_MS, PEOPLE_SEARCH_DEBOUNCE_MS, SIDEBAR_TRANSITION_MS, Z_INDEX, } from '@alaarab/ogrid-core';
|
|
4
4
|
export { FormulaError, FormulaEngine, FormulaEvaluator, DependencyGraph, tokenize, parse, createBuiltInFunctions, parseCellRef, parseRange, formatAddress, toCellKey, fromCellKey, adjustFormulaReferences, toNumber, formulaToString, toBoolean, flattenArgs, isFormulaError, REF_ERROR, DIV_ZERO_ERROR, VALUE_ERROR, NAME_ERROR, CIRC_ERROR, GENERAL_ERROR, NA_ERROR, extractFormulaReferences, processFormulaBarCommit, deriveFormulaBarText, handleFormulaBarKeyDown, canInsertReference, insertReferenceAtCursor, FORMULA_REF_COLORS, FORMULA_BAR_CSS, FORMULA_BAR_STYLES, } from '@alaarab/ogrid-core/formula';
|
|
5
5
|
export type { IColumnDef, IColumnGroupDef, ICellEditorContext } from './types/columnTypes';
|
|
@@ -84,7 +84,7 @@ export declare class TableRenderer<T> {
|
|
|
84
84
|
private attachHeaderDelegation;
|
|
85
85
|
private detachHeaderDelegation;
|
|
86
86
|
getWrapperElement(): HTMLDivElement | null;
|
|
87
|
-
/** Full render
|
|
87
|
+
/** Full render - creates the table structure from scratch. */
|
|
88
88
|
render(): void;
|
|
89
89
|
/** Compute a signature string that captures header-affecting state. */
|
|
90
90
|
private computeHeaderSignature;
|
|
@@ -5,7 +5,7 @@ interface ColumnPinningEvents extends Record<string, unknown> {
|
|
|
5
5
|
};
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Manages column pinning state
|
|
8
|
+
* Manages column pinning state - tracks which columns are pinned left/right.
|
|
9
9
|
* Computes sticky offsets for the renderer.
|
|
10
10
|
*/
|
|
11
11
|
export declare class ColumnPinningState {
|
|
@@ -13,20 +13,20 @@ export interface FormulaEngineStateOptions {
|
|
|
13
13
|
formulaFunctions?: Record<string, IFormulaFunction>;
|
|
14
14
|
/** Callback invoked after every recalculation. */
|
|
15
15
|
onFormulaRecalc?: (result: IRecalcResult) => void;
|
|
16
|
-
/** Named ranges: name
|
|
16
|
+
/** Named ranges: name to cell/range reference string. */
|
|
17
17
|
namedRanges?: Record<string, string>;
|
|
18
18
|
/** Sheet accessors for cross-sheet references. */
|
|
19
19
|
sheets?: Record<string, IGridDataAccessor>;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* FormulaEngineState
|
|
22
|
+
* FormulaEngineState - wraps the core `FormulaEngine` for the vanilla JS grid.
|
|
23
23
|
*
|
|
24
24
|
* Follows the same EventEmitter pattern as other JS state classes. The engine
|
|
25
25
|
* is lazily created only when `formulas` is true in the options, keeping the
|
|
26
26
|
* cost at zero for grids that don't use formulas.
|
|
27
27
|
*
|
|
28
28
|
* ## Events
|
|
29
|
-
* - `formulaRecalc`
|
|
29
|
+
* - `formulaRecalc` - emitted after every recalculation with `IRecalcResult`.
|
|
30
30
|
*/
|
|
31
31
|
export declare class FormulaEngineState {
|
|
32
32
|
private emitter;
|
|
@@ -34,7 +34,7 @@ export declare class FormulaEngineState {
|
|
|
34
34
|
private readonly options;
|
|
35
35
|
constructor(options: FormulaEngineStateOptions);
|
|
36
36
|
/**
|
|
37
|
-
* Initialize with an accessor
|
|
37
|
+
* Initialize with an accessor - loads `initialFormulas` if provided.
|
|
38
38
|
* Must be called after the grid data is available so the accessor is valid.
|
|
39
39
|
*/
|
|
40
40
|
initialize(accessor: IGridDataAccessor): void;
|
|
@@ -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[];
|
|
@@ -21,7 +21,7 @@ export declare class TableLayoutState {
|
|
|
21
21
|
minWidth?: number;
|
|
22
22
|
width?: number;
|
|
23
23
|
}[], hasCheckboxColumn: boolean): number;
|
|
24
|
-
/** Get all column widths (overrides only
|
|
24
|
+
/** Get all column widths (overrides only - non-overridden columns use CSS defaults). */
|
|
25
25
|
getAllColumnWidths(): Record<string, number>;
|
|
26
26
|
/** Remove overrides for columns that no longer exist. */
|
|
27
27
|
cleanupOverrides(validColumnIds: Set<string>): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IColumnDef as ICoreColumnDef, CellEditorParams } from '@alaarab/ogrid-core';
|
|
2
2
|
export type { IColumnMeta, ICellValueChangedEvent, CellEditorParams } from '@alaarab/ogrid-core';
|
|
3
3
|
export type { ColumnFilterType, IDateFilterValue, IColumnFilterDef, IValueParserParams, HeaderCell, HeaderRow, IColumnDefinition, } from '@alaarab/ogrid-core';
|
|
4
|
-
/** Vanilla JS column definition
|
|
4
|
+
/** Vanilla JS column definition - extends core with DOM rendering capabilities. */
|
|
5
5
|
export interface IColumnDef<T = unknown> extends Omit<ICoreColumnDef<T>, 'cellEditor'> {
|
|
6
6
|
/** Render cell content by mutating the cell's DOM. Return void. */
|
|
7
7
|
renderCell?: (cell: HTMLTableCellElement, item: T, value: unknown) => void;
|
|
@@ -155,7 +155,7 @@ export interface OGridOptions<T> {
|
|
|
155
155
|
onFormulaRecalc?: (result: IRecalcResult) => void;
|
|
156
156
|
/** Custom formula functions to register with the formula engine (e.g. { MYFUNC: { minArgs: 1, maxArgs: 1, evaluate: ... } }). */
|
|
157
157
|
formulaFunctions?: Record<string, IFormulaFunction>;
|
|
158
|
-
/** Named ranges for the formula engine: name
|
|
158
|
+
/** Named ranges for the formula engine: name to cell/range ref string (e.g. { Revenue: 'A1:A10' }). */
|
|
159
159
|
namedRanges?: Record<string, string>;
|
|
160
160
|
/** Sheet accessors for cross-sheet formula references (e.g. { Sheet2: accessor }). */
|
|
161
161
|
sheets?: Record<string, IGridDataAccessor>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alaarab/ogrid-js",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.7",
|
|
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"
|