@toolbox-web/grid 1.21.2 → 1.22.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/README.md +6 -8
- package/all.js +1 -1
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +53 -2
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/rows.d.ts.map +1 -1
- package/lib/core/plugin/base-plugin.d.ts +8 -2
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/types.d.ts +84 -2
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/clipboard/types.d.ts +5 -0
- package/lib/plugins/clipboard/types.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/column-virtualization/types.d.ts +5 -0
- package/lib/plugins/column-virtualization/types.d.ts.map +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/context-menu/types.d.ts +5 -0
- package/lib/plugins/context-menu/types.d.ts.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/types.d.ts +26 -0
- package/lib/plugins/editing/types.d.ts.map +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/export/types.d.ts +5 -0
- package/lib/plugins/export/types.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/filtering/types.d.ts +3 -0
- package/lib/plugins/filtering/types.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-columns/types.d.ts +3 -0
- package/lib/plugins/grouping-columns/types.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/grouping-rows/types.d.ts +5 -0
- package/lib/plugins/grouping-rows/types.d.ts.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/types.d.ts +5 -0
- package/lib/plugins/master-detail/types.d.ts.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/multi-sort/types.d.ts +5 -0
- package/lib/plugins/multi-sort/types.d.ts.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-columns/types.d.ts +3 -0
- package/lib/plugins/pinned-columns/types.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pinned-rows/types.d.ts +5 -0
- package/lib/plugins/pinned-rows/types.d.ts.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/pivot/types.d.ts +5 -0
- package/lib/plugins/pivot/types.d.ts.map +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/print/types.d.ts +3 -0
- package/lib/plugins/print/types.d.ts.map +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/reorder/types.d.ts +5 -0
- package/lib/plugins/reorder/types.d.ts.map +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/responsive/types.d.ts +5 -0
- package/lib/plugins/responsive/types.d.ts.map +1 -1
- package/lib/plugins/row-reorder/index.js.map +1 -1
- package/lib/plugins/row-reorder/types.d.ts +5 -0
- package/lib/plugins/row-reorder/types.d.ts.map +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/selection/types.d.ts +3 -0
- package/lib/plugins/selection/types.d.ts.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/server-side/types.d.ts +5 -0
- package/lib/plugins/server-side/types.d.ts.map +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/types.d.ts +5 -0
- package/lib/plugins/tree/types.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/undo-redo/types.d.ts +5 -0
- package/lib/plugins/undo-redo/types.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/lib/plugins/visibility/types.d.ts +5 -0
- package/lib/plugins/visibility/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
package/all.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BaseGridPlugin as e,DEFAULT_GRID_ICONS as t,F as i,e as n,s as r,c as o,runAggregator as s,a,b as l,g as d,r as c,getAggregator as u,getValueAggregator as h,d as g,f as p}from"./index.js";import{DEFAULT_ANIMATION_CONFIG as f,DGEvents as m,DataGridElement as w,FitModeEnum as b,GridCSSVars as v,GridClasses as y,GridDataAttrs as x,DataGridElement as C,GridSelectors as E,PLUGIN_QUERIES as R,PluginEvents as S,PluginManager as k,RenderPhase as A,builtInSort as _,createGrid as L,defaultComparator as I,queryGrid as T}from"./index.js";function F(e,t,i=!0){let n=e;if(i&&(n=n.filter(e=>!e.hidden&&!e.field.startsWith("__")&&!0!==e.meta?.utility)),t?.length){const e=new Set(t);n=n.filter(t=>e.has(t.field))}return n}function M(e,t){return t?.length?[...t].sort((e,t)=>e-t).map(t=>e[t]).filter(e=>null!=e):e}function D(e){return null==e?"":e instanceof Date?e.toISOString():"object"==typeof e?JSON.stringify(e):String(e)}function P(e,t){const i=t.delimiter??"\t",n=t.newline??"\n",r=e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"),o=[];let s=[],a="",l=!1;for(let d=0;d<r.length;d++){const e=r[d];'"'!==e||l?'"'===e&&l?'"'===r[d+1]?(a+='"',d++):l=!1:e!==i||l?e!==n||l?a+=e:(s.push(a),a="",(s.length>1||s.some(e=>""!==e.trim()))&&o.push(s),s=[]):(s.push(a),a=""):l=!0}return s.push(a),(s.length>1||s.some(e=>""!==e.trim()))&&o.push(s),o}function q(e,t){const{rows:i,target:n,fields:r}=e;if(!n)return;const o=t.rows,s=t.effectiveConfig.columns??[],a=s.map(e=>e.field),l=/* @__PURE__ */new Map;s.forEach(e=>{l.set(e.field,!0===e.editable)});const d=[...o],c=n.bounds?n.bounds.endRow:1/0;i.forEach((e,t)=>{const i=n.row+t;if(!(i>c)){if(n.bounds){if(i>=d.length)return}else for(;i>=d.length;){const e={};a.forEach(t=>e[t]=""),d.push(e)}d[i]={...d[i]},e.forEach((e,t)=>{const n=r[t];n&&l.get(n)&&(d[i][n]=e)})}}),t.rows=d}class H extends e{static dependencies=[{name:"selection",required:!1,reason:"Enables copy/paste of selected cells instead of entire grid"}];name="clipboard";get defaultConfig(){return{includeHeaders:!1,delimiter:"\t",newline:"\n",quoteStrings:!1}}lastCopied=null;attach(e){super.attach(e);e.addEventListener("paste",e=>this.#e(e),{signal:this.disconnectSignal})}detach(){this.lastCopied=null}onKeyDown(e){return!(!e.ctrlKey&&!e.metaKey||"c"!==e.key)&&(e.preventDefault(),this.#t(e.target),!0)}#t(e){const t=this.#i();if(t&&0===t.ranges.length){const t=this.#n(e);if(!t)return;const i=this.columns[t.col];if(!i)return;return void this.copy({rowIndices:[t.row],columns:[i.field]})}this.copy()}#e(e){const t=e.clipboardData?.getData("text/plain");if(!t)return;e.preventDefault();const i=P(t,this.config),n=this.#i(),r=n?.ranges?.[0],o=r?.from.row??0,s=r?.from.col??0,a=r&&("range"===n?.mode||"row"===n?.mode)&&(r.from.row!==r.to.row||r.from.col!==r.to.col)?{endRow:r.to.row,endCol:r.to.col}:null,l=a?.endCol??this.visibleColumns.length-1,d=this.visibleColumns[s],c=d?{row:o,col:s,field:d.field,bounds:a}:null,u=[],h=i[0]?.length??0;for(let p=0;p<h&&s+p<=l;p++){const e=this.visibleColumns[s+p];e&&u.push(e.field)}const g={rows:i,text:t,target:c,fields:u};this.emit("paste",g),this.#r(g)}#r(e){if(!this.grid)return;const{pasteHandler:t}=this.config;if(null===t)return;(t??q)(e,this.grid)}#i(){const e=this.grid?.query("getSelection");return e?.[0]}#o(e){const t=this.#i();let i,n;if(e?.columns)i=F(this.columns,e.columns);else if(t?.ranges.length&&"row"!==t.mode){const e=t.ranges[t.ranges.length-1],n=Math.min(e.from.col,e.to.col),r=Math.max(e.from.col,e.to.col);i=F(this.visibleColumns.slice(n,r+1))}else i=F(this.columns);if(e?.rowIndices)n=M(this.rows,e.rowIndices);else if(t?.ranges.length){const e=t.ranges[t.ranges.length-1],i=Math.min(e.from.row,e.to.row),r=Math.max(e.from.row,e.to.row);n=[];for(let t=i;t<=r;t++){const e=this.rows[t];e&&n.push(e)}}else n=this.rows;return{columns:i,rows:n}}#s(e,t,i){const n=i?.delimiter??this.config.delimiter??"\t",r=i?.newline??this.config.newline??"\n",o=i?.includeHeaders??this.config.includeHeaders??!1,s=i?.processCell??this.config.processCell,a=[];o&&a.push(e.map(e=>e.header||e.field).join(n));for(const l of t){const t=e.map(e=>{const t=l[e.field];return s?s(t,e.field,l):D(t)});a.push(t.join(n))}return a.join(r)}#n(e){const t=e.closest("[data-field-cache]");if(!t)return null;const i=t.dataset.fieldCache,n=t.dataset.row;if(!i||!n)return null;const r=parseInt(n,10);if(isNaN(r))return null;const o=this.columns.findIndex(e=>e.field===i);return-1===o?null:{row:r,col:o}}getSelectionAsText(e){const{columns:t,rows:i}=this.#o(e);return 0===t.length||0===i.length?"":this.#s(t,i,e)}async copy(e){const{columns:t,rows:i}=this.#o(e);if(0===t.length||0===i.length)return"";const n=this.#s(t,i,e);return await async function(e){try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("[copyToClipboard] Clipboard API failed:",t);const i=document.createElement("textarea");i.value=e,i.style.position="fixed",i.style.opacity="0",i.style.pointerEvents="none",document.body.appendChild(i),i.select();const n=document.execCommand("copy");return document.body.removeChild(i),n}}(n),this.lastCopied={text:n,timestamp:Date.now()},this.emit("copy",{text:n,rowCount:i.length,columnCount:t.length}),n}async copyRows(e,t){return 0===e.length?"":this.copy({...t,rowIndices:e})}async paste(){const e=await async function(){try{return await navigator.clipboard.readText()}catch{return""}}();return e?P(e,this.config):null}getLastCopied(){return this.lastCopied}}function N(e){if(null==e)return 100;if("number"==typeof e)return e;const t=parseFloat(e);return isNaN(t)?100:t}function z(e){return e.map(e=>N(e.width))}function G(e){const t=[];let i=0;for(const n of e)t.push(i),i+=N(n.width);return t}function K(e){return e.reduce((e,t)=>e+N(t.width),0)}function O(e,t,i,n,r){const o=i.length;if(0===o)return{startCol:0,endCol:0,visibleColumns:[]};let s=function(e,t,i){let n=0,r=t.length-1;for(;n<r;){const o=Math.floor((n+r)/2);t[o]+i[o]<=e?n=o+1:r=o}return n}(e,i,n);s=Math.max(0,s-r);const a=e+t;let l=s;for(let c=s;c<o;c++){if(i[c]>=a){l=c-1;break}l=c}l=Math.min(o-1,l+r);const d=[];for(let c=s;c<=l;c++)d.push(c);return{startCol:s,endCol:l,visibleColumns:d}}class B extends e{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];originalColumns=[];attach(e){super.attach(e);const t=this.columns;this.columnWidths=z(t),this.columnOffsets=G(t),this.totalWidth=K(t),this.endCol=t.length-1}detach(){this.#a(),this.columnWidths=[],this.columnOffsets=[],this.originalColumns=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}#a(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".header-row");t&&(t.style.paddingLeft="",t.style.minWidth="");e.querySelectorAll(".data-grid-row").forEach(e=>{e.style.paddingLeft=""});const i=e.querySelector(".rows-viewport .rows");i&&(i.style.width="");const n=e.querySelector(".rows-body");n&&(n.style.minWidth="")}processColumns(e){(0===this.originalColumns.length||e.length>=this.originalColumns.length)&&(this.originalColumns=e,this.columnWidths=z(e),this.columnOffsets=G(e),this.totalWidth=K(e));const t=this.originalColumns,i=(n=t.length,r=this.config.threshold??30,!!(this.config.autoEnable??!0)&&n>r);var n,r;if(this.isVirtualized=i??!1,!i)return this.startCol=0,this.endCol=t.length-1,[...t];const o=this.grid.clientWidth||800,s=O(this.scrollLeft,o,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=s.startCol,this.endCol=s.endCol,s.visibleColumns.map(e=>t[e])}afterRender(){if(!this.isVirtualized)return;const e=this.gridElement;if(!e)return;const t=this.columnOffsets[this.startCol]??0,i=e.querySelector(".header-row"),n=e.querySelectorAll(".data-grid-row");i&&(i.style.paddingLeft=`${t}px`,i.style.minWidth=`${this.totalWidth}px`),n.forEach(e=>{e.style.paddingLeft=`${t}px`});const r=e.querySelector(".rows-viewport .rows");r&&(r.style.width=`${this.totalWidth}px`);const o=e.querySelector(".rows-body");o&&(o.style.minWidth=`${this.totalWidth}px`)}onScroll(e){if(!this.isVirtualized)return;Math.abs(e.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=e.scrollLeft,this.requestColumnsRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(e){const t=this.columnOffsets[e]??0;this.grid.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const V="@layer tbw-plugins{.tbw-context-menu{position:fixed;background:var(--tbw-context-menu-bg, var(--tbw-color-panel-bg));color:var(--tbw-context-menu-fg, var(--tbw-color-fg));border:1px solid var(--tbw-context-menu-border, var(--tbw-color-border));border-radius:var(--tbw-context-menu-radius, var(--tbw-border-radius));box-shadow:var(--tbw-context-menu-shadow, 0 2px 10px var(--tbw-color-shadow));min-width:var(--tbw-context-menu-min-width, var(--tbw-menu-min-width));padding:var(--tbw-spacing-xs) 0;z-index:10000;font-size:var(--tbw-context-menu-font-size, var(--tbw-font-size-sm));font-family:var(--tbw-context-menu-font-family, var(--tbw-font-family))}.tbw-context-menu-item{display:flex;align-items:center;padding:var(--tbw-context-menu-item-padding, var(--tbw-menu-item-padding));cursor:pointer;gap:var(--tbw-context-menu-item-gap, var(--tbw-menu-item-gap))}.tbw-context-menu-item:hover:not(.disabled){background:var(--tbw-context-menu-hover, var(--tbw-color-row-hover))}.tbw-context-menu-item.disabled{opacity:.5;cursor:default}.tbw-context-menu-item.danger{color:var(--tbw-context-menu-danger, var(--tbw-color-danger))}.tbw-context-menu-icon{width:var(--tbw-context-menu-icon-size, var(--tbw-icon-size));text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut kbd{color:var(--tbw-context-menu-muted, var(--tbw-color-fg-muted));font-size:var(--tbw-context-menu-shortcut-size, var(--tbw-font-size-xs))}.tbw-context-menu-arrow{font-size:var(--tbw-context-menu-arrow-size, var(--tbw-font-size-2xs));color:var(--tbw-context-menu-muted, var(--tbw-color-fg-muted))}.tbw-context-menu-separator{height:1px;background:var(--tbw-context-menu-border, var(--tbw-color-border));margin:var(--tbw-spacing-xs) 0}}";function W(e,t){return("function"==typeof e?e(t):e).filter(e=>!0!==e.hidden&&("function"!=typeof e.hidden||!e.hidden(t)))}function $(e){const t=[];for(const i of e)i.separator&&(0===t.length||t[t.length-1].separator)||t.push(i);return t.length>0&&t[t.length-1].separator&&t.pop(),t}function j(e,t){return!0===e.disabled||"function"==typeof e.disabled&&e.disabled(t)}function U(e,i,n,r=t.submenuArrow){const o=document.createElement("div");o.className="tbw-context-menu",o.setAttribute("role","menu");const s=e.some(e=>!e.separator&&e.icon);for(const t of e){if(t.separator){const e=document.createElement("div");e.className="tbw-context-menu-separator",e.setAttribute("role","separator"),o.appendChild(e);continue}const e=document.createElement("div");e.className="tbw-context-menu-item",t.cssClass&&e.classList.add(t.cssClass),e.setAttribute("role","menuitem"),e.setAttribute("data-id",t.id);const a=j(t,i);if(a&&(e.classList.add("disabled"),e.setAttribute("aria-disabled","true")),t.icon){const i=document.createElement("span");i.className="tbw-context-menu-icon",i.innerHTML=t.icon,e.appendChild(i)}else if(s){const t=document.createElement("span");t.className="tbw-context-menu-icon",t.innerHTML=" ",e.appendChild(t)}const l=document.createElement("span");if(l.className="tbw-context-menu-label",l.textContent=t.name,e.appendChild(l),t.shortcut){const i=document.createElement("span");if(i.className="tbw-context-menu-shortcut",Array.isArray(t.shortcut))t.shortcut.forEach((e,t)=>{t>0&&i.appendChild(document.createTextNode("+"));const n=document.createElement("kbd");n.textContent=e,i.appendChild(n)});else{const e=document.createElement("kbd");e.textContent=t.shortcut,i.appendChild(e)}e.appendChild(i)}if(t.subMenu?.length){const o=document.createElement("span");o.className="tbw-context-menu-arrow","string"==typeof r?o.innerHTML=r:r instanceof HTMLElement&&o.appendChild(r.cloneNode(!0)),e.appendChild(o),e.addEventListener("mouseenter",()=>{if(e.querySelector(".tbw-context-menu"))return;if(!t.subMenu)return;const o=U(W(t.subMenu,i),i,n,r);o.classList.add("tbw-context-submenu"),o.style.position="absolute",o.style.left="100%",o.style.top="0",e.style.position="relative",e.appendChild(o)}),e.addEventListener("mouseleave",()=>{const t=e.querySelector(".tbw-context-menu");t&&t.remove()})}a||!t.action||t.subMenu||e.addEventListener("click",e=>{e.stopPropagation(),n(t)}),o.appendChild(e)}return o}function Y(e,t,i){e.style.position="fixed",e.style.left=`${t}px`,e.style.top=`${i}px`,e.style.visibility="hidden",e.style.zIndex="10000";const n=e.getBoundingClientRect(),r=window.innerWidth,o=window.innerHeight;let s=t,a=i;t+n.width>r&&(s=t-n.width),i+n.height>o&&(a=i-n.height),s=Math.max(0,s),a=Math.max(0,a),e.style.left=`${s}px`,e.style.top=`${a}px`,e.style.visibility="visible"}const Z="getContextMenuItems";let Q=null,X=null,J=null,ee=0;const te=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:e=>{const t=e.grid;t?.plugins?.clipboard?.copy?.()}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:e=>{const t=e.grid;t?.plugins?.export?.exportCsv?.()}}];class ie extends e{static manifest={queries:[{type:Z,description:"Collects context menu items from other plugins for header right-click menus"}]};name="contextMenu";get defaultConfig(){return{items:te}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),ee++}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.uninstallGlobalHandlers()}syncSelectionOnContextMenu(e){if(e<0)return[];const t=this.grid?.query("getSelectedRowIndices"),i=t?.[0];return i?i.includes(e)?i:(this.grid?.query("selectRows",[e]),[e]):[e]}static CSS_VARS_TO_COPY=["--tbw-color-panel-bg","--tbw-color-fg","--tbw-color-fg-muted","--tbw-color-border","--tbw-color-row-hover","--tbw-color-shadow","--tbw-color-danger","--tbw-border-radius","--tbw-font-family","--tbw-font-size-sm","--tbw-font-size-xs","--tbw-font-size-2xs","--tbw-spacing-xs","--tbw-icon-size","--tbw-menu-min-width","--tbw-menu-item-padding","--tbw-menu-item-gap","--tbw-context-menu-bg","--tbw-context-menu-fg","--tbw-context-menu-border","--tbw-context-menu-radius","--tbw-context-menu-shadow","--tbw-context-menu-hover","--tbw-context-menu-danger","--tbw-context-menu-muted","--tbw-context-menu-min-width","--tbw-context-menu-font-size","--tbw-context-menu-font-family","--tbw-context-menu-item-padding","--tbw-context-menu-item-gap","--tbw-context-menu-icon-size","--tbw-context-menu-shortcut-size","--tbw-context-menu-arrow-size"];copyGridStyles(e){const t=this.gridElement;if(!t)return;const i=getComputedStyle(t),n=[],r=i.getPropertyValue("color-scheme").trim();r&&n.push(`color-scheme: ${r}`);for(const o of ie.CSS_VARS_TO_COPY){const e=i.getPropertyValue(o).trim();e&&n.push(`${o}: ${e}`)}if(n.length>0){const t=e.getAttribute("style")||"";e.setAttribute("style",t+n.join("; ")+";")}}installGlobalHandlers(){!J&&"undefined"!=typeof document&&V&&(J=document.createElement("style"),J.id="tbw-context-menu-styles",J.textContent=V,document.head.appendChild(J)),Q||(Q=()=>{document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove())},document.addEventListener("click",Q)),X||(X=e=>{if("Escape"===e.key){document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove())}},document.addEventListener("keydown",X))}uninstallGlobalHandlers(){ee--,ee>0||(Q&&(document.removeEventListener("click",Q),Q=null),X&&(document.removeEventListener("keydown",X),X=null),J&&(J.remove(),J=null))}collectPluginItems(e){if(!this.grid)return[];const t=this.grid.query(Z,e),i=[];for(const n of t)Array.isArray(n)&&i.push(...n);return i.sort((e,t)=>(e.order??100)-(t.order??100)),this.insertGroupSeparators(i)}insertGroupSeparators(e){if(e.length<=1)return e;const t=[];let i=-1;for(const n of e){if(n.separator){t.push(n);continue}const e=Math.floor((n.order??100)/10);i>=0&&e!==i&&t.push({id:`__sep-${i}-${e}`,label:"",separator:!0,action:()=>{}}),i=e,t.push(n)}return t}convertPluginItems(e){return e.map(e=>({id:e.id,name:e.label,icon:e.icon,shortcut:e.shortcut,disabled:e.disabled??!1,action:()=>e.action(),separator:e.separator,cssClass:e.cssClass}))}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-grid-root");t&&"true"!==t.getAttribute("data-context-menu-bound")&&(t.setAttribute("data-context-menu-bound","true"),t.addEventListener("contextmenu",e=>{const t=e;t.preventDefault();const i=t.target,n=i.closest("[data-row][data-col]"),r=i.closest('[part~="header-cell"]');let o;if(n){const e=parseInt(n.getAttribute("data-row")??"-1",10),i=parseInt(n.getAttribute("data-col")??"-1",10),r=this.visibleColumns[i],s=this.rows[e],a=this.syncSelectionOnContextMenu(e);o={row:s,rowIndex:e,column:r,columnIndex:i,field:r?.field??"",value:s?.[r?.field]??null,isHeader:!1,event:t,selectedRows:a}}else{if(!r)return;{const e=parseInt(r.getAttribute("data-col")??"-1",10),i=this.visibleColumns[e];o={row:null,rowIndex:-1,column:i,columnIndex:e,field:i?.field??"",value:null,isHeader:!0,event:t,selectedRows:[]}}}this.params=o,this.position={x:t.clientX,y:t.clientY};const s=this.collectPluginItems(o);let a=W(this.config.items??te,o);if(s.length>0){const e=this.convertPluginItems(s);a=a.length>0&&e.length>0?[...a,{id:"__plugin-sep",name:"",separator:!0},...e]:[...a,...e]}a=$(a),a.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=U(a,o,e=>{e.action&&e.action(o),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),Y(this.menuElement,t.clientX,t.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:o,items:a}))}))}showMenu(e,t,i){const n={row:i.row??null,rowIndex:i.rowIndex??-1,column:i.column??null,columnIndex:i.columnIndex??-1,field:i.field??"",value:i.value??null,isHeader:i.isHeader??!1,event:i.event??new MouseEvent("contextmenu"),selectedRows:i.selectedRows??[]},r=this.collectPluginItems(n);let o=W(this.config.items??te,n);if(r.length>0){const e=this.convertPluginItems(r);o=o.length>0&&e.length>0?[...o,{id:"__plugin-sep",name:"",separator:!0},...e]:[...o,...e]}o=$(o),this.menuElement&&this.menuElement.remove(),this.menuElement=U(o,n,e=>{e.action&&e.action(n),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),Y(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}function ne(e){switch(e.type){case"number":return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="number",n.value=null!=t.value?String(t.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>t.commit(""===n.value?null:Number(n.value));return n.addEventListener("blur",r),n.addEventListener("keydown",e=>{"Enter"===e.key&&r(),"Escape"===e.key&&t.cancel()}),n}}(e);case"boolean":return e=>{const t=document.createElement("input");return t.type="checkbox",t.checked=!!e.value,t.addEventListener("change",()=>e.commit(t.checked)),t};case"date":return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");return n.type="date",t.value instanceof Date?n.valueAsDate=t.value:"string"==typeof t.value&&t.value&&(n.value=t.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder),n.addEventListener("change",()=>{"string"==typeof t.value?t.commit(n.value):t.commit(n.valueAsDate)}),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}(e);case"select":return function(e){return t=>{const i=e.editorParams,n=document.createElement("select");if(e.multi&&(n.multiple=!0),i?.includeEmpty){const e=document.createElement("option");e.value="",e.textContent=i.emptyLabel??"",n.appendChild(e)}const r=function(e){const t=e.options;return t?"function"==typeof t?t():t:[]}(e);r.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,e.multi&&Array.isArray(t.value)&&t.value.includes(i.value)?r.selected=!0:e.multi||t.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(e.multi){const e=Array.from(n.selectedOptions).map(e=>e.value);t.commit(e)}else t.commit(n.value)};return n.addEventListener("change",o),n.addEventListener("blur",o),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}(e);default:return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="text",n.value=null!=t.value?String(t.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const e=n.value;(null!==t.value&&void 0!==t.value||""!==e)&&("string"==typeof t.value&&e===t.value.replace(/[\n\r]/g,"")||("number"==typeof t.value&&""!==e?t.commit(Number(e)):t.commit(e)))};return n.addEventListener("blur",r),n.addEventListener("keydown",e=>{"Enter"===e.key&&r(),"Escape"===e.key&&t.cancel()}),n}}(e)}}function re(e){return"string"==typeof e&&("__proto__"!==e&&"constructor"!==e&&"prototype"!==e)}function oe(e,t,i){return e instanceof HTMLInputElement?"checkbox"===e.type?e.checked:"number"===e.type?""===e.value?null:Number(e.value):"date"===e.type?"string"==typeof i?e.value:e.valueAsDate:"number"==typeof i?""===e.value?null:Number(e.value):null==i&&""===e.value||"string"==typeof i&&e.value===i.replace(/[\n\r]/g,"")?i:e.value:"number"===t?.type&&""!==e.value||"number"==typeof i&&""!==e.value?Number(e.value):null==i&&""===e.value?i:e.value}function se(e){}class ae extends e{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>!0===e},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;&:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}.data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}.data-grid-row>.cell.editing input:not([type=checkbox]),.data-grid-row>.cell.editing select,.data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}.tbw-editor-host{display:contents}--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171);.data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#l(){return"grid"===this.config.mode}#d=-1;#c;#u;#h=-1;#g=/* @__PURE__ */new Map;#p=/* @__PURE__ */new Set;#f=/* @__PURE__ */new Set;#m=/* @__PURE__ */new Map;#w=!1;#b=-1;#v=/* @__PURE__ */new Map;#y=!1;#x=!1;#C=!1;attach(e){super.attach(e);const t=this.disconnectSignal,n=e;n._activeEditRows=-1,n._rowEditSnapshots=/* @__PURE__ */new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),e.resetChangedRows=e=>this.resetChangedRows(e),e.beginBulkEdit=(e,t)=>{t&&this.beginCellEdit(e,t)},document.addEventListener("keydown",e=>{if(!this.#l&&"Escape"===e.key&&-1!==this.#d){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}this.#E(this.#d,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",e=>{if(this.#l)return;if(-1===this.#d)return;const t=n.findRenderedRowElement?.(this.#d);if(!t)return;if(!(e.composedPath&&e.composedPath()||[]).includes(t)){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}queueMicrotask(()=>{-1!==this.#d&&this.#E(this.#d,!1)})}},{signal:t}),this.gridElement.addEventListener("cell-change",e=>{const t=e.detail;if("user"===t.source)return;const i=`${t.rowIndex}:${t.field}`,n=this.#m.get(i);n&&n(t.newValue)},{signal:t}),this.#l&&(n._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",e=>{const t=e.target;if(t.matches(i)){if(this.#x)return t.blur(),void this.gridElement.focus();this.#y=!0}},{signal:t}),this.gridElement.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&this.gridElement.contains(t)&&t.matches(i)||(this.#y=!1)},{signal:t}),this.gridElement.addEventListener("keydown",e=>{if("Escape"===e.key&&this.#y){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#y=!1,this.#x=!0,e.preventDefault(),e.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",e=>{e.target.matches(i)&&(this.#x=!1)},{signal:t}))}detach(){this.gridElement._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#d=-1,this.#c=void 0,this.#u=void 0,this.#h=-1,this.#g.clear(),this.#p.clear(),this.#f.clear(),this.#m.clear(),this.#y=!1,this.#x=!1,this.#C=!1,super.detach()}handleQuery(e){if("isEditing"===e.type)return this.#l||-1!==this.#d}onCellClick(e){if(this.#l)return!1;const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===e.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=e,o=t._columns?.some(e=>e.editable);return!!o&&(e.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(e){const t=this.grid;if("Escape"===e.key){if(this.#l&&this.#y){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}const t=document.activeElement;return t&&this.gridElement.contains(t)&&t.blur(),this.#y=!1,this.requestAfterRender(),!0}if(-1!==this.#d&&!this.#l){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}return this.#E(this.#d,!0),!0}}if(this.#l&&!this.#y&&("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key))return!1;if(this.#l&&this.#y&&("ArrowUp"===e.key||"ArrowDown"===e.key))return!0;if(("ArrowUp"===e.key||"ArrowDown"===e.key)&&-1!==this.#d&&!this.#l){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}const i=t._rows.length-1,r=this.#d;return this.#E(r,!1),"ArrowDown"===e.key?t._focusRow=Math.min(i,t._focusRow+1):t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault(),n(t),this.requestAfterRender(),!0}if("Tab"===e.key&&(-1!==this.#d||this.#l)){if(e.preventDefault(),this.#C)return this.#E(this.#d,!1),!0;const t=!e.shiftKey;return this.#R(t),!0}if(" "===e.key||"Spacebar"===e.key){if(-1!==this.#d)return!1;const i=t._focusRow,n=t._focusCol;if(i>=0&&n>=0){const r=t._visibleColumns[n],o=t._rows[i];if(r?.editable&&"boolean"===r.type&&o){const t=r.field;if(re(t)){const n=!o[t];return this.#S(i,r,n,o),e.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==e.key||e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){if(this.#l&&!this.#y)return this.#k(),!0;if(-1!==this.#d){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}return!1}const i=this.config.editOn??t.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const n=t._focusRow,r=t._focusCol;if(n>=0){const i=t._columns?.some(e=>e.editable);if(i){const i=t._visibleColumns[r],o=t._rows[n],s=i?.field??"",a=s&&o?o[s]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),d=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:s,value:a,row:o,cellEl:l,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(d);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),d.defaultPrevented||c.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===e.key){if(-1!==this.#d||this.#l)return!1;if(!1===(this.config.editOn??t.effectiveConfig?.editOn))return!1;const i=t._focusRow,n=t._focusCol;if(i>=0&&n>=0){const r=t._visibleColumns[n];if(r?.editable&&r.field)return e.preventDefault(),this.beginCellEdit(i,r.field),!0}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,n=t.__frameworkAdapter;return i||n?.getTypeDefault?e.map(e=>{if(!e.type)return e;let t;if(i?.[e.type]?.editorParams&&(t=i[e.type].editorParams),!t&&n?.getTypeDefault){const i=n.getTypeDefault(e.type);i?.editorParams&&(t=i.editorParams)}return t?{...e,editorParams:{...t,...e.editorParams}}:e}):e}afterRender(){const e=this.grid;if(this.#w&&(this.#w=!1,this.#A(e)),-1!==this.#b){const t=this.#b;this.#b=-1,e.animateRow?.(t,"change")}if(!this.#l&&0!==this.#f.size)for(const t of this.#f){const[i,n]=t.split(":"),r=parseInt(i,10),o=parseInt(n,10),s=e.findRenderedRowElement?.(r);if(!s)continue;const a=s.querySelector(`.cell[data-col="${o}"]`);if(!a||a.classList.contains("editing"))continue;const l=e._rows[r],d=e._visibleColumns[o];l&&d&&this.#_(l,r,d,o,a,!0)}}afterCellRender(e){if(!this.#l)return;const{row:t,rowIndex:i,column:n,colIndex:r,cellElement:o}=e;n.editable&&(o.classList.contains("editing")||this.#_(t,i,n,r,o,!0))}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#p){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#p)}get activeEditRow(){return this.#d}get activeEditCol(){return this.#h}isRowEditing(e){return this.#d===e}isCellEditing(e,t){return this.#f.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const e=t.getRowId?.(i);return!!e&&this.#p.has(e)}catch{return!1}}isRowChangedById(e){return this.#p.has(e)}setInvalid(e,t,i=""){let n=this.#v.get(e);n||(n=/* @__PURE__ */new Map,this.#v.set(e,n)),n.set(t,i),this.#L(e,t,!0)}clearInvalid(e,t){const i=this.#v.get(e);i&&(i.delete(t),0===i.size&&this.#v.delete(e)),this.#L(e,t,!1)}clearRowInvalid(e){const t=this.#v.get(e);if(t){const i=Array.from(t.keys());this.#v.delete(e),i.forEach(t=>this.#L(e,t,!1))}}clearAllInvalid(){const e=Array.from(this.#v.entries());this.#v.clear(),e.forEach(([e,t])=>{t.forEach((t,i)=>this.#L(e,i,!1))})}isCellInvalid(e,t){return this.#v.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#v.get(e)?.get(t)}hasInvalidCells(e){const t=this.#v.get(e);return!!t&&t.size>0}getInvalidFields(e){return new Map(this.#v.get(e)??[])}#L(e,t,i){const n=this.grid,r=n._visibleColumns?.findIndex(e=>e.field===t);if(-1===r||void 0===r)return;const o=n._rows,s=o?.findIndex(t=>{try{return n.getRowId?.(t)===e}catch{return!1}});if(-1===s||void 0===s)return;const a=n.findRenderedRowElement?.(s),l=a?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#v.get(e)?.get(t);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#p.clear(),this.#I(),e||this.emit("changed-rows-reset",{rows:t,ids:i});const n=this.grid;n._rowPool?.forEach(e=>e.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,n=i._visibleColumns.findIndex(e=>e.field===t);if(-1===n)return;const r=i._visibleColumns[n];if(!r?.editable)return;const o=i.findRenderedRowElement?.(e),s=o?.querySelector(`.cell[data-col="${n}"]`);s&&(this.#C=!0,this.#T(e,n,s))}beginBulkEdit(e){const t=this.grid;if(!1===(this.config.editOn??t.effectiveConfig?.editOn))return;const n=t._columns?.some(e=>e.editable);if(!n)return;const r=t.findRenderedRowElement?.(e);if(!r)return;this.#C=!1;const o=t._rows[e];this.#F(e,o),Array.from(r.children).forEach((i,n)=>{const r=t._visibleColumns[n];if(r?.editable){const t=i;t.classList.contains("editing")||this.#_(o,e,r,n,t,!0)}}),setTimeout(()=>{let e=r.querySelector(`.cell[data-col="${t._focusCol}"]`);if(e?.classList.contains("editing")||(e=r.querySelector(".cell.editing")),e?.classList.contains("editing")){const t=e.querySelector(i);try{t?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#d&&this.#E(this.#d,!1)}cancelActiveRowEdit(){-1!==this.#d&&this.#E(this.#d,!0)}#T(e,t,i){const n=this.grid,r=n._rows[e],o=n._visibleColumns[t];r&&o?.editable&&(i.classList.contains("editing")||(this.#d!==e&&this.#F(e,r),this.#h=t,this.#_(r,e,o,t,i,!1)))}#k(){const e=this.grid,t=e._focusRow,n=e._focusCol;if(t<0||n<0)return;const r=e.findRenderedRowElement?.(t),o=r?.querySelector(`.cell[data-col="${n}"]`);if(o?.classList.contains("editing")){const e=o.querySelector(i);e&&(this.#x=!1,e.focus(),this.#y=!0,e instanceof HTMLInputElement&&("text"===e.type||"number"===e.type)&&e.select())}}#R(e){const t=this.grid,r=t._rows,o=this.#l?t._focusRow:this.#d,s=t._visibleColumns.map((e,t)=>e.editable?t:-1).filter(e=>e>=0);if(0===s.length)return;const a=s.indexOf(t._focusCol)+(e?1:-1);if(a>=0&&a<s.length){t._focusCol=s[a];const e=t.findRenderedRowElement?.(o),r=e?.querySelector(`.cell[data-col="${s[a]}"]`);if(r?.classList.contains("editing")){const e=r.querySelector(i);e?.focus({preventScroll:!0})}return void n(t,{forceHorizontalScroll:!0})}const l=o+(e?1:-1);l>=0&&l<r.length&&(this.#l?(t._focusRow=l,t._focusCol=e?s[0]:s[s.length-1],n(t,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const e=t.findRenderedRowElement?.(l),n=e?.querySelector(`.cell[data-col="${t._focusCol}"]`);if(n?.classList.contains("editing")){const e=n.querySelector(i);e?.focus({preventScroll:!0})}},0)):(this.#E(o,!1),t._focusRow=l,t._focusCol=e?s[0]:s[s.length-1],this.beginBulkEdit(l),n(t,{forceHorizontalScroll:!0})))}#I(){const e=this.grid;e._activeEditRows=this.#d,e._rowEditSnapshots=this.#g}#F(e,t){if(this.#d!==e){this.#g.set(e,{...t}),this.#d=e,this.#u=t;const i=this.grid;try{this.#c=i.getRowId?.(t)??void 0}catch{this.#c=void 0}this.#I(),this.#l||this.emit("edit-open",{rowIndex:e,rowId:this.#c??"",row:t})}}#E(e,t){if(this.#d!==e)return;const i=this.grid,n=this.#g.get(e),r=i.findRenderedRowElement?.(e);let o=this.#c;const s=o?i._getRowEntry(o):void 0,a=s?.row??this.#u??i._rows[e];if(!o&&a)try{o=i.getRowId?.(a)}catch{}if(!t&&r&&a){r.querySelectorAll(".cell.editing").forEach(t=>{const n=Number(t.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(t.hasAttribute("data-editor-managed"))return;const o=t.querySelector("input,textarea,select");if(o){const t=r.field,i=a[t],n=oe(o,r,i);i!==n&&this.#S(e,r,n,a)}})}if(t||this.#l||!a||this.emit("before-edit-close",{rowIndex:e,rowId:o??"",row:a}),t&&n&&a)Object.keys(n).forEach(e=>{a[e]=n[e]}),o&&(this.#p.delete(o),this.clearRowInvalid(o));else if(!t&&a){const t=this.#M(n,a),i=o?this.#p.has(o):t,r=this.emitCancelable("row-commit",{rowIndex:e,rowId:o??"",row:a,oldValue:n,newValue:a,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(e=>{a[e]=n[e]}),o&&(this.#p.delete(o),this.clearRowInvalid(o))):!r&&t&&this.isAnimationEnabled&&(this.#b=e)}this.#g.delete(e),this.#d=-1,this.#c=void 0,this.#u=void 0,this.#h=-1,this.#C=!1,this.#I();for(const l of this.#f)l.startsWith(`${e}:`)&&this.#f.delete(l);for(const l of this.#m.keys())l.startsWith(`${e}:`)&&this.#m.delete(l);this.#w=!0,r?(r.querySelectorAll(".cell.editing").forEach(e=>{e.classList.remove("editing"),function(e){e.__editingCellCount=0,e.removeAttribute("data-has-editing")}(e.parentElement)}),i.refreshVirtualWindow(!0)):(this.#A(i),this.#w=!1),!this.#l&&a&&this.emit("edit-close",{rowIndex:e,rowId:o??"",row:a,reverted:t})}#S(e,t,i,n){const r=t.field;if(!re(r))return;const o=n[r];if(o===i)return;const s=this.grid;let a;try{a=this.grid.getRowId(n)}catch{}const l=!a||!this.#p.has(a),d=a?e=>this.grid.updateRow(a,e,"cascade"):se;let c=!1;const u=a?e=>{c=!0,this.setInvalid(a,r,e??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:a??"",field:r,oldValue:o,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:d,setInvalid:u}))return;a&&!c&&this.isCellInvalid(a,r)&&this.clearInvalid(a,r),n[r]=i,a&&this.#p.add(a),this.#I(),this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:r,oldValue:o,newValue:i});const h=s.findRenderedRowElement?.(e);h&&h.classList.add("changed")}#_(e,t,n,r,o,s){if(!n.editable)return;if(o.classList.contains("editing"))return;let a;try{a=this.grid.getRowId(e)}catch{}const l=a?e=>this.grid.updateRow(a,e,"cascade"):se,d=re(n.field)?e[n.field]:void 0;o.classList.add("editing"),this.#f.add(`${t}:${r}`);const c=o.parentElement;c&&function(e){const t=(e.__editingCellCount??0)+1;e.__editingCellCount=t,e.setAttribute("data-has-editing","")}(c);let u=!1;const h=i=>{if(u||!this.#l&&-1===this.#d)return;const r=this.grid,o=a?r._getRowEntry(a):void 0,s=o?.row??e,l=o?.index??t;this.#S(l,n,i,s)},g=()=>{if(u=!0,re(n.field)){const t=this.grid,i=a?t._getRowEntry(a):void 0;(i?.row??e)[n.field]=d}},p=document.createElement("div");p.className="tbw-editor-host",o.innerHTML="",o.appendChild(p),p.addEventListener("keydown",e=>{if("Enter"===e.key){if(this.#l){e.stopPropagation(),e.preventDefault();const t=p.querySelector("input,textarea,select");return void(t&&h(oe(t,n,d)))}if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}e.stopPropagation(),e.preventDefault(),u=!0,this.#E(t,!1)}if("Escape"===e.key){if(this.#l)return e.stopPropagation(),void e.preventDefault();if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}e.stopPropagation(),e.preventDefault(),g(),this.#E(t,!0)}});const f=n,m=f.__editorTemplate,w=function(e,t){if(t.editor)return t.editor;if(t.__editorTemplate)return"template";if(!t.type)return;const i=e.effectiveConfig?.typeDefaults;if(i?.[t.type]?.editor)return i[t.type].editor;const n=e.__frameworkAdapter;if(n?.getTypeDefault){const e=n.getTypeDefault(t.type);if(e?.editor)return e.editor}}(this.grid,f)??ne(n),b=d,v=`${t}:${n.field}`,y=[];this.#m.set(v,e=>{for(const t of y)t(e)});const x=e=>{y.push(e)};if("template"===w&&m)this.#D(p,f,e,d,h,g,s,t),x(e=>{const t=p.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if("string"==typeof w){const e=document.createElement(w);e.value=b,e.addEventListener("change",()=>h(e.value)),x(t=>{e.value=t}),p.appendChild(e),s||queueMicrotask(()=>{const e=p.querySelector(i);e?.focus({preventScroll:!0})})}else if("function"==typeof w){const t=w({row:e,rowId:a??"",value:b,field:n.field,column:n,commit:h,cancel:g,updateRow:l,onValueChange:x});if("string"==typeof t)p.innerHTML=t,function(e,t,i,n){const r=e.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(oe(r,t,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(oe(r,t,n))))}(p,n,h,d),x(e=>{const t=p.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if(t instanceof Node){p.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?x(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):o.setAttribute("data-editor-managed","")}s||queueMicrotask(()=>{const e=p.querySelector(i);e?.focus({preventScroll:!0})})}else if(w&&"object"==typeof w){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",n.field),p.appendChild(t),o.setAttribute("data-editor-managed","");const i={row:e,rowId:a??"",value:b,field:n.field,column:n,commit:h,cancel:g,updateRow:l,onValueChange:x};if(w.mount)try{w.mount({placeholder:t,context:i,spec:w})}catch(C){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,C)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:w,context:i}}))}}#D(e,t,i,n,r,o,s,a){const l=t.__editorTemplate;if(!l)return;const d=l.cloneNode(!0),c=t.__compiledEditor;c?d.innerHTML=c({row:i,value:n,field:t.field,column:t,commit:r,cancel:o}):d.querySelectorAll("*").forEach(e=>{1===e.childNodes.length&&e.firstChild?.nodeType===Node.TEXT_NODE&&(e.textContent=e.textContent?.replace(/{{\s*value\s*}}/g,null==n?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(e,t)=>{if(!re(t))return"";const n=i[t];return null==n?"":String(n)})||"")});const u=d.querySelector("input,textarea,select");if(u){u instanceof HTMLInputElement&&"checkbox"===u.type?u.checked=!!n:u.value=String(n??"");let e=!1;u.addEventListener("blur",()=>{e||r(oe(u,t,n))}),u.addEventListener("keydown",i=>{const s=i;if("Enter"===s.key){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(s))return}s.stopPropagation(),s.preventDefault(),e=!0,r(oe(u,t,n)),this.#E(a,!1)}if("Escape"===s.key){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(s))return}s.stopPropagation(),s.preventDefault(),o(),this.#E(a,!0)}}),u instanceof HTMLInputElement&&"checkbox"===u.type&&u.addEventListener("change",()=>r(u.checked)),s||setTimeout(()=>u.focus({preventScroll:!0}),0)}e.appendChild(d)}#M(e,t){if(!e)return!1;const i=e,n=t,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const o of r)if(i[o]!==n[o])return!0;return!1}#A(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,n=e.findRenderedRowElement?.(t);if(n){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(e=>e.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}function le(e,t=!0){if(null==e)return"";if(e instanceof Date)return e.toISOString();if("object"==typeof e)return JSON.stringify(e);const i=String(e);return t&&(i.includes(",")||i.includes('"')||i.includes("\n")||i.includes("\r"))?`"${i.replace(/"/g,'""')}"`:i}function de(e,t){const i=URL.createObjectURL(e),n=document.createElement("a");n.href=i,n.download=t,n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(i)}function ce(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}class ue extends e{name="export";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const i=this.config,n={format:e,fileName:t?.fileName??i.fileName??"export",includeHeaders:t?.includeHeaders??i.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices},r=F(this.columns,t?.columns,i.onlyVisible);let o;if(t?.rowIndices)o=M(this.rows,t.rowIndices);else if(i.onlySelected){const e=this.getSelectionState();o=e?.selected?.size?M(this.rows,[...e.selected]):[...this.rows]}else o=[...this.rows];this.isExportingFlag=!0;let s=n.fileName;try{switch(e){case"csv":{const e=function(e,t,i,n={}){const r=n.delimiter??",",o=n.newline??"\n",s=[],a=n.bom?"\ufeff":"";if(!1!==i.includeHeaders){const e=t.map(e=>{const t=e.header||e.field;return le(i.processHeader?i.processHeader(t,e.field):t)});s.push(e.join(r))}for(const l of e){const e=t.map(e=>{let t=l[e.field];return i.processCell&&(t=i.processCell(t,e.field,l)),le(t)});s.push(e.join(r))}return a+s.join(o)}(o,r,n,{bom:!0});s=s.endsWith(".csv")?s:`${s}.csv`,function(e,t){de(new Blob([e],{type:"text/csv;charset=utf-8;"}),t)}(e,s);break}case"excel":{const e=function(e,t,i){let n='<?xml version="1.0" encoding="UTF-8"?>\n<?mso-application progid="Excel.Sheet"?>\n<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"\n xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">\n<Worksheet ss:Name="Sheet1">\n<Table>';if(!1!==i.includeHeaders){n+="\n<Row>";for(const e of t){const t=e.header||e.field;n+=`<Cell><Data ss:Type="String">${ce(i.processHeader?i.processHeader(t,e.field):t)}</Data></Cell>`}n+="</Row>"}for(const r of e){n+="\n<Row>";for(const e of t){let t=r[e.field];i.processCell&&(t=i.processCell(t,e.field,r));let o="String",s="";null==t?s="":"number"!=typeof t||isNaN(t)?t instanceof Date?(o="DateTime",s=t.toISOString()):s=ce(String(t)):(o="Number",s=String(t)),n+=`<Cell><Data ss:Type="${o}">${s}</Data></Cell>`}n+="</Row>"}return n+="\n</Table>\n</Worksheet>\n</Workbook>",n}(o,r,n);s=s.endsWith(".xls")?s:`${s}.xls`,function(e,t){const i=t.endsWith(".xls")?t:`${t}.xls`;de(new Blob([e],{type:"application/vnd.ms-excel;charset=utf-8;"}),i)}(e,s);break}case"json":{const e=o.map(e=>{const t={};for(const i of r){let r=e[i.field];n.processCell&&(r=n.processCell(r,i.field,e)),t[i.field]=r}return t}),t=JSON.stringify(e,null,2);s=s.endsWith(".json")?s:`${s}.json`;de(new Blob([t],{type:"application/json"}),s);break}}this.lastExportInfo={format:e,timestamp:/* @__PURE__ */new Date},this.emit("export-complete",{format:e,fileName:s,rowCount:o.length,columnCount:r.length})}finally{this.isExportingFlag=!1}}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}const he="(Blank)";function ge(e){if(e instanceof Date)return e.getTime();const t=Number(e);if(!isNaN(t))return t;return new Date(e).getTime()}function pe(e,t,i=!1,n){return t.length?e.filter(e=>t.every(t=>function(e,t,i=!1,n){const r=e[t.field];if("blank"===t.operator)return null==r||""===r;if("notBlank"===t.operator)return null!=r&&""!==r;if(n&&("notIn"===t.operator||"in"===t.operator)){const i=n(r,e),o=Array.isArray(i)?i:null!=i?[i]:[];if("notIn"===t.operator){const e=t.value;return!Array.isArray(e)||(0===o.length?!e.includes(he):!o.some(t=>e.includes(t)))}if("in"===t.operator){const e=t.value;return!!Array.isArray(e)&&(0===o.length?e.includes(he):o.some(t=>e.includes(t)))}}if("notIn"===t.operator)return null==r||""===r?!Array.isArray(t.value)||!t.value.includes(he):Array.isArray(t.value)&&!t.value.includes(r);if("in"===t.operator)return null==r||""===r?Array.isArray(t.value)&&t.value.includes(he):Array.isArray(t.value)&&t.value.includes(r);if(null==r)return!1;const o=String(r),s=i?o:o.toLowerCase(),a=i?String(t.value):String(t.value).toLowerCase();switch(t.operator){case"contains":return s.includes(a);case"notContains":return!s.includes(a);case"equals":return s===a;case"notEquals":return s!==a;case"startsWith":return s.startsWith(a);case"endsWith":return s.endsWith(a);case"lessThan":return ge(r)<ge(t.value);case"lessThanOrEqual":return ge(r)<=ge(t.value);case"greaterThan":return ge(r)>ge(t.value);case"greaterThanOrEqual":return ge(r)>=ge(t.value);case"between":return ge(r)>=ge(t.value)&&ge(r)<=ge(t.valueTo);default:return!0}}(e,t,i,n?.get(t.field)))):e}function fe(e,t,i){const n=/* @__PURE__ */new Set;let r=!1;for(const o of e){const e=o[t];if(i){const t=i(e,o);if(Array.isArray(t)){0===t.length&&(r=!0);for(const e of t)null!=e&&n.add(e)}else null!=t?n.add(t):r=!0}else null!=e&&""!==e?n.add(e):r=!0}return r&&n.add(he),[...n].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t)))}function me(e,t){const i=/* @__PURE__ */new Map;for(const{field:r,filterValue:o}of t)i.set(r,{values:/* @__PURE__ */new Set,hasBlank:!1,hasExtractor:!!o});for(const r of e)for(const{field:e,filterValue:n}of t){const t=i.get(e),o=r[e];if(n){const e=n(o,r);if(Array.isArray(e)){0===e.length&&(t.hasBlank=!0);for(const i of e)null!=i&&t.values.add(i)}else null!=e?t.values.add(e):t.hasBlank=!0}else null!=o&&""!==o?t.values.add(o):t.hasBlank=!0}const n=/* @__PURE__ */new Map;for(const[r,{values:o,hasBlank:s}]of i)s&&o.add(he),n.set(r,[...o].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t))));return n}const we="__tbw_expander";function be(e){return e.field===we}function ve(e){return!0===e.meta?.utility}class ye extends e{static manifest={events:[{type:"filter-applied",description:"Emitted when filter criteria change. Subscribers can react to row visibility changes."}],queries:[{type:"getContextMenuItems",description:"Contributes filter-related items to the header context menu"}]};name="filtering";styles='@layer tbw-plugins{tbw-grid{.tbw-quick-filter-input{flex:1;max-width:300px;height:var(--tbw-input-height, 1.75rem);padding:var(--tbw-input-padding, 0 .5rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:var(--tbw-font-size-sm, .8125rem);&:focus{outline:none;border-color:var(--tbw-color-accent)}}.header-cell.filtered:before{content:"";position:absolute;top:var(--tbw-spacing-xs, .25rem);right:var(--tbw-spacing-xs, .25rem);width:var(--tbw-indicator-size, .375rem);height:var(--tbw-indicator-size, .375rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}.tbw-filter-btn{display:var(--tbw-filter-btn-display, inline-flex);visibility:var(--tbw-filter-btn-visibility, visible);align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:var(--tbw-spacing-xs, .25rem);opacity:.4;transition:opacity .15s,visibility 0s,display 0s allow-discrete;color:inherit;vertical-align:middle;transition-behavior:allow-discrete;&:hover,&.active{opacity:1;visibility:visible;display:inline-flex}&.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}}.header-row .cell:hover .tbw-filter-btn,.header-row .cell.filtered .tbw-filter-btn{display:inline-flex;visibility:visible}}}';get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}isFilteringEnabled(){return!1!==this.grid.effectiveConfig?.filterable}isColumnFilterable(e){return!!this.isFilteringEnabled()&&!1!==e.filterable}getFilterValues(){const e=this.grid.effectiveConfig?.columns;if(!e)return;let t;for(const i of e)i.field&&i.filterValue&&(t||(t=/* @__PURE__ */new Map),t.set(i.field,i.filterValue));return t}filters=/* @__PURE__ */new Map;cachedResult=null;cacheKey=null;cachedInputSpot=null;openPanelField=null;panelElement=null;panelAnchorElement=null;searchText=/* @__PURE__ */new Map;excludedValues=/* @__PURE__ */new Map;panelAbortController=null;globalStylesInjected=!1;static DEFAULT_LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;getListItemHeight(){if(this.panelElement){const e=getComputedStyle(this.panelElement).getPropertyValue("--tbw-filter-item-height");if(e&&e.trim()){const t=parseFloat(e);if(!isNaN(t)&&t>0)return t}}return ye.DEFAULT_LIST_ITEM_HEIGHT}computeSelected(){const e=[];for(const[n,r]of this.filters){if("set"!==r.type||"notIn"!==r.operator)continue;const t=this.grid.effectiveConfig?.columns?.find(e=>e.field===n);e.push({field:n,filterValue:t?.filterValue})}if(0===e.length)return{};const t=me(this.sourceRows,e),i={};for(const{field:n}of e){const e=this.excludedValues.get(n),r=t.get(n)??[];i[n]=e?r.filter(t=>!e.has(t)):r}return i}syncExcludedValues(e,t){t?"set"===t.type&&"notIn"===t.operator&&Array.isArray(t.value)?this.excludedValues.set(e,new Set(t.value)):"set"===t.type&&this.excludedValues.delete(e):this.excludedValues.delete(e)}attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.panelAbortController?.abort(),this.panelAbortController=null}handleQuery(e){if("getContextMenuItems"===e.type){const t=e.context;if(!t.isHeader)return;const i=t.column;if(!i?.field)return;if(!this.isFilteringEnabled())return;if(!this.isColumnFilterable(i))return;const n=[],r=this.isFieldFiltered(i.field),o=this.filters.size>0;return r&&n.push({id:"filtering/clear-column-filter",label:"Clear Filter",icon:"✕",order:20,action:()=>this.clearFieldFilter(i.field)}),o&&n.push({id:"filtering/clear-all-filters",label:"Clear All Filters",icon:"✕",order:21,disabled:!o,action:()=>this.clearAllFilters()}),n.length>0?n:void 0}}processRows(e){const t=[...this.filters.values()];if(!t.length)return[...e];if(this.config.filterHandler)return this.cachedResult?this.cachedResult:[...e];const i=(n=t,JSON.stringify(n.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo}))));var n;const r={len:e.length,first:e[0],mid:e[Math.floor(e.length/2)],last:e[e.length-1]},o=null!=this.cachedInputSpot&&r.len===this.cachedInputSpot.len&&r.first===this.cachedInputSpot.first&&r.mid===this.cachedInputSpot.mid&&r.last===this.cachedInputSpot.last;if(this.cacheKey===i&&this.cachedResult&&o)return this.cachedResult;const s=pe([...e],t,this.config.caseSensitive,this.getFilterValues());return this.cachedResult=s,this.cacheKey=i,this.cachedInputSpot=r,s}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(e=>{const t=e.getAttribute("data-col");if(null===t)return;const i=this.visibleColumns[parseInt(t,10)];if(!i||!this.isColumnFilterable(i))return;if(ve(i))return;const n=i.field;if(!n)return;const r=this.filters.has(n);let o=e.querySelector(".tbw-filter-btn");if(o){const t=o.classList.contains("active");if(o.classList.toggle("active",r),e.classList.toggle("filtered",r),t!==r){const e=r?"filterActive":"filter";this.setIcon(o,this.resolveIcon(e))}return}o=document.createElement("button"),o.className="tbw-filter-btn",o.setAttribute("aria-label",`Filter ${i.header??n}`);const s=r?"filterActive":"filter";this.setIcon(o,this.resolveIcon(s)),r&&(o.classList.add("active"),e.classList.add("filtered")),o.addEventListener("click",e=>{e.stopPropagation(),this.toggleFilterPanel(n,i,o)});const a=e.querySelector(".resize-handle");a?e.insertBefore(o,a):e.appendChild(o)})}setFilter(e,t){if(null===t)this.filters.delete(e),this.syncExcludedValues(e,null);else{const i={...t,field:e};this.filters.set(e,i),this.syncExcludedValues(e,i)}this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0,selected:this.computeSelected()}),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e){this.filters.clear(),this.excludedValues.clear();for(const t of e)this.filters.set(t.field,t),this.syncExcludedValues(t.field,t);this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0,selected:this.computeSelected()}),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}clearAllFilters(){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal()}clearFieldFilter(e){this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal()}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){const t=this.grid.effectiveConfig?.columns?.find(t=>t.field===e),i=t?.filterValue;return fe(this.sourceRows,e,i)}copyGridThemeContext(e){const t=this.gridElement;if(!t)return;for(const n of t.classList)n.startsWith("tbw-")||"selecting"===n||e.classList.add(n);const i=t.dataset.theme;i&&(e.dataset.theme=i)}injectGlobalStyles(){if(this.globalStylesInjected)return;if(document.getElementById("tbw-filter-panel-styles"))return void(this.globalStylesInjected=!0);const e=document.createElement("style");e.id="tbw-filter-panel-styles",e.textContent="@layer tbw-plugins{.tbw-filter-panel{position:fixed;background:var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));color:var(--tbw-filter-panel-fg, var(--tbw-color-fg, light-dark(#222222, #eeeeee)));border:1px solid var(--tbw-filter-panel-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-panel-radius, var(--tbw-border-radius, .25rem));box-shadow:0 4px 16px var(--tbw-filter-panel-shadow, var(--tbw-color-shadow, light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3))));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));z-index:10000;min-width:200px;max-width:280px;max-height:350px;display:flex;flex-direction:column;font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-font-size, .8125rem);transform-origin:top center}.tbw-filter-panel.tbw-filter-panel-above{transform-origin:bottom center}.tbw-filter-panel.tbw-filter-panel-animated{animation:tbw-filter-panel-enter var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}.tbw-filter-panel.tbw-filter-panel-above.tbw-filter-panel-animated{animation:tbw-filter-panel-enter-above var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}@keyframes tbw-filter-panel-enter{0%{opacity:0;transform:scaleY(.3) translateY(-10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@keyframes tbw-filter-panel-enter-above{0%{opacity:0;transform:scaleY(.3) translateY(10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@supports (anchor-name: --test){.tbw-filter-panel{position-anchor:--tbw-filter-anchor;top:anchor(bottom);left:anchor(left);margin-top:4px;position-try-fallbacks:flip-inline,flip-block,flip-block flip-inline}}.tbw-filter-search{margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-search-input{height:var(--tbw-filter-item-height, 28px);width:100%;padding:var(--tbw-filter-search-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-search-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-actions{display:flex;padding:var(--tbw-button-padding-sm, .25rem .125rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-actions .tbw-filter-value-item{flex:1}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));max-height:180px;position:relative}.tbw-filter-values-spacer{width:1px}.tbw-filter-values-content{position:absolute;top:0;left:0;right:0}.tbw-filter-value-item{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding-sm, .25rem .125rem);cursor:pointer;border-radius:3px;height:var(--tbw-filter-item-height, 28px)}.tbw-filter-value-item:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-checkbox{margin:0;cursor:pointer;accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}.tbw-filter-no-match{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem)) 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding-top:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));color:var(--tbw-filter-accent-fg, var(--tbw-color-accent-fg, light-dark(#ffffff, #000000)));border:none;border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:transparent;color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-range-inputs,.tbw-filter-date-range{display:flex;align-items:flex-end;gap:var(--tbw-spacing-sm, .375rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-group,.tbw-filter-date-group{display:flex;flex-direction:column;gap:var(--tbw-spacing-xs, .25rem);flex:1}.tbw-filter-range-label{font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)))}.tbw-filter-range-input,.tbw-filter-date-input{width:100%;height:var(--tbw-filter-item-height, 28px);padding:var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-sm, .375rem);background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-range-input:focus,.tbw-filter-date-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-range-separator{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding-bottom:var(--tbw-spacing-xs, .25rem)}.tbw-filter-blank-option{display:flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-spacing-xs, .25rem) 0;margin-bottom:var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-sm, .8125rem);cursor:pointer;user-select:none}.tbw-filter-blank-checkbox{accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));margin:0;cursor:pointer}.tbw-filter-date-range.tbw-filter-disabled,.tbw-filter-range-inputs.tbw-filter-disabled,.tbw-filter-range-slider.tbw-filter-disabled{opacity:.4;pointer-events:none}.tbw-filter-range-slider{position:relative;height:24px;margin:var(--tbw-spacing-md, .5rem) 0 var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-track{position:absolute;top:50%;left:0;right:0;height:4px;background:var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-fill{position:absolute;top:50%;height:4px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-thumb{position:absolute;top:0;width:100%;height:100%;background:none;pointer-events:none;-webkit-appearance:none;appearance:none}.tbw-filter-range-thumb::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-moz-range-thumb{width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-webkit-slider-thumb:hover{transform:scale(1.1)}.tbw-filter-range-thumb::-moz-range-thumb:hover{transform:scale(1.1)}}",document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,i){if(this.openPanelField===e)return void this.closeFilterPanel();this.closeFilterPanel();const n=document.createElement("div");if(n.className="tbw-filter-panel",this.copyGridThemeContext(n),this.isAnimationEnabled&&n.classList.add("tbw-filter-panel-animated"),this.panelElement=n,this.openPanelField=e,this.config.valuesHandler)return n.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(n),this.positionPanel(n,i),this.setupPanelCloseHandler(n,i),void this.config.valuesHandler(e,t).then(i=>{this.openPanelField===e&&this.panelElement&&(n.innerHTML="",this.renderPanelContent(e,t,n,i))});const r=fe(this.sourceRows,e,t.filterValue);document.body.appendChild(n),this.positionPanel(n,i),this.renderPanelContent(e,t,n,r),this.setupPanelCloseHandler(n,i)}renderPanelContent(e,t,i,n){let r=this.excludedValues.get(e);r||(r=/* @__PURE__ */new Set,this.excludedValues.set(e,r));const o=this.searchText.get(e)??"",s={field:e,column:t,uniqueValues:n,excludedValues:r,searchText:o,currentFilter:this.filters.get(e),applySetFilter:(t,i)=>{this.applySetFilter(e,t,i),this.closeFilterPanel()},applyTextFilter:(t,i,n)=>{this.applyTextFilter(e,t,i,n),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(e),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let a=!1;if(this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,s),a=i.children.length>0),!a&&t.type){const e=this.grid.effectiveConfig.typeDefaults?.[t.type];e?.filterPanelRenderer&&(e.filterPanelRenderer(i,s),a=i.children.length>0)}if(!a){const e=t.type;"number"===e?this.renderNumberFilterPanel(i,s,n):"date"===e?this.renderDateFilterPanel(i,s,n):this.renderDefaultFilterPanel(i,s,n,r)}}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",i=>{e.contains(i.target)||i.target===t||this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){const e=this.panelElement;e&&(e.remove(),this.panelElement=null),this.panelAnchorElement&&(this.panelAnchorElement.style.anchorName="",this.panelAnchorElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}static supportsAnchorPositioning=null;static checkAnchorPositioningSupport(){return null===ye.supportsAnchorPositioning&&(ye.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),ye.supportsAnchorPositioning}positionPanel(e,t){const i=t.closest(".cell")??t;if(i.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=i,ye.checkAnchorPositioningSupport())return void requestAnimationFrame(()=>{const t=e.getBoundingClientRect(),n=i.getBoundingClientRect();t.top<n.top&&e.classList.add("tbw-filter-panel-above")});const n=i.getBoundingClientRect();e.style.position="fixed",e.style.top=`${n.bottom+4}px`,e.style.left=`${n.left}px`,requestAnimationFrame(()=>{const t=e.getBoundingClientRect();t.right>window.innerWidth-8&&(e.style.left=n.right-t.width+"px"),t.bottom>window.innerHeight-8&&(e.style.top=n.top-t.height-4+"px",e.classList.add("tbw-filter-panel-above"))})}renderDefaultFilterPanel(e,t,i,n){const{field:s,column:a}=t,l=this.getListItemHeight(),d=e=>{if(null==e)return"(Blank)";if(a.format&&!a.filterValue){const t=a.format(e,void 0);if(t)return t}return String(e)};i=i.slice().sort((e,t)=>d(e).localeCompare(d(t)));const c=document.createElement("div");c.className="tbw-filter-search";const u=document.createElement("input");u.type="text",u.placeholder="Search...",u.className="tbw-filter-search-input",u.value=this.searchText.get(s)??"",c.appendChild(u),e.appendChild(c);const h=document.createElement("div");h.className="tbw-filter-actions";const g=document.createElement("label");g.className="tbw-filter-value-item",g.style.padding="0",g.style.margin="0";const p=document.createElement("input");p.type="checkbox",p.className="tbw-filter-checkbox";const f=document.createElement("span");f.textContent="Select All",g.appendChild(p),g.appendChild(f),h.appendChild(g);const m=()=>{const e=[...y.values()],t=e.every(e=>e),i=e.every(e=>!e);p.checked=t,p.indeterminate=!t&&!i};p.addEventListener("change",()=>{const e=p.checked;for(const t of y.keys())y.set(t,e);m(),E()}),e.appendChild(h);const w=document.createElement("div");w.className="tbw-filter-values";const b=document.createElement("div");b.className="tbw-filter-values-spacer",w.appendChild(b);const v=document.createElement("div");v.className="tbw-filter-values-content",w.appendChild(v);const y=/* @__PURE__ */new Map;i.forEach(e=>{const t=null==e?"__null__":String(e);y.set(t,!n.has(e))}),m();let x=[];const C=(e,t)=>{const i=d(e),n=null==e?"__null__":String(e),r=document.createElement("label");r.className="tbw-filter-value-item",r.style.position="absolute",r.style.top=`calc(var(--tbw-filter-item-height, 28px) * ${t})`,r.style.left="0",r.style.right="0",r.style.boxSizing="border-box";const o=document.createElement("input");o.type="checkbox",o.className="tbw-filter-checkbox",o.checked=y.get(n)??!0,o.dataset.value=n,o.addEventListener("change",()=>{y.set(n,o.checked),m()});const s=document.createElement("span");return s.textContent=i,r.appendChild(o),r.appendChild(s),r},E=()=>{const e=x.length,t=w.clientHeight,i=w.scrollTop;if(b.style.height=e*l+"px",r(e,ye.LIST_BYPASS_THRESHOLD/3))return v.innerHTML="",v.style.transform="translateY(0px)",void x.forEach((e,t)=>{v.appendChild(C(e,t))});const n=o({totalRows:e,viewportHeight:t,scrollTop:i,rowHeight:l,overscan:ye.LIST_OVERSCAN});v.style.transform=`translateY(${n.offsetY}px)`,v.innerHTML="";for(let r=n.start;r<n.end;r++)v.appendChild(C(x[r],r-n.start))},R=e=>{const t=this.config.caseSensitive??!1,n=t?e:e.toLowerCase();if(x=i.filter(i=>{const r=d(i),o=t?r:r.toLowerCase();return!e||o.includes(n)}),0===x.length){b.style.height="0px",v.innerHTML="";const e=document.createElement("div");return e.className="tbw-filter-no-match",e.textContent="No matching values",void v.appendChild(e)}E()};let S;w.addEventListener("scroll",()=>{x.length>0&&E()},{passive:!0}),R(u.value),e.appendChild(w),u.addEventListener("input",()=>{clearTimeout(S),S=setTimeout(()=>{this.searchText.set(s,u.value),R(u.value)},this.config.debounceMs??150)});const k=document.createElement("div");k.className="tbw-filter-buttons";const A=document.createElement("button");A.className="tbw-filter-apply-btn",A.textContent="Apply",A.addEventListener("click",()=>{const e=[];for(const[t,n]of y)if(!n)if("__null__"===t)e.push(null);else{const n=i.find(e=>String(e)===t);e.push(void 0!==n?n:t)}t.applySetFilter(e)}),k.appendChild(A);const _=document.createElement("button");_.className="tbw-filter-clear-btn",_.textContent="Clear Filter",_.addEventListener("click",()=>{t.clearFilter()}),k.appendChild(_),e.appendChild(k)}renderNumberFilterPanel(e,t,i){const{field:n,column:r}=t,o=r.filterParams,s=r.editorParams,a=(e,t)=>{if("number"==typeof e)return e;if("string"==typeof e){const i=parseFloat(e);return isNaN(i)?t:i}return t},l=i.filter(e=>"number"==typeof e&&!isNaN(e)),d=l.length>0?Math.min(...l):0,c=l.length>0?Math.max(...l):100,u=a(o?.min??s?.min,d),h=a(o?.max??s?.max,c),g=o?.step??s?.step??1,p=this.filters.get(n);let f=u,m=h;const w="blank"===p?.operator;"between"===p?.operator?(f=a(p.value,u),m=a(p.valueTo,h)):"greaterThanOrEqual"===p?.operator?f=a(p.value,u):"lessThanOrEqual"===p?.operator&&(m=a(p.value,h));const b=document.createElement("div");b.className="tbw-filter-range-inputs";const v=document.createElement("div");v.className="tbw-filter-range-group";const y=document.createElement("label");y.textContent="Min",y.className="tbw-filter-range-label";const x=document.createElement("input");x.type="number",x.className="tbw-filter-range-input",x.min=String(u),x.max=String(h),x.step=String(g),x.value=String(f),v.appendChild(y),v.appendChild(x),b.appendChild(v);const C=document.createElement("span");C.className="tbw-filter-range-separator",C.textContent="–",b.appendChild(C);const E=document.createElement("div");E.className="tbw-filter-range-group";const R=document.createElement("label");R.textContent="Max",R.className="tbw-filter-range-label";const S=document.createElement("input");S.type="number",S.className="tbw-filter-range-input",S.min=String(u),S.max=String(h),S.step=String(g),S.value=String(m),E.appendChild(R),E.appendChild(S),b.appendChild(E),e.appendChild(b);const k=document.createElement("div");k.className="tbw-filter-range-slider";const A=document.createElement("div");A.className="tbw-filter-range-track";const _=document.createElement("div");_.className="tbw-filter-range-fill";const L=document.createElement("input");L.type="range",L.className="tbw-filter-range-thumb tbw-filter-range-thumb-min",L.min=String(u),L.max=String(h),L.step=String(g),L.value=String(f);const I=document.createElement("input");I.type="range",I.className="tbw-filter-range-thumb tbw-filter-range-thumb-max",I.min=String(u),I.max=String(h),I.step=String(g),I.value=String(m),k.appendChild(A),k.appendChild(_),k.appendChild(L),k.appendChild(I),e.appendChild(k);const T=document.createElement("label");T.className="tbw-filter-blank-option";const F=document.createElement("input");F.type="checkbox",F.className="tbw-filter-blank-checkbox",F.checked=w;const M=document.createTextNode("Blank");T.appendChild(F),T.appendChild(M);const D=e=>{x.disabled=e,S.disabled=e,L.disabled=e,I.disabled=e,b.classList.toggle("tbw-filter-disabled",e),k.classList.toggle("tbw-filter-disabled",e)};D(w),F.addEventListener("change",()=>{D(F.checked)}),e.appendChild(T);const P=()=>{const e=parseFloat(L.value),t=parseFloat(I.value),i=h-u,n=(e-u)/i*100,r=(t-u)/i*100;_.style.left=`${n}%`,_.style.width=r-n+"%"};L.addEventListener("input",()=>{const e=Math.min(parseFloat(L.value),parseFloat(I.value));L.value=String(e),x.value=String(e),P()}),I.addEventListener("input",()=>{const e=Math.max(parseFloat(I.value),parseFloat(L.value));I.value=String(e),S.value=String(e),P()}),x.addEventListener("input",()=>{let e=parseFloat(x.value)||u;e=Math.max(u,Math.min(e,parseFloat(S.value))),L.value=String(e),P()}),S.addEventListener("input",()=>{let e=parseFloat(S.value)||h;e=Math.min(h,Math.max(e,parseFloat(x.value))),I.value=String(e),P()}),P();const q=document.createElement("div");q.className="tbw-filter-buttons";const H=document.createElement("button");H.className="tbw-filter-apply-btn",H.textContent="Apply",H.addEventListener("click",()=>{if(F.checked)return void t.applyTextFilter("blank","");const e=parseFloat(x.value),i=parseFloat(S.value);t.applyTextFilter("between",e,i)}),q.appendChild(H);const N=document.createElement("button");N.className="tbw-filter-clear-btn",N.textContent="Clear Filter",N.addEventListener("click",()=>{t.clearFilter()}),q.appendChild(N),e.appendChild(q)}renderDateFilterPanel(e,t,i){const{field:n,column:r}=t,o=r.filterParams,s=r.editorParams,a=i.filter(e=>e instanceof Date||"string"==typeof e&&!isNaN(Date.parse(e))).map(e=>e instanceof Date?e:new Date(e)).filter(e=>!isNaN(e.getTime())),l=a.length>0?new Date(Math.min(...a.map(e=>e.getTime()))):null,d=a.length>0?new Date(Math.max(...a.map(e=>e.getTime()))):null,c=e=>e?e.toISOString().split("T")[0]:"",u=e=>e?"string"==typeof e?e:"number"==typeof e?c(new Date(e)):"":"",h=u(o?.min)||u(s?.min)||c(l),g=u(o?.max)||u(s?.max)||c(d),p=this.filters.get(n);let f="",m="";const w="blank"===p?.operator;"between"===p?.operator?(f=u(p.value)||"",m=u(p.valueTo)||""):"greaterThanOrEqual"===p?.operator?f=u(p.value)||"":"lessThanOrEqual"===p?.operator&&(m=u(p.value)||"");const b=document.createElement("div");b.className="tbw-filter-date-range";const v=document.createElement("div");v.className="tbw-filter-date-group";const y=document.createElement("label");y.textContent="From",y.className="tbw-filter-range-label";const x=document.createElement("input");x.type="date",x.className="tbw-filter-date-input",h&&(x.min=h),g&&(x.max=g),x.value=f,v.appendChild(y),v.appendChild(x),b.appendChild(v);const C=document.createElement("span");C.className="tbw-filter-range-separator",C.textContent="–",b.appendChild(C);const E=document.createElement("div");E.className="tbw-filter-date-group";const R=document.createElement("label");R.textContent="To",R.className="tbw-filter-range-label";const S=document.createElement("input");S.type="date",S.className="tbw-filter-date-input",h&&(S.min=h),g&&(S.max=g),S.value=m,E.appendChild(R),E.appendChild(S),b.appendChild(E),e.appendChild(b);const k=document.createElement("label");k.className="tbw-filter-blank-option";const A=document.createElement("input");A.type="checkbox",A.className="tbw-filter-blank-checkbox",A.checked=w;const _=document.createTextNode("Show only blank");k.appendChild(A),k.appendChild(_);const L=e=>{x.disabled=e,S.disabled=e,b.classList.toggle("tbw-filter-disabled",e)};L(w),A.addEventListener("change",()=>{L(A.checked)}),e.appendChild(k);const I=document.createElement("div");I.className="tbw-filter-buttons";const T=document.createElement("button");T.className="tbw-filter-apply-btn",T.textContent="Apply",T.addEventListener("click",()=>{if(A.checked)return void t.applyTextFilter("blank","");const e=x.value,i=S.value;e&&i?t.applyTextFilter("between",e,i):e?t.applyTextFilter("greaterThanOrEqual",e):i?t.applyTextFilter("lessThanOrEqual",i):t.clearFilter()}),I.appendChild(T);const F=document.createElement("button");F.className="tbw-filter-clear-btn",F.textContent="Clear Filter",F.addEventListener("click",()=>{t.clearFilter()}),I.appendChild(F),e.appendChild(I)}applySetFilter(e,t,i){this.excludedValues.set(e,new Set(t)),0===t.length?this.filters.delete(e):this.filters.set(e,{field:e,type:"set",operator:"notIn",value:t,...void 0!==i&&{valueTo:i}}),this.applyFiltersInternal()}applyTextFilter(e,t,i,n){this.filters.set(e,{field:e,type:"text",operator:t,value:i,valueTo:n}),this.applyFiltersInternal()}applyFiltersInternal(){this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null;const e=[...this.filters.values()];if(this.config.filterHandler){const t=this.grid;t.setAttribute("aria-busy","true");const i=this.config.filterHandler(e,this.sourceRows),n=i=>{t.removeAttribute("aria-busy"),this.cachedResult=i,this.grid.rows=i,this.emit("filter-change",{filters:e,filteredRowCount:i.length,selected:this.computeSelected()}),this.emitPluginEvent("filter-applied",{filters:e}),this.requestRender()};return void(i&&"function"==typeof i.then?i.then(n):n(i))}this.emit("filter-change",{filters:e,filteredRowCount:0,selected:this.computeSelected()}),this.emitPluginEvent("filter-applied",{filters:e}),this.requestRender()}getColumnState(e){const t=this.filters.get(e);if(t)return{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}}applyColumnState(e,t){if(!t.filter)return void this.filters.delete(e);const i={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,i),this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null}}function xe(e){if(!e.length)return[];const t=/* @__PURE__ */new Map,i=[],n=(e,t)=>{if(!t.length)return;const n=i[i.length-1];n&&n.implicit&&n.firstIndex+n.columns.length===e?n.columns.push(...t):i.push({id:"__implicit__"+e,label:void 0,columns:t,firstIndex:e,implicit:!0})};let r=[],o=0;return e.forEach((e,s)=>{const a=e.group;if(!a)return 0===r.length&&(o=s),void r.push(e);r.length&&(n(o,r.slice()),r=[]);const l="string"==typeof a?a:a.id;let d=t.get(l);d||(d={id:l,label:"string"==typeof a?void 0:a.label,columns:[],firstIndex:s},t.set(l,d),i.push(d)),d.columns.push(e)}),r.length&&n(o,r),1===i.length&&i[0].implicit&&i[0].columns.length===e.length?[]:i}class Ce extends e{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}],queries:[{type:"getColumnGrouping",description:"Returns column group metadata for the visibility panel"}]};name="groupingColumns";styles="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";get defaultConfig(){return{showGroupBorders:!0,lockGroupOrder:!1}}groups=[];isActive=!1;#P=/* @__PURE__ */new Set;attach(e){super.attach(e),e.addEventListener("column-move",this.#q,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#P.clear()}#q=e=>{if(!this.isActive)return;const t=e,{field:i,columnOrder:n}=t.detail;if(this.config.lockGroupOrder)for(const r of this.groups)if(!r.id.startsWith("__implicit__")&&!this.#H(r,n))return t.preventDefault(),void this.#N(i);this.#z(n)};#z(e){this.#P.clear();const t=this.#G(e);for(const i of this.groups){const n=new Set(i.columns.map(e=>e.field));for(let i=e.length-1;i>=0;i--)if(n.has(e[i])){const n=e[i];n!==t&&this.#P.add(n);break}}}#G(e){if(0===this.groups.length)return null;for(let t=e.length-1;t>=0;t--){const i=e[t];for(const t of this.groups)if(t.columns.some(e=>e.field===i)){const i=new Set(t.columns.map(e=>e.field));for(let t=e.length-1;t>=0;t--)if(i.has(e[t]))return e[t]}}return null}#H(e,t){const i=e.columns.map(e=>t.indexOf(e.field)).filter(e=>-1!==e).sort((e,t)=>e-t);return i.length<=1||i.length===i[i.length-1]-i[0]+1}#N(e){const t=this.gridElement?.querySelector(`.header-row [part~="header-cell"][data-field="${e}"]`);t&&(t.style.setProperty("--_flash-color","var(--tbw-color-error)"),t.animate([{backgroundColor:"rgba(from var(--_flash-color) r g b / 30%)"},{backgroundColor:"transparent"}],{duration:400,easing:"ease-out"}))}handleQuery(e){if("getColumnGrouping"===e.type)return this.#K()}#K(){let e;const t=this.grid?.gridConfig?.columnGroups;if(t&&Array.isArray(t)&&t.length>0)e=t.filter(e=>e.children.length>0).map(e=>({id:e.id,label:e.header,fields:[...e.children]}));else if(this.isActive&&this.groups.length>0){e=this.groups.filter(e=>!e.id.startsWith("__implicit__")).map(e=>({id:e.id,label:e.label??e.id,fields:e.columns.map(e=>e.field)}));const t=this.columns;for(const i of t)if(i.hidden&&i.group){const t="string"==typeof i.group?i.group:i.group.id,n="string"==typeof i.group?i.group:i.group.label??i.group.id,r=e.find(e=>e.id===t);r?r.fields.includes(i.field)||r.fields.push(i.field):e.push({id:t,label:n,fields:[i.field]})}}else{const t=this.columns,i=/* @__PURE__ */new Map;for(const e of t){if(!e.group)continue;const t="string"==typeof e.group?e.group:e.group.id,n="string"==typeof e.group?e.group:e.group.label??e.group.id,r=i.get(t);r?r.fields.includes(e.field)||r.fields.push(e.field):i.set(t,{id:t,label:n,fields:[e.field]})}e=Array.from(i.values())}const i=this.grid?.getColumnOrder();if(i&&i.length>0){const t=new Map(i.map((e,t)=>[e,t]));for(const i of e)i.fields.sort((e,i)=>(t.get(e)??1/0)-(t.get(i)??1/0))}return e}static detect(e,t){if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const i=t?.columns;return!!Array.isArray(i)&&function(e){return e.some(e=>null!=e.group)}(i)}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let i;if(t&&Array.isArray(t)&&t.length>0){const n=/* @__PURE__ */new Map;for(const e of t)for(const t of e.children)n.set(t,{id:e.id,label:e.header});i=e.map(e=>{const t=n.get(e.field);return t&&!e.group?{...e,group:t}:e})}else i=[...e];const n=xe(i);if(0===n.length)return this.isActive=!1,this.groups=[],i;this.isActive=!0,this.groups=n,this.#P.clear();for(const r of n){const e=r.columns[r.columns.length-1];e?.field&&this.#P.add(e.field)}return i}afterRender(){if(!this.isActive){const e=this.gridElement?.querySelector(".header"),t=e?.querySelector(".header-group-row");return void(t&&t.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const i=this.visibleColumns,n=xe(i);if(0===n.length)return;this.#P.clear();for(let s=0;s<n.length;s++){const e=n[s],t=e.columns[e.columns.length-1];t?.field&&s<n.length-1&&this.#P.add(t.field)}const r=function(e,t){if(0===e.length)return null;const i=document.createElement("div");i.className="header-group-row",i.setAttribute("role","row");for(const n of e){const e=n.columns[0],r=e?t.findIndex(t=>t.field===e.field):-1;if(-1===r)continue;const o=String(n.id).startsWith("__implicit__"),s=o?"":n.label||n.id,a=document.createElement("div");a.className="cell header-group-cell",o&&a.classList.add("implicit-group"),a.setAttribute("data-group",String(n.id)),a.style.gridColumn=`${r+1} / span ${n.columns.length}`,a.textContent=s,i.appendChild(a)}return i}(n,i);if(r){r.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(r,t):e.appendChild(r)}const o=e.querySelector(".header-row");o&&(o.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,t){if(!t.length||!e)return;const i=/* @__PURE__ */new Map;for(const r of t)for(const e of r.columns)e.field&&i.set(e.field,r.id);const n=Array.from(e.querySelectorAll(".cell[data-field]"));n.forEach(e=>{const t=e.getAttribute("data-field")||"",n=i.get(t);n&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",n))});for(const r of t){const e=r.columns[r.columns.length-1],t=n.find(t=>t.getAttribute("data-field")===e.field);t&&t.classList.add("group-end")}}(o,n))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#P.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(t=>t.id===e);return t?t.columns:[]}refresh(){this.requestRender()}}function Ee({rows:e,config:t,expanded:i,initialExpanded:n}){const r=t.groupOn;if("function"!=typeof r)return[];const o={key:"__root__",value:null,depth:-1,rows:[],children:/* @__PURE__ */new Map};if(e.forEach(e=>{let t=r(e);null==t||!1===t?t=["__ungrouped__"]:Array.isArray(t)||(t=[t]);let i=o;t.forEach((e,t)=>{const n=null==e?"∅":String(e),r="__root__"===i.key?n:i.key+"||"+n;let o=i.children.get(n);o||(o={key:r,value:e,depth:t,rows:[],children:/* @__PURE__ */new Map,parent:i},i.children.set(n,o)),i=o}),i.rows.push(e)}),1===o.children.size&&o.children.has("__ungrouped__")){if(o.children.get("__ungrouped__").rows.length===e.length)return[]}const s=/* @__PURE__ */new Set([...i,...n??[]]),a=[],l=t=>{if(t===o)return void t.children.forEach(e=>l(e));const i=s.has(t.key);a.push({kind:"group",key:t.key,value:t.value,depth:t.depth,rows:t.rows,expanded:i}),i&&(t.children.size?t.children.forEach(e=>l(e)):t.rows.forEach(t=>a.push({kind:"data",row:t,rowIndex:e.indexOf(t)})))};return l(o),a}class Re extends e{static manifest={events:[{type:"grouping-state-change",description:"Emitted when groups are expanded/collapsed. Subscribers can react to row visibility changes."}],queries:[{type:"canMoveRow",description:"Returns false for group header rows (cannot be reordered)"}],configRules:[{id:"groupingRows/accordion-defaultExpanded",severity:"warn",message:'"accordion: true" and "defaultExpanded" (non-false) are used together.\n → In accordion mode, only one group can be open at a time.\n → Using defaultExpanded with multiple groups will collapse to one on first toggle.\n → Consider using "defaultExpanded: false" or a single group key/index with accordion mode.',check:e=>!0===e.accordion&&!1!==e.defaultExpanded&&void 0!==e.defaultExpanded&&!("number"==typeof e.defaultExpanded)&&!("string"==typeof e.defaultExpanded)&&(!0===e.defaultExpanded||Array.isArray(e.defaultExpanded)&&e.defaultExpanded.length>1)}]};name="groupingRows";styles="@layer tbw-plugins{.group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}.group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem)}.group-row:hover{background:var(--tbw-grouping-rows-bg-hover, var(--tbw-color-row-hover))}.group-toggle{cursor:pointer;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toggle-size, 1.25rem);height:var(--tbw-toggle-size, 1.25rem);margin-right:.25rem;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius, .125rem)}.group-label{display:inline-flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs, .85em);font-weight:400}.group-aggregates{display:inline-flex;align-items:center;gap:var(--tbw-spacing-lg, 1rem);margin-left:var(--tbw-spacing-lg, 1rem);font-weight:400;font-size:var(--tbw-font-size-sm, .875em);color:var(--tbw-grouping-rows-aggregate-color, var(--tbw-color-fg-muted))}.group-aggregate{white-space:nowrap}.group-row{padding-left:calc(var(--tbw-group-depth, 0) * var(--tbw-group-indent-width, 1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide",accordion:!1}}expandedKeys=/* @__PURE__ */new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasAppliedDefaultExpanded=!1;get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1}getRowHeight(e,t){if(null!=this.config.groupRowHeight)return!0===e.__isGroupRow?this.config.groupRowHeight:void 0}handleQuery(e){if("canMoveRow"===e.type){const t=e.context;if(!0===t?.__isGroupRow)return!1}}static detect(e,t){return"function"==typeof t?.groupOn||"boolean"==typeof t?.enableRowGrouping}processRows(e){const t=this.config;if("function"!=typeof t.groupOn)return this.isActive=!1,this.flattenedRows=[],[...e];const i=Ee({rows:[...e],config:t,expanded:/* @__PURE__ */new Set});if(0===i.length)return this.isActive=!1,this.flattenedRows=[],[...e];let n;if(!this.hasAppliedDefaultExpanded&&0===this.expandedKeys.size&&!1!==t.defaultExpanded){const e=function(e){return e.filter(e=>"group"===e.kind).map(e=>e.key)}(i);n=function(e,t){if(!0===e)return new Set(t);if(!1===e||null==e)/* @__PURE__ */
|
|
1
|
+
import{BaseGridPlugin as e,DEFAULT_GRID_ICONS as t,F as i,e as n,s as r,c as o,runAggregator as s,a,b as l,g as d,r as c,getAggregator as u,getValueAggregator as h,d as g,f as p}from"./index.js";import{DEFAULT_ANIMATION_CONFIG as f,DGEvents as m,DataGridElement as w,FitModeEnum as b,GridCSSVars as v,GridClasses as y,GridDataAttrs as x,DataGridElement as C,GridSelectors as E,PLUGIN_QUERIES as R,PluginEvents as S,PluginManager as k,RenderPhase as A,builtInSort as _,createGrid as L,defaultComparator as I,queryGrid as T}from"./index.js";function F(e,t,i=!0){let n=e;if(i&&(n=n.filter(e=>!e.hidden&&!e.field.startsWith("__")&&!0!==e.meta?.utility)),t?.length){const e=new Set(t);n=n.filter(t=>e.has(t.field))}return n}function M(e,t){return t?.length?[...t].sort((e,t)=>e-t).map(t=>e[t]).filter(e=>null!=e):e}function D(e){return null==e?"":e instanceof Date?e.toISOString():"object"==typeof e?JSON.stringify(e):String(e)}function P(e,t){const i=t.delimiter??"\t",n=t.newline??"\n",r=e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"),o=[];let s=[],a="",l=!1;for(let d=0;d<r.length;d++){const e=r[d];'"'!==e||l?'"'===e&&l?'"'===r[d+1]?(a+='"',d++):l=!1:e!==i||l?e!==n||l?a+=e:(s.push(a),a="",(s.length>1||s.some(e=>""!==e.trim()))&&o.push(s),s=[]):(s.push(a),a=""):l=!0}return s.push(a),(s.length>1||s.some(e=>""!==e.trim()))&&o.push(s),o}function q(e,t){const{rows:i,target:n,fields:r}=e;if(!n)return;const o=t.rows,s=t.effectiveConfig.columns??[],a=s.map(e=>e.field),l=/* @__PURE__ */new Map;s.forEach(e=>{l.set(e.field,!0===e.editable)});const d=[...o],c=n.bounds?n.bounds.endRow:1/0;i.forEach((e,t)=>{const i=n.row+t;if(!(i>c)){if(n.bounds){if(i>=d.length)return}else for(;i>=d.length;){const e={};a.forEach(t=>e[t]=""),d.push(e)}d[i]={...d[i]},e.forEach((e,t)=>{const n=r[t];n&&l.get(n)&&(d[i][n]=e)})}}),t.rows=d}class H extends e{static dependencies=[{name:"selection",required:!1,reason:"Enables copy/paste of selected cells instead of entire grid"}];name="clipboard";get defaultConfig(){return{includeHeaders:!1,delimiter:"\t",newline:"\n",quoteStrings:!1}}lastCopied=null;attach(e){super.attach(e);e.addEventListener("paste",e=>this.#e(e),{signal:this.disconnectSignal})}detach(){this.lastCopied=null}onKeyDown(e){return!(!e.ctrlKey&&!e.metaKey||"c"!==e.key)&&(e.preventDefault(),this.#t(e.target),!0)}#t(e){const t=this.#i();if(t&&0===t.ranges.length){const t=this.#n(e);if(!t)return;const i=this.columns[t.col];if(!i)return;return void this.copy({rowIndices:[t.row],columns:[i.field]})}this.copy()}#e(e){const t=e.clipboardData?.getData("text/plain");if(!t)return;e.preventDefault();const i=P(t,this.config),n=this.#i(),r=n?.ranges?.[0],o=r?.from.row??0,s=r?.from.col??0,a=r&&("range"===n?.mode||"row"===n?.mode)&&(r.from.row!==r.to.row||r.from.col!==r.to.col)?{endRow:r.to.row,endCol:r.to.col}:null,l=a?.endCol??this.visibleColumns.length-1,d=this.visibleColumns[s],c=d?{row:o,col:s,field:d.field,bounds:a}:null,u=[],h=i[0]?.length??0;for(let p=0;p<h&&s+p<=l;p++){const e=this.visibleColumns[s+p];e&&u.push(e.field)}const g={rows:i,text:t,target:c,fields:u};this.emit("paste",g),this.#r(g)}#r(e){if(!this.grid)return;const{pasteHandler:t}=this.config;if(null===t)return;(t??q)(e,this.grid)}#i(){const e=this.grid?.query("getSelection");return e?.[0]}#o(e){const t=this.#i();let i,n;if(e?.columns)i=F(this.columns,e.columns);else if(t?.ranges.length&&"row"!==t.mode){const e=t.ranges[t.ranges.length-1],n=Math.min(e.from.col,e.to.col),r=Math.max(e.from.col,e.to.col);i=F(this.visibleColumns.slice(n,r+1))}else i=F(this.columns);if(e?.rowIndices)n=M(this.rows,e.rowIndices);else if(t?.ranges.length){const e=t.ranges[t.ranges.length-1],i=Math.min(e.from.row,e.to.row),r=Math.max(e.from.row,e.to.row);n=[];for(let t=i;t<=r;t++){const e=this.rows[t];e&&n.push(e)}}else n=this.rows;return{columns:i,rows:n}}#s(e,t,i){const n=i?.delimiter??this.config.delimiter??"\t",r=i?.newline??this.config.newline??"\n",o=i?.includeHeaders??this.config.includeHeaders??!1,s=i?.processCell??this.config.processCell,a=[];o&&a.push(e.map(e=>e.header||e.field).join(n));for(const l of t){const t=e.map(e=>{const t=l[e.field];return s?s(t,e.field,l):D(t)});a.push(t.join(n))}return a.join(r)}#n(e){const t=e.closest("[data-field-cache]");if(!t)return null;const i=t.dataset.fieldCache,n=t.dataset.row;if(!i||!n)return null;const r=parseInt(n,10);if(isNaN(r))return null;const o=this.columns.findIndex(e=>e.field===i);return-1===o?null:{row:r,col:o}}getSelectionAsText(e){const{columns:t,rows:i}=this.#o(e);return 0===t.length||0===i.length?"":this.#s(t,i,e)}async copy(e){const{columns:t,rows:i}=this.#o(e);if(0===t.length||0===i.length)return"";const n=this.#s(t,i,e);return await async function(e){try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("[copyToClipboard] Clipboard API failed:",t);const i=document.createElement("textarea");i.value=e,i.style.position="fixed",i.style.opacity="0",i.style.pointerEvents="none",document.body.appendChild(i),i.select();const n=document.execCommand("copy");return document.body.removeChild(i),n}}(n),this.lastCopied={text:n,timestamp:Date.now()},this.emit("copy",{text:n,rowCount:i.length,columnCount:t.length}),n}async copyRows(e,t){return 0===e.length?"":this.copy({...t,rowIndices:e})}async paste(){const e=await async function(){try{return await navigator.clipboard.readText()}catch{return""}}();return e?P(e,this.config):null}getLastCopied(){return this.lastCopied}}function N(e){if(null==e)return 100;if("number"==typeof e)return e;const t=parseFloat(e);return isNaN(t)?100:t}function z(e){return e.map(e=>N(e.width))}function G(e){const t=[];let i=0;for(const n of e)t.push(i),i+=N(n.width);return t}function K(e){return e.reduce((e,t)=>e+N(t.width),0)}function O(e,t,i,n,r){const o=i.length;if(0===o)return{startCol:0,endCol:0,visibleColumns:[]};let s=function(e,t,i){let n=0,r=t.length-1;for(;n<r;){const o=Math.floor((n+r)/2);t[o]+i[o]<=e?n=o+1:r=o}return n}(e,i,n);s=Math.max(0,s-r);const a=e+t;let l=s;for(let c=s;c<o;c++){if(i[c]>=a){l=c-1;break}l=c}l=Math.min(o-1,l+r);const d=[];for(let c=s;c<=l;c++)d.push(c);return{startCol:s,endCol:l,visibleColumns:d}}class B extends e{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];originalColumns=[];attach(e){super.attach(e);const t=this.columns;this.columnWidths=z(t),this.columnOffsets=G(t),this.totalWidth=K(t),this.endCol=t.length-1}detach(){this.#a(),this.columnWidths=[],this.columnOffsets=[],this.originalColumns=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}#a(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".header-row");t&&(t.style.paddingLeft="",t.style.minWidth="");e.querySelectorAll(".data-grid-row").forEach(e=>{e.style.paddingLeft=""});const i=e.querySelector(".rows-viewport .rows");i&&(i.style.width="");const n=e.querySelector(".rows-body");n&&(n.style.minWidth="")}processColumns(e){(0===this.originalColumns.length||e.length>=this.originalColumns.length)&&(this.originalColumns=e,this.columnWidths=z(e),this.columnOffsets=G(e),this.totalWidth=K(e));const t=this.originalColumns,i=(n=t.length,r=this.config.threshold??30,!!(this.config.autoEnable??!0)&&n>r);var n,r;if(this.isVirtualized=i??!1,!i)return this.startCol=0,this.endCol=t.length-1,[...t];const o=this.grid.clientWidth||800,s=O(this.scrollLeft,o,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=s.startCol,this.endCol=s.endCol,s.visibleColumns.map(e=>t[e])}afterRender(){if(!this.isVirtualized)return;const e=this.gridElement;if(!e)return;const t=this.columnOffsets[this.startCol]??0,i=e.querySelector(".header-row"),n=e.querySelectorAll(".data-grid-row");i&&(i.style.paddingLeft=`${t}px`,i.style.minWidth=`${this.totalWidth}px`),n.forEach(e=>{e.style.paddingLeft=`${t}px`});const r=e.querySelector(".rows-viewport .rows");r&&(r.style.width=`${this.totalWidth}px`);const o=e.querySelector(".rows-body");o&&(o.style.minWidth=`${this.totalWidth}px`)}onScroll(e){if(!this.isVirtualized)return;Math.abs(e.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=e.scrollLeft,this.requestColumnsRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(e){const t=this.columnOffsets[e]??0;this.grid.scrollLeft=t}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const V="@layer tbw-plugins{.tbw-context-menu{position:fixed;background:var(--tbw-context-menu-bg, var(--tbw-color-panel-bg));color:var(--tbw-context-menu-fg, var(--tbw-color-fg));border:1px solid var(--tbw-context-menu-border, var(--tbw-color-border));border-radius:var(--tbw-context-menu-radius, var(--tbw-border-radius));box-shadow:var(--tbw-context-menu-shadow, 0 2px 10px var(--tbw-color-shadow));min-width:var(--tbw-context-menu-min-width, var(--tbw-menu-min-width));padding:var(--tbw-spacing-xs) 0;z-index:10000;font-size:var(--tbw-context-menu-font-size, var(--tbw-font-size-sm));font-family:var(--tbw-context-menu-font-family, var(--tbw-font-family))}.tbw-context-menu-item{display:flex;align-items:center;padding:var(--tbw-context-menu-item-padding, var(--tbw-menu-item-padding));cursor:pointer;gap:var(--tbw-context-menu-item-gap, var(--tbw-menu-item-gap))}.tbw-context-menu-item:hover:not(.disabled){background:var(--tbw-context-menu-hover, var(--tbw-color-row-hover))}.tbw-context-menu-item.disabled{opacity:.5;cursor:default}.tbw-context-menu-item.danger{color:var(--tbw-context-menu-danger, var(--tbw-color-danger))}.tbw-context-menu-icon{width:var(--tbw-context-menu-icon-size, var(--tbw-icon-size));text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut kbd{color:var(--tbw-context-menu-muted, var(--tbw-color-fg-muted));font-size:var(--tbw-context-menu-shortcut-size, var(--tbw-font-size-xs))}.tbw-context-menu-arrow{font-size:var(--tbw-context-menu-arrow-size, var(--tbw-font-size-2xs));color:var(--tbw-context-menu-muted, var(--tbw-color-fg-muted))}.tbw-context-menu-separator{height:1px;background:var(--tbw-context-menu-border, var(--tbw-color-border));margin:var(--tbw-spacing-xs) 0}}";function W(e,t){return("function"==typeof e?e(t):e).filter(e=>!0!==e.hidden&&("function"!=typeof e.hidden||!e.hidden(t)))}function $(e){const t=[];for(const i of e)i.separator&&(0===t.length||t[t.length-1].separator)||t.push(i);return t.length>0&&t[t.length-1].separator&&t.pop(),t}function j(e,t){return!0===e.disabled||"function"==typeof e.disabled&&e.disabled(t)}function U(e,i,n,r=t.submenuArrow){const o=document.createElement("div");o.className="tbw-context-menu",o.setAttribute("role","menu");const s=e.some(e=>!e.separator&&e.icon);for(const t of e){if(t.separator){const e=document.createElement("div");e.className="tbw-context-menu-separator",e.setAttribute("role","separator"),o.appendChild(e);continue}const e=document.createElement("div");e.className="tbw-context-menu-item",t.cssClass&&e.classList.add(t.cssClass),e.setAttribute("role","menuitem"),e.setAttribute("data-id",t.id);const a=j(t,i);if(a&&(e.classList.add("disabled"),e.setAttribute("aria-disabled","true")),t.icon){const i=document.createElement("span");i.className="tbw-context-menu-icon",i.innerHTML=t.icon,e.appendChild(i)}else if(s){const t=document.createElement("span");t.className="tbw-context-menu-icon",t.innerHTML=" ",e.appendChild(t)}const l=document.createElement("span");if(l.className="tbw-context-menu-label",l.textContent=t.name,e.appendChild(l),t.shortcut){const i=document.createElement("span");if(i.className="tbw-context-menu-shortcut",Array.isArray(t.shortcut))t.shortcut.forEach((e,t)=>{t>0&&i.appendChild(document.createTextNode("+"));const n=document.createElement("kbd");n.textContent=e,i.appendChild(n)});else{const e=document.createElement("kbd");e.textContent=t.shortcut,i.appendChild(e)}e.appendChild(i)}if(t.subMenu?.length){const o=document.createElement("span");o.className="tbw-context-menu-arrow","string"==typeof r?o.innerHTML=r:r instanceof HTMLElement&&o.appendChild(r.cloneNode(!0)),e.appendChild(o),e.addEventListener("mouseenter",()=>{if(e.querySelector(".tbw-context-menu"))return;if(!t.subMenu)return;const o=U(W(t.subMenu,i),i,n,r);o.classList.add("tbw-context-submenu"),o.style.position="absolute",o.style.left="100%",o.style.top="0",e.style.position="relative",e.appendChild(o)}),e.addEventListener("mouseleave",()=>{const t=e.querySelector(".tbw-context-menu");t&&t.remove()})}a||!t.action||t.subMenu||e.addEventListener("click",e=>{e.stopPropagation(),n(t)}),o.appendChild(e)}return o}function Y(e,t,i){e.style.position="fixed",e.style.left=`${t}px`,e.style.top=`${i}px`,e.style.visibility="hidden",e.style.zIndex="10000";const n=e.getBoundingClientRect(),r=window.innerWidth,o=window.innerHeight;let s=t,a=i;t+n.width>r&&(s=t-n.width),i+n.height>o&&(a=i-n.height),s=Math.max(0,s),a=Math.max(0,a),e.style.left=`${s}px`,e.style.top=`${a}px`,e.style.visibility="visible"}const Z="getContextMenuItems";let Q=null,X=null,J=null,ee=0;const te=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:e=>{const t=e.grid;t?.plugins?.clipboard?.copy?.()}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:e=>{const t=e.grid;t?.plugins?.export?.exportCsv?.()}}];class ie extends e{static manifest={queries:[{type:Z,description:"Collects context menu items from other plugins for header right-click menus"}]};name="contextMenu";get defaultConfig(){return{items:te}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),ee++}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.uninstallGlobalHandlers()}syncSelectionOnContextMenu(e){if(e<0)return[];const t=this.grid?.query("getSelectedRowIndices"),i=t?.[0];return i?i.includes(e)?i:(this.grid?.query("selectRows",[e]),[e]):[e]}static CSS_VARS_TO_COPY=["--tbw-color-panel-bg","--tbw-color-fg","--tbw-color-fg-muted","--tbw-color-border","--tbw-color-row-hover","--tbw-color-shadow","--tbw-color-danger","--tbw-border-radius","--tbw-font-family","--tbw-font-size-sm","--tbw-font-size-xs","--tbw-font-size-2xs","--tbw-spacing-xs","--tbw-icon-size","--tbw-menu-min-width","--tbw-menu-item-padding","--tbw-menu-item-gap","--tbw-context-menu-bg","--tbw-context-menu-fg","--tbw-context-menu-border","--tbw-context-menu-radius","--tbw-context-menu-shadow","--tbw-context-menu-hover","--tbw-context-menu-danger","--tbw-context-menu-muted","--tbw-context-menu-min-width","--tbw-context-menu-font-size","--tbw-context-menu-font-family","--tbw-context-menu-item-padding","--tbw-context-menu-item-gap","--tbw-context-menu-icon-size","--tbw-context-menu-shortcut-size","--tbw-context-menu-arrow-size"];copyGridStyles(e){const t=this.gridElement;if(!t)return;const i=getComputedStyle(t),n=[],r=i.getPropertyValue("color-scheme").trim();r&&n.push(`color-scheme: ${r}`);for(const o of ie.CSS_VARS_TO_COPY){const e=i.getPropertyValue(o).trim();e&&n.push(`${o}: ${e}`)}if(n.length>0){const t=e.getAttribute("style")||"";e.setAttribute("style",t+n.join("; ")+";")}}installGlobalHandlers(){!J&&"undefined"!=typeof document&&V&&(J=document.createElement("style"),J.id="tbw-context-menu-styles",J.textContent=V,document.head.appendChild(J)),Q||(Q=()=>{document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove())},document.addEventListener("click",Q)),X||(X=e=>{if("Escape"===e.key){document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove())}},document.addEventListener("keydown",X))}uninstallGlobalHandlers(){ee--,ee>0||(Q&&(document.removeEventListener("click",Q),Q=null),X&&(document.removeEventListener("keydown",X),X=null),J&&(J.remove(),J=null))}collectPluginItems(e){if(!this.grid)return[];const t=this.grid.query(Z,e),i=[];for(const n of t)Array.isArray(n)&&i.push(...n);return i.sort((e,t)=>(e.order??100)-(t.order??100)),this.insertGroupSeparators(i)}insertGroupSeparators(e){if(e.length<=1)return e;const t=[];let i=-1;for(const n of e){if(n.separator){t.push(n);continue}const e=Math.floor((n.order??100)/10);i>=0&&e!==i&&t.push({id:`__sep-${i}-${e}`,label:"",separator:!0,action:()=>{}}),i=e,t.push(n)}return t}convertPluginItems(e){return e.map(e=>({id:e.id,name:e.label,icon:e.icon,shortcut:e.shortcut,disabled:e.disabled??!1,action:()=>e.action(),separator:e.separator,cssClass:e.cssClass}))}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-grid-root");t&&"true"!==t.getAttribute("data-context-menu-bound")&&(t.setAttribute("data-context-menu-bound","true"),t.addEventListener("contextmenu",e=>{const t=e;t.preventDefault();const i=t.target,n=i.closest("[data-row][data-col]"),r=i.closest('[part~="header-cell"]');let o;if(n){const e=parseInt(n.getAttribute("data-row")??"-1",10),i=parseInt(n.getAttribute("data-col")??"-1",10),r=this.visibleColumns[i],s=this.rows[e],a=this.syncSelectionOnContextMenu(e);o={row:s,rowIndex:e,column:r,columnIndex:i,field:r?.field??"",value:s?.[r?.field]??null,isHeader:!1,event:t,selectedRows:a}}else{if(!r)return;{const e=parseInt(r.getAttribute("data-col")??"-1",10),i=this.visibleColumns[e];o={row:null,rowIndex:-1,column:i,columnIndex:e,field:i?.field??"",value:null,isHeader:!0,event:t,selectedRows:[]}}}this.params=o,this.position={x:t.clientX,y:t.clientY};const s=this.collectPluginItems(o);let a=W(this.config.items??te,o);if(s.length>0){const e=this.convertPluginItems(s);a=a.length>0&&e.length>0?[...a,{id:"__plugin-sep",name:"",separator:!0},...e]:[...a,...e]}a=$(a),a.length&&(this.menuElement&&this.menuElement.remove(),this.menuElement=U(a,o,e=>{e.action&&e.action(o),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),Y(this.menuElement,t.clientX,t.clientY),this.isOpen=!0,this.emit("context-menu-open",{params:o,items:a}))}))}showMenu(e,t,i){const n={row:i.row??null,rowIndex:i.rowIndex??-1,column:i.column??null,columnIndex:i.columnIndex??-1,field:i.field??"",value:i.value??null,isHeader:i.isHeader??!1,event:i.event??new MouseEvent("contextmenu"),selectedRows:i.selectedRows??[]},r=this.collectPluginItems(n);let o=W(this.config.items??te,n);if(r.length>0){const e=this.convertPluginItems(r);o=o.length>0&&e.length>0?[...o,{id:"__plugin-sep",name:"",separator:!0},...e]:[...o,...e]}o=$(o),this.menuElement&&this.menuElement.remove(),this.menuElement=U(o,n,e=>{e.action&&e.action(n),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),Y(this.menuElement,e,t),this.isOpen=!0}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}function ne(e){switch(e.type){case"number":return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="number",n.value=null!=t.value?String(t.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>t.commit(""===n.value?null:Number(n.value));return n.addEventListener("blur",r),n.addEventListener("keydown",e=>{"Enter"===e.key&&r(),"Escape"===e.key&&t.cancel()}),n}}(e);case"boolean":return e=>{const t=document.createElement("input");return t.type="checkbox",t.checked=!!e.value,t.addEventListener("change",()=>e.commit(t.checked)),t};case"date":return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");return n.type="date",t.value instanceof Date?n.valueAsDate=t.value:"string"==typeof t.value&&t.value&&(n.value=t.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder),n.addEventListener("change",()=>{"string"==typeof t.value?t.commit(n.value):t.commit(n.valueAsDate)}),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}(e);case"select":return function(e){return t=>{const i=e.editorParams,n=document.createElement("select");if(e.multi&&(n.multiple=!0),i?.includeEmpty){const e=document.createElement("option");e.value="",e.textContent=i.emptyLabel??"",n.appendChild(e)}const r=function(e){const t=e.options;return t?"function"==typeof t?t():t:[]}(e);r.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,e.multi&&Array.isArray(t.value)&&t.value.includes(i.value)?r.selected=!0:e.multi||t.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(e.multi){const e=Array.from(n.selectedOptions).map(e=>e.value);t.commit(e)}else t.commit(n.value)};return n.addEventListener("change",o),n.addEventListener("blur",o),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}(e);default:return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="text",n.value=null!=t.value?String(t.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const e=n.value;(null!==t.value&&void 0!==t.value||""!==e)&&("string"==typeof t.value&&e===t.value.replace(/[\n\r]/g,"")||("number"==typeof t.value&&""!==e?t.commit(Number(e)):t.commit(e)))};return n.addEventListener("blur",r),n.addEventListener("keydown",e=>{"Enter"===e.key&&r(),"Escape"===e.key&&t.cancel()}),n}}(e)}}function re(e){return"string"==typeof e&&("__proto__"!==e&&"constructor"!==e&&"prototype"!==e)}function oe(e,t,i){return e instanceof HTMLInputElement?"checkbox"===e.type?e.checked:"number"===e.type?""===e.value?null:Number(e.value):"date"===e.type?"string"==typeof i?e.value:e.valueAsDate:"number"==typeof i?""===e.value?null:Number(e.value):null==i&&""===e.value||"string"==typeof i&&e.value===i.replace(/[\n\r]/g,"")?i:e.value:"number"===t?.type&&""!==e.value||"number"==typeof i&&""!==e.value?Number(e.value):null==i&&""===e.value?i:e.value}function se(e){}class ae extends e{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>!0===e},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;&:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}.data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}.data-grid-row>.cell.editing input:not([type=checkbox]),.data-grid-row>.cell.editing select,.data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}.tbw-editor-host{display:contents}--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171);.data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#l(){return"grid"===this.config.mode}#d=-1;#c;#u;#h=-1;#g=/* @__PURE__ */new Map;#p=/* @__PURE__ */new Set;#f=/* @__PURE__ */new Set;#m=/* @__PURE__ */new Map;#w=!1;#b=-1;#v=/* @__PURE__ */new Map;#y=!1;#x=!1;#C=!1;attach(e){super.attach(e);const t=this.disconnectSignal,n=e;n._activeEditRows=-1,n._rowEditSnapshots=/* @__PURE__ */new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),e.resetChangedRows=e=>this.resetChangedRows(e),e.beginBulkEdit=(e,t)=>{t&&this.beginCellEdit(e,t)},document.addEventListener("keydown",e=>{if(!this.#l&&"Escape"===e.key&&-1!==this.#d){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}this.#E(this.#d,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",e=>{if(this.#l)return;if(-1===this.#d)return;const t=n.findRenderedRowElement?.(this.#d);if(!t)return;if((e.composedPath&&e.composedPath()||[]).includes(t))return;const i=e.target;if(!i||!this.grid.containsFocus?.(i)){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}queueMicrotask(()=>{-1!==this.#d&&this.#E(this.#d,!1)})}},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",e=>{if(this.#l)return;if(-1===this.#d)return;const t=e.relatedTarget;t&&this.grid.containsFocus?.(t)||t&&this.gridElement.contains(t)||queueMicrotask(()=>{-1!==this.#d&&this.#R()})},{signal:t}),this.gridElement.addEventListener("cell-change",e=>{const t=e.detail;if("user"===t.source)return;const i=`${t.rowIndex}:${t.field}`,n=this.#m.get(i);n&&n(t.newValue)},{signal:t}),this.#l&&(n._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",e=>{const t=e.target;if(t.matches(i)){if(this.#x)return t.blur(),void this.gridElement.focus();this.#y=!0}},{signal:t}),this.gridElement.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&(this.gridElement.contains(t)||this.grid.containsFocus?.(t))&&t.matches(i)||(this.#y=!1)},{signal:t}),this.gridElement.addEventListener("keydown",e=>{if("Escape"===e.key&&this.#y){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#y=!1,this.#x=!0,e.preventDefault(),e.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",e=>{e.target.matches(i)&&(this.#x=!1)},{signal:t}))}detach(){this.gridElement._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#d=-1,this.#c=void 0,this.#u=void 0,this.#h=-1,this.#g.clear(),this.#p.clear(),this.#f.clear(),this.#m.clear(),this.#y=!1,this.#x=!1,this.#C=!1,super.detach()}handleQuery(e){if("isEditing"===e.type)return this.#l||-1!==this.#d}onCellClick(e){if(this.#l)return!1;const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===e.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=e,o=t._columns?.some(e=>e.editable);return!!o&&(e.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(e){const t=this.grid;if("Escape"===e.key){if(this.#l&&this.#y){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}const t=document.activeElement;return t&&this.gridElement.contains(t)&&t.blur(),this.#y=!1,this.requestAfterRender(),!0}if(-1!==this.#d&&!this.#l){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}return this.#E(this.#d,!0),!0}}if(this.#l&&!this.#y&&("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key))return!1;if(this.#l&&this.#y&&("ArrowUp"===e.key||"ArrowDown"===e.key))return!0;if(("ArrowUp"===e.key||"ArrowDown"===e.key)&&-1!==this.#d&&!this.#l){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}const i=t._rows.length-1,r=this.#d;return this.#E(r,!1),"ArrowDown"===e.key?t._focusRow=Math.min(i,t._focusRow+1):t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault(),n(t),this.requestAfterRender(),!0}if("Tab"===e.key&&(-1!==this.#d||this.#l)){if(e.preventDefault(),this.#C)return this.#E(this.#d,!1),!0;const t=!e.shiftKey;return this.#S(t),!0}if(" "===e.key||"Spacebar"===e.key){if(-1!==this.#d)return!1;const i=t._focusRow,n=t._focusCol;if(i>=0&&n>=0){const r=t._visibleColumns[n],o=t._rows[i];if(r?.editable&&"boolean"===r.type&&o){const t=r.field;if(re(t)){const n=!o[t];return this.#k(i,r,n,o),e.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==e.key||e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){if(this.#l&&!this.#y)return this.#R(),!0;if(-1!==this.#d){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}return!1}const i=this.config.editOn??t.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const n=t._focusRow,r=t._focusCol;if(n>=0){const i=t._columns?.some(e=>e.editable);if(i){const i=t._visibleColumns[r],o=t._rows[n],s=i?.field??"",a=s&&o?o[s]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),d=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:s,value:a,row:o,cellEl:l,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(d);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),d.defaultPrevented||c.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===e.key){if(-1!==this.#d||this.#l)return!1;if(!1===(this.config.editOn??t.effectiveConfig?.editOn))return!1;const i=t._focusRow,n=t._focusCol;if(i>=0&&n>=0){const r=t._visibleColumns[n];if(r?.editable&&r.field)return e.preventDefault(),this.beginCellEdit(i,r.field),!0}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,n=t.__frameworkAdapter;return i||n?.getTypeDefault?e.map(e=>{if(!e.type)return e;let t;if(i?.[e.type]?.editorParams&&(t=i[e.type].editorParams),!t&&n?.getTypeDefault){const i=n.getTypeDefault(e.type);i?.editorParams&&(t=i.editorParams)}return t?{...e,editorParams:{...t,...e.editorParams}}:e}):e}afterRender(){const e=this.grid;if(this.#w&&(this.#w=!1,this.#A(e)),-1!==this.#b){const t=this.#b;this.#b=-1,e.animateRow?.(t,"change")}if(!this.#l&&0!==this.#f.size)for(const t of this.#f){const[i,n]=t.split(":"),r=parseInt(i,10),o=parseInt(n,10),s=e.findRenderedRowElement?.(r);if(!s)continue;const a=s.querySelector(`.cell[data-col="${o}"]`);if(!a||a.classList.contains("editing"))continue;const l=e._rows[r],d=e._visibleColumns[o];l&&d&&this.#_(l,r,d,o,a,!0)}}afterCellRender(e){if(!this.#l)return;const{row:t,rowIndex:i,column:n,colIndex:r,cellElement:o}=e;n.editable&&(o.classList.contains("editing")||this.#_(t,i,n,r,o,!0))}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#p){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#p)}get activeEditRow(){return this.#d}get activeEditCol(){return this.#h}isRowEditing(e){return this.#d===e}isCellEditing(e,t){return this.#f.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const e=t.getRowId?.(i);return!!e&&this.#p.has(e)}catch{return!1}}isRowChangedById(e){return this.#p.has(e)}setInvalid(e,t,i=""){let n=this.#v.get(e);n||(n=/* @__PURE__ */new Map,this.#v.set(e,n)),n.set(t,i),this.#L(e,t,!0)}clearInvalid(e,t){const i=this.#v.get(e);i&&(i.delete(t),0===i.size&&this.#v.delete(e)),this.#L(e,t,!1)}clearRowInvalid(e){const t=this.#v.get(e);if(t){const i=Array.from(t.keys());this.#v.delete(e),i.forEach(t=>this.#L(e,t,!1))}}clearAllInvalid(){const e=Array.from(this.#v.entries());this.#v.clear(),e.forEach(([e,t])=>{t.forEach((t,i)=>this.#L(e,i,!1))})}isCellInvalid(e,t){return this.#v.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#v.get(e)?.get(t)}hasInvalidCells(e){const t=this.#v.get(e);return!!t&&t.size>0}getInvalidFields(e){return new Map(this.#v.get(e)??[])}#L(e,t,i){const n=this.grid,r=n._visibleColumns?.findIndex(e=>e.field===t);if(-1===r||void 0===r)return;const o=n._rows,s=o?.findIndex(t=>{try{return n.getRowId?.(t)===e}catch{return!1}});if(-1===s||void 0===s)return;const a=n.findRenderedRowElement?.(s),l=a?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#v.get(e)?.get(t);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#p.clear(),this.#I(),e||this.emit("changed-rows-reset",{rows:t,ids:i});const n=this.grid;n._rowPool?.forEach(e=>e.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,n=i._visibleColumns.findIndex(e=>e.field===t);if(-1===n)return;const r=i._visibleColumns[n];if(!r?.editable)return;const o=i.findRenderedRowElement?.(e),s=o?.querySelector(`.cell[data-col="${n}"]`);s&&(this.#C=!0,this.#T(e,n,s))}beginBulkEdit(e){const t=this.grid;if(!1===(this.config.editOn??t.effectiveConfig?.editOn))return;const n=t._columns?.some(e=>e.editable);if(!n)return;const r=t.findRenderedRowElement?.(e);if(!r)return;this.#C=!1;const o=t._rows[e];this.#F(e,o),Array.from(r.children).forEach((i,n)=>{const r=t._visibleColumns[n];if(r?.editable){const t=i;t.classList.contains("editing")||this.#_(o,e,r,n,t,!0)}}),setTimeout(()=>{let e=r.querySelector(`.cell[data-col="${t._focusCol}"]`);if(e?.classList.contains("editing")||(e=r.querySelector(".cell.editing")),e?.classList.contains("editing")){const t=e.querySelector(i);try{t?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#d&&this.#E(this.#d,!1)}cancelActiveRowEdit(){-1!==this.#d&&this.#E(this.#d,!0)}#T(e,t,i){const n=this.grid,r=n._rows[e],o=n._visibleColumns[t];r&&o?.editable&&(i.classList.contains("editing")||(this.#d!==e&&this.#F(e,r),this.#h=t,this.#_(r,e,o,t,i,!1)))}#R(){const e=this.grid,t=e._focusRow,n=e._focusCol;if(t<0||n<0)return;const r=e.findRenderedRowElement?.(t),o=r?.querySelector(`.cell[data-col="${n}"]`);if(o?.classList.contains("editing")){const e=o.querySelector(i);e&&(this.#x=!1,e.focus(),this.#y=!0,e instanceof HTMLInputElement&&("text"===e.type||"number"===e.type)&&e.select())}}#S(e){const t=this.grid,r=t._rows,o=this.#l?t._focusRow:this.#d,s=t._visibleColumns.map((e,t)=>e.editable?t:-1).filter(e=>e>=0);if(0===s.length)return;const a=s.indexOf(t._focusCol)+(e?1:-1);if(a>=0&&a<s.length){t._focusCol=s[a];const e=t.findRenderedRowElement?.(o),r=e?.querySelector(`.cell[data-col="${s[a]}"]`);if(r?.classList.contains("editing")){const e=r.querySelector(i);e?.focus({preventScroll:!0})}return void n(t,{forceHorizontalScroll:!0})}const l=o+(e?1:-1);l>=0&&l<r.length&&(this.#l?(t._focusRow=l,t._focusCol=e?s[0]:s[s.length-1],n(t,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const e=t.findRenderedRowElement?.(l),n=e?.querySelector(`.cell[data-col="${t._focusCol}"]`);if(n?.classList.contains("editing")){const e=n.querySelector(i);e?.focus({preventScroll:!0})}},0)):(this.#E(o,!1),t._focusRow=l,t._focusCol=e?s[0]:s[s.length-1],this.beginBulkEdit(l),n(t,{forceHorizontalScroll:!0})))}#I(){const e=this.grid;e._activeEditRows=this.#d,e._rowEditSnapshots=this.#g}#F(e,t){if(this.#d!==e){this.#g.set(e,{...t}),this.#d=e,this.#u=t;const i=this.grid;try{this.#c=i.getRowId?.(t)??void 0}catch{this.#c=void 0}this.#I(),this.#l||this.emit("edit-open",{rowIndex:e,rowId:this.#c??"",row:t})}}#E(e,t){if(this.#d!==e)return;const i=this.grid,n=this.#g.get(e),r=i.findRenderedRowElement?.(e);let o=this.#c;const s=o?i._getRowEntry(o):void 0,a=s?.row??this.#u??i._rows[e];if(!o&&a)try{o=i.getRowId?.(a)}catch{}if(!t&&r&&a){r.querySelectorAll(".cell.editing").forEach(t=>{const n=Number(t.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(t.hasAttribute("data-editor-managed"))return;const o=t.querySelector("input,textarea,select");if(o){const t=r.field,i=a[t],n=oe(o,r,i);i!==n&&this.#k(e,r,n,a)}})}if(t||this.#l||!a||this.emit("before-edit-close",{rowIndex:e,rowId:o??"",row:a}),t&&n&&a)Object.keys(n).forEach(e=>{a[e]=n[e]}),o&&(this.#p.delete(o),this.clearRowInvalid(o));else if(!t&&a){const t=this.#M(n,a),i=o?this.#p.has(o):t,r=this.emitCancelable("row-commit",{rowIndex:e,rowId:o??"",row:a,oldValue:n,newValue:a,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(e=>{a[e]=n[e]}),o&&(this.#p.delete(o),this.clearRowInvalid(o))):!r&&t&&this.isAnimationEnabled&&(this.#b=e)}this.#g.delete(e),this.#d=-1,this.#c=void 0,this.#u=void 0,this.#h=-1,this.#C=!1,this.#I();for(const l of this.#f)l.startsWith(`${e}:`)&&this.#f.delete(l);for(const l of this.#m.keys())l.startsWith(`${e}:`)&&this.#m.delete(l);this.#w=!0,r?(r.querySelectorAll(".cell.editing").forEach(e=>{e.classList.remove("editing"),function(e){e.__editingCellCount=0,e.removeAttribute("data-has-editing")}(e.parentElement)}),i.refreshVirtualWindow(!0)):(this.#A(i),this.#w=!1),!this.#l&&a&&this.emit("edit-close",{rowIndex:e,rowId:o??"",row:a,reverted:t})}#k(e,t,i,n){const r=t.field;if(!re(r))return;const o=n[r];if(o===i)return;const s=this.grid;let a;try{a=this.grid.getRowId(n)}catch{}const l=!a||!this.#p.has(a),d=a?e=>this.grid.updateRow(a,e,"cascade"):se;let c=!1;const u=a?e=>{c=!0,this.setInvalid(a,r,e??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:a??"",field:r,oldValue:o,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:d,setInvalid:u}))return;a&&!c&&this.isCellInvalid(a,r)&&this.clearInvalid(a,r),n[r]=i,a&&this.#p.add(a),this.#I(),this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:r,oldValue:o,newValue:i});const h=s.findRenderedRowElement?.(e);h&&h.classList.add("changed")}#_(e,t,n,r,o,s){if(!n.editable)return;if(o.classList.contains("editing"))return;let a;try{a=this.grid.getRowId(e)}catch{}const l=a?e=>this.grid.updateRow(a,e,"cascade"):se,d=re(n.field)?e[n.field]:void 0;o.classList.add("editing"),this.#f.add(`${t}:${r}`);const c=o.parentElement;c&&function(e){const t=(e.__editingCellCount??0)+1;e.__editingCellCount=t,e.setAttribute("data-has-editing","")}(c);let u=!1;const h=i=>{if(u||!this.#l&&-1===this.#d)return;const r=this.grid,o=a?r._getRowEntry(a):void 0,s=o?.row??e,l=o?.index??t;this.#k(l,n,i,s)},g=()=>{if(u=!0,re(n.field)){const t=this.grid,i=a?t._getRowEntry(a):void 0;(i?.row??e)[n.field]=d}},p=document.createElement("div");p.className="tbw-editor-host",o.innerHTML="",o.appendChild(p),p.addEventListener("keydown",e=>{if("Enter"===e.key){if(this.#l){e.stopPropagation(),e.preventDefault();const t=p.querySelector("input,textarea,select");return void(t&&h(oe(t,n,d)))}if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}e.stopPropagation(),e.preventDefault(),u=!0,this.#E(t,!1)}if("Escape"===e.key){if(this.#l)return e.stopPropagation(),void e.preventDefault();if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}e.stopPropagation(),e.preventDefault(),g(),this.#E(t,!0)}});const f=n,m=f.__editorTemplate,w=function(e,t){if(t.editor)return t.editor;if(t.__editorTemplate)return"template";if(!t.type)return;const i=e.effectiveConfig?.typeDefaults;if(i?.[t.type]?.editor)return i[t.type].editor;const n=e.__frameworkAdapter;if(n?.getTypeDefault){const e=n.getTypeDefault(t.type);if(e?.editor)return e.editor}}(this.grid,f)??ne(n),b=d,v=`${t}:${n.field}`,y=[];this.#m.set(v,e=>{for(const t of y)t(e)});const x=e=>{y.push(e)};if("template"===w&&m)this.#D(p,f,e,d,h,g,s,t),x(e=>{const t=p.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if("string"==typeof w){const e=document.createElement(w);e.value=b,e.addEventListener("change",()=>h(e.value)),x(t=>{e.value=t}),p.appendChild(e),s||queueMicrotask(()=>{const e=p.querySelector(i);e?.focus({preventScroll:!0})})}else if("function"==typeof w){const t=w({row:e,rowId:a??"",value:b,field:n.field,column:n,commit:h,cancel:g,updateRow:l,onValueChange:x});if("string"==typeof t)p.innerHTML=t,function(e,t,i,n){const r=e.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(oe(r,t,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(oe(r,t,n))))}(p,n,h,d),x(e=>{const t=p.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if(t instanceof Node){p.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?x(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):o.setAttribute("data-editor-managed","")}s||queueMicrotask(()=>{const e=p.querySelector(i);e?.focus({preventScroll:!0})})}else if(w&&"object"==typeof w){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",n.field),p.appendChild(t),o.setAttribute("data-editor-managed","");const i={row:e,rowId:a??"",value:b,field:n.field,column:n,commit:h,cancel:g,updateRow:l,onValueChange:x};if(w.mount)try{w.mount({placeholder:t,context:i,spec:w})}catch(C){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,C)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:w,context:i}}))}}#D(e,t,i,n,r,o,s,a){const l=t.__editorTemplate;if(!l)return;const d=l.cloneNode(!0),c=t.__compiledEditor;c?d.innerHTML=c({row:i,value:n,field:t.field,column:t,commit:r,cancel:o}):d.querySelectorAll("*").forEach(e=>{1===e.childNodes.length&&e.firstChild?.nodeType===Node.TEXT_NODE&&(e.textContent=e.textContent?.replace(/{{\s*value\s*}}/g,null==n?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(e,t)=>{if(!re(t))return"";const n=i[t];return null==n?"":String(n)})||"")});const u=d.querySelector("input,textarea,select");if(u){u instanceof HTMLInputElement&&"checkbox"===u.type?u.checked=!!n:u.value=String(n??"");let e=!1;u.addEventListener("blur",()=>{e||r(oe(u,t,n))}),u.addEventListener("keydown",i=>{const s=i;if("Enter"===s.key){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(s))return}s.stopPropagation(),s.preventDefault(),e=!0,r(oe(u,t,n)),this.#E(a,!1)}if("Escape"===s.key){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(s))return}s.stopPropagation(),s.preventDefault(),o(),this.#E(a,!0)}}),u instanceof HTMLInputElement&&"checkbox"===u.type&&u.addEventListener("change",()=>r(u.checked)),s||setTimeout(()=>u.focus({preventScroll:!0}),0)}e.appendChild(d)}#M(e,t){if(!e)return!1;const i=e,n=t,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const o of r)if(i[o]!==n[o])return!0;return!1}#A(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,n=e.findRenderedRowElement?.(t);if(n){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(e=>e.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}function le(e,t=!0){if(null==e)return"";if(e instanceof Date)return e.toISOString();if("object"==typeof e)return JSON.stringify(e);const i=String(e);return t&&(i.includes(",")||i.includes('"')||i.includes("\n")||i.includes("\r"))?`"${i.replace(/"/g,'""')}"`:i}function de(e,t){const i=URL.createObjectURL(e),n=document.createElement("a");n.href=i,n.download=t,n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(i)}function ce(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}class ue extends e{name="export";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;performExport(e,t){const i=this.config,n={format:e,fileName:t?.fileName??i.fileName??"export",includeHeaders:t?.includeHeaders??i.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,columns:t?.columns,rowIndices:t?.rowIndices},r=F(this.columns,t?.columns,i.onlyVisible);let o;if(t?.rowIndices)o=M(this.rows,t.rowIndices);else if(i.onlySelected){const e=this.getSelectionState();o=e?.selected?.size?M(this.rows,[...e.selected]):[...this.rows]}else o=[...this.rows];this.isExportingFlag=!0;let s=n.fileName;try{switch(e){case"csv":{const e=function(e,t,i,n={}){const r=n.delimiter??",",o=n.newline??"\n",s=[],a=n.bom?"\ufeff":"";if(!1!==i.includeHeaders){const e=t.map(e=>{const t=e.header||e.field;return le(i.processHeader?i.processHeader(t,e.field):t)});s.push(e.join(r))}for(const l of e){const e=t.map(e=>{let t=l[e.field];return i.processCell&&(t=i.processCell(t,e.field,l)),le(t)});s.push(e.join(r))}return a+s.join(o)}(o,r,n,{bom:!0});s=s.endsWith(".csv")?s:`${s}.csv`,function(e,t){de(new Blob([e],{type:"text/csv;charset=utf-8;"}),t)}(e,s);break}case"excel":{const e=function(e,t,i){let n='<?xml version="1.0" encoding="UTF-8"?>\n<?mso-application progid="Excel.Sheet"?>\n<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"\n xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">\n<Worksheet ss:Name="Sheet1">\n<Table>';if(!1!==i.includeHeaders){n+="\n<Row>";for(const e of t){const t=e.header||e.field;n+=`<Cell><Data ss:Type="String">${ce(i.processHeader?i.processHeader(t,e.field):t)}</Data></Cell>`}n+="</Row>"}for(const r of e){n+="\n<Row>";for(const e of t){let t=r[e.field];i.processCell&&(t=i.processCell(t,e.field,r));let o="String",s="";null==t?s="":"number"!=typeof t||isNaN(t)?t instanceof Date?(o="DateTime",s=t.toISOString()):s=ce(String(t)):(o="Number",s=String(t)),n+=`<Cell><Data ss:Type="${o}">${s}</Data></Cell>`}n+="</Row>"}return n+="\n</Table>\n</Worksheet>\n</Workbook>",n}(o,r,n);s=s.endsWith(".xls")?s:`${s}.xls`,function(e,t){const i=t.endsWith(".xls")?t:`${t}.xls`;de(new Blob([e],{type:"application/vnd.ms-excel;charset=utf-8;"}),i)}(e,s);break}case"json":{const e=o.map(e=>{const t={};for(const i of r){let r=e[i.field];n.processCell&&(r=n.processCell(r,i.field,e)),t[i.field]=r}return t}),t=JSON.stringify(e,null,2);s=s.endsWith(".json")?s:`${s}.json`;de(new Blob([t],{type:"application/json"}),s);break}}this.lastExportInfo={format:e,timestamp:/* @__PURE__ */new Date},this.emit("export-complete",{format:e,fileName:s,rowCount:o.length,columnCount:r.length})}finally{this.isExportingFlag=!1}}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}const he="(Blank)";function ge(e){if(e instanceof Date)return e.getTime();const t=Number(e);if(!isNaN(t))return t;return new Date(e).getTime()}function pe(e,t,i=!1,n){return t.length?e.filter(e=>t.every(t=>function(e,t,i=!1,n){const r=e[t.field];if("blank"===t.operator)return null==r||""===r;if("notBlank"===t.operator)return null!=r&&""!==r;if(n&&("notIn"===t.operator||"in"===t.operator)){const i=n(r,e),o=Array.isArray(i)?i:null!=i?[i]:[];if("notIn"===t.operator){const e=t.value;return!Array.isArray(e)||(0===o.length?!e.includes(he):!o.some(t=>e.includes(t)))}if("in"===t.operator){const e=t.value;return!!Array.isArray(e)&&(0===o.length?e.includes(he):o.some(t=>e.includes(t)))}}if("notIn"===t.operator)return null==r||""===r?!Array.isArray(t.value)||!t.value.includes(he):Array.isArray(t.value)&&!t.value.includes(r);if("in"===t.operator)return null==r||""===r?Array.isArray(t.value)&&t.value.includes(he):Array.isArray(t.value)&&t.value.includes(r);if(null==r)return!1;const o=String(r),s=i?o:o.toLowerCase(),a=i?String(t.value):String(t.value).toLowerCase();switch(t.operator){case"contains":return s.includes(a);case"notContains":return!s.includes(a);case"equals":return s===a;case"notEquals":return s!==a;case"startsWith":return s.startsWith(a);case"endsWith":return s.endsWith(a);case"lessThan":return ge(r)<ge(t.value);case"lessThanOrEqual":return ge(r)<=ge(t.value);case"greaterThan":return ge(r)>ge(t.value);case"greaterThanOrEqual":return ge(r)>=ge(t.value);case"between":return ge(r)>=ge(t.value)&&ge(r)<=ge(t.valueTo);default:return!0}}(e,t,i,n?.get(t.field)))):e}function fe(e,t,i){const n=/* @__PURE__ */new Set;let r=!1;for(const o of e){const e=o[t];if(i){const t=i(e,o);if(Array.isArray(t)){0===t.length&&(r=!0);for(const e of t)null!=e&&n.add(e)}else null!=t?n.add(t):r=!0}else null!=e&&""!==e?n.add(e):r=!0}return r&&n.add(he),[...n].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t)))}function me(e,t){const i=/* @__PURE__ */new Map;for(const{field:r,filterValue:o}of t)i.set(r,{values:/* @__PURE__ */new Set,hasBlank:!1,hasExtractor:!!o});for(const r of e)for(const{field:e,filterValue:n}of t){const t=i.get(e),o=r[e];if(n){const e=n(o,r);if(Array.isArray(e)){0===e.length&&(t.hasBlank=!0);for(const i of e)null!=i&&t.values.add(i)}else null!=e?t.values.add(e):t.hasBlank=!0}else null!=o&&""!==o?t.values.add(o):t.hasBlank=!0}const n=/* @__PURE__ */new Map;for(const[r,{values:o,hasBlank:s}]of i)s&&o.add(he),n.set(r,[...o].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t))));return n}const we="__tbw_expander";function be(e){return e.field===we}function ve(e){return!0===e.meta?.utility}class ye extends e{static manifest={events:[{type:"filter-applied",description:"Emitted when filter criteria change. Subscribers can react to row visibility changes."}],queries:[{type:"getContextMenuItems",description:"Contributes filter-related items to the header context menu"}]};name="filtering";styles='@layer tbw-plugins{tbw-grid{.tbw-quick-filter-input{flex:1;max-width:300px;height:var(--tbw-input-height, 1.75rem);padding:var(--tbw-input-padding, 0 .5rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:var(--tbw-font-size-sm, .8125rem);&:focus{outline:none;border-color:var(--tbw-color-accent)}}.header-cell.filtered:before{content:"";position:absolute;top:var(--tbw-spacing-xs, .25rem);right:var(--tbw-spacing-xs, .25rem);width:var(--tbw-indicator-size, .375rem);height:var(--tbw-indicator-size, .375rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}.tbw-filter-btn{display:var(--tbw-filter-btn-display, inline-flex);visibility:var(--tbw-filter-btn-visibility, visible);align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:var(--tbw-spacing-xs, .25rem);opacity:.4;transition:opacity .15s,visibility 0s,display 0s allow-discrete;color:inherit;vertical-align:middle;transition-behavior:allow-discrete;&:hover,&.active{opacity:1;visibility:visible;display:inline-flex}&.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}}.header-row .cell:hover .tbw-filter-btn,.header-row .cell.filtered .tbw-filter-btn{display:inline-flex;visibility:visible}}}';get defaultConfig(){return{debounceMs:300,caseSensitive:!1,trimInput:!0,useWorker:!0}}isFilteringEnabled(){return!1!==this.grid.effectiveConfig?.filterable}isColumnFilterable(e){return!!this.isFilteringEnabled()&&!1!==e.filterable}getFilterValues(){const e=this.grid.effectiveConfig?.columns;if(!e)return;let t;for(const i of e)i.field&&i.filterValue&&(t||(t=/* @__PURE__ */new Map),t.set(i.field,i.filterValue));return t}filters=/* @__PURE__ */new Map;cachedResult=null;cacheKey=null;cachedInputSpot=null;openPanelField=null;panelElement=null;panelAnchorElement=null;searchText=/* @__PURE__ */new Map;excludedValues=/* @__PURE__ */new Map;panelAbortController=null;globalStylesInjected=!1;static DEFAULT_LIST_ITEM_HEIGHT=28;static LIST_OVERSCAN=3;static LIST_BYPASS_THRESHOLD=50;getListItemHeight(){if(this.panelElement){const e=getComputedStyle(this.panelElement).getPropertyValue("--tbw-filter-item-height");if(e&&e.trim()){const t=parseFloat(e);if(!isNaN(t)&&t>0)return t}}return ye.DEFAULT_LIST_ITEM_HEIGHT}computeSelected(){const e=[];for(const[n,r]of this.filters){if("set"!==r.type||"notIn"!==r.operator)continue;const t=this.grid.effectiveConfig?.columns?.find(e=>e.field===n);e.push({field:n,filterValue:t?.filterValue})}if(0===e.length)return{};const t=me(this.sourceRows,e),i={};for(const{field:n}of e){const e=this.excludedValues.get(n),r=t.get(n)??[];i[n]=e?r.filter(t=>!e.has(t)):r}return i}syncExcludedValues(e,t){t?"set"===t.type&&"notIn"===t.operator&&Array.isArray(t.value)?this.excludedValues.set(e,new Set(t.value)):"set"===t.type&&this.excludedValues.delete(e):this.excludedValues.delete(e)}attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.panelAbortController?.abort(),this.panelAbortController=null}handleQuery(e){if("getContextMenuItems"===e.type){const t=e.context;if(!t.isHeader)return;const i=t.column;if(!i?.field)return;if(!this.isFilteringEnabled())return;if(!this.isColumnFilterable(i))return;const n=[],r=this.isFieldFiltered(i.field),o=this.filters.size>0;return r&&n.push({id:"filtering/clear-column-filter",label:"Clear Filter",icon:"✕",order:20,action:()=>this.clearFieldFilter(i.field)}),o&&n.push({id:"filtering/clear-all-filters",label:"Clear All Filters",icon:"✕",order:21,disabled:!o,action:()=>this.clearAllFilters()}),n.length>0?n:void 0}}processRows(e){const t=[...this.filters.values()];if(!t.length)return[...e];if(this.config.filterHandler)return this.cachedResult?this.cachedResult:[...e];const i=(n=t,JSON.stringify(n.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo}))));var n;const r={len:e.length,first:e[0],mid:e[Math.floor(e.length/2)],last:e[e.length-1]},o=null!=this.cachedInputSpot&&r.len===this.cachedInputSpot.len&&r.first===this.cachedInputSpot.first&&r.mid===this.cachedInputSpot.mid&&r.last===this.cachedInputSpot.last;if(this.cacheKey===i&&this.cachedResult&&o)return this.cachedResult;const s=pe([...e],t,this.config.caseSensitive,this.getFilterValues());return this.cachedResult=s,this.cacheKey=i,this.cachedInputSpot=r,s}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(e=>{const t=e.getAttribute("data-col");if(null===t)return;const i=this.visibleColumns[parseInt(t,10)];if(!i||!this.isColumnFilterable(i))return;if(ve(i))return;const n=i.field;if(!n)return;const r=this.filters.has(n);let o=e.querySelector(".tbw-filter-btn");if(o){const t=o.classList.contains("active");if(o.classList.toggle("active",r),e.classList.toggle("filtered",r),t!==r){const e=r?"filterActive":"filter";this.setIcon(o,this.resolveIcon(e))}return}o=document.createElement("button"),o.className="tbw-filter-btn",o.setAttribute("aria-label",`Filter ${i.header??n}`);const s=r?"filterActive":"filter";this.setIcon(o,this.resolveIcon(s)),r&&(o.classList.add("active"),e.classList.add("filtered")),o.addEventListener("click",e=>{e.stopPropagation(),this.toggleFilterPanel(n,i,o)});const a=e.querySelector(".resize-handle");a?e.insertBefore(o,a):e.appendChild(o)})}setFilter(e,t){if(null===t)this.filters.delete(e),this.syncExcludedValues(e,null);else{const i={...t,field:e};this.filters.set(e,i),this.syncExcludedValues(e,i)}this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0,selected:this.computeSelected()}),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e){this.filters.clear(),this.excludedValues.clear();for(const t of e)this.filters.set(t.field,t),this.syncExcludedValues(t.field,t);this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0,selected:this.computeSelected()}),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}clearAllFilters(){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal()}clearFieldFilter(e){this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal()}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){const t=this.grid.effectiveConfig?.columns?.find(t=>t.field===e),i=t?.filterValue;return fe(this.sourceRows,e,i)}copyGridThemeContext(e){const t=this.gridElement;if(!t)return;for(const n of t.classList)n.startsWith("tbw-")||"selecting"===n||e.classList.add(n);const i=t.dataset.theme;i&&(e.dataset.theme=i)}injectGlobalStyles(){if(this.globalStylesInjected)return;if(document.getElementById("tbw-filter-panel-styles"))return void(this.globalStylesInjected=!0);const e=document.createElement("style");e.id="tbw-filter-panel-styles",e.textContent="@layer tbw-plugins{.tbw-filter-panel{position:fixed;background:var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));color:var(--tbw-filter-panel-fg, var(--tbw-color-fg, light-dark(#222222, #eeeeee)));border:1px solid var(--tbw-filter-panel-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-panel-radius, var(--tbw-border-radius, .25rem));box-shadow:0 4px 16px var(--tbw-filter-panel-shadow, var(--tbw-color-shadow, light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3))));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));z-index:10000;min-width:200px;max-width:280px;max-height:350px;display:flex;flex-direction:column;font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-font-size, .8125rem);transform-origin:top center}.tbw-filter-panel.tbw-filter-panel-above{transform-origin:bottom center}.tbw-filter-panel.tbw-filter-panel-animated{animation:tbw-filter-panel-enter var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}.tbw-filter-panel.tbw-filter-panel-above.tbw-filter-panel-animated{animation:tbw-filter-panel-enter-above var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}@keyframes tbw-filter-panel-enter{0%{opacity:0;transform:scaleY(.3) translateY(-10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@keyframes tbw-filter-panel-enter-above{0%{opacity:0;transform:scaleY(.3) translateY(10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@supports (anchor-name: --test){.tbw-filter-panel{position-anchor:--tbw-filter-anchor;top:anchor(bottom);left:anchor(left);margin-top:4px;position-try-fallbacks:flip-inline,flip-block,flip-block flip-inline}}.tbw-filter-search{margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-search-input{height:var(--tbw-filter-item-height, 28px);width:100%;padding:var(--tbw-filter-search-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-search-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-actions{display:flex;padding:var(--tbw-button-padding-sm, .25rem .125rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-actions .tbw-filter-value-item{flex:1}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));max-height:180px;position:relative}.tbw-filter-values-spacer{width:1px}.tbw-filter-values-content{position:absolute;top:0;left:0;right:0}.tbw-filter-value-item{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding-sm, .25rem .125rem);cursor:pointer;border-radius:3px;height:var(--tbw-filter-item-height, 28px)}.tbw-filter-value-item:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-checkbox{margin:0;cursor:pointer;accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}.tbw-filter-no-match{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem)) 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding-top:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));color:var(--tbw-filter-accent-fg, var(--tbw-color-accent-fg, light-dark(#ffffff, #000000)));border:none;border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:transparent;color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-range-inputs,.tbw-filter-date-range{display:flex;align-items:flex-end;gap:var(--tbw-spacing-sm, .375rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-group,.tbw-filter-date-group{display:flex;flex-direction:column;gap:var(--tbw-spacing-xs, .25rem);flex:1}.tbw-filter-range-label{font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)))}.tbw-filter-range-input,.tbw-filter-date-input{width:100%;height:var(--tbw-filter-item-height, 28px);padding:var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-sm, .375rem);background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-range-input:focus,.tbw-filter-date-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-range-separator{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding-bottom:var(--tbw-spacing-xs, .25rem)}.tbw-filter-blank-option{display:flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-spacing-xs, .25rem) 0;margin-bottom:var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-sm, .8125rem);cursor:pointer;user-select:none}.tbw-filter-blank-checkbox{accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));margin:0;cursor:pointer}.tbw-filter-date-range.tbw-filter-disabled,.tbw-filter-range-inputs.tbw-filter-disabled,.tbw-filter-range-slider.tbw-filter-disabled{opacity:.4;pointer-events:none}.tbw-filter-range-slider{position:relative;height:24px;margin:var(--tbw-spacing-md, .5rem) 0 var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-track{position:absolute;top:50%;left:0;right:0;height:4px;background:var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-fill{position:absolute;top:50%;height:4px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-thumb{position:absolute;top:0;width:100%;height:100%;background:none;pointer-events:none;-webkit-appearance:none;appearance:none}.tbw-filter-range-thumb::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-moz-range-thumb{width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-webkit-slider-thumb:hover{transform:scale(1.1)}.tbw-filter-range-thumb::-moz-range-thumb:hover{transform:scale(1.1)}}",document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,i){if(this.openPanelField===e)return void this.closeFilterPanel();this.closeFilterPanel();const n=document.createElement("div");if(n.className="tbw-filter-panel",this.copyGridThemeContext(n),this.isAnimationEnabled&&n.classList.add("tbw-filter-panel-animated"),this.panelElement=n,this.openPanelField=e,this.config.valuesHandler)return n.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(n),this.positionPanel(n,i),this.setupPanelCloseHandler(n,i),void this.config.valuesHandler(e,t).then(i=>{this.openPanelField===e&&this.panelElement&&(n.innerHTML="",this.renderPanelContent(e,t,n,i))});const r=fe(this.sourceRows,e,t.filterValue);document.body.appendChild(n),this.positionPanel(n,i),this.renderPanelContent(e,t,n,r),this.setupPanelCloseHandler(n,i)}renderPanelContent(e,t,i,n){let r=this.excludedValues.get(e);r||(r=/* @__PURE__ */new Set,this.excludedValues.set(e,r));const o=this.searchText.get(e)??"",s={field:e,column:t,uniqueValues:n,excludedValues:r,searchText:o,currentFilter:this.filters.get(e),applySetFilter:(t,i)=>{this.applySetFilter(e,t,i),this.closeFilterPanel()},applyTextFilter:(t,i,n)=>{this.applyTextFilter(e,t,i,n),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(e),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let a=!1;if(this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,s),a=i.children.length>0),!a&&t.type){const e=this.grid.effectiveConfig.typeDefaults?.[t.type];e?.filterPanelRenderer&&(e.filterPanelRenderer(i,s),a=i.children.length>0)}if(!a){const e=t.type;"number"===e?this.renderNumberFilterPanel(i,s,n):"date"===e?this.renderDateFilterPanel(i,s,n):this.renderDefaultFilterPanel(i,s,n,r)}}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController,setTimeout(()=>{document.addEventListener("click",i=>{e.contains(i.target)||i.target===t||this.closeFilterPanel()},{signal:this.panelAbortController?.signal})},0)}closeFilterPanel(){const e=this.panelElement;e&&(e.remove(),this.panelElement=null),this.panelAnchorElement&&(this.panelAnchorElement.style.anchorName="",this.panelAnchorElement=null),this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}static supportsAnchorPositioning=null;static checkAnchorPositioningSupport(){return null===ye.supportsAnchorPositioning&&(ye.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),ye.supportsAnchorPositioning}positionPanel(e,t){const i=t.closest(".cell")??t;if(i.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=i,ye.checkAnchorPositioningSupport())return void requestAnimationFrame(()=>{const t=e.getBoundingClientRect(),n=i.getBoundingClientRect();t.top<n.top&&e.classList.add("tbw-filter-panel-above")});const n=i.getBoundingClientRect();e.style.position="fixed",e.style.top=`${n.bottom+4}px`,e.style.left=`${n.left}px`,requestAnimationFrame(()=>{const t=e.getBoundingClientRect();t.right>window.innerWidth-8&&(e.style.left=n.right-t.width+"px"),t.bottom>window.innerHeight-8&&(e.style.top=n.top-t.height-4+"px",e.classList.add("tbw-filter-panel-above"))})}renderDefaultFilterPanel(e,t,i,n){const{field:s,column:a}=t,l=this.getListItemHeight(),d=e=>{if(null==e)return"(Blank)";if(a.format&&!a.filterValue){const t=a.format(e,void 0);if(t)return t}return String(e)};i=i.slice().sort((e,t)=>d(e).localeCompare(d(t)));const c=document.createElement("div");c.className="tbw-filter-search";const u=document.createElement("input");u.type="text",u.placeholder="Search...",u.className="tbw-filter-search-input",u.value=this.searchText.get(s)??"",c.appendChild(u),e.appendChild(c);const h=document.createElement("div");h.className="tbw-filter-actions";const g=document.createElement("label");g.className="tbw-filter-value-item",g.style.padding="0",g.style.margin="0";const p=document.createElement("input");p.type="checkbox",p.className="tbw-filter-checkbox";const f=document.createElement("span");f.textContent="Select All",g.appendChild(p),g.appendChild(f),h.appendChild(g);const m=()=>{const e=[...y.values()],t=e.every(e=>e),i=e.every(e=>!e);p.checked=t,p.indeterminate=!t&&!i};p.addEventListener("change",()=>{const e=p.checked;for(const t of y.keys())y.set(t,e);m(),E()}),e.appendChild(h);const w=document.createElement("div");w.className="tbw-filter-values";const b=document.createElement("div");b.className="tbw-filter-values-spacer",w.appendChild(b);const v=document.createElement("div");v.className="tbw-filter-values-content",w.appendChild(v);const y=/* @__PURE__ */new Map;i.forEach(e=>{const t=null==e?"__null__":String(e);y.set(t,!n.has(e))}),m();let x=[];const C=(e,t)=>{const i=d(e),n=null==e?"__null__":String(e),r=document.createElement("label");r.className="tbw-filter-value-item",r.style.position="absolute",r.style.top=`calc(var(--tbw-filter-item-height, 28px) * ${t})`,r.style.left="0",r.style.right="0",r.style.boxSizing="border-box";const o=document.createElement("input");o.type="checkbox",o.className="tbw-filter-checkbox",o.checked=y.get(n)??!0,o.dataset.value=n,o.addEventListener("change",()=>{y.set(n,o.checked),m()});const s=document.createElement("span");return s.textContent=i,r.appendChild(o),r.appendChild(s),r},E=()=>{const e=x.length,t=w.clientHeight,i=w.scrollTop;if(b.style.height=e*l+"px",r(e,ye.LIST_BYPASS_THRESHOLD/3))return v.innerHTML="",v.style.transform="translateY(0px)",void x.forEach((e,t)=>{v.appendChild(C(e,t))});const n=o({totalRows:e,viewportHeight:t,scrollTop:i,rowHeight:l,overscan:ye.LIST_OVERSCAN});v.style.transform=`translateY(${n.offsetY}px)`,v.innerHTML="";for(let r=n.start;r<n.end;r++)v.appendChild(C(x[r],r-n.start))},R=e=>{const t=this.config.caseSensitive??!1,n=t?e:e.toLowerCase();if(x=i.filter(i=>{const r=d(i),o=t?r:r.toLowerCase();return!e||o.includes(n)}),0===x.length){b.style.height="0px",v.innerHTML="";const e=document.createElement("div");return e.className="tbw-filter-no-match",e.textContent="No matching values",void v.appendChild(e)}E()};let S;w.addEventListener("scroll",()=>{x.length>0&&E()},{passive:!0}),R(u.value),e.appendChild(w),u.addEventListener("input",()=>{clearTimeout(S),S=setTimeout(()=>{this.searchText.set(s,u.value),R(u.value)},this.config.debounceMs??150)});const k=document.createElement("div");k.className="tbw-filter-buttons";const A=document.createElement("button");A.className="tbw-filter-apply-btn",A.textContent="Apply",A.addEventListener("click",()=>{const e=[];for(const[t,n]of y)if(!n)if("__null__"===t)e.push(null);else{const n=i.find(e=>String(e)===t);e.push(void 0!==n?n:t)}t.applySetFilter(e)}),k.appendChild(A);const _=document.createElement("button");_.className="tbw-filter-clear-btn",_.textContent="Clear Filter",_.addEventListener("click",()=>{t.clearFilter()}),k.appendChild(_),e.appendChild(k)}renderNumberFilterPanel(e,t,i){const{field:n,column:r}=t,o=r.filterParams,s=r.editorParams,a=(e,t)=>{if("number"==typeof e)return e;if("string"==typeof e){const i=parseFloat(e);return isNaN(i)?t:i}return t},l=i.filter(e=>"number"==typeof e&&!isNaN(e)),d=l.length>0?Math.min(...l):0,c=l.length>0?Math.max(...l):100,u=a(o?.min??s?.min,d),h=a(o?.max??s?.max,c),g=o?.step??s?.step??1,p=this.filters.get(n);let f=u,m=h;const w="blank"===p?.operator;"between"===p?.operator?(f=a(p.value,u),m=a(p.valueTo,h)):"greaterThanOrEqual"===p?.operator?f=a(p.value,u):"lessThanOrEqual"===p?.operator&&(m=a(p.value,h));const b=document.createElement("div");b.className="tbw-filter-range-inputs";const v=document.createElement("div");v.className="tbw-filter-range-group";const y=document.createElement("label");y.textContent="Min",y.className="tbw-filter-range-label";const x=document.createElement("input");x.type="number",x.className="tbw-filter-range-input",x.min=String(u),x.max=String(h),x.step=String(g),x.value=String(f),v.appendChild(y),v.appendChild(x),b.appendChild(v);const C=document.createElement("span");C.className="tbw-filter-range-separator",C.textContent="–",b.appendChild(C);const E=document.createElement("div");E.className="tbw-filter-range-group";const R=document.createElement("label");R.textContent="Max",R.className="tbw-filter-range-label";const S=document.createElement("input");S.type="number",S.className="tbw-filter-range-input",S.min=String(u),S.max=String(h),S.step=String(g),S.value=String(m),E.appendChild(R),E.appendChild(S),b.appendChild(E),e.appendChild(b);const k=document.createElement("div");k.className="tbw-filter-range-slider";const A=document.createElement("div");A.className="tbw-filter-range-track";const _=document.createElement("div");_.className="tbw-filter-range-fill";const L=document.createElement("input");L.type="range",L.className="tbw-filter-range-thumb tbw-filter-range-thumb-min",L.min=String(u),L.max=String(h),L.step=String(g),L.value=String(f);const I=document.createElement("input");I.type="range",I.className="tbw-filter-range-thumb tbw-filter-range-thumb-max",I.min=String(u),I.max=String(h),I.step=String(g),I.value=String(m),k.appendChild(A),k.appendChild(_),k.appendChild(L),k.appendChild(I),e.appendChild(k);const T=document.createElement("label");T.className="tbw-filter-blank-option";const F=document.createElement("input");F.type="checkbox",F.className="tbw-filter-blank-checkbox",F.checked=w;const M=document.createTextNode("Blank");T.appendChild(F),T.appendChild(M);const D=e=>{x.disabled=e,S.disabled=e,L.disabled=e,I.disabled=e,b.classList.toggle("tbw-filter-disabled",e),k.classList.toggle("tbw-filter-disabled",e)};D(w),F.addEventListener("change",()=>{D(F.checked)}),e.appendChild(T);const P=()=>{const e=parseFloat(L.value),t=parseFloat(I.value),i=h-u,n=(e-u)/i*100,r=(t-u)/i*100;_.style.left=`${n}%`,_.style.width=r-n+"%"};L.addEventListener("input",()=>{const e=Math.min(parseFloat(L.value),parseFloat(I.value));L.value=String(e),x.value=String(e),P()}),I.addEventListener("input",()=>{const e=Math.max(parseFloat(I.value),parseFloat(L.value));I.value=String(e),S.value=String(e),P()}),x.addEventListener("input",()=>{let e=parseFloat(x.value)||u;e=Math.max(u,Math.min(e,parseFloat(S.value))),L.value=String(e),P()}),S.addEventListener("input",()=>{let e=parseFloat(S.value)||h;e=Math.min(h,Math.max(e,parseFloat(x.value))),I.value=String(e),P()}),P();const q=document.createElement("div");q.className="tbw-filter-buttons";const H=document.createElement("button");H.className="tbw-filter-apply-btn",H.textContent="Apply",H.addEventListener("click",()=>{if(F.checked)return void t.applyTextFilter("blank","");const e=parseFloat(x.value),i=parseFloat(S.value);t.applyTextFilter("between",e,i)}),q.appendChild(H);const N=document.createElement("button");N.className="tbw-filter-clear-btn",N.textContent="Clear Filter",N.addEventListener("click",()=>{t.clearFilter()}),q.appendChild(N),e.appendChild(q)}renderDateFilterPanel(e,t,i){const{field:n,column:r}=t,o=r.filterParams,s=r.editorParams,a=i.filter(e=>e instanceof Date||"string"==typeof e&&!isNaN(Date.parse(e))).map(e=>e instanceof Date?e:new Date(e)).filter(e=>!isNaN(e.getTime())),l=a.length>0?new Date(Math.min(...a.map(e=>e.getTime()))):null,d=a.length>0?new Date(Math.max(...a.map(e=>e.getTime()))):null,c=e=>e?e.toISOString().split("T")[0]:"",u=e=>e?"string"==typeof e?e:"number"==typeof e?c(new Date(e)):"":"",h=u(o?.min)||u(s?.min)||c(l),g=u(o?.max)||u(s?.max)||c(d),p=this.filters.get(n);let f="",m="";const w="blank"===p?.operator;"between"===p?.operator?(f=u(p.value)||"",m=u(p.valueTo)||""):"greaterThanOrEqual"===p?.operator?f=u(p.value)||"":"lessThanOrEqual"===p?.operator&&(m=u(p.value)||"");const b=document.createElement("div");b.className="tbw-filter-date-range";const v=document.createElement("div");v.className="tbw-filter-date-group";const y=document.createElement("label");y.textContent="From",y.className="tbw-filter-range-label";const x=document.createElement("input");x.type="date",x.className="tbw-filter-date-input",h&&(x.min=h),g&&(x.max=g),x.value=f,v.appendChild(y),v.appendChild(x),b.appendChild(v);const C=document.createElement("span");C.className="tbw-filter-range-separator",C.textContent="–",b.appendChild(C);const E=document.createElement("div");E.className="tbw-filter-date-group";const R=document.createElement("label");R.textContent="To",R.className="tbw-filter-range-label";const S=document.createElement("input");S.type="date",S.className="tbw-filter-date-input",h&&(S.min=h),g&&(S.max=g),S.value=m,E.appendChild(R),E.appendChild(S),b.appendChild(E),e.appendChild(b);const k=document.createElement("label");k.className="tbw-filter-blank-option";const A=document.createElement("input");A.type="checkbox",A.className="tbw-filter-blank-checkbox",A.checked=w;const _=document.createTextNode("Show only blank");k.appendChild(A),k.appendChild(_);const L=e=>{x.disabled=e,S.disabled=e,b.classList.toggle("tbw-filter-disabled",e)};L(w),A.addEventListener("change",()=>{L(A.checked)}),e.appendChild(k);const I=document.createElement("div");I.className="tbw-filter-buttons";const T=document.createElement("button");T.className="tbw-filter-apply-btn",T.textContent="Apply",T.addEventListener("click",()=>{if(A.checked)return void t.applyTextFilter("blank","");const e=x.value,i=S.value;e&&i?t.applyTextFilter("between",e,i):e?t.applyTextFilter("greaterThanOrEqual",e):i?t.applyTextFilter("lessThanOrEqual",i):t.clearFilter()}),I.appendChild(T);const F=document.createElement("button");F.className="tbw-filter-clear-btn",F.textContent="Clear Filter",F.addEventListener("click",()=>{t.clearFilter()}),I.appendChild(F),e.appendChild(I)}applySetFilter(e,t,i){this.excludedValues.set(e,new Set(t)),0===t.length?this.filters.delete(e):this.filters.set(e,{field:e,type:"set",operator:"notIn",value:t,...void 0!==i&&{valueTo:i}}),this.applyFiltersInternal()}applyTextFilter(e,t,i,n){this.filters.set(e,{field:e,type:"text",operator:t,value:i,valueTo:n}),this.applyFiltersInternal()}applyFiltersInternal(){this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null;const e=[...this.filters.values()];if(this.config.filterHandler){const t=this.grid;t.setAttribute("aria-busy","true");const i=this.config.filterHandler(e,this.sourceRows),n=i=>{t.removeAttribute("aria-busy"),this.cachedResult=i,this.grid.rows=i,this.emit("filter-change",{filters:e,filteredRowCount:i.length,selected:this.computeSelected()}),this.emitPluginEvent("filter-applied",{filters:e}),this.requestRender()};return void(i&&"function"==typeof i.then?i.then(n):n(i))}this.emit("filter-change",{filters:e,filteredRowCount:0,selected:this.computeSelected()}),this.emitPluginEvent("filter-applied",{filters:e}),this.requestRender()}getColumnState(e){const t=this.filters.get(e);if(t)return{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}}applyColumnState(e,t){if(!t.filter)return void this.filters.delete(e);const i={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,i),this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null}}function xe(e){if(!e.length)return[];const t=/* @__PURE__ */new Map,i=[],n=(e,t)=>{if(!t.length)return;const n=i[i.length-1];n&&n.implicit&&n.firstIndex+n.columns.length===e?n.columns.push(...t):i.push({id:"__implicit__"+e,label:void 0,columns:t,firstIndex:e,implicit:!0})};let r=[],o=0;return e.forEach((e,s)=>{const a=e.group;if(!a)return 0===r.length&&(o=s),void r.push(e);r.length&&(n(o,r.slice()),r=[]);const l="string"==typeof a?a:a.id;let d=t.get(l);d||(d={id:l,label:"string"==typeof a?void 0:a.label,columns:[],firstIndex:s},t.set(l,d),i.push(d)),d.columns.push(e)}),r.length&&n(o,r),1===i.length&&i[0].implicit&&i[0].columns.length===e.length?[]:i}class Ce extends e{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}],queries:[{type:"getColumnGrouping",description:"Returns column group metadata for the visibility panel"}]};name="groupingColumns";styles="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";get defaultConfig(){return{showGroupBorders:!0,lockGroupOrder:!1}}groups=[];isActive=!1;#P=/* @__PURE__ */new Set;attach(e){super.attach(e),e.addEventListener("column-move",this.#q,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#P.clear()}#q=e=>{if(!this.isActive)return;const t=e,{field:i,columnOrder:n}=t.detail;if(this.config.lockGroupOrder)for(const r of this.groups)if(!r.id.startsWith("__implicit__")&&!this.#H(r,n))return t.preventDefault(),void this.#N(i);this.#z(n)};#z(e){this.#P.clear();const t=this.#G(e);for(const i of this.groups){const n=new Set(i.columns.map(e=>e.field));for(let i=e.length-1;i>=0;i--)if(n.has(e[i])){const n=e[i];n!==t&&this.#P.add(n);break}}}#G(e){if(0===this.groups.length)return null;for(let t=e.length-1;t>=0;t--){const i=e[t];for(const t of this.groups)if(t.columns.some(e=>e.field===i)){const i=new Set(t.columns.map(e=>e.field));for(let t=e.length-1;t>=0;t--)if(i.has(e[t]))return e[t]}}return null}#H(e,t){const i=e.columns.map(e=>t.indexOf(e.field)).filter(e=>-1!==e).sort((e,t)=>e-t);return i.length<=1||i.length===i[i.length-1]-i[0]+1}#N(e){const t=this.gridElement?.querySelector(`.header-row [part~="header-cell"][data-field="${e}"]`);t&&(t.style.setProperty("--_flash-color","var(--tbw-color-error)"),t.animate([{backgroundColor:"rgba(from var(--_flash-color) r g b / 30%)"},{backgroundColor:"transparent"}],{duration:400,easing:"ease-out"}))}handleQuery(e){if("getColumnGrouping"===e.type)return this.#K()}#K(){let e;const t=this.grid?.gridConfig?.columnGroups;if(t&&Array.isArray(t)&&t.length>0)e=t.filter(e=>e.children.length>0).map(e=>({id:e.id,label:e.header,fields:[...e.children]}));else if(this.isActive&&this.groups.length>0){e=this.groups.filter(e=>!e.id.startsWith("__implicit__")).map(e=>({id:e.id,label:e.label??e.id,fields:e.columns.map(e=>e.field)}));const t=this.columns;for(const i of t)if(i.hidden&&i.group){const t="string"==typeof i.group?i.group:i.group.id,n="string"==typeof i.group?i.group:i.group.label??i.group.id,r=e.find(e=>e.id===t);r?r.fields.includes(i.field)||r.fields.push(i.field):e.push({id:t,label:n,fields:[i.field]})}}else{const t=this.columns,i=/* @__PURE__ */new Map;for(const e of t){if(!e.group)continue;const t="string"==typeof e.group?e.group:e.group.id,n="string"==typeof e.group?e.group:e.group.label??e.group.id,r=i.get(t);r?r.fields.includes(e.field)||r.fields.push(e.field):i.set(t,{id:t,label:n,fields:[e.field]})}e=Array.from(i.values())}const i=this.grid?.getColumnOrder();if(i&&i.length>0){const t=new Map(i.map((e,t)=>[e,t]));for(const i of e)i.fields.sort((e,i)=>(t.get(e)??1/0)-(t.get(i)??1/0))}return e}static detect(e,t){if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const i=t?.columns;return!!Array.isArray(i)&&function(e){return e.some(e=>null!=e.group)}(i)}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let i;if(t&&Array.isArray(t)&&t.length>0){const n=/* @__PURE__ */new Map;for(const e of t)for(const t of e.children)n.set(t,{id:e.id,label:e.header});i=e.map(e=>{const t=n.get(e.field);return t&&!e.group?{...e,group:t}:e})}else i=[...e];const n=xe(i);if(0===n.length)return this.isActive=!1,this.groups=[],i;this.isActive=!0,this.groups=n,this.#P.clear();for(const r of n){const e=r.columns[r.columns.length-1];e?.field&&this.#P.add(e.field)}return i}afterRender(){if(!this.isActive){const e=this.gridElement?.querySelector(".header"),t=e?.querySelector(".header-group-row");return void(t&&t.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const i=this.visibleColumns,n=xe(i);if(0===n.length)return;this.#P.clear();for(let s=0;s<n.length;s++){const e=n[s],t=e.columns[e.columns.length-1];t?.field&&s<n.length-1&&this.#P.add(t.field)}const r=function(e,t){if(0===e.length)return null;const i=document.createElement("div");i.className="header-group-row",i.setAttribute("role","row");for(const n of e){const e=n.columns[0],r=e?t.findIndex(t=>t.field===e.field):-1;if(-1===r)continue;const o=String(n.id).startsWith("__implicit__"),s=o?"":n.label||n.id,a=document.createElement("div");a.className="cell header-group-cell",o&&a.classList.add("implicit-group"),a.setAttribute("data-group",String(n.id)),a.style.gridColumn=`${r+1} / span ${n.columns.length}`,a.textContent=s,i.appendChild(a)}return i}(n,i);if(r){r.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(r,t):e.appendChild(r)}const o=e.querySelector(".header-row");o&&(o.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,t){if(!t.length||!e)return;const i=/* @__PURE__ */new Map;for(const r of t)for(const e of r.columns)e.field&&i.set(e.field,r.id);const n=Array.from(e.querySelectorAll(".cell[data-field]"));n.forEach(e=>{const t=e.getAttribute("data-field")||"",n=i.get(t);n&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",n))});for(const r of t){const e=r.columns[r.columns.length-1],t=n.find(t=>t.getAttribute("data-field")===e.field);t&&t.classList.add("group-end")}}(o,n))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#P.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(t=>t.id===e);return t?t.columns:[]}refresh(){this.requestRender()}}function Ee({rows:e,config:t,expanded:i,initialExpanded:n}){const r=t.groupOn;if("function"!=typeof r)return[];const o={key:"__root__",value:null,depth:-1,rows:[],children:/* @__PURE__ */new Map};if(e.forEach(e=>{let t=r(e);null==t||!1===t?t=["__ungrouped__"]:Array.isArray(t)||(t=[t]);let i=o;t.forEach((e,t)=>{const n=null==e?"∅":String(e),r="__root__"===i.key?n:i.key+"||"+n;let o=i.children.get(n);o||(o={key:r,value:e,depth:t,rows:[],children:/* @__PURE__ */new Map,parent:i},i.children.set(n,o)),i=o}),i.rows.push(e)}),1===o.children.size&&o.children.has("__ungrouped__")){if(o.children.get("__ungrouped__").rows.length===e.length)return[]}const s=/* @__PURE__ */new Set([...i,...n??[]]),a=[],l=t=>{if(t===o)return void t.children.forEach(e=>l(e));const i=s.has(t.key);a.push({kind:"group",key:t.key,value:t.value,depth:t.depth,rows:t.rows,expanded:i}),i&&(t.children.size?t.children.forEach(e=>l(e)):t.rows.forEach(t=>a.push({kind:"data",row:t,rowIndex:e.indexOf(t)})))};return l(o),a}class Re extends e{static manifest={events:[{type:"grouping-state-change",description:"Emitted when groups are expanded/collapsed. Subscribers can react to row visibility changes."}],queries:[{type:"canMoveRow",description:"Returns false for group header rows (cannot be reordered)"}],configRules:[{id:"groupingRows/accordion-defaultExpanded",severity:"warn",message:'"accordion: true" and "defaultExpanded" (non-false) are used together.\n → In accordion mode, only one group can be open at a time.\n → Using defaultExpanded with multiple groups will collapse to one on first toggle.\n → Consider using "defaultExpanded: false" or a single group key/index with accordion mode.',check:e=>!0===e.accordion&&!1!==e.defaultExpanded&&void 0!==e.defaultExpanded&&!("number"==typeof e.defaultExpanded)&&!("string"==typeof e.defaultExpanded)&&(!0===e.defaultExpanded||Array.isArray(e.defaultExpanded)&&e.defaultExpanded.length>1)}]};name="groupingRows";styles="@layer tbw-plugins{.group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}.group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem)}.group-row:hover{background:var(--tbw-grouping-rows-bg-hover, var(--tbw-color-row-hover))}.group-toggle{cursor:pointer;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toggle-size, 1.25rem);height:var(--tbw-toggle-size, 1.25rem);margin-right:.25rem;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius, .125rem)}.group-label{display:inline-flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs, .85em);font-weight:400}.group-aggregates{display:inline-flex;align-items:center;gap:var(--tbw-spacing-lg, 1rem);margin-left:var(--tbw-spacing-lg, 1rem);font-weight:400;font-size:var(--tbw-font-size-sm, .875em);color:var(--tbw-grouping-rows-aggregate-color, var(--tbw-color-fg-muted))}.group-aggregate{white-space:nowrap}.group-row{padding-left:calc(var(--tbw-group-depth, 0) * var(--tbw-group-indent-width, 1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide",accordion:!1}}expandedKeys=/* @__PURE__ */new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasAppliedDefaultExpanded=!1;get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1}getRowHeight(e,t){if(null!=this.config.groupRowHeight)return!0===e.__isGroupRow?this.config.groupRowHeight:void 0}handleQuery(e){if("canMoveRow"===e.type){const t=e.context;if(!0===t?.__isGroupRow)return!1}}static detect(e,t){return"function"==typeof t?.groupOn||"boolean"==typeof t?.enableRowGrouping}processRows(e){const t=this.config;if("function"!=typeof t.groupOn)return this.isActive=!1,this.flattenedRows=[],[...e];const i=Ee({rows:[...e],config:t,expanded:/* @__PURE__ */new Set});if(0===i.length)return this.isActive=!1,this.flattenedRows=[],[...e];let n;if(!this.hasAppliedDefaultExpanded&&0===this.expandedKeys.size&&!1!==t.defaultExpanded){const e=function(e){return e.filter(e=>"group"===e.kind).map(e=>e.key)}(i);n=function(e,t){if(!0===e)return new Set(t);if(!1===e||null==e)/* @__PURE__ */
|
|
2
2
|
return new Set;if("number"==typeof e){const i=t[e];return i?/* @__PURE__ */new Set([i]):/* @__PURE__ */new Set}return"string"==typeof e?/* @__PURE__ */new Set([e]):Array.isArray(e)?new Set(e):/* @__PURE__ */new Set}(t.defaultExpanded??!1,e),n.size>0&&(this.expandedKeys=new Set(n),this.hasAppliedDefaultExpanded=!0)}const r=Ee({rows:[...e],config:t,expanded:this.expandedKeys,initialExpanded:n});this.isActive=!0,this.flattenedRows=r,this.keysToAnimate.clear();const o=/* @__PURE__ */new Set;return r.forEach((e,t)=>{if("data"===e.kind){const e=`data-${t}`;o.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=o,r.map(e=>{return"group"===e.kind?{__isGroupRow:!0,__groupKey:e.key,__groupValue:e.value,__groupDepth:e.depth,__groupRows:e.rows,__groupExpanded:e.expanded,__groupRowCount:(t=e,"group"!==t.kind?0:t.rows.length),__rowCacheKey:`group:${e.key}`}:e.row;var t})}onCellClick(e){const t=e.row;if(t?.__isGroupRow){const i=e.originalEvent.target;if(i?.closest(".group-toggle"))return this.toggle(t.__groupKey),!0}}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,i=this.rows[t];return i?.__isGroupRow?(e.preventDefault(),this.toggle(i.__groupKey),this.requestRenderWithFocus(),!0):void 0}renderRow(e,t,i){if(!e?.__isGroupRow)return!1;const n=this.config;if(n.groupRowRenderer){const i=()=>{this.toggle(e.__groupKey)},r=n.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:i});if(r)return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),"string"==typeof r?t.innerHTML=r:(t.innerHTML="",t.appendChild(r)),!0}const r=()=>{this.toggle(e.__groupKey)};t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),t.setAttribute("role","row"),t.setAttribute("aria-expanded",String(e.__groupExpanded)),t.style.setProperty("--tbw-group-depth",String(e.__groupDepth||0)),void 0!==n.indentWidth&&t.style.setProperty("--tbw-group-indent-width",`${n.indentWidth}px`),t.style.height="",t.innerHTML="";return!1!==n.fullWidth?this.renderFullWidthGroupRow(e,t,r):this.renderPerColumnGroupRow(e,t,r),!0}afterRender(){const e=this.animationStyle;if(!1===e||0===this.keysToAnimate.size)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i="fade"===e?"tbw-group-fade-in":"tbw-group-slide-in";for(const n of t.querySelectorAll(".data-grid-row:not(.group-row)")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r=this.flattenedRows[t],o="data"===r?.kind?`data-${t}`:void 0;o&&this.keysToAnimate.has(o)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}createToggleButton(e,t){const i=document.createElement("button");return i.type="button",i.className="group-toggle"+(e?" expanded":""),i.setAttribute("aria-label",e?"Collapse group":"Expand group"),this.setIcon(i,this.resolveIcon(e?"collapse":"expand")),i.addEventListener("click",e=>{e.stopPropagation(),t()}),i}getGroupLabelText(e,t,i){const n=this.config;return n.formatLabel?n.formatLabel(e,t,i):String(e)}renderFullWidthGroupRow(e,t,i){const n=this.config,r=n.aggregators??{},o=e.__groupRows??[],a=document.createElement("div");a.className="cell group-full",a.style.gridColumn="1 / -1",a.setAttribute("role","gridcell"),a.setAttribute("data-col","0"),a.appendChild(this.createToggleButton(e.__groupExpanded,i));const l=document.createElement("span");if(l.className="group-label",l.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),a.appendChild(l),!1!==n.showRowCount){const t=document.createElement("span");t.className="group-count",t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,a.appendChild(t)}const d=Object.entries(r);if(d.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[t,i]of d){const n=this.columns.find(e=>e.field===t),r=s(i,o,t,n);if(null!=r){const i=document.createElement("span");i.className="group-aggregate",i.setAttribute("data-field",t);const o=n?.header??t;i.textContent=`${o}: ${r}`,e.appendChild(i)}}e.children.length>0&&a.appendChild(e)}t.appendChild(a)}renderPerColumnGroupRow(e,t,i){const n=this.config,r=n.aggregators??{},o=this.columns,a=e.__groupRows??[],l=this.gridElement?.querySelector(".body"),d=l?.style.gridTemplateColumns||"";d&&(t.style.display="grid",t.style.gridTemplateColumns=d);let c=!1;o.forEach((o,l)=>{const d=document.createElement("div");if(d.className="cell group-cell",d.setAttribute("data-col",String(l)),d.setAttribute("role","gridcell"),be(o))return d.setAttribute("data-field",o.field),void t.appendChild(d);if(c){const e=r[o.field];if(e){const t=s(e,a,o.field,o);d.textContent=null!=t?String(t):""}else d.textContent=""}else{c=!0,d.appendChild(this.createToggleButton(e.__groupExpanded,i));const t=document.createElement("span"),l=r[o.field];if(l){const i=s(l,a,o.field,o);t.textContent=String(null!=i?i:e.__groupValue)}else t.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(d.appendChild(t),!1!==n.showRowCount){const e=document.createElement("span");e.className="group-count",e.textContent=` (${a.length})`,d.appendChild(e)}}t.appendChild(d)})}expandAll(){this.expandedKeys=function(e){const t=/* @__PURE__ */new Set;for(const i of e)"group"===i.kind&&t.add(i.key);return t}(this.flattenedRows),this.emitPluginEvent("grouping-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=/* @__PURE__ */new Set,this.emitPluginEvent("grouping-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}toggle(e){const t=!this.expandedKeys.has(e),i=this.config,n=this.flattenedRows.find(t=>"group"===t.kind&&t.key===e);if(i.accordion&&t&&n){const t=/* @__PURE__ */new Set;for(const i of this.expandedKeys)if(e.startsWith(i+"||")||i.startsWith(e+"||"))e.startsWith(i+"||")&&t.add(i);else{const e=this.flattenedRows.find(e=>"group"===e.kind&&e.key===i);e&&e.depth!==n.depth&&t.add(i)}t.add(e),this.expandedKeys=t}else this.expandedKeys=function(e,t){const i=new Set(e);return i.has(t)?i.delete(t):i.add(t),i}(this.expandedKeys,e);this.emit("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:n?.value,depth:n?.depth??0}),this.emitPluginEvent("grouping-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=/* @__PURE__ */new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(e=>"group"===e.kind);return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e){this.config.groupOn=e,this.requestRender()}}function Se(e,t){const i=new Set(e);return i.has(t)?i.delete(t):i.add(t),i}function ke(e,t,i,n){const r=document.createElement("div");r.className="master-detail-row",r.setAttribute("data-detail-for",String(t)),r.setAttribute("role","row");const o=document.createElement("div");o.className="master-detail-cell",o.setAttribute("role","cell"),o.style.gridColumn=`1 / ${n+1}`;const s=i(e,t);return"string"==typeof s?o.innerHTML=s:s instanceof HTMLElement&&o.appendChild(s),r.appendChild(o),r}class Ae extends e{name="masterDetail";styles="@layer tbw-plugins{tbw-grid{.cell[data-field=__tbw_expander]{border-right:none!important;padding:0;display:flex;align-items:center;justify-content:center}.header-row .cell[data-field=__tbw_expander]{display:none}.header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}.master-detail-expander{display:flex;align-items:center;justify-content:center;width:100%;height:100%}.master-detail-toggle{cursor:pointer;opacity:.7;user-select:none;display:inline-flex;align-items:center;justify-content:center}.master-detail-toggle:hover{opacity:1}.master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border));overflow:hidden}.master-detail-cell{padding:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));overflow:auto}.master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}.master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem);padding-top:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem));padding-bottom:var(--tbw-detail-padding, var(--tbw-spacing-xl, 1rem))}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:var(--tbw-detail-max-height, 31.25rem)}to{opacity:0;max-height:0}}}";get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,collapseOnClickOutside:!1,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail()}parseLightDomDetail(){const e=this.grid;if(!e||"function"!=typeof e.querySelector)return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseDetailElement){const e=i.__frameworkAdapter.parseDetailElement(t);if(e)return void(this.config={...this.config,detailRenderer:e})}const n=t.getAttribute("animation"),r=t.getAttribute("show-expand-column"),o=t.getAttribute("expand-on-row-click"),s=t.getAttribute("collapse-on-click-outside"),d=t.getAttribute("height"),c={};null!==n&&(c.animation="false"!==n&&n),null!==r&&(c.showExpandColumn="false"!==r),null!==o&&(c.expandOnRowClick="true"===o),null!==s&&(c.collapseOnClickOutside="true"===s),null!==d&&(c.detailHeight="auto"===d?"auto":parseInt(d,10));const u=t.innerHTML.trim();u&&!this.config.detailRenderer&&(c.detailRenderer=(e,t)=>{const i=a(u,{value:e,row:e});return l(i)}),Object.keys(c).length>0&&(this.config={...this.config,...c})}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}animateExpand(e,t,i){if(!this.isAnimationEnabled||!1===this.animationStyle)return!1;e.classList.add("tbw-expanding");let n=!1;const r=()=>{n||(n=!0,e.classList.remove("tbw-expanding"),void 0!==t&&void 0!==i&&this.#O(e,t,i))};return e.addEventListener("animationend",r,{once:!0}),setTimeout(r,this.animationDuration+50),!0}animateCollapse(e,t){if(!this.isAnimationEnabled||!1===this.animationStyle)return void t();e.classList.add("tbw-collapsing");const i=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",i,{once:!0}),setTimeout(i,this.animationDuration+50)}#O(e,t,i){if(!e.isConnected)return;const n=e.offsetHeight;if(n>0){const e=this.measuredDetailHeights.get(t);this.measuredDetailHeights.set(t,n),e!==n&&this.grid.invalidateRowHeight(i)}}expandedRows=/* @__PURE__ */new Set;detailElements=/* @__PURE__ */new Map;measuredDetailHeights=/* @__PURE__ */new Map;rowsToAnimate=/* @__PURE__ */new Set;static DEFAULT_DETAIL_HEIGHT=150;getDetailHeight(e){const t=this.detailElements.get(e);if(t){if(!(t.classList.contains("tbw-expanding")||t.classList.contains("tbw-collapsing"))){const i=t.offsetHeight;if(i>0)return this.measuredDetailHeights.set(e,i),i}}const i=this.measuredDetailHeights.get(e);return i&&i>0?i:"number"==typeof this.config?.detailHeight?this.config.detailHeight:Ae.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){this.expandedRows=Se(this.expandedRows,e);const i=this.expandedRows.has(e);i&&this.rowsToAnimate.add(e),this.emit("detail-expand",{rowIndex:t,row:e,expanded:i}),this.requestRender()}detach(){this.expandedRows.clear(),this.detailElements.clear(),this.measuredDetailHeights.clear(),this.rowsToAnimate.clear()}processColumns(e){if(!(!0===this.config.showExpandColumn||!1!==this.config.showExpandColumn&&!!this.config.detailRenderer))return[...e];const t=[...e],i=function(e){return e.find(be)}(t);if(i)return t;const n=(r=this.name,{field:we,header:"",width:32,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,expanderColumn:!0,expanderPlugin:r,utility:!0}});var r;return n.viewRenderer=e=>{const{row:t}=e,i=this.expandedRows.has(t),n=document.createElement("span");n.className="master-detail-expander expander-cell";const r=document.createElement("span");return r.className="master-detail-toggle"+(i?" expanded":""),this.setIcon(r,this.resolveIcon(i?"collapse":"expand")),r.setAttribute("role","button"),r.setAttribute("tabindex","0"),r.setAttribute("aria-expanded",String(i)),r.setAttribute("aria-label",i?"Collapse details":"Expand details"),n.appendChild(r),n},[n,...t]}onRowClick(e){if(this.config.expandOnRowClick&&this.config.detailRenderer)return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){const t=e.originalEvent?.target;if(t?.classList.contains("master-detail-toggle"))return this.toggleAndEmit(e.row,e.rowIndex),!0;this.expandedRows.size>0&&queueMicrotask(()=>this.#B())}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusCol,i=this.grid._focusRow,n=this.visibleColumns[t];if(!n||!be(n))return;const r=this.rows[i];return r?(e.preventDefault(),this.toggleAndEmit(r,i),this.requestRenderWithFocus(),!0):void 0}afterRender(){this.#B()}onScrollRender(){this.config.detailRenderer&&0!==this.expandedRows.size&&this.#B()}#B(){if(!this.config.detailRenderer)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.grid,i=t._rowPool,n=t._virtualization?.start??0,r=t._virtualization?.end??0,o=this.columns.length,s=n,a=r,l=/* @__PURE__ */new Map;if(i){const t=Math.min(i.length,a-s);for(let n=0;n<t;n++){const t=i[n];t.parentNode===e&&l.set(s+n,t)}}else{const t=e.querySelectorAll(".data-grid-row");for(const e of t){const t=e.querySelector(".cell[data-row]"),i=t?parseInt(t.getAttribute("data-row")??"-1",10):-1;i>=0&&l.set(i,e)}}for(const[d,c]of this.detailElements){const e=this.rows.indexOf(d),t=this.expandedRows.has(d),i=e>=0&&l.has(e);if(!t||!i){const e=this.grid.__frameworkAdapter;if(e?.unmount){const t=c.querySelector(".master-detail-cell"),i=t?.firstElementChild;i&&e.unmount(i)}c.parentNode&&c.remove(),this.detailElements.delete(d)}}for(const[d,c]of l){const e=this.rows[d];if(!e||!this.expandedRows.has(e))continue;const t=this.detailElements.get(e);if(t){t.previousElementSibling!==c&&c.after(t);continue}const i=ke(e,d,this.config.detailRenderer,o);"number"==typeof this.config.detailHeight&&(i.style.height=`${this.config.detailHeight}px`),c.after(i),this.detailElements.set(e,i);const n=this.rowsToAnimate.has(e);n&&this.rowsToAnimate.delete(e);n&&this.animateExpand(i,e,d)||requestAnimationFrame(()=>{this.#O(i,e,d)})}}getExtraHeight(){let e=0;for(const t of this.expandedRows)e+=this.getDetailHeight(t);return e}getExtraHeightBefore(e){let t=0;for(const i of this.expandedRows){const n=this.rows.indexOf(i);n>=0&&n<e&&(t+=this.getDetailHeight(i))}return t}getRowHeight(e,t){if(!this.expandedRows.has(e))return;return(this.grid.defaultRowHeight??28)+this.getDetailHeight(e)}adjustVirtualStart(e,t,i){if(0===this.expandedRows.size)return e;const n=this.grid?._virtualization?.positionCache;let r=e;if(n&&n.length>0)for(const o of this.expandedRows){const i=this.rows.indexOf(o);if(i<0||i>=e)continue;n[i].offset+n[i].height>t&&i<r&&(r=i)}else{const n=[];for(const e of this.expandedRows){const t=this.rows.indexOf(e);t>=0&&n.push({index:t,row:e})}n.sort((e,t)=>e.index-t.index);let o=0;for(const{index:s,row:a}of n){const n=s*i+o,l=this.getDetailHeight(a);o+=l,s>=e||n+i+l>t&&s<r&&(r=s)}}return r}expand(e){const t=this.rows[e];t&&(this.rowsToAnimate.add(t),this.expandedRows=function(e,t){const i=new Set(e);return i.add(t),i}(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=function(e,t){const i=new Set(e);return i.delete(t),i}(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&(this.expandedRows=Se(this.expandedRows,t),this.expandedRows.has(t)&&this.rowsToAnimate.add(t),this.requestRender())}isExpanded(e){const t=this.rows[e];return!!t&&function(e,t){return e.has(t)}(this.expandedRows,t)}expandAll(){for(const e of this.rows)this.rowsToAnimate.add(e),this.expandedRows.add(e);this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const i=this.rows.indexOf(t);i>=0&&e.push(i)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}refreshDetailRenderer(){const e=this.config.detailRenderer;if(this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e}),this.config.detailRenderer){const e=this.grid;"function"==typeof e.refreshColumns?e.refreshColumns():this.requestRender()}}}function _e(e,t){return null==e&&null==t?0:null==e?1:null==t?-1:"number"==typeof e&&"number"==typeof t?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():"boolean"==typeof e&&"boolean"==typeof t?e===t?0:e?-1:1:String(e).localeCompare(String(t))}function Le(e,t){const i=e.findIndex(e=>e.field===t);return i>=0?i+1:void 0}function Ie(e,t){return e.find(e=>e.field===t)?.direction}class Te extends e{name="multiSort";styles='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs, .7em);background:var(--tbw-multi-sort-badge-bg, var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color, var(--tbw-color-fg));border-radius:50%;width:var(--tbw-multi-sort-badge-size, 1em);height:var(--tbw-multi-sort-badge-size, 1em);display:inline-flex;align-items:center;justify-content:center;margin-left:var(--tbw-spacing-xs, .125em);font-weight:600}}';get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];cachedSortResult=null;clearCoreSortState(){const e=this.gridElement;e&&(e._sortState=null)}detach(){this.sortModel=[],this.cachedSortResult=null}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.gridElement;if(t&&!t._isGridEditMode&&"number"==typeof t._activeEditRows&&-1!==t._activeEditRows&&this.cachedSortResult&&this.cachedSortResult.length===e.length)return[...this.cachedSortResult];const i=function(e,t,i){return t.length?[...e].sort((e,n)=>{for(const r of t){const t=i.find(e=>e.field===r.field),o=(t?.sortComparator??_e)(e[r.field],n[r.field],e,n);if(0!==o)return"asc"===r.direction?o:-o}return 0}):[...e]}([...e],this.sortModel,[...this.columns]);return this.cachedSortResult=i,i}onHeaderClick(e){const t=this.columns.find(t=>t.field===e.field);if(!t?.sortable)return!1;const i=e.originalEvent.shiftKey,n=this.config.maxSortColumns??3;return this.sortModel=function(e,t,i,n){const r=e.find(e=>e.field===t);return i?r?"asc"===r.direction?e.map(e=>e.field===t?{...e,direction:"desc"}:e):e.filter(e=>e.field!==t):e.length<n?[...e,{field:t,direction:"asc"}]:e:"asc"===r?.direction?[{field:t,direction:"desc"}]:"desc"===r?.direction?[]:[{field:t,direction:"asc"}]}(this.sortModel,e.field,i,n),this.clearCoreSortState(),this.emit("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),this.grid?.requestStateChange?.(),!0}afterRender(){const e=this.gridElement;if(!e)return;const t=!1!==this.config.showSortIndex;e.querySelectorAll(".header-row .cell[data-field]").forEach(e=>{const i=e.getAttribute("data-field");if(!i)return;const n=Le(this.sortModel,i),r=Ie(this.sortModel,i),o=e.querySelector(".sort-index");if(o?.remove(),r){const i=e.querySelector('[part~="sort-indicator"], .sort-indicator');i?.remove(),e.setAttribute("data-sort",r);const o=document.createElement("span");o.className="sort-indicator",this.setIcon(o,this.resolveIcon("asc"===r?"sortAsc":"sortDesc"));const s=e.querySelector(".tbw-filter-btn"),a=e.querySelector(".resize-handle"),l=s??a;if(l?e.insertBefore(o,l):e.appendChild(o),t&&this.sortModel.length>1&&void 0!==n){const t=document.createElement("span");t.className="sort-index",t.textContent=String(n),o.nextSibling?e.insertBefore(t,o.nextSibling):e.appendChild(t)}}else{e.removeAttribute("data-sort");const t=e.querySelector('[part~="sort-indicator"], .sort-indicator');t?.remove()}})}getSortModel(){return[...this.sortModel]}setSortModel(e){this.sortModel=[...e],this.clearCoreSortState(),this.emit("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.()}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.emit("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.()}getSortIndex(e){return Le(this.sortModel,e)}getSortDirection(e){return Ie(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(t=>t.field===e);if(-1===t)return;return{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(!t.sort)return void(this.sortModel=this.sortModel.filter(t=>t.field!==e));const i=this.sortModel.findIndex(t=>t.field===e),n={field:e,direction:t.sort.direction};-1!==i?this.sortModel[i]=n:this.sortModel.splice(t.sort.priority,0,n),this.clearCoreSortState()}}function Fe(e){return e.pinned??e.sticky??e.meta?.pinned??e.meta?.sticky}function Me(e,t){return c(e,t)}function De(e,t){const i=Fe(e);return!!i&&"left"===Me(i,t)}function Pe(e,t){const i=Fe(e);return!!i&&"right"===Me(i,t)}function qe(e){return e.some(e=>null!=Fe(e))}function He(e,t){const i=Array.from(e.querySelectorAll(".header-row .cell"));if(!i.length)return;const n=d(e);let r=0;for(const s of t)if(De(s,n)){const t=i.find(e=>e.getAttribute("data-field")===s.field);t&&(t.classList.add("sticky-left"),t.style.position="sticky",t.style.left=r+"px",e.querySelectorAll(`.data-grid-row .cell[data-field="${s.field}"]`).forEach(e=>{e.classList.add("sticky-left"),e.style.position="sticky",e.style.left=r+"px"}),r+=t.offsetWidth)}let o=0;for(const s of[...t].reverse())if(Pe(s,n)){const t=i.find(e=>e.getAttribute("data-field")===s.field);t&&(t.classList.add("sticky-right"),t.style.position="sticky",t.style.right=o+"px",e.querySelectorAll(`.data-grid-row .cell[data-field="${s.field}"]`).forEach(e=>{e.classList.add("sticky-right"),e.style.position="sticky",e.style.right=o+"px"}),o+=t.offsetWidth)}}function Ne(e){e.querySelectorAll(".sticky-left, .sticky-right").forEach(e=>{e.classList.remove("sticky-left","sticky-right"),e.style.position="",e.style.left="",e.style.right=""})}const ze="canMoveColumn";class Ge extends e{static manifest={ownedProperties:[{property:"pinned",level:"column",description:'the "pinned" column property',isUsed:e=>"left"===e||"right"===e||"start"===e||"end"===e},{property:"sticky",level:"column",description:'the "sticky" column property (deprecated, use "pinned")',isUsed:e=>"left"===e||"right"===e||"start"===e||"end"===e}],incompatibleWith:[{name:"groupingColumns",reason:"Pinning reorders columns to the grid edges, but moving a column out of its column group is not supported. The group header layout cannot accommodate members at different positions."}],queries:[{type:ze,description:"Prevents pinned (sticky) columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the sticky offsets for left/right pinned columns"},{type:"getContextMenuItems",description:"Contributes pin/unpin items to the header context menu"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=/* @__PURE__ */new Map;rightOffsets=/* @__PURE__ */new Map;#V=[];detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1,this.#V=[]}static detect(e,t){const i=t?.columns;return!!Array.isArray(i)&&qe(i)}processColumns(e){const t=[...e];if(this.isApplied=qe(t),!this.isApplied)return t;const i=this.gridElement;return function(e,t="ltr"){const i=[],n=[],r=[];for(const o of e){const e=Fe(o);e?"left"===Me(e,t)?i.push(o):r.push(o):n.push(o)}return[...i,...n,...r]}(t,i?d(i):"ltr")}afterRender(){if(!this.isApplied)return;const e=this.grid,t=[...this.columns];if(!qe(t))return Ne(e),void(this.isApplied=!1);queueMicrotask(()=>{He(e,t)})}handleQuery(e){switch(e.type){case ze:return null==Fe(e.context)&&void 0;case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};case"getContextMenuItems":{const t=e.context;if(!t.isHeader)return;const i=t.column;if(!i?.field)return;if(i.meta?.lockPinning)return;const n=this.grid?.getPluginByName("groupingColumns");if(n?.isGroupingActive())return;const r=[];return null!=Fe(i)?r.push({id:"pinned/unpin",label:"Unpin Column",icon:"📌",order:40,action:()=>this.setPinPosition(i.field,void 0)}):(r.push({id:"pinned/pin-left",label:"Pin Left",icon:"⬅",order:40,action:()=>this.setPinPosition(i.field,"left")}),r.push({id:"pinned/pin-right",label:"Pin Right",icon:"➡",order:41,action:()=>this.setPinPosition(i.field,"right")})),r}default:return}}setPinPosition(e,t){const i=this.columns;if(!i?.length)return;const n=i.findIndex(t=>t.field===e);if(-1===n)return;const r=this.grid;if(t){0===this.#V.length&&(this.#V=i.map(e=>e.field));const n=i.map(i=>{if(i.field!==e)return i;const n={...i};return n.pinned=t,delete n.sticky,n});r.columns=n}else{const t={...i[n]};delete t.pinned,delete t.sticky;const o=[...i];o.splice(n,1);const s=this.#V.indexOf(e);if(s>=0){let e=o.length;for(let t=0;t<o.length;t++){if(Fe(o[t]))continue;if(this.#V.indexOf(o[t].field)>s){e=t;break}}o.splice(e,0,t)}else o.splice(Math.min(n,o.length),0,t);o.some(e=>null!=Fe(e))||(this.#V=[]),r.columns=o}}refreshStickyOffsets(){const e=[...this.columns];He(this.grid,e)}getLeftPinnedColumns(){return function(e,t="ltr"){return e.filter(e=>De(e,t))}([...this.columns],d(this.grid))}getRightPinnedColumns(){return function(e,t="ltr"){return e.filter(e=>Pe(e,t))}([...this.columns],d(this.grid))}clearStickyPositions(){Ne(this.grid)}getHorizontalScrollOffsets(e,t){if(!this.isApplied)return;let i=0,n=0;if(e){const t=e.querySelectorAll(".sticky-left"),r=e.querySelectorAll(".sticky-right");t.forEach(e=>{i+=e.offsetWidth}),r.forEach(e=>{n+=e.offsetWidth})}else{this.grid.querySelectorAll(".header-row .cell").forEach(e=>{e.classList.contains("sticky-left")?i+=e.offsetWidth:e.classList.contains("sticky-right")&&(n+=e.offsetWidth)})}const r=t?.classList.contains("sticky-left")||t?.classList.contains("sticky-right");return{left:i,right:n,skipScroll:r}}}function Ke(e,t){const i=document.createElement("div");i.className="tbw-pinned-rows",i.setAttribute("role","presentation"),i.setAttribute("aria-live","polite");const n=document.createElement("div");n.className="tbw-pinned-rows-left";const r=document.createElement("div");r.className="tbw-pinned-rows-center";const o=document.createElement("div");if(o.className="tbw-pinned-rows-right",!1!==e.showRowCount){const e=document.createElement("span");e.className="tbw-status-panel tbw-status-panel-row-count",e.textContent=`Total: ${t.totalRows} rows`,n.appendChild(e)}if(e.showFilteredCount&&t.filteredRows!==t.totalRows){const e=document.createElement("span");e.className="tbw-status-panel tbw-status-panel-filtered-count",e.textContent=`Filtered: ${t.filteredRows}`,n.appendChild(e)}if(e.showSelectedCount&&t.selectedRows>0){const e=document.createElement("span");e.className="tbw-status-panel tbw-status-panel-selected-count",e.textContent=`Selected: ${t.selectedRows}`,o.appendChild(e)}if(e.customPanels)for(const s of e.customPanels){const e=je(s,t);switch(s.position){case"left":n.appendChild(e);break;case"center":r.appendChild(e);break;case"right":o.appendChild(e)}}return i.appendChild(n),i.appendChild(r),i.appendChild(o),i}function Oe(e){const t=document.createElement("div");return t.className=`tbw-aggregation-rows tbw-aggregation-rows-${e}`,t.setAttribute("role","presentation"),t}function Be(e,t,i,n,r=!1){e.innerHTML="";for(const o of t){const t=document.createElement("div");t.className="tbw-aggregation-row",t.setAttribute("role","presentation"),o.id&&t.setAttribute("data-aggregation-id",o.id);o.fullWidth??r?Ve(t,o,i,n):We(t,o,i,n),e.appendChild(t)}}function Ve(e,t,i,n){const r=document.createElement("div");r.className="tbw-aggregation-cell tbw-aggregation-cell-full",r.style.gridColumn="1 / -1";const o="function"==typeof t.label?t.label(n,i):t.label;if(o){const e=document.createElement("span");e.className="tbw-aggregation-label",e.textContent=o,r.appendChild(e)}const s=function(e,t,i){const n=e.aggregators&&Object.keys(e.aggregators).length>0,r=e.cells&&Object.keys(e.cells).length>0;if(!n&&!r)return null;const o=document.createElement("span");o.className="tbw-aggregation-aggregates";for(const s of t){const{value:t,formatter:n}=$e(e,s,i);if(null!=t){const e=document.createElement("span");e.className="tbw-aggregation-aggregate",e.setAttribute("data-field",s.field);const i=s.header??s.field,r=n?n(t,s.field,s):String(t);e.textContent=`${i}: ${r}`,o.appendChild(e)}}return o.children.length>0?o:null}(t,i,n);s&&r.appendChild(s),e.appendChild(r)}function We(e,t,i,n){for(const r of i){const i=document.createElement("div");i.className="tbw-aggregation-cell",i.setAttribute("data-field",r.field);const{value:o,formatter:s}=$e(t,r,n);i.textContent=null!=o?s?s(o,r.field,r):String(o):"",e.appendChild(i)}}function $e(e,t,i){let n,r;const o=e.aggregators?.[t.field];if(o)if("object"==typeof(s=o)&&null!==s&&"aggFunc"in s){const e=u(o.aggFunc);e&&(n=e(i,t.field,t)),r=o.formatter}else{const e=u(o);e&&(n=e(i,t.field,t))}else if(e.cells&&Object.prototype.hasOwnProperty.call(e.cells,t.field)){const r=e.cells[t.field];n="function"==typeof r?r(i,t.field,t):r}var s;return{value:n,formatter:r}}function je(e,t){const i=document.createElement("div");i.className="tbw-status-panel tbw-status-panel-custom",i.id=`status-panel-${e.id}`;const n=e.render(t);return"string"==typeof n?i.innerHTML=n:i.appendChild(n),i}function Ue(e,t,i,n,r){return{totalRows:e.length,filteredRows:r?.cachedResult?.length??e.length,selectedRows:n?.selected?.size??0,columns:t,rows:e,grid:i}}class Ye extends e{name="pinnedRows";styles="@layer tbw-plugins{.tbw-footer{flex-shrink:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-color-panel-bg)}.tbw-pinned-rows{display:flex;align-items:center;justify-content:space-between;padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));background:var(--tbw-pinned-rows-bg, var(--tbw-color-panel-bg));border-top:1px solid var(--tbw-pinned-rows-border, var(--tbw-color-border));font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-pinned-rows-color, var(--tbw-color-fg-muted));min-height:32px;box-sizing:border-box;min-width:fit-content}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{display:flex;align-items:center;gap:var(--tbw-spacing-xl, 1rem)}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{justify-content:center;flex:1}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{min-width:fit-content;background:var(--tbw-aggregation-bg, var(--tbw-color-header-bg))}.tbw-aggregation-rows-top{border-bottom:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-rows-bottom{border-top:1px solid var(--tbw-aggregation-border, var(--tbw-color-border))}.tbw-aggregation-row{display:grid;grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size, .8em);font-weight:var(--tbw-aggregation-font-weight, 600)}.tbw-aggregation-cell{padding:var(--tbw-cell-padding, .125rem .5rem);min-height:var(--tbw-row-height, 1.75rem);display:block;align-items:center;align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;text-overflow:ellipsis;white-space:var(--tbw-cell-white-space, nowrap)}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{grid-column:1 / -1;border-right:0;display:flex;align-items:center;gap:var(--tbw-spacing-lg, .75rem)}.tbw-aggregation-label{white-space:nowrap}.tbw-aggregation-aggregates{display:flex;align-items:center;gap:var(--tbw-spacing-lg, .75rem);font-weight:400;opacity:.85}.tbw-aggregation-aggregate{white-space:nowrap}}";get defaultConfig(){return{position:"bottom",showRowCount:!0,showSelectedCount:!0,showFilteredCount:!0}}infoBarElement=null;topAggregationContainer=null;bottomAggregationContainer=null;footerWrapper=null;detach(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.footerWrapper&&!t.contains(this.footerWrapper)&&(this.footerWrapper=null,this.bottomAggregationContainer=null,this.infoBarElement=null),this.topAggregationContainer&&!t.contains(this.topAggregationContainer)&&(this.topAggregationContainer=null),this.infoBarElement&&!t.contains(this.infoBarElement)&&(this.infoBarElement=null);const i=this.getSelectionState(),n=this.getFilterState(),r=Ue(this.sourceRows,this.columns,this.grid,i,n),o=this.config.aggregationRows||[],s=o.filter(e=>"top"===e.position),a=o.filter(e=>"top"!==e.position);if(s.length>0){if(!this.topAggregationContainer){this.topAggregationContainer=Oe("top");const i=e.querySelector(".header");i&&i.nextSibling?t.insertBefore(this.topAggregationContainer,i.nextSibling):t.appendChild(this.topAggregationContainer)}Be(this.topAggregationContainer,s,this.visibleColumns,this.sourceRows,this.config.fullWidth)}else this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const l=!1!==this.config.showRowCount||this.config.showSelectedCount&&r.selectedRows>0||this.config.showFilteredCount&&r.filteredRows!==r.totalRows||this.config.customPanels&&this.config.customPanels.length>0,d=l&&"top"!==this.config.position,c=a.length>0||d;if(l&&"top"===this.config.position)if(this.infoBarElement){const e=Ke(this.config,r);this.infoBarElement.replaceWith(e),this.infoBarElement=e}else this.infoBarElement=Ke(this.config,r),t.insertBefore(this.infoBarElement,t.firstChild);else"top"===this.config.position&&this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null);c?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",t.appendChild(this.footerWrapper)),this.footerWrapper.innerHTML="",a.length>0&&(this.bottomAggregationContainer||(this.bottomAggregationContainer=Oe("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),Be(this.bottomAggregationContainer,a,this.visibleColumns,this.sourceRows,this.config.fullWidth)),d&&(this.infoBarElement=Ke(this.config,r),this.footerWrapper.appendChild(this.infoBarElement))):this.cleanupFooter()}cleanup(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}cleanupFooter(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.infoBarElement&&"top"!==this.config.position&&(this.infoBarElement.remove(),this.infoBarElement=null)}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}getFilterState(){try{return this.grid?.getPluginState?.("filtering")??null}catch{return null}}refresh(){this.requestRender()}getContext(){const e=this.getSelectionState(),t=this.getFilterState();return Ue(this.rows,this.columns,this.grid,e,t)}addPanel(e){this.config.customPanels||(this.config.customPanels=[]),this.config.customPanels.push(e),this.requestRender()}removePanel(e){this.config.customPanels&&(this.config.customPanels=this.config.customPanels.filter(t=>t.id!==e),this.requestRender())}addAggregationRow(e){this.config.aggregationRows||(this.config.aggregationRows=[]),this.config.aggregationRows.push(e),this.requestRender()}removeAggregationRow(e){this.config.aggregationRows&&(this.config.aggregationRows=this.config.aggregationRows.filter(t=>t.id!==e),this.requestRender())}}const Ze=h;function Qe(e,t){return[...e,t].join("|")}function Xe(e,t){const i=t.rowGroupFields??[],n=t.columnGroupFields??[],r=t.valueFields??[],o=function(e,t){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const n of e){const e=t.map(e=>String(n[e]??"")).join("|");i.add(e)}return[...i].sort()}(e,n),s=Je(e,i,n,o,r,0,""),a=function(e,t,i){const n={};function r(e){for(const o of e)if(o.isGroup&&o.children?.length)o.children&&r(o.children);else for(const e of t)for(const t of i){const i=Qe([e],t.field);n[i]=(n[i]??0)+(o.values[i]??0)}}return r(e),n}(s,o,r);return{rows:s,columnKeys:o,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function Je(e,t,i,n,r,o,s){const a=[];if(0===t.length){const t=et(e,i,n,r),l=tt(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:o,values:t,total:l,isGroup:!1,rowCount:e.length}),a}const l=t[0],d=t.slice(1),c=d.length>0,u=function(e,t){const i=/* @__PURE__ */new Map;for(const n of e){const e=String(n[t]??""),r=i.get(e);r?r.push(n):i.set(e,[n])}return i}(e,l);for(const[h,g]of u){const e=s?`${s}|${h}`:h,t=et(g,i,n,r),l=tt(t);let u;c&&(u=Je(g,d,i,n,r,o+1,e)),a.push({rowKey:e,rowLabel:h||"(blank)",depth:o,values:t,total:l,isGroup:c,children:u,rowCount:g.length})}return a}function et(e,t,i,n){const r={};for(const o of i)for(const i of n){const n=(t.length>0?e.filter(e=>t.map(t=>String(e[t]??"")).join("|")===o):e).map(e=>Number(e[i.field])||0),s=Ze(i.aggFunc),a=n.length>0?s(n):null;r[Qe([o],i.field)]=a}return r}function tt(e){let t=0;for(const i of Object.values(e))t+=i??0;return t}const it=["sum","avg","count","min","max","first","last"];function nt(e,t,i,n){const r=new AbortController,o={config:t,callbacks:n,signal:r.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(rt("Options",()=>function(e,t){const{config:i,callbacks:n,signal:r}=t,o=document.createElement("div");return o.className="tbw-pivot-options",o.appendChild(lt("Enable Pivot View",e,e=>{n.onTogglePivot(e)},r)),o.appendChild(lt("Show Row Totals",i.showTotals??!0,e=>{n.onOptionChange("showTotals",e)},r)),o.appendChild(lt("Show Grand Total",i.showGrandTotal??!0,e=>{n.onOptionChange("showGrandTotal",e)},r)),o}(i,o))),s.appendChild(rt("Row Groups",()=>ot("rowGroups",o))),s.appendChild(rt("Column Groups",()=>ot("columnGroups",o))),s.appendChild(rt("Values",()=>function(e){const{config:t,callbacks:i,signal:n}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone tbw-pivot-values-zone",r.setAttribute("data-zone","values");const o=t.valueFields??[];if(0===o.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag numeric fields here for aggregation",r.appendChild(e)}else for(const s of o)r.appendChild(at(s,e));return r.addEventListener("dragover",e=>{e.preventDefault(),r.classList.add("drag-over")},{signal:n}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:n}),r.addEventListener("drop",e=>{e.preventDefault(),r.classList.remove("drag-over");const t=e.dataTransfer?.getData("text/plain");t&&i.onAddValueField(t,"sum")},{signal:n}),r}(o))),s.appendChild(rt("Available Fields",()=>function(e){const{config:t,callbacks:i,signal:n}=e,r=document.createElement("div");r.className="tbw-pivot-available-fields";const o=i.getAvailableFields(),s=/* @__PURE__ */new Set([...t.rowGroupFields??[],...t.columnGroupFields??[],...t.valueFields?.map(e=>e.field)??[]]),a=o.filter(e=>!s.has(e.field));if(0===a.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="All fields are in use",r.appendChild(e)}else for(const l of a){const e=document.createElement("div");e.className="tbw-pivot-field-chip available",e.textContent=l.header,e.draggable=!0,e.title=`Drag to add "${l.field}" to a zone`,e.addEventListener("dragstart",t=>{t.dataTransfer?.setData("text/plain",l.field),e.classList.add("dragging")},{signal:n}),e.addEventListener("dragend",()=>{e.classList.remove("dragging")},{signal:n}),r.appendChild(e)}return r}(o))),e.appendChild(s),()=>{r.abort(),s.remove()}}function rt(e,t){const i=document.createElement("div");i.className="tbw-pivot-section";const n=document.createElement("div");n.className="tbw-pivot-section-header",n.textContent=e;const r=document.createElement("div");return r.className="tbw-pivot-section-content",r.appendChild(t()),i.appendChild(n),i.appendChild(r),i}function ot(e,t){const{config:i,callbacks:n,signal:r}=t,o=document.createElement("div");o.className="tbw-pivot-drop-zone",o.setAttribute("data-zone",e);const s="rowGroups"===e?i.rowGroupFields??[]:i.columnGroupFields??[];if(0===s.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag fields here or click to add",o.appendChild(e)}else for(const a of s)o.appendChild(st(a,e,t));return o.addEventListener("dragover",e=>{e.preventDefault(),o.classList.add("drag-over")},{signal:r}),o.addEventListener("dragleave",()=>{o.classList.remove("drag-over")},{signal:r}),o.addEventListener("drop",t=>{t.preventDefault(),o.classList.remove("drag-over");const i=t.dataTransfer?.getData("text/plain");i&&n.onAddFieldToZone(i,e)},{signal:r}),o}function st(e,t,i){const{callbacks:n,signal:r}=i,o=document.createElement("div");o.className="tbw-pivot-field-chip",o.draggable=!0;const s=n.getAvailableFields().find(t=>t.field===e),a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=s?.header??e;const l=document.createElement("button");return l.className="tbw-pivot-chip-remove",l.innerHTML="×",l.title="Remove field",l.addEventListener("click",i=>{i.stopPropagation(),n.onRemoveFieldFromZone(e,t)},{signal:r}),o.appendChild(a),o.appendChild(l),o.addEventListener("dragstart",i=>{i.dataTransfer?.setData("text/plain",e),i.dataTransfer?.setData("source-zone",t),o.classList.add("dragging")},{signal:r}),o.addEventListener("dragend",()=>{o.classList.remove("dragging")},{signal:r}),o}function at(e,t){const{callbacks:i,signal:n}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip tbw-pivot-value-chip";const o=i.getAvailableFields().find(t=>t.field===e.field),s=document.createElement("div");s.className="tbw-pivot-value-label-wrapper";const a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=o?.header??e.field;const l=document.createElement("select");l.className="tbw-pivot-agg-select",l.title="Aggregation function";for(const c of it){const t=document.createElement("option");t.value=c,t.textContent=c.toUpperCase(),t.selected=c===e.aggFunc,l.appendChild(t)}l.addEventListener("change",()=>{i.onUpdateValueAggFunc(e.field,l.value)},{signal:n});const d=document.createElement("button");return d.className="tbw-pivot-chip-remove",d.innerHTML="×",d.title="Remove value field",d.addEventListener("click",t=>{t.stopPropagation(),i.onRemoveValueField(e.field)},{signal:n}),s.appendChild(a),s.appendChild(l),r.appendChild(s),r.appendChild(d),r}function lt(e,t,i,n){const r=document.createElement("label");r.className="tbw-pivot-checkbox";const o=document.createElement("input");o.type="checkbox",o.checked=t,o.addEventListener("change",()=>i(o.checked),{signal:n});const s=document.createElement("span");return s.textContent=e,r.appendChild(o),r.appendChild(s),r}class dt extends e{name="pivot";styles='@layer tbw-plugins{.pivot-group-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:600;background:var(--tbw-pivot-group-bg, var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-group-row:hover{background:var(--tbw-pivot-group-hover, var(--tbw-color-row-hover))}.pivot-leaf-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg, var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-grand-total-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:700;background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong)}.pivot-grand-total-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{position:sticky;bottom:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-width:fit-content}.pivot-group-row>.cell,.pivot-leaf-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));height:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));margin-right:var(--tbw-spacing-sm, .375em);border:none;background:transparent;cursor:pointer;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease),color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease)}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg, var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color, var(--tbw-color-fg))}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color, var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{font-weight:700;border-top:2px solid var(--tbw-pivot-border, var(--tbw-color-border-strong))}[data-pivot-depth="1"]{--tbw-pivot-depth: 1}[data-pivot-depth="2"]{--tbw-pivot-depth: 2}[data-pivot-depth="3"]{--tbw-pivot-depth: 3}[data-pivot-depth="4"]{--tbw-pivot-depth: 4}.tbw-pivot-panel{display:flex;flex-direction:column;gap:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));height:100%;overflow-y:auto;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg, var(--tbw-color-bg))}.tbw-pivot-section-header{padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));font-weight:600;background:var(--tbw-pivot-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0}.tbw-pivot-section-content{padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border:2px dashed var(--tbw-pivot-drop-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg, var(--tbw-color-row-alt));display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);align-content:flex-start;transition:all .15s ease}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active, var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);font-style:italic;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-pivot-chip-bg, var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:var(--tbw-font-size-xs, .75rem);transition:all .15s ease}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover, var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}.tbw-pivot-chip-remove{display:flex;align-items:center;justify-content:center;width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm, .875rem);font-weight:700;cursor:pointer;border-radius:50%;transition:all .15s ease}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg, var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg, var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem))}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;min-width:0}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs, .125rem) var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-xs, .6875rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-checkbox{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm, .875rem);height:var(--tbw-icon-size-sm, .875rem);cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}}';static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=/* @__PURE__ */new Map;expandedKeys=/* @__PURE__ */new Set;defaultExpanded=!0;userHasToggledExpand=!1;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.userHasToggledExpand=!1}getToolPanel(){if(!1!==(this.config?.showToolPanel??this.userConfig?.showToolPanel??!0))return{id:dt.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&!1!==this.config.active&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=function(e){const t=[];return e.rowGroupFields?.length||e.columnGroupFields?.length||t.push("At least one row or column group field is required"),e.valueFields?.length||t.push("At least one value field is required"),t}(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=Xe(e,this.config),0===this.expandedKeys.size&&this.defaultExpanded&&!this.userHasToggledExpand&&this.expandAllKeys();const i=this.config.indentWidth??20,n=function(e,t,i=!0){const n=[];function r(e){n.push(e);const o=t?t.has(e.rowKey):i;if(e.children&&o)for(const t of e.children)r(t)}for(const o of e)r(o);return n}(this.pivotResult.rows,this.expandedKeys,this.defaultExpanded).map(e=>({__pivotRowKey:e.rowKey,__pivotLabel:e.rowLabel,__pivotDepth:e.depth,__pivotIsGroup:e.isGroup,__pivotHasChildren:Boolean(e.children?.length),__pivotExpanded:this.expandedKeys.has(e.rowKey),__pivotRowCount:e.rowCount??0,__pivotIndent:e.depth*i,__pivotTotal:e.total,...e.values}));this.keysToAnimate.clear();const r=/* @__PURE__ */new Set;for(const o of n){const e=o.__pivotRowKey;r.add(e),!this.previousVisibleKeys.has(e)&&o.__pivotDepth>0&&this.keysToAnimate.add(e)}return this.previousVisibleKeys=r,n}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],i=(this.config.rowGroupFields??[]).map(e=>this.fieldHeaderMap.get(e)??e).join(" / ");t.push({field:"__pivotLabel",header:i||"Group",width:200});for(const n of this.pivotResult.columnKeys)for(const e of this.config.valueFields??[]){const i=Qe([n],e.field),r=e.header||this.fieldHeaderMap.get(e.field)||e.field;t.push({field:i,header:`${n} - ${r} (${e.aggFunc})`,width:120,type:"number"})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number"}),t}renderRow(e,t,i){const n=e;return n.__pivotRowKey&&n.__pivotHasChildren?function(e,t,i){return t.className="data-grid-row pivot-group-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.setAttribute("role","row"),t.innerHTML="",i.columns.forEach((n,r)=>{const o=document.createElement("div");if(o.className="cell",o.setAttribute("data-col",String(r)),o.setAttribute("data-row",String(i.rowIndex)),o.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;o.style.paddingLeft=`${t}px`;const n=String(e.__pivotRowKey),r=document.createElement("button");r.type="button",r.className="pivot-toggle",r.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),i.setIcon(r,i.resolveIcon(e.__pivotExpanded?"collapse":"expand")),r.addEventListener("click",e=>{e.stopPropagation(),i.onToggle(n)}),o.appendChild(r);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),o.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,o.appendChild(a)}else{const t=e[n.field];o.textContent=null!=t?String(t):""}t.appendChild(o)}),!0}(n,t,{columns:this.gridColumns,rowIndex:i,onToggle:e=>this.toggle(e),resolveIcon:e=>this.resolveIcon(e),setIcon:(e,t)=>this.setIcon(e,t)}):void 0!==n.__pivotRowKey&&this.isActive?function(e,t,i,n){return t.className="data-grid-row pivot-leaf-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.innerHTML="",i.forEach((i,r)=>{const o=document.createElement("div");if(o.className="cell",o.setAttribute("data-col",String(r)),o.setAttribute("data-row",String(n)),o.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;o.style.paddingLeft=`${t+20}px`;const i=document.createElement("span");i.className="pivot-label",i.textContent=String(e.__pivotLabel??""),o.appendChild(i)}else{const t=e[i.field];o.textContent=null!=t?String(t):""}t.appendChild(o)}),!0}(n,t,this.gridColumns,i):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(" "!==e.key)return;if(!this.isActive)return;const t=this.grid._focusRow,i=this.rows[t];return i?.__pivotIsGroup&&i.__pivotHasChildren?(e.preventDefault(),this.toggle(i.__pivotRowKey),this.requestRenderWithFocus(),!0):void 0}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter();const e=this.animationStyle;if(!1===e||0===this.keysToAnimate.size)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i="fade"===e?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const n of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const e=n.dataset.pivotKey;e&&this.keysToAnimate.has(e)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.children[0];if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));const i={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};var n,r,o;n=i,r=this.grandTotalFooter,o=this.gridColumns,r.className="pivot-grand-total-row",r.setAttribute("role","presentation"),r.innerHTML="",o.forEach((e,t)=>{const i=document.createElement("div");if(i.className="cell",i.setAttribute("data-col",String(t)),0===t){const e=document.createElement("span");e.className="pivot-label",e.textContent="Grand Total",i.appendChild(e)}else{const t=n[e.field];i.textContent=null!=t?String(t):""}r.appendChild(i)})}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0,this.expandedKeys.has(e)?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=function(e){const t=[];function i(e){if(e.isGroup&&t.push(e.rowKey),e.children)for(const t of e.children)i(t)}for(const n of e)i(n);return t}(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}enablePivot(){0===this.originalColumns.length&&this.captureOriginalColumns(),this.isActive=!0,this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.requestRender()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.requestRender()}setValueFields(e){this.config.valueFields=e,this.requestRender()}refresh(){this.pivotResult=null,this.requestRender()}showPanel(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(dt.PANEL_ID)||this.grid.toggleToolPanelSection(dt.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(dt.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(dt.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(e=>!e.field.startsWith("__pivot")).map(e=>({field:e.field,header:e.header??e.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,0===this.originalColumns.length&&this.captureOriginalColumns();const t={onTogglePivot:e=>{e?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(e,t)=>this.addFieldToZone(e,t),onRemoveFieldFromZone:(e,t)=>this.removeFieldFromZone(e,t),onAddValueField:(e,t)=>this.addValueField(e,t),onRemoveValueField:e=>this.removeValueField(e),onUpdateValueAggFunc:(e,t)=>this.updateValueAggFunc(e,t),onOptionChange:(e,t)=>{this.config[e]=t,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return nt(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if("rowGroups"===t){const t=this.config.rowGroupFields??[];t.includes(e)||(this.config.rowGroupFields=[...t,e])}else{const t=this.config.columnGroupFields??[];t.includes(e)||(this.config.columnGroupFields=[...t,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),this.refreshIfActive()}removeFromOtherZones(e,t){"rowGroups"!==t&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e)),"columnGroups"!==t&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e)),"values"!==t&&(this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e))}addValueField(e,t){const i=this.config.valueFields??[];i.some(t=>t.field===e)||(this.config.valueFields=[...i,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const i=this.config.valueFields??[],n=i.findIndex(t=>t.field===e);n>=0&&(i[n]={...i[n],aggFunc:t},this.config.valueFields=[...i]),this.isActive&&this.refresh()}}const ct="tbw-print-isolation-style";async function ut(e,t={}){const{orientation:i="landscape"}=t,n=e.id;document.querySelectorAll(`#${CSS.escape(n)}`).length>1&&console.warn(`[tbw-grid:print] Multiple elements found with id="${n}". Print isolation may not work correctly. Ensure each grid has a unique ID.`),document.getElementById(ct)?.remove();const r=function(e,t){const i=document.createElement("style");return i.id=ct,i.textContent=`\n /* Print isolation: hide everything except the target grid */\n @media print {\n /* Hide all body children by default */\n body > *:not(#${e}) {\n display: none !important;\n }\n\n /* But show the grid and ensure it's not hidden by ancestor rules */\n #${e} {\n display: block !important;\n position: static !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n width: 100% !important;\n max-height: none !important;\n margin: 0 !important;\n padding: 0 !important;\n transform: none !important;\n }\n\n /* If grid is nested, we need to show its ancestors too */\n #${e},\n #${e} * {\n visibility: visible !important;\n }\n\n /* Walk up the DOM and show all ancestors of the grid */\n body *:has(> #${e}),\n body *:has(#${e}) {\n display: block !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n position: static !important;\n transform: none !important;\n background: transparent !important;\n border: none !important;\n padding: 0 !important;\n margin: 0 !important;\n }\n\n /* Hide siblings of ancestors (everything that's not in the path to the grid) */\n body *:has(#${e}) > *:not(:has(#${e})):not(#${e}) {\n display: none !important;\n }\n\n /* Page settings */\n @page {\n size: ${t};\n margin: 1cm;\n }\n\n /* Ensure proper print styling */\n body {\n margin: 0 !important;\n padding: 0 !important;\n background: white !important;\n color-scheme: light !important;\n }\n }\n\n /* Screen: also apply isolation for print preview */\n @media screen {\n /* When this stylesheet is active, we're about to print */\n /* No screen-specific rules needed - isolation only applies to print */\n }\n `,i}(n,i);return document.head.appendChild(r),new Promise(e=>{const t=()=>{window.removeEventListener("afterprint",t),document.getElementById(ct)?.remove(),e()};window.addEventListener("afterprint",t),window.print(),setTimeout(()=>{window.removeEventListener("afterprint",t),document.getElementById(ct)?.remove(),e()},5e3)})}const ht={button:!1,orientation:"landscape",warnThreshold:500,maxRows:0,includeTitle:!0,includeTimestamp:!0,title:"",isolate:!1};class gt extends e{name="print";version="1.0.0";styles=".tbw-print-header,.tbw-print-footer{display:none}@media print{tbw-grid{overflow:visible!important;height:auto!important;border:none!important;border-radius:0!important;color-scheme:light only;-webkit-print-color-adjust:exact;print-color-adjust:exact}tbw-grid .tbw-grid-content{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .tbw-scroll-area{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .rows-body{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .rows-container,tbw-grid .rows-viewport,tbw-grid .rows{overflow:visible!important;height:auto!important;max-height:none!important;transform:none!important}tbw-grid .rows-viewport .rows{position:static!important}tbw-grid .resize-handle,tbw-grid [part=sort-indicator],tbw-grid .tbw-filter-btn,tbw-grid .tool-panel,tbw-grid .tool-panel-content,tbw-grid .tbw-shell-header,tbw-grid .shell-toolbar,tbw-grid .tool-panel-toggle,tbw-grid [data-print-hide],tbw-grid .expander-cell,tbw-grid .tree-toggle,tbw-grid .context-menu,tbw-grid .faux-vscroll{display:none!important}tbw-grid .tbw-print-header{display:flex;justify-content:space-between;align-items:baseline;padding:var(--tbw-spacing-md, .5em) 0;margin-bottom:var(--tbw-spacing-md, .5em);border-bottom:2px solid var(--tbw-print-border, var(--tbw-color-border-strong));font-family:inherit}.tbw-print-header-title{font-size:1.25em;font-weight:700}.tbw-print-header-timestamp{font-size:var(--tbw-font-size-sm, .875em);color:var(--tbw-print-muted, var(--tbw-color-fg-muted))}tbw-grid .tbw-print-footer{display:block;margin-top:var(--tbw-spacing-md, .5em);padding-top:var(--tbw-spacing-md, .5em);border-top:1px solid var(--tbw-print-border, var(--tbw-color-border));font-size:var(--tbw-font-size-xs, .75em);color:var(--tbw-print-muted, var(--tbw-color-fg-muted));text-align:end}tbw-grid .data-grid-row{break-inside:avoid;page-break-inside:avoid}tbw-grid .cell{border:1px solid var(--tbw-print-cell-border, var(--tbw-color-border))!important}tbw-grid .header-row,tbw-grid .data-grid-row{padding-inline-end:1px}tbw-grid .data-grid-row:hover,tbw-grid .cell:hover{background:inherit!important}@page{margin:1cm}tbw-grid.print-landscape{@page{size:landscape}}tbw-grid.print-portrait{@page{size:portrait}}}";#W=!1;#$=null;#j=null;#U=null;#Y=null;#Z=null;#Q=null;get#X(){return this.grid}isPrinting(){return this.#W}async print(e){if(this.#W)return void console.warn("[PrintPlugin] Print already in progress");const t=this.gridElement;if(!t)return void console.warn("[PrintPlugin] Grid not available");const i={...ht,...this.config,...e},n=this.rows.length;let r=n,o=!1;if(i.warnThreshold>0&&n>i.warnThreshold){const e=i.maxRows>0?`\n\nNote: Output will be limited to ${i.maxRows.toLocaleString()} rows.`:"";if(!confirm(`This grid has ${n.toLocaleString()} rows. Printing large datasets may cause performance issues or browser slowdowns.${e}\n\nClick OK to continue, or Cancel to abort.`))return}i.maxRows>0&&n>i.maxRows&&(r=i.maxRows,o=!0),this.#W=!0;const s=performance.now();this.emit("print-start",{rowCount:r,limitApplied:o,originalRowCount:n});try{const e=this.#X;this.#j={bypassThreshold:e._virtualization?.bypassThreshold??24},this.#J(),o&&(this.#U=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,r),await new Promise(e=>setTimeout(e,50))),(i.includeTitle||i.includeTimestamp)&&this.#ee(i),await this.#te(),await new Promise(e=>requestAnimationFrame(e)),await new Promise(e=>requestAnimationFrame(e)),t.classList.add(`print-${i.orientation}`),await new Promise(e=>requestAnimationFrame(e)),await new Promise(e=>requestAnimationFrame(e)),i.isolate?await this.#ie(i):await this.#ne(),this.emit("print-complete",{success:!0,rowCount:r,duration:Math.round(performance.now()-s)})}catch(a){console.error("[PrintPlugin] Print failed:",a),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-s)})}finally{this.#re(),this.#W=!1}}#ee(e){const t=this.gridElement;if(t){if(this.#Y=document.createElement("div"),this.#Y.className="tbw-print-header",e.includeTitle){const t=e.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",i=document.createElement("div");i.className="tbw-print-header-title",i.textContent=t,this.#Y.appendChild(i)}if(e.includeTimestamp){const e=document.createElement("div");e.className="tbw-print-header-timestamp",e.textContent=`Printed: ${/* @__PURE__ */(new Date).toLocaleString()}`,this.#Y.appendChild(e)}t.insertBefore(this.#Y,t.firstChild),this.#Z=document.createElement("div"),this.#Z.className="tbw-print-footer",this.#Z.textContent=`Page generated from ${window.location.hostname}`,t.appendChild(this.#Z)}}async#te(){const e=this.#X;if(!e._virtualization)return;const t=this.rows.length;e._virtualization.bypassThreshold=t+100,e.refreshVirtualWindow(!0),await new Promise(e=>setTimeout(e,100))}async#ne(){return new Promise(e=>{const t=()=>{window.removeEventListener("afterprint",t),e()};window.addEventListener("afterprint",t),window.print(),setTimeout(()=>{"undefined"!=typeof window&&window.removeEventListener("afterprint",t),e()},1e3)})}async#ie(e){const t=this.gridElement;t&&await ut(t,{orientation:e.orientation})}#J(){const e=this.columns;if(e){this.#$=/* @__PURE__ */new Map;for(const t of e)t.printHidden&&t.field&&(this.#$.set(t.field,!t.hidden),this.grid.setColumnVisible(t.field,!1))}}#oe(){if(this.#$){for(const[e,t]of this.#$)this.grid.setColumnVisible(e,t);this.#$=null}}#re(){const e=this.gridElement;if(!e)return;this.#oe(),e.classList.remove("print-portrait","print-landscape"),null!==this.#Q&&(e.style.transform="",e.style.transformOrigin="",e.style.width="",this.#Q=null),this.#Y&&(this.#Y.remove(),this.#Y=null),this.#Z&&(this.#Z.remove(),this.#Z=null);const t=this.#X;this.#j&&t._virtualization&&(t._virtualization.bypassThreshold=this.#j.bypassThreshold,t.refreshVirtualWindow(!0),this.#j=null),null!==this.#U&&(this.grid.rows=this.#U,this.#U=null)}afterRender(){this.config?.button&&!this.#se&&(this.#ae(),this.#se=!0)}#se=!1;#ae(){const e=this.#X;e.registerToolbarContent?.({id:"print-button",order:900,render:e=>{const t=document.createElement("button");t.className="tbw-toolbar-btn tbw-print-btn",t.title="Print grid",t.type="button";const i=this.resolveIcon("print")||"🖨️";this.setIcon(t,i),t.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),e.appendChild(t)}})}}function pt(e,t,i){if(t===i)return e;if(t<0||t>=e.length)return e;if(i<0||i>e.length)return e;const n=[...e],[r]=n.splice(t,1);return n.splice(i,0,r),n}class ft extends e{name="reorder";styles='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.cell.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration, .2s) ease-out backwards}}';get defaultConfig(){return{animation:"flip"}}get animationType(){return!!this.isAnimationEnabled&&(void 0!==this.config.animation?this.config.animation:"flip")}get animationDuration(){return void 0!==this.config.animationDuration?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;canMoveColumnWithPlugins(e){if(!e||!function(e){const t=e.meta??{};return!0!==t.lockPosition&&!0!==t.suppressMovable}(e))return!1;return!this.grid.query("canMoveColumn",e).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-reorder-request",e=>{const t=e.detail;t?.field&&"number"==typeof t.toIndex&&this.moveColumn(t.field,t.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll(".header-row > .cell").forEach(e=>{const t=e,i=t.getAttribute("data-field");if(!i)return;const n=this.columns.find(e=>e.field===i);this.canMoveColumnWithPlugins(n)?(t.draggable=!0,t.getAttribute("data-dragstart-bound")||(t.setAttribute("data-dragstart-bound","true"),t.addEventListener("dragstart",e=>{const n=this.getColumnOrder().indexOf(i);this.isDragging=!0,this.draggedField=i,this.draggedIndex=n,e.dataTransfer&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",i)),t.classList.add("dragging")}),t.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses()}),t.addEventListener("dragover",e=>{if(e.preventDefault(),!this.isDragging||this.draggedField===i)return;const n=t.getBoundingClientRect(),r=n.left+n.width/2,o=this.getColumnOrder().indexOf(i);this.dropIndex=e.clientX<r?o:o+1,t.classList.add("drop-target"),t.classList.toggle("drop-before",e.clientX<r),t.classList.toggle("drop-after",e.clientX>=r)}),t.addEventListener("dragleave",()=>{t.classList.remove("drop-target","drop-before","drop-after")}),t.addEventListener("drop",e=>{e.preventDefault();const t=this.draggedField,i=this.draggedIndex,n=this.dropIndex;if(!this.isDragging||null===t||null===i||null===n)return;const r=n>i?n-1:n,o=pt(this.getColumnOrder(),i,r),s={field:t,fromIndex:i,toIndex:r,columnOrder:o};this.emitCancelable("column-move",s)||this.updateColumnOrder(o)}))):t.draggable=!1})}onKeyDown(e){if(!e.altKey||"ArrowLeft"!==e.key&&"ArrowRight"!==e.key)return;const t=this.grid,i=t._focusCol,r=t._visibleColumns;if(i<0||i>=r.length)return;const o=r[i];if(!this.canMoveColumnWithPlugins(o))return;const s=this.getColumnOrder(),a=s.indexOf(o.field);if(-1===a)return;const l="ArrowLeft"===e.key?a-1:a+1;if(l<0||l>=s.length)return;const d=r.find(e=>e.field===s[l]);return this.canMoveColumnWithPlugins(d)?(this.moveColumn(o.field,l),t._focusCol=l,n(this.grid),e.preventDefault(),e.stopPropagation(),!0):void 0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const i=this.getColumnOrder(),n=i.indexOf(e);if(-1===n)return;const r=pt(i,n,t);this.emitCancelable("column-move",{field:e,fromIndex:n,toIndex:t,columnOrder:r})||this.updateColumnOrder(r)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.columns.map(e=>e.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=/* @__PURE__ */new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");i&&e.set(i,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||0===e.size)return;const i=/* @__PURE__ */new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const n=t.getAttribute("data-field");if(!n)return;const r=e.get(n);if(void 0===r)return;const o=r-t.getBoundingClientRect().left;Math.abs(o)>1&&i.set(n,o)}),0===i.size)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=i.get(e.getAttribute("data-field")??"");if(void 0!==t){const i=e;i.style.transform=`translateX(${t}px)`,n.push(i)}}),0===n.length)return;this.gridElement.offsetHeight;const r=this.animationDuration;requestAnimationFrame(()=>{n.forEach(e=>{e.classList.add("flip-animating"),e.style.transform=""}),setTimeout(()=>{n.forEach(e=>{e.style.transform="",e.classList.remove("flip-animating")})},r+50)})}animateFade(e){const t=this.gridElement;if(!t)return void e();const i=this.captureHeaderPositions();e();const n=/* @__PURE__ */new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(!t)return;const r=i.get(t);if(void 0===r)return;const o=e.getBoundingClientRect().left;Math.abs(r-o)>1&&n.add(t)}),0===n.size)return;const r=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(t&&n.has(t)){const t=e;t.classList.add("fade-animating"),r.push(t)}}),0===r.length)return;const o=this.animationDuration;setTimeout(()=>{r.forEach(e=>e.classList.remove("fade-animating"))},o+50)}updateColumnOrder(e){const t=this.animationType;if("flip"===t&&this.gridElement){const t=this.captureHeaderPositions();this.grid.setColumnOrder(e),requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(t)})}else"fade"===t?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}}class mt extends e{name="responsive";version="1.0.0";styles='tbw-grid[data-responsive-animate]{.data-grid-row,.data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration, .2s) ease-out,transform var(--tbw-responsive-duration, .2s) ease-out}}tbw-grid[data-responsive][data-responsive-animate]{.data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration, .2s) ease-out}}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive]{.header{display:none!important}.footer-row{display:none}.tbw-scroll-area{overflow-x:hidden;min-width:0!important}.rows-body-wrapper{min-width:0!important}.data-grid-row:not(.group-row){display:block!important;grid-template-columns:none!important;padding:var(--tbw-cell-padding);padding-inline-start:var(--tbw-spacing-xl);border-bottom:1px solid var(--tbw-color-border);min-height:auto!important;height:auto!important;contain:none!important;content-visibility:visible!important;background:var(--tbw-color-bg);position:relative;&:nth-child(2n){background:var(--tbw-color-row-alt)}&:hover{background:var(--tbw-color-row-hover)}&[aria-selected=true]{background:var(--tbw-color-selection);&:before{content:"";position:absolute;inset-inline-start:0;top:0;bottom:0;width:4px;background:var(--tbw-color-accent)}}}.data-grid-row:not(.group-row)>.cell{display:flex!important;justify-content:space-between;align-items:center;padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);width:100%!important;min-width:0!important;min-height:auto!important;height:auto!important;line-height:1.5!important;position:static!important;left:auto!important;right:auto!important;border:none!important;border-bottom:none!important;border-inline-end:none!important;background:transparent!important;white-space:normal!important;overflow:visible!important;&:before{content:attr(data-header) ": ";font-weight:600;color:var(--tbw-color-header-fg);flex-shrink:0;margin-inline-end:var(--tbw-spacing-md);min-width:100px}&:after{content:none}}.cell[data-utility]{display:none!important}}tbw-grid[data-responsive] .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .cell[data-responsive-value-only]{&:before{display:none!important}justify-content:flex-start!important;font-weight:500}tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive]{.tbw-footer,.tbw-pinned-rows,.tbw-aggregation-rows{display:none!important}.tbw-pinned-rows,.tbw-aggregation-rows,.tbw-aggregation-row{min-width:0!important}}tbw-grid[data-responsive] .data-grid-row.responsive-card{display:block!important;padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border);>*{width:100%}.cell:before{display:none}}';static manifest={incompatibleWith:[{name:"groupingRows",reason:"Responsive card layout does not yet support row grouping. The variable row heights (cards vs group headers) cause scroll calculation issues."}],queries:[{type:"isCardMode",description:"Returns whether the grid is currently in responsive card mode"}]};#le;#de=!1;#ce;#ue=!1;#he=0;#ge=/* @__PURE__ */new Set;#pe=/* @__PURE__ */new Set;#fe=null;#me=[];isResponsive(){return this.#de}setResponsive(e){e!==this.#de&&(this.#de=e,this.#we(),this.emit("responsive-change",{isResponsive:e,width:this.#he,breakpoint:this.config.breakpoint??0}))}setBreakpoint(e){this.config.breakpoint=e,this.#be(this.#he)}setCardRenderer(e){this.config.cardRenderer=e,this.#de&&this.requestRender()}getWidth(){return this.#he}getActiveBreakpoint(){return this.#fe}attach(e){super.attach(e),this.#ve(),this.#ye(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#me=[...this.config.breakpoints].sort((e,t)=>t.maxWidth-e.maxWidth)),this.#le=new ResizeObserver(e=>{const t=e[0]?.contentRect.width??0;this.#he=t,clearTimeout(this.#ce),this.#ce=setTimeout(()=>{this.#be(t)},this.config.debounceMs??100)}),this.#le.observe(this.gridElement)}#ve(){const e=this.grid;if(!e||"function"!=typeof e.querySelector)return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=e;if(i.__frameworkAdapter?.parseResponsiveCardElement){const e=i.__frameworkAdapter.parseResponsiveCardElement(t);e&&(this.config={...this.config,cardRenderer:e})}const n=t.getAttribute("breakpoint"),r=t.getAttribute("card-row-height"),o=t.getAttribute("hidden-columns"),s=t.getAttribute("hide-header"),d=t.getAttribute("debounce-ms"),c={};if(null!==n){const e=parseInt(n,10);isNaN(e)||(c.breakpoint=e)}if(null!==r&&(c.cardRowHeight="auto"===r?"auto":parseInt(r,10)),null!==o&&(c.hiddenColumns=o.split(",").map(e=>e.trim()).filter(e=>e.length>0)),null!==s&&(c.hideHeader="false"!==s),null!==d){const e=parseInt(d,10);isNaN(e)||(c.debounceMs=e)}const u=t.innerHTML.trim();!u||this.config.cardRenderer||i.__frameworkAdapter?.parseResponsiveCardElement||(c.cardRenderer=e=>{const t=a(u,{value:e,row:e}),i=l(t),n=document.createElement("div");return n.className="tbw-responsive-card-content",n.innerHTML=i,n}),Object.keys(c).length>0&&(this.config={...this.config,...c})}#ye(e){if(this.#ge.clear(),this.#pe.clear(),e)for(const t of e)"string"==typeof t?this.#ge.add(t):t.showValue?this.#pe.add(t.field):this.#ge.add(t.field)}detach(){this.#le?.disconnect(),this.#le=void 0,clearTimeout(this.#ce),this.#ce=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if("isCardMode"===e.type)return this.#de}afterRender(){this.#xe();if(!(this.#me.length>0?null!==this.#fe:this.#de))return;const e=this.#ge.size>0,t=this.#pe.size>0;if(!e&&!t)return;const i=this.gridElement.querySelectorAll(".cell[data-field]");for(const n of i){const e=n.getAttribute("data-field");e&&(this.#ge.has(e)?(n.setAttribute("data-responsive-hidden",""),n.removeAttribute("data-responsive-value-only")):this.#pe.has(e)?(n.setAttribute("data-responsive-value-only",""),n.removeAttribute("data-responsive-hidden")):(n.removeAttribute("data-responsive-hidden"),n.removeAttribute("data-responsive-value-only")))}}#be(e){if(this.#me.length>0)return void this.#Ce(e);const t=this.config.breakpoint??0;0!==t||this.#ue||(this.#ue=!0,console.warn("[tbw-grid:ResponsivePlugin] No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=t>0&&e<t;i!==this.#de&&(this.#de=i,this.#we(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#Ce(e){let t=null;for(const i of this.#me)e<=i.maxWidth&&(t=i);if(t!==this.#fe){this.#fe=t,t?.hiddenColumns?this.#ye(t.hiddenColumns):this.#ye(this.config.hiddenColumns);const i=!0===t?.cardLayout;i!==this.#de&&(this.#de=i,this.#we()),this.emit("responsive-change",{isResponsive:this.#de,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#Ee;#we(){this.gridElement.toggleAttribute("data-responsive",this.#de);const e=!1!==this.config.animate;this.gridElement.toggleAttribute("data-responsive-animate",e),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.grid;if(this.#de){t._virtualization&&(this.#Ee=t._virtualization.rowHeight);const e=this.gridElement.querySelector(".tbw-scroll-area");e&&(e.scrollLeft=0)}else{const e=this.gridElement.querySelectorAll(".data-grid-row");for(const t of e)t.style.height="",t.classList.remove("responsive-card");this.#Ee&&this.#Ee>0&&t._virtualization&&(t._virtualization.rowHeight=this.#Ee,this.#Ee=void 0),this.#Re=void 0,this.#Se=void 0,this.#ke=void 0}}renderRow(e,t,i){if(!this.#de||!this.config.cardRenderer)return;if(e.__isGroupRow)return;t.replaceChildren();const n=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const r=this.config.cardRowHeight??"auto";return t.style.height="auto"!==r?`${r}px`:"auto",t.appendChild(n),!0}onKeyDown(e){if(!this.#de)return!1;if(this.config.cardRenderer){if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1}const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),n(this.grid),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),n(this.grid),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),n(this.grid),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),n(this.grid),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),n(this.grid),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),n(this.grid),!0}return!1}#Re;#Se;#ke;#Ae(){if(this.#Re&&this.#Re>0)return this.#Re;const e=this.config.cardRowHeight;return"number"==typeof e&&e>0?e:80}#_e(){return this.#Se&&this.#Se>0?this.#Se:this.#Ee??28}#Le(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}#Ie(){let e=0,t=0;for(const i of this.rows)i.__isGroupRow?e++:t++;return{groupCount:e,cardCount:t}}getExtraHeight(){if(!this.#de||!this.config.cardRenderer)return 0;if(!this.#Le())return 0;const e=this.#Ee??28,t=this.#_e(),i=this.#Ae(),{groupCount:n,cardCount:r}=this.#Ie();return n*Math.max(0,t-e)+r*Math.max(0,i-e)}getExtraHeightBefore(e){if(!this.#de||!this.config.cardRenderer)return 0;if(!this.#Le())return 0;const t=this.#Ee??28,i=this.#_e(),n=this.#Ae(),r=Math.max(0,i-t),o=Math.max(0,n-t);let s=0,a=0;const l=this.rows,d=Math.min(e,l.length);for(let c=0;c<d;c++)l[c].__isGroupRow?s++:a++;return s*r+a*o}getRowHeight(e,t){if(this.#de&&this.config.cardRenderer)return e.__isGroupRow?this.#_e():this.#Ae()}#Te(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#Fe=!1;#xe(){if(!this.#de||!this.config.cardRenderer)return;let e=!1;const t=this.grid,i=this.#Le(),n=this.#Te();if(n!==this.#ke&&(this.#ke=n,e=!0),i){const t=this.gridElement.querySelector(".data-grid-row.group-row");if(t){const i=t.getBoundingClientRect().height;i>0&&i!==this.#Se&&(this.#Se=i,e=!0)}}const r=this.gridElement.querySelector(".data-grid-row.responsive-card");if(r){const n=r.getBoundingClientRect().height;n>0&&n!==this.#Re&&(this.#Re=n,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=n))}e&&!this.#Fe&&(this.#Fe=!0,queueMicrotask(()=>{this.#Fe=!1,this.grid&&this.#de&&this.grid.refreshVirtualWindow?.(!0,!0)}))}}const wt="__tbw_row_drag";class bt extends e{name="rowReorder";styles='@layer tbw-plugins{[data-field=__tbw_row_drag]{display:flex;align-items:center;justify-content:center}.dg-row-drag-handle{display:flex;align-items:center;justify-content:center;min-width:1em;min-height:1em;cursor:grab;user-select:none;color:var(--tbw-row-reorder-handle-color, var(--tbw-color-fg-muted));transition:color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease);font-size:var(--tbw-font-size, 1em);letter-spacing:-2px;&:hover{color:var(--tbw-row-reorder-handle-hover, var(--tbw-color-fg))}&:active{cursor:grabbing}}.data-grid-row.dragging{opacity:.6}.data-grid-row.drop-target{position:relative;&.drop-before:before{content:"";position:absolute;top:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}&.drop-after:after{content:"";position:absolute;bottom:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}}.data-grid-row.keyboard-moving{background-color:var(--tbw-row-reorder-moving-bg, var(--tbw-focus-background));box-shadow:0 0 0 1px var(--tbw-row-reorder-moving-border, var(--tbw-color-accent)) inset}.data-grid-row.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}}';get defaultConfig(){return{enableKeyboard:!0,showDragHandle:!0,dragHandlePosition:"left",dragHandleWidth:40,debounceMs:150,animation:"flip"}}get animationType(){return!!this.isAnimationEnabled&&(void 0!==this.config.animation?this.config.animation:"flip")}isDragging=!1;draggedRowIndex=null;dropRowIndex=null;pendingMove=null;debounceTimer=null;lastFocusCol=0;detach(){this.clearDebounceTimer(),this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.pendingMove=null}processColumns(e){if(!this.config.showDragHandle)return[...e];const t={field:wt,header:"",width:this.config.dragHandleWidth??40,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0},viewRenderer:()=>{const e=document.createElement("div");return e.className="dg-row-drag-handle",e.setAttribute("aria-label","Drag to reorder"),e.setAttribute("role","button"),e.setAttribute("tabindex","-1"),e.draggable=!0,this.setIcon(e,this.resolveIcon("dragHandle")),e}};return"right"===this.config.dragHandlePosition?[...e,t]:[t,...e]}afterRender(){if(!this.config.showDragHandle)return;const e=this.gridElement;if(!e)return;e.querySelectorAll(".dg-row-drag-handle").forEach(e=>{const t=e;if(t.getAttribute("data-drag-bound"))return;t.setAttribute("data-drag-bound","true");const i=t.closest(".data-grid-row");i&&this.setupHandleDragListeners(t,i)});e.querySelectorAll(".data-grid-row").forEach(e=>{const t=e;t.getAttribute("data-drop-bound")||(t.setAttribute("data-drop-bound","true"),this.setupRowDropListeners(t))})}onKeyDown(e){if(!this.config.enableKeyboard)return;if(!e.ctrlKey||"ArrowUp"!==e.key&&"ArrowDown"!==e.key)return;const t=this.grid,i=t._focusRow,n=t._rows??this.sourceRows;if(i<0||i>=n.length)return;const r="ArrowUp"===e.key?"up":"down",o="up"===r?i-1:i+1;if(o<0||o>=n.length)return;const s=n[i];return!this.config.canMove||this.config.canMove(s,i,o,r)?(this.handleKeyboardMove(s,i,o,r,t._focusCol),e.preventDefault(),e.stopPropagation(),!0):void 0}onCellClick(){this.flushPendingMove()}moveRow(e,t){const i=[...this.sourceRows];if(e<0||e>=i.length)return;if(t<0||t>=i.length)return;if(e===t)return;const n=t<e?"up":"down",r=i[e];this.config.canMove&&!this.config.canMove(r,e,t,n)||this.executeMove(r,e,t,"keyboard")}canMoveRow(e,t){const i=this.sourceRows;if(e<0||e>=i.length)return!1;if(t<0||t>=i.length)return!1;if(e===t)return!1;if(!this.config.canMove)return!0;const n=t<e?"up":"down";return this.config.canMove(i[e],e,t,n)}setupHandleDragListeners(e,t){e.addEventListener("dragstart",e=>{const i=this.getRowIndex(t);i<0||(this.isDragging=!0,this.draggedRowIndex=i,e.dataTransfer&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",String(i))),t.classList.add("dragging"))}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.clearDragClasses()})}setupRowDropListeners(e){e.addEventListener("dragover",t=>{if(t.preventDefault(),!this.isDragging||null===this.draggedRowIndex)return;const i=this.getRowIndex(e);if(i<0||i===this.draggedRowIndex)return;const n=e.getBoundingClientRect(),r=n.top+n.height/2,o=t.clientY<r;this.dropRowIndex=o?i:i+1,e.classList.add("drop-target"),e.classList.toggle("drop-before",o),e.classList.toggle("drop-after",!o)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",e=>{e.preventDefault();const t=this.draggedRowIndex;let i=this.dropRowIndex;if(this.isDragging&&null!==t&&null!==i&&(i>t&&i--,t!==i)){const e=this.sourceRows[t],n=i<t?"up":"down";this.config.canMove&&!this.config.canMove(e,t,i,n)||this.executeMove(e,t,i,"drag")}})}handleKeyboardMove(e,t,i,r,o){this.pendingMove?this.pendingMove.currentIndex=i:this.pendingMove={originalIndex:t,currentIndex:i,row:e},this.lastFocusCol=o;const s=this.grid,a=[...s._rows??this.sourceRows],[l]=a.splice(t,1);a.splice(i,0,l),s._rows=a,s._focusRow=i,s._focusCol=o,s.refreshVirtualWindow(!0),n(s),this.clearDebounceTimer(),this.debounceTimer=setTimeout(()=>{this.flushPendingMove()},this.config.debounceMs??300)}flushPendingMove(){if(this.clearDebounceTimer(),!this.pendingMove)return;const{originalIndex:e,currentIndex:t,row:i}=this.pendingMove;if(this.pendingMove=null,e===t)return;const r={row:i,fromIndex:e,toIndex:t,rows:[...this.sourceRows],source:"keyboard"};if(this.emitCancelable("row-move",r)){const i=[...this.sourceRows],[r]=i.splice(t,1);i.splice(e,0,r);const o=this.grid;o._rows=i,o._focusRow=e,o._focusCol=this.lastFocusCol,o.refreshVirtualWindow(!0),n(o)}}executeMove(e,t,i,n){const r=[...this.sourceRows],[o]=r.splice(t,1);r.splice(i,0,o);const s={row:e,fromIndex:t,toIndex:i,rows:r,source:n};if(!this.emitCancelable("row-move",s))if("flip"===this.animationType&&this.gridElement){const e=this.captureRowPositions();this.grid.rows=r,requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(e,t,i)})}else this.grid.rows=r}captureRowPositions(){const e=/* @__PURE__ */new Map;return this.gridElement?.querySelectorAll(".data-grid-row").forEach(t=>{const i=this.getRowIndex(t);i>=0&&e.set(i,t.getBoundingClientRect().top)}),e}animateFLIP(e,t,i){const n=this.gridElement;if(!n||0===e.size)return;const r=Math.min(t,i),o=Math.max(t,i),s=[];if(n.querySelectorAll(".data-grid-row").forEach(n=>{const a=n,l=this.getRowIndex(a);if(l<0||l<r||l>o)return;let d;d=l===i?t:t<i?l+1:l-1;const c=e.get(d);if(void 0===c)return;const u=c-a.getBoundingClientRect().top;Math.abs(u)>1&&s.push({el:a,deltaY:u})}),0===s.length)return;s.forEach(({el:e,deltaY:t})=>{e.style.transform=`translateY(${t}px)`}),n.offsetHeight;const a=this.animationDuration;requestAnimationFrame(()=>{s.forEach(({el:e})=>{e.classList.add("flip-animating"),e.style.transform=""}),setTimeout(()=>{s.forEach(({el:e})=>{e.style.transform="",e.classList.remove("flip-animating")})},a+50)})}getRowIndex(e){const t=e.querySelector(".cell[data-row]");return t?parseInt(t.getAttribute("data-row")??"-1",10):-1}clearDragClasses(){this.gridElement?.querySelectorAll(".data-grid-row").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}}function vt(e){return{startRow:Math.min(e.startRow,e.endRow),startCol:Math.min(e.startCol,e.endCol),endRow:Math.max(e.startRow,e.endRow),endCol:Math.max(e.startCol,e.endCol)}}function yt(e){const t=vt(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function xt(e){return e.map(yt)}function Ct(e,t,i){return i.some(i=>function(e,t,i){const n=vt(i);return e>=n.startRow&&e<=n.endRow&&t>=n.startCol&&t<=n.endCol}(e,t,i))}function Et(e){const t=[],i=vt(e);for(let n=i.startRow;n<=i.endRow;n++)for(let e=i.startCol;e<=i.endCol;e++)t.push({row:n,col:e});return t}function Rt(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function St(e,t){const i=vt(e),n=vt(t);return i.startRow===n.startRow&&i.startCol===n.startCol&&i.endRow===n.endRow&&i.endCol===n.endCol}const kt="__tbw_checkbox";class At extends e{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"},{type:"getSelectedRows",description:"Get actual row objects for the current selection (works in all modes)"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:'"triggerOn: \'dblclick\'" has no effect when mode is "range".\n → Range selection uses drag interaction (mousedown → mousemove), not click events.\n → The "triggerOn" option only affects "cell" and "row" selection modes.',check:e=>"range"===e.mode&&"dblclick"===e.triggerOn}]};name="selection";styles='@layer tbw-plugins{tbw-grid{&.selecting .data-grid-row>.cell{user-select:none}&:has(.selection){user-select:none}.data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%));outline:none;position:relative;&:after{content:"";position:absolute;inset:0;pointer-events:none;border-width:0;border-style:var(--tbw-selection-border-style, var(--tbw-border-style));border-color:var(--tbw-range-border-color, var(--tbw-color-accent));border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width));border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width));z-index:1}+.data-grid-row.row-focus:after{border-top-width:0}&:has(+.data-grid-row.row-focus):after{border-bottom-width:0}}&[data-selection-mode=row] .cell-focus,&[data-selection-mode=row] .row-focus,&[data-selection-mode=range] .cell-focus{outline:none}.data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg);position:relative;&:after{content:"";position:absolute;inset:0;pointer-events:none;border:0 var(--tbw-selection-border-style, var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1}&.top:after{border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width))}&.bottom:after{border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width))}&.first:after{border-left-width:var(--tbw-selection-border-width, var(--tbw-border-width))}&.last:after{border-right-width:var(--tbw-selection-border-width, var(--tbw-border-width))}}.data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:.6;&.row-focus{background-color:var(--tbw-color-row-alt)}}.data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:.6;&.selected{background-color:var(--tbw-selection-warning-bg, rgba(from var(--tbw-color-error) r g b / 50%))}}.tbw-selection-summary{font-size:var(--tbw-font-size-sm, .8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}.data-grid-row>.cell[data-field=__tbw_checkbox],.header-row>.cell[data-field=__tbw_checkbox]{text-align:center;cursor:pointer;padding:0;display:flex;align-items:center;justify-content:center}.tbw-select-row-checkbox{pointer-events:none;margin:0;cursor:pointer}.tbw-checkbox-header{display:flex;justify-content:center;align-items:center;height:100%}.tbw-select-all-checkbox{margin:0;cursor:pointer}}}';get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0,multiSelect:!0}}selected=/* @__PURE__ */new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;selectedCell=null;lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;explicitSelection=!1;isSelectionEnabled(){return!1!==this.config.enabled&&!1!==this.grid.effectiveConfig?.selectable}checkSelectable(e,t){const{isSelectable:i}=this.config;if(!i)return!0;const n=this.rows[e];if(!n)return!1;return i(n,e,void 0!==t?this.visibleColumns[t]:void 0,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}attach(e){super.attach(e),this.on("filter-applied",()=>this.clearSelectionSilent()),this.on("grouping-state-change",()=>this.clearSelectionSilent()),this.on("tree-state-change",()=>this.clearSelectionSilent())}handleQuery(e){return"getSelection"===e.type?this.getSelection():"getSelectedRowIndices"===e.type?this.getSelectedRowIndices():"getSelectedRows"===e.type?this.getSelectedRows():"selectRows"===e.type?(this.selectRows(e.context),!0):void 0}detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.pendingKeyboardUpdate=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1}clearSelectionSilent(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedCell=null,this.lastSelected=null,this.anchor=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,this.requestAfterRender()}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{rowIndex:t,colIndex:i,originalEvent:n}=e,{mode:r,triggerOn:o="click"}=this.config;if(n.type!==o)return!1;const s=e.column,a=s&&ve(s);if("cell"===r){if(a)return!1;if(!this.isCellSelectable(t,i))return!1;const e=this.selectedCell;return e&&e.row===t&&e.col===i||(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#Me()),this.requestAfterRender()),!1}if("row"===r){if(!this.isRowSelectable(t))return!1;const e=!1!==this.config.multiSelect,i=n.shiftKey&&e,r=(n.ctrlKey||n.metaKey)&&e,o=!0===s?.meta?.checkboxColumn;if(i&&null!==this.anchor){const e=Math.min(this.anchor,t),i=Math.max(this.anchor,t);r||this.selected.clear();for(let t=e;t<=i;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(r||o&&e)this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.anchor=t;else{if(1===this.selected.size&&this.selected.has(t))return!1;this.selected.clear(),this.selected.add(t),this.anchor=t}return this.lastSelected=t,this.explicitSelection=!0,this.emit("selection-change",this.#Me()),this.requestAfterRender(),!1}if("range"===r){if(a)return!1;if(!this.isCellSelectable(t,i))return!1;const e=n.shiftKey,r=(n.ctrlKey||n.metaKey)&&!1!==this.config.multiSelect;if(e&&this.cellAnchor){const e=Rt(this.cellAnchor,{row:t,col:i}),n=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(n&&St(n,e))return!1;r?this.ranges.length>0?this.ranges[this.ranges.length-1]=e:this.ranges.push(e):this.ranges=[e],this.activeRange=e}else if(r){const e={startRow:t,startCol:i,endRow:t,endCol:i};this.ranges.push(e),this.activeRange=e,this.cellAnchor={row:t,col:i}}else{const e={startRow:t,startCol:i,endRow:t,endCol:i};if(1===this.ranges.length&&St(this.ranges[0],e))return!1;this.ranges=[e],this.activeRange=e,this.cellAnchor={row:t,col:i}}return this.emit("selection-change",this.#Me()),this.requestAfterRender(),!1}return!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;const{mode:t}=this.config,i=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if("Escape"===e.key){return!this.grid.query("isEditing").some(Boolean)&&("cell"===t?this.selectedCell=null:"row"===t?(this.selected.clear(),this.anchor=null):"range"===t&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#Me()),this.requestAfterRender(),!0)}if("cell"===t&&i)return queueMicrotask(()=>{const e=this.grid._focusRow,t=this.grid._focusCol;this.isCellSelectable(e,t)?this.selectedCell={row:e,col:t}:this.selectedCell=null,this.emit("selection-change",this.#Me()),this.requestAfterRender()}),!1;if("row"===t){const t=!1!==this.config.multiSelect;if("ArrowUp"===e.key||"ArrowDown"===e.key){const i=e.shiftKey&&t;return i&&null===this.anchor&&(this.anchor=this.grid._focusRow),queueMicrotask(()=>{const e=this.grid._focusRow;if(i&&null!==this.anchor){this.selected.clear();const t=Math.min(this.anchor,e),i=Math.max(this.anchor,e);for(let e=t;e<=i;e++)this.isRowSelectable(e)&&this.selected.add(e)}else this.isRowSelectable(e)?(this.selected.clear(),this.selected.add(e),this.anchor=e):this.selected.clear();this.lastSelected=e,this.explicitSelection=!0,this.emit("selection-change",this.#Me()),this.requestAfterRender()}),!1}if(t&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}}if("range"===t&&i){const t="Tab"===e.key,i=e.shiftKey&&!t;return i&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:i},queueMicrotask(()=>this.requestAfterRender()),!1}if("range"===t&&!1!==this.config.multiSelect&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}return!1}onCellMouseDown(e){if(!this.isSelectionEnabled())return;if("range"!==this.config.mode)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(e.column&&ve(e.column))return;if(!this.isCellSelectable(e.rowIndex,e.colIndex))return;if(e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,i=e.colIndex,n=(e.originalEvent.ctrlKey||e.originalEvent.metaKey)&&!1!==this.config.multiSelect,r={startRow:t,startCol:i,endRow:t,endCol:i};return!n&&1===this.ranges.length&&St(this.ranges[0],r)?(this.cellAnchor={row:t,col:i},!0):(this.cellAnchor={row:t,col:i},n||(this.ranges=[]),this.ranges.push(r),this.activeRange=r,this.emit("selection-change",this.#Me()),this.requestAfterRender(),!0)}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.config.mode)return;if(!this.isDragging||!this.cellAnchor)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;let t=e.colIndex;const i=this.visibleColumns[t];if(i&&ve(i)){const e=this.visibleColumns.findIndex(e=>!ve(e));e>=0&&(t=e)}const n=Rt(this.cellAnchor,{row:e.rowIndex,col:t}),r=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return r&&St(r,n)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=n:this.ranges.push(n),this.activeRange=n,this.emit("selection-change",this.#Me()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.config.mode)return this.isDragging?(this.isDragging=!1,!0):void 0}processColumns(e){if(this.config.checkbox&&"row"===this.config.mode){if(e.some(e=>e.field===kt))return e;const t=this.#De(),i=e.findIndex(be),n=i>=0?i+1:0;return[...e.slice(0,n),t,...e.slice(n)]}return e}#De(){return{field:kt,header:"",width:32,resizable:!1,sortable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0,checkboxColumn:!0},headerRenderer:()=>{const e=document.createElement("div");if(e.className="tbw-checkbox-header",!1===this.config.multiSelect)return e;const t=document.createElement("input");return t.type="checkbox",t.className="tbw-select-all-checkbox",t.addEventListener("click",e=>{e.stopPropagation(),e.target.checked?this.selectAll():this.clearSelection()}),e.appendChild(t),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const i=e.cellEl;if(i){const e=parseInt(i.getAttribute("data-row")??"-1",10);e>=0&&(t.checked=this.selected.has(e))}return t}}}#Pe(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),i=t?g(t):-1;i>=0&&(e.checked=this.selected.has(i))});const t=e.querySelector(".tbw-select-all-checkbox");if(t){const e=this.rows.length;let i=0;if(this.config.isSelectable)for(let t=0;t<e;t++)this.isRowSelectable(t)&&i++;else i=e;const n=i>0&&this.selected.size>=i,r=this.selected.size>0;t.checked=n,t.indeterminate=r&&!n}}#qe(e){const t=this.grid._focusRow,i=this.grid._focusCol;if("row"===e){if(this.explicitSelection)return this.explicitSelection=!1,void(this.lastSyncedFocusRow=t);t!==this.lastSyncedFocusRow&&(this.lastSyncedFocusRow=t,this.isRowSelectable(t)&&(this.selected.has(t)&&1===this.selected.size||(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.anchor=t,this.emit("selection-change",this.#Me()))))}if("cell"===e){if(this.explicitSelection)return this.explicitSelection=!1,this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=i);if((t!==this.lastSyncedFocusRow||i!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=i,this.isCellSelectable(t,i))){const e=this.selectedCell;e&&e.row===t&&e.col===i||(this.selectedCell={row:t,col:i},this.emit("selection-change",this.#Me()))}}}#He(){const e=this.gridElement;if(!e)return;const{mode:t}=this.config,i=!!this.config.isSelectable;e.querySelectorAll(".cell").forEach(e=>{e.classList.remove("selected","top","bottom","first","last"),i&&e.removeAttribute("data-selectable")});const n=e.querySelectorAll(".data-grid-row");if(n.forEach(e=>{e.classList.remove("selected","row-focus"),i&&e.removeAttribute("data-selectable")}),"row"===t&&(p(e),n.forEach(e=>{const t=e.querySelector(".cell[data-row]"),n=g(t);n>=0&&(i&&!this.isRowSelectable(n)&&e.setAttribute("data-selectable","false"),this.selected.has(n)&&e.classList.add("selected","row-focus"))}),this.config.checkbox&&this.#Pe(e)),("cell"===t||"range"===t)&&i){e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),i=parseInt(e.getAttribute("data-col")??"-1",10);t>=0&&i>=0&&(this.isCellSelectable(t,i)||e.setAttribute("data-selectable","false"))})}if("range"===t&&this.ranges.length>0){p(e);const t=this.ranges.map(vt),i=(e,i)=>{for(const n of t)if(e>=n.startRow&&e<=n.endRow&&i>=n.startCol&&i<=n.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),n=parseInt(e.getAttribute("data-col")??"-1",10);if(t>=0&&n>=0){const r=this.visibleColumns[n];if(r&&ve(r))return;i(t,n)&&(e.classList.add("selected"),i(t-1,n)||e.classList.add("top"),i(t+1,n)||e.classList.add("bottom"),i(t,n-1)||e.classList.add("first"),i(t,n+1)||e.classList.add("last"))}})}}afterRender(){if(!this.isSelectionEnabled())return;const e=this.gridElement;if(!e)return;const t=e.children[0],{mode:i}=this.config;if(this.pendingKeyboardUpdate&&"range"===i){const{shiftKey:e}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const t=this.grid._focusRow,i=this.grid._focusCol;if(e&&this.cellAnchor){const e=Rt(this.cellAnchor,{row:t,col:i});this.ranges=[e],this.activeRange=e}else e||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:t,col:i});this.emit("selection-change",this.#Me())}this.#qe(i),this.grid.setAttribute("data-selection-mode",i),t&&t.classList.toggle("selecting",this.isDragging),this.#He()}onScrollRender(){this.isSelectionEnabled()&&this.#He()}getSelection(){return{mode:this.config.mode,ranges:this.#Me().ranges,anchor:this.cellAnchor}}getSelectedCells(){return function(e){const t=/* @__PURE__ */new Map;for(const i of e)for(const e of Et(i))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return Ct(e,t,this.ranges)}selectAll(){const{mode:e,multiSelect:t}=this.config;if(!1!==t)if("row"===e){this.selected.clear();for(let e=0;e<this.rows.length;e++)this.isRowSelectable(e)&&this.selected.add(e);this.explicitSelection=!0,this.emit("selection-change",this.#Me()),this.requestAfterRender()}else if("range"===e){const e=this.rows.length,t=this.columns.length;if(e>0&&t>0){const i={startRow:0,startCol:0,endRow:e-1,endCol:t-1};this.ranges=[i],this.activeRange=i,this.emit("selection-change",this.#Me()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.config.mode)return;const t=!1===this.config.multiSelect&&e.length>1?[e[e.length-1]]:e;this.selected.clear();for(const i of t)i>=0&&i<this.rows.length&&this.isRowSelectable(i)&&this.selected.add(i);this.anchor=t.length>0?t[t.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#Me()),this.requestAfterRender()}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const{mode:e}=this.config,t=this.rows;if("row"===e)return this.getSelectedRowIndices().filter(e=>e>=0&&e<t.length).map(e=>t[e]);if("cell"===e&&this.selectedCell){const{row:e}=this.selectedCell;return e>=0&&e<t.length?[t[e]]:[]}if("range"===e&&this.ranges.length>0){const e=/* @__PURE__ */new Set;for(const i of this.ranges){const n=Math.max(0,Math.min(i.startRow,i.endRow)),r=Math.min(t.length-1,Math.max(i.startRow,i.endRow));for(let t=n;t<=r;t++)e.add(t)}return[...e].sort((e,t)=>e-t).map(e=>t[e])}return[]}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.emit("selection-change",{mode:this.config.mode,ranges:[]}),this.requestAfterRender()}setRanges(e){this.ranges=e.map(e=>({startRow:e.from.row,startCol:e.from.col,endRow:e.to.row,endCol:e.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",{mode:this.config.mode,ranges:xt(this.ranges)}),this.requestAfterRender()}#Me(){return function(e,t,i){if("cell"===e&&t.selectedCell)return{mode:e,ranges:[{from:{row:t.selectedCell.row,col:t.selectedCell.col},to:{row:t.selectedCell.row,col:t.selectedCell.col}}]};if("row"===e&&t.selected.size>0){const n=[...t.selected].sort((e,t)=>e-t),r=[];let o=n[0],s=o;for(let e=1;e<n.length;e++)n[e]===s+1?s=n[e]:(r.push({from:{row:o,col:0},to:{row:s,col:i-1}}),o=n[e],s=o);return r.push({from:{row:o,col:0},to:{row:s,col:i-1}}),{mode:e,ranges:r}}return"range"===e&&t.ranges.length>0?{mode:e,ranges:xt(t.ranges)}:{mode:e,ranges:[]}}(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}}function _t(e,t){return Math.floor(e/t)}async function Lt(e,t,i,n){const r=function(e,t){return{start:e*t,end:(e+1)*t}}(t,i);return e.getRows({startRow:r.start,endRow:r.end,sortModel:n.sortModel,filterModel:n.filterModel})}function It(e,t,i){const n=_t(e,t),r=i.get(n);if(!r)return;return r[e%t]}class Tt extends e{name="serverSide";get defaultConfig(){return{pageSize:100,cacheBlockSize:100,maxConcurrentRequests:2}}dataSource=null;totalRowCount=0;loadedBlocks=/* @__PURE__ */new Map;loadingBlocks=/* @__PURE__ */new Set;lastRequestId=0;scrollDebounceTimer;detach(){this.dataSource=null,this.totalRowCount=0,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}loadRequiredBlocks(){if(!this.dataSource)return;const e=this.grid,t=this.config.cacheBlockSize??100,i={startRow:e._virtualization.start,endRow:e._virtualization.end},n=function(e,t,i){const n=_t(e,i),r=_t(t-1,i),o=[];for(let s=n;s<=r;s++)o.push(s);return o}(i.startRow,i.endRow,t);for(const r of n)if(!this.loadedBlocks.has(r)&&!this.loadingBlocks.has(r)){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2))break;this.loadingBlocks.add(r),Lt(this.dataSource,r,t,{}).then(e=>{this.loadedBlocks.set(r,e.rows),this.totalRowCount=e.totalRowCount,this.loadingBlocks.delete(r),this.requestRender(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(r)})}}processRows(e){if(!this.dataSource)return[...e];const t=[];for(let i=0;i<this.totalRowCount;i++){const e=It(i,this.config.cacheBlockSize??100,this.loadedBlocks);t.push(e??{__loading:!0,__index:i})}return t}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},100))}setDataSource(e){this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear();Lt(e,0,this.config.cacheBlockSize??100,{}).then(e=>{this.loadedBlocks.set(0,e.rows),this.totalRowCount=e.totalRowCount,this.requestRender()})}refresh(){this.dataSource&&(this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.requestRender())}purgeCache(){this.loadedBlocks.clear()}getTotalRowCount(){return this.totalRowCount}isRowLoaded(e){const t=_t(e,this.config.cacheBlockSize??100);return this.loadedBlocks.has(t)}getLoadedBlockCount(){return this.loadedBlocks.size}}function Ft(e,t,i){return void 0!==e.id?String(e.id):i?`${i}-${t}`:String(t)}function Mt(e,t){const i=new Set(e);return i.has(t)?i.delete(t):i.add(t),i}function Dt(e,t,i=null,n=0){const r=t.childrenField??"children",o=/* @__PURE__ */new Set;for(let s=0;s<e.length;s++){const a=e[s],l=Ft(a,s,i),d=a[r];if(Array.isArray(d)&&d.length>0){o.add(l);const e=Dt(d,t,l,n+1);for(const t of e)o.add(t)}}return o}function Pt(e,t,i,n=null,r=0){const o=i.childrenField??"children";for(let s=0;s<e.length;s++){const a=e[s],l=Ft(a,s,n);if(l===t)return[l];const d=a[o];if(Array.isArray(d)&&d.length>0){const e=Pt(d,t,i,l,r+1);if(e)return[l,...e]}}return null}function qt(e,t,i,n){const r=Pt(e,t,i);if(!r)return n;const o=new Set(n);for(let s=0;s<r.length-1;s++)o.add(r[s]);return o}function Ht(e,t="children"){if(!Array.isArray(e)||0===e.length)return!1;for(const i of e){if(!i)continue;const e=i[t];if(Array.isArray(e)&&e.length>0)return!0}return!1}class Nt extends e{static manifest={events:[{type:"tree-state-change",description:"Emitted when tree expansion state changes (toggle, expand all, collapse all)"}],queries:[{type:"canMoveRow",description:"Returns false for rows with children (parent nodes cannot be reordered)"}]};name="tree";styles="@layer tbw-plugins{tbw-grid{.cell[data-field=__tbw_expander]{border-inline-end:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}.header-row .cell[data-field=__tbw_expander]{display:none}.header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}.tree-cell-wrapper{display:inline-flex;align-items:center;padding-inline-start:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}.tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}.tree-toggle{cursor:pointer;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}.tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}.tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}.data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}.data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}}";get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=/* @__PURE__ */new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=/* @__PURE__ */new Map;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;sortState=null;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null}handleQuery(e){if("canMoveRow"===e.type){const t=e.context,i=this.config.childrenField??"children",n=t?.[i];if(Array.isArray(n)&&n.length>0)return!1}}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detect(e){if(!this.config.autoDetect)return!1;const t=e,i=this.config.childrenField??function(e){if(!Array.isArray(e)||0===e.length)return null;const t=["children","items","nodes","subRows","nested"];for(const i of e)if(i&&"object"==typeof i)for(const e of t){const t=i[e];if(Array.isArray(t)&&t.length>0)return e}return null}(t)??"children";return Ht(t,i)}processRows(e){const t=e;if(!Ht(t,this.config.childrenField??"children"))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let i=this.withStableKeys(t);this.sortState&&(i=this.sortTree(i,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=Dt(i,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(i,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const n=/* @__PURE__ */new Set;for(const r of this.flattenedRows)this.rowKeyMap.set(r.key,r),n.add(r.key),!this.previousVisibleKeys.has(r.key)&&r.depth>0&&this.keysToAnimate.add(r.key);return this.previousVisibleKeys=n,this.flattenedRows.map(e=>({...e.data,__treeKey:e.key,__treeDepth:e.depth,__treeHasChildren:e.hasChildren,__treeExpanded:e.isExpanded}))}withStableKeys(e,t=null){const i=this.config.childrenField??"children";return e.map((e,n)=>{const r=e.__stableKey,o=void 0!==e.id?String(e.id):r??(t?`${t}-${n}`:String(n)),s=e[i],a=Array.isArray(s)&&s.length>0;return{...e,__stableKey:o,...a?{[i]:this.withStableKeys(s,o)}:{}}})}flattenTree(e,t,i=0){const n=this.config.childrenField??"children",r=[];for(const o of e){const e=o.__stableKey??String(o.id??"?"),s=o[n],a=Array.isArray(s)&&s.length>0,l=t.has(e);r.push({key:e,data:o,depth:i,hasChildren:a,isExpanded:l,parentKey:i>0&&e.substring(0,e.lastIndexOf("-"))||null}),a&&l&&r.push(...this.flattenTree(s,t,i+1))}return r}sortTree(e,t,i){const n=this.config.childrenField??"children";return[...e].sort((e,n)=>{const r=e[t],o=n[t];return null==r&&null==o?0:null==r?-1:null==o?1:r>o?i:r<o?-i:0}).map(e=>{const r=e[n];return Array.isArray(r)&&r.length>0?{...e,[n]:this.sortTree(r,t,i)}:e})}processColumns(e){if(0===this.flattenedRows.length)return[...e];const t=[...e];if(0===t.length)return t;const i=t[0],n=i.viewRenderer,r=()=>this.config,o=this.setIcon.bind(this),s=this.resolveIcon.bind(this);return t[0]={...i,viewRenderer:e=>{const{row:t,value:i}=e,{showExpandIcons:a=!0,indentWidth:l}=r(),d=t,c=d.__treeDepth??0,u=document.createElement("span");if(u.className="tree-cell-wrapper",u.style.setProperty("--tbw-tree-depth",String(c)),void 0!==l&&u.style.setProperty("--tbw-tree-indent-width",`${l}px`),a)if(d.__treeHasChildren){const e=document.createElement("span");e.className="tree-toggle"+(d.__treeExpanded?" expanded":""),o(e,s(d.__treeExpanded?"collapse":"expand")),e.setAttribute("data-tree-key",String(d.__treeKey??"")),u.appendChild(e)}else{const e=document.createElement("span");e.className="tree-spacer",u.appendChild(e)}const h=document.createElement("span");if(h.className="tree-content",n){const t=n(e);t instanceof Node?h.appendChild(t):"string"==typeof t&&(h.innerHTML=t)}else h.textContent=null!=i?String(i):"";return u.appendChild(h),u}},t}onCellClick(e){const t=e.originalEvent?.target;if(!t?.classList.contains("tree-toggle"))return!1;const i=t.getAttribute("data-tree-key");if(!i)return!1;const n=this.rowKeyMap.get(i);return!!n&&(this.expandedKeys=Mt(this.expandedKeys,i),this.emit("tree-expand",{key:i,row:n.data,expanded:this.expandedKeys.has(i),depth:n.depth}),this.requestRender(),!0)}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,i=this.flattenedRows[t];return i?.hasChildren?(e.preventDefault(),this.expandedKeys=Mt(this.expandedKeys,i.key),this.emit("tree-expand",{key:i.key,row:i.data,expanded:this.expandedKeys.has(i.key),depth:i.depth}),this.requestRenderWithFocus(),!0):void 0}onHeaderClick(e){if(0===this.flattenedRows.length||!e.column.sortable)return!1;const{field:t}=e.column;this.sortState&&this.sortState.field===t?1===this.sortState.direction?this.sortState={field:t,direction:-1}:this.sortState=null:this.sortState={field:t,direction:1};const i=this.grid;return void 0!==i._sortState&&(i._sortState=this.sortState?{...this.sortState}:null),this.emit("sort-change",{field:t,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.animationStyle;if(!1===e||0===this.keysToAnimate.size)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i="fade"===e?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const n of t.querySelectorAll(".data-grid-row")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r=this.flattenedRows[t]?.key;r&&this.keysToAnimate.has(r)&&(n.classList.add(i),n.addEventListener("animationend",()=>n.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=Mt(this.expandedKeys,e),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=Dt(this.rows,this.config),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=/* @__PURE__ */new Set,this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=qt(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function zt(e){if(0===e.undoStack.length)return{newState:e,action:null};const t=[...e.undoStack],i=t.pop();return i?{newState:{undoStack:t,redoStack:[...e.redoStack,i]},action:i}:{newState:e,action:null}}function Gt(e){if(0===e.redoStack.length)return{newState:e,action:null};const t=[...e.redoStack],i=t.pop();return i?{newState:{undoStack:[...e.undoStack,i],redoStack:t},action:i}:{newState:e,action:null}}class Kt extends e{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];attach(e){super.attach(e),this.on("cell-edit-committed",e=>{this.recordEdit(e.rowIndex,e.field,e.oldValue,e.newValue)})}detach(){this.undoStack=[],this.redoStack=[]}onKeyDown(e){const t=(e.ctrlKey||e.metaKey)&&"z"===e.key&&!e.shiftKey,i=(e.ctrlKey||e.metaKey)&&("y"===e.key||"z"===e.key&&e.shiftKey);if(t){const e=zt({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.oldValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("undo",{action:e.action,type:"undo"}),this.requestRender()}return!0}if(i){const e=Gt({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.newValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("redo",{action:e.action,type:"redo"}),this.requestRender()}return!0}return!1}recordEdit(e,t,i,n){const r=function(e,t,i,n){return{type:"cell-edit",rowIndex:e,field:t,oldValue:i,newValue:n,timestamp:Date.now()}}(e,t,i,n),o=function(e,t,i){const n=[...e.undoStack,t];for(;n.length>i;)n.shift();return{undoStack:n,redoStack:[]}}({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=o.undoStack,this.redoStack=o.redoStack}undo(){const e=zt({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.oldValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}redo(){const e=Gt({undoStack:this.undoStack,redoStack:this.redoStack});if(e.action){const t=this.rows;t[e.action.rowIndex]&&(t[e.action.rowIndex][e.action.field]=e.action.newValue),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.requestRender()}return e.action}canUndo(){return{undoStack:this.undoStack,redoStack:this.redoStack}.undoStack.length>0}canRedo(){return{undoStack:this.undoStack,redoStack:this.redoStack}.redoStack.length>0}clearHistory(){const e={undoStack:[],redoStack:[]};this.undoStack=e.undoStack,this.redoStack=e.redoStack}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}function Ot(e){const t=e.meta??{};return!0!==t.lockPosition&&!0!==t.suppressMovable}class Bt extends e{static dependencies=[{name:"reorder",required:!1,reason:"Enables drag-to-reorder columns in visibility panel"}];static manifest={queries:[{type:"getContextMenuItems",description:'Contributes "Hide column" item to the header context menu'}]};name="visibility";static PANEL_ID="columns";styles='@layer tbw-plugins{.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem))}.tbw-visibility-row{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-menu-item-padding, .375rem .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);border-radius:var(--tbw-border-radius, .25rem);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;user-select:none;flex-shrink:0}.tbw-visibility-row.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;cursor:pointer}.tbw-visibility-row.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-row.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-show-all{margin:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding, .5rem .75rem);border:1px solid var(--tbw-visibility-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius, .25rem);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg));color:var(--tbw-color-fg);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header{display:flex;align-items:center;padding:var(--tbw-menu-item-padding, .375rem .25rem);font-size:var(--tbw-font-size-sm, .8125rem);font-weight:600;color:var(--tbw-color-fg);border-bottom:1px solid var(--tbw-color-border);margin-top:var(--tbw-spacing-sm, .25rem);position:relative}.tbw-visibility-group-header:first-child{margin-top:0}.tbw-visibility-group-header .tbw-visibility-label{gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-visibility-group-header.reorderable{cursor:grab}.tbw-visibility-group-header.reorderable:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header .tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;user-select:none;flex-shrink:0}.tbw-visibility-group-header.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-group-header.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-group-header.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-group-header.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row--grouped{padding-left:calc(var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem)) + .75rem)}}';get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;draggedGroupId=null;draggedGroupFields=[];clearDragClasses(e){e.querySelectorAll(".tbw-visibility-row, .tbw-visibility-group-header").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-move",()=>{this.columnListElement&&requestAnimationFrame(()=>{this.columnListElement&&this.rebuildToggles(this.columnListElement)})},{signal:this.disconnectSignal})}detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}handleQuery(e){if("getContextMenuItems"===e.type){const t=e.context;if(!t.isHeader)return;const i=t.column;if(!i?.field)return;if(i.meta?.lockVisibility)return;return[{id:"visibility/hide-column",label:"Hide Column",icon:"👁",order:30,action:()=>this.hideColumn(i.field)}]}}getToolPanel(){return{id:Bt.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(Bt.PANEL_ID)||this.grid.toggleToolPanelSection(Bt.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(Bt.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(e=>e.visible).map(e=>e.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(e=>!e.visible).map(e=>e.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.setColumnVisible(e,!0)}hideColumn(e){this.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(Bt.PANEL_ID)}renderPanelContent(e){const t=document.createElement("div");t.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",t.appendChild(i);const n=document.createElement("button");return n.className="tbw-visibility-show-all",n.textContent="Show All",n.addEventListener("click",()=>{this.grid.showAllColumns(),this.rebuildToggles(i)}),t.appendChild(n),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(t),()=>{this.columnListElement=null,t.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!(!e||"function"!=typeof e.moveColumn)}rebuildToggles(e){const t=this.hasReorderPlugin();e.innerHTML="";const i=this.grid.getAllColumns().filter(e=>!e.utility),n=this.grid.query("getColumnGrouping"),r=n?.flat().filter(e=>e&&e.fields.length>0)??[];if(0===r.length)return void this.renderFlatColumnList(i,t,e);const o=/* @__PURE__ */new Map;for(const a of r)for(const e of a.fields)o.set(e,a);const s=/* @__PURE__ */new Set;for(const a of i){const n=o.get(a.field);if(n){if(!s.has(n.id)){s.add(n.id);const r=new Set(n.fields),o=i.filter(e=>r.has(e.field));o.length>0&&this.renderGroupSection(n,o,t,e)}}else{const n=i.indexOf(a);e.appendChild(this.createColumnRow(a,n,t,e))}}}renderGroupSection(e,t,i,n){const r=document.createElement("div");r.className="tbw-visibility-group-header",r.setAttribute("data-group-id",e.id),i&&(r.draggable=!0,r.classList.add("reorderable"),this.setupGroupDragListeners(r,e,n));const o=document.createElement("label");o.className="tbw-visibility-label";const s=document.createElement("input");s.type="checkbox";const a=t.filter(e=>e.visible).length,l=t.every(e=>e.lockVisible);a===t.length?(s.checked=!0,s.indeterminate=!1):0===a?(s.checked=!1,s.indeterminate=!1):(s.checked=!1,s.indeterminate=!0),s.disabled=l,s.addEventListener("change",()=>{const e=s.checked;for(const i of t)i.lockVisible||this.grid.setColumnVisible(i.field,e);setTimeout(()=>this.rebuildToggles(n),0)});const d=document.createElement("span");if(d.textContent=e.label,o.appendChild(s),o.appendChild(d),r.appendChild(o),i){const e=document.createElement("span");e.className="tbw-visibility-handle",this.setIcon(e,this.resolveIcon("dragHandle")),e.title="Drag to reorder group",r.insertBefore(e,o)}n.appendChild(r);const c=this.grid.getAllColumns().filter(e=>!e.utility);for(const u of t){const e=c.findIndex(e=>e.field===u.field),t=this.createColumnRow(u,e,i,n);t.classList.add("tbw-visibility-row--grouped"),n.appendChild(t)}}renderFlatColumnList(e,t,i){const n=this.grid.getAllColumns().filter(e=>!e.utility);for(const r of e){const e=n.findIndex(e=>e.field===r.field);i.appendChild(this.createColumnRow(r,e,t,i))}}createColumnRow(e,t,i,n){const r=e.header||e.field,o=document.createElement("div");o.className=e.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",o.setAttribute("data-field",e.field),o.setAttribute("data-index",String(t)),i&&Ot(e)&&(o.draggable=!0,o.classList.add("reorderable"),this.setupDragListeners(o,e.field,t,n));const s=document.createElement("label");s.className="tbw-visibility-label";const a=document.createElement("input");a.type="checkbox",a.checked=e.visible,a.disabled=e.lockVisible??!1,a.addEventListener("change",()=>{this.grid.toggleColumnVisibility(e.field),setTimeout(()=>this.rebuildToggles(n),0)});const l=document.createElement("span");if(l.textContent=r,s.appendChild(a),s.appendChild(l),i&&Ot(e)){const e=document.createElement("span");e.className="tbw-visibility-handle",this.setIcon(e,this.resolveIcon("dragHandle")),e.title="Drag to reorder",o.appendChild(e)}return o.appendChild(s),o}setupGroupDragListeners(e,t,i){e.addEventListener("dragstart",n=>{this.isDragging=!0,this.draggedGroupId=t.id,this.draggedGroupFields=[...t.fields],this.draggedField=null,this.draggedIndex=null,n.dataTransfer&&(n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",`group:${t.id}`)),e.classList.add("dragging"),i.querySelectorAll(".tbw-visibility-row--grouped").forEach(e=>{const t=e.getAttribute("data-field");t&&this.draggedGroupFields.includes(t)&&e.classList.add("dragging")})}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedGroupId=null,this.draggedGroupFields=[],this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(i)}),e.addEventListener("dragover",n=>{if(n.preventDefault(),!this.isDragging)return;if(this.draggedGroupId===t.id)return;if(!this.draggedGroupId)return;const r=e.getBoundingClientRect(),o=r.top+r.height/2,s=n.clientY<o;this.clearDragClasses(i),e.classList.add("drop-target"),e.classList.toggle("drop-before",s),e.classList.toggle("drop-after",!s)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",n=>{if(n.preventDefault(),!this.isDragging||!this.draggedGroupId||this.draggedGroupId===t.id)return;const r=e.getBoundingClientRect(),o=n.clientY<r.top+r.height/2;this.executeGroupDrop(this.draggedGroupFields,t.fields,o,i)})}executeGroupDrop(e,t,i,n){const r=this.grid.getAllColumns().map(e=>e.field),o=r.filter(t=>!e.includes(t)),s=i?t[0]:t[t.length-1],a=o.indexOf(s);if(-1===a)return;const l=i?a:a+1,d=r.filter(t=>e.includes(t));o.splice(l,0,...d),this.grid.setColumnOrder(o),requestAnimationFrame(()=>{this.columnListElement&&this.rebuildToggles(this.columnListElement)})}setupDragListeners(e,t,i,n){e.addEventListener("dragstart",n=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=i,this.draggedGroupId=null,this.draggedGroupFields=[],n.dataTransfer&&(n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(n)}),e.addEventListener("dragover",r=>{if(r.preventDefault(),!this.isDragging)return;if(this.draggedGroupId){if(e.classList.contains("tbw-visibility-row--grouped"))return}else if(this.draggedField===t)return;const o=e.getBoundingClientRect(),s=o.top+o.height/2;this.dropIndex=r.clientY<s?i:i+1,this.clearDragClasses(n),this.draggedGroupId?(n.querySelector(`.tbw-visibility-group-header[data-group-id="${this.draggedGroupId}"]`)?.classList.add("dragging"),n.querySelectorAll(".tbw-visibility-row--grouped").forEach(e=>{const t=e.getAttribute("data-field");t&&this.draggedGroupFields.includes(t)&&e.classList.add("dragging")})):this.draggedField&&n.querySelector(`.tbw-visibility-row[data-field="${this.draggedField}"]`)?.classList.add("dragging"),e.classList.add("drop-target"),e.classList.toggle("drop-before",r.clientY<s),e.classList.toggle("drop-after",r.clientY>=s)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",i=>{if(i.preventDefault(),!this.isDragging)return;if(this.draggedGroupId&&this.draggedGroupFields.length>0){if(e.classList.contains("tbw-visibility-row--grouped"))return;const r=e.getBoundingClientRect(),o=i.clientY<r.top+r.height/2;return void this.executeGroupDrop(this.draggedGroupFields,[t],o,n)}const r=this.draggedField,o=this.draggedIndex,s=this.dropIndex;if(null===r||null===o||null===s)return;const a=s>o?s-1:s;if(a!==o){const e=this.grid.getAllColumns(),t=e.filter(e=>!e.utility),i=t[a]?.field,n={field:r,fromIndex:o,toIndex:i?e.findIndex(e=>e.field===i):e.length};this.emit("column-reorder-request",n)}})}}export{he as BLANK_FILTER_VALUE,e as BaseGridPlugin,H as ClipboardPlugin,B as ColumnVirtualizationPlugin,ie as ContextMenuPlugin,f as DEFAULT_ANIMATION_CONFIG,t as DEFAULT_GRID_ICONS,m as DGEvents,w as DataGridElement,ae as EditingPlugin,ue as ExportPlugin,ye as FilteringPlugin,b as FitModeEnum,v as GridCSSVars,y as GridClasses,x as GridDataAttrs,C as GridElement,E as GridSelectors,Ce as GroupingColumnsPlugin,Re as GroupingRowsPlugin,Ae as MasterDetailPlugin,Te as MultiSortPlugin,R as PLUGIN_QUERIES,Ge as PinnedColumnsPlugin,Ye as PinnedRowsPlugin,dt as PivotPlugin,S as PluginEvents,k as PluginManager,gt as PrintPlugin,wt as ROW_DRAG_HANDLE_FIELD,A as RenderPhase,ft as ReorderPlugin,mt as ResponsivePlugin,bt as RowReorderPlugin,At as SelectionPlugin,Tt as ServerSidePlugin,Nt as TreePlugin,Kt as UndoRedoPlugin,Bt as VisibilityPlugin,_ as builtInSort,L as createGrid,I as defaultComparator,ne as defaultEditorFor,q as defaultPasteHandler,me as getUniqueValuesBatch,ut as printGridIsolated,T as queryGrid};//# sourceMappingURL=all.js.map
|