@toolbox-web/grid 1.11.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/all.js +1224 -1110
  2. package/all.js.map +1 -1
  3. package/index.js +2000 -1700
  4. package/index.js.map +1 -1
  5. package/lib/core/grid.d.ts +21 -1
  6. package/lib/core/grid.d.ts.map +1 -1
  7. package/lib/core/internal/aria.d.ts +52 -0
  8. package/lib/core/internal/aria.d.ts.map +1 -0
  9. package/lib/core/internal/config-manager.d.ts.map +1 -1
  10. package/lib/core/internal/idle-scheduler.d.ts +0 -27
  11. package/lib/core/internal/idle-scheduler.d.ts.map +1 -1
  12. package/lib/core/internal/loading.d.ts +0 -38
  13. package/lib/core/internal/loading.d.ts.map +1 -1
  14. package/lib/core/internal/row-animation.d.ts.map +1 -1
  15. package/lib/core/internal/shell.d.ts +6 -0
  16. package/lib/core/internal/shell.d.ts.map +1 -1
  17. package/lib/core/internal/style-injector.d.ts +0 -8
  18. package/lib/core/internal/style-injector.d.ts.map +1 -1
  19. package/lib/core/internal/utils.d.ts +6 -4
  20. package/lib/core/internal/utils.d.ts.map +1 -1
  21. package/lib/core/internal/validate-config.d.ts.map +1 -1
  22. package/lib/core/internal/virtualization.d.ts +177 -23
  23. package/lib/core/internal/virtualization.d.ts.map +1 -1
  24. package/lib/core/plugin/base-plugin.d.ts +50 -0
  25. package/lib/core/plugin/base-plugin.d.ts.map +1 -1
  26. package/lib/core/plugin/plugin-manager.d.ts +18 -0
  27. package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
  28. package/lib/core/plugin/types.d.ts +16 -0
  29. package/lib/core/plugin/types.d.ts.map +1 -1
  30. package/lib/core/types.d.ts +56 -3
  31. package/lib/core/types.d.ts.map +1 -1
  32. package/lib/plugins/clipboard/index.js.map +1 -1
  33. package/lib/plugins/column-virtualization/index.js.map +1 -1
  34. package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
  35. package/lib/plugins/context-menu/index.js +1 -1
  36. package/lib/plugins/context-menu/index.js.map +1 -1
  37. package/lib/plugins/editing/EditingPlugin.d.ts +7 -5
  38. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  39. package/lib/plugins/editing/index.js +379 -278
  40. package/lib/plugins/editing/index.js.map +1 -1
  41. package/lib/plugins/editing/types.d.ts +14 -1
  42. package/lib/plugins/editing/types.d.ts.map +1 -1
  43. package/lib/plugins/export/index.js.map +1 -1
  44. package/lib/plugins/filtering/index.js.map +1 -1
  45. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +8 -1
  46. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
  47. package/lib/plugins/grouping-columns/index.js +59 -60
  48. package/lib/plugins/grouping-columns/index.js.map +1 -1
  49. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +14 -0
  50. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
  51. package/lib/plugins/grouping-rows/index.js +88 -69
  52. package/lib/plugins/grouping-rows/index.js.map +1 -1
  53. package/lib/plugins/grouping-rows/types.d.ts +17 -0
  54. package/lib/plugins/grouping-rows/types.d.ts.map +1 -1
  55. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +24 -0
  56. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
  57. package/lib/plugins/master-detail/index.js +203 -128
  58. package/lib/plugins/master-detail/index.js.map +1 -1
  59. package/lib/plugins/multi-sort/index.js.map +1 -1
  60. package/lib/plugins/pinned-columns/index.js.map +1 -1
  61. package/lib/plugins/pinned-rows/index.js +2 -2
  62. package/lib/plugins/pinned-rows/index.js.map +1 -1
  63. package/lib/plugins/pivot/index.js +2 -2
  64. package/lib/plugins/pivot/index.js.map +1 -1
  65. package/lib/plugins/print/index.js.map +1 -1
  66. package/lib/plugins/reorder/index.js.map +1 -1
  67. package/lib/plugins/responsive/ResponsivePlugin.d.ts +13 -0
  68. package/lib/plugins/responsive/ResponsivePlugin.d.ts.map +1 -1
  69. package/lib/plugins/responsive/index.js +65 -49
  70. package/lib/plugins/responsive/index.js.map +1 -1
  71. package/lib/plugins/row-reorder/index.js.map +1 -1
  72. package/lib/plugins/selection/index.js +5 -5
  73. package/lib/plugins/selection/index.js.map +1 -1
  74. package/lib/plugins/server-side/index.js.map +1 -1
  75. package/lib/plugins/tree/index.js.map +1 -1
  76. package/lib/plugins/undo-redo/index.js.map +1 -1
  77. package/lib/plugins/visibility/index.js.map +1 -1
  78. package/package.json +1 -1
  79. package/umd/grid.all.umd.js +27 -25
  80. package/umd/grid.all.umd.js.map +1 -1
  81. package/umd/grid.umd.js +18 -16
  82. package/umd/grid.umd.js.map +1 -1
  83. package/umd/plugins/context-menu.umd.js +1 -1
  84. package/umd/plugins/context-menu.umd.js.map +1 -1
  85. package/umd/plugins/editing.umd.js +1 -1
  86. package/umd/plugins/editing.umd.js.map +1 -1
  87. package/umd/plugins/grouping-columns.umd.js +1 -1
  88. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  89. package/umd/plugins/grouping-rows.umd.js +2 -2
  90. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  91. package/umd/plugins/master-detail.umd.js +1 -1
  92. package/umd/plugins/master-detail.umd.js.map +1 -1
  93. package/umd/plugins/responsive.umd.js +1 -1
  94. package/umd/plugins/responsive.umd.js.map +1 -1
  95. package/umd/plugins/selection.umd.js +2 -2
  96. package/umd/plugins/selection.umd.js.map +1 -1
package/umd/grid.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(v,z){typeof exports=="object"&&typeof module<"u"?z(exports):typeof define=="function"&&define.amd?define(["exports"],z):(v=typeof globalThis<"u"?globalThis:v||self,z(v.TbwGrid={}))})(this,(function(v){"use strict";const z={STRETCH:"stretch",FIXED:"fixed"},Ce={mode:"reduced-motion",duration:200,easing:"ease-out"},ye='<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>',M={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:ye,filterActive:ye,print:"🖨️"};function at(t){return Array.from(t.querySelectorAll("tbw-grid-column")).map(o=>{const i=o.getAttribute("field")||"";if(!i)return null;const n=o.getAttribute("type")||void 0,s=n&&new Set(["number","string","date","boolean","select"]).has(n)?n:void 0,l=o.getAttribute("header")||void 0,a=o.hasAttribute("sortable"),c=o.hasAttribute("editable"),d={field:i,type:s,header:l,sortable:a,editable:c},u=o.getAttribute("width");if(u){const b=parseFloat(u);!isNaN(b)&&/^\d+(\.\d+)?$/.test(u.trim())?d.width=b:d.width=u}const g=o.getAttribute("minWidth")||o.getAttribute("min-width");if(g){const b=parseFloat(g);isNaN(b)||(d.minWidth=b)}o.hasAttribute("resizable")&&(d.resizable=!0),o.hasAttribute("sizable")&&(d.resizable=!0);const f=o.getAttribute("editor"),p=o.getAttribute("renderer");f&&(d.__editorName=f),p&&(d.__rendererName=p);const h=o.getAttribute("options");h&&(d.options=h.split(",").map(b=>{const[I,A]=b.includes(":")?b.split(":"):[b.trim(),b.trim()];return{value:I.trim(),label:A?.trim()||I.trim()}}));const w=o.querySelector("tbw-grid-column-view"),C=o.querySelector("tbw-grid-column-editor"),R=o.querySelector("tbw-grid-column-header");w&&(d.__viewTemplate=w),C&&(d.__editorTemplate=C),R&&(d.__headerTemplate=R);const E=globalThis.DataGridElement?.getAdapters?.()??[],P=w??o,m=E.find(b=>b.canHandle(P));if(m){const b=m.createRenderer(P);b&&(d.viewRenderer=b)}const S=C??o,_=E.find(b=>b.canHandle(S));if(_){const b=_.createEditor(S);b&&(d.editor=b)}return d}).filter(o=>!!o)}function _e(t,e){if((!t||!t.length)&&(!e||!e.length))return[];if(!t||!t.length)return e||[];if(!e||!e.length)return t;const o={};e.forEach(n=>{const r=o[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 o[n.field]={...n}});const i=t.map(n=>{const r=o[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 o[n.field],s});return Object.keys(o).forEach(n=>i.push(o[n])),i}function Ee(t,e){try{t.part?.add?.(e)}catch{}const o=t.getAttribute("part");o?o.split(/\s+/).includes(e)||t.setAttribute("part",o+" "+e):t.setAttribute("part",e)}function Se(t){const e=t.effectiveConfig?.fitMode||t.fitMode||z.STRETCH;if(e!==z.STRETCH&&e!==z.FIXED||t.__didInitialAutoSize||!t.isConnected)return;const o=Array.from(t._headerRowEl?.children||[]);if(!o.length)return;let i=!1;t._visibleColumns.forEach((n,r)=>{if(n.width)return;const s=o[r];let l=s?s.scrollWidth:0;for(const a of t._rowPool){const c=a.children[r];if(c){const d=c.scrollWidth;d>l&&(l=d)}}l>0&&(n.width=l+2,n.__autoSized=!0,i=!0)}),i&&V(t),t.__didInitialAutoSize=!0}function V(t){(t.effectiveConfig?.fitMode||t.fitMode||z.STRETCH)===z.STRETCH?t._gridTemplate=t._visibleColumns.map(o=>{if(o.width)return`${o.width}px`;const i=o.minWidth;return i!=null?`minmax(${i}px, 1fr)`:"1fr"}).join(" ").trim():t._gridTemplate=t._visibleColumns.map(o=>o.width?`${o.width}px`:"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 dt(t,e){const o=t[0]||{},i=Object.keys(o).map(r=>{const s=o[r],l=ct(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),n={};return i.forEach(r=>{n[r.field]=r.type||"string"}),{columns:i,typeMap:n}}const ht=/{{\s*([^}]+)\s*}}/g,D="__DG_EMPTY__",ut=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,ft=/__(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 gt(t){return!t||typeof t!="string"?"":t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}const pt=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"]),Re=/^on\w+$/i,wt=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),bt=/^\s*(javascript|vbscript|data|blob):/i;function $(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,mt(e.content),e.innerHTML}function mt(t){const e=[],o=t.querySelectorAll("*");for(const i of o){const n=i.tagName.toLowerCase();if(pt.has(n)){e.push(i);continue}if((n==="svg"||i.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(i.attributes).some(l=>Re.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(i);continue}const r=[];for(const s of i.attributes){const l=s.name.toLowerCase();if(Re.test(l)){r.push(s.name);continue}if(wt.has(l)&&bt.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=>i.removeAttribute(s))}e.forEach(i=>i.remove())}function Ae(t,e){if(!t||t.indexOf("{{")===-1)return t;const o=[],i=t.replace(ht,(l,a)=>{const c=vt(a,e);return o.push({expr:a.trim(),result:c}),c}),n=Ct(i),r=o.length&&o.every(l=>l.result===""||l.result===D);return/Reflect\.|\bProxy\b|ownKeys\(/.test(t)||r?"":n}function vt(t,e){if(t=(t||"").trim(),!t||/\b(Reflect|Proxy|ownKeys)\b/.test(t))return D;if(t==="value")return e.value==null?D:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),n=e.row?e.row[i]:void 0;return n==null?D:String(n)}if(t.length>80||!ut.test(t)||ft.test(t))return D;const o=t.match(/\./g);if(o&&o.length>1)return D;try{const n=new Function("value","row",`return (${t});`)(e.value,e.row),r=n==null?"":String(n);return/Reflect|Proxy|ownKeys/.test(r)?D:r||D}catch{return D}}function Ct(t){return t&&t.replace(new RegExp(D,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function yt(t){if(/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(Array.from(t.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(t.textContent||""))for(;t.firstChild;)t.removeChild(t.firstChild);t.textContent=(t.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(t.textContent||"").trim().length===0&&(t.textContent="")}}function Te(t){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(t),o=(i=>e?"":Ae(t,i));return o.__blocked=e,o}const _t=100;class Et{#l;#n;#u;#d;#h;#a={};#i={};#f=!0;#g=[];#b;#s;#m;#r;#p;constructor(e){this.#r=e}get original(){return this.#a}get effective(){return this.#i}get columns(){return this.#i.columns??[]}set columns(e){this.#i.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.#p}set lightDomTitle(e){this.#p=e}get initialColumnState(){return this.#m}set initialColumnState(e){this.#m=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.#i.columns?.length??0)>0;if(!this.#f&&e)return;const o=this.#C();this.#f=!1,this.#a=o,Object.freeze(this.#a),this.#a.columns&&Object.freeze(this.#a.columns),this.#i=this.#A(this.#a),this.#D()}#A(e){const o={...e};return e.columns&&(o.columns=e.columns.map(i=>({...i}))),e.shell&&(o.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(i=>({...i})),headerContents:e.shell.headerContents?.map(i=>({...i}))}),o}#D(){const e=this.#i;this.#w(),e.rowHeight&&e.rowHeight>0&&this.#r.setRowHeight(e.rowHeight),e.fitMode==="fixed"&&this.columns.forEach(i=>{i.width==null&&(i.width=80)}),this.#r.applyAnimationConfig(e)}#w(){const e=this.#i.typeDefaults;if(!e)return;const o=this.columns;for(const i of o){if(!i.type)continue;const n=e[i.type];n&&(!i.renderer&&!i.viewRenderer&&n.renderer&&(i.renderer=n.renderer),!i.format&&n.format&&(i.format=n.format),!i.editor&&n.editor&&(i.editor=n.editor),!i.editorParams&&n.editorParams&&(i.editorParams=n.editorParams))}}#C(){const e=this.#l?{...this.#l}:{},o=Array.isArray(e.columns)?[...e.columns]:[],i=(this.#d??[]).map(s=>({...s}));let n=_e(o,i);this.#n&&this.#n.length&&(n=_e(this.#n,i));const r=this.#r.getRows();return n.length===0&&r.length&&(n=dt(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=Te(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=Te(s.__editorTemplate.innerHTML))}),e.columns=n),this.#u&&(e.fitMode=this.#u),e.fitMode||(e.fitMode="stretch"),this.#y(e),e.columnState&&!this.#m&&(this.#m=e.columnState),e}#y(e){e.shell=e.shell?{...e.shell}:{},e.shell.header=e.shell.header?{...e.shell.header}:{};const o=this.#r.getShellLightDomTitle();o&&(this.#p=o),this.#p&&!e.shell.header.title&&(e.shell.header.title=this.#p);const i=this.#r.getShellLightDomHeaderContent();i?.length>0&&(e.shell.header.lightDomContent=i),this.#r.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const n=this.#r.getShellToolPanels();if(n.size>0){const u=Array.from(n.values());u.sort((g,f)=>(g.order??100)-(f.order??100)),e.shell.toolPanels=u}const r=this.#r.getShellHeaderContents();if(r.size>0){const u=Array.from(r.values());u.sort((g,f)=>(g.order??100)-(f.order??100)),e.shell.headerContents=u}const s=this.#r.getShellToolbarContents(),l=Array.from(s.values()),a=this.#l?.shell?.header?.toolbarContents??[],c=new Set(a.map(u=>u.id)),d=[...a];for(const u of l)c.has(u.id)||d.push(u);d.sort((u,g)=>(u.order??0)-(g.order??0)),e.shell.header.toolbarContents=d}collectState(e){const o=this.columns,i=this.#v();return{columns:o.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=i.get(n.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const d=c.getColumnState(n.field);d&&Object.assign(s,d)}return s})}}applyState(e,o){if(!e.columns||e.columns.length===0)return;const i=this.columns,n=new Map(e.columns.map(l=>[l.field,l])),r=i.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,d=n.get(a.field)?.order??1/0;return c-d}),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 o)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}resetState(e){this.#m=void 0,this.#r.setSortState(null),this.#i=this.#A(this.#a),this.#D();for(const o of e)if(o.applyColumnState)for(const i of this.columns)o.applyColumnState(i.field,{field:i.field,order:0,visible:!0});this.requestStateChange(e)}#v(){const e=new Map,o=this.#r.getSortState();return o&&e.set(o.field,{direction:o.direction===1?"asc":"desc",priority:0}),e}requestStateChange(e){this.#s&&clearTimeout(this.#s),this.#s=setTimeout(()=>{this.#s=void 0;const o=this.collectState(e);this.#r.emit("column-state-change",o)},_t)}setColumnVisible(e,o){const i=this.columns,n=i.find(s=>s.field===e);return!n||!o&&n.lockVisible||!o&&i.filter(l=>!l.hidden&&l.field!==e).length===0||!!n.hidden===!o?!1:(n.hidden=!o,this.#r.emit("column-visibility",{field:e,visible:o,visibleColumns:i.filter(s=>!s.hidden).map(s=>s.field)}),this.#r.clearRowPool(),this.#r.setup(),!0)}toggleColumnVisibility(e){const o=this.columns.find(i=>i.field===e);return o?this.setColumnVisible(e,!!o.hidden):!1}isColumnVisible(e){const o=this.columns.find(i=>i.field===e);return o?!o.hidden:!1}showAllColumns(){const e=this.columns;e.some(o=>o.hidden)&&(e.forEach(o=>o.hidden=!1),this.#r.emit("column-visibility",{visibleColumns:e.map(o=>o.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 o=new Map(this.columns.map(n=>[n.field,n])),i=[];for(const n of e){const r=o.get(n);r&&(i.push(r),o.delete(n))}for(const n of o.values())i.push(n);this.columns=i,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?at(e):[])}clearLightDomCache(){this.#d=void 0}#_=new Map;registerLightDomHandler(e,o){this.#_.set(e.toLowerCase(),o)}unregisterLightDomHandler(e){this.#_.delete(e.toLowerCase())}observeLightDOM(e){this.#b&&this.#b.disconnect();const o=new Set;let i=null;const n=()=>{i=null;for(const r of o)this.#_.get(r)?.();o.clear()};this.#b=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.#_.has(c)&&o.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#_.has(a)&&o.add(a)}}o.size>0&&!i&&(i=setTimeout(n,0))}),this.#b.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#g.push(e)}notifyChange(){for(const e of this.#g)e()}dispose(){this.#b?.disconnect(),this.#g=[],this.#s&&clearTimeout(this.#s)}}function xe(t){return`<span role="checkbox" aria-checked="${t}" aria-label="${t}">${t?"&#x1F5F9;":"&#9744;"}</span>`}function Pe(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 Le(t){if(!t)return-1;const e=t.getAttribute("data-row");if(e)return parseInt(e,10);const o=t.closest(".data-grid-row");if(!o)return-1;const i=o.parentElement;if(!i)return-1;const n=i.querySelectorAll(":scope > .data-grid-row");for(let r=0;r<n.length;r++)if(n[r]===o)return r;return-1}function St(t){if(!t)return-1;const e=t.getAttribute("data-col");return e?parseInt(e,10):-1}function se(t){t&&t.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function Rt(t){try{if(getComputedStyle(t).direction==="rtl")return"rtl"}catch{}try{if(t.closest?.("[dir]")?.getAttribute("dir")==="rtl")return"rtl"}catch{}return"ltr"}function He(t){return Rt(t)==="rtl"}function De(t,e){const o=e.renderer||e.viewRenderer;if(o)return o;if(!e.type)return;const i=t.__frameworkAdapter;if(i?.getTypeDefault){const n=i.getTypeDefault(e.type);if(n?.renderer)return n.renderer}}function Oe(t,e){if(e.format)return e.format;if(!e.type)return;const o=t.__frameworkAdapter;if(o?.getTypeDefault){const i=o.getTypeDefault(e.type);if(i?.format)return i.format}}const ze='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function le(t){return(t.__editingCellCount??0)>0}function ae(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing"),t.querySelectorAll(".cell.editing").forEach(o=>o.classList.remove("editing"))}const Me=document.createElement("template");Me.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Ne=document.createElement("template");Ne.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function At(){return Me.content.firstElementChild.cloneNode(!0)}function Tt(){return Ne.content.firstElementChild.cloneNode(!0)}function K(t){t.__cellDisplayCache=void 0,t.__cellCacheEpoch=void 0,t.__hasSpecialColumns=void 0}function xt(t,e,o,i,n){const r=Math.max(0,o-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 g=Tt();t._rowPool.push(g)}if(t._rowPool.length>r){for(let g=r;g<t._rowPool.length;g++){const f=t._rowPool[g];f.parentNode===s&&f.remove()}t._rowPool.length=r}const d=n&&t.__hasRenderRowPlugins!==!1,u=t._hasAfterRowRenderHook?.()??!1;for(let g=0;g<r;g++){const f=e+g,p=t._rows[f],h=t._rowPool[g];if(h.setAttribute("aria-rowindex",String(f+c+1)),d&&n(p,h,f)){h.__epoch=i,h.__rowDataRef=p,h.parentNode!==s&&s.appendChild(h);continue}const w=h.__epoch,C=h.__rowDataRef,R=h.children.length,E=w===i&&R===a,P=C!==p;let m=!1;if(E&&P){for(let A=0;A<a;A++)if(l[A].externalView&&!h.querySelector(`.cell[data-col="${A}"] [data-external-view]`)){m=!0;break}}if(!E||m){const A=le(h),T=t._activeEditRows===f;A&&!T?(h.__isCustomRow&&(h.className="data-grid-row",h.setAttribute("role","row"),h.__isCustomRow=!1),ae(h),B(t,h,p,f),h.__epoch=i,h.__rowDataRef=p):A&&T?(ce(t,h,p,f),h.__rowDataRef=p):(h.__isCustomRow&&(h.className="data-grid-row",h.setAttribute("role","row"),h.__isCustomRow=!1),B(t,h,p,f),h.__epoch=i,h.__rowDataRef=p)}else if(P){const A=le(h),T=t._activeEditRows===f;A&&!T?(ae(h),B(t,h,p,f),h.__epoch=i,h.__rowDataRef=p):(ce(t,h,p,f),h.__rowDataRef=p)}else{const A=le(h),T=t._activeEditRows===f;A&&!T?(ae(h),B(t,h,p,f),h.__epoch=i,h.__rowDataRef=p):ce(t,h,p,f)}let S=!1;const _=t.changedRowIds;if(_&&_.length>0)try{const A=t.getRowId?.(p);A&&(S=_.includes(A))}catch{}const b=h.classList.contains("changed");S!==b&&h.classList.toggle("changed",S);const I=t.effectiveConfig?.rowClass;if(I){const A=h.getAttribute("data-dynamic-classes");A&&A.split(" ").forEach(T=>T&&h.classList.remove(T));try{const T=I(p);if(T&&T.length>0){const ve=T.filter(re=>re&&typeof re=="string");ve.forEach(re=>h.classList.add(re)),h.setAttribute("data-dynamic-classes",ve.join(" "))}else h.removeAttribute("data-dynamic-classes")}catch(T){console.warn("[tbw-grid] rowClass callback error:",T),h.removeAttribute("data-dynamic-classes")}}u&&t._afterRowRender?.({row:p,rowIndex:f,rowElement:h}),h.parentNode!==s&&s.appendChild(h)}}function ce(t,e,o,i){const n=e.children,r=t._visibleColumns,s=r.length,l=n.length,a=s<l?s:l,c=t._focusRow,d=t._focusCol,u=t._hasAfterCellRenderHook?.()??!1;let g=t.__hasSpecialColumns;if(g===void 0){g=!1;const p=t.__frameworkAdapter;for(let h=0;h<s;h++){const w=r[h];if(w.__viewTemplate||w.__compiledView||w.renderer||w.viewRenderer||w.externalView||w.format||w.type==="date"||w.type==="boolean"||w.type&&p?.getTypeDefault?.(w.type)?.renderer||w.type&&p?.getTypeDefault?.(w.type)?.format){g=!0;break}}t.__hasSpecialColumns=g}const f=String(i);if(!g){for(let p=0;p<a;p++){const h=n[p];if(h.classList.contains("editing"))continue;const w=r[p],C=o[w.field];h.textContent=C==null?"":String(C),h.getAttribute("data-row")!==f&&h.setAttribute("data-row",f);const R=c===i&&d===p,y=h.classList.contains("cell-focus");R!==y&&(h.classList.toggle("cell-focus",R),h.setAttribute("aria-selected",String(R))),u&&t._afterCellRender?.({row:o,rowIndex:i,column:w,colIndex:p,value:C,cellElement:h,rowElement:e})}return}for(let p=0;p<a;p++)if(r[p].externalView&&!n[p].querySelector("[data-external-view]")){B(t,e,o,i);return}for(let p=0;p<a;p++){const h=r[p],w=n[p];w.getAttribute("data-row")!==f&&w.setAttribute("data-row",f);const C=c===i&&d===p,R=w.classList.contains("cell-focus");C!==R&&(w.classList.toggle("cell-focus",C),w.setAttribute("aria-selected",String(C)));const y=h.cellClass;if(y){const _=w.getAttribute("data-dynamic-classes");_&&_.split(" ").forEach(b=>b&&w.classList.remove(b));try{const b=o[h.field],I=y(b,o,h);if(I&&I.length>0){const A=I.filter(T=>T&&typeof T=="string");A.forEach(T=>w.classList.add(T)),w.setAttribute("data-dynamic-classes",A.join(" "))}else w.removeAttribute("data-dynamic-classes")}catch(b){console.warn(`[tbw-grid] cellClass callback error for column '${h.field}':`,b),w.removeAttribute("data-dynamic-classes")}}if(w.classList.contains("editing"))continue;const E=De(t,h);if(E){const _=o[h.field],b=E({row:o,value:_,field:h.field,column:h,cellEl:w});typeof b=="string"?w.innerHTML=$(b):b instanceof Node?b.parentElement!==w&&(w.innerHTML="",w.appendChild(b)):b==null&&(w.textContent=_==null?"":String(_)),u&&t._afterCellRender?.({row:o,rowIndex:i,column:h,colIndex:p,value:_,cellElement:w,rowElement:e});continue}if(h.__viewTemplate||h.__compiledView||h.externalView)continue;const P=o[h.field];let m;const S=Oe(t,h);if(S){try{const _=S(P,o);m=_==null?"":String(_)}catch(_){console.warn(`[tbw-grid] Format error in column '${h.field}':`,_),m=P==null?"":String(P)}w.textContent=m}else h.type==="date"?(m=Pe(P),w.textContent=m):h.type==="boolean"?w.innerHTML=xe(!!P):(m=P==null?"":String(P),w.textContent=m);u&&t._afterCellRender?.({row:o,rowIndex:i,column:h,colIndex:p,value:P,cellElement:w,rowElement:e})}}function B(t,e,o,i){e.innerHTML="";const n=t._visibleColumns,r=n.length,s=t._focusRow,l=t._focusCol,a=t,c=t._hasAfterCellRenderHook?.()??!1,d=document.createDocumentFragment();for(let u=0;u<r;u++){const g=n[u],f=At();f.setAttribute("aria-colindex",String(u+1)),f.setAttribute("data-col",String(u)),f.setAttribute("data-row",String(i)),f.setAttribute("data-field",g.field),f.setAttribute("data-header",g.header??g.field),g.type&&f.setAttribute("data-type",g.type);let p=o[g.field];const h=Oe(t,g);if(h)try{p=h(p,o)}catch(m){console.warn(`[tbw-grid] Format error in column '${g.field}':`,m)}const w=g.__compiledView,C=g.__viewTemplate,R=De(t,g),y=g.externalView;let E=!1;if(R){const m=R({row:o,value:p,field:g.field,column:g,cellEl:f});typeof m=="string"?(f.innerHTML=$(m),E=!0):m instanceof Node?m.parentElement!==f&&(f.textContent="",f.appendChild(m)):m==null&&(f.textContent=p==null?"":String(p))}else if(y){const m=y,S=document.createElement("div");S.setAttribute("data-external-view",""),S.setAttribute("data-field",g.field),f.appendChild(S);const _={row:o,value:p,field:g.field,column:g};if(m.mount)try{m.mount({placeholder:S,context:_,spec:m})}catch(b){console.warn(`[tbw-grid] External view mount error for column '${g.field}':`,b)}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:S,spec:m,context:_}}))}catch(b){console.warn(`[tbw-grid] External view event dispatch error for column '${g.field}':`,b)}});S.setAttribute("data-mounted","")}else if(w){const m=w({row:o,value:p,field:g.field,column:g}),S=w.__blocked;f.innerHTML=S?"":$(m),E=!0,S&&(f.textContent="",f.setAttribute("data-blocked-template",""))}else if(C){const m=C.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(m)?(f.textContent="",f.setAttribute("data-blocked-template","")):(f.innerHTML=$(Ae(m,{row:o,value:p})),E=!0)}else h?f.textContent=p==null?"":String(p):g.type==="date"?f.textContent=Pe(p):g.type==="boolean"?f.innerHTML=xe(!!p):f.textContent=p==null?"":String(p);if(E){yt(f);const m=f.textContent||"";/Proxy|Reflect\.ownKeys/.test(m)&&(f.textContent=m.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(f.textContent||"")&&(f.textContent=""))}f.hasAttribute("data-blocked-template")&&(f.textContent||"").trim().length&&(f.textContent=""),g.editable?f.tabIndex=0:g.type==="boolean"&&(f.hasAttribute("tabindex")||(f.tabIndex=0)),s===i&&l===u?(f.classList.add("cell-focus"),f.setAttribute("aria-selected","true")):f.setAttribute("aria-selected","false");const P=g.cellClass;if(P)try{const m=o[g.field],S=P(m,o,g);if(S&&S.length>0){const _=S.filter(b=>b&&typeof b=="string");_.forEach(b=>f.classList.add(b)),f.setAttribute("data-dynamic-classes",_.join(" "))}}catch(m){console.warn(`[tbw-grid] cellClass callback error for column '${g.field}':`,m)}c&&t._afterCellRender?.({row:o,rowIndex:i,column:g,colIndex:u,value:p,cellElement:f,rowElement:e}),d.appendChild(f)}e.appendChild(d)}function ke(t,e,o){if(e.target?.closest(".resize-handle"))return;const i=o.querySelector(".cell[data-row]"),n=Le(i);if(n<0)return;const r=t._rows[n];if(!r||t._dispatchRowClick?.(e,n,r,o))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&&(se(t._bodyEl??t),s.classList.add("cell-focus"));const c=s.querySelector(ze);try{c?.focus({preventScroll:!0})}catch{}return}W(t)}}}function Pt(t,e){if(t._dispatchKeyDown?.(e))return;const o=t._rows.length-1,i=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=d=>{if(!d)return!1;const u=d.tagName;return!!(u==="INPUT"||u==="SELECT"||u==="TEXTAREA"||d.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<i?t._focusCol+=1:(typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow<o&&(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=i),W(t);return}case"ArrowDown":n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.min(o,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":{He(t)?t._focusCol=Math.max(0,t._focusCol-1):t._focusCol=Math.min(i,t._focusCol+1),e.preventDefault();break}case"ArrowLeft":{He(t)?t._focusCol=Math.min(i,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(),W(t,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=o),t._focusCol=i,e.preventDefault(),W(t,{forceScrollRight:!0});return;case"PageDown":t._focusRow=Math.min(o,t._focusRow+20),e.preventDefault();break;case"PageUp":t._focusRow=Math.max(0,t._focusRow-20),e.preventDefault();break;case"Enter":{const d=t._focusRow,u=t._focusCol,g=t._visibleColumns[u],f=t._rows[d],p=g?.field??"",h=p&&f?f[p]:void 0,w=t.querySelector(`[data-row="${d}"][data-col="${u}"]`),C={rowIndex:d,colIndex:u,field:p,value:h,row:f,cellEl:w,trigger:"keyboard",originalEvent:e},R=new CustomEvent("cell-activate",{cancelable:!0,detail:C});t.dispatchEvent(R);const y=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:d,col:u}});if(t.dispatchEvent(y),R.defaultPrevented||y.defaultPrevented){e.preventDefault();return}break}default:return}W(t)}}function W(t,e){if(t._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=t._virtualization,c=l,d=a?.clientHeight??c?.clientHeight??0;if(c&&d>0){const u=t._focusRow*s;u<c.scrollTop?c.scrollTop=u:u+s>c.scrollTop+d&&(c.scrollTop=u-d+s)}}const o=t._activeEditRows!==void 0&&t._activeEditRows!==-1;o||t.refreshVirtualWindow(!1),se(t._bodyEl),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const i=t._focusRow,n=t._virtualization.start??0,r=t._virtualization.end??t._rows.length;if(i>=n&&i<r){const s=t._bodyEl.querySelectorAll(".data-grid-row")[i-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&&(!o||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 d=l.getBoundingClientRect(),u=a.getBoundingClientRect(),g=d.left-u.left+a.scrollLeft,f=g+d.width,p=a.scrollLeft+c.left,h=a.scrollLeft+a.clientWidth-c.right;g<p?a.scrollLeft=g-c.left:f>h&&(a.scrollLeft=f-a.clientWidth+c.right)}}if(t._activeEditRows!==void 0&&t._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector(ze);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const Q=new WeakMap;function Lt(t,e){const o=Le(e),i=St(e);o<0||i<0||(t._focusRow=o,t._focusCol=i,se(t._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true"))}function de(t,e,o,i){let n=null;const r=o.composedPath?.();if(r&&r.length>0?n=r[0]:n=o.target,n&&!e.contains(n)){const h=document.elementFromPoint(o.clientX,o.clientY);h&&(n=h)}const s=n?.closest?.("[data-col]"),l=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let c,d,u,g,f,p;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(u=t._rows[c],p=t._columns[d],g=p?.field,f=u&&g?u[g]:void 0)),{type:i,row:u,rowIndex:c!==void 0&&c>=0?c:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:g,value:f,column:p,originalEvent:o,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:c!==void 0&&d!==void 0&&c>=0&&d>=0?{row:c,col:d}:void 0}}function Ht(t,e,o){const i=de(t,e,o,"mousedown");(t._dispatchCellMouseDown?.(i)??!1)&&Q.set(t,!0)}function Dt(t,e,o){if(!Q.get(t))return;const i=de(t,e,o,"mousemove");t._dispatchCellMouseMove?.(i)}function Ot(t,e,o){if(!Q.get(t))return;const i=de(t,e,o,"mouseup");t._dispatchCellMouseUp?.(i),Q.set(t,!1)}function zt(t,e,o){e.addEventListener("mousedown",i=>{const n=i.target.closest(".cell[data-col]");n&&(n.classList.contains("editing")||Lt(t,n))},{signal:o}),e.addEventListener("click",i=>{const n=i.target.closest(".data-grid-row");n&&ke(t,i,n)},{signal:o}),e.addEventListener("dblclick",i=>{const n=i.target.closest(".data-grid-row");n&&ke(t,i,n)},{signal:o})}function Mt(t,e,o,i){e.addEventListener("keydown",n=>Pt(t,n),{signal:i}),o.addEventListener("mousedown",n=>Ht(t,o,n),{signal:i}),document.addEventListener("mousemove",n=>Dt(t,o,n),{signal:i}),document.addEventListener("mouseup",n=>Ot(t,o,n),{signal:i})}function Ie(t,e){return t==null&&e==null?0:t==null?-1:e==null||t>e?1:t<e?-1:0}function qe(t,e,o){const n=o.find(l=>l.field===e.field)?.sortComparator??Ie,{field:r,direction:s}=e;return[...t].sort((l,a)=>n(l[r],a[r],l,a)*s)}function $e(t,e,o,i){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:o.field,direction:i}})),t.requestStateChange?.()}function We(t,e){!t._sortState||t._sortState.field!==e.field?(t._sortState||(t.__originalOrder=t._rows.slice()),Fe(t,e,1)):t._sortState.direction===1?Fe(t,e,-1):(t._sortState=null,t.__rowRenderEpoch++,t._rowPool.forEach(i=>i.__epoch=-1),t._rows=t.__originalOrder.slice(),oe(t),t._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(i=>{i.getAttribute("aria-sort")?(i.getAttribute("aria-sort")==="ascending"||i.getAttribute("aria-sort")==="descending")&&(t._sortState||i.setAttribute("aria-sort","none")):i.setAttribute("aria-sort","none")}),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),t.requestStateChange?.())}function Fe(t,e,o){t._sortState={field:e.field,direction:o};const i={field:e.field,direction:o},n=t._columns,s=(t.effectiveConfig?.sortHandler??qe)(t._rows,i,n);s&&typeof s.then=="function"?s.then(l=>{$e(t,l,e,o)}):$e(t,s,e,o)}function X(t,e){return t.effectiveConfig?.sortable!==!1&&e.sortable===!0}function Z(t,e){return t.effectiveConfig?.resizable!==!1&&e.resizable!==!1}function Nt(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function J(t,e){const o=document.createElement("span");Ee(o,"sort-indicator");const i=t._sortState?.field===e.field?t._sortState.direction:0,n={...M,...t.icons},r=i===1?n.sortAsc:i===-1?n.sortDesc:n.sortNone;return Nt(o,r),o}function ee(t,e,o){const i=document.createElement("div");return i.className="resize-handle",i.setAttribute("aria-hidden","true"),i.addEventListener("mousedown",n=>{n.stopPropagation(),n.preventDefault(),t._resizeController.start(n,e,o)}),i.addEventListener("dblclick",n=>{n.stopPropagation(),n.preventDefault(),t._resizeController.resetColumn(e)}),i}function te(t,e,o,i){i.classList.add("sortable"),i.tabIndex=0;const n=t._sortState?.field===e.field?t._sortState.direction:0;i.setAttribute("aria-sort",n===0?"none":n===1?"ascending":"descending"),i.addEventListener("click",r=>{t._resizeController?.isResizing||t._dispatchHeaderClick?.(r,o,i)||We(t,e)}),i.addEventListener("keydown",r=>{if(r.key==="Enter"||r.key===" "){if(r.preventDefault(),t._dispatchHeaderClick?.(r,o,i))return;We(t,e)}})}function kt(t,e){if(e!=null)if(typeof e=="string"){const o=document.createElement("span");for(o.innerHTML=$(e);o.firstChild;)t.appendChild(o.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((o,i)=>{const n=document.createElement("div");n.className="cell",Ee(n,"header-cell"),n.setAttribute("role","columnheader"),n.setAttribute("aria-colindex",String(i+1)),n.setAttribute("data-field",o.field),n.setAttribute("data-col",String(i));const r=o.header??o.field,s=t._sortState?.field===o.field?t._sortState.direction:0,l=s===1?"asc":s===-1?"desc":null;if(o.headerRenderer){const a={column:o,value:r,sortState:l,filterActive:!1,cellEl:n,renderSortIcon:()=>X(t,o)?J(t,o):null,renderFilterButton:()=>null},c=o.headerRenderer(a);kt(n,c),X(t,o)&&te(t,o,i,n),Z(t,o)&&(n.classList.add("resizable"),n.appendChild(ee(t,i,n)))}else if(o.headerLabelRenderer){const a={column:o,value:r},c=o.headerLabelRenderer(a),d=document.createElement("span");c==null?d.textContent=r:typeof c=="string"?d.innerHTML=$(c):c instanceof Node&&d.appendChild(c),n.appendChild(d),X(t,o)&&(te(t,o,i,n),n.appendChild(J(t,o))),Z(t,o)&&(n.classList.add("resizable"),n.appendChild(ee(t,i,n)))}else if(o.__headerTemplate)Array.from(o.__headerTemplate.childNodes).forEach(a=>n.appendChild(a.cloneNode(!0))),X(t,o)&&(te(t,o,i,n),n.appendChild(J(t,o))),Z(t,o)&&(n.classList.add("resizable"),n.appendChild(ee(t,i,n)));else{const a=document.createElement("span");a.textContent=r,n.appendChild(a),X(t,o)&&(te(t,o,i,n),n.appendChild(J(t,o))),Z(t,o)&&(n.classList.add("resizable"),n.appendChild(ee(t,i,n)))}e.appendChild(n)}),e.querySelectorAll(".cell.sortable").forEach(o=>{o.getAttribute("aria-sort")||o.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 Ue=typeof requestIdleCallback=="function";function It(t,e){return Ue?requestIdleCallback(t,e):window.setTimeout(()=>{const o=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-o))})},1)}function Ge(t){Ue?cancelIdleCallback(t):clearTimeout(t)}function qt(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 $t(t,e){if(e){const i=e({size:t});if(typeof i=="string"){const n=document.createElement("div");return n.innerHTML=i,n}return i}return qt(t)}function Wt(t){const e=document.createElement("div");return e.className="tbw-loading-overlay",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.appendChild($t("large",t)),e}function Ft(t,e){t.appendChild(e)}function Ut(t){t?.remove()}function Gt(t,e){e?(t.classList.add("tbw-row-loading"),t.setAttribute("aria-busy","true")):(t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy"))}function Vt(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 x=(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))(x||{});class Bt{#l;#n=0;#u=0;#d=null;#h=null;#a=null;#i=!1;constructor(e){this.#l=e}requestPhase(e,o){e>this.#n&&(this.#n=e),this.#u===0&&(this.#f(),this.#u=requestAnimationFrame(()=>this.#g()))}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}))}#g(){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.#i&&this.#a&&(this.#i=!0,this.#a()),this.#h&&(this.#h(),this.#h=null,this.#d=null)}}function Ve(t){let e=null,o=null,i=null,n=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,d=Math.max(40,e.startWidth+c),u=t._visibleColumns[e.colIndex];u.width=d,u.__userResized=!0,u.__renderedWidth=d,o==null&&(o=requestAnimationFrame(()=>{o=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:u.field,width:d}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),i!==null&&(document.documentElement.style.cursor=i,i=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,d){a.preventDefault();const u=t._visibleColumns[c],g=typeof u?.width=="number"?u.width:void 0,f=u?.__renderedWidth??g??d.getBoundingClientRect().width;e={startX:a.clientX,colIndex:c,startWidth:f},window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),i===null&&(i=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 he="data-animating",Xt={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},Yt={change:500,insert:300,remove:200};function jt(t){const e=t.trim().toLowerCase();return e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:parseFloat(e)}function Kt(t,e){const o=Xt[e],i=getComputedStyle(t).getPropertyValue(o);if(i){const n=jt(i);if(!isNaN(n)&&n>0)return n}return Yt[e]}function Qt(t,e,o){t.removeAttribute(he),t.offsetWidth,t.setAttribute(he,e);const i=Kt(t,e);setTimeout(()=>{e!=="remove"&&t.removeAttribute(he)},i)}function ue(t,e,o){if(e<0)return!1;const i=t.findRenderedRowElement?.(e);return i?(Qt(i,o),!0):!1}function Zt(t,e,o){let i=0;for(const n of e)ue(t,n,o)&&i++;return i}function Jt(t,e,o){const i=t._rows??[],n=t.getRowId;if(!n)return!1;const r=i.findIndex(s=>n(s)===e);return r<0?!1:ue(t,r,o)}function ie(t,e,o){const i=document.createElement(t);if(e)for(const n in e){const r=e[n];r!=null&&i.setAttribute(n,r)}return i}function H(t,e){const o=document.createElement("div");if(t&&(o.className=t),e)for(const i in e){const n=e[i];n!=null&&o.setAttribute(i,n)}return o}function Be(t,e,o){const i=document.createElement("button");if(t&&(i.className=t),e)for(const n in e){const r=e[n];r!=null&&i.setAttribute(n,r)}return i}const Xe=document.createElement("template");Xe.innerHTML=`
1
+ (function(y,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(y=typeof globalThis<"u"?globalThis:y||self,F(y.TbwGrid={}))})(this,(function(y){"use strict";function F(){return{rowCount:-1,colCount:-1,ariaLabel:void 0,ariaDescribedBy:void 0}}function ut(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 ft(t,e){const i=t?.gridAriaLabel;return i||(t?.shell?.header?.title??e?.lightDomTitle??void 0)}function gt(t,e,i,o){if(!e)return!1;let n=!1;const r=ft(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 q={STRETCH:"stretch",FIXED:"fixed"},Ee={mode:"reduced-motion",duration:200,easing:"ease-out"},Se='<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>',O={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:Se,filterActive:Se,print:"🖨️"};function pt(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"),d={field:o,type:s,header:l,sortable:a,editable:c},u=i.getAttribute("width");if(u){const b=parseFloat(u);!isNaN(b)&&/^\d+(\.\d+)?$/.test(u.trim())?d.width=b:d.width=u}const f=i.getAttribute("minWidth")||i.getAttribute("min-width");if(f){const b=parseFloat(f);isNaN(b)||(d.minWidth=b)}i.hasAttribute("resizable")&&(d.resizable=!0),i.hasAttribute("sizable")&&(d.resizable=!0);const g=i.getAttribute("editor"),p=i.getAttribute("renderer");g&&(d.__editorName=g),p&&(d.__rendererName=p);const h=i.getAttribute("options");h&&(d.options=h.split(",").map(b=>{const[I,A]=b.includes(":")?b.split(":"):[b.trim(),b.trim()];return{value:I.trim(),label:A?.trim()||I.trim()}}));const w=i.querySelector("tbw-grid-column-view"),C=i.querySelector("tbw-grid-column-editor"),m=i.querySelector("tbw-grid-column-header");w&&(d.__viewTemplate=w),C&&(d.__editorTemplate=C),m&&(d.__headerTemplate=m);const S=globalThis.DataGridElement?.getAdapters?.()??[],T=w??i,v=S.find(b=>b.canHandle(T));if(v){const b=v.createRenderer(T);b&&(d.viewRenderer=b)}const R=C??i,E=S.find(b=>b.canHandle(R));if(E){const b=E.createEditor(R);b&&(d.editor=b)}return d}).filter(i=>!!i)}function Re(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 Ae(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 Te(t){const e=t.effectiveConfig?.fitMode||t.fitMode||q.STRETCH;if(e!==q.STRETCH&&e!==q.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 d=c.scrollWidth;d>l&&(l=d)}}l>0&&(n.width=l+2,n.__autoSized=!0,o=!0)}),o&&U(t),t.__didInitialAutoSize=!0}function U(t){(t.effectiveConfig?.fitMode||t.fitMode||q.STRETCH)===q.STRETCH?t._gridTemplate=t._visibleColumns.map(i=>{if(i.width)return`${i.width}px`;const o=i.minWidth;return o!=null?`minmax(${o}px, 1fr)`:"1fr"}).join(" ").trim():t._gridTemplate=t._visibleColumns.map(i=>i.width?`${i.width}px`:"max-content").join(" "),t.style.setProperty("--tbw-column-template",t._gridTemplate)}function wt(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 bt(t,e){const i=t[0]||{},o=Object.keys(i).map(r=>{const s=i[r],l=wt(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 mt=/{{\s*([^}]+)\s*}}/g,z="__DG_EMPTY__",vt=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Ct=/__(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 yt(t){return!t||typeof t!="string"?"":t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}const _t=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"]),xe=/^on\w+$/i,Et=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),St=/^\s*(javascript|vbscript|data|blob):/i;function $(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,Rt(e.content),e.innerHTML}function Rt(t){const e=[],i=t.querySelectorAll("*");for(const o of i){const n=o.tagName.toLowerCase();if(_t.has(n)){e.push(o);continue}if((n==="svg"||o.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(o.attributes).some(l=>xe.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(xe.test(l)){r.push(s.name);continue}if(Et.has(l)&&St.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 He(t,e){if(!t||t.indexOf("{{")===-1)return t;const i=[],o=t.replace(mt,(l,a)=>{const c=At(a,e);return i.push({expr:a.trim(),result:c}),c}),n=Tt(o),r=i.length&&i.every(l=>l.result===""||l.result===z);return/Reflect\.|\bProxy\b|ownKeys\(/.test(t)||r?"":n}function At(t,e){if(t=(t||"").trim(),!t||/\b(Reflect|Proxy|ownKeys)\b/.test(t))return z;if(t==="value")return e.value==null?z: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?z:String(n)}if(t.length>80||!vt.test(t)||Ct.test(t))return z;const i=t.match(/\./g);if(i&&i.length>1)return z;try{const n=new Function("value","row",`return (${t});`)(e.value,e.row),r=n==null?"":String(n);return/Reflect|Proxy|ownKeys/.test(r)?z:r||z}catch{return z}}function Tt(t){return t&&t.replace(new RegExp(z,"g"),"").replace(/Reflect\.[^<>{}\s]+/g,"").replace(/\bProxy\b/g,"").replace(/ownKeys\([^)]*\)/g,"")}function xt(t){if(/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(Array.from(t.childNodes).forEach(e=>{e.nodeType===Node.TEXT_NODE&&/Reflect|Proxy|ownKeys/.test(e.textContent||"")&&(e.textContent="")}),/Reflect|Proxy|ownKeys/.test(t.textContent||"")){if(/Reflect|Proxy|ownKeys/.test(t.textContent||""))for(;t.firstChild;)t.removeChild(t.firstChild);t.textContent=(t.textContent||"").replace(/Reflect|Proxy|ownKeys/g,"")}(t.textContent||"").trim().length===0&&(t.textContent="")}}function Pe(t){const e=/Reflect\.|\bProxy\b|ownKeys\(/.test(t),i=(o=>e?"":He(t,o));return i.__blocked=e,i}const Ht=100;class Pt{#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.#k();this.#f=!1,this.#a=i,Object.freeze(this.#a),this.#a.columns&&Object.freeze(this.#a.columns),this.#o=this.#T(this.#a),this.#m()}#T(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))}}#k(){const e=this.#l?{...this.#l}:{},i=Array.isArray(e.columns)?[...e.columns]:[],o=(this.#d??[]).map(s=>({...s}));let n=Re(i,o);this.#n&&this.#n.length&&(n=Re(this.#n,o));const r=this.#r.getRows();return n.length===0&&r.length&&(n=bt(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=Pe(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=Pe(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 u=Array.from(n.values());u.sort((f,g)=>(f.order??100)-(g.order??100)),e.shell.toolPanels=u}const r=this.#r.getShellHeaderContents();if(r.size>0){const u=Array.from(r.values());u.sort((f,g)=>(f.order??100)-(g.order??100)),e.shell.headerContents=u}const s=this.#r.getShellToolbarContents(),l=Array.from(s.values()),a=this.#l?.shell?.header?.toolbarContents??[],c=new Set(a.map(u=>u.id)),d=[...a];for(const u of l)c.has(u.id)||d.push(u);d.sort((u,f)=>(u.order??0)-(f.order??0)),e.shell.header.toolbarContents=d}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 d=c.getColumnState(n.field);d&&Object.assign(s,d)}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,d=n.get(a.field)?.order??1/0;return c-d}),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.#T(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)},Ht)}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?pt(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 re(){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 Le(t){return`<span role="checkbox" aria-checked="${t}" aria-label="${t}">${t?"&#x1F5F9;":"&#9744;"}</span>`}function ze(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 De(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 Lt(t){if(!t)return-1;const e=t.getAttribute("data-col");return e?parseInt(e,10):-1}function se(t){t&&t.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function zt(t){try{if(getComputedStyle(t).direction==="rtl")return"rtl"}catch{}try{if(t.closest?.("[dir]")?.getAttribute("dir")==="rtl")return"rtl"}catch{}return"ltr"}function Oe(t){return zt(t)==="rtl"}function Me(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 ke(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 Ie='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function le(t){return(t.__editingCellCount??0)>0}function ae(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing"),t.querySelectorAll(".cell.editing").forEach(i=>i.classList.remove("editing"))}const Ne=document.createElement("template");Ne.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const qe=document.createElement("template");qe.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function Dt(){return Ne.content.firstElementChild.cloneNode(!0)}function Ot(){return qe.content.firstElementChild.cloneNode(!0)}function j(t){t.__cellDisplayCache=void 0,t.__cellCacheEpoch=void 0,t.__hasSpecialColumns=void 0}function Mt(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 f=Ot();t._rowPool.push(f)}if(t._rowPool.length>r){for(let f=r;f<t._rowPool.length;f++){const g=t._rowPool[f];g.parentNode===s&&g.remove()}t._rowPool.length=r}const d=n&&t.__hasRenderRowPlugins!==!1,u=t._hasAfterRowRenderHook?.()??!1;for(let f=0;f<r;f++){const g=e+f,p=t._rows[g],h=t._rowPool[f];if(h.setAttribute("aria-rowindex",String(g+c+1)),d&&n(p,h,g)){h.__epoch=o,h.__rowDataRef=p,h.parentNode!==s&&s.appendChild(h);continue}const w=h.__epoch,C=h.__rowDataRef,m=h.children.length,S=w===o&&m===a,T=C!==p;let v=!1;if(S&&T){for(let A=0;A<a;A++)if(l[A].externalView&&!h.querySelector(`.cell[data-col="${A}"] [data-external-view]`)){v=!0;break}}if(!S||v){const A=le(h),x=t._activeEditRows===g;A&&!x?(h.__isCustomRow&&(h.className="data-grid-row",h.setAttribute("role","row"),h.__isCustomRow=!1),ae(h),V(t,h,p,g),h.__epoch=o,h.__rowDataRef=p):A&&x?(ce(t,h,p,g),h.__rowDataRef=p):(h.__isCustomRow&&(h.className="data-grid-row",h.setAttribute("role","row"),h.__isCustomRow=!1),V(t,h,p,g),h.__epoch=o,h.__rowDataRef=p)}else if(T){const A=le(h),x=t._activeEditRows===g;A&&!x?(ae(h),V(t,h,p,g),h.__epoch=o,h.__rowDataRef=p):(ce(t,h,p,g),h.__rowDataRef=p)}else{const A=le(h),x=t._activeEditRows===g;A&&!x?(ae(h),V(t,h,p,g),h.__epoch=o,h.__rowDataRef=p):ce(t,h,p,g)}let R=!1;const E=t.changedRowIds;if(E&&E.length>0)try{const A=t.getRowId?.(p);A&&(R=E.includes(A))}catch{}const b=h.classList.contains("changed");R!==b&&h.classList.toggle("changed",R);const I=t.effectiveConfig?.rowClass;if(I){const A=h.getAttribute("data-dynamic-classes");A&&A.split(" ").forEach(x=>x&&h.classList.remove(x));try{const x=I(p);if(x&&x.length>0){const _e=x.filter(ne=>ne&&typeof ne=="string");_e.forEach(ne=>h.classList.add(ne)),h.setAttribute("data-dynamic-classes",_e.join(" "))}else h.removeAttribute("data-dynamic-classes")}catch(x){console.warn("[tbw-grid] rowClass callback error:",x),h.removeAttribute("data-dynamic-classes")}}u&&t._afterRowRender?.({row:p,rowIndex:g,rowElement:h}),h.parentNode!==s&&s.appendChild(h)}}function ce(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,d=t._focusCol,u=t._hasAfterCellRenderHook?.()??!1;let f=t.__hasSpecialColumns;if(f===void 0){f=!1;const p=t.__frameworkAdapter;for(let h=0;h<s;h++){const w=r[h];if(w.__viewTemplate||w.__compiledView||w.renderer||w.viewRenderer||w.externalView||w.format||w.type==="date"||w.type==="boolean"||w.type&&p?.getTypeDefault?.(w.type)?.renderer||w.type&&p?.getTypeDefault?.(w.type)?.format){f=!0;break}}t.__hasSpecialColumns=f}const g=String(o);if(!f){for(let p=0;p<a;p++){const h=n[p];if(h.classList.contains("editing"))continue;const w=r[p],C=i[w.field];h.textContent=C==null?"":String(C),h.getAttribute("data-row")!==g&&h.setAttribute("data-row",g);const m=c===o&&d===p,_=h.classList.contains("cell-focus");m!==_&&(h.classList.toggle("cell-focus",m),h.setAttribute("aria-selected",String(m))),u&&t._afterCellRender?.({row:i,rowIndex:o,column:w,colIndex:p,value:C,cellElement:h,rowElement:e})}return}for(let p=0;p<a;p++)if(r[p].externalView&&!n[p].querySelector("[data-external-view]")){V(t,e,i,o);return}for(let p=0;p<a;p++){const h=r[p],w=n[p];w.getAttribute("data-row")!==g&&w.setAttribute("data-row",g);const C=c===o&&d===p,m=w.classList.contains("cell-focus");C!==m&&(w.classList.toggle("cell-focus",C),w.setAttribute("aria-selected",String(C)));const _=h.cellClass;if(_){const E=w.getAttribute("data-dynamic-classes");E&&E.split(" ").forEach(b=>b&&w.classList.remove(b));try{const b=i[h.field],I=_(b,i,h);if(I&&I.length>0){const A=I.filter(x=>x&&typeof x=="string");A.forEach(x=>w.classList.add(x)),w.setAttribute("data-dynamic-classes",A.join(" "))}else w.removeAttribute("data-dynamic-classes")}catch(b){console.warn(`[tbw-grid] cellClass callback error for column '${h.field}':`,b),w.removeAttribute("data-dynamic-classes")}}if(w.classList.contains("editing"))continue;const S=Me(t,h);if(S){const E=i[h.field],b=S({row:i,value:E,field:h.field,column:h,cellEl:w});typeof b=="string"?w.innerHTML=$(b):b instanceof Node?b.parentElement!==w&&(w.innerHTML="",w.appendChild(b)):b==null&&(w.textContent=E==null?"":String(E)),u&&t._afterCellRender?.({row:i,rowIndex:o,column:h,colIndex:p,value:E,cellElement:w,rowElement:e});continue}if(h.__viewTemplate||h.__compiledView||h.externalView)continue;const T=i[h.field];let v;const R=ke(t,h);if(R){try{const E=R(T,i);v=E==null?"":String(E)}catch(E){console.warn(`[tbw-grid] Format error in column '${h.field}':`,E),v=T==null?"":String(T)}w.textContent=v}else h.type==="date"?(v=ze(T),w.textContent=v):h.type==="boolean"?w.innerHTML=Le(!!T):(v=T==null?"":String(T),w.textContent=v);u&&t._afterCellRender?.({row:i,rowIndex:o,column:h,colIndex:p,value:T,cellElement:w,rowElement:e})}}function V(t,e,i,o){e.innerHTML="";const n=t._visibleColumns,r=n.length,s=t._focusRow,l=t._focusCol,a=t,c=t._hasAfterCellRenderHook?.()??!1,d=document.createDocumentFragment();for(let u=0;u<r;u++){const f=n[u],g=Dt();g.setAttribute("aria-colindex",String(u+1)),g.setAttribute("data-col",String(u)),g.setAttribute("data-row",String(o)),g.setAttribute("data-field",f.field),g.setAttribute("data-header",f.header??f.field),f.type&&g.setAttribute("data-type",f.type);let p=i[f.field];const h=ke(t,f);if(h)try{p=h(p,i)}catch(v){console.warn(`[tbw-grid] Format error in column '${f.field}':`,v)}const w=f.__compiledView,C=f.__viewTemplate,m=Me(t,f),_=f.externalView;let S=!1;if(m){const v=m({row:i,value:p,field:f.field,column:f,cellEl:g});typeof v=="string"?(g.innerHTML=$(v),S=!0):v instanceof Node?v.parentElement!==g&&(g.textContent="",g.appendChild(v)):v==null&&(g.textContent=p==null?"":String(p))}else if(_){const v=_,R=document.createElement("div");R.setAttribute("data-external-view",""),R.setAttribute("data-field",f.field),g.appendChild(R);const E={row:i,value:p,field:f.field,column:f};if(v.mount)try{v.mount({placeholder:R,context:E,spec:v})}catch(b){console.warn(`[tbw-grid] External view mount error for column '${f.field}':`,b)}else queueMicrotask(()=>{try{a.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:R,spec:v,context:E}}))}catch(b){console.warn(`[tbw-grid] External view event dispatch error for column '${f.field}':`,b)}});R.setAttribute("data-mounted","")}else if(w){const v=w({row:i,value:p,field:f.field,column:f}),R=w.__blocked;g.innerHTML=R?"":$(v),S=!0,R&&(g.textContent="",g.setAttribute("data-blocked-template",""))}else if(C){const v=C.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(v)?(g.textContent="",g.setAttribute("data-blocked-template","")):(g.innerHTML=$(He(v,{row:i,value:p})),S=!0)}else h?g.textContent=p==null?"":String(p):f.type==="date"?g.textContent=ze(p):f.type==="boolean"?g.innerHTML=Le(!!p):g.textContent=p==null?"":String(p);if(S){xt(g);const v=g.textContent||"";/Proxy|Reflect\.ownKeys/.test(v)&&(g.textContent=v.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(g.textContent||"")&&(g.textContent=""))}g.hasAttribute("data-blocked-template")&&(g.textContent||"").trim().length&&(g.textContent=""),f.editable?g.tabIndex=0:f.type==="boolean"&&(g.hasAttribute("tabindex")||(g.tabIndex=0)),s===o&&l===u?(g.classList.add("cell-focus"),g.setAttribute("aria-selected","true")):g.setAttribute("aria-selected","false");const T=f.cellClass;if(T)try{const v=i[f.field],R=T(v,i,f);if(R&&R.length>0){const E=R.filter(b=>b&&typeof b=="string");E.forEach(b=>g.classList.add(b)),g.setAttribute("data-dynamic-classes",E.join(" "))}}catch(v){console.warn(`[tbw-grid] cellClass callback error for column '${f.field}':`,v)}c&&t._afterCellRender?.({row:i,rowIndex:o,column:f,colIndex:u,value:p,cellElement:g,rowElement:e}),d.appendChild(g)}e.appendChild(d)}function $e(t,e,i){if(e.target?.closest(".resize-handle"))return;const o=i.querySelector(".cell[data-row]"),n=De(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&&(se(t._bodyEl??t),s.classList.add("cell-focus"));const c=s.querySelector(Ie);try{c?.focus({preventScroll:!0})}catch{}return}W(t)}}}function kt(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=d=>{if(!d)return!1;const u=d.tagName;return!!(u==="INPUT"||u==="SELECT"||u==="TEXTAREA"||d.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),W(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":{Oe(t)?t._focusCol=Math.max(0,t._focusCol-1):t._focusCol=Math.min(o,t._focusCol+1),e.preventDefault();break}case"ArrowLeft":{Oe(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(),W(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(),W(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 d=t._focusRow,u=t._focusCol,f=t._visibleColumns[u],g=t._rows[d],p=f?.field??"",h=p&&g?g[p]:void 0,w=t.querySelector(`[data-row="${d}"][data-col="${u}"]`),C={rowIndex:d,colIndex:u,field:p,value:h,row:g,cellEl:w,trigger:"keyboard",originalEvent:e},m=new CustomEvent("cell-activate",{cancelable:!0,detail:C});t.dispatchEvent(m);const _=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:d,col:u}});if(t.dispatchEvent(_),m.defaultPrevented||_.defaultPrevented){e.preventDefault();return}break}default:return}W(t)}}function W(t,e){if(t._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=t._virtualization,c=l,d=a?.clientHeight??c?.clientHeight??0;if(c&&d>0){const u=t._focusRow*s;u<c.scrollTop?c.scrollTop=u:u+s>c.scrollTop+d&&(c.scrollTop=u-d+s)}}const i=t._activeEditRows!==void 0&&t._activeEditRows!==-1;i||t.refreshVirtualWindow(!1),se(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 d=l.getBoundingClientRect(),u=a.getBoundingClientRect(),f=d.left-u.left+a.scrollLeft,g=f+d.width,p=a.scrollLeft+c.left,h=a.scrollLeft+a.clientWidth-c.right;f<p?a.scrollLeft=f-c.left:g>h&&(a.scrollLeft=g-a.clientWidth+c.right)}}if(t._activeEditRows!==void 0&&t._activeEditRows!==-1&&l.classList.contains("editing")){const c=l.querySelector(Ie);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}}}}const K=new WeakMap;function It(t,e){const i=De(e),o=Lt(e);i<0||o<0||(t._focusRow=i,t._focusCol=o,se(t._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true"))}function de(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 h=document.elementFromPoint(i.clientX,i.clientY);h&&(n=h)}const s=n?.closest?.("[data-col]"),l=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let c,d,u,f,g,p;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(u=t._rows[c],p=t._columns[d],f=p?.field,g=u&&f?u[f]:void 0)),{type:o,row:u,rowIndex:c!==void 0&&c>=0?c:void 0,colIndex:d!==void 0&&d>=0?d:void 0,field:f,value:g,column:p,originalEvent:i,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:c!==void 0&&d!==void 0&&c>=0&&d>=0?{row:c,col:d}:void 0}}function Nt(t,e,i){const o=de(t,e,i,"mousedown");(t._dispatchCellMouseDown?.(o)??!1)&&K.set(t,!0)}function qt(t,e,i){if(!K.get(t))return;const o=de(t,e,i,"mousemove");t._dispatchCellMouseMove?.(o)}function $t(t,e,i){if(!K.get(t))return;const o=de(t,e,i,"mouseup");t._dispatchCellMouseUp?.(o),K.set(t,!1)}function Wt(t,e,i){e.addEventListener("mousedown",o=>{const n=o.target.closest(".cell[data-col]");n&&(n.classList.contains("editing")||It(t,n))},{signal:i}),e.addEventListener("click",o=>{const n=o.target.closest(".data-grid-row");n&&$e(t,o,n)},{signal:i}),e.addEventListener("dblclick",o=>{const n=o.target.closest(".data-grid-row");n&&$e(t,o,n)},{signal:i})}function Ft(t,e,i,o){e.addEventListener("keydown",n=>kt(t,n),{signal:o}),i.addEventListener("mousedown",n=>Nt(t,i,n),{signal:o}),document.addEventListener("mousemove",n=>qt(t,i,n),{signal:o}),document.addEventListener("mouseup",n=>$t(t,i,n),{signal:o})}function We(t,e){return t==null&&e==null?0:t==null?-1:e==null||t>e?1:t<e?-1:0}function Fe(t,e,i){const n=i.find(l=>l.field===e.field)?.sortComparator??We,{field:r,direction:s}=e;return[...t].sort((l,a)=>n(l[r],a[r],l,a)*s)}function Ue(t,e,i,o){t._rows=e,t.__rowRenderEpoch++,t._rowPool.forEach(n=>n.__epoch=-1),te(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:i.field,direction:o}})),t.requestStateChange?.()}function Ve(t,e){!t._sortState||t._sortState.field!==e.field?(t._sortState||(t.__originalOrder=t._rows.slice()),Ge(t,e,1)):t._sortState.direction===1?Ge(t,e,-1):(t._sortState=null,t.__rowRenderEpoch++,t._rowPool.forEach(o=>o.__epoch=-1),t._rows=t.__originalOrder.slice(),te(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 Ge(t,e,i){t._sortState={field:e.field,direction:i};const o={field:e.field,direction:i},n=t._columns,s=(t.effectiveConfig?.sortHandler??Fe)(t._rows,o,n);s&&typeof s.then=="function"?s.then(l=>{Ue(t,l,e,i)}):Ue(t,s,e,i)}function G(t,e){return t.effectiveConfig?.sortable!==!1&&e.sortable===!0}function Q(t,e){return t.effectiveConfig?.resizable!==!1&&e.resizable!==!1}function Ut(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function Z(t,e){const i=document.createElement("span");Ae(i,"sort-indicator");const o=t._sortState?.field===e.field?t._sortState.direction:0,n={...O,...t.icons},r=o===1?n.sortAsc:o===-1?n.sortDesc:n.sortNone;return Ut(i,r),i}function J(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 ee(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,i,o)||Ve(t,e)}),o.addEventListener("keydown",r=>{if(r.key==="Enter"||r.key===" "){if(r.preventDefault(),t._dispatchHeaderClick?.(r,i,o))return;Ve(t,e)}})}function Vt(t,e){if(e!=null)if(typeof e=="string"){const i=document.createElement("span");for(i.innerHTML=$(e);i.firstChild;)t.appendChild(i.firstChild)}else e instanceof Node&&t.appendChild(e)}function te(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",Ae(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));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:()=>G(t,i)?Z(t,i):null,renderFilterButton:()=>null},c=i.headerRenderer(a);Vt(n,c),G(t,i)&&ee(t,i,o,n),Q(t,i)&&(n.classList.add("resizable"),n.appendChild(J(t,o,n)))}else if(i.headerLabelRenderer){const a={column:i,value:r},c=i.headerLabelRenderer(a),d=document.createElement("span");c==null?d.textContent=r:typeof c=="string"?d.innerHTML=$(c):c instanceof Node&&d.appendChild(c),n.appendChild(d),G(t,i)&&(ee(t,i,o,n),n.appendChild(Z(t,i))),Q(t,i)&&(n.classList.add("resizable"),n.appendChild(J(t,o,n)))}else if(i.__headerTemplate)Array.from(i.__headerTemplate.childNodes).forEach(a=>n.appendChild(a.cloneNode(!0))),G(t,i)&&(ee(t,i,o,n),n.appendChild(Z(t,i))),Q(t,i)&&(n.classList.add("resizable"),n.appendChild(J(t,o,n)));else{const a=document.createElement("span");a.textContent=r,n.appendChild(a),G(t,i)&&(ee(t,i,o,n),n.appendChild(Z(t,i))),Q(t,i)&&(n.classList.add("resizable"),n.appendChild(J(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 Be=typeof requestIdleCallback=="function";function Gt(t,e){return Be?requestIdleCallback(t,e):window.setTimeout(()=>{const i=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-i))})},1)}function Xe(t){Be?cancelIdleCallback(t):clearTimeout(t)}function Bt(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 Xt(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 Bt(t)}function Yt(t){const e=document.createElement("div");return e.className="tbw-loading-overlay",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.appendChild(Xt("large",t)),e}function jt(t,e){t.appendChild(e)}function Kt(t){t?.remove()}function Qt(t,e){e?(t.classList.add("tbw-row-loading"),t.setAttribute("aria-busy","true")):(t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy"))}function Zt(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 H=(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))(H||{});class Jt{#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 Ye(t){let e=null,i=null,o=null,n=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,d=Math.max(40,e.startWidth+c),u=t._visibleColumns[e.colIndex];u.width=d,u.__userResized=!0,u.__renderedWidth=d,i==null&&(i=requestAnimationFrame(()=>{i=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:u.field,width:d}}))};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,d){a.preventDefault();const u=t._visibleColumns[c],f=typeof u?.width=="number"?u.width:void 0,g=u?.__renderedWidth??f??d.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 he="data-animating",ei={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},ti={change:500,insert:300,remove:200};function ii(t){const e=t.trim().toLowerCase();return e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:parseFloat(e)}function oi(t,e){const i=ei[e],o=getComputedStyle(t).getPropertyValue(i);if(o){const n=ii(o);if(!isNaN(n)&&n>0)return n}return ti[e]}function ni(t,e,i){t.removeAttribute(he),t.offsetWidth,t.setAttribute(he,e);const o=oi(t,e);setTimeout(()=>{e!=="remove"&&t.removeAttribute(he)},o)}function ue(t,e,i){if(e<0)return!1;const o=t.findRenderedRowElement?.(e);return o?(ni(o,i),!0):!1}function ri(t,e,i){let o=0;for(const n of e)ue(t,n,i)&&o++;return o}function si(t,e,i){const o=t._rows??[],n=t.getRowId;if(!n)return!1;const r=o.findIndex(s=>n(s)===e);return r<0?!1:ue(t,r,i)}function ie(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 L(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 Ke=document.createElement("template");Ke.innerHTML=`
2
2
  <div class="tbw-scroll-area">
3
3
  <div class="rows-body-wrapper">
4
4
  <div class="rows-body" role="grid">
@@ -16,23 +16,23 @@
16
16
  <div class="faux-vscroll">
17
17
  <div class="faux-vscroll-spacer"></div>
18
18
  </div>
19
- `;function Ye(){return Xe.content.cloneNode(!0)}function je(t){const e=document.createDocumentFragment(),o=H(t.hasShell?"tbw-grid-root has-shell":"tbw-grid-root");if(t.hasShell&&t.shellHeader&&t.shellBody)o.appendChild(t.shellHeader),o.appendChild(t.shellBody);else{const i=H("tbw-grid-content");i.appendChild(Ye()),o.appendChild(i)}return e.appendChild(o),e}function eo(t){const e=H("tbw-shell-header",{part:"shell-header",role:"presentation"});if(t.title){const r=H("tbw-shell-title");r.textContent=t.title,e.appendChild(r)}const o=H("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});e.appendChild(o);const i=H("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const r of t.configButtons)r.hasRender&&i.appendChild(H("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));for(const r of t.apiButtons)r.hasRender&&i.appendChild(H("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));if((t.configButtons.some(r=>r.hasRender)||t.apiButtons.some(r=>r.hasRender))&&t.hasPanels&&i.appendChild(H("tbw-toolbar-separator")),t.hasPanels){const r=Be(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,i.appendChild(r)}return e.appendChild(i),e}function to(t){const e=H("tbw-shell-body"),o=t.panels.length>0,i=t.panels.length===1,n=H("tbw-grid-content");n.appendChild(Ye());let r=null;if(o){r=ie("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(H("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":s,"aria-hidden":"true"}));const l=H("tbw-tool-panel-content",{role:"presentation"}),a=H("tbw-accordion");for(const c of t.panels){const d=`tbw-accordion-section${c.isExpanded?" expanded":""}${i?" single":""}`,u=H(d,{"data-section":c.id}),g=Be("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(i&&g.setAttribute("aria-disabled","true"),c.icon){const p=ie("span",{class:"tbw-accordion-icon"});p.innerHTML=c.icon,g.appendChild(p)}const f=ie("span",{class:"tbw-accordion-title"});if(f.textContent=c.title,g.appendChild(f),!i){const p=ie("span",{class:"tbw-accordion-chevron"});p.innerHTML=c.isExpanded?t.collapseIcon:t.expandIcon,g.appendChild(p)}u.appendChild(g),u.appendChild(H("tbw-accordion-content",{id:`tbw-section-${c.id}`,role:"presentation"})),a.appendChild(u)}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 oo(){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 Ke(t){return!!(t?.header?.title||t?.header?.toolbarContents?.length||t?.toolPanels?.length||t?.headerContents?.length||t?.header?.lightDomContent?.length||t?.header?.hasToolButtonsContainer)}function Qe(t,e,o="☰"){const i=t?.header?.title??e.lightDomTitle??"",n=!!i,r=q(o),s=t?.header?.toolbarContents??[],l=[...e.toolbarContents.values()],a=new Set(s.map(h=>h.id)),c=[...s];for(const h of l)a.has(h.id)||c.push(h);const d=c.length>0,u=e.toolPanels.size>0,g=d&&u,f=[...c].sort((h,w)=>(h.order??0)-(w.order??0));let p="";for(const h of f)p+=`<div class="tbw-toolbar-content-slot" data-toolbar-content="${h.id}"></div>`;if(g&&(p+='<div class="tbw-toolbar-separator"></div>'),u){const h=e.isPanelOpen;p+=`<button class="${h?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${h}" aria-controls="tbw-tool-panel">${r}</button>`}return`
19
+ `;function Qe(){return Ke.content.cloneNode(!0)}function Ze(t){const e=document.createDocumentFragment(),i=L(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=L("tbw-grid-content");o.appendChild(Qe()),i.appendChild(o)}return e.appendChild(i),e}function li(t){const e=L("tbw-shell-header",{part:"shell-header",role:"presentation"});if(t.title){const r=L("tbw-shell-title");r.textContent=t.title,e.appendChild(r)}const i=L("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});e.appendChild(i);const o=L("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const r of t.configButtons)r.hasRender&&o.appendChild(L("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));for(const r of t.apiButtons)r.hasRender&&o.appendChild(L("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(L("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 ai(t){const e=L("tbw-shell-body"),i=t.panels.length>0,o=t.panels.length===1,n=L("tbw-grid-content");n.appendChild(Qe());let r=null;if(i){r=ie("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(L("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":s,"aria-hidden":"true"}));const l=L("tbw-tool-panel-content",{role:"presentation"}),a=L("tbw-accordion");for(const c of t.panels){const d=`tbw-accordion-section${c.isExpanded?" expanded":""}${o?" single":""}`,u=L(d,{"data-section":c.id}),f=je("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(o&&f.setAttribute("aria-disabled","true"),c.icon){const p=ie("span",{class:"tbw-accordion-icon"});p.innerHTML=c.icon,f.appendChild(p)}const g=ie("span",{class:"tbw-accordion-title"});if(g.textContent=c.title,f.appendChild(g),!o){const p=ie("span",{class:"tbw-accordion-chevron"});p.innerHTML=c.isExpanded?t.collapseIcon:t.expandIcon,f.appendChild(p)}u.appendChild(f),u.appendChild(L("tbw-accordion-content",{id:`tbw-section-${c.id}`,role:"presentation"})),a.appendChild(u)}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 N(t){return t?typeof t=="string"?t:t.outerHTML:""}function ci(){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 Je(t){return!!(t?.header?.title||t?.header?.toolbarContents?.length||t?.toolPanels?.length||t?.headerContents?.length||t?.header?.lightDomContent?.length||t?.header?.hasToolButtonsContainer)}function di(t,e,i="☰"){const o=t?.header?.title??e.lightDomTitle??"",n=!!o,r=N(i),s=t?.header?.toolbarContents??[],l=[...e.toolbarContents.values()],a=new Set(s.map(h=>h.id)),c=[...s];for(const h of l)a.has(h.id)||c.push(h);const d=c.length>0,u=e.toolPanels.size>0,f=d&&u,g=[...c].sort((h,w)=>(h.order??0)-(w.order??0));let p="";for(const h of g)p+=`<div class="tbw-toolbar-content-slot" data-toolbar-content="${h.id}"></div>`;if(f&&(p+='<div class="tbw-toolbar-separator"></div>'),u){const h=e.isPanelOpen;p+=`<button class="${h?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${h}" 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">${gt(i)}</div>`:""}
21
+ ${n?`<div class="tbw-shell-title">${yt(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
  ${p}
25
25
  </div>
26
26
  </div>
27
- `}function F(t,e){const o=t.querySelector("tbw-grid-header");if(!o)return;if(!e.lightDomTitle){const n=o.getAttribute("title");n&&(e.lightDomTitle=n)}const i=o.querySelectorAll("tbw-grid-header-content");i.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(i)),o.style.display="none"}function U(t,e,o){const i=t.querySelector(":scope > tbw-grid-tool-buttons");if(!i)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(;i.firstChild;)s.appendChild(i.firstChild)})};e.toolbarContents.set(n,r),e.lightDomToolbarContentIds.add(n),i.style.display="none"}function G(t,e,o){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,d=parseInt(r.getAttribute("order")??"100",10);let u;const g=o?.(r);if(g)u=g;else{const h=r.innerHTML.trim();u=w=>{const C=document.createElement("div");return C.innerHTML=h,w.appendChild(C),()=>C.remove()}}const f=e.toolPanels.get(s);if(f){if(g){f.render=u,f.order=d,f.icon=a,f.tooltip=c;const h=e.panelCleanups.get(s);h&&(h(),e.panelCleanups.delete(s))}return}const p={id:s,title:l,icon:a,tooltip:c,order:d,render:u};e.toolPanels.set(s,p),e.lightDomToolPanelIds.add(s),r.style.display="none"})}function io(t,e,o,i){const n=t.querySelector(".tbw-shell-toolbar");n&&n.addEventListener("click",s=>{if(s.target.closest("[data-panel-toggle]")){i.onPanelToggle();return}});const r=t.querySelector(".tbw-accordion");r&&r.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const d=a.closest("[data-section]")?.getAttribute("data-section");d&&i.onSectionToggle(d)}})}function no(t,e,o){const i=t.querySelector(".tbw-tool-panel"),n=t.querySelector("[data-resize-handle]"),r=t.querySelector(".tbw-shell-body");if(!i||!n||!r)return()=>{};const s=e?.toolPanel?.position??"right",l=200;let a=0,c=0,d=0,u=!1;const g=h=>{if(!u)return;h.preventDefault();const w=s==="left"?h.clientX-a:a-h.clientX,C=Math.min(d,Math.max(l,c+w));i.style.width=`${C}px`},f=()=>{if(!u)return;u=!1,n.classList.remove("resizing"),i.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const h=i.getBoundingClientRect().width;o(h),document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",f)},p=h=>{h.preventDefault(),u=!0,a=h.clientX,c=i.getBoundingClientRect().width,d=r.getBoundingClientRect().width-20,n.classList.add("resizing"),i.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",g),document.addEventListener("mouseup",f)};return n.addEventListener("mousedown",p),()=>{n.removeEventListener("mousedown",p),document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",f)}}function Ze(t,e,o){const i=e?.header?.toolbarContents??[],n=[...o.toolbarContents.values()],r=new Set(i.map(l=>l.id)),s=[...i];for(const l of n)r.has(l.id)||s.push(l);for(const l of s){if(o.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&&o.toolbarContentCleanups.set(l.id,c)}}function fe(t,e){const o=e.lightDomHeaderContent.length>0&&!e.lightDomContentMoved,i=e.headerContents.size>0;if(!o&&!i)return;const n=t.querySelector(".tbw-shell-content");if(!n)return;if(o){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 ro(t,e,o){if(!e.isPanelOpen)return;const i=q(o?.expand??M.expand),n=q(o?.collapse??M.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 d=a.querySelector(".tbw-accordion-header");d&&d.setAttribute("aria-expanded",String(l));const u=a.querySelector(".tbw-accordion-chevron");if(u&&(u.innerHTML=l?n:i),l){if(c.children.length===0){const g=s.render(c);g&&e.panelCleanups.set(r,g)}}else{const g=e.panelCleanups.get(r);g&&(g(),e.panelCleanups.delete(r)),c.innerHTML=""}}}function Je(t,e){const o=t.querySelector("[data-panel-toggle]");o&&(o.classList.toggle("active",e.isPanelOpen),o.setAttribute("aria-pressed",String(e.isPanelOpen)))}function et(t,e){const o=t.querySelector(".tbw-tool-panel");o&&(o.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(o.style.width=""))}function so(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 lo(t,e){let o=!1;const i={get isInitialized(){return o},setInitialized(n){o=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();Je(n,t),et(n,t),ro(n,t,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:i.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();Je(n,t),et(n,t),e.emit("tool-panel-close",{})},toggleToolPanel(){t.isPanelOpen?i.closeToolPanel():i.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),ge(s,n,!1)}else{for(const[a,c]of t.toolPanels)if(a!==n&&t.expandedSections.has(a)){const d=t.panelCleanups.get(a);d&&(d(),t.panelCleanups.delete(a)),c.onClose?.(),t.expandedSections.delete(a),ge(s,a,!1);const u=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);u&&(u.innerHTML="")}t.expandedSections.add(n),ge(s,n,!0),ao(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),o&&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),o&&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),o&&fe(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),o&&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),o&&e.refreshShellHeader()}};return i}function ge(t,e,o){const i=t.querySelector(`[data-section="${e}"]`);i&&i.classList.toggle("expanded",o)}function ao(t,e,o){const i=e.toolPanels.get(o);if(!i?.render)return;const n=t.querySelector(`[data-section="${o}"] .tbw-accordion-content`);if(!n)return;const r=i.render(n);r&&e.panelCleanups.set(o,r)}function co(t,e,o,i){const n=Ke(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(i?.toolPanel??M.toolPanel),a=q(i?.expand??M.expand),c=q(i?.collapse??M.collapse),u=[...e?.header?.toolbarContents??[]].sort((y,E)=>(y.order??0)-(E.order??0)),f=[...e?.toolPanels??[]].sort((y,E)=>(y.order??100)-(E.order??100)),p={title:e?.header?.title??void 0,hasPanels:f.length>0,isPanelOpen:o.isPanelOpen,toolPanelIcon:l,configButtons:u.map(y=>({id:y.id,hasElement:!1,hasRender:!!y.render})),apiButtons:[]},h={position:e?.toolPanel?.position??"right",isPanelOpen:o.isPanelOpen,expandIcon:a,collapseIcon:c,panels:f.map(y=>({id:y.id,title:y.title,icon:q(y.icon),isExpanded:o.expandedSections.has(y.id)}))},w=eo(p),C=to(h),R=je({hasShell:!0,shellHeader:w,shellBody:C});t.appendChild(R)}else{const l=je({hasShell:!1});t.appendChild(l)}return n}const tt="tbw-grid-styles";let ne="";const pe=new Map;function ho(){let t=document.getElementById(tt);return t||(t=document.createElement("style"),t.id=tt,t.setAttribute("data-tbw-grid","true"),document.head.appendChild(t)),t}function we(){const t=ho(),e=Array.from(pe.values()).join(`
28
- `);t.textContent=`${ne}
27
+ `}function et(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 tt(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 it(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,d=parseInt(r.getAttribute("order")??"100",10);let u;const f=i?.(r);if(f)u=f;else{const h=r.innerHTML.trim();u=w=>{const C=document.createElement("div");return C.innerHTML=h,w.appendChild(C),()=>C.remove()}}const g=e.toolPanels.get(s);if(g){if(f){g.render=u,g.order=d,g.icon=a,g.tooltip=c;const h=e.panelCleanups.get(s);h&&(h(),e.panelCleanups.delete(s))}return}const p={id:s,title:l,icon:a,tooltip:c,order:d,render:u};e.toolPanels.set(s,p),e.lightDomToolPanelIds.add(s),r.style.display="none"})}function hi(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 d=a.closest("[data-section]")?.getAttribute("data-section");d&&o.onSectionToggle(d)}})}function ui(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,d=0,u=!1;const f=h=>{if(!u)return;h.preventDefault();const w=s==="left"?h.clientX-a:a-h.clientX,C=Math.min(d,Math.max(l,c+w));o.style.width=`${C}px`},g=()=>{if(!u)return;u=!1,n.classList.remove("resizing"),o.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const h=o.getBoundingClientRect().width;i(h),document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g)},p=h=>{h.preventDefault(),u=!0,a=h.clientX,c=o.getBoundingClientRect().width,d=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",f),document.addEventListener("mouseup",g)};return n.addEventListener("mousedown",p),()=>{n.removeEventListener("mousedown",p),document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g)}}function fe(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 ge(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 fi(t,e,i){if(!e.isPanelOpen)return;const o=N(i?.expand??O.expand),n=N(i?.collapse??O.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 d=a.querySelector(".tbw-accordion-header");d&&d.setAttribute("aria-expanded",String(l));const u=a.querySelector(".tbw-accordion-chevron");if(u&&(u.innerHTML=l?n:o),l){if(c.children.length===0){const f=s.render(c);f&&e.panelCleanups.set(r,f)}}else{const f=e.panelCleanups.get(r);f&&(f(),e.panelCleanups.delete(r)),c.innerHTML=""}}}function ot(t,e){const i=t.querySelector("[data-panel-toggle]");i&&(i.classList.toggle("active",e.isPanelOpen),i.setAttribute("aria-pressed",String(e.isPanelOpen)))}function nt(t,e){const i=t.querySelector(".tbw-tool-panel");i&&(i.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(i.style.width=""))}function pe(t){for(const e of t.toolbarContentCleanups.values())e();t.toolbarContentCleanups.clear()}function gi(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 pi(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();ot(n,t),nt(n,t),fi(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();ot(n,t),nt(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),we(s,n,!1)}else{for(const[a,c]of t.toolPanels)if(a!==n&&t.expandedSections.has(a)){const d=t.panelCleanups.get(a);d&&(d(),t.panelCleanups.delete(a)),c.onClose?.(),t.expandedSections.delete(a),we(s,a,!1);const u=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);u&&(u.innerHTML="")}t.expandedSections.add(n),we(s,n,!0),wi(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&&ge(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 we(t,e,i){const o=t.querySelector(`[data-section="${e}"]`);o&&o.classList.toggle("expanded",i)}function wi(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 bi(t,e,i,o){const n=Je(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=N(o?.toolPanel??O.toolPanel),a=N(o?.expand??O.expand),c=N(o?.collapse??O.collapse),u=[...e?.header?.toolbarContents??[]].sort((_,S)=>(_.order??0)-(S.order??0)),g=[...e?.toolPanels??[]].sort((_,S)=>(_.order??100)-(S.order??100)),p={title:e?.header?.title??void 0,hasPanels:g.length>0,isPanelOpen:i.isPanelOpen,toolPanelIcon:l,configButtons:u.map(_=>({id:_.id,hasElement:!1,hasRender:!!_.render})),apiButtons:[]},h={position:e?.toolPanel?.position??"right",isPanelOpen:i.isPanelOpen,expandIcon:a,collapseIcon:c,panels:g.map(_=>({id:_.id,title:_.title,icon:N(_.icon),isExpanded:i.expandedSections.has(_.id)}))},w=li(p),C=ai(h),m=Ze({hasShell:!0,shellHeader:w,shellBody:C});t.appendChild(m)}else{const l=Ze({hasShell:!1});t.appendChild(l)}return n}const rt="tbw-grid-styles";let oe="";const be=new Map;function mi(){let t=document.getElementById(rt);return t||(t=document.createElement("style"),t.id=rt,t.setAttribute("data-tbw-grid","true"),document.head.appendChild(t)),t}function me(){const t=mi(),e=Array.from(be.values()).join(`
28
+ `);t.textContent=`${oe}
29
29
 
30
30
  /* Plugin Styles */
31
- ${e}`}function uo(t){let e=!1;for(const{name:o,styles:i}of t)pe.has(o)||(pe.set(o,i),e=!0);return e&&we(),e}function fo(){try{for(const t of Array.from(document.styleSheets))try{const o=Array.from(t.cssRules||[]).map(i=>i.cssText).join(`
32
- `);if(o.includes(".tbw-grid-root")&&o.includes("tbw-grid"))return o}catch{continue}}catch(t){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",t)}return null}async function go(t){if(ne)return;if(typeof t=="string"&&t.length>0){ne=t,we();return}await new Promise(o=>setTimeout(o,50));const e=fo();e?(ne=e,we()):(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(o=>o.href||"(inline)"))}function po(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function wo(t){t.startY=null,t.startX=null,t.scrollTop=null,t.scrollLeft=null,t.lastY=null,t.lastX=null,t.lastTime=null}function ot(t){t.momentumRaf&&(cancelAnimationFrame(t.momentumRaf),t.momentumRaf=0)}function bo(t,e,o){if(t.touches.length!==1)return;ot(e);const i=t.touches[0];e.startY=i.clientY,e.startX=i.clientX,e.lastY=i.clientY,e.lastX=i.clientX,e.lastTime=performance.now(),e.scrollTop=o.fauxScrollbar.scrollTop,e.scrollLeft=o.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function mo(t,e,o){if(t.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const i=t.touches[0],n=i.clientY,r=i.clientX,s=performance.now(),l=e.startY-n,a=e.startX-r;if(e.lastTime!==null&&e.lastY!==null&&e.lastX!==null){const h=s-e.lastTime;h>0&&(e.velocityY=(e.lastY-n)/h,e.velocityX=(e.lastX-r)/h)}e.lastY=n,e.lastX=r,e.lastTime=s;const{scrollTop:c,scrollHeight:d,clientHeight:u}=o.fauxScrollbar,g=d-u,f=l>0&&c<g||l<0&&c>0;let p=!1;if(o.scrollArea){const{scrollLeft:h,scrollWidth:w,clientWidth:C}=o.scrollArea,R=w-C;p=a>0&&h<R||a<0&&h>0}return f&&(o.fauxScrollbar.scrollTop=e.scrollTop+l),p&&o.scrollArea&&(o.scrollArea.scrollLeft=e.scrollLeft+a),f||p}function vo(t,e){(Math.abs(t.velocityY)>.1||Math.abs(t.velocityX)>.1)&&Co(t,e),wo(t)}function Co(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 yo(t,e,o,i){t.addEventListener("touchstart",n=>bo(n,e,o),{passive:!0,signal:i}),t.addEventListener("touchmove",n=>{mo(n,e,o)&&n.preventDefault()},{passive:!1,signal:i}),t.addEventListener("touchend",()=>vo(e,o),{passive:!0,signal:i})}const _o=[{property:"editable",pluginName:"editing",level:"column",description:'the "editable" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",isUsed:t=>t===!0},{property:"editor",pluginName:"editing",level:"column",description:'the "editor" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"editorParams",pluginName:"editing",level:"column",description:'the "editorParams" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"group",pluginName:"groupingColumns",level:"column",description:'the "group" column property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';"},{property:"sticky",pluginName:"pinnedColumns",level:"column",description:'the "sticky" column property',importHint:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",isUsed:t=>t==="left"||t==="right"||t==="start"||t==="end"}],Eo=[{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:'the "columnGroups" config property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",isUsed:t=>Array.isArray(t)&&t.length>0}],So={editing:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",selection:"import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';",reorder:"import { ReorderPlugin } from '@toolbox-web/grid/plugins/reorder';",clipboard:"import { ClipboardPlugin } from '@toolbox-web/grid/plugins/clipboard';",filtering:"import { FilteringPlugin } from '@toolbox-web/grid/plugins/filtering';",multiSort:"import { MultiSortPlugin } from '@toolbox-web/grid/plugins/multi-sort';",groupingRows:"import { GroupingRowsPlugin } from '@toolbox-web/grid/plugins/grouping-rows';",groupingColumns:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",tree:"import { TreePlugin } from '@toolbox-web/grid/plugins/tree';",masterDetail:"import { MasterDetailPlugin } from '@toolbox-web/grid/plugins/master-detail';",pinnedColumns:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",pinnedRows:"import { PinnedRowsPlugin } from '@toolbox-web/grid/plugins/pinned-rows';",visibility:"import { VisibilityPlugin } from '@toolbox-web/grid/plugins/visibility';",undoRedo:"import { UndoRedoPlugin } from '@toolbox-web/grid/plugins/undo-redo';",export:"import { ExportPlugin } from '@toolbox-web/grid/plugins/export';",contextMenu:"import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';",pivot:"import { PivotPlugin } from '@toolbox-web/grid/plugins/pivot';",serverSide:"import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';",columnVirtualization:"import { ColumnVirtualizationPlugin } from '@toolbox-web/grid/plugins/column-virtualization';"};function be(t){return So[t]??`import { ${N(t)}Plugin } from '@toolbox-web/grid/plugins/${t}';`}function it(){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 N(t){return t.charAt(0).toUpperCase()+t.slice(1)}function nt(t,e){return t.some(o=>o.name===e)}function Ro(t,e){const o=_o,i=Eo,n=new Map;function r(l,a,c,d,u=!1){n.has(l)||n.set(l,{description:a,importHint:c,fields:[],isConfigProperty:u});const g=n.get(l);g.fields.includes(d)||g.fields.push(d)}for(const l of i){const a=t[l.property];(l.isUsed?l.isUsed(a):a!==void 0)&&!nt(e,l.pluginName)&&r(l.pluginName,l.description,l.importHint??be(l.pluginName),l.property,!0)}const s=t.columns;if(s&&s.length>0)for(const l of s)for(const a of o){const c=l[a.property];if((a.isUsed?a.isUsed(c):c!==void 0)&&!nt(e,a.pluginName)){const u=l.field||"<unknown>";r(a.pluginName,a.description,a.importHint??be(a.pluginName),u)}}if(n.size>0){const l=[];for(const[a,{description:c,importHint:d,fields:u,isConfigProperty:g}]of n)if(g)l.push(`Config uses ${c}, but the required plugin is not loaded.
31
+ ${e}`}function vi(t){let e=!1;for(const{name:i,styles:o}of t)be.has(i)||(be.set(i,o),e=!0);return e&&me(),e}function Ci(){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 yi(t){if(oe)return;if(typeof t=="string"&&t.length>0){oe=t,me();return}await new Promise(i=>setTimeout(i,50));const e=Ci();e?(oe=e,me()):(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 _i(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function Ei(t){t.startY=null,t.startX=null,t.scrollTop=null,t.scrollLeft=null,t.lastY=null,t.lastX=null,t.lastTime=null}function st(t){t.momentumRaf&&(cancelAnimationFrame(t.momentumRaf),t.momentumRaf=0)}function Si(t,e,i){if(t.touches.length!==1)return;st(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 Ri(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 h=s-e.lastTime;h>0&&(e.velocityY=(e.lastY-n)/h,e.velocityX=(e.lastX-r)/h)}e.lastY=n,e.lastX=r,e.lastTime=s;const{scrollTop:c,scrollHeight:d,clientHeight:u}=i.fauxScrollbar,f=d-u,g=l>0&&c<f||l<0&&c>0;let p=!1;if(i.scrollArea){const{scrollLeft:h,scrollWidth:w,clientWidth:C}=i.scrollArea,m=w-C;p=a>0&&h<m||a<0&&h>0}return g&&(i.fauxScrollbar.scrollTop=e.scrollTop+l),p&&i.scrollArea&&(i.scrollArea.scrollLeft=e.scrollLeft+a),g||p}function Ai(t,e){(Math.abs(t.velocityY)>.1||Math.abs(t.velocityX)>.1)&&Ti(t,e),Ei(t)}function Ti(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 xi(t,e,i,o){t.addEventListener("touchstart",n=>Si(n,e,i),{passive:!0,signal:o}),t.addEventListener("touchmove",n=>{Ri(n,e,i)&&n.preventDefault()},{passive:!1,signal:o}),t.addEventListener("touchend",()=>Ai(e,i),{passive:!0,signal:o})}const Hi=[{property:"editable",pluginName:"editing",level:"column",description:'the "editable" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",isUsed:t=>t===!0},{property:"editor",pluginName:"editing",level:"column",description:'the "editor" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"editorParams",pluginName:"editing",level:"column",description:'the "editorParams" column property',importHint:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';"},{property:"group",pluginName:"groupingColumns",level:"column",description:'the "group" column property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';"},{property:"sticky",pluginName:"pinnedColumns",level:"column",description:'the "sticky" column property',importHint:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",isUsed:t=>t==="left"||t==="right"||t==="start"||t==="end"}],Pi=[{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:'the "columnGroups" config property',importHint:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",isUsed:t=>Array.isArray(t)&&t.length>0}],Li={editing:"import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';",selection:"import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';",reorder:"import { ReorderPlugin } from '@toolbox-web/grid/plugins/reorder';",clipboard:"import { ClipboardPlugin } from '@toolbox-web/grid/plugins/clipboard';",filtering:"import { FilteringPlugin } from '@toolbox-web/grid/plugins/filtering';",multiSort:"import { MultiSortPlugin } from '@toolbox-web/grid/plugins/multi-sort';",groupingRows:"import { GroupingRowsPlugin } from '@toolbox-web/grid/plugins/grouping-rows';",groupingColumns:"import { GroupingColumnsPlugin } from '@toolbox-web/grid/plugins/grouping-columns';",tree:"import { TreePlugin } from '@toolbox-web/grid/plugins/tree';",masterDetail:"import { MasterDetailPlugin } from '@toolbox-web/grid/plugins/master-detail';",pinnedColumns:"import { PinnedColumnsPlugin } from '@toolbox-web/grid/plugins/pinned-columns';",pinnedRows:"import { PinnedRowsPlugin } from '@toolbox-web/grid/plugins/pinned-rows';",visibility:"import { VisibilityPlugin } from '@toolbox-web/grid/plugins/visibility';",undoRedo:"import { UndoRedoPlugin } from '@toolbox-web/grid/plugins/undo-redo';",export:"import { ExportPlugin } from '@toolbox-web/grid/plugins/export';",contextMenu:"import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';",pivot:"import { PivotPlugin } from '@toolbox-web/grid/plugins/pivot';",serverSide:"import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';",columnVirtualization:"import { ColumnVirtualizationPlugin } from '@toolbox-web/grid/plugins/column-virtualization';"};function ve(t){return Li[t]??`import { ${M(t)}Plugin } from '@toolbox-web/grid/plugins/${t}';`}function M(t){return t.charAt(0).toUpperCase()+t.slice(1)}function lt(t,e){return t.some(i=>i.name===e)}function zi(t,e){const i=Hi,o=Pi,n=new Map;function r(l,a,c,d,u=!1){n.has(l)||n.set(l,{description:a,importHint:c,fields:[],isConfigProperty:u});const f=n.get(l);f.fields.includes(d)||f.fields.push(d)}for(const l of o){const a=t[l.property];(l.isUsed?l.isUsed(a):a!==void 0)&&!lt(e,l.pluginName)&&r(l.pluginName,l.description,l.importHint??ve(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)&&!lt(e,a.pluginName)){const u=l.field||"<unknown>";r(a.pluginName,a.description,a.importHint??ve(a.pluginName),u)}}if(n.size>0){const l=[];for(const[a,{description:c,importHint:d,fields:u,isConfigProperty:f}]of n)if(f)l.push(`Config uses ${c}, but the required plugin is not loaded.
33
33
  → Add the plugin to your gridConfig.plugins array:
34
34
  ${d}
35
- plugins: [new ${a.charAt(0).toUpperCase()+a.slice(1)}Plugin(), ...]`);else{const f=u.slice(0,3).join(", ")+(u.length>3?`, ... (${u.length} total)`:"");l.push(`Column(s) [${f}] use ${c}, but the required plugin is not loaded.
35
+ plugins: [new ${a.charAt(0).toUpperCase()+a.slice(1)}Plugin(), ...]`);else{const g=u.slice(0,3).join(", ")+(u.length>3?`, ... (${u.length} total)`:"");l.push(`Column(s) [${g}] use ${c}, but the required plugin is not loaded.
36
36
  → Add the plugin to your gridConfig.plugins array:
37
37
  ${d}
38
38
  plugins: [new ${a.charAt(0).toUpperCase()+a.slice(1)}Plugin(), ...]`)}throw new Error(`[tbw-grid] Configuration error:
@@ -41,23 +41,25 @@ ${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 Ao(t){const e=[],o=[];for(const i of t){const r=i.constructor.manifest;if(r?.configRules)for(const s of r.configRules){const l=i.config;if(s.check(l)){const c=`${`[tbw-grid:${N(i.name)}Plugin]`} Configuration warning: ${s.message}`;s.severity==="error"?e.push(c):o.push(c)}}}if(o.length>0&&it())for(const i of o)console.warn(i);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 Di(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:${M(o.name)}Plugin]`} Configuration warning: ${s.message}`;s.severity==="error"?e.push(c):i.push(c)}}}if(i.length>0&&re())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 To(t,e){const o=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(d=>d.name===s)){const d=a??`${N(o)}Plugin requires ${N(s)}Plugin`,u=be(s);if(l)throw new Error(`[tbw-grid] Plugin dependency error:
48
+ `)}`)}function Oi(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(d=>d.name===s)){const d=a??`${M(i)}Plugin requires ${M(s)}Plugin`,u=ve(s);if(l)throw new Error(`[tbw-grid] Plugin dependency error:
49
49
 
50
50
  ${d}.
51
51
 
52
- → Add the plugin to your gridConfig.plugins array BEFORE ${N(o)}Plugin:
52
+ → Add the plugin to your gridConfig.plugins array BEFORE ${M(i)}Plugin:
53
53
  ${u}
54
- plugins: [new ${N(s)}Plugin(), new ${N(o)}Plugin()]`);console.info(`[tbw-grid] ${N(o)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}function xo(t){if(!it())return;const e=new Set(t.map(i=>i.name)),o=new Set;for(const i of t){const r=i.constructor.manifest;if(r?.incompatibleWith){for(const s of r.incompatibleWith)if(e.has(s.name)){const l=[i.name,s.name].sort().join("↔");if(o.has(l))continue;o.add(l),console.warn(`[tbw-grid] Plugin incompatibility warning:
54
+ plugins: [new ${M(s)}Plugin(), new ${M(i)}Plugin()]`);console.info(`[tbw-grid] ${M(i)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}function Mi(t){if(!re())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
- ${N(i.name)}Plugin and ${N(s.name)}Plugin are both loaded, but they are currently incompatible.
56
+ ${M(o.name)}Plugin and ${M(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.`)}}}}class rt{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;attachAll(e){for(const o of e)this.attach(o)}attach(e){if(To(e,this.plugins),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[o,i]of Object.entries(e.cellRenderers))this.cellRenderers.set(o,i);if(e.headerRenderers)for(const[o,i]of Object.entries(e.headerRenderers))this.headerRenderers.set(o,i);if(e.cellEditors)for(const[o,i]of Object.entries(e.cellEditors))this.cellEditors.set(o,i);this.registerQueryHandlers(e),e.attach(this.grid);for(const o of this.plugins)o!==e&&o.onPluginAttached&&o.onPluginAttached(e.name,e)}registerQueryHandlers(e){const i=e.constructor.manifest;if(i?.queries)for(const n of i.queries){let r=this.queryHandlers.get(n.type);r||(r=new Set,this.queryHandlers.set(n.type,r)),r.add(e)}}unregisterQueryHandlers(e){for(const[o,i]of this.queryHandlers)i.delete(e),i.size===0&&this.queryHandlers.delete(o)}detachAll(){for(const e of this.plugins)for(const o of this.plugins)o!==e&&o.onPluginDetached&&o.onPluginDetached(e.name);for(let e=this.plugins.length-1;e>=0;e--){const o=this.plugins[e];this.unsubscribeAll(o),this.unregisterQueryHandlers(o),o.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(o=>o.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 o=[...e];for(const i of this.plugins)i.processRows&&(o=i.processRows(o));return o}processColumns(e){let o=[...e];for(const i of this.plugins)i.processColumns&&(o=i.processColumns(o));return o}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}afterCellRender(e){for(const o of this.plugins)o.afterCellRender?.(e)}hasAfterCellRenderHook(){return this.plugins.some(e=>typeof e.afterCellRender=="function")}afterRowRender(e){for(const o of this.plugins)o.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 o of this.plugins)typeof o.getExtraHeight=="function"&&(e+=o.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 o=0;for(const i of this.plugins)typeof i.getExtraHeightBefore=="function"&&(o+=i.getExtraHeightBefore(e));return o}adjustVirtualStart(e,o,i){let n=e;for(const r of this.plugins)if(typeof r.adjustVirtualStart=="function"){const s=r.adjustVirtualStart(e,o,i);s<n&&(n=s)}return n}renderRow(e,o,i){for(const n of this.plugins)if(n.renderRow?.(e,o,i))return!0;return!1}queryPlugins(e){const o=[],i=this.queryHandlers.get(e.type);if(i&&i.size>0){for(const n of i){const r=n.handleQuery?.(e)??n.onPluginQuery?.(e);r!==void 0&&o.push(r)}return o}for(const n of this.plugins){const r=n.handleQuery?.(e)??n.onPluginQuery?.(e);r!==void 0&&o.push(r)}return o}subscribe(e,o,i){let n=this.eventListeners.get(o);n||(n=new Map,this.eventListeners.set(o,n)),n.set(e,i)}unsubscribe(e,o){const i=this.eventListeners.get(o);i&&(i.delete(e),i.size===0&&this.eventListeners.delete(o))}unsubscribeAll(e){for(const[o,i]of this.eventListeners)i.delete(e),i.size===0&&this.eventListeners.delete(o)}emitPluginEvent(e,o){const i=this.eventListeners.get(e);if(i)for(const n of i.values())try{n(o)}catch(r){console.error(`[tbw-grid] Error in plugin event handler for "${e}":`,r)}}onKeyDown(e){for(const o of this.plugins)if(o.onKeyDown?.(e))return!0;return!1}onCellClick(e){for(const o of this.plugins)if(o.onCellClick?.(e))return!0;return!1}onRowClick(e){for(const o of this.plugins)if(o.onRowClick?.(e))return!0;return!1}onHeaderClick(e){for(const o of this.plugins)if(o.onHeaderClick?.(e))return!0;return!1}onScroll(e){for(const o of this.plugins)o.onScroll?.(e)}onCellMouseDown(e){for(const o of this.plugins)if(o.onCellMouseDown?.(e))return!0;return!1}onCellMouseMove(e){for(const o of this.plugins)if(o.onCellMouseMove?.(e))return!0;return!1}onCellMouseUp(e){for(const o of this.plugins)if(o.onCellMouseUp?.(e))return!0;return!1}getHorizontalScrollOffsets(e,o){let i=0,n=0,r=!1;for(const s of this.plugins){const l=s.getHorizontalScrollOffsets?.(e,o);l&&(i+=l.left,n+=l.right,l.skipScroll&&(r=!0))}return{left:i,right:n,skipScroll:r}}getToolPanels(){const e=[];for(const o of this.plugins){const i=o.getToolPanel?.();i&&e.push({plugin:o,panel:i})}return e.sort((o,i)=>(o.panel.order??0)-(i.panel.order??0))}getHeaderContents(){const e=[];for(const o of this.plugins){const i=o.getHeaderContent?.();i&&e.push({plugin:o,content:i})}return e.sort((o,i)=>(o.content.order??0)-(i.content.order??0))}}const Po=`/**
60
+ Consider removing one of these plugins to avoid unexpected behavior.`)}}}}function at(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 ki(t,e,i){const o=at(e,i);if(typeof o=="string")return t.byKey.get(o);if(o&&typeof o=="object")return t.byRef.get(o)}function Ii(t,e,i,o){const n=at(e,o);typeof n=="string"?t.byKey.set(n,i):n&&typeof n=="object"&&t.byRef.set(n,i)}function Ni(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),d=c!==void 0;c===void 0&&(c=ki(e,a,o.rowId),d=c!==void 0),c===void 0&&(c=i,d=!1),r[l]={offset:s,height:c,measured:d},s+=c}return r}function Ce(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 qi(t){if(t.length===0)return 0;const e=t[t.length-1];return e.offset+e.height}function ct(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 $i(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 Wi(t){let e=0;for(const i of t)i.measured&&e++;return e}function Fi(t,e){const{positionCache:i,heightCache:o,rows:n,start:r,end:s,getPluginHeight:l,getRowId:a}=t;let c=!1;e.forEach(f=>{const g=f.dataset.rowIndex;if(!g)return;const p=parseInt(g,10);if(p<r||p>=s||p>=n.length)return;const h=n[p],w=l?.(h,p);if(w!==void 0){const m=i[p];(!m.measured||Math.abs(m.height-w)>1)&&(Ce(i,p,w),c=!0);return}const C=f.offsetHeight;if(C>0){const m=i[p];(!m.measured||Math.abs(m.height-C)>1)&&(Ce(i,p,C),Ii(o,h,C,a),c=!0)}});const d=c?Wi(i):0,u=c?$i(i,t.defaultHeight):0;return{hasChanges:c,measuredCount:d,averageHeight:u}}function Ui(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 B{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(Oi(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(B.deprecationWarned.has(i)||!re())return;const o=typeof e.getExtraHeight=="function"||typeof e.getExtraHeightBefore=="function",n=typeof e.getRowHeight=="function";o&&!n&&(B.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
+ → Migrate to getRowHeight(row, index) for better variable row height support.
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 Vi=`/**
61
63
  * tbw-grid Light DOM Styles
62
64
  *
63
65
  * This stylesheet uses CSS nesting to scope all styles to the tbw-grid element.
@@ -79,11 +81,11 @@ ${N(i.name)}Plugin and ${N(s.name)}Plugin are both loaded, but they are currentl
79
81
  @layer tbw-base{tbw-grid{--tbw-base-icon-size: 1em;--tbw-base-radius: .25em;--tbw-font-size: 1em;--tbw-font-size-sm: .9285em;--tbw-font-size-xs: .7857em;--tbw-font-size-2xs: .7142em;--tbw-spacing-xs: .25em;--tbw-spacing-sm: .375em;--tbw-spacing-md: .5em;--tbw-spacing-lg: .75em;--tbw-spacing-xl: 1em;--tbw-icon-size: var(--tbw-base-icon-size);--tbw-icon-size-sm: .875em;--tbw-checkbox-size: var(--tbw-base-icon-size);--tbw-toggle-size: 1.25em;--tbw-border-radius: var(--tbw-base-radius);--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-warning: light-dark(hsl(38, 92%, 50%), hsl(38, 92%, 50%));--tbw-color-error: light-dark(hsl(0, 65%, 51%), hsl(0, 65%, 55%));--tbw-color-danger: var(--tbw-color-error);--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #666666);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding-input: var(--tbw-spacing-xs) var(--tbw-spacing-sm);--tbw-row-height: 1.75em;--tbw-header-height: 1.875em;--tbw-cell-white-space: nowrap;--tbw-border-input: 1px solid var(--tbw-color-border-strong);--tbw-border-header: 1px solid var(--tbw-color-border-header);--tbw-row-divider: 1px solid var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline: 2px solid var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: var(--tbw-spacing-sm);--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-resize-indicator-width: 2px;--tbw-resize-indicator-color: var(--tbw-color-accent);--tbw-resize-indicator-opacity: .6;--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-animation-duration: .2s;--tbw-animation-easing: ease-out;--tbw-animation-enabled: 1;--tbw-row-change-duration: .5s;--tbw-row-insert-duration: .3s;--tbw-row-remove-duration: .2s;--tbw-row-change-color: rgba(from var(--tbw-color-accent) r g b / 25%);--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-sort-indicator-display: inline-flex;--tbw-sort-indicator-visibility: visible;--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-density-scale: 1;--tbw-shell-header-height: 2.75em;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: var(--tbw-font-size);--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 17.5em;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 2.5em;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--tbw-toolbar-button-size: 2em;--tbw-toolbar-button-gap: var(--tbw-spacing-xs);--tbw-panel-padding: var(--tbw-spacing-lg);--tbw-panel-gap: var(--tbw-spacing-md);--tbw-menu-item-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-menu-item-gap: var(--tbw-spacing-md);--tbw-menu-min-width: 10rem;--tbw-button-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-button-padding-sm: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-input-height: var(--tbw-row-height);--tbw-input-padding: 0 var(--tbw-spacing-md);--tbw-detail-padding: var(--tbw-spacing-xl);--tbw-detail-max-height: 31.25rem;--tbw-indicator-size: var(--tbw-spacing-sm)}}
80
82
  @layer tbw-base{tbw-grid{color-scheme:inherit;position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);font-feature-settings:"tnum","lnum";background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}tbw-grid,tbw-grid *{box-sizing:border-box}tbw-grid .tbw-grid-root{position:relative;display:flex;flex-direction:column;height:100%}tbw-grid .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}tbw-grid .tbw-grid-root:has(.selected){-webkit-user-select:none;user-select:none}tbw-grid .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}tbw-grid .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}tbw-grid .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}tbw-grid .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}tbw-grid .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}tbw-grid .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30)}tbw-grid .faux-vscroll-spacer{width:1px}tbw-grid[data-has-focus] .cell-focus,tbw-grid[data-has-focus] .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}tbw-grid .sticky-left,tbw-grid .sticky-right{position:sticky;z-index:25}tbw-grid .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}tbw-grid .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}}
81
83
  @layer tbw-base{tbw-grid .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}tbw-grid .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}tbw-grid .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}tbw-grid .header-group-cell:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30);text-transform:var(--tbw-header-text-transform);letter-spacing:var(--tbw-header-letter-spacing)}tbw-grid .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:visible;min-width:0}tbw-grid .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:inherit}tbw-grid .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0;opacity:.6;color:var(--tbw-sort-indicator-color);display:var(--tbw-sort-indicator-display, inline-flex);visibility:var(--tbw-sort-indicator-visibility, visible);transition:opacity .15s,visibility 0s,display 0s allow-discrete;transition-behavior:allow-discrete}tbw-grid .header-row>.cell:hover>span[part~=sort-indicator]{display:inline-flex;visibility:visible}tbw-grid .header-row>.cell[aria-sort=ascending]>span[part~=sort-indicator],tbw-grid .header-row>.cell[aria-sort=descending]>span[part~=sort-indicator]{display:inline-flex;visibility:visible;opacity:1;color:var(--tbw-sort-indicator-active-color)}tbw-grid .header-row>.cell:last-child{border-right:0}tbw-grid .header-row>.cell:last-child .resize-handle{right:0;width:calc(var(--tbw-resize-handle-width) / 2)}tbw-grid .header-row>.cell.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .header-row>.cell.resizable{position:relative}tbw-grid .header-row>.cell.sticky-left,tbw-grid .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}tbw-grid .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}tbw-grid .resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-handle-width) / -2);width:var(--tbw-resize-handle-width);height:100%;cursor:e-resize;-webkit-user-select:none;user-select:none;touch-action:none;z-index:20;background:var(--tbw-resize-handle-color);transition:background .12s ease;border-radius:var(--tbw-resize-handle-border-radius)}tbw-grid .resize-handle:after{content:"";position:absolute;top:100%;left:50%;transform:translate(-50%);width:var(--tbw-resize-indicator-width, 2px);height:0;background:var(--tbw-resize-indicator-color, var(--tbw-color-accent));opacity:0;pointer-events:none;transition:opacity .12s ease,height 0s .12s;z-index:1000}tbw-grid .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}tbw-grid .resize-handle:hover:after{height:100vh;opacity:var(--tbw-resize-indicator-opacity, .6);transition:opacity .12s ease,height 0s}}
82
- @layer tbw-base{tbw-grid .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style;content-visibility:auto;contain-intrinsic-size:auto var(--tbw-row-height)}tbw-grid .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid .data-grid-row:hover{background:var(--tbw-color-row-hover)}tbw-grid .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}tbw-grid .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}tbw-grid .data-grid-row>.cell:last-child{border-right:0}tbw-grid .data-grid-row>.cell[data-type=boolean]{text-align:center}tbw-grid .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}tbw-grid .data-grid-row>.cell.selected:focus-visible,tbw-grid .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}tbw-grid .data-grid-row>.cell.sticky-left,tbw-grid .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}tbw-grid .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}}
84
+ @layer tbw-base{tbw-grid .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}tbw-grid .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid .data-grid-row:hover{background:var(--tbw-color-row-hover)}tbw-grid .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}tbw-grid .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}tbw-grid .data-grid-row>.cell:last-child{border-right:0}tbw-grid .data-grid-row>.cell[data-type=boolean]{text-align:center}tbw-grid .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}tbw-grid .data-grid-row>.cell.selected:focus-visible,tbw-grid .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}tbw-grid .data-grid-row>.cell.sticky-left,tbw-grid .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}tbw-grid .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}}
83
85
  @layer tbw-base{tbw-grid .tbw-shell-header{display:flex;align-items:center;gap:8px;min-height:var(--tbw-shell-header-height);padding:0 8px;background:var(--tbw-shell-header-bg);border-bottom:1px solid var(--tbw-shell-header-border);flex-shrink:0}tbw-grid .tbw-shell-title{font-size:var(--tbw-shell-title-font-size);font-weight:var(--tbw-shell-title-font-weight);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}tbw-grid .tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}tbw-grid .tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}tbw-grid .tbw-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toolbar-button-size);height:var(--tbw-toolbar-button-size);padding:0;border:1px solid transparent;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg);cursor:pointer;font-size:16px;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease),border-color var(--tbw-transition-duration) var(--tbw-transition-ease)}tbw-grid .tbw-toolbar-btn:hover{background:var(--tbw-color-row-hover)}tbw-grid .tbw-toolbar-btn:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}tbw-grid .tbw-toolbar-btn.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}tbw-grid .tbw-toolbar-btn:disabled{opacity:.5;cursor:not-allowed}tbw-grid .tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}tbw-grid .tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}tbw-grid .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}tbw-grid .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden;overflow-anchor:none}}
84
86
  @layer tbw-base{tbw-grid .tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:30;box-shadow:-2px 0 8px var(--tbw-color-shadow)}tbw-grid .tbw-tool-panel[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}tbw-grid .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}tbw-grid .tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease)}tbw-grid .tbw-tool-panel-resize[data-handle-position=left]{left:0}tbw-grid .tbw-tool-panel-resize[data-handle-position=right]{right:0}tbw-grid .tbw-tool-panel-resize:hover,tbw-grid .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}tbw-grid .tbw-tool-panel-header{display:flex;align-items:center;justify-content:space-between;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}tbw-grid .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}tbw-grid .tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px}tbw-grid .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}tbw-grid .tbw-tool-panel-content{flex:1;overflow:auto}tbw-grid .tbw-accordion{display:flex;flex-direction:column;gap:0}tbw-grid .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}tbw-grid .tbw-accordion-section:last-child{border-bottom:none}tbw-grid .tbw-accordion-section.single .tbw-accordion-header{cursor:default}tbw-grid .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}tbw-grid .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}tbw-grid .tbw-accordion-section.expanded .tbw-accordion-content{display:block}tbw-grid .tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:start;cursor:pointer;-webkit-user-select:none;user-select:none}tbw-grid .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}tbw-grid .tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}tbw-grid .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}tbw-grid .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}tbw-grid .tbw-accordion-content{display:none}}
85
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}.data-grid-row.tbw-row-loading:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:10;animation:tbw-fade-in .15s ease-out}.data-grid-row.tbw-row-loading:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .6);content:"";position:absolute;left:var(--tbw-spacing-md);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:11}.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:10;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:11}}
86
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}}
87
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}}}
88
- `;class k 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#i(){return this.#t?.effective??{}}#f=!1;#g=!1;#b={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#s;#m=0;#r=null;#p=!1;#A;#D=po();#w;#C;#y;#v;#_={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#o;#E;#M=!1;#O;#F;#z;#t;#e=oo();#c;#N;#k=!1;#T=new Set;#x=new Map;#I;#S=new Map;_rows=[];#U=[];get _columns(){return this.#i.columns??[]}set _columns(e){this.#i.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};_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#t?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#t&&(this.#t.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#t?.originalColumnNodes}set __originalColumnNodes(e){this.#t&&(this.#t.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const o=this.#a;this.#a=e,o!==e&&this.#W("rows")}get sourceRows(){return this.#a}get columns(){return[...this._columns]}set columns(e){const o=this.#t?.getColumns();this.#t?.setColumns(e),o!==e&&this.#W("columns")}get gridConfig(){return this.#i}set gridConfig(e){const o=this.#t?.getGridConfig();this.#t?.setGridConfig(e),o!==e&&(this.#t.clearLightDomCache(),this.#W("gridConfig"))}get fitMode(){return this.#i.fitMode??"stretch"}set fitMode(e){const o=this.#t?.getFitMode();this.#t?.setFitMode(e),o!==e&&this.#W("fitMode")}get loading(){return this.#k}set loading(e){const o=this.#k;this.#k=e,e?this.setAttribute("loading",""):this.removeAttribute("loading"),o!==e&&this.#Ae()}setRowLoading(e,o){const i=this.#T.has(e);o?this.#T.add(e):this.#T.delete(e),i!==o&&this.#ce(e,o)}setCellLoading(e,o,i){let n=this.#x.get(e);const r=n?.has(o)??!1;i?(n||(n=new Set,this.#x.set(e,n)),n.add(o)):(n?.delete(o),n?.size===0&&this.#x.delete(e)),r!==i&&this.#de(e,o,i)}isRowLoading(e){return this.#T.has(e)}isCellLoading(e,o){return this.#x.get(e)?.has(o)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#T)this.#ce(e,!1);this.#T.clear();for(const[e,o]of this.#x)for(const i of o)this.#de(e,i,!1);this.#x.clear()}get effectiveConfig(){return this.#i}get disconnectSignal(){return this.#w||(this.#w=new AbortController),this.#w.signal}constructor(){super(),this.#ue(),this.#d=new Promise(e=>this.#h=e),this.#s=new Bt({mergeConfig:()=>{this.#t.parseLightDomColumns(this),this.#t.merge(),this.#Z(),Ro(this.#i,this.#o?.getPlugins()??[]),Ao(this.#o?.getPlugins()??[]),xo(this.#o?.getPlugins()??[]),this.#Re(),this.#U=[...this._columns]},processColumns:()=>this.#_e(),processRows:()=>this.#Ee(),renderHeader:()=>oe(this),updateTemplate:()=>V(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#o?.afterRender(),this.#i.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,Se(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,W(this)),this._virtualization.enabled&&!this.#$&&this.#ge()},isConnected:()=>this.isConnected&&this.#f}),this.#s.setInitialReadyResolver(()=>this.#h?.()),this.#c=lo(this.#e,{getShadow:()=>this.#n,getShellConfig:()=>this.#i?.shell,getAccordionIcons:()=>({expand:this.#i?.icons?.expand??M.expand,collapse:this.#i?.icons?.collapse??M.collapse}),emit:(e,o)=>this.#L(e,o),refreshShellHeader:()=>this.refreshShellHeader()}),this.#t=new Et({getRows:()=>this.#a,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#s.requestPhase(x.FULL,"configChange")},emit:(e,o)=>this.#L(e,o),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#H(),renderHeader:()=>oe(this),updateTemplate:()=>V(this),refreshVirtualWindow:()=>this.#s.requestPhase(x.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#Se(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#ue(){await go(Po)}getPlugin(e){return this.#o?.getPlugin(e)}getPluginByName(e){return this.#o?.getPluginByName(e)}requestRender(){this.#s.requestPhase(x.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#s.requestPhase(x.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#s.requestPhase(x.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){V(this)}requestAfterRender(){this.#s.requestPhase(x.STYLE,"plugin:requestAfterRender")}#Q(){this.#o=new rt(this);const e=this.#i?.plugins,o=Array.isArray(e)?e:[];this.#o.attachAll(o)}#q(){const e=this.#o?.getPluginStyles()??[];uo(e)}#Z(){const e=this.#i?.plugins,o=Array.isArray(e)?e:[];if(this.#E!==o){if(this.#E&&this.#E.length===o.length&&this.#E.every((i,n)=>i===o[n])){this.#E=o;return}this.#o&&this.#o.detachAll();for(const i of this.#e.toolPanels.keys()){const n=this.#e.lightDomToolPanelIds.has(i),r=this.#e.apiToolPanelIds.has(i);if(!n&&!r){const s=this.#e.panelCleanups.get(i);s&&(s(),this.#e.panelCleanups.delete(i)),this.#e.toolPanels.delete(i)}}for(const i of this.#e.headerContents.keys()){const n=this.#e.headerContentCleanups.get(i);n&&(n(),this.#e.headerContentCleanups.delete(i)),this.#e.headerContents.delete(i)}this.#Q(),this.#q(),this.#E=o,this.#J(),this.#p=this.#o?.getAll().some(i=>i.onScroll)??!1}}#fe(){this.#o?.detachAll()}#J(){if(!this.#o)return;const e=this.#o.getToolPanels();for(const{panel:i}of e)this.#e.toolPanels.has(i.id)||this.#e.toolPanels.set(i.id,i);const o=this.#o.getHeaderContents();for(const{content:i}of o)this.#e.headerContents.has(i.id)||this.#e.headerContents.set(i.id,i)}#P(){const e=k.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const o=this.__frameworkAdapter;return i=>{if(o?.createToolPanelRenderer){const n=o.createToolPanelRenderer(i);if(n)return n}for(const n of e)if(n.createToolPanelRenderer){const r=n.createToolPanelRenderer(i);if(r)return r}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",k.version),this.id||(this.id=`tbw-grid-${++k.#l}`),this._rows=Array.isArray(this.#a)?[...this.#a]:[],this.#w&&(this.#w.abort(),this.#M=!1),this.#w=new AbortController,this.#v&&(Ge(this.#v),this.#v=void 0),F(this,this.#e),U(this,this.#e),G(this,this.#e,this.#P()),this.#t.parseLightDomColumns(this),this.#t.merge(),this.#Q();const e=this.#i?.plugins;this.#E=Array.isArray(e)?e:[],this.#J(),this.#u||(this.#j(),this.#q(),this.#u=!0),this.#ee(),this.#v=It(()=>{this.#Le()},{timeout:100})}disconnectedCallback(){this.#v&&(Ge(this.#v),this.#v=void 0),this.#fe(),so(this.#e),this.#c.setInitialized(!1),this.#N?.(),this.#N=void 0,ot(this.#D),this.#w&&(this.#w.abort(),this.#w=void 0),this.#O?.abort(),this.#O=void 0,this.#M=!1,this._resizeController&&this._resizeController.dispose(),this.#C&&(this.#C.disconnect(),this.#C=void 0),this.#y&&(this.#y.disconnect(),this.#y=void 0,this.#$=!1),K(this),this.#R.clear(),this.#E=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#f=!1}attributeChangedCallback(e,o,i){if(e==="loading"){const n=i!==null&&i!=="false";this.loading!==n&&(this.loading=n);return}if(!(o===i||!i||i==="null"||i==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const n=JSON.parse(i);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:`,i)}else e==="fit-mode"&&(this.fitMode=i)}#ee(){const o=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=o?.querySelector(".header-row"),this._virtualization.totalHeightEl=o?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=o?.querySelector(".rows-viewport"),this._bodyEl=o?.querySelector(".rows"),this.__rowsBodyEl=o?.querySelector(".rows-body"),this.#c.isInitialized){fe(this.#n,this.#e),Ze(this.#n,this.#i?.shell,this.#e);const r=this.#i?.shell?.toolPanel?.defaultOpen;r&&this.#e.toolPanels.has(r)&&(this.openToolPanel(),this.#e.expandedSections.add(r))}if(this.setAttribute("data-upgraded",""),this.#f=!0,this._resizeController=Ve(this),this.#H(),this.#oe(o),this.#M)return;this.#M=!0;const i=this.disconnectSignal;Mt(this,this,this.#n,i);const n=this.#i.rowHeight;n&&n>0?this._virtualization.rowHeight=n:requestAnimationFrame(()=>this.#te()),queueMicrotask(()=>this.#pe()),this.#s.requestPhase(x.FULL,"afterConnect")}#te(){if(this.#o.hasExtraHeight())return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const o=e.querySelectorAll(".cell");let i=0;o.forEach(s=>{const l=s.offsetHeight;l>i&&(i=l)});const n=e.getBoundingClientRect(),r=Math.max(n.height,i);r>0&&Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r,this.#s.requestPhase(x.VIRTUALIZATION,"measureRowHeight"))}#oe(e){this.#O?.abort(),this.#O=new AbortController;const o=this.#O.signal,i=e?.querySelector(".faux-vscroll"),n=e?.querySelector(".rows");if(this._virtualization.container=i??this,this.#p=this.#o?.getAll().some(r=>r.onScroll)??!1,i&&n){i.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#p)return;const a=i.scrollTop,c=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)n.style.transform=`translateY(${-a}px)`;else{const d=Math.floor(a/c),u=d-d%2,g=-(a-u*c);n.style.transform=`translateY(${g}px)`}this.#r=a,this.#m||(this.#m=requestAnimationFrame(()=>{this.#m=0,this.#r!==null&&(this.#Te(this.#r),this.#r=null)}))},{passive:!0,signal:o});const r=this.#n.querySelector(".tbw-scroll-area");this.#F=r,r&&this.#p&&r.addEventListener("scroll",()=>{const a=this.#_;a.scrollTop=i.scrollTop,a.scrollLeft=r.scrollLeft,a.scrollHeight=i.scrollHeight,a.scrollWidth=r.scrollWidth,a.clientHeight=i.clientHeight,a.clientWidth=r.clientWidth,this.#o?.onScroll(a)},{passive:!0,signal:o});const s=this.#n.querySelector(".tbw-grid-content"),l=this.#F;s&&(s.addEventListener("wheel",a=>{const c=a.shiftKey||Math.abs(a.deltaX)>Math.abs(a.deltaY);if(c&&l){const d=a.shiftKey?a.deltaY:a.deltaX,{scrollLeft:u,scrollWidth:g,clientWidth:f}=l;(d>0&&u<g-f||d<0&&u>0)&&(a.preventDefault(),l.scrollLeft+=d)}else if(!c){const{scrollTop:d,scrollHeight:u,clientHeight:g}=i;(a.deltaY>0&&d<u-g||a.deltaY<0&&d>0)&&(a.preventDefault(),i.scrollTop+=a.deltaY)}},{passive:!1,signal:o}),yo(s,this.#D,{fauxScrollbar:i,scrollArea:l},o))}this._bodyEl&&zt(this,this._bodyEl,o),this.#C?.disconnect(),this._virtualization.viewportEl&&(this.#C=new ResizeObserver(()=>{this.#s.requestPhase(x.VIRTUALIZATION,"resize-observer")}),this.#C.observe(this._virtualization.viewportEl)),this.#n.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:o}),this.#n.addEventListener("focusout",r=>{const s=r.relatedTarget;(!s||!this.#n.contains(s))&&delete this.dataset.hasFocus},{signal:o})}#$=!1;#ge(){if(this.#$)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#$=!0,this.#y?.disconnect(),this.#y=new ResizeObserver(()=>{this.#te()}),this.#y.observe(e))}addEventListener(e,o,i){super.addEventListener(e,o,i)}removeEventListener(e,o,i){super.removeEventListener(e,o,i)}#L(e,o){this.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0,composed:!0}))}#pe(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((o,i)=>{const n=i===this._focusRow;o.setAttribute("aria-selected",String(n)),o.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(n&&s===this._focusCol))})})}#W(e){this.#b[e]=!0,!this.#g&&(this.#g=!0,queueMicrotask(()=>this.#we()))}#we(){if(!this.#g||!this.#f){this.#g=!1;return}const e=this.#b;if(this.#g=!1,this.#b={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig){this.#Ce(),e.rows&&this.#ie();return}e.columns&&this.#me(),e.rows&&this.#ie(),e.fitMode&&this.#ve()}#ie(){this._rows=Array.isArray(this.#a)?[...this.#a]:[],this.#G(),this.#s.requestPhase(x.ROWS,"applyRowsUpdate")}#G(){this.#S.clear();const e=this.#i.getRowId;this._rows.forEach((o,i)=>{const n=this.#ne(o,e);n!==void 0&&this.#S.set(n,{row:o,index:i})})}#ne(e,o){if(o)return o(e);const i=e;if("id"in i&&i.id!=null)return String(i.id);if("_id"in i&&i._id!=null)return String(i._id)}#be(e,o){const i=this.#ne(e,o);if(i===void 0)throw new Error('[tbw-grid] Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.');return i}#me(){K(this),this.#t.merge(),this.#H()}#ve(){this.#t.merge(),this.#i.fitMode==="fixed"?(this.__didInitialAutoSize=!1,Se(this)):(this._columns.forEach(o=>{!o.__userResized&&o.__autoSized&&delete o.width}),V(this))}#Ce(){F(this,this.#e),U(this,this.#e);const e=!!this.#n.querySelector(".has-shell"),o=!!this.#n.querySelector(".tbw-tool-panel"),i=this.#n.querySelectorAll(".tbw-accordion-section").length;this.#t.parseLightDomColumns(this),this.#t.merge(),this.#Z(),G(this,this.#e,this.#P()),this.#t.markSourcesChanged(),this.#t.merge();const n=Ke(this.#i?.shell),r=(this.#i?.shell?.toolPanels?.length??0)>0,s=(this.#i?.shell?.toolPanels?.length??0)!==i;if(e!==n||!e&&n||!o&&r||o&&s){this.#j(),this.#q(),this.#ee(),this.#G();return}e&&this.#ye(),this.#G(),this.#s.requestPhase(x.COLUMNS,"applyGridConfigUpdate")}#ye(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;const o=this.#i.shell?.header?.title??this.#e.lightDomTitle;let i=e.querySelector(".tbw-shell-title");o?(i||(i=document.createElement("h2"),i.className="tbw-shell-title",i.setAttribute("part","shell-title"),e.insertBefore(i,e.firstChild)),i.textContent=o):i&&i.remove()}#_e(){if(this.#o){const e=this.#U.length>0?this.#U:this._columns,o=e.filter(r=>!r.hidden),i=e.filter(r=>r.hidden),n=this.#o.processColumns([...o]);if(n!==o){new Set(o.map(l=>l.field));const r=new Set(n.map(l=>l.field));!o.some(l=>r.has(l.field))&&n.length>0?this._columns=[...n,...i]:this._columns=[...n,...i]}else this._columns=[...e]}}#Ee(){K(this);const e=Array.isArray(this.#a)?[...this.#a]:[],o=this.#o?.processRows(e)??e;this._rows=o}#Se(e){const o={...Ce,...e.animation},i=o.mode??"reduced-motion";let n=1;i===!1||i==="off"?n=0:(i===!0||i==="on")&&(n=1),this.style.setProperty("--tbw-animation-duration",`${o.duration}ms`),this.style.setProperty("--tbw-animation-easing",o.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode=typeof i=="boolean"?i?"on":"off":i}#V(e,o,i=this.__rowRenderEpoch){this.#A||(this.#A=(n,r,s)=>this.#o?.renderRow(n,r,s)??!1),xt(this,e,o,i,this.#A)}#B=-1;#re=-1;#se(e,o){if(e===this.#B&&o===this.#re)return;const i=this.#B;this.#B=e,this.#re=o,this.__rowsBodyEl&&(this.__rowsBodyEl.setAttribute("aria-rowcount",String(e)),this.__rowsBodyEl.setAttribute("aria-colcount",String(o))),e!==i&&this._bodyEl&&(e>0?this._bodyEl.setAttribute("role","rowgroup"):this._bodyEl.removeAttribute("role"))}#le;#ae;#Re(){if(!this.__rowsBodyEl)return;const e=this.#i.gridAriaLabel,o=this.#i.shell?.header?.title??this.#e?.lightDomTitle??void 0,i=e??o;i!==this.#le&&(this.#le=i,i?this.__rowsBodyEl.setAttribute("aria-label",i):this.__rowsBodyEl.removeAttribute("aria-label"));const n=this.#i.gridAriaDescribedBy;n!==this.#ae&&(this.#ae=n,n?this.__rowsBodyEl.setAttribute("aria-describedby",n):this.__rowsBodyEl.removeAttribute("aria-describedby"))}#Ae(){const e=this.querySelector(".tbw-grid-root");e&&(this.#k?(this.#I||(this.#I=Wt(this.#i?.loadingRenderer)),Ft(e,this.#I)):Ut(this.#I))}#ce(e,o){const i=this.#S.get(e);if(!i)return;const n=this.findRenderedRowElement?.(i.index);n&&Gt(n,o)}#de(e,o,i){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===o);if(s<0)return;const l=r.children[s];l&&Vt(l,i)}#H(){if(this.isConnected&&!(!this._headerRowEl||!this._bodyEl)){if(this.#t.parseLightDomColumns(this),this.#z){const e=this.#z;this.#z=void 0,this.#t.merge();const o=this.#o?.getAll()??[];this.#t.applyState(e,o)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#s.requestPhase(x.FULL,"setup")}}#Te(e){if(this.refreshVirtualWindow(!1),this.#o?.onScrollRender(),this.#p){const o=this._virtualization.container,i=this.#F,n=this.#_;n.scrollTop=e,n.scrollLeft=i?.scrollLeft??0,n.scrollHeight=o?.scrollHeight??0,n.scrollWidth=i?.scrollWidth??0,n.clientHeight=o?.clientHeight??0,n.clientWidth=i?.clientWidth??0,this.#o?.onScroll(n)}}findHeaderRow(){return this.#n.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(o=>{const i=o.querySelector(".cell[data-row]");return i&&Number(i.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,o,i,n){const r=this._rows[o],s=this._columns[i];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:o,colIndex:i,field:l,value:a,row:r,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(c),c.defaultPrevented)return!0;const d={row:r,rowIndex:o,colIndex:i,field:l,value:a,cellEl:n,originalEvent:e},u=this.#o?.onCellClick(d)??!1;return this.#L("cell-click",d),u}_dispatchRowClick(e,o,i,n){if(!i)return!1;const r={rowIndex:o,row:i,rowEl:n,originalEvent:e},s=this.#o?.onRowClick(r)??!1;return this.#L("row-click",r),s}_dispatchHeaderClick(e,o,i){const n=this._columns[o];if(!n)return!1;const r={colIndex:o,field:n.field,column:n,headerEl:i,originalEvent:e};return this.#o?.onHeaderClick(r)??!1}_dispatchKeyDown(e){return this.#o?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,o){return this.#o?.getHorizontalScrollOffsets(e,o)??{left:0,right:0}}queryPlugins(e){return this.#o?.queryPlugins(e)??[]}query(e,o){return this.#o?.queryPlugins({type:e,context:o})??[]}_dispatchCellMouseDown(e){return this.#o?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#o?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#o?.onCellMouseUp(e)}_afterCellRender(e){this.#o?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#o?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#o?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#o?.hasAfterRowRenderHook()??!1}async ready(){return this.#d}async forceLayout(){return this.#s.requestPhase(x.FULL,"forceLayout"),this.#s.whenReady()}async getConfig(){return Object.freeze({...this.#i||{}})}getRowId(e){return this.#be(e,this.#i.getRowId)}getRow(e){return this.#S.get(e)?.row}updateRow(e,o,i="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(o)){const d=r[a];d!==c&&(l.push({field:a,oldValue:d,newValue:c}),r[a]=c)}for(const{field:a,oldValue:c,newValue:d}of l)this.#L("cell-change",{row:r,rowId:e,rowIndex:s,field:a,oldValue:c,newValue:d,changes:o,source:i});l.length>0&&this.#s.requestPhase(x.ROWS,"updateRow")}updateRows(e,o="api"){let i=!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,d]of Object.entries(r)){const u=l[c];u!==d&&(i=!0,l[c]=d,this.#L("cell-change",{row:l,rowId:n,rowIndex:a,field:c,oldValue:u,newValue:d,changes:r,source:o}))}}i&&this.#s.requestPhase(x.ROWS,"updateRows")}animateRow(e,o){ue(this,e,o)}animateRows(e,o){Zt(this,e,o)}animateRowById(e,o){return Jt(this,e,o)}setColumnVisible(e,o){const i=this.#t.setColumnVisible(e,o);return i&&this.requestStateChange(),i}toggleColumnVisibility(e){const o=this.#t.toggleColumnVisibility(e);return o&&this.requestStateChange(),o}isColumnVisible(e){return this.#t.isColumnVisible(e)}showAllColumns(){this.#t.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#t.getAllColumns()}setColumnOrder(e){this.#t.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#t.getColumnOrder()}getColumnState(){const e=this.#o?.getAll()??[];return this.#t.collectState(e)}set columnState(e){e&&(this.#z=e,this.#t.initialColumnState=e,this.#u&&this.#xe(e))}get columnState(){return this.getColumnState()}#xe(e){const o=this.#o?.getAll()??[];this.#t.applyState(e,o),this.#H()}requestStateChange(){const e=this.#o?.getAll()??[];this.#t.requestStateChange(e)}resetColumnState(){this.#z=void 0,this.__originalOrder=[];const e=this.#o?.getAll()??[];this.#t.resetState(e),this.#t.merge(),this.#H()}get isToolPanelOpen(){return this.#c.isPanelOpen}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)}#X=!1;refreshShellHeader(){this.#X||(this.#X=!0,queueMicrotask(()=>{this.#X=!1,this.isConnected&&(F(this,this.#e),U(this,this.#e),G(this,this.#e,this.#P()),this.#t.markSourcesChanged(),this.#t.merge(),this.#j(),this.#q(),this.#Pe())}))}#Pe(){const o=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=o?.querySelector(".header-row"),this._virtualization.totalHeightEl=o?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=o?.querySelector(".rows-viewport"),this._bodyEl=o?.querySelector(".rows"),this.__rowsBodyEl=o?.querySelector(".rows-body"),this.#c.isInitialized){fe(this.#n,this.#e),Ze(this.#n,this.#i?.shell,this.#e);const i=this.#i?.shell?.toolPanel?.defaultOpen;i&&this.#e.toolPanels.has(i)&&(this.openToolPanel(),this.#e.expandedSections.add(i))}this._resizeController=Ve(this),this.#oe(o),this.#s.requestPhase(x.COLUMNS,"shellRefresh")}#R=new Map;registerStyles(e,o){let i=this.#R.get(e);i||(i=new CSSStyleSheet,this.#R.set(e,i)),i.replaceSync(o),this.#he()}unregisterStyles(e){this.#R.delete(e)&&this.#he()}getRegisteredStyles(){return Array.from(this.#R.keys())}#he(){const e=Array.from(this.#R.values()),o=document.adoptedStyleSheets.filter(i=>!Array.from(this.#R.values()).includes(i));document.adoptedStyleSheets=[...o,...e]}#Le(){const e=()=>{const i=this.#e.lightDomTitle,n=this.#e.hasToolButtonsContainer;F(this,this.#e),U(this,this.#e),G(this,this.#e,this.#P());const r=this.#e.lightDomTitle,s=this.#e.hasToolButtonsContainer;if(r&&!i||s&&!n){this.#t.markSourcesChanged(),this.#t.merge();const l=this.#n.querySelector(".tbw-shell-header");if(l){const a=Qe(this.#i.shell,this.#e,this.#i.icons?.toolPanel),c=document.createElement("div");c.innerHTML=a;const d=c.firstElementChild;d&&(l.replaceWith(d),this.#K())}}},o=()=>{this.__lightDomColumnsCache=void 0,this.#H()};this.#t.registerLightDomHandler("tbw-grid-header",e),this.#t.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#t.registerLightDomHandler("tbw-grid-tool-panel",e),this.#t.registerLightDomHandler("tbw-grid-column",o),this.#t.registerLightDomHandler("tbw-grid-detail",o),this.#t.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,K(this),this.#t.parseLightDomColumns(this);const e=this.#e.lightDomTitle,o=this.#e.hasToolButtonsContainer;F(this,this.#e),U(this,this.#e),G(this,this.#e,this.#P());const i=this.#e.lightDomTitle,n=this.#e.hasToolButtonsContainer;if(i&&!e||n&&!o){this.#t.markSourcesChanged(),this.#t.merge();const s=this.#n.querySelector(".tbw-shell-header");if(s){const l=Qe(this.#i.shell,this.#e,this.#i.icons?.toolPanel),a=document.createElement("div");a.innerHTML=l;const c=a.firstElementChild;c&&(s.replaceWith(c),this.#K())}}this.#s.requestPhase(x.COLUMNS,"refreshColumns")}#Y(e){const o=this._virtualization.rowHeight,i=this._virtualization.container??this,n=this._virtualization.viewportEl??i,r=i.clientHeight,s=n.clientHeight,a=this.shadowRoot?.querySelector(".tbw-scroll-area"),c=a?a.clientHeight:r,u=c-s,g=this.#o?.getExtraHeight()??0,f=Math.max(0,r-c);return e*o+u+g+f}refreshVirtualWindow(e=!1,o=!1){if(!this._bodyEl)return;const i=this._rows.length;if(!this._virtualization.enabled){this.#V(0,i),o||this.#o?.afterRender();return}if(this._rows.length<=this._virtualization.bypassThreshold){this._virtualization.start=0,this._virtualization.end=i,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#V(0,i,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#Y(i)}px`),this.#se(i,this._visibleColumns.length),o||this.#o?.afterRender();return}const n=this._virtualization.container??this,r=this._virtualization.viewportEl??n,s=r.clientHeight,l=this._virtualization.rowHeight,a=n.scrollTop;let c=Math.floor(a/l),d=0;const u=10;for(;d<u;){const y=this.#o?.getExtraHeightBefore?.(c)??0,E=Math.floor((a-y)/l);if(E>=c||E<0)break;c=E,d++}c=c-c%2,c<0&&(c=0);const g=this.#o?.adjustVirtualStart(c,a,l);g!==void 0&&g<c&&(c=g,c=c-c%2,c<0&&(c=0));const f=Math.ceil(s/l)+3;let p=c+f;if(p>i&&(p=i),this._virtualization.start=c,this._virtualization.end=p,n.clientHeight===0&&s>0){this.#s.requestPhase(x.VIRTUALIZATION,"stale-refs-retry");return}const w=this.#Y(i);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${w}px`);const C=this.#o?.getExtraHeightBefore?.(c)??0,R=-(a-c*l-C);this._bodyEl.style.transform=`translateY(${R}px)`,this.#V(c,p,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),this.#se(i,this._visibleColumns.length),e&&!o&&(this.#o?.afterRender(),queueMicrotask(()=>{const y=n.clientHeight,E=r.clientHeight;if(y===0&&E>0)return;const P=this.#Y(i);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${P}px`)}))}#j(){F(this,this.#e),U(this,this.#e),G(this,this.#e,this.#P()),this.#t.markSourcesChanged(),this.#t.merge();const e=this.#i?.shell;co(this.#n,e,{isPanelOpen:this.#e.isPanelOpen,expandedSections:this.#e.expandedSections},this.#i?.icons)&&(this.#K(),this.#c.setInitialized(!0))}#K(){io(this.#n,this.#i?.shell,this.#e,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#N?.(),this.#N=no(this.#n,this.#i?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}}customElements.get(k.tagName)||customElements.define(k.tagName,k),globalThis.DataGridElement=k;const Lo={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class Ho{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,o){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:o,bubbles:!0}))}emitCancelable(e,o){const i=new CustomEvent(e,{detail:o,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(e,o){this.grid?._pluginManager?.subscribe(this,e,o)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,o){this.grid?._pluginManager?.emitPluginEvent(e,o)}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{...M,...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 o=this.gridElement;return o?getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationDuration(){const e=this.gridElement;if(e){const o=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(o,10);if(!isNaN(i))return i}return 200}resolveIcon(e,o){return o!==void 0?o:this.gridIcons[e]}setIcon(e,o){typeof o=="string"?e.innerHTML=o:o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const L={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"},Y={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"},Do={ROOT:`.${L.ROOT}`,HEADER:`.${L.HEADER}`,HEADER_ROW:`.${L.HEADER_ROW}`,HEADER_CELL:`.${L.HEADER_CELL}`,ROWS_VIEWPORT:`.${L.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${L.ROWS_CONTAINER}`,DATA_ROW:`.${L.DATA_ROW}`,DATA_CELL:`.${L.DATA_CELL}`,GROUP_ROW:`.${L.GROUP_ROW}`,ROW_BY_INDEX:t=>`.${L.DATA_ROW}[${Y.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${L.DATA_CELL}[${Y.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${L.DATA_ROW}[${Y.ROW_INDEX}="${t}"] .${L.DATA_CELL}[${Y.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${L.DATA_ROW}.${L.SELECTED}`,EDITING_CELL:`.${L.DATA_CELL}.${L.EDITING}`},Oo={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 zo(t){const e=document.createElement("tbw-grid");return t&&(e.gridConfig=t),e}function Mo(t,e=document){return e.querySelector(t)}const No={CELL_CHANGE:"cell-change",CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",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"},ko={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"},me={sum:(t,e)=>t.reduce((o,i)=>o+(Number(i[e])||0),0),avg:(t,e)=>{const o=t.reduce((i,n)=>i+(Number(n[e])||0),0);return t.length?o/t.length:0},count:t=>t.length,min:(t,e)=>Math.min(...t.map(o=>Number(o[e])||1/0)),max:(t,e)=>Math.max(...t.map(o=>Number(o[e])||-1/0)),first:(t,e)=>t[0]?.[e],last:(t,e)=>t[t.length-1]?.[e]},j=new Map,O={register(t,e){j.set(t,e)},unregister(t){j.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:j.get(t)??me[t]},run(t,e,o,i){const n=this.get(t);return n?n(e,o,i):void 0},has(t){return j.has(t)||t in me},list(){return[...Object.keys(me),...j.keys()]}},st={sum:t=>t.reduce((e,o)=>e+o,0),avg:t=>t.length?t.reduce((e,o)=>e+o,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 lt(t){return st[t]??st.sum}function Io(t,e){return lt(t)(e)}const qo=O.register.bind(O),$o=O.unregister.bind(O),Wo=O.get.bind(O),Fo=O.run.bind(O),Uo=O.list.bind(O);v.BaseGridPlugin=Ho,v.DEFAULT_ANIMATION_CONFIG=Ce,v.DEFAULT_GRID_ICONS=M,v.DGEvents=No,v.DataGridElement=k,v.FitModeEnum=z,v.GridCSSVars=Oo,v.GridClasses=L,v.GridDataAttrs=Y,v.GridElement=k,v.GridSelectors=Do,v.PLUGIN_QUERIES=Lo,v.PluginEvents=ko,v.PluginManager=rt,v.RenderPhase=x,v.aggregatorRegistry=O,v.builtInSort=qe,v.createGrid=zo,v.defaultComparator=Ie,v.getAggregator=Wo,v.getValueAggregator=lt,v.listAggregators=Uo,v.queryGrid=Mo,v.registerAggregator=qo,v.runAggregator=Fo,v.runValueAggregator=Io,v.unregisterAggregator=$o,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
90
+ `;class k 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.#t?.effective??{}}#f=!1;#w=!1;#v={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#s;#C=0;#r=null;#g=!1;#T=!1;#m=0;#z;#k=_i();#b;#y;#p;#E;#Z={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#e;#_;#I=!1;#D;#V;#O;#t;#i=ci();#c;#N;#q=!1;#x=new Set;#H=new Map;#$;#S=new Map;_rows=[];#G=[];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};_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#t?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#t&&(this.#t.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#t?.originalColumnNodes}set __originalColumnNodes(e){this.#t&&(this.#t.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const i=this.#a;this.#a=e,i!==e&&this.#U("rows")}get sourceRows(){return this.#a}get columns(){return[...this._columns]}set columns(e){const i=this.#t?.getColumns();this.#t?.setColumns(e),i!==e&&this.#U("columns")}get gridConfig(){return this.#o}set gridConfig(e){const i=this.#t?.getGridConfig();this.#t?.setGridConfig(e),i!==e&&(this.#t.clearLightDomCache(),this.#U("gridConfig"))}get fitMode(){return this.#o.fitMode??"stretch"}set fitMode(e){const i=this.#t?.getFitMode();this.#t?.setFitMode(e),i!==e&&this.#U("fitMode")}get loading(){return this.#q}set loading(e){const i=this.#q;this.#q=e,e?this.setAttribute("loading",""):this.removeAttribute("loading"),i!==e&&this.#Le()}setRowLoading(e,i){const o=this.#x.has(e);i?this.#x.add(e):this.#x.delete(e),o!==i&&this.#de(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.#he(e,i,o)}isRowLoading(e){return this.#x.has(e)}isCellLoading(e,i){return this.#H.get(e)?.has(i)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#x)this.#de(e,!1);this.#x.clear();for(const[e,i]of this.#H)for(const o of i)this.#he(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.#we(),this.#d=new Promise(e=>this.#h=e),this.#s=new Jt({mergeConfig:()=>{this.#t.parseLightDomColumns(this),this.#t.merge(),this.#ee(),zi(this.#o,this.#e?.getPlugins()??[]),Di(this.#e?.getPlugins()??[]),Mi(this.#e?.getPlugins()??[]),this.#Pe(),this.#G=[...this._columns]},processColumns:()=>this.#Te(),processRows:()=>this.#xe(),renderHeader:()=>te(this),updateTemplate:()=>U(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#e?.afterRender(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const i=this.#A(this._rows.length);this._virtualization.totalHeightEl.style.height=`${i}px`}),this.#o.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,Te(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,W(this)),this._virtualization.enabled&&!this.#F&&this.#ve(),this.#T&&(this.#T=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#me()})}))},isConnected:()=>this.isConnected&&this.#f}),this.#s.setInitialReadyResolver(()=>this.#h?.()),this.#c=pi(this.#i,{getShadow:()=>this.#n,getShellConfig:()=>this.#o?.shell,getAccordionIcons:()=>({expand:this.#o?.icons?.expand??O.expand,collapse:this.#o?.icons?.collapse??O.collapse}),emit:(e,i)=>this.#P(e,i),refreshShellHeader:()=>this.refreshShellHeader()}),this.#t=new Pt({getRows:()=>this.#a,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#s.requestPhase(H.FULL,"configChange")},emit:(e,i)=>this.#P(e,i),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#L(),renderHeader:()=>te(this),updateTemplate:()=>U(this),refreshVirtualWindow:()=>this.#s.requestPhase(H.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#He(e),getShellLightDomTitle:()=>this.#i.lightDomTitle,getShellToolPanels:()=>this.#i.toolPanels,getShellHeaderContents:()=>this.#i.headerContents,getShellToolbarContents:()=>this.#i.toolbarContents,getShellLightDomHeaderContent:()=>this.#i.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#i.hasToolButtonsContainer})}async#we(){await yi(Vi)}getPlugin(e){return this.#e?.getPlugin(e)}getPluginByName(e){return this.#e?.getPluginByName(e)}requestRender(){this.#s.requestPhase(H.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#s.requestPhase(H.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#s.requestPhase(H.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){U(this)}requestAfterRender(){this.#s.requestPhase(H.STYLE,"plugin:requestAfterRender")}#J(){this.#e=new B(this);const e=this.#o?.plugins,i=Array.isArray(e)?e:[];this.#e.attachAll(i)}#W(){const e=this.#e?.getPluginStyles()??[];vi(e)}#ee(){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.#e&&this.#e.detachAll();for(const n of this.#i.toolPanels.keys()){const r=this.#i.lightDomToolPanelIds.has(n),s=this.#i.apiToolPanelIds.has(n);if(!r&&!s){const l=this.#i.panelCleanups.get(n);l&&(l(),this.#i.panelCleanups.delete(n)),this.#i.toolPanels.delete(n)}}for(const n of this.#i.headerContents.keys()){const r=this.#i.headerContentCleanups.get(n);r&&(r(),this.#i.headerContentCleanups.delete(n)),this.#i.headerContents.delete(n)}this.#J(),this.#W(),this.#_=i,this.#ne(),this.#te();const o=this.#g;if(this.#g=this.#e?.getAll().some(n=>n.onScroll)??!1,!o&&this.#g){const r=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");this.#B(r)}}#be(){this.#e?.detachAll()}#te(){if(!this.#e)return;const e=this.#e.getToolPanels();for(const{panel:o}of e)this.#i.toolPanels.has(o.id)||this.#i.toolPanels.set(o.id,o);const i=this.#e.getHeaderContents();for(const{content:o}of i)this.#i.headerContents.has(o.id)||this.#i.headerContents.set(o.id,o)}#ie(){const e=k.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",k.version),this.id||(this.id=`tbw-grid-${++k.#l}`),this._rows=Array.isArray(this.#a)?[...this.#a]:[],this.#b&&(this.#b.abort(),this.#I=!1),this.#b=new AbortController,this.#E&&(Xe(this.#E),this.#E=void 0),this.#M(),this.#t.parseLightDomColumns(this),this.#t.merge(),this.#J();const e=this.#o?.plugins;this.#_=Array.isArray(e)?e:[],this.#te(),this.#u||(this.#Q(),this.#W(),this.#u=!0),this.#oe(),this.#E=Gt(()=>{this.#Me()},{timeout:100})}disconnectedCallback(){this.#E&&(Xe(this.#E),this.#E=void 0),this.#m&&(clearTimeout(this.#m),this.#m=0),this.#be(),gi(this.#i),this.#c.setInitialized(!1),this.#N?.(),this.#N=void 0,st(this.#k),this.#b&&(this.#b.abort(),this.#b=void 0),this.#D?.abort(),this.#D=void 0,this.#I=!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.#F=!1),j(this),this.#R.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)}#oe(){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){ge(this.#n,this.#i),fe(this.#n,this.#o?.shell,this.#i);const n=this.#o?.shell?.toolPanel?.defaultOpen;n&&this.#i.toolPanels.has(n)&&(this.openToolPanel(),this.#i.expandedSections.add(n))}if(this.setAttribute("data-upgraded",""),this.#f=!0,this._resizeController=Ye(this),this.#L(),this.#B(i),this.#I)return;this.#I=!0;const o=this.disconnectSignal;Ft(this,this,this.#n,o),this.#ne(),queueMicrotask(()=>this.#Ce()),this.#s.requestPhase(H.FULL,"afterConnect")}#ne(){const e=this.#o.rowHeight,i=this.#e.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.#K(),typeof e!="function"&&(this.#T=!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.#re())}#re(){if(this.#e.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(H.VIRTUALIZATION,"measureRowHeight"))}#me(){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.#K(),this._virtualization.totalHeightEl)){const l=this.#A(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#B(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.#e?.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 d=this._virtualization.positionCache;let u,f;if(this._virtualization.variableHeights&&d&&d.length>0){u=ct(d,a),u===-1&&(u=0);const p=u-u%2;f=d[p]?.offset??p*c}else u=Math.floor(a/c),f=(u-u%2)*c;const g=-(a-f);n.style.transform=`translateY(${g}px)`}this.#r=a,this.#C||(this.#C=requestAnimationFrame(()=>{this.#C=0,this.#r!==null&&(this.#ze(this.#r),this.#r=null)}))},{passive:!0,signal:i});const r=this.#n.querySelector(".tbw-scroll-area");this.#V=r,r&&this.#g&&r.addEventListener("scroll",()=>{const a=this.#Z;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.#e?.onScroll(a)},{passive:!0,signal:i});const s=this.#n.querySelector(".tbw-grid-content"),l=this.#V;s&&(s.addEventListener("wheel",a=>{const c=a.shiftKey||Math.abs(a.deltaX)>Math.abs(a.deltaY);if(c&&l){const d=a.shiftKey?a.deltaY:a.deltaX,{scrollLeft:u,scrollWidth:f,clientWidth:g}=l;(d>0&&u<f-g||d<0&&u>0)&&(a.preventDefault(),l.scrollLeft+=d)}else if(!c){const{scrollTop:d,scrollHeight:u,clientHeight:f}=o;(a.deltaY>0&&d<u-f||a.deltaY<0&&d>0)&&(a.preventDefault(),o.scrollTop+=a.deltaY)}},{passive:!1,signal:i}),xi(s,this.#k,{fauxScrollbar:o,scrollArea:l},i))}this._bodyEl&&Wt(this,this._bodyEl,i),this.#y?.disconnect(),this._virtualization.viewportEl&&(this.#y=new ResizeObserver(()=>{this.#ke(),this.#s.requestPhase(H.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})}#F=!1;#ve(){if(this.#F)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#F=!0,this.#p?.disconnect(),this.#p=new ResizeObserver(()=>{this.#re()}),this.#p.observe(e))}addEventListener(e,i,o){super.addEventListener(e,i,o)}removeEventListener(e,i,o){super.removeEventListener(e,i,o)}#P(e,i){this.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,composed:!0}))}#Ce(){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))})})}#U(e){this.#v[e]=!0,!this.#w&&(this.#w=!0,queueMicrotask(()=>this.#ye()))}#ye(){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.#Re(),e.rows&&this.#se();return}e.columns&&this.#Ee(),e.rows&&this.#se(),e.fitMode&&this.#Se()}#se(){this._rows=Array.isArray(this.#a)?[...this.#a]:[],this.#X(),this.#s.requestPhase(H.ROWS,"applyRowsUpdate")}#X(){this.#S.clear();const e=this.#o.getRowId;this._rows.forEach((i,o)=>{const n=this.#le(i,e);n!==void 0&&this.#S.set(n,{row:i,index:o})})}#le(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)}#_e(e,i){const o=this.#le(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}#Ee(){j(this),this.#t.merge(),this.#L()}#Se(){this.#t.merge(),this.#o.fitMode==="fixed"?(this.__didInitialAutoSize=!1,Te(this)):(this._columns.forEach(i=>{!i.__userResized&&i.__autoSized&&delete i.width}),U(this))}#Re(){et(this,this.#i),tt(this,this.#i);const e=!!this.#n.querySelector(".has-shell"),i=!!this.#n.querySelector(".tbw-tool-panel"),o=this.#n.querySelectorAll(".tbw-accordion-section").length;this.#t.parseLightDomColumns(this),this.#t.merge(),this.#ee(),it(this,this.#i,this.#ie()),this.#t.markSourcesChanged(),this.#t.merge();const n=Je(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){pe(this.#i),this.#Q(),this.#W(),this.#oe(),this.#X();return}e&&this.#Ae(),this.#X(),this.#s.requestPhase(H.COLUMNS,"applyGridConfigUpdate")}#Ae(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;const i=this.#o.shell?.header?.title??this.#i.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()}#Te(){if(this.#e){const e=this.#G.length>0?this.#G:this._columns,i=e.filter(r=>!r.hidden),o=e.filter(r=>r.hidden),n=this.#e.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=[...n,...o]}else this._columns=[...e]}}#xe(){j(this);const e=Array.isArray(this.#a)?[...this.#a]:[],i=this.#e?.processRows(e)??e;this._rows=i,this._virtualization.variableHeights&&this.#K()}#He(e){const i={...Ee,...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}#Y(e,i,o=this.__rowRenderEpoch){this.#z||(this.#z=(n,r,s)=>this.#e?.renderRow(n,r,s)??!1),Mt(this,e,i,o,this.#z)}#ae=F();#ce(e,i){ut(this.#ae,this.__rowsBodyEl,this._bodyEl,e,i)}#Pe(){gt(this.#ae,this.__rowsBodyEl,this.#o,this.#i)}#Le(){const e=this.querySelector(".tbw-grid-root");e&&(this.#q?(this.#$||(this.#$=Yt(this.#o?.loadingRenderer)),jt(e,this.#$)):Kt(this.#$))}#de(e,i){const o=this.#S.get(e);if(!o)return;const n=this.findRenderedRowElement?.(o.index);n&&Qt(n,i)}#he(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&&Zt(l,o)}#L(){if(this.isConnected&&!(!this._headerRowEl||!this._bodyEl)){if(this.#t.parseLightDomColumns(this),this.#O){const e=this.#O;this.#O=void 0,this.#t.merge();const i=this.#e?.getAll()??[];this.#t.applyState(e,i)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#s.requestPhase(H.FULL,"setup")}}#ze(e){let i=0,o=0,n=0,r=0,s=0;if(this.#g){const a=this._virtualization.container,c=this.#V;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.#e?.onScrollRender(),this._virtualization.variableHeights&&(this.#m&&clearTimeout(this.#m),this.#m=window.setTimeout(()=>{this.#m=0,this.#ge(this._virtualization.start,this._virtualization.end)},100)),this.#g){const a=this.#Z;a.scrollTop=e,a.scrollLeft=i,a.scrollHeight=o,a.scrollWidth=n,a.clientHeight=r,a.clientWidth=s,this.#e?.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,field:l,value:a,row:r,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(c),c.defaultPrevented)return!0;const d={row:r,rowIndex:i,colIndex:o,field:l,value:a,cellEl:n,originalEvent:e},u=this.#e?.onCellClick(d)??!1;return this.#P("cell-click",d),u}_dispatchRowClick(e,i,o,n){if(!o)return!1;const r={rowIndex:i,row:o,rowEl:n,originalEvent:e},s=this.#e?.onRowClick(r)??!1;return this.#P("row-click",r),s}_dispatchHeaderClick(e,i,o){const n=this._columns[i];if(!n)return!1;const r={colIndex:i,field:n.field,column:n,headerEl:o,originalEvent:e};return this.#e?.onHeaderClick(r)??!1}_dispatchKeyDown(e){return this.#e?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,i){return this.#e?.getHorizontalScrollOffsets(e,i)??{left:0,right:0}}queryPlugins(e){return this.#e?.queryPlugins(e)??[]}query(e,i){return this.#e?.queryPlugins({type:e,context:i})??[]}_dispatchCellMouseDown(e){return this.#e?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#e?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#e?.onCellMouseUp(e)}_afterCellRender(e){this.#e?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#e?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#e?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#e?.hasAfterRowRenderHook()??!1}async ready(){return this.#d}async forceLayout(){return this.#s.requestPhase(H.FULL,"forceLayout"),this.#s.whenReady()}async getConfig(){return Object.freeze({...this.#o||{}})}getRowId(e){return this.#_e(e,this.#o.getRowId)}getRow(e){return this.#S.get(e)?.row}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 d=r[a];d!==c&&(l.push({field:a,oldValue:d,newValue:c}),r[a]=c)}for(const{field:a,oldValue:c,newValue:d}of l)this.#P("cell-change",{row:r,rowId:e,rowIndex:s,field:a,oldValue:c,newValue:d,changes:i,source:o});l.length>0&&this.#s.requestPhase(H.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,d]of Object.entries(r)){const u=l[c];u!==d&&(o=!0,l[c]=d,this.#P("cell-change",{row:l,rowId:n,rowIndex:a,field:c,oldValue:u,newValue:d,changes:r,source:i}))}}o&&this.#s.requestPhase(H.ROWS,"updateRows")}animateRow(e,i){ue(this,e,i)}animateRows(e,i){ri(this,e,i)}animateRowById(e,i){return si(this,e,i)}setColumnVisible(e,i){const o=this.#t.setColumnVisible(e,i);return o&&this.requestStateChange(),o}toggleColumnVisibility(e){const i=this.#t.toggleColumnVisibility(e);return i&&this.requestStateChange(),i}isColumnVisible(e){return this.#t.isColumnVisible(e)}showAllColumns(){this.#t.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#t.getAllColumns()}setColumnOrder(e){this.#t.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#t.getColumnOrder()}getColumnState(){const e=this.#e?.getAll()??[];return this.#t.collectState(e)}set columnState(e){e&&(this.#O=e,this.#t.initialColumnState=e,this.#u&&this.#De(e))}get columnState(){return this.getColumnState()}#De(e){const i=this.#e?.getAll()??[];this.#t.applyState(e,i),this.#L()}requestStateChange(){const e=this.#e?.getAll()??[];this.#t.requestStateChange(e)}resetColumnState(){this.#O=void 0,this.__originalOrder=[];const e=this.#e?.getAll()??[];this.#t.resetState(e),this.#t.merge(),this.#L()}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.#i.apiToolPanelIds.add(e.id),this.#c.registerToolPanel(e)}unregisterToolPanel(e){this.#i.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)}#j=!1;refreshShellHeader(){this.#j||(this.#j=!0,queueMicrotask(()=>{this.#j=!1,this.isConnected&&(this.#M(),this.#t.markSourcesChanged(),this.#t.merge(),pe(this.#i),this.#Q(),this.#W(),this.#Oe())}))}#Oe(){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){ge(this.#n,this.#i),fe(this.#n,this.#o?.shell,this.#i);const o=this.#o?.shell?.toolPanel?.defaultOpen;o&&this.#i.toolPanels.has(o)&&(this.openToolPanel(),this.#i.expandedSections.add(o))}this._resizeController=Ye(this),this.#B(i),this.#s.requestPhase(H.COLUMNS,"shellRefresh")}#R=new Map;registerStyles(e,i){let o=this.#R.get(e);o||(o=new CSSStyleSheet,this.#R.set(e,o)),o.replaceSync(i),this.#ue()}unregisterStyles(e){this.#R.delete(e)&&this.#ue()}getRegisteredStyles(){return Array.from(this.#R.keys())}#ue(){const e=Array.from(this.#R.values()),i=document.adoptedStyleSheets.filter(o=>!Array.from(this.#R.values()).includes(o));document.adoptedStyleSheets=[...i,...e]}#M(){et(this,this.#i),tt(this,this.#i),it(this,this.#i,this.#ie())}#fe(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;pe(this.#i);const i=di(this.#o.shell,this.#i,this.#o.icons?.toolPanel),o=document.createElement("div");o.innerHTML=i;const n=o.firstElementChild;n&&(e.replaceWith(n),this.#pe(),fe(this.#n,this.#o?.shell,this.#i))}#Me(){const e=()=>{const o=this.#i.lightDomTitle,n=this.#i.hasToolButtonsContainer;this.#M();const r=this.#i.lightDomTitle,s=this.#i.hasToolButtonsContainer;(r&&!o||s&&!n)&&(this.#t.markSourcesChanged(),this.#t.merge(),this.#fe())},i=()=>{this.__lightDomColumnsCache=void 0,this.#L()};this.#t.registerLightDomHandler("tbw-grid-header",e),this.#t.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#t.registerLightDomHandler("tbw-grid-tool-panel",e),this.#t.registerLightDomHandler("tbw-grid-column",i),this.#t.registerLightDomHandler("tbw-grid-detail",i),this.#t.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,j(this),this.#t.parseLightDomColumns(this);const e=this.#i.lightDomTitle,i=this.#i.hasToolButtonsContainer;this.#M();const o=this.#i.lightDomTitle,n=this.#i.hasToolButtonsContainer;(o&&!e||n&&!i)&&(this.#t.markSourcesChanged(),this.#t.merge(),this.#fe()),this.#s.requestPhase(H.COLUMNS,"refreshColumns")}#ke(){const e=this._virtualization.container,i=this._virtualization.viewportEl??e;i&&(this._virtualization.cachedViewportHeight=i.clientHeight),e&&(this._virtualization.cachedFauxHeight=e.clientHeight)}#A(e){const i=this._virtualization.container??this,o=this._virtualization.viewportEl??i,n=i.clientHeight,r=o.clientHeight,s=this.querySelector(".tbw-scroll-area"),l=s?s.clientHeight:n,c=l-r,d=Math.max(0,n-l);let u,f=0;return this._virtualization.variableHeights&&this._virtualization.positionCache?u=qi(this._virtualization.positionCache):(u=e*this._virtualization.rowHeight,f=this.#e?.getExtraHeight()??0),u+c+f+d}#K(){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=Ni(e,this._virtualization.heightCache,i,{rowId:r},(l,a)=>{const c=this.#e?.getRowHeight?.(l,a);if(c!==void 0)return c;if(o){const d=o(l,a);if(d!==void 0&&d>0)return d}});const s=Ui(this._virtualization.positionCache,e,i,(l,a)=>this.#e?.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.#e?.getRowHeight?.(n,e)),r===void 0&&(r=this._virtualization.rowHeight);const s=o[e];if(!(!s||Math.abs(s.height-r)<1)&&(Ce(o,e,r),this._virtualization.totalHeightEl)){const l=this.#A(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#ge(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=Fi({positionCache:this._virtualization.positionCache,heightCache:this._virtualization.heightCache,rows:this._rows,defaultHeight:this._virtualization.rowHeight,start:e,end:i,getPluginHeight:(s,l)=>this.#e?.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.#A(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.#Y(0,o),i||this.#e?.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.#Y(0,o,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),e&&this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#A(o)}px`),this.#ce(o,this._visibleColumns.length),i||this.#e?.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 d=this._virtualization.positionCache;if(this._virtualization.variableHeights&&d&&d.length>0)c=ct(d,a),c===-1&&(c=0);else{c=Math.floor(a/l);let m=0;const _=10;for(;m<_;){const S=this.#e?.getExtraHeightBefore?.(c)??0,T=Math.floor((a-S)/l);if(T>=c||T<0)break;c=T,m++}}c=c-c%2,c<0&&(c=0);const u=this.#e?.adjustVirtualStart(c,a,l);u!==void 0&&u<c&&(c=u,c=c-c%2,c<0&&(c=0));let f;if(this._virtualization.variableHeights&&d&&d.length>0){const m=s+l*3;let _=0;for(f=c;f<o&&_<m;)_+=d[f].height,f++;const S=Math.ceil(s/l)+3;f-c<S&&(f=Math.min(c+S,o))}else{const m=Math.ceil(s/l)+3;f=c+m}f>o&&(f=o);const g=this._virtualization.start,p=this._virtualization.end;if(!e&&c===g&&f===p)return!1;if(this._virtualization.start=c,this._virtualization.end=f,(e?this._virtualization.cachedFauxHeight=n.clientHeight:this._virtualization.cachedFauxHeight||(this._virtualization.cachedFauxHeight=n.clientHeight))===0&&s>0)return this.#s.requestPhase(H.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&this._virtualization.totalHeightEl){const m=this.#A(o);this._virtualization.totalHeightEl.style.height=`${m}px`}let w;if(this._virtualization.variableHeights&&d&&d[c])w=d[c].offset;else{const m=this.#e?.getExtraHeightBefore?.(c)??0;w=c*l+m}const C=-(a-w);return this._bodyEl.style.transform=`translateY(${C}px)`,this.#Y(c,f,e?++this.__rowRenderEpoch:this.__rowRenderEpoch),e&&this._virtualization.variableHeights&&this.#ge(c,f),this.#ce(o,this._visibleColumns.length),e&&!i&&(this.#e?.afterRender(),queueMicrotask(()=>{const m=n.clientHeight,_=r.clientHeight;if(m===0&&_>0)return;const S=this.#A(o);this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${S}px`)})),!0}#Q(){this.#M(),this.#t.markSourcesChanged(),this.#t.merge();const e=this.#o?.shell;bi(this.#n,e,{isPanelOpen:this.#i.isPanelOpen,expandedSections:this.#i.expandedSections},this.#o?.icons)&&(this.#pe(),this.#c.setInitialized(!0))}#pe(){hi(this.#n,this.#o?.shell,this.#i,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#N?.(),this.#N=ui(this.#n,this.#o?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)})}}customElements.get(k.tagName)||customElements.define(k.tagName,k),globalThis.DataGridElement=k;const Gi={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class Bi{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{...O,...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 P={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"},X={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"},Xi={ROOT:`.${P.ROOT}`,HEADER:`.${P.HEADER}`,HEADER_ROW:`.${P.HEADER_ROW}`,HEADER_CELL:`.${P.HEADER_CELL}`,ROWS_VIEWPORT:`.${P.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${P.ROWS_CONTAINER}`,DATA_ROW:`.${P.DATA_ROW}`,DATA_CELL:`.${P.DATA_CELL}`,GROUP_ROW:`.${P.GROUP_ROW}`,ROW_BY_INDEX:t=>`.${P.DATA_ROW}[${X.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${P.DATA_CELL}[${X.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${P.DATA_ROW}[${X.ROW_INDEX}="${t}"] .${P.DATA_CELL}[${X.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${P.DATA_ROW}.${P.SELECTED}`,EDITING_CELL:`.${P.DATA_CELL}.${P.EDITING}`},Yi={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 ji(t){const e=document.createElement("tbw-grid");return t&&(e.gridConfig=t),e}function Ki(t,e=document){return e.querySelector(t)}const Qi={CELL_CHANGE:"cell-change",CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",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"},Zi={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"},ye={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]},Y=new Map,D={register(t,e){Y.set(t,e)},unregister(t){Y.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:Y.get(t)??ye[t]},run(t,e,i,o){const n=this.get(t);return n?n(e,i,o):void 0},has(t){return Y.has(t)||t in ye},list(){return[...Object.keys(ye),...Y.keys()]}},dt={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 ht(t){return dt[t]??dt.sum}function Ji(t,e){return ht(t)(e)}const eo=D.register.bind(D),to=D.unregister.bind(D),io=D.get.bind(D),oo=D.run.bind(D),no=D.list.bind(D);y.BaseGridPlugin=Bi,y.DEFAULT_ANIMATION_CONFIG=Ee,y.DEFAULT_GRID_ICONS=O,y.DGEvents=Qi,y.DataGridElement=k,y.FitModeEnum=q,y.GridCSSVars=Yi,y.GridClasses=P,y.GridDataAttrs=X,y.GridElement=k,y.GridSelectors=Xi,y.PLUGIN_QUERIES=Gi,y.PluginEvents=Zi,y.PluginManager=B,y.RenderPhase=H,y.aggregatorRegistry=D,y.builtInSort=Fe,y.createGrid=ji,y.defaultComparator=We,y.getAggregator=io,y.getValueAggregator=ht,y.listAggregators=no,y.queryGrid=Ki,y.registerAggregator=eo,y.runAggregator=oo,y.runValueAggregator=Ji,y.unregisterAggregator=to,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
89
91
  //# sourceMappingURL=grid.umd.js.map