wandertable 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +505 -0
- package/dist/style.css +1 -0
- package/dist/types/WanderTable.d.ts +112 -0
- package/dist/types/WanderTable.d.ts.map +1 -0
- package/dist/types/__tests__/ColumnModel.test.d.ts +2 -0
- package/dist/types/__tests__/ColumnModel.test.d.ts.map +1 -0
- package/dist/types/__tests__/CommandBus.test.d.ts +2 -0
- package/dist/types/__tests__/CommandBus.test.d.ts.map +1 -0
- package/dist/types/__tests__/DataModel.test.d.ts +2 -0
- package/dist/types/__tests__/DataModel.test.d.ts.map +1 -0
- package/dist/types/__tests__/Export.test.d.ts +2 -0
- package/dist/types/__tests__/Export.test.d.ts.map +1 -0
- package/dist/types/__tests__/GroupedHeaders.test.d.ts +2 -0
- package/dist/types/__tests__/GroupedHeaders.test.d.ts.map +1 -0
- package/dist/types/__tests__/MergeModel.test.d.ts +2 -0
- package/dist/types/__tests__/MergeModel.test.d.ts.map +1 -0
- package/dist/types/__tests__/SelectionModel.test.d.ts +2 -0
- package/dist/types/__tests__/SelectionModel.test.d.ts.map +1 -0
- package/dist/types/__tests__/ViewMapping.test.d.ts +2 -0
- package/dist/types/__tests__/ViewMapping.test.d.ts.map +1 -0
- package/dist/types/columns/ColumnModel.d.ts +25 -0
- package/dist/types/columns/ColumnModel.d.ts.map +1 -0
- package/dist/types/columns/GroupedHeaders.d.ts +20 -0
- package/dist/types/columns/GroupedHeaders.d.ts.map +1 -0
- package/dist/types/core/CommandBus.d.ts +63 -0
- package/dist/types/core/CommandBus.d.ts.map +1 -0
- package/dist/types/core/DataModel.d.ts +27 -0
- package/dist/types/core/DataModel.d.ts.map +1 -0
- package/dist/types/core/EventEmitter.d.ts +10 -0
- package/dist/types/core/EventEmitter.d.ts.map +1 -0
- package/dist/types/core/MergeModel.d.ts +35 -0
- package/dist/types/core/MergeModel.d.ts.map +1 -0
- package/dist/types/core/PaginationModel.d.ts +24 -0
- package/dist/types/core/PaginationModel.d.ts.map +1 -0
- package/dist/types/core/RowGroupModel.d.ts +36 -0
- package/dist/types/core/RowGroupModel.d.ts.map +1 -0
- package/dist/types/core/SelectionModel.d.ts +47 -0
- package/dist/types/core/SelectionModel.d.ts.map +1 -0
- package/dist/types/core/ViewMapping.d.ts +37 -0
- package/dist/types/core/ViewMapping.d.ts.map +1 -0
- package/dist/types/core/ViewportModel.d.ts +9 -0
- package/dist/types/core/ViewportModel.d.ts.map +1 -0
- package/dist/types/editors/BlankEditor.d.ts +20 -0
- package/dist/types/editors/BlankEditor.d.ts.map +1 -0
- package/dist/types/editors/DropdownEditor.d.ts +23 -0
- package/dist/types/editors/DropdownEditor.d.ts.map +1 -0
- package/dist/types/editors/EditorManager.d.ts +22 -0
- package/dist/types/editors/EditorManager.d.ts.map +1 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/interaction/ClipboardManager.d.ts +19 -0
- package/dist/types/interaction/ClipboardManager.d.ts.map +1 -0
- package/dist/types/interaction/ColumnReorder.d.ts +20 -0
- package/dist/types/interaction/ColumnReorder.d.ts.map +1 -0
- package/dist/types/interaction/ColumnResize.d.ts +15 -0
- package/dist/types/interaction/ColumnResize.d.ts.map +1 -0
- package/dist/types/interaction/FillHandle.d.ts +39 -0
- package/dist/types/interaction/FillHandle.d.ts.map +1 -0
- package/dist/types/interaction/KeyboardNav.d.ts +19 -0
- package/dist/types/interaction/KeyboardNav.d.ts.map +1 -0
- package/dist/types/interaction/RowResize.d.ts +15 -0
- package/dist/types/interaction/RowResize.d.ts.map +1 -0
- package/dist/types/plugins/ContextMenu.d.ts +44 -0
- package/dist/types/plugins/ContextMenu.d.ts.map +1 -0
- package/dist/types/plugins/Export.d.ts +16 -0
- package/dist/types/plugins/Export.d.ts.map +1 -0
- package/dist/types/render/AutoFit.d.ts +23 -0
- package/dist/types/render/AutoFit.d.ts.map +1 -0
- package/dist/types/render/DOMRenderer.d.ts +91 -0
- package/dist/types/render/DOMRenderer.d.ts.map +1 -0
- package/dist/types/render/LoadingOverlay.d.ts +9 -0
- package/dist/types/render/LoadingOverlay.d.ts.map +1 -0
- package/dist/types/render/PaginationBar.d.ts +20 -0
- package/dist/types/render/PaginationBar.d.ts.map +1 -0
- package/dist/types/renderers/BadgeRenderer.d.ts +5 -0
- package/dist/types/renderers/BadgeRenderer.d.ts.map +1 -0
- package/dist/types/renderers/BlankRenderer.d.ts +9 -0
- package/dist/types/renderers/BlankRenderer.d.ts.map +1 -0
- package/dist/types/renderers/CheckboxRenderer.d.ts +5 -0
- package/dist/types/renderers/CheckboxRenderer.d.ts.map +1 -0
- package/dist/types/renderers/NumberRenderer.d.ts +7 -0
- package/dist/types/renderers/NumberRenderer.d.ts.map +1 -0
- package/dist/types/renderers/ProgressRenderer.d.ts +5 -0
- package/dist/types/renderers/ProgressRenderer.d.ts.map +1 -0
- package/dist/types/renderers/RendererRegistry.d.ts +10 -0
- package/dist/types/renderers/RendererRegistry.d.ts.map +1 -0
- package/dist/types/renderers/TextRenderer.d.ts +5 -0
- package/dist/types/renderers/TextRenderer.d.ts.map +1 -0
- package/dist/types/rows/RowModel.d.ts +20 -0
- package/dist/types/rows/RowModel.d.ts.map +1 -0
- package/dist/types/themes.d.ts +5 -0
- package/dist/types/themes.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +348 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/wandertable.cjs +14 -0
- package/dist/wandertable.cjs.map +1 -0
- package/dist/wandertable.global.js +14 -0
- package/dist/wandertable.global.js.map +1 -0
- package/dist/wandertable.js +2757 -0
- package/dist/wandertable.js.map +1 -0
- package/dist/wandertable.umd.js +14 -0
- package/dist/wandertable.umd.js.map +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
(function(w,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(w=typeof globalThis<"u"?globalThis:w||self,x(w.WanderTable={}))})(this,(function(w){"use strict";var Fe=Object.defineProperty;var ze=(w,x,B)=>x in w?Fe(w,x,{enumerable:!0,configurable:!0,writable:!0,value:B}):w[x]=B;var n=(w,x,B)=>ze(w,typeof x!="symbol"?x+"":x,B);const x={bgColor:"#ffffff",cellBgColor:"#ffffff",cellTextColor:"#1e293b",headerBgColor:"#f8fafc",headerTextColor:"#475569",gridLineColor:"#e2e8f0",selectionBgColor:"rgba(59, 130, 246, 0.08)",selectionBorderColor:"#3b82f6",focusBorderColor:"#3b82f6",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:13,headerFontSize:12,cellPadding:8,headerHeight:28,rowHeaderWidth:50};class B{constructor(t,e){n(this,"cells",new Map);n(this,"_rowCount");n(this,"_colCount");n(this,"_inTransaction",!1);n(this,"_dirtyKeys",new Set);n(this,"onChange",null);this._rowCount=t,this._colCount=e}get rowCount(){return this._rowCount}set rowCount(t){this._rowCount=t}get colCount(){return this._colCount}set colCount(t){this._colCount=t}key(t,e){return`${t}:${e}`}getCell(t,e){return this.cells.get(this.key(t,e))}setCell(t,e,s){const i=this.key(t,e);this.cells.set(i,s),this.markDirty(i)}setCellValue(t,e,s){const i=this.key(t,e),o=this.cells.get(i);o?o.value=s:this.cells.set(i,{value:s}),this.markDirty(i)}deleteCell(t,e){const s=this.key(t,e);this.cells.delete(s),this.markDirty(s)}hasCell(t,e){return this.cells.has(this.key(t,e))}applyPatch(t){this.transaction(()=>{for(const e of t){const s=this.key(e.row,e.col),i=this.cells.get(s);i?Object.assign(i,e.data):this.cells.set(s,{value:void 0,...e.data}),this._dirtyKeys.add(s)}})}transaction(t){var e;if(this._inTransaction){t();return}this._inTransaction=!0,this._dirtyKeys.clear();try{t()}finally{this._inTransaction=!1,this._dirtyKeys.size>0&&((e=this.onChange)==null||e.call(this,new Set(this._dirtyKeys)),this._dirtyKeys.clear())}}markDirty(t){var e;this._inTransaction?this._dirtyKeys.add(t):(e=this.onChange)==null||e.call(this,new Set([t]))}clear(){var t;this.cells.clear(),(t=this.onChange)==null||t.call(this,new Set)}forEach(t){for(const[e,s]of this.cells){const[i,o]=e.split(":").map(Number);t(i,o,s)}}}class V{constructor(){n(this,"listeners",new Map)}on(t,e){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e),()=>this.off(t,e)}off(t,e){var s;(s=this.listeners.get(t))==null||s.delete(e)}emit(t,e){var s;(s=this.listeners.get(t))==null||s.forEach(i=>{try{i(e)}catch(o){console.error(`[WanderTable] Error in "${String(t)}" handler:`,o)}})}removeAllListeners(){this.listeners.clear()}}class U{constructor(t,e){n(this,"_focus",null);n(this,"_ranges",[]);n(this,"_rowCount");n(this,"_colCount");n(this,"onChange",null);n(this,"infinite",!1);this._rowCount=t,this._colCount=e}get focus(){return this._focus}get ranges(){return this._ranges}setDimensions(t,e){this._rowCount=t,this._colCount=e}focusCell(t,e){var s;t=this.clampRow(t),e=this.clampCol(e),this._focus={row:t,col:e},this._ranges=[{startRow:t,startCol:e,endRow:t,endCol:e}],(s=this.onChange)==null||s.call(this)}extendTo(t,e){var s;this._focus&&(t=this.clampRow(t),e=this.clampCol(e),this._ranges=[{startRow:this._focus.row,startCol:this._focus.col,endRow:t,endCol:e}],(s=this.onChange)==null||s.call(this))}addRange(t){var e;this._ranges.push(t),this._focus={row:t.startRow,col:t.startCol},(e=this.onChange)==null||e.call(this)}selectColumn(t){var e;this._focus={row:0,col:t},this._ranges=[{startRow:0,startCol:t,endRow:1/0,endCol:t}],(e=this.onChange)==null||e.call(this)}selectRow(t){var e;this._focus={row:t,col:0},this._ranges=[{startRow:t,startCol:0,endRow:t,endCol:1/0}],(e=this.onChange)==null||e.call(this)}selectAll(){var t;this._focus={row:0,col:0},this._ranges=[{startRow:0,startCol:0,endRow:1/0,endCol:1/0}],(t=this.onChange)==null||t.call(this)}isSelected(t,e){return this._ranges.some(s=>this.inRange(t,e,s))}isFocused(t,e){var s,i;return((s=this._focus)==null?void 0:s.row)===t&&((i=this._focus)==null?void 0:i.col)===e}forEachSelected(t){for(const e of this._ranges){const s=Math.min(e.startRow,e.endRow),i=Math.min(Math.max(e.startRow,e.endRow),this._rowCount-1),o=Math.min(e.startCol,e.endCol),l=Math.min(Math.max(e.startCol,e.endCol),this._colCount-1);for(let r=s;r<=i;r++)for(let c=o;c<=l;c++)t(r,c)}}getBounds(){if(this._ranges.length===0)return null;let t=1/0,e=1/0,s=-1/0,i=-1/0;for(const o of this._ranges)t=Math.min(t,o.startRow,o.endRow),e=Math.min(e,o.startCol,o.endCol),s=Math.max(s,o.startRow,o.endRow),i=Math.max(i,o.startCol,o.endCol);return s=Math.min(s,this._rowCount-1),i=Math.min(i,this._colCount-1),{r1:t,c1:e,r2:s,c2:i}}getInfo(){const t=this.getBounds();let e=0;this.forEachSelected(()=>{e++});const s=(t==null?void 0:t.r1)??0,i=(t==null?void 0:t.c1)??0,o=(t==null?void 0:t.r2)??0,l=(t==null?void 0:t.c2)??0,r=this._ranges.some(a=>a.endRow===1/0||a.startRow===1/0),c=this._ranges.some(a=>a.endCol===1/0||a.startCol===1/0),h=t!==null&&(c||i===0&&l===this._colCount-1),d=t!==null&&(r||s===0&&o===this._rowCount-1);return{focus:this._focus?{...this._focus}:null,ranges:this._ranges.map(a=>({...a})),bounds:t?{startRow:s,startCol:i,endRow:o,endCol:l}:null,cellCount:e,rangeCount:this._ranges.length,isMultiCell:e>1,isFullRow:h,isFullCol:d,isAll:h&&d,isEmpty:this._ranges.length===0,rowSpan:t?o-s+1:0,colSpan:t?l-i+1:0}}clear(){var t;this._focus=null,this._ranges=[],(t=this.onChange)==null||t.call(this)}move(t,e,s){if(!this._focus){this.focusCell(0,0);return}const i=this.clampRow(this._focus.row+t),o=this.clampCol(this._focus.col+e);s?this.extendTo(i,o):this.focusCell(i,o)}inRange(t,e,s){const i=Math.min(s.startRow,s.endRow),o=Math.max(s.startRow,s.endRow),l=Math.min(s.startCol,s.endCol),r=Math.max(s.startCol,s.endCol);return t>=i&&t<=o&&e>=l&&e<=r}clampRow(t){return this.infinite?Math.max(0,t):Math.max(0,Math.min(this._rowCount-1,t))}clampCol(t){return this.infinite?Math.max(0,t):Math.max(0,Math.min(this._colCount-1,t))}}class X{constructor(t=100){n(this,"undoStack",[]);n(this,"redoStack",[]);n(this,"limit");n(this,"onChange",null);this.limit=t}execute(t){var e;t.execute(),this.undoStack.push(t),this.undoStack.length>this.limit&&this.undoStack.shift(),this.redoStack.length=0,(e=this.onChange)==null||e.call(this)}undo(){var e;const t=this.undoStack.pop();return t?(t.undo(),this.redoStack.push(t),(e=this.onChange)==null||e.call(this),t):null}redo(){var e;const t=this.redoStack.pop();return t?(t.execute(),this.undoStack.push(t),(e=this.onChange)==null||e.call(this),t):null}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}clear(){this.undoStack.length=0,this.redoStack.length=0}}class N{constructor(t,e,s,i){n(this,"oldValue");var o;this.data=t,this.row=e,this.col=s,this.newValue=i,this.oldValue=(o=t.getCell(e,s))==null?void 0:o.value}execute(){this.data.setCellValue(this.row,this.col,this.newValue)}undo(){this.oldValue===void 0?this.data.deleteCell(this.row,this.col):this.data.setCellValue(this.row,this.col,this.oldValue)}getChanges(){return[{row:this.row,col:this.col,oldValue:this.oldValue,newValue:this.newValue}]}}class ${constructor(t,e){n(this,"snapshots");this.data=t,this.patches=e,this.snapshots=e.map(s=>({row:s.row,col:s.col,old:t.getCell(s.row,s.col)?{...t.getCell(s.row,s.col)}:void 0}))}execute(){this.data.applyPatch(this.patches)}undo(){this.data.transaction(()=>{for(const t of this.snapshots)t.old===void 0?this.data.deleteCell(t.row,t.col):this.data.setCell(t.row,t.col,t.old)})}getChanges(){return this.snapshots.map((t,e)=>{var s,i,o;return{row:t.row,col:t.col,oldValue:(s=t.old)==null?void 0:s.value,newValue:(o=(i=this.patches[e])==null?void 0:i.data)==null?void 0:o.value}})}}class Y{constructor(t,e){n(this,"snapshots",[]);this.data=t,this.cells=e;for(const{row:s,col:i}of e){const o=t.getCell(s,i);o&&this.snapshots.push({row:s,col:i,old:{...o}})}}execute(){this.data.transaction(()=>{for(const{row:t,col:e}of this.cells)this.data.deleteCell(t,e)})}undo(){this.data.transaction(()=>{for(const t of this.snapshots)this.data.setCell(t.row,t.col,t.old)})}getChanges(){return this.snapshots.map(t=>({row:t.row,col:t.col,oldValue:t.old.value,newValue:void 0}))}}class D{constructor(t,e,s){n(this,"configs");n(this,"widths");n(this,"prefixSums");n(this,"defaultWidth");var i;this.defaultWidth=e,this.configs=s??[],this.widths=new Array(t);for(let o=0;o<t;o++)this.widths[o]=((i=this.configs[o])==null?void 0:i.width)??e;this.prefixSums=this.buildPrefixSums()}buildPrefixSums(){const t=new Array(this.widths.length+1);t[0]=0;for(let e=0;e<this.widths.length;e++)t[e+1]=t[e]+this.widths[e];return t}get count(){return this.widths.length}getWidth(t){return this.widths[t]??this.defaultWidth}setWidth(t,e){const s=this.configs[t],i=(s==null?void 0:s.minWidth)??30,o=(s==null?void 0:s.maxWidth)??1/0;this.widths[t]=Math.max(i,Math.min(o,e)),this.prefixSums=this.buildPrefixSums()}getX(t){return this.prefixSums[t]??0}getTotalWidth(){return this.prefixSums[this.widths.length]??0}getConfig(t){return this.configs[t]}setCount(t){for(;this.widths.length<t;)this.widths.push(this.defaultWidth);this.widths.length=t,this.prefixSums=this.buildPrefixSums()}getColAtX(t){let e=0,s=this.widths.length-1;for(;e<=s;){const i=e+s>>>1;if(this.prefixSums[i+1]<=t)e=i+1;else if(this.prefixSums[i]>t)s=i-1;else return i}return Math.max(0,Math.min(e,this.widths.length-1))}static columnLabel(t){return z(t)}}function z(g){let t="",e=g;for(;e>=0;)t=String.fromCharCode(65+e%26)+t,e=Math.floor(e/26)-1;return t}class G{constructor(t,e){n(this,"heights");n(this,"prefixSums");n(this,"defaultHeight");n(this,"configs",new Map);this.defaultHeight=e,this.heights=new Array(t).fill(e),this.prefixSums=this.buildPrefixSums()}buildPrefixSums(){const t=new Array(this.heights.length+1);t[0]=0;for(let e=0;e<this.heights.length;e++)t[e+1]=t[e]+this.heights[e];return t}get count(){return this.heights.length}getHeight(t){return this.heights[t]??this.defaultHeight}setHeight(t,e){this.heights[t]=Math.max(20,e),this.prefixSums=this.buildPrefixSums()}getY(t){return this.prefixSums[t]??0}getTotalHeight(){return this.prefixSums[this.heights.length]??0}getConfig(t){return this.configs.get(t)}setConfig(t,e){this.configs.set(t,e),e.height!=null&&this.setHeight(t,e.height)}setCount(t){for(;this.heights.length<t;)this.heights.push(this.defaultHeight);this.heights.length=t,this.prefixSums=this.buildPrefixSums()}getRowAtY(t){let e=0,s=this.heights.length-1;for(;e<=s;){const i=e+s>>>1;if(this.prefixSums[i+1]<=t)e=i+1;else if(this.prefixSums[i]>t)s=i-1;else return i}return Math.max(0,Math.min(e,this.heights.length-1))}}class ue{constructor(t){n(this,"container");n(this,"scrollContainer");n(this,"scrollSentinel");n(this,"viewportEl");n(this,"colHeaderEl");n(this,"rowHeaderEl");n(this,"cornerEl");n(this,"rowPool",[]);n(this,"activeRows",new Map);n(this,"viewport",{startRow:0,endRow:0,startCol:0,endCol:0,scrollX:0,scrollY:0});n(this,"ctx");n(this,"rafId",0);n(this,"needsRender",!1);n(this,"onScroll",null);n(this,"onCellClick",null);n(this,"onCellDblClick",null);n(this,"onCellContextMenu",null);n(this,"onHeaderClick",null);n(this,"onColumnResizeStart",null);n(this,"onHeaderContextMenu",null);n(this,"handleScroll",()=>{this.scheduleRender()});n(this,"handleMouseDown",t=>{var s;const e=this.getCellFromEvent(t);e&&((s=this.onCellClick)==null||s.call(this,e.row,e.col,t))});n(this,"handleDblClick",t=>{var s;const e=this.getCellFromEvent(t);e&&((s=this.onCellDblClick)==null||s.call(this,e.row,e.col,t))});n(this,"handleContextMenu",t=>{var s;const e=this.getCellFromEvent(t);e&&((s=this.onCellContextMenu)==null||s.call(this,e.row,e.col,t))});n(this,"handleColHeaderMouse",t=>{var o,l;const e=t.target.closest(".wt-col-header-cell");if(!e)return;const s=parseInt(e.dataset.col??"",10);if(isNaN(s))return;const i=e.getBoundingClientRect();if(t.clientX>i.right-5){(o=this.onColumnResizeStart)==null||o.call(this,s,t.clientX);return}(l=this.onHeaderClick)==null||l.call(this,"col",s,t)});n(this,"handleRowHeaderMouse",t=>{var i;const e=t.target.closest(".wt-row-header-cell");if(!e)return;const s=parseInt(e.dataset.row??"",10);isNaN(s)||(i=this.onHeaderClick)==null||i.call(this,"row",s,t)});n(this,"handleCornerMouse",t=>{var e;(e=this.onHeaderClick)==null||e.call(this,"corner",-1,t)});n(this,"handleColHeaderContextMenu",t=>{var i;t.preventDefault();const e=t.target.closest(".wt-col-header-cell");if(!e)return;const s=parseInt(e.dataset.col??"",10);isNaN(s)||(i=this.onHeaderContextMenu)==null||i.call(this,"col",s,t)});n(this,"handleRowHeaderContextMenu",t=>{var i;t.preventDefault();const e=t.target.closest(".wt-row-header-cell");if(!e)return;const s=parseInt(e.dataset.row??"",10);isNaN(s)||(i=this.onHeaderContextMenu)==null||i.call(this,"row",s,t)});this.container=t,this.container.classList.add("wt-root"),this.container.setAttribute("tabindex","0"),this.cornerEl=document.createElement("div"),this.cornerEl.className="wt-corner",this.colHeaderEl=document.createElement("div"),this.colHeaderEl.className="wt-col-headers",this.rowHeaderEl=document.createElement("div"),this.rowHeaderEl.className="wt-row-headers",this.scrollContainer=document.createElement("div"),this.scrollContainer.className="wt-scroll-container",this.scrollSentinel=document.createElement("div"),this.scrollSentinel.className="wt-scroll-sentinel",this.viewportEl=document.createElement("div"),this.viewportEl.className="wt-viewport",this.scrollContainer.appendChild(this.scrollSentinel),this.scrollContainer.appendChild(this.viewportEl),this.container.appendChild(this.cornerEl),this.container.appendChild(this.colHeaderEl),this.container.appendChild(this.rowHeaderEl),this.container.appendChild(this.scrollContainer),this.scrollContainer.addEventListener("scroll",this.handleScroll,{passive:!0}),this.viewportEl.addEventListener("mousedown",this.handleMouseDown),this.viewportEl.addEventListener("dblclick",this.handleDblClick),this.viewportEl.addEventListener("contextmenu",this.handleContextMenu),this.colHeaderEl.addEventListener("mousedown",this.handleColHeaderMouse),this.colHeaderEl.addEventListener("contextmenu",this.handleColHeaderContextMenu),this.rowHeaderEl.addEventListener("mousedown",this.handleRowHeaderMouse),this.rowHeaderEl.addEventListener("contextmenu",this.handleRowHeaderContextMenu),this.cornerEl.addEventListener("mousedown",this.handleCornerMouse)}init(t){this.ctx=t,this.container.classList.toggle("wt-root--no-gridlines",!t.showGridLines),this.container.classList.toggle("wt-root--no-border",!t.showBorder),t.layout==="auto"&&(this.container.classList.add("wt-root--auto"),this.scrollContainer.classList.add("wt-scroll-container--auto")),this.applyTheme(),this.updateLayout(),this.scheduleRender()}applyTheme(){const t=this.ctx.theme,e=this.container.style;e.setProperty("--wt-bg",t.bgColor),e.setProperty("--wt-cell-bg",t.cellBgColor),e.setProperty("--wt-cell-text",t.cellTextColor),e.setProperty("--wt-header-bg",t.headerBgColor),e.setProperty("--wt-header-text",t.headerTextColor),e.setProperty("--wt-grid-line",t.gridLineColor),e.setProperty("--wt-sel-bg",t.selectionBgColor),e.setProperty("--wt-sel-border",t.selectionBorderColor),e.setProperty("--wt-focus-border",t.focusBorderColor),e.setProperty("--wt-font",t.fontFamily),e.setProperty("--wt-font-size",`${t.fontSize}px`),e.setProperty("--wt-header-font-size",`${t.headerFontSize}px`),e.setProperty("--wt-cell-padding",`${t.cellPadding}px`),e.setProperty("--wt-header-height",`${t.headerHeight}px`),e.setProperty("--wt-row-header-width",`${t.rowHeaderWidth}px`)}updateLayout(){const{columns:t,rows:e,viewMapping:s,showColHeaders:i,showRowHeaders:o,theme:l}=this.ctx,r=t.getTotalWidth(),c=s.visibleRowCount,h=c===e.count?e.getTotalHeight():e.getY(c),d=this.ctx.headerRows?this.ctx.headerRows.length:1,a=i?l.headerHeight*d:0,u=o?l.rowHeaderWidth:0;if(this.ctx.layout==="auto"){if(this.container.style.display="grid",this.container.style.gridTemplateColumns=`${u}px ${r}px`,this.container.style.gridTemplateRows=`${a}px auto`,this.container.style.width=`${u+r}px`,this.container.style.minWidth="100%",this.cornerEl.style.display=i&&o?"":"none",this.cornerEl.style.position="static",this.cornerEl.style.width="",this.cornerEl.style.height="",this.colHeaderEl.style.display=i?"":"none",this.colHeaderEl.style.position="static",this.colHeaderEl.style.left="",this.colHeaderEl.style.right="",this.colHeaderEl.style.height=`${a}px`,this.colHeaderEl.style.overflow="visible",this.rowHeaderEl.style.display=o?"":"none",this.rowHeaderEl.style.position="static",this.rowHeaderEl.style.top="",this.rowHeaderEl.style.bottom="",this.rowHeaderEl.style.width=`${u}px`,this.rowHeaderEl.style.overflow="visible",this.scrollContainer.style.position="static",this.scrollContainer.style.top="",this.scrollContainer.style.left="",this.scrollContainer.style.right="",this.scrollContainer.style.bottom="",this.scrollContainer.style.overflow="visible",this.scrollContainer.style.gridColumn=o?"2":"1 / -1",this.scrollSentinel.style.width=`${r}px`,this.scrollSentinel.style.height="0",this.viewportEl.style.position="relative",this.viewportEl.style.height=`${h}px`,this.viewportEl.style.width=`${r}px`,o){const f=this.rowHeaderEl.querySelector(".wt-row-headers-inner");f&&(f.style.height=`${h}px`),this.rowHeaderEl.style.height=`${h}px`,this.rowHeaderEl.style.gridRow="2",this.rowHeaderEl.style.gridColumn="1"}}else this.scrollSentinel.style.width=`${r}px`,this.scrollSentinel.style.height=`${h}px`,this.cornerEl.style.display=i&&o?"":"none",this.cornerEl.style.width=`${u}px`,this.cornerEl.style.height=`${a}px`,this.colHeaderEl.style.display=i?"":"none",this.colHeaderEl.style.left=`${u}px`,this.colHeaderEl.style.height=`${a}px`,this.colHeaderEl.style.right="0",this.rowHeaderEl.style.display=o?"":"none",this.rowHeaderEl.style.top=`${a}px`,this.rowHeaderEl.style.width=`${u}px`,this.rowHeaderEl.style.bottom="0",this.scrollContainer.style.top=`${a}px`,this.scrollContainer.style.left=`${u}px`,this.scrollContainer.style.right="0",this.scrollContainer.style.bottom="0"}scheduleRender(){this.needsRender||(this.needsRender=!0,this.rafId=requestAnimationFrame(()=>{this.needsRender=!1,this.render()}))}render(){var H;const{columns:t,rows:e,viewMapping:s,showColHeaders:i,showRowHeaders:o}=this.ctx,l=this.scrollContainer,r=l.clientWidth,c=l.clientHeight,h=l.scrollLeft,d=l.scrollTop,a=s.visibleRowCount,u=this.ctx.layout==="auto",f=3;let m,y,b,R;if(u)m=0,y=a-1,b=0,R=t.count-1;else{const C=e.getRowAtY(d),p=e.getRowAtY(d+c),S=t.getColAtX(h),L=t.getColAtX(h+r);m=Math.max(0,C-f),y=Math.min(a-1,p+f),b=Math.max(0,S-f),R=Math.min(t.count-1,L+f)}const E={startRow:m,endRow:y,startCol:b,endCol:R,scrollX:h,scrollY:d};this.viewport=E;const I=this.ctx.frozenRows,P=this.ctx.frozenCols,_=new Set;for(let C=0;C<I&&C<a;C++)_.add(C);for(let C=E.startRow;C<=E.endRow;C++)_.add(C);for(const[C,p]of this.activeRows)_.has(C)||(p.el.style.display="none",this.rowPool.push(p),this.activeRows.delete(C));for(const C of _)this.renderRow(C,E,h,d,I,P);if(this.ctx.autoRowHeight){let C=!1;for(const p of _){const S=this.activeRows.get(p);if(!S)continue;let L=20;for(const k of S.cells){if(k.style.display==="none")continue;const T=k.scrollHeight;T>L&&(L=T)}const F=e.getHeight(p);Math.abs(L-F)>1&&(e.setHeight(p,L),C=!0)}if(C){this.updateLayout();for(const p of _){const S=this.activeRows.get(p);if(!S)continue;const F=p<I?e.getY(p)+d:e.getY(p),k=e.getHeight(p);S.el.style.transform=`translateY(${F}px)`,S.el.style.height=`${k}px`;for(const T of S.cells)T.style.display!=="none"&&(T.style.height=`${k}px`)}}}i&&this.renderColHeaders(E,h),o&&this.renderRowHeaders(E,d),(H=this.onScroll)==null||H.call(this,E)}renderRow(t,e,s,i,o,l){var _;const{columns:r,rows:c,data:h,selection:d,viewMapping:a}=this.ctx,u=a.toDataRow(t);let f=this.activeRows.get(t);const m=c.getY(t),y=c.getHeight(t),b=e.endCol-e.startCol+1,R=t<o;f||(f=this.acquireRow(b),f.rowIndex=t,this.activeRows.set(t,f));const E=f.el;E.style.display="";const I=R?m+i:m;E.style.transform=`translateY(${I}px)`,E.style.height=`${y}px`,E.style.zIndex=R?"2":"",E.dataset.row=String(u),this.ensureCells(f,b);const{merges:P}=this.ctx;for(let H=0;H<b;H++){const C=e.startCol+H,p=f.cells[H];if(P.isHidden(u,C)){p.style.display="none";continue}const S=r.getX(C);let L=r.getWidth(C),F=y;const k=P.getMerge(u,C);if(k&&k.row===u&&k.col===C){for(let v=1;v<k.colSpan;v++)L+=r.getWidth(C+v);for(let v=1;v<k.rowSpan;v++)F+=c.getHeight(t+v);p.style.zIndex="1"}else p.style.zIndex="";const T=C<l,Be=T?S+s:S;p.style.transform=`translateX(${Be}px)`,p.style.width=`${L}px`,p.style.height=`${F}px`,p.style.display="",(T||R)&&(p.style.zIndex=T&&R?"4":"3"),p.dataset.row=String(u),p.dataset.col=String(C);const M=h.getCell(u,C),A={selected:d.isSelected(u,C),focused:d.isFocused(u,C),editing:!1,hover:!1};if(p.classList.toggle("wt-cell--selected",A.selected),p.classList.toggle("wt-cell--focused",A.focused),M!=null&&M.style){const v=M.style;v.bgColor?p.style.backgroundColor=v.bgColor:p.style.backgroundColor="",v.textColor?p.style.color=v.textColor:p.style.color="",v.textAlign?p.style.textAlign=v.textAlign:p.style.textAlign="",v.borderLeft?p.style.borderLeft=v.borderLeft:p.style.borderLeft="",v.borderRight?p.style.borderRight=v.borderRight:p.style.borderRight="",v.borderTop?p.style.borderTop=v.borderTop:p.style.borderTop="",v.borderBottom?p.style.borderBottom=v.borderBottom:p.style.borderBottom=""}else p.style.backgroundColor="",p.style.color="",p.style.textAlign="",p.style.borderLeft="",p.style.borderRight="",p.style.borderTop="",p.style.borderBottom="";M!=null&&M.className&&(p.className=`wt-cell ${M.className}`,A.selected&&p.classList.add("wt-cell--selected"),A.focused&&p.classList.add("wt-cell--focused"));const Pe=(M==null?void 0:M.type)??((_=this.ctx.columns.getConfig(C))==null?void 0:_.type)??this.ctx.defaultCellType;(this.ctx.renderers.get(Pe)??this.ctx.defaultRenderer).render(p,M,A)}for(let H=b;H<f.cells.length;H++)f.cells[H].style.display="none"}renderColHeaders(t,e){var r;const{columns:s,theme:i}=this.ctx,o=this.ctx.headerRows;this.colHeaderEl.scrollLeft=e;const l=this.colHeaderEl.querySelector(".wt-col-headers-inner")??this.createColHeadersInner();if(l.style.width=`${s.getTotalWidth()}px`,o&&o.length>1){const c=i.headerHeight,h=c*o.length;this.colHeaderEl.style.height=`${h}px`,l.style.height=`${h}px`,l.innerHTML="";for(let d=0;d<o.length;d++)for(const a of o[d]){const u=document.createElement("div");u.className=a.colSpan>1?"wt-header-cell wt-col-header-group":"wt-header-cell wt-col-header-cell";const f=s.getX(a.col);let m=0;for(let y=0;y<a.colSpan;y++)m+=s.getWidth(a.col+y);u.style.transform=`translate(${f}px, ${d*c}px)`,u.style.width=`${m}px`,u.style.height=`${c*a.rowSpan}px`,u.textContent=a.label,a.colSpan===1&&(u.dataset.col=String(a.col)),l.appendChild(u)}}else{const c=t.endCol-t.startCol+1;for(;l.children.length<c;){const h=document.createElement("div");h.className="wt-header-cell wt-col-header-cell",l.appendChild(h)}for(let h=0;h<c;h++){const d=t.startCol+h,a=l.children[h];a.style.display="",a.style.transform=`translateX(${s.getX(d)}px)`,a.style.width=`${s.getWidth(d)}px`,a.style.height=`${i.headerHeight}px`,a.textContent=((r=this.ctx.columns.getConfig(d))==null?void 0:r.label)??D.columnLabel(d),a.dataset.col=String(d)}for(let h=c;h<l.children.length;h++)l.children[h].style.display="none"}}createColHeadersInner(){const t=document.createElement("div");return t.className="wt-col-headers-inner",this.colHeaderEl.appendChild(t),t}renderRowHeaders(t,e){const{rows:s,theme:i}=this.ctx;this.rowHeaderEl.scrollTop=e;let o=this.rowHeaderEl.querySelector(".wt-row-headers-inner");o||(o=document.createElement("div"),o.className="wt-row-headers-inner",this.rowHeaderEl.appendChild(o)),o.style.height=`${s.getTotalHeight()}px`;const l=t.endRow-t.startRow+1;for(;o.children.length<l;){const r=document.createElement("div");r.className="wt-header-cell wt-row-header-cell",o.appendChild(r)}for(let r=0;r<l;r++){const c=t.startRow+r,h=o.children[r];h.style.display="",h.style.transform=`translateY(${s.getY(c)}px)`,h.style.height=`${s.getHeight(c)}px`,h.style.width=`${i.rowHeaderWidth}px`,h.textContent=String(c+1),h.dataset.row=String(c)}for(let r=l;r<o.children.length;r++)o.children[r].style.display="none"}acquireRow(t){let e=this.rowPool.pop();if(!e){const s=document.createElement("div");s.className="wt-row",this.viewportEl.appendChild(s),e={el:s,cells:[],rowIndex:-1}}return this.ensureCells(e,t),e}ensureCells(t,e){for(;t.cells.length<e;){const s=document.createElement("div");s.className="wt-cell",t.el.appendChild(s),t.cells.push(s)}}getCellFromEvent(t){const e=t.target.closest(".wt-cell");if(!e)return null;const s=parseInt(e.dataset.row??"",10),i=parseInt(e.dataset.col??"",10);return isNaN(s)||isNaN(i)?null:{row:s,col:i}}getViewport(){return this.viewport}scrollToCell(t,e){const{columns:s,rows:i}=this.ctx,o=s.getX(e),l=i.getY(t),r=s.getWidth(e),c=i.getHeight(t),h=this.scrollContainer,d=h.clientWidth,a=h.clientHeight;o<h.scrollLeft?h.scrollLeft=o:o+r>h.scrollLeft+d&&(h.scrollLeft=o+r-d),l<h.scrollTop?h.scrollTop=l:l+c>h.scrollTop+a&&(h.scrollTop=l+c-a)}getCellBounds(t,e){const{columns:s,rows:i}=this.ctx;return{x:s.getX(e)-this.scrollContainer.scrollLeft,y:i.getY(t)-this.scrollContainer.scrollTop,width:s.getWidth(e),height:i.getHeight(t)}}getScrollContainer(){return this.scrollContainer}getViewportEl(){return this.viewportEl}getContainer(){return this.container}destroy(){cancelAnimationFrame(this.rafId),this.scrollContainer.removeEventListener("scroll",this.handleScroll),this.viewportEl.removeEventListener("mousedown",this.handleMouseDown),this.viewportEl.removeEventListener("dblclick",this.handleDblClick),this.viewportEl.removeEventListener("contextmenu",this.handleContextMenu),this.colHeaderEl.removeEventListener("mousedown",this.handleColHeaderMouse),this.colHeaderEl.removeEventListener("contextmenu",this.handleColHeaderContextMenu),this.rowHeaderEl.removeEventListener("mousedown",this.handleRowHeaderMouse),this.rowHeaderEl.removeEventListener("contextmenu",this.handleRowHeaderContextMenu),this.cornerEl.removeEventListener("mousedown",this.handleCornerMouse),this.container.innerHTML=""}}const ge={selected:!1,focused:!1,editing:!1,hover:!1};class fe{constructor(t,e,s,i,o,l){n(this,"measureEl");n(this,"data");n(this,"columns");n(this,"renderers");n(this,"defaultRenderer");this.data=e,this.columns=s,this.renderers=o,this.defaultRenderer=l,this.measureEl=document.createElement("div"),this.measureEl.className="wt-cell",this.measureEl.style.position="absolute",this.measureEl.style.visibility="hidden",this.measureEl.style.left="-9999px",this.measureEl.style.top="-9999px",this.measureEl.style.whiteSpace="nowrap",this.measureEl.style.height="auto",this.measureEl.style.width="auto",t.appendChild(this.measureEl)}measureCell(t,e){var c;const s=this.data.getCell(t,e),i=(s==null?void 0:s.type)??((c=this.columns.getConfig(e))==null?void 0:c.type)??"text";(this.renderers.get(i)??this.defaultRenderer).render(this.measureEl,s,ge);const l=this.measureEl.scrollWidth+1,r=this.measureEl.scrollHeight+1;return this.measureEl.textContent="",this.measureEl.innerHTML="",{width:l,height:r}}autoFitColumn(t,e=500){var a;let i=40;const o=((a=this.columns.getConfig(t))==null?void 0:a.label)??z(t);this.measureEl.textContent=o,this.measureEl.style.fontWeight="500",i=Math.max(i,this.measureEl.scrollWidth+16),this.measureEl.style.fontWeight="";const l=this.data.rowCount,r=l>e?Math.floor(l/e):1;for(let u=0;u<l;u+=r){if(!this.data.hasCell(u,t))continue;const{width:f}=this.measureCell(u,t);i=Math.max(i,f+16)}const c=this.columns.getConfig(t),h=(c==null?void 0:c.minWidth)??30,d=(c==null?void 0:c.maxWidth)??600;return Math.max(h,Math.min(d,i))}autoFitRow(t){let e=20;for(let s=0;s<this.columns.count;s++){if(!this.data.hasCell(t,s))continue;this.measureEl.style.width=`${this.columns.getWidth(s)}px`,this.measureEl.style.whiteSpace="normal";const{height:i}=this.measureCell(t,s);e=Math.max(e,i),this.measureEl.style.width="auto",this.measureEl.style.whiteSpace="nowrap"}return e}destroy(){this.measureEl.remove()}}class K{render(t,e,s){const i=e==null?void 0:e.value;if(i==null||i===""){t.textContent="";return}t.textContent=String(i)}}class j{render(t,e,s){const i=!!(e!=null&&e.value);t.innerHTML=`<label class="wt-checkbox">
|
|
2
|
+
<span class="wt-checkbox-box${i?" wt-checkbox-box--checked":""}">
|
|
3
|
+
${i?'<svg width="12" height="12" viewBox="0 0 12 12" fill="none"><path d="M2.5 6L5 8.5L9.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>':""}
|
|
4
|
+
</span>
|
|
5
|
+
</label>`}}const q={active:{bg:"#dcfce7",text:"#166534"},success:{bg:"#dcfce7",text:"#166534"},inactive:{bg:"#fef2f2",text:"#991b1b"},error:{bg:"#fef2f2",text:"#991b1b"},pending:{bg:"#fef9c3",text:"#854d0e"},warning:{bg:"#fef9c3",text:"#854d0e"},info:{bg:"#dbeafe",text:"#1e40af"},default:{bg:"#f1f5f9",text:"#475569"}};class J{render(t,e,s){var h,d;if((e==null?void 0:e.value)==null||e.value===""){t.textContent="";return}const i=String(e.value),o=i.toLowerCase(),l=q[o]??q.default,r=(h=e.meta)==null?void 0:h.badgeBg,c=(d=e.meta)==null?void 0:d.badgeText;t.innerHTML=`<span class="wt-badge" style="background:${r??l.bg};color:${c??l.text}">${i}</span>`}}class Z{constructor(t,e){n(this,"formatter");this.formatter=new Intl.NumberFormat(t,e)}render(t,e,s){if((e==null?void 0:e.value)==null||e.value===""){t.textContent="";return}const i=Number(e.value);if(isNaN(i)){t.textContent=String(e.value);return}t.textContent=this.formatter.format(i),t.style.textAlign="right"}}class Q{render(t,e,s){if((e==null?void 0:e.value)==null){t.textContent="";return}const i=Math.max(0,Math.min(100,Number(e.value)));if(isNaN(i)){t.textContent="";return}const o=i>=80?"#22c55e":i>=50?"#f59e0b":i>=25?"#f97316":"#ef4444";t.innerHTML=`<div class="wt-progress">
|
|
6
|
+
<div class="wt-progress-bar" style="width:${i}%;background:${o}"></div>
|
|
7
|
+
<span class="wt-progress-label">${Math.round(i)}%</span>
|
|
8
|
+
</div>`}}class ee{render(t,e,s){t.textContent=""}}class te{constructor(){n(this,"renderers",new Map);n(this,"defaultRenderer");this.defaultRenderer=new K,this.renderers.set("text",this.defaultRenderer),this.renderers.set("blank",new ee),this.renderers.set("checkbox",new j),this.renderers.set("badge",new J),this.renderers.set("number",new Z),this.renderers.set("progress",new Q)}register(t,e){this.renderers.set(t,e)}get(t){return this.renderers.get(t)}getAll(){return this.renderers}}class pe{constructor(t){n(this,"editors",new Map);n(this,"activeEditor",null);n(this,"activeEditorEl",null);n(this,"activeRow",-1);n(this,"activeCol",-1);n(this,"overlayEl");n(this,"onClose",null);n(this,"handleEditorKey",t=>{switch(t.key){case"Enter":t.shiftKey||(t.preventDefault(),t.stopPropagation(),this.close(!0));break;case"Escape":t.preventDefault(),t.stopPropagation(),this.close(!1);break;case"Tab":t.preventDefault(),t.stopPropagation(),this.close(!0);break}});this.overlayEl=document.createElement("div"),this.overlayEl.className="wt-editor-overlay",this.overlayEl.style.display="none",t.appendChild(this.overlayEl),this.register("text",()=>new we),this.register("blank",()=>new me)}register(t,e){this.editors.set(t,e)}get isEditing(){return this.activeEditor!==null}get editingCell(){return this.activeEditor?{row:this.activeRow,col:this.activeCol}:null}open(t,e,s,i,o,l,r){this.close(!1);const c=this.editors.get(s);if(!c)return;this.activeRow=t,this.activeCol=e,this.activeEditor=c(),this.overlayEl.style.display="",this.overlayEl.style.left=`${o.x}px`,this.overlayEl.style.top=`${o.y}px`,this.overlayEl.style.width=`${o.width}px`,this.overlayEl.style.height=`${o.height}px`,this.activeEditorEl=this.activeEditor.createElement(this.overlayEl);const h=r!==void 0?r:i;this.activeEditor.open(h,o,l),this.activeEditorEl.addEventListener("keydown",this.handleEditorKey)}close(t){var l;if(!this.activeEditor)return;const e=this.activeEditor,s=this.activeRow,i=this.activeCol;let o;t&&(o=e.getValue(),e.validate&&e.validate(o)!==!0)||(this.activeEditorEl&&(this.activeEditorEl.removeEventListener("keydown",this.handleEditorKey),this.activeEditorEl=null),e.close(),this.overlayEl.innerHTML="",this.overlayEl.style.display="none",this.activeEditor=null,this.activeRow=-1,this.activeCol=-1,(l=this.onClose)==null||l.call(this,s,i,t?o:void 0,!t))}destroy(){this.close(!1),this.overlayEl.remove()}}class we{constructor(){n(this,"input")}createElement(t){return this.input=document.createElement("input"),this.input.type="text",this.input.className="wt-editor-input",t.appendChild(this.input),this.input}open(t,e,s){this.input.value=t!=null?String(t):"",requestAnimationFrame(()=>{this.input.focus(),this.input.select()})}getValue(){return this.input.value}close(){this.input.remove()}}class me{constructor(){n(this,"el")}createElement(t){return this.el=document.createElement("div"),t.appendChild(this.el),this.el}open(){}getValue(){}close(){var t;(t=this.el)==null||t.remove()}}class Ce{constructor(t,e){n(this,"selection");n(this,"callbacks");this.selection=t,this.callbacks=e}handleKeyDown(t){const e=t.ctrlKey||t.metaKey,s=t.shiftKey,i=this.selection.focus;switch(t.key){case"ArrowUp":t.preventDefault(),this.selection.move(-1,0,s),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"ArrowDown":t.preventDefault(),this.selection.move(1,0,s),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"ArrowLeft":t.preventDefault(),this.selection.move(0,-1,s),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"ArrowRight":t.preventDefault(),this.selection.move(0,1,s),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"Tab":t.preventDefault(),this.selection.move(0,s?-1:1,!1),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"Enter":t.preventDefault(),i&&this.callbacks.onStartEdit(i.row,i.col);break;case"F2":t.preventDefault(),i&&this.callbacks.onStartEdit(i.row,i.col);break;case"Delete":case"Backspace":t.preventDefault(),this.callbacks.onDelete();break;case"Escape":t.preventDefault(),this.selection.clear();break;case"Home":t.preventDefault(),e?this.selection.focusCell(0,0):i&&this.selection.focusCell(i.row,0),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"End":t.preventDefault(),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"a":e?(t.preventDefault(),this.selection.selectAll()):this.handleCharInput(t);break;case"c":e?(t.preventDefault(),this.callbacks.onCopy()):this.handleCharInput(t);break;case"v":e?(t.preventDefault(),this.callbacks.onPaste()):this.handleCharInput(t);break;case"x":e?(t.preventDefault(),this.callbacks.onCut()):this.handleCharInput(t);break;case"z":e?(t.preventDefault(),s?this.callbacks.onRedo():this.callbacks.onUndo()):this.handleCharInput(t);break;case"y":e?(t.preventDefault(),this.callbacks.onRedo()):this.handleCharInput(t);break;default:!e&&!t.altKey&&t.key.length===1&&this.handleCharInput(t);break}}handleCharInput(t){if(t.ctrlKey||t.metaKey||t.altKey)return;const e=this.selection.focus;e&&(t.preventDefault(),this.callbacks.onStartEdit(e.row,e.col,t.key))}}class ye{constructor(t,e){n(this,"data");n(this,"selection");n(this,"onChange",null);this.data=t,this.selection=e}async copy(){const t=this.selectionToTSV();if(t)try{await navigator.clipboard.writeText(t)}catch{this.fallbackCopy(t)}}async cut(){await this.copy(),this.deleteSelected()}async paste(){var l;const t=this.selection.focus;if(!t)return;let e;try{e=await navigator.clipboard.readText()}catch{return}const s=this.parseTSV(e);if(s.length===0)return;const i=s.length===1&&s[0].length===1,o=[];if(i&&!this.isFullRowOrColSelected()){const r=s[0][0];this.selection.forEachSelected((c,h)=>{c<this.data.rowCount&&h<this.data.colCount&&o.push({row:c,col:h,data:{value:r}})})}else for(let r=0;r<s.length;r++)for(let c=0;c<s[r].length;c++){const h=t.row+r,d=t.col+c;h>=this.data.rowCount||d>=this.data.colCount||o.push({row:h,col:d,data:{value:s[r][c]}})}o.length>0&&(this.data.applyPatch(o),(l=this.onChange)==null||l.call(this,o))}isFullRowOrColSelected(){const t=this.selection.getBounds();if(!t)return!1;const e=t.c1===0&&t.c2===this.data.colCount-1,s=t.r1===0&&t.r2===this.data.rowCount-1;return e||s}deleteSelected(){var e;const t=[];this.selection.forEachSelected((s,i)=>{this.data.hasCell(s,i)&&t.push({row:s,col:i,data:{value:void 0}})}),t.length>0&&(this.data.applyPatch(t),(e=this.onChange)==null||e.call(this,t))}selectionToTSV(){const t=this.selection.getBounds();if(!t)return null;const e=[];for(let s=t.r1;s<=t.r2;s++){const i=[];for(let o=t.c1;o<=t.c2;o++){const l=this.data.getCell(s,o),r=l==null?void 0:l.value;i.push(r!=null?String(r):"")}e.push(i.join(" "))}return e.join(`
|
|
9
|
+
`)}parseTSV(t){return t.split(`
|
|
10
|
+
`).map(e=>e.split(" "))}fallbackCopy(t){const e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.left="-9999px",document.body.appendChild(e),e.select(),document.execCommand("copy"),e.remove()}}class ve{constructor(t){n(this,"columns");n(this,"resizing",!1);n(this,"resizeCol",-1);n(this,"startX",0);n(this,"startWidth",0);n(this,"onResize",null);n(this,"handleMove",t=>{var i;if(!this.resizing)return;const e=t.clientX-this.startX,s=Math.max(30,this.startWidth+e);this.columns.setWidth(this.resizeCol,s),(i=this.onResize)==null||i.call(this,this.resizeCol,s)});n(this,"handleUp",()=>{this.resizing=!1,document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp),document.body.style.cursor="",document.body.style.userSelect=""});this.columns=t}start(t,e){t<0||t>=this.columns.count||(this.resizing=!0,this.resizeCol=t,this.startX=e,this.startWidth=this.columns.getWidth(t),document.addEventListener("mousemove",this.handleMove),document.addEventListener("mouseup",this.handleUp),document.body.style.cursor="col-resize",document.body.style.userSelect="none")}destroy(){document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp)}}class Ee{constructor(t){n(this,"rows");n(this,"resizing",!1);n(this,"resizeRow",-1);n(this,"startY",0);n(this,"startHeight",0);n(this,"onResize",null);n(this,"handleMove",t=>{var i;if(!this.resizing)return;const e=t.clientY-this.startY,s=Math.max(20,this.startHeight+e);this.rows.setHeight(this.resizeRow,s),(i=this.onResize)==null||i.call(this,this.resizeRow,s)});n(this,"handleUp",()=>{this.resizing=!1,document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp),document.body.style.cursor="",document.body.style.userSelect=""});this.rows=t}start(t,e){this.resizing=!0,this.resizeRow=t,this.startY=e,this.startHeight=this.rows.getHeight(t),document.addEventListener("mousemove",this.handleMove),document.addEventListener("mouseup",this.handleUp),document.body.style.cursor="row-resize",document.body.style.userSelect="none"}destroy(){document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp)}}class se{constructor(){n(this,"el",null);n(this,"closeHandler",t=>{this.el&&!this.el.contains(t.target)&&this.close()});n(this,"keyHandler",t=>{t.key==="Escape"&&this.close()})}open(t,e,s,i){this.close(),this.el=document.createElement("div"),this.el.className="wt-context-menu";for(const l of s){if(!(typeof l.visible=="function"?l.visible(i):l.visible??!0))continue;if(l.separator){const a=document.createElement("div");a.className="wt-context-menu-separator",this.el.appendChild(a);continue}const c=typeof l.disabled=="function"?l.disabled(i):l.disabled??!1,h=document.createElement("div");h.className="wt-context-menu-item",c&&h.classList.add("wt-context-menu-item--disabled");const d=document.createElement("span");if(d.textContent=l.label,h.appendChild(d),l.shortcut){const a=document.createElement("span");a.className="wt-context-menu-shortcut",a.textContent=l.shortcut,h.appendChild(a)}if(!c&&l.action){const a=l.action;h.addEventListener("click",u=>{u.stopPropagation(),this.close(),a(i)})}this.el.appendChild(h)}document.body.appendChild(this.el);const o=this.el.getBoundingClientRect();t+o.width>window.innerWidth&&(t=window.innerWidth-o.width-4),e+o.height>window.innerHeight&&(e=window.innerHeight-o.height-4),this.el.style.left=`${Math.max(0,t)}px`,this.el.style.top=`${Math.max(0,e)}px`,requestAnimationFrame(()=>{document.addEventListener("mousedown",this.closeHandler),document.addEventListener("keydown",this.keyHandler)})}close(){this.el&&(this.el.remove(),this.el=null),document.removeEventListener("mousedown",this.closeHandler),document.removeEventListener("keydown",this.keyHandler)}get isOpen(){return this.el!==null}destroy(){this.close()}}class be{constructor(t,e,s,i,o){n(this,"handleEl");n(this,"shadowEl");n(this,"dragging",!1);n(this,"currentRow",-1);n(this,"currentCol",-1);n(this,"data");n(this,"selection");n(this,"getCellAtPoint",null);n(this,"getCellBounds",null);n(this,"onFill",null);n(this,"onFillCallback",null);n(this,"enabled",!0);n(this,"onMouseDown",t=>{t.preventDefault(),t.stopPropagation();const e=this.selection.getBounds();e&&(this.dragging=!0,this.currentRow=e.r2,this.currentCol=e.c2,document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp),document.body.style.cursor="crosshair",document.body.style.userSelect="none")});n(this,"onMouseMove",t=>{if(!this.dragging||!this.getCellAtPoint)return;const e=this.getCellAtPoint(t.clientX,t.clientY);e&&(this.currentRow=e.row,this.currentCol=e.col,this.updateShadow())});n(this,"onMouseUp",()=>{this.dragging&&(this.dragging=!1,document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.body.style.cursor="",document.body.style.userSelect="",this.shadowEl.style.display="none",this.executeFill(),this.updatePosition())});this.data=e,this.selection=s,this.handleEl=document.createElement("div"),this.handleEl.className="wt-fill-handle",this.handleEl.style.display="none",t.appendChild(this.handleEl),this.shadowEl=document.createElement("div"),this.shadowEl.className="wt-fill-shadow",this.shadowEl.style.display="none",t.appendChild(this.shadowEl),this.handleEl.addEventListener("mousedown",this.onMouseDown)}updatePosition(){const t=this.selection.getBounds();if(!this.enabled||!t||!this.getCellBounds){this.handleEl.style.display="none";return}const e=this.getCellBounds(t.r2,t.c2);this.handleEl.style.display="",this.handleEl.style.left=`${e.x+e.width-4}px`,this.handleEl.style.top=`${e.y+e.height-4}px`}updateShadow(){const t=this.selection.getBounds();if(!t||!this.getCellBounds){this.shadowEl.style.display="none";return}const{r1:e,c1:s,r2:i,c2:o}=t,l=this.currentRow,r=this.currentCol;if(l>=e&&l<=i&&r>=s&&r<=o){this.shadowEl.style.display="none",this.updatePosition();return}const c=Math.min(e,l),h=Math.max(i,l),d=Math.min(s,r),a=Math.max(o,r),u=this.getCellBounds(c,d),f=this.getCellBounds(h,a),m=u.x,y=u.y,b=f.x+f.width-m,R=f.y+f.height-y;this.shadowEl.style.display="",this.shadowEl.style.left=`${m}px`,this.shadowEl.style.top=`${y}px`,this.shadowEl.style.width=`${b}px`,this.shadowEl.style.height=`${R}px`;const E=this.getCellBounds(l,r);this.handleEl.style.left=`${E.x+E.width-4}px`,this.handleEl.style.top=`${E.y+E.height-4}px`}executeFill(){var m,y;const t=this.selection.getBounds();if(!t)return;const{r1:e,c1:s,r2:i,c2:o}=t,l=this.currentRow,r=this.currentCol;if(l>=e&&l<=i&&r>=s&&r<=o)return;const c=l>i?l-i:l<e?e-l:0,h=r>o?r-o:r<s?s-r:0;let d,a;c>0&&h>0?(d="diagonal",a={startRow:Math.min(e,l),startCol:Math.min(s,r),endRow:Math.max(i,l),endCol:Math.max(o,r)}):c>0&&h===0?l>i?(d="down",a={startRow:i+1,startCol:s,endRow:l,endCol:o}):(d="up",a={startRow:l,startCol:s,endRow:e-1,endCol:o}):h>0&&c===0?r>o?(d="right",a={startRow:e,startCol:o+1,endRow:i,endCol:r}):(d="left",a={startRow:e,startCol:r,endRow:i,endCol:s-1}):(d="diagonal",a={startRow:Math.min(e,l),startCol:Math.min(s,r),endRow:Math.max(i,l),endCol:Math.max(o,r)});const u={startRow:e,startCol:s,endRow:i,endCol:o};if(this.onFillCallback){const b=this.onFillCallback(u,a,d);if(b===!0)return;if(Array.isArray(b)){(m=this.onFill)==null||m.call(this,b,u,a,d);return}}const f=this.defaultFill(u,a,d);(y=this.onFill)==null||y.call(this,f,u,a,d)}defaultFill(t,e,s){const i=[],o=t.endRow-t.startRow+1,l=t.endCol-t.startCol+1;for(let r=e.startRow;r<=e.endRow;r++)for(let c=e.startCol;c<=e.endCol;c++){if(r>=t.startRow&&r<=t.endRow&&c>=t.startCol&&c<=t.endCol)continue;const h=t.startRow+((r-t.startRow)%o+o)%o,d=t.startCol+((c-t.startCol)%l+l)%l,a=this.data.getCell(h,d);i.push({row:r,col:c,data:{value:a==null?void 0:a.value}})}return i}destroy(){this.handleEl.remove(),this.shadowEl.remove(),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp)}}class Re{constructor(t){n(this,"columns");n(this,"dragging",!1);n(this,"sourceCol",-1);n(this,"targetCol",-1);n(this,"ghostEl",null);n(this,"indicatorEl",null);n(this,"onReorder",null);n(this,"getColAtX",null);n(this,"getColLabel",null);n(this,"onMouseMove",t=>{if(this.dragging&&(this.ghostEl&&(this.ghostEl.style.left=`${t.clientX}px`,this.ghostEl.style.top=`${t.clientY-14}px`),this.getColAtX&&(this.targetCol=this.getColAtX(t.clientX)),this.indicatorEl&&this.targetCol>=0)){const e=this.columns.getX(this.targetCol);this.indicatorEl.style.display="",this.indicatorEl.style.left=`${e}px`}});n(this,"onMouseUp",()=>{var t,e,s;this.dragging&&(this.dragging=!1,document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.body.style.cursor="",document.body.style.userSelect="",(t=this.ghostEl)==null||t.remove(),this.ghostEl=null,(e=this.indicatorEl)==null||e.remove(),this.indicatorEl=null,this.sourceCol!==this.targetCol&&this.targetCol>=0&&((s=this.onReorder)==null||s.call(this,this.sourceCol,this.targetCol)))});this.columns=t}start(t,e,s){var i;this.dragging=!0,this.sourceCol=t,this.targetCol=t,this.ghostEl=document.createElement("div"),this.ghostEl.className="wt-reorder-ghost",this.ghostEl.textContent=((i=this.getColLabel)==null?void 0:i.call(this,t))??String(t),this.ghostEl.style.left=`${e.clientX}px`,this.ghostEl.style.top=`${e.clientY-14}px`,document.body.appendChild(this.ghostEl),this.indicatorEl=document.createElement("div"),this.indicatorEl.className="wt-reorder-indicator",this.indicatorEl.style.display="none",s.appendChild(this.indicatorEl),document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp),document.body.style.cursor="grabbing",document.body.style.userSelect="none"}destroy(){var t,e;(t=this.ghostEl)==null||t.remove(),(e=this.indicatorEl)==null||e.remove(),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp)}}class ie{constructor(t){n(this,"groups",[]);n(this,"hiddenRows",new Set);n(this,"onChange",null);t&&(this.groups=t.map(e=>({...e})),this.rebuildHidden())}addGroup(t){var e;this.groups.push({...t}),this.rebuildHidden(),(e=this.onChange)==null||e.call(this)}removeGroup(t){var e;this.groups=this.groups.filter(s=>s.startRow!==t),this.rebuildHidden(),(e=this.onChange)==null||e.call(this)}toggleGroup(t){var s;const e=this.groups.find(i=>i.startRow===t);e&&(e.expanded=!e.expanded,this.rebuildHidden(),(s=this.onChange)==null||s.call(this))}expandAll(){var t;for(const e of this.groups)e.expanded=!0;this.rebuildHidden(),(t=this.onChange)==null||t.call(this)}collapseAll(){var t;for(const e of this.groups)e.expanded=!1;this.rebuildHidden(),(t=this.onChange)==null||t.call(this)}isGroupHeader(t){return this.groups.find(e=>e.startRow===t)??null}isHidden(t){return this.hiddenRows.has(t)}getGroups(){return[...this.groups]}rebuildHidden(){this.hiddenRows.clear();for(const t of this.groups)if(!t.expanded)for(let e=1;e<=t.count;e++)this.hiddenRows.add(t.startRow+e)}getFilter(){return t=>!this.hiddenRows.has(t)}clear(){var t;this.groups=[],this.hiddenRows.clear(),(t=this.onChange)==null||t.call(this)}}class oe{constructor(t){n(this,"mapping",[]);n(this,"identity",!0);n(this,"sortState",null);n(this,"filters",new Map);n(this,"data");n(this,"onChange",null);this.data=t,this.rebuild()}get visibleRowCount(){return this.identity?this.data.rowCount:this.mapping.length}toDataRow(t){return this.identity?t:this.mapping[t]??t}toVisualRow(t){return this.identity?t:this.mapping.indexOf(t)}sort(t,e,s){var i;e===null?this.sortState=null:this.sortState={col:t,direction:e,compareFn:s},this.rebuild(),(i=this.onChange)==null||i.call(this)}getSortState(){return this.sortState}clearSort(){var t;this.sortState=null,this.rebuild(),(t=this.onChange)==null||t.call(this)}setFilter(t,e){var s;this.filters.set(t,e),this.rebuild(),(s=this.onChange)==null||s.call(this)}removeFilter(t){var e;this.filters.delete(t),this.rebuild(),(e=this.onChange)==null||e.call(this)}clearFilters(){var t;this.filters.clear(),this.rebuild(),(t=this.onChange)==null||t.call(this)}getActiveFilters(){return Array.from(this.filters.keys())}rebuild(){const t=this.sortState!==null,e=this.filters.size>0;if(!t&&!e){this.identity=!0,this.mapping=[];return}this.identity=!1;let s=[];for(let i=0;i<this.data.rowCount;i++)s.push(i);if(e&&(s=s.filter(i=>{for(const o of this.filters.values())if(!o(i,this.data))return!1;return!0})),t&&this.sortState){const{col:i,direction:o,compareFn:l}=this.sortState,r=o==="desc"?-1:1;s.sort((c,h)=>{var u,f;const d=(u=this.data.getCell(c,i))==null?void 0:u.value,a=(f=this.data.getCell(h,i))==null?void 0:f.value;return l?l(d,a)*r:xe(d,a)*r})}this.mapping=s}}function xe(g,t){return g==null&&t==null?0:g==null?1:t==null?-1:typeof g=="number"&&typeof t=="number"?g-t:typeof g=="boolean"&&typeof t=="boolean"?g===t?0:g?-1:1:String(g).localeCompare(String(t),void 0,{numeric:!0,sensitivity:"base"})}class ne{constructor(t){n(this,"merges",[]);n(this,"coverMap",new Map);n(this,"onChange",null);if(t)for(const e of t)this.addMerge(e,!1)}key(t,e){return`${t}:${e}`}addMerge(t,e=!0){var s;if(!(t.rowSpan<1||t.colSpan<1)&&!(t.rowSpan===1&&t.colSpan===1)){for(let i=t.row;i<t.row+t.rowSpan;i++)for(let o=t.col;o<t.col+t.colSpan;o++)if(this.coverMap.has(this.key(i,o))){const l=this.coverMap.get(this.key(i,o));this.removeMerge(l.row,l.col,!1)}this.merges.push(t);for(let i=t.row;i<t.row+t.rowSpan;i++)for(let o=t.col;o<t.col+t.colSpan;o++)this.coverMap.set(this.key(i,o),t);e&&((s=this.onChange)==null||s.call(this))}}removeMerge(t,e,s=!0){var l;const i=this.merges.findIndex(r=>r.row===t&&r.col===e);if(i===-1)return!1;const o=this.merges[i];this.merges.splice(i,1);for(let r=o.row;r<o.row+o.rowSpan;r++)for(let c=o.col;c<o.col+o.colSpan;c++)this.coverMap.delete(this.key(r,c));return s&&((l=this.onChange)==null||l.call(this)),!0}getMerge(t,e){return this.coverMap.get(this.key(t,e))??null}isAnchor(t,e){const s=this.coverMap.get(this.key(t,e));return s!==void 0&&s.row===t&&s.col===e}isHidden(t,e){const s=this.coverMap.get(this.key(t,e));return s!==void 0&&(s.row!==t||s.col!==e)}getAll(){return[...this.merges]}clear(){var t;this.merges.length=0,this.coverMap.clear(),(t=this.onChange)==null||t.call(this)}}class le{constructor(t){n(this,"_page");n(this,"_pageSize");n(this,"_totalRows");n(this,"enabled");n(this,"onChange",null);this.enabled=(t==null?void 0:t.enabled)??!1,this._pageSize=(t==null?void 0:t.pageSize)??50,this._page=(t==null?void 0:t.page)??0,this._totalRows=(t==null?void 0:t.totalRows)??0}get page(){return this._page}get pageSize(){return this._pageSize}get totalRows(){return this._totalRows}get totalPages(){return this._totalRows===0?0:Math.ceil(this._totalRows/this._pageSize)}get startRow(){return this._page*this._pageSize}get endRow(){return Math.min(this.startRow+this._pageSize,this._totalRows)}getState(){return{page:this._page,pageSize:this._pageSize,totalRows:this._totalRows,totalPages:this.totalPages,startRow:this.startRow,endRow:this.endRow}}setPage(t){var s;const e=Math.max(0,Math.min(t,this.totalPages-1));e!==this._page&&(this._page=e,(s=this.onChange)==null||s.call(this,this.getState()))}setPageSize(t){var e;this._pageSize=Math.max(1,t),this._page=Math.min(this._page,this.totalPages-1),this._page<0&&(this._page=0),(e=this.onChange)==null||e.call(this,this.getState())}setTotalRows(t){var e;this._totalRows=t,this._page>=this.totalPages&&(this._page=Math.max(0,this.totalPages-1)),(e=this.onChange)==null||e.call(this,this.getState())}nextPage(){this.setPage(this._page+1)}prevPage(){this.setPage(this._page-1)}firstPage(){this.setPage(0)}lastPage(){this.setPage(this.totalPages-1)}}function W(g){const t=[],e=re(g),s=[];for(let i=0;i<e;i++)s.push([]);return ae(g,0,t,s,e),{flatColumns:t,headerRows:s,maxDepth:e}}function re(g){let t=1;for(const e of g)e.children&&e.children.length>0&&(t=Math.max(t,1+re(e.children)));return t}function ae(g,t,e,s,i){for(const o of g)if(o.children&&o.children.length>0){const l=e.length;ae(o.children,t+1,e,s,i);const r=e.length-l;s[t].push({label:o.label??"",colSpan:r,rowSpan:1,col:l,level:t,config:o})}else{const l=e.length;e.push(o);const r=i-t;s[t].push({label:o.label??"",colSpan:1,rowSpan:r,col:l,level:t,config:o})}}class Se{constructor(t){n(this,"el");n(this,"infoEl");n(this,"prevBtn");n(this,"nextBtn");n(this,"firstBtn");n(this,"lastBtn");n(this,"pageInput");n(this,"clickHandler");n(this,"changeHandler");n(this,"onPageChange",null);this.el=document.createElement("div"),this.el.className="wt-pagination",this.infoEl=document.createElement("span"),this.infoEl.className="wt-pagination-info",this.firstBtn=this.createBtn("first","«"),this.prevBtn=this.createBtn("prev","‹"),this.pageInput=document.createElement("input"),this.pageInput.type="number",this.pageInput.className="wt-pagination-input",this.pageInput.min="1",this.nextBtn=this.createBtn("next","›"),this.lastBtn=this.createBtn("last","»"),this.el.appendChild(this.infoEl),this.el.appendChild(this.firstBtn),this.el.appendChild(this.prevBtn),this.el.appendChild(this.pageInput),this.el.appendChild(this.nextBtn),this.el.appendChild(this.lastBtn),this.clickHandler=e=>{var o,l,r,c;const s=e.target.closest(".wt-pagination-btn");if(!s)return;const i=s.dataset.action;i==="first"?(o=this.onPageChange)==null||o.call(this,0):i==="prev"?(l=this.onPageChange)==null||l.call(this,-1):i==="next"?(r=this.onPageChange)==null||r.call(this,-2):i==="last"&&((c=this.onPageChange)==null||c.call(this,-3))},this.el.addEventListener("click",this.clickHandler),this.changeHandler=()=>{var s;const e=parseInt(this.pageInput.value,10)-1;isNaN(e)||(s=this.onPageChange)==null||s.call(this,e)},this.pageInput.addEventListener("change",this.changeHandler),t.appendChild(this.el)}update(t){this.infoEl.textContent=`${t.startRow+1}-${t.endRow} of ${t.totalRows}`,this.pageInput.value=String(t.page+1),this.pageInput.max=String(t.totalPages),this.prevBtn.disabled=t.page<=0,this.firstBtn.disabled=t.page<=0,this.nextBtn.disabled=t.page>=t.totalPages-1,this.lastBtn.disabled=t.page>=t.totalPages-1}show(){this.el.style.display=""}hide(){this.el.style.display="none"}destroy(){this.el.removeEventListener("click",this.clickHandler),this.pageInput.removeEventListener("change",this.changeHandler),this.el.remove()}createBtn(t,e){const s=document.createElement("button");return s.className="wt-pagination-btn",s.dataset.action=t,s.textContent=e,s}}class Me{constructor(t){n(this,"el");this.el=document.createElement("div"),this.el.className="wt-loading-overlay",this.el.innerHTML='<div class="wt-loading-spinner"></div>',this.el.style.display="none",t.appendChild(this.el)}show(){this.el.style.display=""}hide(){this.el.style.display="none"}get isVisible(){return this.el.style.display!=="none"}destroy(){this.el.remove()}}function he(g,t,e={}){const{visibleOnly:s=!0,columns:i,includeHeaders:o=!0,headers:l}=e,r=i??Array.from({length:g.colCount},(d,a)=>a),c=[];if(o){const d=r.map((a,u)=>{const f=(l==null?void 0:l[u])??z(a);return de(f)});c.push(d.join(","))}const h=s?t.visibleRowCount:g.rowCount;for(let d=0;d<h;d++){const a=s?t.toDataRow(d):d,u=r.map(f=>{const m=g.getCell(a,f),y=m==null?void 0:m.value;return de(y!=null?String(y):"")});c.push(u.join(","))}return c.join(`
|
|
11
|
+
`)}function ce(g,t,e={}){const{visibleOnly:s=!0,columns:i,headers:o}=e,l=i??Array.from({length:g.colCount},(h,d)=>d),r=s?t.visibleRowCount:g.rowCount,c=[];for(let h=0;h<r;h++){const d=s?t.toDataRow(h):h,a={};for(let u=0;u<l.length;u++){const f=l[u],m=(o==null?void 0:o[u])??z(f),y=g.getCell(d,f);a[m]=(y==null?void 0:y.value)??null}c.push(a)}return c}function O(g,t,e){const s=new Blob([g],{type:e}),i=URL.createObjectURL(s),o=document.createElement("a");o.href=i,o.download=t,o.click(),URL.revokeObjectURL(i)}function de(g){return g.includes(",")||g.includes('"')||g.includes(`
|
|
12
|
+
`)?`"${g.replace(/"/g,'""')}"`:g}class He extends V{constructor(e,s={}){var h,d;super();n(this,"data");n(this,"selection");n(this,"columns");n(this,"rows");n(this,"commands");n(this,"viewMapping");n(this,"merges");n(this,"pagination");n(this,"rowGroups");n(this,"renderer");n(this,"rendererRegistry");n(this,"editorManager");n(this,"keyboard");n(this,"clipboard");n(this,"columnResize");n(this,"rowResize");n(this,"contextMenu");n(this,"autoFit");n(this,"paginationBar",null);n(this,"loadingOverlay");n(this,"fillHandle");n(this,"columnReorder");n(this,"headerRows",[]);n(this,"theme");n(this,"options");n(this,"isDragging",!1);n(this,"_infiniteScrollHandler",null);n(this,"_lazyLoadHandler",null);n(this,"_keydownHandler",null);n(this,"contextMenuItems",[{label:"Copy",shortcut:"Ctrl+C",visible:e=>e.target==="cell",action:()=>this.clipboard.copy()},{label:"Paste",shortcut:"Ctrl+V",visible:e=>e.target==="cell",disabled:e=>e.readOnly,action:()=>this.pasteWithUndo()},{label:"Cut",shortcut:"Ctrl+X",visible:e=>e.target==="cell",disabled:e=>e.readOnly,action:()=>this.cutWithUndo()},{label:"",separator:!0,visible:e=>e.target==="cell"},{label:"Delete content",shortcut:"Del",visible:e=>e.target==="cell"&&e.selectedCount>0,disabled:e=>e.readOnly,action:()=>this.deleteSelected()},{label:"",separator:!0,visible:e=>e.target==="cell"},{label:"Insert row above",visible:e=>e.target==="cell"||e.target==="row-header",disabled:e=>e.readOnly,action:e=>this.insertRow(e.row)},{label:"Insert row below",visible:e=>e.target==="cell"||e.target==="row-header",disabled:e=>e.readOnly,action:e=>this.insertRow(e.row+1)},{label:"Insert column left",visible:e=>e.target==="cell"&&!e.isMultiSelect||e.target==="column-header",disabled:e=>e.readOnly,action:e=>this.insertColumn(e.col)},{label:"Insert column right",visible:e=>e.target==="cell"&&!e.isMultiSelect||e.target==="column-header",disabled:e=>e.readOnly,action:e=>this.insertColumn(e.col+1)},{label:"",separator:!0,visible:e=>e.target==="column-header"},{label:"Sort ascending",visible:e=>e.target==="column-header",action:e=>this.sort(e.col,"asc")},{label:"Sort descending",visible:e=>e.target==="column-header",action:e=>this.sort(e.col,"desc")},{label:"Clear sort",visible:e=>e.target==="column-header"&&this.viewMapping.getSortState()!==null,action:()=>this.clearSort()},{label:"",separator:!0,visible:e=>e.target==="column-header"},{label:"Auto-fit column width",visible:e=>e.target==="column-header"||e.target==="cell",action:e=>this.autoFitColumn(e.col>=0?e.col:0)},{label:"",separator:!0,visible:e=>e.target==="row-header"},{label:"Select row",visible:e=>e.target==="row-header",action:e=>this.selection.selectRow(e.row)},{label:"",separator:!0},{label:"Undo",shortcut:"Ctrl+Z",disabled:e=>!e.canUndo,action:()=>this.undo()},{label:"Redo",shortcut:"Ctrl+Y",disabled:e=>!e.canRedo,action:()=>this.redo()}]);this.options=s;const i=s.defaultRowHeight??28,o=s.defaultColWidth??100;let l=s.columns??[];if(l.some(a=>a.children&&a.children.length>0)){const a=W(l);l=a.flatColumns,this.headerRows=a.headerRows}const r=s.colCount??(l.length||26);let c;if(s.mode==="table"&&s.tableData?c=s.tableData.length:c=s.rowCount??100,this.theme={...x,...s.theme},this.data=new B(c,r),this.selection=new U(c,r),s.infinite&&(this.selection.infinite=!0),this.columns=new D(r,o,l),this.rows=new G(c,i),this.commands=new X(s.undoLimit??100),this.viewMapping=new oe(this.data),this.merges=new ne,this.pagination=new le(s.pagination),this.rowGroups=new ie((h=s.rowGroups)==null?void 0:h.map(a=>({...a,expanded:a.expanded??!0,depth:a.depth??0}))),this.rendererRegistry=new te,this.renderer=new ue(e),this.editorManager=new pe(this.renderer.getScrollContainer()),this.columnResize=new ve(this.columns),this.columnReorder=new Re(this.columns),this.rowResize=new Ee(this.rows),this.contextMenu=new se,this.clipboard=new ye(this.data,this.selection),this.fillHandle=new be(this.renderer.getViewportEl(),this.data,this.selection,this.columns,this.rows),this.keyboard=new Ce(this.selection,{onStartEdit:(a,u,f)=>{this.options.allowEditing!==!1&&this.startEditing(a,u,f)},onDelete:()=>this.deleteSelected(),onCopy:()=>{this.options.allowClipboard!==!1&&this.clipboard.copy()},onPaste:()=>{this.options.allowClipboard!==!1&&this.pasteWithUndo()},onCut:()=>{this.options.allowClipboard!==!1&&this.cutWithUndo()},onUndo:()=>{this.options.allowUndoRedo!==!1&&this.undo()},onRedo:()=>{this.options.allowUndoRedo!==!1&&this.redo()},onScrollTo:(a,u)=>this.renderer.scrollToCell(a,u)}),this.wireCallbacks(),this.renderer.init({data:this.data,columns:this.columns,rows:this.rows,selection:this.selection,viewMapping:this.viewMapping,merges:this.merges,theme:this.theme,renderers:this.rendererRegistry.getAll(),defaultRenderer:this.rendererRegistry.defaultRenderer,defaultCellType:s.defaultCellType??"text",showRowHeaders:s.showRowHeaders??!0,showColHeaders:s.showColHeaders??!0,frozenRows:s.frozenRows??0,frozenCols:s.frozenCols??0,autoRowHeight:s.autoRowHeight??!1,showGridLines:s.showGridLines??!0,showBorder:s.showBorder??!0,layout:s.layout??"scroll",headerRows:this.headerRows.length>0?this.headerRows:void 0}),this.autoFit=new fe(e,this.data,this.columns,this.rows,this.rendererRegistry.getAll(),this.rendererRegistry.defaultRenderer),this.fillHandle.getCellBounds=(a,u)=>({x:this.columns.getX(u),y:this.rows.getY(a),width:this.columns.getWidth(u),height:this.rows.getHeight(a)}),this.fillHandle.getCellAtPoint=(a,u)=>{const f=this.renderer.getScrollContainer(),m=f.getBoundingClientRect(),y=f.scrollLeft,b=f.scrollTop,R=a-m.left+y,E=u-m.top+b,I=this.rows.getRowAtY(E),P=this.columns.getColAtX(R);return I>=0&&P>=0?{row:I,col:P}:null},this.fillHandle.enabled=s.allowFillHandle!==!1,this.fillHandle.onFillCallback=s.onFill??null,this.fillHandle.onFill=(a,u,f)=>{if(a.length>0){const m=new $(this.data,a);this.execCommand(m),this.emit("data:patch",{patches:a})}this.selection.extendTo(f.endRow,f.endCol)},this.loadingOverlay=new Me(e),s.loading&&this.loadingOverlay.show(),(d=s.pagination)!=null&&d.enabled&&(this.paginationBar=new Se(e),this.pagination.setTotalRows(s.pagination.totalRows??c),this.paginationBar.update(this.pagination.getState()),this.paginationBar.onPageChange=a=>{a===-1?this.pagination.prevPage():a===-2?this.pagination.nextPage():a===-3?this.pagination.lastPage():this.pagination.setPage(a)},this.pagination.onChange=a=>{var u,f,m;(u=this.paginationBar)==null||u.update(a),(m=(f=this.options).onPageChange)==null||m.call(f,a.page,a.pageSize),this.renderer.scheduleRender()}),s.mode==="table"&&s.tableData?this.loadTableData(s.tableData,l):s.data&&this.data.applyPatch(s.data),s.merges)for(const a of s.merges)this.merges.addMerge(a,!1);if(s.sort&&this.viewMapping.sort(s.sort.col,s.sort.direction),s.filters)for(const[a,u]of Object.entries(s.filters))this.viewMapping.setFilter(Number(a),u);if(this.merges.onChange=()=>{this.renderer.scheduleRender()},this.viewMapping.onChange=()=>{this.renderer.updateLayout(),this.renderer.scheduleRender()},s.infinite)if(s.layout==="auto")this._infiniteScrollHandler=()=>{let f=!1;const m=document.documentElement.scrollHeight,y=document.documentElement.scrollWidth,b=window.scrollY+window.innerHeight,R=window.scrollX+window.innerWidth;m-b<200&&(this.data.rowCount+=20,this.rows.setCount(this.data.rowCount),this.viewMapping.rebuild(),f=!0),y-R<200&&(this.data.colCount+=20,this.columns.setCount(this.data.colCount),f=!0),f&&(this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.refresh())},window.addEventListener("scroll",this._infiniteScrollHandler,{passive:!0});else{const f=this.renderer.getScrollContainer();this._infiniteScrollHandler=()=>{f.scrollTop+f.clientHeight>=f.scrollHeight-200&&(this.data.rowCount+=20,this.rows.setCount(this.data.rowCount),this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.viewMapping.rebuild(),this.refresh()),f.scrollLeft+f.clientWidth>=f.scrollWidth-200&&(this.data.colCount+=20,this.columns.setCount(this.data.colCount),this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.refresh())},f.addEventListener("scroll",this._infiniteScrollHandler,{passive:!0})}this.renderer.getContainer().focus()}wireCallbacks(){if(this.data.onChange=()=>{this.renderer.scheduleRender()},this.selection.onChange=()=>{var e,s;this.options.infinite&&this.selection.focus&&this.expandIfNeeded(this.selection.focus.row,this.selection.focus.col),this.renderer.scheduleRender(),this.fillHandle.updatePosition(),this.emit("selection:change",{ranges:this.selection.ranges}),(s=(e=this.options).onSelectionChange)==null||s.call(e,this.selection.ranges)},this.renderer.onCellClick=(e,s,i)=>{this.contextMenu.isOpen&&this.contextMenu.close(),this.editorManager.isEditing&&this.editorManager.close(!0);const o=this.data.getCell(e,s),l=this.columns.getConfig(s),r=this.options.defaultCellType??"text";if(((o==null?void 0:o.type)??(l==null?void 0:l.type)??r)==="checkbox"&&!this.options.readOnly&&this.options.allowEditing!==!1&&!(l!=null&&l.readOnly)&&!(o!=null&&o.readOnly)){const h=!!(o!=null&&o.value);this.setCellValue(e,s,!h),this.options.allowSelection!==!1&&this.selection.focusCell(e,s),this.emit("cell:click",{row:e,col:s,event:i});return}if(this.options.allowSelection!==!1&&(i.shiftKey&&this.options.allowRangeSelection!==!1?this.selection.extendTo(e,s):(i.ctrlKey||i.metaKey)&&this.options.allowRangeSelection!==!1?this.selection.addRange({startRow:e,startCol:s,endRow:e,endCol:s}):this.selection.focusCell(e,s)),this.emit("cell:click",{row:e,col:s,event:i}),this.options.allowRangeSelection!==!1&&this.options.allowSelection!==!1){this.isDragging=!0;const h=a=>{if(!this.isDragging)return;const u=this.renderer.getCellFromEvent(a);u&&this.selection.extendTo(u.row,u.col)},d=()=>{this.isDragging=!1,document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",d)};document.addEventListener("mousemove",h),document.addEventListener("mouseup",d)}},this.renderer.onCellDblClick=(e,s,i)=>{this.emit("cell:dblclick",{row:e,col:s,event:i}),!this.options.readOnly&&this.options.allowEditing!==!1&&this.startEditing(e,s)},this.renderer.onCellContextMenu=(e,s,i)=>{i.preventDefault(),this.emit("cell:contextmenu",{row:e,col:s,event:i}),this.options.allowContextMenu!==!1&&(this.options.allowSelection!==!1&&!this.selection.isSelected(e,s)&&this.selection.focusCell(e,s),this.openContextMenu(i.clientX,i.clientY,e,s))},this.renderer.onHeaderClick=(e,s,i)=>{if(e==="col")this.options.allowColReorder?this.columnReorder.start(s,i,this.renderer.getContainer()):this.selection.selectColumn(s);else if(e==="row"){const o=i.target.closest(".wt-row-header-cell");if(o){const l=o.getBoundingClientRect();if(i.clientY>l.bottom-4&&this.options.allowRowResize!==!1){this.rowResize.start(s,i.clientY);return}}this.selection.selectRow(s)}else e==="corner"&&this.selection.selectAll()},this.renderer.onColumnResizeStart=(e,s)=>{this.options.allowColResize!==!1&&this.columnResize.start(e,s)},this.columnResize.onResize=(e,s)=>{this.renderer.updateLayout(),this.renderer.scheduleRender(),this.emit("column:resize",{col:e,width:s})},this.rowResize.onResize=(e,s)=>{this.renderer.updateLayout(),this.renderer.scheduleRender(),this.emit("row:resize",{row:e,height:s})},this.renderer.onScroll=e=>{var s,i;this.emit("scroll",{viewport:e}),(i=(s=this.options).onScroll)==null||i.call(s,e)},this.editorManager.onClose=(e,s,i,o)=>{var l,r,c;if(!o&&i!==void 0){const h=(l=this.data.getCell(e,s))==null?void 0:l.value,d=new N(this.data,e,s,i);this.execCommand(d),this.emit("cell:change",{row:e,col:s,oldValue:h,newValue:i}),(c=(r=this.options).onCellChange)==null||c.call(r,e,s,h,i)}this.emit("editor:close",{row:e,col:s,value:i,cancelled:o}),this.renderer.getContainer().focus()},this._keydownHandler=e=>{this.options.allowKeyboardNav!==!1&&(this.editorManager.isEditing||this.keyboard.handleKeyDown(e))},this.renderer.getContainer().addEventListener("keydown",this._keydownHandler),this.renderer.onHeaderContextMenu=(e,s,i)=>{const o=e==="col"?"column-header":"row-header",l=e==="row"?s:-1,r=e==="col"?s:-1,c=this.buildMenuContext(l,r,o);this.contextMenu.open(i.clientX,i.clientY,this.contextMenuItems,c)},this.clipboard.onChange=e=>{this.emit("data:patch",{patches:e})},this.columnReorder.getColAtX=e=>{const s=this.renderer.getScrollContainer(),i=s.getBoundingClientRect();return this.columns.getColAtX(e-i.left+s.scrollLeft)},this.columnReorder.getColLabel=e=>{var s;return((s=this.columns.getConfig(e))==null?void 0:s.label)??D.columnLabel(e)},this.columnReorder.onReorder=(e,s)=>{this.reorderColumn(e,s)},this.rowGroups.onChange=()=>{const e=this.rowGroups.getFilter();this.viewMapping.setFilter(-1,s=>e(s))},this.options.rowGroups&&this.options.rowGroups.length>0){const e=this.rowGroups.getFilter();this.viewMapping.setFilter(-1,s=>e(s))}if(this.options.onLoadMore){const e=this.options.onLoadMore,s=200;if(this.options.layout==="auto")this._lazyLoadHandler=()=>{const i=document.documentElement.scrollHeight,o=window.scrollY+window.innerHeight;i-o<s&&e("down")},window.addEventListener("scroll",this._lazyLoadHandler,{passive:!0});else{const i=this.renderer.getScrollContainer();this._lazyLoadHandler=()=>{i.scrollTop+i.clientHeight>=i.scrollHeight-s&&e("down"),i.scrollLeft+i.clientWidth>=i.scrollWidth-s&&e("right")},i.addEventListener("scroll",this._lazyLoadHandler,{passive:!0})}}}buildMenuContext(e,s,i="cell"){const o=this.selection.getBounds();let l=0;return this.selection.forEachSelected(()=>{l++}),{target:i,row:e,col:s,selectedCount:l,isMultiSelect:l>1,isFullRow:o?o.c1===0&&o.c2===this.data.colCount-1:!1,isFullCol:o?o.r1===0&&o.r2===this.data.rowCount-1:!1,readOnly:!!this.options.readOnly,canUndo:this.commands.canUndo,canRedo:this.commands.canRedo}}openContextMenu(e,s,i,o){const l=this.buildMenuContext(i,o);this.contextMenu.open(e,s,this.contextMenuItems,l)}setCell(e,s,i){this.data.setCell(e,s,i)}getCell(e,s){return this.data.getCell(e,s)}setCellValue(e,s,i){var r;const o=(r=this.data.getCell(e,s))==null?void 0:r.value,l=new N(this.data,e,s,i);this.execCommand(l),this.emit("cell:change",{row:e,col:s,oldValue:o,newValue:i})}deleteCell(e,s){this.data.deleteCell(e,s)}applyPatch(e){const s=new $(this.data,e);this.execCommand(s),this.emit("data:patch",{patches:e})}transaction(e){this.data.transaction(e)}undo(){const e=this.commands.undo();if(e){const s=e.getChanges().map(i=>({row:i.row,col:i.col,oldValue:i.newValue,newValue:i.oldValue}));this.emit("command:undo",{changes:s})}}redo(){const e=this.commands.redo();e&&this.emit("command:redo",{changes:e.getChanges()})}getSelection(){return[...this.selection.ranges]}getSelectionInfo(){return this.selection.getInfo()}setSelection(e){if(e.length>0){this.selection.focusCell(e[0].startRow,e[0].startCol);for(let s=1;s<e.length;s++)this.selection.addRange(e[s])}}scrollTo(e,s){this.renderer.scrollToCell(e,s)}registerRenderer(e,s){this.rendererRegistry.register(e,s)}registerEditor(e,s){this.editorManager.register(e,s)}setColumnWidth(e,s){this.columns.setWidth(e,s),this.renderer.updateLayout(),this.renderer.scheduleRender()}setRowHeight(e,s){this.rows.setHeight(e,s),this.renderer.updateLayout(),this.renderer.scheduleRender()}autoFitColumn(e){const s=this.autoFit.autoFitColumn(e);this.columns.setWidth(e,s),this.renderer.updateLayout(),this.renderer.scheduleRender(),this.emit("column:resize",{col:e,width:s})}autoFitRow(e){const s=this.autoFit.autoFitRow(e);this.rows.setHeight(e,s),this.renderer.updateLayout(),this.renderer.scheduleRender(),this.emit("row:resize",{row:e,height:s})}insertRow(e){this.data.rowCount+=1,this.rows.setCount(this.data.rowCount),this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.data.transaction(()=>{for(let s=this.data.rowCount-1;s>e;s--)for(let i=0;i<this.data.colCount;i++){const o=this.data.getCell(s-1,i);o?this.data.setCell(s,i,{...o}):this.data.deleteCell(s,i)}for(let s=0;s<this.data.colCount;s++)this.data.deleteCell(e,s)}),this.renderer.updateLayout(),this.renderer.scheduleRender()}insertColumn(e){this.data.colCount+=1,this.columns.setCount(this.data.colCount),this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.data.transaction(()=>{for(let s=0;s<this.data.rowCount;s++){for(let i=this.data.colCount-1;i>e;i--){const o=this.data.getCell(s,i-1);o?this.data.setCell(s,i,{...o}):this.data.deleteCell(s,i)}this.data.deleteCell(s,e)}}),this.renderer.updateLayout(),this.renderer.scheduleRender()}sort(e,s,i){var o;if(this.options.onSort){const l=(o=this.columns.getConfig(e))==null?void 0:o.key;if(this.options.onSort(e,s,l)===!0)return}this.viewMapping.sort(e,s,i)}clearSort(){this.options.onSort&&this.options.onSort(-1,null)===!0||this.viewMapping.clearSort()}getSortState(){return this.viewMapping.getSortState()}setFilter(e,s){var i;if(this.options.onFilter){const o=(i=this.columns.getConfig(e))==null?void 0:i.key;if(this.options.onFilter(e,o,!0)===!0)return}this.viewMapping.setFilter(e,s)}removeFilter(e){var s;if(this.options.onFilter){const i=(s=this.columns.getConfig(e))==null?void 0:s.key;if(this.options.onFilter(e,i,!1)===!0)return}this.viewMapping.removeFilter(e)}clearFilters(){this.viewMapping.clearFilters()}getActiveFilters(){return this.viewMapping.getActiveFilters()}mergeCells(e,s,i,o){this.merges.addMerge({row:e,col:s,rowSpan:i,colSpan:o}),this.renderer.scheduleRender()}unmergeCells(e,s){this.merges.removeMerge(e,s),this.renderer.scheduleRender()}getMerge(e,s){return this.merges.getMerge(e,s)}clearMerges(){this.merges.clear(),this.renderer.scheduleRender()}addRowGroup(e,s,i,o=!0){this.rowGroups.addGroup({startRow:e,count:s,label:i,expanded:o,depth:0})}removeRowGroup(e){this.rowGroups.removeGroup(e)}toggleRowGroup(e){this.rowGroups.toggleGroup(e)}expandAllGroups(){this.rowGroups.expandAll()}collapseAllGroups(){this.rowGroups.collapseAll()}exportCSV(e){return he(this.data,this.viewMapping,e)}exportJSON(e){return ce(this.data,this.viewMapping,e)}downloadCSV(e="export.csv",s){const i=this.exportCSV(s);O(i,e,"text/csv;charset=utf-8")}downloadJSON(e="export.json",s){const i=JSON.stringify(this.exportJSON(s),null,2);O(i,e,"application/json")}getViewport(){return this.renderer.getViewport()}refresh(){this.renderer.updateLayout(),this.renderer.scheduleRender()}destroy(){var e;this._keydownHandler&&this.renderer.getContainer().removeEventListener("keydown",this._keydownHandler),this._infiniteScrollHandler&&(window.removeEventListener("scroll",this._infiniteScrollHandler),this.renderer.getScrollContainer().removeEventListener("scroll",this._infiniteScrollHandler)),this._lazyLoadHandler&&(window.removeEventListener("scroll",this._lazyLoadHandler),this.renderer.getScrollContainer().removeEventListener("scroll",this._lazyLoadHandler)),this.fillHandle.destroy(),this.columnReorder.destroy(),this.editorManager.destroy(),this.columnResize.destroy(),this.rowResize.destroy(),this.contextMenu.destroy(),this.autoFit.destroy(),this.loadingOverlay.destroy(),(e=this.paginationBar)==null||e.destroy(),this.renderer.destroy(),this.removeAllListeners()}startEditing(e,s,i){if(this.options.readOnly)return;const o=this.columns.getConfig(s),l=this.data.getCell(e,s);if(o!=null&&o.readOnly||l!=null&&l.readOnly)return;const r=this.options.defaultCellType??"text",c=(l==null?void 0:l.type)??(o==null?void 0:o.type)??r,h=(o==null?void 0:o.editor)??c;if(h==="blank"){this.emit("editor:open",{row:e,col:s}),this.emit("editor:close",{row:e,col:s,value:void 0,cancelled:!0});return}const d=this.renderer.getCellBounds(e,s),a=l==null?void 0:l.value;this.emit("editor:open",{row:e,col:s}),this.editorManager.open(e,s,h,a,d,l,i)}deleteSelected(){if(this.options.readOnly)return;const e=[];if(this.selection.forEachSelected((s,i)=>{this.data.hasCell(s,i)&&e.push({row:s,col:i})}),e.length>0){const s=new Y(this.data,e);this.execCommand(s)}}async pasteWithUndo(){const e=this.selection.focus;if(!e)return;let s;try{s=await navigator.clipboard.readText()}catch{return}const i=s.split(`
|
|
13
|
+
`).map(r=>r.split(" "));if(i.length===0)return;const o=i.length===1&&i[0].length===1,l=[];if(o&&!this.isFullRowOrColSelected()){const r=i[0][0];this.selection.forEachSelected((c,h)=>{c<this.data.rowCount&&h<this.data.colCount&&l.push({row:c,col:h,data:{value:r}})})}else for(let r=0;r<i.length;r++)for(let c=0;c<i[r].length;c++){const h=e.row+r,d=e.col+c;h>=this.data.rowCount||d>=this.data.colCount||l.push({row:h,col:d,data:{value:i[r][c]}})}if(l.length>0){const r=new $(this.data,l);this.execCommand(r),this.emit("data:patch",{patches:l})}}async cutWithUndo(){await this.clipboard.copy(),this.deleteSelected()}execCommand(e){this.commands.execute(e),this.emit("command:execute",{changes:e.getChanges()})}reorderColumn(e,s){if(e===s)return;this.data.transaction(()=>{for(let l=0;l<this.data.rowCount;l++){const r=[];for(let h=0;h<this.data.colCount;h++)r.push(this.data.getCell(l,h));const c=r.splice(e,1)[0];r.splice(s,0,c);for(let h=0;h<r.length;h++)r[h]?this.data.setCell(l,h,r[h]):this.data.deleteCell(l,h)}});const i=[];for(let l=0;l<this.columns.count;l++)i.push(this.columns.getWidth(l));const o=i.splice(e,1)[0];i.splice(s,0,o);for(let l=0;l<i.length;l++)this.columns.setWidth(l,i[l]);this.refresh()}expandIfNeeded(e,s){let i=!1;if(e>=this.data.rowCount){const o=e+2;this.data.rowCount=o,this.rows.setCount(o),this.viewMapping.rebuild(),i=!0}if(s>=this.data.colCount){const o=s+2;this.data.colCount=o,this.columns.setCount(o),i=!0}i&&(this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.refresh())}isFullRowOrColSelected(){const e=this.selection.getBounds();return e?e.c1===0&&e.c2===this.data.colCount-1||e.r1===0&&e.r2===this.data.rowCount-1:!1}loadTableData(e,s){const i=new Map;s.forEach((o,l)=>{o.key&&i.set(o.key,l)}),this.data.transaction(()=>{for(let o=0;o<e.length;o++){const l=e[o];for(const[r,c]of Object.entries(l)){const h=i.get(r);h!==void 0&&this.data.setCell(o,h,{value:c})}}})}setTableData(e){const s=this.options.columns??[];let i=s;s.some(o=>o.children&&o.children.length>0)&&(i=W(s).flatColumns),this.data.clear(),this.data.rowCount=e.length,this.rows.setCount(e.length),this.selection.setDimensions(e.length,this.data.colCount),this.loadTableData(e,i),this.pagination.enabled&&this.pagination.setTotalRows(e.length),this.viewMapping.rebuild(),this.refresh()}setLoading(e){e?this.loadingOverlay.show():this.loadingOverlay.hide()}get isLoading(){return this.loadingOverlay.isVisible}setPage(e){this.pagination.setPage(e)}setPageSize(e){this.pagination.setPageSize(e)}getPaginationState(){return this.pagination.getState()}}class ke{constructor(t){n(this,"config");n(this,"container");n(this,"listEl");n(this,"searchInput",null);n(this,"selected",new Set);n(this,"options",[]);n(this,"highlightIndex",-1);n(this,"searchInputHandler",null);n(this,"handleItemClick",t=>{const e=t.target.closest(".wt-dropdown-item");if(!e)return;t.stopPropagation();const s=parseInt(e.dataset.index??"",10);if(isNaN(s)||s<0||s>=this.options.length)return;const i=this.options[s];i.disabled||this.selectOption(i)});n(this,"handleKey",t=>{const e=this.listEl.children;switch(t.key){case"ArrowDown":t.preventDefault(),this.highlightIndex=Math.min(this.highlightIndex+1,e.length-1),this.updateHighlight();break;case"ArrowUp":t.preventDefault(),this.highlightIndex=Math.max(this.highlightIndex-1,0),this.updateHighlight();break;case"Enter":t.preventDefault(),this.highlightIndex>=0&&this.highlightIndex<this.options.length&&this.selectOption(this.options[this.highlightIndex]);break}});this.config=t}createElement(t){return this.container=document.createElement("div"),this.container.className="wt-dropdown",this.config.searchable&&(this.searchInput=document.createElement("input"),this.searchInput.type="text",this.searchInput.className="wt-dropdown-search",this.searchInput.placeholder=this.config.placeholder??"Search...",this.container.appendChild(this.searchInput),this.searchInputHandler=()=>{this.loadOptions(this.searchInput.value)},this.searchInput.addEventListener("input",this.searchInputHandler)),this.listEl=document.createElement("div"),this.listEl.className="wt-dropdown-list",this.container.appendChild(this.listEl),this.listEl.addEventListener("click",this.handleItemClick),t.appendChild(this.container),this.container.addEventListener("keydown",this.handleKey),this.container}open(t,e,s){this.config.multiple&&Array.isArray(t)?this.selected=new Set(t):t!=null&&(this.selected=new Set([t])),this.loadOptions(""),requestAnimationFrame(()=>{this.searchInput?this.searchInput.focus():this.container.focus()})}getValue(){return this.config.multiple?Array.from(this.selected):this.selected.size>0?this.selected.values().next().value:null}close(){this.searchInput&&this.searchInputHandler&&this.searchInput.removeEventListener("input",this.searchInputHandler),this.listEl.removeEventListener("click",this.handleItemClick),this.container.removeEventListener("keydown",this.handleKey),this.container.remove()}async loadOptions(t){if(this.config.source)this.options=await this.config.source(t,0,0);else if(this.config.options){const e=t.toLowerCase();this.options=e?this.config.options.filter(s=>s.label.toLowerCase().includes(e)):this.config.options}this.renderOptions()}renderOptions(){this.listEl.innerHTML="",this.highlightIndex=-1;for(let t=0;t<this.options.length;t++){const e=this.options[t],s=document.createElement("div");if(s.className="wt-dropdown-item",s.dataset.index=String(t),this.selected.has(e.value)&&s.classList.add("wt-dropdown-item--selected"),e.disabled&&s.classList.add("wt-dropdown-item--disabled"),this.config.renderOption)this.config.renderOption(e,s);else if(s.textContent=e.label,e.icon){const i=document.createElement("span");i.className="wt-dropdown-icon",i.textContent=e.icon,s.prepend(i)}this.listEl.appendChild(s)}}selectOption(t){this.config.multiple?(this.selected.has(t.value)?this.selected.delete(t.value):this.selected.add(t.value),this.renderOptions()):(this.selected.clear(),this.selected.add(t.value))}updateHighlight(){var e;const t=this.listEl.children;for(let s=0;s<t.length;s++)t[s].classList.toggle("wt-dropdown-item--highlight",s===this.highlightIndex);(e=t[this.highlightIndex])==null||e.scrollIntoView({block:"nearest"})}}class Le{constructor(t){n(this,"el");n(this,"onAttempt");n(this,"row",-1);n(this,"col",-1);this.onAttempt=t??null}createElement(t){return this.el=document.createElement("div"),t.appendChild(this.el),this.el}open(t,e,s){this.onAttempt&&this.onAttempt(this.row,this.col)}setPosition(t,e){this.row=t,this.col=e}getValue(){}close(){var t;(t=this.el)==null||t.remove()}}const _e={bgColor:"#ffffff",cellBgColor:"#ffffff",cellTextColor:"#1e293b",headerBgColor:"#f8fafc",headerTextColor:"#475569",gridLineColor:"#e2e8f0",selectionBgColor:"rgba(59, 130, 246, 0.08)",selectionBorderColor:"#3b82f6",focusBorderColor:"#3b82f6",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:13,headerFontSize:12,cellPadding:8,headerHeight:28,rowHeaderWidth:50},Te={bgColor:"#0f172a",cellBgColor:"#1e293b",cellTextColor:"#e2e8f0",headerBgColor:"#0f172a",headerTextColor:"#94a3b8",gridLineColor:"#334155",selectionBgColor:"rgba(59, 130, 246, 0.15)",selectionBorderColor:"#3b82f6",focusBorderColor:"#60a5fa",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:13,headerFontSize:12,cellPadding:8,headerHeight:28,rowHeaderWidth:50},Ie={bgColor:"#ffffff",cellBgColor:"#ffffff",cellTextColor:"#111827",headerBgColor:"#ffffff",headerTextColor:"#9ca3af",gridLineColor:"#f3f4f6",selectionBgColor:"rgba(99, 102, 241, 0.06)",selectionBorderColor:"#6366f1",focusBorderColor:"#6366f1",fontFamily:'"Inter", -apple-system, BlinkMacSystemFont, sans-serif',fontSize:13,headerFontSize:11,cellPadding:10,headerHeight:32,rowHeaderWidth:44};w.BadgeRenderer=J,w.BlankEditor=Le,w.BlankRenderer=ee,w.CheckboxRenderer=j,w.ColumnModel=D,w.CommandBus=X,w.ContextMenu=se,w.DataModel=B,w.DeleteCellsCommand=Y,w.DropdownEditor=ke,w.EventEmitter=V,w.MergeModel=ne,w.NumberRenderer=Z,w.PaginationModel=le,w.PatchCommand=$,w.ProgressRenderer=Q,w.RendererRegistry=te,w.RowGroupModel=ie,w.RowModel=G,w.SelectionModel=U,w.SetCellValueCommand=N,w.THEME_DARK=Te,w.THEME_LIGHT=_e,w.THEME_MINIMAL=Ie,w.TextRenderer=K,w.ViewMapping=oe,w.WanderTable=He,w.columnLabel=z,w.downloadFile=O,w.exportCSV=he,w.exportJSON=ce,w.flattenColumns=W,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}));
|
|
14
|
+
//# sourceMappingURL=wandertable.umd.js.map
|