@toolbox-web/grid 1.26.0 → 1.26.1

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/all.js CHANGED
@@ -1,2 +1,2 @@
1
- import{w as e,C as t,BaseGridPlugin as i,DEFAULT_GRID_ICONS as n,E as r,e as o,s,c as a,a as l,t as d,b as c,d as u,runAggregator as h,f as g,g as p,h as f,r as m,getAggregator as w,getValueAggregator as b,P as v,i as y,j as x,k as C,l as R,M as E,m as S,n as k,F as A,T as _,N as I}from"./index.js";import{DEFAULT_ANIMATION_CONFIG as L,DGEvents as T,DataGridElement as F,FitModeEnum as M,GridCSSVars as D,GridClasses as q,GridDataAttrs as G,DataGridElement as P,GridSelectors as H,PLUGIN_QUERIES as N,PluginEvents as z,PluginManager as K,RenderPhase as O,builtInSort as V,createGrid as B,defaultComparator as $,queryGrid as W,setFeatureResolver as j}from"./index.js";function U(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 Y(e,t){return t?.length?[...t].sort((e,t)=>e-t).map(t=>e[t]).filter(e=>null!=e):e}function Z(e){return null==e?"":e instanceof Date?e.toISOString():"object"==typeof e?JSON.stringify(e):String(e)}function Q(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 X(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 J extends i{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=Q(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??X)(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=U(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=U(this.visibleColumns.slice(n,r+1))}else i=U(this.columns);if(e?.rowIndices)n=Y(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):Z(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(i){const{columns:n,rows:r}=this.#o(i);if(0===n.length||0===r.length)return"";const o=this.#s(n,r,i);return await async function(i){try{return await navigator.clipboard.writeText(i),!0}catch(n){e(t,`Clipboard API failed: ${n}`);const r=document.createElement("textarea");r.value=i,r.style.position="fixed",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r),r.select();const o=document.execCommand("copy");return document.body.removeChild(r),o}}(o),this.lastCopied={text:o,timestamp:Date.now()},this.emit("copy",{text:o,rowCount:r.length,columnCount:n.length}),o}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?Q(e,this.config):null}getLastCopied(){return this.lastCopied}}function ee(e){if(null==e)return 100;if("number"==typeof e)return e;const t=parseFloat(e);return isNaN(t)?100:t}function te(e){return e.map(e=>ee(e.width))}function ie(e){const t=[];let i=0;for(const n of e)t.push(i),i+=ee(n.width);return t}function ne(e){return e.reduce((e,t)=>e+ee(t.width),0)}function re(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 oe extends i{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=te(t),this.columnOffsets=ie(t),this.totalWidth=ne(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=te(e),this.columnOffsets=ie(e),this.totalWidth=ne(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=re(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,i=this.gridElement;i&&(i.scrollLeft=t)}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const se="@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 ae(e,t){return("function"==typeof e?e(t):e).filter(e=>!0!==e.hidden&&("function"!=typeof e.hidden||!e.hidden(t)))}function le(e,t){return!0===e.disabled||"function"==typeof e.disabled&&e.disabled(t)}function de(e,t,i,r=n.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 n of e){if(n.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",n.cssClass&&e.classList.add(n.cssClass),e.setAttribute("role","menuitem"),e.setAttribute("data-id",n.id),e.setAttribute("tabindex","-1");const a=le(n,t);if(a&&(e.classList.add("disabled"),e.setAttribute("aria-disabled","true")),n.icon){const t=document.createElement("span");t.className="tbw-context-menu-icon",t.innerHTML=n.icon,e.appendChild(t)}else if(s){const t=document.createElement("span");t.className="tbw-context-menu-icon",t.innerHTML="&nbsp;",e.appendChild(t)}const l=document.createElement("span");if(l.className="tbw-context-menu-label",l.textContent=n.name,e.appendChild(l),n.shortcut){const t=document.createElement("span");if(t.className="tbw-context-menu-shortcut",Array.isArray(n.shortcut))n.shortcut.forEach((e,i)=>{i>0&&t.appendChild(document.createTextNode("+"));const n=document.createElement("kbd");n.textContent=e,t.appendChild(n)});else{const e=document.createElement("kbd");e.textContent=n.shortcut,t.appendChild(e)}e.appendChild(t)}if(n.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(!n.subMenu)return;const o=de(ae(n.subMenu,t),t,i,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||!n.action||n.subMenu||e.addEventListener("click",e=>{e.stopPropagation(),i(n)}),o.appendChild(e)}return o}const ce="getContextMenuItems";let ue=null,he=null,ge=0;const pe=[{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 fe extends i{static manifest={queries:[{type:ce,description:"Collects context menu items from other plugins for header right-click menus"}]};name="contextMenu";get defaultConfig(){return{items:pe}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),ge++}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 fe.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(){if(!he&&"undefined"!=typeof document&&se&&(he=document.createElement("style"),he.id="tbw-context-menu-styles",he.textContent=se,document.head.appendChild(he)),!ue){ue=new AbortController;const e=ue.signal,t=()=>{document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove())};document.addEventListener("click",t,{signal:e}),document.addEventListener("keydown",e=>{"Escape"===e.key&&t()},{signal:e}),document.addEventListener("scroll",t,{capture:!0,signal:e})}}uninstallGlobalHandlers(){ge--,ge>0||(ue&&(ue.abort(),ue=null),he&&(he.remove(),he=null))}collectPluginItems(e){if(!this.grid)return[];const t=this.grid.query(ce,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}))}openMenuAt(e,t,i,n=!1){this.params=e,this.position={x:t,y:i};const r=this.collectPluginItems(e);let o=ae(this.config.items??pe,e);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]}var s,a;(o=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}(o),o.length)&&(document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove()),this.menuElement=null,this.menuElement=de(o,e,t=>{t.action&&t.action(e),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),s=this.menuElement,a=()=>this.hideMenu(),s.addEventListener("keydown",e=>{const t=Array.from(s.querySelectorAll('[role="menuitem"]:not(.disabled)'));if(!t.length)return;const i=document.activeElement,n=t.indexOf(i);switch(e.key){case"ArrowDown":e.preventDefault(),t[n<t.length-1?n+1:0].focus();break;case"ArrowUp":e.preventDefault(),t[n>0?n-1:t.length-1].focus();break;case"Enter":case" ":e.preventDefault(),i&&t.includes(i)&&i.click();break;case"Escape":e.preventDefault(),a()}}),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),function(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"}(this.menuElement,t,i),this.isOpen=!0,n&&function(e){const t=e.querySelector('[role="menuitem"]:not(.disabled)');t?.focus()}(this.menuElement),this.emit("context-menu-open",{params:e,items:o}))}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.openMenuAt(o,t.clientX,t.clientY)}))}onKeyDown(e){const t="F10"===e.key&&e.shiftKey,i="ContextMenu"===e.key;if(!t&&!i)return;e.preventDefault();const n=this.grid;if(!n)return;const r=n._focusRow,o=n._focusCol,s=this.visibleColumns[o],a=this.rows[r],l=this.gridElement,d=l?.querySelector(`[data-row="${r}"][data-col="${o}"]`);let c=0,u=0;if(d){const e=d.getBoundingClientRect();c=e.left+e.width/2,u=e.bottom}const h=this.syncSelectionOnContextMenu(r),g={row:a,rowIndex:r,column:s,columnIndex:o,field:s?.field??"",value:a?.[s?.field]??null,isHeader:!1,event:e,selectedRows:h};return this.openMenuAt(g,c,u,!0),!0}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??[]};this.openMenuAt(n,e,t)}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}function me(e){return t=>{const i=e.editorParams,n=document.createElement("input");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);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof t.value?t.commit(n.value):t.commit(n.valueAsDate);else if(e.nullable)t.commit(null);else{const e=i?.default;"string"==typeof t.value||"string"==typeof e?t.commit("string"==typeof e?e:`${(r=e??/* @__PURE__ */new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):t.commit(e instanceof Date?e:/* @__PURE__ */new Date)}}),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}const we="__tbw_null__";function be(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=()=>{""===n.value?e.nullable?t.commit(null):t.commit(i?.min??0):t.commit(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 me(e);case"select":return function(e){return t=>{const i=e.editorParams,n=document.createElement("select");if(e.multi&&(n.multiple=!0),e.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=e.nullable?we:"",r.textContent=e.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==t.value&&(r.selected=!0),n.appendChild(r)}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 e.nullable&&n.value===we?t.commit(null):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 i=n.value;""!==i?"string"==typeof t.value&&i===t.value.replace(/[\n\r]/g,"")||("number"==typeof t.value?t.commit(Number(i)):t.commit(i)):e.nullable?t.commit(null):t.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",e=>{"Enter"===e.key&&r(),"Escape"===e.key&&t.cancel()}),n}}(e)}}function ve(e,t,i){if(e instanceof HTMLInputElement){if("checkbox"===e.type)return e.checked;if("number"===e.type){if(""===e.value){if(t?.nullable)return null;const e=t?.editorParams;return e?.min??0}return Number(e.value)}if("date"===e.type)return e.value?"string"==typeof i?e.value:e.valueAsDate:t?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date;if("number"==typeof i){if(""===e.value){if(t?.nullable)return null;const e=t?.editorParams;return e?.min??0}return Number(e.value)}return""===e.value&&null==i?t?.nullable?null:"":"string"==typeof i&&e.value===i.replace(/[\n\r]/g,"")?i:e.value}return"number"===t?.type&&""!==e.value||"number"==typeof i&&""!==e.value?Number(e.value):null==i&&""===e.value?t?.nullable?null:"":e.value}class ye{#l=/* @__PURE__ */new Map;#d;constructor(e){this.#d=e}setInvalid(e,t,i=""){let n=this.#l.get(e);n||(n=/* @__PURE__ */new Map,this.#l.set(e,n)),n.set(t,i),this.#d(e,t,!0)}clearInvalid(e,t){const i=this.#l.get(e);i&&(i.delete(t),0===i.size&&this.#l.delete(e)),this.#d(e,t,!1)}clearRowInvalid(e){const t=this.#l.get(e);if(t){const i=Array.from(t.keys());this.#l.delete(e),i.forEach(t=>this.#d(e,t,!1))}}clearAllInvalid(){const e=Array.from(this.#l.entries());this.#l.clear(),e.forEach(([e,t])=>{t.forEach((t,i)=>this.#d(e,i,!1))})}isCellInvalid(e,t){return this.#l.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#l.get(e)?.get(t)}hasInvalidCells(e){const t=this.#l.get(e);return!!t&&t.size>0}getInvalidFields(e){return new Map(this.#l.get(e)??[])}}function xe(e,t,i){const n=e.get(t);return!!n&&!Ce(n,i)}function Ce(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(typeof e!=typeof t)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!Ce(e[i],t[i]))return!1;return!0}if("object"==typeof e){const i=e,n=t,r=Object.keys(i),o=Object.keys(n);if(r.length!==o.length)return!1;for(const e of r)if(!Ce(i[e],n[e]))return!1;return!0}return!1}function Re(e,t,i){e.set(t,structuredClone(i))}function Ee(e,t,i){const n=e.get(t);if(!n)return!1;const r=n,o=i;for(const s of Object.keys(r))o[s]=r[s];return!0}class Se{baselines=/* @__PURE__ */new Map;baselinesWereCaptured=!1;newRowIds=/* @__PURE__ */new Set;changedRowIds=/* @__PURE__ */new Set;committedDirtyRowIds=/* @__PURE__ */new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(e,t){const i=this.baselines.size;!function(e,t,i){for(const n of t)try{const t=i(n);null==t||e.has(t)||e.set(t,structuredClone(n))}catch{}}(this.baselines,e,t),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(e,t){return xe(this.baselines,e,t)}hasAnyDirty(e){if(this.newRowIds.size>0)return!0;for(const[t]of this.baselines){const i=e(t);if(i&&xe(this.baselines,t,i))return!0}return!1}isCellDirty(e,t,i){return function(e,t,i,n){const r=e.get(t);return!!r&&!Ce(r[n],i[n])}(this.baselines,e,t,i)}getRowDirtyState(e,t){const i=this.newRowIds.has(e);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(e)&&xe(this.baselines,e,t),hasBaseline:this.baselines.has(e)}}markPristine(e,t){Re(this.baselines,e,t),this.newRowIds.delete(e),this.changedRowIds.delete(e),this.committedDirtyRowIds.delete(e)}markNew(e){this.newRowIds.add(e),this.committedDirtyRowIds.add(e)}markDirty(e){this.changedRowIds.add(e),this.committedDirtyRowIds.add(e)}markAllPristine(e){for(const[t]of this.baselines){const i=e(t);i&&Re(this.baselines,t,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(e){return function(e,t){const i=e.get(t);return i?structuredClone(i):void 0}(this.baselines,e)}hasBaseline(e){return this.baselines.has(e)}getDirtyRows(e){const t=[];for(const[i,n]of this.baselines){const r=e(i);r&&xe(this.baselines,i,r)&&t.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=e(i);n&&t.push({id:i,original:void 0,current:n})}return t}getDirtyRowIds(e){const t=[];for(const[i]of this.baselines){const n=e(i);n&&xe(this.baselines,i,n)&&t.push(i)}for(const i of this.newRowIds)t.push(i);return t}revertRow(e,t){const i=Ee(this.baselines,e,t);return i&&(this.changedRowIds.delete(e),this.committedDirtyRowIds.delete(e)),i}revertAll(e){for(const[t]of this.baselines){const i=e(t);i&&Ee(this.baselines,t,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(e){const t=[];for(const i of this.changedRowIds){const n=e(i);n&&t.push(n)}return t}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(e){return this.changedRowIds.has(e)}}const ke='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function Ae(e){return"string"==typeof e&&("__proto__"!==e&&"constructor"!==e&&"prototype"!==e)}function _e(e){}function Ie(e,t){return!1===e.onBeforeEditClose?.(t)}function Le(t,i,n,o,s,a,l){if(!o.editable)return;if(a.classList.contains("editing"))return;const{grid:d,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:g}=t;let p;try{p=d.getRowId?.(i)}catch{}const f=p?e=>d.updateRow(p,e,"cascade"):_e,m=Ae(o.field)?i[o.field]:void 0;a.classList.add("editing"),h.add(`${n}:${s}`);const w=a.parentElement;w&&function(e){const t=(e.__editingCellCount??0)+1;e.__editingCellCount=t,e.setAttribute("data-has-editing","")}(w);let b=!1;const v=e=>{if(b||!c&&!t.isEditSessionActive())return;const r=p?d._getRowEntry(p):void 0,s=r?.row??i,a=r?.index??n;t.commitCellValue(a,o,e,s)},y=()=>{if(b=!0,Ae(o.field)){const e=p?d._getRowEntry(p):void 0;(e?.row??i)[o.field]=m}},x=document.createElement("div");x.className="tbw-editor-host",a.innerHTML="",a.appendChild(x),x.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=x.querySelector("input,textarea,select");return void(t&&v(ve(t,o,m)))}if(Ie(u,e))return;e.stopPropagation(),e.preventDefault(),b=!0,t.exitRowEdit(n,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(Ie(u,e))return;e.stopPropagation(),e.preventDefault(),y(),t.exitRowEdit(n,!0)}});const C=o,R=C.__editorTemplate,E=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}}(d,C)??be(o),S=m,k=`${n}:${o.field}`,A=[];g.set(k,e=>{for(const t of A)t(e)});const _=e=>{A.push(e)};if("template"===E&&R)!function(e,t,i,n,r,o,s,a,l){const d=i.__editorTemplate;if(!d)return;const c=d.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:n,value:r,field:i.field,column:i,commit:o,cancel:s}):c.querySelectorAll("*").forEach(e=>{1===e.childNodes.length&&e.firstChild?.nodeType===Node.TEXT_NODE&&(e.textContent=e.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(e,t)=>{if(!Ae(t))return"";const i=n[t];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!r:h.value=String(r??"");let t=!1;h.addEventListener("blur",()=>{t||o(ve(h,i,r))}),h.addEventListener("keydown",n=>{const a=n;if("Enter"===a.key){if(Ie(e.config,a))return;a.stopPropagation(),a.preventDefault(),t=!0,o(ve(h,i,r)),e.exitRowEdit(l,!1)}if("Escape"===a.key){if(Ie(e.config,a))return;a.stopPropagation(),a.preventDefault(),s(),e.exitRowEdit(l,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>o(h.checked)),a||setTimeout(()=>h.focus({preventScroll:!0}),0)}t.appendChild(c)}(t,x,C,i,m,v,y,l,n),_(e=>{const t=x.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if("string"==typeof E){const e=document.createElement(E);e.value=S,e.addEventListener("change",()=>v(e.value)),_(t=>{e.value=t}),x.appendChild(e),l||queueMicrotask(()=>{const e=x.querySelector(ke);e?.focus({preventScroll:!0})})}else if("function"==typeof E){const e=E({row:i,rowId:p??"",value:S,field:o.field,column:o,commit:v,cancel:y,updateRow:f,onValueChange:_});if("string"==typeof e)x.innerHTML=e,function(e,t,i,n){const r=e.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(ve(r,t,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(ve(r,t,n))))}(x,o,v,m),_(e=>{const t=x.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if(e instanceof Node){x.appendChild(e);e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?_(t=>{e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??"")}):a.setAttribute("data-editor-managed","")}else!e&&x.hasChildNodes()&&a.setAttribute("data-editor-managed","");l||queueMicrotask(()=>{const e=x.querySelector(ke);e?.focus({preventScroll:!0})})}else if(E&&"object"==typeof E){const n=document.createElement("div");n.setAttribute("data-external-editor",""),n.setAttribute("data-field",o.field),x.appendChild(n),a.setAttribute("data-editor-managed","");const s={row:i,rowId:p??"",value:S,field:o.field,column:o,commit:v,cancel:y,updateRow:f,onValueChange:_};if(E.mount)try{E.mount({placeholder:n,context:s,spec:E})}catch(I){e(r,`External editor mount error for column '${o.field}': ${I}`,t.grid.id)}else d.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:n,spec:E,context:s}}))}}class Te extends i{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>!0===e||"function"==typeof e},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],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#c(){return"grid"===this.config.mode}#u(e,t){const i=this.#h.effectiveConfig?.rowEditable;if(i&&!i(t))return!1;const{editable:n}=e;return"function"==typeof n?n(t):!0===n}#g(e){return!0===e.editable||"function"==typeof e.editable}#p=-1;#f;#m;#w=-1;#b=/* @__PURE__ */new Map;#v=/* @__PURE__ */new Set;#y=/* @__PURE__ */new Map;#x=!1;#C=-1;#R;#E=!1;#S=!1;#k=!1;#A=null;#_=new Se;#I;get#h(){return this.grid}attach(e){super.attach(e);const t=this.disconnectSignal,i=this.#h;if(this.#R=new ye((e,t,i)=>{this.#L(e,t,i)}),this.#I={grid:i,isGridMode:this.#c,config:this.config,editingCells:this.#v,editorValueCallbacks:this.#y,isEditSessionActive:()=>-1!==this.#p,commitCellValue:(e,t,i,n)=>this.#T(e,t,i,n),exitRowEdit:(e,t)=>this.#F(e,t)},i._activeEditRows=-1,i._rowEditSnapshots=/* @__PURE__ */new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(e,"_changedRowIdSet",{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.#c&&"Escape"===e.key&&-1!==this.#p){if(Ie(this.config,e))return;this.#F(this.#p,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",e=>{if(this.#c)return;if(-1===this.#p)return;const t=i.findRenderedRowElement?.(this.#p);if(!t)return;if((e.composedPath&&e.composedPath()||[]).includes(t))return;const n=e.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||Ie(this.config,e)||queueMicrotask(()=>{-1!==this.#p&&this.#F(this.#p,!1)})},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",e=>{if(this.#c)return;if(-1===this.#p)return;const t=e.relatedTarget;t&&this.grid.containsFocus?.(t)||t&&this.gridElement.contains(t)||queueMicrotask(()=>{-1!==this.#p&&this.#M()})},{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.#y.get(i);n&&n(t.newValue)},{signal:t}),this.config.dirtyTracking){const e=e=>{const t=e.detail,i=t?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const o=this.#_.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#_.getOriginalRow(r),type:o?"modified":"pristine"})};this.gridElement.addEventListener("undo",e,{signal:t}),this.gridElement.addEventListener("redo",e,{signal:t}),this.on("row-inserted",e=>{const t=this.grid.getRowId(e.row);null!=t&&this.markAsNew(String(t))})}this.#c&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",e=>{const t=e.target;if(t!==this.gridElement&&t.matches(ke)){if(this.#S)return t.blur(),void this.gridElement.focus();const e=i._focusRow,n=i._focusCol,r=this.#A;if(!r||r.rowIndex!==e||r.colIndex!==n){const t=i._visibleColumns?.[n],r=i._rows?.[e];if(t?.field&&r){const i=t.field;this.#A={rowIndex:e,colIndex:n,field:i,value:r[i]}}}this.#E=!0}},{signal:t}),this.gridElement.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&(this.gridElement.contains(t)||this.grid.containsFocus?.(t))&&t.matches(ke)||(this.#E=!1,this.#A=null)},{signal:t}),this.gridElement.addEventListener("keydown",e=>{if("Escape"===e.key&&this.#E){if(Ie(this.config,e))return void queueMicrotask(()=>{if(this.#E){this.#D();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#E=!1,this.#S=!0}});this.#D();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#E=!1,this.#S=!0,e.preventDefault(),e.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",e=>{e.target.matches(ke)&&(this.#S=!1)},{signal:t}))}detach(){this.#h._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#p=-1,this.#f=void 0,this.#m=void 0,this.#w=-1,this.#b.clear(),this.#_.clear(),this.#v.clear(),this.#y.clear(),this.#E=!1,this.#S=!1,this.#A=null,this.#k=!1,super.detach()}handleQuery(e){if("isEditing"===e.type)return this.#c||-1!==this.#p}onCellClick(e){if(this.#c)return!1;const t=this.#h,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=>this.#g(e));if(!o)return!1;const s=t._rows[r],a=t.effectiveConfig?.rowEditable;return!(s&&a&&!a(s))&&(e.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(e){const t=this.#h;if("Escape"===e.key){if(this.#c&&this.#E){this.#D();const e=document.activeElement;return e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#E=!1,this.#S=!0,this.requestAfterRender(),!0}if(-1!==this.#p&&!this.#c)return Ie(this.config,e)||this.#F(this.#p,!0),!0}if(this.#c&&!this.#E&&("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key))return!1;if(this.#c&&this.#E&&("ArrowUp"===e.key||"ArrowDown"===e.key))return!0;if(("ArrowUp"===e.key||"ArrowDown"===e.key)&&-1!==this.#p&&!this.#c){if(Ie(this.config,e))return!0;const i=t._rows.length-1,n=this.#p;return this.#F(n,!1),"ArrowDown"===e.key?t._focusRow=Math.min(i,t._focusRow+1):t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault(),o(t),this.requestAfterRender(),!0}if("Tab"===e.key&&(-1!==this.#p||this.#c)){if(e.preventDefault(),this.#k)return this.#F(this.#p,!1),!0;const t=!e.shiftKey;return this.#q(t),!0}if(" "===e.key||"Spacebar"===e.key){if(-1!==this.#p)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&&o&&this.#u(r,o)&&"boolean"===r.type){const t=r.field;if(Ae(t)){const n=!o[t];return this.#T(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.#c&&!this.#E)return this.#M(),!0;if(-1!==this.#p)return!!Ie(this.config,e);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=>this.#g(e)),o=t._rows[n],s=t.effectiveConfig?.rowEditable,a=o&&s&&!s(o);if(i&&!a){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.#p||this.#c)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],o=t._rows[i];if(r&&o&&this.#u(r,o)&&r.field)return e.preventDefault(),this.beginCellEdit(i,r.field),!0}return!1}return!1}processColumns(e){const t=this.#h,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}processRows(e){const t=this.#h;if(this.config.dirtyTracking&&t.getRowId&&this.#_.capture(e,e=>{try{return t.getRowId?.(e)}catch{return}}),-1===this.#p||this.#c)return e;const i=this.#f,n=this.#m;if(!i||!n)return e;const r=[...e];let o=-1;for(let s=0;s<r.length;s++)try{if(t.getRowId?.(r[s])===i){o=s;break}}catch{}return-1===o?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[o]=n,this.#p!==o&&this.#G(this.#p,o),r)}afterRender(){const e=this.#h;if(-1!==this.#p&&this.#m&&!this.#c&&e._rows[this.#p]!==this.#m){const t=e._rows.indexOf(this.#m);if(-1===t)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#G(this.#p,t)}if(this.#x&&(this.#x=!1,this.#P(e)),-1!==this.#C){const t=this.#C;this.#C=-1,e.animateRow?.(t,"change")}const t=this.#_.drainCapturedFlag();if(null!=t&&this.emit("baselines-captured",{count:t}),!this.#c&&0!==this.#v.size)for(const i of this.#v){const[t,n]=i.split(":"),r=parseInt(t,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.#H(l,r,d,o,a,!0)}}afterCellRender(e){const{row:t,rowIndex:i,column:n,colIndex:r,cellElement:o}=e,s=this.#u(n,t);s?o.removeAttribute("aria-readonly"):o.setAttribute("aria-readonly","true"),this.#c&&s&&(o.classList.contains("editing")||this.#H(t,i,n,r,o,!0))}afterRowRender(e){if(!this.config.dirtyTracking)return;const t=this.#h,i=t.getRowId?.(e.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:o}=this.#_.getRowDirtyState(i,e.row),s=e.rowElement;if(s.classList.toggle("tbw-row-dirty",r),s.classList.toggle("tbw-row-new",n),o){const t=s.querySelectorAll(".cell[data-field]");for(let n=0;n<t.length;n++){const r=t[n],o=r.getAttribute("data-field");o&&r.classList.toggle("tbw-cell-dirty",this.#_.isCellDirty(i,e.row,o))}}else{const e=s.querySelectorAll(".tbw-cell-dirty");for(let t=0;t<e.length;t++)e[t].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#_.getChangedRows(e=>this.grid.getRow(e))}get changedRowIds(){return this.#_.getChangedRowIds()}get activeEditRow(){return this.#p}get activeEditCol(){return this.#w}isRowEditing(e){return this.#p===e}isCellEditing(e,t){return this.#v.has(`${e}:${t}`)}isRowChanged(e){const t=this.#h,i=t._rows[e];if(!i)return!1;try{const e=t.getRowId?.(i);return!!e&&this.#_.isRowChanged(e)}catch{return!1}}isRowChangedById(e){return this.#_.isRowChanged(e)}isDirty(e){if(!this.config.dirtyTracking)return!1;if(this.#_.newRowIds.has(e))return!0;const t=this.grid.getRow(e);return!!t&&this.#_.isRowDirty(e,t)}isPristine(e){return!this.isDirty(e)}get dirty(){if(!this.config.dirtyTracking)return!1;const e=this.#h;return this.#_.hasAnyDirty(t=>e._getRowEntry(t)?.row)}get pristine(){return!this.dirty}markAsPristine(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&(this.#_.markPristine(e,t),this.emit("dirty-change",{rowId:e,row:t,original:t,type:"pristine"}))}markAsNew(e){if(!this.config.dirtyTracking)return;this.#_.markNew(e);const t=this.grid.getRow(e);this.emit("dirty-change",{rowId:e,row:t,original:void 0,type:"new"})}markAsDirty(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&(this.#_.markDirty(e),this.emit("dirty-change",{rowId:e,row:t,original:this.#_.getOriginalRow(e),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const e=this.#h;this.#_.markAllPristine(t=>e._getRowEntry(t)?.row)}getOriginalRow(e){if(this.config.dirtyTracking)return this.#_.getOriginalRow(e)}hasBaseline(e){return!!this.config.dirtyTracking&&this.#_.hasBaseline(e)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const e=this.#h;return this.#_.getDirtyRows(t=>e._getRowEntry(t)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const e=this.#h;return this.#_.getDirtyRowIds(t=>e._getRowEntry(t)?.row)}revertRow(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&this.#_.revertRow(e,t)&&(this.emit("dirty-change",{rowId:e,row:t,original:this.#_.getOriginalRow(e),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const e=this.#h;this.#_.revertAll(t=>e._getRowEntry(t)?.row),this.requestRender()}setInvalid(e,t,i=""){this.#R.setInvalid(e,t,i)}clearInvalid(e,t){this.#R.clearInvalid(e,t)}clearRowInvalid(e){this.#R.clearRowInvalid(e)}clearAllInvalid(){this.#R.clearAllInvalid()}isCellInvalid(e,t){return this.#R.isCellInvalid(e,t)}getInvalidMessage(e,t){return this.#R.getInvalidMessage(e,t)}hasInvalidCells(e){return this.#R.hasInvalidCells(e)}getInvalidFields(e){return this.#R.getInvalidFields(e)}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#_.changedRowIds.clear(),this.#_.committedDirtyRowIds.clear(),this.#N(),e||this.emit("changed-rows-reset",{rows:t,ids:i});const n=this.#h;n._rowPool?.forEach(e=>e.classList.remove("changed"))}beginCellEdit(e,t){const i=this.#h,n=i._visibleColumns.findIndex(e=>e.field===t);if(-1===n)return;const r=i._visibleColumns[n],o=i._rows[e];if(!r||!o||!this.#u(r,o))return;const s=i.findRenderedRowElement?.(e),a=s?.querySelector(`.cell[data-col="${n}"]`);a&&(this.#k=!0,this.#z(e,n,a))}beginBulkEdit(e){const t=this.#h;if(!1===(this.config.editOn??t.effectiveConfig?.editOn))return;const i=t._columns?.some(e=>this.#g(e));if(!i)return;const n=t.findRenderedRowElement?.(e);if(!n)return;const r=t._rows[e],o=t.effectiveConfig?.rowEditable;r&&o&&!o(r)||(this.#k=!1,this.#K(e,r),Array.from(n.children).forEach((i,n)=>{const o=t._visibleColumns[n];if(o&&this.#u(o,r)){const t=i;t.classList.contains("editing")||this.#H(r,e,o,n,t,!0)}}),setTimeout(()=>{let e=n.querySelector(`.cell[data-col="${t._focusCol}"]`);if(e?.classList.contains("editing")||(e=n.querySelector(".cell.editing")),e?.classList.contains("editing")){const t=e.querySelector(ke);try{t?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#p&&this.#F(this.#p,!1)}cancelActiveRowEdit(){-1!==this.#p&&this.#F(this.#p,!0)}#L(e,t,i){const n=this.#h,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.#R.getInvalidMessage(e,t);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#G(e,t){this.#p=t;const i=/* @__PURE__ */new Set,n=`${e}:`;for(const s of this.#v)s.startsWith(n)?i.add(`${t}:${s.substring(n.length)}`):i.add(s);this.#v.clear();for(const s of i)this.#v.add(s);const r=this.#b.get(e);void 0!==r&&(this.#b.delete(e),this.#b.set(t,r));const o=[];for(const[s,a]of this.#y)s.startsWith(n)&&(o.push([`${t}:${s.substring(n.length)}`,a]),this.#y.delete(s));for(const[s,a]of o)this.#y.set(s,a);this.#N()}#z(e,t,i){const n=this.#h,r=n._rows[e],o=n._visibleColumns[t];r&&o&&this.#u(o,r)&&(i.classList.contains("editing")||(this.#p!==e&&this.#K(e,r),this.#w=t,this.#H(r,e,o,t,i,!1)))}#D(){const e=this.#A;if(!e)return;const t=this.#h,i=t._rows?.[e.rowIndex];i&&(i[e.field]=e.value);const n=`${e.rowIndex}:${e.field}`,r=this.#y.get(n);r&&r(e.value),this.emit("cell-cancel",{rowIndex:e.rowIndex,colIndex:e.colIndex,field:e.field,previousValue:e.value}),this.#A=null}#M(){const e=this.#h,t=e._focusRow,i=e._focusCol;if(t<0||i<0)return;const n=e.findRenderedRowElement?.(t),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const e=r.querySelector(ke);e&&(this.#S=!1,e.focus(),this.#E=!0,e instanceof HTMLInputElement&&("text"===e.type||"number"===e.type)&&e.select())}}#q(e){const t=this.#h,i=t._rows,n=this.#c?t._focusRow:this.#p,r=i[n],s=t._visibleColumns.map((e,t)=>r&&this.#u(e,r)?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?.(n),i=e?.querySelector(`.cell[data-col="${s[a]}"]`);if(i?.classList.contains("editing")){const e=i.querySelector(ke);e?.focus({preventScroll:!0})}return void o(t,{forceHorizontalScroll:!0})}const l=n+(e?1:-1);if(l>=0&&l<i.length){const r=i[l],s=t._visibleColumns.map((e,t)=>r&&this.#u(e,r)?t:-1).filter(e=>e>=0);if(0===s.length)return;this.#c?(t._focusRow=l,t._focusCol=e?s[0]:s[s.length-1],o(t,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const e=t.findRenderedRowElement?.(l),i=e?.querySelector(`.cell[data-col="${t._focusCol}"]`);if(i?.classList.contains("editing")){const e=i.querySelector(ke);e?.focus({preventScroll:!0})}},0)):(this.#F(n,!1),t._focusRow=l,t._focusCol=e?s[0]:s[s.length-1],this.beginBulkEdit(l),o(t,{forceHorizontalScroll:!0}))}}#N(){const e=this.#h;e._activeEditRows=this.#p,e._rowEditSnapshots=this.#b}#K(e,t){if(this.#p!==e){-1!==this.#p&&this.#F(this.#p,!1),this.#b.set(e,{...t}),this.#p=e,this.#m=t;const i=this.#h;try{this.#f=i.getRowId?.(t)??void 0}catch{this.#f=void 0}this.#N(),this.#c||this.emit("edit-open",{rowIndex:e,rowId:this.#f??"",row:t})}}#F(e,t){if(this.#p!==e)return;const i=this.#h,n=this.#b.get(e),r=i.findRenderedRowElement?.(e);let o=this.#f;const s=o?i._getRowEntry(o):void 0,a=s?.row??this.#m??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=ve(o,r,i);i!==n&&this.#T(e,r,n,a)}})}if(t||this.#c||!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.#_.changedRowIds.delete(o),this.#_.committedDirtyRowIds.delete(o),this.clearRowInvalid(o));else if(!t&&a){const t=function(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}(n,a),i=o?this.#_.changedRowIds.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.#_.changedRowIds.delete(o),this.#_.committedDirtyRowIds.delete(o),this.clearRowInvalid(o))):r||(o&&this.config.dirtyTracking&&(this.#_.isRowDirty(o,a)?this.#_.committedDirtyRowIds.add(o):this.#_.committedDirtyRowIds.delete(o)),t&&this.isAnimationEnabled&&(this.#C=e))}this.#b.delete(e),this.#p=-1,this.#f=void 0,this.#m=void 0,this.#w=-1,this.#k=!1,this.#N();for(const l of this.#v)l.startsWith(`${e}:`)&&this.#v.delete(l);for(const l of this.#y.keys())l.startsWith(`${e}:`)&&this.#y.delete(l);this.#x=!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.#P(i),this.#x=!1),!this.#c&&a&&this.emit("edit-close",{rowIndex:e,rowId:o??"",row:a,reverted:t})}#T(e,t,i,n){const r=t.field;if(!Ae(r))return;const o=n[r];if(o===i)return;const s=this.#h;let a;try{a=this.grid.getRowId(n)}catch{}const l=!a||!this.#_.changedRowIds.has(a),d=a?e=>this.grid.updateRow(a,e,"cascade"):_e;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;if(a&&!c&&this.isCellInvalid(a,r)&&this.clearInvalid(a,r),n[r]=i,a&&this.#_.changedRowIds.add(a),this.#N(),this.config.dirtyTracking&&a){const e=this.#_.isRowDirty(a,n);this.emit("dirty-change",{rowId:a,row:n,original:this.#_.getOriginalRow(a),type:e?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:r,oldValue:o,newValue:i});const h=s.findRenderedRowElement?.(e);h&&h.classList.add("changed")}#H(e,t,i,n,r,o){Le(this.#I,e,t,i,n,r,o)}#P(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 Fe(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 Me(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 De(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}class qe extends i{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=U(this.columns,t?.columns,i.onlyVisible);let o;if(t?.rowIndices)o=Y(this.rows,t.rowIndices);else if(i.onlySelected){const e=this.getSelectionState();o=e?.selected?.size?Y(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 Fe(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)),Fe(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){Me(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">${De(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=De(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`;Me(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`;Me(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 Ge="(Blank)";function Pe(e){if(e instanceof Date)return e.getTime();const t=Number(e);if(!isNaN(t))return t;return new Date(e).getTime()}function He(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(Ge):!o.some(t=>e.includes(t)))}if("in"===t.operator){const e=t.value;return!!Array.isArray(e)&&(0===o.length?e.includes(Ge):o.some(t=>e.includes(t)))}}if("notIn"===t.operator)return null==r||""===r?!Array.isArray(t.value)||!t.value.includes(Ge):Array.isArray(t.value)&&!t.value.includes(r);if("in"===t.operator)return null==r||""===r?Array.isArray(t.value)&&t.value.includes(Ge):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 Pe(r)<Pe(t.value);case"lessThanOrEqual":return Pe(r)<=Pe(t.value);case"greaterThan":return Pe(r)>Pe(t.value);case"greaterThanOrEqual":return Pe(r)>=Pe(t.value);case"between":return Pe(r)>=Pe(t.value)&&Pe(r)<=Pe(t.valueTo);default:return!0}}(e,t,i,n?.get(t.field)))):e}function Ne(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(Ge),[...n].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t)))}function ze(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(Ge),n.set(r,[...o].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t))));return n}const Ke="__tbw_expander";function Oe(e){return e.field===Ke}function Ve(e){return!0===e.meta?.utility}function Be(e){return e?e.toISOString().split("T")[0]:""}function $e(e){return e?"string"==typeof e?e:"number"==typeof e?Be(new Date(e)):"":""}function We(e,t,i,n,r,o){const{field:l,column:d}=t,c=function(e){if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-filter-item-height");if(t&&t.trim()){const e=parseFloat(t);if(!isNaN(e)&&e>0)return e}}return 28}(e),u=e=>{if(null==e)return"(Blank)";if(d.format&&!d.filterValue){const t=d.format(e,void 0);if(t)return t}return String(e)};i=i.slice().sort((e,t)=>u(e).localeCompare(u(t)));const h=document.createElement("div");h.className="tbw-filter-search";const g=document.createElement("input");g.type="text",g.placeholder="Search...",g.className="tbw-filter-search-input",g.value=o.get(l)??"",h.appendChild(g),e.appendChild(h);const p=document.createElement("div");p.className="tbw-filter-actions";const f=document.createElement("label");f.className="tbw-filter-value-item",f.style.padding="0",f.style.margin="0";const m=document.createElement("input");m.type="checkbox",m.className="tbw-filter-checkbox";const w=document.createElement("span");w.textContent="Select All",f.appendChild(m),f.appendChild(w),p.appendChild(f);const b=/* @__PURE__ */new Map;i.forEach(e=>{const t=null==e?"__null__":String(e);b.set(t,!n.has(e))});const v=()=>{const e=[...b.values()],t=e.every(e=>e),i=e.every(e=>!e);m.checked=t,m.indeterminate=!t&&!i};m.addEventListener("change",()=>{const e=m.checked;for(const t of b.keys())b.set(t,e);v(),S()}),v(),e.appendChild(p);const y=document.createElement("div");y.className="tbw-filter-values";const x=document.createElement("div");x.className="tbw-filter-values-spacer",y.appendChild(x);const C=document.createElement("div");C.className="tbw-filter-values-content",y.appendChild(C);let R=[];const E=(e,t)=>{const i=u(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=b.get(n)??!0,o.dataset.value=n,o.addEventListener("change",()=>{b.set(n,o.checked),v()});const s=document.createElement("span");return s.textContent=i,r.appendChild(o),r.appendChild(s),r},S=()=>{const e=R.length,t=y.clientHeight,i=y.scrollTop;if(x.style.height=e*c+"px",s(e,50/3))return C.innerHTML="",C.style.transform="translateY(0px)",void R.forEach((e,t)=>{C.appendChild(E(e,t))});const n=a({totalRows:e,viewportHeight:t,scrollTop:i,rowHeight:c,overscan:3});C.style.transform=`translateY(${n.offsetY}px)`,C.innerHTML="";for(let r=n.start;r<n.end;r++)C.appendChild(E(R[r],r-n.start))},k=e=>{const t=r.caseSensitive??!1,n=t?e:e.toLowerCase();if(R=i.filter(i=>{const r=u(i),o=t?r:r.toLowerCase();return!e||o.includes(n)}),0===R.length){x.style.height="0px",C.innerHTML="";const e=document.createElement("div");return e.className="tbw-filter-no-match",e.textContent="No matching values",void C.appendChild(e)}S()};let A;y.addEventListener("scroll",()=>{R.length>0&&S()},{passive:!0}),k(g.value),e.appendChild(y),g.addEventListener("input",()=>{clearTimeout(A),A=setTimeout(()=>{o.set(l,g.value),k(g.value)},r.debounceMs??150)});const _=document.createElement("div");_.className="tbw-filter-buttons";const I=document.createElement("button");I.className="tbw-filter-apply-btn",I.textContent="Apply",I.addEventListener("click",()=>{const e=[];for(const[t,n]of b)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)}),_.appendChild(I);const L=document.createElement("button");L.className="tbw-filter-clear-btn",L.textContent="Clear Filter",L.addEventListener("click",()=>{t.clearFilter()}),_.appendChild(L),e.appendChild(_)}function je(e,t){if("number"==typeof e)return e;if("string"==typeof e){const i=parseFloat(e);return isNaN(i)?t:i}return t}class Ue extends i{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;computeSelected(){const e={},t=[];for(const[i,n]of this.filters)if("set"===n.type)if("in"===n.operator&&Array.isArray(n.value))e[i]=n.value;else if("notIn"===n.operator){const e=this.grid.effectiveConfig?.columns?.find(e=>e.field===i);t.push({field:i,filterValue:e?.filterValue})}if(t.length>0){const i=ze(this.sourceRows,t);for(const{field:n}of t){const t=this.excludedValues.get(n),r=i.get(n)??[];e[n]=t?r.filter(e=>!t.has(e)):r}}return e}syncExcludedValues(e,t){if(t)if("set"===t.type&&"notIn"===t.operator&&Array.isArray(t.value))this.excludedValues.set(e,new Set(t.value));else if("set"===t.type&&"in"===t.operator&&Array.isArray(t.value)){const i=this.sourceRows;if(!i||0===i.length)return void this.excludedValues.delete(e);const n=t.value,r=new Set(n.map(e=>null==e?Ge:e)),o=this.getUniqueValues(e),s=new Set(o.filter(e=>!r.has(e)));this.excludedValues.set(e,s)}else"set"===t.type&&this.excludedValues.delete(e);else 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=He([...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),r?e.setAttribute("aria-description","Filtered"):e.removeAttribute("aria-description"),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"),e.setAttribute("aria-description","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,i){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)}if(this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,!i?.silent){this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.();const i=this.grid.effectiveConfig?.columns?.find(t=>t.field===e)?.header??e;l(this.gridElement,null===t?`Filter cleared from ${i}`:`Filter applied on ${i}`)}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,t){this.filters.clear(),this.excludedValues.clear();for(const i of e)this.filters.set(i.field,i),this.syncExcludedValues(i.field,i);this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,t?.silent||(this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.()),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}clearAllFilters(e){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal(e?.silent),e?.silent||l(this.gridElement,"All filters cleared")}clearFieldFilter(e,t){if(this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal(t?.silent),!t?.silent){const t=this.grid.effectiveConfig?.columns?.find(t=>t.field===e)?.header??e;l(this.gridElement,`Filter cleared from ${t}`)}}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 Ne(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=Ne(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){const r=this.filters.get(e);if("in"===r?.operator&&"set"===r.type&&Array.isArray(r.value)&&!this.excludedValues.has(e)){const t=r.value,i=new Set(t.map(e=>null==e?Ge:e)),o=new Set(n.filter(e=>!i.has(e)));this.excludedValues.set(e,o)}let o=this.excludedValues.get(e);o||(o=/* @__PURE__ */new Set,this.excludedValues.set(e,o));const s=this.searchText.get(e)??"",a={field:e,column:t,uniqueValues:n,excludedValues:o,searchText:s,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 l=!1;if(this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,a),l=i.children.length>0),!l&&t.type){const e=this.grid.effectiveConfig.typeDefaults?.[t.type];e?.filterPanelRenderer&&(e.filterPanelRenderer(i,a),l=i.children.length>0)}if(!l){const e=t.type;"number"===e?function(e,t,i,n){const{field:r,column:o}=t,s=o.filterParams,a=o.editorParams,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=je(s?.min??a?.min,d),h=je(s?.max??a?.max,c),g=s?.step??a?.step??1,p=n.get(r);let f=u,m=h;const w="blank"===p?.operator;"between"===p?.operator?(f=je(p.value,u),m=je(p.valueTo,h)):"greaterThanOrEqual"===p?.operator?f=je(p.value,u):"lessThanOrEqual"===p?.operator&&(m=je(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 R=document.createElement("div");R.className="tbw-filter-range-group";const E=document.createElement("label");E.textContent="Max",E.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),R.appendChild(E),R.appendChild(S),b.appendChild(R),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 I=document.createElement("input");I.type="range",I.className="tbw-filter-range-thumb tbw-filter-range-thumb-min",I.min=String(u),I.max=String(h),I.step=String(g),I.value=String(f);const L=document.createElement("input");L.type="range",L.className="tbw-filter-range-thumb tbw-filter-range-thumb-max",L.min=String(u),L.max=String(h),L.step=String(g),L.value=String(m),k.appendChild(A),k.appendChild(_),k.appendChild(I),k.appendChild(L),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,I.disabled=e,L.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 q=()=>{const e=parseFloat(I.value),t=parseFloat(L.value),i=h-u,n=(e-u)/i*100,r=(t-u)/i*100;_.style.left=`${n}%`,_.style.width=r-n+"%"};I.addEventListener("input",()=>{const e=Math.min(parseFloat(I.value),parseFloat(L.value));I.value=String(e),x.value=String(e),q()}),L.addEventListener("input",()=>{const e=Math.max(parseFloat(L.value),parseFloat(I.value));L.value=String(e),S.value=String(e),q()}),x.addEventListener("input",()=>{let e=parseFloat(x.value)||u;e=Math.max(u,Math.min(e,parseFloat(S.value))),I.value=String(e),q()}),S.addEventListener("input",()=>{let e=parseFloat(S.value)||h;e=Math.min(h,Math.max(e,parseFloat(x.value))),L.value=String(e),q()}),q();const G=document.createElement("div");G.className="tbw-filter-buttons";const P=document.createElement("button");P.className="tbw-filter-apply-btn",P.textContent="Apply",P.addEventListener("click",()=>{if(F.checked)return void t.applyTextFilter("blank","");const e=parseFloat(x.value),i=parseFloat(S.value);t.applyTextFilter("between",e,i)}),G.appendChild(P);const H=document.createElement("button");H.className="tbw-filter-clear-btn",H.textContent="Clear Filter",H.addEventListener("click",()=>{t.clearFilter()}),G.appendChild(H),e.appendChild(G)}(i,a,n,this.filters):"date"===e?function(e,t,i,n){const{field:r,column:o}=t,s=o.filterParams,a=o.editorParams,l=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())),d=l.length>0?new Date(Math.min(...l.map(e=>e.getTime()))):null,c=l.length>0?new Date(Math.max(...l.map(e=>e.getTime()))):null,u=$e(s?.min)||$e(a?.min)||Be(d),h=$e(s?.max)||$e(a?.max)||Be(c),g=n.get(r);let p="",f="";const m="blank"===g?.operator;"between"===g?.operator?(p=$e(g.value)||"",f=$e(g.valueTo)||""):"greaterThanOrEqual"===g?.operator?p=$e(g.value)||"":"lessThanOrEqual"===g?.operator&&(f=$e(g.value)||"");const w=document.createElement("div");w.className="tbw-filter-date-range";const b=document.createElement("div");b.className="tbw-filter-date-group";const v=document.createElement("label");v.textContent="From",v.className="tbw-filter-range-label";const y=document.createElement("input");y.type="date",y.className="tbw-filter-date-input",u&&(y.min=u),h&&(y.max=h),y.value=p,b.appendChild(v),b.appendChild(y),w.appendChild(b);const x=document.createElement("span");x.className="tbw-filter-range-separator",x.textContent="–",w.appendChild(x);const C=document.createElement("div");C.className="tbw-filter-date-group";const R=document.createElement("label");R.textContent="To",R.className="tbw-filter-range-label";const E=document.createElement("input");E.type="date",E.className="tbw-filter-date-input",u&&(E.min=u),h&&(E.max=h),E.value=f,C.appendChild(R),C.appendChild(E),w.appendChild(C),e.appendChild(w);const S=document.createElement("label");S.className="tbw-filter-blank-option";const k=document.createElement("input");k.type="checkbox",k.className="tbw-filter-blank-checkbox",k.checked=m;const A=document.createTextNode("Show only blank");S.appendChild(k),S.appendChild(A);const _=e=>{y.disabled=e,E.disabled=e,w.classList.toggle("tbw-filter-disabled",e)};_(m),k.addEventListener("change",()=>{_(k.checked)}),e.appendChild(S);const I=document.createElement("div");I.className="tbw-filter-buttons";const L=document.createElement("button");L.className="tbw-filter-apply-btn",L.textContent="Apply",L.addEventListener("click",()=>{if(k.checked)return void t.applyTextFilter("blank","");const e=y.value,i=E.value;e&&i?t.applyTextFilter("between",e,i):e?t.applyTextFilter("greaterThanOrEqual",e):i?t.applyTextFilter("lessThanOrEqual",i):t.clearFilter()}),I.appendChild(L);const T=document.createElement("button");T.className="tbw-filter-clear-btn",T.textContent="Clear Filter",T.addEventListener("click",()=>{t.clearFilter()}),I.appendChild(T),e.appendChild(I)}(i,a,n,this.filters):We(i,a,n,o,{caseSensitive:this.config.caseSensitive,debounceMs:this.config.debounceMs},this.searchText)}}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===Ue.supportsAnchorPositioning&&(Ue.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),Ue.supportsAnchorPositioning}positionPanel(e,t){const i=t.closest(".cell")??t;if(i.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=i,Ue.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"))})}applySetFilter(e,t,i){if(this.excludedValues.set(e,new Set(t)),0===t.length)this.filters.delete(e);else{const n=this.filters.get(e);if("in"===n?.operator){const n=this.getUniqueValues(e),r=new Set(t),o=n.filter(e=>!r.has(e));this.filters.set(e,{field:e,type:"set",operator:"in",value:o,...void 0!==i&&{valueTo:i}})}else 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(e){this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null;const t=[...this.filters.values()];if(this.config.filterHandler){this.gridElement.setAttribute("aria-busy","true");const i=this.config.filterHandler(t,this.sourceRows),n=i=>{this.gridElement.removeAttribute("aria-busy"),this.cachedResult=i,this.grid.rows=i,e||(this.emit("filter-change",{filters:t,filteredRowCount:i.length,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.()),this.emitPluginEvent("filter-applied",{filters:t}),this.requestRender()};return void(i&&"function"==typeof i.then?i.then(n):n(i))}e||(this.emit("filter-change",{filters:t,filteredRowCount:0,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.()),this.emitPluginEvent("filter-applied",{filters:t}),this.requestRender()}getColumnState(e){if(!this.config.trackColumnState)return;const t=this.filters.get(e);return t?{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}:void 0}applyColumnState(e,t){if(!this.config.trackColumnState)return;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 Ye(e){return e.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function Ze(e){return e.map(e=>e.id?e:(e.header||d(c,'ColumnGroupDefinition requires either an "id" or a "header" to generate an id from.'),{...e,id:Ye(e.header)}))}function Qe(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}function Xe(e,t){const i=e.columns[0],n=e.columns[e.columns.length-1],r=i?t.findIndex(e=>e.field===i.field):-1,o=n?t.findIndex(e=>e.field===n.field):-1;return-1!==r&&-1!==o?[r,o]:null}function Je(e,t){const i=/* @__PURE__ */new Set,n=[];for(const r of e){if(String(r.id).startsWith("__implicit__"))continue;const e=Xe(r,t);e&&n.push(e)}for(const r of e){if(!String(r.id).startsWith("__implicit__"))continue;const e=Xe(r,t);if(!e)continue;const[o,s]=e;n.some(([e,t])=>o>=e&&s<=t)&&i.add(String(r.id))}return i}class et extends i{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;#O=/* @__PURE__ */new Set;#V=[];#B=/* @__PURE__ */new Map;attach(e){super.attach(e),this.gridElement.addEventListener("column-move",this.#$,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#O.clear(),this.#V=[],this.#B.clear()}#$=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.#W(r,n))return t.preventDefault(),void this.#j(i);this.#U(n)};#U(e){this.#O.clear();const t=this.#Y(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.#O.add(n);break}}}#Y(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}#W(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}#j(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.#Z()}#Z(){let e;if(this.#V.length>0)e=this.#V.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 t=this.grid?.getColumnOrder();if(t&&t.length>0){const i=new Map(t.map((e,t)=>[e,t]));for(const t of e)t.fields.sort((e,t)=>(i.get(e)??1/0)-(i.get(t)??1/0))}return e}static detect(e,t){const i=t?.features?.groupingColumns;if(i&&"object"==typeof i&&Array.isArray(i.columnGroups)&&i.columnGroups.length>0)return!0;if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const n=t?.columns;return!!Array.isArray(n)&&function(e){return e.some(e=>null!=e.group)}(n)}processColumns(e){const t=this.config?.columnGroups,i=this.grid?.gridConfig?.columnGroups;let n,r;if(t&&Array.isArray(t)&&t.length>0?(i&&Array.isArray(i)&&i.length>0&&this.warn(u,"columnGroups defined in both gridConfig and groupingColumns feature config. Using feature config (higher precedence)."),n=t):i&&Array.isArray(i)&&i.length>0&&(n=i),n&&n.length>0){const t=Ze(n);this.#V=t,this.#B.clear();for(const e of t)e.renderer&&this.#B.set(e.id,e.renderer);const i=/* @__PURE__ */new Map;for(const e of t)for(const t of e.children)i.set(t,{id:e.id,label:e.header});r=e.map(e=>{const t=i.get(e.field);return t&&!e.group?{...e,group:t}:e})}else this.#V=[],this.#B.clear(),r=[...e];const o=Qe(r);if(0===o.length)return this.isActive=!1,this.groups=[],r;if(this.#B.size>0)for(const s of o){const e=this.#B.get(s.id);e&&(s.renderer=e)}this.isActive=!0,this.groups=o,this.#O.clear();for(const s of o){const e=s.columns[s.columns.length-1];e?.field&&this.#O.add(e.field)}return r}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=Qe(i);if(0===n.length)return;if(this.#B.size>0)for(const a of n){const e=this.#B.get(a.id);e&&(a.renderer=e)}this.#O.clear();const r=Je(n,i);for(let a=0;a<n.length;a++){const e=n[a];if(String(e.id).startsWith("__implicit__")&&r.has(String(e.id)))continue;const t=e.columns[e.columns.length-1];t?.field&&a<n.length-1&&this.#O.add(t.field)}const o=function(e,t,i){if(0===e.length)return null;const n=document.createElement("div");n.className="header-group-row",n.setAttribute("role","row");const r=Je(e,t);for(const o of e){const e=String(o.id),s=e.startsWith("__implicit__");if(s&&r.has(e))continue;const a=Xe(o,t);if(!a)continue;const[l,d]=a,c=d-l+1,u=s?"":o.label||o.id,h=document.createElement("div");h.className="cell header-group-cell",s&&h.classList.add("implicit-group"),h.setAttribute("data-group",e),h.style.gridColumn=`${l+1} / span ${c}`;const g=!s&&(o.renderer||i)||void 0;if(g&&!s){const t=g({id:e,label:String(u),columns:o.columns,firstIndex:l,isImplicit:!1});t instanceof HTMLElement?h.appendChild(t):"string"==typeof t?h.innerHTML=t:h.textContent=u}else h.textContent=u;n.appendChild(h)}return n}(n,i,this.config.groupHeaderRenderer);if(o){o.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(o,t):e.appendChild(o)}const s=e.querySelector(".header-row");s&&(s.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,t,i){if(!t.length||!e)return;const n=Je(t,i),r=/* @__PURE__ */new Map;for(const s of t)if(!String(s.id).startsWith("__implicit__")||!n.has(String(s.id)))for(const e of s.columns)e.field&&r.set(e.field,s.id);const o=Array.from(e.querySelectorAll(".cell[data-field]"));o.forEach(e=>{const t=e.getAttribute("data-field")||"",i=r.get(t);i&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",i))});for(const s of t){if(String(s.id).startsWith("__implicit__")&&n.has(String(s.id)))continue;const e=s.columns[s.columns.length-1],t=o.find(t=>t.getAttribute("data-field")===e.field);t&&t.classList.add("group-end")}}(s,n,i))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#O.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 tt({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 it extends i{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=tt({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{w as e,C as t,BaseGridPlugin as i,DEFAULT_GRID_ICONS as n,E as r,e as o,s,c as a,a as l,t as d,b as c,d as u,runAggregator as h,f as g,g as p,h as f,r as m,getAggregator as w,getValueAggregator as b,P as v,i as y,j as x,k as C,l as R,M as E,m as S,n as k,F as A,T as _,N as I}from"./index.js";import{DEFAULT_ANIMATION_CONFIG as L,DGEvents as T,DataGridElement as F,FitModeEnum as M,GridCSSVars as D,GridClasses as q,GridDataAttrs as G,DataGridElement as P,GridSelectors as H,PLUGIN_QUERIES as N,PluginEvents as z,PluginManager as K,RenderPhase as O,builtInSort as V,createGrid as B,defaultComparator as $,queryGrid as W,setFeatureResolver as j}from"./index.js";function U(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 Y(e,t){return t?.length?[...t].sort((e,t)=>e-t).map(t=>e[t]).filter(e=>null!=e):e}function Z(e){return null==e?"":e instanceof Date?e.toISOString():"object"==typeof e?JSON.stringify(e):String(e)}function Q(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 X(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 J extends i{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=Q(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??X)(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=U(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=U(this.visibleColumns.slice(n,r+1))}else i=U(this.columns);if(e?.rowIndices)n=Y(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):Z(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(i){const{columns:n,rows:r}=this.#o(i);if(0===n.length||0===r.length)return"";const o=this.#s(n,r,i);return await async function(i){try{return await navigator.clipboard.writeText(i),!0}catch(n){e(t,`Clipboard API failed: ${n}`);const r=document.createElement("textarea");r.value=i,r.style.position="fixed",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r),r.select();const o=document.execCommand("copy");return document.body.removeChild(r),o}}(o),this.lastCopied={text:o,timestamp:Date.now()},this.emit("copy",{text:o,rowCount:r.length,columnCount:n.length}),o}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?Q(e,this.config):null}getLastCopied(){return this.lastCopied}}function ee(e){if(null==e)return 100;if("number"==typeof e)return e;const t=parseFloat(e);return isNaN(t)?100:t}function te(e){return e.map(e=>ee(e.width))}function ie(e){const t=[];let i=0;for(const n of e)t.push(i),i+=ee(n.width);return t}function ne(e){return e.reduce((e,t)=>e+ee(t.width),0)}function re(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 oe extends i{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=te(t),this.columnOffsets=ie(t),this.totalWidth=ne(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=te(e),this.columnOffsets=ie(e),this.totalWidth=ne(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=re(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,i=this.gridElement;i&&(i.scrollLeft=t)}getColumnOffset(e){return this.columnOffsets[e]??0}getTotalWidth(){return this.totalWidth}}const se="@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 ae(e,t){return("function"==typeof e?e(t):e).filter(e=>!0!==e.hidden&&("function"!=typeof e.hidden||!e.hidden(t)))}function le(e,t){return!0===e.disabled||"function"==typeof e.disabled&&e.disabled(t)}function de(e,t,i,r=n.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 n of e){if(n.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",n.cssClass&&e.classList.add(n.cssClass),e.setAttribute("role","menuitem"),e.setAttribute("data-id",n.id),e.setAttribute("tabindex","-1");const a=le(n,t);if(a&&(e.classList.add("disabled"),e.setAttribute("aria-disabled","true")),n.icon){const t=document.createElement("span");t.className="tbw-context-menu-icon",t.innerHTML=n.icon,e.appendChild(t)}else if(s){const t=document.createElement("span");t.className="tbw-context-menu-icon",t.innerHTML="&nbsp;",e.appendChild(t)}const l=document.createElement("span");if(l.className="tbw-context-menu-label",l.textContent=n.name,e.appendChild(l),n.shortcut){const t=document.createElement("span");if(t.className="tbw-context-menu-shortcut",Array.isArray(n.shortcut))n.shortcut.forEach((e,i)=>{i>0&&t.appendChild(document.createTextNode("+"));const n=document.createElement("kbd");n.textContent=e,t.appendChild(n)});else{const e=document.createElement("kbd");e.textContent=n.shortcut,t.appendChild(e)}e.appendChild(t)}if(n.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(!n.subMenu)return;const o=de(ae(n.subMenu,t),t,i,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||!n.action||n.subMenu||e.addEventListener("click",e=>{e.stopPropagation(),i(n)}),o.appendChild(e)}return o}const ce="getContextMenuItems";let ue=null,he=null,ge=0;const pe=[{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 fe extends i{static manifest={queries:[{type:ce,description:"Collects context menu items from other plugins for header right-click menus"}]};name="contextMenu";get defaultConfig(){return{items:pe}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;attach(e){super.attach(e),this.installGlobalHandlers(),ge++}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 fe.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(){if(!he&&"undefined"!=typeof document&&se&&(he=document.createElement("style"),he.id="tbw-context-menu-styles",he.textContent=se,document.head.appendChild(he)),!ue){ue=new AbortController;const e=ue.signal,t=()=>{document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove())};document.addEventListener("click",t,{signal:e}),document.addEventListener("keydown",e=>{"Escape"===e.key&&t()},{signal:e}),document.addEventListener("scroll",t,{capture:!0,signal:e})}}uninstallGlobalHandlers(){ge--,ge>0||(ue&&(ue.abort(),ue=null),he&&(he.remove(),he=null))}collectPluginItems(e){if(!this.grid)return[];const t=this.grid.query(ce,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}))}openMenuAt(e,t,i,n=!1){this.params=e,this.position={x:t,y:i};const r=this.collectPluginItems(e);let o=ae(this.config.items??pe,e);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]}var s,a;(o=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}(o),o.length)&&(document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove()),this.menuElement=null,this.menuElement=de(o,e,t=>{t.action&&t.action(e),this.menuElement?.remove(),this.menuElement=null,this.isOpen=!1},this.gridIcons.submenuArrow),s=this.menuElement,a=()=>this.hideMenu(),s.addEventListener("keydown",e=>{const t=Array.from(s.querySelectorAll('[role="menuitem"]:not(.disabled)'));if(!t.length)return;const i=document.activeElement,n=t.indexOf(i);switch(e.key){case"ArrowDown":e.preventDefault(),t[n<t.length-1?n+1:0].focus();break;case"ArrowUp":e.preventDefault(),t[n>0?n-1:t.length-1].focus();break;case"Enter":case" ":e.preventDefault(),i&&t.includes(i)&&i.click();break;case"Escape":e.preventDefault(),a()}}),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),function(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"}(this.menuElement,t,i),this.isOpen=!0,n&&function(e){const t=e.querySelector('[role="menuitem"]:not(.disabled)');t?.focus()}(this.menuElement),this.emit("context-menu-open",{params:e,items:o}))}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.openMenuAt(o,t.clientX,t.clientY)}))}onKeyDown(e){const t="F10"===e.key&&e.shiftKey,i="ContextMenu"===e.key;if(!t&&!i)return;e.preventDefault();const n=this.grid;if(!n)return;const r=n._focusRow,o=n._focusCol,s=this.visibleColumns[o],a=this.rows[r],l=this.gridElement,d=l?.querySelector(`[data-row="${r}"][data-col="${o}"]`);let c=0,u=0;if(d){const e=d.getBoundingClientRect();c=e.left+e.width/2,u=e.bottom}const h=this.syncSelectionOnContextMenu(r),g={row:a,rowIndex:r,column:s,columnIndex:o,field:s?.field??"",value:a?.[s?.field]??null,isHeader:!1,event:e,selectedRows:h};return this.openMenuAt(g,c,u,!0),!0}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??[]};this.openMenuAt(n,e,t)}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null,this.isOpen=!1)}isMenuOpen(){return this.isOpen}}function me(e){return t=>{const i=e.editorParams,n=document.createElement("input");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);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof t.value?t.commit(n.value):t.commit(n.valueAsDate);else if(e.nullable)t.commit(null);else{const e=i?.default;"string"==typeof t.value||"string"==typeof e?t.commit("string"==typeof e?e:`${(r=e??/* @__PURE__ */new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):t.commit(e instanceof Date?e:/* @__PURE__ */new Date)}}),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}const we="__tbw_null__";function be(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=()=>{""===n.value?e.nullable?t.commit(null):t.commit(i?.min??0):t.commit(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 me(e);case"select":return function(e){return t=>{const i=e.editorParams,n=document.createElement("select");if(e.multi&&(n.multiple=!0),e.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=e.nullable?we:"",r.textContent=e.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==t.value&&(r.selected=!0),n.appendChild(r)}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 e.nullable&&n.value===we?t.commit(null):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 i=n.value;""!==i?"string"==typeof t.value&&i===t.value.replace(/[\n\r]/g,"")||("number"==typeof t.value?t.commit(Number(i)):t.commit(i)):e.nullable?t.commit(null):t.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",e=>{"Enter"===e.key&&r(),"Escape"===e.key&&t.cancel()}),n}}(e)}}function ve(e,t,i){if(e instanceof HTMLInputElement){if("checkbox"===e.type)return e.checked;if("number"===e.type){if(""===e.value){if(t?.nullable)return null;const e=t?.editorParams;return e?.min??0}return Number(e.value)}if("date"===e.type)return e.value?"string"==typeof i?e.value:e.valueAsDate:t?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date;if("number"==typeof i){if(""===e.value){if(t?.nullable)return null;const e=t?.editorParams;return e?.min??0}return Number(e.value)}return""===e.value&&null==i?t?.nullable?null:"":"string"==typeof i&&e.value===i.replace(/[\n\r]/g,"")?i:e.value}return"number"===t?.type&&""!==e.value||"number"==typeof i&&""!==e.value?Number(e.value):null==i&&""===e.value?t?.nullable?null:"":e.value}class ye{#l=/* @__PURE__ */new Map;#d;constructor(e){this.#d=e}setInvalid(e,t,i=""){let n=this.#l.get(e);n||(n=/* @__PURE__ */new Map,this.#l.set(e,n)),n.set(t,i),this.#d(e,t,!0)}clearInvalid(e,t){const i=this.#l.get(e);i&&(i.delete(t),0===i.size&&this.#l.delete(e)),this.#d(e,t,!1)}clearRowInvalid(e){const t=this.#l.get(e);if(t){const i=Array.from(t.keys());this.#l.delete(e),i.forEach(t=>this.#d(e,t,!1))}}clearAllInvalid(){const e=Array.from(this.#l.entries());this.#l.clear(),e.forEach(([e,t])=>{t.forEach((t,i)=>this.#d(e,i,!1))})}isCellInvalid(e,t){return this.#l.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#l.get(e)?.get(t)}hasInvalidCells(e){const t=this.#l.get(e);return!!t&&t.size>0}getInvalidFields(e){return new Map(this.#l.get(e)??[])}}function xe(e,t,i){const n=e.get(t);return!!n&&!Ce(n,i)}function Ce(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(typeof e!=typeof t)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!Ce(e[i],t[i]))return!1;return!0}if("object"==typeof e){const i=e,n=t,r=Object.keys(i),o=Object.keys(n);if(r.length!==o.length)return!1;for(const e of r)if(!Ce(i[e],n[e]))return!1;return!0}return!1}function Re(e,t,i){e.set(t,structuredClone(i))}function Ee(e,t,i){const n=e.get(t);if(!n)return!1;const r=n,o=i;for(const s of Object.keys(r))o[s]=r[s];return!0}class Se{baselines=/* @__PURE__ */new Map;baselinesWereCaptured=!1;newRowIds=/* @__PURE__ */new Set;changedRowIds=/* @__PURE__ */new Set;committedDirtyRowIds=/* @__PURE__ */new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(e,t){const i=this.baselines.size;!function(e,t,i){for(const n of t)try{const t=i(n);null==t||e.has(t)||e.set(t,structuredClone(n))}catch{}}(this.baselines,e,t),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(e,t){return xe(this.baselines,e,t)}hasAnyDirty(e){if(this.newRowIds.size>0)return!0;for(const[t]of this.baselines){const i=e(t);if(i&&xe(this.baselines,t,i))return!0}return!1}isCellDirty(e,t,i){return function(e,t,i,n){const r=e.get(t);return!!r&&!Ce(r[n],i[n])}(this.baselines,e,t,i)}getRowDirtyState(e,t){const i=this.newRowIds.has(e);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(e)&&xe(this.baselines,e,t),hasBaseline:this.baselines.has(e)}}markPristine(e,t){Re(this.baselines,e,t),this.newRowIds.delete(e),this.changedRowIds.delete(e),this.committedDirtyRowIds.delete(e)}markNew(e){this.newRowIds.add(e),this.committedDirtyRowIds.add(e)}markDirty(e){this.changedRowIds.add(e),this.committedDirtyRowIds.add(e)}markAllPristine(e){for(const[t]of this.baselines){const i=e(t);i&&Re(this.baselines,t,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(e){return function(e,t){const i=e.get(t);return i?structuredClone(i):void 0}(this.baselines,e)}hasBaseline(e){return this.baselines.has(e)}getDirtyRows(e){const t=[];for(const[i,n]of this.baselines){const r=e(i);r&&xe(this.baselines,i,r)&&t.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=e(i);n&&t.push({id:i,original:void 0,current:n})}return t}getDirtyRowIds(e){const t=[];for(const[i]of this.baselines){const n=e(i);n&&xe(this.baselines,i,n)&&t.push(i)}for(const i of this.newRowIds)t.push(i);return t}revertRow(e,t){const i=Ee(this.baselines,e,t);return i&&(this.changedRowIds.delete(e),this.committedDirtyRowIds.delete(e)),i}revertAll(e){for(const[t]of this.baselines){const i=e(t);i&&Ee(this.baselines,t,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(e){const t=[];for(const i of this.changedRowIds){const n=e(i);n&&t.push(n)}return t}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(e){return this.changedRowIds.has(e)}}const ke='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function Ae(e){return"string"==typeof e&&("__proto__"!==e&&"constructor"!==e&&"prototype"!==e)}function _e(e){}function Ie(e,t){return!1===e.onBeforeEditClose?.(t)}function Le(t,i,n,o,s,a,l,d){if(!o.editable)return;if(a.classList.contains("editing"))return;const{grid:c,isGridMode:u,config:h,editingCells:g,editorValueCallbacks:p}=t;let f;try{f=c.getRowId?.(i)}catch{}const m=f?e=>c.updateRow(f,e,"cascade"):_e,w=Ae(o.field)?i[o.field]:void 0;a.classList.add("editing"),g.add(`${n}:${s}`);const b=d??a.parentElement;b&&function(e){const t=(e.__editingCellCount??0)+1;e.__editingCellCount=t,e.setAttribute("data-has-editing","")}(b);let v=!1;const y=e=>{if(v||!u&&!t.isEditSessionActive())return;const r=f?c._getRowEntry(f):void 0,s=r?.row??i,a=r?.index??n;t.commitCellValue(a,o,e,s)},x=()=>{if(v=!0,Ae(o.field)){const e=f?c._getRowEntry(f):void 0;(e?.row??i)[o.field]=w}},C=document.createElement("div");C.className="tbw-editor-host",a.innerHTML="",a.appendChild(C),C.addEventListener("keydown",e=>{if("Enter"===e.key){if(u){e.stopPropagation(),e.preventDefault();const t=C.querySelector("input,textarea,select");return void(t&&y(ve(t,o,w)))}if(Ie(h,e))return;e.stopPropagation(),e.preventDefault(),v=!0,t.exitRowEdit(n,!1)}if("Escape"===e.key){if(u)return e.stopPropagation(),void e.preventDefault();if(Ie(h,e))return;e.stopPropagation(),e.preventDefault(),x(),t.exitRowEdit(n,!0)}});const R=o,E=R.__editorTemplate,S=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}}(c,R)??be(o),k=w,A=`${n}:${o.field}`,_=[];p.set(A,e=>{for(const t of _)t(e)});const I=e=>{_.push(e)};if("template"===S&&E)!function(e,t,i,n,r,o,s,a,l){const d=i.__editorTemplate;if(!d)return;const c=d.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:n,value:r,field:i.field,column:i,commit:o,cancel:s}):c.querySelectorAll("*").forEach(e=>{1===e.childNodes.length&&e.firstChild?.nodeType===Node.TEXT_NODE&&(e.textContent=e.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(e,t)=>{if(!Ae(t))return"";const i=n[t];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!r:h.value=String(r??"");let t=!1;h.addEventListener("blur",()=>{t||o(ve(h,i,r))}),h.addEventListener("keydown",n=>{const a=n;if("Enter"===a.key){if(Ie(e.config,a))return;a.stopPropagation(),a.preventDefault(),t=!0,o(ve(h,i,r)),e.exitRowEdit(l,!1)}if("Escape"===a.key){if(Ie(e.config,a))return;a.stopPropagation(),a.preventDefault(),s(),e.exitRowEdit(l,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>o(h.checked)),a||setTimeout(()=>h.focus({preventScroll:!0}),0)}t.appendChild(c)}(t,C,R,i,w,y,x,l,n),I(e=>{if(null!=e&&"object"==typeof e)return;const t=C.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if("string"==typeof S){const e=document.createElement(S);e.value=k,e.addEventListener("change",()=>y(e.value)),I(t=>{e.value=t}),C.appendChild(e),l||queueMicrotask(()=>{const e=C.querySelector(ke);e?.focus({preventScroll:!0})})}else if("function"==typeof S){const e=S({row:i,rowId:f??"",value:k,field:o.field,column:o,commit:y,cancel:x,updateRow:m,onValueChange:I});if("string"==typeof e)C.innerHTML=e,function(e,t,i,n){const r=e.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(ve(r,t,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(ve(r,t,n))))}(C,o,y,w),I(e=>{const t=C.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if(e instanceof Node){C.appendChild(e);e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?I(t=>{e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??"")}):a.setAttribute("data-editor-managed","")}else!e&&C.hasChildNodes()&&a.setAttribute("data-editor-managed","");l||queueMicrotask(()=>{const e=C.querySelector(ke);e?.focus({preventScroll:!0})})}else if(S&&"object"==typeof S){const n=document.createElement("div");n.setAttribute("data-external-editor",""),n.setAttribute("data-field",o.field),C.appendChild(n),a.setAttribute("data-editor-managed","");const s={row:i,rowId:f??"",value:k,field:o.field,column:o,commit:y,cancel:x,updateRow:m,onValueChange:I};if(S.mount)try{S.mount({placeholder:n,context:s,spec:S})}catch(L){e(r,`External editor mount error for column '${o.field}': ${L}`,t.grid.id)}else c.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:n,spec:S,context:s}}))}}class Te extends i{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>!0===e||"function"==typeof e},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],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#c(){return"grid"===this.config.mode}#u(e,t){const i=this.#h.effectiveConfig?.rowEditable;if(i&&!i(t))return!1;const{editable:n}=e;return"function"==typeof n?n(t):!0===n}#g(e){return!0===e.editable||"function"==typeof e.editable}#p=-1;#f;#m;#w=-1;#b=/* @__PURE__ */new Map;#v=/* @__PURE__ */new Set;#y=/* @__PURE__ */new Map;#x=!1;#C=-1;#R;#E=!1;#S=!1;#k=!1;#A=null;#_=new Se;#I;get#h(){return this.grid}attach(e){super.attach(e);const t=this.disconnectSignal,i=this.#h;if(this.#R=new ye((e,t,i)=>{this.#L(e,t,i)}),this.#I={grid:i,isGridMode:this.#c,config:this.config,editingCells:this.#v,editorValueCallbacks:this.#y,isEditSessionActive:()=>-1!==this.#p,commitCellValue:(e,t,i,n)=>this.#T(e,t,i,n),exitRowEdit:(e,t)=>this.#F(e,t)},i._activeEditRows=-1,i._rowEditSnapshots=/* @__PURE__ */new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(e,"_changedRowIdSet",{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.#c&&"Escape"===e.key&&-1!==this.#p){if(Ie(this.config,e))return;this.#F(this.#p,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",e=>{if(this.#c)return;if(-1===this.#p)return;const t=i.findRenderedRowElement?.(this.#p);if(!t)return;if((e.composedPath&&e.composedPath()||[]).includes(t))return;const n=e.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||Ie(this.config,e)||queueMicrotask(()=>{-1!==this.#p&&this.#F(this.#p,!1)})},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",e=>{if(this.#c)return;if(-1===this.#p)return;const t=e.relatedTarget;t&&this.grid.containsFocus?.(t)||t&&this.gridElement.contains(t)||queueMicrotask(()=>{-1!==this.#p&&this.#M()})},{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.#y.get(i);n&&n(t.newValue)},{signal:t}),this.config.dirtyTracking){const e=e=>{const t=e.detail,i=t?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const o=this.#_.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#_.getOriginalRow(r),type:o?"modified":"pristine"})};this.gridElement.addEventListener("undo",e,{signal:t}),this.gridElement.addEventListener("redo",e,{signal:t}),this.on("row-inserted",e=>{const t=this.grid.getRowId(e.row);null!=t&&this.markAsNew(String(t))})}this.#c&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",e=>{const t=e.target;if(t!==this.gridElement&&t.matches(ke)){if(this.#S)return t.blur(),void this.gridElement.focus();const e=i._focusRow,n=i._focusCol,r=this.#A;if(!r||r.rowIndex!==e||r.colIndex!==n){const t=i._visibleColumns?.[n],r=i._rows?.[e];if(t?.field&&r){const i=t.field;this.#A={rowIndex:e,colIndex:n,field:i,value:r[i]}}}this.#E=!0}},{signal:t}),this.gridElement.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&(this.gridElement.contains(t)||this.grid.containsFocus?.(t))&&t.matches(ke)||(this.#E=!1,this.#A=null)},{signal:t}),this.gridElement.addEventListener("keydown",e=>{if("Escape"===e.key&&this.#E){if(Ie(this.config,e))return void queueMicrotask(()=>{if(this.#E){this.#D();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#E=!1,this.#S=!0}});this.#D();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#E=!1,this.#S=!0,e.preventDefault(),e.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",e=>{e.target.matches(ke)&&(this.#S=!1)},{signal:t}))}detach(){this.#h._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#p=-1,this.#f=void 0,this.#m=void 0,this.#w=-1,this.#b.clear(),this.#_.clear(),this.#v.clear(),this.#y.clear(),this.#E=!1,this.#S=!1,this.#A=null,this.#k=!1,super.detach()}handleQuery(e){if("isEditing"===e.type)return this.#c||-1!==this.#p}onCellClick(e){if(this.#c)return!1;const t=this.#h,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=>this.#g(e));if(!o)return!1;const s=t._rows[r],a=t.effectiveConfig?.rowEditable;return!(s&&a&&!a(s))&&(e.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(e){const t=this.#h;if("Escape"===e.key){if(this.#c&&this.#E){this.#D();const e=document.activeElement;return e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#E=!1,this.#S=!0,this.requestAfterRender(),!0}if(-1!==this.#p&&!this.#c)return Ie(this.config,e)||this.#F(this.#p,!0),!0}if(this.#c&&!this.#E&&("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key))return!1;if(this.#c&&this.#E&&("ArrowUp"===e.key||"ArrowDown"===e.key))return!0;if(("ArrowUp"===e.key||"ArrowDown"===e.key)&&-1!==this.#p&&!this.#c){if(Ie(this.config,e))return!0;const i=t._rows.length-1,n=this.#p;return this.#F(n,!1),"ArrowDown"===e.key?t._focusRow=Math.min(i,t._focusRow+1):t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault(),o(t),this.requestAfterRender(),!0}if("Tab"===e.key&&(-1!==this.#p||this.#c)){if(e.preventDefault(),this.#k)return this.#F(this.#p,!1),!0;const t=!e.shiftKey;return this.#q(t),!0}if(" "===e.key||"Spacebar"===e.key){if(-1!==this.#p)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&&o&&this.#u(r,o)&&"boolean"===r.type){const t=r.field;if(Ae(t)){const n=!o[t];return this.#T(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.#c&&!this.#E)return this.#M(),!0;if(-1!==this.#p)return!!Ie(this.config,e);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=>this.#g(e)),o=t._rows[n],s=t.effectiveConfig?.rowEditable,a=o&&s&&!s(o);if(i&&!a){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.#p||this.#c)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],o=t._rows[i];if(r&&o&&this.#u(r,o)&&r.field)return e.preventDefault(),this.beginCellEdit(i,r.field),!0}return!1}return!1}processColumns(e){const t=this.#h,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}processRows(e){const t=this.#h;if(this.config.dirtyTracking&&t.getRowId&&this.#_.capture(e,e=>{try{return t.getRowId?.(e)}catch{return}}),-1===this.#p||this.#c)return e;const i=this.#f,n=this.#m;if(!i||!n)return e;const r=[...e];let o=-1;for(let s=0;s<r.length;s++)try{if(t.getRowId?.(r[s])===i){o=s;break}}catch{}return-1===o?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[o]=n,this.#p!==o&&this.#G(this.#p,o),r)}afterRender(){const e=this.#h;if(-1!==this.#p&&this.#m&&!this.#c&&e._rows[this.#p]!==this.#m){const t=e._rows.indexOf(this.#m);if(-1===t)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#G(this.#p,t)}if(this.#x&&(this.#x=!1,this.#P(e)),-1!==this.#C){const t=this.#C;this.#C=-1,e.animateRow?.(t,"change")}const t=this.#_.drainCapturedFlag();if(null!=t&&this.emit("baselines-captured",{count:t}),!this.#c&&0!==this.#v.size)for(const i of this.#v){const[t,n]=i.split(":"),r=parseInt(t,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.#H(l,r,d,o,a,!0)}}afterCellRender(e){const{row:t,rowIndex:i,column:n,colIndex:r,cellElement:o}=e,s=this.#u(n,t);if(s)o.removeAttribute("aria-readonly");else if(o.setAttribute("aria-readonly","true"),this.#c&&o.classList.contains("editing")){o.classList.remove("editing");const e=t[n.field];o.textContent=null==e?"":String(e)}this.#c&&s&&(o.classList.contains("editing")||this.#H(t,i,n,r,o,!0,e.rowElement))}afterRowRender(e){if(!this.config.dirtyTracking)return;const t=this.#h,i=t.getRowId?.(e.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:o}=this.#_.getRowDirtyState(i,e.row),s=e.rowElement;if(s.classList.toggle("tbw-row-dirty",r),s.classList.toggle("tbw-row-new",n),o){const t=s.querySelectorAll(".cell[data-field]");for(let n=0;n<t.length;n++){const r=t[n],o=r.getAttribute("data-field");o&&r.classList.toggle("tbw-cell-dirty",this.#_.isCellDirty(i,e.row,o))}}else{const e=s.querySelectorAll(".tbw-cell-dirty");for(let t=0;t<e.length;t++)e[t].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#_.getChangedRows(e=>this.grid.getRow(e))}get changedRowIds(){return this.#_.getChangedRowIds()}get activeEditRow(){return this.#p}get activeEditCol(){return this.#w}isRowEditing(e){return this.#p===e}isCellEditing(e,t){return this.#v.has(`${e}:${t}`)}isRowChanged(e){const t=this.#h,i=t._rows[e];if(!i)return!1;try{const e=t.getRowId?.(i);return!!e&&this.#_.isRowChanged(e)}catch{return!1}}isRowChangedById(e){return this.#_.isRowChanged(e)}isDirty(e){if(!this.config.dirtyTracking)return!1;if(this.#_.newRowIds.has(e))return!0;const t=this.grid.getRow(e);return!!t&&this.#_.isRowDirty(e,t)}isPristine(e){return!this.isDirty(e)}get dirty(){if(!this.config.dirtyTracking)return!1;const e=this.#h;return this.#_.hasAnyDirty(t=>e._getRowEntry(t)?.row)}get pristine(){return!this.dirty}markAsPristine(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&(this.#_.markPristine(e,t),this.emit("dirty-change",{rowId:e,row:t,original:t,type:"pristine"}))}markAsNew(e){if(!this.config.dirtyTracking)return;this.#_.markNew(e);const t=this.grid.getRow(e);this.emit("dirty-change",{rowId:e,row:t,original:void 0,type:"new"})}markAsDirty(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&(this.#_.markDirty(e),this.emit("dirty-change",{rowId:e,row:t,original:this.#_.getOriginalRow(e),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const e=this.#h;this.#_.markAllPristine(t=>e._getRowEntry(t)?.row)}getOriginalRow(e){if(this.config.dirtyTracking)return this.#_.getOriginalRow(e)}hasBaseline(e){return!!this.config.dirtyTracking&&this.#_.hasBaseline(e)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const e=this.#h;return this.#_.getDirtyRows(t=>e._getRowEntry(t)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const e=this.#h;return this.#_.getDirtyRowIds(t=>e._getRowEntry(t)?.row)}revertRow(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&this.#_.revertRow(e,t)&&(this.emit("dirty-change",{rowId:e,row:t,original:this.#_.getOriginalRow(e),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const e=this.#h;this.#_.revertAll(t=>e._getRowEntry(t)?.row),this.requestRender()}setInvalid(e,t,i=""){this.#R.setInvalid(e,t,i)}clearInvalid(e,t){this.#R.clearInvalid(e,t)}clearRowInvalid(e){this.#R.clearRowInvalid(e)}clearAllInvalid(){this.#R.clearAllInvalid()}isCellInvalid(e,t){return this.#R.isCellInvalid(e,t)}getInvalidMessage(e,t){return this.#R.getInvalidMessage(e,t)}hasInvalidCells(e){return this.#R.hasInvalidCells(e)}getInvalidFields(e){return this.#R.getInvalidFields(e)}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#_.changedRowIds.clear(),this.#_.committedDirtyRowIds.clear(),this.#N(),e||this.emit("changed-rows-reset",{rows:t,ids:i});const n=this.#h;n._rowPool?.forEach(e=>e.classList.remove("changed"))}beginCellEdit(e,t){const i=this.#h,n=i._visibleColumns.findIndex(e=>e.field===t);if(-1===n)return;const r=i._visibleColumns[n],o=i._rows[e];if(!r||!o||!this.#u(r,o))return;const s=i.findRenderedRowElement?.(e),a=s?.querySelector(`.cell[data-col="${n}"]`);a&&(this.#k=!0,this.#z(e,n,a))}beginBulkEdit(e){const t=this.#h;if(!1===(this.config.editOn??t.effectiveConfig?.editOn))return;const i=t._columns?.some(e=>this.#g(e));if(!i)return;const n=t.findRenderedRowElement?.(e);if(!n)return;const r=t._rows[e],o=t.effectiveConfig?.rowEditable;r&&o&&!o(r)||(this.#k=!1,this.#K(e,r),Array.from(n.children).forEach((i,n)=>{const o=t._visibleColumns[n];if(o&&this.#u(o,r)){const t=i;t.classList.contains("editing")||this.#H(r,e,o,n,t,!0)}}),setTimeout(()=>{let e=n.querySelector(`.cell[data-col="${t._focusCol}"]`);if(e?.classList.contains("editing")||(e=n.querySelector(".cell.editing")),e?.classList.contains("editing")){const t=e.querySelector(ke);try{t?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#p&&this.#F(this.#p,!1)}cancelActiveRowEdit(){-1!==this.#p&&this.#F(this.#p,!0)}#L(e,t,i){const n=this.#h,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.#R.getInvalidMessage(e,t);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#G(e,t){this.#p=t;const i=/* @__PURE__ */new Set,n=`${e}:`;for(const s of this.#v)s.startsWith(n)?i.add(`${t}:${s.substring(n.length)}`):i.add(s);this.#v.clear();for(const s of i)this.#v.add(s);const r=this.#b.get(e);void 0!==r&&(this.#b.delete(e),this.#b.set(t,r));const o=[];for(const[s,a]of this.#y)s.startsWith(n)&&(o.push([`${t}:${s.substring(n.length)}`,a]),this.#y.delete(s));for(const[s,a]of o)this.#y.set(s,a);this.#N()}#z(e,t,i){const n=this.#h,r=n._rows[e],o=n._visibleColumns[t];r&&o&&this.#u(o,r)&&(i.classList.contains("editing")||(this.#p!==e&&this.#K(e,r),this.#w=t,this.#H(r,e,o,t,i,!1)))}#D(){const e=this.#A;if(!e)return;const t=this.#h,i=t._rows?.[e.rowIndex];i&&(i[e.field]=e.value);const n=`${e.rowIndex}:${e.field}`,r=this.#y.get(n);if(r&&r(e.value),this.emit("cell-cancel",{rowIndex:e.rowIndex,colIndex:e.colIndex,field:e.field,previousValue:e.value}),i){let e;try{e=this.grid.getRowId(i)}catch{}e&&(this.config.dirtyTracking?this.#_.isRowDirty(e,i)||(this.#_.changedRowIds.delete(e),this.emit("dirty-change",{rowId:e,row:i,original:this.#_.getOriginalRow(e),type:"reverted"})):this.#_.changedRowIds.delete(e))}this.requestRender(),this.#A=null}#M(){const e=this.#h,t=e._focusRow,i=e._focusCol;if(t<0||i<0)return;const n=e.findRenderedRowElement?.(t),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const e=r.querySelector(ke);e&&(this.#S=!1,e.focus(),this.#E=!0,e instanceof HTMLInputElement&&("text"===e.type||"number"===e.type)&&e.select())}}#q(e){const t=this.#h,i=t._rows,n=this.#c?t._focusRow:this.#p,r=i[n],s=t._visibleColumns.map((e,t)=>r&&this.#u(e,r)?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?.(n),i=e?.querySelector(`.cell[data-col="${s[a]}"]`);if(i?.classList.contains("editing")){const e=i.querySelector(ke);e?.focus({preventScroll:!0})}return void o(t,{forceHorizontalScroll:!0})}const l=n+(e?1:-1);if(l>=0&&l<i.length){const r=i[l],s=t._visibleColumns.map((e,t)=>r&&this.#u(e,r)?t:-1).filter(e=>e>=0);if(0===s.length)return;this.#c?(t._focusRow=l,t._focusCol=e?s[0]:s[s.length-1],o(t,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const e=t.findRenderedRowElement?.(l),i=e?.querySelector(`.cell[data-col="${t._focusCol}"]`);if(i?.classList.contains("editing")){const e=i.querySelector(ke);e?.focus({preventScroll:!0})}},0)):(this.#F(n,!1),t._focusRow=l,t._focusCol=e?s[0]:s[s.length-1],this.beginBulkEdit(l),o(t,{forceHorizontalScroll:!0}))}}#N(){const e=this.#h;e._activeEditRows=this.#p,e._rowEditSnapshots=this.#b}#K(e,t){if(this.#p!==e){-1!==this.#p&&this.#F(this.#p,!1),this.#b.set(e,{...t}),this.#p=e,this.#m=t;const i=this.#h;try{this.#f=i.getRowId?.(t)??void 0}catch{this.#f=void 0}this.#N(),this.#c||this.emit("edit-open",{rowIndex:e,rowId:this.#f??"",row:t})}}#F(e,t){if(this.#p!==e)return;const i=this.#h,n=this.#b.get(e),r=i.findRenderedRowElement?.(e);let o=this.#f;const s=o?i._getRowEntry(o):void 0,a=s?.row??this.#m??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=ve(o,r,i);i!==n&&this.#T(e,r,n,a)}})}if(t||this.#c||!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.#_.changedRowIds.delete(o),this.#_.committedDirtyRowIds.delete(o),this.clearRowInvalid(o));else if(!t&&a){const t=function(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}(n,a),i=o?this.#_.changedRowIds.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.#_.changedRowIds.delete(o),this.#_.committedDirtyRowIds.delete(o),this.clearRowInvalid(o))):r||(o&&this.config.dirtyTracking&&(this.#_.isRowDirty(o,a)?this.#_.committedDirtyRowIds.add(o):this.#_.committedDirtyRowIds.delete(o)),t&&this.isAnimationEnabled&&(this.#C=e))}this.#b.delete(e),this.#p=-1,this.#f=void 0,this.#m=void 0,this.#w=-1,this.#k=!1,this.#N();for(const l of this.#v)l.startsWith(`${e}:`)&&this.#v.delete(l);for(const l of this.#y.keys())l.startsWith(`${e}:`)&&this.#y.delete(l);this.#x=!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.#P(i),this.#x=!1),!this.#c&&a&&this.emit("edit-close",{rowIndex:e,rowId:o??"",row:a,reverted:t})}#T(e,t,i,n){const r=t.field;if(!Ae(r))return;const o=n[r];if(o===i)return;const s=this.#h;let a;try{a=this.grid.getRowId(n)}catch{}const l=!a||!this.#_.changedRowIds.has(a),d=a?e=>this.grid.updateRow(a,e,"cascade"):_e;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;if(a&&!c&&this.isCellInvalid(a,r)&&this.clearInvalid(a,r),n[r]=i,a&&this.#_.changedRowIds.add(a),this.#N(),this.config.dirtyTracking&&a){const e=this.#_.isRowDirty(a,n);this.emit("dirty-change",{rowId:a,row:n,original:this.#_.getOriginalRow(a),type:e?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:r,oldValue:o,newValue:i});const h=s.findRenderedRowElement?.(e);h&&h.classList.add("changed")}#H(e,t,i,n,r,o,s){Le(this.#I,e,t,i,n,r,o,s)}#P(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 Fe(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 Me(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 De(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}class qe extends i{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=U(this.columns,t?.columns,i.onlyVisible);let o;if(t?.rowIndices)o=Y(this.rows,t.rowIndices);else if(i.onlySelected){const e=this.getSelectionState();o=e?.selected?.size?Y(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 Fe(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)),Fe(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){Me(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">${De(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=De(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`;Me(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`;Me(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 Ge="(Blank)";function Pe(e){if(e instanceof Date)return e.getTime();const t=Number(e);if(!isNaN(t))return t;return new Date(e).getTime()}function He(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(Ge):!o.some(t=>e.includes(t)))}if("in"===t.operator){const e=t.value;return!!Array.isArray(e)&&(0===o.length?e.includes(Ge):o.some(t=>e.includes(t)))}}if("notIn"===t.operator)return null==r||""===r?!Array.isArray(t.value)||!t.value.includes(Ge):Array.isArray(t.value)&&!t.value.includes(r);if("in"===t.operator)return null==r||""===r?Array.isArray(t.value)&&t.value.includes(Ge):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 Pe(r)<Pe(t.value);case"lessThanOrEqual":return Pe(r)<=Pe(t.value);case"greaterThan":return Pe(r)>Pe(t.value);case"greaterThanOrEqual":return Pe(r)>=Pe(t.value);case"between":return Pe(r)>=Pe(t.value)&&Pe(r)<=Pe(t.valueTo);default:return!0}}(e,t,i,n?.get(t.field)))):e}function Ne(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(Ge),[...n].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t)))}function ze(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(Ge),n.set(r,[...o].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t))));return n}const Ke="__tbw_expander";function Oe(e){return e.field===Ke}function Ve(e){return!0===e.meta?.utility}function Be(e){return e?e.toISOString().split("T")[0]:""}function $e(e){return e?"string"==typeof e?e:"number"==typeof e?Be(new Date(e)):"":""}function We(e,t,i,n,r,o){const{field:l,column:d}=t,c=function(e){if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-filter-item-height");if(t&&t.trim()){const e=parseFloat(t);if(!isNaN(e)&&e>0)return e}}return 28}(e),u=e=>{if(null==e)return"(Blank)";if(d.format&&!d.filterValue){const t=d.format(e,void 0);if(t)return t}return String(e)};i=i.slice().sort((e,t)=>u(e).localeCompare(u(t)));const h=document.createElement("div");h.className="tbw-filter-search";const g=document.createElement("input");g.type="text",g.placeholder="Search...",g.className="tbw-filter-search-input",g.value=o.get(l)??"",h.appendChild(g),e.appendChild(h);const p=document.createElement("div");p.className="tbw-filter-actions";const f=document.createElement("label");f.className="tbw-filter-value-item",f.style.padding="0",f.style.margin="0";const m=document.createElement("input");m.type="checkbox",m.className="tbw-filter-checkbox";const w=document.createElement("span");w.textContent="Select All",f.appendChild(m),f.appendChild(w),p.appendChild(f);const b=/* @__PURE__ */new Map;i.forEach(e=>{const t=null==e?"__null__":String(e);b.set(t,!n.has(e))});const v=()=>{const e=[...b.values()],t=e.every(e=>e),i=e.every(e=>!e);m.checked=t,m.indeterminate=!t&&!i};m.addEventListener("change",()=>{const e=m.checked;for(const t of b.keys())b.set(t,e);v(),S()}),v(),e.appendChild(p);const y=document.createElement("div");y.className="tbw-filter-values";const x=document.createElement("div");x.className="tbw-filter-values-spacer",y.appendChild(x);const C=document.createElement("div");C.className="tbw-filter-values-content",y.appendChild(C);let R=[];const E=(e,t)=>{const i=u(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=b.get(n)??!0,o.dataset.value=n,o.addEventListener("change",()=>{b.set(n,o.checked),v()});const s=document.createElement("span");return s.textContent=i,r.appendChild(o),r.appendChild(s),r},S=()=>{const e=R.length,t=y.clientHeight,i=y.scrollTop;if(x.style.height=e*c+"px",s(e,50/3))return C.innerHTML="",C.style.transform="translateY(0px)",void R.forEach((e,t)=>{C.appendChild(E(e,t))});const n=a({totalRows:e,viewportHeight:t,scrollTop:i,rowHeight:c,overscan:3});C.style.transform=`translateY(${n.offsetY}px)`,C.innerHTML="";for(let r=n.start;r<n.end;r++)C.appendChild(E(R[r],r-n.start))},k=e=>{const t=r.caseSensitive??!1,n=t?e:e.toLowerCase();if(R=i.filter(i=>{const r=u(i),o=t?r:r.toLowerCase();return!e||o.includes(n)}),R.sort((e,t)=>{const i=null==e?"__null__":String(e),n=null==t?"__null__":String(t),r=b.get(i)??!0;return r!==(b.get(n)??!0)?r?-1:1:u(e).localeCompare(u(t))}),0===R.length){x.style.height="0px",C.innerHTML="";const e=document.createElement("div");return e.className="tbw-filter-no-match",e.textContent="No matching values",void C.appendChild(e)}S()};let A;y.addEventListener("scroll",()=>{R.length>0&&S()},{passive:!0}),k(g.value),e.appendChild(y),g.addEventListener("input",()=>{clearTimeout(A),A=setTimeout(()=>{o.set(l,g.value),k(g.value)},r.debounceMs??150)});const _=document.createElement("div");_.className="tbw-filter-buttons";const I=document.createElement("button");I.className="tbw-filter-apply-btn",I.textContent="Apply",I.addEventListener("click",()=>{const e=[];for(const[t,n]of b)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)}),_.appendChild(I);const L=document.createElement("button");L.className="tbw-filter-clear-btn",L.textContent="Clear Filter",L.addEventListener("click",()=>{t.clearFilter()}),_.appendChild(L),e.appendChild(_)}function je(e,t){if("number"==typeof e)return e;if("string"==typeof e){const i=parseFloat(e);return isNaN(i)?t:i}return t}class Ue extends i{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;computeSelected(){const e={},t=[];for(const[i,n]of this.filters)if("set"===n.type)if("in"===n.operator&&Array.isArray(n.value))e[i]=n.value;else if("notIn"===n.operator){const e=this.grid.effectiveConfig?.columns?.find(e=>e.field===i);t.push({field:i,filterValue:e?.filterValue})}if(t.length>0){const i=ze(this.sourceRows,t);for(const{field:n}of t){const t=this.excludedValues.get(n),r=i.get(n)??[];e[n]=t?r.filter(e=>!t.has(e)):r}}return e}syncExcludedValues(e,t){if(t)if("set"===t.type&&"notIn"===t.operator&&Array.isArray(t.value))this.excludedValues.set(e,new Set(t.value));else if("set"===t.type&&"in"===t.operator&&Array.isArray(t.value)){const i=this.sourceRows;if(!i||0===i.length)return void this.excludedValues.delete(e);const n=t.value,r=new Set(n.map(e=>null==e?Ge:e)),o=this.getUniqueValues(e),s=new Set(o.filter(e=>!r.has(e)));this.excludedValues.set(e,s)}else"set"===t.type&&this.excludedValues.delete(e);else 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=He([...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),r?e.setAttribute("aria-description","Filtered"):e.removeAttribute("aria-description"),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"),e.setAttribute("aria-description","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,i){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)}if(this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,!i?.silent){this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.();const i=this.grid.effectiveConfig?.columns?.find(t=>t.field===e)?.header??e;l(this.gridElement,null===t?`Filter cleared from ${i}`:`Filter applied on ${i}`)}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,t){this.filters.clear(),this.excludedValues.clear();for(const i of e)this.filters.set(i.field,i),this.syncExcludedValues(i.field,i);this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null,t?.silent||(this.emit("filter-change",{filters:[...this.filters.values()],filteredRowCount:0,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.()),this.emitPluginEvent("filter-applied",{filters:[...this.filters.values()]}),this.requestRender()}clearAllFilters(e){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal(e?.silent),e?.silent||l(this.gridElement,"All filters cleared")}clearFieldFilter(e,t){if(this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal(t?.silent),!t?.silent){const t=this.grid.effectiveConfig?.columns?.find(t=>t.field===e)?.header??e;l(this.gridElement,`Filter cleared from ${t}`)}}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 Ne(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=Ne(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){const r=this.filters.get(e);if("in"===r?.operator&&"set"===r.type&&Array.isArray(r.value)&&!this.excludedValues.has(e)){const t=r.value,i=new Set(t.map(e=>null==e?Ge:e)),o=new Set(n.filter(e=>!i.has(e)));this.excludedValues.set(e,o)}let o=this.excludedValues.get(e);o||(o=/* @__PURE__ */new Set,this.excludedValues.set(e,o));const s=this.searchText.get(e)??"",a={field:e,column:t,uniqueValues:n,excludedValues:o,searchText:s,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 l=!1;if(this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(i,a),l=i.children.length>0),!l&&t.type){const e=this.grid.effectiveConfig.typeDefaults?.[t.type];e?.filterPanelRenderer&&(e.filterPanelRenderer(i,a),l=i.children.length>0)}if(!l){const e=t.type;"number"===e?function(e,t,i,n){const{field:r,column:o}=t,s=o.filterParams,a=o.editorParams,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=je(s?.min??a?.min,d),h=je(s?.max??a?.max,c),g=s?.step??a?.step??1,p=n.get(r);let f=u,m=h;const w="blank"===p?.operator;"between"===p?.operator?(f=je(p.value,u),m=je(p.valueTo,h)):"greaterThanOrEqual"===p?.operator?f=je(p.value,u):"lessThanOrEqual"===p?.operator&&(m=je(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 R=document.createElement("div");R.className="tbw-filter-range-group";const E=document.createElement("label");E.textContent="Max",E.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),R.appendChild(E),R.appendChild(S),b.appendChild(R),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 I=document.createElement("input");I.type="range",I.className="tbw-filter-range-thumb tbw-filter-range-thumb-min",I.min=String(u),I.max=String(h),I.step=String(g),I.value=String(f);const L=document.createElement("input");L.type="range",L.className="tbw-filter-range-thumb tbw-filter-range-thumb-max",L.min=String(u),L.max=String(h),L.step=String(g),L.value=String(m),k.appendChild(A),k.appendChild(_),k.appendChild(I),k.appendChild(L),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,I.disabled=e,L.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 q=()=>{const e=parseFloat(I.value),t=parseFloat(L.value),i=h-u,n=(e-u)/i*100,r=(t-u)/i*100;_.style.left=`${n}%`,_.style.width=r-n+"%"};I.addEventListener("input",()=>{const e=Math.min(parseFloat(I.value),parseFloat(L.value));I.value=String(e),x.value=String(e),q()}),L.addEventListener("input",()=>{const e=Math.max(parseFloat(L.value),parseFloat(I.value));L.value=String(e),S.value=String(e),q()}),x.addEventListener("input",()=>{let e=parseFloat(x.value)||u;e=Math.max(u,Math.min(e,parseFloat(S.value))),I.value=String(e),q()}),S.addEventListener("input",()=>{let e=parseFloat(S.value)||h;e=Math.min(h,Math.max(e,parseFloat(x.value))),L.value=String(e),q()}),q();const G=document.createElement("div");G.className="tbw-filter-buttons";const P=document.createElement("button");P.className="tbw-filter-apply-btn",P.textContent="Apply",P.addEventListener("click",()=>{if(F.checked)return void t.applyTextFilter("blank","");const e=parseFloat(x.value),i=parseFloat(S.value);t.applyTextFilter("between",e,i)}),G.appendChild(P);const H=document.createElement("button");H.className="tbw-filter-clear-btn",H.textContent="Clear Filter",H.addEventListener("click",()=>{t.clearFilter()}),G.appendChild(H),e.appendChild(G)}(i,a,n,this.filters):"date"===e?function(e,t,i,n){const{field:r,column:o}=t,s=o.filterParams,a=o.editorParams,l=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())),d=l.length>0?new Date(Math.min(...l.map(e=>e.getTime()))):null,c=l.length>0?new Date(Math.max(...l.map(e=>e.getTime()))):null,u=$e(s?.min)||$e(a?.min)||Be(d),h=$e(s?.max)||$e(a?.max)||Be(c),g=n.get(r);let p="",f="";const m="blank"===g?.operator;"between"===g?.operator?(p=$e(g.value)||"",f=$e(g.valueTo)||""):"greaterThanOrEqual"===g?.operator?p=$e(g.value)||"":"lessThanOrEqual"===g?.operator&&(f=$e(g.value)||"");const w=document.createElement("div");w.className="tbw-filter-date-range";const b=document.createElement("div");b.className="tbw-filter-date-group";const v=document.createElement("label");v.textContent="From",v.className="tbw-filter-range-label";const y=document.createElement("input");y.type="date",y.className="tbw-filter-date-input",u&&(y.min=u),h&&(y.max=h),y.value=p,b.appendChild(v),b.appendChild(y),w.appendChild(b);const x=document.createElement("span");x.className="tbw-filter-range-separator",x.textContent="–",w.appendChild(x);const C=document.createElement("div");C.className="tbw-filter-date-group";const R=document.createElement("label");R.textContent="To",R.className="tbw-filter-range-label";const E=document.createElement("input");E.type="date",E.className="tbw-filter-date-input",u&&(E.min=u),h&&(E.max=h),E.value=f,C.appendChild(R),C.appendChild(E),w.appendChild(C),e.appendChild(w);const S=document.createElement("label");S.className="tbw-filter-blank-option";const k=document.createElement("input");k.type="checkbox",k.className="tbw-filter-blank-checkbox",k.checked=m;const A=document.createTextNode("Show only blank");S.appendChild(k),S.appendChild(A);const _=e=>{y.disabled=e,E.disabled=e,w.classList.toggle("tbw-filter-disabled",e)};_(m),k.addEventListener("change",()=>{_(k.checked)}),e.appendChild(S);const I=document.createElement("div");I.className="tbw-filter-buttons";const L=document.createElement("button");L.className="tbw-filter-apply-btn",L.textContent="Apply",L.addEventListener("click",()=>{if(k.checked)return void t.applyTextFilter("blank","");const e=y.value,i=E.value;e&&i?t.applyTextFilter("between",e,i):e?t.applyTextFilter("greaterThanOrEqual",e):i?t.applyTextFilter("lessThanOrEqual",i):t.clearFilter()}),I.appendChild(L);const T=document.createElement("button");T.className="tbw-filter-clear-btn",T.textContent="Clear Filter",T.addEventListener("click",()=>{t.clearFilter()}),I.appendChild(T),e.appendChild(I)}(i,a,n,this.filters):We(i,a,n,o,{caseSensitive:this.config.caseSensitive,debounceMs:this.config.debounceMs},this.searchText)}}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===Ue.supportsAnchorPositioning&&(Ue.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),Ue.supportsAnchorPositioning}positionPanel(e,t){const i=t.closest(".cell")??t;if(i.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=i,Ue.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"))})}applySetFilter(e,t,i){if(this.excludedValues.set(e,new Set(t)),0===t.length)this.filters.delete(e);else{const n=this.filters.get(e);if("in"===n?.operator){const n=this.getUniqueValues(e),r=new Set(t),o=n.filter(e=>!r.has(e));this.filters.set(e,{field:e,type:"set",operator:"in",value:o,...void 0!==i&&{valueTo:i}})}else 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(e){this.cachedResult=null,this.cacheKey=null,this.cachedInputSpot=null;const t=[...this.filters.values()];if(this.config.filterHandler){this.gridElement.setAttribute("aria-busy","true");const i=this.config.filterHandler(t,this.sourceRows),n=i=>{this.gridElement.removeAttribute("aria-busy"),this.cachedResult=i,this.grid.rows=i,e||(this.emit("filter-change",{filters:t,filteredRowCount:i.length,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.()),this.emitPluginEvent("filter-applied",{filters:t}),this.requestRender()};return void(i&&"function"==typeof i.then?i.then(n):n(i))}e||(this.emit("filter-change",{filters:t,filteredRowCount:0,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.()),this.emitPluginEvent("filter-applied",{filters:t}),this.requestRender()}getColumnState(e){if(!this.config.trackColumnState)return;const t=this.filters.get(e);return t?{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}:void 0}applyColumnState(e,t){if(!this.config.trackColumnState)return;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 Ye(e){return e.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function Ze(e){return e.map(e=>e.id?e:(e.header||d(c,'ColumnGroupDefinition requires either an "id" or a "header" to generate an id from.'),{...e,id:Ye(e.header)}))}function Qe(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}function Xe(e,t){const i=e.columns[0],n=e.columns[e.columns.length-1],r=i?t.findIndex(e=>e.field===i.field):-1,o=n?t.findIndex(e=>e.field===n.field):-1;return-1!==r&&-1!==o?[r,o]:null}function Je(e,t){const i=/* @__PURE__ */new Set,n=[];for(const r of e){if(String(r.id).startsWith("__implicit__"))continue;const e=Xe(r,t);e&&n.push(e)}for(const r of e){if(!String(r.id).startsWith("__implicit__"))continue;const e=Xe(r,t);if(!e)continue;const[o,s]=e;n.some(([e,t])=>o>=e&&s<=t)&&i.add(String(r.id))}return i}class et extends i{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;#O=/* @__PURE__ */new Set;#V=[];#B=/* @__PURE__ */new Map;attach(e){super.attach(e),this.gridElement.addEventListener("column-move",this.#$,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#O.clear(),this.#V=[],this.#B.clear()}#$=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.#W(r,n))return t.preventDefault(),void this.#j(i);this.#U(n)};#U(e){this.#O.clear();const t=this.#Y(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.#O.add(n);break}}}#Y(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}#W(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}#j(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.#Z()}#Z(){let e;if(this.#V.length>0)e=this.#V.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 t=this.grid?.getColumnOrder();if(t&&t.length>0){const i=new Map(t.map((e,t)=>[e,t]));for(const t of e)t.fields.sort((e,t)=>(i.get(e)??1/0)-(i.get(t)??1/0))}return e}static detect(e,t){const i=t?.features?.groupingColumns;if(i&&"object"==typeof i&&Array.isArray(i.columnGroups)&&i.columnGroups.length>0)return!0;if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const n=t?.columns;return!!Array.isArray(n)&&function(e){return e.some(e=>null!=e.group)}(n)}processColumns(e){const t=this.config?.columnGroups,i=this.grid?.gridConfig?.columnGroups;let n,r;if(t&&Array.isArray(t)&&t.length>0?(i&&Array.isArray(i)&&i.length>0&&this.warn(u,"columnGroups defined in both gridConfig and groupingColumns feature config. Using feature config (higher precedence)."),n=t):i&&Array.isArray(i)&&i.length>0&&(n=i),n&&n.length>0){const t=Ze(n);this.#V=t,this.#B.clear();for(const e of t)e.renderer&&this.#B.set(e.id,e.renderer);const i=/* @__PURE__ */new Map;for(const e of t)for(const t of e.children)i.set(t,{id:e.id,label:e.header});r=e.map(e=>{const t=i.get(e.field);return t&&!e.group?{...e,group:t}:e})}else this.#V=[],this.#B.clear(),r=[...e];const o=Qe(r);if(0===o.length)return this.isActive=!1,this.groups=[],r;if(this.#B.size>0)for(const s of o){const e=this.#B.get(s.id);e&&(s.renderer=e)}this.isActive=!0,this.groups=o,this.#O.clear();for(const s of o){const e=s.columns[s.columns.length-1];e?.field&&this.#O.add(e.field)}return r}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=Qe(i);if(0===n.length)return;if(this.#B.size>0)for(const a of n){const e=this.#B.get(a.id);e&&(a.renderer=e)}this.#O.clear();const r=Je(n,i);for(let a=0;a<n.length;a++){const e=n[a];if(String(e.id).startsWith("__implicit__")&&r.has(String(e.id)))continue;const t=e.columns[e.columns.length-1];t?.field&&a<n.length-1&&this.#O.add(t.field)}const o=function(e,t,i){if(0===e.length)return null;const n=document.createElement("div");n.className="header-group-row",n.setAttribute("role","row");const r=Je(e,t);for(const o of e){const e=String(o.id),s=e.startsWith("__implicit__");if(s&&r.has(e))continue;const a=Xe(o,t);if(!a)continue;const[l,d]=a,c=d-l+1,u=s?"":o.label||o.id,h=document.createElement("div");h.className="cell header-group-cell",s&&h.classList.add("implicit-group"),h.setAttribute("data-group",e),h.style.gridColumn=`${l+1} / span ${c}`;const g=!s&&(o.renderer||i)||void 0;if(g&&!s){const t=g({id:e,label:String(u),columns:o.columns,firstIndex:l,isImplicit:!1});t instanceof HTMLElement?h.appendChild(t):"string"==typeof t?h.innerHTML=t:h.textContent=u}else h.textContent=u;n.appendChild(h)}return n}(n,i,this.config.groupHeaderRenderer);if(o){o.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(o,t):e.appendChild(o)}const s=e.querySelector(".header-row");s&&(s.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,t,i){if(!t.length||!e)return;const n=Je(t,i),r=/* @__PURE__ */new Map;for(const s of t)if(!String(s.id).startsWith("__implicit__")||!n.has(String(s.id)))for(const e of s.columns)e.field&&r.set(e.field,s.id);const o=Array.from(e.querySelectorAll(".cell[data-field]"));o.forEach(e=>{const t=e.getAttribute("data-field")||"",i=r.get(t);i&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",i))});for(const s of t){if(String(s.id).startsWith("__implicit__")&&n.has(String(s.id)))continue;const e=s.columns[s.columns.length-1],t=o.find(t=>t.getAttribute("data-field")===e.field);t&&t.classList.add("group-end")}}(s,n,i))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#O.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 tt({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 it extends i{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=tt({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=tt({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??[],s=document.createElement("div");s.className="cell group-full",s.style.gridColumn="1 / -1",s.setAttribute("role","gridcell"),s.setAttribute("data-col","0"),s.appendChild(this.createToggleButton(e.__groupExpanded,i));const a=document.createElement("span");if(a.className="group-label",a.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),s.appendChild(a),!1!==n.showRowCount){const t=document.createElement("span");t.className="group-count",t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,s.appendChild(t)}const l=Object.entries(r);if(l.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[t,i]of l){const n=this.columns.find(e=>e.field===t),r=h(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&&s.appendChild(e)}t.appendChild(s)}renderPerColumnGroupRow(e,t,i){const n=this.config,r=n.aggregators??{},o=this.columns,s=e.__groupRows??[],a=this.gridElement?.querySelector(".body"),l=a?.style.gridTemplateColumns||"";l&&(t.style.display="grid",t.style.gridTemplateColumns=l);let d=!1;o.forEach((o,a)=>{const l=document.createElement("div");if(l.className="cell group-cell",l.setAttribute("data-col",String(a)),l.setAttribute("role","gridcell"),Oe(o))return l.setAttribute("data-field",o.field),void t.appendChild(l);if(d){const e=r[o.field];if(e){const t=h(e,s,o.field,o);l.textContent=null!=t?String(t):""}else l.textContent=""}else{d=!0,l.appendChild(this.createToggleButton(e.__groupExpanded,i));const t=document.createElement("span"),a=r[o.field];if(a){const i=h(a,s,o.field,o);t.textContent=String(null!=i?i:e.__groupValue)}else t.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(l.appendChild(t),!1!==n.showRowCount){const e=document.createElement("span");e.className="group-count",e.textContent=` (${s.length})`,l.appendChild(e)}}t.appendChild(l)})}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 nt(e,t){const i=new Set(e);return i.has(t)?i.delete(t):i.add(t),i}function rt(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 ot extends i{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#h(){return this.grid}get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,collapseOnClickOutside:!1,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail()}parseLightDomDetail(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=this.#h.__frameworkAdapter;if(i?.parseDetailElement){const e=i.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"),a=t.getAttribute("height"),l={};null!==n&&(l.animation="false"!==n&&n),null!==r&&(l.showExpandColumn="false"!==r),null!==o&&(l.expandOnRowClick="true"===o),null!==s&&(l.collapseOnClickOutside="true"===s),null!==a&&(l.detailHeight="auto"===a?"auto":parseInt(a,10));const d=t.innerHTML.trim();d&&!this.config.detailRenderer&&(l.detailRenderer=(e,t)=>{const i=g(d,{value:e,row:e});return p(i)}),Object.keys(l).length>0&&(this.config={...this.config,...l})}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.#Q(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)}#Q(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:ot.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){this.expandedRows=nt(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(Oe)}(t);if(i)return t;const n=(r=this.name,{field:Ke,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.#X())}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusCol,i=this.grid._focusRow,n=this.visibleColumns[t];if(!n||!Oe(n))return;const r=this.rows[i];return r?(e.preventDefault(),this.toggleAndEmit(r,i),this.requestRenderWithFocus(),!0):void 0}afterRender(){this.#X()}onScrollRender(){this.config.detailRenderer&&0!==this.expandedRows.size&&this.#X()}#X(){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.#h.__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=rt(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.#Q(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=nt(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.#h;"function"==typeof e.refreshColumns?e.refreshColumns():this.requestRender()}}}function st(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 at(e,t){const i=e.findIndex(e=>e.field===t);return i>=0?i+1:void 0}function lt(e,t){return e.find(e=>e.field===t)?.direction}class dt extends i{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;get#h(){return this.grid}clearCoreSortState(){this.#h._sortState=null}detach(){this.sortModel=[],this.cachedSortResult=null}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.#h;if(!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??st)(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;if(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?.(),this.sortModel.length>0){const e=this.sortModel.map(e=>{const t=this.columns.find(t=>t.field===e.field);return`${t?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`});l(this.gridElement,`Sorted by ${e.join(", then ")}`)}else l(this.gridElement,"Sort cleared");return!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=at(this.sortModel,i),r=lt(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){if(this.sortModel=[...e],this.clearCoreSortState(),this.emit("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.(),e.length>0){const t=e.map(e=>{const t=this.columns.find(t=>t.field===e.field);return`${t?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`});l(this.gridElement,`Sorted by ${t.join(", then ")}`)}}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.emit("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.(),l(this.gridElement,"Sort cleared")}getSortIndex(e){return at(this.sortModel,e)}getSortDirection(e){return lt(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 ct(e){return e.pinned??e.sticky??e.meta?.pinned??e.meta?.sticky}function ut(e,t){return m(e,t)}function ht(e,t){const i=ct(e);return!!i&&"left"===ut(i,t)}function gt(e,t){const i=ct(e);return!!i&&"right"===ut(i,t)}function pt(e){return e.some(e=>null!=ct(e))}function ft(e,t){const i=Array.from(e.querySelectorAll(".header-row .cell"));if(!i.length)return;const n=f(e);let r=0;for(const s of t)if(ht(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(gt(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 mt(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 wt="canMoveColumn";class bt extends i{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:wt,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;#J=[];detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1,this.#J=[]}static detect(e,t){const i=t?.columns;return!!Array.isArray(i)&&pt(i)}processColumns(e){const t=[...e];if(this.isApplied=pt(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=ct(o);e?"left"===ut(e,t)?i.push(o):r.push(o):n.push(o)}return[...i,...n,...r]}(t,i?f(i):"ltr")}afterRender(){if(!this.isApplied)return;const e=this.gridElement,t=[...this.columns];if(!pt(t))return mt(e),void(this.isApplied=!1);queueMicrotask(()=>{ft(e,t)})}handleQuery(e){switch(e.type){case wt:return null==ct(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!=ct(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.gridElement;if(t){0===this.#J.length&&(this.#J=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.#J.indexOf(e);if(s>=0){let e=o.length;for(let t=0;t<o.length;t++){if(ct(o[t]))continue;if(this.#J.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!=ct(e))||(this.#J=[]),r.columns=o}}refreshStickyOffsets(){const e=[...this.columns];ft(this.gridElement,e)}getLeftPinnedColumns(){return function(e,t="ltr"){return e.filter(e=>ht(e,t))}([...this.columns],f(this.gridElement))}getRightPinnedColumns(){return function(e,t="ltr"){return e.filter(e=>gt(e,t))}([...this.columns],f(this.gridElement))}clearStickyPositions(){mt(this.gridElement)}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.gridElement.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 vt(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=St(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 yt(e){const t=document.createElement("div");return t.className=`tbw-aggregation-rows tbw-aggregation-rows-${e}`,t.setAttribute("role","presentation"),t}function xt(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?Ct(t,o,i,n):Rt(t,o,i,n),e.appendChild(t)}}function Ct(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}=Et(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 Rt(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}=Et(t,r,n);i.textContent=null!=o?s?s(o,r.field,r):String(o):"",e.appendChild(i)}}function Et(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=w(o.aggFunc);e&&(n=e(i,t.field,t)),r=o.formatter}else{const e=w(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 St(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 kt(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 At extends i{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=kt(this.sourceRows,this.columns,this.gridElement,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=yt("top");const i=e.querySelector(".header");i&&i.nextSibling?t.insertBefore(this.topAggregationContainer,i.nextSibling):t.appendChild(this.topAggregationContainer)}xt(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=vt(this.config,r);this.infoBarElement.replaceWith(e),this.infoBarElement=e}else this.infoBarElement=vt(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=yt("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),xt(this.bottomAggregationContainer,a,this.visibleColumns,this.sourceRows,this.config.fullWidth)),d&&(this.infoBarElement=vt(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 kt(this.rows,this.columns,this.gridElement,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 _t=b;function It(e,t){return[...e,t].join("|")}function Lt(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=Tt(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=It([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 Tt(e,t,i,n,r,o,s){const a=[];if(0===t.length){const t=Ft(e,i,n,r),l=Mt(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=Ft(g,i,n,r),l=Mt(t);let u;c&&(u=Tt(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 Ft(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=_t(i.aggFunc),a=n.length>0?s(n):null;r[It([o],i.field)]=a}return r}function Mt(e){let t=0;for(const i of Object.values(e))t+=i??0;return t}const Dt=["sum","avg","count","min","max","first","last"];function qt(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(Gt("Options",()=>function(e,t){const{config:i,callbacks:n,signal:r}=t,o=document.createElement("div");return o.className="tbw-pivot-options",o.appendChild(zt("Enable Pivot View",e,e=>{n.onTogglePivot(e)},r)),o.appendChild(zt("Show Row Totals",i.showTotals??!0,e=>{n.onOptionChange("showTotals",e)},r)),o.appendChild(zt("Show Grand Total",i.showGrandTotal??!0,e=>{n.onOptionChange("showGrandTotal",e)},r)),o}(i,o))),s.appendChild(Gt("Row Groups",()=>Pt("rowGroups",o))),s.appendChild(Gt("Column Groups",()=>Pt("columnGroups",o))),s.appendChild(Gt("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(Nt(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(Gt("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 Gt(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 Pt(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(Ht(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 Ht(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 Nt(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 Dt){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 zt(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 Kt extends i{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:Kt.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=Lt(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=It([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(Kt.PANEL_ID)||this.grid.toggleToolPanelSection(Kt.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(Kt.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(Kt.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 qt(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 Ot="tbw-print-isolation-style";async function Vt(t,i={}){const{orientation:n="landscape"}=i,r=t.id;document.querySelectorAll(`#${CSS.escape(r)}`).length>1&&e(v,`Multiple elements found with id="${r}". Print isolation may not work correctly. Ensure each grid has a unique ID.`,r,"print"),document.getElementById(Ot)?.remove();const o=function(e,t){const i=document.createElement("style");return i.id=Ot,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}(r,n);return document.head.appendChild(o),new Promise(e=>{const t=()=>{window.removeEventListener("afterprint",t),document.getElementById(Ot)?.remove(),e()};window.addEventListener("afterprint",t),window.print(),setTimeout(()=>{window.removeEventListener("afterprint",t),document.getElementById(Ot)?.remove(),e()},5e3)})}const Bt={button:!1,orientation:"landscape",warnThreshold:500,maxRows:0,includeTitle:!0,includeTimestamp:!0,title:"",isolate:!1};class $t extends i{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}}}";#ee=!1;#te=null;#ie=null;#ne=null;#re=null;#oe=null;#se=null;get#h(){return this.grid}isPrinting(){return this.#ee}async print(e){if(this.#ee)return void this.warn(y,"Print already in progress");const t=this.gridElement;if(!t)return void this.warn(x,"Grid not available");const i={...Bt,...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.#ee=!0;const s=performance.now();this.emit("print-start",{rowCount:r,limitApplied:o,originalRowCount:n});try{const e=this.#h;this.#ie={bypassThreshold:e._virtualization?.bypassThreshold??24},this.#ae(),o&&(this.#ne=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,r),await new Promise(e=>setTimeout(e,50))),(i.includeTitle||i.includeTimestamp)&&this.#le(i),await this.#de(),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.#ce(i):await this.#ue(),this.emit("print-complete",{success:!0,rowCount:r,duration:Math.round(performance.now()-s)})}catch(a){C(R,`Print failed: ${a}`,this.gridElement?.id,this.name),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-s)})}finally{this.#he(),this.#ee=!1}}#le(e){const t=this.gridElement;if(t){if(this.#re=document.createElement("div"),this.#re.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.#re.appendChild(i)}if(e.includeTimestamp){const e=document.createElement("div");e.className="tbw-print-header-timestamp",e.textContent=`Printed: ${/* @__PURE__ */(new Date).toLocaleString()}`,this.#re.appendChild(e)}t.insertBefore(this.#re,t.firstChild),this.#oe=document.createElement("div"),this.#oe.className="tbw-print-footer",this.#oe.textContent=`Page generated from ${window.location.hostname}`,t.appendChild(this.#oe)}}async#de(){const e=this.#h;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#ue(){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#ce(e){const t=this.gridElement;t&&await Vt(t,{orientation:e.orientation})}#ae(){const e=this.columns;if(e){this.#te=/* @__PURE__ */new Map;for(const t of e)t.printHidden&&t.field&&(this.#te.set(t.field,!t.hidden),this.grid.setColumnVisible(t.field,!1))}}#ge(){if(this.#te){for(const[e,t]of this.#te)this.grid.setColumnVisible(e,t);this.#te=null}}#he(){const e=this.gridElement;if(!e)return;this.#ge(),e.classList.remove("print-portrait","print-landscape"),null!==this.#se&&(e.style.transform="",e.style.transformOrigin="",e.style.width="",this.#se=null),this.#re&&(this.#re.remove(),this.#re=null),this.#oe&&(this.#oe.remove(),this.#oe=null);const t=this.#h;this.#ie&&t._virtualization&&(t._virtualization.bypassThreshold=this.#ie.bypassThreshold,t.refreshVirtualWindow(!0),this.#ie=null),null!==this.#ne&&(this.grid.rows=this.#ne,this.#ne=null)}afterRender(){this.config?.button&&!this.#pe&&(this.#fe(),this.#pe=!0)}#pe=!1;#fe(){const e=this.#h;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 Wt(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 jt extends i{name="reorderColumns";aliases=["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;get#h(){return this.grid}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),this.gridElement.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=Wt(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.#h,i=t._focusCol,n=t._visibleColumns;if(i<0||i>=n.length)return;const r=n[i];if(!this.canMoveColumnWithPlugins(r))return;const s=this.getColumnOrder(),a=s.indexOf(r.field);if(-1===a)return;const l="ArrowLeft"===e.key?a-1:a+1;if(l<0||l>=s.length)return;const d=n.find(e=>e.field===s[l]);return this.canMoveColumnWithPlugins(d)?(this.moveColumn(r.field,l),t._focusCol=l,o(this.#h),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=Wt(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;t.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),"function"==typeof this.grid.forceLayout?this.grid.forceLayout().then(()=>{this.animateFLIP(t)}):requestAnimationFrame(()=>{this.animateFLIP(t)})}else"fade"===t?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}}const Ut="__tbw_row_drag";class Yt extends i{name="reorderRows";aliases=["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;get#h(){return this.grid}attach(e){super.attach(e),this.setupDelegatedDragListeners()}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:Ut,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(){}onKeyDown(e){if(!this.config.enableKeyboard)return;if(!e.ctrlKey||"ArrowUp"!==e.key&&"ArrowDown"!==e.key)return;const t=this.#h,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)}setupDelegatedDragListeners(){const e=this.gridElement;if(!e)return;const t=this.disconnectSignal;e.addEventListener("dragstart",e=>{const t=e,i=t.target.closest(".dg-row-drag-handle");if(!i)return;const n=i.closest(".data-grid-row");if(!n)return;const r=this.getRowIndex(n);r<0||(this.isDragging=!0,this.draggedRowIndex=r,t.dataTransfer&&(t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",String(r))),n.classList.add("dragging"))},{signal:t}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.clearDragClasses()},{signal:t}),e.addEventListener("dragover",e=>{const t=e;if(!this.isDragging||null===this.draggedRowIndex)return;const i=t.target.closest(".data-grid-row");if(!i)return;t.preventDefault();const n=this.getRowIndex(i);if(n<0||n===this.draggedRowIndex)return;const r=i.getBoundingClientRect(),o=r.top+r.height/2,s=t.clientY<o;this.dropRowIndex=s?n:n+1,i.classList.add("drop-target"),i.classList.toggle("drop-before",s),i.classList.toggle("drop-after",!s)},{signal:t}),e.addEventListener("dragleave",e=>{const t=e.target.closest(".data-grid-row");t&&t.classList.remove("drop-target","drop-before","drop-after")},{signal:t}),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")}},{signal:t})}handleKeyboardMove(e,t,i,n,r){this.pendingMove?this.pendingMove.currentIndex=i:this.pendingMove={originalIndex:t,currentIndex:i,row:e},this.lastFocusCol=r;const s=this.#h,a=[...s._rows??this.sourceRows],[l]=a.splice(t,1);a.splice(i,0,l),s._rows=a,s._focusRow=i,s._focusCol=r,s.refreshVirtualWindow(!0),o(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 n={row:i,fromIndex:e,toIndex:t,rows:[...this.sourceRows],source:"keyboard"};if(this.emitCancelable("row-move",n)){const i=[...this.sourceRows],[n]=i.splice(t,1);i.splice(e,0,n);const r=this.#h;r._rows=i,r._focusRow=e,r._focusCol=this.lastFocusCol,r.refreshVirtualWindow(!0),o(r)}}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)}}class Zt extends i{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] .data-grid-row>.cell[data-responsive-hidden]{display:none!important}tbw-grid[data-responsive] .data-grid-row>.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"}]};#me;#we=!1;#be;#ve=!1;#ye=0;#xe=/* @__PURE__ */new Set;#Ce=/* @__PURE__ */new Set;#Re=null;#Ee=[];get#h(){return this.grid}isResponsive(){return this.#we}setResponsive(e){e!==this.#we&&(this.#we=e,this.#Se(),this.emit("responsive-change",{isResponsive:e,width:this.#ye,breakpoint:this.config.breakpoint??0}),this.requestRender())}setBreakpoint(e){this.config.breakpoint=e,this.#ke(this.#ye)}setCardRenderer(e){this.config.cardRenderer=e,this.#we&&this.requestRender()}getWidth(){return this.#ye}getActiveBreakpoint(){return this.#Re}attach(e){super.attach(e),this.#Ae(),this.#_e(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#Ee=[...this.config.breakpoints].sort((e,t)=>t.maxWidth-e.maxWidth)),this.#me=new ResizeObserver(e=>{const t=e[0]?.contentRect.width??0;this.#ye=t,clearTimeout(this.#be),this.#be=setTimeout(()=>{this.#ke(t)},this.config.debounceMs??100)}),this.#me.observe(this.gridElement)}#Ae(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=this.#h.__frameworkAdapter;if(i?.parseResponsiveCardElement){const e=i.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"),a=t.getAttribute("debounce-ms"),l={};if(null!==n){const e=parseInt(n,10);isNaN(e)||(l.breakpoint=e)}if(null!==r&&(l.cardRowHeight="auto"===r?"auto":parseInt(r,10)),null!==o&&(l.hiddenColumns=o.split(",").map(e=>e.trim()).filter(e=>e.length>0)),null!==s&&(l.hideHeader="false"!==s),null!==a){const e=parseInt(a,10);isNaN(e)||(l.debounceMs=e)}const d=t.innerHTML.trim();!d||this.config.cardRenderer||i?.parseResponsiveCardElement||(l.cardRenderer=e=>{const t=g(d,{value:e,row:e}),i=p(t),n=document.createElement("div");return n.className="tbw-responsive-card-content",n.innerHTML=i,n}),Object.keys(l).length>0&&(this.config={...this.config,...l})}#_e(e){if(this.#xe.clear(),this.#Ce.clear(),e)for(const t of e)"string"==typeof t?this.#xe.add(t):t.showValue?this.#Ce.add(t.field):this.#xe.add(t.field)}detach(){this.#me?.disconnect(),this.#me=void 0,clearTimeout(this.#be),this.#be=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if("isCardMode"===e.type)return this.#we}afterRender(){this.#Ie();if(!(this.#Ee.length>0?null!==this.#Re:this.#we))return;const e=this.#xe.size>0,t=this.#Ce.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.#xe.has(e)?(n.setAttribute("data-responsive-hidden",""),n.removeAttribute("data-responsive-value-only")):this.#Ce.has(e)?(n.setAttribute("data-responsive-value-only",""),n.removeAttribute("data-responsive-hidden")):(n.removeAttribute("data-responsive-hidden"),n.removeAttribute("data-responsive-value-only")))}}#ke(e){if(this.#Ee.length>0)return void this.#Le(e);const t=this.config.breakpoint??0;0!==t||this.#ve||(this.#ve=!0,this.warn(E,"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.#we&&(this.#we=i,this.#Se(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#Le(e){let t=null;for(const i of this.#Ee)e<=i.maxWidth&&(t=i);if(t!==this.#Re){this.#Re=t,t?.hiddenColumns?this.#_e(t.hiddenColumns):this.#_e(this.config.hiddenColumns);const i=!0===t?.cardLayout;i!==this.#we&&(this.#we=i,this.#Se()),this.emit("responsive-change",{isResponsive:this.#we,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#Te;#Se(){this.gridElement.toggleAttribute("data-responsive",this.#we);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.#h;if(this.#we){t._virtualization&&(this.#Te=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.#Te&&this.#Te>0&&t._virtualization&&(t._virtualization.rowHeight=this.#Te,this.#Te=void 0),this.#Fe=void 0,this.#Me=void 0,this.#De=void 0}}renderRow(e,t,i){if(!this.#we||!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;return t.style.height="auto"===r||void 0===r?"auto":`${this.#qe()}px`,t.appendChild(n),!0}onKeyDown(e){if(!this.#we)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(),o(this.#h),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),o(this.#h),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),o(this.#h),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),o(this.#h),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),o(this.#h),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),o(this.#h),!0}return!1}#Fe;#Me;#De;#qe(){if(this.#Fe&&this.#Fe>0)return this.#Fe;const e=this.config.cardRowHeight;return"number"==typeof e&&e>0?e:80}#Ge(){return this.#Me&&this.#Me>0?this.#Me:this.#Te??28}#Pe(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}#He(){let e=0,t=0;for(const i of this.rows)i.__isGroupRow?e++:t++;return{groupCount:e,cardCount:t}}getExtraHeight(){if(!this.#we||!this.config.cardRenderer)return 0;if(!this.#Pe())return 0;const e=this.#Te??28,t=this.#Ge(),i=this.#qe(),{groupCount:n,cardCount:r}=this.#He();return n*Math.max(0,t-e)+r*Math.max(0,i-e)}getExtraHeightBefore(e){if(!this.#we||!this.config.cardRenderer)return 0;if(!this.#Pe())return 0;const t=this.#Te??28,i=this.#Ge(),n=this.#qe(),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.#we&&this.config.cardRenderer)return e.__isGroupRow?this.#Ge():this.#qe()}#Ne(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#ze=!1;#Ie(){if(!this.#we||!this.config.cardRenderer)return;let e=!1;const t=this.#h,i=this.#Pe(),n=this.#Ne();if(n!==this.#De&&(this.#De=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.#Me&&(this.#Me=i,e=!0)}}const r=this.gridElement.querySelector(".data-grid-row.responsive-card");if(r){const n=r.getBoundingClientRect().height;n>0&&n!==this.#Fe&&(this.#Fe=n,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=n))}e&&!this.#ze&&(this.#ze=!0,queueMicrotask(()=>{this.#ze=!1,this.grid&&this.#we&&this.#h.refreshVirtualWindow?.(!0,!0)}))}}function Qt(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 Xt(e){const t=Qt(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function Jt(e){return e.map(Xt)}function ei(e,t,i){return i.some(i=>function(e,t,i){const n=Qt(i);return e>=n.startRow&&e<=n.endRow&&t>=n.startCol&&t<=n.endCol}(e,t,i))}function ti(e){const t=[],i=Qt(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 ii(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function ni(e,t){const i=Qt(e),n=Qt(t);return i.startRow===n.startRow&&i.startCol===n.startCol&&i.endRow===n.endRow&&i.endCol===n.endCol}const ri="__tbw_checkbox";class oi extends i{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;pendingRowKeyUpdate=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.pendingRowKeyUpdate=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.#Ke()),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.#Ke()),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=ii(this.cellAnchor,{row:t,col:i}),n=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(n&&ni(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&&ni(this.ranges[0],e))return!1;this.ranges=[e],this.activeRange=e,this.cellAnchor={row:t,col:i}}return this.emit("selection-change",this.#Ke()),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.#Ke()),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.#Ke()),this.requestAfterRender()}),!1;if("row"===t){const t=!1!==this.config.multiSelect;if("ArrowUp"===e.key||"ArrowDown"===e.key||"PageUp"===e.key||"PageDown"===e.key||(e.ctrlKey||e.metaKey)&&("Home"===e.key||"End"===e.key)){const i=e.shiftKey&&t;return i&&null===this.anchor&&(this.anchor=this.grid._focusRow),this.explicitSelection=!0,this.pendingRowKeyUpdate={shiftKey:i},queueMicrotask(()=>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&&ni(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.#Ke()),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=ii(this.cellAnchor,{row:e.rowIndex,col:t}),r=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return r&&ni(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.#Ke()),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===ri))return e;const t=this.#Oe(),i=e.findIndex(Oe),n=i>=0?i+1:0;return[...e.slice(0,n),t,...e.slice(n)]}return e}#Oe(){return{field:ri,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}}}#Ve(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),i=t?S(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}}#Be(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.#Ke()))))}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.#Ke()))}}}#$e(){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"),e.setAttribute("aria-selected","false"),i&&e.removeAttribute("data-selectable")}),"row"===t&&(k(e),n.forEach(e=>{const t=e.querySelector(".cell[data-row]"),n=S(t);n>=0&&(i&&!this.isRowSelectable(n)&&e.setAttribute("data-selectable","false"),this.selected.has(n)&&(e.classList.add("selected","row-focus"),e.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#Ve(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){k(e);const t=this.ranges.map(Qt),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"),e.setAttribute("aria-selected","true"),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.pendingRowKeyUpdate&&"row"===i){const{shiftKey:e}=this.pendingRowKeyUpdate;this.pendingRowKeyUpdate=null;const t=this.grid._focusRow;if(e&&null!==this.anchor){this.selected.clear();const e=Math.min(this.anchor,t),i=Math.max(this.anchor,t);for(let t=e;t<=i;t++)this.isRowSelectable(t)&&this.selected.add(t)}else this.isRowSelectable(t)?(this.selected.clear(),this.selected.add(t),this.anchor=t):this.selected.clear();this.lastSelected=t,this.emit("selection-change",this.#Ke())}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=ii(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.#Ke())}this.#Be(i),this.gridElement.setAttribute("data-selection-mode",i),t&&t.classList.toggle("selecting",this.isDragging),this.#$e()}onScrollRender(){this.isSelectionEnabled()&&this.#$e()}getSelection(){return{mode:this.config.mode,ranges:this.#Ke().ranges,anchor:this.cellAnchor}}getSelectedCells(){return function(e){const t=/* @__PURE__ */new Map;for(const i of e)for(const e of ti(i))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return ei(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.#Ke()),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.#Ke()),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.#Ke()),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:Jt(this.ranges)}),this.requestAfterRender()}#Ke(){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:Jt(t.ranges)}:{mode:e,ranges:[]}}(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length)}}function si(e,t){return Math.floor(e/t)}async function ai(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 li(e,t,i){const n=si(e,t),r=i.get(n);if(!r)return;return r[e%t]}class di extends i{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;managedRows=[];detach(){this.dataSource=null,this.totalRowCount=0,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedRows=[],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=si(e,i),r=si(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),ai(this.dataSource,r,t,{}).then(e=>{this.loadedBlocks.set(r,e.rows),this.totalRowCount=e.totalRowCount,this.loadingBlocks.delete(r);const i=r*t;for(let t=0;t<e.rows.length;t++)i+t<this.managedRows.length&&(this.managedRows[i+t]=e.rows[t]);this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(()=>{this.loadingBlocks.delete(r)})}}processRows(e){if(!this.dataSource)return[...e];const t=this.config.cacheBlockSize??100;for(;this.managedRows.length<this.totalRowCount;){const e=this.managedRows.length;this.managedRows.push({__loading:!0,__index:e})}this.managedRows.length=this.totalRowCount;for(let i=0;i<this.totalRowCount;i++){const e=li(i,t,this.loadedBlocks);e&&(this.managedRows[i]=e)}return this.managedRows}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(),this.managedRows=[];ai(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.managedRows=[],this.requestRender())}purgeCache(){this.loadedBlocks.clear(),this.managedRows=[]}getTotalRowCount(){return this.totalRowCount}isRowLoaded(e){const t=si(e,this.config.cacheBlockSize??100);return this.loadedBlocks.has(t)}getLoadedBlockCount(){return this.loadedBlocks.size}}function ci(e,t,i){return void 0!==e.id?String(e.id):i?`${i}-${t}`:String(t)}function ui(e,t){const i=new Set(e);return i.has(t)?i.delete(t):i.add(t),i}function hi(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=ci(a,s,i),d=a[r];if(Array.isArray(d)&&d.length>0){o.add(l);const e=hi(d,t,l,n+1);for(const t of e)o.add(t)}}return o}function gi(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=ci(a,s,n);if(l===t)return[l];const d=a[o];if(Array.isArray(d)&&d.length>0){const e=gi(d,t,i,l,r+1);if(e)return[l,...e]}}return null}function pi(e,t,i,n){const r=gi(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 fi(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 mi extends i{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 fi(t,i)}processRows(e){const t=e;if(!fi(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=hi(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=ui(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=ui(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.gridElement?.querySelector(".rows");if(!e)return;const t=this.animationStyle,i=!1!==t&&this.keysToAnimate.size>0,n="fade"===t?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const r of e.querySelectorAll(".data-grid-row")){const e=r.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,o=this.flattenedRows[t];o?.hasChildren&&r.setAttribute("aria-expanded",String(o.isExpanded)),i&&o?.key&&this.keysToAnimate.has(o.key)&&(r.classList.add(n),r.addEventListener("animationend",()=>r.classList.remove(n),{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=ui(this.expandedKeys,e),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=hi(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=pi(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}function wi(e,t,i){const n=[...e.undoStack,t];for(;n.length>i;)n.shift();return{undoStack:n,redoStack:[]}}function bi(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 vi(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 yi extends i{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];#We=!1;#je=null;#Ue(e,t){const i=this.rows[e.rowIndex];if(i){try{const n=this.grid.getRowId(i);if(n)return void this.grid.updateRow(n,{[e.field]:t})}catch{}i[e.field]=t}}#Ye(e){const t=this.grid,i=t._visibleColumns?.findIndex(t=>t.field===e.field)??-1;if(i<0)return;t._focusRow=e.rowIndex,t._focusCol=i;const n=t.findRenderedRowElement?.(e.rowIndex);if(!n)return;const r=n.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const e=r.querySelector(A);e?.focus({preventScroll:!0})}}#Ze(e,t){if(this.#We=!0,"compound"===e.type){const i="undo"===t?[...e.actions].reverse():e.actions;for(const e of i)this.#Ue(e,"undo"===t?e.oldValue:e.newValue)}else this.#Ue(e,"undo"===t?e.oldValue:e.newValue);this.#We=!1}#Qe(e){const t="compound"===e.type?e.actions[e.actions.length-1]:e;t&&this.#Ye(t)}attach(e){super.attach(e),this.on("cell-edit-committed",e=>{this.#We||this.recordEdit(e.rowIndex,e.field,e.oldValue,e.newValue)})}detach(){this.undoStack=[],this.redoStack=[],this.#je=null}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){e.preventDefault();const t=bi({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#Ze(t.action,"undo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.emit("undo",{action:t.action,type:"undo"}),this.#Qe(t.action),this.requestRenderWithFocus()),!0}if(i){e.preventDefault();const t=vi({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#Ze(t.action,"redo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.emit("redo",{action:t.action,type:"redo"}),this.#Qe(t.action),this.requestRenderWithFocus()),!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);if(this.#je)return void this.#je.push(r);const o=wi({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=o.undoStack,this.redoStack=o.redoStack}beginTransaction(){this.#je&&d(_,"Transaction already in progress. Call endTransaction() first."),this.#je=[]}endTransaction(){const e=this.#je;if(e||d(I,"No transaction in progress. Call beginTransaction() first."),this.#je=null,0===e.length)return;const t=1===e.length?e[0]:{type:"compound",actions:e,timestamp:Date.now()};const i=wi({undoStack:this.undoStack,redoStack:this.redoStack},t,this.config.maxHistorySize??100);this.undoStack=i.undoStack,this.redoStack=i.redoStack}undo(){const e=bi({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#Ze(e.action,"undo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.#Qe(e.action),this.requestRenderWithFocus()),e.action}redo(){const e=vi({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#Ze(e.action,"redo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.#Qe(e.action),this.requestRenderWithFocus()),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,this.#je=null}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}function xi(e){const t=e.meta??{};return!0!==t.lockPosition&&!0!==t.suppressMovable}class Ci extends i{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),this.gridElement.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:Ci.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(Ci.PANEL_ID)||this.grid.toggleToolPanelSection(Ci.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(Ci.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(Ci.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&&xi(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&&xi(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{Ge as BLANK_FILTER_VALUE,i as BaseGridPlugin,J as ClipboardPlugin,oe as ColumnVirtualizationPlugin,fe as ContextMenuPlugin,L as DEFAULT_ANIMATION_CONFIG,n as DEFAULT_GRID_ICONS,T as DGEvents,F as DataGridElement,Te as EditingPlugin,qe as ExportPlugin,Ue as FilteringPlugin,M as FitModeEnum,D as GridCSSVars,q as GridClasses,G as GridDataAttrs,P as GridElement,H as GridSelectors,et as GroupingColumnsPlugin,it as GroupingRowsPlugin,ot as MasterDetailPlugin,dt as MultiSortPlugin,N as PLUGIN_QUERIES,bt as PinnedColumnsPlugin,At as PinnedRowsPlugin,Kt as PivotPlugin,z as PluginEvents,K as PluginManager,$t as PrintPlugin,Ut as ROW_DRAG_HANDLE_FIELD,O as RenderPhase,jt as ReorderPlugin,Zt as ResponsivePlugin,Yt as RowReorderPlugin,oi as SelectionPlugin,di as ServerSidePlugin,mi as TreePlugin,yi as UndoRedoPlugin,Ci as VisibilityPlugin,V as builtInSort,B as createGrid,$ as defaultComparator,be as defaultEditorFor,X as defaultPasteHandler,ze as getUniqueValuesBatch,Vt as printGridIsolated,W as queryGrid,Ze as resolveColumnGroupDefs,j as setFeatureResolver,Ye as slugifyHeader};//# sourceMappingURL=all.js.map