@toolbox-web/grid 1.19.1 → 1.19.3

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.
Files changed (43) hide show
  1. package/all.js +49 -42
  2. package/all.js.map +1 -1
  3. package/index.js +367 -341
  4. package/index.js.map +1 -1
  5. package/lib/core/grid.d.ts.map +1 -1
  6. package/lib/core/internal/rows.d.ts.map +1 -1
  7. package/lib/core/internal/utils.d.ts +2 -2
  8. package/lib/core/internal/utils.d.ts.map +1 -1
  9. package/lib/core/plugin/types.d.ts +0 -2
  10. package/lib/core/plugin/types.d.ts.map +1 -1
  11. package/lib/core/types.d.ts +11 -0
  12. package/lib/core/types.d.ts.map +1 -1
  13. package/lib/plugins/clipboard/index.js.map +1 -1
  14. package/lib/plugins/column-virtualization/index.js.map +1 -1
  15. package/lib/plugins/context-menu/index.js.map +1 -1
  16. package/lib/plugins/editing/index.js.map +1 -1
  17. package/lib/plugins/export/index.js.map +1 -1
  18. package/lib/plugins/filtering/index.js.map +1 -1
  19. package/lib/plugins/grouping-columns/index.js.map +1 -1
  20. package/lib/plugins/grouping-rows/index.js.map +1 -1
  21. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
  22. package/lib/plugins/master-detail/index.js +62 -55
  23. package/lib/plugins/master-detail/index.js.map +1 -1
  24. package/lib/plugins/multi-sort/index.js.map +1 -1
  25. package/lib/plugins/pinned-columns/index.js.map +1 -1
  26. package/lib/plugins/pinned-rows/index.js.map +1 -1
  27. package/lib/plugins/pivot/index.js.map +1 -1
  28. package/lib/plugins/print/index.js.map +1 -1
  29. package/lib/plugins/reorder/index.js.map +1 -1
  30. package/lib/plugins/responsive/index.js.map +1 -1
  31. package/lib/plugins/row-reorder/index.js.map +1 -1
  32. package/lib/plugins/selection/index.js.map +1 -1
  33. package/lib/plugins/server-side/index.js.map +1 -1
  34. package/lib/plugins/tree/index.js.map +1 -1
  35. package/lib/plugins/undo-redo/index.js.map +1 -1
  36. package/lib/plugins/visibility/index.js.map +1 -1
  37. package/package.json +11 -1
  38. package/umd/grid.all.umd.js +24 -24
  39. package/umd/grid.all.umd.js.map +1 -1
  40. package/umd/grid.umd.js +11 -11
  41. package/umd/grid.umd.js.map +1 -1
  42. package/umd/plugins/master-detail.umd.js +1 -1
  43. package/umd/plugins/master-detail.umd.js.map +1 -1
package/umd/grid.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(_,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(_=typeof globalThis<"u"?globalThis:_||self,V(_.TbwGrid={}))})(this,(function(_){"use strict";function V(){return{rowCount:-1,colCount:-1,ariaLabel:void 0,ariaDescribedBy:void 0}}function pt(t,e,i,o,n){if(o===t.rowCount&&n===t.colCount)return!1;const r=t.rowCount;return t.rowCount=o,t.colCount=n,e&&(e.setAttribute("aria-rowcount",String(o)),e.setAttribute("aria-colcount",String(n))),o!==r&&i&&(o>0?i.setAttribute("role","rowgroup"):i.removeAttribute("role")),!0}function wt(t,e){const i=t?.gridAriaLabel;return i||(t?.shell?.header?.title??e?.lightDomTitle??void 0)}function bt(t,e,i,o){if(!e)return!1;let n=!1;const r=wt(i,o);r!==t.ariaLabel&&(t.ariaLabel=r,r?e.setAttribute("aria-label",r):e.removeAttribute("aria-label"),n=!0);const s=i?.gridAriaDescribedBy;return s!==t.ariaDescribedBy&&(t.ariaDescribedBy=s,s?e.setAttribute("aria-describedby",s):e.removeAttribute("aria-describedby"),n=!0),n}const W={STRETCH:"stretch",FIXED:"fixed"},Re={mode:"reduced-motion",duration:200,easing:"ease-out"},Ae='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',k={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:Ae,filterActive:Ae,print:"🖨️"};function mt(t){return Array.from(t.querySelectorAll("tbw-grid-column")).map(i=>{const o=i.getAttribute("field")||"";if(!o)return null;const n=i.getAttribute("type")||void 0,s=n&&new Set(["number","string","date","boolean","select"]).has(n)?n:void 0,l=i.getAttribute("header")||void 0,a=i.hasAttribute("sortable"),c=i.hasAttribute("editable"),h={field:o,type:s,header:l,sortable:a,editable:c},f=i.getAttribute("width");if(f){const m=parseFloat(f);!isNaN(m)&&/^\d+(\.\d+)?$/.test(f.trim())?h.width=m:h.width=f}const p=i.getAttribute("minWidth")||i.getAttribute("min-width");if(p){const m=parseFloat(p);isNaN(m)||(h.minWidth=m)}i.hasAttribute("resizable")&&(h.resizable=!0),i.hasAttribute("sizable")&&(h.resizable=!0);const g=i.getAttribute("editor"),u=i.getAttribute("renderer");g&&(h.__editorName=g),u&&(h.__rendererName=u);const d=i.getAttribute("options");d&&(h.options=d.split(",").map(m=>{const[L,$]=m.includes(":")?m.split(":"):[m.trim(),m.trim()];return{value:L.trim(),label:$?.trim()||L.trim()}}));const w=i.querySelector("tbw-grid-column-view"),v=i.querySelector("tbw-grid-column-editor"),b=i.querySelector("tbw-grid-column-header");w&&(h.__viewTemplate=w),v&&(h.__editorTemplate=v),b&&(h.__headerTemplate=b);const T=globalThis.DataGridElement?.getAdapters?.()??[],S=w??i,H=T.find(m=>m.canHandle(S));if(H){const m=H.createRenderer(S);m&&(h.viewRenderer=m)}const C=v??i,y=T.find(m=>m.canHandle(C));if(y){const m=y.createEditor(C);m&&(h.editor=m)}return h}).filter(i=>!!i)}function Te(t,e){if((!t||!t.length)&&(!e||!e.length))return[];if(!t||!t.length)return e||[];if(!e||!e.length)return t;const i={};e.forEach(n=>{const r=i[n.field];if(r){n.header&&!r.header&&(r.header=n.header),n.type&&!r.type&&(r.type=n.type),n.sortable&&(r.sortable=!0),n.editable&&(r.editable=!0),n.resizable&&(r.resizable=!0),n.width!=null&&r.width==null&&(r.width=n.width),n.minWidth!=null&&r.minWidth==null&&(r.minWidth=n.minWidth),n.__viewTemplate&&(r.__viewTemplate=n.__viewTemplate),n.__editorTemplate&&(r.__editorTemplate=n.__editorTemplate),n.__headerTemplate&&(r.__headerTemplate=n.__headerTemplate);const s=n.renderer||n.viewRenderer,l=r.renderer||r.viewRenderer;s&&!l&&(r.viewRenderer=s,n.renderer&&(r.renderer=s)),n.editor&&!r.editor&&(r.editor=n.editor)}else i[n.field]={...n}});const o=t.map(n=>{const r=i[n.field];if(!r)return n;const s={...n};r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=n.sortable||r.sortable,(n.resizable===!0||r.resizable===!0)&&(s.resizable=!0),s.editable=n.editable||r.editable,r.width!=null&&s.width==null&&(s.width=r.width),r.minWidth!=null&&s.minWidth==null&&(s.minWidth=r.minWidth),r.__viewTemplate&&(s.__viewTemplate=r.__viewTemplate),r.__editorTemplate&&(s.__editorTemplate=r.__editorTemplate),r.__headerTemplate&&(s.__headerTemplate=r.__headerTemplate);const l=r.renderer||r.viewRenderer,a=s.renderer||s.viewRenderer;return l&&!a&&(s.viewRenderer=l,r.renderer&&(s.renderer=l)),r.editor&&!s.editor&&(s.editor=r.editor),delete i[n.field],s});return Object.keys(i).forEach(n=>o.push(i[n])),o}function xe(t,e){try{t.part?.add?.(e)}catch{}const i=t.getAttribute("part");i?i.split(/\s+/).includes(e)||t.setAttribute("part",i+" "+e):t.setAttribute("part",e)}function He(t){const e=t.effectiveConfig?.fitMode||t.fitMode||W.STRETCH;if(e!==W.STRETCH&&e!==W.FIXED||t.__didInitialAutoSize||!t.isConnected)return;const i=Array.from(t._headerRowEl?.children||[]);if(!i.length)return;let o=!1;t._visibleColumns.forEach((n,r)=>{if(n.width)return;const s=i[r];let l=s?s.scrollWidth:0;for(const a of t._rowPool){const c=a.children[r];if(c){const h=c.scrollWidth;h>l&&(l=h)}}l>0&&(n.width=l+2,n.__autoSized=!0,o=!0)}),o&&G(t),t.__didInitialAutoSize=!0}const vt=/^(?:\d+(?:\.\d+)?(?:px|%|fr|em|rem|ch|vw|vh|vmin|vmax)|calc\(.+\)|min-content|max-content|minmax\(.+\)|fit-content\(.+\)|auto)$/i;function Le(t,e){return typeof t=="number"?`${t}px`:(vt.test(t)||console.warn(`[tbw-grid] Column '${e??"?"}' has an invalid CSS width value: '${t}'. Expected a number (px) or a valid CSS unit string (e.g. '30%', '2fr', 'calc(...)').`),t)}function G(t){(t.effectiveConfig?.fitMode||t.fitMode||W.STRETCH)===W.STRETCH?t._gridTemplate=t._visibleColumns.map(i=>{if(i.width!=null)return Le(i.width,i.field);const o=i.minWidth;return o!=null?`minmax(${o}px, 1fr)`:"1fr"}).join(" ").trim():t._gridTemplate=t._visibleColumns.map(i=>i.width!=null?Le(i.width,i.field):"max-content").join(" "),t.style.setProperty("--tbw-column-template",t._gridTemplate)}function Ct(t){return t==null?"string":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date||typeof t=="string"&&/\d{4}-\d{2}-\d{2}/.test(t)&&!isNaN(Date.parse(t))?"date":"string"}function yt(t,e){const i=t[0]||{},o=Object.keys(i).map(r=>{const s=i[r],l=Ct(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),n={};return o.forEach(r=>{n[r.field]=r.type||"string"}),{columns:o,typeMap:n}}const _t=/{{\s*([^}]+)\s*}}/g,D="__DG_EMPTY__",Et=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,St=/__(proto|defineGetter|defineSetter)|constructor|window|globalThis|global|process|Function|import|eval|Reflect|Proxy|Error|arguments|document|location|cookie|localStorage|sessionStorage|indexedDB|fetch|XMLHttpRequest|WebSocket|Worker|SharedWorker|ServiceWorker|opener|parent|top|frames|self|this\b/;function Rt(t){return!t||typeof t!="string"?"":t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}const At=new Set(["script","iframe","object","embed","form","input","button","textarea","select","link","meta","base","style","template","slot","portal","frame","frameset","applet","noscript","noembed","plaintext","xmp","listing"]),Pe=/^on\w+$/i,Tt=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),xt=/^\s*(javascript|vbscript|data|blob):/i;function F(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,Ht(e.content),e.innerHTML}function Ht(t){const e=[],i=t.querySelectorAll("*");for(const o of i){const n=o.tagName.toLowerCase();if(At.has(n)){e.push(o);continue}if((n==="svg"||o.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(o.attributes).some(l=>Pe.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(o);continue}const r=[];for(const s of o.attributes){const l=s.name.toLowerCase();if(Pe.test(l)){r.push(s.name);continue}if(Tt.has(l)&&xt.test(s.value)){r.push(s.name);continue}if(l==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(s.value)){r.push(s.name);continue}}r.forEach(s=>o.removeAttribute(s))}e.forEach(o=>o.remove())}function ze(t,e){if(!t||t.indexOf("{{")===-1)return t;const i=[],o=t.replace(_t,(l,a)=>{const c=Lt(a,e);return i.push({expr:a.trim(),result:c}),c}),n=Pt(o),r=i.length&&i.every(l=>l.result===""||l.result===D);return N.test(t)||r?"":n}function Lt(t,e){if(t=(t||"").trim(),!t||N.test(t))return D;if(t==="value")return e.value==null?D:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const o=t.slice(4),n=e.row?e.row[o]:void 0;return n==null?D:String(n)}if(t.length>80||!Et.test(t)||St.test(t))return D;const i=t.match(/\./g);if(i&&i.length>1)return D;try{const n=new Function("value","row",`return (${t});`)(e.value,e.row),r=n==null?"":String(n);return N.test(r)?D:r||D}catch{return D}}const N=/Reflect|Proxy|ownKeys/;function Pt(t){return t&&t.replace(new RegExp(D,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,"")}function zt(t){if(N.test(t.textContent||"")){for(const e of t.childNodes)e.nodeType===Node.TEXT_NODE&&N.test(e.textContent||"")&&(e.textContent="");N.test(t.textContent||"")&&(t.textContent="")}}function De(t){const e=N.test(t),i=(o=>e?"":ze(t,o));return i.__blocked=e,i}const Dt=100;class Ot{#l;#n;#u;#d;#h;#a={};#o={};#f=!0;#w=[];#v;#s;#C;#r;#g;constructor(e){this.#r=e}get original(){return this.#a}get effective(){return this.#o}get columns(){return this.#o.columns??[]}set columns(e){this.#o.columns=e}get lightDomColumnsCache(){return this.#d}set lightDomColumnsCache(e){this.#d=e}get originalColumnNodes(){return this.#h}set originalColumnNodes(e){this.#h=e}get lightDomTitle(){return this.#g}set lightDomTitle(e){this.#g=e}get initialColumnState(){return this.#C}set initialColumnState(e){this.#C=e}get sourcesChanged(){return this.#f}markSourcesChanged(){this.#f=!0}setGridConfig(e){this.#l=e,this.#f=!0,this.#d=void 0}getGridConfig(){return this.#l}setColumns(e){this.#n=e,this.#f=!0}getColumns(){return this.#n}setFitMode(e){this.#u=e,this.#f=!0}getFitMode(){return this.#u}merge(){const e=(this.#o.columns?.length??0)>0;if(!this.#f&&e)return;const i=this.#I();this.#f=!1,this.#a=i,Object.freeze(this.#a),this.#a.columns&&Object.freeze(this.#a.columns),this.#o=this.#x(this.#a),this.#m()}#x(e){const i={...e};return e.columns&&(i.columns=e.columns.map(o=>({...o}))),e.shell&&(i.shell={...e.shell,header:e.shell.header?{...e.shell.header}:void 0,toolPanel:e.shell.toolPanel?{...e.shell.toolPanel}:void 0,toolPanels:e.shell.toolPanels?.map(o=>({...o})),headerContents:e.shell.headerContents?.map(o=>({...o}))}),i}#m(){const e=this.#o;this.#z(),typeof e.rowHeight=="number"&&e.rowHeight>0&&this.#r.setRowHeight(e.rowHeight),e.fitMode==="fixed"&&this.columns.forEach(o=>{o.width==null&&(o.width=80)}),this.#r.applyAnimationConfig(e)}#z(){const e=this.#o.typeDefaults;if(!e)return;const i=this.columns;for(const o of i){if(!o.type)continue;const n=e[o.type];n&&(!o.renderer&&!o.viewRenderer&&n.renderer&&(o.renderer=n.renderer),!o.format&&n.format&&(o.format=n.format),!o.editor&&n.editor&&(o.editor=n.editor),!o.editorParams&&n.editorParams&&(o.editorParams=n.editorParams))}}#I(){const e=this.#l?{...this.#l}:{},i=Array.isArray(e.columns)?[...e.columns]:[],o=(this.#d??[]).map(s=>({...s}));let n=Te(i,o);this.#n&&this.#n.length&&(n=Te(this.#n,o));const r=this.#r.getRows();return n.length===0&&r.length&&(n=yt(r).columns),n.length&&(n.forEach(s=>{s.sortable===void 0&&(s.sortable=!0),s.resizable===void 0&&(s.resizable=!0),s.__originalWidth===void 0&&typeof s.width=="number"&&(s.__originalWidth=s.width)}),n.forEach(s=>{s.__viewTemplate&&!s.__compiledView&&(s.__compiledView=De(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=De(s.__editorTemplate.innerHTML))}),e.columns=n),this.#u&&(e.fitMode=this.#u),e.fitMode||(e.fitMode="stretch"),this.#b(e),e.columnState&&!this.#C&&(this.#C=e.columnState),e}#b(e){e.shell=e.shell?{...e.shell}:{},e.shell.header=e.shell.header?{...e.shell.header}:{};const i=this.#r.getShellLightDomTitle();i&&(this.#g=i),this.#g&&!e.shell.header.title&&(e.shell.header.title=this.#g);const o=this.#r.getShellLightDomHeaderContent();o?.length>0&&(e.shell.header.lightDomContent=o),this.#r.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const n=this.#r.getShellToolPanels();if(n.size>0){const f=Array.from(n.values());f.sort((p,g)=>(p.order??100)-(g.order??100)),e.shell.toolPanels=f}const r=this.#r.getShellHeaderContents();if(r.size>0){const f=Array.from(r.values());f.sort((p,g)=>(p.order??100)-(g.order??100)),e.shell.headerContents=f}const s=this.#r.getShellToolbarContents(),l=Array.from(s.values()),a=this.#l?.shell?.header?.toolbarContents??[],c=new Set(a.map(f=>f.id)),h=[...a];for(const f of l)c.has(f.id)||h.push(f);h.sort((f,p)=>(f.order??0)-(p.order??0)),e.shell.header.toolbarContents=h}collectState(e){const i=this.columns,o=this.#y();return{columns:i.map((n,r)=>{const s={field:n.field,order:r,visible:!n.hidden},l=n;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:n.width!==void 0&&(s.width=typeof n.width=="string"?parseFloat(n.width):n.width);const a=o.get(n.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const h=c.getColumnState(n.field);h&&Object.assign(s,h)}return s})}}applyState(e,i){if(!e.columns||e.columns.length===0)return;const o=this.columns,n=new Map(e.columns.map(l=>[l.field,l])),r=o.map(l=>{const a=n.get(l.field);if(!a)return l;const c={...l};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});r.sort((l,a)=>{const c=n.get(l.field)?.order??1/0,h=n.get(a.field)?.order??1/0;return c-h}),this.columns=r;const s=e.columns.filter(l=>l.sort!==void 0).sort((l,a)=>(l.sort?.priority??0)-(a.sort?.priority??0));if(s.length>0){const l=s[0];l.sort&&this.#r.setSortState({field:l.field,direction:l.sort.direction==="asc"?1:-1})}else this.#r.setSortState(null);for(const l of i)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}resetState(e){this.#C=void 0,this.#r.setSortState(null),this.#o=this.#x(this.#a),this.#m();for(const i of e)if(i.applyColumnState)for(const o of this.columns)i.applyColumnState(o.field,{field:o.field,order:0,visible:!0});this.requestStateChange(e)}#y(){const e=new Map,i=this.#r.getSortState();return i&&e.set(i.field,{direction:i.direction===1?"asc":"desc",priority:0}),e}requestStateChange(e){this.#s&&clearTimeout(this.#s),this.#s=setTimeout(()=>{this.#s=void 0;const i=this.collectState(e);this.#r.emit("column-state-change",i)},Dt)}setColumnVisible(e,i){const o=this.columns,n=o.find(s=>s.field===e);return!n||!i&&n.lockVisible||!i&&o.filter(l=>!l.hidden&&l.field!==e).length===0||!!n.hidden===!i?!1:(n.hidden=!i,this.#r.emit("column-visibility",{field:e,visible:i,visibleColumns:o.filter(s=>!s.hidden).map(s=>s.field)}),this.#r.clearRowPool(),this.#r.setup(),!0)}toggleColumnVisibility(e){const i=this.columns.find(o=>o.field===e);return i?this.setColumnVisible(e,!!i.hidden):!1}isColumnVisible(e){const i=this.columns.find(o=>o.field===e);return i?!i.hidden:!1}showAllColumns(){const e=this.columns;e.some(i=>i.hidden)&&(e.forEach(i=>i.hidden=!1),this.#r.emit("column-visibility",{visibleColumns:e.map(i=>i.field)}),this.#r.clearRowPool(),this.#r.setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:e.meta?.utility===!0}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const i=new Map(this.columns.map(n=>[n.field,n])),o=[];for(const n of e){const r=i.get(n);r&&(o.push(r),i.delete(n))}for(const n of i.values())o.push(n);this.columns=o,this.#r.renderHeader(),this.#r.updateTemplate(),this.#r.refreshVirtualWindow()}parseLightDomColumns(e){this.#d||(this.#h=Array.from(e.querySelectorAll("tbw-grid-column")),this.#d=this.#h.length?mt(e):[])}clearLightDomCache(){this.#d=void 0}#p=new Map;registerLightDomHandler(e,i){this.#p.set(e.toLowerCase(),i)}unregisterLightDomHandler(e){this.#p.delete(e.toLowerCase())}observeLightDOM(e){this.#v&&this.#v.disconnect();const i=new Set;let o=null;const n=()=>{o=null;for(const r of i)this.#p.get(r)?.();i.clear()};this.#v=new MutationObserver(r=>{for(const s of r){for(const l of s.addedNodes){if(l.nodeType!==Node.ELEMENT_NODE)continue;const c=l.tagName.toLowerCase();this.#p.has(c)&&i.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#p.has(a)&&i.add(a)}}i.size>0&&!o&&(o=setTimeout(n,0))}),this.#v.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#w.push(e)}notifyChange(){for(const e of this.#w)e()}dispose(){this.#v?.disconnect(),this.#w=[],this.#s&&clearTimeout(this.#s)}}function le(){if(typeof window<"u"&&window.location){const t=window.location.hostname;if(t==="localhost"||t==="127.0.0.1"||t==="::1")return!0}return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function Oe(t){return`<span role="checkbox" aria-checked="${t}" aria-label="${t}">${t?"&#x1F5F9;":"&#9744;"}</span>`}function Me(t){if(t==null||t==="")return"";if(t instanceof Date)return isNaN(t.getTime())?"":t.toLocaleDateString();if(typeof t=="number"||typeof t=="string"){const e=new Date(t);return isNaN(e.getTime())?"":e.toLocaleDateString()}return""}function ke(t){if(!t)return-1;const e=t.getAttribute("data-row");if(e)return parseInt(e,10);const i=t.closest(".data-grid-row");if(!i)return-1;const o=i.parentElement;if(!o)return-1;const n=o.querySelectorAll(":scope > .data-grid-row");for(let r=0;r<n.length;r++)if(n[r]===i)return r;return-1}function Mt(t){if(!t)return-1;const e=t.getAttribute("data-col");return e?parseInt(e,10):-1}function ae(t){t&&t.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function kt(t){try{if(getComputedStyle(t).direction==="rtl")return"rtl"}catch{}try{if(t.closest?.("[dir]")?.getAttribute("dir")==="rtl")return"rtl"}catch{}return"ltr"}function Ie(t){return kt(t)==="rtl"}function Ne(t,e){const i=e.renderer||e.viewRenderer;if(i)return i;if(!e.type)return;const o=t.__frameworkAdapter;if(o?.getTypeDefault){const n=o.getTypeDefault(e.type);if(n?.renderer)return n.renderer}}function qe(t,e){if(e.format)return e.format;if(!e.type)return;const i=t.__frameworkAdapter;if(i?.getTypeDefault){const o=i.getTypeDefault(e.type);if(o?.format)return o.format}}const $e='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function ce(t){return(t.__editingCellCount??0)>0}function de(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing"),t.querySelectorAll(".cell.editing").forEach(i=>i.classList.remove("editing"))}const We=document.createElement("template");We.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Fe=document.createElement("template");Fe.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function It(){return We.content.firstElementChild.cloneNode(!0)}function Nt(){return Fe.content.firstElementChild.cloneNode(!0)}function Q(t){t.__cellDisplayCache=void 0,t.__cellCacheEpoch=void 0,t.__hasSpecialColumns=void 0}function qt(t,e,i,o,n){const r=Math.max(0,i-e),s=t._bodyEl,l=t._visibleColumns,a=l.length;let c=t.__cachedHeaderRowCount;for(c===void 0&&(c=t.querySelector(".header-group-row")?2:1,t.__cachedHeaderRowCount=c);t._rowPool.length<r;){const p=Nt();t._rowPool.push(p)}if(t._rowPool.length>r){for(let p=r;p<t._rowPool.length;p++){const g=t._rowPool[p];g.parentNode===s&&g.remove()}t._rowPool.length=r}const h=n&&t.__hasRenderRowPlugins!==!1,f=t._hasAfterRowRenderHook?.()??!1;for(let p=0;p<r;p++){const g=e+p,u=t._rows[g],d=t._rowPool[p];if(d.setAttribute("aria-rowindex",String(g+c+1)),h&&n(u,d,g)){d.__epoch=o,d.__rowDataRef=u,d.parentNode!==s&&s.appendChild(d);continue}const w=d.__epoch,v=d.__rowDataRef;let b=d.children.length;b>a&&d.lastElementChild?.classList.contains("tbw-row-loading-overlay")&&b--;const T=w===o&&b===a,S=v!==u,H=!!t._isGridEditMode;let C=!1;if(T&&S){for(let R=0;R<a;R++)if(l[R].externalView&&!d.querySelector(`.cell[data-col="${R}"] [data-external-view]`)){C=!0;break}}if(!T||C){const R=ce(d),z=H||t._activeEditRows===g;R&&!z?(d.__isCustomRow&&(d.className="data-grid-row",d.setAttribute("role","row"),d.__isCustomRow=!1),de(d),B(t,d,u,g),d.__epoch=o,d.__rowDataRef=u):R&&z?(he(t,d,u,g),d.__rowDataRef=u):(d.__isCustomRow&&(d.className="data-grid-row",d.setAttribute("role","row"),d.__isCustomRow=!1),B(t,d,u,g),d.__epoch=o,d.__rowDataRef=u)}else if(S){const R=ce(d),z=H||t._activeEditRows===g;R&&!z?(de(d),B(t,d,u,g),d.__epoch=o,d.__rowDataRef=u):(he(t,d,u,g),d.__rowDataRef=u)}else{const R=ce(d),z=H||t._activeEditRows===g;R&&!z?(de(d),B(t,d,u,g),d.__epoch=o,d.__rowDataRef=u):he(t,d,u,g)}let y=!1;const m=t.changedRowIds;if(m&&m.length>0)try{const R=t.getRowId?.(u);R&&(y=m.includes(R))}catch{}const L=d.classList.contains("changed");y!==L&&d.classList.toggle("changed",y);const $=t.effectiveConfig?.rowClass;if($){const R=d.getAttribute("data-dynamic-classes");R&&R.split(" ").forEach(z=>z&&d.classList.remove(z));try{const z=$(u);if(z&&z.length>0){const Se=z.filter(se=>se&&typeof se=="string");Se.forEach(se=>d.classList.add(se)),d.setAttribute("data-dynamic-classes",Se.join(" "))}else d.removeAttribute("data-dynamic-classes")}catch(z){console.warn("[tbw-grid] rowClass callback error:",z),d.removeAttribute("data-dynamic-classes")}}f&&t._afterRowRender?.({row:u,rowIndex:g,rowElement:d}),d.parentNode!==s&&s.appendChild(d)}}function he(t,e,i,o){const n=e.children,r=t._visibleColumns,s=r.length,l=n.length,a=s<l?s:l,c=t._focusRow,h=t._focusCol,f=t._hasAfterCellRenderHook?.()??!1;let p=t.__hasSpecialColumns;if(p===void 0){p=!1;const u=t.__frameworkAdapter;for(let d=0;d<s;d++){const w=r[d];if(w.__viewTemplate||w.__compiledView||w.renderer||w.viewRenderer||w.externalView||w.format||w.type==="date"||w.type==="boolean"||w.type&&u?.getTypeDefault?.(w.type)?.renderer||w.type&&u?.getTypeDefault?.(w.type)?.format){p=!0;break}}t.__hasSpecialColumns=p}const g=String(o);if(!p){for(let u=0;u<a;u++){const d=n[u];if(d.classList.contains("editing"))continue;d.firstElementChild&&t.__frameworkAdapter?.releaseCell?.(d);const w=r[u],v=i[w.field];d.textContent=v==null?"":String(v),d.getAttribute("data-row")!==g&&d.setAttribute("data-row",g);const b=c===o&&h===u,E=d.classList.contains("cell-focus");b!==E&&(d.classList.toggle("cell-focus",b),d.setAttribute("aria-selected",String(b))),f&&t._afterCellRender?.({row:i,rowIndex:o,column:w,colIndex:u,value:v,cellElement:d,rowElement:e})}return}for(let u=0;u<a;u++)if(r[u].externalView&&!n[u].querySelector("[data-external-view]")){B(t,e,i,o);return}for(let u=0;u<a;u++){const d=r[u],w=n[u];w.getAttribute("data-row")!==g&&w.setAttribute("data-row",g);const v=c===o&&h===u,b=w.classList.contains("cell-focus");v!==b&&(w.classList.toggle("cell-focus",v),w.setAttribute("aria-selected",String(v)));const E=d.cellClass;if(E){const y=w.getAttribute("data-dynamic-classes");y&&y.split(" ").forEach(m=>m&&w.classList.remove(m));try{const m=i[d.field],L=E(m,i,d);if(L&&L.length>0){const $=L.filter(R=>R&&typeof R=="string");$.forEach(R=>w.classList.add(R)),w.setAttribute("data-dynamic-classes",$.join(" "))}else w.removeAttribute("data-dynamic-classes")}catch(m){console.warn(`[tbw-grid] cellClass callback error for column '${d.field}':`,m),w.removeAttribute("data-dynamic-classes")}}if(w.classList.contains("editing"))continue;const T=Ne(t,d);if(T){const y=i[d.field],m=T({row:i,value:y,field:d.field,column:d,cellEl:w});typeof m=="string"?(t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML=F(m)):m instanceof Node?m.parentElement!==w&&(t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML="",w.appendChild(m)):m==null&&(t.__frameworkAdapter?.releaseCell?.(w),w.textContent=y==null?"":String(y)),f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:y,cellElement:w,rowElement:e});continue}if(d.__viewTemplate||d.__compiledView||d.externalView)continue;const S=i[d.field];let H;const C=qe(t,d);if(C){try{const y=C(S,i);H=y==null?"":String(y)}catch(y){console.warn(`[tbw-grid] Format error in column '${d.field}':`,y),H=S==null?"":String(S)}w.textContent=H}else d.type==="date"?(H=Me(S),w.textContent=H):d.type==="boolean"?w.innerHTML=Oe(!!S):(H=S==null?"":String(S),w.textContent=H);f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:S,cellElement:w,rowElement:e})}}function B(t,e,i,o){e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy");const n=t.__frameworkAdapter;if(n?.releaseCell){const p=e.children;for(let g=p.length-1;g>=0;g--)n.releaseCell(p[g])}e.innerHTML="";const r=t._visibleColumns,s=r.length,l=t._focusRow,a=t._focusCol,c=t,h=t._hasAfterCellRenderHook?.()??!1,f=document.createDocumentFragment();for(let p=0;p<s;p++){const g=r[p],u=It();u.setAttribute("aria-colindex",String(p+1)),u.setAttribute("data-col",String(p)),u.setAttribute("data-row",String(o)),u.setAttribute("data-field",g.field),u.setAttribute("data-header",g.header??g.field),g.type&&u.setAttribute("data-type",g.type);let d=i[g.field];const w=qe(t,g);if(w)try{d=w(d,i)}catch(C){console.warn(`[tbw-grid] Format error in column '${g.field}':`,C)}const v=g.__compiledView,b=g.__viewTemplate,E=Ne(t,g),T=g.externalView;let S=!1;if(E){const C=E({row:i,value:d,field:g.field,column:g,cellEl:u});typeof C=="string"?(u.innerHTML=F(C),S=!0):C instanceof Node?C.parentElement!==u&&(u.textContent="",u.appendChild(C)):C==null&&(u.textContent=d==null?"":String(d))}else if(T){const C=T,y=document.createElement("div");y.setAttribute("data-external-view",""),y.setAttribute("data-field",g.field),u.appendChild(y);const m={row:i,value:d,field:g.field,column:g};if(C.mount)try{C.mount({placeholder:y,context:m,spec:C})}catch(L){console.warn(`[tbw-grid] External view mount error for column '${g.field}':`,L)}else queueMicrotask(()=>{try{c.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:y,spec:C,context:m}}))}catch(L){console.warn(`[tbw-grid] External view event dispatch error for column '${g.field}':`,L)}});y.setAttribute("data-mounted","")}else if(v){const C=v({row:i,value:d,field:g.field,column:g}),y=v.__blocked;u.innerHTML=y?"":F(C),S=!0,y&&(u.textContent="",u.setAttribute("data-blocked-template",""))}else if(b){const C=b.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(C)?(u.textContent="",u.setAttribute("data-blocked-template","")):(u.innerHTML=F(ze(C,{row:i,value:d})),S=!0)}else w?u.textContent=d==null?"":String(d):g.type==="date"?u.textContent=Me(d):g.type==="boolean"?u.innerHTML=Oe(!!d):u.textContent=d==null?"":String(d);if(S){zt(u);const C=u.textContent||"";/Proxy|Reflect\.ownKeys/.test(C)&&(u.textContent=C.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(u.textContent||"")&&(u.textContent=""))}u.hasAttribute("data-blocked-template")&&(u.textContent||"").trim().length&&(u.textContent=""),g.editable?u.tabIndex=0:g.type==="boolean"&&(u.hasAttribute("tabindex")||(u.tabIndex=0)),l===o&&a===p?(u.classList.add("cell-focus"),u.setAttribute("aria-selected","true")):u.setAttribute("aria-selected","false");const H=g.cellClass;if(H)try{const C=i[g.field],y=H(C,i,g);if(y&&y.length>0){const m=y.filter(L=>L&&typeof L=="string");m.forEach(L=>u.classList.add(L)),u.setAttribute("data-dynamic-classes",m.join(" "))}}catch(C){console.warn(`[tbw-grid] cellClass callback error for column '${g.field}':`,C)}h&&t._afterCellRender?.({row:i,rowIndex:o,column:g,colIndex:p,value:d,cellElement:u,rowElement:e}),f.appendChild(u)}e.appendChild(f)}function Ue(t,e,i){if(e.target?.closest(".resize-handle"))return;const o=i.querySelector(".cell[data-row]"),n=ke(o);if(n<0)return;const r=t._rows[n];if(!r||t._dispatchRowClick?.(e,n,r,i))return;const s=e.target?.closest(".cell[data-col]");if(s){const l=Number(s.getAttribute("data-col"));if(!isNaN(l)){if(t._dispatchCellClick?.(e,n,l,s))return;const a=t._focusRow!==n||t._focusCol!==l;if(t._focusRow=n,t._focusCol=l,s.classList.contains("editing")){a&&(ae(t._bodyEl??t),s.classList.add("cell-focus"));const c=s.querySelector($e);try{c?.focus({preventScroll:!0})}catch{}return}U(t)}}}function $t(t,e){if(t._dispatchKeyDown?.(e))return;const i=t._rows.length-1,o=t._visibleColumns.length-1,n=t._activeEditRows!==void 0&&t._activeEditRows!==-1,s=t._visibleColumns[t._focusCol]?.type,l=e.composedPath?.()??[],a=l.length?l[0]:e.target,c=h=>{if(!h)return!1;const f=h.tagName;return!!(f==="INPUT"||f==="SELECT"||f==="TEXTAREA"||h.isContentEditable)};if(!(c(a)&&(e.key==="Home"||e.key==="End"))&&!(c(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(c(a)&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))&&!(c(a)&&(e.key==="Enter"||e.key==="Escape"))&&!(n&&s==="select"&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?t._focusCol<o?t._focusCol+=1:(typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow<i&&(t._focusRow+=1,t._focusCol=0)):t._focusCol>0?t._focusCol-=1:t._focusRow>0&&(typeof t.commitActiveRowEdit=="function"&&t._activeEditRows===t._focusRow&&t.commitActiveRowEdit(),t._focusRow-=1,t._focusCol=o),U(t);return}case"ArrowDown":n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.min(i,t._focusRow+1),e.preventDefault();break;case"ArrowUp":n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault();break;case"ArrowRight":{Ie(t)?t._focusCol=Math.max(0,t._focusCol-1):t._focusCol=Math.min(o,t._focusCol+1),e.preventDefault();break}case"ArrowLeft":{Ie(t)?t._focusCol=Math.min(o,t._focusCol+1):t._focusCol=Math.max(0,t._focusCol-1),e.preventDefault();break}case"Home":(e.ctrlKey||e.metaKey)&&(n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=0),t._focusCol=0,e.preventDefault(),U(t,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=i),t._focusCol=o,e.preventDefault(),U(t,{forceScrollRight:!0});return;case"PageDown":t._focusRow=Math.min(i,t._focusRow+20),e.preventDefault();break;case"PageUp":t._focusRow=Math.max(0,t._focusRow-20),e.preventDefault();break;case"Enter":{const h=t._focusRow,f=t._focusCol,p=t._visibleColumns[f],g=t._rows[h],u=p?.field??"",d=u&&g?g[u]:void 0,w=t.querySelector(`[data-row="${h}"][data-col="${f}"]`),v={rowIndex:h,colIndex:f,column:p,field:u,value:d,row:g,cellEl:w,trigger:"keyboard",originalEvent:e},b=new CustomEvent("cell-activate",{cancelable:!0,detail:v});t.dispatchEvent(b);const E=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:h,col:f}});if(t.dispatchEvent(E),b.defaultPrevented||E.defaultPrevented){e.preventDefault();return}break}default:return}U(t)}}function U(t,e){if(t._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=t._virtualization,c=l,h=a?.clientHeight??c?.clientHeight??0;if(c&&h>0){const f=t._focusRow*s;f<c.scrollTop?c.scrollTop=f:f+s>c.scrollTop+h&&(c.scrollTop=f-h+s)}}const i=t._activeEditRows!==void 0&&t._activeEditRows!==-1;i||t.refreshVirtualWindow(!1),ae(t._bodyEl),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const o=t._focusRow,n=t._virtualization.start??0,r=t._virtualization.end??t._rows.length;if(o>=n&&o<r){const s=t._bodyEl.querySelectorAll(".data-grid-row")[o-n];let l=s?.children[t._focusCol];if((!l||!l.classList?.contains("cell"))&&(l=s?.querySelector(`.cell[data-col="${t._focusCol}"]`)??s?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=t.querySelector(".tbw-scroll-area");if(a&&l&&(!i||e?.forceHorizontalScroll))if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=t._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const h=l.getBoundingClientRect(),f=a.getBoundingClientRect(),p=h.left-f.left+a.scrollLeft,g=p+h.width,u=a.scrollLeft+c.left,d=a.scrollLeft+a.clientWidth-c.right;p<u?a.scrollLeft=p-c.left:g>d&&(a.scrollLeft=g-a.clientWidth+c.right)}}if(i&&l.classList.contains("editing")){const c=l.querySelector($e);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(i&&!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}else if(!i){const c=t;document.activeElement!==c&&c.focus({preventScroll:!0})}}}}const Z=new WeakMap;function Wt(t,e){const i=ke(e),o=Mt(e);if(i<0||o<0)return;t._focusRow=i,t._focusCol=o,ae(t._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true");const n=e.closest("tbw-grid");n&&document.activeElement!==n&&n.focus({preventScroll:!0})}function ue(t,e,i,o){let n=null;const r=i.composedPath?.();if(r&&r.length>0?n=r[0]:n=i.target,n&&!e.contains(n)){const d=document.elementFromPoint(i.clientX,i.clientY);d&&(n=d)}const s=n?.closest?.("[data-col]"),l=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let c,h,f,p,g,u;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),h=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&h>=0&&(f=t._rows[c],u=t._columns[h],p=u?.field,g=f&&p?f[p]:void 0)),{type:o,row:f,rowIndex:c!==void 0&&c>=0?c:void 0,colIndex:h!==void 0&&h>=0?h:void 0,field:p,value:g,column:u,originalEvent:i,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:c!==void 0&&h!==void 0&&c>=0&&h>=0?{row:c,col:h}:void 0}}function Ft(t,e,i){const o=ue(t,e,i,"mousedown");(t._dispatchCellMouseDown?.(o)??!1)&&Z.set(t,!0)}function Ut(t,e,i){if(!Z.get(t))return;const o=ue(t,e,i,"mousemove");t._dispatchCellMouseMove?.(o)}function Vt(t,e,i){if(!Z.get(t))return;const o=ue(t,e,i,"mouseup");t._dispatchCellMouseUp?.(o),Z.set(t,!1)}function Gt(t,e,i){e.addEventListener("mousedown",o=>{const n=o.target.closest(".cell[data-col]");n&&(n.classList.contains("editing")||(o.preventDefault(),Wt(t,n)))},{signal:i}),e.addEventListener("click",o=>{const n=o.target.closest(".data-grid-row");if(n&&Ue(t,o,n),!document.activeElement?.closest(".cell.editing")){const r=o.target.closest("tbw-grid");r&&r.focus({preventScroll:!0})}},{signal:i}),e.addEventListener("dblclick",o=>{const n=o.target.closest(".data-grid-row");n&&Ue(t,o,n)},{signal:i})}function Bt(t,e,i,o){e.addEventListener("keydown",n=>$t(t,n),{signal:o}),i.addEventListener("mousedown",n=>Ft(t,i,n),{signal:o}),document.addEventListener("mousemove",n=>Ut(t,i,n),{signal:o}),document.addEventListener("mouseup",n=>Vt(t,i,n),{signal:o})}function Ve(t,e){return t==null&&e==null?0:t==null?-1:e==null||t>e?1:t<e?-1:0}function Ge(t,e,i){const n=i.find(l=>l.field===e.field)?.sortComparator??Ve,{field:r,direction:s}=e;return[...t].sort((l,a)=>n(l[r],a[r],l,a)*s)}function Be(t,e,i,o){t._rows=e,t.__rowRenderEpoch++,t._rowPool.forEach(n=>n.__epoch=-1),oe(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:i.field,direction:o}})),t.requestStateChange?.()}function Xe(t,e){!t._sortState||t._sortState.field!==e.field?(t._sortState||(t.__originalOrder=t._rows.slice()),Ye(t,e,1)):t._sortState.direction===1?Ye(t,e,-1):(t._sortState=null,t.__rowRenderEpoch++,t._rowPool.forEach(o=>o.__epoch=-1),t._rows=t.__originalOrder.slice(),oe(t),t._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(o=>{o.getAttribute("aria-sort")?(o.getAttribute("aria-sort")==="ascending"||o.getAttribute("aria-sort")==="descending")&&(t._sortState||o.setAttribute("aria-sort","none")):o.setAttribute("aria-sort","none")}),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),t.requestStateChange?.())}function Ye(t,e,i){t._sortState={field:e.field,direction:i};const o={field:e.field,direction:i},n=t._columns,s=(t.effectiveConfig?.sortHandler??Ge)(t._rows,o,n);s&&typeof s.then=="function"?s.then(l=>{Be(t,l,e,i)}):Be(t,s,e,i)}function X(t,e){return t.effectiveConfig?.sortable!==!1&&e.sortable===!0}function J(t,e){return t.effectiveConfig?.resizable!==!1&&e.resizable!==!1}function Xt(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function ee(t,e){const i=document.createElement("span");xe(i,"sort-indicator");const o=t._sortState?.field===e.field?t._sortState.direction:0,n={...k,...t.icons},r=o===1?n.sortAsc:o===-1?n.sortDesc:n.sortNone;return Xt(i,r),i}function te(t,e,i){const o=document.createElement("div");return o.className="resize-handle",o.setAttribute("aria-hidden","true"),o.addEventListener("mousedown",n=>{n.stopPropagation(),n.preventDefault(),t._resizeController.start(n,e,i)}),o.addEventListener("dblclick",n=>{n.stopPropagation(),n.preventDefault(),t._resizeController.resetColumn(e)}),o}function ie(t,e,i,o){o.classList.add("sortable"),o.tabIndex=0;const n=t._sortState?.field===e.field?t._sortState.direction:0;o.setAttribute("aria-sort",n===0?"none":n===1?"ascending":"descending"),o.addEventListener("click",r=>{t._resizeController?.isResizing||t._dispatchHeaderClick?.(r,e,o)||Xe(t,e)}),o.addEventListener("keydown",r=>{if(r.key==="Enter"||r.key===" "){if(r.preventDefault(),t._dispatchHeaderClick?.(r,e,o))return;Xe(t,e)}})}function Yt(t,e){if(e!=null)if(typeof e=="string"){const i=document.createElement("span");for(i.innerHTML=F(e);i.firstChild;)t.appendChild(i.firstChild)}else e instanceof Node&&t.appendChild(e)}function oe(t){t._headerRowEl=t.findHeaderRow();const e=t._headerRowEl;e&&(e.innerHTML="",t._visibleColumns.forEach((i,o)=>{const n=document.createElement("div");n.className="cell",xe(n,"header-cell"),n.setAttribute("role","columnheader"),n.setAttribute("aria-colindex",String(o+1)),n.setAttribute("data-field",i.field),n.setAttribute("data-col",String(o)),i.type&&n.setAttribute("data-type",i.type);const r=i.header??i.field,s=t._sortState?.field===i.field?t._sortState.direction:0,l=s===1?"asc":s===-1?"desc":null;if(i.headerRenderer){const a={column:i,value:r,sortState:l,filterActive:!1,cellEl:n,renderSortIcon:()=>X(t,i)?ee(t,i):null,renderFilterButton:()=>null},c=i.headerRenderer(a);Yt(n,c),X(t,i)&&ie(t,i,o,n),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)))}else if(i.headerLabelRenderer){const a={column:i,value:r},c=i.headerLabelRenderer(a),h=document.createElement("span");c==null?h.textContent=r:typeof c=="string"?h.innerHTML=F(c):c instanceof Node&&h.appendChild(c),n.appendChild(h),X(t,i)&&(ie(t,i,o,n),n.appendChild(ee(t,i))),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)))}else if(i.__headerTemplate)Array.from(i.__headerTemplate.childNodes).forEach(a=>n.appendChild(a.cloneNode(!0))),X(t,i)&&(ie(t,i,o,n),n.appendChild(ee(t,i))),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)));else{const a=document.createElement("span");a.textContent=r,n.appendChild(a),X(t,i)&&(ie(t,i,o,n),n.appendChild(ee(t,i))),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)))}e.appendChild(n)}),e.querySelectorAll(".cell.sortable").forEach(i=>{i.getAttribute("aria-sort")||i.setAttribute("aria-sort","none")}),e.children.length>0?(e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1")):(e.removeAttribute("role"),e.removeAttribute("aria-rowindex")))}const je=typeof requestIdleCallback=="function";function jt(t,e){return je?requestIdleCallback(t,e):window.setTimeout(()=>{const i=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-i))})},1)}function Ke(t){je?cancelIdleCallback(t):clearTimeout(t)}function Kt(t){const e=document.createElement("div");return e.className=`tbw-spinner tbw-spinner--${t}`,e.setAttribute("role","progressbar"),e.setAttribute("aria-label","Loading"),e}function Qt(t,e){if(e){const o=e({size:t});if(typeof o=="string"){const n=document.createElement("div");return n.innerHTML=o,n}return o}return Kt(t)}function Zt(t){const e=document.createElement("div");return e.className="tbw-loading-overlay",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.appendChild(Qt("large",t)),e}function Jt(t,e){t.appendChild(e)}function ei(t){t?.remove()}function ti(t,e){if(e){if(t.classList.add("tbw-row-loading"),t.setAttribute("aria-busy","true"),!t.querySelector(".tbw-row-loading-overlay")){const i=document.createElement("div");i.className="tbw-row-loading-overlay",i.setAttribute("aria-hidden","true");const o=document.createElement("div");o.className="tbw-row-loading-spinner",i.appendChild(o),t.appendChild(i)}}else t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy"),t.querySelector(".tbw-row-loading-overlay")?.remove()}function ii(t,e){e?(t.classList.add("tbw-cell-loading"),t.setAttribute("aria-busy","true")):(t.classList.remove("tbw-cell-loading"),t.removeAttribute("aria-busy"))}var A=(t=>(t[t.STYLE=1]="STYLE",t[t.VIRTUALIZATION=2]="VIRTUALIZATION",t[t.HEADER=3]="HEADER",t[t.ROWS=4]="ROWS",t[t.COLUMNS=5]="COLUMNS",t[t.FULL=6]="FULL",t))(A||{});class oi{#l;#n=0;#u=0;#d=null;#h=null;#a=null;#o=!1;constructor(e){this.#l=e}requestPhase(e,i){e>this.#n&&(this.#n=e),this.#u===0&&(this.#f(),this.#u=requestAnimationFrame(()=>this.#w()))}whenReady(){return this.#d?this.#d:Promise.resolve()}setInitialReadyResolver(e){this.#a=e}cancel(){this.#u!==0&&(cancelAnimationFrame(this.#u),this.#u=0),this.#n=0,this.#h&&(this.#h(),this.#h=null,this.#d=null)}get isPending(){return this.#n!==0}get pendingPhase(){return this.#n}#f(){this.#d||(this.#d=new Promise(e=>{this.#h=e}))}#w(){if(this.#u=0,!this.#l.isConnected()){this.#n=0,this.#h&&(this.#h(),this.#h=null,this.#d=null);return}const e=this.#n;this.#n=0,e>=5&&this.#l.mergeConfig(),e>=4&&this.#l.processRows(),e>=5&&(this.#l.processColumns(),this.#l.updateTemplate()),e>=3&&this.#l.renderHeader(),e>=2&&this.#l.renderVirtualWindow(),e>=1&&this.#l.afterRender(),!this.#o&&this.#a&&(this.#o=!0,this.#a()),this.#h&&(this.#h(),this.#h=null,this.#d=null)}}function Qe(t){let e=null,i=null,o=null,n=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,h=Math.max(40,e.startWidth+c),f=t._visibleColumns[e.colIndex];f.width=h,f.__userResized=!0,f.__renderedWidth=h,i==null&&(i=requestAnimationFrame(()=>{i=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:f.field,width:h}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),o!==null&&(document.documentElement.style.cursor=o,o=null),n!==null&&(document.body.style.userSelect=n,n=null),e=null,a&&t.requestStateChange&&t.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,h){a.preventDefault();const f=t._visibleColumns[c],p=typeof f?.width=="number"?f.width:void 0,g=f?.__renderedWidth??p??h.getBoundingClientRect().width;e={startX:a.clientX,colIndex:c,startWidth:g},window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),o===null&&(o=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",n===null&&(n=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const c=t._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,t.updateTemplate?.(),t.requestStateChange?.(),t.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){l()}}}const fe="data-animating",ni={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},ri={change:500,insert:300,remove:200};function si(t){const e=t.trim().toLowerCase();return e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:parseFloat(e)}function li(t,e){const i=ni[e],o=getComputedStyle(t).getPropertyValue(i);if(o){const n=si(o);if(!isNaN(n)&&n>0)return n}return ri[e]}function ai(t,e,i){t.removeAttribute(fe),t.offsetWidth,t.setAttribute(fe,e);const o=li(t,e);setTimeout(()=>{e!=="remove"&&t.removeAttribute(fe)},o)}function ge(t,e,i){if(e<0)return!1;const o=t.findRenderedRowElement?.(e);return o?(ai(o,i),!0):!1}function ci(t,e,i){let o=0;for(const n of e)ge(t,n,i)&&o++;return o}function di(t,e,i){const o=t._rows??[],n=t.getRowId;if(!n)return!1;const r=o.findIndex(s=>{if(s==null)return!1;try{return n(s)===e}catch{return!1}});return r<0?!1:ge(t,r,i)}function ne(t,e,i){const o=document.createElement(t);if(e)for(const n in e){const r=e[n];r!=null&&o.setAttribute(n,r)}return o}function P(t,e){const i=document.createElement("div");if(t&&(i.className=t),e)for(const o in e){const n=e[o];n!=null&&i.setAttribute(o,n)}return i}function Ze(t,e,i){const o=document.createElement("button");if(t&&(o.className=t),e)for(const n in e){const r=e[n];r!=null&&o.setAttribute(n,r)}return o}const Je=document.createElement("template");Je.innerHTML=`
1
+ (function(_,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(_=typeof globalThis<"u"?globalThis:_||self,V(_.TbwGrid={}))})(this,(function(_){"use strict";function V(){return{rowCount:-1,colCount:-1,ariaLabel:void 0,ariaDescribedBy:void 0}}function wt(t,e,i,o,n){if(o===t.rowCount&&n===t.colCount)return!1;const r=t.rowCount;return t.rowCount=o,t.colCount=n,e&&(e.setAttribute("aria-rowcount",String(o)),e.setAttribute("aria-colcount",String(n))),o!==r&&i&&(o>0?i.setAttribute("role","rowgroup"):i.removeAttribute("role")),!0}function bt(t,e){const i=t?.gridAriaLabel;return i||(t?.shell?.header?.title??e?.lightDomTitle??void 0)}function mt(t,e,i,o){if(!e)return!1;let n=!1;const r=bt(i,o);r!==t.ariaLabel&&(t.ariaLabel=r,r?e.setAttribute("aria-label",r):e.removeAttribute("aria-label"),n=!0);const s=i?.gridAriaDescribedBy;return s!==t.ariaDescribedBy&&(t.ariaDescribedBy=s,s?e.setAttribute("aria-describedby",s):e.removeAttribute("aria-describedby"),n=!0),n}const F={STRETCH:"stretch",FIXED:"fixed"},Te={mode:"reduced-motion",duration:200,easing:"ease-out"},xe='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',k={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:xe,filterActive:xe,print:"🖨️"};function vt(t){return Array.from(t.querySelectorAll("tbw-grid-column")).map(i=>{const o=i.getAttribute("field")||"";if(!o)return null;const n=i.getAttribute("type")||void 0,s=n&&new Set(["number","string","date","boolean","select"]).has(n)?n:void 0,l=i.getAttribute("header")||void 0,a=i.hasAttribute("sortable"),c=i.hasAttribute("editable"),h={field:o,type:s,header:l,sortable:a,editable:c},f=i.getAttribute("width");if(f){const b=parseFloat(f);!isNaN(b)&&/^\d+(\.\d+)?$/.test(f.trim())?h.width=b:h.width=f}const p=i.getAttribute("minWidth")||i.getAttribute("min-width");if(p){const b=parseFloat(p);isNaN(b)||(h.minWidth=b)}i.hasAttribute("resizable")&&(h.resizable=!0),i.hasAttribute("sizable")&&(h.resizable=!0);const g=i.getAttribute("editor"),u=i.getAttribute("renderer");g&&(h.__editorName=g),u&&(h.__rendererName=u);const d=i.getAttribute("options");d&&(h.options=d.split(",").map(b=>{const[H,W]=b.includes(":")?b.split(":"):[b.trim(),b.trim()];return{value:H.trim(),label:W?.trim()||H.trim()}}));const w=i.querySelector("tbw-grid-column-view"),C=i.querySelector("tbw-grid-column-editor"),m=i.querySelector("tbw-grid-column-header");w&&(h.__viewTemplate=w),C&&(h.__editorTemplate=C),m&&(h.__headerTemplate=m);const T=globalThis.DataGridElement?.getAdapters?.()??[],S=w??i,L=T.find(b=>b.canHandle(S));if(L){const b=L.createRenderer(S);b&&(h.viewRenderer=b)}const y=C??i,v=T.find(b=>b.canHandle(y));if(v){const b=v.createEditor(y);b&&(h.editor=b)}return h}).filter(i=>!!i)}function He(t,e){if((!t||!t.length)&&(!e||!e.length))return[];if(!t||!t.length)return e||[];if(!e||!e.length)return t;const i={};e.forEach(n=>{const r=i[n.field];if(r){n.header&&!r.header&&(r.header=n.header),n.type&&!r.type&&(r.type=n.type),n.sortable&&(r.sortable=!0),n.editable&&(r.editable=!0),n.resizable&&(r.resizable=!0),n.width!=null&&r.width==null&&(r.width=n.width),n.minWidth!=null&&r.minWidth==null&&(r.minWidth=n.minWidth),n.__viewTemplate&&(r.__viewTemplate=n.__viewTemplate),n.__editorTemplate&&(r.__editorTemplate=n.__editorTemplate),n.__headerTemplate&&(r.__headerTemplate=n.__headerTemplate);const s=n.renderer||n.viewRenderer,l=r.renderer||r.viewRenderer;s&&!l&&(r.viewRenderer=s,n.renderer&&(r.renderer=s)),n.editor&&!r.editor&&(r.editor=n.editor)}else i[n.field]={...n}});const o=t.map(n=>{const r=i[n.field];if(!r)return n;const s={...n};r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=n.sortable||r.sortable,(n.resizable===!0||r.resizable===!0)&&(s.resizable=!0),s.editable=n.editable||r.editable,r.width!=null&&s.width==null&&(s.width=r.width),r.minWidth!=null&&s.minWidth==null&&(s.minWidth=r.minWidth),r.__viewTemplate&&(s.__viewTemplate=r.__viewTemplate),r.__editorTemplate&&(s.__editorTemplate=r.__editorTemplate),r.__headerTemplate&&(s.__headerTemplate=r.__headerTemplate);const l=r.renderer||r.viewRenderer,a=s.renderer||s.viewRenderer;return l&&!a&&(s.viewRenderer=l,r.renderer&&(s.renderer=l)),r.editor&&!s.editor&&(s.editor=r.editor),delete i[n.field],s});return Object.keys(i).forEach(n=>o.push(i[n])),o}function Le(t,e){try{t.part?.add?.(e)}catch{}const i=t.getAttribute("part");i?i.split(/\s+/).includes(e)||t.setAttribute("part",i+" "+e):t.setAttribute("part",e)}function Pe(t){const e=t.effectiveConfig?.fitMode||t.fitMode||F.STRETCH;if(e!==F.STRETCH&&e!==F.FIXED||t.__didInitialAutoSize||!t.isConnected)return;const i=Array.from(t._headerRowEl?.children||[]);if(!i.length)return;let o=!1;t._visibleColumns.forEach((n,r)=>{if(n.width)return;const s=i[r];let l=s?s.scrollWidth:0;for(const a of t._rowPool){const c=a.children[r];if(c){const h=c.scrollWidth;h>l&&(l=h)}}l>0&&(n.width=l+2,n.__autoSized=!0,o=!0)}),o&&G(t),t.__didInitialAutoSize=!0}const Ct=/^(?:\d+(?:\.\d+)?(?:px|%|fr|em|rem|ch|vw|vh|vmin|vmax)|calc\(.+\)|min-content|max-content|minmax\(.+\)|fit-content\(.+\)|auto)$/i;function ze(t,e){return typeof t=="number"?`${t}px`:(Ct.test(t)||console.warn(`[tbw-grid] Column '${e??"?"}' has an invalid CSS width value: '${t}'. Expected a number (px) or a valid CSS unit string (e.g. '30%', '2fr', 'calc(...)').`),t)}function G(t){(t.effectiveConfig?.fitMode||t.fitMode||F.STRETCH)===F.STRETCH?t._gridTemplate=t._visibleColumns.map(i=>{if(i.width!=null)return ze(i.width,i.field);const o=i.minWidth;return o!=null?`minmax(${o}px, 1fr)`:"1fr"}).join(" ").trim():t._gridTemplate=t._visibleColumns.map(i=>i.width!=null?ze(i.width,i.field):"max-content").join(" "),t.style.setProperty("--tbw-column-template",t._gridTemplate)}function yt(t){return t==null?"string":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date||typeof t=="string"&&/\d{4}-\d{2}-\d{2}/.test(t)&&!isNaN(Date.parse(t))?"date":"string"}function _t(t,e){const i=t[0]||{},o=Object.keys(i).map(r=>{const s=i[r],l=yt(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),n={};return o.forEach(r=>{n[r.field]=r.type||"string"}),{columns:o,typeMap:n}}const Et=/{{\s*([^}]+)\s*}}/g,D="__DG_EMPTY__",St=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Rt=/__(proto|defineGetter|defineSetter)|constructor|window|globalThis|global|process|Function|import|eval|Reflect|Proxy|Error|arguments|document|location|cookie|localStorage|sessionStorage|indexedDB|fetch|XMLHttpRequest|WebSocket|Worker|SharedWorker|ServiceWorker|opener|parent|top|frames|self|this\b/;function At(t){return!t||typeof t!="string"?"":t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}const Tt=new Set(["script","iframe","object","embed","form","input","button","textarea","select","link","meta","base","style","template","slot","portal","frame","frameset","applet","noscript","noembed","plaintext","xmp","listing"]),De=/^on\w+$/i,xt=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Ht=/^\s*(javascript|vbscript|data|blob):/i;function N(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,Lt(e.content),e.innerHTML}function Lt(t){const e=[],i=t.querySelectorAll("*");for(const o of i){const n=o.tagName.toLowerCase();if(Tt.has(n)){e.push(o);continue}if((n==="svg"||o.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(o.attributes).some(l=>De.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(o);continue}const r=[];for(const s of o.attributes){const l=s.name.toLowerCase();if(De.test(l)){r.push(s.name);continue}if(xt.has(l)&&Ht.test(s.value)){r.push(s.name);continue}if(l==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(s.value)){r.push(s.name);continue}}r.forEach(s=>o.removeAttribute(s))}e.forEach(o=>o.remove())}function le(t,e){if(!t||t.indexOf("{{")===-1)return t;const i=[],o=t.replace(Et,(l,a)=>{const c=Pt(a,e);return i.push({expr:a.trim(),result:c}),c}),n=zt(o),r=i.length&&i.every(l=>l.result===""||l.result===D);return q.test(t)||r?"":n}function Pt(t,e){if(t=(t||"").trim(),!t||q.test(t))return D;if(t==="value")return e.value==null?D:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const o=t.slice(4),n=e.row?e.row[o]:void 0;return n==null?D:String(n)}if(t.length>80||!St.test(t)||Rt.test(t))return D;const i=t.match(/\./g);if(i&&i.length>1)return D;try{const n=new Function("value","row",`return (${t});`)(e.value,e.row),r=n==null?"":String(n);return q.test(r)?D:r||D}catch{return D}}const q=/Reflect|Proxy|ownKeys/;function zt(t){return t&&t.replace(new RegExp(D,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,"")}function ae(t){if(q.test(t.textContent||"")){for(const e of t.childNodes)e.nodeType===Node.TEXT_NODE&&q.test(e.textContent||"")&&(e.textContent="");q.test(t.textContent||"")&&(t.textContent="")}}function Oe(t){const e=q.test(t),i=(o=>e?"":le(t,o));return i.__blocked=e,i}const Dt=100;class Ot{#l;#n;#u;#d;#h;#a={};#o={};#f=!0;#w=[];#v;#s;#C;#r;#g;constructor(e){this.#r=e}get original(){return this.#a}get effective(){return this.#o}get columns(){return this.#o.columns??[]}set columns(e){this.#o.columns=e}get lightDomColumnsCache(){return this.#d}set lightDomColumnsCache(e){this.#d=e}get originalColumnNodes(){return this.#h}set originalColumnNodes(e){this.#h=e}get lightDomTitle(){return this.#g}set lightDomTitle(e){this.#g=e}get initialColumnState(){return this.#C}set initialColumnState(e){this.#C=e}get sourcesChanged(){return this.#f}markSourcesChanged(){this.#f=!0}setGridConfig(e){this.#l=e,this.#f=!0,this.#d=void 0}getGridConfig(){return this.#l}setColumns(e){this.#n=e,this.#f=!0}getColumns(){return this.#n}setFitMode(e){this.#u=e,this.#f=!0}getFitMode(){return this.#u}merge(){const e=(this.#o.columns?.length??0)>0;if(!this.#f&&e)return;const i=this.#I();this.#f=!1,this.#a=i,Object.freeze(this.#a),this.#a.columns&&Object.freeze(this.#a.columns),this.#o=this.#x(this.#a),this.#m()}#x(e){const i={...e};return e.columns&&(i.columns=e.columns.map(o=>({...o}))),e.shell&&(i.shell={...e.shell,header:e.shell.header?{...e.shell.header}:void 0,toolPanel:e.shell.toolPanel?{...e.shell.toolPanel}:void 0,toolPanels:e.shell.toolPanels?.map(o=>({...o})),headerContents:e.shell.headerContents?.map(o=>({...o}))}),i}#m(){const e=this.#o;this.#z(),typeof e.rowHeight=="number"&&e.rowHeight>0&&this.#r.setRowHeight(e.rowHeight),e.fitMode==="fixed"&&this.columns.forEach(o=>{o.width==null&&(o.width=80)}),this.#r.applyAnimationConfig(e)}#z(){const e=this.#o.typeDefaults;if(!e)return;const i=this.columns;for(const o of i){if(!o.type)continue;const n=e[o.type];n&&(!o.renderer&&!o.viewRenderer&&n.renderer&&(o.renderer=n.renderer),!o.format&&n.format&&(o.format=n.format),!o.editor&&n.editor&&(o.editor=n.editor),!o.editorParams&&n.editorParams&&(o.editorParams=n.editorParams))}}#I(){const e=this.#l?{...this.#l}:{},i=Array.isArray(e.columns)?[...e.columns]:[],o=(this.#d??[]).map(s=>({...s}));let n=He(i,o);this.#n&&this.#n.length&&(n=He(this.#n,o));const r=this.#r.getRows();return n.length===0&&r.length&&(n=_t(r).columns),n.length&&(n.forEach(s=>{s.sortable===void 0&&(s.sortable=!0),s.resizable===void 0&&(s.resizable=!0),s.__originalWidth===void 0&&typeof s.width=="number"&&(s.__originalWidth=s.width)}),n.forEach(s=>{s.__viewTemplate&&!s.__compiledView&&(s.__compiledView=Oe(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=Oe(s.__editorTemplate.innerHTML))}),e.columns=n),this.#u&&(e.fitMode=this.#u),e.fitMode||(e.fitMode="stretch"),this.#b(e),e.columnState&&!this.#C&&(this.#C=e.columnState),e}#b(e){e.shell=e.shell?{...e.shell}:{},e.shell.header=e.shell.header?{...e.shell.header}:{};const i=this.#r.getShellLightDomTitle();i&&(this.#g=i),this.#g&&!e.shell.header.title&&(e.shell.header.title=this.#g);const o=this.#r.getShellLightDomHeaderContent();o?.length>0&&(e.shell.header.lightDomContent=o),this.#r.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const n=this.#r.getShellToolPanels();if(n.size>0){const f=Array.from(n.values());f.sort((p,g)=>(p.order??100)-(g.order??100)),e.shell.toolPanels=f}const r=this.#r.getShellHeaderContents();if(r.size>0){const f=Array.from(r.values());f.sort((p,g)=>(p.order??100)-(g.order??100)),e.shell.headerContents=f}const s=this.#r.getShellToolbarContents(),l=Array.from(s.values()),a=this.#l?.shell?.header?.toolbarContents??[],c=new Set(a.map(f=>f.id)),h=[...a];for(const f of l)c.has(f.id)||h.push(f);h.sort((f,p)=>(f.order??0)-(p.order??0)),e.shell.header.toolbarContents=h}collectState(e){const i=this.columns,o=this.#y();return{columns:i.map((n,r)=>{const s={field:n.field,order:r,visible:!n.hidden},l=n;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:n.width!==void 0&&(s.width=typeof n.width=="string"?parseFloat(n.width):n.width);const a=o.get(n.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const h=c.getColumnState(n.field);h&&Object.assign(s,h)}return s})}}applyState(e,i){if(!e.columns||e.columns.length===0)return;const o=this.columns,n=new Map(e.columns.map(l=>[l.field,l])),r=o.map(l=>{const a=n.get(l.field);if(!a)return l;const c={...l};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});r.sort((l,a)=>{const c=n.get(l.field)?.order??1/0,h=n.get(a.field)?.order??1/0;return c-h}),this.columns=r;const s=e.columns.filter(l=>l.sort!==void 0).sort((l,a)=>(l.sort?.priority??0)-(a.sort?.priority??0));if(s.length>0){const l=s[0];l.sort&&this.#r.setSortState({field:l.field,direction:l.sort.direction==="asc"?1:-1})}else this.#r.setSortState(null);for(const l of i)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}resetState(e){this.#C=void 0,this.#r.setSortState(null),this.#o=this.#x(this.#a),this.#m();for(const i of e)if(i.applyColumnState)for(const o of this.columns)i.applyColumnState(o.field,{field:o.field,order:0,visible:!0});this.requestStateChange(e)}#y(){const e=new Map,i=this.#r.getSortState();return i&&e.set(i.field,{direction:i.direction===1?"asc":"desc",priority:0}),e}requestStateChange(e){this.#s&&clearTimeout(this.#s),this.#s=setTimeout(()=>{this.#s=void 0;const i=this.collectState(e);this.#r.emit("column-state-change",i)},Dt)}setColumnVisible(e,i){const o=this.columns,n=o.find(s=>s.field===e);return!n||!i&&n.lockVisible||!i&&o.filter(l=>!l.hidden&&l.field!==e).length===0||!!n.hidden===!i?!1:(n.hidden=!i,this.#r.emit("column-visibility",{field:e,visible:i,visibleColumns:o.filter(s=>!s.hidden).map(s=>s.field)}),this.#r.clearRowPool(),this.#r.setup(),!0)}toggleColumnVisibility(e){const i=this.columns.find(o=>o.field===e);return i?this.setColumnVisible(e,!!i.hidden):!1}isColumnVisible(e){const i=this.columns.find(o=>o.field===e);return i?!i.hidden:!1}showAllColumns(){const e=this.columns;e.some(i=>i.hidden)&&(e.forEach(i=>i.hidden=!1),this.#r.emit("column-visibility",{visibleColumns:e.map(i=>i.field)}),this.#r.clearRowPool(),this.#r.setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:e.meta?.utility===!0}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const i=new Map(this.columns.map(n=>[n.field,n])),o=[];for(const n of e){const r=i.get(n);r&&(o.push(r),i.delete(n))}for(const n of i.values())o.push(n);this.columns=o,this.#r.renderHeader(),this.#r.updateTemplate(),this.#r.refreshVirtualWindow()}parseLightDomColumns(e){this.#d||(this.#h=Array.from(e.querySelectorAll("tbw-grid-column")),this.#d=this.#h.length?vt(e):[])}clearLightDomCache(){this.#d=void 0}#p=new Map;registerLightDomHandler(e,i){this.#p.set(e.toLowerCase(),i)}unregisterLightDomHandler(e){this.#p.delete(e.toLowerCase())}observeLightDOM(e){this.#v&&this.#v.disconnect();const i=new Set;let o=null;const n=()=>{o=null;for(const r of i)this.#p.get(r)?.();i.clear()};this.#v=new MutationObserver(r=>{for(const s of r){for(const l of s.addedNodes){if(l.nodeType!==Node.ELEMENT_NODE)continue;const c=l.tagName.toLowerCase();this.#p.has(c)&&i.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#p.has(a)&&i.add(a)}}i.size>0&&!o&&(o=setTimeout(n,0))}),this.#v.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#w.push(e)}notifyChange(){for(const e of this.#w)e()}dispose(){this.#v?.disconnect(),this.#w=[],this.#s&&clearTimeout(this.#s)}}function ce(){if(typeof window<"u"&&window.location){const t=window.location.hostname;if(t==="localhost"||t==="127.0.0.1"||t==="::1")return!0}return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function Me(t){return`<span role="checkbox" aria-checked="${t}" aria-label="${t}">${t?"&#x1F5F9;":"&#9744;"}</span>`}function ke(t){if(t==null||t==="")return"";if(t instanceof Date)return isNaN(t.getTime())?"":t.toLocaleDateString();if(typeof t=="number"||typeof t=="string"){const e=new Date(t);return isNaN(e.getTime())?"":e.toLocaleDateString()}return""}function Ie(t){if(!t)return-1;const e=t.getAttribute("data-row");if(e)return parseInt(e,10);const i=t.closest(".data-grid-row");if(!i)return-1;const o=i.parentElement;if(!o)return-1;const n=o.querySelectorAll(":scope > .data-grid-row");for(let r=0;r<n.length;r++)if(n[r]===i)return r;return-1}function Mt(t){if(!t)return-1;const e=t.getAttribute("data-col");return e?parseInt(e,10):-1}function de(t){t&&t.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function kt(t){try{if(getComputedStyle(t).direction==="rtl")return"rtl"}catch{}try{if(t.closest?.("[dir]")?.getAttribute("dir")==="rtl")return"rtl"}catch{}return"ltr"}function Ne(t){return kt(t)==="rtl"}function qe(t,e){const i=e.renderer||e.viewRenderer;if(i)return i;if(!e.type)return;const o=t.__frameworkAdapter;if(o?.getTypeDefault){const n=o.getTypeDefault(e.type);if(n?.renderer)return n.renderer}}function $e(t,e){if(e.format)return e.format;if(!e.type)return;const i=t.__frameworkAdapter;if(i?.getTypeDefault){const o=i.getTypeDefault(e.type);if(o?.format)return o.format}}const We='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function he(t){return(t.__editingCellCount??0)>0}function ue(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing"),t.querySelectorAll(".cell.editing").forEach(i=>i.classList.remove("editing"))}const Fe=document.createElement("template");Fe.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Ue=document.createElement("template");Ue.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function It(){return Fe.content.firstElementChild.cloneNode(!0)}function Nt(){return Ue.content.firstElementChild.cloneNode(!0)}function Q(t){t.__cellDisplayCache=void 0,t.__cellCacheEpoch=void 0,t.__hasSpecialColumns=void 0}function qt(t,e,i,o,n){const r=Math.max(0,i-e),s=t._bodyEl,l=t._visibleColumns,a=l.length;let c=t.__cachedHeaderRowCount;for(c===void 0&&(c=t.querySelector(".header-group-row")?2:1,t.__cachedHeaderRowCount=c);t._rowPool.length<r;){const p=Nt();t._rowPool.push(p)}if(t._rowPool.length>r){for(let p=r;p<t._rowPool.length;p++){const g=t._rowPool[p];g.parentNode===s&&g.remove()}t._rowPool.length=r}const h=n&&t.__hasRenderRowPlugins!==!1,f=t._hasAfterRowRenderHook?.()??!1;for(let p=0;p<r;p++){const g=e+p,u=t._rows[g],d=t._rowPool[p];if(d.setAttribute("aria-rowindex",String(g+c+1)),h&&n(u,d,g)){d.__epoch=o,d.__rowDataRef=u,d.parentNode!==s&&s.appendChild(d);continue}const w=d.__epoch,C=d.__rowDataRef;let m=d.children.length;m>a&&d.lastElementChild?.classList.contains("tbw-row-loading-overlay")&&m--;const T=w===o&&m===a,S=C!==u,L=!!t._isGridEditMode;let y=!1;if(T&&S){for(let R=0;R<a;R++)if(l[R].externalView&&!d.querySelector(`.cell[data-col="${R}"] [data-external-view]`)){y=!0;break}}if(!T||y){const R=he(d),z=L||t._activeEditRows===g;R&&!z?(d.__isCustomRow&&(d.className="data-grid-row",d.setAttribute("role","row"),d.__isCustomRow=!1),ue(d),B(t,d,u,g),d.__epoch=o,d.__rowDataRef=u):R&&z?(fe(t,d,u,g),d.__rowDataRef=u):(d.__isCustomRow&&(d.className="data-grid-row",d.setAttribute("role","row"),d.__isCustomRow=!1),B(t,d,u,g),d.__epoch=o,d.__rowDataRef=u)}else if(S){const R=he(d),z=L||t._activeEditRows===g;R&&!z?(ue(d),B(t,d,u,g),d.__epoch=o,d.__rowDataRef=u):(fe(t,d,u,g),d.__rowDataRef=u)}else{const R=he(d),z=L||t._activeEditRows===g;R&&!z?(ue(d),B(t,d,u,g),d.__epoch=o,d.__rowDataRef=u):fe(t,d,u,g)}let v=!1;const b=t.changedRowIds;if(b&&b.length>0)try{const R=t.getRowId?.(u);R&&(v=b.includes(R))}catch{}const H=d.classList.contains("changed");v!==H&&d.classList.toggle("changed",v);const W=t.effectiveConfig?.rowClass;if(W){const R=d.getAttribute("data-dynamic-classes");R&&R.split(" ").forEach(z=>z&&d.classList.remove(z));try{const z=W(u);if(z&&z.length>0){const Ae=z.filter(se=>se&&typeof se=="string");Ae.forEach(se=>d.classList.add(se)),d.setAttribute("data-dynamic-classes",Ae.join(" "))}else d.removeAttribute("data-dynamic-classes")}catch(z){console.warn("[tbw-grid] rowClass callback error:",z),d.removeAttribute("data-dynamic-classes")}}f&&t._afterRowRender?.({row:u,rowIndex:g,rowElement:d}),d.parentNode!==s&&s.appendChild(d)}}function fe(t,e,i,o){const n=e.children,r=t._visibleColumns,s=r.length,l=n.length,a=s<l?s:l,c=t._focusRow,h=t._focusCol,f=t._hasAfterCellRenderHook?.()??!1;let p=t.__hasSpecialColumns;if(p===void 0){p=!1;const u=t.__frameworkAdapter;for(let d=0;d<s;d++){const w=r[d];if(w.__viewTemplate||w.__compiledView||w.renderer||w.viewRenderer||w.externalView||w.format||w.type==="date"||w.type==="boolean"||w.type&&u?.getTypeDefault?.(w.type)?.renderer||w.type&&u?.getTypeDefault?.(w.type)?.format){p=!0;break}}t.__hasSpecialColumns=p}const g=String(o);if(!p){for(let u=0;u<a;u++){const d=n[u];if(d.classList.contains("editing"))continue;d.firstElementChild&&t.__frameworkAdapter?.releaseCell?.(d);const w=r[u],C=i[w.field];d.textContent=C==null?"":String(C),d.getAttribute("data-row")!==g&&d.setAttribute("data-row",g);const m=c===o&&h===u,E=d.classList.contains("cell-focus");m!==E&&(d.classList.toggle("cell-focus",m),d.setAttribute("aria-selected",String(m))),f&&t._afterCellRender?.({row:i,rowIndex:o,column:w,colIndex:u,value:C,cellElement:d,rowElement:e})}return}for(let u=0;u<a;u++)if(r[u].externalView&&!n[u].querySelector("[data-external-view]")){B(t,e,i,o);return}for(let u=0;u<a;u++){const d=r[u],w=n[u];w.getAttribute("data-row")!==g&&w.setAttribute("data-row",g);const C=c===o&&h===u,m=w.classList.contains("cell-focus");C!==m&&(w.classList.toggle("cell-focus",C),w.setAttribute("aria-selected",String(C)));const E=d.cellClass;if(E){const v=w.getAttribute("data-dynamic-classes");v&&v.split(" ").forEach(b=>b&&w.classList.remove(b));try{const b=i[d.field],H=E(b,i,d);if(H&&H.length>0){const W=H.filter(R=>R&&typeof R=="string");W.forEach(R=>w.classList.add(R)),w.setAttribute("data-dynamic-classes",W.join(" "))}else w.removeAttribute("data-dynamic-classes")}catch(b){console.warn(`[tbw-grid] cellClass callback error for column '${d.field}':`,b),w.removeAttribute("data-dynamic-classes")}}if(w.classList.contains("editing"))continue;const T=qe(t,d);if(T){const v=i[d.field],b=T({row:i,value:v,field:d.field,column:d,cellEl:w});typeof b=="string"?(t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML=N(b)):b instanceof Node?b.parentElement!==w&&(t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML="",w.appendChild(b)):b==null&&(t.__frameworkAdapter?.releaseCell?.(w),w.textContent=v==null?"":String(v)),f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:v,cellElement:w,rowElement:e});continue}if(d.__compiledView){const v=i[d.field],b=d.__compiledView({row:i,value:v,field:d.field,column:d});d.__compiledView.__blocked?w.textContent="":(w.firstElementChild&&t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML=N(b),ae(w)),f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:v,cellElement:w,rowElement:e});continue}if(d.__viewTemplate){const v=i[d.field],b=d.__viewTemplate.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(b)?w.textContent="":(w.firstElementChild&&t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML=N(le(b,{row:i,value:v})),ae(w)),f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:v,cellElement:w,rowElement:e});continue}if(d.externalView)continue;const S=i[d.field];let L;const y=$e(t,d);if(y){try{const v=y(S,i);L=v==null?"":String(v)}catch(v){console.warn(`[tbw-grid] Format error in column '${d.field}':`,v),L=S==null?"":String(S)}w.textContent=L}else d.type==="date"?(L=ke(S),w.textContent=L):d.type==="boolean"?w.innerHTML=Me(!!S):(L=S==null?"":String(S),w.textContent=L);f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:S,cellElement:w,rowElement:e})}}function B(t,e,i,o){e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy");const n=t.__frameworkAdapter;if(n?.releaseCell){const p=e.children;for(let g=p.length-1;g>=0;g--)n.releaseCell(p[g])}e.innerHTML="";const r=t._visibleColumns,s=r.length,l=t._focusRow,a=t._focusCol,c=t,h=t._hasAfterCellRenderHook?.()??!1,f=document.createDocumentFragment();for(let p=0;p<s;p++){const g=r[p],u=It();u.setAttribute("aria-colindex",String(p+1)),u.setAttribute("data-col",String(p)),u.setAttribute("data-row",String(o)),u.setAttribute("data-field",g.field),u.setAttribute("data-header",g.header??g.field),g.type&&u.setAttribute("data-type",g.type);let d=i[g.field];const w=$e(t,g);if(w)try{d=w(d,i)}catch(y){console.warn(`[tbw-grid] Format error in column '${g.field}':`,y)}const C=g.__compiledView,m=g.__viewTemplate,E=qe(t,g),T=g.externalView;let S=!1;if(E){const y=E({row:i,value:d,field:g.field,column:g,cellEl:u});typeof y=="string"?(u.innerHTML=N(y),S=!0):y instanceof Node?y.parentElement!==u&&(u.textContent="",u.appendChild(y)):y==null&&(u.textContent=d==null?"":String(d))}else if(T){const y=T,v=document.createElement("div");v.setAttribute("data-external-view",""),v.setAttribute("data-field",g.field),u.appendChild(v);const b={row:i,value:d,field:g.field,column:g};if(y.mount)try{y.mount({placeholder:v,context:b,spec:y})}catch(H){console.warn(`[tbw-grid] External view mount error for column '${g.field}':`,H)}else queueMicrotask(()=>{try{c.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:v,spec:y,context:b}}))}catch(H){console.warn(`[tbw-grid] External view event dispatch error for column '${g.field}':`,H)}});v.setAttribute("data-mounted","")}else if(C){const y=C({row:i,value:d,field:g.field,column:g}),v=C.__blocked;u.innerHTML=v?"":N(y),S=!0,v&&(u.textContent="",u.setAttribute("data-blocked-template",""))}else if(m){const y=m.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(y)?(u.textContent="",u.setAttribute("data-blocked-template","")):(u.innerHTML=N(le(y,{row:i,value:d})),S=!0)}else w?u.textContent=d==null?"":String(d):g.type==="date"?u.textContent=ke(d):g.type==="boolean"?u.innerHTML=Me(!!d):u.textContent=d==null?"":String(d);if(S){ae(u);const y=u.textContent||"";/Proxy|Reflect\.ownKeys/.test(y)&&(u.textContent=y.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(u.textContent||"")&&(u.textContent=""))}u.hasAttribute("data-blocked-template")&&(u.textContent||"").trim().length&&(u.textContent=""),g.editable?u.tabIndex=0:g.type==="boolean"&&(u.hasAttribute("tabindex")||(u.tabIndex=0)),l===o&&a===p?(u.classList.add("cell-focus"),u.setAttribute("aria-selected","true")):u.setAttribute("aria-selected","false");const L=g.cellClass;if(L)try{const y=i[g.field],v=L(y,i,g);if(v&&v.length>0){const b=v.filter(H=>H&&typeof H=="string");b.forEach(H=>u.classList.add(H)),u.setAttribute("data-dynamic-classes",b.join(" "))}}catch(y){console.warn(`[tbw-grid] cellClass callback error for column '${g.field}':`,y)}h&&t._afterCellRender?.({row:i,rowIndex:o,column:g,colIndex:p,value:d,cellElement:u,rowElement:e}),f.appendChild(u)}e.appendChild(f)}function Ve(t,e,i){if(e.target?.closest(".resize-handle"))return;const o=i.querySelector(".cell[data-row]"),n=Ie(o);if(n<0)return;const r=t._rows[n];if(!r||t._dispatchRowClick?.(e,n,r,i))return;const s=e.target?.closest(".cell[data-col]");if(s){const l=Number(s.getAttribute("data-col"));if(!isNaN(l)){if(t._dispatchCellClick?.(e,n,l,s))return;const a=t._focusRow!==n||t._focusCol!==l;if(t._focusRow=n,t._focusCol=l,s.classList.contains("editing")){a&&(de(t._bodyEl??t),s.classList.add("cell-focus"));const c=s.querySelector(We);try{c?.focus({preventScroll:!0})}catch{}return}U(t)}}}function $t(t,e){if(t._dispatchKeyDown?.(e))return;const i=t._rows.length-1,o=t._visibleColumns.length-1,n=t._activeEditRows!==void 0&&t._activeEditRows!==-1,s=t._visibleColumns[t._focusCol]?.type,l=e.composedPath?.()??[],a=l.length?l[0]:e.target,c=h=>{if(!h)return!1;const f=h.tagName;return!!(f==="INPUT"||f==="SELECT"||f==="TEXTAREA"||h.isContentEditable)};if(!(c(a)&&(e.key==="Home"||e.key==="End"))&&!(c(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(c(a)&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))&&!(c(a)&&(e.key==="Enter"||e.key==="Escape"))&&!(n&&s==="select"&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?t._focusCol<o?t._focusCol+=1:(typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow<i&&(t._focusRow+=1,t._focusCol=0)):t._focusCol>0?t._focusCol-=1:t._focusRow>0&&(typeof t.commitActiveRowEdit=="function"&&t._activeEditRows===t._focusRow&&t.commitActiveRowEdit(),t._focusRow-=1,t._focusCol=o),U(t);return}case"ArrowDown":n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.min(i,t._focusRow+1),e.preventDefault();break;case"ArrowUp":n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault();break;case"ArrowRight":{Ne(t)?t._focusCol=Math.max(0,t._focusCol-1):t._focusCol=Math.min(o,t._focusCol+1),e.preventDefault();break}case"ArrowLeft":{Ne(t)?t._focusCol=Math.min(o,t._focusCol+1):t._focusCol=Math.max(0,t._focusCol-1),e.preventDefault();break}case"Home":(e.ctrlKey||e.metaKey)&&(n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=0),t._focusCol=0,e.preventDefault(),U(t,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=i),t._focusCol=o,e.preventDefault(),U(t,{forceScrollRight:!0});return;case"PageDown":t._focusRow=Math.min(i,t._focusRow+20),e.preventDefault();break;case"PageUp":t._focusRow=Math.max(0,t._focusRow-20),e.preventDefault();break;case"Enter":{const h=t._focusRow,f=t._focusCol,p=t._visibleColumns[f],g=t._rows[h],u=p?.field??"",d=u&&g?g[u]:void 0,w=t.querySelector(`[data-row="${h}"][data-col="${f}"]`),C={rowIndex:h,colIndex:f,column:p,field:u,value:d,row:g,cellEl:w,trigger:"keyboard",originalEvent:e},m=new CustomEvent("cell-activate",{cancelable:!0,detail:C});t.dispatchEvent(m);const E=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:h,col:f}});if(t.dispatchEvent(E),m.defaultPrevented||E.defaultPrevented){e.preventDefault();return}break}default:return}U(t)}}function U(t,e){if(t._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=t._virtualization,c=l,h=a?.clientHeight??c?.clientHeight??0;if(c&&h>0){const f=t._focusRow*s;f<c.scrollTop?c.scrollTop=f:f+s>c.scrollTop+h&&(c.scrollTop=f-h+s)}}const i=t._activeEditRows!==void 0&&t._activeEditRows!==-1;i||t.refreshVirtualWindow(!1),de(t._bodyEl),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const o=t._focusRow,n=t._virtualization.start??0,r=t._virtualization.end??t._rows.length;if(o>=n&&o<r){const s=t._bodyEl.querySelectorAll(".data-grid-row")[o-n];let l=s?.children[t._focusCol];if((!l||!l.classList?.contains("cell"))&&(l=s?.querySelector(`.cell[data-col="${t._focusCol}"]`)??s?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=t.querySelector(".tbw-scroll-area");if(a&&l&&(!i||e?.forceHorizontalScroll))if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=t._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const h=l.getBoundingClientRect(),f=a.getBoundingClientRect(),p=h.left-f.left+a.scrollLeft,g=p+h.width,u=a.scrollLeft+c.left,d=a.scrollLeft+a.clientWidth-c.right;p<u?a.scrollLeft=p-c.left:g>d&&(a.scrollLeft=g-a.clientWidth+c.right)}}if(i&&l.classList.contains("editing")){const c=l.querySelector(We);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(i&&!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}else if(!i){const c=t;document.activeElement!==c&&c.focus({preventScroll:!0})}}}}const Z=new WeakMap;function Wt(t,e){const i=Ie(e),o=Mt(e);if(i<0||o<0)return;t._focusRow=i,t._focusCol=o,de(t._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true");const n=e.closest("tbw-grid");n&&document.activeElement!==n&&n.focus({preventScroll:!0})}function ge(t,e,i,o){let n=null;const r=i.composedPath?.();if(r&&r.length>0?n=r[0]:n=i.target,n&&!e.contains(n)){const d=document.elementFromPoint(i.clientX,i.clientY);d&&(n=d)}const s=n?.closest?.("[data-col]"),l=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let c,h,f,p,g,u;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),h=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&h>=0&&(f=t._rows[c],u=t._columns[h],p=u?.field,g=f&&p?f[p]:void 0)),{type:o,row:f,rowIndex:c!==void 0&&c>=0?c:void 0,colIndex:h!==void 0&&h>=0?h:void 0,field:p,value:g,column:u,originalEvent:i,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:c!==void 0&&h!==void 0&&c>=0&&h>=0?{row:c,col:h}:void 0}}function Ft(t,e,i){const o=ge(t,e,i,"mousedown");(t._dispatchCellMouseDown?.(o)??!1)&&Z.set(t,!0)}function Ut(t,e,i){if(!Z.get(t))return;const o=ge(t,e,i,"mousemove");t._dispatchCellMouseMove?.(o)}function Vt(t,e,i){if(!Z.get(t))return;const o=ge(t,e,i,"mouseup");t._dispatchCellMouseUp?.(o),Z.set(t,!1)}function Gt(t,e,i){e.addEventListener("mousedown",o=>{const n=o.target.closest(".cell[data-col]");n&&(n.classList.contains("editing")||(o.preventDefault(),Wt(t,n)))},{signal:i}),e.addEventListener("click",o=>{const n=o.target.closest(".data-grid-row");if(n&&Ve(t,o,n),!document.activeElement?.closest(".cell.editing")){const r=o.target.closest("tbw-grid");r&&r.focus({preventScroll:!0})}},{signal:i}),e.addEventListener("dblclick",o=>{const n=o.target.closest(".data-grid-row");n&&Ve(t,o,n)},{signal:i})}function Bt(t,e,i,o){e.addEventListener("keydown",n=>$t(t,n),{signal:o}),i.addEventListener("mousedown",n=>Ft(t,i,n),{signal:o}),document.addEventListener("mousemove",n=>Ut(t,i,n),{signal:o}),document.addEventListener("mouseup",n=>Vt(t,i,n),{signal:o})}function Ge(t,e){return t==null&&e==null?0:t==null?-1:e==null||t>e?1:t<e?-1:0}function Be(t,e,i){const n=i.find(l=>l.field===e.field)?.sortComparator??Ge,{field:r,direction:s}=e;return[...t].sort((l,a)=>n(l[r],a[r],l,a)*s)}function Xe(t,e,i,o){t._rows=e,t.__rowRenderEpoch++,t._rowPool.forEach(n=>n.__epoch=-1),oe(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:i.field,direction:o}})),t.requestStateChange?.()}function Ye(t,e){!t._sortState||t._sortState.field!==e.field?(t._sortState||(t.__originalOrder=t._rows.slice()),je(t,e,1)):t._sortState.direction===1?je(t,e,-1):(t._sortState=null,t.__rowRenderEpoch++,t._rowPool.forEach(o=>o.__epoch=-1),t._rows=t.__originalOrder.slice(),oe(t),t._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(o=>{o.getAttribute("aria-sort")?(o.getAttribute("aria-sort")==="ascending"||o.getAttribute("aria-sort")==="descending")&&(t._sortState||o.setAttribute("aria-sort","none")):o.setAttribute("aria-sort","none")}),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),t.requestStateChange?.())}function je(t,e,i){t._sortState={field:e.field,direction:i};const o={field:e.field,direction:i},n=t._columns,s=(t.effectiveConfig?.sortHandler??Be)(t._rows,o,n);s&&typeof s.then=="function"?s.then(l=>{Xe(t,l,e,i)}):Xe(t,s,e,i)}function X(t,e){return t.effectiveConfig?.sortable!==!1&&e.sortable===!0}function J(t,e){return t.effectiveConfig?.resizable!==!1&&e.resizable!==!1}function Xt(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function ee(t,e){const i=document.createElement("span");Le(i,"sort-indicator");const o=t._sortState?.field===e.field?t._sortState.direction:0,n={...k,...t.icons},r=o===1?n.sortAsc:o===-1?n.sortDesc:n.sortNone;return Xt(i,r),i}function te(t,e,i){const o=document.createElement("div");return o.className="resize-handle",o.setAttribute("aria-hidden","true"),o.addEventListener("mousedown",n=>{n.stopPropagation(),n.preventDefault(),t._resizeController.start(n,e,i)}),o.addEventListener("dblclick",n=>{n.stopPropagation(),n.preventDefault(),t._resizeController.resetColumn(e)}),o}function ie(t,e,i,o){o.classList.add("sortable"),o.tabIndex=0;const n=t._sortState?.field===e.field?t._sortState.direction:0;o.setAttribute("aria-sort",n===0?"none":n===1?"ascending":"descending"),o.addEventListener("click",r=>{t._resizeController?.isResizing||t._dispatchHeaderClick?.(r,e,o)||Ye(t,e)}),o.addEventListener("keydown",r=>{if(r.key==="Enter"||r.key===" "){if(r.preventDefault(),t._dispatchHeaderClick?.(r,e,o))return;Ye(t,e)}})}function Yt(t,e){if(e!=null)if(typeof e=="string"){const i=document.createElement("span");for(i.innerHTML=N(e);i.firstChild;)t.appendChild(i.firstChild)}else e instanceof Node&&t.appendChild(e)}function oe(t){t._headerRowEl=t.findHeaderRow();const e=t._headerRowEl;e&&(e.innerHTML="",t._visibleColumns.forEach((i,o)=>{const n=document.createElement("div");n.className="cell",Le(n,"header-cell"),n.setAttribute("role","columnheader"),n.setAttribute("aria-colindex",String(o+1)),n.setAttribute("data-field",i.field),n.setAttribute("data-col",String(o)),i.type&&n.setAttribute("data-type",i.type);const r=i.header??i.field,s=t._sortState?.field===i.field?t._sortState.direction:0,l=s===1?"asc":s===-1?"desc":null;if(i.headerRenderer){const a={column:i,value:r,sortState:l,filterActive:!1,cellEl:n,renderSortIcon:()=>X(t,i)?ee(t,i):null,renderFilterButton:()=>null},c=i.headerRenderer(a);Yt(n,c),X(t,i)&&ie(t,i,o,n),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)))}else if(i.headerLabelRenderer){const a={column:i,value:r},c=i.headerLabelRenderer(a),h=document.createElement("span");c==null?h.textContent=r:typeof c=="string"?h.innerHTML=N(c):c instanceof Node&&h.appendChild(c),n.appendChild(h),X(t,i)&&(ie(t,i,o,n),n.appendChild(ee(t,i))),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)))}else if(i.__headerTemplate)Array.from(i.__headerTemplate.childNodes).forEach(a=>n.appendChild(a.cloneNode(!0))),X(t,i)&&(ie(t,i,o,n),n.appendChild(ee(t,i))),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)));else{const a=document.createElement("span");a.textContent=r,n.appendChild(a),X(t,i)&&(ie(t,i,o,n),n.appendChild(ee(t,i))),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)))}e.appendChild(n)}),e.querySelectorAll(".cell.sortable").forEach(i=>{i.getAttribute("aria-sort")||i.setAttribute("aria-sort","none")}),e.children.length>0?(e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1")):(e.removeAttribute("role"),e.removeAttribute("aria-rowindex")))}const Ke=typeof requestIdleCallback=="function";function jt(t,e){return Ke?requestIdleCallback(t,e):window.setTimeout(()=>{const i=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-i))})},1)}function Qe(t){Ke?cancelIdleCallback(t):clearTimeout(t)}function Kt(t){const e=document.createElement("div");return e.className=`tbw-spinner tbw-spinner--${t}`,e.setAttribute("role","progressbar"),e.setAttribute("aria-label","Loading"),e}function Qt(t,e){if(e){const o=e({size:t});if(typeof o=="string"){const n=document.createElement("div");return n.innerHTML=o,n}return o}return Kt(t)}function Zt(t){const e=document.createElement("div");return e.className="tbw-loading-overlay",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.appendChild(Qt("large",t)),e}function Jt(t,e){t.appendChild(e)}function ei(t){t?.remove()}function ti(t,e){if(e){if(t.classList.add("tbw-row-loading"),t.setAttribute("aria-busy","true"),!t.querySelector(".tbw-row-loading-overlay")){const i=document.createElement("div");i.className="tbw-row-loading-overlay",i.setAttribute("aria-hidden","true");const o=document.createElement("div");o.className="tbw-row-loading-spinner",i.appendChild(o),t.appendChild(i)}}else t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy"),t.querySelector(".tbw-row-loading-overlay")?.remove()}function ii(t,e){e?(t.classList.add("tbw-cell-loading"),t.setAttribute("aria-busy","true")):(t.classList.remove("tbw-cell-loading"),t.removeAttribute("aria-busy"))}var A=(t=>(t[t.STYLE=1]="STYLE",t[t.VIRTUALIZATION=2]="VIRTUALIZATION",t[t.HEADER=3]="HEADER",t[t.ROWS=4]="ROWS",t[t.COLUMNS=5]="COLUMNS",t[t.FULL=6]="FULL",t))(A||{});class oi{#l;#n=0;#u=0;#d=null;#h=null;#a=null;#o=!1;constructor(e){this.#l=e}requestPhase(e,i){e>this.#n&&(this.#n=e),this.#u===0&&(this.#f(),this.#u=requestAnimationFrame(()=>this.#w()))}whenReady(){return this.#d?this.#d:Promise.resolve()}setInitialReadyResolver(e){this.#a=e}cancel(){this.#u!==0&&(cancelAnimationFrame(this.#u),this.#u=0),this.#n=0,this.#h&&(this.#h(),this.#h=null,this.#d=null)}get isPending(){return this.#n!==0}get pendingPhase(){return this.#n}#f(){this.#d||(this.#d=new Promise(e=>{this.#h=e}))}#w(){if(this.#u=0,!this.#l.isConnected()){this.#n=0,this.#h&&(this.#h(),this.#h=null,this.#d=null);return}const e=this.#n;this.#n=0,e>=5&&this.#l.mergeConfig(),e>=4&&this.#l.processRows(),e>=5&&(this.#l.processColumns(),this.#l.updateTemplate()),e>=3&&this.#l.renderHeader(),e>=2&&this.#l.renderVirtualWindow(),e>=1&&this.#l.afterRender(),!this.#o&&this.#a&&(this.#o=!0,this.#a()),this.#h&&(this.#h(),this.#h=null,this.#d=null)}}function Ze(t){let e=null,i=null,o=null,n=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,h=Math.max(40,e.startWidth+c),f=t._visibleColumns[e.colIndex];f.width=h,f.__userResized=!0,f.__renderedWidth=h,i==null&&(i=requestAnimationFrame(()=>{i=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:f.field,width:h}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),o!==null&&(document.documentElement.style.cursor=o,o=null),n!==null&&(document.body.style.userSelect=n,n=null),e=null,a&&t.requestStateChange&&t.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,h){a.preventDefault();const f=t._visibleColumns[c],p=typeof f?.width=="number"?f.width:void 0,g=f?.__renderedWidth??p??h.getBoundingClientRect().width;e={startX:a.clientX,colIndex:c,startWidth:g},window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),o===null&&(o=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",n===null&&(n=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const c=t._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,t.updateTemplate?.(),t.requestStateChange?.(),t.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){l()}}}const pe="data-animating",ni={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},ri={change:500,insert:300,remove:200};function si(t){const e=t.trim().toLowerCase();return e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:parseFloat(e)}function li(t,e){const i=ni[e],o=getComputedStyle(t).getPropertyValue(i);if(o){const n=si(o);if(!isNaN(n)&&n>0)return n}return ri[e]}function ai(t,e,i){t.removeAttribute(pe),t.offsetWidth,t.setAttribute(pe,e);const o=li(t,e);setTimeout(()=>{e!=="remove"&&t.removeAttribute(pe)},o)}function we(t,e,i){if(e<0)return!1;const o=t.findRenderedRowElement?.(e);return o?(ai(o,i),!0):!1}function ci(t,e,i){let o=0;for(const n of e)we(t,n,i)&&o++;return o}function di(t,e,i){const o=t._rows??[],n=t.getRowId;if(!n)return!1;const r=o.findIndex(s=>{if(s==null)return!1;try{return n(s)===e}catch{return!1}});return r<0?!1:we(t,r,i)}function ne(t,e,i){const o=document.createElement(t);if(e)for(const n in e){const r=e[n];r!=null&&o.setAttribute(n,r)}return o}function P(t,e){const i=document.createElement("div");if(t&&(i.className=t),e)for(const o in e){const n=e[o];n!=null&&i.setAttribute(o,n)}return i}function Je(t,e,i){const o=document.createElement("button");if(t&&(o.className=t),e)for(const n in e){const r=e[n];r!=null&&o.setAttribute(n,r)}return o}const et=document.createElement("template");et.innerHTML=`
2
2
  <div class="tbw-scroll-area">
3
3
  <div class="rows-body-wrapper">
4
4
  <div class="rows-body" role="grid">
@@ -16,20 +16,20 @@
16
16
  <div class="faux-vscroll">
17
17
  <div class="faux-vscroll-spacer"></div>
18
18
  </div>
19
- `;function et(){return Je.content.cloneNode(!0)}function tt(t){const e=document.createDocumentFragment(),i=P(t.hasShell?"tbw-grid-root has-shell":"tbw-grid-root");if(t.hasShell&&t.shellHeader&&t.shellBody)i.appendChild(t.shellHeader),i.appendChild(t.shellBody);else{const o=P("tbw-grid-content");o.appendChild(et()),i.appendChild(o)}return e.appendChild(i),e}function hi(t){const e=P("tbw-shell-header",{part:"shell-header",role:"presentation"});if(t.title){const r=P("tbw-shell-title");r.textContent=t.title,e.appendChild(r)}const i=P("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});e.appendChild(i);const o=P("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const r of t.configButtons)r.hasRender&&o.appendChild(P("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));for(const r of t.apiButtons)r.hasRender&&o.appendChild(P("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));if((t.configButtons.some(r=>r.hasRender)||t.apiButtons.some(r=>r.hasRender))&&t.hasPanels&&o.appendChild(P("tbw-toolbar-separator")),t.hasPanels){const r=Ze(t.isPanelOpen?"tbw-toolbar-btn active":"tbw-toolbar-btn",{"data-panel-toggle":"",title:"Settings","aria-label":"Toggle settings panel","aria-pressed":String(t.isPanelOpen),"aria-controls":"tbw-tool-panel"});r.innerHTML=t.toolPanelIcon,o.appendChild(r)}return e.appendChild(o),e}function ui(t){const e=P("tbw-shell-body"),i=t.panels.length>0,o=t.panels.length===1,n=P("tbw-grid-content");n.appendChild(et());let r=null;if(i){r=ne("aside",{class:t.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":t.position,role:"presentation",id:"tbw-tool-panel"});const s=t.position==="left"?"right":"left";r.appendChild(P("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":s,"aria-hidden":"true"}));const l=P("tbw-tool-panel-content",{role:"presentation"}),a=P("tbw-accordion");for(const c of t.panels){const h=`tbw-accordion-section${c.isExpanded?" expanded":""}${o?" single":""}`,f=P(h,{"data-section":c.id}),p=Ze("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(o&&p.setAttribute("aria-disabled","true"),c.icon){const u=ne("span",{class:"tbw-accordion-icon"});u.innerHTML=c.icon,p.appendChild(u)}const g=ne("span",{class:"tbw-accordion-title"});if(g.textContent=c.title,p.appendChild(g),!o){const u=ne("span",{class:"tbw-accordion-chevron"});u.innerHTML=c.isExpanded?t.collapseIcon:t.expandIcon,p.appendChild(u)}f.appendChild(p),f.appendChild(P("tbw-accordion-content",{id:`tbw-section-${c.id}`,role:"presentation"})),a.appendChild(f)}l.appendChild(a),r.appendChild(l)}return t.position==="left"&&r?(e.appendChild(r),e.appendChild(n)):(e.appendChild(n),r&&e.appendChild(r)),e}function q(t){return t?typeof t=="string"?t:t.outerHTML:""}function fi(){return{toolPanels:new Map,headerContents:new Map,toolbarContents:new Map,hasToolButtonsContainer:!1,lightDomHeaderContent:[],lightDomTitle:null,lightDomToolPanelIds:new Set,lightDomToolbarContentIds:new Set,apiToolPanelIds:new Set,isPanelOpen:!1,expandedSections:new Set,headerContentCleanups:new Map,panelCleanups:new Map,toolbarContentCleanups:new Map,lightDomContentMoved:!1}}function it(t){return!!(t?.header?.title||t?.header?.toolbarContents?.length||t?.toolPanels?.length||t?.headerContents?.length||t?.header?.lightDomContent?.length||t?.header?.hasToolButtonsContainer)}function gi(t,e,i="☰"){const o=t?.header?.title??e.lightDomTitle??"",n=!!o,r=q(i),s=t?.header?.toolbarContents??[],l=[...e.toolbarContents.values()],a=new Set(s.map(d=>d.id)),c=[...s];for(const d of l)a.has(d.id)||c.push(d);const h=c.length>0,f=e.toolPanels.size>0,p=h&&f,g=[...c].sort((d,w)=>(d.order??0)-(w.order??0));let u="";for(const d of g)u+=`<div class="tbw-toolbar-content-slot" data-toolbar-content="${d.id}"></div>`;if(p&&(u+='<div class="tbw-toolbar-separator"></div>'),f){const d=e.isPanelOpen;u+=`<button class="${d?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${d}" aria-controls="tbw-tool-panel">${r}</button>`}return`
19
+ `;function tt(){return et.content.cloneNode(!0)}function it(t){const e=document.createDocumentFragment(),i=P(t.hasShell?"tbw-grid-root has-shell":"tbw-grid-root");if(t.hasShell&&t.shellHeader&&t.shellBody)i.appendChild(t.shellHeader),i.appendChild(t.shellBody);else{const o=P("tbw-grid-content");o.appendChild(tt()),i.appendChild(o)}return e.appendChild(i),e}function hi(t){const e=P("tbw-shell-header",{part:"shell-header",role:"presentation"});if(t.title){const r=P("tbw-shell-title");r.textContent=t.title,e.appendChild(r)}const i=P("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});e.appendChild(i);const o=P("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const r of t.configButtons)r.hasRender&&o.appendChild(P("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));for(const r of t.apiButtons)r.hasRender&&o.appendChild(P("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));if((t.configButtons.some(r=>r.hasRender)||t.apiButtons.some(r=>r.hasRender))&&t.hasPanels&&o.appendChild(P("tbw-toolbar-separator")),t.hasPanels){const r=Je(t.isPanelOpen?"tbw-toolbar-btn active":"tbw-toolbar-btn",{"data-panel-toggle":"",title:"Settings","aria-label":"Toggle settings panel","aria-pressed":String(t.isPanelOpen),"aria-controls":"tbw-tool-panel"});r.innerHTML=t.toolPanelIcon,o.appendChild(r)}return e.appendChild(o),e}function ui(t){const e=P("tbw-shell-body"),i=t.panels.length>0,o=t.panels.length===1,n=P("tbw-grid-content");n.appendChild(tt());let r=null;if(i){r=ne("aside",{class:t.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":t.position,role:"presentation",id:"tbw-tool-panel"});const s=t.position==="left"?"right":"left";r.appendChild(P("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":s,"aria-hidden":"true"}));const l=P("tbw-tool-panel-content",{role:"presentation"}),a=P("tbw-accordion");for(const c of t.panels){const h=`tbw-accordion-section${c.isExpanded?" expanded":""}${o?" single":""}`,f=P(h,{"data-section":c.id}),p=Je("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(o&&p.setAttribute("aria-disabled","true"),c.icon){const u=ne("span",{class:"tbw-accordion-icon"});u.innerHTML=c.icon,p.appendChild(u)}const g=ne("span",{class:"tbw-accordion-title"});if(g.textContent=c.title,p.appendChild(g),!o){const u=ne("span",{class:"tbw-accordion-chevron"});u.innerHTML=c.isExpanded?t.collapseIcon:t.expandIcon,p.appendChild(u)}f.appendChild(p),f.appendChild(P("tbw-accordion-content",{id:`tbw-section-${c.id}`,role:"presentation"})),a.appendChild(f)}l.appendChild(a),r.appendChild(l)}return t.position==="left"&&r?(e.appendChild(r),e.appendChild(n)):(e.appendChild(n),r&&e.appendChild(r)),e}function $(t){return t?typeof t=="string"?t:t.outerHTML:""}function fi(){return{toolPanels:new Map,headerContents:new Map,toolbarContents:new Map,hasToolButtonsContainer:!1,lightDomHeaderContent:[],lightDomTitle:null,lightDomToolPanelIds:new Set,lightDomToolbarContentIds:new Set,apiToolPanelIds:new Set,isPanelOpen:!1,expandedSections:new Set,headerContentCleanups:new Map,panelCleanups:new Map,toolbarContentCleanups:new Map,lightDomContentMoved:!1}}function ot(t){return!!(t?.header?.title||t?.header?.toolbarContents?.length||t?.toolPanels?.length||t?.headerContents?.length||t?.header?.lightDomContent?.length||t?.header?.hasToolButtonsContainer)}function gi(t,e,i="☰"){const o=t?.header?.title??e.lightDomTitle??"",n=!!o,r=$(i),s=t?.header?.toolbarContents??[],l=[...e.toolbarContents.values()],a=new Set(s.map(d=>d.id)),c=[...s];for(const d of l)a.has(d.id)||c.push(d);const h=c.length>0,f=e.toolPanels.size>0,p=h&&f,g=[...c].sort((d,w)=>(d.order??0)-(w.order??0));let u="";for(const d of g)u+=`<div class="tbw-toolbar-content-slot" data-toolbar-content="${d.id}"></div>`;if(p&&(u+='<div class="tbw-toolbar-separator"></div>'),f){const d=e.isPanelOpen;u+=`<button class="${d?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${d}" aria-controls="tbw-tool-panel">${r}</button>`}return`
20
20
  <div class="tbw-shell-header" part="shell-header" role="presentation">
21
- ${n?`<div class="tbw-shell-title">${Rt(o)}</div>`:""}
21
+ ${n?`<div class="tbw-shell-title">${At(o)}</div>`:""}
22
22
  <div class="tbw-shell-content" part="shell-content" role="presentation" data-light-dom-header-content></div>
23
23
  <div class="tbw-shell-toolbar" part="shell-toolbar" role="presentation">
24
24
  ${u}
25
25
  </div>
26
26
  </div>
27
- `}function ot(t,e){const i=t.querySelector("tbw-grid-header");if(!i)return;if(!e.lightDomTitle){const n=i.getAttribute("title");n&&(e.lightDomTitle=n)}const o=i.querySelectorAll("tbw-grid-header-content");o.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(o)),i.style.display="none"}function nt(t,e,i){const o=t.querySelector(":scope > tbw-grid-tool-buttons");if(!o)return;e.hasToolButtonsContainer=!0;const n="light-dom-toolbar-content";if(e.lightDomToolbarContentIds.has(n))return;const r={id:n,order:0,render:(s=>{for(;o.firstChild;)s.appendChild(o.firstChild);return()=>{for(;s.firstChild;)o.appendChild(s.firstChild)}})};e.toolbarContents.set(n,r),e.lightDomToolbarContentIds.add(n),o.style.display="none"}function rt(t,e,i){t.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(n=>{const r=n,s=r.getAttribute("id"),l=r.getAttribute("title");if(!s||!l){console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${s??""}", title="${l??""}"`);return}const a=r.getAttribute("icon")??void 0,c=r.getAttribute("tooltip")??void 0,h=parseInt(r.getAttribute("order")??"100",10);let f;const p=i?.(r);if(p)f=p;else{const d=r.innerHTML.trim();f=w=>{const v=document.createElement("div");return v.innerHTML=d,w.appendChild(v),()=>v.remove()}}const g=e.toolPanels.get(s);if(g){if(p){g.render=f,g.order=h,g.icon=a,g.tooltip=c;const d=e.panelCleanups.get(s);d&&(d(),e.panelCleanups.delete(s))}return}const u={id:s,title:l,icon:a,tooltip:c,order:h,render:f};e.toolPanels.set(s,u),e.lightDomToolPanelIds.add(s),r.style.display="none"})}function pi(t,e,i,o){const n=t.querySelector(".tbw-shell-toolbar");n&&n.addEventListener("click",s=>{if(s.target.closest("[data-panel-toggle]")){o.onPanelToggle();return}});const r=t.querySelector(".tbw-accordion");r&&r.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const h=a.closest("[data-section]")?.getAttribute("data-section");h&&o.onSectionToggle(h)}})}function wi(t,e,i,o){if(!e?.toolPanel?.closeOnClickOutside)return()=>{};const n=r=>{if(!i.isPanelOpen)return;const s=r.target;s&&(s.closest(".tbw-tool-panel")||s.closest("[data-panel-toggle]")||o())};return t.addEventListener("mousedown",n),()=>t.removeEventListener("mousedown",n)}function bi(t,e,i){const o=t.querySelector(".tbw-tool-panel"),n=t.querySelector("[data-resize-handle]"),r=t.querySelector(".tbw-shell-body");if(!o||!n||!r)return()=>{};const s=e?.toolPanel?.position??"right",l=200;let a=0,c=0,h=0,f=!1;const p=d=>{if(!f)return;d.preventDefault();const w=s==="left"?d.clientX-a:a-d.clientX,v=Math.min(h,Math.max(l,c+w));o.style.width=`${v}px`},g=()=>{if(!f)return;f=!1,n.classList.remove("resizing"),o.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const d=o.getBoundingClientRect().width;i(d),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",g)},u=d=>{d.preventDefault(),f=!0,a=d.clientX,c=o.getBoundingClientRect().width,h=r.getBoundingClientRect().width-20,n.classList.add("resizing"),o.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",p),document.addEventListener("mouseup",g)};return n.addEventListener("mousedown",u),()=>{n.removeEventListener("mousedown",u),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",g)}}function pe(t,e,i){const o=e?.header?.toolbarContents??[],n=[...i.toolbarContents.values()],r=new Set(o.map(l=>l.id)),s=[...o];for(const l of n)r.has(l.id)||s.push(l);for(const l of s){if(i.toolbarContentCleanups.has(l.id)||!l.render)continue;const a=t.querySelector(`[data-toolbar-content="${l.id}"]`);if(!a)continue;const c=l.render(a);c&&i.toolbarContentCleanups.set(l.id,c)}}function we(t,e){const i=e.lightDomHeaderContent.length>0&&!e.lightDomContentMoved,o=e.headerContents.size>0;if(!i&&!o)return;const n=t.querySelector(".tbw-shell-content");if(!n)return;if(i){for(const s of e.lightDomHeaderContent)s.style.display="",n.appendChild(s);e.lightDomContentMoved=!0}const r=[...e.headerContents.values()].sort((s,l)=>(s.order??100)-(l.order??100));for(const s of r){const l=e.headerContentCleanups.get(s.id);l&&(l(),e.headerContentCleanups.delete(s.id));let a=n.querySelector(`[data-header-content="${s.id}"]`);a||(a=document.createElement("div"),a.setAttribute("data-header-content",s.id),n.appendChild(a));const c=s.render(a);c&&e.headerContentCleanups.set(s.id,c)}}function mi(t,e,i){if(!e.isPanelOpen)return;const o=q(i?.expand??k.expand),n=q(i?.collapse??k.collapse);for(const[r,s]of e.toolPanels){const l=e.expandedSections.has(r),a=t.querySelector(`[data-section="${r}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",l);const h=a.querySelector(".tbw-accordion-header");h&&h.setAttribute("aria-expanded",String(l));const f=a.querySelector(".tbw-accordion-chevron");if(f&&(f.innerHTML=l?n:o),l){if(c.children.length===0){const p=s.render(c);p&&e.panelCleanups.set(r,p)}}else{const p=e.panelCleanups.get(r);p&&(p(),e.panelCleanups.delete(r)),c.innerHTML=""}}}function st(t,e){const i=t.querySelector("[data-panel-toggle]");i&&(i.classList.toggle("active",e.isPanelOpen),i.setAttribute("aria-pressed",String(e.isPanelOpen)))}function lt(t,e){const i=t.querySelector(".tbw-tool-panel");i&&(i.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(i.style.width=""))}function be(t){for(const e of t.toolbarContentCleanups.values())e();t.toolbarContentCleanups.clear()}function vi(t){for(const e of t.headerContentCleanups.values())e();t.headerContentCleanups.clear();for(const e of t.panelCleanups.values())e();t.panelCleanups.clear();for(const e of t.toolbarContentCleanups.values())e();t.toolbarContentCleanups.clear();for(const e of t.toolbarContents.values())e.onDestroy?.();if(t.isPanelOpen)for(const e of t.expandedSections)t.toolPanels.get(e)?.onClose?.();t.isPanelOpen=!1,t.expandedSections.clear(),t.toolPanels.clear(),t.headerContents.clear(),t.toolbarContents.clear(),t.lightDomHeaderContent=[],t.lightDomToolPanelIds.clear(),t.lightDomToolbarContentIds.clear(),t.lightDomContentMoved=!1}function Ci(t,e){let i=!1;const o={get isInitialized(){return i},setInitialized(n){i=n},get isPanelOpen(){return t.isPanelOpen},get activePanel(){return t.isPanelOpen&&t.expandedSections.size>0?[...t.expandedSections][0]:null},get expandedSections(){return[...t.expandedSections]},openToolPanel(){if(t.isPanelOpen)return;if(t.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(t.isPanelOpen=!0,t.expandedSections.size===0&&t.toolPanels.size>0){const s=[...t.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];s&&t.expandedSections.add(s.id)}const n=e.getShadow();st(n,t),lt(n,t),mi(n,t,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:o.expandedSections})},closeToolPanel(){if(!t.isPanelOpen)return;for(const r of t.panelCleanups.values())r();t.panelCleanups.clear();for(const r of t.toolPanels.values())r.onClose?.();t.isPanelOpen=!1;const n=e.getShadow();st(n,t),lt(n,t),e.emit("tool-panel-close",{})},toggleToolPanel(){t.isPanelOpen?o.closeToolPanel():o.openToolPanel()},toggleToolPanelSection(n){const r=t.toolPanels.get(n);if(!r){console.warn(`[tbw-grid] Tool panel section "${n}" not found`);return}if(t.toolPanels.size===1)return;const s=e.getShadow(),l=t.expandedSections.has(n);if(l){const a=t.panelCleanups.get(n);a&&(a(),t.panelCleanups.delete(n)),r.onClose?.(),t.expandedSections.delete(n),me(s,n,!1)}else{for(const[a,c]of t.toolPanels)if(a!==n&&t.expandedSections.has(a)){const h=t.panelCleanups.get(a);h&&(h(),t.panelCleanups.delete(a)),c.onClose?.(),t.expandedSections.delete(a),me(s,a,!1);const f=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);f&&(f.innerHTML="")}t.expandedSections.add(n),me(s,n,!0),yi(s,t,n)}e.emit("tool-panel-section-toggle",{id:n,expanded:!l})},getToolPanels(){return[...t.toolPanels.values()]},registerToolPanel(n){if(t.toolPanels.has(n.id)){console.warn(`[tbw-grid] Tool panel "${n.id}" already registered`);return}t.toolPanels.set(n.id,n),i&&e.refreshShellHeader()},unregisterToolPanel(n){if(t.expandedSections.has(n)){const r=t.panelCleanups.get(n);r&&(r(),t.panelCleanups.delete(n)),t.expandedSections.delete(n)}t.toolPanels.delete(n),i&&e.refreshShellHeader()},getHeaderContents(){return[...t.headerContents.values()]},registerHeaderContent(n){if(t.headerContents.has(n.id)){console.warn(`[tbw-grid] Header content "${n.id}" already registered`);return}t.headerContents.set(n.id,n),i&&we(e.getShadow(),t)},unregisterHeaderContent(n){const r=t.headerContentCleanups.get(n);r&&(r(),t.headerContentCleanups.delete(n)),t.headerContents.get(n)?.onDestroy?.(),t.headerContents.delete(n),e.getShadow().querySelector(`[data-header-content="${n}"]`)?.remove()},getToolbarContents(){return[...t.toolbarContents.values()].sort((n,r)=>(n.order??0)-(r.order??0))},registerToolbarContent(n){if(t.toolbarContents.has(n.id)){console.warn(`[tbw-grid] Toolbar content "${n.id}" already registered`);return}t.toolbarContents.set(n.id,n),i&&e.refreshShellHeader()},unregisterToolbarContent(n){const r=t.toolbarContentCleanups.get(n);r&&(r(),t.toolbarContentCleanups.delete(n));const s=t.toolbarContents.get(n);s?.onDestroy&&s.onDestroy(),t.toolbarContents.delete(n),i&&e.refreshShellHeader()}};return o}function me(t,e,i){const o=t.querySelector(`[data-section="${e}"]`);o&&o.classList.toggle("expanded",i)}function yi(t,e,i){const o=e.toolPanels.get(i);if(!o?.render)return;const n=t.querySelector(`[data-section="${i}"] .tbw-accordion-content`);if(!n)return;const r=o.render(n);r&&e.panelCleanups.set(i,r)}function _i(t,e,i,o){const n=it(e),r=[],s=["tbw-grid-header","tbw-grid-tool-buttons","tbw-grid-tool-panel","tbw-grid-column","tbw-grid-detail","tbw-grid-responsive-card"];for(const l of s)t.querySelectorAll(`:scope > ${l}`).forEach(c=>r.push(c));t.replaceChildren();for(const l of r)t.appendChild(l);if(n){const l=q(o?.toolPanel??k.toolPanel),a=q(o?.expand??k.expand),c=q(o?.collapse??k.collapse),f=[...e?.header?.toolbarContents??[]].sort((E,T)=>(E.order??0)-(T.order??0)),g=[...e?.toolPanels??[]].sort((E,T)=>(E.order??100)-(T.order??100)),u={title:e?.header?.title??void 0,hasPanels:g.length>0,isPanelOpen:i.isPanelOpen,toolPanelIcon:l,configButtons:f.map(E=>({id:E.id,hasElement:!1,hasRender:!!E.render})),apiButtons:[]},d={position:e?.toolPanel?.position??"right",isPanelOpen:i.isPanelOpen,expandIcon:a,collapseIcon:c,panels:g.map(E=>({id:E.id,title:E.title,icon:q(E.icon),isExpanded:i.expandedSections.has(E.id)}))},w=hi(u),v=ui(d),b=tt({hasShell:!0,shellHeader:w,shellBody:v});t.appendChild(b)}else{const l=tt({hasShell:!1});t.appendChild(l)}return n}const at="tbw-grid-styles";let re="";const ve=new Map;function Ei(){let t=document.getElementById(at);return t||(t=document.createElement("style"),t.id=at,t.setAttribute("data-tbw-grid","true"),document.head.appendChild(t)),t}function Ce(){const t=Ei(),e=Array.from(ve.values()).join(`
27
+ `}function nt(t,e){const i=t.querySelector("tbw-grid-header");if(!i)return;if(!e.lightDomTitle){const n=i.getAttribute("title");n&&(e.lightDomTitle=n)}const o=i.querySelectorAll("tbw-grid-header-content");o.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(o)),i.style.display="none"}function rt(t,e,i){const o=t.querySelector(":scope > tbw-grid-tool-buttons");if(!o)return;e.hasToolButtonsContainer=!0;const n="light-dom-toolbar-content";if(e.lightDomToolbarContentIds.has(n))return;const r={id:n,order:0,render:(s=>{for(;o.firstChild;)s.appendChild(o.firstChild);return()=>{for(;s.firstChild;)o.appendChild(s.firstChild)}})};e.toolbarContents.set(n,r),e.lightDomToolbarContentIds.add(n),o.style.display="none"}function st(t,e,i){t.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(n=>{const r=n,s=r.getAttribute("id"),l=r.getAttribute("title");if(!s||!l){console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${s??""}", title="${l??""}"`);return}const a=r.getAttribute("icon")??void 0,c=r.getAttribute("tooltip")??void 0,h=parseInt(r.getAttribute("order")??"100",10);let f;const p=i?.(r);if(p)f=p;else{const d=r.innerHTML.trim();f=w=>{const C=document.createElement("div");return C.innerHTML=d,w.appendChild(C),()=>C.remove()}}const g=e.toolPanels.get(s);if(g){if(p){g.render=f,g.order=h,g.icon=a,g.tooltip=c;const d=e.panelCleanups.get(s);d&&(d(),e.panelCleanups.delete(s))}return}const u={id:s,title:l,icon:a,tooltip:c,order:h,render:f};e.toolPanels.set(s,u),e.lightDomToolPanelIds.add(s),r.style.display="none"})}function pi(t,e,i,o){const n=t.querySelector(".tbw-shell-toolbar");n&&n.addEventListener("click",s=>{if(s.target.closest("[data-panel-toggle]")){o.onPanelToggle();return}});const r=t.querySelector(".tbw-accordion");r&&r.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const h=a.closest("[data-section]")?.getAttribute("data-section");h&&o.onSectionToggle(h)}})}function wi(t,e,i,o){if(!e?.toolPanel?.closeOnClickOutside)return()=>{};const n=r=>{if(!i.isPanelOpen)return;const s=r.target;s&&(s.closest(".tbw-tool-panel")||s.closest("[data-panel-toggle]")||o())};return t.addEventListener("mousedown",n),()=>t.removeEventListener("mousedown",n)}function bi(t,e,i){const o=t.querySelector(".tbw-tool-panel"),n=t.querySelector("[data-resize-handle]"),r=t.querySelector(".tbw-shell-body");if(!o||!n||!r)return()=>{};const s=e?.toolPanel?.position??"right",l=200;let a=0,c=0,h=0,f=!1;const p=d=>{if(!f)return;d.preventDefault();const w=s==="left"?d.clientX-a:a-d.clientX,C=Math.min(h,Math.max(l,c+w));o.style.width=`${C}px`},g=()=>{if(!f)return;f=!1,n.classList.remove("resizing"),o.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const d=o.getBoundingClientRect().width;i(d),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",g)},u=d=>{d.preventDefault(),f=!0,a=d.clientX,c=o.getBoundingClientRect().width,h=r.getBoundingClientRect().width-20,n.classList.add("resizing"),o.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",p),document.addEventListener("mouseup",g)};return n.addEventListener("mousedown",u),()=>{n.removeEventListener("mousedown",u),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",g)}}function be(t,e,i){const o=e?.header?.toolbarContents??[],n=[...i.toolbarContents.values()],r=new Set(o.map(l=>l.id)),s=[...o];for(const l of n)r.has(l.id)||s.push(l);for(const l of s){if(i.toolbarContentCleanups.has(l.id)||!l.render)continue;const a=t.querySelector(`[data-toolbar-content="${l.id}"]`);if(!a)continue;const c=l.render(a);c&&i.toolbarContentCleanups.set(l.id,c)}}function me(t,e){const i=e.lightDomHeaderContent.length>0&&!e.lightDomContentMoved,o=e.headerContents.size>0;if(!i&&!o)return;const n=t.querySelector(".tbw-shell-content");if(!n)return;if(i){for(const s of e.lightDomHeaderContent)s.style.display="",n.appendChild(s);e.lightDomContentMoved=!0}const r=[...e.headerContents.values()].sort((s,l)=>(s.order??100)-(l.order??100));for(const s of r){const l=e.headerContentCleanups.get(s.id);l&&(l(),e.headerContentCleanups.delete(s.id));let a=n.querySelector(`[data-header-content="${s.id}"]`);a||(a=document.createElement("div"),a.setAttribute("data-header-content",s.id),n.appendChild(a));const c=s.render(a);c&&e.headerContentCleanups.set(s.id,c)}}function mi(t,e,i){if(!e.isPanelOpen)return;const o=$(i?.expand??k.expand),n=$(i?.collapse??k.collapse);for(const[r,s]of e.toolPanels){const l=e.expandedSections.has(r),a=t.querySelector(`[data-section="${r}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",l);const h=a.querySelector(".tbw-accordion-header");h&&h.setAttribute("aria-expanded",String(l));const f=a.querySelector(".tbw-accordion-chevron");if(f&&(f.innerHTML=l?n:o),l){if(c.children.length===0){const p=s.render(c);p&&e.panelCleanups.set(r,p)}}else{const p=e.panelCleanups.get(r);p&&(p(),e.panelCleanups.delete(r)),c.innerHTML=""}}}function lt(t,e){const i=t.querySelector("[data-panel-toggle]");i&&(i.classList.toggle("active",e.isPanelOpen),i.setAttribute("aria-pressed",String(e.isPanelOpen)))}function at(t,e){const i=t.querySelector(".tbw-tool-panel");i&&(i.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(i.style.width=""))}function ve(t){for(const e of t.toolbarContentCleanups.values())e();t.toolbarContentCleanups.clear()}function vi(t){for(const e of t.headerContentCleanups.values())e();t.headerContentCleanups.clear();for(const e of t.panelCleanups.values())e();t.panelCleanups.clear();for(const e of t.toolbarContentCleanups.values())e();t.toolbarContentCleanups.clear();for(const e of t.toolbarContents.values())e.onDestroy?.();if(t.isPanelOpen)for(const e of t.expandedSections)t.toolPanels.get(e)?.onClose?.();t.isPanelOpen=!1,t.expandedSections.clear(),t.toolPanels.clear(),t.headerContents.clear(),t.toolbarContents.clear(),t.lightDomHeaderContent=[],t.lightDomToolPanelIds.clear(),t.lightDomToolbarContentIds.clear(),t.lightDomContentMoved=!1}function Ci(t,e){let i=!1;const o={get isInitialized(){return i},setInitialized(n){i=n},get isPanelOpen(){return t.isPanelOpen},get activePanel(){return t.isPanelOpen&&t.expandedSections.size>0?[...t.expandedSections][0]:null},get expandedSections(){return[...t.expandedSections]},openToolPanel(){if(t.isPanelOpen)return;if(t.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(t.isPanelOpen=!0,t.expandedSections.size===0&&t.toolPanels.size>0){const s=[...t.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];s&&t.expandedSections.add(s.id)}const n=e.getShadow();lt(n,t),at(n,t),mi(n,t,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:o.expandedSections})},closeToolPanel(){if(!t.isPanelOpen)return;for(const r of t.panelCleanups.values())r();t.panelCleanups.clear();for(const r of t.toolPanels.values())r.onClose?.();t.isPanelOpen=!1;const n=e.getShadow();lt(n,t),at(n,t),e.emit("tool-panel-close",{})},toggleToolPanel(){t.isPanelOpen?o.closeToolPanel():o.openToolPanel()},toggleToolPanelSection(n){const r=t.toolPanels.get(n);if(!r){console.warn(`[tbw-grid] Tool panel section "${n}" not found`);return}if(t.toolPanels.size===1)return;const s=e.getShadow(),l=t.expandedSections.has(n);if(l){const a=t.panelCleanups.get(n);a&&(a(),t.panelCleanups.delete(n)),r.onClose?.(),t.expandedSections.delete(n),Ce(s,n,!1)}else{for(const[a,c]of t.toolPanels)if(a!==n&&t.expandedSections.has(a)){const h=t.panelCleanups.get(a);h&&(h(),t.panelCleanups.delete(a)),c.onClose?.(),t.expandedSections.delete(a),Ce(s,a,!1);const f=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);f&&(f.innerHTML="")}t.expandedSections.add(n),Ce(s,n,!0),yi(s,t,n)}e.emit("tool-panel-section-toggle",{id:n,expanded:!l})},getToolPanels(){return[...t.toolPanels.values()]},registerToolPanel(n){if(t.toolPanels.has(n.id)){console.warn(`[tbw-grid] Tool panel "${n.id}" already registered`);return}t.toolPanels.set(n.id,n),i&&e.refreshShellHeader()},unregisterToolPanel(n){if(t.expandedSections.has(n)){const r=t.panelCleanups.get(n);r&&(r(),t.panelCleanups.delete(n)),t.expandedSections.delete(n)}t.toolPanels.delete(n),i&&e.refreshShellHeader()},getHeaderContents(){return[...t.headerContents.values()]},registerHeaderContent(n){if(t.headerContents.has(n.id)){console.warn(`[tbw-grid] Header content "${n.id}" already registered`);return}t.headerContents.set(n.id,n),i&&me(e.getShadow(),t)},unregisterHeaderContent(n){const r=t.headerContentCleanups.get(n);r&&(r(),t.headerContentCleanups.delete(n)),t.headerContents.get(n)?.onDestroy?.(),t.headerContents.delete(n),e.getShadow().querySelector(`[data-header-content="${n}"]`)?.remove()},getToolbarContents(){return[...t.toolbarContents.values()].sort((n,r)=>(n.order??0)-(r.order??0))},registerToolbarContent(n){if(t.toolbarContents.has(n.id)){console.warn(`[tbw-grid] Toolbar content "${n.id}" already registered`);return}t.toolbarContents.set(n.id,n),i&&e.refreshShellHeader()},unregisterToolbarContent(n){const r=t.toolbarContentCleanups.get(n);r&&(r(),t.toolbarContentCleanups.delete(n));const s=t.toolbarContents.get(n);s?.onDestroy&&s.onDestroy(),t.toolbarContents.delete(n),i&&e.refreshShellHeader()}};return o}function Ce(t,e,i){const o=t.querySelector(`[data-section="${e}"]`);o&&o.classList.toggle("expanded",i)}function yi(t,e,i){const o=e.toolPanels.get(i);if(!o?.render)return;const n=t.querySelector(`[data-section="${i}"] .tbw-accordion-content`);if(!n)return;const r=o.render(n);r&&e.panelCleanups.set(i,r)}function _i(t,e,i,o){const n=ot(e),r=[],s=["tbw-grid-header","tbw-grid-tool-buttons","tbw-grid-tool-panel","tbw-grid-column","tbw-grid-detail","tbw-grid-responsive-card"];for(const l of s)t.querySelectorAll(`:scope > ${l}`).forEach(c=>r.push(c));t.replaceChildren();for(const l of r)t.appendChild(l);if(n){const l=$(o?.toolPanel??k.toolPanel),a=$(o?.expand??k.expand),c=$(o?.collapse??k.collapse),f=[...e?.header?.toolbarContents??[]].sort((E,T)=>(E.order??0)-(T.order??0)),g=[...e?.toolPanels??[]].sort((E,T)=>(E.order??100)-(T.order??100)),u={title:e?.header?.title??void 0,hasPanels:g.length>0,isPanelOpen:i.isPanelOpen,toolPanelIcon:l,configButtons:f.map(E=>({id:E.id,hasElement:!1,hasRender:!!E.render})),apiButtons:[]},d={position:e?.toolPanel?.position??"right",isPanelOpen:i.isPanelOpen,expandIcon:a,collapseIcon:c,panels:g.map(E=>({id:E.id,title:E.title,icon:$(E.icon),isExpanded:i.expandedSections.has(E.id)}))},w=hi(u),C=ui(d),m=it({hasShell:!0,shellHeader:w,shellBody:C});t.appendChild(m)}else{const l=it({hasShell:!1});t.appendChild(l)}return n}const ct="tbw-grid-styles";let re="";const ye=new Map;function Ei(){let t=document.getElementById(ct);return t||(t=document.createElement("style"),t.id=ct,t.setAttribute("data-tbw-grid","true"),document.head.appendChild(t)),t}function _e(){const t=Ei(),e=Array.from(ye.values()).join(`
28
28
  `);t.textContent=`${re}
29
29
 
30
30
  /* Plugin Styles */
31
- ${e}`}function Si(t){let e=!1;for(const{name:i,styles:o}of t)ve.has(i)||(ve.set(i,o),e=!0);return e&&Ce(),e}function Ri(){try{for(const t of Array.from(document.styleSheets))try{const i=Array.from(t.cssRules||[]).map(o=>o.cssText).join(`
32
- `);if(i.includes(".tbw-grid-root")&&i.includes("tbw-grid"))return i}catch{continue}}catch(t){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",t)}return null}async function Ai(t){if(re)return;if(typeof t=="string"&&t.length>0){re=t,Ce();return}await new Promise(i=>setTimeout(i,50));const e=Ri();e?(re=e,Ce()):(typeof process>"u"||process.env?.NODE_ENV!=="test")&&console.warn("[tbw-grid] Could not find grid.css in document.styleSheets. Grid styling will not work.","Available stylesheets:",Array.from(document.styleSheets).map(i=>i.href||"(inline)"))}function Ti(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function xi(t){t.startY=null,t.startX=null,t.scrollTop=null,t.scrollLeft=null,t.lastY=null,t.lastX=null,t.lastTime=null}function ct(t){t.momentumRaf&&(cancelAnimationFrame(t.momentumRaf),t.momentumRaf=0)}function Hi(t,e,i){if(t.touches.length!==1)return;ct(e);const o=t.touches[0];e.startY=o.clientY,e.startX=o.clientX,e.lastY=o.clientY,e.lastX=o.clientX,e.lastTime=performance.now(),e.scrollTop=i.fauxScrollbar.scrollTop,e.scrollLeft=i.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function Li(t,e,i){if(t.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const o=t.touches[0],n=o.clientY,r=o.clientX,s=performance.now(),l=e.startY-n,a=e.startX-r;if(e.lastTime!==null&&e.lastY!==null&&e.lastX!==null){const d=s-e.lastTime;d>0&&(e.velocityY=(e.lastY-n)/d,e.velocityX=(e.lastX-r)/d)}e.lastY=n,e.lastX=r,e.lastTime=s;const{scrollTop:c,scrollHeight:h,clientHeight:f}=i.fauxScrollbar,p=h-f,g=l>0&&c<p||l<0&&c>0;let u=!1;if(i.scrollArea){const{scrollLeft:d,scrollWidth:w,clientWidth:v}=i.scrollArea,b=w-v;u=a>0&&d<b||a<0&&d>0}return g&&(i.fauxScrollbar.scrollTop=e.scrollTop+l),u&&i.scrollArea&&(i.scrollArea.scrollLeft=e.scrollLeft+a),g||u}function Pi(t,e){(Math.abs(t.velocityY)>.1||Math.abs(t.velocityX)>.1)&&zi(t,e),xi(t)}function zi(t,e){const n=()=>{t.velocityY*=.95,t.velocityX*=.95;const r=t.velocityY*16,s=t.velocityX*16;Math.abs(t.velocityY)>.01&&(e.fauxScrollbar.scrollTop+=r),Math.abs(t.velocityX)>.01&&e.scrollArea&&(e.scrollArea.scrollLeft+=s),Math.abs(t.velocityY)>.01||Math.abs(t.velocityX)>.01?t.momentumRaf=requestAnimationFrame(n):t.momentumRaf=0};t.momentumRaf=requestAnimationFrame(n)}function Di(t,e,i,o){t.addEventListener("touchstart",n=>Hi(n,e,i),{passive:!0,signal:o}),t.addEventListener("touchmove",n=>{Li(n,e,i)&&n.preventDefault()},{passive:!1,signal:o}),t.addEventListener("touchend",()=>Pi(e,i),{passive:!0,signal:o})}const Oi=[{property:"editable",pluginName:"editing",level:"column",description:'the "editable" column property',isUsed:t=>t===!0},{property:"editor",pluginName:"editing",level:"column",description:'the "editor" column property'},{property:"editorParams",pluginName:"editing",level:"column",description:'the "editorParams" column property'},{property:"group",pluginName:"groupingColumns",level:"column",description:'the "group" column property'},{property:"pinned",pluginName:"pinnedColumns",level:"column",description:'the "pinned" column property',isUsed:t=>t==="left"||t==="right"||t==="start"||t==="end"},{property:"sticky",pluginName:"pinnedColumns",level:"column",description:'the "sticky" column property (deprecated, use "pinned")',isUsed:t=>t==="left"||t==="right"||t==="start"||t==="end"}],Mi=[{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:'the "columnGroups" config property',isUsed:t=>Array.isArray(t)&&t.length>0}];function ki(t){return t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function ye(t){return`import { ${O(t)}Plugin } from '@toolbox-web/grid/plugins/${ki(t)}';`}function O(t){return t.charAt(0).toUpperCase()+t.slice(1)}function dt(t,e){return t.some(i=>i.name===e)}function Ii(t,e){const i=Oi,o=Mi,n=new Map;function r(l,a,c,h,f=!1){n.has(l)||n.set(l,{description:a,importHint:c,fields:[],isConfigProperty:f});const p=n.get(l);p.fields.includes(h)||p.fields.push(h)}for(const l of o){const a=t[l.property];(l.isUsed?l.isUsed(a):a!==void 0)&&!dt(e,l.pluginName)&&r(l.pluginName,l.description,ye(l.pluginName),l.property,!0)}const s=t.columns;if(s&&s.length>0)for(const l of s)for(const a of i){const c=l[a.property];if((a.isUsed?a.isUsed(c):c!==void 0)&&!dt(e,a.pluginName)){const f=l.field||"<unknown>";r(a.pluginName,a.description,ye(a.pluginName),f)}}if(n.size>0){const l=[];for(const[a,{description:c,importHint:h,fields:f,isConfigProperty:p}]of n)if(p)l.push(`Config uses ${c}, but the required plugin is not loaded.
31
+ ${e}`}function Si(t){let e=!1;for(const{name:i,styles:o}of t)ye.has(i)||(ye.set(i,o),e=!0);return e&&_e(),e}function Ri(){try{for(const t of Array.from(document.styleSheets))try{const i=Array.from(t.cssRules||[]).map(o=>o.cssText).join(`
32
+ `);if(i.includes(".tbw-grid-root")&&i.includes("tbw-grid"))return i}catch{continue}}catch(t){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",t)}return null}async function Ai(t){if(re)return;if(typeof t=="string"&&t.length>0){re=t,_e();return}await new Promise(i=>setTimeout(i,50));const e=Ri();e?(re=e,_e()):(typeof process>"u"||process.env?.NODE_ENV!=="test")&&console.warn("[tbw-grid] Could not find grid.css in document.styleSheets. Grid styling will not work.","Available stylesheets:",Array.from(document.styleSheets).map(i=>i.href||"(inline)"))}function Ti(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function xi(t){t.startY=null,t.startX=null,t.scrollTop=null,t.scrollLeft=null,t.lastY=null,t.lastX=null,t.lastTime=null}function dt(t){t.momentumRaf&&(cancelAnimationFrame(t.momentumRaf),t.momentumRaf=0)}function Hi(t,e,i){if(t.touches.length!==1)return;dt(e);const o=t.touches[0];e.startY=o.clientY,e.startX=o.clientX,e.lastY=o.clientY,e.lastX=o.clientX,e.lastTime=performance.now(),e.scrollTop=i.fauxScrollbar.scrollTop,e.scrollLeft=i.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function Li(t,e,i){if(t.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const o=t.touches[0],n=o.clientY,r=o.clientX,s=performance.now(),l=e.startY-n,a=e.startX-r;if(e.lastTime!==null&&e.lastY!==null&&e.lastX!==null){const d=s-e.lastTime;d>0&&(e.velocityY=(e.lastY-n)/d,e.velocityX=(e.lastX-r)/d)}e.lastY=n,e.lastX=r,e.lastTime=s;const{scrollTop:c,scrollHeight:h,clientHeight:f}=i.fauxScrollbar,p=h-f,g=l>0&&c<p||l<0&&c>0;let u=!1;if(i.scrollArea){const{scrollLeft:d,scrollWidth:w,clientWidth:C}=i.scrollArea,m=w-C;u=a>0&&d<m||a<0&&d>0}return g&&(i.fauxScrollbar.scrollTop=e.scrollTop+l),u&&i.scrollArea&&(i.scrollArea.scrollLeft=e.scrollLeft+a),g||u}function Pi(t,e){(Math.abs(t.velocityY)>.1||Math.abs(t.velocityX)>.1)&&zi(t,e),xi(t)}function zi(t,e){const n=()=>{t.velocityY*=.95,t.velocityX*=.95;const r=t.velocityY*16,s=t.velocityX*16;Math.abs(t.velocityY)>.01&&(e.fauxScrollbar.scrollTop+=r),Math.abs(t.velocityX)>.01&&e.scrollArea&&(e.scrollArea.scrollLeft+=s),Math.abs(t.velocityY)>.01||Math.abs(t.velocityX)>.01?t.momentumRaf=requestAnimationFrame(n):t.momentumRaf=0};t.momentumRaf=requestAnimationFrame(n)}function Di(t,e,i,o){t.addEventListener("touchstart",n=>Hi(n,e,i),{passive:!0,signal:o}),t.addEventListener("touchmove",n=>{Li(n,e,i)&&n.preventDefault()},{passive:!1,signal:o}),t.addEventListener("touchend",()=>Pi(e,i),{passive:!0,signal:o})}const Oi=[{property:"editable",pluginName:"editing",level:"column",description:'the "editable" column property',isUsed:t=>t===!0},{property:"editor",pluginName:"editing",level:"column",description:'the "editor" column property'},{property:"editorParams",pluginName:"editing",level:"column",description:'the "editorParams" column property'},{property:"group",pluginName:"groupingColumns",level:"column",description:'the "group" column property'},{property:"pinned",pluginName:"pinnedColumns",level:"column",description:'the "pinned" column property',isUsed:t=>t==="left"||t==="right"||t==="start"||t==="end"},{property:"sticky",pluginName:"pinnedColumns",level:"column",description:'the "sticky" column property (deprecated, use "pinned")',isUsed:t=>t==="left"||t==="right"||t==="start"||t==="end"}],Mi=[{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:'the "columnGroups" config property',isUsed:t=>Array.isArray(t)&&t.length>0}];function ki(t){return t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function Ee(t){return`import { ${O(t)}Plugin } from '@toolbox-web/grid/plugins/${ki(t)}';`}function O(t){return t.charAt(0).toUpperCase()+t.slice(1)}function ht(t,e){return t.some(i=>i.name===e)}function Ii(t,e){const i=Oi,o=Mi,n=new Map;function r(l,a,c,h,f=!1){n.has(l)||n.set(l,{description:a,importHint:c,fields:[],isConfigProperty:f});const p=n.get(l);p.fields.includes(h)||p.fields.push(h)}for(const l of o){const a=t[l.property];(l.isUsed?l.isUsed(a):a!==void 0)&&!ht(e,l.pluginName)&&r(l.pluginName,l.description,Ee(l.pluginName),l.property,!0)}const s=t.columns;if(s&&s.length>0)for(const l of s)for(const a of i){const c=l[a.property];if((a.isUsed?a.isUsed(c):c!==void 0)&&!ht(e,a.pluginName)){const f=l.field||"<unknown>";r(a.pluginName,a.description,Ee(a.pluginName),f)}}if(n.size>0){const l=[];for(const[a,{description:c,importHint:h,fields:f,isConfigProperty:p}]of n)if(p)l.push(`Config uses ${c}, but the required plugin is not loaded.
33
33
  → Add the plugin to your gridConfig.plugins array:
34
34
  ${h}
35
35
  plugins: [new ${O(a)}Plugin(), ...]`);else{const g=f.slice(0,3).join(", ")+(f.length>3?`, ... (${f.length} total)`:"");l.push(`Column(s) [${g}] use ${c}, but the required plugin is not loaded.
@@ -41,23 +41,23 @@ ${l.join(`
41
41
 
42
42
  `)}
43
43
 
44
- This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}function Ni(t){const e=[],i=[];for(const o of t){const r=o.constructor.manifest;if(r?.configRules)for(const s of r.configRules){const l=o.config;if(s.check(l)){const c=`${`[tbw-grid:${O(o.name)}Plugin]`} Configuration warning: ${s.message}`;s.severity==="error"?e.push(c):i.push(c)}}}if(i.length>0&&le())for(const o of i)console.warn(o);if(e.length>0)throw new Error(`[tbw-grid] Configuration error:
44
+ This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}function Ni(t){const e=[],i=[];for(const o of t){const r=o.constructor.manifest;if(r?.configRules)for(const s of r.configRules){const l=o.config;if(s.check(l)){const c=`${`[tbw-grid:${O(o.name)}Plugin]`} Configuration warning: ${s.message}`;s.severity==="error"?e.push(c):i.push(c)}}}if(i.length>0&&ce())for(const o of i)console.warn(o);if(e.length>0)throw new Error(`[tbw-grid] Configuration error:
45
45
 
46
46
  ${e.join(`
47
47
 
48
- `)}`)}function qi(t,e){const i=t.name,n=t.constructor.dependencies??[];for(const r of n){const s=r.name,l=r.required??!0,a=r.reason;if(!e.some(h=>h.name===s)){const h=a??`${O(i)}Plugin requires ${O(s)}Plugin`,f=ye(s);if(l)throw new Error(`[tbw-grid] Plugin dependency error:
48
+ `)}`)}function qi(t,e){const i=t.name,n=t.constructor.dependencies??[];for(const r of n){const s=r.name,l=r.required??!0,a=r.reason;if(!e.some(h=>h.name===s)){const h=a??`${O(i)}Plugin requires ${O(s)}Plugin`,f=Ee(s);if(l)throw new Error(`[tbw-grid] Plugin dependency error:
49
49
 
50
50
  ${h}.
51
51
 
52
52
  → Add the plugin to your gridConfig.plugins array BEFORE ${O(i)}Plugin:
53
53
  ${f}
54
- plugins: [new ${O(s)}Plugin(), new ${O(i)}Plugin()]`);console.info(`[tbw-grid] ${O(i)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}function $i(t){if(!le())return;const e=new Set(t.map(o=>o.name)),i=new Set;for(const o of t){const r=o.constructor.manifest;if(r?.incompatibleWith){for(const s of r.incompatibleWith)if(e.has(s.name)){const l=[o.name,s.name].sort().join("↔");if(i.has(l))continue;i.add(l),console.warn(`[tbw-grid] Plugin incompatibility warning:
54
+ plugins: [new ${O(s)}Plugin(), new ${O(i)}Plugin()]`);console.info(`[tbw-grid] ${O(i)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}function $i(t){if(!ce())return;const e=new Set(t.map(o=>o.name)),i=new Set;for(const o of t){const r=o.constructor.manifest;if(r?.incompatibleWith){for(const s of r.incompatibleWith)if(e.has(s.name)){const l=[o.name,s.name].sort().join("↔");if(i.has(l))continue;i.add(l),console.warn(`[tbw-grid] Plugin incompatibility warning:
55
55
 
56
56
  ${O(o.name)}Plugin and ${O(s.name)}Plugin are both loaded, but they are currently incompatible.
57
57
 
58
58
  → ${s.reason}
59
59
 
60
- Consider removing one of these plugins to avoid unexpected behavior.`)}}}}function ht(t,e){return!t||typeof t!="object"?t:"__rowCacheKey"in t?t.__rowCacheKey:"rowId"in t&&t.rowId!=null?`id:${t.rowId}`:e?`id:${e(t)}`:t}function Wi(t,e,i){const o=ht(e,i);if(typeof o=="string")return t.byKey.get(o);if(o&&typeof o=="object")return t.byRef.get(o)}function Fi(t,e,i,o){const n=ht(e,o);typeof n=="string"?t.byKey.set(n,i):n&&typeof n=="object"&&t.byRef.set(n,i)}function Ui(t,e,i,o,n){const r=new Array(t.length);let s=0;for(let l=0;l<t.length;l++){const a=t[l];let c=n?.(a,l),h=c!==void 0;c===void 0&&(c=Wi(e,a,o.rowId),h=c!==void 0),c===void 0&&(c=i,h=!1),r[l]={offset:s,height:c,measured:h},s+=c}return r}function _e(t,e,i){if(e<0||e>=t.length)return;const o=t[e],n=i-o.height;if(n!==0){o.height=i,o.measured=!0;for(let r=e+1;r<t.length;r++)t[r].offset+=n}}function Vi(t){if(t.length===0)return 0;const e=t[t.length-1];return e.offset+e.height}function ut(t,e){if(t.length===0)return-1;if(e<=0)return 0;let i=0,o=t.length-1;for(;i<=o;){const n=Math.floor((i+o)/2),r=t[n],s=r.offset+r.height;if(e<r.offset)o=n-1;else if(e>=s)i=n+1;else return n}return Math.max(0,Math.min(i,t.length-1))}function Gi(t,e){let i=0,o=0;for(const n of t)n.measured&&(i+=n.height,o++);return o>0?i/o:e}function Bi(t){let e=0;for(const i of t)i.measured&&e++;return e}function Xi(t,e){const{positionCache:i,heightCache:o,rows:n,start:r,end:s,getPluginHeight:l,getRowId:a}=t;let c=!1;e.forEach(p=>{const g=p.dataset.rowIndex;if(!g)return;const u=parseInt(g,10);if(u<r||u>=s||u>=n.length)return;const d=n[u],w=l?.(d,u);if(w!==void 0){const b=i[u];(!b.measured||Math.abs(b.height-w)>1)&&(_e(i,u,w),c=!0);return}const v=p.offsetHeight;if(v>0){const b=i[u];(!b.measured||Math.abs(b.height-v)>1)&&(_e(i,u,v),Fi(o,d,v,a),c=!0)}});const h=c?Bi(i):0,f=c?Gi(i,t.defaultHeight):0;return{hasChanges:c,measuredCount:h,averageHeight:f}}function Yi(t,e,i,o){let n=0,r=0;for(let s=0;s<t.length;s++){const l=t[s];l.measured&&o?.(e[s],s)===void 0&&(r+=l.height,n++)}return{measuredCount:n,averageHeight:n>0?r/n:i}}class Y{constructor(e){this.grid=e}plugins=[];getPlugins(){return this.plugins}pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;eventListeners=new Map;queryHandlers=new Map;static deprecationWarned=new WeakSet;attachAll(e){for(const i of e)this.attach(i)}attach(e){if(qi(e,this.plugins),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[i,o]of Object.entries(e.cellRenderers))this.cellRenderers.set(i,o);if(e.headerRenderers)for(const[i,o]of Object.entries(e.headerRenderers))this.headerRenderers.set(i,o);if(e.cellEditors)for(const[i,o]of Object.entries(e.cellEditors))this.cellEditors.set(i,o);this.registerQueryHandlers(e),this.warnDeprecatedHooks(e),e.attach(this.grid);for(const i of this.plugins)i!==e&&i.onPluginAttached&&i.onPluginAttached(e.name,e)}registerQueryHandlers(e){const o=e.constructor.manifest;if(o?.queries)for(const n of o.queries){let r=this.queryHandlers.get(n.type);r||(r=new Set,this.queryHandlers.set(n.type,r)),r.add(e)}}warnDeprecatedHooks(e){const i=e.constructor;if(Y.deprecationWarned.has(i)||!le())return;const o=typeof e.getExtraHeight=="function"||typeof e.getExtraHeightBefore=="function",n=typeof e.getRowHeight=="function";o&&!n&&(Y.deprecationWarned.add(i),console.warn(`[tbw-grid] Deprecation warning: "${e.name}" uses getExtraHeight() / getExtraHeightBefore() which are deprecated and will be removed in v3.0.
60
+ Consider removing one of these plugins to avoid unexpected behavior.`)}}}}function ut(t,e){return!t||typeof t!="object"?t:"__rowCacheKey"in t?t.__rowCacheKey:"rowId"in t&&t.rowId!=null?`id:${t.rowId}`:e?`id:${e(t)}`:t}function Wi(t,e,i){const o=ut(e,i);if(typeof o=="string")return t.byKey.get(o);if(o&&typeof o=="object")return t.byRef.get(o)}function Fi(t,e,i,o){const n=ut(e,o);typeof n=="string"?t.byKey.set(n,i):n&&typeof n=="object"&&t.byRef.set(n,i)}function Ui(t,e,i,o,n){const r=new Array(t.length);let s=0;for(let l=0;l<t.length;l++){const a=t[l];let c=n?.(a,l),h=c!==void 0;c===void 0&&(c=Wi(e,a,o.rowId),h=c!==void 0),c===void 0&&(c=i,h=!1),r[l]={offset:s,height:c,measured:h},s+=c}return r}function Se(t,e,i){if(e<0||e>=t.length)return;const o=t[e],n=i-o.height;if(n!==0){o.height=i,o.measured=!0;for(let r=e+1;r<t.length;r++)t[r].offset+=n}}function Vi(t){if(t.length===0)return 0;const e=t[t.length-1];return e.offset+e.height}function ft(t,e){if(t.length===0)return-1;if(e<=0)return 0;let i=0,o=t.length-1;for(;i<=o;){const n=Math.floor((i+o)/2),r=t[n],s=r.offset+r.height;if(e<r.offset)o=n-1;else if(e>=s)i=n+1;else return n}return Math.max(0,Math.min(i,t.length-1))}function Gi(t,e){let i=0,o=0;for(const n of t)n.measured&&(i+=n.height,o++);return o>0?i/o:e}function Bi(t){let e=0;for(const i of t)i.measured&&e++;return e}function Xi(t,e){const{positionCache:i,heightCache:o,rows:n,start:r,end:s,getPluginHeight:l,getRowId:a}=t;let c=!1;e.forEach(p=>{const g=p.dataset.rowIndex;if(!g)return;const u=parseInt(g,10);if(u<r||u>=s||u>=n.length)return;const d=n[u],w=l?.(d,u);if(w!==void 0){const m=i[u];(!m.measured||Math.abs(m.height-w)>1)&&(Se(i,u,w),c=!0);return}const C=p.offsetHeight;if(C>0){const m=i[u];(!m.measured||Math.abs(m.height-C)>1)&&(Se(i,u,C),Fi(o,d,C,a),c=!0)}});const h=c?Bi(i):0,f=c?Gi(i,t.defaultHeight):0;return{hasChanges:c,measuredCount:h,averageHeight:f}}function Yi(t,e,i,o){let n=0,r=0;for(let s=0;s<t.length;s++){const l=t[s];l.measured&&o?.(e[s],s)===void 0&&(r+=l.height,n++)}return{measuredCount:n,averageHeight:n>0?r/n:i}}class Y{constructor(e){this.grid=e}plugins=[];getPlugins(){return this.plugins}pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;eventListeners=new Map;queryHandlers=new Map;static deprecationWarned=new WeakSet;attachAll(e){for(const i of e)this.attach(i)}attach(e){if(qi(e,this.plugins),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[i,o]of Object.entries(e.cellRenderers))this.cellRenderers.set(i,o);if(e.headerRenderers)for(const[i,o]of Object.entries(e.headerRenderers))this.headerRenderers.set(i,o);if(e.cellEditors)for(const[i,o]of Object.entries(e.cellEditors))this.cellEditors.set(i,o);this.registerQueryHandlers(e),this.warnDeprecatedHooks(e),e.attach(this.grid);for(const i of this.plugins)i!==e&&i.onPluginAttached&&i.onPluginAttached(e.name,e)}registerQueryHandlers(e){const o=e.constructor.manifest;if(o?.queries)for(const n of o.queries){let r=this.queryHandlers.get(n.type);r||(r=new Set,this.queryHandlers.set(n.type,r)),r.add(e)}}warnDeprecatedHooks(e){const i=e.constructor;if(Y.deprecationWarned.has(i)||!ce())return;const o=typeof e.getExtraHeight=="function"||typeof e.getExtraHeightBefore=="function",n=typeof e.getRowHeight=="function";o&&!n&&(Y.deprecationWarned.add(i),console.warn(`[tbw-grid] Deprecation warning: "${e.name}" uses getExtraHeight() / getExtraHeightBefore() which are deprecated and will be removed in v3.0.
61
61
  → Migrate to getRowHeight(row, index) for better variable row height support.
62
62
  → See: https://toolbox-web.dev/docs/grid/plugins/migration#row-height-hooks`))}unregisterQueryHandlers(e){for(const[i,o]of this.queryHandlers)o.delete(e),o.size===0&&this.queryHandlers.delete(i)}detachAll(){for(const e of this.plugins)for(const i of this.plugins)i!==e&&i.onPluginDetached&&i.onPluginDetached(e.name);for(let e=this.plugins.length-1;e>=0;e--){const i=this.plugins[e];this.unsubscribeAll(i),this.unregisterQueryHandlers(i),i.detach()}this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear(),this.eventListeners.clear(),this.queryHandlers.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(i=>i.name===e)}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getRegisteredPluginNames(){return this.plugins.map(e=>e.name)}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getPluginStyles(){return this.plugins.filter(e=>e.styles).map(e=>({name:e.name,styles:e.styles}))}processRows(e){let i=[...e];for(const o of this.plugins)o.processRows&&(i=o.processRows(i));return i}processColumns(e){let i=[...e];for(const o of this.plugins)o.processColumns&&(i=o.processColumns(i));return i}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}afterCellRender(e){for(const i of this.plugins)i.afterCellRender?.(e)}hasAfterCellRenderHook(){return this.plugins.some(e=>typeof e.afterCellRender=="function")}afterRowRender(e){for(const i of this.plugins)i.afterRowRender?.(e)}hasAfterRowRenderHook(){return this.plugins.some(e=>typeof e.afterRowRender=="function")}onScrollRender(){for(const e of this.plugins)e.onScrollRender?.()}getExtraHeight(){let e=0;for(const i of this.plugins)typeof i.getExtraHeight=="function"&&(e+=i.getExtraHeight());return e}hasExtraHeight(){for(const e of this.plugins)if(typeof e.getExtraHeight=="function"&&e.getExtraHeight()>0)return!0;return!1}getExtraHeightBefore(e){let i=0;for(const o of this.plugins)typeof o.getExtraHeightBefore=="function"&&(i+=o.getExtraHeightBefore(e));return i}getRowHeight(e,i){for(const o of this.plugins)if(typeof o.getRowHeight=="function"){const n=o.getRowHeight(e,i);if(n!==void 0)return n}}hasRowHeightPlugin(){for(const e of this.plugins)if(typeof e.getRowHeight=="function")return!0;return!1}adjustVirtualStart(e,i,o){let n=e;for(const r of this.plugins)if(typeof r.adjustVirtualStart=="function"){const s=r.adjustVirtualStart(e,i,o);s<n&&(n=s)}return n}renderRow(e,i,o){for(const n of this.plugins)if(n.renderRow?.(e,i,o))return!0;return!1}queryPlugins(e){const i=[],o=this.queryHandlers.get(e.type);if(o&&o.size>0){for(const n of o){const r=n.handleQuery?.(e)??n.onPluginQuery?.(e);r!==void 0&&i.push(r)}return i}for(const n of this.plugins){const r=n.handleQuery?.(e)??n.onPluginQuery?.(e);r!==void 0&&i.push(r)}return i}subscribe(e,i,o){let n=this.eventListeners.get(i);n||(n=new Map,this.eventListeners.set(i,n)),n.set(e,o)}unsubscribe(e,i){const o=this.eventListeners.get(i);o&&(o.delete(e),o.size===0&&this.eventListeners.delete(i))}unsubscribeAll(e){for(const[i,o]of this.eventListeners)o.delete(e),o.size===0&&this.eventListeners.delete(i)}emitPluginEvent(e,i){const o=this.eventListeners.get(e);if(o)for(const n of o.values())try{n(i)}catch(r){console.error(`[tbw-grid] Error in plugin event handler for "${e}":`,r)}}onKeyDown(e){for(const i of this.plugins)if(i.onKeyDown?.(e))return!0;return!1}onCellClick(e){for(const i of this.plugins)if(i.onCellClick?.(e))return!0;return!1}onRowClick(e){for(const i of this.plugins)if(i.onRowClick?.(e))return!0;return!1}onHeaderClick(e){for(const i of this.plugins)if(i.onHeaderClick?.(e))return!0;return!1}onScroll(e){for(const i of this.plugins)i.onScroll?.(e)}onCellMouseDown(e){for(const i of this.plugins)if(i.onCellMouseDown?.(e))return!0;return!1}onCellMouseMove(e){for(const i of this.plugins)if(i.onCellMouseMove?.(e))return!0;return!1}onCellMouseUp(e){for(const i of this.plugins)if(i.onCellMouseUp?.(e))return!0;return!1}getHorizontalScrollOffsets(e,i){let o=0,n=0,r=!1;for(const s of this.plugins){const l=s.getHorizontalScrollOffsets?.(e,i);l&&(o+=l.left,n+=l.right,l.skipScroll&&(r=!0))}return{left:o,right:n,skipScroll:r}}getToolPanels(){const e=[];for(const i of this.plugins){const o=i.getToolPanel?.();o&&e.push({plugin:i,panel:o})}return e.sort((i,o)=>(i.panel.order??0)-(o.panel.order??0))}getHeaderContents(){const e=[];for(const i of this.plugins){const o=i.getHeaderContent?.();o&&e.push({plugin:i,content:o})}return e.sort((i,o)=>(i.content.order??0)-(o.content.order??0))}}const ji=`/**
63
63
  * tbw-grid Light DOM Styles
@@ -87,5 +87,5 @@ ${O(o.name)}Plugin and ${O(s.name)}Plugin are both loaded, but they are currentl
87
87
  @layer tbw-base{.tbw-loading-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:1000;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-spinner{--tbw-spinner-size: 48px;--tbw-spinner-border-width: 3px;--tbw-spinner-color: var(--tbw-color-accent);--tbw-spinner-track-color: var(--tbw-color-border);width:var(--tbw-spinner-size);height:var(--tbw-spinner-size);border:var(--tbw-spinner-border-width) solid var(--tbw-spinner-track-color);border-top-color:var(--tbw-spinner-color);border-radius:50%;animation:tbw-spin .8s linear infinite}.tbw-spinner--large{--tbw-spinner-size: min(48px, calc(100% - 16px) )}.tbw-spinner--small{--tbw-spinner-size: calc(var(--tbw-row-height, 28px) * .6);--tbw-spinner-border-width: 2px}.data-grid-row.tbw-row-loading{position:relative;pointer-events:none}.tbw-row-loading-overlay{position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out;pointer-events:none;display:flex;align-items:center}.tbw-row-loading-spinner{--_spinner-size: calc(var(--tbw-row-height, 28px) * .6);margin-left:var(--tbw-spacing-md);width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite}.cell.tbw-cell-loading{position:relative;pointer-events:none}.cell.tbw-cell-loading:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out}.cell.tbw-cell-loading:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .5);content:"";position:absolute;left:var(--tbw-spacing-sm);top:0;bottom:0;margin:auto 0;width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite;z-index:27}}
88
88
  @layer tbw-base{tbw-grid .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid[data-animation-mode=off]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=off] .data-grid-row[data-animating]{animation:none}tbw-grid .data-grid-row[data-animating=change]{animation:tbw-row-change var(--tbw-row-change-duration) ease-out}tbw-grid .data-grid-row[data-animating=insert]{animation:tbw-row-insert var(--tbw-row-insert-duration) ease-out;will-change:max-height,opacity}tbw-grid .data-grid-row[data-animating=remove]{animation:tbw-row-remove var(--tbw-row-remove-duration) ease-out forwards;will-change:max-height,opacity,transform;pointer-events:none}}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-row-change{0%{background-color:transparent}20%{background-color:var(--tbw-row-change-color)}to{background-color:transparent}}@keyframes tbw-row-insert{0%{opacity:0;max-height:0;overflow:hidden}to{opacity:1;max-height:var(--tbw-row-height, 28px);overflow:hidden}}@keyframes tbw-row-remove{0%{opacity:1;transform:translateY(0);max-height:var(--tbw-row-height, 28px)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-spin{to{transform:rotate(360deg)}}@keyframes tbw-fade-in{0%{opacity:0}to{opacity:1}}
89
89
  @layer tbw-base{@media(forced-colors:active){tbw-grid{--tbw-color-border: CanvasText;--tbw-color-border-strong: CanvasText;--tbw-color-border-cell: CanvasText;--tbw-color-border-header: CanvasText;--tbw-color-fg: CanvasText;--tbw-color-bg: Canvas;--tbw-color-panel-bg: Canvas;--tbw-color-header-bg: Canvas;--tbw-color-header-fg: CanvasText;--tbw-color-accent: Highlight;--tbw-color-accent-fg: HighlightText;--tbw-color-selection: Highlight;--tbw-color-row-hover: Highlight;--tbw-focus-outline: 2px solid Highlight;--tbw-range-border-color: Highlight}tbw-grid .cell:focus,tbw-grid .cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}tbw-grid .data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}@media(prefers-reduced-motion:reduce){tbw-grid[data-animation-mode=reduced-motion]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=reduced-motion] .data-grid-row[data-animating]{animation:none}}}
90
- `;class I extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static#l=0;static adapters=[];static registerAdapter(e){this.adapters.push(e)}static getAdapters(){return this.adapters}static clearAdapters(){this.adapters=[]}static get observedAttributes(){return["rows","columns","grid-config","fit-mode","loading"]}get#n(){return this}#u=!1;#d;#h;#a=[];get#o(){return this.#i?.effective??{}}#f=!1;#w=!1;#v={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#s;#C=0;#r=null;#g=!1;#x=!1;#m=0;#z;#I=Ti();#b;#y;#p;#R;#ee={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#t;#_;#N=!1;#D;#B;#O;#i;#e=fi();#c;#q;#$;#M=!1;#E=new Set;#H=new Map;#W;#S=new Map;_rows=[];#X=[];get _columns(){return this.#o.columns??[]}set _columns(e){this.#o.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null,positionCache:null,heightCache:{byKey:new Map,byRef:new WeakMap},averageHeight:28,measuredCount:0,variableHeights:!1,cachedViewportHeight:0,cachedFauxHeight:0,cachedScrollAreaHeight:0,scrollAreaEl:null};_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#i?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#i&&(this.#i.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#i?.originalColumnNodes}set __originalColumnNodes(e){this.#i&&(this.#i.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const i=this.#a;this.#a=e,i!==e&&this.#V("rows")}get sourceRows(){return this.#a}get columns(){return[...this._columns]}set columns(e){const i=this.#i?.getColumns();this.#i?.setColumns(e),i!==e&&this.#V("columns")}get gridConfig(){return this.#o}set gridConfig(e){const i=this.#i?.getGridConfig();this.#i?.setGridConfig(e),i!==e&&(this.#i.clearLightDomCache(),this.#V("gridConfig"))}get fitMode(){return this.#o.fitMode??"stretch"}set fitMode(e){const i=this.#i?.getFitMode();this.#i?.setFitMode(e),i!==e&&this.#V("fitMode")}get loading(){return this.#M}set loading(e){const i=this.#M;this.#M=e,e?this.setAttribute("loading",""):this.removeAttribute("loading"),i!==e&&this.#ue()}setRowLoading(e,i){const o=this.#E.has(e);i?this.#E.add(e):this.#E.delete(e),o!==i&&this.#K(e,i)}setCellLoading(e,i,o){let n=this.#H.get(e);const r=n?.has(i)??!1;o?(n||(n=new Set,this.#H.set(e,n)),n.add(i)):(n?.delete(i),n?.size===0&&this.#H.delete(e)),r!==o&&this.#fe(e,i,o)}isRowLoading(e){return this.#E.has(e)}isCellLoading(e,i){return this.#H.get(e)?.has(i)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#E)this.#K(e,!1);this.#E.clear();for(const[e,i]of this.#H)for(const o of i)this.#fe(e,o,!1);this.#H.clear()}get effectiveConfig(){return this.#o}get disconnectSignal(){return this.#b||(this.#b=new AbortController),this.#b.signal}constructor(){super(),this.#me(),this.#d=new Promise(e=>this.#h=e),this.#s=new oi({mergeConfig:()=>{this.#i.parseLightDomColumns(this),this.#i.merge(),this.#ie(),Ii(this.#o,this.#t?.getPlugins()??[]),Ni(this.#t?.getPlugins()??[]),$i(this.#t?.getPlugins()??[]),this.#De(),this.#X=[...this._columns]},processColumns:()=>this.#He(),processRows:()=>this.#Pe(),renderHeader:()=>oe(this),updateTemplate:()=>G(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#t?.afterRender(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const i=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${i}px`}),this.#o.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,He(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,U(this)),this._virtualization.enabled&&!this.#U&&this.#ye(),this.#x&&(this.#x=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#Ce()})})),this.#M&&this.#ue()},isConnected:()=>this.isConnected&&this.#f}),this.#s.setInitialReadyResolver(()=>this.#h?.()),this.#c=Ci(this.#e,{getShadow:()=>this.#n,getShellConfig:()=>this.#o?.shell,getAccordionIcons:()=>({expand:this.#o?.icons?.expand??k.expand,collapse:this.#o?.icons?.collapse??k.collapse}),emit:(e,i)=>this.#L(e,i),refreshShellHeader:()=>this.refreshShellHeader()}),this.#i=new Ot({getRows:()=>this.#a,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#s.requestPhase(A.FULL,"configChange")},emit:(e,i)=>this.#L(e,i),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#P(),renderHeader:()=>oe(this),updateTemplate:()=>G(this),refreshVirtualWindow:()=>this.#s.requestPhase(A.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#ze(e),getShellLightDomTitle:()=>this.#e.lightDomTitle,getShellToolPanels:()=>this.#e.toolPanels,getShellHeaderContents:()=>this.#e.headerContents,getShellToolbarContents:()=>this.#e.toolbarContents,getShellLightDomHeaderContent:()=>this.#e.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#e.hasToolButtonsContainer})}async#me(){await Ai(ji)}getPlugin(e){return this.#t?.getPlugin(e)}getPluginByName(e){return this.#t?.getPluginByName(e)}requestRender(){this.#s.requestPhase(A.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#s.requestPhase(A.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#s.requestPhase(A.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){G(this)}requestAfterRender(){this.#s.requestPhase(A.STYLE,"plugin:requestAfterRender")}#te(){this.#t=new Y(this);const e=this.#o?.plugins,i=Array.isArray(e)?e:[];this.#t.attachAll(i)}#F(){const e=this.#t?.getPluginStyles()??[];Si(e)}#ie(){const e=this.#o?.plugins,i=Array.isArray(e)?e:[];if(this.#_===i)return;if(this.#_&&this.#_.length===i.length&&this.#_.every((n,r)=>n===i[r])){this.#_=i;return}this.#t&&this.#t.detachAll();for(const n of this.#e.toolPanels.keys()){const r=this.#e.lightDomToolPanelIds.has(n),s=this.#e.apiToolPanelIds.has(n);if(!r&&!s){const l=this.#e.panelCleanups.get(n);l&&(l(),this.#e.panelCleanups.delete(n)),this.#e.toolPanels.delete(n)}}for(const n of this.#e.headerContents.keys()){const r=this.#e.headerContentCleanups.get(n);r&&(r(),this.#e.headerContentCleanups.delete(n)),this.#e.headerContents.delete(n)}this.#te(),this.#F(),this.#_=i,this.#se(),this.#oe();const o=this.#g;if(this.#g=this.#t?.getAll().some(n=>n.onScroll)??!1,!o&&this.#g){const r=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");this.#Y(r)}}#ve(){this.#t?.detachAll()}#oe(){if(!this.#t)return;const e=this.#t.getToolPanels();for(const{panel:o}of e)this.#e.toolPanels.has(o.id)||this.#e.toolPanels.set(o.id,o);const i=this.#t.getHeaderContents();for(const{content:o}of i)this.#e.headerContents.has(o.id)||this.#e.headerContents.set(o.id,o)}#ne(){const e=I.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const i=this.__frameworkAdapter;return o=>{if(i?.createToolPanelRenderer){const n=i.createToolPanelRenderer(o);if(n)return n}for(const n of e)if(n.createToolPanelRenderer){const r=n.createToolPanelRenderer(o);if(r)return r}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",I.version),this.id||(this.id=`tbw-grid-${++I.#l}`),this._rows=Array.isArray(this.#a)?[...this.#a]:[],this.#b&&(this.#b.abort(),this.#N=!1),this.#b=new AbortController,this.#R&&(Ke(this.#R),this.#R=void 0),this.#k(),this.#i.parseLightDomColumns(this),this.#i.merge(),this.#te();const e=this.#o?.plugins;this.#_=Array.isArray(e)?e:[],this.#oe(),this.#u||(this.#J(),this.#F(),this.#u=!0),this.#re(),this.#R=jt(()=>{this.#Ie()},{timeout:100})}disconnectedCallback(){this.#R&&(Ke(this.#R),this.#R=void 0),this.#m&&(clearTimeout(this.#m),this.#m=0),this.#ve(),vi(this.#e),this.#c.setInitialized(!1),this.#q?.(),this.#q=void 0,this.#$?.(),this.#$=void 0,ct(this.#I),this.#b&&(this.#b.abort(),this.#b=void 0),this.#D?.abort(),this.#D=void 0,this.#N=!1,this._resizeController&&this._resizeController.dispose(),this.#y&&(this.#y.disconnect(),this.#y=void 0),this.#p&&(this.#p.disconnect(),this.#p=void 0,this.#U=!1),Q(this),this.#A.clear(),this.#_=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#f=!1}attributeChangedCallback(e,i,o){if(e==="loading"){const n=o!==null&&o!=="false";this.loading!==n&&(this.loading=n);return}if(!(i===o||!o||o==="null"||o==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const n=JSON.parse(o);e==="rows"?this.rows=n:e==="columns"?this.columns=n:e==="grid-config"&&(this.gridConfig=n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,o)}else e==="fit-mode"&&(this.fitMode=o)}#re(){const i=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=i?.querySelector(".header-row"),this._virtualization.totalHeightEl=i?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=i?.querySelector(".rows-viewport"),this._bodyEl=i?.querySelector(".rows"),this.__rowsBodyEl=i?.querySelector(".rows-body"),this.#c.isInitialized){we(this.#n,this.#e),pe(this.#n,this.#o?.shell,this.#e);const n=this.#o?.shell?.toolPanel?.defaultOpen;n&&this.#e.toolPanels.has(n)&&(this.openToolPanel(),this.#e.expandedSections.add(n))}if(this.setAttribute("data-upgraded",""),this.#f=!0,this._resizeController=Qe(this),this.#P(),this.#Y(i),this.#N)return;this.#N=!0;const o=this.disconnectSignal;Bt(this,this,this.#n,o),this.#se(),queueMicrotask(()=>this.#_e()),this.#s.requestPhase(A.FULL,"afterConnect")}#se(){const e=this.#o.rowHeight,i=this.#t.hasRowHeightPlugin();typeof e=="function"||i?this._virtualization.variableHeights||(this._virtualization.variableHeights=!0,this._virtualization.rowHeight=typeof e=="number"&&e>0?e:this._virtualization.rowHeight||28,this.#Z(),typeof e!="function"&&(this.#x=!0)):!i&&typeof e!="function"&&this._virtualization.variableHeights?(this._virtualization.variableHeights=!1,this._virtualization.positionCache=null):typeof e=="number"&&e>0?(this._virtualization.rowHeight=e,this._virtualization.variableHeights=!1):requestAnimationFrame(()=>this.#le())}#le(){if(this.#t.hasExtraHeight())return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const i=e.querySelectorAll(".cell");let o=0;i.forEach(s=>{const l=s.offsetHeight;l>o&&(o=l)});const n=e.getBoundingClientRect(),r=Math.max(n.height,o);r>0&&Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r,this.#s.requestPhase(A.VIRTUALIZATION,"measureRowHeight"))}#Ce(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const i=e.querySelectorAll(".cell");let o=0;i.forEach(s=>{const l=s.offsetHeight;l>o&&(o=l)});const n=e.getBoundingClientRect(),r=Math.max(n.height,o);if(r>0&&(Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r),this.#Z(),this._virtualization.totalHeightEl)){const l=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#Y(e){this.#D?.abort(),this.#D=new AbortController;const i=this.#D.signal,o=e?.querySelector(".faux-vscroll"),n=e?.querySelector(".rows");if(this._virtualization.container=o??this,this.#g=this.#t?.getAll().some(r=>r.onScroll)??!1,o&&n){o.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#g)return;const a=o.scrollTop,c=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)n.style.transform=`translateY(${-a}px)`;else{const h=this._virtualization.positionCache;let f,p;if(this._virtualization.variableHeights&&h&&h.length>0){f=ut(h,a),f===-1&&(f=0);const u=f-f%2;p=h[u]?.offset??u*c}else f=Math.floor(a/c),p=(f-f%2)*c;const g=-(a-p);n.style.transform=`translateY(${g}px)`}this.#r=a,this.#C||(this.#C=requestAnimationFrame(()=>{this.#C=0,this.#r!==null&&(this.#Oe(this.#r),this.#r=null)}))},{passive:!0,signal:i});const r=this.#n.querySelector(".tbw-scroll-area");this.#B=r,this._virtualization.scrollAreaEl=r,r&&this.#g&&r.addEventListener("scroll",()=>{const a=this.#ee;a.scrollTop=o.scrollTop,a.scrollLeft=r.scrollLeft,a.scrollHeight=o.scrollHeight,a.scrollWidth=r.scrollWidth,a.clientHeight=o.clientHeight,a.clientWidth=r.clientWidth,this.#t?.onScroll(a)},{passive:!0,signal:i});const s=this.#n.querySelector(".tbw-grid-content"),l=this.#B;s&&(s.addEventListener("wheel",a=>{const c=a.shiftKey||Math.abs(a.deltaX)>Math.abs(a.deltaY);if(c&&l){const h=a.shiftKey?a.deltaY:a.deltaX,{scrollLeft:f,scrollWidth:p,clientWidth:g}=l;(h>0&&f<p-g||h<0&&f>0)&&(a.preventDefault(),l.scrollLeft+=h)}else if(!c){const{scrollTop:h,scrollHeight:f,clientHeight:p}=o;(a.deltaY>0&&h<f-p||a.deltaY<0&&h>0)&&(a.preventDefault(),o.scrollTop+=a.deltaY)}},{passive:!1,signal:i}),Di(s,this.#I,{fauxScrollbar:o,scrollArea:l},i))}this._bodyEl&&Gt(this,this._bodyEl,i),this.#y?.disconnect(),this._virtualization.viewportEl&&(this.#y=new ResizeObserver(()=>{this.#Ne(),this.#s.requestPhase(A.VIRTUALIZATION,"resize-observer")}),this.#y.observe(this._virtualization.viewportEl)),this.#n.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:i}),this.#n.addEventListener("focusout",r=>{const s=r.relatedTarget;(!s||!this.#n.contains(s))&&delete this.dataset.hasFocus},{signal:i})}#U=!1;#ye(){if(this.#U)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#U=!0,this.#p?.disconnect(),this.#p=new ResizeObserver(()=>{this.#le()}),this.#p.observe(e))}addEventListener(e,i,o){super.addEventListener(e,i,o)}removeEventListener(e,i,o){super.removeEventListener(e,i,o)}#L(e,i){this.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,composed:!0}))}#_e(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((i,o)=>{const n=o===this._focusRow;i.setAttribute("aria-selected",String(n)),i.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(n&&s===this._focusCol))})})}#V(e){this.#v[e]=!0,!this.#w&&(this.#w=!0,queueMicrotask(()=>this.#Ee()))}#Ee(){if(!this.#w||!this.#f){this.#w=!1;return}const e=this.#v;if(this.#w=!1,this.#v={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig){this.#Te(),e.rows&&this.#ae();return}e.columns&&this.#Re(),e.rows&&this.#ae(),e.fitMode&&this.#Ae()}#ae(){this._rows=Array.isArray(this.#a)?[...this.#a]:[],this.#G(),this.#s.requestPhase(A.ROWS,"applyRowsUpdate")}#G(){this.#S.clear();const e=this.#o.getRowId;this._rows.forEach((i,o)=>{const n=this.#ce(i,e);n!==void 0&&this.#S.set(n,{row:i,index:o})})}#ce(e,i){if(i)return i(e);const o=e;if("id"in o&&o.id!=null)return String(o.id);if("_id"in o&&o._id!=null)return String(o._id)}#Se(e,i){const o=this.#ce(e,i);if(o===void 0)throw new Error('[tbw-grid] Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.');return o}#Re(){Q(this),this.#i.merge(),this.#P()}#Ae(){this.#i.merge(),this.#o.fitMode==="fixed"?(this.__didInitialAutoSize=!1,He(this)):(this._columns.forEach(i=>{!i.__userResized&&i.__autoSized&&delete i.width}),G(this))}#Te(){ot(this,this.#e),nt(this,this.#e);const e=!!this.#n.querySelector(".has-shell"),i=!!this.#n.querySelector(".tbw-tool-panel"),o=this.#n.querySelectorAll(".tbw-accordion-section").length;this.#i.parseLightDomColumns(this),this.#i.merge(),this.#ie(),rt(this,this.#e,this.#ne()),this.#i.markSourcesChanged(),this.#i.merge();const n=it(this.#o?.shell),r=(this.#o?.shell?.toolPanels?.length??0)>0,s=this.#o?.shell?.toolPanels?.length??0;if(e!==n||!i&&r||i&&s!==o){be(this.#e),this.#J(),this.#F(),this.#re(),this.#G();return}e&&this.#xe(),this.#G(),this.#s.requestPhase(A.COLUMNS,"applyGridConfigUpdate")}#xe(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;const i=this.#o.shell?.header?.title??this.#e.lightDomTitle;let o=e.querySelector(".tbw-shell-title");i?(o||(o=document.createElement("h2"),o.className="tbw-shell-title",o.setAttribute("part","shell-title"),e.insertBefore(o,e.firstChild)),o.textContent=i):o&&o.remove()}#He(){if(this.#t){const e=this.#X.length>0?this.#X:this._columns,i=e.filter(r=>!r.hidden),o=e.filter(r=>r.hidden),n=this.#t.processColumns([...i]);if(n!==i){const r=new Set(n.map(l=>l.field));!i.some(l=>r.has(l.field))&&n.length>0?this._columns=[...n,...o]:this._columns=this.#Le(e,n,o)}else this._columns=[...e]}}#Le(e,i,o){if(o.length===0)return i;const n=new Map;for(const a of i)n.set(a.field,a);const r=new Set(e.map(a=>a.field)),s=[];for(const a of i)r.has(a.field)||s.push(a);const l=[];for(const a of e){const c=n.get(a.field);c?l.push(c):a.hidden&&l.push(a)}return l.push(...s),l}#Pe(){Q(this);const e=Array.isArray(this.#a)?[...this.#a]:[],i=this.#t?.processRows(e)??e;this._rows=i,this.#G(),this._virtualization.variableHeights&&this.#Z()}#ze(e){const i={...Re,...e.animation},o=i.mode??"reduced-motion";let n=1;o===!1||o==="off"?n=0:(o===!0||o==="on")&&(n=1),this.style.setProperty("--tbw-animation-duration",`${i.duration}ms`),this.style.setProperty("--tbw-animation-easing",i.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode=typeof o=="boolean"?o?"on":"off":o}#j(e,i,o=this.__rowRenderEpoch){if(this.#z||(this.#z=(n,r,s)=>this.#t?.renderRow(n,r,s)??!1),qt(this,e,i,o,this.#z),this.#E.size>0)for(const n of this.#E)this.#K(n,!0)}#de=V();#he(e,i){pt(this.#de,this.__rowsBodyEl,this._bodyEl,e,i)}#De(){bt(this.#de,this.__rowsBodyEl,this.#o,this.#e)}#ue(){const e=this.querySelector(".tbw-grid-root");e&&(this.#M?(this.#W||(this.#W=Zt(this.#o?.loadingRenderer)),Jt(e,this.#W)):ei(this.#W))}#K(e,i){const o=this.#S.get(e);if(!o)return;const n=this.findRenderedRowElement?.(o.index);n&&ti(n,i)}#fe(e,i,o){const n=this.#S.get(e);if(!n)return;const r=this.findRenderedRowElement?.(n.index);if(!r)return;const s=this._visibleColumns.findIndex(a=>a.field===i);if(s<0)return;const l=r.children[s];l&&ii(l,o)}#P(){if(this.isConnected&&!(!this._headerRowEl||!this._bodyEl)){if(this.#i.parseLightDomColumns(this),this.#O){const e=this.#O;this.#O=void 0,this.#i.merge();const i=this.#t?.getAll()??[];this.#i.applyState(e,i)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#s.requestPhase(A.FULL,"setup")}}#Oe(e){let i=0,o=0,n=0,r=0,s=0;if(this.#g){const a=this._virtualization.container,c=this.#B;i=c?.scrollLeft??0,o=a?.scrollHeight??0,n=c?.scrollWidth??0,r=a?.clientHeight??0,s=c?.clientWidth??0}if(this.refreshVirtualWindow(!1)&&this.#t?.onScrollRender(),this._virtualization.variableHeights&&(this.#m&&clearTimeout(this.#m),this.#m=window.setTimeout(()=>{this.#m=0,this.#we(this._virtualization.start,this._virtualization.end)},100)),this.#g){const a=this.#ee;a.scrollTop=e,a.scrollLeft=i,a.scrollHeight=o,a.scrollWidth=n,a.clientHeight=r,a.clientWidth=s,this.#t?.onScroll(a)}}findHeaderRow(){return this.#n.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(i=>{const o=i.querySelector(".cell[data-row]");return o&&Number(o.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,i,o,n){const r=this._rows[i],s=this._columns[o];if(!r||!s)return!1;const l=s.field,a=r[l],c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:i,colIndex:o,column:s,field:l,value:a,row:r,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(c),c.defaultPrevented)return!0;const h={row:r,rowIndex:i,colIndex:o,column:s,field:l,value:a,cellEl:n,originalEvent:e},f=this.#t?.onCellClick(h)??!1;return this.#L("cell-click",h),f}_dispatchRowClick(e,i,o,n){if(!o)return!1;const r={rowIndex:i,row:o,rowEl:n,originalEvent:e},s=this.#t?.onRowClick(r)??!1;return this.#L("row-click",r),s}_dispatchHeaderClick(e,i,o){if(!i)return!1;const n={colIndex:this._columns.indexOf(i),field:i.field,column:i,headerEl:o,originalEvent:e};return this.#t?.onHeaderClick(n)??!1}_dispatchKeyDown(e){return this.#t?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,i){return this.#t?.getHorizontalScrollOffsets(e,i)??{left:0,right:0}}queryPlugins(e){return this.#t?.queryPlugins(e)??[]}query(e,i){return this.#t?.queryPlugins({type:e,context:i})??[]}_dispatchCellMouseDown(e){return this.#t?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#t?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#t?.onCellMouseUp(e)}_afterCellRender(e){this.#t?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#t?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#t?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#t?.hasAfterRowRenderHook()??!1}async ready(){return this.#d}async forceLayout(){return this.#s.requestPhase(A.FULL,"forceLayout"),this.#s.whenReady()}async getConfig(){return Object.freeze({...this.#o||{}})}getRowId(e){return this.#Se(e,this.#o.getRowId)}getRow(e){return this.#S.get(e)?.row}_getRowEntry(e){return this.#S.get(e)}updateRow(e,i,o="api"){const n=this.#S.get(e);if(!n)throw new Error(`[tbw-grid] Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:r,index:s}=n,l=[];for(const[a,c]of Object.entries(i)){const h=r[a];h!==c&&(l.push({field:a,oldValue:h,newValue:c}),r[a]=c)}for(const{field:a,oldValue:c,newValue:h}of l)this.#L("cell-change",{row:r,rowId:e,rowIndex:s,field:a,oldValue:c,newValue:h,changes:i,source:o});l.length>0&&this.#s.requestPhase(A.ROWS,"updateRow")}updateRows(e,i="api"){let o=!1;for(const{id:n,changes:r}of e){const s=this.#S.get(n);if(!s)throw new Error(`[tbw-grid] Row with ID "${n}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:l,index:a}=s;for(const[c,h]of Object.entries(r)){const f=l[c];f!==h&&(o=!0,l[c]=h,this.#L("cell-change",{row:l,rowId:n,rowIndex:a,field:c,oldValue:f,newValue:h,changes:r,source:i}))}}o&&this.#s.requestPhase(A.ROWS,"updateRows")}animateRow(e,i){ge(this,e,i)}animateRows(e,i){ci(this,e,i)}animateRowById(e,i){return di(this,e,i)}setColumnVisible(e,i){const o=this.#i.setColumnVisible(e,i);return o&&this.requestStateChange(),o}toggleColumnVisibility(e){const i=this.#i.toggleColumnVisibility(e);return i&&this.requestStateChange(),i}isColumnVisible(e){return this.#i.isColumnVisible(e)}showAllColumns(){this.#i.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#i.getAllColumns()}setColumnOrder(e){this.#i.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#i.getColumnOrder()}getColumnState(){const e=this.#t?.getAll()??[];return this.#i.collectState(e)}set columnState(e){e&&(this.#O=e,this.#i.initialColumnState=e,this.#u&&this.#Me(e))}get columnState(){return this.getColumnState()}#Me(e){const i=this.#t?.getAll()??[];this.#i.applyState(e,i),this.#P()}requestStateChange(){const e=this.#t?.getAll()??[];this.#i.requestStateChange(e)}resetColumnState(){this.#O=void 0,this.__originalOrder=[];const e=this.#t?.getAll()??[];this.#i.resetState(e),this.#i.merge(),this.#P()}get isToolPanelOpen(){return this.#c.isPanelOpen}get defaultRowHeight(){return this._virtualization.rowHeight}get expandedToolPanelSections(){return this.#c.expandedSections}openToolPanel(){this.#c.openToolPanel()}closeToolPanel(){this.#c.closeToolPanel()}toggleToolPanel(){this.#c.toggleToolPanel()}toggleToolPanelSection(e){this.#c.toggleToolPanelSection(e)}getToolPanels(){return this.#c.getToolPanels()}registerToolPanel(e){this.#e.apiToolPanelIds.add(e.id),this.#c.registerToolPanel(e)}unregisterToolPanel(e){this.#e.apiToolPanelIds.delete(e),this.#c.unregisterToolPanel(e)}getHeaderContents(){return this.#c.getHeaderContents()}registerHeaderContent(e){this.#c.registerHeaderContent(e)}unregisterHeaderContent(e){this.#c.unregisterHeaderContent(e)}getToolbarContents(){return this.#c.getToolbarContents()}registerToolbarContent(e){this.#c.registerToolbarContent(e)}unregisterToolbarContent(e){this.#c.unregisterToolbarContent(e)}#Q=!1;refreshShellHeader(){this.#Q||(this.#Q=!0,queueMicrotask(()=>{this.#Q=!1,this.isConnected&&(this.#k(),this.#i.markSourcesChanged(),this.#i.merge(),be(this.#e),this.#J(),this.#F(),this.#ke())}))}#ke(){const i=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=i?.querySelector(".header-row"),this._virtualization.totalHeightEl=i?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=i?.querySelector(".rows-viewport"),this._bodyEl=i?.querySelector(".rows"),this.__rowsBodyEl=i?.querySelector(".rows-body"),this.#c.isInitialized){we(this.#n,this.#e),pe(this.#n,this.#o?.shell,this.#e);const o=this.#o?.shell?.toolPanel?.defaultOpen;o&&this.#e.toolPanels.has(o)&&(this.openToolPanel(),this.#e.expandedSections.add(o))}this._resizeController=Qe(this),this.#Y(i),this.#s.requestPhase(A.COLUMNS,"shellRefresh")}#A=new Map;registerStyles(e,i){let o=this.#A.get(e);o||(o=new CSSStyleSheet,this.#A.set(e,o)),o.replaceSync(i),this.#ge()}unregisterStyles(e){this.#A.delete(e)&&this.#ge()}getRegisteredStyles(){return Array.from(this.#A.keys())}#ge(){const e=Array.from(this.#A.values()),i=document.adoptedStyleSheets.filter(o=>!Array.from(this.#A.values()).includes(o));document.adoptedStyleSheets=[...i,...e]}#k(){ot(this,this.#e),nt(this,this.#e),rt(this,this.#e,this.#ne())}#pe(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;be(this.#e);const i=gi(this.#o.shell,this.#e,this.#o.icons?.toolPanel),o=document.createElement("div");o.innerHTML=i;const n=o.firstElementChild;n&&(e.replaceWith(n),this.#be(),pe(this.#n,this.#o?.shell,this.#e))}#Ie(){const e=()=>{const o=this.#e.lightDomTitle,n=this.#e.hasToolButtonsContainer;this.#k();const r=this.#e.lightDomTitle,s=this.#e.hasToolButtonsContainer;(r&&!o||s&&!n)&&(this.#i.markSourcesChanged(),this.#i.merge(),this.#pe())},i=()=>{this.__lightDomColumnsCache=void 0,this.#P()};this.#i.registerLightDomHandler("tbw-grid-header",e),this.#i.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#i.registerLightDomHandler("tbw-grid-tool-panel",e),this.#i.registerLightDomHandler("tbw-grid-column",i),this.#i.registerLightDomHandler("tbw-grid-detail",i),this.#i.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,Q(this),this.#i.parseLightDomColumns(this);const e=this.#e.lightDomTitle,i=this.#e.hasToolButtonsContainer;this.#k();const o=this.#e.lightDomTitle,n=this.#e.hasToolButtonsContainer;(o&&!e||n&&!i)&&(this.#i.markSourcesChanged(),this.#i.merge(),this.#pe()),this.#s.requestPhase(A.COLUMNS,"refreshColumns")}#Ne(){const e=this._virtualization.container,i=this._virtualization.viewportEl??e;i&&(this._virtualization.cachedViewportHeight=i.clientHeight),e&&(this._virtualization.cachedFauxHeight=e.clientHeight);const o=this._virtualization.scrollAreaEl;o&&(this._virtualization.cachedScrollAreaHeight=o.clientHeight)}#T(e,i=!1){const o=this._virtualization;let n,r,s;if(i){const p=o.container??this,g=o.viewportEl??p,u=o.scrollAreaEl;n=p.clientHeight,r=g.clientHeight,s=u?u.clientHeight:n,o.cachedFauxHeight=n,o.cachedViewportHeight=r,o.cachedScrollAreaHeight=s}else n=o.cachedFauxHeight,r=o.cachedViewportHeight,s=o.cachedScrollAreaHeight||n;const l=s-r,a=Math.max(0,n-s);let c,h=0;return o.variableHeights&&o.positionCache?c=Vi(o.positionCache):(c=e*o.rowHeight,h=this.#t?.getExtraHeight()??0),c+l+h+a}#Z(){if(!this._virtualization.variableHeights)return;const e=this._rows,i=this._virtualization.rowHeight||28,o=this.#o.rowHeight,n=this.#o.getRowId,r=n?l=>n(l):void 0;this._virtualization.positionCache=Ui(e,this._virtualization.heightCache,i,{rowId:r},(l,a)=>{const c=this.#t?.getRowHeight?.(l,a);if(c!==void 0)return c;if(o){const h=o(l,a);if(h!==void 0&&h>0)return h}});const s=Yi(this._virtualization.positionCache,e,i,(l,a)=>this.#t?.getRowHeight?.(l,a));this._virtualization.measuredCount=s.measuredCount,s.measuredCount>0&&(this._virtualization.averageHeight=s.averageHeight)}invalidateRowHeight(e,i){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||e<0||e>=this._rows.length)return;const o=this._virtualization.positionCache,n=this._rows[e];let r=i;r===void 0&&(r=this.#t?.getRowHeight?.(n,e)),r===void 0&&(r=this._virtualization.rowHeight);const s=o[e];if(!(!s||Math.abs(s.height-r)<1)&&(_e(o,e,r),this._virtualization.totalHeightEl)){const l=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#we(e,i){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||!this._bodyEl)return;const o=this._bodyEl.querySelectorAll(".data-grid-row"),n=this.#o.getRowId,r=Xi({positionCache:this._virtualization.positionCache,heightCache:this._virtualization.heightCache,rows:this._rows,defaultHeight:this._virtualization.rowHeight,start:e,end:i,getPluginHeight:(s,l)=>this.#t?.getRowHeight?.(s,l),getRowId:n?s=>n(s):void 0},o);if(r.hasChanges&&(this._virtualization.measuredCount=r.measuredCount,this._virtualization.averageHeight=r.averageHeight,this._virtualization.totalHeightEl)){const s=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${s}px`}}refreshVirtualWindow(e=!1,i=!1){if(!this._bodyEl)return!1;const o=this._rows.length;if(!this._virtualization.enabled)return this.#j(0,o),i||this.#t?.afterRender(),!0;if(this._rows.length<=this._virtualization.bypassThreshold)return this._virtualization.start=0,this._virtualization.end=o,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#j(0,o,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),e&&this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#T(o,!0)}px`),this.#he(o,this._visibleColumns.length),i||this.#t?.afterRender(),!0;const n=this._virtualization.container??this,r=this._virtualization.viewportEl??n,s=e?this._virtualization.cachedViewportHeight=r.clientHeight:this._virtualization.cachedViewportHeight||(this._virtualization.cachedViewportHeight=r.clientHeight),l=this._virtualization.rowHeight,a=n.scrollTop;let c;const h=this._virtualization.positionCache;if(this._virtualization.variableHeights&&h&&h.length>0)c=ut(h,a),c===-1&&(c=0);else{c=Math.floor(a/l);let b=0;const E=10;for(;b<E;){const T=this.#t?.getExtraHeightBefore?.(c)??0,S=Math.floor((a-T)/l);if(S>=c||S<0)break;c=S,b++}}c=c-c%2,c<0&&(c=0);const f=this.#t?.adjustVirtualStart(c,a,l);f!==void 0&&f<c&&(c=f,c=c-c%2,c<0&&(c=0));let p;if(this._virtualization.variableHeights&&h&&h.length>0){const b=s+l*3;let E=0;for(p=c;p<o&&E<b;)E+=h[p].height,p++;const T=Math.ceil(s/l)+3;p-c<T&&(p=Math.min(c+T,o))}else{const b=Math.ceil(s/l)+3;p=c+b}p>o&&(p=o);const g=this._virtualization.start,u=this._virtualization.end;if(!e&&c===g&&p===u)return!1;this._virtualization.start=c,this._virtualization.end=p;const d=e?this._virtualization.cachedFauxHeight=n.clientHeight:this._virtualization.cachedFauxHeight||(this._virtualization.cachedFauxHeight=n.clientHeight);if(e){const b=this._virtualization.scrollAreaEl;b&&(this._virtualization.cachedScrollAreaHeight=b.clientHeight)}if(d===0&&s>0)return this.#s.requestPhase(A.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&this._virtualization.totalHeightEl){const b=this.#T(o);this._virtualization.totalHeightEl.style.height=`${b}px`}let w;if(this._virtualization.variableHeights&&h&&h[c])w=h[c].offset;else{const b=this.#t?.getExtraHeightBefore?.(c)??0;w=c*l+b}const v=-(a-w);return this._bodyEl.style.transform=`translateY(${v}px)`,this.#j(c,p,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),e&&this._virtualization.variableHeights&&this.#we(c,p),this.#he(o,this._visibleColumns.length),e&&!i&&(this.#t?.afterRender(),queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const b=this.#T(o);this._virtualization.cachedFauxHeight===0&&this._virtualization.cachedViewportHeight>0||(this._virtualization.totalHeightEl.style.height=`${b}px`)})),!0}#J(){this.#k(),this.#i.markSourcesChanged(),this.#i.merge();const e=this.#o?.shell;_i(this.#n,e,{isPanelOpen:this.#e.isPanelOpen,expandedSections:this.#e.expandedSections},this.#o?.icons)&&(this.#be(),this.#c.setInitialized(!0))}#be(){pi(this.#n,this.#o?.shell,this.#e,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#q?.(),this.#q=bi(this.#n,this.#o?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)}),this.#$?.(),this.#$=wi(this,this.#o?.shell,this.#e,()=>this.closeToolPanel())}}customElements.get(I.tagName)||customElements.define(I.tagName,I),globalThis.DataGridElement=I;const Ki={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class Qi{static dependencies;static manifest;version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#l;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#l?.abort(),this.#l=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#l?.abort(),this.#l=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,i){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:i,bubbles:!0}))}emitCancelable(e,i){const o=new CustomEvent(e,{detail:i,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(e,i){this.grid?._pluginManager?.subscribe(this,e,i)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,i){this.grid?._pluginManager?.emitPluginEvent(e,i)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#l?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...k,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(e===!1||e==="off")return!1;if(e===!0||e==="on")return!0;const i=this.gridElement;return i?getComputedStyle(i).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationDuration(){const e=this.gridElement;if(e){const i=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(i,10);if(!isNaN(o))return o}return 200}resolveIcon(e,i){return i!==void 0?i:this.gridIcons[e]}setIcon(e,i){typeof i=="string"?e.innerHTML=i:i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const x={ROOT:"tbw-grid-root",HEADER:"header",HEADER_ROW:"header-row",HEADER_CELL:"header-cell",ROWS_VIEWPORT:"rows-viewport",ROWS_SPACER:"rows-spacer",ROWS_CONTAINER:"rows",DATA_ROW:"data-row",GROUP_ROW:"group-row",DATA_CELL:"data-cell",SELECTED:"selected",FOCUSED:"focused",EDITING:"editing",EXPANDED:"expanded",COLLAPSED:"collapsed",DRAGGING:"dragging",RESIZING:"resizing",SORTABLE:"sortable",SORTED_ASC:"sorted-asc",SORTED_DESC:"sorted-desc",HIDDEN:"hidden",STICKY_LEFT:"sticky-left",STICKY_RIGHT:"sticky-right",PINNED_TOP:"pinned-top",PINNED_BOTTOM:"pinned-bottom",TREE_TOGGLE:"tree-toggle",TREE_INDENT:"tree-indent",GROUP_TOGGLE:"group-toggle",GROUP_LABEL:"group-label",GROUP_COUNT:"group-count",RANGE_SELECTION:"range-selection",SELECTION_OVERLAY:"selection-overlay"},j={ROW_INDEX:"data-row-index",COL_INDEX:"data-col-index",FIELD:"data-field",GROUP_KEY:"data-group-key",TREE_LEVEL:"data-tree-level",STICKY:"data-sticky"},Zi={ROOT:`.${x.ROOT}`,HEADER:`.${x.HEADER}`,HEADER_ROW:`.${x.HEADER_ROW}`,HEADER_CELL:`.${x.HEADER_CELL}`,ROWS_VIEWPORT:`.${x.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${x.ROWS_CONTAINER}`,DATA_ROW:`.${x.DATA_ROW}`,DATA_CELL:`.${x.DATA_CELL}`,GROUP_ROW:`.${x.GROUP_ROW}`,ROW_BY_INDEX:t=>`.${x.DATA_ROW}[${j.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${x.DATA_CELL}[${j.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${x.DATA_ROW}[${j.ROW_INDEX}="${t}"] .${x.DATA_CELL}[${j.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${x.DATA_ROW}.${x.SELECTED}`,EDITING_CELL:`.${x.DATA_CELL}.${x.EDITING}`},Ji={COLOR_BG:"--tbw-color-bg",COLOR_FG:"--tbw-color-fg",COLOR_FG_MUTED:"--tbw-color-fg-muted",COLOR_BORDER:"--tbw-color-border",COLOR_ACCENT:"--tbw-color-accent",COLOR_HEADER_BG:"--tbw-color-header-bg",COLOR_HEADER_FG:"--tbw-color-header-fg",COLOR_SELECTION:"--tbw-color-selection",COLOR_ROW_HOVER:"--tbw-color-row-hover",COLOR_ROW_ALT:"--tbw-color-row-alt",ROW_HEIGHT:"--tbw-row-height",HEADER_HEIGHT:"--tbw-header-height",CELL_PADDING:"--tbw-cell-padding",FONT_FAMILY:"--tbw-font-family",FONT_SIZE:"--tbw-font-size",BORDER_RADIUS:"--tbw-border-radius",FOCUS_OUTLINE:"--tbw-focus-outline"};function eo(t){const e=document.createElement("tbw-grid");return t&&(e.gridConfig=t),e}function to(t,e=document){return e.querySelector(t)}const io={CELL_CHANGE:"cell-change",CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",EDIT_OPEN:"edit-open",EDIT_CLOSE:"edit-close",CHANGED_ROWS_RESET:"changed-rows-reset",MOUNT_EXTERNAL_VIEW:"mount-external-view",MOUNT_EXTERNAL_EDITOR:"mount-external-editor",SORT_CHANGE:"sort-change",COLUMN_RESIZE:"column-resize",ACTIVATE_CELL:"activate-cell",CELL_ACTIVATE:"cell-activate",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change"},oo={SELECTION_CHANGE:"selection-change",TREE_EXPAND:"tree-expand",FILTER_CHANGE:"filter-change",SORT_MODEL_CHANGE:"sort-model-change",EXPORT_START:"export-start",EXPORT_COMPLETE:"export-complete",CLIPBOARD_COPY:"clipboard-copy",CLIPBOARD_PASTE:"clipboard-paste",CONTEXT_MENU_OPEN:"context-menu-open",CONTEXT_MENU_CLOSE:"context-menu-close",HISTORY_CHANGE:"history-change",SERVER_LOADING:"server-loading",SERVER_ERROR:"server-error",COLUMN_VISIBILITY_CHANGE:"column-visibility-change",COLUMN_REORDER:"column-reorder",DETAIL_EXPAND:"detail-expand",GROUP_EXPAND:"group-expand"},Ee={sum:(t,e)=>t.reduce((i,o)=>i+(Number(o[e])||0),0),avg:(t,e)=>{const i=t.reduce((o,n)=>o+(Number(n[e])||0),0);return t.length?i/t.length:0},count:t=>t.length,min:(t,e)=>t.length?Math.min(...t.map(i=>Number(i[e])||1/0)):0,max:(t,e)=>t.length?Math.max(...t.map(i=>Number(i[e])||-1/0)):0,first:(t,e)=>t[0]?.[e],last:(t,e)=>t[t.length-1]?.[e]},K=new Map,M={register(t,e){K.set(t,e)},unregister(t){K.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:K.get(t)??Ee[t]},run(t,e,i,o){const n=this.get(t);return n?n(e,i,o):void 0},has(t){return K.has(t)||t in Ee},list(){return[...Object.keys(Ee),...K.keys()]}},ft={sum:t=>t.reduce((e,i)=>e+i,0),avg:t=>t.length?t.reduce((e,i)=>e+i,0)/t.length:0,count:t=>t.length,min:t=>t.length?Math.min(...t):0,max:t=>t.length?Math.max(...t):0,first:t=>t[0]??0,last:t=>t[t.length-1]??0};function gt(t){return ft[t]??ft.sum}function no(t,e){return gt(t)(e)}const ro=M.register.bind(M),so=M.unregister.bind(M),lo=M.get.bind(M),ao=M.run.bind(M),co=M.list.bind(M);_.BaseGridPlugin=Qi,_.DEFAULT_ANIMATION_CONFIG=Re,_.DEFAULT_GRID_ICONS=k,_.DGEvents=io,_.DataGridElement=I,_.FitModeEnum=W,_.GridCSSVars=Ji,_.GridClasses=x,_.GridDataAttrs=j,_.GridElement=I,_.GridSelectors=Zi,_.PLUGIN_QUERIES=Ki,_.PluginEvents=oo,_.PluginManager=Y,_.RenderPhase=A,_.aggregatorRegistry=M,_.builtInSort=Ge,_.createGrid=eo,_.defaultComparator=Ve,_.getAggregator=lo,_.getValueAggregator=gt,_.listAggregators=co,_.queryGrid=to,_.registerAggregator=ro,_.runAggregator=ao,_.runValueAggregator=no,_.unregisterAggregator=so,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})}));
90
+ `;class I extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static#l=0;static adapters=[];static registerAdapter(e){this.adapters.push(e)}static getAdapters(){return this.adapters}static clearAdapters(){this.adapters=[]}static get observedAttributes(){return["rows","columns","grid-config","fit-mode","loading"]}get#n(){return this}#u=!1;#d;#h;#a=[];get#o(){return this.#i?.effective??{}}#f=!1;#w=!1;#v={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#s;#C=0;#r=null;#g=!1;#x=!1;#m=0;#z;#I=Ti();#b;#y;#p;#R;#ee={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#t;#_;#N=!1;#D;#B;#O;#i;#e=fi();#c;#q;#$;#M=!1;#E=new Set;#H=new Map;#W;#S=new Map;_rows=[];#X=[];get _columns(){return this.#o.columns??[]}set _columns(e){this.#o.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null,positionCache:null,heightCache:{byKey:new Map,byRef:new WeakMap},averageHeight:28,measuredCount:0,variableHeights:!1,cachedViewportHeight:0,cachedFauxHeight:0,cachedScrollAreaHeight:0,scrollAreaEl:null};_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#i?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#i&&(this.#i.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#i?.originalColumnNodes}set __originalColumnNodes(e){this.#i&&(this.#i.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const i=this.#a;this.#a=e,i!==e&&this.#V("rows")}get sourceRows(){return this.#a}get columns(){return[...this._columns]}set columns(e){const i=this.#i?.getColumns();this.#i?.setColumns(e),i!==e&&this.#V("columns")}get gridConfig(){return this.#o}set gridConfig(e){const i=this.#i?.getGridConfig();this.#i?.setGridConfig(e),i!==e&&(this.#i.clearLightDomCache(),this.#V("gridConfig"))}get fitMode(){return this.#o.fitMode??"stretch"}set fitMode(e){const i=this.#i?.getFitMode();this.#i?.setFitMode(e),i!==e&&this.#V("fitMode")}get loading(){return this.#M}set loading(e){const i=this.#M;this.#M=e,e?this.setAttribute("loading",""):this.removeAttribute("loading"),i!==e&&this.#ue()}setRowLoading(e,i){const o=this.#E.has(e);i?this.#E.add(e):this.#E.delete(e),o!==i&&this.#K(e,i)}setCellLoading(e,i,o){let n=this.#H.get(e);const r=n?.has(i)??!1;o?(n||(n=new Set,this.#H.set(e,n)),n.add(i)):(n?.delete(i),n?.size===0&&this.#H.delete(e)),r!==o&&this.#fe(e,i,o)}isRowLoading(e){return this.#E.has(e)}isCellLoading(e,i){return this.#H.get(e)?.has(i)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#E)this.#K(e,!1);this.#E.clear();for(const[e,i]of this.#H)for(const o of i)this.#fe(e,o,!1);this.#H.clear()}get effectiveConfig(){return this.#o}get disconnectSignal(){return this.#b||(this.#b=new AbortController),this.#b.signal}constructor(){super(),this.#me(),this.#d=new Promise(e=>this.#h=e),this.#s=new oi({mergeConfig:()=>{this.#i.parseLightDomColumns(this),this.#i.merge(),this.#ie(),Ii(this.#o,this.#t?.getPlugins()??[]),Ni(this.#t?.getPlugins()??[]),$i(this.#t?.getPlugins()??[]),this.#De(),this.#X=[...this._columns]},processColumns:()=>this.#He(),processRows:()=>this.#Pe(),renderHeader:()=>oe(this),updateTemplate:()=>G(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#t?.afterRender(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const i=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${i}px`}),this.#o.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,Pe(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,U(this)),this._virtualization.enabled&&!this.#U&&this.#ye(),this.#x&&(this.#x=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#Ce()})})),this.#M&&this.#ue()},isConnected:()=>this.isConnected&&this.#f}),this.#s.setInitialReadyResolver(()=>this.#h?.()),this.#c=Ci(this.#e,{getShadow:()=>this.#n,getShellConfig:()=>this.#o?.shell,getAccordionIcons:()=>({expand:this.#o?.icons?.expand??k.expand,collapse:this.#o?.icons?.collapse??k.collapse}),emit:(e,i)=>this.#L(e,i),refreshShellHeader:()=>this.refreshShellHeader()}),this.#i=new Ot({getRows:()=>this.#a,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#s.requestPhase(A.FULL,"configChange")},emit:(e,i)=>this.#L(e,i),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#P(),renderHeader:()=>oe(this),updateTemplate:()=>G(this),refreshVirtualWindow:()=>this.#s.requestPhase(A.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#ze(e),getShellLightDomTitle:()=>this.#e.lightDomTitle,getShellToolPanels:()=>this.#e.toolPanels,getShellHeaderContents:()=>this.#e.headerContents,getShellToolbarContents:()=>this.#e.toolbarContents,getShellLightDomHeaderContent:()=>this.#e.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#e.hasToolButtonsContainer})}async#me(){await Ai(ji)}getPlugin(e){return this.#t?.getPlugin(e)}getPluginByName(e){return this.#t?.getPluginByName(e)}requestRender(){this.#s.requestPhase(A.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#s.requestPhase(A.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#s.requestPhase(A.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){G(this)}requestAfterRender(){this.#s.requestPhase(A.STYLE,"plugin:requestAfterRender")}#te(){this.#t=new Y(this);const e=this.#o?.plugins,i=Array.isArray(e)?e:[];this.#t.attachAll(i)}#F(){const e=this.#t?.getPluginStyles()??[];Si(e)}#ie(){const e=this.#o?.plugins,i=Array.isArray(e)?e:[];if(this.#_===i)return;if(this.#_&&this.#_.length===i.length&&this.#_.every((n,r)=>n===i[r])){this.#_=i;return}this.#t&&this.#t.detachAll();for(const n of this.#e.toolPanels.keys()){const r=this.#e.lightDomToolPanelIds.has(n),s=this.#e.apiToolPanelIds.has(n);if(!r&&!s){const l=this.#e.panelCleanups.get(n);l&&(l(),this.#e.panelCleanups.delete(n)),this.#e.toolPanels.delete(n)}}for(const n of this.#e.headerContents.keys()){const r=this.#e.headerContentCleanups.get(n);r&&(r(),this.#e.headerContentCleanups.delete(n)),this.#e.headerContents.delete(n)}this.#te(),this.#F(),this.#_=i,this.#se(),this.#oe();const o=this.#g;if(this.#g=this.#t?.getAll().some(n=>n.onScroll)??!1,!o&&this.#g){const r=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");this.#Y(r)}}#ve(){this.#t?.detachAll()}#oe(){if(!this.#t)return;const e=this.#t.getToolPanels();for(const{panel:o}of e)this.#e.toolPanels.has(o.id)||this.#e.toolPanels.set(o.id,o);const i=this.#t.getHeaderContents();for(const{content:o}of i)this.#e.headerContents.has(o.id)||this.#e.headerContents.set(o.id,o)}#ne(){const e=I.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const i=this.__frameworkAdapter;return o=>{if(i?.createToolPanelRenderer){const n=i.createToolPanelRenderer(o);if(n)return n}for(const n of e)if(n.createToolPanelRenderer){const r=n.createToolPanelRenderer(o);if(r)return r}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",I.version),this.id||(this.id=`tbw-grid-${++I.#l}`),this._rows=Array.isArray(this.#a)?[...this.#a]:[],this.#b&&(this.#b.abort(),this.#N=!1),this.#b=new AbortController,this.#R&&(Qe(this.#R),this.#R=void 0),this.#k(),this.#i.parseLightDomColumns(this),this.#i.merge(),this.#te();const e=this.#o?.plugins;this.#_=Array.isArray(e)?e:[],this.#oe(),this.#u||(this.#J(),this.#F(),this.#u=!0),this.#re(),this.#R=jt(()=>{this.#Ie()},{timeout:100})}disconnectedCallback(){this.#R&&(Qe(this.#R),this.#R=void 0),this.#m&&(clearTimeout(this.#m),this.#m=0),this.#ve(),vi(this.#e),this.#c.setInitialized(!1),this.#q?.(),this.#q=void 0,this.#$?.(),this.#$=void 0,dt(this.#I),this.#b&&(this.#b.abort(),this.#b=void 0),this.#D?.abort(),this.#D=void 0,this.#N=!1,this._resizeController&&this._resizeController.dispose(),this.#y&&(this.#y.disconnect(),this.#y=void 0),this.#p&&(this.#p.disconnect(),this.#p=void 0,this.#U=!1),Q(this),this.#A.clear(),this.#_=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#f=!1}attributeChangedCallback(e,i,o){if(e==="loading"){const n=o!==null&&o!=="false";this.loading!==n&&(this.loading=n);return}if(!(i===o||!o||o==="null"||o==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const n=JSON.parse(o);e==="rows"?this.rows=n:e==="columns"?this.columns=n:e==="grid-config"&&(this.gridConfig=n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,o)}else e==="fit-mode"&&(this.fitMode=o)}#re(){const i=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=i?.querySelector(".header-row"),this._virtualization.totalHeightEl=i?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=i?.querySelector(".rows-viewport"),this._bodyEl=i?.querySelector(".rows"),this.__rowsBodyEl=i?.querySelector(".rows-body"),this.#c.isInitialized){me(this.#n,this.#e),be(this.#n,this.#o?.shell,this.#e);const n=this.#o?.shell?.toolPanel?.defaultOpen;n&&this.#e.toolPanels.has(n)&&(this.openToolPanel(),this.#e.expandedSections.add(n))}if(this.setAttribute("data-upgraded",""),this.#f=!0,this._resizeController=Ze(this),this.#P(),this.#Y(i),this.#N)return;this.#N=!0;const o=this.disconnectSignal;Bt(this,this,this.#n,o),this.#se(),queueMicrotask(()=>this.#_e()),this.#s.requestPhase(A.FULL,"afterConnect")}#se(){const e=this.#o.rowHeight,i=this.#t.hasRowHeightPlugin();typeof e=="function"||i?this._virtualization.variableHeights||(this._virtualization.variableHeights=!0,this._virtualization.rowHeight=typeof e=="number"&&e>0?e:this._virtualization.rowHeight||28,this.#Z(),typeof e!="function"&&(this.#x=!0)):!i&&typeof e!="function"&&this._virtualization.variableHeights?(this._virtualization.variableHeights=!1,this._virtualization.positionCache=null):typeof e=="number"&&e>0?(this._virtualization.rowHeight=e,this._virtualization.variableHeights=!1):requestAnimationFrame(()=>this.#le())}#le(){if(this.#t.hasExtraHeight())return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const i=e.querySelectorAll(".cell");let o=0;i.forEach(s=>{const l=s.offsetHeight;l>o&&(o=l)});const n=e.getBoundingClientRect(),r=Math.max(n.height,o);r>0&&Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r,this.#s.requestPhase(A.VIRTUALIZATION,"measureRowHeight"))}#Ce(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const i=e.querySelectorAll(".cell");let o=0;i.forEach(s=>{const l=s.offsetHeight;l>o&&(o=l)});const n=e.getBoundingClientRect(),r=Math.max(n.height,o);if(r>0&&(Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r),this.#Z(),this._virtualization.totalHeightEl)){const l=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#Y(e){this.#D?.abort(),this.#D=new AbortController;const i=this.#D.signal,o=e?.querySelector(".faux-vscroll"),n=e?.querySelector(".rows");if(this._virtualization.container=o??this,this.#g=this.#t?.getAll().some(r=>r.onScroll)??!1,o&&n){o.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#g)return;const a=o.scrollTop,c=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)n.style.transform=`translateY(${-a}px)`;else{const h=this._virtualization.positionCache;let f,p;if(this._virtualization.variableHeights&&h&&h.length>0){f=ft(h,a),f===-1&&(f=0);const u=f-f%2;p=h[u]?.offset??u*c}else f=Math.floor(a/c),p=(f-f%2)*c;const g=-(a-p);n.style.transform=`translateY(${g}px)`}this.#r=a,this.#C||(this.#C=requestAnimationFrame(()=>{this.#C=0,this.#r!==null&&(this.#Oe(this.#r),this.#r=null)}))},{passive:!0,signal:i});const r=this.#n.querySelector(".tbw-scroll-area");this.#B=r,this._virtualization.scrollAreaEl=r,r&&this.#g&&r.addEventListener("scroll",()=>{const a=this.#ee;a.scrollTop=o.scrollTop,a.scrollLeft=r.scrollLeft,a.scrollHeight=o.scrollHeight,a.scrollWidth=r.scrollWidth,a.clientHeight=o.clientHeight,a.clientWidth=r.clientWidth,this.#t?.onScroll(a)},{passive:!0,signal:i});const s=this.#n.querySelector(".tbw-grid-content"),l=this.#B;s&&(s.addEventListener("wheel",a=>{const c=a.shiftKey||Math.abs(a.deltaX)>Math.abs(a.deltaY);if(c&&l){const h=a.shiftKey?a.deltaY:a.deltaX,{scrollLeft:f,scrollWidth:p,clientWidth:g}=l;(h>0&&f<p-g||h<0&&f>0)&&(a.preventDefault(),l.scrollLeft+=h)}else if(!c){const{scrollTop:h,scrollHeight:f,clientHeight:p}=o;(a.deltaY>0&&h<f-p||a.deltaY<0&&h>0)&&(a.preventDefault(),o.scrollTop+=a.deltaY)}},{passive:!1,signal:i}),Di(s,this.#I,{fauxScrollbar:o,scrollArea:l},i))}this._bodyEl&&Gt(this,this._bodyEl,i),this.#y?.disconnect(),this._virtualization.viewportEl&&(this.#y=new ResizeObserver(()=>{this.#Ne(),this.#s.requestPhase(A.VIRTUALIZATION,"resize-observer")}),this.#y.observe(this._virtualization.viewportEl)),this.#n.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:i}),this.#n.addEventListener("focusout",r=>{const s=r.relatedTarget;(!s||!this.#n.contains(s))&&delete this.dataset.hasFocus},{signal:i})}#U=!1;#ye(){if(this.#U)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#U=!0,this.#p?.disconnect(),this.#p=new ResizeObserver(()=>{this.#le()}),this.#p.observe(e))}addEventListener(e,i,o){super.addEventListener(e,i,o)}removeEventListener(e,i,o){super.removeEventListener(e,i,o)}#L(e,i){this.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,composed:!0}))}#_e(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((i,o)=>{const n=o===this._focusRow;i.setAttribute("aria-selected",String(n)),i.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(n&&s===this._focusCol))})})}#V(e){this.#v[e]=!0,!this.#w&&(this.#w=!0,queueMicrotask(()=>this.#Ee()))}#Ee(){if(!this.#w||!this.#f){this.#w=!1;return}const e=this.#v;if(this.#w=!1,this.#v={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig){this.#Te(),e.rows&&this.#ae();return}e.columns&&this.#Re(),e.rows&&this.#ae(),e.fitMode&&this.#Ae()}#ae(){this._rows=Array.isArray(this.#a)?[...this.#a]:[],this.#G(),this.#s.requestPhase(A.ROWS,"applyRowsUpdate")}#G(){this.#S.clear();const e=this.#o.getRowId;this._rows.forEach((i,o)=>{const n=this.#ce(i,e);n!==void 0&&this.#S.set(n,{row:i,index:o})})}#ce(e,i){if(i)return i(e);const o=e;if("id"in o&&o.id!=null)return String(o.id);if("_id"in o&&o._id!=null)return String(o._id)}#Se(e,i){const o=this.#ce(e,i);if(o===void 0)throw new Error('[tbw-grid] Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.');return o}#Re(){Q(this),this.#i.merge(),this.#P()}#Ae(){this.#i.merge(),this.#o.fitMode==="fixed"?(this.__didInitialAutoSize=!1,Pe(this)):(this._columns.forEach(i=>{!i.__userResized&&i.__autoSized&&delete i.width}),G(this))}#Te(){nt(this,this.#e),rt(this,this.#e);const e=!!this.#n.querySelector(".has-shell"),i=!!this.#n.querySelector(".tbw-tool-panel"),o=this.#n.querySelectorAll(".tbw-accordion-section").length;this.#i.parseLightDomColumns(this),this.#i.merge(),this.#ie(),st(this,this.#e,this.#ne()),this.#i.markSourcesChanged(),this.#i.merge();const n=ot(this.#o?.shell),r=(this.#o?.shell?.toolPanels?.length??0)>0,s=this.#o?.shell?.toolPanels?.length??0;if(e!==n||!i&&r||i&&s!==o){ve(this.#e),this.#J(),this.#F(),this.#re(),this.#G();return}e&&this.#xe(),this.#G(),this.#s.requestPhase(A.COLUMNS,"applyGridConfigUpdate")}#xe(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;const i=this.#o.shell?.header?.title??this.#e.lightDomTitle;let o=e.querySelector(".tbw-shell-title");i?(o||(o=document.createElement("h2"),o.className="tbw-shell-title",o.setAttribute("part","shell-title"),e.insertBefore(o,e.firstChild)),o.textContent=i):o&&o.remove()}#He(){if(this.__rowRenderEpoch++,this.#t){const e=this.#X.length>0?this.#X:this._columns,i=e.filter(r=>!r.hidden),o=e.filter(r=>r.hidden),n=this.#t.processColumns([...i]);if(n!==i){const r=new Set(n.map(l=>l.field));!i.some(l=>r.has(l.field))&&n.length>0?this._columns=[...n,...o]:this._columns=this.#Le(e,n,o)}else this._columns=[...e]}}#Le(e,i,o){if(o.length===0)return i;const n=new Map;for(const a of i)n.set(a.field,a);const r=new Set(e.map(a=>a.field)),s=[];for(const a of i)r.has(a.field)||s.push(a);const l=[];for(const a of e){const c=n.get(a.field);c?l.push(c):a.hidden&&l.push(a)}return l.push(...s),l}#Pe(){Q(this);const e=Array.isArray(this.#a)?[...this.#a]:[],i=this.#t?.processRows(e)??e;this._rows=i,this.#G(),this._virtualization.variableHeights&&this.#Z()}#ze(e){const i={...Te,...e.animation},o=i.mode??"reduced-motion";let n=1;o===!1||o==="off"?n=0:(o===!0||o==="on")&&(n=1),this.style.setProperty("--tbw-animation-duration",`${i.duration}ms`),this.style.setProperty("--tbw-animation-easing",i.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode=typeof o=="boolean"?o?"on":"off":o}#j(e,i,o=this.__rowRenderEpoch){if(this.#z||(this.#z=(n,r,s)=>this.#t?.renderRow(n,r,s)??!1),qt(this,e,i,o,this.#z),this.#E.size>0)for(const n of this.#E)this.#K(n,!0)}#de=V();#he(e,i){wt(this.#de,this.__rowsBodyEl,this._bodyEl,e,i)}#De(){mt(this.#de,this.__rowsBodyEl,this.#o,this.#e)}#ue(){const e=this.querySelector(".tbw-grid-root");e&&(this.#M?(this.#W||(this.#W=Zt(this.#o?.loadingRenderer)),Jt(e,this.#W)):ei(this.#W))}#K(e,i){const o=this.#S.get(e);if(!o)return;const n=this.findRenderedRowElement?.(o.index);n&&ti(n,i)}#fe(e,i,o){const n=this.#S.get(e);if(!n)return;const r=this.findRenderedRowElement?.(n.index);if(!r)return;const s=this._visibleColumns.findIndex(a=>a.field===i);if(s<0)return;const l=r.children[s];l&&ii(l,o)}#P(){if(this.isConnected&&!(!this._headerRowEl||!this._bodyEl)){if(this.#i.parseLightDomColumns(this),this.#O){const e=this.#O;this.#O=void 0,this.#i.merge();const i=this.#t?.getAll()??[];this.#i.applyState(e,i)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#s.requestPhase(A.FULL,"setup")}}#Oe(e){let i=0,o=0,n=0,r=0,s=0;if(this.#g){const a=this._virtualization.container,c=this.#B;i=c?.scrollLeft??0,o=a?.scrollHeight??0,n=c?.scrollWidth??0,r=a?.clientHeight??0,s=c?.clientWidth??0}if(this.refreshVirtualWindow(!1)&&this.#t?.onScrollRender(),this._virtualization.variableHeights&&(this.#m&&clearTimeout(this.#m),this.#m=window.setTimeout(()=>{this.#m=0,this.#we(this._virtualization.start,this._virtualization.end)},100)),this.#g){const a=this.#ee;a.scrollTop=e,a.scrollLeft=i,a.scrollHeight=o,a.scrollWidth=n,a.clientHeight=r,a.clientWidth=s,this.#t?.onScroll(a)}}findHeaderRow(){return this.#n.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(i=>{const o=i.querySelector(".cell[data-row]");return o&&Number(o.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,i,o,n){const r=this._rows[i],s=this._columns[o];if(!r||!s)return!1;const l=s.field,a=r[l],c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:i,colIndex:o,column:s,field:l,value:a,row:r,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(c),c.defaultPrevented)return!0;const h={row:r,rowIndex:i,colIndex:o,column:s,field:l,value:a,cellEl:n,originalEvent:e},f=this.#t?.onCellClick(h)??!1;return this.#L("cell-click",h),f}_dispatchRowClick(e,i,o,n){if(!o)return!1;const r={rowIndex:i,row:o,rowEl:n,originalEvent:e},s=this.#t?.onRowClick(r)??!1;return this.#L("row-click",r),s}_dispatchHeaderClick(e,i,o){if(!i)return!1;const n={colIndex:this._columns.indexOf(i),field:i.field,column:i,headerEl:o,originalEvent:e};return this.#t?.onHeaderClick(n)??!1}_dispatchKeyDown(e){return this.#t?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,i){return this.#t?.getHorizontalScrollOffsets(e,i)??{left:0,right:0}}queryPlugins(e){return this.#t?.queryPlugins(e)??[]}query(e,i){return this.#t?.queryPlugins({type:e,context:i})??[]}_dispatchCellMouseDown(e){return this.#t?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#t?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#t?.onCellMouseUp(e)}_afterCellRender(e){this.#t?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#t?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#t?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#t?.hasAfterRowRenderHook()??!1}async ready(){return this.#d}async forceLayout(){return this.#s.requestPhase(A.FULL,"forceLayout"),this.#s.whenReady()}async getConfig(){return Object.freeze({...this.#o||{}})}getRowId(e){return this.#Se(e,this.#o.getRowId)}getRow(e){return this.#S.get(e)?.row}_getRowEntry(e){return this.#S.get(e)}updateRow(e,i,o="api"){const n=this.#S.get(e);if(!n)throw new Error(`[tbw-grid] Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:r,index:s}=n,l=[];for(const[a,c]of Object.entries(i)){const h=r[a];h!==c&&(l.push({field:a,oldValue:h,newValue:c}),r[a]=c)}for(const{field:a,oldValue:c,newValue:h}of l)this.#L("cell-change",{row:r,rowId:e,rowIndex:s,field:a,oldValue:c,newValue:h,changes:i,source:o});l.length>0&&this.#s.requestPhase(A.ROWS,"updateRow")}updateRows(e,i="api"){let o=!1;for(const{id:n,changes:r}of e){const s=this.#S.get(n);if(!s)throw new Error(`[tbw-grid] Row with ID "${n}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:l,index:a}=s;for(const[c,h]of Object.entries(r)){const f=l[c];f!==h&&(o=!0,l[c]=h,this.#L("cell-change",{row:l,rowId:n,rowIndex:a,field:c,oldValue:f,newValue:h,changes:r,source:i}))}}o&&this.#s.requestPhase(A.ROWS,"updateRows")}animateRow(e,i){we(this,e,i)}animateRows(e,i){ci(this,e,i)}animateRowById(e,i){return di(this,e,i)}setColumnVisible(e,i){const o=this.#i.setColumnVisible(e,i);return o&&this.requestStateChange(),o}toggleColumnVisibility(e){const i=this.#i.toggleColumnVisibility(e);return i&&this.requestStateChange(),i}isColumnVisible(e){return this.#i.isColumnVisible(e)}showAllColumns(){this.#i.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#i.getAllColumns()}setColumnOrder(e){this.#i.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#i.getColumnOrder()}getColumnState(){const e=this.#t?.getAll()??[];return this.#i.collectState(e)}set columnState(e){e&&(this.#O=e,this.#i.initialColumnState=e,this.#u&&this.#Me(e))}get columnState(){return this.getColumnState()}#Me(e){const i=this.#t?.getAll()??[];this.#i.applyState(e,i),this.#P()}requestStateChange(){const e=this.#t?.getAll()??[];this.#i.requestStateChange(e)}resetColumnState(){this.#O=void 0,this.__originalOrder=[];const e=this.#t?.getAll()??[];this.#i.resetState(e),this.#i.merge(),this.#P()}get isToolPanelOpen(){return this.#c.isPanelOpen}get defaultRowHeight(){return this._virtualization.rowHeight}get expandedToolPanelSections(){return this.#c.expandedSections}openToolPanel(){this.#c.openToolPanel()}closeToolPanel(){this.#c.closeToolPanel()}toggleToolPanel(){this.#c.toggleToolPanel()}toggleToolPanelSection(e){this.#c.toggleToolPanelSection(e)}getToolPanels(){return this.#c.getToolPanels()}registerToolPanel(e){this.#e.apiToolPanelIds.add(e.id),this.#c.registerToolPanel(e)}unregisterToolPanel(e){this.#e.apiToolPanelIds.delete(e),this.#c.unregisterToolPanel(e)}getHeaderContents(){return this.#c.getHeaderContents()}registerHeaderContent(e){this.#c.registerHeaderContent(e)}unregisterHeaderContent(e){this.#c.unregisterHeaderContent(e)}getToolbarContents(){return this.#c.getToolbarContents()}registerToolbarContent(e){this.#c.registerToolbarContent(e)}unregisterToolbarContent(e){this.#c.unregisterToolbarContent(e)}#Q=!1;refreshShellHeader(){this.#Q||(this.#Q=!0,queueMicrotask(()=>{this.#Q=!1,this.isConnected&&(this.#k(),this.#i.markSourcesChanged(),this.#i.merge(),ve(this.#e),this.#J(),this.#F(),this.#ke())}))}#ke(){const i=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=i?.querySelector(".header-row"),this._virtualization.totalHeightEl=i?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=i?.querySelector(".rows-viewport"),this._bodyEl=i?.querySelector(".rows"),this.__rowsBodyEl=i?.querySelector(".rows-body"),this.#c.isInitialized){me(this.#n,this.#e),be(this.#n,this.#o?.shell,this.#e);const o=this.#o?.shell?.toolPanel?.defaultOpen;o&&this.#e.toolPanels.has(o)&&(this.openToolPanel(),this.#e.expandedSections.add(o))}this._resizeController=Ze(this),this.#Y(i),this.#s.requestPhase(A.COLUMNS,"shellRefresh")}#A=new Map;registerStyles(e,i){let o=this.#A.get(e);o||(o=new CSSStyleSheet,this.#A.set(e,o)),o.replaceSync(i),this.#ge()}unregisterStyles(e){this.#A.delete(e)&&this.#ge()}getRegisteredStyles(){return Array.from(this.#A.keys())}#ge(){const e=Array.from(this.#A.values()),i=document.adoptedStyleSheets.filter(o=>!Array.from(this.#A.values()).includes(o));document.adoptedStyleSheets=[...i,...e]}#k(){nt(this,this.#e),rt(this,this.#e),st(this,this.#e,this.#ne())}#pe(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;ve(this.#e);const i=gi(this.#o.shell,this.#e,this.#o.icons?.toolPanel),o=document.createElement("div");o.innerHTML=i;const n=o.firstElementChild;n&&(e.replaceWith(n),this.#be(),be(this.#n,this.#o?.shell,this.#e))}#Ie(){const e=()=>{const o=this.#e.lightDomTitle,n=this.#e.hasToolButtonsContainer;this.#k();const r=this.#e.lightDomTitle,s=this.#e.hasToolButtonsContainer;(r&&!o||s&&!n)&&(this.#i.markSourcesChanged(),this.#i.merge(),this.#pe())},i=()=>{this.__lightDomColumnsCache=void 0,this.#P()};this.#i.registerLightDomHandler("tbw-grid-header",e),this.#i.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#i.registerLightDomHandler("tbw-grid-tool-panel",e),this.#i.registerLightDomHandler("tbw-grid-column",i),this.#i.registerLightDomHandler("tbw-grid-detail",i),this.#i.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,Q(this),this.#i.parseLightDomColumns(this);const e=this.#e.lightDomTitle,i=this.#e.hasToolButtonsContainer;this.#k();const o=this.#e.lightDomTitle,n=this.#e.hasToolButtonsContainer;(o&&!e||n&&!i)&&(this.#i.markSourcesChanged(),this.#i.merge(),this.#pe()),this.#s.requestPhase(A.COLUMNS,"refreshColumns")}#Ne(){const e=this._virtualization.container,i=this._virtualization.viewportEl??e;i&&(this._virtualization.cachedViewportHeight=i.clientHeight),e&&(this._virtualization.cachedFauxHeight=e.clientHeight);const o=this._virtualization.scrollAreaEl;o&&(this._virtualization.cachedScrollAreaHeight=o.clientHeight)}#T(e,i=!1){const o=this._virtualization;let n,r,s;if(i){const p=o.container??this,g=o.viewportEl??p,u=o.scrollAreaEl;n=p.clientHeight,r=g.clientHeight,s=u?u.clientHeight:n,o.cachedFauxHeight=n,o.cachedViewportHeight=r,o.cachedScrollAreaHeight=s}else n=o.cachedFauxHeight,r=o.cachedViewportHeight,s=o.cachedScrollAreaHeight||n;const l=s-r,a=Math.max(0,n-s);let c,h=0;return o.variableHeights&&o.positionCache?c=Vi(o.positionCache):(c=e*o.rowHeight,h=this.#t?.getExtraHeight()??0),c+l+h+a}#Z(){if(!this._virtualization.variableHeights)return;const e=this._rows,i=this._virtualization.rowHeight||28,o=this.#o.rowHeight,n=this.#o.getRowId,r=n?l=>n(l):void 0;this._virtualization.positionCache=Ui(e,this._virtualization.heightCache,i,{rowId:r},(l,a)=>{const c=this.#t?.getRowHeight?.(l,a);if(c!==void 0)return c;if(o){const h=o(l,a);if(h!==void 0&&h>0)return h}});const s=Yi(this._virtualization.positionCache,e,i,(l,a)=>this.#t?.getRowHeight?.(l,a));this._virtualization.measuredCount=s.measuredCount,s.measuredCount>0&&(this._virtualization.averageHeight=s.averageHeight)}invalidateRowHeight(e,i){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||e<0||e>=this._rows.length)return;const o=this._virtualization.positionCache,n=this._rows[e];let r=i;r===void 0&&(r=this.#t?.getRowHeight?.(n,e)),r===void 0&&(r=this._virtualization.rowHeight);const s=o[e];if(!(!s||Math.abs(s.height-r)<1)&&(Se(o,e,r),this._virtualization.totalHeightEl)){const l=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#we(e,i){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||!this._bodyEl)return;const o=this._bodyEl.querySelectorAll(".data-grid-row"),n=this.#o.getRowId,r=Xi({positionCache:this._virtualization.positionCache,heightCache:this._virtualization.heightCache,rows:this._rows,defaultHeight:this._virtualization.rowHeight,start:e,end:i,getPluginHeight:(s,l)=>this.#t?.getRowHeight?.(s,l),getRowId:n?s=>n(s):void 0},o);if(r.hasChanges&&(this._virtualization.measuredCount=r.measuredCount,this._virtualization.averageHeight=r.averageHeight,this._virtualization.totalHeightEl)){const s=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${s}px`}}refreshVirtualWindow(e=!1,i=!1){if(!this._bodyEl)return!1;const o=this._rows.length;if(!this._virtualization.enabled)return this.#j(0,o),i||this.#t?.afterRender(),!0;if(this._rows.length<=this._virtualization.bypassThreshold)return this._virtualization.start=0,this._virtualization.end=o,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#j(0,o,this.__rowRenderEpoch),e&&this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#T(o,!0)}px`),this.#he(o,this._visibleColumns.length),i||this.#t?.afterRender(),!0;const n=this._virtualization.container??this,r=this._virtualization.viewportEl??n,s=e?this._virtualization.cachedViewportHeight=r.clientHeight:this._virtualization.cachedViewportHeight||(this._virtualization.cachedViewportHeight=r.clientHeight),l=this._virtualization.rowHeight,a=n.scrollTop;let c;const h=this._virtualization.positionCache;if(this._virtualization.variableHeights&&h&&h.length>0)c=ft(h,a),c===-1&&(c=0);else{c=Math.floor(a/l);let m=0;const E=10;for(;m<E;){const T=this.#t?.getExtraHeightBefore?.(c)??0,S=Math.floor((a-T)/l);if(S>=c||S<0)break;c=S,m++}}c=c-c%2,c<0&&(c=0);const f=this.#t?.adjustVirtualStart(c,a,l);f!==void 0&&f<c&&(c=f,c=c-c%2,c<0&&(c=0));let p;if(this._virtualization.variableHeights&&h&&h.length>0){const m=s+l*3;let E=0;for(p=c;p<o&&E<m;)E+=h[p].height,p++;const T=Math.ceil(s/l)+3;p-c<T&&(p=Math.min(c+T,o))}else{const m=Math.ceil(s/l)+3;p=c+m}p>o&&(p=o);const g=this._virtualization.start,u=this._virtualization.end;if(!e&&c===g&&p===u)return!1;this._virtualization.start=c,this._virtualization.end=p;const d=e?this._virtualization.cachedFauxHeight=n.clientHeight:this._virtualization.cachedFauxHeight||(this._virtualization.cachedFauxHeight=n.clientHeight);if(e){const m=this._virtualization.scrollAreaEl;m&&(this._virtualization.cachedScrollAreaHeight=m.clientHeight)}if(d===0&&s>0)return this.#s.requestPhase(A.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&this._virtualization.totalHeightEl){const m=this.#T(o);this._virtualization.totalHeightEl.style.height=`${m}px`}let w;if(this._virtualization.variableHeights&&h&&h[c])w=h[c].offset;else{const m=this.#t?.getExtraHeightBefore?.(c)??0;w=c*l+m}const C=-(a-w);return this._bodyEl.style.transform=`translateY(${C}px)`,this.#j(c,p,this.__rowRenderEpoch),e&&this._virtualization.variableHeights&&this.#we(c,p),this.#he(o,this._visibleColumns.length),e&&!i&&(this.#t?.afterRender(),queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const m=this.#T(o);this._virtualization.cachedFauxHeight===0&&this._virtualization.cachedViewportHeight>0||(this._virtualization.totalHeightEl.style.height=`${m}px`)})),!0}#J(){this.#k(),this.#i.markSourcesChanged(),this.#i.merge();const e=this.#o?.shell;_i(this.#n,e,{isPanelOpen:this.#e.isPanelOpen,expandedSections:this.#e.expandedSections},this.#o?.icons)&&(this.#be(),this.#c.setInitialized(!0))}#be(){pi(this.#n,this.#o?.shell,this.#e,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#q?.(),this.#q=bi(this.#n,this.#o?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)}),this.#$?.(),this.#$=wi(this,this.#o?.shell,this.#e,()=>this.closeToolPanel())}}customElements.get(I.tagName)||customElements.define(I.tagName,I),globalThis.DataGridElement=I;const Ki={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class Qi{static dependencies;static manifest;version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#l;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#l?.abort(),this.#l=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#l?.abort(),this.#l=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,i){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:i,bubbles:!0}))}emitCancelable(e,i){const o=new CustomEvent(e,{detail:i,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(e,i){this.grid?._pluginManager?.subscribe(this,e,i)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,i){this.grid?._pluginManager?.emitPluginEvent(e,i)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#l?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...k,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(e===!1||e==="off")return!1;if(e===!0||e==="on")return!0;const i=this.gridElement;return i?getComputedStyle(i).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationDuration(){const e=this.gridElement;if(e){const i=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(i,10);if(!isNaN(o))return o}return 200}resolveIcon(e,i){return i!==void 0?i:this.gridIcons[e]}setIcon(e,i){typeof i=="string"?e.innerHTML=i:i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const x={ROOT:"tbw-grid-root",HEADER:"header",HEADER_ROW:"header-row",HEADER_CELL:"header-cell",ROWS_VIEWPORT:"rows-viewport",ROWS_SPACER:"rows-spacer",ROWS_CONTAINER:"rows",DATA_ROW:"data-row",GROUP_ROW:"group-row",DATA_CELL:"data-cell",SELECTED:"selected",FOCUSED:"focused",EDITING:"editing",EXPANDED:"expanded",COLLAPSED:"collapsed",DRAGGING:"dragging",RESIZING:"resizing",SORTABLE:"sortable",SORTED_ASC:"sorted-asc",SORTED_DESC:"sorted-desc",HIDDEN:"hidden",STICKY_LEFT:"sticky-left",STICKY_RIGHT:"sticky-right",PINNED_TOP:"pinned-top",PINNED_BOTTOM:"pinned-bottom",TREE_TOGGLE:"tree-toggle",TREE_INDENT:"tree-indent",GROUP_TOGGLE:"group-toggle",GROUP_LABEL:"group-label",GROUP_COUNT:"group-count",RANGE_SELECTION:"range-selection",SELECTION_OVERLAY:"selection-overlay"},j={ROW_INDEX:"data-row-index",COL_INDEX:"data-col-index",FIELD:"data-field",GROUP_KEY:"data-group-key",TREE_LEVEL:"data-tree-level",STICKY:"data-sticky"},Zi={ROOT:`.${x.ROOT}`,HEADER:`.${x.HEADER}`,HEADER_ROW:`.${x.HEADER_ROW}`,HEADER_CELL:`.${x.HEADER_CELL}`,ROWS_VIEWPORT:`.${x.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${x.ROWS_CONTAINER}`,DATA_ROW:`.${x.DATA_ROW}`,DATA_CELL:`.${x.DATA_CELL}`,GROUP_ROW:`.${x.GROUP_ROW}`,ROW_BY_INDEX:t=>`.${x.DATA_ROW}[${j.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${x.DATA_CELL}[${j.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${x.DATA_ROW}[${j.ROW_INDEX}="${t}"] .${x.DATA_CELL}[${j.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${x.DATA_ROW}.${x.SELECTED}`,EDITING_CELL:`.${x.DATA_CELL}.${x.EDITING}`},Ji={COLOR_BG:"--tbw-color-bg",COLOR_FG:"--tbw-color-fg",COLOR_FG_MUTED:"--tbw-color-fg-muted",COLOR_BORDER:"--tbw-color-border",COLOR_ACCENT:"--tbw-color-accent",COLOR_HEADER_BG:"--tbw-color-header-bg",COLOR_HEADER_FG:"--tbw-color-header-fg",COLOR_SELECTION:"--tbw-color-selection",COLOR_ROW_HOVER:"--tbw-color-row-hover",COLOR_ROW_ALT:"--tbw-color-row-alt",ROW_HEIGHT:"--tbw-row-height",HEADER_HEIGHT:"--tbw-header-height",CELL_PADDING:"--tbw-cell-padding",FONT_FAMILY:"--tbw-font-family",FONT_SIZE:"--tbw-font-size",BORDER_RADIUS:"--tbw-border-radius",FOCUS_OUTLINE:"--tbw-focus-outline"};function eo(t){const e=document.createElement("tbw-grid");return t&&(e.gridConfig=t),e}function to(t,e=document){return e.querySelector(t)}const io={CELL_CHANGE:"cell-change",CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",EDIT_OPEN:"edit-open",EDIT_CLOSE:"edit-close",CHANGED_ROWS_RESET:"changed-rows-reset",MOUNT_EXTERNAL_VIEW:"mount-external-view",MOUNT_EXTERNAL_EDITOR:"mount-external-editor",SORT_CHANGE:"sort-change",COLUMN_RESIZE:"column-resize",ACTIVATE_CELL:"activate-cell",CELL_ACTIVATE:"cell-activate",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change"},oo={SELECTION_CHANGE:"selection-change",TREE_EXPAND:"tree-expand",FILTER_CHANGE:"filter-change",SORT_MODEL_CHANGE:"sort-model-change",EXPORT_START:"export-start",EXPORT_COMPLETE:"export-complete",CLIPBOARD_COPY:"clipboard-copy",CLIPBOARD_PASTE:"clipboard-paste",CONTEXT_MENU_OPEN:"context-menu-open",CONTEXT_MENU_CLOSE:"context-menu-close",HISTORY_CHANGE:"history-change",SERVER_LOADING:"server-loading",SERVER_ERROR:"server-error",COLUMN_VISIBILITY_CHANGE:"column-visibility-change",COLUMN_REORDER:"column-reorder",DETAIL_EXPAND:"detail-expand",GROUP_EXPAND:"group-expand"},Re={sum:(t,e)=>t.reduce((i,o)=>i+(Number(o[e])||0),0),avg:(t,e)=>{const i=t.reduce((o,n)=>o+(Number(n[e])||0),0);return t.length?i/t.length:0},count:t=>t.length,min:(t,e)=>t.length?Math.min(...t.map(i=>Number(i[e])||1/0)):0,max:(t,e)=>t.length?Math.max(...t.map(i=>Number(i[e])||-1/0)):0,first:(t,e)=>t[0]?.[e],last:(t,e)=>t[t.length-1]?.[e]},K=new Map,M={register(t,e){K.set(t,e)},unregister(t){K.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:K.get(t)??Re[t]},run(t,e,i,o){const n=this.get(t);return n?n(e,i,o):void 0},has(t){return K.has(t)||t in Re},list(){return[...Object.keys(Re),...K.keys()]}},gt={sum:t=>t.reduce((e,i)=>e+i,0),avg:t=>t.length?t.reduce((e,i)=>e+i,0)/t.length:0,count:t=>t.length,min:t=>t.length?Math.min(...t):0,max:t=>t.length?Math.max(...t):0,first:t=>t[0]??0,last:t=>t[t.length-1]??0};function pt(t){return gt[t]??gt.sum}function no(t,e){return pt(t)(e)}const ro=M.register.bind(M),so=M.unregister.bind(M),lo=M.get.bind(M),ao=M.run.bind(M),co=M.list.bind(M);_.BaseGridPlugin=Qi,_.DEFAULT_ANIMATION_CONFIG=Te,_.DEFAULT_GRID_ICONS=k,_.DGEvents=io,_.DataGridElement=I,_.FitModeEnum=F,_.GridCSSVars=Ji,_.GridClasses=x,_.GridDataAttrs=j,_.GridElement=I,_.GridSelectors=Zi,_.PLUGIN_QUERIES=Ki,_.PluginEvents=oo,_.PluginManager=Y,_.RenderPhase=A,_.aggregatorRegistry=M,_.builtInSort=Be,_.createGrid=eo,_.defaultComparator=Ge,_.getAggregator=lo,_.getValueAggregator=pt,_.listAggregators=co,_.queryGrid=to,_.registerAggregator=ro,_.runAggregator=ao,_.runValueAggregator=no,_.unregisterAggregator=so,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})}));
91
91
  //# sourceMappingURL=grid.umd.js.map