@toolbox-web/grid 1.21.1 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -8
- package/all.js +2 -6850
- package/all.js.map +1 -1
- package/index.js +1 -4352
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +75 -8
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/rows.d.ts.map +1 -1
- package/lib/core/plugin/base-plugin.d.ts +8 -2
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/styles/index.d.ts.map +1 -1
- package/lib/core/types.d.ts +84 -2
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +1 -733
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/clipboard/types.d.ts +5 -0
- package/lib/plugins/clipboard/types.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -560
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/column-virtualization/types.d.ts +5 -0
- package/lib/plugins/column-virtualization/types.d.ts.map +1 -1
- package/lib/plugins/context-menu/index.js +1 -754
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/context-menu/types.d.ts +5 -0
- package/lib/plugins/context-menu/types.d.ts.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/index.d.ts +1 -1
- package/lib/plugins/editing/index.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +1 -1539
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/types.d.ts +49 -0
- package/lib/plugins/editing/types.d.ts.map +1 -1
- package/lib/plugins/export/index.js +1 -589
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/export/types.d.ts +5 -0
- package/lib/plugins/export/types.d.ts.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/filter-model.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1283
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/filtering/types.d.ts +7 -2
- package/lib/plugins/filtering/types.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -726
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-columns/types.d.ts +3 -0
- package/lib/plugins/grouping-columns/types.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/index.js +2 -905
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/grouping-rows/types.d.ts +5 -0
- package/lib/plugins/grouping-rows/types.d.ts.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -950
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/types.d.ts +5 -0
- package/lib/plugins/master-detail/types.d.ts.map +1 -1
- package/lib/plugins/multi-sort/index.js +1 -553
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/multi-sort/types.d.ts +5 -0
- package/lib/plugins/multi-sort/types.d.ts.map +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -688
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-columns/types.d.ts +3 -0
- package/lib/plugins/pinned-columns/types.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -704
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pinned-rows/types.d.ts +5 -0
- package/lib/plugins/pinned-rows/types.d.ts.map +1 -1
- package/lib/plugins/pivot/index.js +1 -1191
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/pivot/types.d.ts +5 -0
- package/lib/plugins/pivot/types.d.ts.map +1 -1
- package/lib/plugins/print/index.js +1 -691
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/print/types.d.ts +3 -0
- package/lib/plugins/print/types.d.ts.map +1 -1
- package/lib/plugins/reorder/index.js +1 -703
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/reorder/types.d.ts +5 -0
- package/lib/plugins/reorder/types.d.ts.map +1 -1
- package/lib/plugins/responsive/index.js +1 -971
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/responsive/types.d.ts +5 -0
- package/lib/plugins/responsive/types.d.ts.map +1 -1
- package/lib/plugins/row-reorder/index.js +1 -728
- package/lib/plugins/row-reorder/index.js.map +1 -1
- package/lib/plugins/row-reorder/types.d.ts +5 -0
- package/lib/plugins/row-reorder/types.d.ts.map +1 -1
- package/lib/plugins/selection/index.js +1 -1071
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/selection/types.d.ts +3 -0
- package/lib/plugins/selection/types.d.ts.map +1 -1
- package/lib/plugins/server-side/index.js +1 -521
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/server-side/types.d.ts +5 -0
- package/lib/plugins/server-side/types.d.ts.map +1 -1
- package/lib/plugins/tree/index.js +1 -686
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/types.d.ts +5 -0
- package/lib/plugins/tree/types.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -584
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/undo-redo/types.d.ts +5 -0
- package/lib/plugins/undo-redo/types.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js +1 -792
- package/lib/plugins/visibility/index.js.map +1 -1
- package/lib/plugins/visibility/types.d.ts +5 -0
- package/lib/plugins/visibility/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -186
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -90
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +1 -6
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/column-virtualization.umd.js +1 -1
- package/umd/plugins/column-virtualization.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/export.umd.js +1 -13
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -4
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js +1 -1
- package/umd/plugins/pinned-columns.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/pivot.umd.js +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/print.umd.js +1 -75
- package/umd/plugins/print.umd.js.map +1 -1
- package/umd/plugins/reorder.umd.js +1 -1
- package/umd/plugins/reorder.umd.js.map +1 -1
- package/umd/plugins/responsive.umd.js +1 -1
- package/umd/plugins/responsive.umd.js.map +1 -1
- package/umd/plugins/row-reorder.umd.js +1 -1
- package/umd/plugins/row-reorder.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -3
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/server-side.umd.js +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
package/umd/grid.umd.js
CHANGED
|
@@ -1,91 +1,2 @@
|
|
|
1
|
-
(function(_,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(_=typeof globalThis<"u"?globalThis:_||self,G(_.TbwGrid={}))})(this,(function(_){"use strict";function G(){return{rowCount:-1,colCount:-1,ariaLabel:void 0,ariaDescribedBy:void 0}}function wt(t,e,i,o,n){if(o===t.rowCount&&n===t.colCount)return!1;const r=t.rowCount;return t.rowCount=o,t.colCount=n,e&&(e.setAttribute("aria-rowcount",String(o)),e.setAttribute("aria-colcount",String(n))),o!==r&&i&&(o>0?i.setAttribute("role","rowgroup"):i.removeAttribute("role")),!0}function bt(t,e){const i=t?.gridAriaLabel;return i||(t?.shell?.header?.title??e?.lightDomTitle??void 0)}function mt(t,e,i,o){if(!e)return!1;let n=!1;const r=bt(i,o);r!==t.ariaLabel&&(t.ariaLabel=r,r?e.setAttribute("aria-label",r):e.removeAttribute("aria-label"),n=!0);const s=i?.gridAriaDescribedBy;return s!==t.ariaDescribedBy&&(t.ariaDescribedBy=s,s?e.setAttribute("aria-describedby",s):e.removeAttribute("aria-describedby"),n=!0),n}const F={STRETCH:"stretch",FIXED:"fixed"},xe={mode:"reduced-motion",duration:200,easing:"ease-out"},He='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',k={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:He,filterActive:He,print:"🖨️"};function vt(t){return Array.from(t.querySelectorAll("tbw-grid-column")).map(i=>{const o=i.getAttribute("field")||"";if(!o)return null;const n=i.getAttribute("type")||void 0,s=n&&new Set(["number","string","date","boolean","select"]).has(n)?n:void 0,l=i.getAttribute("header")||void 0,a=i.hasAttribute("sortable"),c=i.hasAttribute("editable"),h={field:o,type:s,header:l,sortable:a,editable:c},f=i.getAttribute("width");if(f){const b=parseFloat(f);!isNaN(b)&&/^\d+(\.\d+)?$/.test(f.trim())?h.width=b:h.width=f}const p=i.getAttribute("minWidth")||i.getAttribute("min-width");if(p){const b=parseFloat(p);isNaN(b)||(h.minWidth=b)}i.hasAttribute("resizable")&&(h.resizable=!0),i.hasAttribute("sizable")&&(h.resizable=!0);const g=i.getAttribute("editor"),u=i.getAttribute("renderer");g&&(h.__editorName=g),u&&(h.__rendererName=u);const d=i.getAttribute("options");d&&(h.options=d.split(",").map(b=>{const[H,W]=b.includes(":")?b.split(":"):[b.trim(),b.trim()];return{value:H.trim(),label:W?.trim()||H.trim()}}));const w=i.querySelector("tbw-grid-column-view"),C=i.querySelector("tbw-grid-column-editor"),m=i.querySelector("tbw-grid-column-header");w&&(h.__viewTemplate=w),C&&(h.__editorTemplate=C),m&&(h.__headerTemplate=m);const T=globalThis.DataGridElement?.getAdapters?.()??[],S=w??i,P=T.find(b=>b.canHandle(S));if(P){const b=P.createRenderer(S);b&&(h.viewRenderer=b)}const y=C??i,v=T.find(b=>b.canHandle(y));if(v){const b=v.createEditor(y);b&&(h.editor=b)}return h}).filter(i=>!!i)}function Pe(t,e){if((!t||!t.length)&&(!e||!e.length))return[];if(!t||!t.length)return e||[];if(!e||!e.length)return t;const i={};e.forEach(n=>{const r=i[n.field];if(r){n.header&&!r.header&&(r.header=n.header),n.type&&!r.type&&(r.type=n.type),n.sortable&&(r.sortable=!0),n.editable&&(r.editable=!0),n.resizable&&(r.resizable=!0),n.width!=null&&r.width==null&&(r.width=n.width),n.minWidth!=null&&r.minWidth==null&&(r.minWidth=n.minWidth),n.__viewTemplate&&(r.__viewTemplate=n.__viewTemplate),n.__editorTemplate&&(r.__editorTemplate=n.__editorTemplate),n.__headerTemplate&&(r.__headerTemplate=n.__headerTemplate);const s=n.renderer||n.viewRenderer,l=r.renderer||r.viewRenderer;s&&!l&&(r.viewRenderer=s,n.renderer&&(r.renderer=s)),n.editor&&!r.editor&&(r.editor=n.editor)}else i[n.field]={...n}});const o=t.map(n=>{const r=i[n.field];if(!r)return n;const s={...n};r.header&&!s.header&&(s.header=r.header),r.type&&!s.type&&(s.type=r.type),s.sortable=n.sortable||r.sortable,(n.resizable===!0||r.resizable===!0)&&(s.resizable=!0),s.editable=n.editable||r.editable,r.width!=null&&s.width==null&&(s.width=r.width),r.minWidth!=null&&s.minWidth==null&&(s.minWidth=r.minWidth),r.__viewTemplate&&(s.__viewTemplate=r.__viewTemplate),r.__editorTemplate&&(s.__editorTemplate=r.__editorTemplate),r.__headerTemplate&&(s.__headerTemplate=r.__headerTemplate);const l=r.renderer||r.viewRenderer,a=s.renderer||s.viewRenderer;return l&&!a&&(s.viewRenderer=l,r.renderer&&(s.renderer=l)),r.editor&&!s.editor&&(s.editor=r.editor),delete i[n.field],s});return Object.keys(i).forEach(n=>o.push(i[n])),o}function Le(t,e){try{t.part?.add?.(e)}catch{}const i=t.getAttribute("part");i?i.split(/\s+/).includes(e)||t.setAttribute("part",i+" "+e):t.setAttribute("part",e)}function ze(t){const e=t.effectiveConfig?.fitMode||t.fitMode||F.STRETCH;if(e!==F.STRETCH&&e!==F.FIXED||t.__didInitialAutoSize||!t.isConnected)return;const i=Array.from(t._headerRowEl?.children||[]);if(!i.length)return;let o=!1;t._visibleColumns.forEach((n,r)=>{if(n.width)return;const s=i[r];let l=s?s.scrollWidth:0;for(const a of t._rowPool){const c=a.children[r];if(c){const h=c.scrollWidth;h>l&&(l=h)}}l>0&&(n.width=l+2,n.__autoSized=!0,o=!0)}),o&&B(t),t.__didInitialAutoSize=!0}const Ct=/^(?:\d+(?:\.\d+)?(?:px|%|fr|em|rem|ch|vw|vh|vmin|vmax)|calc\(.+\)|min-content|max-content|minmax\(.+\)|fit-content\(.+\)|auto)$/i;function Oe(t,e){return typeof t=="number"?`${t}px`:(Ct.test(t)||console.warn(`[tbw-grid] Column '${e??"?"}' has an invalid CSS width value: '${t}'. Expected a number (px) or a valid CSS unit string (e.g. '30%', '2fr', 'calc(...)').`),t)}function B(t){(t.effectiveConfig?.fitMode||t.fitMode||F.STRETCH)===F.STRETCH?t._gridTemplate=t._visibleColumns.map(i=>{if(i.width!=null)return Oe(i.width,i.field);const o=i.minWidth;return o!=null?`minmax(${o}px, 1fr)`:"1fr"}).join(" ").trim():t._gridTemplate=t._visibleColumns.map(i=>i.width!=null?Oe(i.width,i.field):"max-content").join(" "),t.style.setProperty("--tbw-column-template",t._gridTemplate)}function yt(t){return t==null?"string":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date||typeof t=="string"&&/\d{4}-\d{2}-\d{2}/.test(t)&&!isNaN(Date.parse(t))?"date":"string"}function _t(t,e){const i=t[0]||{},o=Object.keys(i).map(r=>{const s=i[r],l=yt(s);return{field:r,header:r.charAt(0).toUpperCase()+r.slice(1),type:l}}),n={};return o.forEach(r=>{n[r.field]=r.type||"string"}),{columns:o,typeMap:n}}const Et=/{{\s*([^}]+)\s*}}/g,O="__DG_EMPTY__",St=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,Rt=/__(proto|defineGetter|defineSetter)|constructor|window|globalThis|global|process|Function|import|eval|Reflect|Proxy|Error|arguments|document|location|cookie|localStorage|sessionStorage|indexedDB|fetch|XMLHttpRequest|WebSocket|Worker|SharedWorker|ServiceWorker|opener|parent|top|frames|self|this\b/;function At(t){return!t||typeof t!="string"?"":t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const Tt=new Set(["script","iframe","object","embed","form","input","button","textarea","select","link","meta","base","style","template","slot","portal","frame","frameset","applet","noscript","noembed","plaintext","xmp","listing"]),De=/^on\w+$/i,xt=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),Ht=/^\s*(javascript|vbscript|data|blob):/i;function N(t){if(!t||typeof t!="string")return"";if(t.indexOf("<")===-1)return t;const e=document.createElement("template");return e.innerHTML=t,Pt(e.content),e.innerHTML}function Pt(t){const e=[],i=t.querySelectorAll("*");for(const o of i){const n=o.tagName.toLowerCase();if(Tt.has(n)){e.push(o);continue}if((n==="svg"||o.namespaceURI==="http://www.w3.org/2000/svg")&&Array.from(o.attributes).some(l=>De.test(l.name)||l.name==="href"||l.name==="xlink:href")){e.push(o);continue}const r=[];for(const s of o.attributes){const l=s.name.toLowerCase();if(De.test(l)){r.push(s.name);continue}if(xt.has(l)&&Ht.test(s.value)){r.push(s.name);continue}if(l==="style"&&/expression\s*\(|javascript:|behavior\s*:/i.test(s.value)){r.push(s.name);continue}}r.forEach(s=>o.removeAttribute(s))}e.forEach(o=>o.remove())}function le(t,e){if(!t||t.indexOf("{{")===-1)return t;const i=[],o=t.replace(Et,(l,a)=>{const c=Lt(a,e);return i.push({expr:a.trim(),result:c}),c}),n=zt(o),r=i.length&&i.every(l=>l.result===""||l.result===O);return q.test(t)||r?"":n}function Lt(t,e){if(t=(t||"").trim(),!t||q.test(t))return O;if(t==="value")return e.value==null?O: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?O:String(n)}if(t.length>80||!St.test(t)||Rt.test(t))return O;const i=t.match(/\./g);if(i&&i.length>1)return O;try{const n=new Function("value","row",`return (${t});`)(e.value,e.row),r=n==null?"":String(n);return q.test(r)?O:r||O}catch{return O}}const q=/Reflect|Proxy|ownKeys/;function zt(t){return t&&t.replace(new RegExp(O,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,"")}function ae(t){if(q.test(t.textContent||"")){for(const e of t.childNodes)e.nodeType===Node.TEXT_NODE&&q.test(e.textContent||"")&&(e.textContent="");q.test(t.textContent||"")&&(t.textContent="")}}function Me(t){const e=q.test(t),i=(o=>e?"":le(t,o));return i.__blocked=e,i}const Ot=100;class Dt{#a;#n;#u;#d;#h;#l={};#o={};#f=!0;#w=[];#v;#s;#C;#r;#g;constructor(e){this.#r=e}get original(){return this.#l}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.#a=e,this.#f=!0,this.#d=void 0}getGridConfig(){return this.#a}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.#N();this.#f=!1,this.#l=i,Object.freeze(this.#l),this.#l.columns&&Object.freeze(this.#l.columns),this.#o=this.#x(this.#l),this.#m()}#x(e){const i={...e};return e.columns&&(i.columns=e.columns.map(o=>({...o}))),e.shell&&(i.shell={...e.shell,header:e.shell.header?{...e.shell.header}:void 0,toolPanel:e.shell.toolPanel?{...e.shell.toolPanel}:void 0,toolPanels:e.shell.toolPanels?.map(o=>({...o})),headerContents:e.shell.headerContents?.map(o=>({...o}))}),i}#m(){const e=this.#o;this.#O(),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)}#O(){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))}}#N(){const e=this.#a?{...this.#a}:{},i=Array.isArray(e.columns)?[...e.columns]:[],o=(this.#d??[]).map(s=>({...s}));let n=Pe(i,o);this.#n&&this.#n.length&&(n=Pe(this.#n,o));const r=this.#r.getRows();return n.length===0&&r.length&&(n=_t(r).columns),n.length&&(n.forEach(s=>{s.sortable===void 0&&(s.sortable=!0),s.resizable===void 0&&(s.resizable=!0),s.__originalWidth===void 0&&typeof s.width=="number"&&(s.__originalWidth=s.width)}),n.forEach(s=>{s.__viewTemplate&&!s.__compiledView&&(s.__compiledView=Me(s.__viewTemplate.innerHTML)),s.__editorTemplate&&!s.__compiledEditor&&(s.__compiledEditor=Me(s.__editorTemplate.innerHTML))}),e.columns=n),this.#u&&(e.fitMode=this.#u),e.fitMode||(e.fitMode="stretch"),this.#b(e),e.columnState&&!this.#C&&(this.#C=e.columnState),e}#b(e){e.shell=e.shell?{...e.shell}:{},e.shell.header=e.shell.header?{...e.shell.header}:{};const i=this.#r.getShellLightDomTitle();i&&(this.#g=i),this.#g&&!e.shell.header.title&&(e.shell.header.title=this.#g);const o=this.#r.getShellLightDomHeaderContent();o?.length>0&&(e.shell.header.lightDomContent=o),this.#r.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const n=this.#r.getShellToolPanels();if(n.size>0){const f=Array.from(n.values());f.sort((p,g)=>(p.order??100)-(g.order??100)),e.shell.toolPanels=f}const r=this.#r.getShellHeaderContents();if(r.size>0){const f=Array.from(r.values());f.sort((p,g)=>(p.order??100)-(g.order??100)),e.shell.headerContents=f}const s=this.#r.getShellToolbarContents(),l=Array.from(s.values()),a=this.#a?.shell?.header?.toolbarContents??[],c=new Set(a.map(f=>f.id)),h=[...a];for(const f of l)c.has(f.id)||h.push(f);h.sort((f,p)=>(f.order??0)-(p.order??0)),e.shell.header.toolbarContents=h}collectState(e){const i=this.columns,o=this.#y();return{columns:i.map((n,r)=>{const s={field:n.field,order:r,visible:!n.hidden},l=n;l.__renderedWidth!==void 0?s.width=l.__renderedWidth:n.width!==void 0&&(s.width=typeof n.width=="string"?parseFloat(n.width):n.width);const a=o.get(n.field);a&&(s.sort=a);for(const c of e)if(c.getColumnState){const h=c.getColumnState(n.field);h&&Object.assign(s,h)}return s})}}applyState(e,i){if(!e.columns||e.columns.length===0)return;const o=this.columns,n=new Map(e.columns.map(l=>[l.field,l])),r=o.map(l=>{const a=n.get(l.field);if(!a)return l;const c={...l};return a.width!==void 0&&(c.width=a.width,c.__renderedWidth=a.width),a.visible!==void 0&&(c.hidden=!a.visible),c});r.sort((l,a)=>{const c=n.get(l.field)?.order??1/0,h=n.get(a.field)?.order??1/0;return c-h}),this.columns=r;const s=e.columns.filter(l=>l.sort!==void 0).sort((l,a)=>(l.sort?.priority??0)-(a.sort?.priority??0));if(s.length>0){const l=s[0];l.sort&&this.#r.setSortState({field:l.field,direction:l.sort.direction==="asc"?1:-1})}else this.#r.setSortState(null);for(const l of i)if(l.applyColumnState)for(const a of e.columns)l.applyColumnState(a.field,a)}resetState(e){this.#C=void 0,this.#r.setSortState(null),this.#o=this.#x(this.#l),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)},Ot)}setColumnVisible(e,i){const o=this.columns,n=o.find(s=>s.field===e);return!n||!i&&n.lockVisible||!i&&o.filter(l=>!l.hidden&&l.field!==e).length===0||!!n.hidden===!i?!1:(n.hidden=!i,this.#r.emit("column-visibility",{field:e,visible:i,visibleColumns:o.filter(s=>!s.hidden).map(s=>s.field)}),this.#r.clearRowPool(),this.#r.setup(),!0)}toggleColumnVisibility(e){const i=this.columns.find(o=>o.field===e);return i?this.setColumnVisible(e,!!i.hidden):!1}isColumnVisible(e){const i=this.columns.find(o=>o.field===e);return i?!i.hidden:!1}showAllColumns(){const e=this.columns;e.some(i=>i.hidden)&&(e.forEach(i=>i.hidden=!1),this.#r.emit("column-visibility",{visibleColumns:e.map(i=>i.field)}),this.#r.clearRowPool(),this.#r.setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:e.meta?.utility===!0}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const i=new Map(this.columns.map(n=>[n.field,n])),o=[];for(const n of e){const r=i.get(n);r&&(o.push(r),i.delete(n))}for(const n of i.values())o.push(n);this.columns=o,this.#r.renderHeader(),this.#r.updateTemplate(),this.#r.refreshVirtualWindow()}parseLightDomColumns(e){this.#d||(this.#h=Array.from(e.querySelectorAll("tbw-grid-column")),this.#d=this.#h.length?vt(e):[])}clearLightDomCache(){this.#d=void 0}#p=new Map;registerLightDomHandler(e,i){this.#p.set(e.toLowerCase(),i)}unregisterLightDomHandler(e){this.#p.delete(e.toLowerCase())}observeLightDOM(e){this.#v&&this.#v.disconnect();const i=new Set;let o=null;const n=()=>{o=null;for(const r of i)this.#p.get(r)?.();i.clear()};this.#v=new MutationObserver(r=>{for(const s of r){for(const l of s.addedNodes){if(l.nodeType!==Node.ELEMENT_NODE)continue;const c=l.tagName.toLowerCase();this.#p.has(c)&&i.add(c)}if(s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE){const a=s.target.tagName.toLowerCase();this.#p.has(a)&&i.add(a)}}i.size>0&&!o&&(o=setTimeout(n,0))}),this.#v.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#w.push(e)}notifyChange(){for(const e of this.#w)e()}dispose(){this.#v?.disconnect(),this.#w=[],this.#s&&clearTimeout(this.#s)}}function ce(){if(typeof window<"u"&&window.location){const t=window.location.hostname;if(t==="localhost"||t==="127.0.0.1"||t==="::1")return!0}return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function ke(t){return`<span role="checkbox" aria-checked="${t}" aria-label="${t}">${t?"🗹":"☐"}</span>`}function Ie(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 Ne(t){if(!t)return-1;const e=t.getAttribute("data-row");if(e)return parseInt(e,10);const i=t.closest(".data-grid-row");if(!i)return-1;const o=i.parentElement;if(!o)return-1;const n=o.querySelectorAll(":scope > .data-grid-row");for(let r=0;r<n.length;r++)if(n[r]===i)return r;return-1}function Mt(t){if(!t)return-1;const e=t.getAttribute("data-col");return e?parseInt(e,10):-1}function de(t){t&&t.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function kt(t){try{if(getComputedStyle(t).direction==="rtl")return"rtl"}catch{}try{if(t.closest?.("[dir]")?.getAttribute("dir")==="rtl")return"rtl"}catch{}return"ltr"}function qe(t){return kt(t)==="rtl"}function $e(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 We(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 Fe='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function he(t){return(t.__editingCellCount??0)>0}function ue(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing"),t.querySelectorAll(".cell.editing").forEach(i=>i.classList.remove("editing"))}const Ve=document.createElement("template");Ve.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Ue=document.createElement("template");Ue.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';function It(){return Ve.content.firstElementChild.cloneNode(!0)}function Nt(){return Ue.content.firstElementChild.cloneNode(!0)}function V(t){t.__cellDisplayCache=void 0,t.__cellCacheEpoch=void 0,t.__hasSpecialColumns=void 0}function qt(t,e,i,o,n){const r=Math.max(0,i-e),s=t._bodyEl,l=t._visibleColumns,a=l.length;let c=t.__cachedHeaderRowCount;for(c===void 0&&(c=t.querySelector(".header-group-row")?2:1,t.__cachedHeaderRowCount=c);t._rowPool.length<r;){const p=Nt();t._rowPool.push(p)}if(t._rowPool.length>r){for(let p=r;p<t._rowPool.length;p++){const g=t._rowPool[p];g.parentNode===s&&g.remove()}t._rowPool.length=r}const h=n&&t.__hasRenderRowPlugins!==!1,f=t._hasAfterRowRenderHook?.()??!1;for(let p=0;p<r;p++){const g=e+p,u=t._rows[g],d=t._rowPool[p];if(d.setAttribute("aria-rowindex",String(g+c+1)),h&&n(u,d,g)){d.__epoch=o,d.__rowDataRef=u,d.parentNode!==s&&s.appendChild(d);continue}const w=d.__epoch,C=d.__rowDataRef;let m=d.children.length;m>a&&d.lastElementChild?.classList.contains("tbw-row-loading-overlay")&&m--;const T=w===o&&m===a,S=C!==u,P=!!t._isGridEditMode;let y=!1;if(T&&S){for(let R=0;R<a;R++)if(l[R].externalView&&!d.querySelector(`.cell[data-col="${R}"] [data-external-view]`)){y=!0;break}}if(!T||y){const R=he(d),z=P||t._activeEditRows===g;R&&!z?(d.__isCustomRow&&(d.className="data-grid-row",d.setAttribute("role","row"),d.__isCustomRow=!1),ue(d),X(t,d,u,g),d.__epoch=o,d.__rowDataRef=u):R&&z?(fe(t,d,u,g),d.__rowDataRef=u):(d.__isCustomRow&&(d.className="data-grid-row",d.setAttribute("role","row"),d.__isCustomRow=!1),X(t,d,u,g),d.__epoch=o,d.__rowDataRef=u)}else if(S){const R=he(d),z=P||t._activeEditRows===g;R&&!z?(ue(d),X(t,d,u,g),d.__epoch=o,d.__rowDataRef=u):(fe(t,d,u,g),d.__rowDataRef=u)}else{const R=he(d),z=P||t._activeEditRows===g;R&&!z?(ue(d),X(t,d,u,g),d.__epoch=o,d.__rowDataRef=u):fe(t,d,u,g)}let v=!1;const b=t.changedRowIds;if(b&&b.length>0)try{const R=t.getRowId?.(u);R&&(v=b.includes(R))}catch{}const H=d.classList.contains("changed");v!==H&&d.classList.toggle("changed",v);const W=t.effectiveConfig?.rowClass;if(W){const R=d.getAttribute("data-dynamic-classes");R&&R.split(" ").forEach(z=>z&&d.classList.remove(z));try{const z=W(u);if(z&&z.length>0){const Te=z.filter(se=>se&&typeof se=="string");Te.forEach(se=>d.classList.add(se)),d.setAttribute("data-dynamic-classes",Te.join(" "))}else d.removeAttribute("data-dynamic-classes")}catch(z){console.warn("[tbw-grid] rowClass callback error:",z),d.removeAttribute("data-dynamic-classes")}}f&&t._afterRowRender?.({row:u,rowIndex:g,rowElement:d}),d.parentNode!==s&&s.appendChild(d)}}function fe(t,e,i,o){const n=e.children,r=t._visibleColumns,s=r.length,l=n.length,a=s<l?s:l,c=t._focusRow,h=t._focusCol,f=t._hasAfterCellRenderHook?.()??!1;let p=t.__hasSpecialColumns;if(p===void 0){p=!1;const u=t.__frameworkAdapter;for(let d=0;d<s;d++){const w=r[d];if(w.__viewTemplate||w.__compiledView||w.renderer||w.viewRenderer||w.externalView||w.format||w.type==="date"||w.type==="boolean"||w.type&&u?.getTypeDefault?.(w.type)?.renderer||w.type&&u?.getTypeDefault?.(w.type)?.format){p=!0;break}}t.__hasSpecialColumns=p}const g=String(o);if(!p){for(let u=0;u<a;u++){const d=n[u];if(d.classList.contains("editing"))continue;d.firstElementChild&&t.__frameworkAdapter?.releaseCell?.(d);const w=r[u],C=i[w.field];d.textContent=C==null?"":String(C),d.getAttribute("data-row")!==g&&d.setAttribute("data-row",g);const m=c===o&&h===u,E=d.classList.contains("cell-focus");m!==E&&(d.classList.toggle("cell-focus",m),d.setAttribute("aria-selected",String(m))),f&&t._afterCellRender?.({row:i,rowIndex:o,column:w,colIndex:u,value:C,cellElement:d,rowElement:e})}return}for(let u=0;u<a;u++)if(r[u].externalView&&!n[u].querySelector("[data-external-view]")){X(t,e,i,o);return}for(let u=0;u<a;u++){const d=r[u],w=n[u];w.getAttribute("data-row")!==g&&w.setAttribute("data-row",g);const C=c===o&&h===u,m=w.classList.contains("cell-focus");C!==m&&(w.classList.toggle("cell-focus",C),w.setAttribute("aria-selected",String(C)));const E=d.cellClass;if(E){const v=w.getAttribute("data-dynamic-classes");v&&v.split(" ").forEach(b=>b&&w.classList.remove(b));try{const b=i[d.field],H=E(b,i,d);if(H&&H.length>0){const W=H.filter(R=>R&&typeof R=="string");W.forEach(R=>w.classList.add(R)),w.setAttribute("data-dynamic-classes",W.join(" "))}else w.removeAttribute("data-dynamic-classes")}catch(b){console.warn(`[tbw-grid] cellClass callback error for column '${d.field}':`,b),w.removeAttribute("data-dynamic-classes")}}if(w.classList.contains("editing"))continue;const T=$e(t,d);if(T){const v=i[d.field],b=T({row:i,value:v,field:d.field,column:d,cellEl:w});typeof b=="string"?(t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML=N(b)):b instanceof Node?b.parentElement!==w&&(t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML="",w.appendChild(b)):b==null&&(t.__frameworkAdapter?.releaseCell?.(w),w.textContent=v==null?"":String(v)),f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:v,cellElement:w,rowElement:e});continue}if(d.__compiledView){const v=i[d.field],b=d.__compiledView({row:i,value:v,field:d.field,column:d});d.__compiledView.__blocked?w.textContent="":(w.firstElementChild&&t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML=N(b),ae(w)),f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:v,cellElement:w,rowElement:e});continue}if(d.__viewTemplate){const v=i[d.field],b=d.__viewTemplate.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(b)?w.textContent="":(w.firstElementChild&&t.__frameworkAdapter?.releaseCell?.(w),w.innerHTML=N(le(b,{row:i,value:v})),ae(w)),f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:v,cellElement:w,rowElement:e});continue}if(d.externalView)continue;const S=i[d.field];let P;const y=We(t,d);if(y){try{const v=y(S,i);P=v==null?"":String(v)}catch(v){console.warn(`[tbw-grid] Format error in column '${d.field}':`,v),P=S==null?"":String(S)}w.textContent=P}else d.type==="date"?(P=Ie(S),w.textContent=P):d.type==="boolean"?w.innerHTML=ke(!!S):(P=S==null?"":String(S),w.textContent=P);f&&t._afterCellRender?.({row:i,rowIndex:o,column:d,colIndex:u,value:S,cellElement:w,rowElement:e})}}function X(t,e,i,o){e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy");const n=t.__frameworkAdapter;if(n?.releaseCell){const p=e.children;for(let g=p.length-1;g>=0;g--)n.releaseCell(p[g])}e.innerHTML="";const r=t._visibleColumns,s=r.length,l=t._focusRow,a=t._focusCol,c=t,h=t._hasAfterCellRenderHook?.()??!1,f=document.createDocumentFragment();for(let p=0;p<s;p++){const g=r[p],u=It();u.setAttribute("aria-colindex",String(p+1)),u.setAttribute("data-col",String(p)),u.setAttribute("data-row",String(o)),u.setAttribute("data-field",g.field),u.setAttribute("data-header",g.header??g.field),g.type&&u.setAttribute("data-type",g.type);let d=i[g.field];const w=We(t,g);if(w)try{d=w(d,i)}catch(y){console.warn(`[tbw-grid] Format error in column '${g.field}':`,y)}const C=g.__compiledView,m=g.__viewTemplate,E=$e(t,g),T=g.externalView;let S=!1;if(E){const y=E({row:i,value:d,field:g.field,column:g,cellEl:u});typeof y=="string"?(u.innerHTML=N(y),S=!0):y instanceof Node?y.parentElement!==u&&(u.textContent="",u.appendChild(y)):y==null&&(u.textContent=d==null?"":String(d))}else if(T){const y=T,v=document.createElement("div");v.setAttribute("data-external-view",""),v.setAttribute("data-field",g.field),u.appendChild(v);const b={row:i,value:d,field:g.field,column:g};if(y.mount)try{y.mount({placeholder:v,context:b,spec:y})}catch(H){console.warn(`[tbw-grid] External view mount error for column '${g.field}':`,H)}else queueMicrotask(()=>{try{c.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:v,spec:y,context:b}}))}catch(H){console.warn(`[tbw-grid] External view event dispatch error for column '${g.field}':`,H)}});v.setAttribute("data-mounted","")}else if(C){const y=C({row:i,value:d,field:g.field,column:g}),v=C.__blocked;u.innerHTML=v?"":N(y),S=!0,v&&(u.textContent="",u.setAttribute("data-blocked-template",""))}else if(m){const y=m.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(y)?(u.textContent="",u.setAttribute("data-blocked-template","")):(u.innerHTML=N(le(y,{row:i,value:d})),S=!0)}else w?u.textContent=d==null?"":String(d):g.type==="date"?u.textContent=Ie(d):g.type==="boolean"?u.innerHTML=ke(!!d):u.textContent=d==null?"":String(d);if(S){ae(u);const y=u.textContent||"";/Proxy|Reflect\.ownKeys/.test(y)&&(u.textContent=y.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(u.textContent||"")&&(u.textContent=""))}u.hasAttribute("data-blocked-template")&&(u.textContent||"").trim().length&&(u.textContent=""),g.editable?u.tabIndex=0:g.type==="boolean"&&(u.hasAttribute("tabindex")||(u.tabIndex=0)),l===o&&a===p?(u.classList.add("cell-focus"),u.setAttribute("aria-selected","true")):u.setAttribute("aria-selected","false");const P=g.cellClass;if(P)try{const y=i[g.field],v=P(y,i,g);if(v&&v.length>0){const b=v.filter(H=>H&&typeof H=="string");b.forEach(H=>u.classList.add(H)),u.setAttribute("data-dynamic-classes",b.join(" "))}}catch(y){console.warn(`[tbw-grid] cellClass callback error for column '${g.field}':`,y)}h&&t._afterCellRender?.({row:i,rowIndex:o,column:g,colIndex:p,value:d,cellElement:u,rowElement:e}),f.appendChild(u)}e.appendChild(f)}function Ge(t,e,i){if(e.target?.closest(".resize-handle"))return;const o=i.querySelector(".cell[data-row]"),n=Ne(o);if(n<0)return;const r=t._rows[n];if(!r||t._dispatchRowClick?.(e,n,r,i))return;const s=e.target?.closest(".cell[data-col]");if(s){const l=Number(s.getAttribute("data-col"));if(!isNaN(l)){if(t._dispatchCellClick?.(e,n,l,s))return;const a=t._focusRow!==n||t._focusCol!==l;if(t._focusRow=n,t._focusCol=l,s.classList.contains("editing")){a&&(de(t._bodyEl??t),s.classList.add("cell-focus"));const c=s.querySelector(Fe);try{c?.focus({preventScroll:!0})}catch{}return}U(t)}}}function $t(t,e){if(t._dispatchKeyDown?.(e))return;const i=t._rows.length-1,o=t._visibleColumns.length-1,n=t._activeEditRows!==void 0&&t._activeEditRows!==-1,s=t._visibleColumns[t._focusCol]?.type,l=e.composedPath?.()??[],a=l.length?l[0]:e.target,c=h=>{if(!h)return!1;const f=h.tagName;return!!(f==="INPUT"||f==="SELECT"||f==="TEXTAREA"||h.isContentEditable)};if(!(c(a)&&(e.key==="Home"||e.key==="End"))&&!(c(a)&&(e.key==="ArrowUp"||e.key==="ArrowDown")&&a.tagName==="INPUT"&&a.type==="number")&&!(c(a)&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))&&!(c(a)&&(e.key==="Enter"||e.key==="Escape"))&&!(n&&s==="select"&&(e.key==="ArrowDown"||e.key==="ArrowUp"))){switch(e.key){case"Tab":{e.preventDefault(),!e.shiftKey?t._focusCol<o?t._focusCol+=1:(typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow<i&&(t._focusRow+=1,t._focusCol=0)):t._focusCol>0?t._focusCol-=1:t._focusRow>0&&(typeof t.commitActiveRowEdit=="function"&&t._activeEditRows===t._focusRow&&t.commitActiveRowEdit(),t._focusRow-=1,t._focusCol=o),U(t);return}case"ArrowDown":n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.min(i,t._focusRow+1),e.preventDefault();break;case"ArrowUp":n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault();break;case"ArrowRight":{qe(t)?t._focusCol=Math.max(0,t._focusCol-1):t._focusCol=Math.min(o,t._focusCol+1),e.preventDefault();break}case"ArrowLeft":{qe(t)?t._focusCol=Math.min(o,t._focusCol+1):t._focusCol=Math.max(0,t._focusCol-1),e.preventDefault();break}case"Home":(e.ctrlKey||e.metaKey)&&(n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=0),t._focusCol=0,e.preventDefault(),U(t,{forceScrollLeft:!0});return;case"End":(e.ctrlKey||e.metaKey)&&(n&&typeof t.commitActiveRowEdit=="function"&&t.commitActiveRowEdit(),t._focusRow=i),t._focusCol=o,e.preventDefault(),U(t,{forceScrollRight:!0});return;case"PageDown":t._focusRow=Math.min(i,t._focusRow+20),e.preventDefault();break;case"PageUp":t._focusRow=Math.max(0,t._focusRow-20),e.preventDefault();break;case"Enter":{const h=t._focusRow,f=t._focusCol,p=t._visibleColumns[f],g=t._rows[h],u=p?.field??"",d=u&&g?g[u]:void 0,w=t.querySelector(`[data-row="${h}"][data-col="${f}"]`),C={rowIndex:h,colIndex:f,column:p,field:u,value:d,row:g,cellEl:w,trigger:"keyboard",originalEvent:e},m=new CustomEvent("cell-activate",{cancelable:!0,detail:C});t.dispatchEvent(m);const E=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:h,col:f}});if(t.dispatchEvent(E),m.defaultPrevented||E.defaultPrevented){e.preventDefault();return}break}default:return}U(t)}}function U(t,e){if(t._virtualization?.enabled){const{rowHeight:s,container:l,viewportEl:a}=t._virtualization,c=l,h=a?.clientHeight??c?.clientHeight??0;if(c&&h>0){const f=t._focusRow*s;f<c.scrollTop?c.scrollTop=f:f+s>c.scrollTop+h&&(c.scrollTop=f-h+s)}}const i=t._activeEditRows!==void 0&&t._activeEditRows!==-1;i||t.refreshVirtualWindow(!1),de(t._bodyEl),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(s=>{s.setAttribute("aria-selected","false")});const o=t._focusRow,n=t._virtualization.start??0,r=t._virtualization.end??t._rows.length;if(o>=n&&o<r){const s=t._bodyEl.querySelectorAll(".data-grid-row")[o-n];let l=s?.children[t._focusCol];if((!l||!l.classList?.contains("cell"))&&(l=s?.querySelector(`.cell[data-col="${t._focusCol}"]`)??s?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const a=t.querySelector(".tbw-scroll-area");if(a&&l&&(!i||e?.forceHorizontalScroll))if(e?.forceScrollLeft)a.scrollLeft=0;else if(e?.forceScrollRight)a.scrollLeft=a.scrollWidth-a.clientWidth;else{const c=t._getHorizontalScrollOffsets?.(s??void 0,l)??{left:0,right:0};if(!c.skipScroll){const h=l.getBoundingClientRect(),f=a.getBoundingClientRect(),p=h.left-f.left+a.scrollLeft,g=p+h.width,u=a.scrollLeft+c.left,d=a.scrollLeft+a.clientWidth-c.right;p<u?a.scrollLeft=p-c.left:g>d&&(a.scrollLeft=g-a.clientWidth+c.right)}}if(i&&l.classList.contains("editing")){const c=l.querySelector(Fe);if(c&&document.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}}else if(i&&!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}else if(!i){const c=t;document.activeElement!==c&&c.focus({preventScroll:!0})}}}}const Z=new WeakMap;function Wt(t,e){const i=Ne(e),o=Mt(e);if(i<0||o<0)return;t._focusRow=i,t._focusCol=o,de(t._bodyEl),e.classList.add("cell-focus"),e.setAttribute("aria-selected","true");const n=e.closest("tbw-grid");n&&document.activeElement!==n&&n.focus({preventScroll:!0})}function ge(t,e,i,o){let n=null;const r=i.composedPath?.();if(r&&r.length>0?n=r[0]:n=i.target,n&&!e.contains(n)){const d=document.elementFromPoint(i.clientX,i.clientY);d&&(n=d)}const s=n?.closest?.("[data-col]"),l=n?.closest?.(".data-grid-row"),a=n?.closest?.(".header-row");let c,h,f,p,g,u;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),h=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&h>=0&&(f=t._rows[c],u=t._visibleColumns[h],p=u?.field,g=f&&p?f[p]:void 0)),{type:o,row:f,rowIndex:c!==void 0&&c>=0?c:void 0,colIndex:h!==void 0&&h>=0?h:void 0,field:p,value:g,column:u,originalEvent:i,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:c!==void 0&&h!==void 0&&c>=0&&h>=0?{row:c,col:h}:void 0}}function Ft(t,e,i){const o=ge(t,e,i,"mousedown");(t._dispatchCellMouseDown?.(o)??!1)&&Z.set(t,!0)}function Vt(t,e,i){if(!Z.get(t))return;const o=ge(t,e,i,"mousemove");t._dispatchCellMouseMove?.(o)}function Ut(t,e,i){if(!Z.get(t))return;const o=ge(t,e,i,"mouseup");t._dispatchCellMouseUp?.(o),Z.set(t,!1)}function Gt(t,e,i){e.addEventListener("mousedown",o=>{const n=o.target.closest(".cell[data-col]");n&&(n.classList.contains("editing")||(o.preventDefault(),Wt(t,n)))},{signal:i}),e.addEventListener("click",o=>{const n=o.target.closest(".data-grid-row");if(n&&Ge(t,o,n),!document.activeElement?.closest(".cell.editing")){const r=o.target.closest("tbw-grid");r&&r.focus({preventScroll:!0})}},{signal:i}),e.addEventListener("dblclick",o=>{const n=o.target.closest(".data-grid-row");n&&Ge(t,o,n)},{signal:i})}function Bt(t,e,i,o){e.addEventListener("keydown",n=>$t(t,n),{signal:o}),i.addEventListener("mousedown",n=>Ft(t,i,n),{signal:o}),document.addEventListener("mousemove",n=>Vt(t,i,n),{signal:o}),document.addEventListener("mouseup",n=>Ut(t,i,n),{signal:o})}function Be(t,e){return t==null&&e==null?0:t==null?-1:e==null||t>e?1:t<e?-1:0}function pe(t,e,i){const n=i.find(l=>l.field===e.field)?.sortComparator??Be,{field:r,direction:s}=e;return[...t].sort((l,a)=>n(l[r],a[r],l,a)*s)}function Xe(t,e,i,o){t._rows=e,t.__rowRenderEpoch++,t._rowPool.forEach(n=>n.__epoch=-1),oe(t),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:i.field,direction:o}})),t.requestStateChange?.()}function Ye(t,e){!t._sortState||t._sortState.field!==e.field?(t._sortState||(t.__originalOrder=t._rows.slice()),je(t,e,1)):t._sortState.direction===1?je(t,e,-1):(t._sortState=null,t.__rowRenderEpoch++,t._rowPool.forEach(o=>o.__epoch=-1),t._rows=t.__originalOrder.slice(),oe(t),t._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach(o=>{o.getAttribute("aria-sort")?(o.getAttribute("aria-sort")==="ascending"||o.getAttribute("aria-sort")==="descending")&&(t._sortState||o.setAttribute("aria-sort","none")):o.setAttribute("aria-sort","none")}),t.refreshVirtualWindow(!0),t.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e.field,direction:0}})),t.requestStateChange?.())}function Xt(t,e){if(!t._sortState)return e;t.__originalOrder=[...e];const o=(t.effectiveConfig?.sortHandler??pe)(e,t._sortState,t._columns);return o&&typeof o.then=="function"?e:o}function je(t,e,i){t._sortState={field:e.field,direction:i};const o={field:e.field,direction:i},n=t._columns,s=(t.effectiveConfig?.sortHandler??pe)(t._rows,o,n);s&&typeof s.then=="function"?s.then(l=>{Xe(t,l,e,i)}):Xe(t,s,e,i)}function Y(t,e){return t.effectiveConfig?.sortable!==!1&&e.sortable===!0}function J(t,e){return t.effectiveConfig?.resizable!==!1&&e.resizable!==!1}function Yt(t,e){typeof e=="string"?t.textContent=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}function ee(t,e){const i=document.createElement("span");Le(i,"sort-indicator");const o=t._sortState?.field===e.field?t._sortState.direction:0,n={...k,...t.icons},r=o===1?n.sortAsc:o===-1?n.sortDesc:n.sortNone;return Yt(i,r),i}function te(t,e,i){const o=document.createElement("div");return o.className="resize-handle",o.setAttribute("aria-hidden","true"),o.addEventListener("mousedown",n=>{n.stopPropagation(),n.preventDefault(),t._resizeController.start(n,e,i)}),o.addEventListener("dblclick",n=>{n.stopPropagation(),n.preventDefault(),t._resizeController.resetColumn(e)}),o}function ie(t,e,i,o){o.classList.add("sortable"),o.tabIndex=0;const n=t._sortState?.field===e.field?t._sortState.direction:0;o.setAttribute("aria-sort",n===0?"none":n===1?"ascending":"descending"),o.addEventListener("click",r=>{t._resizeController?.isResizing||t._dispatchHeaderClick?.(r,e,o)||Ye(t,e)}),o.addEventListener("keydown",r=>{if(r.key==="Enter"||r.key===" "){if(r.preventDefault(),t._dispatchHeaderClick?.(r,e,o))return;Ye(t,e)}})}function jt(t,e){if(e!=null)if(typeof e=="string"){const i=document.createElement("span");for(i.innerHTML=N(e);i.firstChild;)t.appendChild(i.firstChild)}else e instanceof Node&&t.appendChild(e)}function oe(t){t._headerRowEl=t.findHeaderRow();const e=t._headerRowEl;e&&(e.innerHTML="",t._visibleColumns.forEach((i,o)=>{const n=document.createElement("div");n.className="cell",Le(n,"header-cell"),n.setAttribute("role","columnheader"),n.setAttribute("aria-colindex",String(o+1)),n.setAttribute("data-field",i.field),n.setAttribute("data-col",String(o)),i.type&&n.setAttribute("data-type",i.type);const r=i.header??i.field,s=t._sortState?.field===i.field?t._sortState.direction:0,l=s===1?"asc":s===-1?"desc":null;if(i.headerRenderer){const a={column:i,value:r,sortState:l,filterActive:!1,cellEl:n,renderSortIcon:()=>Y(t,i)?ee(t,i):null,renderFilterButton:()=>null},c=i.headerRenderer(a);jt(n,c),Y(t,i)&&ie(t,i,o,n),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)))}else if(i.headerLabelRenderer){const a={column:i,value:r},c=i.headerLabelRenderer(a),h=document.createElement("span");c==null?h.textContent=r:typeof c=="string"?h.innerHTML=N(c):c instanceof Node&&h.appendChild(c),n.appendChild(h),Y(t,i)&&(ie(t,i,o,n),n.appendChild(ee(t,i))),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)))}else if(i.__headerTemplate)Array.from(i.__headerTemplate.childNodes).forEach(a=>n.appendChild(a.cloneNode(!0))),Y(t,i)&&(ie(t,i,o,n),n.appendChild(ee(t,i))),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)));else{const a=document.createElement("span");a.textContent=r,n.appendChild(a),Y(t,i)&&(ie(t,i,o,n),n.appendChild(ee(t,i))),J(t,i)&&(n.classList.add("resizable"),n.appendChild(te(t,o,n)))}e.appendChild(n)}),e.querySelectorAll(".cell.sortable").forEach(i=>{i.getAttribute("aria-sort")||i.setAttribute("aria-sort","none")}),e.children.length>0?(e.setAttribute("role","row"),e.setAttribute("aria-rowindex","1")):(e.removeAttribute("role"),e.removeAttribute("aria-rowindex")))}const Ke=typeof requestIdleCallback=="function";function Kt(t,e){return Ke?requestIdleCallback(t,e):window.setTimeout(()=>{const i=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-i))})},1)}function Qe(t){Ke?cancelIdleCallback(t):clearTimeout(t)}function 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 Zt(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 Qt(t)}function Jt(t){const e=document.createElement("div");return e.className="tbw-loading-overlay",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.appendChild(Zt("large",t)),e}function ei(t,e){t.appendChild(e)}function ti(t){t?.remove()}function ii(t,e){if(e){if(t.classList.add("tbw-row-loading"),t.setAttribute("aria-busy","true"),!t.querySelector(".tbw-row-loading-overlay")){const i=document.createElement("div");i.className="tbw-row-loading-overlay",i.setAttribute("aria-hidden","true");const o=document.createElement("div");o.className="tbw-row-loading-spinner",i.appendChild(o),t.appendChild(i)}}else t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy"),t.querySelector(".tbw-row-loading-overlay")?.remove()}function oi(t,e){e?(t.classList.add("tbw-cell-loading"),t.setAttribute("aria-busy","true")):(t.classList.remove("tbw-cell-loading"),t.removeAttribute("aria-busy"))}var A=(t=>(t[t.STYLE=1]="STYLE",t[t.VIRTUALIZATION=2]="VIRTUALIZATION",t[t.HEADER=3]="HEADER",t[t.ROWS=4]="ROWS",t[t.COLUMNS=5]="COLUMNS",t[t.FULL=6]="FULL",t))(A||{});class ni{#a;#n=0;#u=0;#d=null;#h=null;#l=null;#o=!1;constructor(e){this.#a=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.#l=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.#a.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.#a.mergeConfig(),e>=4&&this.#a.processRows(),e>=5&&(this.#a.processColumns(),this.#a.updateTemplate()),e>=3&&this.#a.renderHeader(),e>=2&&this.#a.renderVirtualWindow(),e>=1&&this.#a.afterRender(),!this.#o&&this.#l&&(this.#o=!0,this.#l()),this.#h&&(this.#h(),this.#h=null,this.#d=null)}}function Ze(t){let e=null,i=null,o=null,n=null;const r=a=>{if(!e)return;const c=a.clientX-e.startX,h=Math.max(40,e.startWidth+c),f=t._visibleColumns[e.colIndex];f.width=h,f.__userResized=!0,f.__renderedWidth=h,i==null&&(i=requestAnimationFrame(()=>{i=null,t.updateTemplate?.()})),t.dispatchEvent(new CustomEvent("column-resize",{detail:{field:f.field,width:h}}))};let s=!1;const l=()=>{const a=e!==null;a&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),o!==null&&(document.documentElement.style.cursor=o,o=null),n!==null&&(document.body.style.userSelect=n,n=null),e=null,a&&t.requestStateChange&&t.requestStateChange()};return{get isResizing(){return e!==null||s},start(a,c,h){a.preventDefault();const f=t._visibleColumns[c],p=typeof f?.width=="number"?f.width:void 0,g=f?.__renderedWidth??p??h.getBoundingClientRect().width;e={startX:a.clientX,colIndex:c,startWidth:g},window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),o===null&&(o=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",n===null&&(n=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(a){const c=t._visibleColumns[a];c&&(c.__userResized=!1,c.__renderedWidth=void 0,c.width=c.__originalWidth,t.updateTemplate?.(),t.requestStateChange?.(),t.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:c.field,width:c.width}})))},dispose(){l()}}}const we="data-animating",ri={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},si={change:500,insert:300,remove:200};function li(t){const e=t.trim().toLowerCase();return e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:parseFloat(e)}function ai(t,e){const i=ri[e],o=getComputedStyle(t).getPropertyValue(i);if(o){const n=li(o);if(!isNaN(n)&&n>0)return n}return si[e]}function ci(t,e,i){t.removeAttribute(we),t.offsetWidth,t.setAttribute(we,e);const o=ai(t,e);setTimeout(()=>{e!=="remove"&&t.removeAttribute(we),i?.()},o)}function be(t,e,i){if(e<0)return Promise.resolve(!1);const o=t.findRenderedRowElement?.(e);return o?new Promise(n=>{ci(o,i,()=>n(!0))}):Promise.resolve(!1)}function di(t,e,i){return Promise.all(e.map(o=>be(t,o,i))).then(o=>o.filter(Boolean).length)}function hi(t,e,i){const o=t._rows??[],n=t.getRowId;if(!n)return Promise.resolve(!1);const r=o.findIndex(s=>{if(s==null)return!1;try{return n(s)===e}catch{return!1}});return r<0?Promise.resolve(!1):be(t,r,i)}function ne(t,e,i){const o=document.createElement(t);if(e)for(const n in e){const r=e[n];r!=null&&o.setAttribute(n,r)}return o}function 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 et=document.createElement("template");et.innerHTML=`
|
|
2
|
-
<div class="tbw-scroll-area">
|
|
3
|
-
<div class="rows-body-wrapper">
|
|
4
|
-
<div class="rows-body" role="grid">
|
|
5
|
-
<div class="header" role="rowgroup">
|
|
6
|
-
<div class="header-row" role="row" part="header-row"></div>
|
|
7
|
-
</div>
|
|
8
|
-
<div class="rows-container" role="presentation">
|
|
9
|
-
<div class="rows-viewport" role="presentation">
|
|
10
|
-
<div class="rows"></div>
|
|
11
|
-
</div>
|
|
12
|
-
</div>
|
|
13
|
-
</div>
|
|
14
|
-
</div>
|
|
15
|
-
</div>
|
|
16
|
-
<div class="faux-vscroll">
|
|
17
|
-
<div class="faux-vscroll-spacer"></div>
|
|
18
|
-
</div>
|
|
19
|
-
`;function tt(){return et.content.cloneNode(!0)}function it(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(tt()),i.appendChild(o)}return e.appendChild(i),e}function ui(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 fi(t){const e=L("tbw-shell-body"),i=t.panels.length>0,o=t.panels.length===1,n=L("tbw-grid-content");n.appendChild(tt());let r=null;if(i){r=ne("aside",{class:t.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":t.position,role:"presentation",id:"tbw-tool-panel"});const s=t.position==="left"?"right":"left";r.appendChild(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 h=`tbw-accordion-section${c.isExpanded?" expanded":""}${o?" single":""}`,f=L(h,{"data-section":c.id}),p=Je("tbw-accordion-header",{"aria-expanded":String(c.isExpanded),"aria-controls":`tbw-section-${c.id}`});if(o&&p.setAttribute("aria-disabled","true"),c.icon){const u=ne("span",{class:"tbw-accordion-icon"});u.innerHTML=c.icon,p.appendChild(u)}const g=ne("span",{class:"tbw-accordion-title"});if(g.textContent=c.title,p.appendChild(g),!o){const u=ne("span",{class:"tbw-accordion-chevron"});u.innerHTML=c.isExpanded?t.collapseIcon:t.expandIcon,p.appendChild(u)}f.appendChild(p),f.appendChild(L("tbw-accordion-content",{id:`tbw-section-${c.id}`,role:"presentation"})),a.appendChild(f)}l.appendChild(a),r.appendChild(l)}return t.position==="left"&&r?(e.appendChild(r),e.appendChild(n)):(e.appendChild(n),r&&e.appendChild(r)),e}function $(t){return t?typeof t=="string"?t:t.outerHTML:""}function gi(){return{toolPanels:new Map,headerContents:new Map,toolbarContents:new Map,hasToolButtonsContainer:!1,lightDomHeaderContent:[],lightDomTitle:null,lightDomToolPanelIds:new Set,lightDomToolbarContentIds:new Set,apiToolPanelIds:new Set,isPanelOpen:!1,expandedSections:new Set,headerContentCleanups:new Map,panelCleanups:new Map,toolbarContentCleanups:new Map,lightDomContentMoved:!1}}function ot(t){return!!(t?.header?.title||t?.header?.toolbarContents?.length||t?.toolPanels?.length||t?.headerContents?.length||t?.header?.lightDomContent?.length||t?.header?.hasToolButtonsContainer)}function pi(t,e,i="☰"){const o=t?.header?.title??e.lightDomTitle??"",n=!!o,r=$(i),s=t?.header?.toolbarContents??[],l=[...e.toolbarContents.values()],a=new Set(s.map(d=>d.id)),c=[...s];for(const d of l)a.has(d.id)||c.push(d);const h=c.length>0,f=e.toolPanels.size>0,p=h&&f,g=[...c].sort((d,w)=>(d.order??0)-(w.order??0));let u="";for(const d of g)u+=`<div class="tbw-toolbar-content-slot" data-toolbar-content="${d.id}"></div>`;if(p&&(u+='<div class="tbw-toolbar-separator"></div>'),f){const d=e.isPanelOpen;u+=`<button class="${d?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${d}" aria-controls="tbw-tool-panel">${r}</button>`}return`
|
|
20
|
-
<div class="tbw-shell-header" part="shell-header" role="presentation">
|
|
21
|
-
${n?`<div class="tbw-shell-title">${At(o)}</div>`:""}
|
|
22
|
-
<div class="tbw-shell-content" part="shell-content" role="presentation" data-light-dom-header-content></div>
|
|
23
|
-
<div class="tbw-shell-toolbar" part="shell-toolbar" role="presentation">
|
|
24
|
-
${u}
|
|
25
|
-
</div>
|
|
26
|
-
</div>
|
|
27
|
-
`}function nt(t,e){const i=t.querySelector("tbw-grid-header");if(!i)return;if(!e.lightDomTitle){const n=i.getAttribute("title");n&&(e.lightDomTitle=n)}const o=i.querySelectorAll("tbw-grid-header-content");o.length>0&&e.lightDomHeaderContent.length===0&&(e.lightDomHeaderContent=Array.from(o)),i.style.display="none"}function rt(t,e,i){const o=t.querySelector(":scope > tbw-grid-tool-buttons");if(!o)return;e.hasToolButtonsContainer=!0;const n="light-dom-toolbar-content";if(e.lightDomToolbarContentIds.has(n))return;const r={id:n,order:0,render:(s=>{for(;o.firstChild;)s.appendChild(o.firstChild);return()=>{for(;s.firstChild;)o.appendChild(s.firstChild)}})};e.toolbarContents.set(n,r),e.lightDomToolbarContentIds.add(n),o.style.display="none"}function st(t,e,i){t.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(n=>{const r=n,s=r.getAttribute("id"),l=r.getAttribute("title");if(!s||!l){console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${s??""}", title="${l??""}"`);return}const a=r.getAttribute("icon")??void 0,c=r.getAttribute("tooltip")??void 0,h=parseInt(r.getAttribute("order")??"100",10);let f;const p=i?.(r);if(p)f=p;else{const d=r.innerHTML.trim();f=w=>{const C=document.createElement("div");return C.innerHTML=d,w.appendChild(C),()=>C.remove()}}const g=e.toolPanels.get(s);if(g){if(p){g.render=f,g.order=h,g.icon=a,g.tooltip=c;const d=e.panelCleanups.get(s);d&&(d(),e.panelCleanups.delete(s))}return}const u={id:s,title:l,icon:a,tooltip:c,order:h,render:f};e.toolPanels.set(s,u),e.lightDomToolPanelIds.add(s),r.style.display="none"})}function wi(t,e,i,o){const n=t.querySelector(".tbw-shell-toolbar");n&&n.addEventListener("click",s=>{if(s.target.closest("[data-panel-toggle]")){o.onPanelToggle();return}});const r=t.querySelector(".tbw-accordion");r&&r.addEventListener("click",s=>{const a=s.target.closest(".tbw-accordion-header");if(a){const h=a.closest("[data-section]")?.getAttribute("data-section");h&&o.onSectionToggle(h)}})}function bi(t,e,i,o){if(!e?.toolPanel?.closeOnClickOutside)return()=>{};const n=r=>{if(!i.isPanelOpen)return;const s=r.target;s&&(s.closest(".tbw-tool-panel")||s.closest("[data-panel-toggle]")||o())};return t.addEventListener("mousedown",n),()=>t.removeEventListener("mousedown",n)}function mi(t,e,i){const o=t.querySelector(".tbw-tool-panel"),n=t.querySelector("[data-resize-handle]"),r=t.querySelector(".tbw-shell-body");if(!o||!n||!r)return()=>{};const s=e?.toolPanel?.position??"right",l=200;let a=0,c=0,h=0,f=!1;const p=d=>{if(!f)return;d.preventDefault();const w=s==="left"?d.clientX-a:a-d.clientX,C=Math.min(h,Math.max(l,c+w));o.style.width=`${C}px`},g=()=>{if(!f)return;f=!1,n.classList.remove("resizing"),o.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const d=o.getBoundingClientRect().width;i(d),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",g)},u=d=>{d.preventDefault(),f=!0,a=d.clientX,c=o.getBoundingClientRect().width,h=r.getBoundingClientRect().width-20,n.classList.add("resizing"),o.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",p),document.addEventListener("mouseup",g)};return n.addEventListener("mousedown",u),()=>{n.removeEventListener("mousedown",u),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",g)}}function me(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 ve(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 vi(t,e,i){if(!e.isPanelOpen)return;const o=$(i?.expand??k.expand),n=$(i?.collapse??k.collapse);for(const[r,s]of e.toolPanels){const l=e.expandedSections.has(r),a=t.querySelector(`[data-section="${r}"]`),c=a?.querySelector(".tbw-accordion-content");if(!a||!c)continue;a.classList.toggle("expanded",l);const h=a.querySelector(".tbw-accordion-header");h&&h.setAttribute("aria-expanded",String(l));const f=a.querySelector(".tbw-accordion-chevron");if(f&&(f.innerHTML=l?n:o),l){if(c.children.length===0){const p=s.render(c);p&&e.panelCleanups.set(r,p)}}else{const p=e.panelCleanups.get(r);p&&(p(),e.panelCleanups.delete(r)),c.innerHTML=""}}}function lt(t,e){const i=t.querySelector("[data-panel-toggle]");i&&(i.classList.toggle("active",e.isPanelOpen),i.setAttribute("aria-pressed",String(e.isPanelOpen)))}function at(t,e){const i=t.querySelector(".tbw-tool-panel");i&&(i.classList.toggle("open",e.isPanelOpen),e.isPanelOpen||(i.style.width=""))}function Ce(t){for(const e of t.toolbarContentCleanups.values())e();t.toolbarContentCleanups.clear()}function Ci(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 yi(t,e){let i=!1;const o={get isInitialized(){return i},setInitialized(n){i=n},get isPanelOpen(){return t.isPanelOpen},get activePanel(){return t.isPanelOpen&&t.expandedSections.size>0?[...t.expandedSections][0]:null},get expandedSections(){return[...t.expandedSections]},openToolPanel(){if(t.isPanelOpen)return;if(t.toolPanels.size===0){console.warn("[tbw-grid] No tool panels registered");return}if(t.isPanelOpen=!0,t.expandedSections.size===0&&t.toolPanels.size>0){const s=[...t.toolPanels.values()].sort((l,a)=>(l.order??100)-(a.order??100))[0];s&&t.expandedSections.add(s.id)}const n=e.getShadow();lt(n,t),at(n,t),vi(n,t,e.getAccordionIcons()),e.emit("tool-panel-open",{sections:o.expandedSections})},closeToolPanel(){if(!t.isPanelOpen)return;for(const r of t.panelCleanups.values())r();t.panelCleanups.clear();for(const r of t.toolPanels.values())r.onClose?.();t.isPanelOpen=!1;const n=e.getShadow();lt(n,t),at(n,t),e.emit("tool-panel-close",{})},toggleToolPanel(){t.isPanelOpen?o.closeToolPanel():o.openToolPanel()},toggleToolPanelSection(n){const r=t.toolPanels.get(n);if(!r){console.warn(`[tbw-grid] Tool panel section "${n}" not found`);return}if(t.toolPanels.size===1)return;const s=e.getShadow(),l=t.expandedSections.has(n);if(l){const a=t.panelCleanups.get(n);a&&(a(),t.panelCleanups.delete(n)),r.onClose?.(),t.expandedSections.delete(n),ye(s,n,!1)}else{for(const[a,c]of t.toolPanels)if(a!==n&&t.expandedSections.has(a)){const h=t.panelCleanups.get(a);h&&(h(),t.panelCleanups.delete(a)),c.onClose?.(),t.expandedSections.delete(a),ye(s,a,!1);const f=s.querySelector(`[data-section="${a}"] .tbw-accordion-content`);f&&(f.innerHTML="")}t.expandedSections.add(n),ye(s,n,!0),_i(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&&ve(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 ye(t,e,i){const o=t.querySelector(`[data-section="${e}"]`);o&&o.classList.toggle("expanded",i)}function _i(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 Ei(t,e,i,o){const n=ot(e),r=[],s=["tbw-grid-header","tbw-grid-tool-buttons","tbw-grid-tool-panel","tbw-grid-column","tbw-grid-detail","tbw-grid-responsive-card"];for(const l of s)t.querySelectorAll(`:scope > ${l}`).forEach(c=>r.push(c));t.replaceChildren();for(const l of r)t.appendChild(l);if(n){const l=$(o?.toolPanel??k.toolPanel),a=$(o?.expand??k.expand),c=$(o?.collapse??k.collapse),f=[...e?.header?.toolbarContents??[]].sort((E,T)=>(E.order??0)-(T.order??0)),g=[...e?.toolPanels??[]].sort((E,T)=>(E.order??100)-(T.order??100)),u={title:e?.header?.title??void 0,hasPanels:g.length>0,isPanelOpen:i.isPanelOpen,toolPanelIcon:l,configButtons:f.map(E=>({id:E.id,hasElement:!1,hasRender:!!E.render})),apiButtons:[]},d={position:e?.toolPanel?.position??"right",isPanelOpen:i.isPanelOpen,expandIcon:a,collapseIcon:c,panels:g.map(E=>({id:E.id,title:E.title,icon:$(E.icon),isExpanded:i.expandedSections.has(E.id)}))},w=ui(u),C=fi(d),m=it({hasShell:!0,shellHeader:w,shellBody:C});t.appendChild(m)}else{const l=it({hasShell:!1});t.appendChild(l)}return n}const ct="tbw-grid-styles";let re="";const _e=new Map;function Si(){let t=document.getElementById(ct);return t||(t=document.createElement("style"),t.id=ct,t.setAttribute("data-tbw-grid","true"),document.head.appendChild(t)),t}function Ee(){const t=Si(),e=Array.from(_e.values()).join(`
|
|
28
|
-
`);t.textContent=`${re}
|
|
29
|
-
|
|
30
|
-
/* Plugin Styles */
|
|
31
|
-
${e}`}function Ri(t){let e=!1;for(const{name:i,styles:o}of t)_e.has(i)||(_e.set(i,o),e=!0);return e&&Ee(),e}function Ai(){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 Ti(t){if(re)return;if(typeof t=="string"&&t.length>0){re=t,Ee();return}await new Promise(i=>setTimeout(i,50));const e=Ai();e?(re=e,Ee()):(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 xi(){return{startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0}}function Hi(t){t.startY=null,t.startX=null,t.scrollTop=null,t.scrollLeft=null,t.lastY=null,t.lastX=null,t.lastTime=null}function dt(t){t.momentumRaf&&(cancelAnimationFrame(t.momentumRaf),t.momentumRaf=0)}function Pi(t,e,i){if(t.touches.length!==1)return;dt(e);const o=t.touches[0];e.startY=o.clientY,e.startX=o.clientX,e.lastY=o.clientY,e.lastX=o.clientX,e.lastTime=performance.now(),e.scrollTop=i.fauxScrollbar.scrollTop,e.scrollLeft=i.scrollArea?.scrollLeft??0,e.velocityY=0,e.velocityX=0}function Li(t,e,i){if(t.touches.length!==1||e.startY===null||e.startX===null||e.scrollTop===null||e.scrollLeft===null)return!1;const o=t.touches[0],n=o.clientY,r=o.clientX,s=performance.now(),l=e.startY-n,a=e.startX-r;if(e.lastTime!==null&&e.lastY!==null&&e.lastX!==null){const d=s-e.lastTime;d>0&&(e.velocityY=(e.lastY-n)/d,e.velocityX=(e.lastX-r)/d)}e.lastY=n,e.lastX=r,e.lastTime=s;const{scrollTop:c,scrollHeight:h,clientHeight:f}=i.fauxScrollbar,p=h-f,g=l>0&&c<p||l<0&&c>0;let u=!1;if(i.scrollArea){const{scrollLeft:d,scrollWidth:w,clientWidth:C}=i.scrollArea,m=w-C;u=a>0&&d<m||a<0&&d>0}return g&&(i.fauxScrollbar.scrollTop=e.scrollTop+l),u&&i.scrollArea&&(i.scrollArea.scrollLeft=e.scrollLeft+a),g||u}function zi(t,e){(Math.abs(t.velocityY)>.1||Math.abs(t.velocityX)>.1)&&Oi(t,e),Hi(t)}function Oi(t,e){const n=()=>{t.velocityY*=.95,t.velocityX*=.95;const r=t.velocityY*16,s=t.velocityX*16;Math.abs(t.velocityY)>.01&&(e.fauxScrollbar.scrollTop+=r),Math.abs(t.velocityX)>.01&&e.scrollArea&&(e.scrollArea.scrollLeft+=s),Math.abs(t.velocityY)>.01||Math.abs(t.velocityX)>.01?t.momentumRaf=requestAnimationFrame(n):t.momentumRaf=0};t.momentumRaf=requestAnimationFrame(n)}function Di(t,e,i,o){t.addEventListener("touchstart",n=>Pi(n,e,i),{passive:!0,signal:o}),t.addEventListener("touchmove",n=>{Li(n,e,i)&&n.preventDefault()},{passive:!1,signal:o}),t.addEventListener("touchend",()=>zi(e,i),{passive:!0,signal:o})}const Mi=[{property:"editable",pluginName:"editing",level:"column",description:'the "editable" column property',isUsed:t=>t===!0},{property:"editor",pluginName:"editing",level:"column",description:'the "editor" column property'},{property:"editorParams",pluginName:"editing",level:"column",description:'the "editorParams" column property'},{property:"group",pluginName:"groupingColumns",level:"column",description:'the "group" column property'},{property:"pinned",pluginName:"pinnedColumns",level:"column",description:'the "pinned" column property',isUsed:t=>t==="left"||t==="right"||t==="start"||t==="end"},{property:"sticky",pluginName:"pinnedColumns",level:"column",description:'the "sticky" column property (deprecated, use "pinned")',isUsed:t=>t==="left"||t==="right"||t==="start"||t==="end"}],ki=[{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:'the "columnGroups" config property',isUsed:t=>Array.isArray(t)&&t.length>0}];function Ii(t){return t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function Se(t){return`import { ${D(t)}Plugin } from '@toolbox-web/grid/plugins/${Ii(t)}';`}function D(t){return t.charAt(0).toUpperCase()+t.slice(1)}function ht(t,e){return t.some(i=>i.name===e)}function Ni(t,e){const i=Mi,o=ki,n=new Map;function r(l,a,c,h,f=!1){n.has(l)||n.set(l,{description:a,importHint:c,fields:[],isConfigProperty:f});const p=n.get(l);p.fields.includes(h)||p.fields.push(h)}for(const l of o){const a=t[l.property];(l.isUsed?l.isUsed(a):a!==void 0)&&!ht(e,l.pluginName)&&r(l.pluginName,l.description,Se(l.pluginName),l.property,!0)}const s=t.columns;if(s&&s.length>0)for(const l of s)for(const a of i){const c=l[a.property];if((a.isUsed?a.isUsed(c):c!==void 0)&&!ht(e,a.pluginName)){const f=l.field||"<unknown>";r(a.pluginName,a.description,Se(a.pluginName),f)}}if(n.size>0){const l=[];for(const[a,{description:c,importHint:h,fields:f,isConfigProperty:p}]of n)if(p)l.push(`Config uses ${c}, but the required plugin is not loaded.
|
|
33
|
-
→ Add the plugin to your gridConfig.plugins array:
|
|
34
|
-
${h}
|
|
35
|
-
plugins: [new ${D(a)}Plugin(), ...]`);else{const g=f.slice(0,3).join(", ")+(f.length>3?`, ... (${f.length} total)`:"");l.push(`Column(s) [${g}] use ${c}, but the required plugin is not loaded.
|
|
36
|
-
→ Add the plugin to your gridConfig.plugins array:
|
|
37
|
-
${h}
|
|
38
|
-
plugins: [new ${D(a)}Plugin(), ...]`)}throw new Error(`[tbw-grid] Configuration error:
|
|
39
|
-
|
|
40
|
-
${l.join(`
|
|
41
|
-
|
|
42
|
-
`)}
|
|
43
|
-
|
|
44
|
-
This validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}function qi(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:${D(o.name)}Plugin]`} Configuration warning: ${s.message}`;s.severity==="error"?e.push(c):i.push(c)}}}if(i.length>0&&ce())for(const o of i)console.warn(o);if(e.length>0)throw new Error(`[tbw-grid] Configuration error:
|
|
45
|
-
|
|
46
|
-
${e.join(`
|
|
47
|
-
|
|
48
|
-
`)}`)}function $i(t,e){const i=t.name,n=t.constructor.dependencies??[];for(const r of n){const s=r.name,l=r.required??!0,a=r.reason;if(!e.some(h=>h.name===s)){const h=a??`${D(i)}Plugin requires ${D(s)}Plugin`,f=Se(s);if(l)throw new Error(`[tbw-grid] Plugin dependency error:
|
|
49
|
-
|
|
50
|
-
${h}.
|
|
51
|
-
|
|
52
|
-
→ Add the plugin to your gridConfig.plugins array BEFORE ${D(i)}Plugin:
|
|
53
|
-
${f}
|
|
54
|
-
plugins: [new ${D(s)}Plugin(), new ${D(i)}Plugin()]`);console.info(`[tbw-grid] ${D(i)}Plugin: Optional "${s}" plugin not found. Some features may be unavailable.`)}}}function Wi(t){if(!ce())return;const e=new Set(t.map(o=>o.name)),i=new Set;for(const o of t){const r=o.constructor.manifest;if(r?.incompatibleWith){for(const s of r.incompatibleWith)if(e.has(s.name)){const l=[o.name,s.name].sort().join("↔");if(i.has(l))continue;i.add(l),console.warn(`[tbw-grid] Plugin incompatibility warning:
|
|
55
|
-
|
|
56
|
-
${D(o.name)}Plugin and ${D(s.name)}Plugin are both loaded, but they are currently incompatible.
|
|
57
|
-
|
|
58
|
-
→ ${s.reason}
|
|
59
|
-
|
|
60
|
-
Consider removing one of these plugins to avoid unexpected behavior.`)}}}}function ut(t,e){return!t||typeof t!="object"?t:"__rowCacheKey"in t?t.__rowCacheKey:"rowId"in t&&t.rowId!=null?`id:${t.rowId}`:e?`id:${e(t)}`:t}function Fi(t,e,i){const o=ut(e,i);if(typeof o=="string")return t.byKey.get(o);if(o&&typeof o=="object")return t.byRef.get(o)}function Vi(t,e,i,o){const n=ut(e,o);typeof n=="string"?t.byKey.set(n,i):n&&typeof n=="object"&&t.byRef.set(n,i)}function Ui(t,e,i,o,n){const r=new Array(t.length);let s=0;for(let l=0;l<t.length;l++){const a=t[l];let c=n?.(a,l),h=c!==void 0;c===void 0&&(c=Fi(e,a,o.rowId),h=c!==void 0),c===void 0&&(c=i,h=!1),r[l]={offset:s,height:c,measured:h},s+=c}return r}function Re(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 Gi(t){if(t.length===0)return 0;const e=t[t.length-1];return e.offset+e.height}function ft(t,e){if(t.length===0)return-1;if(e<=0)return 0;let i=0,o=t.length-1;for(;i<=o;){const n=Math.floor((i+o)/2),r=t[n],s=r.offset+r.height;if(e<r.offset)o=n-1;else if(e>=s)i=n+1;else return n}return Math.max(0,Math.min(i,t.length-1))}function Bi(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 Xi(t){let e=0;for(const i of t)i.measured&&e++;return e}function Yi(t,e){const{positionCache:i,heightCache:o,rows:n,start:r,end:s,getPluginHeight:l,getRowId:a}=t;let c=!1;e.forEach(p=>{const g=p.dataset.rowIndex;if(!g)return;const u=parseInt(g,10);if(u<r||u>=s||u>=n.length)return;const d=n[u],w=l?.(d,u);if(w!==void 0){const m=i[u];(!m.measured||Math.abs(m.height-w)>1)&&(Re(i,u,w),c=!0);return}const C=p.offsetHeight;if(C>0){const m=i[u];(!m.measured||Math.abs(m.height-C)>1)&&(Re(i,u,C),Vi(o,d,C,a),c=!0)}});const h=c?Xi(i):0,f=c?Bi(i,t.defaultHeight):0;return{hasChanges:c,measuredCount:h,averageHeight:f}}function ji(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 j{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($i(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(j.deprecationWarned.has(i)||!ce())return;const o=typeof e.getExtraHeight=="function"||typeof e.getExtraHeightBefore=="function",n=typeof e.getRowHeight=="function";o&&!n&&(j.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 Ki=`/**
|
|
63
|
-
* tbw-grid Light DOM Styles
|
|
64
|
-
*
|
|
65
|
-
* This stylesheet uses CSS nesting to scope all styles to the tbw-grid element.
|
|
66
|
-
* All selectors are automatically prefixed with \`tbw-grid\` for encapsulation.
|
|
67
|
-
*
|
|
68
|
-
* CSS Cascade Layers are used to control style priority:
|
|
69
|
-
* - tbw-base: Core grid styles (lowest priority)
|
|
70
|
-
* - tbw-plugins: Plugin styles (override base)
|
|
71
|
-
* - tbw-theme: Theme overrides (override plugins)
|
|
72
|
-
* - Unlayered CSS: User customizations (highest priority - always wins)
|
|
73
|
-
*
|
|
74
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_nesting
|
|
75
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@layer
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
/* Declare layer order - earlier layers have lower priority */
|
|
79
|
-
@layer tbw-base, tbw-plugins, tbw-theme;
|
|
80
|
-
|
|
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-v: var(--tbw-spacing-xs);--tbw-cell-padding-h: var(--tbw-spacing-md);--tbw-cell-padding: var(--tbw-cell-padding-v) var(--tbw-cell-padding-h);--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-width: 1px;--tbw-border-style: solid;--tbw-border-input: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-strong);--tbw-border-header: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-header);--tbw-row-divider: var(--tbw-border-width) var(--tbw-border-style) 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-width: 2px;--tbw-focus-outline: var(--tbw-focus-outline-width) var(--tbw-border-style) 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)}}
|
|
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)}}
|
|
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}}
|
|
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}}
|
|
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}}
|
|
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}}
|
|
87
|
-
@layer tbw-base{.tbw-loading-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:1000;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-spinner{--tbw-spinner-size: 48px;--tbw-spinner-border-width: 3px;--tbw-spinner-color: var(--tbw-color-accent);--tbw-spinner-track-color: var(--tbw-color-border);width:var(--tbw-spinner-size);height:var(--tbw-spinner-size);border:var(--tbw-spinner-border-width) solid var(--tbw-spinner-track-color);border-top-color:var(--tbw-spinner-color);border-radius:50%;animation:tbw-spin .8s linear infinite}.tbw-spinner--large{--tbw-spinner-size: min(48px, calc(100% - 16px) )}.tbw-spinner--small{--tbw-spinner-size: calc(var(--tbw-row-height, 28px) * .6);--tbw-spinner-border-width: 2px}.data-grid-row.tbw-row-loading{position:relative;pointer-events:none}.tbw-row-loading-overlay{position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out;pointer-events:none;display:flex;align-items:center}.tbw-row-loading-spinner{--_spinner-size: calc(var(--tbw-row-height, 28px) * .6);margin-left:var(--tbw-spacing-md);width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite}.cell.tbw-cell-loading{position:relative;pointer-events:none}.cell.tbw-cell-loading:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out}.cell.tbw-cell-loading:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .5);content:"";position:absolute;left:var(--tbw-spacing-sm);top:0;bottom:0;margin:auto 0;width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite;z-index:27}}
|
|
88
|
-
@layer tbw-base{tbw-grid .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid[data-animation-mode=off]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=off] .data-grid-row[data-animating]{animation:none}tbw-grid .data-grid-row[data-animating=change]{animation:tbw-row-change var(--tbw-row-change-duration) ease-out}tbw-grid .data-grid-row[data-animating=insert]{animation:tbw-row-insert var(--tbw-row-insert-duration) ease-out;will-change:max-height,opacity}tbw-grid .data-grid-row[data-animating=remove]{animation:tbw-row-remove var(--tbw-row-remove-duration) ease-out forwards;will-change:max-height,opacity,transform;pointer-events:none}}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-row-change{0%{background-color:transparent}20%{background-color:var(--tbw-row-change-color)}to{background-color:transparent}}@keyframes tbw-row-insert{0%{opacity:0;max-height:0;overflow:hidden}to{opacity:1;max-height:var(--tbw-row-height, 28px);overflow:hidden}}@keyframes tbw-row-remove{0%{opacity:1;transform:translateY(0);max-height:var(--tbw-row-height, 28px)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-spin{to{transform:rotate(360deg)}}@keyframes tbw-fade-in{0%{opacity:0}to{opacity:1}}
|
|
89
|
-
@layer tbw-base{@media(forced-colors:active){tbw-grid{--tbw-color-border: CanvasText;--tbw-color-border-strong: CanvasText;--tbw-color-border-cell: CanvasText;--tbw-color-border-header: CanvasText;--tbw-color-fg: CanvasText;--tbw-color-bg: Canvas;--tbw-color-panel-bg: Canvas;--tbw-color-header-bg: Canvas;--tbw-color-header-fg: CanvasText;--tbw-color-accent: Highlight;--tbw-color-accent-fg: HighlightText;--tbw-color-selection: Highlight;--tbw-color-row-hover: Highlight;--tbw-focus-outline: 2px solid Highlight;--tbw-range-border-color: Highlight}tbw-grid .cell:focus,tbw-grid .cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}tbw-grid .data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}@media(prefers-reduced-motion:reduce){tbw-grid[data-animation-mode=reduced-motion]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=reduced-motion] .data-grid-row[data-animating]{animation:none}}}
|
|
90
|
-
`;class I extends HTMLElement{static tagName="tbw-grid";static version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";static#a=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;#l=[];get#o(){return this.#i?.effective??{}}#f=!1;#w=!1;#v={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#s;#C=0;#r=null;#g=!1;#x=!1;#m=0;#O;#N=xi();#b;#y;#p;#R;#ee={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#t;#_;#q=!1;#D;#B;#M;#i;#e=gi();#c;#$;#W;#k=!1;#E=new Set;#H=new Map;#F;#S=new Map;_rows=[];#X=[];get _columns(){return this.#o.columns??[]}set _columns(e){this.#o.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null,positionCache:null,heightCache:{byKey:new Map,byRef:new WeakMap},averageHeight:28,measuredCount:0,variableHeights:!1,cachedViewportHeight:0,cachedFauxHeight:0,cachedScrollAreaHeight:0,scrollAreaEl:null};_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#i?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#i&&(this.#i.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#i?.originalColumnNodes}set __originalColumnNodes(e){this.#i&&(this.#i.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const i=this.#l;this.#l=e,i!==e&&this.#G("rows")}get sourceRows(){return this.#l}get columns(){return[...this._columns]}set columns(e){const i=this.#i?.getColumns();this.#i?.setColumns(e),i!==e&&this.#G("columns")}get gridConfig(){return this.#o}set gridConfig(e){const i=this.#i?.getGridConfig();this.#i?.setGridConfig(e),i!==e&&(this.#i.clearLightDomCache(),this.#G("gridConfig"))}get fitMode(){return this.#o.fitMode??"stretch"}set fitMode(e){const i=this.#i?.getFitMode();this.#i?.setFitMode(e),i!==e&&this.#G("fitMode")}get loading(){return this.#k}set loading(e){const i=this.#k;this.#k=e,e?this.setAttribute("loading",""):this.removeAttribute("loading"),i!==e&&this.#ue()}setRowLoading(e,i){const o=this.#E.has(e);i?this.#E.add(e):this.#E.delete(e),o!==i&&this.#K(e,i)}setCellLoading(e,i,o){let n=this.#H.get(e);const r=n?.has(i)??!1;o?(n||(n=new Set,this.#H.set(e,n)),n.add(i)):(n?.delete(i),n?.size===0&&this.#H.delete(e)),r!==o&&this.#fe(e,i,o)}isRowLoading(e){return this.#E.has(e)}isCellLoading(e,i){return this.#H.get(e)?.has(i)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#E)this.#K(e,!1);this.#E.clear();for(const[e,i]of this.#H)for(const o of i)this.#fe(e,o,!1);this.#H.clear()}get effectiveConfig(){return this.#o}get disconnectSignal(){return this.#b||(this.#b=new AbortController),this.#b.signal}constructor(){super(),this.#me(),this.#d=new Promise(e=>this.#h=e),this.#s=new ni({mergeConfig:()=>{this.#i.parseLightDomColumns(this),this.#i.merge(),this.#ie(),Ni(this.#o,this.#t?.getPlugins()??[]),qi(this.#t?.getPlugins()??[]),Wi(this.#t?.getPlugins()??[]),this.#Oe(),this.#X=[...this._columns]},processColumns:()=>this.#He(),processRows:()=>this.#Le(),renderHeader:()=>oe(this),updateTemplate:()=>B(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#t?.afterRender(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const i=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${i}px`}),this.#o.fitMode==="fixed"&&!this.__didInitialAutoSize&&(this.__didInitialAutoSize=!0,ze(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,U(this)),this._virtualization.enabled&&!this.#U&&this.#ye(),this.#x&&(this.#x=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#Ce()})})),this.#k&&this.#ue()},isConnected:()=>this.isConnected&&this.#f}),this.#s.setInitialReadyResolver(()=>this.#h?.()),this.#c=yi(this.#e,{getShadow:()=>this.#n,getShellConfig:()=>this.#o?.shell,getAccordionIcons:()=>({expand:this.#o?.icons?.expand??k.expand,collapse:this.#o?.icons?.collapse??k.collapse}),emit:(e,i)=>this.#P(e,i),refreshShellHeader:()=>this.refreshShellHeader()}),this.#i=new Dt({getRows:()=>this.#l,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#s.requestPhase(A.FULL,"configChange")},emit:(e,i)=>this.#P(e,i),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#z(),renderHeader:()=>oe(this),updateTemplate:()=>B(this),refreshVirtualWindow:()=>this.#s.requestPhase(A.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#ze(e),getShellLightDomTitle:()=>this.#e.lightDomTitle,getShellToolPanels:()=>this.#e.toolPanels,getShellHeaderContents:()=>this.#e.headerContents,getShellToolbarContents:()=>this.#e.toolbarContents,getShellLightDomHeaderContent:()=>this.#e.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#e.hasToolButtonsContainer})}async#me(){await Ti(Ki)}getPlugin(e){return this.#t?.getPlugin(e)}getPluginByName(e){return this.#t?.getPluginByName(e)}requestRender(){this.#s.requestPhase(A.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#s.requestPhase(A.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#s.requestPhase(A.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){B(this)}requestAfterRender(){this.#s.requestPhase(A.STYLE,"plugin:requestAfterRender")}#te(){this.#t=new j(this);const e=this.#o?.plugins,i=Array.isArray(e)?e:[];this.#t.attachAll(i)}#V(){const e=this.#t?.getPluginStyles()??[];Ri(e)}#ie(){const e=this.#o?.plugins,i=Array.isArray(e)?e:[];if(this.#_===i)return;if(this.#_&&this.#_.length===i.length&&this.#_.every((n,r)=>n===i[r])){this.#_=i;return}this.#t&&this.#t.detachAll();for(const n of this.#e.toolPanels.keys()){const r=this.#e.lightDomToolPanelIds.has(n),s=this.#e.apiToolPanelIds.has(n);if(!r&&!s){const l=this.#e.panelCleanups.get(n);l&&(l(),this.#e.panelCleanups.delete(n)),this.#e.toolPanels.delete(n)}}for(const n of this.#e.headerContents.keys()){const r=this.#e.headerContentCleanups.get(n);r&&(r(),this.#e.headerContentCleanups.delete(n)),this.#e.headerContents.delete(n)}this.#te(),this.#V(),this.#_=i,this.#se(),this.#oe();const o=this.#g;if(this.#g=this.#t?.getAll().some(n=>n.onScroll)??!1,!o&&this.#g){const r=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");this.#Y(r)}}#ve(){this.#t?.detachAll()}#oe(){if(!this.#t)return;const e=this.#t.getToolPanels();for(const{panel:o}of e)this.#e.toolPanels.has(o.id)||this.#e.toolPanels.set(o.id,o);const i=this.#t.getHeaderContents();for(const{content:o}of i)this.#e.headerContents.has(o.id)||this.#e.headerContents.set(o.id,o)}#ne(){const e=I.getAdapters();if(e.length===0&&!this.__frameworkAdapter)return;const i=this.__frameworkAdapter;return o=>{if(i?.createToolPanelRenderer){const n=i.createToolPanelRenderer(o);if(n)return n}for(const n of e)if(n.createToolPanelRenderer){const r=n.createToolPanelRenderer(o);if(r)return r}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",I.version),this.id||(this.id=`tbw-grid-${++I.#a}`),this._rows=Array.isArray(this.#l)?[...this.#l]:[],this.#b&&(this.#b.abort(),this.#q=!1),this.#b=new AbortController,this.#R&&(Qe(this.#R),this.#R=void 0),this.#I(),this.#i.parseLightDomColumns(this),this.#i.merge(),this.#te();const e=this.#o?.plugins;this.#_=Array.isArray(e)?e:[],this.#oe(),this.#u||(this.#J(),this.#V(),this.#u=!0),this.#re(),this.#R=Kt(()=>{this.#Ie()},{timeout:100})}disconnectedCallback(){this.#R&&(Qe(this.#R),this.#R=void 0),this.#m&&(clearTimeout(this.#m),this.#m=0),this.#ve(),Ci(this.#e),this.#c.setInitialized(!1),this.#$?.(),this.#$=void 0,this.#W?.(),this.#W=void 0,dt(this.#N),this.#b&&(this.#b.abort(),this.#b=void 0),this.#D?.abort(),this.#D=void 0,this.#q=!1,this._resizeController&&this._resizeController.dispose(),this.#y&&(this.#y.disconnect(),this.#y=void 0),this.#p&&(this.#p.disconnect(),this.#p=void 0,this.#U=!1),V(this),this.#A.clear(),this.#_=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#f=!1}attributeChangedCallback(e,i,o){if(e==="loading"){const n=o!==null&&o!=="false";this.loading!==n&&(this.loading=n);return}if(!(i===o||!o||o==="null"||o==="undefined"))if(e==="rows"||e==="columns"||e==="grid-config")try{const n=JSON.parse(o);e==="rows"?this.rows=n:e==="columns"?this.columns=n:e==="grid-config"&&(this.gridConfig=n)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,o)}else e==="fit-mode"&&(this.fitMode=o)}#re(){const i=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=i?.querySelector(".header-row"),this._virtualization.totalHeightEl=i?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=i?.querySelector(".rows-viewport"),this._bodyEl=i?.querySelector(".rows"),this.__rowsBodyEl=i?.querySelector(".rows-body"),this.#c.isInitialized){ve(this.#n,this.#e),me(this.#n,this.#o?.shell,this.#e);const n=this.#o?.shell?.toolPanel?.defaultOpen;n&&this.#e.toolPanels.has(n)&&(this.openToolPanel(),this.#e.expandedSections.add(n))}if(this.setAttribute("data-upgraded",""),this.#f=!0,this._resizeController=Ze(this),this.#z(),this.#Y(i),this.#q)return;this.#q=!0;const o=this.disconnectSignal;Bt(this,this,this.#n,o),this.#se(),queueMicrotask(()=>this.#_e()),this.#s.requestPhase(A.FULL,"afterConnect")}#se(){const e=this.#o.rowHeight,i=this.#t.hasRowHeightPlugin();typeof e=="function"||i?this._virtualization.variableHeights||(this._virtualization.variableHeights=!0,this._virtualization.rowHeight=typeof e=="number"&&e>0?e:this._virtualization.rowHeight||28,this.#Z(),typeof e!="function"&&(this.#x=!0)):!i&&typeof e!="function"&&this._virtualization.variableHeights?(this._virtualization.variableHeights=!1,this._virtualization.positionCache=null):typeof e=="number"&&e>0?(this._virtualization.rowHeight=e,this._virtualization.variableHeights=!1):requestAnimationFrame(()=>this.#le())}#le(){if(this.#t.hasExtraHeight())return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const i=e.querySelectorAll(".cell");let o=0;i.forEach(s=>{const l=s.offsetHeight;l>o&&(o=l)});const n=e.getBoundingClientRect(),r=Math.max(n.height,o);r>0&&Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r,this.#s.requestPhase(A.VIRTUALIZATION,"measureRowHeight"))}#Ce(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const i=e.querySelectorAll(".cell");let o=0;i.forEach(s=>{const l=s.offsetHeight;l>o&&(o=l)});const n=e.getBoundingClientRect(),r=Math.max(n.height,o);if(r>0&&(Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r),this.#Z(),this._virtualization.totalHeightEl)){const l=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#Y(e){this.#D?.abort(),this.#D=new AbortController;const i=this.#D.signal,o=e?.querySelector(".faux-vscroll"),n=e?.querySelector(".rows");if(this._virtualization.container=o??this,this.#g=this.#t?.getAll().some(r=>r.onScroll)??!1,o&&n){o.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#g)return;const a=o.scrollTop,c=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)n.style.transform=`translateY(${-a}px)`;else{const h=this._virtualization.positionCache;let f,p;if(this._virtualization.variableHeights&&h&&h.length>0){f=ft(h,a),f===-1&&(f=0);const u=f-f%2;p=h[u]?.offset??u*c}else f=Math.floor(a/c),p=(f-f%2)*c;const g=-(a-p);n.style.transform=`translateY(${g}px)`}this.#r=a,this.#C||(this.#C=requestAnimationFrame(()=>{this.#C=0,this.#r!==null&&(this.#De(this.#r),this.#r=null)}))},{passive:!0,signal:i});const r=this.#n.querySelector(".tbw-scroll-area");this.#B=r,this._virtualization.scrollAreaEl=r,r&&this.#g&&r.addEventListener("scroll",()=>{const a=this.#ee;a.scrollTop=o.scrollTop,a.scrollLeft=r.scrollLeft,a.scrollHeight=o.scrollHeight,a.scrollWidth=r.scrollWidth,a.clientHeight=o.clientHeight,a.clientWidth=r.clientWidth,this.#t?.onScroll(a)},{passive:!0,signal:i});const s=this.#n.querySelector(".tbw-grid-content"),l=this.#B;s&&(s.addEventListener("wheel",a=>{const c=a.shiftKey||Math.abs(a.deltaX)>Math.abs(a.deltaY);if(c&&l){const h=a.shiftKey?a.deltaY:a.deltaX,{scrollLeft:f,scrollWidth:p,clientWidth:g}=l;(h>0&&f<p-g||h<0&&f>0)&&(a.preventDefault(),l.scrollLeft+=h)}else if(!c){const{scrollTop:h,scrollHeight:f,clientHeight:p}=o;(a.deltaY>0&&h<f-p||a.deltaY<0&&h>0)&&(a.preventDefault(),o.scrollTop+=a.deltaY)}},{passive:!1,signal:i}),Di(s,this.#N,{fauxScrollbar:o,scrollArea:l},i))}this._bodyEl&&Gt(this,this._bodyEl,i),this.#y?.disconnect(),this._virtualization.viewportEl&&(this.#y=new ResizeObserver(()=>{this.#Ne(),this.#s.requestPhase(A.VIRTUALIZATION,"resize-observer")}),this.#y.observe(this._virtualization.viewportEl)),this.#n.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:i}),this.#n.addEventListener("focusout",r=>{const s=r.relatedTarget;(!s||!this.#n.contains(s))&&delete this.dataset.hasFocus},{signal:i})}#U=!1;#ye(){if(this.#U)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#U=!0,this.#p?.disconnect(),this.#p=new ResizeObserver(()=>{this.#le()}),this.#p.observe(e))}addEventListener(e,i,o){super.addEventListener(e,i,o)}removeEventListener(e,i,o){super.removeEventListener(e,i,o)}#P(e,i){this.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,composed:!0}))}#_e(){this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((i,o)=>{const n=o===this._focusRow;i.setAttribute("aria-selected",String(n)),i.querySelectorAll(".cell").forEach((r,s)=>{r.setAttribute("aria-selected",String(n&&s===this._focusCol))})})}#G(e){this.#v[e]=!0,!this.#w&&(this.#w=!0,queueMicrotask(()=>this.#Ee()))}#Ee(){if(!this.#w||!this.#f){this.#w=!1;return}const e=this.#v;if(this.#w=!1,this.#v={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig){this.#Te(),e.rows&&this.#ae();return}e.columns&&this.#Re(),e.rows&&this.#ae(),e.fitMode&&this.#Ae()}#ae(){this._rows=Array.isArray(this.#l)?[...this.#l]:[],this.#L(),this.#s.requestPhase(A.ROWS,"applyRowsUpdate")}#L(){this.#S.clear();const e=this.#o.getRowId;this._rows.forEach((i,o)=>{const n=this.#ce(i,e);n!==void 0&&this.#S.set(n,{row:i,index:o})})}#ce(e,i){if(i)return i(e);const o=e;if("id"in o&&o.id!=null)return String(o.id);if("_id"in o&&o._id!=null)return String(o._id)}#Se(e,i){const o=this.#ce(e,i);if(o===void 0)throw new Error('[tbw-grid] Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.');return o}#Re(){V(this),this.#i.merge(),this.#z()}#Ae(){this.#i.merge(),this.#o.fitMode==="fixed"?(this.__didInitialAutoSize=!1,ze(this)):(this._columns.forEach(i=>{!i.__userResized&&i.__autoSized&&delete i.width}),B(this))}#Te(){nt(this,this.#e),rt(this,this.#e);const e=!!this.#n.querySelector(".has-shell"),i=!!this.#n.querySelector(".tbw-tool-panel"),o=this.#n.querySelectorAll(".tbw-accordion-section").length;this.#i.parseLightDomColumns(this),this.#i.merge(),this.#ie(),st(this,this.#e,this.#ne()),this.#i.markSourcesChanged(),this.#i.merge();const n=ot(this.#o?.shell),r=(this.#o?.shell?.toolPanels?.length??0)>0,s=this.#o?.shell?.toolPanels?.length??0;if(e!==n||!i&&r||i&&s!==o){Ce(this.#e),this.#J(),this.#V(),this.#re(),this.#L();return}e&&this.#xe(),this.#L(),this.#s.requestPhase(A.COLUMNS,"applyGridConfigUpdate")}#xe(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;const i=this.#o.shell?.header?.title??this.#e.lightDomTitle;let o=e.querySelector(".tbw-shell-title");i?(o||(o=document.createElement("h2"),o.className="tbw-shell-title",o.setAttribute("part","shell-title"),e.insertBefore(o,e.firstChild)),o.textContent=i):o&&o.remove()}#He(){if(this.__rowRenderEpoch++,this.#t){const e=this.#X.length>0?this.#X:this._columns,i=e.filter(r=>!r.hidden),o=e.filter(r=>r.hidden),n=this.#t.processColumns([...i]);if(n!==i){const r=new Set(n.map(l=>l.field));!i.some(l=>r.has(l.field))&&n.length>0?this._columns=[...n,...o]:this._columns=this.#Pe(e,n,o)}else this._columns=[...e]}}#Pe(e,i,o){if(o.length===0)return i;const n=new Map;for(const a of i)n.set(a.field,a);const r=new Set(e.map(a=>a.field)),s=[];for(const a of i)r.has(a.field)||s.push(a);const l=[];for(const a of e){const c=n.get(a.field);c?l.push(c):a.hidden&&l.push(a)}return l.push(...s),l}#Le(){V(this);const e=Array.isArray(this.#l)?[...this.#l]:[],i=Xt(this,e),o=this.#t?.processRows(i)??i;this._rows=o,this.#L(),this._virtualization.variableHeights&&this.#Z()}#ze(e){const i={...xe,...e.animation},o=i.mode??"reduced-motion";let n=1;o===!1||o==="off"?n=0:(o===!0||o==="on")&&(n=1),this.style.setProperty("--tbw-animation-duration",`${i.duration}ms`),this.style.setProperty("--tbw-animation-easing",i.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode=typeof o=="boolean"?o?"on":"off":o}#j(e,i,o=this.__rowRenderEpoch){if(this.#O||(this.#O=(n,r,s)=>this.#t?.renderRow(n,r,s)??!1),qt(this,e,i,o,this.#O),this.#E.size>0)for(const n of this.#E)this.#K(n,!0)}#de=G();#he(e,i){wt(this.#de,this.__rowsBodyEl,this._bodyEl,e,i)}#Oe(){mt(this.#de,this.__rowsBodyEl,this.#o,this.#e)}#ue(){const e=this.querySelector(".tbw-grid-root");e&&(this.#k?(this.#F||(this.#F=Jt(this.#o?.loadingRenderer)),ei(e,this.#F)):ti(this.#F))}#K(e,i){const o=this.#S.get(e);if(!o)return;const n=this.findRenderedRowElement?.(o.index);n&&ii(n,i)}#fe(e,i,o){const n=this.#S.get(e);if(!n)return;const r=this.findRenderedRowElement?.(n.index);if(!r)return;const s=this._visibleColumns.findIndex(a=>a.field===i);if(s<0)return;const l=r.children[s];l&&oi(l,o)}#z(){if(this.isConnected&&!(!this._headerRowEl||!this._bodyEl)){if(this.#i.parseLightDomColumns(this),this.#M){const e=this.#M;this.#M=void 0,this.#i.merge();const i=this.#t?.getAll()??[];this.#i.applyState(e,i)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#s.requestPhase(A.FULL,"setup")}}#De(e){let i=0,o=0,n=0,r=0,s=0;if(this.#g){const a=this._virtualization.container,c=this.#B;i=c?.scrollLeft??0,o=a?.scrollHeight??0,n=c?.scrollWidth??0,r=a?.clientHeight??0,s=c?.clientWidth??0}if(this.refreshVirtualWindow(!1)&&this.#t?.onScrollRender(),this._virtualization.variableHeights&&(this.#m&&clearTimeout(this.#m),this.#m=window.setTimeout(()=>{this.#m=0,this.#we(this._virtualization.start,this._virtualization.end)},100)),this.#g){const a=this.#ee;a.scrollTop=e,a.scrollLeft=i,a.scrollHeight=o,a.scrollWidth=n,a.clientHeight=r,a.clientWidth=s,this.#t?.onScroll(a)}}findHeaderRow(){return this.#n.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(i=>{const o=i.querySelector(".cell[data-row]");return o&&Number(o.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,i,o,n){const r=this._rows[i],s=this._visibleColumns[o];if(!r||!s)return!1;const l=s.field,a=r[l],c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:i,colIndex:o,column:s,field:l,value:a,row:r,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(c),c.defaultPrevented)return!0;const h={row:r,rowIndex:i,colIndex:o,column:s,field:l,value:a,cellEl:n,originalEvent:e},f=this.#t?.onCellClick(h)??!1;return this.#P("cell-click",h),f}_dispatchRowClick(e,i,o,n){if(!o)return!1;const r={rowIndex:i,row:o,rowEl:n,originalEvent:e},s=this.#t?.onRowClick(r)??!1;return this.#P("row-click",r),s}_dispatchHeaderClick(e,i,o){if(!i)return!1;const n={colIndex:this._columns.indexOf(i),field:i.field,column:i,headerEl:o,originalEvent:e};return this.#t?.onHeaderClick(n)??!1}_dispatchKeyDown(e){return this.#t?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,i){return this.#t?.getHorizontalScrollOffsets(e,i)??{left:0,right:0}}queryPlugins(e){return this.#t?.queryPlugins(e)??[]}query(e,i){return this.#t?.queryPlugins({type:e,context:i})??[]}_dispatchCellMouseDown(e){return this.#t?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#t?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#t?.onCellMouseUp(e)}_afterCellRender(e){this.#t?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#t?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#t?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#t?.hasAfterRowRenderHook()??!1}async ready(){return this.#d}async forceLayout(){return this.#s.requestPhase(A.FULL,"forceLayout"),this.#s.whenReady()}async getConfig(){return Object.freeze({...this.#o||{}})}getRowId(e){return this.#Se(e,this.#o.getRowId)}getRow(e){return this.#S.get(e)?.row}_getRowEntry(e){return this.#S.get(e)}updateRow(e,i,o="api"){const n=this.#S.get(e);if(!n)throw new Error(`[tbw-grid] Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:r,index:s}=n,l=[];for(const[a,c]of Object.entries(i)){const h=r[a];h!==c&&(l.push({field:a,oldValue:h,newValue:c}),r[a]=c)}for(const{field:a,oldValue:c,newValue:h}of l)this.#P("cell-change",{row:r,rowId:e,rowIndex:s,field:a,oldValue:c,newValue:h,changes:i,source:o});l.length>0&&this.#s.requestPhase(A.ROWS,"updateRow")}updateRows(e,i="api"){let o=!1;for(const{id:n,changes:r}of e){const s=this.#S.get(n);if(!s)throw new Error(`[tbw-grid] Row with ID "${n}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:l,index:a}=s;for(const[c,h]of Object.entries(r)){const f=l[c];f!==h&&(o=!0,l[c]=h,this.#P("cell-change",{row:l,rowId:n,rowIndex:a,field:c,oldValue:f,newValue:h,changes:r,source:i}))}}o&&this.#s.requestPhase(A.ROWS,"updateRows")}animateRow(e,i){return be(this,e,i)}animateRows(e,i){return di(this,e,i)}animateRowById(e,i){return hi(this,e,i)}async insertRow(e,i,o=!0){const n=Math.max(0,Math.min(e,this._rows.length));this.#l=[...this.#l,i];const r=[...this._rows];r.splice(n,0,i),this._rows=r,this._sortState&&(this.__originalOrder=[...this.__originalOrder,i]),V(this),this.#L(),this.__rowRenderEpoch++;for(const s of this._rowPool)s.__epoch=-1;this.refreshVirtualWindow(!0),o&&(await new Promise(s=>requestAnimationFrame(()=>s())),await this.animateRow(n,"insert"))}async removeRow(e,i=!0){const o=this._rows[e];if(!o)return;i&&await this.animateRow(e,"remove");const n=this._rows.indexOf(o);if(n<0)return o;const r=[...this._rows];r.splice(n,1),this._rows=r;const s=this.#l.indexOf(o);if(s>=0){const l=[...this.#l];l.splice(s,1),this.#l=l}if(this._sortState){const l=this.__originalOrder.indexOf(o);if(l>=0){const a=[...this.__originalOrder];a.splice(l,1),this.__originalOrder=a}}V(this),this.#L(),this.__rowRenderEpoch++;for(const l of this._rowPool)l.__epoch=-1;return this.refreshVirtualWindow(!0),i&&requestAnimationFrame(()=>{this.querySelectorAll('[data-animating="remove"]').forEach(l=>{l.removeAttribute("data-animating")})}),o}suspendProcessing(){}setColumnVisible(e,i){const o=this.#i.setColumnVisible(e,i);return o&&this.requestStateChange(),o}toggleColumnVisibility(e){const i=this.#i.toggleColumnVisibility(e);return i&&this.requestStateChange(),i}isColumnVisible(e){return this.#i.isColumnVisible(e)}showAllColumns(){this.#i.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#i.getAllColumns()}setColumnOrder(e){this.#i.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#i.getColumnOrder()}getColumnState(){const e=this.#t?.getAll()??[];return this.#i.collectState(e)}set columnState(e){e&&(this.#M=e,this.#i.initialColumnState=e,this.#u&&this.#Me(e))}get columnState(){return this.getColumnState()}#Me(e){const i=this.#t?.getAll()??[];this.#i.applyState(e,i),this.#z()}requestStateChange(){const e=this.#t?.getAll()??[];this.#i.requestStateChange(e)}resetColumnState(){this.#M=void 0,this.__originalOrder=[];const e=this.#t?.getAll()??[];this.#i.resetState(e),this.#i.merge(),this.#z()}get isToolPanelOpen(){return this.#c.isPanelOpen}get defaultRowHeight(){return this._virtualization.rowHeight}get expandedToolPanelSections(){return this.#c.expandedSections}openToolPanel(){this.#c.openToolPanel()}closeToolPanel(){this.#c.closeToolPanel()}toggleToolPanel(){this.#c.toggleToolPanel()}toggleToolPanelSection(e){this.#c.toggleToolPanelSection(e)}getToolPanels(){return this.#c.getToolPanels()}registerToolPanel(e){this.#e.apiToolPanelIds.add(e.id),this.#c.registerToolPanel(e)}unregisterToolPanel(e){this.#e.apiToolPanelIds.delete(e),this.#c.unregisterToolPanel(e)}getHeaderContents(){return this.#c.getHeaderContents()}registerHeaderContent(e){this.#c.registerHeaderContent(e)}unregisterHeaderContent(e){this.#c.unregisterHeaderContent(e)}getToolbarContents(){return this.#c.getToolbarContents()}registerToolbarContent(e){this.#c.registerToolbarContent(e)}unregisterToolbarContent(e){this.#c.unregisterToolbarContent(e)}#Q=!1;refreshShellHeader(){this.#Q||(this.#Q=!0,queueMicrotask(()=>{this.#Q=!1,this.isConnected&&(this.#I(),this.#i.markSourcesChanged(),this.#i.merge(),Ce(this.#e),this.#J(),this.#V(),this.#ke())}))}#ke(){const i=this.#n.querySelector(".tbw-grid-content")??this.#n.querySelector(".tbw-grid-root");if(this._headerRowEl=i?.querySelector(".header-row"),this._virtualization.totalHeightEl=i?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=i?.querySelector(".rows-viewport"),this._bodyEl=i?.querySelector(".rows"),this.__rowsBodyEl=i?.querySelector(".rows-body"),this.#c.isInitialized){ve(this.#n,this.#e),me(this.#n,this.#o?.shell,this.#e);const o=this.#o?.shell?.toolPanel?.defaultOpen;o&&this.#e.toolPanels.has(o)&&(this.openToolPanel(),this.#e.expandedSections.add(o))}this._resizeController=Ze(this),this.#Y(i),this.#s.requestPhase(A.COLUMNS,"shellRefresh")}#A=new Map;registerStyles(e,i){let o=this.#A.get(e);o||(o=new CSSStyleSheet,this.#A.set(e,o)),o.replaceSync(i),this.#ge()}unregisterStyles(e){this.#A.delete(e)&&this.#ge()}getRegisteredStyles(){return Array.from(this.#A.keys())}#ge(){const e=Array.from(this.#A.values()),i=document.adoptedStyleSheets.filter(o=>!Array.from(this.#A.values()).includes(o));document.adoptedStyleSheets=[...i,...e]}#I(){nt(this,this.#e),rt(this,this.#e),st(this,this.#e,this.#ne())}#pe(){const e=this.#n.querySelector(".tbw-shell-header");if(!e)return;Ce(this.#e);const i=pi(this.#o.shell,this.#e,this.#o.icons?.toolPanel),o=document.createElement("div");o.innerHTML=i;const n=o.firstElementChild;n&&(e.replaceWith(n),this.#be(),me(this.#n,this.#o?.shell,this.#e))}#Ie(){const e=()=>{const o=this.#e.lightDomTitle,n=this.#e.hasToolButtonsContainer;this.#I();const r=this.#e.lightDomTitle,s=this.#e.hasToolButtonsContainer;(r&&!o||s&&!n)&&(this.#i.markSourcesChanged(),this.#i.merge(),this.#pe())},i=()=>{this.__lightDomColumnsCache=void 0,this.#z()};this.#i.registerLightDomHandler("tbw-grid-header",e),this.#i.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#i.registerLightDomHandler("tbw-grid-tool-panel",e),this.#i.registerLightDomHandler("tbw-grid-column",i),this.#i.registerLightDomHandler("tbw-grid-detail",i),this.#i.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,V(this),this.#i.parseLightDomColumns(this);const e=this.#e.lightDomTitle,i=this.#e.hasToolButtonsContainer;this.#I();const o=this.#e.lightDomTitle,n=this.#e.hasToolButtonsContainer;(o&&!e||n&&!i)&&(this.#i.markSourcesChanged(),this.#i.merge(),this.#pe()),this.#s.requestPhase(A.COLUMNS,"refreshColumns")}#Ne(){const e=this._virtualization.container,i=this._virtualization.viewportEl??e;i&&(this._virtualization.cachedViewportHeight=i.clientHeight),e&&(this._virtualization.cachedFauxHeight=e.clientHeight);const o=this._virtualization.scrollAreaEl;o&&(this._virtualization.cachedScrollAreaHeight=o.clientHeight)}#T(e,i=!1){const o=this._virtualization;let n,r,s;if(i){const p=o.container??this,g=o.viewportEl??p,u=o.scrollAreaEl;n=p.clientHeight,r=g.clientHeight,s=u?u.clientHeight:n,o.cachedFauxHeight=n,o.cachedViewportHeight=r,o.cachedScrollAreaHeight=s}else n=o.cachedFauxHeight,r=o.cachedViewportHeight,s=o.cachedScrollAreaHeight||n;const l=s-r,a=Math.max(0,n-s);let c,h=0;return o.variableHeights&&o.positionCache?c=Gi(o.positionCache):(c=e*o.rowHeight,h=this.#t?.getExtraHeight()??0),c+l+h+a}#Z(){if(!this._virtualization.variableHeights)return;const e=this._rows,i=this._virtualization.rowHeight||28,o=this.#o.rowHeight,n=this.#o.getRowId,r=n?l=>n(l):void 0;this._virtualization.positionCache=Ui(e,this._virtualization.heightCache,i,{rowId:r},(l,a)=>{const c=this.#t?.getRowHeight?.(l,a);if(c!==void 0)return c;if(o){const h=o(l,a);if(h!==void 0&&h>0)return h}});const s=ji(this._virtualization.positionCache,e,i,(l,a)=>this.#t?.getRowHeight?.(l,a));this._virtualization.measuredCount=s.measuredCount,s.measuredCount>0&&(this._virtualization.averageHeight=s.averageHeight)}invalidateRowHeight(e,i){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||e<0||e>=this._rows.length)return;const o=this._virtualization.positionCache,n=this._rows[e];let r=i;r===void 0&&(r=this.#t?.getRowHeight?.(n,e)),r===void 0&&(r=this._virtualization.rowHeight);const s=o[e];if(!(!s||Math.abs(s.height-r)<1)&&(Re(o,e,r),this._virtualization.totalHeightEl)){const l=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${l}px`}}#we(e,i){if(!this._virtualization.variableHeights||!this._virtualization.positionCache||!this._bodyEl)return;const o=this._bodyEl.querySelectorAll(".data-grid-row"),n=this.#o.getRowId,r=Yi({positionCache:this._virtualization.positionCache,heightCache:this._virtualization.heightCache,rows:this._rows,defaultHeight:this._virtualization.rowHeight,start:e,end:i,getPluginHeight:(s,l)=>this.#t?.getRowHeight?.(s,l),getRowId:n?s=>n(s):void 0},o);if(r.hasChanges&&(this._virtualization.measuredCount=r.measuredCount,this._virtualization.averageHeight=r.averageHeight,this._virtualization.totalHeightEl)){const s=this.#T(this._rows.length);this._virtualization.totalHeightEl.style.height=`${s}px`}}refreshVirtualWindow(e=!1,i=!1){if(!this._bodyEl)return!1;const o=this._rows.length;if(!this._virtualization.enabled)return this.#j(0,o),i||this.#t?.afterRender(),!0;if(this._rows.length<=this._virtualization.bypassThreshold)return this._virtualization.start=0,this._virtualization.end=o,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#j(0,o,this.__rowRenderEpoch),e&&this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#T(o,!0)}px`),this.#he(o,this._visibleColumns.length),i||this.#t?.afterRender(),!0;const n=this._virtualization.container??this,r=this._virtualization.viewportEl??n,s=e?this._virtualization.cachedViewportHeight=r.clientHeight:this._virtualization.cachedViewportHeight||(this._virtualization.cachedViewportHeight=r.clientHeight),l=this._virtualization.rowHeight,a=n.scrollTop;let c;const h=this._virtualization.positionCache;if(this._virtualization.variableHeights&&h&&h.length>0)c=ft(h,a),c===-1&&(c=0);else{c=Math.floor(a/l);let m=0;const E=10;for(;m<E;){const T=this.#t?.getExtraHeightBefore?.(c)??0,S=Math.floor((a-T)/l);if(S>=c||S<0)break;c=S,m++}}c=c-c%2,c<0&&(c=0);const f=this.#t?.adjustVirtualStart(c,a,l);f!==void 0&&f<c&&(c=f,c=c-c%2,c<0&&(c=0));let p;if(this._virtualization.variableHeights&&h&&h.length>0){const m=s+l*3;let E=0;for(p=c;p<o&&E<m;)E+=h[p].height,p++;const T=Math.ceil(s/l)+3;p-c<T&&(p=Math.min(c+T,o))}else{const m=Math.ceil(s/l)+3;p=c+m}p>o&&(p=o);const g=this._virtualization.start,u=this._virtualization.end;if(!e&&c===g&&p===u)return!1;this._virtualization.start=c,this._virtualization.end=p;const d=e?this._virtualization.cachedFauxHeight=n.clientHeight:this._virtualization.cachedFauxHeight||(this._virtualization.cachedFauxHeight=n.clientHeight);if(e){const m=this._virtualization.scrollAreaEl;m&&(this._virtualization.cachedScrollAreaHeight=m.clientHeight)}if(d===0&&s>0)return this.#s.requestPhase(A.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&this._virtualization.totalHeightEl){const m=this.#T(o);this._virtualization.totalHeightEl.style.height=`${m}px`}let w;if(this._virtualization.variableHeights&&h&&h[c])w=h[c].offset;else{const m=this.#t?.getExtraHeightBefore?.(c)??0;w=c*l+m}const C=-(a-w);return this._bodyEl.style.transform=`translateY(${C}px)`,this.#j(c,p,this.__rowRenderEpoch),e&&this._virtualization.variableHeights&&this.#we(c,p),this.#he(o,this._visibleColumns.length),e&&!i&&(this.#t?.afterRender(),queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const m=this.#T(o);this._virtualization.cachedFauxHeight===0&&this._virtualization.cachedViewportHeight>0||(this._virtualization.totalHeightEl.style.height=`${m}px`)})),!0}#J(){this.#I(),this.#i.markSourcesChanged(),this.#i.merge();const e=this.#o?.shell;Ei(this.#n,e,{isPanelOpen:this.#e.isPanelOpen,expandedSections:this.#e.expandedSections},this.#o?.icons)&&(this.#be(),this.#c.setInitialized(!0))}#be(){wi(this.#n,this.#o?.shell,this.#e,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#$?.(),this.#$=mi(this.#n,this.#o?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)}),this.#W?.(),this.#W=bi(this,this.#o?.shell,this.#e,()=>this.closeToolPanel())}}customElements.get(I.tagName)||customElements.define(I.tagName,I),globalThis.DataGridElement=I;const Qi={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"};class Zi{static dependencies;static manifest;version=typeof __GRID_VERSION__<"u"?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#a;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#a?.abort(),this.#a=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#a?.abort(),this.#a=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.#a?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...k,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(e===!1||e==="off")return!1;if(e===!0||e==="on")return!0;const i=this.gridElement;return i?getComputedStyle(i).getPropertyValue("--tbw-animation-enabled").trim()!=="0":!0}get animationDuration(){const e=this.gridElement;if(e){const i=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(i,10);if(!isNaN(o))return o}return 200}resolveIcon(e,i){return i!==void 0?i:this.gridIcons[e]}setIcon(e,i){typeof i=="string"?e.innerHTML=i:i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const x={ROOT:"tbw-grid-root",HEADER:"header",HEADER_ROW:"header-row",HEADER_CELL:"header-cell",ROWS_VIEWPORT:"rows-viewport",ROWS_SPACER:"rows-spacer",ROWS_CONTAINER:"rows",DATA_ROW:"data-row",GROUP_ROW:"group-row",DATA_CELL:"data-cell",SELECTED:"selected",FOCUSED:"focused",EDITING:"editing",EXPANDED:"expanded",COLLAPSED:"collapsed",DRAGGING:"dragging",RESIZING:"resizing",SORTABLE:"sortable",SORTED_ASC:"sorted-asc",SORTED_DESC:"sorted-desc",HIDDEN:"hidden",STICKY_LEFT:"sticky-left",STICKY_RIGHT:"sticky-right",PINNED_TOP:"pinned-top",PINNED_BOTTOM:"pinned-bottom",TREE_TOGGLE:"tree-toggle",TREE_INDENT:"tree-indent",GROUP_TOGGLE:"group-toggle",GROUP_LABEL:"group-label",GROUP_COUNT:"group-count",RANGE_SELECTION:"range-selection",SELECTION_OVERLAY:"selection-overlay"},K={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"},Ji={ROOT:`.${x.ROOT}`,HEADER:`.${x.HEADER}`,HEADER_ROW:`.${x.HEADER_ROW}`,HEADER_CELL:`.${x.HEADER_CELL}`,ROWS_VIEWPORT:`.${x.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${x.ROWS_CONTAINER}`,DATA_ROW:`.${x.DATA_ROW}`,DATA_CELL:`.${x.DATA_CELL}`,GROUP_ROW:`.${x.GROUP_ROW}`,ROW_BY_INDEX:t=>`.${x.DATA_ROW}[${K.ROW_INDEX}="${t}"]`,CELL_BY_FIELD:t=>`.${x.DATA_CELL}[${K.FIELD}="${t}"]`,CELL_AT:(t,e)=>`.${x.DATA_ROW}[${K.ROW_INDEX}="${t}"] .${x.DATA_CELL}[${K.COL_INDEX}="${e}"]`,SELECTED_ROWS:`.${x.DATA_ROW}.${x.SELECTED}`,EDITING_CELL:`.${x.DATA_CELL}.${x.EDITING}`},eo={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 to(t){const e=document.createElement("tbw-grid");return t&&(e.gridConfig=t),e}function io(t,e=document){return e.querySelector(t)}const oo={CELL_CHANGE:"cell-change",CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",EDIT_OPEN:"edit-open",EDIT_CLOSE:"edit-close",CHANGED_ROWS_RESET:"changed-rows-reset",MOUNT_EXTERNAL_VIEW:"mount-external-view",MOUNT_EXTERNAL_EDITOR:"mount-external-editor",SORT_CHANGE:"sort-change",COLUMN_RESIZE:"column-resize",ACTIVATE_CELL:"activate-cell",CELL_ACTIVATE:"cell-activate",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change"},no={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"},Ae={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]},Q=new Map,M={register(t,e){Q.set(t,e)},unregister(t){Q.delete(t)},get(t){if(t!==void 0)return typeof t=="function"?t:Q.get(t)??Ae[t]},run(t,e,i,o){const n=this.get(t);return n?n(e,i,o):void 0},has(t){return Q.has(t)||t in Ae},list(){return[...Object.keys(Ae),...Q.keys()]}},gt={sum:t=>t.reduce((e,i)=>e+i,0),avg:t=>t.length?t.reduce((e,i)=>e+i,0)/t.length:0,count:t=>t.length,min:t=>t.length?Math.min(...t):0,max:t=>t.length?Math.max(...t):0,first:t=>t[0]??0,last:t=>t[t.length-1]??0};function pt(t){return gt[t]??gt.sum}function ro(t,e){return pt(t)(e)}const so=M.register.bind(M),lo=M.unregister.bind(M),ao=M.get.bind(M),co=M.run.bind(M),ho=M.list.bind(M);_.BaseGridPlugin=Zi,_.DEFAULT_ANIMATION_CONFIG=xe,_.DEFAULT_GRID_ICONS=k,_.DGEvents=oo,_.DataGridElement=I,_.FitModeEnum=F,_.GridCSSVars=eo,_.GridClasses=x,_.GridDataAttrs=K,_.GridElement=I,_.GridSelectors=Ji,_.PLUGIN_QUERIES=Qi,_.PluginEvents=no,_.PluginManager=j,_.RenderPhase=A,_.aggregatorRegistry=M,_.builtInSort=pe,_.createGrid=to,_.defaultComparator=Be,_.getAggregator=ao,_.getValueAggregator=pt,_.listAggregators=ho,_.queryGrid=io,_.registerAggregator=so,_.runAggregator=co,_.runValueAggregator=ro,_.unregisterAggregator=lo,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGrid={})}(this,function(e){"use strict";const t={STRETCH:"stretch",FIXED:"fixed"},i={mode:"reduced-motion",duration:200,easing:"ease-out"},o='<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>',r={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:o,filterActive:o,print:"🖨️"};function n(e,t){if(!(e&&e.length||t&&t.length))return[];if(!e||!e.length)return t||[];if(!t||!t.length)return e;const i={};t.forEach(e=>{const t=i[e.field];if(t){e.header&&!t.header&&(t.header=e.header),e.type&&!t.type&&(t.type=e.type),e.sortable&&(t.sortable=!0),e.editable&&(t.editable=!0),e.resizable&&(t.resizable=!0),null!=e.width&&null==t.width&&(t.width=e.width),null!=e.minWidth&&null==t.minWidth&&(t.minWidth=e.minWidth),e.__viewTemplate&&(t.__viewTemplate=e.__viewTemplate),e.__editorTemplate&&(t.__editorTemplate=e.__editorTemplate),e.__headerTemplate&&(t.__headerTemplate=e.__headerTemplate);const i=e.renderer||e.viewRenderer,o=t.renderer||t.viewRenderer;i&&!o&&(t.viewRenderer=i,e.renderer&&(t.renderer=i)),e.editor&&!t.editor&&(t.editor=e.editor)}else i[e.field]={...e}});const o=e.map(e=>{const t=i[e.field];if(!t)return e;const o={...e};t.header&&!o.header&&(o.header=t.header),t.type&&!o.type&&(o.type=t.type),o.sortable=e.sortable||t.sortable,!0!==e.resizable&&!0!==t.resizable||(o.resizable=!0),o.editable=e.editable||t.editable,null!=t.width&&null==o.width&&(o.width=t.width),null!=t.minWidth&&null==o.minWidth&&(o.minWidth=t.minWidth),t.__viewTemplate&&(o.__viewTemplate=t.__viewTemplate),t.__editorTemplate&&(o.__editorTemplate=t.__editorTemplate),t.__headerTemplate&&(o.__headerTemplate=t.__headerTemplate);const r=t.renderer||t.viewRenderer,n=o.renderer||o.viewRenderer;return r&&!n&&(o.viewRenderer=r,t.renderer&&(o.renderer=r)),t.editor&&!o.editor&&(o.editor=t.editor),delete i[e.field],o});return Object.keys(i).forEach(e=>o.push(i[e])),o}function s(e,t){try{e.part?.add?.(t)}catch{}const i=e.getAttribute("part");i?i.split(/\s+/).includes(t)||e.setAttribute("part",i+" "+t):e.setAttribute("part",t)}function l(e){const i=e.effectiveConfig?.fitMode||e.fitMode||t.STRETCH;if(i!==t.STRETCH&&i!==t.FIXED)return;if(e.__didInitialAutoSize)return;if(!e.isConnected)return;const o=Array.from(e._headerRowEl?.children||[]);if(!o.length)return;let r=!1;e._visibleColumns.forEach((t,i)=>{if(t.width)return;const n=o[i];let s=n?n.scrollWidth:0;for(const o of e._rowPool){const e=o.children[i];if(e){const t=e.scrollWidth;t>s&&(s=t)}}s>0&&(t.width=s+2,t.__autoSized=!0,r=!0)}),r&&d(e),e.__didInitialAutoSize=!0}const a=/^(?:\d+(?:\.\d+)?(?:px|%|fr|em|rem|ch|vw|vh|vmin|vmax)|calc\(.+\)|min-content|max-content|minmax\(.+\)|fit-content\(.+\)|auto)$/i;function c(e,t){return"number"==typeof e?`${e}px`:(a.test(e)||console.warn(`[tbw-grid] Column '${t??"?"}' has an invalid CSS width value: '${e}'. Expected a number (px) or a valid CSS unit string (e.g. '30%', '2fr', 'calc(...)').`),e)}function d(e){const i=e.effectiveConfig?.fitMode||e.fitMode||t.STRETCH;e._gridTemplate=i===t.STRETCH?e._visibleColumns.map(e=>{if(null!=e.width)return c(e.width,e.field);const t=e.minWidth;return null!=t?`minmax(${t}px, 1fr)`:"1fr"}).join(" ").trim():e._visibleColumns.map(e=>null!=e.width?c(e.width,e.field):"max-content").join(" "),e.style.setProperty("--tbw-column-template",e._gridTemplate)}function h(e,t){const i=e[0]||{},o=Object.keys(i).map(e=>{const t=i[e],o=null==(r=t)?"string":"number"==typeof r?"number":"boolean"==typeof r?"boolean":r instanceof Date||"string"==typeof r&&/\d{4}-\d{2}-\d{2}/.test(r)&&!isNaN(Date.parse(r))?"date":"string";var r;return{field:e,header:e.charAt(0).toUpperCase()+e.slice(1),type:o}}),r={};return o.forEach(e=>{r[e.field]=e.type||"string"}),{columns:o,typeMap:r}}const u=/{{\s*([^}]+)\s*}}/g,g="__DG_EMPTY__",f=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,p=/__(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/;const w=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"]),b=/^on\w+$/i,m=new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),v=/^\s*(javascript|vbscript|data|blob):/i;function C(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],i=e.querySelectorAll("*");for(const o of i){const e=o.tagName.toLowerCase();if(w.has(e)){t.push(o);continue}if("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI){if(Array.from(o.attributes).some(e=>b.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}}const i=[];for(const t of o.attributes){const e=t.name.toLowerCase();b.test(e)?i.push(t.name):(m.has(e)&&v.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&i.push(t.name)}i.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}function y(e,t){if(!e||-1===e.indexOf("{{"))return e;const i=[],o=e.replace(u,(e,o)=>{const r=function(e,t){if(e=(e||"").trim(),!e)return g;if(_.test(e))return g;if("value"===e)return null==t.value?g:String(t.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(4),o=t.row?t.row[i]:void 0;return null==o?g:String(o)}if(e.length>80)return g;if(!f.test(e)||p.test(e))return g;const i=e.match(/\./g);if(i&&i.length>1)return g;try{const i=new Function("value","row",`return (${e});`)(t.value,t.row),o=null==i?"":String(i);return _.test(o)?g:o||g}catch{return g}}(o,t);return i.push({expr:o.trim(),result:r}),r}),r=(n=o)?n.replace(new RegExp(g,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n;var n;const s=i.length&&i.every(e=>""===e.result||e.result===g);return _.test(e)||s?"":r}const _=/Reflect|Proxy|ownKeys/;function S(e){if(_.test(e.textContent||"")){for(const t of e.childNodes)t.nodeType===Node.TEXT_NODE&&_.test(t.textContent||"")&&(t.textContent="");_.test(e.textContent||"")&&(e.textContent="")}}function R(e){const t=_.test(e),i=i=>{if(t)return"";return y(e,i)};return i.__blocked=t,i}class E{#e;#t;#i;#o;#r;#n={};#s={};#l=!0;#a=[];#c;#d;#h;#u;#g;constructor(e){this.#u=e}get original(){return this.#n}get effective(){return this.#s}get columns(){return this.#s.columns??[]}set columns(e){this.#s.columns=e}get lightDomColumnsCache(){return this.#o}set lightDomColumnsCache(e){this.#o=e}get originalColumnNodes(){return this.#r}set originalColumnNodes(e){this.#r=e}get lightDomTitle(){return this.#g}set lightDomTitle(e){this.#g=e}get initialColumnState(){return this.#h}set initialColumnState(e){this.#h=e}get sourcesChanged(){return this.#l}markSourcesChanged(){this.#l=!0}setGridConfig(e){this.#e=e,this.#l=!0,this.#o=void 0}getGridConfig(){return this.#e}setColumns(e){this.#t=e,this.#l=!0}getColumns(){return this.#t}setFitMode(e){this.#i=e,this.#l=!0}getFitMode(){return this.#i}merge(){const e=(this.#s.columns?.length??0)>0;if(!this.#l&&e)return;const t=this.#f();this.#l=!1,this.#n=t,Object.freeze(this.#n),this.#n.columns&&Object.freeze(this.#n.columns),this.#s=this.#p(this.#n),this.#w()}#p(e){const t={...e};return e.columns&&(t.columns=e.columns.map(e=>({...e}))),e.shell&&(t.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(e=>({...e})),headerContents:e.shell.headerContents?.map(e=>({...e}))}),t}#w(){const e=this.#s;if(this.#b(),"number"==typeof e.rowHeight&&e.rowHeight>0&&this.#u.setRowHeight(e.rowHeight),"fixed"===e.fitMode){this.columns.forEach(e=>{null==e.width&&(e.width=80)})}this.#u.applyAnimationConfig(e)}#b(){const e=this.#s.typeDefaults;if(!e)return;const t=this.columns;for(const i of t){if(!i.type)continue;const t=e[i.type];t&&(i.renderer||i.viewRenderer||!t.renderer||(i.renderer=t.renderer),!i.format&&t.format&&(i.format=t.format),!i.editor&&t.editor&&(i.editor=t.editor),!i.editorParams&&t.editorParams&&(i.editorParams=t.editorParams))}}#f(){const e=this.#e?{...this.#e}:{},t=Array.isArray(e.columns)?[...e.columns]:[],i=(this.#o??[]).map(e=>({...e}));let o=n(t,i);this.#t&&this.#t.length&&(o=n(this.#t,i));const r=this.#u.getRows();if(0===o.length&&r.length){o=h(r).columns}return o.length&&(o.forEach(e=>{void 0===e.sortable&&(e.sortable=!0),void 0===e.resizable&&(e.resizable=!0),void 0===e.__originalWidth&&"number"==typeof e.width&&(e.__originalWidth=e.width)}),o.forEach(e=>{e.__viewTemplate&&!e.__compiledView&&(e.__compiledView=R(e.__viewTemplate.innerHTML)),e.__editorTemplate&&!e.__compiledEditor&&(e.__compiledEditor=R(e.__editorTemplate.innerHTML))}),e.columns=o),this.#i&&(e.fitMode=this.#i),e.fitMode||(e.fitMode="stretch"),this.#m(e),e.columnState&&!this.#h&&(this.#h=e.columnState),e}#m(e){e.shell=e.shell?{...e.shell}:{},e.shell.header=e.shell.header?{...e.shell.header}:{};const t=this.#u.getShellLightDomTitle();t&&(this.#g=t),this.#g&&!e.shell.header.title&&(e.shell.header.title=this.#g);const i=this.#u.getShellLightDomHeaderContent();i?.length>0&&(e.shell.header.lightDomContent=i),this.#u.getShellHasToolButtonsContainer()&&(e.shell.header.hasToolButtonsContainer=!0);const o=this.#u.getShellToolPanels();if(o.size>0){const t=Array.from(o.values());t.sort((e,t)=>(e.order??100)-(t.order??100)),e.shell.toolPanels=t}const r=this.#u.getShellHeaderContents();if(r.size>0){const t=Array.from(r.values());t.sort((e,t)=>(e.order??100)-(t.order??100)),e.shell.headerContents=t}const n=this.#u.getShellToolbarContents(),s=Array.from(n.values()),l=this.#e?.shell?.header?.toolbarContents??[],a=new Set(l.map(e=>e.id)),c=[...l];for(const d of s)a.has(d.id)||c.push(d);c.sort((e,t)=>(e.order??0)-(t.order??0)),e.shell.header.toolbarContents=c}collectState(e){const t=this.columns,i=this.#v();return{columns:t.map((t,o)=>{const r={field:t.field,order:o,visible:!t.hidden},n=t;void 0!==n.__renderedWidth?r.width=n.__renderedWidth:void 0!==t.width&&(r.width="string"==typeof t.width?parseFloat(t.width):t.width);const s=i.get(t.field);s&&(r.sort=s);for(const i of e)if(i.getColumnState){const e=i.getColumnState(t.field);e&&Object.assign(r,e)}return r})}}applyState(e,t){if(!e.columns||0===e.columns.length)return;const i=this.columns,o=new Map(e.columns.map(e=>[e.field,e])),r=i.map(e=>{const t=o.get(e.field);if(!t)return e;const i={...e};return void 0!==t.width&&(i.width=t.width,i.__renderedWidth=t.width),void 0!==t.visible&&(i.hidden=!t.visible),i});r.sort((e,t)=>(o.get(e.field)?.order??1/0)-(o.get(t.field)?.order??1/0)),this.columns=r;const n=e.columns.filter(e=>void 0!==e.sort).sort((e,t)=>(e.sort?.priority??0)-(t.sort?.priority??0));if(n.length>0){const e=n[0];e.sort&&this.#u.setSortState({field:e.field,direction:"asc"===e.sort.direction?1:-1})}else this.#u.setSortState(null);for(const s of t)if(s.applyColumnState)for(const t of e.columns)s.applyColumnState(t.field,t)}resetState(e){this.#h=void 0,this.#u.setSortState(null),this.#s=this.#p(this.#n),this.#w();for(const t of e)if(t.applyColumnState)for(const e of this.columns)t.applyColumnState(e.field,{field:e.field,order:0,visible:!0});this.requestStateChange(e)}#v(){const e=new Map,t=this.#u.getSortState();return t&&e.set(t.field,{direction:1===t.direction?"asc":"desc",priority:0}),e}requestStateChange(e){this.#d&&clearTimeout(this.#d),this.#d=setTimeout(()=>{this.#d=void 0;const t=this.collectState(e);this.#u.emit("column-state-change",t)},100)}setColumnVisible(e,t){const i=this.columns,o=i.find(t=>t.field===e);if(!o)return!1;if(!t&&o.lockVisible)return!1;if(!t){if(0===i.filter(t=>!t.hidden&&t.field!==e).length)return!1}return!!o.hidden!=!t&&(o.hidden=!t,this.#u.emit("column-visibility",{field:e,visible:t,visibleColumns:i.filter(e=>!e.hidden).map(e=>e.field)}),this.#u.clearRowPool(),this.#u.setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(t=>t.field===e);return!!t&&this.setColumnVisible(e,!!t.hidden)}isColumnVisible(e){const t=this.columns.find(t=>t.field===e);return!!t&&!t.hidden}showAllColumns(){const e=this.columns;e.some(e=>e.hidden)&&(e.forEach(e=>e.hidden=!1),this.#u.emit("column-visibility",{visibleColumns:e.map(e=>e.field)}),this.#u.clearRowPool(),this.#u.setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:!0===e.meta?.utility}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const t=new Map(this.columns.map(e=>[e.field,e])),i=[];for(const o of e){const e=t.get(o);e&&(i.push(e),t.delete(o))}for(const o of t.values())i.push(o);this.columns=i,this.#u.renderHeader(),this.#u.updateTemplate(),this.#u.refreshVirtualWindow()}parseLightDomColumns(e){this.#o||(this.#r=Array.from(e.querySelectorAll("tbw-grid-column")),this.#o=this.#r.length?function(e){return Array.from(e.querySelectorAll("tbw-grid-column")).map(e=>{const t=e.getAttribute("field")||"";if(!t)return null;const i=e.getAttribute("type")||void 0,o={field:t,type:i&&new Set(["number","string","date","boolean","select"]).has(i)?i:void 0,header:e.getAttribute("header")||void 0,sortable:e.hasAttribute("sortable"),editable:e.hasAttribute("editable")},r=e.getAttribute("width");if(r){const e=parseFloat(r);!isNaN(e)&&/^\d+(\.\d+)?$/.test(r.trim())?o.width=e:o.width=r}const n=e.getAttribute("minWidth")||e.getAttribute("min-width");if(n){const e=parseFloat(n);isNaN(e)||(o.minWidth=e)}e.hasAttribute("resizable")&&(o.resizable=!0),e.hasAttribute("sizable")&&(o.resizable=!0);const s=e.getAttribute("editor"),l=e.getAttribute("renderer");s&&(o.__editorName=s),l&&(o.__rendererName=l);const a=e.getAttribute("options");a&&(o.options=a.split(",").map(e=>{const[t,i]=e.includes(":")?e.split(":"):[e.trim(),e.trim()];return{value:t.trim(),label:i?.trim()||t.trim()}}));const c=e.querySelector("tbw-grid-column-view"),d=e.querySelector("tbw-grid-column-editor"),h=e.querySelector("tbw-grid-column-header");c&&(o.__viewTemplate=c),d&&(o.__editorTemplate=d),h&&(o.__headerTemplate=h);const u=globalThis.DataGridElement,g=u?.getAdapters?.()??[],f=c??e,p=g.find(e=>e.canHandle(f));if(p){const e=p.createRenderer(f);e&&(o.viewRenderer=e)}const w=d??e,b=g.find(e=>e.canHandle(w));if(b){const e=b.createEditor(w);e&&(o.editor=e)}return o}).filter(e=>!!e)}(e):[])}clearLightDomCache(){this.#o=void 0}#C=new Map;registerLightDomHandler(e,t){this.#C.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#C.delete(e.toLowerCase())}observeLightDOM(e){this.#c&&this.#c.disconnect();const t=new Set;let i=null;const o=()=>{i=null;for(const e of t){const t=this.#C.get(e);t?.()}t.clear()};this.#c=new MutationObserver(e=>{for(const i of e){for(const e of i.addedNodes){if(e.nodeType!==Node.ELEMENT_NODE)continue;const i=e.tagName.toLowerCase();this.#C.has(i)&&t.add(i)}if("attributes"===i.type&&i.target.nodeType===Node.ELEMENT_NODE){const e=i.target.tagName.toLowerCase();this.#C.has(e)&&t.add(e)}}t.size>0&&!i&&(i=setTimeout(o,0))}),this.#c.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#a.push(e)}notifyChange(){for(const e of this.#a)e()}dispose(){this.#c?.disconnect(),this.#a=[],this.#d&&clearTimeout(this.#d)}}function x(){if("undefined"!=typeof window&&window.location){const e=window.location.hostname;if("localhost"===e||"127.0.0.1"===e||"::1"===e)return!0}return"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV}function A(e){return`<span role="checkbox" aria-checked="${e}" aria-label="${e}">${e?"🗹":"☐"}</span>`}function T(e){if(null==e||""===e)return"";if(e instanceof Date)return isNaN(e.getTime())?"":e.toLocaleDateString();if("number"==typeof e||"string"==typeof e){const t=new Date(e);return isNaN(t.getTime())?"":t.toLocaleDateString()}return""}function H(e){if(!e)return-1;const t=e.getAttribute("data-row");if(t)return parseInt(t,10);const i=e.closest(".data-grid-row");if(!i)return-1;const o=i.parentElement;if(!o)return-1;const r=o.querySelectorAll(":scope > .data-grid-row");for(let n=0;n<r.length;n++)if(r[n]===i)return n;return-1}function P(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function M(e){return"rtl"===function(e){try{if("rtl"===getComputedStyle(e).direction)return"rtl"}catch{}try{const t=e.closest?.("[dir]")?.getAttribute("dir");if("rtl"===t)return"rtl"}catch{}return"ltr"}(e)}function L(e,t){const i=t.renderer||t.viewRenderer;if(i)return i;if(!t.type)return;const o=e.__frameworkAdapter;if(o?.getTypeDefault){const e=o.getTypeDefault(t.type);if(e?.renderer)return e.renderer}}function z(e,t){if(t.format)return t.format;if(!t.type)return;const i=e.__frameworkAdapter;if(i?.getTypeDefault){const e=i.getTypeDefault(t.type);if(e?.format)return e.format}}const O='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function k(e){return(e.__editingCellCount??0)>0}function D(e){e.__editingCellCount=0,e.removeAttribute("data-has-editing");e.querySelectorAll(".cell.editing").forEach(e=>e.classList.remove("editing"))}const I=document.createElement("template");I.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const N=document.createElement("template");function q(){return I.content.firstElementChild.cloneNode(!0)}function $(){return N.content.firstElementChild.cloneNode(!0)}function W(e){e.__cellDisplayCache=void 0,e.__cellCacheEpoch=void 0,e.__hasSpecialColumns=void 0}function F(e,t,i,o){const r=t.children,n=e._visibleColumns,s=n.length,l=r.length,a=s<l?s:l,c=e._focusRow,d=e._focusCol,h=e._hasAfterCellRenderHook?.()??!1;let u=e.__hasSpecialColumns;if(void 0===u){u=!1;const t=e.__frameworkAdapter;for(let e=0;e<s;e++){const i=n[e];if(i.__viewTemplate||i.__compiledView||i.renderer||i.viewRenderer||i.externalView||i.format||"date"===i.type||"boolean"===i.type||i.type&&t?.getTypeDefault?.(i.type)?.renderer||i.type&&t?.getTypeDefault?.(i.type)?.format){u=!0;break}}e.__hasSpecialColumns=u}const g=String(o);if(u){for(let s=0;s<a;s++){if(n[s].externalView){if(!r[s].querySelector("[data-external-view]"))return void U(e,t,i,o)}}for(let s=0;s<a;s++){const l=n[s],a=r[s];a.getAttribute("data-row")!==g&&a.setAttribute("data-row",g);const u=a.classList.contains("editing");if(!u){const e=c===o&&d===s;e!==a.classList.contains("cell-focus")&&(a.classList.toggle("cell-focus",e),a.setAttribute("aria-selected",String(e)))}const p=l.cellClass;if(p){const e=a.getAttribute("data-dynamic-classes");e&&e.split(" ").forEach(e=>e&&a.classList.remove(e));try{const e=p(i[l.field],i,l);if(e&&e.length>0){const t=e.filter(e=>e&&"string"==typeof e);t.forEach(e=>a.classList.add(e)),a.setAttribute("data-dynamic-classes",t.join(" "))}else a.removeAttribute("data-dynamic-classes")}catch(f){console.warn(`[tbw-grid] cellClass callback error for column '${l.field}':`,f),a.removeAttribute("data-dynamic-classes")}}if(u)continue;const w=L(e,l);if(w){const r=i[l.field],n=w({row:i,value:r,field:l.field,column:l,cellEl:a});"string"==typeof n?(e.__frameworkAdapter?.releaseCell?.(a),a.innerHTML=C(n)):n instanceof Node?n.parentElement!==a&&(e.__frameworkAdapter?.releaseCell?.(a),a.innerHTML="",a.appendChild(n)):null==n&&(e.__frameworkAdapter?.releaseCell?.(a),a.textContent=null==r?"":String(r)),h&&e._afterCellRender?.({row:i,rowIndex:o,column:l,colIndex:s,value:r,cellElement:a,rowElement:t});continue}if(l.__compiledView){const r=i[l.field],n=l.__compiledView({row:i,value:r,field:l.field,column:l});l.__compiledView.__blocked?a.textContent="":(a.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(a),a.innerHTML=C(n),S(a)),h&&e._afterCellRender?.({row:i,rowIndex:o,column:l,colIndex:s,value:r,cellElement:a,rowElement:t});continue}if(l.__viewTemplate){const r=i[l.field],n=l.__viewTemplate.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(n)?a.textContent="":(a.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(a),a.innerHTML=C(y(n,{row:i,value:r})),S(a)),h&&e._afterCellRender?.({row:i,rowIndex:o,column:l,colIndex:s,value:r,cellElement:a,rowElement:t});continue}if(l.externalView)continue;const b=i[l.field];let m;const v=z(e,l);if(v){try{const e=v(b,i);m=null==e?"":String(e)}catch(f){console.warn(`[tbw-grid] Format error in column '${l.field}':`,f),m=null==b?"":String(b)}a.textContent=m}else"date"===l.type?(m=T(b),a.textContent=m):"boolean"===l.type?a.innerHTML=A(!!b):(m=null==b?"":String(b),a.textContent=m);h&&e._afterCellRender?.({row:i,rowIndex:o,column:l,colIndex:s,value:b,cellElement:a,rowElement:t})}}else for(let p=0;p<a;p++){const s=r[p];if(s.classList.contains("editing"))continue;s.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(s);const l=n[p],a=i[l.field];s.textContent=null==a?"":String(a),s.getAttribute("data-row")!==g&&s.setAttribute("data-row",g);const u=c===o&&d===p;u!==s.classList.contains("cell-focus")&&(s.classList.toggle("cell-focus",u),s.setAttribute("aria-selected",String(u))),h&&e._afterCellRender?.({row:i,rowIndex:o,column:l,colIndex:p,value:a,cellElement:s,rowElement:t})}}function U(e,t,i,o){t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy");const r=e.__frameworkAdapter;if(r?.releaseCell){const e=t.children;for(let t=e.length-1;t>=0;t--)r.releaseCell(e[t])}t.innerHTML="";const n=e._visibleColumns,s=n.length,l=e._focusRow,a=e._focusCol,c=e,d=e._hasAfterCellRenderHook?.()??!1,h=document.createDocumentFragment();for(let g=0;g<s;g++){const r=n[g],s=q();s.setAttribute("aria-colindex",String(g+1)),s.setAttribute("data-col",String(g)),s.setAttribute("data-row",String(o)),s.setAttribute("data-field",r.field),s.setAttribute("data-header",r.header??r.field),r.type&&s.setAttribute("data-type",r.type);let f=i[r.field];const p=z(e,r);if(p)try{f=p(f,i)}catch(u){console.warn(`[tbw-grid] Format error in column '${r.field}':`,u)}const w=r.__compiledView,b=r.__viewTemplate,m=L(e,r),v=r.externalView;let _=!1;if(m){const e=m({row:i,value:f,field:r.field,column:r,cellEl:s});"string"==typeof e?(s.innerHTML=C(e),_=!0):e instanceof Node?e.parentElement!==s&&(s.textContent="",s.appendChild(e)):null==e&&(s.textContent=null==f?"":String(f))}else if(v){const e=v,t=document.createElement("div");t.setAttribute("data-external-view",""),t.setAttribute("data-field",r.field),s.appendChild(t);const o={row:i,value:f,field:r.field,column:r};if(e.mount)try{e.mount({placeholder:t,context:o,spec:e})}catch(u){console.warn(`[tbw-grid] External view mount error for column '${r.field}':`,u)}else queueMicrotask(()=>{try{c.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:t,spec:e,context:o}}))}catch(u){console.warn(`[tbw-grid] External view event dispatch error for column '${r.field}':`,u)}});t.setAttribute("data-mounted","")}else if(w){const e=w({row:i,value:f,field:r.field,column:r}),t=w.__blocked;s.innerHTML=t?"":C(e),_=!0,t&&(s.textContent="",s.setAttribute("data-blocked-template",""))}else if(b){const e=b.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(e)?(s.textContent="",s.setAttribute("data-blocked-template","")):(s.innerHTML=C(y(e,{row:i,value:f})),_=!0)}else p?s.textContent=null==f?"":String(f):"date"===r.type?s.textContent=T(f):"boolean"===r.type?s.innerHTML=A(!!f):s.textContent=null==f?"":String(f);if(_){S(s);const e=s.textContent||"";/Proxy|Reflect\.ownKeys/.test(e)&&(s.textContent=e.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(s.textContent||"")&&(s.textContent=""))}s.hasAttribute("data-blocked-template")&&(s.textContent||"").trim().length&&(s.textContent=""),r.editable?s.tabIndex=0:"boolean"===r.type&&(s.hasAttribute("tabindex")||(s.tabIndex=0)),l===o&&a===g?(s.classList.add("cell-focus"),s.setAttribute("aria-selected","true")):s.setAttribute("aria-selected","false");const R=r.cellClass;if(R)try{const e=R(i[r.field],i,r);if(e&&e.length>0){const t=e.filter(e=>e&&"string"==typeof e);t.forEach(e=>s.classList.add(e)),s.setAttribute("data-dynamic-classes",t.join(" "))}}catch(u){console.warn(`[tbw-grid] cellClass callback error for column '${r.field}':`,u)}d&&e._afterCellRender?.({row:i,rowIndex:o,column:r,colIndex:g,value:f,cellElement:s,rowElement:t}),h.appendChild(s)}t.appendChild(h)}function V(e,t,i){if(t.target?.closest(".resize-handle"))return;const o=H(i.querySelector(".cell[data-row]"));if(o<0)return;const r=e._rows[o];if(!r)return;if(e._dispatchRowClick?.(t,o,r,i))return;const n=t.target?.closest(".cell[data-col]");if(n){const i=Number(n.getAttribute("data-col"));if(!isNaN(i)){if(e._dispatchCellClick?.(t,o,i,n))return;const r=e._focusRow!==o||e._focusCol!==i;if(e._focusRow=o,e._focusCol=i,n.classList.contains("editing")){r&&(P(e._bodyEl??e),n.classList.add("cell-focus"));const t=n.querySelector(O);try{t?.focus({preventScroll:!0})}catch{}return}G(e)}}}function G(e,t){if(e._virtualization?.enabled){const{rowHeight:t,container:i,viewportEl:o}=e._virtualization,r=i,n=o?.clientHeight??r?.clientHeight??0;if(r&&n>0){const i=e._focusRow*t;i<r.scrollTop?r.scrollTop=i:i+t>r.scrollTop+n&&(r.scrollTop=i-n+t)}}const i=void 0!==e._activeEditRows&&-1!==e._activeEditRows;i||e.refreshVirtualWindow(!1),P(e._bodyEl),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const o=e._focusRow,r=e._virtualization.start??0,n=e._virtualization.end??e._rows.length;if(o>=r&&o<n){const n=e._bodyEl.querySelectorAll(".data-grid-row")[o-r];let s=n?.children[e._focusCol];if(s&&s.classList?.contains("cell")||(s=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),s){s.classList.add("cell-focus"),s.setAttribute("aria-selected","true");const o=e.querySelector(".tbw-scroll-area");if(o&&s&&(!i||t?.forceHorizontalScroll))if(t?.forceScrollLeft)o.scrollLeft=0;else if(t?.forceScrollRight)o.scrollLeft=o.scrollWidth-o.clientWidth;else{const t=e._getHorizontalScrollOffsets?.(n??void 0,s)??{left:0,right:0};if(!t.skipScroll){const e=s.getBoundingClientRect(),i=o.getBoundingClientRect(),r=e.left-i.left+o.scrollLeft,n=r+e.width,l=o.scrollLeft+t.left,a=o.scrollLeft+o.clientWidth-t.right;r<l?o.scrollLeft=r-t.left:n>a&&(o.scrollLeft=n-o.clientWidth+t.right)}}if(i&&s.classList.contains("editing")){const e=s.querySelector(O);if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(i&&!s.contains(document.activeElement)){s.hasAttribute("tabindex")||s.setAttribute("tabindex","-1");try{s.focus({preventScroll:!0})}catch{}}else if(!i){const t=e;document.activeElement!==t&&t.focus({preventScroll:!0})}}}}N.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const B=new WeakMap;function X(e,t){const i=H(t),o=function(e){if(!e)return-1;const t=e.getAttribute("data-col");return t?parseInt(t,10):-1}(t);if(i<0||o<0)return;e._focusRow=i,e._focusCol=o,P(e._bodyEl),t.classList.add("cell-focus"),t.setAttribute("aria-selected","true");const r=t.closest("tbw-grid");r&&document.activeElement!==r&&r.focus({preventScroll:!0})}function Y(e,t,i,o){let r=null;const n=i.composedPath?.();if(r=n&&n.length>0?n[0]:i.target,r&&!t.contains(r)){const e=document.elementFromPoint(i.clientX,i.clientY);e&&(r=e)}const s=r?.closest?.("[data-col]"),l=r?.closest?.(".data-grid-row"),a=r?.closest?.(".header-row");let c,d,h,u,g,f;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(h=e._rows[c],f=e._visibleColumns[d],u=f?.field,g=h&&u?h[u]:void 0)),{type:o,row:h,rowIndex:void 0!==c&&c>=0?c:void 0,colIndex:void 0!==d&&d>=0?d:void 0,field:u,value:g,column:f,originalEvent:i,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:void 0!==c&&void 0!==d&&c>=0&&d>=0?{row:c,col:d}:void 0}}function j(e,t,i,o){t.addEventListener("keydown",t=>function(e,t){if(e._dispatchKeyDown?.(t))return;const i=e._rows.length-1,o=e._visibleColumns.length-1,r=void 0!==e._activeEditRows&&-1!==e._activeEditRows,n=e._visibleColumns[e._focusCol],s=n?.type,l=t.composedPath?.()??[],a=l.length?l[0]:t.target,c=e=>{if(!e)return!1;const t=e.tagName;return"INPUT"===t||"SELECT"===t||"TEXTAREA"===t||!!e.isContentEditable};if((!c(a)||"Home"!==t.key&&"End"!==t.key)&&!(c(a)&&("ArrowUp"===t.key||"ArrowDown"===t.key)&&"INPUT"===a.tagName&&"number"===a.type||c(a)&&("ArrowLeft"===t.key||"ArrowRight"===t.key)||c(a)&&("Enter"===t.key||"Escape"===t.key)||r&&"select"===s&&("ArrowDown"===t.key||"ArrowUp"===t.key))){switch(t.key){case"Tab":return t.preventDefault(),t.shiftKey?e._focusCol>0?e._focusCol-=1:e._focusRow>0&&("function"==typeof e.commitActiveRowEdit&&e._activeEditRows===e._focusRow&&e.commitActiveRowEdit(),e._focusRow-=1,e._focusCol=o):e._focusCol<o?e._focusCol+=1:("function"==typeof e.commitActiveRowEdit&&e.commitActiveRowEdit(),e._focusRow<i&&(e._focusRow+=1,e._focusCol=0)),void G(e);case"ArrowDown":r&&"function"==typeof e.commitActiveRowEdit&&e.commitActiveRowEdit(),e._focusRow=Math.min(i,e._focusRow+1),t.preventDefault();break;case"ArrowUp":r&&"function"==typeof e.commitActiveRowEdit&&e.commitActiveRowEdit(),e._focusRow=Math.max(0,e._focusRow-1),t.preventDefault();break;case"ArrowRight":{const i=M(e);e._focusCol=i?Math.max(0,e._focusCol-1):Math.min(o,e._focusCol+1),t.preventDefault();break}case"ArrowLeft":{const i=M(e);e._focusCol=i?Math.min(o,e._focusCol+1):Math.max(0,e._focusCol-1),t.preventDefault();break}case"Home":return t.ctrlKey||t.metaKey?(r&&"function"==typeof e.commitActiveRowEdit&&e.commitActiveRowEdit(),e._focusRow=0,e._focusCol=0):e._focusCol=0,t.preventDefault(),void G(e,{forceScrollLeft:!0});case"End":return t.ctrlKey||t.metaKey?(r&&"function"==typeof e.commitActiveRowEdit&&e.commitActiveRowEdit(),e._focusRow=i,e._focusCol=o):e._focusCol=o,t.preventDefault(),void G(e,{forceScrollRight:!0});case"PageDown":e._focusRow=Math.min(i,e._focusRow+20),t.preventDefault();break;case"PageUp":e._focusRow=Math.max(0,e._focusRow-20),t.preventDefault();break;case"Enter":{const i=e._focusRow,o=e._focusCol,r=e._visibleColumns[o],n=e._rows[i],s=r?.field??"",l=s&&n?n[s]:void 0,a=e.querySelector(`[data-row="${i}"][data-col="${o}"]`),c=new CustomEvent("cell-activate",{cancelable:!0,detail:{rowIndex:i,colIndex:o,column:r,field:s,value:l,row:n,cellEl:a,trigger:"keyboard",originalEvent:t}});e.dispatchEvent(c);const d=new CustomEvent("activate-cell",{cancelable:!0,detail:{row:i,col:o}});if(e.dispatchEvent(d),c.defaultPrevented||d.defaultPrevented)return void t.preventDefault();break}default:return}G(e)}}(e,t),{signal:o}),i.addEventListener("mousedown",t=>function(e,t,i){const o=Y(e,t,i,"mousedown");e._dispatchCellMouseDown?.(o)&&B.set(e,!0)}(e,i,t),{signal:o}),document.addEventListener("mousemove",t=>function(e,t,i){if(!B.get(e))return;const o=Y(e,t,i,"mousemove");e._dispatchCellMouseMove?.(o)}(e,i,t),{signal:o}),document.addEventListener("mouseup",t=>function(e,t,i){if(!B.get(e))return;const o=Y(e,t,i,"mouseup");e._dispatchCellMouseUp?.(o),B.set(e,!1)}(e,i,t),{signal:o})}function K(e,t){return null==e&&null==t?0:null==e?-1:null==t||e>t?1:e<t?-1:0}function Z(e,t,i){const o=i.find(e=>e.field===t.field),r=o?.sortComparator??K,{field:n,direction:s}=t;return[...e].sort((e,t)=>r(e[n],t[n],e,t)*s)}function Q(e,t,i,o){e._rows=t,e.__rowRenderEpoch++,e._rowPool.forEach(e=>e.__epoch=-1),se(e),e.refreshVirtualWindow(!0),e.dispatchEvent(new CustomEvent("sort-change",{detail:{field:i.field,direction:o}})),e.requestStateChange?.()}function J(e,t){if(e._sortState&&e._sortState.field===t.field)if(1===e._sortState.direction)ee(e,t,-1);else{e._sortState=null,e.__rowRenderEpoch++,e._rowPool.forEach(e=>e.__epoch=-1),e._rows=e.__originalOrder.slice(),se(e);const i=e._headerRowEl?.querySelectorAll('[role="columnheader"].sortable');i?.forEach(t=>{t.getAttribute("aria-sort")&&("ascending"!==t.getAttribute("aria-sort")&&"descending"!==t.getAttribute("aria-sort")||e._sortState)||t.setAttribute("aria-sort","none")}),e.refreshVirtualWindow(!0),e.dispatchEvent(new CustomEvent("sort-change",{detail:{field:t.field,direction:0}})),e.requestStateChange?.()}else e._sortState||(e.__originalOrder=e._rows.slice()),ee(e,t,1)}function ee(e,t,i){e._sortState={field:t.field,direction:i};const o={field:t.field,direction:i},r=e._columns,n=(e.effectiveConfig?.sortHandler??Z)(e._rows,o,r);n&&"function"==typeof n.then?n.then(o=>{Q(e,o,t,i)}):Q(e,n,t,i)}function te(e,t){return!1!==e.effectiveConfig?.sortable&&!0===t.sortable}function ie(e,t){return!1!==e.effectiveConfig?.resizable&&!1!==t.resizable}function oe(e,t){const i=document.createElement("span");s(i,"sort-indicator");const o=e._sortState?.field===t.field?e._sortState.direction:0,n={...r,...e.icons};return function(e,t){"string"==typeof t?e.textContent=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}(i,1===o?n.sortAsc:-1===o?n.sortDesc:n.sortNone),i}function re(e,t,i){const o=document.createElement("div");return o.className="resize-handle",o.setAttribute("aria-hidden","true"),o.addEventListener("mousedown",o=>{o.stopPropagation(),o.preventDefault(),e._resizeController.start(o,t,i)}),o.addEventListener("dblclick",i=>{i.stopPropagation(),i.preventDefault(),e._resizeController.resetColumn(t)}),o}function ne(e,t,i,o){o.classList.add("sortable"),o.tabIndex=0;const r=e._sortState?.field===t.field?e._sortState.direction:0;o.setAttribute("aria-sort",0===r?"none":1===r?"ascending":"descending"),o.addEventListener("click",i=>{e._resizeController?.isResizing||e._dispatchHeaderClick?.(i,t,o)||J(e,t)}),o.addEventListener("keydown",i=>{if("Enter"===i.key||" "===i.key){if(i.preventDefault(),e._dispatchHeaderClick?.(i,t,o))return;J(e,t)}})}function se(e){e._headerRowEl=e.findHeaderRow();const t=e._headerRowEl;t&&(t.innerHTML="",e._visibleColumns.forEach((i,o)=>{const r=document.createElement("div");r.className="cell",s(r,"header-cell"),r.setAttribute("role","columnheader"),r.setAttribute("aria-colindex",String(o+1)),r.setAttribute("data-field",i.field),r.setAttribute("data-col",String(o)),i.type&&r.setAttribute("data-type",i.type);const n=i.header??i.field,l=e._sortState?.field===i.field?e._sortState.direction:0,a=1===l?"asc":-1===l?"desc":null;if(i.headerRenderer){const t={column:i,value:n,sortState:a,filterActive:!1,cellEl:r,renderSortIcon:()=>te(e,i)?oe(e,i):null,renderFilterButton:()=>null},s=i.headerRenderer(t);!function(e,t){if(null!=t)if("string"==typeof t){const i=document.createElement("span");for(i.innerHTML=C(t);i.firstChild;)e.appendChild(i.firstChild)}else t instanceof Node&&e.appendChild(t)}(r,s),te(e,i)&&ne(e,i,0,r),ie(e,i)&&(r.classList.add("resizable"),r.appendChild(re(e,o,r)))}else if(i.headerLabelRenderer){const t={column:i,value:n},s=i.headerLabelRenderer(t),l=document.createElement("span");null==s?l.textContent=n:"string"==typeof s?l.innerHTML=C(s):s instanceof Node&&l.appendChild(s),r.appendChild(l),te(e,i)&&(ne(e,i,0,r),r.appendChild(oe(e,i))),ie(e,i)&&(r.classList.add("resizable"),r.appendChild(re(e,o,r)))}else if(i.__headerTemplate)Array.from(i.__headerTemplate.childNodes).forEach(e=>r.appendChild(e.cloneNode(!0))),te(e,i)&&(ne(e,i,0,r),r.appendChild(oe(e,i))),ie(e,i)&&(r.classList.add("resizable"),r.appendChild(re(e,o,r)));else{const t=document.createElement("span");t.textContent=n,r.appendChild(t),te(e,i)&&(ne(e,i,0,r),r.appendChild(oe(e,i))),ie(e,i)&&(r.classList.add("resizable"),r.appendChild(re(e,o,r)))}t.appendChild(r)}),t.querySelectorAll(".cell.sortable").forEach(e=>{e.getAttribute("aria-sort")||e.setAttribute("aria-sort","none")}),t.children.length>0?(t.setAttribute("role","row"),t.setAttribute("aria-rowindex","1")):(t.removeAttribute("role"),t.removeAttribute("aria-rowindex")))}const le="function"==typeof requestIdleCallback;function ae(e){le?cancelIdleCallback(e):clearTimeout(e)}function ce(e,t){if(t){const i=t({size:e});if("string"==typeof i){const e=document.createElement("div");return e.innerHTML=i,e}return i}return function(e){const t=document.createElement("div");return t.className=`tbw-spinner tbw-spinner--${e}`,t.setAttribute("role","progressbar"),t.setAttribute("aria-label","Loading"),t}(e)}var de=(e=>(e[e.STYLE=1]="STYLE",e[e.VIRTUALIZATION=2]="VIRTUALIZATION",e[e.HEADER=3]="HEADER",e[e.ROWS=4]="ROWS",e[e.COLUMNS=5]="COLUMNS",e[e.FULL=6]="FULL",e))(de||{});class he{#u;#y=0;#_=0;#S=null;#R=null;#E=null;#x=!1;constructor(e){this.#u=e}requestPhase(e,t){e>this.#y&&(this.#y=e),0===this.#_&&(this.#A(),this.#_=requestAnimationFrame(()=>this.#T()))}whenReady(){return this.#S?this.#S:Promise.resolve()}setInitialReadyResolver(e){this.#E=e}cancel(){0!==this.#_&&(cancelAnimationFrame(this.#_),this.#_=0),this.#y=0,this.#R&&(this.#R(),this.#R=null,this.#S=null)}get isPending(){return 0!==this.#y}get pendingPhase(){return this.#y}#A(){this.#S||(this.#S=new Promise(e=>{this.#R=e}))}#T(){if(this.#_=0,!this.#u.isConnected())return this.#y=0,void(this.#R&&(this.#R(),this.#R=null,this.#S=null));const e=this.#y;this.#y=0,e>=5&&this.#u.mergeConfig(),e>=4&&this.#u.processRows(),e>=5&&(this.#u.processColumns(),this.#u.updateTemplate()),e>=3&&this.#u.renderHeader(),e>=2&&this.#u.renderVirtualWindow(),e>=1&&this.#u.afterRender(),!this.#x&&this.#E&&(this.#x=!0,this.#E()),this.#R&&(this.#R(),this.#R=null,this.#S=null)}}function ue(e){let t=null,i=null,o=null,r=null;const n=o=>{if(!t)return;const r=o.clientX-t.startX,n=Math.max(40,t.startWidth+r),s=e._visibleColumns[t.colIndex];s.width=n,s.__userResized=!0,s.__renderedWidth=n,null==i&&(i=requestAnimationFrame(()=>{i=null,e.updateTemplate?.()})),e.dispatchEvent(new CustomEvent("column-resize",{detail:{field:s.field,width:n}}))};let s=!1;const l=()=>{const i=null!==t;i&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",l),null!==o&&(document.documentElement.style.cursor=o,o=null),null!==r&&(document.body.style.userSelect=r,r=null),t=null,i&&e.requestStateChange&&e.requestStateChange()};return{get isResizing(){return null!==t||s},start(i,s,a){i.preventDefault();const c=e._visibleColumns[s],d="number"==typeof c?.width?c.width:void 0,h=c?.__renderedWidth??d??a.getBoundingClientRect().width;t={startX:i.clientX,colIndex:s,startWidth:h},window.addEventListener("mousemove",n),window.addEventListener("mouseup",l),null===o&&(o=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",null===r&&(r=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(t){const i=e._visibleColumns[t];i&&(i.__userResized=!1,i.__renderedWidth=void 0,i.width=i.__originalWidth,e.updateTemplate?.(),e.requestStateChange?.(),e.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:i.field,width:i.width}})))},dispose(){l()}}}const ge="data-animating",fe={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},pe={change:500,insert:300,remove:200};function we(e,t){const i=fe[t],o=getComputedStyle(e).getPropertyValue(i);if(o){const e=function(e){const t=e.trim().toLowerCase();return t.endsWith("ms")?parseFloat(t):t.endsWith("s")?1e3*parseFloat(t):parseFloat(t)}(o);if(!isNaN(e)&&e>0)return e}return pe[t]}function be(e,t,i){if(t<0)return Promise.resolve(!1);const o=e.findRenderedRowElement?.(t);return o?new Promise(e=>{!function(e,t,i){e.removeAttribute(ge),e.offsetWidth,e.setAttribute(ge,t);const o=we(e,t);setTimeout(()=>{"remove"!==t&&e.removeAttribute(ge),i?.()},o)}(o,i,()=>e(!0))}):Promise.resolve(!1)}function me(e,t,i){const o=document.createElement(e);if(t)for(const r in t){const e=t[r];null!=e&&o.setAttribute(r,e)}return o}function ve(e,t){const i=document.createElement("div");if(e&&(i.className=e),t)for(const o in t){const e=t[o];null!=e&&i.setAttribute(o,e)}return i}function Ce(e,t,i){const o=document.createElement("button");if(e&&(o.className=e),t)for(const r in t){const e=t[r];null!=e&&o.setAttribute(r,e)}return o}const ye=document.createElement("template");function _e(){return ye.content.cloneNode(!0)}function Se(e){const t=document.createDocumentFragment(),i=ve(e.hasShell?"tbw-grid-root has-shell":"tbw-grid-root");if(e.hasShell&&e.shellHeader&&e.shellBody)i.appendChild(e.shellHeader),i.appendChild(e.shellBody);else{const e=ve("tbw-grid-content");e.appendChild(_e()),i.appendChild(e)}return t.appendChild(i),t}function Re(e){return e?"string"==typeof e?e:e.outerHTML:""}function Ee(e){return!!e?.header?.title||(!!e?.header?.toolbarContents?.length||(!!e?.toolPanels?.length||(!!e?.headerContents?.length||(!!e?.header?.lightDomContent?.length||!!e?.header?.hasToolButtonsContainer))))}function xe(e,t){const i=e.querySelector("tbw-grid-header");if(!i)return;if(!t.lightDomTitle){const e=i.getAttribute("title");e&&(t.lightDomTitle=e)}const o=i.querySelectorAll("tbw-grid-header-content");o.length>0&&0===t.lightDomHeaderContent.length&&(t.lightDomHeaderContent=Array.from(o)),i.style.display="none"}function Ae(e,t,i){const o=e.querySelector(":scope > tbw-grid-tool-buttons");if(!o)return;t.hasToolButtonsContainer=!0;const r="light-dom-toolbar-content";if(t.lightDomToolbarContentIds.has(r))return;const n={id:r,order:0,render:e=>{for(;o.firstChild;)e.appendChild(o.firstChild);return()=>{for(;e.firstChild;)o.appendChild(e.firstChild)}}};t.toolbarContents.set(r,n),t.lightDomToolbarContentIds.add(r),o.style.display="none"}function Te(e,t,i){e.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(e=>{const o=e,r=o.getAttribute("id"),n=o.getAttribute("title");if(!r||!n)return void console.warn(`[parseLightDomToolPanels] Tool panel missing required id or title attribute: id="${r??""}", title="${n??""}"`);const s=o.getAttribute("icon")??void 0,l=o.getAttribute("tooltip")??void 0,a=parseInt(o.getAttribute("order")??"100",10);let c;const d=i?.(o);if(d)c=d;else{const e=o.innerHTML.trim();c=t=>{const i=document.createElement("div");return i.innerHTML=e,t.appendChild(i),()=>i.remove()}}const h=t.toolPanels.get(r);if(h){if(d){h.render=c,h.order=a,h.icon=s,h.tooltip=l;const e=t.panelCleanups.get(r);e&&(e(),t.panelCleanups.delete(r))}return}const u={id:r,title:n,icon:s,tooltip:l,order:a,render:c};t.toolPanels.set(r,u),t.lightDomToolPanelIds.add(r),o.style.display="none"})}function He(e,t,i){const o=t?.header?.toolbarContents??[],r=[...i.toolbarContents.values()],n=new Set(o.map(e=>e.id)),s=[...o];for(const l of r)n.has(l.id)||s.push(l);for(const l of s){if(i.toolbarContentCleanups.has(l.id))continue;if(!l.render)continue;const t=e.querySelector(`[data-toolbar-content="${l.id}"]`);if(!t)continue;const o=l.render(t);o&&i.toolbarContentCleanups.set(l.id,o)}}function Pe(e,t){const i=t.lightDomHeaderContent.length>0&&!t.lightDomContentMoved,o=t.headerContents.size>0;if(!i&&!o)return;const r=e.querySelector(".tbw-shell-content");if(!r)return;if(i){for(const e of t.lightDomHeaderContent)e.style.display="",r.appendChild(e);t.lightDomContentMoved=!0}const n=[...t.headerContents.values()].sort((e,t)=>(e.order??100)-(t.order??100));for(const s of n){const e=t.headerContentCleanups.get(s.id);e&&(e(),t.headerContentCleanups.delete(s.id));let i=r.querySelector(`[data-header-content="${s.id}"]`);i||(i=document.createElement("div"),i.setAttribute("data-header-content",s.id),r.appendChild(i));const o=s.render(i);o&&t.headerContentCleanups.set(s.id,o)}}function Me(e,t){const i=e.querySelector("[data-panel-toggle]");i&&(i.classList.toggle("active",t.isPanelOpen),i.setAttribute("aria-pressed",String(t.isPanelOpen)))}function Le(e,t){const i=e.querySelector(".tbw-tool-panel");i&&(i.classList.toggle("open",t.isPanelOpen),t.isPanelOpen||(i.style.width=""))}function ze(e){for(const t of e.toolbarContentCleanups.values())t();e.toolbarContentCleanups.clear()}function Oe(e,t){let i=!1;const o={get isInitialized(){return i},setInitialized(e){i=e},get isPanelOpen(){return e.isPanelOpen},get activePanel(){return e.isPanelOpen&&e.expandedSections.size>0?[...e.expandedSections][0]:null},get expandedSections(){return[...e.expandedSections]},openToolPanel(){if(e.isPanelOpen)return;if(0===e.toolPanels.size)return void console.warn("[tbw-grid] No tool panels registered");if(e.isPanelOpen=!0,0===e.expandedSections.size&&e.toolPanels.size>0){const t=[...e.toolPanels.values()].sort((e,t)=>(e.order??100)-(t.order??100))[0];t&&e.expandedSections.add(t.id)}const i=t.getShadow();Me(i,e),Le(i,e),function(e,t,i){if(!t.isPanelOpen)return;const o=Re(i?.expand??r.expand),n=Re(i?.collapse??r.collapse);for(const[r,s]of t.toolPanels){const i=t.expandedSections.has(r),l=e.querySelector(`[data-section="${r}"]`),a=l?.querySelector(".tbw-accordion-content");if(!l||!a)continue;l.classList.toggle("expanded",i);const c=l.querySelector(".tbw-accordion-header");c&&c.setAttribute("aria-expanded",String(i));const d=l.querySelector(".tbw-accordion-chevron");if(d&&(d.innerHTML=i?n:o),i){if(0===a.children.length){const e=s.render(a);e&&t.panelCleanups.set(r,e)}}else{const e=t.panelCleanups.get(r);e&&(e(),t.panelCleanups.delete(r)),a.innerHTML=""}}}(i,e,t.getAccordionIcons()),t.emit("tool-panel-open",{sections:o.expandedSections})},closeToolPanel(){if(!e.isPanelOpen)return;for(const t of e.panelCleanups.values())t();e.panelCleanups.clear();for(const t of e.toolPanels.values())t.onClose?.();e.isPanelOpen=!1;const i=t.getShadow();Me(i,e),Le(i,e),t.emit("tool-panel-close",{})},toggleToolPanel(){e.isPanelOpen?o.closeToolPanel():o.openToolPanel()},toggleToolPanelSection(i){const o=e.toolPanels.get(i);if(!o)return void console.warn(`[tbw-grid] Tool panel section "${i}" not found`);if(1===e.toolPanels.size)return;const r=t.getShadow(),n=e.expandedSections.has(i);if(n){const t=e.panelCleanups.get(i);t&&(t(),e.panelCleanups.delete(i)),o.onClose?.(),e.expandedSections.delete(i),ke(r,i,!1)}else{for(const[t,o]of e.toolPanels)if(t!==i&&e.expandedSections.has(t)){const i=e.panelCleanups.get(t);i&&(i(),e.panelCleanups.delete(t)),o.onClose?.(),e.expandedSections.delete(t),ke(r,t,!1);const n=r.querySelector(`[data-section="${t}"] .tbw-accordion-content`);n&&(n.innerHTML="")}e.expandedSections.add(i),ke(r,i,!0),function(e,t,i){const o=t.toolPanels.get(i);if(!o?.render)return;const r=e.querySelector(`[data-section="${i}"] .tbw-accordion-content`);if(!r)return;const n=o.render(r);n&&t.panelCleanups.set(i,n)}(r,e,i)}t.emit("tool-panel-section-toggle",{id:i,expanded:!n})},getToolPanels:()=>[...e.toolPanels.values()],registerToolPanel(o){e.toolPanels.has(o.id)?console.warn(`[tbw-grid] Tool panel "${o.id}" already registered`):(e.toolPanels.set(o.id,o),i&&t.refreshShellHeader())},unregisterToolPanel(o){if(e.expandedSections.has(o)){const t=e.panelCleanups.get(o);t&&(t(),e.panelCleanups.delete(o)),e.expandedSections.delete(o)}e.toolPanels.delete(o),i&&t.refreshShellHeader()},getHeaderContents:()=>[...e.headerContents.values()],registerHeaderContent(o){e.headerContents.has(o.id)?console.warn(`[tbw-grid] Header content "${o.id}" already registered`):(e.headerContents.set(o.id,o),i&&Pe(t.getShadow(),e))},unregisterHeaderContent(i){const o=e.headerContentCleanups.get(i);o&&(o(),e.headerContentCleanups.delete(i));const r=e.headerContents.get(i);r?.onDestroy?.(),e.headerContents.delete(i);const n=t.getShadow().querySelector(`[data-header-content="${i}"]`);n?.remove()},getToolbarContents:()=>[...e.toolbarContents.values()].sort((e,t)=>(e.order??0)-(t.order??0)),registerToolbarContent(o){e.toolbarContents.has(o.id)?console.warn(`[tbw-grid] Toolbar content "${o.id}" already registered`):(e.toolbarContents.set(o.id,o),i&&t.refreshShellHeader())},unregisterToolbarContent(o){const r=e.toolbarContentCleanups.get(o);r&&(r(),e.toolbarContentCleanups.delete(o));const n=e.toolbarContents.get(o);n?.onDestroy&&n.onDestroy(),e.toolbarContents.delete(o),i&&t.refreshShellHeader()}};return o}function ke(e,t,i){const o=e.querySelector(`[data-section="${t}"]`);o&&o.classList.toggle("expanded",i)}function De(e,t,i,o){const n=Ee(t),s=[],l=["tbw-grid-header","tbw-grid-tool-buttons","tbw-grid-tool-panel","tbw-grid-column","tbw-grid-detail","tbw-grid-responsive-card"];for(const r of l){e.querySelectorAll(`:scope > ${r}`).forEach(e=>s.push(e))}e.replaceChildren();for(const r of s)e.appendChild(r);if(n){const n=Re(o?.toolPanel??r.toolPanel),s=Re(o?.expand??r.expand),l=Re(o?.collapse??r.collapse),a=[...t?.header?.toolbarContents??[]].sort((e,t)=>(e.order??0)-(t.order??0)),c=[...t?.toolPanels??[]].sort((e,t)=>(e.order??100)-(t.order??100)),d={title:t?.header?.title??void 0,hasPanels:c.length>0,isPanelOpen:i.isPanelOpen,toolPanelIcon:n,configButtons:a.map(e=>({id:e.id,hasElement:!1,hasRender:!!e.render})),apiButtons:[]},h={position:t?.toolPanel?.position??"right",isPanelOpen:i.isPanelOpen,expandIcon:s,collapseIcon:l,panels:c.map(e=>({id:e.id,title:e.title,icon:Re(e.icon),isExpanded:i.expandedSections.has(e.id)}))},u=Se({hasShell:!0,shellHeader:function(e){const t=ve("tbw-shell-header",{part:"shell-header",role:"presentation"});if(e.title){const i=ve("tbw-shell-title");i.textContent=e.title,t.appendChild(i)}const i=ve("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});t.appendChild(i);const o=ve("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const r of e.configButtons)r.hasRender&&o.appendChild(ve("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));for(const r of e.apiButtons)r.hasRender&&o.appendChild(ve("tbw-toolbar-content-slot",{"data-toolbar-content":r.id}));if((e.configButtons.some(e=>e.hasRender)||e.apiButtons.some(e=>e.hasRender))&&e.hasPanels&&o.appendChild(ve("tbw-toolbar-separator")),e.hasPanels){const t=Ce(e.isPanelOpen?"tbw-toolbar-btn active":"tbw-toolbar-btn",{"data-panel-toggle":"",title:"Settings","aria-label":"Toggle settings panel","aria-pressed":String(e.isPanelOpen),"aria-controls":"tbw-tool-panel"});t.innerHTML=e.toolPanelIcon,o.appendChild(t)}return t.appendChild(o),t}(d),shellBody:function(e){const t=ve("tbw-shell-body"),i=e.panels.length>0,o=1===e.panels.length,r=ve("tbw-grid-content");r.appendChild(_e());let n=null;if(i){n=me("aside",{class:e.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":e.position,role:"presentation",id:"tbw-tool-panel"});const t="left"===e.position?"right":"left";n.appendChild(ve("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":t,"aria-hidden":"true"}));const i=ve("tbw-tool-panel-content",{role:"presentation"}),r=ve("tbw-accordion");for(const n of e.panels){const t=ve(`tbw-accordion-section${n.isExpanded?" expanded":""}${o?" single":""}`,{"data-section":n.id}),i=Ce("tbw-accordion-header",{"aria-expanded":String(n.isExpanded),"aria-controls":`tbw-section-${n.id}`});if(o&&i.setAttribute("aria-disabled","true"),n.icon){const e=me("span",{class:"tbw-accordion-icon"});e.innerHTML=n.icon,i.appendChild(e)}const s=me("span",{class:"tbw-accordion-title"});if(s.textContent=n.title,i.appendChild(s),!o){const t=me("span",{class:"tbw-accordion-chevron"});t.innerHTML=n.isExpanded?e.collapseIcon:e.expandIcon,i.appendChild(t)}t.appendChild(i),t.appendChild(ve("tbw-accordion-content",{id:`tbw-section-${n.id}`,role:"presentation"})),r.appendChild(t)}i.appendChild(r),n.appendChild(i)}return"left"===e.position&&n?(t.appendChild(n),t.appendChild(r)):(t.appendChild(r),n&&t.appendChild(n)),t}(h)});e.appendChild(u)}else{const t=Se({hasShell:!1});e.appendChild(t)}return n}ye.innerHTML='\n <div class="tbw-scroll-area">\n <div class="rows-body-wrapper">\n <div class="rows-body" role="grid">\n <div class="header" role="rowgroup">\n <div class="header-row" role="row" part="header-row"></div>\n </div>\n <div class="rows-container" role="presentation">\n <div class="rows-viewport" role="presentation">\n <div class="rows"></div>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class="faux-vscroll">\n <div class="faux-vscroll-spacer"></div>\n </div>\n';const Ie="tbw-grid-styles";let Ne="";const qe=new Map;function $e(){const e=function(){let e=document.getElementById(Ie);return e||(e=document.createElement("style"),e.id=Ie,e.setAttribute("data-tbw-grid","true"),document.head.appendChild(e)),e}(),t=Array.from(qe.values()).join("\n");e.textContent=`${Ne}\n\n/* Plugin Styles */\n${t}`}async function We(e){if(Ne)return;if("string"==typeof e&&e.length>0)return Ne=e,void $e();await new Promise(e=>setTimeout(e,50));const t=function(){try{for(const e of Array.from(document.styleSheets))try{const t=Array.from(e.cssRules||[]).map(e=>e.cssText).join("\n");if(t.includes(".tbw-grid-root")&&t.includes("tbw-grid"))return t}catch{continue}}catch(e){console.warn("[tbw-grid] Failed to extract grid.css from document stylesheets:",e)}return null}();t?(Ne=t,$e()):"undefined"!=typeof process&&"test"===process.env?.NODE_ENV||console.warn("[tbw-grid] Could not find grid.css in document.styleSheets. Grid styling will not work.","Available stylesheets:",Array.from(document.styleSheets).map(e=>e.href||"(inline)"))}function Fe(e){e.momentumRaf&&(cancelAnimationFrame(e.momentumRaf),e.momentumRaf=0)}function Ue(e,t){(Math.abs(e.velocityY)>.1||Math.abs(e.velocityX)>.1)&&function(e,t){const i=.95,o=.01,r=()=>{e.velocityY*=i,e.velocityX*=i;const n=16*e.velocityY,s=16*e.velocityX;Math.abs(e.velocityY)>o&&(t.fauxScrollbar.scrollTop+=n),Math.abs(e.velocityX)>o&&t.scrollArea&&(t.scrollArea.scrollLeft+=s),Math.abs(e.velocityY)>o||Math.abs(e.velocityX)>o?e.momentumRaf=requestAnimationFrame(r):e.momentumRaf=0};e.momentumRaf=requestAnimationFrame(r)}(e,t),function(e){e.startY=null,e.startX=null,e.scrollTop=null,e.scrollLeft=null,e.lastY=null,e.lastX=null,e.lastTime=null}(e)}function Ve(e,t,i,o){e.addEventListener("touchstart",e=>function(e,t,i){if(1!==e.touches.length)return;Fe(t);const o=e.touches[0];t.startY=o.clientY,t.startX=o.clientX,t.lastY=o.clientY,t.lastX=o.clientX,t.lastTime=performance.now(),t.scrollTop=i.fauxScrollbar.scrollTop,t.scrollLeft=i.scrollArea?.scrollLeft??0,t.velocityY=0,t.velocityX=0}(e,t,i),{passive:!0,signal:o}),e.addEventListener("touchmove",e=>{const o=function(e,t,i){if(1!==e.touches.length||null===t.startY||null===t.startX||null===t.scrollTop||null===t.scrollLeft)return!1;const o=e.touches[0],r=o.clientY,n=o.clientX,s=performance.now(),l=t.startY-r,a=t.startX-n;if(null!==t.lastTime&&null!==t.lastY&&null!==t.lastX){const e=s-t.lastTime;e>0&&(t.velocityY=(t.lastY-r)/e,t.velocityX=(t.lastX-n)/e)}t.lastY=r,t.lastX=n,t.lastTime=s;const{scrollTop:c,scrollHeight:d,clientHeight:h}=i.fauxScrollbar,u=l>0&&c<d-h||l<0&&c>0;let g=!1;if(i.scrollArea){const{scrollLeft:e,scrollWidth:t,clientWidth:o}=i.scrollArea;g=a>0&&e<t-o||a<0&&e>0}return u&&(i.fauxScrollbar.scrollTop=t.scrollTop+l),g&&i.scrollArea&&(i.scrollArea.scrollLeft=t.scrollLeft+a),u||g}(e,t,i);o&&e.preventDefault()},{passive:!1,signal:o}),e.addEventListener("touchend",()=>Ue(t,i),{passive:!0,signal:o})}const Ge=[{property:"editable",pluginName:"editing",level:"column",description:'the "editable" column property',isUsed:e=>!0===e},{property:"editor",pluginName:"editing",level:"column",description:'the "editor" column property'},{property:"editorParams",pluginName:"editing",level:"column",description:'the "editorParams" column property'},{property:"group",pluginName:"groupingColumns",level:"column",description:'the "group" column property'},{property:"pinned",pluginName:"pinnedColumns",level:"column",description:'the "pinned" column property',isUsed:e=>"left"===e||"right"===e||"start"===e||"end"===e},{property:"sticky",pluginName:"pinnedColumns",level:"column",description:'the "sticky" column property (deprecated, use "pinned")',isUsed:e=>"left"===e||"right"===e||"start"===e||"end"===e}],Be=[{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}];function Xe(e){return`import { ${Ye(e)}Plugin } from '@toolbox-web/grid/plugins/${t=e,t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}';`;var t}function Ye(e){return e.charAt(0).toUpperCase()+e.slice(1)}function je(e,t){return e.some(e=>e.name===t)}function Ke(e,t){return e&&"object"==typeof e?"__rowCacheKey"in e?e.__rowCacheKey:"rowId"in e&&null!=e.rowId?`id:${e.rowId}`:t?`id:${t(e)}`:e:e}function Ze(e,t,i){const o=Ke(t,i);return"string"==typeof o?e.byKey.get(o):o&&"object"==typeof o?e.byRef.get(o):void 0}function Qe(e,t,i){if(t<0||t>=e.length)return;const o=e[t],r=i-o.height;if(0!==r){o.height=i,o.measured=!0;for(let i=t+1;i<e.length;i++)e[i].offset+=r}}function Je(e,t){if(0===e.length)return-1;if(t<=0)return 0;let i=0,o=e.length-1;for(;i<=o;){const r=Math.floor((i+o)/2),n=e[r],s=n.offset+n.height;if(t<n.offset)o=r-1;else{if(!(t>=s))return r;i=r+1}}return Math.max(0,Math.min(i,e.length-1))}function et(e,t){const{positionCache:i,heightCache:o,rows:r,start:n,end:s,getPluginHeight:l,getRowId:a}=e;let c=!1;t.forEach(e=>{const t=e.dataset.rowIndex;if(!t)return;const d=parseInt(t,10);if(d<n||d>=s||d>=r.length)return;const h=r[d],u=l?.(h,d);if(void 0!==u){const e=i[d];return void((!e.measured||Math.abs(e.height-u)>1)&&(Qe(i,d,u),c=!0))}const g=e.offsetHeight;if(g>0){const e=i[d];(!e.measured||Math.abs(e.height-g)>1)&&(Qe(i,d,g),function(e,t,i,o){const r=Ke(t,o);"string"==typeof r?e.byKey.set(r,i):r&&"object"==typeof r&&e.byRef.set(r,i)}(o,h,g,a),c=!0)}});const d=c?function(e){let t=0;for(const i of e)i.measured&&t++;return t}(i):0,h=c?function(e,t){let i=0,o=0;for(const r of e)r.measured&&(i+=r.height,o++);return o>0?i/o:t}(i,e.defaultHeight):0;return{hasChanges:c,measuredCount:d,averageHeight:h}}class tt{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 t of e)this.attach(t)}attach(e){if(function(e,t){const i=e.name,o=e.constructor.dependencies??[];for(const r of o){const e=r.name,o=r.required??!0,n=r.reason;if(!t.some(t=>t.name===e)){const t=n??`${Ye(i)}Plugin requires ${Ye(e)}Plugin`,r=Xe(e);if(o)throw new Error(`[tbw-grid] Plugin dependency error:\n\n${t}.\n\n → Add the plugin to your gridConfig.plugins array BEFORE ${Ye(i)}Plugin:\n ${r}\n plugins: [new ${Ye(e)}Plugin(), new ${Ye(i)}Plugin()]`);console.info(`[tbw-grid] ${Ye(i)}Plugin: Optional "${e}" plugin not found. Some features may be unavailable.`)}}}(e,this.plugins),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,i]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,i);if(e.headerRenderers)for(const[t,i]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,i);if(e.cellEditors)for(const[t,i]of Object.entries(e.cellEditors))this.cellEditors.set(t,i);this.registerQueryHandlers(e),this.warnDeprecatedHooks(e),e.attach(this.grid);for(const t of this.plugins)t!==e&&t.onPluginAttached&&t.onPluginAttached(e.name,e)}registerQueryHandlers(e){const t=e.constructor.manifest;if(t?.queries)for(const i of t.queries){let t=this.queryHandlers.get(i.type);t||(t=new Set,this.queryHandlers.set(i.type,t)),t.add(e)}}warnDeprecatedHooks(e){const t=e.constructor;if(tt.deprecationWarned.has(t))return;if(!x())return;const i="function"==typeof e.getExtraHeight||"function"==typeof e.getExtraHeightBefore,o="function"==typeof e.getRowHeight;i&&!o&&(tt.deprecationWarned.add(t),console.warn(`[tbw-grid] Deprecation warning: "${e.name}" uses getExtraHeight() / getExtraHeightBefore() which are deprecated and will be removed in v3.0.\n → Migrate to getRowHeight(row, index) for better variable row height support.\n → See: https://toolbox-web.dev/docs/grid/plugins/migration#row-height-hooks`))}unregisterQueryHandlers(e){for(const[t,i]of this.queryHandlers)i.delete(e),0===i.size&&this.queryHandlers.delete(t)}detachAll(){for(const e of this.plugins)for(const t of this.plugins)t!==e&&t.onPluginDetached&&t.onPluginDetached(e.name);for(let e=this.plugins.length-1;e>=0;e--){const t=this.plugins[e];this.unsubscribeAll(t),this.unregisterQueryHandlers(t),t.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(t=>t.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 t=[...e];for(const i of this.plugins)i.processRows&&(t=i.processRows(t));return t}processColumns(e){let t=[...e];for(const i of this.plugins)i.processColumns&&(t=i.processColumns(t));return t}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterRender(){for(const e of this.plugins)e.afterRender?.()}afterCellRender(e){for(const t of this.plugins)t.afterCellRender?.(e)}hasAfterCellRenderHook(){return this.plugins.some(e=>"function"==typeof e.afterCellRender)}afterRowRender(e){for(const t of this.plugins)t.afterRowRender?.(e)}hasAfterRowRenderHook(){return this.plugins.some(e=>"function"==typeof e.afterRowRender)}onScrollRender(){for(const e of this.plugins)e.onScrollRender?.()}getExtraHeight(){let e=0;for(const t of this.plugins)"function"==typeof t.getExtraHeight&&(e+=t.getExtraHeight());return e}hasExtraHeight(){for(const e of this.plugins)if("function"==typeof e.getExtraHeight&&e.getExtraHeight()>0)return!0;return!1}getExtraHeightBefore(e){let t=0;for(const i of this.plugins)"function"==typeof i.getExtraHeightBefore&&(t+=i.getExtraHeightBefore(e));return t}getRowHeight(e,t){for(const i of this.plugins)if("function"==typeof i.getRowHeight){const o=i.getRowHeight(e,t);if(void 0!==o)return o}}hasRowHeightPlugin(){for(const e of this.plugins)if("function"==typeof e.getRowHeight)return!0;return!1}adjustVirtualStart(e,t,i){let o=e;for(const r of this.plugins)if("function"==typeof r.adjustVirtualStart){const n=r.adjustVirtualStart(e,t,i);n<o&&(o=n)}return o}renderRow(e,t,i){for(const o of this.plugins)if(o.renderRow?.(e,t,i))return!0;return!1}queryPlugins(e){const t=[],i=this.queryHandlers.get(e.type);if(i&&i.size>0){for(const o of i){const i=o.handleQuery?.(e)??o.onPluginQuery?.(e);void 0!==i&&t.push(i)}return t}for(const o of this.plugins){const i=o.handleQuery?.(e)??o.onPluginQuery?.(e);void 0!==i&&t.push(i)}return t}subscribe(e,t,i){let o=this.eventListeners.get(t);o||(o=new Map,this.eventListeners.set(t,o)),o.set(e,i)}unsubscribe(e,t){const i=this.eventListeners.get(t);i&&(i.delete(e),0===i.size&&this.eventListeners.delete(t))}unsubscribeAll(e){for(const[t,i]of this.eventListeners)i.delete(e),0===i.size&&this.eventListeners.delete(t)}emitPluginEvent(e,t){const i=this.eventListeners.get(e);if(i)for(const r of i.values())try{r(t)}catch(o){console.error(`[tbw-grid] Error in plugin event handler for "${e}":`,o)}}onKeyDown(e){for(const t of this.plugins)if(t.onKeyDown?.(e))return!0;return!1}onCellClick(e){for(const t of this.plugins)if(t.onCellClick?.(e))return!0;return!1}onRowClick(e){for(const t of this.plugins)if(t.onRowClick?.(e))return!0;return!1}onHeaderClick(e){for(const t of this.plugins)if(t.onHeaderClick?.(e))return!0;return!1}onScroll(e){for(const t of this.plugins)t.onScroll?.(e)}onCellMouseDown(e){for(const t of this.plugins)if(t.onCellMouseDown?.(e))return!0;return!1}onCellMouseMove(e){for(const t of this.plugins)if(t.onCellMouseMove?.(e))return!0;return!1}onCellMouseUp(e){for(const t of this.plugins)if(t.onCellMouseUp?.(e))return!0;return!1}getHorizontalScrollOffsets(e,t){let i=0,o=0,r=!1;for(const n of this.plugins){const s=n.getHorizontalScrollOffsets?.(e,t);s&&(i+=s.left,o+=s.right,s.skipScroll&&(r=!0))}return{left:i,right:o,skipScroll:r}}getToolPanels(){const e=[];for(const t of this.plugins){const i=t.getToolPanel?.();i&&e.push({plugin:t,panel:i})}return e.sort((e,t)=>(e.panel.order??0)-(t.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const i=t.getHeaderContent?.();i&&e.push({plugin:t,content:i})}return e.sort((e,t)=>(e.content.order??0)-(t.content.order??0))}}class it extends HTMLElement{static tagName="tbw-grid";static version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";static#H=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#P(){return this}#M=!1;#S;#R;#L=[];get#s(){return this.#z?.effective??{}}#O=!1;#k=!1;#D={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#I;#N=0;#q=null;#$=!1;#W=!1;#F=0;#U;#V={startY:null,startX:null,scrollTop:null,scrollLeft:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0};#G;#B;#X;#Y;#j={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#K;#Z;#Q=!1;#J;#ee;#h;#z;#te=function(){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}}();#ie;#oe;#re;#ne=!1;#se=new Set;#le=new Map;#ae;#ce=new Map;_rows=[];#de=[];get _columns(){return this.#s.columns??[]}set _columns(e){this.#s.columns=e}get _visibleColumns(){return this._columns.filter(e=>!e.hidden)}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;_virtualization={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null,positionCache:null,heightCache:{byKey:new Map,byRef:new WeakMap},averageHeight:28,measuredCount:0,variableHeights:!1,cachedViewportHeight:0,cachedFauxHeight:0,cachedScrollAreaHeight:0,scrollAreaEl:null};_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#z?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#z&&(this.#z.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#z?.originalColumnNodes}set __originalColumnNodes(e){this.#z&&(this.#z.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const t=this.#L;this.#L=e,t!==e&&this.#he("rows")}get sourceRows(){return this.#L}get columns(){return[...this._columns]}set columns(e){const t=this.#z?.getColumns();this.#z?.setColumns(e),t!==e&&this.#he("columns")}get gridConfig(){return this.#s}set gridConfig(e){const t=this.#z?.getGridConfig();this.#z?.setGridConfig(e),t!==e&&(this.#z.clearLightDomCache(),this.#he("gridConfig"))}get fitMode(){return this.#s.fitMode??"stretch"}set fitMode(e){const t=this.#z?.getFitMode();this.#z?.setFitMode(e),t!==e&&this.#he("fitMode")}get loading(){return this.#ne}set loading(e){const t=this.#ne;this.#ne=e,e?this.setAttribute("loading",""):this.removeAttribute("loading"),t!==e&&this.#ue()}setRowLoading(e,t){const i=this.#se.has(e);t?this.#se.add(e):this.#se.delete(e),i!==t&&this.#ge(e,t)}setCellLoading(e,t,i){let o=this.#le.get(e);const r=o?.has(t)??!1;i?(o||(o=new Set,this.#le.set(e,o)),o.add(t)):(o?.delete(t),0===o?.size&&this.#le.delete(e)),r!==i&&this.#fe(e,t,i)}isRowLoading(e){return this.#se.has(e)}isCellLoading(e,t){return this.#le.get(e)?.has(t)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#se)this.#ge(e,!1);this.#se.clear();for(const[e,t]of this.#le)for(const i of t)this.#fe(e,i,!1);this.#le.clear()}get effectiveConfig(){return this.#s}get disconnectSignal(){return this.#G||(this.#G=new AbortController),this.#G.signal}constructor(){super(),this.#pe(),this.#S=new Promise(e=>this.#R=e),this.#I=new he({mergeConfig:()=>{this.#z.parseLightDomColumns(this),this.#z.merge(),this.#we(),function(e,t){const i=Ge,o=Be,r=new Map;function n(e,t,i,o,n=!1){r.has(e)||r.set(e,{description:t,importHint:i,fields:[],isConfigProperty:n});const s=r.get(e);s.fields.includes(o)||s.fields.push(o)}for(const l of o){const i=e[l.property];(l.isUsed?l.isUsed(i):void 0!==i)&&!je(t,l.pluginName)&&n(l.pluginName,l.description,Xe(l.pluginName),l.property,!0)}const s=e.columns;if(s&&s.length>0)for(const l of s)for(const e of i){const i=l[e.property];if((e.isUsed?e.isUsed(i):void 0!==i)&&!je(t,e.pluginName)){const t=l.field||"<unknown>";n(e.pluginName,e.description,Xe(e.pluginName),t)}}if(r.size>0){const e=[];for(const[t,{description:i,importHint:o,fields:n,isConfigProperty:s}]of r)if(s)e.push(`Config uses ${i}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${o}\n plugins: [new ${Ye(t)}Plugin(), ...]`);else{const r=n.slice(0,3).join(", ")+(n.length>3?`, ... (${n.length} total)`:"");e.push(`Column(s) [${r}] use ${i}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${o}\n plugins: [new ${Ye(t)}Plugin(), ...]`)}throw new Error(`[tbw-grid] Configuration error:\n\n${e.join("\n\n")}\n\nThis validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`)}}(this.#s,this.#K?.getPlugins()??[]),function(e){const t=[],i=[];for(const o of e){const e=o.constructor.manifest;if(e?.configRules)for(const r of e.configRules){const e=o.config;if(r.check(e)){const e=`[tbw-grid:${Ye(o.name)}Plugin] Configuration warning: ${r.message}`;"error"===r.severity?t.push(e):i.push(e)}}}if(i.length>0&&x())for(const o of i)console.warn(o);if(t.length>0)throw new Error(`[tbw-grid] Configuration error:\n\n${t.join("\n\n")}`)}(this.#K?.getPlugins()??[]),function(e){if(!x())return;const t=new Set(e.map(e=>e.name)),i=new Set;for(const o of e){const e=o.constructor.manifest;if(e?.incompatibleWith)for(const r of e.incompatibleWith)if(t.has(r.name)){const e=[o.name,r.name].sort().join("↔");if(i.has(e))continue;i.add(e),console.warn(`[tbw-grid] Plugin incompatibility warning:\n\n${Ye(o.name)}Plugin and ${Ye(r.name)}Plugin are both loaded, but they are currently incompatible.\n\n → ${r.reason}\n\n Consider removing one of these plugins to avoid unexpected behavior.`)}}}(this.#K?.getPlugins()??[]),this.#be(),this.#de=[...this._columns]},processColumns:()=>this.#me(),processRows:()=>this.#ve(),renderHeader:()=>se(this),updateTemplate:()=>d(this),renderVirtualWindow:()=>this.refreshVirtualWindow(!0,!0),afterRender:()=>{this.#K?.afterRender(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const e=this.#Ce(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`});"fixed"!==this.#s.fitMode||this.__didInitialAutoSize||(this.__didInitialAutoSize=!0,l(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,G(this)),this._virtualization.enabled&&!this.#ye&&this.#_e(),this.#W&&(this.#W=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#Se()})})),this.#ne&&this.#ue()},isConnected:()=>this.isConnected&&this.#O}),this.#I.setInitialReadyResolver(()=>this.#R?.()),this.#ie=Oe(this.#te,{getShadow:()=>this.#P,getShellConfig:()=>this.#s?.shell,getAccordionIcons:()=>({expand:this.#s?.icons?.expand??r.expand,collapse:this.#s?.icons?.collapse??r.collapse}),emit:(e,t)=>this.#Re(e,t),refreshShellHeader:()=>this.refreshShellHeader()}),this.#z=new E({getRows:()=>this.#L,getSortState:()=>this._sortState,setSortState:e=>{this._sortState=e},onConfigChange:()=>{this.#I.requestPhase(de.FULL,"configChange")},emit:(e,t)=>this.#Re(e,t),clearRowPool:()=>{this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML=""),this.__rowRenderEpoch++},setup:()=>this.#Ee(),renderHeader:()=>se(this),updateTemplate:()=>d(this),refreshVirtualWindow:()=>this.#I.requestPhase(de.VIRTUALIZATION,"configManager"),getVirtualization:()=>this._virtualization,setRowHeight:e=>{this._virtualization.rowHeight=e},applyAnimationConfig:e=>this.#xe(e),getShellLightDomTitle:()=>this.#te.lightDomTitle,getShellToolPanels:()=>this.#te.toolPanels,getShellHeaderContents:()=>this.#te.headerContents,getShellToolbarContents:()=>this.#te.toolbarContents,getShellLightDomHeaderContent:()=>this.#te.lightDomHeaderContent,getShellHasToolButtonsContainer:()=>this.#te.hasToolButtonsContainer})}async#pe(){await We('@layer tbw-base, tbw-plugins, tbw-theme;\n\n@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-v: var(--tbw-spacing-xs);--tbw-cell-padding-h: var(--tbw-spacing-md);--tbw-cell-padding: var(--tbw-cell-padding-v) var(--tbw-cell-padding-h);--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-width: 1px;--tbw-border-style: solid;--tbw-border-input: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-strong);--tbw-border-header: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-header);--tbw-row-divider: var(--tbw-border-width) var(--tbw-border-style) 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-width: 2px;--tbw-focus-outline: var(--tbw-focus-outline-width) var(--tbw-border-style) 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)}}\n@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)}}\n@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}}\n@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}}\n@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}}\n@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}}\n@layer tbw-base{.tbw-loading-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:1000;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-spinner{--tbw-spinner-size: 48px;--tbw-spinner-border-width: 3px;--tbw-spinner-color: var(--tbw-color-accent);--tbw-spinner-track-color: var(--tbw-color-border);width:var(--tbw-spinner-size);height:var(--tbw-spinner-size);border:var(--tbw-spinner-border-width) solid var(--tbw-spinner-track-color);border-top-color:var(--tbw-spinner-color);border-radius:50%;animation:tbw-spin .8s linear infinite}.tbw-spinner--large{--tbw-spinner-size: min(48px, calc(100% - 16px) )}.tbw-spinner--small{--tbw-spinner-size: calc(var(--tbw-row-height, 28px) * .6);--tbw-spinner-border-width: 2px}.data-grid-row.tbw-row-loading{position:relative;pointer-events:none}.tbw-row-loading-overlay{position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out;pointer-events:none;display:flex;align-items:center}.tbw-row-loading-spinner{--_spinner-size: calc(var(--tbw-row-height, 28px) * .6);margin-left:var(--tbw-spacing-md);width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite}.cell.tbw-cell-loading{position:relative;pointer-events:none}.cell.tbw-cell-loading:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out}.cell.tbw-cell-loading:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .5);content:"";position:absolute;left:var(--tbw-spacing-sm);top:0;bottom:0;margin:auto 0;width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite;z-index:27}}\n@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}}\n@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}}}\n')}getPlugin(e){return this.#K?.getPlugin(e)}getPluginByName(e){return this.#K?.getPluginByName(e)}requestRender(){this.#I.requestPhase(de.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#I.requestPhase(de.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#I.requestPhase(de.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){d(this)}requestAfterRender(){this.#I.requestPhase(de.STYLE,"plugin:requestAfterRender")}#Ae(){this.#K=new tt(this);const e=this.#s?.plugins,t=Array.isArray(e)?e:[];this.#K.attachAll(t)}#Te(){!function(e){let t=!1;for(const{name:i,styles:o}of e)qe.has(i)||(qe.set(i,o),t=!0);t&&$e()}(this.#K?.getPluginStyles()??[])}#we(){const e=this.#s?.plugins,t=Array.isArray(e)?e:[];if(this.#Z===t)return;if(this.#Z&&this.#Z.length===t.length&&this.#Z.every((e,i)=>e===t[i]))return void(this.#Z=t);this.#K&&this.#K.detachAll();for(const o of this.#te.toolPanels.keys()){const e=this.#te.lightDomToolPanelIds.has(o),t=this.#te.apiToolPanelIds.has(o);if(!e&&!t){const e=this.#te.panelCleanups.get(o);e&&(e(),this.#te.panelCleanups.delete(o)),this.#te.toolPanels.delete(o)}}for(const o of this.#te.headerContents.keys()){const e=this.#te.headerContentCleanups.get(o);e&&(e(),this.#te.headerContentCleanups.delete(o)),this.#te.headerContents.delete(o)}this.#Ae(),this.#Te(),this.#Z=t,this.#He(),this.#Pe();const i=this.#$;if(this.#$=this.#K?.getAll().some(e=>e.onScroll)??!1,!i&&this.#$){const e=this.#P.querySelector(".tbw-grid-content")??this.#P.querySelector(".tbw-grid-root");this.#Me(e)}}#Le(){this.#K?.detachAll()}#Pe(){if(!this.#K)return;const e=this.#K.getToolPanels();for(const{panel:i}of e)this.#te.toolPanels.has(i.id)||this.#te.toolPanels.set(i.id,i);const t=this.#K.getHeaderContents();for(const{content:i}of t)this.#te.headerContents.has(i.id)||this.#te.headerContents.set(i.id,i)}#ze(){const e=it.getAdapters();if(0===e.length&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return i=>{if(t?.createToolPanelRenderer){const e=t.createToolPanelRenderer(i);if(e)return e}for(const t of e)if(t.createToolPanelRenderer){const e=t.createToolPanelRenderer(i);if(e)return e}}}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",it.version),this.id||(this.id="tbw-grid-"+ ++it.#H),this._rows=Array.isArray(this.#L)?[...this.#L]:[],this.#G&&(this.#G.abort(),this.#Q=!1),this.#G=new AbortController,this.#Y&&(ae(this.#Y),this.#Y=void 0),this.#Oe(),this.#z.parseLightDomColumns(this),this.#z.merge(),this.#Ae();const e=this.#s?.plugins;var t,i;this.#Z=Array.isArray(e)?e:[],this.#Pe(),this.#M||(this.#ke(),this.#Te(),this.#M=!0),this.#De(),this.#Y=(t=()=>{this.#Ie()},i={timeout:100},le?requestIdleCallback(t,i):window.setTimeout(()=>{const e=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-e))})},1))}disconnectedCallback(){this.#Y&&(ae(this.#Y),this.#Y=void 0),this.#F&&(clearTimeout(this.#F),this.#F=0),this.#Le(),function(e){for(const t of e.headerContentCleanups.values())t();e.headerContentCleanups.clear();for(const t of e.panelCleanups.values())t();e.panelCleanups.clear();for(const t of e.toolbarContentCleanups.values())t();e.toolbarContentCleanups.clear();for(const t of e.toolbarContents.values())t.onDestroy?.();if(e.isPanelOpen)for(const t of e.expandedSections){const i=e.toolPanels.get(t);i?.onClose?.()}e.isPanelOpen=!1,e.expandedSections.clear(),e.toolPanels.clear(),e.headerContents.clear(),e.toolbarContents.clear(),e.lightDomHeaderContent=[],e.lightDomToolPanelIds.clear(),e.lightDomToolbarContentIds.clear(),e.lightDomContentMoved=!1}(this.#te),this.#ie.setInitialized(!1),this.#oe?.(),this.#oe=void 0,this.#re?.(),this.#re=void 0,Fe(this.#V),this.#G&&(this.#G.abort(),this.#G=void 0),this.#J?.abort(),this.#J=void 0,this.#Q=!1,this._resizeController&&this._resizeController.dispose(),this.#B&&(this.#B.disconnect(),this.#B=void 0),this.#X&&(this.#X.disconnect(),this.#X=void 0,this.#ye=!1),W(this),this.#Ne.clear(),this.#Z=void 0;for(const e of this._rowPool)e.remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#O=!1}attributeChangedCallback(e,t,i){if("loading"===e){const e=null!==i&&"false"!==i;return void(this.loading!==e&&(this.loading=e))}if(t!==i&&i&&"null"!==i&&"undefined"!==i)if("rows"===e||"columns"===e||"grid-config"===e)try{const t=JSON.parse(i);"rows"===e?this.rows=t:"columns"===e?this.columns=t:"grid-config"===e&&(this.gridConfig=t)}catch{console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`,i)}else"fit-mode"===e&&(this.fitMode=i)}#De(){const e=this.#P.querySelector(".tbw-grid-content")??this.#P.querySelector(".tbw-grid-root");if(this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this.#ie.isInitialized){Pe(this.#P,this.#te),He(this.#P,this.#s?.shell,this.#te);const e=this.#s?.shell?.toolPanel?.defaultOpen;e&&this.#te.toolPanels.has(e)&&(this.openToolPanel(),this.#te.expandedSections.add(e))}if(this.setAttribute("data-upgraded",""),this.#O=!0,this._resizeController=ue(this),this.#Ee(),this.#Me(e),this.#Q)return;this.#Q=!0;const t=this.disconnectSignal;j(this,this,this.#P,t),this.#He(),queueMicrotask(()=>this.#qe()),this.#I.requestPhase(de.FULL,"afterConnect")}#He(){const e=this.#s.rowHeight,t=this.#K.hasRowHeightPlugin();"function"==typeof e||t?this._virtualization.variableHeights||(this._virtualization.variableHeights=!0,this._virtualization.rowHeight="number"==typeof e&&e>0?e:this._virtualization.rowHeight||28,this.#$e(),"function"!=typeof e&&(this.#W=!0)):!t&&"function"!=typeof e&&this._virtualization.variableHeights?(this._virtualization.variableHeights=!1,this._virtualization.positionCache=null):"number"==typeof e&&e>0?(this._virtualization.rowHeight=e,this._virtualization.variableHeights=!1):requestAnimationFrame(()=>this.#We())}#We(){if(this.#K.hasExtraHeight())return;const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let i=0;t.forEach(e=>{const t=e.offsetHeight;t>i&&(i=t)});const o=e.getBoundingClientRect(),r=Math.max(o.height,i);r>0&&Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r,this.#I.requestPhase(de.VIRTUALIZATION,"measureRowHeight"))}#Se(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let i=0;t.forEach(e=>{const t=e.offsetHeight;t>i&&(i=t)});const o=e.getBoundingClientRect(),r=Math.max(o.height,i);if(r>0){if(Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r),this.#$e(),this._virtualization.totalHeightEl){const e=this.#Ce(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`}}}#Me(e){this.#J?.abort(),this.#J=new AbortController;const t=this.#J.signal,i=e?.querySelector(".faux-vscroll"),o=e?.querySelector(".rows");if(this._virtualization.container=i??this,this.#$=this.#K?.getAll().some(e=>e.onScroll)??!1,i&&o){i.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#$)return;const e=i.scrollTop,t=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)o.style.transform=`translateY(${-e}px)`;else{const i=this._virtualization.positionCache;let r,n;if(this._virtualization.variableHeights&&i&&i.length>0){r=Je(i,e),-1===r&&(r=0);const o=r-r%2;n=i[o]?.offset??o*t}else{r=Math.floor(e/t);n=(r-r%2)*t}const s=-(e-n);o.style.transform=`translateY(${s}px)`}this.#q=e,this.#N||(this.#N=requestAnimationFrame(()=>{this.#N=0,null!==this.#q&&(this.#Fe(this.#q),this.#q=null)}))},{passive:!0,signal:t});const e=this.#P.querySelector(".tbw-scroll-area");this.#ee=e,this._virtualization.scrollAreaEl=e,e&&this.#$&&e.addEventListener("scroll",()=>{const t=this.#j;t.scrollTop=i.scrollTop,t.scrollLeft=e.scrollLeft,t.scrollHeight=i.scrollHeight,t.scrollWidth=e.scrollWidth,t.clientHeight=i.clientHeight,t.clientWidth=e.clientWidth,this.#K?.onScroll(t)},{passive:!0,signal:t});const r=this.#P.querySelector(".tbw-grid-content"),n=this.#ee;r&&(r.addEventListener("wheel",e=>{const t=e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY);if(t&&n){const t=e.shiftKey?e.deltaY:e.deltaX,{scrollLeft:i,scrollWidth:o,clientWidth:r}=n;(t>0&&i<o-r||t<0&&i>0)&&(e.preventDefault(),n.scrollLeft+=t)}else if(!t){const{scrollTop:t,scrollHeight:o,clientHeight:r}=i;(e.deltaY>0&&t<o-r||e.deltaY<0&&t>0)&&(e.preventDefault(),i.scrollTop+=e.deltaY)}},{passive:!1,signal:t}),Ve(r,this.#V,{fauxScrollbar:i,scrollArea:n},t))}var r,n,s;this._bodyEl&&(r=this,n=this._bodyEl,s=t,n.addEventListener("mousedown",e=>{const t=e.target.closest(".cell[data-col]");t&&(t.classList.contains("editing")||(e.preventDefault(),X(r,t)))},{signal:s}),n.addEventListener("click",e=>{const t=e.target.closest(".data-grid-row");if(t&&V(r,e,t),!document.activeElement?.closest(".cell.editing")){const t=e.target.closest("tbw-grid");t&&t.focus({preventScroll:!0})}},{signal:s}),n.addEventListener("dblclick",e=>{const t=e.target.closest(".data-grid-row");t&&V(r,e,t)},{signal:s})),this.#B?.disconnect(),this._virtualization.viewportEl&&(this.#B=new ResizeObserver(()=>{this.#Ue(),this.#I.requestPhase(de.VIRTUALIZATION,"resize-observer")}),this.#B.observe(this._virtualization.viewportEl)),this.#P.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:t}),this.#P.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&(this.#P.contains(t)||this.#Ve(t))||delete this.dataset.hasFocus},{signal:t})}#ye=!1;#_e(){if(this.#ye)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#ye=!0,this.#X?.disconnect(),this.#X=new ResizeObserver(()=>{this.#We()}),this.#X.observe(e))}addEventListener(e,t,i){super.addEventListener(e,t,i)}removeEventListener(e,t,i){super.removeEventListener(e,t,i)}#Re(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#qe(){const e=this._bodyEl?.querySelectorAll(".data-grid-row");e?.forEach((e,t)=>{const i=t===this._focusRow;e.setAttribute("aria-selected",String(i)),e.querySelectorAll(".cell").forEach((e,t)=>{e.setAttribute("aria-selected",String(i&&t===this._focusCol))})})}#he(e){this.#D[e]=!0,this.#k||(this.#k=!0,queueMicrotask(()=>this.#Ge()))}#Ge(){if(!this.#k||!this.#O)return void(this.#k=!1);const e=this.#D;if(this.#k=!1,this.#D={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig)return this.#Be(),void(e.rows&&this.#Xe());e.columns&&this.#Ye(),e.rows&&this.#Xe(),e.fitMode&&this.#je()}#Xe(){this._rows=Array.isArray(this.#L)?[...this.#L]:[],this.#Ke(),this.#I.requestPhase(de.ROWS,"applyRowsUpdate")}#Ke(){this.#ce.clear();const e=this.#s.getRowId;this._rows.forEach((t,i)=>{const o=this.#Ze(t,e);void 0!==o&&this.#ce.set(o,{row:t,index:i})})}#Ze(e,t){if(t)return t(e);const i=e;return"id"in i&&null!=i.id?String(i.id):"_id"in i&&null!=i._id?String(i._id):void 0}#Qe(e,t){const i=this.#Ze(e,t);if(void 0===i)throw new Error('[tbw-grid] Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.');return i}#Ye(){W(this),this.#z.merge(),this.#Ee()}#je(){this.#z.merge();"fixed"===this.#s.fitMode?(this.__didInitialAutoSize=!1,l(this)):(this._columns.forEach(e=>{!e.__userResized&&e.__autoSized&&delete e.width}),d(this))}#Be(){xe(this,this.#te),Ae(this,this.#te);const e=!!this.#P.querySelector(".has-shell"),t=!!this.#P.querySelector(".tbw-tool-panel"),i=this.#P.querySelectorAll(".tbw-accordion-section").length;this.#z.parseLightDomColumns(this),this.#z.merge(),this.#we(),Te(this,this.#te,this.#ze()),this.#z.markSourcesChanged(),this.#z.merge();const o=Ee(this.#s?.shell),r=(this.#s?.shell?.toolPanels?.length??0)>0,n=this.#s?.shell?.toolPanels?.length??0;if(e!==o||!t&&r||t&&n!==i)return ze(this.#te),this.#ke(),this.#Te(),this.#De(),void this.#Ke();e&&this.#Je(),this.#Ke(),this.#I.requestPhase(de.COLUMNS,"applyGridConfigUpdate")}#Je(){const e=this.#P.querySelector(".tbw-shell-header");if(!e)return;const t=this.#s.shell?.header?.title??this.#te.lightDomTitle;let i=e.querySelector(".tbw-shell-title");t?(i||(i=document.createElement("h2"),i.className="tbw-shell-title",i.setAttribute("part","shell-title"),e.insertBefore(i,e.firstChild)),i.textContent=t):i&&i.remove()}#me(){if(this.__rowRenderEpoch++,this.#K){const e=this.#de.length>0?this.#de:this._columns,t=e.filter(e=>!e.hidden),i=e.filter(e=>e.hidden),o=this.#K.processColumns([...t]);if(o!==t){const r=new Set(o.map(e=>e.field));!t.some(e=>r.has(e.field))&&o.length>0?this._columns=[...o,...i]:this._columns=this.#et(e,o,i)}else this._columns=[...e]}}#et(e,t,i){if(0===i.length)return t;const o=new Map;for(const l of t)o.set(l.field,l);const r=new Set(e.map(e=>e.field)),n=[];for(const l of t)r.has(l.field)||n.push(l);const s=[];for(const l of e){const e=o.get(l.field);e?s.push(e):l.hidden&&s.push(l)}return s.push(...n),s}#ve(){W(this);const e=function(e,t){if(!e._sortState)return t;e.__originalOrder=[...t];const i=(e.effectiveConfig?.sortHandler??Z)(t,e._sortState,e._columns);return i&&"function"==typeof i.then?t:i}(this,Array.isArray(this.#L)?[...this.#L]:[]),t=this.#K?.processRows(e)??e;this._rows=t,this.#Ke(),this._virtualization.variableHeights&&this.#$e()}#xe(e){const t={...i,...e.animation},o=t.mode??"reduced-motion";let r=1;!1===o||"off"===o?r=0:!0!==o&&"on"!==o||(r=1),this.style.setProperty("--tbw-animation-duration",`${t.duration}ms`),this.style.setProperty("--tbw-animation-easing",t.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(r)),this.dataset.animationMode="boolean"==typeof o?o?"on":"off":o}#tt(e,t,i=this.__rowRenderEpoch){if(this.#U||(this.#U=(e,t,i)=>this.#K?.renderRow(e,t,i)??!1),function(e,t,i,o,r){const n=Math.max(0,i-t),s=e._bodyEl,l=e._visibleColumns,a=l.length;let c=e.__cachedHeaderRowCount;for(void 0===c&&(c=e.querySelector(".header-group-row")?2:1,e.__cachedHeaderRowCount=c);e._rowPool.length<n;){const t=$();e._rowPool.push(t)}if(e._rowPool.length>n){for(let t=n;t<e._rowPool.length;t++){const i=e._rowPool[t];i.parentNode===s&&i.remove()}e._rowPool.length=n}const d=r&&!1!==e.__hasRenderRowPlugins,h=e._hasAfterRowRenderHook?.()??!1;for(let g=0;g<n;g++){const i=t+g,n=e._rows[i],f=e._rowPool[g];if(f.setAttribute("aria-rowindex",String(i+c+1)),d&&r(n,f,i)){f.__epoch=o,f.__rowDataRef=n,f.parentNode!==s&&s.appendChild(f);continue}const p=f.__epoch,w=f.__rowDataRef;let b=f.children.length;b>a&&f.lastElementChild?.classList.contains("tbw-row-loading-overlay")&&b--;const m=p===o&&b===a,v=w!==n,C=!!e._isGridEditMode;let y=!1;if(m&&v)for(let e=0;e<a;e++)if(l[e].externalView&&!f.querySelector(`.cell[data-col="${e}"] [data-external-view]`)){y=!0;break}if(!m||y){const t=k(f),r=C||e._activeEditRows===i;t&&!r?(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),D(f),U(e,f,n,i),f.__epoch=o,f.__rowDataRef=n):t&&r?(F(e,f,n,i),f.__rowDataRef=n):(f.__isCustomRow&&(f.className="data-grid-row",f.setAttribute("role","row"),f.__isCustomRow=!1),U(e,f,n,i),f.__epoch=o,f.__rowDataRef=n)}else if(v){const t=k(f),r=C||e._activeEditRows===i;t&&!r?(D(f),U(e,f,n,i),f.__epoch=o,f.__rowDataRef=n):(F(e,f,n,i),f.__rowDataRef=n)}else{const t=k(f),r=C||e._activeEditRows===i;t&&!r?(D(f),U(e,f,n,i),f.__epoch=o,f.__rowDataRef=n):F(e,f,n,i)}let _=!1;const S=e.changedRowIds;if(S&&S.length>0)try{const t=e.getRowId?.(n);t&&(_=S.includes(t))}catch{}_!==f.classList.contains("changed")&&f.classList.toggle("changed",_);const R=e.effectiveConfig?.rowClass;if(R){const e=f.getAttribute("data-dynamic-classes");e&&e.split(" ").forEach(e=>e&&f.classList.remove(e));try{const e=R(n);if(e&&e.length>0){const t=e.filter(e=>e&&"string"==typeof e);t.forEach(e=>f.classList.add(e)),f.setAttribute("data-dynamic-classes",t.join(" "))}else f.removeAttribute("data-dynamic-classes")}catch(u){console.warn("[tbw-grid] rowClass callback error:",u),f.removeAttribute("data-dynamic-classes")}}h&&e._afterRowRender?.({row:n,rowIndex:i,rowElement:f}),f.parentNode!==s&&s.appendChild(f)}}(this,e,t,i,this.#U),this.#se.size>0)for(const o of this.#se)this.#ge(o,!0)}#it={rowCount:-1,colCount:-1,ariaLabel:void 0,ariaDescribedBy:void 0};#ot(e,t){!function(e,t,i,o,r){if(o===e.rowCount&&r===e.colCount)return!1;const n=e.rowCount;e.rowCount=o,e.colCount=r,t&&(t.setAttribute("aria-rowcount",String(o)),t.setAttribute("aria-colcount",String(r))),o!==n&&i&&(o>0?i.setAttribute("role","rowgroup"):i.removeAttribute("role"))}(this.#it,this.__rowsBodyEl,this._bodyEl,e,t)}#be(){!function(e,t,i,o){if(!t)return!1;let r=!1;const n=function(e,t){const i=e?.gridAriaLabel;return i||(e?.shell?.header?.title??t?.lightDomTitle??void 0)}(i,o);n!==e.ariaLabel&&(e.ariaLabel=n,n?t.setAttribute("aria-label",n):t.removeAttribute("aria-label"),r=!0);const s=i?.gridAriaDescribedBy;s!==e.ariaDescribedBy&&(e.ariaDescribedBy=s,s?t.setAttribute("aria-describedby",s):t.removeAttribute("aria-describedby"),r=!0)}(this.#it,this.__rowsBodyEl,this.#s,this.#te)}#ue(){const e=this.querySelector(".tbw-grid-root");var t;e&&(this.#ne?(this.#ae||(this.#ae=function(e){const t=document.createElement("div");return t.className="tbw-loading-overlay",t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.appendChild(ce("large",e)),t}(this.#s?.loadingRenderer)),function(e,t){e.appendChild(t)}(e,this.#ae)):(t=this.#ae,t?.remove()))}#ge(e,t){const i=this.#ce.get(e);if(!i)return;const o=this.findRenderedRowElement?.(i.index);o&&function(e,t){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(".tbw-row-loading-overlay")){const t=document.createElement("div");t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true");const i=document.createElement("div");i.className="tbw-row-loading-spinner",t.appendChild(i),e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),e.querySelector(".tbw-row-loading-overlay")?.remove()}(o,t)}#fe(e,t,i){const o=this.#ce.get(e);if(!o)return;const r=this.findRenderedRowElement?.(o.index);if(!r)return;const n=this._visibleColumns.findIndex(e=>e.field===t);if(n<0)return;const s=r.children[n];s&&function(e,t){t?(e.classList.add("tbw-cell-loading"),e.setAttribute("aria-busy","true")):(e.classList.remove("tbw-cell-loading"),e.removeAttribute("aria-busy"))}(s,i)}#Ee(){if(this.isConnected&&this._headerRowEl&&this._bodyEl){if(this.#z.parseLightDomColumns(this),this.#h){const e=this.#h;this.#h=void 0,this.#z.merge();const t=this.#K?.getAll()??[];this.#z.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#I.requestPhase(de.FULL,"setup")}}#Fe(e){let t=0,i=0,o=0,r=0,n=0;if(this.#$){const e=this._virtualization.container,s=this.#ee;t=s?.scrollLeft??0,i=e?.scrollHeight??0,o=s?.scrollWidth??0,r=e?.clientHeight??0,n=s?.clientWidth??0}if(this.refreshVirtualWindow(!1)&&this.#K?.onScrollRender(),this._virtualization.variableHeights&&(this.#F&&clearTimeout(this.#F),this.#F=window.setTimeout(()=>{this.#F=0,this.#rt(this._virtualization.start,this._virtualization.end)},100)),this.#$){const s=this.#j;s.scrollTop=e,s.scrollLeft=t,s.scrollHeight=i,s.scrollWidth=o,s.clientHeight=r,s.clientWidth=n,this.#K?.onScroll(s)}}findHeaderRow(){return this.#P.querySelector(".header-row")}findRenderedRowElement(e){return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find(t=>{const i=t.querySelector(".cell[data-row]");return i&&Number(i.getAttribute("data-row"))===e})||null}_dispatchCellClick(e,t,i,o){const r=this._rows[t],n=this._visibleColumns[i];if(!r||!n)return!1;const s=n.field,l=r[s],a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:t,colIndex:i,column:n,field:s,value:l,row:r,cellEl:o,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(a),a.defaultPrevented)return!0;const c={row:r,rowIndex:t,colIndex:i,column:n,field:s,value:l,cellEl:o,originalEvent:e},d=this.#K?.onCellClick(c)??!1;return this.#Re("cell-click",c),d}_dispatchRowClick(e,t,i,o){if(!i)return!1;const r={rowIndex:t,row:i,rowEl:o,originalEvent:e},n=this.#K?.onRowClick(r)??!1;return this.#Re("row-click",r),n}_dispatchHeaderClick(e,t,i){if(!t)return!1;const o={colIndex:this._columns.indexOf(t),field:t.field,column:t,headerEl:i,originalEvent:e};return this.#K?.onHeaderClick(o)??!1}_dispatchKeyDown(e){return this.#K?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#K?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}queryPlugins(e){return this.#K?.queryPlugins(e)??[]}query(e,t){return this.#K?.queryPlugins({type:e,context:t})??[]}_dispatchCellMouseDown(e){return this.#K?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#K?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#K?.onCellMouseUp(e)}_afterCellRender(e){this.#K?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#K?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#K?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#K?.hasAfterRowRenderHook()??!1}async ready(){return this.#S}async forceLayout(){return this.#I.requestPhase(de.FULL,"forceLayout"),this.#I.whenReady()}async getConfig(){return Object.freeze({...this.#s||{}})}getRowId(e){return this.#Qe(e,this.#s.getRowId)}getRow(e){return this.#ce.get(e)?.row}_getRowEntry(e){return this.#ce.get(e)}updateRow(e,t,i="api"){const o=this.#ce.get(e);if(!o)throw new Error(`[tbw-grid] Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:r,index:n}=o,s=[];for(const[l,a]of Object.entries(t)){const e=r[l];e!==a&&(s.push({field:l,oldValue:e,newValue:a}),r[l]=a)}for(const{field:l,oldValue:a,newValue:c}of s)this.#Re("cell-change",{row:r,rowId:e,rowIndex:n,field:l,oldValue:a,newValue:c,changes:t,source:i});s.length>0&&this.#I.requestPhase(de.ROWS,"updateRow")}updateRows(e,t="api"){let i=!1;for(const{id:o,changes:r}of e){const e=this.#ce.get(o);if(!e)throw new Error(`[tbw-grid] Row with ID "${o}" not found. Ensure the row exists and getRowId is correctly configured.`);const{row:n,index:s}=e;for(const[l,a]of Object.entries(r)){const e=n[l];e!==a&&(i=!0,n[l]=a,this.#Re("cell-change",{row:n,rowId:o,rowIndex:s,field:l,oldValue:e,newValue:a,changes:r,source:t}))}}i&&this.#I.requestPhase(de.ROWS,"updateRows")}animateRow(e,t){return be(this,e,t)}animateRows(e,t){return function(e,t,i){return Promise.all(t.map(t=>be(e,t,i))).then(e=>e.filter(Boolean).length)}(this,e,t)}animateRowById(e,t){return function(e,t,i){const o=e._rows??[],r=e.getRowId;if(!r)return Promise.resolve(!1);const n=o.findIndex(e=>{if(null==e)return!1;try{return r(e)===t}catch{return!1}});return n<0?Promise.resolve(!1):be(e,n,i)}(this,e,t)}async insertRow(e,t,i=!0){const o=Math.max(0,Math.min(e,this._rows.length));this.#L=[...this.#L,t];const r=[...this._rows];r.splice(o,0,t),this._rows=r,this._sortState&&(this.__originalOrder=[...this.__originalOrder,t]),W(this),this.#Ke(),this.__rowRenderEpoch++;for(const n of this._rowPool)n.__epoch=-1;this.refreshVirtualWindow(!0),i&&(await new Promise(e=>requestAnimationFrame(()=>e())),await this.animateRow(o,"insert"))}async removeRow(e,t=!0){const i=this._rows[e];if(!i)return;t&&await this.animateRow(e,"remove");const o=this._rows.indexOf(i);if(o<0)return i;const r=[...this._rows];r.splice(o,1),this._rows=r;const n=this.#L.indexOf(i);if(n>=0){const e=[...this.#L];e.splice(n,1),this.#L=e}if(this._sortState){const e=this.__originalOrder.indexOf(i);if(e>=0){const t=[...this.__originalOrder];t.splice(e,1),this.__originalOrder=t}}W(this),this.#Ke(),this.__rowRenderEpoch++;for(const s of this._rowPool)s.__epoch=-1;return this.refreshVirtualWindow(!0),t&&requestAnimationFrame(()=>{this.querySelectorAll('[data-animating="remove"]').forEach(e=>{e.removeAttribute("data-animating")})}),i}suspendProcessing(){}setColumnVisible(e,t){const i=this.#z.setColumnVisible(e,t);return i&&this.requestStateChange(),i}toggleColumnVisibility(e){const t=this.#z.toggleColumnVisibility(e);return t&&this.requestStateChange(),t}isColumnVisible(e){return this.#z.isColumnVisible(e)}showAllColumns(){this.#z.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#z.getAllColumns()}setColumnOrder(e){this.#z.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#z.getColumnOrder()}getColumnState(){const e=this.#K?.getAll()??[];return this.#z.collectState(e)}set columnState(e){e&&(this.#h=e,this.#z.initialColumnState=e,this.#M&&this.#nt(e))}get columnState(){return this.getColumnState()}#nt(e){const t=this.#K?.getAll()??[];this.#z.applyState(e,t),this.#Ee()}requestStateChange(){const e=this.#K?.getAll()??[];this.#z.requestStateChange(e)}resetColumnState(){this.#h=void 0,this.__originalOrder=[];const e=this.#K?.getAll()??[];this.#z.resetState(e),this.#z.merge(),this.#Ee()}get isToolPanelOpen(){return this.#ie.isPanelOpen}get defaultRowHeight(){return this._virtualization.rowHeight}get expandedToolPanelSections(){return this.#ie.expandedSections}openToolPanel(){this.#ie.openToolPanel()}closeToolPanel(){this.#ie.closeToolPanel()}toggleToolPanel(){this.#ie.toggleToolPanel()}toggleToolPanelSection(e){this.#ie.toggleToolPanelSection(e)}getToolPanels(){return this.#ie.getToolPanels()}registerToolPanel(e){this.#te.apiToolPanelIds.add(e.id),this.#ie.registerToolPanel(e)}unregisterToolPanel(e){this.#te.apiToolPanelIds.delete(e),this.#ie.unregisterToolPanel(e)}getHeaderContents(){return this.#ie.getHeaderContents()}registerHeaderContent(e){this.#ie.registerHeaderContent(e)}unregisterHeaderContent(e){this.#ie.unregisterHeaderContent(e)}getToolbarContents(){return this.#ie.getToolbarContents()}registerToolbarContent(e){this.#ie.registerToolbarContent(e)}unregisterToolbarContent(e){this.#ie.unregisterToolbarContent(e)}#st=!1;refreshShellHeader(){this.#st||(this.#st=!0,queueMicrotask(()=>{this.#st=!1,this.isConnected&&(this.#Oe(),this.#z.markSourcesChanged(),this.#z.merge(),ze(this.#te),this.#ke(),this.#Te(),this.#lt())}))}#lt(){const e=this.#P.querySelector(".tbw-grid-content")??this.#P.querySelector(".tbw-grid-root");if(this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this.#ie.isInitialized){Pe(this.#P,this.#te),He(this.#P,this.#s?.shell,this.#te);const e=this.#s?.shell?.toolPanel?.defaultOpen;e&&this.#te.toolPanels.has(e)&&(this.openToolPanel(),this.#te.expandedSections.add(e))}this._resizeController=ue(this),this.#Me(e),this.#I.requestPhase(de.COLUMNS,"shellRefresh")}#Ne=new Map;registerStyles(e,t){let i=this.#Ne.get(e);i||(i=new CSSStyleSheet,this.#Ne.set(e,i)),i.replaceSync(t),this.#at()}unregisterStyles(e){this.#Ne.delete(e)&&this.#at()}getRegisteredStyles(){return Array.from(this.#Ne.keys())}#at(){const e=Array.from(this.#Ne.values()),t=document.adoptedStyleSheets.filter(e=>!Array.from(this.#Ne.values()).includes(e));document.adoptedStyleSheets=[...t,...e]}#ct=new Set;#dt=new Map;registerExternalFocusContainer(e){if(this.#ct.has(e))return;this.#ct.add(e);const t=new AbortController,i=t.signal;e.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:i}),e.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&this.containsFocus(t)||delete this.dataset.hasFocus},{signal:i}),this.#dt.set(e,()=>t.abort())}unregisterExternalFocusContainer(e){this.#ct.delete(e);const t=this.#dt.get(e);t&&(t(),this.#dt.delete(e))}containsFocus(e){const t=e??document.activeElement;return!!t&&(!!this.contains(t)||this.#Ve(t))}#Ve(e){for(const t of this.#ct)if(t.contains(e))return!0;return!1}#Oe(){xe(this,this.#te),Ae(this,this.#te),Te(this,this.#te,this.#ze())}#ht(){const e=this.#P.querySelector(".tbw-shell-header");if(!e)return;ze(this.#te);const t=function(e,t,i="☰"){const o=e?.header?.title??t.lightDomTitle??"",r=!!o,n=Re(i),s=e?.header?.toolbarContents??[],l=[...t.toolbarContents.values()],a=new Set(s.map(e=>e.id)),c=[...s];for(const w of l)a.has(w.id)||c.push(w);const d=c.length>0,h=t.toolPanels.size>0,u=d&&h,g=[...c].sort((e,t)=>(e.order??0)-(t.order??0));let f="";for(const w of g)f+=`<div class="tbw-toolbar-content-slot" data-toolbar-content="${w.id}"></div>`;if(u&&(f+='<div class="tbw-toolbar-separator"></div>'),h){const e=t.isPanelOpen;f+=`<button class="${e?"tbw-toolbar-btn active":"tbw-toolbar-btn"}" data-panel-toggle title="Settings" aria-label="Toggle settings panel" aria-pressed="${e}" aria-controls="tbw-tool-panel">${n}</button>`}return`\n <div class="tbw-shell-header" part="shell-header" role="presentation">\n ${r?`<div class="tbw-shell-title">${p=o,p&&"string"==typeof p?p.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"):""}</div>`:""}\n <div class="tbw-shell-content" part="shell-content" role="presentation" data-light-dom-header-content></div>\n <div class="tbw-shell-toolbar" part="shell-toolbar" role="presentation">\n ${f}\n </div>\n </div>\n `;var p}(this.#s.shell,this.#te,this.#s.icons?.toolPanel),i=document.createElement("div");i.innerHTML=t;const o=i.firstElementChild;o&&(e.replaceWith(o),this.#ut(),He(this.#P,this.#s?.shell,this.#te))}#Ie(){const e=()=>{const e=this.#te.lightDomTitle,t=this.#te.hasToolButtonsContainer;this.#Oe();const i=this.#te.lightDomTitle,o=this.#te.hasToolButtonsContainer;(i&&!e||o&&!t)&&(this.#z.markSourcesChanged(),this.#z.merge(),this.#ht())},t=()=>{this.__lightDomColumnsCache=void 0,this.#Ee()};this.#z.registerLightDomHandler("tbw-grid-header",e),this.#z.registerLightDomHandler("tbw-grid-tool-buttons",e),this.#z.registerLightDomHandler("tbw-grid-tool-panel",e),this.#z.registerLightDomHandler("tbw-grid-column",t),this.#z.registerLightDomHandler("tbw-grid-detail",t),this.#z.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,W(this),this.#z.parseLightDomColumns(this);const e=this.#te.lightDomTitle,t=this.#te.hasToolButtonsContainer;this.#Oe();const i=this.#te.lightDomTitle,o=this.#te.hasToolButtonsContainer;(i&&!e||o&&!t)&&(this.#z.markSourcesChanged(),this.#z.merge(),this.#ht()),this.#I.requestPhase(de.COLUMNS,"refreshColumns")}#Ue(){const e=this._virtualization.container,t=this._virtualization.viewportEl??e;t&&(this._virtualization.cachedViewportHeight=t.clientHeight),e&&(this._virtualization.cachedFauxHeight=e.clientHeight);const i=this._virtualization.scrollAreaEl;i&&(this._virtualization.cachedScrollAreaHeight=i.clientHeight)}#Ce(e,t=!1){const i=this._virtualization;let o,r,n;if(t){const e=i.container??this,t=i.viewportEl??e,s=i.scrollAreaEl;o=e.clientHeight,r=t.clientHeight,n=s?s.clientHeight:o,i.cachedFauxHeight=o,i.cachedViewportHeight=r,i.cachedScrollAreaHeight=n}else o=i.cachedFauxHeight,r=i.cachedViewportHeight,n=i.cachedScrollAreaHeight||o;const s=n-r,l=Math.max(0,o-n);let a,c=0;i.variableHeights&&i.positionCache?a=function(e){if(0===e.length)return 0;const t=e[e.length-1];return t.offset+t.height}(i.positionCache):(a=e*i.rowHeight,c=this.#K?.getExtraHeight()??0);return a+s+c+l}#$e(){if(!this._virtualization.variableHeights)return;const e=this._rows,t=this._virtualization.rowHeight||28,i=this.#s.rowHeight,o=this.#s.getRowId,r=o?e=>o(e):void 0;this._virtualization.positionCache=function(e,t,i,o,r){const n=new Array(e.length);let s=0;for(let l=0;l<e.length;l++){const a=e[l];let c=r?.(a,l),d=void 0!==c;void 0===c&&(c=Ze(t,a,o.rowId),d=void 0!==c),void 0===c&&(c=i,d=!1),n[l]={offset:s,height:c,measured:d},s+=c}return n}(e,this._virtualization.heightCache,t,{rowId:r},(e,t)=>{const o=this.#K?.getRowHeight?.(e,t);if(void 0!==o)return o;if(i){const o=i(e,t);if(void 0!==o&&o>0)return o}});const n=function(e,t,i,o){let r=0,n=0;for(let s=0;s<e.length;s++){const i=e[s];if(i.measured){const e=o?.(t[s],s);void 0===e&&(n+=i.height,r++)}}return{measuredCount:r,averageHeight:r>0?n/r:i}}(this._virtualization.positionCache,e,t,(e,t)=>this.#K?.getRowHeight?.(e,t));this._virtualization.measuredCount=n.measuredCount,n.measuredCount>0&&(this._virtualization.averageHeight=n.averageHeight)}invalidateRowHeight(e,t){if(!this._virtualization.variableHeights)return;if(!this._virtualization.positionCache)return;if(e<0||e>=this._rows.length)return;const i=this._virtualization.positionCache,o=this._rows[e];let r=t;void 0===r&&(r=this.#K?.getRowHeight?.(o,e)),void 0===r&&(r=this._virtualization.rowHeight);const n=i[e];if(n&&!(Math.abs(n.height-r)<1)&&(Qe(i,e,r),this._virtualization.totalHeightEl)){const e=this.#Ce(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`}}#rt(e,t){if(!this._virtualization.variableHeights)return;if(!this._virtualization.positionCache)return;if(!this._bodyEl)return;const i=this._bodyEl.querySelectorAll(".data-grid-row"),o=this.#s.getRowId,r=et({positionCache:this._virtualization.positionCache,heightCache:this._virtualization.heightCache,rows:this._rows,defaultHeight:this._virtualization.rowHeight,start:e,end:t,getPluginHeight:(e,t)=>this.#K?.getRowHeight?.(e,t),getRowId:o?e=>o(e):void 0},i);if(r.hasChanges&&(this._virtualization.measuredCount=r.measuredCount,this._virtualization.averageHeight=r.averageHeight,this._virtualization.totalHeightEl)){const e=this.#Ce(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`}}refreshVirtualWindow(e=!1,t=!1){if(!this._bodyEl)return!1;const i=this._rows.length;if(!this._virtualization.enabled)return this.#tt(0,i),t||this.#K?.afterRender(),!0;if(this._rows.length<=this._virtualization.bypassThreshold)return this._virtualization.start=0,this._virtualization.end=i,e&&(this._bodyEl.style.transform="translateY(0px)"),this.#tt(0,i,this.__rowRenderEpoch),e&&this._virtualization.totalHeightEl&&(this._virtualization.totalHeightEl.style.height=`${this.#Ce(i,!0)}px`),this.#ot(i,this._visibleColumns.length),t||this.#K?.afterRender(),!0;const o=this._virtualization.container??this,r=this._virtualization.viewportEl??o,n=e?this._virtualization.cachedViewportHeight=r.clientHeight:this._virtualization.cachedViewportHeight||(this._virtualization.cachedViewportHeight=r.clientHeight),s=this._virtualization.rowHeight,l=o.scrollTop;let a;const c=this._virtualization.positionCache;if(this._virtualization.variableHeights&&c&&c.length>0)a=Je(c,l),-1===a&&(a=0);else{a=Math.floor(l/s);let e=0;const t=10;for(;e<t;){const t=this.#K?.getExtraHeightBefore?.(a)??0,i=Math.floor((l-t)/s);if(i>=a||i<0)break;a=i,e++}}a-=a%2,a<0&&(a=0);const d=this.#K?.adjustVirtualStart(a,l,s);let h;if(void 0!==d&&d<a&&(a=d,a-=a%2,a<0&&(a=0)),this._virtualization.variableHeights&&c&&c.length>0){const e=n+3*s;let t=0;for(h=a;h<i&&t<e;)t+=c[h].height,h++;const o=Math.ceil(n/s)+3;h-a<o&&(h=Math.min(a+o,i))}else{h=a+(Math.ceil(n/s)+3)}h>i&&(h=i);const u=this._virtualization.start,g=this._virtualization.end;if(!e&&a===u&&h===g)return!1;this._virtualization.start=a,this._virtualization.end=h;const f=e?this._virtualization.cachedFauxHeight=o.clientHeight:this._virtualization.cachedFauxHeight||(this._virtualization.cachedFauxHeight=o.clientHeight);if(e){const e=this._virtualization.scrollAreaEl;e&&(this._virtualization.cachedScrollAreaHeight=e.clientHeight)}if(0===f&&n>0)return this.#I.requestPhase(de.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&this._virtualization.totalHeightEl){const e=this.#Ce(i);this._virtualization.totalHeightEl.style.height=`${e}px`}let p;if(this._virtualization.variableHeights&&c&&c[a])p=c[a].offset;else{p=a*s+(this.#K?.getExtraHeightBefore?.(a)??0)}const w=-(l-p);return this._bodyEl.style.transform=`translateY(${w}px)`,this.#tt(a,h,this.__rowRenderEpoch),e&&this._virtualization.variableHeights&&this.#rt(a,h),this.#ot(i,this._visibleColumns.length),e&&!t&&(this.#K?.afterRender(),queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const e=this.#Ce(i);0===this._virtualization.cachedFauxHeight&&this._virtualization.cachedViewportHeight>0||(this._virtualization.totalHeightEl.style.height=`${e}px`)})),!0}#ke(){this.#Oe(),this.#z.markSourcesChanged(),this.#z.merge();const e=this.#s?.shell;De(this.#P,e,{isPanelOpen:this.#te.isPanelOpen,expandedSections:this.#te.expandedSections},this.#s?.icons)&&(this.#ut(),this.#ie.setInitialized(!0))}#ut(){!function(e,t,i,o){const r=e.querySelector(".tbw-shell-toolbar");r&&r.addEventListener("click",e=>{e.target.closest("[data-panel-toggle]")&&o.onPanelToggle()});const n=e.querySelector(".tbw-accordion");n&&n.addEventListener("click",e=>{const t=e.target.closest(".tbw-accordion-header");if(t){const e=t.closest("[data-section]"),i=e?.getAttribute("data-section");i&&o.onSectionToggle(i)}})}(this.#P,this.#s,this.#te,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e)}),this.#oe?.(),this.#oe=function(e,t,i){const o=e.querySelector(".tbw-tool-panel"),r=e.querySelector("[data-resize-handle]"),n=e.querySelector(".tbw-shell-body");if(!o||!r||!n)return()=>{};const s=t?.toolPanel?.position??"right";let l=0,a=0,c=0,d=!1;const h=e=>{if(!d)return;e.preventDefault();const t="left"===s?e.clientX-l:l-e.clientX,i=Math.min(c,Math.max(200,a+t));o.style.width=`${i}px`},u=()=>{if(!d)return;d=!1,r.classList.remove("resizing"),o.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const e=o.getBoundingClientRect().width;i(e),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",u)},g=e=>{e.preventDefault(),d=!0,l=e.clientX,a=o.getBoundingClientRect().width,c=n.getBoundingClientRect().width-20,r.classList.add("resizing"),o.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",u)};return r.addEventListener("mousedown",g),()=>{r.removeEventListener("mousedown",g),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",u)}}(this.#P,this.#s?.shell,e=>{this.style.setProperty("--tbw-tool-panel-width",`${e}px`)}),this.#re?.(),this.#re=function(e,t,i,o){if(!t?.toolPanel?.closeOnClickOutside)return()=>{};const r=e=>{if(!i.isPanelOpen)return;const t=e.target;t&&(t.closest(".tbw-tool-panel")||t.closest("[data-panel-toggle]")||o())};return e.addEventListener("mousedown",r),()=>e.removeEventListener("mousedown",r)}(this,this.#s?.shell,this.#te,()=>this.closeToolPanel())}}customElements.get(it.tagName)||customElements.define(it.tagName,it),globalThis.DataGridElement=it;const ot={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"},rt={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"},nt={ROOT:`.${ot.ROOT}`,HEADER:`.${ot.HEADER}`,HEADER_ROW:`.${ot.HEADER_ROW}`,HEADER_CELL:`.${ot.HEADER_CELL}`,ROWS_VIEWPORT:`.${ot.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${ot.ROWS_CONTAINER}`,DATA_ROW:`.${ot.DATA_ROW}`,DATA_CELL:`.${ot.DATA_CELL}`,GROUP_ROW:`.${ot.GROUP_ROW}`,ROW_BY_INDEX:e=>`.${ot.DATA_ROW}[${rt.ROW_INDEX}="${e}"]`,CELL_BY_FIELD:e=>`.${ot.DATA_CELL}[${rt.FIELD}="${e}"]`,CELL_AT:(e,t)=>`.${ot.DATA_ROW}[${rt.ROW_INDEX}="${e}"] .${ot.DATA_CELL}[${rt.COL_INDEX}="${t}"]`,SELECTED_ROWS:`.${ot.DATA_ROW}.${ot.SELECTED}`,EDITING_CELL:`.${ot.DATA_CELL}.${ot.EDITING}`};const st={sum:(e,t)=>e.reduce((e,i)=>e+(Number(i[t])||0),0),avg:(e,t)=>{const i=e.reduce((e,i)=>e+(Number(i[t])||0),0);return e.length?i/e.length:0},count:e=>e.length,min:(e,t)=>e.length?Math.min(...e.map(e=>Number(e[t])||1/0)):0,max:(e,t)=>e.length?Math.max(...e.map(e=>Number(e[t])||-1/0)):0,first:(e,t)=>e[0]?.[t],last:(e,t)=>e[e.length-1]?.[t]},lt=new Map,at={register(e,t){lt.set(e,t)},unregister(e){lt.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:lt.get(e)??st[e]},run(e,t,i,o){const r=this.get(e);return r?r(t,i,o):void 0},has:e=>lt.has(e)||e in st,list:()=>[...Object.keys(st),...lt.keys()]},ct={sum:e=>e.reduce((e,t)=>e+t,0),avg:e=>e.length?e.reduce((e,t)=>e+t,0)/e.length:0,count:e=>e.length,min:e=>e.length?Math.min(...e):0,max:e=>e.length?Math.max(...e):0,first:e=>e[0]??0,last:e=>e[e.length-1]??0};function dt(e){return ct[e]??ct.sum}const ht=at.register.bind(at),ut=at.unregister.bind(at),gt=at.get.bind(at),ft=at.run.bind(at),pt=at.list.bind(at);e.BaseGridPlugin=class{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#gt;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#gt?.abort(),this.#gt=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#gt?.abort(),this.#gt=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}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.#gt?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...r,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}resolveIcon(e,t){return void 0!==t?t:this.gridIcons[e]}setIcon(e,t){"string"==typeof t?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}},e.DEFAULT_ANIMATION_CONFIG=i,e.DEFAULT_GRID_ICONS=r,e.DGEvents={CELL_CHANGE:"cell-change",CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",EDIT_OPEN:"edit-open",EDIT_CLOSE:"edit-close",CHANGED_ROWS_RESET:"changed-rows-reset",MOUNT_EXTERNAL_VIEW:"mount-external-view",MOUNT_EXTERNAL_EDITOR:"mount-external-editor",SORT_CHANGE:"sort-change",COLUMN_RESIZE:"column-resize",ACTIVATE_CELL:"activate-cell",CELL_ACTIVATE:"cell-activate",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change"},e.DataGridElement=it,e.FitModeEnum=t,e.GridCSSVars={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"},e.GridClasses=ot,e.GridDataAttrs=rt,e.GridElement=it,e.GridSelectors=nt,e.PLUGIN_QUERIES={CAN_MOVE_COLUMN:"canMoveColumn",GET_CONTEXT_MENU_ITEMS:"getContextMenuItems"},e.PluginEvents={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"},e.PluginManager=tt,e.RenderPhase=de,e.aggregatorRegistry=at,e.builtInSort=Z,e.createGrid=function(e){const t=document.createElement("tbw-grid");return e&&(t.gridConfig=e),t},e.defaultComparator=K,e.getAggregator=gt,e.getValueAggregator=dt,e.listAggregators=pt,e.queryGrid=function(e,t=document){return t.querySelector(e)},e.registerAggregator=ht,e.runAggregator=ft,e.runValueAggregator=function(e,t){return dt(e)(t)},e.unregisterAggregator=ut,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
91
2
|
//# sourceMappingURL=grid.umd.js.map
|